raspberry.patch 2.9 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319503205032150322503235032450325503265032750328503295033050331503325033350334503355033650337503385033950340503415034250343503445034550346503475034850349503505035150352503535035450355503565035750358503595036050361503625036350364503655036650367503685036950370503715037250373503745037550376503775037850379503805038150382503835038450385503865038750388503895039050391503925039350394503955039650397503985039950400504015040250403504045040550406504075040850409504105041150412504135041450415504165041750418504195042050421504225042350424504255042650427504285042950430504315043250433504345043550436504375043850439504405044150442504435044450445504465044750448504495045050451504525045350454504555045650457504585045950460504615046250463504645046550466504675046850469504705047150472504735047450475504765047750478504795048050481504825048350484504855048650487504885048950490504915049250493504945049550496504975049850499505005050150502505035050450505505065050750508505095051050511505125051350514505155051650517505185051950520505215052250523505245052550526505275052850529505305053150532505335053450535505365053750538505395054050541505425054350544505455054650547505485054950550505515055250553505545055550556505575055850559505605056150562505635056450565505665056750568505695057050571505725057350574505755057650577505785057950580505815058250583505845058550586505875058850589505905059150592505935059450595505965059750598505995060050601506025060350604506055060650607506085060950610506115061250613506145061550616506175061850619506205062150622506235062450625506265062750628506295063050631506325063350634506355063650637506385063950640506415064250643506445064550646506475064850649506505065150652506535065450655506565065750658506595066050661506625066350664506655066650667506685066950670506715067250673506745067550676506775067850679506805068150682506835068450685506865068750688506895069050691506925069350694506955069650697506985069950700507015070250703507045070550706507075070850709507105071150712507135071450715507165071750718507195072050721507225072350724507255072650727507285072950730507315073250733507345073550736507375073850739507405074150742507435074450745507465074750748507495075050751507525075350754507555075650757507585075950760507615076250763507645076550766507675076850769507705077150772507735077450775507765077750778507795078050781507825078350784507855078650787507885078950790507915079250793507945079550796507975079850799508005080150802508035080450805508065080750808508095081050811508125081350814508155081650817508185081950820508215082250823508245082550826508275082850829508305083150832508335083450835508365083750838508395084050841508425084350844508455084650847508485084950850508515085250853508545085550856508575085850859508605086150862508635086450865508665086750868508695087050871508725087350874508755087650877508785087950880508815088250883508845088550886508875088850889508905089150892508935089450895508965089750898508995090050901509025090350904509055090650907509085090950910509115091250913509145091550916509175091850919509205092150922509235092450925509265092750928509295093050931509325093350934509355093650937509385093950940509415094250943509445094550946509475094850949509505095150952509535095450955509565095750958509595096050961509625096350964509655096650967509685096950970509715097250973509745097550976509775097850979509805098150982509835098450985509865098750988509895099050991509925099350994509955099650997509985099951000510015100251003510045100551006510075100851009510105101151012510135101451015510165101751018510195102051021510225102351024510255102651027510285102951030510315103251033510345103551036510375103851039510405104151042510435104451045510465104751048510495105051051510525105351054510555105651057510585105951060510615106251063510645106551066510675106851069510705107151072510735107451075510765107751078510795108051081510825108351084510855108651087510885108951090510915109251093510945109551096510975109851099511005110151102511035110451105511065110751108511095111051111511125111351114511155111651117511185111951120511215112251123511245112551126511275112851129511305113151132511335113451135511365113751138511395114051141511425114351144511455114651147511485114951150511515115251153511545115551156511575115851159511605116151162511635116451165511665116751168511695117051171511725117351174511755117651177511785117951180511815118251183511845118551186511875118851189511905119151192511935119451195511965119751198511995120051201512025120351204512055120651207512085120951210512115121251213512145121551216512175121851219512205122151222512235122451225512265122751228512295123051231512325123351234512355123651237512385123951240512415124251243512445124551246512475124851249512505125151252512535125451255512565125751258512595126051261512625126351264512655126651267512685126951270512715127251273512745127551276512775127851279512805128151282512835128451285512865128751288512895129051291512925129351294512955129651297512985129951300513015130251303513045130551306513075130851309513105131151312513135131451315513165131751318513195132051321513225132351324513255132651327513285132951330513315133251333513345133551336513375133851339513405134151342513435134451345513465134751348513495135051351513525135351354513555135651357513585135951360513615136251363513645136551366513675136851369513705137151372513735137451375513765137751378513795138051381513825138351384513855138651387513885138951390513915139251393513945139551396513975139851399514005140151402514035140451405514065140751408514095141051411514125141351414514155141651417514185141951420514215142251423514245142551426514275142851429514305143151432514335143451435514365143751438514395144051441514425144351444514455144651447514485144951450514515145251453514545145551456514575145851459514605146151462514635146451465514665146751468514695147051471514725147351474514755147651477514785147951480514815148251483514845148551486514875148851489514905149151492514935149451495514965149751498514995150051501515025150351504515055150651507515085150951510515115151251513515145151551516515175151851519515205152151522515235152451525515265152751528515295153051531515325153351534515355153651537515385153951540515415154251543515445154551546515475154851549515505155151552515535155451555515565155751558515595156051561515625156351564515655156651567515685156951570515715157251573515745157551576515775157851579515805158151582515835158451585515865158751588515895159051591515925159351594515955159651597515985159951600516015160251603516045160551606516075160851609516105161151612516135161451615516165161751618516195162051621516225162351624516255162651627516285162951630516315163251633516345163551636516375163851639516405164151642516435164451645516465164751648516495165051651516525165351654516555165651657516585165951660516615166251663516645166551666516675166851669516705167151672516735167451675516765167751678516795168051681516825168351684516855168651687516885168951690516915169251693516945169551696516975169851699517005170151702517035170451705517065170751708517095171051711517125171351714517155171651717517185171951720517215172251723517245172551726517275172851729517305173151732517335173451735517365173751738517395174051741517425174351744517455174651747517485174951750517515175251753517545175551756517575175851759517605176151762517635176451765517665176751768517695177051771517725177351774517755177651777517785177951780517815178251783517845178551786517875178851789517905179151792517935179451795517965179751798517995180051801518025180351804518055180651807518085180951810518115181251813518145181551816518175181851819518205182151822518235182451825518265182751828518295183051831518325183351834518355183651837518385183951840518415184251843518445184551846518475184851849518505185151852518535185451855518565185751858518595186051861518625186351864518655186651867518685186951870518715187251873518745187551876518775187851879518805188151882518835188451885518865188751888518895189051891518925189351894518955189651897518985189951900519015190251903519045190551906519075190851909519105191151912519135191451915519165191751918519195192051921519225192351924519255192651927519285192951930519315193251933519345193551936519375193851939519405194151942519435194451945519465194751948519495195051951519525195351954519555195651957519585195951960519615196251963519645196551966519675196851969519705197151972519735197451975519765197751978519795198051981519825198351984519855198651987519885198951990519915199251993519945199551996519975199851999520005200152002520035200452005520065200752008520095201052011520125201352014520155201652017520185201952020520215202252023520245202552026520275202852029520305203152032520335203452035520365203752038520395204052041520425204352044520455204652047520485204952050520515205252053520545205552056520575205852059520605206152062520635206452065520665206752068520695207052071520725207352074520755207652077520785207952080520815208252083520845208552086520875208852089520905209152092520935209452095520965209752098520995210052101521025210352104521055210652107521085210952110521115211252113521145211552116521175211852119521205212152122521235212452125521265212752128521295213052131521325213352134521355213652137521385213952140521415214252143521445214552146521475214852149521505215152152521535215452155521565215752158521595216052161521625216352164521655216652167521685216952170521715217252173521745217552176521775217852179521805218152182521835218452185521865218752188521895219052191521925219352194521955219652197521985219952200522015220252203522045220552206522075220852209522105221152212522135221452215522165221752218522195222052221522225222352224522255222652227522285222952230522315223252233522345223552236522375223852239522405224152242522435224452245522465224752248522495225052251522525225352254522555225652257522585225952260522615226252263522645226552266522675226852269522705227152272522735227452275522765227752278522795228052281522825228352284522855228652287522885228952290522915229252293522945229552296522975229852299523005230152302523035230452305523065230752308523095231052311523125231352314523155231652317523185231952320523215232252323523245232552326523275232852329523305233152332523335233452335523365233752338523395234052341523425234352344523455234652347523485234952350523515235252353523545235552356523575235852359523605236152362523635236452365523665236752368523695237052371523725237352374523755237652377523785237952380523815238252383523845238552386523875238852389523905239152392523935239452395523965239752398523995240052401524025240352404524055240652407524085240952410524115241252413524145241552416524175241852419524205242152422524235242452425524265242752428524295243052431524325243352434524355243652437524385243952440524415244252443524445244552446524475244852449524505245152452524535245452455524565245752458524595246052461524625246352464524655246652467524685246952470524715247252473524745247552476524775247852479524805248152482524835248452485524865248752488524895249052491524925249352494524955249652497524985249952500525015250252503525045250552506525075250852509525105251152512525135251452515525165251752518525195252052521525225252352524525255252652527525285252952530525315253252533525345253552536525375253852539525405254152542525435254452545525465254752548525495255052551525525255352554525555255652557525585255952560525615256252563525645256552566525675256852569525705257152572525735257452575525765257752578525795258052581525825258352584525855258652587525885258952590525915259252593525945259552596525975259852599526005260152602526035260452605526065260752608526095261052611526125261352614526155261652617526185261952620526215262252623526245262552626526275262852629526305263152632526335263452635526365263752638526395264052641526425264352644526455264652647526485264952650526515265252653526545265552656526575265852659526605266152662526635266452665526665266752668526695267052671526725267352674526755267652677526785267952680526815268252683526845268552686526875268852689526905269152692526935269452695526965269752698526995270052701527025270352704527055270652707527085270952710527115271252713527145271552716527175271852719527205272152722527235272452725527265272752728527295273052731527325273352734527355273652737527385273952740527415274252743527445274552746527475274852749527505275152752527535275452755527565275752758527595276052761527625276352764527655276652767527685276952770527715277252773527745277552776527775277852779527805278152782527835278452785527865278752788527895279052791527925279352794527955279652797527985279952800528015280252803528045280552806528075280852809528105281152812528135281452815528165281752818528195282052821528225282352824528255282652827528285282952830528315283252833528345283552836528375283852839528405284152842528435284452845528465284752848528495285052851528525285352854528555285652857528585285952860528615286252863528645286552866528675286852869528705287152872528735287452875528765287752878528795288052881528825288352884528855288652887528885288952890528915289252893528945289552896528975289852899529005290152902529035290452905529065290752908529095291052911529125291352914529155291652917529185291952920529215292252923529245292552926529275292852929529305293152932529335293452935529365293752938529395294052941529425294352944529455294652947529485294952950529515295252953529545295552956529575295852959529605296152962529635296452965529665296752968529695297052971529725297352974529755297652977529785297952980529815298252983529845298552986529875298852989529905299152992529935299452995529965299752998529995300053001530025300353004530055300653007530085300953010530115301253013530145301553016530175301853019530205302153022530235302453025530265302753028530295303053031530325303353034530355303653037530385303953040530415304253043530445304553046530475304853049530505305153052530535305453055530565305753058530595306053061530625306353064530655306653067530685306953070530715307253073530745307553076530775307853079530805308153082530835308453085530865308753088530895309053091530925309353094530955309653097530985309953100531015310253103531045310553106531075310853109531105311153112531135311453115531165311753118531195312053121531225312353124531255312653127531285312953130531315313253133531345313553136531375313853139531405314153142531435314453145531465314753148531495315053151531525315353154531555315653157531585315953160531615316253163531645316553166531675316853169531705317153172531735317453175531765317753178531795318053181531825318353184531855318653187531885318953190531915319253193531945319553196531975319853199532005320153202532035320453205532065320753208532095321053211532125321353214532155321653217532185321953220532215322253223532245322553226532275322853229532305323153232532335323453235532365323753238532395324053241532425324353244532455324653247532485324953250532515325253253532545325553256532575325853259532605326153262532635326453265532665326753268532695327053271532725327353274532755327653277532785327953280532815328253283532845328553286532875328853289532905329153292532935329453295532965329753298532995330053301533025330353304533055330653307533085330953310533115331253313533145331553316533175331853319533205332153322533235332453325533265332753328533295333053331533325333353334533355333653337533385333953340533415334253343533445334553346533475334853349533505335153352533535335453355533565335753358533595336053361533625336353364533655336653367533685336953370533715337253373533745337553376533775337853379533805338153382533835338453385533865338753388533895339053391533925339353394533955339653397533985339953400534015340253403534045340553406534075340853409534105341153412534135341453415534165341753418534195342053421534225342353424534255342653427534285342953430534315343253433534345343553436534375343853439534405344153442534435344453445534465344753448534495345053451534525345353454534555345653457534585345953460534615346253463534645346553466534675346853469534705347153472534735347453475534765347753478534795348053481534825348353484534855348653487534885348953490534915349253493534945349553496534975349853499535005350153502535035350453505535065350753508535095351053511535125351353514535155351653517535185351953520535215352253523535245352553526535275352853529535305353153532535335353453535535365353753538535395354053541535425354353544535455354653547535485354953550535515355253553535545355553556535575355853559535605356153562535635356453565535665356753568535695357053571535725357353574535755357653577535785357953580535815358253583535845358553586535875358853589535905359153592535935359453595535965359753598535995360053601536025360353604536055360653607536085360953610536115361253613536145361553616536175361853619536205362153622536235362453625536265362753628536295363053631536325363353634536355363653637536385363953640536415364253643536445364553646536475364853649536505365153652536535365453655536565365753658536595366053661536625366353664536655366653667536685366953670536715367253673536745367553676536775367853679536805368153682536835368453685536865368753688536895369053691536925369353694536955369653697536985369953700537015370253703537045370553706537075370853709537105371153712537135371453715537165371753718537195372053721537225372353724537255372653727537285372953730537315373253733537345373553736537375373853739537405374153742537435374453745537465374753748537495375053751537525375353754537555375653757537585375953760537615376253763537645376553766537675376853769537705377153772537735377453775537765377753778537795378053781537825378353784537855378653787537885378953790537915379253793537945379553796537975379853799538005380153802538035380453805538065380753808538095381053811538125381353814538155381653817538185381953820538215382253823538245382553826538275382853829538305383153832538335383453835538365383753838538395384053841538425384353844538455384653847538485384953850538515385253853538545385553856538575385853859538605386153862538635386453865538665386753868538695387053871538725387353874538755387653877538785387953880538815388253883538845388553886538875388853889538905389153892538935389453895538965389753898538995390053901539025390353904539055390653907539085390953910539115391253913539145391553916539175391853919539205392153922539235392453925539265392753928539295393053931539325393353934539355393653937539385393953940539415394253943539445394553946539475394853949539505395153952539535395453955539565395753958539595396053961539625396353964539655396653967539685396953970539715397253973539745397553976539775397853979539805398153982539835398453985539865398753988539895399053991539925399353994539955399653997539985399954000540015400254003540045400554006540075400854009540105401154012540135401454015540165401754018540195402054021540225402354024540255402654027540285402954030540315403254033540345403554036540375403854039540405404154042540435404454045540465404754048540495405054051540525405354054540555405654057540585405954060540615406254063540645406554066540675406854069540705407154072540735407454075540765407754078540795408054081540825408354084540855408654087540885408954090540915409254093540945409554096540975409854099541005410154102541035410454105541065410754108541095411054111541125411354114541155411654117541185411954120541215412254123541245412554126541275412854129541305413154132541335413454135541365413754138541395414054141541425414354144541455414654147541485414954150541515415254153541545415554156541575415854159541605416154162541635416454165541665416754168541695417054171541725417354174541755417654177541785417954180541815418254183541845418554186541875418854189541905419154192541935419454195541965419754198541995420054201542025420354204542055420654207542085420954210542115421254213542145421554216542175421854219542205422154222542235422454225542265422754228542295423054231542325423354234542355423654237542385423954240542415424254243542445424554246542475424854249542505425154252542535425454255542565425754258542595426054261542625426354264542655426654267542685426954270542715427254273542745427554276542775427854279542805428154282542835428454285542865428754288542895429054291542925429354294542955429654297542985429954300543015430254303543045430554306543075430854309543105431154312543135431454315543165431754318543195432054321543225432354324543255432654327543285432954330543315433254333543345433554336543375433854339543405434154342543435434454345543465434754348543495435054351543525435354354543555435654357543585435954360543615436254363543645436554366543675436854369543705437154372543735437454375543765437754378543795438054381543825438354384543855438654387543885438954390543915439254393543945439554396543975439854399544005440154402544035440454405544065440754408544095441054411544125441354414544155441654417544185441954420544215442254423544245442554426544275442854429544305443154432544335443454435544365443754438544395444054441544425444354444544455444654447544485444954450544515445254453544545445554456544575445854459544605446154462544635446454465544665446754468544695447054471544725447354474544755447654477544785447954480544815448254483544845448554486544875448854489544905449154492544935449454495544965449754498544995450054501545025450354504545055450654507545085450954510545115451254513545145451554516545175451854519545205452154522545235452454525545265452754528545295453054531545325453354534545355453654537545385453954540545415454254543545445454554546545475454854549545505455154552545535455454555545565455754558545595456054561545625456354564545655456654567545685456954570545715457254573545745457554576545775457854579545805458154582545835458454585545865458754588545895459054591545925459354594545955459654597545985459954600546015460254603546045460554606546075460854609546105461154612546135461454615546165461754618546195462054621546225462354624546255462654627546285462954630546315463254633546345463554636546375463854639546405464154642546435464454645546465464754648546495465054651546525465354654546555465654657546585465954660546615466254663546645466554666546675466854669546705467154672546735467454675546765467754678546795468054681546825468354684546855468654687546885468954690546915469254693546945469554696546975469854699547005470154702547035470454705547065470754708547095471054711547125471354714547155471654717547185471954720547215472254723547245472554726547275472854729547305473154732547335473454735547365473754738547395474054741547425474354744547455474654747547485474954750547515475254753547545475554756547575475854759547605476154762547635476454765547665476754768547695477054771547725477354774547755477654777547785477954780547815478254783547845478554786547875478854789547905479154792547935479454795547965479754798547995480054801548025480354804548055480654807548085480954810548115481254813548145481554816548175481854819548205482154822548235482454825548265482754828548295483054831548325483354834548355483654837548385483954840548415484254843548445484554846548475484854849548505485154852548535485454855548565485754858548595486054861548625486354864548655486654867548685486954870548715487254873548745487554876548775487854879548805488154882548835488454885548865488754888548895489054891548925489354894548955489654897548985489954900549015490254903549045490554906549075490854909549105491154912549135491454915549165491754918549195492054921549225492354924549255492654927549285492954930549315493254933549345493554936549375493854939549405494154942549435494454945549465494754948549495495054951549525495354954549555495654957549585495954960549615496254963549645496554966549675496854969549705497154972549735497454975549765497754978549795498054981549825498354984549855498654987549885498954990549915499254993549945499554996549975499854999550005500155002550035500455005550065500755008550095501055011550125501355014550155501655017550185501955020550215502255023550245502555026550275502855029550305503155032550335503455035550365503755038550395504055041550425504355044550455504655047550485504955050550515505255053550545505555056550575505855059550605506155062550635506455065550665506755068550695507055071550725507355074550755507655077550785507955080550815508255083550845508555086550875508855089550905509155092550935509455095550965509755098550995510055101551025510355104551055510655107551085510955110551115511255113551145511555116551175511855119551205512155122551235512455125551265512755128551295513055131551325513355134551355513655137551385513955140551415514255143551445514555146551475514855149551505515155152551535515455155551565515755158551595516055161551625516355164551655516655167551685516955170551715517255173551745517555176551775517855179551805518155182551835518455185551865518755188551895519055191551925519355194551955519655197551985519955200552015520255203552045520555206552075520855209552105521155212552135521455215552165521755218552195522055221552225522355224552255522655227552285522955230552315523255233552345523555236552375523855239552405524155242552435524455245552465524755248552495525055251552525525355254552555525655257552585525955260552615526255263552645526555266552675526855269552705527155272552735527455275552765527755278552795528055281552825528355284552855528655287552885528955290552915529255293552945529555296552975529855299553005530155302553035530455305553065530755308553095531055311553125531355314553155531655317553185531955320553215532255323553245532555326553275532855329553305533155332553335533455335553365533755338553395534055341553425534355344553455534655347553485534955350553515535255353553545535555356553575535855359553605536155362553635536455365553665536755368553695537055371553725537355374553755537655377553785537955380553815538255383553845538555386553875538855389553905539155392553935539455395553965539755398553995540055401554025540355404554055540655407554085540955410554115541255413554145541555416554175541855419554205542155422554235542455425554265542755428554295543055431554325543355434554355543655437554385543955440554415544255443554445544555446554475544855449554505545155452554535545455455554565545755458554595546055461554625546355464554655546655467554685546955470554715547255473554745547555476554775547855479554805548155482554835548455485554865548755488554895549055491554925549355494554955549655497554985549955500555015550255503555045550555506555075550855509555105551155512555135551455515555165551755518555195552055521555225552355524555255552655527555285552955530555315553255533555345553555536555375553855539555405554155542555435554455545555465554755548555495555055551555525555355554555555555655557555585555955560555615556255563555645556555566555675556855569555705557155572555735557455575555765557755578555795558055581555825558355584555855558655587555885558955590555915559255593555945559555596555975559855599556005560155602556035560455605556065560755608556095561055611556125561355614556155561655617556185561955620556215562255623556245562555626556275562855629556305563155632556335563455635556365563755638556395564055641556425564355644556455564655647556485564955650556515565255653556545565555656556575565855659556605566155662556635566455665556665566755668556695567055671556725567355674556755567655677556785567955680556815568255683556845568555686556875568855689556905569155692556935569455695556965569755698556995570055701557025570355704557055570655707557085570955710557115571255713557145571555716557175571855719557205572155722557235572455725557265572755728557295573055731557325573355734557355573655737557385573955740557415574255743557445574555746557475574855749557505575155752557535575455755557565575755758557595576055761557625576355764557655576655767557685576955770557715577255773557745577555776557775577855779557805578155782557835578455785557865578755788557895579055791557925579355794557955579655797557985579955800558015580255803558045580555806558075580855809558105581155812558135581455815558165581755818558195582055821558225582355824558255582655827558285582955830558315583255833558345583555836558375583855839558405584155842558435584455845558465584755848558495585055851558525585355854558555585655857558585585955860558615586255863558645586555866558675586855869558705587155872558735587455875558765587755878558795588055881558825588355884558855588655887558885588955890558915589255893558945589555896558975589855899559005590155902559035590455905559065590755908559095591055911559125591355914559155591655917559185591955920559215592255923559245592555926559275592855929559305593155932559335593455935559365593755938559395594055941559425594355944559455594655947559485594955950559515595255953559545595555956559575595855959559605596155962559635596455965559665596755968559695597055971559725597355974559755597655977559785597955980559815598255983559845598555986559875598855989559905599155992559935599455995559965599755998559995600056001560025600356004560055600656007560085600956010560115601256013560145601556016560175601856019560205602156022560235602456025560265602756028560295603056031560325603356034560355603656037560385603956040560415604256043560445604556046560475604856049560505605156052560535605456055560565605756058560595606056061560625606356064560655606656067560685606956070560715607256073560745607556076560775607856079560805608156082560835608456085560865608756088560895609056091560925609356094560955609656097560985609956100561015610256103561045610556106561075610856109561105611156112561135611456115561165611756118561195612056121561225612356124561255612656127561285612956130561315613256133561345613556136561375613856139561405614156142561435614456145561465614756148561495615056151561525615356154561555615656157561585615956160561615616256163561645616556166561675616856169561705617156172561735617456175561765617756178561795618056181561825618356184561855618656187561885618956190561915619256193561945619556196561975619856199562005620156202562035620456205562065620756208562095621056211562125621356214562155621656217562185621956220562215622256223562245622556226562275622856229562305623156232562335623456235562365623756238562395624056241562425624356244562455624656247562485624956250562515625256253562545625556256562575625856259562605626156262562635626456265562665626756268562695627056271562725627356274562755627656277562785627956280562815628256283562845628556286562875628856289562905629156292562935629456295562965629756298562995630056301563025630356304563055630656307563085630956310563115631256313563145631556316563175631856319563205632156322563235632456325563265632756328563295633056331563325633356334563355633656337563385633956340563415634256343563445634556346563475634856349563505635156352563535635456355563565635756358563595636056361563625636356364563655636656367563685636956370563715637256373563745637556376563775637856379563805638156382563835638456385563865638756388563895639056391563925639356394563955639656397563985639956400564015640256403564045640556406564075640856409564105641156412564135641456415564165641756418564195642056421564225642356424564255642656427564285642956430564315643256433564345643556436564375643856439564405644156442564435644456445564465644756448564495645056451564525645356454564555645656457564585645956460564615646256463564645646556466564675646856469564705647156472564735647456475564765647756478564795648056481564825648356484564855648656487564885648956490564915649256493564945649556496564975649856499565005650156502565035650456505565065650756508565095651056511565125651356514565155651656517565185651956520565215652256523565245652556526565275652856529565305653156532565335653456535565365653756538565395654056541565425654356544565455654656547565485654956550565515655256553565545655556556565575655856559565605656156562565635656456565565665656756568565695657056571565725657356574565755657656577565785657956580565815658256583565845658556586565875658856589565905659156592565935659456595565965659756598565995660056601566025660356604566055660656607566085660956610566115661256613566145661556616566175661856619566205662156622566235662456625566265662756628566295663056631566325663356634566355663656637566385663956640566415664256643566445664556646566475664856649566505665156652566535665456655566565665756658566595666056661566625666356664566655666656667566685666956670566715667256673566745667556676566775667856679566805668156682566835668456685566865668756688566895669056691566925669356694566955669656697566985669956700567015670256703567045670556706567075670856709567105671156712567135671456715567165671756718567195672056721567225672356724567255672656727567285672956730567315673256733567345673556736567375673856739567405674156742567435674456745567465674756748567495675056751567525675356754567555675656757567585675956760567615676256763567645676556766567675676856769567705677156772567735677456775567765677756778567795678056781567825678356784567855678656787567885678956790567915679256793567945679556796567975679856799568005680156802568035680456805568065680756808568095681056811568125681356814568155681656817568185681956820568215682256823568245682556826568275682856829568305683156832568335683456835568365683756838568395684056841568425684356844568455684656847568485684956850568515685256853568545685556856568575685856859568605686156862568635686456865568665686756868568695687056871568725687356874568755687656877568785687956880568815688256883568845688556886568875688856889568905689156892568935689456895568965689756898568995690056901569025690356904569055690656907569085690956910569115691256913569145691556916569175691856919569205692156922569235692456925569265692756928569295693056931569325693356934569355693656937569385693956940569415694256943569445694556946569475694856949569505695156952569535695456955569565695756958569595696056961569625696356964569655696656967569685696956970569715697256973569745697556976569775697856979569805698156982569835698456985569865698756988569895699056991569925699356994569955699656997569985699957000570015700257003570045700557006570075700857009570105701157012570135701457015570165701757018570195702057021570225702357024570255702657027570285702957030570315703257033570345703557036570375703857039570405704157042570435704457045570465704757048570495705057051570525705357054570555705657057570585705957060570615706257063570645706557066570675706857069570705707157072570735707457075570765707757078570795708057081570825708357084570855708657087570885708957090570915709257093570945709557096570975709857099571005710157102571035710457105571065710757108571095711057111571125711357114571155711657117571185711957120571215712257123571245712557126571275712857129571305713157132571335713457135571365713757138571395714057141571425714357144571455714657147571485714957150571515715257153571545715557156571575715857159571605716157162571635716457165571665716757168571695717057171571725717357174571755717657177571785717957180571815718257183571845718557186571875718857189571905719157192571935719457195571965719757198571995720057201572025720357204572055720657207572085720957210572115721257213572145721557216572175721857219572205722157222572235722457225572265722757228572295723057231572325723357234572355723657237572385723957240572415724257243572445724557246572475724857249572505725157252572535725457255572565725757258572595726057261572625726357264572655726657267572685726957270572715727257273572745727557276572775727857279572805728157282572835728457285572865728757288572895729057291572925729357294572955729657297572985729957300573015730257303573045730557306573075730857309573105731157312573135731457315573165731757318573195732057321573225732357324573255732657327573285732957330573315733257333573345733557336573375733857339573405734157342573435734457345573465734757348573495735057351573525735357354573555735657357573585735957360573615736257363573645736557366573675736857369573705737157372573735737457375573765737757378573795738057381573825738357384573855738657387573885738957390573915739257393573945739557396573975739857399574005740157402574035740457405574065740757408574095741057411574125741357414574155741657417574185741957420574215742257423574245742557426574275742857429574305743157432574335743457435574365743757438574395744057441574425744357444574455744657447574485744957450574515745257453574545745557456574575745857459574605746157462574635746457465574665746757468574695747057471574725747357474574755747657477574785747957480574815748257483574845748557486574875748857489574905749157492574935749457495574965749757498574995750057501575025750357504575055750657507575085750957510575115751257513575145751557516575175751857519575205752157522575235752457525575265752757528575295753057531575325753357534575355753657537575385753957540575415754257543575445754557546575475754857549575505755157552575535755457555575565755757558575595756057561575625756357564575655756657567575685756957570575715757257573575745757557576575775757857579575805758157582575835758457585575865758757588575895759057591575925759357594575955759657597575985759957600576015760257603576045760557606576075760857609576105761157612576135761457615576165761757618576195762057621576225762357624576255762657627576285762957630576315763257633576345763557636576375763857639576405764157642576435764457645576465764757648576495765057651576525765357654576555765657657576585765957660576615766257663576645766557666576675766857669576705767157672576735767457675576765767757678576795768057681576825768357684576855768657687576885768957690576915769257693576945769557696576975769857699577005770157702577035770457705577065770757708577095771057711577125771357714577155771657717577185771957720577215772257723577245772557726577275772857729577305773157732577335773457735577365773757738577395774057741577425774357744577455774657747577485774957750577515775257753577545775557756577575775857759577605776157762577635776457765577665776757768577695777057771577725777357774577755777657777577785777957780577815778257783577845778557786577875778857789577905779157792577935779457795577965779757798577995780057801578025780357804578055780657807578085780957810578115781257813578145781557816578175781857819578205782157822578235782457825578265782757828578295783057831578325783357834578355783657837578385783957840578415784257843578445784557846578475784857849578505785157852578535785457855578565785757858578595786057861578625786357864578655786657867578685786957870578715787257873578745787557876578775787857879578805788157882578835788457885578865788757888578895789057891578925789357894578955789657897578985789957900579015790257903579045790557906579075790857909579105791157912579135791457915579165791757918579195792057921579225792357924579255792657927579285792957930579315793257933579345793557936579375793857939579405794157942579435794457945579465794757948579495795057951579525795357954579555795657957579585795957960579615796257963579645796557966579675796857969579705797157972579735797457975579765797757978579795798057981579825798357984579855798657987579885798957990579915799257993579945799557996579975799857999580005800158002580035800458005580065800758008580095801058011580125801358014580155801658017580185801958020580215802258023580245802558026580275802858029580305803158032580335803458035580365803758038580395804058041580425804358044580455804658047580485804958050580515805258053580545805558056580575805858059580605806158062580635806458065580665806758068580695807058071580725807358074580755807658077580785807958080580815808258083580845808558086580875808858089580905809158092580935809458095580965809758098580995810058101581025810358104581055810658107581085810958110581115811258113581145811558116581175811858119581205812158122581235812458125581265812758128581295813058131581325813358134581355813658137581385813958140581415814258143581445814558146581475814858149581505815158152581535815458155581565815758158581595816058161581625816358164581655816658167581685816958170581715817258173581745817558176581775817858179581805818158182581835818458185581865818758188581895819058191581925819358194581955819658197581985819958200582015820258203582045820558206582075820858209582105821158212582135821458215582165821758218582195822058221582225822358224582255822658227582285822958230582315823258233582345823558236582375823858239582405824158242582435824458245582465824758248582495825058251582525825358254582555825658257582585825958260582615826258263582645826558266582675826858269582705827158272582735827458275582765827758278582795828058281582825828358284582855828658287582885828958290582915829258293582945829558296582975829858299583005830158302583035830458305583065830758308583095831058311583125831358314583155831658317583185831958320583215832258323583245832558326583275832858329583305833158332583335833458335583365833758338583395834058341583425834358344583455834658347583485834958350583515835258353583545835558356583575835858359583605836158362583635836458365583665836758368583695837058371583725837358374583755837658377583785837958380583815838258383583845838558386583875838858389583905839158392583935839458395583965839758398583995840058401584025840358404584055840658407584085840958410584115841258413584145841558416584175841858419584205842158422584235842458425584265842758428584295843058431584325843358434584355843658437584385843958440584415844258443584445844558446584475844858449584505845158452584535845458455584565845758458584595846058461584625846358464584655846658467584685846958470584715847258473584745847558476584775847858479584805848158482584835848458485584865848758488584895849058491584925849358494584955849658497584985849958500585015850258503585045850558506585075850858509585105851158512585135851458515585165851758518585195852058521585225852358524585255852658527585285852958530585315853258533585345853558536585375853858539585405854158542585435854458545585465854758548585495855058551585525855358554585555855658557585585855958560585615856258563585645856558566585675856858569585705857158572585735857458575585765857758578585795858058581585825858358584585855858658587585885858958590585915859258593585945859558596585975859858599586005860158602586035860458605586065860758608586095861058611586125861358614586155861658617586185861958620586215862258623586245862558626586275862858629586305863158632586335863458635586365863758638586395864058641586425864358644586455864658647586485864958650586515865258653586545865558656586575865858659586605866158662586635866458665586665866758668586695867058671586725867358674586755867658677586785867958680586815868258683586845868558686586875868858689586905869158692586935869458695586965869758698586995870058701587025870358704587055870658707587085870958710587115871258713587145871558716587175871858719587205872158722587235872458725587265872758728587295873058731587325873358734587355873658737587385873958740587415874258743587445874558746587475874858749587505875158752587535875458755587565875758758587595876058761587625876358764587655876658767587685876958770587715877258773587745877558776587775877858779587805878158782587835878458785587865878758788587895879058791587925879358794587955879658797587985879958800588015880258803588045880558806588075880858809588105881158812588135881458815588165881758818588195882058821588225882358824588255882658827588285882958830588315883258833588345883558836588375883858839588405884158842588435884458845588465884758848588495885058851588525885358854588555885658857588585885958860588615886258863588645886558866588675886858869588705887158872588735887458875588765887758878588795888058881588825888358884588855888658887588885888958890588915889258893588945889558896588975889858899589005890158902589035890458905589065890758908589095891058911589125891358914589155891658917589185891958920589215892258923589245892558926589275892858929589305893158932589335893458935589365893758938589395894058941589425894358944589455894658947589485894958950589515895258953589545895558956589575895858959589605896158962589635896458965589665896758968589695897058971589725897358974589755897658977589785897958980589815898258983589845898558986589875898858989589905899158992589935899458995589965899758998589995900059001590025900359004590055900659007590085900959010590115901259013590145901559016590175901859019590205902159022590235902459025590265902759028590295903059031590325903359034590355903659037590385903959040590415904259043590445904559046590475904859049590505905159052590535905459055590565905759058590595906059061590625906359064590655906659067590685906959070590715907259073590745907559076590775907859079590805908159082590835908459085590865908759088590895909059091590925909359094590955909659097590985909959100591015910259103591045910559106591075910859109591105911159112591135911459115591165911759118591195912059121591225912359124591255912659127591285912959130591315913259133591345913559136591375913859139591405914159142591435914459145591465914759148591495915059151591525915359154591555915659157591585915959160591615916259163591645916559166591675916859169591705917159172591735917459175591765917759178591795918059181591825918359184591855918659187591885918959190591915919259193591945919559196591975919859199592005920159202592035920459205592065920759208592095921059211592125921359214592155921659217592185921959220592215922259223592245922559226592275922859229592305923159232592335923459235592365923759238592395924059241592425924359244592455924659247592485924959250592515925259253592545925559256592575925859259592605926159262592635926459265592665926759268592695927059271592725927359274592755927659277592785927959280592815928259283592845928559286592875928859289592905929159292592935929459295592965929759298592995930059301593025930359304593055930659307593085930959310593115931259313593145931559316593175931859319593205932159322593235932459325593265932759328593295933059331593325933359334593355933659337593385933959340593415934259343593445934559346593475934859349593505935159352593535935459355593565935759358593595936059361593625936359364593655936659367593685936959370593715937259373593745937559376593775937859379593805938159382593835938459385593865938759388593895939059391593925939359394593955939659397593985939959400594015940259403594045940559406594075940859409594105941159412594135941459415594165941759418594195942059421594225942359424594255942659427594285942959430594315943259433594345943559436594375943859439594405944159442594435944459445594465944759448594495945059451594525945359454594555945659457594585945959460594615946259463594645946559466594675946859469594705947159472594735947459475594765947759478594795948059481594825948359484594855948659487594885948959490594915949259493594945949559496594975949859499595005950159502595035950459505595065950759508595095951059511595125951359514595155951659517595185951959520595215952259523595245952559526595275952859529595305953159532595335953459535595365953759538595395954059541595425954359544595455954659547595485954959550595515955259553595545955559556595575955859559595605956159562595635956459565595665956759568595695957059571595725957359574595755957659577595785957959580595815958259583595845958559586595875958859589595905959159592595935959459595595965959759598595995960059601596025960359604596055960659607596085960959610596115961259613596145961559616596175961859619596205962159622596235962459625596265962759628596295963059631596325963359634596355963659637596385963959640596415964259643596445964559646596475964859649596505965159652596535965459655596565965759658596595966059661596625966359664596655966659667596685966959670596715967259673596745967559676596775967859679596805968159682596835968459685596865968759688596895969059691596925969359694596955969659697596985969959700597015970259703597045970559706597075970859709597105971159712597135971459715597165971759718597195972059721597225972359724597255972659727597285972959730597315973259733597345973559736597375973859739597405974159742597435974459745597465974759748597495975059751597525975359754597555975659757597585975959760597615976259763597645976559766597675976859769597705977159772597735977459775597765977759778597795978059781597825978359784597855978659787597885978959790597915979259793597945979559796597975979859799598005980159802598035980459805598065980759808598095981059811598125981359814598155981659817598185981959820598215982259823598245982559826598275982859829598305983159832598335983459835598365983759838598395984059841598425984359844598455984659847598485984959850598515985259853598545985559856598575985859859598605986159862598635986459865598665986759868598695987059871598725987359874598755987659877598785987959880598815988259883598845988559886598875988859889598905989159892598935989459895598965989759898598995990059901599025990359904599055990659907599085990959910599115991259913599145991559916599175991859919599205992159922599235992459925599265992759928599295993059931599325993359934599355993659937599385993959940599415994259943599445994559946599475994859949599505995159952599535995459955599565995759958599595996059961599625996359964599655996659967599685996959970599715997259973599745997559976599775997859979599805998159982599835998459985599865998759988599895999059991599925999359994599955999659997599985999960000600016000260003600046000560006600076000860009600106001160012600136001460015600166001760018600196002060021600226002360024600256002660027600286002960030600316003260033600346003560036600376003860039600406004160042600436004460045600466004760048600496005060051600526005360054600556005660057600586005960060600616006260063600646006560066600676006860069600706007160072600736007460075600766007760078600796008060081600826008360084600856008660087600886008960090600916009260093600946009560096600976009860099601006010160102601036010460105601066010760108601096011060111601126011360114601156011660117601186011960120601216012260123601246012560126601276012860129601306013160132601336013460135601366013760138601396014060141601426014360144601456014660147601486014960150601516015260153601546015560156601576015860159601606016160162601636016460165601666016760168601696017060171601726017360174601756017660177601786017960180601816018260183601846018560186601876018860189601906019160192601936019460195601966019760198601996020060201602026020360204602056020660207602086020960210602116021260213602146021560216602176021860219602206022160222602236022460225602266022760228602296023060231602326023360234602356023660237602386023960240602416024260243602446024560246602476024860249602506025160252602536025460255602566025760258602596026060261602626026360264602656026660267602686026960270602716027260273602746027560276602776027860279602806028160282602836028460285602866028760288602896029060291602926029360294602956029660297602986029960300603016030260303603046030560306603076030860309603106031160312603136031460315603166031760318603196032060321603226032360324603256032660327603286032960330603316033260333603346033560336603376033860339603406034160342603436034460345603466034760348603496035060351603526035360354603556035660357603586035960360603616036260363603646036560366603676036860369603706037160372603736037460375603766037760378603796038060381603826038360384603856038660387603886038960390603916039260393603946039560396603976039860399604006040160402604036040460405604066040760408604096041060411604126041360414604156041660417604186041960420604216042260423604246042560426604276042860429604306043160432604336043460435604366043760438604396044060441604426044360444604456044660447604486044960450604516045260453604546045560456604576045860459604606046160462604636046460465604666046760468604696047060471604726047360474604756047660477604786047960480604816048260483604846048560486604876048860489604906049160492604936049460495604966049760498604996050060501605026050360504605056050660507605086050960510605116051260513605146051560516605176051860519605206052160522605236052460525605266052760528605296053060531605326053360534605356053660537605386053960540605416054260543605446054560546605476054860549605506055160552605536055460555605566055760558605596056060561605626056360564605656056660567605686056960570605716057260573605746057560576605776057860579605806058160582605836058460585605866058760588605896059060591605926059360594605956059660597605986059960600606016060260603606046060560606606076060860609606106061160612606136061460615606166061760618606196062060621606226062360624606256062660627606286062960630606316063260633606346063560636606376063860639606406064160642606436064460645606466064760648606496065060651606526065360654606556065660657606586065960660606616066260663606646066560666606676066860669606706067160672606736067460675606766067760678606796068060681606826068360684606856068660687606886068960690606916069260693606946069560696606976069860699607006070160702607036070460705607066070760708607096071060711607126071360714607156071660717607186071960720607216072260723607246072560726607276072860729607306073160732607336073460735607366073760738607396074060741607426074360744607456074660747607486074960750607516075260753607546075560756607576075860759607606076160762607636076460765607666076760768607696077060771607726077360774607756077660777607786077960780607816078260783607846078560786607876078860789607906079160792607936079460795607966079760798607996080060801608026080360804608056080660807608086080960810608116081260813608146081560816608176081860819608206082160822608236082460825608266082760828608296083060831608326083360834608356083660837608386083960840608416084260843608446084560846608476084860849608506085160852608536085460855608566085760858608596086060861608626086360864608656086660867608686086960870608716087260873608746087560876608776087860879608806088160882608836088460885608866088760888608896089060891608926089360894608956089660897608986089960900609016090260903609046090560906609076090860909609106091160912609136091460915609166091760918609196092060921609226092360924609256092660927609286092960930609316093260933609346093560936609376093860939609406094160942609436094460945609466094760948609496095060951609526095360954609556095660957609586095960960609616096260963609646096560966609676096860969609706097160972609736097460975609766097760978609796098060981609826098360984609856098660987609886098960990609916099260993609946099560996609976099860999610006100161002610036100461005610066100761008610096101061011610126101361014610156101661017610186101961020610216102261023610246102561026610276102861029610306103161032610336103461035610366103761038610396104061041610426104361044610456104661047610486104961050610516105261053610546105561056610576105861059610606106161062610636106461065610666106761068610696107061071610726107361074610756107661077610786107961080610816108261083610846108561086610876108861089610906109161092610936109461095610966109761098610996110061101611026110361104611056110661107611086110961110611116111261113611146111561116611176111861119611206112161122611236112461125611266112761128611296113061131611326113361134611356113661137611386113961140611416114261143611446114561146611476114861149611506115161152611536115461155611566115761158611596116061161611626116361164611656116661167611686116961170611716117261173611746117561176611776117861179611806118161182611836118461185611866118761188611896119061191611926119361194611956119661197611986119961200612016120261203612046120561206612076120861209612106121161212612136121461215612166121761218612196122061221612226122361224612256122661227612286122961230612316123261233612346123561236612376123861239612406124161242612436124461245612466124761248612496125061251612526125361254612556125661257612586125961260612616126261263612646126561266612676126861269612706127161272612736127461275612766127761278612796128061281612826128361284612856128661287612886128961290612916129261293612946129561296612976129861299613006130161302613036130461305613066130761308613096131061311613126131361314613156131661317613186131961320613216132261323613246132561326613276132861329613306133161332613336133461335613366133761338613396134061341613426134361344613456134661347613486134961350613516135261353613546135561356613576135861359613606136161362613636136461365613666136761368613696137061371613726137361374613756137661377613786137961380613816138261383613846138561386613876138861389613906139161392613936139461395613966139761398613996140061401614026140361404614056140661407614086140961410614116141261413614146141561416614176141861419614206142161422614236142461425614266142761428614296143061431614326143361434614356143661437614386143961440614416144261443614446144561446614476144861449614506145161452614536145461455614566145761458614596146061461614626146361464614656146661467614686146961470614716147261473614746147561476614776147861479614806148161482614836148461485614866148761488614896149061491614926149361494614956149661497614986149961500615016150261503615046150561506615076150861509615106151161512615136151461515615166151761518615196152061521615226152361524615256152661527615286152961530615316153261533615346153561536615376153861539615406154161542615436154461545615466154761548615496155061551615526155361554615556155661557615586155961560615616156261563615646156561566615676156861569615706157161572615736157461575615766157761578615796158061581615826158361584615856158661587615886158961590615916159261593615946159561596615976159861599616006160161602616036160461605616066160761608616096161061611616126161361614616156161661617616186161961620616216162261623616246162561626616276162861629616306163161632616336163461635616366163761638616396164061641616426164361644616456164661647616486164961650616516165261653616546165561656616576165861659616606166161662616636166461665616666166761668616696167061671616726167361674616756167661677616786167961680616816168261683616846168561686616876168861689616906169161692616936169461695616966169761698616996170061701617026170361704617056170661707617086170961710617116171261713617146171561716617176171861719617206172161722617236172461725617266172761728617296173061731617326173361734617356173661737617386173961740617416174261743617446174561746617476174861749617506175161752617536175461755617566175761758617596176061761617626176361764617656176661767617686176961770617716177261773617746177561776617776177861779617806178161782617836178461785617866178761788617896179061791617926179361794617956179661797617986179961800618016180261803618046180561806618076180861809618106181161812618136181461815618166181761818618196182061821618226182361824618256182661827618286182961830618316183261833618346183561836618376183861839618406184161842618436184461845618466184761848618496185061851618526185361854618556185661857618586185961860618616186261863618646186561866618676186861869618706187161872618736187461875618766187761878618796188061881618826188361884618856188661887618886188961890618916189261893618946189561896618976189861899619006190161902619036190461905619066190761908619096191061911619126191361914619156191661917619186191961920619216192261923619246192561926619276192861929619306193161932619336193461935619366193761938619396194061941619426194361944619456194661947619486194961950619516195261953619546195561956619576195861959619606196161962619636196461965619666196761968619696197061971619726197361974619756197661977619786197961980619816198261983619846198561986619876198861989619906199161992619936199461995619966199761998619996200062001620026200362004620056200662007620086200962010620116201262013620146201562016620176201862019620206202162022620236202462025620266202762028620296203062031620326203362034620356203662037620386203962040620416204262043620446204562046620476204862049620506205162052620536205462055620566205762058620596206062061620626206362064620656206662067620686206962070620716207262073620746207562076620776207862079620806208162082620836208462085620866208762088620896209062091620926209362094620956209662097620986209962100621016210262103621046210562106621076210862109621106211162112621136211462115621166211762118621196212062121621226212362124621256212662127621286212962130621316213262133621346213562136621376213862139621406214162142621436214462145621466214762148621496215062151621526215362154621556215662157621586215962160621616216262163621646216562166621676216862169621706217162172621736217462175621766217762178621796218062181621826218362184621856218662187621886218962190621916219262193621946219562196621976219862199622006220162202622036220462205622066220762208622096221062211622126221362214622156221662217622186221962220622216222262223622246222562226622276222862229622306223162232622336223462235622366223762238622396224062241622426224362244622456224662247622486224962250622516225262253622546225562256622576225862259622606226162262622636226462265622666226762268622696227062271622726227362274622756227662277622786227962280622816228262283622846228562286622876228862289622906229162292622936229462295622966229762298622996230062301623026230362304623056230662307623086230962310623116231262313623146231562316623176231862319623206232162322623236232462325623266232762328623296233062331623326233362334623356233662337623386233962340623416234262343623446234562346623476234862349623506235162352623536235462355623566235762358623596236062361623626236362364623656236662367623686236962370623716237262373623746237562376623776237862379623806238162382623836238462385623866238762388623896239062391623926239362394623956239662397623986239962400624016240262403624046240562406624076240862409624106241162412624136241462415624166241762418624196242062421624226242362424624256242662427624286242962430624316243262433624346243562436624376243862439624406244162442624436244462445624466244762448624496245062451624526245362454624556245662457624586245962460624616246262463624646246562466624676246862469624706247162472624736247462475624766247762478624796248062481624826248362484624856248662487624886248962490624916249262493624946249562496624976249862499625006250162502625036250462505625066250762508625096251062511625126251362514625156251662517625186251962520625216252262523625246252562526625276252862529625306253162532625336253462535625366253762538625396254062541625426254362544625456254662547625486254962550625516255262553625546255562556625576255862559625606256162562625636256462565625666256762568625696257062571625726257362574625756257662577625786257962580625816258262583625846258562586625876258862589625906259162592625936259462595625966259762598625996260062601626026260362604626056260662607626086260962610626116261262613626146261562616626176261862619626206262162622626236262462625626266262762628626296263062631626326263362634626356263662637626386263962640626416264262643626446264562646626476264862649626506265162652626536265462655626566265762658626596266062661626626266362664626656266662667626686266962670626716267262673626746267562676626776267862679626806268162682626836268462685626866268762688626896269062691626926269362694626956269662697626986269962700627016270262703627046270562706627076270862709627106271162712627136271462715627166271762718627196272062721627226272362724627256272662727627286272962730627316273262733627346273562736627376273862739627406274162742627436274462745627466274762748627496275062751627526275362754627556275662757627586275962760627616276262763627646276562766627676276862769627706277162772627736277462775627766277762778627796278062781627826278362784627856278662787627886278962790627916279262793627946279562796627976279862799628006280162802628036280462805628066280762808628096281062811628126281362814628156281662817628186281962820628216282262823628246282562826628276282862829628306283162832628336283462835628366283762838628396284062841628426284362844628456284662847628486284962850628516285262853628546285562856628576285862859628606286162862628636286462865628666286762868628696287062871628726287362874628756287662877628786287962880628816288262883628846288562886628876288862889628906289162892628936289462895628966289762898628996290062901629026290362904629056290662907629086290962910629116291262913629146291562916629176291862919629206292162922629236292462925629266292762928629296293062931629326293362934629356293662937629386293962940629416294262943629446294562946629476294862949629506295162952629536295462955629566295762958629596296062961629626296362964629656296662967629686296962970629716297262973629746297562976629776297862979629806298162982629836298462985629866298762988629896299062991629926299362994629956299662997629986299963000630016300263003630046300563006630076300863009630106301163012630136301463015630166301763018630196302063021630226302363024630256302663027630286302963030630316303263033630346303563036630376303863039630406304163042630436304463045630466304763048630496305063051630526305363054630556305663057630586305963060630616306263063630646306563066630676306863069630706307163072630736307463075630766307763078630796308063081630826308363084630856308663087630886308963090630916309263093630946309563096630976309863099631006310163102631036310463105631066310763108631096311063111631126311363114631156311663117631186311963120631216312263123631246312563126631276312863129631306313163132631336313463135631366313763138631396314063141631426314363144631456314663147631486314963150631516315263153631546315563156631576315863159631606316163162631636316463165631666316763168631696317063171631726317363174631756317663177631786317963180631816318263183631846318563186631876318863189631906319163192631936319463195631966319763198631996320063201632026320363204632056320663207632086320963210632116321263213632146321563216632176321863219632206322163222632236322463225632266322763228632296323063231632326323363234632356323663237632386323963240632416324263243632446324563246632476324863249632506325163252632536325463255632566325763258632596326063261632626326363264632656326663267632686326963270632716327263273632746327563276632776327863279632806328163282632836328463285632866328763288632896329063291632926329363294632956329663297632986329963300633016330263303633046330563306633076330863309633106331163312633136331463315633166331763318633196332063321633226332363324633256332663327633286332963330633316333263333633346333563336633376333863339633406334163342633436334463345633466334763348633496335063351633526335363354633556335663357633586335963360633616336263363633646336563366633676336863369633706337163372633736337463375633766337763378633796338063381633826338363384633856338663387633886338963390633916339263393633946339563396633976339863399634006340163402634036340463405634066340763408634096341063411634126341363414634156341663417634186341963420634216342263423634246342563426634276342863429634306343163432634336343463435634366343763438634396344063441634426344363444634456344663447634486344963450634516345263453634546345563456634576345863459634606346163462634636346463465634666346763468634696347063471634726347363474634756347663477634786347963480634816348263483634846348563486634876348863489634906349163492634936349463495634966349763498634996350063501635026350363504635056350663507635086350963510635116351263513635146351563516635176351863519635206352163522635236352463525635266352763528635296353063531635326353363534635356353663537635386353963540635416354263543635446354563546635476354863549635506355163552635536355463555635566355763558635596356063561635626356363564635656356663567635686356963570635716357263573635746357563576635776357863579635806358163582635836358463585635866358763588635896359063591635926359363594635956359663597635986359963600636016360263603636046360563606636076360863609636106361163612636136361463615636166361763618636196362063621636226362363624636256362663627636286362963630636316363263633636346363563636636376363863639636406364163642636436364463645636466364763648636496365063651636526365363654636556365663657636586365963660636616366263663636646366563666636676366863669636706367163672636736367463675636766367763678636796368063681636826368363684636856368663687636886368963690636916369263693636946369563696636976369863699637006370163702637036370463705637066370763708637096371063711637126371363714637156371663717637186371963720637216372263723637246372563726637276372863729637306373163732637336373463735637366373763738637396374063741637426374363744637456374663747637486374963750637516375263753637546375563756637576375863759637606376163762637636376463765637666376763768637696377063771637726377363774637756377663777637786377963780637816378263783637846378563786637876378863789637906379163792637936379463795637966379763798637996380063801638026380363804638056380663807638086380963810638116381263813638146381563816638176381863819638206382163822638236382463825638266382763828638296383063831638326383363834638356383663837638386383963840638416384263843638446384563846638476384863849638506385163852638536385463855638566385763858638596386063861638626386363864638656386663867638686386963870638716387263873638746387563876638776387863879638806388163882638836388463885638866388763888638896389063891638926389363894638956389663897638986389963900639016390263903639046390563906639076390863909639106391163912639136391463915639166391763918639196392063921639226392363924639256392663927639286392963930639316393263933639346393563936639376393863939639406394163942639436394463945639466394763948639496395063951639526395363954639556395663957639586395963960639616396263963639646396563966639676396863969639706397163972639736397463975639766397763978639796398063981639826398363984639856398663987639886398963990639916399263993639946399563996639976399863999640006400164002640036400464005640066400764008640096401064011640126401364014640156401664017640186401964020640216402264023640246402564026640276402864029640306403164032640336403464035640366403764038640396404064041640426404364044640456404664047640486404964050640516405264053640546405564056640576405864059640606406164062640636406464065640666406764068640696407064071640726407364074640756407664077640786407964080640816408264083640846408564086640876408864089640906409164092640936409464095640966409764098640996410064101641026410364104641056410664107641086410964110641116411264113641146411564116641176411864119641206412164122641236412464125641266412764128641296413064131641326413364134641356413664137641386413964140641416414264143641446414564146641476414864149641506415164152641536415464155641566415764158641596416064161641626416364164641656416664167641686416964170641716417264173641746417564176641776417864179641806418164182641836418464185641866418764188641896419064191641926419364194641956419664197641986419964200642016420264203642046420564206642076420864209642106421164212642136421464215642166421764218642196422064221642226422364224642256422664227642286422964230642316423264233642346423564236642376423864239642406424164242642436424464245642466424764248642496425064251642526425364254642556425664257642586425964260642616426264263642646426564266642676426864269642706427164272642736427464275642766427764278642796428064281642826428364284642856428664287642886428964290642916429264293642946429564296642976429864299643006430164302643036430464305643066430764308643096431064311643126431364314643156431664317643186431964320643216432264323643246432564326643276432864329643306433164332643336433464335643366433764338643396434064341643426434364344643456434664347643486434964350643516435264353643546435564356643576435864359643606436164362643636436464365643666436764368643696437064371643726437364374643756437664377643786437964380643816438264383643846438564386643876438864389643906439164392643936439464395643966439764398643996440064401644026440364404644056440664407644086440964410644116441264413644146441564416644176441864419644206442164422644236442464425644266442764428644296443064431644326443364434644356443664437644386443964440644416444264443644446444564446644476444864449644506445164452644536445464455644566445764458644596446064461644626446364464644656446664467644686446964470644716447264473644746447564476644776447864479644806448164482644836448464485644866448764488644896449064491644926449364494644956449664497644986449964500645016450264503645046450564506645076450864509645106451164512645136451464515645166451764518645196452064521645226452364524645256452664527645286452964530645316453264533645346453564536645376453864539645406454164542645436454464545645466454764548645496455064551645526455364554645556455664557645586455964560645616456264563645646456564566645676456864569645706457164572645736457464575645766457764578645796458064581645826458364584645856458664587645886458964590645916459264593645946459564596645976459864599646006460164602646036460464605646066460764608646096461064611646126461364614646156461664617646186461964620646216462264623646246462564626646276462864629646306463164632646336463464635646366463764638646396464064641646426464364644646456464664647646486464964650646516465264653646546465564656646576465864659646606466164662646636466464665646666466764668646696467064671646726467364674646756467664677646786467964680646816468264683646846468564686646876468864689646906469164692646936469464695646966469764698646996470064701647026470364704647056470664707647086470964710647116471264713647146471564716647176471864719647206472164722647236472464725647266472764728647296473064731647326473364734647356473664737647386473964740647416474264743647446474564746647476474864749647506475164752647536475464755647566475764758647596476064761647626476364764647656476664767647686476964770647716477264773647746477564776647776477864779647806478164782647836478464785647866478764788647896479064791647926479364794647956479664797647986479964800648016480264803648046480564806648076480864809648106481164812648136481464815648166481764818648196482064821648226482364824648256482664827648286482964830648316483264833648346483564836648376483864839648406484164842648436484464845648466484764848648496485064851648526485364854648556485664857648586485964860648616486264863648646486564866648676486864869648706487164872648736487464875648766487764878648796488064881648826488364884648856488664887648886488964890648916489264893648946489564896648976489864899649006490164902649036490464905649066490764908649096491064911649126491364914649156491664917649186491964920649216492264923649246492564926649276492864929649306493164932649336493464935649366493764938649396494064941649426494364944649456494664947649486494964950649516495264953649546495564956649576495864959649606496164962649636496464965649666496764968649696497064971649726497364974649756497664977649786497964980649816498264983649846498564986649876498864989649906499164992649936499464995649966499764998649996500065001650026500365004650056500665007650086500965010650116501265013650146501565016650176501865019650206502165022650236502465025650266502765028650296503065031650326503365034650356503665037650386503965040650416504265043650446504565046650476504865049650506505165052650536505465055650566505765058650596506065061650626506365064650656506665067650686506965070650716507265073650746507565076650776507865079650806508165082650836508465085650866508765088650896509065091650926509365094650956509665097650986509965100651016510265103651046510565106651076510865109651106511165112651136511465115651166511765118651196512065121651226512365124651256512665127651286512965130651316513265133651346513565136651376513865139651406514165142651436514465145651466514765148651496515065151651526515365154651556515665157651586515965160651616516265163651646516565166651676516865169651706517165172651736517465175651766517765178651796518065181651826518365184651856518665187651886518965190651916519265193651946519565196651976519865199652006520165202652036520465205652066520765208652096521065211652126521365214652156521665217652186521965220652216522265223652246522565226652276522865229652306523165232652336523465235652366523765238652396524065241652426524365244652456524665247652486524965250652516525265253652546525565256652576525865259652606526165262652636526465265652666526765268652696527065271652726527365274652756527665277652786527965280652816528265283652846528565286652876528865289652906529165292652936529465295652966529765298652996530065301653026530365304653056530665307653086530965310653116531265313653146531565316653176531865319653206532165322653236532465325653266532765328653296533065331653326533365334653356533665337653386533965340653416534265343653446534565346653476534865349653506535165352653536535465355653566535765358653596536065361653626536365364653656536665367653686536965370653716537265373653746537565376653776537865379653806538165382653836538465385653866538765388653896539065391653926539365394653956539665397653986539965400654016540265403654046540565406654076540865409654106541165412654136541465415654166541765418654196542065421654226542365424654256542665427654286542965430654316543265433654346543565436654376543865439654406544165442654436544465445654466544765448654496545065451654526545365454654556545665457654586545965460654616546265463654646546565466654676546865469654706547165472654736547465475654766547765478654796548065481654826548365484654856548665487654886548965490654916549265493654946549565496654976549865499655006550165502655036550465505655066550765508655096551065511655126551365514655156551665517655186551965520655216552265523655246552565526655276552865529655306553165532655336553465535655366553765538655396554065541655426554365544655456554665547655486554965550655516555265553655546555565556655576555865559655606556165562655636556465565655666556765568655696557065571655726557365574655756557665577655786557965580655816558265583655846558565586655876558865589655906559165592655936559465595655966559765598655996560065601656026560365604656056560665607656086560965610656116561265613656146561565616656176561865619656206562165622656236562465625656266562765628656296563065631656326563365634656356563665637656386563965640656416564265643656446564565646656476564865649656506565165652656536565465655656566565765658656596566065661656626566365664656656566665667656686566965670656716567265673656746567565676656776567865679656806568165682656836568465685656866568765688656896569065691656926569365694656956569665697656986569965700657016570265703657046570565706657076570865709657106571165712657136571465715657166571765718657196572065721657226572365724657256572665727657286572965730657316573265733657346573565736657376573865739657406574165742657436574465745657466574765748657496575065751657526575365754657556575665757657586575965760657616576265763657646576565766657676576865769657706577165772657736577465775657766577765778657796578065781657826578365784657856578665787657886578965790657916579265793657946579565796657976579865799658006580165802658036580465805658066580765808658096581065811658126581365814658156581665817658186581965820658216582265823658246582565826658276582865829658306583165832658336583465835658366583765838658396584065841658426584365844658456584665847658486584965850658516585265853658546585565856658576585865859658606586165862658636586465865658666586765868658696587065871658726587365874658756587665877658786587965880658816588265883658846588565886658876588865889658906589165892658936589465895658966589765898658996590065901659026590365904659056590665907659086590965910659116591265913659146591565916659176591865919659206592165922659236592465925659266592765928659296593065931659326593365934659356593665937659386593965940659416594265943659446594565946659476594865949659506595165952659536595465955659566595765958659596596065961659626596365964659656596665967659686596965970659716597265973659746597565976659776597865979659806598165982659836598465985659866598765988659896599065991659926599365994659956599665997659986599966000660016600266003660046600566006660076600866009660106601166012660136601466015660166601766018660196602066021660226602366024660256602666027660286602966030660316603266033660346603566036660376603866039660406604166042660436604466045660466604766048660496605066051660526605366054660556605666057660586605966060660616606266063660646606566066660676606866069660706607166072660736607466075660766607766078660796608066081660826608366084660856608666087660886608966090660916609266093660946609566096660976609866099661006610166102661036610466105661066610766108661096611066111661126611366114661156611666117661186611966120661216612266123661246612566126661276612866129661306613166132661336613466135661366613766138661396614066141661426614366144661456614666147661486614966150661516615266153661546615566156661576615866159661606616166162661636616466165661666616766168661696617066171661726617366174661756617666177661786617966180661816618266183661846618566186661876618866189661906619166192661936619466195661966619766198661996620066201662026620366204662056620666207662086620966210662116621266213662146621566216662176621866219662206622166222662236622466225662266622766228662296623066231662326623366234662356623666237662386623966240662416624266243662446624566246662476624866249662506625166252662536625466255662566625766258662596626066261662626626366264662656626666267662686626966270662716627266273662746627566276662776627866279662806628166282662836628466285662866628766288662896629066291662926629366294662956629666297662986629966300663016630266303663046630566306663076630866309663106631166312663136631466315663166631766318663196632066321663226632366324663256632666327663286632966330663316633266333663346633566336663376633866339663406634166342663436634466345663466634766348663496635066351663526635366354663556635666357663586635966360663616636266363663646636566366663676636866369663706637166372663736637466375663766637766378663796638066381663826638366384663856638666387663886638966390663916639266393663946639566396663976639866399664006640166402664036640466405664066640766408664096641066411664126641366414664156641666417664186641966420664216642266423664246642566426664276642866429664306643166432664336643466435664366643766438664396644066441664426644366444664456644666447664486644966450664516645266453664546645566456664576645866459664606646166462664636646466465664666646766468664696647066471664726647366474664756647666477664786647966480664816648266483664846648566486664876648866489664906649166492664936649466495664966649766498664996650066501665026650366504665056650666507665086650966510665116651266513665146651566516665176651866519665206652166522665236652466525665266652766528665296653066531665326653366534665356653666537665386653966540665416654266543665446654566546665476654866549665506655166552665536655466555665566655766558665596656066561665626656366564665656656666567665686656966570665716657266573665746657566576665776657866579665806658166582665836658466585665866658766588665896659066591665926659366594665956659666597665986659966600666016660266603666046660566606666076660866609666106661166612666136661466615666166661766618666196662066621666226662366624666256662666627666286662966630666316663266633666346663566636666376663866639666406664166642666436664466645666466664766648666496665066651666526665366654666556665666657666586665966660666616666266663666646666566666666676666866669666706667166672666736667466675666766667766678666796668066681666826668366684666856668666687666886668966690666916669266693666946669566696666976669866699667006670166702667036670466705667066670766708667096671066711667126671366714667156671666717667186671966720667216672266723667246672566726667276672866729667306673166732667336673466735667366673766738667396674066741667426674366744667456674666747667486674966750667516675266753667546675566756667576675866759667606676166762667636676466765667666676766768667696677066771667726677366774667756677666777667786677966780667816678266783667846678566786667876678866789667906679166792667936679466795667966679766798667996680066801668026680366804668056680666807668086680966810668116681266813668146681566816668176681866819668206682166822668236682466825668266682766828668296683066831668326683366834668356683666837668386683966840668416684266843668446684566846668476684866849668506685166852668536685466855668566685766858668596686066861668626686366864668656686666867668686686966870668716687266873668746687566876668776687866879668806688166882668836688466885668866688766888668896689066891668926689366894668956689666897668986689966900669016690266903669046690566906669076690866909669106691166912669136691466915669166691766918669196692066921669226692366924669256692666927669286692966930669316693266933669346693566936669376693866939669406694166942669436694466945669466694766948669496695066951669526695366954669556695666957669586695966960669616696266963669646696566966669676696866969669706697166972669736697466975669766697766978669796698066981669826698366984669856698666987669886698966990669916699266993669946699566996669976699866999670006700167002670036700467005670066700767008670096701067011670126701367014670156701667017670186701967020670216702267023670246702567026670276702867029670306703167032670336703467035670366703767038670396704067041670426704367044670456704667047670486704967050670516705267053670546705567056670576705867059670606706167062670636706467065670666706767068670696707067071670726707367074670756707667077670786707967080670816708267083670846708567086670876708867089670906709167092670936709467095670966709767098670996710067101671026710367104671056710667107671086710967110671116711267113671146711567116671176711867119671206712167122671236712467125671266712767128671296713067131671326713367134671356713667137671386713967140671416714267143671446714567146671476714867149671506715167152671536715467155671566715767158671596716067161671626716367164671656716667167671686716967170671716717267173671746717567176671776717867179671806718167182671836718467185671866718767188671896719067191671926719367194671956719667197671986719967200672016720267203672046720567206672076720867209672106721167212672136721467215672166721767218672196722067221672226722367224672256722667227672286722967230672316723267233672346723567236672376723867239672406724167242672436724467245672466724767248672496725067251672526725367254672556725667257672586725967260672616726267263672646726567266672676726867269672706727167272672736727467275672766727767278672796728067281672826728367284672856728667287672886728967290672916729267293672946729567296672976729867299673006730167302673036730467305673066730767308673096731067311673126731367314673156731667317673186731967320673216732267323673246732567326673276732867329673306733167332673336733467335673366733767338673396734067341673426734367344673456734667347673486734967350673516735267353673546735567356673576735867359673606736167362673636736467365673666736767368673696737067371673726737367374673756737667377673786737967380673816738267383673846738567386673876738867389673906739167392673936739467395673966739767398673996740067401674026740367404674056740667407674086740967410674116741267413674146741567416674176741867419674206742167422674236742467425674266742767428674296743067431674326743367434674356743667437674386743967440674416744267443674446744567446674476744867449674506745167452674536745467455674566745767458674596746067461674626746367464674656746667467674686746967470674716747267473674746747567476674776747867479674806748167482674836748467485674866748767488674896749067491674926749367494674956749667497674986749967500675016750267503675046750567506675076750867509675106751167512675136751467515675166751767518675196752067521675226752367524675256752667527675286752967530675316753267533675346753567536675376753867539675406754167542675436754467545675466754767548675496755067551675526755367554675556755667557675586755967560675616756267563675646756567566675676756867569675706757167572675736757467575675766757767578675796758067581675826758367584675856758667587675886758967590675916759267593675946759567596675976759867599676006760167602676036760467605676066760767608676096761067611676126761367614676156761667617676186761967620676216762267623676246762567626676276762867629676306763167632676336763467635676366763767638676396764067641676426764367644676456764667647676486764967650676516765267653676546765567656676576765867659676606766167662676636766467665676666766767668676696767067671676726767367674676756767667677676786767967680676816768267683676846768567686676876768867689676906769167692676936769467695676966769767698676996770067701677026770367704677056770667707677086770967710677116771267713677146771567716677176771867719677206772167722677236772467725677266772767728677296773067731677326773367734677356773667737677386773967740677416774267743677446774567746677476774867749677506775167752677536775467755677566775767758677596776067761677626776367764677656776667767677686776967770677716777267773677746777567776677776777867779677806778167782677836778467785677866778767788677896779067791677926779367794677956779667797677986779967800678016780267803678046780567806678076780867809678106781167812678136781467815678166781767818678196782067821678226782367824678256782667827678286782967830678316783267833678346783567836678376783867839678406784167842678436784467845678466784767848678496785067851678526785367854678556785667857678586785967860678616786267863678646786567866678676786867869678706787167872678736787467875678766787767878678796788067881678826788367884678856788667887678886788967890678916789267893678946789567896678976789867899679006790167902679036790467905679066790767908679096791067911679126791367914679156791667917679186791967920679216792267923679246792567926679276792867929679306793167932679336793467935679366793767938679396794067941679426794367944679456794667947679486794967950679516795267953679546795567956679576795867959679606796167962679636796467965679666796767968679696797067971679726797367974679756797667977679786797967980679816798267983679846798567986679876798867989679906799167992679936799467995679966799767998679996800068001680026800368004680056800668007680086800968010680116801268013680146801568016680176801868019680206802168022680236802468025680266802768028680296803068031680326803368034680356803668037680386803968040680416804268043680446804568046680476804868049680506805168052680536805468055680566805768058680596806068061680626806368064680656806668067680686806968070680716807268073680746807568076680776807868079680806808168082680836808468085680866808768088680896809068091680926809368094680956809668097680986809968100681016810268103681046810568106681076810868109681106811168112681136811468115681166811768118681196812068121681226812368124681256812668127681286812968130681316813268133681346813568136681376813868139681406814168142681436814468145681466814768148681496815068151681526815368154681556815668157681586815968160681616816268163681646816568166681676816868169681706817168172681736817468175681766817768178681796818068181681826818368184681856818668187681886818968190681916819268193681946819568196681976819868199682006820168202682036820468205682066820768208682096821068211682126821368214682156821668217682186821968220682216822268223682246822568226682276822868229682306823168232682336823468235682366823768238682396824068241682426824368244682456824668247682486824968250682516825268253682546825568256682576825868259682606826168262682636826468265682666826768268682696827068271682726827368274682756827668277682786827968280682816828268283682846828568286682876828868289682906829168292682936829468295682966829768298682996830068301683026830368304683056830668307683086830968310683116831268313683146831568316683176831868319683206832168322683236832468325683266832768328683296833068331683326833368334683356833668337683386833968340683416834268343683446834568346683476834868349683506835168352683536835468355683566835768358683596836068361683626836368364683656836668367683686836968370683716837268373683746837568376683776837868379683806838168382683836838468385683866838768388683896839068391683926839368394683956839668397683986839968400684016840268403684046840568406684076840868409684106841168412684136841468415684166841768418684196842068421684226842368424684256842668427684286842968430684316843268433684346843568436684376843868439684406844168442684436844468445684466844768448684496845068451684526845368454684556845668457684586845968460684616846268463684646846568466684676846868469684706847168472684736847468475684766847768478684796848068481684826848368484684856848668487684886848968490684916849268493684946849568496684976849868499685006850168502685036850468505685066850768508685096851068511685126851368514685156851668517685186851968520685216852268523685246852568526685276852868529685306853168532685336853468535685366853768538685396854068541685426854368544685456854668547685486854968550685516855268553685546855568556685576855868559685606856168562685636856468565685666856768568685696857068571685726857368574685756857668577685786857968580685816858268583685846858568586685876858868589685906859168592685936859468595685966859768598685996860068601686026860368604686056860668607686086860968610686116861268613686146861568616686176861868619686206862168622686236862468625686266862768628686296863068631686326863368634686356863668637686386863968640686416864268643686446864568646686476864868649686506865168652686536865468655686566865768658686596866068661686626866368664686656866668667686686866968670686716867268673686746867568676686776867868679686806868168682686836868468685686866868768688686896869068691686926869368694686956869668697686986869968700687016870268703687046870568706687076870868709687106871168712687136871468715687166871768718687196872068721687226872368724687256872668727687286872968730687316873268733687346873568736687376873868739687406874168742687436874468745687466874768748687496875068751687526875368754687556875668757687586875968760687616876268763687646876568766687676876868769687706877168772687736877468775687766877768778687796878068781687826878368784687856878668787687886878968790687916879268793687946879568796687976879868799688006880168802688036880468805688066880768808688096881068811688126881368814688156881668817688186881968820688216882268823688246882568826688276882868829688306883168832688336883468835688366883768838688396884068841688426884368844688456884668847688486884968850688516885268853688546885568856688576885868859688606886168862688636886468865688666886768868688696887068871688726887368874688756887668877688786887968880688816888268883688846888568886688876888868889688906889168892688936889468895688966889768898688996890068901689026890368904689056890668907689086890968910689116891268913689146891568916689176891868919689206892168922689236892468925689266892768928689296893068931689326893368934689356893668937689386893968940689416894268943689446894568946689476894868949689506895168952689536895468955689566895768958689596896068961689626896368964689656896668967689686896968970689716897268973689746897568976689776897868979689806898168982689836898468985689866898768988689896899068991689926899368994689956899668997689986899969000690016900269003690046900569006690076900869009690106901169012690136901469015690166901769018690196902069021690226902369024690256902669027690286902969030690316903269033690346903569036690376903869039690406904169042690436904469045690466904769048690496905069051690526905369054690556905669057690586905969060690616906269063690646906569066690676906869069690706907169072690736907469075690766907769078690796908069081690826908369084690856908669087690886908969090690916909269093690946909569096690976909869099691006910169102691036910469105691066910769108691096911069111691126911369114691156911669117691186911969120691216912269123691246912569126691276912869129691306913169132691336913469135691366913769138691396914069141691426914369144691456914669147691486914969150691516915269153691546915569156691576915869159691606916169162691636916469165691666916769168691696917069171691726917369174691756917669177691786917969180691816918269183691846918569186691876918869189691906919169192691936919469195691966919769198691996920069201692026920369204692056920669207692086920969210692116921269213692146921569216692176921869219692206922169222692236922469225692266922769228692296923069231692326923369234692356923669237692386923969240692416924269243692446924569246692476924869249692506925169252692536925469255692566925769258692596926069261692626926369264692656926669267692686926969270692716927269273692746927569276692776927869279692806928169282692836928469285692866928769288692896929069291692926929369294692956929669297692986929969300693016930269303693046930569306693076930869309693106931169312693136931469315693166931769318693196932069321693226932369324693256932669327693286932969330693316933269333693346933569336693376933869339693406934169342693436934469345693466934769348693496935069351693526935369354693556935669357693586935969360693616936269363693646936569366693676936869369693706937169372693736937469375693766937769378693796938069381693826938369384693856938669387693886938969390693916939269393693946939569396693976939869399694006940169402694036940469405694066940769408694096941069411694126941369414694156941669417694186941969420694216942269423694246942569426694276942869429694306943169432694336943469435694366943769438694396944069441694426944369444694456944669447694486944969450694516945269453694546945569456694576945869459694606946169462694636946469465694666946769468694696947069471694726947369474694756947669477694786947969480694816948269483694846948569486694876948869489694906949169492694936949469495694966949769498694996950069501695026950369504695056950669507695086950969510695116951269513695146951569516695176951869519695206952169522695236952469525695266952769528695296953069531695326953369534695356953669537695386953969540695416954269543695446954569546695476954869549695506955169552695536955469555695566955769558695596956069561695626956369564695656956669567695686956969570695716957269573695746957569576695776957869579695806958169582695836958469585695866958769588695896959069591695926959369594695956959669597695986959969600696016960269603696046960569606696076960869609696106961169612696136961469615696166961769618696196962069621696226962369624696256962669627696286962969630696316963269633696346963569636696376963869639696406964169642696436964469645696466964769648696496965069651696526965369654696556965669657696586965969660696616966269663696646966569666696676966869669696706967169672696736967469675696766967769678696796968069681696826968369684696856968669687696886968969690696916969269693696946969569696696976969869699697006970169702697036970469705697066970769708697096971069711697126971369714697156971669717697186971969720697216972269723697246972569726697276972869729697306973169732697336973469735697366973769738697396974069741697426974369744697456974669747697486974969750697516975269753697546975569756697576975869759697606976169762697636976469765697666976769768697696977069771697726977369774697756977669777697786977969780697816978269783697846978569786697876978869789697906979169792697936979469795697966979769798697996980069801698026980369804698056980669807698086980969810698116981269813698146981569816698176981869819698206982169822698236982469825698266982769828698296983069831698326983369834698356983669837698386983969840698416984269843698446984569846698476984869849698506985169852698536985469855698566985769858698596986069861698626986369864698656986669867698686986969870698716987269873698746987569876698776987869879698806988169882698836988469885698866988769888698896989069891698926989369894698956989669897698986989969900699016990269903699046990569906699076990869909699106991169912699136991469915699166991769918699196992069921699226992369924699256992669927699286992969930699316993269933699346993569936699376993869939699406994169942699436994469945699466994769948699496995069951699526995369954699556995669957699586995969960699616996269963699646996569966699676996869969699706997169972699736997469975699766997769978699796998069981699826998369984699856998669987699886998969990699916999269993699946999569996699976999869999700007000170002700037000470005700067000770008700097001070011700127001370014700157001670017700187001970020700217002270023700247002570026700277002870029700307003170032700337003470035700367003770038700397004070041700427004370044700457004670047700487004970050700517005270053700547005570056700577005870059700607006170062700637006470065700667006770068700697007070071700727007370074700757007670077700787007970080700817008270083700847008570086700877008870089700907009170092700937009470095700967009770098700997010070101701027010370104701057010670107701087010970110701117011270113701147011570116701177011870119701207012170122701237012470125701267012770128701297013070131701327013370134701357013670137701387013970140701417014270143701447014570146701477014870149701507015170152701537015470155701567015770158701597016070161701627016370164701657016670167701687016970170701717017270173701747017570176701777017870179701807018170182701837018470185701867018770188701897019070191701927019370194701957019670197701987019970200702017020270203702047020570206702077020870209702107021170212702137021470215702167021770218702197022070221702227022370224702257022670227702287022970230702317023270233702347023570236702377023870239702407024170242702437024470245702467024770248702497025070251702527025370254702557025670257702587025970260702617026270263702647026570266702677026870269702707027170272702737027470275702767027770278702797028070281702827028370284702857028670287702887028970290702917029270293702947029570296702977029870299703007030170302703037030470305703067030770308703097031070311703127031370314703157031670317703187031970320703217032270323703247032570326703277032870329703307033170332703337033470335703367033770338703397034070341703427034370344703457034670347703487034970350703517035270353703547035570356703577035870359703607036170362703637036470365703667036770368703697037070371703727037370374703757037670377703787037970380703817038270383703847038570386703877038870389703907039170392703937039470395703967039770398703997040070401704027040370404704057040670407704087040970410704117041270413704147041570416704177041870419704207042170422704237042470425704267042770428704297043070431704327043370434704357043670437704387043970440704417044270443704447044570446704477044870449704507045170452704537045470455704567045770458704597046070461704627046370464704657046670467704687046970470704717047270473704747047570476704777047870479704807048170482704837048470485704867048770488704897049070491704927049370494704957049670497704987049970500705017050270503705047050570506705077050870509705107051170512705137051470515705167051770518705197052070521705227052370524705257052670527705287052970530705317053270533705347053570536705377053870539705407054170542705437054470545705467054770548705497055070551705527055370554705557055670557705587055970560705617056270563705647056570566705677056870569705707057170572705737057470575705767057770578705797058070581705827058370584705857058670587705887058970590705917059270593705947059570596705977059870599706007060170602706037060470605706067060770608706097061070611706127061370614706157061670617706187061970620706217062270623706247062570626706277062870629706307063170632706337063470635706367063770638706397064070641706427064370644706457064670647706487064970650706517065270653706547065570656706577065870659706607066170662706637066470665706667066770668706697067070671706727067370674706757067670677706787067970680706817068270683706847068570686706877068870689706907069170692706937069470695706967069770698706997070070701707027070370704707057070670707707087070970710707117071270713707147071570716707177071870719707207072170722707237072470725707267072770728707297073070731707327073370734707357073670737707387073970740707417074270743707447074570746707477074870749707507075170752707537075470755707567075770758707597076070761707627076370764707657076670767707687076970770707717077270773707747077570776707777077870779707807078170782707837078470785707867078770788707897079070791707927079370794707957079670797707987079970800708017080270803708047080570806708077080870809708107081170812708137081470815708167081770818708197082070821708227082370824708257082670827708287082970830708317083270833708347083570836708377083870839708407084170842708437084470845708467084770848708497085070851708527085370854708557085670857708587085970860708617086270863708647086570866708677086870869708707087170872708737087470875708767087770878708797088070881708827088370884708857088670887708887088970890708917089270893708947089570896708977089870899709007090170902709037090470905709067090770908709097091070911709127091370914709157091670917709187091970920709217092270923709247092570926709277092870929709307093170932709337093470935709367093770938709397094070941709427094370944709457094670947709487094970950709517095270953709547095570956709577095870959709607096170962709637096470965709667096770968709697097070971709727097370974709757097670977709787097970980709817098270983709847098570986709877098870989709907099170992709937099470995709967099770998709997100071001710027100371004710057100671007710087100971010710117101271013710147101571016710177101871019710207102171022710237102471025710267102771028710297103071031710327103371034710357103671037710387103971040710417104271043710447104571046710477104871049710507105171052710537105471055710567105771058710597106071061710627106371064710657106671067710687106971070710717107271073710747107571076710777107871079710807108171082710837108471085710867108771088710897109071091710927109371094710957109671097710987109971100711017110271103711047110571106711077110871109711107111171112711137111471115711167111771118711197112071121711227112371124711257112671127711287112971130711317113271133711347113571136711377113871139711407114171142711437114471145711467114771148711497115071151711527115371154711557115671157711587115971160711617116271163711647116571166711677116871169711707117171172711737117471175711767117771178711797118071181711827118371184711857118671187711887118971190711917119271193711947119571196711977119871199712007120171202712037120471205712067120771208712097121071211712127121371214712157121671217712187121971220712217122271223712247122571226712277122871229712307123171232712337123471235712367123771238712397124071241712427124371244712457124671247712487124971250712517125271253712547125571256712577125871259712607126171262712637126471265712667126771268712697127071271712727127371274712757127671277712787127971280712817128271283712847128571286712877128871289712907129171292712937129471295712967129771298712997130071301713027130371304713057130671307713087130971310713117131271313713147131571316713177131871319713207132171322713237132471325713267132771328713297133071331713327133371334713357133671337713387133971340713417134271343713447134571346713477134871349713507135171352713537135471355713567135771358713597136071361713627136371364713657136671367713687136971370713717137271373713747137571376713777137871379713807138171382713837138471385713867138771388713897139071391713927139371394713957139671397713987139971400714017140271403714047140571406714077140871409714107141171412714137141471415714167141771418714197142071421714227142371424714257142671427714287142971430714317143271433714347143571436714377143871439714407144171442714437144471445714467144771448714497145071451714527145371454714557145671457714587145971460714617146271463714647146571466714677146871469714707147171472714737147471475714767147771478714797148071481714827148371484714857148671487714887148971490714917149271493714947149571496714977149871499715007150171502715037150471505715067150771508715097151071511715127151371514715157151671517715187151971520715217152271523715247152571526715277152871529715307153171532715337153471535715367153771538715397154071541715427154371544715457154671547715487154971550715517155271553715547155571556715577155871559715607156171562715637156471565715667156771568715697157071571715727157371574715757157671577715787157971580715817158271583715847158571586715877158871589715907159171592715937159471595715967159771598715997160071601716027160371604716057160671607716087160971610716117161271613716147161571616716177161871619716207162171622716237162471625716267162771628716297163071631716327163371634716357163671637716387163971640716417164271643716447164571646716477164871649716507165171652716537165471655716567165771658716597166071661716627166371664716657166671667716687166971670716717167271673716747167571676716777167871679716807168171682716837168471685716867168771688716897169071691716927169371694716957169671697716987169971700717017170271703717047170571706717077170871709717107171171712717137171471715717167171771718717197172071721717227172371724717257172671727717287172971730717317173271733717347173571736717377173871739717407174171742717437174471745717467174771748717497175071751717527175371754717557175671757717587175971760717617176271763717647176571766717677176871769717707177171772717737177471775717767177771778717797178071781717827178371784717857178671787717887178971790717917179271793717947179571796717977179871799718007180171802718037180471805718067180771808718097181071811718127181371814718157181671817718187181971820718217182271823718247182571826718277182871829718307183171832718337183471835718367183771838718397184071841718427184371844718457184671847718487184971850718517185271853718547185571856718577185871859718607186171862718637186471865718667186771868718697187071871718727187371874718757187671877718787187971880718817188271883718847188571886718877188871889718907189171892718937189471895718967189771898718997190071901719027190371904719057190671907719087190971910719117191271913719147191571916719177191871919719207192171922719237192471925719267192771928719297193071931719327193371934719357193671937719387193971940719417194271943719447194571946719477194871949719507195171952719537195471955719567195771958719597196071961719627196371964719657196671967719687196971970719717197271973719747197571976719777197871979719807198171982719837198471985719867198771988719897199071991719927199371994719957199671997719987199972000720017200272003720047200572006720077200872009720107201172012720137201472015720167201772018720197202072021720227202372024720257202672027720287202972030720317203272033720347203572036720377203872039720407204172042720437204472045720467204772048720497205072051720527205372054720557205672057720587205972060720617206272063720647206572066720677206872069720707207172072720737207472075720767207772078720797208072081720827208372084720857208672087720887208972090720917209272093720947209572096720977209872099721007210172102721037210472105721067210772108721097211072111721127211372114721157211672117721187211972120721217212272123721247212572126721277212872129721307213172132721337213472135721367213772138721397214072141721427214372144721457214672147721487214972150721517215272153721547215572156721577215872159721607216172162721637216472165721667216772168721697217072171721727217372174721757217672177721787217972180721817218272183721847218572186721877218872189721907219172192721937219472195721967219772198721997220072201722027220372204722057220672207722087220972210722117221272213722147221572216722177221872219722207222172222722237222472225722267222772228722297223072231722327223372234722357223672237722387223972240722417224272243722447224572246722477224872249722507225172252722537225472255722567225772258722597226072261722627226372264722657226672267722687226972270722717227272273722747227572276722777227872279722807228172282722837228472285722867228772288722897229072291722927229372294722957229672297722987229972300723017230272303723047230572306723077230872309723107231172312723137231472315723167231772318723197232072321723227232372324723257232672327723287232972330723317233272333723347233572336723377233872339723407234172342723437234472345723467234772348723497235072351723527235372354723557235672357723587235972360723617236272363723647236572366723677236872369723707237172372723737237472375723767237772378723797238072381723827238372384723857238672387723887238972390723917239272393723947239572396723977239872399724007240172402724037240472405724067240772408724097241072411724127241372414724157241672417724187241972420724217242272423724247242572426724277242872429724307243172432724337243472435724367243772438724397244072441724427244372444724457244672447724487244972450724517245272453724547245572456724577245872459724607246172462724637246472465724667246772468724697247072471724727247372474724757247672477724787247972480724817248272483724847248572486724877248872489724907249172492724937249472495724967249772498724997250072501725027250372504725057250672507725087250972510725117251272513725147251572516725177251872519725207252172522725237252472525725267252772528725297253072531725327253372534725357253672537725387253972540725417254272543725447254572546725477254872549725507255172552725537255472555725567255772558725597256072561725627256372564725657256672567725687256972570725717257272573725747257572576725777257872579725807258172582725837258472585725867258772588725897259072591725927259372594725957259672597725987259972600726017260272603726047260572606726077260872609726107261172612726137261472615726167261772618726197262072621726227262372624726257262672627726287262972630726317263272633726347263572636726377263872639726407264172642726437264472645726467264772648726497265072651726527265372654726557265672657726587265972660726617266272663726647266572666726677266872669726707267172672726737267472675726767267772678726797268072681726827268372684726857268672687726887268972690726917269272693726947269572696726977269872699727007270172702727037270472705727067270772708727097271072711727127271372714727157271672717727187271972720727217272272723727247272572726727277272872729727307273172732727337273472735727367273772738727397274072741727427274372744727457274672747727487274972750727517275272753727547275572756727577275872759727607276172762727637276472765727667276772768727697277072771727727277372774727757277672777727787277972780727817278272783727847278572786727877278872789727907279172792727937279472795727967279772798727997280072801728027280372804728057280672807728087280972810728117281272813728147281572816728177281872819728207282172822728237282472825728267282772828728297283072831728327283372834728357283672837728387283972840728417284272843728447284572846728477284872849728507285172852728537285472855728567285772858728597286072861728627286372864728657286672867728687286972870728717287272873728747287572876728777287872879728807288172882728837288472885728867288772888728897289072891728927289372894728957289672897728987289972900729017290272903729047290572906729077290872909729107291172912729137291472915729167291772918729197292072921729227292372924729257292672927729287292972930729317293272933729347293572936729377293872939729407294172942729437294472945729467294772948729497295072951729527295372954729557295672957729587295972960729617296272963729647296572966729677296872969729707297172972729737297472975729767297772978729797298072981729827298372984729857298672987729887298972990729917299272993729947299572996729977299872999730007300173002730037300473005730067300773008730097301073011730127301373014730157301673017730187301973020730217302273023730247302573026730277302873029730307303173032730337303473035730367303773038730397304073041730427304373044730457304673047730487304973050730517305273053730547305573056730577305873059730607306173062730637306473065730667306773068730697307073071730727307373074730757307673077730787307973080730817308273083730847308573086730877308873089730907309173092730937309473095730967309773098730997310073101731027310373104731057310673107731087310973110731117311273113731147311573116731177311873119731207312173122731237312473125731267312773128731297313073131731327313373134731357313673137731387313973140731417314273143731447314573146731477314873149731507315173152731537315473155731567315773158731597316073161731627316373164731657316673167731687316973170731717317273173731747317573176731777317873179731807318173182731837318473185731867318773188731897319073191731927319373194731957319673197731987319973200732017320273203732047320573206732077320873209732107321173212732137321473215732167321773218732197322073221732227322373224732257322673227732287322973230732317323273233732347323573236732377323873239732407324173242732437324473245732467324773248732497325073251732527325373254732557325673257732587325973260732617326273263732647326573266732677326873269732707327173272732737327473275732767327773278732797328073281732827328373284732857328673287732887328973290732917329273293732947329573296732977329873299733007330173302733037330473305733067330773308733097331073311733127331373314733157331673317733187331973320733217332273323733247332573326733277332873329733307333173332733337333473335733367333773338733397334073341733427334373344733457334673347733487334973350733517335273353733547335573356733577335873359733607336173362733637336473365733667336773368733697337073371733727337373374733757337673377733787337973380733817338273383733847338573386733877338873389733907339173392733937339473395733967339773398733997340073401734027340373404734057340673407734087340973410734117341273413734147341573416734177341873419734207342173422734237342473425734267342773428734297343073431734327343373434734357343673437734387343973440734417344273443734447344573446734477344873449734507345173452734537345473455734567345773458734597346073461734627346373464734657346673467734687346973470734717347273473734747347573476734777347873479734807348173482734837348473485734867348773488734897349073491734927349373494734957349673497734987349973500735017350273503735047350573506735077350873509735107351173512735137351473515735167351773518735197352073521735227352373524735257352673527735287352973530735317353273533735347353573536735377353873539735407354173542735437354473545735467354773548735497355073551735527355373554735557355673557735587355973560735617356273563735647356573566735677356873569735707357173572735737357473575735767357773578735797358073581735827358373584735857358673587735887358973590735917359273593735947359573596735977359873599736007360173602736037360473605736067360773608736097361073611736127361373614736157361673617736187361973620736217362273623736247362573626736277362873629736307363173632736337363473635736367363773638736397364073641736427364373644736457364673647736487364973650736517365273653736547365573656736577365873659736607366173662736637366473665736667366773668736697367073671736727367373674736757367673677736787367973680736817368273683736847368573686736877368873689736907369173692736937369473695736967369773698736997370073701737027370373704737057370673707737087370973710737117371273713737147371573716737177371873719737207372173722737237372473725737267372773728737297373073731737327373373734737357373673737737387373973740737417374273743737447374573746737477374873749737507375173752737537375473755737567375773758737597376073761737627376373764737657376673767737687376973770737717377273773737747377573776737777377873779737807378173782737837378473785737867378773788737897379073791737927379373794737957379673797737987379973800738017380273803738047380573806738077380873809738107381173812738137381473815738167381773818738197382073821738227382373824738257382673827738287382973830738317383273833738347383573836738377383873839738407384173842738437384473845738467384773848738497385073851738527385373854738557385673857738587385973860738617386273863738647386573866738677386873869738707387173872738737387473875738767387773878738797388073881738827388373884738857388673887738887388973890738917389273893738947389573896738977389873899739007390173902739037390473905739067390773908739097391073911739127391373914739157391673917739187391973920739217392273923739247392573926739277392873929739307393173932739337393473935739367393773938739397394073941739427394373944739457394673947739487394973950739517395273953739547395573956739577395873959739607396173962739637396473965739667396773968739697397073971739727397373974739757397673977739787397973980739817398273983739847398573986739877398873989739907399173992739937399473995739967399773998739997400074001740027400374004740057400674007740087400974010740117401274013740147401574016740177401874019740207402174022740237402474025740267402774028740297403074031740327403374034740357403674037740387403974040740417404274043740447404574046740477404874049740507405174052740537405474055740567405774058740597406074061740627406374064740657406674067740687406974070740717407274073740747407574076740777407874079740807408174082740837408474085740867408774088740897409074091740927409374094740957409674097740987409974100741017410274103741047410574106741077410874109741107411174112741137411474115741167411774118741197412074121741227412374124741257412674127741287412974130741317413274133741347413574136741377413874139741407414174142741437414474145741467414774148741497415074151741527415374154741557415674157741587415974160741617416274163741647416574166741677416874169741707417174172741737417474175741767417774178741797418074181741827418374184741857418674187741887418974190741917419274193741947419574196741977419874199742007420174202742037420474205742067420774208742097421074211742127421374214742157421674217742187421974220742217422274223742247422574226742277422874229742307423174232742337423474235742367423774238742397424074241742427424374244742457424674247742487424974250742517425274253742547425574256742577425874259742607426174262742637426474265742667426774268742697427074271742727427374274742757427674277742787427974280742817428274283742847428574286742877428874289742907429174292742937429474295742967429774298742997430074301743027430374304743057430674307743087430974310743117431274313743147431574316743177431874319743207432174322743237432474325743267432774328743297433074331743327433374334743357433674337743387433974340743417434274343743447434574346743477434874349743507435174352743537435474355743567435774358743597436074361743627436374364743657436674367743687436974370743717437274373743747437574376743777437874379743807438174382743837438474385743867438774388743897439074391743927439374394743957439674397743987439974400744017440274403744047440574406744077440874409744107441174412744137441474415744167441774418744197442074421744227442374424744257442674427744287442974430744317443274433744347443574436744377443874439744407444174442744437444474445744467444774448744497445074451744527445374454744557445674457744587445974460744617446274463744647446574466744677446874469744707447174472744737447474475744767447774478744797448074481744827448374484744857448674487744887448974490744917449274493744947449574496744977449874499745007450174502745037450474505745067450774508745097451074511745127451374514745157451674517745187451974520745217452274523745247452574526745277452874529745307453174532745337453474535745367453774538745397454074541745427454374544745457454674547745487454974550745517455274553745547455574556745577455874559745607456174562745637456474565745667456774568745697457074571745727457374574745757457674577745787457974580745817458274583745847458574586745877458874589745907459174592745937459474595745967459774598745997460074601746027460374604746057460674607746087460974610746117461274613746147461574616746177461874619746207462174622746237462474625746267462774628746297463074631746327463374634746357463674637746387463974640746417464274643746447464574646746477464874649746507465174652746537465474655746567465774658746597466074661746627466374664746657466674667746687466974670746717467274673746747467574676746777467874679746807468174682746837468474685746867468774688746897469074691746927469374694746957469674697746987469974700747017470274703747047470574706747077470874709747107471174712747137471474715747167471774718747197472074721747227472374724747257472674727747287472974730747317473274733747347473574736747377473874739747407474174742747437474474745747467474774748747497475074751747527475374754747557475674757747587475974760747617476274763747647476574766747677476874769747707477174772747737477474775747767477774778747797478074781747827478374784747857478674787747887478974790747917479274793747947479574796747977479874799748007480174802748037480474805748067480774808748097481074811748127481374814748157481674817748187481974820748217482274823748247482574826748277482874829748307483174832748337483474835748367483774838748397484074841748427484374844748457484674847748487484974850748517485274853748547485574856748577485874859748607486174862748637486474865748667486774868748697487074871748727487374874748757487674877748787487974880748817488274883748847488574886748877488874889748907489174892748937489474895748967489774898748997490074901749027490374904749057490674907749087490974910749117491274913749147491574916749177491874919749207492174922749237492474925749267492774928749297493074931749327493374934749357493674937749387493974940749417494274943749447494574946749477494874949749507495174952749537495474955749567495774958749597496074961749627496374964749657496674967749687496974970749717497274973749747497574976749777497874979749807498174982749837498474985749867498774988749897499074991749927499374994749957499674997749987499975000750017500275003750047500575006750077500875009750107501175012750137501475015750167501775018750197502075021750227502375024750257502675027750287502975030750317503275033750347503575036750377503875039750407504175042750437504475045750467504775048750497505075051750527505375054750557505675057750587505975060750617506275063750647506575066750677506875069750707507175072750737507475075750767507775078750797508075081750827508375084750857508675087750887508975090750917509275093750947509575096750977509875099751007510175102751037510475105751067510775108751097511075111751127511375114751157511675117751187511975120751217512275123751247512575126751277512875129751307513175132751337513475135751367513775138751397514075141751427514375144751457514675147751487514975150751517515275153751547515575156751577515875159751607516175162751637516475165751667516775168751697517075171751727517375174751757517675177751787517975180751817518275183751847518575186751877518875189751907519175192751937519475195751967519775198751997520075201752027520375204752057520675207752087520975210752117521275213752147521575216752177521875219752207522175222752237522475225752267522775228752297523075231752327523375234752357523675237752387523975240752417524275243752447524575246752477524875249752507525175252752537525475255752567525775258752597526075261752627526375264752657526675267752687526975270752717527275273752747527575276752777527875279752807528175282752837528475285752867528775288752897529075291752927529375294752957529675297752987529975300753017530275303753047530575306753077530875309753107531175312753137531475315753167531775318753197532075321753227532375324753257532675327753287532975330753317533275333753347533575336753377533875339753407534175342753437534475345753467534775348753497535075351753527535375354753557535675357753587535975360753617536275363753647536575366753677536875369753707537175372753737537475375753767537775378753797538075381753827538375384753857538675387753887538975390753917539275393753947539575396753977539875399754007540175402754037540475405754067540775408754097541075411754127541375414754157541675417754187541975420754217542275423754247542575426754277542875429754307543175432754337543475435754367543775438754397544075441754427544375444754457544675447754487544975450754517545275453754547545575456754577545875459754607546175462754637546475465754667546775468754697547075471754727547375474754757547675477754787547975480754817548275483754847548575486754877548875489754907549175492754937549475495754967549775498754997550075501755027550375504755057550675507755087550975510755117551275513755147551575516755177551875519755207552175522755237552475525755267552775528755297553075531755327553375534755357553675537755387553975540755417554275543755447554575546755477554875549755507555175552755537555475555755567555775558755597556075561755627556375564755657556675567755687556975570755717557275573755747557575576755777557875579755807558175582755837558475585755867558775588755897559075591755927559375594755957559675597755987559975600756017560275603756047560575606756077560875609756107561175612756137561475615756167561775618756197562075621756227562375624756257562675627756287562975630756317563275633756347563575636756377563875639756407564175642756437564475645756467564775648756497565075651756527565375654756557565675657756587565975660756617566275663756647566575666756677566875669756707567175672756737567475675756767567775678756797568075681756827568375684756857568675687756887568975690756917569275693756947569575696756977569875699757007570175702757037570475705757067570775708757097571075711757127571375714757157571675717757187571975720757217572275723757247572575726757277572875729757307573175732757337573475735757367573775738757397574075741757427574375744757457574675747757487574975750757517575275753757547575575756757577575875759757607576175762757637576475765757667576775768757697577075771757727577375774757757577675777757787577975780757817578275783757847578575786757877578875789757907579175792757937579475795757967579775798757997580075801758027580375804758057580675807758087580975810758117581275813758147581575816758177581875819758207582175822758237582475825758267582775828758297583075831758327583375834758357583675837758387583975840758417584275843758447584575846758477584875849758507585175852758537585475855758567585775858758597586075861758627586375864758657586675867758687586975870758717587275873758747587575876758777587875879758807588175882758837588475885758867588775888758897589075891758927589375894758957589675897758987589975900759017590275903759047590575906759077590875909759107591175912759137591475915759167591775918759197592075921759227592375924759257592675927759287592975930759317593275933759347593575936759377593875939759407594175942759437594475945759467594775948759497595075951759527595375954759557595675957759587595975960759617596275963759647596575966759677596875969759707597175972759737597475975759767597775978759797598075981759827598375984759857598675987759887598975990759917599275993759947599575996759977599875999760007600176002760037600476005760067600776008760097601076011760127601376014760157601676017760187601976020760217602276023760247602576026760277602876029760307603176032760337603476035760367603776038760397604076041760427604376044760457604676047760487604976050760517605276053760547605576056760577605876059760607606176062760637606476065760667606776068760697607076071760727607376074760757607676077760787607976080760817608276083760847608576086760877608876089760907609176092760937609476095760967609776098760997610076101761027610376104761057610676107761087610976110761117611276113761147611576116761177611876119761207612176122761237612476125761267612776128761297613076131761327613376134761357613676137761387613976140761417614276143761447614576146761477614876149761507615176152761537615476155761567615776158761597616076161761627616376164761657616676167761687616976170761717617276173761747617576176761777617876179761807618176182761837618476185761867618776188761897619076191761927619376194761957619676197761987619976200762017620276203762047620576206762077620876209762107621176212762137621476215762167621776218762197622076221762227622376224762257622676227762287622976230762317623276233762347623576236762377623876239762407624176242762437624476245762467624776248762497625076251762527625376254762557625676257762587625976260762617626276263762647626576266762677626876269762707627176272762737627476275762767627776278762797628076281762827628376284762857628676287762887628976290762917629276293762947629576296762977629876299763007630176302763037630476305763067630776308763097631076311763127631376314763157631676317763187631976320763217632276323763247632576326763277632876329763307633176332763337633476335763367633776338763397634076341763427634376344763457634676347763487634976350763517635276353763547635576356763577635876359763607636176362763637636476365763667636776368763697637076371763727637376374763757637676377763787637976380763817638276383763847638576386763877638876389763907639176392763937639476395763967639776398763997640076401764027640376404764057640676407764087640976410764117641276413764147641576416764177641876419764207642176422764237642476425764267642776428764297643076431764327643376434764357643676437764387643976440764417644276443764447644576446764477644876449764507645176452764537645476455764567645776458764597646076461764627646376464764657646676467764687646976470764717647276473764747647576476764777647876479764807648176482764837648476485764867648776488764897649076491764927649376494764957649676497764987649976500765017650276503765047650576506765077650876509765107651176512765137651476515765167651776518765197652076521765227652376524765257652676527765287652976530765317653276533765347653576536765377653876539765407654176542765437654476545765467654776548765497655076551765527655376554765557655676557765587655976560765617656276563765647656576566765677656876569765707657176572765737657476575765767657776578765797658076581765827658376584765857658676587765887658976590765917659276593765947659576596765977659876599766007660176602766037660476605766067660776608766097661076611766127661376614766157661676617766187661976620766217662276623766247662576626766277662876629766307663176632766337663476635766367663776638766397664076641766427664376644766457664676647766487664976650766517665276653766547665576656766577665876659766607666176662766637666476665766667666776668766697667076671766727667376674766757667676677766787667976680766817668276683766847668576686766877668876689766907669176692766937669476695766967669776698766997670076701767027670376704767057670676707767087670976710767117671276713767147671576716767177671876719767207672176722767237672476725767267672776728767297673076731767327673376734767357673676737767387673976740767417674276743767447674576746767477674876749767507675176752767537675476755767567675776758767597676076761767627676376764767657676676767767687676976770767717677276773767747677576776767777677876779767807678176782767837678476785767867678776788767897679076791767927679376794767957679676797767987679976800768017680276803768047680576806768077680876809768107681176812768137681476815768167681776818768197682076821768227682376824768257682676827768287682976830768317683276833768347683576836768377683876839768407684176842768437684476845768467684776848768497685076851768527685376854768557685676857768587685976860768617686276863768647686576866768677686876869768707687176872768737687476875768767687776878768797688076881768827688376884768857688676887768887688976890768917689276893768947689576896768977689876899769007690176902769037690476905769067690776908769097691076911769127691376914769157691676917769187691976920769217692276923769247692576926769277692876929769307693176932769337693476935769367693776938769397694076941769427694376944769457694676947769487694976950769517695276953769547695576956769577695876959769607696176962769637696476965769667696776968769697697076971769727697376974769757697676977769787697976980769817698276983769847698576986769877698876989769907699176992769937699476995769967699776998769997700077001770027700377004770057700677007770087700977010770117701277013770147701577016770177701877019770207702177022770237702477025770267702777028770297703077031770327703377034770357703677037770387703977040770417704277043770447704577046770477704877049770507705177052770537705477055770567705777058770597706077061770627706377064770657706677067770687706977070770717707277073770747707577076770777707877079770807708177082770837708477085770867708777088770897709077091770927709377094770957709677097770987709977100771017710277103771047710577106771077710877109771107711177112771137711477115771167711777118771197712077121771227712377124771257712677127771287712977130771317713277133771347713577136771377713877139771407714177142771437714477145771467714777148771497715077151771527715377154771557715677157771587715977160771617716277163771647716577166771677716877169771707717177172771737717477175771767717777178771797718077181771827718377184771857718677187771887718977190771917719277193771947719577196771977719877199772007720177202772037720477205772067720777208772097721077211772127721377214772157721677217772187721977220772217722277223772247722577226772277722877229772307723177232772337723477235772367723777238772397724077241772427724377244772457724677247772487724977250772517725277253772547725577256772577725877259772607726177262772637726477265772667726777268772697727077271772727727377274772757727677277772787727977280772817728277283772847728577286772877728877289772907729177292772937729477295772967729777298772997730077301773027730377304773057730677307773087730977310773117731277313773147731577316773177731877319773207732177322773237732477325773267732777328773297733077331773327733377334773357733677337773387733977340773417734277343773447734577346773477734877349773507735177352773537735477355773567735777358773597736077361773627736377364773657736677367773687736977370773717737277373773747737577376773777737877379773807738177382773837738477385773867738777388773897739077391773927739377394773957739677397773987739977400774017740277403774047740577406774077740877409774107741177412774137741477415774167741777418774197742077421774227742377424774257742677427774287742977430774317743277433774347743577436774377743877439774407744177442774437744477445774467744777448774497745077451774527745377454774557745677457774587745977460774617746277463774647746577466774677746877469774707747177472774737747477475774767747777478774797748077481774827748377484774857748677487774887748977490774917749277493774947749577496774977749877499775007750177502775037750477505775067750777508775097751077511775127751377514775157751677517775187751977520775217752277523775247752577526775277752877529775307753177532775337753477535775367753777538775397754077541775427754377544775457754677547775487754977550775517755277553775547755577556775577755877559775607756177562775637756477565775667756777568775697757077571775727757377574775757757677577775787757977580775817758277583775847758577586775877758877589775907759177592775937759477595775967759777598775997760077601776027760377604776057760677607776087760977610776117761277613776147761577616776177761877619776207762177622776237762477625776267762777628776297763077631776327763377634776357763677637776387763977640776417764277643776447764577646776477764877649776507765177652776537765477655776567765777658776597766077661776627766377664776657766677667776687766977670776717767277673776747767577676776777767877679776807768177682776837768477685776867768777688776897769077691776927769377694776957769677697776987769977700777017770277703777047770577706777077770877709777107771177712777137771477715777167771777718777197772077721777227772377724777257772677727777287772977730777317773277733777347773577736777377773877739777407774177742777437774477745777467774777748777497775077751777527775377754777557775677757777587775977760777617776277763777647776577766777677776877769777707777177772777737777477775777767777777778777797778077781777827778377784777857778677787777887778977790777917779277793777947779577796777977779877799778007780177802778037780477805778067780777808778097781077811778127781377814778157781677817778187781977820778217782277823778247782577826778277782877829778307783177832778337783477835778367783777838778397784077841778427784377844778457784677847778487784977850778517785277853778547785577856778577785877859778607786177862778637786477865778667786777868778697787077871778727787377874778757787677877778787787977880778817788277883778847788577886778877788877889778907789177892778937789477895778967789777898778997790077901779027790377904779057790677907779087790977910779117791277913779147791577916779177791877919779207792177922779237792477925779267792777928779297793077931779327793377934779357793677937779387793977940779417794277943779447794577946779477794877949779507795177952779537795477955779567795777958779597796077961779627796377964779657796677967779687796977970779717797277973779747797577976779777797877979779807798177982779837798477985779867798777988779897799077991779927799377994779957799677997779987799978000780017800278003780047800578006780077800878009780107801178012780137801478015780167801778018780197802078021780227802378024780257802678027780287802978030780317803278033780347803578036780377803878039780407804178042780437804478045780467804778048780497805078051780527805378054780557805678057780587805978060780617806278063780647806578066780677806878069780707807178072780737807478075780767807778078780797808078081780827808378084780857808678087780887808978090780917809278093780947809578096780977809878099781007810178102781037810478105781067810778108781097811078111781127811378114781157811678117781187811978120781217812278123781247812578126781277812878129781307813178132781337813478135781367813778138781397814078141781427814378144781457814678147781487814978150781517815278153781547815578156781577815878159781607816178162781637816478165781667816778168781697817078171781727817378174781757817678177781787817978180781817818278183781847818578186781877818878189781907819178192781937819478195781967819778198781997820078201782027820378204782057820678207782087820978210782117821278213782147821578216782177821878219782207822178222782237822478225782267822778228782297823078231782327823378234782357823678237782387823978240782417824278243782447824578246782477824878249782507825178252782537825478255782567825778258782597826078261782627826378264782657826678267782687826978270782717827278273782747827578276782777827878279782807828178282782837828478285782867828778288782897829078291782927829378294782957829678297782987829978300783017830278303783047830578306783077830878309783107831178312783137831478315783167831778318783197832078321783227832378324783257832678327783287832978330783317833278333783347833578336783377833878339783407834178342783437834478345783467834778348783497835078351783527835378354783557835678357783587835978360783617836278363783647836578366783677836878369783707837178372783737837478375783767837778378783797838078381783827838378384783857838678387783887838978390783917839278393783947839578396783977839878399784007840178402784037840478405784067840778408784097841078411784127841378414784157841678417784187841978420784217842278423784247842578426784277842878429784307843178432784337843478435784367843778438784397844078441784427844378444784457844678447784487844978450784517845278453784547845578456784577845878459784607846178462784637846478465784667846778468784697847078471784727847378474784757847678477784787847978480784817848278483784847848578486784877848878489784907849178492784937849478495784967849778498784997850078501785027850378504785057850678507785087850978510785117851278513785147851578516785177851878519785207852178522785237852478525785267852778528785297853078531785327853378534785357853678537785387853978540785417854278543785447854578546785477854878549785507855178552785537855478555785567855778558785597856078561785627856378564785657856678567785687856978570785717857278573785747857578576785777857878579785807858178582785837858478585785867858778588785897859078591785927859378594785957859678597785987859978600786017860278603786047860578606786077860878609786107861178612786137861478615786167861778618786197862078621786227862378624786257862678627786287862978630786317863278633786347863578636786377863878639786407864178642786437864478645786467864778648786497865078651786527865378654786557865678657786587865978660786617866278663786647866578666786677866878669786707867178672786737867478675786767867778678786797868078681786827868378684786857868678687786887868978690786917869278693786947869578696786977869878699787007870178702787037870478705787067870778708787097871078711787127871378714787157871678717787187871978720787217872278723787247872578726787277872878729787307873178732787337873478735787367873778738787397874078741787427874378744787457874678747787487874978750787517875278753787547875578756787577875878759787607876178762787637876478765787667876778768787697877078771787727877378774787757877678777787787877978780787817878278783787847878578786787877878878789787907879178792787937879478795787967879778798787997880078801788027880378804788057880678807788087880978810788117881278813788147881578816788177881878819788207882178822788237882478825788267882778828788297883078831788327883378834788357883678837788387883978840788417884278843788447884578846788477884878849788507885178852788537885478855788567885778858788597886078861788627886378864788657886678867788687886978870788717887278873788747887578876788777887878879788807888178882788837888478885788867888778888788897889078891788927889378894788957889678897788987889978900789017890278903789047890578906789077890878909789107891178912789137891478915789167891778918789197892078921789227892378924789257892678927789287892978930789317893278933789347893578936789377893878939789407894178942789437894478945789467894778948789497895078951789527895378954789557895678957789587895978960789617896278963789647896578966789677896878969789707897178972789737897478975789767897778978789797898078981789827898378984789857898678987789887898978990789917899278993789947899578996789977899878999790007900179002790037900479005790067900779008790097901079011790127901379014790157901679017790187901979020790217902279023790247902579026790277902879029790307903179032790337903479035790367903779038790397904079041790427904379044790457904679047790487904979050790517905279053790547905579056790577905879059790607906179062790637906479065790667906779068790697907079071790727907379074790757907679077790787907979080790817908279083790847908579086790877908879089790907909179092790937909479095790967909779098790997910079101791027910379104791057910679107791087910979110791117911279113791147911579116791177911879119791207912179122791237912479125791267912779128791297913079131791327913379134791357913679137791387913979140791417914279143791447914579146791477914879149791507915179152791537915479155791567915779158791597916079161791627916379164791657916679167791687916979170791717917279173791747917579176791777917879179791807918179182791837918479185791867918779188791897919079191791927919379194791957919679197791987919979200792017920279203792047920579206792077920879209792107921179212792137921479215792167921779218792197922079221792227922379224792257922679227792287922979230792317923279233792347923579236792377923879239792407924179242792437924479245792467924779248792497925079251792527925379254792557925679257792587925979260792617926279263792647926579266792677926879269792707927179272792737927479275792767927779278792797928079281792827928379284792857928679287792887928979290792917929279293792947929579296792977929879299793007930179302793037930479305793067930779308793097931079311793127931379314793157931679317793187931979320793217932279323793247932579326793277932879329793307933179332793337933479335793367933779338793397934079341793427934379344793457934679347793487934979350793517935279353793547935579356793577935879359793607936179362793637936479365793667936779368793697937079371793727937379374793757937679377793787937979380793817938279383793847938579386793877938879389793907939179392793937939479395793967939779398793997940079401794027940379404794057940679407794087940979410794117941279413794147941579416794177941879419794207942179422794237942479425794267942779428794297943079431794327943379434794357943679437794387943979440794417944279443794447944579446794477944879449794507945179452794537945479455794567945779458794597946079461794627946379464794657946679467794687946979470794717947279473794747947579476794777947879479794807948179482794837948479485794867948779488794897949079491794927949379494794957949679497794987949979500795017950279503795047950579506795077950879509795107951179512795137951479515795167951779518795197952079521795227952379524795257952679527795287952979530795317953279533795347953579536795377953879539795407954179542795437954479545795467954779548795497955079551795527955379554795557955679557795587955979560795617956279563795647956579566795677956879569795707957179572795737957479575795767957779578795797958079581795827958379584795857958679587795887958979590795917959279593795947959579596795977959879599796007960179602796037960479605796067960779608796097961079611796127961379614796157961679617796187961979620796217962279623796247962579626796277962879629796307963179632796337963479635796367963779638796397964079641796427964379644796457964679647796487964979650796517965279653796547965579656796577965879659796607966179662796637966479665796667966779668796697967079671796727967379674796757967679677796787967979680796817968279683796847968579686796877968879689796907969179692796937969479695796967969779698796997970079701797027970379704797057970679707797087970979710797117971279713797147971579716797177971879719797207972179722797237972479725797267972779728797297973079731797327973379734797357973679737797387973979740797417974279743797447974579746797477974879749797507975179752797537975479755797567975779758797597976079761797627976379764797657976679767797687976979770797717977279773797747977579776797777977879779797807978179782797837978479785797867978779788797897979079791797927979379794797957979679797797987979979800798017980279803798047980579806798077980879809798107981179812798137981479815798167981779818798197982079821798227982379824798257982679827798287982979830798317983279833798347983579836798377983879839798407984179842798437984479845798467984779848798497985079851798527985379854798557985679857798587985979860798617986279863798647986579866798677986879869798707987179872798737987479875798767987779878798797988079881798827988379884798857988679887798887988979890798917989279893798947989579896798977989879899799007990179902799037990479905799067990779908799097991079911799127991379914799157991679917799187991979920799217992279923799247992579926799277992879929799307993179932799337993479935799367993779938799397994079941799427994379944799457994679947799487994979950799517995279953799547995579956799577995879959799607996179962799637996479965799667996779968799697997079971799727997379974799757997679977799787997979980799817998279983799847998579986799877998879989799907999179992799937999479995799967999779998799998000080001800028000380004800058000680007800088000980010800118001280013800148001580016800178001880019800208002180022800238002480025800268002780028800298003080031800328003380034800358003680037800388003980040800418004280043800448004580046800478004880049800508005180052800538005480055800568005780058800598006080061800628006380064800658006680067800688006980070800718007280073800748007580076800778007880079800808008180082800838008480085800868008780088800898009080091800928009380094800958009680097800988009980100801018010280103801048010580106801078010880109801108011180112801138011480115801168011780118801198012080121801228012380124801258012680127801288012980130801318013280133801348013580136801378013880139801408014180142801438014480145801468014780148801498015080151801528015380154801558015680157801588015980160801618016280163801648016580166801678016880169801708017180172801738017480175801768017780178801798018080181801828018380184801858018680187801888018980190801918019280193801948019580196801978019880199802008020180202802038020480205802068020780208802098021080211802128021380214802158021680217802188021980220802218022280223802248022580226802278022880229802308023180232802338023480235802368023780238802398024080241802428024380244802458024680247802488024980250802518025280253802548025580256802578025880259802608026180262802638026480265802668026780268802698027080271802728027380274802758027680277802788027980280802818028280283802848028580286802878028880289802908029180292802938029480295802968029780298802998030080301803028030380304803058030680307803088030980310803118031280313803148031580316803178031880319803208032180322803238032480325803268032780328803298033080331803328033380334803358033680337803388033980340803418034280343803448034580346803478034880349803508035180352803538035480355803568035780358803598036080361803628036380364803658036680367803688036980370803718037280373803748037580376803778037880379803808038180382803838038480385803868038780388803898039080391803928039380394803958039680397803988039980400804018040280403804048040580406804078040880409804108041180412804138041480415804168041780418804198042080421804228042380424804258042680427804288042980430804318043280433804348043580436804378043880439804408044180442804438044480445804468044780448804498045080451804528045380454804558045680457804588045980460804618046280463804648046580466804678046880469804708047180472804738047480475804768047780478804798048080481804828048380484804858048680487804888048980490804918049280493804948049580496804978049880499805008050180502805038050480505805068050780508805098051080511805128051380514805158051680517805188051980520805218052280523805248052580526805278052880529805308053180532805338053480535805368053780538805398054080541805428054380544805458054680547805488054980550805518055280553805548055580556805578055880559805608056180562805638056480565805668056780568805698057080571805728057380574805758057680577805788057980580805818058280583805848058580586805878058880589805908059180592805938059480595805968059780598805998060080601806028060380604806058060680607806088060980610806118061280613806148061580616806178061880619806208062180622806238062480625806268062780628806298063080631806328063380634806358063680637806388063980640806418064280643806448064580646806478064880649806508065180652806538065480655806568065780658806598066080661806628066380664806658066680667806688066980670806718067280673806748067580676806778067880679806808068180682806838068480685806868068780688806898069080691806928069380694806958069680697806988069980700807018070280703807048070580706807078070880709807108071180712807138071480715807168071780718807198072080721807228072380724807258072680727807288072980730807318073280733807348073580736807378073880739807408074180742807438074480745807468074780748807498075080751807528075380754807558075680757807588075980760807618076280763807648076580766807678076880769807708077180772807738077480775807768077780778807798078080781807828078380784807858078680787807888078980790807918079280793807948079580796807978079880799808008080180802808038080480805808068080780808808098081080811808128081380814808158081680817808188081980820808218082280823808248082580826808278082880829808308083180832808338083480835808368083780838808398084080841808428084380844808458084680847808488084980850808518085280853808548085580856808578085880859808608086180862808638086480865808668086780868808698087080871808728087380874808758087680877808788087980880808818088280883808848088580886808878088880889808908089180892808938089480895808968089780898808998090080901809028090380904809058090680907809088090980910809118091280913809148091580916809178091880919809208092180922809238092480925809268092780928809298093080931809328093380934809358093680937809388093980940809418094280943809448094580946809478094880949809508095180952809538095480955809568095780958809598096080961809628096380964809658096680967809688096980970809718097280973809748097580976809778097880979809808098180982809838098480985809868098780988809898099080991809928099380994809958099680997809988099981000810018100281003810048100581006810078100881009810108101181012810138101481015810168101781018810198102081021810228102381024810258102681027810288102981030810318103281033810348103581036810378103881039810408104181042810438104481045810468104781048810498105081051810528105381054810558105681057810588105981060810618106281063810648106581066810678106881069810708107181072810738107481075810768107781078810798108081081810828108381084810858108681087810888108981090810918109281093810948109581096810978109881099811008110181102811038110481105811068110781108811098111081111811128111381114811158111681117811188111981120811218112281123811248112581126811278112881129811308113181132811338113481135811368113781138811398114081141811428114381144811458114681147811488114981150811518115281153811548115581156811578115881159811608116181162811638116481165811668116781168811698117081171811728117381174811758117681177811788117981180811818118281183811848118581186811878118881189811908119181192811938119481195811968119781198811998120081201812028120381204812058120681207812088120981210812118121281213812148121581216812178121881219812208122181222812238122481225812268122781228812298123081231812328123381234812358123681237812388123981240812418124281243812448124581246812478124881249812508125181252812538125481255812568125781258812598126081261812628126381264812658126681267812688126981270812718127281273812748127581276812778127881279812808128181282812838128481285812868128781288812898129081291812928129381294812958129681297812988129981300813018130281303813048130581306813078130881309813108131181312813138131481315813168131781318813198132081321813228132381324813258132681327813288132981330813318133281333813348133581336813378133881339813408134181342813438134481345813468134781348813498135081351813528135381354813558135681357813588135981360813618136281363813648136581366813678136881369813708137181372813738137481375813768137781378813798138081381813828138381384813858138681387813888138981390813918139281393813948139581396813978139881399814008140181402814038140481405814068140781408814098141081411814128141381414814158141681417814188141981420814218142281423814248142581426814278142881429814308143181432814338143481435814368143781438814398144081441814428144381444814458144681447814488144981450814518145281453814548145581456814578145881459814608146181462814638146481465814668146781468814698147081471814728147381474814758147681477814788147981480814818148281483814848148581486814878148881489814908149181492814938149481495814968149781498814998150081501815028150381504815058150681507815088150981510815118151281513815148151581516815178151881519815208152181522815238152481525815268152781528815298153081531815328153381534815358153681537815388153981540815418154281543815448154581546815478154881549815508155181552815538155481555815568155781558815598156081561815628156381564815658156681567815688156981570815718157281573815748157581576815778157881579815808158181582815838158481585815868158781588815898159081591815928159381594815958159681597815988159981600816018160281603816048160581606816078160881609816108161181612816138161481615816168161781618816198162081621816228162381624816258162681627816288162981630816318163281633816348163581636816378163881639816408164181642816438164481645816468164781648816498165081651816528165381654816558165681657816588165981660816618166281663816648166581666816678166881669816708167181672816738167481675816768167781678816798168081681816828168381684816858168681687816888168981690816918169281693816948169581696816978169881699817008170181702817038170481705817068170781708817098171081711817128171381714817158171681717817188171981720817218172281723817248172581726817278172881729817308173181732817338173481735817368173781738817398174081741817428174381744817458174681747817488174981750817518175281753817548175581756817578175881759817608176181762817638176481765817668176781768817698177081771817728177381774817758177681777817788177981780817818178281783817848178581786817878178881789817908179181792817938179481795817968179781798817998180081801818028180381804818058180681807818088180981810818118181281813818148181581816818178181881819818208182181822818238182481825818268182781828818298183081831818328183381834818358183681837818388183981840818418184281843818448184581846818478184881849818508185181852818538185481855818568185781858818598186081861818628186381864818658186681867818688186981870818718187281873818748187581876818778187881879818808188181882818838188481885818868188781888818898189081891818928189381894818958189681897818988189981900819018190281903819048190581906819078190881909819108191181912819138191481915819168191781918819198192081921819228192381924819258192681927819288192981930819318193281933819348193581936819378193881939819408194181942819438194481945819468194781948819498195081951819528195381954819558195681957819588195981960819618196281963819648196581966819678196881969819708197181972819738197481975819768197781978819798198081981819828198381984819858198681987819888198981990819918199281993819948199581996819978199881999820008200182002820038200482005820068200782008820098201082011820128201382014820158201682017820188201982020820218202282023820248202582026820278202882029820308203182032820338203482035820368203782038820398204082041820428204382044820458204682047820488204982050820518205282053820548205582056820578205882059820608206182062820638206482065820668206782068820698207082071820728207382074820758207682077820788207982080820818208282083820848208582086820878208882089820908209182092820938209482095820968209782098820998210082101821028210382104821058210682107821088210982110821118211282113821148211582116821178211882119821208212182122821238212482125821268212782128821298213082131821328213382134821358213682137821388213982140821418214282143821448214582146821478214882149821508215182152821538215482155821568215782158821598216082161821628216382164821658216682167821688216982170821718217282173821748217582176821778217882179821808218182182821838218482185821868218782188821898219082191821928219382194821958219682197821988219982200822018220282203822048220582206822078220882209822108221182212822138221482215822168221782218822198222082221822228222382224822258222682227822288222982230822318223282233822348223582236822378223882239822408224182242822438224482245822468224782248822498225082251822528225382254822558225682257822588225982260822618226282263822648226582266822678226882269822708227182272822738227482275822768227782278822798228082281822828228382284822858228682287822888228982290822918229282293822948229582296822978229882299823008230182302823038230482305823068230782308823098231082311823128231382314823158231682317823188231982320823218232282323823248232582326823278232882329823308233182332823338233482335823368233782338823398234082341823428234382344823458234682347823488234982350823518235282353823548235582356823578235882359823608236182362823638236482365823668236782368823698237082371823728237382374823758237682377823788237982380823818238282383823848238582386823878238882389823908239182392823938239482395823968239782398823998240082401824028240382404824058240682407824088240982410824118241282413824148241582416824178241882419824208242182422824238242482425824268242782428824298243082431824328243382434824358243682437824388243982440824418244282443824448244582446824478244882449824508245182452824538245482455824568245782458824598246082461824628246382464824658246682467824688246982470824718247282473824748247582476824778247882479824808248182482824838248482485824868248782488824898249082491824928249382494824958249682497824988249982500825018250282503825048250582506825078250882509825108251182512825138251482515825168251782518825198252082521825228252382524825258252682527825288252982530825318253282533825348253582536825378253882539825408254182542825438254482545825468254782548825498255082551825528255382554825558255682557825588255982560825618256282563825648256582566825678256882569825708257182572825738257482575825768257782578825798258082581825828258382584825858258682587825888258982590825918259282593825948259582596825978259882599826008260182602826038260482605826068260782608826098261082611826128261382614826158261682617826188261982620826218262282623826248262582626826278262882629826308263182632826338263482635826368263782638826398264082641826428264382644826458264682647826488264982650826518265282653826548265582656826578265882659826608266182662826638266482665826668266782668826698267082671826728267382674826758267682677826788267982680826818268282683826848268582686826878268882689826908269182692826938269482695826968269782698826998270082701827028270382704827058270682707827088270982710827118271282713827148271582716827178271882719827208272182722827238272482725827268272782728827298273082731827328273382734827358273682737827388273982740827418274282743827448274582746827478274882749827508275182752827538275482755827568275782758827598276082761827628276382764827658276682767827688276982770827718277282773827748277582776827778277882779827808278182782827838278482785827868278782788827898279082791827928279382794827958279682797827988279982800828018280282803828048280582806828078280882809828108281182812828138281482815828168281782818828198282082821828228282382824828258282682827828288282982830828318283282833828348283582836828378283882839828408284182842828438284482845828468284782848828498285082851828528285382854828558285682857828588285982860828618286282863828648286582866828678286882869828708287182872828738287482875828768287782878828798288082881828828288382884828858288682887828888288982890828918289282893828948289582896828978289882899829008290182902829038290482905829068290782908829098291082911829128291382914829158291682917829188291982920829218292282923829248292582926829278292882929829308293182932829338293482935829368293782938829398294082941829428294382944829458294682947829488294982950829518295282953829548295582956829578295882959829608296182962829638296482965829668296782968829698297082971829728297382974829758297682977829788297982980829818298282983829848298582986829878298882989829908299182992829938299482995829968299782998829998300083001830028300383004830058300683007830088300983010830118301283013830148301583016830178301883019830208302183022830238302483025830268302783028830298303083031830328303383034830358303683037830388303983040830418304283043830448304583046830478304883049830508305183052830538305483055830568305783058830598306083061830628306383064830658306683067830688306983070830718307283073830748307583076830778307883079830808308183082830838308483085830868308783088830898309083091830928309383094830958309683097830988309983100831018310283103831048310583106831078310883109831108311183112831138311483115831168311783118831198312083121831228312383124831258312683127831288312983130831318313283133831348313583136831378313883139831408314183142831438314483145831468314783148831498315083151831528315383154831558315683157831588315983160831618316283163831648316583166831678316883169831708317183172831738317483175831768317783178831798318083181831828318383184831858318683187831888318983190831918319283193831948319583196831978319883199832008320183202832038320483205832068320783208832098321083211832128321383214832158321683217832188321983220832218322283223832248322583226832278322883229832308323183232832338323483235832368323783238832398324083241832428324383244832458324683247832488324983250832518325283253832548325583256832578325883259832608326183262832638326483265832668326783268832698327083271832728327383274832758327683277832788327983280832818328283283832848328583286832878328883289832908329183292832938329483295832968329783298832998330083301833028330383304833058330683307833088330983310833118331283313833148331583316833178331883319833208332183322833238332483325833268332783328833298333083331833328333383334833358333683337833388333983340833418334283343833448334583346833478334883349833508335183352833538335483355833568335783358833598336083361833628336383364833658336683367833688336983370833718337283373833748337583376833778337883379833808338183382833838338483385833868338783388833898339083391833928339383394833958339683397833988339983400834018340283403834048340583406834078340883409834108341183412834138341483415834168341783418834198342083421834228342383424834258342683427834288342983430834318343283433834348343583436834378343883439834408344183442834438344483445834468344783448834498345083451834528345383454834558345683457834588345983460834618346283463834648346583466834678346883469834708347183472834738347483475834768347783478834798348083481834828348383484834858348683487834888348983490834918349283493834948349583496834978349883499835008350183502835038350483505835068350783508835098351083511835128351383514835158351683517835188351983520835218352283523835248352583526835278352883529835308353183532835338353483535835368353783538835398354083541835428354383544835458354683547835488354983550835518355283553835548355583556835578355883559835608356183562835638356483565835668356783568835698357083571835728357383574835758357683577835788357983580835818358283583835848358583586835878358883589835908359183592835938359483595835968359783598835998360083601836028360383604836058360683607836088360983610836118361283613836148361583616836178361883619836208362183622836238362483625836268362783628836298363083631836328363383634836358363683637836388363983640836418364283643836448364583646836478364883649836508365183652836538365483655836568365783658836598366083661836628366383664836658366683667836688366983670836718367283673836748367583676836778367883679836808368183682836838368483685836868368783688836898369083691836928369383694836958369683697836988369983700837018370283703837048370583706837078370883709837108371183712837138371483715837168371783718837198372083721837228372383724837258372683727837288372983730837318373283733837348373583736837378373883739837408374183742837438374483745837468374783748837498375083751837528375383754837558375683757837588375983760837618376283763837648376583766837678376883769837708377183772837738377483775837768377783778837798378083781837828378383784837858378683787837888378983790837918379283793837948379583796837978379883799838008380183802838038380483805838068380783808838098381083811838128381383814838158381683817838188381983820838218382283823838248382583826838278382883829838308383183832838338383483835838368383783838838398384083841838428384383844838458384683847838488384983850838518385283853838548385583856838578385883859838608386183862838638386483865838668386783868838698387083871838728387383874838758387683877838788387983880838818388283883838848388583886838878388883889838908389183892838938389483895838968389783898838998390083901839028390383904839058390683907839088390983910839118391283913839148391583916839178391883919839208392183922839238392483925839268392783928839298393083931839328393383934839358393683937839388393983940839418394283943839448394583946839478394883949839508395183952839538395483955839568395783958839598396083961839628396383964839658396683967839688396983970839718397283973839748397583976839778397883979839808398183982839838398483985839868398783988839898399083991839928399383994839958399683997839988399984000840018400284003840048400584006840078400884009840108401184012840138401484015840168401784018840198402084021840228402384024840258402684027840288402984030840318403284033840348403584036840378403884039840408404184042840438404484045840468404784048840498405084051840528405384054840558405684057840588405984060840618406284063840648406584066840678406884069840708407184072840738407484075840768407784078840798408084081840828408384084840858408684087840888408984090840918409284093840948409584096840978409884099841008410184102841038410484105841068410784108841098411084111841128411384114841158411684117841188411984120841218412284123841248412584126841278412884129841308413184132841338413484135841368413784138841398414084141841428414384144841458414684147841488414984150841518415284153841548415584156841578415884159841608416184162841638416484165841668416784168841698417084171841728417384174841758417684177841788417984180841818418284183841848418584186841878418884189841908419184192841938419484195841968419784198841998420084201842028420384204842058420684207842088420984210842118421284213842148421584216842178421884219842208422184222842238422484225842268422784228842298423084231842328423384234842358423684237842388423984240842418424284243842448424584246842478424884249842508425184252842538425484255842568425784258842598426084261842628426384264842658426684267842688426984270842718427284273842748427584276842778427884279842808428184282842838428484285842868428784288842898429084291842928429384294842958429684297842988429984300843018430284303843048430584306843078430884309843108431184312843138431484315843168431784318843198432084321843228432384324843258432684327843288432984330843318433284333843348433584336843378433884339843408434184342843438434484345843468434784348843498435084351843528435384354843558435684357843588435984360843618436284363843648436584366843678436884369843708437184372843738437484375843768437784378843798438084381843828438384384843858438684387843888438984390843918439284393843948439584396843978439884399844008440184402844038440484405844068440784408844098441084411844128441384414844158441684417844188441984420844218442284423844248442584426844278442884429844308443184432844338443484435844368443784438844398444084441844428444384444844458444684447844488444984450844518445284453844548445584456844578445884459844608446184462844638446484465844668446784468844698447084471844728447384474844758447684477844788447984480844818448284483844848448584486844878448884489844908449184492844938449484495844968449784498844998450084501845028450384504845058450684507845088450984510845118451284513845148451584516845178451884519845208452184522845238452484525845268452784528845298453084531845328453384534845358453684537845388453984540845418454284543845448454584546845478454884549845508455184552845538455484555845568455784558845598456084561845628456384564845658456684567845688456984570845718457284573845748457584576845778457884579845808458184582845838458484585845868458784588845898459084591845928459384594845958459684597845988459984600846018460284603846048460584606846078460884609846108461184612846138461484615846168461784618846198462084621846228462384624846258462684627846288462984630846318463284633846348463584636846378463884639846408464184642846438464484645846468464784648846498465084651846528465384654846558465684657846588465984660846618466284663846648466584666846678466884669846708467184672846738467484675846768467784678846798468084681846828468384684846858468684687846888468984690846918469284693846948469584696846978469884699847008470184702847038470484705847068470784708847098471084711847128471384714847158471684717847188471984720847218472284723847248472584726847278472884729847308473184732847338473484735847368473784738847398474084741847428474384744847458474684747847488474984750847518475284753847548475584756847578475884759847608476184762847638476484765847668476784768847698477084771847728477384774847758477684777847788477984780847818478284783847848478584786847878478884789847908479184792847938479484795847968479784798847998480084801848028480384804848058480684807848088480984810848118481284813848148481584816848178481884819848208482184822848238482484825848268482784828848298483084831848328483384834848358483684837848388483984840848418484284843848448484584846848478484884849848508485184852848538485484855848568485784858848598486084861848628486384864848658486684867848688486984870848718487284873848748487584876848778487884879848808488184882848838488484885848868488784888848898489084891848928489384894848958489684897848988489984900849018490284903849048490584906849078490884909849108491184912849138491484915849168491784918849198492084921849228492384924849258492684927849288492984930849318493284933849348493584936849378493884939849408494184942849438494484945849468494784948849498495084951849528495384954849558495684957849588495984960849618496284963849648496584966849678496884969849708497184972849738497484975849768497784978849798498084981849828498384984849858498684987849888498984990849918499284993849948499584996849978499884999850008500185002850038500485005850068500785008850098501085011850128501385014850158501685017850188501985020850218502285023850248502585026850278502885029850308503185032850338503485035850368503785038850398504085041850428504385044850458504685047850488504985050850518505285053850548505585056850578505885059850608506185062850638506485065850668506785068850698507085071850728507385074850758507685077850788507985080850818508285083850848508585086850878508885089850908509185092850938509485095850968509785098850998510085101851028510385104851058510685107851088510985110851118511285113851148511585116851178511885119851208512185122851238512485125851268512785128851298513085131851328513385134851358513685137851388513985140851418514285143851448514585146851478514885149851508515185152851538515485155851568515785158851598516085161851628516385164851658516685167851688516985170851718517285173851748517585176851778517885179851808518185182851838518485185851868518785188851898519085191851928519385194851958519685197851988519985200852018520285203852048520585206852078520885209852108521185212852138521485215852168521785218852198522085221852228522385224852258522685227852288522985230852318523285233852348523585236852378523885239852408524185242852438524485245852468524785248852498525085251852528525385254852558525685257852588525985260852618526285263852648526585266852678526885269852708527185272852738527485275852768527785278852798528085281852828528385284852858528685287852888528985290852918529285293852948529585296852978529885299853008530185302853038530485305853068530785308853098531085311853128531385314853158531685317853188531985320853218532285323853248532585326853278532885329853308533185332853338533485335853368533785338853398534085341853428534385344853458534685347853488534985350853518535285353853548535585356853578535885359853608536185362853638536485365853668536785368853698537085371853728537385374853758537685377853788537985380853818538285383853848538585386853878538885389853908539185392853938539485395853968539785398853998540085401854028540385404854058540685407854088540985410854118541285413854148541585416854178541885419854208542185422854238542485425854268542785428854298543085431854328543385434854358543685437854388543985440854418544285443854448544585446854478544885449854508545185452854538545485455854568545785458854598546085461854628546385464854658546685467854688546985470854718547285473854748547585476854778547885479854808548185482854838548485485854868548785488854898549085491854928549385494854958549685497854988549985500855018550285503855048550585506855078550885509855108551185512855138551485515855168551785518855198552085521855228552385524855258552685527855288552985530855318553285533855348553585536855378553885539855408554185542855438554485545855468554785548855498555085551855528555385554855558555685557855588555985560855618556285563855648556585566855678556885569855708557185572855738557485575855768557785578855798558085581855828558385584855858558685587855888558985590855918559285593855948559585596855978559885599856008560185602856038560485605856068560785608856098561085611856128561385614856158561685617856188561985620856218562285623856248562585626856278562885629856308563185632856338563485635856368563785638856398564085641856428564385644856458564685647856488564985650856518565285653856548565585656856578565885659856608566185662856638566485665856668566785668856698567085671856728567385674856758567685677856788567985680856818568285683856848568585686856878568885689856908569185692856938569485695856968569785698856998570085701857028570385704857058570685707857088570985710857118571285713857148571585716857178571885719857208572185722857238572485725857268572785728857298573085731857328573385734857358573685737857388573985740857418574285743857448574585746857478574885749857508575185752857538575485755857568575785758857598576085761857628576385764857658576685767857688576985770857718577285773857748577585776857778577885779857808578185782857838578485785857868578785788857898579085791857928579385794857958579685797857988579985800858018580285803858048580585806858078580885809858108581185812858138581485815858168581785818858198582085821858228582385824858258582685827858288582985830858318583285833858348583585836858378583885839858408584185842858438584485845858468584785848858498585085851858528585385854858558585685857858588585985860858618586285863858648586585866858678586885869858708587185872858738587485875858768587785878858798588085881858828588385884858858588685887858888588985890858918589285893858948589585896858978589885899859008590185902859038590485905859068590785908859098591085911859128591385914859158591685917859188591985920859218592285923859248592585926859278592885929859308593185932859338593485935859368593785938859398594085941859428594385944859458594685947859488594985950859518595285953859548595585956859578595885959859608596185962859638596485965859668596785968859698597085971859728597385974859758597685977859788597985980859818598285983859848598585986859878598885989859908599185992859938599485995859968599785998859998600086001860028600386004860058600686007860088600986010860118601286013860148601586016860178601886019860208602186022860238602486025860268602786028860298603086031860328603386034860358603686037860388603986040860418604286043860448604586046860478604886049860508605186052860538605486055860568605786058860598606086061860628606386064860658606686067860688606986070860718607286073860748607586076860778607886079860808608186082860838608486085860868608786088860898609086091860928609386094860958609686097860988609986100861018610286103861048610586106861078610886109861108611186112861138611486115861168611786118861198612086121861228612386124861258612686127861288612986130861318613286133861348613586136861378613886139861408614186142861438614486145861468614786148861498615086151861528615386154861558615686157861588615986160861618616286163861648616586166861678616886169861708617186172861738617486175861768617786178861798618086181861828618386184861858618686187861888618986190861918619286193861948619586196861978619886199862008620186202862038620486205862068620786208862098621086211862128621386214862158621686217862188621986220862218622286223862248622586226862278622886229862308623186232862338623486235862368623786238862398624086241862428624386244862458624686247862488624986250862518625286253862548625586256862578625886259862608626186262862638626486265862668626786268862698627086271862728627386274862758627686277862788627986280862818628286283862848628586286862878628886289862908629186292862938629486295862968629786298862998630086301863028630386304863058630686307863088630986310863118631286313863148631586316863178631886319863208632186322863238632486325863268632786328863298633086331863328633386334863358633686337863388633986340863418634286343863448634586346863478634886349863508635186352863538635486355863568635786358863598636086361863628636386364863658636686367863688636986370863718637286373863748637586376863778637886379863808638186382863838638486385863868638786388863898639086391863928639386394863958639686397863988639986400864018640286403864048640586406864078640886409864108641186412864138641486415864168641786418864198642086421864228642386424864258642686427864288642986430864318643286433864348643586436864378643886439864408644186442864438644486445864468644786448864498645086451864528645386454864558645686457864588645986460864618646286463864648646586466864678646886469864708647186472864738647486475864768647786478864798648086481864828648386484864858648686487864888648986490864918649286493864948649586496864978649886499865008650186502865038650486505865068650786508865098651086511865128651386514865158651686517865188651986520865218652286523865248652586526865278652886529865308653186532865338653486535865368653786538865398654086541865428654386544865458654686547865488654986550865518655286553865548655586556865578655886559865608656186562865638656486565865668656786568865698657086571865728657386574865758657686577865788657986580865818658286583865848658586586865878658886589865908659186592865938659486595865968659786598865998660086601866028660386604866058660686607866088660986610866118661286613866148661586616866178661886619866208662186622866238662486625866268662786628866298663086631866328663386634866358663686637866388663986640866418664286643866448664586646866478664886649866508665186652866538665486655866568665786658866598666086661866628666386664866658666686667866688666986670866718667286673866748667586676866778667886679866808668186682866838668486685866868668786688866898669086691866928669386694866958669686697866988669986700867018670286703867048670586706867078670886709867108671186712867138671486715867168671786718867198672086721867228672386724867258672686727867288672986730867318673286733867348673586736867378673886739867408674186742867438674486745867468674786748867498675086751867528675386754867558675686757867588675986760867618676286763867648676586766867678676886769867708677186772867738677486775867768677786778867798678086781867828678386784867858678686787867888678986790867918679286793867948679586796867978679886799868008680186802868038680486805868068680786808868098681086811868128681386814868158681686817868188681986820868218682286823868248682586826868278682886829868308683186832868338683486835868368683786838868398684086841868428684386844868458684686847868488684986850868518685286853868548685586856868578685886859868608686186862868638686486865868668686786868868698687086871868728687386874868758687686877868788687986880868818688286883868848688586886868878688886889868908689186892868938689486895868968689786898868998690086901869028690386904869058690686907869088690986910869118691286913869148691586916869178691886919869208692186922869238692486925869268692786928869298693086931869328693386934869358693686937869388693986940869418694286943869448694586946869478694886949869508695186952869538695486955869568695786958869598696086961869628696386964869658696686967869688696986970869718697286973869748697586976869778697886979869808698186982869838698486985869868698786988869898699086991869928699386994869958699686997869988699987000870018700287003870048700587006870078700887009870108701187012870138701487015870168701787018870198702087021870228702387024870258702687027870288702987030870318703287033870348703587036870378703887039870408704187042870438704487045870468704787048870498705087051870528705387054870558705687057870588705987060870618706287063870648706587066870678706887069870708707187072870738707487075870768707787078870798708087081870828708387084870858708687087870888708987090870918709287093870948709587096870978709887099871008710187102871038710487105871068710787108871098711087111871128711387114871158711687117871188711987120871218712287123871248712587126871278712887129871308713187132871338713487135871368713787138871398714087141871428714387144871458714687147871488714987150871518715287153871548715587156871578715887159871608716187162871638716487165871668716787168871698717087171871728717387174871758717687177871788717987180871818718287183871848718587186871878718887189871908719187192871938719487195871968719787198871998720087201872028720387204872058720687207872088720987210872118721287213872148721587216872178721887219872208722187222872238722487225872268722787228872298723087231872328723387234872358723687237872388723987240872418724287243872448724587246872478724887249872508725187252872538725487255872568725787258872598726087261872628726387264872658726687267872688726987270872718727287273872748727587276872778727887279872808728187282872838728487285872868728787288872898729087291872928729387294872958729687297872988729987300873018730287303873048730587306873078730887309873108731187312873138731487315873168731787318873198732087321873228732387324873258732687327873288732987330873318733287333873348733587336873378733887339873408734187342873438734487345873468734787348873498735087351873528735387354873558735687357873588735987360873618736287363873648736587366873678736887369873708737187372873738737487375873768737787378873798738087381873828738387384873858738687387873888738987390873918739287393873948739587396873978739887399874008740187402874038740487405874068740787408874098741087411874128741387414874158741687417874188741987420874218742287423874248742587426874278742887429874308743187432874338743487435874368743787438874398744087441874428744387444874458744687447874488744987450874518745287453874548745587456874578745887459874608746187462874638746487465874668746787468874698747087471874728747387474874758747687477874788747987480874818748287483874848748587486874878748887489874908749187492874938749487495874968749787498874998750087501875028750387504875058750687507875088750987510875118751287513875148751587516875178751887519875208752187522875238752487525875268752787528875298753087531875328753387534875358753687537875388753987540875418754287543875448754587546875478754887549875508755187552875538755487555875568755787558875598756087561875628756387564875658756687567875688756987570875718757287573875748757587576875778757887579875808758187582875838758487585875868758787588875898759087591875928759387594875958759687597875988759987600876018760287603876048760587606876078760887609876108761187612876138761487615876168761787618876198762087621876228762387624876258762687627876288762987630876318763287633876348763587636876378763887639876408764187642876438764487645876468764787648876498765087651876528765387654876558765687657876588765987660876618766287663876648766587666876678766887669876708767187672876738767487675876768767787678876798768087681876828768387684876858768687687876888768987690876918769287693876948769587696876978769887699877008770187702877038770487705877068770787708877098771087711877128771387714877158771687717877188771987720877218772287723877248772587726877278772887729877308773187732877338773487735877368773787738877398774087741877428774387744877458774687747877488774987750877518775287753877548775587756877578775887759877608776187762877638776487765877668776787768877698777087771877728777387774877758777687777877788777987780877818778287783877848778587786877878778887789877908779187792877938779487795877968779787798877998780087801878028780387804878058780687807878088780987810878118781287813878148781587816878178781887819878208782187822878238782487825878268782787828878298783087831878328783387834878358783687837878388783987840878418784287843878448784587846878478784887849878508785187852878538785487855878568785787858878598786087861878628786387864878658786687867878688786987870878718787287873878748787587876878778787887879878808788187882878838788487885878868788787888878898789087891878928789387894878958789687897878988789987900879018790287903879048790587906879078790887909879108791187912879138791487915879168791787918879198792087921879228792387924879258792687927879288792987930879318793287933879348793587936879378793887939879408794187942879438794487945879468794787948879498795087951879528795387954879558795687957879588795987960879618796287963879648796587966879678796887969879708797187972879738797487975879768797787978879798798087981879828798387984879858798687987879888798987990879918799287993879948799587996879978799887999880008800188002880038800488005880068800788008880098801088011880128801388014880158801688017880188801988020880218802288023880248802588026880278802888029880308803188032880338803488035880368803788038880398804088041880428804388044880458804688047880488804988050880518805288053880548805588056880578805888059880608806188062880638806488065880668806788068880698807088071880728807388074880758807688077880788807988080880818808288083880848808588086880878808888089880908809188092880938809488095880968809788098880998810088101881028810388104881058810688107881088810988110881118811288113881148811588116881178811888119881208812188122881238812488125881268812788128881298813088131881328813388134881358813688137881388813988140881418814288143881448814588146881478814888149881508815188152881538815488155881568815788158881598816088161881628816388164881658816688167881688816988170881718817288173881748817588176881778817888179881808818188182881838818488185881868818788188881898819088191881928819388194881958819688197881988819988200882018820288203882048820588206882078820888209882108821188212882138821488215882168821788218882198822088221882228822388224882258822688227882288822988230882318823288233882348823588236882378823888239882408824188242882438824488245882468824788248882498825088251882528825388254882558825688257882588825988260882618826288263882648826588266882678826888269882708827188272882738827488275882768827788278882798828088281882828828388284882858828688287882888828988290882918829288293882948829588296882978829888299883008830188302883038830488305883068830788308883098831088311883128831388314883158831688317883188831988320883218832288323883248832588326883278832888329883308833188332883338833488335883368833788338883398834088341883428834388344883458834688347883488834988350883518835288353883548835588356883578835888359883608836188362883638836488365883668836788368883698837088371883728837388374883758837688377883788837988380883818838288383883848838588386883878838888389883908839188392883938839488395883968839788398883998840088401884028840388404884058840688407884088840988410884118841288413884148841588416884178841888419884208842188422884238842488425884268842788428884298843088431884328843388434884358843688437884388843988440884418844288443884448844588446884478844888449884508845188452884538845488455884568845788458884598846088461884628846388464884658846688467884688846988470884718847288473884748847588476884778847888479884808848188482884838848488485884868848788488884898849088491884928849388494884958849688497884988849988500885018850288503885048850588506885078850888509885108851188512885138851488515885168851788518885198852088521885228852388524885258852688527885288852988530885318853288533885348853588536885378853888539885408854188542885438854488545885468854788548885498855088551885528855388554885558855688557885588855988560885618856288563885648856588566885678856888569885708857188572885738857488575885768857788578885798858088581885828858388584885858858688587885888858988590885918859288593885948859588596885978859888599886008860188602886038860488605886068860788608886098861088611886128861388614886158861688617886188861988620886218862288623886248862588626886278862888629886308863188632886338863488635886368863788638886398864088641886428864388644886458864688647886488864988650886518865288653886548865588656886578865888659886608866188662886638866488665886668866788668886698867088671886728867388674886758867688677886788867988680886818868288683886848868588686886878868888689886908869188692886938869488695886968869788698886998870088701887028870388704887058870688707887088870988710887118871288713887148871588716887178871888719887208872188722887238872488725887268872788728887298873088731887328873388734887358873688737887388873988740887418874288743887448874588746887478874888749887508875188752887538875488755887568875788758887598876088761887628876388764887658876688767887688876988770887718877288773887748877588776887778877888779887808878188782887838878488785887868878788788887898879088791887928879388794887958879688797887988879988800888018880288803888048880588806888078880888809888108881188812888138881488815888168881788818888198882088821888228882388824888258882688827888288882988830888318883288833888348883588836888378883888839888408884188842888438884488845888468884788848888498885088851888528885388854888558885688857888588885988860888618886288863888648886588866888678886888869888708887188872888738887488875888768887788878888798888088881888828888388884888858888688887888888888988890888918889288893888948889588896888978889888899889008890188902889038890488905889068890788908889098891088911889128891388914889158891688917889188891988920889218892288923889248892588926889278892888929889308893188932889338893488935889368893788938889398894088941889428894388944889458894688947889488894988950889518895288953889548895588956889578895888959889608896188962889638896488965889668896788968889698897088971889728897388974889758897688977889788897988980889818898288983889848898588986889878898888989889908899188992889938899488995889968899788998889998900089001890028900389004890058900689007890088900989010890118901289013890148901589016890178901889019890208902189022890238902489025890268902789028890298903089031890328903389034890358903689037890388903989040890418904289043890448904589046890478904889049890508905189052890538905489055890568905789058890598906089061890628906389064890658906689067890688906989070890718907289073890748907589076890778907889079890808908189082890838908489085890868908789088890898909089091890928909389094890958909689097890988909989100891018910289103891048910589106891078910889109891108911189112891138911489115891168911789118891198912089121891228912389124891258912689127891288912989130891318913289133891348913589136891378913889139891408914189142891438914489145891468914789148891498915089151891528915389154891558915689157891588915989160891618916289163891648916589166891678916889169891708917189172891738917489175891768917789178891798918089181891828918389184891858918689187891888918989190891918919289193891948919589196891978919889199892008920189202892038920489205892068920789208892098921089211892128921389214892158921689217892188921989220892218922289223892248922589226892278922889229892308923189232892338923489235892368923789238892398924089241892428924389244892458924689247892488924989250892518925289253892548925589256892578925889259892608926189262892638926489265892668926789268892698927089271892728927389274892758927689277892788927989280892818928289283892848928589286892878928889289892908929189292892938929489295892968929789298892998930089301893028930389304893058930689307893088930989310893118931289313893148931589316893178931889319893208932189322893238932489325893268932789328893298933089331893328933389334893358933689337893388933989340893418934289343893448934589346893478934889349893508935189352893538935489355893568935789358893598936089361893628936389364893658936689367893688936989370893718937289373893748937589376893778937889379893808938189382893838938489385893868938789388893898939089391893928939389394893958939689397893988939989400894018940289403894048940589406894078940889409894108941189412894138941489415894168941789418894198942089421894228942389424894258942689427894288942989430894318943289433894348943589436894378943889439894408944189442894438944489445894468944789448894498945089451894528945389454894558945689457894588945989460894618946289463894648946589466894678946889469894708947189472894738947489475894768947789478894798948089481894828948389484894858948689487894888948989490894918949289493894948949589496894978949889499895008950189502895038950489505895068950789508895098951089511895128951389514895158951689517895188951989520895218952289523895248952589526895278952889529895308953189532895338953489535895368953789538895398954089541895428954389544895458954689547895488954989550895518955289553895548955589556895578955889559895608956189562895638956489565895668956789568895698957089571895728957389574895758957689577895788957989580895818958289583895848958589586895878958889589895908959189592895938959489595895968959789598895998960089601896028960389604896058960689607896088960989610896118961289613896148961589616896178961889619896208962189622896238962489625896268962789628896298963089631896328963389634896358963689637896388963989640896418964289643896448964589646896478964889649896508965189652896538965489655896568965789658896598966089661896628966389664896658966689667896688966989670896718967289673896748967589676896778967889679896808968189682896838968489685896868968789688896898969089691896928969389694896958969689697896988969989700897018970289703897048970589706897078970889709897108971189712897138971489715897168971789718897198972089721897228972389724897258972689727897288972989730897318973289733897348973589736897378973889739897408974189742897438974489745897468974789748897498975089751897528975389754897558975689757897588975989760897618976289763897648976589766897678976889769897708977189772897738977489775897768977789778897798978089781897828978389784897858978689787897888978989790897918979289793897948979589796897978979889799898008980189802898038980489805898068980789808898098981089811898128981389814898158981689817898188981989820898218982289823898248982589826898278982889829898308983189832898338983489835898368983789838898398984089841898428984389844898458984689847898488984989850898518985289853898548985589856898578985889859898608986189862898638986489865898668986789868898698987089871898728987389874898758987689877898788987989880898818988289883898848988589886898878988889889898908989189892898938989489895898968989789898898998990089901899028990389904899058990689907899088990989910899118991289913899148991589916899178991889919899208992189922899238992489925899268992789928899298993089931899328993389934899358993689937899388993989940899418994289943899448994589946899478994889949899508995189952899538995489955899568995789958899598996089961899628996389964899658996689967899688996989970899718997289973899748997589976899778997889979899808998189982899838998489985899868998789988899898999089991899928999389994899958999689997899988999990000900019000290003900049000590006900079000890009900109001190012900139001490015900169001790018900199002090021900229002390024900259002690027900289002990030900319003290033900349003590036900379003890039900409004190042900439004490045900469004790048900499005090051900529005390054900559005690057900589005990060900619006290063900649006590066900679006890069900709007190072900739007490075900769007790078900799008090081900829008390084900859008690087900889008990090900919009290093900949009590096900979009890099901009010190102901039010490105901069010790108901099011090111901129011390114901159011690117901189011990120901219012290123901249012590126901279012890129901309013190132901339013490135901369013790138901399014090141901429014390144901459014690147901489014990150901519015290153901549015590156901579015890159901609016190162901639016490165901669016790168901699017090171901729017390174901759017690177901789017990180901819018290183901849018590186901879018890189901909019190192901939019490195901969019790198901999020090201902029020390204902059020690207902089020990210902119021290213902149021590216902179021890219902209022190222902239022490225902269022790228902299023090231902329023390234902359023690237902389023990240902419024290243902449024590246902479024890249902509025190252902539025490255902569025790258902599026090261902629026390264902659026690267902689026990270902719027290273902749027590276902779027890279902809028190282902839028490285902869028790288902899029090291902929029390294902959029690297902989029990300903019030290303903049030590306903079030890309903109031190312903139031490315903169031790318903199032090321903229032390324903259032690327903289032990330903319033290333903349033590336903379033890339903409034190342903439034490345903469034790348903499035090351903529035390354903559035690357903589035990360903619036290363903649036590366903679036890369903709037190372903739037490375903769037790378903799038090381903829038390384903859038690387903889038990390903919039290393903949039590396903979039890399904009040190402904039040490405904069040790408904099041090411904129041390414904159041690417904189041990420904219042290423904249042590426904279042890429904309043190432904339043490435904369043790438904399044090441904429044390444904459044690447904489044990450904519045290453904549045590456904579045890459904609046190462904639046490465904669046790468904699047090471904729047390474904759047690477904789047990480904819048290483904849048590486904879048890489904909049190492904939049490495904969049790498904999050090501905029050390504905059050690507905089050990510905119051290513905149051590516905179051890519905209052190522905239052490525905269052790528905299053090531905329053390534905359053690537905389053990540905419054290543905449054590546905479054890549905509055190552905539055490555905569055790558905599056090561905629056390564905659056690567905689056990570905719057290573905749057590576905779057890579905809058190582905839058490585905869058790588905899059090591905929059390594905959059690597905989059990600906019060290603906049060590606906079060890609906109061190612906139061490615906169061790618906199062090621906229062390624906259062690627906289062990630906319063290633906349063590636906379063890639906409064190642906439064490645906469064790648906499065090651906529065390654906559065690657906589065990660906619066290663906649066590666906679066890669906709067190672906739067490675906769067790678906799068090681906829068390684906859068690687906889068990690906919069290693906949069590696906979069890699907009070190702907039070490705907069070790708907099071090711907129071390714907159071690717907189071990720907219072290723907249072590726907279072890729907309073190732907339073490735907369073790738907399074090741907429074390744907459074690747907489074990750907519075290753907549075590756907579075890759907609076190762907639076490765907669076790768907699077090771907729077390774907759077690777907789077990780907819078290783907849078590786907879078890789907909079190792907939079490795907969079790798907999080090801908029080390804908059080690807908089080990810908119081290813908149081590816908179081890819908209082190822908239082490825908269082790828908299083090831908329083390834908359083690837908389083990840908419084290843908449084590846908479084890849908509085190852908539085490855908569085790858908599086090861908629086390864908659086690867908689086990870908719087290873908749087590876908779087890879908809088190882908839088490885908869088790888908899089090891908929089390894908959089690897908989089990900909019090290903909049090590906909079090890909909109091190912909139091490915909169091790918909199092090921909229092390924909259092690927909289092990930909319093290933909349093590936909379093890939909409094190942909439094490945909469094790948909499095090951909529095390954909559095690957909589095990960909619096290963909649096590966909679096890969909709097190972909739097490975909769097790978909799098090981909829098390984909859098690987909889098990990909919099290993909949099590996909979099890999910009100191002910039100491005910069100791008910099101091011910129101391014910159101691017910189101991020910219102291023910249102591026910279102891029910309103191032910339103491035910369103791038910399104091041910429104391044910459104691047910489104991050910519105291053910549105591056910579105891059910609106191062910639106491065910669106791068910699107091071910729107391074910759107691077910789107991080910819108291083910849108591086910879108891089910909109191092910939109491095910969109791098910999110091101911029110391104911059110691107911089110991110911119111291113911149111591116911179111891119911209112191122911239112491125911269112791128911299113091131911329113391134911359113691137911389113991140911419114291143911449114591146911479114891149911509115191152911539115491155911569115791158911599116091161911629116391164911659116691167911689116991170911719117291173911749117591176911779117891179911809118191182911839118491185911869118791188911899119091191911929119391194911959119691197911989119991200912019120291203912049120591206912079120891209912109121191212912139121491215912169121791218912199122091221912229122391224912259122691227912289122991230912319123291233912349123591236912379123891239912409124191242912439124491245912469124791248912499125091251912529125391254912559125691257912589125991260912619126291263912649126591266912679126891269912709127191272912739127491275912769127791278912799128091281912829128391284912859128691287912889128991290912919129291293912949129591296912979129891299913009130191302913039130491305913069130791308913099131091311913129131391314913159131691317913189131991320913219132291323913249132591326913279132891329913309133191332913339133491335913369133791338913399134091341913429134391344913459134691347913489134991350913519135291353913549135591356913579135891359913609136191362913639136491365913669136791368913699137091371913729137391374913759137691377913789137991380913819138291383913849138591386913879138891389913909139191392913939139491395913969139791398913999140091401914029140391404914059140691407914089140991410914119141291413914149141591416914179141891419914209142191422914239142491425914269142791428914299143091431914329143391434914359143691437914389143991440914419144291443914449144591446914479144891449914509145191452914539145491455914569145791458914599146091461914629146391464914659146691467914689146991470914719147291473914749147591476914779147891479914809148191482914839148491485914869148791488914899149091491914929149391494914959149691497914989149991500915019150291503915049150591506915079150891509915109151191512915139151491515915169151791518915199152091521915229152391524915259152691527915289152991530915319153291533915349153591536915379153891539915409154191542915439154491545915469154791548915499155091551915529155391554915559155691557915589155991560915619156291563915649156591566915679156891569915709157191572915739157491575915769157791578915799158091581915829158391584915859158691587915889158991590915919159291593915949159591596915979159891599916009160191602916039160491605916069160791608916099161091611916129161391614916159161691617916189161991620916219162291623916249162591626916279162891629916309163191632916339163491635916369163791638916399164091641916429164391644916459164691647916489164991650916519165291653916549165591656916579165891659916609166191662916639166491665916669166791668916699167091671916729167391674916759167691677916789167991680916819168291683916849168591686916879168891689916909169191692916939169491695916969169791698916999170091701917029170391704917059170691707917089170991710917119171291713917149171591716917179171891719917209172191722917239172491725917269172791728917299173091731917329173391734917359173691737917389173991740917419174291743917449174591746917479174891749917509175191752917539175491755917569175791758917599176091761917629176391764917659176691767917689176991770917719177291773917749177591776917779177891779917809178191782917839178491785917869178791788917899179091791917929179391794917959179691797917989179991800918019180291803918049180591806918079180891809918109181191812918139181491815918169181791818918199182091821918229182391824918259182691827918289182991830918319183291833918349183591836918379183891839918409184191842918439184491845918469184791848918499185091851918529185391854918559185691857918589185991860918619186291863918649186591866918679186891869918709187191872918739187491875918769187791878918799188091881918829188391884918859188691887918889188991890918919189291893918949189591896918979189891899919009190191902919039190491905919069190791908919099191091911919129191391914919159191691917919189191991920919219192291923919249192591926919279192891929919309193191932919339193491935919369193791938919399194091941919429194391944919459194691947919489194991950919519195291953919549195591956919579195891959919609196191962919639196491965919669196791968919699197091971919729197391974919759197691977919789197991980919819198291983919849198591986919879198891989919909199191992919939199491995919969199791998919999200092001920029200392004920059200692007920089200992010920119201292013920149201592016920179201892019920209202192022920239202492025920269202792028920299203092031920329203392034920359203692037920389203992040920419204292043920449204592046920479204892049920509205192052920539205492055920569205792058920599206092061920629206392064920659206692067920689206992070920719207292073920749207592076920779207892079920809208192082920839208492085920869208792088920899209092091920929209392094920959209692097920989209992100921019210292103921049210592106921079210892109921109211192112921139211492115921169211792118921199212092121921229212392124921259212692127921289212992130921319213292133921349213592136921379213892139921409214192142921439214492145921469214792148921499215092151921529215392154921559215692157921589215992160921619216292163921649216592166921679216892169921709217192172921739217492175921769217792178921799218092181921829218392184921859218692187921889218992190921919219292193921949219592196921979219892199922009220192202922039220492205922069220792208922099221092211922129221392214922159221692217922189221992220922219222292223922249222592226922279222892229922309223192232922339223492235922369223792238922399224092241922429224392244922459224692247922489224992250922519225292253922549225592256922579225892259922609226192262922639226492265922669226792268922699227092271922729227392274922759227692277922789227992280922819228292283922849228592286922879228892289922909229192292922939229492295922969229792298922999230092301923029230392304923059230692307923089230992310923119231292313923149231592316923179231892319923209232192322923239232492325923269232792328923299233092331923329233392334923359233692337923389233992340923419234292343923449234592346923479234892349923509235192352923539235492355923569235792358923599236092361923629236392364923659236692367923689236992370923719237292373923749237592376923779237892379923809238192382923839238492385923869238792388923899239092391923929239392394923959239692397923989239992400924019240292403924049240592406924079240892409924109241192412924139241492415924169241792418924199242092421924229242392424924259242692427924289242992430924319243292433924349243592436924379243892439924409244192442924439244492445924469244792448924499245092451924529245392454924559245692457924589245992460924619246292463924649246592466924679246892469924709247192472924739247492475924769247792478924799248092481924829248392484924859248692487924889248992490924919249292493924949249592496924979249892499925009250192502925039250492505925069250792508925099251092511925129251392514925159251692517925189251992520925219252292523925249252592526925279252892529925309253192532925339253492535925369253792538925399254092541925429254392544925459254692547925489254992550925519255292553925549255592556925579255892559925609256192562925639256492565925669256792568925699257092571925729257392574925759257692577925789257992580925819258292583925849258592586925879258892589925909259192592925939259492595925969259792598925999260092601926029260392604926059260692607926089260992610926119261292613926149261592616926179261892619926209262192622926239262492625926269262792628926299263092631926329263392634926359263692637926389263992640926419264292643926449264592646926479264892649926509265192652926539265492655926569265792658926599266092661926629266392664926659266692667926689266992670926719267292673926749267592676926779267892679926809268192682926839268492685926869268792688926899269092691926929269392694926959269692697926989269992700927019270292703927049270592706927079270892709927109271192712927139271492715927169271792718927199272092721927229272392724927259272692727927289272992730927319273292733927349273592736927379273892739927409274192742927439274492745927469274792748927499275092751927529275392754927559275692757927589275992760927619276292763927649276592766927679276892769927709277192772927739277492775927769277792778927799278092781927829278392784927859278692787927889278992790927919279292793927949279592796927979279892799928009280192802928039280492805928069280792808928099281092811928129281392814928159281692817928189281992820928219282292823928249282592826928279282892829928309283192832928339283492835928369283792838928399284092841928429284392844928459284692847928489284992850928519285292853928549285592856928579285892859928609286192862928639286492865928669286792868928699287092871928729287392874928759287692877928789287992880928819288292883928849288592886928879288892889928909289192892928939289492895928969289792898928999290092901929029290392904929059290692907929089290992910929119291292913929149291592916929179291892919929209292192922929239292492925929269292792928929299293092931929329293392934929359293692937929389293992940929419294292943929449294592946929479294892949929509295192952929539295492955929569295792958929599296092961929629296392964929659296692967929689296992970929719297292973929749297592976929779297892979929809298192982929839298492985929869298792988929899299092991929929299392994929959299692997929989299993000930019300293003930049300593006930079300893009930109301193012930139301493015930169301793018930199302093021930229302393024930259302693027930289302993030930319303293033930349303593036930379303893039930409304193042930439304493045930469304793048930499305093051930529305393054930559305693057930589305993060930619306293063930649306593066930679306893069930709307193072930739307493075930769307793078930799308093081930829308393084930859308693087930889308993090930919309293093930949309593096930979309893099931009310193102931039310493105931069310793108931099311093111931129311393114931159311693117931189311993120931219312293123931249312593126931279312893129931309313193132931339313493135931369313793138931399314093141931429314393144931459314693147931489314993150931519315293153931549315593156931579315893159931609316193162931639316493165931669316793168931699317093171931729317393174931759317693177931789317993180931819318293183931849318593186931879318893189931909319193192931939319493195931969319793198931999320093201932029320393204932059320693207932089320993210932119321293213932149321593216932179321893219932209322193222932239322493225932269322793228932299323093231932329323393234932359323693237932389323993240932419324293243932449324593246932479324893249932509325193252932539325493255932569325793258932599326093261932629326393264932659326693267932689326993270932719327293273932749327593276932779327893279932809328193282932839328493285932869328793288932899329093291932929329393294932959329693297932989329993300933019330293303933049330593306933079330893309933109331193312933139331493315933169331793318933199332093321933229332393324933259332693327933289332993330933319333293333933349333593336933379333893339933409334193342933439334493345933469334793348933499335093351933529335393354933559335693357933589335993360933619336293363933649336593366933679336893369933709337193372933739337493375933769337793378933799338093381933829338393384933859338693387933889338993390933919339293393933949339593396933979339893399934009340193402934039340493405934069340793408934099341093411934129341393414934159341693417934189341993420934219342293423934249342593426934279342893429934309343193432934339343493435934369343793438934399344093441934429344393444934459344693447934489344993450934519345293453934549345593456934579345893459934609346193462934639346493465934669346793468934699347093471934729347393474934759347693477934789347993480934819348293483934849348593486934879348893489934909349193492934939349493495934969349793498934999350093501935029350393504935059350693507935089350993510935119351293513935149351593516935179351893519935209352193522935239352493525935269352793528935299353093531935329353393534935359353693537935389353993540935419354293543935449354593546935479354893549935509355193552935539355493555935569355793558935599356093561935629356393564935659356693567935689356993570935719357293573935749357593576935779357893579935809358193582935839358493585935869358793588935899359093591935929359393594935959359693597935989359993600936019360293603936049360593606936079360893609936109361193612936139361493615936169361793618936199362093621936229362393624936259362693627936289362993630936319363293633936349363593636936379363893639936409364193642936439364493645936469364793648936499365093651936529365393654936559365693657936589365993660936619366293663936649366593666936679366893669936709367193672936739367493675936769367793678936799368093681936829368393684936859368693687936889368993690936919369293693936949369593696936979369893699937009370193702937039370493705937069370793708937099371093711937129371393714937159371693717937189371993720937219372293723937249372593726937279372893729937309373193732937339373493735937369373793738937399374093741937429374393744937459374693747937489374993750937519375293753937549375593756937579375893759937609376193762937639376493765937669376793768937699377093771937729377393774937759377693777937789377993780937819378293783937849378593786937879378893789937909379193792937939379493795937969379793798937999380093801938029380393804938059380693807938089380993810938119381293813938149381593816938179381893819938209382193822938239382493825938269382793828938299383093831938329383393834938359383693837938389383993840938419384293843938449384593846938479384893849938509385193852938539385493855938569385793858938599386093861938629386393864938659386693867938689386993870938719387293873938749387593876938779387893879938809388193882938839388493885938869388793888938899389093891938929389393894938959389693897938989389993900939019390293903939049390593906939079390893909939109391193912939139391493915939169391793918939199392093921939229392393924939259392693927939289392993930939319393293933939349393593936939379393893939939409394193942939439394493945939469394793948939499395093951939529395393954939559395693957939589395993960939619396293963939649396593966939679396893969939709397193972939739397493975939769397793978939799398093981939829398393984939859398693987939889398993990939919399293993939949399593996939979399893999940009400194002940039400494005940069400794008940099401094011940129401394014940159401694017940189401994020940219402294023940249402594026940279402894029940309403194032940339403494035940369403794038940399404094041940429404394044940459404694047940489404994050940519405294053940549405594056940579405894059940609406194062940639406494065940669406794068940699407094071940729407394074940759407694077940789407994080940819408294083940849408594086940879408894089940909409194092940939409494095940969409794098940999410094101941029410394104941059410694107941089410994110941119411294113941149411594116941179411894119941209412194122941239412494125941269412794128941299413094131941329413394134941359413694137941389413994140941419414294143941449414594146941479414894149941509415194152941539415494155941569415794158941599416094161941629416394164941659416694167941689416994170941719417294173941749417594176941779417894179941809418194182941839418494185941869418794188941899419094191941929419394194941959419694197941989419994200942019420294203942049420594206942079420894209942109421194212942139421494215942169421794218942199422094221942229422394224942259422694227942289422994230942319423294233942349423594236942379423894239942409424194242942439424494245942469424794248942499425094251942529425394254942559425694257942589425994260942619426294263942649426594266942679426894269942709427194272942739427494275942769427794278942799428094281942829428394284942859428694287942889428994290942919429294293942949429594296942979429894299943009430194302943039430494305943069430794308943099431094311943129431394314943159431694317943189431994320943219432294323943249432594326943279432894329943309433194332943339433494335943369433794338943399434094341943429434394344943459434694347943489434994350943519435294353943549435594356943579435894359943609436194362943639436494365943669436794368943699437094371943729437394374943759437694377943789437994380943819438294383943849438594386943879438894389943909439194392943939439494395943969439794398943999440094401944029440394404944059440694407944089440994410944119441294413944149441594416944179441894419944209442194422944239442494425944269442794428944299443094431944329443394434944359443694437944389443994440944419444294443944449444594446944479444894449944509445194452944539445494455944569445794458944599446094461944629446394464944659446694467944689446994470944719447294473944749447594476944779447894479944809448194482944839448494485944869448794488944899449094491944929449394494944959449694497944989449994500945019450294503945049450594506945079450894509945109451194512945139451494515945169451794518945199452094521945229452394524945259452694527945289452994530945319453294533945349453594536945379453894539945409454194542945439454494545945469454794548945499455094551945529455394554945559455694557945589455994560945619456294563945649456594566945679456894569945709457194572945739457494575945769457794578945799458094581945829458394584945859458694587945889458994590945919459294593945949459594596945979459894599946009460194602946039460494605946069460794608946099461094611946129461394614946159461694617946189461994620946219462294623946249462594626946279462894629946309463194632946339463494635946369463794638946399464094641946429464394644946459464694647946489464994650946519465294653946549465594656946579465894659946609466194662946639466494665946669466794668946699467094671946729467394674946759467694677946789467994680946819468294683946849468594686946879468894689946909469194692946939469494695946969469794698946999470094701947029470394704947059470694707947089470994710947119471294713947149471594716947179471894719947209472194722947239472494725947269472794728947299473094731947329473394734947359473694737947389473994740947419474294743947449474594746947479474894749947509475194752947539475494755947569475794758947599476094761947629476394764947659476694767947689476994770947719477294773947749477594776947779477894779947809478194782947839478494785947869478794788947899479094791947929479394794947959479694797947989479994800948019480294803948049480594806948079480894809948109481194812948139481494815948169481794818948199482094821948229482394824948259482694827948289482994830948319483294833948349483594836948379483894839948409484194842948439484494845948469484794848948499485094851948529485394854948559485694857948589485994860948619486294863948649486594866948679486894869948709487194872948739487494875948769487794878948799488094881948829488394884948859488694887948889488994890948919489294893948949489594896948979489894899949009490194902949039490494905949069490794908949099491094911949129491394914949159491694917949189491994920949219492294923949249492594926949279492894929949309493194932949339493494935949369493794938949399494094941949429494394944949459494694947949489494994950949519495294953949549495594956949579495894959949609496194962949639496494965949669496794968949699497094971949729497394974949759497694977949789497994980949819498294983949849498594986949879498894989949909499194992949939499494995949969499794998949999500095001950029500395004950059500695007950089500995010950119501295013950149501595016950179501895019950209502195022950239502495025950269502795028950299503095031950329503395034950359503695037950389503995040950419504295043950449504595046950479504895049950509505195052950539505495055950569505795058950599506095061950629506395064950659506695067950689506995070950719507295073950749507595076950779507895079950809508195082950839508495085950869508795088950899509095091950929509395094950959509695097950989509995100951019510295103951049510595106951079510895109951109511195112951139511495115951169511795118951199512095121951229512395124951259512695127951289512995130951319513295133951349513595136951379513895139951409514195142951439514495145951469514795148951499515095151951529515395154951559515695157951589515995160951619516295163951649516595166951679516895169951709517195172951739517495175951769517795178951799518095181951829518395184951859518695187951889518995190951919519295193951949519595196951979519895199952009520195202952039520495205952069520795208952099521095211952129521395214952159521695217952189521995220952219522295223952249522595226952279522895229952309523195232952339523495235952369523795238952399524095241952429524395244952459524695247952489524995250952519525295253952549525595256952579525895259952609526195262952639526495265952669526795268952699527095271952729527395274952759527695277952789527995280952819528295283952849528595286952879528895289952909529195292952939529495295952969529795298952999530095301953029530395304953059530695307953089530995310953119531295313953149531595316953179531895319953209532195322953239532495325953269532795328953299533095331953329533395334953359533695337953389533995340953419534295343953449534595346953479534895349953509535195352953539535495355953569535795358953599536095361953629536395364953659536695367953689536995370953719537295373953749537595376953779537895379953809538195382953839538495385953869538795388953899539095391953929539395394953959539695397953989539995400954019540295403954049540595406954079540895409954109541195412954139541495415954169541795418954199542095421954229542395424954259542695427954289542995430954319543295433954349543595436954379543895439954409544195442954439544495445954469544795448954499545095451954529545395454954559545695457954589545995460954619546295463954649546595466954679546895469954709547195472954739547495475954769547795478954799548095481954829548395484954859548695487954889548995490954919549295493954949549595496954979549895499955009550195502955039550495505955069550795508955099551095511955129551395514955159551695517955189551995520955219552295523955249552595526955279552895529955309553195532955339553495535955369553795538955399554095541955429554395544955459554695547955489554995550955519555295553955549555595556955579555895559955609556195562955639556495565955669556795568955699557095571955729557395574955759557695577955789557995580955819558295583955849558595586955879558895589955909559195592955939559495595955969559795598955999560095601956029560395604956059560695607956089560995610956119561295613956149561595616956179561895619956209562195622956239562495625956269562795628956299563095631956329563395634956359563695637956389563995640956419564295643956449564595646956479564895649956509565195652956539565495655956569565795658956599566095661956629566395664956659566695667956689566995670956719567295673956749567595676956779567895679956809568195682956839568495685956869568795688956899569095691956929569395694956959569695697956989569995700957019570295703957049570595706957079570895709957109571195712957139571495715957169571795718957199572095721957229572395724957259572695727957289572995730957319573295733957349573595736957379573895739957409574195742957439574495745957469574795748957499575095751957529575395754957559575695757957589575995760957619576295763957649576595766957679576895769957709577195772957739577495775957769577795778957799578095781957829578395784957859578695787957889578995790957919579295793957949579595796957979579895799958009580195802958039580495805958069580795808958099581095811958129581395814958159581695817958189581995820958219582295823958249582595826958279582895829958309583195832958339583495835958369583795838958399584095841958429584395844958459584695847958489584995850958519585295853958549585595856958579585895859958609586195862958639586495865958669586795868958699587095871958729587395874958759587695877958789587995880958819588295883958849588595886958879588895889958909589195892958939589495895958969589795898958999590095901959029590395904959059590695907959089590995910959119591295913959149591595916959179591895919959209592195922959239592495925959269592795928959299593095931959329593395934959359593695937959389593995940959419594295943959449594595946959479594895949959509595195952959539595495955959569595795958959599596095961959629596395964959659596695967959689596995970959719597295973959749597595976959779597895979959809598195982959839598495985959869598795988959899599095991959929599395994959959599695997959989599996000960019600296003960049600596006960079600896009960109601196012960139601496015960169601796018960199602096021960229602396024960259602696027960289602996030960319603296033960349603596036960379603896039960409604196042960439604496045960469604796048960499605096051960529605396054960559605696057960589605996060960619606296063960649606596066960679606896069960709607196072960739607496075960769607796078960799608096081960829608396084960859608696087960889608996090960919609296093960949609596096960979609896099961009610196102961039610496105961069610796108961099611096111961129611396114961159611696117961189611996120961219612296123961249612596126961279612896129961309613196132961339613496135961369613796138961399614096141961429614396144961459614696147961489614996150961519615296153961549615596156961579615896159961609616196162961639616496165961669616796168961699617096171961729617396174961759617696177961789617996180961819618296183961849618596186961879618896189961909619196192961939619496195961969619796198961999620096201962029620396204962059620696207962089620996210962119621296213962149621596216962179621896219962209622196222962239622496225962269622796228962299623096231962329623396234962359623696237962389623996240962419624296243962449624596246962479624896249962509625196252962539625496255962569625796258962599626096261962629626396264962659626696267962689626996270962719627296273962749627596276962779627896279962809628196282962839628496285962869628796288962899629096291962929629396294962959629696297962989629996300963019630296303963049630596306963079630896309963109631196312963139631496315963169631796318963199632096321963229632396324963259632696327963289632996330963319633296333963349633596336963379633896339963409634196342963439634496345963469634796348963499635096351963529635396354963559635696357963589635996360963619636296363963649636596366963679636896369963709637196372963739637496375963769637796378963799638096381963829638396384963859638696387963889638996390963919639296393963949639596396963979639896399964009640196402964039640496405964069640796408964099641096411964129641396414964159641696417964189641996420964219642296423964249642596426964279642896429964309643196432964339643496435964369643796438964399644096441964429644396444964459644696447964489644996450964519645296453964549645596456964579645896459964609646196462964639646496465964669646796468964699647096471964729647396474964759647696477964789647996480964819648296483964849648596486964879648896489964909649196492964939649496495964969649796498964999650096501965029650396504965059650696507965089650996510965119651296513965149651596516965179651896519965209652196522965239652496525965269652796528965299653096531965329653396534965359653696537965389653996540965419654296543965449654596546965479654896549965509655196552965539655496555965569655796558965599656096561965629656396564965659656696567965689656996570965719657296573965749657596576965779657896579965809658196582965839658496585965869658796588965899659096591965929659396594965959659696597965989659996600966019660296603966049660596606966079660896609966109661196612966139661496615966169661796618966199662096621966229662396624966259662696627966289662996630966319663296633966349663596636966379663896639966409664196642966439664496645966469664796648966499665096651966529665396654966559665696657966589665996660966619666296663966649666596666966679666896669966709667196672966739667496675966769667796678966799668096681966829668396684966859668696687966889668996690966919669296693966949669596696966979669896699967009670196702967039670496705967069670796708967099671096711967129671396714967159671696717967189671996720967219672296723967249672596726967279672896729967309673196732967339673496735967369673796738967399674096741967429674396744967459674696747967489674996750967519675296753967549675596756967579675896759967609676196762967639676496765967669676796768967699677096771967729677396774967759677696777967789677996780967819678296783967849678596786967879678896789967909679196792967939679496795967969679796798967999680096801968029680396804968059680696807968089680996810968119681296813968149681596816968179681896819968209682196822968239682496825968269682796828968299683096831968329683396834968359683696837968389683996840968419684296843968449684596846968479684896849968509685196852968539685496855968569685796858968599686096861968629686396864968659686696867968689686996870968719687296873968749687596876968779687896879968809688196882968839688496885968869688796888968899689096891968929689396894968959689696897968989689996900969019690296903969049690596906969079690896909969109691196912969139691496915969169691796918969199692096921969229692396924969259692696927969289692996930969319693296933969349693596936969379693896939969409694196942969439694496945969469694796948969499695096951969529695396954969559695696957969589695996960969619696296963969649696596966969679696896969969709697196972969739697496975969769697796978969799698096981969829698396984969859698696987969889698996990969919699296993969949699596996969979699896999970009700197002970039700497005970069700797008970099701097011970129701397014970159701697017970189701997020970219702297023970249702597026970279702897029970309703197032970339703497035970369703797038970399704097041970429704397044970459704697047970489704997050970519705297053970549705597056970579705897059970609706197062970639706497065970669706797068970699707097071970729707397074970759707697077970789707997080970819708297083970849708597086970879708897089970909709197092970939709497095970969709797098970999710097101971029710397104971059710697107971089710997110971119711297113971149711597116971179711897119971209712197122971239712497125971269712797128971299713097131971329713397134971359713697137971389713997140971419714297143971449714597146971479714897149971509715197152971539715497155971569715797158971599716097161971629716397164971659716697167971689716997170971719717297173971749717597176971779717897179971809718197182971839718497185971869718797188971899719097191971929719397194971959719697197971989719997200972019720297203972049720597206972079720897209972109721197212972139721497215972169721797218972199722097221972229722397224972259722697227972289722997230972319723297233972349723597236972379723897239972409724197242972439724497245972469724797248972499725097251972529725397254972559725697257972589725997260972619726297263972649726597266972679726897269972709727197272972739727497275972769727797278972799728097281972829728397284972859728697287972889728997290972919729297293972949729597296972979729897299973009730197302973039730497305973069730797308973099731097311973129731397314973159731697317973189731997320973219732297323973249732597326973279732897329973309733197332973339733497335973369733797338973399734097341973429734397344973459734697347973489734997350973519735297353973549735597356973579735897359973609736197362973639736497365973669736797368973699737097371973729737397374973759737697377973789737997380973819738297383973849738597386973879738897389973909739197392973939739497395973969739797398973999740097401974029740397404974059740697407974089740997410974119741297413974149741597416974179741897419974209742197422974239742497425974269742797428974299743097431974329743397434974359743697437974389743997440974419744297443974449744597446974479744897449974509745197452974539745497455974569745797458974599746097461974629746397464974659746697467974689746997470974719747297473974749747597476974779747897479974809748197482974839748497485974869748797488974899749097491974929749397494974959749697497974989749997500975019750297503975049750597506975079750897509975109751197512975139751497515975169751797518975199752097521975229752397524975259752697527975289752997530975319753297533975349753597536975379753897539975409754197542975439754497545975469754797548975499755097551975529755397554975559755697557975589755997560975619756297563975649756597566975679756897569975709757197572975739757497575975769757797578975799758097581975829758397584975859758697587975889758997590975919759297593975949759597596975979759897599976009760197602976039760497605976069760797608976099761097611976129761397614976159761697617976189761997620976219762297623976249762597626976279762897629976309763197632976339763497635976369763797638976399764097641976429764397644976459764697647976489764997650976519765297653976549765597656976579765897659976609766197662976639766497665976669766797668976699767097671976729767397674976759767697677976789767997680976819768297683976849768597686976879768897689976909769197692976939769497695976969769797698976999770097701977029770397704977059770697707977089770997710977119771297713977149771597716977179771897719977209772197722977239772497725977269772797728977299773097731977329773397734977359773697737977389773997740977419774297743977449774597746977479774897749977509775197752977539775497755977569775797758977599776097761977629776397764977659776697767977689776997770977719777297773977749777597776977779777897779977809778197782977839778497785977869778797788977899779097791977929779397794977959779697797977989779997800978019780297803978049780597806978079780897809978109781197812978139781497815978169781797818978199782097821978229782397824978259782697827978289782997830978319783297833978349783597836978379783897839978409784197842978439784497845978469784797848978499785097851978529785397854978559785697857978589785997860978619786297863978649786597866978679786897869978709787197872978739787497875978769787797878978799788097881978829788397884978859788697887978889788997890978919789297893978949789597896978979789897899979009790197902979039790497905979069790797908979099791097911979129791397914979159791697917979189791997920979219792297923979249792597926979279792897929979309793197932979339793497935979369793797938979399794097941979429794397944979459794697947979489794997950979519795297953979549795597956979579795897959979609796197962979639796497965979669796797968979699797097971979729797397974979759797697977979789797997980979819798297983979849798597986979879798897989979909799197992979939799497995979969799797998979999800098001980029800398004980059800698007980089800998010980119801298013980149801598016980179801898019980209802198022980239802498025980269802798028980299803098031980329803398034980359803698037980389803998040980419804298043980449804598046980479804898049980509805198052980539805498055980569805798058980599806098061980629806398064980659806698067980689806998070980719807298073980749807598076980779807898079980809808198082980839808498085980869808798088980899809098091980929809398094980959809698097980989809998100981019810298103981049810598106981079810898109981109811198112981139811498115981169811798118981199812098121981229812398124981259812698127981289812998130981319813298133981349813598136981379813898139981409814198142981439814498145981469814798148981499815098151981529815398154981559815698157981589815998160981619816298163981649816598166981679816898169981709817198172981739817498175981769817798178981799818098181981829818398184981859818698187981889818998190981919819298193981949819598196981979819898199982009820198202982039820498205982069820798208982099821098211982129821398214982159821698217982189821998220982219822298223982249822598226982279822898229982309823198232982339823498235982369823798238982399824098241982429824398244982459824698247982489824998250982519825298253982549825598256982579825898259982609826198262982639826498265982669826798268982699827098271982729827398274982759827698277982789827998280982819828298283982849828598286982879828898289982909829198292982939829498295982969829798298982999830098301983029830398304983059830698307983089830998310983119831298313983149831598316983179831898319983209832198322983239832498325983269832798328983299833098331983329833398334983359833698337983389833998340983419834298343983449834598346983479834898349983509835198352983539835498355983569835798358983599836098361983629836398364983659836698367983689836998370983719837298373983749837598376983779837898379983809838198382983839838498385983869838798388983899839098391983929839398394983959839698397983989839998400984019840298403984049840598406984079840898409984109841198412984139841498415984169841798418984199842098421984229842398424984259842698427984289842998430984319843298433984349843598436984379843898439984409844198442984439844498445984469844798448984499845098451984529845398454984559845698457984589845998460984619846298463984649846598466984679846898469984709847198472984739847498475984769847798478984799848098481984829848398484984859848698487984889848998490984919849298493984949849598496984979849898499985009850198502985039850498505985069850798508985099851098511985129851398514985159851698517985189851998520985219852298523985249852598526985279852898529985309853198532985339853498535985369853798538985399854098541985429854398544985459854698547985489854998550985519855298553985549855598556985579855898559985609856198562985639856498565985669856798568985699857098571985729857398574985759857698577985789857998580985819858298583985849858598586985879858898589985909859198592985939859498595985969859798598985999860098601986029860398604986059860698607986089860998610986119861298613986149861598616986179861898619986209862198622986239862498625986269862798628986299863098631986329863398634986359863698637986389863998640986419864298643986449864598646986479864898649986509865198652986539865498655986569865798658986599866098661986629866398664986659866698667986689866998670986719867298673986749867598676986779867898679986809868198682986839868498685986869868798688986899869098691986929869398694986959869698697986989869998700987019870298703987049870598706987079870898709987109871198712987139871498715987169871798718987199872098721987229872398724987259872698727987289872998730987319873298733987349873598736987379873898739987409874198742987439874498745987469874798748987499875098751987529875398754987559875698757987589875998760987619876298763987649876598766987679876898769987709877198772987739877498775987769877798778987799878098781987829878398784987859878698787987889878998790987919879298793987949879598796987979879898799988009880198802988039880498805988069880798808988099881098811988129881398814988159881698817988189881998820988219882298823988249882598826988279882898829988309883198832988339883498835988369883798838988399884098841988429884398844988459884698847988489884998850988519885298853988549885598856988579885898859988609886198862988639886498865988669886798868988699887098871988729887398874988759887698877988789887998880988819888298883988849888598886988879888898889988909889198892988939889498895988969889798898988999890098901989029890398904989059890698907989089890998910989119891298913989149891598916989179891898919989209892198922989239892498925989269892798928989299893098931989329893398934989359893698937989389893998940989419894298943989449894598946989479894898949989509895198952989539895498955989569895798958989599896098961989629896398964989659896698967989689896998970989719897298973989749897598976989779897898979989809898198982989839898498985989869898798988989899899098991989929899398994989959899698997989989899999000990019900299003990049900599006990079900899009990109901199012990139901499015990169901799018990199902099021990229902399024990259902699027990289902999030990319903299033990349903599036990379903899039990409904199042990439904499045990469904799048990499905099051990529905399054990559905699057990589905999060990619906299063990649906599066990679906899069990709907199072990739907499075990769907799078990799908099081990829908399084990859908699087990889908999090990919909299093990949909599096990979909899099991009910199102991039910499105991069910799108991099911099111991129911399114991159911699117991189911999120991219912299123991249912599126991279912899129991309913199132991339913499135991369913799138991399914099141991429914399144991459914699147991489914999150991519915299153991549915599156991579915899159991609916199162991639916499165991669916799168991699917099171991729917399174991759917699177991789917999180991819918299183991849918599186991879918899189991909919199192991939919499195991969919799198991999920099201992029920399204992059920699207992089920999210992119921299213992149921599216992179921899219992209922199222992239922499225992269922799228992299923099231992329923399234992359923699237992389923999240992419924299243992449924599246992479924899249992509925199252992539925499255992569925799258992599926099261992629926399264992659926699267992689926999270992719927299273992749927599276992779927899279992809928199282992839928499285992869928799288992899929099291992929929399294992959929699297992989929999300993019930299303993049930599306993079930899309993109931199312993139931499315993169931799318993199932099321993229932399324993259932699327993289932999330993319933299333993349933599336993379933899339993409934199342993439934499345993469934799348993499935099351993529935399354993559935699357993589935999360993619936299363993649936599366993679936899369993709937199372993739937499375993769937799378993799938099381993829938399384993859938699387993889938999390993919939299393993949939599396993979939899399994009940199402994039940499405994069940799408994099941099411994129941399414994159941699417994189941999420994219942299423994249942599426994279942899429994309943199432994339943499435994369943799438994399944099441994429944399444994459944699447994489944999450994519945299453994549945599456994579945899459994609946199462994639946499465994669946799468994699947099471994729947399474994759947699477994789947999480994819948299483994849948599486994879948899489994909949199492994939949499495994969949799498994999950099501995029950399504995059950699507995089950999510995119951299513995149951599516995179951899519995209952199522995239952499525995269952799528995299953099531995329953399534995359953699537995389953999540995419954299543995449954599546995479954899549995509955199552995539955499555995569955799558995599956099561995629956399564995659956699567995689956999570995719957299573995749957599576995779957899579995809958199582995839958499585995869958799588995899959099591995929959399594995959959699597995989959999600996019960299603996049960599606996079960899609996109961199612996139961499615996169961799618996199962099621996229962399624996259962699627996289962999630996319963299633996349963599636996379963899639996409964199642996439964499645996469964799648996499965099651996529965399654996559965699657996589965999660996619966299663996649966599666996679966899669996709967199672996739967499675996769967799678996799968099681996829968399684996859968699687996889968999690996919969299693996949969599696996979969899699997009970199702997039970499705997069970799708997099971099711997129971399714997159971699717997189971999720997219972299723997249972599726997279972899729997309973199732997339973499735997369973799738997399974099741997429974399744997459974699747997489974999750997519975299753997549975599756997579975899759997609976199762997639976499765997669976799768997699977099771997729977399774997759977699777997789977999780997819978299783997849978599786997879978899789997909979199792997939979499795997969979799798997999980099801998029980399804998059980699807998089980999810998119981299813998149981599816998179981899819998209982199822998239982499825998269982799828998299983099831998329983399834998359983699837998389983999840998419984299843998449984599846998479984899849998509985199852998539985499855998569985799858998599986099861998629986399864998659986699867998689986999870998719987299873998749987599876998779987899879998809988199882998839988499885998869988799888998899989099891998929989399894998959989699897998989989999900999019990299903999049990599906999079990899909999109991199912999139991499915999169991799918999199992099921999229992399924999259992699927999289992999930999319993299933999349993599936999379993899939999409994199942999439994499945999469994799948999499995099951999529995399954999559995699957999589995999960999619996299963999649996599966999679996899969999709997199972999739997499975999769997799978999799998099981999829998399984999859998699987999889998999990999919999299993999949999599996999979999899999100000100001100002100003100004100005100006100007100008100009100010100011100012100013100014100015100016100017100018100019100020100021100022100023100024100025100026100027100028100029100030100031100032100033100034100035100036100037100038100039100040100041100042100043100044100045100046100047100048100049100050100051100052100053100054100055100056100057100058100059100060100061100062100063100064100065100066100067100068100069100070100071100072100073100074100075100076100077100078100079100080100081100082100083100084100085100086100087100088100089100090100091100092100093100094100095100096100097100098100099100100100101100102100103100104100105100106100107100108100109100110100111100112100113100114100115100116100117100118100119100120100121100122100123100124100125100126100127100128100129100130100131100132100133100134100135100136100137100138100139100140100141100142100143100144100145100146100147100148100149100150100151100152100153100154100155100156100157100158100159100160100161100162100163100164100165100166100167100168100169100170100171100172100173100174100175100176100177100178100179100180100181100182100183100184100185100186100187100188100189100190100191100192100193100194100195100196100197100198100199100200100201100202100203100204100205100206100207100208100209100210100211100212100213100214100215100216100217100218100219100220100221100222100223100224100225100226100227100228100229100230100231100232100233100234100235100236100237100238100239100240100241100242100243100244100245100246100247100248100249100250100251100252100253100254100255100256100257100258100259100260100261100262100263100264100265100266100267100268100269100270100271100272100273100274100275100276100277100278100279100280100281100282100283100284100285100286100287100288100289100290100291100292100293100294100295100296100297100298100299100300100301100302100303100304100305100306100307100308100309100310100311100312100313100314100315100316100317100318100319100320100321100322100323100324100325100326100327100328100329100330100331100332100333100334100335100336100337100338100339100340100341100342100343100344100345100346100347100348100349100350100351100352100353100354100355100356100357100358100359100360100361100362100363100364100365100366100367100368100369100370100371100372100373100374100375100376100377100378100379100380100381100382100383100384100385100386100387100388100389100390100391100392100393100394100395100396100397100398100399100400100401100402100403100404100405100406100407100408100409100410100411100412100413100414100415100416100417100418100419100420100421100422100423100424100425100426100427100428100429100430100431100432100433100434100435100436100437100438100439100440100441100442100443100444100445100446100447100448100449100450100451100452100453100454100455100456100457100458100459100460100461100462100463100464100465100466100467100468100469100470100471100472100473100474100475100476100477100478100479100480100481100482100483100484100485100486100487100488100489100490100491100492100493100494100495100496100497100498100499100500100501100502100503100504100505100506100507100508100509100510100511100512100513100514100515100516100517100518100519100520100521100522100523100524100525100526100527100528100529100530100531100532100533100534100535100536100537100538100539100540100541100542
  1. diff -Nur linux-3.13.3.orig/arch/arm/configs/bcmrpi_cutdown_defconfig linux-3.13.3/arch/arm/configs/bcmrpi_cutdown_defconfig
  2. --- linux-3.13.3.orig/arch/arm/configs/bcmrpi_cutdown_defconfig 1970-01-01 01:00:00.000000000 +0100
  3. +++ linux-3.13.3/arch/arm/configs/bcmrpi_cutdown_defconfig 2014-02-17 22:41:01.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.13.3.orig/arch/arm/configs/bcmrpi_defconfig linux-3.13.3/arch/arm/configs/bcmrpi_defconfig
  509. --- linux-3.13.3.orig/arch/arm/configs/bcmrpi_defconfig 1970-01-01 01:00:00.000000000 +0100
  510. +++ linux-3.13.3/arch/arm/configs/bcmrpi_defconfig 2014-02-17 22:41:01.000000000 +0100
  511. @@ -0,0 +1,1088 @@
  512. +# CONFIG_ARM_PATCH_PHYS_VIRT is not set
  513. +# CONFIG_LOCALVERSION_AUTO is not set
  514. +CONFIG_SYSVIPC=y
  515. +CONFIG_POSIX_MQUEUE=y
  516. +CONFIG_FHANDLE=y
  517. +CONFIG_AUDIT=y
  518. +CONFIG_NO_HZ=y
  519. +CONFIG_HIGH_RES_TIMERS=y
  520. +CONFIG_BSD_PROCESS_ACCT=y
  521. +CONFIG_BSD_PROCESS_ACCT_V3=y
  522. +CONFIG_TASKSTATS=y
  523. +CONFIG_TASK_DELAY_ACCT=y
  524. +CONFIG_TASK_XACCT=y
  525. +CONFIG_TASK_IO_ACCOUNTING=y
  526. +CONFIG_IKCONFIG=y
  527. +CONFIG_IKCONFIG_PROC=y
  528. +CONFIG_CGROUP_FREEZER=y
  529. +CONFIG_CGROUP_DEVICE=y
  530. +CONFIG_CGROUP_CPUACCT=y
  531. +CONFIG_RESOURCE_COUNTERS=y
  532. +CONFIG_MEMCG=y
  533. +CONFIG_BLK_CGROUP=y
  534. +CONFIG_NAMESPACES=y
  535. +CONFIG_SCHED_AUTOGROUP=y
  536. +CONFIG_RELAY=y
  537. +CONFIG_BLK_DEV_INITRD=y
  538. +CONFIG_EMBEDDED=y
  539. +# CONFIG_COMPAT_BRK is not set
  540. +CONFIG_PROFILING=y
  541. +CONFIG_OPROFILE=m
  542. +CONFIG_KPROBES=y
  543. +CONFIG_JUMP_LABEL=y
  544. +CONFIG_MODULES=y
  545. +CONFIG_MODULE_UNLOAD=y
  546. +CONFIG_MODVERSIONS=y
  547. +CONFIG_MODULE_SRCVERSION_ALL=y
  548. +CONFIG_BLK_DEV_THROTTLING=y
  549. +CONFIG_PARTITION_ADVANCED=y
  550. +CONFIG_MAC_PARTITION=y
  551. +CONFIG_CFQ_GROUP_IOSCHED=y
  552. +CONFIG_ARCH_BCM2708=y
  553. +CONFIG_PREEMPT=y
  554. +CONFIG_AEABI=y
  555. +CONFIG_CLEANCACHE=y
  556. +CONFIG_FRONTSWAP=y
  557. +CONFIG_CMA=y
  558. +CONFIG_UACCESS_WITH_MEMCPY=y
  559. +CONFIG_SECCOMP=y
  560. +CONFIG_CC_STACKPROTECTOR=y
  561. +CONFIG_ZBOOT_ROM_TEXT=0x0
  562. +CONFIG_ZBOOT_ROM_BSS=0x0
  563. +CONFIG_CMDLINE="console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait"
  564. +CONFIG_KEXEC=y
  565. +CONFIG_CPU_FREQ=y
  566. +CONFIG_CPU_FREQ_STAT=m
  567. +CONFIG_CPU_FREQ_STAT_DETAILS=y
  568. +CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE=y
  569. +CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
  570. +CONFIG_CPU_FREQ_GOV_USERSPACE=y
  571. +CONFIG_CPU_FREQ_GOV_ONDEMAND=y
  572. +CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
  573. +CONFIG_CPU_IDLE=y
  574. +CONFIG_VFP=y
  575. +CONFIG_BINFMT_MISC=m
  576. +CONFIG_NET=y
  577. +CONFIG_PACKET=y
  578. +CONFIG_UNIX=y
  579. +CONFIG_XFRM_USER=y
  580. +CONFIG_NET_KEY=m
  581. +CONFIG_INET=y
  582. +CONFIG_IP_MULTICAST=y
  583. +CONFIG_IP_ADVANCED_ROUTER=y
  584. +CONFIG_IP_MULTIPLE_TABLES=y
  585. +CONFIG_IP_ROUTE_MULTIPATH=y
  586. +CONFIG_IP_ROUTE_VERBOSE=y
  587. +CONFIG_IP_PNP=y
  588. +CONFIG_IP_PNP_DHCP=y
  589. +CONFIG_IP_PNP_RARP=y
  590. +CONFIG_NET_IPIP=m
  591. +CONFIG_NET_IPGRE_DEMUX=m
  592. +CONFIG_NET_IPGRE=m
  593. +CONFIG_IP_MROUTE=y
  594. +CONFIG_IP_MROUTE_MULTIPLE_TABLES=y
  595. +CONFIG_IP_PIMSM_V1=y
  596. +CONFIG_IP_PIMSM_V2=y
  597. +CONFIG_SYN_COOKIES=y
  598. +CONFIG_INET_AH=m
  599. +CONFIG_INET_ESP=m
  600. +CONFIG_INET_IPCOMP=m
  601. +CONFIG_INET_XFRM_MODE_TRANSPORT=m
  602. +CONFIG_INET_XFRM_MODE_TUNNEL=m
  603. +CONFIG_INET_XFRM_MODE_BEET=m
  604. +CONFIG_INET_LRO=m
  605. +CONFIG_INET_DIAG=m
  606. +CONFIG_INET6_AH=m
  607. +CONFIG_INET6_ESP=m
  608. +CONFIG_INET6_IPCOMP=m
  609. +CONFIG_IPV6_TUNNEL=m
  610. +CONFIG_IPV6_MULTIPLE_TABLES=y
  611. +CONFIG_IPV6_MROUTE=y
  612. +CONFIG_IPV6_MROUTE_MULTIPLE_TABLES=y
  613. +CONFIG_IPV6_PIMSM_V2=y
  614. +CONFIG_NETFILTER=y
  615. +CONFIG_NF_CONNTRACK=m
  616. +CONFIG_NF_CONNTRACK_ZONES=y
  617. +CONFIG_NF_CONNTRACK_EVENTS=y
  618. +CONFIG_NF_CONNTRACK_TIMESTAMP=y
  619. +CONFIG_NF_CT_PROTO_DCCP=m
  620. +CONFIG_NF_CT_PROTO_UDPLITE=m
  621. +CONFIG_NF_CONNTRACK_AMANDA=m
  622. +CONFIG_NF_CONNTRACK_FTP=m
  623. +CONFIG_NF_CONNTRACK_H323=m
  624. +CONFIG_NF_CONNTRACK_IRC=m
  625. +CONFIG_NF_CONNTRACK_NETBIOS_NS=m
  626. +CONFIG_NF_CONNTRACK_SNMP=m
  627. +CONFIG_NF_CONNTRACK_PPTP=m
  628. +CONFIG_NF_CONNTRACK_SANE=m
  629. +CONFIG_NF_CONNTRACK_SIP=m
  630. +CONFIG_NF_CONNTRACK_TFTP=m
  631. +CONFIG_NF_CT_NETLINK=m
  632. +CONFIG_NETFILTER_XT_SET=m
  633. +CONFIG_NETFILTER_XT_TARGET_AUDIT=m
  634. +CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m
  635. +CONFIG_NETFILTER_XT_TARGET_CLASSIFY=m
  636. +CONFIG_NETFILTER_XT_TARGET_CONNMARK=m
  637. +CONFIG_NETFILTER_XT_TARGET_DSCP=m
  638. +CONFIG_NETFILTER_XT_TARGET_HMARK=m
  639. +CONFIG_NETFILTER_XT_TARGET_IDLETIMER=m
  640. +CONFIG_NETFILTER_XT_TARGET_LED=m
  641. +CONFIG_NETFILTER_XT_TARGET_LOG=m
  642. +CONFIG_NETFILTER_XT_TARGET_MARK=m
  643. +CONFIG_NETFILTER_XT_TARGET_NFLOG=m
  644. +CONFIG_NETFILTER_XT_TARGET_NFQUEUE=m
  645. +CONFIG_NETFILTER_XT_TARGET_NOTRACK=m
  646. +CONFIG_NETFILTER_XT_TARGET_TEE=m
  647. +CONFIG_NETFILTER_XT_TARGET_TPROXY=m
  648. +CONFIG_NETFILTER_XT_TARGET_TRACE=m
  649. +CONFIG_NETFILTER_XT_TARGET_TCPMSS=m
  650. +CONFIG_NETFILTER_XT_TARGET_TCPOPTSTRIP=m
  651. +CONFIG_NETFILTER_XT_MATCH_ADDRTYPE=m
  652. +CONFIG_NETFILTER_XT_MATCH_BPF=m
  653. +CONFIG_NETFILTER_XT_MATCH_CLUSTER=m
  654. +CONFIG_NETFILTER_XT_MATCH_COMMENT=m
  655. +CONFIG_NETFILTER_XT_MATCH_CONNBYTES=m
  656. +CONFIG_NETFILTER_XT_MATCH_CONNLABEL=m
  657. +CONFIG_NETFILTER_XT_MATCH_CONNLIMIT=m
  658. +CONFIG_NETFILTER_XT_MATCH_CONNMARK=m
  659. +CONFIG_NETFILTER_XT_MATCH_CONNTRACK=m
  660. +CONFIG_NETFILTER_XT_MATCH_CPU=m
  661. +CONFIG_NETFILTER_XT_MATCH_DCCP=m
  662. +CONFIG_NETFILTER_XT_MATCH_DEVGROUP=m
  663. +CONFIG_NETFILTER_XT_MATCH_DSCP=m
  664. +CONFIG_NETFILTER_XT_MATCH_ESP=m
  665. +CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m
  666. +CONFIG_NETFILTER_XT_MATCH_HELPER=m
  667. +CONFIG_NETFILTER_XT_MATCH_IPRANGE=m
  668. +CONFIG_NETFILTER_XT_MATCH_IPVS=m
  669. +CONFIG_NETFILTER_XT_MATCH_LENGTH=m
  670. +CONFIG_NETFILTER_XT_MATCH_LIMIT=m
  671. +CONFIG_NETFILTER_XT_MATCH_MAC=m
  672. +CONFIG_NETFILTER_XT_MATCH_MARK=m
  673. +CONFIG_NETFILTER_XT_MATCH_MULTIPORT=m
  674. +CONFIG_NETFILTER_XT_MATCH_NFACCT=m
  675. +CONFIG_NETFILTER_XT_MATCH_OSF=m
  676. +CONFIG_NETFILTER_XT_MATCH_OWNER=m
  677. +CONFIG_NETFILTER_XT_MATCH_POLICY=m
  678. +CONFIG_NETFILTER_XT_MATCH_PHYSDEV=m
  679. +CONFIG_NETFILTER_XT_MATCH_PKTTYPE=m
  680. +CONFIG_NETFILTER_XT_MATCH_QUOTA=m
  681. +CONFIG_NETFILTER_XT_MATCH_RATEEST=m
  682. +CONFIG_NETFILTER_XT_MATCH_REALM=m
  683. +CONFIG_NETFILTER_XT_MATCH_RECENT=m
  684. +CONFIG_NETFILTER_XT_MATCH_SOCKET=m
  685. +CONFIG_NETFILTER_XT_MATCH_STATE=m
  686. +CONFIG_NETFILTER_XT_MATCH_STATISTIC=m
  687. +CONFIG_NETFILTER_XT_MATCH_STRING=m
  688. +CONFIG_NETFILTER_XT_MATCH_TCPMSS=m
  689. +CONFIG_NETFILTER_XT_MATCH_TIME=m
  690. +CONFIG_NETFILTER_XT_MATCH_U32=m
  691. +CONFIG_IP_SET=m
  692. +CONFIG_IP_SET_BITMAP_IP=m
  693. +CONFIG_IP_SET_BITMAP_IPMAC=m
  694. +CONFIG_IP_SET_BITMAP_PORT=m
  695. +CONFIG_IP_SET_HASH_IP=m
  696. +CONFIG_IP_SET_HASH_IPPORT=m
  697. +CONFIG_IP_SET_HASH_IPPORTIP=m
  698. +CONFIG_IP_SET_HASH_IPPORTNET=m
  699. +CONFIG_IP_SET_HASH_NET=m
  700. +CONFIG_IP_SET_HASH_NETPORT=m
  701. +CONFIG_IP_SET_HASH_NETIFACE=m
  702. +CONFIG_IP_SET_LIST_SET=m
  703. +CONFIG_IP_VS=m
  704. +CONFIG_IP_VS_PROTO_TCP=y
  705. +CONFIG_IP_VS_PROTO_UDP=y
  706. +CONFIG_IP_VS_PROTO_ESP=y
  707. +CONFIG_IP_VS_PROTO_AH=y
  708. +CONFIG_IP_VS_PROTO_SCTP=y
  709. +CONFIG_IP_VS_RR=m
  710. +CONFIG_IP_VS_WRR=m
  711. +CONFIG_IP_VS_LC=m
  712. +CONFIG_IP_VS_WLC=m
  713. +CONFIG_IP_VS_LBLC=m
  714. +CONFIG_IP_VS_LBLCR=m
  715. +CONFIG_IP_VS_DH=m
  716. +CONFIG_IP_VS_SH=m
  717. +CONFIG_IP_VS_SED=m
  718. +CONFIG_IP_VS_NQ=m
  719. +CONFIG_IP_VS_FTP=m
  720. +CONFIG_IP_VS_PE_SIP=m
  721. +CONFIG_NF_CONNTRACK_IPV4=m
  722. +CONFIG_IP_NF_IPTABLES=m
  723. +CONFIG_IP_NF_MATCH_AH=m
  724. +CONFIG_IP_NF_MATCH_ECN=m
  725. +CONFIG_IP_NF_MATCH_TTL=m
  726. +CONFIG_IP_NF_FILTER=m
  727. +CONFIG_IP_NF_TARGET_REJECT=m
  728. +CONFIG_IP_NF_TARGET_ULOG=m
  729. +CONFIG_NF_NAT_IPV4=m
  730. +CONFIG_IP_NF_TARGET_MASQUERADE=m
  731. +CONFIG_IP_NF_TARGET_NETMAP=m
  732. +CONFIG_IP_NF_TARGET_REDIRECT=m
  733. +CONFIG_IP_NF_MANGLE=m
  734. +CONFIG_IP_NF_TARGET_ECN=m
  735. +CONFIG_IP_NF_TARGET_TTL=m
  736. +CONFIG_IP_NF_RAW=m
  737. +CONFIG_IP_NF_ARPTABLES=m
  738. +CONFIG_IP_NF_ARPFILTER=m
  739. +CONFIG_IP_NF_ARP_MANGLE=m
  740. +CONFIG_NF_CONNTRACK_IPV6=m
  741. +CONFIG_IP6_NF_IPTABLES=m
  742. +CONFIG_IP6_NF_MATCH_AH=m
  743. +CONFIG_IP6_NF_MATCH_EUI64=m
  744. +CONFIG_IP6_NF_MATCH_FRAG=m
  745. +CONFIG_IP6_NF_MATCH_OPTS=m
  746. +CONFIG_IP6_NF_MATCH_HL=m
  747. +CONFIG_IP6_NF_MATCH_IPV6HEADER=m
  748. +CONFIG_IP6_NF_MATCH_MH=m
  749. +CONFIG_IP6_NF_MATCH_RT=m
  750. +CONFIG_IP6_NF_TARGET_HL=m
  751. +CONFIG_IP6_NF_FILTER=m
  752. +CONFIG_IP6_NF_TARGET_REJECT=m
  753. +CONFIG_IP6_NF_MANGLE=m
  754. +CONFIG_IP6_NF_RAW=m
  755. +CONFIG_NF_NAT_IPV6=m
  756. +CONFIG_IP6_NF_TARGET_MASQUERADE=m
  757. +CONFIG_IP6_NF_TARGET_NPT=m
  758. +CONFIG_BRIDGE_NF_EBTABLES=m
  759. +CONFIG_BRIDGE_EBT_BROUTE=m
  760. +CONFIG_BRIDGE_EBT_T_FILTER=m
  761. +CONFIG_BRIDGE_EBT_T_NAT=m
  762. +CONFIG_BRIDGE_EBT_802_3=m
  763. +CONFIG_BRIDGE_EBT_AMONG=m
  764. +CONFIG_BRIDGE_EBT_ARP=m
  765. +CONFIG_BRIDGE_EBT_IP=m
  766. +CONFIG_BRIDGE_EBT_IP6=m
  767. +CONFIG_BRIDGE_EBT_LIMIT=m
  768. +CONFIG_BRIDGE_EBT_MARK=m
  769. +CONFIG_BRIDGE_EBT_PKTTYPE=m
  770. +CONFIG_BRIDGE_EBT_STP=m
  771. +CONFIG_BRIDGE_EBT_VLAN=m
  772. +CONFIG_BRIDGE_EBT_ARPREPLY=m
  773. +CONFIG_BRIDGE_EBT_DNAT=m
  774. +CONFIG_BRIDGE_EBT_MARK_T=m
  775. +CONFIG_BRIDGE_EBT_REDIRECT=m
  776. +CONFIG_BRIDGE_EBT_SNAT=m
  777. +CONFIG_BRIDGE_EBT_LOG=m
  778. +CONFIG_BRIDGE_EBT_ULOG=m
  779. +CONFIG_BRIDGE_EBT_NFLOG=m
  780. +CONFIG_SCTP_COOKIE_HMAC_SHA1=y
  781. +CONFIG_L2TP=m
  782. +CONFIG_BRIDGE=m
  783. +CONFIG_VLAN_8021Q=m
  784. +CONFIG_VLAN_8021Q_GVRP=y
  785. +CONFIG_ATALK=m
  786. +CONFIG_NET_SCHED=y
  787. +CONFIG_NET_SCH_CBQ=m
  788. +CONFIG_NET_SCH_HTB=m
  789. +CONFIG_NET_SCH_HFSC=m
  790. +CONFIG_NET_SCH_PRIO=m
  791. +CONFIG_NET_SCH_MULTIQ=m
  792. +CONFIG_NET_SCH_RED=m
  793. +CONFIG_NET_SCH_SFB=m
  794. +CONFIG_NET_SCH_SFQ=m
  795. +CONFIG_NET_SCH_TEQL=m
  796. +CONFIG_NET_SCH_TBF=m
  797. +CONFIG_NET_SCH_GRED=m
  798. +CONFIG_NET_SCH_DSMARK=m
  799. +CONFIG_NET_SCH_NETEM=m
  800. +CONFIG_NET_SCH_DRR=m
  801. +CONFIG_NET_SCH_MQPRIO=m
  802. +CONFIG_NET_SCH_CHOKE=m
  803. +CONFIG_NET_SCH_QFQ=m
  804. +CONFIG_NET_SCH_CODEL=m
  805. +CONFIG_NET_SCH_FQ_CODEL=m
  806. +CONFIG_NET_SCH_INGRESS=m
  807. +CONFIG_NET_SCH_PLUG=m
  808. +CONFIG_NET_CLS_BASIC=m
  809. +CONFIG_NET_CLS_TCINDEX=m
  810. +CONFIG_NET_CLS_ROUTE4=m
  811. +CONFIG_NET_CLS_FW=m
  812. +CONFIG_NET_CLS_U32=m
  813. +CONFIG_CLS_U32_MARK=y
  814. +CONFIG_NET_CLS_RSVP=m
  815. +CONFIG_NET_CLS_RSVP6=m
  816. +CONFIG_NET_CLS_FLOW=m
  817. +CONFIG_NET_CLS_CGROUP=m
  818. +CONFIG_NET_EMATCH=y
  819. +CONFIG_NET_EMATCH_CMP=m
  820. +CONFIG_NET_EMATCH_NBYTE=m
  821. +CONFIG_NET_EMATCH_U32=m
  822. +CONFIG_NET_EMATCH_META=m
  823. +CONFIG_NET_EMATCH_TEXT=m
  824. +CONFIG_NET_EMATCH_IPSET=m
  825. +CONFIG_NET_CLS_ACT=y
  826. +CONFIG_NET_ACT_POLICE=m
  827. +CONFIG_NET_ACT_GACT=m
  828. +CONFIG_GACT_PROB=y
  829. +CONFIG_NET_ACT_MIRRED=m
  830. +CONFIG_NET_ACT_IPT=m
  831. +CONFIG_NET_ACT_NAT=m
  832. +CONFIG_NET_ACT_PEDIT=m
  833. +CONFIG_NET_ACT_SIMP=m
  834. +CONFIG_NET_ACT_SKBEDIT=m
  835. +CONFIG_NET_ACT_CSUM=m
  836. +CONFIG_BATMAN_ADV=m
  837. +CONFIG_OPENVSWITCH=m
  838. +CONFIG_NET_PKTGEN=m
  839. +CONFIG_HAMRADIO=y
  840. +CONFIG_AX25=m
  841. +CONFIG_NETROM=m
  842. +CONFIG_ROSE=m
  843. +CONFIG_MKISS=m
  844. +CONFIG_6PACK=m
  845. +CONFIG_BPQETHER=m
  846. +CONFIG_BAYCOM_SER_FDX=m
  847. +CONFIG_BAYCOM_SER_HDX=m
  848. +CONFIG_YAM=m
  849. +CONFIG_IRDA=m
  850. +CONFIG_IRLAN=m
  851. +CONFIG_IRNET=m
  852. +CONFIG_IRCOMM=m
  853. +CONFIG_IRDA_ULTRA=y
  854. +CONFIG_IRDA_CACHE_LAST_LSAP=y
  855. +CONFIG_IRDA_FAST_RR=y
  856. +CONFIG_IRTTY_SIR=m
  857. +CONFIG_KINGSUN_DONGLE=m
  858. +CONFIG_KSDAZZLE_DONGLE=m
  859. +CONFIG_KS959_DONGLE=m
  860. +CONFIG_USB_IRDA=m
  861. +CONFIG_SIGMATEL_FIR=m
  862. +CONFIG_MCS_FIR=m
  863. +CONFIG_BT=m
  864. +CONFIG_BT_RFCOMM=m
  865. +CONFIG_BT_RFCOMM_TTY=y
  866. +CONFIG_BT_BNEP=m
  867. +CONFIG_BT_BNEP_MC_FILTER=y
  868. +CONFIG_BT_BNEP_PROTO_FILTER=y
  869. +CONFIG_BT_HIDP=m
  870. +CONFIG_BT_HCIBTUSB=m
  871. +CONFIG_BT_HCIBCM203X=m
  872. +CONFIG_BT_HCIBPA10X=m
  873. +CONFIG_BT_HCIBFUSB=m
  874. +CONFIG_BT_HCIVHCI=m
  875. +CONFIG_BT_MRVL=m
  876. +CONFIG_BT_MRVL_SDIO=m
  877. +CONFIG_BT_ATH3K=m
  878. +CONFIG_BT_WILINK=m
  879. +CONFIG_CFG80211=m
  880. +CONFIG_CFG80211_WEXT=y
  881. +CONFIG_MAC80211=m
  882. +CONFIG_MAC80211_RC_PID=y
  883. +CONFIG_MAC80211_MESH=y
  884. +CONFIG_WIMAX=m
  885. +CONFIG_RFKILL=m
  886. +CONFIG_RFKILL_INPUT=y
  887. +CONFIG_NET_9P=m
  888. +CONFIG_NFC=m
  889. +CONFIG_NFC_PN533=m
  890. +CONFIG_DEVTMPFS=y
  891. +CONFIG_DEVTMPFS_MOUNT=y
  892. +CONFIG_BLK_DEV_LOOP=y
  893. +CONFIG_BLK_DEV_CRYPTOLOOP=m
  894. +CONFIG_BLK_DEV_DRBD=m
  895. +CONFIG_BLK_DEV_NBD=m
  896. +CONFIG_BLK_DEV_RAM=y
  897. +CONFIG_CDROM_PKTCDVD=m
  898. +CONFIG_SCSI=y
  899. +# CONFIG_SCSI_PROC_FS is not set
  900. +CONFIG_BLK_DEV_SD=y
  901. +CONFIG_CHR_DEV_ST=m
  902. +CONFIG_CHR_DEV_OSST=m
  903. +CONFIG_BLK_DEV_SR=m
  904. +CONFIG_SCSI_MULTI_LUN=y
  905. +CONFIG_SCSI_ISCSI_ATTRS=y
  906. +CONFIG_ISCSI_TCP=m
  907. +CONFIG_ISCSI_BOOT_SYSFS=m
  908. +CONFIG_MD=y
  909. +CONFIG_MD_LINEAR=m
  910. +CONFIG_MD_RAID0=m
  911. +CONFIG_BLK_DEV_DM=m
  912. +CONFIG_DM_CRYPT=m
  913. +CONFIG_DM_SNAPSHOT=m
  914. +CONFIG_DM_MIRROR=m
  915. +CONFIG_DM_LOG_USERSPACE=m
  916. +CONFIG_DM_RAID=m
  917. +CONFIG_DM_ZERO=m
  918. +CONFIG_DM_DELAY=m
  919. +CONFIG_NETDEVICES=y
  920. +CONFIG_BONDING=m
  921. +CONFIG_DUMMY=m
  922. +CONFIG_IFB=m
  923. +CONFIG_MACVLAN=m
  924. +CONFIG_NETCONSOLE=m
  925. +CONFIG_TUN=m
  926. +CONFIG_MDIO_BITBANG=m
  927. +CONFIG_PPP=m
  928. +CONFIG_PPP_BSDCOMP=m
  929. +CONFIG_PPP_DEFLATE=m
  930. +CONFIG_PPP_FILTER=y
  931. +CONFIG_PPP_MPPE=m
  932. +CONFIG_PPP_MULTILINK=y
  933. +CONFIG_PPPOE=m
  934. +CONFIG_PPPOL2TP=m
  935. +CONFIG_PPP_ASYNC=m
  936. +CONFIG_PPP_SYNC_TTY=m
  937. +CONFIG_SLIP=m
  938. +CONFIG_SLIP_COMPRESSED=y
  939. +CONFIG_SLIP_SMART=y
  940. +CONFIG_USB_CATC=m
  941. +CONFIG_USB_KAWETH=m
  942. +CONFIG_USB_PEGASUS=m
  943. +CONFIG_USB_RTL8150=m
  944. +CONFIG_USB_RTL8152=m
  945. +CONFIG_USB_USBNET=y
  946. +CONFIG_USB_NET_AX8817X=m
  947. +CONFIG_USB_NET_AX88179_178A=m
  948. +CONFIG_USB_NET_CDCETHER=m
  949. +CONFIG_USB_NET_CDC_EEM=m
  950. +CONFIG_USB_NET_CDC_NCM=m
  951. +CONFIG_USB_NET_CDC_MBIM=m
  952. +CONFIG_USB_NET_DM9601=m
  953. +CONFIG_USB_NET_SMSC75XX=m
  954. +CONFIG_USB_NET_SMSC95XX=y
  955. +CONFIG_USB_NET_GL620A=m
  956. +CONFIG_USB_NET_NET1080=m
  957. +CONFIG_USB_NET_PLUSB=m
  958. +CONFIG_USB_NET_MCS7830=m
  959. +CONFIG_USB_NET_CDC_SUBSET=m
  960. +CONFIG_USB_ALI_M5632=y
  961. +CONFIG_USB_AN2720=y
  962. +CONFIG_USB_EPSON2888=y
  963. +CONFIG_USB_KC2190=y
  964. +CONFIG_USB_NET_ZAURUS=m
  965. +CONFIG_USB_NET_CX82310_ETH=m
  966. +CONFIG_USB_NET_KALMIA=m
  967. +CONFIG_USB_NET_QMI_WWAN=m
  968. +CONFIG_USB_NET_INT51X1=m
  969. +CONFIG_USB_IPHETH=m
  970. +CONFIG_USB_SIERRA_NET=m
  971. +CONFIG_USB_VL600=m
  972. +CONFIG_LIBERTAS_THINFIRM=m
  973. +CONFIG_LIBERTAS_THINFIRM_USB=m
  974. +CONFIG_AT76C50X_USB=m
  975. +CONFIG_USB_ZD1201=m
  976. +CONFIG_USB_NET_RNDIS_WLAN=m
  977. +CONFIG_RTL8187=m
  978. +CONFIG_MAC80211_HWSIM=m
  979. +CONFIG_ATH_CARDS=m
  980. +CONFIG_ATH9K=m
  981. +CONFIG_ATH9K_HTC=m
  982. +CONFIG_CARL9170=m
  983. +CONFIG_ATH6KL=m
  984. +CONFIG_ATH6KL_USB=m
  985. +CONFIG_AR5523=m
  986. +CONFIG_B43=m
  987. +# CONFIG_B43_PHY_N is not set
  988. +CONFIG_B43LEGACY=m
  989. +CONFIG_HOSTAP=m
  990. +CONFIG_LIBERTAS=m
  991. +CONFIG_LIBERTAS_USB=m
  992. +CONFIG_LIBERTAS_SDIO=m
  993. +CONFIG_P54_COMMON=m
  994. +CONFIG_P54_USB=m
  995. +CONFIG_RT2X00=m
  996. +CONFIG_RT2500USB=m
  997. +CONFIG_RT73USB=m
  998. +CONFIG_RT2800USB=m
  999. +CONFIG_RT2800USB_RT3573=y
  1000. +CONFIG_RT2800USB_RT53XX=y
  1001. +CONFIG_RT2800USB_RT55XX=y
  1002. +CONFIG_RT2800USB_UNKNOWN=y
  1003. +CONFIG_RTL8192CU=m
  1004. +CONFIG_ZD1211RW=m
  1005. +CONFIG_MWIFIEX=m
  1006. +CONFIG_MWIFIEX_SDIO=m
  1007. +CONFIG_WIMAX_I2400M_USB=m
  1008. +CONFIG_INPUT_POLLDEV=m
  1009. +# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
  1010. +CONFIG_INPUT_JOYDEV=m
  1011. +CONFIG_INPUT_EVDEV=m
  1012. +# CONFIG_INPUT_KEYBOARD is not set
  1013. +# CONFIG_INPUT_MOUSE is not set
  1014. +CONFIG_INPUT_JOYSTICK=y
  1015. +CONFIG_JOYSTICK_IFORCE=m
  1016. +CONFIG_JOYSTICK_IFORCE_USB=y
  1017. +CONFIG_JOYSTICK_XPAD=m
  1018. +CONFIG_JOYSTICK_XPAD_FF=y
  1019. +CONFIG_INPUT_MISC=y
  1020. +CONFIG_INPUT_AD714X=m
  1021. +CONFIG_INPUT_ATI_REMOTE2=m
  1022. +CONFIG_INPUT_KEYSPAN_REMOTE=m
  1023. +CONFIG_INPUT_POWERMATE=m
  1024. +CONFIG_INPUT_YEALINK=m
  1025. +CONFIG_INPUT_CM109=m
  1026. +CONFIG_INPUT_UINPUT=m
  1027. +CONFIG_INPUT_GPIO_ROTARY_ENCODER=m
  1028. +CONFIG_INPUT_ADXL34X=m
  1029. +CONFIG_INPUT_CMA3000=m
  1030. +CONFIG_SERIO=m
  1031. +CONFIG_SERIO_RAW=m
  1032. +CONFIG_GAMEPORT=m
  1033. +CONFIG_GAMEPORT_NS558=m
  1034. +CONFIG_GAMEPORT_L4=m
  1035. +# CONFIG_LEGACY_PTYS is not set
  1036. +# CONFIG_DEVKMEM is not set
  1037. +CONFIG_SERIAL_AMBA_PL011=y
  1038. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  1039. +CONFIG_TTY_PRINTK=y
  1040. +CONFIG_HW_RANDOM=y
  1041. +CONFIG_HW_RANDOM_BCM2708=m
  1042. +CONFIG_RAW_DRIVER=y
  1043. +CONFIG_BRCM_CHAR_DRIVERS=y
  1044. +CONFIG_BCM_VC_CMA=y
  1045. +CONFIG_I2C=y
  1046. +CONFIG_I2C_CHARDEV=m
  1047. +CONFIG_I2C_BCM2708=m
  1048. +CONFIG_SPI=y
  1049. +CONFIG_SPI_BCM2708=m
  1050. +CONFIG_SPI_SPIDEV=y
  1051. +CONFIG_GPIO_SYSFS=y
  1052. +CONFIG_W1=m
  1053. +CONFIG_W1_MASTER_DS2490=m
  1054. +CONFIG_W1_MASTER_DS2482=m
  1055. +CONFIG_W1_MASTER_DS1WM=m
  1056. +CONFIG_W1_MASTER_GPIO=m
  1057. +CONFIG_W1_SLAVE_THERM=m
  1058. +CONFIG_W1_SLAVE_SMEM=m
  1059. +CONFIG_W1_SLAVE_DS2408=m
  1060. +CONFIG_W1_SLAVE_DS2413=m
  1061. +CONFIG_W1_SLAVE_DS2423=m
  1062. +CONFIG_W1_SLAVE_DS2431=m
  1063. +CONFIG_W1_SLAVE_DS2433=m
  1064. +CONFIG_W1_SLAVE_DS2760=m
  1065. +CONFIG_W1_SLAVE_DS2780=m
  1066. +CONFIG_W1_SLAVE_DS2781=m
  1067. +CONFIG_W1_SLAVE_DS28E04=m
  1068. +CONFIG_W1_SLAVE_BQ27000=m
  1069. +CONFIG_BATTERY_DS2760=m
  1070. +# CONFIG_HWMON is not set
  1071. +CONFIG_THERMAL=y
  1072. +CONFIG_THERMAL_BCM2835=y
  1073. +CONFIG_WATCHDOG=y
  1074. +CONFIG_BCM2708_WDT=m
  1075. +CONFIG_MEDIA_SUPPORT=m
  1076. +CONFIG_MEDIA_CAMERA_SUPPORT=y
  1077. +CONFIG_MEDIA_ANALOG_TV_SUPPORT=y
  1078. +CONFIG_MEDIA_DIGITAL_TV_SUPPORT=y
  1079. +CONFIG_MEDIA_RADIO_SUPPORT=y
  1080. +CONFIG_MEDIA_RC_SUPPORT=y
  1081. +CONFIG_MEDIA_CONTROLLER=y
  1082. +CONFIG_LIRC=m
  1083. +CONFIG_RC_DEVICES=y
  1084. +CONFIG_RC_ATI_REMOTE=m
  1085. +CONFIG_IR_IMON=m
  1086. +CONFIG_IR_MCEUSB=m
  1087. +CONFIG_IR_REDRAT3=m
  1088. +CONFIG_IR_STREAMZAP=m
  1089. +CONFIG_IR_IGUANA=m
  1090. +CONFIG_IR_TTUSBIR=m
  1091. +CONFIG_RC_LOOPBACK=m
  1092. +CONFIG_IR_GPIO_CIR=m
  1093. +CONFIG_MEDIA_USB_SUPPORT=y
  1094. +CONFIG_USB_VIDEO_CLASS=m
  1095. +CONFIG_USB_M5602=m
  1096. +CONFIG_USB_STV06XX=m
  1097. +CONFIG_USB_GL860=m
  1098. +CONFIG_USB_GSPCA_BENQ=m
  1099. +CONFIG_USB_GSPCA_CONEX=m
  1100. +CONFIG_USB_GSPCA_CPIA1=m
  1101. +CONFIG_USB_GSPCA_ETOMS=m
  1102. +CONFIG_USB_GSPCA_FINEPIX=m
  1103. +CONFIG_USB_GSPCA_JEILINJ=m
  1104. +CONFIG_USB_GSPCA_JL2005BCD=m
  1105. +CONFIG_USB_GSPCA_KINECT=m
  1106. +CONFIG_USB_GSPCA_KONICA=m
  1107. +CONFIG_USB_GSPCA_MARS=m
  1108. +CONFIG_USB_GSPCA_MR97310A=m
  1109. +CONFIG_USB_GSPCA_NW80X=m
  1110. +CONFIG_USB_GSPCA_OV519=m
  1111. +CONFIG_USB_GSPCA_OV534=m
  1112. +CONFIG_USB_GSPCA_OV534_9=m
  1113. +CONFIG_USB_GSPCA_PAC207=m
  1114. +CONFIG_USB_GSPCA_PAC7302=m
  1115. +CONFIG_USB_GSPCA_PAC7311=m
  1116. +CONFIG_USB_GSPCA_SE401=m
  1117. +CONFIG_USB_GSPCA_SN9C2028=m
  1118. +CONFIG_USB_GSPCA_SN9C20X=m
  1119. +CONFIG_USB_GSPCA_SONIXB=m
  1120. +CONFIG_USB_GSPCA_SONIXJ=m
  1121. +CONFIG_USB_GSPCA_SPCA500=m
  1122. +CONFIG_USB_GSPCA_SPCA501=m
  1123. +CONFIG_USB_GSPCA_SPCA505=m
  1124. +CONFIG_USB_GSPCA_SPCA506=m
  1125. +CONFIG_USB_GSPCA_SPCA508=m
  1126. +CONFIG_USB_GSPCA_SPCA561=m
  1127. +CONFIG_USB_GSPCA_SPCA1528=m
  1128. +CONFIG_USB_GSPCA_SQ905=m
  1129. +CONFIG_USB_GSPCA_SQ905C=m
  1130. +CONFIG_USB_GSPCA_SQ930X=m
  1131. +CONFIG_USB_GSPCA_STK014=m
  1132. +CONFIG_USB_GSPCA_STV0680=m
  1133. +CONFIG_USB_GSPCA_SUNPLUS=m
  1134. +CONFIG_USB_GSPCA_T613=m
  1135. +CONFIG_USB_GSPCA_TOPRO=m
  1136. +CONFIG_USB_GSPCA_TV8532=m
  1137. +CONFIG_USB_GSPCA_VC032X=m
  1138. +CONFIG_USB_GSPCA_VICAM=m
  1139. +CONFIG_USB_GSPCA_XIRLINK_CIT=m
  1140. +CONFIG_USB_GSPCA_ZC3XX=m
  1141. +CONFIG_USB_PWC=m
  1142. +CONFIG_VIDEO_CPIA2=m
  1143. +CONFIG_USB_ZR364XX=m
  1144. +CONFIG_USB_STKWEBCAM=m
  1145. +CONFIG_USB_S2255=m
  1146. +CONFIG_USB_SN9C102=m
  1147. +CONFIG_VIDEO_PVRUSB2=m
  1148. +CONFIG_VIDEO_HDPVR=m
  1149. +CONFIG_VIDEO_TLG2300=m
  1150. +CONFIG_VIDEO_USBVISION=m
  1151. +CONFIG_VIDEO_AU0828=m
  1152. +CONFIG_VIDEO_CX231XX=m
  1153. +CONFIG_VIDEO_CX231XX_ALSA=m
  1154. +CONFIG_VIDEO_CX231XX_DVB=m
  1155. +CONFIG_VIDEO_TM6000=m
  1156. +CONFIG_VIDEO_TM6000_ALSA=m
  1157. +CONFIG_VIDEO_TM6000_DVB=m
  1158. +CONFIG_DVB_USB=m
  1159. +CONFIG_DVB_USB_A800=m
  1160. +CONFIG_DVB_USB_DIBUSB_MB=m
  1161. +CONFIG_DVB_USB_DIBUSB_MB_FAULTY=y
  1162. +CONFIG_DVB_USB_DIBUSB_MC=m
  1163. +CONFIG_DVB_USB_DIB0700=m
  1164. +CONFIG_DVB_USB_UMT_010=m
  1165. +CONFIG_DVB_USB_CXUSB=m
  1166. +CONFIG_DVB_USB_M920X=m
  1167. +CONFIG_DVB_USB_DIGITV=m
  1168. +CONFIG_DVB_USB_VP7045=m
  1169. +CONFIG_DVB_USB_VP702X=m
  1170. +CONFIG_DVB_USB_GP8PSK=m
  1171. +CONFIG_DVB_USB_NOVA_T_USB2=m
  1172. +CONFIG_DVB_USB_TTUSB2=m
  1173. +CONFIG_DVB_USB_DTT200U=m
  1174. +CONFIG_DVB_USB_OPERA1=m
  1175. +CONFIG_DVB_USB_AF9005=m
  1176. +CONFIG_DVB_USB_AF9005_REMOTE=m
  1177. +CONFIG_DVB_USB_PCTV452E=m
  1178. +CONFIG_DVB_USB_DW2102=m
  1179. +CONFIG_DVB_USB_CINERGY_T2=m
  1180. +CONFIG_DVB_USB_DTV5100=m
  1181. +CONFIG_DVB_USB_FRIIO=m
  1182. +CONFIG_DVB_USB_AZ6027=m
  1183. +CONFIG_DVB_USB_TECHNISAT_USB2=m
  1184. +CONFIG_DVB_USB_V2=m
  1185. +CONFIG_DVB_USB_AF9015=m
  1186. +CONFIG_DVB_USB_AF9035=m
  1187. +CONFIG_DVB_USB_ANYSEE=m
  1188. +CONFIG_DVB_USB_AU6610=m
  1189. +CONFIG_DVB_USB_AZ6007=m
  1190. +CONFIG_DVB_USB_CE6230=m
  1191. +CONFIG_DVB_USB_EC168=m
  1192. +CONFIG_DVB_USB_GL861=m
  1193. +CONFIG_DVB_USB_IT913X=m
  1194. +CONFIG_DVB_USB_LME2510=m
  1195. +CONFIG_DVB_USB_MXL111SF=m
  1196. +CONFIG_DVB_USB_RTL28XXU=m
  1197. +CONFIG_SMS_USB_DRV=m
  1198. +CONFIG_DVB_B2C2_FLEXCOP_USB=m
  1199. +CONFIG_VIDEO_EM28XX=m
  1200. +CONFIG_VIDEO_EM28XX_ALSA=m
  1201. +CONFIG_VIDEO_EM28XX_DVB=m
  1202. +CONFIG_V4L_PLATFORM_DRIVERS=y
  1203. +CONFIG_VIDEO_BCM2835=y
  1204. +CONFIG_VIDEO_BCM2835_MMAL=m
  1205. +CONFIG_RADIO_SI470X=y
  1206. +CONFIG_USB_SI470X=m
  1207. +CONFIG_I2C_SI470X=m
  1208. +CONFIG_USB_MR800=m
  1209. +CONFIG_USB_DSBR=m
  1210. +CONFIG_RADIO_SHARK=m
  1211. +CONFIG_RADIO_SHARK2=m
  1212. +CONFIG_RADIO_SI4713=m
  1213. +CONFIG_USB_KEENE=m
  1214. +CONFIG_USB_MA901=m
  1215. +CONFIG_RADIO_TEA5764=m
  1216. +CONFIG_RADIO_SAA7706H=m
  1217. +CONFIG_RADIO_TEF6862=m
  1218. +CONFIG_RADIO_WL1273=m
  1219. +CONFIG_RADIO_WL128X=m
  1220. +CONFIG_FB=y
  1221. +CONFIG_FB_BCM2708=y
  1222. +# CONFIG_BACKLIGHT_GENERIC is not set
  1223. +CONFIG_FRAMEBUFFER_CONSOLE=y
  1224. +CONFIG_LOGO=y
  1225. +# CONFIG_LOGO_LINUX_MONO is not set
  1226. +# CONFIG_LOGO_LINUX_VGA16 is not set
  1227. +CONFIG_SOUND=y
  1228. +CONFIG_SND=m
  1229. +CONFIG_SND_SEQUENCER=m
  1230. +CONFIG_SND_SEQ_DUMMY=m
  1231. +CONFIG_SND_MIXER_OSS=m
  1232. +CONFIG_SND_PCM_OSS=m
  1233. +CONFIG_SND_SEQUENCER_OSS=y
  1234. +CONFIG_SND_HRTIMER=m
  1235. +CONFIG_SND_DUMMY=m
  1236. +CONFIG_SND_ALOOP=m
  1237. +CONFIG_SND_VIRMIDI=m
  1238. +CONFIG_SND_MTPAV=m
  1239. +CONFIG_SND_SERIAL_U16550=m
  1240. +CONFIG_SND_MPU401=m
  1241. +CONFIG_SND_BCM2835=m
  1242. +CONFIG_SND_USB_AUDIO=m
  1243. +CONFIG_SND_USB_UA101=m
  1244. +CONFIG_SND_USB_CAIAQ=m
  1245. +CONFIG_SND_USB_CAIAQ_INPUT=y
  1246. +CONFIG_SND_USB_6FIRE=m
  1247. +CONFIG_SND_SOC=m
  1248. +CONFIG_SND_SOC_DMAENGINE_PCM=y
  1249. +CONFIG_SND_SOC_GENERIC_DMAENGINE_PCM=y
  1250. +CONFIG_SND_SOC_WM8804=m
  1251. +CONFIG_SND_BCM2708_SOC_I2S=m
  1252. +CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC=m
  1253. +CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI=m
  1254. +CONFIG_SND_BCM2708_SOC_RPI_DAC=m
  1255. +CONFIG_SND_SOC_I2C_AND_SPI=m
  1256. +CONFIG_SND_SOC_PCM5102A=m
  1257. +CONFIG_SND_SOC_PCM1794A=m
  1258. +CONFIG_SOUND_PRIME=m
  1259. +CONFIG_HIDRAW=y
  1260. +CONFIG_HID_A4TECH=m
  1261. +CONFIG_HID_ACRUX=m
  1262. +CONFIG_HID_APPLE=m
  1263. +CONFIG_HID_BELKIN=m
  1264. +CONFIG_HID_CHERRY=m
  1265. +CONFIG_HID_CHICONY=m
  1266. +CONFIG_HID_CYPRESS=m
  1267. +CONFIG_HID_DRAGONRISE=m
  1268. +CONFIG_HID_EMS_FF=m
  1269. +CONFIG_HID_ELECOM=m
  1270. +CONFIG_HID_EZKEY=m
  1271. +CONFIG_HID_HOLTEK=m
  1272. +CONFIG_HID_KEYTOUCH=m
  1273. +CONFIG_HID_KYE=m
  1274. +CONFIG_HID_UCLOGIC=m
  1275. +CONFIG_HID_WALTOP=m
  1276. +CONFIG_HID_GYRATION=m
  1277. +CONFIG_HID_TWINHAN=m
  1278. +CONFIG_HID_KENSINGTON=m
  1279. +CONFIG_HID_LCPOWER=m
  1280. +CONFIG_HID_LOGITECH=m
  1281. +CONFIG_HID_MAGICMOUSE=m
  1282. +CONFIG_HID_MICROSOFT=m
  1283. +CONFIG_HID_MONTEREY=m
  1284. +CONFIG_HID_MULTITOUCH=m
  1285. +CONFIG_HID_NTRIG=m
  1286. +CONFIG_HID_ORTEK=m
  1287. +CONFIG_HID_PANTHERLORD=m
  1288. +CONFIG_HID_PETALYNX=m
  1289. +CONFIG_HID_PICOLCD=m
  1290. +CONFIG_HID_ROCCAT=m
  1291. +CONFIG_HID_SAMSUNG=m
  1292. +CONFIG_HID_SONY=m
  1293. +CONFIG_HID_SPEEDLINK=m
  1294. +CONFIG_HID_SUNPLUS=m
  1295. +CONFIG_HID_GREENASIA=m
  1296. +CONFIG_HID_SMARTJOYPLUS=m
  1297. +CONFIG_HID_TOPSEED=m
  1298. +CONFIG_HID_THINGM=m
  1299. +CONFIG_HID_THRUSTMASTER=m
  1300. +CONFIG_HID_WACOM=m
  1301. +CONFIG_HID_WIIMOTE=m
  1302. +CONFIG_HID_ZEROPLUS=m
  1303. +CONFIG_HID_ZYDACRON=m
  1304. +CONFIG_HID_PID=y
  1305. +CONFIG_USB_HIDDEV=y
  1306. +CONFIG_USB=y
  1307. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  1308. +CONFIG_USB_MON=m
  1309. +CONFIG_USB_DWCOTG=y
  1310. +CONFIG_USB_PRINTER=m
  1311. +CONFIG_USB_STORAGE=y
  1312. +CONFIG_USB_STORAGE_REALTEK=m
  1313. +CONFIG_USB_STORAGE_DATAFAB=m
  1314. +CONFIG_USB_STORAGE_FREECOM=m
  1315. +CONFIG_USB_STORAGE_ISD200=m
  1316. +CONFIG_USB_STORAGE_USBAT=m
  1317. +CONFIG_USB_STORAGE_SDDR09=m
  1318. +CONFIG_USB_STORAGE_SDDR55=m
  1319. +CONFIG_USB_STORAGE_JUMPSHOT=m
  1320. +CONFIG_USB_STORAGE_ALAUDA=m
  1321. +CONFIG_USB_STORAGE_ONETOUCH=m
  1322. +CONFIG_USB_STORAGE_KARMA=m
  1323. +CONFIG_USB_STORAGE_CYPRESS_ATACB=m
  1324. +CONFIG_USB_STORAGE_ENE_UB6250=m
  1325. +CONFIG_USB_MDC800=m
  1326. +CONFIG_USB_MICROTEK=m
  1327. +CONFIG_USB_SERIAL=m
  1328. +CONFIG_USB_SERIAL_GENERIC=y
  1329. +CONFIG_USB_SERIAL_AIRCABLE=m
  1330. +CONFIG_USB_SERIAL_ARK3116=m
  1331. +CONFIG_USB_SERIAL_BELKIN=m
  1332. +CONFIG_USB_SERIAL_CH341=m
  1333. +CONFIG_USB_SERIAL_WHITEHEAT=m
  1334. +CONFIG_USB_SERIAL_DIGI_ACCELEPORT=m
  1335. +CONFIG_USB_SERIAL_CP210X=m
  1336. +CONFIG_USB_SERIAL_CYPRESS_M8=m
  1337. +CONFIG_USB_SERIAL_EMPEG=m
  1338. +CONFIG_USB_SERIAL_FTDI_SIO=m
  1339. +CONFIG_USB_SERIAL_VISOR=m
  1340. +CONFIG_USB_SERIAL_IPAQ=m
  1341. +CONFIG_USB_SERIAL_IR=m
  1342. +CONFIG_USB_SERIAL_EDGEPORT=m
  1343. +CONFIG_USB_SERIAL_EDGEPORT_TI=m
  1344. +CONFIG_USB_SERIAL_F81232=m
  1345. +CONFIG_USB_SERIAL_GARMIN=m
  1346. +CONFIG_USB_SERIAL_IPW=m
  1347. +CONFIG_USB_SERIAL_IUU=m
  1348. +CONFIG_USB_SERIAL_KEYSPAN_PDA=m
  1349. +CONFIG_USB_SERIAL_KEYSPAN=m
  1350. +CONFIG_USB_SERIAL_KLSI=m
  1351. +CONFIG_USB_SERIAL_KOBIL_SCT=m
  1352. +CONFIG_USB_SERIAL_MCT_U232=m
  1353. +CONFIG_USB_SERIAL_METRO=m
  1354. +CONFIG_USB_SERIAL_MOS7720=m
  1355. +CONFIG_USB_SERIAL_MOS7840=m
  1356. +CONFIG_USB_SERIAL_NAVMAN=m
  1357. +CONFIG_USB_SERIAL_PL2303=m
  1358. +CONFIG_USB_SERIAL_OTI6858=m
  1359. +CONFIG_USB_SERIAL_QCAUX=m
  1360. +CONFIG_USB_SERIAL_QUALCOMM=m
  1361. +CONFIG_USB_SERIAL_SPCP8X5=m
  1362. +CONFIG_USB_SERIAL_SAFE=m
  1363. +CONFIG_USB_SERIAL_SIERRAWIRELESS=m
  1364. +CONFIG_USB_SERIAL_SYMBOL=m
  1365. +CONFIG_USB_SERIAL_TI=m
  1366. +CONFIG_USB_SERIAL_CYBERJACK=m
  1367. +CONFIG_USB_SERIAL_XIRCOM=m
  1368. +CONFIG_USB_SERIAL_OPTION=m
  1369. +CONFIG_USB_SERIAL_OMNINET=m
  1370. +CONFIG_USB_SERIAL_OPTICON=m
  1371. +CONFIG_USB_SERIAL_XSENS_MT=m
  1372. +CONFIG_USB_SERIAL_WISHBONE=m
  1373. +CONFIG_USB_SERIAL_ZTE=m
  1374. +CONFIG_USB_SERIAL_SSU100=m
  1375. +CONFIG_USB_SERIAL_QT2=m
  1376. +CONFIG_USB_SERIAL_DEBUG=m
  1377. +CONFIG_USB_EMI62=m
  1378. +CONFIG_USB_EMI26=m
  1379. +CONFIG_USB_ADUTUX=m
  1380. +CONFIG_USB_SEVSEG=m
  1381. +CONFIG_USB_RIO500=m
  1382. +CONFIG_USB_LEGOTOWER=m
  1383. +CONFIG_USB_LCD=m
  1384. +CONFIG_USB_LED=m
  1385. +CONFIG_USB_CYPRESS_CY7C63=m
  1386. +CONFIG_USB_CYTHERM=m
  1387. +CONFIG_USB_IDMOUSE=m
  1388. +CONFIG_USB_FTDI_ELAN=m
  1389. +CONFIG_USB_APPLEDISPLAY=m
  1390. +CONFIG_USB_LD=m
  1391. +CONFIG_USB_TRANCEVIBRATOR=m
  1392. +CONFIG_USB_IOWARRIOR=m
  1393. +CONFIG_USB_TEST=m
  1394. +CONFIG_USB_ISIGHTFW=m
  1395. +CONFIG_USB_YUREX=m
  1396. +CONFIG_MMC=y
  1397. +CONFIG_MMC_BLOCK_MINORS=32
  1398. +CONFIG_MMC_SDHCI=y
  1399. +CONFIG_MMC_SDHCI_PLTFM=y
  1400. +CONFIG_MMC_SDHCI_BCM2708=y
  1401. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  1402. +CONFIG_MMC_SPI=m
  1403. +CONFIG_LEDS_GPIO=m
  1404. +CONFIG_LEDS_TRIGGER_TIMER=y
  1405. +CONFIG_LEDS_TRIGGER_ONESHOT=y
  1406. +CONFIG_LEDS_TRIGGER_HEARTBEAT=y
  1407. +CONFIG_LEDS_TRIGGER_BACKLIGHT=y
  1408. +CONFIG_LEDS_TRIGGER_CPU=y
  1409. +CONFIG_LEDS_TRIGGER_GPIO=y
  1410. +CONFIG_LEDS_TRIGGER_DEFAULT_ON=y
  1411. +CONFIG_LEDS_TRIGGER_TRANSIENT=m
  1412. +CONFIG_LEDS_TRIGGER_CAMERA=m
  1413. +CONFIG_RTC_CLASS=y
  1414. +# CONFIG_RTC_HCTOSYS is not set
  1415. +CONFIG_RTC_DRV_DS1307=m
  1416. +CONFIG_RTC_DRV_DS1374=m
  1417. +CONFIG_RTC_DRV_DS1672=m
  1418. +CONFIG_RTC_DRV_DS3232=m
  1419. +CONFIG_RTC_DRV_MAX6900=m
  1420. +CONFIG_RTC_DRV_RS5C372=m
  1421. +CONFIG_RTC_DRV_ISL1208=m
  1422. +CONFIG_RTC_DRV_ISL12022=m
  1423. +CONFIG_RTC_DRV_X1205=m
  1424. +CONFIG_RTC_DRV_PCF8523=m
  1425. +CONFIG_RTC_DRV_PCF8563=m
  1426. +CONFIG_RTC_DRV_PCF8583=m
  1427. +CONFIG_RTC_DRV_M41T80=m
  1428. +CONFIG_RTC_DRV_BQ32K=m
  1429. +CONFIG_RTC_DRV_S35390A=m
  1430. +CONFIG_RTC_DRV_FM3130=m
  1431. +CONFIG_RTC_DRV_RX8581=m
  1432. +CONFIG_RTC_DRV_RX8025=m
  1433. +CONFIG_RTC_DRV_EM3027=m
  1434. +CONFIG_RTC_DRV_RV3029C2=m
  1435. +CONFIG_RTC_DRV_M41T93=m
  1436. +CONFIG_RTC_DRV_M41T94=m
  1437. +CONFIG_RTC_DRV_DS1305=m
  1438. +CONFIG_RTC_DRV_DS1390=m
  1439. +CONFIG_RTC_DRV_MAX6902=m
  1440. +CONFIG_RTC_DRV_R9701=m
  1441. +CONFIG_RTC_DRV_RS5C348=m
  1442. +CONFIG_RTC_DRV_DS3234=m
  1443. +CONFIG_RTC_DRV_PCF2123=m
  1444. +CONFIG_RTC_DRV_RX4581=m
  1445. +CONFIG_DMADEVICES=y
  1446. +CONFIG_DMA_BCM2708=m
  1447. +CONFIG_DMA_ENGINE=y
  1448. +CONFIG_DMA_VIRTUAL_CHANNELS=m
  1449. +CONFIG_UIO=m
  1450. +CONFIG_UIO_PDRV_GENIRQ=m
  1451. +CONFIG_STAGING=y
  1452. +CONFIG_W35UND=m
  1453. +CONFIG_PRISM2_USB=m
  1454. +CONFIG_R8712U=m
  1455. +CONFIG_VT6656=m
  1456. +CONFIG_SPEAKUP=m
  1457. +CONFIG_SPEAKUP_SYNTH_SOFT=m
  1458. +CONFIG_STAGING_MEDIA=y
  1459. +CONFIG_DVB_AS102=m
  1460. +CONFIG_LIRC_STAGING=y
  1461. +CONFIG_LIRC_IGORPLUGUSB=m
  1462. +CONFIG_LIRC_IMON=m
  1463. +CONFIG_LIRC_RPI=m
  1464. +CONFIG_LIRC_SASEM=m
  1465. +CONFIG_LIRC_SERIAL=m
  1466. +# CONFIG_IOMMU_SUPPORT is not set
  1467. +CONFIG_EXT4_FS=y
  1468. +CONFIG_EXT4_FS_POSIX_ACL=y
  1469. +CONFIG_EXT4_FS_SECURITY=y
  1470. +CONFIG_REISERFS_FS=m
  1471. +CONFIG_REISERFS_FS_XATTR=y
  1472. +CONFIG_REISERFS_FS_POSIX_ACL=y
  1473. +CONFIG_REISERFS_FS_SECURITY=y
  1474. +CONFIG_JFS_FS=m
  1475. +CONFIG_JFS_POSIX_ACL=y
  1476. +CONFIG_JFS_SECURITY=y
  1477. +CONFIG_JFS_STATISTICS=y
  1478. +CONFIG_XFS_FS=m
  1479. +CONFIG_XFS_QUOTA=y
  1480. +CONFIG_XFS_POSIX_ACL=y
  1481. +CONFIG_XFS_RT=y
  1482. +CONFIG_GFS2_FS=m
  1483. +CONFIG_OCFS2_FS=m
  1484. +CONFIG_BTRFS_FS=m
  1485. +CONFIG_BTRFS_FS_POSIX_ACL=y
  1486. +CONFIG_NILFS2_FS=m
  1487. +CONFIG_FANOTIFY=y
  1488. +CONFIG_QFMT_V1=m
  1489. +CONFIG_QFMT_V2=m
  1490. +CONFIG_AUTOFS4_FS=y
  1491. +CONFIG_FUSE_FS=m
  1492. +CONFIG_CUSE=m
  1493. +CONFIG_FSCACHE=y
  1494. +CONFIG_FSCACHE_STATS=y
  1495. +CONFIG_FSCACHE_HISTOGRAM=y
  1496. +CONFIG_CACHEFILES=y
  1497. +CONFIG_ISO9660_FS=m
  1498. +CONFIG_JOLIET=y
  1499. +CONFIG_ZISOFS=y
  1500. +CONFIG_UDF_FS=m
  1501. +CONFIG_MSDOS_FS=y
  1502. +CONFIG_VFAT_FS=y
  1503. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  1504. +CONFIG_NTFS_FS=m
  1505. +CONFIG_NTFS_RW=y
  1506. +CONFIG_TMPFS=y
  1507. +CONFIG_TMPFS_POSIX_ACL=y
  1508. +CONFIG_CONFIGFS_FS=y
  1509. +CONFIG_ECRYPT_FS=m
  1510. +CONFIG_HFS_FS=m
  1511. +CONFIG_HFSPLUS_FS=m
  1512. +CONFIG_SQUASHFS=m
  1513. +CONFIG_SQUASHFS_XATTR=y
  1514. +CONFIG_SQUASHFS_LZO=y
  1515. +CONFIG_SQUASHFS_XZ=y
  1516. +CONFIG_F2FS_FS=y
  1517. +CONFIG_NFS_FS=y
  1518. +CONFIG_NFS_V3_ACL=y
  1519. +CONFIG_NFS_V4=y
  1520. +CONFIG_ROOT_NFS=y
  1521. +CONFIG_NFS_FSCACHE=y
  1522. +CONFIG_NFSD=m
  1523. +CONFIG_NFSD_V3_ACL=y
  1524. +CONFIG_NFSD_V4=y
  1525. +CONFIG_CIFS=m
  1526. +CONFIG_CIFS_WEAK_PW_HASH=y
  1527. +CONFIG_CIFS_XATTR=y
  1528. +CONFIG_CIFS_POSIX=y
  1529. +CONFIG_9P_FS=m
  1530. +CONFIG_9P_FS_POSIX_ACL=y
  1531. +CONFIG_NLS_DEFAULT="utf8"
  1532. +CONFIG_NLS_CODEPAGE_437=y
  1533. +CONFIG_NLS_CODEPAGE_737=m
  1534. +CONFIG_NLS_CODEPAGE_775=m
  1535. +CONFIG_NLS_CODEPAGE_850=m
  1536. +CONFIG_NLS_CODEPAGE_852=m
  1537. +CONFIG_NLS_CODEPAGE_855=m
  1538. +CONFIG_NLS_CODEPAGE_857=m
  1539. +CONFIG_NLS_CODEPAGE_860=m
  1540. +CONFIG_NLS_CODEPAGE_861=m
  1541. +CONFIG_NLS_CODEPAGE_862=m
  1542. +CONFIG_NLS_CODEPAGE_863=m
  1543. +CONFIG_NLS_CODEPAGE_864=m
  1544. +CONFIG_NLS_CODEPAGE_865=m
  1545. +CONFIG_NLS_CODEPAGE_866=m
  1546. +CONFIG_NLS_CODEPAGE_869=m
  1547. +CONFIG_NLS_CODEPAGE_936=m
  1548. +CONFIG_NLS_CODEPAGE_950=m
  1549. +CONFIG_NLS_CODEPAGE_932=m
  1550. +CONFIG_NLS_CODEPAGE_949=m
  1551. +CONFIG_NLS_CODEPAGE_874=m
  1552. +CONFIG_NLS_ISO8859_8=m
  1553. +CONFIG_NLS_CODEPAGE_1250=m
  1554. +CONFIG_NLS_CODEPAGE_1251=m
  1555. +CONFIG_NLS_ASCII=y
  1556. +CONFIG_NLS_ISO8859_1=m
  1557. +CONFIG_NLS_ISO8859_2=m
  1558. +CONFIG_NLS_ISO8859_3=m
  1559. +CONFIG_NLS_ISO8859_4=m
  1560. +CONFIG_NLS_ISO8859_5=m
  1561. +CONFIG_NLS_ISO8859_6=m
  1562. +CONFIG_NLS_ISO8859_7=m
  1563. +CONFIG_NLS_ISO8859_9=m
  1564. +CONFIG_NLS_ISO8859_13=m
  1565. +CONFIG_NLS_ISO8859_14=m
  1566. +CONFIG_NLS_ISO8859_15=m
  1567. +CONFIG_NLS_KOI8_R=m
  1568. +CONFIG_NLS_KOI8_U=m
  1569. +CONFIG_DLM=m
  1570. +CONFIG_PRINTK_TIME=y
  1571. +CONFIG_BOOT_PRINTK_DELAY=y
  1572. +CONFIG_DEBUG_FS=y
  1573. +CONFIG_DEBUG_MEMORY_INIT=y
  1574. +CONFIG_DETECT_HUNG_TASK=y
  1575. +CONFIG_TIMER_STATS=y
  1576. +# CONFIG_DEBUG_PREEMPT is not set
  1577. +CONFIG_LATENCYTOP=y
  1578. +# CONFIG_KPROBE_EVENT is not set
  1579. +CONFIG_KGDB=y
  1580. +CONFIG_KGDB_KDB=y
  1581. +CONFIG_KDB_KEYBOARD=y
  1582. +CONFIG_STRICT_DEVMEM=y
  1583. +CONFIG_CRYPTO_USER=m
  1584. +CONFIG_CRYPTO_NULL=m
  1585. +CONFIG_CRYPTO_CRYPTD=m
  1586. +CONFIG_CRYPTO_CBC=y
  1587. +CONFIG_CRYPTO_XTS=m
  1588. +CONFIG_CRYPTO_XCBC=m
  1589. +CONFIG_CRYPTO_SHA1_ARM=m
  1590. +CONFIG_CRYPTO_SHA512=m
  1591. +CONFIG_CRYPTO_TGR192=m
  1592. +CONFIG_CRYPTO_WP512=m
  1593. +CONFIG_CRYPTO_AES_ARM=m
  1594. +CONFIG_CRYPTO_CAST5=m
  1595. +CONFIG_CRYPTO_DES=y
  1596. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  1597. +# CONFIG_CRYPTO_HW is not set
  1598. +CONFIG_CRC_ITU_T=y
  1599. +CONFIG_LIBCRC32C=y
  1600. diff -Nur linux-3.13.3.orig/arch/arm/configs/bcmrpi_emergency_defconfig linux-3.13.3/arch/arm/configs/bcmrpi_emergency_defconfig
  1601. --- linux-3.13.3.orig/arch/arm/configs/bcmrpi_emergency_defconfig 1970-01-01 01:00:00.000000000 +0100
  1602. +++ linux-3.13.3/arch/arm/configs/bcmrpi_emergency_defconfig 2014-02-17 22:41:01.000000000 +0100
  1603. @@ -0,0 +1,532 @@
  1604. +CONFIG_EXPERIMENTAL=y
  1605. +# CONFIG_LOCALVERSION_AUTO is not set
  1606. +CONFIG_SYSVIPC=y
  1607. +CONFIG_POSIX_MQUEUE=y
  1608. +CONFIG_BSD_PROCESS_ACCT=y
  1609. +CONFIG_BSD_PROCESS_ACCT_V3=y
  1610. +CONFIG_FHANDLE=y
  1611. +CONFIG_AUDIT=y
  1612. +CONFIG_IKCONFIG=y
  1613. +CONFIG_IKCONFIG_PROC=y
  1614. +CONFIG_BLK_DEV_INITRD=y
  1615. +CONFIG_INITRAMFS_SOURCE="../target_fs"
  1616. +CONFIG_CGROUP_FREEZER=y
  1617. +CONFIG_CGROUP_DEVICE=y
  1618. +CONFIG_CGROUP_CPUACCT=y
  1619. +CONFIG_RESOURCE_COUNTERS=y
  1620. +CONFIG_BLK_CGROUP=y
  1621. +CONFIG_NAMESPACES=y
  1622. +CONFIG_SCHED_AUTOGROUP=y
  1623. +CONFIG_EMBEDDED=y
  1624. +# CONFIG_COMPAT_BRK is not set
  1625. +CONFIG_SLAB=y
  1626. +CONFIG_PROFILING=y
  1627. +CONFIG_OPROFILE=m
  1628. +CONFIG_KPROBES=y
  1629. +CONFIG_MODULES=y
  1630. +CONFIG_MODULE_UNLOAD=y
  1631. +CONFIG_MODVERSIONS=y
  1632. +CONFIG_MODULE_SRCVERSION_ALL=y
  1633. +# CONFIG_BLK_DEV_BSG is not set
  1634. +CONFIG_BLK_DEV_THROTTLING=y
  1635. +CONFIG_CFQ_GROUP_IOSCHED=y
  1636. +CONFIG_ARCH_BCM2708=y
  1637. +CONFIG_NO_HZ=y
  1638. +CONFIG_HIGH_RES_TIMERS=y
  1639. +CONFIG_AEABI=y
  1640. +CONFIG_SECCOMP=y
  1641. +CONFIG_CC_STACKPROTECTOR=y
  1642. +CONFIG_ZBOOT_ROM_TEXT=0x0
  1643. +CONFIG_ZBOOT_ROM_BSS=0x0
  1644. +CONFIG_CMDLINE="dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext3 rootwait"
  1645. +CONFIG_KEXEC=y
  1646. +CONFIG_CPU_IDLE=y
  1647. +CONFIG_VFP=y
  1648. +CONFIG_BINFMT_MISC=m
  1649. +CONFIG_NET=y
  1650. +CONFIG_PACKET=y
  1651. +CONFIG_UNIX=y
  1652. +CONFIG_XFRM_USER=y
  1653. +CONFIG_NET_KEY=m
  1654. +CONFIG_INET=y
  1655. +CONFIG_IP_MULTICAST=y
  1656. +CONFIG_IP_PNP=y
  1657. +CONFIG_IP_PNP_DHCP=y
  1658. +CONFIG_IP_PNP_RARP=y
  1659. +CONFIG_SYN_COOKIES=y
  1660. +# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
  1661. +# CONFIG_INET_XFRM_MODE_TUNNEL is not set
  1662. +# CONFIG_INET_XFRM_MODE_BEET is not set
  1663. +# CONFIG_INET_LRO is not set
  1664. +# CONFIG_INET_DIAG is not set
  1665. +# CONFIG_IPV6 is not set
  1666. +CONFIG_NET_PKTGEN=m
  1667. +CONFIG_IRDA=m
  1668. +CONFIG_IRLAN=m
  1669. +CONFIG_IRCOMM=m
  1670. +CONFIG_IRDA_ULTRA=y
  1671. +CONFIG_IRDA_CACHE_LAST_LSAP=y
  1672. +CONFIG_IRDA_FAST_RR=y
  1673. +CONFIG_IRTTY_SIR=m
  1674. +CONFIG_KINGSUN_DONGLE=m
  1675. +CONFIG_KSDAZZLE_DONGLE=m
  1676. +CONFIG_KS959_DONGLE=m
  1677. +CONFIG_USB_IRDA=m
  1678. +CONFIG_SIGMATEL_FIR=m
  1679. +CONFIG_MCS_FIR=m
  1680. +CONFIG_BT=m
  1681. +CONFIG_BT_L2CAP=y
  1682. +CONFIG_BT_SCO=y
  1683. +CONFIG_BT_RFCOMM=m
  1684. +CONFIG_BT_RFCOMM_TTY=y
  1685. +CONFIG_BT_BNEP=m
  1686. +CONFIG_BT_BNEP_MC_FILTER=y
  1687. +CONFIG_BT_BNEP_PROTO_FILTER=y
  1688. +CONFIG_BT_HIDP=m
  1689. +CONFIG_BT_HCIBTUSB=m
  1690. +CONFIG_BT_HCIBCM203X=m
  1691. +CONFIG_BT_HCIBPA10X=m
  1692. +CONFIG_BT_HCIBFUSB=m
  1693. +CONFIG_BT_HCIVHCI=m
  1694. +CONFIG_BT_MRVL=m
  1695. +CONFIG_BT_MRVL_SDIO=m
  1696. +CONFIG_BT_ATH3K=m
  1697. +CONFIG_CFG80211=m
  1698. +CONFIG_MAC80211=m
  1699. +CONFIG_MAC80211_RC_PID=y
  1700. +CONFIG_MAC80211_MESH=y
  1701. +CONFIG_WIMAX=m
  1702. +CONFIG_NET_9P=m
  1703. +CONFIG_NFC=m
  1704. +CONFIG_NFC_PN533=m
  1705. +CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
  1706. +CONFIG_BLK_DEV_LOOP=y
  1707. +CONFIG_BLK_DEV_CRYPTOLOOP=m
  1708. +CONFIG_BLK_DEV_NBD=m
  1709. +CONFIG_BLK_DEV_RAM=y
  1710. +CONFIG_CDROM_PKTCDVD=m
  1711. +CONFIG_MISC_DEVICES=y
  1712. +CONFIG_SCSI=y
  1713. +# CONFIG_SCSI_PROC_FS is not set
  1714. +CONFIG_BLK_DEV_SD=y
  1715. +CONFIG_BLK_DEV_SR=m
  1716. +CONFIG_SCSI_MULTI_LUN=y
  1717. +# CONFIG_SCSI_LOWLEVEL is not set
  1718. +CONFIG_MD=y
  1719. +CONFIG_NETDEVICES=y
  1720. +CONFIG_TUN=m
  1721. +CONFIG_PHYLIB=m
  1722. +CONFIG_MDIO_BITBANG=m
  1723. +CONFIG_NET_ETHERNET=y
  1724. +# CONFIG_NETDEV_1000 is not set
  1725. +# CONFIG_NETDEV_10000 is not set
  1726. +CONFIG_LIBERTAS_THINFIRM=m
  1727. +CONFIG_LIBERTAS_THINFIRM_USB=m
  1728. +CONFIG_AT76C50X_USB=m
  1729. +CONFIG_USB_ZD1201=m
  1730. +CONFIG_USB_NET_RNDIS_WLAN=m
  1731. +CONFIG_RTL8187=m
  1732. +CONFIG_MAC80211_HWSIM=m
  1733. +CONFIG_ATH_COMMON=m
  1734. +CONFIG_ATH9K=m
  1735. +CONFIG_ATH9K_HTC=m
  1736. +CONFIG_CARL9170=m
  1737. +CONFIG_B43=m
  1738. +CONFIG_B43LEGACY=m
  1739. +CONFIG_HOSTAP=m
  1740. +CONFIG_IWM=m
  1741. +CONFIG_LIBERTAS=m
  1742. +CONFIG_LIBERTAS_USB=m
  1743. +CONFIG_LIBERTAS_SDIO=m
  1744. +CONFIG_P54_COMMON=m
  1745. +CONFIG_P54_USB=m
  1746. +CONFIG_RT2X00=m
  1747. +CONFIG_RT2500USB=m
  1748. +CONFIG_RT73USB=m
  1749. +CONFIG_RT2800USB=m
  1750. +CONFIG_RT2800USB_RT53XX=y
  1751. +CONFIG_RTL8192CU=m
  1752. +CONFIG_WL1251=m
  1753. +CONFIG_WL12XX_MENU=m
  1754. +CONFIG_ZD1211RW=m
  1755. +CONFIG_MWIFIEX=m
  1756. +CONFIG_MWIFIEX_SDIO=m
  1757. +CONFIG_WIMAX_I2400M_USB=m
  1758. +CONFIG_USB_CATC=m
  1759. +CONFIG_USB_KAWETH=m
  1760. +CONFIG_USB_PEGASUS=m
  1761. +CONFIG_USB_RTL8150=m
  1762. +CONFIG_USB_USBNET=y
  1763. +CONFIG_USB_NET_AX8817X=m
  1764. +CONFIG_USB_NET_CDCETHER=m
  1765. +CONFIG_USB_NET_CDC_EEM=m
  1766. +CONFIG_USB_NET_DM9601=m
  1767. +CONFIG_USB_NET_SMSC75XX=m
  1768. +CONFIG_USB_NET_SMSC95XX=y
  1769. +CONFIG_USB_NET_GL620A=m
  1770. +CONFIG_USB_NET_NET1080=m
  1771. +CONFIG_USB_NET_PLUSB=m
  1772. +CONFIG_USB_NET_MCS7830=m
  1773. +CONFIG_USB_NET_CDC_SUBSET=m
  1774. +CONFIG_USB_ALI_M5632=y
  1775. +CONFIG_USB_AN2720=y
  1776. +CONFIG_USB_KC2190=y
  1777. +# CONFIG_USB_NET_ZAURUS is not set
  1778. +CONFIG_USB_NET_CX82310_ETH=m
  1779. +CONFIG_USB_NET_KALMIA=m
  1780. +CONFIG_USB_NET_INT51X1=m
  1781. +CONFIG_USB_IPHETH=m
  1782. +CONFIG_USB_SIERRA_NET=m
  1783. +CONFIG_USB_VL600=m
  1784. +CONFIG_PPP=m
  1785. +CONFIG_PPP_ASYNC=m
  1786. +CONFIG_PPP_SYNC_TTY=m
  1787. +CONFIG_PPP_DEFLATE=m
  1788. +CONFIG_PPP_BSDCOMP=m
  1789. +CONFIG_SLIP=m
  1790. +CONFIG_SLIP_COMPRESSED=y
  1791. +CONFIG_NETCONSOLE=m
  1792. +CONFIG_INPUT_POLLDEV=m
  1793. +# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
  1794. +CONFIG_INPUT_JOYDEV=m
  1795. +CONFIG_INPUT_EVDEV=m
  1796. +# CONFIG_INPUT_KEYBOARD is not set
  1797. +# CONFIG_INPUT_MOUSE is not set
  1798. +CONFIG_INPUT_MISC=y
  1799. +CONFIG_INPUT_AD714X=m
  1800. +CONFIG_INPUT_ATI_REMOTE=m
  1801. +CONFIG_INPUT_ATI_REMOTE2=m
  1802. +CONFIG_INPUT_KEYSPAN_REMOTE=m
  1803. +CONFIG_INPUT_POWERMATE=m
  1804. +CONFIG_INPUT_YEALINK=m
  1805. +CONFIG_INPUT_CM109=m
  1806. +CONFIG_INPUT_UINPUT=m
  1807. +CONFIG_INPUT_GPIO_ROTARY_ENCODER=m
  1808. +CONFIG_INPUT_ADXL34X=m
  1809. +CONFIG_INPUT_CMA3000=m
  1810. +CONFIG_SERIO=m
  1811. +CONFIG_SERIO_RAW=m
  1812. +CONFIG_GAMEPORT=m
  1813. +CONFIG_GAMEPORT_NS558=m
  1814. +CONFIG_GAMEPORT_L4=m
  1815. +CONFIG_VT_HW_CONSOLE_BINDING=y
  1816. +# CONFIG_LEGACY_PTYS is not set
  1817. +# CONFIG_DEVKMEM is not set
  1818. +CONFIG_SERIAL_AMBA_PL011=y
  1819. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  1820. +# CONFIG_HW_RANDOM is not set
  1821. +CONFIG_RAW_DRIVER=y
  1822. +CONFIG_GPIO_SYSFS=y
  1823. +# CONFIG_HWMON is not set
  1824. +CONFIG_WATCHDOG=y
  1825. +CONFIG_BCM2708_WDT=m
  1826. +# CONFIG_MFD_SUPPORT is not set
  1827. +CONFIG_FB=y
  1828. +CONFIG_FB_BCM2708=y
  1829. +CONFIG_FRAMEBUFFER_CONSOLE=y
  1830. +CONFIG_LOGO=y
  1831. +# CONFIG_LOGO_LINUX_MONO is not set
  1832. +# CONFIG_LOGO_LINUX_VGA16 is not set
  1833. +CONFIG_SOUND=y
  1834. +CONFIG_SND=m
  1835. +CONFIG_SND_SEQUENCER=m
  1836. +CONFIG_SND_SEQ_DUMMY=m
  1837. +CONFIG_SND_MIXER_OSS=m
  1838. +CONFIG_SND_PCM_OSS=m
  1839. +CONFIG_SND_SEQUENCER_OSS=y
  1840. +CONFIG_SND_HRTIMER=m
  1841. +CONFIG_SND_DUMMY=m
  1842. +CONFIG_SND_ALOOP=m
  1843. +CONFIG_SND_VIRMIDI=m
  1844. +CONFIG_SND_MTPAV=m
  1845. +CONFIG_SND_SERIAL_U16550=m
  1846. +CONFIG_SND_MPU401=m
  1847. +CONFIG_SND_BCM2835=m
  1848. +CONFIG_SND_USB_AUDIO=m
  1849. +CONFIG_SND_USB_UA101=m
  1850. +CONFIG_SND_USB_CAIAQ=m
  1851. +CONFIG_SND_USB_6FIRE=m
  1852. +CONFIG_SOUND_PRIME=m
  1853. +CONFIG_HID_PID=y
  1854. +CONFIG_USB_HIDDEV=y
  1855. +CONFIG_HID_A4TECH=m
  1856. +CONFIG_HID_ACRUX=m
  1857. +CONFIG_HID_APPLE=m
  1858. +CONFIG_HID_BELKIN=m
  1859. +CONFIG_HID_CHERRY=m
  1860. +CONFIG_HID_CHICONY=m
  1861. +CONFIG_HID_CYPRESS=m
  1862. +CONFIG_HID_DRAGONRISE=m
  1863. +CONFIG_HID_EMS_FF=m
  1864. +CONFIG_HID_ELECOM=m
  1865. +CONFIG_HID_EZKEY=m
  1866. +CONFIG_HID_HOLTEK=m
  1867. +CONFIG_HID_KEYTOUCH=m
  1868. +CONFIG_HID_KYE=m
  1869. +CONFIG_HID_UCLOGIC=m
  1870. +CONFIG_HID_WALTOP=m
  1871. +CONFIG_HID_GYRATION=m
  1872. +CONFIG_HID_TWINHAN=m
  1873. +CONFIG_HID_KENSINGTON=m
  1874. +CONFIG_HID_LCPOWER=m
  1875. +CONFIG_HID_LOGITECH=m
  1876. +CONFIG_HID_MAGICMOUSE=m
  1877. +CONFIG_HID_MICROSOFT=m
  1878. +CONFIG_HID_MONTEREY=m
  1879. +CONFIG_HID_MULTITOUCH=m
  1880. +CONFIG_HID_NTRIG=m
  1881. +CONFIG_HID_ORTEK=m
  1882. +CONFIG_HID_PANTHERLORD=m
  1883. +CONFIG_HID_PETALYNX=m
  1884. +CONFIG_HID_PICOLCD=m
  1885. +CONFIG_HID_QUANTA=m
  1886. +CONFIG_HID_ROCCAT=m
  1887. +CONFIG_HID_SAMSUNG=m
  1888. +CONFIG_HID_SONY=m
  1889. +CONFIG_HID_SPEEDLINK=m
  1890. +CONFIG_HID_SUNPLUS=m
  1891. +CONFIG_HID_GREENASIA=m
  1892. +CONFIG_HID_SMARTJOYPLUS=m
  1893. +CONFIG_HID_TOPSEED=m
  1894. +CONFIG_HID_THRUSTMASTER=m
  1895. +CONFIG_HID_WACOM=m
  1896. +CONFIG_HID_WIIMOTE=m
  1897. +CONFIG_HID_ZEROPLUS=m
  1898. +CONFIG_HID_ZYDACRON=m
  1899. +CONFIG_USB=y
  1900. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  1901. +CONFIG_USB_MON=m
  1902. +CONFIG_USB_DWCOTG=y
  1903. +CONFIG_USB_STORAGE=y
  1904. +CONFIG_USB_STORAGE_REALTEK=m
  1905. +CONFIG_USB_STORAGE_DATAFAB=m
  1906. +CONFIG_USB_STORAGE_FREECOM=m
  1907. +CONFIG_USB_STORAGE_ISD200=m
  1908. +CONFIG_USB_STORAGE_USBAT=m
  1909. +CONFIG_USB_STORAGE_SDDR09=m
  1910. +CONFIG_USB_STORAGE_SDDR55=m
  1911. +CONFIG_USB_STORAGE_JUMPSHOT=m
  1912. +CONFIG_USB_STORAGE_ALAUDA=m
  1913. +CONFIG_USB_STORAGE_ONETOUCH=m
  1914. +CONFIG_USB_STORAGE_KARMA=m
  1915. +CONFIG_USB_STORAGE_CYPRESS_ATACB=m
  1916. +CONFIG_USB_STORAGE_ENE_UB6250=m
  1917. +CONFIG_USB_UAS=y
  1918. +CONFIG_USB_LIBUSUAL=y
  1919. +CONFIG_USB_MDC800=m
  1920. +CONFIG_USB_MICROTEK=m
  1921. +CONFIG_USB_SERIAL=m
  1922. +CONFIG_USB_SERIAL_GENERIC=y
  1923. +CONFIG_USB_SERIAL_AIRCABLE=m
  1924. +CONFIG_USB_SERIAL_ARK3116=m
  1925. +CONFIG_USB_SERIAL_BELKIN=m
  1926. +CONFIG_USB_SERIAL_CH341=m
  1927. +CONFIG_USB_SERIAL_WHITEHEAT=m
  1928. +CONFIG_USB_SERIAL_DIGI_ACCELEPORT=m
  1929. +CONFIG_USB_SERIAL_CP210X=m
  1930. +CONFIG_USB_SERIAL_CYPRESS_M8=m
  1931. +CONFIG_USB_SERIAL_EMPEG=m
  1932. +CONFIG_USB_SERIAL_FTDI_SIO=m
  1933. +CONFIG_USB_SERIAL_FUNSOFT=m
  1934. +CONFIG_USB_SERIAL_VISOR=m
  1935. +CONFIG_USB_SERIAL_IPAQ=m
  1936. +CONFIG_USB_SERIAL_IR=m
  1937. +CONFIG_USB_SERIAL_EDGEPORT=m
  1938. +CONFIG_USB_SERIAL_EDGEPORT_TI=m
  1939. +CONFIG_USB_SERIAL_GARMIN=m
  1940. +CONFIG_USB_SERIAL_IPW=m
  1941. +CONFIG_USB_SERIAL_IUU=m
  1942. +CONFIG_USB_SERIAL_KEYSPAN_PDA=m
  1943. +CONFIG_USB_SERIAL_KEYSPAN=m
  1944. +CONFIG_USB_SERIAL_KLSI=m
  1945. +CONFIG_USB_SERIAL_KOBIL_SCT=m
  1946. +CONFIG_USB_SERIAL_MCT_U232=m
  1947. +CONFIG_USB_SERIAL_MOS7720=m
  1948. +CONFIG_USB_SERIAL_MOS7840=m
  1949. +CONFIG_USB_SERIAL_MOTOROLA=m
  1950. +CONFIG_USB_SERIAL_NAVMAN=m
  1951. +CONFIG_USB_SERIAL_PL2303=m
  1952. +CONFIG_USB_SERIAL_OTI6858=m
  1953. +CONFIG_USB_SERIAL_QCAUX=m
  1954. +CONFIG_USB_SERIAL_QUALCOMM=m
  1955. +CONFIG_USB_SERIAL_SPCP8X5=m
  1956. +CONFIG_USB_SERIAL_HP4X=m
  1957. +CONFIG_USB_SERIAL_SAFE=m
  1958. +CONFIG_USB_SERIAL_SIEMENS_MPI=m
  1959. +CONFIG_USB_SERIAL_SIERRAWIRELESS=m
  1960. +CONFIG_USB_SERIAL_SYMBOL=m
  1961. +CONFIG_USB_SERIAL_TI=m
  1962. +CONFIG_USB_SERIAL_CYBERJACK=m
  1963. +CONFIG_USB_SERIAL_XIRCOM=m
  1964. +CONFIG_USB_SERIAL_OPTION=m
  1965. +CONFIG_USB_SERIAL_OMNINET=m
  1966. +CONFIG_USB_SERIAL_OPTICON=m
  1967. +CONFIG_USB_SERIAL_VIVOPAY_SERIAL=m
  1968. +CONFIG_USB_SERIAL_ZIO=m
  1969. +CONFIG_USB_SERIAL_SSU100=m
  1970. +CONFIG_USB_SERIAL_DEBUG=m
  1971. +CONFIG_USB_EMI62=m
  1972. +CONFIG_USB_EMI26=m
  1973. +CONFIG_USB_ADUTUX=m
  1974. +CONFIG_USB_SEVSEG=m
  1975. +CONFIG_USB_RIO500=m
  1976. +CONFIG_USB_LEGOTOWER=m
  1977. +CONFIG_USB_LCD=m
  1978. +CONFIG_USB_LED=m
  1979. +CONFIG_USB_CYPRESS_CY7C63=m
  1980. +CONFIG_USB_CYTHERM=m
  1981. +CONFIG_USB_IDMOUSE=m
  1982. +CONFIG_USB_FTDI_ELAN=m
  1983. +CONFIG_USB_APPLEDISPLAY=m
  1984. +CONFIG_USB_LD=m
  1985. +CONFIG_USB_TRANCEVIBRATOR=m
  1986. +CONFIG_USB_IOWARRIOR=m
  1987. +CONFIG_USB_TEST=m
  1988. +CONFIG_USB_ISIGHTFW=m
  1989. +CONFIG_USB_YUREX=m
  1990. +CONFIG_MMC=y
  1991. +CONFIG_MMC_SDHCI=y
  1992. +CONFIG_MMC_SDHCI_PLTFM=y
  1993. +CONFIG_MMC_SDHCI_BCM2708=y
  1994. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  1995. +CONFIG_LEDS_GPIO=y
  1996. +CONFIG_LEDS_TRIGGER_TIMER=m
  1997. +CONFIG_LEDS_TRIGGER_HEARTBEAT=m
  1998. +CONFIG_LEDS_TRIGGER_DEFAULT_ON=m
  1999. +CONFIG_UIO=m
  2000. +CONFIG_UIO_PDRV=m
  2001. +CONFIG_UIO_PDRV_GENIRQ=m
  2002. +# CONFIG_IOMMU_SUPPORT is not set
  2003. +CONFIG_EXT4_FS=y
  2004. +CONFIG_EXT4_FS_POSIX_ACL=y
  2005. +CONFIG_EXT4_FS_SECURITY=y
  2006. +CONFIG_REISERFS_FS=m
  2007. +CONFIG_REISERFS_FS_XATTR=y
  2008. +CONFIG_REISERFS_FS_POSIX_ACL=y
  2009. +CONFIG_REISERFS_FS_SECURITY=y
  2010. +CONFIG_JFS_FS=m
  2011. +CONFIG_JFS_POSIX_ACL=y
  2012. +CONFIG_JFS_SECURITY=y
  2013. +CONFIG_JFS_STATISTICS=y
  2014. +CONFIG_XFS_FS=m
  2015. +CONFIG_XFS_QUOTA=y
  2016. +CONFIG_XFS_POSIX_ACL=y
  2017. +CONFIG_XFS_RT=y
  2018. +CONFIG_GFS2_FS=m
  2019. +CONFIG_OCFS2_FS=m
  2020. +CONFIG_BTRFS_FS=m
  2021. +CONFIG_BTRFS_FS_POSIX_ACL=y
  2022. +CONFIG_NILFS2_FS=m
  2023. +CONFIG_FANOTIFY=y
  2024. +CONFIG_AUTOFS4_FS=y
  2025. +CONFIG_FUSE_FS=m
  2026. +CONFIG_CUSE=m
  2027. +CONFIG_FSCACHE=y
  2028. +CONFIG_FSCACHE_STATS=y
  2029. +CONFIG_FSCACHE_HISTOGRAM=y
  2030. +CONFIG_CACHEFILES=y
  2031. +CONFIG_ISO9660_FS=m
  2032. +CONFIG_JOLIET=y
  2033. +CONFIG_ZISOFS=y
  2034. +CONFIG_UDF_FS=m
  2035. +CONFIG_MSDOS_FS=y
  2036. +CONFIG_VFAT_FS=y
  2037. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  2038. +CONFIG_NTFS_FS=m
  2039. +CONFIG_TMPFS=y
  2040. +CONFIG_TMPFS_POSIX_ACL=y
  2041. +CONFIG_CONFIGFS_FS=y
  2042. +CONFIG_SQUASHFS=m
  2043. +CONFIG_SQUASHFS_XATTR=y
  2044. +CONFIG_SQUASHFS_LZO=y
  2045. +CONFIG_SQUASHFS_XZ=y
  2046. +CONFIG_NFS_FS=y
  2047. +CONFIG_NFS_V3=y
  2048. +CONFIG_NFS_V3_ACL=y
  2049. +CONFIG_NFS_V4=y
  2050. +CONFIG_ROOT_NFS=y
  2051. +CONFIG_NFS_FSCACHE=y
  2052. +CONFIG_CIFS=m
  2053. +CONFIG_CIFS_WEAK_PW_HASH=y
  2054. +CONFIG_CIFS_XATTR=y
  2055. +CONFIG_CIFS_POSIX=y
  2056. +CONFIG_9P_FS=m
  2057. +CONFIG_9P_FS_POSIX_ACL=y
  2058. +CONFIG_PARTITION_ADVANCED=y
  2059. +CONFIG_MAC_PARTITION=y
  2060. +CONFIG_EFI_PARTITION=y
  2061. +CONFIG_NLS_DEFAULT="utf8"
  2062. +CONFIG_NLS_CODEPAGE_437=y
  2063. +CONFIG_NLS_CODEPAGE_737=m
  2064. +CONFIG_NLS_CODEPAGE_775=m
  2065. +CONFIG_NLS_CODEPAGE_850=m
  2066. +CONFIG_NLS_CODEPAGE_852=m
  2067. +CONFIG_NLS_CODEPAGE_855=m
  2068. +CONFIG_NLS_CODEPAGE_857=m
  2069. +CONFIG_NLS_CODEPAGE_860=m
  2070. +CONFIG_NLS_CODEPAGE_861=m
  2071. +CONFIG_NLS_CODEPAGE_862=m
  2072. +CONFIG_NLS_CODEPAGE_863=m
  2073. +CONFIG_NLS_CODEPAGE_864=m
  2074. +CONFIG_NLS_CODEPAGE_865=m
  2075. +CONFIG_NLS_CODEPAGE_866=m
  2076. +CONFIG_NLS_CODEPAGE_869=m
  2077. +CONFIG_NLS_CODEPAGE_936=m
  2078. +CONFIG_NLS_CODEPAGE_950=m
  2079. +CONFIG_NLS_CODEPAGE_932=m
  2080. +CONFIG_NLS_CODEPAGE_949=m
  2081. +CONFIG_NLS_CODEPAGE_874=m
  2082. +CONFIG_NLS_ISO8859_8=m
  2083. +CONFIG_NLS_CODEPAGE_1250=m
  2084. +CONFIG_NLS_CODEPAGE_1251=m
  2085. +CONFIG_NLS_ASCII=y
  2086. +CONFIG_NLS_ISO8859_1=m
  2087. +CONFIG_NLS_ISO8859_2=m
  2088. +CONFIG_NLS_ISO8859_3=m
  2089. +CONFIG_NLS_ISO8859_4=m
  2090. +CONFIG_NLS_ISO8859_5=m
  2091. +CONFIG_NLS_ISO8859_6=m
  2092. +CONFIG_NLS_ISO8859_7=m
  2093. +CONFIG_NLS_ISO8859_9=m
  2094. +CONFIG_NLS_ISO8859_13=m
  2095. +CONFIG_NLS_ISO8859_14=m
  2096. +CONFIG_NLS_ISO8859_15=m
  2097. +CONFIG_NLS_KOI8_R=m
  2098. +CONFIG_NLS_KOI8_U=m
  2099. +CONFIG_NLS_UTF8=m
  2100. +CONFIG_PRINTK_TIME=y
  2101. +CONFIG_DETECT_HUNG_TASK=y
  2102. +CONFIG_TIMER_STATS=y
  2103. +CONFIG_DEBUG_STACK_USAGE=y
  2104. +CONFIG_DEBUG_INFO=y
  2105. +CONFIG_DEBUG_MEMORY_INIT=y
  2106. +CONFIG_BOOT_PRINTK_DELAY=y
  2107. +CONFIG_LATENCYTOP=y
  2108. +CONFIG_SYSCTL_SYSCALL_CHECK=y
  2109. +CONFIG_IRQSOFF_TRACER=y
  2110. +CONFIG_SCHED_TRACER=y
  2111. +CONFIG_STACK_TRACER=y
  2112. +CONFIG_BLK_DEV_IO_TRACE=y
  2113. +CONFIG_FUNCTION_PROFILER=y
  2114. +CONFIG_KGDB=y
  2115. +CONFIG_KGDB_KDB=y
  2116. +CONFIG_KDB_KEYBOARD=y
  2117. +CONFIG_STRICT_DEVMEM=y
  2118. +CONFIG_CRYPTO_AUTHENC=m
  2119. +CONFIG_CRYPTO_SEQIV=m
  2120. +CONFIG_CRYPTO_CBC=y
  2121. +CONFIG_CRYPTO_HMAC=y
  2122. +CONFIG_CRYPTO_XCBC=m
  2123. +CONFIG_CRYPTO_MD5=y
  2124. +CONFIG_CRYPTO_SHA1=y
  2125. +CONFIG_CRYPTO_SHA256=m
  2126. +CONFIG_CRYPTO_SHA512=m
  2127. +CONFIG_CRYPTO_TGR192=m
  2128. +CONFIG_CRYPTO_WP512=m
  2129. +CONFIG_CRYPTO_CAST5=m
  2130. +CONFIG_CRYPTO_DES=y
  2131. +CONFIG_CRYPTO_DEFLATE=m
  2132. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  2133. +# CONFIG_CRYPTO_HW is not set
  2134. +CONFIG_CRC_ITU_T=y
  2135. +CONFIG_LIBCRC32C=y
  2136. diff -Nur linux-3.13.3.orig/arch/arm/configs/bcmrpi_quick_defconfig linux-3.13.3/arch/arm/configs/bcmrpi_quick_defconfig
  2137. --- linux-3.13.3.orig/arch/arm/configs/bcmrpi_quick_defconfig 1970-01-01 01:00:00.000000000 +0100
  2138. +++ linux-3.13.3/arch/arm/configs/bcmrpi_quick_defconfig 2014-02-17 22:41:01.000000000 +0100
  2139. @@ -0,0 +1,197 @@
  2140. +# CONFIG_ARM_PATCH_PHYS_VIRT is not set
  2141. +CONFIG_LOCALVERSION="-quick"
  2142. +# CONFIG_LOCALVERSION_AUTO is not set
  2143. +# CONFIG_SWAP is not set
  2144. +CONFIG_SYSVIPC=y
  2145. +CONFIG_POSIX_MQUEUE=y
  2146. +CONFIG_NO_HZ=y
  2147. +CONFIG_HIGH_RES_TIMERS=y
  2148. +CONFIG_IKCONFIG=y
  2149. +CONFIG_IKCONFIG_PROC=y
  2150. +CONFIG_KALLSYMS_ALL=y
  2151. +CONFIG_EMBEDDED=y
  2152. +CONFIG_PERF_EVENTS=y
  2153. +# CONFIG_COMPAT_BRK is not set
  2154. +CONFIG_SLAB=y
  2155. +CONFIG_MODULES=y
  2156. +CONFIG_MODULE_UNLOAD=y
  2157. +CONFIG_MODVERSIONS=y
  2158. +CONFIG_MODULE_SRCVERSION_ALL=y
  2159. +# CONFIG_BLK_DEV_BSG is not set
  2160. +CONFIG_ARCH_BCM2708=y
  2161. +CONFIG_PREEMPT=y
  2162. +CONFIG_AEABI=y
  2163. +CONFIG_UACCESS_WITH_MEMCPY=y
  2164. +CONFIG_ZBOOT_ROM_TEXT=0x0
  2165. +CONFIG_ZBOOT_ROM_BSS=0x0
  2166. +CONFIG_CMDLINE="dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait"
  2167. +CONFIG_CPU_FREQ=y
  2168. +CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE=y
  2169. +CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
  2170. +CONFIG_CPU_FREQ_GOV_USERSPACE=y
  2171. +CONFIG_CPU_FREQ_GOV_ONDEMAND=y
  2172. +CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
  2173. +CONFIG_CPU_IDLE=y
  2174. +CONFIG_VFP=y
  2175. +CONFIG_BINFMT_MISC=y
  2176. +CONFIG_NET=y
  2177. +CONFIG_PACKET=y
  2178. +CONFIG_UNIX=y
  2179. +CONFIG_INET=y
  2180. +CONFIG_IP_MULTICAST=y
  2181. +CONFIG_IP_PNP=y
  2182. +CONFIG_IP_PNP_DHCP=y
  2183. +CONFIG_IP_PNP_RARP=y
  2184. +CONFIG_SYN_COOKIES=y
  2185. +# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
  2186. +# CONFIG_INET_XFRM_MODE_TUNNEL is not set
  2187. +# CONFIG_INET_XFRM_MODE_BEET is not set
  2188. +# CONFIG_INET_LRO is not set
  2189. +# CONFIG_INET_DIAG is not set
  2190. +# CONFIG_IPV6 is not set
  2191. +# CONFIG_WIRELESS is not set
  2192. +CONFIG_DEVTMPFS=y
  2193. +CONFIG_DEVTMPFS_MOUNT=y
  2194. +CONFIG_BLK_DEV_LOOP=y
  2195. +CONFIG_BLK_DEV_RAM=y
  2196. +CONFIG_SCSI=y
  2197. +# CONFIG_SCSI_PROC_FS is not set
  2198. +# CONFIG_SCSI_LOWLEVEL is not set
  2199. +CONFIG_NETDEVICES=y
  2200. +# CONFIG_NET_VENDOR_BROADCOM is not set
  2201. +# CONFIG_NET_VENDOR_CIRRUS is not set
  2202. +# CONFIG_NET_VENDOR_FARADAY is not set
  2203. +# CONFIG_NET_VENDOR_INTEL is not set
  2204. +# CONFIG_NET_VENDOR_MARVELL is not set
  2205. +# CONFIG_NET_VENDOR_MICREL is not set
  2206. +# CONFIG_NET_VENDOR_NATSEMI is not set
  2207. +# CONFIG_NET_VENDOR_SEEQ is not set
  2208. +# CONFIG_NET_VENDOR_STMICRO is not set
  2209. +# CONFIG_NET_VENDOR_WIZNET is not set
  2210. +CONFIG_USB_USBNET=y
  2211. +# CONFIG_USB_NET_AX8817X is not set
  2212. +# CONFIG_USB_NET_CDCETHER is not set
  2213. +# CONFIG_USB_NET_CDC_NCM is not set
  2214. +CONFIG_USB_NET_SMSC95XX=y
  2215. +# CONFIG_USB_NET_NET1080 is not set
  2216. +# CONFIG_USB_NET_CDC_SUBSET is not set
  2217. +# CONFIG_USB_NET_ZAURUS is not set
  2218. +# CONFIG_WLAN is not set
  2219. +# CONFIG_INPUT_MOUSEDEV is not set
  2220. +CONFIG_INPUT_EVDEV=y
  2221. +# CONFIG_INPUT_KEYBOARD is not set
  2222. +# CONFIG_INPUT_MOUSE is not set
  2223. +# CONFIG_SERIO is not set
  2224. +CONFIG_VT_HW_CONSOLE_BINDING=y
  2225. +# CONFIG_LEGACY_PTYS is not set
  2226. +# CONFIG_DEVKMEM is not set
  2227. +CONFIG_SERIAL_AMBA_PL011=y
  2228. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  2229. +CONFIG_TTY_PRINTK=y
  2230. +CONFIG_HW_RANDOM=y
  2231. +CONFIG_HW_RANDOM_BCM2708=y
  2232. +CONFIG_RAW_DRIVER=y
  2233. +CONFIG_THERMAL=y
  2234. +CONFIG_THERMAL_BCM2835=y
  2235. +CONFIG_WATCHDOG=y
  2236. +CONFIG_BCM2708_WDT=y
  2237. +CONFIG_REGULATOR=y
  2238. +CONFIG_REGULATOR_DEBUG=y
  2239. +CONFIG_REGULATOR_FIXED_VOLTAGE=y
  2240. +CONFIG_REGULATOR_VIRTUAL_CONSUMER=y
  2241. +CONFIG_REGULATOR_USERSPACE_CONSUMER=y
  2242. +CONFIG_FB=y
  2243. +CONFIG_FB_BCM2708=y
  2244. +CONFIG_FRAMEBUFFER_CONSOLE=y
  2245. +CONFIG_LOGO=y
  2246. +# CONFIG_LOGO_LINUX_MONO is not set
  2247. +# CONFIG_LOGO_LINUX_VGA16 is not set
  2248. +CONFIG_SOUND=y
  2249. +CONFIG_SND=y
  2250. +CONFIG_SND_BCM2835=y
  2251. +# CONFIG_SND_USB is not set
  2252. +CONFIG_USB=y
  2253. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  2254. +CONFIG_USB_DWCOTG=y
  2255. +CONFIG_MMC=y
  2256. +CONFIG_MMC_SDHCI=y
  2257. +CONFIG_MMC_SDHCI_PLTFM=y
  2258. +CONFIG_MMC_SDHCI_BCM2708=y
  2259. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  2260. +CONFIG_NEW_LEDS=y
  2261. +CONFIG_LEDS_CLASS=y
  2262. +CONFIG_LEDS_TRIGGERS=y
  2263. +# CONFIG_IOMMU_SUPPORT is not set
  2264. +CONFIG_EXT4_FS=y
  2265. +CONFIG_EXT4_FS_POSIX_ACL=y
  2266. +CONFIG_EXT4_FS_SECURITY=y
  2267. +CONFIG_AUTOFS4_FS=y
  2268. +CONFIG_FSCACHE=y
  2269. +CONFIG_CACHEFILES=y
  2270. +CONFIG_MSDOS_FS=y
  2271. +CONFIG_VFAT_FS=y
  2272. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  2273. +CONFIG_TMPFS=y
  2274. +CONFIG_TMPFS_POSIX_ACL=y
  2275. +CONFIG_CONFIGFS_FS=y
  2276. +# CONFIG_MISC_FILESYSTEMS is not set
  2277. +CONFIG_NFS_FS=y
  2278. +CONFIG_NFS_V3_ACL=y
  2279. +CONFIG_NFS_V4=y
  2280. +CONFIG_ROOT_NFS=y
  2281. +CONFIG_NFS_FSCACHE=y
  2282. +CONFIG_NLS_DEFAULT="utf8"
  2283. +CONFIG_NLS_CODEPAGE_437=y
  2284. +CONFIG_NLS_CODEPAGE_737=y
  2285. +CONFIG_NLS_CODEPAGE_775=y
  2286. +CONFIG_NLS_CODEPAGE_850=y
  2287. +CONFIG_NLS_CODEPAGE_852=y
  2288. +CONFIG_NLS_CODEPAGE_855=y
  2289. +CONFIG_NLS_CODEPAGE_857=y
  2290. +CONFIG_NLS_CODEPAGE_860=y
  2291. +CONFIG_NLS_CODEPAGE_861=y
  2292. +CONFIG_NLS_CODEPAGE_862=y
  2293. +CONFIG_NLS_CODEPAGE_863=y
  2294. +CONFIG_NLS_CODEPAGE_864=y
  2295. +CONFIG_NLS_CODEPAGE_865=y
  2296. +CONFIG_NLS_CODEPAGE_866=y
  2297. +CONFIG_NLS_CODEPAGE_869=y
  2298. +CONFIG_NLS_CODEPAGE_936=y
  2299. +CONFIG_NLS_CODEPAGE_950=y
  2300. +CONFIG_NLS_CODEPAGE_932=y
  2301. +CONFIG_NLS_CODEPAGE_949=y
  2302. +CONFIG_NLS_CODEPAGE_874=y
  2303. +CONFIG_NLS_ISO8859_8=y
  2304. +CONFIG_NLS_CODEPAGE_1250=y
  2305. +CONFIG_NLS_CODEPAGE_1251=y
  2306. +CONFIG_NLS_ASCII=y
  2307. +CONFIG_NLS_ISO8859_1=y
  2308. +CONFIG_NLS_ISO8859_2=y
  2309. +CONFIG_NLS_ISO8859_3=y
  2310. +CONFIG_NLS_ISO8859_4=y
  2311. +CONFIG_NLS_ISO8859_5=y
  2312. +CONFIG_NLS_ISO8859_6=y
  2313. +CONFIG_NLS_ISO8859_7=y
  2314. +CONFIG_NLS_ISO8859_9=y
  2315. +CONFIG_NLS_ISO8859_13=y
  2316. +CONFIG_NLS_ISO8859_14=y
  2317. +CONFIG_NLS_ISO8859_15=y
  2318. +CONFIG_NLS_UTF8=y
  2319. +CONFIG_PRINTK_TIME=y
  2320. +CONFIG_DEBUG_FS=y
  2321. +CONFIG_DETECT_HUNG_TASK=y
  2322. +# CONFIG_DEBUG_PREEMPT is not set
  2323. +# CONFIG_DEBUG_BUGVERBOSE is not set
  2324. +# CONFIG_FTRACE is not set
  2325. +CONFIG_KGDB=y
  2326. +CONFIG_KGDB_KDB=y
  2327. +# CONFIG_ARM_UNWIND is not set
  2328. +CONFIG_CRYPTO_CBC=y
  2329. +CONFIG_CRYPTO_HMAC=y
  2330. +CONFIG_CRYPTO_MD5=y
  2331. +CONFIG_CRYPTO_SHA1=y
  2332. +CONFIG_CRYPTO_DES=y
  2333. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  2334. +# CONFIG_CRYPTO_HW is not set
  2335. +CONFIG_CRC_ITU_T=y
  2336. +CONFIG_LIBCRC32C=y
  2337. diff -Nur linux-3.13.3.orig/arch/arm/include/asm/fiq.h linux-3.13.3/arch/arm/include/asm/fiq.h
  2338. --- linux-3.13.3.orig/arch/arm/include/asm/fiq.h 2014-02-13 23:00:14.000000000 +0100
  2339. +++ linux-3.13.3/arch/arm/include/asm/fiq.h 2014-02-17 22:41:01.000000000 +0100
  2340. @@ -42,6 +42,7 @@
  2341. /* helpers defined in fiqasm.S: */
  2342. extern void __set_fiq_regs(unsigned long const *regs);
  2343. extern void __get_fiq_regs(unsigned long *regs);
  2344. +extern void __FIQ_Branch(unsigned long *regs);
  2345. static inline void set_fiq_regs(struct pt_regs const *regs)
  2346. {
  2347. diff -Nur linux-3.13.3.orig/arch/arm/Kconfig linux-3.13.3/arch/arm/Kconfig
  2348. --- linux-3.13.3.orig/arch/arm/Kconfig 2014-02-13 23:00:14.000000000 +0100
  2349. +++ linux-3.13.3/arch/arm/Kconfig 2014-02-17 22:41:01.000000000 +0100
  2350. @@ -373,6 +373,24 @@
  2351. This enables support for systems based on Atmel
  2352. AT91RM9200 and AT91SAM9* processors.
  2353. +config ARCH_BCM2708
  2354. + bool "Broadcom BCM2708 family"
  2355. + select CPU_V6
  2356. + select ARM_AMBA
  2357. + select HAVE_CLK
  2358. + select HAVE_SCHED_CLOCK
  2359. + select NEED_MACH_GPIO_H
  2360. + select NEED_MACH_MEMORY_H
  2361. + select CLKDEV_LOOKUP
  2362. + select ARCH_HAS_CPUFREQ
  2363. + select GENERIC_CLOCKEVENTS
  2364. + select ARM_ERRATA_411920
  2365. + select MACH_BCM2708
  2366. + select VC4
  2367. + select FIQ
  2368. + help
  2369. + This enables support for Broadcom BCM2708 boards.
  2370. +
  2371. config ARCH_CLPS711X
  2372. bool "Cirrus Logic CLPS711x/EP721x/EP731x-based"
  2373. select ARCH_REQUIRE_GPIOLIB
  2374. @@ -1020,6 +1038,7 @@
  2375. source "arch/arm/mach-vt8500/Kconfig"
  2376. source "arch/arm/mach-w90x900/Kconfig"
  2377. +source "arch/arm/mach-bcm2708/Kconfig"
  2378. source "arch/arm/mach-zynq/Kconfig"
  2379. diff -Nur linux-3.13.3.orig/arch/arm/Kconfig.debug linux-3.13.3/arch/arm/Kconfig.debug
  2380. --- linux-3.13.3.orig/arch/arm/Kconfig.debug 2014-02-13 23:00:14.000000000 +0100
  2381. +++ linux-3.13.3/arch/arm/Kconfig.debug 2014-02-17 22:41:01.000000000 +0100
  2382. @@ -882,6 +882,14 @@
  2383. options; the platform specific options are deprecated
  2384. and will be soon removed.
  2385. + config DEBUG_BCM2708_UART0
  2386. + bool "Broadcom BCM2708 UART0 (PL011)"
  2387. + depends on MACH_BCM2708
  2388. + help
  2389. + Say Y here if you want the debug print routines to direct
  2390. + their output to UART 0. The port must have been initialised
  2391. + by the boot-loader before use.
  2392. +
  2393. endchoice
  2394. config DEBUG_EXYNOS_UART
  2395. diff -Nur linux-3.13.3.orig/arch/arm/kernel/fiqasm.S linux-3.13.3/arch/arm/kernel/fiqasm.S
  2396. --- linux-3.13.3.orig/arch/arm/kernel/fiqasm.S 2014-02-13 23:00:14.000000000 +0100
  2397. +++ linux-3.13.3/arch/arm/kernel/fiqasm.S 2014-02-17 22:41:01.000000000 +0100
  2398. @@ -25,6 +25,9 @@
  2399. ENTRY(__set_fiq_regs)
  2400. mov r2, #PSR_I_BIT | PSR_F_BIT | FIQ_MODE
  2401. mrs r1, cpsr
  2402. +@@@@@@@@@@@@@@@ hack: enable the fiq here to keep usb driver happy
  2403. + and r1, #~PSR_F_BIT
  2404. +@@@@@@@@@@@@@@@ endhack: (need to find better place for this to happen)
  2405. msr cpsr_c, r2 @ select FIQ mode
  2406. mov r0, r0 @ avoid hazard prior to ARMv4
  2407. ldmia r0!, {r8 - r12}
  2408. @@ -47,3 +50,7 @@
  2409. mov r0, r0 @ avoid hazard prior to ARMv4
  2410. mov pc, lr
  2411. ENDPROC(__get_fiq_regs)
  2412. +
  2413. +ENTRY(__FIQ_Branch)
  2414. + mov pc, r8
  2415. +ENDPROC(__FIQ_Branch)
  2416. diff -Nur linux-3.13.3.orig/arch/arm/kernel/fiq.c linux-3.13.3/arch/arm/kernel/fiq.c
  2417. --- linux-3.13.3.orig/arch/arm/kernel/fiq.c 2014-02-13 23:00:14.000000000 +0100
  2418. +++ linux-3.13.3/arch/arm/kernel/fiq.c 2014-02-17 22:41:01.000000000 +0100
  2419. @@ -142,6 +142,7 @@
  2420. EXPORT_SYMBOL(set_fiq_handler);
  2421. EXPORT_SYMBOL(__set_fiq_regs); /* defined in fiqasm.S */
  2422. EXPORT_SYMBOL(__get_fiq_regs); /* defined in fiqasm.S */
  2423. +EXPORT_SYMBOL(__FIQ_Branch); /* defined in fiqasm.S */
  2424. EXPORT_SYMBOL(claim_fiq);
  2425. EXPORT_SYMBOL(release_fiq);
  2426. EXPORT_SYMBOL(enable_fiq);
  2427. diff -Nur linux-3.13.3.orig/arch/arm/kernel/process.c linux-3.13.3/arch/arm/kernel/process.c
  2428. --- linux-3.13.3.orig/arch/arm/kernel/process.c 2014-02-13 23:00:14.000000000 +0100
  2429. +++ linux-3.13.3/arch/arm/kernel/process.c 2014-02-17 22:41:01.000000000 +0100
  2430. @@ -176,6 +176,16 @@
  2431. default_idle();
  2432. }
  2433. +char bcm2708_reboot_mode = 'h';
  2434. +
  2435. +int __init reboot_setup(char *str)
  2436. +{
  2437. + bcm2708_reboot_mode = str[0];
  2438. + return 1;
  2439. +}
  2440. +
  2441. +__setup("reboot=", reboot_setup);
  2442. +
  2443. /*
  2444. * Called by kexec, immediately prior to machine_kexec().
  2445. *
  2446. diff -Nur linux-3.13.3.orig/arch/arm/mach-bcm2708/armctrl.c linux-3.13.3/arch/arm/mach-bcm2708/armctrl.c
  2447. --- linux-3.13.3.orig/arch/arm/mach-bcm2708/armctrl.c 1970-01-01 01:00:00.000000000 +0100
  2448. +++ linux-3.13.3/arch/arm/mach-bcm2708/armctrl.c 2014-02-17 22:41:01.000000000 +0100
  2449. @@ -0,0 +1,219 @@
  2450. +/*
  2451. + * linux/arch/arm/mach-bcm2708/armctrl.c
  2452. + *
  2453. + * Copyright (C) 2010 Broadcom
  2454. + *
  2455. + * This program is free software; you can redistribute it and/or modify
  2456. + * it under the terms of the GNU General Public License as published by
  2457. + * the Free Software Foundation; either version 2 of the License, or
  2458. + * (at your option) any later version.
  2459. + *
  2460. + * This program is distributed in the hope that it will be useful,
  2461. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2462. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2463. + * GNU General Public License for more details.
  2464. + *
  2465. + * You should have received a copy of the GNU General Public License
  2466. + * along with this program; if not, write to the Free Software
  2467. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  2468. + */
  2469. +#include <linux/init.h>
  2470. +#include <linux/list.h>
  2471. +#include <linux/io.h>
  2472. +#include <linux/version.h>
  2473. +#include <linux/syscore_ops.h>
  2474. +#include <linux/interrupt.h>
  2475. +
  2476. +#include <asm/mach/irq.h>
  2477. +#include <mach/hardware.h>
  2478. +#include "armctrl.h"
  2479. +
  2480. +/* For support of kernels >= 3.0 assume only one VIC for now*/
  2481. +static unsigned int remap_irqs[(INTERRUPT_ARASANSDIO + 1) - INTERRUPT_JPEG] = {
  2482. + INTERRUPT_VC_JPEG,
  2483. + INTERRUPT_VC_USB,
  2484. + INTERRUPT_VC_3D,
  2485. + INTERRUPT_VC_DMA2,
  2486. + INTERRUPT_VC_DMA3,
  2487. + INTERRUPT_VC_I2C,
  2488. + INTERRUPT_VC_SPI,
  2489. + INTERRUPT_VC_I2SPCM,
  2490. + INTERRUPT_VC_SDIO,
  2491. + INTERRUPT_VC_UART,
  2492. + INTERRUPT_VC_ARASANSDIO
  2493. +};
  2494. +
  2495. +static void armctrl_mask_irq(struct irq_data *d)
  2496. +{
  2497. + static const unsigned int disables[4] = {
  2498. + ARM_IRQ_DIBL1,
  2499. + ARM_IRQ_DIBL2,
  2500. + ARM_IRQ_DIBL3,
  2501. + 0
  2502. + };
  2503. +
  2504. + if (d->irq >= FIQ_START) {
  2505. + writel(0, __io_address(ARM_IRQ_FAST));
  2506. + } else {
  2507. + unsigned int data = (unsigned int)irq_get_chip_data(d->irq);
  2508. + writel(1 << (data & 0x1f), __io_address(disables[(data >> 5) & 0x3]));
  2509. + }
  2510. +}
  2511. +
  2512. +static void armctrl_unmask_irq(struct irq_data *d)
  2513. +{
  2514. + static const unsigned int enables[4] = {
  2515. + ARM_IRQ_ENBL1,
  2516. + ARM_IRQ_ENBL2,
  2517. + ARM_IRQ_ENBL3,
  2518. + 0
  2519. + };
  2520. +
  2521. + if (d->irq >= FIQ_START) {
  2522. + unsigned int data =
  2523. + (unsigned int)irq_get_chip_data(d->irq) - FIQ_START;
  2524. + writel(0x80 | data, __io_address(ARM_IRQ_FAST));
  2525. + } else {
  2526. + unsigned int data = (unsigned int)irq_get_chip_data(d->irq);
  2527. + writel(1 << (data & 0x1f), __io_address(enables[(data >> 5) & 0x3]));
  2528. + }
  2529. +}
  2530. +
  2531. +#if defined(CONFIG_PM)
  2532. +
  2533. +/* for kernels 3.xx use the new syscore_ops apis but for older kernels use the sys dev class */
  2534. +
  2535. +/* Static defines
  2536. + * struct armctrl_device - VIC PM device (< 3.xx)
  2537. + * @sysdev: The system device which is registered. (< 3.xx)
  2538. + * @irq: The IRQ number for the base of the VIC.
  2539. + * @base: The register base for the VIC.
  2540. + * @resume_sources: A bitmask of interrupts for resume.
  2541. + * @resume_irqs: The IRQs enabled for resume.
  2542. + * @int_select: Save for VIC_INT_SELECT.
  2543. + * @int_enable: Save for VIC_INT_ENABLE.
  2544. + * @soft_int: Save for VIC_INT_SOFT.
  2545. + * @protect: Save for VIC_PROTECT.
  2546. + */
  2547. +struct armctrl_info {
  2548. + void __iomem *base;
  2549. + int irq;
  2550. + u32 resume_sources;
  2551. + u32 resume_irqs;
  2552. + u32 int_select;
  2553. + u32 int_enable;
  2554. + u32 soft_int;
  2555. + u32 protect;
  2556. +} armctrl;
  2557. +
  2558. +static int armctrl_suspend(void)
  2559. +{
  2560. + return 0;
  2561. +}
  2562. +
  2563. +static void armctrl_resume(void)
  2564. +{
  2565. + return;
  2566. +}
  2567. +
  2568. +/**
  2569. + * armctrl_pm_register - Register a VIC for later power management control
  2570. + * @base: The base address of the VIC.
  2571. + * @irq: The base IRQ for the VIC.
  2572. + * @resume_sources: bitmask of interrupts allowed for resume sources.
  2573. + *
  2574. + * For older kernels (< 3.xx) do -
  2575. + * Register the VIC with the system device tree so that it can be notified
  2576. + * of suspend and resume requests and ensure that the correct actions are
  2577. + * taken to re-instate the settings on resume.
  2578. + */
  2579. +static void __init armctrl_pm_register(void __iomem * base, unsigned int irq,
  2580. + u32 resume_sources)
  2581. +{
  2582. + armctrl.base = base;
  2583. + armctrl.resume_sources = resume_sources;
  2584. + armctrl.irq = irq;
  2585. +}
  2586. +
  2587. +static int armctrl_set_wake(struct irq_data *d, unsigned int on)
  2588. +{
  2589. + unsigned int off = d->irq & 31;
  2590. + u32 bit = 1 << off;
  2591. +
  2592. + if (!(bit & armctrl.resume_sources))
  2593. + return -EINVAL;
  2594. +
  2595. + if (on)
  2596. + armctrl.resume_irqs |= bit;
  2597. + else
  2598. + armctrl.resume_irqs &= ~bit;
  2599. +
  2600. + return 0;
  2601. +}
  2602. +
  2603. +#else
  2604. +static inline void armctrl_pm_register(void __iomem * base, unsigned int irq,
  2605. + u32 arg1)
  2606. +{
  2607. +}
  2608. +
  2609. +#define armctrl_suspend NULL
  2610. +#define armctrl_resume NULL
  2611. +#define armctrl_set_wake NULL
  2612. +#endif /* CONFIG_PM */
  2613. +
  2614. +static struct syscore_ops armctrl_syscore_ops = {
  2615. + .suspend = armctrl_suspend,
  2616. + .resume = armctrl_resume,
  2617. +};
  2618. +
  2619. +/**
  2620. + * armctrl_syscore_init - initicall to register VIC pm functions
  2621. + *
  2622. + * This is called via late_initcall() to register
  2623. + * the resources for the VICs due to the early
  2624. + * nature of the VIC's registration.
  2625. +*/
  2626. +static int __init armctrl_syscore_init(void)
  2627. +{
  2628. + register_syscore_ops(&armctrl_syscore_ops);
  2629. + return 0;
  2630. +}
  2631. +
  2632. +late_initcall(armctrl_syscore_init);
  2633. +
  2634. +static struct irq_chip armctrl_chip = {
  2635. + .name = "ARMCTRL",
  2636. + .irq_ack = armctrl_mask_irq,
  2637. + .irq_mask = armctrl_mask_irq,
  2638. + .irq_unmask = armctrl_unmask_irq,
  2639. + .irq_set_wake = armctrl_set_wake,
  2640. +};
  2641. +
  2642. +/**
  2643. + * armctrl_init - initialise a vectored interrupt controller
  2644. + * @base: iomem base address
  2645. + * @irq_start: starting interrupt number, must be muliple of 32
  2646. + * @armctrl_sources: bitmask of interrupt sources to allow
  2647. + * @resume_sources: bitmask of interrupt sources to allow for resume
  2648. + */
  2649. +int __init armctrl_init(void __iomem * base, unsigned int irq_start,
  2650. + u32 armctrl_sources, u32 resume_sources)
  2651. +{
  2652. + unsigned int irq;
  2653. +
  2654. + for (irq = 0; irq < NR_IRQS; irq++) {
  2655. + unsigned int data = irq;
  2656. + if (irq >= INTERRUPT_JPEG && irq <= INTERRUPT_ARASANSDIO)
  2657. + data = remap_irqs[irq - INTERRUPT_JPEG];
  2658. +
  2659. + irq_set_chip(irq, &armctrl_chip);
  2660. + irq_set_chip_data(irq, (void *)data);
  2661. + irq_set_handler(irq, handle_level_irq);
  2662. + set_irq_flags(irq, IRQF_VALID | IRQF_PROBE | IRQF_DISABLED);
  2663. + }
  2664. +
  2665. + armctrl_pm_register(base, irq_start, resume_sources);
  2666. + init_FIQ(FIQ_START);
  2667. + return 0;
  2668. +}
  2669. diff -Nur linux-3.13.3.orig/arch/arm/mach-bcm2708/armctrl.h linux-3.13.3/arch/arm/mach-bcm2708/armctrl.h
  2670. --- linux-3.13.3.orig/arch/arm/mach-bcm2708/armctrl.h 1970-01-01 01:00:00.000000000 +0100
  2671. +++ linux-3.13.3/arch/arm/mach-bcm2708/armctrl.h 2014-02-17 22:41:01.000000000 +0100
  2672. @@ -0,0 +1,27 @@
  2673. +/*
  2674. + * linux/arch/arm/mach-bcm2708/armctrl.h
  2675. + *
  2676. + * Copyright (C) 2010 Broadcom
  2677. + *
  2678. + * This program is free software; you can redistribute it and/or modify
  2679. + * it under the terms of the GNU General Public License as published by
  2680. + * the Free Software Foundation; either version 2 of the License, or
  2681. + * (at your option) any later version.
  2682. + *
  2683. + * This program is distributed in the hope that it will be useful,
  2684. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2685. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2686. + * GNU General Public License for more details.
  2687. + *
  2688. + * You should have received a copy of the GNU General Public License
  2689. + * along with this program; if not, write to the Free Software
  2690. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  2691. + */
  2692. +
  2693. +#ifndef __BCM2708_ARMCTRL_H
  2694. +#define __BCM2708_ARMCTRL_H
  2695. +
  2696. +extern int __init armctrl_init(void __iomem * base, unsigned int irq_start,
  2697. + u32 armctrl_sources, u32 resume_sources);
  2698. +
  2699. +#endif
  2700. diff -Nur linux-3.13.3.orig/arch/arm/mach-bcm2708/bcm2708.c linux-3.13.3/arch/arm/mach-bcm2708/bcm2708.c
  2701. --- linux-3.13.3.orig/arch/arm/mach-bcm2708/bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  2702. +++ linux-3.13.3/arch/arm/mach-bcm2708/bcm2708.c 2014-02-17 22:41:01.000000000 +0100
  2703. @@ -0,0 +1,1129 @@
  2704. +/*
  2705. + * linux/arch/arm/mach-bcm2708/bcm2708.c
  2706. + *
  2707. + * Copyright (C) 2010 Broadcom
  2708. + *
  2709. + * This program is free software; you can redistribute it and/or modify
  2710. + * it under the terms of the GNU General Public License as published by
  2711. + * the Free Software Foundation; either version 2 of the License, or
  2712. + * (at your option) any later version.
  2713. + *
  2714. + * This program is distributed in the hope that it will be useful,
  2715. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2716. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2717. + * GNU General Public License for more details.
  2718. + *
  2719. + * You should have received a copy of the GNU General Public License
  2720. + * along with this program; if not, write to the Free Software
  2721. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  2722. + */
  2723. +
  2724. +#include <linux/init.h>
  2725. +#include <linux/device.h>
  2726. +#include <linux/dma-mapping.h>
  2727. +#include <linux/serial_8250.h>
  2728. +#include <linux/platform_device.h>
  2729. +#include <linux/syscore_ops.h>
  2730. +#include <linux/interrupt.h>
  2731. +#include <linux/amba/bus.h>
  2732. +#include <linux/amba/clcd.h>
  2733. +#include <linux/clockchips.h>
  2734. +#include <linux/cnt32_to_63.h>
  2735. +#include <linux/io.h>
  2736. +#include <linux/module.h>
  2737. +#include <linux/spi/spi.h>
  2738. +#include <linux/w1-gpio.h>
  2739. +
  2740. +#include <linux/version.h>
  2741. +#include <linux/clkdev.h>
  2742. +#include <asm/system.h>
  2743. +#include <mach/hardware.h>
  2744. +#include <asm/irq.h>
  2745. +#include <linux/leds.h>
  2746. +#include <asm/mach-types.h>
  2747. +#include <linux/sched_clock.h>
  2748. +
  2749. +#include <asm/mach/arch.h>
  2750. +#include <asm/mach/flash.h>
  2751. +#include <asm/mach/irq.h>
  2752. +#include <asm/mach/time.h>
  2753. +#include <asm/mach/map.h>
  2754. +
  2755. +#include <mach/timex.h>
  2756. +#include <mach/dma.h>
  2757. +#include <mach/vcio.h>
  2758. +#include <mach/system.h>
  2759. +
  2760. +#include <linux/delay.h>
  2761. +
  2762. +#include "bcm2708.h"
  2763. +#include "armctrl.h"
  2764. +#include "clock.h"
  2765. +
  2766. +#ifdef CONFIG_BCM_VC_CMA
  2767. +#include <linux/broadcom/vc_cma.h>
  2768. +#endif
  2769. +
  2770. +
  2771. +/* Effectively we have an IOMMU (ARM<->VideoCore map) that is set up to
  2772. + * give us IO access only to 64Mbytes of physical memory (26 bits). We could
  2773. + * represent this window by setting our dmamasks to 26 bits but, in fact
  2774. + * we're not going to use addresses outside this range (they're not in real
  2775. + * memory) so we don't bother.
  2776. + *
  2777. + * In the future we might include code to use this IOMMU to remap other
  2778. + * physical addresses onto VideoCore memory then the use of 32-bits would be
  2779. + * more legitimate.
  2780. + */
  2781. +#define DMA_MASK_BITS_COMMON 32
  2782. +
  2783. +// use GPIO 4 for the one-wire GPIO pin, if enabled
  2784. +#define W1_GPIO 4
  2785. +
  2786. +/* command line parameters */
  2787. +static unsigned boardrev, serial;
  2788. +static unsigned uart_clock;
  2789. +static unsigned disk_led_gpio = 16;
  2790. +static unsigned disk_led_active_low = 1;
  2791. +static unsigned reboot_part = 0;
  2792. +
  2793. +static void __init bcm2708_init_led(void);
  2794. +
  2795. +void __init bcm2708_init_irq(void)
  2796. +{
  2797. + armctrl_init(__io_address(ARMCTRL_IC_BASE), 0, 0, 0);
  2798. +}
  2799. +
  2800. +static struct map_desc bcm2708_io_desc[] __initdata = {
  2801. + {
  2802. + .virtual = IO_ADDRESS(ARMCTRL_BASE),
  2803. + .pfn = __phys_to_pfn(ARMCTRL_BASE),
  2804. + .length = SZ_4K,
  2805. + .type = MT_DEVICE},
  2806. + {
  2807. + .virtual = IO_ADDRESS(UART0_BASE),
  2808. + .pfn = __phys_to_pfn(UART0_BASE),
  2809. + .length = SZ_4K,
  2810. + .type = MT_DEVICE},
  2811. + {
  2812. + .virtual = IO_ADDRESS(UART1_BASE),
  2813. + .pfn = __phys_to_pfn(UART1_BASE),
  2814. + .length = SZ_4K,
  2815. + .type = MT_DEVICE},
  2816. + {
  2817. + .virtual = IO_ADDRESS(DMA_BASE),
  2818. + .pfn = __phys_to_pfn(DMA_BASE),
  2819. + .length = SZ_4K,
  2820. + .type = MT_DEVICE},
  2821. + {
  2822. + .virtual = IO_ADDRESS(MCORE_BASE),
  2823. + .pfn = __phys_to_pfn(MCORE_BASE),
  2824. + .length = SZ_4K,
  2825. + .type = MT_DEVICE},
  2826. + {
  2827. + .virtual = IO_ADDRESS(ST_BASE),
  2828. + .pfn = __phys_to_pfn(ST_BASE),
  2829. + .length = SZ_4K,
  2830. + .type = MT_DEVICE},
  2831. + {
  2832. + .virtual = IO_ADDRESS(USB_BASE),
  2833. + .pfn = __phys_to_pfn(USB_BASE),
  2834. + .length = SZ_128K,
  2835. + .type = MT_DEVICE},
  2836. + {
  2837. + .virtual = IO_ADDRESS(PM_BASE),
  2838. + .pfn = __phys_to_pfn(PM_BASE),
  2839. + .length = SZ_4K,
  2840. + .type = MT_DEVICE},
  2841. + {
  2842. + .virtual = IO_ADDRESS(GPIO_BASE),
  2843. + .pfn = __phys_to_pfn(GPIO_BASE),
  2844. + .length = SZ_4K,
  2845. + .type = MT_DEVICE}
  2846. +};
  2847. +
  2848. +void __init bcm2708_map_io(void)
  2849. +{
  2850. + iotable_init(bcm2708_io_desc, ARRAY_SIZE(bcm2708_io_desc));
  2851. +}
  2852. +
  2853. +/* The STC is a free running counter that increments at the rate of 1MHz */
  2854. +#define STC_FREQ_HZ 1000000
  2855. +
  2856. +static inline uint32_t timer_read(void)
  2857. +{
  2858. + /* STC: a free running counter that increments at the rate of 1MHz */
  2859. + return readl(__io_address(ST_BASE + 0x04));
  2860. +}
  2861. +
  2862. +static unsigned long bcm2708_read_current_timer(void)
  2863. +{
  2864. + return timer_read();
  2865. +}
  2866. +
  2867. +static u32 notrace bcm2708_read_sched_clock(void)
  2868. +{
  2869. + return timer_read();
  2870. +}
  2871. +
  2872. +static cycle_t clksrc_read(struct clocksource *cs)
  2873. +{
  2874. + return timer_read();
  2875. +}
  2876. +
  2877. +static struct clocksource clocksource_stc = {
  2878. + .name = "stc",
  2879. + .rating = 300,
  2880. + .read = clksrc_read,
  2881. + .mask = CLOCKSOURCE_MASK(32),
  2882. + .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  2883. +};
  2884. +
  2885. +unsigned long frc_clock_ticks32(void)
  2886. +{
  2887. + return timer_read();
  2888. +}
  2889. +
  2890. +static void __init bcm2708_clocksource_init(void)
  2891. +{
  2892. + if (clocksource_register_hz(&clocksource_stc, STC_FREQ_HZ)) {
  2893. + printk(KERN_ERR "timer: failed to initialize clock "
  2894. + "source %s\n", clocksource_stc.name);
  2895. + }
  2896. +}
  2897. +
  2898. +
  2899. +/*
  2900. + * These are fixed clocks.
  2901. + */
  2902. +static struct clk ref24_clk = {
  2903. + .rate = UART0_CLOCK, /* The UART is clocked at 3MHz via APB_CLK */
  2904. +};
  2905. +
  2906. +static struct clk osc_clk = {
  2907. +#ifdef CONFIG_ARCH_BCM2708_CHIPIT
  2908. + .rate = 27000000,
  2909. +#else
  2910. + .rate = 500000000, /* ARM clock is set from the VideoCore booter */
  2911. +#endif
  2912. +};
  2913. +
  2914. +/* warning - the USB needs a clock > 34MHz */
  2915. +
  2916. +static struct clk sdhost_clk = {
  2917. +#ifdef CONFIG_ARCH_BCM2708_CHIPIT
  2918. + .rate = 4000000, /* 4MHz */
  2919. +#else
  2920. + .rate = 250000000, /* 250MHz */
  2921. +#endif
  2922. +};
  2923. +
  2924. +static struct clk_lookup lookups[] = {
  2925. + { /* UART0 */
  2926. + .dev_id = "dev:f1",
  2927. + .clk = &ref24_clk,
  2928. + },
  2929. + { /* USB */
  2930. + .dev_id = "bcm2708_usb",
  2931. + .clk = &osc_clk,
  2932. + }, { /* SPI */
  2933. + .dev_id = "bcm2708_spi.0",
  2934. + .clk = &sdhost_clk,
  2935. + }, { /* BSC0 */
  2936. + .dev_id = "bcm2708_i2c.0",
  2937. + .clk = &sdhost_clk,
  2938. + }, { /* BSC1 */
  2939. + .dev_id = "bcm2708_i2c.1",
  2940. + .clk = &sdhost_clk,
  2941. + }
  2942. +};
  2943. +
  2944. +#define UART0_IRQ { IRQ_UART, 0 /*NO_IRQ*/ }
  2945. +#define UART0_DMA { 15, 14 }
  2946. +
  2947. +AMBA_DEVICE(uart0, "dev:f1", UART0, NULL);
  2948. +
  2949. +static struct amba_device *amba_devs[] __initdata = {
  2950. + &uart0_device,
  2951. +};
  2952. +
  2953. +static struct resource bcm2708_dmaman_resources[] = {
  2954. + {
  2955. + .start = DMA_BASE,
  2956. + .end = DMA_BASE + SZ_4K - 1,
  2957. + .flags = IORESOURCE_MEM,
  2958. + }
  2959. +};
  2960. +
  2961. +static struct platform_device bcm2708_dmaman_device = {
  2962. + .name = BCM_DMAMAN_DRIVER_NAME,
  2963. + .id = 0, /* first bcm2708_dma */
  2964. + .resource = bcm2708_dmaman_resources,
  2965. + .num_resources = ARRAY_SIZE(bcm2708_dmaman_resources),
  2966. +};
  2967. +
  2968. +#if defined(CONFIG_W1_MASTER_GPIO) || defined(CONFIG_W1_MASTER_GPIO_MODULE)
  2969. +static struct w1_gpio_platform_data w1_gpio_pdata = {
  2970. + .pin = W1_GPIO,
  2971. + .is_open_drain = 0,
  2972. +};
  2973. +
  2974. +static struct platform_device w1_device = {
  2975. + .name = "w1-gpio",
  2976. + .id = -1,
  2977. + .dev.platform_data = &w1_gpio_pdata,
  2978. +};
  2979. +#endif
  2980. +
  2981. +static u64 fb_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  2982. +
  2983. +static struct platform_device bcm2708_fb_device = {
  2984. + .name = "bcm2708_fb",
  2985. + .id = -1, /* only one bcm2708_fb */
  2986. + .resource = NULL,
  2987. + .num_resources = 0,
  2988. + .dev = {
  2989. + .dma_mask = &fb_dmamask,
  2990. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  2991. + },
  2992. +};
  2993. +
  2994. +static struct plat_serial8250_port bcm2708_uart1_platform_data[] = {
  2995. + {
  2996. + .mapbase = UART1_BASE + 0x40,
  2997. + .irq = IRQ_AUX,
  2998. + .uartclk = 125000000,
  2999. + .regshift = 2,
  3000. + .iotype = UPIO_MEM,
  3001. + .flags = UPF_FIXED_TYPE | UPF_IOREMAP | UPF_SKIP_TEST,
  3002. + .type = PORT_8250,
  3003. + },
  3004. + {},
  3005. +};
  3006. +
  3007. +static struct platform_device bcm2708_uart1_device = {
  3008. + .name = "serial8250",
  3009. + .id = PLAT8250_DEV_PLATFORM,
  3010. + .dev = {
  3011. + .platform_data = bcm2708_uart1_platform_data,
  3012. + },
  3013. +};
  3014. +
  3015. +static struct resource bcm2708_usb_resources[] = {
  3016. + [0] = {
  3017. + .start = USB_BASE,
  3018. + .end = USB_BASE + SZ_128K - 1,
  3019. + .flags = IORESOURCE_MEM,
  3020. + },
  3021. + [1] = {
  3022. + .start = MPHI_BASE,
  3023. + .end = MPHI_BASE + SZ_4K - 1,
  3024. + .flags = IORESOURCE_MEM,
  3025. + },
  3026. + [2] = {
  3027. + .start = IRQ_HOSTPORT,
  3028. + .end = IRQ_HOSTPORT,
  3029. + .flags = IORESOURCE_IRQ,
  3030. + },
  3031. +};
  3032. +
  3033. +bool fiq_fix_enable = true;
  3034. +
  3035. +static struct resource bcm2708_usb_resources_no_fiq_fix[] = {
  3036. + [0] = {
  3037. + .start = USB_BASE,
  3038. + .end = USB_BASE + SZ_128K - 1,
  3039. + .flags = IORESOURCE_MEM,
  3040. + },
  3041. + [1] = {
  3042. + .start = IRQ_USB,
  3043. + .end = IRQ_USB,
  3044. + .flags = IORESOURCE_IRQ,
  3045. + },
  3046. +};
  3047. +
  3048. +static u64 usb_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3049. +
  3050. +static struct platform_device bcm2708_usb_device = {
  3051. + .name = "bcm2708_usb",
  3052. + .id = -1, /* only one bcm2708_usb */
  3053. + .resource = bcm2708_usb_resources,
  3054. + .num_resources = ARRAY_SIZE(bcm2708_usb_resources),
  3055. + .dev = {
  3056. + .dma_mask = &usb_dmamask,
  3057. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  3058. + },
  3059. +};
  3060. +
  3061. +static struct resource bcm2708_vcio_resources[] = {
  3062. + [0] = { /* mailbox/semaphore/doorbell access */
  3063. + .start = MCORE_BASE,
  3064. + .end = MCORE_BASE + SZ_4K - 1,
  3065. + .flags = IORESOURCE_MEM,
  3066. + },
  3067. +};
  3068. +
  3069. +static u64 vcio_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3070. +
  3071. +static struct platform_device bcm2708_vcio_device = {
  3072. + .name = BCM_VCIO_DRIVER_NAME,
  3073. + .id = -1, /* only one VideoCore I/O area */
  3074. + .resource = bcm2708_vcio_resources,
  3075. + .num_resources = ARRAY_SIZE(bcm2708_vcio_resources),
  3076. + .dev = {
  3077. + .dma_mask = &vcio_dmamask,
  3078. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  3079. + },
  3080. +};
  3081. +
  3082. +#ifdef CONFIG_BCM2708_GPIO
  3083. +#define BCM_GPIO_DRIVER_NAME "bcm2708_gpio"
  3084. +
  3085. +static struct resource bcm2708_gpio_resources[] = {
  3086. + [0] = { /* general purpose I/O */
  3087. + .start = GPIO_BASE,
  3088. + .end = GPIO_BASE + SZ_4K - 1,
  3089. + .flags = IORESOURCE_MEM,
  3090. + },
  3091. +};
  3092. +
  3093. +static u64 gpio_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3094. +
  3095. +static struct platform_device bcm2708_gpio_device = {
  3096. + .name = BCM_GPIO_DRIVER_NAME,
  3097. + .id = -1, /* only one VideoCore I/O area */
  3098. + .resource = bcm2708_gpio_resources,
  3099. + .num_resources = ARRAY_SIZE(bcm2708_gpio_resources),
  3100. + .dev = {
  3101. + .dma_mask = &gpio_dmamask,
  3102. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  3103. + },
  3104. +};
  3105. +#endif
  3106. +
  3107. +static struct resource bcm2708_systemtimer_resources[] = {
  3108. + [0] = { /* system timer access */
  3109. + .start = ST_BASE,
  3110. + .end = ST_BASE + SZ_4K - 1,
  3111. + .flags = IORESOURCE_MEM,
  3112. + },
  3113. + {
  3114. + .start = IRQ_TIMER3,
  3115. + .end = IRQ_TIMER3,
  3116. + .flags = IORESOURCE_IRQ,
  3117. + }
  3118. +
  3119. +};
  3120. +
  3121. +static u64 systemtimer_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3122. +
  3123. +static struct platform_device bcm2708_systemtimer_device = {
  3124. + .name = "bcm2708_systemtimer",
  3125. + .id = -1, /* only one VideoCore I/O area */
  3126. + .resource = bcm2708_systemtimer_resources,
  3127. + .num_resources = ARRAY_SIZE(bcm2708_systemtimer_resources),
  3128. + .dev = {
  3129. + .dma_mask = &systemtimer_dmamask,
  3130. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  3131. + },
  3132. +};
  3133. +
  3134. +#ifdef CONFIG_MMC_SDHCI_BCM2708 /* Arasan emmc SD */
  3135. +static struct resource bcm2708_emmc_resources[] = {
  3136. + [0] = {
  3137. + .start = EMMC_BASE,
  3138. + .end = EMMC_BASE + SZ_256 - 1, /* we only need this area */
  3139. + /* the memory map actually makes SZ_4K available */
  3140. + .flags = IORESOURCE_MEM,
  3141. + },
  3142. + [1] = {
  3143. + .start = IRQ_ARASANSDIO,
  3144. + .end = IRQ_ARASANSDIO,
  3145. + .flags = IORESOURCE_IRQ,
  3146. + },
  3147. +};
  3148. +
  3149. +static u64 bcm2708_emmc_dmamask = 0xffffffffUL;
  3150. +
  3151. +struct platform_device bcm2708_emmc_device = {
  3152. + .name = "bcm2708_sdhci",
  3153. + .id = 0,
  3154. + .num_resources = ARRAY_SIZE(bcm2708_emmc_resources),
  3155. + .resource = bcm2708_emmc_resources,
  3156. + .dev = {
  3157. + .dma_mask = &bcm2708_emmc_dmamask,
  3158. + .coherent_dma_mask = 0xffffffffUL},
  3159. +};
  3160. +#endif /* CONFIG_MMC_SDHCI_BCM2708 */
  3161. +
  3162. +static struct resource bcm2708_powerman_resources[] = {
  3163. + [0] = {
  3164. + .start = PM_BASE,
  3165. + .end = PM_BASE + SZ_256 - 1,
  3166. + .flags = IORESOURCE_MEM,
  3167. + },
  3168. +};
  3169. +
  3170. +static u64 powerman_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3171. +
  3172. +struct platform_device bcm2708_powerman_device = {
  3173. + .name = "bcm2708_powerman",
  3174. + .id = 0,
  3175. + .num_resources = ARRAY_SIZE(bcm2708_powerman_resources),
  3176. + .resource = bcm2708_powerman_resources,
  3177. + .dev = {
  3178. + .dma_mask = &powerman_dmamask,
  3179. + .coherent_dma_mask = 0xffffffffUL},
  3180. +};
  3181. +
  3182. +
  3183. +static struct platform_device bcm2708_alsa_devices[] = {
  3184. + [0] = {
  3185. + .name = "bcm2835_AUD0",
  3186. + .id = 0, /* first audio device */
  3187. + .resource = 0,
  3188. + .num_resources = 0,
  3189. + },
  3190. + [1] = {
  3191. + .name = "bcm2835_AUD1",
  3192. + .id = 1, /* second audio device */
  3193. + .resource = 0,
  3194. + .num_resources = 0,
  3195. + },
  3196. + [2] = {
  3197. + .name = "bcm2835_AUD2",
  3198. + .id = 2, /* third audio device */
  3199. + .resource = 0,
  3200. + .num_resources = 0,
  3201. + },
  3202. + [3] = {
  3203. + .name = "bcm2835_AUD3",
  3204. + .id = 3, /* forth audio device */
  3205. + .resource = 0,
  3206. + .num_resources = 0,
  3207. + },
  3208. + [4] = {
  3209. + .name = "bcm2835_AUD4",
  3210. + .id = 4, /* fifth audio device */
  3211. + .resource = 0,
  3212. + .num_resources = 0,
  3213. + },
  3214. + [5] = {
  3215. + .name = "bcm2835_AUD5",
  3216. + .id = 5, /* sixth audio device */
  3217. + .resource = 0,
  3218. + .num_resources = 0,
  3219. + },
  3220. + [6] = {
  3221. + .name = "bcm2835_AUD6",
  3222. + .id = 6, /* seventh audio device */
  3223. + .resource = 0,
  3224. + .num_resources = 0,
  3225. + },
  3226. + [7] = {
  3227. + .name = "bcm2835_AUD7",
  3228. + .id = 7, /* eighth audio device */
  3229. + .resource = 0,
  3230. + .num_resources = 0,
  3231. + },
  3232. +};
  3233. +
  3234. +static struct resource bcm2708_spi_resources[] = {
  3235. + {
  3236. + .start = SPI0_BASE,
  3237. + .end = SPI0_BASE + SZ_256 - 1,
  3238. + .flags = IORESOURCE_MEM,
  3239. + }, {
  3240. + .start = IRQ_SPI,
  3241. + .end = IRQ_SPI,
  3242. + .flags = IORESOURCE_IRQ,
  3243. + }
  3244. +};
  3245. +
  3246. +
  3247. +static u64 bcm2708_spi_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3248. +static struct platform_device bcm2708_spi_device = {
  3249. + .name = "bcm2708_spi",
  3250. + .id = 0,
  3251. + .num_resources = ARRAY_SIZE(bcm2708_spi_resources),
  3252. + .resource = bcm2708_spi_resources,
  3253. + .dev = {
  3254. + .dma_mask = &bcm2708_spi_dmamask,
  3255. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON)},
  3256. +};
  3257. +
  3258. +#ifdef CONFIG_BCM2708_SPIDEV
  3259. +static struct spi_board_info bcm2708_spi_devices[] = {
  3260. +#ifdef CONFIG_SPI_SPIDEV
  3261. + {
  3262. + .modalias = "spidev",
  3263. + .max_speed_hz = 500000,
  3264. + .bus_num = 0,
  3265. + .chip_select = 0,
  3266. + .mode = SPI_MODE_0,
  3267. + }, {
  3268. + .modalias = "spidev",
  3269. + .max_speed_hz = 500000,
  3270. + .bus_num = 0,
  3271. + .chip_select = 1,
  3272. + .mode = SPI_MODE_0,
  3273. + }
  3274. +#endif
  3275. +};
  3276. +#endif
  3277. +
  3278. +static struct resource bcm2708_bsc0_resources[] = {
  3279. + {
  3280. + .start = BSC0_BASE,
  3281. + .end = BSC0_BASE + SZ_256 - 1,
  3282. + .flags = IORESOURCE_MEM,
  3283. + }, {
  3284. + .start = INTERRUPT_I2C,
  3285. + .end = INTERRUPT_I2C,
  3286. + .flags = IORESOURCE_IRQ,
  3287. + }
  3288. +};
  3289. +
  3290. +static struct platform_device bcm2708_bsc0_device = {
  3291. + .name = "bcm2708_i2c",
  3292. + .id = 0,
  3293. + .num_resources = ARRAY_SIZE(bcm2708_bsc0_resources),
  3294. + .resource = bcm2708_bsc0_resources,
  3295. +};
  3296. +
  3297. +
  3298. +static struct resource bcm2708_bsc1_resources[] = {
  3299. + {
  3300. + .start = BSC1_BASE,
  3301. + .end = BSC1_BASE + SZ_256 - 1,
  3302. + .flags = IORESOURCE_MEM,
  3303. + }, {
  3304. + .start = INTERRUPT_I2C,
  3305. + .end = INTERRUPT_I2C,
  3306. + .flags = IORESOURCE_IRQ,
  3307. + }
  3308. +};
  3309. +
  3310. +static struct platform_device bcm2708_bsc1_device = {
  3311. + .name = "bcm2708_i2c",
  3312. + .id = 1,
  3313. + .num_resources = ARRAY_SIZE(bcm2708_bsc1_resources),
  3314. + .resource = bcm2708_bsc1_resources,
  3315. +};
  3316. +
  3317. +static struct platform_device bcm2835_hwmon_device = {
  3318. + .name = "bcm2835_hwmon",
  3319. +};
  3320. +
  3321. +static struct platform_device bcm2835_thermal_device = {
  3322. + .name = "bcm2835_thermal",
  3323. +};
  3324. +
  3325. +#ifdef CONFIG_SND_BCM2708_SOC_I2S_MODULE
  3326. +static struct resource bcm2708_i2s_resources[] = {
  3327. + {
  3328. + .start = I2S_BASE,
  3329. + .end = I2S_BASE + 0x20,
  3330. + .flags = IORESOURCE_MEM,
  3331. + },
  3332. + {
  3333. + .start = PCM_CLOCK_BASE,
  3334. + .end = PCM_CLOCK_BASE + 0x02,
  3335. + .flags = IORESOURCE_MEM,
  3336. + }
  3337. +};
  3338. +
  3339. +static struct platform_device bcm2708_i2s_device = {
  3340. + .name = "bcm2708-i2s",
  3341. + .id = 0,
  3342. + .num_resources = ARRAY_SIZE(bcm2708_i2s_resources),
  3343. + .resource = bcm2708_i2s_resources,
  3344. +};
  3345. +#endif
  3346. +
  3347. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC_MODULE)
  3348. +static struct platform_device snd_hifiberry_dac_device = {
  3349. + .name = "snd-hifiberry-dac",
  3350. + .id = 0,
  3351. + .num_resources = 0,
  3352. +};
  3353. +
  3354. +static struct platform_device snd_pcm5102a_codec_device = {
  3355. + .name = "pcm5102a-codec",
  3356. + .id = -1,
  3357. + .num_resources = 0,
  3358. +};
  3359. +#endif
  3360. +
  3361. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI_MODULE)
  3362. +static struct platform_device snd_hifiberry_digi_device = {
  3363. + .name = "snd-hifiberry-digi",
  3364. + .id = 0,
  3365. + .num_resources = 0,
  3366. +};
  3367. +
  3368. +static struct i2c_board_info __initdata snd_wm8804_i2c_devices[] = {
  3369. + {
  3370. + I2C_BOARD_INFO("wm8804", 0x3b)
  3371. + },
  3372. +};
  3373. +
  3374. +#endif
  3375. +
  3376. +#if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
  3377. +static struct platform_device snd_rpi_dac_device = {
  3378. + .name = "snd-rpi-dac",
  3379. + .id = 0,
  3380. + .num_resources = 0,
  3381. +};
  3382. +
  3383. +static struct platform_device snd_pcm1794a_codec_device = {
  3384. + .name = "pcm1794a-codec",
  3385. + .id = -1,
  3386. + .num_resources = 0,
  3387. +};
  3388. +#endif
  3389. +
  3390. +#ifdef CONFIG_SND_BCM2708_SOC_RPI_CODEC_MBED_MODULE
  3391. +static struct platform_device snd_rpi_mbed_device = {
  3392. + .name = "snd-rpi-mbed",
  3393. + .id = 0,
  3394. + .num_resources = 0,
  3395. +};
  3396. +
  3397. +
  3398. +static struct i2c_board_info __initdata snd_rpi_mbed_i2c_devices[] = {
  3399. + {
  3400. + I2C_BOARD_INFO("tlv320aic23", 0x1b)
  3401. + },
  3402. +};
  3403. +#endif
  3404. +
  3405. +
  3406. +#ifdef CONFIG_SND_BCM2708_SOC_RPI_CODEC_TDA1541A_MODULE
  3407. +static struct platform_device snd_rpi_tda1541a_device = {
  3408. + .name = "snd-rpi-tda1541a",
  3409. + .id = 0,
  3410. + .num_resources = 0,
  3411. +};
  3412. +
  3413. +static struct platform_device snd_rpi_tda1541a_codec_device = {
  3414. + .name = "tda1541a-codec",
  3415. + .id = -1,
  3416. + .num_resources = 0,
  3417. +};
  3418. +#endif
  3419. +
  3420. +#ifdef CONFIG_SND_BCM2708_SOC_RPI_CODEC_PROTO_MODULE
  3421. +static struct platform_device snd_rpi_proto_device = {
  3422. + .name = "snd-rpi-proto",
  3423. + .id = 0,
  3424. + .num_resources = 0,
  3425. +};
  3426. +
  3427. +static struct i2c_board_info __initdata snd_rpi_proto_i2c_devices[] = {
  3428. + {
  3429. + I2C_BOARD_INFO("wm8731", 0x1a)
  3430. + },
  3431. +};
  3432. +#endif
  3433. +
  3434. +#ifdef CONFIG_SND_BCM2708_SOC_RPI_CODEC_CS534X_MODULE
  3435. +static struct platform_device snd_rpi_cs534x_device = {
  3436. + .name = "snd-rpi-cs534x",
  3437. + .id = 0,
  3438. + .num_resources = 0,
  3439. +};
  3440. +
  3441. +static struct platform_device snd_rpi_cs534x_codec_device = {
  3442. + .name = "cs534x-codec",
  3443. + .id = -1,
  3444. + .num_resources = 0,
  3445. +};
  3446. +
  3447. +#endif
  3448. +
  3449. +#ifdef CONFIG_SND_BCM2708_SOC_RPI_CODEC_ESS9018_MODULE
  3450. +static struct platform_device snd_rpi_ess9018_device = {
  3451. + .name = "snd-rpi-ess9018",
  3452. + .id = 0,
  3453. + .num_resources = 0,
  3454. +};
  3455. +
  3456. +static struct platform_device snd_rpi_ess9018_codec_device = {
  3457. + .name = "ess9018-codec",
  3458. + .id = -1,
  3459. + .num_resources = 0,
  3460. +};
  3461. +#endif
  3462. +
  3463. +#ifdef CONFIG_SND_BCM2708_SOC_RPI_CODEC_PCM5102A_MODULE
  3464. +static struct platform_device snd_rpi_pcm5102a_device = {
  3465. + .name = "snd-rpi-pcm5102a",
  3466. + .id = 0,
  3467. + .num_resources = 0,
  3468. +};
  3469. +
  3470. +static struct platform_device snd_rpi_pcm5102a_codec_device = {
  3471. + .name = "pcm5102a-codec",
  3472. + .id = -1,
  3473. + .num_resources = 0,
  3474. +};
  3475. +#endif
  3476. +
  3477. +int __init bcm_register_device(struct platform_device *pdev)
  3478. +{
  3479. + int ret;
  3480. +
  3481. + ret = platform_device_register(pdev);
  3482. + if (ret)
  3483. + pr_debug("Unable to register platform device '%s': %d\n",
  3484. + pdev->name, ret);
  3485. +
  3486. + return ret;
  3487. +}
  3488. +
  3489. +int calc_rsts(int partition)
  3490. +{
  3491. + return PM_PASSWORD |
  3492. + ((partition & (1 << 0)) << 0) |
  3493. + ((partition & (1 << 1)) << 1) |
  3494. + ((partition & (1 << 2)) << 2) |
  3495. + ((partition & (1 << 3)) << 3) |
  3496. + ((partition & (1 << 4)) << 4) |
  3497. + ((partition & (1 << 5)) << 5);
  3498. +}
  3499. +
  3500. +static void bcm2708_restart(enum reboot_mode mode, const char *cmd)
  3501. +{
  3502. + extern char bcm2708_reboot_mode;
  3503. + uint32_t pm_rstc, pm_wdog;
  3504. + uint32_t timeout = 10;
  3505. + uint32_t pm_rsts = 0;
  3506. +
  3507. + if(bcm2708_reboot_mode == 'q')
  3508. + {
  3509. + // NOOBS < 1.3 booting with reboot=q
  3510. + pm_rsts = readl(__io_address(PM_RSTS));
  3511. + pm_rsts = PM_PASSWORD | pm_rsts | PM_RSTS_HADWRQ_SET;
  3512. + }
  3513. + else if(bcm2708_reboot_mode == 'p')
  3514. + {
  3515. + // NOOBS < 1.3 halting
  3516. + pm_rsts = readl(__io_address(PM_RSTS));
  3517. + pm_rsts = PM_PASSWORD | pm_rsts | PM_RSTS_HADWRH_SET;
  3518. + }
  3519. + else
  3520. + {
  3521. + pm_rsts = calc_rsts(reboot_part);
  3522. + }
  3523. +
  3524. + writel(pm_rsts, __io_address(PM_RSTS));
  3525. +
  3526. + /* Setup watchdog for reset */
  3527. + pm_rstc = readl(__io_address(PM_RSTC));
  3528. +
  3529. + pm_wdog = PM_PASSWORD | (timeout & PM_WDOG_TIME_SET); // watchdog timer = timer clock / 16; need password (31:16) + value (11:0)
  3530. + pm_rstc = PM_PASSWORD | (pm_rstc & PM_RSTC_WRCFG_CLR) | PM_RSTC_WRCFG_FULL_RESET;
  3531. +
  3532. + writel(pm_wdog, __io_address(PM_WDOG));
  3533. + writel(pm_rstc, __io_address(PM_RSTC));
  3534. +}
  3535. +
  3536. +/* 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 */
  3537. +static void bcm2708_power_off(void)
  3538. +{
  3539. + extern char bcm2708_reboot_mode;
  3540. + if(bcm2708_reboot_mode == 'q')
  3541. + {
  3542. + // NOOBS < v1.3
  3543. + bcm2708_restart('p', "");
  3544. + }
  3545. + else
  3546. + {
  3547. + /* partition 63 is special code for HALT the bootloader knows not to boot*/
  3548. + reboot_part = 63;
  3549. + /* continue with normal reset mechanism */
  3550. + bcm2708_restart(0, "");
  3551. + }
  3552. +}
  3553. +
  3554. +void __init bcm2708_init(void)
  3555. +{
  3556. + int i;
  3557. +
  3558. +#if defined(CONFIG_BCM_VC_CMA)
  3559. + vc_cma_early_init();
  3560. +#endif
  3561. + printk("bcm2708.uart_clock = %d\n", uart_clock);
  3562. + pm_power_off = bcm2708_power_off;
  3563. +
  3564. + if (uart_clock)
  3565. + lookups[0].clk->rate = uart_clock;
  3566. +
  3567. + for (i = 0; i < ARRAY_SIZE(lookups); i++)
  3568. + clkdev_add(&lookups[i]);
  3569. +
  3570. + bcm_register_device(&bcm2708_dmaman_device);
  3571. + bcm_register_device(&bcm2708_vcio_device);
  3572. +#ifdef CONFIG_BCM2708_GPIO
  3573. + bcm_register_device(&bcm2708_gpio_device);
  3574. +#endif
  3575. +#if defined(CONFIG_W1_MASTER_GPIO) || defined(CONFIG_W1_MASTER_GPIO_MODULE)
  3576. + platform_device_register(&w1_device);
  3577. +#endif
  3578. + bcm_register_device(&bcm2708_systemtimer_device);
  3579. + bcm_register_device(&bcm2708_fb_device);
  3580. + if (!fiq_fix_enable)
  3581. + {
  3582. + bcm2708_usb_device.resource = bcm2708_usb_resources_no_fiq_fix;
  3583. + bcm2708_usb_device.num_resources = ARRAY_SIZE(bcm2708_usb_resources_no_fiq_fix);
  3584. + }
  3585. + bcm_register_device(&bcm2708_usb_device);
  3586. + bcm_register_device(&bcm2708_uart1_device);
  3587. + bcm_register_device(&bcm2708_powerman_device);
  3588. +
  3589. +#ifdef CONFIG_MMC_SDHCI_BCM2708
  3590. + bcm_register_device(&bcm2708_emmc_device);
  3591. +#endif
  3592. + bcm2708_init_led();
  3593. + for (i = 0; i < ARRAY_SIZE(bcm2708_alsa_devices); i++)
  3594. + bcm_register_device(&bcm2708_alsa_devices[i]);
  3595. +
  3596. + bcm_register_device(&bcm2708_spi_device);
  3597. + bcm_register_device(&bcm2708_bsc0_device);
  3598. + bcm_register_device(&bcm2708_bsc1_device);
  3599. +
  3600. + bcm_register_device(&bcm2835_hwmon_device);
  3601. + bcm_register_device(&bcm2835_thermal_device);
  3602. +
  3603. +#ifdef CONFIG_SND_BCM2708_SOC_I2S_MODULE
  3604. + bcm_register_device(&bcm2708_i2s_device);
  3605. +#endif
  3606. +
  3607. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC_MODULE)
  3608. + bcm_register_device(&snd_hifiberry_dac_device);
  3609. + bcm_register_device(&snd_pcm5102a_codec_device);
  3610. +#endif
  3611. +
  3612. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI_MODULE)
  3613. + bcm_register_device(&snd_hifiberry_digi_device);
  3614. + i2c_register_board_info(1, snd_wm8804_i2c_devices, ARRAY_SIZE(snd_wm8804_i2c_devices));
  3615. +#endif
  3616. +
  3617. +#if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
  3618. + bcm_register_device(&snd_rpi_dac_device);
  3619. + bcm_register_device(&snd_pcm1794a_codec_device);
  3620. +#endif
  3621. +
  3622. +
  3623. +#ifdef CONFIG_SND_BCM2708_SOC_RPI_CODEC_MBED_MODULE
  3624. + bcm_register_device(&snd_rpi_mbed_device);
  3625. + i2c_register_board_info(1, snd_rpi_mbed_i2c_devices, ARRAY_SIZE(snd_rpi_mbed_i2c_devices));
  3626. +#endif
  3627. +
  3628. +#ifdef CONFIG_SND_BCM2708_SOC_RPI_CODEC_CS534X_MODULE
  3629. + bcm_register_device(&snd_rpi_cs534x_device);
  3630. + bcm_register_device(&snd_rpi_cs534x_codec_device);
  3631. +#endif
  3632. +
  3633. +#ifdef CONFIG_SND_BCM2708_SOC_RPI_CODEC_TDA1541A_MODULE
  3634. + bcm_register_device(&snd_rpi_tda1541a_device);
  3635. + bcm_register_device(&snd_rpi_tda1541a_codec_device);
  3636. +#endif
  3637. +
  3638. +#ifdef CONFIG_SND_BCM2708_SOC_RPI_CODEC_PROTO_MODULE
  3639. + bcm_register_device(&snd_rpi_proto_device);
  3640. + i2c_register_board_info(1, snd_rpi_proto_i2c_devices, ARRAY_SIZE(snd_rpi_proto_i2c_devices));
  3641. +#endif
  3642. +
  3643. +#ifdef CONFIG_SND_BCM2708_SOC_RPI_CODEC_ESS9018_MODULE
  3644. + bcm_register_device(&snd_rpi_ess9018_device);
  3645. + bcm_register_device(&snd_rpi_ess9018_codec_device);
  3646. +#endif
  3647. +
  3648. +#ifdef CONFIG_SND_BCM2708_SOC_RPI_CODEC_PCM5102A_MODULE
  3649. + bcm_register_device(&snd_rpi_pcm5102a_device);
  3650. + bcm_register_device(&snd_rpi_pcm5102a_codec_device);
  3651. +#endif
  3652. +
  3653. + for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
  3654. + struct amba_device *d = amba_devs[i];
  3655. + amba_device_register(d, &iomem_resource);
  3656. + }
  3657. + system_rev = boardrev;
  3658. + system_serial_low = serial;
  3659. +
  3660. +#ifdef CONFIG_BCM2708_SPIDEV
  3661. + spi_register_board_info(bcm2708_spi_devices,
  3662. + ARRAY_SIZE(bcm2708_spi_devices));
  3663. +#endif
  3664. +}
  3665. +
  3666. +static void timer_set_mode(enum clock_event_mode mode,
  3667. + struct clock_event_device *clk)
  3668. +{
  3669. + switch (mode) {
  3670. + case CLOCK_EVT_MODE_ONESHOT: /* Leave the timer disabled, .set_next_event will enable it */
  3671. + case CLOCK_EVT_MODE_SHUTDOWN:
  3672. + break;
  3673. + case CLOCK_EVT_MODE_PERIODIC:
  3674. +
  3675. + case CLOCK_EVT_MODE_UNUSED:
  3676. + case CLOCK_EVT_MODE_RESUME:
  3677. +
  3678. + default:
  3679. + printk(KERN_ERR "timer_set_mode: unhandled mode:%d\n",
  3680. + (int)mode);
  3681. + break;
  3682. + }
  3683. +
  3684. +}
  3685. +
  3686. +static int timer_set_next_event(unsigned long cycles,
  3687. + struct clock_event_device *unused)
  3688. +{
  3689. + unsigned long stc;
  3690. +
  3691. + stc = readl(__io_address(ST_BASE + 0x04));
  3692. + writel(stc + cycles, __io_address(ST_BASE + 0x18)); /* stc3 */
  3693. + return 0;
  3694. +}
  3695. +
  3696. +static struct clock_event_device timer0_clockevent = {
  3697. + .name = "timer0",
  3698. + .shift = 32,
  3699. + .features = CLOCK_EVT_FEAT_ONESHOT,
  3700. + .set_mode = timer_set_mode,
  3701. + .set_next_event = timer_set_next_event,
  3702. +};
  3703. +
  3704. +/*
  3705. + * IRQ handler for the timer
  3706. + */
  3707. +static irqreturn_t bcm2708_timer_interrupt(int irq, void *dev_id)
  3708. +{
  3709. + struct clock_event_device *evt = &timer0_clockevent;
  3710. +
  3711. + writel(1 << 3, __io_address(ST_BASE + 0x00)); /* stcs clear timer int */
  3712. +
  3713. + evt->event_handler(evt);
  3714. +
  3715. + return IRQ_HANDLED;
  3716. +}
  3717. +
  3718. +static struct irqaction bcm2708_timer_irq = {
  3719. + .name = "BCM2708 Timer Tick",
  3720. + .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  3721. + .handler = bcm2708_timer_interrupt,
  3722. +};
  3723. +
  3724. +/*
  3725. + * Set up timer interrupt, and return the current time in seconds.
  3726. + */
  3727. +
  3728. +static struct delay_timer bcm2708_delay_timer = {
  3729. + .read_current_timer = bcm2708_read_current_timer,
  3730. + .freq = STC_FREQ_HZ,
  3731. +};
  3732. +
  3733. +static void __init bcm2708_timer_init(void)
  3734. +{
  3735. + /* init high res timer */
  3736. + bcm2708_clocksource_init();
  3737. +
  3738. + /*
  3739. + * Initialise to a known state (all timers off)
  3740. + */
  3741. + writel(0, __io_address(ARM_T_CONTROL));
  3742. + /*
  3743. + * Make irqs happen for the system timer
  3744. + */
  3745. + setup_irq(IRQ_TIMER3, &bcm2708_timer_irq);
  3746. +
  3747. + setup_sched_clock(bcm2708_read_sched_clock, 32, STC_FREQ_HZ);
  3748. +
  3749. + timer0_clockevent.mult =
  3750. + div_sc(STC_FREQ_HZ, NSEC_PER_SEC, timer0_clockevent.shift);
  3751. + timer0_clockevent.max_delta_ns =
  3752. + clockevent_delta2ns(0xffffffff, &timer0_clockevent);
  3753. + timer0_clockevent.min_delta_ns =
  3754. + clockevent_delta2ns(0xf, &timer0_clockevent);
  3755. +
  3756. + timer0_clockevent.cpumask = cpumask_of(0);
  3757. + clockevents_register_device(&timer0_clockevent);
  3758. +
  3759. + register_current_timer_delay(&bcm2708_delay_timer);
  3760. +}
  3761. +
  3762. +#if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
  3763. +#include <linux/leds.h>
  3764. +
  3765. +static struct gpio_led bcm2708_leds[] = {
  3766. + [0] = {
  3767. + .gpio = 16,
  3768. + .name = "led0",
  3769. + .default_trigger = "mmc0",
  3770. + .active_low = 1,
  3771. + },
  3772. +};
  3773. +
  3774. +static struct gpio_led_platform_data bcm2708_led_pdata = {
  3775. + .num_leds = ARRAY_SIZE(bcm2708_leds),
  3776. + .leds = bcm2708_leds,
  3777. +};
  3778. +
  3779. +static struct platform_device bcm2708_led_device = {
  3780. + .name = "leds-gpio",
  3781. + .id = -1,
  3782. + .dev = {
  3783. + .platform_data = &bcm2708_led_pdata,
  3784. + },
  3785. +};
  3786. +
  3787. +static void __init bcm2708_init_led(void)
  3788. +{
  3789. + bcm2708_leds[0].gpio = disk_led_gpio;
  3790. + bcm2708_leds[0].active_low = disk_led_active_low;
  3791. + platform_device_register(&bcm2708_led_device);
  3792. +}
  3793. +#else
  3794. +static inline void bcm2708_init_led(void)
  3795. +{
  3796. +}
  3797. +#endif
  3798. +
  3799. +void __init bcm2708_init_early(void)
  3800. +{
  3801. + /*
  3802. + * Some devices allocate their coherent buffers from atomic
  3803. + * context. Increase size of atomic coherent pool to make sure such
  3804. + * the allocations won't fail.
  3805. + */
  3806. + init_dma_coherent_pool_size(SZ_4M);
  3807. +}
  3808. +
  3809. +static void __init board_reserve(void)
  3810. +{
  3811. +#if defined(CONFIG_BCM_VC_CMA)
  3812. + vc_cma_reserve();
  3813. +#endif
  3814. +}
  3815. +
  3816. +MACHINE_START(BCM2708, "BCM2708")
  3817. + /* Maintainer: Broadcom Europe Ltd. */
  3818. + .map_io = bcm2708_map_io,
  3819. + .init_irq = bcm2708_init_irq,
  3820. + .init_time = bcm2708_timer_init,
  3821. + .init_machine = bcm2708_init,
  3822. + .init_early = bcm2708_init_early,
  3823. + .reserve = board_reserve,
  3824. + .restart = bcm2708_restart,
  3825. +MACHINE_END
  3826. +
  3827. +module_param(boardrev, uint, 0644);
  3828. +module_param(serial, uint, 0644);
  3829. +module_param(uart_clock, uint, 0644);
  3830. +module_param(disk_led_gpio, uint, 0644);
  3831. +module_param(disk_led_active_low, uint, 0644);
  3832. +module_param(reboot_part, uint, 0644);
  3833. diff -Nur linux-3.13.3.orig/arch/arm/mach-bcm2708/bcm2708_gpio.c linux-3.13.3/arch/arm/mach-bcm2708/bcm2708_gpio.c
  3834. --- linux-3.13.3.orig/arch/arm/mach-bcm2708/bcm2708_gpio.c 1970-01-01 01:00:00.000000000 +0100
  3835. +++ linux-3.13.3/arch/arm/mach-bcm2708/bcm2708_gpio.c 2014-02-17 22:41:01.000000000 +0100
  3836. @@ -0,0 +1,361 @@
  3837. +/*
  3838. + * linux/arch/arm/mach-bcm2708/bcm2708_gpio.c
  3839. + *
  3840. + * Copyright (C) 2010 Broadcom
  3841. + *
  3842. + * This program is free software; you can redistribute it and/or modify
  3843. + * it under the terms of the GNU General Public License version 2 as
  3844. + * published by the Free Software Foundation.
  3845. + *
  3846. + */
  3847. +
  3848. +#include <linux/spinlock.h>
  3849. +#include <linux/module.h>
  3850. +#include <linux/list.h>
  3851. +#include <linux/io.h>
  3852. +#include <linux/irq.h>
  3853. +#include <linux/interrupt.h>
  3854. +#include <linux/slab.h>
  3855. +#include <mach/gpio.h>
  3856. +#include <linux/gpio.h>
  3857. +#include <linux/platform_device.h>
  3858. +#include <mach/platform.h>
  3859. +
  3860. +#define BCM_GPIO_DRIVER_NAME "bcm2708_gpio"
  3861. +#define DRIVER_NAME BCM_GPIO_DRIVER_NAME
  3862. +#define BCM_GPIO_USE_IRQ 1
  3863. +
  3864. +#define GPIOFSEL(x) (0x00+(x)*4)
  3865. +#define GPIOSET(x) (0x1c+(x)*4)
  3866. +#define GPIOCLR(x) (0x28+(x)*4)
  3867. +#define GPIOLEV(x) (0x34+(x)*4)
  3868. +#define GPIOEDS(x) (0x40+(x)*4)
  3869. +#define GPIOREN(x) (0x4c+(x)*4)
  3870. +#define GPIOFEN(x) (0x58+(x)*4)
  3871. +#define GPIOHEN(x) (0x64+(x)*4)
  3872. +#define GPIOLEN(x) (0x70+(x)*4)
  3873. +#define GPIOAREN(x) (0x7c+(x)*4)
  3874. +#define GPIOAFEN(x) (0x88+(x)*4)
  3875. +#define GPIOUD(x) (0x94+(x)*4)
  3876. +#define GPIOUDCLK(x) (0x98+(x)*4)
  3877. +
  3878. +enum { GPIO_FSEL_INPUT, GPIO_FSEL_OUTPUT,
  3879. + GPIO_FSEL_ALT5, GPIO_FSEL_ALT_4,
  3880. + GPIO_FSEL_ALT0, GPIO_FSEL_ALT1,
  3881. + GPIO_FSEL_ALT2, GPIO_FSEL_ALT3,
  3882. +};
  3883. +
  3884. + /* Each of the two spinlocks protects a different set of hardware
  3885. + * regiters and data structurs. This decouples the code of the IRQ from
  3886. + * the GPIO code. This also makes the case of a GPIO routine call from
  3887. + * the IRQ code simpler.
  3888. + */
  3889. +static DEFINE_SPINLOCK(lock); /* GPIO registers */
  3890. +
  3891. +struct bcm2708_gpio {
  3892. + struct list_head list;
  3893. + void __iomem *base;
  3894. + struct gpio_chip gc;
  3895. + unsigned long rising;
  3896. + unsigned long falling;
  3897. + unsigned long high;
  3898. + unsigned long low;
  3899. +};
  3900. +
  3901. +static int bcm2708_set_function(struct gpio_chip *gc, unsigned offset,
  3902. + int function)
  3903. +{
  3904. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  3905. + unsigned long flags;
  3906. + unsigned gpiodir;
  3907. + unsigned gpio_bank = offset / 10;
  3908. + unsigned gpio_field_offset = (offset - 10 * gpio_bank) * 3;
  3909. +
  3910. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_set_function %p (%d,%d)\n", gc, offset, function);
  3911. + if (offset >= ARCH_NR_GPIOS)
  3912. + return -EINVAL;
  3913. +
  3914. + spin_lock_irqsave(&lock, flags);
  3915. +
  3916. + gpiodir = readl(gpio->base + GPIOFSEL(gpio_bank));
  3917. + gpiodir &= ~(7 << gpio_field_offset);
  3918. + gpiodir |= function << gpio_field_offset;
  3919. + writel(gpiodir, gpio->base + GPIOFSEL(gpio_bank));
  3920. + spin_unlock_irqrestore(&lock, flags);
  3921. + gpiodir = readl(gpio->base + GPIOFSEL(gpio_bank));
  3922. +
  3923. + return 0;
  3924. +}
  3925. +
  3926. +static int bcm2708_gpio_dir_in(struct gpio_chip *gc, unsigned offset)
  3927. +{
  3928. + return bcm2708_set_function(gc, offset, GPIO_FSEL_INPUT);
  3929. +}
  3930. +
  3931. +static void bcm2708_gpio_set(struct gpio_chip *gc, unsigned offset, int value);
  3932. +static int bcm2708_gpio_dir_out(struct gpio_chip *gc, unsigned offset,
  3933. + int value)
  3934. +{
  3935. + int ret;
  3936. + ret = bcm2708_set_function(gc, offset, GPIO_FSEL_OUTPUT);
  3937. + if (ret >= 0)
  3938. + bcm2708_gpio_set(gc, offset, value);
  3939. + return ret;
  3940. +}
  3941. +
  3942. +static int bcm2708_gpio_get(struct gpio_chip *gc, unsigned offset)
  3943. +{
  3944. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  3945. + unsigned gpio_bank = offset / 32;
  3946. + unsigned gpio_field_offset = (offset - 32 * gpio_bank);
  3947. + unsigned lev;
  3948. +
  3949. + if (offset >= ARCH_NR_GPIOS)
  3950. + return 0;
  3951. + lev = readl(gpio->base + GPIOLEV(gpio_bank));
  3952. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_get %p (%d)=%d\n", gc, offset, 0x1 & (lev>>gpio_field_offset));
  3953. + return 0x1 & (lev >> gpio_field_offset);
  3954. +}
  3955. +
  3956. +static void bcm2708_gpio_set(struct gpio_chip *gc, unsigned offset, int value)
  3957. +{
  3958. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  3959. + unsigned gpio_bank = offset / 32;
  3960. + unsigned gpio_field_offset = (offset - 32 * gpio_bank);
  3961. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_set %p (%d=%d)\n", gc, offset, value);
  3962. + if (offset >= ARCH_NR_GPIOS)
  3963. + return;
  3964. + if (value)
  3965. + writel(1 << gpio_field_offset, gpio->base + GPIOSET(gpio_bank));
  3966. + else
  3967. + writel(1 << gpio_field_offset, gpio->base + GPIOCLR(gpio_bank));
  3968. +}
  3969. +
  3970. +/*************************************************************************************************************************
  3971. + * bcm2708 GPIO IRQ
  3972. + */
  3973. +
  3974. +#if BCM_GPIO_USE_IRQ
  3975. +
  3976. +static int bcm2708_gpio_to_irq(struct gpio_chip *chip, unsigned gpio)
  3977. +{
  3978. + return gpio_to_irq(gpio);
  3979. +}
  3980. +
  3981. +static int bcm2708_gpio_irq_set_type(struct irq_data *d, unsigned type)
  3982. +{
  3983. + unsigned irq = d->irq;
  3984. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  3985. +
  3986. + gpio->rising &= ~(1 << irq_to_gpio(irq));
  3987. + gpio->falling &= ~(1 << irq_to_gpio(irq));
  3988. + gpio->high &= ~(1 << irq_to_gpio(irq));
  3989. + gpio->low &= ~(1 << irq_to_gpio(irq));
  3990. +
  3991. + if (type & ~(IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING | IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
  3992. + return -EINVAL;
  3993. +
  3994. + if (type & IRQ_TYPE_EDGE_RISING)
  3995. + gpio->rising |= (1 << irq_to_gpio(irq));
  3996. + if (type & IRQ_TYPE_EDGE_FALLING)
  3997. + gpio->falling |= (1 << irq_to_gpio(irq));
  3998. + if (type & IRQ_TYPE_LEVEL_HIGH)
  3999. + gpio->high |= (1 << irq_to_gpio(irq));
  4000. + if (type & IRQ_TYPE_LEVEL_LOW)
  4001. + gpio->low |= (1 << irq_to_gpio(irq));
  4002. + return 0;
  4003. +}
  4004. +
  4005. +static void bcm2708_gpio_irq_mask(struct irq_data *d)
  4006. +{
  4007. + unsigned irq = d->irq;
  4008. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  4009. + unsigned gn = irq_to_gpio(irq);
  4010. + unsigned gb = gn / 32;
  4011. + unsigned long rising = readl(gpio->base + GPIOREN(gb));
  4012. + unsigned long falling = readl(gpio->base + GPIOFEN(gb));
  4013. + unsigned long high = readl(gpio->base + GPIOHEN(gb));
  4014. + unsigned long low = readl(gpio->base + GPIOLEN(gb));
  4015. +
  4016. + gn = gn % 32;
  4017. +
  4018. + writel(rising & ~(1 << gn), gpio->base + GPIOREN(gb));
  4019. + writel(falling & ~(1 << gn), gpio->base + GPIOFEN(gb));
  4020. + writel(high & ~(1 << gn), gpio->base + GPIOHEN(gb));
  4021. + writel(low & ~(1 << gn), gpio->base + GPIOLEN(gb));
  4022. +}
  4023. +
  4024. +static void bcm2708_gpio_irq_unmask(struct irq_data *d)
  4025. +{
  4026. + unsigned irq = d->irq;
  4027. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  4028. + unsigned gn = irq_to_gpio(irq);
  4029. + unsigned gb = gn / 32;
  4030. + unsigned long rising = readl(gpio->base + GPIOREN(gb));
  4031. + unsigned long falling = readl(gpio->base + GPIOFEN(gb));
  4032. + unsigned long high = readl(gpio->base + GPIOHEN(gb));
  4033. + unsigned long low = readl(gpio->base + GPIOLEN(gb));
  4034. +
  4035. + gn = gn % 32;
  4036. +
  4037. + writel(1 << gn, gpio->base + GPIOEDS(gb));
  4038. +
  4039. + if (gpio->rising & (1 << gn)) {
  4040. + writel(rising | (1 << gn), gpio->base + GPIOREN(gb));
  4041. + } else {
  4042. + writel(rising & ~(1 << gn), gpio->base + GPIOREN(gb));
  4043. + }
  4044. +
  4045. + if (gpio->falling & (1 << gn)) {
  4046. + writel(falling | (1 << gn), gpio->base + GPIOFEN(gb));
  4047. + } else {
  4048. + writel(falling & ~(1 << gn), gpio->base + GPIOFEN(gb));
  4049. + }
  4050. +
  4051. + if (gpio->high & (1 << gn)) {
  4052. + writel(high | (1 << gn), gpio->base + GPIOHEN(gb));
  4053. + } else {
  4054. + writel(high & ~(1 << gn), gpio->base + GPIOHEN(gb));
  4055. + }
  4056. +
  4057. + if (gpio->low & (1 << gn)) {
  4058. + writel(low | (1 << gn), gpio->base + GPIOLEN(gb));
  4059. + } else {
  4060. + writel(low & ~(1 << gn), gpio->base + GPIOLEN(gb));
  4061. + }
  4062. +}
  4063. +
  4064. +static struct irq_chip bcm2708_irqchip = {
  4065. + .name = "GPIO",
  4066. + .irq_enable = bcm2708_gpio_irq_unmask,
  4067. + .irq_disable = bcm2708_gpio_irq_mask,
  4068. + .irq_unmask = bcm2708_gpio_irq_unmask,
  4069. + .irq_mask = bcm2708_gpio_irq_mask,
  4070. + .irq_set_type = bcm2708_gpio_irq_set_type,
  4071. +};
  4072. +
  4073. +static irqreturn_t bcm2708_gpio_interrupt(int irq, void *dev_id)
  4074. +{
  4075. + unsigned long edsr;
  4076. + unsigned bank;
  4077. + int i;
  4078. + unsigned gpio;
  4079. + for (bank = 0; bank <= 1; bank++) {
  4080. + edsr = readl(__io_address(GPIO_BASE) + GPIOEDS(bank));
  4081. + for_each_set_bit(i, &edsr, 32) {
  4082. + gpio = i + bank * 32;
  4083. + generic_handle_irq(gpio_to_irq(gpio));
  4084. + }
  4085. + writel(0xffffffff, __io_address(GPIO_BASE) + GPIOEDS(bank));
  4086. + }
  4087. + return IRQ_HANDLED;
  4088. +}
  4089. +
  4090. +static struct irqaction bcm2708_gpio_irq = {
  4091. + .name = "BCM2708 GPIO catchall handler",
  4092. + .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  4093. + .handler = bcm2708_gpio_interrupt,
  4094. +};
  4095. +
  4096. +static void bcm2708_gpio_irq_init(struct bcm2708_gpio *ucb)
  4097. +{
  4098. + unsigned irq;
  4099. +
  4100. + ucb->gc.to_irq = bcm2708_gpio_to_irq;
  4101. +
  4102. + for (irq = GPIO_IRQ_START; irq < (GPIO_IRQ_START + GPIO_IRQS); irq++) {
  4103. + irq_set_chip_data(irq, ucb);
  4104. + irq_set_chip(irq, &bcm2708_irqchip);
  4105. + set_irq_flags(irq, IRQF_VALID);
  4106. + }
  4107. + setup_irq(IRQ_GPIO3, &bcm2708_gpio_irq);
  4108. +}
  4109. +
  4110. +#else
  4111. +
  4112. +static void bcm2708_gpio_irq_init(struct bcm2708_gpio *ucb)
  4113. +{
  4114. +}
  4115. +
  4116. +#endif /* #if BCM_GPIO_USE_IRQ ***************************************************************************************************************** */
  4117. +
  4118. +static int bcm2708_gpio_probe(struct platform_device *dev)
  4119. +{
  4120. + struct bcm2708_gpio *ucb;
  4121. + struct resource *res;
  4122. + int err = 0;
  4123. +
  4124. + printk(KERN_INFO DRIVER_NAME ": bcm2708_gpio_probe %p\n", dev);
  4125. +
  4126. + ucb = kzalloc(sizeof(*ucb), GFP_KERNEL);
  4127. + if (NULL == ucb) {
  4128. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  4129. + "mailbox memory\n");
  4130. + err = -ENOMEM;
  4131. + goto err;
  4132. + }
  4133. +
  4134. + res = platform_get_resource(dev, IORESOURCE_MEM, 0);
  4135. +
  4136. + platform_set_drvdata(dev, ucb);
  4137. + ucb->base = __io_address(GPIO_BASE);
  4138. +
  4139. + ucb->gc.label = "bcm2708_gpio";
  4140. + ucb->gc.base = 0;
  4141. + ucb->gc.ngpio = ARCH_NR_GPIOS;
  4142. + ucb->gc.owner = THIS_MODULE;
  4143. +
  4144. + ucb->gc.direction_input = bcm2708_gpio_dir_in;
  4145. + ucb->gc.direction_output = bcm2708_gpio_dir_out;
  4146. + ucb->gc.get = bcm2708_gpio_get;
  4147. + ucb->gc.set = bcm2708_gpio_set;
  4148. + ucb->gc.can_sleep = 0;
  4149. +
  4150. + bcm2708_gpio_irq_init(ucb);
  4151. +
  4152. + err = gpiochip_add(&ucb->gc);
  4153. + if (err)
  4154. + goto err;
  4155. +
  4156. +err:
  4157. + return err;
  4158. +
  4159. +}
  4160. +
  4161. +static int bcm2708_gpio_remove(struct platform_device *dev)
  4162. +{
  4163. + int err = 0;
  4164. + struct bcm2708_gpio *ucb = platform_get_drvdata(dev);
  4165. +
  4166. + printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_remove %p\n", dev);
  4167. +
  4168. + err = gpiochip_remove(&ucb->gc);
  4169. +
  4170. + platform_set_drvdata(dev, NULL);
  4171. + kfree(ucb);
  4172. +
  4173. + return err;
  4174. +}
  4175. +
  4176. +static struct platform_driver bcm2708_gpio_driver = {
  4177. + .probe = bcm2708_gpio_probe,
  4178. + .remove = bcm2708_gpio_remove,
  4179. + .driver = {
  4180. + .name = "bcm2708_gpio"},
  4181. +};
  4182. +
  4183. +static int __init bcm2708_gpio_init(void)
  4184. +{
  4185. + return platform_driver_register(&bcm2708_gpio_driver);
  4186. +}
  4187. +
  4188. +static void __exit bcm2708_gpio_exit(void)
  4189. +{
  4190. + platform_driver_unregister(&bcm2708_gpio_driver);
  4191. +}
  4192. +
  4193. +module_init(bcm2708_gpio_init);
  4194. +module_exit(bcm2708_gpio_exit);
  4195. +
  4196. +MODULE_DESCRIPTION("Broadcom BCM2708 GPIO driver");
  4197. +MODULE_LICENSE("GPL");
  4198. diff -Nur linux-3.13.3.orig/arch/arm/mach-bcm2708/bcm2708.h linux-3.13.3/arch/arm/mach-bcm2708/bcm2708.h
  4199. --- linux-3.13.3.orig/arch/arm/mach-bcm2708/bcm2708.h 1970-01-01 01:00:00.000000000 +0100
  4200. +++ linux-3.13.3/arch/arm/mach-bcm2708/bcm2708.h 2014-02-17 22:41:01.000000000 +0100
  4201. @@ -0,0 +1,49 @@
  4202. +/*
  4203. + * linux/arch/arm/mach-bcm2708/bcm2708.h
  4204. + *
  4205. + * BCM2708 machine support header
  4206. + *
  4207. + * Copyright (C) 2010 Broadcom
  4208. + *
  4209. + * This program is free software; you can redistribute it and/or modify
  4210. + * it under the terms of the GNU General Public License as published by
  4211. + * the Free Software Foundation; either version 2 of the License, or
  4212. + * (at your option) any later version.
  4213. + *
  4214. + * This program is distributed in the hope that it will be useful,
  4215. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4216. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4217. + * GNU General Public License for more details.
  4218. + *
  4219. + * You should have received a copy of the GNU General Public License
  4220. + * along with this program; if not, write to the Free Software
  4221. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  4222. + */
  4223. +
  4224. +#ifndef __BCM2708_BCM2708_H
  4225. +#define __BCM2708_BCM2708_H
  4226. +
  4227. +#include <linux/amba/bus.h>
  4228. +
  4229. +extern void __init bcm2708_init(void);
  4230. +extern void __init bcm2708_init_irq(void);
  4231. +extern void __init bcm2708_map_io(void);
  4232. +extern struct sys_timer bcm2708_timer;
  4233. +extern unsigned int mmc_status(struct device *dev);
  4234. +
  4235. +#define AMBA_DEVICE(name, busid, base, plat) \
  4236. +static struct amba_device name##_device = { \
  4237. + .dev = { \
  4238. + .coherent_dma_mask = ~0, \
  4239. + .init_name = busid, \
  4240. + .platform_data = plat, \
  4241. + }, \
  4242. + .res = { \
  4243. + .start = base##_BASE, \
  4244. + .end = (base##_BASE) + SZ_4K - 1,\
  4245. + .flags = IORESOURCE_MEM, \
  4246. + }, \
  4247. + .irq = base##_IRQ, \
  4248. +}
  4249. +
  4250. +#endif
  4251. diff -Nur linux-3.13.3.orig/arch/arm/mach-bcm2708/clock.c linux-3.13.3/arch/arm/mach-bcm2708/clock.c
  4252. --- linux-3.13.3.orig/arch/arm/mach-bcm2708/clock.c 1970-01-01 01:00:00.000000000 +0100
  4253. +++ linux-3.13.3/arch/arm/mach-bcm2708/clock.c 2014-02-17 22:41:01.000000000 +0100
  4254. @@ -0,0 +1,61 @@
  4255. +/*
  4256. + * linux/arch/arm/mach-bcm2708/clock.c
  4257. + *
  4258. + * Copyright (C) 2010 Broadcom
  4259. + *
  4260. + * This program is free software; you can redistribute it and/or modify
  4261. + * it under the terms of the GNU General Public License as published by
  4262. + * the Free Software Foundation; either version 2 of the License, or
  4263. + * (at your option) any later version.
  4264. + *
  4265. + * This program is distributed in the hope that it will be useful,
  4266. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4267. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4268. + * GNU General Public License for more details.
  4269. + *
  4270. + * You should have received a copy of the GNU General Public License
  4271. + * along with this program; if not, write to the Free Software
  4272. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  4273. + */
  4274. +#include <linux/module.h>
  4275. +#include <linux/kernel.h>
  4276. +#include <linux/device.h>
  4277. +#include <linux/list.h>
  4278. +#include <linux/errno.h>
  4279. +#include <linux/err.h>
  4280. +#include <linux/string.h>
  4281. +#include <linux/clk.h>
  4282. +#include <linux/mutex.h>
  4283. +
  4284. +#include <asm/clkdev.h>
  4285. +
  4286. +#include "clock.h"
  4287. +
  4288. +int clk_enable(struct clk *clk)
  4289. +{
  4290. + return 0;
  4291. +}
  4292. +EXPORT_SYMBOL(clk_enable);
  4293. +
  4294. +void clk_disable(struct clk *clk)
  4295. +{
  4296. +}
  4297. +EXPORT_SYMBOL(clk_disable);
  4298. +
  4299. +unsigned long clk_get_rate(struct clk *clk)
  4300. +{
  4301. + return clk->rate;
  4302. +}
  4303. +EXPORT_SYMBOL(clk_get_rate);
  4304. +
  4305. +long clk_round_rate(struct clk *clk, unsigned long rate)
  4306. +{
  4307. + return clk->rate;
  4308. +}
  4309. +EXPORT_SYMBOL(clk_round_rate);
  4310. +
  4311. +int clk_set_rate(struct clk *clk, unsigned long rate)
  4312. +{
  4313. + return -EIO;
  4314. +}
  4315. +EXPORT_SYMBOL(clk_set_rate);
  4316. diff -Nur linux-3.13.3.orig/arch/arm/mach-bcm2708/clock.h linux-3.13.3/arch/arm/mach-bcm2708/clock.h
  4317. --- linux-3.13.3.orig/arch/arm/mach-bcm2708/clock.h 1970-01-01 01:00:00.000000000 +0100
  4318. +++ linux-3.13.3/arch/arm/mach-bcm2708/clock.h 2014-02-17 22:41:01.000000000 +0100
  4319. @@ -0,0 +1,24 @@
  4320. +/*
  4321. + * linux/arch/arm/mach-bcm2708/clock.h
  4322. + *
  4323. + * Copyright (C) 2010 Broadcom
  4324. + *
  4325. + * This program is free software; you can redistribute it and/or modify
  4326. + * it under the terms of the GNU General Public License as published by
  4327. + * the Free Software Foundation; either version 2 of the License, or
  4328. + * (at your option) any later version.
  4329. + *
  4330. + * This program is distributed in the hope that it will be useful,
  4331. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4332. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4333. + * GNU General Public License for more details.
  4334. + *
  4335. + * You should have received a copy of the GNU General Public License
  4336. + * along with this program; if not, write to the Free Software
  4337. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  4338. + */
  4339. +struct module;
  4340. +
  4341. +struct clk {
  4342. + unsigned long rate;
  4343. +};
  4344. diff -Nur linux-3.13.3.orig/arch/arm/mach-bcm2708/dma.c linux-3.13.3/arch/arm/mach-bcm2708/dma.c
  4345. --- linux-3.13.3.orig/arch/arm/mach-bcm2708/dma.c 1970-01-01 01:00:00.000000000 +0100
  4346. +++ linux-3.13.3/arch/arm/mach-bcm2708/dma.c 2014-02-17 22:41:01.000000000 +0100
  4347. @@ -0,0 +1,407 @@
  4348. +/*
  4349. + * linux/arch/arm/mach-bcm2708/dma.c
  4350. + *
  4351. + * Copyright (C) 2010 Broadcom
  4352. + *
  4353. + * This program is free software; you can redistribute it and/or modify
  4354. + * it under the terms of the GNU General Public License version 2 as
  4355. + * published by the Free Software Foundation.
  4356. + */
  4357. +
  4358. +#include <linux/slab.h>
  4359. +#include <linux/device.h>
  4360. +#include <linux/platform_device.h>
  4361. +#include <linux/module.h>
  4362. +#include <linux/scatterlist.h>
  4363. +
  4364. +#include <mach/dma.h>
  4365. +#include <mach/irqs.h>
  4366. +
  4367. +/*****************************************************************************\
  4368. + * *
  4369. + * Configuration *
  4370. + * *
  4371. +\*****************************************************************************/
  4372. +
  4373. +#define CACHE_LINE_MASK 31
  4374. +#define DRIVER_NAME BCM_DMAMAN_DRIVER_NAME
  4375. +#define DEFAULT_DMACHAN_BITMAP 0x10 /* channel 4 only */
  4376. +
  4377. +/* valid only for channels 0 - 14, 15 has its own base address */
  4378. +#define BCM2708_DMA_CHAN(n) ((n)<<8) /* base address */
  4379. +#define BCM2708_DMA_CHANIO(dma_base, n) \
  4380. + ((void __iomem *)((char *)(dma_base)+BCM2708_DMA_CHAN(n)))
  4381. +
  4382. +
  4383. +/*****************************************************************************\
  4384. + * *
  4385. + * DMA Auxilliary Functions *
  4386. + * *
  4387. +\*****************************************************************************/
  4388. +
  4389. +/* A DMA buffer on an arbitrary boundary may separate a cache line into a
  4390. + section inside the DMA buffer and another section outside it.
  4391. + Even if we flush DMA buffers from the cache there is always the chance that
  4392. + during a DMA someone will access the part of a cache line that is outside
  4393. + the DMA buffer - which will then bring in unwelcome data.
  4394. + Without being able to dictate our own buffer pools we must insist that
  4395. + DMA buffers consist of a whole number of cache lines.
  4396. +*/
  4397. +
  4398. +extern int
  4399. +bcm_sg_suitable_for_dma(struct scatterlist *sg_ptr, int sg_len)
  4400. +{
  4401. + int i;
  4402. +
  4403. + for (i = 0; i < sg_len; i++) {
  4404. + if (sg_ptr[i].offset & CACHE_LINE_MASK ||
  4405. + sg_ptr[i].length & CACHE_LINE_MASK)
  4406. + return 0;
  4407. + }
  4408. +
  4409. + return 1;
  4410. +}
  4411. +EXPORT_SYMBOL_GPL(bcm_sg_suitable_for_dma);
  4412. +
  4413. +extern void
  4414. +bcm_dma_start(void __iomem *dma_chan_base, dma_addr_t control_block)
  4415. +{
  4416. + dsb(); /* ARM data synchronization (push) operation */
  4417. +
  4418. + writel(control_block, dma_chan_base + BCM2708_DMA_ADDR);
  4419. + writel(BCM2708_DMA_ACTIVE, dma_chan_base + BCM2708_DMA_CS);
  4420. +}
  4421. +
  4422. +extern void bcm_dma_wait_idle(void __iomem *dma_chan_base)
  4423. +{
  4424. + dsb();
  4425. +
  4426. + /* ugly busy wait only option for now */
  4427. + while (readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_ACTIVE)
  4428. + cpu_relax();
  4429. +}
  4430. +
  4431. +EXPORT_SYMBOL_GPL(bcm_dma_start);
  4432. +
  4433. +extern bool bcm_dma_is_busy(void __iomem *dma_chan_base)
  4434. +{
  4435. + dsb();
  4436. +
  4437. + return readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_ACTIVE;
  4438. +}
  4439. +EXPORT_SYMBOL_GPL(bcm_dma_is_busy);
  4440. +
  4441. +/* Complete an ongoing DMA (assuming its results are to be ignored)
  4442. + Does nothing if there is no DMA in progress.
  4443. + This routine waits for the current AXI transfer to complete before
  4444. + terminating the current DMA. If the current transfer is hung on a DREQ used
  4445. + by an uncooperative peripheral the AXI transfer may never complete. In this
  4446. + case the routine times out and return a non-zero error code.
  4447. + Use of this routine doesn't guarantee that the ongoing or aborted DMA
  4448. + does not produce an interrupt.
  4449. +*/
  4450. +extern int
  4451. +bcm_dma_abort(void __iomem *dma_chan_base)
  4452. +{
  4453. + unsigned long int cs;
  4454. + int rc = 0;
  4455. +
  4456. + cs = readl(dma_chan_base + BCM2708_DMA_CS);
  4457. +
  4458. + if (BCM2708_DMA_ACTIVE & cs) {
  4459. + long int timeout = 10000;
  4460. +
  4461. + /* write 0 to the active bit - pause the DMA */
  4462. + writel(0, dma_chan_base + BCM2708_DMA_CS);
  4463. +
  4464. + /* wait for any current AXI transfer to complete */
  4465. + while (0 != (cs & BCM2708_DMA_ISPAUSED) && --timeout >= 0)
  4466. + cs = readl(dma_chan_base + BCM2708_DMA_CS);
  4467. +
  4468. + if (0 != (cs & BCM2708_DMA_ISPAUSED)) {
  4469. + /* we'll un-pause when we set of our next DMA */
  4470. + rc = -ETIMEDOUT;
  4471. +
  4472. + } else if (BCM2708_DMA_ACTIVE & cs) {
  4473. + /* terminate the control block chain */
  4474. + writel(0, dma_chan_base + BCM2708_DMA_NEXTCB);
  4475. +
  4476. + /* abort the whole DMA */
  4477. + writel(BCM2708_DMA_ABORT | BCM2708_DMA_ACTIVE,
  4478. + dma_chan_base + BCM2708_DMA_CS);
  4479. + }
  4480. + }
  4481. +
  4482. + return rc;
  4483. +}
  4484. +EXPORT_SYMBOL_GPL(bcm_dma_abort);
  4485. +
  4486. +
  4487. +/***************************************************************************** \
  4488. + * *
  4489. + * DMA Manager Device Methods *
  4490. + * *
  4491. +\*****************************************************************************/
  4492. +
  4493. +struct vc_dmaman {
  4494. + void __iomem *dma_base;
  4495. + u32 chan_available; /* bitmap of available channels */
  4496. + u32 has_feature[BCM_DMA_FEATURE_COUNT]; /* bitmap of feature presence */
  4497. +};
  4498. +
  4499. +static void vc_dmaman_init(struct vc_dmaman *dmaman, void __iomem *dma_base,
  4500. + u32 chans_available)
  4501. +{
  4502. + dmaman->dma_base = dma_base;
  4503. + dmaman->chan_available = chans_available;
  4504. + dmaman->has_feature[BCM_DMA_FEATURE_FAST_ORD] = 0x0c; /* chans 2 & 3 */
  4505. + dmaman->has_feature[BCM_DMA_FEATURE_BULK_ORD] = 0x01; /* chan 0 */
  4506. +}
  4507. +
  4508. +static int vc_dmaman_chan_alloc(struct vc_dmaman *dmaman,
  4509. + unsigned preferred_feature_set)
  4510. +{
  4511. + u32 chans;
  4512. + int feature;
  4513. +
  4514. + chans = dmaman->chan_available;
  4515. + for (feature = 0; feature < BCM_DMA_FEATURE_COUNT; feature++)
  4516. + /* select the subset of available channels with the desired
  4517. + feature so long as some of the candidate channels have that
  4518. + feature */
  4519. + if ((preferred_feature_set & (1 << feature)) &&
  4520. + (chans & dmaman->has_feature[feature]))
  4521. + chans &= dmaman->has_feature[feature];
  4522. +
  4523. + if (chans) {
  4524. + int chan = 0;
  4525. + /* return the ordinal of the first channel in the bitmap */
  4526. + while (chans != 0 && (chans & 1) == 0) {
  4527. + chans >>= 1;
  4528. + chan++;
  4529. + }
  4530. + /* claim the channel */
  4531. + dmaman->chan_available &= ~(1 << chan);
  4532. + return chan;
  4533. + } else
  4534. + return -ENOMEM;
  4535. +}
  4536. +
  4537. +static int vc_dmaman_chan_free(struct vc_dmaman *dmaman, int chan)
  4538. +{
  4539. + if (chan < 0)
  4540. + return -EINVAL;
  4541. + else if ((1 << chan) & dmaman->chan_available)
  4542. + return -EIDRM;
  4543. + else {
  4544. + dmaman->chan_available |= (1 << chan);
  4545. + return 0;
  4546. + }
  4547. +}
  4548. +
  4549. +/*****************************************************************************\
  4550. + * *
  4551. + * DMA IRQs *
  4552. + * *
  4553. +\*****************************************************************************/
  4554. +
  4555. +static unsigned char bcm_dma_irqs[] = {
  4556. + IRQ_DMA0,
  4557. + IRQ_DMA1,
  4558. + IRQ_DMA2,
  4559. + IRQ_DMA3,
  4560. + IRQ_DMA4,
  4561. + IRQ_DMA5,
  4562. + IRQ_DMA6,
  4563. + IRQ_DMA7,
  4564. + IRQ_DMA8,
  4565. + IRQ_DMA9,
  4566. + IRQ_DMA10,
  4567. + IRQ_DMA11,
  4568. + IRQ_DMA12
  4569. +};
  4570. +
  4571. +
  4572. +/***************************************************************************** \
  4573. + * *
  4574. + * DMA Manager Monitor *
  4575. + * *
  4576. +\*****************************************************************************/
  4577. +
  4578. +static struct device *dmaman_dev; /* we assume there's only one! */
  4579. +
  4580. +extern int bcm_dma_chan_alloc(unsigned preferred_feature_set,
  4581. + void __iomem **out_dma_base, int *out_dma_irq)
  4582. +{
  4583. + if (!dmaman_dev)
  4584. + return -ENODEV;
  4585. + else {
  4586. + struct vc_dmaman *dmaman = dev_get_drvdata(dmaman_dev);
  4587. + int rc;
  4588. +
  4589. + device_lock(dmaman_dev);
  4590. + rc = vc_dmaman_chan_alloc(dmaman, preferred_feature_set);
  4591. + if (rc >= 0) {
  4592. + *out_dma_base = BCM2708_DMA_CHANIO(dmaman->dma_base,
  4593. + rc);
  4594. + *out_dma_irq = bcm_dma_irqs[rc];
  4595. + }
  4596. + device_unlock(dmaman_dev);
  4597. +
  4598. + return rc;
  4599. + }
  4600. +}
  4601. +EXPORT_SYMBOL_GPL(bcm_dma_chan_alloc);
  4602. +
  4603. +extern int bcm_dma_chan_free(int channel)
  4604. +{
  4605. + if (dmaman_dev) {
  4606. + struct vc_dmaman *dmaman = dev_get_drvdata(dmaman_dev);
  4607. + int rc;
  4608. +
  4609. + device_lock(dmaman_dev);
  4610. + rc = vc_dmaman_chan_free(dmaman, channel);
  4611. + device_unlock(dmaman_dev);
  4612. +
  4613. + return rc;
  4614. + } else
  4615. + return -ENODEV;
  4616. +}
  4617. +EXPORT_SYMBOL_GPL(bcm_dma_chan_free);
  4618. +
  4619. +static int dev_dmaman_register(const char *dev_name, struct device *dev)
  4620. +{
  4621. + int rc = dmaman_dev ? -EINVAL : 0;
  4622. + dmaman_dev = dev;
  4623. + return rc;
  4624. +}
  4625. +
  4626. +static void dev_dmaman_deregister(const char *dev_name, struct device *dev)
  4627. +{
  4628. + dmaman_dev = NULL;
  4629. +}
  4630. +
  4631. +/*****************************************************************************\
  4632. + * *
  4633. + * DMA Device *
  4634. + * *
  4635. +\*****************************************************************************/
  4636. +
  4637. +static int dmachans = -1; /* module parameter */
  4638. +
  4639. +static int bcm_dmaman_probe(struct platform_device *pdev)
  4640. +{
  4641. + int ret = 0;
  4642. + struct vc_dmaman *dmaman;
  4643. + struct resource *dma_res = NULL;
  4644. + void __iomem *dma_base = NULL;
  4645. + int have_dma_region = 0;
  4646. +
  4647. + dmaman = kzalloc(sizeof(*dmaman), GFP_KERNEL);
  4648. + if (NULL == dmaman) {
  4649. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  4650. + "DMA management memory\n");
  4651. + ret = -ENOMEM;
  4652. + } else {
  4653. +
  4654. + dma_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  4655. + if (dma_res == NULL) {
  4656. + printk(KERN_ERR DRIVER_NAME ": failed to obtain memory "
  4657. + "resource\n");
  4658. + ret = -ENODEV;
  4659. + } else if (!request_mem_region(dma_res->start,
  4660. + resource_size(dma_res),
  4661. + DRIVER_NAME)) {
  4662. + dev_err(&pdev->dev, "cannot obtain DMA region\n");
  4663. + ret = -EBUSY;
  4664. + } else {
  4665. + have_dma_region = 1;
  4666. + dma_base = ioremap(dma_res->start,
  4667. + resource_size(dma_res));
  4668. + if (!dma_base) {
  4669. + dev_err(&pdev->dev, "cannot map DMA region\n");
  4670. + ret = -ENOMEM;
  4671. + } else {
  4672. + /* use module parameter if one was provided */
  4673. + if (dmachans > 0)
  4674. + vc_dmaman_init(dmaman, dma_base,
  4675. + dmachans);
  4676. + else
  4677. + vc_dmaman_init(dmaman, dma_base,
  4678. + DEFAULT_DMACHAN_BITMAP);
  4679. +
  4680. + platform_set_drvdata(pdev, dmaman);
  4681. + dev_dmaman_register(DRIVER_NAME, &pdev->dev);
  4682. +
  4683. + printk(KERN_INFO DRIVER_NAME ": DMA manager "
  4684. + "at %p\n", dma_base);
  4685. + }
  4686. + }
  4687. + }
  4688. + if (ret != 0) {
  4689. + if (dma_base)
  4690. + iounmap(dma_base);
  4691. + if (dma_res && have_dma_region)
  4692. + release_mem_region(dma_res->start,
  4693. + resource_size(dma_res));
  4694. + if (dmaman)
  4695. + kfree(dmaman);
  4696. + }
  4697. + return ret;
  4698. +}
  4699. +
  4700. +static int bcm_dmaman_remove(struct platform_device *pdev)
  4701. +{
  4702. + struct vc_dmaman *dmaman = platform_get_drvdata(pdev);
  4703. +
  4704. + platform_set_drvdata(pdev, NULL);
  4705. + dev_dmaman_deregister(DRIVER_NAME, &pdev->dev);
  4706. + kfree(dmaman);
  4707. +
  4708. + return 0;
  4709. +}
  4710. +
  4711. +static struct platform_driver bcm_dmaman_driver = {
  4712. + .probe = bcm_dmaman_probe,
  4713. + .remove = bcm_dmaman_remove,
  4714. +
  4715. + .driver = {
  4716. + .name = DRIVER_NAME,
  4717. + .owner = THIS_MODULE,
  4718. + },
  4719. +};
  4720. +
  4721. +/*****************************************************************************\
  4722. + * *
  4723. + * Driver init/exit *
  4724. + * *
  4725. +\*****************************************************************************/
  4726. +
  4727. +static int __init bcm_dmaman_drv_init(void)
  4728. +{
  4729. + int ret;
  4730. +
  4731. + ret = platform_driver_register(&bcm_dmaman_driver);
  4732. + if (ret != 0) {
  4733. + printk(KERN_ERR DRIVER_NAME ": failed to register "
  4734. + "on platform\n");
  4735. + }
  4736. +
  4737. + return ret;
  4738. +}
  4739. +
  4740. +static void __exit bcm_dmaman_drv_exit(void)
  4741. +{
  4742. + platform_driver_unregister(&bcm_dmaman_driver);
  4743. +}
  4744. +
  4745. +module_init(bcm_dmaman_drv_init);
  4746. +module_exit(bcm_dmaman_drv_exit);
  4747. +
  4748. +module_param(dmachans, int, 0644);
  4749. +
  4750. +MODULE_AUTHOR("Gray Girling <grayg@broadcom.com>");
  4751. +MODULE_DESCRIPTION("DMA channel manager driver");
  4752. +MODULE_LICENSE("GPL");
  4753. +
  4754. +MODULE_PARM_DESC(dmachans, "Bitmap of DMA channels available to the ARM");
  4755. diff -Nur linux-3.13.3.orig/arch/arm/mach-bcm2708/include/mach/arm_control.h linux-3.13.3/arch/arm/mach-bcm2708/include/mach/arm_control.h
  4756. --- linux-3.13.3.orig/arch/arm/mach-bcm2708/include/mach/arm_control.h 1970-01-01 01:00:00.000000000 +0100
  4757. +++ linux-3.13.3/arch/arm/mach-bcm2708/include/mach/arm_control.h 2014-02-17 22:41:01.000000000 +0100
  4758. @@ -0,0 +1,419 @@
  4759. +/*
  4760. + * linux/arch/arm/mach-bcm2708/arm_control.h
  4761. + *
  4762. + * Copyright (C) 2010 Broadcom
  4763. + *
  4764. + * This program is free software; you can redistribute it and/or modify
  4765. + * it under the terms of the GNU General Public License as published by
  4766. + * the Free Software Foundation; either version 2 of the License, or
  4767. + * (at your option) any later version.
  4768. + *
  4769. + * This program is distributed in the hope that it will be useful,
  4770. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4771. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4772. + * GNU General Public License for more details.
  4773. + *
  4774. + * You should have received a copy of the GNU General Public License
  4775. + * along with this program; if not, write to the Free Software
  4776. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  4777. + */
  4778. +
  4779. +#ifndef __BCM2708_ARM_CONTROL_H
  4780. +#define __BCM2708_ARM_CONTROL_H
  4781. +
  4782. +/*
  4783. + * Definitions and addresses for the ARM CONTROL logic
  4784. + * This file is manually generated.
  4785. + */
  4786. +
  4787. +#define ARM_BASE 0x7E00B000
  4788. +
  4789. +/* Basic configuration */
  4790. +#define ARM_CONTROL0 HW_REGISTER_RW(ARM_BASE+0x000)
  4791. +#define ARM_C0_SIZ128M 0x00000000
  4792. +#define ARM_C0_SIZ256M 0x00000001
  4793. +#define ARM_C0_SIZ512M 0x00000002
  4794. +#define ARM_C0_SIZ1G 0x00000003
  4795. +#define ARM_C0_BRESP0 0x00000000
  4796. +#define ARM_C0_BRESP1 0x00000004
  4797. +#define ARM_C0_BRESP2 0x00000008
  4798. +#define ARM_C0_BOOTHI 0x00000010
  4799. +#define ARM_C0_UNUSED05 0x00000020 /* free */
  4800. +#define ARM_C0_FULLPERI 0x00000040
  4801. +#define ARM_C0_UNUSED78 0x00000180 /* free */
  4802. +#define ARM_C0_JTAGMASK 0x00000E00
  4803. +#define ARM_C0_JTAGOFF 0x00000000
  4804. +#define ARM_C0_JTAGBASH 0x00000800 /* Debug on GPIO off */
  4805. +#define ARM_C0_JTAGGPIO 0x00000C00 /* Debug on GPIO on */
  4806. +#define ARM_C0_APROTMSK 0x0000F000
  4807. +#define ARM_C0_DBG0SYNC 0x00010000 /* VPU0 halt sync */
  4808. +#define ARM_C0_DBG1SYNC 0x00020000 /* VPU1 halt sync */
  4809. +#define ARM_C0_SWDBGREQ 0x00040000 /* HW debug request */
  4810. +#define ARM_C0_PASSHALT 0x00080000 /* ARM halt passed to debugger */
  4811. +#define ARM_C0_PRIO_PER 0x00F00000 /* per priority mask */
  4812. +#define ARM_C0_PRIO_L2 0x0F000000
  4813. +#define ARM_C0_PRIO_UC 0xF0000000
  4814. +
  4815. +#define ARM_C0_APROTPASS 0x0000A000 /* Translate 1:1 */
  4816. +#define ARM_C0_APROTUSER 0x00000000 /* Only user mode */
  4817. +#define ARM_C0_APROTSYST 0x0000F000 /* Only system mode */
  4818. +
  4819. +
  4820. +#define ARM_CONTROL1 HW_REGISTER_RW(ARM_BASE+0x440)
  4821. +#define ARM_C1_TIMER 0x00000001 /* re-route timer IRQ to VC */
  4822. +#define ARM_C1_MAIL 0x00000002 /* re-route Mail IRQ to VC */
  4823. +#define ARM_C1_BELL0 0x00000004 /* re-route Doorbell 0 to VC */
  4824. +#define ARM_C1_BELL1 0x00000008 /* re-route Doorbell 1 to VC */
  4825. +#define ARM_C1_PERSON 0x00000100 /* peripherals on */
  4826. +#define ARM_C1_REQSTOP 0x00000200 /* ASYNC bridge request stop */
  4827. +
  4828. +#define ARM_STATUS HW_REGISTER_RW(ARM_BASE+0x444)
  4829. +#define ARM_S_ACKSTOP 0x80000000 /* Bridge stopped */
  4830. +#define ARM_S_READPEND 0x000003FF /* pending reads counter */
  4831. +#define ARM_S_WRITPEND 0x000FFC00 /* pending writes counter */
  4832. +
  4833. +#define ARM_ERRHALT HW_REGISTER_RW(ARM_BASE+0x448)
  4834. +#define ARM_EH_PERIBURST 0x00000001 /* Burst write seen on peri bus */
  4835. +#define ARM_EH_ILLADDRS1 0x00000002 /* Address bits 25-27 error */
  4836. +#define ARM_EH_ILLADDRS2 0x00000004 /* Address bits 31-28 error */
  4837. +#define ARM_EH_VPU0HALT 0x00000008 /* VPU0 halted & in debug mode */
  4838. +#define ARM_EH_VPU1HALT 0x00000010 /* VPU1 halted & in debug mode */
  4839. +#define ARM_EH_ARMHALT 0x00000020 /* ARM in halted debug mode */
  4840. +
  4841. +#define ARM_ID_SECURE HW_REGISTER_RW(ARM_BASE+0x00C)
  4842. +#define ARM_ID HW_REGISTER_RW(ARM_BASE+0x44C)
  4843. +#define ARM_IDVAL 0x364D5241
  4844. +
  4845. +/* Translation memory */
  4846. +#define ARM_TRANSLATE HW_REGISTER_RW(ARM_BASE+0x100)
  4847. +/* 32 locations: 0x100.. 0x17F */
  4848. +/* 32 spare means we CAN go to 64 pages.... */
  4849. +
  4850. +
  4851. +/* Interrupts */
  4852. +#define ARM_IRQ_PEND0 HW_REGISTER_RW(ARM_BASE+0x200) /* Top IRQ bits */
  4853. +#define ARM_I0_TIMER 0x00000001 /* timer IRQ */
  4854. +#define ARM_I0_MAIL 0x00000002 /* Mail IRQ */
  4855. +#define ARM_I0_BELL0 0x00000004 /* Doorbell 0 */
  4856. +#define ARM_I0_BELL1 0x00000008 /* Doorbell 1 */
  4857. +#define ARM_I0_BANK1 0x00000100 /* Bank1 IRQ */
  4858. +#define ARM_I0_BANK2 0x00000200 /* Bank2 IRQ */
  4859. +
  4860. +#define ARM_IRQ_PEND1 HW_REGISTER_RW(ARM_BASE+0x204) /* All bank1 IRQ bits */
  4861. +/* todo: all I1_interrupt sources */
  4862. +#define ARM_IRQ_PEND2 HW_REGISTER_RW(ARM_BASE+0x208) /* All bank2 IRQ bits */
  4863. +/* todo: all I2_interrupt sources */
  4864. +
  4865. +#define ARM_IRQ_FAST HW_REGISTER_RW(ARM_BASE+0x20C) /* FIQ control */
  4866. +#define ARM_IF_INDEX 0x0000007F /* FIQ select */
  4867. +#define ARM_IF_ENABLE 0x00000080 /* FIQ enable */
  4868. +#define ARM_IF_VCMASK 0x0000003F /* FIQ = (index from VC source) */
  4869. +#define ARM_IF_TIMER 0x00000040 /* FIQ = ARM timer */
  4870. +#define ARM_IF_MAIL 0x00000041 /* FIQ = ARM Mail */
  4871. +#define ARM_IF_BELL0 0x00000042 /* FIQ = ARM Doorbell 0 */
  4872. +#define ARM_IF_BELL1 0x00000043 /* FIQ = ARM Doorbell 1 */
  4873. +#define ARM_IF_VP0HALT 0x00000044 /* FIQ = VPU0 Halt seen */
  4874. +#define ARM_IF_VP1HALT 0x00000045 /* FIQ = VPU1 Halt seen */
  4875. +#define ARM_IF_ILLEGAL 0x00000046 /* FIQ = Illegal access seen */
  4876. +
  4877. +#define ARM_IRQ_ENBL1 HW_REGISTER_RW(ARM_BASE+0x210) /* Bank1 enable bits */
  4878. +#define ARM_IRQ_ENBL2 HW_REGISTER_RW(ARM_BASE+0x214) /* Bank2 enable bits */
  4879. +#define ARM_IRQ_ENBL3 HW_REGISTER_RW(ARM_BASE+0x218) /* ARM irqs enable bits */
  4880. +#define ARM_IRQ_DIBL1 HW_REGISTER_RW(ARM_BASE+0x21C) /* Bank1 disable bits */
  4881. +#define ARM_IRQ_DIBL2 HW_REGISTER_RW(ARM_BASE+0x220) /* Bank2 disable bits */
  4882. +#define ARM_IRQ_DIBL3 HW_REGISTER_RW(ARM_BASE+0x224) /* ARM irqs disable bits */
  4883. +#define ARM_IE_TIMER 0x00000001 /* Timer IRQ */
  4884. +#define ARM_IE_MAIL 0x00000002 /* Mail IRQ */
  4885. +#define ARM_IE_BELL0 0x00000004 /* Doorbell 0 */
  4886. +#define ARM_IE_BELL1 0x00000008 /* Doorbell 1 */
  4887. +#define ARM_IE_VP0HALT 0x00000010 /* VPU0 Halt */
  4888. +#define ARM_IE_VP1HALT 0x00000020 /* VPU1 Halt */
  4889. +#define ARM_IE_ILLEGAL 0x00000040 /* Illegal access seen */
  4890. +
  4891. +/* Timer */
  4892. +/* For reg. fields see sp804 spec. */
  4893. +#define ARM_T_LOAD HW_REGISTER_RW(ARM_BASE+0x400)
  4894. +#define ARM_T_VALUE HW_REGISTER_RW(ARM_BASE+0x404)
  4895. +#define ARM_T_CONTROL HW_REGISTER_RW(ARM_BASE+0x408)
  4896. +#define ARM_T_IRQCNTL HW_REGISTER_RW(ARM_BASE+0x40C)
  4897. +#define ARM_T_RAWIRQ HW_REGISTER_RW(ARM_BASE+0x410)
  4898. +#define ARM_T_MSKIRQ HW_REGISTER_RW(ARM_BASE+0x414)
  4899. +#define ARM_T_RELOAD HW_REGISTER_RW(ARM_BASE+0x418)
  4900. +#define ARM_T_PREDIV HW_REGISTER_RW(ARM_BASE+0x41c)
  4901. +#define ARM_T_FREECNT HW_REGISTER_RW(ARM_BASE+0x420)
  4902. +
  4903. +#define TIMER_CTRL_ONESHOT (1 << 0)
  4904. +#define TIMER_CTRL_32BIT (1 << 1)
  4905. +#define TIMER_CTRL_DIV1 (0 << 2)
  4906. +#define TIMER_CTRL_DIV16 (1 << 2)
  4907. +#define TIMER_CTRL_DIV256 (2 << 2)
  4908. +#define TIMER_CTRL_IE (1 << 5)
  4909. +#define TIMER_CTRL_PERIODIC (1 << 6)
  4910. +#define TIMER_CTRL_ENABLE (1 << 7)
  4911. +#define TIMER_CTRL_DBGHALT (1 << 8)
  4912. +#define TIMER_CTRL_ENAFREE (1 << 9)
  4913. +#define TIMER_CTRL_FREEDIV_SHIFT 16)
  4914. +#define TIMER_CTRL_FREEDIV_MASK 0xff
  4915. +
  4916. +/* Semaphores, Doorbells, Mailboxes */
  4917. +#define ARM_SBM_OWN0 (ARM_BASE+0x800)
  4918. +#define ARM_SBM_OWN1 (ARM_BASE+0x900)
  4919. +#define ARM_SBM_OWN2 (ARM_BASE+0xA00)
  4920. +#define ARM_SBM_OWN3 (ARM_BASE+0xB00)
  4921. +
  4922. +/* MAILBOXES
  4923. + * Register flags are common across all
  4924. + * owner registers. See end of this section
  4925. + *
  4926. + * Semaphores, Doorbells, Mailboxes Owner 0
  4927. + *
  4928. + */
  4929. +
  4930. +#define ARM_0_SEMS HW_REGISTER_RW(ARM_SBM_OWN0+0x00)
  4931. +#define ARM_0_SEM0 HW_REGISTER_RW(ARM_SBM_OWN0+0x00)
  4932. +#define ARM_0_SEM1 HW_REGISTER_RW(ARM_SBM_OWN0+0x04)
  4933. +#define ARM_0_SEM2 HW_REGISTER_RW(ARM_SBM_OWN0+0x08)
  4934. +#define ARM_0_SEM3 HW_REGISTER_RW(ARM_SBM_OWN0+0x0C)
  4935. +#define ARM_0_SEM4 HW_REGISTER_RW(ARM_SBM_OWN0+0x10)
  4936. +#define ARM_0_SEM5 HW_REGISTER_RW(ARM_SBM_OWN0+0x14)
  4937. +#define ARM_0_SEM6 HW_REGISTER_RW(ARM_SBM_OWN0+0x18)
  4938. +#define ARM_0_SEM7 HW_REGISTER_RW(ARM_SBM_OWN0+0x1C)
  4939. +#define ARM_0_BELL0 HW_REGISTER_RW(ARM_SBM_OWN0+0x40)
  4940. +#define ARM_0_BELL1 HW_REGISTER_RW(ARM_SBM_OWN0+0x44)
  4941. +#define ARM_0_BELL2 HW_REGISTER_RW(ARM_SBM_OWN0+0x48)
  4942. +#define ARM_0_BELL3 HW_REGISTER_RW(ARM_SBM_OWN0+0x4C)
  4943. +/* MAILBOX 0 access in Owner 0 area */
  4944. +/* Some addresses should ONLY be used by owner 0 */
  4945. +#define ARM_0_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN0+0x80) /* .. 0x8C (4 locations) */
  4946. +#define ARM_0_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN0+0x80) /* .. 0x8C (4 locations) Normal read */
  4947. +#define ARM_0_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN0+0x90) /* none-pop read */
  4948. +#define ARM_0_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN0+0x94) /* Sender read (only LS 2 bits) */
  4949. +#define ARM_0_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN0+0x98) /* Status read */
  4950. +#define ARM_0_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN0+0x9C) /* Config read/write */
  4951. +/* MAILBOX 1 access in Owner 0 area */
  4952. +/* Owner 0 should only WRITE to this mailbox */
  4953. +#define ARM_0_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN0+0xA0) /* .. 0xAC (4 locations) */
  4954. +/*#define ARM_0_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN0+0xA0) */ /* DO NOT USE THIS !!!!! */
  4955. +/*#define ARM_0_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN0+0xB0) */ /* DO NOT USE THIS !!!!! */
  4956. +/*#define ARM_0_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN0+0xB4) */ /* DO NOT USE THIS !!!!! */
  4957. +#define ARM_0_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN0+0xB8) /* Status read */
  4958. +/*#define ARM_0_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN0+0xBC) */ /* DO NOT USE THIS !!!!! */
  4959. +/* General SEM, BELL, MAIL config/status */
  4960. +#define ARM_0_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN0+0xE0) /* semaphore clear/debug register */
  4961. +#define ARM_0_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN0+0xE4) /* Doorbells clear/debug register */
  4962. +#define ARM_0_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN0+0xF8) /* ALL interrupts */
  4963. +#define ARM_0_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN0+0xFC) /* IRQS pending for owner 0 */
  4964. +
  4965. +/* Semaphores, Doorbells, Mailboxes Owner 1 */
  4966. +#define ARM_1_SEMS HW_REGISTER_RW(ARM_SBM_OWN1+0x00)
  4967. +#define ARM_1_SEM0 HW_REGISTER_RW(ARM_SBM_OWN1+0x00)
  4968. +#define ARM_1_SEM1 HW_REGISTER_RW(ARM_SBM_OWN1+0x04)
  4969. +#define ARM_1_SEM2 HW_REGISTER_RW(ARM_SBM_OWN1+0x08)
  4970. +#define ARM_1_SEM3 HW_REGISTER_RW(ARM_SBM_OWN1+0x0C)
  4971. +#define ARM_1_SEM4 HW_REGISTER_RW(ARM_SBM_OWN1+0x10)
  4972. +#define ARM_1_SEM5 HW_REGISTER_RW(ARM_SBM_OWN1+0x14)
  4973. +#define ARM_1_SEM6 HW_REGISTER_RW(ARM_SBM_OWN1+0x18)
  4974. +#define ARM_1_SEM7 HW_REGISTER_RW(ARM_SBM_OWN1+0x1C)
  4975. +#define ARM_1_BELL0 HW_REGISTER_RW(ARM_SBM_OWN1+0x40)
  4976. +#define ARM_1_BELL1 HW_REGISTER_RW(ARM_SBM_OWN1+0x44)
  4977. +#define ARM_1_BELL2 HW_REGISTER_RW(ARM_SBM_OWN1+0x48)
  4978. +#define ARM_1_BELL3 HW_REGISTER_RW(ARM_SBM_OWN1+0x4C)
  4979. +/* MAILBOX 0 access in Owner 0 area */
  4980. +/* Owner 1 should only WRITE to this mailbox */
  4981. +#define ARM_1_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN1+0x80) /* .. 0x8C (4 locations) */
  4982. +/*#define ARM_1_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN1+0x80) */ /* DO NOT USE THIS !!!!! */
  4983. +/*#define ARM_1_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN1+0x90) */ /* DO NOT USE THIS !!!!! */
  4984. +/*#define ARM_1_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN1+0x94) */ /* DO NOT USE THIS !!!!! */
  4985. +#define ARM_1_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN1+0x98) /* Status read */
  4986. +/*#define ARM_1_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN1+0x9C) */ /* DO NOT USE THIS !!!!! */
  4987. +/* MAILBOX 1 access in Owner 0 area */
  4988. +#define ARM_1_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN1+0xA0) /* .. 0xAC (4 locations) */
  4989. +#define ARM_1_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN1+0xA0) /* .. 0xAC (4 locations) Normal read */
  4990. +#define ARM_1_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN1+0xB0) /* none-pop read */
  4991. +#define ARM_1_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN1+0xB4) /* Sender read (only LS 2 bits) */
  4992. +#define ARM_1_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN1+0xB8) /* Status read */
  4993. +#define ARM_1_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN1+0xBC)
  4994. +/* General SEM, BELL, MAIL config/status */
  4995. +#define ARM_1_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN1+0xE0) /* semaphore clear/debug register */
  4996. +#define ARM_1_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN1+0xE4) /* Doorbells clear/debug register */
  4997. +#define ARM_1_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN1+0xFC) /* IRQS pending for owner 1 */
  4998. +#define ARM_1_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN1+0xF8) /* ALL interrupts */
  4999. +
  5000. +/* Semaphores, Doorbells, Mailboxes Owner 2 */
  5001. +#define ARM_2_SEMS HW_REGISTER_RW(ARM_SBM_OWN2+0x00)
  5002. +#define ARM_2_SEM0 HW_REGISTER_RW(ARM_SBM_OWN2+0x00)
  5003. +#define ARM_2_SEM1 HW_REGISTER_RW(ARM_SBM_OWN2+0x04)
  5004. +#define ARM_2_SEM2 HW_REGISTER_RW(ARM_SBM_OWN2+0x08)
  5005. +#define ARM_2_SEM3 HW_REGISTER_RW(ARM_SBM_OWN2+0x0C)
  5006. +#define ARM_2_SEM4 HW_REGISTER_RW(ARM_SBM_OWN2+0x10)
  5007. +#define ARM_2_SEM5 HW_REGISTER_RW(ARM_SBM_OWN2+0x14)
  5008. +#define ARM_2_SEM6 HW_REGISTER_RW(ARM_SBM_OWN2+0x18)
  5009. +#define ARM_2_SEM7 HW_REGISTER_RW(ARM_SBM_OWN2+0x1C)
  5010. +#define ARM_2_BELL0 HW_REGISTER_RW(ARM_SBM_OWN2+0x40)
  5011. +#define ARM_2_BELL1 HW_REGISTER_RW(ARM_SBM_OWN2+0x44)
  5012. +#define ARM_2_BELL2 HW_REGISTER_RW(ARM_SBM_OWN2+0x48)
  5013. +#define ARM_2_BELL3 HW_REGISTER_RW(ARM_SBM_OWN2+0x4C)
  5014. +/* MAILBOX 0 access in Owner 2 area */
  5015. +/* Owner 2 should only WRITE to this mailbox */
  5016. +#define ARM_2_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN2+0x80) /* .. 0x8C (4 locations) */
  5017. +/*#define ARM_2_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN2+0x80) */ /* DO NOT USE THIS !!!!! */
  5018. +/*#define ARM_2_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN2+0x90) */ /* DO NOT USE THIS !!!!! */
  5019. +/*#define ARM_2_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN2+0x94) */ /* DO NOT USE THIS !!!!! */
  5020. +#define ARM_2_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN2+0x98) /* Status read */
  5021. +/*#define ARM_2_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN2+0x9C) */ /* DO NOT USE THIS !!!!! */
  5022. +/* MAILBOX 1 access in Owner 2 area */
  5023. +/* Owner 2 should only WRITE to this mailbox */
  5024. +#define ARM_2_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN2+0xA0) /* .. 0xAC (4 locations) */
  5025. +/*#define ARM_2_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN2+0xA0) */ /* DO NOT USE THIS !!!!! */
  5026. +/*#define ARM_2_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN2+0xB0) */ /* DO NOT USE THIS !!!!! */
  5027. +/*#define ARM_2_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN2+0xB4) */ /* DO NOT USE THIS !!!!! */
  5028. +#define ARM_2_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN2+0xB8) /* Status read */
  5029. +/*#define ARM_2_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN2+0xBC) */ /* DO NOT USE THIS !!!!! */
  5030. +/* General SEM, BELL, MAIL config/status */
  5031. +#define ARM_2_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN2+0xE0) /* semaphore clear/debug register */
  5032. +#define ARM_2_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN2+0xE4) /* Doorbells clear/debug register */
  5033. +#define ARM_2_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN2+0xFC) /* IRQS pending for owner 2 */
  5034. +#define ARM_2_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN2+0xF8) /* ALL interrupts */
  5035. +
  5036. +/* Semaphores, Doorbells, Mailboxes Owner 3 */
  5037. +#define ARM_3_SEMS HW_REGISTER_RW(ARM_SBM_OWN3+0x00)
  5038. +#define ARM_3_SEM0 HW_REGISTER_RW(ARM_SBM_OWN3+0x00)
  5039. +#define ARM_3_SEM1 HW_REGISTER_RW(ARM_SBM_OWN3+0x04)
  5040. +#define ARM_3_SEM2 HW_REGISTER_RW(ARM_SBM_OWN3+0x08)
  5041. +#define ARM_3_SEM3 HW_REGISTER_RW(ARM_SBM_OWN3+0x0C)
  5042. +#define ARM_3_SEM4 HW_REGISTER_RW(ARM_SBM_OWN3+0x10)
  5043. +#define ARM_3_SEM5 HW_REGISTER_RW(ARM_SBM_OWN3+0x14)
  5044. +#define ARM_3_SEM6 HW_REGISTER_RW(ARM_SBM_OWN3+0x18)
  5045. +#define ARM_3_SEM7 HW_REGISTER_RW(ARM_SBM_OWN3+0x1C)
  5046. +#define ARM_3_BELL0 HW_REGISTER_RW(ARM_SBM_OWN3+0x40)
  5047. +#define ARM_3_BELL1 HW_REGISTER_RW(ARM_SBM_OWN3+0x44)
  5048. +#define ARM_3_BELL2 HW_REGISTER_RW(ARM_SBM_OWN3+0x48)
  5049. +#define ARM_3_BELL3 HW_REGISTER_RW(ARM_SBM_OWN3+0x4C)
  5050. +/* MAILBOX 0 access in Owner 3 area */
  5051. +/* Owner 3 should only WRITE to this mailbox */
  5052. +#define ARM_3_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN3+0x80) /* .. 0x8C (4 locations) */
  5053. +/*#define ARM_3_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN3+0x80) */ /* DO NOT USE THIS !!!!! */
  5054. +/*#define ARM_3_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN3+0x90) */ /* DO NOT USE THIS !!!!! */
  5055. +/*#define ARM_3_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN3+0x94) */ /* DO NOT USE THIS !!!!! */
  5056. +#define ARM_3_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN3+0x98) /* Status read */
  5057. +/*#define ARM_3_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN3+0x9C) */ /* DO NOT USE THIS !!!!! */
  5058. +/* MAILBOX 1 access in Owner 3 area */
  5059. +/* Owner 3 should only WRITE to this mailbox */
  5060. +#define ARM_3_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN3+0xA0) /* .. 0xAC (4 locations) */
  5061. +/*#define ARM_3_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN3+0xA0) */ /* DO NOT USE THIS !!!!! */
  5062. +/*#define ARM_3_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN3+0xB0) */ /* DO NOT USE THIS !!!!! */
  5063. +/*#define ARM_3_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN3+0xB4) */ /* DO NOT USE THIS !!!!! */
  5064. +#define ARM_3_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN3+0xB8) /* Status read */
  5065. +/*#define ARM_3_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN3+0xBC) */ /* DO NOT USE THIS !!!!! */
  5066. +/* General SEM, BELL, MAIL config/status */
  5067. +#define ARM_3_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN3+0xE0) /* semaphore clear/debug register */
  5068. +#define ARM_3_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN3+0xE4) /* Doorbells clear/debug register */
  5069. +#define ARM_3_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN3+0xFC) /* IRQS pending for owner 3 */
  5070. +#define ARM_3_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN3+0xF8) /* ALL interrupts */
  5071. +
  5072. +
  5073. +
  5074. +/* Mailbox flags. Valid for all owners */
  5075. +
  5076. +/* Mailbox status register (...0x98) */
  5077. +#define ARM_MS_FULL 0x80000000
  5078. +#define ARM_MS_EMPTY 0x40000000
  5079. +#define ARM_MS_LEVEL 0x400000FF /* Max. value depdnds on mailbox depth parameter */
  5080. +
  5081. +/* MAILBOX config/status register (...0x9C) */
  5082. +/* ANY write to this register clears the error bits! */
  5083. +#define ARM_MC_IHAVEDATAIRQEN 0x00000001 /* mailbox irq enable: has data */
  5084. +#define ARM_MC_IHAVESPACEIRQEN 0x00000002 /* mailbox irq enable: has space */
  5085. +#define ARM_MC_OPPISEMPTYIRQEN 0x00000004 /* mailbox irq enable: Opp. is empty */
  5086. +#define ARM_MC_MAIL_CLEAR 0x00000008 /* mailbox clear write 1, then 0 */
  5087. +#define ARM_MC_IHAVEDATAIRQPEND 0x00000010 /* mailbox irq pending: has space */
  5088. +#define ARM_MC_IHAVESPACEIRQPEND 0x00000020 /* mailbox irq pending: Opp. is empty */
  5089. +#define ARM_MC_OPPISEMPTYIRQPEND 0x00000040 /* mailbox irq pending */
  5090. +/* Bit 7 is unused */
  5091. +#define ARM_MC_ERRNOOWN 0x00000100 /* error : none owner read from mailbox */
  5092. +#define ARM_MC_ERROVERFLW 0x00000200 /* error : write to fill mailbox */
  5093. +#define ARM_MC_ERRUNDRFLW 0x00000400 /* error : read from empty mailbox */
  5094. +
  5095. +/* Semaphore clear/debug register (...0xE0) */
  5096. +#define ARM_SD_OWN0 0x00000003 /* Owner of sem 0 */
  5097. +#define ARM_SD_OWN1 0x0000000C /* Owner of sem 1 */
  5098. +#define ARM_SD_OWN2 0x00000030 /* Owner of sem 2 */
  5099. +#define ARM_SD_OWN3 0x000000C0 /* Owner of sem 3 */
  5100. +#define ARM_SD_OWN4 0x00000300 /* Owner of sem 4 */
  5101. +#define ARM_SD_OWN5 0x00000C00 /* Owner of sem 5 */
  5102. +#define ARM_SD_OWN6 0x00003000 /* Owner of sem 6 */
  5103. +#define ARM_SD_OWN7 0x0000C000 /* Owner of sem 7 */
  5104. +#define ARM_SD_SEM0 0x00010000 /* Status of sem 0 */
  5105. +#define ARM_SD_SEM1 0x00020000 /* Status of sem 1 */
  5106. +#define ARM_SD_SEM2 0x00040000 /* Status of sem 2 */
  5107. +#define ARM_SD_SEM3 0x00080000 /* Status of sem 3 */
  5108. +#define ARM_SD_SEM4 0x00100000 /* Status of sem 4 */
  5109. +#define ARM_SD_SEM5 0x00200000 /* Status of sem 5 */
  5110. +#define ARM_SD_SEM6 0x00400000 /* Status of sem 6 */
  5111. +#define ARM_SD_SEM7 0x00800000 /* Status of sem 7 */
  5112. +
  5113. +/* Doorbells clear/debug register (...0xE4) */
  5114. +#define ARM_BD_OWN0 0x00000003 /* Owner of doorbell 0 */
  5115. +#define ARM_BD_OWN1 0x0000000C /* Owner of doorbell 1 */
  5116. +#define ARM_BD_OWN2 0x00000030 /* Owner of doorbell 2 */
  5117. +#define ARM_BD_OWN3 0x000000C0 /* Owner of doorbell 3 */
  5118. +#define ARM_BD_BELL0 0x00000100 /* Status of doorbell 0 */
  5119. +#define ARM_BD_BELL1 0x00000200 /* Status of doorbell 1 */
  5120. +#define ARM_BD_BELL2 0x00000400 /* Status of doorbell 2 */
  5121. +#define ARM_BD_BELL3 0x00000800 /* Status of doorbell 3 */
  5122. +
  5123. +/* MY IRQS register (...0xF8) */
  5124. +#define ARM_MYIRQ_BELL 0x00000001 /* This owner has a doorbell IRQ */
  5125. +#define ARM_MYIRQ_MAIL 0x00000002 /* This owner has a mailbox IRQ */
  5126. +
  5127. +/* ALL IRQS register (...0xF8) */
  5128. +#define ARM_AIS_BELL0 0x00000001 /* Doorbell 0 IRQ pending */
  5129. +#define ARM_AIS_BELL1 0x00000002 /* Doorbell 1 IRQ pending */
  5130. +#define ARM_AIS_BELL2 0x00000004 /* Doorbell 2 IRQ pending */
  5131. +#define ARM_AIS_BELL3 0x00000008 /* Doorbell 3 IRQ pending */
  5132. +#define ARM_AIS0_HAVEDATA 0x00000010 /* MAIL 0 has data IRQ pending */
  5133. +#define ARM_AIS0_HAVESPAC 0x00000020 /* MAIL 0 has space IRQ pending */
  5134. +#define ARM_AIS0_OPPEMPTY 0x00000040 /* MAIL 0 opposite is empty IRQ */
  5135. +#define ARM_AIS1_HAVEDATA 0x00000080 /* MAIL 1 has data IRQ pending */
  5136. +#define ARM_AIS1_HAVESPAC 0x00000100 /* MAIL 1 has space IRQ pending */
  5137. +#define ARM_AIS1_OPPEMPTY 0x00000200 /* MAIL 1 opposite is empty IRQ */
  5138. +/* Note that bell-0, bell-1 and MAIL0 IRQ go only to the ARM */
  5139. +/* Whilst that bell-2, bell-3 and MAIL1 IRQ go only to the VC */
  5140. +/* */
  5141. +/* ARM JTAG BASH */
  5142. +/* */
  5143. +#define AJB_BASE 0x7e2000c0
  5144. +
  5145. +#define AJBCONF HW_REGISTER_RW(AJB_BASE+0x00)
  5146. +#define AJB_BITS0 0x000000
  5147. +#define AJB_BITS4 0x000004
  5148. +#define AJB_BITS8 0x000008
  5149. +#define AJB_BITS12 0x00000C
  5150. +#define AJB_BITS16 0x000010
  5151. +#define AJB_BITS20 0x000014
  5152. +#define AJB_BITS24 0x000018
  5153. +#define AJB_BITS28 0x00001C
  5154. +#define AJB_BITS32 0x000020
  5155. +#define AJB_BITS34 0x000022
  5156. +#define AJB_OUT_MS 0x000040
  5157. +#define AJB_OUT_LS 0x000000
  5158. +#define AJB_INV_CLK 0x000080
  5159. +#define AJB_D0_RISE 0x000100
  5160. +#define AJB_D0_FALL 0x000000
  5161. +#define AJB_D1_RISE 0x000200
  5162. +#define AJB_D1_FALL 0x000000
  5163. +#define AJB_IN_RISE 0x000400
  5164. +#define AJB_IN_FALL 0x000000
  5165. +#define AJB_ENABLE 0x000800
  5166. +#define AJB_HOLD0 0x000000
  5167. +#define AJB_HOLD1 0x001000
  5168. +#define AJB_HOLD2 0x002000
  5169. +#define AJB_HOLD3 0x003000
  5170. +#define AJB_RESETN 0x004000
  5171. +#define AJB_CLKSHFT 16
  5172. +#define AJB_BUSY 0x80000000
  5173. +#define AJBTMS HW_REGISTER_RW(AJB_BASE+0x04)
  5174. +#define AJBTDI HW_REGISTER_RW(AJB_BASE+0x08)
  5175. +#define AJBTDO HW_REGISTER_RW(AJB_BASE+0x0c)
  5176. +
  5177. +#endif
  5178. diff -Nur linux-3.13.3.orig/arch/arm/mach-bcm2708/include/mach/arm_power.h linux-3.13.3/arch/arm/mach-bcm2708/include/mach/arm_power.h
  5179. --- linux-3.13.3.orig/arch/arm/mach-bcm2708/include/mach/arm_power.h 1970-01-01 01:00:00.000000000 +0100
  5180. +++ linux-3.13.3/arch/arm/mach-bcm2708/include/mach/arm_power.h 2014-02-17 22:41:01.000000000 +0100
  5181. @@ -0,0 +1,60 @@
  5182. +/*
  5183. + * linux/arch/arm/mach-bcm2708/include/mach/arm_power.h
  5184. + *
  5185. + * Copyright (C) 2010 Broadcom
  5186. + *
  5187. + * This program is free software; you can redistribute it and/or modify
  5188. + * it under the terms of the GNU General Public License as published by
  5189. + * the Free Software Foundation; either version 2 of the License, or
  5190. + * (at your option) any later version.
  5191. + *
  5192. + * This program is distributed in the hope that it will be useful,
  5193. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5194. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5195. + * GNU General Public License for more details.
  5196. + *
  5197. + * You should have received a copy of the GNU General Public License
  5198. + * along with this program; if not, write to the Free Software
  5199. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5200. + */
  5201. +
  5202. +#ifndef _ARM_POWER_H
  5203. +#define _ARM_POWER_H
  5204. +
  5205. +/* Use meaningful names on each side */
  5206. +#ifdef __VIDEOCORE__
  5207. +#define PREFIX(x) ARM_##x
  5208. +#else
  5209. +#define PREFIX(x) BCM_##x
  5210. +#endif
  5211. +
  5212. +enum {
  5213. + PREFIX(POWER_SDCARD_BIT),
  5214. + PREFIX(POWER_UART_BIT),
  5215. + PREFIX(POWER_MINIUART_BIT),
  5216. + PREFIX(POWER_USB_BIT),
  5217. + PREFIX(POWER_I2C0_BIT),
  5218. + PREFIX(POWER_I2C1_BIT),
  5219. + PREFIX(POWER_I2C2_BIT),
  5220. + PREFIX(POWER_SPI_BIT),
  5221. + PREFIX(POWER_CCP2TX_BIT),
  5222. +
  5223. + PREFIX(POWER_MAX)
  5224. +};
  5225. +
  5226. +enum {
  5227. + PREFIX(POWER_SDCARD) = (1 << PREFIX(POWER_SDCARD_BIT)),
  5228. + PREFIX(POWER_UART) = (1 << PREFIX(POWER_UART_BIT)),
  5229. + PREFIX(POWER_MINIUART) = (1 << PREFIX(POWER_MINIUART_BIT)),
  5230. + PREFIX(POWER_USB) = (1 << PREFIX(POWER_USB_BIT)),
  5231. + PREFIX(POWER_I2C0) = (1 << PREFIX(POWER_I2C0_BIT)),
  5232. + PREFIX(POWER_I2C1_MASK) = (1 << PREFIX(POWER_I2C1_BIT)),
  5233. + PREFIX(POWER_I2C2_MASK) = (1 << PREFIX(POWER_I2C2_BIT)),
  5234. + PREFIX(POWER_SPI_MASK) = (1 << PREFIX(POWER_SPI_BIT)),
  5235. + PREFIX(POWER_CCP2TX_MASK) = (1 << PREFIX(POWER_CCP2TX_BIT)),
  5236. +
  5237. + PREFIX(POWER_MASK) = (1 << PREFIX(POWER_MAX)) - 1,
  5238. + PREFIX(POWER_NONE) = 0
  5239. +};
  5240. +
  5241. +#endif
  5242. diff -Nur linux-3.13.3.orig/arch/arm/mach-bcm2708/include/mach/clkdev.h linux-3.13.3/arch/arm/mach-bcm2708/include/mach/clkdev.h
  5243. --- linux-3.13.3.orig/arch/arm/mach-bcm2708/include/mach/clkdev.h 1970-01-01 01:00:00.000000000 +0100
  5244. +++ linux-3.13.3/arch/arm/mach-bcm2708/include/mach/clkdev.h 2014-02-17 22:41:01.000000000 +0100
  5245. @@ -0,0 +1,7 @@
  5246. +#ifndef __ASM_MACH_CLKDEV_H
  5247. +#define __ASM_MACH_CLKDEV_H
  5248. +
  5249. +#define __clk_get(clk) ({ 1; })
  5250. +#define __clk_put(clk) do { } while (0)
  5251. +
  5252. +#endif
  5253. diff -Nur linux-3.13.3.orig/arch/arm/mach-bcm2708/include/mach/debug-macro.S linux-3.13.3/arch/arm/mach-bcm2708/include/mach/debug-macro.S
  5254. --- linux-3.13.3.orig/arch/arm/mach-bcm2708/include/mach/debug-macro.S 1970-01-01 01:00:00.000000000 +0100
  5255. +++ linux-3.13.3/arch/arm/mach-bcm2708/include/mach/debug-macro.S 2014-02-17 22:41:01.000000000 +0100
  5256. @@ -0,0 +1,22 @@
  5257. +/* arch/arm/mach-bcm2708/include/mach/debug-macro.S
  5258. + *
  5259. + * Debugging macro include header
  5260. + *
  5261. + * Copyright (C) 2010 Broadcom
  5262. + * Copyright (C) 1994-1999 Russell King
  5263. + * Moved from linux/arch/arm/kernel/debug.S by Ben Dooks
  5264. + *
  5265. + * This program is free software; you can redistribute it and/or modify
  5266. + * it under the terms of the GNU General Public License version 2 as
  5267. + * published by the Free Software Foundation.
  5268. + *
  5269. +*/
  5270. +
  5271. +#include <mach/platform.h>
  5272. +
  5273. + .macro addruart, rp, rv, tmp
  5274. + ldr \rp, =UART0_BASE
  5275. + ldr \rv, =IO_ADDRESS(UART0_BASE)
  5276. + .endm
  5277. +
  5278. +#include <debug/pl01x.S>
  5279. diff -Nur linux-3.13.3.orig/arch/arm/mach-bcm2708/include/mach/dma.h linux-3.13.3/arch/arm/mach-bcm2708/include/mach/dma.h
  5280. --- linux-3.13.3.orig/arch/arm/mach-bcm2708/include/mach/dma.h 1970-01-01 01:00:00.000000000 +0100
  5281. +++ linux-3.13.3/arch/arm/mach-bcm2708/include/mach/dma.h 2014-02-17 22:41:01.000000000 +0100
  5282. @@ -0,0 +1,90 @@
  5283. +/*
  5284. + * linux/arch/arm/mach-bcm2708/include/mach/dma.h
  5285. + *
  5286. + * Copyright (C) 2010 Broadcom
  5287. + *
  5288. + * This program is free software; you can redistribute it and/or modify
  5289. + * it under the terms of the GNU General Public License version 2 as
  5290. + * published by the Free Software Foundation.
  5291. + */
  5292. +
  5293. +
  5294. +#ifndef _MACH_BCM2708_DMA_H
  5295. +#define _MACH_BCM2708_DMA_H
  5296. +
  5297. +#define BCM_DMAMAN_DRIVER_NAME "bcm2708_dma"
  5298. +
  5299. +/* DMA CS Control and Status bits */
  5300. +#define BCM2708_DMA_ACTIVE (1 << 0)
  5301. +#define BCM2708_DMA_INT (1 << 2)
  5302. +#define BCM2708_DMA_ISPAUSED (1 << 4) /* Pause requested or not active */
  5303. +#define BCM2708_DMA_ISHELD (1 << 5) /* Is held by DREQ flow control */
  5304. +#define BCM2708_DMA_ERR (1 << 8)
  5305. +#define BCM2708_DMA_ABORT (1 << 30) /* stop current CB, go to next, WO */
  5306. +#define BCM2708_DMA_RESET (1 << 31) /* WO, self clearing */
  5307. +
  5308. +/* DMA control block "info" field bits */
  5309. +#define BCM2708_DMA_INT_EN (1 << 0)
  5310. +#define BCM2708_DMA_TDMODE (1 << 1)
  5311. +#define BCM2708_DMA_WAIT_RESP (1 << 3)
  5312. +#define BCM2708_DMA_D_INC (1 << 4)
  5313. +#define BCM2708_DMA_D_WIDTH (1 << 5)
  5314. +#define BCM2708_DMA_D_DREQ (1 << 6)
  5315. +#define BCM2708_DMA_S_INC (1 << 8)
  5316. +#define BCM2708_DMA_S_WIDTH (1 << 9)
  5317. +#define BCM2708_DMA_S_DREQ (1 << 10)
  5318. +
  5319. +#define BCM2708_DMA_BURST(x) (((x)&0xf) << 12)
  5320. +#define BCM2708_DMA_PER_MAP(x) ((x) << 16)
  5321. +#define BCM2708_DMA_WAITS(x) (((x)&0x1f) << 21)
  5322. +
  5323. +#define BCM2708_DMA_DREQ_EMMC 11
  5324. +#define BCM2708_DMA_DREQ_SDHOST 13
  5325. +
  5326. +#define BCM2708_DMA_CS 0x00 /* Control and Status */
  5327. +#define BCM2708_DMA_ADDR 0x04
  5328. +/* the current control block appears in the following registers - read only */
  5329. +#define BCM2708_DMA_INFO 0x08
  5330. +#define BCM2708_DMA_SOURCE_AD 0x0c
  5331. +#define BCM2708_DMA_DEST_AD 0x10
  5332. +#define BCM2708_DMA_NEXTCB 0x1C
  5333. +#define BCM2708_DMA_DEBUG 0x20
  5334. +
  5335. +#define BCM2708_DMA4_CS (BCM2708_DMA_CHAN(4)+BCM2708_DMA_CS)
  5336. +#define BCM2708_DMA4_ADDR (BCM2708_DMA_CHAN(4)+BCM2708_DMA_ADDR)
  5337. +
  5338. +#define BCM2708_DMA_TDMODE_LEN(w, h) ((h) << 16 | (w))
  5339. +
  5340. +struct bcm2708_dma_cb {
  5341. + unsigned long info;
  5342. + unsigned long src;
  5343. + unsigned long dst;
  5344. + unsigned long length;
  5345. + unsigned long stride;
  5346. + unsigned long next;
  5347. + unsigned long pad[2];
  5348. +};
  5349. +struct scatterlist;
  5350. +
  5351. +extern int bcm_sg_suitable_for_dma(struct scatterlist *sg_ptr, int sg_len);
  5352. +extern void bcm_dma_start(void __iomem *dma_chan_base,
  5353. + dma_addr_t control_block);
  5354. +extern void bcm_dma_wait_idle(void __iomem *dma_chan_base);
  5355. +extern bool bcm_dma_is_busy(void __iomem *dma_chan_base);
  5356. +extern int /*rc*/ bcm_dma_abort(void __iomem *dma_chan_base);
  5357. +
  5358. +/* When listing features we can ask for when allocating DMA channels give
  5359. + those with higher priority smaller ordinal numbers */
  5360. +#define BCM_DMA_FEATURE_FAST_ORD 0
  5361. +#define BCM_DMA_FEATURE_BULK_ORD 1
  5362. +#define BCM_DMA_FEATURE_FAST (1<<BCM_DMA_FEATURE_FAST_ORD)
  5363. +#define BCM_DMA_FEATURE_BULK (1<<BCM_DMA_FEATURE_BULK_ORD)
  5364. +#define BCM_DMA_FEATURE_COUNT 2
  5365. +
  5366. +/* return channel no or -ve error */
  5367. +extern int bcm_dma_chan_alloc(unsigned preferred_feature_set,
  5368. + void __iomem **out_dma_base, int *out_dma_irq);
  5369. +extern int bcm_dma_chan_free(int channel);
  5370. +
  5371. +
  5372. +#endif /* _MACH_BCM2708_DMA_H */
  5373. diff -Nur linux-3.13.3.orig/arch/arm/mach-bcm2708/include/mach/entry-macro.S linux-3.13.3/arch/arm/mach-bcm2708/include/mach/entry-macro.S
  5374. --- linux-3.13.3.orig/arch/arm/mach-bcm2708/include/mach/entry-macro.S 1970-01-01 01:00:00.000000000 +0100
  5375. +++ linux-3.13.3/arch/arm/mach-bcm2708/include/mach/entry-macro.S 2014-02-17 22:41:01.000000000 +0100
  5376. @@ -0,0 +1,69 @@
  5377. +/*
  5378. + * arch/arm/mach-bcm2708/include/mach/entry-macro.S
  5379. + *
  5380. + * Low-level IRQ helper macros for BCM2708 platforms
  5381. + *
  5382. + * Copyright (C) 2010 Broadcom
  5383. + *
  5384. + * This program is free software; you can redistribute it and/or modify
  5385. + * it under the terms of the GNU General Public License as published by
  5386. + * the Free Software Foundation; either version 2 of the License, or
  5387. + * (at your option) any later version.
  5388. + *
  5389. + * This program is distributed in the hope that it will be useful,
  5390. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5391. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5392. + * GNU General Public License for more details.
  5393. + *
  5394. + * You should have received a copy of the GNU General Public License
  5395. + * along with this program; if not, write to the Free Software
  5396. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5397. + */
  5398. +#include <mach/hardware.h>
  5399. +
  5400. + .macro disable_fiq
  5401. + .endm
  5402. +
  5403. + .macro get_irqnr_preamble, base, tmp
  5404. + ldr \base, =IO_ADDRESS(ARMCTRL_IC_BASE)
  5405. + .endm
  5406. +
  5407. + .macro arch_ret_to_user, tmp1, tmp2
  5408. + .endm
  5409. +
  5410. + .macro get_irqnr_and_base, irqnr, irqstat, base, tmp
  5411. + /* get masked status */
  5412. + ldr \irqstat, [\base, #(ARM_IRQ_PEND0 - ARMCTRL_IC_BASE)]
  5413. + mov \irqnr, #(ARM_IRQ0_BASE + 31)
  5414. + and \tmp, \irqstat, #0x300 @ save bits 8 and 9
  5415. + /* clear bits 8 and 9, and test */
  5416. + bics \irqstat, \irqstat, #0x300
  5417. + bne 1010f
  5418. +
  5419. + tst \tmp, #0x100
  5420. + ldrne \irqstat, [\base, #(ARM_IRQ_PEND1 - ARMCTRL_IC_BASE)]
  5421. + movne \irqnr, #(ARM_IRQ1_BASE + 31)
  5422. + @ Mask out the interrupts also present in PEND0 - see SW-5809
  5423. + bicne \irqstat, #((1<<7) | (1<<9) | (1<<10))
  5424. + bicne \irqstat, #((1<<18) | (1<<19))
  5425. + bne 1010f
  5426. +
  5427. + tst \tmp, #0x200
  5428. + ldrne \irqstat, [\base, #(ARM_IRQ_PEND2 - ARMCTRL_IC_BASE)]
  5429. + movne \irqnr, #(ARM_IRQ2_BASE + 31)
  5430. + @ Mask out the interrupts also present in PEND0 - see SW-5809
  5431. + bicne \irqstat, #((1<<21) | (1<<22) | (1<<23) | (1<<24) | (1<<25))
  5432. + bicne \irqstat, #((1<<30))
  5433. + beq 1020f
  5434. +
  5435. +1010:
  5436. + @ For non-zero x, LSB(x) = 31 - CLZ(x^(x-1))
  5437. + @ N.B. CLZ is an ARM5 instruction.
  5438. + sub \tmp, \irqstat, #1
  5439. + eor \irqstat, \irqstat, \tmp
  5440. + clz \tmp, \irqstat
  5441. + sub \irqnr, \tmp
  5442. +
  5443. +1020: @ EQ will be set if no irqs pending
  5444. +
  5445. + .endm
  5446. diff -Nur linux-3.13.3.orig/arch/arm/mach-bcm2708/include/mach/frc.h linux-3.13.3/arch/arm/mach-bcm2708/include/mach/frc.h
  5447. --- linux-3.13.3.orig/arch/arm/mach-bcm2708/include/mach/frc.h 1970-01-01 01:00:00.000000000 +0100
  5448. +++ linux-3.13.3/arch/arm/mach-bcm2708/include/mach/frc.h 2014-02-17 22:41:01.000000000 +0100
  5449. @@ -0,0 +1,38 @@
  5450. +/*
  5451. + * arch/arm/mach-bcm2708/include/mach/timex.h
  5452. + *
  5453. + * BCM2708 free running counter (timer)
  5454. + *
  5455. + * Copyright (C) 2010 Broadcom
  5456. + *
  5457. + * This program is free software; you can redistribute it and/or modify
  5458. + * it under the terms of the GNU General Public License as published by
  5459. + * the Free Software Foundation; either version 2 of the License, or
  5460. + * (at your option) any later version.
  5461. + *
  5462. + * This program is distributed in the hope that it will be useful,
  5463. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5464. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5465. + * GNU General Public License for more details.
  5466. + *
  5467. + * You should have received a copy of the GNU General Public License
  5468. + * along with this program; if not, write to the Free Software
  5469. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5470. + */
  5471. +
  5472. +#ifndef _MACH_FRC_H
  5473. +#define _MACH_FRC_H
  5474. +
  5475. +#define FRC_TICK_RATE (1000000)
  5476. +
  5477. +/*! Free running counter incrementing at the CLOCK_TICK_RATE
  5478. + (slightly faster than frc_clock_ticks63()
  5479. + */
  5480. +extern unsigned long frc_clock_ticks32(void);
  5481. +
  5482. +/*! Free running counter incrementing at the CLOCK_TICK_RATE
  5483. + * Note - top bit should be ignored (see cnt32_to_63)
  5484. + */
  5485. +extern unsigned long long frc_clock_ticks63(void);
  5486. +
  5487. +#endif
  5488. diff -Nur linux-3.13.3.orig/arch/arm/mach-bcm2708/include/mach/gpio.h linux-3.13.3/arch/arm/mach-bcm2708/include/mach/gpio.h
  5489. --- linux-3.13.3.orig/arch/arm/mach-bcm2708/include/mach/gpio.h 1970-01-01 01:00:00.000000000 +0100
  5490. +++ linux-3.13.3/arch/arm/mach-bcm2708/include/mach/gpio.h 2014-02-17 22:41:01.000000000 +0100
  5491. @@ -0,0 +1,17 @@
  5492. +/*
  5493. + * arch/arm/mach-bcm2708/include/mach/gpio.h
  5494. + *
  5495. + * This file is licensed under the terms of the GNU General Public
  5496. + * License version 2. This program is licensed "as is" without any
  5497. + * warranty of any kind, whether express or implied.
  5498. + */
  5499. +
  5500. +#ifndef __ASM_ARCH_GPIO_H
  5501. +#define __ASM_ARCH_GPIO_H
  5502. +
  5503. +#define ARCH_NR_GPIOS 54 // number of gpio lines
  5504. +
  5505. +#define gpio_to_irq(x) ((x) + GPIO_IRQ_START)
  5506. +#define irq_to_gpio(x) ((x) - GPIO_IRQ_START)
  5507. +
  5508. +#endif
  5509. diff -Nur linux-3.13.3.orig/arch/arm/mach-bcm2708/include/mach/hardware.h linux-3.13.3/arch/arm/mach-bcm2708/include/mach/hardware.h
  5510. --- linux-3.13.3.orig/arch/arm/mach-bcm2708/include/mach/hardware.h 1970-01-01 01:00:00.000000000 +0100
  5511. +++ linux-3.13.3/arch/arm/mach-bcm2708/include/mach/hardware.h 2014-02-17 22:41:01.000000000 +0100
  5512. @@ -0,0 +1,28 @@
  5513. +/*
  5514. + * arch/arm/mach-bcm2708/include/mach/hardware.h
  5515. + *
  5516. + * This file contains the hardware definitions of the BCM2708 devices.
  5517. + *
  5518. + * Copyright (C) 2010 Broadcom
  5519. + *
  5520. + * This program is free software; you can redistribute it and/or modify
  5521. + * it under the terms of the GNU General Public License as published by
  5522. + * the Free Software Foundation; either version 2 of the License, or
  5523. + * (at your option) any later version.
  5524. + *
  5525. + * This program is distributed in the hope that it will be useful,
  5526. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5527. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5528. + * GNU General Public License for more details.
  5529. + *
  5530. + * You should have received a copy of the GNU General Public License
  5531. + * along with this program; if not, write to the Free Software
  5532. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5533. + */
  5534. +#ifndef __ASM_ARCH_HARDWARE_H
  5535. +#define __ASM_ARCH_HARDWARE_H
  5536. +
  5537. +#include <asm/sizes.h>
  5538. +#include <mach/platform.h>
  5539. +
  5540. +#endif
  5541. diff -Nur linux-3.13.3.orig/arch/arm/mach-bcm2708/include/mach/io.h linux-3.13.3/arch/arm/mach-bcm2708/include/mach/io.h
  5542. --- linux-3.13.3.orig/arch/arm/mach-bcm2708/include/mach/io.h 1970-01-01 01:00:00.000000000 +0100
  5543. +++ linux-3.13.3/arch/arm/mach-bcm2708/include/mach/io.h 2014-02-17 22:41:01.000000000 +0100
  5544. @@ -0,0 +1,27 @@
  5545. +/*
  5546. + * arch/arm/mach-bcm2708/include/mach/io.h
  5547. + *
  5548. + * Copyright (C) 2003 ARM Limited
  5549. + *
  5550. + * This program is free software; you can redistribute it and/or modify
  5551. + * it under the terms of the GNU General Public License as published by
  5552. + * the Free Software Foundation; either version 2 of the License, or
  5553. + * (at your option) any later version.
  5554. + *
  5555. + * This program is distributed in the hope that it will be useful,
  5556. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5557. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5558. + * GNU General Public License for more details.
  5559. + *
  5560. + * You should have received a copy of the GNU General Public License
  5561. + * along with this program; if not, write to the Free Software
  5562. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5563. + */
  5564. +#ifndef __ASM_ARM_ARCH_IO_H
  5565. +#define __ASM_ARM_ARCH_IO_H
  5566. +
  5567. +#define IO_SPACE_LIMIT 0xffffffff
  5568. +
  5569. +#define __io(a) __typesafe_io(a)
  5570. +
  5571. +#endif
  5572. diff -Nur linux-3.13.3.orig/arch/arm/mach-bcm2708/include/mach/irqs.h linux-3.13.3/arch/arm/mach-bcm2708/include/mach/irqs.h
  5573. --- linux-3.13.3.orig/arch/arm/mach-bcm2708/include/mach/irqs.h 1970-01-01 01:00:00.000000000 +0100
  5574. +++ linux-3.13.3/arch/arm/mach-bcm2708/include/mach/irqs.h 2014-02-17 22:41:01.000000000 +0100
  5575. @@ -0,0 +1,199 @@
  5576. +/*
  5577. + * arch/arm/mach-bcm2708/include/mach/irqs.h
  5578. + *
  5579. + * Copyright (C) 2010 Broadcom
  5580. + * Copyright (C) 2003 ARM Limited
  5581. + * Copyright (C) 2000 Deep Blue Solutions Ltd.
  5582. + *
  5583. + * This program is free software; you can redistribute it and/or modify
  5584. + * it under the terms of the GNU General Public License as published by
  5585. + * the Free Software Foundation; either version 2 of the License, or
  5586. + * (at your option) any later version.
  5587. + *
  5588. + * This program is distributed in the hope that it will be useful,
  5589. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5590. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5591. + * GNU General Public License for more details.
  5592. + *
  5593. + * You should have received a copy of the GNU General Public License
  5594. + * along with this program; if not, write to the Free Software
  5595. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5596. + */
  5597. +
  5598. +#ifndef _BCM2708_IRQS_H_
  5599. +#define _BCM2708_IRQS_H_
  5600. +
  5601. +#include <mach/platform.h>
  5602. +
  5603. +/*
  5604. + * IRQ interrupts definitions are the same as the INT definitions
  5605. + * held within platform.h
  5606. + */
  5607. +#define IRQ_ARMCTRL_START 0
  5608. +#define IRQ_TIMER0 (IRQ_ARMCTRL_START + INTERRUPT_TIMER0)
  5609. +#define IRQ_TIMER1 (IRQ_ARMCTRL_START + INTERRUPT_TIMER1)
  5610. +#define IRQ_TIMER2 (IRQ_ARMCTRL_START + INTERRUPT_TIMER2)
  5611. +#define IRQ_TIMER3 (IRQ_ARMCTRL_START + INTERRUPT_TIMER3)
  5612. +#define IRQ_CODEC0 (IRQ_ARMCTRL_START + INTERRUPT_CODEC0)
  5613. +#define IRQ_CODEC1 (IRQ_ARMCTRL_START + INTERRUPT_CODEC1)
  5614. +#define IRQ_CODEC2 (IRQ_ARMCTRL_START + INTERRUPT_CODEC2)
  5615. +#define IRQ_JPEG (IRQ_ARMCTRL_START + INTERRUPT_JPEG)
  5616. +#define IRQ_ISP (IRQ_ARMCTRL_START + INTERRUPT_ISP)
  5617. +#define IRQ_USB (IRQ_ARMCTRL_START + INTERRUPT_USB)
  5618. +#define IRQ_3D (IRQ_ARMCTRL_START + INTERRUPT_3D)
  5619. +#define IRQ_TRANSPOSER (IRQ_ARMCTRL_START + INTERRUPT_TRANSPOSER)
  5620. +#define IRQ_MULTICORESYNC0 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC0)
  5621. +#define IRQ_MULTICORESYNC1 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC1)
  5622. +#define IRQ_MULTICORESYNC2 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC2)
  5623. +#define IRQ_MULTICORESYNC3 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC3)
  5624. +#define IRQ_DMA0 (IRQ_ARMCTRL_START + INTERRUPT_DMA0)
  5625. +#define IRQ_DMA1 (IRQ_ARMCTRL_START + INTERRUPT_DMA1)
  5626. +#define IRQ_DMA2 (IRQ_ARMCTRL_START + INTERRUPT_DMA2)
  5627. +#define IRQ_DMA3 (IRQ_ARMCTRL_START + INTERRUPT_DMA3)
  5628. +#define IRQ_DMA4 (IRQ_ARMCTRL_START + INTERRUPT_DMA4)
  5629. +#define IRQ_DMA5 (IRQ_ARMCTRL_START + INTERRUPT_DMA5)
  5630. +#define IRQ_DMA6 (IRQ_ARMCTRL_START + INTERRUPT_DMA6)
  5631. +#define IRQ_DMA7 (IRQ_ARMCTRL_START + INTERRUPT_DMA7)
  5632. +#define IRQ_DMA8 (IRQ_ARMCTRL_START + INTERRUPT_DMA8)
  5633. +#define IRQ_DMA9 (IRQ_ARMCTRL_START + INTERRUPT_DMA9)
  5634. +#define IRQ_DMA10 (IRQ_ARMCTRL_START + INTERRUPT_DMA10)
  5635. +#define IRQ_DMA11 (IRQ_ARMCTRL_START + INTERRUPT_DMA11)
  5636. +#define IRQ_DMA12 (IRQ_ARMCTRL_START + INTERRUPT_DMA12)
  5637. +#define IRQ_AUX (IRQ_ARMCTRL_START + INTERRUPT_AUX)
  5638. +#define IRQ_ARM (IRQ_ARMCTRL_START + INTERRUPT_ARM)
  5639. +#define IRQ_VPUDMA (IRQ_ARMCTRL_START + INTERRUPT_VPUDMA)
  5640. +#define IRQ_HOSTPORT (IRQ_ARMCTRL_START + INTERRUPT_HOSTPORT)
  5641. +#define IRQ_VIDEOSCALER (IRQ_ARMCTRL_START + INTERRUPT_VIDEOSCALER)
  5642. +#define IRQ_CCP2TX (IRQ_ARMCTRL_START + INTERRUPT_CCP2TX)
  5643. +#define IRQ_SDC (IRQ_ARMCTRL_START + INTERRUPT_SDC)
  5644. +#define IRQ_DSI0 (IRQ_ARMCTRL_START + INTERRUPT_DSI0)
  5645. +#define IRQ_AVE (IRQ_ARMCTRL_START + INTERRUPT_AVE)
  5646. +#define IRQ_CAM0 (IRQ_ARMCTRL_START + INTERRUPT_CAM0)
  5647. +#define IRQ_CAM1 (IRQ_ARMCTRL_START + INTERRUPT_CAM1)
  5648. +#define IRQ_HDMI0 (IRQ_ARMCTRL_START + INTERRUPT_HDMI0)
  5649. +#define IRQ_HDMI1 (IRQ_ARMCTRL_START + INTERRUPT_HDMI1)
  5650. +#define IRQ_PIXELVALVE1 (IRQ_ARMCTRL_START + INTERRUPT_PIXELVALVE1)
  5651. +#define IRQ_I2CSPISLV (IRQ_ARMCTRL_START + INTERRUPT_I2CSPISLV)
  5652. +#define IRQ_DSI1 (IRQ_ARMCTRL_START + INTERRUPT_DSI1)
  5653. +#define IRQ_PWA0 (IRQ_ARMCTRL_START + INTERRUPT_PWA0)
  5654. +#define IRQ_PWA1 (IRQ_ARMCTRL_START + INTERRUPT_PWA1)
  5655. +#define IRQ_CPR (IRQ_ARMCTRL_START + INTERRUPT_CPR)
  5656. +#define IRQ_SMI (IRQ_ARMCTRL_START + INTERRUPT_SMI)
  5657. +#define IRQ_GPIO0 (IRQ_ARMCTRL_START + INTERRUPT_GPIO0)
  5658. +#define IRQ_GPIO1 (IRQ_ARMCTRL_START + INTERRUPT_GPIO1)
  5659. +#define IRQ_GPIO2 (IRQ_ARMCTRL_START + INTERRUPT_GPIO2)
  5660. +#define IRQ_GPIO3 (IRQ_ARMCTRL_START + INTERRUPT_GPIO3)
  5661. +#define IRQ_I2C (IRQ_ARMCTRL_START + INTERRUPT_I2C)
  5662. +#define IRQ_SPI (IRQ_ARMCTRL_START + INTERRUPT_SPI)
  5663. +#define IRQ_I2SPCM (IRQ_ARMCTRL_START + INTERRUPT_I2SPCM)
  5664. +#define IRQ_SDIO (IRQ_ARMCTRL_START + INTERRUPT_SDIO)
  5665. +#define IRQ_UART (IRQ_ARMCTRL_START + INTERRUPT_UART)
  5666. +#define IRQ_SLIMBUS (IRQ_ARMCTRL_START + INTERRUPT_SLIMBUS)
  5667. +#define IRQ_VEC (IRQ_ARMCTRL_START + INTERRUPT_VEC)
  5668. +#define IRQ_CPG (IRQ_ARMCTRL_START + INTERRUPT_CPG)
  5669. +#define IRQ_RNG (IRQ_ARMCTRL_START + INTERRUPT_RNG)
  5670. +#define IRQ_ARASANSDIO (IRQ_ARMCTRL_START + INTERRUPT_ARASANSDIO)
  5671. +#define IRQ_AVSPMON (IRQ_ARMCTRL_START + INTERRUPT_AVSPMON)
  5672. +
  5673. +#define IRQ_ARM_TIMER (IRQ_ARMCTRL_START + INTERRUPT_ARM_TIMER)
  5674. +#define IRQ_ARM_MAILBOX (IRQ_ARMCTRL_START + INTERRUPT_ARM_MAILBOX)
  5675. +#define IRQ_ARM_DOORBELL_0 (IRQ_ARMCTRL_START + INTERRUPT_ARM_DOORBELL_0)
  5676. +#define IRQ_ARM_DOORBELL_1 (IRQ_ARMCTRL_START + INTERRUPT_ARM_DOORBELL_1)
  5677. +#define IRQ_VPU0_HALTED (IRQ_ARMCTRL_START + INTERRUPT_VPU0_HALTED)
  5678. +#define IRQ_VPU1_HALTED (IRQ_ARMCTRL_START + INTERRUPT_VPU1_HALTED)
  5679. +#define IRQ_ILLEGAL_TYPE0 (IRQ_ARMCTRL_START + INTERRUPT_ILLEGAL_TYPE0)
  5680. +#define IRQ_ILLEGAL_TYPE1 (IRQ_ARMCTRL_START + INTERRUPT_ILLEGAL_TYPE1)
  5681. +#define IRQ_PENDING1 (IRQ_ARMCTRL_START + INTERRUPT_PENDING1)
  5682. +#define IRQ_PENDING2 (IRQ_ARMCTRL_START + INTERRUPT_PENDING2)
  5683. +
  5684. +#define FIQ_START HARD_IRQS
  5685. +
  5686. +/*
  5687. + * FIQ interrupts definitions are the same as the INT definitions.
  5688. + */
  5689. +#define FIQ_TIMER0 (FIQ_START+INTERRUPT_TIMER0)
  5690. +#define FIQ_TIMER1 (FIQ_START+INTERRUPT_TIMER1)
  5691. +#define FIQ_TIMER2 (FIQ_START+INTERRUPT_TIMER2)
  5692. +#define FIQ_TIMER3 (FIQ_START+INTERRUPT_TIMER3)
  5693. +#define FIQ_CODEC0 (FIQ_START+INTERRUPT_CODEC0)
  5694. +#define FIQ_CODEC1 (FIQ_START+INTERRUPT_CODEC1)
  5695. +#define FIQ_CODEC2 (FIQ_START+INTERRUPT_CODEC2)
  5696. +#define FIQ_JPEG (FIQ_START+INTERRUPT_JPEG)
  5697. +#define FIQ_ISP (FIQ_START+INTERRUPT_ISP)
  5698. +#define FIQ_USB (FIQ_START+INTERRUPT_USB)
  5699. +#define FIQ_3D (FIQ_START+INTERRUPT_3D)
  5700. +#define FIQ_TRANSPOSER (FIQ_START+INTERRUPT_TRANSPOSER)
  5701. +#define FIQ_MULTICORESYNC0 (FIQ_START+INTERRUPT_MULTICORESYNC0)
  5702. +#define FIQ_MULTICORESYNC1 (FIQ_START+INTERRUPT_MULTICORESYNC1)
  5703. +#define FIQ_MULTICORESYNC2 (FIQ_START+INTERRUPT_MULTICORESYNC2)
  5704. +#define FIQ_MULTICORESYNC3 (FIQ_START+INTERRUPT_MULTICORESYNC3)
  5705. +#define FIQ_DMA0 (FIQ_START+INTERRUPT_DMA0)
  5706. +#define FIQ_DMA1 (FIQ_START+INTERRUPT_DMA1)
  5707. +#define FIQ_DMA2 (FIQ_START+INTERRUPT_DMA2)
  5708. +#define FIQ_DMA3 (FIQ_START+INTERRUPT_DMA3)
  5709. +#define FIQ_DMA4 (FIQ_START+INTERRUPT_DMA4)
  5710. +#define FIQ_DMA5 (FIQ_START+INTERRUPT_DMA5)
  5711. +#define FIQ_DMA6 (FIQ_START+INTERRUPT_DMA6)
  5712. +#define FIQ_DMA7 (FIQ_START+INTERRUPT_DMA7)
  5713. +#define FIQ_DMA8 (FIQ_START+INTERRUPT_DMA8)
  5714. +#define FIQ_DMA9 (FIQ_START+INTERRUPT_DMA9)
  5715. +#define FIQ_DMA10 (FIQ_START+INTERRUPT_DMA10)
  5716. +#define FIQ_DMA11 (FIQ_START+INTERRUPT_DMA11)
  5717. +#define FIQ_DMA12 (FIQ_START+INTERRUPT_DMA12)
  5718. +#define FIQ_AUX (FIQ_START+INTERRUPT_AUX)
  5719. +#define FIQ_ARM (FIQ_START+INTERRUPT_ARM)
  5720. +#define FIQ_VPUDMA (FIQ_START+INTERRUPT_VPUDMA)
  5721. +#define FIQ_HOSTPORT (FIQ_START+INTERRUPT_HOSTPORT)
  5722. +#define FIQ_VIDEOSCALER (FIQ_START+INTERRUPT_VIDEOSCALER)
  5723. +#define FIQ_CCP2TX (FIQ_START+INTERRUPT_CCP2TX)
  5724. +#define FIQ_SDC (FIQ_START+INTERRUPT_SDC)
  5725. +#define FIQ_DSI0 (FIQ_START+INTERRUPT_DSI0)
  5726. +#define FIQ_AVE (FIQ_START+INTERRUPT_AVE)
  5727. +#define FIQ_CAM0 (FIQ_START+INTERRUPT_CAM0)
  5728. +#define FIQ_CAM1 (FIQ_START+INTERRUPT_CAM1)
  5729. +#define FIQ_HDMI0 (FIQ_START+INTERRUPT_HDMI0)
  5730. +#define FIQ_HDMI1 (FIQ_START+INTERRUPT_HDMI1)
  5731. +#define FIQ_PIXELVALVE1 (FIQ_START+INTERRUPT_PIXELVALVE1)
  5732. +#define FIQ_I2CSPISLV (FIQ_START+INTERRUPT_I2CSPISLV)
  5733. +#define FIQ_DSI1 (FIQ_START+INTERRUPT_DSI1)
  5734. +#define FIQ_PWA0 (FIQ_START+INTERRUPT_PWA0)
  5735. +#define FIQ_PWA1 (FIQ_START+INTERRUPT_PWA1)
  5736. +#define FIQ_CPR (FIQ_START+INTERRUPT_CPR)
  5737. +#define FIQ_SMI (FIQ_START+INTERRUPT_SMI)
  5738. +#define FIQ_GPIO0 (FIQ_START+INTERRUPT_GPIO0)
  5739. +#define FIQ_GPIO1 (FIQ_START+INTERRUPT_GPIO1)
  5740. +#define FIQ_GPIO2 (FIQ_START+INTERRUPT_GPIO2)
  5741. +#define FIQ_GPIO3 (FIQ_START+INTERRUPT_GPIO3)
  5742. +#define FIQ_I2C (FIQ_START+INTERRUPT_I2C)
  5743. +#define FIQ_SPI (FIQ_START+INTERRUPT_SPI)
  5744. +#define FIQ_I2SPCM (FIQ_START+INTERRUPT_I2SPCM)
  5745. +#define FIQ_SDIO (FIQ_START+INTERRUPT_SDIO)
  5746. +#define FIQ_UART (FIQ_START+INTERRUPT_UART)
  5747. +#define FIQ_SLIMBUS (FIQ_START+INTERRUPT_SLIMBUS)
  5748. +#define FIQ_VEC (FIQ_START+INTERRUPT_VEC)
  5749. +#define FIQ_CPG (FIQ_START+INTERRUPT_CPG)
  5750. +#define FIQ_RNG (FIQ_START+INTERRUPT_RNG)
  5751. +#define FIQ_ARASANSDIO (FIQ_START+INTERRUPT_ARASANSDIO)
  5752. +#define FIQ_AVSPMON (FIQ_START+INTERRUPT_AVSPMON)
  5753. +
  5754. +#define FIQ_ARM_TIMER (FIQ_START+INTERRUPT_ARM_TIMER)
  5755. +#define FIQ_ARM_MAILBOX (FIQ_START+INTERRUPT_ARM_MAILBOX)
  5756. +#define FIQ_ARM_DOORBELL_0 (FIQ_START+INTERRUPT_ARM_DOORBELL_0)
  5757. +#define FIQ_ARM_DOORBELL_1 (FIQ_START+INTERRUPT_ARM_DOORBELL_1)
  5758. +#define FIQ_VPU0_HALTED (FIQ_START+INTERRUPT_VPU0_HALTED)
  5759. +#define FIQ_VPU1_HALTED (FIQ_START+INTERRUPT_VPU1_HALTED)
  5760. +#define FIQ_ILLEGAL_TYPE0 (FIQ_START+INTERRUPT_ILLEGAL_TYPE0)
  5761. +#define FIQ_ILLEGAL_TYPE1 (FIQ_START+INTERRUPT_ILLEGAL_TYPE1)
  5762. +#define FIQ_PENDING1 (FIQ_START+INTERRUPT_PENDING1)
  5763. +#define FIQ_PENDING2 (FIQ_START+INTERRUPT_PENDING2)
  5764. +
  5765. +#define GPIO_IRQ_START (HARD_IRQS + FIQ_IRQS)
  5766. +
  5767. +#define HARD_IRQS (64 + 21)
  5768. +#define FIQ_IRQS (64 + 21)
  5769. +#define GPIO_IRQS (32*5)
  5770. +
  5771. +#define NR_IRQS HARD_IRQS+FIQ_IRQS+GPIO_IRQS
  5772. +
  5773. +
  5774. +#endif /* _BCM2708_IRQS_H_ */
  5775. diff -Nur linux-3.13.3.orig/arch/arm/mach-bcm2708/include/mach/memory.h linux-3.13.3/arch/arm/mach-bcm2708/include/mach/memory.h
  5776. --- linux-3.13.3.orig/arch/arm/mach-bcm2708/include/mach/memory.h 1970-01-01 01:00:00.000000000 +0100
  5777. +++ linux-3.13.3/arch/arm/mach-bcm2708/include/mach/memory.h 2014-02-17 22:41:01.000000000 +0100
  5778. @@ -0,0 +1,57 @@
  5779. +/*
  5780. + * arch/arm/mach-bcm2708/include/mach/memory.h
  5781. + *
  5782. + * Copyright (C) 2010 Broadcom
  5783. + *
  5784. + * This program is free software; you can redistribute it and/or modify
  5785. + * it under the terms of the GNU General Public License as published by
  5786. + * the Free Software Foundation; either version 2 of the License, or
  5787. + * (at your option) any later version.
  5788. + *
  5789. + * This program is distributed in the hope that it will be useful,
  5790. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5791. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5792. + * GNU General Public License for more details.
  5793. + *
  5794. + * You should have received a copy of the GNU General Public License
  5795. + * along with this program; if not, write to the Free Software
  5796. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5797. + */
  5798. +#ifndef __ASM_ARCH_MEMORY_H
  5799. +#define __ASM_ARCH_MEMORY_H
  5800. +
  5801. +/* Memory overview:
  5802. +
  5803. + [ARMcore] <--virtual addr-->
  5804. + [ARMmmu] <--physical addr-->
  5805. + [GERTmap] <--bus add-->
  5806. + [VCperiph]
  5807. +
  5808. +*/
  5809. +
  5810. +/*
  5811. + * Physical DRAM offset.
  5812. + */
  5813. +#define PLAT_PHYS_OFFSET UL(0x00000000)
  5814. +#define VC_ARMMEM_OFFSET UL(0x00000000) /* offset in VC of ARM memory */
  5815. +
  5816. +#ifdef CONFIG_BCM2708_NOL2CACHE
  5817. + #define _REAL_BUS_OFFSET UL(0xC0000000) /* don't use L1 or L2 caches */
  5818. +#else
  5819. + #define _REAL_BUS_OFFSET UL(0x40000000) /* use L2 cache */
  5820. +#endif
  5821. +
  5822. +/* We're using the memory at 64M in the VideoCore for Linux - this adjustment
  5823. + * will provide the offset into this area as well as setting the bits that
  5824. + * stop the L1 and L2 cache from being used
  5825. + *
  5826. + * WARNING: this only works because the ARM is given memory at a fixed location
  5827. + * (ARMMEM_OFFSET)
  5828. + */
  5829. +#define BUS_OFFSET (VC_ARMMEM_OFFSET + _REAL_BUS_OFFSET)
  5830. +#define __virt_to_bus(x) ((x) + (BUS_OFFSET - PAGE_OFFSET))
  5831. +#define __bus_to_virt(x) ((x) - (BUS_OFFSET - PAGE_OFFSET))
  5832. +#define __pfn_to_bus(x) (__pfn_to_phys(x) + (BUS_OFFSET - PLAT_PHYS_OFFSET))
  5833. +#define __bus_to_pfn(x) __phys_to_pfn((x) - (BUS_OFFSET - PLAT_PHYS_OFFSET))
  5834. +
  5835. +#endif
  5836. diff -Nur linux-3.13.3.orig/arch/arm/mach-bcm2708/include/mach/platform.h linux-3.13.3/arch/arm/mach-bcm2708/include/mach/platform.h
  5837. --- linux-3.13.3.orig/arch/arm/mach-bcm2708/include/mach/platform.h 1970-01-01 01:00:00.000000000 +0100
  5838. +++ linux-3.13.3/arch/arm/mach-bcm2708/include/mach/platform.h 2014-02-17 22:41:01.000000000 +0100
  5839. @@ -0,0 +1,228 @@
  5840. +/*
  5841. + * arch/arm/mach-bcm2708/include/mach/platform.h
  5842. + *
  5843. + * Copyright (C) 2010 Broadcom
  5844. + *
  5845. + * This program is free software; you can redistribute it and/or modify
  5846. + * it under the terms of the GNU General Public License as published by
  5847. + * the Free Software Foundation; either version 2 of the License, or
  5848. + * (at your option) any later version.
  5849. + *
  5850. + * This program is distributed in the hope that it will be useful,
  5851. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5852. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5853. + * GNU General Public License for more details.
  5854. + *
  5855. + * You should have received a copy of the GNU General Public License
  5856. + * along with this program; if not, write to the Free Software
  5857. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5858. + */
  5859. +
  5860. +#ifndef _BCM2708_PLATFORM_H
  5861. +#define _BCM2708_PLATFORM_H
  5862. +
  5863. +
  5864. +/* macros to get at IO space when running virtually */
  5865. +#define IO_ADDRESS(x) (((x) & 0x0fffffff) + (((x) >> 4) & 0x0f000000) + 0xf0000000)
  5866. +
  5867. +#define __io_address(n) IOMEM(IO_ADDRESS(n))
  5868. +
  5869. +
  5870. +/*
  5871. + * SDRAM
  5872. + */
  5873. +#define BCM2708_SDRAM_BASE 0x00000000
  5874. +
  5875. +/*
  5876. + * Logic expansion modules
  5877. + *
  5878. + */
  5879. +
  5880. +
  5881. +/* ------------------------------------------------------------------------
  5882. + * BCM2708 ARMCTRL Registers
  5883. + * ------------------------------------------------------------------------
  5884. + */
  5885. +
  5886. +#define HW_REGISTER_RW(addr) (addr)
  5887. +#define HW_REGISTER_RO(addr) (addr)
  5888. +
  5889. +#include "arm_control.h"
  5890. +#undef ARM_BASE
  5891. +
  5892. +/*
  5893. + * Definitions and addresses for the ARM CONTROL logic
  5894. + * This file is manually generated.
  5895. + */
  5896. +
  5897. +#define BCM2708_PERI_BASE 0x20000000
  5898. +#define IC0_BASE (BCM2708_PERI_BASE + 0x2000)
  5899. +#define ST_BASE (BCM2708_PERI_BASE + 0x3000) /* System Timer */
  5900. +#define MPHI_BASE (BCM2708_PERI_BASE + 0x6000) /* Message -based Parallel Host Interface */
  5901. +#define DMA_BASE (BCM2708_PERI_BASE + 0x7000) /* DMA controller */
  5902. +#define ARM_BASE (BCM2708_PERI_BASE + 0xB000) /* BCM2708 ARM control block */
  5903. +#define PM_BASE (BCM2708_PERI_BASE + 0x100000) /* Power Management, Reset controller and Watchdog registers */
  5904. +#define PCM_CLOCK_BASE (BCM2708_PERI_BASE + 0x101098) /* PCM Clock */
  5905. +#define RNG_BASE (BCM2708_PERI_BASE + 0x104000) /* Hardware RNG */
  5906. +#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) /* GPIO */
  5907. +#define UART0_BASE (BCM2708_PERI_BASE + 0x201000) /* Uart 0 */
  5908. +#define MMCI0_BASE (BCM2708_PERI_BASE + 0x202000) /* MMC interface */
  5909. +#define I2S_BASE (BCM2708_PERI_BASE + 0x203000) /* I2S */
  5910. +#define SPI0_BASE (BCM2708_PERI_BASE + 0x204000) /* SPI0 */
  5911. +#define BSC0_BASE (BCM2708_PERI_BASE + 0x205000) /* BSC0 I2C/TWI */
  5912. +#define UART1_BASE (BCM2708_PERI_BASE + 0x215000) /* Uart 1 */
  5913. +#define EMMC_BASE (BCM2708_PERI_BASE + 0x300000) /* eMMC interface */
  5914. +#define SMI_BASE (BCM2708_PERI_BASE + 0x600000) /* SMI */
  5915. +#define BSC1_BASE (BCM2708_PERI_BASE + 0x804000) /* BSC1 I2C/TWI */
  5916. +#define USB_BASE (BCM2708_PERI_BASE + 0x980000) /* DTC_OTG USB controller */
  5917. +#define MCORE_BASE (BCM2708_PERI_BASE + 0x0000) /* Fake frame buffer device (actually the multicore sync block*/
  5918. +
  5919. +#define ARMCTRL_BASE (ARM_BASE + 0x000)
  5920. +#define ARMCTRL_IC_BASE (ARM_BASE + 0x200) /* ARM interrupt controller */
  5921. +#define ARMCTRL_TIMER0_1_BASE (ARM_BASE + 0x400) /* Timer 0 and 1 */
  5922. +#define ARMCTRL_0_SBM_BASE (ARM_BASE + 0x800) /* User 0 (ARM)'s Semaphores Doorbells and Mailboxes */
  5923. +
  5924. +
  5925. +/*
  5926. + * Interrupt assignments
  5927. + */
  5928. +
  5929. +#define ARM_IRQ1_BASE 0
  5930. +#define INTERRUPT_TIMER0 (ARM_IRQ1_BASE + 0)
  5931. +#define INTERRUPT_TIMER1 (ARM_IRQ1_BASE + 1)
  5932. +#define INTERRUPT_TIMER2 (ARM_IRQ1_BASE + 2)
  5933. +#define INTERRUPT_TIMER3 (ARM_IRQ1_BASE + 3)
  5934. +#define INTERRUPT_CODEC0 (ARM_IRQ1_BASE + 4)
  5935. +#define INTERRUPT_CODEC1 (ARM_IRQ1_BASE + 5)
  5936. +#define INTERRUPT_CODEC2 (ARM_IRQ1_BASE + 6)
  5937. +#define INTERRUPT_VC_JPEG (ARM_IRQ1_BASE + 7)
  5938. +#define INTERRUPT_ISP (ARM_IRQ1_BASE + 8)
  5939. +#define INTERRUPT_VC_USB (ARM_IRQ1_BASE + 9)
  5940. +#define INTERRUPT_VC_3D (ARM_IRQ1_BASE + 10)
  5941. +#define INTERRUPT_TRANSPOSER (ARM_IRQ1_BASE + 11)
  5942. +#define INTERRUPT_MULTICORESYNC0 (ARM_IRQ1_BASE + 12)
  5943. +#define INTERRUPT_MULTICORESYNC1 (ARM_IRQ1_BASE + 13)
  5944. +#define INTERRUPT_MULTICORESYNC2 (ARM_IRQ1_BASE + 14)
  5945. +#define INTERRUPT_MULTICORESYNC3 (ARM_IRQ1_BASE + 15)
  5946. +#define INTERRUPT_DMA0 (ARM_IRQ1_BASE + 16)
  5947. +#define INTERRUPT_DMA1 (ARM_IRQ1_BASE + 17)
  5948. +#define INTERRUPT_VC_DMA2 (ARM_IRQ1_BASE + 18)
  5949. +#define INTERRUPT_VC_DMA3 (ARM_IRQ1_BASE + 19)
  5950. +#define INTERRUPT_DMA4 (ARM_IRQ1_BASE + 20)
  5951. +#define INTERRUPT_DMA5 (ARM_IRQ1_BASE + 21)
  5952. +#define INTERRUPT_DMA6 (ARM_IRQ1_BASE + 22)
  5953. +#define INTERRUPT_DMA7 (ARM_IRQ1_BASE + 23)
  5954. +#define INTERRUPT_DMA8 (ARM_IRQ1_BASE + 24)
  5955. +#define INTERRUPT_DMA9 (ARM_IRQ1_BASE + 25)
  5956. +#define INTERRUPT_DMA10 (ARM_IRQ1_BASE + 26)
  5957. +#define INTERRUPT_DMA11 (ARM_IRQ1_BASE + 27)
  5958. +#define INTERRUPT_DMA12 (ARM_IRQ1_BASE + 28)
  5959. +#define INTERRUPT_AUX (ARM_IRQ1_BASE + 29)
  5960. +#define INTERRUPT_ARM (ARM_IRQ1_BASE + 30)
  5961. +#define INTERRUPT_VPUDMA (ARM_IRQ1_BASE + 31)
  5962. +
  5963. +#define ARM_IRQ2_BASE 32
  5964. +#define INTERRUPT_HOSTPORT (ARM_IRQ2_BASE + 0)
  5965. +#define INTERRUPT_VIDEOSCALER (ARM_IRQ2_BASE + 1)
  5966. +#define INTERRUPT_CCP2TX (ARM_IRQ2_BASE + 2)
  5967. +#define INTERRUPT_SDC (ARM_IRQ2_BASE + 3)
  5968. +#define INTERRUPT_DSI0 (ARM_IRQ2_BASE + 4)
  5969. +#define INTERRUPT_AVE (ARM_IRQ2_BASE + 5)
  5970. +#define INTERRUPT_CAM0 (ARM_IRQ2_BASE + 6)
  5971. +#define INTERRUPT_CAM1 (ARM_IRQ2_BASE + 7)
  5972. +#define INTERRUPT_HDMI0 (ARM_IRQ2_BASE + 8)
  5973. +#define INTERRUPT_HDMI1 (ARM_IRQ2_BASE + 9)
  5974. +#define INTERRUPT_PIXELVALVE1 (ARM_IRQ2_BASE + 10)
  5975. +#define INTERRUPT_I2CSPISLV (ARM_IRQ2_BASE + 11)
  5976. +#define INTERRUPT_DSI1 (ARM_IRQ2_BASE + 12)
  5977. +#define INTERRUPT_PWA0 (ARM_IRQ2_BASE + 13)
  5978. +#define INTERRUPT_PWA1 (ARM_IRQ2_BASE + 14)
  5979. +#define INTERRUPT_CPR (ARM_IRQ2_BASE + 15)
  5980. +#define INTERRUPT_SMI (ARM_IRQ2_BASE + 16)
  5981. +#define INTERRUPT_GPIO0 (ARM_IRQ2_BASE + 17)
  5982. +#define INTERRUPT_GPIO1 (ARM_IRQ2_BASE + 18)
  5983. +#define INTERRUPT_GPIO2 (ARM_IRQ2_BASE + 19)
  5984. +#define INTERRUPT_GPIO3 (ARM_IRQ2_BASE + 20)
  5985. +#define INTERRUPT_VC_I2C (ARM_IRQ2_BASE + 21)
  5986. +#define INTERRUPT_VC_SPI (ARM_IRQ2_BASE + 22)
  5987. +#define INTERRUPT_VC_I2SPCM (ARM_IRQ2_BASE + 23)
  5988. +#define INTERRUPT_VC_SDIO (ARM_IRQ2_BASE + 24)
  5989. +#define INTERRUPT_VC_UART (ARM_IRQ2_BASE + 25)
  5990. +#define INTERRUPT_SLIMBUS (ARM_IRQ2_BASE + 26)
  5991. +#define INTERRUPT_VEC (ARM_IRQ2_BASE + 27)
  5992. +#define INTERRUPT_CPG (ARM_IRQ2_BASE + 28)
  5993. +#define INTERRUPT_RNG (ARM_IRQ2_BASE + 29)
  5994. +#define INTERRUPT_VC_ARASANSDIO (ARM_IRQ2_BASE + 30)
  5995. +#define INTERRUPT_AVSPMON (ARM_IRQ2_BASE + 31)
  5996. +
  5997. +#define ARM_IRQ0_BASE 64
  5998. +#define INTERRUPT_ARM_TIMER (ARM_IRQ0_BASE + 0)
  5999. +#define INTERRUPT_ARM_MAILBOX (ARM_IRQ0_BASE + 1)
  6000. +#define INTERRUPT_ARM_DOORBELL_0 (ARM_IRQ0_BASE + 2)
  6001. +#define INTERRUPT_ARM_DOORBELL_1 (ARM_IRQ0_BASE + 3)
  6002. +#define INTERRUPT_VPU0_HALTED (ARM_IRQ0_BASE + 4)
  6003. +#define INTERRUPT_VPU1_HALTED (ARM_IRQ0_BASE + 5)
  6004. +#define INTERRUPT_ILLEGAL_TYPE0 (ARM_IRQ0_BASE + 6)
  6005. +#define INTERRUPT_ILLEGAL_TYPE1 (ARM_IRQ0_BASE + 7)
  6006. +#define INTERRUPT_PENDING1 (ARM_IRQ0_BASE + 8)
  6007. +#define INTERRUPT_PENDING2 (ARM_IRQ0_BASE + 9)
  6008. +#define INTERRUPT_JPEG (ARM_IRQ0_BASE + 10)
  6009. +#define INTERRUPT_USB (ARM_IRQ0_BASE + 11)
  6010. +#define INTERRUPT_3D (ARM_IRQ0_BASE + 12)
  6011. +#define INTERRUPT_DMA2 (ARM_IRQ0_BASE + 13)
  6012. +#define INTERRUPT_DMA3 (ARM_IRQ0_BASE + 14)
  6013. +#define INTERRUPT_I2C (ARM_IRQ0_BASE + 15)
  6014. +#define INTERRUPT_SPI (ARM_IRQ0_BASE + 16)
  6015. +#define INTERRUPT_I2SPCM (ARM_IRQ0_BASE + 17)
  6016. +#define INTERRUPT_SDIO (ARM_IRQ0_BASE + 18)
  6017. +#define INTERRUPT_UART (ARM_IRQ0_BASE + 19)
  6018. +#define INTERRUPT_ARASANSDIO (ARM_IRQ0_BASE + 20)
  6019. +
  6020. +#define MAXIRQNUM (32 + 32 + 20)
  6021. +#define MAXFIQNUM (32 + 32 + 20)
  6022. +
  6023. +#define MAX_TIMER 2
  6024. +#define MAX_PERIOD 699050
  6025. +#define TICKS_PER_uSEC 1
  6026. +
  6027. +/*
  6028. + * These are useconds NOT ticks.
  6029. + *
  6030. + */
  6031. +#define mSEC_1 1000
  6032. +#define mSEC_5 (mSEC_1 * 5)
  6033. +#define mSEC_10 (mSEC_1 * 10)
  6034. +#define mSEC_25 (mSEC_1 * 25)
  6035. +#define SEC_1 (mSEC_1 * 1000)
  6036. +
  6037. +/*
  6038. + * Watchdog
  6039. + */
  6040. +#define PM_RSTC (PM_BASE+0x1c)
  6041. +#define PM_RSTS (PM_BASE+0x20)
  6042. +#define PM_WDOG (PM_BASE+0x24)
  6043. +
  6044. +#define PM_WDOG_RESET 0000000000
  6045. +#define PM_PASSWORD 0x5a000000
  6046. +#define PM_WDOG_TIME_SET 0x000fffff
  6047. +#define PM_RSTC_WRCFG_CLR 0xffffffcf
  6048. +#define PM_RSTC_WRCFG_SET 0x00000030
  6049. +#define PM_RSTC_WRCFG_FULL_RESET 0x00000020
  6050. +#define PM_RSTC_RESET 0x00000102
  6051. +
  6052. +#define PM_RSTS_HADPOR_SET 0x00001000
  6053. +#define PM_RSTS_HADSRH_SET 0x00000400
  6054. +#define PM_RSTS_HADSRF_SET 0x00000200
  6055. +#define PM_RSTS_HADSRQ_SET 0x00000100
  6056. +#define PM_RSTS_HADWRH_SET 0x00000040
  6057. +#define PM_RSTS_HADWRF_SET 0x00000020
  6058. +#define PM_RSTS_HADWRQ_SET 0x00000010
  6059. +#define PM_RSTS_HADDRH_SET 0x00000004
  6060. +#define PM_RSTS_HADDRF_SET 0x00000002
  6061. +#define PM_RSTS_HADDRQ_SET 0x00000001
  6062. +
  6063. +#define UART0_CLOCK 3000000
  6064. +
  6065. +#endif
  6066. +
  6067. +/* END */
  6068. diff -Nur linux-3.13.3.orig/arch/arm/mach-bcm2708/include/mach/power.h linux-3.13.3/arch/arm/mach-bcm2708/include/mach/power.h
  6069. --- linux-3.13.3.orig/arch/arm/mach-bcm2708/include/mach/power.h 1970-01-01 01:00:00.000000000 +0100
  6070. +++ linux-3.13.3/arch/arm/mach-bcm2708/include/mach/power.h 2014-02-17 22:41:01.000000000 +0100
  6071. @@ -0,0 +1,26 @@
  6072. +/*
  6073. + * linux/arch/arm/mach-bcm2708/power.h
  6074. + *
  6075. + * Copyright (C) 2010 Broadcom
  6076. + *
  6077. + * This program is free software; you can redistribute it and/or modify
  6078. + * it under the terms of the GNU General Public License version 2 as
  6079. + * published by the Free Software Foundation.
  6080. + *
  6081. + * This device provides a shared mechanism for controlling the power to
  6082. + * VideoCore subsystems.
  6083. + */
  6084. +
  6085. +#ifndef _MACH_BCM2708_POWER_H
  6086. +#define _MACH_BCM2708_POWER_H
  6087. +
  6088. +#include <linux/types.h>
  6089. +#include <mach/arm_power.h>
  6090. +
  6091. +typedef unsigned int BCM_POWER_HANDLE_T;
  6092. +
  6093. +extern int bcm_power_open(BCM_POWER_HANDLE_T *handle);
  6094. +extern int bcm_power_request(BCM_POWER_HANDLE_T handle, uint32_t request);
  6095. +extern int bcm_power_close(BCM_POWER_HANDLE_T handle);
  6096. +
  6097. +#endif
  6098. diff -Nur linux-3.13.3.orig/arch/arm/mach-bcm2708/include/mach/system.h linux-3.13.3/arch/arm/mach-bcm2708/include/mach/system.h
  6099. --- linux-3.13.3.orig/arch/arm/mach-bcm2708/include/mach/system.h 1970-01-01 01:00:00.000000000 +0100
  6100. +++ linux-3.13.3/arch/arm/mach-bcm2708/include/mach/system.h 2014-02-17 22:41:01.000000000 +0100
  6101. @@ -0,0 +1,38 @@
  6102. +/*
  6103. + * arch/arm/mach-bcm2708/include/mach/system.h
  6104. + *
  6105. + * Copyright (C) 2010 Broadcom
  6106. + * Copyright (C) 2003 ARM Limited
  6107. + * Copyright (C) 2000 Deep Blue Solutions Ltd
  6108. + *
  6109. + * This program is free software; you can redistribute it and/or modify
  6110. + * it under the terms of the GNU General Public License as published by
  6111. + * the Free Software Foundation; either version 2 of the License, or
  6112. + * (at your option) any later version.
  6113. + *
  6114. + * This program is distributed in the hope that it will be useful,
  6115. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6116. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6117. + * GNU General Public License for more details.
  6118. + *
  6119. + * You should have received a copy of the GNU General Public License
  6120. + * along with this program; if not, write to the Free Software
  6121. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6122. + */
  6123. +#ifndef __ASM_ARCH_SYSTEM_H
  6124. +#define __ASM_ARCH_SYSTEM_H
  6125. +
  6126. +#include <linux/io.h>
  6127. +#include <mach/hardware.h>
  6128. +#include <mach/platform.h>
  6129. +
  6130. +static inline void arch_idle(void)
  6131. +{
  6132. + /*
  6133. + * This should do all the clock switching
  6134. + * and wait for interrupt tricks
  6135. + */
  6136. + cpu_do_idle();
  6137. +}
  6138. +
  6139. +#endif
  6140. diff -Nur linux-3.13.3.orig/arch/arm/mach-bcm2708/include/mach/timex.h linux-3.13.3/arch/arm/mach-bcm2708/include/mach/timex.h
  6141. --- linux-3.13.3.orig/arch/arm/mach-bcm2708/include/mach/timex.h 1970-01-01 01:00:00.000000000 +0100
  6142. +++ linux-3.13.3/arch/arm/mach-bcm2708/include/mach/timex.h 2014-02-17 22:41:01.000000000 +0100
  6143. @@ -0,0 +1,23 @@
  6144. +/*
  6145. + * arch/arm/mach-bcm2708/include/mach/timex.h
  6146. + *
  6147. + * BCM2708 sysem clock frequency
  6148. + *
  6149. + * Copyright (C) 2010 Broadcom
  6150. + *
  6151. + * This program is free software; you can redistribute it and/or modify
  6152. + * it under the terms of the GNU General Public License as published by
  6153. + * the Free Software Foundation; either version 2 of the License, or
  6154. + * (at your option) any later version.
  6155. + *
  6156. + * This program is distributed in the hope that it will be useful,
  6157. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6158. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6159. + * GNU General Public License for more details.
  6160. + *
  6161. + * You should have received a copy of the GNU General Public License
  6162. + * along with this program; if not, write to the Free Software
  6163. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6164. + */
  6165. +
  6166. +#define CLOCK_TICK_RATE (1000000)
  6167. diff -Nur linux-3.13.3.orig/arch/arm/mach-bcm2708/include/mach/uncompress.h linux-3.13.3/arch/arm/mach-bcm2708/include/mach/uncompress.h
  6168. --- linux-3.13.3.orig/arch/arm/mach-bcm2708/include/mach/uncompress.h 1970-01-01 01:00:00.000000000 +0100
  6169. +++ linux-3.13.3/arch/arm/mach-bcm2708/include/mach/uncompress.h 2014-02-17 22:41:01.000000000 +0100
  6170. @@ -0,0 +1,84 @@
  6171. +/*
  6172. + * arch/arm/mach-bcn2708/include/mach/uncompress.h
  6173. + *
  6174. + * Copyright (C) 2010 Broadcom
  6175. + * Copyright (C) 2003 ARM Limited
  6176. + *
  6177. + * This program is free software; you can redistribute it and/or modify
  6178. + * it under the terms of the GNU General Public License as published by
  6179. + * the Free Software Foundation; either version 2 of the License, or
  6180. + * (at your option) any later version.
  6181. + *
  6182. + * This program is distributed in the hope that it will be useful,
  6183. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6184. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6185. + * GNU General Public License for more details.
  6186. + *
  6187. + * You should have received a copy of the GNU General Public License
  6188. + * along with this program; if not, write to the Free Software
  6189. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6190. + */
  6191. +
  6192. +#include <linux/io.h>
  6193. +#include <linux/amba/serial.h>
  6194. +#include <mach/hardware.h>
  6195. +
  6196. +#define UART_BAUD 115200
  6197. +
  6198. +#define BCM2708_UART_DR __io(UART0_BASE + UART01x_DR)
  6199. +#define BCM2708_UART_FR __io(UART0_BASE + UART01x_FR)
  6200. +#define BCM2708_UART_IBRD __io(UART0_BASE + UART011_IBRD)
  6201. +#define BCM2708_UART_FBRD __io(UART0_BASE + UART011_FBRD)
  6202. +#define BCM2708_UART_LCRH __io(UART0_BASE + UART011_LCRH)
  6203. +#define BCM2708_UART_CR __io(UART0_BASE + UART011_CR)
  6204. +
  6205. +/*
  6206. + * This does not append a newline
  6207. + */
  6208. +static inline void putc(int c)
  6209. +{
  6210. + while (__raw_readl(BCM2708_UART_FR) & UART01x_FR_TXFF)
  6211. + barrier();
  6212. +
  6213. + __raw_writel(c, BCM2708_UART_DR);
  6214. +}
  6215. +
  6216. +static inline void flush(void)
  6217. +{
  6218. + int fr;
  6219. +
  6220. + do {
  6221. + fr = __raw_readl(BCM2708_UART_FR);
  6222. + barrier();
  6223. + } while ((fr & (UART011_FR_TXFE | UART01x_FR_BUSY)) != UART011_FR_TXFE);
  6224. +}
  6225. +
  6226. +static inline void arch_decomp_setup(void)
  6227. +{
  6228. + int temp, div, rem, frac;
  6229. +
  6230. + temp = 16 * UART_BAUD;
  6231. + div = UART0_CLOCK / temp;
  6232. + rem = UART0_CLOCK % temp;
  6233. + temp = (8 * rem) / UART_BAUD;
  6234. + frac = (temp >> 1) + (temp & 1);
  6235. +
  6236. + /* Make sure the UART is disabled before we start */
  6237. + __raw_writel(0, BCM2708_UART_CR);
  6238. +
  6239. + /* Set the baud rate */
  6240. + __raw_writel(div, BCM2708_UART_IBRD);
  6241. + __raw_writel(frac, BCM2708_UART_FBRD);
  6242. +
  6243. + /* Set the UART to 8n1, FIFO enabled */
  6244. + __raw_writel(UART01x_LCRH_WLEN_8 | UART01x_LCRH_FEN, BCM2708_UART_LCRH);
  6245. +
  6246. + /* Enable the UART */
  6247. + __raw_writel(UART01x_CR_UARTEN | UART011_CR_TXE | UART011_CR_RXE,
  6248. + BCM2708_UART_CR);
  6249. +}
  6250. +
  6251. +/*
  6252. + * nothing to do
  6253. + */
  6254. +#define arch_decomp_wdog()
  6255. diff -Nur linux-3.13.3.orig/arch/arm/mach-bcm2708/include/mach/vcio.h linux-3.13.3/arch/arm/mach-bcm2708/include/mach/vcio.h
  6256. --- linux-3.13.3.orig/arch/arm/mach-bcm2708/include/mach/vcio.h 1970-01-01 01:00:00.000000000 +0100
  6257. +++ linux-3.13.3/arch/arm/mach-bcm2708/include/mach/vcio.h 2014-02-17 22:41:01.000000000 +0100
  6258. @@ -0,0 +1,141 @@
  6259. +/*
  6260. + * arch/arm/mach-bcm2708/include/mach/vcio.h
  6261. + *
  6262. + * Copyright (C) 2010 Broadcom
  6263. + *
  6264. + * This program is free software; you can redistribute it and/or modify
  6265. + * it under the terms of the GNU General Public License as published by
  6266. + * the Free Software Foundation; either version 2 of the License, or
  6267. + * (at your option) any later version.
  6268. + *
  6269. + * This program is distributed in the hope that it will be useful,
  6270. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6271. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6272. + * GNU General Public License for more details.
  6273. + *
  6274. + * You should have received a copy of the GNU General Public License
  6275. + * along with this program; if not, write to the Free Software
  6276. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6277. + */
  6278. +#ifndef _MACH_BCM2708_VCIO_H
  6279. +#define _MACH_BCM2708_VCIO_H
  6280. +
  6281. +/* Routines to handle I/O via the VideoCore "ARM control" registers
  6282. + * (semaphores, doorbells, mailboxes)
  6283. + */
  6284. +
  6285. +#define BCM_VCIO_DRIVER_NAME "bcm2708_vcio"
  6286. +
  6287. +/* Constants shared with the ARM identifying separate mailbox channels */
  6288. +#define MBOX_CHAN_POWER 0 /* for use by the power management interface */
  6289. +#define MBOX_CHAN_FB 1 /* for use by the frame buffer */
  6290. +#define MBOX_CHAN_VCHIQ 3 /* for use by the VCHIQ interface */
  6291. +#define MBOX_CHAN_PROPERTY 8 /* for use by the property channel */
  6292. +#define MBOX_CHAN_COUNT 9
  6293. +
  6294. +/* Mailbox property tags */
  6295. +enum {
  6296. + VCMSG_PROPERTY_END = 0x00000000,
  6297. + VCMSG_GET_FIRMWARE_REVISION = 0x00000001,
  6298. + VCMSG_GET_BOARD_MODEL = 0x00010001,
  6299. + VCMSG_GET_BOARD_REVISION = 0x00020002,
  6300. + VCMSG_GET_BOARD_MAC_ADDRESS = 0x00020003,
  6301. + VCMSG_GET_BOARD_SERIAL = 0x00020004,
  6302. + VCMSG_GET_ARM_MEMORY = 0x00020005,
  6303. + VCMSG_GET_VC_MEMORY = 0x00020006,
  6304. + VCMSG_GET_CLOCKS = 0x00020007,
  6305. + VCMSG_GET_COMMAND_LINE = 0x00050001,
  6306. + VCMSG_GET_DMA_CHANNELS = 0x00060001,
  6307. + VCMSG_GET_POWER_STATE = 0x00020001,
  6308. + VCMSG_GET_TIMING = 0x00020002,
  6309. + VCMSG_SET_POWER_STATE = 0x00028001,
  6310. + VCMSG_GET_CLOCK_STATE = 0x00030001,
  6311. + VCMSG_SET_CLOCK_STATE = 0x00038001,
  6312. + VCMSG_GET_CLOCK_RATE = 0x00030002,
  6313. + VCMSG_SET_CLOCK_RATE = 0x00038002,
  6314. + VCMSG_GET_VOLTAGE = 0x00030003,
  6315. + VCMSG_SET_VOLTAGE = 0x00038003,
  6316. + VCMSG_GET_MAX_CLOCK = 0x00030004,
  6317. + VCMSG_GET_MAX_VOLTAGE = 0x00030005,
  6318. + VCMSG_GET_TEMPERATURE = 0x00030006,
  6319. + VCMSG_GET_MIN_CLOCK = 0x00030007,
  6320. + VCMSG_GET_MIN_VOLTAGE = 0x00030008,
  6321. + VCMSG_GET_TURBO = 0x00030009,
  6322. + VCMSG_SET_TURBO = 0x00038009,
  6323. + VCMSG_SET_ALLOCATE_BUFFER = 0x00040001,
  6324. + VCMSG_SET_RELEASE_BUFFER = 0x00048001,
  6325. + VCMSG_SET_BLANK_SCREEN = 0x00040002,
  6326. + VCMSG_TST_BLANK_SCREEN = 0x00044002,
  6327. + VCMSG_GET_PHYSICAL_WIDTH_HEIGHT = 0x00040003,
  6328. + VCMSG_TST_PHYSICAL_WIDTH_HEIGHT = 0x00044003,
  6329. + VCMSG_SET_PHYSICAL_WIDTH_HEIGHT = 0x00048003,
  6330. + VCMSG_GET_VIRTUAL_WIDTH_HEIGHT = 0x00040004,
  6331. + VCMSG_TST_VIRTUAL_WIDTH_HEIGHT = 0x00044004,
  6332. + VCMSG_SET_VIRTUAL_WIDTH_HEIGHT = 0x00048004,
  6333. + VCMSG_GET_DEPTH = 0x00040005,
  6334. + VCMSG_TST_DEPTH = 0x00044005,
  6335. + VCMSG_SET_DEPTH = 0x00048005,
  6336. + VCMSG_GET_PIXEL_ORDER = 0x00040006,
  6337. + VCMSG_TST_PIXEL_ORDER = 0x00044006,
  6338. + VCMSG_SET_PIXEL_ORDER = 0x00048006,
  6339. + VCMSG_GET_ALPHA_MODE = 0x00040007,
  6340. + VCMSG_TST_ALPHA_MODE = 0x00044007,
  6341. + VCMSG_SET_ALPHA_MODE = 0x00048007,
  6342. + VCMSG_GET_PITCH = 0x00040008,
  6343. + VCMSG_TST_PITCH = 0x00044008,
  6344. + VCMSG_SET_PITCH = 0x00048008,
  6345. + VCMSG_GET_VIRTUAL_OFFSET = 0x00040009,
  6346. + VCMSG_TST_VIRTUAL_OFFSET = 0x00044009,
  6347. + VCMSG_SET_VIRTUAL_OFFSET = 0x00048009,
  6348. + VCMSG_GET_OVERSCAN = 0x0004000a,
  6349. + VCMSG_TST_OVERSCAN = 0x0004400a,
  6350. + VCMSG_SET_OVERSCAN = 0x0004800a,
  6351. + VCMSG_GET_PALETTE = 0x0004000b,
  6352. + VCMSG_TST_PALETTE = 0x0004400b,
  6353. + VCMSG_SET_PALETTE = 0x0004800b,
  6354. + VCMSG_GET_LAYER = 0x0004000c,
  6355. + VCMSG_TST_LAYER = 0x0004400c,
  6356. + VCMSG_SET_LAYER = 0x0004800c,
  6357. + VCMSG_GET_TRANSFORM = 0x0004000d,
  6358. + VCMSG_TST_TRANSFORM = 0x0004400d,
  6359. + VCMSG_SET_TRANSFORM = 0x0004800d,
  6360. +};
  6361. +
  6362. +extern int /*rc*/ bcm_mailbox_read(unsigned chan, uint32_t *data28);
  6363. +extern int /*rc*/ bcm_mailbox_write(unsigned chan, uint32_t data28);
  6364. +extern int /*rc*/ bcm_mailbox_property(void *data, int size);
  6365. +
  6366. +#include <linux/ioctl.h>
  6367. +
  6368. +/*
  6369. + * The major device number. We can't rely on dynamic
  6370. + * registration any more, because ioctls need to know
  6371. + * it.
  6372. + */
  6373. +#define MAJOR_NUM 100
  6374. +
  6375. +/*
  6376. + * Set the message of the device driver
  6377. + */
  6378. +#define IOCTL_MBOX_PROPERTY _IOWR(MAJOR_NUM, 0, char *)
  6379. +/*
  6380. + * _IOWR means that we're creating an ioctl command
  6381. + * number for passing information from a user process
  6382. + * to the kernel module and from the kernel module to user process
  6383. + *
  6384. + * The first arguments, MAJOR_NUM, is the major device
  6385. + * number we're using.
  6386. + *
  6387. + * The second argument is the number of the command
  6388. + * (there could be several with different meanings).
  6389. + *
  6390. + * The third argument is the type we want to get from
  6391. + * the process to the kernel.
  6392. + */
  6393. +
  6394. +/*
  6395. + * The name of the device file
  6396. + */
  6397. +#define DEVICE_FILE_NAME "char_dev"
  6398. +
  6399. +#endif
  6400. diff -Nur linux-3.13.3.orig/arch/arm/mach-bcm2708/include/mach/vc_mem.h linux-3.13.3/arch/arm/mach-bcm2708/include/mach/vc_mem.h
  6401. --- linux-3.13.3.orig/arch/arm/mach-bcm2708/include/mach/vc_mem.h 1970-01-01 01:00:00.000000000 +0100
  6402. +++ linux-3.13.3/arch/arm/mach-bcm2708/include/mach/vc_mem.h 2014-02-17 22:41:01.000000000 +0100
  6403. @@ -0,0 +1,35 @@
  6404. +/*****************************************************************************
  6405. +* Copyright 2010 - 2011 Broadcom Corporation. All rights reserved.
  6406. +*
  6407. +* Unless you and Broadcom execute a separate written software license
  6408. +* agreement governing use of this software, this software is licensed to you
  6409. +* under the terms of the GNU General Public License version 2, available at
  6410. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  6411. +*
  6412. +* Notwithstanding the above, under no circumstances may you combine this
  6413. +* software in any way with any other Broadcom software provided under a
  6414. +* license other than the GPL, without Broadcom's express prior written
  6415. +* consent.
  6416. +*****************************************************************************/
  6417. +
  6418. +#if !defined( VC_MEM_H )
  6419. +#define VC_MEM_H
  6420. +
  6421. +#include <linux/ioctl.h>
  6422. +
  6423. +#define VC_MEM_IOC_MAGIC 'v'
  6424. +
  6425. +#define VC_MEM_IOC_MEM_PHYS_ADDR _IOR( VC_MEM_IOC_MAGIC, 0, unsigned long )
  6426. +#define VC_MEM_IOC_MEM_SIZE _IOR( VC_MEM_IOC_MAGIC, 1, unsigned int )
  6427. +#define VC_MEM_IOC_MEM_BASE _IOR( VC_MEM_IOC_MAGIC, 2, unsigned int )
  6428. +#define VC_MEM_IOC_MEM_LOAD _IOR( VC_MEM_IOC_MAGIC, 3, unsigned int )
  6429. +
  6430. +#if defined( __KERNEL__ )
  6431. +#define VC_MEM_TO_ARM_ADDR_MASK 0x3FFFFFFF
  6432. +
  6433. +extern unsigned long mm_vc_mem_phys_addr;
  6434. +extern unsigned int mm_vc_mem_size;
  6435. +extern int vc_mem_get_current_size( void );
  6436. +#endif
  6437. +
  6438. +#endif /* VC_MEM_H */
  6439. diff -Nur linux-3.13.3.orig/arch/arm/mach-bcm2708/include/mach/vmalloc.h linux-3.13.3/arch/arm/mach-bcm2708/include/mach/vmalloc.h
  6440. --- linux-3.13.3.orig/arch/arm/mach-bcm2708/include/mach/vmalloc.h 1970-01-01 01:00:00.000000000 +0100
  6441. +++ linux-3.13.3/arch/arm/mach-bcm2708/include/mach/vmalloc.h 2014-02-17 22:41:01.000000000 +0100
  6442. @@ -0,0 +1,20 @@
  6443. +/*
  6444. + * arch/arm/mach-bcm2708/include/mach/vmalloc.h
  6445. + *
  6446. + * Copyright (C) 2010 Broadcom
  6447. + *
  6448. + * This program is free software; you can redistribute it and/or modify
  6449. + * it under the terms of the GNU General Public License as published by
  6450. + * the Free Software Foundation; either version 2 of the License, or
  6451. + * (at your option) any later version.
  6452. + *
  6453. + * This program is distributed in the hope that it will be useful,
  6454. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6455. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6456. + * GNU General Public License for more details.
  6457. + *
  6458. + * You should have received a copy of the GNU General Public License
  6459. + * along with this program; if not, write to the Free Software
  6460. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6461. + */
  6462. +#define VMALLOC_END (0xe8000000)
  6463. diff -Nur linux-3.13.3.orig/arch/arm/mach-bcm2708/Kconfig linux-3.13.3/arch/arm/mach-bcm2708/Kconfig
  6464. --- linux-3.13.3.orig/arch/arm/mach-bcm2708/Kconfig 1970-01-01 01:00:00.000000000 +0100
  6465. +++ linux-3.13.3/arch/arm/mach-bcm2708/Kconfig 2014-02-17 22:41:01.000000000 +0100
  6466. @@ -0,0 +1,41 @@
  6467. +menu "Broadcom BCM2708 Implementations"
  6468. + depends on ARCH_BCM2708
  6469. +
  6470. +config MACH_BCM2708
  6471. + bool "Broadcom BCM2708 Development Platform"
  6472. + select NEED_MACH_MEMORY_H
  6473. + select NEED_MACH_IO_H
  6474. + select CPU_V6
  6475. + help
  6476. + Include support for the Broadcom(R) BCM2708 platform.
  6477. +
  6478. +config BCM2708_GPIO
  6479. + bool "BCM2708 gpio support"
  6480. + depends on MACH_BCM2708
  6481. + select ARCH_REQUIRE_GPIOLIB
  6482. + default y
  6483. + help
  6484. + Include support for the Broadcom(R) BCM2708 gpio.
  6485. +
  6486. +config BCM2708_VCMEM
  6487. + bool "Videocore Memory"
  6488. + depends on MACH_BCM2708
  6489. + default y
  6490. + help
  6491. + Helper for videocore memory access and total size allocation.
  6492. +
  6493. +config BCM2708_NOL2CACHE
  6494. + bool "Videocore L2 cache disable"
  6495. + depends on MACH_BCM2708
  6496. + default n
  6497. + help
  6498. + Do not allow ARM to use GPU's L2 cache. Requires disable_l2cache in config.txt.
  6499. +
  6500. +config BCM2708_SPIDEV
  6501. + bool "Bind spidev to SPI0 master"
  6502. + depends on MACH_BCM2708
  6503. + depends on SPI
  6504. + default y
  6505. + help
  6506. + Binds spidev driver to the SPI0 master
  6507. +endmenu
  6508. diff -Nur linux-3.13.3.orig/arch/arm/mach-bcm2708/Makefile linux-3.13.3/arch/arm/mach-bcm2708/Makefile
  6509. --- linux-3.13.3.orig/arch/arm/mach-bcm2708/Makefile 1970-01-01 01:00:00.000000000 +0100
  6510. +++ linux-3.13.3/arch/arm/mach-bcm2708/Makefile 2014-02-17 22:41:01.000000000 +0100
  6511. @@ -0,0 +1,7 @@
  6512. +#
  6513. +# Makefile for the linux kernel.
  6514. +#
  6515. +
  6516. +obj-$(CONFIG_MACH_BCM2708) += clock.o bcm2708.o armctrl.o vcio.o power.o dma.o
  6517. +obj-$(CONFIG_BCM2708_GPIO) += bcm2708_gpio.o
  6518. +obj-$(CONFIG_BCM2708_VCMEM) += vc_mem.o
  6519. diff -Nur linux-3.13.3.orig/arch/arm/mach-bcm2708/Makefile.boot linux-3.13.3/arch/arm/mach-bcm2708/Makefile.boot
  6520. --- linux-3.13.3.orig/arch/arm/mach-bcm2708/Makefile.boot 1970-01-01 01:00:00.000000000 +0100
  6521. +++ linux-3.13.3/arch/arm/mach-bcm2708/Makefile.boot 2014-02-17 22:41:01.000000000 +0100
  6522. @@ -0,0 +1,3 @@
  6523. + zreladdr-y := 0x00008000
  6524. +params_phys-y := 0x00000100
  6525. +initrd_phys-y := 0x00800000
  6526. diff -Nur linux-3.13.3.orig/arch/arm/mach-bcm2708/power.c linux-3.13.3/arch/arm/mach-bcm2708/power.c
  6527. --- linux-3.13.3.orig/arch/arm/mach-bcm2708/power.c 1970-01-01 01:00:00.000000000 +0100
  6528. +++ linux-3.13.3/arch/arm/mach-bcm2708/power.c 2014-02-17 22:41:01.000000000 +0100
  6529. @@ -0,0 +1,194 @@
  6530. +/*
  6531. + * linux/arch/arm/mach-bcm2708/power.c
  6532. + *
  6533. + * Copyright (C) 2010 Broadcom
  6534. + *
  6535. + * This program is free software; you can redistribute it and/or modify
  6536. + * it under the terms of the GNU General Public License version 2 as
  6537. + * published by the Free Software Foundation.
  6538. + *
  6539. + * This device provides a shared mechanism for controlling the power to
  6540. + * VideoCore subsystems.
  6541. + */
  6542. +
  6543. +#include <linux/module.h>
  6544. +#include <linux/semaphore.h>
  6545. +#include <linux/bug.h>
  6546. +#include <mach/power.h>
  6547. +#include <mach/vcio.h>
  6548. +#include <mach/arm_power.h>
  6549. +
  6550. +#define DRIVER_NAME "bcm2708_power"
  6551. +
  6552. +#define BCM_POWER_MAXCLIENTS 4
  6553. +#define BCM_POWER_NOCLIENT (1<<31)
  6554. +
  6555. +/* Some drivers expect there devices to be permanently powered */
  6556. +#define BCM_POWER_ALWAYS_ON (BCM_POWER_USB)
  6557. +
  6558. +#if 1
  6559. +#define DPRINTK printk
  6560. +#else
  6561. +#define DPRINTK if (0) printk
  6562. +#endif
  6563. +
  6564. +struct state_struct {
  6565. + uint32_t global_request;
  6566. + uint32_t client_request[BCM_POWER_MAXCLIENTS];
  6567. + struct semaphore client_mutex;
  6568. + struct semaphore mutex;
  6569. +} g_state;
  6570. +
  6571. +int bcm_power_open(BCM_POWER_HANDLE_T *handle)
  6572. +{
  6573. + BCM_POWER_HANDLE_T i;
  6574. + int ret = -EBUSY;
  6575. +
  6576. + down(&g_state.client_mutex);
  6577. +
  6578. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++) {
  6579. + if (g_state.client_request[i] == BCM_POWER_NOCLIENT) {
  6580. + g_state.client_request[i] = BCM_POWER_NONE;
  6581. + *handle = i;
  6582. + ret = 0;
  6583. + break;
  6584. + }
  6585. + }
  6586. +
  6587. + up(&g_state.client_mutex);
  6588. +
  6589. + DPRINTK("bcm_power_open() -> %d\n", *handle);
  6590. +
  6591. + return ret;
  6592. +}
  6593. +EXPORT_SYMBOL_GPL(bcm_power_open);
  6594. +
  6595. +int bcm_power_request(BCM_POWER_HANDLE_T handle, uint32_t request)
  6596. +{
  6597. + int rc = 0;
  6598. +
  6599. + DPRINTK("bcm_power_request(%d, %x)\n", handle, request);
  6600. +
  6601. + if ((handle < BCM_POWER_MAXCLIENTS) &&
  6602. + (g_state.client_request[handle] != BCM_POWER_NOCLIENT)) {
  6603. + if (down_interruptible(&g_state.mutex) != 0) {
  6604. + DPRINTK("bcm_power_request -> interrupted\n");
  6605. + return -EINTR;
  6606. + }
  6607. +
  6608. + if (request != g_state.client_request[handle]) {
  6609. + uint32_t others_request = 0;
  6610. + uint32_t global_request;
  6611. + BCM_POWER_HANDLE_T i;
  6612. +
  6613. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++) {
  6614. + if (i != handle)
  6615. + others_request |=
  6616. + g_state.client_request[i];
  6617. + }
  6618. + others_request &= ~BCM_POWER_NOCLIENT;
  6619. +
  6620. + global_request = request | others_request;
  6621. + if (global_request != g_state.global_request) {
  6622. + uint32_t actual;
  6623. +
  6624. + /* Send a request to VideoCore */
  6625. + bcm_mailbox_write(MBOX_CHAN_POWER,
  6626. + global_request << 4);
  6627. +
  6628. + /* Wait for a response during power-up */
  6629. + if (global_request & ~g_state.global_request) {
  6630. + rc = bcm_mailbox_read(MBOX_CHAN_POWER,
  6631. + &actual);
  6632. + DPRINTK
  6633. + ("bcm_mailbox_read -> %08x, %d\n",
  6634. + actual, rc);
  6635. + actual >>= 4;
  6636. + } else {
  6637. + rc = 0;
  6638. + actual = global_request;
  6639. + }
  6640. +
  6641. + if (rc == 0) {
  6642. + if (actual != global_request) {
  6643. + printk(KERN_ERR
  6644. + "%s: prev global %x, new global %x, actual %x, request %x, others_request %x\n",
  6645. + __func__,
  6646. + g_state.global_request,
  6647. + global_request, actual, request, others_request);
  6648. + /* A failure */
  6649. + BUG_ON((others_request & actual)
  6650. + != others_request);
  6651. + request &= actual;
  6652. + rc = -EIO;
  6653. + }
  6654. +
  6655. + g_state.global_request = actual;
  6656. + g_state.client_request[handle] =
  6657. + request;
  6658. + }
  6659. + }
  6660. + }
  6661. + up(&g_state.mutex);
  6662. + } else {
  6663. + rc = -EINVAL;
  6664. + }
  6665. + DPRINTK("bcm_power_request -> %d\n", rc);
  6666. + return rc;
  6667. +}
  6668. +EXPORT_SYMBOL_GPL(bcm_power_request);
  6669. +
  6670. +int bcm_power_close(BCM_POWER_HANDLE_T handle)
  6671. +{
  6672. + int rc;
  6673. +
  6674. + DPRINTK("bcm_power_close(%d)\n", handle);
  6675. +
  6676. + rc = bcm_power_request(handle, BCM_POWER_NONE);
  6677. + if (rc == 0)
  6678. + g_state.client_request[handle] = BCM_POWER_NOCLIENT;
  6679. +
  6680. + return rc;
  6681. +}
  6682. +EXPORT_SYMBOL_GPL(bcm_power_close);
  6683. +
  6684. +static int __init bcm_power_init(void)
  6685. +{
  6686. +#if defined(BCM_POWER_ALWAYS_ON)
  6687. + BCM_POWER_HANDLE_T always_on_handle;
  6688. +#endif
  6689. + int rc = 0;
  6690. + int i;
  6691. +
  6692. + printk(KERN_INFO "bcm_power: Broadcom power driver\n");
  6693. + bcm_mailbox_write(MBOX_CHAN_POWER, 0);
  6694. +
  6695. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++)
  6696. + g_state.client_request[i] = BCM_POWER_NOCLIENT;
  6697. +
  6698. + sema_init(&g_state.client_mutex, 1);
  6699. + sema_init(&g_state.mutex, 1);
  6700. +
  6701. + g_state.global_request = 0;
  6702. +
  6703. +#if defined(BCM_POWER_ALWAYS_ON)
  6704. + if (BCM_POWER_ALWAYS_ON) {
  6705. + bcm_power_open(&always_on_handle);
  6706. + bcm_power_request(always_on_handle, BCM_POWER_ALWAYS_ON);
  6707. + }
  6708. +#endif
  6709. +
  6710. + return rc;
  6711. +}
  6712. +
  6713. +static void __exit bcm_power_exit(void)
  6714. +{
  6715. + bcm_mailbox_write(MBOX_CHAN_POWER, 0);
  6716. +}
  6717. +
  6718. +arch_initcall(bcm_power_init); /* Initialize early */
  6719. +module_exit(bcm_power_exit);
  6720. +
  6721. +MODULE_AUTHOR("Phil Elwell");
  6722. +MODULE_DESCRIPTION("Interface to BCM2708 power management");
  6723. +MODULE_LICENSE("GPL");
  6724. diff -Nur linux-3.13.3.orig/arch/arm/mach-bcm2708/vcio.c linux-3.13.3/arch/arm/mach-bcm2708/vcio.c
  6725. --- linux-3.13.3.orig/arch/arm/mach-bcm2708/vcio.c 1970-01-01 01:00:00.000000000 +0100
  6726. +++ linux-3.13.3/arch/arm/mach-bcm2708/vcio.c 2014-02-17 22:41:01.000000000 +0100
  6727. @@ -0,0 +1,474 @@
  6728. +/*
  6729. + * linux/arch/arm/mach-bcm2708/vcio.c
  6730. + *
  6731. + * Copyright (C) 2010 Broadcom
  6732. + *
  6733. + * This program is free software; you can redistribute it and/or modify
  6734. + * it under the terms of the GNU General Public License version 2 as
  6735. + * published by the Free Software Foundation.
  6736. + *
  6737. + * This device provides a shared mechanism for writing to the mailboxes,
  6738. + * semaphores, doorbells etc. that are shared between the ARM and the
  6739. + * VideoCore processor
  6740. + */
  6741. +
  6742. +#if defined(CONFIG_SERIAL_BCM_MBOX_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
  6743. +#define SUPPORT_SYSRQ
  6744. +#endif
  6745. +
  6746. +#include <linux/module.h>
  6747. +#include <linux/console.h>
  6748. +#include <linux/serial_core.h>
  6749. +#include <linux/serial.h>
  6750. +#include <linux/errno.h>
  6751. +#include <linux/device.h>
  6752. +#include <linux/init.h>
  6753. +#include <linux/mm.h>
  6754. +#include <linux/dma-mapping.h>
  6755. +#include <linux/platform_device.h>
  6756. +#include <linux/sysrq.h>
  6757. +#include <linux/delay.h>
  6758. +#include <linux/slab.h>
  6759. +#include <linux/interrupt.h>
  6760. +#include <linux/irq.h>
  6761. +
  6762. +#include <linux/io.h>
  6763. +
  6764. +#include <mach/vcio.h>
  6765. +#include <mach/platform.h>
  6766. +
  6767. +#include <asm/uaccess.h>
  6768. +
  6769. +
  6770. +#define DRIVER_NAME BCM_VCIO_DRIVER_NAME
  6771. +
  6772. +/* ----------------------------------------------------------------------
  6773. + * Mailbox
  6774. + * -------------------------------------------------------------------- */
  6775. +
  6776. +/* offsets from a mail box base address */
  6777. +#define MAIL_WRT 0x00 /* write - and next 4 words */
  6778. +#define MAIL_RD 0x00 /* read - and next 4 words */
  6779. +#define MAIL_POL 0x10 /* read without popping the fifo */
  6780. +#define MAIL_SND 0x14 /* sender ID (bottom two bits) */
  6781. +#define MAIL_STA 0x18 /* status */
  6782. +#define MAIL_CNF 0x1C /* configuration */
  6783. +
  6784. +#define MBOX_MSG(chan, data28) (((data28) & ~0xf) | ((chan) & 0xf))
  6785. +#define MBOX_MSG_LSB(chan, data28) (((data28) << 4) | ((chan) & 0xf))
  6786. +#define MBOX_CHAN(msg) ((msg) & 0xf)
  6787. +#define MBOX_DATA28(msg) ((msg) & ~0xf)
  6788. +#define MBOX_DATA28_LSB(msg) (((uint32_t)msg) >> 4)
  6789. +
  6790. +#define MBOX_MAGIC 0xd0d0c0de
  6791. +
  6792. +struct vc_mailbox {
  6793. + struct device *dev; /* parent device */
  6794. + void __iomem *status;
  6795. + void __iomem *config;
  6796. + void __iomem *read;
  6797. + void __iomem *write;
  6798. + uint32_t msg[MBOX_CHAN_COUNT];
  6799. + struct semaphore sema[MBOX_CHAN_COUNT];
  6800. + uint32_t magic;
  6801. +};
  6802. +
  6803. +static void mbox_init(struct vc_mailbox *mbox_out, struct device *dev,
  6804. + uint32_t addr_mbox)
  6805. +{
  6806. + int i;
  6807. +
  6808. + mbox_out->dev = dev;
  6809. + mbox_out->status = __io_address(addr_mbox + MAIL_STA);
  6810. + mbox_out->config = __io_address(addr_mbox + MAIL_CNF);
  6811. + mbox_out->read = __io_address(addr_mbox + MAIL_RD);
  6812. + /* Write to the other mailbox */
  6813. + mbox_out->write =
  6814. + __io_address((addr_mbox ^ ARM_0_MAIL0_WRT ^ ARM_0_MAIL1_WRT) +
  6815. + MAIL_WRT);
  6816. +
  6817. + for (i = 0; i < MBOX_CHAN_COUNT; i++) {
  6818. + mbox_out->msg[i] = 0;
  6819. + sema_init(&mbox_out->sema[i], 0);
  6820. + }
  6821. +
  6822. + /* Enable the interrupt on data reception */
  6823. + writel(ARM_MC_IHAVEDATAIRQEN, mbox_out->config);
  6824. +
  6825. + mbox_out->magic = MBOX_MAGIC;
  6826. +}
  6827. +
  6828. +static int mbox_write(struct vc_mailbox *mbox, unsigned chan, uint32_t data28)
  6829. +{
  6830. + int rc;
  6831. +
  6832. + if (mbox->magic != MBOX_MAGIC)
  6833. + rc = -EINVAL;
  6834. + else {
  6835. + /* wait for the mailbox FIFO to have some space in it */
  6836. + while (0 != (readl(mbox->status) & ARM_MS_FULL))
  6837. + cpu_relax();
  6838. +
  6839. + writel(MBOX_MSG(chan, data28), mbox->write);
  6840. + rc = 0;
  6841. + }
  6842. + return rc;
  6843. +}
  6844. +
  6845. +static int mbox_read(struct vc_mailbox *mbox, unsigned chan, uint32_t *data28)
  6846. +{
  6847. + int rc;
  6848. +
  6849. + if (mbox->magic != MBOX_MAGIC)
  6850. + rc = -EINVAL;
  6851. + else {
  6852. + down(&mbox->sema[chan]);
  6853. + *data28 = MBOX_DATA28(mbox->msg[chan]);
  6854. + mbox->msg[chan] = 0;
  6855. + rc = 0;
  6856. + }
  6857. + return rc;
  6858. +}
  6859. +
  6860. +static irqreturn_t mbox_irq(int irq, void *dev_id)
  6861. +{
  6862. + /* wait for the mailbox FIFO to have some data in it */
  6863. + struct vc_mailbox *mbox = (struct vc_mailbox *) dev_id;
  6864. + int status = readl(mbox->status);
  6865. + int ret = IRQ_NONE;
  6866. +
  6867. + while (!(status & ARM_MS_EMPTY)) {
  6868. + uint32_t msg = readl(mbox->read);
  6869. + int chan = MBOX_CHAN(msg);
  6870. + if (chan < MBOX_CHAN_COUNT) {
  6871. + if (mbox->msg[chan]) {
  6872. + /* Overflow */
  6873. + printk(KERN_ERR DRIVER_NAME
  6874. + ": mbox chan %d overflow - drop %08x\n",
  6875. + chan, msg);
  6876. + } else {
  6877. + mbox->msg[chan] = (msg | 0xf);
  6878. + up(&mbox->sema[chan]);
  6879. + }
  6880. + } else {
  6881. + printk(KERN_ERR DRIVER_NAME
  6882. + ": invalid channel selector (msg %08x)\n", msg);
  6883. + }
  6884. + ret = IRQ_HANDLED;
  6885. + status = readl(mbox->status);
  6886. + }
  6887. + return ret;
  6888. +}
  6889. +
  6890. +static struct irqaction mbox_irqaction = {
  6891. + .name = "ARM Mailbox IRQ",
  6892. + .flags = IRQF_DISABLED | IRQF_IRQPOLL,
  6893. + .handler = mbox_irq,
  6894. +};
  6895. +
  6896. +/* ----------------------------------------------------------------------
  6897. + * Mailbox Methods
  6898. + * -------------------------------------------------------------------- */
  6899. +
  6900. +static struct device *mbox_dev; /* we assume there's only one! */
  6901. +
  6902. +static int dev_mbox_write(struct device *dev, unsigned chan, uint32_t data28)
  6903. +{
  6904. + int rc;
  6905. +
  6906. + struct vc_mailbox *mailbox = dev_get_drvdata(dev);
  6907. + device_lock(dev);
  6908. + rc = mbox_write(mailbox, chan, data28);
  6909. + device_unlock(dev);
  6910. +
  6911. + return rc;
  6912. +}
  6913. +
  6914. +static int dev_mbox_read(struct device *dev, unsigned chan, uint32_t *data28)
  6915. +{
  6916. + int rc;
  6917. +
  6918. + struct vc_mailbox *mailbox = dev_get_drvdata(dev);
  6919. + device_lock(dev);
  6920. + rc = mbox_read(mailbox, chan, data28);
  6921. + device_unlock(dev);
  6922. +
  6923. + return rc;
  6924. +}
  6925. +
  6926. +extern int bcm_mailbox_write(unsigned chan, uint32_t data28)
  6927. +{
  6928. + if (mbox_dev)
  6929. + return dev_mbox_write(mbox_dev, chan, data28);
  6930. + else
  6931. + return -ENODEV;
  6932. +}
  6933. +EXPORT_SYMBOL_GPL(bcm_mailbox_write);
  6934. +
  6935. +extern int bcm_mailbox_read(unsigned chan, uint32_t *data28)
  6936. +{
  6937. + if (mbox_dev)
  6938. + return dev_mbox_read(mbox_dev, chan, data28);
  6939. + else
  6940. + return -ENODEV;
  6941. +}
  6942. +EXPORT_SYMBOL_GPL(bcm_mailbox_read);
  6943. +
  6944. +static void dev_mbox_register(const char *dev_name, struct device *dev)
  6945. +{
  6946. + mbox_dev = dev;
  6947. +}
  6948. +
  6949. +static int mbox_copy_from_user(void *dst, const void *src, int size)
  6950. +{
  6951. + if ( (uint32_t)src < TASK_SIZE)
  6952. + {
  6953. + return copy_from_user(dst, src, size);
  6954. + }
  6955. + else
  6956. + {
  6957. + memcpy( dst, src, size );
  6958. + return 0;
  6959. + }
  6960. +}
  6961. +
  6962. +static int mbox_copy_to_user(void *dst, const void *src, int size)
  6963. +{
  6964. + if ( (uint32_t)dst < TASK_SIZE)
  6965. + {
  6966. + return copy_to_user(dst, src, size);
  6967. + }
  6968. + else
  6969. + {
  6970. + memcpy( dst, src, size );
  6971. + return 0;
  6972. + }
  6973. +}
  6974. +
  6975. +static DEFINE_MUTEX(mailbox_lock);
  6976. +extern int bcm_mailbox_property(void *data, int size)
  6977. +{
  6978. + uint32_t success;
  6979. + dma_addr_t mem_bus; /* the memory address accessed from videocore */
  6980. + void *mem_kern; /* the memory address accessed from driver */
  6981. + int s = 0;
  6982. +
  6983. + mutex_lock(&mailbox_lock);
  6984. + /* allocate some memory for the messages communicating with GPU */
  6985. + mem_kern = dma_alloc_coherent(NULL, PAGE_ALIGN(size), &mem_bus, GFP_ATOMIC);
  6986. + if (mem_kern) {
  6987. + /* create the message */
  6988. + mbox_copy_from_user(mem_kern, data, size);
  6989. +
  6990. + /* send the message */
  6991. + wmb();
  6992. + s = bcm_mailbox_write(MBOX_CHAN_PROPERTY, (uint32_t)mem_bus);
  6993. + if (s == 0) {
  6994. + s = bcm_mailbox_read(MBOX_CHAN_PROPERTY, &success);
  6995. + }
  6996. + if (s == 0) {
  6997. + /* copy the response */
  6998. + rmb();
  6999. + mbox_copy_to_user(data, mem_kern, size);
  7000. + }
  7001. + dma_free_coherent(NULL, PAGE_ALIGN(size), mem_kern, mem_bus);
  7002. + } else {
  7003. + s = -ENOMEM;
  7004. + }
  7005. + if (s != 0)
  7006. + printk(KERN_ERR DRIVER_NAME ": %s failed (%d)\n", __func__, s);
  7007. +
  7008. + mutex_unlock(&mailbox_lock);
  7009. + return s;
  7010. +}
  7011. +EXPORT_SYMBOL_GPL(bcm_mailbox_property);
  7012. +
  7013. +/* ----------------------------------------------------------------------
  7014. + * Platform Device for Mailbox
  7015. + * -------------------------------------------------------------------- */
  7016. +
  7017. +/*
  7018. + * Is the device open right now? Used to prevent
  7019. + * concurent access into the same device
  7020. + */
  7021. +static int Device_Open = 0;
  7022. +
  7023. +/*
  7024. + * This is called whenever a process attempts to open the device file
  7025. + */
  7026. +static int device_open(struct inode *inode, struct file *file)
  7027. +{
  7028. + /*
  7029. + * We don't want to talk to two processes at the same time
  7030. + */
  7031. + if (Device_Open)
  7032. + return -EBUSY;
  7033. +
  7034. + Device_Open++;
  7035. + /*
  7036. + * Initialize the message
  7037. + */
  7038. + try_module_get(THIS_MODULE);
  7039. + return 0;
  7040. +}
  7041. +
  7042. +static int device_release(struct inode *inode, struct file *file)
  7043. +{
  7044. + /*
  7045. + * We're now ready for our next caller
  7046. + */
  7047. + Device_Open--;
  7048. +
  7049. + module_put(THIS_MODULE);
  7050. + return 0;
  7051. +}
  7052. +
  7053. +/*
  7054. + * This function is called whenever a process tries to do an ioctl on our
  7055. + * device file. We get two extra parameters (additional to the inode and file
  7056. + * structures, which all device functions get): the number of the ioctl called
  7057. + * and the parameter given to the ioctl function.
  7058. + *
  7059. + * If the ioctl is write or read/write (meaning output is returned to the
  7060. + * calling process), the ioctl call returns the output of this function.
  7061. + *
  7062. + */
  7063. +static long device_ioctl(struct file *file, /* see include/linux/fs.h */
  7064. + unsigned int ioctl_num, /* number and param for ioctl */
  7065. + unsigned long ioctl_param)
  7066. +{
  7067. + unsigned size;
  7068. + /*
  7069. + * Switch according to the ioctl called
  7070. + */
  7071. + switch (ioctl_num) {
  7072. + case IOCTL_MBOX_PROPERTY:
  7073. + /*
  7074. + * Receive a pointer to a message (in user space) and set that
  7075. + * to be the device's message. Get the parameter given to
  7076. + * ioctl by the process.
  7077. + */
  7078. + mbox_copy_from_user(&size, (void *)ioctl_param, sizeof size);
  7079. + return bcm_mailbox_property((void *)ioctl_param, size);
  7080. + break;
  7081. + default:
  7082. + printk(KERN_ERR DRIVER_NAME "unknown ioctl: %d\n", ioctl_num);
  7083. + return -EINVAL;
  7084. + }
  7085. +
  7086. + return 0;
  7087. +}
  7088. +
  7089. +/* Module Declarations */
  7090. +
  7091. +/*
  7092. + * This structure will hold the functions to be called
  7093. + * when a process does something to the device we
  7094. + * created. Since a pointer to this structure is kept in
  7095. + * the devices table, it can't be local to
  7096. + * init_module. NULL is for unimplemented functios.
  7097. + */
  7098. +struct file_operations fops = {
  7099. + .unlocked_ioctl = device_ioctl,
  7100. + .open = device_open,
  7101. + .release = device_release, /* a.k.a. close */
  7102. +};
  7103. +
  7104. +static int bcm_vcio_probe(struct platform_device *pdev)
  7105. +{
  7106. + int ret = 0;
  7107. + struct vc_mailbox *mailbox;
  7108. +
  7109. + mailbox = kzalloc(sizeof(*mailbox), GFP_KERNEL);
  7110. + if (NULL == mailbox) {
  7111. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  7112. + "mailbox memory\n");
  7113. + ret = -ENOMEM;
  7114. + } else {
  7115. + struct resource *res;
  7116. +
  7117. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  7118. + if (res == NULL) {
  7119. + printk(KERN_ERR DRIVER_NAME ": failed to obtain memory "
  7120. + "resource\n");
  7121. + ret = -ENODEV;
  7122. + kfree(mailbox);
  7123. + } else {
  7124. + /* should be based on the registers from res really */
  7125. + mbox_init(mailbox, &pdev->dev, ARM_0_MAIL0_RD);
  7126. +
  7127. + platform_set_drvdata(pdev, mailbox);
  7128. + dev_mbox_register(DRIVER_NAME, &pdev->dev);
  7129. +
  7130. + mbox_irqaction.dev_id = mailbox;
  7131. + setup_irq(IRQ_ARM_MAILBOX, &mbox_irqaction);
  7132. + printk(KERN_INFO DRIVER_NAME ": mailbox at %p\n",
  7133. + __io_address(ARM_0_MAIL0_RD));
  7134. + }
  7135. + }
  7136. +
  7137. + if (ret == 0) {
  7138. + /*
  7139. + * Register the character device
  7140. + */
  7141. + ret = register_chrdev(MAJOR_NUM, DEVICE_FILE_NAME, &fops);
  7142. +
  7143. + /*
  7144. + * Negative values signify an error
  7145. + */
  7146. + if (ret < 0) {
  7147. + printk(KERN_ERR DRIVER_NAME
  7148. + "Failed registering the character device %d\n", ret);
  7149. + return ret;
  7150. + }
  7151. + }
  7152. + return ret;
  7153. +}
  7154. +
  7155. +static int bcm_vcio_remove(struct platform_device *pdev)
  7156. +{
  7157. + struct vc_mailbox *mailbox = platform_get_drvdata(pdev);
  7158. +
  7159. + platform_set_drvdata(pdev, NULL);
  7160. + kfree(mailbox);
  7161. +
  7162. + return 0;
  7163. +}
  7164. +
  7165. +static struct platform_driver bcm_mbox_driver = {
  7166. + .probe = bcm_vcio_probe,
  7167. + .remove = bcm_vcio_remove,
  7168. +
  7169. + .driver = {
  7170. + .name = DRIVER_NAME,
  7171. + .owner = THIS_MODULE,
  7172. + },
  7173. +};
  7174. +
  7175. +static int __init bcm_mbox_init(void)
  7176. +{
  7177. + int ret;
  7178. +
  7179. + printk(KERN_INFO "mailbox: Broadcom VideoCore Mailbox driver\n");
  7180. +
  7181. + ret = platform_driver_register(&bcm_mbox_driver);
  7182. + if (ret != 0) {
  7183. + printk(KERN_ERR DRIVER_NAME ": failed to register "
  7184. + "on platform\n");
  7185. + }
  7186. +
  7187. + return ret;
  7188. +}
  7189. +
  7190. +static void __exit bcm_mbox_exit(void)
  7191. +{
  7192. + platform_driver_unregister(&bcm_mbox_driver);
  7193. +}
  7194. +
  7195. +arch_initcall(bcm_mbox_init); /* Initialize early */
  7196. +module_exit(bcm_mbox_exit);
  7197. +
  7198. +MODULE_AUTHOR("Gray Girling");
  7199. +MODULE_DESCRIPTION("ARM I/O to VideoCore processor");
  7200. +MODULE_LICENSE("GPL");
  7201. +MODULE_ALIAS("platform:bcm-mbox");
  7202. diff -Nur linux-3.13.3.orig/arch/arm/mach-bcm2708/vc_mem.c linux-3.13.3/arch/arm/mach-bcm2708/vc_mem.c
  7203. --- linux-3.13.3.orig/arch/arm/mach-bcm2708/vc_mem.c 1970-01-01 01:00:00.000000000 +0100
  7204. +++ linux-3.13.3/arch/arm/mach-bcm2708/vc_mem.c 2014-02-17 22:41:01.000000000 +0100
  7205. @@ -0,0 +1,432 @@
  7206. +/*****************************************************************************
  7207. +* Copyright 2010 - 2011 Broadcom Corporation. All rights reserved.
  7208. +*
  7209. +* Unless you and Broadcom execute a separate written software license
  7210. +* agreement governing use of this software, this software is licensed to you
  7211. +* under the terms of the GNU General Public License version 2, available at
  7212. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  7213. +*
  7214. +* Notwithstanding the above, under no circumstances may you combine this
  7215. +* software in any way with any other Broadcom software provided under a
  7216. +* license other than the GPL, without Broadcom's express prior written
  7217. +* consent.
  7218. +*****************************************************************************/
  7219. +
  7220. +#include <linux/kernel.h>
  7221. +#include <linux/module.h>
  7222. +#include <linux/fs.h>
  7223. +#include <linux/device.h>
  7224. +#include <linux/cdev.h>
  7225. +#include <linux/mm.h>
  7226. +#include <linux/slab.h>
  7227. +#include <linux/debugfs.h>
  7228. +#include <asm/uaccess.h>
  7229. +#include <linux/dma-mapping.h>
  7230. +
  7231. +#ifdef CONFIG_ARCH_KONA
  7232. +#include <chal/chal_ipc.h>
  7233. +#elif CONFIG_ARCH_BCM2708
  7234. +#else
  7235. +#include <csp/chal_ipc.h>
  7236. +#endif
  7237. +
  7238. +#include "mach/vc_mem.h"
  7239. +#include <mach/vcio.h>
  7240. +
  7241. +#define DRIVER_NAME "vc-mem"
  7242. +
  7243. +// Device (/dev) related variables
  7244. +static dev_t vc_mem_devnum = 0;
  7245. +static struct class *vc_mem_class = NULL;
  7246. +static struct cdev vc_mem_cdev;
  7247. +static int vc_mem_inited = 0;
  7248. +
  7249. +#ifdef CONFIG_DEBUG_FS
  7250. +static struct dentry *vc_mem_debugfs_entry;
  7251. +#endif
  7252. +
  7253. +/*
  7254. + * Videocore memory addresses and size
  7255. + *
  7256. + * Drivers that wish to know the videocore memory addresses and sizes should
  7257. + * use these variables instead of the MM_IO_BASE and MM_ADDR_IO defines in
  7258. + * headers. This allows the other drivers to not be tied down to a a certain
  7259. + * address/size at compile time.
  7260. + *
  7261. + * In the future, the goal is to have the videocore memory virtual address and
  7262. + * size be calculated at boot time rather than at compile time. The decision of
  7263. + * where the videocore memory resides and its size would be in the hands of the
  7264. + * bootloader (and/or kernel). When that happens, the values of these variables
  7265. + * would be calculated and assigned in the init function.
  7266. + */
  7267. +// in the 2835 VC in mapped above ARM, but ARM has full access to VC space
  7268. +unsigned long mm_vc_mem_phys_addr = 0x00000000;
  7269. +unsigned int mm_vc_mem_size = 0;
  7270. +unsigned int mm_vc_mem_base = 0;
  7271. +
  7272. +EXPORT_SYMBOL(mm_vc_mem_phys_addr);
  7273. +EXPORT_SYMBOL(mm_vc_mem_size);
  7274. +EXPORT_SYMBOL(mm_vc_mem_base);
  7275. +
  7276. +static uint phys_addr = 0;
  7277. +static uint mem_size = 0;
  7278. +static uint mem_base = 0;
  7279. +
  7280. +
  7281. +/****************************************************************************
  7282. +*
  7283. +* vc_mem_open
  7284. +*
  7285. +***************************************************************************/
  7286. +
  7287. +static int
  7288. +vc_mem_open(struct inode *inode, struct file *file)
  7289. +{
  7290. + (void) inode;
  7291. + (void) file;
  7292. +
  7293. + pr_debug("%s: called file = 0x%p\n", __func__, file);
  7294. +
  7295. + return 0;
  7296. +}
  7297. +
  7298. +/****************************************************************************
  7299. +*
  7300. +* vc_mem_release
  7301. +*
  7302. +***************************************************************************/
  7303. +
  7304. +static int
  7305. +vc_mem_release(struct inode *inode, struct file *file)
  7306. +{
  7307. + (void) inode;
  7308. + (void) file;
  7309. +
  7310. + pr_debug("%s: called file = 0x%p\n", __func__, file);
  7311. +
  7312. + return 0;
  7313. +}
  7314. +
  7315. +/****************************************************************************
  7316. +*
  7317. +* vc_mem_get_size
  7318. +*
  7319. +***************************************************************************/
  7320. +
  7321. +static void
  7322. +vc_mem_get_size(void)
  7323. +{
  7324. +}
  7325. +
  7326. +/****************************************************************************
  7327. +*
  7328. +* vc_mem_get_base
  7329. +*
  7330. +***************************************************************************/
  7331. +
  7332. +static void
  7333. +vc_mem_get_base(void)
  7334. +{
  7335. +}
  7336. +
  7337. +/****************************************************************************
  7338. +*
  7339. +* vc_mem_get_current_size
  7340. +*
  7341. +***************************************************************************/
  7342. +
  7343. +int
  7344. +vc_mem_get_current_size(void)
  7345. +{
  7346. + return mm_vc_mem_size;
  7347. +}
  7348. +
  7349. +EXPORT_SYMBOL_GPL(vc_mem_get_current_size);
  7350. +
  7351. +/****************************************************************************
  7352. +*
  7353. +* vc_mem_ioctl
  7354. +*
  7355. +***************************************************************************/
  7356. +
  7357. +static long
  7358. +vc_mem_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  7359. +{
  7360. + int rc = 0;
  7361. +
  7362. + (void) cmd;
  7363. + (void) arg;
  7364. +
  7365. + pr_debug("%s: called file = 0x%p\n", __func__, file);
  7366. +
  7367. + switch (cmd) {
  7368. + case VC_MEM_IOC_MEM_PHYS_ADDR:
  7369. + {
  7370. + pr_debug("%s: VC_MEM_IOC_MEM_PHYS_ADDR=0x%p\n",
  7371. + __func__, (void *) mm_vc_mem_phys_addr);
  7372. +
  7373. + if (copy_to_user((void *) arg, &mm_vc_mem_phys_addr,
  7374. + sizeof (mm_vc_mem_phys_addr)) != 0) {
  7375. + rc = -EFAULT;
  7376. + }
  7377. + break;
  7378. + }
  7379. + case VC_MEM_IOC_MEM_SIZE:
  7380. + {
  7381. + // Get the videocore memory size first
  7382. + vc_mem_get_size();
  7383. +
  7384. + pr_debug("%s: VC_MEM_IOC_MEM_SIZE=%u\n", __func__,
  7385. + mm_vc_mem_size);
  7386. +
  7387. + if (copy_to_user((void *) arg, &mm_vc_mem_size,
  7388. + sizeof (mm_vc_mem_size)) != 0) {
  7389. + rc = -EFAULT;
  7390. + }
  7391. + break;
  7392. + }
  7393. + case VC_MEM_IOC_MEM_BASE:
  7394. + {
  7395. + // Get the videocore memory base
  7396. + vc_mem_get_base();
  7397. +
  7398. + pr_debug("%s: VC_MEM_IOC_MEM_BASE=%u\n", __func__,
  7399. + mm_vc_mem_base);
  7400. +
  7401. + if (copy_to_user((void *) arg, &mm_vc_mem_base,
  7402. + sizeof (mm_vc_mem_base)) != 0) {
  7403. + rc = -EFAULT;
  7404. + }
  7405. + break;
  7406. + }
  7407. + case VC_MEM_IOC_MEM_LOAD:
  7408. + {
  7409. + // Get the videocore memory base
  7410. + vc_mem_get_base();
  7411. +
  7412. + pr_debug("%s: VC_MEM_IOC_MEM_LOAD=%u\n", __func__,
  7413. + mm_vc_mem_base);
  7414. +
  7415. + if (copy_to_user((void *) arg, &mm_vc_mem_base,
  7416. + sizeof (mm_vc_mem_base)) != 0) {
  7417. + rc = -EFAULT;
  7418. + }
  7419. + break;
  7420. + }
  7421. + default:
  7422. + {
  7423. + return -ENOTTY;
  7424. + }
  7425. + }
  7426. + pr_debug("%s: file = 0x%p returning %d\n", __func__, file, rc);
  7427. +
  7428. + return rc;
  7429. +}
  7430. +
  7431. +/****************************************************************************
  7432. +*
  7433. +* vc_mem_mmap
  7434. +*
  7435. +***************************************************************************/
  7436. +
  7437. +static int
  7438. +vc_mem_mmap(struct file *filp, struct vm_area_struct *vma)
  7439. +{
  7440. + int rc = 0;
  7441. + unsigned long length = vma->vm_end - vma->vm_start;
  7442. + unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
  7443. +
  7444. + pr_debug("%s: vm_start = 0x%08lx vm_end = 0x%08lx vm_pgoff = 0x%08lx\n",
  7445. + __func__, (long) vma->vm_start, (long) vma->vm_end,
  7446. + (long) vma->vm_pgoff);
  7447. +
  7448. + if (offset + length > mm_vc_mem_size) {
  7449. + pr_err("%s: length %ld is too big\n", __func__, length);
  7450. + return -EINVAL;
  7451. + }
  7452. + // Do not cache the memory map
  7453. + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  7454. +
  7455. + rc = remap_pfn_range(vma, vma->vm_start,
  7456. + (mm_vc_mem_phys_addr >> PAGE_SHIFT) +
  7457. + vma->vm_pgoff, length, vma->vm_page_prot);
  7458. + if (rc != 0) {
  7459. + pr_err("%s: remap_pfn_range failed (rc=%d)\n", __func__, rc);
  7460. + }
  7461. +
  7462. + return rc;
  7463. +}
  7464. +
  7465. +/****************************************************************************
  7466. +*
  7467. +* File Operations for the driver.
  7468. +*
  7469. +***************************************************************************/
  7470. +
  7471. +static const struct file_operations vc_mem_fops = {
  7472. + .owner = THIS_MODULE,
  7473. + .open = vc_mem_open,
  7474. + .release = vc_mem_release,
  7475. + .unlocked_ioctl = vc_mem_ioctl,
  7476. + .mmap = vc_mem_mmap,
  7477. +};
  7478. +
  7479. +#ifdef CONFIG_DEBUG_FS
  7480. +static void vc_mem_debugfs_deinit(void)
  7481. +{
  7482. + debugfs_remove_recursive(vc_mem_debugfs_entry);
  7483. + vc_mem_debugfs_entry = NULL;
  7484. +}
  7485. +
  7486. +
  7487. +static int vc_mem_debugfs_init(
  7488. + struct device *dev)
  7489. +{
  7490. + vc_mem_debugfs_entry = debugfs_create_dir(DRIVER_NAME, NULL);
  7491. + if (!vc_mem_debugfs_entry) {
  7492. + dev_warn(dev, "could not create debugfs entry\n");
  7493. + return -EFAULT;
  7494. + }
  7495. +
  7496. + if (!debugfs_create_x32("vc_mem_phys_addr",
  7497. + 0444,
  7498. + vc_mem_debugfs_entry,
  7499. + (u32 *)&mm_vc_mem_phys_addr)) {
  7500. + dev_warn(dev, "%s:could not create vc_mem_phys entry\n",
  7501. + __func__);
  7502. + goto fail;
  7503. + }
  7504. +
  7505. + if (!debugfs_create_x32("vc_mem_size",
  7506. + 0444,
  7507. + vc_mem_debugfs_entry,
  7508. + (u32 *)&mm_vc_mem_size)) {
  7509. + dev_warn(dev, "%s:could not create vc_mem_size entry\n",
  7510. + __func__);
  7511. + goto fail;
  7512. + }
  7513. +
  7514. + if (!debugfs_create_x32("vc_mem_base",
  7515. + 0444,
  7516. + vc_mem_debugfs_entry,
  7517. + (u32 *)&mm_vc_mem_base)) {
  7518. + dev_warn(dev, "%s:could not create vc_mem_base entry\n",
  7519. + __func__);
  7520. + goto fail;
  7521. + }
  7522. +
  7523. + return 0;
  7524. +
  7525. +fail:
  7526. + vc_mem_debugfs_deinit();
  7527. + return -EFAULT;
  7528. +}
  7529. +
  7530. +#endif /* CONFIG_DEBUG_FS */
  7531. +
  7532. +
  7533. +/****************************************************************************
  7534. +*
  7535. +* vc_mem_init
  7536. +*
  7537. +***************************************************************************/
  7538. +
  7539. +static int __init
  7540. +vc_mem_init(void)
  7541. +{
  7542. + int rc = -EFAULT;
  7543. + struct device *dev;
  7544. +
  7545. + pr_debug("%s: called\n", __func__);
  7546. +
  7547. + mm_vc_mem_phys_addr = phys_addr;
  7548. + mm_vc_mem_size = mem_size;
  7549. + mm_vc_mem_base = mem_base;
  7550. +
  7551. + vc_mem_get_size();
  7552. +
  7553. + pr_info("vc-mem: phys_addr:0x%08lx mem_base=0x%08x mem_size:0x%08x(%u MiB)\n",
  7554. + mm_vc_mem_phys_addr, mm_vc_mem_base, mm_vc_mem_size, mm_vc_mem_size / (1024 * 1024));
  7555. +
  7556. + if ((rc = alloc_chrdev_region(&vc_mem_devnum, 0, 1, DRIVER_NAME)) < 0) {
  7557. + pr_err("%s: alloc_chrdev_region failed (rc=%d)\n",
  7558. + __func__, rc);
  7559. + goto out_err;
  7560. + }
  7561. +
  7562. + cdev_init(&vc_mem_cdev, &vc_mem_fops);
  7563. + if ((rc = cdev_add(&vc_mem_cdev, vc_mem_devnum, 1)) != 0) {
  7564. + pr_err("%s: cdev_add failed (rc=%d)\n", __func__, rc);
  7565. + goto out_unregister;
  7566. + }
  7567. +
  7568. + vc_mem_class = class_create(THIS_MODULE, DRIVER_NAME);
  7569. + if (IS_ERR(vc_mem_class)) {
  7570. + rc = PTR_ERR(vc_mem_class);
  7571. + pr_err("%s: class_create failed (rc=%d)\n", __func__, rc);
  7572. + goto out_cdev_del;
  7573. + }
  7574. +
  7575. + dev = device_create(vc_mem_class, NULL, vc_mem_devnum, NULL,
  7576. + DRIVER_NAME);
  7577. + if (IS_ERR(dev)) {
  7578. + rc = PTR_ERR(dev);
  7579. + pr_err("%s: device_create failed (rc=%d)\n", __func__, rc);
  7580. + goto out_class_destroy;
  7581. + }
  7582. +
  7583. +#ifdef CONFIG_DEBUG_FS
  7584. + /* don't fail if the debug entries cannot be created */
  7585. + vc_mem_debugfs_init(dev);
  7586. +#endif
  7587. +
  7588. + vc_mem_inited = 1;
  7589. + return 0;
  7590. +
  7591. + device_destroy(vc_mem_class, vc_mem_devnum);
  7592. +
  7593. + out_class_destroy:
  7594. + class_destroy(vc_mem_class);
  7595. + vc_mem_class = NULL;
  7596. +
  7597. + out_cdev_del:
  7598. + cdev_del(&vc_mem_cdev);
  7599. +
  7600. + out_unregister:
  7601. + unregister_chrdev_region(vc_mem_devnum, 1);
  7602. +
  7603. + out_err:
  7604. + return -1;
  7605. +}
  7606. +
  7607. +/****************************************************************************
  7608. +*
  7609. +* vc_mem_exit
  7610. +*
  7611. +***************************************************************************/
  7612. +
  7613. +static void __exit
  7614. +vc_mem_exit(void)
  7615. +{
  7616. + pr_debug("%s: called\n", __func__);
  7617. +
  7618. + if (vc_mem_inited) {
  7619. +#if CONFIG_DEBUG_FS
  7620. + vc_mem_debugfs_deinit();
  7621. +#endif
  7622. + device_destroy(vc_mem_class, vc_mem_devnum);
  7623. + class_destroy(vc_mem_class);
  7624. + cdev_del(&vc_mem_cdev);
  7625. + unregister_chrdev_region(vc_mem_devnum, 1);
  7626. + }
  7627. +}
  7628. +
  7629. +module_init(vc_mem_init);
  7630. +module_exit(vc_mem_exit);
  7631. +MODULE_LICENSE("GPL");
  7632. +MODULE_AUTHOR("Broadcom Corporation");
  7633. +
  7634. +module_param(phys_addr, uint, 0644);
  7635. +module_param(mem_size, uint, 0644);
  7636. +module_param(mem_base, uint, 0644);
  7637. +
  7638. diff -Nur linux-3.13.3.orig/arch/arm/Makefile linux-3.13.3/arch/arm/Makefile
  7639. --- linux-3.13.3.orig/arch/arm/Makefile 2014-02-13 23:00:14.000000000 +0100
  7640. +++ linux-3.13.3/arch/arm/Makefile 2014-02-17 22:41:01.000000000 +0100
  7641. @@ -147,6 +147,7 @@
  7642. # by CONFIG_* macro name.
  7643. machine-$(CONFIG_ARCH_AT91) += at91
  7644. machine-$(CONFIG_ARCH_BCM) += bcm
  7645. +machine-$(CONFIG_ARCH_BCM2708) += bcm2708
  7646. machine-$(CONFIG_ARCH_BCM2835) += bcm2835
  7647. machine-$(CONFIG_ARCH_CLPS711X) += clps711x
  7648. machine-$(CONFIG_ARCH_CNS3XXX) += cns3xxx
  7649. diff -Nur linux-3.13.3.orig/arch/arm/mm/Kconfig linux-3.13.3/arch/arm/mm/Kconfig
  7650. --- linux-3.13.3.orig/arch/arm/mm/Kconfig 2014-02-13 23:00:14.000000000 +0100
  7651. +++ linux-3.13.3/arch/arm/mm/Kconfig 2014-02-17 22:41:01.000000000 +0100
  7652. @@ -358,7 +358,7 @@
  7653. # ARMv6
  7654. config CPU_V6
  7655. - bool "Support ARM V6 processor" if ARCH_INTEGRATOR || MACH_REALVIEW_EB || MACH_REALVIEW_PBX
  7656. + bool "Support ARM V6 processor" if ARCH_INTEGRATOR || MACH_REALVIEW_EB || MACH_REALVIEW_PBX || MACH_BCM2708
  7657. select CPU_32v6
  7658. select CPU_ABRT_EV6
  7659. select CPU_CACHE_V6
  7660. diff -Nur linux-3.13.3.orig/arch/arm/mm/proc-v6.S linux-3.13.3/arch/arm/mm/proc-v6.S
  7661. --- linux-3.13.3.orig/arch/arm/mm/proc-v6.S 2014-02-13 23:00:14.000000000 +0100
  7662. +++ linux-3.13.3/arch/arm/mm/proc-v6.S 2014-02-17 22:41:01.000000000 +0100
  7663. @@ -73,10 +73,19 @@
  7664. *
  7665. * IRQs are already disabled.
  7666. */
  7667. +
  7668. +/* See jira SW-5991 for details of this workaround */
  7669. ENTRY(cpu_v6_do_idle)
  7670. - mov r1, #0
  7671. - mcr p15, 0, r1, c7, c10, 4 @ DWB - WFI may enter a low-power mode
  7672. - mcr p15, 0, r1, c7, c0, 4 @ wait for interrupt
  7673. + .align 5
  7674. + mov r1, #2
  7675. +1: subs r1, #1
  7676. + nop
  7677. + mcreq p15, 0, r1, c7, c10, 4 @ DWB - WFI may enter a low-power mode
  7678. + mcreq p15, 0, r1, c7, c0, 4 @ wait for interrupt
  7679. + nop
  7680. + nop
  7681. + nop
  7682. + bne 1b
  7683. mov pc, lr
  7684. ENTRY(cpu_v6_dcache_clean_area)
  7685. diff -Nur linux-3.13.3.orig/arch/arm/tools/mach-types linux-3.13.3/arch/arm/tools/mach-types
  7686. --- linux-3.13.3.orig/arch/arm/tools/mach-types 2014-02-13 23:00:14.000000000 +0100
  7687. +++ linux-3.13.3/arch/arm/tools/mach-types 2014-02-17 22:41:01.000000000 +0100
  7688. @@ -522,6 +522,7 @@
  7689. prima2_evb MACH_PRIMA2_EVB PRIMA2_EVB 3103
  7690. paz00 MACH_PAZ00 PAZ00 3128
  7691. acmenetusfoxg20 MACH_ACMENETUSFOXG20 ACMENETUSFOXG20 3129
  7692. +bcm2708 MACH_BCM2708 BCM2708 3138
  7693. ag5evm MACH_AG5EVM AG5EVM 3189
  7694. ics_if_voip MACH_ICS_IF_VOIP ICS_IF_VOIP 3206
  7695. wlf_cragg_6410 MACH_WLF_CRAGG_6410 WLF_CRAGG_6410 3207
  7696. diff -Nur linux-3.13.3.orig/Documentation/video4linux/bcm2835-v4l2.txt linux-3.13.3/Documentation/video4linux/bcm2835-v4l2.txt
  7697. --- linux-3.13.3.orig/Documentation/video4linux/bcm2835-v4l2.txt 1970-01-01 01:00:00.000000000 +0100
  7698. +++ linux-3.13.3/Documentation/video4linux/bcm2835-v4l2.txt 2014-02-17 22:41:01.000000000 +0100
  7699. @@ -0,0 +1,60 @@
  7700. +
  7701. +BCM2835 (aka Raspberry Pi) V4L2 driver
  7702. +======================================
  7703. +
  7704. +1. Copyright
  7705. +============
  7706. +
  7707. +Copyright © 2013 Raspberry Pi (Trading) Ltd.
  7708. +
  7709. +2. License
  7710. +==========
  7711. +
  7712. +This program is free software; you can redistribute it and/or modify
  7713. +it under the terms of the GNU General Public License as published by
  7714. +the Free Software Foundation; either version 2 of the License, or
  7715. +(at your option) any later version.
  7716. +
  7717. +This program is distributed in the hope that it will be useful,
  7718. +but WITHOUT ANY WARRANTY; without even the implied warranty of
  7719. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  7720. +GNU General Public License for more details.
  7721. +
  7722. +You should have received a copy of the GNU General Public License
  7723. +along with this program; if not, write to the Free Software
  7724. +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  7725. +
  7726. +3. Quick Start
  7727. +==============
  7728. +
  7729. +You need a version 1.0 or later of v4l2-ctl, available from:
  7730. + git://git.linuxtv.org/v4l-utils.git
  7731. +
  7732. +$ sudo modprobe bcm2835-v4l2
  7733. +
  7734. +Turn on the overlay:
  7735. +
  7736. +$ v4l2-ctl --overlay=1
  7737. +
  7738. +Turn off the overlay:
  7739. +
  7740. +$ v4l2-ctl --overlay=0
  7741. +
  7742. +Set the capture format for video:
  7743. +
  7744. +$ v4l2-ctl --set-fmt-video=width=1920,height=1088,pixelformat=4
  7745. +
  7746. +(Note: 1088 not 1080).
  7747. +
  7748. +Capture:
  7749. +
  7750. +$ v4l2-ctl --stream-mmap=3 --stream-count=100 --stream-to=somefile.h264
  7751. +
  7752. +Stills capture:
  7753. +
  7754. +$ v4l2-ctl --set-fmt-video=width=2592,height=1944,pixelformat=3
  7755. +$ v4l2-ctl --stream-mmap=3 --stream-count=1 --stream-to=somefile.jpg
  7756. +
  7757. +List of available formats:
  7758. +
  7759. +$ v4l2-ctl --list-formats
  7760. diff -Nur linux-3.13.3.orig/drivers/char/broadcom/Kconfig linux-3.13.3/drivers/char/broadcom/Kconfig
  7761. --- linux-3.13.3.orig/drivers/char/broadcom/Kconfig 1970-01-01 01:00:00.000000000 +0100
  7762. +++ linux-3.13.3/drivers/char/broadcom/Kconfig 2014-02-17 22:41:01.000000000 +0100
  7763. @@ -0,0 +1,16 @@
  7764. +#
  7765. +# Broadcom char driver config
  7766. +#
  7767. +
  7768. +menuconfig BRCM_CHAR_DRIVERS
  7769. + bool "Broadcom Char Drivers"
  7770. + help
  7771. + Broadcom's char drivers
  7772. +
  7773. +config BCM_VC_CMA
  7774. + bool "Videocore CMA"
  7775. + depends on CMA && BRCM_CHAR_DRIVERS && BCM2708_VCHIQ
  7776. + default n
  7777. + help
  7778. + Helper for videocore CMA access.
  7779. +
  7780. diff -Nur linux-3.13.3.orig/drivers/char/broadcom/Makefile linux-3.13.3/drivers/char/broadcom/Makefile
  7781. --- linux-3.13.3.orig/drivers/char/broadcom/Makefile 1970-01-01 01:00:00.000000000 +0100
  7782. +++ linux-3.13.3/drivers/char/broadcom/Makefile 2014-02-17 22:41:01.000000000 +0100
  7783. @@ -0,0 +1 @@
  7784. +obj-$(CONFIG_BCM_VC_CMA) += vc_cma/
  7785. diff -Nur linux-3.13.3.orig/drivers/char/broadcom/vc_cma/Makefile linux-3.13.3/drivers/char/broadcom/vc_cma/Makefile
  7786. --- linux-3.13.3.orig/drivers/char/broadcom/vc_cma/Makefile 1970-01-01 01:00:00.000000000 +0100
  7787. +++ linux-3.13.3/drivers/char/broadcom/vc_cma/Makefile 2014-02-17 22:41:01.000000000 +0100
  7788. @@ -0,0 +1,14 @@
  7789. +EXTRA_CFLAGS += -Wall -Wstrict-prototypes -Wno-trigraphs
  7790. +EXTRA_CFLAGS += -Werror
  7791. +EXTRA_CFLAGS += -I"include/linux/broadcom"
  7792. +EXTRA_CFLAGS += -I"drivers/misc/vc04_services"
  7793. +EXTRA_CFLAGS += -I"drivers/misc/vc04_services/interface/vchi"
  7794. +EXTRA_CFLAGS += -I"drivers/misc/vc04_services/interface/vchiq_arm"
  7795. +
  7796. +EXTRA_CFLAGS += -D__KERNEL__
  7797. +EXTRA_CFLAGS += -D__linux__
  7798. +EXTRA_CFLAGS += -Werror
  7799. +
  7800. +obj-$(CONFIG_BCM_VC_CMA) += vc-cma.o
  7801. +
  7802. +vc-cma-objs := vc_cma.o
  7803. diff -Nur linux-3.13.3.orig/drivers/char/broadcom/vc_cma/vc_cma.c linux-3.13.3/drivers/char/broadcom/vc_cma/vc_cma.c
  7804. --- linux-3.13.3.orig/drivers/char/broadcom/vc_cma/vc_cma.c 1970-01-01 01:00:00.000000000 +0100
  7805. +++ linux-3.13.3/drivers/char/broadcom/vc_cma/vc_cma.c 2014-02-17 22:41:01.000000000 +0100
  7806. @@ -0,0 +1,1143 @@
  7807. +/**
  7808. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  7809. + *
  7810. + * Redistribution and use in source and binary forms, with or without
  7811. + * modification, are permitted provided that the following conditions
  7812. + * are met:
  7813. + * 1. Redistributions of source code must retain the above copyright
  7814. + * notice, this list of conditions, and the following disclaimer,
  7815. + * without modification.
  7816. + * 2. Redistributions in binary form must reproduce the above copyright
  7817. + * notice, this list of conditions and the following disclaimer in the
  7818. + * documentation and/or other materials provided with the distribution.
  7819. + * 3. The names of the above-listed copyright holders may not be used
  7820. + * to endorse or promote products derived from this software without
  7821. + * specific prior written permission.
  7822. + *
  7823. + * ALTERNATIVELY, this software may be distributed under the terms of the
  7824. + * GNU General Public License ("GPL") version 2, as published by the Free
  7825. + * Software Foundation.
  7826. + *
  7827. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  7828. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  7829. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  7830. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  7831. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  7832. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  7833. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  7834. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  7835. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  7836. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  7837. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7838. + */
  7839. +
  7840. +#include <linux/kernel.h>
  7841. +#include <linux/module.h>
  7842. +#include <linux/kthread.h>
  7843. +#include <linux/fs.h>
  7844. +#include <linux/device.h>
  7845. +#include <linux/cdev.h>
  7846. +#include <linux/mm.h>
  7847. +#include <linux/proc_fs.h>
  7848. +#include <linux/seq_file.h>
  7849. +#include <linux/dma-mapping.h>
  7850. +#include <linux/dma-contiguous.h>
  7851. +#include <linux/platform_device.h>
  7852. +#include <linux/uaccess.h>
  7853. +#include <asm/cacheflush.h>
  7854. +
  7855. +#include "vc_cma.h"
  7856. +
  7857. +#include "vchiq_util.h"
  7858. +#include "vchiq_connected.h"
  7859. +//#include "debug_sym.h"
  7860. +//#include "vc_mem.h"
  7861. +
  7862. +#define DRIVER_NAME "vc-cma"
  7863. +
  7864. +#define LOG_DBG(fmt, ...) \
  7865. + if (vc_cma_debug) \
  7866. + printk(KERN_INFO fmt "\n", ##__VA_ARGS__)
  7867. +#define LOG_ERR(fmt, ...) \
  7868. + printk(KERN_ERR fmt "\n", ##__VA_ARGS__)
  7869. +
  7870. +#define VC_CMA_FOURCC VCHIQ_MAKE_FOURCC('C', 'M', 'A', ' ')
  7871. +#define VC_CMA_VERSION 2
  7872. +
  7873. +#define VC_CMA_CHUNK_ORDER 6 /* 256K */
  7874. +#define VC_CMA_CHUNK_SIZE (4096 << VC_CMA_CHUNK_ORDER)
  7875. +#define VC_CMA_MAX_PARAMS_PER_MSG \
  7876. + ((VCHIQ_MAX_MSG_SIZE - sizeof(unsigned short))/sizeof(unsigned short))
  7877. +#define VC_CMA_RESERVE_COUNT_MAX 16
  7878. +
  7879. +#define PAGES_PER_CHUNK (VC_CMA_CHUNK_SIZE / PAGE_SIZE)
  7880. +
  7881. +#define VCADDR_TO_PHYSADDR(vcaddr) (mm_vc_mem_phys_addr + vcaddr)
  7882. +
  7883. +#define loud_error(...) \
  7884. + LOG_ERR("===== " __VA_ARGS__)
  7885. +
  7886. +enum {
  7887. + VC_CMA_MSG_QUIT,
  7888. + VC_CMA_MSG_OPEN,
  7889. + VC_CMA_MSG_TICK,
  7890. + VC_CMA_MSG_ALLOC, /* chunk count */
  7891. + VC_CMA_MSG_FREE, /* chunk, chunk, ... */
  7892. + VC_CMA_MSG_ALLOCATED, /* chunk, chunk, ... */
  7893. + VC_CMA_MSG_REQUEST_ALLOC, /* chunk count */
  7894. + VC_CMA_MSG_REQUEST_FREE, /* chunk count */
  7895. + VC_CMA_MSG_RESERVE, /* bytes lo, bytes hi */
  7896. + VC_CMA_MSG_UPDATE_RESERVE,
  7897. + VC_CMA_MSG_MAX
  7898. +};
  7899. +
  7900. +struct cma_msg {
  7901. + unsigned short type;
  7902. + unsigned short params[VC_CMA_MAX_PARAMS_PER_MSG];
  7903. +};
  7904. +
  7905. +struct vc_cma_reserve_user {
  7906. + unsigned int pid;
  7907. + unsigned int reserve;
  7908. +};
  7909. +
  7910. +/* Device (/dev) related variables */
  7911. +static dev_t vc_cma_devnum;
  7912. +static struct class *vc_cma_class;
  7913. +static struct cdev vc_cma_cdev;
  7914. +static int vc_cma_inited;
  7915. +static int vc_cma_debug;
  7916. +
  7917. +/* Proc entry */
  7918. +static struct proc_dir_entry *vc_cma_proc_entry;
  7919. +
  7920. +phys_addr_t vc_cma_base;
  7921. +struct page *vc_cma_base_page;
  7922. +unsigned int vc_cma_size;
  7923. +EXPORT_SYMBOL(vc_cma_size);
  7924. +unsigned int vc_cma_initial;
  7925. +unsigned int vc_cma_chunks;
  7926. +unsigned int vc_cma_chunks_used;
  7927. +unsigned int vc_cma_chunks_reserved;
  7928. +
  7929. +static int in_loud_error;
  7930. +
  7931. +unsigned int vc_cma_reserve_total;
  7932. +unsigned int vc_cma_reserve_count;
  7933. +struct vc_cma_reserve_user vc_cma_reserve_users[VC_CMA_RESERVE_COUNT_MAX];
  7934. +static DEFINE_SEMAPHORE(vc_cma_reserve_mutex);
  7935. +static DEFINE_SEMAPHORE(vc_cma_worker_queue_push_mutex);
  7936. +
  7937. +static u64 vc_cma_dma_mask = DMA_BIT_MASK(32);
  7938. +static struct platform_device vc_cma_device = {
  7939. + .name = "vc-cma",
  7940. + .id = 0,
  7941. + .dev = {
  7942. + .dma_mask = &vc_cma_dma_mask,
  7943. + .coherent_dma_mask = DMA_BIT_MASK(32),
  7944. + },
  7945. +};
  7946. +
  7947. +static VCHIQ_INSTANCE_T cma_instance;
  7948. +static VCHIQ_SERVICE_HANDLE_T cma_service;
  7949. +static VCHIU_QUEUE_T cma_msg_queue;
  7950. +static struct task_struct *cma_worker;
  7951. +
  7952. +static int vc_cma_set_reserve(unsigned int reserve, unsigned int pid);
  7953. +static int vc_cma_alloc_chunks(int num_chunks, struct cma_msg *reply);
  7954. +static VCHIQ_STATUS_T cma_service_callback(VCHIQ_REASON_T reason,
  7955. + VCHIQ_HEADER_T * header,
  7956. + VCHIQ_SERVICE_HANDLE_T service,
  7957. + void *bulk_userdata);
  7958. +static void send_vc_msg(unsigned short type,
  7959. + unsigned short param1, unsigned short param2);
  7960. +static bool send_worker_msg(VCHIQ_HEADER_T * msg);
  7961. +
  7962. +static int early_vc_cma_mem(char *p)
  7963. +{
  7964. + unsigned int new_size;
  7965. + printk(KERN_NOTICE "early_vc_cma_mem(%s)", p);
  7966. + vc_cma_size = memparse(p, &p);
  7967. + vc_cma_initial = vc_cma_size;
  7968. + if (*p == '/')
  7969. + vc_cma_size = memparse(p + 1, &p);
  7970. + if (*p == '@')
  7971. + vc_cma_base = memparse(p + 1, &p);
  7972. +
  7973. + new_size = (vc_cma_size - ((-vc_cma_base) & (VC_CMA_CHUNK_SIZE - 1)))
  7974. + & ~(VC_CMA_CHUNK_SIZE - 1);
  7975. + if (new_size > vc_cma_size)
  7976. + vc_cma_size = 0;
  7977. + vc_cma_initial = (vc_cma_initial + VC_CMA_CHUNK_SIZE - 1)
  7978. + & ~(VC_CMA_CHUNK_SIZE - 1);
  7979. + if (vc_cma_initial > vc_cma_size)
  7980. + vc_cma_initial = vc_cma_size;
  7981. + vc_cma_base = (vc_cma_base + VC_CMA_CHUNK_SIZE - 1)
  7982. + & ~(VC_CMA_CHUNK_SIZE - 1);
  7983. +
  7984. + printk(KERN_NOTICE " -> initial %x, size %x, base %x", vc_cma_initial,
  7985. + vc_cma_size, (unsigned int)vc_cma_base);
  7986. +
  7987. + return 0;
  7988. +}
  7989. +
  7990. +early_param("vc-cma-mem", early_vc_cma_mem);
  7991. +
  7992. +void vc_cma_early_init(void)
  7993. +{
  7994. + LOG_DBG("vc_cma_early_init - vc_cma_chunks = %d", vc_cma_chunks);
  7995. + if (vc_cma_size) {
  7996. + int rc = platform_device_register(&vc_cma_device);
  7997. + LOG_DBG("platform_device_register -> %d", rc);
  7998. + }
  7999. +}
  8000. +
  8001. +void vc_cma_reserve(void)
  8002. +{
  8003. + /* if vc_cma_size is set, then declare vc CMA area of the same
  8004. + * size from the end of memory
  8005. + */
  8006. + if (vc_cma_size) {
  8007. + if (dma_declare_contiguous(NULL /*&vc_cma_device.dev*/, vc_cma_size,
  8008. + vc_cma_base, 0) == 0) {
  8009. + } else {
  8010. + LOG_ERR("vc_cma: dma_declare_contiguous(%x,%x) failed",
  8011. + vc_cma_size, (unsigned int)vc_cma_base);
  8012. + vc_cma_size = 0;
  8013. + }
  8014. + }
  8015. + vc_cma_chunks = vc_cma_size / VC_CMA_CHUNK_SIZE;
  8016. +}
  8017. +
  8018. +/****************************************************************************
  8019. +*
  8020. +* vc_cma_open
  8021. +*
  8022. +***************************************************************************/
  8023. +
  8024. +static int vc_cma_open(struct inode *inode, struct file *file)
  8025. +{
  8026. + (void)inode;
  8027. + (void)file;
  8028. +
  8029. + return 0;
  8030. +}
  8031. +
  8032. +/****************************************************************************
  8033. +*
  8034. +* vc_cma_release
  8035. +*
  8036. +***************************************************************************/
  8037. +
  8038. +static int vc_cma_release(struct inode *inode, struct file *file)
  8039. +{
  8040. + (void)inode;
  8041. + (void)file;
  8042. +
  8043. + vc_cma_set_reserve(0, current->tgid);
  8044. +
  8045. + return 0;
  8046. +}
  8047. +
  8048. +/****************************************************************************
  8049. +*
  8050. +* vc_cma_ioctl
  8051. +*
  8052. +***************************************************************************/
  8053. +
  8054. +static long vc_cma_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  8055. +{
  8056. + int rc = 0;
  8057. +
  8058. + (void)cmd;
  8059. + (void)arg;
  8060. +
  8061. + switch (cmd) {
  8062. + case VC_CMA_IOC_RESERVE:
  8063. + rc = vc_cma_set_reserve((unsigned int)arg, current->tgid);
  8064. + if (rc >= 0)
  8065. + rc = 0;
  8066. + break;
  8067. + default:
  8068. + LOG_ERR("vc-cma: Unknown ioctl %x", cmd);
  8069. + return -ENOTTY;
  8070. + }
  8071. +
  8072. + return rc;
  8073. +}
  8074. +
  8075. +/****************************************************************************
  8076. +*
  8077. +* File Operations for the driver.
  8078. +*
  8079. +***************************************************************************/
  8080. +
  8081. +static const struct file_operations vc_cma_fops = {
  8082. + .owner = THIS_MODULE,
  8083. + .open = vc_cma_open,
  8084. + .release = vc_cma_release,
  8085. + .unlocked_ioctl = vc_cma_ioctl,
  8086. +};
  8087. +
  8088. +/****************************************************************************
  8089. +*
  8090. +* vc_cma_proc_open
  8091. +*
  8092. +***************************************************************************/
  8093. +
  8094. +static int vc_cma_show_info(struct seq_file *m, void *v)
  8095. +{
  8096. + int i;
  8097. +
  8098. + seq_printf(m, "Videocore CMA:\n");
  8099. + seq_printf(m, " Base : %08x\n", (unsigned int)vc_cma_base);
  8100. + seq_printf(m, " Length : %08x\n", vc_cma_size);
  8101. + seq_printf(m, " Initial : %08x\n", vc_cma_initial);
  8102. + seq_printf(m, " Chunk size : %08x\n", VC_CMA_CHUNK_SIZE);
  8103. + seq_printf(m, " Chunks : %4d (%d bytes)\n",
  8104. + (int)vc_cma_chunks,
  8105. + (int)(vc_cma_chunks * VC_CMA_CHUNK_SIZE));
  8106. + seq_printf(m, " Used : %4d (%d bytes)\n",
  8107. + (int)vc_cma_chunks_used,
  8108. + (int)(vc_cma_chunks_used * VC_CMA_CHUNK_SIZE));
  8109. + seq_printf(m, " Reserved : %4d (%d bytes)\n",
  8110. + (unsigned int)vc_cma_chunks_reserved,
  8111. + (int)(vc_cma_chunks_reserved * VC_CMA_CHUNK_SIZE));
  8112. +
  8113. + for (i = 0; i < vc_cma_reserve_count; i++) {
  8114. + struct vc_cma_reserve_user *user = &vc_cma_reserve_users[i];
  8115. + seq_printf(m, " PID %5d: %d bytes\n", user->pid,
  8116. + user->reserve);
  8117. + }
  8118. +
  8119. + seq_printf(m, "\n");
  8120. +
  8121. + return 0;
  8122. +}
  8123. +
  8124. +static int vc_cma_proc_open(struct inode *inode, struct file *file)
  8125. +{
  8126. + return single_open(file, vc_cma_show_info, NULL);
  8127. +}
  8128. +
  8129. +/****************************************************************************
  8130. +*
  8131. +* vc_cma_proc_write
  8132. +*
  8133. +***************************************************************************/
  8134. +
  8135. +static int vc_cma_proc_write(struct file *file,
  8136. + const char __user *buffer,
  8137. + size_t size, loff_t *ppos)
  8138. +{
  8139. + int rc = -EFAULT;
  8140. + char input_str[20];
  8141. +
  8142. + memset(input_str, 0, sizeof(input_str));
  8143. +
  8144. + if (size > sizeof(input_str)) {
  8145. + LOG_ERR("%s: input string length too long", __func__);
  8146. + goto out;
  8147. + }
  8148. +
  8149. + if (copy_from_user(input_str, buffer, size - 1)) {
  8150. + LOG_ERR("%s: failed to get input string", __func__);
  8151. + goto out;
  8152. + }
  8153. +#define ALLOC_STR "alloc"
  8154. +#define FREE_STR "free"
  8155. +#define DEBUG_STR "debug"
  8156. +#define RESERVE_STR "reserve"
  8157. + if (strncmp(input_str, ALLOC_STR, strlen(ALLOC_STR)) == 0) {
  8158. + int size;
  8159. + char *p = input_str + strlen(ALLOC_STR);
  8160. +
  8161. + while (*p == ' ')
  8162. + p++;
  8163. + size = memparse(p, NULL);
  8164. + LOG_ERR("/proc/vc-cma: alloc %d", size);
  8165. + if (size)
  8166. + send_vc_msg(VC_CMA_MSG_REQUEST_FREE,
  8167. + size / VC_CMA_CHUNK_SIZE, 0);
  8168. + else
  8169. + LOG_ERR("invalid size '%s'", p);
  8170. + rc = size;
  8171. + } else if (strncmp(input_str, FREE_STR, strlen(FREE_STR)) == 0) {
  8172. + int size;
  8173. + char *p = input_str + strlen(FREE_STR);
  8174. +
  8175. + while (*p == ' ')
  8176. + p++;
  8177. + size = memparse(p, NULL);
  8178. + LOG_ERR("/proc/vc-cma: free %d", size);
  8179. + if (size)
  8180. + send_vc_msg(VC_CMA_MSG_REQUEST_ALLOC,
  8181. + size / VC_CMA_CHUNK_SIZE, 0);
  8182. + else
  8183. + LOG_ERR("invalid size '%s'", p);
  8184. + rc = size;
  8185. + } else if (strncmp(input_str, DEBUG_STR, strlen(DEBUG_STR)) == 0) {
  8186. + char *p = input_str + strlen(DEBUG_STR);
  8187. + while (*p == ' ')
  8188. + p++;
  8189. + if ((strcmp(p, "on") == 0) || (strcmp(p, "1") == 0))
  8190. + vc_cma_debug = 1;
  8191. + else if ((strcmp(p, "off") == 0) || (strcmp(p, "0") == 0))
  8192. + vc_cma_debug = 0;
  8193. + LOG_ERR("/proc/vc-cma: debug %s", vc_cma_debug ? "on" : "off");
  8194. + rc = size;
  8195. + } else if (strncmp(input_str, RESERVE_STR, strlen(RESERVE_STR)) == 0) {
  8196. + int size;
  8197. + int reserved;
  8198. + char *p = input_str + strlen(RESERVE_STR);
  8199. + while (*p == ' ')
  8200. + p++;
  8201. + size = memparse(p, NULL);
  8202. +
  8203. + reserved = vc_cma_set_reserve(size, current->tgid);
  8204. + rc = (reserved >= 0) ? size : reserved;
  8205. + }
  8206. +
  8207. +out:
  8208. + return rc;
  8209. +}
  8210. +
  8211. +/****************************************************************************
  8212. +*
  8213. +* File Operations for /proc interface.
  8214. +*
  8215. +***************************************************************************/
  8216. +
  8217. +static const struct file_operations vc_cma_proc_fops = {
  8218. + .open = vc_cma_proc_open,
  8219. + .read = seq_read,
  8220. + .write = vc_cma_proc_write,
  8221. + .llseek = seq_lseek,
  8222. + .release = single_release
  8223. +};
  8224. +
  8225. +static int vc_cma_set_reserve(unsigned int reserve, unsigned int pid)
  8226. +{
  8227. + struct vc_cma_reserve_user *user = NULL;
  8228. + int delta = 0;
  8229. + int i;
  8230. +
  8231. + if (down_interruptible(&vc_cma_reserve_mutex))
  8232. + return -ERESTARTSYS;
  8233. +
  8234. + for (i = 0; i < vc_cma_reserve_count; i++) {
  8235. + if (pid == vc_cma_reserve_users[i].pid) {
  8236. + user = &vc_cma_reserve_users[i];
  8237. + delta = reserve - user->reserve;
  8238. + if (reserve)
  8239. + user->reserve = reserve;
  8240. + else {
  8241. + /* Remove this entry by copying downwards */
  8242. + while ((i + 1) < vc_cma_reserve_count) {
  8243. + user[0].pid = user[1].pid;
  8244. + user[0].reserve = user[1].reserve;
  8245. + user++;
  8246. + i++;
  8247. + }
  8248. + vc_cma_reserve_count--;
  8249. + user = NULL;
  8250. + }
  8251. + break;
  8252. + }
  8253. + }
  8254. +
  8255. + if (reserve && !user) {
  8256. + if (vc_cma_reserve_count == VC_CMA_RESERVE_COUNT_MAX) {
  8257. + LOG_ERR("vc-cma: Too many reservations - "
  8258. + "increase CMA_RESERVE_COUNT_MAX");
  8259. + up(&vc_cma_reserve_mutex);
  8260. + return -EBUSY;
  8261. + }
  8262. + user = &vc_cma_reserve_users[vc_cma_reserve_count];
  8263. + user->pid = pid;
  8264. + user->reserve = reserve;
  8265. + delta = reserve;
  8266. + vc_cma_reserve_count++;
  8267. + }
  8268. +
  8269. + vc_cma_reserve_total += delta;
  8270. +
  8271. + send_vc_msg(VC_CMA_MSG_RESERVE,
  8272. + vc_cma_reserve_total & 0xffff, vc_cma_reserve_total >> 16);
  8273. +
  8274. + send_worker_msg((VCHIQ_HEADER_T *) VC_CMA_MSG_UPDATE_RESERVE);
  8275. +
  8276. + LOG_DBG("/proc/vc-cma: reserve %d (PID %d) - total %u",
  8277. + reserve, pid, vc_cma_reserve_total);
  8278. +
  8279. + up(&vc_cma_reserve_mutex);
  8280. +
  8281. + return vc_cma_reserve_total;
  8282. +}
  8283. +
  8284. +static VCHIQ_STATUS_T cma_service_callback(VCHIQ_REASON_T reason,
  8285. + VCHIQ_HEADER_T * header,
  8286. + VCHIQ_SERVICE_HANDLE_T service,
  8287. + void *bulk_userdata)
  8288. +{
  8289. + switch (reason) {
  8290. + case VCHIQ_MESSAGE_AVAILABLE:
  8291. + if (!send_worker_msg(header))
  8292. + return VCHIQ_RETRY;
  8293. + break;
  8294. + case VCHIQ_SERVICE_CLOSED:
  8295. + LOG_DBG("CMA service closed");
  8296. + break;
  8297. + default:
  8298. + LOG_ERR("Unexpected CMA callback reason %d", reason);
  8299. + break;
  8300. + }
  8301. + return VCHIQ_SUCCESS;
  8302. +}
  8303. +
  8304. +static void send_vc_msg(unsigned short type,
  8305. + unsigned short param1, unsigned short param2)
  8306. +{
  8307. + unsigned short msg[] = { type, param1, param2 };
  8308. + VCHIQ_ELEMENT_T elem = { &msg, sizeof(msg) };
  8309. + VCHIQ_STATUS_T ret;
  8310. + vchiq_use_service(cma_service);
  8311. + ret = vchiq_queue_message(cma_service, &elem, 1);
  8312. + vchiq_release_service(cma_service);
  8313. + if (ret != VCHIQ_SUCCESS)
  8314. + LOG_ERR("vchiq_queue_message returned %x", ret);
  8315. +}
  8316. +
  8317. +static bool send_worker_msg(VCHIQ_HEADER_T * msg)
  8318. +{
  8319. + if (down_interruptible(&vc_cma_worker_queue_push_mutex))
  8320. + return false;
  8321. + vchiu_queue_push(&cma_msg_queue, msg);
  8322. + up(&vc_cma_worker_queue_push_mutex);
  8323. + return true;
  8324. +}
  8325. +
  8326. +static int vc_cma_alloc_chunks(int num_chunks, struct cma_msg *reply)
  8327. +{
  8328. + int i;
  8329. + for (i = 0; i < num_chunks; i++) {
  8330. + struct page *chunk;
  8331. + unsigned int chunk_num;
  8332. + uint8_t *chunk_addr;
  8333. + size_t chunk_size = PAGES_PER_CHUNK << PAGE_SHIFT;
  8334. +
  8335. + chunk = dma_alloc_from_contiguous(NULL /*&vc_cma_device.dev*/,
  8336. + PAGES_PER_CHUNK,
  8337. + VC_CMA_CHUNK_ORDER);
  8338. + if (!chunk)
  8339. + break;
  8340. +
  8341. + chunk_addr = page_address(chunk);
  8342. + dmac_flush_range(chunk_addr, chunk_addr + chunk_size);
  8343. + outer_inv_range(__pa(chunk_addr), __pa(chunk_addr) +
  8344. + chunk_size);
  8345. +
  8346. + chunk_num =
  8347. + (page_to_phys(chunk) - vc_cma_base) / VC_CMA_CHUNK_SIZE;
  8348. + BUG_ON(((page_to_phys(chunk) - vc_cma_base) %
  8349. + VC_CMA_CHUNK_SIZE) != 0);
  8350. + if (chunk_num >= vc_cma_chunks) {
  8351. + LOG_ERR("%s: ===============================",
  8352. + __func__);
  8353. + LOG_ERR("%s: chunk phys %x, vc_cma %x-%x - "
  8354. + "bad SPARSEMEM configuration?",
  8355. + __func__, (unsigned int)page_to_phys(chunk),
  8356. + vc_cma_base, vc_cma_base + vc_cma_size - 1);
  8357. + LOG_ERR("%s: dev->cma_area = %p\n", __func__,
  8358. + (void*)0/*vc_cma_device.dev.cma_area*/);
  8359. + LOG_ERR("%s: ===============================",
  8360. + __func__);
  8361. + break;
  8362. + }
  8363. + reply->params[i] = chunk_num;
  8364. + vc_cma_chunks_used++;
  8365. + }
  8366. +
  8367. + if (i < num_chunks) {
  8368. + LOG_ERR("%s: dma_alloc_from_contiguous failed "
  8369. + "for %x bytes (alloc %d of %d, %d free)",
  8370. + __func__, VC_CMA_CHUNK_SIZE, i,
  8371. + num_chunks, vc_cma_chunks - vc_cma_chunks_used);
  8372. + num_chunks = i;
  8373. + }
  8374. +
  8375. + LOG_DBG("CMA allocated %d chunks -> %d used",
  8376. + num_chunks, vc_cma_chunks_used);
  8377. + reply->type = VC_CMA_MSG_ALLOCATED;
  8378. +
  8379. + {
  8380. + VCHIQ_ELEMENT_T elem = {
  8381. + reply,
  8382. + offsetof(struct cma_msg, params[0]) +
  8383. + num_chunks * sizeof(reply->params[0])
  8384. + };
  8385. + VCHIQ_STATUS_T ret;
  8386. + vchiq_use_service(cma_service);
  8387. + ret = vchiq_queue_message(cma_service, &elem, 1);
  8388. + vchiq_release_service(cma_service);
  8389. + if (ret != VCHIQ_SUCCESS)
  8390. + LOG_ERR("vchiq_queue_message return " "%x", ret);
  8391. + }
  8392. +
  8393. + return num_chunks;
  8394. +}
  8395. +
  8396. +static int cma_worker_proc(void *param)
  8397. +{
  8398. + static struct cma_msg reply;
  8399. + (void)param;
  8400. +
  8401. + while (1) {
  8402. + VCHIQ_HEADER_T *msg;
  8403. + static struct cma_msg msg_copy;
  8404. + struct cma_msg *cma_msg = &msg_copy;
  8405. + int type, msg_size;
  8406. +
  8407. + msg = vchiu_queue_pop(&cma_msg_queue);
  8408. + if ((unsigned int)msg >= VC_CMA_MSG_MAX) {
  8409. + msg_size = msg->size;
  8410. + memcpy(&msg_copy, msg->data, msg_size);
  8411. + type = cma_msg->type;
  8412. + vchiq_release_message(cma_service, msg);
  8413. + } else {
  8414. + msg_size = 0;
  8415. + type = (int)msg;
  8416. + if (type == VC_CMA_MSG_QUIT)
  8417. + break;
  8418. + else if (type == VC_CMA_MSG_UPDATE_RESERVE) {
  8419. + msg = NULL;
  8420. + cma_msg = NULL;
  8421. + } else {
  8422. + BUG();
  8423. + continue;
  8424. + }
  8425. + }
  8426. +
  8427. + switch (type) {
  8428. + case VC_CMA_MSG_ALLOC:{
  8429. + int num_chunks, free_chunks;
  8430. + num_chunks = cma_msg->params[0];
  8431. + free_chunks =
  8432. + vc_cma_chunks - vc_cma_chunks_used;
  8433. + LOG_DBG("CMA_MSG_ALLOC(%d chunks)", num_chunks);
  8434. + if (num_chunks > VC_CMA_MAX_PARAMS_PER_MSG) {
  8435. + LOG_ERR
  8436. + ("CMA_MSG_ALLOC - chunk count (%d) "
  8437. + "exceeds VC_CMA_MAX_PARAMS_PER_MSG (%d)",
  8438. + num_chunks,
  8439. + VC_CMA_MAX_PARAMS_PER_MSG);
  8440. + num_chunks = VC_CMA_MAX_PARAMS_PER_MSG;
  8441. + }
  8442. +
  8443. + if (num_chunks > free_chunks) {
  8444. + LOG_ERR
  8445. + ("CMA_MSG_ALLOC - chunk count (%d) "
  8446. + "exceeds free chunks (%d)",
  8447. + num_chunks, free_chunks);
  8448. + num_chunks = free_chunks;
  8449. + }
  8450. +
  8451. + vc_cma_alloc_chunks(num_chunks, &reply);
  8452. + }
  8453. + break;
  8454. +
  8455. + case VC_CMA_MSG_FREE:{
  8456. + int chunk_count =
  8457. + (msg_size -
  8458. + offsetof(struct cma_msg,
  8459. + params)) /
  8460. + sizeof(cma_msg->params[0]);
  8461. + int i;
  8462. + BUG_ON(chunk_count <= 0);
  8463. +
  8464. + LOG_DBG("CMA_MSG_FREE(%d chunks - %x, ...)",
  8465. + chunk_count, cma_msg->params[0]);
  8466. + for (i = 0; i < chunk_count; i++) {
  8467. + int chunk_num = cma_msg->params[i];
  8468. + struct page *page = vc_cma_base_page +
  8469. + chunk_num * PAGES_PER_CHUNK;
  8470. + if (chunk_num >= vc_cma_chunks) {
  8471. + LOG_ERR
  8472. + ("CMA_MSG_FREE - chunk %d of %d"
  8473. + " (value %x) exceeds maximum "
  8474. + "(%x)", i, chunk_count,
  8475. + chunk_num,
  8476. + vc_cma_chunks - 1);
  8477. + break;
  8478. + }
  8479. +
  8480. + if (!dma_release_from_contiguous
  8481. + (NULL /*&vc_cma_device.dev*/, page,
  8482. + PAGES_PER_CHUNK)) {
  8483. + LOG_ERR
  8484. + ("CMA_MSG_FREE - failed to "
  8485. + "release chunk %d (phys %x, "
  8486. + "page %x)", chunk_num,
  8487. + page_to_phys(page),
  8488. + (unsigned int)page);
  8489. + }
  8490. + vc_cma_chunks_used--;
  8491. + }
  8492. + LOG_DBG("CMA released %d chunks -> %d used",
  8493. + i, vc_cma_chunks_used);
  8494. + }
  8495. + break;
  8496. +
  8497. + case VC_CMA_MSG_UPDATE_RESERVE:{
  8498. + int chunks_needed =
  8499. + ((vc_cma_reserve_total + VC_CMA_CHUNK_SIZE -
  8500. + 1)
  8501. + / VC_CMA_CHUNK_SIZE) -
  8502. + vc_cma_chunks_reserved;
  8503. +
  8504. + LOG_DBG
  8505. + ("CMA_MSG_UPDATE_RESERVE(%d chunks needed)",
  8506. + chunks_needed);
  8507. +
  8508. + /* Cap the reservations to what is available */
  8509. + if (chunks_needed > 0) {
  8510. + if (chunks_needed >
  8511. + (vc_cma_chunks -
  8512. + vc_cma_chunks_used))
  8513. + chunks_needed =
  8514. + (vc_cma_chunks -
  8515. + vc_cma_chunks_used);
  8516. +
  8517. + chunks_needed =
  8518. + vc_cma_alloc_chunks(chunks_needed,
  8519. + &reply);
  8520. + }
  8521. +
  8522. + LOG_DBG
  8523. + ("CMA_MSG_UPDATE_RESERVE(%d chunks allocated)",
  8524. + chunks_needed);
  8525. + vc_cma_chunks_reserved += chunks_needed;
  8526. + }
  8527. + break;
  8528. +
  8529. + default:
  8530. + LOG_ERR("unexpected msg type %d", type);
  8531. + break;
  8532. + }
  8533. + }
  8534. +
  8535. + LOG_DBG("quitting...");
  8536. + return 0;
  8537. +}
  8538. +
  8539. +/****************************************************************************
  8540. +*
  8541. +* vc_cma_connected_init
  8542. +*
  8543. +* This function is called once the videocore has been connected.
  8544. +*
  8545. +***************************************************************************/
  8546. +
  8547. +static void vc_cma_connected_init(void)
  8548. +{
  8549. + VCHIQ_SERVICE_PARAMS_T service_params;
  8550. +
  8551. + LOG_DBG("vc_cma_connected_init");
  8552. +
  8553. + if (!vchiu_queue_init(&cma_msg_queue, 16)) {
  8554. + LOG_ERR("could not create CMA msg queue");
  8555. + goto fail_queue;
  8556. + }
  8557. +
  8558. + if (vchiq_initialise(&cma_instance) != VCHIQ_SUCCESS)
  8559. + goto fail_vchiq_init;
  8560. +
  8561. + vchiq_connect(cma_instance);
  8562. +
  8563. + service_params.fourcc = VC_CMA_FOURCC;
  8564. + service_params.callback = cma_service_callback;
  8565. + service_params.userdata = NULL;
  8566. + service_params.version = VC_CMA_VERSION;
  8567. + service_params.version_min = VC_CMA_VERSION;
  8568. +
  8569. + if (vchiq_open_service(cma_instance, &service_params,
  8570. + &cma_service) != VCHIQ_SUCCESS) {
  8571. + LOG_ERR("failed to open service - already in use?");
  8572. + goto fail_vchiq_open;
  8573. + }
  8574. +
  8575. + vchiq_release_service(cma_service);
  8576. +
  8577. + cma_worker = kthread_create(cma_worker_proc, NULL, "cma_worker");
  8578. + if (!cma_worker) {
  8579. + LOG_ERR("could not create CMA worker thread");
  8580. + goto fail_worker;
  8581. + }
  8582. + set_user_nice(cma_worker, -20);
  8583. + wake_up_process(cma_worker);
  8584. +
  8585. + return;
  8586. +
  8587. +fail_worker:
  8588. + vchiq_close_service(cma_service);
  8589. +fail_vchiq_open:
  8590. + vchiq_shutdown(cma_instance);
  8591. +fail_vchiq_init:
  8592. + vchiu_queue_delete(&cma_msg_queue);
  8593. +fail_queue:
  8594. + return;
  8595. +}
  8596. +
  8597. +void
  8598. +loud_error_header(void)
  8599. +{
  8600. + if (in_loud_error)
  8601. + return;
  8602. +
  8603. + LOG_ERR("============================================================"
  8604. + "================");
  8605. + LOG_ERR("============================================================"
  8606. + "================");
  8607. + LOG_ERR("=====");
  8608. +
  8609. + in_loud_error = 1;
  8610. +}
  8611. +
  8612. +void
  8613. +loud_error_footer(void)
  8614. +{
  8615. + if (!in_loud_error)
  8616. + return;
  8617. +
  8618. + LOG_ERR("=====");
  8619. + LOG_ERR("============================================================"
  8620. + "================");
  8621. + LOG_ERR("============================================================"
  8622. + "================");
  8623. +
  8624. + in_loud_error = 0;
  8625. +}
  8626. +
  8627. +#if 1
  8628. +static int check_cma_config(void) { return 1; }
  8629. +#else
  8630. +static int
  8631. +read_vc_debug_var(VC_MEM_ACCESS_HANDLE_T handle,
  8632. + const char *symbol,
  8633. + void *buf, size_t bufsize)
  8634. +{
  8635. + VC_MEM_ADDR_T vcMemAddr;
  8636. + size_t vcMemSize;
  8637. + uint8_t *mapAddr;
  8638. + off_t vcMapAddr;
  8639. +
  8640. + if (!LookupVideoCoreSymbol(handle, symbol,
  8641. + &vcMemAddr,
  8642. + &vcMemSize)) {
  8643. + loud_error_header();
  8644. + loud_error(
  8645. + "failed to find VC symbol \"%s\".",
  8646. + symbol);
  8647. + loud_error_footer();
  8648. + return 0;
  8649. + }
  8650. +
  8651. + if (vcMemSize != bufsize) {
  8652. + loud_error_header();
  8653. + loud_error(
  8654. + "VC symbol \"%s\" is the wrong size.",
  8655. + symbol);
  8656. + loud_error_footer();
  8657. + return 0;
  8658. + }
  8659. +
  8660. + vcMapAddr = (off_t)vcMemAddr & VC_MEM_TO_ARM_ADDR_MASK;
  8661. + vcMapAddr += mm_vc_mem_phys_addr;
  8662. + mapAddr = ioremap_nocache(vcMapAddr, vcMemSize);
  8663. + if (mapAddr == 0) {
  8664. + loud_error_header();
  8665. + loud_error(
  8666. + "failed to ioremap \"%s\" @ 0x%x "
  8667. + "(phys: 0x%x, size: %u).",
  8668. + symbol,
  8669. + (unsigned int)vcMapAddr,
  8670. + (unsigned int)vcMemAddr,
  8671. + (unsigned int)vcMemSize);
  8672. + loud_error_footer();
  8673. + return 0;
  8674. + }
  8675. +
  8676. + memcpy(buf, mapAddr, bufsize);
  8677. + iounmap(mapAddr);
  8678. +
  8679. + return 1;
  8680. +}
  8681. +
  8682. +
  8683. +static int
  8684. +check_cma_config(void)
  8685. +{
  8686. + VC_MEM_ACCESS_HANDLE_T mem_hndl;
  8687. + VC_MEM_ADDR_T mempool_start;
  8688. + VC_MEM_ADDR_T mempool_end;
  8689. + VC_MEM_ADDR_T mempool_offline_start;
  8690. + VC_MEM_ADDR_T mempool_offline_end;
  8691. + VC_MEM_ADDR_T cam_alloc_base;
  8692. + VC_MEM_ADDR_T cam_alloc_size;
  8693. + VC_MEM_ADDR_T cam_alloc_end;
  8694. + int success = 0;
  8695. +
  8696. + if (OpenVideoCoreMemory(&mem_hndl) != 0)
  8697. + goto out;
  8698. +
  8699. + /* Read the relevant VideoCore variables */
  8700. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_START",
  8701. + &mempool_start,
  8702. + sizeof(mempool_start)))
  8703. + goto close;
  8704. +
  8705. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_END",
  8706. + &mempool_end,
  8707. + sizeof(mempool_end)))
  8708. + goto close;
  8709. +
  8710. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_OFFLINE_START",
  8711. + &mempool_offline_start,
  8712. + sizeof(mempool_offline_start)))
  8713. + goto close;
  8714. +
  8715. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_OFFLINE_END",
  8716. + &mempool_offline_end,
  8717. + sizeof(mempool_offline_end)))
  8718. + goto close;
  8719. +
  8720. + if (!read_vc_debug_var(mem_hndl, "cam_alloc_base",
  8721. + &cam_alloc_base,
  8722. + sizeof(cam_alloc_base)))
  8723. + goto close;
  8724. +
  8725. + if (!read_vc_debug_var(mem_hndl, "cam_alloc_size",
  8726. + &cam_alloc_size,
  8727. + sizeof(cam_alloc_size)))
  8728. + goto close;
  8729. +
  8730. + cam_alloc_end = cam_alloc_base + cam_alloc_size;
  8731. +
  8732. + success = 1;
  8733. +
  8734. + /* Now the sanity checks */
  8735. + if (!mempool_offline_start)
  8736. + mempool_offline_start = mempool_start;
  8737. + if (!mempool_offline_end)
  8738. + mempool_offline_end = mempool_end;
  8739. +
  8740. + if (VCADDR_TO_PHYSADDR(mempool_offline_start) != vc_cma_base) {
  8741. + loud_error_header();
  8742. + loud_error(
  8743. + "__MEMPOOL_OFFLINE_START(%x -> %lx) doesn't match "
  8744. + "vc_cma_base(%x)",
  8745. + mempool_offline_start,
  8746. + VCADDR_TO_PHYSADDR(mempool_offline_start),
  8747. + vc_cma_base);
  8748. + success = 0;
  8749. + }
  8750. +
  8751. + if (VCADDR_TO_PHYSADDR(mempool_offline_end) !=
  8752. + (vc_cma_base + vc_cma_size)) {
  8753. + loud_error_header();
  8754. + loud_error(
  8755. + "__MEMPOOL_OFFLINE_END(%x -> %lx) doesn't match "
  8756. + "vc_cma_base(%x) + vc_cma_size(%x) = %x",
  8757. + mempool_offline_start,
  8758. + VCADDR_TO_PHYSADDR(mempool_offline_end),
  8759. + vc_cma_base, vc_cma_size, vc_cma_base + vc_cma_size);
  8760. + success = 0;
  8761. + }
  8762. +
  8763. + if (mempool_end < mempool_start) {
  8764. + loud_error_header();
  8765. + loud_error(
  8766. + "__MEMPOOL_END(%x) must not be before "
  8767. + "__MEMPOOL_START(%x)",
  8768. + mempool_end,
  8769. + mempool_start);
  8770. + success = 0;
  8771. + }
  8772. +
  8773. + if (mempool_offline_end < mempool_offline_start) {
  8774. + loud_error_header();
  8775. + loud_error(
  8776. + "__MEMPOOL_OFFLINE_END(%x) must not be before "
  8777. + "__MEMPOOL_OFFLINE_START(%x)",
  8778. + mempool_offline_end,
  8779. + mempool_offline_start);
  8780. + success = 0;
  8781. + }
  8782. +
  8783. + if (mempool_offline_start < mempool_start) {
  8784. + loud_error_header();
  8785. + loud_error(
  8786. + "__MEMPOOL_OFFLINE_START(%x) must not be before "
  8787. + "__MEMPOOL_START(%x)",
  8788. + mempool_offline_start,
  8789. + mempool_start);
  8790. + success = 0;
  8791. + }
  8792. +
  8793. + if (mempool_offline_end > mempool_end) {
  8794. + loud_error_header();
  8795. + loud_error(
  8796. + "__MEMPOOL_OFFLINE_END(%x) must not be after "
  8797. + "__MEMPOOL_END(%x)",
  8798. + mempool_offline_end,
  8799. + mempool_end);
  8800. + success = 0;
  8801. + }
  8802. +
  8803. + if ((cam_alloc_base < mempool_end) &&
  8804. + (cam_alloc_end > mempool_start)) {
  8805. + loud_error_header();
  8806. + loud_error(
  8807. + "cam_alloc pool(%x-%x) overlaps "
  8808. + "mempool(%x-%x)",
  8809. + cam_alloc_base, cam_alloc_end,
  8810. + mempool_start, mempool_end);
  8811. + success = 0;
  8812. + }
  8813. +
  8814. + loud_error_footer();
  8815. +
  8816. +close:
  8817. + CloseVideoCoreMemory(mem_hndl);
  8818. +
  8819. +out:
  8820. + return success;
  8821. +}
  8822. +#endif
  8823. +
  8824. +static int vc_cma_init(void)
  8825. +{
  8826. + int rc = -EFAULT;
  8827. + struct device *dev;
  8828. +
  8829. + if (!check_cma_config())
  8830. + goto out_release;
  8831. +
  8832. + printk(KERN_INFO "vc-cma: Videocore CMA driver\n");
  8833. + printk(KERN_INFO "vc-cma: vc_cma_base = 0x%08x\n", vc_cma_base);
  8834. + printk(KERN_INFO "vc-cma: vc_cma_size = 0x%08x (%u MiB)\n",
  8835. + vc_cma_size, vc_cma_size / (1024 * 1024));
  8836. + printk(KERN_INFO "vc-cma: vc_cma_initial = 0x%08x (%u MiB)\n",
  8837. + vc_cma_initial, vc_cma_initial / (1024 * 1024));
  8838. +
  8839. + vc_cma_base_page = phys_to_page(vc_cma_base);
  8840. +
  8841. + if (vc_cma_chunks) {
  8842. + int chunks_needed = vc_cma_initial / VC_CMA_CHUNK_SIZE;
  8843. +
  8844. + for (vc_cma_chunks_used = 0;
  8845. + vc_cma_chunks_used < chunks_needed; vc_cma_chunks_used++) {
  8846. + struct page *chunk;
  8847. + chunk = dma_alloc_from_contiguous(NULL /*&vc_cma_device.dev*/,
  8848. + PAGES_PER_CHUNK,
  8849. + VC_CMA_CHUNK_ORDER);
  8850. + if (!chunk)
  8851. + break;
  8852. + BUG_ON(((page_to_phys(chunk) - vc_cma_base) %
  8853. + VC_CMA_CHUNK_SIZE) != 0);
  8854. + }
  8855. + if (vc_cma_chunks_used != chunks_needed) {
  8856. + LOG_ERR("%s: dma_alloc_from_contiguous failed (%d "
  8857. + "bytes, allocation %d of %d)",
  8858. + __func__, VC_CMA_CHUNK_SIZE,
  8859. + vc_cma_chunks_used, chunks_needed);
  8860. + goto out_release;
  8861. + }
  8862. +
  8863. + vchiq_add_connected_callback(vc_cma_connected_init);
  8864. + }
  8865. +
  8866. + rc = alloc_chrdev_region(&vc_cma_devnum, 0, 1, DRIVER_NAME);
  8867. + if (rc < 0) {
  8868. + LOG_ERR("%s: alloc_chrdev_region failed (rc=%d)", __func__, rc);
  8869. + goto out_release;
  8870. + }
  8871. +
  8872. + cdev_init(&vc_cma_cdev, &vc_cma_fops);
  8873. + rc = cdev_add(&vc_cma_cdev, vc_cma_devnum, 1);
  8874. + if (rc != 0) {
  8875. + LOG_ERR("%s: cdev_add failed (rc=%d)", __func__, rc);
  8876. + goto out_unregister;
  8877. + }
  8878. +
  8879. + vc_cma_class = class_create(THIS_MODULE, DRIVER_NAME);
  8880. + if (IS_ERR(vc_cma_class)) {
  8881. + rc = PTR_ERR(vc_cma_class);
  8882. + LOG_ERR("%s: class_create failed (rc=%d)", __func__, rc);
  8883. + goto out_cdev_del;
  8884. + }
  8885. +
  8886. + dev = device_create(vc_cma_class, NULL, vc_cma_devnum, NULL,
  8887. + DRIVER_NAME);
  8888. + if (IS_ERR(dev)) {
  8889. + rc = PTR_ERR(dev);
  8890. + LOG_ERR("%s: device_create failed (rc=%d)", __func__, rc);
  8891. + goto out_class_destroy;
  8892. + }
  8893. +
  8894. + vc_cma_proc_entry = proc_create(DRIVER_NAME, 0444, NULL, &vc_cma_proc_fops);
  8895. + if (vc_cma_proc_entry == NULL) {
  8896. + rc = -EFAULT;
  8897. + LOG_ERR("%s: proc_create failed", __func__);
  8898. + goto out_device_destroy;
  8899. + }
  8900. +
  8901. + vc_cma_inited = 1;
  8902. + return 0;
  8903. +
  8904. +out_device_destroy:
  8905. + device_destroy(vc_cma_class, vc_cma_devnum);
  8906. +
  8907. +out_class_destroy:
  8908. + class_destroy(vc_cma_class);
  8909. + vc_cma_class = NULL;
  8910. +
  8911. +out_cdev_del:
  8912. + cdev_del(&vc_cma_cdev);
  8913. +
  8914. +out_unregister:
  8915. + unregister_chrdev_region(vc_cma_devnum, 1);
  8916. +
  8917. +out_release:
  8918. + /* It is tempting to try to clean up by calling
  8919. + dma_release_from_contiguous for all allocated chunks, but it isn't
  8920. + a very safe thing to do. If vc_cma_initial is non-zero it is because
  8921. + VideoCore is already using that memory, so giving it back to Linux
  8922. + is likely to be fatal.
  8923. + */
  8924. + return -1;
  8925. +}
  8926. +
  8927. +/****************************************************************************
  8928. +*
  8929. +* vc_cma_exit
  8930. +*
  8931. +***************************************************************************/
  8932. +
  8933. +static void __exit vc_cma_exit(void)
  8934. +{
  8935. + LOG_DBG("%s: called", __func__);
  8936. +
  8937. + if (vc_cma_inited) {
  8938. + remove_proc_entry(DRIVER_NAME, NULL);
  8939. + device_destroy(vc_cma_class, vc_cma_devnum);
  8940. + class_destroy(vc_cma_class);
  8941. + cdev_del(&vc_cma_cdev);
  8942. + unregister_chrdev_region(vc_cma_devnum, 1);
  8943. + }
  8944. +}
  8945. +
  8946. +module_init(vc_cma_init);
  8947. +module_exit(vc_cma_exit);
  8948. +MODULE_LICENSE("GPL");
  8949. +MODULE_AUTHOR("Broadcom Corporation");
  8950. diff -Nur linux-3.13.3.orig/drivers/char/hw_random/bcm2708-rng.c linux-3.13.3/drivers/char/hw_random/bcm2708-rng.c
  8951. --- linux-3.13.3.orig/drivers/char/hw_random/bcm2708-rng.c 1970-01-01 01:00:00.000000000 +0100
  8952. +++ linux-3.13.3/drivers/char/hw_random/bcm2708-rng.c 2014-02-17 22:41:01.000000000 +0100
  8953. @@ -0,0 +1,117 @@
  8954. +/**
  8955. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  8956. + *
  8957. + * Redistribution and use in source and binary forms, with or without
  8958. + * modification, are permitted provided that the following conditions
  8959. + * are met:
  8960. + * 1. Redistributions of source code must retain the above copyright
  8961. + * notice, this list of conditions, and the following disclaimer,
  8962. + * without modification.
  8963. + * 2. Redistributions in binary form must reproduce the above copyright
  8964. + * notice, this list of conditions and the following disclaimer in the
  8965. + * documentation and/or other materials provided with the distribution.
  8966. + * 3. The names of the above-listed copyright holders may not be used
  8967. + * to endorse or promote products derived from this software without
  8968. + * specific prior written permission.
  8969. + *
  8970. + * ALTERNATIVELY, this software may be distributed under the terms of the
  8971. + * GNU General Public License ("GPL") version 2, as published by the Free
  8972. + * Software Foundation.
  8973. + *
  8974. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  8975. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  8976. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  8977. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  8978. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  8979. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  8980. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  8981. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  8982. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  8983. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  8984. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  8985. + */
  8986. +
  8987. +#include <linux/kernel.h>
  8988. +#include <linux/module.h>
  8989. +#include <linux/init.h>
  8990. +#include <linux/hw_random.h>
  8991. +#include <linux/printk.h>
  8992. +
  8993. +#include <asm/io.h>
  8994. +#include <mach/hardware.h>
  8995. +#include <mach/platform.h>
  8996. +
  8997. +#define RNG_CTRL (0x0)
  8998. +#define RNG_STATUS (0x4)
  8999. +#define RNG_DATA (0x8)
  9000. +#define RNG_FF_THRESHOLD (0xc)
  9001. +
  9002. +/* enable rng */
  9003. +#define RNG_RBGEN 0x1
  9004. +/* double speed, less random mode */
  9005. +#define RNG_RBG2X 0x2
  9006. +
  9007. +/* the initial numbers generated are "less random" so will be discarded */
  9008. +#define RNG_WARMUP_COUNT 0x40000
  9009. +
  9010. +static int bcm2708_rng_data_read(struct hwrng *rng, u32 *buffer)
  9011. +{
  9012. + void __iomem *rng_base = (void __iomem *)rng->priv;
  9013. + unsigned words;
  9014. + /* wait for a random number to be in fifo */
  9015. + do {
  9016. + words = __raw_readl(rng_base + RNG_STATUS)>>24;
  9017. + }
  9018. + while (words == 0);
  9019. + /* read the random number */
  9020. + *buffer = __raw_readl(rng_base + RNG_DATA);
  9021. + return 4;
  9022. +}
  9023. +
  9024. +static struct hwrng bcm2708_rng_ops = {
  9025. + .name = "bcm2708",
  9026. + .data_read = bcm2708_rng_data_read,
  9027. +};
  9028. +
  9029. +static int __init bcm2708_rng_init(void)
  9030. +{
  9031. + void __iomem *rng_base;
  9032. + int err;
  9033. +
  9034. + /* map peripheral */
  9035. + rng_base = ioremap(RNG_BASE, 0x10);
  9036. + pr_info("bcm2708_rng_init=%p\n", rng_base);
  9037. + if (!rng_base) {
  9038. + pr_err("bcm2708_rng_init failed to ioremap\n");
  9039. + return -ENOMEM;
  9040. + }
  9041. + bcm2708_rng_ops.priv = (unsigned long)rng_base;
  9042. + /* register driver */
  9043. + err = hwrng_register(&bcm2708_rng_ops);
  9044. + if (err) {
  9045. + pr_err("bcm2708_rng_init hwrng_register()=%d\n", err);
  9046. + iounmap(rng_base);
  9047. + } else {
  9048. + /* set warm-up count & enable */
  9049. + __raw_writel(RNG_WARMUP_COUNT, rng_base + RNG_STATUS);
  9050. + __raw_writel(RNG_RBGEN, rng_base + RNG_CTRL);
  9051. + }
  9052. + return err;
  9053. +}
  9054. +
  9055. +static void __exit bcm2708_rng_exit(void)
  9056. +{
  9057. + void __iomem *rng_base = (void __iomem *)bcm2708_rng_ops.priv;
  9058. + pr_info("bcm2708_rng_exit\n");
  9059. + /* disable rng hardware */
  9060. + __raw_writel(0, rng_base + RNG_CTRL);
  9061. + /* unregister driver */
  9062. + hwrng_unregister(&bcm2708_rng_ops);
  9063. + iounmap(rng_base);
  9064. +}
  9065. +
  9066. +module_init(bcm2708_rng_init);
  9067. +module_exit(bcm2708_rng_exit);
  9068. +
  9069. +MODULE_DESCRIPTION("BCM2708 H/W Random Number Generator (RNG) driver");
  9070. +MODULE_LICENSE("GPL and additional rights");
  9071. diff -Nur linux-3.13.3.orig/drivers/char/hw_random/Kconfig linux-3.13.3/drivers/char/hw_random/Kconfig
  9072. --- linux-3.13.3.orig/drivers/char/hw_random/Kconfig 2014-02-13 23:00:14.000000000 +0100
  9073. +++ linux-3.13.3/drivers/char/hw_random/Kconfig 2014-02-17 22:41:01.000000000 +0100
  9074. @@ -341,6 +341,17 @@
  9075. If unsure, say Y.
  9076. +config HW_RANDOM_BCM2708
  9077. + tristate "BCM2708 generic true random number generator support"
  9078. + depends on HW_RANDOM && ARCH_BCM2708
  9079. + ---help---
  9080. + This driver provides the kernel-side support for the BCM2708 hardware.
  9081. +
  9082. + To compile this driver as a module, choose M here: the
  9083. + module will be called bcm2708-rng.
  9084. +
  9085. + If unsure, say N.
  9086. +
  9087. config HW_RANDOM_MSM
  9088. tristate "Qualcomm MSM Random Number Generator support"
  9089. depends on HW_RANDOM && ARCH_MSM
  9090. diff -Nur linux-3.13.3.orig/drivers/char/hw_random/Makefile linux-3.13.3/drivers/char/hw_random/Makefile
  9091. --- linux-3.13.3.orig/drivers/char/hw_random/Makefile 2014-02-13 23:00:14.000000000 +0100
  9092. +++ linux-3.13.3/drivers/char/hw_random/Makefile 2014-02-17 22:41:01.000000000 +0100
  9093. @@ -29,4 +29,5 @@
  9094. obj-$(CONFIG_HW_RANDOM_EXYNOS) += exynos-rng.o
  9095. obj-$(CONFIG_HW_RANDOM_TPM) += tpm-rng.o
  9096. obj-$(CONFIG_HW_RANDOM_BCM2835) += bcm2835-rng.o
  9097. +obj-$(CONFIG_HW_RANDOM_BCM2708) += bcm2708-rng.o
  9098. obj-$(CONFIG_HW_RANDOM_MSM) += msm-rng.o
  9099. diff -Nur linux-3.13.3.orig/drivers/char/Kconfig linux-3.13.3/drivers/char/Kconfig
  9100. --- linux-3.13.3.orig/drivers/char/Kconfig 2014-02-13 23:00:14.000000000 +0100
  9101. +++ linux-3.13.3/drivers/char/Kconfig 2014-02-17 22:41:01.000000000 +0100
  9102. @@ -580,6 +580,8 @@
  9103. source "drivers/s390/char/Kconfig"
  9104. +source "drivers/char/broadcom/Kconfig"
  9105. +
  9106. config MSM_SMD_PKT
  9107. bool "Enable device interface for some SMD packet ports"
  9108. default n
  9109. diff -Nur linux-3.13.3.orig/drivers/char/Makefile linux-3.13.3/drivers/char/Makefile
  9110. --- linux-3.13.3.orig/drivers/char/Makefile 2014-02-13 23:00:14.000000000 +0100
  9111. +++ linux-3.13.3/drivers/char/Makefile 2014-02-17 22:41:01.000000000 +0100
  9112. @@ -62,3 +62,5 @@
  9113. js-rtc-y = rtc.o
  9114. obj-$(CONFIG_TILE_SROM) += tile-srom.o
  9115. +
  9116. +obj-$(CONFIG_BRCM_CHAR_DRIVERS) += broadcom/
  9117. diff -Nur linux-3.13.3.orig/drivers/cpufreq/bcm2835-cpufreq.c linux-3.13.3/drivers/cpufreq/bcm2835-cpufreq.c
  9118. --- linux-3.13.3.orig/drivers/cpufreq/bcm2835-cpufreq.c 1970-01-01 01:00:00.000000000 +0100
  9119. +++ linux-3.13.3/drivers/cpufreq/bcm2835-cpufreq.c 2014-02-17 22:41:01.000000000 +0100
  9120. @@ -0,0 +1,239 @@
  9121. +/*****************************************************************************
  9122. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  9123. +*
  9124. +* Unless you and Broadcom execute a separate written software license
  9125. +* agreement governing use of this software, this software is licensed to you
  9126. +* under the terms of the GNU General Public License version 2, available at
  9127. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  9128. +*
  9129. +* Notwithstanding the above, under no circumstances may you combine this
  9130. +* software in any way with any other Broadcom software provided under a
  9131. +* license other than the GPL, without Broadcom's express prior written
  9132. +* consent.
  9133. +*****************************************************************************/
  9134. +
  9135. +/*****************************************************************************
  9136. +* FILENAME: bcm2835-cpufreq.h
  9137. +* DESCRIPTION: This driver dynamically manages the CPU Frequency of the ARM
  9138. +* processor. Messages are sent to Videocore either setting or requesting the
  9139. +* frequency of the ARM in order to match an appropiate frequency to the current
  9140. +* usage of the processor. The policy which selects the frequency to use is
  9141. +* defined in the kernel .config file, but can be changed during runtime.
  9142. +*****************************************************************************/
  9143. +
  9144. +/* ---------- INCLUDES ---------- */
  9145. +#include <linux/kernel.h>
  9146. +#include <linux/init.h>
  9147. +#include <linux/module.h>
  9148. +#include <linux/cpufreq.h>
  9149. +#include <mach/vcio.h>
  9150. +
  9151. +/* ---------- DEFINES ---------- */
  9152. +/*#define CPUFREQ_DEBUG_ENABLE*/ /* enable debugging */
  9153. +#define MODULE_NAME "bcm2835-cpufreq"
  9154. +
  9155. +#define VCMSG_ID_ARM_CLOCK 0x000000003 /* Clock/Voltage ID's */
  9156. +
  9157. +/* debug printk macros */
  9158. +#ifdef CPUFREQ_DEBUG_ENABLE
  9159. +#define print_debug(fmt,...) pr_debug("%s:%s:%d: "fmt, MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  9160. +#else
  9161. +#define print_debug(fmt,...)
  9162. +#endif
  9163. +#define print_err(fmt,...) pr_err("%s:%s:%d: "fmt, MODULE_NAME, __func__,__LINE__, ##__VA_ARGS__)
  9164. +#define print_info(fmt,...) pr_info("%s: "fmt, MODULE_NAME, ##__VA_ARGS__)
  9165. +
  9166. +/* tag part of the message */
  9167. +struct vc_msg_tag {
  9168. + uint32_t tag_id; /* the message id */
  9169. + uint32_t buffer_size; /* size of the buffer (which in this case is always 8 bytes) */
  9170. + uint32_t data_size; /* amount of data being sent or received */
  9171. + uint32_t dev_id; /* the ID of the clock/voltage to get or set */
  9172. + uint32_t val; /* the value (e.g. rate (in Hz)) to set */
  9173. +};
  9174. +
  9175. +/* message structure to be sent to videocore */
  9176. +struct vc_msg {
  9177. + uint32_t msg_size; /* simply, sizeof(struct vc_msg) */
  9178. + uint32_t request_code; /* holds various information like the success and number of bytes returned (refer to mailboxes wiki) */
  9179. + struct vc_msg_tag tag; /* the tag structure above to make */
  9180. + uint32_t end_tag; /* an end identifier, should be set to NULL */
  9181. +};
  9182. +
  9183. +/* ---------- GLOBALS ---------- */
  9184. +static struct cpufreq_driver bcm2835_cpufreq_driver; /* the cpufreq driver global */
  9185. +
  9186. +/*
  9187. + ===============================================
  9188. + clk_rate either gets or sets the clock rates.
  9189. + ===============================================
  9190. +*/
  9191. +static uint32_t bcm2835_cpufreq_set_clock(int cur_rate, int arm_rate)
  9192. +{
  9193. + int s, actual_rate=0;
  9194. + struct vc_msg msg;
  9195. +
  9196. + /* wipe all previous message data */
  9197. + memset(&msg, 0, sizeof msg);
  9198. +
  9199. + msg.msg_size = sizeof msg;
  9200. +
  9201. + msg.tag.tag_id = VCMSG_SET_CLOCK_RATE;
  9202. + msg.tag.buffer_size = 8;
  9203. + msg.tag.data_size = 8; /* we're sending the clock ID and the new rates which is a total of 2 words */
  9204. + msg.tag.dev_id = VCMSG_ID_ARM_CLOCK;
  9205. + msg.tag.val = arm_rate * 1000;
  9206. +
  9207. + /* send the message */
  9208. + s = bcm_mailbox_property(&msg, sizeof msg);
  9209. +
  9210. + /* check if it was all ok and return the rate in KHz */
  9211. + if (s == 0 && (msg.request_code & 0x80000000))
  9212. + actual_rate = msg.tag.val/1000;
  9213. +
  9214. + print_debug("Setting new frequency = %d -> %d (actual %d)\n", cur_rate, arm_rate, actual_rate);
  9215. + return actual_rate;
  9216. +}
  9217. +
  9218. +static uint32_t bcm2835_cpufreq_get_clock(int tag)
  9219. +{
  9220. + int s;
  9221. + int arm_rate = 0;
  9222. + struct vc_msg msg;
  9223. +
  9224. + /* wipe all previous message data */
  9225. + memset(&msg, 0, sizeof msg);
  9226. +
  9227. + msg.msg_size = sizeof msg;
  9228. + msg.tag.tag_id = tag;
  9229. + msg.tag.buffer_size = 8;
  9230. + msg.tag.data_size = 4; /* we're just sending the clock ID which is one word long */
  9231. + msg.tag.dev_id = VCMSG_ID_ARM_CLOCK;
  9232. +
  9233. + /* send the message */
  9234. + s = bcm_mailbox_property(&msg, sizeof msg);
  9235. +
  9236. + /* check if it was all ok and return the rate in KHz */
  9237. + if (s == 0 && (msg.request_code & 0x80000000))
  9238. + arm_rate = msg.tag.val/1000;
  9239. +
  9240. + print_debug("%s frequency = %d\n",
  9241. + tag == VCMSG_GET_CLOCK_RATE ? "Current":
  9242. + tag == VCMSG_GET_MIN_CLOCK ? "Min":
  9243. + tag == VCMSG_GET_MAX_CLOCK ? "Max":
  9244. + "Unexpected", arm_rate);
  9245. +
  9246. + return arm_rate;
  9247. +}
  9248. +
  9249. +/*
  9250. + ====================================================
  9251. + Module Initialisation registers the cpufreq driver
  9252. + ====================================================
  9253. +*/
  9254. +static int __init bcm2835_cpufreq_module_init(void)
  9255. +{
  9256. + print_debug("IN\n");
  9257. + return cpufreq_register_driver(&bcm2835_cpufreq_driver);
  9258. +}
  9259. +
  9260. +/*
  9261. + =============
  9262. + Module exit
  9263. + =============
  9264. +*/
  9265. +static void __exit bcm2835_cpufreq_module_exit(void)
  9266. +{
  9267. + print_debug("IN\n");
  9268. + cpufreq_unregister_driver(&bcm2835_cpufreq_driver);
  9269. + return;
  9270. +}
  9271. +
  9272. +/*
  9273. + ==============================================================
  9274. + Initialisation function sets up the CPU policy for first use
  9275. + ==============================================================
  9276. +*/
  9277. +static int bcm2835_cpufreq_driver_init(struct cpufreq_policy *policy)
  9278. +{
  9279. + /* measured value of how long it takes to change frequency */
  9280. + policy->cpuinfo.transition_latency = 355000; /* ns */
  9281. +
  9282. + /* now find out what the maximum and minimum frequencies are */
  9283. + policy->min = policy->cpuinfo.min_freq = bcm2835_cpufreq_get_clock(VCMSG_GET_MIN_CLOCK);
  9284. + policy->max = policy->cpuinfo.max_freq = bcm2835_cpufreq_get_clock(VCMSG_GET_MAX_CLOCK);
  9285. + policy->cur = bcm2835_cpufreq_get_clock(VCMSG_GET_CLOCK_RATE);
  9286. +
  9287. + print_info("min=%d max=%d cur=%d\n", policy->min, policy->max, policy->cur);
  9288. + return 0;
  9289. +}
  9290. +
  9291. +/*
  9292. + =================================================================================
  9293. + Target function chooses the most appropriate frequency from the table to enable
  9294. + =================================================================================
  9295. +*/
  9296. +
  9297. +static int bcm2835_cpufreq_driver_target(struct cpufreq_policy *policy, unsigned int target_freq, unsigned int relation)
  9298. +{
  9299. + unsigned int target = target_freq;
  9300. +#ifdef CPUFREQ_DEBUG_ENABLE
  9301. + unsigned int cur = policy->cur;
  9302. +#endif
  9303. + print_debug("%s: min=%d max=%d cur=%d target=%d\n",policy->governor->name,policy->min,policy->max,policy->cur,target_freq);
  9304. +
  9305. + /* if we are above min and using ondemand, then just use max */
  9306. + if (strcmp("ondemand", policy->governor->name)==0 && target > policy->min)
  9307. + target = policy->max;
  9308. + /* if the frequency is the same, just quit */
  9309. + if (target == policy->cur)
  9310. + return 0;
  9311. +
  9312. + /* otherwise were good to set the clock frequency */
  9313. + policy->cur = bcm2835_cpufreq_set_clock(policy->cur, target);
  9314. +
  9315. + if (!policy->cur)
  9316. + {
  9317. + print_err("Error occurred setting a new frequency (%d)!\n", target);
  9318. + policy->cur = bcm2835_cpufreq_get_clock(VCMSG_GET_CLOCK_RATE);
  9319. + return -EINVAL;
  9320. + }
  9321. + print_debug("Freq %d->%d (min=%d max=%d target=%d request=%d)\n", cur, policy->cur, policy->min, policy->max, target_freq, target);
  9322. + return 0;
  9323. +}
  9324. +
  9325. +static unsigned int bcm2835_cpufreq_driver_get(unsigned int cpu)
  9326. +{
  9327. + unsigned int actual_rate = bcm2835_cpufreq_get_clock(VCMSG_GET_CLOCK_RATE);
  9328. + print_debug("cpu=%d\n", actual_rate);
  9329. + return actual_rate;
  9330. +}
  9331. +
  9332. +/*
  9333. + =================================================================================
  9334. + Verify ensures that when a policy is changed, it is suitable for the CPU to use
  9335. + =================================================================================
  9336. +*/
  9337. +
  9338. +static int bcm2835_cpufreq_driver_verify(struct cpufreq_policy *policy)
  9339. +{
  9340. + print_info("switching to governor %s\n", policy->governor->name);
  9341. + return 0;
  9342. +}
  9343. +
  9344. +
  9345. +/* the CPUFreq driver */
  9346. +static struct cpufreq_driver bcm2835_cpufreq_driver = {
  9347. + .name = "BCM2835 CPUFreq",
  9348. + .init = bcm2835_cpufreq_driver_init,
  9349. + .verify = bcm2835_cpufreq_driver_verify,
  9350. + .target = bcm2835_cpufreq_driver_target,
  9351. + .get = bcm2835_cpufreq_driver_get
  9352. +};
  9353. +
  9354. +MODULE_AUTHOR("Dorian Peake and Dom Cobley");
  9355. +MODULE_DESCRIPTION("CPU frequency driver for BCM2835 chip");
  9356. +MODULE_LICENSE("GPL");
  9357. +
  9358. +module_init(bcm2835_cpufreq_module_init);
  9359. +module_exit(bcm2835_cpufreq_module_exit);
  9360. diff -Nur linux-3.13.3.orig/drivers/cpufreq/Kconfig.arm linux-3.13.3/drivers/cpufreq/Kconfig.arm
  9361. --- linux-3.13.3.orig/drivers/cpufreq/Kconfig.arm 2014-02-13 23:00:14.000000000 +0100
  9362. +++ linux-3.13.3/drivers/cpufreq/Kconfig.arm 2014-02-17 22:41:01.000000000 +0100
  9363. @@ -218,6 +218,14 @@
  9364. help
  9365. This adds the CPUFreq driver support for SPEAr SOCs.
  9366. +config ARM_BCM2835_CPUFREQ
  9367. + bool "BCM2835 Driver"
  9368. + default y
  9369. + help
  9370. + This adds the CPUFreq driver for BCM2835
  9371. +
  9372. + If in doubt, say N.
  9373. +
  9374. config ARM_TEGRA_CPUFREQ
  9375. bool "TEGRA CPUFreq support"
  9376. depends on ARCH_TEGRA
  9377. diff -Nur linux-3.13.3.orig/drivers/cpufreq/Makefile linux-3.13.3/drivers/cpufreq/Makefile
  9378. --- linux-3.13.3.orig/drivers/cpufreq/Makefile 2014-02-13 23:00:14.000000000 +0100
  9379. +++ linux-3.13.3/drivers/cpufreq/Makefile 2014-02-17 22:41:01.000000000 +0100
  9380. @@ -73,6 +73,7 @@
  9381. obj-$(CONFIG_ARM_SA1100_CPUFREQ) += sa1100-cpufreq.o
  9382. obj-$(CONFIG_ARM_SA1110_CPUFREQ) += sa1110-cpufreq.o
  9383. obj-$(CONFIG_ARM_SPEAR_CPUFREQ) += spear-cpufreq.o
  9384. +obj-$(CONFIG_ARM_BCM2835_CPUFREQ) += bcm2835-cpufreq.o
  9385. obj-$(CONFIG_ARM_TEGRA_CPUFREQ) += tegra-cpufreq.o
  9386. obj-$(CONFIG_ARM_VEXPRESS_SPC_CPUFREQ) += vexpress-spc-cpufreq.o
  9387. diff -Nur linux-3.13.3.orig/drivers/dma/bcm2708-dmaengine.c linux-3.13.3/drivers/dma/bcm2708-dmaengine.c
  9388. --- linux-3.13.3.orig/drivers/dma/bcm2708-dmaengine.c 1970-01-01 01:00:00.000000000 +0100
  9389. +++ linux-3.13.3/drivers/dma/bcm2708-dmaengine.c 2014-02-17 22:41:01.000000000 +0100
  9390. @@ -0,0 +1,588 @@
  9391. +/*
  9392. + * BCM2708 DMA engine support
  9393. + *
  9394. + * This driver only supports cyclic DMA transfers
  9395. + * as needed for the I2S module.
  9396. + *
  9397. + * Author: Florian Meier <florian.meier@koalo.de>
  9398. + * Copyright 2013
  9399. + *
  9400. + * Based on
  9401. + * OMAP DMAengine support by Russell King
  9402. + *
  9403. + * BCM2708 DMA Driver
  9404. + * Copyright (C) 2010 Broadcom
  9405. + *
  9406. + * Raspberry Pi PCM I2S ALSA Driver
  9407. + * Copyright (c) by Phil Poole 2013
  9408. + *
  9409. + * MARVELL MMP Peripheral DMA Driver
  9410. + * Copyright 2012 Marvell International Ltd.
  9411. + *
  9412. + * This program is free software; you can redistribute it and/or modify
  9413. + * it under the terms of the GNU General Public License as published by
  9414. + * the Free Software Foundation; either version 2 of the License, or
  9415. + * (at your option) any later version.
  9416. + *
  9417. + * This program is distributed in the hope that it will be useful,
  9418. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9419. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9420. + * GNU General Public License for more details.
  9421. + */
  9422. +#include <linux/dmaengine.h>
  9423. +#include <linux/dma-mapping.h>
  9424. +#include <linux/err.h>
  9425. +#include <linux/init.h>
  9426. +#include <linux/interrupt.h>
  9427. +#include <linux/list.h>
  9428. +#include <linux/module.h>
  9429. +#include <linux/platform_device.h>
  9430. +#include <linux/slab.h>
  9431. +#include <linux/io.h>
  9432. +#include <linux/spinlock.h>
  9433. +#include <linux/irq.h>
  9434. +
  9435. +#include "virt-dma.h"
  9436. +
  9437. +#include <mach/dma.h>
  9438. +#include <mach/irqs.h>
  9439. +
  9440. +struct bcm2708_dmadev {
  9441. + struct dma_device ddev;
  9442. + spinlock_t lock;
  9443. + void __iomem *base;
  9444. + struct device_dma_parameters dma_parms;
  9445. +};
  9446. +
  9447. +struct bcm2708_chan {
  9448. + struct virt_dma_chan vc;
  9449. + struct list_head node;
  9450. +
  9451. + struct dma_slave_config cfg;
  9452. + bool cyclic;
  9453. +
  9454. + int ch;
  9455. + struct bcm2708_desc *desc;
  9456. +
  9457. + void __iomem *chan_base;
  9458. + int irq_number;
  9459. +};
  9460. +
  9461. +struct bcm2708_desc {
  9462. + struct virt_dma_desc vd;
  9463. + enum dma_transfer_direction dir;
  9464. +
  9465. + unsigned int control_block_size;
  9466. + struct bcm2708_dma_cb *control_block_base;
  9467. + dma_addr_t control_block_base_phys;
  9468. +
  9469. + unsigned frames;
  9470. + size_t size;
  9471. +};
  9472. +
  9473. +#define BCM2708_DMA_DATA_TYPE_S8 1
  9474. +#define BCM2708_DMA_DATA_TYPE_S16 2
  9475. +#define BCM2708_DMA_DATA_TYPE_S32 4
  9476. +#define BCM2708_DMA_DATA_TYPE_S128 16
  9477. +
  9478. +static inline struct bcm2708_dmadev *to_bcm2708_dma_dev(struct dma_device *d)
  9479. +{
  9480. + return container_of(d, struct bcm2708_dmadev, ddev);
  9481. +}
  9482. +
  9483. +static inline struct bcm2708_chan *to_bcm2708_dma_chan(struct dma_chan *c)
  9484. +{
  9485. + return container_of(c, struct bcm2708_chan, vc.chan);
  9486. +}
  9487. +
  9488. +static inline struct bcm2708_desc *to_bcm2708_dma_desc(
  9489. + struct dma_async_tx_descriptor *t)
  9490. +{
  9491. + return container_of(t, struct bcm2708_desc, vd.tx);
  9492. +}
  9493. +
  9494. +static void bcm2708_dma_desc_free(struct virt_dma_desc *vd)
  9495. +{
  9496. + struct bcm2708_desc *desc = container_of(vd, struct bcm2708_desc, vd);
  9497. + dma_free_coherent(desc->vd.tx.chan->device->dev,
  9498. + desc->control_block_size,
  9499. + desc->control_block_base,
  9500. + desc->control_block_base_phys);
  9501. + kfree(desc);
  9502. +}
  9503. +
  9504. +static void bcm2708_dma_start_desc(struct bcm2708_chan *c)
  9505. +{
  9506. + struct virt_dma_desc *vd = vchan_next_desc(&c->vc);
  9507. + struct bcm2708_desc *d;
  9508. +
  9509. + if (!vd) {
  9510. + c->desc = NULL;
  9511. + return;
  9512. + }
  9513. +
  9514. + list_del(&vd->node);
  9515. +
  9516. + c->desc = d = to_bcm2708_dma_desc(&vd->tx);
  9517. +
  9518. + bcm_dma_start(c->chan_base, d->control_block_base_phys);
  9519. +}
  9520. +
  9521. +static irqreturn_t bcm2708_dma_callback(int irq, void *data)
  9522. +{
  9523. + struct bcm2708_chan *c = data;
  9524. + struct bcm2708_desc *d;
  9525. + unsigned long flags;
  9526. +
  9527. + spin_lock_irqsave(&c->vc.lock, flags);
  9528. +
  9529. + /* Acknowledge interrupt */
  9530. + writel(BCM2708_DMA_INT, c->chan_base + BCM2708_DMA_CS);
  9531. +
  9532. + d = c->desc;
  9533. +
  9534. + if (d) {
  9535. + /* TODO Only works for cyclic DMA */
  9536. + vchan_cyclic_callback(&d->vd);
  9537. + }
  9538. +
  9539. + /* Keep the DMA engine running */
  9540. + dsb(); /* ARM synchronization barrier */
  9541. + writel(BCM2708_DMA_ACTIVE, c->chan_base + BCM2708_DMA_CS);
  9542. +
  9543. + spin_unlock_irqrestore(&c->vc.lock, flags);
  9544. +
  9545. + return IRQ_HANDLED;
  9546. +}
  9547. +
  9548. +static int bcm2708_dma_alloc_chan_resources(struct dma_chan *chan)
  9549. +{
  9550. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  9551. +
  9552. + return request_irq(c->irq_number,
  9553. + bcm2708_dma_callback, 0, "DMA IRQ", c);
  9554. +}
  9555. +
  9556. +static void bcm2708_dma_free_chan_resources(struct dma_chan *chan)
  9557. +{
  9558. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  9559. +
  9560. + vchan_free_chan_resources(&c->vc);
  9561. + free_irq(c->irq_number, c);
  9562. +
  9563. + dev_dbg(c->vc.chan.device->dev, "Freeing DMA channel %u\n", c->ch);
  9564. +}
  9565. +
  9566. +static size_t bcm2708_dma_desc_size(struct bcm2708_desc *d)
  9567. +{
  9568. + return d->size;
  9569. +}
  9570. +
  9571. +static size_t bcm2708_dma_desc_size_pos(struct bcm2708_desc *d, dma_addr_t addr)
  9572. +{
  9573. + unsigned i;
  9574. + size_t size;
  9575. +
  9576. + for (size = i = 0; i < d->frames; i++) {
  9577. + struct bcm2708_dma_cb *control_block =
  9578. + &d->control_block_base[i];
  9579. + size_t this_size = control_block->length;
  9580. + dma_addr_t dma;
  9581. +
  9582. + if (d->dir == DMA_DEV_TO_MEM)
  9583. + dma = control_block->dst;
  9584. + else
  9585. + dma = control_block->src;
  9586. +
  9587. + if (size)
  9588. + size += this_size;
  9589. + else if (addr >= dma && addr < dma + this_size)
  9590. + size += dma + this_size - addr;
  9591. + }
  9592. +
  9593. + return size;
  9594. +}
  9595. +
  9596. +static enum dma_status bcm2708_dma_tx_status(struct dma_chan *chan,
  9597. + dma_cookie_t cookie, struct dma_tx_state *txstate)
  9598. +{
  9599. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  9600. + struct virt_dma_desc *vd;
  9601. + enum dma_status ret;
  9602. + unsigned long flags;
  9603. +
  9604. + ret = dma_cookie_status(chan, cookie, txstate);
  9605. + if (ret == DMA_COMPLETE || !txstate)
  9606. + return ret;
  9607. +
  9608. + spin_lock_irqsave(&c->vc.lock, flags);
  9609. + vd = vchan_find_desc(&c->vc, cookie);
  9610. + if (vd) {
  9611. + txstate->residue =
  9612. + bcm2708_dma_desc_size(to_bcm2708_dma_desc(&vd->tx));
  9613. + } else if (c->desc && c->desc->vd.tx.cookie == cookie) {
  9614. + struct bcm2708_desc *d = c->desc;
  9615. + dma_addr_t pos;
  9616. +
  9617. + if (d->dir == DMA_MEM_TO_DEV)
  9618. + pos = readl(c->chan_base + BCM2708_DMA_SOURCE_AD);
  9619. + else if (d->dir == DMA_DEV_TO_MEM)
  9620. + pos = readl(c->chan_base + BCM2708_DMA_DEST_AD);
  9621. + else
  9622. + pos = 0;
  9623. +
  9624. + txstate->residue = bcm2708_dma_desc_size_pos(d, pos);
  9625. + } else {
  9626. + txstate->residue = 0;
  9627. + }
  9628. +
  9629. + spin_unlock_irqrestore(&c->vc.lock, flags);
  9630. +
  9631. + return ret;
  9632. +}
  9633. +
  9634. +static void bcm2708_dma_issue_pending(struct dma_chan *chan)
  9635. +{
  9636. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  9637. + unsigned long flags;
  9638. +
  9639. + c->cyclic = true; /* Nothing else is implemented */
  9640. +
  9641. + spin_lock_irqsave(&c->vc.lock, flags);
  9642. + if (vchan_issue_pending(&c->vc) && !c->desc)
  9643. + bcm2708_dma_start_desc(c);
  9644. +
  9645. + spin_unlock_irqrestore(&c->vc.lock, flags);
  9646. +}
  9647. +
  9648. +static struct dma_async_tx_descriptor *bcm2708_dma_prep_dma_cyclic(
  9649. + struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len,
  9650. + size_t period_len, enum dma_transfer_direction direction,
  9651. + unsigned long flags, void *context)
  9652. +{
  9653. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  9654. + enum dma_slave_buswidth dev_width;
  9655. + struct bcm2708_desc *d;
  9656. + dma_addr_t dev_addr;
  9657. + unsigned es, sync_type;
  9658. + unsigned frame;
  9659. +
  9660. + /* Grab configuration */
  9661. + if (direction == DMA_DEV_TO_MEM) {
  9662. + dev_addr = c->cfg.src_addr;
  9663. + dev_width = c->cfg.src_addr_width;
  9664. + sync_type = BCM2708_DMA_S_DREQ;
  9665. + } else if (direction == DMA_MEM_TO_DEV) {
  9666. + dev_addr = c->cfg.dst_addr;
  9667. + dev_width = c->cfg.dst_addr_width;
  9668. + sync_type = BCM2708_DMA_D_DREQ;
  9669. + } else {
  9670. + dev_err(chan->device->dev, "%s: bad direction?\n", __func__);
  9671. + return NULL;
  9672. + }
  9673. +
  9674. + /* Bus width translates to the element size (ES) */
  9675. + switch (dev_width) {
  9676. + case DMA_SLAVE_BUSWIDTH_4_BYTES:
  9677. + es = BCM2708_DMA_DATA_TYPE_S32;
  9678. + break;
  9679. + default:
  9680. + return NULL;
  9681. + }
  9682. +
  9683. + /* Now allocate and setup the descriptor. */
  9684. + d = kzalloc(sizeof(*d), GFP_NOWAIT);
  9685. + if (!d)
  9686. + return NULL;
  9687. +
  9688. + d->dir = direction;
  9689. + d->frames = buf_len / period_len;
  9690. +
  9691. + /* Allocate memory for control blocks */
  9692. + d->control_block_size = d->frames * sizeof(struct bcm2708_dma_cb);
  9693. + d->control_block_base = dma_zalloc_coherent(chan->device->dev,
  9694. + d->control_block_size, &d->control_block_base_phys,
  9695. + GFP_NOWAIT);
  9696. +
  9697. + if (!d->control_block_base) {
  9698. + kfree(d);
  9699. + return NULL;
  9700. + }
  9701. +
  9702. + /*
  9703. + * Iterate over all frames, create a control block
  9704. + * for each frame and link them together.
  9705. + */
  9706. + for (frame = 0; frame < d->frames; frame++) {
  9707. + struct bcm2708_dma_cb *control_block =
  9708. + &d->control_block_base[frame];
  9709. +
  9710. + /* Setup adresses */
  9711. + if (d->dir == DMA_DEV_TO_MEM) {
  9712. + control_block->info = BCM2708_DMA_D_INC;
  9713. + control_block->src = dev_addr;
  9714. + control_block->dst = buf_addr + frame * period_len;
  9715. + } else {
  9716. + control_block->info = BCM2708_DMA_S_INC;
  9717. + control_block->src = buf_addr + frame * period_len;
  9718. + control_block->dst = dev_addr;
  9719. + }
  9720. +
  9721. + /* Enable interrupt */
  9722. + control_block->info |= BCM2708_DMA_INT_EN;
  9723. +
  9724. + /* Setup synchronization */
  9725. + if (sync_type != 0)
  9726. + control_block->info |= sync_type;
  9727. +
  9728. + /* Setup DREQ channel */
  9729. + if (c->cfg.slave_id != 0)
  9730. + control_block->info |=
  9731. + BCM2708_DMA_PER_MAP(c->cfg.slave_id);
  9732. +
  9733. + /* Length of a frame */
  9734. + control_block->length = period_len;
  9735. + d->size += control_block->length;
  9736. +
  9737. + /*
  9738. + * Next block is the next frame.
  9739. + * This DMA engine driver currently only supports cyclic DMA.
  9740. + * Therefore, wrap around at number of frames.
  9741. + */
  9742. + control_block->next = d->control_block_base_phys +
  9743. + sizeof(struct bcm2708_dma_cb)
  9744. + * ((frame + 1) % d->frames);
  9745. + }
  9746. +
  9747. + return vchan_tx_prep(&c->vc, &d->vd, flags);
  9748. +}
  9749. +
  9750. +static int bcm2708_dma_slave_config(struct bcm2708_chan *c,
  9751. + struct dma_slave_config *cfg)
  9752. +{
  9753. + if ((cfg->direction == DMA_DEV_TO_MEM &&
  9754. + cfg->src_addr_width != DMA_SLAVE_BUSWIDTH_4_BYTES) ||
  9755. + (cfg->direction == DMA_MEM_TO_DEV &&
  9756. + cfg->dst_addr_width != DMA_SLAVE_BUSWIDTH_4_BYTES) ||
  9757. + !is_slave_direction(cfg->direction)) {
  9758. + return -EINVAL;
  9759. + }
  9760. +
  9761. + c->cfg = *cfg;
  9762. +
  9763. + return 0;
  9764. +}
  9765. +
  9766. +static int bcm2708_dma_terminate_all(struct bcm2708_chan *c)
  9767. +{
  9768. + struct bcm2708_dmadev *d = to_bcm2708_dma_dev(c->vc.chan.device);
  9769. + unsigned long flags;
  9770. + int timeout = 10000;
  9771. + LIST_HEAD(head);
  9772. +
  9773. + spin_lock_irqsave(&c->vc.lock, flags);
  9774. +
  9775. + /* Prevent this channel being scheduled */
  9776. + spin_lock(&d->lock);
  9777. + list_del_init(&c->node);
  9778. + spin_unlock(&d->lock);
  9779. +
  9780. + /*
  9781. + * Stop DMA activity: we assume the callback will not be called
  9782. + * after bcm_dma_abort() returns (even if it does, it will see
  9783. + * c->desc is NULL and exit.)
  9784. + */
  9785. + if (c->desc) {
  9786. + c->desc = NULL;
  9787. + bcm_dma_abort(c->chan_base);
  9788. +
  9789. + /* Wait for stopping */
  9790. + while (timeout > 0) {
  9791. + timeout--;
  9792. + if (!(readl(c->chan_base + BCM2708_DMA_CS) &
  9793. + BCM2708_DMA_ACTIVE))
  9794. + break;
  9795. +
  9796. + cpu_relax();
  9797. + }
  9798. +
  9799. + if (timeout <= 0)
  9800. + dev_err(d->ddev.dev, "DMA transfer could not be terminated\n");
  9801. + }
  9802. +
  9803. + vchan_get_all_descriptors(&c->vc, &head);
  9804. + spin_unlock_irqrestore(&c->vc.lock, flags);
  9805. + vchan_dma_desc_free_list(&c->vc, &head);
  9806. +
  9807. + return 0;
  9808. +}
  9809. +
  9810. +static int bcm2708_dma_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
  9811. + unsigned long arg)
  9812. +{
  9813. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  9814. +
  9815. + switch (cmd) {
  9816. + case DMA_SLAVE_CONFIG:
  9817. + return bcm2708_dma_slave_config(c,
  9818. + (struct dma_slave_config *)arg);
  9819. +
  9820. + case DMA_TERMINATE_ALL:
  9821. + return bcm2708_dma_terminate_all(c);
  9822. +
  9823. + default:
  9824. + return -ENXIO;
  9825. + }
  9826. +}
  9827. +
  9828. +static int bcm2708_dma_chan_init(struct bcm2708_dmadev *d, void __iomem* chan_base,
  9829. + int chan_id, int irq)
  9830. +{
  9831. + struct bcm2708_chan *c;
  9832. +
  9833. + c = devm_kzalloc(d->ddev.dev, sizeof(*c), GFP_KERNEL);
  9834. + if (!c)
  9835. + return -ENOMEM;
  9836. +
  9837. + c->vc.desc_free = bcm2708_dma_desc_free;
  9838. + vchan_init(&c->vc, &d->ddev);
  9839. + INIT_LIST_HEAD(&c->node);
  9840. +
  9841. + d->ddev.chancnt++;
  9842. +
  9843. + c->chan_base = chan_base;
  9844. + c->ch = chan_id;
  9845. + c->irq_number = irq;
  9846. +
  9847. + return 0;
  9848. +}
  9849. +
  9850. +static void bcm2708_dma_free(struct bcm2708_dmadev *od)
  9851. +{
  9852. + while (!list_empty(&od->ddev.channels)) {
  9853. + struct bcm2708_chan *c = list_first_entry(&od->ddev.channels,
  9854. + struct bcm2708_chan, vc.chan.device_node);
  9855. +
  9856. + list_del(&c->vc.chan.device_node);
  9857. + tasklet_kill(&c->vc.task);
  9858. + }
  9859. +}
  9860. +
  9861. +static int bcm2708_dma_probe(struct platform_device *pdev)
  9862. +{
  9863. + struct bcm2708_dmadev *od;
  9864. + int rc, i;
  9865. +
  9866. + if (!pdev->dev.dma_mask)
  9867. + pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
  9868. +
  9869. + rc = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
  9870. + if (rc)
  9871. + return rc;
  9872. + dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
  9873. +
  9874. + od = devm_kzalloc(&pdev->dev, sizeof(*od), GFP_KERNEL);
  9875. + if (!od)
  9876. + return -ENOMEM;
  9877. +
  9878. + pdev->dev.dma_parms = &od->dma_parms;
  9879. + dma_set_max_seg_size(&pdev->dev, 0x3FFFFFFF);
  9880. +
  9881. + dma_cap_set(DMA_SLAVE, od->ddev.cap_mask);
  9882. + dma_cap_set(DMA_CYCLIC, od->ddev.cap_mask);
  9883. + od->ddev.device_alloc_chan_resources = bcm2708_dma_alloc_chan_resources;
  9884. + od->ddev.device_free_chan_resources = bcm2708_dma_free_chan_resources;
  9885. + od->ddev.device_tx_status = bcm2708_dma_tx_status;
  9886. + od->ddev.device_issue_pending = bcm2708_dma_issue_pending;
  9887. + od->ddev.device_prep_dma_cyclic = bcm2708_dma_prep_dma_cyclic;
  9888. + od->ddev.device_control = bcm2708_dma_control;
  9889. + od->ddev.dev = &pdev->dev;
  9890. + INIT_LIST_HEAD(&od->ddev.channels);
  9891. + spin_lock_init(&od->lock);
  9892. +
  9893. + platform_set_drvdata(pdev, od);
  9894. +
  9895. + for (i = 0; i < 16; i++) {
  9896. + void __iomem* chan_base;
  9897. + int chan_id, irq;
  9898. +
  9899. + chan_id = bcm_dma_chan_alloc(BCM_DMA_FEATURE_FAST,
  9900. + &chan_base,
  9901. + &irq);
  9902. +
  9903. + if (chan_id < 0)
  9904. + break;
  9905. +
  9906. + rc = bcm2708_dma_chan_init(od, chan_base, chan_id, irq);
  9907. + if (rc) {
  9908. + bcm2708_dma_free(od);
  9909. + return rc;
  9910. + }
  9911. + }
  9912. +
  9913. + rc = dma_async_device_register(&od->ddev);
  9914. + if (rc) {
  9915. + dev_err(&pdev->dev,
  9916. + "Failed to register slave DMA engine device: %d\n", rc);
  9917. + bcm2708_dma_free(od);
  9918. + return rc;
  9919. + }
  9920. +
  9921. + dev_dbg(&pdev->dev, "Load BCM2708 DMA engine driver\n");
  9922. +
  9923. + return rc;
  9924. +}
  9925. +
  9926. +static int bcm2708_dma_remove(struct platform_device *pdev)
  9927. +{
  9928. + struct bcm2708_dmadev *od = platform_get_drvdata(pdev);
  9929. +
  9930. + dma_async_device_unregister(&od->ddev);
  9931. + bcm2708_dma_free(od);
  9932. +
  9933. + return 0;
  9934. +}
  9935. +
  9936. +static struct platform_driver bcm2708_dma_driver = {
  9937. + .probe = bcm2708_dma_probe,
  9938. + .remove = bcm2708_dma_remove,
  9939. + .driver = {
  9940. + .name = "bcm2708-dmaengine",
  9941. + .owner = THIS_MODULE,
  9942. + },
  9943. +};
  9944. +
  9945. +static struct platform_device *pdev;
  9946. +
  9947. +static const struct platform_device_info bcm2708_dma_dev_info = {
  9948. + .name = "bcm2708-dmaengine",
  9949. + .id = -1,
  9950. +};
  9951. +
  9952. +static int bcm2708_dma_init(void)
  9953. +{
  9954. + int rc = platform_driver_register(&bcm2708_dma_driver);
  9955. +
  9956. + if (rc == 0) {
  9957. + pdev = platform_device_register_full(&bcm2708_dma_dev_info);
  9958. + if (IS_ERR(pdev)) {
  9959. + platform_driver_unregister(&bcm2708_dma_driver);
  9960. + rc = PTR_ERR(pdev);
  9961. + }
  9962. + }
  9963. +
  9964. + return rc;
  9965. +}
  9966. +subsys_initcall(bcm2708_dma_init);
  9967. +
  9968. +static void __exit bcm2708_dma_exit(void)
  9969. +{
  9970. + platform_device_unregister(pdev);
  9971. + platform_driver_unregister(&bcm2708_dma_driver);
  9972. +}
  9973. +module_exit(bcm2708_dma_exit);
  9974. +
  9975. +MODULE_ALIAS("platform:bcm2708-dma");
  9976. +MODULE_DESCRIPTION("BCM2708 DMA engine driver");
  9977. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  9978. +MODULE_LICENSE("GPL v2");
  9979. diff -Nur linux-3.13.3.orig/drivers/dma/Kconfig linux-3.13.3/drivers/dma/Kconfig
  9980. --- linux-3.13.3.orig/drivers/dma/Kconfig 2014-02-13 23:00:14.000000000 +0100
  9981. +++ linux-3.13.3/drivers/dma/Kconfig 2014-02-17 22:41:01.000000000 +0100
  9982. @@ -312,6 +312,12 @@
  9983. The Communications Port Programming Interface (CPPI) 4.1 DMA engine
  9984. is currently used by the USB driver on AM335x platforms.
  9985. +config DMA_BCM2708
  9986. + tristate "BCM2708 DMA engine support"
  9987. + depends on MACH_BCM2708
  9988. + select DMA_ENGINE
  9989. + select DMA_VIRTUAL_CHANNELS
  9990. +
  9991. config MMP_PDMA
  9992. bool "MMP PDMA support"
  9993. depends on (ARCH_MMP || ARCH_PXA)
  9994. diff -Nur linux-3.13.3.orig/drivers/dma/Makefile linux-3.13.3/drivers/dma/Makefile
  9995. --- linux-3.13.3.orig/drivers/dma/Makefile 2014-02-13 23:00:14.000000000 +0100
  9996. +++ linux-3.13.3/drivers/dma/Makefile 2014-02-17 22:41:01.000000000 +0100
  9997. @@ -38,6 +38,7 @@
  9998. obj-$(CONFIG_DMA_SA11X0) += sa11x0-dma.o
  9999. obj-$(CONFIG_MMP_TDMA) += mmp_tdma.o
  10000. obj-$(CONFIG_DMA_OMAP) += omap-dma.o
  10001. +obj-$(CONFIG_DMA_BCM2708) += bcm2708-dmaengine.o
  10002. obj-$(CONFIG_MMP_PDMA) += mmp_pdma.o
  10003. obj-$(CONFIG_DMA_JZ4740) += dma-jz4740.o
  10004. obj-$(CONFIG_TI_CPPI41) += cppi41.o
  10005. diff -Nur linux-3.13.3.orig/drivers/hwmon/bcm2835-hwmon.c linux-3.13.3/drivers/hwmon/bcm2835-hwmon.c
  10006. --- linux-3.13.3.orig/drivers/hwmon/bcm2835-hwmon.c 1970-01-01 01:00:00.000000000 +0100
  10007. +++ linux-3.13.3/drivers/hwmon/bcm2835-hwmon.c 2014-02-17 22:41:01.000000000 +0100
  10008. @@ -0,0 +1,219 @@
  10009. +/*****************************************************************************
  10010. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  10011. +*
  10012. +* Unless you and Broadcom execute a separate written software license
  10013. +* agreement governing use of this software, this software is licensed to you
  10014. +* under the terms of the GNU General Public License version 2, available at
  10015. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  10016. +*
  10017. +* Notwithstanding the above, under no circumstances may you combine this
  10018. +* software in any way with any other Broadcom software provided under a
  10019. +* license other than the GPL, without Broadcom's express prior written
  10020. +* consent.
  10021. +*****************************************************************************/
  10022. +
  10023. +#include <linux/kernel.h>
  10024. +#include <linux/module.h>
  10025. +#include <linux/init.h>
  10026. +#include <linux/hwmon.h>
  10027. +#include <linux/hwmon-sysfs.h>
  10028. +#include <linux/platform_device.h>
  10029. +#include <linux/sysfs.h>
  10030. +#include <mach/vcio.h>
  10031. +#include <linux/slab.h>
  10032. +#include <linux/err.h>
  10033. +
  10034. +#define MODULE_NAME "bcm2835_hwmon"
  10035. +
  10036. +/*#define HWMON_DEBUG_ENABLE*/
  10037. +
  10038. +#ifdef HWMON_DEBUG_ENABLE
  10039. +#define print_debug(fmt,...) printk(KERN_INFO "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  10040. +#else
  10041. +#define print_debug(fmt,...)
  10042. +#endif
  10043. +#define print_err(fmt,...) printk(KERN_ERR "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__,__LINE__, ##__VA_ARGS__)
  10044. +#define print_info(fmt,...) printk(KERN_INFO "%s: "fmt"\n", MODULE_NAME, ##__VA_ARGS__)
  10045. +
  10046. +#define VC_TAG_GET_TEMP 0x00030006
  10047. +#define VC_TAG_GET_MAX_TEMP 0x0003000A
  10048. +
  10049. +/* --- STRUCTS --- */
  10050. +struct bcm2835_hwmon_data {
  10051. + struct device *hwmon_dev;
  10052. +};
  10053. +
  10054. +/* tag part of the message */
  10055. +struct vc_msg_tag {
  10056. + uint32_t tag_id; /* the tag ID for the temperature */
  10057. + uint32_t buffer_size; /* size of the buffer (should be 8) */
  10058. + uint32_t request_code; /* identifies message as a request (should be 0) */
  10059. + uint32_t id; /* extra ID field (should be 0) */
  10060. + uint32_t val; /* returned value of the temperature */
  10061. +};
  10062. +
  10063. +/* message structure to be sent to videocore */
  10064. +struct vc_msg {
  10065. + uint32_t msg_size; /* simply, sizeof(struct vc_msg) */
  10066. + uint32_t request_code; /* holds various information like the success and number of bytes returned (refer to mailboxes wiki) */
  10067. + struct vc_msg_tag tag; /* the tag structure above to make */
  10068. + uint32_t end_tag; /* an end identifier, should be set to NULL */
  10069. +};
  10070. +
  10071. +typedef enum {
  10072. + TEMP,
  10073. + MAX_TEMP,
  10074. +} temp_type;
  10075. +
  10076. +/* --- PROTOTYPES --- */
  10077. +static ssize_t bcm2835_get_temp(struct device *dev, struct device_attribute *attr, char *buf);
  10078. +static ssize_t bcm2835_get_name(struct device *dev, struct device_attribute *attr, char *buf);
  10079. +
  10080. +/* --- GLOBALS --- */
  10081. +
  10082. +static struct bcm2835_hwmon_data *bcm2835_data;
  10083. +static struct platform_driver bcm2835_hwmon_driver;
  10084. +
  10085. +static SENSOR_DEVICE_ATTR(name, S_IRUGO,bcm2835_get_name,NULL,0);
  10086. +static SENSOR_DEVICE_ATTR(temp1_input,S_IRUGO,bcm2835_get_temp,NULL,TEMP);
  10087. +static SENSOR_DEVICE_ATTR(temp1_max,S_IRUGO,bcm2835_get_temp,NULL,MAX_TEMP);
  10088. +
  10089. +static struct attribute* bcm2835_attributes[] = {
  10090. + &sensor_dev_attr_name.dev_attr.attr,
  10091. + &sensor_dev_attr_temp1_input.dev_attr.attr,
  10092. + &sensor_dev_attr_temp1_max.dev_attr.attr,
  10093. + NULL,
  10094. +};
  10095. +
  10096. +static struct attribute_group bcm2835_attr_group = {
  10097. + .attrs = bcm2835_attributes,
  10098. +};
  10099. +
  10100. +/* --- FUNCTIONS --- */
  10101. +
  10102. +static ssize_t bcm2835_get_name(struct device *dev, struct device_attribute *attr, char *buf)
  10103. +{
  10104. + return sprintf(buf,"bcm2835_hwmon\n");
  10105. +}
  10106. +
  10107. +static ssize_t bcm2835_get_temp(struct device *dev, struct device_attribute *attr, char *buf)
  10108. +{
  10109. + struct vc_msg msg;
  10110. + int result;
  10111. + uint temp = 0;
  10112. + int index = ((struct sensor_device_attribute*)to_sensor_dev_attr(attr))->index;
  10113. +
  10114. + print_debug("IN");
  10115. +
  10116. + /* wipe all previous message data */
  10117. + memset(&msg, 0, sizeof msg);
  10118. +
  10119. + /* determine the message type */
  10120. + if(index == TEMP)
  10121. + msg.tag.tag_id = VC_TAG_GET_TEMP;
  10122. + else if (index == MAX_TEMP)
  10123. + msg.tag.tag_id = VC_TAG_GET_MAX_TEMP;
  10124. + else
  10125. + {
  10126. + print_debug("Unknown temperature message!");
  10127. + return -EINVAL;
  10128. + }
  10129. +
  10130. + msg.msg_size = sizeof msg;
  10131. + msg.tag.buffer_size = 8;
  10132. +
  10133. + /* send the message */
  10134. + result = bcm_mailbox_property(&msg, sizeof msg);
  10135. +
  10136. + /* check if it was all ok and return the rate in milli degrees C */
  10137. + if (result == 0 && (msg.request_code & 0x80000000))
  10138. + temp = (uint)msg.tag.val;
  10139. + #ifdef HWMON_DEBUG_ENABLE
  10140. + else
  10141. + print_debug("Failed to get temperature!");
  10142. + #endif
  10143. + print_debug("Got temperature as %u",temp);
  10144. + print_debug("OUT");
  10145. + return sprintf(buf, "%u\n", temp);
  10146. +}
  10147. +
  10148. +
  10149. +static int bcm2835_hwmon_probe(struct platform_device *pdev)
  10150. +{
  10151. + int err;
  10152. +
  10153. + print_debug("IN");
  10154. + print_debug("HWMON Driver has been probed!");
  10155. +
  10156. + /* check that the device isn't null!*/
  10157. + if(pdev == NULL)
  10158. + {
  10159. + print_debug("Platform device is empty!");
  10160. + return -ENODEV;
  10161. + }
  10162. +
  10163. + /* allocate memory for neccessary data */
  10164. + bcm2835_data = kzalloc(sizeof(struct bcm2835_hwmon_data),GFP_KERNEL);
  10165. + if(!bcm2835_data)
  10166. + {
  10167. + print_debug("Unable to allocate memory for hwmon data!");
  10168. + err = -ENOMEM;
  10169. + goto kzalloc_error;
  10170. + }
  10171. +
  10172. + /* create the sysfs files */
  10173. + if(sysfs_create_group(&pdev->dev.kobj, &bcm2835_attr_group))
  10174. + {
  10175. + print_debug("Unable to create sysfs files!");
  10176. + err = -EFAULT;
  10177. + goto sysfs_error;
  10178. + }
  10179. +
  10180. + /* register the hwmon device */
  10181. + bcm2835_data->hwmon_dev = hwmon_device_register(&pdev->dev);
  10182. + if (IS_ERR(bcm2835_data->hwmon_dev))
  10183. + {
  10184. + err = PTR_ERR(bcm2835_data->hwmon_dev);
  10185. + goto hwmon_error;
  10186. + }
  10187. + print_debug("OUT");
  10188. + return 0;
  10189. +
  10190. + /* error goto's */
  10191. + hwmon_error:
  10192. + sysfs_remove_group(&pdev->dev.kobj, &bcm2835_attr_group);
  10193. +
  10194. + sysfs_error:
  10195. + kfree(bcm2835_data);
  10196. +
  10197. + kzalloc_error:
  10198. +
  10199. + return err;
  10200. +
  10201. +}
  10202. +
  10203. +static int bcm2835_hwmon_remove(struct platform_device *pdev)
  10204. +{
  10205. + print_debug("IN");
  10206. + hwmon_device_unregister(bcm2835_data->hwmon_dev);
  10207. +
  10208. + sysfs_remove_group(&pdev->dev.kobj, &bcm2835_attr_group);
  10209. + print_debug("OUT");
  10210. + return 0;
  10211. +}
  10212. +
  10213. +/* Hwmon Driver */
  10214. +static struct platform_driver bcm2835_hwmon_driver = {
  10215. + .probe = bcm2835_hwmon_probe,
  10216. + .remove = bcm2835_hwmon_remove,
  10217. + .driver = {
  10218. + .name = "bcm2835_hwmon",
  10219. + .owner = THIS_MODULE,
  10220. + },
  10221. +};
  10222. +
  10223. +MODULE_LICENSE("GPL");
  10224. +MODULE_AUTHOR("Dorian Peake");
  10225. +MODULE_DESCRIPTION("HW Monitor driver for bcm2835 chip");
  10226. +
  10227. +module_platform_driver(bcm2835_hwmon_driver);
  10228. diff -Nur linux-3.13.3.orig/drivers/hwmon/Kconfig linux-3.13.3/drivers/hwmon/Kconfig
  10229. --- linux-3.13.3.orig/drivers/hwmon/Kconfig 2014-02-13 23:00:14.000000000 +0100
  10230. +++ linux-3.13.3/drivers/hwmon/Kconfig 2014-02-17 22:41:01.000000000 +0100
  10231. @@ -1554,6 +1554,16 @@
  10232. help
  10233. Support for the A/D converter on MC13783 and MC13892 PMIC.
  10234. +config SENSORS_BCM2835
  10235. + depends on THERMAL_BCM2835=n
  10236. + tristate "Broadcom BCM2835 HWMON Driver"
  10237. + help
  10238. + If you say yes here you get support for the hardware
  10239. + monitoring features of the BCM2835 Chip
  10240. +
  10241. + This driver can also be built as a module. If so, the module
  10242. + will be called bcm2835-hwmon.
  10243. +
  10244. if ACPI
  10245. comment "ACPI drivers"
  10246. diff -Nur linux-3.13.3.orig/drivers/hwmon/Makefile linux-3.13.3/drivers/hwmon/Makefile
  10247. --- linux-3.13.3.orig/drivers/hwmon/Makefile 2014-02-13 23:00:14.000000000 +0100
  10248. +++ linux-3.13.3/drivers/hwmon/Makefile 2014-02-17 22:41:01.000000000 +0100
  10249. @@ -142,6 +142,7 @@
  10250. obj-$(CONFIG_SENSORS_W83L786NG) += w83l786ng.o
  10251. obj-$(CONFIG_SENSORS_WM831X) += wm831x-hwmon.o
  10252. obj-$(CONFIG_SENSORS_WM8350) += wm8350-hwmon.o
  10253. +obj-$(CONFIG_SENSORS_BCM2835) += bcm2835-hwmon.o
  10254. obj-$(CONFIG_PMBUS) += pmbus/
  10255. diff -Nur linux-3.13.3.orig/drivers/i2c/busses/i2c-bcm2708.c linux-3.13.3/drivers/i2c/busses/i2c-bcm2708.c
  10256. --- linux-3.13.3.orig/drivers/i2c/busses/i2c-bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  10257. +++ linux-3.13.3/drivers/i2c/busses/i2c-bcm2708.c 2014-02-17 22:41:01.000000000 +0100
  10258. @@ -0,0 +1,408 @@
  10259. +/*
  10260. + * Driver for Broadcom BCM2708 BSC Controllers
  10261. + *
  10262. + * Copyright (C) 2012 Chris Boot & Frank Buss
  10263. + *
  10264. + * This driver is inspired by:
  10265. + * i2c-ocores.c, by Peter Korsgaard <jacmet@sunsite.dk>
  10266. + *
  10267. + * This program is free software; you can redistribute it and/or modify
  10268. + * it under the terms of the GNU General Public License as published by
  10269. + * the Free Software Foundation; either version 2 of the License, or
  10270. + * (at your option) any later version.
  10271. + *
  10272. + * This program is distributed in the hope that it will be useful,
  10273. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10274. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10275. + * GNU General Public License for more details.
  10276. + *
  10277. + * You should have received a copy of the GNU General Public License
  10278. + * along with this program; if not, write to the Free Software
  10279. + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  10280. + */
  10281. +
  10282. +#include <linux/kernel.h>
  10283. +#include <linux/module.h>
  10284. +#include <linux/spinlock.h>
  10285. +#include <linux/clk.h>
  10286. +#include <linux/err.h>
  10287. +#include <linux/platform_device.h>
  10288. +#include <linux/io.h>
  10289. +#include <linux/slab.h>
  10290. +#include <linux/i2c.h>
  10291. +#include <linux/interrupt.h>
  10292. +#include <linux/sched.h>
  10293. +#include <linux/wait.h>
  10294. +
  10295. +/* BSC register offsets */
  10296. +#define BSC_C 0x00
  10297. +#define BSC_S 0x04
  10298. +#define BSC_DLEN 0x08
  10299. +#define BSC_A 0x0c
  10300. +#define BSC_FIFO 0x10
  10301. +#define BSC_DIV 0x14
  10302. +#define BSC_DEL 0x18
  10303. +#define BSC_CLKT 0x1c
  10304. +
  10305. +/* Bitfields in BSC_C */
  10306. +#define BSC_C_I2CEN 0x00008000
  10307. +#define BSC_C_INTR 0x00000400
  10308. +#define BSC_C_INTT 0x00000200
  10309. +#define BSC_C_INTD 0x00000100
  10310. +#define BSC_C_ST 0x00000080
  10311. +#define BSC_C_CLEAR_1 0x00000020
  10312. +#define BSC_C_CLEAR_2 0x00000010
  10313. +#define BSC_C_READ 0x00000001
  10314. +
  10315. +/* Bitfields in BSC_S */
  10316. +#define BSC_S_CLKT 0x00000200
  10317. +#define BSC_S_ERR 0x00000100
  10318. +#define BSC_S_RXF 0x00000080
  10319. +#define BSC_S_TXE 0x00000040
  10320. +#define BSC_S_RXD 0x00000020
  10321. +#define BSC_S_TXD 0x00000010
  10322. +#define BSC_S_RXR 0x00000008
  10323. +#define BSC_S_TXW 0x00000004
  10324. +#define BSC_S_DONE 0x00000002
  10325. +#define BSC_S_TA 0x00000001
  10326. +
  10327. +#define I2C_TIMEOUT_MS 150
  10328. +
  10329. +#define DRV_NAME "bcm2708_i2c"
  10330. +
  10331. +static unsigned int baudrate = CONFIG_I2C_BCM2708_BAUDRATE;
  10332. +module_param(baudrate, uint, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
  10333. +MODULE_PARM_DESC(baudrate, "The I2C baudrate");
  10334. +
  10335. +
  10336. +struct bcm2708_i2c {
  10337. + struct i2c_adapter adapter;
  10338. +
  10339. + spinlock_t lock;
  10340. + void __iomem *base;
  10341. + int irq;
  10342. + struct clk *clk;
  10343. +
  10344. + struct completion done;
  10345. +
  10346. + struct i2c_msg *msg;
  10347. + int pos;
  10348. + int nmsgs;
  10349. + bool error;
  10350. +};
  10351. +
  10352. +/*
  10353. + * This function sets the ALT mode on the I2C pins so that we can use them with
  10354. + * the BSC hardware.
  10355. + *
  10356. + * FIXME: This is a hack. Use pinmux / pinctrl.
  10357. + */
  10358. +static void bcm2708_i2c_init_pinmode(int id)
  10359. +{
  10360. +#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
  10361. +#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
  10362. +
  10363. + int pin;
  10364. + u32 *gpio = ioremap(0x20200000, SZ_16K);
  10365. +
  10366. + BUG_ON(id != 0 && id != 1);
  10367. + /* BSC0 is on GPIO 0 & 1, BSC1 is on GPIO 2 & 3 */
  10368. + for (pin = id*2+0; pin <= id*2+1; pin++) {
  10369. +printk("bcm2708_i2c_init_pinmode(%d,%d)\n", id, pin);
  10370. + INP_GPIO(pin); /* set mode to GPIO input first */
  10371. + SET_GPIO_ALT(pin, 0); /* set mode to ALT 0 */
  10372. + }
  10373. +
  10374. + iounmap(gpio);
  10375. +
  10376. +#undef INP_GPIO
  10377. +#undef SET_GPIO_ALT
  10378. +}
  10379. +
  10380. +static inline u32 bcm2708_rd(struct bcm2708_i2c *bi, unsigned reg)
  10381. +{
  10382. + return readl(bi->base + reg);
  10383. +}
  10384. +
  10385. +static inline void bcm2708_wr(struct bcm2708_i2c *bi, unsigned reg, u32 val)
  10386. +{
  10387. + writel(val, bi->base + reg);
  10388. +}
  10389. +
  10390. +static inline void bcm2708_bsc_reset(struct bcm2708_i2c *bi)
  10391. +{
  10392. + bcm2708_wr(bi, BSC_C, 0);
  10393. + bcm2708_wr(bi, BSC_S, BSC_S_CLKT | BSC_S_ERR | BSC_S_DONE);
  10394. +}
  10395. +
  10396. +static inline void bcm2708_bsc_fifo_drain(struct bcm2708_i2c *bi)
  10397. +{
  10398. + while ((bcm2708_rd(bi, BSC_S) & BSC_S_RXD) && (bi->pos < bi->msg->len))
  10399. + bi->msg->buf[bi->pos++] = bcm2708_rd(bi, BSC_FIFO);
  10400. +}
  10401. +
  10402. +static inline void bcm2708_bsc_fifo_fill(struct bcm2708_i2c *bi)
  10403. +{
  10404. + while ((bcm2708_rd(bi, BSC_S) & BSC_S_TXD) && (bi->pos < bi->msg->len))
  10405. + bcm2708_wr(bi, BSC_FIFO, bi->msg->buf[bi->pos++]);
  10406. +}
  10407. +
  10408. +static inline void bcm2708_bsc_setup(struct bcm2708_i2c *bi)
  10409. +{
  10410. + unsigned long bus_hz;
  10411. + u32 cdiv;
  10412. + u32 c = BSC_C_I2CEN | BSC_C_INTD | BSC_C_ST | BSC_C_CLEAR_1;
  10413. +
  10414. + bus_hz = clk_get_rate(bi->clk);
  10415. + cdiv = bus_hz / baudrate;
  10416. +
  10417. + if (bi->msg->flags & I2C_M_RD)
  10418. + c |= BSC_C_INTR | BSC_C_READ;
  10419. + else
  10420. + c |= BSC_C_INTT;
  10421. +
  10422. + bcm2708_wr(bi, BSC_DIV, cdiv);
  10423. + bcm2708_wr(bi, BSC_A, bi->msg->addr);
  10424. + bcm2708_wr(bi, BSC_DLEN, bi->msg->len);
  10425. + bcm2708_wr(bi, BSC_C, c);
  10426. +}
  10427. +
  10428. +static irqreturn_t bcm2708_i2c_interrupt(int irq, void *dev_id)
  10429. +{
  10430. + struct bcm2708_i2c *bi = dev_id;
  10431. + bool handled = true;
  10432. + u32 s;
  10433. +
  10434. + spin_lock(&bi->lock);
  10435. +
  10436. + /* we may see camera interrupts on the "other" I2C channel
  10437. + Just return if we've not sent anything */
  10438. + if (!bi->nmsgs || !bi->msg )
  10439. + goto early_exit;
  10440. +
  10441. + s = bcm2708_rd(bi, BSC_S);
  10442. +
  10443. + if (s & (BSC_S_CLKT | BSC_S_ERR)) {
  10444. + bcm2708_bsc_reset(bi);
  10445. + bi->error = true;
  10446. +
  10447. + /* wake up our bh */
  10448. + complete(&bi->done);
  10449. + } else if (s & BSC_S_DONE) {
  10450. + bi->nmsgs--;
  10451. +
  10452. + if (bi->msg->flags & I2C_M_RD)
  10453. + bcm2708_bsc_fifo_drain(bi);
  10454. +
  10455. + bcm2708_bsc_reset(bi);
  10456. +
  10457. + if (bi->nmsgs) {
  10458. + /* advance to next message */
  10459. + bi->msg++;
  10460. + bi->pos = 0;
  10461. + bcm2708_bsc_setup(bi);
  10462. + } else {
  10463. + /* wake up our bh */
  10464. + complete(&bi->done);
  10465. + }
  10466. + } else if (s & BSC_S_TXW) {
  10467. + bcm2708_bsc_fifo_fill(bi);
  10468. + } else if (s & BSC_S_RXR) {
  10469. + bcm2708_bsc_fifo_drain(bi);
  10470. + } else {
  10471. + handled = false;
  10472. + }
  10473. +
  10474. +early_exit:
  10475. + spin_unlock(&bi->lock);
  10476. +
  10477. + return handled ? IRQ_HANDLED : IRQ_NONE;
  10478. +}
  10479. +
  10480. +static int bcm2708_i2c_master_xfer(struct i2c_adapter *adap,
  10481. + struct i2c_msg *msgs, int num)
  10482. +{
  10483. + struct bcm2708_i2c *bi = adap->algo_data;
  10484. + unsigned long flags;
  10485. + int ret;
  10486. +
  10487. + spin_lock_irqsave(&bi->lock, flags);
  10488. +
  10489. + reinit_completion(&bi->done);
  10490. + bi->msg = msgs;
  10491. + bi->pos = 0;
  10492. + bi->nmsgs = num;
  10493. + bi->error = false;
  10494. +
  10495. + spin_unlock_irqrestore(&bi->lock, flags);
  10496. +
  10497. + bcm2708_bsc_setup(bi);
  10498. +
  10499. + ret = wait_for_completion_timeout(&bi->done,
  10500. + msecs_to_jiffies(I2C_TIMEOUT_MS));
  10501. + if (ret == 0) {
  10502. + dev_err(&adap->dev, "transfer timed out\n");
  10503. + spin_lock_irqsave(&bi->lock, flags);
  10504. + bcm2708_bsc_reset(bi);
  10505. + spin_unlock_irqrestore(&bi->lock, flags);
  10506. + return -ETIMEDOUT;
  10507. + }
  10508. +
  10509. + return bi->error ? -EIO : num;
  10510. +}
  10511. +
  10512. +static u32 bcm2708_i2c_functionality(struct i2c_adapter *adap)
  10513. +{
  10514. + return I2C_FUNC_I2C | /*I2C_FUNC_10BIT_ADDR |*/ I2C_FUNC_SMBUS_EMUL;
  10515. +}
  10516. +
  10517. +static struct i2c_algorithm bcm2708_i2c_algorithm = {
  10518. + .master_xfer = bcm2708_i2c_master_xfer,
  10519. + .functionality = bcm2708_i2c_functionality,
  10520. +};
  10521. +
  10522. +static int bcm2708_i2c_probe(struct platform_device *pdev)
  10523. +{
  10524. + struct resource *regs;
  10525. + int irq, err = -ENOMEM;
  10526. + struct clk *clk;
  10527. + struct bcm2708_i2c *bi;
  10528. + struct i2c_adapter *adap;
  10529. +
  10530. + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  10531. + if (!regs) {
  10532. + dev_err(&pdev->dev, "could not get IO memory\n");
  10533. + return -ENXIO;
  10534. + }
  10535. +
  10536. + irq = platform_get_irq(pdev, 0);
  10537. + if (irq < 0) {
  10538. + dev_err(&pdev->dev, "could not get IRQ\n");
  10539. + return irq;
  10540. + }
  10541. +
  10542. + clk = clk_get(&pdev->dev, NULL);
  10543. + if (IS_ERR(clk)) {
  10544. + dev_err(&pdev->dev, "could not find clk: %ld\n", PTR_ERR(clk));
  10545. + return PTR_ERR(clk);
  10546. + }
  10547. +
  10548. + bcm2708_i2c_init_pinmode(pdev->id);
  10549. +
  10550. + bi = kzalloc(sizeof(*bi), GFP_KERNEL);
  10551. + if (!bi)
  10552. + goto out_clk_put;
  10553. +
  10554. + platform_set_drvdata(pdev, bi);
  10555. +
  10556. + adap = &bi->adapter;
  10557. + adap->class = I2C_CLASS_HWMON | I2C_CLASS_DDC;
  10558. + adap->algo = &bcm2708_i2c_algorithm;
  10559. + adap->algo_data = bi;
  10560. + adap->dev.parent = &pdev->dev;
  10561. + adap->nr = pdev->id;
  10562. + strlcpy(adap->name, dev_name(&pdev->dev), sizeof(adap->name));
  10563. +
  10564. + switch (pdev->id) {
  10565. + case 0:
  10566. + adap->class = I2C_CLASS_HWMON;
  10567. + break;
  10568. + case 1:
  10569. + adap->class = I2C_CLASS_DDC;
  10570. + break;
  10571. + default:
  10572. + dev_err(&pdev->dev, "can only bind to BSC 0 or 1\n");
  10573. + err = -ENXIO;
  10574. + goto out_free_bi;
  10575. + }
  10576. +
  10577. + spin_lock_init(&bi->lock);
  10578. + init_completion(&bi->done);
  10579. +
  10580. + bi->base = ioremap(regs->start, resource_size(regs));
  10581. + if (!bi->base) {
  10582. + dev_err(&pdev->dev, "could not remap memory\n");
  10583. + goto out_free_bi;
  10584. + }
  10585. +
  10586. + bi->irq = irq;
  10587. + bi->clk = clk;
  10588. +
  10589. + err = request_irq(irq, bcm2708_i2c_interrupt, IRQF_SHARED,
  10590. + dev_name(&pdev->dev), bi);
  10591. + if (err) {
  10592. + dev_err(&pdev->dev, "could not request IRQ: %d\n", err);
  10593. + goto out_iounmap;
  10594. + }
  10595. +
  10596. + bcm2708_bsc_reset(bi);
  10597. +
  10598. + err = i2c_add_numbered_adapter(adap);
  10599. + if (err < 0) {
  10600. + dev_err(&pdev->dev, "could not add I2C adapter: %d\n", err);
  10601. + goto out_free_irq;
  10602. + }
  10603. +
  10604. + dev_info(&pdev->dev, "BSC%d Controller at 0x%08lx (irq %d) (baudrate %dk)\n",
  10605. + pdev->id, (unsigned long)regs->start, irq, baudrate/1000);
  10606. +
  10607. + return 0;
  10608. +
  10609. +out_free_irq:
  10610. + free_irq(bi->irq, bi);
  10611. +out_iounmap:
  10612. + iounmap(bi->base);
  10613. +out_free_bi:
  10614. + kfree(bi);
  10615. +out_clk_put:
  10616. + clk_put(clk);
  10617. + return err;
  10618. +}
  10619. +
  10620. +static int bcm2708_i2c_remove(struct platform_device *pdev)
  10621. +{
  10622. + struct bcm2708_i2c *bi = platform_get_drvdata(pdev);
  10623. +
  10624. + platform_set_drvdata(pdev, NULL);
  10625. +
  10626. + i2c_del_adapter(&bi->adapter);
  10627. + free_irq(bi->irq, bi);
  10628. + iounmap(bi->base);
  10629. + clk_disable(bi->clk);
  10630. + clk_put(bi->clk);
  10631. + kfree(bi);
  10632. +
  10633. + return 0;
  10634. +}
  10635. +
  10636. +static struct platform_driver bcm2708_i2c_driver = {
  10637. + .driver = {
  10638. + .name = DRV_NAME,
  10639. + .owner = THIS_MODULE,
  10640. + },
  10641. + .probe = bcm2708_i2c_probe,
  10642. + .remove = bcm2708_i2c_remove,
  10643. +};
  10644. +
  10645. +// module_platform_driver(bcm2708_i2c_driver);
  10646. +
  10647. +
  10648. +static int __init bcm2708_i2c_init(void)
  10649. +{
  10650. + return platform_driver_register(&bcm2708_i2c_driver);
  10651. +}
  10652. +
  10653. +static void __exit bcm2708_i2c_exit(void)
  10654. +{
  10655. + platform_driver_unregister(&bcm2708_i2c_driver);
  10656. +}
  10657. +
  10658. +module_init(bcm2708_i2c_init);
  10659. +module_exit(bcm2708_i2c_exit);
  10660. +
  10661. +
  10662. +
  10663. +MODULE_DESCRIPTION("BSC controller driver for Broadcom BCM2708");
  10664. +MODULE_AUTHOR("Chris Boot <bootc@bootc.net>");
  10665. +MODULE_LICENSE("GPL v2");
  10666. +MODULE_ALIAS("platform:" DRV_NAME);
  10667. diff -Nur linux-3.13.3.orig/drivers/i2c/busses/Kconfig linux-3.13.3/drivers/i2c/busses/Kconfig
  10668. --- linux-3.13.3.orig/drivers/i2c/busses/Kconfig 2014-02-13 23:00:14.000000000 +0100
  10669. +++ linux-3.13.3/drivers/i2c/busses/Kconfig 2014-02-17 22:41:01.000000000 +0100
  10670. @@ -347,6 +347,25 @@
  10671. This support is also available as a module. If so, the module
  10672. will be called i2c-bcm2835.
  10673. +config I2C_BCM2708
  10674. + tristate "BCM2708 BSC"
  10675. + depends on MACH_BCM2708
  10676. + help
  10677. + Enabling this option will add BSC (Broadcom Serial Controller)
  10678. + support for the BCM2708. BSC is a Broadcom proprietary bus compatible
  10679. + with I2C/TWI/SMBus.
  10680. +
  10681. +config I2C_BCM2708_BAUDRATE
  10682. + prompt "BCM2708 I2C baudrate"
  10683. + depends on I2C_BCM2708
  10684. + int
  10685. + default 100000
  10686. + help
  10687. + Set the I2C baudrate. This will alter the default value. A
  10688. + different baudrate can be set by using a module parameter as well. If
  10689. + no parameter is provided when loading, this is the value that will be
  10690. + used.
  10691. +
  10692. config I2C_BCM_KONA
  10693. tristate "BCM Kona I2C adapter"
  10694. depends on ARCH_BCM_MOBILE
  10695. diff -Nur linux-3.13.3.orig/drivers/i2c/busses/Makefile linux-3.13.3/drivers/i2c/busses/Makefile
  10696. --- linux-3.13.3.orig/drivers/i2c/busses/Makefile 2014-02-13 23:00:14.000000000 +0100
  10697. +++ linux-3.13.3/drivers/i2c/busses/Makefile 2014-02-17 22:41:01.000000000 +0100
  10698. @@ -32,6 +32,7 @@
  10699. obj-$(CONFIG_I2C_AT91) += i2c-at91.o
  10700. obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o
  10701. obj-$(CONFIG_I2C_BCM2835) += i2c-bcm2835.o
  10702. +obj-$(CONFIG_I2C_BCM2708) += i2c-bcm2708.o
  10703. obj-$(CONFIG_I2C_BLACKFIN_TWI) += i2c-bfin-twi.o
  10704. obj-$(CONFIG_I2C_CBUS_GPIO) += i2c-cbus-gpio.o
  10705. obj-$(CONFIG_I2C_CPM) += i2c-cpm.o
  10706. diff -Nur linux-3.13.3.orig/drivers/media/dvb-core/dvb-usb-ids.h linux-3.13.3/drivers/media/dvb-core/dvb-usb-ids.h
  10707. --- linux-3.13.3.orig/drivers/media/dvb-core/dvb-usb-ids.h 2014-02-13 23:00:14.000000000 +0100
  10708. +++ linux-3.13.3/drivers/media/dvb-core/dvb-usb-ids.h 2014-02-17 22:41:01.000000000 +0100
  10709. @@ -366,6 +366,7 @@
  10710. #define USB_PID_TERRATEC_DVBS2CI_V2 0x10ac
  10711. #define USB_PID_TECHNISAT_USB2_HDCI_V1 0x0001
  10712. #define USB_PID_TECHNISAT_USB2_HDCI_V2 0x0002
  10713. +#define USB_PID_TECHNISAT_USB2_CABLESTAR_HDCI 0x0003
  10714. #define USB_PID_TECHNISAT_AIRSTAR_TELESTICK_2 0x0004
  10715. #define USB_PID_TECHNISAT_USB2_DVB_S2 0x0500
  10716. #define USB_PID_CPYTO_REDI_PC50A 0xa803
  10717. diff -Nur linux-3.13.3.orig/drivers/media/platform/bcm2835/bcm2835-camera.c linux-3.13.3/drivers/media/platform/bcm2835/bcm2835-camera.c
  10718. --- linux-3.13.3.orig/drivers/media/platform/bcm2835/bcm2835-camera.c 1970-01-01 01:00:00.000000000 +0100
  10719. +++ linux-3.13.3/drivers/media/platform/bcm2835/bcm2835-camera.c 2014-02-17 22:41:01.000000000 +0100
  10720. @@ -0,0 +1,1622 @@
  10721. +/*
  10722. + * Broadcom BM2835 V4L2 driver
  10723. + *
  10724. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  10725. + *
  10726. + * This file is subject to the terms and conditions of the GNU General Public
  10727. + * License. See the file COPYING in the main directory of this archive
  10728. + * for more details.
  10729. + *
  10730. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  10731. + * Dave Stevenson <dsteve@broadcom.com>
  10732. + * Simon Mellor <simellor@broadcom.com>
  10733. + * Luke Diamand <luked@broadcom.com>
  10734. + */
  10735. +
  10736. +#include <linux/errno.h>
  10737. +#include <linux/kernel.h>
  10738. +#include <linux/module.h>
  10739. +#include <linux/slab.h>
  10740. +#include <media/videobuf2-vmalloc.h>
  10741. +#include <media/videobuf2-dma-contig.h>
  10742. +#include <media/v4l2-device.h>
  10743. +#include <media/v4l2-ioctl.h>
  10744. +#include <media/v4l2-ctrls.h>
  10745. +#include <media/v4l2-fh.h>
  10746. +#include <media/v4l2-event.h>
  10747. +#include <media/v4l2-common.h>
  10748. +#include <linux/delay.h>
  10749. +
  10750. +#include "mmal-common.h"
  10751. +#include "mmal-encodings.h"
  10752. +#include "mmal-vchiq.h"
  10753. +#include "mmal-msg.h"
  10754. +#include "mmal-parameters.h"
  10755. +#include "bcm2835-camera.h"
  10756. +
  10757. +#define BM2835_MMAL_VERSION "0.0.2"
  10758. +#define BM2835_MMAL_MODULE_NAME "bcm2835-v4l2"
  10759. +
  10760. +#define MAX_WIDTH 2592
  10761. +#define MAX_HEIGHT 1944
  10762. +#define MIN_BUFFER_SIZE (80*1024)
  10763. +
  10764. +#define MAX_VIDEO_MODE_WIDTH 1280
  10765. +#define MAX_VIDEO_MODE_HEIGHT 720
  10766. +
  10767. +MODULE_DESCRIPTION("Broadcom 2835 MMAL video capture");
  10768. +MODULE_AUTHOR("Vincent Sanders");
  10769. +MODULE_LICENSE("GPL");
  10770. +MODULE_VERSION(BM2835_MMAL_VERSION);
  10771. +
  10772. +int bcm2835_v4l2_debug;
  10773. +module_param_named(debug, bcm2835_v4l2_debug, int, 0644);
  10774. +MODULE_PARM_DESC(bcm2835_v4l2_debug, "Debug level 0-2");
  10775. +
  10776. +static struct bm2835_mmal_dev *gdev; /* global device data */
  10777. +
  10778. +#define FPS_MIN 1
  10779. +#define FPS_MAX 30
  10780. +
  10781. +/* timeperframe: min/max and default */
  10782. +static const struct v4l2_fract
  10783. + tpf_min = {.numerator = 1, .denominator = FPS_MAX},
  10784. + tpf_max = {.numerator = 1, .denominator = FPS_MIN},
  10785. + tpf_default = {.numerator = 1000, .denominator = 30000};
  10786. +
  10787. +/* video formats */
  10788. +static struct mmal_fmt formats[] = {
  10789. + {
  10790. + .name = "4:2:0, packed YUV",
  10791. + .fourcc = V4L2_PIX_FMT_YUV420,
  10792. + .mmal = MMAL_ENCODING_I420,
  10793. + .depth = 12,
  10794. + .mmal_component = MMAL_COMPONENT_CAMERA,
  10795. + },
  10796. + {
  10797. + .name = "4:2:2, packed, YUYV",
  10798. + .fourcc = V4L2_PIX_FMT_YUYV,
  10799. + .mmal = MMAL_ENCODING_YUYV,
  10800. + .depth = 16,
  10801. + .mmal_component = MMAL_COMPONENT_CAMERA,
  10802. + },
  10803. + {
  10804. + .name = "RGB24 (BE)",
  10805. + .fourcc = V4L2_PIX_FMT_BGR24,
  10806. + .mmal = MMAL_ENCODING_BGR24,
  10807. + .depth = 24,
  10808. + .mmal_component = MMAL_COMPONENT_CAMERA,
  10809. + },
  10810. + {
  10811. + .name = "JPEG",
  10812. + .fourcc = V4L2_PIX_FMT_JPEG,
  10813. + .mmal = MMAL_ENCODING_JPEG,
  10814. + .depth = 8,
  10815. + .mmal_component = MMAL_COMPONENT_IMAGE_ENCODE,
  10816. + },
  10817. + {
  10818. + .name = "H264",
  10819. + .fourcc = V4L2_PIX_FMT_H264,
  10820. + .mmal = MMAL_ENCODING_H264,
  10821. + .depth = 8,
  10822. + .mmal_component = MMAL_COMPONENT_VIDEO_ENCODE,
  10823. + }
  10824. +};
  10825. +
  10826. +static struct mmal_fmt *get_format(struct v4l2_format *f)
  10827. +{
  10828. + struct mmal_fmt *fmt;
  10829. + unsigned int k;
  10830. +
  10831. + for (k = 0; k < ARRAY_SIZE(formats); k++) {
  10832. + fmt = &formats[k];
  10833. + if (fmt->fourcc == f->fmt.pix.pixelformat)
  10834. + break;
  10835. + }
  10836. +
  10837. + if (k == ARRAY_SIZE(formats))
  10838. + return NULL;
  10839. +
  10840. + return &formats[k];
  10841. +}
  10842. +
  10843. +/* ------------------------------------------------------------------
  10844. + Videobuf queue operations
  10845. + ------------------------------------------------------------------*/
  10846. +
  10847. +static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
  10848. + unsigned int *nbuffers, unsigned int *nplanes,
  10849. + unsigned int sizes[], void *alloc_ctxs[])
  10850. +{
  10851. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  10852. + unsigned long size;
  10853. +
  10854. + /* refuse queue setup if port is not configured */
  10855. + if (dev->capture.port == NULL) {
  10856. + v4l2_err(&dev->v4l2_dev,
  10857. + "%s: capture port not configured\n", __func__);
  10858. + return -EINVAL;
  10859. + }
  10860. +
  10861. + size = dev->capture.port->current_buffer.size;
  10862. + if (size == 0) {
  10863. + v4l2_err(&dev->v4l2_dev,
  10864. + "%s: capture port buffer size is zero\n", __func__);
  10865. + return -EINVAL;
  10866. + }
  10867. +
  10868. + if (*nbuffers < (dev->capture.port->current_buffer.num + 2))
  10869. + *nbuffers = (dev->capture.port->current_buffer.num + 2);
  10870. +
  10871. + *nplanes = 1;
  10872. +
  10873. + sizes[0] = size;
  10874. +
  10875. + /*
  10876. + * videobuf2-vmalloc allocator is context-less so no need to set
  10877. + * alloc_ctxs array.
  10878. + */
  10879. +
  10880. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  10881. + __func__, dev);
  10882. +
  10883. + return 0;
  10884. +}
  10885. +
  10886. +static int buffer_prepare(struct vb2_buffer *vb)
  10887. +{
  10888. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
  10889. + unsigned long size;
  10890. +
  10891. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  10892. + __func__, dev);
  10893. +
  10894. + BUG_ON(dev->capture.port == NULL);
  10895. + BUG_ON(dev->capture.fmt == NULL);
  10896. +
  10897. + size = dev->capture.stride * dev->capture.height;
  10898. + if (vb2_plane_size(vb, 0) < size) {
  10899. + v4l2_err(&dev->v4l2_dev,
  10900. + "%s data will not fit into plane (%lu < %lu)\n",
  10901. + __func__, vb2_plane_size(vb, 0), size);
  10902. + return -EINVAL;
  10903. + }
  10904. +
  10905. + return 0;
  10906. +}
  10907. +
  10908. +static inline bool is_capturing(struct bm2835_mmal_dev *dev)
  10909. +{
  10910. + return dev->capture.camera_port ==
  10911. + &dev->
  10912. + component[MMAL_COMPONENT_CAMERA]->output[MMAL_CAMERA_PORT_CAPTURE];
  10913. +}
  10914. +
  10915. +static void buffer_cb(struct vchiq_mmal_instance *instance,
  10916. + struct vchiq_mmal_port *port,
  10917. + int status,
  10918. + struct mmal_buffer *buf,
  10919. + unsigned long length, u32 mmal_flags, s64 dts, s64 pts)
  10920. +{
  10921. + struct bm2835_mmal_dev *dev = port->cb_ctx;
  10922. +
  10923. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  10924. + "%s: status:%d, buf:%p, length:%lu, flags %u, pts %lld\n",
  10925. + __func__, status, buf, length, mmal_flags, pts);
  10926. +
  10927. + if (status != 0) {
  10928. + /* error in transfer */
  10929. + if (buf != NULL) {
  10930. + /* there was a buffer with the error so return it */
  10931. + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
  10932. + }
  10933. + return;
  10934. + } else if (length == 0) {
  10935. + /* stream ended */
  10936. + if (buf != NULL) {
  10937. + /* this should only ever happen if the port is
  10938. + * disabled and there are buffers still queued
  10939. + */
  10940. + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
  10941. + pr_debug("Empty buffer");
  10942. + } else if (dev->capture.frame_count) {
  10943. + /* grab another frame */
  10944. + if (is_capturing(dev)) {
  10945. + pr_debug("Grab another frame");
  10946. + vchiq_mmal_port_parameter_set(
  10947. + instance,
  10948. + dev->capture.
  10949. + camera_port,
  10950. + MMAL_PARAMETER_CAPTURE,
  10951. + &dev->capture.
  10952. + frame_count,
  10953. + sizeof(dev->capture.frame_count));
  10954. + }
  10955. + } else {
  10956. + /* signal frame completion */
  10957. + complete(&dev->capture.frame_cmplt);
  10958. + }
  10959. + } else {
  10960. + if (dev->capture.frame_count) {
  10961. + if (dev->capture.vc_start_timestamp != -1 &&
  10962. + pts != 0) {
  10963. + s64 runtime_us = pts -
  10964. + dev->capture.vc_start_timestamp;
  10965. + u32 div = 0;
  10966. + u32 rem = 0;
  10967. +
  10968. + div =
  10969. + div_u64_rem(runtime_us, USEC_PER_SEC, &rem);
  10970. + buf->vb.v4l2_buf.timestamp.tv_sec =
  10971. + dev->capture.kernel_start_ts.tv_sec - 1 +
  10972. + div;
  10973. + buf->vb.v4l2_buf.timestamp.tv_usec =
  10974. + dev->capture.kernel_start_ts.tv_usec + rem;
  10975. +
  10976. + if (buf->vb.v4l2_buf.timestamp.tv_usec >=
  10977. + USEC_PER_SEC) {
  10978. + buf->vb.v4l2_buf.timestamp.tv_sec++;
  10979. + buf->vb.v4l2_buf.timestamp.tv_usec -=
  10980. + USEC_PER_SEC;
  10981. + }
  10982. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  10983. + "Convert start time %d.%06d and %llu "
  10984. + "with offset %llu to %d.%06d\n",
  10985. + (int)dev->capture.kernel_start_ts.
  10986. + tv_sec,
  10987. + (int)dev->capture.kernel_start_ts.
  10988. + tv_usec,
  10989. + dev->capture.vc_start_timestamp, pts,
  10990. + (int)buf->vb.v4l2_buf.timestamp.tv_sec,
  10991. + (int)buf->vb.v4l2_buf.timestamp.
  10992. + tv_usec);
  10993. + } else {
  10994. + v4l2_get_timestamp(&buf->vb.v4l2_buf.timestamp);
  10995. + }
  10996. +
  10997. + vb2_set_plane_payload(&buf->vb, 0, length);
  10998. + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_DONE);
  10999. +
  11000. + if (mmal_flags & MMAL_BUFFER_HEADER_FLAG_EOS &&
  11001. + is_capturing(dev)) {
  11002. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11003. + "Grab another frame as buffer has EOS");
  11004. + vchiq_mmal_port_parameter_set(
  11005. + instance,
  11006. + dev->capture.
  11007. + camera_port,
  11008. + MMAL_PARAMETER_CAPTURE,
  11009. + &dev->capture.
  11010. + frame_count,
  11011. + sizeof(dev->capture.frame_count));
  11012. + }
  11013. + } else {
  11014. + /* signal frame completion */
  11015. + complete(&dev->capture.frame_cmplt);
  11016. + }
  11017. + }
  11018. +}
  11019. +
  11020. +static int enable_camera(struct bm2835_mmal_dev *dev)
  11021. +{
  11022. + int ret;
  11023. + if (!dev->camera_use_count) {
  11024. + ret = vchiq_mmal_component_enable(
  11025. + dev->instance,
  11026. + dev->component[MMAL_COMPONENT_CAMERA]);
  11027. + if (ret < 0) {
  11028. + v4l2_err(&dev->v4l2_dev,
  11029. + "Failed enabling camera, ret %d\n", ret);
  11030. + return -EINVAL;
  11031. + }
  11032. + }
  11033. + dev->camera_use_count++;
  11034. + v4l2_dbg(1, bcm2835_v4l2_debug,
  11035. + &dev->v4l2_dev, "enabled camera (refcount %d)\n",
  11036. + dev->camera_use_count);
  11037. + return 0;
  11038. +}
  11039. +
  11040. +static int disable_camera(struct bm2835_mmal_dev *dev)
  11041. +{
  11042. + int ret;
  11043. + if (!dev->camera_use_count) {
  11044. + v4l2_err(&dev->v4l2_dev,
  11045. + "Disabled the camera when already disabled\n");
  11046. + return -EINVAL;
  11047. + }
  11048. + dev->camera_use_count--;
  11049. + if (!dev->camera_use_count) {
  11050. + unsigned int i = 0xFFFFFFFF;
  11051. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11052. + "Disabling camera\n");
  11053. + ret =
  11054. + vchiq_mmal_component_disable(
  11055. + dev->instance,
  11056. + dev->component[MMAL_COMPONENT_CAMERA]);
  11057. + if (ret < 0) {
  11058. + v4l2_err(&dev->v4l2_dev,
  11059. + "Failed disabling camera, ret %d\n", ret);
  11060. + return -EINVAL;
  11061. + }
  11062. + vchiq_mmal_port_parameter_set(
  11063. + dev->instance,
  11064. + &dev->component[MMAL_COMPONENT_CAMERA]->control,
  11065. + MMAL_PARAMETER_CAMERA_NUM, &i,
  11066. + sizeof(i));
  11067. + }
  11068. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11069. + "Camera refcount now %d\n", dev->camera_use_count);
  11070. + return 0;
  11071. +}
  11072. +
  11073. +static void buffer_queue(struct vb2_buffer *vb)
  11074. +{
  11075. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
  11076. + struct mmal_buffer *buf = container_of(vb, struct mmal_buffer, vb);
  11077. + int ret;
  11078. +
  11079. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11080. + "%s: dev:%p buf:%p\n", __func__, dev, buf);
  11081. +
  11082. + buf->buffer = vb2_plane_vaddr(&buf->vb, 0);
  11083. + buf->buffer_size = vb2_plane_size(&buf->vb, 0);
  11084. +
  11085. + ret = vchiq_mmal_submit_buffer(dev->instance, dev->capture.port, buf);
  11086. + if (ret < 0)
  11087. + v4l2_err(&dev->v4l2_dev, "%s: error submitting buffer\n",
  11088. + __func__);
  11089. +}
  11090. +
  11091. +static int start_streaming(struct vb2_queue *vq, unsigned int count)
  11092. +{
  11093. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  11094. + int ret;
  11095. + int parameter_size;
  11096. +
  11097. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  11098. + __func__, dev);
  11099. +
  11100. + /* ensure a format has actually been set */
  11101. + if (dev->capture.port == NULL)
  11102. + return -EINVAL;
  11103. +
  11104. + if (enable_camera(dev) < 0) {
  11105. + v4l2_err(&dev->v4l2_dev, "Failed to enable camera\n");
  11106. + return -EINVAL;
  11107. + }
  11108. +
  11109. + /*init_completion(&dev->capture.frame_cmplt); */
  11110. +
  11111. + /* enable frame capture */
  11112. + dev->capture.frame_count = 1;
  11113. +
  11114. + /* if the preview is not already running, wait for a few frames for AGC
  11115. + * to settle down.
  11116. + */
  11117. + if (!dev->component[MMAL_COMPONENT_PREVIEW]->enabled)
  11118. + msleep(300);
  11119. +
  11120. + /* enable the connection from camera to encoder (if applicable) */
  11121. + if (dev->capture.camera_port != dev->capture.port
  11122. + && dev->capture.camera_port) {
  11123. + ret = vchiq_mmal_port_enable(dev->instance,
  11124. + dev->capture.camera_port, NULL);
  11125. + if (ret) {
  11126. + v4l2_err(&dev->v4l2_dev,
  11127. + "Failed to enable encode tunnel - error %d\n",
  11128. + ret);
  11129. + return -1;
  11130. + }
  11131. + }
  11132. +
  11133. + /* Get VC timestamp at this point in time */
  11134. + parameter_size = sizeof(dev->capture.vc_start_timestamp);
  11135. + if (vchiq_mmal_port_parameter_get(dev->instance,
  11136. + dev->capture.camera_port,
  11137. + MMAL_PARAMETER_SYSTEM_TIME,
  11138. + &dev->capture.vc_start_timestamp,
  11139. + &parameter_size)) {
  11140. + v4l2_err(&dev->v4l2_dev,
  11141. + "Failed to get VC start time - update your VC f/w\n");
  11142. +
  11143. + /* Flag to indicate just to rely on kernel timestamps */
  11144. + dev->capture.vc_start_timestamp = -1;
  11145. + } else
  11146. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11147. + "Start time %lld size %d\n",
  11148. + dev->capture.vc_start_timestamp, parameter_size);
  11149. +
  11150. + v4l2_get_timestamp(&dev->capture.kernel_start_ts);
  11151. +
  11152. + /* enable the camera port */
  11153. + dev->capture.port->cb_ctx = dev;
  11154. + ret =
  11155. + vchiq_mmal_port_enable(dev->instance, dev->capture.port, buffer_cb);
  11156. + if (ret) {
  11157. + v4l2_err(&dev->v4l2_dev,
  11158. + "Failed to enable capture port - error %d. "
  11159. + "Disabling camera port again\n", ret);
  11160. +
  11161. + vchiq_mmal_port_disable(dev->instance,
  11162. + dev->capture.camera_port);
  11163. + if (disable_camera(dev) < 0) {
  11164. + v4l2_err(&dev->v4l2_dev, "Failed to disable camera");
  11165. + return -EINVAL;
  11166. + }
  11167. + return -1;
  11168. + }
  11169. +
  11170. + /* capture the first frame */
  11171. + vchiq_mmal_port_parameter_set(dev->instance,
  11172. + dev->capture.camera_port,
  11173. + MMAL_PARAMETER_CAPTURE,
  11174. + &dev->capture.frame_count,
  11175. + sizeof(dev->capture.frame_count));
  11176. + return 0;
  11177. +}
  11178. +
  11179. +/* abort streaming and wait for last buffer */
  11180. +static int stop_streaming(struct vb2_queue *vq)
  11181. +{
  11182. + int ret;
  11183. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  11184. +
  11185. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  11186. + __func__, dev);
  11187. +
  11188. + init_completion(&dev->capture.frame_cmplt);
  11189. + dev->capture.frame_count = 0;
  11190. +
  11191. + /* ensure a format has actually been set */
  11192. + if (dev->capture.port == NULL)
  11193. + return -EINVAL;
  11194. +
  11195. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "stopping capturing\n");
  11196. +
  11197. + /* stop capturing frames */
  11198. + vchiq_mmal_port_parameter_set(dev->instance,
  11199. + dev->capture.camera_port,
  11200. + MMAL_PARAMETER_CAPTURE,
  11201. + &dev->capture.frame_count,
  11202. + sizeof(dev->capture.frame_count));
  11203. +
  11204. + /* wait for last frame to complete */
  11205. + ret = wait_for_completion_timeout(&dev->capture.frame_cmplt, HZ);
  11206. + if (ret <= 0)
  11207. + v4l2_err(&dev->v4l2_dev,
  11208. + "error %d waiting for frame completion\n", ret);
  11209. +
  11210. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11211. + "disabling connection\n");
  11212. +
  11213. + /* disable the connection from camera to encoder */
  11214. + ret = vchiq_mmal_port_disable(dev->instance, dev->capture.camera_port);
  11215. + if (!ret && dev->capture.camera_port != dev->capture.port) {
  11216. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11217. + "disabling port\n");
  11218. + ret = vchiq_mmal_port_disable(dev->instance, dev->capture.port);
  11219. + } else if (dev->capture.camera_port != dev->capture.port) {
  11220. + v4l2_err(&dev->v4l2_dev, "port_disable failed, error %d\n",
  11221. + ret);
  11222. + }
  11223. +
  11224. + if (disable_camera(dev) < 0) {
  11225. + v4l2_err(&dev->v4l2_dev, "Failed to disable camera");
  11226. + return -EINVAL;
  11227. + }
  11228. +
  11229. + return ret;
  11230. +}
  11231. +
  11232. +static void bm2835_mmal_lock(struct vb2_queue *vq)
  11233. +{
  11234. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  11235. + mutex_lock(&dev->mutex);
  11236. +}
  11237. +
  11238. +static void bm2835_mmal_unlock(struct vb2_queue *vq)
  11239. +{
  11240. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  11241. + mutex_unlock(&dev->mutex);
  11242. +}
  11243. +
  11244. +static struct vb2_ops bm2835_mmal_video_qops = {
  11245. + .queue_setup = queue_setup,
  11246. + .buf_prepare = buffer_prepare,
  11247. + .buf_queue = buffer_queue,
  11248. + .start_streaming = start_streaming,
  11249. + .stop_streaming = stop_streaming,
  11250. + .wait_prepare = bm2835_mmal_unlock,
  11251. + .wait_finish = bm2835_mmal_lock,
  11252. +};
  11253. +
  11254. +/* ------------------------------------------------------------------
  11255. + IOCTL operations
  11256. + ------------------------------------------------------------------*/
  11257. +
  11258. +/* overlay ioctl */
  11259. +static int vidioc_enum_fmt_vid_overlay(struct file *file, void *priv,
  11260. + struct v4l2_fmtdesc *f)
  11261. +{
  11262. + struct mmal_fmt *fmt;
  11263. +
  11264. + if (f->index >= ARRAY_SIZE(formats))
  11265. + return -EINVAL;
  11266. +
  11267. + fmt = &formats[f->index];
  11268. +
  11269. + strlcpy(f->description, fmt->name, sizeof(f->description));
  11270. + f->pixelformat = fmt->fourcc;
  11271. +
  11272. + return 0;
  11273. +}
  11274. +
  11275. +static int vidioc_g_fmt_vid_overlay(struct file *file, void *priv,
  11276. + struct v4l2_format *f)
  11277. +{
  11278. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  11279. +
  11280. + f->fmt.win = dev->overlay;
  11281. +
  11282. + return 0;
  11283. +}
  11284. +
  11285. +static int vidioc_try_fmt_vid_overlay(struct file *file, void *priv,
  11286. + struct v4l2_format *f)
  11287. +{
  11288. + /* Only support one format so get the current one. */
  11289. + vidioc_g_fmt_vid_overlay(file, priv, f);
  11290. +
  11291. + /* todo: allow the size and/or offset to be changed. */
  11292. + return 0;
  11293. +}
  11294. +
  11295. +static int vidioc_s_fmt_vid_overlay(struct file *file, void *priv,
  11296. + struct v4l2_format *f)
  11297. +{
  11298. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  11299. +
  11300. + vidioc_try_fmt_vid_overlay(file, priv, f);
  11301. +
  11302. + dev->overlay = f->fmt.win;
  11303. +
  11304. + /* todo: program the preview port parameters */
  11305. + return 0;
  11306. +}
  11307. +
  11308. +static int vidioc_overlay(struct file *file, void *f, unsigned int on)
  11309. +{
  11310. + int ret;
  11311. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  11312. + struct vchiq_mmal_port *src;
  11313. + struct vchiq_mmal_port *dst;
  11314. + struct mmal_parameter_displayregion prev_config = {
  11315. + .set = MMAL_DISPLAY_SET_LAYER | MMAL_DISPLAY_SET_ALPHA |
  11316. + MMAL_DISPLAY_SET_DEST_RECT | MMAL_DISPLAY_SET_FULLSCREEN,
  11317. + .layer = PREVIEW_LAYER,
  11318. + .alpha = 255,
  11319. + .fullscreen = 0,
  11320. + .dest_rect = {
  11321. + .x = dev->overlay.w.left,
  11322. + .y = dev->overlay.w.top,
  11323. + .width = dev->overlay.w.width,
  11324. + .height = dev->overlay.w.height,
  11325. + },
  11326. + };
  11327. +
  11328. + if ((on && dev->component[MMAL_COMPONENT_PREVIEW]->enabled) ||
  11329. + (!on && !dev->component[MMAL_COMPONENT_PREVIEW]->enabled))
  11330. + return 0; /* already in requested state */
  11331. +
  11332. + src =
  11333. + &dev->component[MMAL_COMPONENT_CAMERA]->
  11334. + output[MMAL_CAMERA_PORT_PREVIEW];
  11335. +
  11336. + if (!on) {
  11337. + /* disconnect preview ports and disable component */
  11338. + ret = vchiq_mmal_port_disable(dev->instance, src);
  11339. + if (!ret)
  11340. + ret =
  11341. + vchiq_mmal_port_connect_tunnel(dev->instance, src,
  11342. + NULL);
  11343. + if (ret >= 0)
  11344. + ret = vchiq_mmal_component_disable(
  11345. + dev->instance,
  11346. + dev->component[MMAL_COMPONENT_PREVIEW]);
  11347. +
  11348. + disable_camera(dev);
  11349. + return ret;
  11350. + }
  11351. +
  11352. + /* set preview port format and connect it to output */
  11353. + dst = &dev->component[MMAL_COMPONENT_PREVIEW]->input[0];
  11354. +
  11355. + ret = vchiq_mmal_port_set_format(dev->instance, src);
  11356. + if (ret < 0)
  11357. + goto error;
  11358. +
  11359. + ret = vchiq_mmal_port_parameter_set(dev->instance, dst,
  11360. + MMAL_PARAMETER_DISPLAYREGION,
  11361. + &prev_config, sizeof(prev_config));
  11362. + if (ret < 0)
  11363. + goto error;
  11364. +
  11365. + if (enable_camera(dev) < 0)
  11366. + goto error;
  11367. +
  11368. + ret = vchiq_mmal_component_enable(
  11369. + dev->instance,
  11370. + dev->component[MMAL_COMPONENT_PREVIEW]);
  11371. + if (ret < 0)
  11372. + goto error;
  11373. +
  11374. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "connecting %p to %p\n",
  11375. + src, dst);
  11376. + ret = vchiq_mmal_port_connect_tunnel(dev->instance, src, dst);
  11377. + if (!ret)
  11378. + ret = vchiq_mmal_port_enable(dev->instance, src, NULL);
  11379. +error:
  11380. + return ret;
  11381. +}
  11382. +
  11383. +static int vidioc_g_fbuf(struct file *file, void *fh,
  11384. + struct v4l2_framebuffer *a)
  11385. +{
  11386. + /* The video overlay must stay within the framebuffer and can't be
  11387. + positioned independently. */
  11388. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  11389. + struct vchiq_mmal_port *preview_port =
  11390. + &dev->component[MMAL_COMPONENT_CAMERA]->
  11391. + output[MMAL_CAMERA_PORT_PREVIEW];
  11392. + a->flags = V4L2_FBUF_FLAG_OVERLAY;
  11393. + a->fmt.width = preview_port->es.video.width;
  11394. + a->fmt.height = preview_port->es.video.height;
  11395. + a->fmt.pixelformat = V4L2_PIX_FMT_YUV420;
  11396. + a->fmt.bytesperline = (preview_port->es.video.width * 3)>>1;
  11397. + a->fmt.sizeimage = (preview_port->es.video.width *
  11398. + preview_port->es.video.height * 3)>>1;
  11399. + a->fmt.colorspace = V4L2_COLORSPACE_SMPTE170M;
  11400. +
  11401. + return 0;
  11402. +}
  11403. +
  11404. +/* input ioctls */
  11405. +static int vidioc_enum_input(struct file *file, void *priv,
  11406. + struct v4l2_input *inp)
  11407. +{
  11408. + /* only a single camera input */
  11409. + if (inp->index != 0)
  11410. + return -EINVAL;
  11411. +
  11412. + inp->type = V4L2_INPUT_TYPE_CAMERA;
  11413. + sprintf(inp->name, "Camera %u", inp->index);
  11414. + return 0;
  11415. +}
  11416. +
  11417. +static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
  11418. +{
  11419. + *i = 0;
  11420. + return 0;
  11421. +}
  11422. +
  11423. +static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
  11424. +{
  11425. + if (i != 0)
  11426. + return -EINVAL;
  11427. +
  11428. + return 0;
  11429. +}
  11430. +
  11431. +/* capture ioctls */
  11432. +static int vidioc_querycap(struct file *file, void *priv,
  11433. + struct v4l2_capability *cap)
  11434. +{
  11435. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  11436. + u32 major;
  11437. + u32 minor;
  11438. +
  11439. + vchiq_mmal_version(dev->instance, &major, &minor);
  11440. +
  11441. + strcpy(cap->driver, "bm2835 mmal");
  11442. + snprintf(cap->card, sizeof(cap->card), "mmal service %d.%d",
  11443. + major, minor);
  11444. +
  11445. + snprintf(cap->bus_info, sizeof(cap->bus_info),
  11446. + "platform:%s", dev->v4l2_dev.name);
  11447. + cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OVERLAY |
  11448. + V4L2_CAP_STREAMING | V4L2_CAP_READWRITE;
  11449. + cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
  11450. +
  11451. + return 0;
  11452. +}
  11453. +
  11454. +static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
  11455. + struct v4l2_fmtdesc *f)
  11456. +{
  11457. + struct mmal_fmt *fmt;
  11458. +
  11459. + if (f->index >= ARRAY_SIZE(formats))
  11460. + return -EINVAL;
  11461. +
  11462. + fmt = &formats[f->index];
  11463. +
  11464. + strlcpy(f->description, fmt->name, sizeof(f->description));
  11465. + f->pixelformat = fmt->fourcc;
  11466. + return 0;
  11467. +}
  11468. +
  11469. +static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
  11470. + struct v4l2_format *f)
  11471. +{
  11472. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  11473. +
  11474. + f->fmt.pix.width = dev->capture.width;
  11475. + f->fmt.pix.height = dev->capture.height;
  11476. + f->fmt.pix.field = V4L2_FIELD_NONE;
  11477. + f->fmt.pix.pixelformat = dev->capture.fmt->fourcc;
  11478. + f->fmt.pix.bytesperline =
  11479. + (f->fmt.pix.width * dev->capture.fmt->depth) >> 3;
  11480. + f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
  11481. + if (dev->capture.fmt->fourcc == V4L2_PIX_FMT_JPEG
  11482. + && f->fmt.pix.sizeimage < (100 << 10)) {
  11483. + /* Need a minimum size for JPEG to account for EXIF. */
  11484. + f->fmt.pix.sizeimage = (100 << 10);
  11485. + }
  11486. +
  11487. + if (dev->capture.fmt->fourcc == V4L2_PIX_FMT_YUYV ||
  11488. + dev->capture.fmt->fourcc == V4L2_PIX_FMT_UYVY)
  11489. + f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
  11490. + else
  11491. + f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
  11492. + f->fmt.pix.priv = 0;
  11493. +
  11494. + v4l2_dump_pix_format(1, bcm2835_v4l2_debug, &dev->v4l2_dev, &f->fmt.pix,
  11495. + __func__);
  11496. + return 0;
  11497. +}
  11498. +
  11499. +static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
  11500. + struct v4l2_format *f)
  11501. +{
  11502. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  11503. + struct mmal_fmt *mfmt;
  11504. +
  11505. + mfmt = get_format(f);
  11506. + if (!mfmt) {
  11507. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11508. + "Fourcc format (0x%08x) unknown.\n",
  11509. + f->fmt.pix.pixelformat);
  11510. + f->fmt.pix.pixelformat = formats[0].fourcc;
  11511. + mfmt = get_format(f);
  11512. + }
  11513. +
  11514. + f->fmt.pix.field = V4L2_FIELD_NONE;
  11515. + /* image must be a multiple of 32 pixels wide and 16 lines high */
  11516. + v4l_bound_align_image(&f->fmt.pix.width, 48, MAX_WIDTH, 5,
  11517. + &f->fmt.pix.height, 32, MAX_HEIGHT, 4, 0);
  11518. + f->fmt.pix.bytesperline = (f->fmt.pix.width * mfmt->depth) >> 3;
  11519. + f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
  11520. + if (f->fmt.pix.sizeimage < MIN_BUFFER_SIZE)
  11521. + f->fmt.pix.sizeimage = MIN_BUFFER_SIZE;
  11522. +
  11523. + if (mfmt->fourcc == V4L2_PIX_FMT_YUYV ||
  11524. + mfmt->fourcc == V4L2_PIX_FMT_UYVY)
  11525. + f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
  11526. + else
  11527. + f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
  11528. + f->fmt.pix.priv = 0;
  11529. +
  11530. + v4l2_dump_pix_format(1, bcm2835_v4l2_debug, &dev->v4l2_dev, &f->fmt.pix,
  11531. + __func__);
  11532. + return 0;
  11533. +}
  11534. +
  11535. +static int mmal_setup_components(struct bm2835_mmal_dev *dev,
  11536. + struct v4l2_format *f)
  11537. +{
  11538. + int ret;
  11539. + struct vchiq_mmal_port *port = NULL, *camera_port = NULL;
  11540. + struct vchiq_mmal_component *encode_component = NULL;
  11541. + struct mmal_fmt *mfmt = get_format(f);
  11542. +
  11543. + BUG_ON(!mfmt);
  11544. +
  11545. + if (dev->capture.encode_component) {
  11546. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11547. + "vid_cap - disconnect previous tunnel\n");
  11548. +
  11549. + /* Disconnect any previous connection */
  11550. + vchiq_mmal_port_connect_tunnel(dev->instance,
  11551. + dev->capture.camera_port, NULL);
  11552. + dev->capture.camera_port = NULL;
  11553. + ret = vchiq_mmal_component_disable(dev->instance,
  11554. + dev->capture.
  11555. + encode_component);
  11556. + if (ret)
  11557. + v4l2_err(&dev->v4l2_dev,
  11558. + "Failed to disable encode component %d\n",
  11559. + ret);
  11560. +
  11561. + dev->capture.encode_component = NULL;
  11562. + }
  11563. + /* format dependant port setup */
  11564. + switch (mfmt->mmal_component) {
  11565. + case MMAL_COMPONENT_CAMERA:
  11566. + /* Make a further decision on port based on resolution */
  11567. + if (f->fmt.pix.width <= MAX_VIDEO_MODE_WIDTH
  11568. + && f->fmt.pix.height <= MAX_VIDEO_MODE_HEIGHT)
  11569. + camera_port = port =
  11570. + &dev->component[MMAL_COMPONENT_CAMERA]->
  11571. + output[MMAL_CAMERA_PORT_VIDEO];
  11572. + else
  11573. + camera_port = port =
  11574. + &dev->component[MMAL_COMPONENT_CAMERA]->
  11575. + output[MMAL_CAMERA_PORT_CAPTURE];
  11576. + break;
  11577. + case MMAL_COMPONENT_IMAGE_ENCODE:
  11578. + encode_component = dev->component[MMAL_COMPONENT_IMAGE_ENCODE];
  11579. + port = &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->output[0];
  11580. + camera_port =
  11581. + &dev->component[MMAL_COMPONENT_CAMERA]->
  11582. + output[MMAL_CAMERA_PORT_CAPTURE];
  11583. + break;
  11584. + case MMAL_COMPONENT_VIDEO_ENCODE:
  11585. + encode_component = dev->component[MMAL_COMPONENT_VIDEO_ENCODE];
  11586. + port = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  11587. + camera_port =
  11588. + &dev->component[MMAL_COMPONENT_CAMERA]->
  11589. + output[MMAL_CAMERA_PORT_VIDEO];
  11590. + break;
  11591. + default:
  11592. + break;
  11593. + }
  11594. +
  11595. + if (!port)
  11596. + return -EINVAL;
  11597. +
  11598. + if (encode_component)
  11599. + camera_port->format.encoding = MMAL_ENCODING_OPAQUE;
  11600. + else
  11601. + camera_port->format.encoding = mfmt->mmal;
  11602. +
  11603. + camera_port->format.encoding_variant = 0;
  11604. + camera_port->es.video.width = f->fmt.pix.width;
  11605. + camera_port->es.video.height = f->fmt.pix.height;
  11606. + camera_port->es.video.crop.x = 0;
  11607. + camera_port->es.video.crop.y = 0;
  11608. + camera_port->es.video.crop.width = f->fmt.pix.width;
  11609. + camera_port->es.video.crop.height = f->fmt.pix.height;
  11610. + camera_port->es.video.frame_rate.num =
  11611. + dev->capture.timeperframe.denominator;
  11612. + camera_port->es.video.frame_rate.den =
  11613. + dev->capture.timeperframe.numerator;
  11614. +
  11615. + ret = vchiq_mmal_port_set_format(dev->instance, camera_port);
  11616. +
  11617. + if (!ret
  11618. + && camera_port ==
  11619. + &dev->component[MMAL_COMPONENT_CAMERA]->
  11620. + output[MMAL_CAMERA_PORT_VIDEO]) {
  11621. + bool overlay_enabled =
  11622. + !!dev->component[MMAL_COMPONENT_PREVIEW]->enabled;
  11623. + struct vchiq_mmal_port *preview_port =
  11624. + &dev->component[MMAL_COMPONENT_CAMERA]->
  11625. + output[MMAL_CAMERA_PORT_PREVIEW];
  11626. + /* Preview and encode ports need to match on resolution */
  11627. + if (overlay_enabled) {
  11628. + /* Need to disable the overlay before we can update
  11629. + * the resolution
  11630. + */
  11631. + ret =
  11632. + vchiq_mmal_port_disable(dev->instance,
  11633. + preview_port);
  11634. + if (!ret)
  11635. + ret =
  11636. + vchiq_mmal_port_connect_tunnel(
  11637. + dev->instance,
  11638. + preview_port,
  11639. + NULL);
  11640. + }
  11641. + preview_port->es.video.width = f->fmt.pix.width;
  11642. + preview_port->es.video.height = f->fmt.pix.height;
  11643. + preview_port->es.video.crop.x = 0;
  11644. + preview_port->es.video.crop.y = 0;
  11645. + preview_port->es.video.crop.width = f->fmt.pix.width;
  11646. + preview_port->es.video.crop.height = f->fmt.pix.height;
  11647. + preview_port->es.video.frame_rate.num = 30;
  11648. + preview_port->es.video.frame_rate.den = 1;
  11649. + ret = vchiq_mmal_port_set_format(dev->instance, preview_port);
  11650. + if (overlay_enabled) {
  11651. + ret = vchiq_mmal_port_connect_tunnel(
  11652. + dev->instance,
  11653. + preview_port,
  11654. + &dev->component[MMAL_COMPONENT_PREVIEW]->input[0]);
  11655. + if (!ret)
  11656. + ret = vchiq_mmal_port_enable(dev->instance,
  11657. + preview_port,
  11658. + NULL);
  11659. + }
  11660. + }
  11661. +
  11662. + if (ret) {
  11663. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11664. + "%s failed to set format\n", __func__);
  11665. + /* ensure capture is not going to be tried */
  11666. + dev->capture.port = NULL;
  11667. + } else {
  11668. + if (encode_component) {
  11669. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11670. + "vid_cap - set up encode comp\n");
  11671. +
  11672. + /* configure buffering */
  11673. + camera_port->current_buffer.size =
  11674. + camera_port->recommended_buffer.size;
  11675. + camera_port->current_buffer.num =
  11676. + camera_port->recommended_buffer.num;
  11677. +
  11678. + ret =
  11679. + vchiq_mmal_port_connect_tunnel(
  11680. + dev->instance,
  11681. + camera_port,
  11682. + &encode_component->input[0]);
  11683. + if (ret) {
  11684. + v4l2_dbg(1, bcm2835_v4l2_debug,
  11685. + &dev->v4l2_dev,
  11686. + "%s failed to create connection\n",
  11687. + __func__);
  11688. + /* ensure capture is not going to be tried */
  11689. + dev->capture.port = NULL;
  11690. + } else {
  11691. + port->es.video.width = f->fmt.pix.width;
  11692. + port->es.video.height = f->fmt.pix.height;
  11693. + port->es.video.crop.x = 0;
  11694. + port->es.video.crop.y = 0;
  11695. + port->es.video.crop.width = f->fmt.pix.width;
  11696. + port->es.video.crop.height = f->fmt.pix.height;
  11697. + port->es.video.frame_rate.num =
  11698. + dev->capture.timeperframe.denominator;
  11699. + port->es.video.frame_rate.den =
  11700. + dev->capture.timeperframe.numerator;
  11701. +
  11702. + port->format.encoding = mfmt->mmal;
  11703. + port->format.encoding_variant = 0;
  11704. + /* Set any encoding specific parameters */
  11705. + switch (mfmt->mmal_component) {
  11706. + case MMAL_COMPONENT_VIDEO_ENCODE:
  11707. + port->format.bitrate =
  11708. + dev->capture.encode_bitrate;
  11709. + break;
  11710. + case MMAL_COMPONENT_IMAGE_ENCODE:
  11711. + /* Could set EXIF parameters here */
  11712. + break;
  11713. + default:
  11714. + break;
  11715. + }
  11716. + ret = vchiq_mmal_port_set_format(dev->instance,
  11717. + port);
  11718. + if (ret)
  11719. + v4l2_dbg(1, bcm2835_v4l2_debug,
  11720. + &dev->v4l2_dev,
  11721. + "%s failed to set format\n",
  11722. + __func__);
  11723. + }
  11724. +
  11725. + if (!ret) {
  11726. + ret = vchiq_mmal_component_enable(
  11727. + dev->instance,
  11728. + encode_component);
  11729. + if (ret) {
  11730. + v4l2_dbg(1, bcm2835_v4l2_debug,
  11731. + &dev->v4l2_dev,
  11732. + "%s Failed to enable encode components\n",
  11733. + __func__);
  11734. + }
  11735. + }
  11736. + if (!ret) {
  11737. + /* configure buffering */
  11738. + port->current_buffer.num = 1;
  11739. + port->current_buffer.size =
  11740. + f->fmt.pix.sizeimage;
  11741. + if (port->format.encoding ==
  11742. + MMAL_ENCODING_JPEG) {
  11743. + v4l2_dbg(1, bcm2835_v4l2_debug,
  11744. + &dev->v4l2_dev,
  11745. + "JPG - buf size now %d was %d\n",
  11746. + f->fmt.pix.sizeimage,
  11747. + port->current_buffer.size);
  11748. + port->current_buffer.size =
  11749. + (f->fmt.pix.sizeimage <
  11750. + (100 << 10))
  11751. + ? (100 << 10) : f->fmt.pix.
  11752. + sizeimage;
  11753. + }
  11754. + v4l2_dbg(1, bcm2835_v4l2_debug,
  11755. + &dev->v4l2_dev,
  11756. + "vid_cap - cur_buf.size set to %d\n",
  11757. + f->fmt.pix.sizeimage);
  11758. + port->current_buffer.alignment = 0;
  11759. + }
  11760. + } else {
  11761. + /* configure buffering */
  11762. + camera_port->current_buffer.num = 1;
  11763. + camera_port->current_buffer.size = f->fmt.pix.sizeimage;
  11764. + camera_port->current_buffer.alignment = 0;
  11765. + }
  11766. +
  11767. + if (!ret) {
  11768. + dev->capture.fmt = mfmt;
  11769. + dev->capture.stride = f->fmt.pix.bytesperline;
  11770. + dev->capture.width = camera_port->es.video.crop.width;
  11771. + dev->capture.height = camera_port->es.video.crop.height;
  11772. +
  11773. + /* select port for capture */
  11774. + dev->capture.port = port;
  11775. + dev->capture.camera_port = camera_port;
  11776. + dev->capture.encode_component = encode_component;
  11777. + v4l2_dbg(1, bcm2835_v4l2_debug,
  11778. + &dev->v4l2_dev,
  11779. + "Set dev->capture.fmt %08X, %dx%d, stride %d",
  11780. + port->format.encoding,
  11781. + dev->capture.width, dev->capture.height,
  11782. + dev->capture.stride);
  11783. + }
  11784. + }
  11785. +
  11786. + /* todo: Need to convert the vchiq/mmal error into a v4l2 error. */
  11787. + return ret;
  11788. +}
  11789. +
  11790. +static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
  11791. + struct v4l2_format *f)
  11792. +{
  11793. + int ret;
  11794. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  11795. + struct mmal_fmt *mfmt;
  11796. +
  11797. + /* try the format to set valid parameters */
  11798. + ret = vidioc_try_fmt_vid_cap(file, priv, f);
  11799. + if (ret) {
  11800. + v4l2_err(&dev->v4l2_dev,
  11801. + "vid_cap - vidioc_try_fmt_vid_cap failed\n");
  11802. + return ret;
  11803. + }
  11804. +
  11805. + /* if a capture is running refuse to set format */
  11806. + if (vb2_is_busy(&dev->capture.vb_vidq)) {
  11807. + v4l2_info(&dev->v4l2_dev, "%s device busy\n", __func__);
  11808. + return -EBUSY;
  11809. + }
  11810. +
  11811. + /* If the format is unsupported v4l2 says we should switch to
  11812. + * a supported one and not return an error. */
  11813. + mfmt = get_format(f);
  11814. + if (!mfmt) {
  11815. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11816. + "Fourcc format (0x%08x) unknown.\n",
  11817. + f->fmt.pix.pixelformat);
  11818. + f->fmt.pix.pixelformat = formats[0].fourcc;
  11819. + mfmt = get_format(f);
  11820. + }
  11821. +
  11822. + ret = mmal_setup_components(dev, f);
  11823. + if (ret != 0)
  11824. + v4l2_err(&dev->v4l2_dev,
  11825. + "%s: failed to setup mmal components: %d\n",
  11826. + __func__, ret);
  11827. +
  11828. + return ret;
  11829. +}
  11830. +
  11831. +/* timeperframe is arbitrary and continous */
  11832. +static int vidioc_enum_frameintervals(struct file *file, void *priv,
  11833. + struct v4l2_frmivalenum *fival)
  11834. +{
  11835. + if (fival->index)
  11836. + return -EINVAL;
  11837. +
  11838. + /* regarding width & height - we support any */
  11839. +
  11840. + fival->type = V4L2_FRMIVAL_TYPE_CONTINUOUS;
  11841. +
  11842. + /* fill in stepwise (step=1.0 is requred by V4L2 spec) */
  11843. + fival->stepwise.min = tpf_min;
  11844. + fival->stepwise.max = tpf_max;
  11845. + fival->stepwise.step = (struct v4l2_fract) {1, 1};
  11846. +
  11847. + return 0;
  11848. +}
  11849. +
  11850. +static int vidioc_g_parm(struct file *file, void *priv,
  11851. + struct v4l2_streamparm *parm)
  11852. +{
  11853. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  11854. +
  11855. + if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  11856. + return -EINVAL;
  11857. +
  11858. + parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
  11859. + parm->parm.capture.timeperframe = dev->capture.timeperframe;
  11860. + parm->parm.capture.readbuffers = 1;
  11861. + return 0;
  11862. +}
  11863. +
  11864. +#define FRACT_CMP(a, OP, b) \
  11865. + ((u64)(a).numerator * (b).denominator OP \
  11866. + (u64)(b).numerator * (a).denominator)
  11867. +
  11868. +static int vidioc_s_parm(struct file *file, void *priv,
  11869. + struct v4l2_streamparm *parm)
  11870. +{
  11871. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  11872. + struct v4l2_fract tpf;
  11873. + struct mmal_parameter_rational fps_param;
  11874. + int ret;
  11875. +
  11876. + if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  11877. + return -EINVAL;
  11878. +
  11879. + tpf = parm->parm.capture.timeperframe;
  11880. +
  11881. + /* tpf: {*, 0} resets timing; clip to [min, max]*/
  11882. + tpf = tpf.denominator ? tpf : tpf_default;
  11883. + tpf = FRACT_CMP(tpf, <, tpf_min) ? tpf_min : tpf;
  11884. + tpf = FRACT_CMP(tpf, >, tpf_max) ? tpf_max : tpf;
  11885. +
  11886. + dev->capture.timeperframe = tpf;
  11887. + parm->parm.capture.timeperframe = tpf;
  11888. + parm->parm.capture.readbuffers = 1;
  11889. +
  11890. + fps_param.num = dev->capture.timeperframe.denominator;
  11891. + fps_param.den = dev->capture.timeperframe.numerator;
  11892. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  11893. + &dev->component[MMAL_COMPONENT_CAMERA]->
  11894. + output[MMAL_CAMERA_PORT_PREVIEW],
  11895. + MMAL_PARAMETER_VIDEO_FRAME_RATE,
  11896. + &fps_param, sizeof(fps_param));
  11897. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  11898. + &dev->component[MMAL_COMPONENT_CAMERA]->
  11899. + output[MMAL_CAMERA_PORT_VIDEO],
  11900. + MMAL_PARAMETER_VIDEO_FRAME_RATE,
  11901. + &fps_param, sizeof(fps_param));
  11902. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  11903. + &dev->component[MMAL_COMPONENT_CAMERA]->
  11904. + output[MMAL_CAMERA_PORT_CAPTURE],
  11905. + MMAL_PARAMETER_VIDEO_FRAME_RATE,
  11906. + &fps_param, sizeof(fps_param));
  11907. + if (ret)
  11908. + v4l2_dbg(0, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11909. + "Failed to set fps ret %d\n",
  11910. + ret);
  11911. +
  11912. + return 0;
  11913. +}
  11914. +
  11915. +static const struct v4l2_ioctl_ops camera0_ioctl_ops = {
  11916. + /* overlay */
  11917. + .vidioc_enum_fmt_vid_overlay = vidioc_enum_fmt_vid_overlay,
  11918. + .vidioc_g_fmt_vid_overlay = vidioc_g_fmt_vid_overlay,
  11919. + .vidioc_try_fmt_vid_overlay = vidioc_try_fmt_vid_overlay,
  11920. + .vidioc_s_fmt_vid_overlay = vidioc_s_fmt_vid_overlay,
  11921. + .vidioc_overlay = vidioc_overlay,
  11922. + .vidioc_g_fbuf = vidioc_g_fbuf,
  11923. +
  11924. + /* inputs */
  11925. + .vidioc_enum_input = vidioc_enum_input,
  11926. + .vidioc_g_input = vidioc_g_input,
  11927. + .vidioc_s_input = vidioc_s_input,
  11928. +
  11929. + /* capture */
  11930. + .vidioc_querycap = vidioc_querycap,
  11931. + .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
  11932. + .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
  11933. + .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
  11934. + .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
  11935. +
  11936. + /* buffer management */
  11937. + .vidioc_reqbufs = vb2_ioctl_reqbufs,
  11938. + .vidioc_create_bufs = vb2_ioctl_create_bufs,
  11939. + .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
  11940. + .vidioc_querybuf = vb2_ioctl_querybuf,
  11941. + .vidioc_qbuf = vb2_ioctl_qbuf,
  11942. + .vidioc_dqbuf = vb2_ioctl_dqbuf,
  11943. + .vidioc_enum_frameintervals = vidioc_enum_frameintervals,
  11944. + .vidioc_g_parm = vidioc_g_parm,
  11945. + .vidioc_s_parm = vidioc_s_parm,
  11946. + .vidioc_streamon = vb2_ioctl_streamon,
  11947. + .vidioc_streamoff = vb2_ioctl_streamoff,
  11948. +
  11949. + .vidioc_log_status = v4l2_ctrl_log_status,
  11950. + .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
  11951. + .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
  11952. +};
  11953. +
  11954. +/* ------------------------------------------------------------------
  11955. + Driver init/finalise
  11956. + ------------------------------------------------------------------*/
  11957. +
  11958. +static const struct v4l2_file_operations camera0_fops = {
  11959. + .owner = THIS_MODULE,
  11960. + .open = v4l2_fh_open,
  11961. + .release = vb2_fop_release,
  11962. + .read = vb2_fop_read,
  11963. + .poll = vb2_fop_poll,
  11964. + .unlocked_ioctl = video_ioctl2, /* V4L2 ioctl handler */
  11965. + .mmap = vb2_fop_mmap,
  11966. +};
  11967. +
  11968. +static struct video_device vdev_template = {
  11969. + .name = "camera0",
  11970. + .fops = &camera0_fops,
  11971. + .ioctl_ops = &camera0_ioctl_ops,
  11972. + .release = video_device_release_empty,
  11973. +};
  11974. +
  11975. +static int set_camera_parameters(struct vchiq_mmal_instance *instance,
  11976. + struct vchiq_mmal_component *camera)
  11977. +{
  11978. + int ret;
  11979. + struct mmal_parameter_camera_config cam_config = {
  11980. + .max_stills_w = MAX_WIDTH,
  11981. + .max_stills_h = MAX_HEIGHT,
  11982. + .stills_yuv422 = 1,
  11983. + .one_shot_stills = 1,
  11984. + .max_preview_video_w = 1920,
  11985. + .max_preview_video_h = 1088,
  11986. + .num_preview_video_frames = 3,
  11987. + .stills_capture_circular_buffer_height = 0,
  11988. + .fast_preview_resume = 0,
  11989. + .use_stc_timestamp = MMAL_PARAM_TIMESTAMP_MODE_RAW_STC
  11990. + };
  11991. +
  11992. + ret = vchiq_mmal_port_parameter_set(instance, &camera->control,
  11993. + MMAL_PARAMETER_CAMERA_CONFIG,
  11994. + &cam_config, sizeof(cam_config));
  11995. + return ret;
  11996. +}
  11997. +
  11998. +/* MMAL instance and component init */
  11999. +static int __init mmal_init(struct bm2835_mmal_dev *dev)
  12000. +{
  12001. + int ret;
  12002. + struct mmal_es_format *format;
  12003. +
  12004. + ret = vchiq_mmal_init(&dev->instance);
  12005. + if (ret < 0)
  12006. + return ret;
  12007. +
  12008. + /* get the camera component ready */
  12009. + ret = vchiq_mmal_component_init(dev->instance, "ril.camera",
  12010. + &dev->component[MMAL_COMPONENT_CAMERA]);
  12011. + if (ret < 0)
  12012. + goto unreg_mmal;
  12013. +
  12014. + if (dev->component[MMAL_COMPONENT_CAMERA]->outputs <
  12015. + MMAL_CAMERA_PORT_COUNT) {
  12016. + ret = -EINVAL;
  12017. + goto unreg_camera;
  12018. + }
  12019. +
  12020. + ret = set_camera_parameters(dev->instance,
  12021. + dev->component[MMAL_COMPONENT_CAMERA]);
  12022. + if (ret < 0)
  12023. + goto unreg_camera;
  12024. +
  12025. + format =
  12026. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12027. + output[MMAL_CAMERA_PORT_PREVIEW].format;
  12028. +
  12029. + format->encoding = MMAL_ENCODING_OPAQUE;
  12030. + format->encoding_variant = MMAL_ENCODING_I420;
  12031. +
  12032. + format->es->video.width = 1024;
  12033. + format->es->video.height = 768;
  12034. + format->es->video.crop.x = 0;
  12035. + format->es->video.crop.y = 0;
  12036. + format->es->video.crop.width = 1024;
  12037. + format->es->video.crop.height = 768;
  12038. + format->es->video.frame_rate.num =
  12039. + dev->capture.timeperframe.denominator;
  12040. + format->es->video.frame_rate.den =
  12041. + dev->capture.timeperframe.numerator;
  12042. +
  12043. + format =
  12044. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12045. + output[MMAL_CAMERA_PORT_VIDEO].format;
  12046. +
  12047. + format->encoding = MMAL_ENCODING_OPAQUE;
  12048. + format->encoding_variant = MMAL_ENCODING_I420;
  12049. +
  12050. + format->es->video.width = 1024;
  12051. + format->es->video.height = 768;
  12052. + format->es->video.crop.x = 0;
  12053. + format->es->video.crop.y = 0;
  12054. + format->es->video.crop.width = 1024;
  12055. + format->es->video.crop.height = 768;
  12056. + format->es->video.frame_rate.num =
  12057. + dev->capture.timeperframe.denominator;
  12058. + format->es->video.frame_rate.den =
  12059. + dev->capture.timeperframe.numerator;
  12060. +
  12061. + format =
  12062. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12063. + output[MMAL_CAMERA_PORT_CAPTURE].format;
  12064. +
  12065. + format->encoding = MMAL_ENCODING_OPAQUE;
  12066. +
  12067. + format->es->video.width = 2592;
  12068. + format->es->video.height = 1944;
  12069. + format->es->video.crop.x = 0;
  12070. + format->es->video.crop.y = 0;
  12071. + format->es->video.crop.width = 2592;
  12072. + format->es->video.crop.height = 1944;
  12073. + format->es->video.frame_rate.num = 30;
  12074. + format->es->video.frame_rate.den = 1;
  12075. +
  12076. + dev->capture.width = format->es->video.width;
  12077. + dev->capture.height = format->es->video.height;
  12078. + dev->capture.fmt = &formats[0];
  12079. + dev->capture.encode_component = NULL;
  12080. + dev->capture.timeperframe = tpf_default;
  12081. +
  12082. + /* get the preview component ready */
  12083. + ret = vchiq_mmal_component_init(
  12084. + dev->instance, "ril.video_render",
  12085. + &dev->component[MMAL_COMPONENT_PREVIEW]);
  12086. + if (ret < 0)
  12087. + goto unreg_camera;
  12088. +
  12089. + if (dev->component[MMAL_COMPONENT_PREVIEW]->inputs < 1) {
  12090. + ret = -EINVAL;
  12091. + pr_debug("too few input ports %d needed %d\n",
  12092. + dev->component[MMAL_COMPONENT_PREVIEW]->inputs, 1);
  12093. + goto unreg_preview;
  12094. + }
  12095. +
  12096. + /* get the image encoder component ready */
  12097. + ret = vchiq_mmal_component_init(
  12098. + dev->instance, "ril.image_encode",
  12099. + &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]);
  12100. + if (ret < 0)
  12101. + goto unreg_preview;
  12102. +
  12103. + if (dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->inputs < 1) {
  12104. + ret = -EINVAL;
  12105. + v4l2_err(&dev->v4l2_dev, "too few input ports %d needed %d\n",
  12106. + dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->inputs,
  12107. + 1);
  12108. + goto unreg_image_encoder;
  12109. + }
  12110. +
  12111. + /* get the video encoder component ready */
  12112. + ret = vchiq_mmal_component_init(dev->instance, "ril.video_encode",
  12113. + &dev->
  12114. + component[MMAL_COMPONENT_VIDEO_ENCODE]);
  12115. + if (ret < 0)
  12116. + goto unreg_image_encoder;
  12117. +
  12118. + if (dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->inputs < 1) {
  12119. + ret = -EINVAL;
  12120. + v4l2_err(&dev->v4l2_dev, "too few input ports %d needed %d\n",
  12121. + dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->inputs,
  12122. + 1);
  12123. + goto unreg_vid_encoder;
  12124. + }
  12125. +
  12126. + {
  12127. + unsigned int enable = 1;
  12128. + vchiq_mmal_port_parameter_set(
  12129. + dev->instance,
  12130. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->control,
  12131. + MMAL_PARAMETER_VIDEO_IMMUTABLE_INPUT,
  12132. + &enable, sizeof(enable));
  12133. +
  12134. + vchiq_mmal_port_parameter_set(dev->instance,
  12135. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->control,
  12136. + MMAL_PARAMETER_MINIMISE_FRAGMENTATION,
  12137. + &enable,
  12138. + sizeof(enable));
  12139. + }
  12140. + ret = bm2835_mmal_set_all_camera_controls(dev);
  12141. + if (ret < 0)
  12142. + goto unreg_vid_encoder;
  12143. +
  12144. + return 0;
  12145. +
  12146. +unreg_vid_encoder:
  12147. + pr_err("Cleanup: Destroy video encoder\n");
  12148. + vchiq_mmal_component_finalise(
  12149. + dev->instance,
  12150. + dev->component[MMAL_COMPONENT_VIDEO_ENCODE]);
  12151. +
  12152. +unreg_image_encoder:
  12153. + pr_err("Cleanup: Destroy image encoder\n");
  12154. + vchiq_mmal_component_finalise(
  12155. + dev->instance,
  12156. + dev->component[MMAL_COMPONENT_IMAGE_ENCODE]);
  12157. +
  12158. +unreg_preview:
  12159. + pr_err("Cleanup: Destroy video render\n");
  12160. + vchiq_mmal_component_finalise(dev->instance,
  12161. + dev->component[MMAL_COMPONENT_PREVIEW]);
  12162. +
  12163. +unreg_camera:
  12164. + pr_err("Cleanup: Destroy camera\n");
  12165. + vchiq_mmal_component_finalise(dev->instance,
  12166. + dev->component[MMAL_COMPONENT_CAMERA]);
  12167. +
  12168. +unreg_mmal:
  12169. + vchiq_mmal_finalise(dev->instance);
  12170. + return ret;
  12171. +}
  12172. +
  12173. +static int __init bm2835_mmal_init_device(struct bm2835_mmal_dev *dev,
  12174. + struct video_device *vfd)
  12175. +{
  12176. + int ret;
  12177. +
  12178. + *vfd = vdev_template;
  12179. +
  12180. + vfd->v4l2_dev = &dev->v4l2_dev;
  12181. +
  12182. + vfd->lock = &dev->mutex;
  12183. +
  12184. + vfd->queue = &dev->capture.vb_vidq;
  12185. +
  12186. + set_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
  12187. +
  12188. + /* video device needs to be able to access instance data */
  12189. + video_set_drvdata(vfd, dev);
  12190. +
  12191. + ret = video_register_device(vfd, VFL_TYPE_GRABBER, -1);
  12192. + if (ret < 0)
  12193. + return ret;
  12194. +
  12195. + v4l2_info(vfd->v4l2_dev, "V4L2 device registered as %s\n",
  12196. + video_device_node_name(vfd));
  12197. +
  12198. + return 0;
  12199. +}
  12200. +
  12201. +static struct v4l2_format default_v4l2_format = {
  12202. + .fmt.pix.pixelformat = V4L2_PIX_FMT_JPEG,
  12203. + .fmt.pix.width = 1024,
  12204. + .fmt.pix.bytesperline = 1024 * 3 / 2,
  12205. + .fmt.pix.height = 768,
  12206. + .fmt.pix.sizeimage = 1<<18,
  12207. +};
  12208. +
  12209. +static int __init bm2835_mmal_init(void)
  12210. +{
  12211. + int ret;
  12212. + struct bm2835_mmal_dev *dev;
  12213. + struct vb2_queue *q;
  12214. +
  12215. + dev = kzalloc(sizeof(*gdev), GFP_KERNEL);
  12216. + if (!dev)
  12217. + return -ENOMEM;
  12218. +
  12219. + /* setup device defaults */
  12220. + dev->overlay.w.left = 150;
  12221. + dev->overlay.w.top = 50;
  12222. + dev->overlay.w.width = 1024;
  12223. + dev->overlay.w.height = 768;
  12224. + dev->overlay.clipcount = 0;
  12225. + dev->overlay.field = V4L2_FIELD_NONE;
  12226. +
  12227. + dev->capture.fmt = &formats[3]; /* JPEG */
  12228. +
  12229. + /* v4l device registration */
  12230. + snprintf(dev->v4l2_dev.name, sizeof(dev->v4l2_dev.name),
  12231. + "%s", BM2835_MMAL_MODULE_NAME);
  12232. + ret = v4l2_device_register(NULL, &dev->v4l2_dev);
  12233. + if (ret)
  12234. + goto free_dev;
  12235. +
  12236. + /* setup v4l controls */
  12237. + ret = bm2835_mmal_init_controls(dev, &dev->ctrl_handler);
  12238. + if (ret < 0)
  12239. + goto unreg_dev;
  12240. + dev->v4l2_dev.ctrl_handler = &dev->ctrl_handler;
  12241. +
  12242. + /* mmal init */
  12243. + ret = mmal_init(dev);
  12244. + if (ret < 0)
  12245. + goto unreg_dev;
  12246. +
  12247. + /* initialize queue */
  12248. + q = &dev->capture.vb_vidq;
  12249. + memset(q, 0, sizeof(*q));
  12250. + q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  12251. + q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ;
  12252. + q->drv_priv = dev;
  12253. + q->buf_struct_size = sizeof(struct mmal_buffer);
  12254. + q->ops = &bm2835_mmal_video_qops;
  12255. + q->mem_ops = &vb2_vmalloc_memops;
  12256. + q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
  12257. + ret = vb2_queue_init(q);
  12258. + if (ret < 0)
  12259. + goto unreg_dev;
  12260. +
  12261. + /* v4l2 core mutex used to protect all fops and v4l2 ioctls. */
  12262. + mutex_init(&dev->mutex);
  12263. +
  12264. + /* initialise video devices */
  12265. + ret = bm2835_mmal_init_device(dev, &dev->vdev);
  12266. + if (ret < 0)
  12267. + goto unreg_dev;
  12268. +
  12269. + ret = mmal_setup_components(dev, &default_v4l2_format);
  12270. + if (ret < 0) {
  12271. + v4l2_err(&dev->v4l2_dev,
  12272. + "%s: could not setup components\n", __func__);
  12273. + goto unreg_dev;
  12274. + }
  12275. +
  12276. + v4l2_info(&dev->v4l2_dev,
  12277. + "Broadcom 2835 MMAL video capture ver %s loaded.\n",
  12278. + BM2835_MMAL_VERSION);
  12279. +
  12280. + gdev = dev;
  12281. + return 0;
  12282. +
  12283. +unreg_dev:
  12284. + v4l2_ctrl_handler_free(&dev->ctrl_handler);
  12285. + v4l2_device_unregister(&dev->v4l2_dev);
  12286. +
  12287. +free_dev:
  12288. + kfree(dev);
  12289. +
  12290. + v4l2_err(&dev->v4l2_dev,
  12291. + "%s: error %d while loading driver\n",
  12292. + BM2835_MMAL_MODULE_NAME, ret);
  12293. +
  12294. + return ret;
  12295. +}
  12296. +
  12297. +static void __exit bm2835_mmal_exit(void)
  12298. +{
  12299. + if (!gdev)
  12300. + return;
  12301. +
  12302. + v4l2_info(&gdev->v4l2_dev, "unregistering %s\n",
  12303. + video_device_node_name(&gdev->vdev));
  12304. +
  12305. + video_unregister_device(&gdev->vdev);
  12306. +
  12307. + if (gdev->capture.encode_component) {
  12308. + v4l2_dbg(1, bcm2835_v4l2_debug, &gdev->v4l2_dev,
  12309. + "mmal_exit - disconnect tunnel\n");
  12310. + vchiq_mmal_port_connect_tunnel(gdev->instance,
  12311. + gdev->capture.camera_port, NULL);
  12312. + vchiq_mmal_component_disable(gdev->instance,
  12313. + gdev->capture.encode_component);
  12314. + }
  12315. + vchiq_mmal_component_disable(gdev->instance,
  12316. + gdev->component[MMAL_COMPONENT_CAMERA]);
  12317. +
  12318. + vchiq_mmal_component_finalise(gdev->instance,
  12319. + gdev->
  12320. + component[MMAL_COMPONENT_VIDEO_ENCODE]);
  12321. +
  12322. + vchiq_mmal_component_finalise(gdev->instance,
  12323. + gdev->
  12324. + component[MMAL_COMPONENT_IMAGE_ENCODE]);
  12325. +
  12326. + vchiq_mmal_component_finalise(gdev->instance,
  12327. + gdev->component[MMAL_COMPONENT_PREVIEW]);
  12328. +
  12329. + vchiq_mmal_component_finalise(gdev->instance,
  12330. + gdev->component[MMAL_COMPONENT_CAMERA]);
  12331. +
  12332. + vchiq_mmal_finalise(gdev->instance);
  12333. +
  12334. + v4l2_ctrl_handler_free(&gdev->ctrl_handler);
  12335. +
  12336. + v4l2_device_unregister(&gdev->v4l2_dev);
  12337. +
  12338. + kfree(gdev);
  12339. +}
  12340. +
  12341. +module_init(bm2835_mmal_init);
  12342. +module_exit(bm2835_mmal_exit);
  12343. diff -Nur linux-3.13.3.orig/drivers/media/platform/bcm2835/bcm2835-camera.h linux-3.13.3/drivers/media/platform/bcm2835/bcm2835-camera.h
  12344. --- linux-3.13.3.orig/drivers/media/platform/bcm2835/bcm2835-camera.h 1970-01-01 01:00:00.000000000 +0100
  12345. +++ linux-3.13.3/drivers/media/platform/bcm2835/bcm2835-camera.h 2014-02-17 22:41:01.000000000 +0100
  12346. @@ -0,0 +1,113 @@
  12347. +/*
  12348. + * Broadcom BM2835 V4L2 driver
  12349. + *
  12350. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  12351. + *
  12352. + * This file is subject to the terms and conditions of the GNU General Public
  12353. + * License. See the file COPYING in the main directory of this archive
  12354. + * for more details.
  12355. + *
  12356. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  12357. + * Dave Stevenson <dsteve@broadcom.com>
  12358. + * Simon Mellor <simellor@broadcom.com>
  12359. + * Luke Diamand <luked@broadcom.com>
  12360. + *
  12361. + * core driver device
  12362. + */
  12363. +
  12364. +#define V4L2_CTRL_COUNT 21 /* number of v4l controls */
  12365. +
  12366. +enum {
  12367. + MMAL_COMPONENT_CAMERA = 0,
  12368. + MMAL_COMPONENT_PREVIEW,
  12369. + MMAL_COMPONENT_IMAGE_ENCODE,
  12370. + MMAL_COMPONENT_VIDEO_ENCODE,
  12371. + MMAL_COMPONENT_COUNT
  12372. +};
  12373. +
  12374. +enum {
  12375. + MMAL_CAMERA_PORT_PREVIEW = 0,
  12376. + MMAL_CAMERA_PORT_VIDEO,
  12377. + MMAL_CAMERA_PORT_CAPTURE,
  12378. + MMAL_CAMERA_PORT_COUNT
  12379. +};
  12380. +
  12381. +#define PREVIEW_LAYER 2
  12382. +
  12383. +extern int bcm2835_v4l2_debug;
  12384. +
  12385. +struct bm2835_mmal_dev {
  12386. + /* v4l2 devices */
  12387. + struct v4l2_device v4l2_dev;
  12388. + struct video_device vdev;
  12389. + struct mutex mutex;
  12390. +
  12391. + /* controls */
  12392. + struct v4l2_ctrl_handler ctrl_handler;
  12393. + struct v4l2_ctrl *ctrls[V4L2_CTRL_COUNT];
  12394. + struct mmal_colourfx colourfx;
  12395. + int hflip;
  12396. + int vflip;
  12397. + enum mmal_parameter_exposuremode exposure_mode;
  12398. + unsigned int manual_shutter_speed;
  12399. +
  12400. + /* allocated mmal instance and components */
  12401. + struct vchiq_mmal_instance *instance;
  12402. + struct vchiq_mmal_component *component[MMAL_COMPONENT_COUNT];
  12403. + int camera_use_count;
  12404. +
  12405. + struct v4l2_window overlay;
  12406. +
  12407. + struct {
  12408. + unsigned int width; /* width */
  12409. + unsigned int height; /* height */
  12410. + unsigned int stride; /* stride */
  12411. + struct mmal_fmt *fmt;
  12412. + struct v4l2_fract timeperframe;
  12413. +
  12414. + /* H264 encode bitrate */
  12415. + int encode_bitrate;
  12416. + /* H264 bitrate mode. CBR/VBR */
  12417. + int encode_bitrate_mode;
  12418. + /* JPEG Q-factor */
  12419. + int q_factor;
  12420. +
  12421. + struct vb2_queue vb_vidq;
  12422. +
  12423. + /* VC start timestamp for streaming */
  12424. + s64 vc_start_timestamp;
  12425. + /* Kernel start timestamp for streaming */
  12426. + struct timeval kernel_start_ts;
  12427. +
  12428. + struct vchiq_mmal_port *port; /* port being used for capture */
  12429. + /* camera port being used for capture */
  12430. + struct vchiq_mmal_port *camera_port;
  12431. + /* component being used for encode */
  12432. + struct vchiq_mmal_component *encode_component;
  12433. + /* number of frames remaining which driver should capture */
  12434. + unsigned int frame_count;
  12435. + /* last frame completion */
  12436. + struct completion frame_cmplt;
  12437. +
  12438. + } capture;
  12439. +
  12440. +};
  12441. +
  12442. +int bm2835_mmal_init_controls(
  12443. + struct bm2835_mmal_dev *dev,
  12444. + struct v4l2_ctrl_handler *hdl);
  12445. +
  12446. +int bm2835_mmal_set_all_camera_controls(struct bm2835_mmal_dev *dev);
  12447. +
  12448. +
  12449. +/* Debug helpers */
  12450. +
  12451. +#define v4l2_dump_pix_format(level, debug, dev, pix_fmt, desc) \
  12452. +{ \
  12453. + v4l2_dbg(level, debug, dev, \
  12454. +"%s: w %u h %u field %u pfmt 0x%x bpl %u sz_img %u colorspace 0x%x priv %u\n", \
  12455. + desc == NULL ? "" : desc, \
  12456. + (pix_fmt)->width, (pix_fmt)->height, (pix_fmt)->field, \
  12457. + (pix_fmt)->pixelformat, (pix_fmt)->bytesperline, \
  12458. + (pix_fmt)->sizeimage, (pix_fmt)->colorspace, (pix_fmt)->priv); \
  12459. +}
  12460. diff -Nur linux-3.13.3.orig/drivers/media/platform/bcm2835/controls.c linux-3.13.3/drivers/media/platform/bcm2835/controls.c
  12461. --- linux-3.13.3.orig/drivers/media/platform/bcm2835/controls.c 1970-01-01 01:00:00.000000000 +0100
  12462. +++ linux-3.13.3/drivers/media/platform/bcm2835/controls.c 2014-02-17 22:41:01.000000000 +0100
  12463. @@ -0,0 +1,902 @@
  12464. +/*
  12465. + * Broadcom BM2835 V4L2 driver
  12466. + *
  12467. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  12468. + *
  12469. + * This file is subject to the terms and conditions of the GNU General Public
  12470. + * License. See the file COPYING in the main directory of this archive
  12471. + * for more details.
  12472. + *
  12473. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  12474. + * Dave Stevenson <dsteve@broadcom.com>
  12475. + * Simon Mellor <simellor@broadcom.com>
  12476. + * Luke Diamand <luked@broadcom.com>
  12477. + */
  12478. +
  12479. +#include <linux/errno.h>
  12480. +#include <linux/kernel.h>
  12481. +#include <linux/module.h>
  12482. +#include <linux/slab.h>
  12483. +#include <media/videobuf2-vmalloc.h>
  12484. +#include <media/v4l2-device.h>
  12485. +#include <media/v4l2-ioctl.h>
  12486. +#include <media/v4l2-ctrls.h>
  12487. +#include <media/v4l2-fh.h>
  12488. +#include <media/v4l2-event.h>
  12489. +#include <media/v4l2-common.h>
  12490. +
  12491. +#include "mmal-common.h"
  12492. +#include "mmal-vchiq.h"
  12493. +#include "mmal-parameters.h"
  12494. +#include "bcm2835-camera.h"
  12495. +
  12496. +/* The supported V4L2_CID_AUTO_EXPOSURE_BIAS values are from -4.0 to +4.0.
  12497. + * MMAL values are in 1/6th increments so the MMAL range is -24 to +24.
  12498. + * V4L2 docs say value "is expressed in terms of EV, drivers should interpret
  12499. + * the values as 0.001 EV units, where the value 1000 stands for +1 EV."
  12500. + * V4L2 is limited to a max of 32 values in a menu, so count in 1/3rds from
  12501. + * -4 to +4
  12502. + */
  12503. +static const s64 ev_bias_qmenu[] = {
  12504. + -4000, -3667, -3333,
  12505. + -3000, -2667, -2333,
  12506. + -2000, -1667, -1333,
  12507. + -1000, -667, -333,
  12508. + 0, 333, 667,
  12509. + 1000, 1333, 1667,
  12510. + 2000, 2333, 2667,
  12511. + 3000, 3333, 3667,
  12512. + 4000
  12513. +};
  12514. +
  12515. +/* Supported ISO values
  12516. + * ISOO = auto ISO
  12517. + */
  12518. +static const s64 iso_qmenu[] = {
  12519. + 0, 100, 200, 400, 800,
  12520. +};
  12521. +
  12522. +static const s64 mains_freq_qmenu[] = {
  12523. + V4L2_CID_POWER_LINE_FREQUENCY_DISABLED,
  12524. + V4L2_CID_POWER_LINE_FREQUENCY_50HZ,
  12525. + V4L2_CID_POWER_LINE_FREQUENCY_60HZ,
  12526. + V4L2_CID_POWER_LINE_FREQUENCY_AUTO
  12527. +};
  12528. +
  12529. +/* Supported video encode modes */
  12530. +static const s64 bitrate_mode_qmenu[] = {
  12531. + (s64)V4L2_MPEG_VIDEO_BITRATE_MODE_VBR,
  12532. + (s64)V4L2_MPEG_VIDEO_BITRATE_MODE_CBR,
  12533. +};
  12534. +
  12535. +
  12536. +enum bm2835_mmal_ctrl_type {
  12537. + MMAL_CONTROL_TYPE_STD,
  12538. + MMAL_CONTROL_TYPE_STD_MENU,
  12539. + MMAL_CONTROL_TYPE_INT_MENU,
  12540. + MMAL_CONTROL_TYPE_CLUSTER, /* special cluster entry */
  12541. +};
  12542. +
  12543. +struct bm2835_mmal_v4l2_ctrl;
  12544. +
  12545. +typedef int(bm2835_mmal_v4l2_ctrl_cb)(
  12546. + struct bm2835_mmal_dev *dev,
  12547. + struct v4l2_ctrl *ctrl,
  12548. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl);
  12549. +
  12550. +struct bm2835_mmal_v4l2_ctrl {
  12551. + u32 id; /* v4l2 control identifier */
  12552. + enum bm2835_mmal_ctrl_type type;
  12553. + /* control minimum value or
  12554. + * mask for MMAL_CONTROL_TYPE_STD_MENU */
  12555. + s32 min;
  12556. + s32 max; /* maximum value of control */
  12557. + s32 def; /* default value of control */
  12558. + s32 step; /* step size of the control */
  12559. + const s64 *imenu; /* integer menu array */
  12560. + u32 mmal_id; /* mmal parameter id */
  12561. + bm2835_mmal_v4l2_ctrl_cb *setter;
  12562. + bool ignore_errors;
  12563. +};
  12564. +
  12565. +struct v4l2_to_mmal_effects_setting {
  12566. + u32 v4l2_effect;
  12567. + u32 mmal_effect;
  12568. + s32 col_fx_enable;
  12569. + s32 col_fx_fixed_cbcr;
  12570. + u32 u;
  12571. + u32 v;
  12572. + u32 num_effect_params;
  12573. + u32 effect_params[MMAL_MAX_IMAGEFX_PARAMETERS];
  12574. +};
  12575. +
  12576. +static const struct v4l2_to_mmal_effects_setting
  12577. + v4l2_to_mmal_effects_values[] = {
  12578. + { V4L2_COLORFX_NONE, MMAL_PARAM_IMAGEFX_NONE,
  12579. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  12580. + { V4L2_COLORFX_BW, MMAL_PARAM_IMAGEFX_NONE,
  12581. + 1, 0, 128, 128, 0, {0, 0, 0, 0, 0} },
  12582. + { V4L2_COLORFX_SEPIA, MMAL_PARAM_IMAGEFX_NONE,
  12583. + 1, 0, 87, 151, 0, {0, 0, 0, 0, 0} },
  12584. + { V4L2_COLORFX_NEGATIVE, MMAL_PARAM_IMAGEFX_NEGATIVE,
  12585. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  12586. + { V4L2_COLORFX_EMBOSS, MMAL_PARAM_IMAGEFX_EMBOSS,
  12587. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  12588. + { V4L2_COLORFX_SKETCH, MMAL_PARAM_IMAGEFX_SKETCH,
  12589. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  12590. + { V4L2_COLORFX_SKY_BLUE, MMAL_PARAM_IMAGEFX_PASTEL,
  12591. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  12592. + { V4L2_COLORFX_GRASS_GREEN, MMAL_PARAM_IMAGEFX_WATERCOLOUR,
  12593. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  12594. + { V4L2_COLORFX_SKIN_WHITEN, MMAL_PARAM_IMAGEFX_WASHEDOUT,
  12595. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  12596. + { V4L2_COLORFX_VIVID, MMAL_PARAM_IMAGEFX_SATURATION,
  12597. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  12598. + { V4L2_COLORFX_AQUA, MMAL_PARAM_IMAGEFX_NONE,
  12599. + 1, 0, 171, 121, 0, {0, 0, 0, 0, 0} },
  12600. + { V4L2_COLORFX_ART_FREEZE, MMAL_PARAM_IMAGEFX_HATCH,
  12601. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  12602. + { V4L2_COLORFX_SILHOUETTE, MMAL_PARAM_IMAGEFX_FILM,
  12603. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  12604. + { V4L2_COLORFX_SOLARIZATION, MMAL_PARAM_IMAGEFX_SOLARIZE,
  12605. + 0, 0, 0, 0, 5, {1, 128, 160, 160, 48} },
  12606. + { V4L2_COLORFX_ANTIQUE, MMAL_PARAM_IMAGEFX_COLOURBALANCE,
  12607. + 0, 0, 0, 0, 3, {108, 274, 238, 0, 0} },
  12608. + { V4L2_COLORFX_SET_CBCR, MMAL_PARAM_IMAGEFX_NONE,
  12609. + 1, 1, 0, 0, 0, {0, 0, 0, 0, 0} }
  12610. +};
  12611. +
  12612. +
  12613. +/* control handlers*/
  12614. +
  12615. +static int ctrl_set_rational(struct bm2835_mmal_dev *dev,
  12616. + struct v4l2_ctrl *ctrl,
  12617. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  12618. +{
  12619. + struct mmal_parameter_rational rational_value;
  12620. + struct vchiq_mmal_port *control;
  12621. +
  12622. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  12623. +
  12624. + rational_value.num = ctrl->val;
  12625. + rational_value.den = 100;
  12626. +
  12627. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  12628. + mmal_ctrl->mmal_id,
  12629. + &rational_value,
  12630. + sizeof(rational_value));
  12631. +}
  12632. +
  12633. +static int ctrl_set_value(struct bm2835_mmal_dev *dev,
  12634. + struct v4l2_ctrl *ctrl,
  12635. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  12636. +{
  12637. + u32 u32_value;
  12638. + struct vchiq_mmal_port *control;
  12639. +
  12640. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  12641. +
  12642. + u32_value = ctrl->val;
  12643. +
  12644. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  12645. + mmal_ctrl->mmal_id,
  12646. + &u32_value, sizeof(u32_value));
  12647. +}
  12648. +
  12649. +static int ctrl_set_value_menu(struct bm2835_mmal_dev *dev,
  12650. + struct v4l2_ctrl *ctrl,
  12651. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  12652. +{
  12653. + u32 u32_value;
  12654. + struct vchiq_mmal_port *control;
  12655. +
  12656. + if (ctrl->val > mmal_ctrl->max || ctrl->val < mmal_ctrl->min)
  12657. + return 1;
  12658. +
  12659. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  12660. +
  12661. + u32_value = mmal_ctrl->imenu[ctrl->val];
  12662. +
  12663. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  12664. + mmal_ctrl->mmal_id,
  12665. + &u32_value, sizeof(u32_value));
  12666. +}
  12667. +
  12668. +static int ctrl_set_value_ev(struct bm2835_mmal_dev *dev,
  12669. + struct v4l2_ctrl *ctrl,
  12670. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  12671. +{
  12672. + s32 s32_value;
  12673. + struct vchiq_mmal_port *control;
  12674. +
  12675. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  12676. +
  12677. + s32_value = (ctrl->val-12)*2; /* Convert from index to 1/6ths */
  12678. +
  12679. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  12680. + mmal_ctrl->mmal_id,
  12681. + &s32_value, sizeof(s32_value));
  12682. +}
  12683. +
  12684. +static int ctrl_set_rotate(struct bm2835_mmal_dev *dev,
  12685. + struct v4l2_ctrl *ctrl,
  12686. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  12687. +{
  12688. + int ret;
  12689. + u32 u32_value;
  12690. + struct vchiq_mmal_component *camera;
  12691. +
  12692. + camera = dev->component[MMAL_COMPONENT_CAMERA];
  12693. +
  12694. + u32_value = ((ctrl->val % 360) / 90) * 90;
  12695. +
  12696. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[0],
  12697. + mmal_ctrl->mmal_id,
  12698. + &u32_value, sizeof(u32_value));
  12699. + if (ret < 0)
  12700. + return ret;
  12701. +
  12702. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[1],
  12703. + mmal_ctrl->mmal_id,
  12704. + &u32_value, sizeof(u32_value));
  12705. + if (ret < 0)
  12706. + return ret;
  12707. +
  12708. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[2],
  12709. + mmal_ctrl->mmal_id,
  12710. + &u32_value, sizeof(u32_value));
  12711. +
  12712. + return ret;
  12713. +}
  12714. +
  12715. +static int ctrl_set_flip(struct bm2835_mmal_dev *dev,
  12716. + struct v4l2_ctrl *ctrl,
  12717. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  12718. +{
  12719. + int ret;
  12720. + u32 u32_value;
  12721. + struct vchiq_mmal_component *camera;
  12722. +
  12723. + if (ctrl->id == V4L2_CID_HFLIP)
  12724. + dev->hflip = ctrl->val;
  12725. + else
  12726. + dev->vflip = ctrl->val;
  12727. +
  12728. + camera = dev->component[MMAL_COMPONENT_CAMERA];
  12729. +
  12730. + if (dev->hflip && dev->vflip)
  12731. + u32_value = MMAL_PARAM_MIRROR_BOTH;
  12732. + else if (dev->hflip)
  12733. + u32_value = MMAL_PARAM_MIRROR_HORIZONTAL;
  12734. + else if (dev->vflip)
  12735. + u32_value = MMAL_PARAM_MIRROR_VERTICAL;
  12736. + else
  12737. + u32_value = MMAL_PARAM_MIRROR_NONE;
  12738. +
  12739. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[0],
  12740. + mmal_ctrl->mmal_id,
  12741. + &u32_value, sizeof(u32_value));
  12742. + if (ret < 0)
  12743. + return ret;
  12744. +
  12745. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[1],
  12746. + mmal_ctrl->mmal_id,
  12747. + &u32_value, sizeof(u32_value));
  12748. + if (ret < 0)
  12749. + return ret;
  12750. +
  12751. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[2],
  12752. + mmal_ctrl->mmal_id,
  12753. + &u32_value, sizeof(u32_value));
  12754. +
  12755. + return ret;
  12756. +
  12757. +}
  12758. +
  12759. +static int ctrl_set_exposure(struct bm2835_mmal_dev *dev,
  12760. + struct v4l2_ctrl *ctrl,
  12761. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  12762. +{
  12763. + enum mmal_parameter_exposuremode exp_mode = dev->exposure_mode;
  12764. + u32 shutter_speed = 0;
  12765. + struct vchiq_mmal_port *control;
  12766. + int ret = 0;
  12767. +
  12768. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  12769. +
  12770. + if (mmal_ctrl->mmal_id == MMAL_PARAMETER_SHUTTER_SPEED) {
  12771. + /* V4L2 is in 100usec increments.
  12772. + * MMAL is 1usec.
  12773. + */
  12774. + dev->manual_shutter_speed = ctrl->val * 100;
  12775. + } else if (mmal_ctrl->mmal_id == MMAL_PARAMETER_EXPOSURE_MODE) {
  12776. + switch (ctrl->val) {
  12777. + case V4L2_EXPOSURE_AUTO:
  12778. + exp_mode = MMAL_PARAM_EXPOSUREMODE_AUTO;
  12779. + break;
  12780. +
  12781. + case V4L2_EXPOSURE_MANUAL:
  12782. + exp_mode = MMAL_PARAM_EXPOSUREMODE_OFF;
  12783. + break;
  12784. +
  12785. + case V4L2_EXPOSURE_SHUTTER_PRIORITY:
  12786. + exp_mode = MMAL_PARAM_EXPOSUREMODE_SPORTS;
  12787. + break;
  12788. +
  12789. + case V4L2_EXPOSURE_APERTURE_PRIORITY:
  12790. + exp_mode = MMAL_PARAM_EXPOSUREMODE_NIGHT;
  12791. + break;
  12792. +
  12793. + }
  12794. + dev->exposure_mode = exp_mode;
  12795. + }
  12796. +
  12797. + if (dev->exposure_mode == MMAL_PARAM_EXPOSUREMODE_OFF)
  12798. + shutter_speed = dev->manual_shutter_speed;
  12799. +
  12800. + ret = vchiq_mmal_port_parameter_set(dev->instance, control,
  12801. + MMAL_PARAMETER_SHUTTER_SPEED,
  12802. + &shutter_speed, sizeof(shutter_speed));
  12803. + ret += vchiq_mmal_port_parameter_set(dev->instance, control,
  12804. + MMAL_PARAMETER_EXPOSURE_MODE,
  12805. + &exp_mode, sizeof(u32));
  12806. + return ret;
  12807. +}
  12808. +
  12809. +static int ctrl_set_metering_mode(struct bm2835_mmal_dev *dev,
  12810. + struct v4l2_ctrl *ctrl,
  12811. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  12812. +{
  12813. + u32 u32_value;
  12814. + struct vchiq_mmal_port *control;
  12815. +
  12816. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  12817. +
  12818. + switch (ctrl->val) {
  12819. + case V4L2_EXPOSURE_METERING_AVERAGE:
  12820. + u32_value = MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE;
  12821. + break;
  12822. +
  12823. + case V4L2_EXPOSURE_METERING_CENTER_WEIGHTED:
  12824. + u32_value = MMAL_PARAM_EXPOSUREMETERINGMODE_BACKLIT;
  12825. + break;
  12826. +
  12827. + case V4L2_EXPOSURE_METERING_SPOT:
  12828. + u32_value = MMAL_PARAM_EXPOSUREMETERINGMODE_SPOT;
  12829. + break;
  12830. +
  12831. + /* todo matrix weighting not added to Linux API till 3.9
  12832. + case V4L2_EXPOSURE_METERING_MATRIX:
  12833. + u32_value = MMAL_PARAM_EXPOSUREMETERINGMODE_MATRIX;
  12834. + break;
  12835. + */
  12836. +
  12837. + }
  12838. +
  12839. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  12840. + mmal_ctrl->mmal_id,
  12841. + &u32_value, sizeof(u32_value));
  12842. +}
  12843. +
  12844. +static int ctrl_set_flicker_avoidance(struct bm2835_mmal_dev *dev,
  12845. + struct v4l2_ctrl *ctrl,
  12846. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  12847. +{
  12848. + u32 u32_value;
  12849. + struct vchiq_mmal_port *control;
  12850. +
  12851. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  12852. +
  12853. + switch (ctrl->val) {
  12854. + case V4L2_CID_POWER_LINE_FREQUENCY_DISABLED:
  12855. + u32_value = MMAL_PARAM_FLICKERAVOID_OFF;
  12856. + break;
  12857. + case V4L2_CID_POWER_LINE_FREQUENCY_50HZ:
  12858. + u32_value = MMAL_PARAM_FLICKERAVOID_50HZ;
  12859. + break;
  12860. + case V4L2_CID_POWER_LINE_FREQUENCY_60HZ:
  12861. + u32_value = MMAL_PARAM_FLICKERAVOID_60HZ;
  12862. + break;
  12863. + case V4L2_CID_POWER_LINE_FREQUENCY_AUTO:
  12864. + u32_value = MMAL_PARAM_FLICKERAVOID_AUTO;
  12865. + break;
  12866. + }
  12867. +
  12868. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  12869. + mmal_ctrl->mmal_id,
  12870. + &u32_value, sizeof(u32_value));
  12871. +}
  12872. +
  12873. +static int ctrl_set_awb_mode(struct bm2835_mmal_dev *dev,
  12874. + struct v4l2_ctrl *ctrl,
  12875. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  12876. +{
  12877. + u32 u32_value;
  12878. + struct vchiq_mmal_port *control;
  12879. +
  12880. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  12881. +
  12882. + switch (ctrl->val) {
  12883. + case V4L2_WHITE_BALANCE_MANUAL:
  12884. + u32_value = MMAL_PARAM_AWBMODE_OFF;
  12885. + break;
  12886. +
  12887. + case V4L2_WHITE_BALANCE_AUTO:
  12888. + u32_value = MMAL_PARAM_AWBMODE_AUTO;
  12889. + break;
  12890. +
  12891. + case V4L2_WHITE_BALANCE_INCANDESCENT:
  12892. + u32_value = MMAL_PARAM_AWBMODE_INCANDESCENT;
  12893. + break;
  12894. +
  12895. + case V4L2_WHITE_BALANCE_FLUORESCENT:
  12896. + u32_value = MMAL_PARAM_AWBMODE_FLUORESCENT;
  12897. + break;
  12898. +
  12899. + case V4L2_WHITE_BALANCE_FLUORESCENT_H:
  12900. + u32_value = MMAL_PARAM_AWBMODE_TUNGSTEN;
  12901. + break;
  12902. +
  12903. + case V4L2_WHITE_BALANCE_HORIZON:
  12904. + u32_value = MMAL_PARAM_AWBMODE_HORIZON;
  12905. + break;
  12906. +
  12907. + case V4L2_WHITE_BALANCE_DAYLIGHT:
  12908. + u32_value = MMAL_PARAM_AWBMODE_SUNLIGHT;
  12909. + break;
  12910. +
  12911. + case V4L2_WHITE_BALANCE_FLASH:
  12912. + u32_value = MMAL_PARAM_AWBMODE_FLASH;
  12913. + break;
  12914. +
  12915. + case V4L2_WHITE_BALANCE_CLOUDY:
  12916. + u32_value = MMAL_PARAM_AWBMODE_CLOUDY;
  12917. + break;
  12918. +
  12919. + case V4L2_WHITE_BALANCE_SHADE:
  12920. + u32_value = MMAL_PARAM_AWBMODE_SHADE;
  12921. + break;
  12922. +
  12923. + }
  12924. +
  12925. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  12926. + mmal_ctrl->mmal_id,
  12927. + &u32_value, sizeof(u32_value));
  12928. +}
  12929. +
  12930. +static int ctrl_set_image_effect(struct bm2835_mmal_dev *dev,
  12931. + struct v4l2_ctrl *ctrl,
  12932. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  12933. +{
  12934. + int ret = -EINVAL;
  12935. + int i, j;
  12936. + struct vchiq_mmal_port *control;
  12937. + struct mmal_parameter_imagefx_parameters imagefx;
  12938. +
  12939. + for (i = 0; i < ARRAY_SIZE(v4l2_to_mmal_effects_values); i++) {
  12940. + if (ctrl->val == v4l2_to_mmal_effects_values[i].v4l2_effect) {
  12941. +
  12942. + imagefx.effect =
  12943. + v4l2_to_mmal_effects_values[i].mmal_effect;
  12944. + imagefx.num_effect_params =
  12945. + v4l2_to_mmal_effects_values[i].num_effect_params;
  12946. +
  12947. + if (imagefx.num_effect_params > MMAL_MAX_IMAGEFX_PARAMETERS)
  12948. + imagefx.num_effect_params = MMAL_MAX_IMAGEFX_PARAMETERS;
  12949. +
  12950. + for (j = 0; j < imagefx.num_effect_params; j++)
  12951. + imagefx.effect_parameter[j] =
  12952. + v4l2_to_mmal_effects_values[i].effect_params[j];
  12953. +
  12954. + dev->colourfx.enable =
  12955. + v4l2_to_mmal_effects_values[i].col_fx_enable;
  12956. + if (!v4l2_to_mmal_effects_values[i].col_fx_fixed_cbcr) {
  12957. + dev->colourfx.u =
  12958. + v4l2_to_mmal_effects_values[i].u;
  12959. + dev->colourfx.v =
  12960. + v4l2_to_mmal_effects_values[i].v;
  12961. + }
  12962. +
  12963. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  12964. +
  12965. + ret = vchiq_mmal_port_parameter_set(
  12966. + dev->instance, control,
  12967. + MMAL_PARAMETER_IMAGE_EFFECT_PARAMETERS,
  12968. + &imagefx, sizeof(imagefx));
  12969. + if (ret)
  12970. + goto exit;
  12971. +
  12972. + ret = vchiq_mmal_port_parameter_set(
  12973. + dev->instance, control,
  12974. + MMAL_PARAMETER_COLOUR_EFFECT,
  12975. + &dev->colourfx, sizeof(dev->colourfx));
  12976. + }
  12977. + }
  12978. +
  12979. +exit:
  12980. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12981. + "mmal_ctrl:%p ctrl id:0x%x ctrl val:%d imagefx:0x%x color_effect:%s u:%d v:%d ret %d(%d)\n",
  12982. + mmal_ctrl, ctrl->id, ctrl->val, imagefx.effect,
  12983. + dev->colourfx.enable ? "true" : "false",
  12984. + dev->colourfx.u, dev->colourfx.v,
  12985. + ret, (ret == 0 ? 0 : -EINVAL));
  12986. + return (ret == 0 ? 0 : EINVAL);
  12987. +}
  12988. +
  12989. +static int ctrl_set_colfx(struct bm2835_mmal_dev *dev,
  12990. + struct v4l2_ctrl *ctrl,
  12991. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  12992. +{
  12993. + int ret = -EINVAL;
  12994. + struct vchiq_mmal_port *control;
  12995. +
  12996. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  12997. +
  12998. + dev->colourfx.enable = (ctrl->val & 0xff00) >> 8;
  12999. + dev->colourfx.enable = ctrl->val & 0xff;
  13000. +
  13001. + ret = vchiq_mmal_port_parameter_set(dev->instance, control,
  13002. + MMAL_PARAMETER_COLOUR_EFFECT,
  13003. + &dev->colourfx, sizeof(dev->colourfx));
  13004. +
  13005. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  13006. + "After: mmal_ctrl:%p ctrl id:0x%x ctrl val:%d ret %d(%d)\n",
  13007. + mmal_ctrl, ctrl->id, ctrl->val, ret,
  13008. + (ret == 0 ? 0 : -EINVAL));
  13009. + return (ret == 0 ? 0 : EINVAL);
  13010. +}
  13011. +
  13012. +static int ctrl_set_bitrate(struct bm2835_mmal_dev *dev,
  13013. + struct v4l2_ctrl *ctrl,
  13014. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13015. +{
  13016. + int ret;
  13017. + struct vchiq_mmal_port *encoder_out;
  13018. +
  13019. + dev->capture.encode_bitrate = ctrl->val;
  13020. +
  13021. + encoder_out = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  13022. +
  13023. + ret = vchiq_mmal_port_parameter_set(dev->instance, encoder_out,
  13024. + mmal_ctrl->mmal_id,
  13025. + &ctrl->val, sizeof(ctrl->val));
  13026. + ret = 0;
  13027. + return ret;
  13028. +}
  13029. +
  13030. +static int ctrl_set_bitrate_mode(struct bm2835_mmal_dev *dev,
  13031. + struct v4l2_ctrl *ctrl,
  13032. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13033. +{
  13034. + u32 bitrate_mode;
  13035. + struct vchiq_mmal_port *encoder_out;
  13036. +
  13037. + encoder_out = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  13038. +
  13039. + dev->capture.encode_bitrate_mode = ctrl->val;
  13040. + switch (ctrl->val) {
  13041. + default:
  13042. + case V4L2_MPEG_VIDEO_BITRATE_MODE_VBR:
  13043. + bitrate_mode = MMAL_VIDEO_RATECONTROL_VARIABLE;
  13044. + break;
  13045. + case V4L2_MPEG_VIDEO_BITRATE_MODE_CBR:
  13046. + bitrate_mode = MMAL_VIDEO_RATECONTROL_CONSTANT;
  13047. + break;
  13048. + }
  13049. +
  13050. + vchiq_mmal_port_parameter_set(dev->instance, encoder_out,
  13051. + mmal_ctrl->mmal_id,
  13052. + &bitrate_mode,
  13053. + sizeof(bitrate_mode));
  13054. + return 0;
  13055. +}
  13056. +
  13057. +static int ctrl_set_image_encode_output(struct bm2835_mmal_dev *dev,
  13058. + struct v4l2_ctrl *ctrl,
  13059. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13060. +{
  13061. + u32 u32_value;
  13062. + struct vchiq_mmal_port *jpeg_out;
  13063. +
  13064. + jpeg_out = &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->output[0];
  13065. +
  13066. + u32_value = ctrl->val;
  13067. +
  13068. + return vchiq_mmal_port_parameter_set(dev->instance, jpeg_out,
  13069. + mmal_ctrl->mmal_id,
  13070. + &u32_value, sizeof(u32_value));
  13071. +}
  13072. +
  13073. +static int ctrl_set_video_encode_param_output(struct bm2835_mmal_dev *dev,
  13074. + struct v4l2_ctrl *ctrl,
  13075. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13076. +{
  13077. + u32 u32_value;
  13078. + struct vchiq_mmal_port *vid_enc_ctl;
  13079. +
  13080. + vid_enc_ctl = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  13081. +
  13082. + u32_value = ctrl->val;
  13083. +
  13084. + return vchiq_mmal_port_parameter_set(dev->instance, vid_enc_ctl,
  13085. + mmal_ctrl->mmal_id,
  13086. + &u32_value, sizeof(u32_value));
  13087. +}
  13088. +
  13089. +static int bm2835_mmal_s_ctrl(struct v4l2_ctrl *ctrl)
  13090. +{
  13091. + struct bm2835_mmal_dev *dev =
  13092. + container_of(ctrl->handler, struct bm2835_mmal_dev,
  13093. + ctrl_handler);
  13094. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl = ctrl->priv;
  13095. + int ret;
  13096. +
  13097. + if ((mmal_ctrl == NULL) ||
  13098. + (mmal_ctrl->id != ctrl->id) ||
  13099. + (mmal_ctrl->setter == NULL)) {
  13100. + pr_warn("mmal_ctrl:%p ctrl id:%d\n", mmal_ctrl, ctrl->id);
  13101. + return -EINVAL;
  13102. + }
  13103. +
  13104. + ret = mmal_ctrl->setter(dev, ctrl, mmal_ctrl);
  13105. + if (mmal_ctrl->ignore_errors)
  13106. + ret = 0;
  13107. + return ret;
  13108. +}
  13109. +
  13110. +static const struct v4l2_ctrl_ops bm2835_mmal_ctrl_ops = {
  13111. + .s_ctrl = bm2835_mmal_s_ctrl,
  13112. +};
  13113. +
  13114. +
  13115. +
  13116. +static const struct bm2835_mmal_v4l2_ctrl v4l2_ctrls[V4L2_CTRL_COUNT] = {
  13117. + {
  13118. + V4L2_CID_SATURATION, MMAL_CONTROL_TYPE_STD,
  13119. + -100, 100, 0, 1, NULL,
  13120. + MMAL_PARAMETER_SATURATION,
  13121. + &ctrl_set_rational,
  13122. + false
  13123. + },
  13124. + {
  13125. + V4L2_CID_SHARPNESS, MMAL_CONTROL_TYPE_STD,
  13126. + -100, 100, 0, 1, NULL,
  13127. + MMAL_PARAMETER_SHARPNESS,
  13128. + &ctrl_set_rational,
  13129. + false
  13130. + },
  13131. + {
  13132. + V4L2_CID_CONTRAST, MMAL_CONTROL_TYPE_STD,
  13133. + -100, 100, 0, 1, NULL,
  13134. + MMAL_PARAMETER_CONTRAST,
  13135. + &ctrl_set_rational,
  13136. + false
  13137. + },
  13138. + {
  13139. + V4L2_CID_BRIGHTNESS, MMAL_CONTROL_TYPE_STD,
  13140. + 0, 100, 50, 1, NULL,
  13141. + MMAL_PARAMETER_BRIGHTNESS,
  13142. + &ctrl_set_rational,
  13143. + false
  13144. + },
  13145. + {
  13146. + V4L2_CID_ISO_SENSITIVITY, MMAL_CONTROL_TYPE_INT_MENU,
  13147. + 0, ARRAY_SIZE(iso_qmenu) - 1, 0, 1, iso_qmenu,
  13148. + MMAL_PARAMETER_ISO,
  13149. + &ctrl_set_value_menu,
  13150. + false
  13151. + },
  13152. + {
  13153. + V4L2_CID_IMAGE_STABILIZATION, MMAL_CONTROL_TYPE_STD,
  13154. + 0, 1, 0, 1, NULL,
  13155. + MMAL_PARAMETER_VIDEO_STABILISATION,
  13156. + &ctrl_set_value,
  13157. + false
  13158. + },
  13159. +/* {
  13160. + 0, MMAL_CONTROL_TYPE_CLUSTER, 3, 1, 0, NULL, 0, NULL
  13161. + },
  13162. +*/ {
  13163. + V4L2_CID_EXPOSURE_AUTO, MMAL_CONTROL_TYPE_STD_MENU,
  13164. + ~0x03, 3, V4L2_EXPOSURE_AUTO, 0, NULL,
  13165. + MMAL_PARAMETER_EXPOSURE_MODE,
  13166. + &ctrl_set_exposure,
  13167. + false
  13168. + },
  13169. +/* todo this needs mixing in with set exposure
  13170. + {
  13171. + V4L2_CID_SCENE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
  13172. + },
  13173. + */
  13174. + {
  13175. + V4L2_CID_EXPOSURE_ABSOLUTE, MMAL_CONTROL_TYPE_STD,
  13176. + /* Units of 100usecs */
  13177. + 1, 1*1000*10, 100*10, 1, NULL,
  13178. + MMAL_PARAMETER_SHUTTER_SPEED,
  13179. + &ctrl_set_exposure,
  13180. + false
  13181. + },
  13182. + {
  13183. + V4L2_CID_AUTO_EXPOSURE_BIAS, MMAL_CONTROL_TYPE_INT_MENU,
  13184. + 0, ARRAY_SIZE(ev_bias_qmenu) - 1,
  13185. + (ARRAY_SIZE(ev_bias_qmenu)+1)/2 - 1, 0, ev_bias_qmenu,
  13186. + MMAL_PARAMETER_EXPOSURE_COMP,
  13187. + &ctrl_set_value_ev,
  13188. + false
  13189. + },
  13190. + {
  13191. + V4L2_CID_EXPOSURE_METERING,
  13192. + MMAL_CONTROL_TYPE_STD_MENU,
  13193. + ~0x7, 2, V4L2_EXPOSURE_METERING_AVERAGE, 0, NULL,
  13194. + MMAL_PARAMETER_EXP_METERING_MODE,
  13195. + &ctrl_set_metering_mode,
  13196. + false
  13197. + },
  13198. + {
  13199. + V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE,
  13200. + MMAL_CONTROL_TYPE_STD_MENU,
  13201. + ~0x3fe, 9, V4L2_WHITE_BALANCE_AUTO, 0, NULL,
  13202. + MMAL_PARAMETER_AWB_MODE,
  13203. + &ctrl_set_awb_mode,
  13204. + false
  13205. + },
  13206. + {
  13207. + V4L2_CID_COLORFX, MMAL_CONTROL_TYPE_STD_MENU,
  13208. + 0, 15, V4L2_COLORFX_NONE, 0, NULL,
  13209. + MMAL_PARAMETER_IMAGE_EFFECT,
  13210. + &ctrl_set_image_effect,
  13211. + false
  13212. + },
  13213. + {
  13214. + V4L2_CID_COLORFX_CBCR, MMAL_CONTROL_TYPE_STD,
  13215. + 0, 0xffff, 0x8080, 1, NULL,
  13216. + MMAL_PARAMETER_COLOUR_EFFECT,
  13217. + &ctrl_set_colfx,
  13218. + false
  13219. + },
  13220. + {
  13221. + V4L2_CID_ROTATE, MMAL_CONTROL_TYPE_STD,
  13222. + 0, 360, 0, 90, NULL,
  13223. + MMAL_PARAMETER_ROTATION,
  13224. + &ctrl_set_rotate,
  13225. + false
  13226. + },
  13227. + {
  13228. + V4L2_CID_HFLIP, MMAL_CONTROL_TYPE_STD,
  13229. + 0, 1, 0, 1, NULL,
  13230. + MMAL_PARAMETER_MIRROR,
  13231. + &ctrl_set_flip,
  13232. + false
  13233. + },
  13234. + {
  13235. + V4L2_CID_VFLIP, MMAL_CONTROL_TYPE_STD,
  13236. + 0, 1, 0, 1, NULL,
  13237. + MMAL_PARAMETER_MIRROR,
  13238. + &ctrl_set_flip,
  13239. + false
  13240. + },
  13241. + {
  13242. + V4L2_CID_MPEG_VIDEO_BITRATE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
  13243. + 0, ARRAY_SIZE(bitrate_mode_qmenu) - 1,
  13244. + 0, 0, bitrate_mode_qmenu,
  13245. + MMAL_PARAMETER_RATECONTROL,
  13246. + &ctrl_set_bitrate_mode,
  13247. + false
  13248. + },
  13249. + {
  13250. + V4L2_CID_MPEG_VIDEO_BITRATE, MMAL_CONTROL_TYPE_STD,
  13251. + 25*1000, 25*1000*1000, 10*1000*1000, 25*1000, NULL,
  13252. + MMAL_PARAMETER_VIDEO_BIT_RATE,
  13253. + &ctrl_set_bitrate,
  13254. + false
  13255. + },
  13256. + {
  13257. + V4L2_CID_JPEG_COMPRESSION_QUALITY, MMAL_CONTROL_TYPE_STD,
  13258. + 1, 100,
  13259. + 30, 1, NULL,
  13260. + MMAL_PARAMETER_JPEG_Q_FACTOR,
  13261. + &ctrl_set_image_encode_output,
  13262. + false
  13263. + },
  13264. + {
  13265. + V4L2_CID_POWER_LINE_FREQUENCY, MMAL_CONTROL_TYPE_STD_MENU,
  13266. + 0, ARRAY_SIZE(mains_freq_qmenu) - 1,
  13267. + 1, 1, NULL,
  13268. + MMAL_PARAMETER_FLICKER_AVOID,
  13269. + &ctrl_set_flicker_avoidance,
  13270. + false
  13271. + },
  13272. + {
  13273. + V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER, MMAL_CONTROL_TYPE_STD,
  13274. + 0, 1,
  13275. + 0, 1, NULL,
  13276. + MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER,
  13277. + &ctrl_set_video_encode_param_output,
  13278. + true /* Errors ignored as requires latest firmware to work */
  13279. + },
  13280. +};
  13281. +
  13282. +int bm2835_mmal_set_all_camera_controls(struct bm2835_mmal_dev *dev)
  13283. +{
  13284. + int c;
  13285. + int ret = 0;
  13286. +
  13287. + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
  13288. + if ((dev->ctrls[c]) && (v4l2_ctrls[c].setter)) {
  13289. + ret = v4l2_ctrls[c].setter(dev, dev->ctrls[c],
  13290. + &v4l2_ctrls[c]);
  13291. + if (!v4l2_ctrls[c]. ignore_errors && ret)
  13292. + break;
  13293. + }
  13294. + }
  13295. + return ret;
  13296. +}
  13297. +
  13298. +int bm2835_mmal_init_controls(struct bm2835_mmal_dev *dev,
  13299. + struct v4l2_ctrl_handler *hdl)
  13300. +{
  13301. + int c;
  13302. + const struct bm2835_mmal_v4l2_ctrl *ctrl;
  13303. +
  13304. + v4l2_ctrl_handler_init(hdl, V4L2_CTRL_COUNT);
  13305. +
  13306. + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
  13307. + ctrl = &v4l2_ctrls[c];
  13308. +
  13309. + switch (ctrl->type) {
  13310. + case MMAL_CONTROL_TYPE_STD:
  13311. + dev->ctrls[c] = v4l2_ctrl_new_std(hdl,
  13312. + &bm2835_mmal_ctrl_ops, ctrl->id,
  13313. + ctrl->min, ctrl->max, ctrl->step, ctrl->def);
  13314. + break;
  13315. +
  13316. + case MMAL_CONTROL_TYPE_STD_MENU:
  13317. + dev->ctrls[c] = v4l2_ctrl_new_std_menu(hdl,
  13318. + &bm2835_mmal_ctrl_ops, ctrl->id,
  13319. + ctrl->max, ctrl->min, ctrl->def);
  13320. + break;
  13321. +
  13322. + case MMAL_CONTROL_TYPE_INT_MENU:
  13323. + dev->ctrls[c] = v4l2_ctrl_new_int_menu(hdl,
  13324. + &bm2835_mmal_ctrl_ops, ctrl->id,
  13325. + ctrl->max, ctrl->def, ctrl->imenu);
  13326. + break;
  13327. +
  13328. + case MMAL_CONTROL_TYPE_CLUSTER:
  13329. + /* skip this entry when constructing controls */
  13330. + continue;
  13331. + }
  13332. +
  13333. + if (hdl->error)
  13334. + break;
  13335. +
  13336. + dev->ctrls[c]->priv = (void *)ctrl;
  13337. + }
  13338. +
  13339. + if (hdl->error) {
  13340. + pr_err("error adding control %d/%d id 0x%x\n", c,
  13341. + V4L2_CTRL_COUNT, ctrl->id);
  13342. + return hdl->error;
  13343. + }
  13344. +
  13345. + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
  13346. + ctrl = &v4l2_ctrls[c];
  13347. +
  13348. + switch (ctrl->type) {
  13349. + case MMAL_CONTROL_TYPE_CLUSTER:
  13350. + v4l2_ctrl_auto_cluster(ctrl->min,
  13351. + &dev->ctrls[c+1],
  13352. + ctrl->max,
  13353. + ctrl->def);
  13354. + break;
  13355. +
  13356. + case MMAL_CONTROL_TYPE_STD:
  13357. + case MMAL_CONTROL_TYPE_STD_MENU:
  13358. + case MMAL_CONTROL_TYPE_INT_MENU:
  13359. + break;
  13360. + }
  13361. +
  13362. + }
  13363. +
  13364. + return 0;
  13365. +}
  13366. diff -Nur linux-3.13.3.orig/drivers/media/platform/bcm2835/Kconfig linux-3.13.3/drivers/media/platform/bcm2835/Kconfig
  13367. --- linux-3.13.3.orig/drivers/media/platform/bcm2835/Kconfig 1970-01-01 01:00:00.000000000 +0100
  13368. +++ linux-3.13.3/drivers/media/platform/bcm2835/Kconfig 2014-02-17 22:41:01.000000000 +0100
  13369. @@ -0,0 +1,25 @@
  13370. +# Broadcom VideoCore IV v4l2 camera support
  13371. +
  13372. +config VIDEO_BCM2835
  13373. + bool "Broadcom BCM2835 camera interface driver"
  13374. + depends on VIDEO_V4L2 && ARCH_BCM2708
  13375. + ---help---
  13376. + Say Y here to enable camera host interface devices for
  13377. + Broadcom BCM2835 SoC. This operates over the VCHIQ interface
  13378. + to a service running on VideoCore.
  13379. +
  13380. +
  13381. +if VIDEO_BCM2835
  13382. +
  13383. +config VIDEO_BCM2835_MMAL
  13384. + tristate "Broadcom BM2835 MMAL camera interface driver"
  13385. + depends on BCM2708_VCHIQ
  13386. + select VIDEOBUF2_VMALLOC
  13387. + ---help---
  13388. + This is a V4L2 driver for the Broadcom BCM2835 MMAL camera host interface
  13389. +
  13390. + To compile this driver as a module, choose M here: the
  13391. + module will be called bcm2835-v4l2.o
  13392. +
  13393. +
  13394. +endif # VIDEO_BM2835
  13395. diff -Nur linux-3.13.3.orig/drivers/media/platform/bcm2835/Makefile linux-3.13.3/drivers/media/platform/bcm2835/Makefile
  13396. --- linux-3.13.3.orig/drivers/media/platform/bcm2835/Makefile 1970-01-01 01:00:00.000000000 +0100
  13397. +++ linux-3.13.3/drivers/media/platform/bcm2835/Makefile 2014-02-17 22:41:01.000000000 +0100
  13398. @@ -0,0 +1,5 @@
  13399. +bcm2835-v4l2-objs := bcm2835-camera.o controls.o mmal-vchiq.o
  13400. +
  13401. +obj-$(CONFIG_VIDEO_BCM2835_MMAL) += bcm2835-v4l2.o
  13402. +
  13403. +ccflags-$(CONFIG_VIDEO_BCM2835) += -Idrivers/misc/vc04_services -Idrivers/misc/vc04_services/interface/vcos/linuxkernel -D__VCCOREVER__=0x04000000
  13404. diff -Nur linux-3.13.3.orig/drivers/media/platform/bcm2835/mmal-common.h linux-3.13.3/drivers/media/platform/bcm2835/mmal-common.h
  13405. --- linux-3.13.3.orig/drivers/media/platform/bcm2835/mmal-common.h 1970-01-01 01:00:00.000000000 +0100
  13406. +++ linux-3.13.3/drivers/media/platform/bcm2835/mmal-common.h 2014-02-17 22:41:01.000000000 +0100
  13407. @@ -0,0 +1,52 @@
  13408. +/*
  13409. + * Broadcom BM2835 V4L2 driver
  13410. + *
  13411. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  13412. + *
  13413. + * This file is subject to the terms and conditions of the GNU General Public
  13414. + * License. See the file COPYING in the main directory of this archive
  13415. + * for more details.
  13416. + *
  13417. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  13418. + * Dave Stevenson <dsteve@broadcom.com>
  13419. + * Simon Mellor <simellor@broadcom.com>
  13420. + * Luke Diamand <luked@broadcom.com>
  13421. + *
  13422. + * MMAL structures
  13423. + *
  13424. + */
  13425. +
  13426. +#define MMAL_FOURCC(a, b, c, d) ((a) | (b << 8) | (c << 16) | (d << 24))
  13427. +#define MMAL_MAGIC MMAL_FOURCC('m', 'm', 'a', 'l')
  13428. +
  13429. +/** Special value signalling that time is not known */
  13430. +#define MMAL_TIME_UNKNOWN (1LL<<63)
  13431. +
  13432. +/* mapping between v4l and mmal video modes */
  13433. +struct mmal_fmt {
  13434. + char *name;
  13435. + u32 fourcc; /* v4l2 format id */
  13436. + u32 mmal;
  13437. + int depth;
  13438. + u32 mmal_component; /* MMAL component index to be used to encode */
  13439. +};
  13440. +
  13441. +/* buffer for one video frame */
  13442. +struct mmal_buffer {
  13443. + /* v4l buffer data -- must be first */
  13444. + struct vb2_buffer vb;
  13445. +
  13446. + /* list of buffers available */
  13447. + struct list_head list;
  13448. +
  13449. + void *buffer; /* buffer pointer */
  13450. + unsigned long buffer_size; /* size of allocated buffer */
  13451. +};
  13452. +
  13453. +/* */
  13454. +struct mmal_colourfx {
  13455. + s32 enable;
  13456. + u32 u;
  13457. + u32 v;
  13458. +};
  13459. +
  13460. diff -Nur linux-3.13.3.orig/drivers/media/platform/bcm2835/mmal-encodings.h linux-3.13.3/drivers/media/platform/bcm2835/mmal-encodings.h
  13461. --- linux-3.13.3.orig/drivers/media/platform/bcm2835/mmal-encodings.h 1970-01-01 01:00:00.000000000 +0100
  13462. +++ linux-3.13.3/drivers/media/platform/bcm2835/mmal-encodings.h 2014-02-17 22:41:01.000000000 +0100
  13463. @@ -0,0 +1,93 @@
  13464. +/*
  13465. + * Broadcom BM2835 V4L2 driver
  13466. + *
  13467. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  13468. + *
  13469. + * This file is subject to the terms and conditions of the GNU General Public
  13470. + * License. See the file COPYING in the main directory of this archive
  13471. + * for more details.
  13472. + *
  13473. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  13474. + * Dave Stevenson <dsteve@broadcom.com>
  13475. + * Simon Mellor <simellor@broadcom.com>
  13476. + * Luke Diamand <luked@broadcom.com>
  13477. + */
  13478. +
  13479. +#define MMAL_ENCODING_H264 MMAL_FOURCC('H', '2', '6', '4')
  13480. +#define MMAL_ENCODING_H263 MMAL_FOURCC('H', '2', '6', '3')
  13481. +#define MMAL_ENCODING_MP4V MMAL_FOURCC('M', 'P', '4', 'V')
  13482. +#define MMAL_ENCODING_MP2V MMAL_FOURCC('M', 'P', '2', 'V')
  13483. +#define MMAL_ENCODING_MP1V MMAL_FOURCC('M', 'P', '1', 'V')
  13484. +#define MMAL_ENCODING_WMV3 MMAL_FOURCC('W', 'M', 'V', '3')
  13485. +#define MMAL_ENCODING_WMV2 MMAL_FOURCC('W', 'M', 'V', '2')
  13486. +#define MMAL_ENCODING_WMV1 MMAL_FOURCC('W', 'M', 'V', '1')
  13487. +#define MMAL_ENCODING_WVC1 MMAL_FOURCC('W', 'V', 'C', '1')
  13488. +#define MMAL_ENCODING_VP8 MMAL_FOURCC('V', 'P', '8', ' ')
  13489. +#define MMAL_ENCODING_VP7 MMAL_FOURCC('V', 'P', '7', ' ')
  13490. +#define MMAL_ENCODING_VP6 MMAL_FOURCC('V', 'P', '6', ' ')
  13491. +#define MMAL_ENCODING_THEORA MMAL_FOURCC('T', 'H', 'E', 'O')
  13492. +#define MMAL_ENCODING_SPARK MMAL_FOURCC('S', 'P', 'R', 'K')
  13493. +
  13494. +#define MMAL_ENCODING_JPEG MMAL_FOURCC('J', 'P', 'E', 'G')
  13495. +#define MMAL_ENCODING_GIF MMAL_FOURCC('G', 'I', 'F', ' ')
  13496. +#define MMAL_ENCODING_PNG MMAL_FOURCC('P', 'N', 'G', ' ')
  13497. +#define MMAL_ENCODING_PPM MMAL_FOURCC('P', 'P', 'M', ' ')
  13498. +#define MMAL_ENCODING_TGA MMAL_FOURCC('T', 'G', 'A', ' ')
  13499. +#define MMAL_ENCODING_BMP MMAL_FOURCC('B', 'M', 'P', ' ')
  13500. +
  13501. +#define MMAL_ENCODING_I420 MMAL_FOURCC('I', '4', '2', '0')
  13502. +#define MMAL_ENCODING_I420_SLICE MMAL_FOURCC('S', '4', '2', '0')
  13503. +#define MMAL_ENCODING_YV12 MMAL_FOURCC('Y', 'V', '1', '2')
  13504. +#define MMAL_ENCODING_I422 MMAL_FOURCC('I', '4', '2', '2')
  13505. +#define MMAL_ENCODING_I422_SLICE MMAL_FOURCC('S', '4', '2', '2')
  13506. +#define MMAL_ENCODING_YUYV MMAL_FOURCC('Y', 'U', 'Y', 'V')
  13507. +#define MMAL_ENCODING_YVYU MMAL_FOURCC('Y', 'V', 'Y', 'U')
  13508. +#define MMAL_ENCODING_UYVY MMAL_FOURCC('U', 'Y', 'V', 'Y')
  13509. +#define MMAL_ENCODING_VYUY MMAL_FOURCC('V', 'Y', 'U', 'Y')
  13510. +#define MMAL_ENCODING_NV12 MMAL_FOURCC('N', 'V', '1', '2')
  13511. +#define MMAL_ENCODING_NV21 MMAL_FOURCC('N', 'V', '2', '1')
  13512. +#define MMAL_ENCODING_ARGB MMAL_FOURCC('A', 'R', 'G', 'B')
  13513. +#define MMAL_ENCODING_RGBA MMAL_FOURCC('R', 'G', 'B', 'A')
  13514. +#define MMAL_ENCODING_ABGR MMAL_FOURCC('A', 'B', 'G', 'R')
  13515. +#define MMAL_ENCODING_BGRA MMAL_FOURCC('B', 'G', 'R', 'A')
  13516. +#define MMAL_ENCODING_RGB16 MMAL_FOURCC('R', 'G', 'B', '2')
  13517. +#define MMAL_ENCODING_RGB24 MMAL_FOURCC('R', 'G', 'B', '3')
  13518. +#define MMAL_ENCODING_RGB32 MMAL_FOURCC('R', 'G', 'B', '4')
  13519. +#define MMAL_ENCODING_BGR16 MMAL_FOURCC('B', 'G', 'R', '2')
  13520. +#define MMAL_ENCODING_BGR24 MMAL_FOURCC('B', 'G', 'R', '3')
  13521. +#define MMAL_ENCODING_BGR32 MMAL_FOURCC('B', 'G', 'R', '4')
  13522. +
  13523. +/** SAND Video (YUVUV128) format, native format understood by VideoCore.
  13524. + * This format is *not* opaque - if requested you will receive full frames
  13525. + * of YUV_UV video.
  13526. + */
  13527. +#define MMAL_ENCODING_YUVUV128 MMAL_FOURCC('S', 'A', 'N', 'D')
  13528. +
  13529. +/** VideoCore opaque image format, image handles are returned to
  13530. + * the host but not the actual image data.
  13531. + */
  13532. +#define MMAL_ENCODING_OPAQUE MMAL_FOURCC('O', 'P', 'Q', 'V')
  13533. +
  13534. +/** An EGL image handle
  13535. + */
  13536. +#define MMAL_ENCODING_EGL_IMAGE MMAL_FOURCC('E', 'G', 'L', 'I')
  13537. +
  13538. +/* }@ */
  13539. +
  13540. +/** \name Pre-defined audio encodings */
  13541. +/* @{ */
  13542. +#define MMAL_ENCODING_PCM_UNSIGNED_BE MMAL_FOURCC('P', 'C', 'M', 'U')
  13543. +#define MMAL_ENCODING_PCM_UNSIGNED_LE MMAL_FOURCC('p', 'c', 'm', 'u')
  13544. +#define MMAL_ENCODING_PCM_SIGNED_BE MMAL_FOURCC('P', 'C', 'M', 'S')
  13545. +#define MMAL_ENCODING_PCM_SIGNED_LE MMAL_FOURCC('p', 'c', 'm', 's')
  13546. +#define MMAL_ENCODING_PCM_FLOAT_BE MMAL_FOURCC('P', 'C', 'M', 'F')
  13547. +#define MMAL_ENCODING_PCM_FLOAT_LE MMAL_FOURCC('p', 'c', 'm', 'f')
  13548. +
  13549. +/* Pre-defined H264 encoding variants */
  13550. +
  13551. +/** ISO 14496-10 Annex B byte stream format */
  13552. +#define MMAL_ENCODING_VARIANT_H264_DEFAULT 0
  13553. +/** ISO 14496-15 AVC stream format */
  13554. +#define MMAL_ENCODING_VARIANT_H264_AVC1 MMAL_FOURCC('A', 'V', 'C', '1')
  13555. +/** Implicitly delineated NAL units without emulation prevention */
  13556. +#define MMAL_ENCODING_VARIANT_H264_RAW MMAL_FOURCC('R', 'A', 'W', ' ')
  13557. diff -Nur linux-3.13.3.orig/drivers/media/platform/bcm2835/mmal-msg-common.h linux-3.13.3/drivers/media/platform/bcm2835/mmal-msg-common.h
  13558. --- linux-3.13.3.orig/drivers/media/platform/bcm2835/mmal-msg-common.h 1970-01-01 01:00:00.000000000 +0100
  13559. +++ linux-3.13.3/drivers/media/platform/bcm2835/mmal-msg-common.h 2014-02-17 22:41:01.000000000 +0100
  13560. @@ -0,0 +1,50 @@
  13561. +/*
  13562. + * Broadcom BM2835 V4L2 driver
  13563. + *
  13564. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  13565. + *
  13566. + * This file is subject to the terms and conditions of the GNU General Public
  13567. + * License. See the file COPYING in the main directory of this archive
  13568. + * for more details.
  13569. + *
  13570. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  13571. + * Dave Stevenson <dsteve@broadcom.com>
  13572. + * Simon Mellor <simellor@broadcom.com>
  13573. + * Luke Diamand <luked@broadcom.com>
  13574. + */
  13575. +
  13576. +#ifndef MMAL_MSG_COMMON_H
  13577. +#define MMAL_MSG_COMMON_H
  13578. +
  13579. +enum mmal_msg_status {
  13580. + MMAL_MSG_STATUS_SUCCESS = 0, /**< Success */
  13581. + MMAL_MSG_STATUS_ENOMEM, /**< Out of memory */
  13582. + MMAL_MSG_STATUS_ENOSPC, /**< Out of resources other than memory */
  13583. + MMAL_MSG_STATUS_EINVAL, /**< Argument is invalid */
  13584. + MMAL_MSG_STATUS_ENOSYS, /**< Function not implemented */
  13585. + MMAL_MSG_STATUS_ENOENT, /**< No such file or directory */
  13586. + MMAL_MSG_STATUS_ENXIO, /**< No such device or address */
  13587. + MMAL_MSG_STATUS_EIO, /**< I/O error */
  13588. + MMAL_MSG_STATUS_ESPIPE, /**< Illegal seek */
  13589. + MMAL_MSG_STATUS_ECORRUPT, /**< Data is corrupt \attention */
  13590. + MMAL_MSG_STATUS_ENOTREADY, /**< Component is not ready */
  13591. + MMAL_MSG_STATUS_ECONFIG, /**< Component is not configured */
  13592. + MMAL_MSG_STATUS_EISCONN, /**< Port is already connected */
  13593. + MMAL_MSG_STATUS_ENOTCONN, /**< Port is disconnected */
  13594. + MMAL_MSG_STATUS_EAGAIN, /**< Resource temporarily unavailable. */
  13595. + MMAL_MSG_STATUS_EFAULT, /**< Bad address */
  13596. +};
  13597. +
  13598. +struct mmal_rect {
  13599. + s32 x; /**< x coordinate (from left) */
  13600. + s32 y; /**< y coordinate (from top) */
  13601. + s32 width; /**< width */
  13602. + s32 height; /**< height */
  13603. +};
  13604. +
  13605. +struct mmal_rational {
  13606. + s32 num; /**< Numerator */
  13607. + s32 den; /**< Denominator */
  13608. +};
  13609. +
  13610. +#endif /* MMAL_MSG_COMMON_H */
  13611. diff -Nur linux-3.13.3.orig/drivers/media/platform/bcm2835/mmal-msg-format.h linux-3.13.3/drivers/media/platform/bcm2835/mmal-msg-format.h
  13612. --- linux-3.13.3.orig/drivers/media/platform/bcm2835/mmal-msg-format.h 1970-01-01 01:00:00.000000000 +0100
  13613. +++ linux-3.13.3/drivers/media/platform/bcm2835/mmal-msg-format.h 2014-02-17 22:41:01.000000000 +0100
  13614. @@ -0,0 +1,81 @@
  13615. +/*
  13616. + * Broadcom BM2835 V4L2 driver
  13617. + *
  13618. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  13619. + *
  13620. + * This file is subject to the terms and conditions of the GNU General Public
  13621. + * License. See the file COPYING in the main directory of this archive
  13622. + * for more details.
  13623. + *
  13624. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  13625. + * Dave Stevenson <dsteve@broadcom.com>
  13626. + * Simon Mellor <simellor@broadcom.com>
  13627. + * Luke Diamand <luked@broadcom.com>
  13628. + */
  13629. +
  13630. +#ifndef MMAL_MSG_FORMAT_H
  13631. +#define MMAL_MSG_FORMAT_H
  13632. +
  13633. +#include "mmal-msg-common.h"
  13634. +
  13635. +/* MMAL_ES_FORMAT_T */
  13636. +
  13637. +
  13638. +struct mmal_audio_format {
  13639. + u32 channels; /**< Number of audio channels */
  13640. + u32 sample_rate; /**< Sample rate */
  13641. +
  13642. + u32 bits_per_sample; /**< Bits per sample */
  13643. + u32 block_align; /**< Size of a block of data */
  13644. +};
  13645. +
  13646. +struct mmal_video_format {
  13647. + u32 width; /**< Width of frame in pixels */
  13648. + u32 height; /**< Height of frame in rows of pixels */
  13649. + struct mmal_rect crop; /**< Visible region of the frame */
  13650. + struct mmal_rational frame_rate; /**< Frame rate */
  13651. + struct mmal_rational par; /**< Pixel aspect ratio */
  13652. +
  13653. + /* FourCC specifying the color space of the video stream. See the
  13654. + * \ref MmalColorSpace "pre-defined color spaces" for some examples.
  13655. + */
  13656. + u32 color_space;
  13657. +};
  13658. +
  13659. +struct mmal_subpicture_format {
  13660. + u32 x_offset;
  13661. + u32 y_offset;
  13662. +};
  13663. +
  13664. +union mmal_es_specific_format {
  13665. + struct mmal_audio_format audio;
  13666. + struct mmal_video_format video;
  13667. + struct mmal_subpicture_format subpicture;
  13668. +};
  13669. +
  13670. +/** Definition of an elementary stream format (MMAL_ES_FORMAT_T) */
  13671. +struct mmal_es_format {
  13672. + u32 type; /* enum mmal_es_type */
  13673. +
  13674. + u32 encoding; /* FourCC specifying encoding of the elementary stream.*/
  13675. + u32 encoding_variant; /* FourCC specifying the specific
  13676. + * encoding variant of the elementary
  13677. + * stream.
  13678. + */
  13679. +
  13680. + union mmal_es_specific_format *es; /* TODO: pointers in
  13681. + * message serialisation?!?
  13682. + */
  13683. + /* Type specific
  13684. + * information for the
  13685. + * elementary stream
  13686. + */
  13687. +
  13688. + u32 bitrate; /**< Bitrate in bits per second */
  13689. + u32 flags; /**< Flags describing properties of the elementary stream. */
  13690. +
  13691. + u32 extradata_size; /**< Size of the codec specific data */
  13692. + u8 *extradata; /**< Codec specific data */
  13693. +};
  13694. +
  13695. +#endif /* MMAL_MSG_FORMAT_H */
  13696. diff -Nur linux-3.13.3.orig/drivers/media/platform/bcm2835/mmal-msg.h linux-3.13.3/drivers/media/platform/bcm2835/mmal-msg.h
  13697. --- linux-3.13.3.orig/drivers/media/platform/bcm2835/mmal-msg.h 1970-01-01 01:00:00.000000000 +0100
  13698. +++ linux-3.13.3/drivers/media/platform/bcm2835/mmal-msg.h 2014-02-17 22:41:01.000000000 +0100
  13699. @@ -0,0 +1,404 @@
  13700. +/*
  13701. + * Broadcom BM2835 V4L2 driver
  13702. + *
  13703. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  13704. + *
  13705. + * This file is subject to the terms and conditions of the GNU General Public
  13706. + * License. See the file COPYING in the main directory of this archive
  13707. + * for more details.
  13708. + *
  13709. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  13710. + * Dave Stevenson <dsteve@broadcom.com>
  13711. + * Simon Mellor <simellor@broadcom.com>
  13712. + * Luke Diamand <luked@broadcom.com>
  13713. + */
  13714. +
  13715. +/* all the data structures which serialise the MMAL protocol. note
  13716. + * these are directly mapped onto the recived message data.
  13717. + *
  13718. + * BEWARE: They seem to *assume* pointers are u32 and that there is no
  13719. + * structure padding!
  13720. + *
  13721. + * NOTE: this implementation uses kernel types to ensure sizes. Rather
  13722. + * than assigning values to enums to force their size the
  13723. + * implementation uses fixed size types and not the enums (though the
  13724. + * comments have the actual enum type
  13725. + */
  13726. +
  13727. +#define VC_MMAL_VER 15
  13728. +#define VC_MMAL_MIN_VER 10
  13729. +#define VC_MMAL_SERVER_NAME MAKE_FOURCC("mmal")
  13730. +
  13731. +/* max total message size is 512 bytes */
  13732. +#define MMAL_MSG_MAX_SIZE 512
  13733. +/* with six 32bit header elements max payload is therefore 488 bytes */
  13734. +#define MMAL_MSG_MAX_PAYLOAD 488
  13735. +
  13736. +#include "mmal-msg-common.h"
  13737. +#include "mmal-msg-format.h"
  13738. +#include "mmal-msg-port.h"
  13739. +
  13740. +enum mmal_msg_type {
  13741. + MMAL_MSG_TYPE_QUIT = 1,
  13742. + MMAL_MSG_TYPE_SERVICE_CLOSED,
  13743. + MMAL_MSG_TYPE_GET_VERSION,
  13744. + MMAL_MSG_TYPE_COMPONENT_CREATE,
  13745. + MMAL_MSG_TYPE_COMPONENT_DESTROY, /* 5 */
  13746. + MMAL_MSG_TYPE_COMPONENT_ENABLE,
  13747. + MMAL_MSG_TYPE_COMPONENT_DISABLE,
  13748. + MMAL_MSG_TYPE_PORT_INFO_GET,
  13749. + MMAL_MSG_TYPE_PORT_INFO_SET,
  13750. + MMAL_MSG_TYPE_PORT_ACTION, /* 10 */
  13751. + MMAL_MSG_TYPE_BUFFER_FROM_HOST,
  13752. + MMAL_MSG_TYPE_BUFFER_TO_HOST,
  13753. + MMAL_MSG_TYPE_GET_STATS,
  13754. + MMAL_MSG_TYPE_PORT_PARAMETER_SET,
  13755. + MMAL_MSG_TYPE_PORT_PARAMETER_GET, /* 15 */
  13756. + MMAL_MSG_TYPE_EVENT_TO_HOST,
  13757. + MMAL_MSG_TYPE_GET_CORE_STATS_FOR_PORT,
  13758. + MMAL_MSG_TYPE_OPAQUE_ALLOCATOR,
  13759. + MMAL_MSG_TYPE_CONSUME_MEM,
  13760. + MMAL_MSG_TYPE_LMK, /* 20 */
  13761. + MMAL_MSG_TYPE_OPAQUE_ALLOCATOR_DESC,
  13762. + MMAL_MSG_TYPE_DRM_GET_LHS32,
  13763. + MMAL_MSG_TYPE_DRM_GET_TIME,
  13764. + MMAL_MSG_TYPE_BUFFER_FROM_HOST_ZEROLEN,
  13765. + MMAL_MSG_TYPE_PORT_FLUSH, /* 25 */
  13766. + MMAL_MSG_TYPE_HOST_LOG,
  13767. + MMAL_MSG_TYPE_MSG_LAST
  13768. +};
  13769. +
  13770. +/* port action request messages differ depending on the action type */
  13771. +enum mmal_msg_port_action_type {
  13772. + MMAL_MSG_PORT_ACTION_TYPE_UNKNOWN = 0, /* Unkown action */
  13773. + MMAL_MSG_PORT_ACTION_TYPE_ENABLE, /* Enable a port */
  13774. + MMAL_MSG_PORT_ACTION_TYPE_DISABLE, /* Disable a port */
  13775. + MMAL_MSG_PORT_ACTION_TYPE_FLUSH, /* Flush a port */
  13776. + MMAL_MSG_PORT_ACTION_TYPE_CONNECT, /* Connect ports */
  13777. + MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT, /* Disconnect ports */
  13778. + MMAL_MSG_PORT_ACTION_TYPE_SET_REQUIREMENTS, /* Set buffer requirements*/
  13779. +};
  13780. +
  13781. +struct mmal_msg_header {
  13782. + u32 magic;
  13783. + u32 type; /** enum mmal_msg_type */
  13784. +
  13785. + /* Opaque handle to the control service */
  13786. + struct mmal_control_service *control_service;
  13787. +
  13788. + struct mmal_msg_context *context; /** a u32 per message context */
  13789. + u32 status; /** The status of the vchiq operation */
  13790. + u32 padding;
  13791. +};
  13792. +
  13793. +/* Send from VC to host to report version */
  13794. +struct mmal_msg_version {
  13795. + u32 flags;
  13796. + u32 major;
  13797. + u32 minor;
  13798. + u32 minimum;
  13799. +};
  13800. +
  13801. +/* request to VC to create component */
  13802. +struct mmal_msg_component_create {
  13803. + void *client_component; /* component context */
  13804. + char name[128];
  13805. + u32 pid; /* For debug */
  13806. +};
  13807. +
  13808. +/* reply from VC to component creation request */
  13809. +struct mmal_msg_component_create_reply {
  13810. + u32 status; /** enum mmal_msg_status - how does this differ to
  13811. + * the one in the header?
  13812. + */
  13813. + u32 component_handle; /* VideoCore handle for component */
  13814. + u32 input_num; /* Number of input ports */
  13815. + u32 output_num; /* Number of output ports */
  13816. + u32 clock_num; /* Number of clock ports */
  13817. +};
  13818. +
  13819. +/* request to VC to destroy a component */
  13820. +struct mmal_msg_component_destroy {
  13821. + u32 component_handle;
  13822. +};
  13823. +
  13824. +struct mmal_msg_component_destroy_reply {
  13825. + u32 status; /** The component destruction status */
  13826. +};
  13827. +
  13828. +
  13829. +/* request and reply to VC to enable a component */
  13830. +struct mmal_msg_component_enable {
  13831. + u32 component_handle;
  13832. +};
  13833. +
  13834. +struct mmal_msg_component_enable_reply {
  13835. + u32 status; /** The component enable status */
  13836. +};
  13837. +
  13838. +
  13839. +/* request and reply to VC to disable a component */
  13840. +struct mmal_msg_component_disable {
  13841. + u32 component_handle;
  13842. +};
  13843. +
  13844. +struct mmal_msg_component_disable_reply {
  13845. + u32 status; /** The component disable status */
  13846. +};
  13847. +
  13848. +/* request to VC to get port information */
  13849. +struct mmal_msg_port_info_get {
  13850. + u32 component_handle; /* component handle port is associated with */
  13851. + u32 port_type; /* enum mmal_msg_port_type */
  13852. + u32 index; /* port index to query */
  13853. +};
  13854. +
  13855. +/* reply from VC to get port info request */
  13856. +struct mmal_msg_port_info_get_reply {
  13857. + u32 status; /** enum mmal_msg_status */
  13858. + u32 component_handle; /* component handle port is associated with */
  13859. + u32 port_type; /* enum mmal_msg_port_type */
  13860. + u32 port_index; /* port indexed in query */
  13861. + s32 found; /* unused */
  13862. + u32 port_handle; /**< Handle to use for this port */
  13863. + struct mmal_port port;
  13864. + struct mmal_es_format format; /* elementry stream format */
  13865. + union mmal_es_specific_format es; /* es type specific data */
  13866. + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE]; /* es extra data */
  13867. +};
  13868. +
  13869. +/* request to VC to set port information */
  13870. +struct mmal_msg_port_info_set {
  13871. + u32 component_handle;
  13872. + u32 port_type; /* enum mmal_msg_port_type */
  13873. + u32 port_index; /* port indexed in query */
  13874. + struct mmal_port port;
  13875. + struct mmal_es_format format;
  13876. + union mmal_es_specific_format es;
  13877. + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
  13878. +};
  13879. +
  13880. +/* reply from VC to port info set request */
  13881. +struct mmal_msg_port_info_set_reply {
  13882. + u32 status;
  13883. + u32 component_handle; /* component handle port is associated with */
  13884. + u32 port_type; /* enum mmal_msg_port_type */
  13885. + u32 index; /* port indexed in query */
  13886. + s32 found; /* unused */
  13887. + u32 port_handle; /**< Handle to use for this port */
  13888. + struct mmal_port port;
  13889. + struct mmal_es_format format;
  13890. + union mmal_es_specific_format es;
  13891. + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
  13892. +};
  13893. +
  13894. +
  13895. +/* port action requests that take a mmal_port as a parameter */
  13896. +struct mmal_msg_port_action_port {
  13897. + u32 component_handle;
  13898. + u32 port_handle;
  13899. + u32 action; /* enum mmal_msg_port_action_type */
  13900. + struct mmal_port port;
  13901. +};
  13902. +
  13903. +/* port action requests that take handles as a parameter */
  13904. +struct mmal_msg_port_action_handle {
  13905. + u32 component_handle;
  13906. + u32 port_handle;
  13907. + u32 action; /* enum mmal_msg_port_action_type */
  13908. + u32 connect_component_handle;
  13909. + u32 connect_port_handle;
  13910. +};
  13911. +
  13912. +struct mmal_msg_port_action_reply {
  13913. + u32 status; /** The port action operation status */
  13914. +};
  13915. +
  13916. +
  13917. +
  13918. +
  13919. +/* MMAL buffer transfer */
  13920. +
  13921. +/** Size of space reserved in a buffer message for short messages. */
  13922. +#define MMAL_VC_SHORT_DATA 128
  13923. +
  13924. +/** Signals that the current payload is the end of the stream of data */
  13925. +#define MMAL_BUFFER_HEADER_FLAG_EOS (1<<0)
  13926. +/** Signals that the start of the current payload starts a frame */
  13927. +#define MMAL_BUFFER_HEADER_FLAG_FRAME_START (1<<1)
  13928. +/** Signals that the end of the current payload ends a frame */
  13929. +#define MMAL_BUFFER_HEADER_FLAG_FRAME_END (1<<2)
  13930. +/** Signals that the current payload contains only complete frames (>1) */
  13931. +#define MMAL_BUFFER_HEADER_FLAG_FRAME \
  13932. + (MMAL_BUFFER_HEADER_FLAG_FRAME_START|MMAL_BUFFER_HEADER_FLAG_FRAME_END)
  13933. +/** Signals that the current payload is a keyframe (i.e. self decodable) */
  13934. +#define MMAL_BUFFER_HEADER_FLAG_KEYFRAME (1<<3)
  13935. +/** Signals a discontinuity in the stream of data (e.g. after a seek).
  13936. + * Can be used for instance by a decoder to reset its state */
  13937. +#define MMAL_BUFFER_HEADER_FLAG_DISCONTINUITY (1<<4)
  13938. +/** Signals a buffer containing some kind of config data for the component
  13939. + * (e.g. codec config data) */
  13940. +#define MMAL_BUFFER_HEADER_FLAG_CONFIG (1<<5)
  13941. +/** Signals an encrypted payload */
  13942. +#define MMAL_BUFFER_HEADER_FLAG_ENCRYPTED (1<<6)
  13943. +/** Signals a buffer containing side information */
  13944. +#define MMAL_BUFFER_HEADER_FLAG_CODECSIDEINFO (1<<7)
  13945. +/** Signals a buffer which is the snapshot/postview image from a stills
  13946. + * capture
  13947. + */
  13948. +#define MMAL_BUFFER_HEADER_FLAGS_SNAPSHOT (1<<8)
  13949. +/** Signals a buffer which contains data known to be corrupted */
  13950. +#define MMAL_BUFFER_HEADER_FLAG_CORRUPTED (1<<9)
  13951. +/** Signals that a buffer failed to be transmitted */
  13952. +#define MMAL_BUFFER_HEADER_FLAG_TRANSMISSION_FAILED (1<<10)
  13953. +
  13954. +struct mmal_driver_buffer {
  13955. + u32 magic;
  13956. + u32 component_handle;
  13957. + u32 port_handle;
  13958. + void *client_context;
  13959. +};
  13960. +
  13961. +/* buffer header */
  13962. +struct mmal_buffer_header {
  13963. + struct mmal_buffer_header *next; /* next header */
  13964. + void *priv; /* framework private data */
  13965. + u32 cmd;
  13966. + void *data;
  13967. + u32 alloc_size;
  13968. + u32 length;
  13969. + u32 offset;
  13970. + u32 flags;
  13971. + s64 pts;
  13972. + s64 dts;
  13973. + void *type;
  13974. + void *user_data;
  13975. +};
  13976. +
  13977. +struct mmal_buffer_header_type_specific {
  13978. + union {
  13979. + struct {
  13980. + u32 planes;
  13981. + u32 offset[4];
  13982. + u32 pitch[4];
  13983. + u32 flags;
  13984. + } video;
  13985. + } u;
  13986. +};
  13987. +
  13988. +struct mmal_msg_buffer_from_host {
  13989. + /* The front 32 bytes of the buffer header are copied
  13990. + * back to us in the reply to allow for context. This
  13991. + * area is used to store two mmal_driver_buffer structures to
  13992. + * allow for multiple concurrent service users.
  13993. + */
  13994. + /* control data */
  13995. + struct mmal_driver_buffer drvbuf;
  13996. +
  13997. + /* referenced control data for passthrough buffer management */
  13998. + struct mmal_driver_buffer drvbuf_ref;
  13999. + struct mmal_buffer_header buffer_header; /* buffer header itself */
  14000. + struct mmal_buffer_header_type_specific buffer_header_type_specific;
  14001. + s32 is_zero_copy;
  14002. + s32 has_reference;
  14003. +
  14004. + /** allows short data to be xfered in control message */
  14005. + u32 payload_in_message;
  14006. + u8 short_data[MMAL_VC_SHORT_DATA];
  14007. +};
  14008. +
  14009. +
  14010. +/* port parameter setting */
  14011. +
  14012. +#define MMAL_WORKER_PORT_PARAMETER_SPACE 96
  14013. +
  14014. +struct mmal_msg_port_parameter_set {
  14015. + u32 component_handle; /* component */
  14016. + u32 port_handle; /* port */
  14017. + u32 id; /* Parameter ID */
  14018. + u32 size; /* Parameter size */
  14019. + uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
  14020. +};
  14021. +
  14022. +struct mmal_msg_port_parameter_set_reply {
  14023. + u32 status; /** enum mmal_msg_status todo: how does this
  14024. + * differ to the one in the header?
  14025. + */
  14026. +};
  14027. +
  14028. +/* port parameter getting */
  14029. +
  14030. +struct mmal_msg_port_parameter_get {
  14031. + u32 component_handle; /* component */
  14032. + u32 port_handle; /* port */
  14033. + u32 id; /* Parameter ID */
  14034. + u32 size; /* Parameter size */
  14035. +};
  14036. +
  14037. +struct mmal_msg_port_parameter_get_reply {
  14038. + u32 status; /* Status of mmal_port_parameter_get call */
  14039. + u32 id; /* Parameter ID */
  14040. + u32 size; /* Parameter size */
  14041. + uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
  14042. +};
  14043. +
  14044. +/* event messages */
  14045. +#define MMAL_WORKER_EVENT_SPACE 256
  14046. +
  14047. +struct mmal_msg_event_to_host {
  14048. + void *client_component; /* component context */
  14049. +
  14050. + u32 port_type;
  14051. + u32 port_num;
  14052. +
  14053. + u32 cmd;
  14054. + u32 length;
  14055. + u8 data[MMAL_WORKER_EVENT_SPACE];
  14056. + struct mmal_buffer_header *delayed_buffer;
  14057. +};
  14058. +
  14059. +/* all mmal messages are serialised through this structure */
  14060. +struct mmal_msg {
  14061. + /* header */
  14062. + struct mmal_msg_header h;
  14063. + /* payload */
  14064. + union {
  14065. + struct mmal_msg_version version;
  14066. +
  14067. + struct mmal_msg_component_create component_create;
  14068. + struct mmal_msg_component_create_reply component_create_reply;
  14069. +
  14070. + struct mmal_msg_component_destroy component_destroy;
  14071. + struct mmal_msg_component_destroy_reply component_destroy_reply;
  14072. +
  14073. + struct mmal_msg_component_enable component_enable;
  14074. + struct mmal_msg_component_enable_reply component_enable_reply;
  14075. +
  14076. + struct mmal_msg_component_disable component_disable;
  14077. + struct mmal_msg_component_disable_reply component_disable_reply;
  14078. +
  14079. + struct mmal_msg_port_info_get port_info_get;
  14080. + struct mmal_msg_port_info_get_reply port_info_get_reply;
  14081. +
  14082. + struct mmal_msg_port_info_set port_info_set;
  14083. + struct mmal_msg_port_info_set_reply port_info_set_reply;
  14084. +
  14085. + struct mmal_msg_port_action_port port_action_port;
  14086. + struct mmal_msg_port_action_handle port_action_handle;
  14087. + struct mmal_msg_port_action_reply port_action_reply;
  14088. +
  14089. + struct mmal_msg_buffer_from_host buffer_from_host;
  14090. +
  14091. + struct mmal_msg_port_parameter_set port_parameter_set;
  14092. + struct mmal_msg_port_parameter_set_reply
  14093. + port_parameter_set_reply;
  14094. + struct mmal_msg_port_parameter_get
  14095. + port_parameter_get;
  14096. + struct mmal_msg_port_parameter_get_reply
  14097. + port_parameter_get_reply;
  14098. +
  14099. + struct mmal_msg_event_to_host event_to_host;
  14100. +
  14101. + u8 payload[MMAL_MSG_MAX_PAYLOAD];
  14102. + } u;
  14103. +};
  14104. diff -Nur linux-3.13.3.orig/drivers/media/platform/bcm2835/mmal-msg-port.h linux-3.13.3/drivers/media/platform/bcm2835/mmal-msg-port.h
  14105. --- linux-3.13.3.orig/drivers/media/platform/bcm2835/mmal-msg-port.h 1970-01-01 01:00:00.000000000 +0100
  14106. +++ linux-3.13.3/drivers/media/platform/bcm2835/mmal-msg-port.h 2014-02-17 22:41:01.000000000 +0100
  14107. @@ -0,0 +1,107 @@
  14108. +/*
  14109. + * Broadcom BM2835 V4L2 driver
  14110. + *
  14111. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  14112. + *
  14113. + * This file is subject to the terms and conditions of the GNU General Public
  14114. + * License. See the file COPYING in the main directory of this archive
  14115. + * for more details.
  14116. + *
  14117. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  14118. + * Dave Stevenson <dsteve@broadcom.com>
  14119. + * Simon Mellor <simellor@broadcom.com>
  14120. + * Luke Diamand <luked@broadcom.com>
  14121. + */
  14122. +
  14123. +/* MMAL_PORT_TYPE_T */
  14124. +enum mmal_port_type {
  14125. + MMAL_PORT_TYPE_UNKNOWN = 0, /**< Unknown port type */
  14126. + MMAL_PORT_TYPE_CONTROL, /**< Control port */
  14127. + MMAL_PORT_TYPE_INPUT, /**< Input port */
  14128. + MMAL_PORT_TYPE_OUTPUT, /**< Output port */
  14129. + MMAL_PORT_TYPE_CLOCK, /**< Clock port */
  14130. +};
  14131. +
  14132. +/** The port is pass-through and doesn't need buffer headers allocated */
  14133. +#define MMAL_PORT_CAPABILITY_PASSTHROUGH 0x01
  14134. +/** The port wants to allocate the buffer payloads.
  14135. + * This signals a preference that payload allocation should be done
  14136. + * on this port for efficiency reasons. */
  14137. +#define MMAL_PORT_CAPABILITY_ALLOCATION 0x02
  14138. +/** The port supports format change events.
  14139. + * This applies to input ports and is used to let the client know
  14140. + * whether the port supports being reconfigured via a format
  14141. + * change event (i.e. without having to disable the port). */
  14142. +#define MMAL_PORT_CAPABILITY_SUPPORTS_EVENT_FORMAT_CHANGE 0x04
  14143. +
  14144. +/* mmal port structure (MMAL_PORT_T)
  14145. + *
  14146. + * most elements are informational only, the pointer values for
  14147. + * interogation messages are generally provided as additional
  14148. + * strucures within the message. When used to set values only teh
  14149. + * buffer_num, buffer_size and userdata parameters are writable.
  14150. + */
  14151. +struct mmal_port {
  14152. + void *priv; /* Private member used by the framework */
  14153. + const char *name; /* Port name. Used for debugging purposes (RO) */
  14154. +
  14155. + u32 type; /* Type of the port (RO) enum mmal_port_type */
  14156. + u16 index; /* Index of the port in its type list (RO) */
  14157. + u16 index_all; /* Index of the port in the list of all ports (RO) */
  14158. +
  14159. + u32 is_enabled; /* Indicates whether the port is enabled or not (RO) */
  14160. + struct mmal_es_format *format; /* Format of the elementary stream */
  14161. +
  14162. + u32 buffer_num_min; /* Minimum number of buffers the port
  14163. + * requires (RO). This is set by the
  14164. + * component.
  14165. + */
  14166. +
  14167. + u32 buffer_size_min; /* Minimum size of buffers the port
  14168. + * requires (RO). This is set by the
  14169. + * component.
  14170. + */
  14171. +
  14172. + u32 buffer_alignment_min; /* Minimum alignment requirement for
  14173. + * the buffers (RO). A value of
  14174. + * zero means no special alignment
  14175. + * requirements. This is set by the
  14176. + * component.
  14177. + */
  14178. +
  14179. + u32 buffer_num_recommended; /* Number of buffers the port
  14180. + * recommends for optimal
  14181. + * performance (RO). A value of
  14182. + * zero means no special
  14183. + * recommendation. This is set
  14184. + * by the component.
  14185. + */
  14186. +
  14187. + u32 buffer_size_recommended; /* Size of buffers the port
  14188. + * recommends for optimal
  14189. + * performance (RO). A value of
  14190. + * zero means no special
  14191. + * recommendation. This is set
  14192. + * by the component.
  14193. + */
  14194. +
  14195. + u32 buffer_num; /* Actual number of buffers the port will use.
  14196. + * This is set by the client.
  14197. + */
  14198. +
  14199. + u32 buffer_size; /* Actual maximum size of the buffers that
  14200. + * will be sent to the port. This is set by
  14201. + * the client.
  14202. + */
  14203. +
  14204. + void *component; /* Component this port belongs to (Read Only) */
  14205. +
  14206. + void *userdata; /* Field reserved for use by the client */
  14207. +
  14208. + u32 capabilities; /* Flags describing the capabilities of a
  14209. + * port (RO). Bitwise combination of \ref
  14210. + * portcapabilities "Port capabilities"
  14211. + * values.
  14212. + */
  14213. +
  14214. +};
  14215. diff -Nur linux-3.13.3.orig/drivers/media/platform/bcm2835/mmal-parameters.h linux-3.13.3/drivers/media/platform/bcm2835/mmal-parameters.h
  14216. --- linux-3.13.3.orig/drivers/media/platform/bcm2835/mmal-parameters.h 1970-01-01 01:00:00.000000000 +0100
  14217. +++ linux-3.13.3/drivers/media/platform/bcm2835/mmal-parameters.h 2014-02-17 22:41:01.000000000 +0100
  14218. @@ -0,0 +1,562 @@
  14219. +/*
  14220. + * Broadcom BM2835 V4L2 driver
  14221. + *
  14222. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  14223. + *
  14224. + * This file is subject to the terms and conditions of the GNU General Public
  14225. + * License. See the file COPYING in the main directory of this archive
  14226. + * for more details.
  14227. + *
  14228. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  14229. + * Dave Stevenson <dsteve@broadcom.com>
  14230. + * Simon Mellor <simellor@broadcom.com>
  14231. + * Luke Diamand <luked@broadcom.com>
  14232. + */
  14233. +
  14234. +/* common parameters */
  14235. +
  14236. +/** @name Parameter groups
  14237. + * Parameters are divided into groups, and then allocated sequentially within
  14238. + * a group using an enum.
  14239. + * @{
  14240. + */
  14241. +
  14242. +/** Common parameter ID group, used with many types of component. */
  14243. +#define MMAL_PARAMETER_GROUP_COMMON (0<<16)
  14244. +/** Camera-specific parameter ID group. */
  14245. +#define MMAL_PARAMETER_GROUP_CAMERA (1<<16)
  14246. +/** Video-specific parameter ID group. */
  14247. +#define MMAL_PARAMETER_GROUP_VIDEO (2<<16)
  14248. +/** Audio-specific parameter ID group. */
  14249. +#define MMAL_PARAMETER_GROUP_AUDIO (3<<16)
  14250. +/** Clock-specific parameter ID group. */
  14251. +#define MMAL_PARAMETER_GROUP_CLOCK (4<<16)
  14252. +/** Miracast-specific parameter ID group. */
  14253. +#define MMAL_PARAMETER_GROUP_MIRACAST (5<<16)
  14254. +
  14255. +/* Common parameters */
  14256. +enum mmal_parameter_common_type {
  14257. + MMAL_PARAMETER_UNUSED /**< Never a valid parameter ID */
  14258. + = MMAL_PARAMETER_GROUP_COMMON,
  14259. + MMAL_PARAMETER_SUPPORTED_ENCODINGS, /**< MMAL_PARAMETER_ENCODING_T */
  14260. + MMAL_PARAMETER_URI, /**< MMAL_PARAMETER_URI_T */
  14261. +
  14262. + /** MMAL_PARAMETER_CHANGE_EVENT_REQUEST_T */
  14263. + MMAL_PARAMETER_CHANGE_EVENT_REQUEST,
  14264. +
  14265. + /** MMAL_PARAMETER_BOOLEAN_T */
  14266. + MMAL_PARAMETER_ZERO_COPY,
  14267. +
  14268. + /**< MMAL_PARAMETER_BUFFER_REQUIREMENTS_T */
  14269. + MMAL_PARAMETER_BUFFER_REQUIREMENTS,
  14270. +
  14271. + MMAL_PARAMETER_STATISTICS, /**< MMAL_PARAMETER_STATISTICS_T */
  14272. + MMAL_PARAMETER_CORE_STATISTICS, /**< MMAL_PARAMETER_CORE_STATISTICS_T */
  14273. + MMAL_PARAMETER_MEM_USAGE, /**< MMAL_PARAMETER_MEM_USAGE_T */
  14274. + MMAL_PARAMETER_BUFFER_FLAG_FILTER, /**< MMAL_PARAMETER_UINT32_T */
  14275. + MMAL_PARAMETER_SEEK, /**< MMAL_PARAMETER_SEEK_T */
  14276. + MMAL_PARAMETER_POWERMON_ENABLE, /**< MMAL_PARAMETER_BOOLEAN_T */
  14277. + MMAL_PARAMETER_LOGGING, /**< MMAL_PARAMETER_LOGGING_T */
  14278. + MMAL_PARAMETER_SYSTEM_TIME /**< MMAL_PARAMETER_UINT64_T */
  14279. +};
  14280. +
  14281. +/* camera parameters */
  14282. +
  14283. +enum mmal_parameter_camera_type {
  14284. + /* 0 */
  14285. + /** @ref MMAL_PARAMETER_THUMBNAIL_CONFIG_T */
  14286. + MMAL_PARAMETER_THUMBNAIL_CONFIGURATION
  14287. + = MMAL_PARAMETER_GROUP_CAMERA,
  14288. + MMAL_PARAMETER_CAPTURE_QUALITY, /**< Unused? */
  14289. + MMAL_PARAMETER_ROTATION, /**< @ref MMAL_PARAMETER_INT32_T */
  14290. + MMAL_PARAMETER_EXIF_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14291. + MMAL_PARAMETER_EXIF, /**< @ref MMAL_PARAMETER_EXIF_T */
  14292. + MMAL_PARAMETER_AWB_MODE, /**< @ref MMAL_PARAM_AWBMODE_T */
  14293. + MMAL_PARAMETER_IMAGE_EFFECT, /**< @ref MMAL_PARAMETER_IMAGEFX_T */
  14294. + MMAL_PARAMETER_COLOUR_EFFECT, /**< @ref MMAL_PARAMETER_COLOURFX_T */
  14295. + MMAL_PARAMETER_FLICKER_AVOID, /**< @ref MMAL_PARAMETER_FLICKERAVOID_T */
  14296. + MMAL_PARAMETER_FLASH, /**< @ref MMAL_PARAMETER_FLASH_T */
  14297. + MMAL_PARAMETER_REDEYE, /**< @ref MMAL_PARAMETER_REDEYE_T */
  14298. + MMAL_PARAMETER_FOCUS, /**< @ref MMAL_PARAMETER_FOCUS_T */
  14299. + MMAL_PARAMETER_FOCAL_LENGTHS, /**< Unused? */
  14300. + MMAL_PARAMETER_EXPOSURE_COMP, /**< @ref MMAL_PARAMETER_INT32_T */
  14301. + MMAL_PARAMETER_ZOOM, /**< @ref MMAL_PARAMETER_SCALEFACTOR_T */
  14302. + MMAL_PARAMETER_MIRROR, /**< @ref MMAL_PARAMETER_MIRROR_T */
  14303. +
  14304. + /* 0x10 */
  14305. + MMAL_PARAMETER_CAMERA_NUM, /**< @ref MMAL_PARAMETER_UINT32_T */
  14306. + MMAL_PARAMETER_CAPTURE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14307. + MMAL_PARAMETER_EXPOSURE_MODE, /**< @ref MMAL_PARAMETER_EXPOSUREMODE_T */
  14308. + MMAL_PARAMETER_EXP_METERING_MODE, /**< @ref MMAL_PARAMETER_EXPOSUREMETERINGMODE_T */
  14309. + MMAL_PARAMETER_FOCUS_STATUS, /**< @ref MMAL_PARAMETER_FOCUS_STATUS_T */
  14310. + MMAL_PARAMETER_CAMERA_CONFIG, /**< @ref MMAL_PARAMETER_CAMERA_CONFIG_T */
  14311. + MMAL_PARAMETER_CAPTURE_STATUS, /**< @ref MMAL_PARAMETER_CAPTURE_STATUS_T */
  14312. + MMAL_PARAMETER_FACE_TRACK, /**< @ref MMAL_PARAMETER_FACE_TRACK_T */
  14313. + MMAL_PARAMETER_DRAW_BOX_FACES_AND_FOCUS, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14314. + MMAL_PARAMETER_JPEG_Q_FACTOR, /**< @ref MMAL_PARAMETER_UINT32_T */
  14315. + MMAL_PARAMETER_FRAME_RATE, /**< @ref MMAL_PARAMETER_FRAME_RATE_T */
  14316. + MMAL_PARAMETER_USE_STC, /**< @ref MMAL_PARAMETER_CAMERA_STC_MODE_T */
  14317. + MMAL_PARAMETER_CAMERA_INFO, /**< @ref MMAL_PARAMETER_CAMERA_INFO_T */
  14318. + MMAL_PARAMETER_VIDEO_STABILISATION, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14319. + MMAL_PARAMETER_FACE_TRACK_RESULTS, /**< @ref MMAL_PARAMETER_FACE_TRACK_RESULTS_T */
  14320. + MMAL_PARAMETER_ENABLE_RAW_CAPTURE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14321. +
  14322. + /* 0x20 */
  14323. + MMAL_PARAMETER_DPF_FILE, /**< @ref MMAL_PARAMETER_URI_T */
  14324. + MMAL_PARAMETER_ENABLE_DPF_FILE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14325. + MMAL_PARAMETER_DPF_FAIL_IS_FATAL, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14326. + MMAL_PARAMETER_CAPTURE_MODE, /**< @ref MMAL_PARAMETER_CAPTUREMODE_T */
  14327. + MMAL_PARAMETER_FOCUS_REGIONS, /**< @ref MMAL_PARAMETER_FOCUS_REGIONS_T */
  14328. + MMAL_PARAMETER_INPUT_CROP, /**< @ref MMAL_PARAMETER_INPUT_CROP_T */
  14329. + MMAL_PARAMETER_SENSOR_INFORMATION, /**< @ref MMAL_PARAMETER_SENSOR_INFORMATION_T */
  14330. + MMAL_PARAMETER_FLASH_SELECT, /**< @ref MMAL_PARAMETER_FLASH_SELECT_T */
  14331. + MMAL_PARAMETER_FIELD_OF_VIEW, /**< @ref MMAL_PARAMETER_FIELD_OF_VIEW_T */
  14332. + MMAL_PARAMETER_HIGH_DYNAMIC_RANGE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14333. + MMAL_PARAMETER_DYNAMIC_RANGE_COMPRESSION, /**< @ref MMAL_PARAMETER_DRC_T */
  14334. + MMAL_PARAMETER_ALGORITHM_CONTROL, /**< @ref MMAL_PARAMETER_ALGORITHM_CONTROL_T */
  14335. + MMAL_PARAMETER_SHARPNESS, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  14336. + MMAL_PARAMETER_CONTRAST, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  14337. + MMAL_PARAMETER_BRIGHTNESS, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  14338. + MMAL_PARAMETER_SATURATION, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  14339. +
  14340. + /* 0x30 */
  14341. + MMAL_PARAMETER_ISO, /**< @ref MMAL_PARAMETER_UINT32_T */
  14342. + MMAL_PARAMETER_ANTISHAKE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14343. +
  14344. + /** @ref MMAL_PARAMETER_IMAGEFX_PARAMETERS_T */
  14345. + MMAL_PARAMETER_IMAGE_EFFECT_PARAMETERS,
  14346. +
  14347. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  14348. + MMAL_PARAMETER_CAMERA_BURST_CAPTURE,
  14349. +
  14350. + /** @ref MMAL_PARAMETER_UINT32_T */
  14351. + MMAL_PARAMETER_CAMERA_MIN_ISO,
  14352. +
  14353. + /** @ref MMAL_PARAMETER_CAMERA_USE_CASE_T */
  14354. + MMAL_PARAMETER_CAMERA_USE_CASE,
  14355. +
  14356. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14357. + MMAL_PARAMETER_CAPTURE_STATS_PASS,
  14358. +
  14359. + /** @ref MMAL_PARAMETER_UINT32_T */
  14360. + MMAL_PARAMETER_CAMERA_CUSTOM_SENSOR_CONFIG,
  14361. +
  14362. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  14363. + MMAL_PARAMETER_ENABLE_REGISTER_FILE,
  14364. +
  14365. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  14366. + MMAL_PARAMETER_REGISTER_FAIL_IS_FATAL,
  14367. +
  14368. + /** @ref MMAL_PARAMETER_CONFIGFILE_T */
  14369. + MMAL_PARAMETER_CONFIGFILE_REGISTERS,
  14370. +
  14371. + /** @ref MMAL_PARAMETER_CONFIGFILE_CHUNK_T */
  14372. + MMAL_PARAMETER_CONFIGFILE_CHUNK_REGISTERS,
  14373. + MMAL_PARAMETER_JPEG_ATTACH_LOG, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14374. + MMAL_PARAMETER_ZERO_SHUTTER_LAG, /**< @ref MMAL_PARAMETER_ZEROSHUTTERLAG_T */
  14375. + MMAL_PARAMETER_FPS_RANGE, /**< @ref MMAL_PARAMETER_FPS_RANGE_T */
  14376. + MMAL_PARAMETER_CAPTURE_EXPOSURE_COMP, /**< @ref MMAL_PARAMETER_INT32_T */
  14377. +
  14378. + /* 0x40 */
  14379. + MMAL_PARAMETER_SW_SHARPEN_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14380. + MMAL_PARAMETER_FLASH_REQUIRED, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14381. + MMAL_PARAMETER_SW_SATURATION_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14382. + MMAL_PARAMETER_SHUTTER_SPEED /**< Takes a @ref MMAL_PARAMETER_UINT32_T */
  14383. +};
  14384. +
  14385. +struct mmal_parameter_rational {
  14386. + s32 num; /**< Numerator */
  14387. + s32 den; /**< Denominator */
  14388. +};
  14389. +
  14390. +enum mmal_parameter_camera_config_timestamp_mode {
  14391. + MMAL_PARAM_TIMESTAMP_MODE_ZERO = 0, /* Always timestamp frames as 0 */
  14392. + MMAL_PARAM_TIMESTAMP_MODE_RAW_STC, /* Use the raw STC value
  14393. + * for the frame timestamp
  14394. + */
  14395. + MMAL_PARAM_TIMESTAMP_MODE_RESET_STC, /* Use the STC timestamp
  14396. + * but subtract the
  14397. + * timestamp of the first
  14398. + * frame sent to give a
  14399. + * zero based timestamp.
  14400. + */
  14401. +};
  14402. +
  14403. +/* camera configuration parameter */
  14404. +struct mmal_parameter_camera_config {
  14405. + /* Parameters for setting up the image pools */
  14406. + u32 max_stills_w; /* Max size of stills capture */
  14407. + u32 max_stills_h;
  14408. + u32 stills_yuv422; /* Allow YUV422 stills capture */
  14409. + u32 one_shot_stills; /* Continuous or one shot stills captures. */
  14410. +
  14411. + u32 max_preview_video_w; /* Max size of the preview or video
  14412. + * capture frames
  14413. + */
  14414. + u32 max_preview_video_h;
  14415. + u32 num_preview_video_frames;
  14416. +
  14417. + /** Sets the height of the circular buffer for stills capture. */
  14418. + u32 stills_capture_circular_buffer_height;
  14419. +
  14420. + /** Allows preview/encode to resume as fast as possible after the stills
  14421. + * input frame has been received, and then processes the still frame in
  14422. + * the background whilst preview/encode has resumed.
  14423. + * Actual mode is controlled by MMAL_PARAMETER_CAPTURE_MODE.
  14424. + */
  14425. + u32 fast_preview_resume;
  14426. +
  14427. + /** Selects algorithm for timestamping frames if
  14428. + * there is no clock component connected.
  14429. + * enum mmal_parameter_camera_config_timestamp_mode
  14430. + */
  14431. + s32 use_stc_timestamp;
  14432. +};
  14433. +
  14434. +
  14435. +enum mmal_parameter_exposuremode {
  14436. + MMAL_PARAM_EXPOSUREMODE_OFF,
  14437. + MMAL_PARAM_EXPOSUREMODE_AUTO,
  14438. + MMAL_PARAM_EXPOSUREMODE_NIGHT,
  14439. + MMAL_PARAM_EXPOSUREMODE_NIGHTPREVIEW,
  14440. + MMAL_PARAM_EXPOSUREMODE_BACKLIGHT,
  14441. + MMAL_PARAM_EXPOSUREMODE_SPOTLIGHT,
  14442. + MMAL_PARAM_EXPOSUREMODE_SPORTS,
  14443. + MMAL_PARAM_EXPOSUREMODE_SNOW,
  14444. + MMAL_PARAM_EXPOSUREMODE_BEACH,
  14445. + MMAL_PARAM_EXPOSUREMODE_VERYLONG,
  14446. + MMAL_PARAM_EXPOSUREMODE_FIXEDFPS,
  14447. + MMAL_PARAM_EXPOSUREMODE_ANTISHAKE,
  14448. + MMAL_PARAM_EXPOSUREMODE_FIREWORKS,
  14449. +};
  14450. +
  14451. +enum mmal_parameter_exposuremeteringmode {
  14452. + MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE,
  14453. + MMAL_PARAM_EXPOSUREMETERINGMODE_SPOT,
  14454. + MMAL_PARAM_EXPOSUREMETERINGMODE_BACKLIT,
  14455. + MMAL_PARAM_EXPOSUREMETERINGMODE_MATRIX,
  14456. +};
  14457. +
  14458. +enum mmal_parameter_awbmode {
  14459. + MMAL_PARAM_AWBMODE_OFF,
  14460. + MMAL_PARAM_AWBMODE_AUTO,
  14461. + MMAL_PARAM_AWBMODE_SUNLIGHT,
  14462. + MMAL_PARAM_AWBMODE_CLOUDY,
  14463. + MMAL_PARAM_AWBMODE_SHADE,
  14464. + MMAL_PARAM_AWBMODE_TUNGSTEN,
  14465. + MMAL_PARAM_AWBMODE_FLUORESCENT,
  14466. + MMAL_PARAM_AWBMODE_INCANDESCENT,
  14467. + MMAL_PARAM_AWBMODE_FLASH,
  14468. + MMAL_PARAM_AWBMODE_HORIZON,
  14469. +};
  14470. +
  14471. +enum mmal_parameter_imagefx {
  14472. + MMAL_PARAM_IMAGEFX_NONE,
  14473. + MMAL_PARAM_IMAGEFX_NEGATIVE,
  14474. + MMAL_PARAM_IMAGEFX_SOLARIZE,
  14475. + MMAL_PARAM_IMAGEFX_POSTERIZE,
  14476. + MMAL_PARAM_IMAGEFX_WHITEBOARD,
  14477. + MMAL_PARAM_IMAGEFX_BLACKBOARD,
  14478. + MMAL_PARAM_IMAGEFX_SKETCH,
  14479. + MMAL_PARAM_IMAGEFX_DENOISE,
  14480. + MMAL_PARAM_IMAGEFX_EMBOSS,
  14481. + MMAL_PARAM_IMAGEFX_OILPAINT,
  14482. + MMAL_PARAM_IMAGEFX_HATCH,
  14483. + MMAL_PARAM_IMAGEFX_GPEN,
  14484. + MMAL_PARAM_IMAGEFX_PASTEL,
  14485. + MMAL_PARAM_IMAGEFX_WATERCOLOUR,
  14486. + MMAL_PARAM_IMAGEFX_FILM,
  14487. + MMAL_PARAM_IMAGEFX_BLUR,
  14488. + MMAL_PARAM_IMAGEFX_SATURATION,
  14489. + MMAL_PARAM_IMAGEFX_COLOURSWAP,
  14490. + MMAL_PARAM_IMAGEFX_WASHEDOUT,
  14491. + MMAL_PARAM_IMAGEFX_POSTERISE,
  14492. + MMAL_PARAM_IMAGEFX_COLOURPOINT,
  14493. + MMAL_PARAM_IMAGEFX_COLOURBALANCE,
  14494. + MMAL_PARAM_IMAGEFX_CARTOON,
  14495. +};
  14496. +
  14497. +enum MMAL_PARAM_FLICKERAVOID_T {
  14498. + MMAL_PARAM_FLICKERAVOID_OFF,
  14499. + MMAL_PARAM_FLICKERAVOID_AUTO,
  14500. + MMAL_PARAM_FLICKERAVOID_50HZ,
  14501. + MMAL_PARAM_FLICKERAVOID_60HZ,
  14502. + MMAL_PARAM_FLICKERAVOID_MAX = 0x7FFFFFFF
  14503. +};
  14504. +
  14505. +/** Manner of video rate control */
  14506. +enum mmal_parameter_rate_control_mode {
  14507. + MMAL_VIDEO_RATECONTROL_DEFAULT,
  14508. + MMAL_VIDEO_RATECONTROL_VARIABLE,
  14509. + MMAL_VIDEO_RATECONTROL_CONSTANT,
  14510. + MMAL_VIDEO_RATECONTROL_VARIABLE_SKIP_FRAMES,
  14511. + MMAL_VIDEO_RATECONTROL_CONSTANT_SKIP_FRAMES
  14512. +};
  14513. +
  14514. +/* video parameters */
  14515. +
  14516. +enum mmal_parameter_video_type {
  14517. + /** @ref MMAL_DISPLAYREGION_T */
  14518. + MMAL_PARAMETER_DISPLAYREGION = MMAL_PARAMETER_GROUP_VIDEO,
  14519. +
  14520. + /** @ref MMAL_PARAMETER_VIDEO_PROFILE_T */
  14521. + MMAL_PARAMETER_SUPPORTED_PROFILES,
  14522. +
  14523. + /** @ref MMAL_PARAMETER_VIDEO_PROFILE_T */
  14524. + MMAL_PARAMETER_PROFILE,
  14525. +
  14526. + /** @ref MMAL_PARAMETER_UINT32_T */
  14527. + MMAL_PARAMETER_INTRAPERIOD,
  14528. +
  14529. + /** @ref MMAL_PARAMETER_VIDEO_RATECONTROL_T */
  14530. + MMAL_PARAMETER_RATECONTROL,
  14531. +
  14532. + /** @ref MMAL_PARAMETER_VIDEO_NALUNITFORMAT_T */
  14533. + MMAL_PARAMETER_NALUNITFORMAT,
  14534. +
  14535. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  14536. + MMAL_PARAMETER_MINIMISE_FRAGMENTATION,
  14537. +
  14538. + /** @ref MMAL_PARAMETER_UINT32_T.
  14539. + * Setting the value to zero resets to the default (one slice per frame).
  14540. + */
  14541. + MMAL_PARAMETER_MB_ROWS_PER_SLICE,
  14542. +
  14543. + /** @ref MMAL_PARAMETER_VIDEO_LEVEL_EXTENSION_T */
  14544. + MMAL_PARAMETER_VIDEO_LEVEL_EXTENSION,
  14545. +
  14546. + /** @ref MMAL_PARAMETER_VIDEO_EEDE_ENABLE_T */
  14547. + MMAL_PARAMETER_VIDEO_EEDE_ENABLE,
  14548. +
  14549. + /** @ref MMAL_PARAMETER_VIDEO_EEDE_LOSSRATE_T */
  14550. + MMAL_PARAMETER_VIDEO_EEDE_LOSSRATE,
  14551. +
  14552. + /** @ref MMAL_PARAMETER_BOOLEAN_T. Request an I-frame. */
  14553. + MMAL_PARAMETER_VIDEO_REQUEST_I_FRAME,
  14554. + /** @ref MMAL_PARAMETER_VIDEO_INTRA_REFRESH_T */
  14555. + MMAL_PARAMETER_VIDEO_INTRA_REFRESH,
  14556. +
  14557. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  14558. + MMAL_PARAMETER_VIDEO_IMMUTABLE_INPUT,
  14559. +
  14560. + /** @ref MMAL_PARAMETER_UINT32_T. Run-time bit rate control */
  14561. + MMAL_PARAMETER_VIDEO_BIT_RATE,
  14562. +
  14563. + /** @ref MMAL_PARAMETER_FRAME_RATE_T */
  14564. + MMAL_PARAMETER_VIDEO_FRAME_RATE,
  14565. +
  14566. + /** @ref MMAL_PARAMETER_UINT32_T. */
  14567. + MMAL_PARAMETER_VIDEO_ENCODE_MIN_QUANT,
  14568. +
  14569. + /** @ref MMAL_PARAMETER_UINT32_T. */
  14570. + MMAL_PARAMETER_VIDEO_ENCODE_MAX_QUANT,
  14571. +
  14572. + /** @ref MMAL_PARAMETER_VIDEO_ENCODE_RC_MODEL_T. */
  14573. + MMAL_PARAMETER_VIDEO_ENCODE_RC_MODEL,
  14574. +
  14575. + MMAL_PARAMETER_EXTRA_BUFFERS, /**< @ref MMAL_PARAMETER_UINT32_T. */
  14576. + /** @ref MMAL_PARAMETER_UINT32_T.
  14577. + * Changing this parameter from the default can reduce frame rate
  14578. + * because image buffers need to be re-pitched.
  14579. + */
  14580. + MMAL_PARAMETER_VIDEO_ALIGN_HORIZ,
  14581. +
  14582. + /** @ref MMAL_PARAMETER_UINT32_T.
  14583. + * Changing this parameter from the default can reduce frame rate
  14584. + * because image buffers need to be re-pitched.
  14585. + */
  14586. + MMAL_PARAMETER_VIDEO_ALIGN_VERT,
  14587. +
  14588. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  14589. + MMAL_PARAMETER_VIDEO_DROPPABLE_PFRAMES,
  14590. +
  14591. + /** @ref MMAL_PARAMETER_UINT32_T. */
  14592. + MMAL_PARAMETER_VIDEO_ENCODE_INITIAL_QUANT,
  14593. +
  14594. + /**< @ref MMAL_PARAMETER_UINT32_T. */
  14595. + MMAL_PARAMETER_VIDEO_ENCODE_QP_P,
  14596. +
  14597. + /**< @ref MMAL_PARAMETER_UINT32_T. */
  14598. + MMAL_PARAMETER_VIDEO_ENCODE_RC_SLICE_DQUANT,
  14599. +
  14600. + /** @ref MMAL_PARAMETER_UINT32_T */
  14601. + MMAL_PARAMETER_VIDEO_ENCODE_FRAME_LIMIT_BITS,
  14602. +
  14603. + /** @ref MMAL_PARAMETER_UINT32_T. */
  14604. + MMAL_PARAMETER_VIDEO_ENCODE_PEAK_RATE,
  14605. +
  14606. + /* H264 specific parameters */
  14607. +
  14608. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  14609. + MMAL_PARAMETER_VIDEO_ENCODE_H264_DISABLE_CABAC,
  14610. +
  14611. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  14612. + MMAL_PARAMETER_VIDEO_ENCODE_H264_LOW_LATENCY,
  14613. +
  14614. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  14615. + MMAL_PARAMETER_VIDEO_ENCODE_H264_AU_DELIMITERS,
  14616. +
  14617. + /** @ref MMAL_PARAMETER_UINT32_T. */
  14618. + MMAL_PARAMETER_VIDEO_ENCODE_H264_DEBLOCK_IDC,
  14619. +
  14620. + /** @ref MMAL_PARAMETER_VIDEO_ENCODER_H264_MB_INTRA_MODES_T. */
  14621. + MMAL_PARAMETER_VIDEO_ENCODE_H264_MB_INTRA_MODE,
  14622. +
  14623. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  14624. + MMAL_PARAMETER_VIDEO_ENCODE_HEADER_ON_OPEN,
  14625. +
  14626. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  14627. + MMAL_PARAMETER_VIDEO_ENCODE_PRECODE_FOR_QP,
  14628. +
  14629. + /** @ref MMAL_PARAMETER_VIDEO_DRM_INIT_INFO_T. */
  14630. + MMAL_PARAMETER_VIDEO_DRM_INIT_INFO,
  14631. +
  14632. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  14633. + MMAL_PARAMETER_VIDEO_TIMESTAMP_FIFO,
  14634. +
  14635. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  14636. + MMAL_PARAMETER_VIDEO_DECODE_ERROR_CONCEALMENT,
  14637. +
  14638. + /** @ref MMAL_PARAMETER_VIDEO_DRM_PROTECT_BUFFER_T. */
  14639. + MMAL_PARAMETER_VIDEO_DRM_PROTECT_BUFFER,
  14640. +
  14641. + /** @ref MMAL_PARAMETER_BYTES_T */
  14642. + MMAL_PARAMETER_VIDEO_DECODE_CONFIG_VD3,
  14643. +
  14644. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14645. + MMAL_PARAMETER_VIDEO_ENCODE_H264_VCL_HRD_PARAMETERS,
  14646. +
  14647. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14648. + MMAL_PARAMETER_VIDEO_ENCODE_H264_LOW_DELAY_HRD_FLAG,
  14649. +
  14650. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14651. + MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER
  14652. +};
  14653. +
  14654. +/** Valid mirror modes */
  14655. +enum mmal_parameter_mirror {
  14656. + MMAL_PARAM_MIRROR_NONE,
  14657. + MMAL_PARAM_MIRROR_VERTICAL,
  14658. + MMAL_PARAM_MIRROR_HORIZONTAL,
  14659. + MMAL_PARAM_MIRROR_BOTH,
  14660. +};
  14661. +
  14662. +enum mmal_parameter_displaytransform {
  14663. + MMAL_DISPLAY_ROT0 = 0,
  14664. + MMAL_DISPLAY_MIRROR_ROT0 = 1,
  14665. + MMAL_DISPLAY_MIRROR_ROT180 = 2,
  14666. + MMAL_DISPLAY_ROT180 = 3,
  14667. + MMAL_DISPLAY_MIRROR_ROT90 = 4,
  14668. + MMAL_DISPLAY_ROT270 = 5,
  14669. + MMAL_DISPLAY_ROT90 = 6,
  14670. + MMAL_DISPLAY_MIRROR_ROT270 = 7,
  14671. +};
  14672. +
  14673. +enum mmal_parameter_displaymode {
  14674. + MMAL_DISPLAY_MODE_FILL = 0,
  14675. + MMAL_DISPLAY_MODE_LETTERBOX = 1,
  14676. +};
  14677. +
  14678. +enum mmal_parameter_displayset {
  14679. + MMAL_DISPLAY_SET_NONE = 0,
  14680. + MMAL_DISPLAY_SET_NUM = 1,
  14681. + MMAL_DISPLAY_SET_FULLSCREEN = 2,
  14682. + MMAL_DISPLAY_SET_TRANSFORM = 4,
  14683. + MMAL_DISPLAY_SET_DEST_RECT = 8,
  14684. + MMAL_DISPLAY_SET_SRC_RECT = 0x10,
  14685. + MMAL_DISPLAY_SET_MODE = 0x20,
  14686. + MMAL_DISPLAY_SET_PIXEL = 0x40,
  14687. + MMAL_DISPLAY_SET_NOASPECT = 0x80,
  14688. + MMAL_DISPLAY_SET_LAYER = 0x100,
  14689. + MMAL_DISPLAY_SET_COPYPROTECT = 0x200,
  14690. + MMAL_DISPLAY_SET_ALPHA = 0x400,
  14691. +};
  14692. +
  14693. +struct mmal_parameter_displayregion {
  14694. + /** Bitfield that indicates which fields are set and should be
  14695. + * used. All other fields will maintain their current value.
  14696. + * \ref MMAL_DISPLAYSET_T defines the bits that can be
  14697. + * combined.
  14698. + */
  14699. + u32 set;
  14700. +
  14701. + /** Describes the display output device, with 0 typically
  14702. + * being a directly connected LCD display. The actual values
  14703. + * will depend on the hardware. Code using hard-wired numbers
  14704. + * (e.g. 2) is certain to fail.
  14705. + */
  14706. +
  14707. + u32 display_num;
  14708. + /** Indicates that we are using the full device screen area,
  14709. + * rather than a window of the display. If zero, then
  14710. + * dest_rect is used to specify a region of the display to
  14711. + * use.
  14712. + */
  14713. +
  14714. + s32 fullscreen;
  14715. + /** Indicates any rotation or flipping used to map frames onto
  14716. + * the natural display orientation.
  14717. + */
  14718. + u32 transform; /* enum mmal_parameter_displaytransform */
  14719. +
  14720. + /** Where to display the frame within the screen, if
  14721. + * fullscreen is zero.
  14722. + */
  14723. + struct vchiq_mmal_rect dest_rect;
  14724. +
  14725. + /** Indicates which area of the frame to display. If all
  14726. + * values are zero, the whole frame will be used.
  14727. + */
  14728. + struct vchiq_mmal_rect src_rect;
  14729. +
  14730. + /** If set to non-zero, indicates that any display scaling
  14731. + * should disregard the aspect ratio of the frame region being
  14732. + * displayed.
  14733. + */
  14734. + s32 noaspect;
  14735. +
  14736. + /** Indicates how the image should be scaled to fit the
  14737. + * display. \code MMAL_DISPLAY_MODE_FILL \endcode indicates
  14738. + * that the image should fill the screen by potentially
  14739. + * cropping the frames. Setting \code mode \endcode to \code
  14740. + * MMAL_DISPLAY_MODE_LETTERBOX \endcode indicates that all the
  14741. + * source region should be displayed and black bars added if
  14742. + * necessary.
  14743. + */
  14744. + u32 mode; /* enum mmal_parameter_displaymode */
  14745. +
  14746. + /** If non-zero, defines the width of a source pixel relative
  14747. + * to \code pixel_y \endcode. If zero, then pixels default to
  14748. + * being square.
  14749. + */
  14750. + u32 pixel_x;
  14751. +
  14752. + /** If non-zero, defines the height of a source pixel relative
  14753. + * to \code pixel_x \endcode. If zero, then pixels default to
  14754. + * being square.
  14755. + */
  14756. + u32 pixel_y;
  14757. +
  14758. + /** Sets the relative depth of the images, with greater values
  14759. + * being in front of smaller values.
  14760. + */
  14761. + u32 layer;
  14762. +
  14763. + /** Set to non-zero to ensure copy protection is used on
  14764. + * output.
  14765. + */
  14766. + s32 copyprotect_required;
  14767. +
  14768. + /** Level of opacity of the layer, where zero is fully
  14769. + * transparent and 255 is fully opaque.
  14770. + */
  14771. + u32 alpha;
  14772. +};
  14773. +
  14774. +#define MMAL_MAX_IMAGEFX_PARAMETERS 5
  14775. +
  14776. +struct mmal_parameter_imagefx_parameters {
  14777. + enum mmal_parameter_imagefx effect;
  14778. + u32 num_effect_params;
  14779. + u32 effect_parameter[MMAL_MAX_IMAGEFX_PARAMETERS];
  14780. +};
  14781. diff -Nur linux-3.13.3.orig/drivers/media/platform/bcm2835/mmal-vchiq.c linux-3.13.3/drivers/media/platform/bcm2835/mmal-vchiq.c
  14782. --- linux-3.13.3.orig/drivers/media/platform/bcm2835/mmal-vchiq.c 1970-01-01 01:00:00.000000000 +0100
  14783. +++ linux-3.13.3/drivers/media/platform/bcm2835/mmal-vchiq.c 2014-02-17 22:41:01.000000000 +0100
  14784. @@ -0,0 +1,1916 @@
  14785. +/*
  14786. + * Broadcom BM2835 V4L2 driver
  14787. + *
  14788. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  14789. + *
  14790. + * This file is subject to the terms and conditions of the GNU General Public
  14791. + * License. See the file COPYING in the main directory of this archive
  14792. + * for more details.
  14793. + *
  14794. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  14795. + * Dave Stevenson <dsteve@broadcom.com>
  14796. + * Simon Mellor <simellor@broadcom.com>
  14797. + * Luke Diamand <luked@broadcom.com>
  14798. + *
  14799. + * V4L2 driver MMAL vchiq interface code
  14800. + */
  14801. +
  14802. +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  14803. +
  14804. +#include <linux/errno.h>
  14805. +#include <linux/kernel.h>
  14806. +#include <linux/mutex.h>
  14807. +#include <linux/mm.h>
  14808. +#include <linux/slab.h>
  14809. +#include <linux/completion.h>
  14810. +#include <linux/vmalloc.h>
  14811. +#include <asm/cacheflush.h>
  14812. +#include <media/videobuf2-vmalloc.h>
  14813. +
  14814. +#include "mmal-common.h"
  14815. +#include "mmal-vchiq.h"
  14816. +#include "mmal-msg.h"
  14817. +
  14818. +#define USE_VCHIQ_ARM
  14819. +#include "interface/vchi/vchi.h"
  14820. +
  14821. +/* maximum number of components supported */
  14822. +#define VCHIQ_MMAL_MAX_COMPONENTS 4
  14823. +
  14824. +/*#define FULL_MSG_DUMP 1*/
  14825. +
  14826. +#ifdef DEBUG
  14827. +static const char *const msg_type_names[] = {
  14828. + "UNKNOWN",
  14829. + "QUIT",
  14830. + "SERVICE_CLOSED",
  14831. + "GET_VERSION",
  14832. + "COMPONENT_CREATE",
  14833. + "COMPONENT_DESTROY",
  14834. + "COMPONENT_ENABLE",
  14835. + "COMPONENT_DISABLE",
  14836. + "PORT_INFO_GET",
  14837. + "PORT_INFO_SET",
  14838. + "PORT_ACTION",
  14839. + "BUFFER_FROM_HOST",
  14840. + "BUFFER_TO_HOST",
  14841. + "GET_STATS",
  14842. + "PORT_PARAMETER_SET",
  14843. + "PORT_PARAMETER_GET",
  14844. + "EVENT_TO_HOST",
  14845. + "GET_CORE_STATS_FOR_PORT",
  14846. + "OPAQUE_ALLOCATOR",
  14847. + "CONSUME_MEM",
  14848. + "LMK",
  14849. + "OPAQUE_ALLOCATOR_DESC",
  14850. + "DRM_GET_LHS32",
  14851. + "DRM_GET_TIME",
  14852. + "BUFFER_FROM_HOST_ZEROLEN",
  14853. + "PORT_FLUSH",
  14854. + "HOST_LOG",
  14855. +};
  14856. +#endif
  14857. +
  14858. +static const char *const port_action_type_names[] = {
  14859. + "UNKNOWN",
  14860. + "ENABLE",
  14861. + "DISABLE",
  14862. + "FLUSH",
  14863. + "CONNECT",
  14864. + "DISCONNECT",
  14865. + "SET_REQUIREMENTS",
  14866. +};
  14867. +
  14868. +#if defined(DEBUG)
  14869. +#if defined(FULL_MSG_DUMP)
  14870. +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE) \
  14871. + do { \
  14872. + pr_debug(TITLE" type:%s(%d) length:%d\n", \
  14873. + msg_type_names[(MSG)->h.type], \
  14874. + (MSG)->h.type, (MSG_LEN)); \
  14875. + print_hex_dump(KERN_DEBUG, "<<h: ", DUMP_PREFIX_OFFSET, \
  14876. + 16, 4, (MSG), \
  14877. + sizeof(struct mmal_msg_header), 1); \
  14878. + print_hex_dump(KERN_DEBUG, "<<p: ", DUMP_PREFIX_OFFSET, \
  14879. + 16, 4, \
  14880. + ((u8 *)(MSG)) + sizeof(struct mmal_msg_header),\
  14881. + (MSG_LEN) - sizeof(struct mmal_msg_header), 1); \
  14882. + } while (0)
  14883. +#else
  14884. +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE) \
  14885. + { \
  14886. + pr_debug(TITLE" type:%s(%d) length:%d\n", \
  14887. + msg_type_names[(MSG)->h.type], \
  14888. + (MSG)->h.type, (MSG_LEN)); \
  14889. + }
  14890. +#endif
  14891. +#else
  14892. +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE)
  14893. +#endif
  14894. +
  14895. +/* normal message context */
  14896. +struct mmal_msg_context {
  14897. + union {
  14898. + struct {
  14899. + /* work struct for defered callback - must come first */
  14900. + struct work_struct work;
  14901. + /* mmal instance */
  14902. + struct vchiq_mmal_instance *instance;
  14903. + /* mmal port */
  14904. + struct vchiq_mmal_port *port;
  14905. + /* actual buffer used to store bulk reply */
  14906. + struct mmal_buffer *buffer;
  14907. + /* amount of buffer used */
  14908. + unsigned long buffer_used;
  14909. + /* MMAL buffer flags */
  14910. + u32 mmal_flags;
  14911. + /* Presentation and Decode timestamps */
  14912. + s64 pts;
  14913. + s64 dts;
  14914. +
  14915. + int status; /* context status */
  14916. +
  14917. + } bulk; /* bulk data */
  14918. +
  14919. + struct {
  14920. + /* message handle to release */
  14921. + VCHI_HELD_MSG_T msg_handle;
  14922. + /* pointer to received message */
  14923. + struct mmal_msg *msg;
  14924. + /* received message length */
  14925. + u32 msg_len;
  14926. + /* completion upon reply */
  14927. + struct completion cmplt;
  14928. + } sync; /* synchronous response */
  14929. + } u;
  14930. +
  14931. +};
  14932. +
  14933. +struct vchiq_mmal_instance {
  14934. + VCHI_SERVICE_HANDLE_T handle;
  14935. +
  14936. + /* ensure serialised access to service */
  14937. + struct mutex vchiq_mutex;
  14938. +
  14939. + /* ensure serialised access to bulk operations */
  14940. + struct mutex bulk_mutex;
  14941. +
  14942. + /* vmalloc page to receive scratch bulk xfers into */
  14943. + void *bulk_scratch;
  14944. +
  14945. + /* component to use next */
  14946. + int component_idx;
  14947. + struct vchiq_mmal_component component[VCHIQ_MMAL_MAX_COMPONENTS];
  14948. +};
  14949. +
  14950. +static struct mmal_msg_context *get_msg_context(struct vchiq_mmal_instance
  14951. + *instance)
  14952. +{
  14953. + struct mmal_msg_context *msg_context;
  14954. +
  14955. + /* todo: should this be allocated from a pool to avoid kmalloc */
  14956. + msg_context = kmalloc(sizeof(*msg_context), GFP_KERNEL);
  14957. + memset(msg_context, 0, sizeof(*msg_context));
  14958. +
  14959. + return msg_context;
  14960. +}
  14961. +
  14962. +static void release_msg_context(struct mmal_msg_context *msg_context)
  14963. +{
  14964. + kfree(msg_context);
  14965. +}
  14966. +
  14967. +/* deals with receipt of event to host message */
  14968. +static void event_to_host_cb(struct vchiq_mmal_instance *instance,
  14969. + struct mmal_msg *msg, u32 msg_len)
  14970. +{
  14971. + pr_debug("unhandled event\n");
  14972. + pr_debug("component:%p port type:%d num:%d cmd:0x%x length:%d\n",
  14973. + msg->u.event_to_host.client_component,
  14974. + msg->u.event_to_host.port_type,
  14975. + msg->u.event_to_host.port_num,
  14976. + msg->u.event_to_host.cmd, msg->u.event_to_host.length);
  14977. +}
  14978. +
  14979. +/* workqueue scheduled callback
  14980. + *
  14981. + * we do this because it is important we do not call any other vchiq
  14982. + * sync calls from witin the message delivery thread
  14983. + */
  14984. +static void buffer_work_cb(struct work_struct *work)
  14985. +{
  14986. + struct mmal_msg_context *msg_context = (struct mmal_msg_context *)work;
  14987. +
  14988. + msg_context->u.bulk.port->buffer_cb(msg_context->u.bulk.instance,
  14989. + msg_context->u.bulk.port,
  14990. + msg_context->u.bulk.status,
  14991. + msg_context->u.bulk.buffer,
  14992. + msg_context->u.bulk.buffer_used,
  14993. + msg_context->u.bulk.mmal_flags,
  14994. + msg_context->u.bulk.dts,
  14995. + msg_context->u.bulk.pts);
  14996. +
  14997. + /* release message context */
  14998. + release_msg_context(msg_context);
  14999. +}
  15000. +
  15001. +/* enqueue a bulk receive for a given message context */
  15002. +static int bulk_receive(struct vchiq_mmal_instance *instance,
  15003. + struct mmal_msg *msg,
  15004. + struct mmal_msg_context *msg_context)
  15005. +{
  15006. + unsigned long rd_len;
  15007. + unsigned long flags = 0;
  15008. + int ret;
  15009. +
  15010. + /* bulk mutex stops other bulk operations while we have a
  15011. + * receive in progress - released in callback
  15012. + */
  15013. + ret = mutex_lock_interruptible(&instance->bulk_mutex);
  15014. + if (ret != 0)
  15015. + return ret;
  15016. +
  15017. + rd_len = msg->u.buffer_from_host.buffer_header.length;
  15018. +
  15019. + /* take buffer from queue */
  15020. + spin_lock_irqsave(&msg_context->u.bulk.port->slock, flags);
  15021. + if (list_empty(&msg_context->u.bulk.port->buffers)) {
  15022. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  15023. + pr_err("buffer list empty trying to submit bulk receive\n");
  15024. +
  15025. + /* todo: this is a serious error, we should never have
  15026. + * commited a buffer_to_host operation to the mmal
  15027. + * port without the buffer to back it up (underflow
  15028. + * handling) and there is no obvious way to deal with
  15029. + * this - how is the mmal servie going to react when
  15030. + * we fail to do the xfer and reschedule a buffer when
  15031. + * it arrives? perhaps a starved flag to indicate a
  15032. + * waiting bulk receive?
  15033. + */
  15034. +
  15035. + mutex_unlock(&instance->bulk_mutex);
  15036. +
  15037. + return -EINVAL;
  15038. + }
  15039. +
  15040. + msg_context->u.bulk.buffer =
  15041. + list_entry(msg_context->u.bulk.port->buffers.next,
  15042. + struct mmal_buffer, list);
  15043. + list_del(&msg_context->u.bulk.buffer->list);
  15044. +
  15045. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  15046. +
  15047. + /* ensure we do not overrun the available buffer */
  15048. + if (rd_len > msg_context->u.bulk.buffer->buffer_size) {
  15049. + rd_len = msg_context->u.bulk.buffer->buffer_size;
  15050. + pr_warn("short read as not enough receive buffer space\n");
  15051. + /* todo: is this the correct response, what happens to
  15052. + * the rest of the message data?
  15053. + */
  15054. + }
  15055. +
  15056. + /* store length */
  15057. + msg_context->u.bulk.buffer_used = rd_len;
  15058. + msg_context->u.bulk.mmal_flags =
  15059. + msg->u.buffer_from_host.buffer_header.flags;
  15060. + msg_context->u.bulk.dts = msg->u.buffer_from_host.buffer_header.dts;
  15061. + msg_context->u.bulk.pts = msg->u.buffer_from_host.buffer_header.pts;
  15062. +
  15063. + // only need to flush L1 cache here, as VCHIQ takes care of the L2
  15064. + // cache.
  15065. + __cpuc_flush_dcache_area(msg_context->u.bulk.buffer->buffer, rd_len);
  15066. +
  15067. + /* queue the bulk submission */
  15068. + vchi_service_use(instance->handle);
  15069. + ret = vchi_bulk_queue_receive(instance->handle,
  15070. + msg_context->u.bulk.buffer->buffer,
  15071. + /* Actual receive needs to be a multiple
  15072. + * of 4 bytes
  15073. + */
  15074. + (rd_len + 3) & ~3,
  15075. + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE |
  15076. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED,
  15077. + msg_context);
  15078. +
  15079. + vchi_service_release(instance->handle);
  15080. +
  15081. + if (ret != 0) {
  15082. + /* callback will not be clearing the mutex */
  15083. + mutex_unlock(&instance->bulk_mutex);
  15084. + }
  15085. +
  15086. + return ret;
  15087. +}
  15088. +
  15089. +/* enque a dummy bulk receive for a given message context */
  15090. +static int dummy_bulk_receive(struct vchiq_mmal_instance *instance,
  15091. + struct mmal_msg_context *msg_context)
  15092. +{
  15093. + int ret;
  15094. +
  15095. + /* bulk mutex stops other bulk operations while we have a
  15096. + * receive in progress - released in callback
  15097. + */
  15098. + ret = mutex_lock_interruptible(&instance->bulk_mutex);
  15099. + if (ret != 0)
  15100. + return ret;
  15101. +
  15102. + /* zero length indicates this was a dummy transfer */
  15103. + msg_context->u.bulk.buffer_used = 0;
  15104. +
  15105. + /* queue the bulk submission */
  15106. + vchi_service_use(instance->handle);
  15107. +
  15108. + ret = vchi_bulk_queue_receive(instance->handle,
  15109. + instance->bulk_scratch,
  15110. + 8,
  15111. + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE |
  15112. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED,
  15113. + msg_context);
  15114. +
  15115. + vchi_service_release(instance->handle);
  15116. +
  15117. + if (ret != 0) {
  15118. + /* callback will not be clearing the mutex */
  15119. + mutex_unlock(&instance->bulk_mutex);
  15120. + }
  15121. +
  15122. + return ret;
  15123. +}
  15124. +
  15125. +/* data in message, memcpy from packet into output buffer */
  15126. +static int inline_receive(struct vchiq_mmal_instance *instance,
  15127. + struct mmal_msg *msg,
  15128. + struct mmal_msg_context *msg_context)
  15129. +{
  15130. + unsigned long flags = 0;
  15131. +
  15132. + /* take buffer from queue */
  15133. + spin_lock_irqsave(&msg_context->u.bulk.port->slock, flags);
  15134. + if (list_empty(&msg_context->u.bulk.port->buffers)) {
  15135. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  15136. + pr_err("buffer list empty trying to receive inline\n");
  15137. +
  15138. + /* todo: this is a serious error, we should never have
  15139. + * commited a buffer_to_host operation to the mmal
  15140. + * port without the buffer to back it up (with
  15141. + * underflow handling) and there is no obvious way to
  15142. + * deal with this. Less bad than the bulk case as we
  15143. + * can just drop this on the floor but...unhelpful
  15144. + */
  15145. + return -EINVAL;
  15146. + }
  15147. +
  15148. + msg_context->u.bulk.buffer =
  15149. + list_entry(msg_context->u.bulk.port->buffers.next,
  15150. + struct mmal_buffer, list);
  15151. + list_del(&msg_context->u.bulk.buffer->list);
  15152. +
  15153. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  15154. +
  15155. + memcpy(msg_context->u.bulk.buffer->buffer,
  15156. + msg->u.buffer_from_host.short_data,
  15157. + msg->u.buffer_from_host.payload_in_message);
  15158. +
  15159. + msg_context->u.bulk.buffer_used =
  15160. + msg->u.buffer_from_host.payload_in_message;
  15161. +
  15162. + return 0;
  15163. +}
  15164. +
  15165. +/* queue the buffer availability with MMAL_MSG_TYPE_BUFFER_FROM_HOST */
  15166. +static int
  15167. +buffer_from_host(struct vchiq_mmal_instance *instance,
  15168. + struct vchiq_mmal_port *port, struct mmal_buffer *buf)
  15169. +{
  15170. + struct mmal_msg_context *msg_context;
  15171. + struct mmal_msg m;
  15172. + int ret;
  15173. +
  15174. + pr_debug("instance:%p buffer:%p\n", instance->handle, buf);
  15175. +
  15176. + /* bulk mutex stops other bulk operations while we
  15177. + * have a receive in progress
  15178. + */
  15179. + if (mutex_lock_interruptible(&instance->bulk_mutex))
  15180. + return -EINTR;
  15181. +
  15182. + /* get context */
  15183. + msg_context = get_msg_context(instance);
  15184. + if (msg_context == NULL)
  15185. + return -ENOMEM;
  15186. +
  15187. + /* store bulk message context for when data arrives */
  15188. + msg_context->u.bulk.instance = instance;
  15189. + msg_context->u.bulk.port = port;
  15190. + msg_context->u.bulk.buffer = NULL; /* not valid until bulk xfer */
  15191. + msg_context->u.bulk.buffer_used = 0;
  15192. +
  15193. + /* initialise work structure ready to schedule callback */
  15194. + INIT_WORK(&msg_context->u.bulk.work, buffer_work_cb);
  15195. +
  15196. + /* prep the buffer from host message */
  15197. + memset(&m, 0xbc, sizeof(m)); /* just to make debug clearer */
  15198. +
  15199. + m.h.type = MMAL_MSG_TYPE_BUFFER_FROM_HOST;
  15200. + m.h.magic = MMAL_MAGIC;
  15201. + m.h.context = msg_context;
  15202. + m.h.status = 0;
  15203. +
  15204. + /* drvbuf is our private data passed back */
  15205. + m.u.buffer_from_host.drvbuf.magic = MMAL_MAGIC;
  15206. + m.u.buffer_from_host.drvbuf.component_handle = port->component->handle;
  15207. + m.u.buffer_from_host.drvbuf.port_handle = port->handle;
  15208. + m.u.buffer_from_host.drvbuf.client_context = msg_context;
  15209. +
  15210. + /* buffer header */
  15211. + m.u.buffer_from_host.buffer_header.cmd = 0;
  15212. + m.u.buffer_from_host.buffer_header.data = buf->buffer;
  15213. + m.u.buffer_from_host.buffer_header.alloc_size = buf->buffer_size;
  15214. + m.u.buffer_from_host.buffer_header.length = 0; /* nothing used yet */
  15215. + m.u.buffer_from_host.buffer_header.offset = 0; /* no offset */
  15216. + m.u.buffer_from_host.buffer_header.flags = 0; /* no flags */
  15217. + m.u.buffer_from_host.buffer_header.pts = MMAL_TIME_UNKNOWN;
  15218. + m.u.buffer_from_host.buffer_header.dts = MMAL_TIME_UNKNOWN;
  15219. +
  15220. + /* clear buffer type sepecific data */
  15221. + memset(&m.u.buffer_from_host.buffer_header_type_specific, 0,
  15222. + sizeof(m.u.buffer_from_host.buffer_header_type_specific));
  15223. +
  15224. + /* no payload in message */
  15225. + m.u.buffer_from_host.payload_in_message = 0;
  15226. +
  15227. + vchi_service_use(instance->handle);
  15228. +
  15229. + ret = vchi_msg_queue(instance->handle, &m,
  15230. + sizeof(struct mmal_msg_header) +
  15231. + sizeof(m.u.buffer_from_host),
  15232. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  15233. +
  15234. + if (ret != 0) {
  15235. + release_msg_context(msg_context);
  15236. + /* todo: is this correct error value? */
  15237. + }
  15238. +
  15239. + vchi_service_release(instance->handle);
  15240. +
  15241. + mutex_unlock(&instance->bulk_mutex);
  15242. +
  15243. + return ret;
  15244. +}
  15245. +
  15246. +/* submit a buffer to the mmal sevice
  15247. + *
  15248. + * the buffer_from_host uses size data from the ports next available
  15249. + * mmal_buffer and deals with there being no buffer available by
  15250. + * incrementing the underflow for later
  15251. + */
  15252. +static int port_buffer_from_host(struct vchiq_mmal_instance *instance,
  15253. + struct vchiq_mmal_port *port)
  15254. +{
  15255. + int ret;
  15256. + struct mmal_buffer *buf;
  15257. + unsigned long flags = 0;
  15258. +
  15259. + if (!port->enabled)
  15260. + return -EINVAL;
  15261. +
  15262. + /* peek buffer from queue */
  15263. + spin_lock_irqsave(&port->slock, flags);
  15264. + if (list_empty(&port->buffers)) {
  15265. + port->buffer_underflow++;
  15266. + spin_unlock_irqrestore(&port->slock, flags);
  15267. + return -ENOSPC;
  15268. + }
  15269. +
  15270. + buf = list_entry(port->buffers.next, struct mmal_buffer, list);
  15271. +
  15272. + spin_unlock_irqrestore(&port->slock, flags);
  15273. +
  15274. + /* issue buffer to mmal service */
  15275. + ret = buffer_from_host(instance, port, buf);
  15276. + if (ret) {
  15277. + pr_err("adding buffer header failed\n");
  15278. + /* todo: how should this be dealt with */
  15279. + }
  15280. +
  15281. + return ret;
  15282. +}
  15283. +
  15284. +/* deals with receipt of buffer to host message */
  15285. +static void buffer_to_host_cb(struct vchiq_mmal_instance *instance,
  15286. + struct mmal_msg *msg, u32 msg_len)
  15287. +{
  15288. + struct mmal_msg_context *msg_context;
  15289. +
  15290. + pr_debug("buffer_to_host_cb: instance:%p msg:%p msg_len:%d\n",
  15291. + instance, msg, msg_len);
  15292. +
  15293. + if (msg->u.buffer_from_host.drvbuf.magic == MMAL_MAGIC) {
  15294. + msg_context = msg->u.buffer_from_host.drvbuf.client_context;
  15295. + } else {
  15296. + pr_err("MMAL_MSG_TYPE_BUFFER_TO_HOST with bad magic\n");
  15297. + return;
  15298. + }
  15299. +
  15300. + if (msg->h.status != MMAL_MSG_STATUS_SUCCESS) {
  15301. + /* message reception had an error */
  15302. + pr_warn("error %d in reply\n", msg->h.status);
  15303. +
  15304. + msg_context->u.bulk.status = msg->h.status;
  15305. +
  15306. + } else if (msg->u.buffer_from_host.buffer_header.length == 0) {
  15307. + /* empty buffer */
  15308. + if (msg->u.buffer_from_host.buffer_header.flags &
  15309. + MMAL_BUFFER_HEADER_FLAG_EOS) {
  15310. + msg_context->u.bulk.status =
  15311. + dummy_bulk_receive(instance, msg_context);
  15312. + if (msg_context->u.bulk.status == 0)
  15313. + return; /* successful bulk submission, bulk
  15314. + * completion will trigger callback
  15315. + */
  15316. + } else {
  15317. + /* do callback with empty buffer - not EOS though */
  15318. + msg_context->u.bulk.status = 0;
  15319. + msg_context->u.bulk.buffer_used = 0;
  15320. + }
  15321. + } else if (msg->u.buffer_from_host.payload_in_message == 0) {
  15322. + /* data is not in message, queue a bulk receive */
  15323. + msg_context->u.bulk.status =
  15324. + bulk_receive(instance, msg, msg_context);
  15325. + if (msg_context->u.bulk.status == 0)
  15326. + return; /* successful bulk submission, bulk
  15327. + * completion will trigger callback
  15328. + */
  15329. +
  15330. + /* failed to submit buffer, this will end badly */
  15331. + pr_err("error %d on bulk submission\n",
  15332. + msg_context->u.bulk.status);
  15333. +
  15334. + } else if (msg->u.buffer_from_host.payload_in_message <=
  15335. + MMAL_VC_SHORT_DATA) {
  15336. + /* data payload within message */
  15337. + msg_context->u.bulk.status = inline_receive(instance, msg,
  15338. + msg_context);
  15339. + } else {
  15340. + pr_err("message with invalid short payload\n");
  15341. +
  15342. + /* signal error */
  15343. + msg_context->u.bulk.status = -EINVAL;
  15344. + msg_context->u.bulk.buffer_used =
  15345. + msg->u.buffer_from_host.payload_in_message;
  15346. + }
  15347. +
  15348. + /* replace the buffer header */
  15349. + port_buffer_from_host(instance, msg_context->u.bulk.port);
  15350. +
  15351. + /* schedule the port callback */
  15352. + schedule_work(&msg_context->u.bulk.work);
  15353. +}
  15354. +
  15355. +static void bulk_receive_cb(struct vchiq_mmal_instance *instance,
  15356. + struct mmal_msg_context *msg_context)
  15357. +{
  15358. + /* bulk receive operation complete */
  15359. + mutex_unlock(&msg_context->u.bulk.instance->bulk_mutex);
  15360. +
  15361. + /* replace the buffer header */
  15362. + port_buffer_from_host(msg_context->u.bulk.instance,
  15363. + msg_context->u.bulk.port);
  15364. +
  15365. + msg_context->u.bulk.status = 0;
  15366. +
  15367. + /* schedule the port callback */
  15368. + schedule_work(&msg_context->u.bulk.work);
  15369. +}
  15370. +
  15371. +static void bulk_abort_cb(struct vchiq_mmal_instance *instance,
  15372. + struct mmal_msg_context *msg_context)
  15373. +{
  15374. + pr_err("%s: bulk ABORTED msg_context:%p\n", __func__, msg_context);
  15375. +
  15376. + /* bulk receive operation complete */
  15377. + mutex_unlock(&msg_context->u.bulk.instance->bulk_mutex);
  15378. +
  15379. + /* replace the buffer header */
  15380. + port_buffer_from_host(msg_context->u.bulk.instance,
  15381. + msg_context->u.bulk.port);
  15382. +
  15383. + msg_context->u.bulk.status = -EINTR;
  15384. +
  15385. + schedule_work(&msg_context->u.bulk.work);
  15386. +}
  15387. +
  15388. +/* incoming event service callback */
  15389. +static void service_callback(void *param,
  15390. + const VCHI_CALLBACK_REASON_T reason,
  15391. + void *bulk_ctx)
  15392. +{
  15393. + struct vchiq_mmal_instance *instance = param;
  15394. + int status;
  15395. + u32 msg_len;
  15396. + struct mmal_msg *msg;
  15397. + VCHI_HELD_MSG_T msg_handle;
  15398. +
  15399. + if (!instance) {
  15400. + pr_err("Message callback passed NULL instance\n");
  15401. + return;
  15402. + }
  15403. +
  15404. + switch (reason) {
  15405. + case VCHI_CALLBACK_MSG_AVAILABLE:
  15406. + status = vchi_msg_hold(instance->handle, (void **)&msg,
  15407. + &msg_len, VCHI_FLAGS_NONE, &msg_handle);
  15408. + if (status) {
  15409. + pr_err("Unable to dequeue a message (%d)\n", status);
  15410. + break;
  15411. + }
  15412. +
  15413. + DBG_DUMP_MSG(msg, msg_len, "<<< reply message");
  15414. +
  15415. + /* handling is different for buffer messages */
  15416. + switch (msg->h.type) {
  15417. +
  15418. + case MMAL_MSG_TYPE_BUFFER_FROM_HOST:
  15419. + vchi_held_msg_release(&msg_handle);
  15420. + break;
  15421. +
  15422. + case MMAL_MSG_TYPE_EVENT_TO_HOST:
  15423. + event_to_host_cb(instance, msg, msg_len);
  15424. + vchi_held_msg_release(&msg_handle);
  15425. +
  15426. + break;
  15427. +
  15428. + case MMAL_MSG_TYPE_BUFFER_TO_HOST:
  15429. + buffer_to_host_cb(instance, msg, msg_len);
  15430. + vchi_held_msg_release(&msg_handle);
  15431. + break;
  15432. +
  15433. + default:
  15434. + /* messages dependant on header context to complete */
  15435. +
  15436. + /* todo: the msg.context really ought to be sanity
  15437. + * checked before we just use it, afaict it comes back
  15438. + * and is used raw from the videocore. Perhaps it
  15439. + * should be verified the address lies in the kernel
  15440. + * address space.
  15441. + */
  15442. + if (msg->h.context == NULL) {
  15443. + pr_err("received message context was null!\n");
  15444. + vchi_held_msg_release(&msg_handle);
  15445. + break;
  15446. + }
  15447. +
  15448. + /* fill in context values */
  15449. + msg->h.context->u.sync.msg_handle = msg_handle;
  15450. + msg->h.context->u.sync.msg = msg;
  15451. + msg->h.context->u.sync.msg_len = msg_len;
  15452. +
  15453. + /* todo: should this check (completion_done()
  15454. + * == 1) for no one waiting? or do we need a
  15455. + * flag to tell us the completion has been
  15456. + * interrupted so we can free the message and
  15457. + * its context. This probably also solves the
  15458. + * message arriving after interruption todo
  15459. + * below
  15460. + */
  15461. +
  15462. + /* complete message so caller knows it happened */
  15463. + complete(&msg->h.context->u.sync.cmplt);
  15464. + break;
  15465. + }
  15466. +
  15467. + break;
  15468. +
  15469. + case VCHI_CALLBACK_BULK_RECEIVED:
  15470. + bulk_receive_cb(instance, bulk_ctx);
  15471. + break;
  15472. +
  15473. + case VCHI_CALLBACK_BULK_RECEIVE_ABORTED:
  15474. + bulk_abort_cb(instance, bulk_ctx);
  15475. + break;
  15476. +
  15477. + case VCHI_CALLBACK_SERVICE_CLOSED:
  15478. + /* TODO: consider if this requires action if received when
  15479. + * driver is not explicitly closing the service
  15480. + */
  15481. + break;
  15482. +
  15483. + default:
  15484. + pr_err("Received unhandled message reason %d\n", reason);
  15485. + break;
  15486. + }
  15487. +}
  15488. +
  15489. +static int send_synchronous_mmal_msg(struct vchiq_mmal_instance *instance,
  15490. + struct mmal_msg *msg,
  15491. + unsigned int payload_len,
  15492. + struct mmal_msg **msg_out,
  15493. + VCHI_HELD_MSG_T *msg_handle_out)
  15494. +{
  15495. + struct mmal_msg_context msg_context;
  15496. + int ret;
  15497. +
  15498. + /* payload size must not cause message to exceed max size */
  15499. + if (payload_len >
  15500. + (MMAL_MSG_MAX_SIZE - sizeof(struct mmal_msg_header))) {
  15501. + pr_err("payload length %d exceeds max:%d\n", payload_len,
  15502. + (MMAL_MSG_MAX_SIZE - sizeof(struct mmal_msg_header)));
  15503. + return -EINVAL;
  15504. + }
  15505. +
  15506. + init_completion(&msg_context.u.sync.cmplt);
  15507. +
  15508. + msg->h.magic = MMAL_MAGIC;
  15509. + msg->h.context = &msg_context;
  15510. + msg->h.status = 0;
  15511. +
  15512. + DBG_DUMP_MSG(msg, (sizeof(struct mmal_msg_header) + payload_len),
  15513. + ">>> sync message");
  15514. +
  15515. + vchi_service_use(instance->handle);
  15516. +
  15517. + ret = vchi_msg_queue(instance->handle,
  15518. + msg,
  15519. + sizeof(struct mmal_msg_header) + payload_len,
  15520. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  15521. +
  15522. + vchi_service_release(instance->handle);
  15523. +
  15524. + if (ret) {
  15525. + pr_err("error %d queuing message\n", ret);
  15526. + return ret;
  15527. + }
  15528. +
  15529. + ret = wait_for_completion_timeout(&msg_context.u.sync.cmplt, HZ);
  15530. + if (ret <= 0) {
  15531. + pr_err("error %d waiting for sync completion\n", ret);
  15532. + if (ret == 0)
  15533. + ret = -ETIME;
  15534. + /* todo: what happens if the message arrives after aborting */
  15535. + return ret;
  15536. + }
  15537. +
  15538. + *msg_out = msg_context.u.sync.msg;
  15539. + *msg_handle_out = msg_context.u.sync.msg_handle;
  15540. +
  15541. + return 0;
  15542. +}
  15543. +
  15544. +static void dump_port_info(struct vchiq_mmal_port *port)
  15545. +{
  15546. + pr_debug("port handle:0x%x enabled:%d\n", port->handle, port->enabled);
  15547. +
  15548. + pr_debug("buffer minimum num:%d size:%d align:%d\n",
  15549. + port->minimum_buffer.num,
  15550. + port->minimum_buffer.size, port->minimum_buffer.alignment);
  15551. +
  15552. + pr_debug("buffer recommended num:%d size:%d align:%d\n",
  15553. + port->recommended_buffer.num,
  15554. + port->recommended_buffer.size,
  15555. + port->recommended_buffer.alignment);
  15556. +
  15557. + pr_debug("buffer current values num:%d size:%d align:%d\n",
  15558. + port->current_buffer.num,
  15559. + port->current_buffer.size, port->current_buffer.alignment);
  15560. +
  15561. + pr_debug("elementry stream: type:%d encoding:0x%x varient:0x%x\n",
  15562. + port->format.type,
  15563. + port->format.encoding, port->format.encoding_variant);
  15564. +
  15565. + pr_debug(" bitrate:%d flags:0x%x\n",
  15566. + port->format.bitrate, port->format.flags);
  15567. +
  15568. + if (port->format.type == MMAL_ES_TYPE_VIDEO) {
  15569. + pr_debug
  15570. + ("es video format: width:%d height:%d colourspace:0x%x\n",
  15571. + port->es.video.width, port->es.video.height,
  15572. + port->es.video.color_space);
  15573. +
  15574. + pr_debug(" : crop xywh %d,%d,%d,%d\n",
  15575. + port->es.video.crop.x,
  15576. + port->es.video.crop.y,
  15577. + port->es.video.crop.width, port->es.video.crop.height);
  15578. + pr_debug(" : framerate %d/%d aspect %d/%d\n",
  15579. + port->es.video.frame_rate.num,
  15580. + port->es.video.frame_rate.den,
  15581. + port->es.video.par.num, port->es.video.par.den);
  15582. + }
  15583. +}
  15584. +
  15585. +static void port_to_mmal_msg(struct vchiq_mmal_port *port, struct mmal_port *p)
  15586. +{
  15587. +
  15588. + /* todo do readonly fields need setting at all? */
  15589. + p->type = port->type;
  15590. + p->index = port->index;
  15591. + p->index_all = 0;
  15592. + p->is_enabled = port->enabled;
  15593. + p->buffer_num_min = port->minimum_buffer.num;
  15594. + p->buffer_size_min = port->minimum_buffer.size;
  15595. + p->buffer_alignment_min = port->minimum_buffer.alignment;
  15596. + p->buffer_num_recommended = port->recommended_buffer.num;
  15597. + p->buffer_size_recommended = port->recommended_buffer.size;
  15598. +
  15599. + /* only three writable fields in a port */
  15600. + p->buffer_num = port->current_buffer.num;
  15601. + p->buffer_size = port->current_buffer.size;
  15602. + p->userdata = port;
  15603. +}
  15604. +
  15605. +static int port_info_set(struct vchiq_mmal_instance *instance,
  15606. + struct vchiq_mmal_port *port)
  15607. +{
  15608. + int ret;
  15609. + struct mmal_msg m;
  15610. + struct mmal_msg *rmsg;
  15611. + VCHI_HELD_MSG_T rmsg_handle;
  15612. +
  15613. + pr_debug("setting port info port %p\n", port);
  15614. + if (!port)
  15615. + return -1;
  15616. + dump_port_info(port);
  15617. +
  15618. + m.h.type = MMAL_MSG_TYPE_PORT_INFO_SET;
  15619. +
  15620. + m.u.port_info_set.component_handle = port->component->handle;
  15621. + m.u.port_info_set.port_type = port->type;
  15622. + m.u.port_info_set.port_index = port->index;
  15623. +
  15624. + port_to_mmal_msg(port, &m.u.port_info_set.port);
  15625. +
  15626. + /* elementry stream format setup */
  15627. + m.u.port_info_set.format.type = port->format.type;
  15628. + m.u.port_info_set.format.encoding = port->format.encoding;
  15629. + m.u.port_info_set.format.encoding_variant =
  15630. + port->format.encoding_variant;
  15631. + m.u.port_info_set.format.bitrate = port->format.bitrate;
  15632. + m.u.port_info_set.format.flags = port->format.flags;
  15633. +
  15634. + memcpy(&m.u.port_info_set.es, &port->es,
  15635. + sizeof(union mmal_es_specific_format));
  15636. +
  15637. + m.u.port_info_set.format.extradata_size = port->format.extradata_size;
  15638. + memcpy(rmsg->u.port_info_set.extradata, port->format.extradata,
  15639. + port->format.extradata_size);
  15640. +
  15641. + ret = send_synchronous_mmal_msg(instance, &m,
  15642. + sizeof(m.u.port_info_set),
  15643. + &rmsg, &rmsg_handle);
  15644. + if (ret)
  15645. + return ret;
  15646. +
  15647. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_INFO_SET) {
  15648. + /* got an unexpected message type in reply */
  15649. + ret = -EINVAL;
  15650. + goto release_msg;
  15651. + }
  15652. +
  15653. + /* return operation status */
  15654. + ret = -rmsg->u.port_info_get_reply.status;
  15655. +
  15656. + pr_debug("%s:result:%d component:0x%x port:%d\n", __func__, ret,
  15657. + port->component->handle, port->handle);
  15658. +
  15659. +release_msg:
  15660. + vchi_held_msg_release(&rmsg_handle);
  15661. +
  15662. + return ret;
  15663. +
  15664. +}
  15665. +
  15666. +/* use port info get message to retrive port information */
  15667. +static int port_info_get(struct vchiq_mmal_instance *instance,
  15668. + struct vchiq_mmal_port *port)
  15669. +{
  15670. + int ret;
  15671. + struct mmal_msg m;
  15672. + struct mmal_msg *rmsg;
  15673. + VCHI_HELD_MSG_T rmsg_handle;
  15674. +
  15675. + /* port info time */
  15676. + m.h.type = MMAL_MSG_TYPE_PORT_INFO_GET;
  15677. + m.u.port_info_get.component_handle = port->component->handle;
  15678. + m.u.port_info_get.port_type = port->type;
  15679. + m.u.port_info_get.index = port->index;
  15680. +
  15681. + ret = send_synchronous_mmal_msg(instance, &m,
  15682. + sizeof(m.u.port_info_get),
  15683. + &rmsg, &rmsg_handle);
  15684. + if (ret)
  15685. + return ret;
  15686. +
  15687. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_INFO_GET) {
  15688. + /* got an unexpected message type in reply */
  15689. + ret = -EINVAL;
  15690. + goto release_msg;
  15691. + }
  15692. +
  15693. + /* return operation status */
  15694. + ret = -rmsg->u.port_info_get_reply.status;
  15695. + if (ret != MMAL_MSG_STATUS_SUCCESS)
  15696. + goto release_msg;
  15697. +
  15698. + if (rmsg->u.port_info_get_reply.port.is_enabled == 0)
  15699. + port->enabled = false;
  15700. + else
  15701. + port->enabled = true;
  15702. +
  15703. + /* copy the values out of the message */
  15704. + port->handle = rmsg->u.port_info_get_reply.port_handle;
  15705. +
  15706. + /* port type and index cached to use on port info set becuase
  15707. + * it does not use a port handle
  15708. + */
  15709. + port->type = rmsg->u.port_info_get_reply.port_type;
  15710. + port->index = rmsg->u.port_info_get_reply.port_index;
  15711. +
  15712. + port->minimum_buffer.num =
  15713. + rmsg->u.port_info_get_reply.port.buffer_num_min;
  15714. + port->minimum_buffer.size =
  15715. + rmsg->u.port_info_get_reply.port.buffer_size_min;
  15716. + port->minimum_buffer.alignment =
  15717. + rmsg->u.port_info_get_reply.port.buffer_alignment_min;
  15718. +
  15719. + port->recommended_buffer.alignment =
  15720. + rmsg->u.port_info_get_reply.port.buffer_alignment_min;
  15721. + port->recommended_buffer.num =
  15722. + rmsg->u.port_info_get_reply.port.buffer_num_recommended;
  15723. +
  15724. + port->current_buffer.num = rmsg->u.port_info_get_reply.port.buffer_num;
  15725. + port->current_buffer.size =
  15726. + rmsg->u.port_info_get_reply.port.buffer_size;
  15727. +
  15728. + /* stream format */
  15729. + port->format.type = rmsg->u.port_info_get_reply.format.type;
  15730. + port->format.encoding = rmsg->u.port_info_get_reply.format.encoding;
  15731. + port->format.encoding_variant =
  15732. + rmsg->u.port_info_get_reply.format.encoding_variant;
  15733. + port->format.bitrate = rmsg->u.port_info_get_reply.format.bitrate;
  15734. + port->format.flags = rmsg->u.port_info_get_reply.format.flags;
  15735. +
  15736. + /* elementry stream format */
  15737. + memcpy(&port->es,
  15738. + &rmsg->u.port_info_get_reply.es,
  15739. + sizeof(union mmal_es_specific_format));
  15740. + port->format.es = &port->es;
  15741. +
  15742. + port->format.extradata_size =
  15743. + rmsg->u.port_info_get_reply.format.extradata_size;
  15744. + memcpy(port->format.extradata,
  15745. + rmsg->u.port_info_get_reply.extradata,
  15746. + port->format.extradata_size);
  15747. +
  15748. + pr_debug("received port info\n");
  15749. + dump_port_info(port);
  15750. +
  15751. +release_msg:
  15752. +
  15753. + pr_debug("%s:result:%d component:0x%x port:%d\n",
  15754. + __func__, ret, port->component->handle, port->handle);
  15755. +
  15756. + vchi_held_msg_release(&rmsg_handle);
  15757. +
  15758. + return ret;
  15759. +}
  15760. +
  15761. +/* create comonent on vc */
  15762. +static int create_component(struct vchiq_mmal_instance *instance,
  15763. + struct vchiq_mmal_component *component,
  15764. + const char *name)
  15765. +{
  15766. + int ret;
  15767. + struct mmal_msg m;
  15768. + struct mmal_msg *rmsg;
  15769. + VCHI_HELD_MSG_T rmsg_handle;
  15770. +
  15771. + /* build component create message */
  15772. + m.h.type = MMAL_MSG_TYPE_COMPONENT_CREATE;
  15773. + m.u.component_create.client_component = component;
  15774. + strncpy(m.u.component_create.name, name,
  15775. + sizeof(m.u.component_create.name));
  15776. +
  15777. + ret = send_synchronous_mmal_msg(instance, &m,
  15778. + sizeof(m.u.component_create),
  15779. + &rmsg, &rmsg_handle);
  15780. + if (ret)
  15781. + return ret;
  15782. +
  15783. + if (rmsg->h.type != m.h.type) {
  15784. + /* got an unexpected message type in reply */
  15785. + ret = -EINVAL;
  15786. + goto release_msg;
  15787. + }
  15788. +
  15789. + ret = -rmsg->u.component_create_reply.status;
  15790. + if (ret != MMAL_MSG_STATUS_SUCCESS)
  15791. + goto release_msg;
  15792. +
  15793. + /* a valid component response received */
  15794. + component->handle = rmsg->u.component_create_reply.component_handle;
  15795. + component->inputs = rmsg->u.component_create_reply.input_num;
  15796. + component->outputs = rmsg->u.component_create_reply.output_num;
  15797. + component->clocks = rmsg->u.component_create_reply.clock_num;
  15798. +
  15799. + pr_debug("Component handle:0x%x in:%d out:%d clock:%d\n",
  15800. + component->handle,
  15801. + component->inputs, component->outputs, component->clocks);
  15802. +
  15803. +release_msg:
  15804. + vchi_held_msg_release(&rmsg_handle);
  15805. +
  15806. + return ret;
  15807. +}
  15808. +
  15809. +/* destroys a component on vc */
  15810. +static int destroy_component(struct vchiq_mmal_instance *instance,
  15811. + struct vchiq_mmal_component *component)
  15812. +{
  15813. + int ret;
  15814. + struct mmal_msg m;
  15815. + struct mmal_msg *rmsg;
  15816. + VCHI_HELD_MSG_T rmsg_handle;
  15817. +
  15818. + m.h.type = MMAL_MSG_TYPE_COMPONENT_DESTROY;
  15819. + m.u.component_destroy.component_handle = component->handle;
  15820. +
  15821. + ret = send_synchronous_mmal_msg(instance, &m,
  15822. + sizeof(m.u.component_destroy),
  15823. + &rmsg, &rmsg_handle);
  15824. + if (ret)
  15825. + return ret;
  15826. +
  15827. + if (rmsg->h.type != m.h.type) {
  15828. + /* got an unexpected message type in reply */
  15829. + ret = -EINVAL;
  15830. + goto release_msg;
  15831. + }
  15832. +
  15833. + ret = -rmsg->u.component_destroy_reply.status;
  15834. +
  15835. +release_msg:
  15836. +
  15837. + vchi_held_msg_release(&rmsg_handle);
  15838. +
  15839. + return ret;
  15840. +}
  15841. +
  15842. +/* enable a component on vc */
  15843. +static int enable_component(struct vchiq_mmal_instance *instance,
  15844. + struct vchiq_mmal_component *component)
  15845. +{
  15846. + int ret;
  15847. + struct mmal_msg m;
  15848. + struct mmal_msg *rmsg;
  15849. + VCHI_HELD_MSG_T rmsg_handle;
  15850. +
  15851. + m.h.type = MMAL_MSG_TYPE_COMPONENT_ENABLE;
  15852. + m.u.component_enable.component_handle = component->handle;
  15853. +
  15854. + ret = send_synchronous_mmal_msg(instance, &m,
  15855. + sizeof(m.u.component_enable),
  15856. + &rmsg, &rmsg_handle);
  15857. + if (ret)
  15858. + return ret;
  15859. +
  15860. + if (rmsg->h.type != m.h.type) {
  15861. + /* got an unexpected message type in reply */
  15862. + ret = -EINVAL;
  15863. + goto release_msg;
  15864. + }
  15865. +
  15866. + ret = -rmsg->u.component_enable_reply.status;
  15867. +
  15868. +release_msg:
  15869. + vchi_held_msg_release(&rmsg_handle);
  15870. +
  15871. + return ret;
  15872. +}
  15873. +
  15874. +/* disable a component on vc */
  15875. +static int disable_component(struct vchiq_mmal_instance *instance,
  15876. + struct vchiq_mmal_component *component)
  15877. +{
  15878. + int ret;
  15879. + struct mmal_msg m;
  15880. + struct mmal_msg *rmsg;
  15881. + VCHI_HELD_MSG_T rmsg_handle;
  15882. +
  15883. + m.h.type = MMAL_MSG_TYPE_COMPONENT_DISABLE;
  15884. + m.u.component_disable.component_handle = component->handle;
  15885. +
  15886. + ret = send_synchronous_mmal_msg(instance, &m,
  15887. + sizeof(m.u.component_disable),
  15888. + &rmsg, &rmsg_handle);
  15889. + if (ret)
  15890. + return ret;
  15891. +
  15892. + if (rmsg->h.type != m.h.type) {
  15893. + /* got an unexpected message type in reply */
  15894. + ret = -EINVAL;
  15895. + goto release_msg;
  15896. + }
  15897. +
  15898. + ret = -rmsg->u.component_disable_reply.status;
  15899. +
  15900. +release_msg:
  15901. +
  15902. + vchi_held_msg_release(&rmsg_handle);
  15903. +
  15904. + return ret;
  15905. +}
  15906. +
  15907. +/* get version of mmal implementation */
  15908. +static int get_version(struct vchiq_mmal_instance *instance,
  15909. + u32 *major_out, u32 *minor_out)
  15910. +{
  15911. + int ret;
  15912. + struct mmal_msg m;
  15913. + struct mmal_msg *rmsg;
  15914. + VCHI_HELD_MSG_T rmsg_handle;
  15915. +
  15916. + m.h.type = MMAL_MSG_TYPE_GET_VERSION;
  15917. +
  15918. + ret = send_synchronous_mmal_msg(instance, &m,
  15919. + sizeof(m.u.version),
  15920. + &rmsg, &rmsg_handle);
  15921. + if (ret)
  15922. + return ret;
  15923. +
  15924. + if (rmsg->h.type != m.h.type) {
  15925. + /* got an unexpected message type in reply */
  15926. + ret = -EINVAL;
  15927. + goto release_msg;
  15928. + }
  15929. +
  15930. + *major_out = rmsg->u.version.major;
  15931. + *minor_out = rmsg->u.version.minor;
  15932. +
  15933. +release_msg:
  15934. + vchi_held_msg_release(&rmsg_handle);
  15935. +
  15936. + return ret;
  15937. +}
  15938. +
  15939. +/* do a port action with a port as a parameter */
  15940. +static int port_action_port(struct vchiq_mmal_instance *instance,
  15941. + struct vchiq_mmal_port *port,
  15942. + enum mmal_msg_port_action_type action_type)
  15943. +{
  15944. + int ret;
  15945. + struct mmal_msg m;
  15946. + struct mmal_msg *rmsg;
  15947. + VCHI_HELD_MSG_T rmsg_handle;
  15948. +
  15949. + m.h.type = MMAL_MSG_TYPE_PORT_ACTION;
  15950. + m.u.port_action_port.component_handle = port->component->handle;
  15951. + m.u.port_action_port.port_handle = port->handle;
  15952. + m.u.port_action_port.action = action_type;
  15953. +
  15954. + port_to_mmal_msg(port, &m.u.port_action_port.port);
  15955. +
  15956. + ret = send_synchronous_mmal_msg(instance, &m,
  15957. + sizeof(m.u.port_action_port),
  15958. + &rmsg, &rmsg_handle);
  15959. + if (ret)
  15960. + return ret;
  15961. +
  15962. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_ACTION) {
  15963. + /* got an unexpected message type in reply */
  15964. + ret = -EINVAL;
  15965. + goto release_msg;
  15966. + }
  15967. +
  15968. + ret = -rmsg->u.port_action_reply.status;
  15969. +
  15970. + pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d)\n",
  15971. + __func__,
  15972. + ret, port->component->handle, port->handle,
  15973. + port_action_type_names[action_type], action_type);
  15974. +
  15975. +release_msg:
  15976. + vchi_held_msg_release(&rmsg_handle);
  15977. +
  15978. + return ret;
  15979. +}
  15980. +
  15981. +/* do a port action with handles as parameters */
  15982. +static int port_action_handle(struct vchiq_mmal_instance *instance,
  15983. + struct vchiq_mmal_port *port,
  15984. + enum mmal_msg_port_action_type action_type,
  15985. + u32 connect_component_handle,
  15986. + u32 connect_port_handle)
  15987. +{
  15988. + int ret;
  15989. + struct mmal_msg m;
  15990. + struct mmal_msg *rmsg;
  15991. + VCHI_HELD_MSG_T rmsg_handle;
  15992. +
  15993. + m.h.type = MMAL_MSG_TYPE_PORT_ACTION;
  15994. +
  15995. + m.u.port_action_handle.component_handle = port->component->handle;
  15996. + m.u.port_action_handle.port_handle = port->handle;
  15997. + m.u.port_action_handle.action = action_type;
  15998. +
  15999. + m.u.port_action_handle.connect_component_handle =
  16000. + connect_component_handle;
  16001. + m.u.port_action_handle.connect_port_handle = connect_port_handle;
  16002. +
  16003. + ret = send_synchronous_mmal_msg(instance, &m,
  16004. + sizeof(m.u.port_action_handle),
  16005. + &rmsg, &rmsg_handle);
  16006. + if (ret)
  16007. + return ret;
  16008. +
  16009. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_ACTION) {
  16010. + /* got an unexpected message type in reply */
  16011. + ret = -EINVAL;
  16012. + goto release_msg;
  16013. + }
  16014. +
  16015. + ret = -rmsg->u.port_action_reply.status;
  16016. +
  16017. + pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d)" \
  16018. + " connect component:0x%x connect port:%d\n",
  16019. + __func__,
  16020. + ret, port->component->handle, port->handle,
  16021. + port_action_type_names[action_type],
  16022. + action_type, connect_component_handle, connect_port_handle);
  16023. +
  16024. +release_msg:
  16025. + vchi_held_msg_release(&rmsg_handle);
  16026. +
  16027. + return ret;
  16028. +}
  16029. +
  16030. +static int port_parameter_set(struct vchiq_mmal_instance *instance,
  16031. + struct vchiq_mmal_port *port,
  16032. + u32 parameter_id, void *value, u32 value_size)
  16033. +{
  16034. + int ret;
  16035. + struct mmal_msg m;
  16036. + struct mmal_msg *rmsg;
  16037. + VCHI_HELD_MSG_T rmsg_handle;
  16038. +
  16039. + m.h.type = MMAL_MSG_TYPE_PORT_PARAMETER_SET;
  16040. +
  16041. + m.u.port_parameter_set.component_handle = port->component->handle;
  16042. + m.u.port_parameter_set.port_handle = port->handle;
  16043. + m.u.port_parameter_set.id = parameter_id;
  16044. + m.u.port_parameter_set.size = (2 * sizeof(u32)) + value_size;
  16045. + memcpy(&m.u.port_parameter_set.value, value, value_size);
  16046. +
  16047. + ret = send_synchronous_mmal_msg(instance, &m,
  16048. + (4 * sizeof(u32)) + value_size,
  16049. + &rmsg, &rmsg_handle);
  16050. + if (ret)
  16051. + return ret;
  16052. +
  16053. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_PARAMETER_SET) {
  16054. + /* got an unexpected message type in reply */
  16055. + ret = -EINVAL;
  16056. + goto release_msg;
  16057. + }
  16058. +
  16059. + ret = -rmsg->u.port_parameter_set_reply.status;
  16060. +
  16061. + pr_debug("%s:result:%d component:0x%x port:%d parameter:%d\n",
  16062. + __func__,
  16063. + ret, port->component->handle, port->handle, parameter_id);
  16064. +
  16065. +release_msg:
  16066. + vchi_held_msg_release(&rmsg_handle);
  16067. +
  16068. + return ret;
  16069. +}
  16070. +
  16071. +static int port_parameter_get(struct vchiq_mmal_instance *instance,
  16072. + struct vchiq_mmal_port *port,
  16073. + u32 parameter_id, void *value, u32 *value_size)
  16074. +{
  16075. + int ret;
  16076. + struct mmal_msg m;
  16077. + struct mmal_msg *rmsg;
  16078. + VCHI_HELD_MSG_T rmsg_handle;
  16079. +
  16080. + m.h.type = MMAL_MSG_TYPE_PORT_PARAMETER_GET;
  16081. +
  16082. + m.u.port_parameter_get.component_handle = port->component->handle;
  16083. + m.u.port_parameter_get.port_handle = port->handle;
  16084. + m.u.port_parameter_get.id = parameter_id;
  16085. + m.u.port_parameter_get.size = (2 * sizeof(u32)) + *value_size;
  16086. +
  16087. + ret = send_synchronous_mmal_msg(instance, &m,
  16088. + sizeof(struct
  16089. + mmal_msg_port_parameter_get),
  16090. + &rmsg, &rmsg_handle);
  16091. + if (ret)
  16092. + return ret;
  16093. +
  16094. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_PARAMETER_GET) {
  16095. + /* got an unexpected message type in reply */
  16096. + pr_err("Incorrect reply type %d\n", rmsg->h.type);
  16097. + ret = -EINVAL;
  16098. + goto release_msg;
  16099. + }
  16100. +
  16101. + ret = -rmsg->u.port_parameter_get_reply.status;
  16102. + if (ret) {
  16103. + /* Copy only as much as we have space for
  16104. + * but report true size of parameter
  16105. + */
  16106. + memcpy(value, &rmsg->u.port_parameter_get_reply.value,
  16107. + *value_size);
  16108. + *value_size = rmsg->u.port_parameter_get_reply.size;
  16109. + } else
  16110. + memcpy(value, &rmsg->u.port_parameter_get_reply.value,
  16111. + rmsg->u.port_parameter_get_reply.size);
  16112. +
  16113. + pr_info("%s:result:%d component:0x%x port:%d parameter:%d\n", __func__,
  16114. + ret, port->component->handle, port->handle, parameter_id);
  16115. +
  16116. +release_msg:
  16117. + vchi_held_msg_release(&rmsg_handle);
  16118. +
  16119. + return ret;
  16120. +}
  16121. +
  16122. +/* disables a port and drains buffers from it */
  16123. +static int port_disable(struct vchiq_mmal_instance *instance,
  16124. + struct vchiq_mmal_port *port)
  16125. +{
  16126. + int ret;
  16127. + struct list_head *q, *buf_head;
  16128. + unsigned long flags = 0;
  16129. +
  16130. + if (!port->enabled)
  16131. + return 0;
  16132. +
  16133. + port->enabled = false;
  16134. +
  16135. + ret = port_action_port(instance, port,
  16136. + MMAL_MSG_PORT_ACTION_TYPE_DISABLE);
  16137. + if (ret == 0) {
  16138. +
  16139. + /* drain all queued buffers on port */
  16140. + spin_lock_irqsave(&port->slock, flags);
  16141. +
  16142. + list_for_each_safe(buf_head, q, &port->buffers) {
  16143. + struct mmal_buffer *mmalbuf;
  16144. + mmalbuf = list_entry(buf_head, struct mmal_buffer,
  16145. + list);
  16146. + list_del(buf_head);
  16147. + if (port->buffer_cb)
  16148. + port->buffer_cb(instance,
  16149. + port, 0, mmalbuf, 0, 0,
  16150. + MMAL_TIME_UNKNOWN,
  16151. + MMAL_TIME_UNKNOWN);
  16152. + }
  16153. +
  16154. + spin_unlock_irqrestore(&port->slock, flags);
  16155. +
  16156. + ret = port_info_get(instance, port);
  16157. + }
  16158. +
  16159. + return ret;
  16160. +}
  16161. +
  16162. +/* enable a port */
  16163. +static int port_enable(struct vchiq_mmal_instance *instance,
  16164. + struct vchiq_mmal_port *port)
  16165. +{
  16166. + unsigned int hdr_count;
  16167. + struct list_head *buf_head;
  16168. + int ret;
  16169. +
  16170. + if (port->enabled)
  16171. + return 0;
  16172. +
  16173. + /* ensure there are enough buffers queued to cover the buffer headers */
  16174. + if (port->buffer_cb != NULL) {
  16175. + hdr_count = 0;
  16176. + list_for_each(buf_head, &port->buffers) {
  16177. + hdr_count++;
  16178. + }
  16179. + if (hdr_count < port->current_buffer.num)
  16180. + return -ENOSPC;
  16181. + }
  16182. +
  16183. + ret = port_action_port(instance, port,
  16184. + MMAL_MSG_PORT_ACTION_TYPE_ENABLE);
  16185. + if (ret)
  16186. + goto done;
  16187. +
  16188. + port->enabled = true;
  16189. +
  16190. + if (port->buffer_cb) {
  16191. + /* send buffer headers to videocore */
  16192. + hdr_count = 1;
  16193. + list_for_each(buf_head, &port->buffers) {
  16194. + struct mmal_buffer *mmalbuf;
  16195. + mmalbuf = list_entry(buf_head, struct mmal_buffer,
  16196. + list);
  16197. + ret = buffer_from_host(instance, port, mmalbuf);
  16198. + if (ret)
  16199. + goto done;
  16200. +
  16201. + hdr_count++;
  16202. + if (hdr_count > port->current_buffer.num)
  16203. + break;
  16204. + }
  16205. + }
  16206. +
  16207. + ret = port_info_get(instance, port);
  16208. +
  16209. +done:
  16210. + return ret;
  16211. +}
  16212. +
  16213. +/* ------------------------------------------------------------------
  16214. + * Exported API
  16215. + *------------------------------------------------------------------*/
  16216. +
  16217. +int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
  16218. + struct vchiq_mmal_port *port)
  16219. +{
  16220. + int ret;
  16221. +
  16222. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  16223. + return -EINTR;
  16224. +
  16225. + ret = port_info_set(instance, port);
  16226. + if (ret)
  16227. + goto release_unlock;
  16228. +
  16229. + /* read what has actually been set */
  16230. + ret = port_info_get(instance, port);
  16231. +
  16232. +release_unlock:
  16233. + mutex_unlock(&instance->vchiq_mutex);
  16234. +
  16235. + return ret;
  16236. +
  16237. +}
  16238. +
  16239. +int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
  16240. + struct vchiq_mmal_port *port,
  16241. + u32 parameter, void *value, u32 value_size)
  16242. +{
  16243. + int ret;
  16244. +
  16245. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  16246. + return -EINTR;
  16247. +
  16248. + ret = port_parameter_set(instance, port, parameter, value, value_size);
  16249. +
  16250. + mutex_unlock(&instance->vchiq_mutex);
  16251. +
  16252. + return ret;
  16253. +}
  16254. +
  16255. +int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
  16256. + struct vchiq_mmal_port *port,
  16257. + u32 parameter, void *value, u32 *value_size)
  16258. +{
  16259. + int ret;
  16260. +
  16261. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  16262. + return -EINTR;
  16263. +
  16264. + ret = port_parameter_get(instance, port, parameter, value, value_size);
  16265. +
  16266. + mutex_unlock(&instance->vchiq_mutex);
  16267. +
  16268. + return ret;
  16269. +}
  16270. +
  16271. +/* enable a port
  16272. + *
  16273. + * enables a port and queues buffers for satisfying callbacks if we
  16274. + * provide a callback handler
  16275. + */
  16276. +int vchiq_mmal_port_enable(struct vchiq_mmal_instance *instance,
  16277. + struct vchiq_mmal_port *port,
  16278. + vchiq_mmal_buffer_cb buffer_cb)
  16279. +{
  16280. + int ret;
  16281. +
  16282. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  16283. + return -EINTR;
  16284. +
  16285. + /* already enabled - noop */
  16286. + if (port->enabled) {
  16287. + ret = 0;
  16288. + goto unlock;
  16289. + }
  16290. +
  16291. + port->buffer_cb = buffer_cb;
  16292. +
  16293. + ret = port_enable(instance, port);
  16294. +
  16295. +unlock:
  16296. + mutex_unlock(&instance->vchiq_mutex);
  16297. +
  16298. + return ret;
  16299. +}
  16300. +
  16301. +int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
  16302. + struct vchiq_mmal_port *port)
  16303. +{
  16304. + int ret;
  16305. +
  16306. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  16307. + return -EINTR;
  16308. +
  16309. + if (!port->enabled) {
  16310. + mutex_unlock(&instance->vchiq_mutex);
  16311. + return 0;
  16312. + }
  16313. +
  16314. + ret = port_disable(instance, port);
  16315. +
  16316. + mutex_unlock(&instance->vchiq_mutex);
  16317. +
  16318. + return ret;
  16319. +}
  16320. +
  16321. +/* ports will be connected in a tunneled manner so data buffers
  16322. + * are not handled by client.
  16323. + */
  16324. +int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
  16325. + struct vchiq_mmal_port *src,
  16326. + struct vchiq_mmal_port *dst)
  16327. +{
  16328. + int ret;
  16329. +
  16330. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  16331. + return -EINTR;
  16332. +
  16333. + /* disconnect ports if connected */
  16334. + if (src->connected != NULL) {
  16335. + ret = port_disable(instance, src);
  16336. + if (ret) {
  16337. + pr_err("failed disabling src port(%d)\n", ret);
  16338. + goto release_unlock;
  16339. + }
  16340. +
  16341. + /* do not need to disable the destination port as they
  16342. + * are connected and it is done automatically
  16343. + */
  16344. +
  16345. + ret = port_action_handle(instance, src,
  16346. + MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT,
  16347. + src->connected->component->handle,
  16348. + src->connected->handle);
  16349. + if (ret < 0) {
  16350. + pr_err("failed disconnecting src port\n");
  16351. + goto release_unlock;
  16352. + }
  16353. + src->connected->enabled = false;
  16354. + src->connected = NULL;
  16355. + }
  16356. +
  16357. + if (dst == NULL) {
  16358. + /* do not make new connection */
  16359. + ret = 0;
  16360. + pr_debug("not making new connection\n");
  16361. + goto release_unlock;
  16362. + }
  16363. +
  16364. + /* copy src port format to dst */
  16365. + dst->format.encoding = src->format.encoding;
  16366. + dst->es.video.width = src->es.video.width;
  16367. + dst->es.video.height = src->es.video.height;
  16368. + dst->es.video.crop.x = src->es.video.crop.x;
  16369. + dst->es.video.crop.y = src->es.video.crop.y;
  16370. + dst->es.video.crop.width = src->es.video.crop.width;
  16371. + dst->es.video.crop.height = src->es.video.crop.height;
  16372. + dst->es.video.frame_rate.num = src->es.video.frame_rate.num;
  16373. + dst->es.video.frame_rate.den = src->es.video.frame_rate.den;
  16374. +
  16375. + /* set new format */
  16376. + ret = port_info_set(instance, dst);
  16377. + if (ret) {
  16378. + pr_debug("setting port info failed\n");
  16379. + goto release_unlock;
  16380. + }
  16381. +
  16382. + /* read what has actually been set */
  16383. + ret = port_info_get(instance, dst);
  16384. + if (ret) {
  16385. + pr_debug("read back port info failed\n");
  16386. + goto release_unlock;
  16387. + }
  16388. +
  16389. + /* connect two ports together */
  16390. + ret = port_action_handle(instance, src,
  16391. + MMAL_MSG_PORT_ACTION_TYPE_CONNECT,
  16392. + dst->component->handle, dst->handle);
  16393. + if (ret < 0) {
  16394. + pr_debug("connecting port %d:%d to %d:%d failed\n",
  16395. + src->component->handle, src->handle,
  16396. + dst->component->handle, dst->handle);
  16397. + goto release_unlock;
  16398. + }
  16399. + src->connected = dst;
  16400. +
  16401. +release_unlock:
  16402. +
  16403. + mutex_unlock(&instance->vchiq_mutex);
  16404. +
  16405. + return ret;
  16406. +}
  16407. +
  16408. +int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
  16409. + struct vchiq_mmal_port *port,
  16410. + struct mmal_buffer *buffer)
  16411. +{
  16412. + unsigned long flags = 0;
  16413. +
  16414. + spin_lock_irqsave(&port->slock, flags);
  16415. + list_add_tail(&buffer->list, &port->buffers);
  16416. + spin_unlock_irqrestore(&port->slock, flags);
  16417. +
  16418. + /* the port previously underflowed because it was missing a
  16419. + * mmal_buffer which has just been added, submit that buffer
  16420. + * to the mmal service.
  16421. + */
  16422. + if (port->buffer_underflow) {
  16423. + port_buffer_from_host(instance, port);
  16424. + port->buffer_underflow--;
  16425. + }
  16426. +
  16427. + return 0;
  16428. +}
  16429. +
  16430. +/* Initialise a mmal component and its ports
  16431. + *
  16432. + */
  16433. +int vchiq_mmal_component_init(struct vchiq_mmal_instance *instance,
  16434. + const char *name,
  16435. + struct vchiq_mmal_component **component_out)
  16436. +{
  16437. + int ret;
  16438. + int idx; /* port index */
  16439. + struct vchiq_mmal_component *component;
  16440. +
  16441. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  16442. + return -EINTR;
  16443. +
  16444. + if (instance->component_idx == VCHIQ_MMAL_MAX_COMPONENTS) {
  16445. + ret = -EINVAL; /* todo is this correct error? */
  16446. + goto unlock;
  16447. + }
  16448. +
  16449. + component = &instance->component[instance->component_idx];
  16450. +
  16451. + ret = create_component(instance, component, name);
  16452. + if (ret < 0)
  16453. + goto unlock;
  16454. +
  16455. + /* ports info needs gathering */
  16456. + component->control.type = MMAL_PORT_TYPE_CONTROL;
  16457. + component->control.index = 0;
  16458. + component->control.component = component;
  16459. + spin_lock_init(&component->control.slock);
  16460. + INIT_LIST_HEAD(&component->control.buffers);
  16461. + ret = port_info_get(instance, &component->control);
  16462. + if (ret < 0)
  16463. + goto release_component;
  16464. +
  16465. + for (idx = 0; idx < component->inputs; idx++) {
  16466. + component->input[idx].type = MMAL_PORT_TYPE_INPUT;
  16467. + component->input[idx].index = idx;
  16468. + component->input[idx].component = component;
  16469. + spin_lock_init(&component->input[idx].slock);
  16470. + INIT_LIST_HEAD(&component->input[idx].buffers);
  16471. + ret = port_info_get(instance, &component->input[idx]);
  16472. + if (ret < 0)
  16473. + goto release_component;
  16474. + }
  16475. +
  16476. + for (idx = 0; idx < component->outputs; idx++) {
  16477. + component->output[idx].type = MMAL_PORT_TYPE_OUTPUT;
  16478. + component->output[idx].index = idx;
  16479. + component->output[idx].component = component;
  16480. + spin_lock_init(&component->output[idx].slock);
  16481. + INIT_LIST_HEAD(&component->output[idx].buffers);
  16482. + ret = port_info_get(instance, &component->output[idx]);
  16483. + if (ret < 0)
  16484. + goto release_component;
  16485. + }
  16486. +
  16487. + for (idx = 0; idx < component->clocks; idx++) {
  16488. + component->clock[idx].type = MMAL_PORT_TYPE_CLOCK;
  16489. + component->clock[idx].index = idx;
  16490. + component->clock[idx].component = component;
  16491. + spin_lock_init(&component->clock[idx].slock);
  16492. + INIT_LIST_HEAD(&component->clock[idx].buffers);
  16493. + ret = port_info_get(instance, &component->clock[idx]);
  16494. + if (ret < 0)
  16495. + goto release_component;
  16496. + }
  16497. +
  16498. + instance->component_idx++;
  16499. +
  16500. + *component_out = component;
  16501. +
  16502. + mutex_unlock(&instance->vchiq_mutex);
  16503. +
  16504. + return 0;
  16505. +
  16506. +release_component:
  16507. + destroy_component(instance, component);
  16508. +unlock:
  16509. + mutex_unlock(&instance->vchiq_mutex);
  16510. +
  16511. + return ret;
  16512. +}
  16513. +
  16514. +/*
  16515. + * cause a mmal component to be destroyed
  16516. + */
  16517. +int vchiq_mmal_component_finalise(struct vchiq_mmal_instance *instance,
  16518. + struct vchiq_mmal_component *component)
  16519. +{
  16520. + int ret;
  16521. +
  16522. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  16523. + return -EINTR;
  16524. +
  16525. + if (component->enabled)
  16526. + ret = disable_component(instance, component);
  16527. +
  16528. + ret = destroy_component(instance, component);
  16529. +
  16530. + mutex_unlock(&instance->vchiq_mutex);
  16531. +
  16532. + return ret;
  16533. +}
  16534. +
  16535. +/*
  16536. + * cause a mmal component to be enabled
  16537. + */
  16538. +int vchiq_mmal_component_enable(struct vchiq_mmal_instance *instance,
  16539. + struct vchiq_mmal_component *component)
  16540. +{
  16541. + int ret;
  16542. +
  16543. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  16544. + return -EINTR;
  16545. +
  16546. + if (component->enabled) {
  16547. + mutex_unlock(&instance->vchiq_mutex);
  16548. + return 0;
  16549. + }
  16550. +
  16551. + ret = enable_component(instance, component);
  16552. + if (ret == 0)
  16553. + component->enabled = true;
  16554. +
  16555. + mutex_unlock(&instance->vchiq_mutex);
  16556. +
  16557. + return ret;
  16558. +}
  16559. +
  16560. +/*
  16561. + * cause a mmal component to be enabled
  16562. + */
  16563. +int vchiq_mmal_component_disable(struct vchiq_mmal_instance *instance,
  16564. + struct vchiq_mmal_component *component)
  16565. +{
  16566. + int ret;
  16567. +
  16568. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  16569. + return -EINTR;
  16570. +
  16571. + if (!component->enabled) {
  16572. + mutex_unlock(&instance->vchiq_mutex);
  16573. + return 0;
  16574. + }
  16575. +
  16576. + ret = disable_component(instance, component);
  16577. + if (ret == 0)
  16578. + component->enabled = false;
  16579. +
  16580. + mutex_unlock(&instance->vchiq_mutex);
  16581. +
  16582. + return ret;
  16583. +}
  16584. +
  16585. +int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
  16586. + u32 *major_out, u32 *minor_out)
  16587. +{
  16588. + int ret;
  16589. +
  16590. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  16591. + return -EINTR;
  16592. +
  16593. + ret = get_version(instance, major_out, minor_out);
  16594. +
  16595. + mutex_unlock(&instance->vchiq_mutex);
  16596. +
  16597. + return ret;
  16598. +}
  16599. +
  16600. +int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance)
  16601. +{
  16602. + int status = 0;
  16603. +
  16604. + if (instance == NULL)
  16605. + return -EINVAL;
  16606. +
  16607. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  16608. + return -EINTR;
  16609. +
  16610. + vchi_service_use(instance->handle);
  16611. +
  16612. + status = vchi_service_close(instance->handle);
  16613. + if (status != 0)
  16614. + pr_err("mmal-vchiq: VCHIQ close failed");
  16615. +
  16616. + mutex_unlock(&instance->vchiq_mutex);
  16617. +
  16618. + vfree(instance->bulk_scratch);
  16619. +
  16620. + kfree(instance);
  16621. +
  16622. + return status;
  16623. +}
  16624. +
  16625. +int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance)
  16626. +{
  16627. + int status;
  16628. + struct vchiq_mmal_instance *instance;
  16629. + static VCHI_CONNECTION_T *vchi_connection;
  16630. + static VCHI_INSTANCE_T vchi_instance;
  16631. + SERVICE_CREATION_T params = {
  16632. + VCHI_VERSION_EX(VC_MMAL_VER, VC_MMAL_MIN_VER),
  16633. + VC_MMAL_SERVER_NAME,
  16634. + vchi_connection,
  16635. + 0, /* rx fifo size (unused) */
  16636. + 0, /* tx fifo size (unused) */
  16637. + service_callback,
  16638. + NULL, /* service callback parameter */
  16639. + 1, /* unaligned bulk receives */
  16640. + 1, /* unaligned bulk transmits */
  16641. + 0 /* want crc check on bulk transfers */
  16642. + };
  16643. +
  16644. + /* compile time checks to ensure structure size as they are
  16645. + * directly (de)serialised from memory.
  16646. + */
  16647. +
  16648. + /* ensure the header structure has packed to the correct size */
  16649. + BUILD_BUG_ON(sizeof(struct mmal_msg_header) != 24);
  16650. +
  16651. + /* ensure message structure does not exceed maximum length */
  16652. + BUILD_BUG_ON(sizeof(struct mmal_msg) > MMAL_MSG_MAX_SIZE);
  16653. +
  16654. + /* mmal port struct is correct size */
  16655. + BUILD_BUG_ON(sizeof(struct mmal_port) != 64);
  16656. +
  16657. + /* create a vchi instance */
  16658. + status = vchi_initialise(&vchi_instance);
  16659. + if (status) {
  16660. + pr_err("Failed to initialise VCHI instance (status=%d)\n",
  16661. + status);
  16662. + return -EIO;
  16663. + }
  16664. +
  16665. + status = vchi_connect(NULL, 0, vchi_instance);
  16666. + if (status) {
  16667. + pr_err("Failed to connect VCHI instance (status=%d)\n", status);
  16668. + return -EIO;
  16669. + }
  16670. +
  16671. + instance = kmalloc(sizeof(*instance), GFP_KERNEL);
  16672. + memset(instance, 0, sizeof(*instance));
  16673. +
  16674. + mutex_init(&instance->vchiq_mutex);
  16675. + mutex_init(&instance->bulk_mutex);
  16676. +
  16677. + instance->bulk_scratch = vmalloc(PAGE_SIZE);
  16678. +
  16679. + params.callback_param = instance;
  16680. +
  16681. + status = vchi_service_open(vchi_instance, &params, &instance->handle);
  16682. + if (status) {
  16683. + pr_err("Failed to open VCHI service connection (status=%d)\n",
  16684. + status);
  16685. + goto err_close_services;
  16686. + }
  16687. +
  16688. + vchi_service_release(instance->handle);
  16689. +
  16690. + *out_instance = instance;
  16691. +
  16692. + return 0;
  16693. +
  16694. +err_close_services:
  16695. +
  16696. + vchi_service_close(instance->handle);
  16697. + vfree(instance->bulk_scratch);
  16698. + kfree(instance);
  16699. + return -ENODEV;
  16700. +}
  16701. diff -Nur linux-3.13.3.orig/drivers/media/platform/bcm2835/mmal-vchiq.h linux-3.13.3/drivers/media/platform/bcm2835/mmal-vchiq.h
  16702. --- linux-3.13.3.orig/drivers/media/platform/bcm2835/mmal-vchiq.h 1970-01-01 01:00:00.000000000 +0100
  16703. +++ linux-3.13.3/drivers/media/platform/bcm2835/mmal-vchiq.h 2014-02-17 22:41:01.000000000 +0100
  16704. @@ -0,0 +1,178 @@
  16705. +/*
  16706. + * Broadcom BM2835 V4L2 driver
  16707. + *
  16708. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  16709. + *
  16710. + * This file is subject to the terms and conditions of the GNU General Public
  16711. + * License. See the file COPYING in the main directory of this archive
  16712. + * for more details.
  16713. + *
  16714. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  16715. + * Dave Stevenson <dsteve@broadcom.com>
  16716. + * Simon Mellor <simellor@broadcom.com>
  16717. + * Luke Diamand <luked@broadcom.com>
  16718. + *
  16719. + * MMAL interface to VCHIQ message passing
  16720. + */
  16721. +
  16722. +#ifndef MMAL_VCHIQ_H
  16723. +#define MMAL_VCHIQ_H
  16724. +
  16725. +#include "mmal-msg-format.h"
  16726. +
  16727. +#define MAX_PORT_COUNT 4
  16728. +
  16729. +/* Maximum size of the format extradata. */
  16730. +#define MMAL_FORMAT_EXTRADATA_MAX_SIZE 128
  16731. +
  16732. +struct vchiq_mmal_instance;
  16733. +
  16734. +enum vchiq_mmal_es_type {
  16735. + MMAL_ES_TYPE_UNKNOWN, /**< Unknown elementary stream type */
  16736. + MMAL_ES_TYPE_CONTROL, /**< Elementary stream of control commands */
  16737. + MMAL_ES_TYPE_AUDIO, /**< Audio elementary stream */
  16738. + MMAL_ES_TYPE_VIDEO, /**< Video elementary stream */
  16739. + MMAL_ES_TYPE_SUBPICTURE /**< Sub-picture elementary stream */
  16740. +};
  16741. +
  16742. +/* rectangle, used lots so it gets its own struct */
  16743. +struct vchiq_mmal_rect {
  16744. + s32 x;
  16745. + s32 y;
  16746. + s32 width;
  16747. + s32 height;
  16748. +};
  16749. +
  16750. +struct vchiq_mmal_port_buffer {
  16751. + unsigned int num; /* number of buffers */
  16752. + u32 size; /* size of buffers */
  16753. + u32 alignment; /* alignment of buffers */
  16754. +};
  16755. +
  16756. +struct vchiq_mmal_port;
  16757. +
  16758. +typedef void (*vchiq_mmal_buffer_cb)(
  16759. + struct vchiq_mmal_instance *instance,
  16760. + struct vchiq_mmal_port *port,
  16761. + int status, struct mmal_buffer *buffer,
  16762. + unsigned long length, u32 mmal_flags, s64 dts, s64 pts);
  16763. +
  16764. +struct vchiq_mmal_port {
  16765. + bool enabled;
  16766. + u32 handle;
  16767. + u32 type; /* port type, cached to use on port info set */
  16768. + u32 index; /* port index, cached to use on port info set */
  16769. +
  16770. + /* component port belongs to, allows simple deref */
  16771. + struct vchiq_mmal_component *component;
  16772. +
  16773. + struct vchiq_mmal_port *connected; /* port conencted to */
  16774. +
  16775. + /* buffer info */
  16776. + struct vchiq_mmal_port_buffer minimum_buffer;
  16777. + struct vchiq_mmal_port_buffer recommended_buffer;
  16778. + struct vchiq_mmal_port_buffer current_buffer;
  16779. +
  16780. + /* stream format */
  16781. + struct mmal_es_format format;
  16782. + /* elementry stream format */
  16783. + union mmal_es_specific_format es;
  16784. +
  16785. + /* data buffers to fill */
  16786. + struct list_head buffers;
  16787. + /* lock to serialise adding and removing buffers from list */
  16788. + spinlock_t slock;
  16789. + /* count of how many buffer header refils have failed because
  16790. + * there was no buffer to satisfy them
  16791. + */
  16792. + int buffer_underflow;
  16793. + /* callback on buffer completion */
  16794. + vchiq_mmal_buffer_cb buffer_cb;
  16795. + /* callback context */
  16796. + void *cb_ctx;
  16797. +};
  16798. +
  16799. +struct vchiq_mmal_component {
  16800. + bool enabled;
  16801. + u32 handle; /* VideoCore handle for component */
  16802. + u32 inputs; /* Number of input ports */
  16803. + u32 outputs; /* Number of output ports */
  16804. + u32 clocks; /* Number of clock ports */
  16805. + struct vchiq_mmal_port control; /* control port */
  16806. + struct vchiq_mmal_port input[MAX_PORT_COUNT]; /* input ports */
  16807. + struct vchiq_mmal_port output[MAX_PORT_COUNT]; /* output ports */
  16808. + struct vchiq_mmal_port clock[MAX_PORT_COUNT]; /* clock ports */
  16809. +};
  16810. +
  16811. +
  16812. +int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance);
  16813. +int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance);
  16814. +
  16815. +/* Initialise a mmal component and its ports
  16816. +*
  16817. +*/
  16818. +int vchiq_mmal_component_init(
  16819. + struct vchiq_mmal_instance *instance,
  16820. + const char *name,
  16821. + struct vchiq_mmal_component **component_out);
  16822. +
  16823. +int vchiq_mmal_component_finalise(
  16824. + struct vchiq_mmal_instance *instance,
  16825. + struct vchiq_mmal_component *component);
  16826. +
  16827. +int vchiq_mmal_component_enable(
  16828. + struct vchiq_mmal_instance *instance,
  16829. + struct vchiq_mmal_component *component);
  16830. +
  16831. +int vchiq_mmal_component_disable(
  16832. + struct vchiq_mmal_instance *instance,
  16833. + struct vchiq_mmal_component *component);
  16834. +
  16835. +
  16836. +
  16837. +/* enable a mmal port
  16838. + *
  16839. + * enables a port and if a buffer callback provided enque buffer
  16840. + * headers as apropriate for the port.
  16841. + */
  16842. +int vchiq_mmal_port_enable(
  16843. + struct vchiq_mmal_instance *instance,
  16844. + struct vchiq_mmal_port *port,
  16845. + vchiq_mmal_buffer_cb buffer_cb);
  16846. +
  16847. +/* disable a port
  16848. + *
  16849. + * disable a port will dequeue any pending buffers
  16850. + */
  16851. +int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
  16852. + struct vchiq_mmal_port *port);
  16853. +
  16854. +
  16855. +int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
  16856. + struct vchiq_mmal_port *port,
  16857. + u32 parameter,
  16858. + void *value,
  16859. + u32 value_size);
  16860. +
  16861. +int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
  16862. + struct vchiq_mmal_port *port,
  16863. + u32 parameter,
  16864. + void *value,
  16865. + u32 *value_size);
  16866. +
  16867. +int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
  16868. + struct vchiq_mmal_port *port);
  16869. +
  16870. +int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
  16871. + struct vchiq_mmal_port *src,
  16872. + struct vchiq_mmal_port *dst);
  16873. +
  16874. +int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
  16875. + u32 *major_out,
  16876. + u32 *minor_out);
  16877. +
  16878. +int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
  16879. + struct vchiq_mmal_port *port,
  16880. + struct mmal_buffer *buf);
  16881. +
  16882. +#endif /* MMAL_VCHIQ_H */
  16883. diff -Nur linux-3.13.3.orig/drivers/media/platform/Kconfig linux-3.13.3/drivers/media/platform/Kconfig
  16884. --- linux-3.13.3.orig/drivers/media/platform/Kconfig 2014-02-13 23:00:14.000000000 +0100
  16885. +++ linux-3.13.3/drivers/media/platform/Kconfig 2014-02-17 22:41:01.000000000 +0100
  16886. @@ -124,6 +124,7 @@
  16887. source "drivers/media/platform/soc_camera/Kconfig"
  16888. source "drivers/media/platform/exynos4-is/Kconfig"
  16889. source "drivers/media/platform/s5p-tv/Kconfig"
  16890. +source "drivers/media/platform/bcm2835/Kconfig"
  16891. endif # V4L_PLATFORM_DRIVERS
  16892. diff -Nur linux-3.13.3.orig/drivers/media/platform/Makefile linux-3.13.3/drivers/media/platform/Makefile
  16893. --- linux-3.13.3.orig/drivers/media/platform/Makefile 2014-02-13 23:00:14.000000000 +0100
  16894. +++ linux-3.13.3/drivers/media/platform/Makefile 2014-02-17 22:41:01.000000000 +0100
  16895. @@ -54,4 +54,6 @@
  16896. obj-$(CONFIG_ARCH_OMAP) += omap/
  16897. +obj-$(CONFIG_VIDEO_BCM2835) += bcm2835/
  16898. +
  16899. ccflags-y += -I$(srctree)/drivers/media/i2c
  16900. diff -Nur linux-3.13.3.orig/drivers/media/usb/dvb-usb-v2/az6007.c linux-3.13.3/drivers/media/usb/dvb-usb-v2/az6007.c
  16901. --- linux-3.13.3.orig/drivers/media/usb/dvb-usb-v2/az6007.c 2014-02-13 23:00:14.000000000 +0100
  16902. +++ linux-3.13.3/drivers/media/usb/dvb-usb-v2/az6007.c 2014-02-17 22:41:01.000000000 +0100
  16903. @@ -68,6 +68,19 @@
  16904. .microcode_name = "dvb-usb-terratec-h7-drxk.fw",
  16905. };
  16906. +static struct drxk_config cablestar_hdci_drxk = {
  16907. + .adr = 0x29,
  16908. + .parallel_ts = true,
  16909. + .dynamic_clk = true,
  16910. + .single_master = true,
  16911. + .enable_merr_cfg = true,
  16912. + .no_i2c_bridge = false,
  16913. + .chunk_size = 64,
  16914. + .mpeg_out_clk_strength = 0x02,
  16915. + .qam_demod_parameter_count = 2,
  16916. + .microcode_name = "dvb-usb-technisat-cablestar-hdci-drxk.fw",
  16917. +};
  16918. +
  16919. static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable)
  16920. {
  16921. struct az6007_device_state *st = fe_to_priv(fe);
  16922. @@ -630,6 +643,27 @@
  16923. return 0;
  16924. }
  16925. +static int az6007_cablestar_hdci_frontend_attach(struct dvb_usb_adapter *adap)
  16926. +{
  16927. + struct az6007_device_state *st = adap_to_priv(adap);
  16928. + struct dvb_usb_device *d = adap_to_d(adap);
  16929. +
  16930. + pr_debug("attaching demod drxk\n");
  16931. +
  16932. + adap->fe[0] = dvb_attach(drxk_attach, &cablestar_hdci_drxk,
  16933. + &d->i2c_adap);
  16934. + if (!adap->fe[0])
  16935. + return -EINVAL;
  16936. +
  16937. + adap->fe[0]->sec_priv = adap;
  16938. + st->gate_ctrl = adap->fe[0]->ops.i2c_gate_ctrl;
  16939. + adap->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
  16940. +
  16941. + az6007_ci_init(adap);
  16942. +
  16943. + return 0;
  16944. +}
  16945. +
  16946. static int az6007_tuner_attach(struct dvb_usb_adapter *adap)
  16947. {
  16948. struct dvb_usb_device *d = adap_to_d(adap);
  16949. @@ -868,6 +902,29 @@
  16950. }
  16951. };
  16952. +static struct dvb_usb_device_properties az6007_cablestar_hdci_props = {
  16953. + .driver_name = KBUILD_MODNAME,
  16954. + .owner = THIS_MODULE,
  16955. + .firmware = AZ6007_FIRMWARE,
  16956. +
  16957. + .adapter_nr = adapter_nr,
  16958. + .size_of_priv = sizeof(struct az6007_device_state),
  16959. + .i2c_algo = &az6007_i2c_algo,
  16960. + .tuner_attach = az6007_tuner_attach,
  16961. + .frontend_attach = az6007_cablestar_hdci_frontend_attach,
  16962. + .streaming_ctrl = az6007_streaming_ctrl,
  16963. +/* ditch get_rc_config as it can't work (TS35 remote, I believe it's rc5) */
  16964. + .get_rc_config = NULL,
  16965. + .read_mac_address = az6007_read_mac_addr,
  16966. + .download_firmware = az6007_download_firmware,
  16967. + .identify_state = az6007_identify_state,
  16968. + .power_ctrl = az6007_power_ctrl,
  16969. + .num_adapters = 1,
  16970. + .adapter = {
  16971. + { .stream = DVB_USB_STREAM_BULK(0x02, 10, 4096), }
  16972. + }
  16973. +};
  16974. +
  16975. static struct usb_device_id az6007_usb_table[] = {
  16976. {DVB_USB_DEVICE(USB_VID_AZUREWAVE, USB_PID_AZUREWAVE_6007,
  16977. &az6007_props, "Azurewave 6007", RC_MAP_EMPTY)},
  16978. @@ -875,6 +932,8 @@
  16979. &az6007_props, "Terratec H7", RC_MAP_NEC_TERRATEC_CINERGY_XS)},
  16980. {DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_H7_2,
  16981. &az6007_props, "Terratec H7", RC_MAP_NEC_TERRATEC_CINERGY_XS)},
  16982. + {DVB_USB_DEVICE(USB_VID_TECHNISAT, USB_PID_TECHNISAT_USB2_CABLESTAR_HDCI,
  16983. + &az6007_cablestar_hdci_props, "Technisat CableStar Combo HD CI", RC_MAP_EMPTY)},
  16984. {0},
  16985. };
  16986. diff -Nur linux-3.13.3.orig/drivers/media/usb/dvb-usb-v2/rtl28xxu.c linux-3.13.3/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
  16987. --- linux-3.13.3.orig/drivers/media/usb/dvb-usb-v2/rtl28xxu.c 2014-02-13 23:00:14.000000000 +0100
  16988. +++ linux-3.13.3/drivers/media/usb/dvb-usb-v2/rtl28xxu.c 2014-02-17 22:41:01.000000000 +0100
  16989. @@ -1423,6 +1423,10 @@
  16990. &rtl2832u_props, "Compro VideoMate U620F", NULL) },
  16991. { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd394,
  16992. &rtl2832u_props, "MaxMedia HU394-T", NULL) },
  16993. + { DVB_USB_DEVICE(USB_VID_GTEK, 0xb803 /*USB_PID_AUGUST_DVBT205*/,
  16994. + &rtl2832u_props, "August DVB-T 205", NULL) },
  16995. + { DVB_USB_DEVICE(USB_VID_GTEK, 0xa803 /*USB_PID_AUGUST_DVBT205*/,
  16996. + &rtl2832u_props, "August DVB-T 205", NULL) },
  16997. { DVB_USB_DEVICE(USB_VID_LEADTEK, 0x6a03,
  16998. &rtl2832u_props, "Leadtek WinFast DTV Dongle mini", NULL) },
  16999. { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_CPYTO_REDI_PC50A,
  17000. diff -Nur linux-3.13.3.orig/drivers/misc/Kconfig linux-3.13.3/drivers/misc/Kconfig
  17001. --- linux-3.13.3.orig/drivers/misc/Kconfig 2014-02-13 23:00:14.000000000 +0100
  17002. +++ linux-3.13.3/drivers/misc/Kconfig 2014-02-17 22:41:01.000000000 +0100
  17003. @@ -524,5 +524,6 @@
  17004. source "drivers/misc/altera-stapl/Kconfig"
  17005. source "drivers/misc/mei/Kconfig"
  17006. source "drivers/misc/vmw_vmci/Kconfig"
  17007. +source "drivers/misc/vc04_services/Kconfig"
  17008. source "drivers/misc/mic/Kconfig"
  17009. endmenu
  17010. diff -Nur linux-3.13.3.orig/drivers/misc/Makefile linux-3.13.3/drivers/misc/Makefile
  17011. --- linux-3.13.3.orig/drivers/misc/Makefile 2014-02-13 23:00:14.000000000 +0100
  17012. +++ linux-3.13.3/drivers/misc/Makefile 2014-02-17 22:41:01.000000000 +0100
  17013. @@ -52,4 +52,5 @@
  17014. obj-$(CONFIG_VMWARE_VMCI) += vmw_vmci/
  17015. obj-$(CONFIG_LATTICE_ECP3_CONFIG) += lattice-ecp3-config.o
  17016. obj-$(CONFIG_SRAM) += sram.o
  17017. +obj-$(CONFIG_BCM2708_VCHIQ) += vc04_services/
  17018. obj-y += mic/
  17019. diff -Nur linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchi/connections/connection.h linux-3.13.3/drivers/misc/vc04_services/interface/vchi/connections/connection.h
  17020. --- linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchi/connections/connection.h 1970-01-01 01:00:00.000000000 +0100
  17021. +++ linux-3.13.3/drivers/misc/vc04_services/interface/vchi/connections/connection.h 2014-02-17 22:41:01.000000000 +0100
  17022. @@ -0,0 +1,328 @@
  17023. +/**
  17024. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  17025. + *
  17026. + * Redistribution and use in source and binary forms, with or without
  17027. + * modification, are permitted provided that the following conditions
  17028. + * are met:
  17029. + * 1. Redistributions of source code must retain the above copyright
  17030. + * notice, this list of conditions, and the following disclaimer,
  17031. + * without modification.
  17032. + * 2. Redistributions in binary form must reproduce the above copyright
  17033. + * notice, this list of conditions and the following disclaimer in the
  17034. + * documentation and/or other materials provided with the distribution.
  17035. + * 3. The names of the above-listed copyright holders may not be used
  17036. + * to endorse or promote products derived from this software without
  17037. + * specific prior written permission.
  17038. + *
  17039. + * ALTERNATIVELY, this software may be distributed under the terms of the
  17040. + * GNU General Public License ("GPL") version 2, as published by the Free
  17041. + * Software Foundation.
  17042. + *
  17043. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  17044. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  17045. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  17046. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  17047. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  17048. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  17049. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  17050. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  17051. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  17052. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  17053. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  17054. + */
  17055. +
  17056. +#ifndef CONNECTION_H_
  17057. +#define CONNECTION_H_
  17058. +
  17059. +#include <linux/kernel.h>
  17060. +#include <linux/types.h>
  17061. +#include <linux/semaphore.h>
  17062. +
  17063. +#include "interface/vchi/vchi_cfg_internal.h"
  17064. +#include "interface/vchi/vchi_common.h"
  17065. +#include "interface/vchi/message_drivers/message.h"
  17066. +
  17067. +/******************************************************************************
  17068. + Global defs
  17069. + *****************************************************************************/
  17070. +
  17071. +// Opaque handle for a connection / service pair
  17072. +typedef struct opaque_vchi_connection_connected_service_handle_t *VCHI_CONNECTION_SERVICE_HANDLE_T;
  17073. +
  17074. +// opaque handle to the connection state information
  17075. +typedef struct opaque_vchi_connection_info_t VCHI_CONNECTION_STATE_T;
  17076. +
  17077. +typedef struct vchi_connection_t VCHI_CONNECTION_T;
  17078. +
  17079. +
  17080. +/******************************************************************************
  17081. + API
  17082. + *****************************************************************************/
  17083. +
  17084. +// Routine to init a connection with a particular low level driver
  17085. +typedef VCHI_CONNECTION_STATE_T * (*VCHI_CONNECTION_INIT_T)( struct vchi_connection_t * connection,
  17086. + const VCHI_MESSAGE_DRIVER_T * driver );
  17087. +
  17088. +// Routine to control CRC enabling at a connection level
  17089. +typedef int32_t (*VCHI_CONNECTION_CRC_CONTROL_T)( VCHI_CONNECTION_STATE_T *state_handle,
  17090. + VCHI_CRC_CONTROL_T control );
  17091. +
  17092. +// Routine to create a service
  17093. +typedef int32_t (*VCHI_CONNECTION_SERVICE_CONNECT_T)( VCHI_CONNECTION_STATE_T *state_handle,
  17094. + int32_t service_id,
  17095. + uint32_t rx_fifo_size,
  17096. + uint32_t tx_fifo_size,
  17097. + int server,
  17098. + VCHI_CALLBACK_T callback,
  17099. + void *callback_param,
  17100. + int32_t want_crc,
  17101. + int32_t want_unaligned_bulk_rx,
  17102. + int32_t want_unaligned_bulk_tx,
  17103. + VCHI_CONNECTION_SERVICE_HANDLE_T *service_handle );
  17104. +
  17105. +// Routine to close a service
  17106. +typedef int32_t (*VCHI_CONNECTION_SERVICE_DISCONNECT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle );
  17107. +
  17108. +// Routine to queue a message
  17109. +typedef int32_t (*VCHI_CONNECTION_SERVICE_QUEUE_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  17110. + const void *data,
  17111. + uint32_t data_size,
  17112. + VCHI_FLAGS_T flags,
  17113. + void *msg_handle );
  17114. +
  17115. +// scatter-gather (vector) message queueing
  17116. +typedef int32_t (*VCHI_CONNECTION_SERVICE_QUEUE_MESSAGEV_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  17117. + VCHI_MSG_VECTOR_T *vector,
  17118. + uint32_t count,
  17119. + VCHI_FLAGS_T flags,
  17120. + void *msg_handle );
  17121. +
  17122. +// Routine to dequeue a message
  17123. +typedef int32_t (*VCHI_CONNECTION_SERVICE_DEQUEUE_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  17124. + void *data,
  17125. + uint32_t max_data_size_to_read,
  17126. + uint32_t *actual_msg_size,
  17127. + VCHI_FLAGS_T flags );
  17128. +
  17129. +// Routine to peek at a message
  17130. +typedef int32_t (*VCHI_CONNECTION_SERVICE_PEEK_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  17131. + void **data,
  17132. + uint32_t *msg_size,
  17133. + VCHI_FLAGS_T flags );
  17134. +
  17135. +// Routine to hold a message
  17136. +typedef int32_t (*VCHI_CONNECTION_SERVICE_HOLD_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  17137. + void **data,
  17138. + uint32_t *msg_size,
  17139. + VCHI_FLAGS_T flags,
  17140. + void **message_handle );
  17141. +
  17142. +// Routine to initialise a received message iterator
  17143. +typedef int32_t (*VCHI_CONNECTION_SERVICE_LOOKAHEAD_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  17144. + VCHI_MSG_ITER_T *iter,
  17145. + VCHI_FLAGS_T flags );
  17146. +
  17147. +// Routine to release a held message
  17148. +typedef int32_t (*VCHI_CONNECTION_HELD_MSG_RELEASE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  17149. + void *message_handle );
  17150. +
  17151. +// Routine to get info on a held message
  17152. +typedef int32_t (*VCHI_CONNECTION_HELD_MSG_INFO_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  17153. + void *message_handle,
  17154. + void **data,
  17155. + int32_t *msg_size,
  17156. + uint32_t *tx_timestamp,
  17157. + uint32_t *rx_timestamp );
  17158. +
  17159. +// Routine to check whether the iterator has a next message
  17160. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_HAS_NEXT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  17161. + const VCHI_MSG_ITER_T *iter );
  17162. +
  17163. +// Routine to advance the iterator
  17164. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_NEXT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  17165. + VCHI_MSG_ITER_T *iter,
  17166. + void **data,
  17167. + uint32_t *msg_size );
  17168. +
  17169. +// Routine to remove the last message returned by the iterator
  17170. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_REMOVE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  17171. + VCHI_MSG_ITER_T *iter );
  17172. +
  17173. +// Routine to hold the last message returned by the iterator
  17174. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_HOLD_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  17175. + VCHI_MSG_ITER_T *iter,
  17176. + void **msg_handle );
  17177. +
  17178. +// Routine to transmit bulk data
  17179. +typedef int32_t (*VCHI_CONNECTION_BULK_QUEUE_TRANSMIT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  17180. + const void *data_src,
  17181. + uint32_t data_size,
  17182. + VCHI_FLAGS_T flags,
  17183. + void *bulk_handle );
  17184. +
  17185. +// Routine to receive data
  17186. +typedef int32_t (*VCHI_CONNECTION_BULK_QUEUE_RECEIVE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  17187. + void *data_dst,
  17188. + uint32_t data_size,
  17189. + VCHI_FLAGS_T flags,
  17190. + void *bulk_handle );
  17191. +
  17192. +// Routine to report if a server is available
  17193. +typedef int32_t (*VCHI_CONNECTION_SERVER_PRESENT)( VCHI_CONNECTION_STATE_T *state, int32_t service_id, int32_t peer_flags );
  17194. +
  17195. +// Routine to report the number of RX slots available
  17196. +typedef int (*VCHI_CONNECTION_RX_SLOTS_AVAILABLE)( const VCHI_CONNECTION_STATE_T *state );
  17197. +
  17198. +// Routine to report the RX slot size
  17199. +typedef uint32_t (*VCHI_CONNECTION_RX_SLOT_SIZE)( const VCHI_CONNECTION_STATE_T *state );
  17200. +
  17201. +// Callback to indicate that the other side has added a buffer to the rx bulk DMA FIFO
  17202. +typedef void (*VCHI_CONNECTION_RX_BULK_BUFFER_ADDED)(VCHI_CONNECTION_STATE_T *state,
  17203. + int32_t service,
  17204. + uint32_t length,
  17205. + MESSAGE_TX_CHANNEL_T channel,
  17206. + uint32_t channel_params,
  17207. + uint32_t data_length,
  17208. + uint32_t data_offset);
  17209. +
  17210. +// Callback to inform a service that a Xon or Xoff message has been received
  17211. +typedef void (*VCHI_CONNECTION_FLOW_CONTROL)(VCHI_CONNECTION_STATE_T *state, int32_t service_id, int32_t xoff);
  17212. +
  17213. +// Callback to inform a service that a server available reply message has been received
  17214. +typedef void (*VCHI_CONNECTION_SERVER_AVAILABLE_REPLY)(VCHI_CONNECTION_STATE_T *state, int32_t service_id, uint32_t flags);
  17215. +
  17216. +// Callback to indicate that bulk auxiliary messages have arrived
  17217. +typedef void (*VCHI_CONNECTION_BULK_AUX_RECEIVED)(VCHI_CONNECTION_STATE_T *state);
  17218. +
  17219. +// Callback to indicate that bulk auxiliary messages have arrived
  17220. +typedef void (*VCHI_CONNECTION_BULK_AUX_TRANSMITTED)(VCHI_CONNECTION_STATE_T *state, void *handle);
  17221. +
  17222. +// Callback with all the connection info you require
  17223. +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);
  17224. +
  17225. +// Callback to inform of a disconnect
  17226. +typedef void (*VCHI_CONNECTION_DISCONNECT)(VCHI_CONNECTION_STATE_T *state, uint32_t flags);
  17227. +
  17228. +// Callback to inform of a power control request
  17229. +typedef void (*VCHI_CONNECTION_POWER_CONTROL)(VCHI_CONNECTION_STATE_T *state, MESSAGE_TX_CHANNEL_T channel, int32_t enable);
  17230. +
  17231. +// allocate memory suitably aligned for this connection
  17232. +typedef void * (*VCHI_BUFFER_ALLOCATE)(VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, uint32_t * length);
  17233. +
  17234. +// free memory allocated by buffer_allocate
  17235. +typedef void (*VCHI_BUFFER_FREE)(VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, void * address);
  17236. +
  17237. +
  17238. +/******************************************************************************
  17239. + System driver struct
  17240. + *****************************************************************************/
  17241. +
  17242. +struct opaque_vchi_connection_api_t
  17243. +{
  17244. + // Routine to init the connection
  17245. + VCHI_CONNECTION_INIT_T init;
  17246. +
  17247. + // Connection-level CRC control
  17248. + VCHI_CONNECTION_CRC_CONTROL_T crc_control;
  17249. +
  17250. + // Routine to connect to or create service
  17251. + VCHI_CONNECTION_SERVICE_CONNECT_T service_connect;
  17252. +
  17253. + // Routine to disconnect from a service
  17254. + VCHI_CONNECTION_SERVICE_DISCONNECT_T service_disconnect;
  17255. +
  17256. + // Routine to queue a message
  17257. + VCHI_CONNECTION_SERVICE_QUEUE_MESSAGE_T service_queue_msg;
  17258. +
  17259. + // scatter-gather (vector) message queue
  17260. + VCHI_CONNECTION_SERVICE_QUEUE_MESSAGEV_T service_queue_msgv;
  17261. +
  17262. + // Routine to dequeue a message
  17263. + VCHI_CONNECTION_SERVICE_DEQUEUE_MESSAGE_T service_dequeue_msg;
  17264. +
  17265. + // Routine to peek at a message
  17266. + VCHI_CONNECTION_SERVICE_PEEK_MESSAGE_T service_peek_msg;
  17267. +
  17268. + // Routine to hold a message
  17269. + VCHI_CONNECTION_SERVICE_HOLD_MESSAGE_T service_hold_msg;
  17270. +
  17271. + // Routine to initialise a received message iterator
  17272. + VCHI_CONNECTION_SERVICE_LOOKAHEAD_MESSAGE_T service_look_ahead_msg;
  17273. +
  17274. + // Routine to release a message
  17275. + VCHI_CONNECTION_HELD_MSG_RELEASE_T held_msg_release;
  17276. +
  17277. + // Routine to get information on a held message
  17278. + VCHI_CONNECTION_HELD_MSG_INFO_T held_msg_info;
  17279. +
  17280. + // Routine to check for next message on iterator
  17281. + VCHI_CONNECTION_MSG_ITER_HAS_NEXT_T msg_iter_has_next;
  17282. +
  17283. + // Routine to get next message on iterator
  17284. + VCHI_CONNECTION_MSG_ITER_NEXT_T msg_iter_next;
  17285. +
  17286. + // Routine to remove the last message returned by iterator
  17287. + VCHI_CONNECTION_MSG_ITER_REMOVE_T msg_iter_remove;
  17288. +
  17289. + // Routine to hold the last message returned by iterator
  17290. + VCHI_CONNECTION_MSG_ITER_HOLD_T msg_iter_hold;
  17291. +
  17292. + // Routine to transmit bulk data
  17293. + VCHI_CONNECTION_BULK_QUEUE_TRANSMIT_T bulk_queue_transmit;
  17294. +
  17295. + // Routine to receive data
  17296. + VCHI_CONNECTION_BULK_QUEUE_RECEIVE_T bulk_queue_receive;
  17297. +
  17298. + // Routine to report the available servers
  17299. + VCHI_CONNECTION_SERVER_PRESENT server_present;
  17300. +
  17301. + // Routine to report the number of RX slots available
  17302. + VCHI_CONNECTION_RX_SLOTS_AVAILABLE connection_rx_slots_available;
  17303. +
  17304. + // Routine to report the RX slot size
  17305. + VCHI_CONNECTION_RX_SLOT_SIZE connection_rx_slot_size;
  17306. +
  17307. + // Callback to indicate that the other side has added a buffer to the rx bulk DMA FIFO
  17308. + VCHI_CONNECTION_RX_BULK_BUFFER_ADDED rx_bulk_buffer_added;
  17309. +
  17310. + // Callback to inform a service that a Xon or Xoff message has been received
  17311. + VCHI_CONNECTION_FLOW_CONTROL flow_control;
  17312. +
  17313. + // Callback to inform a service that a server available reply message has been received
  17314. + VCHI_CONNECTION_SERVER_AVAILABLE_REPLY server_available_reply;
  17315. +
  17316. + // Callback to indicate that bulk auxiliary messages have arrived
  17317. + VCHI_CONNECTION_BULK_AUX_RECEIVED bulk_aux_received;
  17318. +
  17319. + // Callback to indicate that a bulk auxiliary message has been transmitted
  17320. + VCHI_CONNECTION_BULK_AUX_TRANSMITTED bulk_aux_transmitted;
  17321. +
  17322. + // Callback to provide information about the connection
  17323. + VCHI_CONNECTION_INFO connection_info;
  17324. +
  17325. + // Callback to notify that peer has requested disconnect
  17326. + VCHI_CONNECTION_DISCONNECT disconnect;
  17327. +
  17328. + // Callback to notify that peer has requested power change
  17329. + VCHI_CONNECTION_POWER_CONTROL power_control;
  17330. +
  17331. + // allocate memory suitably aligned for this connection
  17332. + VCHI_BUFFER_ALLOCATE buffer_allocate;
  17333. +
  17334. + // free memory allocated by buffer_allocate
  17335. + VCHI_BUFFER_FREE buffer_free;
  17336. +
  17337. +};
  17338. +
  17339. +struct vchi_connection_t {
  17340. + const VCHI_CONNECTION_API_T *api;
  17341. + VCHI_CONNECTION_STATE_T *state;
  17342. +#ifdef VCHI_COARSE_LOCKING
  17343. + struct semaphore sem;
  17344. +#endif
  17345. +};
  17346. +
  17347. +
  17348. +#endif /* CONNECTION_H_ */
  17349. +
  17350. +/****************************** End of file **********************************/
  17351. diff -Nur linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h linux-3.13.3/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h
  17352. --- linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h 1970-01-01 01:00:00.000000000 +0100
  17353. +++ linux-3.13.3/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h 2014-02-17 22:41:01.000000000 +0100
  17354. @@ -0,0 +1,204 @@
  17355. +/**
  17356. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  17357. + *
  17358. + * Redistribution and use in source and binary forms, with or without
  17359. + * modification, are permitted provided that the following conditions
  17360. + * are met:
  17361. + * 1. Redistributions of source code must retain the above copyright
  17362. + * notice, this list of conditions, and the following disclaimer,
  17363. + * without modification.
  17364. + * 2. Redistributions in binary form must reproduce the above copyright
  17365. + * notice, this list of conditions and the following disclaimer in the
  17366. + * documentation and/or other materials provided with the distribution.
  17367. + * 3. The names of the above-listed copyright holders may not be used
  17368. + * to endorse or promote products derived from this software without
  17369. + * specific prior written permission.
  17370. + *
  17371. + * ALTERNATIVELY, this software may be distributed under the terms of the
  17372. + * GNU General Public License ("GPL") version 2, as published by the Free
  17373. + * Software Foundation.
  17374. + *
  17375. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  17376. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  17377. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  17378. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  17379. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  17380. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  17381. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  17382. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  17383. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  17384. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  17385. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  17386. + */
  17387. +
  17388. +#ifndef _VCHI_MESSAGE_H_
  17389. +#define _VCHI_MESSAGE_H_
  17390. +
  17391. +#include <linux/kernel.h>
  17392. +#include <linux/types.h>
  17393. +#include <linux/semaphore.h>
  17394. +
  17395. +#include "interface/vchi/vchi_cfg_internal.h"
  17396. +#include "interface/vchi/vchi_common.h"
  17397. +
  17398. +
  17399. +typedef enum message_event_type {
  17400. + MESSAGE_EVENT_NONE,
  17401. + MESSAGE_EVENT_NOP,
  17402. + MESSAGE_EVENT_MESSAGE,
  17403. + MESSAGE_EVENT_SLOT_COMPLETE,
  17404. + MESSAGE_EVENT_RX_BULK_PAUSED,
  17405. + MESSAGE_EVENT_RX_BULK_COMPLETE,
  17406. + MESSAGE_EVENT_TX_COMPLETE,
  17407. + MESSAGE_EVENT_MSG_DISCARDED
  17408. +} MESSAGE_EVENT_TYPE_T;
  17409. +
  17410. +typedef enum vchi_msg_flags
  17411. +{
  17412. + VCHI_MSG_FLAGS_NONE = 0x0,
  17413. + VCHI_MSG_FLAGS_TERMINATE_DMA = 0x1
  17414. +} VCHI_MSG_FLAGS_T;
  17415. +
  17416. +typedef enum message_tx_channel
  17417. +{
  17418. + MESSAGE_TX_CHANNEL_MESSAGE = 0,
  17419. + MESSAGE_TX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards
  17420. +} MESSAGE_TX_CHANNEL_T;
  17421. +
  17422. +// Macros used for cycling through bulk channels
  17423. +#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)
  17424. +#define MESSAGE_TX_CHANNEL_BULK_NEXT(c) (MESSAGE_TX_CHANNEL_BULK+((c)-MESSAGE_TX_CHANNEL_BULK+1)%VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION)
  17425. +
  17426. +typedef enum message_rx_channel
  17427. +{
  17428. + MESSAGE_RX_CHANNEL_MESSAGE = 0,
  17429. + MESSAGE_RX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards
  17430. +} MESSAGE_RX_CHANNEL_T;
  17431. +
  17432. +// Message receive slot information
  17433. +typedef struct rx_msg_slot_info {
  17434. +
  17435. + struct rx_msg_slot_info *next;
  17436. + //struct slot_info *prev;
  17437. +#if !defined VCHI_COARSE_LOCKING
  17438. + struct semaphore sem;
  17439. +#endif
  17440. +
  17441. + uint8_t *addr; // base address of slot
  17442. + uint32_t len; // length of slot in bytes
  17443. +
  17444. + uint32_t write_ptr; // hardware causes this to advance
  17445. + uint32_t read_ptr; // this module does the reading
  17446. + int active; // is this slot in the hardware dma fifo?
  17447. + uint32_t msgs_parsed; // count how many messages are in this slot
  17448. + uint32_t msgs_released; // how many messages have been released
  17449. + void *state; // connection state information
  17450. + uint8_t ref_count[VCHI_MAX_SERVICES_PER_CONNECTION]; // reference count for slots held by services
  17451. +} RX_MSG_SLOTINFO_T;
  17452. +
  17453. +// The message driver no longer needs to know about the fields of RX_BULK_SLOTINFO_T - sort this out.
  17454. +// In particular, it mustn't use addr and len - they're the client buffer, but the message
  17455. +// driver will be tasked with sending the aligned core section.
  17456. +typedef struct rx_bulk_slotinfo_t {
  17457. + struct rx_bulk_slotinfo_t *next;
  17458. +
  17459. + struct semaphore *blocking;
  17460. +
  17461. + // needed by DMA
  17462. + void *addr;
  17463. + uint32_t len;
  17464. +
  17465. + // needed for the callback
  17466. + void *service;
  17467. + void *handle;
  17468. + VCHI_FLAGS_T flags;
  17469. +} RX_BULK_SLOTINFO_T;
  17470. +
  17471. +
  17472. +/* ----------------------------------------------------------------------
  17473. + * each connection driver will have a pool of the following struct.
  17474. + *
  17475. + * the pool will be managed by vchi_qman_*
  17476. + * this means there will be multiple queues (single linked lists)
  17477. + * a given struct message_info will be on exactly one of these queues
  17478. + * at any one time
  17479. + * -------------------------------------------------------------------- */
  17480. +typedef struct rx_message_info {
  17481. +
  17482. + struct message_info *next;
  17483. + //struct message_info *prev;
  17484. +
  17485. + uint8_t *addr;
  17486. + uint32_t len;
  17487. + RX_MSG_SLOTINFO_T *slot; // points to whichever slot contains this message
  17488. + uint32_t tx_timestamp;
  17489. + uint32_t rx_timestamp;
  17490. +
  17491. +} RX_MESSAGE_INFO_T;
  17492. +
  17493. +typedef struct {
  17494. + MESSAGE_EVENT_TYPE_T type;
  17495. +
  17496. + struct {
  17497. + // for messages
  17498. + void *addr; // address of message
  17499. + uint16_t slot_delta; // whether this message indicated slot delta
  17500. + uint32_t len; // length of message
  17501. + RX_MSG_SLOTINFO_T *slot; // slot this message is in
  17502. + int32_t service; // service id this message is destined for
  17503. + uint32_t tx_timestamp; // timestamp from the header
  17504. + uint32_t rx_timestamp; // timestamp when we parsed it
  17505. + } message;
  17506. +
  17507. + // FIXME: cleanup slot reporting...
  17508. + RX_MSG_SLOTINFO_T *rx_msg;
  17509. + RX_BULK_SLOTINFO_T *rx_bulk;
  17510. + void *tx_handle;
  17511. + MESSAGE_TX_CHANNEL_T tx_channel;
  17512. +
  17513. +} MESSAGE_EVENT_T;
  17514. +
  17515. +
  17516. +// callbacks
  17517. +typedef void VCHI_MESSAGE_DRIVER_EVENT_CALLBACK_T( void *state );
  17518. +
  17519. +typedef struct {
  17520. + VCHI_MESSAGE_DRIVER_EVENT_CALLBACK_T *event_callback;
  17521. +} VCHI_MESSAGE_DRIVER_OPEN_T;
  17522. +
  17523. +
  17524. +// handle to this instance of message driver (as returned by ->open)
  17525. +typedef struct opaque_mhandle_t *VCHI_MDRIVER_HANDLE_T;
  17526. +
  17527. +struct opaque_vchi_message_driver_t {
  17528. + VCHI_MDRIVER_HANDLE_T *(*open)( VCHI_MESSAGE_DRIVER_OPEN_T *params, void *state );
  17529. + int32_t (*suspending)( VCHI_MDRIVER_HANDLE_T *handle );
  17530. + int32_t (*resumed)( VCHI_MDRIVER_HANDLE_T *handle );
  17531. + int32_t (*power_control)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T, int32_t enable );
  17532. + int32_t (*add_msg_rx_slot)( VCHI_MDRIVER_HANDLE_T *handle, RX_MSG_SLOTINFO_T *slot ); // rx message
  17533. + int32_t (*add_bulk_rx)( VCHI_MDRIVER_HANDLE_T *handle, void *data, uint32_t len, RX_BULK_SLOTINFO_T *slot ); // rx data (bulk)
  17534. + 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)
  17535. + void (*next_event)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_EVENT_T *event ); // get the next event from message_driver
  17536. + int32_t (*enable)( VCHI_MDRIVER_HANDLE_T *handle );
  17537. + int32_t (*form_message)( VCHI_MDRIVER_HANDLE_T *handle, int32_t service_id, VCHI_MSG_VECTOR_T *vector, uint32_t count, void
  17538. + *address, uint32_t length_avail, uint32_t max_total_length, int32_t pad_to_fill, int32_t allow_partial );
  17539. +
  17540. + int32_t (*update_message)( VCHI_MDRIVER_HANDLE_T *handle, void *dest, int16_t *slot_count );
  17541. + int32_t (*buffer_aligned)( VCHI_MDRIVER_HANDLE_T *handle, int tx, int uncached, const void *address, const uint32_t length );
  17542. + void * (*allocate_buffer)( VCHI_MDRIVER_HANDLE_T *handle, uint32_t *length );
  17543. + void (*free_buffer)( VCHI_MDRIVER_HANDLE_T *handle, void *address );
  17544. + int (*rx_slot_size)( VCHI_MDRIVER_HANDLE_T *handle, int msg_size );
  17545. + int (*tx_slot_size)( VCHI_MDRIVER_HANDLE_T *handle, int msg_size );
  17546. +
  17547. + int32_t (*tx_supports_terminate)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
  17548. + uint32_t (*tx_bulk_chunk_size)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
  17549. + int (*tx_alignment)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
  17550. + int (*rx_alignment)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_RX_CHANNEL_T channel );
  17551. + 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 );
  17552. + void (*debug)( VCHI_MDRIVER_HANDLE_T *handle );
  17553. +};
  17554. +
  17555. +
  17556. +#endif // _VCHI_MESSAGE_H_
  17557. +
  17558. +/****************************** End of file ***********************************/
  17559. diff -Nur linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h linux-3.13.3/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h
  17560. --- linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h 1970-01-01 01:00:00.000000000 +0100
  17561. +++ linux-3.13.3/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h 2014-02-17 22:41:01.000000000 +0100
  17562. @@ -0,0 +1,224 @@
  17563. +/**
  17564. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  17565. + *
  17566. + * Redistribution and use in source and binary forms, with or without
  17567. + * modification, are permitted provided that the following conditions
  17568. + * are met:
  17569. + * 1. Redistributions of source code must retain the above copyright
  17570. + * notice, this list of conditions, and the following disclaimer,
  17571. + * without modification.
  17572. + * 2. Redistributions in binary form must reproduce the above copyright
  17573. + * notice, this list of conditions and the following disclaimer in the
  17574. + * documentation and/or other materials provided with the distribution.
  17575. + * 3. The names of the above-listed copyright holders may not be used
  17576. + * to endorse or promote products derived from this software without
  17577. + * specific prior written permission.
  17578. + *
  17579. + * ALTERNATIVELY, this software may be distributed under the terms of the
  17580. + * GNU General Public License ("GPL") version 2, as published by the Free
  17581. + * Software Foundation.
  17582. + *
  17583. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  17584. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  17585. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  17586. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  17587. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  17588. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  17589. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  17590. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  17591. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  17592. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  17593. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  17594. + */
  17595. +
  17596. +#ifndef VCHI_CFG_H_
  17597. +#define VCHI_CFG_H_
  17598. +
  17599. +/****************************************************************************************
  17600. + * Defines in this first section are part of the VCHI API and may be examined by VCHI
  17601. + * services.
  17602. + ***************************************************************************************/
  17603. +
  17604. +/* Required alignment of base addresses for bulk transfer, if unaligned transfers are not enabled */
  17605. +/* Really determined by the message driver, and should be available from a run-time call. */
  17606. +#ifndef VCHI_BULK_ALIGN
  17607. +# if __VCCOREVER__ >= 0x04000000
  17608. +# define VCHI_BULK_ALIGN 32 // Allows for the need to do cache cleans
  17609. +# else
  17610. +# define VCHI_BULK_ALIGN 16
  17611. +# endif
  17612. +#endif
  17613. +
  17614. +/* Required length multiple for bulk transfers, if unaligned transfers are not enabled */
  17615. +/* May be less than or greater than VCHI_BULK_ALIGN */
  17616. +/* Really determined by the message driver, and should be available from a run-time call. */
  17617. +#ifndef VCHI_BULK_GRANULARITY
  17618. +# if __VCCOREVER__ >= 0x04000000
  17619. +# define VCHI_BULK_GRANULARITY 32 // Allows for the need to do cache cleans
  17620. +# else
  17621. +# define VCHI_BULK_GRANULARITY 16
  17622. +# endif
  17623. +#endif
  17624. +
  17625. +/* The largest possible message to be queued with vchi_msg_queue. */
  17626. +#ifndef VCHI_MAX_MSG_SIZE
  17627. +# if defined VCHI_LOCAL_HOST_PORT
  17628. +# define VCHI_MAX_MSG_SIZE 16384 // makes file transfers fast, but should they be using bulk?
  17629. +# else
  17630. +# define VCHI_MAX_MSG_SIZE 4096 // NOTE: THIS MUST BE LARGER THAN OR EQUAL TO THE SIZE OF THE KHRONOS MERGE BUFFER!!
  17631. +# endif
  17632. +#endif
  17633. +
  17634. +/******************************************************************************************
  17635. + * Defines below are system configuration options, and should not be used by VCHI services.
  17636. + *****************************************************************************************/
  17637. +
  17638. +/* How many connections can we support? A localhost implementation uses 2 connections,
  17639. + * 1 for host-app, 1 for VMCS, and these are hooked together by a loopback MPHI VCFW
  17640. + * driver. */
  17641. +#ifndef VCHI_MAX_NUM_CONNECTIONS
  17642. +# define VCHI_MAX_NUM_CONNECTIONS 3
  17643. +#endif
  17644. +
  17645. +/* How many services can we open per connection? Extending this doesn't cost processing time, just a small
  17646. + * amount of static memory. */
  17647. +#ifndef VCHI_MAX_SERVICES_PER_CONNECTION
  17648. +# define VCHI_MAX_SERVICES_PER_CONNECTION 36
  17649. +#endif
  17650. +
  17651. +/* Adjust if using a message driver that supports more logical TX channels */
  17652. +#ifndef VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION
  17653. +# define VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION 9 // 1 MPHI + 8 CCP2 logical channels
  17654. +#endif
  17655. +
  17656. +/* Adjust if using a message driver that supports more logical RX channels */
  17657. +#ifndef VCHI_MAX_BULK_RX_CHANNELS_PER_CONNECTION
  17658. +# define VCHI_MAX_BULK_RX_CHANNELS_PER_CONNECTION 1 // 1 MPHI
  17659. +#endif
  17660. +
  17661. +/* How many receive slots do we use. This times VCHI_MAX_MSG_SIZE gives the effective
  17662. + * receive queue space, less message headers. */
  17663. +#ifndef VCHI_NUM_READ_SLOTS
  17664. +# if defined(VCHI_LOCAL_HOST_PORT)
  17665. +# define VCHI_NUM_READ_SLOTS 4
  17666. +# else
  17667. +# define VCHI_NUM_READ_SLOTS 48
  17668. +# endif
  17669. +#endif
  17670. +
  17671. +/* Do we utilise overrun facility for receive message slots? Can aid peer transmit
  17672. + * performance. Only define on VideoCore end, talking to host.
  17673. + */
  17674. +//#define VCHI_MSG_RX_OVERRUN
  17675. +
  17676. +/* How many transmit slots do we use. Generally don't need many, as the hardware driver
  17677. + * underneath VCHI will usually have its own buffering. */
  17678. +#ifndef VCHI_NUM_WRITE_SLOTS
  17679. +# define VCHI_NUM_WRITE_SLOTS 4
  17680. +#endif
  17681. +
  17682. +/* If a service has held or queued received messages in VCHI_XOFF_THRESHOLD or more slots,
  17683. + * then it's taking up too much buffer space, and the peer service will be told to stop
  17684. + * transmitting with an XOFF message. For this to be effective, the VCHI_NUM_READ_SLOTS
  17685. + * needs to be considerably bigger than VCHI_NUM_WRITE_SLOTS, or the transmit latency
  17686. + * is too high. */
  17687. +#ifndef VCHI_XOFF_THRESHOLD
  17688. +# define VCHI_XOFF_THRESHOLD (VCHI_NUM_READ_SLOTS / 2)
  17689. +#endif
  17690. +
  17691. +/* After we've sent an XOFF, the peer will be told to resume transmission once the local
  17692. + * service has dequeued/released enough messages that it's now occupying
  17693. + * VCHI_XON_THRESHOLD slots or fewer. */
  17694. +#ifndef VCHI_XON_THRESHOLD
  17695. +# define VCHI_XON_THRESHOLD (VCHI_NUM_READ_SLOTS / 4)
  17696. +#endif
  17697. +
  17698. +/* A size below which a bulk transfer omits the handshake completely and always goes
  17699. + * via the message channel, if bulk auxiliary is being sent on that service. (The user
  17700. + * can guarantee this by enabling unaligned transmits).
  17701. + * Not API. */
  17702. +#ifndef VCHI_MIN_BULK_SIZE
  17703. +# define VCHI_MIN_BULK_SIZE ( VCHI_MAX_MSG_SIZE / 2 < 4096 ? VCHI_MAX_MSG_SIZE / 2 : 4096 )
  17704. +#endif
  17705. +
  17706. +/* Maximum size of bulk transmission chunks, for each interface type. A trade-off between
  17707. + * speed and latency; the smaller the chunk size the better change of messages and other
  17708. + * bulk transmissions getting in when big bulk transfers are happening. Set to 0 to not
  17709. + * break transmissions into chunks.
  17710. + */
  17711. +#ifndef VCHI_MAX_BULK_CHUNK_SIZE_MPHI
  17712. +# define VCHI_MAX_BULK_CHUNK_SIZE_MPHI (16 * 1024)
  17713. +#endif
  17714. +
  17715. +/* NB Chunked CCP2 transmissions violate the letter of the CCP2 spec by using "JPEG8" mode
  17716. + * with multiple-line frames. Only use if the receiver can cope. */
  17717. +#ifndef VCHI_MAX_BULK_CHUNK_SIZE_CCP2
  17718. +# define VCHI_MAX_BULK_CHUNK_SIZE_CCP2 0
  17719. +#endif
  17720. +
  17721. +/* How many TX messages can we have pending in our transmit slots. Once exhausted,
  17722. + * vchi_msg_queue will be blocked. */
  17723. +#ifndef VCHI_TX_MSG_QUEUE_SIZE
  17724. +# define VCHI_TX_MSG_QUEUE_SIZE 256
  17725. +#endif
  17726. +
  17727. +/* How many RX messages can we have parsed in the receive slots. Once exhausted, parsing
  17728. + * will be suspended until older messages are dequeued/released. */
  17729. +#ifndef VCHI_RX_MSG_QUEUE_SIZE
  17730. +# define VCHI_RX_MSG_QUEUE_SIZE 256
  17731. +#endif
  17732. +
  17733. +/* Really should be able to cope if we run out of received message descriptors, by
  17734. + * suspending parsing as the comment above says, but we don't. This sweeps the issue
  17735. + * under the carpet. */
  17736. +#if VCHI_RX_MSG_QUEUE_SIZE < (VCHI_MAX_MSG_SIZE/16 + 1) * VCHI_NUM_READ_SLOTS
  17737. +# undef VCHI_RX_MSG_QUEUE_SIZE
  17738. +# define VCHI_RX_MSG_QUEUE_SIZE (VCHI_MAX_MSG_SIZE/16 + 1) * VCHI_NUM_READ_SLOTS
  17739. +#endif
  17740. +
  17741. +/* How many bulk transmits can we have pending. Once exhausted, vchi_bulk_queue_transmit
  17742. + * will be blocked. */
  17743. +#ifndef VCHI_TX_BULK_QUEUE_SIZE
  17744. +# define VCHI_TX_BULK_QUEUE_SIZE 64
  17745. +#endif
  17746. +
  17747. +/* How many bulk receives can we have pending. Once exhausted, vchi_bulk_queue_receive
  17748. + * will be blocked. */
  17749. +#ifndef VCHI_RX_BULK_QUEUE_SIZE
  17750. +# define VCHI_RX_BULK_QUEUE_SIZE 64
  17751. +#endif
  17752. +
  17753. +/* A limit on how many outstanding bulk requests we expect the peer to give us. If
  17754. + * the peer asks for more than this, VCHI will fail and assert. The number is determined
  17755. + * by the peer's hardware - it's the number of outstanding requests that can be queued
  17756. + * on all bulk channels. VC3's MPHI peripheral allows 16. */
  17757. +#ifndef VCHI_MAX_PEER_BULK_REQUESTS
  17758. +# define VCHI_MAX_PEER_BULK_REQUESTS 32
  17759. +#endif
  17760. +
  17761. +/* Define VCHI_CCP2TX_MANUAL_POWER if the host tells us when to turn the CCP2
  17762. + * transmitter on and off.
  17763. + */
  17764. +/*#define VCHI_CCP2TX_MANUAL_POWER*/
  17765. +
  17766. +#ifndef VCHI_CCP2TX_MANUAL_POWER
  17767. +
  17768. +/* Timeout (in milliseconds) for putting the CCP2TX interface into IDLE state. Set
  17769. + * negative for no IDLE.
  17770. + */
  17771. +# ifndef VCHI_CCP2TX_IDLE_TIMEOUT
  17772. +# define VCHI_CCP2TX_IDLE_TIMEOUT 5
  17773. +# endif
  17774. +
  17775. +/* Timeout (in milliseconds) for putting the CCP2TX interface into OFF state. Set
  17776. + * negative for no OFF.
  17777. + */
  17778. +# ifndef VCHI_CCP2TX_OFF_TIMEOUT
  17779. +# define VCHI_CCP2TX_OFF_TIMEOUT 1000
  17780. +# endif
  17781. +
  17782. +#endif /* VCHI_CCP2TX_MANUAL_POWER */
  17783. +
  17784. +#endif /* VCHI_CFG_H_ */
  17785. +
  17786. +/****************************** End of file **********************************/
  17787. diff -Nur linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h linux-3.13.3/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h
  17788. --- linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h 1970-01-01 01:00:00.000000000 +0100
  17789. +++ linux-3.13.3/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h 2014-02-17 22:41:01.000000000 +0100
  17790. @@ -0,0 +1,71 @@
  17791. +/**
  17792. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  17793. + *
  17794. + * Redistribution and use in source and binary forms, with or without
  17795. + * modification, are permitted provided that the following conditions
  17796. + * are met:
  17797. + * 1. Redistributions of source code must retain the above copyright
  17798. + * notice, this list of conditions, and the following disclaimer,
  17799. + * without modification.
  17800. + * 2. Redistributions in binary form must reproduce the above copyright
  17801. + * notice, this list of conditions and the following disclaimer in the
  17802. + * documentation and/or other materials provided with the distribution.
  17803. + * 3. The names of the above-listed copyright holders may not be used
  17804. + * to endorse or promote products derived from this software without
  17805. + * specific prior written permission.
  17806. + *
  17807. + * ALTERNATIVELY, this software may be distributed under the terms of the
  17808. + * GNU General Public License ("GPL") version 2, as published by the Free
  17809. + * Software Foundation.
  17810. + *
  17811. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  17812. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  17813. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  17814. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  17815. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  17816. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  17817. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  17818. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  17819. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  17820. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  17821. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  17822. + */
  17823. +
  17824. +#ifndef VCHI_CFG_INTERNAL_H_
  17825. +#define VCHI_CFG_INTERNAL_H_
  17826. +
  17827. +/****************************************************************************************
  17828. + * Control optimisation attempts.
  17829. + ***************************************************************************************/
  17830. +
  17831. +// Don't use lots of short-term locks - use great long ones, reducing the overall locks-per-second
  17832. +#define VCHI_COARSE_LOCKING
  17833. +
  17834. +// Avoid lock then unlock on exit from blocking queue operations (msg tx, bulk rx/tx)
  17835. +// (only relevant if VCHI_COARSE_LOCKING)
  17836. +#define VCHI_ELIDE_BLOCK_EXIT_LOCK
  17837. +
  17838. +// Avoid lock on non-blocking peek
  17839. +// (only relevant if VCHI_COARSE_LOCKING)
  17840. +#define VCHI_AVOID_PEEK_LOCK
  17841. +
  17842. +// Use one slot-handler thread per connection, rather than 1 thread dealing with all connections in rotation.
  17843. +#define VCHI_MULTIPLE_HANDLER_THREADS
  17844. +
  17845. +// Put free descriptors onto the head of the free queue, rather than the tail, so that we don't thrash
  17846. +// our way through the pool of descriptors.
  17847. +#define VCHI_PUSH_FREE_DESCRIPTORS_ONTO_HEAD
  17848. +
  17849. +// Don't issue a MSG_AVAILABLE callback for every single message. Possibly only safe if VCHI_COARSE_LOCKING.
  17850. +#define VCHI_FEWER_MSG_AVAILABLE_CALLBACKS
  17851. +
  17852. +// Don't use message descriptors for TX messages that don't need them
  17853. +#define VCHI_MINIMISE_TX_MSG_DESCRIPTORS
  17854. +
  17855. +// Nano-locks for multiqueue
  17856. +//#define VCHI_MQUEUE_NANOLOCKS
  17857. +
  17858. +// Lock-free(er) dequeuing
  17859. +//#define VCHI_RX_NANOLOCKS
  17860. +
  17861. +#endif /*VCHI_CFG_INTERNAL_H_*/
  17862. diff -Nur linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchi/vchi_common.h linux-3.13.3/drivers/misc/vc04_services/interface/vchi/vchi_common.h
  17863. --- linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchi/vchi_common.h 1970-01-01 01:00:00.000000000 +0100
  17864. +++ linux-3.13.3/drivers/misc/vc04_services/interface/vchi/vchi_common.h 2014-02-17 22:41:01.000000000 +0100
  17865. @@ -0,0 +1,163 @@
  17866. +/**
  17867. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  17868. + *
  17869. + * Redistribution and use in source and binary forms, with or without
  17870. + * modification, are permitted provided that the following conditions
  17871. + * are met:
  17872. + * 1. Redistributions of source code must retain the above copyright
  17873. + * notice, this list of conditions, and the following disclaimer,
  17874. + * without modification.
  17875. + * 2. Redistributions in binary form must reproduce the above copyright
  17876. + * notice, this list of conditions and the following disclaimer in the
  17877. + * documentation and/or other materials provided with the distribution.
  17878. + * 3. The names of the above-listed copyright holders may not be used
  17879. + * to endorse or promote products derived from this software without
  17880. + * specific prior written permission.
  17881. + *
  17882. + * ALTERNATIVELY, this software may be distributed under the terms of the
  17883. + * GNU General Public License ("GPL") version 2, as published by the Free
  17884. + * Software Foundation.
  17885. + *
  17886. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  17887. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  17888. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  17889. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  17890. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  17891. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  17892. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  17893. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  17894. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  17895. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  17896. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  17897. + */
  17898. +
  17899. +#ifndef VCHI_COMMON_H_
  17900. +#define VCHI_COMMON_H_
  17901. +
  17902. +
  17903. +//flags used when sending messages (must be bitmapped)
  17904. +typedef enum
  17905. +{
  17906. + VCHI_FLAGS_NONE = 0x0,
  17907. + 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)
  17908. + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE = 0x2, // run a callback when message sent
  17909. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED = 0x4, // return once the transfer is in a queue ready to go
  17910. + VCHI_FLAGS_ALLOW_PARTIAL = 0x8,
  17911. + VCHI_FLAGS_BLOCK_UNTIL_DATA_READ = 0x10,
  17912. + VCHI_FLAGS_CALLBACK_WHEN_DATA_READ = 0x20,
  17913. +
  17914. + VCHI_FLAGS_ALIGN_SLOT = 0x000080, // internal use only
  17915. + VCHI_FLAGS_BULK_AUX_QUEUED = 0x010000, // internal use only
  17916. + VCHI_FLAGS_BULK_AUX_COMPLETE = 0x020000, // internal use only
  17917. + VCHI_FLAGS_BULK_DATA_QUEUED = 0x040000, // internal use only
  17918. + VCHI_FLAGS_BULK_DATA_COMPLETE = 0x080000, // internal use only
  17919. + VCHI_FLAGS_INTERNAL = 0xFF0000
  17920. +} VCHI_FLAGS_T;
  17921. +
  17922. +// constants for vchi_crc_control()
  17923. +typedef enum {
  17924. + VCHI_CRC_NOTHING = -1,
  17925. + VCHI_CRC_PER_SERVICE = 0,
  17926. + VCHI_CRC_EVERYTHING = 1,
  17927. +} VCHI_CRC_CONTROL_T;
  17928. +
  17929. +//callback reasons when an event occurs on a service
  17930. +typedef enum
  17931. +{
  17932. + VCHI_CALLBACK_REASON_MIN,
  17933. +
  17934. + //This indicates that there is data available
  17935. + //handle is the msg id that was transmitted with the data
  17936. + // When a message is received and there was no FULL message available previously, send callback
  17937. + // Tasks get kicked by the callback, reset their event and try and read from the fifo until it fails
  17938. + VCHI_CALLBACK_MSG_AVAILABLE,
  17939. + VCHI_CALLBACK_MSG_SENT,
  17940. + VCHI_CALLBACK_MSG_SPACE_AVAILABLE, // XXX not yet implemented
  17941. +
  17942. + // This indicates that a transfer from the other side has completed
  17943. + VCHI_CALLBACK_BULK_RECEIVED,
  17944. + //This indicates that data queued up to be sent has now gone
  17945. + //handle is the msg id that was used when sending the data
  17946. + VCHI_CALLBACK_BULK_SENT,
  17947. + VCHI_CALLBACK_BULK_RX_SPACE_AVAILABLE, // XXX not yet implemented
  17948. + VCHI_CALLBACK_BULK_TX_SPACE_AVAILABLE, // XXX not yet implemented
  17949. +
  17950. + VCHI_CALLBACK_SERVICE_CLOSED,
  17951. +
  17952. + // this side has sent XOFF to peer due to lack of data consumption by service
  17953. + // (suggests the service may need to take some recovery action if it has
  17954. + // been deliberately holding off consuming data)
  17955. + VCHI_CALLBACK_SENT_XOFF,
  17956. + VCHI_CALLBACK_SENT_XON,
  17957. +
  17958. + // indicates that a bulk transfer has finished reading the source buffer
  17959. + VCHI_CALLBACK_BULK_DATA_READ,
  17960. +
  17961. + // power notification events (currently host side only)
  17962. + VCHI_CALLBACK_PEER_OFF,
  17963. + VCHI_CALLBACK_PEER_SUSPENDED,
  17964. + VCHI_CALLBACK_PEER_ON,
  17965. + VCHI_CALLBACK_PEER_RESUMED,
  17966. + VCHI_CALLBACK_FORCED_POWER_OFF,
  17967. +
  17968. +#ifdef USE_VCHIQ_ARM
  17969. + // some extra notifications provided by vchiq_arm
  17970. + VCHI_CALLBACK_SERVICE_OPENED,
  17971. + VCHI_CALLBACK_BULK_RECEIVE_ABORTED,
  17972. + VCHI_CALLBACK_BULK_TRANSMIT_ABORTED,
  17973. +#endif
  17974. +
  17975. + VCHI_CALLBACK_REASON_MAX
  17976. +} VCHI_CALLBACK_REASON_T;
  17977. +
  17978. +//Calback used by all services / bulk transfers
  17979. +typedef void (*VCHI_CALLBACK_T)( void *callback_param, //my service local param
  17980. + VCHI_CALLBACK_REASON_T reason,
  17981. + void *handle ); //for transmitting msg's only
  17982. +
  17983. +
  17984. +
  17985. +/*
  17986. + * Define vector struct for scatter-gather (vector) operations
  17987. + * Vectors can be nested - if a vector element has negative length, then
  17988. + * the data pointer is treated as pointing to another vector array, with
  17989. + * '-vec_len' elements. Thus to append a header onto an existing vector,
  17990. + * you can do this:
  17991. + *
  17992. + * void foo(const VCHI_MSG_VECTOR_T *v, int n)
  17993. + * {
  17994. + * VCHI_MSG_VECTOR_T nv[2];
  17995. + * nv[0].vec_base = my_header;
  17996. + * nv[0].vec_len = sizeof my_header;
  17997. + * nv[1].vec_base = v;
  17998. + * nv[1].vec_len = -n;
  17999. + * ...
  18000. + *
  18001. + */
  18002. +typedef struct vchi_msg_vector {
  18003. + const void *vec_base;
  18004. + int32_t vec_len;
  18005. +} VCHI_MSG_VECTOR_T;
  18006. +
  18007. +// Opaque type for a connection API
  18008. +typedef struct opaque_vchi_connection_api_t VCHI_CONNECTION_API_T;
  18009. +
  18010. +// Opaque type for a message driver
  18011. +typedef struct opaque_vchi_message_driver_t VCHI_MESSAGE_DRIVER_T;
  18012. +
  18013. +
  18014. +// Iterator structure for reading ahead through received message queue. Allocated by client,
  18015. +// initialised by vchi_msg_look_ahead. Fields are for internal VCHI use only.
  18016. +// Iterates over messages in queue at the instant of the call to vchi_msg_lookahead -
  18017. +// will not proceed to messages received since. Behaviour is undefined if an iterator
  18018. +// is used again after messages for that service are removed/dequeued by any
  18019. +// means other than vchi_msg_iter_... calls on the iterator itself.
  18020. +typedef struct {
  18021. + struct opaque_vchi_service_t *service;
  18022. + void *last;
  18023. + void *next;
  18024. + void *remove;
  18025. +} VCHI_MSG_ITER_T;
  18026. +
  18027. +
  18028. +#endif // VCHI_COMMON_H_
  18029. diff -Nur linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchi/vchi.h linux-3.13.3/drivers/misc/vc04_services/interface/vchi/vchi.h
  18030. --- linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchi/vchi.h 1970-01-01 01:00:00.000000000 +0100
  18031. +++ linux-3.13.3/drivers/misc/vc04_services/interface/vchi/vchi.h 2014-02-17 22:41:01.000000000 +0100
  18032. @@ -0,0 +1,373 @@
  18033. +/**
  18034. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  18035. + *
  18036. + * Redistribution and use in source and binary forms, with or without
  18037. + * modification, are permitted provided that the following conditions
  18038. + * are met:
  18039. + * 1. Redistributions of source code must retain the above copyright
  18040. + * notice, this list of conditions, and the following disclaimer,
  18041. + * without modification.
  18042. + * 2. Redistributions in binary form must reproduce the above copyright
  18043. + * notice, this list of conditions and the following disclaimer in the
  18044. + * documentation and/or other materials provided with the distribution.
  18045. + * 3. The names of the above-listed copyright holders may not be used
  18046. + * to endorse or promote products derived from this software without
  18047. + * specific prior written permission.
  18048. + *
  18049. + * ALTERNATIVELY, this software may be distributed under the terms of the
  18050. + * GNU General Public License ("GPL") version 2, as published by the Free
  18051. + * Software Foundation.
  18052. + *
  18053. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  18054. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  18055. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  18056. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18057. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18058. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18059. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  18060. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  18061. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  18062. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  18063. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  18064. + */
  18065. +
  18066. +#ifndef VCHI_H_
  18067. +#define VCHI_H_
  18068. +
  18069. +#include "interface/vchi/vchi_cfg.h"
  18070. +#include "interface/vchi/vchi_common.h"
  18071. +#include "interface/vchi/connections/connection.h"
  18072. +#include "vchi_mh.h"
  18073. +
  18074. +
  18075. +/******************************************************************************
  18076. + Global defs
  18077. + *****************************************************************************/
  18078. +
  18079. +#define VCHI_BULK_ROUND_UP(x) ((((unsigned long)(x))+VCHI_BULK_ALIGN-1) & ~(VCHI_BULK_ALIGN-1))
  18080. +#define VCHI_BULK_ROUND_DOWN(x) (((unsigned long)(x)) & ~(VCHI_BULK_ALIGN-1))
  18081. +#define VCHI_BULK_ALIGN_NBYTES(x) (VCHI_BULK_ALIGNED(x) ? 0 : (VCHI_BULK_ALIGN - ((unsigned long)(x) & (VCHI_BULK_ALIGN-1))))
  18082. +
  18083. +#ifdef USE_VCHIQ_ARM
  18084. +#define VCHI_BULK_ALIGNED(x) 1
  18085. +#else
  18086. +#define VCHI_BULK_ALIGNED(x) (((unsigned long)(x) & (VCHI_BULK_ALIGN-1)) == 0)
  18087. +#endif
  18088. +
  18089. +struct vchi_version {
  18090. + uint32_t version;
  18091. + uint32_t version_min;
  18092. +};
  18093. +#define VCHI_VERSION(v_) { v_, v_ }
  18094. +#define VCHI_VERSION_EX(v_, m_) { v_, m_ }
  18095. +
  18096. +typedef enum
  18097. +{
  18098. + VCHI_VEC_POINTER,
  18099. + VCHI_VEC_HANDLE,
  18100. + VCHI_VEC_LIST
  18101. +} VCHI_MSG_VECTOR_TYPE_T;
  18102. +
  18103. +typedef struct vchi_msg_vector_ex {
  18104. +
  18105. + VCHI_MSG_VECTOR_TYPE_T type;
  18106. + union
  18107. + {
  18108. + // a memory handle
  18109. + struct
  18110. + {
  18111. + VCHI_MEM_HANDLE_T handle;
  18112. + uint32_t offset;
  18113. + int32_t vec_len;
  18114. + } handle;
  18115. +
  18116. + // an ordinary data pointer
  18117. + struct
  18118. + {
  18119. + const void *vec_base;
  18120. + int32_t vec_len;
  18121. + } ptr;
  18122. +
  18123. + // a nested vector list
  18124. + struct
  18125. + {
  18126. + struct vchi_msg_vector_ex *vec;
  18127. + uint32_t vec_len;
  18128. + } list;
  18129. + } u;
  18130. +} VCHI_MSG_VECTOR_EX_T;
  18131. +
  18132. +
  18133. +// Construct an entry in a msg vector for a pointer (p) of length (l)
  18134. +#define VCHI_VEC_POINTER(p,l) VCHI_VEC_POINTER, { { (VCHI_MEM_HANDLE_T)(p), (l) } }
  18135. +
  18136. +// Construct an entry in a msg vector for a message handle (h), starting at offset (o) of length (l)
  18137. +#define VCHI_VEC_HANDLE(h,o,l) VCHI_VEC_HANDLE, { { (h), (o), (l) } }
  18138. +
  18139. +// Macros to manipulate 'FOURCC' values
  18140. +#define MAKE_FOURCC(x) ((int32_t)( (x[0] << 24) | (x[1] << 16) | (x[2] << 8) | x[3] ))
  18141. +#define FOURCC_TO_CHAR(x) (x >> 24) & 0xFF,(x >> 16) & 0xFF,(x >> 8) & 0xFF, x & 0xFF
  18142. +
  18143. +
  18144. +// Opaque service information
  18145. +struct opaque_vchi_service_t;
  18146. +
  18147. +// Descriptor for a held message. Allocated by client, initialised by vchi_msg_hold,
  18148. +// vchi_msg_iter_hold or vchi_msg_iter_hold_next. Fields are for internal VCHI use only.
  18149. +typedef struct
  18150. +{
  18151. + struct opaque_vchi_service_t *service;
  18152. + void *message;
  18153. +} VCHI_HELD_MSG_T;
  18154. +
  18155. +
  18156. +
  18157. +// structure used to provide the information needed to open a server or a client
  18158. +typedef struct {
  18159. + struct vchi_version version;
  18160. + int32_t service_id;
  18161. + VCHI_CONNECTION_T *connection;
  18162. + uint32_t rx_fifo_size;
  18163. + uint32_t tx_fifo_size;
  18164. + VCHI_CALLBACK_T callback;
  18165. + void *callback_param;
  18166. + /* client intends to receive bulk transfers of
  18167. + odd lengths or into unaligned buffers */
  18168. + int32_t want_unaligned_bulk_rx;
  18169. + /* client intends to transmit bulk transfers of
  18170. + odd lengths or out of unaligned buffers */
  18171. + int32_t want_unaligned_bulk_tx;
  18172. + /* client wants to check CRCs on (bulk) xfers.
  18173. + Only needs to be set at 1 end - will do both directions. */
  18174. + int32_t want_crc;
  18175. +} SERVICE_CREATION_T;
  18176. +
  18177. +// Opaque handle for a VCHI instance
  18178. +typedef struct opaque_vchi_instance_handle_t *VCHI_INSTANCE_T;
  18179. +
  18180. +// Opaque handle for a server or client
  18181. +typedef struct opaque_vchi_service_handle_t *VCHI_SERVICE_HANDLE_T;
  18182. +
  18183. +// Service registration & startup
  18184. +typedef void (*VCHI_SERVICE_INIT)(VCHI_INSTANCE_T initialise_instance, VCHI_CONNECTION_T **connections, uint32_t num_connections);
  18185. +
  18186. +typedef struct service_info_tag {
  18187. + const char * const vll_filename; /* VLL to load to start this service. This is an empty string if VLL is "static" */
  18188. + VCHI_SERVICE_INIT init; /* Service initialisation function */
  18189. + void *vll_handle; /* VLL handle; NULL when unloaded or a "static VLL" in build */
  18190. +} SERVICE_INFO_T;
  18191. +
  18192. +/******************************************************************************
  18193. + Global funcs - implementation is specific to which side you are on (local / remote)
  18194. + *****************************************************************************/
  18195. +
  18196. +#ifdef __cplusplus
  18197. +extern "C" {
  18198. +#endif
  18199. +
  18200. +extern /*@observer@*/ VCHI_CONNECTION_T * vchi_create_connection( const VCHI_CONNECTION_API_T * function_table,
  18201. + const VCHI_MESSAGE_DRIVER_T * low_level);
  18202. +
  18203. +
  18204. +// Routine used to initialise the vchi on both local + remote connections
  18205. +extern int32_t vchi_initialise( VCHI_INSTANCE_T *instance_handle );
  18206. +
  18207. +extern int32_t vchi_exit( void );
  18208. +
  18209. +extern int32_t vchi_connect( VCHI_CONNECTION_T **connections,
  18210. + const uint32_t num_connections,
  18211. + VCHI_INSTANCE_T instance_handle );
  18212. +
  18213. +//When this is called, ensure that all services have no data pending.
  18214. +//Bulk transfers can remain 'queued'
  18215. +extern int32_t vchi_disconnect( VCHI_INSTANCE_T instance_handle );
  18216. +
  18217. +// Global control over bulk CRC checking
  18218. +extern int32_t vchi_crc_control( VCHI_CONNECTION_T *connection,
  18219. + VCHI_CRC_CONTROL_T control );
  18220. +
  18221. +// helper functions
  18222. +extern void * vchi_allocate_buffer(VCHI_SERVICE_HANDLE_T handle, uint32_t *length);
  18223. +extern void vchi_free_buffer(VCHI_SERVICE_HANDLE_T handle, void *address);
  18224. +extern uint32_t vchi_current_time(VCHI_INSTANCE_T instance_handle);
  18225. +
  18226. +
  18227. +/******************************************************************************
  18228. + Global service API
  18229. + *****************************************************************************/
  18230. +// Routine to create a named service
  18231. +extern int32_t vchi_service_create( VCHI_INSTANCE_T instance_handle,
  18232. + SERVICE_CREATION_T *setup,
  18233. + VCHI_SERVICE_HANDLE_T *handle );
  18234. +
  18235. +// Routine to destory a service
  18236. +extern int32_t vchi_service_destroy( const VCHI_SERVICE_HANDLE_T handle );
  18237. +
  18238. +// Routine to open a named service
  18239. +extern int32_t vchi_service_open( VCHI_INSTANCE_T instance_handle,
  18240. + SERVICE_CREATION_T *setup,
  18241. + VCHI_SERVICE_HANDLE_T *handle);
  18242. +
  18243. +extern int32_t vchi_get_peer_version( const VCHI_SERVICE_HANDLE_T handle,
  18244. + short *peer_version );
  18245. +
  18246. +// Routine to close a named service
  18247. +extern int32_t vchi_service_close( const VCHI_SERVICE_HANDLE_T handle );
  18248. +
  18249. +// Routine to increment ref count on a named service
  18250. +extern int32_t vchi_service_use( const VCHI_SERVICE_HANDLE_T handle );
  18251. +
  18252. +// Routine to decrement ref count on a named service
  18253. +extern int32_t vchi_service_release( const VCHI_SERVICE_HANDLE_T handle );
  18254. +
  18255. +// Routine to send a message accross a service
  18256. +extern int32_t vchi_msg_queue( VCHI_SERVICE_HANDLE_T handle,
  18257. + const void *data,
  18258. + uint32_t data_size,
  18259. + VCHI_FLAGS_T flags,
  18260. + void *msg_handle );
  18261. +
  18262. +// scatter-gather (vector) and send message
  18263. +int32_t vchi_msg_queuev_ex( VCHI_SERVICE_HANDLE_T handle,
  18264. + VCHI_MSG_VECTOR_EX_T *vector,
  18265. + uint32_t count,
  18266. + VCHI_FLAGS_T flags,
  18267. + void *msg_handle );
  18268. +
  18269. +// legacy scatter-gather (vector) and send message, only handles pointers
  18270. +int32_t vchi_msg_queuev( VCHI_SERVICE_HANDLE_T handle,
  18271. + VCHI_MSG_VECTOR_T *vector,
  18272. + uint32_t count,
  18273. + VCHI_FLAGS_T flags,
  18274. + void *msg_handle );
  18275. +
  18276. +// Routine to receive a msg from a service
  18277. +// Dequeue is equivalent to hold, copy into client buffer, release
  18278. +extern int32_t vchi_msg_dequeue( VCHI_SERVICE_HANDLE_T handle,
  18279. + void *data,
  18280. + uint32_t max_data_size_to_read,
  18281. + uint32_t *actual_msg_size,
  18282. + VCHI_FLAGS_T flags );
  18283. +
  18284. +// Routine to look at a message in place.
  18285. +// The message is not dequeued, so a subsequent call to peek or dequeue
  18286. +// will return the same message.
  18287. +extern int32_t vchi_msg_peek( VCHI_SERVICE_HANDLE_T handle,
  18288. + void **data,
  18289. + uint32_t *msg_size,
  18290. + VCHI_FLAGS_T flags );
  18291. +
  18292. +// Routine to remove a message after it has been read in place with peek
  18293. +// The first message on the queue is dequeued.
  18294. +extern int32_t vchi_msg_remove( VCHI_SERVICE_HANDLE_T handle );
  18295. +
  18296. +// Routine to look at a message in place.
  18297. +// The message is dequeued, so the caller is left holding it; the descriptor is
  18298. +// filled in and must be released when the user has finished with the message.
  18299. +extern int32_t vchi_msg_hold( VCHI_SERVICE_HANDLE_T handle,
  18300. + void **data, // } may be NULL, as info can be
  18301. + uint32_t *msg_size, // } obtained from HELD_MSG_T
  18302. + VCHI_FLAGS_T flags,
  18303. + VCHI_HELD_MSG_T *message_descriptor );
  18304. +
  18305. +// Initialise an iterator to look through messages in place
  18306. +extern int32_t vchi_msg_look_ahead( VCHI_SERVICE_HANDLE_T handle,
  18307. + VCHI_MSG_ITER_T *iter,
  18308. + VCHI_FLAGS_T flags );
  18309. +
  18310. +/******************************************************************************
  18311. + Global service support API - operations on held messages and message iterators
  18312. + *****************************************************************************/
  18313. +
  18314. +// Routine to get the address of a held message
  18315. +extern void *vchi_held_msg_ptr( const VCHI_HELD_MSG_T *message );
  18316. +
  18317. +// Routine to get the size of a held message
  18318. +extern int32_t vchi_held_msg_size( const VCHI_HELD_MSG_T *message );
  18319. +
  18320. +// Routine to get the transmit timestamp as written into the header by the peer
  18321. +extern uint32_t vchi_held_msg_tx_timestamp( const VCHI_HELD_MSG_T *message );
  18322. +
  18323. +// Routine to get the reception timestamp, written as we parsed the header
  18324. +extern uint32_t vchi_held_msg_rx_timestamp( const VCHI_HELD_MSG_T *message );
  18325. +
  18326. +// Routine to release a held message after it has been processed
  18327. +extern int32_t vchi_held_msg_release( VCHI_HELD_MSG_T *message );
  18328. +
  18329. +// Indicates whether the iterator has a next message.
  18330. +extern int32_t vchi_msg_iter_has_next( const VCHI_MSG_ITER_T *iter );
  18331. +
  18332. +// Return the pointer and length for the next message and advance the iterator.
  18333. +extern int32_t vchi_msg_iter_next( VCHI_MSG_ITER_T *iter,
  18334. + void **data,
  18335. + uint32_t *msg_size );
  18336. +
  18337. +// Remove the last message returned by vchi_msg_iter_next.
  18338. +// Can only be called once after each call to vchi_msg_iter_next.
  18339. +extern int32_t vchi_msg_iter_remove( VCHI_MSG_ITER_T *iter );
  18340. +
  18341. +// Hold the last message returned by vchi_msg_iter_next.
  18342. +// Can only be called once after each call to vchi_msg_iter_next.
  18343. +extern int32_t vchi_msg_iter_hold( VCHI_MSG_ITER_T *iter,
  18344. + VCHI_HELD_MSG_T *message );
  18345. +
  18346. +// Return information for the next message, and hold it, advancing the iterator.
  18347. +extern int32_t vchi_msg_iter_hold_next( VCHI_MSG_ITER_T *iter,
  18348. + void **data, // } may be NULL
  18349. + uint32_t *msg_size, // }
  18350. + VCHI_HELD_MSG_T *message );
  18351. +
  18352. +
  18353. +/******************************************************************************
  18354. + Global bulk API
  18355. + *****************************************************************************/
  18356. +
  18357. +// Routine to prepare interface for a transfer from the other side
  18358. +extern int32_t vchi_bulk_queue_receive( VCHI_SERVICE_HANDLE_T handle,
  18359. + void *data_dst,
  18360. + uint32_t data_size,
  18361. + VCHI_FLAGS_T flags,
  18362. + void *transfer_handle );
  18363. +
  18364. +
  18365. +// Prepare interface for a transfer from the other side into relocatable memory.
  18366. +int32_t vchi_bulk_queue_receive_reloc( const VCHI_SERVICE_HANDLE_T handle,
  18367. + VCHI_MEM_HANDLE_T h_dst,
  18368. + uint32_t offset,
  18369. + uint32_t data_size,
  18370. + const VCHI_FLAGS_T flags,
  18371. + void * const bulk_handle );
  18372. +
  18373. +// Routine to queue up data ready for transfer to the other (once they have signalled they are ready)
  18374. +extern int32_t vchi_bulk_queue_transmit( VCHI_SERVICE_HANDLE_T handle,
  18375. + const void *data_src,
  18376. + uint32_t data_size,
  18377. + VCHI_FLAGS_T flags,
  18378. + void *transfer_handle );
  18379. +
  18380. +
  18381. +/******************************************************************************
  18382. + Configuration plumbing
  18383. + *****************************************************************************/
  18384. +
  18385. +// function prototypes for the different mid layers (the state info gives the different physical connections)
  18386. +extern const VCHI_CONNECTION_API_T *single_get_func_table( void );
  18387. +//extern const VCHI_CONNECTION_API_T *local_server_get_func_table( void );
  18388. +//extern const VCHI_CONNECTION_API_T *local_client_get_func_table( void );
  18389. +
  18390. +// declare all message drivers here
  18391. +const VCHI_MESSAGE_DRIVER_T *vchi_mphi_message_driver_func_table( void );
  18392. +
  18393. +#ifdef __cplusplus
  18394. +}
  18395. +#endif
  18396. +
  18397. +extern int32_t vchi_bulk_queue_transmit_reloc( VCHI_SERVICE_HANDLE_T handle,
  18398. + VCHI_MEM_HANDLE_T h_src,
  18399. + uint32_t offset,
  18400. + uint32_t data_size,
  18401. + VCHI_FLAGS_T flags,
  18402. + void *transfer_handle );
  18403. +#endif /* VCHI_H_ */
  18404. +
  18405. +/****************************** End of file **********************************/
  18406. diff -Nur linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchi/vchi_mh.h linux-3.13.3/drivers/misc/vc04_services/interface/vchi/vchi_mh.h
  18407. --- linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchi/vchi_mh.h 1970-01-01 01:00:00.000000000 +0100
  18408. +++ linux-3.13.3/drivers/misc/vc04_services/interface/vchi/vchi_mh.h 2014-02-17 22:41:01.000000000 +0100
  18409. @@ -0,0 +1,42 @@
  18410. +/**
  18411. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  18412. + *
  18413. + * Redistribution and use in source and binary forms, with or without
  18414. + * modification, are permitted provided that the following conditions
  18415. + * are met:
  18416. + * 1. Redistributions of source code must retain the above copyright
  18417. + * notice, this list of conditions, and the following disclaimer,
  18418. + * without modification.
  18419. + * 2. Redistributions in binary form must reproduce the above copyright
  18420. + * notice, this list of conditions and the following disclaimer in the
  18421. + * documentation and/or other materials provided with the distribution.
  18422. + * 3. The names of the above-listed copyright holders may not be used
  18423. + * to endorse or promote products derived from this software without
  18424. + * specific prior written permission.
  18425. + *
  18426. + * ALTERNATIVELY, this software may be distributed under the terms of the
  18427. + * GNU General Public License ("GPL") version 2, as published by the Free
  18428. + * Software Foundation.
  18429. + *
  18430. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  18431. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  18432. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  18433. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18434. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18435. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18436. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  18437. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  18438. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  18439. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  18440. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  18441. + */
  18442. +
  18443. +#ifndef VCHI_MH_H_
  18444. +#define VCHI_MH_H_
  18445. +
  18446. +#include <linux/types.h>
  18447. +
  18448. +typedef int32_t VCHI_MEM_HANDLE_T;
  18449. +#define VCHI_MEM_HANDLE_INVALID 0
  18450. +
  18451. +#endif
  18452. diff -Nur linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
  18453. --- linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c 1970-01-01 01:00:00.000000000 +0100
  18454. +++ linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c 2014-02-17 22:41:01.000000000 +0100
  18455. @@ -0,0 +1,561 @@
  18456. +/**
  18457. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  18458. + *
  18459. + * Redistribution and use in source and binary forms, with or without
  18460. + * modification, are permitted provided that the following conditions
  18461. + * are met:
  18462. + * 1. Redistributions of source code must retain the above copyright
  18463. + * notice, this list of conditions, and the following disclaimer,
  18464. + * without modification.
  18465. + * 2. Redistributions in binary form must reproduce the above copyright
  18466. + * notice, this list of conditions and the following disclaimer in the
  18467. + * documentation and/or other materials provided with the distribution.
  18468. + * 3. The names of the above-listed copyright holders may not be used
  18469. + * to endorse or promote products derived from this software without
  18470. + * specific prior written permission.
  18471. + *
  18472. + * ALTERNATIVELY, this software may be distributed under the terms of the
  18473. + * GNU General Public License ("GPL") version 2, as published by the Free
  18474. + * Software Foundation.
  18475. + *
  18476. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  18477. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  18478. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  18479. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18480. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18481. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18482. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  18483. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  18484. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  18485. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  18486. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  18487. + */
  18488. +
  18489. +#include <linux/kernel.h>
  18490. +#include <linux/types.h>
  18491. +#include <linux/errno.h>
  18492. +#include <linux/interrupt.h>
  18493. +#include <linux/irq.h>
  18494. +#include <linux/pagemap.h>
  18495. +#include <linux/dma-mapping.h>
  18496. +#include <linux/version.h>
  18497. +#include <linux/io.h>
  18498. +#include <linux/uaccess.h>
  18499. +#include <asm/pgtable.h>
  18500. +
  18501. +#include <mach/irqs.h>
  18502. +
  18503. +#include <mach/platform.h>
  18504. +#include <mach/vcio.h>
  18505. +
  18506. +#define TOTAL_SLOTS (VCHIQ_SLOT_ZERO_SLOTS + 2 * 32)
  18507. +
  18508. +#define VCHIQ_DOORBELL_IRQ IRQ_ARM_DOORBELL_0
  18509. +#define VCHIQ_ARM_ADDRESS(x) ((void *)__virt_to_bus((unsigned)x))
  18510. +
  18511. +#include "vchiq_arm.h"
  18512. +#include "vchiq_2835.h"
  18513. +#include "vchiq_connected.h"
  18514. +
  18515. +#define MAX_FRAGMENTS (VCHIQ_NUM_CURRENT_BULKS * 2)
  18516. +
  18517. +typedef struct vchiq_2835_state_struct {
  18518. + int inited;
  18519. + VCHIQ_ARM_STATE_T arm_state;
  18520. +} VCHIQ_2835_ARM_STATE_T;
  18521. +
  18522. +static char *g_slot_mem;
  18523. +static int g_slot_mem_size;
  18524. +dma_addr_t g_slot_phys;
  18525. +static FRAGMENTS_T *g_fragments_base;
  18526. +static FRAGMENTS_T *g_free_fragments;
  18527. +struct semaphore g_free_fragments_sema;
  18528. +
  18529. +extern int vchiq_arm_log_level;
  18530. +
  18531. +static DEFINE_SEMAPHORE(g_free_fragments_mutex);
  18532. +
  18533. +static irqreturn_t
  18534. +vchiq_doorbell_irq(int irq, void *dev_id);
  18535. +
  18536. +static int
  18537. +create_pagelist(char __user *buf, size_t count, unsigned short type,
  18538. + struct task_struct *task, PAGELIST_T ** ppagelist);
  18539. +
  18540. +static void
  18541. +free_pagelist(PAGELIST_T *pagelist, int actual);
  18542. +
  18543. +int __init
  18544. +vchiq_platform_init(VCHIQ_STATE_T *state)
  18545. +{
  18546. + VCHIQ_SLOT_ZERO_T *vchiq_slot_zero;
  18547. + int frag_mem_size;
  18548. + int err;
  18549. + int i;
  18550. +
  18551. + /* Allocate space for the channels in coherent memory */
  18552. + g_slot_mem_size = PAGE_ALIGN(TOTAL_SLOTS * VCHIQ_SLOT_SIZE);
  18553. + frag_mem_size = PAGE_ALIGN(sizeof(FRAGMENTS_T) * MAX_FRAGMENTS);
  18554. +
  18555. + g_slot_mem = dma_alloc_coherent(NULL, g_slot_mem_size + frag_mem_size,
  18556. + &g_slot_phys, GFP_ATOMIC);
  18557. +
  18558. + if (!g_slot_mem) {
  18559. + vchiq_log_error(vchiq_arm_log_level,
  18560. + "Unable to allocate channel memory");
  18561. + err = -ENOMEM;
  18562. + goto failed_alloc;
  18563. + }
  18564. +
  18565. + WARN_ON(((int)g_slot_mem & (PAGE_SIZE - 1)) != 0);
  18566. +
  18567. + vchiq_slot_zero = vchiq_init_slots(g_slot_mem, g_slot_mem_size);
  18568. + if (!vchiq_slot_zero) {
  18569. + err = -EINVAL;
  18570. + goto failed_init_slots;
  18571. + }
  18572. +
  18573. + vchiq_slot_zero->platform_data[VCHIQ_PLATFORM_FRAGMENTS_OFFSET_IDX] =
  18574. + (int)g_slot_phys + g_slot_mem_size;
  18575. + vchiq_slot_zero->platform_data[VCHIQ_PLATFORM_FRAGMENTS_COUNT_IDX] =
  18576. + MAX_FRAGMENTS;
  18577. +
  18578. + g_fragments_base = (FRAGMENTS_T *)(g_slot_mem + g_slot_mem_size);
  18579. + g_slot_mem_size += frag_mem_size;
  18580. +
  18581. + g_free_fragments = g_fragments_base;
  18582. + for (i = 0; i < (MAX_FRAGMENTS - 1); i++) {
  18583. + *(FRAGMENTS_T **)&g_fragments_base[i] =
  18584. + &g_fragments_base[i + 1];
  18585. + }
  18586. + *(FRAGMENTS_T **)&g_fragments_base[i] = NULL;
  18587. + sema_init(&g_free_fragments_sema, MAX_FRAGMENTS);
  18588. +
  18589. + if (vchiq_init_state(state, vchiq_slot_zero, 0/*slave*/) !=
  18590. + VCHIQ_SUCCESS) {
  18591. + err = -EINVAL;
  18592. + goto failed_vchiq_init;
  18593. + }
  18594. +
  18595. + err = request_irq(VCHIQ_DOORBELL_IRQ, vchiq_doorbell_irq,
  18596. + IRQF_IRQPOLL, "VCHIQ doorbell",
  18597. + state);
  18598. + if (err < 0) {
  18599. + vchiq_log_error(vchiq_arm_log_level, "%s: failed to register "
  18600. + "irq=%d err=%d", __func__,
  18601. + VCHIQ_DOORBELL_IRQ, err);
  18602. + goto failed_request_irq;
  18603. + }
  18604. +
  18605. + /* Send the base address of the slots to VideoCore */
  18606. +
  18607. + dsb(); /* Ensure all writes have completed */
  18608. +
  18609. + bcm_mailbox_write(MBOX_CHAN_VCHIQ, (unsigned int)g_slot_phys);
  18610. +
  18611. + vchiq_log_info(vchiq_arm_log_level,
  18612. + "vchiq_init - done (slots %x, phys %x)",
  18613. + (unsigned int)vchiq_slot_zero, g_slot_phys);
  18614. +
  18615. + vchiq_call_connected_callbacks();
  18616. +
  18617. + return 0;
  18618. +
  18619. +failed_request_irq:
  18620. +failed_vchiq_init:
  18621. +failed_init_slots:
  18622. + dma_free_coherent(NULL, g_slot_mem_size, g_slot_mem, g_slot_phys);
  18623. +
  18624. +failed_alloc:
  18625. + return err;
  18626. +}
  18627. +
  18628. +void __exit
  18629. +vchiq_platform_exit(VCHIQ_STATE_T *state)
  18630. +{
  18631. + free_irq(VCHIQ_DOORBELL_IRQ, state);
  18632. + dma_free_coherent(NULL, g_slot_mem_size,
  18633. + g_slot_mem, g_slot_phys);
  18634. +}
  18635. +
  18636. +
  18637. +VCHIQ_STATUS_T
  18638. +vchiq_platform_init_state(VCHIQ_STATE_T *state)
  18639. +{
  18640. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  18641. + state->platform_state = kzalloc(sizeof(VCHIQ_2835_ARM_STATE_T), GFP_KERNEL);
  18642. + ((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited = 1;
  18643. + status = vchiq_arm_init_state(state, &((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->arm_state);
  18644. + if(status != VCHIQ_SUCCESS)
  18645. + {
  18646. + ((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited = 0;
  18647. + }
  18648. + return status;
  18649. +}
  18650. +
  18651. +VCHIQ_ARM_STATE_T*
  18652. +vchiq_platform_get_arm_state(VCHIQ_STATE_T *state)
  18653. +{
  18654. + if(!((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited)
  18655. + {
  18656. + BUG();
  18657. + }
  18658. + return &((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->arm_state;
  18659. +}
  18660. +
  18661. +void
  18662. +remote_event_signal(REMOTE_EVENT_T *event)
  18663. +{
  18664. + wmb();
  18665. +
  18666. + event->fired = 1;
  18667. +
  18668. + dsb(); /* data barrier operation */
  18669. +
  18670. + if (event->armed) {
  18671. + /* trigger vc interrupt */
  18672. +
  18673. + writel(0, __io_address(ARM_0_BELL2));
  18674. + }
  18675. +}
  18676. +
  18677. +int
  18678. +vchiq_copy_from_user(void *dst, const void *src, int size)
  18679. +{
  18680. + if ((uint32_t)src < TASK_SIZE) {
  18681. + return copy_from_user(dst, src, size);
  18682. + } else {
  18683. + memcpy(dst, src, size);
  18684. + return 0;
  18685. + }
  18686. +}
  18687. +
  18688. +VCHIQ_STATUS_T
  18689. +vchiq_prepare_bulk_data(VCHIQ_BULK_T *bulk, VCHI_MEM_HANDLE_T memhandle,
  18690. + void *offset, int size, int dir)
  18691. +{
  18692. + PAGELIST_T *pagelist;
  18693. + int ret;
  18694. +
  18695. + WARN_ON(memhandle != VCHI_MEM_HANDLE_INVALID);
  18696. +
  18697. + ret = create_pagelist((char __user *)offset, size,
  18698. + (dir == VCHIQ_BULK_RECEIVE)
  18699. + ? PAGELIST_READ
  18700. + : PAGELIST_WRITE,
  18701. + current,
  18702. + &pagelist);
  18703. + if (ret != 0)
  18704. + return VCHIQ_ERROR;
  18705. +
  18706. + bulk->handle = memhandle;
  18707. + bulk->data = VCHIQ_ARM_ADDRESS(pagelist);
  18708. +
  18709. + /* Store the pagelist address in remote_data, which isn't used by the
  18710. + slave. */
  18711. + bulk->remote_data = pagelist;
  18712. +
  18713. + return VCHIQ_SUCCESS;
  18714. +}
  18715. +
  18716. +void
  18717. +vchiq_complete_bulk(VCHIQ_BULK_T *bulk)
  18718. +{
  18719. + if (bulk && bulk->remote_data && bulk->actual)
  18720. + free_pagelist((PAGELIST_T *)bulk->remote_data, bulk->actual);
  18721. +}
  18722. +
  18723. +void
  18724. +vchiq_transfer_bulk(VCHIQ_BULK_T *bulk)
  18725. +{
  18726. + /*
  18727. + * This should only be called on the master (VideoCore) side, but
  18728. + * provide an implementation to avoid the need for ifdefery.
  18729. + */
  18730. + BUG();
  18731. +}
  18732. +
  18733. +void
  18734. +vchiq_dump_platform_state(void *dump_context)
  18735. +{
  18736. + char buf[80];
  18737. + int len;
  18738. + len = snprintf(buf, sizeof(buf),
  18739. + " Platform: 2835 (VC master)");
  18740. + vchiq_dump(dump_context, buf, len + 1);
  18741. +}
  18742. +
  18743. +VCHIQ_STATUS_T
  18744. +vchiq_platform_suspend(VCHIQ_STATE_T *state)
  18745. +{
  18746. + return VCHIQ_ERROR;
  18747. +}
  18748. +
  18749. +VCHIQ_STATUS_T
  18750. +vchiq_platform_resume(VCHIQ_STATE_T *state)
  18751. +{
  18752. + return VCHIQ_SUCCESS;
  18753. +}
  18754. +
  18755. +void
  18756. +vchiq_platform_paused(VCHIQ_STATE_T *state)
  18757. +{
  18758. +}
  18759. +
  18760. +void
  18761. +vchiq_platform_resumed(VCHIQ_STATE_T *state)
  18762. +{
  18763. +}
  18764. +
  18765. +int
  18766. +vchiq_platform_videocore_wanted(VCHIQ_STATE_T* state)
  18767. +{
  18768. + return 1; // autosuspend not supported - videocore always wanted
  18769. +}
  18770. +
  18771. +int
  18772. +vchiq_platform_use_suspend_timer(void)
  18773. +{
  18774. + return 0;
  18775. +}
  18776. +void
  18777. +vchiq_dump_platform_use_state(VCHIQ_STATE_T *state)
  18778. +{
  18779. + vchiq_log_info((vchiq_arm_log_level>=VCHIQ_LOG_INFO),"Suspend timer not in use");
  18780. +}
  18781. +void
  18782. +vchiq_platform_handle_timeout(VCHIQ_STATE_T *state)
  18783. +{
  18784. + (void)state;
  18785. +}
  18786. +/*
  18787. + * Local functions
  18788. + */
  18789. +
  18790. +static irqreturn_t
  18791. +vchiq_doorbell_irq(int irq, void *dev_id)
  18792. +{
  18793. + VCHIQ_STATE_T *state = dev_id;
  18794. + irqreturn_t ret = IRQ_NONE;
  18795. + unsigned int status;
  18796. +
  18797. + /* Read (and clear) the doorbell */
  18798. + status = readl(__io_address(ARM_0_BELL0));
  18799. +
  18800. + if (status & 0x4) { /* Was the doorbell rung? */
  18801. + remote_event_pollall(state);
  18802. + ret = IRQ_HANDLED;
  18803. + }
  18804. +
  18805. + return ret;
  18806. +}
  18807. +
  18808. +/* There is a potential problem with partial cache lines (pages?)
  18809. +** at the ends of the block when reading. If the CPU accessed anything in
  18810. +** the same line (page?) then it may have pulled old data into the cache,
  18811. +** obscuring the new data underneath. We can solve this by transferring the
  18812. +** partial cache lines separately, and allowing the ARM to copy into the
  18813. +** cached area.
  18814. +
  18815. +** N.B. This implementation plays slightly fast and loose with the Linux
  18816. +** driver programming rules, e.g. its use of __virt_to_bus instead of
  18817. +** dma_map_single, but it isn't a multi-platform driver and it benefits
  18818. +** from increased speed as a result.
  18819. +*/
  18820. +
  18821. +static int
  18822. +create_pagelist(char __user *buf, size_t count, unsigned short type,
  18823. + struct task_struct *task, PAGELIST_T ** ppagelist)
  18824. +{
  18825. + PAGELIST_T *pagelist;
  18826. + struct page **pages;
  18827. + struct page *page;
  18828. + unsigned long *addrs;
  18829. + unsigned int num_pages, offset, i;
  18830. + char *addr, *base_addr, *next_addr;
  18831. + int run, addridx, actual_pages;
  18832. + unsigned long *need_release;
  18833. +
  18834. + offset = (unsigned int)buf & (PAGE_SIZE - 1);
  18835. + num_pages = (count + offset + PAGE_SIZE - 1) / PAGE_SIZE;
  18836. +
  18837. + *ppagelist = NULL;
  18838. +
  18839. + /* Allocate enough storage to hold the page pointers and the page
  18840. + ** list
  18841. + */
  18842. + pagelist = kmalloc(sizeof(PAGELIST_T) +
  18843. + (num_pages * sizeof(unsigned long)) +
  18844. + sizeof(unsigned long) +
  18845. + (num_pages * sizeof(pages[0])),
  18846. + GFP_KERNEL);
  18847. +
  18848. + vchiq_log_trace(vchiq_arm_log_level,
  18849. + "create_pagelist - %x", (unsigned int)pagelist);
  18850. + if (!pagelist)
  18851. + return -ENOMEM;
  18852. +
  18853. + addrs = pagelist->addrs;
  18854. + need_release = (unsigned long *)(addrs + num_pages);
  18855. + pages = (struct page **)(addrs + num_pages + 1);
  18856. +
  18857. + if (is_vmalloc_addr(buf)) {
  18858. + for (actual_pages = 0; actual_pages < num_pages; actual_pages++) {
  18859. + pages[actual_pages] = vmalloc_to_page(buf + (actual_pages * PAGE_SIZE));
  18860. + }
  18861. + *need_release = 0; /* do not try and release vmalloc pages */
  18862. + } else {
  18863. + down_read(&task->mm->mmap_sem);
  18864. + actual_pages = get_user_pages(task, task->mm,
  18865. + (unsigned long)buf & ~(PAGE_SIZE - 1),
  18866. + num_pages,
  18867. + (type == PAGELIST_READ) /*Write */ ,
  18868. + 0 /*Force */ ,
  18869. + pages,
  18870. + NULL /*vmas */);
  18871. + up_read(&task->mm->mmap_sem);
  18872. +
  18873. + if (actual_pages != num_pages) {
  18874. + vchiq_log_info(vchiq_arm_log_level,
  18875. + "create_pagelist - only %d/%d pages locked",
  18876. + actual_pages,
  18877. + num_pages);
  18878. +
  18879. + /* This is probably due to the process being killed */
  18880. + while (actual_pages > 0)
  18881. + {
  18882. + actual_pages--;
  18883. + page_cache_release(pages[actual_pages]);
  18884. + }
  18885. + kfree(pagelist);
  18886. + if (actual_pages == 0)
  18887. + actual_pages = -ENOMEM;
  18888. + return actual_pages;
  18889. + }
  18890. + *need_release = 1; /* release user pages */
  18891. + }
  18892. +
  18893. + pagelist->length = count;
  18894. + pagelist->type = type;
  18895. + pagelist->offset = offset;
  18896. +
  18897. + /* Group the pages into runs of contiguous pages */
  18898. +
  18899. + base_addr = VCHIQ_ARM_ADDRESS(page_address(pages[0]));
  18900. + next_addr = base_addr + PAGE_SIZE;
  18901. + addridx = 0;
  18902. + run = 0;
  18903. +
  18904. + for (i = 1; i < num_pages; i++) {
  18905. + addr = VCHIQ_ARM_ADDRESS(page_address(pages[i]));
  18906. + if ((addr == next_addr) && (run < (PAGE_SIZE - 1))) {
  18907. + next_addr += PAGE_SIZE;
  18908. + run++;
  18909. + } else {
  18910. + addrs[addridx] = (unsigned long)base_addr + run;
  18911. + addridx++;
  18912. + base_addr = addr;
  18913. + next_addr = addr + PAGE_SIZE;
  18914. + run = 0;
  18915. + }
  18916. + }
  18917. +
  18918. + addrs[addridx] = (unsigned long)base_addr + run;
  18919. + addridx++;
  18920. +
  18921. + /* Partial cache lines (fragments) require special measures */
  18922. + if ((type == PAGELIST_READ) &&
  18923. + ((pagelist->offset & (CACHE_LINE_SIZE - 1)) ||
  18924. + ((pagelist->offset + pagelist->length) &
  18925. + (CACHE_LINE_SIZE - 1)))) {
  18926. + FRAGMENTS_T *fragments;
  18927. +
  18928. + if (down_interruptible(&g_free_fragments_sema) != 0) {
  18929. + kfree(pagelist);
  18930. + return -EINTR;
  18931. + }
  18932. +
  18933. + WARN_ON(g_free_fragments == NULL);
  18934. +
  18935. + down(&g_free_fragments_mutex);
  18936. + fragments = (FRAGMENTS_T *) g_free_fragments;
  18937. + WARN_ON(fragments == NULL);
  18938. + g_free_fragments = *(FRAGMENTS_T **) g_free_fragments;
  18939. + up(&g_free_fragments_mutex);
  18940. + pagelist->type =
  18941. + PAGELIST_READ_WITH_FRAGMENTS + (fragments -
  18942. + g_fragments_base);
  18943. + }
  18944. +
  18945. + for (page = virt_to_page(pagelist);
  18946. + page <= virt_to_page(addrs + num_pages - 1); page++) {
  18947. + flush_dcache_page(page);
  18948. + }
  18949. +
  18950. + *ppagelist = pagelist;
  18951. +
  18952. + return 0;
  18953. +}
  18954. +
  18955. +static void
  18956. +free_pagelist(PAGELIST_T *pagelist, int actual)
  18957. +{
  18958. + unsigned long *need_release;
  18959. + struct page **pages;
  18960. + unsigned int num_pages, i;
  18961. +
  18962. + vchiq_log_trace(vchiq_arm_log_level,
  18963. + "free_pagelist - %x, %d", (unsigned int)pagelist, actual);
  18964. +
  18965. + num_pages =
  18966. + (pagelist->length + pagelist->offset + PAGE_SIZE - 1) /
  18967. + PAGE_SIZE;
  18968. +
  18969. + need_release = (unsigned long *)(pagelist->addrs + num_pages);
  18970. + pages = (struct page **)(pagelist->addrs + num_pages + 1);
  18971. +
  18972. + /* Deal with any partial cache lines (fragments) */
  18973. + if (pagelist->type >= PAGELIST_READ_WITH_FRAGMENTS) {
  18974. + FRAGMENTS_T *fragments = g_fragments_base +
  18975. + (pagelist->type - PAGELIST_READ_WITH_FRAGMENTS);
  18976. + int head_bytes, tail_bytes;
  18977. + head_bytes = (CACHE_LINE_SIZE - pagelist->offset) &
  18978. + (CACHE_LINE_SIZE - 1);
  18979. + tail_bytes = (pagelist->offset + actual) &
  18980. + (CACHE_LINE_SIZE - 1);
  18981. +
  18982. + if ((actual >= 0) && (head_bytes != 0)) {
  18983. + if (head_bytes > actual)
  18984. + head_bytes = actual;
  18985. +
  18986. + memcpy((char *)page_address(pages[0]) +
  18987. + pagelist->offset,
  18988. + fragments->headbuf,
  18989. + head_bytes);
  18990. + }
  18991. + if ((actual >= 0) && (head_bytes < actual) &&
  18992. + (tail_bytes != 0)) {
  18993. + memcpy((char *)page_address(pages[num_pages - 1]) +
  18994. + ((pagelist->offset + actual) &
  18995. + (PAGE_SIZE - 1) & ~(CACHE_LINE_SIZE - 1)),
  18996. + fragments->tailbuf, tail_bytes);
  18997. + }
  18998. +
  18999. + down(&g_free_fragments_mutex);
  19000. + *(FRAGMENTS_T **) fragments = g_free_fragments;
  19001. + g_free_fragments = fragments;
  19002. + up(&g_free_fragments_mutex);
  19003. + up(&g_free_fragments_sema);
  19004. + }
  19005. +
  19006. + if (*need_release) {
  19007. + for (i = 0; i < num_pages; i++) {
  19008. + if (pagelist->type != PAGELIST_WRITE)
  19009. + set_page_dirty(pages[i]);
  19010. +
  19011. + page_cache_release(pages[i]);
  19012. + }
  19013. + }
  19014. +
  19015. + kfree(pagelist);
  19016. +}
  19017. diff -Nur linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h
  19018. --- linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h 1970-01-01 01:00:00.000000000 +0100
  19019. +++ linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h 2014-02-17 22:41:01.000000000 +0100
  19020. @@ -0,0 +1,42 @@
  19021. +/**
  19022. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  19023. + *
  19024. + * Redistribution and use in source and binary forms, with or without
  19025. + * modification, are permitted provided that the following conditions
  19026. + * are met:
  19027. + * 1. Redistributions of source code must retain the above copyright
  19028. + * notice, this list of conditions, and the following disclaimer,
  19029. + * without modification.
  19030. + * 2. Redistributions in binary form must reproduce the above copyright
  19031. + * notice, this list of conditions and the following disclaimer in the
  19032. + * documentation and/or other materials provided with the distribution.
  19033. + * 3. The names of the above-listed copyright holders may not be used
  19034. + * to endorse or promote products derived from this software without
  19035. + * specific prior written permission.
  19036. + *
  19037. + * ALTERNATIVELY, this software may be distributed under the terms of the
  19038. + * GNU General Public License ("GPL") version 2, as published by the Free
  19039. + * Software Foundation.
  19040. + *
  19041. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  19042. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  19043. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19044. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  19045. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19046. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19047. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19048. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  19049. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  19050. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  19051. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19052. + */
  19053. +
  19054. +#ifndef VCHIQ_2835_H
  19055. +#define VCHIQ_2835_H
  19056. +
  19057. +#include "vchiq_pagelist.h"
  19058. +
  19059. +#define VCHIQ_PLATFORM_FRAGMENTS_OFFSET_IDX 0
  19060. +#define VCHIQ_PLATFORM_FRAGMENTS_COUNT_IDX 1
  19061. +
  19062. +#endif /* VCHIQ_2835_H */
  19063. diff -Nur linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c
  19064. --- linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c 1970-01-01 01:00:00.000000000 +0100
  19065. +++ linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c 2014-02-17 22:41:01.000000000 +0100
  19066. @@ -0,0 +1,2813 @@
  19067. +/**
  19068. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  19069. + *
  19070. + * Redistribution and use in source and binary forms, with or without
  19071. + * modification, are permitted provided that the following conditions
  19072. + * are met:
  19073. + * 1. Redistributions of source code must retain the above copyright
  19074. + * notice, this list of conditions, and the following disclaimer,
  19075. + * without modification.
  19076. + * 2. Redistributions in binary form must reproduce the above copyright
  19077. + * notice, this list of conditions and the following disclaimer in the
  19078. + * documentation and/or other materials provided with the distribution.
  19079. + * 3. The names of the above-listed copyright holders may not be used
  19080. + * to endorse or promote products derived from this software without
  19081. + * specific prior written permission.
  19082. + *
  19083. + * ALTERNATIVELY, this software may be distributed under the terms of the
  19084. + * GNU General Public License ("GPL") version 2, as published by the Free
  19085. + * Software Foundation.
  19086. + *
  19087. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  19088. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  19089. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19090. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  19091. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19092. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19093. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19094. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  19095. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  19096. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  19097. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19098. + */
  19099. +
  19100. +#include <linux/kernel.h>
  19101. +#include <linux/module.h>
  19102. +#include <linux/types.h>
  19103. +#include <linux/errno.h>
  19104. +#include <linux/cdev.h>
  19105. +#include <linux/fs.h>
  19106. +#include <linux/device.h>
  19107. +#include <linux/mm.h>
  19108. +#include <linux/highmem.h>
  19109. +#include <linux/pagemap.h>
  19110. +#include <linux/bug.h>
  19111. +#include <linux/semaphore.h>
  19112. +#include <linux/list.h>
  19113. +#include <linux/proc_fs.h>
  19114. +
  19115. +#include "vchiq_core.h"
  19116. +#include "vchiq_ioctl.h"
  19117. +#include "vchiq_arm.h"
  19118. +
  19119. +#define DEVICE_NAME "vchiq"
  19120. +
  19121. +/* Override the default prefix, which would be vchiq_arm (from the filename) */
  19122. +#undef MODULE_PARAM_PREFIX
  19123. +#define MODULE_PARAM_PREFIX DEVICE_NAME "."
  19124. +
  19125. +#define VCHIQ_MINOR 0
  19126. +
  19127. +/* Some per-instance constants */
  19128. +#define MAX_COMPLETIONS 16
  19129. +#define MAX_SERVICES 64
  19130. +#define MAX_ELEMENTS 8
  19131. +#define MSG_QUEUE_SIZE 64
  19132. +
  19133. +#define KEEPALIVE_VER 1
  19134. +#define KEEPALIVE_VER_MIN KEEPALIVE_VER
  19135. +
  19136. +/* Run time control of log level, based on KERN_XXX level. */
  19137. +int vchiq_arm_log_level = VCHIQ_LOG_DEFAULT;
  19138. +int vchiq_susp_log_level = VCHIQ_LOG_ERROR;
  19139. +
  19140. +#define SUSPEND_TIMER_TIMEOUT_MS 100
  19141. +#define SUSPEND_RETRY_TIMER_TIMEOUT_MS 1000
  19142. +
  19143. +#define VC_SUSPEND_NUM_OFFSET 3 /* number of values before idle which are -ve */
  19144. +static const char *const suspend_state_names[] = {
  19145. + "VC_SUSPEND_FORCE_CANCELED",
  19146. + "VC_SUSPEND_REJECTED",
  19147. + "VC_SUSPEND_FAILED",
  19148. + "VC_SUSPEND_IDLE",
  19149. + "VC_SUSPEND_REQUESTED",
  19150. + "VC_SUSPEND_IN_PROGRESS",
  19151. + "VC_SUSPEND_SUSPENDED"
  19152. +};
  19153. +#define VC_RESUME_NUM_OFFSET 1 /* number of values before idle which are -ve */
  19154. +static const char *const resume_state_names[] = {
  19155. + "VC_RESUME_FAILED",
  19156. + "VC_RESUME_IDLE",
  19157. + "VC_RESUME_REQUESTED",
  19158. + "VC_RESUME_IN_PROGRESS",
  19159. + "VC_RESUME_RESUMED"
  19160. +};
  19161. +/* The number of times we allow force suspend to timeout before actually
  19162. +** _forcing_ suspend. This is to cater for SW which fails to release vchiq
  19163. +** correctly - we don't want to prevent ARM suspend indefinitely in this case.
  19164. +*/
  19165. +#define FORCE_SUSPEND_FAIL_MAX 8
  19166. +
  19167. +/* The time in ms allowed for videocore to go idle when force suspend has been
  19168. + * requested */
  19169. +#define FORCE_SUSPEND_TIMEOUT_MS 200
  19170. +
  19171. +
  19172. +static void suspend_timer_callback(unsigned long context);
  19173. +static int vchiq_proc_add_instance(VCHIQ_INSTANCE_T instance);
  19174. +static void vchiq_proc_remove_instance(VCHIQ_INSTANCE_T instance);
  19175. +
  19176. +
  19177. +typedef struct user_service_struct {
  19178. + VCHIQ_SERVICE_T *service;
  19179. + void *userdata;
  19180. + VCHIQ_INSTANCE_T instance;
  19181. + int is_vchi;
  19182. + int dequeue_pending;
  19183. + int message_available_pos;
  19184. + int msg_insert;
  19185. + int msg_remove;
  19186. + struct semaphore insert_event;
  19187. + struct semaphore remove_event;
  19188. + VCHIQ_HEADER_T * msg_queue[MSG_QUEUE_SIZE];
  19189. +} USER_SERVICE_T;
  19190. +
  19191. +struct bulk_waiter_node {
  19192. + struct bulk_waiter bulk_waiter;
  19193. + int pid;
  19194. + struct list_head list;
  19195. +};
  19196. +
  19197. +struct vchiq_instance_struct {
  19198. + VCHIQ_STATE_T *state;
  19199. + VCHIQ_COMPLETION_DATA_T completions[MAX_COMPLETIONS];
  19200. + int completion_insert;
  19201. + int completion_remove;
  19202. + struct semaphore insert_event;
  19203. + struct semaphore remove_event;
  19204. + struct mutex completion_mutex;
  19205. +
  19206. + int connected;
  19207. + int closing;
  19208. + int pid;
  19209. + int mark;
  19210. +
  19211. + struct list_head bulk_waiter_list;
  19212. + struct mutex bulk_waiter_list_mutex;
  19213. +
  19214. + struct proc_dir_entry *proc_entry;
  19215. +};
  19216. +
  19217. +typedef struct dump_context_struct {
  19218. + char __user *buf;
  19219. + size_t actual;
  19220. + size_t space;
  19221. + loff_t offset;
  19222. +} DUMP_CONTEXT_T;
  19223. +
  19224. +static struct cdev vchiq_cdev;
  19225. +static dev_t vchiq_devid;
  19226. +static VCHIQ_STATE_T g_state;
  19227. +static struct class *vchiq_class;
  19228. +static struct device *vchiq_dev;
  19229. +static DEFINE_SPINLOCK(msg_queue_spinlock);
  19230. +
  19231. +static const char *const ioctl_names[] = {
  19232. + "CONNECT",
  19233. + "SHUTDOWN",
  19234. + "CREATE_SERVICE",
  19235. + "REMOVE_SERVICE",
  19236. + "QUEUE_MESSAGE",
  19237. + "QUEUE_BULK_TRANSMIT",
  19238. + "QUEUE_BULK_RECEIVE",
  19239. + "AWAIT_COMPLETION",
  19240. + "DEQUEUE_MESSAGE",
  19241. + "GET_CLIENT_ID",
  19242. + "GET_CONFIG",
  19243. + "CLOSE_SERVICE",
  19244. + "USE_SERVICE",
  19245. + "RELEASE_SERVICE",
  19246. + "SET_SERVICE_OPTION",
  19247. + "DUMP_PHYS_MEM"
  19248. +};
  19249. +
  19250. +vchiq_static_assert((sizeof(ioctl_names)/sizeof(ioctl_names[0])) ==
  19251. + (VCHIQ_IOC_MAX + 1));
  19252. +
  19253. +static void
  19254. +dump_phys_mem(void *virt_addr, uint32_t num_bytes);
  19255. +
  19256. +/****************************************************************************
  19257. +*
  19258. +* add_completion
  19259. +*
  19260. +***************************************************************************/
  19261. +
  19262. +static VCHIQ_STATUS_T
  19263. +add_completion(VCHIQ_INSTANCE_T instance, VCHIQ_REASON_T reason,
  19264. + VCHIQ_HEADER_T *header, USER_SERVICE_T *user_service,
  19265. + void *bulk_userdata)
  19266. +{
  19267. + VCHIQ_COMPLETION_DATA_T *completion;
  19268. + DEBUG_INITIALISE(g_state.local)
  19269. +
  19270. + while (instance->completion_insert ==
  19271. + (instance->completion_remove + MAX_COMPLETIONS)) {
  19272. + /* Out of space - wait for the client */
  19273. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  19274. + vchiq_log_trace(vchiq_arm_log_level,
  19275. + "add_completion - completion queue full");
  19276. + DEBUG_COUNT(COMPLETION_QUEUE_FULL_COUNT);
  19277. + if (down_interruptible(&instance->remove_event) != 0) {
  19278. + vchiq_log_info(vchiq_arm_log_level,
  19279. + "service_callback interrupted");
  19280. + return VCHIQ_RETRY;
  19281. + } else if (instance->closing) {
  19282. + vchiq_log_info(vchiq_arm_log_level,
  19283. + "service_callback closing");
  19284. + return VCHIQ_ERROR;
  19285. + }
  19286. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  19287. + }
  19288. +
  19289. + completion =
  19290. + &instance->completions[instance->completion_insert &
  19291. + (MAX_COMPLETIONS - 1)];
  19292. +
  19293. + completion->header = header;
  19294. + completion->reason = reason;
  19295. + /* N.B. service_userdata is updated while processing AWAIT_COMPLETION */
  19296. + completion->service_userdata = user_service->service;
  19297. + completion->bulk_userdata = bulk_userdata;
  19298. +
  19299. + if (reason == VCHIQ_SERVICE_CLOSED)
  19300. + /* Take an extra reference, to be held until
  19301. + this CLOSED notification is delivered. */
  19302. + lock_service(user_service->service);
  19303. +
  19304. + /* A write barrier is needed here to ensure that the entire completion
  19305. + record is written out before the insert point. */
  19306. + wmb();
  19307. +
  19308. + if (reason == VCHIQ_MESSAGE_AVAILABLE)
  19309. + user_service->message_available_pos =
  19310. + instance->completion_insert;
  19311. + instance->completion_insert++;
  19312. +
  19313. + up(&instance->insert_event);
  19314. +
  19315. + return VCHIQ_SUCCESS;
  19316. +}
  19317. +
  19318. +/****************************************************************************
  19319. +*
  19320. +* service_callback
  19321. +*
  19322. +***************************************************************************/
  19323. +
  19324. +static VCHIQ_STATUS_T
  19325. +service_callback(VCHIQ_REASON_T reason, VCHIQ_HEADER_T *header,
  19326. + VCHIQ_SERVICE_HANDLE_T handle, void *bulk_userdata)
  19327. +{
  19328. + /* How do we ensure the callback goes to the right client?
  19329. + ** The service_user data points to a USER_SERVICE_T record containing
  19330. + ** the original callback and the user state structure, which contains a
  19331. + ** circular buffer for completion records.
  19332. + */
  19333. + USER_SERVICE_T *user_service;
  19334. + VCHIQ_SERVICE_T *service;
  19335. + VCHIQ_INSTANCE_T instance;
  19336. + DEBUG_INITIALISE(g_state.local)
  19337. +
  19338. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  19339. +
  19340. + service = handle_to_service(handle);
  19341. + BUG_ON(!service);
  19342. + user_service = (USER_SERVICE_T *)service->base.userdata;
  19343. + instance = user_service->instance;
  19344. +
  19345. + if (!instance || instance->closing)
  19346. + return VCHIQ_SUCCESS;
  19347. +
  19348. + vchiq_log_trace(vchiq_arm_log_level,
  19349. + "service_callback - service %lx(%d), reason %d, header %lx, "
  19350. + "instance %lx, bulk_userdata %lx",
  19351. + (unsigned long)user_service,
  19352. + service->localport,
  19353. + reason, (unsigned long)header,
  19354. + (unsigned long)instance, (unsigned long)bulk_userdata);
  19355. +
  19356. + if (header && user_service->is_vchi) {
  19357. + spin_lock(&msg_queue_spinlock);
  19358. + while (user_service->msg_insert ==
  19359. + (user_service->msg_remove + MSG_QUEUE_SIZE)) {
  19360. + spin_unlock(&msg_queue_spinlock);
  19361. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  19362. + DEBUG_COUNT(MSG_QUEUE_FULL_COUNT);
  19363. + vchiq_log_trace(vchiq_arm_log_level,
  19364. + "service_callback - msg queue full");
  19365. + /* If there is no MESSAGE_AVAILABLE in the completion
  19366. + ** queue, add one
  19367. + */
  19368. + if ((user_service->message_available_pos -
  19369. + instance->completion_remove) < 0) {
  19370. + VCHIQ_STATUS_T status;
  19371. + vchiq_log_info(vchiq_arm_log_level,
  19372. + "Inserting extra MESSAGE_AVAILABLE");
  19373. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  19374. + status = add_completion(instance, reason,
  19375. + NULL, user_service, bulk_userdata);
  19376. + if (status != VCHIQ_SUCCESS) {
  19377. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  19378. + return status;
  19379. + }
  19380. + }
  19381. +
  19382. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  19383. + if (down_interruptible(&user_service->remove_event)
  19384. + != 0) {
  19385. + vchiq_log_info(vchiq_arm_log_level,
  19386. + "service_callback interrupted");
  19387. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  19388. + return VCHIQ_RETRY;
  19389. + } else if (instance->closing) {
  19390. + vchiq_log_info(vchiq_arm_log_level,
  19391. + "service_callback closing");
  19392. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  19393. + return VCHIQ_ERROR;
  19394. + }
  19395. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  19396. + spin_lock(&msg_queue_spinlock);
  19397. + }
  19398. +
  19399. + user_service->msg_queue[user_service->msg_insert &
  19400. + (MSG_QUEUE_SIZE - 1)] = header;
  19401. + user_service->msg_insert++;
  19402. + spin_unlock(&msg_queue_spinlock);
  19403. +
  19404. + up(&user_service->insert_event);
  19405. +
  19406. + /* If there is a thread waiting in DEQUEUE_MESSAGE, or if
  19407. + ** there is a MESSAGE_AVAILABLE in the completion queue then
  19408. + ** bypass the completion queue.
  19409. + */
  19410. + if (((user_service->message_available_pos -
  19411. + instance->completion_remove) >= 0) ||
  19412. + user_service->dequeue_pending) {
  19413. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  19414. + user_service->dequeue_pending = 0;
  19415. + return VCHIQ_SUCCESS;
  19416. + }
  19417. +
  19418. + header = NULL;
  19419. + }
  19420. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  19421. +
  19422. + return add_completion(instance, reason, header, user_service,
  19423. + bulk_userdata);
  19424. +}
  19425. +
  19426. +/****************************************************************************
  19427. +*
  19428. +* user_service_free
  19429. +*
  19430. +***************************************************************************/
  19431. +static void
  19432. +user_service_free(void *userdata)
  19433. +{
  19434. + kfree(userdata);
  19435. +}
  19436. +
  19437. +/****************************************************************************
  19438. +*
  19439. +* vchiq_ioctl
  19440. +*
  19441. +***************************************************************************/
  19442. +
  19443. +static long
  19444. +vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  19445. +{
  19446. + VCHIQ_INSTANCE_T instance = file->private_data;
  19447. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  19448. + VCHIQ_SERVICE_T *service = NULL;
  19449. + long ret = 0;
  19450. + int i, rc;
  19451. + DEBUG_INITIALISE(g_state.local)
  19452. +
  19453. + vchiq_log_trace(vchiq_arm_log_level,
  19454. + "vchiq_ioctl - instance %x, cmd %s, arg %lx",
  19455. + (unsigned int)instance,
  19456. + ((_IOC_TYPE(cmd) == VCHIQ_IOC_MAGIC) &&
  19457. + (_IOC_NR(cmd) <= VCHIQ_IOC_MAX)) ?
  19458. + ioctl_names[_IOC_NR(cmd)] : "<invalid>", arg);
  19459. +
  19460. + switch (cmd) {
  19461. + case VCHIQ_IOC_SHUTDOWN:
  19462. + if (!instance->connected)
  19463. + break;
  19464. +
  19465. + /* Remove all services */
  19466. + i = 0;
  19467. + while ((service = next_service_by_instance(instance->state,
  19468. + instance, &i)) != NULL) {
  19469. + status = vchiq_remove_service(service->handle);
  19470. + unlock_service(service);
  19471. + if (status != VCHIQ_SUCCESS)
  19472. + break;
  19473. + }
  19474. + service = NULL;
  19475. +
  19476. + if (status == VCHIQ_SUCCESS) {
  19477. + /* Wake the completion thread and ask it to exit */
  19478. + instance->closing = 1;
  19479. + up(&instance->insert_event);
  19480. + }
  19481. +
  19482. + break;
  19483. +
  19484. + case VCHIQ_IOC_CONNECT:
  19485. + if (instance->connected) {
  19486. + ret = -EINVAL;
  19487. + break;
  19488. + }
  19489. + rc = mutex_lock_interruptible(&instance->state->mutex);
  19490. + if (rc != 0) {
  19491. + vchiq_log_error(vchiq_arm_log_level,
  19492. + "vchiq: connect: could not lock mutex for "
  19493. + "state %d: %d",
  19494. + instance->state->id, rc);
  19495. + ret = -EINTR;
  19496. + break;
  19497. + }
  19498. + status = vchiq_connect_internal(instance->state, instance);
  19499. + mutex_unlock(&instance->state->mutex);
  19500. +
  19501. + if (status == VCHIQ_SUCCESS)
  19502. + instance->connected = 1;
  19503. + else
  19504. + vchiq_log_error(vchiq_arm_log_level,
  19505. + "vchiq: could not connect: %d", status);
  19506. + break;
  19507. +
  19508. + case VCHIQ_IOC_CREATE_SERVICE: {
  19509. + VCHIQ_CREATE_SERVICE_T args;
  19510. + USER_SERVICE_T *user_service = NULL;
  19511. + void *userdata;
  19512. + int srvstate;
  19513. +
  19514. + if (copy_from_user
  19515. + (&args, (const void __user *)arg,
  19516. + sizeof(args)) != 0) {
  19517. + ret = -EFAULT;
  19518. + break;
  19519. + }
  19520. +
  19521. + user_service = kmalloc(sizeof(USER_SERVICE_T), GFP_KERNEL);
  19522. + if (!user_service) {
  19523. + ret = -ENOMEM;
  19524. + break;
  19525. + }
  19526. +
  19527. + if (args.is_open) {
  19528. + if (!instance->connected) {
  19529. + ret = -ENOTCONN;
  19530. + kfree(user_service);
  19531. + break;
  19532. + }
  19533. + srvstate = VCHIQ_SRVSTATE_OPENING;
  19534. + } else {
  19535. + srvstate =
  19536. + instance->connected ?
  19537. + VCHIQ_SRVSTATE_LISTENING :
  19538. + VCHIQ_SRVSTATE_HIDDEN;
  19539. + }
  19540. +
  19541. + userdata = args.params.userdata;
  19542. + args.params.callback = service_callback;
  19543. + args.params.userdata = user_service;
  19544. + service = vchiq_add_service_internal(
  19545. + instance->state,
  19546. + &args.params, srvstate,
  19547. + instance, user_service_free);
  19548. +
  19549. + if (service != NULL) {
  19550. + user_service->service = service;
  19551. + user_service->userdata = userdata;
  19552. + user_service->instance = instance;
  19553. + user_service->is_vchi = args.is_vchi;
  19554. + user_service->dequeue_pending = 0;
  19555. + user_service->message_available_pos =
  19556. + instance->completion_remove - 1;
  19557. + user_service->msg_insert = 0;
  19558. + user_service->msg_remove = 0;
  19559. + sema_init(&user_service->insert_event, 0);
  19560. + sema_init(&user_service->remove_event, 0);
  19561. +
  19562. + if (args.is_open) {
  19563. + status = vchiq_open_service_internal
  19564. + (service, instance->pid);
  19565. + if (status != VCHIQ_SUCCESS) {
  19566. + vchiq_remove_service(service->handle);
  19567. + service = NULL;
  19568. + ret = (status == VCHIQ_RETRY) ?
  19569. + -EINTR : -EIO;
  19570. + break;
  19571. + }
  19572. + }
  19573. +
  19574. + if (copy_to_user((void __user *)
  19575. + &(((VCHIQ_CREATE_SERVICE_T __user *)
  19576. + arg)->handle),
  19577. + (const void *)&service->handle,
  19578. + sizeof(service->handle)) != 0) {
  19579. + ret = -EFAULT;
  19580. + vchiq_remove_service(service->handle);
  19581. + }
  19582. +
  19583. + service = NULL;
  19584. + } else {
  19585. + ret = -EEXIST;
  19586. + kfree(user_service);
  19587. + }
  19588. + } break;
  19589. +
  19590. + case VCHIQ_IOC_CLOSE_SERVICE: {
  19591. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  19592. +
  19593. + service = find_service_for_instance(instance, handle);
  19594. + if (service != NULL)
  19595. + status = vchiq_close_service(service->handle);
  19596. + else
  19597. + ret = -EINVAL;
  19598. + } break;
  19599. +
  19600. + case VCHIQ_IOC_REMOVE_SERVICE: {
  19601. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  19602. +
  19603. + service = find_service_for_instance(instance, handle);
  19604. + if (service != NULL)
  19605. + status = vchiq_remove_service(service->handle);
  19606. + else
  19607. + ret = -EINVAL;
  19608. + } break;
  19609. +
  19610. + case VCHIQ_IOC_USE_SERVICE:
  19611. + case VCHIQ_IOC_RELEASE_SERVICE: {
  19612. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  19613. +
  19614. + service = find_service_for_instance(instance, handle);
  19615. + if (service != NULL) {
  19616. + status = (cmd == VCHIQ_IOC_USE_SERVICE) ?
  19617. + vchiq_use_service_internal(service) :
  19618. + vchiq_release_service_internal(service);
  19619. + if (status != VCHIQ_SUCCESS) {
  19620. + vchiq_log_error(vchiq_susp_log_level,
  19621. + "%s: cmd %s returned error %d for "
  19622. + "service %c%c%c%c:%03d",
  19623. + __func__,
  19624. + (cmd == VCHIQ_IOC_USE_SERVICE) ?
  19625. + "VCHIQ_IOC_USE_SERVICE" :
  19626. + "VCHIQ_IOC_RELEASE_SERVICE",
  19627. + status,
  19628. + VCHIQ_FOURCC_AS_4CHARS(
  19629. + service->base.fourcc),
  19630. + service->client_id);
  19631. + ret = -EINVAL;
  19632. + }
  19633. + } else
  19634. + ret = -EINVAL;
  19635. + } break;
  19636. +
  19637. + case VCHIQ_IOC_QUEUE_MESSAGE: {
  19638. + VCHIQ_QUEUE_MESSAGE_T args;
  19639. + if (copy_from_user
  19640. + (&args, (const void __user *)arg,
  19641. + sizeof(args)) != 0) {
  19642. + ret = -EFAULT;
  19643. + break;
  19644. + }
  19645. +
  19646. + service = find_service_for_instance(instance, args.handle);
  19647. +
  19648. + if ((service != NULL) && (args.count <= MAX_ELEMENTS)) {
  19649. + /* Copy elements into kernel space */
  19650. + VCHIQ_ELEMENT_T elements[MAX_ELEMENTS];
  19651. + if (copy_from_user(elements, args.elements,
  19652. + args.count * sizeof(VCHIQ_ELEMENT_T)) == 0)
  19653. + status = vchiq_queue_message
  19654. + (args.handle,
  19655. + elements, args.count);
  19656. + else
  19657. + ret = -EFAULT;
  19658. + } else {
  19659. + ret = -EINVAL;
  19660. + }
  19661. + } break;
  19662. +
  19663. + case VCHIQ_IOC_QUEUE_BULK_TRANSMIT:
  19664. + case VCHIQ_IOC_QUEUE_BULK_RECEIVE: {
  19665. + VCHIQ_QUEUE_BULK_TRANSFER_T args;
  19666. + struct bulk_waiter_node *waiter = NULL;
  19667. + VCHIQ_BULK_DIR_T dir =
  19668. + (cmd == VCHIQ_IOC_QUEUE_BULK_TRANSMIT) ?
  19669. + VCHIQ_BULK_TRANSMIT : VCHIQ_BULK_RECEIVE;
  19670. +
  19671. + if (copy_from_user
  19672. + (&args, (const void __user *)arg,
  19673. + sizeof(args)) != 0) {
  19674. + ret = -EFAULT;
  19675. + break;
  19676. + }
  19677. +
  19678. + service = find_service_for_instance(instance, args.handle);
  19679. + if (!service) {
  19680. + ret = -EINVAL;
  19681. + break;
  19682. + }
  19683. +
  19684. + if (args.mode == VCHIQ_BULK_MODE_BLOCKING) {
  19685. + waiter = kzalloc(sizeof(struct bulk_waiter_node),
  19686. + GFP_KERNEL);
  19687. + if (!waiter) {
  19688. + ret = -ENOMEM;
  19689. + break;
  19690. + }
  19691. + args.userdata = &waiter->bulk_waiter;
  19692. + } else if (args.mode == VCHIQ_BULK_MODE_WAITING) {
  19693. + struct list_head *pos;
  19694. + mutex_lock(&instance->bulk_waiter_list_mutex);
  19695. + list_for_each(pos, &instance->bulk_waiter_list) {
  19696. + if (list_entry(pos, struct bulk_waiter_node,
  19697. + list)->pid == current->pid) {
  19698. + waiter = list_entry(pos,
  19699. + struct bulk_waiter_node,
  19700. + list);
  19701. + list_del(pos);
  19702. + break;
  19703. + }
  19704. +
  19705. + }
  19706. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  19707. + if (!waiter) {
  19708. + vchiq_log_error(vchiq_arm_log_level,
  19709. + "no bulk_waiter found for pid %d",
  19710. + current->pid);
  19711. + ret = -ESRCH;
  19712. + break;
  19713. + }
  19714. + vchiq_log_info(vchiq_arm_log_level,
  19715. + "found bulk_waiter %x for pid %d",
  19716. + (unsigned int)waiter, current->pid);
  19717. + args.userdata = &waiter->bulk_waiter;
  19718. + }
  19719. + status = vchiq_bulk_transfer
  19720. + (args.handle,
  19721. + VCHI_MEM_HANDLE_INVALID,
  19722. + args.data, args.size,
  19723. + args.userdata, args.mode,
  19724. + dir);
  19725. + if (!waiter)
  19726. + break;
  19727. + if ((status != VCHIQ_RETRY) || fatal_signal_pending(current) ||
  19728. + !waiter->bulk_waiter.bulk) {
  19729. + if (waiter->bulk_waiter.bulk) {
  19730. + /* Cancel the signal when the transfer
  19731. + ** completes. */
  19732. + spin_lock(&bulk_waiter_spinlock);
  19733. + waiter->bulk_waiter.bulk->userdata = NULL;
  19734. + spin_unlock(&bulk_waiter_spinlock);
  19735. + }
  19736. + kfree(waiter);
  19737. + } else {
  19738. + const VCHIQ_BULK_MODE_T mode_waiting =
  19739. + VCHIQ_BULK_MODE_WAITING;
  19740. + waiter->pid = current->pid;
  19741. + mutex_lock(&instance->bulk_waiter_list_mutex);
  19742. + list_add(&waiter->list, &instance->bulk_waiter_list);
  19743. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  19744. + vchiq_log_info(vchiq_arm_log_level,
  19745. + "saved bulk_waiter %x for pid %d",
  19746. + (unsigned int)waiter, current->pid);
  19747. +
  19748. + if (copy_to_user((void __user *)
  19749. + &(((VCHIQ_QUEUE_BULK_TRANSFER_T __user *)
  19750. + arg)->mode),
  19751. + (const void *)&mode_waiting,
  19752. + sizeof(mode_waiting)) != 0)
  19753. + ret = -EFAULT;
  19754. + }
  19755. + } break;
  19756. +
  19757. + case VCHIQ_IOC_AWAIT_COMPLETION: {
  19758. + VCHIQ_AWAIT_COMPLETION_T args;
  19759. +
  19760. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  19761. + if (!instance->connected) {
  19762. + ret = -ENOTCONN;
  19763. + break;
  19764. + }
  19765. +
  19766. + if (copy_from_user(&args, (const void __user *)arg,
  19767. + sizeof(args)) != 0) {
  19768. + ret = -EFAULT;
  19769. + break;
  19770. + }
  19771. +
  19772. + mutex_lock(&instance->completion_mutex);
  19773. +
  19774. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  19775. + while ((instance->completion_remove ==
  19776. + instance->completion_insert)
  19777. + && !instance->closing) {
  19778. + int rc;
  19779. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  19780. + mutex_unlock(&instance->completion_mutex);
  19781. + rc = down_interruptible(&instance->insert_event);
  19782. + mutex_lock(&instance->completion_mutex);
  19783. + if (rc != 0) {
  19784. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  19785. + vchiq_log_info(vchiq_arm_log_level,
  19786. + "AWAIT_COMPLETION interrupted");
  19787. + ret = -EINTR;
  19788. + break;
  19789. + }
  19790. + }
  19791. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  19792. +
  19793. + /* A read memory barrier is needed to stop prefetch of a stale
  19794. + ** completion record
  19795. + */
  19796. + rmb();
  19797. +
  19798. + if (ret == 0) {
  19799. + int msgbufcount = args.msgbufcount;
  19800. + for (ret = 0; ret < args.count; ret++) {
  19801. + VCHIQ_COMPLETION_DATA_T *completion;
  19802. + VCHIQ_SERVICE_T *service;
  19803. + USER_SERVICE_T *user_service;
  19804. + VCHIQ_HEADER_T *header;
  19805. + if (instance->completion_remove ==
  19806. + instance->completion_insert)
  19807. + break;
  19808. + completion = &instance->completions[
  19809. + instance->completion_remove &
  19810. + (MAX_COMPLETIONS - 1)];
  19811. +
  19812. + service = completion->service_userdata;
  19813. + user_service = service->base.userdata;
  19814. + completion->service_userdata =
  19815. + user_service->userdata;
  19816. +
  19817. + header = completion->header;
  19818. + if (header) {
  19819. + void __user *msgbuf;
  19820. + int msglen;
  19821. +
  19822. + msglen = header->size +
  19823. + sizeof(VCHIQ_HEADER_T);
  19824. + /* This must be a VCHIQ-style service */
  19825. + if (args.msgbufsize < msglen) {
  19826. + vchiq_log_error(
  19827. + vchiq_arm_log_level,
  19828. + "header %x: msgbufsize"
  19829. + " %x < msglen %x",
  19830. + (unsigned int)header,
  19831. + args.msgbufsize,
  19832. + msglen);
  19833. + WARN(1, "invalid message "
  19834. + "size\n");
  19835. + if (ret == 0)
  19836. + ret = -EMSGSIZE;
  19837. + break;
  19838. + }
  19839. + if (msgbufcount <= 0)
  19840. + /* Stall here for lack of a
  19841. + ** buffer for the message. */
  19842. + break;
  19843. + /* Get the pointer from user space */
  19844. + msgbufcount--;
  19845. + if (copy_from_user(&msgbuf,
  19846. + (const void __user *)
  19847. + &args.msgbufs[msgbufcount],
  19848. + sizeof(msgbuf)) != 0) {
  19849. + if (ret == 0)
  19850. + ret = -EFAULT;
  19851. + break;
  19852. + }
  19853. +
  19854. + /* Copy the message to user space */
  19855. + if (copy_to_user(msgbuf, header,
  19856. + msglen) != 0) {
  19857. + if (ret == 0)
  19858. + ret = -EFAULT;
  19859. + break;
  19860. + }
  19861. +
  19862. + /* Now it has been copied, the message
  19863. + ** can be released. */
  19864. + vchiq_release_message(service->handle,
  19865. + header);
  19866. +
  19867. + /* The completion must point to the
  19868. + ** msgbuf. */
  19869. + completion->header = msgbuf;
  19870. + }
  19871. +
  19872. + if (completion->reason ==
  19873. + VCHIQ_SERVICE_CLOSED)
  19874. + unlock_service(service);
  19875. +
  19876. + if (copy_to_user((void __user *)(
  19877. + (size_t)args.buf +
  19878. + ret * sizeof(VCHIQ_COMPLETION_DATA_T)),
  19879. + completion,
  19880. + sizeof(VCHIQ_COMPLETION_DATA_T)) != 0) {
  19881. + if (ret == 0)
  19882. + ret = -EFAULT;
  19883. + break;
  19884. + }
  19885. +
  19886. + instance->completion_remove++;
  19887. + }
  19888. +
  19889. + if (msgbufcount != args.msgbufcount) {
  19890. + if (copy_to_user((void __user *)
  19891. + &((VCHIQ_AWAIT_COMPLETION_T *)arg)->
  19892. + msgbufcount,
  19893. + &msgbufcount,
  19894. + sizeof(msgbufcount)) != 0) {
  19895. + ret = -EFAULT;
  19896. + }
  19897. + }
  19898. + }
  19899. +
  19900. + if (ret != 0)
  19901. + up(&instance->remove_event);
  19902. + mutex_unlock(&instance->completion_mutex);
  19903. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  19904. + } break;
  19905. +
  19906. + case VCHIQ_IOC_DEQUEUE_MESSAGE: {
  19907. + VCHIQ_DEQUEUE_MESSAGE_T args;
  19908. + USER_SERVICE_T *user_service;
  19909. + VCHIQ_HEADER_T *header;
  19910. +
  19911. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  19912. + if (copy_from_user
  19913. + (&args, (const void __user *)arg,
  19914. + sizeof(args)) != 0) {
  19915. + ret = -EFAULT;
  19916. + break;
  19917. + }
  19918. + service = find_service_for_instance(instance, args.handle);
  19919. + if (!service) {
  19920. + ret = -EINVAL;
  19921. + break;
  19922. + }
  19923. + user_service = (USER_SERVICE_T *)service->base.userdata;
  19924. + if (user_service->is_vchi == 0) {
  19925. + ret = -EINVAL;
  19926. + break;
  19927. + }
  19928. +
  19929. + spin_lock(&msg_queue_spinlock);
  19930. + if (user_service->msg_remove == user_service->msg_insert) {
  19931. + if (!args.blocking) {
  19932. + spin_unlock(&msg_queue_spinlock);
  19933. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  19934. + ret = -EWOULDBLOCK;
  19935. + break;
  19936. + }
  19937. + user_service->dequeue_pending = 1;
  19938. + do {
  19939. + spin_unlock(&msg_queue_spinlock);
  19940. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  19941. + if (down_interruptible(
  19942. + &user_service->insert_event) != 0) {
  19943. + vchiq_log_info(vchiq_arm_log_level,
  19944. + "DEQUEUE_MESSAGE interrupted");
  19945. + ret = -EINTR;
  19946. + break;
  19947. + }
  19948. + spin_lock(&msg_queue_spinlock);
  19949. + } while (user_service->msg_remove ==
  19950. + user_service->msg_insert);
  19951. +
  19952. + if (ret)
  19953. + break;
  19954. + }
  19955. +
  19956. + BUG_ON((int)(user_service->msg_insert -
  19957. + user_service->msg_remove) < 0);
  19958. +
  19959. + header = user_service->msg_queue[user_service->msg_remove &
  19960. + (MSG_QUEUE_SIZE - 1)];
  19961. + user_service->msg_remove++;
  19962. + spin_unlock(&msg_queue_spinlock);
  19963. +
  19964. + up(&user_service->remove_event);
  19965. + if (header == NULL)
  19966. + ret = -ENOTCONN;
  19967. + else if (header->size <= args.bufsize) {
  19968. + /* Copy to user space if msgbuf is not NULL */
  19969. + if ((args.buf == NULL) ||
  19970. + (copy_to_user((void __user *)args.buf,
  19971. + header->data,
  19972. + header->size) == 0)) {
  19973. + ret = header->size;
  19974. + vchiq_release_message(
  19975. + service->handle,
  19976. + header);
  19977. + } else
  19978. + ret = -EFAULT;
  19979. + } else {
  19980. + vchiq_log_error(vchiq_arm_log_level,
  19981. + "header %x: bufsize %x < size %x",
  19982. + (unsigned int)header, args.bufsize,
  19983. + header->size);
  19984. + WARN(1, "invalid size\n");
  19985. + ret = -EMSGSIZE;
  19986. + }
  19987. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  19988. + } break;
  19989. +
  19990. + case VCHIQ_IOC_GET_CLIENT_ID: {
  19991. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  19992. +
  19993. + ret = vchiq_get_client_id(handle);
  19994. + } break;
  19995. +
  19996. + case VCHIQ_IOC_GET_CONFIG: {
  19997. + VCHIQ_GET_CONFIG_T args;
  19998. + VCHIQ_CONFIG_T config;
  19999. +
  20000. + if (copy_from_user(&args, (const void __user *)arg,
  20001. + sizeof(args)) != 0) {
  20002. + ret = -EFAULT;
  20003. + break;
  20004. + }
  20005. + if (args.config_size > sizeof(config)) {
  20006. + ret = -EINVAL;
  20007. + break;
  20008. + }
  20009. + status = vchiq_get_config(instance, args.config_size, &config);
  20010. + if (status == VCHIQ_SUCCESS) {
  20011. + if (copy_to_user((void __user *)args.pconfig,
  20012. + &config, args.config_size) != 0) {
  20013. + ret = -EFAULT;
  20014. + break;
  20015. + }
  20016. + }
  20017. + } break;
  20018. +
  20019. + case VCHIQ_IOC_SET_SERVICE_OPTION: {
  20020. + VCHIQ_SET_SERVICE_OPTION_T args;
  20021. +
  20022. + if (copy_from_user(
  20023. + &args, (const void __user *)arg,
  20024. + sizeof(args)) != 0) {
  20025. + ret = -EFAULT;
  20026. + break;
  20027. + }
  20028. +
  20029. + service = find_service_for_instance(instance, args.handle);
  20030. + if (!service) {
  20031. + ret = -EINVAL;
  20032. + break;
  20033. + }
  20034. +
  20035. + status = vchiq_set_service_option(
  20036. + args.handle, args.option, args.value);
  20037. + } break;
  20038. +
  20039. + case VCHIQ_IOC_DUMP_PHYS_MEM: {
  20040. + VCHIQ_DUMP_MEM_T args;
  20041. +
  20042. + if (copy_from_user
  20043. + (&args, (const void __user *)arg,
  20044. + sizeof(args)) != 0) {
  20045. + ret = -EFAULT;
  20046. + break;
  20047. + }
  20048. + dump_phys_mem(args.virt_addr, args.num_bytes);
  20049. + } break;
  20050. +
  20051. + default:
  20052. + ret = -ENOTTY;
  20053. + break;
  20054. + }
  20055. +
  20056. + if (service)
  20057. + unlock_service(service);
  20058. +
  20059. + if (ret == 0) {
  20060. + if (status == VCHIQ_ERROR)
  20061. + ret = -EIO;
  20062. + else if (status == VCHIQ_RETRY)
  20063. + ret = -EINTR;
  20064. + }
  20065. +
  20066. + if ((status == VCHIQ_SUCCESS) && (ret < 0) && (ret != -EINTR) &&
  20067. + (ret != -EWOULDBLOCK))
  20068. + vchiq_log_info(vchiq_arm_log_level,
  20069. + " ioctl instance %lx, cmd %s -> status %d, %ld",
  20070. + (unsigned long)instance,
  20071. + (_IOC_NR(cmd) <= VCHIQ_IOC_MAX) ?
  20072. + ioctl_names[_IOC_NR(cmd)] :
  20073. + "<invalid>",
  20074. + status, ret);
  20075. + else
  20076. + vchiq_log_trace(vchiq_arm_log_level,
  20077. + " ioctl instance %lx, cmd %s -> status %d, %ld",
  20078. + (unsigned long)instance,
  20079. + (_IOC_NR(cmd) <= VCHIQ_IOC_MAX) ?
  20080. + ioctl_names[_IOC_NR(cmd)] :
  20081. + "<invalid>",
  20082. + status, ret);
  20083. +
  20084. + return ret;
  20085. +}
  20086. +
  20087. +/****************************************************************************
  20088. +*
  20089. +* vchiq_open
  20090. +*
  20091. +***************************************************************************/
  20092. +
  20093. +static int
  20094. +vchiq_open(struct inode *inode, struct file *file)
  20095. +{
  20096. + int dev = iminor(inode) & 0x0f;
  20097. + vchiq_log_info(vchiq_arm_log_level, "vchiq_open");
  20098. + switch (dev) {
  20099. + case VCHIQ_MINOR: {
  20100. + int ret;
  20101. + VCHIQ_STATE_T *state = vchiq_get_state();
  20102. + VCHIQ_INSTANCE_T instance;
  20103. +
  20104. + if (!state) {
  20105. + vchiq_log_error(vchiq_arm_log_level,
  20106. + "vchiq has no connection to VideoCore");
  20107. + return -ENOTCONN;
  20108. + }
  20109. +
  20110. + instance = kzalloc(sizeof(*instance), GFP_KERNEL);
  20111. + if (!instance)
  20112. + return -ENOMEM;
  20113. +
  20114. + instance->state = state;
  20115. + instance->pid = current->tgid;
  20116. +
  20117. + ret = vchiq_proc_add_instance(instance);
  20118. + if (ret != 0) {
  20119. + kfree(instance);
  20120. + return ret;
  20121. + }
  20122. +
  20123. + sema_init(&instance->insert_event, 0);
  20124. + sema_init(&instance->remove_event, 0);
  20125. + mutex_init(&instance->completion_mutex);
  20126. + mutex_init(&instance->bulk_waiter_list_mutex);
  20127. + INIT_LIST_HEAD(&instance->bulk_waiter_list);
  20128. +
  20129. + file->private_data = instance;
  20130. + } break;
  20131. +
  20132. + default:
  20133. + vchiq_log_error(vchiq_arm_log_level,
  20134. + "Unknown minor device: %d", dev);
  20135. + return -ENXIO;
  20136. + }
  20137. +
  20138. + return 0;
  20139. +}
  20140. +
  20141. +/****************************************************************************
  20142. +*
  20143. +* vchiq_release
  20144. +*
  20145. +***************************************************************************/
  20146. +
  20147. +static int
  20148. +vchiq_release(struct inode *inode, struct file *file)
  20149. +{
  20150. + int dev = iminor(inode) & 0x0f;
  20151. + int ret = 0;
  20152. + switch (dev) {
  20153. + case VCHIQ_MINOR: {
  20154. + VCHIQ_INSTANCE_T instance = file->private_data;
  20155. + VCHIQ_STATE_T *state = vchiq_get_state();
  20156. + VCHIQ_SERVICE_T *service;
  20157. + int i;
  20158. +
  20159. + vchiq_log_info(vchiq_arm_log_level,
  20160. + "vchiq_release: instance=%lx",
  20161. + (unsigned long)instance);
  20162. +
  20163. + if (!state) {
  20164. + ret = -EPERM;
  20165. + goto out;
  20166. + }
  20167. +
  20168. + /* Ensure videocore is awake to allow termination. */
  20169. + vchiq_use_internal(instance->state, NULL,
  20170. + USE_TYPE_VCHIQ);
  20171. +
  20172. + mutex_lock(&instance->completion_mutex);
  20173. +
  20174. + /* Wake the completion thread and ask it to exit */
  20175. + instance->closing = 1;
  20176. + up(&instance->insert_event);
  20177. +
  20178. + mutex_unlock(&instance->completion_mutex);
  20179. +
  20180. + /* Wake the slot handler if the completion queue is full. */
  20181. + up(&instance->remove_event);
  20182. +
  20183. + /* Mark all services for termination... */
  20184. + i = 0;
  20185. + while ((service = next_service_by_instance(state, instance,
  20186. + &i)) != NULL) {
  20187. + USER_SERVICE_T *user_service = service->base.userdata;
  20188. +
  20189. + /* Wake the slot handler if the msg queue is full. */
  20190. + up(&user_service->remove_event);
  20191. +
  20192. + vchiq_terminate_service_internal(service);
  20193. + unlock_service(service);
  20194. + }
  20195. +
  20196. + /* ...and wait for them to die */
  20197. + i = 0;
  20198. + while ((service = next_service_by_instance(state, instance, &i))
  20199. + != NULL) {
  20200. + USER_SERVICE_T *user_service = service->base.userdata;
  20201. +
  20202. + down(&service->remove_event);
  20203. +
  20204. + BUG_ON(service->srvstate != VCHIQ_SRVSTATE_FREE);
  20205. +
  20206. + spin_lock(&msg_queue_spinlock);
  20207. +
  20208. + while (user_service->msg_remove !=
  20209. + user_service->msg_insert) {
  20210. + VCHIQ_HEADER_T *header = user_service->
  20211. + msg_queue[user_service->msg_remove &
  20212. + (MSG_QUEUE_SIZE - 1)];
  20213. + user_service->msg_remove++;
  20214. + spin_unlock(&msg_queue_spinlock);
  20215. +
  20216. + if (header)
  20217. + vchiq_release_message(
  20218. + service->handle,
  20219. + header);
  20220. + spin_lock(&msg_queue_spinlock);
  20221. + }
  20222. +
  20223. + spin_unlock(&msg_queue_spinlock);
  20224. +
  20225. + unlock_service(service);
  20226. + }
  20227. +
  20228. + /* Release any closed services */
  20229. + while (instance->completion_remove !=
  20230. + instance->completion_insert) {
  20231. + VCHIQ_COMPLETION_DATA_T *completion;
  20232. + VCHIQ_SERVICE_T *service;
  20233. + completion = &instance->completions[
  20234. + instance->completion_remove &
  20235. + (MAX_COMPLETIONS - 1)];
  20236. + service = completion->service_userdata;
  20237. + if (completion->reason == VCHIQ_SERVICE_CLOSED)
  20238. + unlock_service(service);
  20239. + instance->completion_remove++;
  20240. + }
  20241. +
  20242. + /* Release the PEER service count. */
  20243. + vchiq_release_internal(instance->state, NULL);
  20244. +
  20245. + {
  20246. + struct list_head *pos, *next;
  20247. + list_for_each_safe(pos, next,
  20248. + &instance->bulk_waiter_list) {
  20249. + struct bulk_waiter_node *waiter;
  20250. + waiter = list_entry(pos,
  20251. + struct bulk_waiter_node,
  20252. + list);
  20253. + list_del(pos);
  20254. + vchiq_log_info(vchiq_arm_log_level,
  20255. + "bulk_waiter - cleaned up %x "
  20256. + "for pid %d",
  20257. + (unsigned int)waiter, waiter->pid);
  20258. + kfree(waiter);
  20259. + }
  20260. + }
  20261. +
  20262. + vchiq_proc_remove_instance(instance);
  20263. +
  20264. + kfree(instance);
  20265. + file->private_data = NULL;
  20266. + } break;
  20267. +
  20268. + default:
  20269. + vchiq_log_error(vchiq_arm_log_level,
  20270. + "Unknown minor device: %d", dev);
  20271. + ret = -ENXIO;
  20272. + }
  20273. +
  20274. +out:
  20275. + return ret;
  20276. +}
  20277. +
  20278. +/****************************************************************************
  20279. +*
  20280. +* vchiq_dump
  20281. +*
  20282. +***************************************************************************/
  20283. +
  20284. +void
  20285. +vchiq_dump(void *dump_context, const char *str, int len)
  20286. +{
  20287. + DUMP_CONTEXT_T *context = (DUMP_CONTEXT_T *)dump_context;
  20288. +
  20289. + if (context->actual < context->space) {
  20290. + int copy_bytes;
  20291. + if (context->offset > 0) {
  20292. + int skip_bytes = min(len, (int)context->offset);
  20293. + str += skip_bytes;
  20294. + len -= skip_bytes;
  20295. + context->offset -= skip_bytes;
  20296. + if (context->offset > 0)
  20297. + return;
  20298. + }
  20299. + copy_bytes = min(len, (int)(context->space - context->actual));
  20300. + if (copy_bytes == 0)
  20301. + return;
  20302. + if (copy_to_user(context->buf + context->actual, str,
  20303. + copy_bytes))
  20304. + context->actual = -EFAULT;
  20305. + context->actual += copy_bytes;
  20306. + len -= copy_bytes;
  20307. +
  20308. + /* If tne terminating NUL is included in the length, then it
  20309. + ** marks the end of a line and should be replaced with a
  20310. + ** carriage return. */
  20311. + if ((len == 0) && (str[copy_bytes - 1] == '\0')) {
  20312. + char cr = '\n';
  20313. + if (copy_to_user(context->buf + context->actual - 1,
  20314. + &cr, 1))
  20315. + context->actual = -EFAULT;
  20316. + }
  20317. + }
  20318. +}
  20319. +
  20320. +/****************************************************************************
  20321. +*
  20322. +* vchiq_dump_platform_instance_state
  20323. +*
  20324. +***************************************************************************/
  20325. +
  20326. +void
  20327. +vchiq_dump_platform_instances(void *dump_context)
  20328. +{
  20329. + VCHIQ_STATE_T *state = vchiq_get_state();
  20330. + char buf[80];
  20331. + int len;
  20332. + int i;
  20333. +
  20334. + /* There is no list of instances, so instead scan all services,
  20335. + marking those that have been dumped. */
  20336. +
  20337. + for (i = 0; i < state->unused_service; i++) {
  20338. + VCHIQ_SERVICE_T *service = state->services[i];
  20339. + VCHIQ_INSTANCE_T instance;
  20340. +
  20341. + if (service && (service->base.callback == service_callback)) {
  20342. + instance = service->instance;
  20343. + if (instance)
  20344. + instance->mark = 0;
  20345. + }
  20346. + }
  20347. +
  20348. + for (i = 0; i < state->unused_service; i++) {
  20349. + VCHIQ_SERVICE_T *service = state->services[i];
  20350. + VCHIQ_INSTANCE_T instance;
  20351. +
  20352. + if (service && (service->base.callback == service_callback)) {
  20353. + instance = service->instance;
  20354. + if (instance && !instance->mark) {
  20355. + len = snprintf(buf, sizeof(buf),
  20356. + "Instance %x: pid %d,%s completions "
  20357. + "%d/%d",
  20358. + (unsigned int)instance, instance->pid,
  20359. + instance->connected ? " connected, " :
  20360. + "",
  20361. + instance->completion_insert -
  20362. + instance->completion_remove,
  20363. + MAX_COMPLETIONS);
  20364. +
  20365. + vchiq_dump(dump_context, buf, len + 1);
  20366. +
  20367. + instance->mark = 1;
  20368. + }
  20369. + }
  20370. + }
  20371. +}
  20372. +
  20373. +/****************************************************************************
  20374. +*
  20375. +* vchiq_dump_platform_service_state
  20376. +*
  20377. +***************************************************************************/
  20378. +
  20379. +void
  20380. +vchiq_dump_platform_service_state(void *dump_context, VCHIQ_SERVICE_T *service)
  20381. +{
  20382. + USER_SERVICE_T *user_service = (USER_SERVICE_T *)service->base.userdata;
  20383. + char buf[80];
  20384. + int len;
  20385. +
  20386. + len = snprintf(buf, sizeof(buf), " instance %x",
  20387. + (unsigned int)service->instance);
  20388. +
  20389. + if ((service->base.callback == service_callback) &&
  20390. + user_service->is_vchi) {
  20391. + len += snprintf(buf + len, sizeof(buf) - len,
  20392. + ", %d/%d messages",
  20393. + user_service->msg_insert - user_service->msg_remove,
  20394. + MSG_QUEUE_SIZE);
  20395. +
  20396. + if (user_service->dequeue_pending)
  20397. + len += snprintf(buf + len, sizeof(buf) - len,
  20398. + " (dequeue pending)");
  20399. + }
  20400. +
  20401. + vchiq_dump(dump_context, buf, len + 1);
  20402. +}
  20403. +
  20404. +/****************************************************************************
  20405. +*
  20406. +* dump_user_mem
  20407. +*
  20408. +***************************************************************************/
  20409. +
  20410. +static void
  20411. +dump_phys_mem(void *virt_addr, uint32_t num_bytes)
  20412. +{
  20413. + int rc;
  20414. + uint8_t *end_virt_addr = virt_addr + num_bytes;
  20415. + int num_pages;
  20416. + int offset;
  20417. + int end_offset;
  20418. + int page_idx;
  20419. + int prev_idx;
  20420. + struct page *page;
  20421. + struct page **pages;
  20422. + uint8_t *kmapped_virt_ptr;
  20423. +
  20424. + /* Align virtAddr and endVirtAddr to 16 byte boundaries. */
  20425. +
  20426. + virt_addr = (void *)((unsigned long)virt_addr & ~0x0fuL);
  20427. + end_virt_addr = (void *)(((unsigned long)end_virt_addr + 15uL) &
  20428. + ~0x0fuL);
  20429. +
  20430. + offset = (int)(long)virt_addr & (PAGE_SIZE - 1);
  20431. + end_offset = (int)(long)end_virt_addr & (PAGE_SIZE - 1);
  20432. +
  20433. + num_pages = (offset + num_bytes + PAGE_SIZE - 1) / PAGE_SIZE;
  20434. +
  20435. + pages = kmalloc(sizeof(struct page *) * num_pages, GFP_KERNEL);
  20436. + if (pages == NULL) {
  20437. + vchiq_log_error(vchiq_arm_log_level,
  20438. + "Unable to allocation memory for %d pages\n",
  20439. + num_pages);
  20440. + return;
  20441. + }
  20442. +
  20443. + down_read(&current->mm->mmap_sem);
  20444. + rc = get_user_pages(current, /* task */
  20445. + current->mm, /* mm */
  20446. + (unsigned long)virt_addr, /* start */
  20447. + num_pages, /* len */
  20448. + 0, /* write */
  20449. + 0, /* force */
  20450. + pages, /* pages (array of page pointers) */
  20451. + NULL); /* vmas */
  20452. + up_read(&current->mm->mmap_sem);
  20453. +
  20454. + prev_idx = -1;
  20455. + page = NULL;
  20456. +
  20457. + while (offset < end_offset) {
  20458. +
  20459. + int page_offset = offset % PAGE_SIZE;
  20460. + page_idx = offset / PAGE_SIZE;
  20461. +
  20462. + if (page_idx != prev_idx) {
  20463. +
  20464. + if (page != NULL)
  20465. + kunmap(page);
  20466. + page = pages[page_idx];
  20467. + kmapped_virt_ptr = kmap(page);
  20468. +
  20469. + prev_idx = page_idx;
  20470. + }
  20471. +
  20472. + if (vchiq_arm_log_level >= VCHIQ_LOG_TRACE)
  20473. + vchiq_log_dump_mem("ph",
  20474. + (uint32_t)(unsigned long)&kmapped_virt_ptr[
  20475. + page_offset],
  20476. + &kmapped_virt_ptr[page_offset], 16);
  20477. +
  20478. + offset += 16;
  20479. + }
  20480. + if (page != NULL)
  20481. + kunmap(page);
  20482. +
  20483. + for (page_idx = 0; page_idx < num_pages; page_idx++)
  20484. + page_cache_release(pages[page_idx]);
  20485. +
  20486. + kfree(pages);
  20487. +}
  20488. +
  20489. +/****************************************************************************
  20490. +*
  20491. +* vchiq_read
  20492. +*
  20493. +***************************************************************************/
  20494. +
  20495. +static ssize_t
  20496. +vchiq_read(struct file *file, char __user *buf,
  20497. + size_t count, loff_t *ppos)
  20498. +{
  20499. + DUMP_CONTEXT_T context;
  20500. + context.buf = buf;
  20501. + context.actual = 0;
  20502. + context.space = count;
  20503. + context.offset = *ppos;
  20504. +
  20505. + vchiq_dump_state(&context, &g_state);
  20506. +
  20507. + *ppos += context.actual;
  20508. +
  20509. + return context.actual;
  20510. +}
  20511. +
  20512. +VCHIQ_STATE_T *
  20513. +vchiq_get_state(void)
  20514. +{
  20515. +
  20516. + if (g_state.remote == NULL)
  20517. + printk(KERN_ERR "%s: g_state.remote == NULL\n", __func__);
  20518. + else if (g_state.remote->initialised != 1)
  20519. + printk(KERN_NOTICE "%s: g_state.remote->initialised != 1 (%d)\n",
  20520. + __func__, g_state.remote->initialised);
  20521. +
  20522. + return ((g_state.remote != NULL) &&
  20523. + (g_state.remote->initialised == 1)) ? &g_state : NULL;
  20524. +}
  20525. +
  20526. +static const struct file_operations
  20527. +vchiq_fops = {
  20528. + .owner = THIS_MODULE,
  20529. + .unlocked_ioctl = vchiq_ioctl,
  20530. + .open = vchiq_open,
  20531. + .release = vchiq_release,
  20532. + .read = vchiq_read
  20533. +};
  20534. +
  20535. +/*
  20536. + * Autosuspend related functionality
  20537. + */
  20538. +
  20539. +int
  20540. +vchiq_videocore_wanted(VCHIQ_STATE_T *state)
  20541. +{
  20542. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  20543. + if (!arm_state)
  20544. + /* autosuspend not supported - always return wanted */
  20545. + return 1;
  20546. + else if (arm_state->blocked_count)
  20547. + return 1;
  20548. + else if (!arm_state->videocore_use_count)
  20549. + /* usage count zero - check for override unless we're forcing */
  20550. + if (arm_state->resume_blocked)
  20551. + return 0;
  20552. + else
  20553. + return vchiq_platform_videocore_wanted(state);
  20554. + else
  20555. + /* non-zero usage count - videocore still required */
  20556. + return 1;
  20557. +}
  20558. +
  20559. +static VCHIQ_STATUS_T
  20560. +vchiq_keepalive_vchiq_callback(VCHIQ_REASON_T reason,
  20561. + VCHIQ_HEADER_T *header,
  20562. + VCHIQ_SERVICE_HANDLE_T service_user,
  20563. + void *bulk_user)
  20564. +{
  20565. + vchiq_log_error(vchiq_susp_log_level,
  20566. + "%s callback reason %d", __func__, reason);
  20567. + return 0;
  20568. +}
  20569. +
  20570. +static int
  20571. +vchiq_keepalive_thread_func(void *v)
  20572. +{
  20573. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  20574. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  20575. +
  20576. + VCHIQ_STATUS_T status;
  20577. + VCHIQ_INSTANCE_T instance;
  20578. + VCHIQ_SERVICE_HANDLE_T ka_handle;
  20579. +
  20580. + VCHIQ_SERVICE_PARAMS_T params = {
  20581. + .fourcc = VCHIQ_MAKE_FOURCC('K', 'E', 'E', 'P'),
  20582. + .callback = vchiq_keepalive_vchiq_callback,
  20583. + .version = KEEPALIVE_VER,
  20584. + .version_min = KEEPALIVE_VER_MIN
  20585. + };
  20586. +
  20587. + status = vchiq_initialise(&instance);
  20588. + if (status != VCHIQ_SUCCESS) {
  20589. + vchiq_log_error(vchiq_susp_log_level,
  20590. + "%s vchiq_initialise failed %d", __func__, status);
  20591. + goto exit;
  20592. + }
  20593. +
  20594. + status = vchiq_connect(instance);
  20595. + if (status != VCHIQ_SUCCESS) {
  20596. + vchiq_log_error(vchiq_susp_log_level,
  20597. + "%s vchiq_connect failed %d", __func__, status);
  20598. + goto shutdown;
  20599. + }
  20600. +
  20601. + status = vchiq_add_service(instance, &params, &ka_handle);
  20602. + if (status != VCHIQ_SUCCESS) {
  20603. + vchiq_log_error(vchiq_susp_log_level,
  20604. + "%s vchiq_open_service failed %d", __func__, status);
  20605. + goto shutdown;
  20606. + }
  20607. +
  20608. + while (1) {
  20609. + long rc = 0, uc = 0;
  20610. + if (wait_for_completion_interruptible(&arm_state->ka_evt)
  20611. + != 0) {
  20612. + vchiq_log_error(vchiq_susp_log_level,
  20613. + "%s interrupted", __func__);
  20614. + flush_signals(current);
  20615. + continue;
  20616. + }
  20617. +
  20618. + /* read and clear counters. Do release_count then use_count to
  20619. + * prevent getting more releases than uses */
  20620. + rc = atomic_xchg(&arm_state->ka_release_count, 0);
  20621. + uc = atomic_xchg(&arm_state->ka_use_count, 0);
  20622. +
  20623. + /* Call use/release service the requisite number of times.
  20624. + * Process use before release so use counts don't go negative */
  20625. + while (uc--) {
  20626. + atomic_inc(&arm_state->ka_use_ack_count);
  20627. + status = vchiq_use_service(ka_handle);
  20628. + if (status != VCHIQ_SUCCESS) {
  20629. + vchiq_log_error(vchiq_susp_log_level,
  20630. + "%s vchiq_use_service error %d",
  20631. + __func__, status);
  20632. + }
  20633. + }
  20634. + while (rc--) {
  20635. + status = vchiq_release_service(ka_handle);
  20636. + if (status != VCHIQ_SUCCESS) {
  20637. + vchiq_log_error(vchiq_susp_log_level,
  20638. + "%s vchiq_release_service error %d",
  20639. + __func__, status);
  20640. + }
  20641. + }
  20642. + }
  20643. +
  20644. +shutdown:
  20645. + vchiq_shutdown(instance);
  20646. +exit:
  20647. + return 0;
  20648. +}
  20649. +
  20650. +
  20651. +
  20652. +VCHIQ_STATUS_T
  20653. +vchiq_arm_init_state(VCHIQ_STATE_T *state, VCHIQ_ARM_STATE_T *arm_state)
  20654. +{
  20655. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  20656. +
  20657. + if (arm_state) {
  20658. + rwlock_init(&arm_state->susp_res_lock);
  20659. +
  20660. + init_completion(&arm_state->ka_evt);
  20661. + atomic_set(&arm_state->ka_use_count, 0);
  20662. + atomic_set(&arm_state->ka_use_ack_count, 0);
  20663. + atomic_set(&arm_state->ka_release_count, 0);
  20664. +
  20665. + init_completion(&arm_state->vc_suspend_complete);
  20666. +
  20667. + init_completion(&arm_state->vc_resume_complete);
  20668. + /* Initialise to 'done' state. We only want to block on resume
  20669. + * completion while videocore is suspended. */
  20670. + set_resume_state(arm_state, VC_RESUME_RESUMED);
  20671. +
  20672. + init_completion(&arm_state->resume_blocker);
  20673. + /* Initialise to 'done' state. We only want to block on this
  20674. + * completion while resume is blocked */
  20675. + complete_all(&arm_state->resume_blocker);
  20676. +
  20677. + init_completion(&arm_state->blocked_blocker);
  20678. + /* Initialise to 'done' state. We only want to block on this
  20679. + * completion while things are waiting on the resume blocker */
  20680. + complete_all(&arm_state->blocked_blocker);
  20681. +
  20682. + arm_state->suspend_timer_timeout = SUSPEND_TIMER_TIMEOUT_MS;
  20683. + arm_state->suspend_timer_running = 0;
  20684. + init_timer(&arm_state->suspend_timer);
  20685. + arm_state->suspend_timer.data = (unsigned long)(state);
  20686. + arm_state->suspend_timer.function = suspend_timer_callback;
  20687. +
  20688. + arm_state->first_connect = 0;
  20689. +
  20690. + }
  20691. + return status;
  20692. +}
  20693. +
  20694. +/*
  20695. +** Functions to modify the state variables;
  20696. +** set_suspend_state
  20697. +** set_resume_state
  20698. +**
  20699. +** There are more state variables than we might like, so ensure they remain in
  20700. +** step. Suspend and resume state are maintained separately, since most of
  20701. +** these state machines can operate independently. However, there are a few
  20702. +** states where state transitions in one state machine cause a reset to the
  20703. +** other state machine. In addition, there are some completion events which
  20704. +** need to occur on state machine reset and end-state(s), so these are also
  20705. +** dealt with in these functions.
  20706. +**
  20707. +** In all states we set the state variable according to the input, but in some
  20708. +** cases we perform additional steps outlined below;
  20709. +**
  20710. +** VC_SUSPEND_IDLE - Initialise the suspend completion at the same time.
  20711. +** The suspend completion is completed after any suspend
  20712. +** attempt. When we reset the state machine we also reset
  20713. +** the completion. This reset occurs when videocore is
  20714. +** resumed, and also if we initiate suspend after a suspend
  20715. +** failure.
  20716. +**
  20717. +** VC_SUSPEND_IN_PROGRESS - This state is considered the point of no return for
  20718. +** suspend - ie from this point on we must try to suspend
  20719. +** before resuming can occur. We therefore also reset the
  20720. +** resume state machine to VC_RESUME_IDLE in this state.
  20721. +**
  20722. +** VC_SUSPEND_SUSPENDED - Suspend has completed successfully. Also call
  20723. +** complete_all on the suspend completion to notify
  20724. +** anything waiting for suspend to happen.
  20725. +**
  20726. +** VC_SUSPEND_REJECTED - Videocore rejected suspend. Videocore will also
  20727. +** initiate resume, so no need to alter resume state.
  20728. +** We call complete_all on the suspend completion to notify
  20729. +** of suspend rejection.
  20730. +**
  20731. +** VC_SUSPEND_FAILED - We failed to initiate videocore suspend. We notify the
  20732. +** suspend completion and reset the resume state machine.
  20733. +**
  20734. +** VC_RESUME_IDLE - Initialise the resume completion at the same time. The
  20735. +** resume completion is in it's 'done' state whenever
  20736. +** videcore is running. Therfore, the VC_RESUME_IDLE state
  20737. +** implies that videocore is suspended.
  20738. +** Hence, any thread which needs to wait until videocore is
  20739. +** running can wait on this completion - it will only block
  20740. +** if videocore is suspended.
  20741. +**
  20742. +** VC_RESUME_RESUMED - Resume has completed successfully. Videocore is running.
  20743. +** Call complete_all on the resume completion to unblock
  20744. +** any threads waiting for resume. Also reset the suspend
  20745. +** state machine to it's idle state.
  20746. +**
  20747. +** VC_RESUME_FAILED - Currently unused - no mechanism to fail resume exists.
  20748. +*/
  20749. +
  20750. +inline void
  20751. +set_suspend_state(VCHIQ_ARM_STATE_T *arm_state,
  20752. + enum vc_suspend_status new_state)
  20753. +{
  20754. + /* set the state in all cases */
  20755. + arm_state->vc_suspend_state = new_state;
  20756. +
  20757. + /* state specific additional actions */
  20758. + switch (new_state) {
  20759. + case VC_SUSPEND_FORCE_CANCELED:
  20760. + complete_all(&arm_state->vc_suspend_complete);
  20761. + break;
  20762. + case VC_SUSPEND_REJECTED:
  20763. + complete_all(&arm_state->vc_suspend_complete);
  20764. + break;
  20765. + case VC_SUSPEND_FAILED:
  20766. + complete_all(&arm_state->vc_suspend_complete);
  20767. + arm_state->vc_resume_state = VC_RESUME_RESUMED;
  20768. + complete_all(&arm_state->vc_resume_complete);
  20769. + break;
  20770. + case VC_SUSPEND_IDLE:
  20771. + reinit_completion(&arm_state->vc_suspend_complete);
  20772. + break;
  20773. + case VC_SUSPEND_REQUESTED:
  20774. + break;
  20775. + case VC_SUSPEND_IN_PROGRESS:
  20776. + set_resume_state(arm_state, VC_RESUME_IDLE);
  20777. + break;
  20778. + case VC_SUSPEND_SUSPENDED:
  20779. + complete_all(&arm_state->vc_suspend_complete);
  20780. + break;
  20781. + default:
  20782. + BUG();
  20783. + break;
  20784. + }
  20785. +}
  20786. +
  20787. +inline void
  20788. +set_resume_state(VCHIQ_ARM_STATE_T *arm_state,
  20789. + enum vc_resume_status new_state)
  20790. +{
  20791. + /* set the state in all cases */
  20792. + arm_state->vc_resume_state = new_state;
  20793. +
  20794. + /* state specific additional actions */
  20795. + switch (new_state) {
  20796. + case VC_RESUME_FAILED:
  20797. + break;
  20798. + case VC_RESUME_IDLE:
  20799. + reinit_completion(&arm_state->vc_resume_complete);
  20800. + break;
  20801. + case VC_RESUME_REQUESTED:
  20802. + break;
  20803. + case VC_RESUME_IN_PROGRESS:
  20804. + break;
  20805. + case VC_RESUME_RESUMED:
  20806. + complete_all(&arm_state->vc_resume_complete);
  20807. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  20808. + break;
  20809. + default:
  20810. + BUG();
  20811. + break;
  20812. + }
  20813. +}
  20814. +
  20815. +
  20816. +/* should be called with the write lock held */
  20817. +inline void
  20818. +start_suspend_timer(VCHIQ_ARM_STATE_T *arm_state)
  20819. +{
  20820. + del_timer(&arm_state->suspend_timer);
  20821. + arm_state->suspend_timer.expires = jiffies +
  20822. + msecs_to_jiffies(arm_state->
  20823. + suspend_timer_timeout);
  20824. + add_timer(&arm_state->suspend_timer);
  20825. + arm_state->suspend_timer_running = 1;
  20826. +}
  20827. +
  20828. +/* should be called with the write lock held */
  20829. +static inline void
  20830. +stop_suspend_timer(VCHIQ_ARM_STATE_T *arm_state)
  20831. +{
  20832. + if (arm_state->suspend_timer_running) {
  20833. + del_timer(&arm_state->suspend_timer);
  20834. + arm_state->suspend_timer_running = 0;
  20835. + }
  20836. +}
  20837. +
  20838. +static inline int
  20839. +need_resume(VCHIQ_STATE_T *state)
  20840. +{
  20841. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  20842. + return (arm_state->vc_suspend_state > VC_SUSPEND_IDLE) &&
  20843. + (arm_state->vc_resume_state < VC_RESUME_REQUESTED) &&
  20844. + vchiq_videocore_wanted(state);
  20845. +}
  20846. +
  20847. +static int
  20848. +block_resume(VCHIQ_ARM_STATE_T *arm_state)
  20849. +{
  20850. + int status = VCHIQ_SUCCESS;
  20851. + const unsigned long timeout_val =
  20852. + msecs_to_jiffies(FORCE_SUSPEND_TIMEOUT_MS);
  20853. + int resume_count = 0;
  20854. +
  20855. + /* Allow any threads which were blocked by the last force suspend to
  20856. + * complete if they haven't already. Only give this one shot; if
  20857. + * blocked_count is incremented after blocked_blocker is completed
  20858. + * (which only happens when blocked_count hits 0) then those threads
  20859. + * will have to wait until next time around */
  20860. + if (arm_state->blocked_count) {
  20861. + reinit_completion(&arm_state->blocked_blocker);
  20862. + write_unlock_bh(&arm_state->susp_res_lock);
  20863. + vchiq_log_info(vchiq_susp_log_level, "%s wait for previously "
  20864. + "blocked clients", __func__);
  20865. + if (wait_for_completion_interruptible_timeout(
  20866. + &arm_state->blocked_blocker, timeout_val)
  20867. + <= 0) {
  20868. + vchiq_log_error(vchiq_susp_log_level, "%s wait for "
  20869. + "previously blocked clients failed" , __func__);
  20870. + status = VCHIQ_ERROR;
  20871. + write_lock_bh(&arm_state->susp_res_lock);
  20872. + goto out;
  20873. + }
  20874. + vchiq_log_info(vchiq_susp_log_level, "%s previously blocked "
  20875. + "clients resumed", __func__);
  20876. + write_lock_bh(&arm_state->susp_res_lock);
  20877. + }
  20878. +
  20879. + /* We need to wait for resume to complete if it's in process */
  20880. + while (arm_state->vc_resume_state != VC_RESUME_RESUMED &&
  20881. + arm_state->vc_resume_state > VC_RESUME_IDLE) {
  20882. + if (resume_count > 1) {
  20883. + status = VCHIQ_ERROR;
  20884. + vchiq_log_error(vchiq_susp_log_level, "%s waited too "
  20885. + "many times for resume" , __func__);
  20886. + goto out;
  20887. + }
  20888. + write_unlock_bh(&arm_state->susp_res_lock);
  20889. + vchiq_log_info(vchiq_susp_log_level, "%s wait for resume",
  20890. + __func__);
  20891. + if (wait_for_completion_interruptible_timeout(
  20892. + &arm_state->vc_resume_complete, timeout_val)
  20893. + <= 0) {
  20894. + vchiq_log_error(vchiq_susp_log_level, "%s wait for "
  20895. + "resume failed (%s)", __func__,
  20896. + resume_state_names[arm_state->vc_resume_state +
  20897. + VC_RESUME_NUM_OFFSET]);
  20898. + status = VCHIQ_ERROR;
  20899. + write_lock_bh(&arm_state->susp_res_lock);
  20900. + goto out;
  20901. + }
  20902. + vchiq_log_info(vchiq_susp_log_level, "%s resumed", __func__);
  20903. + write_lock_bh(&arm_state->susp_res_lock);
  20904. + resume_count++;
  20905. + }
  20906. + reinit_completion(&arm_state->resume_blocker);
  20907. + arm_state->resume_blocked = 1;
  20908. +
  20909. +out:
  20910. + return status;
  20911. +}
  20912. +
  20913. +static inline void
  20914. +unblock_resume(VCHIQ_ARM_STATE_T *arm_state)
  20915. +{
  20916. + complete_all(&arm_state->resume_blocker);
  20917. + arm_state->resume_blocked = 0;
  20918. +}
  20919. +
  20920. +/* Initiate suspend via slot handler. Should be called with the write lock
  20921. + * held */
  20922. +VCHIQ_STATUS_T
  20923. +vchiq_arm_vcsuspend(VCHIQ_STATE_T *state)
  20924. +{
  20925. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  20926. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  20927. +
  20928. + if (!arm_state)
  20929. + goto out;
  20930. +
  20931. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  20932. + status = VCHIQ_SUCCESS;
  20933. +
  20934. +
  20935. + switch (arm_state->vc_suspend_state) {
  20936. + case VC_SUSPEND_REQUESTED:
  20937. + vchiq_log_info(vchiq_susp_log_level, "%s: suspend already "
  20938. + "requested", __func__);
  20939. + break;
  20940. + case VC_SUSPEND_IN_PROGRESS:
  20941. + vchiq_log_info(vchiq_susp_log_level, "%s: suspend already in "
  20942. + "progress", __func__);
  20943. + break;
  20944. +
  20945. + default:
  20946. + /* We don't expect to be in other states, so log but continue
  20947. + * anyway */
  20948. + vchiq_log_error(vchiq_susp_log_level,
  20949. + "%s unexpected suspend state %s", __func__,
  20950. + suspend_state_names[arm_state->vc_suspend_state +
  20951. + VC_SUSPEND_NUM_OFFSET]);
  20952. + /* fall through */
  20953. + case VC_SUSPEND_REJECTED:
  20954. + case VC_SUSPEND_FAILED:
  20955. + /* Ensure any idle state actions have been run */
  20956. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  20957. + /* fall through */
  20958. + case VC_SUSPEND_IDLE:
  20959. + vchiq_log_info(vchiq_susp_log_level,
  20960. + "%s: suspending", __func__);
  20961. + set_suspend_state(arm_state, VC_SUSPEND_REQUESTED);
  20962. + /* kick the slot handler thread to initiate suspend */
  20963. + request_poll(state, NULL, 0);
  20964. + break;
  20965. + }
  20966. +
  20967. +out:
  20968. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, status);
  20969. + return status;
  20970. +}
  20971. +
  20972. +void
  20973. +vchiq_platform_check_suspend(VCHIQ_STATE_T *state)
  20974. +{
  20975. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  20976. + int susp = 0;
  20977. +
  20978. + if (!arm_state)
  20979. + goto out;
  20980. +
  20981. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  20982. +
  20983. + write_lock_bh(&arm_state->susp_res_lock);
  20984. + if (arm_state->vc_suspend_state == VC_SUSPEND_REQUESTED &&
  20985. + arm_state->vc_resume_state == VC_RESUME_RESUMED) {
  20986. + set_suspend_state(arm_state, VC_SUSPEND_IN_PROGRESS);
  20987. + susp = 1;
  20988. + }
  20989. + write_unlock_bh(&arm_state->susp_res_lock);
  20990. +
  20991. + if (susp)
  20992. + vchiq_platform_suspend(state);
  20993. +
  20994. +out:
  20995. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  20996. + return;
  20997. +}
  20998. +
  20999. +
  21000. +static void
  21001. +output_timeout_error(VCHIQ_STATE_T *state)
  21002. +{
  21003. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21004. + char service_err[50] = "";
  21005. + int vc_use_count = arm_state->videocore_use_count;
  21006. + int active_services = state->unused_service;
  21007. + int i;
  21008. +
  21009. + if (!arm_state->videocore_use_count) {
  21010. + snprintf(service_err, 50, " Videocore usecount is 0");
  21011. + goto output_msg;
  21012. + }
  21013. + for (i = 0; i < active_services; i++) {
  21014. + VCHIQ_SERVICE_T *service_ptr = state->services[i];
  21015. + if (service_ptr && service_ptr->service_use_count &&
  21016. + (service_ptr->srvstate != VCHIQ_SRVSTATE_FREE)) {
  21017. + snprintf(service_err, 50, " %c%c%c%c(%d) service has "
  21018. + "use count %d%s", VCHIQ_FOURCC_AS_4CHARS(
  21019. + service_ptr->base.fourcc),
  21020. + service_ptr->client_id,
  21021. + service_ptr->service_use_count,
  21022. + service_ptr->service_use_count ==
  21023. + vc_use_count ? "" : " (+ more)");
  21024. + break;
  21025. + }
  21026. + }
  21027. +
  21028. +output_msg:
  21029. + vchiq_log_error(vchiq_susp_log_level,
  21030. + "timed out waiting for vc suspend (%d).%s",
  21031. + arm_state->autosuspend_override, service_err);
  21032. +
  21033. +}
  21034. +
  21035. +/* Try to get videocore into suspended state, regardless of autosuspend state.
  21036. +** We don't actually force suspend, since videocore may get into a bad state
  21037. +** if we force suspend at a bad time. Instead, we wait for autosuspend to
  21038. +** determine a good point to suspend. If this doesn't happen within 100ms we
  21039. +** report failure.
  21040. +**
  21041. +** Returns VCHIQ_SUCCESS if videocore suspended successfully, VCHIQ_RETRY if
  21042. +** videocore failed to suspend in time or VCHIQ_ERROR if interrupted.
  21043. +*/
  21044. +VCHIQ_STATUS_T
  21045. +vchiq_arm_force_suspend(VCHIQ_STATE_T *state)
  21046. +{
  21047. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21048. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  21049. + long rc = 0;
  21050. + int repeat = -1;
  21051. +
  21052. + if (!arm_state)
  21053. + goto out;
  21054. +
  21055. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  21056. +
  21057. + write_lock_bh(&arm_state->susp_res_lock);
  21058. +
  21059. + status = block_resume(arm_state);
  21060. + if (status != VCHIQ_SUCCESS)
  21061. + goto unlock;
  21062. + if (arm_state->vc_suspend_state == VC_SUSPEND_SUSPENDED) {
  21063. + /* Already suspended - just block resume and exit */
  21064. + vchiq_log_info(vchiq_susp_log_level, "%s already suspended",
  21065. + __func__);
  21066. + status = VCHIQ_SUCCESS;
  21067. + goto unlock;
  21068. + } else if (arm_state->vc_suspend_state <= VC_SUSPEND_IDLE) {
  21069. + /* initiate suspend immediately in the case that we're waiting
  21070. + * for the timeout */
  21071. + stop_suspend_timer(arm_state);
  21072. + if (!vchiq_videocore_wanted(state)) {
  21073. + vchiq_log_info(vchiq_susp_log_level, "%s videocore "
  21074. + "idle, initiating suspend", __func__);
  21075. + status = vchiq_arm_vcsuspend(state);
  21076. + } else if (arm_state->autosuspend_override <
  21077. + FORCE_SUSPEND_FAIL_MAX) {
  21078. + vchiq_log_info(vchiq_susp_log_level, "%s letting "
  21079. + "videocore go idle", __func__);
  21080. + status = VCHIQ_SUCCESS;
  21081. + } else {
  21082. + vchiq_log_warning(vchiq_susp_log_level, "%s failed too "
  21083. + "many times - attempting suspend", __func__);
  21084. + status = vchiq_arm_vcsuspend(state);
  21085. + }
  21086. + } else {
  21087. + vchiq_log_info(vchiq_susp_log_level, "%s videocore suspend "
  21088. + "in progress - wait for completion", __func__);
  21089. + status = VCHIQ_SUCCESS;
  21090. + }
  21091. +
  21092. + /* Wait for suspend to happen due to system idle (not forced..) */
  21093. + if (status != VCHIQ_SUCCESS)
  21094. + goto unblock_resume;
  21095. +
  21096. + do {
  21097. + write_unlock_bh(&arm_state->susp_res_lock);
  21098. +
  21099. + rc = wait_for_completion_interruptible_timeout(
  21100. + &arm_state->vc_suspend_complete,
  21101. + msecs_to_jiffies(FORCE_SUSPEND_TIMEOUT_MS));
  21102. +
  21103. + write_lock_bh(&arm_state->susp_res_lock);
  21104. + if (rc < 0) {
  21105. + vchiq_log_warning(vchiq_susp_log_level, "%s "
  21106. + "interrupted waiting for suspend", __func__);
  21107. + status = VCHIQ_ERROR;
  21108. + goto unblock_resume;
  21109. + } else if (rc == 0) {
  21110. + if (arm_state->vc_suspend_state > VC_SUSPEND_IDLE) {
  21111. + /* Repeat timeout once if in progress */
  21112. + if (repeat < 0) {
  21113. + repeat = 1;
  21114. + continue;
  21115. + }
  21116. + }
  21117. + arm_state->autosuspend_override++;
  21118. + output_timeout_error(state);
  21119. +
  21120. + status = VCHIQ_RETRY;
  21121. + goto unblock_resume;
  21122. + }
  21123. + } while (0 < (repeat--));
  21124. +
  21125. + /* Check and report state in case we need to abort ARM suspend */
  21126. + if (arm_state->vc_suspend_state != VC_SUSPEND_SUSPENDED) {
  21127. + status = VCHIQ_RETRY;
  21128. + vchiq_log_error(vchiq_susp_log_level,
  21129. + "%s videocore suspend failed (state %s)", __func__,
  21130. + suspend_state_names[arm_state->vc_suspend_state +
  21131. + VC_SUSPEND_NUM_OFFSET]);
  21132. + /* Reset the state only if it's still in an error state.
  21133. + * Something could have already initiated another suspend. */
  21134. + if (arm_state->vc_suspend_state < VC_SUSPEND_IDLE)
  21135. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  21136. +
  21137. + goto unblock_resume;
  21138. + }
  21139. +
  21140. + /* successfully suspended - unlock and exit */
  21141. + goto unlock;
  21142. +
  21143. +unblock_resume:
  21144. + /* all error states need to unblock resume before exit */
  21145. + unblock_resume(arm_state);
  21146. +
  21147. +unlock:
  21148. + write_unlock_bh(&arm_state->susp_res_lock);
  21149. +
  21150. +out:
  21151. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, status);
  21152. + return status;
  21153. +}
  21154. +
  21155. +void
  21156. +vchiq_check_suspend(VCHIQ_STATE_T *state)
  21157. +{
  21158. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21159. +
  21160. + if (!arm_state)
  21161. + goto out;
  21162. +
  21163. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  21164. +
  21165. + write_lock_bh(&arm_state->susp_res_lock);
  21166. + if (arm_state->vc_suspend_state != VC_SUSPEND_SUSPENDED &&
  21167. + arm_state->first_connect &&
  21168. + !vchiq_videocore_wanted(state)) {
  21169. + vchiq_arm_vcsuspend(state);
  21170. + }
  21171. + write_unlock_bh(&arm_state->susp_res_lock);
  21172. +
  21173. +out:
  21174. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  21175. + return;
  21176. +}
  21177. +
  21178. +
  21179. +int
  21180. +vchiq_arm_allow_resume(VCHIQ_STATE_T *state)
  21181. +{
  21182. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21183. + int resume = 0;
  21184. + int ret = -1;
  21185. +
  21186. + if (!arm_state)
  21187. + goto out;
  21188. +
  21189. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  21190. +
  21191. + write_lock_bh(&arm_state->susp_res_lock);
  21192. + unblock_resume(arm_state);
  21193. + resume = vchiq_check_resume(state);
  21194. + write_unlock_bh(&arm_state->susp_res_lock);
  21195. +
  21196. + if (resume) {
  21197. + if (wait_for_completion_interruptible(
  21198. + &arm_state->vc_resume_complete) < 0) {
  21199. + vchiq_log_error(vchiq_susp_log_level,
  21200. + "%s interrupted", __func__);
  21201. + /* failed, cannot accurately derive suspend
  21202. + * state, so exit early. */
  21203. + goto out;
  21204. + }
  21205. + }
  21206. +
  21207. + read_lock_bh(&arm_state->susp_res_lock);
  21208. + if (arm_state->vc_suspend_state == VC_SUSPEND_SUSPENDED) {
  21209. + vchiq_log_info(vchiq_susp_log_level,
  21210. + "%s: Videocore remains suspended", __func__);
  21211. + } else {
  21212. + vchiq_log_info(vchiq_susp_log_level,
  21213. + "%s: Videocore resumed", __func__);
  21214. + ret = 0;
  21215. + }
  21216. + read_unlock_bh(&arm_state->susp_res_lock);
  21217. +out:
  21218. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, ret);
  21219. + return ret;
  21220. +}
  21221. +
  21222. +/* This function should be called with the write lock held */
  21223. +int
  21224. +vchiq_check_resume(VCHIQ_STATE_T *state)
  21225. +{
  21226. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21227. + int resume = 0;
  21228. +
  21229. + if (!arm_state)
  21230. + goto out;
  21231. +
  21232. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  21233. +
  21234. + if (need_resume(state)) {
  21235. + set_resume_state(arm_state, VC_RESUME_REQUESTED);
  21236. + request_poll(state, NULL, 0);
  21237. + resume = 1;
  21238. + }
  21239. +
  21240. +out:
  21241. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  21242. + return resume;
  21243. +}
  21244. +
  21245. +void
  21246. +vchiq_platform_check_resume(VCHIQ_STATE_T *state)
  21247. +{
  21248. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21249. + int res = 0;
  21250. +
  21251. + if (!arm_state)
  21252. + goto out;
  21253. +
  21254. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  21255. +
  21256. + write_lock_bh(&arm_state->susp_res_lock);
  21257. + if (arm_state->wake_address == 0) {
  21258. + vchiq_log_info(vchiq_susp_log_level,
  21259. + "%s: already awake", __func__);
  21260. + goto unlock;
  21261. + }
  21262. + if (arm_state->vc_resume_state == VC_RESUME_IN_PROGRESS) {
  21263. + vchiq_log_info(vchiq_susp_log_level,
  21264. + "%s: already resuming", __func__);
  21265. + goto unlock;
  21266. + }
  21267. +
  21268. + if (arm_state->vc_resume_state == VC_RESUME_REQUESTED) {
  21269. + set_resume_state(arm_state, VC_RESUME_IN_PROGRESS);
  21270. + res = 1;
  21271. + } else
  21272. + vchiq_log_trace(vchiq_susp_log_level,
  21273. + "%s: not resuming (resume state %s)", __func__,
  21274. + resume_state_names[arm_state->vc_resume_state +
  21275. + VC_RESUME_NUM_OFFSET]);
  21276. +
  21277. +unlock:
  21278. + write_unlock_bh(&arm_state->susp_res_lock);
  21279. +
  21280. + if (res)
  21281. + vchiq_platform_resume(state);
  21282. +
  21283. +out:
  21284. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  21285. + return;
  21286. +
  21287. +}
  21288. +
  21289. +
  21290. +
  21291. +VCHIQ_STATUS_T
  21292. +vchiq_use_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  21293. + enum USE_TYPE_E use_type)
  21294. +{
  21295. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21296. + VCHIQ_STATUS_T ret = VCHIQ_SUCCESS;
  21297. + char entity[16];
  21298. + int *entity_uc;
  21299. + int local_uc, local_entity_uc;
  21300. +
  21301. + if (!arm_state)
  21302. + goto out;
  21303. +
  21304. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  21305. +
  21306. + if (use_type == USE_TYPE_VCHIQ) {
  21307. + sprintf(entity, "VCHIQ: ");
  21308. + entity_uc = &arm_state->peer_use_count;
  21309. + } else if (service) {
  21310. + sprintf(entity, "%c%c%c%c:%03d",
  21311. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  21312. + service->client_id);
  21313. + entity_uc = &service->service_use_count;
  21314. + } else {
  21315. + vchiq_log_error(vchiq_susp_log_level, "%s null service "
  21316. + "ptr", __func__);
  21317. + ret = VCHIQ_ERROR;
  21318. + goto out;
  21319. + }
  21320. +
  21321. + write_lock_bh(&arm_state->susp_res_lock);
  21322. + while (arm_state->resume_blocked) {
  21323. + /* If we call 'use' while force suspend is waiting for suspend,
  21324. + * then we're about to block the thread which the force is
  21325. + * waiting to complete, so we're bound to just time out. In this
  21326. + * case, set the suspend state such that the wait will be
  21327. + * canceled, so we can complete as quickly as possible. */
  21328. + if (arm_state->resume_blocked && arm_state->vc_suspend_state ==
  21329. + VC_SUSPEND_IDLE) {
  21330. + set_suspend_state(arm_state, VC_SUSPEND_FORCE_CANCELED);
  21331. + break;
  21332. + }
  21333. + /* If suspend is already in progress then we need to block */
  21334. + if (!try_wait_for_completion(&arm_state->resume_blocker)) {
  21335. + /* Indicate that there are threads waiting on the resume
  21336. + * blocker. These need to be allowed to complete before
  21337. + * a _second_ call to force suspend can complete,
  21338. + * otherwise low priority threads might never actually
  21339. + * continue */
  21340. + arm_state->blocked_count++;
  21341. + write_unlock_bh(&arm_state->susp_res_lock);
  21342. + vchiq_log_info(vchiq_susp_log_level, "%s %s resume "
  21343. + "blocked - waiting...", __func__, entity);
  21344. + if (wait_for_completion_killable(
  21345. + &arm_state->resume_blocker) != 0) {
  21346. + vchiq_log_error(vchiq_susp_log_level, "%s %s "
  21347. + "wait for resume blocker interrupted",
  21348. + __func__, entity);
  21349. + ret = VCHIQ_ERROR;
  21350. + write_lock_bh(&arm_state->susp_res_lock);
  21351. + arm_state->blocked_count--;
  21352. + write_unlock_bh(&arm_state->susp_res_lock);
  21353. + goto out;
  21354. + }
  21355. + vchiq_log_info(vchiq_susp_log_level, "%s %s resume "
  21356. + "unblocked", __func__, entity);
  21357. + write_lock_bh(&arm_state->susp_res_lock);
  21358. + if (--arm_state->blocked_count == 0)
  21359. + complete_all(&arm_state->blocked_blocker);
  21360. + }
  21361. + }
  21362. +
  21363. + stop_suspend_timer(arm_state);
  21364. +
  21365. + local_uc = ++arm_state->videocore_use_count;
  21366. + local_entity_uc = ++(*entity_uc);
  21367. +
  21368. + /* If there's a pending request which hasn't yet been serviced then
  21369. + * just clear it. If we're past VC_SUSPEND_REQUESTED state then
  21370. + * vc_resume_complete will block until we either resume or fail to
  21371. + * suspend */
  21372. + if (arm_state->vc_suspend_state <= VC_SUSPEND_REQUESTED)
  21373. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  21374. +
  21375. + if ((use_type != USE_TYPE_SERVICE_NO_RESUME) && need_resume(state)) {
  21376. + set_resume_state(arm_state, VC_RESUME_REQUESTED);
  21377. + vchiq_log_info(vchiq_susp_log_level,
  21378. + "%s %s count %d, state count %d",
  21379. + __func__, entity, local_entity_uc, local_uc);
  21380. + request_poll(state, NULL, 0);
  21381. + } else
  21382. + vchiq_log_trace(vchiq_susp_log_level,
  21383. + "%s %s count %d, state count %d",
  21384. + __func__, entity, *entity_uc, local_uc);
  21385. +
  21386. +
  21387. + write_unlock_bh(&arm_state->susp_res_lock);
  21388. +
  21389. + /* Completion is in a done state when we're not suspended, so this won't
  21390. + * block for the non-suspended case. */
  21391. + if (!try_wait_for_completion(&arm_state->vc_resume_complete)) {
  21392. + vchiq_log_info(vchiq_susp_log_level, "%s %s wait for resume",
  21393. + __func__, entity);
  21394. + if (wait_for_completion_killable(
  21395. + &arm_state->vc_resume_complete) != 0) {
  21396. + vchiq_log_error(vchiq_susp_log_level, "%s %s wait for "
  21397. + "resume interrupted", __func__, entity);
  21398. + ret = VCHIQ_ERROR;
  21399. + goto out;
  21400. + }
  21401. + vchiq_log_info(vchiq_susp_log_level, "%s %s resumed", __func__,
  21402. + entity);
  21403. + }
  21404. +
  21405. + if (ret == VCHIQ_SUCCESS) {
  21406. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  21407. + long ack_cnt = atomic_xchg(&arm_state->ka_use_ack_count, 0);
  21408. + while (ack_cnt && (status == VCHIQ_SUCCESS)) {
  21409. + /* Send the use notify to videocore */
  21410. + status = vchiq_send_remote_use_active(state);
  21411. + if (status == VCHIQ_SUCCESS)
  21412. + ack_cnt--;
  21413. + else
  21414. + atomic_add(ack_cnt,
  21415. + &arm_state->ka_use_ack_count);
  21416. + }
  21417. + }
  21418. +
  21419. +out:
  21420. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, ret);
  21421. + return ret;
  21422. +}
  21423. +
  21424. +VCHIQ_STATUS_T
  21425. +vchiq_release_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service)
  21426. +{
  21427. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21428. + VCHIQ_STATUS_T ret = VCHIQ_SUCCESS;
  21429. + char entity[16];
  21430. + int *entity_uc;
  21431. + int local_uc, local_entity_uc;
  21432. +
  21433. + if (!arm_state)
  21434. + goto out;
  21435. +
  21436. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  21437. +
  21438. + if (service) {
  21439. + sprintf(entity, "%c%c%c%c:%03d",
  21440. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  21441. + service->client_id);
  21442. + entity_uc = &service->service_use_count;
  21443. + } else {
  21444. + sprintf(entity, "PEER: ");
  21445. + entity_uc = &arm_state->peer_use_count;
  21446. + }
  21447. +
  21448. + write_lock_bh(&arm_state->susp_res_lock);
  21449. + if (!arm_state->videocore_use_count || !(*entity_uc)) {
  21450. + /* Don't use BUG_ON - don't allow user thread to crash kernel */
  21451. + WARN_ON(!arm_state->videocore_use_count);
  21452. + WARN_ON(!(*entity_uc));
  21453. + ret = VCHIQ_ERROR;
  21454. + goto unlock;
  21455. + }
  21456. + local_uc = --arm_state->videocore_use_count;
  21457. + local_entity_uc = --(*entity_uc);
  21458. +
  21459. + if (!vchiq_videocore_wanted(state)) {
  21460. + if (vchiq_platform_use_suspend_timer() &&
  21461. + !arm_state->resume_blocked) {
  21462. + /* Only use the timer if we're not trying to force
  21463. + * suspend (=> resume_blocked) */
  21464. + start_suspend_timer(arm_state);
  21465. + } else {
  21466. + vchiq_log_info(vchiq_susp_log_level,
  21467. + "%s %s count %d, state count %d - suspending",
  21468. + __func__, entity, *entity_uc,
  21469. + arm_state->videocore_use_count);
  21470. + vchiq_arm_vcsuspend(state);
  21471. + }
  21472. + } else
  21473. + vchiq_log_trace(vchiq_susp_log_level,
  21474. + "%s %s count %d, state count %d",
  21475. + __func__, entity, *entity_uc,
  21476. + arm_state->videocore_use_count);
  21477. +
  21478. +unlock:
  21479. + write_unlock_bh(&arm_state->susp_res_lock);
  21480. +
  21481. +out:
  21482. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, ret);
  21483. + return ret;
  21484. +}
  21485. +
  21486. +void
  21487. +vchiq_on_remote_use(VCHIQ_STATE_T *state)
  21488. +{
  21489. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21490. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  21491. + atomic_inc(&arm_state->ka_use_count);
  21492. + complete(&arm_state->ka_evt);
  21493. +}
  21494. +
  21495. +void
  21496. +vchiq_on_remote_release(VCHIQ_STATE_T *state)
  21497. +{
  21498. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21499. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  21500. + atomic_inc(&arm_state->ka_release_count);
  21501. + complete(&arm_state->ka_evt);
  21502. +}
  21503. +
  21504. +VCHIQ_STATUS_T
  21505. +vchiq_use_service_internal(VCHIQ_SERVICE_T *service)
  21506. +{
  21507. + return vchiq_use_internal(service->state, service, USE_TYPE_SERVICE);
  21508. +}
  21509. +
  21510. +VCHIQ_STATUS_T
  21511. +vchiq_release_service_internal(VCHIQ_SERVICE_T *service)
  21512. +{
  21513. + return vchiq_release_internal(service->state, service);
  21514. +}
  21515. +
  21516. +static void suspend_timer_callback(unsigned long context)
  21517. +{
  21518. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *)context;
  21519. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21520. + if (!arm_state)
  21521. + goto out;
  21522. + vchiq_log_info(vchiq_susp_log_level,
  21523. + "%s - suspend timer expired - check suspend", __func__);
  21524. + vchiq_check_suspend(state);
  21525. +out:
  21526. + return;
  21527. +}
  21528. +
  21529. +VCHIQ_STATUS_T
  21530. +vchiq_use_service_no_resume(VCHIQ_SERVICE_HANDLE_T handle)
  21531. +{
  21532. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  21533. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  21534. + if (service) {
  21535. + ret = vchiq_use_internal(service->state, service,
  21536. + USE_TYPE_SERVICE_NO_RESUME);
  21537. + unlock_service(service);
  21538. + }
  21539. + return ret;
  21540. +}
  21541. +
  21542. +VCHIQ_STATUS_T
  21543. +vchiq_use_service(VCHIQ_SERVICE_HANDLE_T handle)
  21544. +{
  21545. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  21546. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  21547. + if (service) {
  21548. + ret = vchiq_use_internal(service->state, service,
  21549. + USE_TYPE_SERVICE);
  21550. + unlock_service(service);
  21551. + }
  21552. + return ret;
  21553. +}
  21554. +
  21555. +VCHIQ_STATUS_T
  21556. +vchiq_release_service(VCHIQ_SERVICE_HANDLE_T handle)
  21557. +{
  21558. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  21559. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  21560. + if (service) {
  21561. + ret = vchiq_release_internal(service->state, service);
  21562. + unlock_service(service);
  21563. + }
  21564. + return ret;
  21565. +}
  21566. +
  21567. +void
  21568. +vchiq_dump_service_use_state(VCHIQ_STATE_T *state)
  21569. +{
  21570. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21571. + int i, j = 0;
  21572. + /* Only dump 64 services */
  21573. + static const int local_max_services = 64;
  21574. + /* If there's more than 64 services, only dump ones with
  21575. + * non-zero counts */
  21576. + int only_nonzero = 0;
  21577. + static const char *nz = "<-- preventing suspend";
  21578. +
  21579. + enum vc_suspend_status vc_suspend_state;
  21580. + enum vc_resume_status vc_resume_state;
  21581. + int peer_count;
  21582. + int vc_use_count;
  21583. + int active_services;
  21584. + struct service_data_struct {
  21585. + int fourcc;
  21586. + int clientid;
  21587. + int use_count;
  21588. + } service_data[local_max_services];
  21589. +
  21590. + if (!arm_state)
  21591. + return;
  21592. +
  21593. + read_lock_bh(&arm_state->susp_res_lock);
  21594. + vc_suspend_state = arm_state->vc_suspend_state;
  21595. + vc_resume_state = arm_state->vc_resume_state;
  21596. + peer_count = arm_state->peer_use_count;
  21597. + vc_use_count = arm_state->videocore_use_count;
  21598. + active_services = state->unused_service;
  21599. + if (active_services > local_max_services)
  21600. + only_nonzero = 1;
  21601. +
  21602. + for (i = 0; (i < active_services) && (j < local_max_services); i++) {
  21603. + VCHIQ_SERVICE_T *service_ptr = state->services[i];
  21604. + if (!service_ptr)
  21605. + continue;
  21606. +
  21607. + if (only_nonzero && !service_ptr->service_use_count)
  21608. + continue;
  21609. +
  21610. + if (service_ptr->srvstate != VCHIQ_SRVSTATE_FREE) {
  21611. + service_data[j].fourcc = service_ptr->base.fourcc;
  21612. + service_data[j].clientid = service_ptr->client_id;
  21613. + service_data[j++].use_count = service_ptr->
  21614. + service_use_count;
  21615. + }
  21616. + }
  21617. +
  21618. + read_unlock_bh(&arm_state->susp_res_lock);
  21619. +
  21620. + vchiq_log_warning(vchiq_susp_log_level,
  21621. + "-- Videcore suspend state: %s --",
  21622. + suspend_state_names[vc_suspend_state + VC_SUSPEND_NUM_OFFSET]);
  21623. + vchiq_log_warning(vchiq_susp_log_level,
  21624. + "-- Videcore resume state: %s --",
  21625. + resume_state_names[vc_resume_state + VC_RESUME_NUM_OFFSET]);
  21626. +
  21627. + if (only_nonzero)
  21628. + vchiq_log_warning(vchiq_susp_log_level, "Too many active "
  21629. + "services (%d). Only dumping up to first %d services "
  21630. + "with non-zero use-count", active_services,
  21631. + local_max_services);
  21632. +
  21633. + for (i = 0; i < j; i++) {
  21634. + vchiq_log_warning(vchiq_susp_log_level,
  21635. + "----- %c%c%c%c:%d service count %d %s",
  21636. + VCHIQ_FOURCC_AS_4CHARS(service_data[i].fourcc),
  21637. + service_data[i].clientid,
  21638. + service_data[i].use_count,
  21639. + service_data[i].use_count ? nz : "");
  21640. + }
  21641. + vchiq_log_warning(vchiq_susp_log_level,
  21642. + "----- VCHIQ use count count %d", peer_count);
  21643. + vchiq_log_warning(vchiq_susp_log_level,
  21644. + "--- Overall vchiq instance use count %d", vc_use_count);
  21645. +
  21646. + vchiq_dump_platform_use_state(state);
  21647. +}
  21648. +
  21649. +VCHIQ_STATUS_T
  21650. +vchiq_check_service(VCHIQ_SERVICE_T *service)
  21651. +{
  21652. + VCHIQ_ARM_STATE_T *arm_state;
  21653. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  21654. +
  21655. + if (!service || !service->state)
  21656. + goto out;
  21657. +
  21658. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  21659. +
  21660. + arm_state = vchiq_platform_get_arm_state(service->state);
  21661. +
  21662. + read_lock_bh(&arm_state->susp_res_lock);
  21663. + if (service->service_use_count)
  21664. + ret = VCHIQ_SUCCESS;
  21665. + read_unlock_bh(&arm_state->susp_res_lock);
  21666. +
  21667. + if (ret == VCHIQ_ERROR) {
  21668. + vchiq_log_error(vchiq_susp_log_level,
  21669. + "%s ERROR - %c%c%c%c:%d service count %d, "
  21670. + "state count %d, videocore suspend state %s", __func__,
  21671. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  21672. + service->client_id, service->service_use_count,
  21673. + arm_state->videocore_use_count,
  21674. + suspend_state_names[arm_state->vc_suspend_state +
  21675. + VC_SUSPEND_NUM_OFFSET]);
  21676. + vchiq_dump_service_use_state(service->state);
  21677. + }
  21678. +out:
  21679. + return ret;
  21680. +}
  21681. +
  21682. +/* stub functions */
  21683. +void vchiq_on_remote_use_active(VCHIQ_STATE_T *state)
  21684. +{
  21685. + (void)state;
  21686. +}
  21687. +
  21688. +void vchiq_platform_conn_state_changed(VCHIQ_STATE_T *state,
  21689. + VCHIQ_CONNSTATE_T oldstate, VCHIQ_CONNSTATE_T newstate)
  21690. +{
  21691. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21692. + vchiq_log_info(vchiq_susp_log_level, "%d: %s->%s", state->id,
  21693. + get_conn_state_name(oldstate), get_conn_state_name(newstate));
  21694. + if (state->conn_state == VCHIQ_CONNSTATE_CONNECTED) {
  21695. + write_lock_bh(&arm_state->susp_res_lock);
  21696. + if (!arm_state->first_connect) {
  21697. + char threadname[10];
  21698. + arm_state->first_connect = 1;
  21699. + write_unlock_bh(&arm_state->susp_res_lock);
  21700. + snprintf(threadname, sizeof(threadname), "VCHIQka-%d",
  21701. + state->id);
  21702. + arm_state->ka_thread = kthread_create(
  21703. + &vchiq_keepalive_thread_func,
  21704. + (void *)state,
  21705. + threadname);
  21706. + if (arm_state->ka_thread == NULL) {
  21707. + vchiq_log_error(vchiq_susp_log_level,
  21708. + "vchiq: FATAL: couldn't create thread %s",
  21709. + threadname);
  21710. + } else {
  21711. + wake_up_process(arm_state->ka_thread);
  21712. + }
  21713. + } else
  21714. + write_unlock_bh(&arm_state->susp_res_lock);
  21715. + }
  21716. +}
  21717. +
  21718. +
  21719. +/****************************************************************************
  21720. +*
  21721. +* vchiq_init - called when the module is loaded.
  21722. +*
  21723. +***************************************************************************/
  21724. +
  21725. +static int __init
  21726. +vchiq_init(void)
  21727. +{
  21728. + int err;
  21729. + void *ptr_err;
  21730. +
  21731. + /* create proc entries */
  21732. + err = vchiq_proc_init();
  21733. + if (err != 0)
  21734. + goto failed_proc_init;
  21735. +
  21736. + err = alloc_chrdev_region(&vchiq_devid, VCHIQ_MINOR, 1, DEVICE_NAME);
  21737. + if (err != 0) {
  21738. + vchiq_log_error(vchiq_arm_log_level,
  21739. + "Unable to allocate device number");
  21740. + goto failed_alloc_chrdev;
  21741. + }
  21742. + cdev_init(&vchiq_cdev, &vchiq_fops);
  21743. + vchiq_cdev.owner = THIS_MODULE;
  21744. + err = cdev_add(&vchiq_cdev, vchiq_devid, 1);
  21745. + if (err != 0) {
  21746. + vchiq_log_error(vchiq_arm_log_level,
  21747. + "Unable to register device");
  21748. + goto failed_cdev_add;
  21749. + }
  21750. +
  21751. + /* create sysfs entries */
  21752. + vchiq_class = class_create(THIS_MODULE, DEVICE_NAME);
  21753. + ptr_err = vchiq_class;
  21754. + if (IS_ERR(ptr_err))
  21755. + goto failed_class_create;
  21756. +
  21757. + vchiq_dev = device_create(vchiq_class, NULL,
  21758. + vchiq_devid, NULL, "vchiq");
  21759. + ptr_err = vchiq_dev;
  21760. + if (IS_ERR(ptr_err))
  21761. + goto failed_device_create;
  21762. +
  21763. + err = vchiq_platform_init(&g_state);
  21764. + if (err != 0)
  21765. + goto failed_platform_init;
  21766. +
  21767. + vchiq_log_info(vchiq_arm_log_level,
  21768. + "vchiq: initialised - version %d (min %d), device %d.%d",
  21769. + VCHIQ_VERSION, VCHIQ_VERSION_MIN,
  21770. + MAJOR(vchiq_devid), MINOR(vchiq_devid));
  21771. +
  21772. + return 0;
  21773. +
  21774. +failed_platform_init:
  21775. + device_destroy(vchiq_class, vchiq_devid);
  21776. +failed_device_create:
  21777. + class_destroy(vchiq_class);
  21778. +failed_class_create:
  21779. + cdev_del(&vchiq_cdev);
  21780. + err = PTR_ERR(ptr_err);
  21781. +failed_cdev_add:
  21782. + unregister_chrdev_region(vchiq_devid, 1);
  21783. +failed_alloc_chrdev:
  21784. + vchiq_proc_deinit();
  21785. +failed_proc_init:
  21786. + vchiq_log_warning(vchiq_arm_log_level, "could not load vchiq");
  21787. + return err;
  21788. +}
  21789. +
  21790. +static int vchiq_instance_get_use_count(VCHIQ_INSTANCE_T instance)
  21791. +{
  21792. + VCHIQ_SERVICE_T *service;
  21793. + int use_count = 0, i;
  21794. + i = 0;
  21795. + while ((service = next_service_by_instance(instance->state,
  21796. + instance, &i)) != NULL) {
  21797. + use_count += service->service_use_count;
  21798. + unlock_service(service);
  21799. + }
  21800. + return use_count;
  21801. +}
  21802. +
  21803. +/* read the per-process use-count */
  21804. +static int proc_read_use_count(char *page, char **start,
  21805. + off_t off, int count,
  21806. + int *eof, void *data)
  21807. +{
  21808. + VCHIQ_INSTANCE_T instance = data;
  21809. + int len, use_count;
  21810. +
  21811. + use_count = vchiq_instance_get_use_count(instance);
  21812. + len = snprintf(page+off, count, "%d\n", use_count);
  21813. +
  21814. + return len;
  21815. +}
  21816. +
  21817. +/* add an instance (process) to the proc entries */
  21818. +static int vchiq_proc_add_instance(VCHIQ_INSTANCE_T instance)
  21819. +{
  21820. +#if 1
  21821. + return 0;
  21822. +#else
  21823. + char pidstr[32];
  21824. + struct proc_dir_entry *top, *use_count;
  21825. + struct proc_dir_entry *clients = vchiq_clients_top();
  21826. + int pid = instance->pid;
  21827. +
  21828. + snprintf(pidstr, sizeof(pidstr), "%d", pid);
  21829. + top = proc_mkdir(pidstr, clients);
  21830. + if (!top)
  21831. + goto fail_top;
  21832. +
  21833. + use_count = create_proc_read_entry("use_count",
  21834. + 0444, top,
  21835. + proc_read_use_count,
  21836. + instance);
  21837. + if (!use_count)
  21838. + goto fail_use_count;
  21839. +
  21840. + instance->proc_entry = top;
  21841. +
  21842. + return 0;
  21843. +
  21844. +fail_use_count:
  21845. + remove_proc_entry(top->name, clients);
  21846. +fail_top:
  21847. + return -ENOMEM;
  21848. +#endif
  21849. +}
  21850. +
  21851. +static void vchiq_proc_remove_instance(VCHIQ_INSTANCE_T instance)
  21852. +{
  21853. +#if 0
  21854. + struct proc_dir_entry *clients = vchiq_clients_top();
  21855. + remove_proc_entry("use_count", instance->proc_entry);
  21856. + remove_proc_entry(instance->proc_entry->name, clients);
  21857. +#endif
  21858. +}
  21859. +
  21860. +/****************************************************************************
  21861. +*
  21862. +* vchiq_exit - called when the module is unloaded.
  21863. +*
  21864. +***************************************************************************/
  21865. +
  21866. +static void __exit
  21867. +vchiq_exit(void)
  21868. +{
  21869. + vchiq_platform_exit(&g_state);
  21870. + device_destroy(vchiq_class, vchiq_devid);
  21871. + class_destroy(vchiq_class);
  21872. + cdev_del(&vchiq_cdev);
  21873. + unregister_chrdev_region(vchiq_devid, 1);
  21874. +}
  21875. +
  21876. +module_init(vchiq_init);
  21877. +module_exit(vchiq_exit);
  21878. +MODULE_LICENSE("GPL");
  21879. +MODULE_AUTHOR("Broadcom Corporation");
  21880. diff -Nur linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h
  21881. --- linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h 1970-01-01 01:00:00.000000000 +0100
  21882. +++ linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h 2014-02-17 22:41:01.000000000 +0100
  21883. @@ -0,0 +1,212 @@
  21884. +/**
  21885. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  21886. + *
  21887. + * Redistribution and use in source and binary forms, with or without
  21888. + * modification, are permitted provided that the following conditions
  21889. + * are met:
  21890. + * 1. Redistributions of source code must retain the above copyright
  21891. + * notice, this list of conditions, and the following disclaimer,
  21892. + * without modification.
  21893. + * 2. Redistributions in binary form must reproduce the above copyright
  21894. + * notice, this list of conditions and the following disclaimer in the
  21895. + * documentation and/or other materials provided with the distribution.
  21896. + * 3. The names of the above-listed copyright holders may not be used
  21897. + * to endorse or promote products derived from this software without
  21898. + * specific prior written permission.
  21899. + *
  21900. + * ALTERNATIVELY, this software may be distributed under the terms of the
  21901. + * GNU General Public License ("GPL") version 2, as published by the Free
  21902. + * Software Foundation.
  21903. + *
  21904. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  21905. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  21906. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  21907. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  21908. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  21909. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  21910. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  21911. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  21912. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  21913. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  21914. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  21915. + */
  21916. +
  21917. +#ifndef VCHIQ_ARM_H
  21918. +#define VCHIQ_ARM_H
  21919. +
  21920. +#include <linux/mutex.h>
  21921. +#include <linux/semaphore.h>
  21922. +#include <linux/atomic.h>
  21923. +#include "vchiq_core.h"
  21924. +
  21925. +
  21926. +enum vc_suspend_status {
  21927. + VC_SUSPEND_FORCE_CANCELED = -3, /* Force suspend canceled, too busy */
  21928. + VC_SUSPEND_REJECTED = -2, /* Videocore rejected suspend request */
  21929. + VC_SUSPEND_FAILED = -1, /* Videocore suspend failed */
  21930. + VC_SUSPEND_IDLE = 0, /* VC active, no suspend actions */
  21931. + VC_SUSPEND_REQUESTED, /* User has requested suspend */
  21932. + VC_SUSPEND_IN_PROGRESS, /* Slot handler has recvd suspend request */
  21933. + VC_SUSPEND_SUSPENDED /* Videocore suspend succeeded */
  21934. +};
  21935. +
  21936. +enum vc_resume_status {
  21937. + VC_RESUME_FAILED = -1, /* Videocore resume failed */
  21938. + VC_RESUME_IDLE = 0, /* VC suspended, no resume actions */
  21939. + VC_RESUME_REQUESTED, /* User has requested resume */
  21940. + VC_RESUME_IN_PROGRESS, /* Slot handler has received resume request */
  21941. + VC_RESUME_RESUMED /* Videocore resumed successfully (active) */
  21942. +};
  21943. +
  21944. +
  21945. +enum USE_TYPE_E {
  21946. + USE_TYPE_SERVICE,
  21947. + USE_TYPE_SERVICE_NO_RESUME,
  21948. + USE_TYPE_VCHIQ
  21949. +};
  21950. +
  21951. +
  21952. +
  21953. +typedef struct vchiq_arm_state_struct {
  21954. + /* Keepalive-related data */
  21955. + struct task_struct *ka_thread;
  21956. + struct completion ka_evt;
  21957. + atomic_t ka_use_count;
  21958. + atomic_t ka_use_ack_count;
  21959. + atomic_t ka_release_count;
  21960. +
  21961. + struct completion vc_suspend_complete;
  21962. + struct completion vc_resume_complete;
  21963. +
  21964. + rwlock_t susp_res_lock;
  21965. + enum vc_suspend_status vc_suspend_state;
  21966. + enum vc_resume_status vc_resume_state;
  21967. +
  21968. + unsigned int wake_address;
  21969. +
  21970. + struct timer_list suspend_timer;
  21971. + int suspend_timer_timeout;
  21972. + int suspend_timer_running;
  21973. +
  21974. + /* Global use count for videocore.
  21975. + ** This is equal to the sum of the use counts for all services. When
  21976. + ** this hits zero the videocore suspend procedure will be initiated.
  21977. + */
  21978. + int videocore_use_count;
  21979. +
  21980. + /* Use count to track requests from videocore peer.
  21981. + ** This use count is not associated with a service, so needs to be
  21982. + ** tracked separately with the state.
  21983. + */
  21984. + int peer_use_count;
  21985. +
  21986. + /* Flag to indicate whether resume is blocked. This happens when the
  21987. + ** ARM is suspending
  21988. + */
  21989. + struct completion resume_blocker;
  21990. + int resume_blocked;
  21991. + struct completion blocked_blocker;
  21992. + int blocked_count;
  21993. +
  21994. + int autosuspend_override;
  21995. +
  21996. + /* Flag to indicate that the first vchiq connect has made it through.
  21997. + ** This means that both sides should be fully ready, and we should
  21998. + ** be able to suspend after this point.
  21999. + */
  22000. + int first_connect;
  22001. +
  22002. + unsigned long long suspend_start_time;
  22003. + unsigned long long sleep_start_time;
  22004. + unsigned long long resume_start_time;
  22005. + unsigned long long last_wake_time;
  22006. +
  22007. +} VCHIQ_ARM_STATE_T;
  22008. +
  22009. +extern int vchiq_arm_log_level;
  22010. +extern int vchiq_susp_log_level;
  22011. +
  22012. +extern int __init
  22013. +vchiq_platform_init(VCHIQ_STATE_T *state);
  22014. +
  22015. +extern void __exit
  22016. +vchiq_platform_exit(VCHIQ_STATE_T *state);
  22017. +
  22018. +extern VCHIQ_STATE_T *
  22019. +vchiq_get_state(void);
  22020. +
  22021. +extern VCHIQ_STATUS_T
  22022. +vchiq_arm_vcsuspend(VCHIQ_STATE_T *state);
  22023. +
  22024. +extern VCHIQ_STATUS_T
  22025. +vchiq_arm_force_suspend(VCHIQ_STATE_T *state);
  22026. +
  22027. +extern int
  22028. +vchiq_arm_allow_resume(VCHIQ_STATE_T *state);
  22029. +
  22030. +extern VCHIQ_STATUS_T
  22031. +vchiq_arm_vcresume(VCHIQ_STATE_T *state);
  22032. +
  22033. +extern VCHIQ_STATUS_T
  22034. +vchiq_arm_init_state(VCHIQ_STATE_T *state, VCHIQ_ARM_STATE_T *arm_state);
  22035. +
  22036. +extern int
  22037. +vchiq_check_resume(VCHIQ_STATE_T *state);
  22038. +
  22039. +extern void
  22040. +vchiq_check_suspend(VCHIQ_STATE_T *state);
  22041. +
  22042. +extern VCHIQ_STATUS_T
  22043. +vchiq_use_service(VCHIQ_SERVICE_HANDLE_T handle);
  22044. +
  22045. +extern VCHIQ_STATUS_T
  22046. +vchiq_release_service(VCHIQ_SERVICE_HANDLE_T handle);
  22047. +
  22048. +extern VCHIQ_STATUS_T
  22049. +vchiq_check_service(VCHIQ_SERVICE_T *service);
  22050. +
  22051. +extern VCHIQ_STATUS_T
  22052. +vchiq_platform_suspend(VCHIQ_STATE_T *state);
  22053. +
  22054. +extern int
  22055. +vchiq_platform_videocore_wanted(VCHIQ_STATE_T *state);
  22056. +
  22057. +extern int
  22058. +vchiq_platform_use_suspend_timer(void);
  22059. +
  22060. +extern void
  22061. +vchiq_dump_platform_use_state(VCHIQ_STATE_T *state);
  22062. +
  22063. +extern void
  22064. +vchiq_dump_service_use_state(VCHIQ_STATE_T *state);
  22065. +
  22066. +extern VCHIQ_ARM_STATE_T*
  22067. +vchiq_platform_get_arm_state(VCHIQ_STATE_T *state);
  22068. +
  22069. +extern int
  22070. +vchiq_videocore_wanted(VCHIQ_STATE_T *state);
  22071. +
  22072. +extern VCHIQ_STATUS_T
  22073. +vchiq_use_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  22074. + enum USE_TYPE_E use_type);
  22075. +extern VCHIQ_STATUS_T
  22076. +vchiq_release_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service);
  22077. +
  22078. +void
  22079. +set_suspend_state(VCHIQ_ARM_STATE_T *arm_state,
  22080. + enum vc_suspend_status new_state);
  22081. +
  22082. +void
  22083. +set_resume_state(VCHIQ_ARM_STATE_T *arm_state,
  22084. + enum vc_resume_status new_state);
  22085. +
  22086. +void
  22087. +start_suspend_timer(VCHIQ_ARM_STATE_T *arm_state);
  22088. +
  22089. +extern int vchiq_proc_init(void);
  22090. +extern void vchiq_proc_deinit(void);
  22091. +extern struct proc_dir_entry *vchiq_proc_top(void);
  22092. +extern struct proc_dir_entry *vchiq_clients_top(void);
  22093. +
  22094. +
  22095. +#endif /* VCHIQ_ARM_H */
  22096. diff -Nur linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h
  22097. --- linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h 1970-01-01 01:00:00.000000000 +0100
  22098. +++ linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h 2014-02-17 22:41:01.000000000 +0100
  22099. @@ -0,0 +1,37 @@
  22100. +/**
  22101. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  22102. + *
  22103. + * Redistribution and use in source and binary forms, with or without
  22104. + * modification, are permitted provided that the following conditions
  22105. + * are met:
  22106. + * 1. Redistributions of source code must retain the above copyright
  22107. + * notice, this list of conditions, and the following disclaimer,
  22108. + * without modification.
  22109. + * 2. Redistributions in binary form must reproduce the above copyright
  22110. + * notice, this list of conditions and the following disclaimer in the
  22111. + * documentation and/or other materials provided with the distribution.
  22112. + * 3. The names of the above-listed copyright holders may not be used
  22113. + * to endorse or promote products derived from this software without
  22114. + * specific prior written permission.
  22115. + *
  22116. + * ALTERNATIVELY, this software may be distributed under the terms of the
  22117. + * GNU General Public License ("GPL") version 2, as published by the Free
  22118. + * Software Foundation.
  22119. + *
  22120. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  22121. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  22122. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  22123. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  22124. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  22125. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  22126. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  22127. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  22128. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  22129. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22130. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22131. + */
  22132. +
  22133. +const char *vchiq_get_build_hostname(void);
  22134. +const char *vchiq_get_build_version(void);
  22135. +const char *vchiq_get_build_time(void);
  22136. +const char *vchiq_get_build_date(void);
  22137. diff -Nur linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h
  22138. --- linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h 1970-01-01 01:00:00.000000000 +0100
  22139. +++ linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h 2014-02-17 22:41:01.000000000 +0100
  22140. @@ -0,0 +1,60 @@
  22141. +/**
  22142. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  22143. + *
  22144. + * Redistribution and use in source and binary forms, with or without
  22145. + * modification, are permitted provided that the following conditions
  22146. + * are met:
  22147. + * 1. Redistributions of source code must retain the above copyright
  22148. + * notice, this list of conditions, and the following disclaimer,
  22149. + * without modification.
  22150. + * 2. Redistributions in binary form must reproduce the above copyright
  22151. + * notice, this list of conditions and the following disclaimer in the
  22152. + * documentation and/or other materials provided with the distribution.
  22153. + * 3. The names of the above-listed copyright holders may not be used
  22154. + * to endorse or promote products derived from this software without
  22155. + * specific prior written permission.
  22156. + *
  22157. + * ALTERNATIVELY, this software may be distributed under the terms of the
  22158. + * GNU General Public License ("GPL") version 2, as published by the Free
  22159. + * Software Foundation.
  22160. + *
  22161. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  22162. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  22163. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  22164. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  22165. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  22166. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  22167. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  22168. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  22169. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  22170. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22171. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22172. + */
  22173. +
  22174. +#ifndef VCHIQ_CFG_H
  22175. +#define VCHIQ_CFG_H
  22176. +
  22177. +#define VCHIQ_MAGIC VCHIQ_MAKE_FOURCC('V', 'C', 'H', 'I')
  22178. +/* The version of VCHIQ - change with any non-trivial change */
  22179. +#define VCHIQ_VERSION 6
  22180. +/* The minimum compatible version - update to match VCHIQ_VERSION with any
  22181. +** incompatible change */
  22182. +#define VCHIQ_VERSION_MIN 3
  22183. +
  22184. +#define VCHIQ_MAX_STATES 1
  22185. +#define VCHIQ_MAX_SERVICES 4096
  22186. +#define VCHIQ_MAX_SLOTS 128
  22187. +#define VCHIQ_MAX_SLOTS_PER_SIDE 64
  22188. +
  22189. +#define VCHIQ_NUM_CURRENT_BULKS 32
  22190. +#define VCHIQ_NUM_SERVICE_BULKS 4
  22191. +
  22192. +#ifndef VCHIQ_ENABLE_DEBUG
  22193. +#define VCHIQ_ENABLE_DEBUG 1
  22194. +#endif
  22195. +
  22196. +#ifndef VCHIQ_ENABLE_STATS
  22197. +#define VCHIQ_ENABLE_STATS 1
  22198. +#endif
  22199. +
  22200. +#endif /* VCHIQ_CFG_H */
  22201. diff -Nur linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c
  22202. --- linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c 1970-01-01 01:00:00.000000000 +0100
  22203. +++ linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c 2014-02-17 22:41:01.000000000 +0100
  22204. @@ -0,0 +1,119 @@
  22205. +/**
  22206. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  22207. + *
  22208. + * Redistribution and use in source and binary forms, with or without
  22209. + * modification, are permitted provided that the following conditions
  22210. + * are met:
  22211. + * 1. Redistributions of source code must retain the above copyright
  22212. + * notice, this list of conditions, and the following disclaimer,
  22213. + * without modification.
  22214. + * 2. Redistributions in binary form must reproduce the above copyright
  22215. + * notice, this list of conditions and the following disclaimer in the
  22216. + * documentation and/or other materials provided with the distribution.
  22217. + * 3. The names of the above-listed copyright holders may not be used
  22218. + * to endorse or promote products derived from this software without
  22219. + * specific prior written permission.
  22220. + *
  22221. + * ALTERNATIVELY, this software may be distributed under the terms of the
  22222. + * GNU General Public License ("GPL") version 2, as published by the Free
  22223. + * Software Foundation.
  22224. + *
  22225. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  22226. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  22227. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  22228. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  22229. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  22230. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  22231. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  22232. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  22233. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  22234. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22235. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22236. + */
  22237. +
  22238. +#include "vchiq_connected.h"
  22239. +#include "vchiq_core.h"
  22240. +#include <linux/module.h>
  22241. +#include <linux/mutex.h>
  22242. +
  22243. +#define MAX_CALLBACKS 10
  22244. +
  22245. +static int g_connected;
  22246. +static int g_num_deferred_callbacks;
  22247. +static VCHIQ_CONNECTED_CALLBACK_T g_deferred_callback[MAX_CALLBACKS];
  22248. +static int g_once_init;
  22249. +static struct mutex g_connected_mutex;
  22250. +
  22251. +/****************************************************************************
  22252. +*
  22253. +* Function to initialize our lock.
  22254. +*
  22255. +***************************************************************************/
  22256. +
  22257. +static void connected_init(void)
  22258. +{
  22259. + if (!g_once_init) {
  22260. + mutex_init(&g_connected_mutex);
  22261. + g_once_init = 1;
  22262. + }
  22263. +}
  22264. +
  22265. +/****************************************************************************
  22266. +*
  22267. +* This function is used to defer initialization until the vchiq stack is
  22268. +* initialized. If the stack is already initialized, then the callback will
  22269. +* be made immediately, otherwise it will be deferred until
  22270. +* vchiq_call_connected_callbacks is called.
  22271. +*
  22272. +***************************************************************************/
  22273. +
  22274. +void vchiq_add_connected_callback(VCHIQ_CONNECTED_CALLBACK_T callback)
  22275. +{
  22276. + connected_init();
  22277. +
  22278. + if (mutex_lock_interruptible(&g_connected_mutex) != 0)
  22279. + return;
  22280. +
  22281. + if (g_connected)
  22282. + /* We're already connected. Call the callback immediately. */
  22283. +
  22284. + callback();
  22285. + else {
  22286. + if (g_num_deferred_callbacks >= MAX_CALLBACKS)
  22287. + vchiq_log_error(vchiq_core_log_level,
  22288. + "There already %d callback registered - "
  22289. + "please increase MAX_CALLBACKS",
  22290. + g_num_deferred_callbacks);
  22291. + else {
  22292. + g_deferred_callback[g_num_deferred_callbacks] =
  22293. + callback;
  22294. + g_num_deferred_callbacks++;
  22295. + }
  22296. + }
  22297. + mutex_unlock(&g_connected_mutex);
  22298. +}
  22299. +
  22300. +/****************************************************************************
  22301. +*
  22302. +* This function is called by the vchiq stack once it has been connected to
  22303. +* the videocore and clients can start to use the stack.
  22304. +*
  22305. +***************************************************************************/
  22306. +
  22307. +void vchiq_call_connected_callbacks(void)
  22308. +{
  22309. + int i;
  22310. +
  22311. + connected_init();
  22312. +
  22313. + if (mutex_lock_interruptible(&g_connected_mutex) != 0)
  22314. + return;
  22315. +
  22316. + for (i = 0; i < g_num_deferred_callbacks; i++)
  22317. + g_deferred_callback[i]();
  22318. +
  22319. + g_num_deferred_callbacks = 0;
  22320. + g_connected = 1;
  22321. + mutex_unlock(&g_connected_mutex);
  22322. +}
  22323. +EXPORT_SYMBOL(vchiq_add_connected_callback);
  22324. diff -Nur linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h
  22325. --- linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h 1970-01-01 01:00:00.000000000 +0100
  22326. +++ linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h 2014-02-17 22:41:01.000000000 +0100
  22327. @@ -0,0 +1,50 @@
  22328. +/**
  22329. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  22330. + *
  22331. + * Redistribution and use in source and binary forms, with or without
  22332. + * modification, are permitted provided that the following conditions
  22333. + * are met:
  22334. + * 1. Redistributions of source code must retain the above copyright
  22335. + * notice, this list of conditions, and the following disclaimer,
  22336. + * without modification.
  22337. + * 2. Redistributions in binary form must reproduce the above copyright
  22338. + * notice, this list of conditions and the following disclaimer in the
  22339. + * documentation and/or other materials provided with the distribution.
  22340. + * 3. The names of the above-listed copyright holders may not be used
  22341. + * to endorse or promote products derived from this software without
  22342. + * specific prior written permission.
  22343. + *
  22344. + * ALTERNATIVELY, this software may be distributed under the terms of the
  22345. + * GNU General Public License ("GPL") version 2, as published by the Free
  22346. + * Software Foundation.
  22347. + *
  22348. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  22349. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  22350. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  22351. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  22352. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  22353. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  22354. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  22355. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  22356. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  22357. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22358. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22359. + */
  22360. +
  22361. +#ifndef VCHIQ_CONNECTED_H
  22362. +#define VCHIQ_CONNECTED_H
  22363. +
  22364. +/* ---- Include Files ----------------------------------------------------- */
  22365. +
  22366. +/* ---- Constants and Types ---------------------------------------------- */
  22367. +
  22368. +typedef void (*VCHIQ_CONNECTED_CALLBACK_T)(void);
  22369. +
  22370. +/* ---- Variable Externs ------------------------------------------------- */
  22371. +
  22372. +/* ---- Function Prototypes ---------------------------------------------- */
  22373. +
  22374. +void vchiq_add_connected_callback(VCHIQ_CONNECTED_CALLBACK_T callback);
  22375. +void vchiq_call_connected_callbacks(void);
  22376. +
  22377. +#endif /* VCHIQ_CONNECTED_H */
  22378. diff -Nur linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c
  22379. --- linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c 1970-01-01 01:00:00.000000000 +0100
  22380. +++ linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c 2014-02-17 22:41:01.000000000 +0100
  22381. @@ -0,0 +1,3824 @@
  22382. +/**
  22383. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  22384. + *
  22385. + * Redistribution and use in source and binary forms, with or without
  22386. + * modification, are permitted provided that the following conditions
  22387. + * are met:
  22388. + * 1. Redistributions of source code must retain the above copyright
  22389. + * notice, this list of conditions, and the following disclaimer,
  22390. + * without modification.
  22391. + * 2. Redistributions in binary form must reproduce the above copyright
  22392. + * notice, this list of conditions and the following disclaimer in the
  22393. + * documentation and/or other materials provided with the distribution.
  22394. + * 3. The names of the above-listed copyright holders may not be used
  22395. + * to endorse or promote products derived from this software without
  22396. + * specific prior written permission.
  22397. + *
  22398. + * ALTERNATIVELY, this software may be distributed under the terms of the
  22399. + * GNU General Public License ("GPL") version 2, as published by the Free
  22400. + * Software Foundation.
  22401. + *
  22402. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  22403. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  22404. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  22405. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  22406. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  22407. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  22408. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  22409. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  22410. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  22411. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22412. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22413. + */
  22414. +
  22415. +#include "vchiq_core.h"
  22416. +
  22417. +#define VCHIQ_SLOT_HANDLER_STACK 8192
  22418. +
  22419. +#define HANDLE_STATE_SHIFT 12
  22420. +
  22421. +#define SLOT_INFO_FROM_INDEX(state, index) (state->slot_info + (index))
  22422. +#define SLOT_DATA_FROM_INDEX(state, index) (state->slot_data + (index))
  22423. +#define SLOT_INDEX_FROM_DATA(state, data) \
  22424. + (((unsigned int)((char *)data - (char *)state->slot_data)) / \
  22425. + VCHIQ_SLOT_SIZE)
  22426. +#define SLOT_INDEX_FROM_INFO(state, info) \
  22427. + ((unsigned int)(info - state->slot_info))
  22428. +#define SLOT_QUEUE_INDEX_FROM_POS(pos) \
  22429. + ((int)((unsigned int)(pos) / VCHIQ_SLOT_SIZE))
  22430. +
  22431. +
  22432. +#define BULK_INDEX(x) (x & (VCHIQ_NUM_SERVICE_BULKS - 1))
  22433. +
  22434. +
  22435. +struct vchiq_open_payload {
  22436. + int fourcc;
  22437. + int client_id;
  22438. + short version;
  22439. + short version_min;
  22440. +};
  22441. +
  22442. +struct vchiq_openack_payload {
  22443. + short version;
  22444. +};
  22445. +
  22446. +/* we require this for consistency between endpoints */
  22447. +vchiq_static_assert(sizeof(VCHIQ_HEADER_T) == 8);
  22448. +vchiq_static_assert(IS_POW2(sizeof(VCHIQ_HEADER_T)));
  22449. +vchiq_static_assert(IS_POW2(VCHIQ_NUM_CURRENT_BULKS));
  22450. +vchiq_static_assert(IS_POW2(VCHIQ_NUM_SERVICE_BULKS));
  22451. +vchiq_static_assert(IS_POW2(VCHIQ_MAX_SERVICES));
  22452. +vchiq_static_assert(VCHIQ_VERSION >= VCHIQ_VERSION_MIN);
  22453. +
  22454. +/* Run time control of log level, based on KERN_XXX level. */
  22455. +int vchiq_core_log_level = VCHIQ_LOG_DEFAULT;
  22456. +int vchiq_core_msg_log_level = VCHIQ_LOG_DEFAULT;
  22457. +int vchiq_sync_log_level = VCHIQ_LOG_DEFAULT;
  22458. +
  22459. +static atomic_t pause_bulks_count = ATOMIC_INIT(0);
  22460. +
  22461. +static DEFINE_SPINLOCK(service_spinlock);
  22462. +DEFINE_SPINLOCK(bulk_waiter_spinlock);
  22463. +DEFINE_SPINLOCK(quota_spinlock);
  22464. +
  22465. +VCHIQ_STATE_T *vchiq_states[VCHIQ_MAX_STATES];
  22466. +static unsigned int handle_seq;
  22467. +
  22468. +static const char *const srvstate_names[] = {
  22469. + "FREE",
  22470. + "HIDDEN",
  22471. + "LISTENING",
  22472. + "OPENING",
  22473. + "OPEN",
  22474. + "OPENSYNC",
  22475. + "CLOSESENT",
  22476. + "CLOSERECVD",
  22477. + "CLOSEWAIT",
  22478. + "CLOSED"
  22479. +};
  22480. +
  22481. +static const char *const reason_names[] = {
  22482. + "SERVICE_OPENED",
  22483. + "SERVICE_CLOSED",
  22484. + "MESSAGE_AVAILABLE",
  22485. + "BULK_TRANSMIT_DONE",
  22486. + "BULK_RECEIVE_DONE",
  22487. + "BULK_TRANSMIT_ABORTED",
  22488. + "BULK_RECEIVE_ABORTED"
  22489. +};
  22490. +
  22491. +static const char *const conn_state_names[] = {
  22492. + "DISCONNECTED",
  22493. + "CONNECTING",
  22494. + "CONNECTED",
  22495. + "PAUSING",
  22496. + "PAUSE_SENT",
  22497. + "PAUSED",
  22498. + "RESUMING",
  22499. + "PAUSE_TIMEOUT",
  22500. + "RESUME_TIMEOUT"
  22501. +};
  22502. +
  22503. +
  22504. +static void
  22505. +release_message_sync(VCHIQ_STATE_T *state, VCHIQ_HEADER_T *header);
  22506. +
  22507. +static const char *msg_type_str(unsigned int msg_type)
  22508. +{
  22509. + switch (msg_type) {
  22510. + case VCHIQ_MSG_PADDING: return "PADDING";
  22511. + case VCHIQ_MSG_CONNECT: return "CONNECT";
  22512. + case VCHIQ_MSG_OPEN: return "OPEN";
  22513. + case VCHIQ_MSG_OPENACK: return "OPENACK";
  22514. + case VCHIQ_MSG_CLOSE: return "CLOSE";
  22515. + case VCHIQ_MSG_DATA: return "DATA";
  22516. + case VCHIQ_MSG_BULK_RX: return "BULK_RX";
  22517. + case VCHIQ_MSG_BULK_TX: return "BULK_TX";
  22518. + case VCHIQ_MSG_BULK_RX_DONE: return "BULK_RX_DONE";
  22519. + case VCHIQ_MSG_BULK_TX_DONE: return "BULK_TX_DONE";
  22520. + case VCHIQ_MSG_PAUSE: return "PAUSE";
  22521. + case VCHIQ_MSG_RESUME: return "RESUME";
  22522. + case VCHIQ_MSG_REMOTE_USE: return "REMOTE_USE";
  22523. + case VCHIQ_MSG_REMOTE_RELEASE: return "REMOTE_RELEASE";
  22524. + case VCHIQ_MSG_REMOTE_USE_ACTIVE: return "REMOTE_USE_ACTIVE";
  22525. + }
  22526. + return "???";
  22527. +}
  22528. +
  22529. +static inline void
  22530. +vchiq_set_service_state(VCHIQ_SERVICE_T *service, int newstate)
  22531. +{
  22532. + vchiq_log_info(vchiq_core_log_level, "%d: srv:%d %s->%s",
  22533. + service->state->id, service->localport,
  22534. + srvstate_names[service->srvstate],
  22535. + srvstate_names[newstate]);
  22536. + service->srvstate = newstate;
  22537. +}
  22538. +
  22539. +VCHIQ_SERVICE_T *
  22540. +find_service_by_handle(VCHIQ_SERVICE_HANDLE_T handle)
  22541. +{
  22542. + VCHIQ_SERVICE_T *service;
  22543. +
  22544. + spin_lock(&service_spinlock);
  22545. + service = handle_to_service(handle);
  22546. + if (service && (service->srvstate != VCHIQ_SRVSTATE_FREE) &&
  22547. + (service->handle == handle)) {
  22548. + BUG_ON(service->ref_count == 0);
  22549. + service->ref_count++;
  22550. + } else
  22551. + service = NULL;
  22552. + spin_unlock(&service_spinlock);
  22553. +
  22554. + if (!service)
  22555. + vchiq_log_info(vchiq_core_log_level,
  22556. + "Invalid service handle 0x%x", handle);
  22557. +
  22558. + return service;
  22559. +}
  22560. +
  22561. +VCHIQ_SERVICE_T *
  22562. +find_service_by_port(VCHIQ_STATE_T *state, int localport)
  22563. +{
  22564. + VCHIQ_SERVICE_T *service = NULL;
  22565. + if ((unsigned int)localport <= VCHIQ_PORT_MAX) {
  22566. + spin_lock(&service_spinlock);
  22567. + service = state->services[localport];
  22568. + if (service && (service->srvstate != VCHIQ_SRVSTATE_FREE)) {
  22569. + BUG_ON(service->ref_count == 0);
  22570. + service->ref_count++;
  22571. + } else
  22572. + service = NULL;
  22573. + spin_unlock(&service_spinlock);
  22574. + }
  22575. +
  22576. + if (!service)
  22577. + vchiq_log_info(vchiq_core_log_level,
  22578. + "Invalid port %d", localport);
  22579. +
  22580. + return service;
  22581. +}
  22582. +
  22583. +VCHIQ_SERVICE_T *
  22584. +find_service_for_instance(VCHIQ_INSTANCE_T instance,
  22585. + VCHIQ_SERVICE_HANDLE_T handle) {
  22586. + VCHIQ_SERVICE_T *service;
  22587. +
  22588. + spin_lock(&service_spinlock);
  22589. + service = handle_to_service(handle);
  22590. + if (service && (service->srvstate != VCHIQ_SRVSTATE_FREE) &&
  22591. + (service->handle == handle) &&
  22592. + (service->instance == instance)) {
  22593. + BUG_ON(service->ref_count == 0);
  22594. + service->ref_count++;
  22595. + } else
  22596. + service = NULL;
  22597. + spin_unlock(&service_spinlock);
  22598. +
  22599. + if (!service)
  22600. + vchiq_log_info(vchiq_core_log_level,
  22601. + "Invalid service handle 0x%x", handle);
  22602. +
  22603. + return service;
  22604. +}
  22605. +
  22606. +VCHIQ_SERVICE_T *
  22607. +next_service_by_instance(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance,
  22608. + int *pidx)
  22609. +{
  22610. + VCHIQ_SERVICE_T *service = NULL;
  22611. + int idx = *pidx;
  22612. +
  22613. + spin_lock(&service_spinlock);
  22614. + while (idx < state->unused_service) {
  22615. + VCHIQ_SERVICE_T *srv = state->services[idx++];
  22616. + if (srv && (srv->srvstate != VCHIQ_SRVSTATE_FREE) &&
  22617. + (srv->instance == instance)) {
  22618. + service = srv;
  22619. + BUG_ON(service->ref_count == 0);
  22620. + service->ref_count++;
  22621. + break;
  22622. + }
  22623. + }
  22624. + spin_unlock(&service_spinlock);
  22625. +
  22626. + *pidx = idx;
  22627. +
  22628. + return service;
  22629. +}
  22630. +
  22631. +void
  22632. +lock_service(VCHIQ_SERVICE_T *service)
  22633. +{
  22634. + spin_lock(&service_spinlock);
  22635. + BUG_ON(!service || (service->ref_count == 0));
  22636. + if (service)
  22637. + service->ref_count++;
  22638. + spin_unlock(&service_spinlock);
  22639. +}
  22640. +
  22641. +void
  22642. +unlock_service(VCHIQ_SERVICE_T *service)
  22643. +{
  22644. + VCHIQ_STATE_T *state = service->state;
  22645. + spin_lock(&service_spinlock);
  22646. + BUG_ON(!service || (service->ref_count == 0));
  22647. + if (service && service->ref_count) {
  22648. + service->ref_count--;
  22649. + if (!service->ref_count) {
  22650. + BUG_ON(service->srvstate != VCHIQ_SRVSTATE_FREE);
  22651. + state->services[service->localport] = NULL;
  22652. + } else
  22653. + service = NULL;
  22654. + }
  22655. + spin_unlock(&service_spinlock);
  22656. +
  22657. + if (service && service->userdata_term)
  22658. + service->userdata_term(service->base.userdata);
  22659. +
  22660. + kfree(service);
  22661. +}
  22662. +
  22663. +int
  22664. +vchiq_get_client_id(VCHIQ_SERVICE_HANDLE_T handle)
  22665. +{
  22666. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  22667. + int id;
  22668. +
  22669. + id = service ? service->client_id : 0;
  22670. + if (service)
  22671. + unlock_service(service);
  22672. +
  22673. + return id;
  22674. +}
  22675. +
  22676. +void *
  22677. +vchiq_get_service_userdata(VCHIQ_SERVICE_HANDLE_T handle)
  22678. +{
  22679. + VCHIQ_SERVICE_T *service = handle_to_service(handle);
  22680. +
  22681. + return service ? service->base.userdata : NULL;
  22682. +}
  22683. +
  22684. +int
  22685. +vchiq_get_service_fourcc(VCHIQ_SERVICE_HANDLE_T handle)
  22686. +{
  22687. + VCHIQ_SERVICE_T *service = handle_to_service(handle);
  22688. +
  22689. + return service ? service->base.fourcc : 0;
  22690. +}
  22691. +
  22692. +static void
  22693. +mark_service_closing_internal(VCHIQ_SERVICE_T *service, int sh_thread)
  22694. +{
  22695. + VCHIQ_STATE_T *state = service->state;
  22696. + VCHIQ_SERVICE_QUOTA_T *service_quota;
  22697. +
  22698. + service->closing = 1;
  22699. +
  22700. + /* Synchronise with other threads. */
  22701. + mutex_lock(&state->recycle_mutex);
  22702. + mutex_unlock(&state->recycle_mutex);
  22703. + if (!sh_thread || (state->conn_state != VCHIQ_CONNSTATE_PAUSE_SENT)) {
  22704. + /* If we're pausing then the slot_mutex is held until resume
  22705. + * by the slot handler. Therefore don't try to acquire this
  22706. + * mutex if we're the slot handler and in the pause sent state.
  22707. + * We don't need to in this case anyway. */
  22708. + mutex_lock(&state->slot_mutex);
  22709. + mutex_unlock(&state->slot_mutex);
  22710. + }
  22711. +
  22712. + /* Unblock any sending thread. */
  22713. + service_quota = &state->service_quotas[service->localport];
  22714. + up(&service_quota->quota_event);
  22715. +}
  22716. +
  22717. +static void
  22718. +mark_service_closing(VCHIQ_SERVICE_T *service)
  22719. +{
  22720. + mark_service_closing_internal(service, 0);
  22721. +}
  22722. +
  22723. +static inline VCHIQ_STATUS_T
  22724. +make_service_callback(VCHIQ_SERVICE_T *service, VCHIQ_REASON_T reason,
  22725. + VCHIQ_HEADER_T *header, void *bulk_userdata)
  22726. +{
  22727. + VCHIQ_STATUS_T status;
  22728. + vchiq_log_trace(vchiq_core_log_level, "%d: callback:%d (%s, %x, %x)",
  22729. + service->state->id, service->localport, reason_names[reason],
  22730. + (unsigned int)header, (unsigned int)bulk_userdata);
  22731. + status = service->base.callback(reason, header, service->handle,
  22732. + bulk_userdata);
  22733. + if (status == VCHIQ_ERROR) {
  22734. + vchiq_log_warning(vchiq_core_log_level,
  22735. + "%d: ignoring ERROR from callback to service %x",
  22736. + service->state->id, service->handle);
  22737. + status = VCHIQ_SUCCESS;
  22738. + }
  22739. + return status;
  22740. +}
  22741. +
  22742. +inline void
  22743. +vchiq_set_conn_state(VCHIQ_STATE_T *state, VCHIQ_CONNSTATE_T newstate)
  22744. +{
  22745. + VCHIQ_CONNSTATE_T oldstate = state->conn_state;
  22746. + vchiq_log_info(vchiq_core_log_level, "%d: %s->%s", state->id,
  22747. + conn_state_names[oldstate],
  22748. + conn_state_names[newstate]);
  22749. + state->conn_state = newstate;
  22750. + vchiq_platform_conn_state_changed(state, oldstate, newstate);
  22751. +}
  22752. +
  22753. +static inline void
  22754. +remote_event_create(REMOTE_EVENT_T *event)
  22755. +{
  22756. + event->armed = 0;
  22757. + /* Don't clear the 'fired' flag because it may already have been set
  22758. + ** by the other side. */
  22759. + sema_init(event->event, 0);
  22760. +}
  22761. +
  22762. +static inline void
  22763. +remote_event_destroy(REMOTE_EVENT_T *event)
  22764. +{
  22765. + (void)event;
  22766. +}
  22767. +
  22768. +static inline int
  22769. +remote_event_wait(REMOTE_EVENT_T *event)
  22770. +{
  22771. + if (!event->fired) {
  22772. + event->armed = 1;
  22773. + dsb();
  22774. + if (!event->fired) {
  22775. + if (down_interruptible(event->event) != 0) {
  22776. + event->armed = 0;
  22777. + return 0;
  22778. + }
  22779. + }
  22780. + event->armed = 0;
  22781. + wmb();
  22782. + }
  22783. +
  22784. + event->fired = 0;
  22785. + return 1;
  22786. +}
  22787. +
  22788. +static inline void
  22789. +remote_event_signal_local(REMOTE_EVENT_T *event)
  22790. +{
  22791. + event->armed = 0;
  22792. + up(event->event);
  22793. +}
  22794. +
  22795. +static inline void
  22796. +remote_event_poll(REMOTE_EVENT_T *event)
  22797. +{
  22798. + if (event->fired && event->armed)
  22799. + remote_event_signal_local(event);
  22800. +}
  22801. +
  22802. +void
  22803. +remote_event_pollall(VCHIQ_STATE_T *state)
  22804. +{
  22805. + remote_event_poll(&state->local->sync_trigger);
  22806. + remote_event_poll(&state->local->sync_release);
  22807. + remote_event_poll(&state->local->trigger);
  22808. + remote_event_poll(&state->local->recycle);
  22809. +}
  22810. +
  22811. +/* Round up message sizes so that any space at the end of a slot is always big
  22812. +** enough for a header. This relies on header size being a power of two, which
  22813. +** has been verified earlier by a static assertion. */
  22814. +
  22815. +static inline unsigned int
  22816. +calc_stride(unsigned int size)
  22817. +{
  22818. + /* Allow room for the header */
  22819. + size += sizeof(VCHIQ_HEADER_T);
  22820. +
  22821. + /* Round up */
  22822. + return (size + sizeof(VCHIQ_HEADER_T) - 1) & ~(sizeof(VCHIQ_HEADER_T)
  22823. + - 1);
  22824. +}
  22825. +
  22826. +/* Called by the slot handler thread */
  22827. +static VCHIQ_SERVICE_T *
  22828. +get_listening_service(VCHIQ_STATE_T *state, int fourcc)
  22829. +{
  22830. + int i;
  22831. +
  22832. + WARN_ON(fourcc == VCHIQ_FOURCC_INVALID);
  22833. +
  22834. + for (i = 0; i < state->unused_service; i++) {
  22835. + VCHIQ_SERVICE_T *service = state->services[i];
  22836. + if (service &&
  22837. + (service->public_fourcc == fourcc) &&
  22838. + ((service->srvstate == VCHIQ_SRVSTATE_LISTENING) ||
  22839. + ((service->srvstate == VCHIQ_SRVSTATE_OPEN) &&
  22840. + (service->remoteport == VCHIQ_PORT_FREE)))) {
  22841. + lock_service(service);
  22842. + return service;
  22843. + }
  22844. + }
  22845. +
  22846. + return NULL;
  22847. +}
  22848. +
  22849. +/* Called by the slot handler thread */
  22850. +static VCHIQ_SERVICE_T *
  22851. +get_connected_service(VCHIQ_STATE_T *state, unsigned int port)
  22852. +{
  22853. + int i;
  22854. + for (i = 0; i < state->unused_service; i++) {
  22855. + VCHIQ_SERVICE_T *service = state->services[i];
  22856. + if (service && (service->srvstate == VCHIQ_SRVSTATE_OPEN)
  22857. + && (service->remoteport == port)) {
  22858. + lock_service(service);
  22859. + return service;
  22860. + }
  22861. + }
  22862. + return NULL;
  22863. +}
  22864. +
  22865. +inline void
  22866. +request_poll(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service, int poll_type)
  22867. +{
  22868. + uint32_t value;
  22869. +
  22870. + if (service) {
  22871. + do {
  22872. + value = atomic_read(&service->poll_flags);
  22873. + } while (atomic_cmpxchg(&service->poll_flags, value,
  22874. + value | (1 << poll_type)) != value);
  22875. +
  22876. + do {
  22877. + value = atomic_read(&state->poll_services[
  22878. + service->localport>>5]);
  22879. + } while (atomic_cmpxchg(
  22880. + &state->poll_services[service->localport>>5],
  22881. + value, value | (1 << (service->localport & 0x1f)))
  22882. + != value);
  22883. + }
  22884. +
  22885. + state->poll_needed = 1;
  22886. + wmb();
  22887. +
  22888. + /* ... and ensure the slot handler runs. */
  22889. + remote_event_signal_local(&state->local->trigger);
  22890. +}
  22891. +
  22892. +/* Called from queue_message, by the slot handler and application threads,
  22893. +** with slot_mutex held */
  22894. +static VCHIQ_HEADER_T *
  22895. +reserve_space(VCHIQ_STATE_T *state, int space, int is_blocking)
  22896. +{
  22897. + VCHIQ_SHARED_STATE_T *local = state->local;
  22898. + int tx_pos = state->local_tx_pos;
  22899. + int slot_space = VCHIQ_SLOT_SIZE - (tx_pos & VCHIQ_SLOT_MASK);
  22900. +
  22901. + if (space > slot_space) {
  22902. + VCHIQ_HEADER_T *header;
  22903. + /* Fill the remaining space with padding */
  22904. + WARN_ON(state->tx_data == NULL);
  22905. + header = (VCHIQ_HEADER_T *)
  22906. + (state->tx_data + (tx_pos & VCHIQ_SLOT_MASK));
  22907. + header->msgid = VCHIQ_MSGID_PADDING;
  22908. + header->size = slot_space - sizeof(VCHIQ_HEADER_T);
  22909. +
  22910. + tx_pos += slot_space;
  22911. + }
  22912. +
  22913. + /* If necessary, get the next slot. */
  22914. + if ((tx_pos & VCHIQ_SLOT_MASK) == 0) {
  22915. + int slot_index;
  22916. +
  22917. + /* If there is no free slot... */
  22918. +
  22919. + if (down_trylock(&state->slot_available_event) != 0) {
  22920. + /* ...wait for one. */
  22921. +
  22922. + VCHIQ_STATS_INC(state, slot_stalls);
  22923. +
  22924. + /* But first, flush through the last slot. */
  22925. + state->local_tx_pos = tx_pos;
  22926. + local->tx_pos = tx_pos;
  22927. + remote_event_signal(&state->remote->trigger);
  22928. +
  22929. + if (!is_blocking ||
  22930. + (down_interruptible(
  22931. + &state->slot_available_event) != 0))
  22932. + return NULL; /* No space available */
  22933. + }
  22934. +
  22935. + BUG_ON(tx_pos ==
  22936. + (state->slot_queue_available * VCHIQ_SLOT_SIZE));
  22937. +
  22938. + slot_index = local->slot_queue[
  22939. + SLOT_QUEUE_INDEX_FROM_POS(tx_pos) &
  22940. + VCHIQ_SLOT_QUEUE_MASK];
  22941. + state->tx_data =
  22942. + (char *)SLOT_DATA_FROM_INDEX(state, slot_index);
  22943. + }
  22944. +
  22945. + state->local_tx_pos = tx_pos + space;
  22946. +
  22947. + return (VCHIQ_HEADER_T *)(state->tx_data + (tx_pos & VCHIQ_SLOT_MASK));
  22948. +}
  22949. +
  22950. +/* Called by the recycle thread. */
  22951. +static void
  22952. +process_free_queue(VCHIQ_STATE_T *state)
  22953. +{
  22954. + VCHIQ_SHARED_STATE_T *local = state->local;
  22955. + BITSET_T service_found[BITSET_SIZE(VCHIQ_MAX_SERVICES)];
  22956. + int slot_queue_available;
  22957. +
  22958. + /* Use a read memory barrier to ensure that any state that may have
  22959. + ** been modified by another thread is not masked by stale prefetched
  22960. + ** values. */
  22961. + rmb();
  22962. +
  22963. + /* Find slots which have been freed by the other side, and return them
  22964. + ** to the available queue. */
  22965. + slot_queue_available = state->slot_queue_available;
  22966. +
  22967. + while (slot_queue_available != local->slot_queue_recycle) {
  22968. + unsigned int pos;
  22969. + int slot_index = local->slot_queue[slot_queue_available++ &
  22970. + VCHIQ_SLOT_QUEUE_MASK];
  22971. + char *data = (char *)SLOT_DATA_FROM_INDEX(state, slot_index);
  22972. + int data_found = 0;
  22973. +
  22974. + vchiq_log_trace(vchiq_core_log_level, "%d: pfq %d=%x %x %x",
  22975. + state->id, slot_index, (unsigned int)data,
  22976. + local->slot_queue_recycle, slot_queue_available);
  22977. +
  22978. + /* Initialise the bitmask for services which have used this
  22979. + ** slot */
  22980. + BITSET_ZERO(service_found);
  22981. +
  22982. + pos = 0;
  22983. +
  22984. + while (pos < VCHIQ_SLOT_SIZE) {
  22985. + VCHIQ_HEADER_T *header =
  22986. + (VCHIQ_HEADER_T *)(data + pos);
  22987. + int msgid = header->msgid;
  22988. + if (VCHIQ_MSG_TYPE(msgid) == VCHIQ_MSG_DATA) {
  22989. + int port = VCHIQ_MSG_SRCPORT(msgid);
  22990. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  22991. + &state->service_quotas[port];
  22992. + int count;
  22993. + spin_lock(&quota_spinlock);
  22994. + count = service_quota->message_use_count;
  22995. + if (count > 0)
  22996. + service_quota->message_use_count =
  22997. + count - 1;
  22998. + spin_unlock(&quota_spinlock);
  22999. +
  23000. + if (count == service_quota->message_quota)
  23001. + /* Signal the service that it
  23002. + ** has dropped below its quota
  23003. + */
  23004. + up(&service_quota->quota_event);
  23005. + else if (count == 0) {
  23006. + vchiq_log_error(vchiq_core_log_level,
  23007. + "service %d "
  23008. + "message_use_count=%d "
  23009. + "(header %x, msgid %x, "
  23010. + "header->msgid %x, "
  23011. + "header->size %x)",
  23012. + port,
  23013. + service_quota->
  23014. + message_use_count,
  23015. + (unsigned int)header, msgid,
  23016. + header->msgid,
  23017. + header->size);
  23018. + WARN(1, "invalid message use count\n");
  23019. + }
  23020. + if (!BITSET_IS_SET(service_found, port)) {
  23021. + /* Set the found bit for this service */
  23022. + BITSET_SET(service_found, port);
  23023. +
  23024. + spin_lock(&quota_spinlock);
  23025. + count = service_quota->slot_use_count;
  23026. + if (count > 0)
  23027. + service_quota->slot_use_count =
  23028. + count - 1;
  23029. + spin_unlock(&quota_spinlock);
  23030. +
  23031. + if (count > 0) {
  23032. + /* Signal the service in case
  23033. + ** it has dropped below its
  23034. + ** quota */
  23035. + up(&service_quota->quota_event);
  23036. + vchiq_log_trace(
  23037. + vchiq_core_log_level,
  23038. + "%d: pfq:%d %x@%x - "
  23039. + "slot_use->%d",
  23040. + state->id, port,
  23041. + header->size,
  23042. + (unsigned int)header,
  23043. + count - 1);
  23044. + } else {
  23045. + vchiq_log_error(
  23046. + vchiq_core_log_level,
  23047. + "service %d "
  23048. + "slot_use_count"
  23049. + "=%d (header %x"
  23050. + ", msgid %x, "
  23051. + "header->msgid"
  23052. + " %x, header->"
  23053. + "size %x)",
  23054. + port, count,
  23055. + (unsigned int)header,
  23056. + msgid,
  23057. + header->msgid,
  23058. + header->size);
  23059. + WARN(1, "bad slot use count\n");
  23060. + }
  23061. + }
  23062. +
  23063. + data_found = 1;
  23064. + }
  23065. +
  23066. + pos += calc_stride(header->size);
  23067. + if (pos > VCHIQ_SLOT_SIZE) {
  23068. + vchiq_log_error(vchiq_core_log_level,
  23069. + "pfq - pos %x: header %x, msgid %x, "
  23070. + "header->msgid %x, header->size %x",
  23071. + pos, (unsigned int)header, msgid,
  23072. + header->msgid, header->size);
  23073. + WARN(1, "invalid slot position\n");
  23074. + }
  23075. + }
  23076. +
  23077. + if (data_found) {
  23078. + int count;
  23079. + spin_lock(&quota_spinlock);
  23080. + count = state->data_use_count;
  23081. + if (count > 0)
  23082. + state->data_use_count =
  23083. + count - 1;
  23084. + spin_unlock(&quota_spinlock);
  23085. + if (count == state->data_quota)
  23086. + up(&state->data_quota_event);
  23087. + }
  23088. +
  23089. + state->slot_queue_available = slot_queue_available;
  23090. + up(&state->slot_available_event);
  23091. + }
  23092. +}
  23093. +
  23094. +/* Called by the slot handler and application threads */
  23095. +static VCHIQ_STATUS_T
  23096. +queue_message(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  23097. + int msgid, const VCHIQ_ELEMENT_T *elements,
  23098. + int count, int size, int is_blocking)
  23099. +{
  23100. + VCHIQ_SHARED_STATE_T *local;
  23101. + VCHIQ_SERVICE_QUOTA_T *service_quota = NULL;
  23102. + VCHIQ_HEADER_T *header;
  23103. + int type = VCHIQ_MSG_TYPE(msgid);
  23104. +
  23105. + unsigned int stride;
  23106. +
  23107. + local = state->local;
  23108. +
  23109. + stride = calc_stride(size);
  23110. +
  23111. + WARN_ON(!(stride <= VCHIQ_SLOT_SIZE));
  23112. +
  23113. + if ((type != VCHIQ_MSG_RESUME) &&
  23114. + (mutex_lock_interruptible(&state->slot_mutex) != 0))
  23115. + return VCHIQ_RETRY;
  23116. +
  23117. + if (type == VCHIQ_MSG_DATA) {
  23118. + int tx_end_index;
  23119. +
  23120. + BUG_ON(!service);
  23121. +
  23122. + if (service->closing) {
  23123. + /* The service has been closed */
  23124. + mutex_unlock(&state->slot_mutex);
  23125. + return VCHIQ_ERROR;
  23126. + }
  23127. +
  23128. + service_quota = &state->service_quotas[service->localport];
  23129. +
  23130. + spin_lock(&quota_spinlock);
  23131. +
  23132. + /* Ensure this service doesn't use more than its quota of
  23133. + ** messages or slots */
  23134. + tx_end_index = SLOT_QUEUE_INDEX_FROM_POS(
  23135. + state->local_tx_pos + stride - 1);
  23136. +
  23137. + /* Ensure data messages don't use more than their quota of
  23138. + ** slots */
  23139. + while ((tx_end_index != state->previous_data_index) &&
  23140. + (state->data_use_count == state->data_quota)) {
  23141. + VCHIQ_STATS_INC(state, data_stalls);
  23142. + spin_unlock(&quota_spinlock);
  23143. + mutex_unlock(&state->slot_mutex);
  23144. +
  23145. + if (down_interruptible(&state->data_quota_event)
  23146. + != 0)
  23147. + return VCHIQ_RETRY;
  23148. +
  23149. + mutex_lock(&state->slot_mutex);
  23150. + spin_lock(&quota_spinlock);
  23151. + tx_end_index = SLOT_QUEUE_INDEX_FROM_POS(
  23152. + state->local_tx_pos + stride - 1);
  23153. + if ((tx_end_index == state->previous_data_index) ||
  23154. + (state->data_use_count < state->data_quota)) {
  23155. + /* Pass the signal on to other waiters */
  23156. + up(&state->data_quota_event);
  23157. + break;
  23158. + }
  23159. + }
  23160. +
  23161. + while ((service_quota->message_use_count ==
  23162. + service_quota->message_quota) ||
  23163. + ((tx_end_index != service_quota->previous_tx_index) &&
  23164. + (service_quota->slot_use_count ==
  23165. + service_quota->slot_quota))) {
  23166. + spin_unlock(&quota_spinlock);
  23167. + vchiq_log_trace(vchiq_core_log_level,
  23168. + "%d: qm:%d %s,%x - quota stall "
  23169. + "(msg %d, slot %d)",
  23170. + state->id, service->localport,
  23171. + msg_type_str(type), size,
  23172. + service_quota->message_use_count,
  23173. + service_quota->slot_use_count);
  23174. + VCHIQ_SERVICE_STATS_INC(service, quota_stalls);
  23175. + mutex_unlock(&state->slot_mutex);
  23176. + if (down_interruptible(&service_quota->quota_event)
  23177. + != 0)
  23178. + return VCHIQ_RETRY;
  23179. + if (service->closing)
  23180. + return VCHIQ_ERROR;
  23181. + if (mutex_lock_interruptible(&state->slot_mutex) != 0)
  23182. + return VCHIQ_RETRY;
  23183. + if (service->srvstate != VCHIQ_SRVSTATE_OPEN) {
  23184. + /* The service has been closed */
  23185. + mutex_unlock(&state->slot_mutex);
  23186. + return VCHIQ_ERROR;
  23187. + }
  23188. + spin_lock(&quota_spinlock);
  23189. + tx_end_index = SLOT_QUEUE_INDEX_FROM_POS(
  23190. + state->local_tx_pos + stride - 1);
  23191. + }
  23192. +
  23193. + spin_unlock(&quota_spinlock);
  23194. + }
  23195. +
  23196. + header = reserve_space(state, stride, is_blocking);
  23197. +
  23198. + if (!header) {
  23199. + if (service)
  23200. + VCHIQ_SERVICE_STATS_INC(service, slot_stalls);
  23201. + mutex_unlock(&state->slot_mutex);
  23202. + return VCHIQ_RETRY;
  23203. + }
  23204. +
  23205. + if (type == VCHIQ_MSG_DATA) {
  23206. + int i, pos;
  23207. + int tx_end_index;
  23208. + int slot_use_count;
  23209. +
  23210. + vchiq_log_info(vchiq_core_log_level,
  23211. + "%d: qm %s@%x,%x (%d->%d)",
  23212. + state->id,
  23213. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  23214. + (unsigned int)header, size,
  23215. + VCHIQ_MSG_SRCPORT(msgid),
  23216. + VCHIQ_MSG_DSTPORT(msgid));
  23217. +
  23218. + BUG_ON(!service);
  23219. +
  23220. + for (i = 0, pos = 0; i < (unsigned int)count;
  23221. + pos += elements[i++].size)
  23222. + if (elements[i].size) {
  23223. + if (vchiq_copy_from_user
  23224. + (header->data + pos, elements[i].data,
  23225. + (size_t) elements[i].size) !=
  23226. + VCHIQ_SUCCESS) {
  23227. + mutex_unlock(&state->slot_mutex);
  23228. + VCHIQ_SERVICE_STATS_INC(service,
  23229. + error_count);
  23230. + return VCHIQ_ERROR;
  23231. + }
  23232. + if (i == 0) {
  23233. + if (vchiq_core_msg_log_level >=
  23234. + VCHIQ_LOG_INFO)
  23235. + vchiq_log_dump_mem("Sent", 0,
  23236. + header->data + pos,
  23237. + min(64u,
  23238. + elements[0].size));
  23239. + }
  23240. + }
  23241. +
  23242. + spin_lock(&quota_spinlock);
  23243. + service_quota->message_use_count++;
  23244. +
  23245. + tx_end_index =
  23246. + SLOT_QUEUE_INDEX_FROM_POS(state->local_tx_pos - 1);
  23247. +
  23248. + /* If this transmission can't fit in the last slot used by any
  23249. + ** service, the data_use_count must be increased. */
  23250. + if (tx_end_index != state->previous_data_index) {
  23251. + state->previous_data_index = tx_end_index;
  23252. + state->data_use_count++;
  23253. + }
  23254. +
  23255. + /* If this isn't the same slot last used by this service,
  23256. + ** the service's slot_use_count must be increased. */
  23257. + if (tx_end_index != service_quota->previous_tx_index) {
  23258. + service_quota->previous_tx_index = tx_end_index;
  23259. + slot_use_count = ++service_quota->slot_use_count;
  23260. + } else {
  23261. + slot_use_count = 0;
  23262. + }
  23263. +
  23264. + spin_unlock(&quota_spinlock);
  23265. +
  23266. + if (slot_use_count)
  23267. + vchiq_log_trace(vchiq_core_log_level,
  23268. + "%d: qm:%d %s,%x - slot_use->%d (hdr %p)",
  23269. + state->id, service->localport,
  23270. + msg_type_str(VCHIQ_MSG_TYPE(msgid)), size,
  23271. + slot_use_count, header);
  23272. +
  23273. + VCHIQ_SERVICE_STATS_INC(service, ctrl_tx_count);
  23274. + VCHIQ_SERVICE_STATS_ADD(service, ctrl_tx_bytes, size);
  23275. + } else {
  23276. + vchiq_log_info(vchiq_core_log_level,
  23277. + "%d: qm %s@%x,%x (%d->%d)", state->id,
  23278. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  23279. + (unsigned int)header, size,
  23280. + VCHIQ_MSG_SRCPORT(msgid),
  23281. + VCHIQ_MSG_DSTPORT(msgid));
  23282. + if (size != 0) {
  23283. + WARN_ON(!((count == 1) && (size == elements[0].size)));
  23284. + memcpy(header->data, elements[0].data,
  23285. + elements[0].size);
  23286. + }
  23287. + VCHIQ_STATS_INC(state, ctrl_tx_count);
  23288. + }
  23289. +
  23290. + header->msgid = msgid;
  23291. + header->size = size;
  23292. +
  23293. + {
  23294. + int svc_fourcc;
  23295. +
  23296. + svc_fourcc = service
  23297. + ? service->base.fourcc
  23298. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  23299. +
  23300. + vchiq_log_info(vchiq_core_msg_log_level,
  23301. + "Sent Msg %s(%u) to %c%c%c%c s:%u d:%d len:%d",
  23302. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  23303. + VCHIQ_MSG_TYPE(msgid),
  23304. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  23305. + VCHIQ_MSG_SRCPORT(msgid),
  23306. + VCHIQ_MSG_DSTPORT(msgid),
  23307. + size);
  23308. + }
  23309. +
  23310. + /* Make sure the new header is visible to the peer. */
  23311. + wmb();
  23312. +
  23313. + /* Make the new tx_pos visible to the peer. */
  23314. + local->tx_pos = state->local_tx_pos;
  23315. + wmb();
  23316. +
  23317. + if (service && (type == VCHIQ_MSG_CLOSE))
  23318. + vchiq_set_service_state(service, VCHIQ_SRVSTATE_CLOSESENT);
  23319. +
  23320. + if (VCHIQ_MSG_TYPE(msgid) != VCHIQ_MSG_PAUSE)
  23321. + mutex_unlock(&state->slot_mutex);
  23322. +
  23323. + remote_event_signal(&state->remote->trigger);
  23324. +
  23325. + return VCHIQ_SUCCESS;
  23326. +}
  23327. +
  23328. +/* Called by the slot handler and application threads */
  23329. +static VCHIQ_STATUS_T
  23330. +queue_message_sync(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  23331. + int msgid, const VCHIQ_ELEMENT_T *elements,
  23332. + int count, int size, int is_blocking)
  23333. +{
  23334. + VCHIQ_SHARED_STATE_T *local;
  23335. + VCHIQ_HEADER_T *header;
  23336. +
  23337. + local = state->local;
  23338. +
  23339. + if ((VCHIQ_MSG_TYPE(msgid) != VCHIQ_MSG_RESUME) &&
  23340. + (mutex_lock_interruptible(&state->sync_mutex) != 0))
  23341. + return VCHIQ_RETRY;
  23342. +
  23343. + remote_event_wait(&local->sync_release);
  23344. +
  23345. + rmb();
  23346. +
  23347. + header = (VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state,
  23348. + local->slot_sync);
  23349. +
  23350. + {
  23351. + int oldmsgid = header->msgid;
  23352. + if (oldmsgid != VCHIQ_MSGID_PADDING)
  23353. + vchiq_log_error(vchiq_core_log_level,
  23354. + "%d: qms - msgid %x, not PADDING",
  23355. + state->id, oldmsgid);
  23356. + }
  23357. +
  23358. + if (service) {
  23359. + int i, pos;
  23360. +
  23361. + vchiq_log_info(vchiq_sync_log_level,
  23362. + "%d: qms %s@%x,%x (%d->%d)", state->id,
  23363. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  23364. + (unsigned int)header, size,
  23365. + VCHIQ_MSG_SRCPORT(msgid),
  23366. + VCHIQ_MSG_DSTPORT(msgid));
  23367. +
  23368. + for (i = 0, pos = 0; i < (unsigned int)count;
  23369. + pos += elements[i++].size)
  23370. + if (elements[i].size) {
  23371. + if (vchiq_copy_from_user
  23372. + (header->data + pos, elements[i].data,
  23373. + (size_t) elements[i].size) !=
  23374. + VCHIQ_SUCCESS) {
  23375. + mutex_unlock(&state->sync_mutex);
  23376. + VCHIQ_SERVICE_STATS_INC(service,
  23377. + error_count);
  23378. + return VCHIQ_ERROR;
  23379. + }
  23380. + if (i == 0) {
  23381. + if (vchiq_sync_log_level >=
  23382. + VCHIQ_LOG_TRACE)
  23383. + vchiq_log_dump_mem("Sent Sync",
  23384. + 0, header->data + pos,
  23385. + min(64u,
  23386. + elements[0].size));
  23387. + }
  23388. + }
  23389. +
  23390. + VCHIQ_SERVICE_STATS_INC(service, ctrl_tx_count);
  23391. + VCHIQ_SERVICE_STATS_ADD(service, ctrl_tx_bytes, size);
  23392. + } else {
  23393. + vchiq_log_info(vchiq_sync_log_level,
  23394. + "%d: qms %s@%x,%x (%d->%d)", state->id,
  23395. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  23396. + (unsigned int)header, size,
  23397. + VCHIQ_MSG_SRCPORT(msgid),
  23398. + VCHIQ_MSG_DSTPORT(msgid));
  23399. + if (size != 0) {
  23400. + WARN_ON(!((count == 1) && (size == elements[0].size)));
  23401. + memcpy(header->data, elements[0].data,
  23402. + elements[0].size);
  23403. + }
  23404. + VCHIQ_STATS_INC(state, ctrl_tx_count);
  23405. + }
  23406. +
  23407. + header->size = size;
  23408. + header->msgid = msgid;
  23409. +
  23410. + if (vchiq_sync_log_level >= VCHIQ_LOG_TRACE) {
  23411. + int svc_fourcc;
  23412. +
  23413. + svc_fourcc = service
  23414. + ? service->base.fourcc
  23415. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  23416. +
  23417. + vchiq_log_trace(vchiq_sync_log_level,
  23418. + "Sent Sync Msg %s(%u) to %c%c%c%c s:%u d:%d len:%d",
  23419. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  23420. + VCHIQ_MSG_TYPE(msgid),
  23421. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  23422. + VCHIQ_MSG_SRCPORT(msgid),
  23423. + VCHIQ_MSG_DSTPORT(msgid),
  23424. + size);
  23425. + }
  23426. +
  23427. + /* Make sure the new header is visible to the peer. */
  23428. + wmb();
  23429. +
  23430. + remote_event_signal(&state->remote->sync_trigger);
  23431. +
  23432. + if (VCHIQ_MSG_TYPE(msgid) != VCHIQ_MSG_PAUSE)
  23433. + mutex_unlock(&state->sync_mutex);
  23434. +
  23435. + return VCHIQ_SUCCESS;
  23436. +}
  23437. +
  23438. +static inline void
  23439. +claim_slot(VCHIQ_SLOT_INFO_T *slot)
  23440. +{
  23441. + slot->use_count++;
  23442. +}
  23443. +
  23444. +static void
  23445. +release_slot(VCHIQ_STATE_T *state, VCHIQ_SLOT_INFO_T *slot_info,
  23446. + VCHIQ_HEADER_T *header, VCHIQ_SERVICE_T *service)
  23447. +{
  23448. + int release_count;
  23449. +
  23450. + mutex_lock(&state->recycle_mutex);
  23451. +
  23452. + if (header) {
  23453. + int msgid = header->msgid;
  23454. + if (((msgid & VCHIQ_MSGID_CLAIMED) == 0) ||
  23455. + (service && service->closing)) {
  23456. + mutex_unlock(&state->recycle_mutex);
  23457. + return;
  23458. + }
  23459. +
  23460. + /* Rewrite the message header to prevent a double
  23461. + ** release */
  23462. + header->msgid = msgid & ~VCHIQ_MSGID_CLAIMED;
  23463. + }
  23464. +
  23465. + release_count = slot_info->release_count;
  23466. + slot_info->release_count = ++release_count;
  23467. +
  23468. + if (release_count == slot_info->use_count) {
  23469. + int slot_queue_recycle;
  23470. + /* Add to the freed queue */
  23471. +
  23472. + /* A read barrier is necessary here to prevent speculative
  23473. + ** fetches of remote->slot_queue_recycle from overtaking the
  23474. + ** mutex. */
  23475. + rmb();
  23476. +
  23477. + slot_queue_recycle = state->remote->slot_queue_recycle;
  23478. + state->remote->slot_queue[slot_queue_recycle &
  23479. + VCHIQ_SLOT_QUEUE_MASK] =
  23480. + SLOT_INDEX_FROM_INFO(state, slot_info);
  23481. + state->remote->slot_queue_recycle = slot_queue_recycle + 1;
  23482. + vchiq_log_info(vchiq_core_log_level,
  23483. + "%d: release_slot %d - recycle->%x",
  23484. + state->id, SLOT_INDEX_FROM_INFO(state, slot_info),
  23485. + state->remote->slot_queue_recycle);
  23486. +
  23487. + /* A write barrier is necessary, but remote_event_signal
  23488. + ** contains one. */
  23489. + remote_event_signal(&state->remote->recycle);
  23490. + }
  23491. +
  23492. + mutex_unlock(&state->recycle_mutex);
  23493. +}
  23494. +
  23495. +/* Called by the slot handler - don't hold the bulk mutex */
  23496. +static VCHIQ_STATUS_T
  23497. +notify_bulks(VCHIQ_SERVICE_T *service, VCHIQ_BULK_QUEUE_T *queue,
  23498. + int retry_poll)
  23499. +{
  23500. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  23501. +
  23502. + vchiq_log_trace(vchiq_core_log_level,
  23503. + "%d: nb:%d %cx - p=%x rn=%x r=%x",
  23504. + service->state->id, service->localport,
  23505. + (queue == &service->bulk_tx) ? 't' : 'r',
  23506. + queue->process, queue->remote_notify, queue->remove);
  23507. +
  23508. + if (service->state->is_master) {
  23509. + while (queue->remote_notify != queue->process) {
  23510. + VCHIQ_BULK_T *bulk =
  23511. + &queue->bulks[BULK_INDEX(queue->remote_notify)];
  23512. + int msgtype = (bulk->dir == VCHIQ_BULK_TRANSMIT) ?
  23513. + VCHIQ_MSG_BULK_RX_DONE : VCHIQ_MSG_BULK_TX_DONE;
  23514. + int msgid = VCHIQ_MAKE_MSG(msgtype, service->localport,
  23515. + service->remoteport);
  23516. + VCHIQ_ELEMENT_T element = { &bulk->actual, 4 };
  23517. + /* Only reply to non-dummy bulk requests */
  23518. + if (bulk->remote_data) {
  23519. + status = queue_message(service->state, NULL,
  23520. + msgid, &element, 1, 4, 0);
  23521. + if (status != VCHIQ_SUCCESS)
  23522. + break;
  23523. + }
  23524. + queue->remote_notify++;
  23525. + }
  23526. + } else {
  23527. + queue->remote_notify = queue->process;
  23528. + }
  23529. +
  23530. + if (status == VCHIQ_SUCCESS) {
  23531. + while (queue->remove != queue->remote_notify) {
  23532. + VCHIQ_BULK_T *bulk =
  23533. + &queue->bulks[BULK_INDEX(queue->remove)];
  23534. +
  23535. + /* Only generate callbacks for non-dummy bulk
  23536. + ** requests, and non-terminated services */
  23537. + if (bulk->data && service->instance) {
  23538. + if (bulk->actual != VCHIQ_BULK_ACTUAL_ABORTED) {
  23539. + if (bulk->dir == VCHIQ_BULK_TRANSMIT) {
  23540. + VCHIQ_SERVICE_STATS_INC(service,
  23541. + bulk_tx_count);
  23542. + VCHIQ_SERVICE_STATS_ADD(service,
  23543. + bulk_tx_bytes,
  23544. + bulk->actual);
  23545. + } else {
  23546. + VCHIQ_SERVICE_STATS_INC(service,
  23547. + bulk_rx_count);
  23548. + VCHIQ_SERVICE_STATS_ADD(service,
  23549. + bulk_rx_bytes,
  23550. + bulk->actual);
  23551. + }
  23552. + } else {
  23553. + VCHIQ_SERVICE_STATS_INC(service,
  23554. + bulk_aborted_count);
  23555. + }
  23556. + if (bulk->mode == VCHIQ_BULK_MODE_BLOCKING) {
  23557. + struct bulk_waiter *waiter;
  23558. + spin_lock(&bulk_waiter_spinlock);
  23559. + waiter = bulk->userdata;
  23560. + if (waiter) {
  23561. + waiter->actual = bulk->actual;
  23562. + up(&waiter->event);
  23563. + }
  23564. + spin_unlock(&bulk_waiter_spinlock);
  23565. + } else if (bulk->mode ==
  23566. + VCHIQ_BULK_MODE_CALLBACK) {
  23567. + VCHIQ_REASON_T reason = (bulk->dir ==
  23568. + VCHIQ_BULK_TRANSMIT) ?
  23569. + ((bulk->actual ==
  23570. + VCHIQ_BULK_ACTUAL_ABORTED) ?
  23571. + VCHIQ_BULK_TRANSMIT_ABORTED :
  23572. + VCHIQ_BULK_TRANSMIT_DONE) :
  23573. + ((bulk->actual ==
  23574. + VCHIQ_BULK_ACTUAL_ABORTED) ?
  23575. + VCHIQ_BULK_RECEIVE_ABORTED :
  23576. + VCHIQ_BULK_RECEIVE_DONE);
  23577. + status = make_service_callback(service,
  23578. + reason, NULL, bulk->userdata);
  23579. + if (status == VCHIQ_RETRY)
  23580. + break;
  23581. + }
  23582. + }
  23583. +
  23584. + queue->remove++;
  23585. + up(&service->bulk_remove_event);
  23586. + }
  23587. + if (!retry_poll)
  23588. + status = VCHIQ_SUCCESS;
  23589. + }
  23590. +
  23591. + if (status == VCHIQ_RETRY)
  23592. + request_poll(service->state, service,
  23593. + (queue == &service->bulk_tx) ?
  23594. + VCHIQ_POLL_TXNOTIFY : VCHIQ_POLL_RXNOTIFY);
  23595. +
  23596. + return status;
  23597. +}
  23598. +
  23599. +/* Called by the slot handler thread */
  23600. +static void
  23601. +poll_services(VCHIQ_STATE_T *state)
  23602. +{
  23603. + int group, i;
  23604. +
  23605. + for (group = 0; group < BITSET_SIZE(state->unused_service); group++) {
  23606. + uint32_t flags;
  23607. + flags = atomic_xchg(&state->poll_services[group], 0);
  23608. + for (i = 0; flags; i++) {
  23609. + if (flags & (1 << i)) {
  23610. + VCHIQ_SERVICE_T *service =
  23611. + find_service_by_port(state,
  23612. + (group<<5) + i);
  23613. + uint32_t service_flags;
  23614. + flags &= ~(1 << i);
  23615. + if (!service)
  23616. + continue;
  23617. + service_flags =
  23618. + atomic_xchg(&service->poll_flags, 0);
  23619. + if (service_flags &
  23620. + (1 << VCHIQ_POLL_REMOVE)) {
  23621. + vchiq_log_info(vchiq_core_log_level,
  23622. + "%d: ps - remove %d<->%d",
  23623. + state->id, service->localport,
  23624. + service->remoteport);
  23625. +
  23626. + /* Make it look like a client, because
  23627. + it must be removed and not left in
  23628. + the LISTENING state. */
  23629. + service->public_fourcc =
  23630. + VCHIQ_FOURCC_INVALID;
  23631. +
  23632. + if (vchiq_close_service_internal(
  23633. + service, 0/*!close_recvd*/) !=
  23634. + VCHIQ_SUCCESS)
  23635. + request_poll(state, service,
  23636. + VCHIQ_POLL_REMOVE);
  23637. + } else if (service_flags &
  23638. + (1 << VCHIQ_POLL_TERMINATE)) {
  23639. + vchiq_log_info(vchiq_core_log_level,
  23640. + "%d: ps - terminate %d<->%d",
  23641. + state->id, service->localport,
  23642. + service->remoteport);
  23643. + if (vchiq_close_service_internal(
  23644. + service, 0/*!close_recvd*/) !=
  23645. + VCHIQ_SUCCESS)
  23646. + request_poll(state, service,
  23647. + VCHIQ_POLL_TERMINATE);
  23648. + }
  23649. + if (service_flags & (1 << VCHIQ_POLL_TXNOTIFY))
  23650. + notify_bulks(service,
  23651. + &service->bulk_tx,
  23652. + 1/*retry_poll*/);
  23653. + if (service_flags & (1 << VCHIQ_POLL_RXNOTIFY))
  23654. + notify_bulks(service,
  23655. + &service->bulk_rx,
  23656. + 1/*retry_poll*/);
  23657. + unlock_service(service);
  23658. + }
  23659. + }
  23660. + }
  23661. +}
  23662. +
  23663. +/* Called by the slot handler or application threads, holding the bulk mutex. */
  23664. +static int
  23665. +resolve_bulks(VCHIQ_SERVICE_T *service, VCHIQ_BULK_QUEUE_T *queue)
  23666. +{
  23667. + VCHIQ_STATE_T *state = service->state;
  23668. + int resolved = 0;
  23669. + int rc;
  23670. +
  23671. + while ((queue->process != queue->local_insert) &&
  23672. + (queue->process != queue->remote_insert)) {
  23673. + VCHIQ_BULK_T *bulk = &queue->bulks[BULK_INDEX(queue->process)];
  23674. +
  23675. + vchiq_log_trace(vchiq_core_log_level,
  23676. + "%d: rb:%d %cx - li=%x ri=%x p=%x",
  23677. + state->id, service->localport,
  23678. + (queue == &service->bulk_tx) ? 't' : 'r',
  23679. + queue->local_insert, queue->remote_insert,
  23680. + queue->process);
  23681. +
  23682. + WARN_ON(!((int)(queue->local_insert - queue->process) > 0));
  23683. + WARN_ON(!((int)(queue->remote_insert - queue->process) > 0));
  23684. +
  23685. + rc = mutex_lock_interruptible(&state->bulk_transfer_mutex);
  23686. + if (rc != 0)
  23687. + break;
  23688. +
  23689. + vchiq_transfer_bulk(bulk);
  23690. + mutex_unlock(&state->bulk_transfer_mutex);
  23691. +
  23692. + if (vchiq_core_msg_log_level >= VCHIQ_LOG_INFO) {
  23693. + const char *header = (queue == &service->bulk_tx) ?
  23694. + "Send Bulk to" : "Recv Bulk from";
  23695. + if (bulk->actual != VCHIQ_BULK_ACTUAL_ABORTED)
  23696. + vchiq_log_info(vchiq_core_msg_log_level,
  23697. + "%s %c%c%c%c d:%d len:%d %x<->%x",
  23698. + header,
  23699. + VCHIQ_FOURCC_AS_4CHARS(
  23700. + service->base.fourcc),
  23701. + service->remoteport,
  23702. + bulk->size,
  23703. + (unsigned int)bulk->data,
  23704. + (unsigned int)bulk->remote_data);
  23705. + else
  23706. + vchiq_log_info(vchiq_core_msg_log_level,
  23707. + "%s %c%c%c%c d:%d ABORTED - tx len:%d,"
  23708. + " rx len:%d %x<->%x",
  23709. + header,
  23710. + VCHIQ_FOURCC_AS_4CHARS(
  23711. + service->base.fourcc),
  23712. + service->remoteport,
  23713. + bulk->size,
  23714. + bulk->remote_size,
  23715. + (unsigned int)bulk->data,
  23716. + (unsigned int)bulk->remote_data);
  23717. + }
  23718. +
  23719. + vchiq_complete_bulk(bulk);
  23720. + queue->process++;
  23721. + resolved++;
  23722. + }
  23723. + return resolved;
  23724. +}
  23725. +
  23726. +/* Called with the bulk_mutex held */
  23727. +static void
  23728. +abort_outstanding_bulks(VCHIQ_SERVICE_T *service, VCHIQ_BULK_QUEUE_T *queue)
  23729. +{
  23730. + int is_tx = (queue == &service->bulk_tx);
  23731. + vchiq_log_trace(vchiq_core_log_level,
  23732. + "%d: aob:%d %cx - li=%x ri=%x p=%x",
  23733. + service->state->id, service->localport, is_tx ? 't' : 'r',
  23734. + queue->local_insert, queue->remote_insert, queue->process);
  23735. +
  23736. + WARN_ON(!((int)(queue->local_insert - queue->process) >= 0));
  23737. + WARN_ON(!((int)(queue->remote_insert - queue->process) >= 0));
  23738. +
  23739. + while ((queue->process != queue->local_insert) ||
  23740. + (queue->process != queue->remote_insert)) {
  23741. + VCHIQ_BULK_T *bulk = &queue->bulks[BULK_INDEX(queue->process)];
  23742. +
  23743. + if (queue->process == queue->remote_insert) {
  23744. + /* fabricate a matching dummy bulk */
  23745. + bulk->remote_data = NULL;
  23746. + bulk->remote_size = 0;
  23747. + queue->remote_insert++;
  23748. + }
  23749. +
  23750. + if (queue->process != queue->local_insert) {
  23751. + vchiq_complete_bulk(bulk);
  23752. +
  23753. + vchiq_log_info(vchiq_core_msg_log_level,
  23754. + "%s %c%c%c%c d:%d ABORTED - tx len:%d, "
  23755. + "rx len:%d",
  23756. + is_tx ? "Send Bulk to" : "Recv Bulk from",
  23757. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  23758. + service->remoteport,
  23759. + bulk->size,
  23760. + bulk->remote_size);
  23761. + } else {
  23762. + /* fabricate a matching dummy bulk */
  23763. + bulk->data = NULL;
  23764. + bulk->size = 0;
  23765. + bulk->actual = VCHIQ_BULK_ACTUAL_ABORTED;
  23766. + bulk->dir = is_tx ? VCHIQ_BULK_TRANSMIT :
  23767. + VCHIQ_BULK_RECEIVE;
  23768. + queue->local_insert++;
  23769. + }
  23770. +
  23771. + queue->process++;
  23772. + }
  23773. +}
  23774. +
  23775. +/* Called from the slot handler thread */
  23776. +static void
  23777. +pause_bulks(VCHIQ_STATE_T *state)
  23778. +{
  23779. + if (unlikely(atomic_inc_return(&pause_bulks_count) != 1)) {
  23780. + WARN_ON_ONCE(1);
  23781. + atomic_set(&pause_bulks_count, 1);
  23782. + return;
  23783. + }
  23784. +
  23785. + /* Block bulk transfers from all services */
  23786. + mutex_lock(&state->bulk_transfer_mutex);
  23787. +}
  23788. +
  23789. +/* Called from the slot handler thread */
  23790. +static void
  23791. +resume_bulks(VCHIQ_STATE_T *state)
  23792. +{
  23793. + int i;
  23794. + if (unlikely(atomic_dec_return(&pause_bulks_count) != 0)) {
  23795. + WARN_ON_ONCE(1);
  23796. + atomic_set(&pause_bulks_count, 0);
  23797. + return;
  23798. + }
  23799. +
  23800. + /* Allow bulk transfers from all services */
  23801. + mutex_unlock(&state->bulk_transfer_mutex);
  23802. +
  23803. + if (state->deferred_bulks == 0)
  23804. + return;
  23805. +
  23806. + /* Deal with any bulks which had to be deferred due to being in
  23807. + * paused state. Don't try to match up to number of deferred bulks
  23808. + * in case we've had something come and close the service in the
  23809. + * interim - just process all bulk queues for all services */
  23810. + vchiq_log_info(vchiq_core_log_level, "%s: processing %d deferred bulks",
  23811. + __func__, state->deferred_bulks);
  23812. +
  23813. + for (i = 0; i < state->unused_service; i++) {
  23814. + VCHIQ_SERVICE_T *service = state->services[i];
  23815. + int resolved_rx = 0;
  23816. + int resolved_tx = 0;
  23817. + if (!service || (service->srvstate != VCHIQ_SRVSTATE_OPEN))
  23818. + continue;
  23819. +
  23820. + mutex_lock(&service->bulk_mutex);
  23821. + resolved_rx = resolve_bulks(service, &service->bulk_rx);
  23822. + resolved_tx = resolve_bulks(service, &service->bulk_tx);
  23823. + mutex_unlock(&service->bulk_mutex);
  23824. + if (resolved_rx)
  23825. + notify_bulks(service, &service->bulk_rx, 1);
  23826. + if (resolved_tx)
  23827. + notify_bulks(service, &service->bulk_tx, 1);
  23828. + }
  23829. + state->deferred_bulks = 0;
  23830. +}
  23831. +
  23832. +static int
  23833. +parse_open(VCHIQ_STATE_T *state, VCHIQ_HEADER_T *header)
  23834. +{
  23835. + VCHIQ_SERVICE_T *service = NULL;
  23836. + int msgid, size;
  23837. + int type;
  23838. + unsigned int localport, remoteport;
  23839. +
  23840. + msgid = header->msgid;
  23841. + size = header->size;
  23842. + type = VCHIQ_MSG_TYPE(msgid);
  23843. + localport = VCHIQ_MSG_DSTPORT(msgid);
  23844. + remoteport = VCHIQ_MSG_SRCPORT(msgid);
  23845. + if (size >= sizeof(struct vchiq_open_payload)) {
  23846. + const struct vchiq_open_payload *payload =
  23847. + (struct vchiq_open_payload *)header->data;
  23848. + unsigned int fourcc;
  23849. +
  23850. + fourcc = payload->fourcc;
  23851. + vchiq_log_info(vchiq_core_log_level,
  23852. + "%d: prs OPEN@%x (%d->'%c%c%c%c')",
  23853. + state->id, (unsigned int)header,
  23854. + localport,
  23855. + VCHIQ_FOURCC_AS_4CHARS(fourcc));
  23856. +
  23857. + service = get_listening_service(state, fourcc);
  23858. +
  23859. + if (service) {
  23860. + /* A matching service exists */
  23861. + short version = payload->version;
  23862. + short version_min = payload->version_min;
  23863. + if ((service->version < version_min) ||
  23864. + (version < service->version_min)) {
  23865. + /* Version mismatch */
  23866. + vchiq_loud_error_header();
  23867. + vchiq_loud_error("%d: service %d (%c%c%c%c) "
  23868. + "version mismatch - local (%d, min %d)"
  23869. + " vs. remote (%d, min %d)",
  23870. + state->id, service->localport,
  23871. + VCHIQ_FOURCC_AS_4CHARS(fourcc),
  23872. + service->version, service->version_min,
  23873. + version, version_min);
  23874. + vchiq_loud_error_footer();
  23875. + unlock_service(service);
  23876. + service = NULL;
  23877. + goto fail_open;
  23878. + }
  23879. + service->peer_version = version;
  23880. +
  23881. + if (service->srvstate == VCHIQ_SRVSTATE_LISTENING) {
  23882. + struct vchiq_openack_payload ack_payload = {
  23883. + service->version
  23884. + };
  23885. + VCHIQ_ELEMENT_T body = {
  23886. + &ack_payload,
  23887. + sizeof(ack_payload)
  23888. + };
  23889. +
  23890. + /* Acknowledge the OPEN */
  23891. + if (service->sync) {
  23892. + if (queue_message_sync(state, NULL,
  23893. + VCHIQ_MAKE_MSG(
  23894. + VCHIQ_MSG_OPENACK,
  23895. + service->localport,
  23896. + remoteport),
  23897. + &body, 1, sizeof(ack_payload),
  23898. + 0) == VCHIQ_RETRY)
  23899. + goto bail_not_ready;
  23900. + } else {
  23901. + if (queue_message(state, NULL,
  23902. + VCHIQ_MAKE_MSG(
  23903. + VCHIQ_MSG_OPENACK,
  23904. + service->localport,
  23905. + remoteport),
  23906. + &body, 1, sizeof(ack_payload),
  23907. + 0) == VCHIQ_RETRY)
  23908. + goto bail_not_ready;
  23909. + }
  23910. +
  23911. + /* The service is now open */
  23912. + vchiq_set_service_state(service,
  23913. + service->sync ? VCHIQ_SRVSTATE_OPENSYNC
  23914. + : VCHIQ_SRVSTATE_OPEN);
  23915. + }
  23916. +
  23917. + service->remoteport = remoteport;
  23918. + service->client_id = ((int *)header->data)[1];
  23919. + if (make_service_callback(service, VCHIQ_SERVICE_OPENED,
  23920. + NULL, NULL) == VCHIQ_RETRY) {
  23921. + /* Bail out if not ready */
  23922. + service->remoteport = VCHIQ_PORT_FREE;
  23923. + goto bail_not_ready;
  23924. + }
  23925. +
  23926. + /* Success - the message has been dealt with */
  23927. + unlock_service(service);
  23928. + return 1;
  23929. + }
  23930. + }
  23931. +
  23932. +fail_open:
  23933. + /* No available service, or an invalid request - send a CLOSE */
  23934. + if (queue_message(state, NULL,
  23935. + VCHIQ_MAKE_MSG(VCHIQ_MSG_CLOSE, 0, VCHIQ_MSG_SRCPORT(msgid)),
  23936. + NULL, 0, 0, 0) == VCHIQ_RETRY)
  23937. + goto bail_not_ready;
  23938. +
  23939. + return 1;
  23940. +
  23941. +bail_not_ready:
  23942. + if (service)
  23943. + unlock_service(service);
  23944. +
  23945. + return 0;
  23946. +}
  23947. +
  23948. +/* Called by the slot handler thread */
  23949. +static void
  23950. +parse_rx_slots(VCHIQ_STATE_T *state)
  23951. +{
  23952. + VCHIQ_SHARED_STATE_T *remote = state->remote;
  23953. + VCHIQ_SERVICE_T *service = NULL;
  23954. + int tx_pos;
  23955. + DEBUG_INITIALISE(state->local)
  23956. +
  23957. + tx_pos = remote->tx_pos;
  23958. +
  23959. + while (state->rx_pos != tx_pos) {
  23960. + VCHIQ_HEADER_T *header;
  23961. + int msgid, size;
  23962. + int type;
  23963. + unsigned int localport, remoteport;
  23964. +
  23965. + DEBUG_TRACE(PARSE_LINE);
  23966. + if (!state->rx_data) {
  23967. + int rx_index;
  23968. + WARN_ON(!((state->rx_pos & VCHIQ_SLOT_MASK) == 0));
  23969. + rx_index = remote->slot_queue[
  23970. + SLOT_QUEUE_INDEX_FROM_POS(state->rx_pos) &
  23971. + VCHIQ_SLOT_QUEUE_MASK];
  23972. + state->rx_data = (char *)SLOT_DATA_FROM_INDEX(state,
  23973. + rx_index);
  23974. + state->rx_info = SLOT_INFO_FROM_INDEX(state, rx_index);
  23975. +
  23976. + /* Initialise use_count to one, and increment
  23977. + ** release_count at the end of the slot to avoid
  23978. + ** releasing the slot prematurely. */
  23979. + state->rx_info->use_count = 1;
  23980. + state->rx_info->release_count = 0;
  23981. + }
  23982. +
  23983. + header = (VCHIQ_HEADER_T *)(state->rx_data +
  23984. + (state->rx_pos & VCHIQ_SLOT_MASK));
  23985. + DEBUG_VALUE(PARSE_HEADER, (int)header);
  23986. + msgid = header->msgid;
  23987. + DEBUG_VALUE(PARSE_MSGID, msgid);
  23988. + size = header->size;
  23989. + type = VCHIQ_MSG_TYPE(msgid);
  23990. + localport = VCHIQ_MSG_DSTPORT(msgid);
  23991. + remoteport = VCHIQ_MSG_SRCPORT(msgid);
  23992. +
  23993. + if (type != VCHIQ_MSG_DATA)
  23994. + VCHIQ_STATS_INC(state, ctrl_rx_count);
  23995. +
  23996. + switch (type) {
  23997. + case VCHIQ_MSG_OPENACK:
  23998. + case VCHIQ_MSG_CLOSE:
  23999. + case VCHIQ_MSG_DATA:
  24000. + case VCHIQ_MSG_BULK_RX:
  24001. + case VCHIQ_MSG_BULK_TX:
  24002. + case VCHIQ_MSG_BULK_RX_DONE:
  24003. + case VCHIQ_MSG_BULK_TX_DONE:
  24004. + service = find_service_by_port(state, localport);
  24005. + if ((!service || service->remoteport != remoteport) &&
  24006. + (localport == 0) &&
  24007. + (type == VCHIQ_MSG_CLOSE)) {
  24008. + /* This could be a CLOSE from a client which
  24009. + hadn't yet received the OPENACK - look for
  24010. + the connected service */
  24011. + if (service)
  24012. + unlock_service(service);
  24013. + service = get_connected_service(state,
  24014. + remoteport);
  24015. + if (service)
  24016. + vchiq_log_warning(vchiq_core_log_level,
  24017. + "%d: prs %s@%x (%d->%d) - "
  24018. + "found connected service %d",
  24019. + state->id, msg_type_str(type),
  24020. + (unsigned int)header,
  24021. + remoteport, localport,
  24022. + service->localport);
  24023. + }
  24024. +
  24025. + if (!service) {
  24026. + vchiq_log_error(vchiq_core_log_level,
  24027. + "%d: prs %s@%x (%d->%d) - "
  24028. + "invalid/closed service %d",
  24029. + state->id, msg_type_str(type),
  24030. + (unsigned int)header,
  24031. + remoteport, localport, localport);
  24032. + goto skip_message;
  24033. + }
  24034. + break;
  24035. + default:
  24036. + break;
  24037. + }
  24038. +
  24039. + if (vchiq_core_msg_log_level >= VCHIQ_LOG_INFO) {
  24040. + int svc_fourcc;
  24041. +
  24042. + svc_fourcc = service
  24043. + ? service->base.fourcc
  24044. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  24045. + vchiq_log_info(vchiq_core_msg_log_level,
  24046. + "Rcvd Msg %s(%u) from %c%c%c%c s:%d d:%d "
  24047. + "len:%d",
  24048. + msg_type_str(type), type,
  24049. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  24050. + remoteport, localport, size);
  24051. + if (size > 0)
  24052. + vchiq_log_dump_mem("Rcvd", 0, header->data,
  24053. + min(64, size));
  24054. + }
  24055. +
  24056. + if (((unsigned int)header & VCHIQ_SLOT_MASK) + calc_stride(size)
  24057. + > VCHIQ_SLOT_SIZE) {
  24058. + vchiq_log_error(vchiq_core_log_level,
  24059. + "header %x (msgid %x) - size %x too big for "
  24060. + "slot",
  24061. + (unsigned int)header, (unsigned int)msgid,
  24062. + (unsigned int)size);
  24063. + WARN(1, "oversized for slot\n");
  24064. + }
  24065. +
  24066. + switch (type) {
  24067. + case VCHIQ_MSG_OPEN:
  24068. + WARN_ON(!(VCHIQ_MSG_DSTPORT(msgid) == 0));
  24069. + if (!parse_open(state, header))
  24070. + goto bail_not_ready;
  24071. + break;
  24072. + case VCHIQ_MSG_OPENACK:
  24073. + if (size >= sizeof(struct vchiq_openack_payload)) {
  24074. + const struct vchiq_openack_payload *payload =
  24075. + (struct vchiq_openack_payload *)
  24076. + header->data;
  24077. + service->peer_version = payload->version;
  24078. + }
  24079. + vchiq_log_info(vchiq_core_log_level,
  24080. + "%d: prs OPENACK@%x,%x (%d->%d) v:%d",
  24081. + state->id, (unsigned int)header, size,
  24082. + remoteport, localport, service->peer_version);
  24083. + if (service->srvstate ==
  24084. + VCHIQ_SRVSTATE_OPENING) {
  24085. + service->remoteport = remoteport;
  24086. + vchiq_set_service_state(service,
  24087. + VCHIQ_SRVSTATE_OPEN);
  24088. + up(&service->remove_event);
  24089. + } else
  24090. + vchiq_log_error(vchiq_core_log_level,
  24091. + "OPENACK received in state %s",
  24092. + srvstate_names[service->srvstate]);
  24093. + break;
  24094. + case VCHIQ_MSG_CLOSE:
  24095. + WARN_ON(size != 0); /* There should be no data */
  24096. +
  24097. + vchiq_log_info(vchiq_core_log_level,
  24098. + "%d: prs CLOSE@%x (%d->%d)",
  24099. + state->id, (unsigned int)header,
  24100. + remoteport, localport);
  24101. +
  24102. + mark_service_closing_internal(service, 1);
  24103. +
  24104. + if (vchiq_close_service_internal(service,
  24105. + 1/*close_recvd*/) == VCHIQ_RETRY)
  24106. + goto bail_not_ready;
  24107. +
  24108. + vchiq_log_info(vchiq_core_log_level,
  24109. + "Close Service %c%c%c%c s:%u d:%d",
  24110. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  24111. + service->localport,
  24112. + service->remoteport);
  24113. + break;
  24114. + case VCHIQ_MSG_DATA:
  24115. + vchiq_log_trace(vchiq_core_log_level,
  24116. + "%d: prs DATA@%x,%x (%d->%d)",
  24117. + state->id, (unsigned int)header, size,
  24118. + remoteport, localport);
  24119. +
  24120. + if ((service->remoteport == remoteport)
  24121. + && (service->srvstate ==
  24122. + VCHIQ_SRVSTATE_OPEN)) {
  24123. + header->msgid = msgid | VCHIQ_MSGID_CLAIMED;
  24124. + claim_slot(state->rx_info);
  24125. + DEBUG_TRACE(PARSE_LINE);
  24126. + if (make_service_callback(service,
  24127. + VCHIQ_MESSAGE_AVAILABLE, header,
  24128. + NULL) == VCHIQ_RETRY) {
  24129. + DEBUG_TRACE(PARSE_LINE);
  24130. + goto bail_not_ready;
  24131. + }
  24132. + VCHIQ_SERVICE_STATS_INC(service, ctrl_rx_count);
  24133. + VCHIQ_SERVICE_STATS_ADD(service, ctrl_rx_bytes,
  24134. + size);
  24135. + } else {
  24136. + VCHIQ_STATS_INC(state, error_count);
  24137. + }
  24138. + break;
  24139. + case VCHIQ_MSG_CONNECT:
  24140. + vchiq_log_info(vchiq_core_log_level,
  24141. + "%d: prs CONNECT@%x",
  24142. + state->id, (unsigned int)header);
  24143. + up(&state->connect);
  24144. + break;
  24145. + case VCHIQ_MSG_BULK_RX:
  24146. + case VCHIQ_MSG_BULK_TX: {
  24147. + VCHIQ_BULK_QUEUE_T *queue;
  24148. + WARN_ON(!state->is_master);
  24149. + queue = (type == VCHIQ_MSG_BULK_RX) ?
  24150. + &service->bulk_tx : &service->bulk_rx;
  24151. + if ((service->remoteport == remoteport)
  24152. + && (service->srvstate ==
  24153. + VCHIQ_SRVSTATE_OPEN)) {
  24154. + VCHIQ_BULK_T *bulk;
  24155. + int resolved = 0;
  24156. +
  24157. + DEBUG_TRACE(PARSE_LINE);
  24158. + if (mutex_lock_interruptible(
  24159. + &service->bulk_mutex) != 0) {
  24160. + DEBUG_TRACE(PARSE_LINE);
  24161. + goto bail_not_ready;
  24162. + }
  24163. +
  24164. + WARN_ON(!(queue->remote_insert < queue->remove +
  24165. + VCHIQ_NUM_SERVICE_BULKS));
  24166. + bulk = &queue->bulks[
  24167. + BULK_INDEX(queue->remote_insert)];
  24168. + bulk->remote_data =
  24169. + (void *)((int *)header->data)[0];
  24170. + bulk->remote_size = ((int *)header->data)[1];
  24171. + wmb();
  24172. +
  24173. + vchiq_log_info(vchiq_core_log_level,
  24174. + "%d: prs %s@%x (%d->%d) %x@%x",
  24175. + state->id, msg_type_str(type),
  24176. + (unsigned int)header,
  24177. + remoteport, localport,
  24178. + bulk->remote_size,
  24179. + (unsigned int)bulk->remote_data);
  24180. +
  24181. + queue->remote_insert++;
  24182. +
  24183. + if (atomic_read(&pause_bulks_count)) {
  24184. + state->deferred_bulks++;
  24185. + vchiq_log_info(vchiq_core_log_level,
  24186. + "%s: deferring bulk (%d)",
  24187. + __func__,
  24188. + state->deferred_bulks);
  24189. + if (state->conn_state !=
  24190. + VCHIQ_CONNSTATE_PAUSE_SENT)
  24191. + vchiq_log_error(
  24192. + vchiq_core_log_level,
  24193. + "%s: bulks paused in "
  24194. + "unexpected state %s",
  24195. + __func__,
  24196. + conn_state_names[
  24197. + state->conn_state]);
  24198. + } else if (state->conn_state ==
  24199. + VCHIQ_CONNSTATE_CONNECTED) {
  24200. + DEBUG_TRACE(PARSE_LINE);
  24201. + resolved = resolve_bulks(service,
  24202. + queue);
  24203. + }
  24204. +
  24205. + mutex_unlock(&service->bulk_mutex);
  24206. + if (resolved)
  24207. + notify_bulks(service, queue,
  24208. + 1/*retry_poll*/);
  24209. + }
  24210. + } break;
  24211. + case VCHIQ_MSG_BULK_RX_DONE:
  24212. + case VCHIQ_MSG_BULK_TX_DONE:
  24213. + WARN_ON(state->is_master);
  24214. + if ((service->remoteport == remoteport)
  24215. + && (service->srvstate !=
  24216. + VCHIQ_SRVSTATE_FREE)) {
  24217. + VCHIQ_BULK_QUEUE_T *queue;
  24218. + VCHIQ_BULK_T *bulk;
  24219. +
  24220. + queue = (type == VCHIQ_MSG_BULK_RX_DONE) ?
  24221. + &service->bulk_rx : &service->bulk_tx;
  24222. +
  24223. + DEBUG_TRACE(PARSE_LINE);
  24224. + if (mutex_lock_interruptible(
  24225. + &service->bulk_mutex) != 0) {
  24226. + DEBUG_TRACE(PARSE_LINE);
  24227. + goto bail_not_ready;
  24228. + }
  24229. + if ((int)(queue->remote_insert -
  24230. + queue->local_insert) >= 0) {
  24231. + vchiq_log_error(vchiq_core_log_level,
  24232. + "%d: prs %s@%x (%d->%d) "
  24233. + "unexpected (ri=%d,li=%d)",
  24234. + state->id, msg_type_str(type),
  24235. + (unsigned int)header,
  24236. + remoteport, localport,
  24237. + queue->remote_insert,
  24238. + queue->local_insert);
  24239. + mutex_unlock(&service->bulk_mutex);
  24240. + break;
  24241. + }
  24242. +
  24243. + BUG_ON(queue->process == queue->local_insert);
  24244. + BUG_ON(queue->process != queue->remote_insert);
  24245. +
  24246. + bulk = &queue->bulks[
  24247. + BULK_INDEX(queue->remote_insert)];
  24248. + bulk->actual = *(int *)header->data;
  24249. + queue->remote_insert++;
  24250. +
  24251. + vchiq_log_info(vchiq_core_log_level,
  24252. + "%d: prs %s@%x (%d->%d) %x@%x",
  24253. + state->id, msg_type_str(type),
  24254. + (unsigned int)header,
  24255. + remoteport, localport,
  24256. + bulk->actual, (unsigned int)bulk->data);
  24257. +
  24258. + vchiq_log_trace(vchiq_core_log_level,
  24259. + "%d: prs:%d %cx li=%x ri=%x p=%x",
  24260. + state->id, localport,
  24261. + (type == VCHIQ_MSG_BULK_RX_DONE) ?
  24262. + 'r' : 't',
  24263. + queue->local_insert,
  24264. + queue->remote_insert, queue->process);
  24265. +
  24266. + DEBUG_TRACE(PARSE_LINE);
  24267. + WARN_ON(queue->process == queue->local_insert);
  24268. + vchiq_complete_bulk(bulk);
  24269. + queue->process++;
  24270. + mutex_unlock(&service->bulk_mutex);
  24271. + DEBUG_TRACE(PARSE_LINE);
  24272. + notify_bulks(service, queue, 1/*retry_poll*/);
  24273. + DEBUG_TRACE(PARSE_LINE);
  24274. + }
  24275. + break;
  24276. + case VCHIQ_MSG_PADDING:
  24277. + vchiq_log_trace(vchiq_core_log_level,
  24278. + "%d: prs PADDING@%x,%x",
  24279. + state->id, (unsigned int)header, size);
  24280. + break;
  24281. + case VCHIQ_MSG_PAUSE:
  24282. + /* If initiated, signal the application thread */
  24283. + vchiq_log_trace(vchiq_core_log_level,
  24284. + "%d: prs PAUSE@%x,%x",
  24285. + state->id, (unsigned int)header, size);
  24286. + if (state->conn_state == VCHIQ_CONNSTATE_PAUSED) {
  24287. + vchiq_log_error(vchiq_core_log_level,
  24288. + "%d: PAUSE received in state PAUSED",
  24289. + state->id);
  24290. + break;
  24291. + }
  24292. + if (state->conn_state != VCHIQ_CONNSTATE_PAUSE_SENT) {
  24293. + /* Send a PAUSE in response */
  24294. + if (queue_message(state, NULL,
  24295. + VCHIQ_MAKE_MSG(VCHIQ_MSG_PAUSE, 0, 0),
  24296. + NULL, 0, 0, 0) == VCHIQ_RETRY)
  24297. + goto bail_not_ready;
  24298. + if (state->is_master)
  24299. + pause_bulks(state);
  24300. + }
  24301. + /* At this point slot_mutex is held */
  24302. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_PAUSED);
  24303. + vchiq_platform_paused(state);
  24304. + break;
  24305. + case VCHIQ_MSG_RESUME:
  24306. + vchiq_log_trace(vchiq_core_log_level,
  24307. + "%d: prs RESUME@%x,%x",
  24308. + state->id, (unsigned int)header, size);
  24309. + /* Release the slot mutex */
  24310. + mutex_unlock(&state->slot_mutex);
  24311. + if (state->is_master)
  24312. + resume_bulks(state);
  24313. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTED);
  24314. + vchiq_platform_resumed(state);
  24315. + break;
  24316. +
  24317. + case VCHIQ_MSG_REMOTE_USE:
  24318. + vchiq_on_remote_use(state);
  24319. + break;
  24320. + case VCHIQ_MSG_REMOTE_RELEASE:
  24321. + vchiq_on_remote_release(state);
  24322. + break;
  24323. + case VCHIQ_MSG_REMOTE_USE_ACTIVE:
  24324. + vchiq_on_remote_use_active(state);
  24325. + break;
  24326. +
  24327. + default:
  24328. + vchiq_log_error(vchiq_core_log_level,
  24329. + "%d: prs invalid msgid %x@%x,%x",
  24330. + state->id, msgid, (unsigned int)header, size);
  24331. + WARN(1, "invalid message\n");
  24332. + break;
  24333. + }
  24334. +
  24335. +skip_message:
  24336. + if (service) {
  24337. + unlock_service(service);
  24338. + service = NULL;
  24339. + }
  24340. +
  24341. + state->rx_pos += calc_stride(size);
  24342. +
  24343. + DEBUG_TRACE(PARSE_LINE);
  24344. + /* Perform some housekeeping when the end of the slot is
  24345. + ** reached. */
  24346. + if ((state->rx_pos & VCHIQ_SLOT_MASK) == 0) {
  24347. + /* Remove the extra reference count. */
  24348. + release_slot(state, state->rx_info, NULL, NULL);
  24349. + state->rx_data = NULL;
  24350. + }
  24351. + }
  24352. +
  24353. +bail_not_ready:
  24354. + if (service)
  24355. + unlock_service(service);
  24356. +}
  24357. +
  24358. +/* Called by the slot handler thread */
  24359. +static int
  24360. +slot_handler_func(void *v)
  24361. +{
  24362. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  24363. + VCHIQ_SHARED_STATE_T *local = state->local;
  24364. + DEBUG_INITIALISE(local)
  24365. +
  24366. + while (1) {
  24367. + DEBUG_COUNT(SLOT_HANDLER_COUNT);
  24368. + DEBUG_TRACE(SLOT_HANDLER_LINE);
  24369. + remote_event_wait(&local->trigger);
  24370. +
  24371. + rmb();
  24372. +
  24373. + DEBUG_TRACE(SLOT_HANDLER_LINE);
  24374. + if (state->poll_needed) {
  24375. + /* Check if we need to suspend - may change our
  24376. + * conn_state */
  24377. + vchiq_platform_check_suspend(state);
  24378. +
  24379. + state->poll_needed = 0;
  24380. +
  24381. + /* Handle service polling and other rare conditions here
  24382. + ** out of the mainline code */
  24383. + switch (state->conn_state) {
  24384. + case VCHIQ_CONNSTATE_CONNECTED:
  24385. + /* Poll the services as requested */
  24386. + poll_services(state);
  24387. + break;
  24388. +
  24389. + case VCHIQ_CONNSTATE_PAUSING:
  24390. + if (state->is_master)
  24391. + pause_bulks(state);
  24392. + if (queue_message(state, NULL,
  24393. + VCHIQ_MAKE_MSG(VCHIQ_MSG_PAUSE, 0, 0),
  24394. + NULL, 0, 0, 0) != VCHIQ_RETRY) {
  24395. + vchiq_set_conn_state(state,
  24396. + VCHIQ_CONNSTATE_PAUSE_SENT);
  24397. + } else {
  24398. + if (state->is_master)
  24399. + resume_bulks(state);
  24400. + /* Retry later */
  24401. + state->poll_needed = 1;
  24402. + }
  24403. + break;
  24404. +
  24405. + case VCHIQ_CONNSTATE_PAUSED:
  24406. + vchiq_platform_resume(state);
  24407. + break;
  24408. +
  24409. + case VCHIQ_CONNSTATE_RESUMING:
  24410. + if (queue_message(state, NULL,
  24411. + VCHIQ_MAKE_MSG(VCHIQ_MSG_RESUME, 0, 0),
  24412. + NULL, 0, 0, 0) != VCHIQ_RETRY) {
  24413. + if (state->is_master)
  24414. + resume_bulks(state);
  24415. + vchiq_set_conn_state(state,
  24416. + VCHIQ_CONNSTATE_CONNECTED);
  24417. + vchiq_platform_resumed(state);
  24418. + } else {
  24419. + /* This should really be impossible,
  24420. + ** since the PAUSE should have flushed
  24421. + ** through outstanding messages. */
  24422. + vchiq_log_error(vchiq_core_log_level,
  24423. + "Failed to send RESUME "
  24424. + "message");
  24425. + BUG();
  24426. + }
  24427. + break;
  24428. +
  24429. + case VCHIQ_CONNSTATE_PAUSE_TIMEOUT:
  24430. + case VCHIQ_CONNSTATE_RESUME_TIMEOUT:
  24431. + vchiq_platform_handle_timeout(state);
  24432. + break;
  24433. + default:
  24434. + break;
  24435. + }
  24436. +
  24437. +
  24438. + }
  24439. +
  24440. + DEBUG_TRACE(SLOT_HANDLER_LINE);
  24441. + parse_rx_slots(state);
  24442. + }
  24443. + return 0;
  24444. +}
  24445. +
  24446. +
  24447. +/* Called by the recycle thread */
  24448. +static int
  24449. +recycle_func(void *v)
  24450. +{
  24451. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  24452. + VCHIQ_SHARED_STATE_T *local = state->local;
  24453. +
  24454. + while (1) {
  24455. + remote_event_wait(&local->recycle);
  24456. +
  24457. + process_free_queue(state);
  24458. + }
  24459. + return 0;
  24460. +}
  24461. +
  24462. +
  24463. +/* Called by the sync thread */
  24464. +static int
  24465. +sync_func(void *v)
  24466. +{
  24467. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  24468. + VCHIQ_SHARED_STATE_T *local = state->local;
  24469. + VCHIQ_HEADER_T *header = (VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state,
  24470. + state->remote->slot_sync);
  24471. +
  24472. + while (1) {
  24473. + VCHIQ_SERVICE_T *service;
  24474. + int msgid, size;
  24475. + int type;
  24476. + unsigned int localport, remoteport;
  24477. +
  24478. + remote_event_wait(&local->sync_trigger);
  24479. +
  24480. + rmb();
  24481. +
  24482. + msgid = header->msgid;
  24483. + size = header->size;
  24484. + type = VCHIQ_MSG_TYPE(msgid);
  24485. + localport = VCHIQ_MSG_DSTPORT(msgid);
  24486. + remoteport = VCHIQ_MSG_SRCPORT(msgid);
  24487. +
  24488. + service = find_service_by_port(state, localport);
  24489. +
  24490. + if (!service) {
  24491. + vchiq_log_error(vchiq_sync_log_level,
  24492. + "%d: sf %s@%x (%d->%d) - "
  24493. + "invalid/closed service %d",
  24494. + state->id, msg_type_str(type),
  24495. + (unsigned int)header,
  24496. + remoteport, localport, localport);
  24497. + release_message_sync(state, header);
  24498. + continue;
  24499. + }
  24500. +
  24501. + if (vchiq_sync_log_level >= VCHIQ_LOG_TRACE) {
  24502. + int svc_fourcc;
  24503. +
  24504. + svc_fourcc = service
  24505. + ? service->base.fourcc
  24506. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  24507. + vchiq_log_trace(vchiq_sync_log_level,
  24508. + "Rcvd Msg %s from %c%c%c%c s:%d d:%d len:%d",
  24509. + msg_type_str(type),
  24510. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  24511. + remoteport, localport, size);
  24512. + if (size > 0)
  24513. + vchiq_log_dump_mem("Rcvd", 0, header->data,
  24514. + min(64, size));
  24515. + }
  24516. +
  24517. + switch (type) {
  24518. + case VCHIQ_MSG_OPENACK:
  24519. + if (size >= sizeof(struct vchiq_openack_payload)) {
  24520. + const struct vchiq_openack_payload *payload =
  24521. + (struct vchiq_openack_payload *)
  24522. + header->data;
  24523. + service->peer_version = payload->version;
  24524. + }
  24525. + vchiq_log_info(vchiq_sync_log_level,
  24526. + "%d: sf OPENACK@%x,%x (%d->%d) v:%d",
  24527. + state->id, (unsigned int)header, size,
  24528. + remoteport, localport, service->peer_version);
  24529. + if (service->srvstate == VCHIQ_SRVSTATE_OPENING) {
  24530. + service->remoteport = remoteport;
  24531. + vchiq_set_service_state(service,
  24532. + VCHIQ_SRVSTATE_OPENSYNC);
  24533. + up(&service->remove_event);
  24534. + }
  24535. + release_message_sync(state, header);
  24536. + break;
  24537. +
  24538. + case VCHIQ_MSG_DATA:
  24539. + vchiq_log_trace(vchiq_sync_log_level,
  24540. + "%d: sf DATA@%x,%x (%d->%d)",
  24541. + state->id, (unsigned int)header, size,
  24542. + remoteport, localport);
  24543. +
  24544. + if ((service->remoteport == remoteport) &&
  24545. + (service->srvstate ==
  24546. + VCHIQ_SRVSTATE_OPENSYNC)) {
  24547. + if (make_service_callback(service,
  24548. + VCHIQ_MESSAGE_AVAILABLE, header,
  24549. + NULL) == VCHIQ_RETRY)
  24550. + vchiq_log_error(vchiq_sync_log_level,
  24551. + "synchronous callback to "
  24552. + "service %d returns "
  24553. + "VCHIQ_RETRY",
  24554. + localport);
  24555. + }
  24556. + break;
  24557. +
  24558. + default:
  24559. + vchiq_log_error(vchiq_sync_log_level,
  24560. + "%d: sf unexpected msgid %x@%x,%x",
  24561. + state->id, msgid, (unsigned int)header, size);
  24562. + release_message_sync(state, header);
  24563. + break;
  24564. + }
  24565. +
  24566. + unlock_service(service);
  24567. + }
  24568. +
  24569. + return 0;
  24570. +}
  24571. +
  24572. +
  24573. +static void
  24574. +init_bulk_queue(VCHIQ_BULK_QUEUE_T *queue)
  24575. +{
  24576. + queue->local_insert = 0;
  24577. + queue->remote_insert = 0;
  24578. + queue->process = 0;
  24579. + queue->remote_notify = 0;
  24580. + queue->remove = 0;
  24581. +}
  24582. +
  24583. +
  24584. +inline const char *
  24585. +get_conn_state_name(VCHIQ_CONNSTATE_T conn_state)
  24586. +{
  24587. + return conn_state_names[conn_state];
  24588. +}
  24589. +
  24590. +
  24591. +VCHIQ_SLOT_ZERO_T *
  24592. +vchiq_init_slots(void *mem_base, int mem_size)
  24593. +{
  24594. + int mem_align = (VCHIQ_SLOT_SIZE - (int)mem_base) & VCHIQ_SLOT_MASK;
  24595. + VCHIQ_SLOT_ZERO_T *slot_zero =
  24596. + (VCHIQ_SLOT_ZERO_T *)((char *)mem_base + mem_align);
  24597. + int num_slots = (mem_size - mem_align)/VCHIQ_SLOT_SIZE;
  24598. + int first_data_slot = VCHIQ_SLOT_ZERO_SLOTS;
  24599. +
  24600. + /* Ensure there is enough memory to run an absolutely minimum system */
  24601. + num_slots -= first_data_slot;
  24602. +
  24603. + if (num_slots < 4) {
  24604. + vchiq_log_error(vchiq_core_log_level,
  24605. + "vchiq_init_slots - insufficient memory %x bytes",
  24606. + mem_size);
  24607. + return NULL;
  24608. + }
  24609. +
  24610. + memset(slot_zero, 0, sizeof(VCHIQ_SLOT_ZERO_T));
  24611. +
  24612. + slot_zero->magic = VCHIQ_MAGIC;
  24613. + slot_zero->version = VCHIQ_VERSION;
  24614. + slot_zero->version_min = VCHIQ_VERSION_MIN;
  24615. + slot_zero->slot_zero_size = sizeof(VCHIQ_SLOT_ZERO_T);
  24616. + slot_zero->slot_size = VCHIQ_SLOT_SIZE;
  24617. + slot_zero->max_slots = VCHIQ_MAX_SLOTS;
  24618. + slot_zero->max_slots_per_side = VCHIQ_MAX_SLOTS_PER_SIDE;
  24619. +
  24620. + slot_zero->master.slot_sync = first_data_slot;
  24621. + slot_zero->master.slot_first = first_data_slot + 1;
  24622. + slot_zero->master.slot_last = first_data_slot + (num_slots/2) - 1;
  24623. + slot_zero->slave.slot_sync = first_data_slot + (num_slots/2);
  24624. + slot_zero->slave.slot_first = first_data_slot + (num_slots/2) + 1;
  24625. + slot_zero->slave.slot_last = first_data_slot + num_slots - 1;
  24626. +
  24627. + return slot_zero;
  24628. +}
  24629. +
  24630. +VCHIQ_STATUS_T
  24631. +vchiq_init_state(VCHIQ_STATE_T *state, VCHIQ_SLOT_ZERO_T *slot_zero,
  24632. + int is_master)
  24633. +{
  24634. + VCHIQ_SHARED_STATE_T *local;
  24635. + VCHIQ_SHARED_STATE_T *remote;
  24636. + VCHIQ_STATUS_T status;
  24637. + char threadname[10];
  24638. + static int id;
  24639. + int i;
  24640. +
  24641. + vchiq_log_warning(vchiq_core_log_level,
  24642. + "%s: slot_zero = 0x%08lx, is_master = %d",
  24643. + __func__, (unsigned long)slot_zero, is_master);
  24644. +
  24645. + /* Check the input configuration */
  24646. +
  24647. + if (slot_zero->magic != VCHIQ_MAGIC) {
  24648. + vchiq_loud_error_header();
  24649. + vchiq_loud_error("Invalid VCHIQ magic value found.");
  24650. + vchiq_loud_error("slot_zero=%x: magic=%x (expected %x)",
  24651. + (unsigned int)slot_zero, slot_zero->magic, VCHIQ_MAGIC);
  24652. + vchiq_loud_error_footer();
  24653. + return VCHIQ_ERROR;
  24654. + }
  24655. +
  24656. + if (slot_zero->version < VCHIQ_VERSION_MIN) {
  24657. + vchiq_loud_error_header();
  24658. + vchiq_loud_error("Incompatible VCHIQ versions found.");
  24659. + vchiq_loud_error("slot_zero=%x: VideoCore version=%d "
  24660. + "(minimum %d)",
  24661. + (unsigned int)slot_zero, slot_zero->version,
  24662. + VCHIQ_VERSION_MIN);
  24663. + vchiq_loud_error("Restart with a newer VideoCore image.");
  24664. + vchiq_loud_error_footer();
  24665. + return VCHIQ_ERROR;
  24666. + }
  24667. +
  24668. + if (VCHIQ_VERSION < slot_zero->version_min) {
  24669. + vchiq_loud_error_header();
  24670. + vchiq_loud_error("Incompatible VCHIQ versions found.");
  24671. + vchiq_loud_error("slot_zero=%x: version=%d (VideoCore "
  24672. + "minimum %d)",
  24673. + (unsigned int)slot_zero, VCHIQ_VERSION,
  24674. + slot_zero->version_min);
  24675. + vchiq_loud_error("Restart with a newer kernel.");
  24676. + vchiq_loud_error_footer();
  24677. + return VCHIQ_ERROR;
  24678. + }
  24679. +
  24680. + if ((slot_zero->slot_zero_size != sizeof(VCHIQ_SLOT_ZERO_T)) ||
  24681. + (slot_zero->slot_size != VCHIQ_SLOT_SIZE) ||
  24682. + (slot_zero->max_slots != VCHIQ_MAX_SLOTS) ||
  24683. + (slot_zero->max_slots_per_side != VCHIQ_MAX_SLOTS_PER_SIDE)) {
  24684. + vchiq_loud_error_header();
  24685. + if (slot_zero->slot_zero_size != sizeof(VCHIQ_SLOT_ZERO_T))
  24686. + vchiq_loud_error("slot_zero=%x: slot_zero_size=%x "
  24687. + "(expected %x)",
  24688. + (unsigned int)slot_zero,
  24689. + slot_zero->slot_zero_size,
  24690. + sizeof(VCHIQ_SLOT_ZERO_T));
  24691. + if (slot_zero->slot_size != VCHIQ_SLOT_SIZE)
  24692. + vchiq_loud_error("slot_zero=%x: slot_size=%d "
  24693. + "(expected %d",
  24694. + (unsigned int)slot_zero, slot_zero->slot_size,
  24695. + VCHIQ_SLOT_SIZE);
  24696. + if (slot_zero->max_slots != VCHIQ_MAX_SLOTS)
  24697. + vchiq_loud_error("slot_zero=%x: max_slots=%d "
  24698. + "(expected %d)",
  24699. + (unsigned int)slot_zero, slot_zero->max_slots,
  24700. + VCHIQ_MAX_SLOTS);
  24701. + if (slot_zero->max_slots_per_side != VCHIQ_MAX_SLOTS_PER_SIDE)
  24702. + vchiq_loud_error("slot_zero=%x: max_slots_per_side=%d "
  24703. + "(expected %d)",
  24704. + (unsigned int)slot_zero,
  24705. + slot_zero->max_slots_per_side,
  24706. + VCHIQ_MAX_SLOTS_PER_SIDE);
  24707. + vchiq_loud_error_footer();
  24708. + return VCHIQ_ERROR;
  24709. + }
  24710. +
  24711. + if (is_master) {
  24712. + local = &slot_zero->master;
  24713. + remote = &slot_zero->slave;
  24714. + } else {
  24715. + local = &slot_zero->slave;
  24716. + remote = &slot_zero->master;
  24717. + }
  24718. +
  24719. + if (local->initialised) {
  24720. + vchiq_loud_error_header();
  24721. + if (remote->initialised)
  24722. + vchiq_loud_error("local state has already been "
  24723. + "initialised");
  24724. + else
  24725. + vchiq_loud_error("master/slave mismatch - two %ss",
  24726. + is_master ? "master" : "slave");
  24727. + vchiq_loud_error_footer();
  24728. + return VCHIQ_ERROR;
  24729. + }
  24730. +
  24731. + memset(state, 0, sizeof(VCHIQ_STATE_T));
  24732. +
  24733. + state->id = id++;
  24734. + state->is_master = is_master;
  24735. +
  24736. + /*
  24737. + initialize shared state pointers
  24738. + */
  24739. +
  24740. + state->local = local;
  24741. + state->remote = remote;
  24742. + state->slot_data = (VCHIQ_SLOT_T *)slot_zero;
  24743. +
  24744. + /*
  24745. + initialize events and mutexes
  24746. + */
  24747. +
  24748. + sema_init(&state->connect, 0);
  24749. + mutex_init(&state->mutex);
  24750. + sema_init(&state->trigger_event, 0);
  24751. + sema_init(&state->recycle_event, 0);
  24752. + sema_init(&state->sync_trigger_event, 0);
  24753. + sema_init(&state->sync_release_event, 0);
  24754. +
  24755. + mutex_init(&state->slot_mutex);
  24756. + mutex_init(&state->recycle_mutex);
  24757. + mutex_init(&state->sync_mutex);
  24758. + mutex_init(&state->bulk_transfer_mutex);
  24759. +
  24760. + sema_init(&state->slot_available_event, 0);
  24761. + sema_init(&state->slot_remove_event, 0);
  24762. + sema_init(&state->data_quota_event, 0);
  24763. +
  24764. + state->slot_queue_available = 0;
  24765. +
  24766. + for (i = 0; i < VCHIQ_MAX_SERVICES; i++) {
  24767. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  24768. + &state->service_quotas[i];
  24769. + sema_init(&service_quota->quota_event, 0);
  24770. + }
  24771. +
  24772. + for (i = local->slot_first; i <= local->slot_last; i++) {
  24773. + local->slot_queue[state->slot_queue_available++] = i;
  24774. + up(&state->slot_available_event);
  24775. + }
  24776. +
  24777. + state->default_slot_quota = state->slot_queue_available/2;
  24778. + state->default_message_quota =
  24779. + min((unsigned short)(state->default_slot_quota * 256),
  24780. + (unsigned short)~0);
  24781. +
  24782. + state->previous_data_index = -1;
  24783. + state->data_use_count = 0;
  24784. + state->data_quota = state->slot_queue_available - 1;
  24785. +
  24786. + local->trigger.event = &state->trigger_event;
  24787. + remote_event_create(&local->trigger);
  24788. + local->tx_pos = 0;
  24789. +
  24790. + local->recycle.event = &state->recycle_event;
  24791. + remote_event_create(&local->recycle);
  24792. + local->slot_queue_recycle = state->slot_queue_available;
  24793. +
  24794. + local->sync_trigger.event = &state->sync_trigger_event;
  24795. + remote_event_create(&local->sync_trigger);
  24796. +
  24797. + local->sync_release.event = &state->sync_release_event;
  24798. + remote_event_create(&local->sync_release);
  24799. +
  24800. + /* At start-of-day, the slot is empty and available */
  24801. + ((VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state, local->slot_sync))->msgid
  24802. + = VCHIQ_MSGID_PADDING;
  24803. + remote_event_signal_local(&local->sync_release);
  24804. +
  24805. + local->debug[DEBUG_ENTRIES] = DEBUG_MAX;
  24806. +
  24807. + status = vchiq_platform_init_state(state);
  24808. +
  24809. + /*
  24810. + bring up slot handler thread
  24811. + */
  24812. + snprintf(threadname, sizeof(threadname), "VCHIQ-%d", state->id);
  24813. + state->slot_handler_thread = kthread_create(&slot_handler_func,
  24814. + (void *)state,
  24815. + threadname);
  24816. +
  24817. + if (state->slot_handler_thread == NULL) {
  24818. + vchiq_loud_error_header();
  24819. + vchiq_loud_error("couldn't create thread %s", threadname);
  24820. + vchiq_loud_error_footer();
  24821. + return VCHIQ_ERROR;
  24822. + }
  24823. + set_user_nice(state->slot_handler_thread, -19);
  24824. + wake_up_process(state->slot_handler_thread);
  24825. +
  24826. + snprintf(threadname, sizeof(threadname), "VCHIQr-%d", state->id);
  24827. + state->recycle_thread = kthread_create(&recycle_func,
  24828. + (void *)state,
  24829. + threadname);
  24830. + if (state->recycle_thread == NULL) {
  24831. + vchiq_loud_error_header();
  24832. + vchiq_loud_error("couldn't create thread %s", threadname);
  24833. + vchiq_loud_error_footer();
  24834. + return VCHIQ_ERROR;
  24835. + }
  24836. + set_user_nice(state->recycle_thread, -19);
  24837. + wake_up_process(state->recycle_thread);
  24838. +
  24839. + snprintf(threadname, sizeof(threadname), "VCHIQs-%d", state->id);
  24840. + state->sync_thread = kthread_create(&sync_func,
  24841. + (void *)state,
  24842. + threadname);
  24843. + if (state->sync_thread == NULL) {
  24844. + vchiq_loud_error_header();
  24845. + vchiq_loud_error("couldn't create thread %s", threadname);
  24846. + vchiq_loud_error_footer();
  24847. + return VCHIQ_ERROR;
  24848. + }
  24849. + set_user_nice(state->sync_thread, -20);
  24850. + wake_up_process(state->sync_thread);
  24851. +
  24852. + BUG_ON(state->id >= VCHIQ_MAX_STATES);
  24853. + vchiq_states[state->id] = state;
  24854. +
  24855. + /* Indicate readiness to the other side */
  24856. + local->initialised = 1;
  24857. +
  24858. + return status;
  24859. +}
  24860. +
  24861. +/* Called from application thread when a client or server service is created. */
  24862. +VCHIQ_SERVICE_T *
  24863. +vchiq_add_service_internal(VCHIQ_STATE_T *state,
  24864. + const VCHIQ_SERVICE_PARAMS_T *params, int srvstate,
  24865. + VCHIQ_INSTANCE_T instance, VCHIQ_USERDATA_TERM_T userdata_term)
  24866. +{
  24867. + VCHIQ_SERVICE_T *service;
  24868. +
  24869. + service = kmalloc(sizeof(VCHIQ_SERVICE_T), GFP_KERNEL);
  24870. + if (service) {
  24871. + service->base.fourcc = params->fourcc;
  24872. + service->base.callback = params->callback;
  24873. + service->base.userdata = params->userdata;
  24874. + service->handle = VCHIQ_SERVICE_HANDLE_INVALID;
  24875. + service->ref_count = 1;
  24876. + service->srvstate = VCHIQ_SRVSTATE_FREE;
  24877. + service->userdata_term = userdata_term;
  24878. + service->localport = VCHIQ_PORT_FREE;
  24879. + service->remoteport = VCHIQ_PORT_FREE;
  24880. +
  24881. + service->public_fourcc = (srvstate == VCHIQ_SRVSTATE_OPENING) ?
  24882. + VCHIQ_FOURCC_INVALID : params->fourcc;
  24883. + service->client_id = 0;
  24884. + service->auto_close = 1;
  24885. + service->sync = 0;
  24886. + service->closing = 0;
  24887. + atomic_set(&service->poll_flags, 0);
  24888. + service->version = params->version;
  24889. + service->version_min = params->version_min;
  24890. + service->state = state;
  24891. + service->instance = instance;
  24892. + service->service_use_count = 0;
  24893. + init_bulk_queue(&service->bulk_tx);
  24894. + init_bulk_queue(&service->bulk_rx);
  24895. + sema_init(&service->remove_event, 0);
  24896. + sema_init(&service->bulk_remove_event, 0);
  24897. + mutex_init(&service->bulk_mutex);
  24898. + memset(&service->stats, 0, sizeof(service->stats));
  24899. + } else {
  24900. + vchiq_log_error(vchiq_core_log_level,
  24901. + "Out of memory");
  24902. + }
  24903. +
  24904. + if (service) {
  24905. + VCHIQ_SERVICE_T **pservice = NULL;
  24906. + int i;
  24907. +
  24908. + /* Although it is perfectly possible to use service_spinlock
  24909. + ** to protect the creation of services, it is overkill as it
  24910. + ** disables interrupts while the array is searched.
  24911. + ** The only danger is of another thread trying to create a
  24912. + ** service - service deletion is safe.
  24913. + ** Therefore it is preferable to use state->mutex which,
  24914. + ** although slower to claim, doesn't block interrupts while
  24915. + ** it is held.
  24916. + */
  24917. +
  24918. + mutex_lock(&state->mutex);
  24919. +
  24920. + /* Prepare to use a previously unused service */
  24921. + if (state->unused_service < VCHIQ_MAX_SERVICES)
  24922. + pservice = &state->services[state->unused_service];
  24923. +
  24924. + if (srvstate == VCHIQ_SRVSTATE_OPENING) {
  24925. + for (i = 0; i < state->unused_service; i++) {
  24926. + VCHIQ_SERVICE_T *srv = state->services[i];
  24927. + if (!srv) {
  24928. + pservice = &state->services[i];
  24929. + break;
  24930. + }
  24931. + }
  24932. + } else {
  24933. + for (i = (state->unused_service - 1); i >= 0; i--) {
  24934. + VCHIQ_SERVICE_T *srv = state->services[i];
  24935. + if (!srv)
  24936. + pservice = &state->services[i];
  24937. + else if ((srv->public_fourcc == params->fourcc)
  24938. + && ((srv->instance != instance) ||
  24939. + (srv->base.callback !=
  24940. + params->callback))) {
  24941. + /* There is another server using this
  24942. + ** fourcc which doesn't match. */
  24943. + pservice = NULL;
  24944. + break;
  24945. + }
  24946. + }
  24947. + }
  24948. +
  24949. + if (pservice) {
  24950. + service->localport = (pservice - state->services);
  24951. + if (!handle_seq)
  24952. + handle_seq = VCHIQ_MAX_STATES *
  24953. + VCHIQ_MAX_SERVICES;
  24954. + service->handle = handle_seq |
  24955. + (state->id * VCHIQ_MAX_SERVICES) |
  24956. + service->localport;
  24957. + handle_seq += VCHIQ_MAX_STATES * VCHIQ_MAX_SERVICES;
  24958. + *pservice = service;
  24959. + if (pservice == &state->services[state->unused_service])
  24960. + state->unused_service++;
  24961. + }
  24962. +
  24963. + mutex_unlock(&state->mutex);
  24964. +
  24965. + if (!pservice) {
  24966. + kfree(service);
  24967. + service = NULL;
  24968. + }
  24969. + }
  24970. +
  24971. + if (service) {
  24972. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  24973. + &state->service_quotas[service->localport];
  24974. + service_quota->slot_quota = state->default_slot_quota;
  24975. + service_quota->message_quota = state->default_message_quota;
  24976. + if (service_quota->slot_use_count == 0)
  24977. + service_quota->previous_tx_index =
  24978. + SLOT_QUEUE_INDEX_FROM_POS(state->local_tx_pos)
  24979. + - 1;
  24980. +
  24981. + /* Bring this service online */
  24982. + vchiq_set_service_state(service, srvstate);
  24983. +
  24984. + vchiq_log_info(vchiq_core_msg_log_level,
  24985. + "%s Service %c%c%c%c SrcPort:%d",
  24986. + (srvstate == VCHIQ_SRVSTATE_OPENING)
  24987. + ? "Open" : "Add",
  24988. + VCHIQ_FOURCC_AS_4CHARS(params->fourcc),
  24989. + service->localport);
  24990. + }
  24991. +
  24992. + /* Don't unlock the service - leave it with a ref_count of 1. */
  24993. +
  24994. + return service;
  24995. +}
  24996. +
  24997. +VCHIQ_STATUS_T
  24998. +vchiq_open_service_internal(VCHIQ_SERVICE_T *service, int client_id)
  24999. +{
  25000. + struct vchiq_open_payload payload = {
  25001. + service->base.fourcc,
  25002. + client_id,
  25003. + service->version,
  25004. + service->version_min
  25005. + };
  25006. + VCHIQ_ELEMENT_T body = { &payload, sizeof(payload) };
  25007. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  25008. +
  25009. + service->client_id = client_id;
  25010. + vchiq_use_service_internal(service);
  25011. + status = queue_message(service->state, NULL,
  25012. + VCHIQ_MAKE_MSG(VCHIQ_MSG_OPEN, service->localport, 0),
  25013. + &body, 1, sizeof(payload), 1);
  25014. + if (status == VCHIQ_SUCCESS) {
  25015. + if (down_interruptible(&service->remove_event) != 0) {
  25016. + status = VCHIQ_RETRY;
  25017. + vchiq_release_service_internal(service);
  25018. + } else if ((service->srvstate != VCHIQ_SRVSTATE_OPEN) &&
  25019. + (service->srvstate != VCHIQ_SRVSTATE_OPENSYNC)) {
  25020. + if (service->srvstate != VCHIQ_SRVSTATE_CLOSEWAIT)
  25021. + vchiq_log_error(vchiq_core_log_level,
  25022. + "%d: osi - srvstate = %s (ref %d)",
  25023. + service->state->id,
  25024. + srvstate_names[service->srvstate],
  25025. + service->ref_count);
  25026. + status = VCHIQ_ERROR;
  25027. + VCHIQ_SERVICE_STATS_INC(service, error_count);
  25028. + vchiq_release_service_internal(service);
  25029. + }
  25030. + }
  25031. + return status;
  25032. +}
  25033. +
  25034. +static void
  25035. +release_service_messages(VCHIQ_SERVICE_T *service)
  25036. +{
  25037. + VCHIQ_STATE_T *state = service->state;
  25038. + int slot_last = state->remote->slot_last;
  25039. + int i;
  25040. +
  25041. + /* Release any claimed messages */
  25042. + for (i = state->remote->slot_first; i <= slot_last; i++) {
  25043. + VCHIQ_SLOT_INFO_T *slot_info =
  25044. + SLOT_INFO_FROM_INDEX(state, i);
  25045. + if (slot_info->release_count != slot_info->use_count) {
  25046. + char *data =
  25047. + (char *)SLOT_DATA_FROM_INDEX(state, i);
  25048. + unsigned int pos, end;
  25049. +
  25050. + end = VCHIQ_SLOT_SIZE;
  25051. + if (data == state->rx_data)
  25052. + /* This buffer is still being read from - stop
  25053. + ** at the current read position */
  25054. + end = state->rx_pos & VCHIQ_SLOT_MASK;
  25055. +
  25056. + pos = 0;
  25057. +
  25058. + while (pos < end) {
  25059. + VCHIQ_HEADER_T *header =
  25060. + (VCHIQ_HEADER_T *)(data + pos);
  25061. + int msgid = header->msgid;
  25062. + int port = VCHIQ_MSG_DSTPORT(msgid);
  25063. + if ((port == service->localport) &&
  25064. + (msgid & VCHIQ_MSGID_CLAIMED)) {
  25065. + vchiq_log_info(vchiq_core_log_level,
  25066. + " fsi - hdr %x",
  25067. + (unsigned int)header);
  25068. + release_slot(state, slot_info, header,
  25069. + NULL);
  25070. + }
  25071. + pos += calc_stride(header->size);
  25072. + if (pos > VCHIQ_SLOT_SIZE) {
  25073. + vchiq_log_error(vchiq_core_log_level,
  25074. + "fsi - pos %x: header %x, "
  25075. + "msgid %x, header->msgid %x, "
  25076. + "header->size %x",
  25077. + pos, (unsigned int)header,
  25078. + msgid, header->msgid,
  25079. + header->size);
  25080. + WARN(1, "invalid slot position\n");
  25081. + }
  25082. + }
  25083. + }
  25084. + }
  25085. +}
  25086. +
  25087. +static int
  25088. +do_abort_bulks(VCHIQ_SERVICE_T *service)
  25089. +{
  25090. + VCHIQ_STATUS_T status;
  25091. +
  25092. + /* Abort any outstanding bulk transfers */
  25093. + if (mutex_lock_interruptible(&service->bulk_mutex) != 0)
  25094. + return 0;
  25095. + abort_outstanding_bulks(service, &service->bulk_tx);
  25096. + abort_outstanding_bulks(service, &service->bulk_rx);
  25097. + mutex_unlock(&service->bulk_mutex);
  25098. +
  25099. + status = notify_bulks(service, &service->bulk_tx, 0/*!retry_poll*/);
  25100. + if (status == VCHIQ_SUCCESS)
  25101. + status = notify_bulks(service, &service->bulk_rx,
  25102. + 0/*!retry_poll*/);
  25103. + return (status == VCHIQ_SUCCESS);
  25104. +}
  25105. +
  25106. +static VCHIQ_STATUS_T
  25107. +close_service_complete(VCHIQ_SERVICE_T *service, int failstate)
  25108. +{
  25109. + VCHIQ_STATUS_T status;
  25110. + int is_server = (service->public_fourcc != VCHIQ_FOURCC_INVALID);
  25111. + int newstate;
  25112. +
  25113. + switch (service->srvstate) {
  25114. + case VCHIQ_SRVSTATE_OPEN:
  25115. + case VCHIQ_SRVSTATE_CLOSESENT:
  25116. + case VCHIQ_SRVSTATE_CLOSERECVD:
  25117. + if (is_server) {
  25118. + if (service->auto_close) {
  25119. + service->client_id = 0;
  25120. + service->remoteport = VCHIQ_PORT_FREE;
  25121. + newstate = VCHIQ_SRVSTATE_LISTENING;
  25122. + } else
  25123. + newstate = VCHIQ_SRVSTATE_CLOSEWAIT;
  25124. + } else
  25125. + newstate = VCHIQ_SRVSTATE_CLOSED;
  25126. + vchiq_set_service_state(service, newstate);
  25127. + break;
  25128. + case VCHIQ_SRVSTATE_LISTENING:
  25129. + break;
  25130. + default:
  25131. + vchiq_log_error(vchiq_core_log_level,
  25132. + "close_service_complete(%x) called in state %s",
  25133. + service->handle, srvstate_names[service->srvstate]);
  25134. + WARN(1, "close_service_complete in unexpected state\n");
  25135. + return VCHIQ_ERROR;
  25136. + }
  25137. +
  25138. + status = make_service_callback(service,
  25139. + VCHIQ_SERVICE_CLOSED, NULL, NULL);
  25140. +
  25141. + if (status != VCHIQ_RETRY) {
  25142. + int uc = service->service_use_count;
  25143. + int i;
  25144. + /* Complete the close process */
  25145. + for (i = 0; i < uc; i++)
  25146. + /* cater for cases where close is forced and the
  25147. + ** client may not close all it's handles */
  25148. + vchiq_release_service_internal(service);
  25149. +
  25150. + service->client_id = 0;
  25151. + service->remoteport = VCHIQ_PORT_FREE;
  25152. +
  25153. + if (service->srvstate == VCHIQ_SRVSTATE_CLOSED)
  25154. + vchiq_free_service_internal(service);
  25155. + else if (service->srvstate != VCHIQ_SRVSTATE_CLOSEWAIT) {
  25156. + if (is_server)
  25157. + service->closing = 0;
  25158. +
  25159. + up(&service->remove_event);
  25160. + }
  25161. + } else
  25162. + vchiq_set_service_state(service, failstate);
  25163. +
  25164. + return status;
  25165. +}
  25166. +
  25167. +/* Called by the slot handler */
  25168. +VCHIQ_STATUS_T
  25169. +vchiq_close_service_internal(VCHIQ_SERVICE_T *service, int close_recvd)
  25170. +{
  25171. + VCHIQ_STATE_T *state = service->state;
  25172. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  25173. + int is_server = (service->public_fourcc != VCHIQ_FOURCC_INVALID);
  25174. +
  25175. + vchiq_log_info(vchiq_core_log_level, "%d: csi:%d,%d (%s)",
  25176. + service->state->id, service->localport, close_recvd,
  25177. + srvstate_names[service->srvstate]);
  25178. +
  25179. + switch (service->srvstate) {
  25180. + case VCHIQ_SRVSTATE_CLOSED:
  25181. + case VCHIQ_SRVSTATE_HIDDEN:
  25182. + case VCHIQ_SRVSTATE_LISTENING:
  25183. + case VCHIQ_SRVSTATE_CLOSEWAIT:
  25184. + if (close_recvd)
  25185. + vchiq_log_error(vchiq_core_log_level,
  25186. + "vchiq_close_service_internal(1) called "
  25187. + "in state %s",
  25188. + srvstate_names[service->srvstate]);
  25189. + else if (is_server) {
  25190. + if (service->srvstate == VCHIQ_SRVSTATE_LISTENING) {
  25191. + status = VCHIQ_ERROR;
  25192. + } else {
  25193. + service->client_id = 0;
  25194. + service->remoteport = VCHIQ_PORT_FREE;
  25195. + if (service->srvstate ==
  25196. + VCHIQ_SRVSTATE_CLOSEWAIT)
  25197. + vchiq_set_service_state(service,
  25198. + VCHIQ_SRVSTATE_LISTENING);
  25199. + }
  25200. + up(&service->remove_event);
  25201. + } else
  25202. + vchiq_free_service_internal(service);
  25203. + break;
  25204. + case VCHIQ_SRVSTATE_OPENING:
  25205. + if (close_recvd) {
  25206. + /* The open was rejected - tell the user */
  25207. + vchiq_set_service_state(service,
  25208. + VCHIQ_SRVSTATE_CLOSEWAIT);
  25209. + up(&service->remove_event);
  25210. + } else {
  25211. + /* Shutdown mid-open - let the other side know */
  25212. + status = queue_message(state, service,
  25213. + VCHIQ_MAKE_MSG
  25214. + (VCHIQ_MSG_CLOSE,
  25215. + service->localport,
  25216. + VCHIQ_MSG_DSTPORT(service->remoteport)),
  25217. + NULL, 0, 0, 0);
  25218. + }
  25219. + break;
  25220. +
  25221. + case VCHIQ_SRVSTATE_OPENSYNC:
  25222. + mutex_lock(&state->sync_mutex);
  25223. + /* Drop through */
  25224. +
  25225. + case VCHIQ_SRVSTATE_OPEN:
  25226. + if (state->is_master || close_recvd) {
  25227. + if (!do_abort_bulks(service))
  25228. + status = VCHIQ_RETRY;
  25229. + }
  25230. +
  25231. + release_service_messages(service);
  25232. +
  25233. + if (status == VCHIQ_SUCCESS)
  25234. + status = queue_message(state, service,
  25235. + VCHIQ_MAKE_MSG
  25236. + (VCHIQ_MSG_CLOSE,
  25237. + service->localport,
  25238. + VCHIQ_MSG_DSTPORT(service->remoteport)),
  25239. + NULL, 0, 0, 0);
  25240. +
  25241. + if (status == VCHIQ_SUCCESS) {
  25242. + if (!close_recvd)
  25243. + break;
  25244. + } else if (service->srvstate == VCHIQ_SRVSTATE_OPENSYNC) {
  25245. + mutex_unlock(&state->sync_mutex);
  25246. + break;
  25247. + } else
  25248. + break;
  25249. +
  25250. + status = close_service_complete(service,
  25251. + VCHIQ_SRVSTATE_CLOSERECVD);
  25252. + break;
  25253. +
  25254. + case VCHIQ_SRVSTATE_CLOSESENT:
  25255. + if (!close_recvd)
  25256. + /* This happens when a process is killed mid-close */
  25257. + break;
  25258. +
  25259. + if (!state->is_master) {
  25260. + if (!do_abort_bulks(service)) {
  25261. + status = VCHIQ_RETRY;
  25262. + break;
  25263. + }
  25264. + }
  25265. +
  25266. + if (status == VCHIQ_SUCCESS)
  25267. + status = close_service_complete(service,
  25268. + VCHIQ_SRVSTATE_CLOSERECVD);
  25269. + break;
  25270. +
  25271. + case VCHIQ_SRVSTATE_CLOSERECVD:
  25272. + if (!close_recvd && is_server)
  25273. + /* Force into LISTENING mode */
  25274. + vchiq_set_service_state(service,
  25275. + VCHIQ_SRVSTATE_LISTENING);
  25276. + status = close_service_complete(service,
  25277. + VCHIQ_SRVSTATE_CLOSERECVD);
  25278. + break;
  25279. +
  25280. + default:
  25281. + vchiq_log_error(vchiq_core_log_level,
  25282. + "vchiq_close_service_internal(%d) called in state %s",
  25283. + close_recvd, srvstate_names[service->srvstate]);
  25284. + break;
  25285. + }
  25286. +
  25287. + return status;
  25288. +}
  25289. +
  25290. +/* Called from the application process upon process death */
  25291. +void
  25292. +vchiq_terminate_service_internal(VCHIQ_SERVICE_T *service)
  25293. +{
  25294. + VCHIQ_STATE_T *state = service->state;
  25295. +
  25296. + vchiq_log_info(vchiq_core_log_level, "%d: tsi - (%d<->%d)",
  25297. + state->id, service->localport, service->remoteport);
  25298. +
  25299. + mark_service_closing(service);
  25300. +
  25301. + /* Mark the service for removal by the slot handler */
  25302. + request_poll(state, service, VCHIQ_POLL_REMOVE);
  25303. +}
  25304. +
  25305. +/* Called from the slot handler */
  25306. +void
  25307. +vchiq_free_service_internal(VCHIQ_SERVICE_T *service)
  25308. +{
  25309. + VCHIQ_STATE_T *state = service->state;
  25310. +
  25311. + vchiq_log_info(vchiq_core_log_level, "%d: fsi - (%d)",
  25312. + state->id, service->localport);
  25313. +
  25314. + switch (service->srvstate) {
  25315. + case VCHIQ_SRVSTATE_OPENING:
  25316. + case VCHIQ_SRVSTATE_CLOSED:
  25317. + case VCHIQ_SRVSTATE_HIDDEN:
  25318. + case VCHIQ_SRVSTATE_LISTENING:
  25319. + case VCHIQ_SRVSTATE_CLOSEWAIT:
  25320. + break;
  25321. + default:
  25322. + vchiq_log_error(vchiq_core_log_level,
  25323. + "%d: fsi - (%d) in state %s",
  25324. + state->id, service->localport,
  25325. + srvstate_names[service->srvstate]);
  25326. + return;
  25327. + }
  25328. +
  25329. + vchiq_set_service_state(service, VCHIQ_SRVSTATE_FREE);
  25330. +
  25331. + up(&service->remove_event);
  25332. +
  25333. + /* Release the initial lock */
  25334. + unlock_service(service);
  25335. +}
  25336. +
  25337. +VCHIQ_STATUS_T
  25338. +vchiq_connect_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance)
  25339. +{
  25340. + VCHIQ_SERVICE_T *service;
  25341. + int i;
  25342. +
  25343. + /* Find all services registered to this client and enable them. */
  25344. + i = 0;
  25345. + while ((service = next_service_by_instance(state, instance,
  25346. + &i)) != NULL) {
  25347. + if (service->srvstate == VCHIQ_SRVSTATE_HIDDEN)
  25348. + vchiq_set_service_state(service,
  25349. + VCHIQ_SRVSTATE_LISTENING);
  25350. + unlock_service(service);
  25351. + }
  25352. +
  25353. + if (state->conn_state == VCHIQ_CONNSTATE_DISCONNECTED) {
  25354. + if (queue_message(state, NULL,
  25355. + VCHIQ_MAKE_MSG(VCHIQ_MSG_CONNECT, 0, 0), NULL, 0,
  25356. + 0, 1) == VCHIQ_RETRY)
  25357. + return VCHIQ_RETRY;
  25358. +
  25359. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTING);
  25360. + }
  25361. +
  25362. + if (state->conn_state == VCHIQ_CONNSTATE_CONNECTING) {
  25363. + if (down_interruptible(&state->connect) != 0)
  25364. + return VCHIQ_RETRY;
  25365. +
  25366. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTED);
  25367. + up(&state->connect);
  25368. + }
  25369. +
  25370. + return VCHIQ_SUCCESS;
  25371. +}
  25372. +
  25373. +VCHIQ_STATUS_T
  25374. +vchiq_shutdown_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance)
  25375. +{
  25376. + VCHIQ_SERVICE_T *service;
  25377. + int i;
  25378. +
  25379. + /* Find all services registered to this client and enable them. */
  25380. + i = 0;
  25381. + while ((service = next_service_by_instance(state, instance,
  25382. + &i)) != NULL) {
  25383. + (void)vchiq_remove_service(service->handle);
  25384. + unlock_service(service);
  25385. + }
  25386. +
  25387. + return VCHIQ_SUCCESS;
  25388. +}
  25389. +
  25390. +VCHIQ_STATUS_T
  25391. +vchiq_pause_internal(VCHIQ_STATE_T *state)
  25392. +{
  25393. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  25394. +
  25395. + switch (state->conn_state) {
  25396. + case VCHIQ_CONNSTATE_CONNECTED:
  25397. + /* Request a pause */
  25398. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_PAUSING);
  25399. + request_poll(state, NULL, 0);
  25400. + break;
  25401. + default:
  25402. + vchiq_log_error(vchiq_core_log_level,
  25403. + "vchiq_pause_internal in state %s\n",
  25404. + conn_state_names[state->conn_state]);
  25405. + status = VCHIQ_ERROR;
  25406. + VCHIQ_STATS_INC(state, error_count);
  25407. + break;
  25408. + }
  25409. +
  25410. + return status;
  25411. +}
  25412. +
  25413. +VCHIQ_STATUS_T
  25414. +vchiq_resume_internal(VCHIQ_STATE_T *state)
  25415. +{
  25416. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  25417. +
  25418. + if (state->conn_state == VCHIQ_CONNSTATE_PAUSED) {
  25419. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_RESUMING);
  25420. + request_poll(state, NULL, 0);
  25421. + } else {
  25422. + status = VCHIQ_ERROR;
  25423. + VCHIQ_STATS_INC(state, error_count);
  25424. + }
  25425. +
  25426. + return status;
  25427. +}
  25428. +
  25429. +VCHIQ_STATUS_T
  25430. +vchiq_close_service(VCHIQ_SERVICE_HANDLE_T handle)
  25431. +{
  25432. + /* Unregister the service */
  25433. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  25434. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  25435. +
  25436. + if (!service)
  25437. + return VCHIQ_ERROR;
  25438. +
  25439. + vchiq_log_info(vchiq_core_log_level,
  25440. + "%d: close_service:%d",
  25441. + service->state->id, service->localport);
  25442. +
  25443. + if ((service->srvstate == VCHIQ_SRVSTATE_FREE) ||
  25444. + (service->srvstate == VCHIQ_SRVSTATE_LISTENING) ||
  25445. + (service->srvstate == VCHIQ_SRVSTATE_HIDDEN)) {
  25446. + unlock_service(service);
  25447. + return VCHIQ_ERROR;
  25448. + }
  25449. +
  25450. + mark_service_closing(service);
  25451. +
  25452. + if (current == service->state->slot_handler_thread) {
  25453. + status = vchiq_close_service_internal(service,
  25454. + 0/*!close_recvd*/);
  25455. + BUG_ON(status == VCHIQ_RETRY);
  25456. + } else {
  25457. + /* Mark the service for termination by the slot handler */
  25458. + request_poll(service->state, service, VCHIQ_POLL_TERMINATE);
  25459. + }
  25460. +
  25461. + while (1) {
  25462. + if (down_interruptible(&service->remove_event) != 0) {
  25463. + status = VCHIQ_RETRY;
  25464. + break;
  25465. + }
  25466. +
  25467. + if ((service->srvstate == VCHIQ_SRVSTATE_FREE) ||
  25468. + (service->srvstate == VCHIQ_SRVSTATE_LISTENING) ||
  25469. + (service->srvstate == VCHIQ_SRVSTATE_OPEN))
  25470. + break;
  25471. +
  25472. + vchiq_log_warning(vchiq_core_log_level,
  25473. + "%d: close_service:%d - waiting in state %s",
  25474. + service->state->id, service->localport,
  25475. + srvstate_names[service->srvstate]);
  25476. + }
  25477. +
  25478. + if ((status == VCHIQ_SUCCESS) &&
  25479. + (service->srvstate != VCHIQ_SRVSTATE_FREE) &&
  25480. + (service->srvstate != VCHIQ_SRVSTATE_LISTENING))
  25481. + status = VCHIQ_ERROR;
  25482. +
  25483. + unlock_service(service);
  25484. +
  25485. + return status;
  25486. +}
  25487. +
  25488. +VCHIQ_STATUS_T
  25489. +vchiq_remove_service(VCHIQ_SERVICE_HANDLE_T handle)
  25490. +{
  25491. + /* Unregister the service */
  25492. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  25493. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  25494. +
  25495. + if (!service)
  25496. + return VCHIQ_ERROR;
  25497. +
  25498. + vchiq_log_info(vchiq_core_log_level,
  25499. + "%d: remove_service:%d",
  25500. + service->state->id, service->localport);
  25501. +
  25502. + if (service->srvstate == VCHIQ_SRVSTATE_FREE) {
  25503. + unlock_service(service);
  25504. + return VCHIQ_ERROR;
  25505. + }
  25506. +
  25507. + mark_service_closing(service);
  25508. +
  25509. + if ((service->srvstate == VCHIQ_SRVSTATE_HIDDEN) ||
  25510. + (current == service->state->slot_handler_thread)) {
  25511. + /* Make it look like a client, because it must be removed and
  25512. + not left in the LISTENING state. */
  25513. + service->public_fourcc = VCHIQ_FOURCC_INVALID;
  25514. +
  25515. + status = vchiq_close_service_internal(service,
  25516. + 0/*!close_recvd*/);
  25517. + BUG_ON(status == VCHIQ_RETRY);
  25518. + } else {
  25519. + /* Mark the service for removal by the slot handler */
  25520. + request_poll(service->state, service, VCHIQ_POLL_REMOVE);
  25521. + }
  25522. + while (1) {
  25523. + if (down_interruptible(&service->remove_event) != 0) {
  25524. + status = VCHIQ_RETRY;
  25525. + break;
  25526. + }
  25527. +
  25528. + if ((service->srvstate == VCHIQ_SRVSTATE_FREE) ||
  25529. + (service->srvstate == VCHIQ_SRVSTATE_OPEN))
  25530. + break;
  25531. +
  25532. + vchiq_log_warning(vchiq_core_log_level,
  25533. + "%d: remove_service:%d - waiting in state %s",
  25534. + service->state->id, service->localport,
  25535. + srvstate_names[service->srvstate]);
  25536. + }
  25537. +
  25538. + if ((status == VCHIQ_SUCCESS) &&
  25539. + (service->srvstate != VCHIQ_SRVSTATE_FREE))
  25540. + status = VCHIQ_ERROR;
  25541. +
  25542. + unlock_service(service);
  25543. +
  25544. + return status;
  25545. +}
  25546. +
  25547. +
  25548. +/* This function may be called by kernel threads or user threads.
  25549. + * User threads may receive VCHIQ_RETRY to indicate that a signal has been
  25550. + * received and the call should be retried after being returned to user
  25551. + * context.
  25552. + * When called in blocking mode, the userdata field points to a bulk_waiter
  25553. + * structure.
  25554. + */
  25555. +VCHIQ_STATUS_T
  25556. +vchiq_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle,
  25557. + VCHI_MEM_HANDLE_T memhandle, void *offset, int size, void *userdata,
  25558. + VCHIQ_BULK_MODE_T mode, VCHIQ_BULK_DIR_T dir)
  25559. +{
  25560. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  25561. + VCHIQ_BULK_QUEUE_T *queue;
  25562. + VCHIQ_BULK_T *bulk;
  25563. + VCHIQ_STATE_T *state;
  25564. + struct bulk_waiter *bulk_waiter = NULL;
  25565. + const char dir_char = (dir == VCHIQ_BULK_TRANSMIT) ? 't' : 'r';
  25566. + const int dir_msgtype = (dir == VCHIQ_BULK_TRANSMIT) ?
  25567. + VCHIQ_MSG_BULK_TX : VCHIQ_MSG_BULK_RX;
  25568. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  25569. +
  25570. + if (!service ||
  25571. + (service->srvstate != VCHIQ_SRVSTATE_OPEN) ||
  25572. + ((memhandle == VCHI_MEM_HANDLE_INVALID) && (offset == NULL)) ||
  25573. + (vchiq_check_service(service) != VCHIQ_SUCCESS))
  25574. + goto error_exit;
  25575. +
  25576. + switch (mode) {
  25577. + case VCHIQ_BULK_MODE_NOCALLBACK:
  25578. + case VCHIQ_BULK_MODE_CALLBACK:
  25579. + break;
  25580. + case VCHIQ_BULK_MODE_BLOCKING:
  25581. + bulk_waiter = (struct bulk_waiter *)userdata;
  25582. + sema_init(&bulk_waiter->event, 0);
  25583. + bulk_waiter->actual = 0;
  25584. + bulk_waiter->bulk = NULL;
  25585. + break;
  25586. + case VCHIQ_BULK_MODE_WAITING:
  25587. + bulk_waiter = (struct bulk_waiter *)userdata;
  25588. + bulk = bulk_waiter->bulk;
  25589. + goto waiting;
  25590. + default:
  25591. + goto error_exit;
  25592. + }
  25593. +
  25594. + state = service->state;
  25595. +
  25596. + queue = (dir == VCHIQ_BULK_TRANSMIT) ?
  25597. + &service->bulk_tx : &service->bulk_rx;
  25598. +
  25599. + if (mutex_lock_interruptible(&service->bulk_mutex) != 0) {
  25600. + status = VCHIQ_RETRY;
  25601. + goto error_exit;
  25602. + }
  25603. +
  25604. + if (queue->local_insert == queue->remove + VCHIQ_NUM_SERVICE_BULKS) {
  25605. + VCHIQ_SERVICE_STATS_INC(service, bulk_stalls);
  25606. + do {
  25607. + mutex_unlock(&service->bulk_mutex);
  25608. + if (down_interruptible(&service->bulk_remove_event)
  25609. + != 0) {
  25610. + status = VCHIQ_RETRY;
  25611. + goto error_exit;
  25612. + }
  25613. + if (mutex_lock_interruptible(&service->bulk_mutex)
  25614. + != 0) {
  25615. + status = VCHIQ_RETRY;
  25616. + goto error_exit;
  25617. + }
  25618. + } while (queue->local_insert == queue->remove +
  25619. + VCHIQ_NUM_SERVICE_BULKS);
  25620. + }
  25621. +
  25622. + bulk = &queue->bulks[BULK_INDEX(queue->local_insert)];
  25623. +
  25624. + bulk->mode = mode;
  25625. + bulk->dir = dir;
  25626. + bulk->userdata = userdata;
  25627. + bulk->size = size;
  25628. + bulk->actual = VCHIQ_BULK_ACTUAL_ABORTED;
  25629. +
  25630. + if (vchiq_prepare_bulk_data(bulk, memhandle, offset, size, dir) !=
  25631. + VCHIQ_SUCCESS)
  25632. + goto unlock_error_exit;
  25633. +
  25634. + wmb();
  25635. +
  25636. + vchiq_log_info(vchiq_core_log_level,
  25637. + "%d: bt (%d->%d) %cx %x@%x %x",
  25638. + state->id,
  25639. + service->localport, service->remoteport, dir_char,
  25640. + size, (unsigned int)bulk->data, (unsigned int)userdata);
  25641. +
  25642. + if (state->is_master) {
  25643. + queue->local_insert++;
  25644. + if (resolve_bulks(service, queue))
  25645. + request_poll(state, service,
  25646. + (dir == VCHIQ_BULK_TRANSMIT) ?
  25647. + VCHIQ_POLL_TXNOTIFY : VCHIQ_POLL_RXNOTIFY);
  25648. + } else {
  25649. + int payload[2] = { (int)bulk->data, bulk->size };
  25650. + VCHIQ_ELEMENT_T element = { payload, sizeof(payload) };
  25651. +
  25652. + status = queue_message(state, NULL,
  25653. + VCHIQ_MAKE_MSG(dir_msgtype,
  25654. + service->localport, service->remoteport),
  25655. + &element, 1, sizeof(payload), 1);
  25656. + if (status != VCHIQ_SUCCESS) {
  25657. + vchiq_complete_bulk(bulk);
  25658. + goto unlock_error_exit;
  25659. + }
  25660. + queue->local_insert++;
  25661. + }
  25662. +
  25663. + mutex_unlock(&service->bulk_mutex);
  25664. +
  25665. + vchiq_log_trace(vchiq_core_log_level,
  25666. + "%d: bt:%d %cx li=%x ri=%x p=%x",
  25667. + state->id,
  25668. + service->localport, dir_char,
  25669. + queue->local_insert, queue->remote_insert, queue->process);
  25670. +
  25671. +waiting:
  25672. + unlock_service(service);
  25673. +
  25674. + status = VCHIQ_SUCCESS;
  25675. +
  25676. + if (bulk_waiter) {
  25677. + bulk_waiter->bulk = bulk;
  25678. + if (down_interruptible(&bulk_waiter->event) != 0)
  25679. + status = VCHIQ_RETRY;
  25680. + else if (bulk_waiter->actual == VCHIQ_BULK_ACTUAL_ABORTED)
  25681. + status = VCHIQ_ERROR;
  25682. + }
  25683. +
  25684. + return status;
  25685. +
  25686. +unlock_error_exit:
  25687. + mutex_unlock(&service->bulk_mutex);
  25688. +
  25689. +error_exit:
  25690. + if (service)
  25691. + unlock_service(service);
  25692. + return status;
  25693. +}
  25694. +
  25695. +VCHIQ_STATUS_T
  25696. +vchiq_queue_message(VCHIQ_SERVICE_HANDLE_T handle,
  25697. + const VCHIQ_ELEMENT_T *elements, unsigned int count)
  25698. +{
  25699. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  25700. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  25701. +
  25702. + unsigned int size = 0;
  25703. + unsigned int i;
  25704. +
  25705. + if (!service ||
  25706. + (vchiq_check_service(service) != VCHIQ_SUCCESS))
  25707. + goto error_exit;
  25708. +
  25709. + for (i = 0; i < (unsigned int)count; i++) {
  25710. + if (elements[i].size) {
  25711. + if (elements[i].data == NULL) {
  25712. + VCHIQ_SERVICE_STATS_INC(service, error_count);
  25713. + goto error_exit;
  25714. + }
  25715. + size += elements[i].size;
  25716. + }
  25717. + }
  25718. +
  25719. + if (size > VCHIQ_MAX_MSG_SIZE) {
  25720. + VCHIQ_SERVICE_STATS_INC(service, error_count);
  25721. + goto error_exit;
  25722. + }
  25723. +
  25724. + switch (service->srvstate) {
  25725. + case VCHIQ_SRVSTATE_OPEN:
  25726. + status = queue_message(service->state, service,
  25727. + VCHIQ_MAKE_MSG(VCHIQ_MSG_DATA,
  25728. + service->localport,
  25729. + service->remoteport),
  25730. + elements, count, size, 1);
  25731. + break;
  25732. + case VCHIQ_SRVSTATE_OPENSYNC:
  25733. + status = queue_message_sync(service->state, service,
  25734. + VCHIQ_MAKE_MSG(VCHIQ_MSG_DATA,
  25735. + service->localport,
  25736. + service->remoteport),
  25737. + elements, count, size, 1);
  25738. + break;
  25739. + default:
  25740. + status = VCHIQ_ERROR;
  25741. + break;
  25742. + }
  25743. +
  25744. +error_exit:
  25745. + if (service)
  25746. + unlock_service(service);
  25747. +
  25748. + return status;
  25749. +}
  25750. +
  25751. +void
  25752. +vchiq_release_message(VCHIQ_SERVICE_HANDLE_T handle, VCHIQ_HEADER_T *header)
  25753. +{
  25754. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  25755. + VCHIQ_SHARED_STATE_T *remote;
  25756. + VCHIQ_STATE_T *state;
  25757. + int slot_index;
  25758. +
  25759. + if (!service)
  25760. + return;
  25761. +
  25762. + state = service->state;
  25763. + remote = state->remote;
  25764. +
  25765. + slot_index = SLOT_INDEX_FROM_DATA(state, (void *)header);
  25766. +
  25767. + if ((slot_index >= remote->slot_first) &&
  25768. + (slot_index <= remote->slot_last)) {
  25769. + int msgid = header->msgid;
  25770. + if (msgid & VCHIQ_MSGID_CLAIMED) {
  25771. + VCHIQ_SLOT_INFO_T *slot_info =
  25772. + SLOT_INFO_FROM_INDEX(state, slot_index);
  25773. +
  25774. + release_slot(state, slot_info, header, service);
  25775. + }
  25776. + } else if (slot_index == remote->slot_sync)
  25777. + release_message_sync(state, header);
  25778. +
  25779. + unlock_service(service);
  25780. +}
  25781. +
  25782. +static void
  25783. +release_message_sync(VCHIQ_STATE_T *state, VCHIQ_HEADER_T *header)
  25784. +{
  25785. + header->msgid = VCHIQ_MSGID_PADDING;
  25786. + wmb();
  25787. + remote_event_signal(&state->remote->sync_release);
  25788. +}
  25789. +
  25790. +VCHIQ_STATUS_T
  25791. +vchiq_get_peer_version(VCHIQ_SERVICE_HANDLE_T handle, short *peer_version)
  25792. +{
  25793. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  25794. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  25795. +
  25796. + if (!service ||
  25797. + (vchiq_check_service(service) != VCHIQ_SUCCESS) ||
  25798. + !peer_version)
  25799. + goto exit;
  25800. + *peer_version = service->peer_version;
  25801. + status = VCHIQ_SUCCESS;
  25802. +
  25803. +exit:
  25804. + if (service)
  25805. + unlock_service(service);
  25806. + return status;
  25807. +}
  25808. +
  25809. +VCHIQ_STATUS_T
  25810. +vchiq_get_config(VCHIQ_INSTANCE_T instance,
  25811. + int config_size, VCHIQ_CONFIG_T *pconfig)
  25812. +{
  25813. + VCHIQ_CONFIG_T config;
  25814. +
  25815. + (void)instance;
  25816. +
  25817. + config.max_msg_size = VCHIQ_MAX_MSG_SIZE;
  25818. + config.bulk_threshold = VCHIQ_MAX_MSG_SIZE;
  25819. + config.max_outstanding_bulks = VCHIQ_NUM_SERVICE_BULKS;
  25820. + config.max_services = VCHIQ_MAX_SERVICES;
  25821. + config.version = VCHIQ_VERSION;
  25822. + config.version_min = VCHIQ_VERSION_MIN;
  25823. +
  25824. + if (config_size > sizeof(VCHIQ_CONFIG_T))
  25825. + return VCHIQ_ERROR;
  25826. +
  25827. + memcpy(pconfig, &config,
  25828. + min(config_size, (int)(sizeof(VCHIQ_CONFIG_T))));
  25829. +
  25830. + return VCHIQ_SUCCESS;
  25831. +}
  25832. +
  25833. +VCHIQ_STATUS_T
  25834. +vchiq_set_service_option(VCHIQ_SERVICE_HANDLE_T handle,
  25835. + VCHIQ_SERVICE_OPTION_T option, int value)
  25836. +{
  25837. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  25838. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  25839. +
  25840. + if (service) {
  25841. + switch (option) {
  25842. + case VCHIQ_SERVICE_OPTION_AUTOCLOSE:
  25843. + service->auto_close = value;
  25844. + status = VCHIQ_SUCCESS;
  25845. + break;
  25846. +
  25847. + case VCHIQ_SERVICE_OPTION_SLOT_QUOTA: {
  25848. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  25849. + &service->state->service_quotas[
  25850. + service->localport];
  25851. + if (value == 0)
  25852. + value = service->state->default_slot_quota;
  25853. + if ((value >= service_quota->slot_use_count) &&
  25854. + (value < (unsigned short)~0)) {
  25855. + service_quota->slot_quota = value;
  25856. + if ((value >= service_quota->slot_use_count) &&
  25857. + (service_quota->message_quota >=
  25858. + service_quota->message_use_count)) {
  25859. + /* Signal the service that it may have
  25860. + ** dropped below its quota */
  25861. + up(&service_quota->quota_event);
  25862. + }
  25863. + status = VCHIQ_SUCCESS;
  25864. + }
  25865. + } break;
  25866. +
  25867. + case VCHIQ_SERVICE_OPTION_MESSAGE_QUOTA: {
  25868. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  25869. + &service->state->service_quotas[
  25870. + service->localport];
  25871. + if (value == 0)
  25872. + value = service->state->default_message_quota;
  25873. + if ((value >= service_quota->message_use_count) &&
  25874. + (value < (unsigned short)~0)) {
  25875. + service_quota->message_quota = value;
  25876. + if ((value >=
  25877. + service_quota->message_use_count) &&
  25878. + (service_quota->slot_quota >=
  25879. + service_quota->slot_use_count))
  25880. + /* Signal the service that it may have
  25881. + ** dropped below its quota */
  25882. + up(&service_quota->quota_event);
  25883. + status = VCHIQ_SUCCESS;
  25884. + }
  25885. + } break;
  25886. +
  25887. + case VCHIQ_SERVICE_OPTION_SYNCHRONOUS:
  25888. + if ((service->srvstate == VCHIQ_SRVSTATE_HIDDEN) ||
  25889. + (service->srvstate ==
  25890. + VCHIQ_SRVSTATE_LISTENING)) {
  25891. + service->sync = value;
  25892. + status = VCHIQ_SUCCESS;
  25893. + }
  25894. + break;
  25895. +
  25896. + default:
  25897. + break;
  25898. + }
  25899. + unlock_service(service);
  25900. + }
  25901. +
  25902. + return status;
  25903. +}
  25904. +
  25905. +void
  25906. +vchiq_dump_shared_state(void *dump_context, VCHIQ_STATE_T *state,
  25907. + VCHIQ_SHARED_STATE_T *shared, const char *label)
  25908. +{
  25909. + static const char *const debug_names[] = {
  25910. + "<entries>",
  25911. + "SLOT_HANDLER_COUNT",
  25912. + "SLOT_HANDLER_LINE",
  25913. + "PARSE_LINE",
  25914. + "PARSE_HEADER",
  25915. + "PARSE_MSGID",
  25916. + "AWAIT_COMPLETION_LINE",
  25917. + "DEQUEUE_MESSAGE_LINE",
  25918. + "SERVICE_CALLBACK_LINE",
  25919. + "MSG_QUEUE_FULL_COUNT",
  25920. + "COMPLETION_QUEUE_FULL_COUNT"
  25921. + };
  25922. + int i;
  25923. +
  25924. + char buf[80];
  25925. + int len;
  25926. + len = snprintf(buf, sizeof(buf),
  25927. + " %s: slots %d-%d tx_pos=%x recycle=%x",
  25928. + label, shared->slot_first, shared->slot_last,
  25929. + shared->tx_pos, shared->slot_queue_recycle);
  25930. + vchiq_dump(dump_context, buf, len + 1);
  25931. +
  25932. + len = snprintf(buf, sizeof(buf),
  25933. + " Slots claimed:");
  25934. + vchiq_dump(dump_context, buf, len + 1);
  25935. +
  25936. + for (i = shared->slot_first; i <= shared->slot_last; i++) {
  25937. + VCHIQ_SLOT_INFO_T slot_info = *SLOT_INFO_FROM_INDEX(state, i);
  25938. + if (slot_info.use_count != slot_info.release_count) {
  25939. + len = snprintf(buf, sizeof(buf),
  25940. + " %d: %d/%d", i, slot_info.use_count,
  25941. + slot_info.release_count);
  25942. + vchiq_dump(dump_context, buf, len + 1);
  25943. + }
  25944. + }
  25945. +
  25946. + for (i = 1; i < shared->debug[DEBUG_ENTRIES]; i++) {
  25947. + len = snprintf(buf, sizeof(buf), " DEBUG: %s = %d(%x)",
  25948. + debug_names[i], shared->debug[i], shared->debug[i]);
  25949. + vchiq_dump(dump_context, buf, len + 1);
  25950. + }
  25951. +}
  25952. +
  25953. +void
  25954. +vchiq_dump_state(void *dump_context, VCHIQ_STATE_T *state)
  25955. +{
  25956. + char buf[80];
  25957. + int len;
  25958. + int i;
  25959. +
  25960. + len = snprintf(buf, sizeof(buf), "State %d: %s", state->id,
  25961. + conn_state_names[state->conn_state]);
  25962. + vchiq_dump(dump_context, buf, len + 1);
  25963. +
  25964. + len = snprintf(buf, sizeof(buf),
  25965. + " tx_pos=%x(@%x), rx_pos=%x(@%x)",
  25966. + state->local->tx_pos,
  25967. + (uint32_t)state->tx_data +
  25968. + (state->local_tx_pos & VCHIQ_SLOT_MASK),
  25969. + state->rx_pos,
  25970. + (uint32_t)state->rx_data +
  25971. + (state->rx_pos & VCHIQ_SLOT_MASK));
  25972. + vchiq_dump(dump_context, buf, len + 1);
  25973. +
  25974. + len = snprintf(buf, sizeof(buf),
  25975. + " Version: %d (min %d)",
  25976. + VCHIQ_VERSION, VCHIQ_VERSION_MIN);
  25977. + vchiq_dump(dump_context, buf, len + 1);
  25978. +
  25979. + if (VCHIQ_ENABLE_STATS) {
  25980. + len = snprintf(buf, sizeof(buf),
  25981. + " Stats: ctrl_tx_count=%d, ctrl_rx_count=%d, "
  25982. + "error_count=%d",
  25983. + state->stats.ctrl_tx_count, state->stats.ctrl_rx_count,
  25984. + state->stats.error_count);
  25985. + vchiq_dump(dump_context, buf, len + 1);
  25986. + }
  25987. +
  25988. + len = snprintf(buf, sizeof(buf),
  25989. + " Slots: %d available (%d data), %d recyclable, %d stalls "
  25990. + "(%d data)",
  25991. + ((state->slot_queue_available * VCHIQ_SLOT_SIZE) -
  25992. + state->local_tx_pos) / VCHIQ_SLOT_SIZE,
  25993. + state->data_quota - state->data_use_count,
  25994. + state->local->slot_queue_recycle - state->slot_queue_available,
  25995. + state->stats.slot_stalls, state->stats.data_stalls);
  25996. + vchiq_dump(dump_context, buf, len + 1);
  25997. +
  25998. + vchiq_dump_platform_state(dump_context);
  25999. +
  26000. + vchiq_dump_shared_state(dump_context, state, state->local, "Local");
  26001. + vchiq_dump_shared_state(dump_context, state, state->remote, "Remote");
  26002. +
  26003. + vchiq_dump_platform_instances(dump_context);
  26004. +
  26005. + for (i = 0; i < state->unused_service; i++) {
  26006. + VCHIQ_SERVICE_T *service = find_service_by_port(state, i);
  26007. +
  26008. + if (service) {
  26009. + vchiq_dump_service_state(dump_context, service);
  26010. + unlock_service(service);
  26011. + }
  26012. + }
  26013. +}
  26014. +
  26015. +void
  26016. +vchiq_dump_service_state(void *dump_context, VCHIQ_SERVICE_T *service)
  26017. +{
  26018. + char buf[80];
  26019. + int len;
  26020. +
  26021. + len = snprintf(buf, sizeof(buf), "Service %d: %s (ref %u)",
  26022. + service->localport, srvstate_names[service->srvstate],
  26023. + service->ref_count - 1); /*Don't include the lock just taken*/
  26024. +
  26025. + if (service->srvstate != VCHIQ_SRVSTATE_FREE) {
  26026. + char remoteport[30];
  26027. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  26028. + &service->state->service_quotas[service->localport];
  26029. + int fourcc = service->base.fourcc;
  26030. + int tx_pending, rx_pending;
  26031. + if (service->remoteport != VCHIQ_PORT_FREE) {
  26032. + int len2 = snprintf(remoteport, sizeof(remoteport),
  26033. + "%d", service->remoteport);
  26034. + if (service->public_fourcc != VCHIQ_FOURCC_INVALID)
  26035. + snprintf(remoteport + len2,
  26036. + sizeof(remoteport) - len2,
  26037. + " (client %x)", service->client_id);
  26038. + } else
  26039. + strcpy(remoteport, "n/a");
  26040. +
  26041. + len += snprintf(buf + len, sizeof(buf) - len,
  26042. + " '%c%c%c%c' remote %s (msg use %d/%d, slot use %d/%d)",
  26043. + VCHIQ_FOURCC_AS_4CHARS(fourcc),
  26044. + remoteport,
  26045. + service_quota->message_use_count,
  26046. + service_quota->message_quota,
  26047. + service_quota->slot_use_count,
  26048. + service_quota->slot_quota);
  26049. +
  26050. + vchiq_dump(dump_context, buf, len + 1);
  26051. +
  26052. + tx_pending = service->bulk_tx.local_insert -
  26053. + service->bulk_tx.remote_insert;
  26054. +
  26055. + rx_pending = service->bulk_rx.local_insert -
  26056. + service->bulk_rx.remote_insert;
  26057. +
  26058. + len = snprintf(buf, sizeof(buf),
  26059. + " Bulk: tx_pending=%d (size %d),"
  26060. + " rx_pending=%d (size %d)",
  26061. + tx_pending,
  26062. + tx_pending ? service->bulk_tx.bulks[
  26063. + BULK_INDEX(service->bulk_tx.remove)].size : 0,
  26064. + rx_pending,
  26065. + rx_pending ? service->bulk_rx.bulks[
  26066. + BULK_INDEX(service->bulk_rx.remove)].size : 0);
  26067. +
  26068. + if (VCHIQ_ENABLE_STATS) {
  26069. + vchiq_dump(dump_context, buf, len + 1);
  26070. +
  26071. + len = snprintf(buf, sizeof(buf),
  26072. + " Ctrl: tx_count=%d, tx_bytes=%llu, "
  26073. + "rx_count=%d, rx_bytes=%llu",
  26074. + service->stats.ctrl_tx_count,
  26075. + service->stats.ctrl_tx_bytes,
  26076. + service->stats.ctrl_rx_count,
  26077. + service->stats.ctrl_rx_bytes);
  26078. + vchiq_dump(dump_context, buf, len + 1);
  26079. +
  26080. + len = snprintf(buf, sizeof(buf),
  26081. + " Bulk: tx_count=%d, tx_bytes=%llu, "
  26082. + "rx_count=%d, rx_bytes=%llu",
  26083. + service->stats.bulk_tx_count,
  26084. + service->stats.bulk_tx_bytes,
  26085. + service->stats.bulk_rx_count,
  26086. + service->stats.bulk_rx_bytes);
  26087. + vchiq_dump(dump_context, buf, len + 1);
  26088. +
  26089. + len = snprintf(buf, sizeof(buf),
  26090. + " %d quota stalls, %d slot stalls, "
  26091. + "%d bulk stalls, %d aborted, %d errors",
  26092. + service->stats.quota_stalls,
  26093. + service->stats.slot_stalls,
  26094. + service->stats.bulk_stalls,
  26095. + service->stats.bulk_aborted_count,
  26096. + service->stats.error_count);
  26097. + }
  26098. + }
  26099. +
  26100. + vchiq_dump(dump_context, buf, len + 1);
  26101. +
  26102. + if (service->srvstate != VCHIQ_SRVSTATE_FREE)
  26103. + vchiq_dump_platform_service_state(dump_context, service);
  26104. +}
  26105. +
  26106. +
  26107. +void
  26108. +vchiq_loud_error_header(void)
  26109. +{
  26110. + vchiq_log_error(vchiq_core_log_level,
  26111. + "============================================================"
  26112. + "================");
  26113. + vchiq_log_error(vchiq_core_log_level,
  26114. + "============================================================"
  26115. + "================");
  26116. + vchiq_log_error(vchiq_core_log_level, "=====");
  26117. +}
  26118. +
  26119. +void
  26120. +vchiq_loud_error_footer(void)
  26121. +{
  26122. + vchiq_log_error(vchiq_core_log_level, "=====");
  26123. + vchiq_log_error(vchiq_core_log_level,
  26124. + "============================================================"
  26125. + "================");
  26126. + vchiq_log_error(vchiq_core_log_level,
  26127. + "============================================================"
  26128. + "================");
  26129. +}
  26130. +
  26131. +
  26132. +VCHIQ_STATUS_T vchiq_send_remote_use(VCHIQ_STATE_T *state)
  26133. +{
  26134. + VCHIQ_STATUS_T status = VCHIQ_RETRY;
  26135. + if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED)
  26136. + status = queue_message(state, NULL,
  26137. + VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_USE, 0, 0),
  26138. + NULL, 0, 0, 0);
  26139. + return status;
  26140. +}
  26141. +
  26142. +VCHIQ_STATUS_T vchiq_send_remote_release(VCHIQ_STATE_T *state)
  26143. +{
  26144. + VCHIQ_STATUS_T status = VCHIQ_RETRY;
  26145. + if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED)
  26146. + status = queue_message(state, NULL,
  26147. + VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_RELEASE, 0, 0),
  26148. + NULL, 0, 0, 0);
  26149. + return status;
  26150. +}
  26151. +
  26152. +VCHIQ_STATUS_T vchiq_send_remote_use_active(VCHIQ_STATE_T *state)
  26153. +{
  26154. + VCHIQ_STATUS_T status = VCHIQ_RETRY;
  26155. + if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED)
  26156. + status = queue_message(state, NULL,
  26157. + VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_USE_ACTIVE, 0, 0),
  26158. + NULL, 0, 0, 0);
  26159. + return status;
  26160. +}
  26161. +
  26162. +void vchiq_log_dump_mem(const char *label, uint32_t addr, const void *voidMem,
  26163. + size_t numBytes)
  26164. +{
  26165. + const uint8_t *mem = (const uint8_t *)voidMem;
  26166. + size_t offset;
  26167. + char lineBuf[100];
  26168. + char *s;
  26169. +
  26170. + while (numBytes > 0) {
  26171. + s = lineBuf;
  26172. +
  26173. + for (offset = 0; offset < 16; offset++) {
  26174. + if (offset < numBytes)
  26175. + s += snprintf(s, 4, "%02x ", mem[offset]);
  26176. + else
  26177. + s += snprintf(s, 4, " ");
  26178. + }
  26179. +
  26180. + for (offset = 0; offset < 16; offset++) {
  26181. + if (offset < numBytes) {
  26182. + uint8_t ch = mem[offset];
  26183. +
  26184. + if ((ch < ' ') || (ch > '~'))
  26185. + ch = '.';
  26186. + *s++ = (char)ch;
  26187. + }
  26188. + }
  26189. + *s++ = '\0';
  26190. +
  26191. + if ((label != NULL) && (*label != '\0'))
  26192. + vchiq_log_trace(VCHIQ_LOG_TRACE,
  26193. + "%s: %08x: %s", label, addr, lineBuf);
  26194. + else
  26195. + vchiq_log_trace(VCHIQ_LOG_TRACE,
  26196. + "%08x: %s", addr, lineBuf);
  26197. +
  26198. + addr += 16;
  26199. + mem += 16;
  26200. + if (numBytes > 16)
  26201. + numBytes -= 16;
  26202. + else
  26203. + numBytes = 0;
  26204. + }
  26205. +}
  26206. diff -Nur linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h
  26207. --- linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h 1970-01-01 01:00:00.000000000 +0100
  26208. +++ linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h 2014-02-17 22:41:01.000000000 +0100
  26209. @@ -0,0 +1,706 @@
  26210. +/**
  26211. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  26212. + *
  26213. + * Redistribution and use in source and binary forms, with or without
  26214. + * modification, are permitted provided that the following conditions
  26215. + * are met:
  26216. + * 1. Redistributions of source code must retain the above copyright
  26217. + * notice, this list of conditions, and the following disclaimer,
  26218. + * without modification.
  26219. + * 2. Redistributions in binary form must reproduce the above copyright
  26220. + * notice, this list of conditions and the following disclaimer in the
  26221. + * documentation and/or other materials provided with the distribution.
  26222. + * 3. The names of the above-listed copyright holders may not be used
  26223. + * to endorse or promote products derived from this software without
  26224. + * specific prior written permission.
  26225. + *
  26226. + * ALTERNATIVELY, this software may be distributed under the terms of the
  26227. + * GNU General Public License ("GPL") version 2, as published by the Free
  26228. + * Software Foundation.
  26229. + *
  26230. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  26231. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  26232. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  26233. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  26234. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  26235. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  26236. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  26237. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  26238. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  26239. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  26240. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26241. + */
  26242. +
  26243. +#ifndef VCHIQ_CORE_H
  26244. +#define VCHIQ_CORE_H
  26245. +
  26246. +#include <linux/mutex.h>
  26247. +#include <linux/semaphore.h>
  26248. +#include <linux/kthread.h>
  26249. +
  26250. +#include "vchiq_cfg.h"
  26251. +
  26252. +#include "vchiq.h"
  26253. +
  26254. +/* Run time control of log level, based on KERN_XXX level. */
  26255. +#define VCHIQ_LOG_DEFAULT 4
  26256. +#define VCHIQ_LOG_ERROR 3
  26257. +#define VCHIQ_LOG_WARNING 4
  26258. +#define VCHIQ_LOG_INFO 6
  26259. +#define VCHIQ_LOG_TRACE 7
  26260. +
  26261. +#define VCHIQ_LOG_PREFIX KERN_INFO "vchiq: "
  26262. +
  26263. +#ifndef vchiq_log_error
  26264. +#define vchiq_log_error(cat, fmt, ...) \
  26265. + do { if (cat >= VCHIQ_LOG_ERROR) \
  26266. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  26267. +#endif
  26268. +#ifndef vchiq_log_warning
  26269. +#define vchiq_log_warning(cat, fmt, ...) \
  26270. + do { if (cat >= VCHIQ_LOG_WARNING) \
  26271. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  26272. +#endif
  26273. +#ifndef vchiq_log_info
  26274. +#define vchiq_log_info(cat, fmt, ...) \
  26275. + do { if (cat >= VCHIQ_LOG_INFO) \
  26276. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  26277. +#endif
  26278. +#ifndef vchiq_log_trace
  26279. +#define vchiq_log_trace(cat, fmt, ...) \
  26280. + do { if (cat >= VCHIQ_LOG_TRACE) \
  26281. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  26282. +#endif
  26283. +
  26284. +#define vchiq_loud_error(...) \
  26285. + vchiq_log_error(vchiq_core_log_level, "===== " __VA_ARGS__)
  26286. +
  26287. +#ifndef vchiq_static_assert
  26288. +#define vchiq_static_assert(cond) __attribute__((unused)) \
  26289. + extern int vchiq_static_assert[(cond) ? 1 : -1]
  26290. +#endif
  26291. +
  26292. +#define IS_POW2(x) (x && ((x & (x - 1)) == 0))
  26293. +
  26294. +/* Ensure that the slot size and maximum number of slots are powers of 2 */
  26295. +vchiq_static_assert(IS_POW2(VCHIQ_SLOT_SIZE));
  26296. +vchiq_static_assert(IS_POW2(VCHIQ_MAX_SLOTS));
  26297. +vchiq_static_assert(IS_POW2(VCHIQ_MAX_SLOTS_PER_SIDE));
  26298. +
  26299. +#define VCHIQ_SLOT_MASK (VCHIQ_SLOT_SIZE - 1)
  26300. +#define VCHIQ_SLOT_QUEUE_MASK (VCHIQ_MAX_SLOTS_PER_SIDE - 1)
  26301. +#define VCHIQ_SLOT_ZERO_SLOTS ((sizeof(VCHIQ_SLOT_ZERO_T) + \
  26302. + VCHIQ_SLOT_SIZE - 1) / VCHIQ_SLOT_SIZE)
  26303. +
  26304. +#define VCHIQ_MSG_PADDING 0 /* - */
  26305. +#define VCHIQ_MSG_CONNECT 1 /* - */
  26306. +#define VCHIQ_MSG_OPEN 2 /* + (srcport, -), fourcc, client_id */
  26307. +#define VCHIQ_MSG_OPENACK 3 /* + (srcport, dstport) */
  26308. +#define VCHIQ_MSG_CLOSE 4 /* + (srcport, dstport) */
  26309. +#define VCHIQ_MSG_DATA 5 /* + (srcport, dstport) */
  26310. +#define VCHIQ_MSG_BULK_RX 6 /* + (srcport, dstport), data, size */
  26311. +#define VCHIQ_MSG_BULK_TX 7 /* + (srcport, dstport), data, size */
  26312. +#define VCHIQ_MSG_BULK_RX_DONE 8 /* + (srcport, dstport), actual */
  26313. +#define VCHIQ_MSG_BULK_TX_DONE 9 /* + (srcport, dstport), actual */
  26314. +#define VCHIQ_MSG_PAUSE 10 /* - */
  26315. +#define VCHIQ_MSG_RESUME 11 /* - */
  26316. +#define VCHIQ_MSG_REMOTE_USE 12 /* - */
  26317. +#define VCHIQ_MSG_REMOTE_RELEASE 13 /* - */
  26318. +#define VCHIQ_MSG_REMOTE_USE_ACTIVE 14 /* - */
  26319. +
  26320. +#define VCHIQ_PORT_MAX (VCHIQ_MAX_SERVICES - 1)
  26321. +#define VCHIQ_PORT_FREE 0x1000
  26322. +#define VCHIQ_PORT_IS_VALID(port) (port < VCHIQ_PORT_FREE)
  26323. +#define VCHIQ_MAKE_MSG(type, srcport, dstport) \
  26324. + ((type<<24) | (srcport<<12) | (dstport<<0))
  26325. +#define VCHIQ_MSG_TYPE(msgid) ((unsigned int)msgid >> 24)
  26326. +#define VCHIQ_MSG_SRCPORT(msgid) \
  26327. + (unsigned short)(((unsigned int)msgid >> 12) & 0xfff)
  26328. +#define VCHIQ_MSG_DSTPORT(msgid) \
  26329. + ((unsigned short)msgid & 0xfff)
  26330. +
  26331. +#define VCHIQ_FOURCC_AS_4CHARS(fourcc) \
  26332. + ((fourcc) >> 24) & 0xff, \
  26333. + ((fourcc) >> 16) & 0xff, \
  26334. + ((fourcc) >> 8) & 0xff, \
  26335. + (fourcc) & 0xff
  26336. +
  26337. +/* Ensure the fields are wide enough */
  26338. +vchiq_static_assert(VCHIQ_MSG_SRCPORT(VCHIQ_MAKE_MSG(0, 0, VCHIQ_PORT_MAX))
  26339. + == 0);
  26340. +vchiq_static_assert(VCHIQ_MSG_TYPE(VCHIQ_MAKE_MSG(0, VCHIQ_PORT_MAX, 0)) == 0);
  26341. +vchiq_static_assert((unsigned int)VCHIQ_PORT_MAX <
  26342. + (unsigned int)VCHIQ_PORT_FREE);
  26343. +
  26344. +#define VCHIQ_MSGID_PADDING VCHIQ_MAKE_MSG(VCHIQ_MSG_PADDING, 0, 0)
  26345. +#define VCHIQ_MSGID_CLAIMED 0x40000000
  26346. +
  26347. +#define VCHIQ_FOURCC_INVALID 0x00000000
  26348. +#define VCHIQ_FOURCC_IS_LEGAL(fourcc) (fourcc != VCHIQ_FOURCC_INVALID)
  26349. +
  26350. +#define VCHIQ_BULK_ACTUAL_ABORTED -1
  26351. +
  26352. +typedef uint32_t BITSET_T;
  26353. +
  26354. +vchiq_static_assert((sizeof(BITSET_T) * 8) == 32);
  26355. +
  26356. +#define BITSET_SIZE(b) ((b + 31) >> 5)
  26357. +#define BITSET_WORD(b) (b >> 5)
  26358. +#define BITSET_BIT(b) (1 << (b & 31))
  26359. +#define BITSET_ZERO(bs) memset(bs, 0, sizeof(bs))
  26360. +#define BITSET_IS_SET(bs, b) (bs[BITSET_WORD(b)] & BITSET_BIT(b))
  26361. +#define BITSET_SET(bs, b) (bs[BITSET_WORD(b)] |= BITSET_BIT(b))
  26362. +#define BITSET_CLR(bs, b) (bs[BITSET_WORD(b)] &= ~BITSET_BIT(b))
  26363. +
  26364. +#if VCHIQ_ENABLE_STATS
  26365. +#define VCHIQ_STATS_INC(state, stat) (state->stats. stat++)
  26366. +#define VCHIQ_SERVICE_STATS_INC(service, stat) (service->stats. stat++)
  26367. +#define VCHIQ_SERVICE_STATS_ADD(service, stat, addend) \
  26368. + (service->stats. stat += addend)
  26369. +#else
  26370. +#define VCHIQ_STATS_INC(state, stat) ((void)0)
  26371. +#define VCHIQ_SERVICE_STATS_INC(service, stat) ((void)0)
  26372. +#define VCHIQ_SERVICE_STATS_ADD(service, stat, addend) ((void)0)
  26373. +#endif
  26374. +
  26375. +enum {
  26376. + DEBUG_ENTRIES,
  26377. +#if VCHIQ_ENABLE_DEBUG
  26378. + DEBUG_SLOT_HANDLER_COUNT,
  26379. + DEBUG_SLOT_HANDLER_LINE,
  26380. + DEBUG_PARSE_LINE,
  26381. + DEBUG_PARSE_HEADER,
  26382. + DEBUG_PARSE_MSGID,
  26383. + DEBUG_AWAIT_COMPLETION_LINE,
  26384. + DEBUG_DEQUEUE_MESSAGE_LINE,
  26385. + DEBUG_SERVICE_CALLBACK_LINE,
  26386. + DEBUG_MSG_QUEUE_FULL_COUNT,
  26387. + DEBUG_COMPLETION_QUEUE_FULL_COUNT,
  26388. +#endif
  26389. + DEBUG_MAX
  26390. +};
  26391. +
  26392. +#if VCHIQ_ENABLE_DEBUG
  26393. +
  26394. +#define DEBUG_INITIALISE(local) int *debug_ptr = (local)->debug;
  26395. +#define DEBUG_TRACE(d) \
  26396. + do { debug_ptr[DEBUG_ ## d] = __LINE__; dsb(); } while (0)
  26397. +#define DEBUG_VALUE(d, v) \
  26398. + do { debug_ptr[DEBUG_ ## d] = (v); dsb(); } while (0)
  26399. +#define DEBUG_COUNT(d) \
  26400. + do { debug_ptr[DEBUG_ ## d]++; dsb(); } while (0)
  26401. +
  26402. +#else /* VCHIQ_ENABLE_DEBUG */
  26403. +
  26404. +#define DEBUG_INITIALISE(local)
  26405. +#define DEBUG_TRACE(d)
  26406. +#define DEBUG_VALUE(d, v)
  26407. +#define DEBUG_COUNT(d)
  26408. +
  26409. +#endif /* VCHIQ_ENABLE_DEBUG */
  26410. +
  26411. +typedef enum {
  26412. + VCHIQ_CONNSTATE_DISCONNECTED,
  26413. + VCHIQ_CONNSTATE_CONNECTING,
  26414. + VCHIQ_CONNSTATE_CONNECTED,
  26415. + VCHIQ_CONNSTATE_PAUSING,
  26416. + VCHIQ_CONNSTATE_PAUSE_SENT,
  26417. + VCHIQ_CONNSTATE_PAUSED,
  26418. + VCHIQ_CONNSTATE_RESUMING,
  26419. + VCHIQ_CONNSTATE_PAUSE_TIMEOUT,
  26420. + VCHIQ_CONNSTATE_RESUME_TIMEOUT
  26421. +} VCHIQ_CONNSTATE_T;
  26422. +
  26423. +enum {
  26424. + VCHIQ_SRVSTATE_FREE,
  26425. + VCHIQ_SRVSTATE_HIDDEN,
  26426. + VCHIQ_SRVSTATE_LISTENING,
  26427. + VCHIQ_SRVSTATE_OPENING,
  26428. + VCHIQ_SRVSTATE_OPEN,
  26429. + VCHIQ_SRVSTATE_OPENSYNC,
  26430. + VCHIQ_SRVSTATE_CLOSESENT,
  26431. + VCHIQ_SRVSTATE_CLOSERECVD,
  26432. + VCHIQ_SRVSTATE_CLOSEWAIT,
  26433. + VCHIQ_SRVSTATE_CLOSED
  26434. +};
  26435. +
  26436. +enum {
  26437. + VCHIQ_POLL_TERMINATE,
  26438. + VCHIQ_POLL_REMOVE,
  26439. + VCHIQ_POLL_TXNOTIFY,
  26440. + VCHIQ_POLL_RXNOTIFY,
  26441. + VCHIQ_POLL_COUNT
  26442. +};
  26443. +
  26444. +typedef enum {
  26445. + VCHIQ_BULK_TRANSMIT,
  26446. + VCHIQ_BULK_RECEIVE
  26447. +} VCHIQ_BULK_DIR_T;
  26448. +
  26449. +typedef void (*VCHIQ_USERDATA_TERM_T)(void *userdata);
  26450. +
  26451. +typedef struct vchiq_bulk_struct {
  26452. + short mode;
  26453. + short dir;
  26454. + void *userdata;
  26455. + VCHI_MEM_HANDLE_T handle;
  26456. + void *data;
  26457. + int size;
  26458. + void *remote_data;
  26459. + int remote_size;
  26460. + int actual;
  26461. +} VCHIQ_BULK_T;
  26462. +
  26463. +typedef struct vchiq_bulk_queue_struct {
  26464. + int local_insert; /* Where to insert the next local bulk */
  26465. + int remote_insert; /* Where to insert the next remote bulk (master) */
  26466. + int process; /* Bulk to transfer next */
  26467. + int remote_notify; /* Bulk to notify the remote client of next (mstr) */
  26468. + int remove; /* Bulk to notify the local client of, and remove,
  26469. + ** next */
  26470. + VCHIQ_BULK_T bulks[VCHIQ_NUM_SERVICE_BULKS];
  26471. +} VCHIQ_BULK_QUEUE_T;
  26472. +
  26473. +typedef struct remote_event_struct {
  26474. + int armed;
  26475. + int fired;
  26476. + struct semaphore *event;
  26477. +} REMOTE_EVENT_T;
  26478. +
  26479. +typedef struct opaque_platform_state_t *VCHIQ_PLATFORM_STATE_T;
  26480. +
  26481. +typedef struct vchiq_state_struct VCHIQ_STATE_T;
  26482. +
  26483. +typedef struct vchiq_slot_struct {
  26484. + char data[VCHIQ_SLOT_SIZE];
  26485. +} VCHIQ_SLOT_T;
  26486. +
  26487. +typedef struct vchiq_slot_info_struct {
  26488. + /* Use two counters rather than one to avoid the need for a mutex. */
  26489. + short use_count;
  26490. + short release_count;
  26491. +} VCHIQ_SLOT_INFO_T;
  26492. +
  26493. +typedef struct vchiq_service_struct {
  26494. + VCHIQ_SERVICE_BASE_T base;
  26495. + VCHIQ_SERVICE_HANDLE_T handle;
  26496. + unsigned int ref_count;
  26497. + int srvstate;
  26498. + VCHIQ_USERDATA_TERM_T userdata_term;
  26499. + unsigned int localport;
  26500. + unsigned int remoteport;
  26501. + int public_fourcc;
  26502. + int client_id;
  26503. + char auto_close;
  26504. + char sync;
  26505. + char closing;
  26506. + atomic_t poll_flags;
  26507. + short version;
  26508. + short version_min;
  26509. + short peer_version;
  26510. +
  26511. + VCHIQ_STATE_T *state;
  26512. + VCHIQ_INSTANCE_T instance;
  26513. +
  26514. + int service_use_count;
  26515. +
  26516. + VCHIQ_BULK_QUEUE_T bulk_tx;
  26517. + VCHIQ_BULK_QUEUE_T bulk_rx;
  26518. +
  26519. + struct semaphore remove_event;
  26520. + struct semaphore bulk_remove_event;
  26521. + struct mutex bulk_mutex;
  26522. +
  26523. + struct service_stats_struct {
  26524. + int quota_stalls;
  26525. + int slot_stalls;
  26526. + int bulk_stalls;
  26527. + int error_count;
  26528. + int ctrl_tx_count;
  26529. + int ctrl_rx_count;
  26530. + int bulk_tx_count;
  26531. + int bulk_rx_count;
  26532. + int bulk_aborted_count;
  26533. + uint64_t ctrl_tx_bytes;
  26534. + uint64_t ctrl_rx_bytes;
  26535. + uint64_t bulk_tx_bytes;
  26536. + uint64_t bulk_rx_bytes;
  26537. + } stats;
  26538. +} VCHIQ_SERVICE_T;
  26539. +
  26540. +/* The quota information is outside VCHIQ_SERVICE_T so that it can be
  26541. + statically allocated, since for accounting reasons a service's slot
  26542. + usage is carried over between users of the same port number.
  26543. + */
  26544. +typedef struct vchiq_service_quota_struct {
  26545. + unsigned short slot_quota;
  26546. + unsigned short slot_use_count;
  26547. + unsigned short message_quota;
  26548. + unsigned short message_use_count;
  26549. + struct semaphore quota_event;
  26550. + int previous_tx_index;
  26551. +} VCHIQ_SERVICE_QUOTA_T;
  26552. +
  26553. +typedef struct vchiq_shared_state_struct {
  26554. +
  26555. + /* A non-zero value here indicates that the content is valid. */
  26556. + int initialised;
  26557. +
  26558. + /* The first and last (inclusive) slots allocated to the owner. */
  26559. + int slot_first;
  26560. + int slot_last;
  26561. +
  26562. + /* The slot allocated to synchronous messages from the owner. */
  26563. + int slot_sync;
  26564. +
  26565. + /* Signalling this event indicates that owner's slot handler thread
  26566. + ** should run. */
  26567. + REMOTE_EVENT_T trigger;
  26568. +
  26569. + /* Indicates the byte position within the stream where the next message
  26570. + ** will be written. The least significant bits are an index into the
  26571. + ** slot. The next bits are the index of the slot in slot_queue. */
  26572. + int tx_pos;
  26573. +
  26574. + /* This event should be signalled when a slot is recycled. */
  26575. + REMOTE_EVENT_T recycle;
  26576. +
  26577. + /* The slot_queue index where the next recycled slot will be written. */
  26578. + int slot_queue_recycle;
  26579. +
  26580. + /* This event should be signalled when a synchronous message is sent. */
  26581. + REMOTE_EVENT_T sync_trigger;
  26582. +
  26583. + /* This event should be signalled when a synchronous message has been
  26584. + ** released. */
  26585. + REMOTE_EVENT_T sync_release;
  26586. +
  26587. + /* A circular buffer of slot indexes. */
  26588. + int slot_queue[VCHIQ_MAX_SLOTS_PER_SIDE];
  26589. +
  26590. + /* Debugging state */
  26591. + int debug[DEBUG_MAX];
  26592. +} VCHIQ_SHARED_STATE_T;
  26593. +
  26594. +typedef struct vchiq_slot_zero_struct {
  26595. + int magic;
  26596. + short version;
  26597. + short version_min;
  26598. + int slot_zero_size;
  26599. + int slot_size;
  26600. + int max_slots;
  26601. + int max_slots_per_side;
  26602. + int platform_data[2];
  26603. + VCHIQ_SHARED_STATE_T master;
  26604. + VCHIQ_SHARED_STATE_T slave;
  26605. + VCHIQ_SLOT_INFO_T slots[VCHIQ_MAX_SLOTS];
  26606. +} VCHIQ_SLOT_ZERO_T;
  26607. +
  26608. +struct vchiq_state_struct {
  26609. + int id;
  26610. + int initialised;
  26611. + VCHIQ_CONNSTATE_T conn_state;
  26612. + int is_master;
  26613. +
  26614. + VCHIQ_SHARED_STATE_T *local;
  26615. + VCHIQ_SHARED_STATE_T *remote;
  26616. + VCHIQ_SLOT_T *slot_data;
  26617. +
  26618. + unsigned short default_slot_quota;
  26619. + unsigned short default_message_quota;
  26620. +
  26621. + /* Event indicating connect message received */
  26622. + struct semaphore connect;
  26623. +
  26624. + /* Mutex protecting services */
  26625. + struct mutex mutex;
  26626. + VCHIQ_INSTANCE_T *instance;
  26627. +
  26628. + /* Processes incoming messages */
  26629. + struct task_struct *slot_handler_thread;
  26630. +
  26631. + /* Processes recycled slots */
  26632. + struct task_struct *recycle_thread;
  26633. +
  26634. + /* Processes synchronous messages */
  26635. + struct task_struct *sync_thread;
  26636. +
  26637. + /* Local implementation of the trigger remote event */
  26638. + struct semaphore trigger_event;
  26639. +
  26640. + /* Local implementation of the recycle remote event */
  26641. + struct semaphore recycle_event;
  26642. +
  26643. + /* Local implementation of the sync trigger remote event */
  26644. + struct semaphore sync_trigger_event;
  26645. +
  26646. + /* Local implementation of the sync release remote event */
  26647. + struct semaphore sync_release_event;
  26648. +
  26649. + char *tx_data;
  26650. + char *rx_data;
  26651. + VCHIQ_SLOT_INFO_T *rx_info;
  26652. +
  26653. + struct mutex slot_mutex;
  26654. +
  26655. + struct mutex recycle_mutex;
  26656. +
  26657. + struct mutex sync_mutex;
  26658. +
  26659. + struct mutex bulk_transfer_mutex;
  26660. +
  26661. + /* Indicates the byte position within the stream from where the next
  26662. + ** message will be read. The least significant bits are an index into
  26663. + ** the slot.The next bits are the index of the slot in
  26664. + ** remote->slot_queue. */
  26665. + int rx_pos;
  26666. +
  26667. + /* A cached copy of local->tx_pos. Only write to local->tx_pos, and read
  26668. + from remote->tx_pos. */
  26669. + int local_tx_pos;
  26670. +
  26671. + /* The slot_queue index of the slot to become available next. */
  26672. + int slot_queue_available;
  26673. +
  26674. + /* A flag to indicate if any poll has been requested */
  26675. + int poll_needed;
  26676. +
  26677. + /* Ths index of the previous slot used for data messages. */
  26678. + int previous_data_index;
  26679. +
  26680. + /* The number of slots occupied by data messages. */
  26681. + unsigned short data_use_count;
  26682. +
  26683. + /* The maximum number of slots to be occupied by data messages. */
  26684. + unsigned short data_quota;
  26685. +
  26686. + /* An array of bit sets indicating which services must be polled. */
  26687. + atomic_t poll_services[BITSET_SIZE(VCHIQ_MAX_SERVICES)];
  26688. +
  26689. + /* The number of the first unused service */
  26690. + int unused_service;
  26691. +
  26692. + /* Signalled when a free slot becomes available. */
  26693. + struct semaphore slot_available_event;
  26694. +
  26695. + struct semaphore slot_remove_event;
  26696. +
  26697. + /* Signalled when a free data slot becomes available. */
  26698. + struct semaphore data_quota_event;
  26699. +
  26700. + /* Incremented when there are bulk transfers which cannot be processed
  26701. + * whilst paused and must be processed on resume */
  26702. + int deferred_bulks;
  26703. +
  26704. + struct state_stats_struct {
  26705. + int slot_stalls;
  26706. + int data_stalls;
  26707. + int ctrl_tx_count;
  26708. + int ctrl_rx_count;
  26709. + int error_count;
  26710. + } stats;
  26711. +
  26712. + VCHIQ_SERVICE_T * services[VCHIQ_MAX_SERVICES];
  26713. + VCHIQ_SERVICE_QUOTA_T service_quotas[VCHIQ_MAX_SERVICES];
  26714. + VCHIQ_SLOT_INFO_T slot_info[VCHIQ_MAX_SLOTS];
  26715. +
  26716. + VCHIQ_PLATFORM_STATE_T platform_state;
  26717. +};
  26718. +
  26719. +struct bulk_waiter {
  26720. + VCHIQ_BULK_T *bulk;
  26721. + struct semaphore event;
  26722. + int actual;
  26723. +};
  26724. +
  26725. +extern spinlock_t bulk_waiter_spinlock;
  26726. +
  26727. +extern int vchiq_core_log_level;
  26728. +extern int vchiq_core_msg_log_level;
  26729. +extern int vchiq_sync_log_level;
  26730. +
  26731. +extern VCHIQ_STATE_T *vchiq_states[VCHIQ_MAX_STATES];
  26732. +
  26733. +extern const char *
  26734. +get_conn_state_name(VCHIQ_CONNSTATE_T conn_state);
  26735. +
  26736. +extern VCHIQ_SLOT_ZERO_T *
  26737. +vchiq_init_slots(void *mem_base, int mem_size);
  26738. +
  26739. +extern VCHIQ_STATUS_T
  26740. +vchiq_init_state(VCHIQ_STATE_T *state, VCHIQ_SLOT_ZERO_T *slot_zero,
  26741. + int is_master);
  26742. +
  26743. +extern VCHIQ_STATUS_T
  26744. +vchiq_connect_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance);
  26745. +
  26746. +extern VCHIQ_SERVICE_T *
  26747. +vchiq_add_service_internal(VCHIQ_STATE_T *state,
  26748. + const VCHIQ_SERVICE_PARAMS_T *params, int srvstate,
  26749. + VCHIQ_INSTANCE_T instance, VCHIQ_USERDATA_TERM_T userdata_term);
  26750. +
  26751. +extern VCHIQ_STATUS_T
  26752. +vchiq_open_service_internal(VCHIQ_SERVICE_T *service, int client_id);
  26753. +
  26754. +extern VCHIQ_STATUS_T
  26755. +vchiq_close_service_internal(VCHIQ_SERVICE_T *service, int close_recvd);
  26756. +
  26757. +extern void
  26758. +vchiq_terminate_service_internal(VCHIQ_SERVICE_T *service);
  26759. +
  26760. +extern void
  26761. +vchiq_free_service_internal(VCHIQ_SERVICE_T *service);
  26762. +
  26763. +extern VCHIQ_STATUS_T
  26764. +vchiq_shutdown_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance);
  26765. +
  26766. +extern VCHIQ_STATUS_T
  26767. +vchiq_pause_internal(VCHIQ_STATE_T *state);
  26768. +
  26769. +extern VCHIQ_STATUS_T
  26770. +vchiq_resume_internal(VCHIQ_STATE_T *state);
  26771. +
  26772. +extern void
  26773. +remote_event_pollall(VCHIQ_STATE_T *state);
  26774. +
  26775. +extern VCHIQ_STATUS_T
  26776. +vchiq_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle,
  26777. + VCHI_MEM_HANDLE_T memhandle, void *offset, int size, void *userdata,
  26778. + VCHIQ_BULK_MODE_T mode, VCHIQ_BULK_DIR_T dir);
  26779. +
  26780. +extern void
  26781. +vchiq_dump_state(void *dump_context, VCHIQ_STATE_T *state);
  26782. +
  26783. +extern void
  26784. +vchiq_dump_service_state(void *dump_context, VCHIQ_SERVICE_T *service);
  26785. +
  26786. +extern void
  26787. +vchiq_loud_error_header(void);
  26788. +
  26789. +extern void
  26790. +vchiq_loud_error_footer(void);
  26791. +
  26792. +extern void
  26793. +request_poll(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service, int poll_type);
  26794. +
  26795. +static inline VCHIQ_SERVICE_T *
  26796. +handle_to_service(VCHIQ_SERVICE_HANDLE_T handle)
  26797. +{
  26798. + VCHIQ_STATE_T *state = vchiq_states[(handle / VCHIQ_MAX_SERVICES) &
  26799. + (VCHIQ_MAX_STATES - 1)];
  26800. + if (!state)
  26801. + return NULL;
  26802. +
  26803. + return state->services[handle & (VCHIQ_MAX_SERVICES - 1)];
  26804. +}
  26805. +
  26806. +extern VCHIQ_SERVICE_T *
  26807. +find_service_by_handle(VCHIQ_SERVICE_HANDLE_T handle);
  26808. +
  26809. +extern VCHIQ_SERVICE_T *
  26810. +find_service_by_port(VCHIQ_STATE_T *state, int localport);
  26811. +
  26812. +extern VCHIQ_SERVICE_T *
  26813. +find_service_for_instance(VCHIQ_INSTANCE_T instance,
  26814. + VCHIQ_SERVICE_HANDLE_T handle);
  26815. +
  26816. +extern VCHIQ_SERVICE_T *
  26817. +next_service_by_instance(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance,
  26818. + int *pidx);
  26819. +
  26820. +extern void
  26821. +lock_service(VCHIQ_SERVICE_T *service);
  26822. +
  26823. +extern void
  26824. +unlock_service(VCHIQ_SERVICE_T *service);
  26825. +
  26826. +/* The following functions are called from vchiq_core, and external
  26827. +** implementations must be provided. */
  26828. +
  26829. +extern VCHIQ_STATUS_T
  26830. +vchiq_prepare_bulk_data(VCHIQ_BULK_T *bulk,
  26831. + VCHI_MEM_HANDLE_T memhandle, void *offset, int size, int dir);
  26832. +
  26833. +extern void
  26834. +vchiq_transfer_bulk(VCHIQ_BULK_T *bulk);
  26835. +
  26836. +extern void
  26837. +vchiq_complete_bulk(VCHIQ_BULK_T *bulk);
  26838. +
  26839. +extern VCHIQ_STATUS_T
  26840. +vchiq_copy_from_user(void *dst, const void *src, int size);
  26841. +
  26842. +extern void
  26843. +remote_event_signal(REMOTE_EVENT_T *event);
  26844. +
  26845. +void
  26846. +vchiq_platform_check_suspend(VCHIQ_STATE_T *state);
  26847. +
  26848. +extern void
  26849. +vchiq_platform_paused(VCHIQ_STATE_T *state);
  26850. +
  26851. +extern VCHIQ_STATUS_T
  26852. +vchiq_platform_resume(VCHIQ_STATE_T *state);
  26853. +
  26854. +extern void
  26855. +vchiq_platform_resumed(VCHIQ_STATE_T *state);
  26856. +
  26857. +extern void
  26858. +vchiq_dump(void *dump_context, const char *str, int len);
  26859. +
  26860. +extern void
  26861. +vchiq_dump_platform_state(void *dump_context);
  26862. +
  26863. +extern void
  26864. +vchiq_dump_platform_instances(void *dump_context);
  26865. +
  26866. +extern void
  26867. +vchiq_dump_platform_service_state(void *dump_context,
  26868. + VCHIQ_SERVICE_T *service);
  26869. +
  26870. +extern VCHIQ_STATUS_T
  26871. +vchiq_use_service_internal(VCHIQ_SERVICE_T *service);
  26872. +
  26873. +extern VCHIQ_STATUS_T
  26874. +vchiq_release_service_internal(VCHIQ_SERVICE_T *service);
  26875. +
  26876. +extern void
  26877. +vchiq_on_remote_use(VCHIQ_STATE_T *state);
  26878. +
  26879. +extern void
  26880. +vchiq_on_remote_release(VCHIQ_STATE_T *state);
  26881. +
  26882. +extern VCHIQ_STATUS_T
  26883. +vchiq_platform_init_state(VCHIQ_STATE_T *state);
  26884. +
  26885. +extern VCHIQ_STATUS_T
  26886. +vchiq_check_service(VCHIQ_SERVICE_T *service);
  26887. +
  26888. +extern void
  26889. +vchiq_on_remote_use_active(VCHIQ_STATE_T *state);
  26890. +
  26891. +extern VCHIQ_STATUS_T
  26892. +vchiq_send_remote_use(VCHIQ_STATE_T *state);
  26893. +
  26894. +extern VCHIQ_STATUS_T
  26895. +vchiq_send_remote_release(VCHIQ_STATE_T *state);
  26896. +
  26897. +extern VCHIQ_STATUS_T
  26898. +vchiq_send_remote_use_active(VCHIQ_STATE_T *state);
  26899. +
  26900. +extern void
  26901. +vchiq_platform_conn_state_changed(VCHIQ_STATE_T *state,
  26902. + VCHIQ_CONNSTATE_T oldstate, VCHIQ_CONNSTATE_T newstate);
  26903. +
  26904. +extern void
  26905. +vchiq_platform_handle_timeout(VCHIQ_STATE_T *state);
  26906. +
  26907. +extern void
  26908. +vchiq_set_conn_state(VCHIQ_STATE_T *state, VCHIQ_CONNSTATE_T newstate);
  26909. +
  26910. +
  26911. +extern void
  26912. +vchiq_log_dump_mem(const char *label, uint32_t addr, const void *voidMem,
  26913. + size_t numBytes);
  26914. +
  26915. +#endif
  26916. diff -Nur linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion
  26917. --- linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion 1970-01-01 01:00:00.000000000 +0100
  26918. +++ linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion 2014-02-17 22:41:01.000000000 +0100
  26919. @@ -0,0 +1,87 @@
  26920. +#!/usr/bin/perl -w
  26921. +
  26922. +use strict;
  26923. +
  26924. +#
  26925. +# Generate a version from available information
  26926. +#
  26927. +
  26928. +my $prefix = shift @ARGV;
  26929. +my $root = shift @ARGV;
  26930. +
  26931. +
  26932. +if ( not defined $root ) {
  26933. + die "usage: $0 prefix root-dir\n";
  26934. +}
  26935. +
  26936. +if ( ! -d $root ) {
  26937. + die "root directory $root not found\n";
  26938. +}
  26939. +
  26940. +my $version = "unknown";
  26941. +my $tainted = "";
  26942. +
  26943. +if ( -d "$root/.git" ) {
  26944. + # attempt to work out git version. only do so
  26945. + # on a linux build host, as cygwin builds are
  26946. + # already slow enough
  26947. +
  26948. + if ( -f "/usr/bin/git" || -f "/usr/local/bin/git" ) {
  26949. + if (not open(F, "git --git-dir $root/.git rev-parse --verify HEAD|")) {
  26950. + $version = "no git version";
  26951. + }
  26952. + else {
  26953. + $version = <F>;
  26954. + $version =~ s/[ \r\n]*$//; # chomp may not be enough (cygwin).
  26955. + $version =~ s/^[ \r\n]*//; # chomp may not be enough (cygwin).
  26956. + }
  26957. +
  26958. + if (open(G, "git --git-dir $root/.git status --porcelain|")) {
  26959. + $tainted = <G>;
  26960. + $tainted =~ s/[ \r\n]*$//; # chomp may not be enough (cygwin).
  26961. + $tainted =~ s/^[ \r\n]*//; # chomp may not be enough (cygwin).
  26962. + if (length $tainted) {
  26963. + $version = join ' ', $version, "(tainted)";
  26964. + }
  26965. + else {
  26966. + $version = join ' ', $version, "(clean)";
  26967. + }
  26968. + }
  26969. + }
  26970. +}
  26971. +
  26972. +my $hostname = `hostname`;
  26973. +$hostname =~ s/[ \r\n]*$//; # chomp may not be enough (cygwin).
  26974. +$hostname =~ s/^[ \r\n]*//; # chomp may not be enough (cygwin).
  26975. +
  26976. +
  26977. +print STDERR "Version $version\n";
  26978. +print <<EOF;
  26979. +#include "${prefix}_build_info.h"
  26980. +#include <linux/broadcom/vc_debug_sym.h>
  26981. +
  26982. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_hostname, "$hostname" );
  26983. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_version, "$version" );
  26984. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_time, __TIME__ );
  26985. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_date, __DATE__ );
  26986. +
  26987. +const char *vchiq_get_build_hostname( void )
  26988. +{
  26989. + return vchiq_build_hostname;
  26990. +}
  26991. +
  26992. +const char *vchiq_get_build_version( void )
  26993. +{
  26994. + return vchiq_build_version;
  26995. +}
  26996. +
  26997. +const char *vchiq_get_build_date( void )
  26998. +{
  26999. + return vchiq_build_date;
  27000. +}
  27001. +
  27002. +const char *vchiq_get_build_time( void )
  27003. +{
  27004. + return vchiq_build_time;
  27005. +}
  27006. +EOF
  27007. diff -Nur linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h
  27008. --- linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h 1970-01-01 01:00:00.000000000 +0100
  27009. +++ linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h 2014-02-17 22:41:01.000000000 +0100
  27010. @@ -0,0 +1,40 @@
  27011. +/**
  27012. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  27013. + *
  27014. + * Redistribution and use in source and binary forms, with or without
  27015. + * modification, are permitted provided that the following conditions
  27016. + * are met:
  27017. + * 1. Redistributions of source code must retain the above copyright
  27018. + * notice, this list of conditions, and the following disclaimer,
  27019. + * without modification.
  27020. + * 2. Redistributions in binary form must reproduce the above copyright
  27021. + * notice, this list of conditions and the following disclaimer in the
  27022. + * documentation and/or other materials provided with the distribution.
  27023. + * 3. The names of the above-listed copyright holders may not be used
  27024. + * to endorse or promote products derived from this software without
  27025. + * specific prior written permission.
  27026. + *
  27027. + * ALTERNATIVELY, this software may be distributed under the terms of the
  27028. + * GNU General Public License ("GPL") version 2, as published by the Free
  27029. + * Software Foundation.
  27030. + *
  27031. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  27032. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  27033. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  27034. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  27035. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  27036. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  27037. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27038. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  27039. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  27040. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27041. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27042. + */
  27043. +
  27044. +#ifndef VCHIQ_VCHIQ_H
  27045. +#define VCHIQ_VCHIQ_H
  27046. +
  27047. +#include "vchiq_if.h"
  27048. +#include "vchiq_util.h"
  27049. +
  27050. +#endif
  27051. diff -Nur linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h
  27052. --- linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h 1970-01-01 01:00:00.000000000 +0100
  27053. +++ linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h 2014-02-17 22:41:01.000000000 +0100
  27054. @@ -0,0 +1,188 @@
  27055. +/**
  27056. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  27057. + *
  27058. + * Redistribution and use in source and binary forms, with or without
  27059. + * modification, are permitted provided that the following conditions
  27060. + * are met:
  27061. + * 1. Redistributions of source code must retain the above copyright
  27062. + * notice, this list of conditions, and the following disclaimer,
  27063. + * without modification.
  27064. + * 2. Redistributions in binary form must reproduce the above copyright
  27065. + * notice, this list of conditions and the following disclaimer in the
  27066. + * documentation and/or other materials provided with the distribution.
  27067. + * 3. The names of the above-listed copyright holders may not be used
  27068. + * to endorse or promote products derived from this software without
  27069. + * specific prior written permission.
  27070. + *
  27071. + * ALTERNATIVELY, this software may be distributed under the terms of the
  27072. + * GNU General Public License ("GPL") version 2, as published by the Free
  27073. + * Software Foundation.
  27074. + *
  27075. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  27076. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  27077. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  27078. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  27079. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  27080. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  27081. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27082. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  27083. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  27084. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27085. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27086. + */
  27087. +
  27088. +#ifndef VCHIQ_IF_H
  27089. +#define VCHIQ_IF_H
  27090. +
  27091. +#include "interface/vchi/vchi_mh.h"
  27092. +
  27093. +#define VCHIQ_SERVICE_HANDLE_INVALID 0
  27094. +
  27095. +#define VCHIQ_SLOT_SIZE 4096
  27096. +#define VCHIQ_MAX_MSG_SIZE (VCHIQ_SLOT_SIZE - sizeof(VCHIQ_HEADER_T))
  27097. +#define VCHIQ_CHANNEL_SIZE VCHIQ_MAX_MSG_SIZE /* For backwards compatibility */
  27098. +
  27099. +#define VCHIQ_MAKE_FOURCC(x0, x1, x2, x3) \
  27100. + (((x0) << 24) | ((x1) << 16) | ((x2) << 8) | (x3))
  27101. +#define VCHIQ_GET_SERVICE_USERDATA(service) vchiq_get_service_userdata(service)
  27102. +#define VCHIQ_GET_SERVICE_FOURCC(service) vchiq_get_service_fourcc(service)
  27103. +
  27104. +typedef enum {
  27105. + VCHIQ_SERVICE_OPENED, /* service, -, - */
  27106. + VCHIQ_SERVICE_CLOSED, /* service, -, - */
  27107. + VCHIQ_MESSAGE_AVAILABLE, /* service, header, - */
  27108. + VCHIQ_BULK_TRANSMIT_DONE, /* service, -, bulk_userdata */
  27109. + VCHIQ_BULK_RECEIVE_DONE, /* service, -, bulk_userdata */
  27110. + VCHIQ_BULK_TRANSMIT_ABORTED, /* service, -, bulk_userdata */
  27111. + VCHIQ_BULK_RECEIVE_ABORTED /* service, -, bulk_userdata */
  27112. +} VCHIQ_REASON_T;
  27113. +
  27114. +typedef enum {
  27115. + VCHIQ_ERROR = -1,
  27116. + VCHIQ_SUCCESS = 0,
  27117. + VCHIQ_RETRY = 1
  27118. +} VCHIQ_STATUS_T;
  27119. +
  27120. +typedef enum {
  27121. + VCHIQ_BULK_MODE_CALLBACK,
  27122. + VCHIQ_BULK_MODE_BLOCKING,
  27123. + VCHIQ_BULK_MODE_NOCALLBACK,
  27124. + VCHIQ_BULK_MODE_WAITING /* Reserved for internal use */
  27125. +} VCHIQ_BULK_MODE_T;
  27126. +
  27127. +typedef enum {
  27128. + VCHIQ_SERVICE_OPTION_AUTOCLOSE,
  27129. + VCHIQ_SERVICE_OPTION_SLOT_QUOTA,
  27130. + VCHIQ_SERVICE_OPTION_MESSAGE_QUOTA,
  27131. + VCHIQ_SERVICE_OPTION_SYNCHRONOUS
  27132. +} VCHIQ_SERVICE_OPTION_T;
  27133. +
  27134. +typedef struct vchiq_header_struct {
  27135. + /* The message identifier - opaque to applications. */
  27136. + int msgid;
  27137. +
  27138. + /* Size of message data. */
  27139. + unsigned int size;
  27140. +
  27141. + char data[0]; /* message */
  27142. +} VCHIQ_HEADER_T;
  27143. +
  27144. +typedef struct {
  27145. + const void *data;
  27146. + unsigned int size;
  27147. +} VCHIQ_ELEMENT_T;
  27148. +
  27149. +typedef unsigned int VCHIQ_SERVICE_HANDLE_T;
  27150. +
  27151. +typedef VCHIQ_STATUS_T (*VCHIQ_CALLBACK_T)(VCHIQ_REASON_T, VCHIQ_HEADER_T *,
  27152. + VCHIQ_SERVICE_HANDLE_T, void *);
  27153. +
  27154. +typedef struct vchiq_service_base_struct {
  27155. + int fourcc;
  27156. + VCHIQ_CALLBACK_T callback;
  27157. + void *userdata;
  27158. +} VCHIQ_SERVICE_BASE_T;
  27159. +
  27160. +typedef struct vchiq_service_params_struct {
  27161. + int fourcc;
  27162. + VCHIQ_CALLBACK_T callback;
  27163. + void *userdata;
  27164. + short version; /* Increment for non-trivial changes */
  27165. + short version_min; /* Update for incompatible changes */
  27166. +} VCHIQ_SERVICE_PARAMS_T;
  27167. +
  27168. +typedef struct vchiq_config_struct {
  27169. + unsigned int max_msg_size;
  27170. + unsigned int bulk_threshold; /* The message size above which it
  27171. + is better to use a bulk transfer
  27172. + (<= max_msg_size) */
  27173. + unsigned int max_outstanding_bulks;
  27174. + unsigned int max_services;
  27175. + short version; /* The version of VCHIQ */
  27176. + short version_min; /* The minimum compatible version of VCHIQ */
  27177. +} VCHIQ_CONFIG_T;
  27178. +
  27179. +typedef struct vchiq_instance_struct *VCHIQ_INSTANCE_T;
  27180. +typedef void (*VCHIQ_REMOTE_USE_CALLBACK_T)(void *cb_arg);
  27181. +
  27182. +extern VCHIQ_STATUS_T vchiq_initialise(VCHIQ_INSTANCE_T *pinstance);
  27183. +extern VCHIQ_STATUS_T vchiq_shutdown(VCHIQ_INSTANCE_T instance);
  27184. +extern VCHIQ_STATUS_T vchiq_connect(VCHIQ_INSTANCE_T instance);
  27185. +extern VCHIQ_STATUS_T vchiq_add_service(VCHIQ_INSTANCE_T instance,
  27186. + const VCHIQ_SERVICE_PARAMS_T *params,
  27187. + VCHIQ_SERVICE_HANDLE_T *pservice);
  27188. +extern VCHIQ_STATUS_T vchiq_open_service(VCHIQ_INSTANCE_T instance,
  27189. + const VCHIQ_SERVICE_PARAMS_T *params,
  27190. + VCHIQ_SERVICE_HANDLE_T *pservice);
  27191. +extern VCHIQ_STATUS_T vchiq_close_service(VCHIQ_SERVICE_HANDLE_T service);
  27192. +extern VCHIQ_STATUS_T vchiq_remove_service(VCHIQ_SERVICE_HANDLE_T service);
  27193. +extern VCHIQ_STATUS_T vchiq_use_service(VCHIQ_SERVICE_HANDLE_T service);
  27194. +extern VCHIQ_STATUS_T vchiq_use_service_no_resume(
  27195. + VCHIQ_SERVICE_HANDLE_T service);
  27196. +extern VCHIQ_STATUS_T vchiq_release_service(VCHIQ_SERVICE_HANDLE_T service);
  27197. +
  27198. +extern VCHIQ_STATUS_T vchiq_queue_message(VCHIQ_SERVICE_HANDLE_T service,
  27199. + const VCHIQ_ELEMENT_T *elements, unsigned int count);
  27200. +extern void vchiq_release_message(VCHIQ_SERVICE_HANDLE_T service,
  27201. + VCHIQ_HEADER_T *header);
  27202. +extern VCHIQ_STATUS_T vchiq_queue_bulk_transmit(VCHIQ_SERVICE_HANDLE_T service,
  27203. + const void *data, unsigned int size, void *userdata);
  27204. +extern VCHIQ_STATUS_T vchiq_queue_bulk_receive(VCHIQ_SERVICE_HANDLE_T service,
  27205. + void *data, unsigned int size, void *userdata);
  27206. +extern VCHIQ_STATUS_T vchiq_queue_bulk_transmit_handle(
  27207. + VCHIQ_SERVICE_HANDLE_T service, VCHI_MEM_HANDLE_T handle,
  27208. + const void *offset, unsigned int size, void *userdata);
  27209. +extern VCHIQ_STATUS_T vchiq_queue_bulk_receive_handle(
  27210. + VCHIQ_SERVICE_HANDLE_T service, VCHI_MEM_HANDLE_T handle,
  27211. + void *offset, unsigned int size, void *userdata);
  27212. +extern VCHIQ_STATUS_T vchiq_bulk_transmit(VCHIQ_SERVICE_HANDLE_T service,
  27213. + const void *data, unsigned int size, void *userdata,
  27214. + VCHIQ_BULK_MODE_T mode);
  27215. +extern VCHIQ_STATUS_T vchiq_bulk_receive(VCHIQ_SERVICE_HANDLE_T service,
  27216. + void *data, unsigned int size, void *userdata,
  27217. + VCHIQ_BULK_MODE_T mode);
  27218. +extern VCHIQ_STATUS_T vchiq_bulk_transmit_handle(VCHIQ_SERVICE_HANDLE_T service,
  27219. + VCHI_MEM_HANDLE_T handle, const void *offset, unsigned int size,
  27220. + void *userdata, VCHIQ_BULK_MODE_T mode);
  27221. +extern VCHIQ_STATUS_T vchiq_bulk_receive_handle(VCHIQ_SERVICE_HANDLE_T service,
  27222. + VCHI_MEM_HANDLE_T handle, void *offset, unsigned int size,
  27223. + void *userdata, VCHIQ_BULK_MODE_T mode);
  27224. +extern int vchiq_get_client_id(VCHIQ_SERVICE_HANDLE_T service);
  27225. +extern void *vchiq_get_service_userdata(VCHIQ_SERVICE_HANDLE_T service);
  27226. +extern int vchiq_get_service_fourcc(VCHIQ_SERVICE_HANDLE_T service);
  27227. +extern VCHIQ_STATUS_T vchiq_get_config(VCHIQ_INSTANCE_T instance,
  27228. + int config_size, VCHIQ_CONFIG_T *pconfig);
  27229. +extern VCHIQ_STATUS_T vchiq_set_service_option(VCHIQ_SERVICE_HANDLE_T service,
  27230. + VCHIQ_SERVICE_OPTION_T option, int value);
  27231. +
  27232. +extern VCHIQ_STATUS_T vchiq_remote_use(VCHIQ_INSTANCE_T instance,
  27233. + VCHIQ_REMOTE_USE_CALLBACK_T callback, void *cb_arg);
  27234. +extern VCHIQ_STATUS_T vchiq_remote_release(VCHIQ_INSTANCE_T instance);
  27235. +
  27236. +extern VCHIQ_STATUS_T vchiq_dump_phys_mem(VCHIQ_SERVICE_HANDLE_T service,
  27237. + void *ptr, size_t num_bytes);
  27238. +
  27239. +extern VCHIQ_STATUS_T vchiq_get_peer_version(VCHIQ_SERVICE_HANDLE_T handle,
  27240. + short *peer_version);
  27241. +
  27242. +#endif /* VCHIQ_IF_H */
  27243. diff -Nur linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h
  27244. --- linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h 1970-01-01 01:00:00.000000000 +0100
  27245. +++ linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h 2014-02-17 22:41:01.000000000 +0100
  27246. @@ -0,0 +1,129 @@
  27247. +/**
  27248. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  27249. + *
  27250. + * Redistribution and use in source and binary forms, with or without
  27251. + * modification, are permitted provided that the following conditions
  27252. + * are met:
  27253. + * 1. Redistributions of source code must retain the above copyright
  27254. + * notice, this list of conditions, and the following disclaimer,
  27255. + * without modification.
  27256. + * 2. Redistributions in binary form must reproduce the above copyright
  27257. + * notice, this list of conditions and the following disclaimer in the
  27258. + * documentation and/or other materials provided with the distribution.
  27259. + * 3. The names of the above-listed copyright holders may not be used
  27260. + * to endorse or promote products derived from this software without
  27261. + * specific prior written permission.
  27262. + *
  27263. + * ALTERNATIVELY, this software may be distributed under the terms of the
  27264. + * GNU General Public License ("GPL") version 2, as published by the Free
  27265. + * Software Foundation.
  27266. + *
  27267. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  27268. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  27269. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  27270. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  27271. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  27272. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  27273. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27274. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  27275. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  27276. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27277. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27278. + */
  27279. +
  27280. +#ifndef VCHIQ_IOCTLS_H
  27281. +#define VCHIQ_IOCTLS_H
  27282. +
  27283. +#include <linux/ioctl.h>
  27284. +#include "vchiq_if.h"
  27285. +
  27286. +#define VCHIQ_IOC_MAGIC 0xc4
  27287. +#define VCHIQ_INVALID_HANDLE (~0)
  27288. +
  27289. +typedef struct {
  27290. + VCHIQ_SERVICE_PARAMS_T params;
  27291. + int is_open;
  27292. + int is_vchi;
  27293. + unsigned int handle; /* OUT */
  27294. +} VCHIQ_CREATE_SERVICE_T;
  27295. +
  27296. +typedef struct {
  27297. + unsigned int handle;
  27298. + unsigned int count;
  27299. + const VCHIQ_ELEMENT_T *elements;
  27300. +} VCHIQ_QUEUE_MESSAGE_T;
  27301. +
  27302. +typedef struct {
  27303. + unsigned int handle;
  27304. + void *data;
  27305. + unsigned int size;
  27306. + void *userdata;
  27307. + VCHIQ_BULK_MODE_T mode;
  27308. +} VCHIQ_QUEUE_BULK_TRANSFER_T;
  27309. +
  27310. +typedef struct {
  27311. + VCHIQ_REASON_T reason;
  27312. + VCHIQ_HEADER_T *header;
  27313. + void *service_userdata;
  27314. + void *bulk_userdata;
  27315. +} VCHIQ_COMPLETION_DATA_T;
  27316. +
  27317. +typedef struct {
  27318. + unsigned int count;
  27319. + VCHIQ_COMPLETION_DATA_T *buf;
  27320. + unsigned int msgbufsize;
  27321. + unsigned int msgbufcount; /* IN/OUT */
  27322. + void **msgbufs;
  27323. +} VCHIQ_AWAIT_COMPLETION_T;
  27324. +
  27325. +typedef struct {
  27326. + unsigned int handle;
  27327. + int blocking;
  27328. + unsigned int bufsize;
  27329. + void *buf;
  27330. +} VCHIQ_DEQUEUE_MESSAGE_T;
  27331. +
  27332. +typedef struct {
  27333. + unsigned int config_size;
  27334. + VCHIQ_CONFIG_T *pconfig;
  27335. +} VCHIQ_GET_CONFIG_T;
  27336. +
  27337. +typedef struct {
  27338. + unsigned int handle;
  27339. + VCHIQ_SERVICE_OPTION_T option;
  27340. + int value;
  27341. +} VCHIQ_SET_SERVICE_OPTION_T;
  27342. +
  27343. +typedef struct {
  27344. + void *virt_addr;
  27345. + size_t num_bytes;
  27346. +} VCHIQ_DUMP_MEM_T;
  27347. +
  27348. +#define VCHIQ_IOC_CONNECT _IO(VCHIQ_IOC_MAGIC, 0)
  27349. +#define VCHIQ_IOC_SHUTDOWN _IO(VCHIQ_IOC_MAGIC, 1)
  27350. +#define VCHIQ_IOC_CREATE_SERVICE \
  27351. + _IOWR(VCHIQ_IOC_MAGIC, 2, VCHIQ_CREATE_SERVICE_T)
  27352. +#define VCHIQ_IOC_REMOVE_SERVICE _IO(VCHIQ_IOC_MAGIC, 3)
  27353. +#define VCHIQ_IOC_QUEUE_MESSAGE \
  27354. + _IOW(VCHIQ_IOC_MAGIC, 4, VCHIQ_QUEUE_MESSAGE_T)
  27355. +#define VCHIQ_IOC_QUEUE_BULK_TRANSMIT \
  27356. + _IOWR(VCHIQ_IOC_MAGIC, 5, VCHIQ_QUEUE_BULK_TRANSFER_T)
  27357. +#define VCHIQ_IOC_QUEUE_BULK_RECEIVE \
  27358. + _IOWR(VCHIQ_IOC_MAGIC, 6, VCHIQ_QUEUE_BULK_TRANSFER_T)
  27359. +#define VCHIQ_IOC_AWAIT_COMPLETION \
  27360. + _IOWR(VCHIQ_IOC_MAGIC, 7, VCHIQ_AWAIT_COMPLETION_T)
  27361. +#define VCHIQ_IOC_DEQUEUE_MESSAGE \
  27362. + _IOWR(VCHIQ_IOC_MAGIC, 8, VCHIQ_DEQUEUE_MESSAGE_T)
  27363. +#define VCHIQ_IOC_GET_CLIENT_ID _IO(VCHIQ_IOC_MAGIC, 9)
  27364. +#define VCHIQ_IOC_GET_CONFIG \
  27365. + _IOWR(VCHIQ_IOC_MAGIC, 10, VCHIQ_GET_CONFIG_T)
  27366. +#define VCHIQ_IOC_CLOSE_SERVICE _IO(VCHIQ_IOC_MAGIC, 11)
  27367. +#define VCHIQ_IOC_USE_SERVICE _IO(VCHIQ_IOC_MAGIC, 12)
  27368. +#define VCHIQ_IOC_RELEASE_SERVICE _IO(VCHIQ_IOC_MAGIC, 13)
  27369. +#define VCHIQ_IOC_SET_SERVICE_OPTION \
  27370. + _IOW(VCHIQ_IOC_MAGIC, 14, VCHIQ_SET_SERVICE_OPTION_T)
  27371. +#define VCHIQ_IOC_DUMP_PHYS_MEM \
  27372. + _IOW(VCHIQ_IOC_MAGIC, 15, VCHIQ_DUMP_MEM_T)
  27373. +#define VCHIQ_IOC_MAX 15
  27374. +
  27375. +#endif
  27376. diff -Nur linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c
  27377. --- linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c 1970-01-01 01:00:00.000000000 +0100
  27378. +++ linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c 2014-02-17 22:41:01.000000000 +0100
  27379. @@ -0,0 +1,456 @@
  27380. +/**
  27381. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  27382. + *
  27383. + * Redistribution and use in source and binary forms, with or without
  27384. + * modification, are permitted provided that the following conditions
  27385. + * are met:
  27386. + * 1. Redistributions of source code must retain the above copyright
  27387. + * notice, this list of conditions, and the following disclaimer,
  27388. + * without modification.
  27389. + * 2. Redistributions in binary form must reproduce the above copyright
  27390. + * notice, this list of conditions and the following disclaimer in the
  27391. + * documentation and/or other materials provided with the distribution.
  27392. + * 3. The names of the above-listed copyright holders may not be used
  27393. + * to endorse or promote products derived from this software without
  27394. + * specific prior written permission.
  27395. + *
  27396. + * ALTERNATIVELY, this software may be distributed under the terms of the
  27397. + * GNU General Public License ("GPL") version 2, as published by the Free
  27398. + * Software Foundation.
  27399. + *
  27400. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  27401. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  27402. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  27403. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  27404. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  27405. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  27406. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27407. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  27408. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  27409. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27410. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27411. + */
  27412. +
  27413. +/* ---- Include Files ---------------------------------------------------- */
  27414. +
  27415. +#include <linux/kernel.h>
  27416. +#include <linux/module.h>
  27417. +#include <linux/mutex.h>
  27418. +
  27419. +#include "vchiq_core.h"
  27420. +#include "vchiq_arm.h"
  27421. +
  27422. +/* ---- Public Variables ------------------------------------------------- */
  27423. +
  27424. +/* ---- Private Constants and Types -------------------------------------- */
  27425. +
  27426. +struct bulk_waiter_node {
  27427. + struct bulk_waiter bulk_waiter;
  27428. + int pid;
  27429. + struct list_head list;
  27430. +};
  27431. +
  27432. +struct vchiq_instance_struct {
  27433. + VCHIQ_STATE_T *state;
  27434. +
  27435. + int connected;
  27436. +
  27437. + struct list_head bulk_waiter_list;
  27438. + struct mutex bulk_waiter_list_mutex;
  27439. +};
  27440. +
  27441. +static VCHIQ_STATUS_T
  27442. +vchiq_blocking_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  27443. + unsigned int size, VCHIQ_BULK_DIR_T dir);
  27444. +
  27445. +/****************************************************************************
  27446. +*
  27447. +* vchiq_initialise
  27448. +*
  27449. +***************************************************************************/
  27450. +#define VCHIQ_INIT_RETRIES 10
  27451. +VCHIQ_STATUS_T vchiq_initialise(VCHIQ_INSTANCE_T *instanceOut)
  27452. +{
  27453. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  27454. + VCHIQ_STATE_T *state;
  27455. + VCHIQ_INSTANCE_T instance = NULL;
  27456. + int i;
  27457. +
  27458. + vchiq_log_trace(vchiq_core_log_level, "%s called", __func__);
  27459. +
  27460. + /* VideoCore may not be ready due to boot up timing.
  27461. + It may never be ready if kernel and firmware are mismatched, so don't block forever. */
  27462. + for (i=0; i<VCHIQ_INIT_RETRIES; i++) {
  27463. + state = vchiq_get_state();
  27464. + if (state)
  27465. + break;
  27466. + udelay(500);
  27467. + }
  27468. + if (i==VCHIQ_INIT_RETRIES) {
  27469. + vchiq_log_error(vchiq_core_log_level,
  27470. + "%s: videocore not initialized\n", __func__);
  27471. + goto failed;
  27472. + } else if (i>0) {
  27473. + vchiq_log_warning(vchiq_core_log_level,
  27474. + "%s: videocore initialized after %d retries\n", __func__, i);
  27475. + }
  27476. +
  27477. + instance = kzalloc(sizeof(*instance), GFP_KERNEL);
  27478. + if (!instance) {
  27479. + vchiq_log_error(vchiq_core_log_level,
  27480. + "%s: error allocating vchiq instance\n", __func__);
  27481. + goto failed;
  27482. + }
  27483. +
  27484. + instance->connected = 0;
  27485. + instance->state = state;
  27486. + mutex_init(&instance->bulk_waiter_list_mutex);
  27487. + INIT_LIST_HEAD(&instance->bulk_waiter_list);
  27488. +
  27489. + *instanceOut = instance;
  27490. +
  27491. + status = VCHIQ_SUCCESS;
  27492. +
  27493. +failed:
  27494. + vchiq_log_trace(vchiq_core_log_level,
  27495. + "%s(%p): returning %d", __func__, instance, status);
  27496. +
  27497. + return status;
  27498. +}
  27499. +EXPORT_SYMBOL(vchiq_initialise);
  27500. +
  27501. +/****************************************************************************
  27502. +*
  27503. +* vchiq_shutdown
  27504. +*
  27505. +***************************************************************************/
  27506. +
  27507. +VCHIQ_STATUS_T vchiq_shutdown(VCHIQ_INSTANCE_T instance)
  27508. +{
  27509. + VCHIQ_STATUS_T status;
  27510. + VCHIQ_STATE_T *state = instance->state;
  27511. +
  27512. + vchiq_log_trace(vchiq_core_log_level,
  27513. + "%s(%p) called", __func__, instance);
  27514. +
  27515. + if (mutex_lock_interruptible(&state->mutex) != 0)
  27516. + return VCHIQ_RETRY;
  27517. +
  27518. + /* Remove all services */
  27519. + status = vchiq_shutdown_internal(state, instance);
  27520. +
  27521. + mutex_unlock(&state->mutex);
  27522. +
  27523. + vchiq_log_trace(vchiq_core_log_level,
  27524. + "%s(%p): returning %d", __func__, instance, status);
  27525. +
  27526. + if (status == VCHIQ_SUCCESS) {
  27527. + struct list_head *pos, *next;
  27528. + list_for_each_safe(pos, next,
  27529. + &instance->bulk_waiter_list) {
  27530. + struct bulk_waiter_node *waiter;
  27531. + waiter = list_entry(pos,
  27532. + struct bulk_waiter_node,
  27533. + list);
  27534. + list_del(pos);
  27535. + vchiq_log_info(vchiq_arm_log_level,
  27536. + "bulk_waiter - cleaned up %x "
  27537. + "for pid %d",
  27538. + (unsigned int)waiter, waiter->pid);
  27539. + kfree(waiter);
  27540. + }
  27541. + kfree(instance);
  27542. + }
  27543. +
  27544. + return status;
  27545. +}
  27546. +EXPORT_SYMBOL(vchiq_shutdown);
  27547. +
  27548. +/****************************************************************************
  27549. +*
  27550. +* vchiq_is_connected
  27551. +*
  27552. +***************************************************************************/
  27553. +
  27554. +int vchiq_is_connected(VCHIQ_INSTANCE_T instance)
  27555. +{
  27556. + return instance->connected;
  27557. +}
  27558. +
  27559. +/****************************************************************************
  27560. +*
  27561. +* vchiq_connect
  27562. +*
  27563. +***************************************************************************/
  27564. +
  27565. +VCHIQ_STATUS_T vchiq_connect(VCHIQ_INSTANCE_T instance)
  27566. +{
  27567. + VCHIQ_STATUS_T status;
  27568. + VCHIQ_STATE_T *state = instance->state;
  27569. +
  27570. + vchiq_log_trace(vchiq_core_log_level,
  27571. + "%s(%p) called", __func__, instance);
  27572. +
  27573. + if (mutex_lock_interruptible(&state->mutex) != 0) {
  27574. + vchiq_log_trace(vchiq_core_log_level,
  27575. + "%s: call to mutex_lock failed", __func__);
  27576. + status = VCHIQ_RETRY;
  27577. + goto failed;
  27578. + }
  27579. + status = vchiq_connect_internal(state, instance);
  27580. +
  27581. + if (status == VCHIQ_SUCCESS)
  27582. + instance->connected = 1;
  27583. +
  27584. + mutex_unlock(&state->mutex);
  27585. +
  27586. +failed:
  27587. + vchiq_log_trace(vchiq_core_log_level,
  27588. + "%s(%p): returning %d", __func__, instance, status);
  27589. +
  27590. + return status;
  27591. +}
  27592. +EXPORT_SYMBOL(vchiq_connect);
  27593. +
  27594. +/****************************************************************************
  27595. +*
  27596. +* vchiq_add_service
  27597. +*
  27598. +***************************************************************************/
  27599. +
  27600. +VCHIQ_STATUS_T vchiq_add_service(
  27601. + VCHIQ_INSTANCE_T instance,
  27602. + const VCHIQ_SERVICE_PARAMS_T *params,
  27603. + VCHIQ_SERVICE_HANDLE_T *phandle)
  27604. +{
  27605. + VCHIQ_STATUS_T status;
  27606. + VCHIQ_STATE_T *state = instance->state;
  27607. + VCHIQ_SERVICE_T *service = NULL;
  27608. + int srvstate;
  27609. +
  27610. + vchiq_log_trace(vchiq_core_log_level,
  27611. + "%s(%p) called", __func__, instance);
  27612. +
  27613. + *phandle = VCHIQ_SERVICE_HANDLE_INVALID;
  27614. +
  27615. + srvstate = vchiq_is_connected(instance)
  27616. + ? VCHIQ_SRVSTATE_LISTENING
  27617. + : VCHIQ_SRVSTATE_HIDDEN;
  27618. +
  27619. + service = vchiq_add_service_internal(
  27620. + state,
  27621. + params,
  27622. + srvstate,
  27623. + instance,
  27624. + NULL);
  27625. +
  27626. + if (service) {
  27627. + *phandle = service->handle;
  27628. + status = VCHIQ_SUCCESS;
  27629. + } else
  27630. + status = VCHIQ_ERROR;
  27631. +
  27632. + vchiq_log_trace(vchiq_core_log_level,
  27633. + "%s(%p): returning %d", __func__, instance, status);
  27634. +
  27635. + return status;
  27636. +}
  27637. +EXPORT_SYMBOL(vchiq_add_service);
  27638. +
  27639. +/****************************************************************************
  27640. +*
  27641. +* vchiq_open_service
  27642. +*
  27643. +***************************************************************************/
  27644. +
  27645. +VCHIQ_STATUS_T vchiq_open_service(
  27646. + VCHIQ_INSTANCE_T instance,
  27647. + const VCHIQ_SERVICE_PARAMS_T *params,
  27648. + VCHIQ_SERVICE_HANDLE_T *phandle)
  27649. +{
  27650. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  27651. + VCHIQ_STATE_T *state = instance->state;
  27652. + VCHIQ_SERVICE_T *service = NULL;
  27653. +
  27654. + vchiq_log_trace(vchiq_core_log_level,
  27655. + "%s(%p) called", __func__, instance);
  27656. +
  27657. + *phandle = VCHIQ_SERVICE_HANDLE_INVALID;
  27658. +
  27659. + if (!vchiq_is_connected(instance))
  27660. + goto failed;
  27661. +
  27662. + service = vchiq_add_service_internal(state,
  27663. + params,
  27664. + VCHIQ_SRVSTATE_OPENING,
  27665. + instance,
  27666. + NULL);
  27667. +
  27668. + if (service) {
  27669. + status = vchiq_open_service_internal(service, current->pid);
  27670. + if (status == VCHIQ_SUCCESS)
  27671. + *phandle = service->handle;
  27672. + else
  27673. + vchiq_remove_service(service->handle);
  27674. + }
  27675. +
  27676. +failed:
  27677. + vchiq_log_trace(vchiq_core_log_level,
  27678. + "%s(%p): returning %d", __func__, instance, status);
  27679. +
  27680. + return status;
  27681. +}
  27682. +EXPORT_SYMBOL(vchiq_open_service);
  27683. +
  27684. +VCHIQ_STATUS_T
  27685. +vchiq_queue_bulk_transmit(VCHIQ_SERVICE_HANDLE_T handle,
  27686. + const void *data, unsigned int size, void *userdata)
  27687. +{
  27688. + return vchiq_bulk_transfer(handle,
  27689. + VCHI_MEM_HANDLE_INVALID, (void *)data, size, userdata,
  27690. + VCHIQ_BULK_MODE_CALLBACK, VCHIQ_BULK_TRANSMIT);
  27691. +}
  27692. +EXPORT_SYMBOL(vchiq_queue_bulk_transmit);
  27693. +
  27694. +VCHIQ_STATUS_T
  27695. +vchiq_queue_bulk_receive(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  27696. + unsigned int size, void *userdata)
  27697. +{
  27698. + return vchiq_bulk_transfer(handle,
  27699. + VCHI_MEM_HANDLE_INVALID, data, size, userdata,
  27700. + VCHIQ_BULK_MODE_CALLBACK, VCHIQ_BULK_RECEIVE);
  27701. +}
  27702. +EXPORT_SYMBOL(vchiq_queue_bulk_receive);
  27703. +
  27704. +VCHIQ_STATUS_T
  27705. +vchiq_bulk_transmit(VCHIQ_SERVICE_HANDLE_T handle, const void *data,
  27706. + unsigned int size, void *userdata, VCHIQ_BULK_MODE_T mode)
  27707. +{
  27708. + VCHIQ_STATUS_T status;
  27709. +
  27710. + switch (mode) {
  27711. + case VCHIQ_BULK_MODE_NOCALLBACK:
  27712. + case VCHIQ_BULK_MODE_CALLBACK:
  27713. + status = vchiq_bulk_transfer(handle,
  27714. + VCHI_MEM_HANDLE_INVALID, (void *)data, size, userdata,
  27715. + mode, VCHIQ_BULK_TRANSMIT);
  27716. + break;
  27717. + case VCHIQ_BULK_MODE_BLOCKING:
  27718. + status = vchiq_blocking_bulk_transfer(handle,
  27719. + (void *)data, size, VCHIQ_BULK_TRANSMIT);
  27720. + break;
  27721. + default:
  27722. + return VCHIQ_ERROR;
  27723. + }
  27724. +
  27725. + return status;
  27726. +}
  27727. +EXPORT_SYMBOL(vchiq_bulk_transmit);
  27728. +
  27729. +VCHIQ_STATUS_T
  27730. +vchiq_bulk_receive(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  27731. + unsigned int size, void *userdata, VCHIQ_BULK_MODE_T mode)
  27732. +{
  27733. + VCHIQ_STATUS_T status;
  27734. +
  27735. + switch (mode) {
  27736. + case VCHIQ_BULK_MODE_NOCALLBACK:
  27737. + case VCHIQ_BULK_MODE_CALLBACK:
  27738. + status = vchiq_bulk_transfer(handle,
  27739. + VCHI_MEM_HANDLE_INVALID, data, size, userdata,
  27740. + mode, VCHIQ_BULK_RECEIVE);
  27741. + break;
  27742. + case VCHIQ_BULK_MODE_BLOCKING:
  27743. + status = vchiq_blocking_bulk_transfer(handle,
  27744. + (void *)data, size, VCHIQ_BULK_RECEIVE);
  27745. + break;
  27746. + default:
  27747. + return VCHIQ_ERROR;
  27748. + }
  27749. +
  27750. + return status;
  27751. +}
  27752. +EXPORT_SYMBOL(vchiq_bulk_receive);
  27753. +
  27754. +static VCHIQ_STATUS_T
  27755. +vchiq_blocking_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  27756. + unsigned int size, VCHIQ_BULK_DIR_T dir)
  27757. +{
  27758. + VCHIQ_INSTANCE_T instance;
  27759. + VCHIQ_SERVICE_T *service;
  27760. + VCHIQ_STATUS_T status;
  27761. + struct bulk_waiter_node *waiter = NULL;
  27762. + struct list_head *pos;
  27763. +
  27764. + service = find_service_by_handle(handle);
  27765. + if (!service)
  27766. + return VCHIQ_ERROR;
  27767. +
  27768. + instance = service->instance;
  27769. +
  27770. + unlock_service(service);
  27771. +
  27772. + mutex_lock(&instance->bulk_waiter_list_mutex);
  27773. + list_for_each(pos, &instance->bulk_waiter_list) {
  27774. + if (list_entry(pos, struct bulk_waiter_node,
  27775. + list)->pid == current->pid) {
  27776. + waiter = list_entry(pos,
  27777. + struct bulk_waiter_node,
  27778. + list);
  27779. + list_del(pos);
  27780. + break;
  27781. + }
  27782. + }
  27783. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  27784. +
  27785. + if (waiter) {
  27786. + VCHIQ_BULK_T *bulk = waiter->bulk_waiter.bulk;
  27787. + if (bulk) {
  27788. + /* This thread has an outstanding bulk transfer. */
  27789. + if ((bulk->data != data) ||
  27790. + (bulk->size != size)) {
  27791. + /* This is not a retry of the previous one.
  27792. + ** Cancel the signal when the transfer
  27793. + ** completes. */
  27794. + spin_lock(&bulk_waiter_spinlock);
  27795. + bulk->userdata = NULL;
  27796. + spin_unlock(&bulk_waiter_spinlock);
  27797. + }
  27798. + }
  27799. + }
  27800. +
  27801. + if (!waiter) {
  27802. + waiter = kzalloc(sizeof(struct bulk_waiter_node), GFP_KERNEL);
  27803. + if (!waiter) {
  27804. + vchiq_log_error(vchiq_core_log_level,
  27805. + "%s - out of memory", __func__);
  27806. + return VCHIQ_ERROR;
  27807. + }
  27808. + }
  27809. +
  27810. + status = vchiq_bulk_transfer(handle, VCHI_MEM_HANDLE_INVALID,
  27811. + data, size, &waiter->bulk_waiter, VCHIQ_BULK_MODE_BLOCKING,
  27812. + dir);
  27813. + if ((status != VCHIQ_RETRY) || fatal_signal_pending(current) ||
  27814. + !waiter->bulk_waiter.bulk) {
  27815. + VCHIQ_BULK_T *bulk = waiter->bulk_waiter.bulk;
  27816. + if (bulk) {
  27817. + /* Cancel the signal when the transfer
  27818. + ** completes. */
  27819. + spin_lock(&bulk_waiter_spinlock);
  27820. + bulk->userdata = NULL;
  27821. + spin_unlock(&bulk_waiter_spinlock);
  27822. + }
  27823. + kfree(waiter);
  27824. + } else {
  27825. + waiter->pid = current->pid;
  27826. + mutex_lock(&instance->bulk_waiter_list_mutex);
  27827. + list_add(&waiter->list, &instance->bulk_waiter_list);
  27828. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  27829. + vchiq_log_info(vchiq_arm_log_level,
  27830. + "saved bulk_waiter %x for pid %d",
  27831. + (unsigned int)waiter, current->pid);
  27832. + }
  27833. +
  27834. + return status;
  27835. +}
  27836. diff -Nur linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h
  27837. --- linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h 1970-01-01 01:00:00.000000000 +0100
  27838. +++ linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h 2014-02-17 22:41:01.000000000 +0100
  27839. @@ -0,0 +1,71 @@
  27840. +/**
  27841. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  27842. + *
  27843. + * Redistribution and use in source and binary forms, with or without
  27844. + * modification, are permitted provided that the following conditions
  27845. + * are met:
  27846. + * 1. Redistributions of source code must retain the above copyright
  27847. + * notice, this list of conditions, and the following disclaimer,
  27848. + * without modification.
  27849. + * 2. Redistributions in binary form must reproduce the above copyright
  27850. + * notice, this list of conditions and the following disclaimer in the
  27851. + * documentation and/or other materials provided with the distribution.
  27852. + * 3. The names of the above-listed copyright holders may not be used
  27853. + * to endorse or promote products derived from this software without
  27854. + * specific prior written permission.
  27855. + *
  27856. + * ALTERNATIVELY, this software may be distributed under the terms of the
  27857. + * GNU General Public License ("GPL") version 2, as published by the Free
  27858. + * Software Foundation.
  27859. + *
  27860. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  27861. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  27862. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  27863. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  27864. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  27865. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  27866. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27867. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  27868. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  27869. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27870. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27871. + */
  27872. +
  27873. +#ifndef VCHIQ_MEMDRV_H
  27874. +#define VCHIQ_MEMDRV_H
  27875. +
  27876. +/* ---- Include Files ----------------------------------------------------- */
  27877. +
  27878. +#include <linux/kernel.h>
  27879. +#include "vchiq_if.h"
  27880. +
  27881. +/* ---- Constants and Types ---------------------------------------------- */
  27882. +
  27883. +typedef struct {
  27884. + void *armSharedMemVirt;
  27885. + dma_addr_t armSharedMemPhys;
  27886. + size_t armSharedMemSize;
  27887. +
  27888. + void *vcSharedMemVirt;
  27889. + dma_addr_t vcSharedMemPhys;
  27890. + size_t vcSharedMemSize;
  27891. +} VCHIQ_SHARED_MEM_INFO_T;
  27892. +
  27893. +/* ---- Variable Externs ------------------------------------------------- */
  27894. +
  27895. +/* ---- Function Prototypes ---------------------------------------------- */
  27896. +
  27897. +void vchiq_get_shared_mem_info(VCHIQ_SHARED_MEM_INFO_T *info);
  27898. +
  27899. +VCHIQ_STATUS_T vchiq_memdrv_initialise(void);
  27900. +
  27901. +VCHIQ_STATUS_T vchiq_userdrv_create_instance(
  27902. + const VCHIQ_PLATFORM_DATA_T * platform_data);
  27903. +
  27904. +VCHIQ_STATUS_T vchiq_userdrv_suspend(
  27905. + const VCHIQ_PLATFORM_DATA_T * platform_data);
  27906. +
  27907. +VCHIQ_STATUS_T vchiq_userdrv_resume(
  27908. + const VCHIQ_PLATFORM_DATA_T * platform_data);
  27909. +
  27910. +#endif
  27911. diff -Nur linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h
  27912. --- linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h 1970-01-01 01:00:00.000000000 +0100
  27913. +++ linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h 2014-02-17 22:41:01.000000000 +0100
  27914. @@ -0,0 +1,58 @@
  27915. +/**
  27916. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  27917. + *
  27918. + * Redistribution and use in source and binary forms, with or without
  27919. + * modification, are permitted provided that the following conditions
  27920. + * are met:
  27921. + * 1. Redistributions of source code must retain the above copyright
  27922. + * notice, this list of conditions, and the following disclaimer,
  27923. + * without modification.
  27924. + * 2. Redistributions in binary form must reproduce the above copyright
  27925. + * notice, this list of conditions and the following disclaimer in the
  27926. + * documentation and/or other materials provided with the distribution.
  27927. + * 3. The names of the above-listed copyright holders may not be used
  27928. + * to endorse or promote products derived from this software without
  27929. + * specific prior written permission.
  27930. + *
  27931. + * ALTERNATIVELY, this software may be distributed under the terms of the
  27932. + * GNU General Public License ("GPL") version 2, as published by the Free
  27933. + * Software Foundation.
  27934. + *
  27935. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  27936. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  27937. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  27938. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  27939. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  27940. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  27941. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27942. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  27943. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  27944. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27945. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27946. + */
  27947. +
  27948. +#ifndef VCHIQ_PAGELIST_H
  27949. +#define VCHIQ_PAGELIST_H
  27950. +
  27951. +#ifndef PAGE_SIZE
  27952. +#define PAGE_SIZE 4096
  27953. +#endif
  27954. +#define CACHE_LINE_SIZE 32
  27955. +#define PAGELIST_WRITE 0
  27956. +#define PAGELIST_READ 1
  27957. +#define PAGELIST_READ_WITH_FRAGMENTS 2
  27958. +
  27959. +typedef struct pagelist_struct {
  27960. + unsigned long length;
  27961. + unsigned short type;
  27962. + unsigned short offset;
  27963. + unsigned long addrs[1]; /* N.B. 12 LSBs hold the number of following
  27964. + pages at consecutive addresses. */
  27965. +} PAGELIST_T;
  27966. +
  27967. +typedef struct fragments_struct {
  27968. + char headbuf[CACHE_LINE_SIZE];
  27969. + char tailbuf[CACHE_LINE_SIZE];
  27970. +} FRAGMENTS_T;
  27971. +
  27972. +#endif /* VCHIQ_PAGELIST_H */
  27973. diff -Nur linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_proc.c linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_proc.c
  27974. --- linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_proc.c 1970-01-01 01:00:00.000000000 +0100
  27975. +++ linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_proc.c 2014-02-17 22:41:01.000000000 +0100
  27976. @@ -0,0 +1,253 @@
  27977. +/**
  27978. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  27979. + *
  27980. + * Redistribution and use in source and binary forms, with or without
  27981. + * modification, are permitted provided that the following conditions
  27982. + * are met:
  27983. + * 1. Redistributions of source code must retain the above copyright
  27984. + * notice, this list of conditions, and the following disclaimer,
  27985. + * without modification.
  27986. + * 2. Redistributions in binary form must reproduce the above copyright
  27987. + * notice, this list of conditions and the following disclaimer in the
  27988. + * documentation and/or other materials provided with the distribution.
  27989. + * 3. The names of the above-listed copyright holders may not be used
  27990. + * to endorse or promote products derived from this software without
  27991. + * specific prior written permission.
  27992. + *
  27993. + * ALTERNATIVELY, this software may be distributed under the terms of the
  27994. + * GNU General Public License ("GPL") version 2, as published by the Free
  27995. + * Software Foundation.
  27996. + *
  27997. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  27998. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  27999. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  28000. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  28001. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28002. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  28003. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28004. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28005. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28006. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28007. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28008. + */
  28009. +
  28010. +
  28011. +#include <linux/proc_fs.h>
  28012. +#include "vchiq_core.h"
  28013. +#include "vchiq_arm.h"
  28014. +
  28015. +#if 1
  28016. +
  28017. +int vchiq_proc_init(void)
  28018. +{
  28019. + return 0;
  28020. +}
  28021. +
  28022. +void vchiq_proc_deinit(void)
  28023. +{
  28024. +}
  28025. +
  28026. +#else
  28027. +
  28028. +struct vchiq_proc_info {
  28029. + /* Global 'vc' proc entry used by all instances */
  28030. + struct proc_dir_entry *vc_cfg_dir;
  28031. +
  28032. + /* one entry per client process */
  28033. + struct proc_dir_entry *clients;
  28034. +
  28035. + /* log categories */
  28036. + struct proc_dir_entry *log_categories;
  28037. +};
  28038. +
  28039. +static struct vchiq_proc_info proc_info;
  28040. +
  28041. +struct proc_dir_entry *vchiq_proc_top(void)
  28042. +{
  28043. + BUG_ON(proc_info.vc_cfg_dir == NULL);
  28044. + return proc_info.vc_cfg_dir;
  28045. +}
  28046. +
  28047. +/****************************************************************************
  28048. +*
  28049. +* log category entries
  28050. +*
  28051. +***************************************************************************/
  28052. +#define PROC_WRITE_BUF_SIZE 256
  28053. +
  28054. +#define VCHIQ_LOG_ERROR_STR "error"
  28055. +#define VCHIQ_LOG_WARNING_STR "warning"
  28056. +#define VCHIQ_LOG_INFO_STR "info"
  28057. +#define VCHIQ_LOG_TRACE_STR "trace"
  28058. +
  28059. +static int log_cfg_read(char *buffer,
  28060. + char **start,
  28061. + off_t off,
  28062. + int count,
  28063. + int *eof,
  28064. + void *data)
  28065. +{
  28066. + int len = 0;
  28067. + char *log_value = NULL;
  28068. +
  28069. + switch (*((int *)data)) {
  28070. + case VCHIQ_LOG_ERROR:
  28071. + log_value = VCHIQ_LOG_ERROR_STR;
  28072. + break;
  28073. + case VCHIQ_LOG_WARNING:
  28074. + log_value = VCHIQ_LOG_WARNING_STR;
  28075. + break;
  28076. + case VCHIQ_LOG_INFO:
  28077. + log_value = VCHIQ_LOG_INFO_STR;
  28078. + break;
  28079. + case VCHIQ_LOG_TRACE:
  28080. + log_value = VCHIQ_LOG_TRACE_STR;
  28081. + break;
  28082. + default:
  28083. + break;
  28084. + }
  28085. +
  28086. + len += sprintf(buffer + len,
  28087. + "%s\n",
  28088. + log_value ? log_value : "(null)");
  28089. +
  28090. + return len;
  28091. +}
  28092. +
  28093. +
  28094. +static int log_cfg_write(struct file *file,
  28095. + const char __user *buffer,
  28096. + unsigned long count,
  28097. + void *data)
  28098. +{
  28099. + int *log_module = data;
  28100. + char kbuf[PROC_WRITE_BUF_SIZE + 1];
  28101. +
  28102. + (void)file;
  28103. +
  28104. + memset(kbuf, 0, PROC_WRITE_BUF_SIZE + 1);
  28105. + if (count >= PROC_WRITE_BUF_SIZE)
  28106. + count = PROC_WRITE_BUF_SIZE;
  28107. +
  28108. + if (copy_from_user(kbuf,
  28109. + buffer,
  28110. + count) != 0)
  28111. + return -EFAULT;
  28112. + kbuf[count - 1] = 0;
  28113. +
  28114. + if (strncmp("error", kbuf, strlen("error")) == 0)
  28115. + *log_module = VCHIQ_LOG_ERROR;
  28116. + else if (strncmp("warning", kbuf, strlen("warning")) == 0)
  28117. + *log_module = VCHIQ_LOG_WARNING;
  28118. + else if (strncmp("info", kbuf, strlen("info")) == 0)
  28119. + *log_module = VCHIQ_LOG_INFO;
  28120. + else if (strncmp("trace", kbuf, strlen("trace")) == 0)
  28121. + *log_module = VCHIQ_LOG_TRACE;
  28122. + else
  28123. + *log_module = VCHIQ_LOG_DEFAULT;
  28124. +
  28125. + return count;
  28126. +}
  28127. +
  28128. +/* Log category proc entries */
  28129. +struct vchiq_proc_log_entry {
  28130. + const char *name;
  28131. + int *plevel;
  28132. + struct proc_dir_entry *dir;
  28133. +};
  28134. +
  28135. +static struct vchiq_proc_log_entry vchiq_proc_log_entries[] = {
  28136. + { "core", &vchiq_core_log_level },
  28137. + { "msg", &vchiq_core_msg_log_level },
  28138. + { "sync", &vchiq_sync_log_level },
  28139. + { "susp", &vchiq_susp_log_level },
  28140. + { "arm", &vchiq_arm_log_level },
  28141. +};
  28142. +static int n_log_entries =
  28143. + sizeof(vchiq_proc_log_entries)/sizeof(vchiq_proc_log_entries[0]);
  28144. +
  28145. +/* create an entry under /proc/vc/log for each log category */
  28146. +static int vchiq_proc_create_log_entries(struct proc_dir_entry *top)
  28147. +{
  28148. + struct proc_dir_entry *dir;
  28149. + size_t i;
  28150. + int ret = 0;
  28151. + dir = proc_mkdir("log", proc_info.vc_cfg_dir);
  28152. + if (!dir)
  28153. + return -ENOMEM;
  28154. + proc_info.log_categories = dir;
  28155. +
  28156. + for (i = 0; i < n_log_entries; i++) {
  28157. + dir = create_proc_entry(vchiq_proc_log_entries[i].name,
  28158. + 0644,
  28159. + proc_info.log_categories);
  28160. + if (!dir) {
  28161. + ret = -ENOMEM;
  28162. + break;
  28163. + }
  28164. +
  28165. + dir->read_proc = &log_cfg_read;
  28166. + dir->write_proc = &log_cfg_write;
  28167. + dir->data = (void *)vchiq_proc_log_entries[i].plevel;
  28168. +
  28169. + vchiq_proc_log_entries[i].dir = dir;
  28170. + }
  28171. + return ret;
  28172. +}
  28173. +
  28174. +
  28175. +int vchiq_proc_init(void)
  28176. +{
  28177. + BUG_ON(proc_info.vc_cfg_dir != NULL);
  28178. +
  28179. + proc_info.vc_cfg_dir = proc_mkdir("vc", NULL);
  28180. + if (proc_info.vc_cfg_dir == NULL)
  28181. + goto fail;
  28182. +
  28183. + proc_info.clients = proc_mkdir("clients",
  28184. + proc_info.vc_cfg_dir);
  28185. + if (!proc_info.clients)
  28186. + goto fail;
  28187. +
  28188. + if (vchiq_proc_create_log_entries(proc_info.vc_cfg_dir) != 0)
  28189. + goto fail;
  28190. +
  28191. + return 0;
  28192. +
  28193. +fail:
  28194. + vchiq_proc_deinit();
  28195. + vchiq_log_error(vchiq_arm_log_level,
  28196. + "%s: failed to create proc directory",
  28197. + __func__);
  28198. +
  28199. + return -ENOMEM;
  28200. +}
  28201. +
  28202. +/* remove all the proc entries */
  28203. +void vchiq_proc_deinit(void)
  28204. +{
  28205. + /* log category entries */
  28206. + if (proc_info.log_categories) {
  28207. + size_t i;
  28208. + for (i = 0; i < n_log_entries; i++)
  28209. + if (vchiq_proc_log_entries[i].dir)
  28210. + remove_proc_entry(
  28211. + vchiq_proc_log_entries[i].name,
  28212. + proc_info.log_categories);
  28213. +
  28214. + remove_proc_entry(proc_info.log_categories->name,
  28215. + proc_info.vc_cfg_dir);
  28216. + }
  28217. + if (proc_info.clients)
  28218. + remove_proc_entry(proc_info.clients->name,
  28219. + proc_info.vc_cfg_dir);
  28220. + if (proc_info.vc_cfg_dir)
  28221. + remove_proc_entry(proc_info.vc_cfg_dir->name, NULL);
  28222. +}
  28223. +
  28224. +struct proc_dir_entry *vchiq_clients_top(void)
  28225. +{
  28226. + return proc_info.clients;
  28227. +}
  28228. +
  28229. +#endif
  28230. diff -Nur linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c
  28231. --- linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c 1970-01-01 01:00:00.000000000 +0100
  28232. +++ linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c 2014-02-17 22:41:01.000000000 +0100
  28233. @@ -0,0 +1,828 @@
  28234. +/**
  28235. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  28236. + *
  28237. + * Redistribution and use in source and binary forms, with or without
  28238. + * modification, are permitted provided that the following conditions
  28239. + * are met:
  28240. + * 1. Redistributions of source code must retain the above copyright
  28241. + * notice, this list of conditions, and the following disclaimer,
  28242. + * without modification.
  28243. + * 2. Redistributions in binary form must reproduce the above copyright
  28244. + * notice, this list of conditions and the following disclaimer in the
  28245. + * documentation and/or other materials provided with the distribution.
  28246. + * 3. The names of the above-listed copyright holders may not be used
  28247. + * to endorse or promote products derived from this software without
  28248. + * specific prior written permission.
  28249. + *
  28250. + * ALTERNATIVELY, this software may be distributed under the terms of the
  28251. + * GNU General Public License ("GPL") version 2, as published by the Free
  28252. + * Software Foundation.
  28253. + *
  28254. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  28255. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  28256. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  28257. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  28258. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28259. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  28260. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28261. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28262. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28263. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28264. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28265. + */
  28266. +#include <linux/module.h>
  28267. +#include <linux/types.h>
  28268. +
  28269. +#include "interface/vchi/vchi.h"
  28270. +#include "vchiq.h"
  28271. +#include "vchiq_core.h"
  28272. +
  28273. +#include "vchiq_util.h"
  28274. +
  28275. +#include <stddef.h>
  28276. +
  28277. +#define vchiq_status_to_vchi(status) ((int32_t)status)
  28278. +
  28279. +typedef struct {
  28280. + VCHIQ_SERVICE_HANDLE_T handle;
  28281. +
  28282. + VCHIU_QUEUE_T queue;
  28283. +
  28284. + VCHI_CALLBACK_T callback;
  28285. + void *callback_param;
  28286. +} SHIM_SERVICE_T;
  28287. +
  28288. +/* ----------------------------------------------------------------------
  28289. + * return pointer to the mphi message driver function table
  28290. + * -------------------------------------------------------------------- */
  28291. +const VCHI_MESSAGE_DRIVER_T *
  28292. +vchi_mphi_message_driver_func_table(void)
  28293. +{
  28294. + return NULL;
  28295. +}
  28296. +
  28297. +/* ----------------------------------------------------------------------
  28298. + * return a pointer to the 'single' connection driver fops
  28299. + * -------------------------------------------------------------------- */
  28300. +const VCHI_CONNECTION_API_T *
  28301. +single_get_func_table(void)
  28302. +{
  28303. + return NULL;
  28304. +}
  28305. +
  28306. +VCHI_CONNECTION_T *vchi_create_connection(
  28307. + const VCHI_CONNECTION_API_T *function_table,
  28308. + const VCHI_MESSAGE_DRIVER_T *low_level)
  28309. +{
  28310. + (void)function_table;
  28311. + (void)low_level;
  28312. + return NULL;
  28313. +}
  28314. +
  28315. +/***********************************************************
  28316. + * Name: vchi_msg_peek
  28317. + *
  28318. + * Arguments: const VCHI_SERVICE_HANDLE_T handle,
  28319. + * void **data,
  28320. + * uint32_t *msg_size,
  28321. +
  28322. +
  28323. + * VCHI_FLAGS_T flags
  28324. + *
  28325. + * Description: Routine to return a pointer to the current message (to allow in
  28326. + * place processing). The message can be removed using
  28327. + * vchi_msg_remove when you're finished
  28328. + *
  28329. + * Returns: int32_t - success == 0
  28330. + *
  28331. + ***********************************************************/
  28332. +int32_t vchi_msg_peek(VCHI_SERVICE_HANDLE_T handle,
  28333. + void **data,
  28334. + uint32_t *msg_size,
  28335. + VCHI_FLAGS_T flags)
  28336. +{
  28337. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  28338. + VCHIQ_HEADER_T *header;
  28339. +
  28340. + WARN_ON((flags != VCHI_FLAGS_NONE) &&
  28341. + (flags != VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE));
  28342. +
  28343. + if (flags == VCHI_FLAGS_NONE)
  28344. + if (vchiu_queue_is_empty(&service->queue))
  28345. + return -1;
  28346. +
  28347. + header = vchiu_queue_peek(&service->queue);
  28348. +
  28349. + *data = header->data;
  28350. + *msg_size = header->size;
  28351. +
  28352. + return 0;
  28353. +}
  28354. +EXPORT_SYMBOL(vchi_msg_peek);
  28355. +
  28356. +/***********************************************************
  28357. + * Name: vchi_msg_remove
  28358. + *
  28359. + * Arguments: const VCHI_SERVICE_HANDLE_T handle,
  28360. + *
  28361. + * Description: Routine to remove a message (after it has been read with
  28362. + * vchi_msg_peek)
  28363. + *
  28364. + * Returns: int32_t - success == 0
  28365. + *
  28366. + ***********************************************************/
  28367. +int32_t vchi_msg_remove(VCHI_SERVICE_HANDLE_T handle)
  28368. +{
  28369. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  28370. + VCHIQ_HEADER_T *header;
  28371. +
  28372. + header = vchiu_queue_pop(&service->queue);
  28373. +
  28374. + vchiq_release_message(service->handle, header);
  28375. +
  28376. + return 0;
  28377. +}
  28378. +EXPORT_SYMBOL(vchi_msg_remove);
  28379. +
  28380. +/***********************************************************
  28381. + * Name: vchi_msg_queue
  28382. + *
  28383. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  28384. + * const void *data,
  28385. + * uint32_t data_size,
  28386. + * VCHI_FLAGS_T flags,
  28387. + * void *msg_handle,
  28388. + *
  28389. + * Description: Thin wrapper to queue a message onto a connection
  28390. + *
  28391. + * Returns: int32_t - success == 0
  28392. + *
  28393. + ***********************************************************/
  28394. +int32_t vchi_msg_queue(VCHI_SERVICE_HANDLE_T handle,
  28395. + const void *data,
  28396. + uint32_t data_size,
  28397. + VCHI_FLAGS_T flags,
  28398. + void *msg_handle)
  28399. +{
  28400. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  28401. + VCHIQ_ELEMENT_T element = {data, data_size};
  28402. + VCHIQ_STATUS_T status;
  28403. +
  28404. + (void)msg_handle;
  28405. +
  28406. + WARN_ON(flags != VCHI_FLAGS_BLOCK_UNTIL_QUEUED);
  28407. +
  28408. + status = vchiq_queue_message(service->handle, &element, 1);
  28409. +
  28410. + /* vchiq_queue_message() may return VCHIQ_RETRY, so we need to
  28411. + ** implement a retry mechanism since this function is supposed
  28412. + ** to block until queued
  28413. + */
  28414. + while (status == VCHIQ_RETRY) {
  28415. + msleep(1);
  28416. + status = vchiq_queue_message(service->handle, &element, 1);
  28417. + }
  28418. +
  28419. + return vchiq_status_to_vchi(status);
  28420. +}
  28421. +EXPORT_SYMBOL(vchi_msg_queue);
  28422. +
  28423. +/***********************************************************
  28424. + * Name: vchi_bulk_queue_receive
  28425. + *
  28426. + * Arguments: VCHI_BULK_HANDLE_T handle,
  28427. + * void *data_dst,
  28428. + * const uint32_t data_size,
  28429. + * VCHI_FLAGS_T flags
  28430. + * void *bulk_handle
  28431. + *
  28432. + * Description: Routine to setup a rcv buffer
  28433. + *
  28434. + * Returns: int32_t - success == 0
  28435. + *
  28436. + ***********************************************************/
  28437. +int32_t vchi_bulk_queue_receive(VCHI_SERVICE_HANDLE_T handle,
  28438. + void *data_dst,
  28439. + uint32_t data_size,
  28440. + VCHI_FLAGS_T flags,
  28441. + void *bulk_handle)
  28442. +{
  28443. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  28444. + VCHIQ_BULK_MODE_T mode;
  28445. + VCHIQ_STATUS_T status;
  28446. +
  28447. + switch ((int)flags) {
  28448. + case VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE
  28449. + | VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  28450. + WARN_ON(!service->callback);
  28451. + mode = VCHIQ_BULK_MODE_CALLBACK;
  28452. + break;
  28453. + case VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE:
  28454. + mode = VCHIQ_BULK_MODE_BLOCKING;
  28455. + break;
  28456. + case VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  28457. + case VCHI_FLAGS_NONE:
  28458. + mode = VCHIQ_BULK_MODE_NOCALLBACK;
  28459. + break;
  28460. + default:
  28461. + WARN(1, "unsupported message\n");
  28462. + return vchiq_status_to_vchi(VCHIQ_ERROR);
  28463. + }
  28464. +
  28465. + status = vchiq_bulk_receive(service->handle, data_dst, data_size,
  28466. + bulk_handle, mode);
  28467. +
  28468. + /* vchiq_bulk_receive() may return VCHIQ_RETRY, so we need to
  28469. + ** implement a retry mechanism since this function is supposed
  28470. + ** to block until queued
  28471. + */
  28472. + while (status == VCHIQ_RETRY) {
  28473. + msleep(1);
  28474. + status = vchiq_bulk_receive(service->handle, data_dst,
  28475. + data_size, bulk_handle, mode);
  28476. + }
  28477. +
  28478. + return vchiq_status_to_vchi(status);
  28479. +}
  28480. +EXPORT_SYMBOL(vchi_bulk_queue_receive);
  28481. +
  28482. +/***********************************************************
  28483. + * Name: vchi_bulk_queue_transmit
  28484. + *
  28485. + * Arguments: VCHI_BULK_HANDLE_T handle,
  28486. + * const void *data_src,
  28487. + * uint32_t data_size,
  28488. + * VCHI_FLAGS_T flags,
  28489. + * void *bulk_handle
  28490. + *
  28491. + * Description: Routine to transmit some data
  28492. + *
  28493. + * Returns: int32_t - success == 0
  28494. + *
  28495. + ***********************************************************/
  28496. +int32_t vchi_bulk_queue_transmit(VCHI_SERVICE_HANDLE_T handle,
  28497. + const void *data_src,
  28498. + uint32_t data_size,
  28499. + VCHI_FLAGS_T flags,
  28500. + void *bulk_handle)
  28501. +{
  28502. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  28503. + VCHIQ_BULK_MODE_T mode;
  28504. + VCHIQ_STATUS_T status;
  28505. +
  28506. + switch ((int)flags) {
  28507. + case VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE
  28508. + | VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  28509. + WARN_ON(!service->callback);
  28510. + mode = VCHIQ_BULK_MODE_CALLBACK;
  28511. + break;
  28512. + case VCHI_FLAGS_BLOCK_UNTIL_DATA_READ:
  28513. + case VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE:
  28514. + mode = VCHIQ_BULK_MODE_BLOCKING;
  28515. + break;
  28516. + case VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  28517. + case VCHI_FLAGS_NONE:
  28518. + mode = VCHIQ_BULK_MODE_NOCALLBACK;
  28519. + break;
  28520. + default:
  28521. + WARN(1, "unsupported message\n");
  28522. + return vchiq_status_to_vchi(VCHIQ_ERROR);
  28523. + }
  28524. +
  28525. + status = vchiq_bulk_transmit(service->handle, data_src, data_size,
  28526. + bulk_handle, mode);
  28527. +
  28528. + /* vchiq_bulk_transmit() may return VCHIQ_RETRY, so we need to
  28529. + ** implement a retry mechanism since this function is supposed
  28530. + ** to block until queued
  28531. + */
  28532. + while (status == VCHIQ_RETRY) {
  28533. + msleep(1);
  28534. + status = vchiq_bulk_transmit(service->handle, data_src,
  28535. + data_size, bulk_handle, mode);
  28536. + }
  28537. +
  28538. + return vchiq_status_to_vchi(status);
  28539. +}
  28540. +EXPORT_SYMBOL(vchi_bulk_queue_transmit);
  28541. +
  28542. +/***********************************************************
  28543. + * Name: vchi_msg_dequeue
  28544. + *
  28545. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  28546. + * void *data,
  28547. + * uint32_t max_data_size_to_read,
  28548. + * uint32_t *actual_msg_size
  28549. + * VCHI_FLAGS_T flags
  28550. + *
  28551. + * Description: Routine to dequeue a message into the supplied buffer
  28552. + *
  28553. + * Returns: int32_t - success == 0
  28554. + *
  28555. + ***********************************************************/
  28556. +int32_t vchi_msg_dequeue(VCHI_SERVICE_HANDLE_T handle,
  28557. + void *data,
  28558. + uint32_t max_data_size_to_read,
  28559. + uint32_t *actual_msg_size,
  28560. + VCHI_FLAGS_T flags)
  28561. +{
  28562. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  28563. + VCHIQ_HEADER_T *header;
  28564. +
  28565. + WARN_ON((flags != VCHI_FLAGS_NONE) &&
  28566. + (flags != VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE));
  28567. +
  28568. + if (flags == VCHI_FLAGS_NONE)
  28569. + if (vchiu_queue_is_empty(&service->queue))
  28570. + return -1;
  28571. +
  28572. + header = vchiu_queue_pop(&service->queue);
  28573. +
  28574. + memcpy(data, header->data, header->size < max_data_size_to_read ?
  28575. + header->size : max_data_size_to_read);
  28576. +
  28577. + *actual_msg_size = header->size;
  28578. +
  28579. + vchiq_release_message(service->handle, header);
  28580. +
  28581. + return 0;
  28582. +}
  28583. +EXPORT_SYMBOL(vchi_msg_dequeue);
  28584. +
  28585. +/***********************************************************
  28586. + * Name: vchi_msg_queuev
  28587. + *
  28588. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  28589. + * VCHI_MSG_VECTOR_T *vector,
  28590. + * uint32_t count,
  28591. + * VCHI_FLAGS_T flags,
  28592. + * void *msg_handle
  28593. + *
  28594. + * Description: Thin wrapper to queue a message onto a connection
  28595. + *
  28596. + * Returns: int32_t - success == 0
  28597. + *
  28598. + ***********************************************************/
  28599. +
  28600. +vchiq_static_assert(sizeof(VCHI_MSG_VECTOR_T) == sizeof(VCHIQ_ELEMENT_T));
  28601. +vchiq_static_assert(offsetof(VCHI_MSG_VECTOR_T, vec_base) ==
  28602. + offsetof(VCHIQ_ELEMENT_T, data));
  28603. +vchiq_static_assert(offsetof(VCHI_MSG_VECTOR_T, vec_len) ==
  28604. + offsetof(VCHIQ_ELEMENT_T, size));
  28605. +
  28606. +int32_t vchi_msg_queuev(VCHI_SERVICE_HANDLE_T handle,
  28607. + VCHI_MSG_VECTOR_T *vector,
  28608. + uint32_t count,
  28609. + VCHI_FLAGS_T flags,
  28610. + void *msg_handle)
  28611. +{
  28612. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  28613. +
  28614. + (void)msg_handle;
  28615. +
  28616. + WARN_ON(flags != VCHI_FLAGS_BLOCK_UNTIL_QUEUED);
  28617. +
  28618. + return vchiq_status_to_vchi(vchiq_queue_message(service->handle,
  28619. + (const VCHIQ_ELEMENT_T *)vector, count));
  28620. +}
  28621. +EXPORT_SYMBOL(vchi_msg_queuev);
  28622. +
  28623. +/***********************************************************
  28624. + * Name: vchi_held_msg_release
  28625. + *
  28626. + * Arguments: VCHI_HELD_MSG_T *message
  28627. + *
  28628. + * Description: Routine to release a held message (after it has been read with
  28629. + * vchi_msg_hold)
  28630. + *
  28631. + * Returns: int32_t - success == 0
  28632. + *
  28633. + ***********************************************************/
  28634. +int32_t vchi_held_msg_release(VCHI_HELD_MSG_T *message)
  28635. +{
  28636. + vchiq_release_message((VCHIQ_SERVICE_HANDLE_T)message->service,
  28637. + (VCHIQ_HEADER_T *)message->message);
  28638. +
  28639. + return 0;
  28640. +}
  28641. +EXPORT_SYMBOL(vchi_held_msg_release);
  28642. +
  28643. +/***********************************************************
  28644. + * Name: vchi_msg_hold
  28645. + *
  28646. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  28647. + * void **data,
  28648. + * uint32_t *msg_size,
  28649. + * VCHI_FLAGS_T flags,
  28650. + * VCHI_HELD_MSG_T *message_handle
  28651. + *
  28652. + * Description: Routine to return a pointer to the current message (to allow
  28653. + * in place processing). The message is dequeued - don't forget
  28654. + * to release the message using vchi_held_msg_release when you're
  28655. + * finished.
  28656. + *
  28657. + * Returns: int32_t - success == 0
  28658. + *
  28659. + ***********************************************************/
  28660. +int32_t vchi_msg_hold(VCHI_SERVICE_HANDLE_T handle,
  28661. + void **data,
  28662. + uint32_t *msg_size,
  28663. + VCHI_FLAGS_T flags,
  28664. + VCHI_HELD_MSG_T *message_handle)
  28665. +{
  28666. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  28667. + VCHIQ_HEADER_T *header;
  28668. +
  28669. + WARN_ON((flags != VCHI_FLAGS_NONE) &&
  28670. + (flags != VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE));
  28671. +
  28672. + if (flags == VCHI_FLAGS_NONE)
  28673. + if (vchiu_queue_is_empty(&service->queue))
  28674. + return -1;
  28675. +
  28676. + header = vchiu_queue_pop(&service->queue);
  28677. +
  28678. + *data = header->data;
  28679. + *msg_size = header->size;
  28680. +
  28681. + message_handle->service =
  28682. + (struct opaque_vchi_service_t *)service->handle;
  28683. + message_handle->message = header;
  28684. +
  28685. + return 0;
  28686. +}
  28687. +EXPORT_SYMBOL(vchi_msg_hold);
  28688. +
  28689. +/***********************************************************
  28690. + * Name: vchi_initialise
  28691. + *
  28692. + * Arguments: VCHI_INSTANCE_T *instance_handle
  28693. + * VCHI_CONNECTION_T **connections
  28694. + * const uint32_t num_connections
  28695. + *
  28696. + * Description: Initialises the hardware but does not transmit anything
  28697. + * When run as a Host App this will be called twice hence the need
  28698. + * to malloc the state information
  28699. + *
  28700. + * Returns: 0 if successful, failure otherwise
  28701. + *
  28702. + ***********************************************************/
  28703. +
  28704. +int32_t vchi_initialise(VCHI_INSTANCE_T *instance_handle)
  28705. +{
  28706. + VCHIQ_INSTANCE_T instance;
  28707. + VCHIQ_STATUS_T status;
  28708. +
  28709. + status = vchiq_initialise(&instance);
  28710. +
  28711. + *instance_handle = (VCHI_INSTANCE_T)instance;
  28712. +
  28713. + return vchiq_status_to_vchi(status);
  28714. +}
  28715. +EXPORT_SYMBOL(vchi_initialise);
  28716. +
  28717. +/***********************************************************
  28718. + * Name: vchi_connect
  28719. + *
  28720. + * Arguments: VCHI_CONNECTION_T **connections
  28721. + * const uint32_t num_connections
  28722. + * VCHI_INSTANCE_T instance_handle)
  28723. + *
  28724. + * Description: Starts the command service on each connection,
  28725. + * causing INIT messages to be pinged back and forth
  28726. + *
  28727. + * Returns: 0 if successful, failure otherwise
  28728. + *
  28729. + ***********************************************************/
  28730. +int32_t vchi_connect(VCHI_CONNECTION_T **connections,
  28731. + const uint32_t num_connections,
  28732. + VCHI_INSTANCE_T instance_handle)
  28733. +{
  28734. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  28735. +
  28736. + (void)connections;
  28737. + (void)num_connections;
  28738. +
  28739. + return vchiq_connect(instance);
  28740. +}
  28741. +EXPORT_SYMBOL(vchi_connect);
  28742. +
  28743. +
  28744. +/***********************************************************
  28745. + * Name: vchi_disconnect
  28746. + *
  28747. + * Arguments: VCHI_INSTANCE_T instance_handle
  28748. + *
  28749. + * Description: Stops the command service on each connection,
  28750. + * causing DE-INIT messages to be pinged back and forth
  28751. + *
  28752. + * Returns: 0 if successful, failure otherwise
  28753. + *
  28754. + ***********************************************************/
  28755. +int32_t vchi_disconnect(VCHI_INSTANCE_T instance_handle)
  28756. +{
  28757. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  28758. + return vchiq_status_to_vchi(vchiq_shutdown(instance));
  28759. +}
  28760. +EXPORT_SYMBOL(vchi_disconnect);
  28761. +
  28762. +
  28763. +/***********************************************************
  28764. + * Name: vchi_service_open
  28765. + * Name: vchi_service_create
  28766. + *
  28767. + * Arguments: VCHI_INSTANCE_T *instance_handle
  28768. + * SERVICE_CREATION_T *setup,
  28769. + * VCHI_SERVICE_HANDLE_T *handle
  28770. + *
  28771. + * Description: Routine to open a service
  28772. + *
  28773. + * Returns: int32_t - success == 0
  28774. + *
  28775. + ***********************************************************/
  28776. +
  28777. +static VCHIQ_STATUS_T shim_callback(VCHIQ_REASON_T reason,
  28778. + VCHIQ_HEADER_T *header, VCHIQ_SERVICE_HANDLE_T handle, void *bulk_user)
  28779. +{
  28780. + SHIM_SERVICE_T *service =
  28781. + (SHIM_SERVICE_T *)VCHIQ_GET_SERVICE_USERDATA(handle);
  28782. +
  28783. + if (!service->callback)
  28784. + goto release;
  28785. +
  28786. + switch (reason) {
  28787. + case VCHIQ_MESSAGE_AVAILABLE:
  28788. + vchiu_queue_push(&service->queue, header);
  28789. +
  28790. + service->callback(service->callback_param,
  28791. + VCHI_CALLBACK_MSG_AVAILABLE, NULL);
  28792. +
  28793. + goto done;
  28794. + break;
  28795. +
  28796. + case VCHIQ_BULK_TRANSMIT_DONE:
  28797. + service->callback(service->callback_param,
  28798. + VCHI_CALLBACK_BULK_SENT, bulk_user);
  28799. + break;
  28800. +
  28801. + case VCHIQ_BULK_RECEIVE_DONE:
  28802. + service->callback(service->callback_param,
  28803. + VCHI_CALLBACK_BULK_RECEIVED, bulk_user);
  28804. + break;
  28805. +
  28806. + case VCHIQ_SERVICE_CLOSED:
  28807. + service->callback(service->callback_param,
  28808. + VCHI_CALLBACK_SERVICE_CLOSED, NULL);
  28809. + break;
  28810. +
  28811. + case VCHIQ_SERVICE_OPENED:
  28812. + /* No equivalent VCHI reason */
  28813. + break;
  28814. +
  28815. + case VCHIQ_BULK_TRANSMIT_ABORTED:
  28816. + service->callback(service->callback_param,
  28817. + VCHI_CALLBACK_BULK_TRANSMIT_ABORTED,
  28818. + bulk_user);
  28819. + break;
  28820. +
  28821. + case VCHIQ_BULK_RECEIVE_ABORTED:
  28822. + service->callback(service->callback_param,
  28823. + VCHI_CALLBACK_BULK_RECEIVE_ABORTED,
  28824. + bulk_user);
  28825. + break;
  28826. +
  28827. + default:
  28828. + WARN(1, "not supported\n");
  28829. + break;
  28830. + }
  28831. +
  28832. +release:
  28833. + vchiq_release_message(service->handle, header);
  28834. +done:
  28835. + return VCHIQ_SUCCESS;
  28836. +}
  28837. +
  28838. +static SHIM_SERVICE_T *service_alloc(VCHIQ_INSTANCE_T instance,
  28839. + SERVICE_CREATION_T *setup)
  28840. +{
  28841. + SHIM_SERVICE_T *service = kzalloc(sizeof(SHIM_SERVICE_T), GFP_KERNEL);
  28842. +
  28843. + (void)instance;
  28844. +
  28845. + if (service) {
  28846. + if (vchiu_queue_init(&service->queue, 64)) {
  28847. + service->callback = setup->callback;
  28848. + service->callback_param = setup->callback_param;
  28849. + } else {
  28850. + kfree(service);
  28851. + service = NULL;
  28852. + }
  28853. + }
  28854. +
  28855. + return service;
  28856. +}
  28857. +
  28858. +static void service_free(SHIM_SERVICE_T *service)
  28859. +{
  28860. + if (service) {
  28861. + vchiu_queue_delete(&service->queue);
  28862. + kfree(service);
  28863. + }
  28864. +}
  28865. +
  28866. +int32_t vchi_service_open(VCHI_INSTANCE_T instance_handle,
  28867. + SERVICE_CREATION_T *setup,
  28868. + VCHI_SERVICE_HANDLE_T *handle)
  28869. +{
  28870. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  28871. + SHIM_SERVICE_T *service = service_alloc(instance, setup);
  28872. + if (service) {
  28873. + VCHIQ_SERVICE_PARAMS_T params;
  28874. + VCHIQ_STATUS_T status;
  28875. +
  28876. + memset(&params, 0, sizeof(params));
  28877. + params.fourcc = setup->service_id;
  28878. + params.callback = shim_callback;
  28879. + params.userdata = service;
  28880. + params.version = setup->version.version;
  28881. + params.version_min = setup->version.version_min;
  28882. +
  28883. + status = vchiq_open_service(instance, &params,
  28884. + &service->handle);
  28885. + if (status != VCHIQ_SUCCESS) {
  28886. + service_free(service);
  28887. + service = NULL;
  28888. + }
  28889. + }
  28890. +
  28891. + *handle = (VCHI_SERVICE_HANDLE_T)service;
  28892. +
  28893. + return (service != NULL) ? 0 : -1;
  28894. +}
  28895. +EXPORT_SYMBOL(vchi_service_open);
  28896. +
  28897. +int32_t vchi_service_create(VCHI_INSTANCE_T instance_handle,
  28898. + SERVICE_CREATION_T *setup,
  28899. + VCHI_SERVICE_HANDLE_T *handle)
  28900. +{
  28901. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  28902. + SHIM_SERVICE_T *service = service_alloc(instance, setup);
  28903. + if (service) {
  28904. + VCHIQ_SERVICE_PARAMS_T params;
  28905. + VCHIQ_STATUS_T status;
  28906. +
  28907. + memset(&params, 0, sizeof(params));
  28908. + params.fourcc = setup->service_id;
  28909. + params.callback = shim_callback;
  28910. + params.userdata = service;
  28911. + params.version = setup->version.version;
  28912. + params.version_min = setup->version.version_min;
  28913. + status = vchiq_add_service(instance, &params, &service->handle);
  28914. +
  28915. + if (status != VCHIQ_SUCCESS) {
  28916. + service_free(service);
  28917. + service = NULL;
  28918. + }
  28919. + }
  28920. +
  28921. + *handle = (VCHI_SERVICE_HANDLE_T)service;
  28922. +
  28923. + return (service != NULL) ? 0 : -1;
  28924. +}
  28925. +EXPORT_SYMBOL(vchi_service_create);
  28926. +
  28927. +int32_t vchi_service_close(const VCHI_SERVICE_HANDLE_T handle)
  28928. +{
  28929. + int32_t ret = -1;
  28930. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  28931. + if (service) {
  28932. + VCHIQ_STATUS_T status = vchiq_close_service(service->handle);
  28933. + if (status == VCHIQ_SUCCESS) {
  28934. + service_free(service);
  28935. + service = NULL;
  28936. + }
  28937. +
  28938. + ret = vchiq_status_to_vchi(status);
  28939. + }
  28940. + return ret;
  28941. +}
  28942. +EXPORT_SYMBOL(vchi_service_close);
  28943. +
  28944. +int32_t vchi_service_destroy(const VCHI_SERVICE_HANDLE_T handle)
  28945. +{
  28946. + int32_t ret = -1;
  28947. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  28948. + if (service) {
  28949. + VCHIQ_STATUS_T status = vchiq_remove_service(service->handle);
  28950. + if (status == VCHIQ_SUCCESS) {
  28951. + service_free(service);
  28952. + service = NULL;
  28953. + }
  28954. +
  28955. + ret = vchiq_status_to_vchi(status);
  28956. + }
  28957. + return ret;
  28958. +}
  28959. +EXPORT_SYMBOL(vchi_service_destroy);
  28960. +
  28961. +int32_t vchi_get_peer_version( const VCHI_SERVICE_HANDLE_T handle, short *peer_version )
  28962. +{
  28963. + int32_t ret = -1;
  28964. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  28965. + if(service)
  28966. + {
  28967. + VCHIQ_STATUS_T status = vchiq_get_peer_version(service->handle, peer_version);
  28968. + ret = vchiq_status_to_vchi( status );
  28969. + }
  28970. + return ret;
  28971. +}
  28972. +EXPORT_SYMBOL(vchi_get_peer_version);
  28973. +
  28974. +/* ----------------------------------------------------------------------
  28975. + * read a uint32_t from buffer.
  28976. + * network format is defined to be little endian
  28977. + * -------------------------------------------------------------------- */
  28978. +uint32_t
  28979. +vchi_readbuf_uint32(const void *_ptr)
  28980. +{
  28981. + const unsigned char *ptr = _ptr;
  28982. + return ptr[0] | (ptr[1] << 8) | (ptr[2] << 16) | (ptr[3] << 24);
  28983. +}
  28984. +
  28985. +/* ----------------------------------------------------------------------
  28986. + * write a uint32_t to buffer.
  28987. + * network format is defined to be little endian
  28988. + * -------------------------------------------------------------------- */
  28989. +void
  28990. +vchi_writebuf_uint32(void *_ptr, uint32_t value)
  28991. +{
  28992. + unsigned char *ptr = _ptr;
  28993. + ptr[0] = (unsigned char)((value >> 0) & 0xFF);
  28994. + ptr[1] = (unsigned char)((value >> 8) & 0xFF);
  28995. + ptr[2] = (unsigned char)((value >> 16) & 0xFF);
  28996. + ptr[3] = (unsigned char)((value >> 24) & 0xFF);
  28997. +}
  28998. +
  28999. +/* ----------------------------------------------------------------------
  29000. + * read a uint16_t from buffer.
  29001. + * network format is defined to be little endian
  29002. + * -------------------------------------------------------------------- */
  29003. +uint16_t
  29004. +vchi_readbuf_uint16(const void *_ptr)
  29005. +{
  29006. + const unsigned char *ptr = _ptr;
  29007. + return ptr[0] | (ptr[1] << 8);
  29008. +}
  29009. +
  29010. +/* ----------------------------------------------------------------------
  29011. + * write a uint16_t into the buffer.
  29012. + * network format is defined to be little endian
  29013. + * -------------------------------------------------------------------- */
  29014. +void
  29015. +vchi_writebuf_uint16(void *_ptr, uint16_t value)
  29016. +{
  29017. + unsigned char *ptr = _ptr;
  29018. + ptr[0] = (value >> 0) & 0xFF;
  29019. + ptr[1] = (value >> 8) & 0xFF;
  29020. +}
  29021. +
  29022. +/***********************************************************
  29023. + * Name: vchi_service_use
  29024. + *
  29025. + * Arguments: const VCHI_SERVICE_HANDLE_T handle
  29026. + *
  29027. + * Description: Routine to increment refcount on a service
  29028. + *
  29029. + * Returns: void
  29030. + *
  29031. + ***********************************************************/
  29032. +int32_t vchi_service_use(const VCHI_SERVICE_HANDLE_T handle)
  29033. +{
  29034. + int32_t ret = -1;
  29035. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29036. + if (service)
  29037. + ret = vchiq_status_to_vchi(vchiq_use_service(service->handle));
  29038. + return ret;
  29039. +}
  29040. +EXPORT_SYMBOL(vchi_service_use);
  29041. +
  29042. +/***********************************************************
  29043. + * Name: vchi_service_release
  29044. + *
  29045. + * Arguments: const VCHI_SERVICE_HANDLE_T handle
  29046. + *
  29047. + * Description: Routine to decrement refcount on a service
  29048. + *
  29049. + * Returns: void
  29050. + *
  29051. + ***********************************************************/
  29052. +int32_t vchi_service_release(const VCHI_SERVICE_HANDLE_T handle)
  29053. +{
  29054. + int32_t ret = -1;
  29055. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29056. + if (service)
  29057. + ret = vchiq_status_to_vchi(
  29058. + vchiq_release_service(service->handle));
  29059. + return ret;
  29060. +}
  29061. +EXPORT_SYMBOL(vchi_service_release);
  29062. diff -Nur linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c
  29063. --- linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c 1970-01-01 01:00:00.000000000 +0100
  29064. +++ linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c 2014-02-17 22:41:01.000000000 +0100
  29065. @@ -0,0 +1,151 @@
  29066. +/**
  29067. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  29068. + *
  29069. + * Redistribution and use in source and binary forms, with or without
  29070. + * modification, are permitted provided that the following conditions
  29071. + * are met:
  29072. + * 1. Redistributions of source code must retain the above copyright
  29073. + * notice, this list of conditions, and the following disclaimer,
  29074. + * without modification.
  29075. + * 2. Redistributions in binary form must reproduce the above copyright
  29076. + * notice, this list of conditions and the following disclaimer in the
  29077. + * documentation and/or other materials provided with the distribution.
  29078. + * 3. The names of the above-listed copyright holders may not be used
  29079. + * to endorse or promote products derived from this software without
  29080. + * specific prior written permission.
  29081. + *
  29082. + * ALTERNATIVELY, this software may be distributed under the terms of the
  29083. + * GNU General Public License ("GPL") version 2, as published by the Free
  29084. + * Software Foundation.
  29085. + *
  29086. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  29087. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  29088. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  29089. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  29090. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  29091. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29092. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  29093. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29094. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29095. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29096. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29097. + */
  29098. +
  29099. +#include "vchiq_util.h"
  29100. +
  29101. +static inline int is_pow2(int i)
  29102. +{
  29103. + return i && !(i & (i - 1));
  29104. +}
  29105. +
  29106. +int vchiu_queue_init(VCHIU_QUEUE_T *queue, int size)
  29107. +{
  29108. + WARN_ON(!is_pow2(size));
  29109. +
  29110. + queue->size = size;
  29111. + queue->read = 0;
  29112. + queue->write = 0;
  29113. +
  29114. + sema_init(&queue->pop, 0);
  29115. + sema_init(&queue->push, 0);
  29116. +
  29117. + queue->storage = kzalloc(size * sizeof(VCHIQ_HEADER_T *), GFP_KERNEL);
  29118. + if (queue->storage == NULL) {
  29119. + vchiu_queue_delete(queue);
  29120. + return 0;
  29121. + }
  29122. + return 1;
  29123. +}
  29124. +
  29125. +void vchiu_queue_delete(VCHIU_QUEUE_T *queue)
  29126. +{
  29127. + if (queue->storage != NULL)
  29128. + kfree(queue->storage);
  29129. +}
  29130. +
  29131. +int vchiu_queue_is_empty(VCHIU_QUEUE_T *queue)
  29132. +{
  29133. + return queue->read == queue->write;
  29134. +}
  29135. +
  29136. +int vchiu_queue_is_full(VCHIU_QUEUE_T *queue)
  29137. +{
  29138. + return queue->write == queue->read + queue->size;
  29139. +}
  29140. +
  29141. +void vchiu_queue_push(VCHIU_QUEUE_T *queue, VCHIQ_HEADER_T *header)
  29142. +{
  29143. + while (queue->write == queue->read + queue->size) {
  29144. + if (down_interruptible(&queue->pop) != 0) {
  29145. + flush_signals(current);
  29146. + }
  29147. + }
  29148. +
  29149. + /*
  29150. + * Write to queue->storage must be visible after read from
  29151. + * queue->read
  29152. + */
  29153. + smp_mb();
  29154. +
  29155. + queue->storage[queue->write & (queue->size - 1)] = header;
  29156. +
  29157. + /*
  29158. + * Write to queue->storage must be visible before write to
  29159. + * queue->write
  29160. + */
  29161. + smp_wmb();
  29162. +
  29163. + queue->write++;
  29164. +
  29165. + up(&queue->push);
  29166. +}
  29167. +
  29168. +VCHIQ_HEADER_T *vchiu_queue_peek(VCHIU_QUEUE_T *queue)
  29169. +{
  29170. + while (queue->write == queue->read) {
  29171. + if (down_interruptible(&queue->push) != 0) {
  29172. + flush_signals(current);
  29173. + }
  29174. + }
  29175. +
  29176. + up(&queue->push); // We haven't removed anything from the queue.
  29177. +
  29178. + /*
  29179. + * Read from queue->storage must be visible after read from
  29180. + * queue->write
  29181. + */
  29182. + smp_rmb();
  29183. +
  29184. + return queue->storage[queue->read & (queue->size - 1)];
  29185. +}
  29186. +
  29187. +VCHIQ_HEADER_T *vchiu_queue_pop(VCHIU_QUEUE_T *queue)
  29188. +{
  29189. + VCHIQ_HEADER_T *header;
  29190. +
  29191. + while (queue->write == queue->read) {
  29192. + if (down_interruptible(&queue->push) != 0) {
  29193. + flush_signals(current);
  29194. + }
  29195. + }
  29196. +
  29197. + /*
  29198. + * Read from queue->storage must be visible after read from
  29199. + * queue->write
  29200. + */
  29201. + smp_rmb();
  29202. +
  29203. + header = queue->storage[queue->read & (queue->size - 1)];
  29204. +
  29205. + /*
  29206. + * Read from queue->storage must be visible before write to
  29207. + * queue->read
  29208. + */
  29209. + smp_mb();
  29210. +
  29211. + queue->read++;
  29212. +
  29213. + up(&queue->pop);
  29214. +
  29215. + return header;
  29216. +}
  29217. diff -Nur linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h
  29218. --- linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h 1970-01-01 01:00:00.000000000 +0100
  29219. +++ linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h 2014-02-17 22:41:01.000000000 +0100
  29220. @@ -0,0 +1,81 @@
  29221. +/**
  29222. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  29223. + *
  29224. + * Redistribution and use in source and binary forms, with or without
  29225. + * modification, are permitted provided that the following conditions
  29226. + * are met:
  29227. + * 1. Redistributions of source code must retain the above copyright
  29228. + * notice, this list of conditions, and the following disclaimer,
  29229. + * without modification.
  29230. + * 2. Redistributions in binary form must reproduce the above copyright
  29231. + * notice, this list of conditions and the following disclaimer in the
  29232. + * documentation and/or other materials provided with the distribution.
  29233. + * 3. The names of the above-listed copyright holders may not be used
  29234. + * to endorse or promote products derived from this software without
  29235. + * specific prior written permission.
  29236. + *
  29237. + * ALTERNATIVELY, this software may be distributed under the terms of the
  29238. + * GNU General Public License ("GPL") version 2, as published by the Free
  29239. + * Software Foundation.
  29240. + *
  29241. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  29242. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  29243. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  29244. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  29245. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  29246. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29247. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  29248. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29249. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29250. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29251. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29252. + */
  29253. +
  29254. +#ifndef VCHIQ_UTIL_H
  29255. +#define VCHIQ_UTIL_H
  29256. +
  29257. +#include <linux/types.h>
  29258. +#include <linux/semaphore.h>
  29259. +#include <linux/mutex.h>
  29260. +#include <linux/bitops.h>
  29261. +#include <linux/kthread.h>
  29262. +#include <linux/wait.h>
  29263. +#include <linux/vmalloc.h>
  29264. +#include <linux/jiffies.h>
  29265. +#include <linux/delay.h>
  29266. +#include <linux/string.h>
  29267. +#include <linux/types.h>
  29268. +#include <linux/interrupt.h>
  29269. +#include <linux/random.h>
  29270. +#include <linux/sched.h>
  29271. +#include <linux/ctype.h>
  29272. +#include <linux/uaccess.h>
  29273. +#include <linux/time.h> /* for time_t */
  29274. +#include <linux/slab.h>
  29275. +#include <linux/vmalloc.h>
  29276. +
  29277. +#include "vchiq_if.h"
  29278. +
  29279. +typedef struct {
  29280. + int size;
  29281. + int read;
  29282. + int write;
  29283. +
  29284. + struct semaphore pop;
  29285. + struct semaphore push;
  29286. +
  29287. + VCHIQ_HEADER_T **storage;
  29288. +} VCHIU_QUEUE_T;
  29289. +
  29290. +extern int vchiu_queue_init(VCHIU_QUEUE_T *queue, int size);
  29291. +extern void vchiu_queue_delete(VCHIU_QUEUE_T *queue);
  29292. +
  29293. +extern int vchiu_queue_is_empty(VCHIU_QUEUE_T *queue);
  29294. +extern int vchiu_queue_is_full(VCHIU_QUEUE_T *queue);
  29295. +
  29296. +extern void vchiu_queue_push(VCHIU_QUEUE_T *queue, VCHIQ_HEADER_T *header);
  29297. +
  29298. +extern VCHIQ_HEADER_T *vchiu_queue_peek(VCHIU_QUEUE_T *queue);
  29299. +extern VCHIQ_HEADER_T *vchiu_queue_pop(VCHIU_QUEUE_T *queue);
  29300. +
  29301. +#endif
  29302. diff -Nur linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c
  29303. --- linux-3.13.3.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c 1970-01-01 01:00:00.000000000 +0100
  29304. +++ linux-3.13.3/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c 2014-02-17 22:41:01.000000000 +0100
  29305. @@ -0,0 +1,59 @@
  29306. +/**
  29307. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  29308. + *
  29309. + * Redistribution and use in source and binary forms, with or without
  29310. + * modification, are permitted provided that the following conditions
  29311. + * are met:
  29312. + * 1. Redistributions of source code must retain the above copyright
  29313. + * notice, this list of conditions, and the following disclaimer,
  29314. + * without modification.
  29315. + * 2. Redistributions in binary form must reproduce the above copyright
  29316. + * notice, this list of conditions and the following disclaimer in the
  29317. + * documentation and/or other materials provided with the distribution.
  29318. + * 3. The names of the above-listed copyright holders may not be used
  29319. + * to endorse or promote products derived from this software without
  29320. + * specific prior written permission.
  29321. + *
  29322. + * ALTERNATIVELY, this software may be distributed under the terms of the
  29323. + * GNU General Public License ("GPL") version 2, as published by the Free
  29324. + * Software Foundation.
  29325. + *
  29326. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  29327. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  29328. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  29329. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  29330. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  29331. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29332. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  29333. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29334. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29335. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29336. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29337. + */
  29338. +#include "vchiq_build_info.h"
  29339. +#include <linux/broadcom/vc_debug_sym.h>
  29340. +
  29341. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_hostname, "dc4-arm-01" );
  29342. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_version, "9245b4c35b99b3870e1f7dc598c5692b3c66a6f0 (tainted)" );
  29343. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_time, __TIME__ );
  29344. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_date, __DATE__ );
  29345. +
  29346. +const char *vchiq_get_build_hostname( void )
  29347. +{
  29348. + return vchiq_build_hostname;
  29349. +}
  29350. +
  29351. +const char *vchiq_get_build_version( void )
  29352. +{
  29353. + return vchiq_build_version;
  29354. +}
  29355. +
  29356. +const char *vchiq_get_build_date( void )
  29357. +{
  29358. + return vchiq_build_date;
  29359. +}
  29360. +
  29361. +const char *vchiq_get_build_time( void )
  29362. +{
  29363. + return vchiq_build_time;
  29364. +}
  29365. diff -Nur linux-3.13.3.orig/drivers/misc/vc04_services/Kconfig linux-3.13.3/drivers/misc/vc04_services/Kconfig
  29366. --- linux-3.13.3.orig/drivers/misc/vc04_services/Kconfig 1970-01-01 01:00:00.000000000 +0100
  29367. +++ linux-3.13.3/drivers/misc/vc04_services/Kconfig 2014-02-17 22:41:01.000000000 +0100
  29368. @@ -0,0 +1,9 @@
  29369. +config BCM2708_VCHIQ
  29370. + tristate "Videocore VCHIQ"
  29371. + depends on MACH_BCM2708
  29372. + default y
  29373. + help
  29374. + Kernel to VideoCore communication interface for the
  29375. + BCM2708 family of products.
  29376. + Defaults to Y when the Broadcom Videocore services
  29377. + are included in the build, N otherwise.
  29378. diff -Nur linux-3.13.3.orig/drivers/misc/vc04_services/Makefile linux-3.13.3/drivers/misc/vc04_services/Makefile
  29379. --- linux-3.13.3.orig/drivers/misc/vc04_services/Makefile 1970-01-01 01:00:00.000000000 +0100
  29380. +++ linux-3.13.3/drivers/misc/vc04_services/Makefile 2014-02-17 22:41:01.000000000 +0100
  29381. @@ -0,0 +1,17 @@
  29382. +ifeq ($(CONFIG_MACH_BCM2708),y)
  29383. +
  29384. +obj-$(CONFIG_BCM2708_VCHIQ) += vchiq.o
  29385. +
  29386. +vchiq-objs := \
  29387. + interface/vchiq_arm/vchiq_core.o \
  29388. + interface/vchiq_arm/vchiq_arm.o \
  29389. + interface/vchiq_arm/vchiq_kern_lib.o \
  29390. + interface/vchiq_arm/vchiq_2835_arm.o \
  29391. + interface/vchiq_arm/vchiq_proc.o \
  29392. + interface/vchiq_arm/vchiq_shim.o \
  29393. + interface/vchiq_arm/vchiq_util.o \
  29394. + interface/vchiq_arm/vchiq_connected.o \
  29395. +
  29396. +EXTRA_CFLAGS += -DVCOS_VERIFY_BKPTS=1 -Idrivers/misc/vc04_services -DUSE_VCHIQ_ARM -D__VCCOREVER__=0x04000000
  29397. +
  29398. +endif
  29399. diff -Nur linux-3.13.3.orig/drivers/mmc/card/block.c linux-3.13.3/drivers/mmc/card/block.c
  29400. --- linux-3.13.3.orig/drivers/mmc/card/block.c 2014-02-13 23:00:14.000000000 +0100
  29401. +++ linux-3.13.3/drivers/mmc/card/block.c 2014-02-17 22:41:01.000000000 +0100
  29402. @@ -1361,7 +1361,7 @@
  29403. brq->data.blocks = 1;
  29404. }
  29405. - if (brq->data.blocks > 1 || do_rel_wr) {
  29406. + if (brq->data.blocks > 1 || do_rel_wr || card->host->caps2 & MMC_CAP2_FORCE_MULTIBLOCK) {
  29407. /* SPI multiblock writes terminate using a special
  29408. * token, not a STOP_TRANSMISSION request.
  29409. */
  29410. diff -Nur linux-3.13.3.orig/drivers/mmc/core/sd.c linux-3.13.3/drivers/mmc/core/sd.c
  29411. --- linux-3.13.3.orig/drivers/mmc/core/sd.c 2014-02-13 23:00:14.000000000 +0100
  29412. +++ linux-3.13.3/drivers/mmc/core/sd.c 2014-02-17 22:41:01.000000000 +0100
  29413. @@ -15,6 +15,8 @@
  29414. #include <linux/slab.h>
  29415. #include <linux/stat.h>
  29416. #include <linux/pm_runtime.h>
  29417. +#include <linux/jiffies.h>
  29418. +#include <linux/nmi.h>
  29419. #include <linux/mmc/host.h>
  29420. #include <linux/mmc/card.h>
  29421. @@ -67,6 +69,15 @@
  29422. __res & __mask; \
  29423. })
  29424. +// timeout for tries
  29425. +static const unsigned long retry_timeout_ms= 10*1000;
  29426. +
  29427. +// try at least 10 times, even if timeout is reached
  29428. +static const int retry_min_tries= 10;
  29429. +
  29430. +// delay between tries
  29431. +static const unsigned long retry_delay_ms= 10;
  29432. +
  29433. /*
  29434. * Given the decoded CSD structure, decode the raw CID to our CID structure.
  29435. */
  29436. @@ -219,12 +230,63 @@
  29437. }
  29438. /*
  29439. - * Fetch and process SD Status register.
  29440. + * Fetch and process SD Configuration Register.
  29441. + */
  29442. +static int mmc_read_scr(struct mmc_card *card)
  29443. +{
  29444. + unsigned long timeout_at;
  29445. + int err, tries;
  29446. +
  29447. + timeout_at= jiffies + msecs_to_jiffies( retry_timeout_ms );
  29448. + tries= 0;
  29449. +
  29450. + while( tries < retry_min_tries || time_before( jiffies, timeout_at ) )
  29451. + {
  29452. + unsigned long delay_at;
  29453. + tries++;
  29454. +
  29455. + err = mmc_app_send_scr(card, card->raw_scr);
  29456. + if( !err )
  29457. + break; // success!!!
  29458. +
  29459. + touch_nmi_watchdog(); // we are still alive!
  29460. +
  29461. + // delay
  29462. + delay_at= jiffies + msecs_to_jiffies( retry_delay_ms );
  29463. + while( time_before( jiffies, delay_at ) )
  29464. + {
  29465. + mdelay( 1 );
  29466. + touch_nmi_watchdog(); // we are still alive!
  29467. + }
  29468. + }
  29469. +
  29470. + if( err)
  29471. + {
  29472. + 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 );
  29473. + return err;
  29474. + }
  29475. +
  29476. + if( tries > 1 )
  29477. + {
  29478. + pr_info("%s: could read SD Configuration register (SCR) at the %dth attempt\n", mmc_hostname(card->host), tries );
  29479. + }
  29480. +
  29481. + err = mmc_decode_scr(card);
  29482. + if (err)
  29483. + return err;
  29484. +
  29485. + return err;
  29486. +}
  29487. +
  29488. +/*
  29489. + * Fetch and process SD Status Register.
  29490. */
  29491. static int mmc_read_ssr(struct mmc_card *card)
  29492. {
  29493. + unsigned long timeout_at;
  29494. unsigned int au, es, et, eo;
  29495. int err, i;
  29496. + int tries;
  29497. u32 *ssr;
  29498. if (!(card->csd.cmdclass & CCC_APP_SPEC)) {
  29499. @@ -237,14 +299,40 @@
  29500. if (!ssr)
  29501. return -ENOMEM;
  29502. - err = mmc_app_sd_status(card, ssr);
  29503. - if (err) {
  29504. - pr_warning("%s: problem reading SD Status "
  29505. - "register.\n", mmc_hostname(card->host));
  29506. - err = 0;
  29507. + timeout_at= jiffies + msecs_to_jiffies( retry_timeout_ms );
  29508. + tries= 0;
  29509. +
  29510. + while( tries < retry_min_tries || time_before( jiffies, timeout_at ) )
  29511. + {
  29512. + unsigned long delay_at;
  29513. + tries++;
  29514. +
  29515. + err= mmc_app_sd_status(card, ssr);
  29516. + if( !err )
  29517. + break; // sucess!!!
  29518. +
  29519. + touch_nmi_watchdog(); // we are still alive!
  29520. +
  29521. + // delay
  29522. + delay_at= jiffies + msecs_to_jiffies( retry_delay_ms );
  29523. + while( time_before( jiffies, delay_at ) )
  29524. + {
  29525. + mdelay( 1 );
  29526. + touch_nmi_watchdog(); // we are still alive!
  29527. + }
  29528. + }
  29529. +
  29530. + if( err)
  29531. + {
  29532. + 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 );
  29533. goto out;
  29534. }
  29535. + if( tries > 1 )
  29536. + {
  29537. + pr_info("%s: read SD Status register (SSR) after %d attempts\n", mmc_hostname(card->host), tries );
  29538. + }
  29539. +
  29540. for (i = 0; i < 16; i++)
  29541. ssr[i] = be32_to_cpu(ssr[i]);
  29542. @@ -826,14 +914,10 @@
  29543. if (!reinit) {
  29544. /*
  29545. - * Fetch SCR from card.
  29546. + * Fetch and decode SD Configuration register.
  29547. */
  29548. - err = mmc_app_send_scr(card, card->raw_scr);
  29549. - if (err)
  29550. - return err;
  29551. -
  29552. - err = mmc_decode_scr(card);
  29553. - if (err)
  29554. + err = mmc_read_scr(card);
  29555. + if( err )
  29556. return err;
  29557. /*
  29558. diff -Nur linux-3.13.3.orig/drivers/mmc/host/Kconfig linux-3.13.3/drivers/mmc/host/Kconfig
  29559. --- linux-3.13.3.orig/drivers/mmc/host/Kconfig 2014-02-13 23:00:14.000000000 +0100
  29560. +++ linux-3.13.3/drivers/mmc/host/Kconfig 2014-02-17 22:41:01.000000000 +0100
  29561. @@ -260,6 +260,27 @@
  29562. If you have a controller with this interface, say Y or M here.
  29563. +config MMC_SDHCI_BCM2708
  29564. + tristate "SDHCI support on BCM2708"
  29565. + depends on MMC_SDHCI && MACH_BCM2708
  29566. + select MMC_SDHCI_IO_ACCESSORS
  29567. + help
  29568. + This selects the Secure Digital Host Controller Interface (SDHCI)
  29569. + often referrered to as the eMMC block.
  29570. +
  29571. + If you have a controller with this interface, say Y or M here.
  29572. +
  29573. + If unsure, say N.
  29574. +
  29575. +config MMC_SDHCI_BCM2708_DMA
  29576. + bool "DMA support on BCM2708 Arasan controller"
  29577. + depends on MMC_SDHCI_BCM2708
  29578. + help
  29579. + Enable DMA support on the Arasan SDHCI controller in Broadcom 2708
  29580. + based chips.
  29581. +
  29582. + If unsure, say N.
  29583. +
  29584. config MMC_SDHCI_BCM2835
  29585. tristate "SDHCI platform support for the BCM2835 SD/MMC Controller"
  29586. depends on ARCH_BCM2835
  29587. diff -Nur linux-3.13.3.orig/drivers/mmc/host/Makefile linux-3.13.3/drivers/mmc/host/Makefile
  29588. --- linux-3.13.3.orig/drivers/mmc/host/Makefile 2014-02-13 23:00:14.000000000 +0100
  29589. +++ linux-3.13.3/drivers/mmc/host/Makefile 2014-02-17 22:41:01.000000000 +0100
  29590. @@ -15,6 +15,7 @@
  29591. obj-$(CONFIG_MMC_SDHCI_S3C) += sdhci-s3c.o
  29592. obj-$(CONFIG_MMC_SDHCI_SIRF) += sdhci-sirf.o
  29593. obj-$(CONFIG_MMC_SDHCI_SPEAR) += sdhci-spear.o
  29594. +obj-$(CONFIG_MMC_SDHCI_BCM2708) += sdhci-bcm2708.o
  29595. obj-$(CONFIG_MMC_WBSD) += wbsd.o
  29596. obj-$(CONFIG_MMC_AU1X) += au1xmmc.o
  29597. obj-$(CONFIG_MMC_OMAP) += omap.o
  29598. diff -Nur linux-3.13.3.orig/drivers/mmc/host/sdhci-bcm2708.c linux-3.13.3/drivers/mmc/host/sdhci-bcm2708.c
  29599. --- linux-3.13.3.orig/drivers/mmc/host/sdhci-bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  29600. +++ linux-3.13.3/drivers/mmc/host/sdhci-bcm2708.c 2014-02-17 22:41:01.000000000 +0100
  29601. @@ -0,0 +1,1410 @@
  29602. +/*
  29603. + * sdhci-bcm2708.c Support for SDHCI device on BCM2708
  29604. + * Copyright (c) 2010 Broadcom
  29605. + *
  29606. + * This program is free software; you can redistribute it and/or modify
  29607. + * it under the terms of the GNU General Public License version 2 as
  29608. + * published by the Free Software Foundation.
  29609. + *
  29610. + * This program is distributed in the hope that it will be useful,
  29611. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  29612. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  29613. + * GNU General Public License for more details.
  29614. + *
  29615. + * You should have received a copy of the GNU General Public License
  29616. + * along with this program; if not, write to the Free Software
  29617. + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  29618. + */
  29619. +
  29620. +/* Supports:
  29621. + * SDHCI platform device - Arasan SD controller in BCM2708
  29622. + *
  29623. + * Inspired by sdhci-pci.c, by Pierre Ossman
  29624. + */
  29625. +
  29626. +#include <linux/delay.h>
  29627. +#include <linux/highmem.h>
  29628. +#include <linux/platform_device.h>
  29629. +#include <linux/module.h>
  29630. +#include <linux/mmc/mmc.h>
  29631. +#include <linux/mmc/host.h>
  29632. +#include <linux/mmc/sd.h>
  29633. +
  29634. +#include <linux/io.h>
  29635. +#include <linux/dma-mapping.h>
  29636. +#include <mach/dma.h>
  29637. +
  29638. +#include "sdhci.h"
  29639. +
  29640. +/*****************************************************************************\
  29641. + * *
  29642. + * Configuration *
  29643. + * *
  29644. +\*****************************************************************************/
  29645. +
  29646. +#define DRIVER_NAME "bcm2708_sdhci"
  29647. +
  29648. +/* for the time being insist on DMA mode - PIO seems not to work */
  29649. +#ifndef CONFIG_MMC_SDHCI_BCM2708_DMA
  29650. +#warning Non-DMA (PIO) version of this driver currently unavailable
  29651. +#endif
  29652. +#undef CONFIG_MMC_SDHCI_BCM2708_DMA
  29653. +#define CONFIG_MMC_SDHCI_BCM2708_DMA y
  29654. +
  29655. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  29656. +/* #define CHECK_DMA_USE */
  29657. +#endif
  29658. +//#define LOG_REGISTERS
  29659. +
  29660. +#define USE_SCHED_TIME
  29661. +#define USE_SPACED_WRITES_2CLK 1 /* space consecutive register writes */
  29662. +#define USE_SOFTWARE_TIMEOUTS 1 /* not hardware timeouts */
  29663. +#define SOFTWARE_ERASE_TIMEOUT_SEC 30
  29664. +
  29665. +#define SDHCI_BCM_DMA_CHAN 4 /* this default is normally overriden */
  29666. +#define SDHCI_BCM_DMA_WAITS 0 /* delays slowing DMA transfers: 0-31 */
  29667. +/* We are worried that SD card DMA use may be blocking the AXI bus for others */
  29668. +
  29669. +/*! TODO: obtain these from the physical address */
  29670. +#define DMA_SDHCI_BASE 0x7e300000 /* EMMC register block on Videocore */
  29671. +#define DMA_SDHCI_BUFFER (DMA_SDHCI_BASE + SDHCI_BUFFER)
  29672. +
  29673. +#define BCM2708_SDHCI_SLEEP_TIMEOUT 1000 /* msecs */
  29674. +
  29675. +/* Mhz clock that the EMMC core is running at. Should match the platform clockman settings */
  29676. +#define BCM2708_EMMC_CLOCK_FREQ 50000000
  29677. +
  29678. +#define REG_EXRDFIFO_EN 0x80
  29679. +#define REG_EXRDFIFO_CFG 0x84
  29680. +
  29681. +int cycle_delay=2;
  29682. +
  29683. +/*****************************************************************************\
  29684. + * *
  29685. + * Debug *
  29686. + * *
  29687. +\*****************************************************************************/
  29688. +
  29689. +
  29690. +
  29691. +#define DBG(f, x...) \
  29692. + pr_debug(DRIVER_NAME " [%s()]: " f, __func__,## x)
  29693. +// printk(KERN_INFO DRIVER_NAME " [%s()]: " f, __func__,## x)//GRAYG
  29694. +
  29695. +
  29696. +/*****************************************************************************\
  29697. + * *
  29698. + * High Precision Time *
  29699. + * *
  29700. +\*****************************************************************************/
  29701. +
  29702. +#ifdef USE_SCHED_TIME
  29703. +
  29704. +#include <mach/frc.h>
  29705. +
  29706. +typedef unsigned long hptime_t;
  29707. +
  29708. +#define FMT_HPT "lu"
  29709. +
  29710. +static inline hptime_t hptime(void)
  29711. +{
  29712. + return frc_clock_ticks32();
  29713. +}
  29714. +
  29715. +#define HPTIME_CLK_NS 1000ul
  29716. +
  29717. +#else
  29718. +
  29719. +typedef unsigned long hptime_t;
  29720. +
  29721. +#define FMT_HPT "lu"
  29722. +
  29723. +static inline hptime_t hptime(void)
  29724. +{
  29725. + return jiffies;
  29726. +}
  29727. +
  29728. +#define HPTIME_CLK_NS (1000000000ul/HZ)
  29729. +
  29730. +#endif
  29731. +
  29732. +static inline unsigned long int since_ns(hptime_t t)
  29733. +{
  29734. + return (unsigned long)((hptime() - t) * HPTIME_CLK_NS);
  29735. +}
  29736. +
  29737. +static bool allow_highspeed = 1;
  29738. +static int emmc_clock_freq = BCM2708_EMMC_CLOCK_FREQ;
  29739. +static bool sync_after_dma = 1;
  29740. +static bool missing_status = 1;
  29741. +static bool spurious_crc_acmd51 = 0;
  29742. +bool enable_llm = 1;
  29743. +bool extra_messages = 0;
  29744. +
  29745. +#if 0
  29746. +static void hptime_test(void)
  29747. +{
  29748. + hptime_t now;
  29749. + hptime_t later;
  29750. +
  29751. + now = hptime();
  29752. + msleep(10);
  29753. + later = hptime();
  29754. +
  29755. + printk(KERN_INFO DRIVER_NAME": 10ms = %"FMT_HPT" clks "
  29756. + "(from %"FMT_HPT" to %"FMT_HPT") = %luns\n",
  29757. + later-now, now, later,
  29758. + (unsigned long)(HPTIME_CLK_NS * (later - now)));
  29759. +
  29760. + now = hptime();
  29761. + msleep(1000);
  29762. + later = hptime();
  29763. +
  29764. + printk(KERN_INFO DRIVER_NAME": 1s = %"FMT_HPT" clks "
  29765. + "(from %"FMT_HPT" to %"FMT_HPT") = %luns\n",
  29766. + later-now, now, later,
  29767. + (unsigned long)(HPTIME_CLK_NS * (later - now)));
  29768. +}
  29769. +#endif
  29770. +
  29771. +/*****************************************************************************\
  29772. + * *
  29773. + * SDHCI core callbacks *
  29774. + * *
  29775. +\*****************************************************************************/
  29776. +
  29777. +
  29778. +#ifdef CHECK_DMA_USE
  29779. +/*#define CHECK_DMA_REG_USE*/
  29780. +#endif
  29781. +
  29782. +#ifdef CHECK_DMA_REG_USE
  29783. +/* we don't expect anything to be using these registers during a
  29784. + DMA (except the IRQ status) - so check */
  29785. +static void check_dma_reg_use(struct sdhci_host *host, int reg);
  29786. +#else
  29787. +#define check_dma_reg_use(host, reg)
  29788. +#endif
  29789. +
  29790. +
  29791. +static inline u32 sdhci_bcm2708_raw_readl(struct sdhci_host *host, int reg)
  29792. +{
  29793. + return readl(host->ioaddr + reg);
  29794. +}
  29795. +
  29796. +u32 sdhci_bcm2708_readl(struct sdhci_host *host, int reg)
  29797. +{
  29798. + u32 l = sdhci_bcm2708_raw_readl(host, reg);
  29799. +
  29800. +#ifdef LOG_REGISTERS
  29801. + printk(KERN_ERR "%s: readl from 0x%02x, value 0x%08x\n",
  29802. + mmc_hostname(host->mmc), reg, l);
  29803. +#endif
  29804. + check_dma_reg_use(host, reg);
  29805. +
  29806. + return l;
  29807. +}
  29808. +
  29809. +u16 sdhci_bcm2708_readw(struct sdhci_host *host, int reg)
  29810. +{
  29811. + u32 l = sdhci_bcm2708_raw_readl(host, reg & ~3);
  29812. + u32 w = l >> (reg << 3 & 0x18) & 0xffff;
  29813. +
  29814. +#ifdef LOG_REGISTERS
  29815. + printk(KERN_ERR "%s: readw from 0x%02x, value 0x%04x\n",
  29816. + mmc_hostname(host->mmc), reg, w);
  29817. +#endif
  29818. + check_dma_reg_use(host, reg);
  29819. +
  29820. + return (u16)w;
  29821. +}
  29822. +
  29823. +u8 sdhci_bcm2708_readb(struct sdhci_host *host, int reg)
  29824. +{
  29825. + u32 l = sdhci_bcm2708_raw_readl(host, reg & ~3);
  29826. + u32 b = l >> (reg << 3 & 0x18) & 0xff;
  29827. +
  29828. +#ifdef LOG_REGISTERS
  29829. + printk(KERN_ERR "%s: readb from 0x%02x, value 0x%02x\n",
  29830. + mmc_hostname(host->mmc), reg, b);
  29831. +#endif
  29832. + check_dma_reg_use(host, reg);
  29833. +
  29834. + return (u8)b;
  29835. +}
  29836. +
  29837. +
  29838. +static void sdhci_bcm2708_raw_writel(struct sdhci_host *host, u32 val, int reg)
  29839. +{
  29840. + u32 ier;
  29841. +
  29842. +#if USE_SPACED_WRITES_2CLK
  29843. + static bool timeout_disabled = false;
  29844. + unsigned int ns_2clk = 0;
  29845. +
  29846. + /* The Arasan has a bugette whereby it may lose the content of
  29847. + * successive writes to registers that are within two SD-card clock
  29848. + * cycles of each other (a clock domain crossing problem).
  29849. + * It seems, however, that the data register does not have this problem.
  29850. + * (Which is just as well - otherwise we'd have to nobble the DMA engine
  29851. + * too)
  29852. + */
  29853. + if (reg != SDHCI_BUFFER && host->clock != 0) {
  29854. + /* host->clock is the clock freq in Hz */
  29855. + static hptime_t last_write_hpt;
  29856. + hptime_t now = hptime();
  29857. + ns_2clk = cycle_delay*1000000/(host->clock/1000);
  29858. +
  29859. + if (now == last_write_hpt || now == last_write_hpt+1) {
  29860. + /* we can't guarantee any significant time has
  29861. + * passed - we'll have to wait anyway ! */
  29862. + ndelay(ns_2clk);
  29863. + } else
  29864. + {
  29865. + /* we must have waited at least this many ns: */
  29866. + unsigned int ns_wait = HPTIME_CLK_NS *
  29867. + (last_write_hpt - now - 1);
  29868. + if (ns_wait < ns_2clk)
  29869. + ndelay(ns_2clk - ns_wait);
  29870. + }
  29871. + last_write_hpt = now;
  29872. + }
  29873. +#if USE_SOFTWARE_TIMEOUTS
  29874. + /* The Arasan is clocked for timeouts using the SD clock which is too
  29875. + * fast for ERASE commands and causes issues. So we disable timeouts
  29876. + * for ERASE */
  29877. + if (host->cmd != NULL && host->cmd->opcode == MMC_ERASE &&
  29878. + reg == (SDHCI_COMMAND & ~3)) {
  29879. + mod_timer(&host->timer,
  29880. + jiffies + SOFTWARE_ERASE_TIMEOUT_SEC * HZ);
  29881. + ier = readl(host->ioaddr + SDHCI_SIGNAL_ENABLE);
  29882. + ier &= ~SDHCI_INT_DATA_TIMEOUT;
  29883. + writel(ier, host->ioaddr + SDHCI_SIGNAL_ENABLE);
  29884. + timeout_disabled = true;
  29885. + ndelay(ns_2clk);
  29886. + } else if (timeout_disabled) {
  29887. + ier = readl(host->ioaddr + SDHCI_SIGNAL_ENABLE);
  29888. + ier |= SDHCI_INT_DATA_TIMEOUT;
  29889. + writel(ier, host->ioaddr + SDHCI_SIGNAL_ENABLE);
  29890. + timeout_disabled = false;
  29891. + ndelay(ns_2clk);
  29892. + }
  29893. +#endif
  29894. + writel(val, host->ioaddr + reg);
  29895. +#else
  29896. + void __iomem * regaddr = host->ioaddr + reg;
  29897. +
  29898. + writel(val, regaddr);
  29899. +
  29900. + if (reg != SDHCI_BUFFER && reg != SDHCI_INT_STATUS && host->clock != 0)
  29901. + {
  29902. + int timeout = 100000;
  29903. + while (val != readl(regaddr) && --timeout > 0)
  29904. + continue;
  29905. +
  29906. + if (timeout <= 0)
  29907. + printk(KERN_ERR "%s: writing 0x%X to reg 0x%X "
  29908. + "always gives 0x%X\n",
  29909. + mmc_hostname(host->mmc),
  29910. + val, reg, readl(regaddr));
  29911. + BUG_ON(timeout <= 0);
  29912. + }
  29913. +#endif
  29914. +}
  29915. +
  29916. +
  29917. +void sdhci_bcm2708_writel(struct sdhci_host *host, u32 val, int reg)
  29918. +{
  29919. +#ifdef LOG_REGISTERS
  29920. + printk(KERN_ERR "%s: writel to 0x%02x, value 0x%08x\n",
  29921. + mmc_hostname(host->mmc), reg, val);
  29922. +#endif
  29923. + check_dma_reg_use(host, reg);
  29924. +
  29925. + sdhci_bcm2708_raw_writel(host, val, reg);
  29926. +}
  29927. +
  29928. +void sdhci_bcm2708_writew(struct sdhci_host *host, u16 val, int reg)
  29929. +{
  29930. + static u32 shadow = 0;
  29931. +
  29932. + u32 p = reg == SDHCI_COMMAND ? shadow :
  29933. + sdhci_bcm2708_raw_readl(host, reg & ~3);
  29934. + u32 s = reg << 3 & 0x18;
  29935. + u32 l = val << s;
  29936. + u32 m = 0xffff << s;
  29937. +
  29938. +#ifdef LOG_REGISTERS
  29939. + printk(KERN_ERR "%s: writew to 0x%02x, value 0x%04x\n",
  29940. + mmc_hostname(host->mmc), reg, val);
  29941. +#endif
  29942. +
  29943. + if (reg == SDHCI_TRANSFER_MODE)
  29944. + shadow = (p & ~m) | l;
  29945. + else {
  29946. + check_dma_reg_use(host, reg);
  29947. + sdhci_bcm2708_raw_writel(host, (p & ~m) | l, reg & ~3);
  29948. + }
  29949. +}
  29950. +
  29951. +void sdhci_bcm2708_writeb(struct sdhci_host *host, u8 val, int reg)
  29952. +{
  29953. + u32 p = sdhci_bcm2708_raw_readl(host, reg & ~3);
  29954. + u32 s = reg << 3 & 0x18;
  29955. + u32 l = val << s;
  29956. + u32 m = 0xff << s;
  29957. +
  29958. +#ifdef LOG_REGISTERS
  29959. + printk(KERN_ERR "%s: writeb to 0x%02x, value 0x%02x\n",
  29960. + mmc_hostname(host->mmc), reg, val);
  29961. +#endif
  29962. +
  29963. + check_dma_reg_use(host, reg);
  29964. + sdhci_bcm2708_raw_writel(host, (p & ~m) | l, reg & ~3);
  29965. +}
  29966. +
  29967. +static unsigned int sdhci_bcm2708_get_max_clock(struct sdhci_host *host)
  29968. +{
  29969. + return emmc_clock_freq;
  29970. +}
  29971. +
  29972. +/*****************************************************************************\
  29973. + * *
  29974. + * DMA Operation *
  29975. + * *
  29976. +\*****************************************************************************/
  29977. +
  29978. +struct sdhci_bcm2708_priv {
  29979. + int dma_chan;
  29980. + int dma_irq;
  29981. + void __iomem *dma_chan_base;
  29982. + struct bcm2708_dma_cb *cb_base; /* DMA control blocks */
  29983. + dma_addr_t cb_handle;
  29984. + /* tracking scatter gather progress */
  29985. + unsigned sg_ix; /* scatter gather list index */
  29986. + unsigned sg_done; /* bytes in current sg_ix done */
  29987. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  29988. + unsigned char dma_wanted; /* DMA transfer requested */
  29989. + unsigned char dma_waits; /* wait states in DMAs */
  29990. +#ifdef CHECK_DMA_USE
  29991. + unsigned char dmas_pending; /* no of unfinished DMAs */
  29992. + hptime_t when_started;
  29993. + hptime_t when_reset;
  29994. + hptime_t when_stopped;
  29995. +#endif
  29996. +#endif
  29997. + /* signalling the end of a transfer */
  29998. + void (*complete)(struct sdhci_host *);
  29999. +};
  30000. +
  30001. +#define SDHCI_HOST_PRIV(host) \
  30002. + (struct sdhci_bcm2708_priv *)((struct sdhci_host *)(host)+1)
  30003. +
  30004. +
  30005. +
  30006. +#ifdef CHECK_DMA_REG_USE
  30007. +static void check_dma_reg_use(struct sdhci_host *host, int reg)
  30008. +{
  30009. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  30010. + if (host_priv->dma_wanted && reg != SDHCI_INT_STATUS) {
  30011. + printk(KERN_INFO"%s: accessing register 0x%x during DMA\n",
  30012. + mmc_hostname(host->mmc), reg);
  30013. + }
  30014. +}
  30015. +#endif
  30016. +
  30017. +
  30018. +
  30019. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  30020. +
  30021. +static void sdhci_clear_set_irqgen(struct sdhci_host *host, u32 clear, u32 set)
  30022. +{
  30023. + u32 ier;
  30024. +
  30025. + ier = sdhci_bcm2708_raw_readl(host, SDHCI_SIGNAL_ENABLE);
  30026. + ier &= ~clear;
  30027. + ier |= set;
  30028. + /* change which requests generate IRQs - makes no difference to
  30029. + the content of SDHCI_INT_STATUS, or the need to acknowledge IRQs */
  30030. + sdhci_bcm2708_raw_writel(host, ier, SDHCI_SIGNAL_ENABLE);
  30031. +}
  30032. +
  30033. +static void sdhci_signal_irqs(struct sdhci_host *host, u32 irqs)
  30034. +{
  30035. + sdhci_clear_set_irqgen(host, 0, irqs);
  30036. +}
  30037. +
  30038. +static void sdhci_unsignal_irqs(struct sdhci_host *host, u32 irqs)
  30039. +{
  30040. + sdhci_clear_set_irqgen(host, irqs, 0);
  30041. +}
  30042. +
  30043. +
  30044. +
  30045. +static void schci_bcm2708_cb_read(struct sdhci_bcm2708_priv *host,
  30046. + int ix,
  30047. + dma_addr_t dma_addr, unsigned len,
  30048. + int /*bool*/ is_last)
  30049. +{
  30050. + struct bcm2708_dma_cb *cb = &host->cb_base[ix];
  30051. + unsigned char dmawaits = host->dma_waits;
  30052. +
  30053. + cb->info = BCM2708_DMA_PER_MAP(BCM2708_DMA_DREQ_EMMC) |
  30054. + BCM2708_DMA_WAITS(dmawaits) |
  30055. + BCM2708_DMA_S_DREQ |
  30056. + BCM2708_DMA_D_WIDTH |
  30057. + BCM2708_DMA_D_INC;
  30058. + cb->src = DMA_SDHCI_BUFFER; /* DATA register DMA address */
  30059. + cb->dst = dma_addr;
  30060. + cb->length = len;
  30061. + cb->stride = 0;
  30062. +
  30063. + if (is_last) {
  30064. + cb->info |= BCM2708_DMA_INT_EN |
  30065. + BCM2708_DMA_WAIT_RESP;
  30066. + cb->next = 0;
  30067. + } else
  30068. + cb->next = host->cb_handle +
  30069. + (ix+1)*sizeof(struct bcm2708_dma_cb);
  30070. +
  30071. + cb->pad[0] = 0;
  30072. + cb->pad[1] = 0;
  30073. +}
  30074. +
  30075. +static void schci_bcm2708_cb_write(struct sdhci_bcm2708_priv *host,
  30076. + int ix,
  30077. + dma_addr_t dma_addr, unsigned len,
  30078. + int /*bool*/ is_last)
  30079. +{
  30080. + struct bcm2708_dma_cb *cb = &host->cb_base[ix];
  30081. + unsigned char dmawaits = host->dma_waits;
  30082. +
  30083. + /* We can make arbitrarily large writes as long as we specify DREQ to
  30084. + pace the delivery of bytes to the Arasan hardware */
  30085. + cb->info = BCM2708_DMA_PER_MAP(BCM2708_DMA_DREQ_EMMC) |
  30086. + BCM2708_DMA_WAITS(dmawaits) |
  30087. + BCM2708_DMA_D_DREQ |
  30088. + BCM2708_DMA_S_WIDTH |
  30089. + BCM2708_DMA_S_INC;
  30090. + cb->src = dma_addr;
  30091. + cb->dst = DMA_SDHCI_BUFFER; /* DATA register DMA address */
  30092. + cb->length = len;
  30093. + cb->stride = 0;
  30094. +
  30095. + if (is_last) {
  30096. + cb->info |= BCM2708_DMA_INT_EN |
  30097. + BCM2708_DMA_WAIT_RESP;
  30098. + cb->next = 0;
  30099. + } else
  30100. + cb->next = host->cb_handle +
  30101. + (ix+1)*sizeof(struct bcm2708_dma_cb);
  30102. +
  30103. + cb->pad[0] = 0;
  30104. + cb->pad[1] = 0;
  30105. +}
  30106. +
  30107. +
  30108. +static void schci_bcm2708_dma_go(struct sdhci_host *host)
  30109. +{
  30110. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  30111. + void __iomem *dma_chan_base = host_priv->dma_chan_base;
  30112. +
  30113. + BUG_ON(host_priv->dma_wanted);
  30114. +#ifdef CHECK_DMA_USE
  30115. + if (host_priv->dma_wanted)
  30116. + printk(KERN_ERR "%s: DMA already in progress - "
  30117. + "now %"FMT_HPT", last started %lu "
  30118. + "reset %lu stopped %lu\n",
  30119. + mmc_hostname(host->mmc),
  30120. + hptime(), since_ns(host_priv->when_started),
  30121. + since_ns(host_priv->when_reset),
  30122. + since_ns(host_priv->when_stopped));
  30123. + else if (host_priv->dmas_pending > 0)
  30124. + printk(KERN_INFO "%s: note - new DMA when %d reset DMAs "
  30125. + "already in progress - "
  30126. + "now %"FMT_HPT", started %lu reset %lu stopped %lu\n",
  30127. + mmc_hostname(host->mmc),
  30128. + host_priv->dmas_pending,
  30129. + hptime(), since_ns(host_priv->when_started),
  30130. + since_ns(host_priv->when_reset),
  30131. + since_ns(host_priv->when_stopped));
  30132. + host_priv->dmas_pending += 1;
  30133. + host_priv->when_started = hptime();
  30134. +#endif
  30135. + host_priv->dma_wanted = 1;
  30136. + DBG("PDMA go - base %p handle %08X\n", dma_chan_base,
  30137. + host_priv->cb_handle);
  30138. + bcm_dma_start(dma_chan_base, host_priv->cb_handle);
  30139. +}
  30140. +
  30141. +
  30142. +static void
  30143. +sdhci_platdma_read(struct sdhci_host *host, dma_addr_t dma_addr, size_t len)
  30144. +{
  30145. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  30146. +
  30147. + DBG("PDMA to read %d bytes\n", len);
  30148. + host_priv->sg_done += len;
  30149. + schci_bcm2708_cb_read(host_priv, 0, dma_addr, len, 1/*TRUE*/);
  30150. + schci_bcm2708_dma_go(host);
  30151. +}
  30152. +
  30153. +
  30154. +static void
  30155. +sdhci_platdma_write(struct sdhci_host *host, dma_addr_t dma_addr, size_t len)
  30156. +{
  30157. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  30158. +
  30159. + DBG("PDMA to write %d bytes\n", len);
  30160. + //BUG_ON(0 != (len & 0x1ff));
  30161. +
  30162. + host_priv->sg_done += len;
  30163. + schci_bcm2708_cb_write(host_priv, 0, dma_addr, len, 1/*TRUE*/);
  30164. + schci_bcm2708_dma_go(host);
  30165. +}
  30166. +
  30167. +/*! space is avaiable to receive into or data is available to write
  30168. + Platform DMA exported function
  30169. +*/
  30170. +void
  30171. +sdhci_bcm2708_platdma_avail(struct sdhci_host *host, unsigned int *ref_intmask,
  30172. + void(*completion_callback)(struct sdhci_host *host))
  30173. +{
  30174. + struct mmc_data *data = host->data;
  30175. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  30176. + int sg_ix;
  30177. + size_t bytes;
  30178. + dma_addr_t addr;
  30179. +
  30180. + BUG_ON(NULL == data);
  30181. + BUG_ON(0 == data->blksz);
  30182. +
  30183. + host_priv->complete = completion_callback;
  30184. +
  30185. + sg_ix = host_priv->sg_ix;
  30186. + BUG_ON(sg_ix >= data->sg_len);
  30187. +
  30188. + /* we can DMA blocks larger than blksz - it may hang the DMA
  30189. + channel but we are its only user */
  30190. + bytes = sg_dma_len(&data->sg[sg_ix]) - host_priv->sg_done;
  30191. + addr = sg_dma_address(&data->sg[sg_ix]) + host_priv->sg_done;
  30192. +
  30193. + if (bytes > 0) {
  30194. + /* We're going to poll for read/write available state until
  30195. + we finish this DMA
  30196. + */
  30197. +
  30198. + if (data->flags & MMC_DATA_READ) {
  30199. + if (*ref_intmask & SDHCI_INT_DATA_AVAIL) {
  30200. + sdhci_unsignal_irqs(host, SDHCI_INT_DATA_AVAIL |
  30201. + SDHCI_INT_SPACE_AVAIL);
  30202. + sdhci_platdma_read(host, addr, bytes);
  30203. + }
  30204. + } else {
  30205. + if (*ref_intmask & SDHCI_INT_SPACE_AVAIL) {
  30206. + sdhci_unsignal_irqs(host, SDHCI_INT_DATA_AVAIL |
  30207. + SDHCI_INT_SPACE_AVAIL);
  30208. + sdhci_platdma_write(host, addr, bytes);
  30209. + }
  30210. + }
  30211. + }
  30212. + /* else:
  30213. + we have run out of bytes that need transferring (e.g. we may be in
  30214. + the middle of the last DMA transfer), or
  30215. + it is also possible that we've been called when another IRQ is
  30216. + signalled, even though we've turned off signalling of our own IRQ */
  30217. +
  30218. + *ref_intmask &= ~SDHCI_INT_DATA_END;
  30219. + /* don't let the main sdhci driver act on this .. we'll deal with it
  30220. + when we respond to the DMA - if one is currently in progress */
  30221. +}
  30222. +
  30223. +/* is it possible to DMA the given mmc_data structure?
  30224. + Platform DMA exported function
  30225. +*/
  30226. +int /*bool*/
  30227. +sdhci_bcm2708_platdma_dmaable(struct sdhci_host *host, struct mmc_data *data)
  30228. +{
  30229. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  30230. + int ok = bcm_sg_suitable_for_dma(data->sg, data->sg_len);
  30231. +
  30232. + if (!ok)
  30233. + DBG("Reverting to PIO - bad cache alignment\n");
  30234. +
  30235. + else {
  30236. + host_priv->sg_ix = 0; /* first SG index */
  30237. + host_priv->sg_done = 0; /* no bytes done */
  30238. + }
  30239. +
  30240. + return ok;
  30241. +}
  30242. +
  30243. +#include <mach/arm_control.h> //GRAYG
  30244. +/*! the current SD transacton has been abandonned
  30245. + We need to tidy up if we were in the middle of a DMA
  30246. + Platform DMA exported function
  30247. +*/
  30248. +void
  30249. +sdhci_bcm2708_platdma_reset(struct sdhci_host *host, struct mmc_data *data)
  30250. +{
  30251. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  30252. +// unsigned long flags;
  30253. +
  30254. + BUG_ON(NULL == host);
  30255. +
  30256. +// spin_lock_irqsave(&host->lock, flags);
  30257. +
  30258. + if (host_priv->dma_wanted) {
  30259. + if (NULL == data) {
  30260. + printk(KERN_ERR "%s: ongoing DMA reset - no data!\n",
  30261. + mmc_hostname(host->mmc));
  30262. + BUG_ON(NULL == data);
  30263. + } else {
  30264. + struct scatterlist *sg;
  30265. + int sg_len;
  30266. + int sg_todo;
  30267. + int rc;
  30268. + unsigned long cs;
  30269. +
  30270. + sg = data->sg;
  30271. + sg_len = data->sg_len;
  30272. + sg_todo = sg_dma_len(&sg[host_priv->sg_ix]);
  30273. +
  30274. + cs = readl(host_priv->dma_chan_base + BCM2708_DMA_CS);
  30275. +
  30276. + if (!(BCM2708_DMA_ACTIVE & cs))
  30277. + {
  30278. + if (extra_messages)
  30279. + printk(KERN_INFO "%s: missed completion of "
  30280. + "cmd %d DMA (%d/%d [%d]/[%d]) - "
  30281. + "ignoring it\n",
  30282. + mmc_hostname(host->mmc),
  30283. + host->last_cmdop,
  30284. + host_priv->sg_done, sg_todo,
  30285. + host_priv->sg_ix+1, sg_len);
  30286. + }
  30287. + else
  30288. + printk(KERN_INFO "%s: resetting ongoing cmd %d"
  30289. + "DMA before %d/%d [%d]/[%d] complete\n",
  30290. + mmc_hostname(host->mmc),
  30291. + host->last_cmdop,
  30292. + host_priv->sg_done, sg_todo,
  30293. + host_priv->sg_ix+1, sg_len);
  30294. +#ifdef CHECK_DMA_USE
  30295. + printk(KERN_INFO "%s: now %"FMT_HPT" started %lu "
  30296. + "last reset %lu last stopped %lu\n",
  30297. + mmc_hostname(host->mmc),
  30298. + hptime(), since_ns(host_priv->when_started),
  30299. + since_ns(host_priv->when_reset),
  30300. + since_ns(host_priv->when_stopped));
  30301. + { unsigned long info, debug;
  30302. + void __iomem *base;
  30303. + unsigned long pend0, pend1, pend2;
  30304. +
  30305. + base = host_priv->dma_chan_base;
  30306. + cs = readl(base + BCM2708_DMA_CS);
  30307. + info = readl(base + BCM2708_DMA_INFO);
  30308. + debug = readl(base + BCM2708_DMA_DEBUG);
  30309. + printk(KERN_INFO "%s: DMA%d CS=%08lX TI=%08lX "
  30310. + "DEBUG=%08lX\n",
  30311. + mmc_hostname(host->mmc),
  30312. + host_priv->dma_chan,
  30313. + cs, info, debug);
  30314. + pend0 = readl(__io_address(ARM_IRQ_PEND0));
  30315. + pend1 = readl(__io_address(ARM_IRQ_PEND1));
  30316. + pend2 = readl(__io_address(ARM_IRQ_PEND2));
  30317. +
  30318. + printk(KERN_INFO "%s: PEND0=%08lX "
  30319. + "PEND1=%08lX PEND2=%08lX\n",
  30320. + mmc_hostname(host->mmc),
  30321. + pend0, pend1, pend2);
  30322. +
  30323. + //gintsts = readl(__io_address(GINTSTS));
  30324. + //gintmsk = readl(__io_address(GINTMSK));
  30325. + //printk(KERN_INFO "%s: USB GINTSTS=%08lX"
  30326. + // "GINTMSK=%08lX\n",
  30327. + // mmc_hostname(host->mmc), gintsts, gintmsk);
  30328. + }
  30329. +#endif
  30330. + rc = bcm_dma_abort(host_priv->dma_chan_base);
  30331. + BUG_ON(rc != 0);
  30332. + }
  30333. + host_priv->dma_wanted = 0;
  30334. +#ifdef CHECK_DMA_USE
  30335. + host_priv->when_reset = hptime();
  30336. +#endif
  30337. + }
  30338. +
  30339. +// spin_unlock_irqrestore(&host->lock, flags);
  30340. +}
  30341. +
  30342. +
  30343. +static void sdhci_bcm2708_dma_complete_irq(struct sdhci_host *host,
  30344. + u32 dma_cs)
  30345. +{
  30346. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  30347. + struct mmc_data *data;
  30348. + struct scatterlist *sg;
  30349. + int sg_len;
  30350. + int sg_ix;
  30351. + int sg_todo;
  30352. +// unsigned long flags;
  30353. +
  30354. + BUG_ON(NULL == host);
  30355. +
  30356. +// spin_lock_irqsave(&host->lock, flags);
  30357. + data = host->data;
  30358. +
  30359. +#ifdef CHECK_DMA_USE
  30360. + if (host_priv->dmas_pending <= 0)
  30361. + DBG("on completion no DMA in progress - "
  30362. + "now %"FMT_HPT" started %lu reset %lu stopped %lu\n",
  30363. + hptime(), since_ns(host_priv->when_started),
  30364. + since_ns(host_priv->when_reset),
  30365. + since_ns(host_priv->when_stopped));
  30366. + else if (host_priv->dmas_pending > 1)
  30367. + DBG("still %d DMA in progress after completion - "
  30368. + "now %"FMT_HPT" started %lu reset %lu stopped %lu\n",
  30369. + host_priv->dmas_pending - 1,
  30370. + hptime(), since_ns(host_priv->when_started),
  30371. + since_ns(host_priv->when_reset),
  30372. + since_ns(host_priv->when_stopped));
  30373. + BUG_ON(host_priv->dmas_pending <= 0);
  30374. + host_priv->dmas_pending -= 1;
  30375. + host_priv->when_stopped = hptime();
  30376. +#endif
  30377. + host_priv->dma_wanted = 0;
  30378. +
  30379. + if (NULL == data) {
  30380. + DBG("PDMA unused completion - status 0x%X\n", dma_cs);
  30381. +// spin_unlock_irqrestore(&host->lock, flags);
  30382. + return;
  30383. + }
  30384. + sg = data->sg;
  30385. + sg_len = data->sg_len;
  30386. + sg_todo = sg_dma_len(&sg[host_priv->sg_ix]);
  30387. +
  30388. + DBG("PDMA complete %d/%d [%d]/[%d]..\n",
  30389. + host_priv->sg_done, sg_todo,
  30390. + host_priv->sg_ix+1, sg_len);
  30391. +
  30392. + BUG_ON(host_priv->sg_done > sg_todo);
  30393. +
  30394. + if (host_priv->sg_done >= sg_todo) {
  30395. + host_priv->sg_ix++;
  30396. + host_priv->sg_done = 0;
  30397. + }
  30398. +
  30399. + sg_ix = host_priv->sg_ix;
  30400. + if (sg_ix < sg_len) {
  30401. + u32 irq_mask;
  30402. + /* Set off next DMA if we've got the capacity */
  30403. +
  30404. + if (data->flags & MMC_DATA_READ)
  30405. + irq_mask = SDHCI_INT_DATA_AVAIL;
  30406. + else
  30407. + irq_mask = SDHCI_INT_SPACE_AVAIL;
  30408. +
  30409. + /* We have to use the interrupt status register on the BCM2708
  30410. + rather than the SDHCI_PRESENT_STATE register because latency
  30411. + in the glue logic means that the information retrieved from
  30412. + the latter is not always up-to-date w.r.t the DMA engine -
  30413. + it may not indicate that a read or a write is ready yet */
  30414. + if (sdhci_bcm2708_raw_readl(host, SDHCI_INT_STATUS) &
  30415. + irq_mask) {
  30416. + size_t bytes = sg_dma_len(&sg[sg_ix]) -
  30417. + host_priv->sg_done;
  30418. + dma_addr_t addr = sg_dma_address(&data->sg[sg_ix]) +
  30419. + host_priv->sg_done;
  30420. +
  30421. + /* acknowledge interrupt */
  30422. + sdhci_bcm2708_raw_writel(host, irq_mask,
  30423. + SDHCI_INT_STATUS);
  30424. +
  30425. + BUG_ON(0 == bytes);
  30426. +
  30427. + if (data->flags & MMC_DATA_READ)
  30428. + sdhci_platdma_read(host, addr, bytes);
  30429. + else
  30430. + sdhci_platdma_write(host, addr, bytes);
  30431. + } else {
  30432. + DBG("PDMA - wait avail\n");
  30433. + /* may generate an IRQ if already present */
  30434. + sdhci_signal_irqs(host, SDHCI_INT_DATA_AVAIL |
  30435. + SDHCI_INT_SPACE_AVAIL);
  30436. + }
  30437. + } else {
  30438. + if (sync_after_dma) {
  30439. + /* On the Arasan controller the stop command (which will be
  30440. + scheduled after this completes) does not seem to work
  30441. + properly if we allow it to be issued when we are
  30442. + transferring data to/from the SD card.
  30443. + We get CRC and DEND errors unless we wait for
  30444. + the SD controller to finish reading/writing to the card. */
  30445. + u32 state_mask;
  30446. + int timeout=3*1000*1000;
  30447. +
  30448. + DBG("PDMA over - sync card\n");
  30449. + if (data->flags & MMC_DATA_READ)
  30450. + state_mask = SDHCI_DOING_READ;
  30451. + else
  30452. + state_mask = SDHCI_DOING_WRITE;
  30453. +
  30454. + while (0 != (sdhci_bcm2708_raw_readl(host, SDHCI_PRESENT_STATE)
  30455. + & state_mask) && --timeout > 0)
  30456. + {
  30457. + udelay(1);
  30458. + continue;
  30459. + }
  30460. + if (timeout <= 0)
  30461. + printk(KERN_ERR"%s: final %s to SD card still "
  30462. + "running\n",
  30463. + mmc_hostname(host->mmc),
  30464. + data->flags & MMC_DATA_READ? "read": "write");
  30465. + }
  30466. + if (host_priv->complete) {
  30467. + (*host_priv->complete)(host);
  30468. + DBG("PDMA %s complete\n",
  30469. + data->flags & MMC_DATA_READ?"read":"write");
  30470. + sdhci_signal_irqs(host, SDHCI_INT_DATA_AVAIL |
  30471. + SDHCI_INT_SPACE_AVAIL);
  30472. + }
  30473. + }
  30474. +// spin_unlock_irqrestore(&host->lock, flags);
  30475. +}
  30476. +
  30477. +static irqreturn_t sdhci_bcm2708_dma_irq(int irq, void *dev_id)
  30478. +{
  30479. + irqreturn_t result = IRQ_NONE;
  30480. + struct sdhci_host *host = dev_id;
  30481. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  30482. + u32 dma_cs; /* control and status register */
  30483. +
  30484. + BUG_ON(NULL == dev_id);
  30485. + BUG_ON(NULL == host_priv->dma_chan_base);
  30486. +
  30487. + sdhci_spin_lock(host);
  30488. +
  30489. + dma_cs = readl(host_priv->dma_chan_base + BCM2708_DMA_CS);
  30490. +
  30491. + if (dma_cs & BCM2708_DMA_ERR) {
  30492. + unsigned long debug;
  30493. + debug = readl(host_priv->dma_chan_base +
  30494. + BCM2708_DMA_DEBUG);
  30495. + printk(KERN_ERR "%s: DMA error - CS %lX DEBUG %lX\n",
  30496. + mmc_hostname(host->mmc), (unsigned long)dma_cs,
  30497. + (unsigned long)debug);
  30498. + /* reset error */
  30499. + writel(debug, host_priv->dma_chan_base +
  30500. + BCM2708_DMA_DEBUG);
  30501. + }
  30502. + if (dma_cs & BCM2708_DMA_INT) {
  30503. + /* acknowledge interrupt */
  30504. + writel(BCM2708_DMA_INT,
  30505. + host_priv->dma_chan_base + BCM2708_DMA_CS);
  30506. +
  30507. + dsb(); /* ARM data synchronization (push) operation */
  30508. +
  30509. + if (!host_priv->dma_wanted) {
  30510. + /* ignore this interrupt - it was reset */
  30511. + if (extra_messages)
  30512. + printk(KERN_INFO "%s: DMA IRQ %X ignored - "
  30513. + "results were reset\n",
  30514. + mmc_hostname(host->mmc), dma_cs);
  30515. +#ifdef CHECK_DMA_USE
  30516. + printk(KERN_INFO "%s: now %"FMT_HPT
  30517. + " started %lu reset %lu stopped %lu\n",
  30518. + mmc_hostname(host->mmc), hptime(),
  30519. + since_ns(host_priv->when_started),
  30520. + since_ns(host_priv->when_reset),
  30521. + since_ns(host_priv->when_stopped));
  30522. + host_priv->dmas_pending--;
  30523. +#endif
  30524. + } else
  30525. + sdhci_bcm2708_dma_complete_irq(host, dma_cs);
  30526. +
  30527. + result = IRQ_HANDLED;
  30528. + }
  30529. + sdhci_spin_unlock(host);
  30530. +
  30531. + return result;
  30532. +}
  30533. +#endif /* CONFIG_MMC_SDHCI_BCM2708_DMA */
  30534. +
  30535. +
  30536. +/***************************************************************************** \
  30537. + * *
  30538. + * Device Attributes *
  30539. + * *
  30540. +\*****************************************************************************/
  30541. +
  30542. +
  30543. +/**
  30544. + * Show the DMA-using status
  30545. + */
  30546. +static ssize_t attr_dma_show(struct device *_dev,
  30547. + struct device_attribute *attr, char *buf)
  30548. +{
  30549. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  30550. +
  30551. + if (host) {
  30552. + int use_dma = (host->flags & SDHCI_USE_PLATDMA? 1:0);
  30553. + return sprintf(buf, "%d\n", use_dma);
  30554. + } else
  30555. + return -EINVAL;
  30556. +}
  30557. +
  30558. +/**
  30559. + * Set the DMA-using status
  30560. + */
  30561. +static ssize_t attr_dma_store(struct device *_dev,
  30562. + struct device_attribute *attr,
  30563. + const char *buf, size_t count)
  30564. +{
  30565. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  30566. +
  30567. + if (host) {
  30568. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  30569. + int on = simple_strtol(buf, NULL, 0);
  30570. + if (on) {
  30571. + host->flags |= SDHCI_USE_PLATDMA;
  30572. + sdhci_bcm2708_writel(host, 1, REG_EXRDFIFO_EN);
  30573. + printk(KERN_INFO "%s: DMA enabled\n",
  30574. + mmc_hostname(host->mmc));
  30575. + } else {
  30576. + host->flags &= ~(SDHCI_USE_PLATDMA | SDHCI_REQ_USE_DMA);
  30577. + sdhci_bcm2708_writel(host, 0, REG_EXRDFIFO_EN);
  30578. + printk(KERN_INFO "%s: DMA disabled\n",
  30579. + mmc_hostname(host->mmc));
  30580. + }
  30581. +#endif
  30582. + return count;
  30583. + } else
  30584. + return -EINVAL;
  30585. +}
  30586. +
  30587. +static DEVICE_ATTR(use_dma, S_IRUGO | S_IWUGO, attr_dma_show, attr_dma_store);
  30588. +
  30589. +
  30590. +/**
  30591. + * Show the DMA wait states used
  30592. + */
  30593. +static ssize_t attr_dmawait_show(struct device *_dev,
  30594. + struct device_attribute *attr, char *buf)
  30595. +{
  30596. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  30597. +
  30598. + if (host) {
  30599. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  30600. + int dmawait = host_priv->dma_waits;
  30601. + return sprintf(buf, "%d\n", dmawait);
  30602. + } else
  30603. + return -EINVAL;
  30604. +}
  30605. +
  30606. +/**
  30607. + * Set the DMA wait state used
  30608. + */
  30609. +static ssize_t attr_dmawait_store(struct device *_dev,
  30610. + struct device_attribute *attr,
  30611. + const char *buf, size_t count)
  30612. +{
  30613. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  30614. +
  30615. + if (host) {
  30616. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  30617. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  30618. + int dma_waits = simple_strtol(buf, NULL, 0);
  30619. + if (dma_waits >= 0 && dma_waits < 32)
  30620. + host_priv->dma_waits = dma_waits;
  30621. + else
  30622. + printk(KERN_ERR "%s: illegal dma_waits value - %d",
  30623. + mmc_hostname(host->mmc), dma_waits);
  30624. +#endif
  30625. + return count;
  30626. + } else
  30627. + return -EINVAL;
  30628. +}
  30629. +
  30630. +static DEVICE_ATTR(dma_wait, S_IRUGO | S_IWUGO,
  30631. + attr_dmawait_show, attr_dmawait_store);
  30632. +
  30633. +
  30634. +/**
  30635. + * Show the DMA-using status
  30636. + */
  30637. +static ssize_t attr_status_show(struct device *_dev,
  30638. + struct device_attribute *attr, char *buf)
  30639. +{
  30640. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  30641. +
  30642. + if (host) {
  30643. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  30644. + return sprintf(buf,
  30645. + "present: yes\n"
  30646. + "power: %s\n"
  30647. + "clock: %u Hz\n"
  30648. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  30649. + "dma: %s (%d waits)\n",
  30650. +#else
  30651. + "dma: unconfigured\n",
  30652. +#endif
  30653. + "always on",
  30654. + host->clock
  30655. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  30656. + , (host->flags & SDHCI_USE_PLATDMA)? "on": "off"
  30657. + , host_priv->dma_waits
  30658. +#endif
  30659. + );
  30660. + } else
  30661. + return -EINVAL;
  30662. +}
  30663. +
  30664. +static DEVICE_ATTR(status, S_IRUGO, attr_status_show, NULL);
  30665. +
  30666. +/***************************************************************************** \
  30667. + * *
  30668. + * Power Management *
  30669. + * *
  30670. +\*****************************************************************************/
  30671. +
  30672. +
  30673. +#ifdef CONFIG_PM
  30674. +static int sdhci_bcm2708_suspend(struct platform_device *dev, pm_message_t state)
  30675. +{
  30676. + struct sdhci_host *host = (struct sdhci_host *)
  30677. + platform_get_drvdata(dev);
  30678. + int ret = 0;
  30679. +
  30680. + if (host->mmc) {
  30681. + //ret = mmc_suspend_host(host->mmc);
  30682. + }
  30683. +
  30684. + return ret;
  30685. +}
  30686. +
  30687. +static int sdhci_bcm2708_resume(struct platform_device *dev)
  30688. +{
  30689. + struct sdhci_host *host = (struct sdhci_host *)
  30690. + platform_get_drvdata(dev);
  30691. + int ret = 0;
  30692. +
  30693. + if (host->mmc) {
  30694. + //ret = mmc_resume_host(host->mmc);
  30695. + }
  30696. +
  30697. + return ret;
  30698. +}
  30699. +#endif
  30700. +
  30701. +
  30702. +/*****************************************************************************\
  30703. + * *
  30704. + * Device quirk functions. Implemented as local ops because the flags *
  30705. + * field is out of space with newer kernels. This implementation can be *
  30706. + * back ported to older kernels as well. *
  30707. +\****************************************************************************/
  30708. +static unsigned int sdhci_bcm2708_quirk_extra_ints(struct sdhci_host *host)
  30709. +{
  30710. + return 1;
  30711. +}
  30712. +
  30713. +static unsigned int sdhci_bcm2708_quirk_spurious_crc_acmd51(struct sdhci_host *host)
  30714. +{
  30715. + return 1;
  30716. +}
  30717. +
  30718. +static unsigned int sdhci_bcm2708_missing_status(struct sdhci_host *host)
  30719. +{
  30720. + return 1;
  30721. +}
  30722. +
  30723. +/***************************************************************************** \
  30724. + * *
  30725. + * Device ops *
  30726. + * *
  30727. +\*****************************************************************************/
  30728. +
  30729. +static struct sdhci_ops sdhci_bcm2708_ops = {
  30730. +#ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS
  30731. + .read_l = sdhci_bcm2708_readl,
  30732. + .read_w = sdhci_bcm2708_readw,
  30733. + .read_b = sdhci_bcm2708_readb,
  30734. + .write_l = sdhci_bcm2708_writel,
  30735. + .write_w = sdhci_bcm2708_writew,
  30736. + .write_b = sdhci_bcm2708_writeb,
  30737. +#else
  30738. +#error The BCM2708 SDHCI driver needs CONFIG_MMC_SDHCI_IO_ACCESSORS to be set
  30739. +#endif
  30740. + .get_max_clock = sdhci_bcm2708_get_max_clock,
  30741. +
  30742. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  30743. + // Platform DMA operations
  30744. + .pdma_able = sdhci_bcm2708_platdma_dmaable,
  30745. + .pdma_avail = sdhci_bcm2708_platdma_avail,
  30746. + .pdma_reset = sdhci_bcm2708_platdma_reset,
  30747. +#endif
  30748. + .extra_ints = sdhci_bcm2708_quirk_extra_ints,
  30749. +};
  30750. +
  30751. +/*****************************************************************************\
  30752. + * *
  30753. + * Device probing/removal *
  30754. + * *
  30755. +\*****************************************************************************/
  30756. +
  30757. +static int sdhci_bcm2708_probe(struct platform_device *pdev)
  30758. +{
  30759. + struct sdhci_host *host;
  30760. + struct resource *iomem;
  30761. + struct sdhci_bcm2708_priv *host_priv;
  30762. + int ret;
  30763. +
  30764. + BUG_ON(pdev == NULL);
  30765. +
  30766. + iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  30767. + if (!iomem) {
  30768. + ret = -ENOMEM;
  30769. + goto err;
  30770. + }
  30771. +
  30772. + if (resource_size(iomem) != 0x100)
  30773. + dev_err(&pdev->dev, "Invalid iomem size. You may "
  30774. + "experience problems.\n");
  30775. +
  30776. + if (pdev->dev.parent)
  30777. + host = sdhci_alloc_host(pdev->dev.parent,
  30778. + sizeof(struct sdhci_bcm2708_priv));
  30779. + else
  30780. + host = sdhci_alloc_host(&pdev->dev,
  30781. + sizeof(struct sdhci_bcm2708_priv));
  30782. +
  30783. + if (IS_ERR(host)) {
  30784. + ret = PTR_ERR(host);
  30785. + goto err;
  30786. + }
  30787. + if (missing_status) {
  30788. + sdhci_bcm2708_ops.missing_status = sdhci_bcm2708_missing_status;
  30789. + }
  30790. +
  30791. + if( spurious_crc_acmd51 ) {
  30792. + sdhci_bcm2708_ops.spurious_crc_acmd51 = sdhci_bcm2708_quirk_spurious_crc_acmd51;
  30793. + }
  30794. +
  30795. +
  30796. + printk("sdhci: %s low-latency mode\n",enable_llm?"Enable":"Disable");
  30797. +
  30798. + host->hw_name = "BCM2708_Arasan";
  30799. + host->ops = &sdhci_bcm2708_ops;
  30800. + host->irq = platform_get_irq(pdev, 0);
  30801. + host->second_irq = 0;
  30802. +
  30803. + host->quirks = SDHCI_QUIRK_BROKEN_CARD_DETECTION |
  30804. + SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK |
  30805. + SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
  30806. + SDHCI_QUIRK_MISSING_CAPS |
  30807. + SDHCI_QUIRK_NO_HISPD_BIT |
  30808. + (sync_after_dma ? 0:SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12);
  30809. +
  30810. +
  30811. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  30812. + host->flags = SDHCI_USE_PLATDMA;
  30813. +#endif
  30814. +
  30815. + if (!request_mem_region(iomem->start, resource_size(iomem),
  30816. + mmc_hostname(host->mmc))) {
  30817. + dev_err(&pdev->dev, "cannot request region\n");
  30818. + ret = -EBUSY;
  30819. + goto err_request;
  30820. + }
  30821. +
  30822. + host->ioaddr = ioremap(iomem->start, resource_size(iomem));
  30823. + if (!host->ioaddr) {
  30824. + dev_err(&pdev->dev, "failed to remap registers\n");
  30825. + ret = -ENOMEM;
  30826. + goto err_remap;
  30827. + }
  30828. +
  30829. + host_priv = SDHCI_HOST_PRIV(host);
  30830. +
  30831. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  30832. + host_priv->dma_wanted = 0;
  30833. +#ifdef CHECK_DMA_USE
  30834. + host_priv->dmas_pending = 0;
  30835. + host_priv->when_started = 0;
  30836. + host_priv->when_reset = 0;
  30837. + host_priv->when_stopped = 0;
  30838. +#endif
  30839. + host_priv->sg_ix = 0;
  30840. + host_priv->sg_done = 0;
  30841. + host_priv->complete = NULL;
  30842. + host_priv->dma_waits = SDHCI_BCM_DMA_WAITS;
  30843. +
  30844. + host_priv->cb_base = dma_alloc_writecombine(&pdev->dev, SZ_4K,
  30845. + &host_priv->cb_handle,
  30846. + GFP_KERNEL);
  30847. + if (!host_priv->cb_base) {
  30848. + dev_err(&pdev->dev, "cannot allocate DMA CBs\n");
  30849. + ret = -ENOMEM;
  30850. + goto err_alloc_cb;
  30851. + }
  30852. +
  30853. + ret = bcm_dma_chan_alloc(BCM_DMA_FEATURE_FAST,
  30854. + &host_priv->dma_chan_base,
  30855. + &host_priv->dma_irq);
  30856. + if (ret < 0) {
  30857. + dev_err(&pdev->dev, "couldn't allocate a DMA channel\n");
  30858. + goto err_add_dma;
  30859. + }
  30860. + host_priv->dma_chan = ret;
  30861. +
  30862. + ret = request_irq(host_priv->dma_irq, sdhci_bcm2708_dma_irq,
  30863. + 0 /*IRQF_SHARED*/, DRIVER_NAME " (dma)", host);
  30864. + if (ret) {
  30865. + dev_err(&pdev->dev, "cannot set DMA IRQ\n");
  30866. + goto err_add_dma_irq;
  30867. + }
  30868. + host->second_irq = host_priv->dma_irq;
  30869. + DBG("DMA CBs %p handle %08X DMA%d %p DMA IRQ %d\n",
  30870. + host_priv->cb_base, (unsigned)host_priv->cb_handle,
  30871. + host_priv->dma_chan, host_priv->dma_chan_base,
  30872. + host_priv->dma_irq);
  30873. +
  30874. + // we support 3.3V
  30875. + host->caps |= SDHCI_CAN_VDD_330;
  30876. + if (allow_highspeed)
  30877. + host->mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED;
  30878. +
  30879. + /* single block writes cause data loss with some SD cards! */
  30880. + host->mmc->caps2 |= MMC_CAP2_FORCE_MULTIBLOCK;
  30881. +#endif
  30882. +
  30883. + ret = sdhci_add_host(host);
  30884. + if (ret)
  30885. + goto err_add_host;
  30886. +
  30887. + platform_set_drvdata(pdev, host);
  30888. + ret = device_create_file(&pdev->dev, &dev_attr_use_dma);
  30889. + ret = device_create_file(&pdev->dev, &dev_attr_dma_wait);
  30890. + ret = device_create_file(&pdev->dev, &dev_attr_status);
  30891. +
  30892. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  30893. + /* enable extension fifo for paced DMA transfers */
  30894. + sdhci_bcm2708_writel(host, 1, REG_EXRDFIFO_EN);
  30895. + sdhci_bcm2708_writel(host, 4, REG_EXRDFIFO_CFG);
  30896. +#endif
  30897. +
  30898. + printk(KERN_INFO "%s: BCM2708 SDHC host at 0x%08llx DMA %d IRQ %d\n",
  30899. + mmc_hostname(host->mmc), (unsigned long long)iomem->start,
  30900. + host_priv->dma_chan, host_priv->dma_irq);
  30901. +
  30902. + return 0;
  30903. +
  30904. +err_add_host:
  30905. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  30906. + free_irq(host_priv->dma_irq, host);
  30907. +err_add_dma_irq:
  30908. + bcm_dma_chan_free(host_priv->dma_chan);
  30909. +err_add_dma:
  30910. + dma_free_writecombine(&pdev->dev, SZ_4K, host_priv->cb_base,
  30911. + host_priv->cb_handle);
  30912. +err_alloc_cb:
  30913. +#endif
  30914. + iounmap(host->ioaddr);
  30915. +err_remap:
  30916. + release_mem_region(iomem->start, resource_size(iomem));
  30917. +err_request:
  30918. + sdhci_free_host(host);
  30919. +err:
  30920. + dev_err(&pdev->dev, "probe failed, err %d\n", ret);
  30921. + return ret;
  30922. +}
  30923. +
  30924. +static int sdhci_bcm2708_remove(struct platform_device *pdev)
  30925. +{
  30926. + struct sdhci_host *host = platform_get_drvdata(pdev);
  30927. + struct resource *iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  30928. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  30929. + int dead;
  30930. + u32 scratch;
  30931. +
  30932. + dead = 0;
  30933. + scratch = sdhci_bcm2708_readl(host, SDHCI_INT_STATUS);
  30934. + if (scratch == (u32)-1)
  30935. + dead = 1;
  30936. +
  30937. + device_remove_file(&pdev->dev, &dev_attr_status);
  30938. + device_remove_file(&pdev->dev, &dev_attr_dma_wait);
  30939. + device_remove_file(&pdev->dev, &dev_attr_use_dma);
  30940. +
  30941. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  30942. + free_irq(host_priv->dma_irq, host);
  30943. + dma_free_writecombine(&pdev->dev, SZ_4K, host_priv->cb_base,
  30944. + host_priv->cb_handle);
  30945. +#endif
  30946. + sdhci_remove_host(host, dead);
  30947. + iounmap(host->ioaddr);
  30948. + release_mem_region(iomem->start, resource_size(iomem));
  30949. + sdhci_free_host(host);
  30950. + platform_set_drvdata(pdev, NULL);
  30951. +
  30952. + return 0;
  30953. +}
  30954. +
  30955. +static struct platform_driver sdhci_bcm2708_driver = {
  30956. + .driver = {
  30957. + .name = DRIVER_NAME,
  30958. + .owner = THIS_MODULE,
  30959. + },
  30960. + .probe = sdhci_bcm2708_probe,
  30961. + .remove = sdhci_bcm2708_remove,
  30962. +
  30963. +#ifdef CONFIG_PM
  30964. + .suspend = sdhci_bcm2708_suspend,
  30965. + .resume = sdhci_bcm2708_resume,
  30966. +#endif
  30967. +
  30968. +};
  30969. +
  30970. +/*****************************************************************************\
  30971. + * *
  30972. + * Driver init/exit *
  30973. + * *
  30974. +\*****************************************************************************/
  30975. +
  30976. +static int __init sdhci_drv_init(void)
  30977. +{
  30978. + return platform_driver_register(&sdhci_bcm2708_driver);
  30979. +}
  30980. +
  30981. +static void __exit sdhci_drv_exit(void)
  30982. +{
  30983. + platform_driver_unregister(&sdhci_bcm2708_driver);
  30984. +}
  30985. +
  30986. +module_init(sdhci_drv_init);
  30987. +module_exit(sdhci_drv_exit);
  30988. +
  30989. +module_param(allow_highspeed, bool, 0444);
  30990. +module_param(emmc_clock_freq, int, 0444);
  30991. +module_param(sync_after_dma, bool, 0444);
  30992. +module_param(missing_status, bool, 0444);
  30993. +module_param(spurious_crc_acmd51, bool, 0444);
  30994. +module_param(enable_llm, bool, 0444);
  30995. +module_param(cycle_delay, int, 0444);
  30996. +module_param(extra_messages, bool, 0444);
  30997. +
  30998. +MODULE_DESCRIPTION("Secure Digital Host Controller Interface platform driver");
  30999. +MODULE_AUTHOR("Broadcom <info@broadcom.com>");
  31000. +MODULE_LICENSE("GPL v2");
  31001. +MODULE_ALIAS("platform:"DRIVER_NAME);
  31002. +
  31003. +MODULE_PARM_DESC(allow_highspeed, "Allow high speed transfers modes");
  31004. +MODULE_PARM_DESC(emmc_clock_freq, "Specify the speed of emmc clock");
  31005. +MODULE_PARM_DESC(sync_after_dma, "Block in driver until dma complete");
  31006. +MODULE_PARM_DESC(missing_status, "Use the missing status quirk");
  31007. +MODULE_PARM_DESC(spurious_crc_acmd51, "Use the spurious crc quirk for reading SCR (ACMD51)");
  31008. +MODULE_PARM_DESC(enable_llm, "Enable low-latency mode");
  31009. +MODULE_PARM_DESC(extra_messages, "Enable more sdcard warning messages");
  31010. +
  31011. +
  31012. diff -Nur linux-3.13.3.orig/drivers/mmc/host/sdhci.c linux-3.13.3/drivers/mmc/host/sdhci.c
  31013. --- linux-3.13.3.orig/drivers/mmc/host/sdhci.c 2014-02-13 23:00:14.000000000 +0100
  31014. +++ linux-3.13.3/drivers/mmc/host/sdhci.c 2014-02-17 22:41:01.000000000 +0100
  31015. @@ -28,6 +28,7 @@
  31016. #include <linux/mmc/mmc.h>
  31017. #include <linux/mmc/host.h>
  31018. #include <linux/mmc/card.h>
  31019. +#include <linux/mmc/sd.h>
  31020. #include <linux/mmc/slot-gpio.h>
  31021. #include "sdhci.h"
  31022. @@ -130,6 +131,99 @@
  31023. * Low level functions *
  31024. * *
  31025. \*****************************************************************************/
  31026. +extern bool enable_llm;
  31027. +static int sdhci_locked=0;
  31028. +void sdhci_spin_lock(struct sdhci_host *host)
  31029. +{
  31030. + spin_lock(&host->lock);
  31031. +#ifdef CONFIG_PREEMPT
  31032. + if(enable_llm)
  31033. + {
  31034. + disable_irq_nosync(host->irq);
  31035. + if(host->second_irq)
  31036. + disable_irq_nosync(host->second_irq);
  31037. + local_irq_enable();
  31038. + }
  31039. +#endif
  31040. +}
  31041. +
  31042. +void sdhci_spin_unlock(struct sdhci_host *host)
  31043. +{
  31044. +#ifdef CONFIG_PREEMPT
  31045. + if(enable_llm)
  31046. + {
  31047. + local_irq_disable();
  31048. + if(host->second_irq)
  31049. + enable_irq(host->second_irq);
  31050. + enable_irq(host->irq);
  31051. + }
  31052. +#endif
  31053. + spin_unlock(&host->lock);
  31054. +}
  31055. +
  31056. +void sdhci_spin_lock_irqsave(struct sdhci_host *host,unsigned long *flags)
  31057. +{
  31058. +#ifdef CONFIG_PREEMPT
  31059. + if(enable_llm)
  31060. + {
  31061. + while(sdhci_locked)
  31062. + {
  31063. + preempt_schedule();
  31064. + }
  31065. + spin_lock_irqsave(&host->lock,*flags);
  31066. + disable_irq(host->irq);
  31067. + if(host->second_irq)
  31068. + disable_irq(host->second_irq);
  31069. + local_irq_enable();
  31070. + }
  31071. + else
  31072. +#endif
  31073. + spin_lock_irqsave(&host->lock,*flags);
  31074. +}
  31075. +
  31076. +void sdhci_spin_unlock_irqrestore(struct sdhci_host *host,unsigned long flags)
  31077. +{
  31078. +#ifdef CONFIG_PREEMPT
  31079. + if(enable_llm)
  31080. + {
  31081. + local_irq_disable();
  31082. + if(host->second_irq)
  31083. + enable_irq(host->second_irq);
  31084. + enable_irq(host->irq);
  31085. + }
  31086. +#endif
  31087. + spin_unlock_irqrestore(&host->lock,flags);
  31088. +}
  31089. +
  31090. +static void sdhci_spin_enable_schedule(struct sdhci_host *host)
  31091. +{
  31092. +#ifdef CONFIG_PREEMPT
  31093. + if(enable_llm)
  31094. + {
  31095. + sdhci_locked = 1;
  31096. + preempt_enable();
  31097. + }
  31098. +#endif
  31099. +}
  31100. +
  31101. +static void sdhci_spin_disable_schedule(struct sdhci_host *host)
  31102. +{
  31103. +#ifdef CONFIG_PREEMPT
  31104. + if(enable_llm)
  31105. + {
  31106. + preempt_disable();
  31107. + sdhci_locked = 0;
  31108. + }
  31109. +#endif
  31110. +}
  31111. +
  31112. +
  31113. +#undef spin_lock_irqsave
  31114. +#define spin_lock_irqsave(host_lock, flags) sdhci_spin_lock_irqsave(container_of(host_lock, struct sdhci_host, lock), &flags)
  31115. +#define spin_unlock_irqrestore(host_lock, flags) sdhci_spin_unlock_irqrestore(container_of(host_lock, struct sdhci_host, lock), flags)
  31116. +
  31117. +#define spin_lock(host_lock) sdhci_spin_lock(container_of(host_lock, struct sdhci_host, lock))
  31118. +#define spin_unlock(host_lock) sdhci_spin_unlock(container_of(host_lock, struct sdhci_host, lock))
  31119. static void sdhci_clear_set_irqs(struct sdhci_host *host, u32 clear, u32 set)
  31120. {
  31121. @@ -299,7 +393,7 @@
  31122. struct sdhci_host *host = container_of(led, struct sdhci_host, led);
  31123. unsigned long flags;
  31124. - spin_lock_irqsave(&host->lock, flags);
  31125. + sdhci_spin_lock_irqsave(host, &flags);
  31126. if (host->runtime_suspended)
  31127. goto out;
  31128. @@ -309,7 +403,7 @@
  31129. else
  31130. sdhci_activate_led(host);
  31131. out:
  31132. - spin_unlock_irqrestore(&host->lock, flags);
  31133. + sdhci_spin_unlock_irqrestore(host, flags);
  31134. }
  31135. #endif
  31136. @@ -326,7 +420,7 @@
  31137. u32 uninitialized_var(scratch);
  31138. u8 *buf;
  31139. - DBG("PIO reading\n");
  31140. + DBG("PIO reading %db\n", host->data->blksz);
  31141. blksize = host->data->blksz;
  31142. chunk = 0;
  31143. @@ -371,7 +465,7 @@
  31144. u32 scratch;
  31145. u8 *buf;
  31146. - DBG("PIO writing\n");
  31147. + DBG("PIO writing %db\n", host->data->blksz);
  31148. blksize = host->data->blksz;
  31149. chunk = 0;
  31150. @@ -410,19 +504,28 @@
  31151. local_irq_restore(flags);
  31152. }
  31153. -static void sdhci_transfer_pio(struct sdhci_host *host)
  31154. +static void sdhci_transfer_pio(struct sdhci_host *host, u32 intstate)
  31155. {
  31156. u32 mask;
  31157. + u32 state = 0;
  31158. + u32 intmask;
  31159. + int available;
  31160. BUG_ON(!host->data);
  31161. if (host->blocks == 0)
  31162. return;
  31163. - if (host->data->flags & MMC_DATA_READ)
  31164. + if (host->data->flags & MMC_DATA_READ) {
  31165. mask = SDHCI_DATA_AVAILABLE;
  31166. - else
  31167. + intmask = SDHCI_INT_DATA_AVAIL;
  31168. + } else {
  31169. mask = SDHCI_SPACE_AVAILABLE;
  31170. + intmask = SDHCI_INT_SPACE_AVAIL;
  31171. + }
  31172. +
  31173. + /* initially we can see whether we can procede using intstate */
  31174. + available = (intstate & intmask);
  31175. /*
  31176. * Some controllers (JMicron JMB38x) mess up the buffer bits
  31177. @@ -433,7 +536,7 @@
  31178. (host->data->blocks == 1))
  31179. mask = ~0;
  31180. - while (sdhci_readl(host, SDHCI_PRESENT_STATE) & mask) {
  31181. + while (available) {
  31182. if (host->quirks & SDHCI_QUIRK_PIO_NEEDS_DELAY)
  31183. udelay(100);
  31184. @@ -445,9 +548,12 @@
  31185. host->blocks--;
  31186. if (host->blocks == 0)
  31187. break;
  31188. + state = sdhci_readl(host, SDHCI_PRESENT_STATE);
  31189. + available = state & mask;
  31190. + break;
  31191. }
  31192. - DBG("PIO transfer complete.\n");
  31193. + DBG("PIO transfer complete - %d blocks left.\n", host->blocks);
  31194. }
  31195. static char *sdhci_kmap_atomic(struct scatterlist *sg, unsigned long *flags)
  31196. @@ -720,7 +826,9 @@
  31197. u32 pio_irqs = SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL;
  31198. u32 dma_irqs = SDHCI_INT_DMA_END | SDHCI_INT_ADMA_ERROR;
  31199. - if (host->flags & SDHCI_REQ_USE_DMA)
  31200. + /* platform DMA will begin on receipt of PIO irqs */
  31201. + if ((host->flags & SDHCI_REQ_USE_DMA) &&
  31202. + !(host->flags & SDHCI_USE_PLATDMA))
  31203. sdhci_clear_set_irqs(host, pio_irqs, dma_irqs);
  31204. else
  31205. sdhci_clear_set_irqs(host, dma_irqs, pio_irqs);
  31206. @@ -752,44 +860,25 @@
  31207. host->data_early = 0;
  31208. host->data->bytes_xfered = 0;
  31209. - if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA))
  31210. + if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA | SDHCI_USE_PLATDMA))
  31211. host->flags |= SDHCI_REQ_USE_DMA;
  31212. /*
  31213. * FIXME: This doesn't account for merging when mapping the
  31214. * scatterlist.
  31215. */
  31216. - if (host->flags & SDHCI_REQ_USE_DMA) {
  31217. - int broken, i;
  31218. - struct scatterlist *sg;
  31219. -
  31220. - broken = 0;
  31221. - if (host->flags & SDHCI_USE_ADMA) {
  31222. - if (host->quirks & SDHCI_QUIRK_32BIT_ADMA_SIZE)
  31223. - broken = 1;
  31224. - } else {
  31225. - if (host->quirks & SDHCI_QUIRK_32BIT_DMA_SIZE)
  31226. - broken = 1;
  31227. - }
  31228. -
  31229. - if (unlikely(broken)) {
  31230. - for_each_sg(data->sg, sg, data->sg_len, i) {
  31231. - if (sg->length & 0x3) {
  31232. - DBG("Reverting to PIO because of "
  31233. - "transfer size (%d)\n",
  31234. - sg->length);
  31235. - host->flags &= ~SDHCI_REQ_USE_DMA;
  31236. - break;
  31237. - }
  31238. - }
  31239. - }
  31240. - }
  31241. /*
  31242. * The assumption here being that alignment is the same after
  31243. * translation to device address space.
  31244. */
  31245. - if (host->flags & SDHCI_REQ_USE_DMA) {
  31246. + if ((host->flags & (SDHCI_REQ_USE_DMA | SDHCI_USE_PLATDMA)) ==
  31247. + (SDHCI_REQ_USE_DMA | SDHCI_USE_PLATDMA)) {
  31248. +
  31249. + if (! sdhci_platdma_dmaable(host, data))
  31250. + host->flags &= ~SDHCI_REQ_USE_DMA;
  31251. +
  31252. + } else if (host->flags & SDHCI_REQ_USE_DMA) {
  31253. int broken, i;
  31254. struct scatterlist *sg;
  31255. @@ -848,7 +937,8 @@
  31256. */
  31257. WARN_ON(1);
  31258. host->flags &= ~SDHCI_REQ_USE_DMA;
  31259. - } else {
  31260. + } else
  31261. + if (!(host->flags & SDHCI_USE_PLATDMA)) {
  31262. WARN_ON(sg_cnt != 1);
  31263. sdhci_writel(host, sg_dma_address(data->sg),
  31264. SDHCI_DMA_ADDRESS);
  31265. @@ -864,11 +954,13 @@
  31266. if (host->version >= SDHCI_SPEC_200) {
  31267. ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
  31268. ctrl &= ~SDHCI_CTRL_DMA_MASK;
  31269. + if (! (host->flags & SDHCI_USE_PLATDMA)) {
  31270. if ((host->flags & SDHCI_REQ_USE_DMA) &&
  31271. (host->flags & SDHCI_USE_ADMA))
  31272. ctrl |= SDHCI_CTRL_ADMA32;
  31273. else
  31274. ctrl |= SDHCI_CTRL_SDMA;
  31275. + }
  31276. sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
  31277. }
  31278. @@ -920,7 +1012,8 @@
  31279. if (data->flags & MMC_DATA_READ)
  31280. mode |= SDHCI_TRNS_READ;
  31281. - if (host->flags & SDHCI_REQ_USE_DMA)
  31282. + if ((host->flags & SDHCI_REQ_USE_DMA) &&
  31283. + !(host->flags & SDHCI_USE_PLATDMA))
  31284. mode |= SDHCI_TRNS_DMA;
  31285. sdhci_writew(host, mode, SDHCI_TRANSFER_MODE);
  31286. @@ -936,13 +1029,16 @@
  31287. host->data = NULL;
  31288. if (host->flags & SDHCI_REQ_USE_DMA) {
  31289. - if (host->flags & SDHCI_USE_ADMA)
  31290. - sdhci_adma_table_post(host, data);
  31291. - else {
  31292. + /* we may have to abandon an ongoing platform DMA */
  31293. + if (host->flags & SDHCI_USE_PLATDMA)
  31294. + sdhci_platdma_reset(host, data);
  31295. +
  31296. + if (host->flags & (SDHCI_USE_PLATDMA | SDHCI_USE_SDMA)) {
  31297. dma_unmap_sg(mmc_dev(host->mmc), data->sg,
  31298. data->sg_len, (data->flags & MMC_DATA_READ) ?
  31299. DMA_FROM_DEVICE : DMA_TO_DEVICE);
  31300. - }
  31301. + } else if (host->flags & SDHCI_USE_ADMA)
  31302. + sdhci_adma_table_post(host, data);
  31303. }
  31304. /*
  31305. @@ -995,6 +1091,12 @@
  31306. if ((cmd->data != NULL) || (cmd->flags & MMC_RSP_BUSY))
  31307. mask |= SDHCI_DATA_INHIBIT;
  31308. + if(host->ops->missing_status && (cmd->opcode == MMC_SEND_STATUS)) {
  31309. + timeout = 5000; // Really obscenely large delay to send the status, due to bug in controller
  31310. + // which might cause the STATUS command to get stuck when a data operation is in flow
  31311. + mask |= SDHCI_DATA_INHIBIT;
  31312. + }
  31313. +
  31314. /* We shouldn't wait for data inihibit for stop commands, even
  31315. though they might use busy signaling */
  31316. if (host->mrq->data && (cmd == host->mrq->data->stop))
  31317. @@ -1010,12 +1112,20 @@
  31318. return;
  31319. }
  31320. timeout--;
  31321. + sdhci_spin_enable_schedule(host);
  31322. mdelay(1);
  31323. + sdhci_spin_disable_schedule(host);
  31324. }
  31325. + DBG("send cmd %d - wait 0x%X irq 0x%x\n", cmd->opcode, mask,
  31326. + sdhci_readl(host, SDHCI_INT_STATUS));
  31327. mod_timer(&host->timer, jiffies + 10 * HZ);
  31328. host->cmd = cmd;
  31329. + if (host->last_cmdop == MMC_APP_CMD)
  31330. + host->last_cmdop = -cmd->opcode;
  31331. + else
  31332. + host->last_cmdop = cmd->opcode;
  31333. sdhci_prepare_data(host, cmd);
  31334. @@ -1232,7 +1342,9 @@
  31335. return;
  31336. }
  31337. timeout--;
  31338. + sdhci_spin_enable_schedule(host);
  31339. mdelay(1);
  31340. + sdhci_spin_disable_schedule(host);
  31341. }
  31342. clk |= SDHCI_CLOCK_CARD_EN;
  31343. @@ -1333,7 +1445,7 @@
  31344. sdhci_runtime_pm_get(host);
  31345. - spin_lock_irqsave(&host->lock, flags);
  31346. + sdhci_spin_lock_irqsave(host, &flags);
  31347. WARN_ON(host->mrq != NULL);
  31348. @@ -1391,9 +1503,9 @@
  31349. mmc->card->type == MMC_TYPE_MMC ?
  31350. MMC_SEND_TUNING_BLOCK_HS200 :
  31351. MMC_SEND_TUNING_BLOCK;
  31352. - spin_unlock_irqrestore(&host->lock, flags);
  31353. + sdhci_spin_unlock_irqrestore(host, flags);
  31354. sdhci_execute_tuning(mmc, tuning_opcode);
  31355. - spin_lock_irqsave(&host->lock, flags);
  31356. + sdhci_spin_lock_irqsave(host, &flags);
  31357. /* Restore original mmc_request structure */
  31358. host->mrq = mrq;
  31359. @@ -1407,7 +1519,7 @@
  31360. }
  31361. mmiowb();
  31362. - spin_unlock_irqrestore(&host->lock, flags);
  31363. + sdhci_spin_unlock_irqrestore(host, flags);
  31364. }
  31365. static void sdhci_do_set_ios(struct sdhci_host *host, struct mmc_ios *ios)
  31366. @@ -1416,10 +1528,10 @@
  31367. int vdd_bit = -1;
  31368. u8 ctrl;
  31369. - spin_lock_irqsave(&host->lock, flags);
  31370. + sdhci_spin_lock_irqsave(host, &flags);
  31371. if (host->flags & SDHCI_DEVICE_DEAD) {
  31372. - spin_unlock_irqrestore(&host->lock, flags);
  31373. + sdhci_spin_unlock_irqrestore(host, flags);
  31374. if (host->vmmc && ios->power_mode == MMC_POWER_OFF)
  31375. mmc_regulator_set_ocr(host->mmc, host->vmmc, 0);
  31376. return;
  31377. @@ -1447,9 +1559,9 @@
  31378. vdd_bit = sdhci_set_power(host, ios->vdd);
  31379. if (host->vmmc && vdd_bit != -1) {
  31380. - spin_unlock_irqrestore(&host->lock, flags);
  31381. + sdhci_spin_unlock_irqrestore(host, flags);
  31382. mmc_regulator_set_ocr(host->mmc, host->vmmc, vdd_bit);
  31383. - spin_lock_irqsave(&host->lock, flags);
  31384. + sdhci_spin_lock_irqsave(host, &flags);
  31385. }
  31386. if (host->ops->platform_send_init_74_clocks)
  31387. @@ -1586,7 +1698,7 @@
  31388. sdhci_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA);
  31389. mmiowb();
  31390. - spin_unlock_irqrestore(&host->lock, flags);
  31391. + sdhci_spin_unlock_irqrestore(host, flags);
  31392. }
  31393. static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  31394. @@ -1634,7 +1746,7 @@
  31395. unsigned long flags;
  31396. int is_readonly;
  31397. - spin_lock_irqsave(&host->lock, flags);
  31398. + sdhci_spin_lock_irqsave(host, &flags);
  31399. if (host->flags & SDHCI_DEVICE_DEAD)
  31400. is_readonly = 0;
  31401. @@ -1644,7 +1756,7 @@
  31402. is_readonly = !(sdhci_readl(host, SDHCI_PRESENT_STATE)
  31403. & SDHCI_WRITE_PROTECT);
  31404. - spin_unlock_irqrestore(&host->lock, flags);
  31405. + sdhci_spin_unlock_irqrestore(host, flags);
  31406. /* This quirk needs to be replaced by a callback-function later */
  31407. return host->quirks & SDHCI_QUIRK_INVERTED_WRITE_PROTECT ?
  31408. @@ -1717,9 +1829,9 @@
  31409. struct sdhci_host *host = mmc_priv(mmc);
  31410. unsigned long flags;
  31411. - spin_lock_irqsave(&host->lock, flags);
  31412. + sdhci_spin_lock_irqsave(host, &flags);
  31413. sdhci_enable_sdio_irq_nolock(host, enable);
  31414. - spin_unlock_irqrestore(&host->lock, flags);
  31415. + sdhci_spin_unlock_irqrestore(host, flags);
  31416. }
  31417. static int sdhci_do_start_signal_voltage_switch(struct sdhci_host *host,
  31418. @@ -2070,7 +2182,7 @@
  31419. if (host->ops->card_event)
  31420. host->ops->card_event(host);
  31421. - spin_lock_irqsave(&host->lock, flags);
  31422. + sdhci_spin_lock_irqsave(host, &flags);
  31423. /* Check host->mrq first in case we are runtime suspended */
  31424. if (host->mrq && !sdhci_do_get_cd(host)) {
  31425. @@ -2086,7 +2198,7 @@
  31426. tasklet_schedule(&host->finish_tasklet);
  31427. }
  31428. - spin_unlock_irqrestore(&host->lock, flags);
  31429. + sdhci_spin_unlock_irqrestore(host, flags);
  31430. }
  31431. static const struct mmc_host_ops sdhci_ops = {
  31432. @@ -2125,14 +2237,14 @@
  31433. host = (struct sdhci_host*)param;
  31434. - spin_lock_irqsave(&host->lock, flags);
  31435. + sdhci_spin_lock_irqsave(host, &flags);
  31436. /*
  31437. * If this tasklet gets rescheduled while running, it will
  31438. * be run again afterwards but without any active request.
  31439. */
  31440. if (!host->mrq) {
  31441. - spin_unlock_irqrestore(&host->lock, flags);
  31442. + sdhci_spin_unlock_irqrestore(host, flags);
  31443. return;
  31444. }
  31445. @@ -2170,7 +2282,7 @@
  31446. #endif
  31447. mmiowb();
  31448. - spin_unlock_irqrestore(&host->lock, flags);
  31449. + sdhci_spin_unlock_irqrestore(host, flags);
  31450. mmc_request_done(host->mmc, mrq);
  31451. sdhci_runtime_pm_put(host);
  31452. @@ -2183,11 +2295,11 @@
  31453. host = (struct sdhci_host*)data;
  31454. - spin_lock_irqsave(&host->lock, flags);
  31455. + sdhci_spin_lock_irqsave(host, &flags);
  31456. if (host->mrq) {
  31457. pr_err("%s: Timeout waiting for hardware "
  31458. - "interrupt.\n", mmc_hostname(host->mmc));
  31459. + "interrupt - cmd%d.\n", mmc_hostname(host->mmc), host->last_cmdop);
  31460. sdhci_dumpregs(host);
  31461. if (host->data) {
  31462. @@ -2204,7 +2316,7 @@
  31463. }
  31464. mmiowb();
  31465. - spin_unlock_irqrestore(&host->lock, flags);
  31466. + sdhci_spin_unlock_irqrestore(host, flags);
  31467. }
  31468. static void sdhci_tuning_timer(unsigned long data)
  31469. @@ -2214,11 +2326,11 @@
  31470. host = (struct sdhci_host *)data;
  31471. - spin_lock_irqsave(&host->lock, flags);
  31472. + sdhci_spin_lock_irqsave(host, &flags);
  31473. host->flags |= SDHCI_NEEDS_RETUNING;
  31474. - spin_unlock_irqrestore(&host->lock, flags);
  31475. + sdhci_spin_unlock_irqrestore(host, flags);
  31476. }
  31477. /*****************************************************************************\
  31478. @@ -2232,10 +2344,13 @@
  31479. BUG_ON(intmask == 0);
  31480. if (!host->cmd) {
  31481. + if (!(host->ops->extra_ints)) {
  31482. pr_err("%s: Got command interrupt 0x%08x even "
  31483. "though no command operation was in progress.\n",
  31484. mmc_hostname(host->mmc), (unsigned)intmask);
  31485. sdhci_dumpregs(host);
  31486. + } else
  31487. + DBG("cmd irq 0x%08x cmd complete\n", (unsigned)intmask);
  31488. return;
  31489. }
  31490. @@ -2305,6 +2420,19 @@
  31491. static void sdhci_show_adma_error(struct sdhci_host *host) { }
  31492. #endif
  31493. +static void sdhci_data_end(struct sdhci_host *host)
  31494. +{
  31495. + if (host->cmd) {
  31496. + /*
  31497. + * Data managed to finish before the
  31498. + * command completed. Make sure we do
  31499. + * things in the proper order.
  31500. + */
  31501. + host->data_early = 1;
  31502. + } else
  31503. + sdhci_finish_data(host);
  31504. +}
  31505. +
  31506. static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
  31507. {
  31508. u32 command;
  31509. @@ -2334,23 +2462,39 @@
  31510. }
  31511. }
  31512. + if (!(host->ops->extra_ints)) {
  31513. pr_err("%s: Got data interrupt 0x%08x even "
  31514. "though no data operation was in progress.\n",
  31515. mmc_hostname(host->mmc), (unsigned)intmask);
  31516. sdhci_dumpregs(host);
  31517. + } else
  31518. + DBG("data irq 0x%08x but no data\n", (unsigned)intmask);
  31519. return;
  31520. }
  31521. if (intmask & SDHCI_INT_DATA_TIMEOUT)
  31522. host->data->error = -ETIMEDOUT;
  31523. - else if (intmask & SDHCI_INT_DATA_END_BIT)
  31524. + else if (intmask & SDHCI_INT_DATA_END_BIT) {
  31525. + DBG("end error in cmd %d\n", host->last_cmdop);
  31526. + if (host->ops->spurious_crc_acmd51 &&
  31527. + host->last_cmdop == -SD_APP_SEND_SCR) {
  31528. + DBG("ignoring spurious data_end_bit error\n");
  31529. + intmask = SDHCI_INT_DATA_AVAIL|SDHCI_INT_DATA_END;
  31530. + } else
  31531. host->data->error = -EILSEQ;
  31532. - else if ((intmask & SDHCI_INT_DATA_CRC) &&
  31533. + } else if ((intmask & SDHCI_INT_DATA_CRC) &&
  31534. SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND))
  31535. - != MMC_BUS_TEST_R)
  31536. + != MMC_BUS_TEST_R) {
  31537. + DBG("crc error in cmd %d\n", host->last_cmdop);
  31538. + if (host->ops->spurious_crc_acmd51 &&
  31539. + host->last_cmdop == -SD_APP_SEND_SCR) {
  31540. + DBG("ignoring spurious data_crc_bit error\n");
  31541. + intmask = SDHCI_INT_DATA_AVAIL|SDHCI_INT_DATA_END;
  31542. + } else {
  31543. host->data->error = -EILSEQ;
  31544. - else if (intmask & SDHCI_INT_ADMA_ERROR) {
  31545. + }
  31546. + } else if (intmask & SDHCI_INT_ADMA_ERROR) {
  31547. pr_err("%s: ADMA error\n", mmc_hostname(host->mmc));
  31548. sdhci_show_adma_error(host);
  31549. host->data->error = -EIO;
  31550. @@ -2358,11 +2502,18 @@
  31551. host->ops->adma_workaround(host, intmask);
  31552. }
  31553. - if (host->data->error)
  31554. + if (host->data->error) {
  31555. + DBG("finish request early on error %d\n", host->data->error);
  31556. sdhci_finish_data(host);
  31557. - else {
  31558. - if (intmask & (SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL))
  31559. - sdhci_transfer_pio(host);
  31560. + } else {
  31561. + if (intmask & (SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL)) {
  31562. + if (host->flags & SDHCI_REQ_USE_DMA) {
  31563. + /* possible only in PLATDMA mode */
  31564. + sdhci_platdma_avail(host, &intmask,
  31565. + &sdhci_data_end);
  31566. + } else
  31567. + sdhci_transfer_pio(host, intmask);
  31568. + }
  31569. /*
  31570. * We currently don't do anything fancy with DMA
  31571. @@ -2391,18 +2542,8 @@
  31572. sdhci_writel(host, dmanow, SDHCI_DMA_ADDRESS);
  31573. }
  31574. - if (intmask & SDHCI_INT_DATA_END) {
  31575. - if (host->cmd) {
  31576. - /*
  31577. - * Data managed to finish before the
  31578. - * command completed. Make sure we do
  31579. - * things in the proper order.
  31580. - */
  31581. - host->data_early = 1;
  31582. - } else {
  31583. - sdhci_finish_data(host);
  31584. - }
  31585. - }
  31586. + if (intmask & SDHCI_INT_DATA_END)
  31587. + sdhci_data_end(host);
  31588. }
  31589. }
  31590. @@ -2413,10 +2554,10 @@
  31591. u32 intmask, unexpected = 0;
  31592. int cardint = 0, max_loops = 16;
  31593. - spin_lock(&host->lock);
  31594. + sdhci_spin_lock(host);
  31595. if (host->runtime_suspended) {
  31596. - spin_unlock(&host->lock);
  31597. + sdhci_spin_unlock(host);
  31598. pr_warning("%s: got irq while runtime suspended\n",
  31599. mmc_hostname(host->mmc));
  31600. return IRQ_HANDLED;
  31601. @@ -2458,6 +2599,22 @@
  31602. tasklet_schedule(&host->card_tasklet);
  31603. }
  31604. + if (intmask & SDHCI_INT_ERROR_MASK & ~SDHCI_INT_ERROR)
  31605. + DBG("controller reports error 0x%x -"
  31606. + "%s%s%s%s%s%s%s%s%s%s",
  31607. + intmask,
  31608. + intmask & SDHCI_INT_TIMEOUT? " timeout": "",
  31609. + intmask & SDHCI_INT_CRC ? " crc": "",
  31610. + intmask & SDHCI_INT_END_BIT? " endbit": "",
  31611. + intmask & SDHCI_INT_INDEX? " index": "",
  31612. + intmask & SDHCI_INT_DATA_TIMEOUT? " data_timeout": "",
  31613. + intmask & SDHCI_INT_DATA_CRC? " data_crc": "",
  31614. + intmask & SDHCI_INT_DATA_END_BIT? " data_endbit": "",
  31615. + intmask & SDHCI_INT_BUS_POWER? " buspower": "",
  31616. + intmask & SDHCI_INT_ACMD12ERR? " acmd12": "",
  31617. + intmask & SDHCI_INT_ADMA_ERROR? " adma": ""
  31618. + );
  31619. +
  31620. if (intmask & SDHCI_INT_CMD_MASK) {
  31621. sdhci_writel(host, intmask & SDHCI_INT_CMD_MASK,
  31622. SDHCI_INT_STATUS);
  31623. @@ -2472,7 +2629,13 @@
  31624. intmask &= ~(SDHCI_INT_CMD_MASK | SDHCI_INT_DATA_MASK);
  31625. - intmask &= ~SDHCI_INT_ERROR;
  31626. + if (intmask & SDHCI_INT_ERROR_MASK) {
  31627. + /* collect any uncovered errors */
  31628. + sdhci_writel(host, intmask & SDHCI_INT_ERROR_MASK,
  31629. + SDHCI_INT_STATUS);
  31630. + }
  31631. +
  31632. + intmask &= ~SDHCI_INT_ERROR_MASK;
  31633. if (intmask & SDHCI_INT_BUS_POWER) {
  31634. pr_err("%s: Card is consuming too much power!\n",
  31635. @@ -2506,7 +2669,7 @@
  31636. if (intmask && --max_loops)
  31637. goto again;
  31638. out:
  31639. - spin_unlock(&host->lock);
  31640. + sdhci_spin_unlock(host);
  31641. if (unexpected) {
  31642. pr_err("%s: Unexpected interrupt 0x%08x.\n",
  31643. @@ -2585,13 +2748,14 @@
  31644. {
  31645. int ret = 0;
  31646. - if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
  31647. + if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA |
  31648. + SDHCI_USE_PLATDMA)) {
  31649. if (host->ops->enable_dma)
  31650. host->ops->enable_dma(host);
  31651. }
  31652. if (!device_may_wakeup(mmc_dev(host->mmc))) {
  31653. - ret = request_irq(host->irq, sdhci_irq, IRQF_SHARED,
  31654. + ret = request_irq(host->irq, sdhci_irq, 0 /*IRQF_SHARED*/,
  31655. mmc_hostname(host->mmc), host);
  31656. if (ret)
  31657. return ret;
  31658. @@ -2667,15 +2831,15 @@
  31659. host->flags &= ~SDHCI_NEEDS_RETUNING;
  31660. }
  31661. - spin_lock_irqsave(&host->lock, flags);
  31662. + sdhci_spin_lock_irqsave(host, &flags);
  31663. sdhci_mask_irqs(host, SDHCI_INT_ALL_MASK);
  31664. - spin_unlock_irqrestore(&host->lock, flags);
  31665. + sdhci_spin_unlock_irqrestore(host, flags);
  31666. synchronize_irq(host->irq);
  31667. - spin_lock_irqsave(&host->lock, flags);
  31668. + sdhci_spin_lock_irqsave(host, &flags);
  31669. host->runtime_suspended = true;
  31670. - spin_unlock_irqrestore(&host->lock, flags);
  31671. + sdhci_spin_unlock_irqrestore(host, flags);
  31672. return ret;
  31673. }
  31674. @@ -2701,16 +2865,16 @@
  31675. sdhci_do_start_signal_voltage_switch(host, &host->mmc->ios);
  31676. if ((host_flags & SDHCI_PV_ENABLED) &&
  31677. !(host->quirks2 & SDHCI_QUIRK2_PRESET_VALUE_BROKEN)) {
  31678. - spin_lock_irqsave(&host->lock, flags);
  31679. + sdhci_spin_lock_irqsave(host, &flags);
  31680. sdhci_enable_preset_value(host, true);
  31681. - spin_unlock_irqrestore(&host->lock, flags);
  31682. + sdhci_spin_unlock_irqrestore(host, flags);
  31683. }
  31684. /* Set the re-tuning expiration flag */
  31685. if (host->flags & SDHCI_USING_RETUNING_TIMER)
  31686. host->flags |= SDHCI_NEEDS_RETUNING;
  31687. - spin_lock_irqsave(&host->lock, flags);
  31688. + sdhci_spin_lock_irqsave(host, &flags);
  31689. host->runtime_suspended = false;
  31690. @@ -2721,7 +2885,7 @@
  31691. /* Enable Card Detection */
  31692. sdhci_enable_card_detection(host);
  31693. - spin_unlock_irqrestore(&host->lock, flags);
  31694. + sdhci_spin_unlock_irqrestore(host, flags);
  31695. return ret;
  31696. }
  31697. @@ -2816,14 +2980,16 @@
  31698. host->flags &= ~SDHCI_USE_ADMA;
  31699. }
  31700. - if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
  31701. + if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA |
  31702. + SDHCI_USE_PLATDMA)) {
  31703. if (host->ops->enable_dma) {
  31704. if (host->ops->enable_dma(host)) {
  31705. pr_warning("%s: No suitable DMA "
  31706. "available. Falling back to PIO.\n",
  31707. mmc_hostname(mmc));
  31708. host->flags &=
  31709. - ~(SDHCI_USE_SDMA | SDHCI_USE_ADMA);
  31710. + ~(SDHCI_USE_SDMA | SDHCI_USE_ADMA |
  31711. + SDHCI_USE_PLATDMA);
  31712. }
  31713. }
  31714. }
  31715. @@ -3215,8 +3381,8 @@
  31716. sdhci_init(host, 0);
  31717. - ret = request_irq(host->irq, sdhci_irq, IRQF_SHARED,
  31718. - mmc_hostname(mmc), host);
  31719. + ret = request_irq(host->irq, sdhci_irq, 0 /*IRQF_SHARED*/,
  31720. + mmc_hostname(mmc), host);
  31721. if (ret) {
  31722. pr_err("%s: Failed to request IRQ %d: %d\n",
  31723. mmc_hostname(mmc), host->irq, ret);
  31724. @@ -3249,6 +3415,7 @@
  31725. pr_info("%s: SDHCI controller on %s [%s] using %s\n",
  31726. mmc_hostname(mmc), host->hw_name, dev_name(mmc_dev(mmc)),
  31727. + (host->flags & SDHCI_USE_PLATDMA) ? "platform's DMA" :
  31728. (host->flags & SDHCI_USE_ADMA) ? "ADMA" :
  31729. (host->flags & SDHCI_USE_SDMA) ? "DMA" : "PIO");
  31730. @@ -3276,7 +3443,7 @@
  31731. unsigned long flags;
  31732. if (dead) {
  31733. - spin_lock_irqsave(&host->lock, flags);
  31734. + sdhci_spin_lock_irqsave(host, &flags);
  31735. host->flags |= SDHCI_DEVICE_DEAD;
  31736. @@ -3288,7 +3455,7 @@
  31737. tasklet_schedule(&host->finish_tasklet);
  31738. }
  31739. - spin_unlock_irqrestore(&host->lock, flags);
  31740. + sdhci_spin_unlock_irqrestore(host, flags);
  31741. }
  31742. sdhci_disable_card_detection(host);
  31743. diff -Nur linux-3.13.3.orig/drivers/mmc/host/sdhci-esdhc-imx.c linux-3.13.3/drivers/mmc/host/sdhci-esdhc-imx.c
  31744. --- linux-3.13.3.orig/drivers/mmc/host/sdhci-esdhc-imx.c 2014-02-13 23:00:14.000000000 +0100
  31745. +++ linux-3.13.3/drivers/mmc/host/sdhci-esdhc-imx.c 2014-02-17 22:45:44.000000000 +0100
  31746. @@ -112,6 +112,8 @@
  31747. /* The IP has SDHCI_CAPABILITIES_1 register */
  31748. #define ESDHC_FLAG_HAVE_CAP1 BIT(6)
  31749. +bool enable_llm = 0;
  31750. +
  31751. struct esdhc_soc_data {
  31752. u32 flags;
  31753. };
  31754. diff -Nur linux-3.13.3.orig/drivers/mmc/host/sdhci.h linux-3.13.3/drivers/mmc/host/sdhci.h
  31755. --- linux-3.13.3.orig/drivers/mmc/host/sdhci.h 2014-02-13 23:00:14.000000000 +0100
  31756. +++ linux-3.13.3/drivers/mmc/host/sdhci.h 2014-02-17 22:41:01.000000000 +0100
  31757. @@ -290,6 +290,18 @@
  31758. void (*platform_reset_exit)(struct sdhci_host *host, u8 mask);
  31759. int (*platform_execute_tuning)(struct sdhci_host *host, u32 opcode);
  31760. int (*set_uhs_signaling)(struct sdhci_host *host, unsigned int uhs);
  31761. +
  31762. + int (*pdma_able)(struct sdhci_host *host,
  31763. + struct mmc_data *data);
  31764. + void (*pdma_avail)(struct sdhci_host *host,
  31765. + unsigned int *ref_intmask,
  31766. + void(*complete)(struct sdhci_host *));
  31767. + void (*pdma_reset)(struct sdhci_host *host,
  31768. + struct mmc_data *data);
  31769. + unsigned int (*extra_ints)(struct sdhci_host *host);
  31770. + unsigned int (*spurious_crc_acmd51)(struct sdhci_host *host);
  31771. + unsigned int (*missing_status)(struct sdhci_host *host);
  31772. +
  31773. void (*hw_reset)(struct sdhci_host *host);
  31774. void (*platform_suspend)(struct sdhci_host *host);
  31775. void (*platform_resume)(struct sdhci_host *host);
  31776. @@ -403,9 +415,38 @@
  31777. extern void sdhci_enable_irq_wakeups(struct sdhci_host *host);
  31778. #endif
  31779. +static inline int /*bool*/
  31780. +sdhci_platdma_dmaable(struct sdhci_host *host, struct mmc_data *data)
  31781. +{
  31782. + if (host->ops->pdma_able)
  31783. + return host->ops->pdma_able(host, data);
  31784. + else
  31785. + return 1;
  31786. +}
  31787. +static inline void
  31788. +sdhci_platdma_avail(struct sdhci_host *host, unsigned int *ref_intmask,
  31789. + void(*completion_callback)(struct sdhci_host *))
  31790. +{
  31791. + if (host->ops->pdma_avail)
  31792. + host->ops->pdma_avail(host, ref_intmask, completion_callback);
  31793. +}
  31794. +
  31795. +static inline void
  31796. +sdhci_platdma_reset(struct sdhci_host *host, struct mmc_data *data)
  31797. +{
  31798. + if (host->ops->pdma_reset)
  31799. + host->ops->pdma_reset(host, data);
  31800. +}
  31801. +
  31802. #ifdef CONFIG_PM_RUNTIME
  31803. extern int sdhci_runtime_suspend_host(struct sdhci_host *host);
  31804. extern int sdhci_runtime_resume_host(struct sdhci_host *host);
  31805. #endif
  31806. +extern void sdhci_spin_lock_irqsave(struct sdhci_host *host,unsigned long *flags);
  31807. +extern void sdhci_spin_unlock_irqrestore(struct sdhci_host *host,unsigned long flags);
  31808. +extern void sdhci_spin_lock(struct sdhci_host *host);
  31809. +extern void sdhci_spin_unlock(struct sdhci_host *host);
  31810. +
  31811. +
  31812. #endif /* __SDHCI_HW_H */
  31813. diff -Nur linux-3.13.3.orig/drivers/net/usb/smsc95xx.c linux-3.13.3/drivers/net/usb/smsc95xx.c
  31814. --- linux-3.13.3.orig/drivers/net/usb/smsc95xx.c 2014-02-13 23:00:14.000000000 +0100
  31815. +++ linux-3.13.3/drivers/net/usb/smsc95xx.c 2014-02-17 22:41:01.000000000 +0100
  31816. @@ -61,6 +61,7 @@
  31817. #define SUSPEND_SUSPEND3 (0x08)
  31818. #define SUSPEND_ALLMODES (SUSPEND_SUSPEND0 | SUSPEND_SUSPEND1 | \
  31819. SUSPEND_SUSPEND2 | SUSPEND_SUSPEND3)
  31820. +#define MAC_ADDR_LEN (6)
  31821. struct smsc95xx_priv {
  31822. u32 mac_cr;
  31823. @@ -76,6 +77,10 @@
  31824. module_param(turbo_mode, bool, 0644);
  31825. MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction");
  31826. +static char *macaddr = ":";
  31827. +module_param(macaddr, charp, 0);
  31828. +MODULE_PARM_DESC(macaddr, "MAC address");
  31829. +
  31830. static int __must_check __smsc95xx_read_reg(struct usbnet *dev, u32 index,
  31831. u32 *data, int in_pm)
  31832. {
  31833. @@ -765,8 +770,59 @@
  31834. return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
  31835. }
  31836. +/* Check the macaddr module parameter for a MAC address */
  31837. +static int smsc95xx_is_macaddr_param(struct usbnet *dev, u8 *dev_mac)
  31838. +{
  31839. + int i, j, got_num, num;
  31840. + u8 mtbl[MAC_ADDR_LEN];
  31841. +
  31842. + if (macaddr[0] == ':')
  31843. + return 0;
  31844. +
  31845. + i = 0;
  31846. + j = 0;
  31847. + num = 0;
  31848. + got_num = 0;
  31849. + while (j < MAC_ADDR_LEN) {
  31850. + if (macaddr[i] && macaddr[i] != ':') {
  31851. + got_num++;
  31852. + if ('0' <= macaddr[i] && macaddr[i] <= '9')
  31853. + num = num * 16 + macaddr[i] - '0';
  31854. + else if ('A' <= macaddr[i] && macaddr[i] <= 'F')
  31855. + num = num * 16 + 10 + macaddr[i] - 'A';
  31856. + else if ('a' <= macaddr[i] && macaddr[i] <= 'f')
  31857. + num = num * 16 + 10 + macaddr[i] - 'a';
  31858. + else
  31859. + break;
  31860. + i++;
  31861. + } else if (got_num == 2) {
  31862. + mtbl[j++] = (u8) num;
  31863. + num = 0;
  31864. + got_num = 0;
  31865. + i++;
  31866. + } else {
  31867. + break;
  31868. + }
  31869. + }
  31870. +
  31871. + if (j == MAC_ADDR_LEN) {
  31872. + netif_dbg(dev, ifup, dev->net, "Overriding MAC address with: "
  31873. + "%02x:%02x:%02x:%02x:%02x:%02x\n", mtbl[0], mtbl[1], mtbl[2],
  31874. + mtbl[3], mtbl[4], mtbl[5]);
  31875. + for (i = 0; i < MAC_ADDR_LEN; i++)
  31876. + dev_mac[i] = mtbl[i];
  31877. + return 1;
  31878. + } else {
  31879. + return 0;
  31880. + }
  31881. +}
  31882. +
  31883. static void smsc95xx_init_mac_address(struct usbnet *dev)
  31884. {
  31885. + /* Check module parameters */
  31886. + if (smsc95xx_is_macaddr_param(dev, dev->net->dev_addr))
  31887. + return;
  31888. +
  31889. /* try reading mac address from EEPROM */
  31890. if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
  31891. dev->net->dev_addr) == 0) {
  31892. diff -Nur linux-3.13.3.orig/drivers/spi/Kconfig linux-3.13.3/drivers/spi/Kconfig
  31893. --- linux-3.13.3.orig/drivers/spi/Kconfig 2014-02-13 23:00:14.000000000 +0100
  31894. +++ linux-3.13.3/drivers/spi/Kconfig 2014-02-17 22:41:01.000000000 +0100
  31895. @@ -85,6 +85,14 @@
  31896. is for the regular SPI controller. Slave mode operation is not also
  31897. not supported.
  31898. +config SPI_BCM2708
  31899. + tristate "BCM2708 SPI controller driver (SPI0)"
  31900. + depends on MACH_BCM2708
  31901. + help
  31902. + This selects a driver for the Broadcom BCM2708 SPI master (SPI0). This
  31903. + driver is not compatible with the "Universal SPI Master" or the SPI slave
  31904. + device.
  31905. +
  31906. config SPI_BFIN5XX
  31907. tristate "SPI controller driver for ADI Blackfin5xx"
  31908. depends on BLACKFIN && !BF60x
  31909. diff -Nur linux-3.13.3.orig/drivers/spi/Makefile linux-3.13.3/drivers/spi/Makefile
  31910. --- linux-3.13.3.orig/drivers/spi/Makefile 2014-02-13 23:00:14.000000000 +0100
  31911. +++ linux-3.13.3/drivers/spi/Makefile 2014-02-17 22:41:01.000000000 +0100
  31912. @@ -18,6 +18,7 @@
  31913. obj-$(CONFIG_SPI_BCM63XX) += spi-bcm63xx.o
  31914. obj-$(CONFIG_SPI_BFIN5XX) += spi-bfin5xx.o
  31915. obj-$(CONFIG_SPI_BFIN_V3) += spi-bfin-v3.o
  31916. +obj-$(CONFIG_SPI_BCM2708) += spi-bcm2708.o
  31917. obj-$(CONFIG_SPI_BFIN_SPORT) += spi-bfin-sport.o
  31918. obj-$(CONFIG_SPI_BITBANG) += spi-bitbang.o
  31919. obj-$(CONFIG_SPI_BUTTERFLY) += spi-butterfly.o
  31920. diff -Nur linux-3.13.3.orig/drivers/spi/spi-bcm2708.c linux-3.13.3/drivers/spi/spi-bcm2708.c
  31921. --- linux-3.13.3.orig/drivers/spi/spi-bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  31922. +++ linux-3.13.3/drivers/spi/spi-bcm2708.c 2014-02-17 22:41:01.000000000 +0100
  31923. @@ -0,0 +1,626 @@
  31924. +/*
  31925. + * Driver for Broadcom BCM2708 SPI Controllers
  31926. + *
  31927. + * Copyright (C) 2012 Chris Boot
  31928. + *
  31929. + * This driver is inspired by:
  31930. + * spi-ath79.c, Copyright (C) 2009-2011 Gabor Juhos <juhosg@openwrt.org>
  31931. + * spi-atmel.c, Copyright (C) 2006 Atmel Corporation
  31932. + *
  31933. + * This program is free software; you can redistribute it and/or modify
  31934. + * it under the terms of the GNU General Public License as published by
  31935. + * the Free Software Foundation; either version 2 of the License, or
  31936. + * (at your option) any later version.
  31937. + *
  31938. + * This program is distributed in the hope that it will be useful,
  31939. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  31940. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  31941. + * GNU General Public License for more details.
  31942. + *
  31943. + * You should have received a copy of the GNU General Public License
  31944. + * along with this program; if not, write to the Free Software
  31945. + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  31946. + */
  31947. +
  31948. +#include <linux/kernel.h>
  31949. +#include <linux/module.h>
  31950. +#include <linux/spinlock.h>
  31951. +#include <linux/clk.h>
  31952. +#include <linux/err.h>
  31953. +#include <linux/platform_device.h>
  31954. +#include <linux/io.h>
  31955. +#include <linux/spi/spi.h>
  31956. +#include <linux/interrupt.h>
  31957. +#include <linux/delay.h>
  31958. +#include <linux/log2.h>
  31959. +#include <linux/sched.h>
  31960. +#include <linux/wait.h>
  31961. +
  31962. +/* SPI register offsets */
  31963. +#define SPI_CS 0x00
  31964. +#define SPI_FIFO 0x04
  31965. +#define SPI_CLK 0x08
  31966. +#define SPI_DLEN 0x0c
  31967. +#define SPI_LTOH 0x10
  31968. +#define SPI_DC 0x14
  31969. +
  31970. +/* Bitfields in CS */
  31971. +#define SPI_CS_LEN_LONG 0x02000000
  31972. +#define SPI_CS_DMA_LEN 0x01000000
  31973. +#define SPI_CS_CSPOL2 0x00800000
  31974. +#define SPI_CS_CSPOL1 0x00400000
  31975. +#define SPI_CS_CSPOL0 0x00200000
  31976. +#define SPI_CS_RXF 0x00100000
  31977. +#define SPI_CS_RXR 0x00080000
  31978. +#define SPI_CS_TXD 0x00040000
  31979. +#define SPI_CS_RXD 0x00020000
  31980. +#define SPI_CS_DONE 0x00010000
  31981. +#define SPI_CS_LEN 0x00002000
  31982. +#define SPI_CS_REN 0x00001000
  31983. +#define SPI_CS_ADCS 0x00000800
  31984. +#define SPI_CS_INTR 0x00000400
  31985. +#define SPI_CS_INTD 0x00000200
  31986. +#define SPI_CS_DMAEN 0x00000100
  31987. +#define SPI_CS_TA 0x00000080
  31988. +#define SPI_CS_CSPOL 0x00000040
  31989. +#define SPI_CS_CLEAR_RX 0x00000020
  31990. +#define SPI_CS_CLEAR_TX 0x00000010
  31991. +#define SPI_CS_CPOL 0x00000008
  31992. +#define SPI_CS_CPHA 0x00000004
  31993. +#define SPI_CS_CS_10 0x00000002
  31994. +#define SPI_CS_CS_01 0x00000001
  31995. +
  31996. +#define SPI_TIMEOUT_MS 150
  31997. +
  31998. +#define DRV_NAME "bcm2708_spi"
  31999. +
  32000. +struct bcm2708_spi {
  32001. + spinlock_t lock;
  32002. + void __iomem *base;
  32003. + int irq;
  32004. + struct clk *clk;
  32005. + bool stopping;
  32006. +
  32007. + struct list_head queue;
  32008. + struct workqueue_struct *workq;
  32009. + struct work_struct work;
  32010. + struct completion done;
  32011. +
  32012. + const u8 *tx_buf;
  32013. + u8 *rx_buf;
  32014. + int len;
  32015. +};
  32016. +
  32017. +struct bcm2708_spi_state {
  32018. + u32 cs;
  32019. + u16 cdiv;
  32020. +};
  32021. +
  32022. +/*
  32023. + * This function sets the ALT mode on the SPI pins so that we can use them with
  32024. + * the SPI hardware.
  32025. + *
  32026. + * FIXME: This is a hack. Use pinmux / pinctrl.
  32027. + */
  32028. +static void bcm2708_init_pinmode(void)
  32029. +{
  32030. +#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
  32031. +#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
  32032. +
  32033. + int pin;
  32034. + u32 *gpio = ioremap(0x20200000, SZ_16K);
  32035. +
  32036. + /* SPI is on GPIO 7..11 */
  32037. + for (pin = 7; pin <= 11; pin++) {
  32038. + INP_GPIO(pin); /* set mode to GPIO input first */
  32039. + SET_GPIO_ALT(pin, 0); /* set mode to ALT 0 */
  32040. + }
  32041. +
  32042. + iounmap(gpio);
  32043. +
  32044. +#undef INP_GPIO
  32045. +#undef SET_GPIO_ALT
  32046. +}
  32047. +
  32048. +static inline u32 bcm2708_rd(struct bcm2708_spi *bs, unsigned reg)
  32049. +{
  32050. + return readl(bs->base + reg);
  32051. +}
  32052. +
  32053. +static inline void bcm2708_wr(struct bcm2708_spi *bs, unsigned reg, u32 val)
  32054. +{
  32055. + writel(val, bs->base + reg);
  32056. +}
  32057. +
  32058. +static inline void bcm2708_rd_fifo(struct bcm2708_spi *bs, int len)
  32059. +{
  32060. + u8 byte;
  32061. +
  32062. + while (len--) {
  32063. + byte = bcm2708_rd(bs, SPI_FIFO);
  32064. + if (bs->rx_buf)
  32065. + *bs->rx_buf++ = byte;
  32066. + }
  32067. +}
  32068. +
  32069. +static inline void bcm2708_wr_fifo(struct bcm2708_spi *bs, int len)
  32070. +{
  32071. + u8 byte;
  32072. + u16 val;
  32073. +
  32074. + if (len > bs->len)
  32075. + len = bs->len;
  32076. +
  32077. + if (unlikely(bcm2708_rd(bs, SPI_CS) & SPI_CS_LEN)) {
  32078. + /* LoSSI mode */
  32079. + if (unlikely(len % 2)) {
  32080. + printk(KERN_ERR"bcm2708_wr_fifo: length must be even, skipping.\n");
  32081. + bs->len = 0;
  32082. + return;
  32083. + }
  32084. + while (len) {
  32085. + if (bs->tx_buf) {
  32086. + val = *(const u16 *)bs->tx_buf;
  32087. + bs->tx_buf += 2;
  32088. + } else
  32089. + val = 0;
  32090. + bcm2708_wr(bs, SPI_FIFO, val);
  32091. + bs->len -= 2;
  32092. + len -= 2;
  32093. + }
  32094. + return;
  32095. + }
  32096. +
  32097. + while (len--) {
  32098. + byte = bs->tx_buf ? *bs->tx_buf++ : 0;
  32099. + bcm2708_wr(bs, SPI_FIFO, byte);
  32100. + bs->len--;
  32101. + }
  32102. +}
  32103. +
  32104. +static irqreturn_t bcm2708_spi_interrupt(int irq, void *dev_id)
  32105. +{
  32106. + struct spi_master *master = dev_id;
  32107. + struct bcm2708_spi *bs = spi_master_get_devdata(master);
  32108. + u32 cs;
  32109. +
  32110. + spin_lock(&bs->lock);
  32111. +
  32112. + cs = bcm2708_rd(bs, SPI_CS);
  32113. +
  32114. + if (cs & SPI_CS_DONE) {
  32115. + if (bs->len) { /* first interrupt in a transfer */
  32116. + /* fill the TX fifo with up to 16 bytes */
  32117. + bcm2708_wr_fifo(bs, 16);
  32118. + } else { /* transfer complete */
  32119. + /* disable interrupts */
  32120. + cs &= ~(SPI_CS_INTR | SPI_CS_INTD);
  32121. + bcm2708_wr(bs, SPI_CS, cs);
  32122. +
  32123. + /* drain RX FIFO */
  32124. + while (cs & SPI_CS_RXD) {
  32125. + bcm2708_rd_fifo(bs, 1);
  32126. + cs = bcm2708_rd(bs, SPI_CS);
  32127. + }
  32128. +
  32129. + /* wake up our bh */
  32130. + complete(&bs->done);
  32131. + }
  32132. + } else if (cs & SPI_CS_RXR) {
  32133. + /* read 12 bytes of data */
  32134. + bcm2708_rd_fifo(bs, 12);
  32135. +
  32136. + /* write up to 12 bytes */
  32137. + bcm2708_wr_fifo(bs, 12);
  32138. + }
  32139. +
  32140. + spin_unlock(&bs->lock);
  32141. +
  32142. + return IRQ_HANDLED;
  32143. +}
  32144. +
  32145. +static int bcm2708_setup_state(struct spi_master *master,
  32146. + struct device *dev, struct bcm2708_spi_state *state,
  32147. + u32 hz, u8 csel, u8 mode, u8 bpw)
  32148. +{
  32149. + struct bcm2708_spi *bs = spi_master_get_devdata(master);
  32150. + int cdiv;
  32151. + unsigned long bus_hz;
  32152. + u32 cs = 0;
  32153. +
  32154. + bus_hz = clk_get_rate(bs->clk);
  32155. +
  32156. + if (hz >= bus_hz) {
  32157. + cdiv = 2; /* bus_hz / 2 is as fast as we can go */
  32158. + } else if (hz) {
  32159. + cdiv = DIV_ROUND_UP(bus_hz, hz);
  32160. +
  32161. + /* CDIV must be a power of 2, so round up */
  32162. + cdiv = roundup_pow_of_two(cdiv);
  32163. +
  32164. + if (cdiv > 65536) {
  32165. + dev_dbg(dev,
  32166. + "setup: %d Hz too slow, cdiv %u; min %ld Hz\n",
  32167. + hz, cdiv, bus_hz / 65536);
  32168. + return -EINVAL;
  32169. + } else if (cdiv == 65536) {
  32170. + cdiv = 0;
  32171. + } else if (cdiv == 1) {
  32172. + cdiv = 2; /* 1 gets rounded down to 0; == 65536 */
  32173. + }
  32174. + } else {
  32175. + cdiv = 0;
  32176. + }
  32177. +
  32178. + switch (bpw) {
  32179. + case 8:
  32180. + break;
  32181. + case 9:
  32182. + /* Reading in LoSSI mode is a special case. See 'BCM2835 ARM Peripherals' datasheet */
  32183. + cs |= SPI_CS_LEN;
  32184. + break;
  32185. + default:
  32186. + dev_dbg(dev, "setup: invalid bits_per_word %u (must be 8 or 9)\n",
  32187. + bpw);
  32188. + return -EINVAL;
  32189. + }
  32190. +
  32191. + if (mode & SPI_CPOL)
  32192. + cs |= SPI_CS_CPOL;
  32193. + if (mode & SPI_CPHA)
  32194. + cs |= SPI_CS_CPHA;
  32195. +
  32196. + if (!(mode & SPI_NO_CS)) {
  32197. + if (mode & SPI_CS_HIGH) {
  32198. + cs |= SPI_CS_CSPOL;
  32199. + cs |= SPI_CS_CSPOL0 << csel;
  32200. + }
  32201. +
  32202. + cs |= csel;
  32203. + } else {
  32204. + cs |= SPI_CS_CS_10 | SPI_CS_CS_01;
  32205. + }
  32206. +
  32207. + if (state) {
  32208. + state->cs = cs;
  32209. + state->cdiv = cdiv;
  32210. + dev_dbg(dev, "setup: want %d Hz; "
  32211. + "bus_hz=%lu / cdiv=%u == %lu Hz; "
  32212. + "mode %u: cs 0x%08X\n",
  32213. + hz, bus_hz, cdiv, bus_hz/cdiv, mode, cs);
  32214. + }
  32215. +
  32216. + return 0;
  32217. +}
  32218. +
  32219. +static int bcm2708_process_transfer(struct bcm2708_spi *bs,
  32220. + struct spi_message *msg, struct spi_transfer *xfer)
  32221. +{
  32222. + struct spi_device *spi = msg->spi;
  32223. + struct bcm2708_spi_state state, *stp;
  32224. + int ret;
  32225. + u32 cs;
  32226. +
  32227. + if (bs->stopping)
  32228. + return -ESHUTDOWN;
  32229. +
  32230. + if (xfer->bits_per_word || xfer->speed_hz) {
  32231. + ret = bcm2708_setup_state(spi->master, &spi->dev, &state,
  32232. + xfer->speed_hz ? xfer->speed_hz : spi->max_speed_hz,
  32233. + spi->chip_select, spi->mode,
  32234. + xfer->bits_per_word ? xfer->bits_per_word :
  32235. + spi->bits_per_word);
  32236. + if (ret)
  32237. + return ret;
  32238. +
  32239. + stp = &state;
  32240. + } else {
  32241. + stp = spi->controller_state;
  32242. + }
  32243. +
  32244. + reinit_completion(&bs->done);
  32245. + bs->tx_buf = xfer->tx_buf;
  32246. + bs->rx_buf = xfer->rx_buf;
  32247. + bs->len = xfer->len;
  32248. +
  32249. + cs = stp->cs | SPI_CS_INTR | SPI_CS_INTD | SPI_CS_TA;
  32250. +
  32251. + bcm2708_wr(bs, SPI_CLK, stp->cdiv);
  32252. + bcm2708_wr(bs, SPI_CS, cs);
  32253. +
  32254. + ret = wait_for_completion_timeout(&bs->done,
  32255. + msecs_to_jiffies(SPI_TIMEOUT_MS));
  32256. + if (ret == 0) {
  32257. + dev_err(&spi->dev, "transfer timed out\n");
  32258. + return -ETIMEDOUT;
  32259. + }
  32260. +
  32261. + if (xfer->delay_usecs)
  32262. + udelay(xfer->delay_usecs);
  32263. +
  32264. + if (list_is_last(&xfer->transfer_list, &msg->transfers) ||
  32265. + xfer->cs_change) {
  32266. + /* clear TA and interrupt flags */
  32267. + bcm2708_wr(bs, SPI_CS, stp->cs);
  32268. + }
  32269. +
  32270. + msg->actual_length += (xfer->len - bs->len);
  32271. +
  32272. + return 0;
  32273. +}
  32274. +
  32275. +static void bcm2708_work(struct work_struct *work)
  32276. +{
  32277. + struct bcm2708_spi *bs = container_of(work, struct bcm2708_spi, work);
  32278. + unsigned long flags;
  32279. + struct spi_message *msg;
  32280. + struct spi_transfer *xfer;
  32281. + int status = 0;
  32282. +
  32283. + spin_lock_irqsave(&bs->lock, flags);
  32284. + while (!list_empty(&bs->queue)) {
  32285. + msg = list_first_entry(&bs->queue, struct spi_message, queue);
  32286. + list_del_init(&msg->queue);
  32287. + spin_unlock_irqrestore(&bs->lock, flags);
  32288. +
  32289. + list_for_each_entry(xfer, &msg->transfers, transfer_list) {
  32290. + status = bcm2708_process_transfer(bs, msg, xfer);
  32291. + if (status)
  32292. + break;
  32293. + }
  32294. +
  32295. + msg->status = status;
  32296. + msg->complete(msg->context);
  32297. +
  32298. + spin_lock_irqsave(&bs->lock, flags);
  32299. + }
  32300. + spin_unlock_irqrestore(&bs->lock, flags);
  32301. +}
  32302. +
  32303. +static int bcm2708_spi_setup(struct spi_device *spi)
  32304. +{
  32305. + struct bcm2708_spi *bs = spi_master_get_devdata(spi->master);
  32306. + struct bcm2708_spi_state *state;
  32307. + int ret;
  32308. +
  32309. + if (bs->stopping)
  32310. + return -ESHUTDOWN;
  32311. +
  32312. + if (!(spi->mode & SPI_NO_CS) &&
  32313. + (spi->chip_select > spi->master->num_chipselect)) {
  32314. + dev_dbg(&spi->dev,
  32315. + "setup: invalid chipselect %u (%u defined)\n",
  32316. + spi->chip_select, spi->master->num_chipselect);
  32317. + return -EINVAL;
  32318. + }
  32319. +
  32320. + state = spi->controller_state;
  32321. + if (!state) {
  32322. + state = kzalloc(sizeof(*state), GFP_KERNEL);
  32323. + if (!state)
  32324. + return -ENOMEM;
  32325. +
  32326. + spi->controller_state = state;
  32327. + }
  32328. +
  32329. + ret = bcm2708_setup_state(spi->master, &spi->dev, state,
  32330. + spi->max_speed_hz, spi->chip_select, spi->mode,
  32331. + spi->bits_per_word);
  32332. + if (ret < 0) {
  32333. + kfree(state);
  32334. + spi->controller_state = NULL;
  32335. + return ret;
  32336. + }
  32337. +
  32338. + dev_dbg(&spi->dev,
  32339. + "setup: cd %d: %d Hz, bpw %u, mode 0x%x -> CS=%08x CDIV=%04x\n",
  32340. + spi->chip_select, spi->max_speed_hz, spi->bits_per_word,
  32341. + spi->mode, state->cs, state->cdiv);
  32342. +
  32343. + return 0;
  32344. +}
  32345. +
  32346. +static int bcm2708_spi_transfer(struct spi_device *spi, struct spi_message *msg)
  32347. +{
  32348. + struct bcm2708_spi *bs = spi_master_get_devdata(spi->master);
  32349. + struct spi_transfer *xfer;
  32350. + int ret;
  32351. + unsigned long flags;
  32352. +
  32353. + if (unlikely(list_empty(&msg->transfers)))
  32354. + return -EINVAL;
  32355. +
  32356. + if (bs->stopping)
  32357. + return -ESHUTDOWN;
  32358. +
  32359. + list_for_each_entry(xfer, &msg->transfers, transfer_list) {
  32360. + if (!(xfer->tx_buf || xfer->rx_buf) && xfer->len) {
  32361. + dev_dbg(&spi->dev, "missing rx or tx buf\n");
  32362. + return -EINVAL;
  32363. + }
  32364. +
  32365. + if (!xfer->bits_per_word || xfer->speed_hz)
  32366. + continue;
  32367. +
  32368. + ret = bcm2708_setup_state(spi->master, &spi->dev, NULL,
  32369. + xfer->speed_hz ? xfer->speed_hz : spi->max_speed_hz,
  32370. + spi->chip_select, spi->mode,
  32371. + xfer->bits_per_word ? xfer->bits_per_word :
  32372. + spi->bits_per_word);
  32373. + if (ret)
  32374. + return ret;
  32375. + }
  32376. +
  32377. + msg->status = -EINPROGRESS;
  32378. + msg->actual_length = 0;
  32379. +
  32380. + spin_lock_irqsave(&bs->lock, flags);
  32381. + list_add_tail(&msg->queue, &bs->queue);
  32382. + queue_work(bs->workq, &bs->work);
  32383. + spin_unlock_irqrestore(&bs->lock, flags);
  32384. +
  32385. + return 0;
  32386. +}
  32387. +
  32388. +static void bcm2708_spi_cleanup(struct spi_device *spi)
  32389. +{
  32390. + if (spi->controller_state) {
  32391. + kfree(spi->controller_state);
  32392. + spi->controller_state = NULL;
  32393. + }
  32394. +}
  32395. +
  32396. +static int bcm2708_spi_probe(struct platform_device *pdev)
  32397. +{
  32398. + struct resource *regs;
  32399. + int irq, err = -ENOMEM;
  32400. + struct clk *clk;
  32401. + struct spi_master *master;
  32402. + struct bcm2708_spi *bs;
  32403. +
  32404. + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  32405. + if (!regs) {
  32406. + dev_err(&pdev->dev, "could not get IO memory\n");
  32407. + return -ENXIO;
  32408. + }
  32409. +
  32410. + irq = platform_get_irq(pdev, 0);
  32411. + if (irq < 0) {
  32412. + dev_err(&pdev->dev, "could not get IRQ\n");
  32413. + return irq;
  32414. + }
  32415. +
  32416. + clk = clk_get(&pdev->dev, NULL);
  32417. + if (IS_ERR(clk)) {
  32418. + dev_err(&pdev->dev, "could not find clk: %ld\n", PTR_ERR(clk));
  32419. + return PTR_ERR(clk);
  32420. + }
  32421. +
  32422. + bcm2708_init_pinmode();
  32423. +
  32424. + master = spi_alloc_master(&pdev->dev, sizeof(*bs));
  32425. + if (!master) {
  32426. + dev_err(&pdev->dev, "spi_alloc_master() failed\n");
  32427. + goto out_clk_put;
  32428. + }
  32429. +
  32430. + /* the spi->mode bits understood by this driver: */
  32431. + master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_NO_CS;
  32432. +
  32433. + master->bus_num = pdev->id;
  32434. + master->num_chipselect = 3;
  32435. + master->setup = bcm2708_spi_setup;
  32436. + master->transfer = bcm2708_spi_transfer;
  32437. + master->cleanup = bcm2708_spi_cleanup;
  32438. + platform_set_drvdata(pdev, master);
  32439. +
  32440. + bs = spi_master_get_devdata(master);
  32441. +
  32442. + spin_lock_init(&bs->lock);
  32443. + INIT_LIST_HEAD(&bs->queue);
  32444. + init_completion(&bs->done);
  32445. + INIT_WORK(&bs->work, bcm2708_work);
  32446. +
  32447. + bs->base = ioremap(regs->start, resource_size(regs));
  32448. + if (!bs->base) {
  32449. + dev_err(&pdev->dev, "could not remap memory\n");
  32450. + goto out_master_put;
  32451. + }
  32452. +
  32453. + bs->workq = create_singlethread_workqueue(dev_name(&pdev->dev));
  32454. + if (!bs->workq) {
  32455. + dev_err(&pdev->dev, "could not create workqueue\n");
  32456. + goto out_iounmap;
  32457. + }
  32458. +
  32459. + bs->irq = irq;
  32460. + bs->clk = clk;
  32461. + bs->stopping = false;
  32462. +
  32463. + err = request_irq(irq, bcm2708_spi_interrupt, 0, dev_name(&pdev->dev),
  32464. + master);
  32465. + if (err) {
  32466. + dev_err(&pdev->dev, "could not request IRQ: %d\n", err);
  32467. + goto out_workqueue;
  32468. + }
  32469. +
  32470. + /* initialise the hardware */
  32471. + clk_enable(clk);
  32472. + bcm2708_wr(bs, SPI_CS, SPI_CS_REN | SPI_CS_CLEAR_RX | SPI_CS_CLEAR_TX);
  32473. +
  32474. + err = spi_register_master(master);
  32475. + if (err) {
  32476. + dev_err(&pdev->dev, "could not register SPI master: %d\n", err);
  32477. + goto out_free_irq;
  32478. + }
  32479. +
  32480. + dev_info(&pdev->dev, "SPI Controller at 0x%08lx (irq %d)\n",
  32481. + (unsigned long)regs->start, irq);
  32482. +
  32483. + return 0;
  32484. +
  32485. +out_free_irq:
  32486. + free_irq(bs->irq, master);
  32487. +out_workqueue:
  32488. + destroy_workqueue(bs->workq);
  32489. +out_iounmap:
  32490. + iounmap(bs->base);
  32491. +out_master_put:
  32492. + spi_master_put(master);
  32493. +out_clk_put:
  32494. + clk_put(clk);
  32495. + return err;
  32496. +}
  32497. +
  32498. +static int bcm2708_spi_remove(struct platform_device *pdev)
  32499. +{
  32500. + struct spi_master *master = platform_get_drvdata(pdev);
  32501. + struct bcm2708_spi *bs = spi_master_get_devdata(master);
  32502. +
  32503. + /* reset the hardware and block queue progress */
  32504. + spin_lock_irq(&bs->lock);
  32505. + bs->stopping = true;
  32506. + bcm2708_wr(bs, SPI_CS, SPI_CS_CLEAR_RX | SPI_CS_CLEAR_TX);
  32507. + spin_unlock_irq(&bs->lock);
  32508. +
  32509. + flush_work_sync(&bs->work);
  32510. +
  32511. + clk_disable(bs->clk);
  32512. + clk_put(bs->clk);
  32513. + free_irq(bs->irq, master);
  32514. + iounmap(bs->base);
  32515. +
  32516. + spi_unregister_master(master);
  32517. +
  32518. + return 0;
  32519. +}
  32520. +
  32521. +static struct platform_driver bcm2708_spi_driver = {
  32522. + .driver = {
  32523. + .name = DRV_NAME,
  32524. + .owner = THIS_MODULE,
  32525. + },
  32526. + .probe = bcm2708_spi_probe,
  32527. + .remove = bcm2708_spi_remove,
  32528. +};
  32529. +
  32530. +
  32531. +static int __init bcm2708_spi_init(void)
  32532. +{
  32533. + return platform_driver_probe(&bcm2708_spi_driver, bcm2708_spi_probe);
  32534. +}
  32535. +module_init(bcm2708_spi_init);
  32536. +
  32537. +static void __exit bcm2708_spi_exit(void)
  32538. +{
  32539. + platform_driver_unregister(&bcm2708_spi_driver);
  32540. +}
  32541. +module_exit(bcm2708_spi_exit);
  32542. +
  32543. +
  32544. +//module_platform_driver(bcm2708_spi_driver);
  32545. +
  32546. +MODULE_DESCRIPTION("SPI controller driver for Broadcom BCM2708");
  32547. +MODULE_AUTHOR("Chris Boot <bootc@bootc.net>");
  32548. +MODULE_LICENSE("GPL v2");
  32549. +MODULE_ALIAS("platform:" DRV_NAME);
  32550. diff -Nur linux-3.13.3.orig/drivers/staging/media/lirc/Kconfig linux-3.13.3/drivers/staging/media/lirc/Kconfig
  32551. --- linux-3.13.3.orig/drivers/staging/media/lirc/Kconfig 2014-02-13 23:00:14.000000000 +0100
  32552. +++ linux-3.13.3/drivers/staging/media/lirc/Kconfig 2014-02-17 22:41:01.000000000 +0100
  32553. @@ -38,6 +38,12 @@
  32554. help
  32555. Driver for Homebrew Parallel Port Receivers
  32556. +config LIRC_RPI
  32557. + tristate "Homebrew GPIO Port Receiver/Transmitter for the RaspberryPi"
  32558. + depends on LIRC
  32559. + help
  32560. + Driver for Homebrew GPIO Port Receiver/Transmitter for the RaspberryPi
  32561. +
  32562. config LIRC_SASEM
  32563. tristate "Sasem USB IR Remote"
  32564. depends on LIRC && USB
  32565. diff -Nur linux-3.13.3.orig/drivers/staging/media/lirc/lirc_rpi.c linux-3.13.3/drivers/staging/media/lirc/lirc_rpi.c
  32566. --- linux-3.13.3.orig/drivers/staging/media/lirc/lirc_rpi.c 1970-01-01 01:00:00.000000000 +0100
  32567. +++ linux-3.13.3/drivers/staging/media/lirc/lirc_rpi.c 2014-02-17 22:41:01.000000000 +0100
  32568. @@ -0,0 +1,693 @@
  32569. +/*
  32570. + * lirc_rpi.c
  32571. + *
  32572. + * lirc_rpi - Device driver that records pulse- and pause-lengths
  32573. + * (space-lengths) (just like the lirc_serial driver does)
  32574. + * between GPIO interrupt events on the Raspberry Pi.
  32575. + * Lots of code has been taken from the lirc_serial module,
  32576. + * so I would like say thanks to the authors.
  32577. + *
  32578. + * Copyright (C) 2012 Aron Robert Szabo <aron@reon.hu>,
  32579. + * Michael Bishop <cleverca22@gmail.com>
  32580. + * This program is free software; you can redistribute it and/or modify
  32581. + * it under the terms of the GNU General Public License as published by
  32582. + * the Free Software Foundation; either version 2 of the License, or
  32583. + * (at your option) any later version.
  32584. + *
  32585. + * This program is distributed in the hope that it will be useful,
  32586. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  32587. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  32588. + * GNU General Public License for more details.
  32589. + *
  32590. + * You should have received a copy of the GNU General Public License
  32591. + * along with this program; if not, write to the Free Software
  32592. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  32593. + */
  32594. +
  32595. +#include <linux/module.h>
  32596. +#include <linux/errno.h>
  32597. +#include <linux/interrupt.h>
  32598. +#include <linux/sched.h>
  32599. +#include <linux/kernel.h>
  32600. +#include <linux/time.h>
  32601. +#include <linux/string.h>
  32602. +#include <linux/delay.h>
  32603. +#include <linux/platform_device.h>
  32604. +#include <linux/irq.h>
  32605. +#include <linux/spinlock.h>
  32606. +#include <media/lirc.h>
  32607. +#include <media/lirc_dev.h>
  32608. +#include <linux/gpio.h>
  32609. +
  32610. +#define LIRC_DRIVER_NAME "lirc_rpi"
  32611. +#define RBUF_LEN 256
  32612. +#define LIRC_TRANSMITTER_LATENCY 256
  32613. +
  32614. +#ifndef MAX_UDELAY_MS
  32615. +#define MAX_UDELAY_US 5000
  32616. +#else
  32617. +#define MAX_UDELAY_US (MAX_UDELAY_MS*1000)
  32618. +#endif
  32619. +
  32620. +#define dprintk(fmt, args...) \
  32621. + do { \
  32622. + if (debug) \
  32623. + printk(KERN_DEBUG LIRC_DRIVER_NAME ": " \
  32624. + fmt, ## args); \
  32625. + } while (0)
  32626. +
  32627. +/* module parameters */
  32628. +
  32629. +/* set the default GPIO input pin */
  32630. +static int gpio_in_pin = 18;
  32631. +/* set the default GPIO output pin */
  32632. +static int gpio_out_pin = 17;
  32633. +/* enable debugging messages */
  32634. +static bool debug;
  32635. +/* -1 = auto, 0 = active high, 1 = active low */
  32636. +static int sense = -1;
  32637. +/* use softcarrier by default */
  32638. +static bool softcarrier = 1;
  32639. +/* 0 = do not invert output, 1 = invert output */
  32640. +static bool invert = 0;
  32641. +
  32642. +struct gpio_chip *gpiochip;
  32643. +struct irq_chip *irqchip;
  32644. +struct irq_data *irqdata;
  32645. +
  32646. +/* forward declarations */
  32647. +static long send_pulse(unsigned long length);
  32648. +static void send_space(long length);
  32649. +static void lirc_rpi_exit(void);
  32650. +
  32651. +int valid_gpio_pins[] = { 0, 1, 4, 8, 7, 9, 10, 11, 14, 15, 17, 18, 21, 22, 23,
  32652. + 24, 25 };
  32653. +
  32654. +static struct platform_device *lirc_rpi_dev;
  32655. +static struct timeval lasttv = { 0, 0 };
  32656. +static struct lirc_buffer rbuf;
  32657. +static spinlock_t lock;
  32658. +
  32659. +/* initialized/set in init_timing_params() */
  32660. +static unsigned int freq = 38000;
  32661. +static unsigned int duty_cycle = 50;
  32662. +static unsigned long period;
  32663. +static unsigned long pulse_width;
  32664. +static unsigned long space_width;
  32665. +
  32666. +static void safe_udelay(unsigned long usecs)
  32667. +{
  32668. + while (usecs > MAX_UDELAY_US) {
  32669. + udelay(MAX_UDELAY_US);
  32670. + usecs -= MAX_UDELAY_US;
  32671. + }
  32672. + udelay(usecs);
  32673. +}
  32674. +
  32675. +static int init_timing_params(unsigned int new_duty_cycle,
  32676. + unsigned int new_freq)
  32677. +{
  32678. + /*
  32679. + * period, pulse/space width are kept with 8 binary places -
  32680. + * IE multiplied by 256.
  32681. + */
  32682. + if (256 * 1000000L / new_freq * new_duty_cycle / 100 <=
  32683. + LIRC_TRANSMITTER_LATENCY)
  32684. + return -EINVAL;
  32685. + if (256 * 1000000L / new_freq * (100 - new_duty_cycle) / 100 <=
  32686. + LIRC_TRANSMITTER_LATENCY)
  32687. + return -EINVAL;
  32688. + duty_cycle = new_duty_cycle;
  32689. + freq = new_freq;
  32690. + period = 256 * 1000000L / freq;
  32691. + pulse_width = period * duty_cycle / 100;
  32692. + space_width = period - pulse_width;
  32693. + dprintk("in init_timing_params, freq=%d pulse=%ld, "
  32694. + "space=%ld\n", freq, pulse_width, space_width);
  32695. + return 0;
  32696. +}
  32697. +
  32698. +static long send_pulse_softcarrier(unsigned long length)
  32699. +{
  32700. + int flag;
  32701. + unsigned long actual, target, d;
  32702. +
  32703. + length <<= 8;
  32704. +
  32705. + actual = 0; target = 0; flag = 0;
  32706. + while (actual < length) {
  32707. + if (flag) {
  32708. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  32709. + target += space_width;
  32710. + } else {
  32711. + gpiochip->set(gpiochip, gpio_out_pin, !invert);
  32712. + target += pulse_width;
  32713. + }
  32714. + d = (target - actual -
  32715. + LIRC_TRANSMITTER_LATENCY + 128) >> 8;
  32716. + /*
  32717. + * Note - we've checked in ioctl that the pulse/space
  32718. + * widths are big enough so that d is > 0
  32719. + */
  32720. + udelay(d);
  32721. + actual += (d << 8) + LIRC_TRANSMITTER_LATENCY;
  32722. + flag = !flag;
  32723. + }
  32724. + return (actual-length) >> 8;
  32725. +}
  32726. +
  32727. +static long send_pulse(unsigned long length)
  32728. +{
  32729. + if (length <= 0)
  32730. + return 0;
  32731. +
  32732. + if (softcarrier) {
  32733. + return send_pulse_softcarrier(length);
  32734. + } else {
  32735. + gpiochip->set(gpiochip, gpio_out_pin, !invert);
  32736. + safe_udelay(length);
  32737. + return 0;
  32738. + }
  32739. +}
  32740. +
  32741. +static void send_space(long length)
  32742. +{
  32743. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  32744. + if (length <= 0)
  32745. + return;
  32746. + safe_udelay(length);
  32747. +}
  32748. +
  32749. +static void rbwrite(int l)
  32750. +{
  32751. + if (lirc_buffer_full(&rbuf)) {
  32752. + /* no new signals will be accepted */
  32753. + dprintk("Buffer overrun\n");
  32754. + return;
  32755. + }
  32756. + lirc_buffer_write(&rbuf, (void *)&l);
  32757. +}
  32758. +
  32759. +static void frbwrite(int l)
  32760. +{
  32761. + /* simple noise filter */
  32762. + static int pulse, space;
  32763. + static unsigned int ptr;
  32764. +
  32765. + if (ptr > 0 && (l & PULSE_BIT)) {
  32766. + pulse += l & PULSE_MASK;
  32767. + if (pulse > 250) {
  32768. + rbwrite(space);
  32769. + rbwrite(pulse | PULSE_BIT);
  32770. + ptr = 0;
  32771. + pulse = 0;
  32772. + }
  32773. + return;
  32774. + }
  32775. + if (!(l & PULSE_BIT)) {
  32776. + if (ptr == 0) {
  32777. + if (l > 20000) {
  32778. + space = l;
  32779. + ptr++;
  32780. + return;
  32781. + }
  32782. + } else {
  32783. + if (l > 20000) {
  32784. + space += pulse;
  32785. + if (space > PULSE_MASK)
  32786. + space = PULSE_MASK;
  32787. + space += l;
  32788. + if (space > PULSE_MASK)
  32789. + space = PULSE_MASK;
  32790. + pulse = 0;
  32791. + return;
  32792. + }
  32793. + rbwrite(space);
  32794. + rbwrite(pulse | PULSE_BIT);
  32795. + ptr = 0;
  32796. + pulse = 0;
  32797. + }
  32798. + }
  32799. + rbwrite(l);
  32800. +}
  32801. +
  32802. +static irqreturn_t irq_handler(int i, void *blah, struct pt_regs *regs)
  32803. +{
  32804. + struct timeval tv;
  32805. + long deltv;
  32806. + int data;
  32807. + int signal;
  32808. +
  32809. + /* use the GPIO signal level */
  32810. + signal = gpiochip->get(gpiochip, gpio_in_pin);
  32811. +
  32812. + /* unmask the irq */
  32813. + irqchip->irq_unmask(irqdata);
  32814. +
  32815. + if (sense != -1) {
  32816. + /* get current time */
  32817. + do_gettimeofday(&tv);
  32818. +
  32819. + /* calc time since last interrupt in microseconds */
  32820. + deltv = tv.tv_sec-lasttv.tv_sec;
  32821. + if (tv.tv_sec < lasttv.tv_sec ||
  32822. + (tv.tv_sec == lasttv.tv_sec &&
  32823. + tv.tv_usec < lasttv.tv_usec)) {
  32824. + printk(KERN_WARNING LIRC_DRIVER_NAME
  32825. + ": AIEEEE: your clock just jumped backwards\n");
  32826. + printk(KERN_WARNING LIRC_DRIVER_NAME
  32827. + ": %d %d %lx %lx %lx %lx\n", signal, sense,
  32828. + tv.tv_sec, lasttv.tv_sec,
  32829. + tv.tv_usec, lasttv.tv_usec);
  32830. + data = PULSE_MASK;
  32831. + } else if (deltv > 15) {
  32832. + data = PULSE_MASK; /* really long time */
  32833. + if (!(signal^sense)) {
  32834. + /* sanity check */
  32835. + printk(KERN_WARNING LIRC_DRIVER_NAME
  32836. + ": AIEEEE: %d %d %lx %lx %lx %lx\n",
  32837. + signal, sense, tv.tv_sec, lasttv.tv_sec,
  32838. + tv.tv_usec, lasttv.tv_usec);
  32839. + /*
  32840. + * detecting pulse while this
  32841. + * MUST be a space!
  32842. + */
  32843. + sense = sense ? 0 : 1;
  32844. + }
  32845. + } else {
  32846. + data = (int) (deltv*1000000 +
  32847. + (tv.tv_usec - lasttv.tv_usec));
  32848. + }
  32849. + frbwrite(signal^sense ? data : (data|PULSE_BIT));
  32850. + lasttv = tv;
  32851. + wake_up_interruptible(&rbuf.wait_poll);
  32852. + }
  32853. +
  32854. + return IRQ_HANDLED;
  32855. +}
  32856. +
  32857. +static int is_right_chip(struct gpio_chip *chip, void *data)
  32858. +{
  32859. + dprintk("is_right_chip %s %d\n", chip->label, strcmp(data, chip->label));
  32860. +
  32861. + if (strcmp(data, chip->label) == 0)
  32862. + return 1;
  32863. + return 0;
  32864. +}
  32865. +
  32866. +static int init_port(void)
  32867. +{
  32868. + int i, nlow, nhigh, ret, irq;
  32869. +
  32870. + gpiochip = gpiochip_find("bcm2708_gpio", is_right_chip);
  32871. +
  32872. + if (!gpiochip)
  32873. + return -ENODEV;
  32874. +
  32875. + if (gpio_request(gpio_out_pin, LIRC_DRIVER_NAME " ir/out")) {
  32876. + printk(KERN_ALERT LIRC_DRIVER_NAME
  32877. + ": cant claim gpio pin %d\n", gpio_out_pin);
  32878. + ret = -ENODEV;
  32879. + goto exit_init_port;
  32880. + }
  32881. +
  32882. + if (gpio_request(gpio_in_pin, LIRC_DRIVER_NAME " ir/in")) {
  32883. + printk(KERN_ALERT LIRC_DRIVER_NAME
  32884. + ": cant claim gpio pin %d\n", gpio_in_pin);
  32885. + ret = -ENODEV;
  32886. + goto exit_gpio_free_out_pin;
  32887. + }
  32888. +
  32889. + gpiochip->direction_input(gpiochip, gpio_in_pin);
  32890. + gpiochip->direction_output(gpiochip, gpio_out_pin, 1);
  32891. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  32892. +
  32893. + irq = gpiochip->to_irq(gpiochip, gpio_in_pin);
  32894. + dprintk("to_irq %d\n", irq);
  32895. + irqdata = irq_get_irq_data(irq);
  32896. +
  32897. + if (irqdata && irqdata->chip) {
  32898. + irqchip = irqdata->chip;
  32899. + } else {
  32900. + ret = -ENODEV;
  32901. + goto exit_gpio_free_in_pin;
  32902. + }
  32903. +
  32904. + /* if pin is high, then this must be an active low receiver. */
  32905. + if (sense == -1) {
  32906. + /* wait 1/2 sec for the power supply */
  32907. + msleep(500);
  32908. +
  32909. + /*
  32910. + * probe 9 times every 0.04s, collect "votes" for
  32911. + * active high/low
  32912. + */
  32913. + nlow = 0;
  32914. + nhigh = 0;
  32915. + for (i = 0; i < 9; i++) {
  32916. + if (gpiochip->get(gpiochip, gpio_in_pin))
  32917. + nlow++;
  32918. + else
  32919. + nhigh++;
  32920. + msleep(40);
  32921. + }
  32922. + sense = (nlow >= nhigh ? 1 : 0);
  32923. + printk(KERN_INFO LIRC_DRIVER_NAME
  32924. + ": auto-detected active %s receiver on GPIO pin %d\n",
  32925. + sense ? "low" : "high", gpio_in_pin);
  32926. + } else {
  32927. + printk(KERN_INFO LIRC_DRIVER_NAME
  32928. + ": manually using active %s receiver on GPIO pin %d\n",
  32929. + sense ? "low" : "high", gpio_in_pin);
  32930. + }
  32931. +
  32932. + return 0;
  32933. +
  32934. + exit_gpio_free_in_pin:
  32935. + gpio_free(gpio_in_pin);
  32936. +
  32937. + exit_gpio_free_out_pin:
  32938. + gpio_free(gpio_out_pin);
  32939. +
  32940. + exit_init_port:
  32941. + return ret;
  32942. +}
  32943. +
  32944. +// called when the character device is opened
  32945. +static int set_use_inc(void *data)
  32946. +{
  32947. + int result;
  32948. + unsigned long flags;
  32949. +
  32950. + /* initialize timestamp */
  32951. + do_gettimeofday(&lasttv);
  32952. +
  32953. + result = request_irq(gpiochip->to_irq(gpiochip, gpio_in_pin),
  32954. + (irq_handler_t) irq_handler, 0,
  32955. + LIRC_DRIVER_NAME, (void*) 0);
  32956. +
  32957. + switch (result) {
  32958. + case -EBUSY:
  32959. + printk(KERN_ERR LIRC_DRIVER_NAME
  32960. + ": IRQ %d is busy\n",
  32961. + gpiochip->to_irq(gpiochip, gpio_in_pin));
  32962. + return -EBUSY;
  32963. + case -EINVAL:
  32964. + printk(KERN_ERR LIRC_DRIVER_NAME
  32965. + ": Bad irq number or handler\n");
  32966. + return -EINVAL;
  32967. + default:
  32968. + dprintk("Interrupt %d obtained\n",
  32969. + gpiochip->to_irq(gpiochip, gpio_in_pin));
  32970. + break;
  32971. + };
  32972. +
  32973. + /* initialize pulse/space widths */
  32974. + init_timing_params(duty_cycle, freq);
  32975. +
  32976. + spin_lock_irqsave(&lock, flags);
  32977. +
  32978. + /* GPIO Pin Falling/Rising Edge Detect Enable */
  32979. + irqchip->irq_set_type(irqdata,
  32980. + IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING);
  32981. +
  32982. + /* unmask the irq */
  32983. + irqchip->irq_unmask(irqdata);
  32984. +
  32985. + spin_unlock_irqrestore(&lock, flags);
  32986. +
  32987. + return 0;
  32988. +}
  32989. +
  32990. +static void set_use_dec(void *data)
  32991. +{
  32992. + unsigned long flags;
  32993. +
  32994. + spin_lock_irqsave(&lock, flags);
  32995. +
  32996. + /* GPIO Pin Falling/Rising Edge Detect Disable */
  32997. + irqchip->irq_set_type(irqdata, 0);
  32998. + irqchip->irq_mask(irqdata);
  32999. +
  33000. + spin_unlock_irqrestore(&lock, flags);
  33001. +
  33002. + free_irq(gpiochip->to_irq(gpiochip, gpio_in_pin), (void *) 0);
  33003. +
  33004. + dprintk(KERN_INFO LIRC_DRIVER_NAME
  33005. + ": freed IRQ %d\n", gpiochip->to_irq(gpiochip, gpio_in_pin));
  33006. +}
  33007. +
  33008. +static ssize_t lirc_write(struct file *file, const char *buf,
  33009. + size_t n, loff_t *ppos)
  33010. +{
  33011. + int i, count;
  33012. + unsigned long flags;
  33013. + long delta = 0;
  33014. + int *wbuf;
  33015. +
  33016. + count = n / sizeof(int);
  33017. + if (n % sizeof(int) || count % 2 == 0)
  33018. + return -EINVAL;
  33019. + wbuf = memdup_user(buf, n);
  33020. + if (IS_ERR(wbuf))
  33021. + return PTR_ERR(wbuf);
  33022. + spin_lock_irqsave(&lock, flags);
  33023. +
  33024. + for (i = 0; i < count; i++) {
  33025. + if (i%2)
  33026. + send_space(wbuf[i] - delta);
  33027. + else
  33028. + delta = send_pulse(wbuf[i]);
  33029. + }
  33030. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  33031. +
  33032. + spin_unlock_irqrestore(&lock, flags);
  33033. + kfree(wbuf);
  33034. + return n;
  33035. +}
  33036. +
  33037. +static long lirc_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
  33038. +{
  33039. + int result;
  33040. + __u32 value;
  33041. +
  33042. + switch (cmd) {
  33043. + case LIRC_GET_SEND_MODE:
  33044. + return -ENOIOCTLCMD;
  33045. + break;
  33046. +
  33047. + case LIRC_SET_SEND_MODE:
  33048. + result = get_user(value, (__u32 *) arg);
  33049. + if (result)
  33050. + return result;
  33051. + /* only LIRC_MODE_PULSE supported */
  33052. + if (value != LIRC_MODE_PULSE)
  33053. + return -ENOSYS;
  33054. + break;
  33055. +
  33056. + case LIRC_GET_LENGTH:
  33057. + return -ENOSYS;
  33058. + break;
  33059. +
  33060. + case LIRC_SET_SEND_DUTY_CYCLE:
  33061. + dprintk("SET_SEND_DUTY_CYCLE\n");
  33062. + result = get_user(value, (__u32 *) arg);
  33063. + if (result)
  33064. + return result;
  33065. + if (value <= 0 || value > 100)
  33066. + return -EINVAL;
  33067. + return init_timing_params(value, freq);
  33068. + break;
  33069. +
  33070. + case LIRC_SET_SEND_CARRIER:
  33071. + dprintk("SET_SEND_CARRIER\n");
  33072. + result = get_user(value, (__u32 *) arg);
  33073. + if (result)
  33074. + return result;
  33075. + if (value > 500000 || value < 20000)
  33076. + return -EINVAL;
  33077. + return init_timing_params(duty_cycle, value);
  33078. + break;
  33079. +
  33080. + default:
  33081. + return lirc_dev_fop_ioctl(filep, cmd, arg);
  33082. + }
  33083. + return 0;
  33084. +}
  33085. +
  33086. +static const struct file_operations lirc_fops = {
  33087. + .owner = THIS_MODULE,
  33088. + .write = lirc_write,
  33089. + .unlocked_ioctl = lirc_ioctl,
  33090. + .read = lirc_dev_fop_read,
  33091. + .poll = lirc_dev_fop_poll,
  33092. + .open = lirc_dev_fop_open,
  33093. + .release = lirc_dev_fop_close,
  33094. + .llseek = no_llseek,
  33095. +};
  33096. +
  33097. +static struct lirc_driver driver = {
  33098. + .name = LIRC_DRIVER_NAME,
  33099. + .minor = -1,
  33100. + .code_length = 1,
  33101. + .sample_rate = 0,
  33102. + .data = NULL,
  33103. + .add_to_buf = NULL,
  33104. + .rbuf = &rbuf,
  33105. + .set_use_inc = set_use_inc,
  33106. + .set_use_dec = set_use_dec,
  33107. + .fops = &lirc_fops,
  33108. + .dev = NULL,
  33109. + .owner = THIS_MODULE,
  33110. +};
  33111. +
  33112. +static struct platform_driver lirc_rpi_driver = {
  33113. + .driver = {
  33114. + .name = LIRC_DRIVER_NAME,
  33115. + .owner = THIS_MODULE,
  33116. + },
  33117. +};
  33118. +
  33119. +static int __init lirc_rpi_init(void)
  33120. +{
  33121. + int result;
  33122. +
  33123. + /* Init read buffer. */
  33124. + result = lirc_buffer_init(&rbuf, sizeof(int), RBUF_LEN);
  33125. + if (result < 0)
  33126. + return -ENOMEM;
  33127. +
  33128. + result = platform_driver_register(&lirc_rpi_driver);
  33129. + if (result) {
  33130. + printk(KERN_ERR LIRC_DRIVER_NAME
  33131. + ": lirc register returned %d\n", result);
  33132. + goto exit_buffer_free;
  33133. + }
  33134. +
  33135. + lirc_rpi_dev = platform_device_alloc(LIRC_DRIVER_NAME, 0);
  33136. + if (!lirc_rpi_dev) {
  33137. + result = -ENOMEM;
  33138. + goto exit_driver_unregister;
  33139. + }
  33140. +
  33141. + result = platform_device_add(lirc_rpi_dev);
  33142. + if (result)
  33143. + goto exit_device_put;
  33144. +
  33145. + return 0;
  33146. +
  33147. + exit_device_put:
  33148. + platform_device_put(lirc_rpi_dev);
  33149. +
  33150. + exit_driver_unregister:
  33151. + platform_driver_unregister(&lirc_rpi_driver);
  33152. +
  33153. + exit_buffer_free:
  33154. + lirc_buffer_free(&rbuf);
  33155. +
  33156. + return result;
  33157. +}
  33158. +
  33159. +static void lirc_rpi_exit(void)
  33160. +{
  33161. + platform_device_unregister(lirc_rpi_dev);
  33162. + platform_driver_unregister(&lirc_rpi_driver);
  33163. + lirc_buffer_free(&rbuf);
  33164. +}
  33165. +
  33166. +static int __init lirc_rpi_init_module(void)
  33167. +{
  33168. + int result, i;
  33169. +
  33170. + result = lirc_rpi_init();
  33171. + if (result)
  33172. + return result;
  33173. +
  33174. + /* check if the module received valid gpio pin numbers */
  33175. + result = 0;
  33176. + if (gpio_in_pin != gpio_out_pin) {
  33177. + for(i = 0; (i < ARRAY_SIZE(valid_gpio_pins)) && (result != 2); i++) {
  33178. + if (gpio_in_pin == valid_gpio_pins[i] ||
  33179. + gpio_out_pin == valid_gpio_pins[i]) {
  33180. + result++;
  33181. + }
  33182. + }
  33183. + }
  33184. +
  33185. + if (result != 2) {
  33186. + result = -EINVAL;
  33187. + printk(KERN_ERR LIRC_DRIVER_NAME
  33188. + ": invalid GPIO pin(s) specified!\n");
  33189. + goto exit_rpi;
  33190. + }
  33191. +
  33192. + result = init_port();
  33193. + if (result < 0)
  33194. + goto exit_rpi;
  33195. +
  33196. + driver.features = LIRC_CAN_SET_SEND_DUTY_CYCLE |
  33197. + LIRC_CAN_SET_SEND_CARRIER |
  33198. + LIRC_CAN_SEND_PULSE |
  33199. + LIRC_CAN_REC_MODE2;
  33200. +
  33201. + driver.dev = &lirc_rpi_dev->dev;
  33202. + driver.minor = lirc_register_driver(&driver);
  33203. +
  33204. + if (driver.minor < 0) {
  33205. + printk(KERN_ERR LIRC_DRIVER_NAME
  33206. + ": device registration failed with %d\n", result);
  33207. + result = -EIO;
  33208. + goto exit_rpi;
  33209. + }
  33210. +
  33211. + printk(KERN_INFO LIRC_DRIVER_NAME ": driver registered!\n");
  33212. +
  33213. + return 0;
  33214. +
  33215. + exit_rpi:
  33216. + lirc_rpi_exit();
  33217. +
  33218. + return result;
  33219. +}
  33220. +
  33221. +static void __exit lirc_rpi_exit_module(void)
  33222. +{
  33223. + gpio_free(gpio_out_pin);
  33224. + gpio_free(gpio_in_pin);
  33225. +
  33226. + lirc_rpi_exit();
  33227. +
  33228. + lirc_unregister_driver(driver.minor);
  33229. + printk(KERN_INFO LIRC_DRIVER_NAME ": cleaned up module\n");
  33230. +}
  33231. +
  33232. +module_init(lirc_rpi_init_module);
  33233. +module_exit(lirc_rpi_exit_module);
  33234. +
  33235. +MODULE_DESCRIPTION("Infra-red receiver and blaster driver for Raspberry Pi GPIO.");
  33236. +MODULE_AUTHOR("Aron Robert Szabo <aron@reon.hu>");
  33237. +MODULE_AUTHOR("Michael Bishop <cleverca22@gmail.com>");
  33238. +MODULE_LICENSE("GPL");
  33239. +
  33240. +module_param(gpio_out_pin, int, S_IRUGO);
  33241. +MODULE_PARM_DESC(gpio_out_pin, "GPIO output/transmitter pin number of the BCM"
  33242. + " processor. Valid pin numbers are: 0, 1, 4, 8, 7, 9, 10, 11,"
  33243. + " 14, 15, 17, 18, 21, 22, 23, 24, 25, default 17");
  33244. +
  33245. +module_param(gpio_in_pin, int, S_IRUGO);
  33246. +MODULE_PARM_DESC(gpio_in_pin, "GPIO input pin number of the BCM processor."
  33247. + " Valid pin numbers are: 0, 1, 4, 8, 7, 9, 10, 11, 14, 15,"
  33248. + " 17, 18, 21, 22, 23, 24, 25, default 18");
  33249. +
  33250. +module_param(sense, int, S_IRUGO);
  33251. +MODULE_PARM_DESC(sense, "Override autodetection of IR receiver circuit"
  33252. + " (0 = active high, 1 = active low )");
  33253. +
  33254. +module_param(softcarrier, bool, S_IRUGO);
  33255. +MODULE_PARM_DESC(softcarrier, "Software carrier (0 = off, 1 = on, default on)");
  33256. +
  33257. +module_param(invert, bool, S_IRUGO);
  33258. +MODULE_PARM_DESC(invert, "Invert output (0 = off, 1 = on, default off");
  33259. +
  33260. +module_param(debug, bool, S_IRUGO | S_IWUSR);
  33261. +MODULE_PARM_DESC(debug, "Enable debugging messages");
  33262. diff -Nur linux-3.13.3.orig/drivers/staging/media/lirc/Makefile linux-3.13.3/drivers/staging/media/lirc/Makefile
  33263. --- linux-3.13.3.orig/drivers/staging/media/lirc/Makefile 2014-02-13 23:00:14.000000000 +0100
  33264. +++ linux-3.13.3/drivers/staging/media/lirc/Makefile 2014-02-17 22:41:01.000000000 +0100
  33265. @@ -7,6 +7,7 @@
  33266. obj-$(CONFIG_LIRC_IGORPLUGUSB) += lirc_igorplugusb.o
  33267. obj-$(CONFIG_LIRC_IMON) += lirc_imon.o
  33268. obj-$(CONFIG_LIRC_PARALLEL) += lirc_parallel.o
  33269. +obj-$(CONFIG_LIRC_RPI) += lirc_rpi.o
  33270. obj-$(CONFIG_LIRC_SASEM) += lirc_sasem.o
  33271. obj-$(CONFIG_LIRC_SERIAL) += lirc_serial.o
  33272. obj-$(CONFIG_LIRC_SIR) += lirc_sir.o
  33273. diff -Nur linux-3.13.3.orig/drivers/thermal/bcm2835-thermal.c linux-3.13.3/drivers/thermal/bcm2835-thermal.c
  33274. --- linux-3.13.3.orig/drivers/thermal/bcm2835-thermal.c 1970-01-01 01:00:00.000000000 +0100
  33275. +++ linux-3.13.3/drivers/thermal/bcm2835-thermal.c 2014-02-17 22:41:01.000000000 +0100
  33276. @@ -0,0 +1,184 @@
  33277. +/*****************************************************************************
  33278. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  33279. +*
  33280. +* Unless you and Broadcom execute a separate written software license
  33281. +* agreement governing use of this software, this software is licensed to you
  33282. +* under the terms of the GNU General Public License version 2, available at
  33283. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  33284. +*
  33285. +* Notwithstanding the above, under no circumstances may you combine this
  33286. +* software in any way with any other Broadcom software provided under a
  33287. +* license other than the GPL, without Broadcom's express prior written
  33288. +* consent.
  33289. +*****************************************************************************/
  33290. +
  33291. +#include <linux/kernel.h>
  33292. +#include <linux/module.h>
  33293. +#include <linux/init.h>
  33294. +#include <linux/platform_device.h>
  33295. +#include <linux/slab.h>
  33296. +#include <linux/sysfs.h>
  33297. +#include <mach/vcio.h>
  33298. +#include <linux/thermal.h>
  33299. +
  33300. +
  33301. +/* --- DEFINITIONS --- */
  33302. +#define MODULE_NAME "bcm2835_thermal"
  33303. +
  33304. +/*#define THERMAL_DEBUG_ENABLE*/
  33305. +
  33306. +#ifdef THERMAL_DEBUG_ENABLE
  33307. +#define print_debug(fmt,...) printk(KERN_INFO "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  33308. +#else
  33309. +#define print_debug(fmt,...)
  33310. +#endif
  33311. +#define print_err(fmt,...) printk(KERN_ERR "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__,__LINE__, ##__VA_ARGS__)
  33312. +
  33313. +#define VC_TAG_GET_TEMP 0x00030006
  33314. +#define VC_TAG_GET_MAX_TEMP 0x0003000A
  33315. +
  33316. +typedef enum {
  33317. + TEMP,
  33318. + MAX_TEMP,
  33319. +} temp_type;
  33320. +
  33321. +/* --- STRUCTS --- */
  33322. +/* tag part of the message */
  33323. +struct vc_msg_tag {
  33324. + uint32_t tag_id; /* the tag ID for the temperature */
  33325. + uint32_t buffer_size; /* size of the buffer (should be 8) */
  33326. + uint32_t request_code; /* identifies message as a request (should be 0) */
  33327. + uint32_t id; /* extra ID field (should be 0) */
  33328. + uint32_t val; /* returned value of the temperature */
  33329. +};
  33330. +
  33331. +/* message structure to be sent to videocore */
  33332. +struct vc_msg {
  33333. + uint32_t msg_size; /* simply, sizeof(struct vc_msg) */
  33334. + uint32_t request_code; /* holds various information like the success and number of bytes returned (refer to mailboxes wiki) */
  33335. + struct vc_msg_tag tag; /* the tag structure above to make */
  33336. + uint32_t end_tag; /* an end identifier, should be set to NULL */
  33337. +};
  33338. +
  33339. +struct bcm2835_thermal_data {
  33340. + struct thermal_zone_device *thermal_dev;
  33341. + struct vc_msg msg;
  33342. +};
  33343. +
  33344. +/* --- GLOBALS --- */
  33345. +static struct bcm2835_thermal_data bcm2835_data;
  33346. +
  33347. +/* Thermal Device Operations */
  33348. +static struct thermal_zone_device_ops ops;
  33349. +
  33350. +/* --- FUNCTIONS --- */
  33351. +
  33352. +static int bcm2835_get_temp_or_max(struct thermal_zone_device *thermal_dev, unsigned long *temp, unsigned tag_id)
  33353. +{
  33354. + int result = -1, retry = 3;
  33355. + print_debug("IN");
  33356. +
  33357. + *temp = 0;
  33358. + while (result != 0 && retry-- > 0) {
  33359. + /* wipe all previous message data */
  33360. + memset(&bcm2835_data.msg, 0, sizeof bcm2835_data.msg);
  33361. +
  33362. + /* prepare message */
  33363. + bcm2835_data.msg.msg_size = sizeof bcm2835_data.msg;
  33364. + bcm2835_data.msg.tag.buffer_size = 8;
  33365. + bcm2835_data.msg.tag.tag_id = tag_id;
  33366. +
  33367. + /* send the message */
  33368. + result = bcm_mailbox_property(&bcm2835_data.msg, sizeof bcm2835_data.msg);
  33369. + 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);
  33370. + if (!(bcm2835_data.msg.request_code & 0x80000000))
  33371. + result = -1;
  33372. + }
  33373. +
  33374. + /* check if it was all ok and return the rate in milli degrees C */
  33375. + if (result == 0)
  33376. + *temp = (uint)bcm2835_data.msg.tag.val;
  33377. + else
  33378. + print_err("Failed to get temperature! (%x:%d)\n", tag_id, result);
  33379. + print_debug("OUT");
  33380. + return result;
  33381. +}
  33382. +
  33383. +static int bcm2835_get_temp(struct thermal_zone_device *thermal_dev, unsigned long *temp)
  33384. +{
  33385. + return bcm2835_get_temp_or_max(thermal_dev, temp, VC_TAG_GET_TEMP);
  33386. +}
  33387. +
  33388. +static int bcm2835_get_max_temp(struct thermal_zone_device *thermal_dev, int trip_num, unsigned long *temp)
  33389. +{
  33390. + return bcm2835_get_temp_or_max(thermal_dev, temp, VC_TAG_GET_MAX_TEMP);
  33391. +}
  33392. +
  33393. +static int bcm2835_get_trip_type(struct thermal_zone_device * thermal_dev, int trip_num, enum thermal_trip_type *trip_type)
  33394. +{
  33395. + *trip_type = THERMAL_TRIP_HOT;
  33396. + return 0;
  33397. +}
  33398. +
  33399. +
  33400. +static int bcm2835_get_mode(struct thermal_zone_device *thermal_dev, enum thermal_device_mode *dev_mode)
  33401. +{
  33402. + *dev_mode = THERMAL_DEVICE_ENABLED;
  33403. + return 0;
  33404. +}
  33405. +
  33406. +
  33407. +static int bcm2835_thermal_probe(struct platform_device *pdev)
  33408. +{
  33409. + print_debug("IN");
  33410. + print_debug("THERMAL Driver has been probed!");
  33411. +
  33412. + /* check that the device isn't null!*/
  33413. + if(pdev == NULL)
  33414. + {
  33415. + print_debug("Platform device is empty!");
  33416. + return -ENODEV;
  33417. + }
  33418. +
  33419. + if(!(bcm2835_data.thermal_dev = thermal_zone_device_register("bcm2835_thermal", 1, 0, NULL, &ops, NULL, 0, 0)))
  33420. + {
  33421. + print_debug("Unable to register the thermal device!");
  33422. + return -EFAULT;
  33423. + }
  33424. + return 0;
  33425. +}
  33426. +
  33427. +
  33428. +static int bcm2835_thermal_remove(struct platform_device *pdev)
  33429. +{
  33430. + print_debug("IN");
  33431. +
  33432. + thermal_zone_device_unregister(bcm2835_data.thermal_dev);
  33433. +
  33434. + print_debug("OUT");
  33435. +
  33436. + return 0;
  33437. +}
  33438. +
  33439. +static struct thermal_zone_device_ops ops = {
  33440. + .get_temp = bcm2835_get_temp,
  33441. + .get_trip_temp = bcm2835_get_max_temp,
  33442. + .get_trip_type = bcm2835_get_trip_type,
  33443. + .get_mode = bcm2835_get_mode,
  33444. +};
  33445. +
  33446. +/* Thermal Driver */
  33447. +static struct platform_driver bcm2835_thermal_driver = {
  33448. + .probe = bcm2835_thermal_probe,
  33449. + .remove = bcm2835_thermal_remove,
  33450. + .driver = {
  33451. + .name = "bcm2835_thermal",
  33452. + .owner = THIS_MODULE,
  33453. + },
  33454. +};
  33455. +
  33456. +MODULE_LICENSE("GPL");
  33457. +MODULE_AUTHOR("Dorian Peake");
  33458. +MODULE_DESCRIPTION("Thermal driver for bcm2835 chip");
  33459. +
  33460. +module_platform_driver(bcm2835_thermal_driver);
  33461. diff -Nur linux-3.13.3.orig/drivers/thermal/Kconfig linux-3.13.3/drivers/thermal/Kconfig
  33462. --- linux-3.13.3.orig/drivers/thermal/Kconfig 2014-02-13 23:00:14.000000000 +0100
  33463. +++ linux-3.13.3/drivers/thermal/Kconfig 2014-02-17 22:41:01.000000000 +0100
  33464. @@ -181,6 +181,12 @@
  33465. enforce idle time which results in more package C-state residency. The
  33466. user interface is exposed via generic thermal framework.
  33467. +config THERMAL_BCM2835
  33468. + tristate "BCM2835 Thermal Driver"
  33469. + help
  33470. + This will enable temperature monitoring for the Broadcom BCM2835
  33471. + chip. If built as a module, it will be called 'bcm2835-thermal'.
  33472. +
  33473. config X86_PKG_TEMP_THERMAL
  33474. tristate "X86 package temperature thermal driver"
  33475. depends on X86_THERMAL_VECTOR
  33476. diff -Nur linux-3.13.3.orig/drivers/thermal/Makefile linux-3.13.3/drivers/thermal/Makefile
  33477. --- linux-3.13.3.orig/drivers/thermal/Makefile 2014-02-13 23:00:14.000000000 +0100
  33478. +++ linux-3.13.3/drivers/thermal/Makefile 2014-02-17 22:41:01.000000000 +0100
  33479. @@ -27,5 +27,6 @@
  33480. obj-$(CONFIG_IMX_THERMAL) += imx_thermal.o
  33481. obj-$(CONFIG_DB8500_CPUFREQ_COOLING) += db8500_cpufreq_cooling.o
  33482. obj-$(CONFIG_INTEL_POWERCLAMP) += intel_powerclamp.o
  33483. +obj-$(CONFIG_THERMAL_BCM2835) += bcm2835-thermal.o
  33484. obj-$(CONFIG_X86_PKG_TEMP_THERMAL) += x86_pkg_temp_thermal.o
  33485. obj-$(CONFIG_TI_SOC_THERMAL) += ti-soc-thermal/
  33486. diff -Nur linux-3.13.3.orig/drivers/tty/serial/amba-pl011.c linux-3.13.3/drivers/tty/serial/amba-pl011.c
  33487. --- linux-3.13.3.orig/drivers/tty/serial/amba-pl011.c 2014-02-13 23:00:14.000000000 +0100
  33488. +++ linux-3.13.3/drivers/tty/serial/amba-pl011.c 2014-02-17 22:41:01.000000000 +0100
  33489. @@ -84,7 +84,7 @@
  33490. static unsigned int get_fifosize_arm(struct amba_device *dev)
  33491. {
  33492. - return amba_rev(dev) < 3 ? 16 : 32;
  33493. + return 16; //TODO: fix: amba_rev(dev) < 3 ? 16 : 32;
  33494. }
  33495. static struct vendor_data vendor_arm = {
  33496. diff -Nur linux-3.13.3.orig/drivers/usb/core/generic.c linux-3.13.3/drivers/usb/core/generic.c
  33497. --- linux-3.13.3.orig/drivers/usb/core/generic.c 2014-02-13 23:00:14.000000000 +0100
  33498. +++ linux-3.13.3/drivers/usb/core/generic.c 2014-02-17 22:41:01.000000000 +0100
  33499. @@ -152,6 +152,7 @@
  33500. dev_warn(&udev->dev,
  33501. "no configuration chosen from %d choice%s\n",
  33502. num_configs, plural(num_configs));
  33503. + dev_warn(&udev->dev, "No support over %dmA\n", udev->bus_mA);
  33504. }
  33505. return i;
  33506. }
  33507. diff -Nur linux-3.13.3.orig/drivers/usb/core/message.c linux-3.13.3/drivers/usb/core/message.c
  33508. --- linux-3.13.3.orig/drivers/usb/core/message.c 2014-02-13 23:00:14.000000000 +0100
  33509. +++ linux-3.13.3/drivers/usb/core/message.c 2014-02-17 22:41:01.000000000 +0100
  33510. @@ -1889,6 +1889,85 @@
  33511. if (cp->string == NULL &&
  33512. !(dev->quirks & USB_QUIRK_CONFIG_INTF_STRINGS))
  33513. cp->string = usb_cache_string(dev, cp->desc.iConfiguration);
  33514. +/* Uncomment this define to enable the HS Electrical Test support */
  33515. +#define DWC_HS_ELECT_TST 1
  33516. +#ifdef DWC_HS_ELECT_TST
  33517. + /* Here we implement the HS Electrical Test support. The
  33518. + * tester uses a vendor ID of 0x1A0A to indicate we should
  33519. + * run a special test sequence. The product ID tells us
  33520. + * which sequence to run. We invoke the test sequence by
  33521. + * sending a non-standard SetFeature command to our root
  33522. + * hub port. Our dwc_otg_hcd_hub_control() routine will
  33523. + * recognize the command and perform the desired test
  33524. + * sequence.
  33525. + */
  33526. + if (dev->descriptor.idVendor == 0x1A0A) {
  33527. + /* HSOTG Electrical Test */
  33528. + dev_warn(&dev->dev, "VID from HSOTG Electrical Test Fixture\n");
  33529. +
  33530. + if (dev->bus && dev->bus->root_hub) {
  33531. + struct usb_device *hdev = dev->bus->root_hub;
  33532. + dev_warn(&dev->dev, "Got PID 0x%x\n", dev->descriptor.idProduct);
  33533. +
  33534. + switch (dev->descriptor.idProduct) {
  33535. + case 0x0101: /* TEST_SE0_NAK */
  33536. + dev_warn(&dev->dev, "TEST_SE0_NAK\n");
  33537. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  33538. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  33539. + USB_PORT_FEAT_TEST, 0x300, NULL, 0, HZ);
  33540. + break;
  33541. +
  33542. + case 0x0102: /* TEST_J */
  33543. + dev_warn(&dev->dev, "TEST_J\n");
  33544. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  33545. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  33546. + USB_PORT_FEAT_TEST, 0x100, NULL, 0, HZ);
  33547. + break;
  33548. +
  33549. + case 0x0103: /* TEST_K */
  33550. + dev_warn(&dev->dev, "TEST_K\n");
  33551. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  33552. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  33553. + USB_PORT_FEAT_TEST, 0x200, NULL, 0, HZ);
  33554. + break;
  33555. +
  33556. + case 0x0104: /* TEST_PACKET */
  33557. + dev_warn(&dev->dev, "TEST_PACKET\n");
  33558. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  33559. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  33560. + USB_PORT_FEAT_TEST, 0x400, NULL, 0, HZ);
  33561. + break;
  33562. +
  33563. + case 0x0105: /* TEST_FORCE_ENABLE */
  33564. + dev_warn(&dev->dev, "TEST_FORCE_ENABLE\n");
  33565. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  33566. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  33567. + USB_PORT_FEAT_TEST, 0x500, NULL, 0, HZ);
  33568. + break;
  33569. +
  33570. + case 0x0106: /* HS_HOST_PORT_SUSPEND_RESUME */
  33571. + dev_warn(&dev->dev, "HS_HOST_PORT_SUSPEND_RESUME\n");
  33572. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  33573. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  33574. + USB_PORT_FEAT_TEST, 0x600, NULL, 0, 40 * HZ);
  33575. + break;
  33576. +
  33577. + case 0x0107: /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup */
  33578. + dev_warn(&dev->dev, "SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup\n");
  33579. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  33580. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  33581. + USB_PORT_FEAT_TEST, 0x700, NULL, 0, 40 * HZ);
  33582. + break;
  33583. +
  33584. + case 0x0108: /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute */
  33585. + dev_warn(&dev->dev, "SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute\n");
  33586. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  33587. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  33588. + USB_PORT_FEAT_TEST, 0x800, NULL, 0, 40 * HZ);
  33589. + }
  33590. + }
  33591. + }
  33592. +#endif /* DWC_HS_ELECT_TST */
  33593. /* Now that the interfaces are installed, re-enable LPM. */
  33594. usb_unlocked_enable_lpm(dev);
  33595. diff -Nur linux-3.13.3.orig/drivers/usb/core/otg_whitelist.h linux-3.13.3/drivers/usb/core/otg_whitelist.h
  33596. --- linux-3.13.3.orig/drivers/usb/core/otg_whitelist.h 2014-02-13 23:00:14.000000000 +0100
  33597. +++ linux-3.13.3/drivers/usb/core/otg_whitelist.h 2014-02-17 22:41:01.000000000 +0100
  33598. @@ -19,33 +19,82 @@
  33599. static struct usb_device_id whitelist_table [] = {
  33600. /* hubs are optional in OTG, but very handy ... */
  33601. +#define CERT_WITHOUT_HUBS
  33602. +#if defined(CERT_WITHOUT_HUBS)
  33603. +{ USB_DEVICE( 0x0000, 0x0000 ), }, /* Root HUB Only*/
  33604. +#else
  33605. { USB_DEVICE_INFO(USB_CLASS_HUB, 0, 0), },
  33606. { USB_DEVICE_INFO(USB_CLASS_HUB, 0, 1), },
  33607. +{ USB_DEVICE_INFO(USB_CLASS_HUB, 0, 2), },
  33608. +#endif
  33609. #ifdef CONFIG_USB_PRINTER /* ignoring nonstatic linkage! */
  33610. /* FIXME actually, printers are NOT supposed to use device classes;
  33611. * they're supposed to use interface classes...
  33612. */
  33613. -{ USB_DEVICE_INFO(7, 1, 1) },
  33614. -{ USB_DEVICE_INFO(7, 1, 2) },
  33615. -{ USB_DEVICE_INFO(7, 1, 3) },
  33616. +//{ USB_DEVICE_INFO(7, 1, 1) },
  33617. +//{ USB_DEVICE_INFO(7, 1, 2) },
  33618. +//{ USB_DEVICE_INFO(7, 1, 3) },
  33619. #endif
  33620. #ifdef CONFIG_USB_NET_CDCETHER
  33621. /* Linux-USB CDC Ethernet gadget */
  33622. -{ USB_DEVICE(0x0525, 0xa4a1), },
  33623. +//{ USB_DEVICE(0x0525, 0xa4a1), },
  33624. /* Linux-USB CDC Ethernet + RNDIS gadget */
  33625. -{ USB_DEVICE(0x0525, 0xa4a2), },
  33626. +//{ USB_DEVICE(0x0525, 0xa4a2), },
  33627. #endif
  33628. #if defined(CONFIG_USB_TEST) || defined(CONFIG_USB_TEST_MODULE)
  33629. /* gadget zero, for testing */
  33630. -{ USB_DEVICE(0x0525, 0xa4a0), },
  33631. +//{ USB_DEVICE(0x0525, 0xa4a0), },
  33632. #endif
  33633. +/* OPT Tester */
  33634. +{ USB_DEVICE( 0x1a0a, 0x0101 ), }, /* TEST_SE0_NAK */
  33635. +{ USB_DEVICE( 0x1a0a, 0x0102 ), }, /* Test_J */
  33636. +{ USB_DEVICE( 0x1a0a, 0x0103 ), }, /* Test_K */
  33637. +{ USB_DEVICE( 0x1a0a, 0x0104 ), }, /* Test_PACKET */
  33638. +{ USB_DEVICE( 0x1a0a, 0x0105 ), }, /* Test_FORCE_ENABLE */
  33639. +{ USB_DEVICE( 0x1a0a, 0x0106 ), }, /* HS_PORT_SUSPEND_RESUME */
  33640. +{ USB_DEVICE( 0x1a0a, 0x0107 ), }, /* SINGLE_STEP_GET_DESCRIPTOR setup */
  33641. +{ USB_DEVICE( 0x1a0a, 0x0108 ), }, /* SINGLE_STEP_GET_DESCRIPTOR execute */
  33642. +
  33643. +/* Sony cameras */
  33644. +{ USB_DEVICE_VER(0x054c,0x0010,0x0410, 0x0500), },
  33645. +
  33646. +/* Memory Devices */
  33647. +//{ USB_DEVICE( 0x0781, 0x5150 ), }, /* SanDisk */
  33648. +//{ USB_DEVICE( 0x05DC, 0x0080 ), }, /* Lexar */
  33649. +//{ USB_DEVICE( 0x4146, 0x9281 ), }, /* IOMEGA */
  33650. +//{ USB_DEVICE( 0x067b, 0x2507 ), }, /* Hammer 20GB External HD */
  33651. +{ USB_DEVICE( 0x0EA0, 0x2168 ), }, /* Ours Technology Inc. (BUFFALO ClipDrive)*/
  33652. +//{ USB_DEVICE( 0x0457, 0x0150 ), }, /* Silicon Integrated Systems Corp. */
  33653. +
  33654. +/* HP Printers */
  33655. +//{ USB_DEVICE( 0x03F0, 0x1102 ), }, /* HP Photosmart 245 */
  33656. +//{ USB_DEVICE( 0x03F0, 0x1302 ), }, /* HP Photosmart 370 Series */
  33657. +
  33658. +/* Speakers */
  33659. +//{ USB_DEVICE( 0x0499, 0x3002 ), }, /* YAMAHA YST-MS35D USB Speakers */
  33660. +//{ USB_DEVICE( 0x0672, 0x1041 ), }, /* Labtec USB Headset */
  33661. +
  33662. { } /* Terminating entry */
  33663. };
  33664. +static inline void report_errors(struct usb_device *dev)
  33665. +{
  33666. + /* OTG MESSAGE: report errors here, customize to match your product */
  33667. + dev_info(&dev->dev, "device Vendor:%04x Product:%04x is not supported\n",
  33668. + le16_to_cpu(dev->descriptor.idVendor),
  33669. + le16_to_cpu(dev->descriptor.idProduct));
  33670. + if (USB_CLASS_HUB == dev->descriptor.bDeviceClass){
  33671. + dev_printk(KERN_CRIT, &dev->dev, "Unsupported Hub Topology\n");
  33672. + } else {
  33673. + dev_printk(KERN_CRIT, &dev->dev, "Attached Device is not Supported\n");
  33674. + }
  33675. +}
  33676. +
  33677. +
  33678. static int is_targeted(struct usb_device *dev)
  33679. {
  33680. struct usb_device_id *id = whitelist_table;
  33681. @@ -55,58 +104,83 @@
  33682. return 1;
  33683. /* HNP test device is _never_ targeted (see OTG spec 6.6.6) */
  33684. - if ((le16_to_cpu(dev->descriptor.idVendor) == 0x1a0a &&
  33685. - le16_to_cpu(dev->descriptor.idProduct) == 0xbadd))
  33686. - return 0;
  33687. + if (dev->descriptor.idVendor == 0x1a0a &&
  33688. + dev->descriptor.idProduct == 0xbadd) {
  33689. + return 0;
  33690. + } else if (!enable_whitelist) {
  33691. + return 1;
  33692. + } else {
  33693. - /* NOTE: can't use usb_match_id() since interface caches
  33694. - * aren't set up yet. this is cut/paste from that code.
  33695. - */
  33696. - for (id = whitelist_table; id->match_flags; id++) {
  33697. - if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) &&
  33698. - id->idVendor != le16_to_cpu(dev->descriptor.idVendor))
  33699. - continue;
  33700. -
  33701. - if ((id->match_flags & USB_DEVICE_ID_MATCH_PRODUCT) &&
  33702. - id->idProduct != le16_to_cpu(dev->descriptor.idProduct))
  33703. - continue;
  33704. -
  33705. - /* No need to test id->bcdDevice_lo != 0, since 0 is never
  33706. - greater than any unsigned number. */
  33707. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_LO) &&
  33708. - (id->bcdDevice_lo > le16_to_cpu(dev->descriptor.bcdDevice)))
  33709. - continue;
  33710. -
  33711. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI) &&
  33712. - (id->bcdDevice_hi < le16_to_cpu(dev->descriptor.bcdDevice)))
  33713. - continue;
  33714. -
  33715. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_CLASS) &&
  33716. - (id->bDeviceClass != dev->descriptor.bDeviceClass))
  33717. - continue;
  33718. -
  33719. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) &&
  33720. - (id->bDeviceSubClass != dev->descriptor.bDeviceSubClass))
  33721. - continue;
  33722. -
  33723. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) &&
  33724. - (id->bDeviceProtocol != dev->descriptor.bDeviceProtocol))
  33725. - continue;
  33726. +#ifdef DEBUG
  33727. + dev_dbg(&dev->dev, "device V:%04x P:%04x DC:%04x SC:%04x PR:%04x \n",
  33728. + dev->descriptor.idVendor,
  33729. + dev->descriptor.idProduct,
  33730. + dev->descriptor.bDeviceClass,
  33731. + dev->descriptor.bDeviceSubClass,
  33732. + dev->descriptor.bDeviceProtocol);
  33733. +#endif
  33734. return 1;
  33735. + /* NOTE: can't use usb_match_id() since interface caches
  33736. + * aren't set up yet. this is cut/paste from that code.
  33737. + */
  33738. + for (id = whitelist_table; id->match_flags; id++) {
  33739. +#ifdef DEBUG
  33740. + dev_dbg(&dev->dev,
  33741. + "ID: V:%04x P:%04x DC:%04x SC:%04x PR:%04x \n",
  33742. + id->idVendor,
  33743. + id->idProduct,
  33744. + id->bDeviceClass,
  33745. + id->bDeviceSubClass,
  33746. + id->bDeviceProtocol);
  33747. +#endif
  33748. +
  33749. + if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) &&
  33750. + id->idVendor != le16_to_cpu(dev->descriptor.idVendor))
  33751. + continue;
  33752. +
  33753. + if ((id->match_flags & USB_DEVICE_ID_MATCH_PRODUCT) &&
  33754. + id->idProduct != le16_to_cpu(dev->descriptor.idProduct))
  33755. + continue;
  33756. +
  33757. + /* No need to test id->bcdDevice_lo != 0, since 0 is never
  33758. + greater than any unsigned number. */
  33759. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_LO) &&
  33760. + (id->bcdDevice_lo > le16_to_cpu(dev->descriptor.bcdDevice)))
  33761. + continue;
  33762. +
  33763. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI) &&
  33764. + (id->bcdDevice_hi < le16_to_cpu(dev->descriptor.bcdDevice)))
  33765. + continue;
  33766. +
  33767. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_CLASS) &&
  33768. + (id->bDeviceClass != dev->descriptor.bDeviceClass))
  33769. + continue;
  33770. +
  33771. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) &&
  33772. + (id->bDeviceSubClass != dev->descriptor.bDeviceSubClass))
  33773. + continue;
  33774. +
  33775. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) &&
  33776. + (id->bDeviceProtocol != dev->descriptor.bDeviceProtocol))
  33777. + continue;
  33778. +
  33779. + return 1;
  33780. + }
  33781. }
  33782. /* add other match criteria here ... */
  33783. -
  33784. - /* OTG MESSAGE: report errors here, customize to match your product */
  33785. - dev_err(&dev->dev, "device v%04x p%04x is not supported\n",
  33786. - le16_to_cpu(dev->descriptor.idVendor),
  33787. - le16_to_cpu(dev->descriptor.idProduct));
  33788. #ifdef CONFIG_USB_OTG_WHITELIST
  33789. + report_errors(dev);
  33790. return 0;
  33791. #else
  33792. - return 1;
  33793. + if (enable_whitelist) {
  33794. + report_errors(dev);
  33795. + return 0;
  33796. + } else {
  33797. + return 1;
  33798. + }
  33799. #endif
  33800. }
  33801. diff -Nur linux-3.13.3.orig/drivers/usb/gadget/file_storage.c linux-3.13.3/drivers/usb/gadget/file_storage.c
  33802. --- linux-3.13.3.orig/drivers/usb/gadget/file_storage.c 1970-01-01 01:00:00.000000000 +0100
  33803. +++ linux-3.13.3/drivers/usb/gadget/file_storage.c 2014-02-17 22:41:01.000000000 +0100
  33804. @@ -0,0 +1,3676 @@
  33805. +/*
  33806. + * file_storage.c -- File-backed USB Storage Gadget, for USB development
  33807. + *
  33808. + * Copyright (C) 2003-2008 Alan Stern
  33809. + * All rights reserved.
  33810. + *
  33811. + * Redistribution and use in source and binary forms, with or without
  33812. + * modification, are permitted provided that the following conditions
  33813. + * are met:
  33814. + * 1. Redistributions of source code must retain the above copyright
  33815. + * notice, this list of conditions, and the following disclaimer,
  33816. + * without modification.
  33817. + * 2. Redistributions in binary form must reproduce the above copyright
  33818. + * notice, this list of conditions and the following disclaimer in the
  33819. + * documentation and/or other materials provided with the distribution.
  33820. + * 3. The names of the above-listed copyright holders may not be used
  33821. + * to endorse or promote products derived from this software without
  33822. + * specific prior written permission.
  33823. + *
  33824. + * ALTERNATIVELY, this software may be distributed under the terms of the
  33825. + * GNU General Public License ("GPL") as published by the Free Software
  33826. + * Foundation, either version 2 of that License or (at your option) any
  33827. + * later version.
  33828. + *
  33829. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  33830. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  33831. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  33832. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  33833. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  33834. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  33835. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  33836. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  33837. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  33838. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  33839. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33840. + */
  33841. +
  33842. +
  33843. +/*
  33844. + * The File-backed Storage Gadget acts as a USB Mass Storage device,
  33845. + * appearing to the host as a disk drive or as a CD-ROM drive. In addition
  33846. + * to providing an example of a genuinely useful gadget driver for a USB
  33847. + * device, it also illustrates a technique of double-buffering for increased
  33848. + * throughput. Last but not least, it gives an easy way to probe the
  33849. + * behavior of the Mass Storage drivers in a USB host.
  33850. + *
  33851. + * Backing storage is provided by a regular file or a block device, specified
  33852. + * by the "file" module parameter. Access can be limited to read-only by
  33853. + * setting the optional "ro" module parameter. (For CD-ROM emulation,
  33854. + * access is always read-only.) The gadget will indicate that it has
  33855. + * removable media if the optional "removable" module parameter is set.
  33856. + *
  33857. + * The gadget supports the Control-Bulk (CB), Control-Bulk-Interrupt (CBI),
  33858. + * and Bulk-Only (also known as Bulk-Bulk-Bulk or BBB) transports, selected
  33859. + * by the optional "transport" module parameter. It also supports the
  33860. + * following protocols: RBC (0x01), ATAPI or SFF-8020i (0x02), QIC-157 (0c03),
  33861. + * UFI (0x04), SFF-8070i (0x05), and transparent SCSI (0x06), selected by
  33862. + * the optional "protocol" module parameter. In addition, the default
  33863. + * Vendor ID, Product ID, release number and serial number can be overridden.
  33864. + *
  33865. + * There is support for multiple logical units (LUNs), each of which has
  33866. + * its own backing file. The number of LUNs can be set using the optional
  33867. + * "luns" module parameter (anywhere from 1 to 8), and the corresponding
  33868. + * files are specified using comma-separated lists for "file" and "ro".
  33869. + * The default number of LUNs is taken from the number of "file" elements;
  33870. + * it is 1 if "file" is not given. If "removable" is not set then a backing
  33871. + * file must be specified for each LUN. If it is set, then an unspecified
  33872. + * or empty backing filename means the LUN's medium is not loaded. Ideally
  33873. + * each LUN would be settable independently as a disk drive or a CD-ROM
  33874. + * drive, but currently all LUNs have to be the same type. The CD-ROM
  33875. + * emulation includes a single data track and no audio tracks; hence there
  33876. + * need be only one backing file per LUN.
  33877. + *
  33878. + * Requirements are modest; only a bulk-in and a bulk-out endpoint are
  33879. + * needed (an interrupt-out endpoint is also needed for CBI). The memory
  33880. + * requirement amounts to two 16K buffers, size configurable by a parameter.
  33881. + * Support is included for both full-speed and high-speed operation.
  33882. + *
  33883. + * Note that the driver is slightly non-portable in that it assumes a
  33884. + * single memory/DMA buffer will be useable for bulk-in, bulk-out, and
  33885. + * interrupt-in endpoints. With most device controllers this isn't an
  33886. + * issue, but there may be some with hardware restrictions that prevent
  33887. + * a buffer from being used by more than one endpoint.
  33888. + *
  33889. + * Module options:
  33890. + *
  33891. + * file=filename[,filename...]
  33892. + * Required if "removable" is not set, names of
  33893. + * the files or block devices used for
  33894. + * backing storage
  33895. + * serial=HHHH... Required serial number (string of hex chars)
  33896. + * ro=b[,b...] Default false, booleans for read-only access
  33897. + * removable Default false, boolean for removable media
  33898. + * luns=N Default N = number of filenames, number of
  33899. + * LUNs to support
  33900. + * nofua=b[,b...] Default false, booleans for ignore FUA flag
  33901. + * in SCSI WRITE(10,12) commands
  33902. + * stall Default determined according to the type of
  33903. + * USB device controller (usually true),
  33904. + * boolean to permit the driver to halt
  33905. + * bulk endpoints
  33906. + * cdrom Default false, boolean for whether to emulate
  33907. + * a CD-ROM drive
  33908. + * transport=XXX Default BBB, transport name (CB, CBI, or BBB)
  33909. + * protocol=YYY Default SCSI, protocol name (RBC, 8020 or
  33910. + * ATAPI, QIC, UFI, 8070, or SCSI;
  33911. + * also 1 - 6)
  33912. + * vendor=0xVVVV Default 0x0525 (NetChip), USB Vendor ID
  33913. + * product=0xPPPP Default 0xa4a5 (FSG), USB Product ID
  33914. + * release=0xRRRR Override the USB release number (bcdDevice)
  33915. + * buflen=N Default N=16384, buffer size used (will be
  33916. + * rounded down to a multiple of
  33917. + * PAGE_CACHE_SIZE)
  33918. + *
  33919. + * If CONFIG_USB_FILE_STORAGE_TEST is not set, only the "file", "serial", "ro",
  33920. + * "removable", "luns", "nofua", "stall", and "cdrom" options are available;
  33921. + * default values are used for everything else.
  33922. + *
  33923. + * The pathnames of the backing files and the ro settings are available in
  33924. + * the attribute files "file", "nofua", and "ro" in the lun<n> subdirectory of
  33925. + * the gadget's sysfs directory. If the "removable" option is set, writing to
  33926. + * these files will simulate ejecting/loading the medium (writing an empty
  33927. + * line means eject) and adjusting a write-enable tab. Changes to the ro
  33928. + * setting are not allowed when the medium is loaded or if CD-ROM emulation
  33929. + * is being used.
  33930. + *
  33931. + * This gadget driver is heavily based on "Gadget Zero" by David Brownell.
  33932. + * The driver's SCSI command interface was based on the "Information
  33933. + * technology - Small Computer System Interface - 2" document from
  33934. + * X3T9.2 Project 375D, Revision 10L, 7-SEP-93, available at
  33935. + * <http://www.t10.org/ftp/t10/drafts/s2/s2-r10l.pdf>. The single exception
  33936. + * is opcode 0x23 (READ FORMAT CAPACITIES), which was based on the
  33937. + * "Universal Serial Bus Mass Storage Class UFI Command Specification"
  33938. + * document, Revision 1.0, December 14, 1998, available at
  33939. + * <http://www.usb.org/developers/devclass_docs/usbmass-ufi10.pdf>.
  33940. + */
  33941. +
  33942. +
  33943. +/*
  33944. + * Driver Design
  33945. + *
  33946. + * The FSG driver is fairly straightforward. There is a main kernel
  33947. + * thread that handles most of the work. Interrupt routines field
  33948. + * callbacks from the controller driver: bulk- and interrupt-request
  33949. + * completion notifications, endpoint-0 events, and disconnect events.
  33950. + * Completion events are passed to the main thread by wakeup calls. Many
  33951. + * ep0 requests are handled at interrupt time, but SetInterface,
  33952. + * SetConfiguration, and device reset requests are forwarded to the
  33953. + * thread in the form of "exceptions" using SIGUSR1 signals (since they
  33954. + * should interrupt any ongoing file I/O operations).
  33955. + *
  33956. + * The thread's main routine implements the standard command/data/status
  33957. + * parts of a SCSI interaction. It and its subroutines are full of tests
  33958. + * for pending signals/exceptions -- all this polling is necessary since
  33959. + * the kernel has no setjmp/longjmp equivalents. (Maybe this is an
  33960. + * indication that the driver really wants to be running in userspace.)
  33961. + * An important point is that so long as the thread is alive it keeps an
  33962. + * open reference to the backing file. This will prevent unmounting
  33963. + * the backing file's underlying filesystem and could cause problems
  33964. + * during system shutdown, for example. To prevent such problems, the
  33965. + * thread catches INT, TERM, and KILL signals and converts them into
  33966. + * an EXIT exception.
  33967. + *
  33968. + * In normal operation the main thread is started during the gadget's
  33969. + * fsg_bind() callback and stopped during fsg_unbind(). But it can also
  33970. + * exit when it receives a signal, and there's no point leaving the
  33971. + * gadget running when the thread is dead. So just before the thread
  33972. + * exits, it deregisters the gadget driver. This makes things a little
  33973. + * tricky: The driver is deregistered at two places, and the exiting
  33974. + * thread can indirectly call fsg_unbind() which in turn can tell the
  33975. + * thread to exit. The first problem is resolved through the use of the
  33976. + * REGISTERED atomic bitflag; the driver will only be deregistered once.
  33977. + * The second problem is resolved by having fsg_unbind() check
  33978. + * fsg->state; it won't try to stop the thread if the state is already
  33979. + * FSG_STATE_TERMINATED.
  33980. + *
  33981. + * To provide maximum throughput, the driver uses a circular pipeline of
  33982. + * buffer heads (struct fsg_buffhd). In principle the pipeline can be
  33983. + * arbitrarily long; in practice the benefits don't justify having more
  33984. + * than 2 stages (i.e., double buffering). But it helps to think of the
  33985. + * pipeline as being a long one. Each buffer head contains a bulk-in and
  33986. + * a bulk-out request pointer (since the buffer can be used for both
  33987. + * output and input -- directions always are given from the host's
  33988. + * point of view) as well as a pointer to the buffer and various state
  33989. + * variables.
  33990. + *
  33991. + * Use of the pipeline follows a simple protocol. There is a variable
  33992. + * (fsg->next_buffhd_to_fill) that points to the next buffer head to use.
  33993. + * At any time that buffer head may still be in use from an earlier
  33994. + * request, so each buffer head has a state variable indicating whether
  33995. + * it is EMPTY, FULL, or BUSY. Typical use involves waiting for the
  33996. + * buffer head to be EMPTY, filling the buffer either by file I/O or by
  33997. + * USB I/O (during which the buffer head is BUSY), and marking the buffer
  33998. + * head FULL when the I/O is complete. Then the buffer will be emptied
  33999. + * (again possibly by USB I/O, during which it is marked BUSY) and
  34000. + * finally marked EMPTY again (possibly by a completion routine).
  34001. + *
  34002. + * A module parameter tells the driver to avoid stalling the bulk
  34003. + * endpoints wherever the transport specification allows. This is
  34004. + * necessary for some UDCs like the SuperH, which cannot reliably clear a
  34005. + * halt on a bulk endpoint. However, under certain circumstances the
  34006. + * Bulk-only specification requires a stall. In such cases the driver
  34007. + * will halt the endpoint and set a flag indicating that it should clear
  34008. + * the halt in software during the next device reset. Hopefully this
  34009. + * will permit everything to work correctly. Furthermore, although the
  34010. + * specification allows the bulk-out endpoint to halt when the host sends
  34011. + * too much data, implementing this would cause an unavoidable race.
  34012. + * The driver will always use the "no-stall" approach for OUT transfers.
  34013. + *
  34014. + * One subtle point concerns sending status-stage responses for ep0
  34015. + * requests. Some of these requests, such as device reset, can involve
  34016. + * interrupting an ongoing file I/O operation, which might take an
  34017. + * arbitrarily long time. During that delay the host might give up on
  34018. + * the original ep0 request and issue a new one. When that happens the
  34019. + * driver should not notify the host about completion of the original
  34020. + * request, as the host will no longer be waiting for it. So the driver
  34021. + * assigns to each ep0 request a unique tag, and it keeps track of the
  34022. + * tag value of the request associated with a long-running exception
  34023. + * (device-reset, interface-change, or configuration-change). When the
  34024. + * exception handler is finished, the status-stage response is submitted
  34025. + * only if the current ep0 request tag is equal to the exception request
  34026. + * tag. Thus only the most recently received ep0 request will get a
  34027. + * status-stage response.
  34028. + *
  34029. + * Warning: This driver source file is too long. It ought to be split up
  34030. + * into a header file plus about 3 separate .c files, to handle the details
  34031. + * of the Gadget, USB Mass Storage, and SCSI protocols.
  34032. + */
  34033. +
  34034. +
  34035. +/* #define VERBOSE_DEBUG */
  34036. +/* #define DUMP_MSGS */
  34037. +
  34038. +
  34039. +#include <linux/blkdev.h>
  34040. +#include <linux/completion.h>
  34041. +#include <linux/dcache.h>
  34042. +#include <linux/delay.h>
  34043. +#include <linux/device.h>
  34044. +#include <linux/fcntl.h>
  34045. +#include <linux/file.h>
  34046. +#include <linux/fs.h>
  34047. +#include <linux/kref.h>
  34048. +#include <linux/kthread.h>
  34049. +#include <linux/limits.h>
  34050. +#include <linux/module.h>
  34051. +#include <linux/rwsem.h>
  34052. +#include <linux/slab.h>
  34053. +#include <linux/spinlock.h>
  34054. +#include <linux/string.h>
  34055. +#include <linux/freezer.h>
  34056. +#include <linux/utsname.h>
  34057. +
  34058. +#include <linux/usb/ch9.h>
  34059. +#include <linux/usb/gadget.h>
  34060. +
  34061. +#include "gadget_chips.h"
  34062. +
  34063. +
  34064. +
  34065. +/*
  34066. + * Kbuild is not very cooperative with respect to linking separately
  34067. + * compiled library objects into one module. So for now we won't use
  34068. + * separate compilation ... ensuring init/exit sections work to shrink
  34069. + * the runtime footprint, and giving us at least some parts of what
  34070. + * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
  34071. + */
  34072. +#include "usbstring.c"
  34073. +#include "config.c"
  34074. +#include "epautoconf.c"
  34075. +
  34076. +/*-------------------------------------------------------------------------*/
  34077. +
  34078. +#define DRIVER_DESC "File-backed Storage Gadget"
  34079. +#define DRIVER_NAME "g_file_storage"
  34080. +#define DRIVER_VERSION "1 September 2010"
  34081. +
  34082. +static char fsg_string_manufacturer[64];
  34083. +static const char fsg_string_product[] = DRIVER_DESC;
  34084. +static const char fsg_string_config[] = "Self-powered";
  34085. +static const char fsg_string_interface[] = "Mass Storage";
  34086. +
  34087. +
  34088. +#include "storage_common.c"
  34089. +
  34090. +
  34091. +MODULE_DESCRIPTION(DRIVER_DESC);
  34092. +MODULE_AUTHOR("Alan Stern");
  34093. +MODULE_LICENSE("Dual BSD/GPL");
  34094. +
  34095. +/*
  34096. + * This driver assumes self-powered hardware and has no way for users to
  34097. + * trigger remote wakeup. It uses autoconfiguration to select endpoints
  34098. + * and endpoint addresses.
  34099. + */
  34100. +
  34101. +
  34102. +/*-------------------------------------------------------------------------*/
  34103. +
  34104. +
  34105. +/* Encapsulate the module parameter settings */
  34106. +
  34107. +static struct {
  34108. + char *file[FSG_MAX_LUNS];
  34109. + char *serial;
  34110. + bool ro[FSG_MAX_LUNS];
  34111. + bool nofua[FSG_MAX_LUNS];
  34112. + unsigned int num_filenames;
  34113. + unsigned int num_ros;
  34114. + unsigned int num_nofuas;
  34115. + unsigned int nluns;
  34116. +
  34117. + bool removable;
  34118. + bool can_stall;
  34119. + bool cdrom;
  34120. +
  34121. + char *transport_parm;
  34122. + char *protocol_parm;
  34123. + unsigned short vendor;
  34124. + unsigned short product;
  34125. + unsigned short release;
  34126. + unsigned int buflen;
  34127. +
  34128. + int transport_type;
  34129. + char *transport_name;
  34130. + int protocol_type;
  34131. + char *protocol_name;
  34132. +
  34133. +} mod_data = { // Default values
  34134. + .transport_parm = "BBB",
  34135. + .protocol_parm = "SCSI",
  34136. + .removable = 0,
  34137. + .can_stall = 1,
  34138. + .cdrom = 0,
  34139. + .vendor = FSG_VENDOR_ID,
  34140. + .product = FSG_PRODUCT_ID,
  34141. + .release = 0xffff, // Use controller chip type
  34142. + .buflen = 16384,
  34143. + };
  34144. +
  34145. +
  34146. +module_param_array_named(file, mod_data.file, charp, &mod_data.num_filenames,
  34147. + S_IRUGO);
  34148. +MODULE_PARM_DESC(file, "names of backing files or devices");
  34149. +
  34150. +module_param_named(serial, mod_data.serial, charp, S_IRUGO);
  34151. +MODULE_PARM_DESC(serial, "USB serial number");
  34152. +
  34153. +module_param_array_named(ro, mod_data.ro, bool, &mod_data.num_ros, S_IRUGO);
  34154. +MODULE_PARM_DESC(ro, "true to force read-only");
  34155. +
  34156. +module_param_array_named(nofua, mod_data.nofua, bool, &mod_data.num_nofuas,
  34157. + S_IRUGO);
  34158. +MODULE_PARM_DESC(nofua, "true to ignore SCSI WRITE(10,12) FUA bit");
  34159. +
  34160. +module_param_named(luns, mod_data.nluns, uint, S_IRUGO);
  34161. +MODULE_PARM_DESC(luns, "number of LUNs");
  34162. +
  34163. +module_param_named(removable, mod_data.removable, bool, S_IRUGO);
  34164. +MODULE_PARM_DESC(removable, "true to simulate removable media");
  34165. +
  34166. +module_param_named(stall, mod_data.can_stall, bool, S_IRUGO);
  34167. +MODULE_PARM_DESC(stall, "false to prevent bulk stalls");
  34168. +
  34169. +module_param_named(cdrom, mod_data.cdrom, bool, S_IRUGO);
  34170. +MODULE_PARM_DESC(cdrom, "true to emulate cdrom instead of disk");
  34171. +
  34172. +/* In the non-TEST version, only the module parameters listed above
  34173. + * are available. */
  34174. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  34175. +
  34176. +module_param_named(transport, mod_data.transport_parm, charp, S_IRUGO);
  34177. +MODULE_PARM_DESC(transport, "type of transport (BBB, CBI, or CB)");
  34178. +
  34179. +module_param_named(protocol, mod_data.protocol_parm, charp, S_IRUGO);
  34180. +MODULE_PARM_DESC(protocol, "type of protocol (RBC, 8020, QIC, UFI, "
  34181. + "8070, or SCSI)");
  34182. +
  34183. +module_param_named(vendor, mod_data.vendor, ushort, S_IRUGO);
  34184. +MODULE_PARM_DESC(vendor, "USB Vendor ID");
  34185. +
  34186. +module_param_named(product, mod_data.product, ushort, S_IRUGO);
  34187. +MODULE_PARM_DESC(product, "USB Product ID");
  34188. +
  34189. +module_param_named(release, mod_data.release, ushort, S_IRUGO);
  34190. +MODULE_PARM_DESC(release, "USB release number");
  34191. +
  34192. +module_param_named(buflen, mod_data.buflen, uint, S_IRUGO);
  34193. +MODULE_PARM_DESC(buflen, "I/O buffer size");
  34194. +
  34195. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  34196. +
  34197. +
  34198. +/*
  34199. + * These definitions will permit the compiler to avoid generating code for
  34200. + * parts of the driver that aren't used in the non-TEST version. Even gcc
  34201. + * can recognize when a test of a constant expression yields a dead code
  34202. + * path.
  34203. + */
  34204. +
  34205. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  34206. +
  34207. +#define transport_is_bbb() (mod_data.transport_type == USB_PR_BULK)
  34208. +#define transport_is_cbi() (mod_data.transport_type == USB_PR_CBI)
  34209. +#define protocol_is_scsi() (mod_data.protocol_type == USB_SC_SCSI)
  34210. +
  34211. +#else
  34212. +
  34213. +#define transport_is_bbb() 1
  34214. +#define transport_is_cbi() 0
  34215. +#define protocol_is_scsi() 1
  34216. +
  34217. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  34218. +
  34219. +
  34220. +/*-------------------------------------------------------------------------*/
  34221. +
  34222. +
  34223. +struct fsg_dev {
  34224. + /* lock protects: state, all the req_busy's, and cbbuf_cmnd */
  34225. + spinlock_t lock;
  34226. + struct usb_gadget *gadget;
  34227. +
  34228. + /* filesem protects: backing files in use */
  34229. + struct rw_semaphore filesem;
  34230. +
  34231. + /* reference counting: wait until all LUNs are released */
  34232. + struct kref ref;
  34233. +
  34234. + struct usb_ep *ep0; // Handy copy of gadget->ep0
  34235. + struct usb_request *ep0req; // For control responses
  34236. + unsigned int ep0_req_tag;
  34237. + const char *ep0req_name;
  34238. +
  34239. + struct usb_request *intreq; // For interrupt responses
  34240. + int intreq_busy;
  34241. + struct fsg_buffhd *intr_buffhd;
  34242. +
  34243. + unsigned int bulk_out_maxpacket;
  34244. + enum fsg_state state; // For exception handling
  34245. + unsigned int exception_req_tag;
  34246. +
  34247. + u8 config, new_config;
  34248. +
  34249. + unsigned int running : 1;
  34250. + unsigned int bulk_in_enabled : 1;
  34251. + unsigned int bulk_out_enabled : 1;
  34252. + unsigned int intr_in_enabled : 1;
  34253. + unsigned int phase_error : 1;
  34254. + unsigned int short_packet_received : 1;
  34255. + unsigned int bad_lun_okay : 1;
  34256. +
  34257. + unsigned long atomic_bitflags;
  34258. +#define REGISTERED 0
  34259. +#define IGNORE_BULK_OUT 1
  34260. +#define SUSPENDED 2
  34261. +
  34262. + struct usb_ep *bulk_in;
  34263. + struct usb_ep *bulk_out;
  34264. + struct usb_ep *intr_in;
  34265. +
  34266. + struct fsg_buffhd *next_buffhd_to_fill;
  34267. + struct fsg_buffhd *next_buffhd_to_drain;
  34268. +
  34269. + int thread_wakeup_needed;
  34270. + struct completion thread_notifier;
  34271. + struct task_struct *thread_task;
  34272. +
  34273. + int cmnd_size;
  34274. + u8 cmnd[MAX_COMMAND_SIZE];
  34275. + enum data_direction data_dir;
  34276. + u32 data_size;
  34277. + u32 data_size_from_cmnd;
  34278. + u32 tag;
  34279. + unsigned int lun;
  34280. + u32 residue;
  34281. + u32 usb_amount_left;
  34282. +
  34283. + /* The CB protocol offers no way for a host to know when a command
  34284. + * has completed. As a result the next command may arrive early,
  34285. + * and we will still have to handle it. For that reason we need
  34286. + * a buffer to store new commands when using CB (or CBI, which
  34287. + * does not oblige a host to wait for command completion either). */
  34288. + int cbbuf_cmnd_size;
  34289. + u8 cbbuf_cmnd[MAX_COMMAND_SIZE];
  34290. +
  34291. + unsigned int nluns;
  34292. + struct fsg_lun *luns;
  34293. + struct fsg_lun *curlun;
  34294. + /* Must be the last entry */
  34295. + struct fsg_buffhd buffhds[];
  34296. +};
  34297. +
  34298. +typedef void (*fsg_routine_t)(struct fsg_dev *);
  34299. +
  34300. +static int exception_in_progress(struct fsg_dev *fsg)
  34301. +{
  34302. + return (fsg->state > FSG_STATE_IDLE);
  34303. +}
  34304. +
  34305. +/* Make bulk-out requests be divisible by the maxpacket size */
  34306. +static void set_bulk_out_req_length(struct fsg_dev *fsg,
  34307. + struct fsg_buffhd *bh, unsigned int length)
  34308. +{
  34309. + unsigned int rem;
  34310. +
  34311. + bh->bulk_out_intended_length = length;
  34312. + rem = length % fsg->bulk_out_maxpacket;
  34313. + if (rem > 0)
  34314. + length += fsg->bulk_out_maxpacket - rem;
  34315. + bh->outreq->length = length;
  34316. +}
  34317. +
  34318. +static struct fsg_dev *the_fsg;
  34319. +static struct usb_gadget_driver fsg_driver;
  34320. +
  34321. +
  34322. +/*-------------------------------------------------------------------------*/
  34323. +
  34324. +static int fsg_set_halt(struct fsg_dev *fsg, struct usb_ep *ep)
  34325. +{
  34326. + const char *name;
  34327. +
  34328. + if (ep == fsg->bulk_in)
  34329. + name = "bulk-in";
  34330. + else if (ep == fsg->bulk_out)
  34331. + name = "bulk-out";
  34332. + else
  34333. + name = ep->name;
  34334. + DBG(fsg, "%s set halt\n", name);
  34335. + return usb_ep_set_halt(ep);
  34336. +}
  34337. +
  34338. +
  34339. +/*-------------------------------------------------------------------------*/
  34340. +
  34341. +/*
  34342. + * DESCRIPTORS ... most are static, but strings and (full) configuration
  34343. + * descriptors are built on demand. Also the (static) config and interface
  34344. + * descriptors are adjusted during fsg_bind().
  34345. + */
  34346. +
  34347. +/* There is only one configuration. */
  34348. +#define CONFIG_VALUE 1
  34349. +
  34350. +static struct usb_device_descriptor
  34351. +device_desc = {
  34352. + .bLength = sizeof device_desc,
  34353. + .bDescriptorType = USB_DT_DEVICE,
  34354. +
  34355. + .bcdUSB = cpu_to_le16(0x0200),
  34356. + .bDeviceClass = USB_CLASS_PER_INTERFACE,
  34357. +
  34358. + /* The next three values can be overridden by module parameters */
  34359. + .idVendor = cpu_to_le16(FSG_VENDOR_ID),
  34360. + .idProduct = cpu_to_le16(FSG_PRODUCT_ID),
  34361. + .bcdDevice = cpu_to_le16(0xffff),
  34362. +
  34363. + .iManufacturer = FSG_STRING_MANUFACTURER,
  34364. + .iProduct = FSG_STRING_PRODUCT,
  34365. + .iSerialNumber = FSG_STRING_SERIAL,
  34366. + .bNumConfigurations = 1,
  34367. +};
  34368. +
  34369. +static struct usb_config_descriptor
  34370. +config_desc = {
  34371. + .bLength = sizeof config_desc,
  34372. + .bDescriptorType = USB_DT_CONFIG,
  34373. +
  34374. + /* wTotalLength computed by usb_gadget_config_buf() */
  34375. + .bNumInterfaces = 1,
  34376. + .bConfigurationValue = CONFIG_VALUE,
  34377. + .iConfiguration = FSG_STRING_CONFIG,
  34378. + .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
  34379. + .bMaxPower = CONFIG_USB_GADGET_VBUS_DRAW / 2,
  34380. +};
  34381. +
  34382. +
  34383. +static struct usb_qualifier_descriptor
  34384. +dev_qualifier = {
  34385. + .bLength = sizeof dev_qualifier,
  34386. + .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
  34387. +
  34388. + .bcdUSB = cpu_to_le16(0x0200),
  34389. + .bDeviceClass = USB_CLASS_PER_INTERFACE,
  34390. +
  34391. + .bNumConfigurations = 1,
  34392. +};
  34393. +
  34394. +static int populate_bos(struct fsg_dev *fsg, u8 *buf)
  34395. +{
  34396. + memcpy(buf, &fsg_bos_desc, USB_DT_BOS_SIZE);
  34397. + buf += USB_DT_BOS_SIZE;
  34398. +
  34399. + memcpy(buf, &fsg_ext_cap_desc, USB_DT_USB_EXT_CAP_SIZE);
  34400. + buf += USB_DT_USB_EXT_CAP_SIZE;
  34401. +
  34402. + memcpy(buf, &fsg_ss_cap_desc, USB_DT_USB_SS_CAP_SIZE);
  34403. +
  34404. + return USB_DT_BOS_SIZE + USB_DT_USB_SS_CAP_SIZE
  34405. + + USB_DT_USB_EXT_CAP_SIZE;
  34406. +}
  34407. +
  34408. +/*
  34409. + * Config descriptors must agree with the code that sets configurations
  34410. + * and with code managing interfaces and their altsettings. They must
  34411. + * also handle different speeds and other-speed requests.
  34412. + */
  34413. +static int populate_config_buf(struct usb_gadget *gadget,
  34414. + u8 *buf, u8 type, unsigned index)
  34415. +{
  34416. + enum usb_device_speed speed = gadget->speed;
  34417. + int len;
  34418. + const struct usb_descriptor_header **function;
  34419. +
  34420. + if (index > 0)
  34421. + return -EINVAL;
  34422. +
  34423. + if (gadget_is_dualspeed(gadget) && type == USB_DT_OTHER_SPEED_CONFIG)
  34424. + speed = (USB_SPEED_FULL + USB_SPEED_HIGH) - speed;
  34425. + function = gadget_is_dualspeed(gadget) && speed == USB_SPEED_HIGH
  34426. + ? (const struct usb_descriptor_header **)fsg_hs_function
  34427. + : (const struct usb_descriptor_header **)fsg_fs_function;
  34428. +
  34429. + /* for now, don't advertise srp-only devices */
  34430. + if (!gadget_is_otg(gadget))
  34431. + function++;
  34432. +
  34433. + len = usb_gadget_config_buf(&config_desc, buf, EP0_BUFSIZE, function);
  34434. + ((struct usb_config_descriptor *) buf)->bDescriptorType = type;
  34435. + return len;
  34436. +}
  34437. +
  34438. +
  34439. +/*-------------------------------------------------------------------------*/
  34440. +
  34441. +/* These routines may be called in process context or in_irq */
  34442. +
  34443. +/* Caller must hold fsg->lock */
  34444. +static void wakeup_thread(struct fsg_dev *fsg)
  34445. +{
  34446. + /* Tell the main thread that something has happened */
  34447. + fsg->thread_wakeup_needed = 1;
  34448. + if (fsg->thread_task)
  34449. + wake_up_process(fsg->thread_task);
  34450. +}
  34451. +
  34452. +
  34453. +static void raise_exception(struct fsg_dev *fsg, enum fsg_state new_state)
  34454. +{
  34455. + unsigned long flags;
  34456. +
  34457. + /* Do nothing if a higher-priority exception is already in progress.
  34458. + * If a lower-or-equal priority exception is in progress, preempt it
  34459. + * and notify the main thread by sending it a signal. */
  34460. + spin_lock_irqsave(&fsg->lock, flags);
  34461. + if (fsg->state <= new_state) {
  34462. + fsg->exception_req_tag = fsg->ep0_req_tag;
  34463. + fsg->state = new_state;
  34464. + if (fsg->thread_task)
  34465. + send_sig_info(SIGUSR1, SEND_SIG_FORCED,
  34466. + fsg->thread_task);
  34467. + }
  34468. + spin_unlock_irqrestore(&fsg->lock, flags);
  34469. +}
  34470. +
  34471. +
  34472. +/*-------------------------------------------------------------------------*/
  34473. +
  34474. +/* The disconnect callback and ep0 routines. These always run in_irq,
  34475. + * except that ep0_queue() is called in the main thread to acknowledge
  34476. + * completion of various requests: set config, set interface, and
  34477. + * Bulk-only device reset. */
  34478. +
  34479. +static void fsg_disconnect(struct usb_gadget *gadget)
  34480. +{
  34481. + struct fsg_dev *fsg = get_gadget_data(gadget);
  34482. +
  34483. + DBG(fsg, "disconnect or port reset\n");
  34484. + raise_exception(fsg, FSG_STATE_DISCONNECT);
  34485. +}
  34486. +
  34487. +
  34488. +static int ep0_queue(struct fsg_dev *fsg)
  34489. +{
  34490. + int rc;
  34491. +
  34492. + rc = usb_ep_queue(fsg->ep0, fsg->ep0req, GFP_ATOMIC);
  34493. + if (rc != 0 && rc != -ESHUTDOWN) {
  34494. +
  34495. + /* We can't do much more than wait for a reset */
  34496. + WARNING(fsg, "error in submission: %s --> %d\n",
  34497. + fsg->ep0->name, rc);
  34498. + }
  34499. + return rc;
  34500. +}
  34501. +
  34502. +static void ep0_complete(struct usb_ep *ep, struct usb_request *req)
  34503. +{
  34504. + struct fsg_dev *fsg = ep->driver_data;
  34505. +
  34506. + if (req->actual > 0)
  34507. + dump_msg(fsg, fsg->ep0req_name, req->buf, req->actual);
  34508. + if (req->status || req->actual != req->length)
  34509. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  34510. + req->status, req->actual, req->length);
  34511. + if (req->status == -ECONNRESET) // Request was cancelled
  34512. + usb_ep_fifo_flush(ep);
  34513. +
  34514. + if (req->status == 0 && req->context)
  34515. + ((fsg_routine_t) (req->context))(fsg);
  34516. +}
  34517. +
  34518. +
  34519. +/*-------------------------------------------------------------------------*/
  34520. +
  34521. +/* Bulk and interrupt endpoint completion handlers.
  34522. + * These always run in_irq. */
  34523. +
  34524. +static void bulk_in_complete(struct usb_ep *ep, struct usb_request *req)
  34525. +{
  34526. + struct fsg_dev *fsg = ep->driver_data;
  34527. + struct fsg_buffhd *bh = req->context;
  34528. +
  34529. + if (req->status || req->actual != req->length)
  34530. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  34531. + req->status, req->actual, req->length);
  34532. + if (req->status == -ECONNRESET) // Request was cancelled
  34533. + usb_ep_fifo_flush(ep);
  34534. +
  34535. + /* Hold the lock while we update the request and buffer states */
  34536. + smp_wmb();
  34537. + spin_lock(&fsg->lock);
  34538. + bh->inreq_busy = 0;
  34539. + bh->state = BUF_STATE_EMPTY;
  34540. + wakeup_thread(fsg);
  34541. + spin_unlock(&fsg->lock);
  34542. +}
  34543. +
  34544. +static void bulk_out_complete(struct usb_ep *ep, struct usb_request *req)
  34545. +{
  34546. + struct fsg_dev *fsg = ep->driver_data;
  34547. + struct fsg_buffhd *bh = req->context;
  34548. +
  34549. + dump_msg(fsg, "bulk-out", req->buf, req->actual);
  34550. + if (req->status || req->actual != bh->bulk_out_intended_length)
  34551. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  34552. + req->status, req->actual,
  34553. + bh->bulk_out_intended_length);
  34554. + if (req->status == -ECONNRESET) // Request was cancelled
  34555. + usb_ep_fifo_flush(ep);
  34556. +
  34557. + /* Hold the lock while we update the request and buffer states */
  34558. + smp_wmb();
  34559. + spin_lock(&fsg->lock);
  34560. + bh->outreq_busy = 0;
  34561. + bh->state = BUF_STATE_FULL;
  34562. + wakeup_thread(fsg);
  34563. + spin_unlock(&fsg->lock);
  34564. +}
  34565. +
  34566. +
  34567. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  34568. +static void intr_in_complete(struct usb_ep *ep, struct usb_request *req)
  34569. +{
  34570. + struct fsg_dev *fsg = ep->driver_data;
  34571. + struct fsg_buffhd *bh = req->context;
  34572. +
  34573. + if (req->status || req->actual != req->length)
  34574. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  34575. + req->status, req->actual, req->length);
  34576. + if (req->status == -ECONNRESET) // Request was cancelled
  34577. + usb_ep_fifo_flush(ep);
  34578. +
  34579. + /* Hold the lock while we update the request and buffer states */
  34580. + smp_wmb();
  34581. + spin_lock(&fsg->lock);
  34582. + fsg->intreq_busy = 0;
  34583. + bh->state = BUF_STATE_EMPTY;
  34584. + wakeup_thread(fsg);
  34585. + spin_unlock(&fsg->lock);
  34586. +}
  34587. +
  34588. +#else
  34589. +static void intr_in_complete(struct usb_ep *ep, struct usb_request *req)
  34590. +{}
  34591. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  34592. +
  34593. +
  34594. +/*-------------------------------------------------------------------------*/
  34595. +
  34596. +/* Ep0 class-specific handlers. These always run in_irq. */
  34597. +
  34598. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  34599. +static void received_cbi_adsc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  34600. +{
  34601. + struct usb_request *req = fsg->ep0req;
  34602. + static u8 cbi_reset_cmnd[6] = {
  34603. + SEND_DIAGNOSTIC, 4, 0xff, 0xff, 0xff, 0xff};
  34604. +
  34605. + /* Error in command transfer? */
  34606. + if (req->status || req->length != req->actual ||
  34607. + req->actual < 6 || req->actual > MAX_COMMAND_SIZE) {
  34608. +
  34609. + /* Not all controllers allow a protocol stall after
  34610. + * receiving control-out data, but we'll try anyway. */
  34611. + fsg_set_halt(fsg, fsg->ep0);
  34612. + return; // Wait for reset
  34613. + }
  34614. +
  34615. + /* Is it the special reset command? */
  34616. + if (req->actual >= sizeof cbi_reset_cmnd &&
  34617. + memcmp(req->buf, cbi_reset_cmnd,
  34618. + sizeof cbi_reset_cmnd) == 0) {
  34619. +
  34620. + /* Raise an exception to stop the current operation
  34621. + * and reinitialize our state. */
  34622. + DBG(fsg, "cbi reset request\n");
  34623. + raise_exception(fsg, FSG_STATE_RESET);
  34624. + return;
  34625. + }
  34626. +
  34627. + VDBG(fsg, "CB[I] accept device-specific command\n");
  34628. + spin_lock(&fsg->lock);
  34629. +
  34630. + /* Save the command for later */
  34631. + if (fsg->cbbuf_cmnd_size)
  34632. + WARNING(fsg, "CB[I] overwriting previous command\n");
  34633. + fsg->cbbuf_cmnd_size = req->actual;
  34634. + memcpy(fsg->cbbuf_cmnd, req->buf, fsg->cbbuf_cmnd_size);
  34635. +
  34636. + wakeup_thread(fsg);
  34637. + spin_unlock(&fsg->lock);
  34638. +}
  34639. +
  34640. +#else
  34641. +static void received_cbi_adsc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  34642. +{}
  34643. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  34644. +
  34645. +
  34646. +static int class_setup_req(struct fsg_dev *fsg,
  34647. + const struct usb_ctrlrequest *ctrl)
  34648. +{
  34649. + struct usb_request *req = fsg->ep0req;
  34650. + int value = -EOPNOTSUPP;
  34651. + u16 w_index = le16_to_cpu(ctrl->wIndex);
  34652. + u16 w_value = le16_to_cpu(ctrl->wValue);
  34653. + u16 w_length = le16_to_cpu(ctrl->wLength);
  34654. +
  34655. + if (!fsg->config)
  34656. + return value;
  34657. +
  34658. + /* Handle Bulk-only class-specific requests */
  34659. + if (transport_is_bbb()) {
  34660. + switch (ctrl->bRequest) {
  34661. +
  34662. + case US_BULK_RESET_REQUEST:
  34663. + if (ctrl->bRequestType != (USB_DIR_OUT |
  34664. + USB_TYPE_CLASS | USB_RECIP_INTERFACE))
  34665. + break;
  34666. + if (w_index != 0 || w_value != 0 || w_length != 0) {
  34667. + value = -EDOM;
  34668. + break;
  34669. + }
  34670. +
  34671. + /* Raise an exception to stop the current operation
  34672. + * and reinitialize our state. */
  34673. + DBG(fsg, "bulk reset request\n");
  34674. + raise_exception(fsg, FSG_STATE_RESET);
  34675. + value = DELAYED_STATUS;
  34676. + break;
  34677. +
  34678. + case US_BULK_GET_MAX_LUN:
  34679. + if (ctrl->bRequestType != (USB_DIR_IN |
  34680. + USB_TYPE_CLASS | USB_RECIP_INTERFACE))
  34681. + break;
  34682. + if (w_index != 0 || w_value != 0 || w_length != 1) {
  34683. + value = -EDOM;
  34684. + break;
  34685. + }
  34686. + VDBG(fsg, "get max LUN\n");
  34687. + *(u8 *) req->buf = fsg->nluns - 1;
  34688. + value = 1;
  34689. + break;
  34690. + }
  34691. + }
  34692. +
  34693. + /* Handle CBI class-specific requests */
  34694. + else {
  34695. + switch (ctrl->bRequest) {
  34696. +
  34697. + case USB_CBI_ADSC_REQUEST:
  34698. + if (ctrl->bRequestType != (USB_DIR_OUT |
  34699. + USB_TYPE_CLASS | USB_RECIP_INTERFACE))
  34700. + break;
  34701. + if (w_index != 0 || w_value != 0) {
  34702. + value = -EDOM;
  34703. + break;
  34704. + }
  34705. + if (w_length > MAX_COMMAND_SIZE) {
  34706. + value = -EOVERFLOW;
  34707. + break;
  34708. + }
  34709. + value = w_length;
  34710. + fsg->ep0req->context = received_cbi_adsc;
  34711. + break;
  34712. + }
  34713. + }
  34714. +
  34715. + if (value == -EOPNOTSUPP)
  34716. + VDBG(fsg,
  34717. + "unknown class-specific control req "
  34718. + "%02x.%02x v%04x i%04x l%u\n",
  34719. + ctrl->bRequestType, ctrl->bRequest,
  34720. + le16_to_cpu(ctrl->wValue), w_index, w_length);
  34721. + return value;
  34722. +}
  34723. +
  34724. +
  34725. +/*-------------------------------------------------------------------------*/
  34726. +
  34727. +/* Ep0 standard request handlers. These always run in_irq. */
  34728. +
  34729. +static int standard_setup_req(struct fsg_dev *fsg,
  34730. + const struct usb_ctrlrequest *ctrl)
  34731. +{
  34732. + struct usb_request *req = fsg->ep0req;
  34733. + int value = -EOPNOTSUPP;
  34734. + u16 w_index = le16_to_cpu(ctrl->wIndex);
  34735. + u16 w_value = le16_to_cpu(ctrl->wValue);
  34736. +
  34737. + /* Usually this just stores reply data in the pre-allocated ep0 buffer,
  34738. + * but config change events will also reconfigure hardware. */
  34739. + switch (ctrl->bRequest) {
  34740. +
  34741. + case USB_REQ_GET_DESCRIPTOR:
  34742. + if (ctrl->bRequestType != (USB_DIR_IN | USB_TYPE_STANDARD |
  34743. + USB_RECIP_DEVICE))
  34744. + break;
  34745. + switch (w_value >> 8) {
  34746. +
  34747. + case USB_DT_DEVICE:
  34748. + VDBG(fsg, "get device descriptor\n");
  34749. + device_desc.bMaxPacketSize0 = fsg->ep0->maxpacket;
  34750. + value = sizeof device_desc;
  34751. + memcpy(req->buf, &device_desc, value);
  34752. + break;
  34753. + case USB_DT_DEVICE_QUALIFIER:
  34754. + VDBG(fsg, "get device qualifier\n");
  34755. + if (!gadget_is_dualspeed(fsg->gadget) ||
  34756. + fsg->gadget->speed == USB_SPEED_SUPER)
  34757. + break;
  34758. + /*
  34759. + * Assume ep0 uses the same maxpacket value for both
  34760. + * speeds
  34761. + */
  34762. + dev_qualifier.bMaxPacketSize0 = fsg->ep0->maxpacket;
  34763. + value = sizeof dev_qualifier;
  34764. + memcpy(req->buf, &dev_qualifier, value);
  34765. + break;
  34766. +
  34767. + case USB_DT_OTHER_SPEED_CONFIG:
  34768. + VDBG(fsg, "get other-speed config descriptor\n");
  34769. + if (!gadget_is_dualspeed(fsg->gadget) ||
  34770. + fsg->gadget->speed == USB_SPEED_SUPER)
  34771. + break;
  34772. + goto get_config;
  34773. + case USB_DT_CONFIG:
  34774. + VDBG(fsg, "get configuration descriptor\n");
  34775. +get_config:
  34776. + value = populate_config_buf(fsg->gadget,
  34777. + req->buf,
  34778. + w_value >> 8,
  34779. + w_value & 0xff);
  34780. + break;
  34781. +
  34782. + case USB_DT_STRING:
  34783. + VDBG(fsg, "get string descriptor\n");
  34784. +
  34785. + /* wIndex == language code */
  34786. + value = usb_gadget_get_string(&fsg_stringtab,
  34787. + w_value & 0xff, req->buf);
  34788. + break;
  34789. +
  34790. + case USB_DT_BOS:
  34791. + VDBG(fsg, "get bos descriptor\n");
  34792. +
  34793. + if (gadget_is_superspeed(fsg->gadget))
  34794. + value = populate_bos(fsg, req->buf);
  34795. + break;
  34796. + }
  34797. +
  34798. + break;
  34799. +
  34800. + /* One config, two speeds */
  34801. + case USB_REQ_SET_CONFIGURATION:
  34802. + if (ctrl->bRequestType != (USB_DIR_OUT | USB_TYPE_STANDARD |
  34803. + USB_RECIP_DEVICE))
  34804. + break;
  34805. + VDBG(fsg, "set configuration\n");
  34806. + if (w_value == CONFIG_VALUE || w_value == 0) {
  34807. + fsg->new_config = w_value;
  34808. +
  34809. + /* Raise an exception to wipe out previous transaction
  34810. + * state (queued bufs, etc) and set the new config. */
  34811. + raise_exception(fsg, FSG_STATE_CONFIG_CHANGE);
  34812. + value = DELAYED_STATUS;
  34813. + }
  34814. + break;
  34815. + case USB_REQ_GET_CONFIGURATION:
  34816. + if (ctrl->bRequestType != (USB_DIR_IN | USB_TYPE_STANDARD |
  34817. + USB_RECIP_DEVICE))
  34818. + break;
  34819. + VDBG(fsg, "get configuration\n");
  34820. + *(u8 *) req->buf = fsg->config;
  34821. + value = 1;
  34822. + break;
  34823. +
  34824. + case USB_REQ_SET_INTERFACE:
  34825. + if (ctrl->bRequestType != (USB_DIR_OUT| USB_TYPE_STANDARD |
  34826. + USB_RECIP_INTERFACE))
  34827. + break;
  34828. + if (fsg->config && w_index == 0) {
  34829. +
  34830. + /* Raise an exception to wipe out previous transaction
  34831. + * state (queued bufs, etc) and install the new
  34832. + * interface altsetting. */
  34833. + raise_exception(fsg, FSG_STATE_INTERFACE_CHANGE);
  34834. + value = DELAYED_STATUS;
  34835. + }
  34836. + break;
  34837. + case USB_REQ_GET_INTERFACE:
  34838. + if (ctrl->bRequestType != (USB_DIR_IN | USB_TYPE_STANDARD |
  34839. + USB_RECIP_INTERFACE))
  34840. + break;
  34841. + if (!fsg->config)
  34842. + break;
  34843. + if (w_index != 0) {
  34844. + value = -EDOM;
  34845. + break;
  34846. + }
  34847. + VDBG(fsg, "get interface\n");
  34848. + *(u8 *) req->buf = 0;
  34849. + value = 1;
  34850. + break;
  34851. +
  34852. + default:
  34853. + VDBG(fsg,
  34854. + "unknown control req %02x.%02x v%04x i%04x l%u\n",
  34855. + ctrl->bRequestType, ctrl->bRequest,
  34856. + w_value, w_index, le16_to_cpu(ctrl->wLength));
  34857. + }
  34858. +
  34859. + return value;
  34860. +}
  34861. +
  34862. +
  34863. +static int fsg_setup(struct usb_gadget *gadget,
  34864. + const struct usb_ctrlrequest *ctrl)
  34865. +{
  34866. + struct fsg_dev *fsg = get_gadget_data(gadget);
  34867. + int rc;
  34868. + int w_length = le16_to_cpu(ctrl->wLength);
  34869. +
  34870. + ++fsg->ep0_req_tag; // Record arrival of a new request
  34871. + fsg->ep0req->context = NULL;
  34872. + fsg->ep0req->length = 0;
  34873. + dump_msg(fsg, "ep0-setup", (u8 *) ctrl, sizeof(*ctrl));
  34874. +
  34875. + if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_CLASS)
  34876. + rc = class_setup_req(fsg, ctrl);
  34877. + else
  34878. + rc = standard_setup_req(fsg, ctrl);
  34879. +
  34880. + /* Respond with data/status or defer until later? */
  34881. + if (rc >= 0 && rc != DELAYED_STATUS) {
  34882. + rc = min(rc, w_length);
  34883. + fsg->ep0req->length = rc;
  34884. + fsg->ep0req->zero = rc < w_length;
  34885. + fsg->ep0req_name = (ctrl->bRequestType & USB_DIR_IN ?
  34886. + "ep0-in" : "ep0-out");
  34887. + rc = ep0_queue(fsg);
  34888. + }
  34889. +
  34890. + /* Device either stalls (rc < 0) or reports success */
  34891. + return rc;
  34892. +}
  34893. +
  34894. +
  34895. +/*-------------------------------------------------------------------------*/
  34896. +
  34897. +/* All the following routines run in process context */
  34898. +
  34899. +
  34900. +/* Use this for bulk or interrupt transfers, not ep0 */
  34901. +static void start_transfer(struct fsg_dev *fsg, struct usb_ep *ep,
  34902. + struct usb_request *req, int *pbusy,
  34903. + enum fsg_buffer_state *state)
  34904. +{
  34905. + int rc;
  34906. +
  34907. + if (ep == fsg->bulk_in)
  34908. + dump_msg(fsg, "bulk-in", req->buf, req->length);
  34909. + else if (ep == fsg->intr_in)
  34910. + dump_msg(fsg, "intr-in", req->buf, req->length);
  34911. +
  34912. + spin_lock_irq(&fsg->lock);
  34913. + *pbusy = 1;
  34914. + *state = BUF_STATE_BUSY;
  34915. + spin_unlock_irq(&fsg->lock);
  34916. + rc = usb_ep_queue(ep, req, GFP_KERNEL);
  34917. + if (rc != 0) {
  34918. + *pbusy = 0;
  34919. + *state = BUF_STATE_EMPTY;
  34920. +
  34921. + /* We can't do much more than wait for a reset */
  34922. +
  34923. + /* Note: currently the net2280 driver fails zero-length
  34924. + * submissions if DMA is enabled. */
  34925. + if (rc != -ESHUTDOWN && !(rc == -EOPNOTSUPP &&
  34926. + req->length == 0))
  34927. + WARNING(fsg, "error in submission: %s --> %d\n",
  34928. + ep->name, rc);
  34929. + }
  34930. +}
  34931. +
  34932. +
  34933. +static int sleep_thread(struct fsg_dev *fsg)
  34934. +{
  34935. + int rc = 0;
  34936. +
  34937. + /* Wait until a signal arrives or we are woken up */
  34938. + for (;;) {
  34939. + try_to_freeze();
  34940. + set_current_state(TASK_INTERRUPTIBLE);
  34941. + if (signal_pending(current)) {
  34942. + rc = -EINTR;
  34943. + break;
  34944. + }
  34945. + if (fsg->thread_wakeup_needed)
  34946. + break;
  34947. + schedule();
  34948. + }
  34949. + __set_current_state(TASK_RUNNING);
  34950. + fsg->thread_wakeup_needed = 0;
  34951. + return rc;
  34952. +}
  34953. +
  34954. +
  34955. +/*-------------------------------------------------------------------------*/
  34956. +
  34957. +static int do_read(struct fsg_dev *fsg)
  34958. +{
  34959. + struct fsg_lun *curlun = fsg->curlun;
  34960. + u32 lba;
  34961. + struct fsg_buffhd *bh;
  34962. + int rc;
  34963. + u32 amount_left;
  34964. + loff_t file_offset, file_offset_tmp;
  34965. + unsigned int amount;
  34966. + ssize_t nread;
  34967. +
  34968. + /* Get the starting Logical Block Address and check that it's
  34969. + * not too big */
  34970. + if (fsg->cmnd[0] == READ_6)
  34971. + lba = get_unaligned_be24(&fsg->cmnd[1]);
  34972. + else {
  34973. + lba = get_unaligned_be32(&fsg->cmnd[2]);
  34974. +
  34975. + /* We allow DPO (Disable Page Out = don't save data in the
  34976. + * cache) and FUA (Force Unit Access = don't read from the
  34977. + * cache), but we don't implement them. */
  34978. + if ((fsg->cmnd[1] & ~0x18) != 0) {
  34979. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  34980. + return -EINVAL;
  34981. + }
  34982. + }
  34983. + if (lba >= curlun->num_sectors) {
  34984. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  34985. + return -EINVAL;
  34986. + }
  34987. + file_offset = ((loff_t) lba) << curlun->blkbits;
  34988. +
  34989. + /* Carry out the file reads */
  34990. + amount_left = fsg->data_size_from_cmnd;
  34991. + if (unlikely(amount_left == 0))
  34992. + return -EIO; // No default reply
  34993. +
  34994. + for (;;) {
  34995. +
  34996. + /* Figure out how much we need to read:
  34997. + * Try to read the remaining amount.
  34998. + * But don't read more than the buffer size.
  34999. + * And don't try to read past the end of the file.
  35000. + */
  35001. + amount = min((unsigned int) amount_left, mod_data.buflen);
  35002. + amount = min((loff_t) amount,
  35003. + curlun->file_length - file_offset);
  35004. +
  35005. + /* Wait for the next buffer to become available */
  35006. + bh = fsg->next_buffhd_to_fill;
  35007. + while (bh->state != BUF_STATE_EMPTY) {
  35008. + rc = sleep_thread(fsg);
  35009. + if (rc)
  35010. + return rc;
  35011. + }
  35012. +
  35013. + /* If we were asked to read past the end of file,
  35014. + * end with an empty buffer. */
  35015. + if (amount == 0) {
  35016. + curlun->sense_data =
  35017. + SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  35018. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  35019. + curlun->info_valid = 1;
  35020. + bh->inreq->length = 0;
  35021. + bh->state = BUF_STATE_FULL;
  35022. + break;
  35023. + }
  35024. +
  35025. + /* Perform the read */
  35026. + file_offset_tmp = file_offset;
  35027. + nread = vfs_read(curlun->filp,
  35028. + (char __user *) bh->buf,
  35029. + amount, &file_offset_tmp);
  35030. + VLDBG(curlun, "file read %u @ %llu -> %d\n", amount,
  35031. + (unsigned long long) file_offset,
  35032. + (int) nread);
  35033. + if (signal_pending(current))
  35034. + return -EINTR;
  35035. +
  35036. + if (nread < 0) {
  35037. + LDBG(curlun, "error in file read: %d\n",
  35038. + (int) nread);
  35039. + nread = 0;
  35040. + } else if (nread < amount) {
  35041. + LDBG(curlun, "partial file read: %d/%u\n",
  35042. + (int) nread, amount);
  35043. + nread = round_down(nread, curlun->blksize);
  35044. + }
  35045. + file_offset += nread;
  35046. + amount_left -= nread;
  35047. + fsg->residue -= nread;
  35048. +
  35049. + /* Except at the end of the transfer, nread will be
  35050. + * equal to the buffer size, which is divisible by the
  35051. + * bulk-in maxpacket size.
  35052. + */
  35053. + bh->inreq->length = nread;
  35054. + bh->state = BUF_STATE_FULL;
  35055. +
  35056. + /* If an error occurred, report it and its position */
  35057. + if (nread < amount) {
  35058. + curlun->sense_data = SS_UNRECOVERED_READ_ERROR;
  35059. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  35060. + curlun->info_valid = 1;
  35061. + break;
  35062. + }
  35063. +
  35064. + if (amount_left == 0)
  35065. + break; // No more left to read
  35066. +
  35067. + /* Send this buffer and go read some more */
  35068. + bh->inreq->zero = 0;
  35069. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  35070. + &bh->inreq_busy, &bh->state);
  35071. + fsg->next_buffhd_to_fill = bh->next;
  35072. + }
  35073. +
  35074. + return -EIO; // No default reply
  35075. +}
  35076. +
  35077. +
  35078. +/*-------------------------------------------------------------------------*/
  35079. +
  35080. +static int do_write(struct fsg_dev *fsg)
  35081. +{
  35082. + struct fsg_lun *curlun = fsg->curlun;
  35083. + u32 lba;
  35084. + struct fsg_buffhd *bh;
  35085. + int get_some_more;
  35086. + u32 amount_left_to_req, amount_left_to_write;
  35087. + loff_t usb_offset, file_offset, file_offset_tmp;
  35088. + unsigned int amount;
  35089. + ssize_t nwritten;
  35090. + int rc;
  35091. +
  35092. + if (curlun->ro) {
  35093. + curlun->sense_data = SS_WRITE_PROTECTED;
  35094. + return -EINVAL;
  35095. + }
  35096. + spin_lock(&curlun->filp->f_lock);
  35097. + curlun->filp->f_flags &= ~O_SYNC; // Default is not to wait
  35098. + spin_unlock(&curlun->filp->f_lock);
  35099. +
  35100. + /* Get the starting Logical Block Address and check that it's
  35101. + * not too big */
  35102. + if (fsg->cmnd[0] == WRITE_6)
  35103. + lba = get_unaligned_be24(&fsg->cmnd[1]);
  35104. + else {
  35105. + lba = get_unaligned_be32(&fsg->cmnd[2]);
  35106. +
  35107. + /* We allow DPO (Disable Page Out = don't save data in the
  35108. + * cache) and FUA (Force Unit Access = write directly to the
  35109. + * medium). We don't implement DPO; we implement FUA by
  35110. + * performing synchronous output. */
  35111. + if ((fsg->cmnd[1] & ~0x18) != 0) {
  35112. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  35113. + return -EINVAL;
  35114. + }
  35115. + /* FUA */
  35116. + if (!curlun->nofua && (fsg->cmnd[1] & 0x08)) {
  35117. + spin_lock(&curlun->filp->f_lock);
  35118. + curlun->filp->f_flags |= O_DSYNC;
  35119. + spin_unlock(&curlun->filp->f_lock);
  35120. + }
  35121. + }
  35122. + if (lba >= curlun->num_sectors) {
  35123. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  35124. + return -EINVAL;
  35125. + }
  35126. +
  35127. + /* Carry out the file writes */
  35128. + get_some_more = 1;
  35129. + file_offset = usb_offset = ((loff_t) lba) << curlun->blkbits;
  35130. + amount_left_to_req = amount_left_to_write = fsg->data_size_from_cmnd;
  35131. +
  35132. + while (amount_left_to_write > 0) {
  35133. +
  35134. + /* Queue a request for more data from the host */
  35135. + bh = fsg->next_buffhd_to_fill;
  35136. + if (bh->state == BUF_STATE_EMPTY && get_some_more) {
  35137. +
  35138. + /* Figure out how much we want to get:
  35139. + * Try to get the remaining amount,
  35140. + * but not more than the buffer size.
  35141. + */
  35142. + amount = min(amount_left_to_req, mod_data.buflen);
  35143. +
  35144. + /* Beyond the end of the backing file? */
  35145. + if (usb_offset >= curlun->file_length) {
  35146. + get_some_more = 0;
  35147. + curlun->sense_data =
  35148. + SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  35149. + curlun->sense_data_info = usb_offset >> curlun->blkbits;
  35150. + curlun->info_valid = 1;
  35151. + continue;
  35152. + }
  35153. +
  35154. + /* Get the next buffer */
  35155. + usb_offset += amount;
  35156. + fsg->usb_amount_left -= amount;
  35157. + amount_left_to_req -= amount;
  35158. + if (amount_left_to_req == 0)
  35159. + get_some_more = 0;
  35160. +
  35161. + /* Except at the end of the transfer, amount will be
  35162. + * equal to the buffer size, which is divisible by
  35163. + * the bulk-out maxpacket size.
  35164. + */
  35165. + set_bulk_out_req_length(fsg, bh, amount);
  35166. + start_transfer(fsg, fsg->bulk_out, bh->outreq,
  35167. + &bh->outreq_busy, &bh->state);
  35168. + fsg->next_buffhd_to_fill = bh->next;
  35169. + continue;
  35170. + }
  35171. +
  35172. + /* Write the received data to the backing file */
  35173. + bh = fsg->next_buffhd_to_drain;
  35174. + if (bh->state == BUF_STATE_EMPTY && !get_some_more)
  35175. + break; // We stopped early
  35176. + if (bh->state == BUF_STATE_FULL) {
  35177. + smp_rmb();
  35178. + fsg->next_buffhd_to_drain = bh->next;
  35179. + bh->state = BUF_STATE_EMPTY;
  35180. +
  35181. + /* Did something go wrong with the transfer? */
  35182. + if (bh->outreq->status != 0) {
  35183. + curlun->sense_data = SS_COMMUNICATION_FAILURE;
  35184. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  35185. + curlun->info_valid = 1;
  35186. + break;
  35187. + }
  35188. +
  35189. + amount = bh->outreq->actual;
  35190. + if (curlun->file_length - file_offset < amount) {
  35191. + LERROR(curlun,
  35192. + "write %u @ %llu beyond end %llu\n",
  35193. + amount, (unsigned long long) file_offset,
  35194. + (unsigned long long) curlun->file_length);
  35195. + amount = curlun->file_length - file_offset;
  35196. + }
  35197. +
  35198. + /* Don't accept excess data. The spec doesn't say
  35199. + * what to do in this case. We'll ignore the error.
  35200. + */
  35201. + amount = min(amount, bh->bulk_out_intended_length);
  35202. +
  35203. + /* Don't write a partial block */
  35204. + amount = round_down(amount, curlun->blksize);
  35205. + if (amount == 0)
  35206. + goto empty_write;
  35207. +
  35208. + /* Perform the write */
  35209. + file_offset_tmp = file_offset;
  35210. + nwritten = vfs_write(curlun->filp,
  35211. + (char __user *) bh->buf,
  35212. + amount, &file_offset_tmp);
  35213. + VLDBG(curlun, "file write %u @ %llu -> %d\n", amount,
  35214. + (unsigned long long) file_offset,
  35215. + (int) nwritten);
  35216. + if (signal_pending(current))
  35217. + return -EINTR; // Interrupted!
  35218. +
  35219. + if (nwritten < 0) {
  35220. + LDBG(curlun, "error in file write: %d\n",
  35221. + (int) nwritten);
  35222. + nwritten = 0;
  35223. + } else if (nwritten < amount) {
  35224. + LDBG(curlun, "partial file write: %d/%u\n",
  35225. + (int) nwritten, amount);
  35226. + nwritten = round_down(nwritten, curlun->blksize);
  35227. + }
  35228. + file_offset += nwritten;
  35229. + amount_left_to_write -= nwritten;
  35230. + fsg->residue -= nwritten;
  35231. +
  35232. + /* If an error occurred, report it and its position */
  35233. + if (nwritten < amount) {
  35234. + curlun->sense_data = SS_WRITE_ERROR;
  35235. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  35236. + curlun->info_valid = 1;
  35237. + break;
  35238. + }
  35239. +
  35240. + empty_write:
  35241. + /* Did the host decide to stop early? */
  35242. + if (bh->outreq->actual < bh->bulk_out_intended_length) {
  35243. + fsg->short_packet_received = 1;
  35244. + break;
  35245. + }
  35246. + continue;
  35247. + }
  35248. +
  35249. + /* Wait for something to happen */
  35250. + rc = sleep_thread(fsg);
  35251. + if (rc)
  35252. + return rc;
  35253. + }
  35254. +
  35255. + return -EIO; // No default reply
  35256. +}
  35257. +
  35258. +
  35259. +/*-------------------------------------------------------------------------*/
  35260. +
  35261. +static int do_synchronize_cache(struct fsg_dev *fsg)
  35262. +{
  35263. + struct fsg_lun *curlun = fsg->curlun;
  35264. + int rc;
  35265. +
  35266. + /* We ignore the requested LBA and write out all file's
  35267. + * dirty data buffers. */
  35268. + rc = fsg_lun_fsync_sub(curlun);
  35269. + if (rc)
  35270. + curlun->sense_data = SS_WRITE_ERROR;
  35271. + return 0;
  35272. +}
  35273. +
  35274. +
  35275. +/*-------------------------------------------------------------------------*/
  35276. +
  35277. +static void invalidate_sub(struct fsg_lun *curlun)
  35278. +{
  35279. + struct file *filp = curlun->filp;
  35280. + struct inode *inode = filp->f_path.dentry->d_inode;
  35281. + unsigned long rc;
  35282. +
  35283. + rc = invalidate_mapping_pages(inode->i_mapping, 0, -1);
  35284. + VLDBG(curlun, "invalidate_mapping_pages -> %ld\n", rc);
  35285. +}
  35286. +
  35287. +static int do_verify(struct fsg_dev *fsg)
  35288. +{
  35289. + struct fsg_lun *curlun = fsg->curlun;
  35290. + u32 lba;
  35291. + u32 verification_length;
  35292. + struct fsg_buffhd *bh = fsg->next_buffhd_to_fill;
  35293. + loff_t file_offset, file_offset_tmp;
  35294. + u32 amount_left;
  35295. + unsigned int amount;
  35296. + ssize_t nread;
  35297. +
  35298. + /* Get the starting Logical Block Address and check that it's
  35299. + * not too big */
  35300. + lba = get_unaligned_be32(&fsg->cmnd[2]);
  35301. + if (lba >= curlun->num_sectors) {
  35302. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  35303. + return -EINVAL;
  35304. + }
  35305. +
  35306. + /* We allow DPO (Disable Page Out = don't save data in the
  35307. + * cache) but we don't implement it. */
  35308. + if ((fsg->cmnd[1] & ~0x10) != 0) {
  35309. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  35310. + return -EINVAL;
  35311. + }
  35312. +
  35313. + verification_length = get_unaligned_be16(&fsg->cmnd[7]);
  35314. + if (unlikely(verification_length == 0))
  35315. + return -EIO; // No default reply
  35316. +
  35317. + /* Prepare to carry out the file verify */
  35318. + amount_left = verification_length << curlun->blkbits;
  35319. + file_offset = ((loff_t) lba) << curlun->blkbits;
  35320. +
  35321. + /* Write out all the dirty buffers before invalidating them */
  35322. + fsg_lun_fsync_sub(curlun);
  35323. + if (signal_pending(current))
  35324. + return -EINTR;
  35325. +
  35326. + invalidate_sub(curlun);
  35327. + if (signal_pending(current))
  35328. + return -EINTR;
  35329. +
  35330. + /* Just try to read the requested blocks */
  35331. + while (amount_left > 0) {
  35332. +
  35333. + /* Figure out how much we need to read:
  35334. + * Try to read the remaining amount, but not more than
  35335. + * the buffer size.
  35336. + * And don't try to read past the end of the file.
  35337. + */
  35338. + amount = min((unsigned int) amount_left, mod_data.buflen);
  35339. + amount = min((loff_t) amount,
  35340. + curlun->file_length - file_offset);
  35341. + if (amount == 0) {
  35342. + curlun->sense_data =
  35343. + SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  35344. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  35345. + curlun->info_valid = 1;
  35346. + break;
  35347. + }
  35348. +
  35349. + /* Perform the read */
  35350. + file_offset_tmp = file_offset;
  35351. + nread = vfs_read(curlun->filp,
  35352. + (char __user *) bh->buf,
  35353. + amount, &file_offset_tmp);
  35354. + VLDBG(curlun, "file read %u @ %llu -> %d\n", amount,
  35355. + (unsigned long long) file_offset,
  35356. + (int) nread);
  35357. + if (signal_pending(current))
  35358. + return -EINTR;
  35359. +
  35360. + if (nread < 0) {
  35361. + LDBG(curlun, "error in file verify: %d\n",
  35362. + (int) nread);
  35363. + nread = 0;
  35364. + } else if (nread < amount) {
  35365. + LDBG(curlun, "partial file verify: %d/%u\n",
  35366. + (int) nread, amount);
  35367. + nread = round_down(nread, curlun->blksize);
  35368. + }
  35369. + if (nread == 0) {
  35370. + curlun->sense_data = SS_UNRECOVERED_READ_ERROR;
  35371. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  35372. + curlun->info_valid = 1;
  35373. + break;
  35374. + }
  35375. + file_offset += nread;
  35376. + amount_left -= nread;
  35377. + }
  35378. + return 0;
  35379. +}
  35380. +
  35381. +
  35382. +/*-------------------------------------------------------------------------*/
  35383. +
  35384. +static int do_inquiry(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  35385. +{
  35386. + u8 *buf = (u8 *) bh->buf;
  35387. +
  35388. + static char vendor_id[] = "Linux ";
  35389. + static char product_disk_id[] = "File-Stor Gadget";
  35390. + static char product_cdrom_id[] = "File-CD Gadget ";
  35391. +
  35392. + if (!fsg->curlun) { // Unsupported LUNs are okay
  35393. + fsg->bad_lun_okay = 1;
  35394. + memset(buf, 0, 36);
  35395. + buf[0] = 0x7f; // Unsupported, no device-type
  35396. + buf[4] = 31; // Additional length
  35397. + return 36;
  35398. + }
  35399. +
  35400. + memset(buf, 0, 8);
  35401. + buf[0] = (mod_data.cdrom ? TYPE_ROM : TYPE_DISK);
  35402. + if (mod_data.removable)
  35403. + buf[1] = 0x80;
  35404. + buf[2] = 2; // ANSI SCSI level 2
  35405. + buf[3] = 2; // SCSI-2 INQUIRY data format
  35406. + buf[4] = 31; // Additional length
  35407. + // No special options
  35408. + sprintf(buf + 8, "%-8s%-16s%04x", vendor_id,
  35409. + (mod_data.cdrom ? product_cdrom_id :
  35410. + product_disk_id),
  35411. + mod_data.release);
  35412. + return 36;
  35413. +}
  35414. +
  35415. +
  35416. +static int do_request_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  35417. +{
  35418. + struct fsg_lun *curlun = fsg->curlun;
  35419. + u8 *buf = (u8 *) bh->buf;
  35420. + u32 sd, sdinfo;
  35421. + int valid;
  35422. +
  35423. + /*
  35424. + * From the SCSI-2 spec., section 7.9 (Unit attention condition):
  35425. + *
  35426. + * If a REQUEST SENSE command is received from an initiator
  35427. + * with a pending unit attention condition (before the target
  35428. + * generates the contingent allegiance condition), then the
  35429. + * target shall either:
  35430. + * a) report any pending sense data and preserve the unit
  35431. + * attention condition on the logical unit, or,
  35432. + * b) report the unit attention condition, may discard any
  35433. + * pending sense data, and clear the unit attention
  35434. + * condition on the logical unit for that initiator.
  35435. + *
  35436. + * FSG normally uses option a); enable this code to use option b).
  35437. + */
  35438. +#if 0
  35439. + if (curlun && curlun->unit_attention_data != SS_NO_SENSE) {
  35440. + curlun->sense_data = curlun->unit_attention_data;
  35441. + curlun->unit_attention_data = SS_NO_SENSE;
  35442. + }
  35443. +#endif
  35444. +
  35445. + if (!curlun) { // Unsupported LUNs are okay
  35446. + fsg->bad_lun_okay = 1;
  35447. + sd = SS_LOGICAL_UNIT_NOT_SUPPORTED;
  35448. + sdinfo = 0;
  35449. + valid = 0;
  35450. + } else {
  35451. + sd = curlun->sense_data;
  35452. + sdinfo = curlun->sense_data_info;
  35453. + valid = curlun->info_valid << 7;
  35454. + curlun->sense_data = SS_NO_SENSE;
  35455. + curlun->sense_data_info = 0;
  35456. + curlun->info_valid = 0;
  35457. + }
  35458. +
  35459. + memset(buf, 0, 18);
  35460. + buf[0] = valid | 0x70; // Valid, current error
  35461. + buf[2] = SK(sd);
  35462. + put_unaligned_be32(sdinfo, &buf[3]); /* Sense information */
  35463. + buf[7] = 18 - 8; // Additional sense length
  35464. + buf[12] = ASC(sd);
  35465. + buf[13] = ASCQ(sd);
  35466. + return 18;
  35467. +}
  35468. +
  35469. +
  35470. +static int do_read_capacity(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  35471. +{
  35472. + struct fsg_lun *curlun = fsg->curlun;
  35473. + u32 lba = get_unaligned_be32(&fsg->cmnd[2]);
  35474. + int pmi = fsg->cmnd[8];
  35475. + u8 *buf = (u8 *) bh->buf;
  35476. +
  35477. + /* Check the PMI and LBA fields */
  35478. + if (pmi > 1 || (pmi == 0 && lba != 0)) {
  35479. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  35480. + return -EINVAL;
  35481. + }
  35482. +
  35483. + put_unaligned_be32(curlun->num_sectors - 1, &buf[0]);
  35484. + /* Max logical block */
  35485. + put_unaligned_be32(curlun->blksize, &buf[4]); /* Block length */
  35486. + return 8;
  35487. +}
  35488. +
  35489. +
  35490. +static int do_read_header(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  35491. +{
  35492. + struct fsg_lun *curlun = fsg->curlun;
  35493. + int msf = fsg->cmnd[1] & 0x02;
  35494. + u32 lba = get_unaligned_be32(&fsg->cmnd[2]);
  35495. + u8 *buf = (u8 *) bh->buf;
  35496. +
  35497. + if ((fsg->cmnd[1] & ~0x02) != 0) { /* Mask away MSF */
  35498. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  35499. + return -EINVAL;
  35500. + }
  35501. + if (lba >= curlun->num_sectors) {
  35502. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  35503. + return -EINVAL;
  35504. + }
  35505. +
  35506. + memset(buf, 0, 8);
  35507. + buf[0] = 0x01; /* 2048 bytes of user data, rest is EC */
  35508. + store_cdrom_address(&buf[4], msf, lba);
  35509. + return 8;
  35510. +}
  35511. +
  35512. +
  35513. +static int do_read_toc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  35514. +{
  35515. + struct fsg_lun *curlun = fsg->curlun;
  35516. + int msf = fsg->cmnd[1] & 0x02;
  35517. + int start_track = fsg->cmnd[6];
  35518. + u8 *buf = (u8 *) bh->buf;
  35519. +
  35520. + if ((fsg->cmnd[1] & ~0x02) != 0 || /* Mask away MSF */
  35521. + start_track > 1) {
  35522. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  35523. + return -EINVAL;
  35524. + }
  35525. +
  35526. + memset(buf, 0, 20);
  35527. + buf[1] = (20-2); /* TOC data length */
  35528. + buf[2] = 1; /* First track number */
  35529. + buf[3] = 1; /* Last track number */
  35530. + buf[5] = 0x16; /* Data track, copying allowed */
  35531. + buf[6] = 0x01; /* Only track is number 1 */
  35532. + store_cdrom_address(&buf[8], msf, 0);
  35533. +
  35534. + buf[13] = 0x16; /* Lead-out track is data */
  35535. + buf[14] = 0xAA; /* Lead-out track number */
  35536. + store_cdrom_address(&buf[16], msf, curlun->num_sectors);
  35537. + return 20;
  35538. +}
  35539. +
  35540. +
  35541. +static int do_mode_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  35542. +{
  35543. + struct fsg_lun *curlun = fsg->curlun;
  35544. + int mscmnd = fsg->cmnd[0];
  35545. + u8 *buf = (u8 *) bh->buf;
  35546. + u8 *buf0 = buf;
  35547. + int pc, page_code;
  35548. + int changeable_values, all_pages;
  35549. + int valid_page = 0;
  35550. + int len, limit;
  35551. +
  35552. + if ((fsg->cmnd[1] & ~0x08) != 0) { // Mask away DBD
  35553. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  35554. + return -EINVAL;
  35555. + }
  35556. + pc = fsg->cmnd[2] >> 6;
  35557. + page_code = fsg->cmnd[2] & 0x3f;
  35558. + if (pc == 3) {
  35559. + curlun->sense_data = SS_SAVING_PARAMETERS_NOT_SUPPORTED;
  35560. + return -EINVAL;
  35561. + }
  35562. + changeable_values = (pc == 1);
  35563. + all_pages = (page_code == 0x3f);
  35564. +
  35565. + /* Write the mode parameter header. Fixed values are: default
  35566. + * medium type, no cache control (DPOFUA), and no block descriptors.
  35567. + * The only variable value is the WriteProtect bit. We will fill in
  35568. + * the mode data length later. */
  35569. + memset(buf, 0, 8);
  35570. + if (mscmnd == MODE_SENSE) {
  35571. + buf[2] = (curlun->ro ? 0x80 : 0x00); // WP, DPOFUA
  35572. + buf += 4;
  35573. + limit = 255;
  35574. + } else { // MODE_SENSE_10
  35575. + buf[3] = (curlun->ro ? 0x80 : 0x00); // WP, DPOFUA
  35576. + buf += 8;
  35577. + limit = 65535; // Should really be mod_data.buflen
  35578. + }
  35579. +
  35580. + /* No block descriptors */
  35581. +
  35582. + /* The mode pages, in numerical order. The only page we support
  35583. + * is the Caching page. */
  35584. + if (page_code == 0x08 || all_pages) {
  35585. + valid_page = 1;
  35586. + buf[0] = 0x08; // Page code
  35587. + buf[1] = 10; // Page length
  35588. + memset(buf+2, 0, 10); // None of the fields are changeable
  35589. +
  35590. + if (!changeable_values) {
  35591. + buf[2] = 0x04; // Write cache enable,
  35592. + // Read cache not disabled
  35593. + // No cache retention priorities
  35594. + put_unaligned_be16(0xffff, &buf[4]);
  35595. + /* Don't disable prefetch */
  35596. + /* Minimum prefetch = 0 */
  35597. + put_unaligned_be16(0xffff, &buf[8]);
  35598. + /* Maximum prefetch */
  35599. + put_unaligned_be16(0xffff, &buf[10]);
  35600. + /* Maximum prefetch ceiling */
  35601. + }
  35602. + buf += 12;
  35603. + }
  35604. +
  35605. + /* Check that a valid page was requested and the mode data length
  35606. + * isn't too long. */
  35607. + len = buf - buf0;
  35608. + if (!valid_page || len > limit) {
  35609. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  35610. + return -EINVAL;
  35611. + }
  35612. +
  35613. + /* Store the mode data length */
  35614. + if (mscmnd == MODE_SENSE)
  35615. + buf0[0] = len - 1;
  35616. + else
  35617. + put_unaligned_be16(len - 2, buf0);
  35618. + return len;
  35619. +}
  35620. +
  35621. +
  35622. +static int do_start_stop(struct fsg_dev *fsg)
  35623. +{
  35624. + struct fsg_lun *curlun = fsg->curlun;
  35625. + int loej, start;
  35626. +
  35627. + if (!mod_data.removable) {
  35628. + curlun->sense_data = SS_INVALID_COMMAND;
  35629. + return -EINVAL;
  35630. + }
  35631. +
  35632. + // int immed = fsg->cmnd[1] & 0x01;
  35633. + loej = fsg->cmnd[4] & 0x02;
  35634. + start = fsg->cmnd[4] & 0x01;
  35635. +
  35636. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  35637. + if ((fsg->cmnd[1] & ~0x01) != 0 || // Mask away Immed
  35638. + (fsg->cmnd[4] & ~0x03) != 0) { // Mask LoEj, Start
  35639. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  35640. + return -EINVAL;
  35641. + }
  35642. +
  35643. + if (!start) {
  35644. +
  35645. + /* Are we allowed to unload the media? */
  35646. + if (curlun->prevent_medium_removal) {
  35647. + LDBG(curlun, "unload attempt prevented\n");
  35648. + curlun->sense_data = SS_MEDIUM_REMOVAL_PREVENTED;
  35649. + return -EINVAL;
  35650. + }
  35651. + if (loej) { // Simulate an unload/eject
  35652. + up_read(&fsg->filesem);
  35653. + down_write(&fsg->filesem);
  35654. + fsg_lun_close(curlun);
  35655. + up_write(&fsg->filesem);
  35656. + down_read(&fsg->filesem);
  35657. + }
  35658. + } else {
  35659. +
  35660. + /* Our emulation doesn't support mounting; the medium is
  35661. + * available for use as soon as it is loaded. */
  35662. + if (!fsg_lun_is_open(curlun)) {
  35663. + curlun->sense_data = SS_MEDIUM_NOT_PRESENT;
  35664. + return -EINVAL;
  35665. + }
  35666. + }
  35667. +#endif
  35668. + return 0;
  35669. +}
  35670. +
  35671. +
  35672. +static int do_prevent_allow(struct fsg_dev *fsg)
  35673. +{
  35674. + struct fsg_lun *curlun = fsg->curlun;
  35675. + int prevent;
  35676. +
  35677. + if (!mod_data.removable) {
  35678. + curlun->sense_data = SS_INVALID_COMMAND;
  35679. + return -EINVAL;
  35680. + }
  35681. +
  35682. + prevent = fsg->cmnd[4] & 0x01;
  35683. + if ((fsg->cmnd[4] & ~0x01) != 0) { // Mask away Prevent
  35684. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  35685. + return -EINVAL;
  35686. + }
  35687. +
  35688. + if (curlun->prevent_medium_removal && !prevent)
  35689. + fsg_lun_fsync_sub(curlun);
  35690. + curlun->prevent_medium_removal = prevent;
  35691. + return 0;
  35692. +}
  35693. +
  35694. +
  35695. +static int do_read_format_capacities(struct fsg_dev *fsg,
  35696. + struct fsg_buffhd *bh)
  35697. +{
  35698. + struct fsg_lun *curlun = fsg->curlun;
  35699. + u8 *buf = (u8 *) bh->buf;
  35700. +
  35701. + buf[0] = buf[1] = buf[2] = 0;
  35702. + buf[3] = 8; // Only the Current/Maximum Capacity Descriptor
  35703. + buf += 4;
  35704. +
  35705. + put_unaligned_be32(curlun->num_sectors, &buf[0]);
  35706. + /* Number of blocks */
  35707. + put_unaligned_be32(curlun->blksize, &buf[4]); /* Block length */
  35708. + buf[4] = 0x02; /* Current capacity */
  35709. + return 12;
  35710. +}
  35711. +
  35712. +
  35713. +static int do_mode_select(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  35714. +{
  35715. + struct fsg_lun *curlun = fsg->curlun;
  35716. +
  35717. + /* We don't support MODE SELECT */
  35718. + curlun->sense_data = SS_INVALID_COMMAND;
  35719. + return -EINVAL;
  35720. +}
  35721. +
  35722. +
  35723. +/*-------------------------------------------------------------------------*/
  35724. +
  35725. +static int halt_bulk_in_endpoint(struct fsg_dev *fsg)
  35726. +{
  35727. + int rc;
  35728. +
  35729. + rc = fsg_set_halt(fsg, fsg->bulk_in);
  35730. + if (rc == -EAGAIN)
  35731. + VDBG(fsg, "delayed bulk-in endpoint halt\n");
  35732. + while (rc != 0) {
  35733. + if (rc != -EAGAIN) {
  35734. + WARNING(fsg, "usb_ep_set_halt -> %d\n", rc);
  35735. + rc = 0;
  35736. + break;
  35737. + }
  35738. +
  35739. + /* Wait for a short time and then try again */
  35740. + if (msleep_interruptible(100) != 0)
  35741. + return -EINTR;
  35742. + rc = usb_ep_set_halt(fsg->bulk_in);
  35743. + }
  35744. + return rc;
  35745. +}
  35746. +
  35747. +static int wedge_bulk_in_endpoint(struct fsg_dev *fsg)
  35748. +{
  35749. + int rc;
  35750. +
  35751. + DBG(fsg, "bulk-in set wedge\n");
  35752. + rc = usb_ep_set_wedge(fsg->bulk_in);
  35753. + if (rc == -EAGAIN)
  35754. + VDBG(fsg, "delayed bulk-in endpoint wedge\n");
  35755. + while (rc != 0) {
  35756. + if (rc != -EAGAIN) {
  35757. + WARNING(fsg, "usb_ep_set_wedge -> %d\n", rc);
  35758. + rc = 0;
  35759. + break;
  35760. + }
  35761. +
  35762. + /* Wait for a short time and then try again */
  35763. + if (msleep_interruptible(100) != 0)
  35764. + return -EINTR;
  35765. + rc = usb_ep_set_wedge(fsg->bulk_in);
  35766. + }
  35767. + return rc;
  35768. +}
  35769. +
  35770. +static int throw_away_data(struct fsg_dev *fsg)
  35771. +{
  35772. + struct fsg_buffhd *bh;
  35773. + u32 amount;
  35774. + int rc;
  35775. +
  35776. + while ((bh = fsg->next_buffhd_to_drain)->state != BUF_STATE_EMPTY ||
  35777. + fsg->usb_amount_left > 0) {
  35778. +
  35779. + /* Throw away the data in a filled buffer */
  35780. + if (bh->state == BUF_STATE_FULL) {
  35781. + smp_rmb();
  35782. + bh->state = BUF_STATE_EMPTY;
  35783. + fsg->next_buffhd_to_drain = bh->next;
  35784. +
  35785. + /* A short packet or an error ends everything */
  35786. + if (bh->outreq->actual < bh->bulk_out_intended_length ||
  35787. + bh->outreq->status != 0) {
  35788. + raise_exception(fsg, FSG_STATE_ABORT_BULK_OUT);
  35789. + return -EINTR;
  35790. + }
  35791. + continue;
  35792. + }
  35793. +
  35794. + /* Try to submit another request if we need one */
  35795. + bh = fsg->next_buffhd_to_fill;
  35796. + if (bh->state == BUF_STATE_EMPTY && fsg->usb_amount_left > 0) {
  35797. + amount = min(fsg->usb_amount_left,
  35798. + (u32) mod_data.buflen);
  35799. +
  35800. + /* Except at the end of the transfer, amount will be
  35801. + * equal to the buffer size, which is divisible by
  35802. + * the bulk-out maxpacket size.
  35803. + */
  35804. + set_bulk_out_req_length(fsg, bh, amount);
  35805. + start_transfer(fsg, fsg->bulk_out, bh->outreq,
  35806. + &bh->outreq_busy, &bh->state);
  35807. + fsg->next_buffhd_to_fill = bh->next;
  35808. + fsg->usb_amount_left -= amount;
  35809. + continue;
  35810. + }
  35811. +
  35812. + /* Otherwise wait for something to happen */
  35813. + rc = sleep_thread(fsg);
  35814. + if (rc)
  35815. + return rc;
  35816. + }
  35817. + return 0;
  35818. +}
  35819. +
  35820. +
  35821. +static int finish_reply(struct fsg_dev *fsg)
  35822. +{
  35823. + struct fsg_buffhd *bh = fsg->next_buffhd_to_fill;
  35824. + int rc = 0;
  35825. +
  35826. + switch (fsg->data_dir) {
  35827. + case DATA_DIR_NONE:
  35828. + break; // Nothing to send
  35829. +
  35830. + /* If we don't know whether the host wants to read or write,
  35831. + * this must be CB or CBI with an unknown command. We mustn't
  35832. + * try to send or receive any data. So stall both bulk pipes
  35833. + * if we can and wait for a reset. */
  35834. + case DATA_DIR_UNKNOWN:
  35835. + if (mod_data.can_stall) {
  35836. + fsg_set_halt(fsg, fsg->bulk_out);
  35837. + rc = halt_bulk_in_endpoint(fsg);
  35838. + }
  35839. + break;
  35840. +
  35841. + /* All but the last buffer of data must have already been sent */
  35842. + case DATA_DIR_TO_HOST:
  35843. + if (fsg->data_size == 0)
  35844. + ; // Nothing to send
  35845. +
  35846. + /* If there's no residue, simply send the last buffer */
  35847. + else if (fsg->residue == 0) {
  35848. + bh->inreq->zero = 0;
  35849. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  35850. + &bh->inreq_busy, &bh->state);
  35851. + fsg->next_buffhd_to_fill = bh->next;
  35852. + }
  35853. +
  35854. + /* There is a residue. For CB and CBI, simply mark the end
  35855. + * of the data with a short packet. However, if we are
  35856. + * allowed to stall, there was no data at all (residue ==
  35857. + * data_size), and the command failed (invalid LUN or
  35858. + * sense data is set), then halt the bulk-in endpoint
  35859. + * instead. */
  35860. + else if (!transport_is_bbb()) {
  35861. + if (mod_data.can_stall &&
  35862. + fsg->residue == fsg->data_size &&
  35863. + (!fsg->curlun || fsg->curlun->sense_data != SS_NO_SENSE)) {
  35864. + bh->state = BUF_STATE_EMPTY;
  35865. + rc = halt_bulk_in_endpoint(fsg);
  35866. + } else {
  35867. + bh->inreq->zero = 1;
  35868. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  35869. + &bh->inreq_busy, &bh->state);
  35870. + fsg->next_buffhd_to_fill = bh->next;
  35871. + }
  35872. + }
  35873. +
  35874. + /*
  35875. + * For Bulk-only, mark the end of the data with a short
  35876. + * packet. If we are allowed to stall, halt the bulk-in
  35877. + * endpoint. (Note: This violates the Bulk-Only Transport
  35878. + * specification, which requires us to pad the data if we
  35879. + * don't halt the endpoint. Presumably nobody will mind.)
  35880. + */
  35881. + else {
  35882. + bh->inreq->zero = 1;
  35883. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  35884. + &bh->inreq_busy, &bh->state);
  35885. + fsg->next_buffhd_to_fill = bh->next;
  35886. + if (mod_data.can_stall)
  35887. + rc = halt_bulk_in_endpoint(fsg);
  35888. + }
  35889. + break;
  35890. +
  35891. + /* We have processed all we want from the data the host has sent.
  35892. + * There may still be outstanding bulk-out requests. */
  35893. + case DATA_DIR_FROM_HOST:
  35894. + if (fsg->residue == 0)
  35895. + ; // Nothing to receive
  35896. +
  35897. + /* Did the host stop sending unexpectedly early? */
  35898. + else if (fsg->short_packet_received) {
  35899. + raise_exception(fsg, FSG_STATE_ABORT_BULK_OUT);
  35900. + rc = -EINTR;
  35901. + }
  35902. +
  35903. + /* We haven't processed all the incoming data. Even though
  35904. + * we may be allowed to stall, doing so would cause a race.
  35905. + * The controller may already have ACK'ed all the remaining
  35906. + * bulk-out packets, in which case the host wouldn't see a
  35907. + * STALL. Not realizing the endpoint was halted, it wouldn't
  35908. + * clear the halt -- leading to problems later on. */
  35909. +#if 0
  35910. + else if (mod_data.can_stall) {
  35911. + fsg_set_halt(fsg, fsg->bulk_out);
  35912. + raise_exception(fsg, FSG_STATE_ABORT_BULK_OUT);
  35913. + rc = -EINTR;
  35914. + }
  35915. +#endif
  35916. +
  35917. + /* We can't stall. Read in the excess data and throw it
  35918. + * all away. */
  35919. + else
  35920. + rc = throw_away_data(fsg);
  35921. + break;
  35922. + }
  35923. + return rc;
  35924. +}
  35925. +
  35926. +
  35927. +static int send_status(struct fsg_dev *fsg)
  35928. +{
  35929. + struct fsg_lun *curlun = fsg->curlun;
  35930. + struct fsg_buffhd *bh;
  35931. + int rc;
  35932. + u8 status = US_BULK_STAT_OK;
  35933. + u32 sd, sdinfo = 0;
  35934. +
  35935. + /* Wait for the next buffer to become available */
  35936. + bh = fsg->next_buffhd_to_fill;
  35937. + while (bh->state != BUF_STATE_EMPTY) {
  35938. + rc = sleep_thread(fsg);
  35939. + if (rc)
  35940. + return rc;
  35941. + }
  35942. +
  35943. + if (curlun) {
  35944. + sd = curlun->sense_data;
  35945. + sdinfo = curlun->sense_data_info;
  35946. + } else if (fsg->bad_lun_okay)
  35947. + sd = SS_NO_SENSE;
  35948. + else
  35949. + sd = SS_LOGICAL_UNIT_NOT_SUPPORTED;
  35950. +
  35951. + if (fsg->phase_error) {
  35952. + DBG(fsg, "sending phase-error status\n");
  35953. + status = US_BULK_STAT_PHASE;
  35954. + sd = SS_INVALID_COMMAND;
  35955. + } else if (sd != SS_NO_SENSE) {
  35956. + DBG(fsg, "sending command-failure status\n");
  35957. + status = US_BULK_STAT_FAIL;
  35958. + VDBG(fsg, " sense data: SK x%02x, ASC x%02x, ASCQ x%02x;"
  35959. + " info x%x\n",
  35960. + SK(sd), ASC(sd), ASCQ(sd), sdinfo);
  35961. + }
  35962. +
  35963. + if (transport_is_bbb()) {
  35964. + struct bulk_cs_wrap *csw = bh->buf;
  35965. +
  35966. + /* Store and send the Bulk-only CSW */
  35967. + csw->Signature = cpu_to_le32(US_BULK_CS_SIGN);
  35968. + csw->Tag = fsg->tag;
  35969. + csw->Residue = cpu_to_le32(fsg->residue);
  35970. + csw->Status = status;
  35971. +
  35972. + bh->inreq->length = US_BULK_CS_WRAP_LEN;
  35973. + bh->inreq->zero = 0;
  35974. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  35975. + &bh->inreq_busy, &bh->state);
  35976. +
  35977. + } else if (mod_data.transport_type == USB_PR_CB) {
  35978. +
  35979. + /* Control-Bulk transport has no status phase! */
  35980. + return 0;
  35981. +
  35982. + } else { // USB_PR_CBI
  35983. + struct interrupt_data *buf = bh->buf;
  35984. +
  35985. + /* Store and send the Interrupt data. UFI sends the ASC
  35986. + * and ASCQ bytes. Everything else sends a Type (which
  35987. + * is always 0) and the status Value. */
  35988. + if (mod_data.protocol_type == USB_SC_UFI) {
  35989. + buf->bType = ASC(sd);
  35990. + buf->bValue = ASCQ(sd);
  35991. + } else {
  35992. + buf->bType = 0;
  35993. + buf->bValue = status;
  35994. + }
  35995. + fsg->intreq->length = CBI_INTERRUPT_DATA_LEN;
  35996. +
  35997. + fsg->intr_buffhd = bh; // Point to the right buffhd
  35998. + fsg->intreq->buf = bh->inreq->buf;
  35999. + fsg->intreq->context = bh;
  36000. + start_transfer(fsg, fsg->intr_in, fsg->intreq,
  36001. + &fsg->intreq_busy, &bh->state);
  36002. + }
  36003. +
  36004. + fsg->next_buffhd_to_fill = bh->next;
  36005. + return 0;
  36006. +}
  36007. +
  36008. +
  36009. +/*-------------------------------------------------------------------------*/
  36010. +
  36011. +/* Check whether the command is properly formed and whether its data size
  36012. + * and direction agree with the values we already have. */
  36013. +static int check_command(struct fsg_dev *fsg, int cmnd_size,
  36014. + enum data_direction data_dir, unsigned int mask,
  36015. + int needs_medium, const char *name)
  36016. +{
  36017. + int i;
  36018. + int lun = fsg->cmnd[1] >> 5;
  36019. + static const char dirletter[4] = {'u', 'o', 'i', 'n'};
  36020. + char hdlen[20];
  36021. + struct fsg_lun *curlun;
  36022. +
  36023. + /* Adjust the expected cmnd_size for protocol encapsulation padding.
  36024. + * Transparent SCSI doesn't pad. */
  36025. + if (protocol_is_scsi())
  36026. + ;
  36027. +
  36028. + /* There's some disagreement as to whether RBC pads commands or not.
  36029. + * We'll play it safe and accept either form. */
  36030. + else if (mod_data.protocol_type == USB_SC_RBC) {
  36031. + if (fsg->cmnd_size == 12)
  36032. + cmnd_size = 12;
  36033. +
  36034. + /* All the other protocols pad to 12 bytes */
  36035. + } else
  36036. + cmnd_size = 12;
  36037. +
  36038. + hdlen[0] = 0;
  36039. + if (fsg->data_dir != DATA_DIR_UNKNOWN)
  36040. + sprintf(hdlen, ", H%c=%u", dirletter[(int) fsg->data_dir],
  36041. + fsg->data_size);
  36042. + VDBG(fsg, "SCSI command: %s; Dc=%d, D%c=%u; Hc=%d%s\n",
  36043. + name, cmnd_size, dirletter[(int) data_dir],
  36044. + fsg->data_size_from_cmnd, fsg->cmnd_size, hdlen);
  36045. +
  36046. + /* We can't reply at all until we know the correct data direction
  36047. + * and size. */
  36048. + if (fsg->data_size_from_cmnd == 0)
  36049. + data_dir = DATA_DIR_NONE;
  36050. + if (fsg->data_dir == DATA_DIR_UNKNOWN) { // CB or CBI
  36051. + fsg->data_dir = data_dir;
  36052. + fsg->data_size = fsg->data_size_from_cmnd;
  36053. +
  36054. + } else { // Bulk-only
  36055. + if (fsg->data_size < fsg->data_size_from_cmnd) {
  36056. +
  36057. + /* Host data size < Device data size is a phase error.
  36058. + * Carry out the command, but only transfer as much
  36059. + * as we are allowed. */
  36060. + fsg->data_size_from_cmnd = fsg->data_size;
  36061. + fsg->phase_error = 1;
  36062. + }
  36063. + }
  36064. + fsg->residue = fsg->usb_amount_left = fsg->data_size;
  36065. +
  36066. + /* Conflicting data directions is a phase error */
  36067. + if (fsg->data_dir != data_dir && fsg->data_size_from_cmnd > 0) {
  36068. + fsg->phase_error = 1;
  36069. + return -EINVAL;
  36070. + }
  36071. +
  36072. + /* Verify the length of the command itself */
  36073. + if (cmnd_size != fsg->cmnd_size) {
  36074. +
  36075. + /* Special case workaround: There are plenty of buggy SCSI
  36076. + * implementations. Many have issues with cbw->Length
  36077. + * field passing a wrong command size. For those cases we
  36078. + * always try to work around the problem by using the length
  36079. + * sent by the host side provided it is at least as large
  36080. + * as the correct command length.
  36081. + * Examples of such cases would be MS-Windows, which issues
  36082. + * REQUEST SENSE with cbw->Length == 12 where it should
  36083. + * be 6, and xbox360 issuing INQUIRY, TEST UNIT READY and
  36084. + * REQUEST SENSE with cbw->Length == 10 where it should
  36085. + * be 6 as well.
  36086. + */
  36087. + if (cmnd_size <= fsg->cmnd_size) {
  36088. + DBG(fsg, "%s is buggy! Expected length %d "
  36089. + "but we got %d\n", name,
  36090. + cmnd_size, fsg->cmnd_size);
  36091. + cmnd_size = fsg->cmnd_size;
  36092. + } else {
  36093. + fsg->phase_error = 1;
  36094. + return -EINVAL;
  36095. + }
  36096. + }
  36097. +
  36098. + /* Check that the LUN values are consistent */
  36099. + if (transport_is_bbb()) {
  36100. + if (fsg->lun != lun)
  36101. + DBG(fsg, "using LUN %d from CBW, "
  36102. + "not LUN %d from CDB\n",
  36103. + fsg->lun, lun);
  36104. + }
  36105. +
  36106. + /* Check the LUN */
  36107. + curlun = fsg->curlun;
  36108. + if (curlun) {
  36109. + if (fsg->cmnd[0] != REQUEST_SENSE) {
  36110. + curlun->sense_data = SS_NO_SENSE;
  36111. + curlun->sense_data_info = 0;
  36112. + curlun->info_valid = 0;
  36113. + }
  36114. + } else {
  36115. + fsg->bad_lun_okay = 0;
  36116. +
  36117. + /* INQUIRY and REQUEST SENSE commands are explicitly allowed
  36118. + * to use unsupported LUNs; all others may not. */
  36119. + if (fsg->cmnd[0] != INQUIRY &&
  36120. + fsg->cmnd[0] != REQUEST_SENSE) {
  36121. + DBG(fsg, "unsupported LUN %d\n", fsg->lun);
  36122. + return -EINVAL;
  36123. + }
  36124. + }
  36125. +
  36126. + /* If a unit attention condition exists, only INQUIRY and
  36127. + * REQUEST SENSE commands are allowed; anything else must fail. */
  36128. + if (curlun && curlun->unit_attention_data != SS_NO_SENSE &&
  36129. + fsg->cmnd[0] != INQUIRY &&
  36130. + fsg->cmnd[0] != REQUEST_SENSE) {
  36131. + curlun->sense_data = curlun->unit_attention_data;
  36132. + curlun->unit_attention_data = SS_NO_SENSE;
  36133. + return -EINVAL;
  36134. + }
  36135. +
  36136. + /* Check that only command bytes listed in the mask are non-zero */
  36137. + fsg->cmnd[1] &= 0x1f; // Mask away the LUN
  36138. + for (i = 1; i < cmnd_size; ++i) {
  36139. + if (fsg->cmnd[i] && !(mask & (1 << i))) {
  36140. + if (curlun)
  36141. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36142. + return -EINVAL;
  36143. + }
  36144. + }
  36145. +
  36146. + /* If the medium isn't mounted and the command needs to access
  36147. + * it, return an error. */
  36148. + if (curlun && !fsg_lun_is_open(curlun) && needs_medium) {
  36149. + curlun->sense_data = SS_MEDIUM_NOT_PRESENT;
  36150. + return -EINVAL;
  36151. + }
  36152. +
  36153. + return 0;
  36154. +}
  36155. +
  36156. +/* wrapper of check_command for data size in blocks handling */
  36157. +static int check_command_size_in_blocks(struct fsg_dev *fsg, int cmnd_size,
  36158. + enum data_direction data_dir, unsigned int mask,
  36159. + int needs_medium, const char *name)
  36160. +{
  36161. + if (fsg->curlun)
  36162. + fsg->data_size_from_cmnd <<= fsg->curlun->blkbits;
  36163. + return check_command(fsg, cmnd_size, data_dir,
  36164. + mask, needs_medium, name);
  36165. +}
  36166. +
  36167. +static int do_scsi_command(struct fsg_dev *fsg)
  36168. +{
  36169. + struct fsg_buffhd *bh;
  36170. + int rc;
  36171. + int reply = -EINVAL;
  36172. + int i;
  36173. + static char unknown[16];
  36174. +
  36175. + dump_cdb(fsg);
  36176. +
  36177. + /* Wait for the next buffer to become available for data or status */
  36178. + bh = fsg->next_buffhd_to_drain = fsg->next_buffhd_to_fill;
  36179. + while (bh->state != BUF_STATE_EMPTY) {
  36180. + rc = sleep_thread(fsg);
  36181. + if (rc)
  36182. + return rc;
  36183. + }
  36184. + fsg->phase_error = 0;
  36185. + fsg->short_packet_received = 0;
  36186. +
  36187. + down_read(&fsg->filesem); // We're using the backing file
  36188. + switch (fsg->cmnd[0]) {
  36189. +
  36190. + case INQUIRY:
  36191. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  36192. + if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
  36193. + (1<<4), 0,
  36194. + "INQUIRY")) == 0)
  36195. + reply = do_inquiry(fsg, bh);
  36196. + break;
  36197. +
  36198. + case MODE_SELECT:
  36199. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  36200. + if ((reply = check_command(fsg, 6, DATA_DIR_FROM_HOST,
  36201. + (1<<1) | (1<<4), 0,
  36202. + "MODE SELECT(6)")) == 0)
  36203. + reply = do_mode_select(fsg, bh);
  36204. + break;
  36205. +
  36206. + case MODE_SELECT_10:
  36207. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  36208. + if ((reply = check_command(fsg, 10, DATA_DIR_FROM_HOST,
  36209. + (1<<1) | (3<<7), 0,
  36210. + "MODE SELECT(10)")) == 0)
  36211. + reply = do_mode_select(fsg, bh);
  36212. + break;
  36213. +
  36214. + case MODE_SENSE:
  36215. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  36216. + if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
  36217. + (1<<1) | (1<<2) | (1<<4), 0,
  36218. + "MODE SENSE(6)")) == 0)
  36219. + reply = do_mode_sense(fsg, bh);
  36220. + break;
  36221. +
  36222. + case MODE_SENSE_10:
  36223. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  36224. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  36225. + (1<<1) | (1<<2) | (3<<7), 0,
  36226. + "MODE SENSE(10)")) == 0)
  36227. + reply = do_mode_sense(fsg, bh);
  36228. + break;
  36229. +
  36230. + case ALLOW_MEDIUM_REMOVAL:
  36231. + fsg->data_size_from_cmnd = 0;
  36232. + if ((reply = check_command(fsg, 6, DATA_DIR_NONE,
  36233. + (1<<4), 0,
  36234. + "PREVENT-ALLOW MEDIUM REMOVAL")) == 0)
  36235. + reply = do_prevent_allow(fsg);
  36236. + break;
  36237. +
  36238. + case READ_6:
  36239. + i = fsg->cmnd[4];
  36240. + fsg->data_size_from_cmnd = (i == 0) ? 256 : i;
  36241. + if ((reply = check_command_size_in_blocks(fsg, 6,
  36242. + DATA_DIR_TO_HOST,
  36243. + (7<<1) | (1<<4), 1,
  36244. + "READ(6)")) == 0)
  36245. + reply = do_read(fsg);
  36246. + break;
  36247. +
  36248. + case READ_10:
  36249. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  36250. + if ((reply = check_command_size_in_blocks(fsg, 10,
  36251. + DATA_DIR_TO_HOST,
  36252. + (1<<1) | (0xf<<2) | (3<<7), 1,
  36253. + "READ(10)")) == 0)
  36254. + reply = do_read(fsg);
  36255. + break;
  36256. +
  36257. + case READ_12:
  36258. + fsg->data_size_from_cmnd = get_unaligned_be32(&fsg->cmnd[6]);
  36259. + if ((reply = check_command_size_in_blocks(fsg, 12,
  36260. + DATA_DIR_TO_HOST,
  36261. + (1<<1) | (0xf<<2) | (0xf<<6), 1,
  36262. + "READ(12)")) == 0)
  36263. + reply = do_read(fsg);
  36264. + break;
  36265. +
  36266. + case READ_CAPACITY:
  36267. + fsg->data_size_from_cmnd = 8;
  36268. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  36269. + (0xf<<2) | (1<<8), 1,
  36270. + "READ CAPACITY")) == 0)
  36271. + reply = do_read_capacity(fsg, bh);
  36272. + break;
  36273. +
  36274. + case READ_HEADER:
  36275. + if (!mod_data.cdrom)
  36276. + goto unknown_cmnd;
  36277. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  36278. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  36279. + (3<<7) | (0x1f<<1), 1,
  36280. + "READ HEADER")) == 0)
  36281. + reply = do_read_header(fsg, bh);
  36282. + break;
  36283. +
  36284. + case READ_TOC:
  36285. + if (!mod_data.cdrom)
  36286. + goto unknown_cmnd;
  36287. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  36288. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  36289. + (7<<6) | (1<<1), 1,
  36290. + "READ TOC")) == 0)
  36291. + reply = do_read_toc(fsg, bh);
  36292. + break;
  36293. +
  36294. + case READ_FORMAT_CAPACITIES:
  36295. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  36296. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  36297. + (3<<7), 1,
  36298. + "READ FORMAT CAPACITIES")) == 0)
  36299. + reply = do_read_format_capacities(fsg, bh);
  36300. + break;
  36301. +
  36302. + case REQUEST_SENSE:
  36303. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  36304. + if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
  36305. + (1<<4), 0,
  36306. + "REQUEST SENSE")) == 0)
  36307. + reply = do_request_sense(fsg, bh);
  36308. + break;
  36309. +
  36310. + case START_STOP:
  36311. + fsg->data_size_from_cmnd = 0;
  36312. + if ((reply = check_command(fsg, 6, DATA_DIR_NONE,
  36313. + (1<<1) | (1<<4), 0,
  36314. + "START-STOP UNIT")) == 0)
  36315. + reply = do_start_stop(fsg);
  36316. + break;
  36317. +
  36318. + case SYNCHRONIZE_CACHE:
  36319. + fsg->data_size_from_cmnd = 0;
  36320. + if ((reply = check_command(fsg, 10, DATA_DIR_NONE,
  36321. + (0xf<<2) | (3<<7), 1,
  36322. + "SYNCHRONIZE CACHE")) == 0)
  36323. + reply = do_synchronize_cache(fsg);
  36324. + break;
  36325. +
  36326. + case TEST_UNIT_READY:
  36327. + fsg->data_size_from_cmnd = 0;
  36328. + reply = check_command(fsg, 6, DATA_DIR_NONE,
  36329. + 0, 1,
  36330. + "TEST UNIT READY");
  36331. + break;
  36332. +
  36333. + /* Although optional, this command is used by MS-Windows. We
  36334. + * support a minimal version: BytChk must be 0. */
  36335. + case VERIFY:
  36336. + fsg->data_size_from_cmnd = 0;
  36337. + if ((reply = check_command(fsg, 10, DATA_DIR_NONE,
  36338. + (1<<1) | (0xf<<2) | (3<<7), 1,
  36339. + "VERIFY")) == 0)
  36340. + reply = do_verify(fsg);
  36341. + break;
  36342. +
  36343. + case WRITE_6:
  36344. + i = fsg->cmnd[4];
  36345. + fsg->data_size_from_cmnd = (i == 0) ? 256 : i;
  36346. + if ((reply = check_command_size_in_blocks(fsg, 6,
  36347. + DATA_DIR_FROM_HOST,
  36348. + (7<<1) | (1<<4), 1,
  36349. + "WRITE(6)")) == 0)
  36350. + reply = do_write(fsg);
  36351. + break;
  36352. +
  36353. + case WRITE_10:
  36354. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  36355. + if ((reply = check_command_size_in_blocks(fsg, 10,
  36356. + DATA_DIR_FROM_HOST,
  36357. + (1<<1) | (0xf<<2) | (3<<7), 1,
  36358. + "WRITE(10)")) == 0)
  36359. + reply = do_write(fsg);
  36360. + break;
  36361. +
  36362. + case WRITE_12:
  36363. + fsg->data_size_from_cmnd = get_unaligned_be32(&fsg->cmnd[6]);
  36364. + if ((reply = check_command_size_in_blocks(fsg, 12,
  36365. + DATA_DIR_FROM_HOST,
  36366. + (1<<1) | (0xf<<2) | (0xf<<6), 1,
  36367. + "WRITE(12)")) == 0)
  36368. + reply = do_write(fsg);
  36369. + break;
  36370. +
  36371. + /* Some mandatory commands that we recognize but don't implement.
  36372. + * They don't mean much in this setting. It's left as an exercise
  36373. + * for anyone interested to implement RESERVE and RELEASE in terms
  36374. + * of Posix locks. */
  36375. + case FORMAT_UNIT:
  36376. + case RELEASE:
  36377. + case RESERVE:
  36378. + case SEND_DIAGNOSTIC:
  36379. + // Fall through
  36380. +
  36381. + default:
  36382. + unknown_cmnd:
  36383. + fsg->data_size_from_cmnd = 0;
  36384. + sprintf(unknown, "Unknown x%02x", fsg->cmnd[0]);
  36385. + if ((reply = check_command(fsg, fsg->cmnd_size,
  36386. + DATA_DIR_UNKNOWN, ~0, 0, unknown)) == 0) {
  36387. + fsg->curlun->sense_data = SS_INVALID_COMMAND;
  36388. + reply = -EINVAL;
  36389. + }
  36390. + break;
  36391. + }
  36392. + up_read(&fsg->filesem);
  36393. +
  36394. + if (reply == -EINTR || signal_pending(current))
  36395. + return -EINTR;
  36396. +
  36397. + /* Set up the single reply buffer for finish_reply() */
  36398. + if (reply == -EINVAL)
  36399. + reply = 0; // Error reply length
  36400. + if (reply >= 0 && fsg->data_dir == DATA_DIR_TO_HOST) {
  36401. + reply = min((u32) reply, fsg->data_size_from_cmnd);
  36402. + bh->inreq->length = reply;
  36403. + bh->state = BUF_STATE_FULL;
  36404. + fsg->residue -= reply;
  36405. + } // Otherwise it's already set
  36406. +
  36407. + return 0;
  36408. +}
  36409. +
  36410. +
  36411. +/*-------------------------------------------------------------------------*/
  36412. +
  36413. +static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  36414. +{
  36415. + struct usb_request *req = bh->outreq;
  36416. + struct bulk_cb_wrap *cbw = req->buf;
  36417. +
  36418. + /* Was this a real packet? Should it be ignored? */
  36419. + if (req->status || test_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags))
  36420. + return -EINVAL;
  36421. +
  36422. + /* Is the CBW valid? */
  36423. + if (req->actual != US_BULK_CB_WRAP_LEN ||
  36424. + cbw->Signature != cpu_to_le32(
  36425. + US_BULK_CB_SIGN)) {
  36426. + DBG(fsg, "invalid CBW: len %u sig 0x%x\n",
  36427. + req->actual,
  36428. + le32_to_cpu(cbw->Signature));
  36429. +
  36430. + /* The Bulk-only spec says we MUST stall the IN endpoint
  36431. + * (6.6.1), so it's unavoidable. It also says we must
  36432. + * retain this state until the next reset, but there's
  36433. + * no way to tell the controller driver it should ignore
  36434. + * Clear-Feature(HALT) requests.
  36435. + *
  36436. + * We aren't required to halt the OUT endpoint; instead
  36437. + * we can simply accept and discard any data received
  36438. + * until the next reset. */
  36439. + wedge_bulk_in_endpoint(fsg);
  36440. + set_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
  36441. + return -EINVAL;
  36442. + }
  36443. +
  36444. + /* Is the CBW meaningful? */
  36445. + if (cbw->Lun >= FSG_MAX_LUNS || cbw->Flags & ~US_BULK_FLAG_IN ||
  36446. + cbw->Length <= 0 || cbw->Length > MAX_COMMAND_SIZE) {
  36447. + DBG(fsg, "non-meaningful CBW: lun = %u, flags = 0x%x, "
  36448. + "cmdlen %u\n",
  36449. + cbw->Lun, cbw->Flags, cbw->Length);
  36450. +
  36451. + /* We can do anything we want here, so let's stall the
  36452. + * bulk pipes if we are allowed to. */
  36453. + if (mod_data.can_stall) {
  36454. + fsg_set_halt(fsg, fsg->bulk_out);
  36455. + halt_bulk_in_endpoint(fsg);
  36456. + }
  36457. + return -EINVAL;
  36458. + }
  36459. +
  36460. + /* Save the command for later */
  36461. + fsg->cmnd_size = cbw->Length;
  36462. + memcpy(fsg->cmnd, cbw->CDB, fsg->cmnd_size);
  36463. + if (cbw->Flags & US_BULK_FLAG_IN)
  36464. + fsg->data_dir = DATA_DIR_TO_HOST;
  36465. + else
  36466. + fsg->data_dir = DATA_DIR_FROM_HOST;
  36467. + fsg->data_size = le32_to_cpu(cbw->DataTransferLength);
  36468. + if (fsg->data_size == 0)
  36469. + fsg->data_dir = DATA_DIR_NONE;
  36470. + fsg->lun = cbw->Lun;
  36471. + fsg->tag = cbw->Tag;
  36472. + return 0;
  36473. +}
  36474. +
  36475. +
  36476. +static int get_next_command(struct fsg_dev *fsg)
  36477. +{
  36478. + struct fsg_buffhd *bh;
  36479. + int rc = 0;
  36480. +
  36481. + if (transport_is_bbb()) {
  36482. +
  36483. + /* Wait for the next buffer to become available */
  36484. + bh = fsg->next_buffhd_to_fill;
  36485. + while (bh->state != BUF_STATE_EMPTY) {
  36486. + rc = sleep_thread(fsg);
  36487. + if (rc)
  36488. + return rc;
  36489. + }
  36490. +
  36491. + /* Queue a request to read a Bulk-only CBW */
  36492. + set_bulk_out_req_length(fsg, bh, US_BULK_CB_WRAP_LEN);
  36493. + start_transfer(fsg, fsg->bulk_out, bh->outreq,
  36494. + &bh->outreq_busy, &bh->state);
  36495. +
  36496. + /* We will drain the buffer in software, which means we
  36497. + * can reuse it for the next filling. No need to advance
  36498. + * next_buffhd_to_fill. */
  36499. +
  36500. + /* Wait for the CBW to arrive */
  36501. + while (bh->state != BUF_STATE_FULL) {
  36502. + rc = sleep_thread(fsg);
  36503. + if (rc)
  36504. + return rc;
  36505. + }
  36506. + smp_rmb();
  36507. + rc = received_cbw(fsg, bh);
  36508. + bh->state = BUF_STATE_EMPTY;
  36509. +
  36510. + } else { // USB_PR_CB or USB_PR_CBI
  36511. +
  36512. + /* Wait for the next command to arrive */
  36513. + while (fsg->cbbuf_cmnd_size == 0) {
  36514. + rc = sleep_thread(fsg);
  36515. + if (rc)
  36516. + return rc;
  36517. + }
  36518. +
  36519. + /* Is the previous status interrupt request still busy?
  36520. + * The host is allowed to skip reading the status,
  36521. + * so we must cancel it. */
  36522. + if (fsg->intreq_busy)
  36523. + usb_ep_dequeue(fsg->intr_in, fsg->intreq);
  36524. +
  36525. + /* Copy the command and mark the buffer empty */
  36526. + fsg->data_dir = DATA_DIR_UNKNOWN;
  36527. + spin_lock_irq(&fsg->lock);
  36528. + fsg->cmnd_size = fsg->cbbuf_cmnd_size;
  36529. + memcpy(fsg->cmnd, fsg->cbbuf_cmnd, fsg->cmnd_size);
  36530. + fsg->cbbuf_cmnd_size = 0;
  36531. + spin_unlock_irq(&fsg->lock);
  36532. +
  36533. + /* Use LUN from the command */
  36534. + fsg->lun = fsg->cmnd[1] >> 5;
  36535. + }
  36536. +
  36537. + /* Update current lun */
  36538. + if (fsg->lun >= 0 && fsg->lun < fsg->nluns)
  36539. + fsg->curlun = &fsg->luns[fsg->lun];
  36540. + else
  36541. + fsg->curlun = NULL;
  36542. +
  36543. + return rc;
  36544. +}
  36545. +
  36546. +
  36547. +/*-------------------------------------------------------------------------*/
  36548. +
  36549. +static int enable_endpoint(struct fsg_dev *fsg, struct usb_ep *ep,
  36550. + const struct usb_endpoint_descriptor *d)
  36551. +{
  36552. + int rc;
  36553. +
  36554. + ep->driver_data = fsg;
  36555. + ep->desc = d;
  36556. + rc = usb_ep_enable(ep);
  36557. + if (rc)
  36558. + ERROR(fsg, "can't enable %s, result %d\n", ep->name, rc);
  36559. + return rc;
  36560. +}
  36561. +
  36562. +static int alloc_request(struct fsg_dev *fsg, struct usb_ep *ep,
  36563. + struct usb_request **preq)
  36564. +{
  36565. + *preq = usb_ep_alloc_request(ep, GFP_ATOMIC);
  36566. + if (*preq)
  36567. + return 0;
  36568. + ERROR(fsg, "can't allocate request for %s\n", ep->name);
  36569. + return -ENOMEM;
  36570. +}
  36571. +
  36572. +/*
  36573. + * Reset interface setting and re-init endpoint state (toggle etc).
  36574. + * Call with altsetting < 0 to disable the interface. The only other
  36575. + * available altsetting is 0, which enables the interface.
  36576. + */
  36577. +static int do_set_interface(struct fsg_dev *fsg, int altsetting)
  36578. +{
  36579. + int rc = 0;
  36580. + int i;
  36581. + const struct usb_endpoint_descriptor *d;
  36582. +
  36583. + if (fsg->running)
  36584. + DBG(fsg, "reset interface\n");
  36585. +
  36586. +reset:
  36587. + /* Deallocate the requests */
  36588. + for (i = 0; i < fsg_num_buffers; ++i) {
  36589. + struct fsg_buffhd *bh = &fsg->buffhds[i];
  36590. +
  36591. + if (bh->inreq) {
  36592. + usb_ep_free_request(fsg->bulk_in, bh->inreq);
  36593. + bh->inreq = NULL;
  36594. + }
  36595. + if (bh->outreq) {
  36596. + usb_ep_free_request(fsg->bulk_out, bh->outreq);
  36597. + bh->outreq = NULL;
  36598. + }
  36599. + }
  36600. + if (fsg->intreq) {
  36601. + usb_ep_free_request(fsg->intr_in, fsg->intreq);
  36602. + fsg->intreq = NULL;
  36603. + }
  36604. +
  36605. + /* Disable the endpoints */
  36606. + if (fsg->bulk_in_enabled) {
  36607. + usb_ep_disable(fsg->bulk_in);
  36608. + fsg->bulk_in_enabled = 0;
  36609. + }
  36610. + if (fsg->bulk_out_enabled) {
  36611. + usb_ep_disable(fsg->bulk_out);
  36612. + fsg->bulk_out_enabled = 0;
  36613. + }
  36614. + if (fsg->intr_in_enabled) {
  36615. + usb_ep_disable(fsg->intr_in);
  36616. + fsg->intr_in_enabled = 0;
  36617. + }
  36618. +
  36619. + fsg->running = 0;
  36620. + if (altsetting < 0 || rc != 0)
  36621. + return rc;
  36622. +
  36623. + DBG(fsg, "set interface %d\n", altsetting);
  36624. +
  36625. + /* Enable the endpoints */
  36626. + d = fsg_ep_desc(fsg->gadget,
  36627. + &fsg_fs_bulk_in_desc, &fsg_hs_bulk_in_desc,
  36628. + &fsg_ss_bulk_in_desc);
  36629. + if ((rc = enable_endpoint(fsg, fsg->bulk_in, d)) != 0)
  36630. + goto reset;
  36631. + fsg->bulk_in_enabled = 1;
  36632. +
  36633. + d = fsg_ep_desc(fsg->gadget,
  36634. + &fsg_fs_bulk_out_desc, &fsg_hs_bulk_out_desc,
  36635. + &fsg_ss_bulk_out_desc);
  36636. + if ((rc = enable_endpoint(fsg, fsg->bulk_out, d)) != 0)
  36637. + goto reset;
  36638. + fsg->bulk_out_enabled = 1;
  36639. + fsg->bulk_out_maxpacket = usb_endpoint_maxp(d);
  36640. + clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
  36641. +
  36642. + if (transport_is_cbi()) {
  36643. + d = fsg_ep_desc(fsg->gadget,
  36644. + &fsg_fs_intr_in_desc, &fsg_hs_intr_in_desc,
  36645. + &fsg_ss_intr_in_desc);
  36646. + if ((rc = enable_endpoint(fsg, fsg->intr_in, d)) != 0)
  36647. + goto reset;
  36648. + fsg->intr_in_enabled = 1;
  36649. + }
  36650. +
  36651. + /* Allocate the requests */
  36652. + for (i = 0; i < fsg_num_buffers; ++i) {
  36653. + struct fsg_buffhd *bh = &fsg->buffhds[i];
  36654. +
  36655. + if ((rc = alloc_request(fsg, fsg->bulk_in, &bh->inreq)) != 0)
  36656. + goto reset;
  36657. + if ((rc = alloc_request(fsg, fsg->bulk_out, &bh->outreq)) != 0)
  36658. + goto reset;
  36659. + bh->inreq->buf = bh->outreq->buf = bh->buf;
  36660. + bh->inreq->context = bh->outreq->context = bh;
  36661. + bh->inreq->complete = bulk_in_complete;
  36662. + bh->outreq->complete = bulk_out_complete;
  36663. + }
  36664. + if (transport_is_cbi()) {
  36665. + if ((rc = alloc_request(fsg, fsg->intr_in, &fsg->intreq)) != 0)
  36666. + goto reset;
  36667. + fsg->intreq->complete = intr_in_complete;
  36668. + }
  36669. +
  36670. + fsg->running = 1;
  36671. + for (i = 0; i < fsg->nluns; ++i)
  36672. + fsg->luns[i].unit_attention_data = SS_RESET_OCCURRED;
  36673. + return rc;
  36674. +}
  36675. +
  36676. +
  36677. +/*
  36678. + * Change our operational configuration. This code must agree with the code
  36679. + * that returns config descriptors, and with interface altsetting code.
  36680. + *
  36681. + * It's also responsible for power management interactions. Some
  36682. + * configurations might not work with our current power sources.
  36683. + * For now we just assume the gadget is always self-powered.
  36684. + */
  36685. +static int do_set_config(struct fsg_dev *fsg, u8 new_config)
  36686. +{
  36687. + int rc = 0;
  36688. +
  36689. + /* Disable the single interface */
  36690. + if (fsg->config != 0) {
  36691. + DBG(fsg, "reset config\n");
  36692. + fsg->config = 0;
  36693. + rc = do_set_interface(fsg, -1);
  36694. + }
  36695. +
  36696. + /* Enable the interface */
  36697. + if (new_config != 0) {
  36698. + fsg->config = new_config;
  36699. + if ((rc = do_set_interface(fsg, 0)) != 0)
  36700. + fsg->config = 0; // Reset on errors
  36701. + else
  36702. + INFO(fsg, "%s config #%d\n",
  36703. + usb_speed_string(fsg->gadget->speed),
  36704. + fsg->config);
  36705. + }
  36706. + return rc;
  36707. +}
  36708. +
  36709. +
  36710. +/*-------------------------------------------------------------------------*/
  36711. +
  36712. +static void handle_exception(struct fsg_dev *fsg)
  36713. +{
  36714. + siginfo_t info;
  36715. + int sig;
  36716. + int i;
  36717. + int num_active;
  36718. + struct fsg_buffhd *bh;
  36719. + enum fsg_state old_state;
  36720. + u8 new_config;
  36721. + struct fsg_lun *curlun;
  36722. + unsigned int exception_req_tag;
  36723. + int rc;
  36724. +
  36725. + /* Clear the existing signals. Anything but SIGUSR1 is converted
  36726. + * into a high-priority EXIT exception. */
  36727. + for (;;) {
  36728. + sig = dequeue_signal_lock(current, &current->blocked, &info);
  36729. + if (!sig)
  36730. + break;
  36731. + if (sig != SIGUSR1) {
  36732. + if (fsg->state < FSG_STATE_EXIT)
  36733. + DBG(fsg, "Main thread exiting on signal\n");
  36734. + raise_exception(fsg, FSG_STATE_EXIT);
  36735. + }
  36736. + }
  36737. +
  36738. + /* Cancel all the pending transfers */
  36739. + if (fsg->intreq_busy)
  36740. + usb_ep_dequeue(fsg->intr_in, fsg->intreq);
  36741. + for (i = 0; i < fsg_num_buffers; ++i) {
  36742. + bh = &fsg->buffhds[i];
  36743. + if (bh->inreq_busy)
  36744. + usb_ep_dequeue(fsg->bulk_in, bh->inreq);
  36745. + if (bh->outreq_busy)
  36746. + usb_ep_dequeue(fsg->bulk_out, bh->outreq);
  36747. + }
  36748. +
  36749. + /* Wait until everything is idle */
  36750. + for (;;) {
  36751. + num_active = fsg->intreq_busy;
  36752. + for (i = 0; i < fsg_num_buffers; ++i) {
  36753. + bh = &fsg->buffhds[i];
  36754. + num_active += bh->inreq_busy + bh->outreq_busy;
  36755. + }
  36756. + if (num_active == 0)
  36757. + break;
  36758. + if (sleep_thread(fsg))
  36759. + return;
  36760. + }
  36761. +
  36762. + /* Clear out the controller's fifos */
  36763. + if (fsg->bulk_in_enabled)
  36764. + usb_ep_fifo_flush(fsg->bulk_in);
  36765. + if (fsg->bulk_out_enabled)
  36766. + usb_ep_fifo_flush(fsg->bulk_out);
  36767. + if (fsg->intr_in_enabled)
  36768. + usb_ep_fifo_flush(fsg->intr_in);
  36769. +
  36770. + /* Reset the I/O buffer states and pointers, the SCSI
  36771. + * state, and the exception. Then invoke the handler. */
  36772. + spin_lock_irq(&fsg->lock);
  36773. +
  36774. + for (i = 0; i < fsg_num_buffers; ++i) {
  36775. + bh = &fsg->buffhds[i];
  36776. + bh->state = BUF_STATE_EMPTY;
  36777. + }
  36778. + fsg->next_buffhd_to_fill = fsg->next_buffhd_to_drain =
  36779. + &fsg->buffhds[0];
  36780. +
  36781. + exception_req_tag = fsg->exception_req_tag;
  36782. + new_config = fsg->new_config;
  36783. + old_state = fsg->state;
  36784. +
  36785. + if (old_state == FSG_STATE_ABORT_BULK_OUT)
  36786. + fsg->state = FSG_STATE_STATUS_PHASE;
  36787. + else {
  36788. + for (i = 0; i < fsg->nluns; ++i) {
  36789. + curlun = &fsg->luns[i];
  36790. + curlun->prevent_medium_removal = 0;
  36791. + curlun->sense_data = curlun->unit_attention_data =
  36792. + SS_NO_SENSE;
  36793. + curlun->sense_data_info = 0;
  36794. + curlun->info_valid = 0;
  36795. + }
  36796. + fsg->state = FSG_STATE_IDLE;
  36797. + }
  36798. + spin_unlock_irq(&fsg->lock);
  36799. +
  36800. + /* Carry out any extra actions required for the exception */
  36801. + switch (old_state) {
  36802. + default:
  36803. + break;
  36804. +
  36805. + case FSG_STATE_ABORT_BULK_OUT:
  36806. + send_status(fsg);
  36807. + spin_lock_irq(&fsg->lock);
  36808. + if (fsg->state == FSG_STATE_STATUS_PHASE)
  36809. + fsg->state = FSG_STATE_IDLE;
  36810. + spin_unlock_irq(&fsg->lock);
  36811. + break;
  36812. +
  36813. + case FSG_STATE_RESET:
  36814. + /* In case we were forced against our will to halt a
  36815. + * bulk endpoint, clear the halt now. (The SuperH UDC
  36816. + * requires this.) */
  36817. + if (test_and_clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags))
  36818. + usb_ep_clear_halt(fsg->bulk_in);
  36819. +
  36820. + if (transport_is_bbb()) {
  36821. + if (fsg->ep0_req_tag == exception_req_tag)
  36822. + ep0_queue(fsg); // Complete the status stage
  36823. +
  36824. + } else if (transport_is_cbi())
  36825. + send_status(fsg); // Status by interrupt pipe
  36826. +
  36827. + /* Technically this should go here, but it would only be
  36828. + * a waste of time. Ditto for the INTERFACE_CHANGE and
  36829. + * CONFIG_CHANGE cases. */
  36830. + // for (i = 0; i < fsg->nluns; ++i)
  36831. + // fsg->luns[i].unit_attention_data = SS_RESET_OCCURRED;
  36832. + break;
  36833. +
  36834. + case FSG_STATE_INTERFACE_CHANGE:
  36835. + rc = do_set_interface(fsg, 0);
  36836. + if (fsg->ep0_req_tag != exception_req_tag)
  36837. + break;
  36838. + if (rc != 0) // STALL on errors
  36839. + fsg_set_halt(fsg, fsg->ep0);
  36840. + else // Complete the status stage
  36841. + ep0_queue(fsg);
  36842. + break;
  36843. +
  36844. + case FSG_STATE_CONFIG_CHANGE:
  36845. + rc = do_set_config(fsg, new_config);
  36846. + if (fsg->ep0_req_tag != exception_req_tag)
  36847. + break;
  36848. + if (rc != 0) // STALL on errors
  36849. + fsg_set_halt(fsg, fsg->ep0);
  36850. + else // Complete the status stage
  36851. + ep0_queue(fsg);
  36852. + break;
  36853. +
  36854. + case FSG_STATE_DISCONNECT:
  36855. + for (i = 0; i < fsg->nluns; ++i)
  36856. + fsg_lun_fsync_sub(fsg->luns + i);
  36857. + do_set_config(fsg, 0); // Unconfigured state
  36858. + break;
  36859. +
  36860. + case FSG_STATE_EXIT:
  36861. + case FSG_STATE_TERMINATED:
  36862. + do_set_config(fsg, 0); // Free resources
  36863. + spin_lock_irq(&fsg->lock);
  36864. + fsg->state = FSG_STATE_TERMINATED; // Stop the thread
  36865. + spin_unlock_irq(&fsg->lock);
  36866. + break;
  36867. + }
  36868. +}
  36869. +
  36870. +
  36871. +/*-------------------------------------------------------------------------*/
  36872. +
  36873. +static int fsg_main_thread(void *fsg_)
  36874. +{
  36875. + struct fsg_dev *fsg = fsg_;
  36876. +
  36877. + /* Allow the thread to be killed by a signal, but set the signal mask
  36878. + * to block everything but INT, TERM, KILL, and USR1. */
  36879. + allow_signal(SIGINT);
  36880. + allow_signal(SIGTERM);
  36881. + allow_signal(SIGKILL);
  36882. + allow_signal(SIGUSR1);
  36883. +
  36884. + /* Allow the thread to be frozen */
  36885. + set_freezable();
  36886. +
  36887. + /* Arrange for userspace references to be interpreted as kernel
  36888. + * pointers. That way we can pass a kernel pointer to a routine
  36889. + * that expects a __user pointer and it will work okay. */
  36890. + set_fs(get_ds());
  36891. +
  36892. + /* The main loop */
  36893. + while (fsg->state != FSG_STATE_TERMINATED) {
  36894. + if (exception_in_progress(fsg) || signal_pending(current)) {
  36895. + handle_exception(fsg);
  36896. + continue;
  36897. + }
  36898. +
  36899. + if (!fsg->running) {
  36900. + sleep_thread(fsg);
  36901. + continue;
  36902. + }
  36903. +
  36904. + if (get_next_command(fsg))
  36905. + continue;
  36906. +
  36907. + spin_lock_irq(&fsg->lock);
  36908. + if (!exception_in_progress(fsg))
  36909. + fsg->state = FSG_STATE_DATA_PHASE;
  36910. + spin_unlock_irq(&fsg->lock);
  36911. +
  36912. + if (do_scsi_command(fsg) || finish_reply(fsg))
  36913. + continue;
  36914. +
  36915. + spin_lock_irq(&fsg->lock);
  36916. + if (!exception_in_progress(fsg))
  36917. + fsg->state = FSG_STATE_STATUS_PHASE;
  36918. + spin_unlock_irq(&fsg->lock);
  36919. +
  36920. + if (send_status(fsg))
  36921. + continue;
  36922. +
  36923. + spin_lock_irq(&fsg->lock);
  36924. + if (!exception_in_progress(fsg))
  36925. + fsg->state = FSG_STATE_IDLE;
  36926. + spin_unlock_irq(&fsg->lock);
  36927. + }
  36928. +
  36929. + spin_lock_irq(&fsg->lock);
  36930. + fsg->thread_task = NULL;
  36931. + spin_unlock_irq(&fsg->lock);
  36932. +
  36933. + /* If we are exiting because of a signal, unregister the
  36934. + * gadget driver. */
  36935. + if (test_and_clear_bit(REGISTERED, &fsg->atomic_bitflags))
  36936. + usb_gadget_unregister_driver(&fsg_driver);
  36937. +
  36938. + /* Let the unbind and cleanup routines know the thread has exited */
  36939. + complete_and_exit(&fsg->thread_notifier, 0);
  36940. +}
  36941. +
  36942. +
  36943. +/*-------------------------------------------------------------------------*/
  36944. +
  36945. +
  36946. +/* The write permissions and store_xxx pointers are set in fsg_bind() */
  36947. +static DEVICE_ATTR(ro, 0444, fsg_show_ro, NULL);
  36948. +static DEVICE_ATTR(nofua, 0644, fsg_show_nofua, NULL);
  36949. +static DEVICE_ATTR(file, 0444, fsg_show_file, NULL);
  36950. +
  36951. +
  36952. +/*-------------------------------------------------------------------------*/
  36953. +
  36954. +static void fsg_release(struct kref *ref)
  36955. +{
  36956. + struct fsg_dev *fsg = container_of(ref, struct fsg_dev, ref);
  36957. +
  36958. + kfree(fsg->luns);
  36959. + kfree(fsg);
  36960. +}
  36961. +
  36962. +static void lun_release(struct device *dev)
  36963. +{
  36964. + struct rw_semaphore *filesem = dev_get_drvdata(dev);
  36965. + struct fsg_dev *fsg =
  36966. + container_of(filesem, struct fsg_dev, filesem);
  36967. +
  36968. + kref_put(&fsg->ref, fsg_release);
  36969. +}
  36970. +
  36971. +static void /* __init_or_exit */ fsg_unbind(struct usb_gadget *gadget)
  36972. +{
  36973. + struct fsg_dev *fsg = get_gadget_data(gadget);
  36974. + int i;
  36975. + struct fsg_lun *curlun;
  36976. + struct usb_request *req = fsg->ep0req;
  36977. +
  36978. + DBG(fsg, "unbind\n");
  36979. + clear_bit(REGISTERED, &fsg->atomic_bitflags);
  36980. +
  36981. + /* If the thread isn't already dead, tell it to exit now */
  36982. + if (fsg->state != FSG_STATE_TERMINATED) {
  36983. + raise_exception(fsg, FSG_STATE_EXIT);
  36984. + wait_for_completion(&fsg->thread_notifier);
  36985. +
  36986. + /* The cleanup routine waits for this completion also */
  36987. + complete(&fsg->thread_notifier);
  36988. + }
  36989. +
  36990. + /* Unregister the sysfs attribute files and the LUNs */
  36991. + for (i = 0; i < fsg->nluns; ++i) {
  36992. + curlun = &fsg->luns[i];
  36993. + if (curlun->registered) {
  36994. + device_remove_file(&curlun->dev, &dev_attr_nofua);
  36995. + device_remove_file(&curlun->dev, &dev_attr_ro);
  36996. + device_remove_file(&curlun->dev, &dev_attr_file);
  36997. + fsg_lun_close(curlun);
  36998. + device_unregister(&curlun->dev);
  36999. + curlun->registered = 0;
  37000. + }
  37001. + }
  37002. +
  37003. + /* Free the data buffers */
  37004. + for (i = 0; i < fsg_num_buffers; ++i)
  37005. + kfree(fsg->buffhds[i].buf);
  37006. +
  37007. + /* Free the request and buffer for endpoint 0 */
  37008. + if (req) {
  37009. + kfree(req->buf);
  37010. + usb_ep_free_request(fsg->ep0, req);
  37011. + }
  37012. +
  37013. + set_gadget_data(gadget, NULL);
  37014. +}
  37015. +
  37016. +
  37017. +static int __init check_parameters(struct fsg_dev *fsg)
  37018. +{
  37019. + int prot;
  37020. + int gcnum;
  37021. +
  37022. + /* Store the default values */
  37023. + mod_data.transport_type = USB_PR_BULK;
  37024. + mod_data.transport_name = "Bulk-only";
  37025. + mod_data.protocol_type = USB_SC_SCSI;
  37026. + mod_data.protocol_name = "Transparent SCSI";
  37027. +
  37028. + /* Some peripheral controllers are known not to be able to
  37029. + * halt bulk endpoints correctly. If one of them is present,
  37030. + * disable stalls.
  37031. + */
  37032. + if (gadget_is_at91(fsg->gadget))
  37033. + mod_data.can_stall = 0;
  37034. +
  37035. + if (mod_data.release == 0xffff) { // Parameter wasn't set
  37036. + gcnum = usb_gadget_controller_number(fsg->gadget);
  37037. + if (gcnum >= 0)
  37038. + mod_data.release = 0x0300 + gcnum;
  37039. + else {
  37040. + WARNING(fsg, "controller '%s' not recognized\n",
  37041. + fsg->gadget->name);
  37042. + mod_data.release = 0x0399;
  37043. + }
  37044. + }
  37045. +
  37046. + prot = simple_strtol(mod_data.protocol_parm, NULL, 0);
  37047. +
  37048. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  37049. + if (strnicmp(mod_data.transport_parm, "BBB", 10) == 0) {
  37050. + ; // Use default setting
  37051. + } else if (strnicmp(mod_data.transport_parm, "CB", 10) == 0) {
  37052. + mod_data.transport_type = USB_PR_CB;
  37053. + mod_data.transport_name = "Control-Bulk";
  37054. + } else if (strnicmp(mod_data.transport_parm, "CBI", 10) == 0) {
  37055. + mod_data.transport_type = USB_PR_CBI;
  37056. + mod_data.transport_name = "Control-Bulk-Interrupt";
  37057. + } else {
  37058. + ERROR(fsg, "invalid transport: %s\n", mod_data.transport_parm);
  37059. + return -EINVAL;
  37060. + }
  37061. +
  37062. + if (strnicmp(mod_data.protocol_parm, "SCSI", 10) == 0 ||
  37063. + prot == USB_SC_SCSI) {
  37064. + ; // Use default setting
  37065. + } else if (strnicmp(mod_data.protocol_parm, "RBC", 10) == 0 ||
  37066. + prot == USB_SC_RBC) {
  37067. + mod_data.protocol_type = USB_SC_RBC;
  37068. + mod_data.protocol_name = "RBC";
  37069. + } else if (strnicmp(mod_data.protocol_parm, "8020", 4) == 0 ||
  37070. + strnicmp(mod_data.protocol_parm, "ATAPI", 10) == 0 ||
  37071. + prot == USB_SC_8020) {
  37072. + mod_data.protocol_type = USB_SC_8020;
  37073. + mod_data.protocol_name = "8020i (ATAPI)";
  37074. + } else if (strnicmp(mod_data.protocol_parm, "QIC", 3) == 0 ||
  37075. + prot == USB_SC_QIC) {
  37076. + mod_data.protocol_type = USB_SC_QIC;
  37077. + mod_data.protocol_name = "QIC-157";
  37078. + } else if (strnicmp(mod_data.protocol_parm, "UFI", 10) == 0 ||
  37079. + prot == USB_SC_UFI) {
  37080. + mod_data.protocol_type = USB_SC_UFI;
  37081. + mod_data.protocol_name = "UFI";
  37082. + } else if (strnicmp(mod_data.protocol_parm, "8070", 4) == 0 ||
  37083. + prot == USB_SC_8070) {
  37084. + mod_data.protocol_type = USB_SC_8070;
  37085. + mod_data.protocol_name = "8070i";
  37086. + } else {
  37087. + ERROR(fsg, "invalid protocol: %s\n", mod_data.protocol_parm);
  37088. + return -EINVAL;
  37089. + }
  37090. +
  37091. + mod_data.buflen &= PAGE_CACHE_MASK;
  37092. + if (mod_data.buflen <= 0) {
  37093. + ERROR(fsg, "invalid buflen\n");
  37094. + return -ETOOSMALL;
  37095. + }
  37096. +
  37097. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  37098. +
  37099. + /* Serial string handling.
  37100. + * On a real device, the serial string would be loaded
  37101. + * from permanent storage. */
  37102. + if (mod_data.serial) {
  37103. + const char *ch;
  37104. + unsigned len = 0;
  37105. +
  37106. + /* Sanity check :
  37107. + * The CB[I] specification limits the serial string to
  37108. + * 12 uppercase hexadecimal characters.
  37109. + * BBB need at least 12 uppercase hexadecimal characters,
  37110. + * with a maximum of 126. */
  37111. + for (ch = mod_data.serial; *ch; ++ch) {
  37112. + ++len;
  37113. + if ((*ch < '0' || *ch > '9') &&
  37114. + (*ch < 'A' || *ch > 'F')) { /* not uppercase hex */
  37115. + WARNING(fsg,
  37116. + "Invalid serial string character: %c\n",
  37117. + *ch);
  37118. + goto no_serial;
  37119. + }
  37120. + }
  37121. + if (len > 126 ||
  37122. + (mod_data.transport_type == USB_PR_BULK && len < 12) ||
  37123. + (mod_data.transport_type != USB_PR_BULK && len > 12)) {
  37124. + WARNING(fsg, "Invalid serial string length!\n");
  37125. + goto no_serial;
  37126. + }
  37127. + fsg_strings[FSG_STRING_SERIAL - 1].s = mod_data.serial;
  37128. + } else {
  37129. + WARNING(fsg, "No serial-number string provided!\n");
  37130. + no_serial:
  37131. + device_desc.iSerialNumber = 0;
  37132. + }
  37133. +
  37134. + return 0;
  37135. +}
  37136. +
  37137. +
  37138. +static int __init fsg_bind(struct usb_gadget *gadget)
  37139. +{
  37140. + struct fsg_dev *fsg = the_fsg;
  37141. + int rc;
  37142. + int i;
  37143. + struct fsg_lun *curlun;
  37144. + struct usb_ep *ep;
  37145. + struct usb_request *req;
  37146. + char *pathbuf, *p;
  37147. +
  37148. + fsg->gadget = gadget;
  37149. + set_gadget_data(gadget, fsg);
  37150. + fsg->ep0 = gadget->ep0;
  37151. + fsg->ep0->driver_data = fsg;
  37152. +
  37153. + if ((rc = check_parameters(fsg)) != 0)
  37154. + goto out;
  37155. +
  37156. + if (mod_data.removable) { // Enable the store_xxx attributes
  37157. + dev_attr_file.attr.mode = 0644;
  37158. + dev_attr_file.store = fsg_store_file;
  37159. + if (!mod_data.cdrom) {
  37160. + dev_attr_ro.attr.mode = 0644;
  37161. + dev_attr_ro.store = fsg_store_ro;
  37162. + }
  37163. + }
  37164. +
  37165. + /* Only for removable media? */
  37166. + dev_attr_nofua.attr.mode = 0644;
  37167. + dev_attr_nofua.store = fsg_store_nofua;
  37168. +
  37169. + /* Find out how many LUNs there should be */
  37170. + i = mod_data.nluns;
  37171. + if (i == 0)
  37172. + i = max(mod_data.num_filenames, 1u);
  37173. + if (i > FSG_MAX_LUNS) {
  37174. + ERROR(fsg, "invalid number of LUNs: %d\n", i);
  37175. + rc = -EINVAL;
  37176. + goto out;
  37177. + }
  37178. +
  37179. + /* Create the LUNs, open their backing files, and register the
  37180. + * LUN devices in sysfs. */
  37181. + fsg->luns = kzalloc(i * sizeof(struct fsg_lun), GFP_KERNEL);
  37182. + if (!fsg->luns) {
  37183. + rc = -ENOMEM;
  37184. + goto out;
  37185. + }
  37186. + fsg->nluns = i;
  37187. +
  37188. + for (i = 0; i < fsg->nluns; ++i) {
  37189. + curlun = &fsg->luns[i];
  37190. + curlun->cdrom = !!mod_data.cdrom;
  37191. + curlun->ro = mod_data.cdrom || mod_data.ro[i];
  37192. + curlun->initially_ro = curlun->ro;
  37193. + curlun->removable = mod_data.removable;
  37194. + curlun->nofua = mod_data.nofua[i];
  37195. + curlun->dev.release = lun_release;
  37196. + curlun->dev.parent = &gadget->dev;
  37197. + curlun->dev.driver = &fsg_driver.driver;
  37198. + dev_set_drvdata(&curlun->dev, &fsg->filesem);
  37199. + dev_set_name(&curlun->dev,"%s-lun%d",
  37200. + dev_name(&gadget->dev), i);
  37201. +
  37202. + kref_get(&fsg->ref);
  37203. + rc = device_register(&curlun->dev);
  37204. + if (rc) {
  37205. + INFO(fsg, "failed to register LUN%d: %d\n", i, rc);
  37206. + put_device(&curlun->dev);
  37207. + goto out;
  37208. + }
  37209. + curlun->registered = 1;
  37210. +
  37211. + rc = device_create_file(&curlun->dev, &dev_attr_ro);
  37212. + if (rc)
  37213. + goto out;
  37214. + rc = device_create_file(&curlun->dev, &dev_attr_nofua);
  37215. + if (rc)
  37216. + goto out;
  37217. + rc = device_create_file(&curlun->dev, &dev_attr_file);
  37218. + if (rc)
  37219. + goto out;
  37220. +
  37221. + if (mod_data.file[i] && *mod_data.file[i]) {
  37222. + rc = fsg_lun_open(curlun, mod_data.file[i]);
  37223. + if (rc)
  37224. + goto out;
  37225. + } else if (!mod_data.removable) {
  37226. + ERROR(fsg, "no file given for LUN%d\n", i);
  37227. + rc = -EINVAL;
  37228. + goto out;
  37229. + }
  37230. + }
  37231. +
  37232. + /* Find all the endpoints we will use */
  37233. + usb_ep_autoconfig_reset(gadget);
  37234. + ep = usb_ep_autoconfig(gadget, &fsg_fs_bulk_in_desc);
  37235. + if (!ep)
  37236. + goto autoconf_fail;
  37237. + ep->driver_data = fsg; // claim the endpoint
  37238. + fsg->bulk_in = ep;
  37239. +
  37240. + ep = usb_ep_autoconfig(gadget, &fsg_fs_bulk_out_desc);
  37241. + if (!ep)
  37242. + goto autoconf_fail;
  37243. + ep->driver_data = fsg; // claim the endpoint
  37244. + fsg->bulk_out = ep;
  37245. +
  37246. + if (transport_is_cbi()) {
  37247. + ep = usb_ep_autoconfig(gadget, &fsg_fs_intr_in_desc);
  37248. + if (!ep)
  37249. + goto autoconf_fail;
  37250. + ep->driver_data = fsg; // claim the endpoint
  37251. + fsg->intr_in = ep;
  37252. + }
  37253. +
  37254. + /* Fix up the descriptors */
  37255. + device_desc.idVendor = cpu_to_le16(mod_data.vendor);
  37256. + device_desc.idProduct = cpu_to_le16(mod_data.product);
  37257. + device_desc.bcdDevice = cpu_to_le16(mod_data.release);
  37258. +
  37259. + i = (transport_is_cbi() ? 3 : 2); // Number of endpoints
  37260. + fsg_intf_desc.bNumEndpoints = i;
  37261. + fsg_intf_desc.bInterfaceSubClass = mod_data.protocol_type;
  37262. + fsg_intf_desc.bInterfaceProtocol = mod_data.transport_type;
  37263. + fsg_fs_function[i + FSG_FS_FUNCTION_PRE_EP_ENTRIES] = NULL;
  37264. +
  37265. + if (gadget_is_dualspeed(gadget)) {
  37266. + fsg_hs_function[i + FSG_HS_FUNCTION_PRE_EP_ENTRIES] = NULL;
  37267. +
  37268. + /* Assume endpoint addresses are the same for both speeds */
  37269. + fsg_hs_bulk_in_desc.bEndpointAddress =
  37270. + fsg_fs_bulk_in_desc.bEndpointAddress;
  37271. + fsg_hs_bulk_out_desc.bEndpointAddress =
  37272. + fsg_fs_bulk_out_desc.bEndpointAddress;
  37273. + fsg_hs_intr_in_desc.bEndpointAddress =
  37274. + fsg_fs_intr_in_desc.bEndpointAddress;
  37275. + }
  37276. +
  37277. + if (gadget_is_superspeed(gadget)) {
  37278. + unsigned max_burst;
  37279. +
  37280. + fsg_ss_function[i + FSG_SS_FUNCTION_PRE_EP_ENTRIES] = NULL;
  37281. +
  37282. + /* Calculate bMaxBurst, we know packet size is 1024 */
  37283. + max_burst = min_t(unsigned, mod_data.buflen / 1024, 15);
  37284. +
  37285. + /* Assume endpoint addresses are the same for both speeds */
  37286. + fsg_ss_bulk_in_desc.bEndpointAddress =
  37287. + fsg_fs_bulk_in_desc.bEndpointAddress;
  37288. + fsg_ss_bulk_in_comp_desc.bMaxBurst = max_burst;
  37289. +
  37290. + fsg_ss_bulk_out_desc.bEndpointAddress =
  37291. + fsg_fs_bulk_out_desc.bEndpointAddress;
  37292. + fsg_ss_bulk_out_comp_desc.bMaxBurst = max_burst;
  37293. + }
  37294. +
  37295. + if (gadget_is_otg(gadget))
  37296. + fsg_otg_desc.bmAttributes |= USB_OTG_HNP;
  37297. +
  37298. + rc = -ENOMEM;
  37299. +
  37300. + /* Allocate the request and buffer for endpoint 0 */
  37301. + fsg->ep0req = req = usb_ep_alloc_request(fsg->ep0, GFP_KERNEL);
  37302. + if (!req)
  37303. + goto out;
  37304. + req->buf = kmalloc(EP0_BUFSIZE, GFP_KERNEL);
  37305. + if (!req->buf)
  37306. + goto out;
  37307. + req->complete = ep0_complete;
  37308. +
  37309. + /* Allocate the data buffers */
  37310. + for (i = 0; i < fsg_num_buffers; ++i) {
  37311. + struct fsg_buffhd *bh = &fsg->buffhds[i];
  37312. +
  37313. + /* Allocate for the bulk-in endpoint. We assume that
  37314. + * the buffer will also work with the bulk-out (and
  37315. + * interrupt-in) endpoint. */
  37316. + bh->buf = kmalloc(mod_data.buflen, GFP_KERNEL);
  37317. + if (!bh->buf)
  37318. + goto out;
  37319. + bh->next = bh + 1;
  37320. + }
  37321. + fsg->buffhds[fsg_num_buffers - 1].next = &fsg->buffhds[0];
  37322. +
  37323. + /* This should reflect the actual gadget power source */
  37324. + usb_gadget_set_selfpowered(gadget);
  37325. +
  37326. + snprintf(fsg_string_manufacturer, sizeof fsg_string_manufacturer,
  37327. + "%s %s with %s",
  37328. + init_utsname()->sysname, init_utsname()->release,
  37329. + gadget->name);
  37330. +
  37331. + fsg->thread_task = kthread_create(fsg_main_thread, fsg,
  37332. + "file-storage-gadget");
  37333. + if (IS_ERR(fsg->thread_task)) {
  37334. + rc = PTR_ERR(fsg->thread_task);
  37335. + goto out;
  37336. + }
  37337. +
  37338. + INFO(fsg, DRIVER_DESC ", version: " DRIVER_VERSION "\n");
  37339. + INFO(fsg, "NOTE: This driver is deprecated. "
  37340. + "Consider using g_mass_storage instead.\n");
  37341. + INFO(fsg, "Number of LUNs=%d\n", fsg->nluns);
  37342. +
  37343. + pathbuf = kmalloc(PATH_MAX, GFP_KERNEL);
  37344. + for (i = 0; i < fsg->nluns; ++i) {
  37345. + curlun = &fsg->luns[i];
  37346. + if (fsg_lun_is_open(curlun)) {
  37347. + p = NULL;
  37348. + if (pathbuf) {
  37349. + p = d_path(&curlun->filp->f_path,
  37350. + pathbuf, PATH_MAX);
  37351. + if (IS_ERR(p))
  37352. + p = NULL;
  37353. + }
  37354. + LINFO(curlun, "ro=%d, nofua=%d, file: %s\n",
  37355. + curlun->ro, curlun->nofua, (p ? p : "(error)"));
  37356. + }
  37357. + }
  37358. + kfree(pathbuf);
  37359. +
  37360. + DBG(fsg, "transport=%s (x%02x)\n",
  37361. + mod_data.transport_name, mod_data.transport_type);
  37362. + DBG(fsg, "protocol=%s (x%02x)\n",
  37363. + mod_data.protocol_name, mod_data.protocol_type);
  37364. + DBG(fsg, "VendorID=x%04x, ProductID=x%04x, Release=x%04x\n",
  37365. + mod_data.vendor, mod_data.product, mod_data.release);
  37366. + DBG(fsg, "removable=%d, stall=%d, cdrom=%d, buflen=%u\n",
  37367. + mod_data.removable, mod_data.can_stall,
  37368. + mod_data.cdrom, mod_data.buflen);
  37369. + DBG(fsg, "I/O thread pid: %d\n", task_pid_nr(fsg->thread_task));
  37370. +
  37371. + set_bit(REGISTERED, &fsg->atomic_bitflags);
  37372. +
  37373. + /* Tell the thread to start working */
  37374. + wake_up_process(fsg->thread_task);
  37375. + return 0;
  37376. +
  37377. +autoconf_fail:
  37378. + ERROR(fsg, "unable to autoconfigure all endpoints\n");
  37379. + rc = -ENOTSUPP;
  37380. +
  37381. +out:
  37382. + fsg->state = FSG_STATE_TERMINATED; // The thread is dead
  37383. + fsg_unbind(gadget);
  37384. + complete(&fsg->thread_notifier);
  37385. + return rc;
  37386. +}
  37387. +
  37388. +
  37389. +/*-------------------------------------------------------------------------*/
  37390. +
  37391. +static void fsg_suspend(struct usb_gadget *gadget)
  37392. +{
  37393. + struct fsg_dev *fsg = get_gadget_data(gadget);
  37394. +
  37395. + DBG(fsg, "suspend\n");
  37396. + set_bit(SUSPENDED, &fsg->atomic_bitflags);
  37397. +}
  37398. +
  37399. +static void fsg_resume(struct usb_gadget *gadget)
  37400. +{
  37401. + struct fsg_dev *fsg = get_gadget_data(gadget);
  37402. +
  37403. + DBG(fsg, "resume\n");
  37404. + clear_bit(SUSPENDED, &fsg->atomic_bitflags);
  37405. +}
  37406. +
  37407. +
  37408. +/*-------------------------------------------------------------------------*/
  37409. +
  37410. +static struct usb_gadget_driver fsg_driver = {
  37411. + .max_speed = USB_SPEED_SUPER,
  37412. + .function = (char *) fsg_string_product,
  37413. + .unbind = fsg_unbind,
  37414. + .disconnect = fsg_disconnect,
  37415. + .setup = fsg_setup,
  37416. + .suspend = fsg_suspend,
  37417. + .resume = fsg_resume,
  37418. +
  37419. + .driver = {
  37420. + .name = DRIVER_NAME,
  37421. + .owner = THIS_MODULE,
  37422. + // .release = ...
  37423. + // .suspend = ...
  37424. + // .resume = ...
  37425. + },
  37426. +};
  37427. +
  37428. +
  37429. +static int __init fsg_alloc(void)
  37430. +{
  37431. + struct fsg_dev *fsg;
  37432. +
  37433. + fsg = kzalloc(sizeof *fsg +
  37434. + fsg_num_buffers * sizeof *(fsg->buffhds), GFP_KERNEL);
  37435. +
  37436. + if (!fsg)
  37437. + return -ENOMEM;
  37438. + spin_lock_init(&fsg->lock);
  37439. + init_rwsem(&fsg->filesem);
  37440. + kref_init(&fsg->ref);
  37441. + init_completion(&fsg->thread_notifier);
  37442. +
  37443. + the_fsg = fsg;
  37444. + return 0;
  37445. +}
  37446. +
  37447. +
  37448. +static int __init fsg_init(void)
  37449. +{
  37450. + int rc;
  37451. + struct fsg_dev *fsg;
  37452. +
  37453. + rc = fsg_num_buffers_validate();
  37454. + if (rc != 0)
  37455. + return rc;
  37456. +
  37457. + if ((rc = fsg_alloc()) != 0)
  37458. + return rc;
  37459. + fsg = the_fsg;
  37460. + if ((rc = usb_gadget_probe_driver(&fsg_driver, fsg_bind)) != 0)
  37461. + kref_put(&fsg->ref, fsg_release);
  37462. + return rc;
  37463. +}
  37464. +module_init(fsg_init);
  37465. +
  37466. +
  37467. +static void __exit fsg_cleanup(void)
  37468. +{
  37469. + struct fsg_dev *fsg = the_fsg;
  37470. +
  37471. + /* Unregister the driver iff the thread hasn't already done so */
  37472. + if (test_and_clear_bit(REGISTERED, &fsg->atomic_bitflags))
  37473. + usb_gadget_unregister_driver(&fsg_driver);
  37474. +
  37475. + /* Wait for the thread to finish up */
  37476. + wait_for_completion(&fsg->thread_notifier);
  37477. +
  37478. + kref_put(&fsg->ref, fsg_release);
  37479. +}
  37480. +module_exit(fsg_cleanup);
  37481. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_common_port/changes.txt linux-3.13.3/drivers/usb/host/dwc_common_port/changes.txt
  37482. --- linux-3.13.3.orig/drivers/usb/host/dwc_common_port/changes.txt 1970-01-01 01:00:00.000000000 +0100
  37483. +++ linux-3.13.3/drivers/usb/host/dwc_common_port/changes.txt 2014-02-17 22:41:01.000000000 +0100
  37484. @@ -0,0 +1,174 @@
  37485. +
  37486. +dwc_read_reg32() and friends now take an additional parameter, a pointer to an
  37487. +IO context struct. The IO context struct should live in an os-dependent struct
  37488. +in your driver. As an example, the dwc_usb3 driver has an os-dependent struct
  37489. +named 'os_dep' embedded in the main device struct. So there these calls look
  37490. +like this:
  37491. +
  37492. + dwc_read_reg32(&usb3_dev->os_dep.ioctx, &pcd->dev_global_regs->dcfg);
  37493. +
  37494. + dwc_write_reg32(&usb3_dev->os_dep.ioctx,
  37495. + &pcd->dev_global_regs->dcfg, 0);
  37496. +
  37497. +Note that for the existing Linux driver ports, it is not necessary to actually
  37498. +define the 'ioctx' member in the os-dependent struct. Since Linux does not
  37499. +require an IO context, its macros for dwc_read_reg32() and friends do not
  37500. +use the context pointer, so it is optimized away by the compiler. But it is
  37501. +necessary to add the pointer parameter to all of the call sites, to be ready
  37502. +for any future ports (such as FreeBSD) which do require an IO context.
  37503. +
  37504. +
  37505. +Similarly, dwc_alloc(), dwc_alloc_atomic(), dwc_strdup(), and dwc_free() now
  37506. +take an additional parameter, a pointer to a memory context. Examples:
  37507. +
  37508. + addr = dwc_alloc(&usb3_dev->os_dep.memctx, size);
  37509. +
  37510. + dwc_free(&usb3_dev->os_dep.memctx, addr);
  37511. +
  37512. +Again, for the Linux ports, it is not necessary to actually define the memctx
  37513. +member, but it is necessary to add the pointer parameter to all of the call
  37514. +sites.
  37515. +
  37516. +
  37517. +Same for dwc_dma_alloc() and dwc_dma_free(). Examples:
  37518. +
  37519. + virt_addr = dwc_dma_alloc(&usb3_dev->os_dep.dmactx, size, &phys_addr);
  37520. +
  37521. + dwc_dma_free(&usb3_dev->os_dep.dmactx, size, virt_addr, phys_addr);
  37522. +
  37523. +
  37524. +Same for dwc_mutex_alloc() and dwc_mutex_free(). Examples:
  37525. +
  37526. + mutex = dwc_mutex_alloc(&usb3_dev->os_dep.mtxctx);
  37527. +
  37528. + dwc_mutex_free(&usb3_dev->os_dep.mtxctx, mutex);
  37529. +
  37530. +
  37531. +Same for dwc_spinlock_alloc() and dwc_spinlock_free(). Examples:
  37532. +
  37533. + lock = dwc_spinlock_alloc(&usb3_dev->osdep.splctx);
  37534. +
  37535. + dwc_spinlock_free(&usb3_dev->osdep.splctx, lock);
  37536. +
  37537. +
  37538. +Same for dwc_timer_alloc(). Example:
  37539. +
  37540. + timer = dwc_timer_alloc(&usb3_dev->os_dep.tmrctx, "dwc_usb3_tmr1",
  37541. + cb_func, cb_data);
  37542. +
  37543. +
  37544. +Same for dwc_waitq_alloc(). Example:
  37545. +
  37546. + waitq = dwc_waitq_alloc(&usb3_dev->os_dep.wtqctx);
  37547. +
  37548. +
  37549. +Same for dwc_thread_run(). Example:
  37550. +
  37551. + thread = dwc_thread_run(&usb3_dev->os_dep.thdctx, func,
  37552. + "dwc_usb3_thd1", data);
  37553. +
  37554. +
  37555. +Same for dwc_workq_alloc(). Example:
  37556. +
  37557. + workq = dwc_workq_alloc(&usb3_dev->osdep.wkqctx, "dwc_usb3_wkq1");
  37558. +
  37559. +
  37560. +Same for dwc_task_alloc(). Example:
  37561. +
  37562. + task = dwc_task_alloc(&usb3_dev->os_dep.tskctx, "dwc_usb3_tsk1",
  37563. + cb_func, cb_data);
  37564. +
  37565. +
  37566. +In addition to the context pointer additions, a few core functions have had
  37567. +other changes made to their parameters:
  37568. +
  37569. +The 'flags' parameter to dwc_spinlock_irqsave() and dwc_spinunlock_irqrestore()
  37570. +has been changed from a uint64_t to a dwc_irqflags_t.
  37571. +
  37572. +dwc_thread_should_stop() now takes a 'dwc_thread_t *' parameter, because the
  37573. +FreeBSD equivalent of that function requires it.
  37574. +
  37575. +And, in addition to the context pointer, dwc_task_alloc() also adds a
  37576. +'char *name' parameter, to be consistent with dwc_thread_run() and
  37577. +dwc_workq_alloc(), and because the FreeBSD equivalent of that function
  37578. +requires a unique name.
  37579. +
  37580. +
  37581. +Here is a complete list of the core functions that now take a pointer to a
  37582. +context as their first parameter:
  37583. +
  37584. + dwc_read_reg32
  37585. + dwc_read_reg64
  37586. + dwc_write_reg32
  37587. + dwc_write_reg64
  37588. + dwc_modify_reg32
  37589. + dwc_modify_reg64
  37590. + dwc_alloc
  37591. + dwc_alloc_atomic
  37592. + dwc_strdup
  37593. + dwc_free
  37594. + dwc_dma_alloc
  37595. + dwc_dma_free
  37596. + dwc_mutex_alloc
  37597. + dwc_mutex_free
  37598. + dwc_spinlock_alloc
  37599. + dwc_spinlock_free
  37600. + dwc_timer_alloc
  37601. + dwc_waitq_alloc
  37602. + dwc_thread_run
  37603. + dwc_workq_alloc
  37604. + dwc_task_alloc Also adds a 'char *name' as its 2nd parameter
  37605. +
  37606. +And here are the core functions that have other changes to their parameters:
  37607. +
  37608. + dwc_spinlock_irqsave 'flags' param is now a 'dwc_irqflags_t *'
  37609. + dwc_spinunlock_irqrestore 'flags' param is now a 'dwc_irqflags_t'
  37610. + dwc_thread_should_stop Adds a 'dwc_thread_t *' parameter
  37611. +
  37612. +
  37613. +
  37614. +The changes to the core functions also require some of the other library
  37615. +functions to change:
  37616. +
  37617. + dwc_cc_if_alloc() and dwc_cc_if_free() now take a 'void *memctx'
  37618. + (for memory allocation) as the 1st param and a 'void *mtxctx'
  37619. + (for mutex allocation) as the 2nd param.
  37620. +
  37621. + dwc_cc_clear(), dwc_cc_add(), dwc_cc_change(), dwc_cc_remove(),
  37622. + dwc_cc_data_for_save(), and dwc_cc_restore_from_data() now take a
  37623. + 'void *memctx' as the 1st param.
  37624. +
  37625. + dwc_dh_modpow(), dwc_dh_pk(), and dwc_dh_derive_keys() now take a
  37626. + 'void *memctx' as the 1st param.
  37627. +
  37628. + dwc_modpow() now takes a 'void *memctx' as the 1st param.
  37629. +
  37630. + dwc_alloc_notification_manager() now takes a 'void *memctx' as the
  37631. + 1st param and a 'void *wkqctx' (for work queue allocation) as the 2nd
  37632. + param, and also now returns an integer value that is non-zero if
  37633. + allocation of its data structures or work queue fails.
  37634. +
  37635. + dwc_register_notifier() now takes a 'void *memctx' as the 1st param.
  37636. +
  37637. + dwc_memory_debug_start() now takes a 'void *mem_ctx' as the first
  37638. + param, and also now returns an integer value that is non-zero if
  37639. + allocation of its data structures fails.
  37640. +
  37641. +
  37642. +
  37643. +Other miscellaneous changes:
  37644. +
  37645. +The DEBUG_MEMORY and DEBUG_REGS #define's have been renamed to
  37646. +DWC_DEBUG_MEMORY and DWC_DEBUG_REGS.
  37647. +
  37648. +The following #define's have been added to allow selectively compiling library
  37649. +features:
  37650. +
  37651. + DWC_CCLIB
  37652. + DWC_CRYPTOLIB
  37653. + DWC_NOTIFYLIB
  37654. + DWC_UTFLIB
  37655. +
  37656. +A DWC_LIBMODULE #define has also been added. If this is not defined, then the
  37657. +module code in dwc_common_linux.c is not compiled in. This allows linking the
  37658. +library code directly into a driver module, instead of as a standalone module.
  37659. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_common_port/doc/doxygen.cfg linux-3.13.3/drivers/usb/host/dwc_common_port/doc/doxygen.cfg
  37660. --- linux-3.13.3.orig/drivers/usb/host/dwc_common_port/doc/doxygen.cfg 1970-01-01 01:00:00.000000000 +0100
  37661. +++ linux-3.13.3/drivers/usb/host/dwc_common_port/doc/doxygen.cfg 2014-02-17 22:41:01.000000000 +0100
  37662. @@ -0,0 +1,270 @@
  37663. +# Doxyfile 1.4.5
  37664. +
  37665. +#---------------------------------------------------------------------------
  37666. +# Project related configuration options
  37667. +#---------------------------------------------------------------------------
  37668. +PROJECT_NAME = "Synopsys DWC Portability and Common Library for UWB"
  37669. +PROJECT_NUMBER =
  37670. +OUTPUT_DIRECTORY = doc
  37671. +CREATE_SUBDIRS = NO
  37672. +OUTPUT_LANGUAGE = English
  37673. +BRIEF_MEMBER_DESC = YES
  37674. +REPEAT_BRIEF = YES
  37675. +ABBREVIATE_BRIEF = "The $name class" \
  37676. + "The $name widget" \
  37677. + "The $name file" \
  37678. + is \
  37679. + provides \
  37680. + specifies \
  37681. + contains \
  37682. + represents \
  37683. + a \
  37684. + an \
  37685. + the
  37686. +ALWAYS_DETAILED_SEC = YES
  37687. +INLINE_INHERITED_MEMB = NO
  37688. +FULL_PATH_NAMES = NO
  37689. +STRIP_FROM_PATH = ..
  37690. +STRIP_FROM_INC_PATH =
  37691. +SHORT_NAMES = NO
  37692. +JAVADOC_AUTOBRIEF = YES
  37693. +MULTILINE_CPP_IS_BRIEF = NO
  37694. +DETAILS_AT_TOP = YES
  37695. +INHERIT_DOCS = YES
  37696. +SEPARATE_MEMBER_PAGES = NO
  37697. +TAB_SIZE = 8
  37698. +ALIASES =
  37699. +OPTIMIZE_OUTPUT_FOR_C = YES
  37700. +OPTIMIZE_OUTPUT_JAVA = NO
  37701. +BUILTIN_STL_SUPPORT = NO
  37702. +DISTRIBUTE_GROUP_DOC = NO
  37703. +SUBGROUPING = NO
  37704. +#---------------------------------------------------------------------------
  37705. +# Build related configuration options
  37706. +#---------------------------------------------------------------------------
  37707. +EXTRACT_ALL = NO
  37708. +EXTRACT_PRIVATE = NO
  37709. +EXTRACT_STATIC = YES
  37710. +EXTRACT_LOCAL_CLASSES = NO
  37711. +EXTRACT_LOCAL_METHODS = NO
  37712. +HIDE_UNDOC_MEMBERS = NO
  37713. +HIDE_UNDOC_CLASSES = NO
  37714. +HIDE_FRIEND_COMPOUNDS = NO
  37715. +HIDE_IN_BODY_DOCS = NO
  37716. +INTERNAL_DOCS = NO
  37717. +CASE_SENSE_NAMES = YES
  37718. +HIDE_SCOPE_NAMES = NO
  37719. +SHOW_INCLUDE_FILES = NO
  37720. +INLINE_INFO = YES
  37721. +SORT_MEMBER_DOCS = NO
  37722. +SORT_BRIEF_DOCS = NO
  37723. +SORT_BY_SCOPE_NAME = NO
  37724. +GENERATE_TODOLIST = YES
  37725. +GENERATE_TESTLIST = YES
  37726. +GENERATE_BUGLIST = YES
  37727. +GENERATE_DEPRECATEDLIST= YES
  37728. +ENABLED_SECTIONS =
  37729. +MAX_INITIALIZER_LINES = 30
  37730. +SHOW_USED_FILES = YES
  37731. +SHOW_DIRECTORIES = YES
  37732. +FILE_VERSION_FILTER =
  37733. +#---------------------------------------------------------------------------
  37734. +# configuration options related to warning and progress messages
  37735. +#---------------------------------------------------------------------------
  37736. +QUIET = YES
  37737. +WARNINGS = YES
  37738. +WARN_IF_UNDOCUMENTED = NO
  37739. +WARN_IF_DOC_ERROR = YES
  37740. +WARN_NO_PARAMDOC = YES
  37741. +WARN_FORMAT = "$file:$line: $text"
  37742. +WARN_LOGFILE =
  37743. +#---------------------------------------------------------------------------
  37744. +# configuration options related to the input files
  37745. +#---------------------------------------------------------------------------
  37746. +INPUT = .
  37747. +FILE_PATTERNS = *.c \
  37748. + *.cc \
  37749. + *.cxx \
  37750. + *.cpp \
  37751. + *.c++ \
  37752. + *.d \
  37753. + *.java \
  37754. + *.ii \
  37755. + *.ixx \
  37756. + *.ipp \
  37757. + *.i++ \
  37758. + *.inl \
  37759. + *.h \
  37760. + *.hh \
  37761. + *.hxx \
  37762. + *.hpp \
  37763. + *.h++ \
  37764. + *.idl \
  37765. + *.odl \
  37766. + *.cs \
  37767. + *.php \
  37768. + *.php3 \
  37769. + *.inc \
  37770. + *.m \
  37771. + *.mm \
  37772. + *.dox \
  37773. + *.py \
  37774. + *.C \
  37775. + *.CC \
  37776. + *.C++ \
  37777. + *.II \
  37778. + *.I++ \
  37779. + *.H \
  37780. + *.HH \
  37781. + *.H++ \
  37782. + *.CS \
  37783. + *.PHP \
  37784. + *.PHP3 \
  37785. + *.M \
  37786. + *.MM \
  37787. + *.PY
  37788. +RECURSIVE = NO
  37789. +EXCLUDE =
  37790. +EXCLUDE_SYMLINKS = NO
  37791. +EXCLUDE_PATTERNS =
  37792. +EXAMPLE_PATH =
  37793. +EXAMPLE_PATTERNS = *
  37794. +EXAMPLE_RECURSIVE = NO
  37795. +IMAGE_PATH =
  37796. +INPUT_FILTER =
  37797. +FILTER_PATTERNS =
  37798. +FILTER_SOURCE_FILES = NO
  37799. +#---------------------------------------------------------------------------
  37800. +# configuration options related to source browsing
  37801. +#---------------------------------------------------------------------------
  37802. +SOURCE_BROWSER = NO
  37803. +INLINE_SOURCES = NO
  37804. +STRIP_CODE_COMMENTS = YES
  37805. +REFERENCED_BY_RELATION = YES
  37806. +REFERENCES_RELATION = YES
  37807. +USE_HTAGS = NO
  37808. +VERBATIM_HEADERS = NO
  37809. +#---------------------------------------------------------------------------
  37810. +# configuration options related to the alphabetical class index
  37811. +#---------------------------------------------------------------------------
  37812. +ALPHABETICAL_INDEX = NO
  37813. +COLS_IN_ALPHA_INDEX = 5
  37814. +IGNORE_PREFIX =
  37815. +#---------------------------------------------------------------------------
  37816. +# configuration options related to the HTML output
  37817. +#---------------------------------------------------------------------------
  37818. +GENERATE_HTML = YES
  37819. +HTML_OUTPUT = html
  37820. +HTML_FILE_EXTENSION = .html
  37821. +HTML_HEADER =
  37822. +HTML_FOOTER =
  37823. +HTML_STYLESHEET =
  37824. +HTML_ALIGN_MEMBERS = YES
  37825. +GENERATE_HTMLHELP = NO
  37826. +CHM_FILE =
  37827. +HHC_LOCATION =
  37828. +GENERATE_CHI = NO
  37829. +BINARY_TOC = NO
  37830. +TOC_EXPAND = NO
  37831. +DISABLE_INDEX = NO
  37832. +ENUM_VALUES_PER_LINE = 4
  37833. +GENERATE_TREEVIEW = YES
  37834. +TREEVIEW_WIDTH = 250
  37835. +#---------------------------------------------------------------------------
  37836. +# configuration options related to the LaTeX output
  37837. +#---------------------------------------------------------------------------
  37838. +GENERATE_LATEX = NO
  37839. +LATEX_OUTPUT = latex
  37840. +LATEX_CMD_NAME = latex
  37841. +MAKEINDEX_CMD_NAME = makeindex
  37842. +COMPACT_LATEX = NO
  37843. +PAPER_TYPE = a4wide
  37844. +EXTRA_PACKAGES =
  37845. +LATEX_HEADER =
  37846. +PDF_HYPERLINKS = NO
  37847. +USE_PDFLATEX = NO
  37848. +LATEX_BATCHMODE = NO
  37849. +LATEX_HIDE_INDICES = NO
  37850. +#---------------------------------------------------------------------------
  37851. +# configuration options related to the RTF output
  37852. +#---------------------------------------------------------------------------
  37853. +GENERATE_RTF = NO
  37854. +RTF_OUTPUT = rtf
  37855. +COMPACT_RTF = NO
  37856. +RTF_HYPERLINKS = NO
  37857. +RTF_STYLESHEET_FILE =
  37858. +RTF_EXTENSIONS_FILE =
  37859. +#---------------------------------------------------------------------------
  37860. +# configuration options related to the man page output
  37861. +#---------------------------------------------------------------------------
  37862. +GENERATE_MAN = NO
  37863. +MAN_OUTPUT = man
  37864. +MAN_EXTENSION = .3
  37865. +MAN_LINKS = NO
  37866. +#---------------------------------------------------------------------------
  37867. +# configuration options related to the XML output
  37868. +#---------------------------------------------------------------------------
  37869. +GENERATE_XML = NO
  37870. +XML_OUTPUT = xml
  37871. +XML_SCHEMA =
  37872. +XML_DTD =
  37873. +XML_PROGRAMLISTING = YES
  37874. +#---------------------------------------------------------------------------
  37875. +# configuration options for the AutoGen Definitions output
  37876. +#---------------------------------------------------------------------------
  37877. +GENERATE_AUTOGEN_DEF = NO
  37878. +#---------------------------------------------------------------------------
  37879. +# configuration options related to the Perl module output
  37880. +#---------------------------------------------------------------------------
  37881. +GENERATE_PERLMOD = NO
  37882. +PERLMOD_LATEX = NO
  37883. +PERLMOD_PRETTY = YES
  37884. +PERLMOD_MAKEVAR_PREFIX =
  37885. +#---------------------------------------------------------------------------
  37886. +# Configuration options related to the preprocessor
  37887. +#---------------------------------------------------------------------------
  37888. +ENABLE_PREPROCESSING = YES
  37889. +MACRO_EXPANSION = NO
  37890. +EXPAND_ONLY_PREDEF = NO
  37891. +SEARCH_INCLUDES = YES
  37892. +INCLUDE_PATH =
  37893. +INCLUDE_FILE_PATTERNS =
  37894. +PREDEFINED = DEBUG DEBUG_MEMORY
  37895. +EXPAND_AS_DEFINED =
  37896. +SKIP_FUNCTION_MACROS = YES
  37897. +#---------------------------------------------------------------------------
  37898. +# Configuration::additions related to external references
  37899. +#---------------------------------------------------------------------------
  37900. +TAGFILES =
  37901. +GENERATE_TAGFILE =
  37902. +ALLEXTERNALS = NO
  37903. +EXTERNAL_GROUPS = YES
  37904. +PERL_PATH = /usr/bin/perl
  37905. +#---------------------------------------------------------------------------
  37906. +# Configuration options related to the dot tool
  37907. +#---------------------------------------------------------------------------
  37908. +CLASS_DIAGRAMS = YES
  37909. +HIDE_UNDOC_RELATIONS = YES
  37910. +HAVE_DOT = NO
  37911. +CLASS_GRAPH = YES
  37912. +COLLABORATION_GRAPH = YES
  37913. +GROUP_GRAPHS = YES
  37914. +UML_LOOK = NO
  37915. +TEMPLATE_RELATIONS = NO
  37916. +INCLUDE_GRAPH = NO
  37917. +INCLUDED_BY_GRAPH = YES
  37918. +CALL_GRAPH = NO
  37919. +GRAPHICAL_HIERARCHY = YES
  37920. +DIRECTORY_GRAPH = YES
  37921. +DOT_IMAGE_FORMAT = png
  37922. +DOT_PATH =
  37923. +DOTFILE_DIRS =
  37924. +MAX_DOT_GRAPH_DEPTH = 1000
  37925. +DOT_TRANSPARENT = NO
  37926. +DOT_MULTI_TARGETS = NO
  37927. +GENERATE_LEGEND = YES
  37928. +DOT_CLEANUP = YES
  37929. +#---------------------------------------------------------------------------
  37930. +# Configuration::additions related to the search engine
  37931. +#---------------------------------------------------------------------------
  37932. +SEARCHENGINE = NO
  37933. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_common_port/dwc_cc.c linux-3.13.3/drivers/usb/host/dwc_common_port/dwc_cc.c
  37934. --- linux-3.13.3.orig/drivers/usb/host/dwc_common_port/dwc_cc.c 1970-01-01 01:00:00.000000000 +0100
  37935. +++ linux-3.13.3/drivers/usb/host/dwc_common_port/dwc_cc.c 2014-02-17 22:41:01.000000000 +0100
  37936. @@ -0,0 +1,532 @@
  37937. +/* =========================================================================
  37938. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_cc.c $
  37939. + * $Revision: #4 $
  37940. + * $Date: 2010/11/04 $
  37941. + * $Change: 1621692 $
  37942. + *
  37943. + * Synopsys Portability Library Software and documentation
  37944. + * (hereinafter, "Software") is an Unsupported proprietary work of
  37945. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  37946. + * between Synopsys and you.
  37947. + *
  37948. + * The Software IS NOT an item of Licensed Software or Licensed Product
  37949. + * under any End User Software License Agreement or Agreement for
  37950. + * Licensed Product with Synopsys or any supplement thereto. You are
  37951. + * permitted to use and redistribute this Software in source and binary
  37952. + * forms, with or without modification, provided that redistributions
  37953. + * of source code must retain this notice. You may not view, use,
  37954. + * disclose, copy or distribute this file or any information contained
  37955. + * herein except pursuant to this license grant from Synopsys. If you
  37956. + * do not agree with this notice, including the disclaimer below, then
  37957. + * you are not authorized to use the Software.
  37958. + *
  37959. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  37960. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  37961. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  37962. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  37963. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  37964. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  37965. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  37966. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  37967. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  37968. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  37969. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  37970. + * DAMAGE.
  37971. + * ========================================================================= */
  37972. +#ifdef DWC_CCLIB
  37973. +
  37974. +#include "dwc_cc.h"
  37975. +
  37976. +typedef struct dwc_cc
  37977. +{
  37978. + uint32_t uid;
  37979. + uint8_t chid[16];
  37980. + uint8_t cdid[16];
  37981. + uint8_t ck[16];
  37982. + uint8_t *name;
  37983. + uint8_t length;
  37984. + DWC_CIRCLEQ_ENTRY(dwc_cc) list_entry;
  37985. +} dwc_cc_t;
  37986. +
  37987. +DWC_CIRCLEQ_HEAD(context_list, dwc_cc);
  37988. +
  37989. +/** The main structure for CC management. */
  37990. +struct dwc_cc_if
  37991. +{
  37992. + dwc_mutex_t *mutex;
  37993. + char *filename;
  37994. +
  37995. + unsigned is_host:1;
  37996. +
  37997. + dwc_notifier_t *notifier;
  37998. +
  37999. + struct context_list list;
  38000. +};
  38001. +
  38002. +#ifdef DEBUG
  38003. +static inline void dump_bytes(char *name, uint8_t *bytes, int len)
  38004. +{
  38005. + int i;
  38006. + DWC_PRINTF("%s: ", name);
  38007. + for (i=0; i<len; i++) {
  38008. + DWC_PRINTF("%02x ", bytes[i]);
  38009. + }
  38010. + DWC_PRINTF("\n");
  38011. +}
  38012. +#else
  38013. +#define dump_bytes(x...)
  38014. +#endif
  38015. +
  38016. +static dwc_cc_t *alloc_cc(void *mem_ctx, uint8_t *name, uint32_t length)
  38017. +{
  38018. + dwc_cc_t *cc = dwc_alloc(mem_ctx, sizeof(dwc_cc_t));
  38019. + if (!cc) {
  38020. + return NULL;
  38021. + }
  38022. + DWC_MEMSET(cc, 0, sizeof(dwc_cc_t));
  38023. +
  38024. + if (name) {
  38025. + cc->length = length;
  38026. + cc->name = dwc_alloc(mem_ctx, length);
  38027. + if (!cc->name) {
  38028. + dwc_free(mem_ctx, cc);
  38029. + return NULL;
  38030. + }
  38031. +
  38032. + DWC_MEMCPY(cc->name, name, length);
  38033. + }
  38034. +
  38035. + return cc;
  38036. +}
  38037. +
  38038. +static void free_cc(void *mem_ctx, dwc_cc_t *cc)
  38039. +{
  38040. + if (cc->name) {
  38041. + dwc_free(mem_ctx, cc->name);
  38042. + }
  38043. + dwc_free(mem_ctx, cc);
  38044. +}
  38045. +
  38046. +static uint32_t next_uid(dwc_cc_if_t *cc_if)
  38047. +{
  38048. + uint32_t uid = 0;
  38049. + dwc_cc_t *cc;
  38050. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  38051. + if (cc->uid > uid) {
  38052. + uid = cc->uid;
  38053. + }
  38054. + }
  38055. +
  38056. + if (uid == 0) {
  38057. + uid = 255;
  38058. + }
  38059. +
  38060. + return uid + 1;
  38061. +}
  38062. +
  38063. +static dwc_cc_t *cc_find(dwc_cc_if_t *cc_if, uint32_t uid)
  38064. +{
  38065. + dwc_cc_t *cc;
  38066. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  38067. + if (cc->uid == uid) {
  38068. + return cc;
  38069. + }
  38070. + }
  38071. + return NULL;
  38072. +}
  38073. +
  38074. +static unsigned int cc_data_size(dwc_cc_if_t *cc_if)
  38075. +{
  38076. + unsigned int size = 0;
  38077. + dwc_cc_t *cc;
  38078. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  38079. + size += (48 + 1);
  38080. + if (cc->name) {
  38081. + size += cc->length;
  38082. + }
  38083. + }
  38084. + return size;
  38085. +}
  38086. +
  38087. +static uint32_t cc_match_chid(dwc_cc_if_t *cc_if, uint8_t *chid)
  38088. +{
  38089. + uint32_t uid = 0;
  38090. + dwc_cc_t *cc;
  38091. +
  38092. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  38093. + if (DWC_MEMCMP(cc->chid, chid, 16) == 0) {
  38094. + uid = cc->uid;
  38095. + break;
  38096. + }
  38097. + }
  38098. + return uid;
  38099. +}
  38100. +static uint32_t cc_match_cdid(dwc_cc_if_t *cc_if, uint8_t *cdid)
  38101. +{
  38102. + uint32_t uid = 0;
  38103. + dwc_cc_t *cc;
  38104. +
  38105. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  38106. + if (DWC_MEMCMP(cc->cdid, cdid, 16) == 0) {
  38107. + uid = cc->uid;
  38108. + break;
  38109. + }
  38110. + }
  38111. + return uid;
  38112. +}
  38113. +
  38114. +/* Internal cc_add */
  38115. +static int32_t cc_add(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *chid,
  38116. + uint8_t *cdid, uint8_t *ck, uint8_t *name, uint8_t length)
  38117. +{
  38118. + dwc_cc_t *cc;
  38119. + uint32_t uid;
  38120. +
  38121. + if (cc_if->is_host) {
  38122. + uid = cc_match_cdid(cc_if, cdid);
  38123. + }
  38124. + else {
  38125. + uid = cc_match_chid(cc_if, chid);
  38126. + }
  38127. +
  38128. + if (uid) {
  38129. + DWC_DEBUGC("Replacing previous connection context id=%d name=%p name_len=%d", uid, name, length);
  38130. + cc = cc_find(cc_if, uid);
  38131. + }
  38132. + else {
  38133. + cc = alloc_cc(mem_ctx, name, length);
  38134. + cc->uid = next_uid(cc_if);
  38135. + DWC_CIRCLEQ_INSERT_TAIL(&cc_if->list, cc, list_entry);
  38136. + }
  38137. +
  38138. + DWC_MEMCPY(&(cc->chid[0]), chid, 16);
  38139. + DWC_MEMCPY(&(cc->cdid[0]), cdid, 16);
  38140. + DWC_MEMCPY(&(cc->ck[0]), ck, 16);
  38141. +
  38142. + DWC_DEBUGC("Added connection context id=%d name=%p name_len=%d", cc->uid, name, length);
  38143. + dump_bytes("CHID", cc->chid, 16);
  38144. + dump_bytes("CDID", cc->cdid, 16);
  38145. + dump_bytes("CK", cc->ck, 16);
  38146. + return cc->uid;
  38147. +}
  38148. +
  38149. +/* Internal cc_clear */
  38150. +static void cc_clear(void *mem_ctx, dwc_cc_if_t *cc_if)
  38151. +{
  38152. + while (!DWC_CIRCLEQ_EMPTY(&cc_if->list)) {
  38153. + dwc_cc_t *cc = DWC_CIRCLEQ_FIRST(&cc_if->list);
  38154. + DWC_CIRCLEQ_REMOVE_INIT(&cc_if->list, cc, list_entry);
  38155. + free_cc(mem_ctx, cc);
  38156. + }
  38157. +}
  38158. +
  38159. +dwc_cc_if_t *dwc_cc_if_alloc(void *mem_ctx, void *mtx_ctx,
  38160. + dwc_notifier_t *notifier, unsigned is_host)
  38161. +{
  38162. + dwc_cc_if_t *cc_if = NULL;
  38163. +
  38164. + /* Allocate a common_cc_if structure */
  38165. + cc_if = dwc_alloc(mem_ctx, sizeof(dwc_cc_if_t));
  38166. +
  38167. + if (!cc_if)
  38168. + return NULL;
  38169. +
  38170. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  38171. + DWC_MUTEX_ALLOC_LINUX_DEBUG(cc_if->mutex);
  38172. +#else
  38173. + cc_if->mutex = dwc_mutex_alloc(mtx_ctx);
  38174. +#endif
  38175. + if (!cc_if->mutex) {
  38176. + dwc_free(mem_ctx, cc_if);
  38177. + return NULL;
  38178. + }
  38179. +
  38180. + DWC_CIRCLEQ_INIT(&cc_if->list);
  38181. + cc_if->is_host = is_host;
  38182. + cc_if->notifier = notifier;
  38183. + return cc_if;
  38184. +}
  38185. +
  38186. +void dwc_cc_if_free(void *mem_ctx, void *mtx_ctx, dwc_cc_if_t *cc_if)
  38187. +{
  38188. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  38189. + DWC_MUTEX_FREE(cc_if->mutex);
  38190. +#else
  38191. + dwc_mutex_free(mtx_ctx, cc_if->mutex);
  38192. +#endif
  38193. + cc_clear(mem_ctx, cc_if);
  38194. + dwc_free(mem_ctx, cc_if);
  38195. +}
  38196. +
  38197. +static void cc_changed(dwc_cc_if_t *cc_if)
  38198. +{
  38199. + if (cc_if->notifier) {
  38200. + dwc_notify(cc_if->notifier, DWC_CC_LIST_CHANGED_NOTIFICATION, cc_if);
  38201. + }
  38202. +}
  38203. +
  38204. +void dwc_cc_clear(void *mem_ctx, dwc_cc_if_t *cc_if)
  38205. +{
  38206. + DWC_MUTEX_LOCK(cc_if->mutex);
  38207. + cc_clear(mem_ctx, cc_if);
  38208. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  38209. + cc_changed(cc_if);
  38210. +}
  38211. +
  38212. +int32_t dwc_cc_add(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *chid,
  38213. + uint8_t *cdid, uint8_t *ck, uint8_t *name, uint8_t length)
  38214. +{
  38215. + uint32_t uid;
  38216. +
  38217. + DWC_MUTEX_LOCK(cc_if->mutex);
  38218. + uid = cc_add(mem_ctx, cc_if, chid, cdid, ck, name, length);
  38219. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  38220. + cc_changed(cc_if);
  38221. +
  38222. + return uid;
  38223. +}
  38224. +
  38225. +void dwc_cc_change(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id, uint8_t *chid,
  38226. + uint8_t *cdid, uint8_t *ck, uint8_t *name, uint8_t length)
  38227. +{
  38228. + dwc_cc_t* cc;
  38229. +
  38230. + DWC_DEBUGC("Change connection context %d", id);
  38231. +
  38232. + DWC_MUTEX_LOCK(cc_if->mutex);
  38233. + cc = cc_find(cc_if, id);
  38234. + if (!cc) {
  38235. + DWC_ERROR("Uid %d not found in cc list\n", id);
  38236. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  38237. + return;
  38238. + }
  38239. +
  38240. + if (chid) {
  38241. + DWC_MEMCPY(&(cc->chid[0]), chid, 16);
  38242. + }
  38243. + if (cdid) {
  38244. + DWC_MEMCPY(&(cc->cdid[0]), cdid, 16);
  38245. + }
  38246. + if (ck) {
  38247. + DWC_MEMCPY(&(cc->ck[0]), ck, 16);
  38248. + }
  38249. +
  38250. + if (name) {
  38251. + if (cc->name) {
  38252. + dwc_free(mem_ctx, cc->name);
  38253. + }
  38254. + cc->name = dwc_alloc(mem_ctx, length);
  38255. + if (!cc->name) {
  38256. + DWC_ERROR("Out of memory in dwc_cc_change()\n");
  38257. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  38258. + return;
  38259. + }
  38260. + cc->length = length;
  38261. + DWC_MEMCPY(cc->name, name, length);
  38262. + }
  38263. +
  38264. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  38265. +
  38266. + cc_changed(cc_if);
  38267. +
  38268. + DWC_DEBUGC("Changed connection context id=%d\n", id);
  38269. + dump_bytes("New CHID", cc->chid, 16);
  38270. + dump_bytes("New CDID", cc->cdid, 16);
  38271. + dump_bytes("New CK", cc->ck, 16);
  38272. +}
  38273. +
  38274. +void dwc_cc_remove(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id)
  38275. +{
  38276. + dwc_cc_t *cc;
  38277. +
  38278. + DWC_DEBUGC("Removing connection context %d", id);
  38279. +
  38280. + DWC_MUTEX_LOCK(cc_if->mutex);
  38281. + cc = cc_find(cc_if, id);
  38282. + if (!cc) {
  38283. + DWC_ERROR("Uid %d not found in cc list\n", id);
  38284. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  38285. + return;
  38286. + }
  38287. +
  38288. + DWC_CIRCLEQ_REMOVE_INIT(&cc_if->list, cc, list_entry);
  38289. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  38290. + free_cc(mem_ctx, cc);
  38291. +
  38292. + cc_changed(cc_if);
  38293. +}
  38294. +
  38295. +uint8_t *dwc_cc_data_for_save(void *mem_ctx, dwc_cc_if_t *cc_if, unsigned int *length)
  38296. +{
  38297. + uint8_t *buf, *x;
  38298. + uint8_t zero = 0;
  38299. + dwc_cc_t *cc;
  38300. +
  38301. + DWC_MUTEX_LOCK(cc_if->mutex);
  38302. + *length = cc_data_size(cc_if);
  38303. + if (!(*length)) {
  38304. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  38305. + return NULL;
  38306. + }
  38307. +
  38308. + DWC_DEBUGC("Creating data for saving (length=%d)", *length);
  38309. +
  38310. + buf = dwc_alloc(mem_ctx, *length);
  38311. + if (!buf) {
  38312. + *length = 0;
  38313. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  38314. + return NULL;
  38315. + }
  38316. +
  38317. + x = buf;
  38318. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  38319. + DWC_MEMCPY(x, cc->chid, 16);
  38320. + x += 16;
  38321. + DWC_MEMCPY(x, cc->cdid, 16);
  38322. + x += 16;
  38323. + DWC_MEMCPY(x, cc->ck, 16);
  38324. + x += 16;
  38325. + if (cc->name) {
  38326. + DWC_MEMCPY(x, &cc->length, 1);
  38327. + x += 1;
  38328. + DWC_MEMCPY(x, cc->name, cc->length);
  38329. + x += cc->length;
  38330. + }
  38331. + else {
  38332. + DWC_MEMCPY(x, &zero, 1);
  38333. + x += 1;
  38334. + }
  38335. + }
  38336. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  38337. +
  38338. + return buf;
  38339. +}
  38340. +
  38341. +void dwc_cc_restore_from_data(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *data, uint32_t length)
  38342. +{
  38343. + uint8_t name_length;
  38344. + uint8_t *name;
  38345. + uint8_t *chid;
  38346. + uint8_t *cdid;
  38347. + uint8_t *ck;
  38348. + uint32_t i = 0;
  38349. +
  38350. + DWC_MUTEX_LOCK(cc_if->mutex);
  38351. + cc_clear(mem_ctx, cc_if);
  38352. +
  38353. + while (i < length) {
  38354. + chid = &data[i];
  38355. + i += 16;
  38356. + cdid = &data[i];
  38357. + i += 16;
  38358. + ck = &data[i];
  38359. + i += 16;
  38360. +
  38361. + name_length = data[i];
  38362. + i ++;
  38363. +
  38364. + if (name_length) {
  38365. + name = &data[i];
  38366. + i += name_length;
  38367. + }
  38368. + else {
  38369. + name = NULL;
  38370. + }
  38371. +
  38372. + /* check to see if we haven't overflown the buffer */
  38373. + if (i > length) {
  38374. + DWC_ERROR("Data format error while attempting to load CCs "
  38375. + "(nlen=%d, iter=%d, buflen=%d).\n", name_length, i, length);
  38376. + break;
  38377. + }
  38378. +
  38379. + cc_add(mem_ctx, cc_if, chid, cdid, ck, name, name_length);
  38380. + }
  38381. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  38382. +
  38383. + cc_changed(cc_if);
  38384. +}
  38385. +
  38386. +uint32_t dwc_cc_match_chid(dwc_cc_if_t *cc_if, uint8_t *chid)
  38387. +{
  38388. + uint32_t uid = 0;
  38389. +
  38390. + DWC_MUTEX_LOCK(cc_if->mutex);
  38391. + uid = cc_match_chid(cc_if, chid);
  38392. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  38393. + return uid;
  38394. +}
  38395. +uint32_t dwc_cc_match_cdid(dwc_cc_if_t *cc_if, uint8_t *cdid)
  38396. +{
  38397. + uint32_t uid = 0;
  38398. +
  38399. + DWC_MUTEX_LOCK(cc_if->mutex);
  38400. + uid = cc_match_cdid(cc_if, cdid);
  38401. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  38402. + return uid;
  38403. +}
  38404. +
  38405. +uint8_t *dwc_cc_ck(dwc_cc_if_t *cc_if, int32_t id)
  38406. +{
  38407. + uint8_t *ck = NULL;
  38408. + dwc_cc_t *cc;
  38409. +
  38410. + DWC_MUTEX_LOCK(cc_if->mutex);
  38411. + cc = cc_find(cc_if, id);
  38412. + if (cc) {
  38413. + ck = cc->ck;
  38414. + }
  38415. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  38416. +
  38417. + return ck;
  38418. +
  38419. +}
  38420. +
  38421. +uint8_t *dwc_cc_chid(dwc_cc_if_t *cc_if, int32_t id)
  38422. +{
  38423. + uint8_t *retval = NULL;
  38424. + dwc_cc_t *cc;
  38425. +
  38426. + DWC_MUTEX_LOCK(cc_if->mutex);
  38427. + cc = cc_find(cc_if, id);
  38428. + if (cc) {
  38429. + retval = cc->chid;
  38430. + }
  38431. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  38432. +
  38433. + return retval;
  38434. +}
  38435. +
  38436. +uint8_t *dwc_cc_cdid(dwc_cc_if_t *cc_if, int32_t id)
  38437. +{
  38438. + uint8_t *retval = NULL;
  38439. + dwc_cc_t *cc;
  38440. +
  38441. + DWC_MUTEX_LOCK(cc_if->mutex);
  38442. + cc = cc_find(cc_if, id);
  38443. + if (cc) {
  38444. + retval = cc->cdid;
  38445. + }
  38446. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  38447. +
  38448. + return retval;
  38449. +}
  38450. +
  38451. +uint8_t *dwc_cc_name(dwc_cc_if_t *cc_if, int32_t id, uint8_t *length)
  38452. +{
  38453. + uint8_t *retval = NULL;
  38454. + dwc_cc_t *cc;
  38455. +
  38456. + DWC_MUTEX_LOCK(cc_if->mutex);
  38457. + *length = 0;
  38458. + cc = cc_find(cc_if, id);
  38459. + if (cc) {
  38460. + *length = cc->length;
  38461. + retval = cc->name;
  38462. + }
  38463. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  38464. +
  38465. + return retval;
  38466. +}
  38467. +
  38468. +#endif /* DWC_CCLIB */
  38469. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_common_port/dwc_cc.h linux-3.13.3/drivers/usb/host/dwc_common_port/dwc_cc.h
  38470. --- linux-3.13.3.orig/drivers/usb/host/dwc_common_port/dwc_cc.h 1970-01-01 01:00:00.000000000 +0100
  38471. +++ linux-3.13.3/drivers/usb/host/dwc_common_port/dwc_cc.h 2014-02-17 22:41:01.000000000 +0100
  38472. @@ -0,0 +1,224 @@
  38473. +/* =========================================================================
  38474. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_cc.h $
  38475. + * $Revision: #4 $
  38476. + * $Date: 2010/09/28 $
  38477. + * $Change: 1596182 $
  38478. + *
  38479. + * Synopsys Portability Library Software and documentation
  38480. + * (hereinafter, "Software") is an Unsupported proprietary work of
  38481. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  38482. + * between Synopsys and you.
  38483. + *
  38484. + * The Software IS NOT an item of Licensed Software or Licensed Product
  38485. + * under any End User Software License Agreement or Agreement for
  38486. + * Licensed Product with Synopsys or any supplement thereto. You are
  38487. + * permitted to use and redistribute this Software in source and binary
  38488. + * forms, with or without modification, provided that redistributions
  38489. + * of source code must retain this notice. You may not view, use,
  38490. + * disclose, copy or distribute this file or any information contained
  38491. + * herein except pursuant to this license grant from Synopsys. If you
  38492. + * do not agree with this notice, including the disclaimer below, then
  38493. + * you are not authorized to use the Software.
  38494. + *
  38495. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  38496. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  38497. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  38498. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  38499. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  38500. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  38501. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  38502. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  38503. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  38504. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  38505. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  38506. + * DAMAGE.
  38507. + * ========================================================================= */
  38508. +#ifndef _DWC_CC_H_
  38509. +#define _DWC_CC_H_
  38510. +
  38511. +#ifdef __cplusplus
  38512. +extern "C" {
  38513. +#endif
  38514. +
  38515. +/** @file
  38516. + *
  38517. + * This file defines the Context Context library.
  38518. + *
  38519. + * The main data structure is dwc_cc_if_t which is returned by either the
  38520. + * dwc_cc_if_alloc function or returned by the module to the user via a provided
  38521. + * function. The data structure is opaque and should only be manipulated via the
  38522. + * functions provied in this API.
  38523. + *
  38524. + * It manages a list of connection contexts and operations can be performed to
  38525. + * add, remove, query, search, and change, those contexts. Additionally,
  38526. + * a dwc_notifier_t object can be requested from the manager so that
  38527. + * the user can be notified whenever the context list has changed.
  38528. + */
  38529. +
  38530. +#include "dwc_os.h"
  38531. +#include "dwc_list.h"
  38532. +#include "dwc_notifier.h"
  38533. +
  38534. +
  38535. +/* Notifications */
  38536. +#define DWC_CC_LIST_CHANGED_NOTIFICATION "DWC_CC_LIST_CHANGED_NOTIFICATION"
  38537. +
  38538. +struct dwc_cc_if;
  38539. +typedef struct dwc_cc_if dwc_cc_if_t;
  38540. +
  38541. +
  38542. +/** @name Connection Context Operations */
  38543. +/** @{ */
  38544. +
  38545. +/** This function allocates memory for a dwc_cc_if_t structure, initializes
  38546. + * fields to default values, and returns a pointer to the structure or NULL on
  38547. + * error. */
  38548. +extern dwc_cc_if_t *dwc_cc_if_alloc(void *mem_ctx, void *mtx_ctx,
  38549. + dwc_notifier_t *notifier, unsigned is_host);
  38550. +
  38551. +/** Frees the memory for the specified CC structure allocated from
  38552. + * dwc_cc_if_alloc(). */
  38553. +extern void dwc_cc_if_free(void *mem_ctx, void *mtx_ctx, dwc_cc_if_t *cc_if);
  38554. +
  38555. +/** Removes all contexts from the connection context list */
  38556. +extern void dwc_cc_clear(void *mem_ctx, dwc_cc_if_t *cc_if);
  38557. +
  38558. +/** Adds a connection context (CHID, CK, CDID, Name) to the connection context list.
  38559. + * If a CHID already exists, the CK and name are overwritten. Statistics are
  38560. + * not overwritten.
  38561. + *
  38562. + * @param cc_if The cc_if structure.
  38563. + * @param chid A pointer to the 16-byte CHID. This value will be copied.
  38564. + * @param ck A pointer to the 16-byte CK. This value will be copied.
  38565. + * @param cdid A pointer to the 16-byte CDID. This value will be copied.
  38566. + * @param name An optional host friendly name as defined in the association model
  38567. + * spec. Must be a UTF16-LE unicode string. Can be NULL to indicated no name.
  38568. + * @param length The length othe unicode string.
  38569. + * @return A unique identifier used to refer to this context that is valid for
  38570. + * as long as this context is still in the list. */
  38571. +extern int32_t dwc_cc_add(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *chid,
  38572. + uint8_t *cdid, uint8_t *ck, uint8_t *name,
  38573. + uint8_t length);
  38574. +
  38575. +/** Changes the CHID, CK, CDID, or Name values of a connection context in the
  38576. + * list, preserving any accumulated statistics. This would typically be called
  38577. + * if the host decideds to change the context with a SET_CONNECTION request.
  38578. + *
  38579. + * @param cc_if The cc_if structure.
  38580. + * @param id The identifier of the connection context.
  38581. + * @param chid A pointer to the 16-byte CHID. This value will be copied. NULL
  38582. + * indicates no change.
  38583. + * @param cdid A pointer to the 16-byte CDID. This value will be copied. NULL
  38584. + * indicates no change.
  38585. + * @param ck A pointer to the 16-byte CK. This value will be copied. NULL
  38586. + * indicates no change.
  38587. + * @param name Host friendly name UTF16-LE. NULL indicates no change.
  38588. + * @param length Length of name. */
  38589. +extern void dwc_cc_change(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id,
  38590. + uint8_t *chid, uint8_t *cdid, uint8_t *ck,
  38591. + uint8_t *name, uint8_t length);
  38592. +
  38593. +/** Remove the specified connection context.
  38594. + * @param cc_if The cc_if structure.
  38595. + * @param id The identifier of the connection context to remove. */
  38596. +extern void dwc_cc_remove(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id);
  38597. +
  38598. +/** Get a binary block of data for the connection context list and attributes.
  38599. + * This data can be used by the OS specific driver to save the connection
  38600. + * context list into non-volatile memory.
  38601. + *
  38602. + * @param cc_if The cc_if structure.
  38603. + * @param length Return the length of the data buffer.
  38604. + * @return A pointer to the data buffer. The memory for this buffer should be
  38605. + * freed with DWC_FREE() after use. */
  38606. +extern uint8_t *dwc_cc_data_for_save(void *mem_ctx, dwc_cc_if_t *cc_if,
  38607. + unsigned int *length);
  38608. +
  38609. +/** Restore the connection context list from the binary data that was previously
  38610. + * returned from a call to dwc_cc_data_for_save. This can be used by the OS specific
  38611. + * driver to load a connection context list from non-volatile memory.
  38612. + *
  38613. + * @param cc_if The cc_if structure.
  38614. + * @param data The data bytes as returned from dwc_cc_data_for_save.
  38615. + * @param length The length of the data. */
  38616. +extern void dwc_cc_restore_from_data(void *mem_ctx, dwc_cc_if_t *cc_if,
  38617. + uint8_t *data, unsigned int length);
  38618. +
  38619. +/** Find the connection context from the specified CHID.
  38620. + *
  38621. + * @param cc_if The cc_if structure.
  38622. + * @param chid A pointer to the CHID data.
  38623. + * @return A non-zero identifier of the connection context if the CHID matches.
  38624. + * Otherwise returns 0. */
  38625. +extern uint32_t dwc_cc_match_chid(dwc_cc_if_t *cc_if, uint8_t *chid);
  38626. +
  38627. +/** Find the connection context from the specified CDID.
  38628. + *
  38629. + * @param cc_if The cc_if structure.
  38630. + * @param cdid A pointer to the CDID data.
  38631. + * @return A non-zero identifier of the connection context if the CHID matches.
  38632. + * Otherwise returns 0. */
  38633. +extern uint32_t dwc_cc_match_cdid(dwc_cc_if_t *cc_if, uint8_t *cdid);
  38634. +
  38635. +/** Retrieve the CK from the specified connection context.
  38636. + *
  38637. + * @param cc_if The cc_if structure.
  38638. + * @param id The identifier of the connection context.
  38639. + * @return A pointer to the CK data. The memory does not need to be freed. */
  38640. +extern uint8_t *dwc_cc_ck(dwc_cc_if_t *cc_if, int32_t id);
  38641. +
  38642. +/** Retrieve the CHID from the specified connection context.
  38643. + *
  38644. + * @param cc_if The cc_if structure.
  38645. + * @param id The identifier of the connection context.
  38646. + * @return A pointer to the CHID data. The memory does not need to be freed. */
  38647. +extern uint8_t *dwc_cc_chid(dwc_cc_if_t *cc_if, int32_t id);
  38648. +
  38649. +/** Retrieve the CDID from the specified connection context.
  38650. + *
  38651. + * @param cc_if The cc_if structure.
  38652. + * @param id The identifier of the connection context.
  38653. + * @return A pointer to the CDID data. The memory does not need to be freed. */
  38654. +extern uint8_t *dwc_cc_cdid(dwc_cc_if_t *cc_if, int32_t id);
  38655. +
  38656. +extern uint8_t *dwc_cc_name(dwc_cc_if_t *cc_if, int32_t id, uint8_t *length);
  38657. +
  38658. +/** Checks a buffer for non-zero.
  38659. + * @param id A pointer to a 16 byte buffer.
  38660. + * @return true if the 16 byte value is non-zero. */
  38661. +static inline unsigned dwc_assoc_is_not_zero_id(uint8_t *id) {
  38662. + int i;
  38663. + for (i=0; i<16; i++) {
  38664. + if (id[i]) return 1;
  38665. + }
  38666. + return 0;
  38667. +}
  38668. +
  38669. +/** Checks a buffer for zero.
  38670. + * @param id A pointer to a 16 byte buffer.
  38671. + * @return true if the 16 byte value is zero. */
  38672. +static inline unsigned dwc_assoc_is_zero_id(uint8_t *id) {
  38673. + return !dwc_assoc_is_not_zero_id(id);
  38674. +}
  38675. +
  38676. +/** Prints an ASCII representation for the 16-byte chid, cdid, or ck, into
  38677. + * buffer. */
  38678. +static inline int dwc_print_id_string(char *buffer, uint8_t *id) {
  38679. + char *ptr = buffer;
  38680. + int i;
  38681. + for (i=0; i<16; i++) {
  38682. + ptr += DWC_SPRINTF(ptr, "%02x", id[i]);
  38683. + if (i < 15) {
  38684. + ptr += DWC_SPRINTF(ptr, " ");
  38685. + }
  38686. + }
  38687. + return ptr - buffer;
  38688. +}
  38689. +
  38690. +/** @} */
  38691. +
  38692. +#ifdef __cplusplus
  38693. +}
  38694. +#endif
  38695. +
  38696. +#endif /* _DWC_CC_H_ */
  38697. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c linux-3.13.3/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c
  38698. --- linux-3.13.3.orig/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c 1970-01-01 01:00:00.000000000 +0100
  38699. +++ linux-3.13.3/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c 2014-02-17 22:41:01.000000000 +0100
  38700. @@ -0,0 +1,1308 @@
  38701. +#include "dwc_os.h"
  38702. +#include "dwc_list.h"
  38703. +
  38704. +#ifdef DWC_CCLIB
  38705. +# include "dwc_cc.h"
  38706. +#endif
  38707. +
  38708. +#ifdef DWC_CRYPTOLIB
  38709. +# include "dwc_modpow.h"
  38710. +# include "dwc_dh.h"
  38711. +# include "dwc_crypto.h"
  38712. +#endif
  38713. +
  38714. +#ifdef DWC_NOTIFYLIB
  38715. +# include "dwc_notifier.h"
  38716. +#endif
  38717. +
  38718. +/* OS-Level Implementations */
  38719. +
  38720. +/* This is the FreeBSD 7.0 kernel implementation of the DWC platform library. */
  38721. +
  38722. +
  38723. +/* MISC */
  38724. +
  38725. +void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size)
  38726. +{
  38727. + return memset(dest, byte, size);
  38728. +}
  38729. +
  38730. +void *DWC_MEMCPY(void *dest, void const *src, uint32_t size)
  38731. +{
  38732. + return memcpy(dest, src, size);
  38733. +}
  38734. +
  38735. +void *DWC_MEMMOVE(void *dest, void *src, uint32_t size)
  38736. +{
  38737. + bcopy(src, dest, size);
  38738. + return dest;
  38739. +}
  38740. +
  38741. +int DWC_MEMCMP(void *m1, void *m2, uint32_t size)
  38742. +{
  38743. + return memcmp(m1, m2, size);
  38744. +}
  38745. +
  38746. +int DWC_STRNCMP(void *s1, void *s2, uint32_t size)
  38747. +{
  38748. + return strncmp(s1, s2, size);
  38749. +}
  38750. +
  38751. +int DWC_STRCMP(void *s1, void *s2)
  38752. +{
  38753. + return strcmp(s1, s2);
  38754. +}
  38755. +
  38756. +int DWC_STRLEN(char const *str)
  38757. +{
  38758. + return strlen(str);
  38759. +}
  38760. +
  38761. +char *DWC_STRCPY(char *to, char const *from)
  38762. +{
  38763. + return strcpy(to, from);
  38764. +}
  38765. +
  38766. +char *DWC_STRDUP(char const *str)
  38767. +{
  38768. + int len = DWC_STRLEN(str) + 1;
  38769. + char *new = DWC_ALLOC_ATOMIC(len);
  38770. +
  38771. + if (!new) {
  38772. + return NULL;
  38773. + }
  38774. +
  38775. + DWC_MEMCPY(new, str, len);
  38776. + return new;
  38777. +}
  38778. +
  38779. +int DWC_ATOI(char *str, int32_t *value)
  38780. +{
  38781. + char *end = NULL;
  38782. +
  38783. + *value = strtol(str, &end, 0);
  38784. + if (*end == '\0') {
  38785. + return 0;
  38786. + }
  38787. +
  38788. + return -1;
  38789. +}
  38790. +
  38791. +int DWC_ATOUI(char *str, uint32_t *value)
  38792. +{
  38793. + char *end = NULL;
  38794. +
  38795. + *value = strtoul(str, &end, 0);
  38796. + if (*end == '\0') {
  38797. + return 0;
  38798. + }
  38799. +
  38800. + return -1;
  38801. +}
  38802. +
  38803. +
  38804. +#ifdef DWC_UTFLIB
  38805. +/* From usbstring.c */
  38806. +
  38807. +int DWC_UTF8_TO_UTF16LE(uint8_t const *s, uint16_t *cp, unsigned len)
  38808. +{
  38809. + int count = 0;
  38810. + u8 c;
  38811. + u16 uchar;
  38812. +
  38813. + /* this insists on correct encodings, though not minimal ones.
  38814. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  38815. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  38816. + */
  38817. + while (len != 0 && (c = (u8) *s++) != 0) {
  38818. + if (unlikely(c & 0x80)) {
  38819. + // 2-byte sequence:
  38820. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  38821. + if ((c & 0xe0) == 0xc0) {
  38822. + uchar = (c & 0x1f) << 6;
  38823. +
  38824. + c = (u8) *s++;
  38825. + if ((c & 0xc0) != 0xc0)
  38826. + goto fail;
  38827. + c &= 0x3f;
  38828. + uchar |= c;
  38829. +
  38830. + // 3-byte sequence (most CJKV characters):
  38831. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  38832. + } else if ((c & 0xf0) == 0xe0) {
  38833. + uchar = (c & 0x0f) << 12;
  38834. +
  38835. + c = (u8) *s++;
  38836. + if ((c & 0xc0) != 0xc0)
  38837. + goto fail;
  38838. + c &= 0x3f;
  38839. + uchar |= c << 6;
  38840. +
  38841. + c = (u8) *s++;
  38842. + if ((c & 0xc0) != 0xc0)
  38843. + goto fail;
  38844. + c &= 0x3f;
  38845. + uchar |= c;
  38846. +
  38847. + /* no bogus surrogates */
  38848. + if (0xd800 <= uchar && uchar <= 0xdfff)
  38849. + goto fail;
  38850. +
  38851. + // 4-byte sequence (surrogate pairs, currently rare):
  38852. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  38853. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  38854. + // (uuuuu = wwww + 1)
  38855. + // FIXME accept the surrogate code points (only)
  38856. + } else
  38857. + goto fail;
  38858. + } else
  38859. + uchar = c;
  38860. + put_unaligned (cpu_to_le16 (uchar), cp++);
  38861. + count++;
  38862. + len--;
  38863. + }
  38864. + return count;
  38865. +fail:
  38866. + return -1;
  38867. +}
  38868. +
  38869. +#endif /* DWC_UTFLIB */
  38870. +
  38871. +
  38872. +/* dwc_debug.h */
  38873. +
  38874. +dwc_bool_t DWC_IN_IRQ(void)
  38875. +{
  38876. +// return in_irq();
  38877. + return 0;
  38878. +}
  38879. +
  38880. +dwc_bool_t DWC_IN_BH(void)
  38881. +{
  38882. +// return in_softirq();
  38883. + return 0;
  38884. +}
  38885. +
  38886. +void DWC_VPRINTF(char *format, va_list args)
  38887. +{
  38888. + vprintf(format, args);
  38889. +}
  38890. +
  38891. +int DWC_VSNPRINTF(char *str, int size, char *format, va_list args)
  38892. +{
  38893. + return vsnprintf(str, size, format, args);
  38894. +}
  38895. +
  38896. +void DWC_PRINTF(char *format, ...)
  38897. +{
  38898. + va_list args;
  38899. +
  38900. + va_start(args, format);
  38901. + DWC_VPRINTF(format, args);
  38902. + va_end(args);
  38903. +}
  38904. +
  38905. +int DWC_SPRINTF(char *buffer, char *format, ...)
  38906. +{
  38907. + int retval;
  38908. + va_list args;
  38909. +
  38910. + va_start(args, format);
  38911. + retval = vsprintf(buffer, format, args);
  38912. + va_end(args);
  38913. + return retval;
  38914. +}
  38915. +
  38916. +int DWC_SNPRINTF(char *buffer, int size, char *format, ...)
  38917. +{
  38918. + int retval;
  38919. + va_list args;
  38920. +
  38921. + va_start(args, format);
  38922. + retval = vsnprintf(buffer, size, format, args);
  38923. + va_end(args);
  38924. + return retval;
  38925. +}
  38926. +
  38927. +void __DWC_WARN(char *format, ...)
  38928. +{
  38929. + va_list args;
  38930. +
  38931. + va_start(args, format);
  38932. + DWC_VPRINTF(format, args);
  38933. + va_end(args);
  38934. +}
  38935. +
  38936. +void __DWC_ERROR(char *format, ...)
  38937. +{
  38938. + va_list args;
  38939. +
  38940. + va_start(args, format);
  38941. + DWC_VPRINTF(format, args);
  38942. + va_end(args);
  38943. +}
  38944. +
  38945. +void DWC_EXCEPTION(char *format, ...)
  38946. +{
  38947. + va_list args;
  38948. +
  38949. + va_start(args, format);
  38950. + DWC_VPRINTF(format, args);
  38951. + va_end(args);
  38952. +// BUG_ON(1); ???
  38953. +}
  38954. +
  38955. +#ifdef DEBUG
  38956. +void __DWC_DEBUG(char *format, ...)
  38957. +{
  38958. + va_list args;
  38959. +
  38960. + va_start(args, format);
  38961. + DWC_VPRINTF(format, args);
  38962. + va_end(args);
  38963. +}
  38964. +#endif
  38965. +
  38966. +
  38967. +/* dwc_mem.h */
  38968. +
  38969. +#if 0
  38970. +dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size,
  38971. + uint32_t align,
  38972. + uint32_t alloc)
  38973. +{
  38974. + struct dma_pool *pool = dma_pool_create("Pool", NULL,
  38975. + size, align, alloc);
  38976. + return (dwc_pool_t *)pool;
  38977. +}
  38978. +
  38979. +void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool)
  38980. +{
  38981. + dma_pool_destroy((struct dma_pool *)pool);
  38982. +}
  38983. +
  38984. +void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  38985. +{
  38986. +// return dma_pool_alloc((struct dma_pool *)pool, GFP_KERNEL, dma_addr);
  38987. + return dma_pool_alloc((struct dma_pool *)pool, M_WAITOK, dma_addr);
  38988. +}
  38989. +
  38990. +void *DWC_DMA_POOL_ZALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  38991. +{
  38992. + void *vaddr = DWC_DMA_POOL_ALLOC(pool, dma_addr);
  38993. + memset(..);
  38994. +}
  38995. +
  38996. +void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr)
  38997. +{
  38998. + dma_pool_free(pool, vaddr, daddr);
  38999. +}
  39000. +#endif
  39001. +
  39002. +static void dmamap_cb(void *arg, bus_dma_segment_t *segs, int nseg, int error)
  39003. +{
  39004. + if (error)
  39005. + return;
  39006. + *(bus_addr_t *)arg = segs[0].ds_addr;
  39007. +}
  39008. +
  39009. +void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  39010. +{
  39011. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  39012. + int error;
  39013. +
  39014. + error = bus_dma_tag_create(
  39015. +#if __FreeBSD_version >= 700000
  39016. + bus_get_dma_tag(dma->dev), /* parent */
  39017. +#else
  39018. + NULL, /* parent */
  39019. +#endif
  39020. + 4, 0, /* alignment, bounds */
  39021. + BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
  39022. + BUS_SPACE_MAXADDR, /* highaddr */
  39023. + NULL, NULL, /* filter, filterarg */
  39024. + size, /* maxsize */
  39025. + 1, /* nsegments */
  39026. + size, /* maxsegsize */
  39027. + 0, /* flags */
  39028. + NULL, /* lockfunc */
  39029. + NULL, /* lockarg */
  39030. + &dma->dma_tag);
  39031. + if (error) {
  39032. + device_printf(dma->dev, "%s: bus_dma_tag_create failed: %d\n",
  39033. + __func__, error);
  39034. + goto fail_0;
  39035. + }
  39036. +
  39037. + error = bus_dmamem_alloc(dma->dma_tag, &dma->dma_vaddr,
  39038. + BUS_DMA_NOWAIT | BUS_DMA_COHERENT, &dma->dma_map);
  39039. + if (error) {
  39040. + device_printf(dma->dev, "%s: bus_dmamem_alloc(%ju) failed: %d\n",
  39041. + __func__, (uintmax_t)size, error);
  39042. + goto fail_1;
  39043. + }
  39044. +
  39045. + dma->dma_paddr = 0;
  39046. + error = bus_dmamap_load(dma->dma_tag, dma->dma_map, dma->dma_vaddr, size,
  39047. + dmamap_cb, &dma->dma_paddr, BUS_DMA_NOWAIT);
  39048. + if (error || dma->dma_paddr == 0) {
  39049. + device_printf(dma->dev, "%s: bus_dmamap_load failed: %d\n",
  39050. + __func__, error);
  39051. + goto fail_2;
  39052. + }
  39053. +
  39054. + *dma_addr = dma->dma_paddr;
  39055. + return dma->dma_vaddr;
  39056. +
  39057. +fail_2:
  39058. + bus_dmamap_unload(dma->dma_tag, dma->dma_map);
  39059. +fail_1:
  39060. + bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
  39061. + bus_dma_tag_destroy(dma->dma_tag);
  39062. +fail_0:
  39063. + dma->dma_map = NULL;
  39064. + dma->dma_tag = NULL;
  39065. +
  39066. + return NULL;
  39067. +}
  39068. +
  39069. +void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr)
  39070. +{
  39071. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  39072. +
  39073. + if (dma->dma_tag == NULL)
  39074. + return;
  39075. + if (dma->dma_map != NULL) {
  39076. + bus_dmamap_sync(dma->dma_tag, dma->dma_map,
  39077. + BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
  39078. + bus_dmamap_unload(dma->dma_tag, dma->dma_map);
  39079. + bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
  39080. + dma->dma_map = NULL;
  39081. + }
  39082. +
  39083. + bus_dma_tag_destroy(dma->dma_tag);
  39084. + dma->dma_tag = NULL;
  39085. +}
  39086. +
  39087. +void *__DWC_ALLOC(void *mem_ctx, uint32_t size)
  39088. +{
  39089. + return malloc(size, M_DEVBUF, M_WAITOK | M_ZERO);
  39090. +}
  39091. +
  39092. +void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size)
  39093. +{
  39094. + return malloc(size, M_DEVBUF, M_NOWAIT | M_ZERO);
  39095. +}
  39096. +
  39097. +void __DWC_FREE(void *mem_ctx, void *addr)
  39098. +{
  39099. + free(addr, M_DEVBUF);
  39100. +}
  39101. +
  39102. +
  39103. +#ifdef DWC_CRYPTOLIB
  39104. +/* dwc_crypto.h */
  39105. +
  39106. +void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length)
  39107. +{
  39108. + get_random_bytes(buffer, length);
  39109. +}
  39110. +
  39111. +int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out)
  39112. +{
  39113. + struct crypto_blkcipher *tfm;
  39114. + struct blkcipher_desc desc;
  39115. + struct scatterlist sgd;
  39116. + struct scatterlist sgs;
  39117. +
  39118. + tfm = crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC);
  39119. + if (tfm == NULL) {
  39120. + printk("failed to load transform for aes CBC\n");
  39121. + return -1;
  39122. + }
  39123. +
  39124. + crypto_blkcipher_setkey(tfm, key, keylen);
  39125. + crypto_blkcipher_set_iv(tfm, iv, 16);
  39126. +
  39127. + sg_init_one(&sgd, out, messagelen);
  39128. + sg_init_one(&sgs, message, messagelen);
  39129. +
  39130. + desc.tfm = tfm;
  39131. + desc.flags = 0;
  39132. +
  39133. + if (crypto_blkcipher_encrypt(&desc, &sgd, &sgs, messagelen)) {
  39134. + crypto_free_blkcipher(tfm);
  39135. + DWC_ERROR("AES CBC encryption failed");
  39136. + return -1;
  39137. + }
  39138. +
  39139. + crypto_free_blkcipher(tfm);
  39140. + return 0;
  39141. +}
  39142. +
  39143. +int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out)
  39144. +{
  39145. + struct crypto_hash *tfm;
  39146. + struct hash_desc desc;
  39147. + struct scatterlist sg;
  39148. +
  39149. + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
  39150. + if (IS_ERR(tfm)) {
  39151. + DWC_ERROR("Failed to load transform for sha256: %ld", PTR_ERR(tfm));
  39152. + return 0;
  39153. + }
  39154. + desc.tfm = tfm;
  39155. + desc.flags = 0;
  39156. +
  39157. + sg_init_one(&sg, message, len);
  39158. + crypto_hash_digest(&desc, &sg, len, out);
  39159. + crypto_free_hash(tfm);
  39160. +
  39161. + return 1;
  39162. +}
  39163. +
  39164. +int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen,
  39165. + uint8_t *key, uint32_t keylen, uint8_t *out)
  39166. +{
  39167. + struct crypto_hash *tfm;
  39168. + struct hash_desc desc;
  39169. + struct scatterlist sg;
  39170. +
  39171. + tfm = crypto_alloc_hash("hmac(sha256)", 0, CRYPTO_ALG_ASYNC);
  39172. + if (IS_ERR(tfm)) {
  39173. + DWC_ERROR("Failed to load transform for hmac(sha256): %ld", PTR_ERR(tfm));
  39174. + return 0;
  39175. + }
  39176. + desc.tfm = tfm;
  39177. + desc.flags = 0;
  39178. +
  39179. + sg_init_one(&sg, message, messagelen);
  39180. + crypto_hash_setkey(tfm, key, keylen);
  39181. + crypto_hash_digest(&desc, &sg, messagelen, out);
  39182. + crypto_free_hash(tfm);
  39183. +
  39184. + return 1;
  39185. +}
  39186. +
  39187. +#endif /* DWC_CRYPTOLIB */
  39188. +
  39189. +
  39190. +/* Byte Ordering Conversions */
  39191. +
  39192. +uint32_t DWC_CPU_TO_LE32(uint32_t *p)
  39193. +{
  39194. +#ifdef __LITTLE_ENDIAN
  39195. + return *p;
  39196. +#else
  39197. + uint8_t *u_p = (uint8_t *)p;
  39198. +
  39199. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  39200. +#endif
  39201. +}
  39202. +
  39203. +uint32_t DWC_CPU_TO_BE32(uint32_t *p)
  39204. +{
  39205. +#ifdef __BIG_ENDIAN
  39206. + return *p;
  39207. +#else
  39208. + uint8_t *u_p = (uint8_t *)p;
  39209. +
  39210. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  39211. +#endif
  39212. +}
  39213. +
  39214. +uint32_t DWC_LE32_TO_CPU(uint32_t *p)
  39215. +{
  39216. +#ifdef __LITTLE_ENDIAN
  39217. + return *p;
  39218. +#else
  39219. + uint8_t *u_p = (uint8_t *)p;
  39220. +
  39221. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  39222. +#endif
  39223. +}
  39224. +
  39225. +uint32_t DWC_BE32_TO_CPU(uint32_t *p)
  39226. +{
  39227. +#ifdef __BIG_ENDIAN
  39228. + return *p;
  39229. +#else
  39230. + uint8_t *u_p = (uint8_t *)p;
  39231. +
  39232. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  39233. +#endif
  39234. +}
  39235. +
  39236. +uint16_t DWC_CPU_TO_LE16(uint16_t *p)
  39237. +{
  39238. +#ifdef __LITTLE_ENDIAN
  39239. + return *p;
  39240. +#else
  39241. + uint8_t *u_p = (uint8_t *)p;
  39242. + return (u_p[1] | (u_p[0] << 8));
  39243. +#endif
  39244. +}
  39245. +
  39246. +uint16_t DWC_CPU_TO_BE16(uint16_t *p)
  39247. +{
  39248. +#ifdef __BIG_ENDIAN
  39249. + return *p;
  39250. +#else
  39251. + uint8_t *u_p = (uint8_t *)p;
  39252. + return (u_p[1] | (u_p[0] << 8));
  39253. +#endif
  39254. +}
  39255. +
  39256. +uint16_t DWC_LE16_TO_CPU(uint16_t *p)
  39257. +{
  39258. +#ifdef __LITTLE_ENDIAN
  39259. + return *p;
  39260. +#else
  39261. + uint8_t *u_p = (uint8_t *)p;
  39262. + return (u_p[1] | (u_p[0] << 8));
  39263. +#endif
  39264. +}
  39265. +
  39266. +uint16_t DWC_BE16_TO_CPU(uint16_t *p)
  39267. +{
  39268. +#ifdef __BIG_ENDIAN
  39269. + return *p;
  39270. +#else
  39271. + uint8_t *u_p = (uint8_t *)p;
  39272. + return (u_p[1] | (u_p[0] << 8));
  39273. +#endif
  39274. +}
  39275. +
  39276. +
  39277. +/* Registers */
  39278. +
  39279. +uint32_t DWC_READ_REG32(void *io_ctx, uint32_t volatile *reg)
  39280. +{
  39281. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  39282. + bus_size_t ior = (bus_size_t)reg;
  39283. +
  39284. + return bus_space_read_4(io->iot, io->ioh, ior);
  39285. +}
  39286. +
  39287. +#if 0
  39288. +uint64_t DWC_READ_REG64(void *io_ctx, uint64_t volatile *reg)
  39289. +{
  39290. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  39291. + bus_size_t ior = (bus_size_t)reg;
  39292. +
  39293. + return bus_space_read_8(io->iot, io->ioh, ior);
  39294. +}
  39295. +#endif
  39296. +
  39297. +void DWC_WRITE_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t value)
  39298. +{
  39299. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  39300. + bus_size_t ior = (bus_size_t)reg;
  39301. +
  39302. + bus_space_write_4(io->iot, io->ioh, ior, value);
  39303. +}
  39304. +
  39305. +#if 0
  39306. +void DWC_WRITE_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t value)
  39307. +{
  39308. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  39309. + bus_size_t ior = (bus_size_t)reg;
  39310. +
  39311. + bus_space_write_8(io->iot, io->ioh, ior, value);
  39312. +}
  39313. +#endif
  39314. +
  39315. +void DWC_MODIFY_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t clear_mask,
  39316. + uint32_t set_mask)
  39317. +{
  39318. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  39319. + bus_size_t ior = (bus_size_t)reg;
  39320. +
  39321. + bus_space_write_4(io->iot, io->ioh, ior,
  39322. + (bus_space_read_4(io->iot, io->ioh, ior) &
  39323. + ~clear_mask) | set_mask);
  39324. +}
  39325. +
  39326. +#if 0
  39327. +void DWC_MODIFY_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t clear_mask,
  39328. + uint64_t set_mask)
  39329. +{
  39330. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  39331. + bus_size_t ior = (bus_size_t)reg;
  39332. +
  39333. + bus_space_write_8(io->iot, io->ioh, ior,
  39334. + (bus_space_read_8(io->iot, io->ioh, ior) &
  39335. + ~clear_mask) | set_mask);
  39336. +}
  39337. +#endif
  39338. +
  39339. +
  39340. +/* Locking */
  39341. +
  39342. +dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void)
  39343. +{
  39344. + struct mtx *sl = DWC_ALLOC(sizeof(*sl));
  39345. +
  39346. + if (!sl) {
  39347. + DWC_ERROR("Cannot allocate memory for spinlock");
  39348. + return NULL;
  39349. + }
  39350. +
  39351. + mtx_init(sl, "dw3spn", NULL, MTX_SPIN);
  39352. + return (dwc_spinlock_t *)sl;
  39353. +}
  39354. +
  39355. +void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock)
  39356. +{
  39357. + struct mtx *sl = (struct mtx *)lock;
  39358. +
  39359. + mtx_destroy(sl);
  39360. + DWC_FREE(sl);
  39361. +}
  39362. +
  39363. +void DWC_SPINLOCK(dwc_spinlock_t *lock)
  39364. +{
  39365. + mtx_lock_spin((struct mtx *)lock); // ???
  39366. +}
  39367. +
  39368. +void DWC_SPINUNLOCK(dwc_spinlock_t *lock)
  39369. +{
  39370. + mtx_unlock_spin((struct mtx *)lock); // ???
  39371. +}
  39372. +
  39373. +void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags)
  39374. +{
  39375. + mtx_lock_spin((struct mtx *)lock);
  39376. +}
  39377. +
  39378. +void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags)
  39379. +{
  39380. + mtx_unlock_spin((struct mtx *)lock);
  39381. +}
  39382. +
  39383. +dwc_mutex_t *DWC_MUTEX_ALLOC(void)
  39384. +{
  39385. + struct mtx *m;
  39386. + dwc_mutex_t *mutex = (dwc_mutex_t *)DWC_ALLOC(sizeof(struct mtx));
  39387. +
  39388. + if (!mutex) {
  39389. + DWC_ERROR("Cannot allocate memory for mutex");
  39390. + return NULL;
  39391. + }
  39392. +
  39393. + m = (struct mtx *)mutex;
  39394. + mtx_init(m, "dw3mtx", NULL, MTX_DEF);
  39395. + return mutex;
  39396. +}
  39397. +
  39398. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  39399. +#else
  39400. +void DWC_MUTEX_FREE(dwc_mutex_t *mutex)
  39401. +{
  39402. + mtx_destroy((struct mtx *)mutex);
  39403. + DWC_FREE(mutex);
  39404. +}
  39405. +#endif
  39406. +
  39407. +void DWC_MUTEX_LOCK(dwc_mutex_t *mutex)
  39408. +{
  39409. + struct mtx *m = (struct mtx *)mutex;
  39410. +
  39411. + mtx_lock(m);
  39412. +}
  39413. +
  39414. +int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex)
  39415. +{
  39416. + struct mtx *m = (struct mtx *)mutex;
  39417. +
  39418. + return mtx_trylock(m);
  39419. +}
  39420. +
  39421. +void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex)
  39422. +{
  39423. + struct mtx *m = (struct mtx *)mutex;
  39424. +
  39425. + mtx_unlock(m);
  39426. +}
  39427. +
  39428. +
  39429. +/* Timing */
  39430. +
  39431. +void DWC_UDELAY(uint32_t usecs)
  39432. +{
  39433. + DELAY(usecs);
  39434. +}
  39435. +
  39436. +void DWC_MDELAY(uint32_t msecs)
  39437. +{
  39438. + do {
  39439. + DELAY(1000);
  39440. + } while (--msecs);
  39441. +}
  39442. +
  39443. +void DWC_MSLEEP(uint32_t msecs)
  39444. +{
  39445. + struct timeval tv;
  39446. +
  39447. + tv.tv_sec = msecs / 1000;
  39448. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  39449. + pause("dw3slp", tvtohz(&tv));
  39450. +}
  39451. +
  39452. +uint32_t DWC_TIME(void)
  39453. +{
  39454. + struct timeval tv;
  39455. +
  39456. + microuptime(&tv); // or getmicrouptime? (less precise, but faster)
  39457. + return tv.tv_sec * 1000 + tv.tv_usec / 1000;
  39458. +}
  39459. +
  39460. +
  39461. +/* Timers */
  39462. +
  39463. +struct dwc_timer {
  39464. + struct callout t;
  39465. + char *name;
  39466. + dwc_spinlock_t *lock;
  39467. + dwc_timer_callback_t cb;
  39468. + void *data;
  39469. +};
  39470. +
  39471. +dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data)
  39472. +{
  39473. + dwc_timer_t *t = DWC_ALLOC(sizeof(*t));
  39474. +
  39475. + if (!t) {
  39476. + DWC_ERROR("Cannot allocate memory for timer");
  39477. + return NULL;
  39478. + }
  39479. +
  39480. + callout_init(&t->t, 1);
  39481. +
  39482. + t->name = DWC_STRDUP(name);
  39483. + if (!t->name) {
  39484. + DWC_ERROR("Cannot allocate memory for timer->name");
  39485. + goto no_name;
  39486. + }
  39487. +
  39488. + t->lock = DWC_SPINLOCK_ALLOC();
  39489. + if (!t->lock) {
  39490. + DWC_ERROR("Cannot allocate memory for lock");
  39491. + goto no_lock;
  39492. + }
  39493. +
  39494. + t->cb = cb;
  39495. + t->data = data;
  39496. +
  39497. + return t;
  39498. +
  39499. + no_lock:
  39500. + DWC_FREE(t->name);
  39501. + no_name:
  39502. + DWC_FREE(t);
  39503. +
  39504. + return NULL;
  39505. +}
  39506. +
  39507. +void DWC_TIMER_FREE(dwc_timer_t *timer)
  39508. +{
  39509. + callout_stop(&timer->t);
  39510. + DWC_SPINLOCK_FREE(timer->lock);
  39511. + DWC_FREE(timer->name);
  39512. + DWC_FREE(timer);
  39513. +}
  39514. +
  39515. +void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time)
  39516. +{
  39517. + struct timeval tv;
  39518. +
  39519. + tv.tv_sec = time / 1000;
  39520. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  39521. + callout_reset(&timer->t, tvtohz(&tv), timer->cb, timer->data);
  39522. +}
  39523. +
  39524. +void DWC_TIMER_CANCEL(dwc_timer_t *timer)
  39525. +{
  39526. + callout_stop(&timer->t);
  39527. +}
  39528. +
  39529. +
  39530. +/* Wait Queues */
  39531. +
  39532. +struct dwc_waitq {
  39533. + struct mtx lock;
  39534. + int abort;
  39535. +};
  39536. +
  39537. +dwc_waitq_t *DWC_WAITQ_ALLOC(void)
  39538. +{
  39539. + dwc_waitq_t *wq = DWC_ALLOC(sizeof(*wq));
  39540. +
  39541. + if (!wq) {
  39542. + DWC_ERROR("Cannot allocate memory for waitqueue");
  39543. + return NULL;
  39544. + }
  39545. +
  39546. + mtx_init(&wq->lock, "dw3wtq", NULL, MTX_DEF);
  39547. + wq->abort = 0;
  39548. +
  39549. + return wq;
  39550. +}
  39551. +
  39552. +void DWC_WAITQ_FREE(dwc_waitq_t *wq)
  39553. +{
  39554. + mtx_destroy(&wq->lock);
  39555. + DWC_FREE(wq);
  39556. +}
  39557. +
  39558. +int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data)
  39559. +{
  39560. +// intrmask_t ipl;
  39561. + int result = 0;
  39562. +
  39563. + mtx_lock(&wq->lock);
  39564. +// ipl = splbio();
  39565. +
  39566. + /* Skip the sleep if already aborted or triggered */
  39567. + if (!wq->abort && !cond(data)) {
  39568. +// splx(ipl);
  39569. + result = msleep(wq, &wq->lock, PCATCH, "dw3wat", 0); // infinite timeout
  39570. +// ipl = splbio();
  39571. + }
  39572. +
  39573. + if (result == ERESTART) { // signaled - restart
  39574. + result = -DWC_E_RESTART;
  39575. +
  39576. + } else if (result == EINTR) { // signaled - interrupt
  39577. + result = -DWC_E_ABORT;
  39578. +
  39579. + } else if (wq->abort) {
  39580. + result = -DWC_E_ABORT;
  39581. +
  39582. + } else {
  39583. + result = 0;
  39584. + }
  39585. +
  39586. + wq->abort = 0;
  39587. +// splx(ipl);
  39588. + mtx_unlock(&wq->lock);
  39589. + return result;
  39590. +}
  39591. +
  39592. +int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  39593. + void *data, int32_t msecs)
  39594. +{
  39595. + struct timeval tv, tv1, tv2;
  39596. +// intrmask_t ipl;
  39597. + int result = 0;
  39598. +
  39599. + tv.tv_sec = msecs / 1000;
  39600. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  39601. +
  39602. + mtx_lock(&wq->lock);
  39603. +// ipl = splbio();
  39604. +
  39605. + /* Skip the sleep if already aborted or triggered */
  39606. + if (!wq->abort && !cond(data)) {
  39607. +// splx(ipl);
  39608. + getmicrouptime(&tv1);
  39609. + result = msleep(wq, &wq->lock, PCATCH, "dw3wto", tvtohz(&tv));
  39610. + getmicrouptime(&tv2);
  39611. +// ipl = splbio();
  39612. + }
  39613. +
  39614. + if (result == 0) { // awoken
  39615. + if (wq->abort) {
  39616. + result = -DWC_E_ABORT;
  39617. + } else {
  39618. + tv2.tv_usec -= tv1.tv_usec;
  39619. + if (tv2.tv_usec < 0) {
  39620. + tv2.tv_usec += 1000000;
  39621. + tv2.tv_sec--;
  39622. + }
  39623. +
  39624. + tv2.tv_sec -= tv1.tv_sec;
  39625. + result = tv2.tv_sec * 1000 + tv2.tv_usec / 1000;
  39626. + result = msecs - result;
  39627. + if (result <= 0)
  39628. + result = 1;
  39629. + }
  39630. + } else if (result == ERESTART) { // signaled - restart
  39631. + result = -DWC_E_RESTART;
  39632. +
  39633. + } else if (result == EINTR) { // signaled - interrupt
  39634. + result = -DWC_E_ABORT;
  39635. +
  39636. + } else { // timed out
  39637. + result = -DWC_E_TIMEOUT;
  39638. + }
  39639. +
  39640. + wq->abort = 0;
  39641. +// splx(ipl);
  39642. + mtx_unlock(&wq->lock);
  39643. + return result;
  39644. +}
  39645. +
  39646. +void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq)
  39647. +{
  39648. + wakeup(wq);
  39649. +}
  39650. +
  39651. +void DWC_WAITQ_ABORT(dwc_waitq_t *wq)
  39652. +{
  39653. +// intrmask_t ipl;
  39654. +
  39655. + mtx_lock(&wq->lock);
  39656. +// ipl = splbio();
  39657. + wq->abort = 1;
  39658. + wakeup(wq);
  39659. +// splx(ipl);
  39660. + mtx_unlock(&wq->lock);
  39661. +}
  39662. +
  39663. +
  39664. +/* Threading */
  39665. +
  39666. +struct dwc_thread {
  39667. + struct proc *proc;
  39668. + int abort;
  39669. +};
  39670. +
  39671. +dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data)
  39672. +{
  39673. + int retval;
  39674. + dwc_thread_t *thread = DWC_ALLOC(sizeof(*thread));
  39675. +
  39676. + if (!thread) {
  39677. + return NULL;
  39678. + }
  39679. +
  39680. + thread->abort = 0;
  39681. + retval = kthread_create((void (*)(void *))func, data, &thread->proc,
  39682. + RFPROC | RFNOWAIT, 0, "%s", name);
  39683. + if (retval) {
  39684. + DWC_FREE(thread);
  39685. + return NULL;
  39686. + }
  39687. +
  39688. + return thread;
  39689. +}
  39690. +
  39691. +int DWC_THREAD_STOP(dwc_thread_t *thread)
  39692. +{
  39693. + int retval;
  39694. +
  39695. + thread->abort = 1;
  39696. + retval = tsleep(&thread->abort, 0, "dw3stp", 60 * hz);
  39697. +
  39698. + if (retval == 0) {
  39699. + /* DWC_THREAD_EXIT() will free the thread struct */
  39700. + return 0;
  39701. + }
  39702. +
  39703. + /* NOTE: We leak the thread struct if thread doesn't die */
  39704. +
  39705. + if (retval == EWOULDBLOCK) {
  39706. + return -DWC_E_TIMEOUT;
  39707. + }
  39708. +
  39709. + return -DWC_E_UNKNOWN;
  39710. +}
  39711. +
  39712. +dwc_bool_t DWC_THREAD_SHOULD_STOP(dwc_thread_t *thread)
  39713. +{
  39714. + return thread->abort;
  39715. +}
  39716. +
  39717. +void DWC_THREAD_EXIT(dwc_thread_t *thread)
  39718. +{
  39719. + wakeup(&thread->abort);
  39720. + DWC_FREE(thread);
  39721. + kthread_exit(0);
  39722. +}
  39723. +
  39724. +
  39725. +/* tasklets
  39726. + - Runs in interrupt context (cannot sleep)
  39727. + - Each tasklet runs on a single CPU [ How can we ensure this on FreeBSD? Does it matter? ]
  39728. + - Different tasklets can be running simultaneously on different CPUs [ shouldn't matter ]
  39729. + */
  39730. +struct dwc_tasklet {
  39731. + struct task t;
  39732. + dwc_tasklet_callback_t cb;
  39733. + void *data;
  39734. +};
  39735. +
  39736. +static void tasklet_callback(void *data, int pending) // what to do with pending ???
  39737. +{
  39738. + dwc_tasklet_t *task = (dwc_tasklet_t *)data;
  39739. +
  39740. + task->cb(task->data);
  39741. +}
  39742. +
  39743. +dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data)
  39744. +{
  39745. + dwc_tasklet_t *task = DWC_ALLOC(sizeof(*task));
  39746. +
  39747. + if (task) {
  39748. + task->cb = cb;
  39749. + task->data = data;
  39750. + TASK_INIT(&task->t, 0, tasklet_callback, task);
  39751. + } else {
  39752. + DWC_ERROR("Cannot allocate memory for tasklet");
  39753. + }
  39754. +
  39755. + return task;
  39756. +}
  39757. +
  39758. +void DWC_TASK_FREE(dwc_tasklet_t *task)
  39759. +{
  39760. + taskqueue_drain(taskqueue_fast, &task->t); // ???
  39761. + DWC_FREE(task);
  39762. +}
  39763. +
  39764. +void DWC_TASK_SCHEDULE(dwc_tasklet_t *task)
  39765. +{
  39766. + /* Uses predefined system queue */
  39767. + taskqueue_enqueue_fast(taskqueue_fast, &task->t);
  39768. +}
  39769. +
  39770. +
  39771. +/* workqueues
  39772. + - Runs in process context (can sleep)
  39773. + */
  39774. +typedef struct work_container {
  39775. + dwc_work_callback_t cb;
  39776. + void *data;
  39777. + dwc_workq_t *wq;
  39778. + char *name;
  39779. + int hz;
  39780. +
  39781. +#ifdef DEBUG
  39782. + DWC_CIRCLEQ_ENTRY(work_container) entry;
  39783. +#endif
  39784. + struct task task;
  39785. +} work_container_t;
  39786. +
  39787. +#ifdef DEBUG
  39788. +DWC_CIRCLEQ_HEAD(work_container_queue, work_container);
  39789. +#endif
  39790. +
  39791. +struct dwc_workq {
  39792. + struct taskqueue *taskq;
  39793. + dwc_spinlock_t *lock;
  39794. + dwc_waitq_t *waitq;
  39795. + int pending;
  39796. +
  39797. +#ifdef DEBUG
  39798. + struct work_container_queue entries;
  39799. +#endif
  39800. +};
  39801. +
  39802. +static void do_work(void *data, int pending) // what to do with pending ???
  39803. +{
  39804. + work_container_t *container = (work_container_t *)data;
  39805. + dwc_workq_t *wq = container->wq;
  39806. + dwc_irqflags_t flags;
  39807. +
  39808. + if (container->hz) {
  39809. + pause("dw3wrk", container->hz);
  39810. + }
  39811. +
  39812. + container->cb(container->data);
  39813. + DWC_DEBUG("Work done: %s, container=%p", container->name, container);
  39814. +
  39815. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  39816. +
  39817. +#ifdef DEBUG
  39818. + DWC_CIRCLEQ_REMOVE(&wq->entries, container, entry);
  39819. +#endif
  39820. + if (container->name)
  39821. + DWC_FREE(container->name);
  39822. + DWC_FREE(container);
  39823. + wq->pending--;
  39824. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  39825. + DWC_WAITQ_TRIGGER(wq->waitq);
  39826. +}
  39827. +
  39828. +static int work_done(void *data)
  39829. +{
  39830. + dwc_workq_t *workq = (dwc_workq_t *)data;
  39831. +
  39832. + return workq->pending == 0;
  39833. +}
  39834. +
  39835. +int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout)
  39836. +{
  39837. + return DWC_WAITQ_WAIT_TIMEOUT(workq->waitq, work_done, workq, timeout);
  39838. +}
  39839. +
  39840. +dwc_workq_t *DWC_WORKQ_ALLOC(char *name)
  39841. +{
  39842. + dwc_workq_t *wq = DWC_ALLOC(sizeof(*wq));
  39843. +
  39844. + if (!wq) {
  39845. + DWC_ERROR("Cannot allocate memory for workqueue");
  39846. + return NULL;
  39847. + }
  39848. +
  39849. + wq->taskq = taskqueue_create(name, M_NOWAIT, taskqueue_thread_enqueue, &wq->taskq);
  39850. + if (!wq->taskq) {
  39851. + DWC_ERROR("Cannot allocate memory for taskqueue");
  39852. + goto no_taskq;
  39853. + }
  39854. +
  39855. + wq->pending = 0;
  39856. +
  39857. + wq->lock = DWC_SPINLOCK_ALLOC();
  39858. + if (!wq->lock) {
  39859. + DWC_ERROR("Cannot allocate memory for spinlock");
  39860. + goto no_lock;
  39861. + }
  39862. +
  39863. + wq->waitq = DWC_WAITQ_ALLOC();
  39864. + if (!wq->waitq) {
  39865. + DWC_ERROR("Cannot allocate memory for waitqueue");
  39866. + goto no_waitq;
  39867. + }
  39868. +
  39869. + taskqueue_start_threads(&wq->taskq, 1, PWAIT, "%s taskq", "dw3tsk");
  39870. +
  39871. +#ifdef DEBUG
  39872. + DWC_CIRCLEQ_INIT(&wq->entries);
  39873. +#endif
  39874. + return wq;
  39875. +
  39876. + no_waitq:
  39877. + DWC_SPINLOCK_FREE(wq->lock);
  39878. + no_lock:
  39879. + taskqueue_free(wq->taskq);
  39880. + no_taskq:
  39881. + DWC_FREE(wq);
  39882. +
  39883. + return NULL;
  39884. +}
  39885. +
  39886. +void DWC_WORKQ_FREE(dwc_workq_t *wq)
  39887. +{
  39888. +#ifdef DEBUG
  39889. + dwc_irqflags_t flags;
  39890. +
  39891. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  39892. +
  39893. + if (wq->pending != 0) {
  39894. + struct work_container *container;
  39895. +
  39896. + DWC_ERROR("Destroying work queue with pending work");
  39897. +
  39898. + DWC_CIRCLEQ_FOREACH(container, &wq->entries, entry) {
  39899. + DWC_ERROR("Work %s still pending", container->name);
  39900. + }
  39901. + }
  39902. +
  39903. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  39904. +#endif
  39905. + DWC_WAITQ_FREE(wq->waitq);
  39906. + DWC_SPINLOCK_FREE(wq->lock);
  39907. + taskqueue_free(wq->taskq);
  39908. + DWC_FREE(wq);
  39909. +}
  39910. +
  39911. +void DWC_WORKQ_SCHEDULE(dwc_workq_t *wq, dwc_work_callback_t cb, void *data,
  39912. + char *format, ...)
  39913. +{
  39914. + dwc_irqflags_t flags;
  39915. + work_container_t *container;
  39916. + static char name[128];
  39917. + va_list args;
  39918. +
  39919. + va_start(args, format);
  39920. + DWC_VSNPRINTF(name, 128, format, args);
  39921. + va_end(args);
  39922. +
  39923. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  39924. + wq->pending++;
  39925. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  39926. + DWC_WAITQ_TRIGGER(wq->waitq);
  39927. +
  39928. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  39929. + if (!container) {
  39930. + DWC_ERROR("Cannot allocate memory for container");
  39931. + return;
  39932. + }
  39933. +
  39934. + container->name = DWC_STRDUP(name);
  39935. + if (!container->name) {
  39936. + DWC_ERROR("Cannot allocate memory for container->name");
  39937. + DWC_FREE(container);
  39938. + return;
  39939. + }
  39940. +
  39941. + container->cb = cb;
  39942. + container->data = data;
  39943. + container->wq = wq;
  39944. + container->hz = 0;
  39945. +
  39946. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  39947. +
  39948. + TASK_INIT(&container->task, 0, do_work, container);
  39949. +
  39950. +#ifdef DEBUG
  39951. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  39952. +#endif
  39953. + taskqueue_enqueue_fast(wq->taskq, &container->task);
  39954. +}
  39955. +
  39956. +void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *wq, dwc_work_callback_t cb,
  39957. + void *data, uint32_t time, char *format, ...)
  39958. +{
  39959. + dwc_irqflags_t flags;
  39960. + work_container_t *container;
  39961. + static char name[128];
  39962. + struct timeval tv;
  39963. + va_list args;
  39964. +
  39965. + va_start(args, format);
  39966. + DWC_VSNPRINTF(name, 128, format, args);
  39967. + va_end(args);
  39968. +
  39969. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  39970. + wq->pending++;
  39971. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  39972. + DWC_WAITQ_TRIGGER(wq->waitq);
  39973. +
  39974. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  39975. + if (!container) {
  39976. + DWC_ERROR("Cannot allocate memory for container");
  39977. + return;
  39978. + }
  39979. +
  39980. + container->name = DWC_STRDUP(name);
  39981. + if (!container->name) {
  39982. + DWC_ERROR("Cannot allocate memory for container->name");
  39983. + DWC_FREE(container);
  39984. + return;
  39985. + }
  39986. +
  39987. + container->cb = cb;
  39988. + container->data = data;
  39989. + container->wq = wq;
  39990. +
  39991. + tv.tv_sec = time / 1000;
  39992. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  39993. + container->hz = tvtohz(&tv);
  39994. +
  39995. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  39996. +
  39997. + TASK_INIT(&container->task, 0, do_work, container);
  39998. +
  39999. +#ifdef DEBUG
  40000. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  40001. +#endif
  40002. + taskqueue_enqueue_fast(wq->taskq, &container->task);
  40003. +}
  40004. +
  40005. +int DWC_WORKQ_PENDING(dwc_workq_t *wq)
  40006. +{
  40007. + return wq->pending;
  40008. +}
  40009. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_common_port/dwc_common_linux.c linux-3.13.3/drivers/usb/host/dwc_common_port/dwc_common_linux.c
  40010. --- linux-3.13.3.orig/drivers/usb/host/dwc_common_port/dwc_common_linux.c 1970-01-01 01:00:00.000000000 +0100
  40011. +++ linux-3.13.3/drivers/usb/host/dwc_common_port/dwc_common_linux.c 2014-02-17 22:41:01.000000000 +0100
  40012. @@ -0,0 +1,1431 @@
  40013. +#include <linux/kernel.h>
  40014. +#include <linux/init.h>
  40015. +#include <linux/module.h>
  40016. +#include <linux/kthread.h>
  40017. +
  40018. +#ifdef DWC_CCLIB
  40019. +# include "dwc_cc.h"
  40020. +#endif
  40021. +
  40022. +#ifdef DWC_CRYPTOLIB
  40023. +# include "dwc_modpow.h"
  40024. +# include "dwc_dh.h"
  40025. +# include "dwc_crypto.h"
  40026. +#endif
  40027. +
  40028. +#ifdef DWC_NOTIFYLIB
  40029. +# include "dwc_notifier.h"
  40030. +#endif
  40031. +
  40032. +/* OS-Level Implementations */
  40033. +
  40034. +/* This is the Linux kernel implementation of the DWC platform library. */
  40035. +#include <linux/moduleparam.h>
  40036. +#include <linux/ctype.h>
  40037. +#include <linux/crypto.h>
  40038. +#include <linux/delay.h>
  40039. +#include <linux/device.h>
  40040. +#include <linux/dma-mapping.h>
  40041. +#include <linux/cdev.h>
  40042. +#include <linux/errno.h>
  40043. +#include <linux/interrupt.h>
  40044. +#include <linux/jiffies.h>
  40045. +#include <linux/list.h>
  40046. +#include <linux/pci.h>
  40047. +#include <linux/random.h>
  40048. +#include <linux/scatterlist.h>
  40049. +#include <linux/slab.h>
  40050. +#include <linux/stat.h>
  40051. +#include <linux/string.h>
  40052. +#include <linux/timer.h>
  40053. +#include <linux/usb.h>
  40054. +
  40055. +#include <linux/version.h>
  40056. +
  40057. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
  40058. +# include <linux/usb/gadget.h>
  40059. +#else
  40060. +# include <linux/usb_gadget.h>
  40061. +#endif
  40062. +
  40063. +#include <asm/io.h>
  40064. +#include <asm/page.h>
  40065. +#include <asm/uaccess.h>
  40066. +#include <asm/unaligned.h>
  40067. +
  40068. +#include "dwc_os.h"
  40069. +#include "dwc_list.h"
  40070. +
  40071. +
  40072. +/* MISC */
  40073. +
  40074. +void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size)
  40075. +{
  40076. + return memset(dest, byte, size);
  40077. +}
  40078. +
  40079. +void *DWC_MEMCPY(void *dest, void const *src, uint32_t size)
  40080. +{
  40081. + return memcpy(dest, src, size);
  40082. +}
  40083. +
  40084. +void *DWC_MEMMOVE(void *dest, void *src, uint32_t size)
  40085. +{
  40086. + return memmove(dest, src, size);
  40087. +}
  40088. +
  40089. +int DWC_MEMCMP(void *m1, void *m2, uint32_t size)
  40090. +{
  40091. + return memcmp(m1, m2, size);
  40092. +}
  40093. +
  40094. +int DWC_STRNCMP(void *s1, void *s2, uint32_t size)
  40095. +{
  40096. + return strncmp(s1, s2, size);
  40097. +}
  40098. +
  40099. +int DWC_STRCMP(void *s1, void *s2)
  40100. +{
  40101. + return strcmp(s1, s2);
  40102. +}
  40103. +
  40104. +int DWC_STRLEN(char const *str)
  40105. +{
  40106. + return strlen(str);
  40107. +}
  40108. +
  40109. +char *DWC_STRCPY(char *to, char const *from)
  40110. +{
  40111. + return strcpy(to, from);
  40112. +}
  40113. +
  40114. +char *DWC_STRDUP(char const *str)
  40115. +{
  40116. + int len = DWC_STRLEN(str) + 1;
  40117. + char *new = DWC_ALLOC_ATOMIC(len);
  40118. +
  40119. + if (!new) {
  40120. + return NULL;
  40121. + }
  40122. +
  40123. + DWC_MEMCPY(new, str, len);
  40124. + return new;
  40125. +}
  40126. +
  40127. +int DWC_ATOI(const char *str, int32_t *value)
  40128. +{
  40129. + char *end = NULL;
  40130. +
  40131. + *value = simple_strtol(str, &end, 0);
  40132. + if (*end == '\0') {
  40133. + return 0;
  40134. + }
  40135. +
  40136. + return -1;
  40137. +}
  40138. +
  40139. +int DWC_ATOUI(const char *str, uint32_t *value)
  40140. +{
  40141. + char *end = NULL;
  40142. +
  40143. + *value = simple_strtoul(str, &end, 0);
  40144. + if (*end == '\0') {
  40145. + return 0;
  40146. + }
  40147. +
  40148. + return -1;
  40149. +}
  40150. +
  40151. +
  40152. +#ifdef DWC_UTFLIB
  40153. +/* From usbstring.c */
  40154. +
  40155. +int DWC_UTF8_TO_UTF16LE(uint8_t const *s, uint16_t *cp, unsigned len)
  40156. +{
  40157. + int count = 0;
  40158. + u8 c;
  40159. + u16 uchar;
  40160. +
  40161. + /* this insists on correct encodings, though not minimal ones.
  40162. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  40163. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  40164. + */
  40165. + while (len != 0 && (c = (u8) *s++) != 0) {
  40166. + if (unlikely(c & 0x80)) {
  40167. + // 2-byte sequence:
  40168. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  40169. + if ((c & 0xe0) == 0xc0) {
  40170. + uchar = (c & 0x1f) << 6;
  40171. +
  40172. + c = (u8) *s++;
  40173. + if ((c & 0xc0) != 0xc0)
  40174. + goto fail;
  40175. + c &= 0x3f;
  40176. + uchar |= c;
  40177. +
  40178. + // 3-byte sequence (most CJKV characters):
  40179. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  40180. + } else if ((c & 0xf0) == 0xe0) {
  40181. + uchar = (c & 0x0f) << 12;
  40182. +
  40183. + c = (u8) *s++;
  40184. + if ((c & 0xc0) != 0xc0)
  40185. + goto fail;
  40186. + c &= 0x3f;
  40187. + uchar |= c << 6;
  40188. +
  40189. + c = (u8) *s++;
  40190. + if ((c & 0xc0) != 0xc0)
  40191. + goto fail;
  40192. + c &= 0x3f;
  40193. + uchar |= c;
  40194. +
  40195. + /* no bogus surrogates */
  40196. + if (0xd800 <= uchar && uchar <= 0xdfff)
  40197. + goto fail;
  40198. +
  40199. + // 4-byte sequence (surrogate pairs, currently rare):
  40200. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  40201. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  40202. + // (uuuuu = wwww + 1)
  40203. + // FIXME accept the surrogate code points (only)
  40204. + } else
  40205. + goto fail;
  40206. + } else
  40207. + uchar = c;
  40208. + put_unaligned (cpu_to_le16 (uchar), cp++);
  40209. + count++;
  40210. + len--;
  40211. + }
  40212. + return count;
  40213. +fail:
  40214. + return -1;
  40215. +}
  40216. +#endif /* DWC_UTFLIB */
  40217. +
  40218. +
  40219. +/* dwc_debug.h */
  40220. +
  40221. +dwc_bool_t DWC_IN_IRQ(void)
  40222. +{
  40223. + return in_irq();
  40224. +}
  40225. +
  40226. +dwc_bool_t DWC_IN_BH(void)
  40227. +{
  40228. + return in_softirq();
  40229. +}
  40230. +
  40231. +void DWC_VPRINTF(char *format, va_list args)
  40232. +{
  40233. + vprintk(format, args);
  40234. +}
  40235. +
  40236. +int DWC_VSNPRINTF(char *str, int size, char *format, va_list args)
  40237. +{
  40238. + return vsnprintf(str, size, format, args);
  40239. +}
  40240. +
  40241. +void DWC_PRINTF(char *format, ...)
  40242. +{
  40243. + va_list args;
  40244. +
  40245. + va_start(args, format);
  40246. + DWC_VPRINTF(format, args);
  40247. + va_end(args);
  40248. +}
  40249. +
  40250. +int DWC_SPRINTF(char *buffer, char *format, ...)
  40251. +{
  40252. + int retval;
  40253. + va_list args;
  40254. +
  40255. + va_start(args, format);
  40256. + retval = vsprintf(buffer, format, args);
  40257. + va_end(args);
  40258. + return retval;
  40259. +}
  40260. +
  40261. +int DWC_SNPRINTF(char *buffer, int size, char *format, ...)
  40262. +{
  40263. + int retval;
  40264. + va_list args;
  40265. +
  40266. + va_start(args, format);
  40267. + retval = vsnprintf(buffer, size, format, args);
  40268. + va_end(args);
  40269. + return retval;
  40270. +}
  40271. +
  40272. +void __DWC_WARN(char *format, ...)
  40273. +{
  40274. + va_list args;
  40275. +
  40276. + va_start(args, format);
  40277. + DWC_PRINTF(KERN_WARNING);
  40278. + DWC_VPRINTF(format, args);
  40279. + va_end(args);
  40280. +}
  40281. +
  40282. +void __DWC_ERROR(char *format, ...)
  40283. +{
  40284. + va_list args;
  40285. +
  40286. + va_start(args, format);
  40287. + DWC_PRINTF(KERN_ERR);
  40288. + DWC_VPRINTF(format, args);
  40289. + va_end(args);
  40290. +}
  40291. +
  40292. +void DWC_EXCEPTION(char *format, ...)
  40293. +{
  40294. + va_list args;
  40295. +
  40296. + va_start(args, format);
  40297. + DWC_PRINTF(KERN_ERR);
  40298. + DWC_VPRINTF(format, args);
  40299. + va_end(args);
  40300. + BUG_ON(1);
  40301. +}
  40302. +
  40303. +#ifdef DEBUG
  40304. +void __DWC_DEBUG(char *format, ...)
  40305. +{
  40306. + va_list args;
  40307. +
  40308. + va_start(args, format);
  40309. + DWC_PRINTF(KERN_DEBUG);
  40310. + DWC_VPRINTF(format, args);
  40311. + va_end(args);
  40312. +}
  40313. +#endif
  40314. +
  40315. +
  40316. +/* dwc_mem.h */
  40317. +
  40318. +#if 0
  40319. +dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size,
  40320. + uint32_t align,
  40321. + uint32_t alloc)
  40322. +{
  40323. + struct dma_pool *pool = dma_pool_create("Pool", NULL,
  40324. + size, align, alloc);
  40325. + return (dwc_pool_t *)pool;
  40326. +}
  40327. +
  40328. +void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool)
  40329. +{
  40330. + dma_pool_destroy((struct dma_pool *)pool);
  40331. +}
  40332. +
  40333. +void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  40334. +{
  40335. + return dma_pool_alloc((struct dma_pool *)pool, GFP_KERNEL, dma_addr);
  40336. +}
  40337. +
  40338. +void *DWC_DMA_POOL_ZALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  40339. +{
  40340. + void *vaddr = DWC_DMA_POOL_ALLOC(pool, dma_addr);
  40341. + memset(..);
  40342. +}
  40343. +
  40344. +void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr)
  40345. +{
  40346. + dma_pool_free(pool, vaddr, daddr);
  40347. +}
  40348. +#endif
  40349. +
  40350. +void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  40351. +{
  40352. +#ifdef xxCOSIM /* Only works for 32-bit cosim */
  40353. + void *buf = dma_alloc_coherent(dma_ctx, (size_t)size, dma_addr, GFP_KERNEL);
  40354. +#else
  40355. + void *buf = dma_alloc_coherent(dma_ctx, (size_t)size, dma_addr, GFP_KERNEL | GFP_DMA32);
  40356. +#endif
  40357. + if (!buf) {
  40358. + return NULL;
  40359. + }
  40360. +
  40361. + memset(buf, 0, (size_t)size);
  40362. + return buf;
  40363. +}
  40364. +
  40365. +void *__DWC_DMA_ALLOC_ATOMIC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  40366. +{
  40367. + void *buf = dma_alloc_coherent(NULL, (size_t)size, dma_addr, GFP_ATOMIC);
  40368. + if (!buf) {
  40369. + return NULL;
  40370. + }
  40371. + memset(buf, 0, (size_t)size);
  40372. + return buf;
  40373. +}
  40374. +
  40375. +void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr)
  40376. +{
  40377. + dma_free_coherent(dma_ctx, size, virt_addr, dma_addr);
  40378. +}
  40379. +
  40380. +void *__DWC_ALLOC(void *mem_ctx, uint32_t size)
  40381. +{
  40382. + return kzalloc(size, GFP_KERNEL);
  40383. +}
  40384. +
  40385. +void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size)
  40386. +{
  40387. + return kzalloc(size, GFP_ATOMIC);
  40388. +}
  40389. +
  40390. +void __DWC_FREE(void *mem_ctx, void *addr)
  40391. +{
  40392. + kfree(addr);
  40393. +}
  40394. +
  40395. +
  40396. +#ifdef DWC_CRYPTOLIB
  40397. +/* dwc_crypto.h */
  40398. +
  40399. +void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length)
  40400. +{
  40401. + get_random_bytes(buffer, length);
  40402. +}
  40403. +
  40404. +int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out)
  40405. +{
  40406. + struct crypto_blkcipher *tfm;
  40407. + struct blkcipher_desc desc;
  40408. + struct scatterlist sgd;
  40409. + struct scatterlist sgs;
  40410. +
  40411. + tfm = crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC);
  40412. + if (tfm == NULL) {
  40413. + printk("failed to load transform for aes CBC\n");
  40414. + return -1;
  40415. + }
  40416. +
  40417. + crypto_blkcipher_setkey(tfm, key, keylen);
  40418. + crypto_blkcipher_set_iv(tfm, iv, 16);
  40419. +
  40420. + sg_init_one(&sgd, out, messagelen);
  40421. + sg_init_one(&sgs, message, messagelen);
  40422. +
  40423. + desc.tfm = tfm;
  40424. + desc.flags = 0;
  40425. +
  40426. + if (crypto_blkcipher_encrypt(&desc, &sgd, &sgs, messagelen)) {
  40427. + crypto_free_blkcipher(tfm);
  40428. + DWC_ERROR("AES CBC encryption failed");
  40429. + return -1;
  40430. + }
  40431. +
  40432. + crypto_free_blkcipher(tfm);
  40433. + return 0;
  40434. +}
  40435. +
  40436. +int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out)
  40437. +{
  40438. + struct crypto_hash *tfm;
  40439. + struct hash_desc desc;
  40440. + struct scatterlist sg;
  40441. +
  40442. + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
  40443. + if (IS_ERR(tfm)) {
  40444. + DWC_ERROR("Failed to load transform for sha256: %ld\n", PTR_ERR(tfm));
  40445. + return 0;
  40446. + }
  40447. + desc.tfm = tfm;
  40448. + desc.flags = 0;
  40449. +
  40450. + sg_init_one(&sg, message, len);
  40451. + crypto_hash_digest(&desc, &sg, len, out);
  40452. + crypto_free_hash(tfm);
  40453. +
  40454. + return 1;
  40455. +}
  40456. +
  40457. +int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen,
  40458. + uint8_t *key, uint32_t keylen, uint8_t *out)
  40459. +{
  40460. + struct crypto_hash *tfm;
  40461. + struct hash_desc desc;
  40462. + struct scatterlist sg;
  40463. +
  40464. + tfm = crypto_alloc_hash("hmac(sha256)", 0, CRYPTO_ALG_ASYNC);
  40465. + if (IS_ERR(tfm)) {
  40466. + DWC_ERROR("Failed to load transform for hmac(sha256): %ld\n", PTR_ERR(tfm));
  40467. + return 0;
  40468. + }
  40469. + desc.tfm = tfm;
  40470. + desc.flags = 0;
  40471. +
  40472. + sg_init_one(&sg, message, messagelen);
  40473. + crypto_hash_setkey(tfm, key, keylen);
  40474. + crypto_hash_digest(&desc, &sg, messagelen, out);
  40475. + crypto_free_hash(tfm);
  40476. +
  40477. + return 1;
  40478. +}
  40479. +#endif /* DWC_CRYPTOLIB */
  40480. +
  40481. +
  40482. +/* Byte Ordering Conversions */
  40483. +
  40484. +uint32_t DWC_CPU_TO_LE32(uint32_t *p)
  40485. +{
  40486. +#ifdef __LITTLE_ENDIAN
  40487. + return *p;
  40488. +#else
  40489. + uint8_t *u_p = (uint8_t *)p;
  40490. +
  40491. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  40492. +#endif
  40493. +}
  40494. +
  40495. +uint32_t DWC_CPU_TO_BE32(uint32_t *p)
  40496. +{
  40497. +#ifdef __BIG_ENDIAN
  40498. + return *p;
  40499. +#else
  40500. + uint8_t *u_p = (uint8_t *)p;
  40501. +
  40502. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  40503. +#endif
  40504. +}
  40505. +
  40506. +uint32_t DWC_LE32_TO_CPU(uint32_t *p)
  40507. +{
  40508. +#ifdef __LITTLE_ENDIAN
  40509. + return *p;
  40510. +#else
  40511. + uint8_t *u_p = (uint8_t *)p;
  40512. +
  40513. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  40514. +#endif
  40515. +}
  40516. +
  40517. +uint32_t DWC_BE32_TO_CPU(uint32_t *p)
  40518. +{
  40519. +#ifdef __BIG_ENDIAN
  40520. + return *p;
  40521. +#else
  40522. + uint8_t *u_p = (uint8_t *)p;
  40523. +
  40524. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  40525. +#endif
  40526. +}
  40527. +
  40528. +uint16_t DWC_CPU_TO_LE16(uint16_t *p)
  40529. +{
  40530. +#ifdef __LITTLE_ENDIAN
  40531. + return *p;
  40532. +#else
  40533. + uint8_t *u_p = (uint8_t *)p;
  40534. + return (u_p[1] | (u_p[0] << 8));
  40535. +#endif
  40536. +}
  40537. +
  40538. +uint16_t DWC_CPU_TO_BE16(uint16_t *p)
  40539. +{
  40540. +#ifdef __BIG_ENDIAN
  40541. + return *p;
  40542. +#else
  40543. + uint8_t *u_p = (uint8_t *)p;
  40544. + return (u_p[1] | (u_p[0] << 8));
  40545. +#endif
  40546. +}
  40547. +
  40548. +uint16_t DWC_LE16_TO_CPU(uint16_t *p)
  40549. +{
  40550. +#ifdef __LITTLE_ENDIAN
  40551. + return *p;
  40552. +#else
  40553. + uint8_t *u_p = (uint8_t *)p;
  40554. + return (u_p[1] | (u_p[0] << 8));
  40555. +#endif
  40556. +}
  40557. +
  40558. +uint16_t DWC_BE16_TO_CPU(uint16_t *p)
  40559. +{
  40560. +#ifdef __BIG_ENDIAN
  40561. + return *p;
  40562. +#else
  40563. + uint8_t *u_p = (uint8_t *)p;
  40564. + return (u_p[1] | (u_p[0] << 8));
  40565. +#endif
  40566. +}
  40567. +
  40568. +
  40569. +/* Registers */
  40570. +
  40571. +uint32_t DWC_READ_REG32(uint32_t volatile *reg)
  40572. +{
  40573. + return readl(reg);
  40574. +}
  40575. +
  40576. +#if 0
  40577. +uint64_t DWC_READ_REG64(uint64_t volatile *reg)
  40578. +{
  40579. +}
  40580. +#endif
  40581. +
  40582. +void DWC_WRITE_REG32(uint32_t volatile *reg, uint32_t value)
  40583. +{
  40584. + writel(value, reg);
  40585. +}
  40586. +
  40587. +#if 0
  40588. +void DWC_WRITE_REG64(uint64_t volatile *reg, uint64_t value)
  40589. +{
  40590. +}
  40591. +#endif
  40592. +
  40593. +void DWC_MODIFY_REG32(uint32_t volatile *reg, uint32_t clear_mask, uint32_t set_mask)
  40594. +{
  40595. + unsigned long flags;
  40596. +
  40597. + local_irq_save(flags);
  40598. + local_fiq_disable();
  40599. + writel((readl(reg) & ~clear_mask) | set_mask, reg);
  40600. + local_irq_restore(flags);
  40601. +}
  40602. +
  40603. +#if 0
  40604. +void DWC_MODIFY_REG64(uint64_t volatile *reg, uint64_t clear_mask, uint64_t set_mask)
  40605. +{
  40606. +}
  40607. +#endif
  40608. +
  40609. +
  40610. +/* Locking */
  40611. +
  40612. +dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void)
  40613. +{
  40614. + spinlock_t *sl = (spinlock_t *)1;
  40615. +
  40616. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  40617. + sl = DWC_ALLOC(sizeof(*sl));
  40618. + if (!sl) {
  40619. + DWC_ERROR("Cannot allocate memory for spinlock\n");
  40620. + return NULL;
  40621. + }
  40622. +
  40623. + spin_lock_init(sl);
  40624. +#endif
  40625. + return (dwc_spinlock_t *)sl;
  40626. +}
  40627. +
  40628. +void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock)
  40629. +{
  40630. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  40631. + DWC_FREE(lock);
  40632. +#endif
  40633. +}
  40634. +
  40635. +void DWC_SPINLOCK(dwc_spinlock_t *lock)
  40636. +{
  40637. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  40638. + spin_lock((spinlock_t *)lock);
  40639. +#endif
  40640. +}
  40641. +
  40642. +void DWC_SPINUNLOCK(dwc_spinlock_t *lock)
  40643. +{
  40644. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  40645. + spin_unlock((spinlock_t *)lock);
  40646. +#endif
  40647. +}
  40648. +
  40649. +void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags)
  40650. +{
  40651. + dwc_irqflags_t f;
  40652. +
  40653. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  40654. + spin_lock_irqsave((spinlock_t *)lock, f);
  40655. +#else
  40656. + local_irq_save(f);
  40657. +#endif
  40658. + *flags = f;
  40659. +}
  40660. +
  40661. +void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags)
  40662. +{
  40663. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  40664. + spin_unlock_irqrestore((spinlock_t *)lock, flags);
  40665. +#else
  40666. + local_irq_restore(flags);
  40667. +#endif
  40668. +}
  40669. +
  40670. +dwc_mutex_t *DWC_MUTEX_ALLOC(void)
  40671. +{
  40672. + struct mutex *m;
  40673. + dwc_mutex_t *mutex = (dwc_mutex_t *)DWC_ALLOC(sizeof(struct mutex));
  40674. +
  40675. + if (!mutex) {
  40676. + DWC_ERROR("Cannot allocate memory for mutex\n");
  40677. + return NULL;
  40678. + }
  40679. +
  40680. + m = (struct mutex *)mutex;
  40681. + mutex_init(m);
  40682. + return mutex;
  40683. +}
  40684. +
  40685. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  40686. +#else
  40687. +void DWC_MUTEX_FREE(dwc_mutex_t *mutex)
  40688. +{
  40689. + mutex_destroy((struct mutex *)mutex);
  40690. + DWC_FREE(mutex);
  40691. +}
  40692. +#endif
  40693. +
  40694. +void DWC_MUTEX_LOCK(dwc_mutex_t *mutex)
  40695. +{
  40696. + struct mutex *m = (struct mutex *)mutex;
  40697. + mutex_lock(m);
  40698. +}
  40699. +
  40700. +int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex)
  40701. +{
  40702. + struct mutex *m = (struct mutex *)mutex;
  40703. + return mutex_trylock(m);
  40704. +}
  40705. +
  40706. +void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex)
  40707. +{
  40708. + struct mutex *m = (struct mutex *)mutex;
  40709. + mutex_unlock(m);
  40710. +}
  40711. +
  40712. +
  40713. +/* Timing */
  40714. +
  40715. +void DWC_UDELAY(uint32_t usecs)
  40716. +{
  40717. + udelay(usecs);
  40718. +}
  40719. +
  40720. +void DWC_MDELAY(uint32_t msecs)
  40721. +{
  40722. + mdelay(msecs);
  40723. +}
  40724. +
  40725. +void DWC_MSLEEP(uint32_t msecs)
  40726. +{
  40727. + msleep(msecs);
  40728. +}
  40729. +
  40730. +uint32_t DWC_TIME(void)
  40731. +{
  40732. + return jiffies_to_msecs(jiffies);
  40733. +}
  40734. +
  40735. +
  40736. +/* Timers */
  40737. +
  40738. +struct dwc_timer {
  40739. + struct timer_list *t;
  40740. + char *name;
  40741. + dwc_timer_callback_t cb;
  40742. + void *data;
  40743. + uint8_t scheduled;
  40744. + dwc_spinlock_t *lock;
  40745. +};
  40746. +
  40747. +static void timer_callback(unsigned long data)
  40748. +{
  40749. + dwc_timer_t *timer = (dwc_timer_t *)data;
  40750. + dwc_irqflags_t flags;
  40751. +
  40752. + DWC_SPINLOCK_IRQSAVE(timer->lock, &flags);
  40753. + timer->scheduled = 0;
  40754. + DWC_SPINUNLOCK_IRQRESTORE(timer->lock, flags);
  40755. + DWC_DEBUGC("Timer %s callback", timer->name);
  40756. + timer->cb(timer->data);
  40757. +}
  40758. +
  40759. +dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data)
  40760. +{
  40761. + dwc_timer_t *t = DWC_ALLOC(sizeof(*t));
  40762. +
  40763. + if (!t) {
  40764. + DWC_ERROR("Cannot allocate memory for timer");
  40765. + return NULL;
  40766. + }
  40767. +
  40768. + t->t = DWC_ALLOC(sizeof(*t->t));
  40769. + if (!t->t) {
  40770. + DWC_ERROR("Cannot allocate memory for timer->t");
  40771. + goto no_timer;
  40772. + }
  40773. +
  40774. + t->name = DWC_STRDUP(name);
  40775. + if (!t->name) {
  40776. + DWC_ERROR("Cannot allocate memory for timer->name");
  40777. + goto no_name;
  40778. + }
  40779. +
  40780. + t->lock = DWC_SPINLOCK_ALLOC();
  40781. + if (!t->lock) {
  40782. + DWC_ERROR("Cannot allocate memory for lock");
  40783. + goto no_lock;
  40784. + }
  40785. +
  40786. + t->scheduled = 0;
  40787. + t->t->base = &boot_tvec_bases;
  40788. + t->t->expires = jiffies;
  40789. + setup_timer(t->t, timer_callback, (unsigned long)t);
  40790. +
  40791. + t->cb = cb;
  40792. + t->data = data;
  40793. +
  40794. + return t;
  40795. +
  40796. + no_lock:
  40797. + DWC_FREE(t->name);
  40798. + no_name:
  40799. + DWC_FREE(t->t);
  40800. + no_timer:
  40801. + DWC_FREE(t);
  40802. + return NULL;
  40803. +}
  40804. +
  40805. +void DWC_TIMER_FREE(dwc_timer_t *timer)
  40806. +{
  40807. + dwc_irqflags_t flags;
  40808. +
  40809. + DWC_SPINLOCK_IRQSAVE(timer->lock, &flags);
  40810. +
  40811. + if (timer->scheduled) {
  40812. + del_timer(timer->t);
  40813. + timer->scheduled = 0;
  40814. + }
  40815. +
  40816. + DWC_SPINUNLOCK_IRQRESTORE(timer->lock, flags);
  40817. + DWC_SPINLOCK_FREE(timer->lock);
  40818. + DWC_FREE(timer->t);
  40819. + DWC_FREE(timer->name);
  40820. + DWC_FREE(timer);
  40821. +}
  40822. +
  40823. +void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time)
  40824. +{
  40825. + dwc_irqflags_t flags;
  40826. +
  40827. + DWC_SPINLOCK_IRQSAVE(timer->lock, &flags);
  40828. +
  40829. + if (!timer->scheduled) {
  40830. + timer->scheduled = 1;
  40831. + DWC_DEBUGC("Scheduling timer %s to expire in +%d msec", timer->name, time);
  40832. + timer->t->expires = jiffies + msecs_to_jiffies(time);
  40833. + add_timer(timer->t);
  40834. + } else {
  40835. + DWC_DEBUGC("Modifying timer %s to expire in +%d msec", timer->name, time);
  40836. + mod_timer(timer->t, jiffies + msecs_to_jiffies(time));
  40837. + }
  40838. +
  40839. + DWC_SPINUNLOCK_IRQRESTORE(timer->lock, flags);
  40840. +}
  40841. +
  40842. +void DWC_TIMER_CANCEL(dwc_timer_t *timer)
  40843. +{
  40844. + del_timer(timer->t);
  40845. +}
  40846. +
  40847. +
  40848. +/* Wait Queues */
  40849. +
  40850. +struct dwc_waitq {
  40851. + wait_queue_head_t queue;
  40852. + int abort;
  40853. +};
  40854. +
  40855. +dwc_waitq_t *DWC_WAITQ_ALLOC(void)
  40856. +{
  40857. + dwc_waitq_t *wq = DWC_ALLOC(sizeof(*wq));
  40858. +
  40859. + if (!wq) {
  40860. + DWC_ERROR("Cannot allocate memory for waitqueue\n");
  40861. + return NULL;
  40862. + }
  40863. +
  40864. + init_waitqueue_head(&wq->queue);
  40865. + wq->abort = 0;
  40866. + return wq;
  40867. +}
  40868. +
  40869. +void DWC_WAITQ_FREE(dwc_waitq_t *wq)
  40870. +{
  40871. + DWC_FREE(wq);
  40872. +}
  40873. +
  40874. +int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data)
  40875. +{
  40876. + int result = wait_event_interruptible(wq->queue,
  40877. + cond(data) || wq->abort);
  40878. + if (result == -ERESTARTSYS) {
  40879. + wq->abort = 0;
  40880. + return -DWC_E_RESTART;
  40881. + }
  40882. +
  40883. + if (wq->abort == 1) {
  40884. + wq->abort = 0;
  40885. + return -DWC_E_ABORT;
  40886. + }
  40887. +
  40888. + wq->abort = 0;
  40889. +
  40890. + if (result == 0) {
  40891. + return 0;
  40892. + }
  40893. +
  40894. + return -DWC_E_UNKNOWN;
  40895. +}
  40896. +
  40897. +int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  40898. + void *data, int32_t msecs)
  40899. +{
  40900. + int32_t tmsecs;
  40901. + int result = wait_event_interruptible_timeout(wq->queue,
  40902. + cond(data) || wq->abort,
  40903. + msecs_to_jiffies(msecs));
  40904. + if (result == -ERESTARTSYS) {
  40905. + wq->abort = 0;
  40906. + return -DWC_E_RESTART;
  40907. + }
  40908. +
  40909. + if (wq->abort == 1) {
  40910. + wq->abort = 0;
  40911. + return -DWC_E_ABORT;
  40912. + }
  40913. +
  40914. + wq->abort = 0;
  40915. +
  40916. + if (result > 0) {
  40917. + tmsecs = jiffies_to_msecs(result);
  40918. + if (!tmsecs) {
  40919. + return 1;
  40920. + }
  40921. +
  40922. + return tmsecs;
  40923. + }
  40924. +
  40925. + if (result == 0) {
  40926. + return -DWC_E_TIMEOUT;
  40927. + }
  40928. +
  40929. + return -DWC_E_UNKNOWN;
  40930. +}
  40931. +
  40932. +void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq)
  40933. +{
  40934. + wq->abort = 0;
  40935. + wake_up_interruptible(&wq->queue);
  40936. +}
  40937. +
  40938. +void DWC_WAITQ_ABORT(dwc_waitq_t *wq)
  40939. +{
  40940. + wq->abort = 1;
  40941. + wake_up_interruptible(&wq->queue);
  40942. +}
  40943. +
  40944. +
  40945. +/* Threading */
  40946. +
  40947. +dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data)
  40948. +{
  40949. + struct task_struct *thread = kthread_run(func, data, name);
  40950. +
  40951. + if (thread == ERR_PTR(-ENOMEM)) {
  40952. + return NULL;
  40953. + }
  40954. +
  40955. + return (dwc_thread_t *)thread;
  40956. +}
  40957. +
  40958. +int DWC_THREAD_STOP(dwc_thread_t *thread)
  40959. +{
  40960. + return kthread_stop((struct task_struct *)thread);
  40961. +}
  40962. +
  40963. +dwc_bool_t DWC_THREAD_SHOULD_STOP(void)
  40964. +{
  40965. + return kthread_should_stop();
  40966. +}
  40967. +
  40968. +
  40969. +/* tasklets
  40970. + - run in interrupt context (cannot sleep)
  40971. + - each tasklet runs on a single CPU
  40972. + - different tasklets can be running simultaneously on different CPUs
  40973. + */
  40974. +struct dwc_tasklet {
  40975. + struct tasklet_struct t;
  40976. + dwc_tasklet_callback_t cb;
  40977. + void *data;
  40978. +};
  40979. +
  40980. +static void tasklet_callback(unsigned long data)
  40981. +{
  40982. + dwc_tasklet_t *t = (dwc_tasklet_t *)data;
  40983. + t->cb(t->data);
  40984. +}
  40985. +
  40986. +dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data)
  40987. +{
  40988. + dwc_tasklet_t *t = DWC_ALLOC(sizeof(*t));
  40989. +
  40990. + if (t) {
  40991. + t->cb = cb;
  40992. + t->data = data;
  40993. + tasklet_init(&t->t, tasklet_callback, (unsigned long)t);
  40994. + } else {
  40995. + DWC_ERROR("Cannot allocate memory for tasklet\n");
  40996. + }
  40997. +
  40998. + return t;
  40999. +}
  41000. +
  41001. +void DWC_TASK_FREE(dwc_tasklet_t *task)
  41002. +{
  41003. + DWC_FREE(task);
  41004. +}
  41005. +
  41006. +void DWC_TASK_SCHEDULE(dwc_tasklet_t *task)
  41007. +{
  41008. + tasklet_schedule(&task->t);
  41009. +}
  41010. +
  41011. +void DWC_TASK_HI_SCHEDULE(dwc_tasklet_t *task)
  41012. +{
  41013. + tasklet_hi_schedule(&task->t);
  41014. +}
  41015. +
  41016. +
  41017. +/* workqueues
  41018. + - run in process context (can sleep)
  41019. + */
  41020. +typedef struct work_container {
  41021. + dwc_work_callback_t cb;
  41022. + void *data;
  41023. + dwc_workq_t *wq;
  41024. + char *name;
  41025. +
  41026. +#ifdef DEBUG
  41027. + DWC_CIRCLEQ_ENTRY(work_container) entry;
  41028. +#endif
  41029. + struct delayed_work work;
  41030. +} work_container_t;
  41031. +
  41032. +#ifdef DEBUG
  41033. +DWC_CIRCLEQ_HEAD(work_container_queue, work_container);
  41034. +#endif
  41035. +
  41036. +struct dwc_workq {
  41037. + struct workqueue_struct *wq;
  41038. + dwc_spinlock_t *lock;
  41039. + dwc_waitq_t *waitq;
  41040. + int pending;
  41041. +
  41042. +#ifdef DEBUG
  41043. + struct work_container_queue entries;
  41044. +#endif
  41045. +};
  41046. +
  41047. +static void do_work(struct work_struct *work)
  41048. +{
  41049. + dwc_irqflags_t flags;
  41050. + struct delayed_work *dw = container_of(work, struct delayed_work, work);
  41051. + work_container_t *container = container_of(dw, struct work_container, work);
  41052. + dwc_workq_t *wq = container->wq;
  41053. +
  41054. + container->cb(container->data);
  41055. +
  41056. +#ifdef DEBUG
  41057. + DWC_CIRCLEQ_REMOVE(&wq->entries, container, entry);
  41058. +#endif
  41059. + DWC_DEBUGC("Work done: %s, container=%p", container->name, container);
  41060. + if (container->name) {
  41061. + DWC_FREE(container->name);
  41062. + }
  41063. + DWC_FREE(container);
  41064. +
  41065. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  41066. + wq->pending--;
  41067. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  41068. + DWC_WAITQ_TRIGGER(wq->waitq);
  41069. +}
  41070. +
  41071. +static int work_done(void *data)
  41072. +{
  41073. + dwc_workq_t *workq = (dwc_workq_t *)data;
  41074. + return workq->pending == 0;
  41075. +}
  41076. +
  41077. +int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout)
  41078. +{
  41079. + return DWC_WAITQ_WAIT_TIMEOUT(workq->waitq, work_done, workq, timeout);
  41080. +}
  41081. +
  41082. +dwc_workq_t *DWC_WORKQ_ALLOC(char *name)
  41083. +{
  41084. + dwc_workq_t *wq = DWC_ALLOC(sizeof(*wq));
  41085. +
  41086. + if (!wq) {
  41087. + return NULL;
  41088. + }
  41089. +
  41090. + wq->wq = create_singlethread_workqueue(name);
  41091. + if (!wq->wq) {
  41092. + goto no_wq;
  41093. + }
  41094. +
  41095. + wq->pending = 0;
  41096. +
  41097. + wq->lock = DWC_SPINLOCK_ALLOC();
  41098. + if (!wq->lock) {
  41099. + goto no_lock;
  41100. + }
  41101. +
  41102. + wq->waitq = DWC_WAITQ_ALLOC();
  41103. + if (!wq->waitq) {
  41104. + goto no_waitq;
  41105. + }
  41106. +
  41107. +#ifdef DEBUG
  41108. + DWC_CIRCLEQ_INIT(&wq->entries);
  41109. +#endif
  41110. + return wq;
  41111. +
  41112. + no_waitq:
  41113. + DWC_SPINLOCK_FREE(wq->lock);
  41114. + no_lock:
  41115. + destroy_workqueue(wq->wq);
  41116. + no_wq:
  41117. + DWC_FREE(wq);
  41118. +
  41119. + return NULL;
  41120. +}
  41121. +
  41122. +void DWC_WORKQ_FREE(dwc_workq_t *wq)
  41123. +{
  41124. +#ifdef DEBUG
  41125. + if (wq->pending != 0) {
  41126. + struct work_container *wc;
  41127. + DWC_ERROR("Destroying work queue with pending work");
  41128. + DWC_CIRCLEQ_FOREACH(wc, &wq->entries, entry) {
  41129. + DWC_ERROR("Work %s still pending", wc->name);
  41130. + }
  41131. + }
  41132. +#endif
  41133. + destroy_workqueue(wq->wq);
  41134. + DWC_SPINLOCK_FREE(wq->lock);
  41135. + DWC_WAITQ_FREE(wq->waitq);
  41136. + DWC_FREE(wq);
  41137. +}
  41138. +
  41139. +void DWC_WORKQ_SCHEDULE(dwc_workq_t *wq, dwc_work_callback_t cb, void *data,
  41140. + char *format, ...)
  41141. +{
  41142. + dwc_irqflags_t flags;
  41143. + work_container_t *container;
  41144. + static char name[128];
  41145. + va_list args;
  41146. +
  41147. + va_start(args, format);
  41148. + DWC_VSNPRINTF(name, 128, format, args);
  41149. + va_end(args);
  41150. +
  41151. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  41152. + wq->pending++;
  41153. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  41154. + DWC_WAITQ_TRIGGER(wq->waitq);
  41155. +
  41156. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  41157. + if (!container) {
  41158. + DWC_ERROR("Cannot allocate memory for container\n");
  41159. + return;
  41160. + }
  41161. +
  41162. + container->name = DWC_STRDUP(name);
  41163. + if (!container->name) {
  41164. + DWC_ERROR("Cannot allocate memory for container->name\n");
  41165. + DWC_FREE(container);
  41166. + return;
  41167. + }
  41168. +
  41169. + container->cb = cb;
  41170. + container->data = data;
  41171. + container->wq = wq;
  41172. + DWC_DEBUGC("Queueing work: %s, container=%p", container->name, container);
  41173. + INIT_WORK(&container->work.work, do_work);
  41174. +
  41175. +#ifdef DEBUG
  41176. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  41177. +#endif
  41178. + queue_work(wq->wq, &container->work.work);
  41179. +}
  41180. +
  41181. +void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *wq, dwc_work_callback_t cb,
  41182. + void *data, uint32_t time, char *format, ...)
  41183. +{
  41184. + dwc_irqflags_t flags;
  41185. + work_container_t *container;
  41186. + static char name[128];
  41187. + va_list args;
  41188. +
  41189. + va_start(args, format);
  41190. + DWC_VSNPRINTF(name, 128, format, args);
  41191. + va_end(args);
  41192. +
  41193. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  41194. + wq->pending++;
  41195. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  41196. + DWC_WAITQ_TRIGGER(wq->waitq);
  41197. +
  41198. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  41199. + if (!container) {
  41200. + DWC_ERROR("Cannot allocate memory for container\n");
  41201. + return;
  41202. + }
  41203. +
  41204. + container->name = DWC_STRDUP(name);
  41205. + if (!container->name) {
  41206. + DWC_ERROR("Cannot allocate memory for container->name\n");
  41207. + DWC_FREE(container);
  41208. + return;
  41209. + }
  41210. +
  41211. + container->cb = cb;
  41212. + container->data = data;
  41213. + container->wq = wq;
  41214. + DWC_DEBUGC("Queueing work: %s, container=%p", container->name, container);
  41215. + INIT_DELAYED_WORK(&container->work, do_work);
  41216. +
  41217. +#ifdef DEBUG
  41218. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  41219. +#endif
  41220. + queue_delayed_work(wq->wq, &container->work, msecs_to_jiffies(time));
  41221. +}
  41222. +
  41223. +int DWC_WORKQ_PENDING(dwc_workq_t *wq)
  41224. +{
  41225. + return wq->pending;
  41226. +}
  41227. +
  41228. +
  41229. +#ifdef DWC_LIBMODULE
  41230. +
  41231. +#ifdef DWC_CCLIB
  41232. +/* CC */
  41233. +EXPORT_SYMBOL(dwc_cc_if_alloc);
  41234. +EXPORT_SYMBOL(dwc_cc_if_free);
  41235. +EXPORT_SYMBOL(dwc_cc_clear);
  41236. +EXPORT_SYMBOL(dwc_cc_add);
  41237. +EXPORT_SYMBOL(dwc_cc_remove);
  41238. +EXPORT_SYMBOL(dwc_cc_change);
  41239. +EXPORT_SYMBOL(dwc_cc_data_for_save);
  41240. +EXPORT_SYMBOL(dwc_cc_restore_from_data);
  41241. +EXPORT_SYMBOL(dwc_cc_match_chid);
  41242. +EXPORT_SYMBOL(dwc_cc_match_cdid);
  41243. +EXPORT_SYMBOL(dwc_cc_ck);
  41244. +EXPORT_SYMBOL(dwc_cc_chid);
  41245. +EXPORT_SYMBOL(dwc_cc_cdid);
  41246. +EXPORT_SYMBOL(dwc_cc_name);
  41247. +#endif /* DWC_CCLIB */
  41248. +
  41249. +#ifdef DWC_CRYPTOLIB
  41250. +# ifndef CONFIG_MACH_IPMATE
  41251. +/* Modpow */
  41252. +EXPORT_SYMBOL(dwc_modpow);
  41253. +
  41254. +/* DH */
  41255. +EXPORT_SYMBOL(dwc_dh_modpow);
  41256. +EXPORT_SYMBOL(dwc_dh_derive_keys);
  41257. +EXPORT_SYMBOL(dwc_dh_pk);
  41258. +# endif /* CONFIG_MACH_IPMATE */
  41259. +
  41260. +/* Crypto */
  41261. +EXPORT_SYMBOL(dwc_wusb_aes_encrypt);
  41262. +EXPORT_SYMBOL(dwc_wusb_cmf);
  41263. +EXPORT_SYMBOL(dwc_wusb_prf);
  41264. +EXPORT_SYMBOL(dwc_wusb_fill_ccm_nonce);
  41265. +EXPORT_SYMBOL(dwc_wusb_gen_nonce);
  41266. +EXPORT_SYMBOL(dwc_wusb_gen_key);
  41267. +EXPORT_SYMBOL(dwc_wusb_gen_mic);
  41268. +#endif /* DWC_CRYPTOLIB */
  41269. +
  41270. +/* Notification */
  41271. +#ifdef DWC_NOTIFYLIB
  41272. +EXPORT_SYMBOL(dwc_alloc_notification_manager);
  41273. +EXPORT_SYMBOL(dwc_free_notification_manager);
  41274. +EXPORT_SYMBOL(dwc_register_notifier);
  41275. +EXPORT_SYMBOL(dwc_unregister_notifier);
  41276. +EXPORT_SYMBOL(dwc_add_observer);
  41277. +EXPORT_SYMBOL(dwc_remove_observer);
  41278. +EXPORT_SYMBOL(dwc_notify);
  41279. +#endif
  41280. +
  41281. +/* Memory Debugging Routines */
  41282. +#ifdef DWC_DEBUG_MEMORY
  41283. +EXPORT_SYMBOL(dwc_alloc_debug);
  41284. +EXPORT_SYMBOL(dwc_alloc_atomic_debug);
  41285. +EXPORT_SYMBOL(dwc_free_debug);
  41286. +EXPORT_SYMBOL(dwc_dma_alloc_debug);
  41287. +EXPORT_SYMBOL(dwc_dma_free_debug);
  41288. +#endif
  41289. +
  41290. +EXPORT_SYMBOL(DWC_MEMSET);
  41291. +EXPORT_SYMBOL(DWC_MEMCPY);
  41292. +EXPORT_SYMBOL(DWC_MEMMOVE);
  41293. +EXPORT_SYMBOL(DWC_MEMCMP);
  41294. +EXPORT_SYMBOL(DWC_STRNCMP);
  41295. +EXPORT_SYMBOL(DWC_STRCMP);
  41296. +EXPORT_SYMBOL(DWC_STRLEN);
  41297. +EXPORT_SYMBOL(DWC_STRCPY);
  41298. +EXPORT_SYMBOL(DWC_STRDUP);
  41299. +EXPORT_SYMBOL(DWC_ATOI);
  41300. +EXPORT_SYMBOL(DWC_ATOUI);
  41301. +
  41302. +#ifdef DWC_UTFLIB
  41303. +EXPORT_SYMBOL(DWC_UTF8_TO_UTF16LE);
  41304. +#endif /* DWC_UTFLIB */
  41305. +
  41306. +EXPORT_SYMBOL(DWC_IN_IRQ);
  41307. +EXPORT_SYMBOL(DWC_IN_BH);
  41308. +EXPORT_SYMBOL(DWC_VPRINTF);
  41309. +EXPORT_SYMBOL(DWC_VSNPRINTF);
  41310. +EXPORT_SYMBOL(DWC_PRINTF);
  41311. +EXPORT_SYMBOL(DWC_SPRINTF);
  41312. +EXPORT_SYMBOL(DWC_SNPRINTF);
  41313. +EXPORT_SYMBOL(__DWC_WARN);
  41314. +EXPORT_SYMBOL(__DWC_ERROR);
  41315. +EXPORT_SYMBOL(DWC_EXCEPTION);
  41316. +
  41317. +#ifdef DEBUG
  41318. +EXPORT_SYMBOL(__DWC_DEBUG);
  41319. +#endif
  41320. +
  41321. +EXPORT_SYMBOL(__DWC_DMA_ALLOC);
  41322. +EXPORT_SYMBOL(__DWC_DMA_ALLOC_ATOMIC);
  41323. +EXPORT_SYMBOL(__DWC_DMA_FREE);
  41324. +EXPORT_SYMBOL(__DWC_ALLOC);
  41325. +EXPORT_SYMBOL(__DWC_ALLOC_ATOMIC);
  41326. +EXPORT_SYMBOL(__DWC_FREE);
  41327. +
  41328. +#ifdef DWC_CRYPTOLIB
  41329. +EXPORT_SYMBOL(DWC_RANDOM_BYTES);
  41330. +EXPORT_SYMBOL(DWC_AES_CBC);
  41331. +EXPORT_SYMBOL(DWC_SHA256);
  41332. +EXPORT_SYMBOL(DWC_HMAC_SHA256);
  41333. +#endif
  41334. +
  41335. +EXPORT_SYMBOL(DWC_CPU_TO_LE32);
  41336. +EXPORT_SYMBOL(DWC_CPU_TO_BE32);
  41337. +EXPORT_SYMBOL(DWC_LE32_TO_CPU);
  41338. +EXPORT_SYMBOL(DWC_BE32_TO_CPU);
  41339. +EXPORT_SYMBOL(DWC_CPU_TO_LE16);
  41340. +EXPORT_SYMBOL(DWC_CPU_TO_BE16);
  41341. +EXPORT_SYMBOL(DWC_LE16_TO_CPU);
  41342. +EXPORT_SYMBOL(DWC_BE16_TO_CPU);
  41343. +EXPORT_SYMBOL(DWC_READ_REG32);
  41344. +EXPORT_SYMBOL(DWC_WRITE_REG32);
  41345. +EXPORT_SYMBOL(DWC_MODIFY_REG32);
  41346. +
  41347. +#if 0
  41348. +EXPORT_SYMBOL(DWC_READ_REG64);
  41349. +EXPORT_SYMBOL(DWC_WRITE_REG64);
  41350. +EXPORT_SYMBOL(DWC_MODIFY_REG64);
  41351. +#endif
  41352. +
  41353. +EXPORT_SYMBOL(DWC_SPINLOCK_ALLOC);
  41354. +EXPORT_SYMBOL(DWC_SPINLOCK_FREE);
  41355. +EXPORT_SYMBOL(DWC_SPINLOCK);
  41356. +EXPORT_SYMBOL(DWC_SPINUNLOCK);
  41357. +EXPORT_SYMBOL(DWC_SPINLOCK_IRQSAVE);
  41358. +EXPORT_SYMBOL(DWC_SPINUNLOCK_IRQRESTORE);
  41359. +EXPORT_SYMBOL(DWC_MUTEX_ALLOC);
  41360. +
  41361. +#if (!defined(DWC_LINUX) || !defined(CONFIG_DEBUG_MUTEXES))
  41362. +EXPORT_SYMBOL(DWC_MUTEX_FREE);
  41363. +#endif
  41364. +
  41365. +EXPORT_SYMBOL(DWC_MUTEX_LOCK);
  41366. +EXPORT_SYMBOL(DWC_MUTEX_TRYLOCK);
  41367. +EXPORT_SYMBOL(DWC_MUTEX_UNLOCK);
  41368. +EXPORT_SYMBOL(DWC_UDELAY);
  41369. +EXPORT_SYMBOL(DWC_MDELAY);
  41370. +EXPORT_SYMBOL(DWC_MSLEEP);
  41371. +EXPORT_SYMBOL(DWC_TIME);
  41372. +EXPORT_SYMBOL(DWC_TIMER_ALLOC);
  41373. +EXPORT_SYMBOL(DWC_TIMER_FREE);
  41374. +EXPORT_SYMBOL(DWC_TIMER_SCHEDULE);
  41375. +EXPORT_SYMBOL(DWC_TIMER_CANCEL);
  41376. +EXPORT_SYMBOL(DWC_WAITQ_ALLOC);
  41377. +EXPORT_SYMBOL(DWC_WAITQ_FREE);
  41378. +EXPORT_SYMBOL(DWC_WAITQ_WAIT);
  41379. +EXPORT_SYMBOL(DWC_WAITQ_WAIT_TIMEOUT);
  41380. +EXPORT_SYMBOL(DWC_WAITQ_TRIGGER);
  41381. +EXPORT_SYMBOL(DWC_WAITQ_ABORT);
  41382. +EXPORT_SYMBOL(DWC_THREAD_RUN);
  41383. +EXPORT_SYMBOL(DWC_THREAD_STOP);
  41384. +EXPORT_SYMBOL(DWC_THREAD_SHOULD_STOP);
  41385. +EXPORT_SYMBOL(DWC_TASK_ALLOC);
  41386. +EXPORT_SYMBOL(DWC_TASK_FREE);
  41387. +EXPORT_SYMBOL(DWC_TASK_SCHEDULE);
  41388. +EXPORT_SYMBOL(DWC_WORKQ_WAIT_WORK_DONE);
  41389. +EXPORT_SYMBOL(DWC_WORKQ_ALLOC);
  41390. +EXPORT_SYMBOL(DWC_WORKQ_FREE);
  41391. +EXPORT_SYMBOL(DWC_WORKQ_SCHEDULE);
  41392. +EXPORT_SYMBOL(DWC_WORKQ_SCHEDULE_DELAYED);
  41393. +EXPORT_SYMBOL(DWC_WORKQ_PENDING);
  41394. +
  41395. +static int dwc_common_port_init_module(void)
  41396. +{
  41397. + int result = 0;
  41398. +
  41399. + printk(KERN_DEBUG "Module dwc_common_port init\n" );
  41400. +
  41401. +#ifdef DWC_DEBUG_MEMORY
  41402. + result = dwc_memory_debug_start(NULL);
  41403. + if (result) {
  41404. + printk(KERN_ERR
  41405. + "dwc_memory_debug_start() failed with error %d\n",
  41406. + result);
  41407. + return result;
  41408. + }
  41409. +#endif
  41410. +
  41411. +#ifdef DWC_NOTIFYLIB
  41412. + result = dwc_alloc_notification_manager(NULL, NULL);
  41413. + if (result) {
  41414. + printk(KERN_ERR
  41415. + "dwc_alloc_notification_manager() failed with error %d\n",
  41416. + result);
  41417. + return result;
  41418. + }
  41419. +#endif
  41420. + return result;
  41421. +}
  41422. +
  41423. +static void dwc_common_port_exit_module(void)
  41424. +{
  41425. + printk(KERN_DEBUG "Module dwc_common_port exit\n" );
  41426. +
  41427. +#ifdef DWC_NOTIFYLIB
  41428. + dwc_free_notification_manager();
  41429. +#endif
  41430. +
  41431. +#ifdef DWC_DEBUG_MEMORY
  41432. + dwc_memory_debug_stop();
  41433. +#endif
  41434. +}
  41435. +
  41436. +module_init(dwc_common_port_init_module);
  41437. +module_exit(dwc_common_port_exit_module);
  41438. +
  41439. +MODULE_DESCRIPTION("DWC Common Library - Portable version");
  41440. +MODULE_AUTHOR("Synopsys Inc.");
  41441. +MODULE_LICENSE ("GPL");
  41442. +
  41443. +#endif /* DWC_LIBMODULE */
  41444. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c linux-3.13.3/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c
  41445. --- linux-3.13.3.orig/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c 1970-01-01 01:00:00.000000000 +0100
  41446. +++ linux-3.13.3/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c 2014-02-17 22:41:01.000000000 +0100
  41447. @@ -0,0 +1,1275 @@
  41448. +#include "dwc_os.h"
  41449. +#include "dwc_list.h"
  41450. +
  41451. +#ifdef DWC_CCLIB
  41452. +# include "dwc_cc.h"
  41453. +#endif
  41454. +
  41455. +#ifdef DWC_CRYPTOLIB
  41456. +# include "dwc_modpow.h"
  41457. +# include "dwc_dh.h"
  41458. +# include "dwc_crypto.h"
  41459. +#endif
  41460. +
  41461. +#ifdef DWC_NOTIFYLIB
  41462. +# include "dwc_notifier.h"
  41463. +#endif
  41464. +
  41465. +/* OS-Level Implementations */
  41466. +
  41467. +/* This is the NetBSD 4.0.1 kernel implementation of the DWC platform library. */
  41468. +
  41469. +
  41470. +/* MISC */
  41471. +
  41472. +void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size)
  41473. +{
  41474. + return memset(dest, byte, size);
  41475. +}
  41476. +
  41477. +void *DWC_MEMCPY(void *dest, void const *src, uint32_t size)
  41478. +{
  41479. + return memcpy(dest, src, size);
  41480. +}
  41481. +
  41482. +void *DWC_MEMMOVE(void *dest, void *src, uint32_t size)
  41483. +{
  41484. + bcopy(src, dest, size);
  41485. + return dest;
  41486. +}
  41487. +
  41488. +int DWC_MEMCMP(void *m1, void *m2, uint32_t size)
  41489. +{
  41490. + return memcmp(m1, m2, size);
  41491. +}
  41492. +
  41493. +int DWC_STRNCMP(void *s1, void *s2, uint32_t size)
  41494. +{
  41495. + return strncmp(s1, s2, size);
  41496. +}
  41497. +
  41498. +int DWC_STRCMP(void *s1, void *s2)
  41499. +{
  41500. + return strcmp(s1, s2);
  41501. +}
  41502. +
  41503. +int DWC_STRLEN(char const *str)
  41504. +{
  41505. + return strlen(str);
  41506. +}
  41507. +
  41508. +char *DWC_STRCPY(char *to, char const *from)
  41509. +{
  41510. + return strcpy(to, from);
  41511. +}
  41512. +
  41513. +char *DWC_STRDUP(char const *str)
  41514. +{
  41515. + int len = DWC_STRLEN(str) + 1;
  41516. + char *new = DWC_ALLOC_ATOMIC(len);
  41517. +
  41518. + if (!new) {
  41519. + return NULL;
  41520. + }
  41521. +
  41522. + DWC_MEMCPY(new, str, len);
  41523. + return new;
  41524. +}
  41525. +
  41526. +int DWC_ATOI(char *str, int32_t *value)
  41527. +{
  41528. + char *end = NULL;
  41529. +
  41530. + /* NetBSD doesn't have 'strtol' in the kernel, but 'strtoul'
  41531. + * should be equivalent on 2's complement machines
  41532. + */
  41533. + *value = strtoul(str, &end, 0);
  41534. + if (*end == '\0') {
  41535. + return 0;
  41536. + }
  41537. +
  41538. + return -1;
  41539. +}
  41540. +
  41541. +int DWC_ATOUI(char *str, uint32_t *value)
  41542. +{
  41543. + char *end = NULL;
  41544. +
  41545. + *value = strtoul(str, &end, 0);
  41546. + if (*end == '\0') {
  41547. + return 0;
  41548. + }
  41549. +
  41550. + return -1;
  41551. +}
  41552. +
  41553. +
  41554. +#ifdef DWC_UTFLIB
  41555. +/* From usbstring.c */
  41556. +
  41557. +int DWC_UTF8_TO_UTF16LE(uint8_t const *s, uint16_t *cp, unsigned len)
  41558. +{
  41559. + int count = 0;
  41560. + u8 c;
  41561. + u16 uchar;
  41562. +
  41563. + /* this insists on correct encodings, though not minimal ones.
  41564. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  41565. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  41566. + */
  41567. + while (len != 0 && (c = (u8) *s++) != 0) {
  41568. + if (unlikely(c & 0x80)) {
  41569. + // 2-byte sequence:
  41570. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  41571. + if ((c & 0xe0) == 0xc0) {
  41572. + uchar = (c & 0x1f) << 6;
  41573. +
  41574. + c = (u8) *s++;
  41575. + if ((c & 0xc0) != 0xc0)
  41576. + goto fail;
  41577. + c &= 0x3f;
  41578. + uchar |= c;
  41579. +
  41580. + // 3-byte sequence (most CJKV characters):
  41581. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  41582. + } else if ((c & 0xf0) == 0xe0) {
  41583. + uchar = (c & 0x0f) << 12;
  41584. +
  41585. + c = (u8) *s++;
  41586. + if ((c & 0xc0) != 0xc0)
  41587. + goto fail;
  41588. + c &= 0x3f;
  41589. + uchar |= c << 6;
  41590. +
  41591. + c = (u8) *s++;
  41592. + if ((c & 0xc0) != 0xc0)
  41593. + goto fail;
  41594. + c &= 0x3f;
  41595. + uchar |= c;
  41596. +
  41597. + /* no bogus surrogates */
  41598. + if (0xd800 <= uchar && uchar <= 0xdfff)
  41599. + goto fail;
  41600. +
  41601. + // 4-byte sequence (surrogate pairs, currently rare):
  41602. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  41603. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  41604. + // (uuuuu = wwww + 1)
  41605. + // FIXME accept the surrogate code points (only)
  41606. + } else
  41607. + goto fail;
  41608. + } else
  41609. + uchar = c;
  41610. + put_unaligned (cpu_to_le16 (uchar), cp++);
  41611. + count++;
  41612. + len--;
  41613. + }
  41614. + return count;
  41615. +fail:
  41616. + return -1;
  41617. +}
  41618. +
  41619. +#endif /* DWC_UTFLIB */
  41620. +
  41621. +
  41622. +/* dwc_debug.h */
  41623. +
  41624. +dwc_bool_t DWC_IN_IRQ(void)
  41625. +{
  41626. +// return in_irq();
  41627. + return 0;
  41628. +}
  41629. +
  41630. +dwc_bool_t DWC_IN_BH(void)
  41631. +{
  41632. +// return in_softirq();
  41633. + return 0;
  41634. +}
  41635. +
  41636. +void DWC_VPRINTF(char *format, va_list args)
  41637. +{
  41638. + vprintf(format, args);
  41639. +}
  41640. +
  41641. +int DWC_VSNPRINTF(char *str, int size, char *format, va_list args)
  41642. +{
  41643. + return vsnprintf(str, size, format, args);
  41644. +}
  41645. +
  41646. +void DWC_PRINTF(char *format, ...)
  41647. +{
  41648. + va_list args;
  41649. +
  41650. + va_start(args, format);
  41651. + DWC_VPRINTF(format, args);
  41652. + va_end(args);
  41653. +}
  41654. +
  41655. +int DWC_SPRINTF(char *buffer, char *format, ...)
  41656. +{
  41657. + int retval;
  41658. + va_list args;
  41659. +
  41660. + va_start(args, format);
  41661. + retval = vsprintf(buffer, format, args);
  41662. + va_end(args);
  41663. + return retval;
  41664. +}
  41665. +
  41666. +int DWC_SNPRINTF(char *buffer, int size, char *format, ...)
  41667. +{
  41668. + int retval;
  41669. + va_list args;
  41670. +
  41671. + va_start(args, format);
  41672. + retval = vsnprintf(buffer, size, format, args);
  41673. + va_end(args);
  41674. + return retval;
  41675. +}
  41676. +
  41677. +void __DWC_WARN(char *format, ...)
  41678. +{
  41679. + va_list args;
  41680. +
  41681. + va_start(args, format);
  41682. + DWC_VPRINTF(format, args);
  41683. + va_end(args);
  41684. +}
  41685. +
  41686. +void __DWC_ERROR(char *format, ...)
  41687. +{
  41688. + va_list args;
  41689. +
  41690. + va_start(args, format);
  41691. + DWC_VPRINTF(format, args);
  41692. + va_end(args);
  41693. +}
  41694. +
  41695. +void DWC_EXCEPTION(char *format, ...)
  41696. +{
  41697. + va_list args;
  41698. +
  41699. + va_start(args, format);
  41700. + DWC_VPRINTF(format, args);
  41701. + va_end(args);
  41702. +// BUG_ON(1); ???
  41703. +}
  41704. +
  41705. +#ifdef DEBUG
  41706. +void __DWC_DEBUG(char *format, ...)
  41707. +{
  41708. + va_list args;
  41709. +
  41710. + va_start(args, format);
  41711. + DWC_VPRINTF(format, args);
  41712. + va_end(args);
  41713. +}
  41714. +#endif
  41715. +
  41716. +
  41717. +/* dwc_mem.h */
  41718. +
  41719. +#if 0
  41720. +dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size,
  41721. + uint32_t align,
  41722. + uint32_t alloc)
  41723. +{
  41724. + struct dma_pool *pool = dma_pool_create("Pool", NULL,
  41725. + size, align, alloc);
  41726. + return (dwc_pool_t *)pool;
  41727. +}
  41728. +
  41729. +void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool)
  41730. +{
  41731. + dma_pool_destroy((struct dma_pool *)pool);
  41732. +}
  41733. +
  41734. +void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  41735. +{
  41736. +// return dma_pool_alloc((struct dma_pool *)pool, GFP_KERNEL, dma_addr);
  41737. + return dma_pool_alloc((struct dma_pool *)pool, M_WAITOK, dma_addr);
  41738. +}
  41739. +
  41740. +void *DWC_DMA_POOL_ZALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  41741. +{
  41742. + void *vaddr = DWC_DMA_POOL_ALLOC(pool, dma_addr);
  41743. + memset(..);
  41744. +}
  41745. +
  41746. +void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr)
  41747. +{
  41748. + dma_pool_free(pool, vaddr, daddr);
  41749. +}
  41750. +#endif
  41751. +
  41752. +void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  41753. +{
  41754. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  41755. + int error;
  41756. +
  41757. + error = bus_dmamem_alloc(dma->dma_tag, size, 1, size, dma->segs,
  41758. + sizeof(dma->segs) / sizeof(dma->segs[0]),
  41759. + &dma->nsegs, BUS_DMA_NOWAIT);
  41760. + if (error) {
  41761. + printf("%s: bus_dmamem_alloc(%ju) failed: %d\n", __func__,
  41762. + (uintmax_t)size, error);
  41763. + goto fail_0;
  41764. + }
  41765. +
  41766. + error = bus_dmamem_map(dma->dma_tag, dma->segs, dma->nsegs, size,
  41767. + (caddr_t *)&dma->dma_vaddr,
  41768. + BUS_DMA_NOWAIT | BUS_DMA_COHERENT);
  41769. + if (error) {
  41770. + printf("%s: bus_dmamem_map failed: %d\n", __func__, error);
  41771. + goto fail_1;
  41772. + }
  41773. +
  41774. + error = bus_dmamap_create(dma->dma_tag, size, 1, size, 0,
  41775. + BUS_DMA_NOWAIT, &dma->dma_map);
  41776. + if (error) {
  41777. + printf("%s: bus_dmamap_create failed: %d\n", __func__, error);
  41778. + goto fail_2;
  41779. + }
  41780. +
  41781. + error = bus_dmamap_load(dma->dma_tag, dma->dma_map, dma->dma_vaddr,
  41782. + size, NULL, BUS_DMA_NOWAIT);
  41783. + if (error) {
  41784. + printf("%s: bus_dmamap_load failed: %d\n", __func__, error);
  41785. + goto fail_3;
  41786. + }
  41787. +
  41788. + dma->dma_paddr = (bus_addr_t)dma->segs[0].ds_addr;
  41789. + *dma_addr = dma->dma_paddr;
  41790. + return dma->dma_vaddr;
  41791. +
  41792. +fail_3:
  41793. + bus_dmamap_destroy(dma->dma_tag, dma->dma_map);
  41794. +fail_2:
  41795. + bus_dmamem_unmap(dma->dma_tag, dma->dma_vaddr, size);
  41796. +fail_1:
  41797. + bus_dmamem_free(dma->dma_tag, dma->segs, dma->nsegs);
  41798. +fail_0:
  41799. + dma->dma_map = NULL;
  41800. + dma->dma_vaddr = NULL;
  41801. + dma->nsegs = 0;
  41802. +
  41803. + return NULL;
  41804. +}
  41805. +
  41806. +void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr)
  41807. +{
  41808. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  41809. +
  41810. + if (dma->dma_map != NULL) {
  41811. + bus_dmamap_sync(dma->dma_tag, dma->dma_map, 0, size,
  41812. + BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
  41813. + bus_dmamap_unload(dma->dma_tag, dma->dma_map);
  41814. + bus_dmamap_destroy(dma->dma_tag, dma->dma_map);
  41815. + bus_dmamem_unmap(dma->dma_tag, dma->dma_vaddr, size);
  41816. + bus_dmamem_free(dma->dma_tag, dma->segs, dma->nsegs);
  41817. + dma->dma_paddr = 0;
  41818. + dma->dma_map = NULL;
  41819. + dma->dma_vaddr = NULL;
  41820. + dma->nsegs = 0;
  41821. + }
  41822. +}
  41823. +
  41824. +void *__DWC_ALLOC(void *mem_ctx, uint32_t size)
  41825. +{
  41826. + return malloc(size, M_DEVBUF, M_WAITOK | M_ZERO);
  41827. +}
  41828. +
  41829. +void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size)
  41830. +{
  41831. + return malloc(size, M_DEVBUF, M_NOWAIT | M_ZERO);
  41832. +}
  41833. +
  41834. +void __DWC_FREE(void *mem_ctx, void *addr)
  41835. +{
  41836. + free(addr, M_DEVBUF);
  41837. +}
  41838. +
  41839. +
  41840. +#ifdef DWC_CRYPTOLIB
  41841. +/* dwc_crypto.h */
  41842. +
  41843. +void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length)
  41844. +{
  41845. + get_random_bytes(buffer, length);
  41846. +}
  41847. +
  41848. +int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out)
  41849. +{
  41850. + struct crypto_blkcipher *tfm;
  41851. + struct blkcipher_desc desc;
  41852. + struct scatterlist sgd;
  41853. + struct scatterlist sgs;
  41854. +
  41855. + tfm = crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC);
  41856. + if (tfm == NULL) {
  41857. + printk("failed to load transform for aes CBC\n");
  41858. + return -1;
  41859. + }
  41860. +
  41861. + crypto_blkcipher_setkey(tfm, key, keylen);
  41862. + crypto_blkcipher_set_iv(tfm, iv, 16);
  41863. +
  41864. + sg_init_one(&sgd, out, messagelen);
  41865. + sg_init_one(&sgs, message, messagelen);
  41866. +
  41867. + desc.tfm = tfm;
  41868. + desc.flags = 0;
  41869. +
  41870. + if (crypto_blkcipher_encrypt(&desc, &sgd, &sgs, messagelen)) {
  41871. + crypto_free_blkcipher(tfm);
  41872. + DWC_ERROR("AES CBC encryption failed");
  41873. + return -1;
  41874. + }
  41875. +
  41876. + crypto_free_blkcipher(tfm);
  41877. + return 0;
  41878. +}
  41879. +
  41880. +int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out)
  41881. +{
  41882. + struct crypto_hash *tfm;
  41883. + struct hash_desc desc;
  41884. + struct scatterlist sg;
  41885. +
  41886. + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
  41887. + if (IS_ERR(tfm)) {
  41888. + DWC_ERROR("Failed to load transform for sha256: %ld", PTR_ERR(tfm));
  41889. + return 0;
  41890. + }
  41891. + desc.tfm = tfm;
  41892. + desc.flags = 0;
  41893. +
  41894. + sg_init_one(&sg, message, len);
  41895. + crypto_hash_digest(&desc, &sg, len, out);
  41896. + crypto_free_hash(tfm);
  41897. +
  41898. + return 1;
  41899. +}
  41900. +
  41901. +int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen,
  41902. + uint8_t *key, uint32_t keylen, uint8_t *out)
  41903. +{
  41904. + struct crypto_hash *tfm;
  41905. + struct hash_desc desc;
  41906. + struct scatterlist sg;
  41907. +
  41908. + tfm = crypto_alloc_hash("hmac(sha256)", 0, CRYPTO_ALG_ASYNC);
  41909. + if (IS_ERR(tfm)) {
  41910. + DWC_ERROR("Failed to load transform for hmac(sha256): %ld", PTR_ERR(tfm));
  41911. + return 0;
  41912. + }
  41913. + desc.tfm = tfm;
  41914. + desc.flags = 0;
  41915. +
  41916. + sg_init_one(&sg, message, messagelen);
  41917. + crypto_hash_setkey(tfm, key, keylen);
  41918. + crypto_hash_digest(&desc, &sg, messagelen, out);
  41919. + crypto_free_hash(tfm);
  41920. +
  41921. + return 1;
  41922. +}
  41923. +
  41924. +#endif /* DWC_CRYPTOLIB */
  41925. +
  41926. +
  41927. +/* Byte Ordering Conversions */
  41928. +
  41929. +uint32_t DWC_CPU_TO_LE32(uint32_t *p)
  41930. +{
  41931. +#ifdef __LITTLE_ENDIAN
  41932. + return *p;
  41933. +#else
  41934. + uint8_t *u_p = (uint8_t *)p;
  41935. +
  41936. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  41937. +#endif
  41938. +}
  41939. +
  41940. +uint32_t DWC_CPU_TO_BE32(uint32_t *p)
  41941. +{
  41942. +#ifdef __BIG_ENDIAN
  41943. + return *p;
  41944. +#else
  41945. + uint8_t *u_p = (uint8_t *)p;
  41946. +
  41947. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  41948. +#endif
  41949. +}
  41950. +
  41951. +uint32_t DWC_LE32_TO_CPU(uint32_t *p)
  41952. +{
  41953. +#ifdef __LITTLE_ENDIAN
  41954. + return *p;
  41955. +#else
  41956. + uint8_t *u_p = (uint8_t *)p;
  41957. +
  41958. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  41959. +#endif
  41960. +}
  41961. +
  41962. +uint32_t DWC_BE32_TO_CPU(uint32_t *p)
  41963. +{
  41964. +#ifdef __BIG_ENDIAN
  41965. + return *p;
  41966. +#else
  41967. + uint8_t *u_p = (uint8_t *)p;
  41968. +
  41969. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  41970. +#endif
  41971. +}
  41972. +
  41973. +uint16_t DWC_CPU_TO_LE16(uint16_t *p)
  41974. +{
  41975. +#ifdef __LITTLE_ENDIAN
  41976. + return *p;
  41977. +#else
  41978. + uint8_t *u_p = (uint8_t *)p;
  41979. + return (u_p[1] | (u_p[0] << 8));
  41980. +#endif
  41981. +}
  41982. +
  41983. +uint16_t DWC_CPU_TO_BE16(uint16_t *p)
  41984. +{
  41985. +#ifdef __BIG_ENDIAN
  41986. + return *p;
  41987. +#else
  41988. + uint8_t *u_p = (uint8_t *)p;
  41989. + return (u_p[1] | (u_p[0] << 8));
  41990. +#endif
  41991. +}
  41992. +
  41993. +uint16_t DWC_LE16_TO_CPU(uint16_t *p)
  41994. +{
  41995. +#ifdef __LITTLE_ENDIAN
  41996. + return *p;
  41997. +#else
  41998. + uint8_t *u_p = (uint8_t *)p;
  41999. + return (u_p[1] | (u_p[0] << 8));
  42000. +#endif
  42001. +}
  42002. +
  42003. +uint16_t DWC_BE16_TO_CPU(uint16_t *p)
  42004. +{
  42005. +#ifdef __BIG_ENDIAN
  42006. + return *p;
  42007. +#else
  42008. + uint8_t *u_p = (uint8_t *)p;
  42009. + return (u_p[1] | (u_p[0] << 8));
  42010. +#endif
  42011. +}
  42012. +
  42013. +
  42014. +/* Registers */
  42015. +
  42016. +uint32_t DWC_READ_REG32(void *io_ctx, uint32_t volatile *reg)
  42017. +{
  42018. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  42019. + bus_size_t ior = (bus_size_t)reg;
  42020. +
  42021. + return bus_space_read_4(io->iot, io->ioh, ior);
  42022. +}
  42023. +
  42024. +#if 0
  42025. +uint64_t DWC_READ_REG64(void *io_ctx, uint64_t volatile *reg)
  42026. +{
  42027. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  42028. + bus_size_t ior = (bus_size_t)reg;
  42029. +
  42030. + return bus_space_read_8(io->iot, io->ioh, ior);
  42031. +}
  42032. +#endif
  42033. +
  42034. +void DWC_WRITE_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t value)
  42035. +{
  42036. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  42037. + bus_size_t ior = (bus_size_t)reg;
  42038. +
  42039. + bus_space_write_4(io->iot, io->ioh, ior, value);
  42040. +}
  42041. +
  42042. +#if 0
  42043. +void DWC_WRITE_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t value)
  42044. +{
  42045. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  42046. + bus_size_t ior = (bus_size_t)reg;
  42047. +
  42048. + bus_space_write_8(io->iot, io->ioh, ior, value);
  42049. +}
  42050. +#endif
  42051. +
  42052. +void DWC_MODIFY_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t clear_mask,
  42053. + uint32_t set_mask)
  42054. +{
  42055. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  42056. + bus_size_t ior = (bus_size_t)reg;
  42057. +
  42058. + bus_space_write_4(io->iot, io->ioh, ior,
  42059. + (bus_space_read_4(io->iot, io->ioh, ior) &
  42060. + ~clear_mask) | set_mask);
  42061. +}
  42062. +
  42063. +#if 0
  42064. +void DWC_MODIFY_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t clear_mask,
  42065. + uint64_t set_mask)
  42066. +{
  42067. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  42068. + bus_size_t ior = (bus_size_t)reg;
  42069. +
  42070. + bus_space_write_8(io->iot, io->ioh, ior,
  42071. + (bus_space_read_8(io->iot, io->ioh, ior) &
  42072. + ~clear_mask) | set_mask);
  42073. +}
  42074. +#endif
  42075. +
  42076. +
  42077. +/* Locking */
  42078. +
  42079. +dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void)
  42080. +{
  42081. + struct simplelock *sl = DWC_ALLOC(sizeof(*sl));
  42082. +
  42083. + if (!sl) {
  42084. + DWC_ERROR("Cannot allocate memory for spinlock");
  42085. + return NULL;
  42086. + }
  42087. +
  42088. + simple_lock_init(sl);
  42089. + return (dwc_spinlock_t *)sl;
  42090. +}
  42091. +
  42092. +void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock)
  42093. +{
  42094. + struct simplelock *sl = (struct simplelock *)lock;
  42095. +
  42096. + DWC_FREE(sl);
  42097. +}
  42098. +
  42099. +void DWC_SPINLOCK(dwc_spinlock_t *lock)
  42100. +{
  42101. + simple_lock((struct simplelock *)lock);
  42102. +}
  42103. +
  42104. +void DWC_SPINUNLOCK(dwc_spinlock_t *lock)
  42105. +{
  42106. + simple_unlock((struct simplelock *)lock);
  42107. +}
  42108. +
  42109. +void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags)
  42110. +{
  42111. + simple_lock((struct simplelock *)lock);
  42112. + *flags = splbio();
  42113. +}
  42114. +
  42115. +void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags)
  42116. +{
  42117. + splx(flags);
  42118. + simple_unlock((struct simplelock *)lock);
  42119. +}
  42120. +
  42121. +dwc_mutex_t *DWC_MUTEX_ALLOC(void)
  42122. +{
  42123. + dwc_mutex_t *mutex = DWC_ALLOC(sizeof(struct lock));
  42124. +
  42125. + if (!mutex) {
  42126. + DWC_ERROR("Cannot allocate memory for mutex");
  42127. + return NULL;
  42128. + }
  42129. +
  42130. + lockinit((struct lock *)mutex, 0, "dw3mtx", 0, 0);
  42131. + return mutex;
  42132. +}
  42133. +
  42134. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  42135. +#else
  42136. +void DWC_MUTEX_FREE(dwc_mutex_t *mutex)
  42137. +{
  42138. + DWC_FREE(mutex);
  42139. +}
  42140. +#endif
  42141. +
  42142. +void DWC_MUTEX_LOCK(dwc_mutex_t *mutex)
  42143. +{
  42144. + lockmgr((struct lock *)mutex, LK_EXCLUSIVE, NULL);
  42145. +}
  42146. +
  42147. +int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex)
  42148. +{
  42149. + int status;
  42150. +
  42151. + status = lockmgr((struct lock *)mutex, LK_EXCLUSIVE | LK_NOWAIT, NULL);
  42152. + return status == 0;
  42153. +}
  42154. +
  42155. +void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex)
  42156. +{
  42157. + lockmgr((struct lock *)mutex, LK_RELEASE, NULL);
  42158. +}
  42159. +
  42160. +
  42161. +/* Timing */
  42162. +
  42163. +void DWC_UDELAY(uint32_t usecs)
  42164. +{
  42165. + DELAY(usecs);
  42166. +}
  42167. +
  42168. +void DWC_MDELAY(uint32_t msecs)
  42169. +{
  42170. + do {
  42171. + DELAY(1000);
  42172. + } while (--msecs);
  42173. +}
  42174. +
  42175. +void DWC_MSLEEP(uint32_t msecs)
  42176. +{
  42177. + struct timeval tv;
  42178. +
  42179. + tv.tv_sec = msecs / 1000;
  42180. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  42181. + tsleep(&tv, 0, "dw3slp", tvtohz(&tv));
  42182. +}
  42183. +
  42184. +uint32_t DWC_TIME(void)
  42185. +{
  42186. + struct timeval tv;
  42187. +
  42188. + microuptime(&tv); // or getmicrouptime? (less precise, but faster)
  42189. + return tv.tv_sec * 1000 + tv.tv_usec / 1000;
  42190. +}
  42191. +
  42192. +
  42193. +/* Timers */
  42194. +
  42195. +struct dwc_timer {
  42196. + struct callout t;
  42197. + char *name;
  42198. + dwc_spinlock_t *lock;
  42199. + dwc_timer_callback_t cb;
  42200. + void *data;
  42201. +};
  42202. +
  42203. +dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data)
  42204. +{
  42205. + dwc_timer_t *t = DWC_ALLOC(sizeof(*t));
  42206. +
  42207. + if (!t) {
  42208. + DWC_ERROR("Cannot allocate memory for timer");
  42209. + return NULL;
  42210. + }
  42211. +
  42212. + callout_init(&t->t);
  42213. +
  42214. + t->name = DWC_STRDUP(name);
  42215. + if (!t->name) {
  42216. + DWC_ERROR("Cannot allocate memory for timer->name");
  42217. + goto no_name;
  42218. + }
  42219. +
  42220. + t->lock = DWC_SPINLOCK_ALLOC();
  42221. + if (!t->lock) {
  42222. + DWC_ERROR("Cannot allocate memory for timer->lock");
  42223. + goto no_lock;
  42224. + }
  42225. +
  42226. + t->cb = cb;
  42227. + t->data = data;
  42228. +
  42229. + return t;
  42230. +
  42231. + no_lock:
  42232. + DWC_FREE(t->name);
  42233. + no_name:
  42234. + DWC_FREE(t);
  42235. +
  42236. + return NULL;
  42237. +}
  42238. +
  42239. +void DWC_TIMER_FREE(dwc_timer_t *timer)
  42240. +{
  42241. + callout_stop(&timer->t);
  42242. + DWC_SPINLOCK_FREE(timer->lock);
  42243. + DWC_FREE(timer->name);
  42244. + DWC_FREE(timer);
  42245. +}
  42246. +
  42247. +void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time)
  42248. +{
  42249. + struct timeval tv;
  42250. +
  42251. + tv.tv_sec = time / 1000;
  42252. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  42253. + callout_reset(&timer->t, tvtohz(&tv), timer->cb, timer->data);
  42254. +}
  42255. +
  42256. +void DWC_TIMER_CANCEL(dwc_timer_t *timer)
  42257. +{
  42258. + callout_stop(&timer->t);
  42259. +}
  42260. +
  42261. +
  42262. +/* Wait Queues */
  42263. +
  42264. +struct dwc_waitq {
  42265. + struct simplelock lock;
  42266. + int abort;
  42267. +};
  42268. +
  42269. +dwc_waitq_t *DWC_WAITQ_ALLOC(void)
  42270. +{
  42271. + dwc_waitq_t *wq = DWC_ALLOC(sizeof(*wq));
  42272. +
  42273. + if (!wq) {
  42274. + DWC_ERROR("Cannot allocate memory for waitqueue");
  42275. + return NULL;
  42276. + }
  42277. +
  42278. + simple_lock_init(&wq->lock);
  42279. + wq->abort = 0;
  42280. +
  42281. + return wq;
  42282. +}
  42283. +
  42284. +void DWC_WAITQ_FREE(dwc_waitq_t *wq)
  42285. +{
  42286. + DWC_FREE(wq);
  42287. +}
  42288. +
  42289. +int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data)
  42290. +{
  42291. + int ipl;
  42292. + int result = 0;
  42293. +
  42294. + simple_lock(&wq->lock);
  42295. + ipl = splbio();
  42296. +
  42297. + /* Skip the sleep if already aborted or triggered */
  42298. + if (!wq->abort && !cond(data)) {
  42299. + splx(ipl);
  42300. + result = ltsleep(wq, PCATCH, "dw3wat", 0, &wq->lock); // infinite timeout
  42301. + ipl = splbio();
  42302. + }
  42303. +
  42304. + if (result == 0) { // awoken
  42305. + if (wq->abort) {
  42306. + wq->abort = 0;
  42307. + result = -DWC_E_ABORT;
  42308. + } else {
  42309. + result = 0;
  42310. + }
  42311. +
  42312. + splx(ipl);
  42313. + simple_unlock(&wq->lock);
  42314. + } else {
  42315. + wq->abort = 0;
  42316. + splx(ipl);
  42317. + simple_unlock(&wq->lock);
  42318. +
  42319. + if (result == ERESTART) { // signaled - restart
  42320. + result = -DWC_E_RESTART;
  42321. + } else { // signaled - must be EINTR
  42322. + result = -DWC_E_ABORT;
  42323. + }
  42324. + }
  42325. +
  42326. + return result;
  42327. +}
  42328. +
  42329. +int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  42330. + void *data, int32_t msecs)
  42331. +{
  42332. + struct timeval tv, tv1, tv2;
  42333. + int ipl;
  42334. + int result = 0;
  42335. +
  42336. + tv.tv_sec = msecs / 1000;
  42337. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  42338. +
  42339. + simple_lock(&wq->lock);
  42340. + ipl = splbio();
  42341. +
  42342. + /* Skip the sleep if already aborted or triggered */
  42343. + if (!wq->abort && !cond(data)) {
  42344. + splx(ipl);
  42345. + getmicrouptime(&tv1);
  42346. + result = ltsleep(wq, PCATCH, "dw3wto", tvtohz(&tv), &wq->lock);
  42347. + getmicrouptime(&tv2);
  42348. + ipl = splbio();
  42349. + }
  42350. +
  42351. + if (result == 0) { // awoken
  42352. + if (wq->abort) {
  42353. + wq->abort = 0;
  42354. + splx(ipl);
  42355. + simple_unlock(&wq->lock);
  42356. + result = -DWC_E_ABORT;
  42357. + } else {
  42358. + splx(ipl);
  42359. + simple_unlock(&wq->lock);
  42360. +
  42361. + tv2.tv_usec -= tv1.tv_usec;
  42362. + if (tv2.tv_usec < 0) {
  42363. + tv2.tv_usec += 1000000;
  42364. + tv2.tv_sec--;
  42365. + }
  42366. +
  42367. + tv2.tv_sec -= tv1.tv_sec;
  42368. + result = tv2.tv_sec * 1000 + tv2.tv_usec / 1000;
  42369. + result = msecs - result;
  42370. + if (result <= 0)
  42371. + result = 1;
  42372. + }
  42373. + } else {
  42374. + wq->abort = 0;
  42375. + splx(ipl);
  42376. + simple_unlock(&wq->lock);
  42377. +
  42378. + if (result == ERESTART) { // signaled - restart
  42379. + result = -DWC_E_RESTART;
  42380. +
  42381. + } else if (result == EINTR) { // signaled - interrupt
  42382. + result = -DWC_E_ABORT;
  42383. +
  42384. + } else { // timed out
  42385. + result = -DWC_E_TIMEOUT;
  42386. + }
  42387. + }
  42388. +
  42389. + return result;
  42390. +}
  42391. +
  42392. +void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq)
  42393. +{
  42394. + wakeup(wq);
  42395. +}
  42396. +
  42397. +void DWC_WAITQ_ABORT(dwc_waitq_t *wq)
  42398. +{
  42399. + int ipl;
  42400. +
  42401. + simple_lock(&wq->lock);
  42402. + ipl = splbio();
  42403. + wq->abort = 1;
  42404. + wakeup(wq);
  42405. + splx(ipl);
  42406. + simple_unlock(&wq->lock);
  42407. +}
  42408. +
  42409. +
  42410. +/* Threading */
  42411. +
  42412. +struct dwc_thread {
  42413. + struct proc *proc;
  42414. + int abort;
  42415. +};
  42416. +
  42417. +dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data)
  42418. +{
  42419. + int retval;
  42420. + dwc_thread_t *thread = DWC_ALLOC(sizeof(*thread));
  42421. +
  42422. + if (!thread) {
  42423. + return NULL;
  42424. + }
  42425. +
  42426. + thread->abort = 0;
  42427. + retval = kthread_create1((void (*)(void *))func, data, &thread->proc,
  42428. + "%s", name);
  42429. + if (retval) {
  42430. + DWC_FREE(thread);
  42431. + return NULL;
  42432. + }
  42433. +
  42434. + return thread;
  42435. +}
  42436. +
  42437. +int DWC_THREAD_STOP(dwc_thread_t *thread)
  42438. +{
  42439. + int retval;
  42440. +
  42441. + thread->abort = 1;
  42442. + retval = tsleep(&thread->abort, 0, "dw3stp", 60 * hz);
  42443. +
  42444. + if (retval == 0) {
  42445. + /* DWC_THREAD_EXIT() will free the thread struct */
  42446. + return 0;
  42447. + }
  42448. +
  42449. + /* NOTE: We leak the thread struct if thread doesn't die */
  42450. +
  42451. + if (retval == EWOULDBLOCK) {
  42452. + return -DWC_E_TIMEOUT;
  42453. + }
  42454. +
  42455. + return -DWC_E_UNKNOWN;
  42456. +}
  42457. +
  42458. +dwc_bool_t DWC_THREAD_SHOULD_STOP(dwc_thread_t *thread)
  42459. +{
  42460. + return thread->abort;
  42461. +}
  42462. +
  42463. +void DWC_THREAD_EXIT(dwc_thread_t *thread)
  42464. +{
  42465. + wakeup(&thread->abort);
  42466. + DWC_FREE(thread);
  42467. + kthread_exit(0);
  42468. +}
  42469. +
  42470. +/* tasklets
  42471. + - Runs in interrupt context (cannot sleep)
  42472. + - Each tasklet runs on a single CPU
  42473. + - Different tasklets can be running simultaneously on different CPUs
  42474. + [ On NetBSD there is no corresponding mechanism, drivers don't have bottom-
  42475. + halves. So we just call the callback directly from DWC_TASK_SCHEDULE() ]
  42476. + */
  42477. +struct dwc_tasklet {
  42478. + dwc_tasklet_callback_t cb;
  42479. + void *data;
  42480. +};
  42481. +
  42482. +static void tasklet_callback(void *data)
  42483. +{
  42484. + dwc_tasklet_t *task = (dwc_tasklet_t *)data;
  42485. +
  42486. + task->cb(task->data);
  42487. +}
  42488. +
  42489. +dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data)
  42490. +{
  42491. + dwc_tasklet_t *task = DWC_ALLOC(sizeof(*task));
  42492. +
  42493. + if (task) {
  42494. + task->cb = cb;
  42495. + task->data = data;
  42496. + } else {
  42497. + DWC_ERROR("Cannot allocate memory for tasklet");
  42498. + }
  42499. +
  42500. + return task;
  42501. +}
  42502. +
  42503. +void DWC_TASK_FREE(dwc_tasklet_t *task)
  42504. +{
  42505. + DWC_FREE(task);
  42506. +}
  42507. +
  42508. +void DWC_TASK_SCHEDULE(dwc_tasklet_t *task)
  42509. +{
  42510. + tasklet_callback(task);
  42511. +}
  42512. +
  42513. +
  42514. +/* workqueues
  42515. + - Runs in process context (can sleep)
  42516. + */
  42517. +typedef struct work_container {
  42518. + dwc_work_callback_t cb;
  42519. + void *data;
  42520. + dwc_workq_t *wq;
  42521. + char *name;
  42522. + int hz;
  42523. + struct work task;
  42524. +} work_container_t;
  42525. +
  42526. +struct dwc_workq {
  42527. + struct workqueue *taskq;
  42528. + dwc_spinlock_t *lock;
  42529. + dwc_waitq_t *waitq;
  42530. + int pending;
  42531. + struct work_container *container;
  42532. +};
  42533. +
  42534. +static void do_work(struct work *task, void *data)
  42535. +{
  42536. + dwc_workq_t *wq = (dwc_workq_t *)data;
  42537. + work_container_t *container = wq->container;
  42538. + dwc_irqflags_t flags;
  42539. +
  42540. + if (container->hz) {
  42541. + tsleep(container, 0, "dw3wrk", container->hz);
  42542. + }
  42543. +
  42544. + container->cb(container->data);
  42545. + DWC_DEBUG("Work done: %s, container=%p", container->name, container);
  42546. +
  42547. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  42548. + if (container->name)
  42549. + DWC_FREE(container->name);
  42550. + DWC_FREE(container);
  42551. + wq->pending--;
  42552. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  42553. + DWC_WAITQ_TRIGGER(wq->waitq);
  42554. +}
  42555. +
  42556. +static int work_done(void *data)
  42557. +{
  42558. + dwc_workq_t *workq = (dwc_workq_t *)data;
  42559. +
  42560. + return workq->pending == 0;
  42561. +}
  42562. +
  42563. +int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout)
  42564. +{
  42565. + return DWC_WAITQ_WAIT_TIMEOUT(workq->waitq, work_done, workq, timeout);
  42566. +}
  42567. +
  42568. +dwc_workq_t *DWC_WORKQ_ALLOC(char *name)
  42569. +{
  42570. + int result;
  42571. + dwc_workq_t *wq = DWC_ALLOC(sizeof(*wq));
  42572. +
  42573. + if (!wq) {
  42574. + DWC_ERROR("Cannot allocate memory for workqueue");
  42575. + return NULL;
  42576. + }
  42577. +
  42578. + result = workqueue_create(&wq->taskq, name, do_work, wq, 0 /*PWAIT*/,
  42579. + IPL_BIO, 0);
  42580. + if (result) {
  42581. + DWC_ERROR("Cannot create workqueue");
  42582. + goto no_taskq;
  42583. + }
  42584. +
  42585. + wq->pending = 0;
  42586. +
  42587. + wq->lock = DWC_SPINLOCK_ALLOC();
  42588. + if (!wq->lock) {
  42589. + DWC_ERROR("Cannot allocate memory for spinlock");
  42590. + goto no_lock;
  42591. + }
  42592. +
  42593. + wq->waitq = DWC_WAITQ_ALLOC();
  42594. + if (!wq->waitq) {
  42595. + DWC_ERROR("Cannot allocate memory for waitqueue");
  42596. + goto no_waitq;
  42597. + }
  42598. +
  42599. + return wq;
  42600. +
  42601. + no_waitq:
  42602. + DWC_SPINLOCK_FREE(wq->lock);
  42603. + no_lock:
  42604. + workqueue_destroy(wq->taskq);
  42605. + no_taskq:
  42606. + DWC_FREE(wq);
  42607. +
  42608. + return NULL;
  42609. +}
  42610. +
  42611. +void DWC_WORKQ_FREE(dwc_workq_t *wq)
  42612. +{
  42613. +#ifdef DEBUG
  42614. + dwc_irqflags_t flags;
  42615. +
  42616. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  42617. +
  42618. + if (wq->pending != 0) {
  42619. + struct work_container *container = wq->container;
  42620. +
  42621. + DWC_ERROR("Destroying work queue with pending work");
  42622. +
  42623. + if (container && container->name) {
  42624. + DWC_ERROR("Work %s still pending", container->name);
  42625. + }
  42626. + }
  42627. +
  42628. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  42629. +#endif
  42630. + DWC_WAITQ_FREE(wq->waitq);
  42631. + DWC_SPINLOCK_FREE(wq->lock);
  42632. + workqueue_destroy(wq->taskq);
  42633. + DWC_FREE(wq);
  42634. +}
  42635. +
  42636. +void DWC_WORKQ_SCHEDULE(dwc_workq_t *wq, dwc_work_callback_t cb, void *data,
  42637. + char *format, ...)
  42638. +{
  42639. + dwc_irqflags_t flags;
  42640. + work_container_t *container;
  42641. + static char name[128];
  42642. + va_list args;
  42643. +
  42644. + va_start(args, format);
  42645. + DWC_VSNPRINTF(name, 128, format, args);
  42646. + va_end(args);
  42647. +
  42648. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  42649. + wq->pending++;
  42650. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  42651. + DWC_WAITQ_TRIGGER(wq->waitq);
  42652. +
  42653. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  42654. + if (!container) {
  42655. + DWC_ERROR("Cannot allocate memory for container");
  42656. + return;
  42657. + }
  42658. +
  42659. + container->name = DWC_STRDUP(name);
  42660. + if (!container->name) {
  42661. + DWC_ERROR("Cannot allocate memory for container->name");
  42662. + DWC_FREE(container);
  42663. + return;
  42664. + }
  42665. +
  42666. + container->cb = cb;
  42667. + container->data = data;
  42668. + container->wq = wq;
  42669. + container->hz = 0;
  42670. + wq->container = container;
  42671. +
  42672. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  42673. + workqueue_enqueue(wq->taskq, &container->task);
  42674. +}
  42675. +
  42676. +void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *wq, dwc_work_callback_t cb,
  42677. + void *data, uint32_t time, char *format, ...)
  42678. +{
  42679. + dwc_irqflags_t flags;
  42680. + work_container_t *container;
  42681. + static char name[128];
  42682. + struct timeval tv;
  42683. + va_list args;
  42684. +
  42685. + va_start(args, format);
  42686. + DWC_VSNPRINTF(name, 128, format, args);
  42687. + va_end(args);
  42688. +
  42689. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  42690. + wq->pending++;
  42691. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  42692. + DWC_WAITQ_TRIGGER(wq->waitq);
  42693. +
  42694. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  42695. + if (!container) {
  42696. + DWC_ERROR("Cannot allocate memory for container");
  42697. + return;
  42698. + }
  42699. +
  42700. + container->name = DWC_STRDUP(name);
  42701. + if (!container->name) {
  42702. + DWC_ERROR("Cannot allocate memory for container->name");
  42703. + DWC_FREE(container);
  42704. + return;
  42705. + }
  42706. +
  42707. + container->cb = cb;
  42708. + container->data = data;
  42709. + container->wq = wq;
  42710. + tv.tv_sec = time / 1000;
  42711. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  42712. + container->hz = tvtohz(&tv);
  42713. + wq->container = container;
  42714. +
  42715. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  42716. + workqueue_enqueue(wq->taskq, &container->task);
  42717. +}
  42718. +
  42719. +int DWC_WORKQ_PENDING(dwc_workq_t *wq)
  42720. +{
  42721. + return wq->pending;
  42722. +}
  42723. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_common_port/dwc_crypto.c linux-3.13.3/drivers/usb/host/dwc_common_port/dwc_crypto.c
  42724. --- linux-3.13.3.orig/drivers/usb/host/dwc_common_port/dwc_crypto.c 1970-01-01 01:00:00.000000000 +0100
  42725. +++ linux-3.13.3/drivers/usb/host/dwc_common_port/dwc_crypto.c 2014-02-17 22:41:01.000000000 +0100
  42726. @@ -0,0 +1,308 @@
  42727. +/* =========================================================================
  42728. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_crypto.c $
  42729. + * $Revision: #5 $
  42730. + * $Date: 2010/09/28 $
  42731. + * $Change: 1596182 $
  42732. + *
  42733. + * Synopsys Portability Library Software and documentation
  42734. + * (hereinafter, "Software") is an Unsupported proprietary work of
  42735. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  42736. + * between Synopsys and you.
  42737. + *
  42738. + * The Software IS NOT an item of Licensed Software or Licensed Product
  42739. + * under any End User Software License Agreement or Agreement for
  42740. + * Licensed Product with Synopsys or any supplement thereto. You are
  42741. + * permitted to use and redistribute this Software in source and binary
  42742. + * forms, with or without modification, provided that redistributions
  42743. + * of source code must retain this notice. You may not view, use,
  42744. + * disclose, copy or distribute this file or any information contained
  42745. + * herein except pursuant to this license grant from Synopsys. If you
  42746. + * do not agree with this notice, including the disclaimer below, then
  42747. + * you are not authorized to use the Software.
  42748. + *
  42749. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  42750. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  42751. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  42752. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  42753. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  42754. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  42755. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  42756. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  42757. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  42758. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  42759. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  42760. + * DAMAGE.
  42761. + * ========================================================================= */
  42762. +
  42763. +/** @file
  42764. + * This file contains the WUSB cryptographic routines.
  42765. + */
  42766. +
  42767. +#ifdef DWC_CRYPTOLIB
  42768. +
  42769. +#include "dwc_crypto.h"
  42770. +#include "usb.h"
  42771. +
  42772. +#ifdef DEBUG
  42773. +static inline void dump_bytes(char *name, uint8_t *bytes, int len)
  42774. +{
  42775. + int i;
  42776. + DWC_PRINTF("%s: ", name);
  42777. + for (i=0; i<len; i++) {
  42778. + DWC_PRINTF("%02x ", bytes[i]);
  42779. + }
  42780. + DWC_PRINTF("\n");
  42781. +}
  42782. +#else
  42783. +#define dump_bytes(x...)
  42784. +#endif
  42785. +
  42786. +/* Display a block */
  42787. +void show_block(const u8 *blk, const char *prefix, const char *suffix, int a)
  42788. +{
  42789. +#ifdef DWC_DEBUG_CRYPTO
  42790. + int i, blksize = 16;
  42791. +
  42792. + DWC_DEBUG("%s", prefix);
  42793. +
  42794. + if (suffix == NULL) {
  42795. + suffix = "\n";
  42796. + blksize = a;
  42797. + }
  42798. +
  42799. + for (i = 0; i < blksize; i++)
  42800. + DWC_PRINT("%02x%s", *blk++, ((i & 3) == 3) ? " " : " ");
  42801. + DWC_PRINT(suffix);
  42802. +#endif
  42803. +}
  42804. +
  42805. +/**
  42806. + * Encrypts an array of bytes using the AES encryption engine.
  42807. + * If <code>dst</code> == <code>src</code>, then the bytes will be encrypted
  42808. + * in-place.
  42809. + *
  42810. + * @return 0 on success, negative error code on error.
  42811. + */
  42812. +int dwc_wusb_aes_encrypt(u8 *src, u8 *key, u8 *dst)
  42813. +{
  42814. + u8 block_t[16];
  42815. + DWC_MEMSET(block_t, 0, 16);
  42816. +
  42817. + return DWC_AES_CBC(src, 16, key, 16, block_t, dst);
  42818. +}
  42819. +
  42820. +/**
  42821. + * The CCM-MAC-FUNCTION described in section 6.5 of the WUSB spec.
  42822. + * This function takes a data string and returns the encrypted CBC
  42823. + * Counter-mode MIC.
  42824. + *
  42825. + * @param key The 128-bit symmetric key.
  42826. + * @param nonce The CCM nonce.
  42827. + * @param label The unique 14-byte ASCII text label.
  42828. + * @param bytes The byte array to be encrypted.
  42829. + * @param len Length of the byte array.
  42830. + * @param result Byte array to receive the 8-byte encrypted MIC.
  42831. + */
  42832. +void dwc_wusb_cmf(u8 *key, u8 *nonce,
  42833. + char *label, u8 *bytes, int len, u8 *result)
  42834. +{
  42835. + u8 block_m[16];
  42836. + u8 block_x[16];
  42837. + u8 block_t[8];
  42838. + int idx, blkNum;
  42839. + u16 la = (u16)(len + 14);
  42840. +
  42841. + /* Set the AES-128 key */
  42842. + //dwc_aes_setkey(tfm, key, 16);
  42843. +
  42844. + /* Fill block B0 from flags = 0x59, N, and l(m) = 0 */
  42845. + block_m[0] = 0x59;
  42846. + for (idx = 0; idx < 13; idx++)
  42847. + block_m[idx + 1] = nonce[idx];
  42848. + block_m[14] = 0;
  42849. + block_m[15] = 0;
  42850. +
  42851. + /* Produce the CBC IV */
  42852. + dwc_wusb_aes_encrypt(block_m, key, block_x);
  42853. + show_block(block_m, "CBC IV in: ", "\n", 0);
  42854. + show_block(block_x, "CBC IV out:", "\n", 0);
  42855. +
  42856. + /* Fill block B1 from l(a) = Blen + 14, and A */
  42857. + block_x[0] ^= (u8)(la >> 8);
  42858. + block_x[1] ^= (u8)la;
  42859. + for (idx = 0; idx < 14; idx++)
  42860. + block_x[idx + 2] ^= label[idx];
  42861. + show_block(block_x, "After xor: ", "b1\n", 16);
  42862. +
  42863. + dwc_wusb_aes_encrypt(block_x, key, block_x);
  42864. + show_block(block_x, "After AES: ", "b1\n", 16);
  42865. +
  42866. + idx = 0;
  42867. + blkNum = 0;
  42868. +
  42869. + /* Fill remaining blocks with B */
  42870. + while (len-- > 0) {
  42871. + block_x[idx] ^= *bytes++;
  42872. + if (++idx >= 16) {
  42873. + idx = 0;
  42874. + show_block(block_x, "After xor: ", "\n", blkNum);
  42875. + dwc_wusb_aes_encrypt(block_x, key, block_x);
  42876. + show_block(block_x, "After AES: ", "\n", blkNum);
  42877. + blkNum++;
  42878. + }
  42879. + }
  42880. +
  42881. + /* Handle partial last block */
  42882. + if (idx > 0) {
  42883. + show_block(block_x, "After xor: ", "\n", blkNum);
  42884. + dwc_wusb_aes_encrypt(block_x, key, block_x);
  42885. + show_block(block_x, "After AES: ", "\n", blkNum);
  42886. + }
  42887. +
  42888. + /* Save the MIC tag */
  42889. + DWC_MEMCPY(block_t, block_x, 8);
  42890. + show_block(block_t, "MIC tag : ", NULL, 8);
  42891. +
  42892. + /* Fill block A0 from flags = 0x01, N, and counter = 0 */
  42893. + block_m[0] = 0x01;
  42894. + block_m[14] = 0;
  42895. + block_m[15] = 0;
  42896. +
  42897. + /* Encrypt the counter */
  42898. + dwc_wusb_aes_encrypt(block_m, key, block_x);
  42899. + show_block(block_x, "CTR[MIC] : ", NULL, 8);
  42900. +
  42901. + /* XOR with MIC tag */
  42902. + for (idx = 0; idx < 8; idx++) {
  42903. + block_t[idx] ^= block_x[idx];
  42904. + }
  42905. +
  42906. + /* Return result to caller */
  42907. + DWC_MEMCPY(result, block_t, 8);
  42908. + show_block(result, "CCM-MIC : ", NULL, 8);
  42909. +
  42910. +}
  42911. +
  42912. +/**
  42913. + * The PRF function described in section 6.5 of the WUSB spec. This function
  42914. + * concatenates MIC values returned from dwc_cmf() to create a value of
  42915. + * the requested length.
  42916. + *
  42917. + * @param prf_len Length of the PRF function in bits (64, 128, or 256).
  42918. + * @param key, nonce, label, bytes, len Same as for dwc_cmf().
  42919. + * @param result Byte array to receive the result.
  42920. + */
  42921. +void dwc_wusb_prf(int prf_len, u8 *key,
  42922. + u8 *nonce, char *label, u8 *bytes, int len, u8 *result)
  42923. +{
  42924. + int i;
  42925. +
  42926. + nonce[0] = 0;
  42927. + for (i = 0; i < prf_len >> 6; i++, nonce[0]++) {
  42928. + dwc_wusb_cmf(key, nonce, label, bytes, len, result);
  42929. + result += 8;
  42930. + }
  42931. +}
  42932. +
  42933. +/**
  42934. + * Fills in CCM Nonce per the WUSB spec.
  42935. + *
  42936. + * @param[in] haddr Host address.
  42937. + * @param[in] daddr Device address.
  42938. + * @param[in] tkid Session Key(PTK) identifier.
  42939. + * @param[out] nonce Pointer to where the CCM Nonce output is to be written.
  42940. + */
  42941. +void dwc_wusb_fill_ccm_nonce(uint16_t haddr, uint16_t daddr, uint8_t *tkid,
  42942. + uint8_t *nonce)
  42943. +{
  42944. +
  42945. + DWC_DEBUG("%s %x %x\n", __func__, daddr, haddr);
  42946. +
  42947. + DWC_MEMSET(&nonce[0], 0, 16);
  42948. +
  42949. + DWC_MEMCPY(&nonce[6], tkid, 3);
  42950. + nonce[9] = daddr & 0xFF;
  42951. + nonce[10] = (daddr >> 8) & 0xFF;
  42952. + nonce[11] = haddr & 0xFF;
  42953. + nonce[12] = (haddr >> 8) & 0xFF;
  42954. +
  42955. + dump_bytes("CCM nonce", nonce, 16);
  42956. +}
  42957. +
  42958. +/**
  42959. + * Generates a 16-byte cryptographic-grade random number for the Host/Device
  42960. + * Nonce.
  42961. + */
  42962. +void dwc_wusb_gen_nonce(uint16_t addr, uint8_t *nonce)
  42963. +{
  42964. + uint8_t inonce[16];
  42965. + uint32_t temp[4];
  42966. +
  42967. + /* Fill in the Nonce */
  42968. + DWC_MEMSET(&inonce[0], 0, sizeof(inonce));
  42969. + inonce[9] = addr & 0xFF;
  42970. + inonce[10] = (addr >> 8) & 0xFF;
  42971. + inonce[11] = inonce[9];
  42972. + inonce[12] = inonce[10];
  42973. +
  42974. + /* Collect "randomness samples" */
  42975. + DWC_RANDOM_BYTES((uint8_t *)temp, 16);
  42976. +
  42977. + dwc_wusb_prf_128((uint8_t *)temp, nonce,
  42978. + "Random Numbers", (uint8_t *)temp, sizeof(temp),
  42979. + nonce);
  42980. +}
  42981. +
  42982. +/**
  42983. + * Generates the Session Key (PTK) and Key Confirmation Key (KCK) per the
  42984. + * WUSB spec.
  42985. + *
  42986. + * @param[in] ccm_nonce Pointer to CCM Nonce.
  42987. + * @param[in] mk Master Key to derive the session from
  42988. + * @param[in] hnonce Pointer to Host Nonce.
  42989. + * @param[in] dnonce Pointer to Device Nonce.
  42990. + * @param[out] kck Pointer to where the KCK output is to be written.
  42991. + * @param[out] ptk Pointer to where the PTK output is to be written.
  42992. + */
  42993. +void dwc_wusb_gen_key(uint8_t *ccm_nonce, uint8_t *mk, uint8_t *hnonce,
  42994. + uint8_t *dnonce, uint8_t *kck, uint8_t *ptk)
  42995. +{
  42996. + uint8_t idata[32];
  42997. + uint8_t odata[32];
  42998. +
  42999. + dump_bytes("ck", mk, 16);
  43000. + dump_bytes("hnonce", hnonce, 16);
  43001. + dump_bytes("dnonce", dnonce, 16);
  43002. +
  43003. + /* The data is the HNonce and DNonce concatenated */
  43004. + DWC_MEMCPY(&idata[0], hnonce, 16);
  43005. + DWC_MEMCPY(&idata[16], dnonce, 16);
  43006. +
  43007. + dwc_wusb_prf_256(mk, ccm_nonce, "Pair-wise keys", idata, 32, odata);
  43008. +
  43009. + /* Low 16 bytes of the result is the KCK, high 16 is the PTK */
  43010. + DWC_MEMCPY(kck, &odata[0], 16);
  43011. + DWC_MEMCPY(ptk, &odata[16], 16);
  43012. +
  43013. + dump_bytes("kck", kck, 16);
  43014. + dump_bytes("ptk", ptk, 16);
  43015. +}
  43016. +
  43017. +/**
  43018. + * Generates the Message Integrity Code over the Handshake data per the
  43019. + * WUSB spec.
  43020. + *
  43021. + * @param ccm_nonce Pointer to CCM Nonce.
  43022. + * @param kck Pointer to Key Confirmation Key.
  43023. + * @param data Pointer to Handshake data to be checked.
  43024. + * @param mic Pointer to where the MIC output is to be written.
  43025. + */
  43026. +void dwc_wusb_gen_mic(uint8_t *ccm_nonce, uint8_t *kck,
  43027. + uint8_t *data, uint8_t *mic)
  43028. +{
  43029. +
  43030. + dwc_wusb_prf_64(kck, ccm_nonce, "out-of-bandMIC",
  43031. + data, WUSB_HANDSHAKE_LEN_FOR_MIC, mic);
  43032. +}
  43033. +
  43034. +#endif /* DWC_CRYPTOLIB */
  43035. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_common_port/dwc_crypto.h linux-3.13.3/drivers/usb/host/dwc_common_port/dwc_crypto.h
  43036. --- linux-3.13.3.orig/drivers/usb/host/dwc_common_port/dwc_crypto.h 1970-01-01 01:00:00.000000000 +0100
  43037. +++ linux-3.13.3/drivers/usb/host/dwc_common_port/dwc_crypto.h 2014-02-17 22:41:01.000000000 +0100
  43038. @@ -0,0 +1,111 @@
  43039. +/* =========================================================================
  43040. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_crypto.h $
  43041. + * $Revision: #3 $
  43042. + * $Date: 2010/09/28 $
  43043. + * $Change: 1596182 $
  43044. + *
  43045. + * Synopsys Portability Library Software and documentation
  43046. + * (hereinafter, "Software") is an Unsupported proprietary work of
  43047. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  43048. + * between Synopsys and you.
  43049. + *
  43050. + * The Software IS NOT an item of Licensed Software or Licensed Product
  43051. + * under any End User Software License Agreement or Agreement for
  43052. + * Licensed Product with Synopsys or any supplement thereto. You are
  43053. + * permitted to use and redistribute this Software in source and binary
  43054. + * forms, with or without modification, provided that redistributions
  43055. + * of source code must retain this notice. You may not view, use,
  43056. + * disclose, copy or distribute this file or any information contained
  43057. + * herein except pursuant to this license grant from Synopsys. If you
  43058. + * do not agree with this notice, including the disclaimer below, then
  43059. + * you are not authorized to use the Software.
  43060. + *
  43061. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  43062. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  43063. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  43064. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  43065. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  43066. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  43067. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  43068. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  43069. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  43070. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  43071. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  43072. + * DAMAGE.
  43073. + * ========================================================================= */
  43074. +
  43075. +#ifndef _DWC_CRYPTO_H_
  43076. +#define _DWC_CRYPTO_H_
  43077. +
  43078. +#ifdef __cplusplus
  43079. +extern "C" {
  43080. +#endif
  43081. +
  43082. +/** @file
  43083. + *
  43084. + * This file contains declarations for the WUSB Cryptographic routines as
  43085. + * defined in the WUSB spec. They are only to be used internally by the DWC UWB
  43086. + * modules.
  43087. + */
  43088. +
  43089. +#include "dwc_os.h"
  43090. +
  43091. +int dwc_wusb_aes_encrypt(u8 *src, u8 *key, u8 *dst);
  43092. +
  43093. +void dwc_wusb_cmf(u8 *key, u8 *nonce,
  43094. + char *label, u8 *bytes, int len, u8 *result);
  43095. +void dwc_wusb_prf(int prf_len, u8 *key,
  43096. + u8 *nonce, char *label, u8 *bytes, int len, u8 *result);
  43097. +
  43098. +/**
  43099. + * The PRF-64 function described in section 6.5 of the WUSB spec.
  43100. + *
  43101. + * @param key, nonce, label, bytes, len, result Same as for dwc_prf().
  43102. + */
  43103. +static inline void dwc_wusb_prf_64(u8 *key, u8 *nonce,
  43104. + char *label, u8 *bytes, int len, u8 *result)
  43105. +{
  43106. + dwc_wusb_prf(64, key, nonce, label, bytes, len, result);
  43107. +}
  43108. +
  43109. +/**
  43110. + * The PRF-128 function described in section 6.5 of the WUSB spec.
  43111. + *
  43112. + * @param key, nonce, label, bytes, len, result Same as for dwc_prf().
  43113. + */
  43114. +static inline void dwc_wusb_prf_128(u8 *key, u8 *nonce,
  43115. + char *label, u8 *bytes, int len, u8 *result)
  43116. +{
  43117. + dwc_wusb_prf(128, key, nonce, label, bytes, len, result);
  43118. +}
  43119. +
  43120. +/**
  43121. + * The PRF-256 function described in section 6.5 of the WUSB spec.
  43122. + *
  43123. + * @param key, nonce, label, bytes, len, result Same as for dwc_prf().
  43124. + */
  43125. +static inline void dwc_wusb_prf_256(u8 *key, u8 *nonce,
  43126. + char *label, u8 *bytes, int len, u8 *result)
  43127. +{
  43128. + dwc_wusb_prf(256, key, nonce, label, bytes, len, result);
  43129. +}
  43130. +
  43131. +
  43132. +void dwc_wusb_fill_ccm_nonce(uint16_t haddr, uint16_t daddr, uint8_t *tkid,
  43133. + uint8_t *nonce);
  43134. +void dwc_wusb_gen_nonce(uint16_t addr,
  43135. + uint8_t *nonce);
  43136. +
  43137. +void dwc_wusb_gen_key(uint8_t *ccm_nonce, uint8_t *mk,
  43138. + uint8_t *hnonce, uint8_t *dnonce,
  43139. + uint8_t *kck, uint8_t *ptk);
  43140. +
  43141. +
  43142. +void dwc_wusb_gen_mic(uint8_t *ccm_nonce, uint8_t
  43143. + *kck, uint8_t *data, uint8_t *mic);
  43144. +
  43145. +#ifdef __cplusplus
  43146. +}
  43147. +#endif
  43148. +
  43149. +#endif /* _DWC_CRYPTO_H_ */
  43150. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_common_port/dwc_dh.c linux-3.13.3/drivers/usb/host/dwc_common_port/dwc_dh.c
  43151. --- linux-3.13.3.orig/drivers/usb/host/dwc_common_port/dwc_dh.c 1970-01-01 01:00:00.000000000 +0100
  43152. +++ linux-3.13.3/drivers/usb/host/dwc_common_port/dwc_dh.c 2014-02-17 22:41:01.000000000 +0100
  43153. @@ -0,0 +1,291 @@
  43154. +/* =========================================================================
  43155. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_dh.c $
  43156. + * $Revision: #3 $
  43157. + * $Date: 2010/09/28 $
  43158. + * $Change: 1596182 $
  43159. + *
  43160. + * Synopsys Portability Library Software and documentation
  43161. + * (hereinafter, "Software") is an Unsupported proprietary work of
  43162. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  43163. + * between Synopsys and you.
  43164. + *
  43165. + * The Software IS NOT an item of Licensed Software or Licensed Product
  43166. + * under any End User Software License Agreement or Agreement for
  43167. + * Licensed Product with Synopsys or any supplement thereto. You are
  43168. + * permitted to use and redistribute this Software in source and binary
  43169. + * forms, with or without modification, provided that redistributions
  43170. + * of source code must retain this notice. You may not view, use,
  43171. + * disclose, copy or distribute this file or any information contained
  43172. + * herein except pursuant to this license grant from Synopsys. If you
  43173. + * do not agree with this notice, including the disclaimer below, then
  43174. + * you are not authorized to use the Software.
  43175. + *
  43176. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  43177. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  43178. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  43179. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  43180. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  43181. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  43182. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  43183. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  43184. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  43185. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  43186. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  43187. + * DAMAGE.
  43188. + * ========================================================================= */
  43189. +#ifdef DWC_CRYPTOLIB
  43190. +
  43191. +#ifndef CONFIG_MACH_IPMATE
  43192. +
  43193. +#include "dwc_dh.h"
  43194. +#include "dwc_modpow.h"
  43195. +
  43196. +#ifdef DEBUG
  43197. +/* This function prints out a buffer in the format described in the Association
  43198. + * Model specification. */
  43199. +static void dh_dump(char *str, void *_num, int len)
  43200. +{
  43201. + uint8_t *num = _num;
  43202. + int i;
  43203. + DWC_PRINTF("%s\n", str);
  43204. + for (i = 0; i < len; i ++) {
  43205. + DWC_PRINTF("%02x", num[i]);
  43206. + if (((i + 1) % 2) == 0) DWC_PRINTF(" ");
  43207. + if (((i + 1) % 26) == 0) DWC_PRINTF("\n");
  43208. + }
  43209. +
  43210. + DWC_PRINTF("\n");
  43211. +}
  43212. +#else
  43213. +#define dh_dump(_x...) do {; } while(0)
  43214. +#endif
  43215. +
  43216. +/* Constant g value */
  43217. +static __u32 dh_g[] = {
  43218. + 0x02000000,
  43219. +};
  43220. +
  43221. +/* Constant p value */
  43222. +static __u32 dh_p[] = {
  43223. + 0xFFFFFFFF, 0xFFFFFFFF, 0xA2DA0FC9, 0x34C26821, 0x8B62C6C4, 0xD11CDC80, 0x084E0229, 0x74CC678A,
  43224. + 0xA6BE0B02, 0x229B133B, 0x79084A51, 0xDD04348E, 0xB31995EF, 0x1B433ACD, 0x6D0A2B30, 0x37145FF2,
  43225. + 0x6D35E14F, 0x45C2516D, 0x76B585E4, 0xC67E5E62, 0xE9424CF4, 0x6BED37A6, 0xB65CFF0B, 0xEDB706F4,
  43226. + 0xFB6B38EE, 0xA59F895A, 0x11249FAE, 0xE61F4B7C, 0x51662849, 0x3D5BE4EC, 0xB87C00C2, 0x05BF63A1,
  43227. + 0x3648DA98, 0x9AD3551C, 0xA83F1669, 0x5FCF24FD, 0x235D6583, 0x96ADA3DC, 0x56F3621C, 0xBB528520,
  43228. + 0x0729D59E, 0x6D969670, 0x4E350C67, 0x0498BC4A, 0x086C74F1, 0x7C2118CA, 0x465E9032, 0x3BCE362E,
  43229. + 0x2C779EE3, 0x03860E18, 0xA283279B, 0x8FA207EC, 0xF05DC5B5, 0xC9524C6F, 0xF6CB2BDE, 0x18175895,
  43230. + 0x7C499539, 0xE56A95EA, 0x1826D215, 0x1005FA98, 0x5A8E7215, 0x2DC4AA8A, 0x0D1733AD, 0x337A5004,
  43231. + 0xAB2155A8, 0x64BA1CDF, 0x0485FBEC, 0x0AEFDB58, 0x5771EA8A, 0x7D0C065D, 0x850F97B3, 0xC7E4E1A6,
  43232. + 0x8CAEF5AB, 0xD73309DB, 0xE0948C1E, 0x9D61254A, 0x26D2E3CE, 0x6BEED21A, 0x06FA2FF1, 0x64088AD9,
  43233. + 0x730276D8, 0x646AC83E, 0x182B1F52, 0x0C207B17, 0x5717E1BB, 0x6C5D617A, 0xC0880977, 0xE246D9BA,
  43234. + 0xA04FE208, 0x31ABE574, 0xFC5BDB43, 0x8E10FDE0, 0x20D1824B, 0xCAD23AA9, 0xFFFFFFFF, 0xFFFFFFFF,
  43235. +};
  43236. +
  43237. +static void dh_swap_bytes(void *_in, void *_out, uint32_t len)
  43238. +{
  43239. + uint8_t *in = _in;
  43240. + uint8_t *out = _out;
  43241. + int i;
  43242. + for (i=0; i<len; i++) {
  43243. + out[i] = in[len-1-i];
  43244. + }
  43245. +}
  43246. +
  43247. +/* Computes the modular exponentiation (num^exp % mod). num, exp, and mod are
  43248. + * big endian numbers of size len, in bytes. Each len value must be a multiple
  43249. + * of 4. */
  43250. +int dwc_dh_modpow(void *mem_ctx, void *num, uint32_t num_len,
  43251. + void *exp, uint32_t exp_len,
  43252. + void *mod, uint32_t mod_len,
  43253. + void *out)
  43254. +{
  43255. + /* modpow() takes little endian numbers. AM uses big-endian. This
  43256. + * function swaps bytes of numbers before passing onto modpow. */
  43257. +
  43258. + int retval = 0;
  43259. + uint32_t *result;
  43260. +
  43261. + uint32_t *bignum_num = dwc_alloc(mem_ctx, num_len + 4);
  43262. + uint32_t *bignum_exp = dwc_alloc(mem_ctx, exp_len + 4);
  43263. + uint32_t *bignum_mod = dwc_alloc(mem_ctx, mod_len + 4);
  43264. +
  43265. + dh_swap_bytes(num, &bignum_num[1], num_len);
  43266. + bignum_num[0] = num_len / 4;
  43267. +
  43268. + dh_swap_bytes(exp, &bignum_exp[1], exp_len);
  43269. + bignum_exp[0] = exp_len / 4;
  43270. +
  43271. + dh_swap_bytes(mod, &bignum_mod[1], mod_len);
  43272. + bignum_mod[0] = mod_len / 4;
  43273. +
  43274. + result = dwc_modpow(mem_ctx, bignum_num, bignum_exp, bignum_mod);
  43275. + if (!result) {
  43276. + retval = -1;
  43277. + goto dh_modpow_nomem;
  43278. + }
  43279. +
  43280. + dh_swap_bytes(&result[1], out, result[0] * 4);
  43281. + dwc_free(mem_ctx, result);
  43282. +
  43283. + dh_modpow_nomem:
  43284. + dwc_free(mem_ctx, bignum_num);
  43285. + dwc_free(mem_ctx, bignum_exp);
  43286. + dwc_free(mem_ctx, bignum_mod);
  43287. + return retval;
  43288. +}
  43289. +
  43290. +
  43291. +int dwc_dh_pk(void *mem_ctx, uint8_t nd, uint8_t *exp, uint8_t *pk, uint8_t *hash)
  43292. +{
  43293. + int retval;
  43294. + uint8_t m3[385];
  43295. +
  43296. +#ifndef DH_TEST_VECTORS
  43297. + DWC_RANDOM_BYTES(exp, 32);
  43298. +#endif
  43299. +
  43300. + /* Compute the pkd */
  43301. + if ((retval = dwc_dh_modpow(mem_ctx, dh_g, 4,
  43302. + exp, 32,
  43303. + dh_p, 384, pk))) {
  43304. + return retval;
  43305. + }
  43306. +
  43307. + m3[384] = nd;
  43308. + DWC_MEMCPY(&m3[0], pk, 384);
  43309. + DWC_SHA256(m3, 385, hash);
  43310. +
  43311. + dh_dump("PK", pk, 384);
  43312. + dh_dump("SHA-256(M3)", hash, 32);
  43313. + return 0;
  43314. +}
  43315. +
  43316. +int dwc_dh_derive_keys(void *mem_ctx, uint8_t nd, uint8_t *pkh, uint8_t *pkd,
  43317. + uint8_t *exp, int is_host,
  43318. + char *dd, uint8_t *ck, uint8_t *kdk)
  43319. +{
  43320. + int retval;
  43321. + uint8_t mv[784];
  43322. + uint8_t sha_result[32];
  43323. + uint8_t dhkey[384];
  43324. + uint8_t shared_secret[384];
  43325. + char *message;
  43326. + uint32_t vd;
  43327. +
  43328. + uint8_t *pk;
  43329. +
  43330. + if (is_host) {
  43331. + pk = pkd;
  43332. + }
  43333. + else {
  43334. + pk = pkh;
  43335. + }
  43336. +
  43337. + if ((retval = dwc_dh_modpow(mem_ctx, pk, 384,
  43338. + exp, 32,
  43339. + dh_p, 384, shared_secret))) {
  43340. + return retval;
  43341. + }
  43342. + dh_dump("Shared Secret", shared_secret, 384);
  43343. +
  43344. + DWC_SHA256(shared_secret, 384, dhkey);
  43345. + dh_dump("DHKEY", dhkey, 384);
  43346. +
  43347. + DWC_MEMCPY(&mv[0], pkd, 384);
  43348. + DWC_MEMCPY(&mv[384], pkh, 384);
  43349. + DWC_MEMCPY(&mv[768], "displayed digest", 16);
  43350. + dh_dump("MV", mv, 784);
  43351. +
  43352. + DWC_SHA256(mv, 784, sha_result);
  43353. + dh_dump("SHA-256(MV)", sha_result, 32);
  43354. + dh_dump("First 32-bits of SHA-256(MV)", sha_result, 4);
  43355. +
  43356. + dh_swap_bytes(sha_result, &vd, 4);
  43357. +#ifdef DEBUG
  43358. + DWC_PRINTF("Vd (decimal) = %d\n", vd);
  43359. +#endif
  43360. +
  43361. + switch (nd) {
  43362. + case 2:
  43363. + vd = vd % 100;
  43364. + DWC_SPRINTF(dd, "%02d", vd);
  43365. + break;
  43366. + case 3:
  43367. + vd = vd % 1000;
  43368. + DWC_SPRINTF(dd, "%03d", vd);
  43369. + break;
  43370. + case 4:
  43371. + vd = vd % 10000;
  43372. + DWC_SPRINTF(dd, "%04d", vd);
  43373. + break;
  43374. + }
  43375. +#ifdef DEBUG
  43376. + DWC_PRINTF("Display Digits: %s\n", dd);
  43377. +#endif
  43378. +
  43379. + message = "connection key";
  43380. + DWC_HMAC_SHA256(message, DWC_STRLEN(message), dhkey, 32, sha_result);
  43381. + dh_dump("HMAC(SHA-256, DHKey, connection key)", sha_result, 32);
  43382. + DWC_MEMCPY(ck, sha_result, 16);
  43383. +
  43384. + message = "key derivation key";
  43385. + DWC_HMAC_SHA256(message, DWC_STRLEN(message), dhkey, 32, sha_result);
  43386. + dh_dump("HMAC(SHA-256, DHKey, key derivation key)", sha_result, 32);
  43387. + DWC_MEMCPY(kdk, sha_result, 32);
  43388. +
  43389. + return 0;
  43390. +}
  43391. +
  43392. +
  43393. +#ifdef DH_TEST_VECTORS
  43394. +
  43395. +static __u8 dh_a[] = {
  43396. + 0x44, 0x00, 0x51, 0xd6,
  43397. + 0xf0, 0xb5, 0x5e, 0xa9,
  43398. + 0x67, 0xab, 0x31, 0xc6,
  43399. + 0x8a, 0x8b, 0x5e, 0x37,
  43400. + 0xd9, 0x10, 0xda, 0xe0,
  43401. + 0xe2, 0xd4, 0x59, 0xa4,
  43402. + 0x86, 0x45, 0x9c, 0xaa,
  43403. + 0xdf, 0x36, 0x75, 0x16,
  43404. +};
  43405. +
  43406. +static __u8 dh_b[] = {
  43407. + 0x5d, 0xae, 0xc7, 0x86,
  43408. + 0x79, 0x80, 0xa3, 0x24,
  43409. + 0x8c, 0xe3, 0x57, 0x8f,
  43410. + 0xc7, 0x5f, 0x1b, 0x0f,
  43411. + 0x2d, 0xf8, 0x9d, 0x30,
  43412. + 0x6f, 0xa4, 0x52, 0xcd,
  43413. + 0xe0, 0x7a, 0x04, 0x8a,
  43414. + 0xde, 0xd9, 0x26, 0x56,
  43415. +};
  43416. +
  43417. +void dwc_run_dh_test_vectors(void *mem_ctx)
  43418. +{
  43419. + uint8_t pkd[384];
  43420. + uint8_t pkh[384];
  43421. + uint8_t hashd[32];
  43422. + uint8_t hashh[32];
  43423. + uint8_t ck[16];
  43424. + uint8_t kdk[32];
  43425. + char dd[5];
  43426. +
  43427. + DWC_PRINTF("\n\n\nDH_TEST_VECTORS\n\n");
  43428. +
  43429. + /* compute the PKd and SHA-256(PKd || Nd) */
  43430. + DWC_PRINTF("Computing PKd\n");
  43431. + dwc_dh_pk(mem_ctx, 2, dh_a, pkd, hashd);
  43432. +
  43433. + /* compute the PKd and SHA-256(PKh || Nd) */
  43434. + DWC_PRINTF("Computing PKh\n");
  43435. + dwc_dh_pk(mem_ctx, 2, dh_b, pkh, hashh);
  43436. +
  43437. + /* compute the dhkey */
  43438. + dwc_dh_derive_keys(mem_ctx, 2, pkh, pkd, dh_a, 0, dd, ck, kdk);
  43439. +}
  43440. +#endif /* DH_TEST_VECTORS */
  43441. +
  43442. +#endif /* !CONFIG_MACH_IPMATE */
  43443. +
  43444. +#endif /* DWC_CRYPTOLIB */
  43445. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_common_port/dwc_dh.h linux-3.13.3/drivers/usb/host/dwc_common_port/dwc_dh.h
  43446. --- linux-3.13.3.orig/drivers/usb/host/dwc_common_port/dwc_dh.h 1970-01-01 01:00:00.000000000 +0100
  43447. +++ linux-3.13.3/drivers/usb/host/dwc_common_port/dwc_dh.h 2014-02-17 22:41:01.000000000 +0100
  43448. @@ -0,0 +1,106 @@
  43449. +/* =========================================================================
  43450. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_dh.h $
  43451. + * $Revision: #4 $
  43452. + * $Date: 2010/09/28 $
  43453. + * $Change: 1596182 $
  43454. + *
  43455. + * Synopsys Portability Library Software and documentation
  43456. + * (hereinafter, "Software") is an Unsupported proprietary work of
  43457. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  43458. + * between Synopsys and you.
  43459. + *
  43460. + * The Software IS NOT an item of Licensed Software or Licensed Product
  43461. + * under any End User Software License Agreement or Agreement for
  43462. + * Licensed Product with Synopsys or any supplement thereto. You are
  43463. + * permitted to use and redistribute this Software in source and binary
  43464. + * forms, with or without modification, provided that redistributions
  43465. + * of source code must retain this notice. You may not view, use,
  43466. + * disclose, copy or distribute this file or any information contained
  43467. + * herein except pursuant to this license grant from Synopsys. If you
  43468. + * do not agree with this notice, including the disclaimer below, then
  43469. + * you are not authorized to use the Software.
  43470. + *
  43471. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  43472. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  43473. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  43474. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  43475. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  43476. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  43477. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  43478. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  43479. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  43480. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  43481. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  43482. + * DAMAGE.
  43483. + * ========================================================================= */
  43484. +#ifndef _DWC_DH_H_
  43485. +#define _DWC_DH_H_
  43486. +
  43487. +#ifdef __cplusplus
  43488. +extern "C" {
  43489. +#endif
  43490. +
  43491. +#include "dwc_os.h"
  43492. +
  43493. +/** @file
  43494. + *
  43495. + * This file defines the common functions on device and host for performing
  43496. + * numeric association as defined in the WUSB spec. They are only to be
  43497. + * used internally by the DWC UWB modules. */
  43498. +
  43499. +extern int dwc_dh_sha256(uint8_t *message, uint32_t len, uint8_t *out);
  43500. +extern int dwc_dh_hmac_sha256(uint8_t *message, uint32_t messagelen,
  43501. + uint8_t *key, uint32_t keylen,
  43502. + uint8_t *out);
  43503. +extern int dwc_dh_modpow(void *mem_ctx, void *num, uint32_t num_len,
  43504. + void *exp, uint32_t exp_len,
  43505. + void *mod, uint32_t mod_len,
  43506. + void *out);
  43507. +
  43508. +/** Computes PKD or PKH, and SHA-256(PKd || Nd)
  43509. + *
  43510. + * PK = g^exp mod p.
  43511. + *
  43512. + * Input:
  43513. + * Nd = Number of digits on the device.
  43514. + *
  43515. + * Output:
  43516. + * exp = A 32-byte buffer to be filled with a randomly generated number.
  43517. + * used as either A or B.
  43518. + * pk = A 384-byte buffer to be filled with the PKH or PKD.
  43519. + * hash = A 32-byte buffer to be filled with SHA-256(PK || ND).
  43520. + */
  43521. +extern int dwc_dh_pk(void *mem_ctx, uint8_t nd, uint8_t *exp, uint8_t *pkd, uint8_t *hash);
  43522. +
  43523. +/** Computes the DHKEY, and VD.
  43524. + *
  43525. + * If called from host, then it will comput DHKEY=PKD^exp % p.
  43526. + * If called from device, then it will comput DHKEY=PKH^exp % p.
  43527. + *
  43528. + * Input:
  43529. + * pkd = The PKD value.
  43530. + * pkh = The PKH value.
  43531. + * exp = The A value (if device) or B value (if host) generated in dwc_wudev_dh_pk.
  43532. + * is_host = Set to non zero if a WUSB host is calling this function.
  43533. + *
  43534. + * Output:
  43535. +
  43536. + * dd = A pointer to an buffer to be set to the displayed digits string to be shown
  43537. + * to the user. This buffer should be at 5 bytes long to hold 4 digits plus a
  43538. + * null termination character. This buffer can be used directly for display.
  43539. + * ck = A 16-byte buffer to be filled with the CK.
  43540. + * kdk = A 32-byte buffer to be filled with the KDK.
  43541. + */
  43542. +extern int dwc_dh_derive_keys(void *mem_ctx, uint8_t nd, uint8_t *pkh, uint8_t *pkd,
  43543. + uint8_t *exp, int is_host,
  43544. + char *dd, uint8_t *ck, uint8_t *kdk);
  43545. +
  43546. +#ifdef DH_TEST_VECTORS
  43547. +extern void dwc_run_dh_test_vectors(void);
  43548. +#endif
  43549. +
  43550. +#ifdef __cplusplus
  43551. +}
  43552. +#endif
  43553. +
  43554. +#endif /* _DWC_DH_H_ */
  43555. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_common_port/dwc_list.h linux-3.13.3/drivers/usb/host/dwc_common_port/dwc_list.h
  43556. --- linux-3.13.3.orig/drivers/usb/host/dwc_common_port/dwc_list.h 1970-01-01 01:00:00.000000000 +0100
  43557. +++ linux-3.13.3/drivers/usb/host/dwc_common_port/dwc_list.h 2014-02-17 22:41:01.000000000 +0100
  43558. @@ -0,0 +1,594 @@
  43559. +/* $OpenBSD: queue.h,v 1.26 2004/05/04 16:59:32 grange Exp $ */
  43560. +/* $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $ */
  43561. +
  43562. +/*
  43563. + * Copyright (c) 1991, 1993
  43564. + * The Regents of the University of California. All rights reserved.
  43565. + *
  43566. + * Redistribution and use in source and binary forms, with or without
  43567. + * modification, are permitted provided that the following conditions
  43568. + * are met:
  43569. + * 1. Redistributions of source code must retain the above copyright
  43570. + * notice, this list of conditions and the following disclaimer.
  43571. + * 2. Redistributions in binary form must reproduce the above copyright
  43572. + * notice, this list of conditions and the following disclaimer in the
  43573. + * documentation and/or other materials provided with the distribution.
  43574. + * 3. Neither the name of the University nor the names of its contributors
  43575. + * may be used to endorse or promote products derived from this software
  43576. + * without specific prior written permission.
  43577. + *
  43578. + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  43579. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  43580. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  43581. + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  43582. + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  43583. + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  43584. + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  43585. + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  43586. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  43587. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  43588. + * SUCH DAMAGE.
  43589. + *
  43590. + * @(#)queue.h 8.5 (Berkeley) 8/20/94
  43591. + */
  43592. +
  43593. +#ifndef _DWC_LIST_H_
  43594. +#define _DWC_LIST_H_
  43595. +
  43596. +#ifdef __cplusplus
  43597. +extern "C" {
  43598. +#endif
  43599. +
  43600. +/** @file
  43601. + *
  43602. + * This file defines linked list operations. It is derived from BSD with
  43603. + * only the MACRO names being prefixed with DWC_. This is because a few of
  43604. + * these names conflict with those on Linux. For documentation on use, see the
  43605. + * inline comments in the source code. The original license for this source
  43606. + * code applies and is preserved in the dwc_list.h source file.
  43607. + */
  43608. +
  43609. +/*
  43610. + * This file defines five types of data structures: singly-linked lists,
  43611. + * lists, simple queues, tail queues, and circular queues.
  43612. + *
  43613. + *
  43614. + * A singly-linked list is headed by a single forward pointer. The elements
  43615. + * are singly linked for minimum space and pointer manipulation overhead at
  43616. + * the expense of O(n) removal for arbitrary elements. New elements can be
  43617. + * added to the list after an existing element or at the head of the list.
  43618. + * Elements being removed from the head of the list should use the explicit
  43619. + * macro for this purpose for optimum efficiency. A singly-linked list may
  43620. + * only be traversed in the forward direction. Singly-linked lists are ideal
  43621. + * for applications with large datasets and few or no removals or for
  43622. + * implementing a LIFO queue.
  43623. + *
  43624. + * A list is headed by a single forward pointer (or an array of forward
  43625. + * pointers for a hash table header). The elements are doubly linked
  43626. + * so that an arbitrary element can be removed without a need to
  43627. + * traverse the list. New elements can be added to the list before
  43628. + * or after an existing element or at the head of the list. A list
  43629. + * may only be traversed in the forward direction.
  43630. + *
  43631. + * A simple queue is headed by a pair of pointers, one the head of the
  43632. + * list and the other to the tail of the list. The elements are singly
  43633. + * linked to save space, so elements can only be removed from the
  43634. + * head of the list. New elements can be added to the list before or after
  43635. + * an existing element, at the head of the list, or at the end of the
  43636. + * list. A simple queue may only be traversed in the forward direction.
  43637. + *
  43638. + * A tail queue is headed by a pair of pointers, one to the head of the
  43639. + * list and the other to the tail of the list. The elements are doubly
  43640. + * linked so that an arbitrary element can be removed without a need to
  43641. + * traverse the list. New elements can be added to the list before or
  43642. + * after an existing element, at the head of the list, or at the end of
  43643. + * the list. A tail queue may be traversed in either direction.
  43644. + *
  43645. + * A circle queue is headed by a pair of pointers, one to the head of the
  43646. + * list and the other to the tail of the list. The elements are doubly
  43647. + * linked so that an arbitrary element can be removed without a need to
  43648. + * traverse the list. New elements can be added to the list before or after
  43649. + * an existing element, at the head of the list, or at the end of the list.
  43650. + * A circle queue may be traversed in either direction, but has a more
  43651. + * complex end of list detection.
  43652. + *
  43653. + * For details on the use of these macros, see the queue(3) manual page.
  43654. + */
  43655. +
  43656. +/*
  43657. + * Double-linked List.
  43658. + */
  43659. +
  43660. +typedef struct dwc_list_link {
  43661. + struct dwc_list_link *next;
  43662. + struct dwc_list_link *prev;
  43663. +} dwc_list_link_t;
  43664. +
  43665. +#define DWC_LIST_INIT(link) do { \
  43666. + (link)->next = (link); \
  43667. + (link)->prev = (link); \
  43668. +} while (0)
  43669. +
  43670. +#define DWC_LIST_FIRST(link) ((link)->next)
  43671. +#define DWC_LIST_LAST(link) ((link)->prev)
  43672. +#define DWC_LIST_END(link) (link)
  43673. +#define DWC_LIST_NEXT(link) ((link)->next)
  43674. +#define DWC_LIST_PREV(link) ((link)->prev)
  43675. +#define DWC_LIST_EMPTY(link) \
  43676. + (DWC_LIST_FIRST(link) == DWC_LIST_END(link))
  43677. +#define DWC_LIST_ENTRY(link, type, field) \
  43678. + (type *)((uint8_t *)(link) - (size_t)(&((type *)0)->field))
  43679. +
  43680. +#if 0
  43681. +#define DWC_LIST_INSERT_HEAD(list, link) do { \
  43682. + (link)->next = (list)->next; \
  43683. + (link)->prev = (list); \
  43684. + (list)->next->prev = (link); \
  43685. + (list)->next = (link); \
  43686. +} while (0)
  43687. +
  43688. +#define DWC_LIST_INSERT_TAIL(list, link) do { \
  43689. + (link)->next = (list); \
  43690. + (link)->prev = (list)->prev; \
  43691. + (list)->prev->next = (link); \
  43692. + (list)->prev = (link); \
  43693. +} while (0)
  43694. +#else
  43695. +#define DWC_LIST_INSERT_HEAD(list, link) do { \
  43696. + dwc_list_link_t *__next__ = (list)->next; \
  43697. + __next__->prev = (link); \
  43698. + (link)->next = __next__; \
  43699. + (link)->prev = (list); \
  43700. + (list)->next = (link); \
  43701. +} while (0)
  43702. +
  43703. +#define DWC_LIST_INSERT_TAIL(list, link) do { \
  43704. + dwc_list_link_t *__prev__ = (list)->prev; \
  43705. + (list)->prev = (link); \
  43706. + (link)->next = (list); \
  43707. + (link)->prev = __prev__; \
  43708. + __prev__->next = (link); \
  43709. +} while (0)
  43710. +#endif
  43711. +
  43712. +#if 0
  43713. +static inline void __list_add(struct list_head *new,
  43714. + struct list_head *prev,
  43715. + struct list_head *next)
  43716. +{
  43717. + next->prev = new;
  43718. + new->next = next;
  43719. + new->prev = prev;
  43720. + prev->next = new;
  43721. +}
  43722. +
  43723. +static inline void list_add(struct list_head *new, struct list_head *head)
  43724. +{
  43725. + __list_add(new, head, head->next);
  43726. +}
  43727. +
  43728. +static inline void list_add_tail(struct list_head *new, struct list_head *head)
  43729. +{
  43730. + __list_add(new, head->prev, head);
  43731. +}
  43732. +
  43733. +static inline void __list_del(struct list_head * prev, struct list_head * next)
  43734. +{
  43735. + next->prev = prev;
  43736. + prev->next = next;
  43737. +}
  43738. +
  43739. +static inline void list_del(struct list_head *entry)
  43740. +{
  43741. + __list_del(entry->prev, entry->next);
  43742. + entry->next = LIST_POISON1;
  43743. + entry->prev = LIST_POISON2;
  43744. +}
  43745. +#endif
  43746. +
  43747. +#define DWC_LIST_REMOVE(link) do { \
  43748. + (link)->next->prev = (link)->prev; \
  43749. + (link)->prev->next = (link)->next; \
  43750. +} while (0)
  43751. +
  43752. +#define DWC_LIST_REMOVE_INIT(link) do { \
  43753. + DWC_LIST_REMOVE(link); \
  43754. + DWC_LIST_INIT(link); \
  43755. +} while (0)
  43756. +
  43757. +#define DWC_LIST_MOVE_HEAD(list, link) do { \
  43758. + DWC_LIST_REMOVE(link); \
  43759. + DWC_LIST_INSERT_HEAD(list, link); \
  43760. +} while (0)
  43761. +
  43762. +#define DWC_LIST_MOVE_TAIL(list, link) do { \
  43763. + DWC_LIST_REMOVE(link); \
  43764. + DWC_LIST_INSERT_TAIL(list, link); \
  43765. +} while (0)
  43766. +
  43767. +#define DWC_LIST_FOREACH(var, list) \
  43768. + for((var) = DWC_LIST_FIRST(list); \
  43769. + (var) != DWC_LIST_END(list); \
  43770. + (var) = DWC_LIST_NEXT(var))
  43771. +
  43772. +#define DWC_LIST_FOREACH_SAFE(var, var2, list) \
  43773. + for((var) = DWC_LIST_FIRST(list), (var2) = DWC_LIST_NEXT(var); \
  43774. + (var) != DWC_LIST_END(list); \
  43775. + (var) = (var2), (var2) = DWC_LIST_NEXT(var2))
  43776. +
  43777. +#define DWC_LIST_FOREACH_REVERSE(var, list) \
  43778. + for((var) = DWC_LIST_LAST(list); \
  43779. + (var) != DWC_LIST_END(list); \
  43780. + (var) = DWC_LIST_PREV(var))
  43781. +
  43782. +/*
  43783. + * Singly-linked List definitions.
  43784. + */
  43785. +#define DWC_SLIST_HEAD(name, type) \
  43786. +struct name { \
  43787. + struct type *slh_first; /* first element */ \
  43788. +}
  43789. +
  43790. +#define DWC_SLIST_HEAD_INITIALIZER(head) \
  43791. + { NULL }
  43792. +
  43793. +#define DWC_SLIST_ENTRY(type) \
  43794. +struct { \
  43795. + struct type *sle_next; /* next element */ \
  43796. +}
  43797. +
  43798. +/*
  43799. + * Singly-linked List access methods.
  43800. + */
  43801. +#define DWC_SLIST_FIRST(head) ((head)->slh_first)
  43802. +#define DWC_SLIST_END(head) NULL
  43803. +#define DWC_SLIST_EMPTY(head) (SLIST_FIRST(head) == SLIST_END(head))
  43804. +#define DWC_SLIST_NEXT(elm, field) ((elm)->field.sle_next)
  43805. +
  43806. +#define DWC_SLIST_FOREACH(var, head, field) \
  43807. + for((var) = SLIST_FIRST(head); \
  43808. + (var) != SLIST_END(head); \
  43809. + (var) = SLIST_NEXT(var, field))
  43810. +
  43811. +#define DWC_SLIST_FOREACH_PREVPTR(var, varp, head, field) \
  43812. + for((varp) = &SLIST_FIRST((head)); \
  43813. + ((var) = *(varp)) != SLIST_END(head); \
  43814. + (varp) = &SLIST_NEXT((var), field))
  43815. +
  43816. +/*
  43817. + * Singly-linked List functions.
  43818. + */
  43819. +#define DWC_SLIST_INIT(head) { \
  43820. + SLIST_FIRST(head) = SLIST_END(head); \
  43821. +}
  43822. +
  43823. +#define DWC_SLIST_INSERT_AFTER(slistelm, elm, field) do { \
  43824. + (elm)->field.sle_next = (slistelm)->field.sle_next; \
  43825. + (slistelm)->field.sle_next = (elm); \
  43826. +} while (0)
  43827. +
  43828. +#define DWC_SLIST_INSERT_HEAD(head, elm, field) do { \
  43829. + (elm)->field.sle_next = (head)->slh_first; \
  43830. + (head)->slh_first = (elm); \
  43831. +} while (0)
  43832. +
  43833. +#define DWC_SLIST_REMOVE_NEXT(head, elm, field) do { \
  43834. + (elm)->field.sle_next = (elm)->field.sle_next->field.sle_next; \
  43835. +} while (0)
  43836. +
  43837. +#define DWC_SLIST_REMOVE_HEAD(head, field) do { \
  43838. + (head)->slh_first = (head)->slh_first->field.sle_next; \
  43839. +} while (0)
  43840. +
  43841. +#define DWC_SLIST_REMOVE(head, elm, type, field) do { \
  43842. + if ((head)->slh_first == (elm)) { \
  43843. + SLIST_REMOVE_HEAD((head), field); \
  43844. + } \
  43845. + else { \
  43846. + struct type *curelm = (head)->slh_first; \
  43847. + while( curelm->field.sle_next != (elm) ) \
  43848. + curelm = curelm->field.sle_next; \
  43849. + curelm->field.sle_next = \
  43850. + curelm->field.sle_next->field.sle_next; \
  43851. + } \
  43852. +} while (0)
  43853. +
  43854. +/*
  43855. + * Simple queue definitions.
  43856. + */
  43857. +#define DWC_SIMPLEQ_HEAD(name, type) \
  43858. +struct name { \
  43859. + struct type *sqh_first; /* first element */ \
  43860. + struct type **sqh_last; /* addr of last next element */ \
  43861. +}
  43862. +
  43863. +#define DWC_SIMPLEQ_HEAD_INITIALIZER(head) \
  43864. + { NULL, &(head).sqh_first }
  43865. +
  43866. +#define DWC_SIMPLEQ_ENTRY(type) \
  43867. +struct { \
  43868. + struct type *sqe_next; /* next element */ \
  43869. +}
  43870. +
  43871. +/*
  43872. + * Simple queue access methods.
  43873. + */
  43874. +#define DWC_SIMPLEQ_FIRST(head) ((head)->sqh_first)
  43875. +#define DWC_SIMPLEQ_END(head) NULL
  43876. +#define DWC_SIMPLEQ_EMPTY(head) (SIMPLEQ_FIRST(head) == SIMPLEQ_END(head))
  43877. +#define DWC_SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next)
  43878. +
  43879. +#define DWC_SIMPLEQ_FOREACH(var, head, field) \
  43880. + for((var) = SIMPLEQ_FIRST(head); \
  43881. + (var) != SIMPLEQ_END(head); \
  43882. + (var) = SIMPLEQ_NEXT(var, field))
  43883. +
  43884. +/*
  43885. + * Simple queue functions.
  43886. + */
  43887. +#define DWC_SIMPLEQ_INIT(head) do { \
  43888. + (head)->sqh_first = NULL; \
  43889. + (head)->sqh_last = &(head)->sqh_first; \
  43890. +} while (0)
  43891. +
  43892. +#define DWC_SIMPLEQ_INSERT_HEAD(head, elm, field) do { \
  43893. + if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \
  43894. + (head)->sqh_last = &(elm)->field.sqe_next; \
  43895. + (head)->sqh_first = (elm); \
  43896. +} while (0)
  43897. +
  43898. +#define DWC_SIMPLEQ_INSERT_TAIL(head, elm, field) do { \
  43899. + (elm)->field.sqe_next = NULL; \
  43900. + *(head)->sqh_last = (elm); \
  43901. + (head)->sqh_last = &(elm)->field.sqe_next; \
  43902. +} while (0)
  43903. +
  43904. +#define DWC_SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
  43905. + if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\
  43906. + (head)->sqh_last = &(elm)->field.sqe_next; \
  43907. + (listelm)->field.sqe_next = (elm); \
  43908. +} while (0)
  43909. +
  43910. +#define DWC_SIMPLEQ_REMOVE_HEAD(head, field) do { \
  43911. + if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \
  43912. + (head)->sqh_last = &(head)->sqh_first; \
  43913. +} while (0)
  43914. +
  43915. +/*
  43916. + * Tail queue definitions.
  43917. + */
  43918. +#define DWC_TAILQ_HEAD(name, type) \
  43919. +struct name { \
  43920. + struct type *tqh_first; /* first element */ \
  43921. + struct type **tqh_last; /* addr of last next element */ \
  43922. +}
  43923. +
  43924. +#define DWC_TAILQ_HEAD_INITIALIZER(head) \
  43925. + { NULL, &(head).tqh_first }
  43926. +
  43927. +#define DWC_TAILQ_ENTRY(type) \
  43928. +struct { \
  43929. + struct type *tqe_next; /* next element */ \
  43930. + struct type **tqe_prev; /* address of previous next element */ \
  43931. +}
  43932. +
  43933. +/*
  43934. + * tail queue access methods
  43935. + */
  43936. +#define DWC_TAILQ_FIRST(head) ((head)->tqh_first)
  43937. +#define DWC_TAILQ_END(head) NULL
  43938. +#define DWC_TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
  43939. +#define DWC_TAILQ_LAST(head, headname) \
  43940. + (*(((struct headname *)((head)->tqh_last))->tqh_last))
  43941. +/* XXX */
  43942. +#define DWC_TAILQ_PREV(elm, headname, field) \
  43943. + (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
  43944. +#define DWC_TAILQ_EMPTY(head) \
  43945. + (DWC_TAILQ_FIRST(head) == DWC_TAILQ_END(head))
  43946. +
  43947. +#define DWC_TAILQ_FOREACH(var, head, field) \
  43948. + for ((var) = DWC_TAILQ_FIRST(head); \
  43949. + (var) != DWC_TAILQ_END(head); \
  43950. + (var) = DWC_TAILQ_NEXT(var, field))
  43951. +
  43952. +#define DWC_TAILQ_FOREACH_REVERSE(var, head, headname, field) \
  43953. + for ((var) = DWC_TAILQ_LAST(head, headname); \
  43954. + (var) != DWC_TAILQ_END(head); \
  43955. + (var) = DWC_TAILQ_PREV(var, headname, field))
  43956. +
  43957. +/*
  43958. + * Tail queue functions.
  43959. + */
  43960. +#define DWC_TAILQ_INIT(head) do { \
  43961. + (head)->tqh_first = NULL; \
  43962. + (head)->tqh_last = &(head)->tqh_first; \
  43963. +} while (0)
  43964. +
  43965. +#define DWC_TAILQ_INSERT_HEAD(head, elm, field) do { \
  43966. + if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
  43967. + (head)->tqh_first->field.tqe_prev = \
  43968. + &(elm)->field.tqe_next; \
  43969. + else \
  43970. + (head)->tqh_last = &(elm)->field.tqe_next; \
  43971. + (head)->tqh_first = (elm); \
  43972. + (elm)->field.tqe_prev = &(head)->tqh_first; \
  43973. +} while (0)
  43974. +
  43975. +#define DWC_TAILQ_INSERT_TAIL(head, elm, field) do { \
  43976. + (elm)->field.tqe_next = NULL; \
  43977. + (elm)->field.tqe_prev = (head)->tqh_last; \
  43978. + *(head)->tqh_last = (elm); \
  43979. + (head)->tqh_last = &(elm)->field.tqe_next; \
  43980. +} while (0)
  43981. +
  43982. +#define DWC_TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
  43983. + if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
  43984. + (elm)->field.tqe_next->field.tqe_prev = \
  43985. + &(elm)->field.tqe_next; \
  43986. + else \
  43987. + (head)->tqh_last = &(elm)->field.tqe_next; \
  43988. + (listelm)->field.tqe_next = (elm); \
  43989. + (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
  43990. +} while (0)
  43991. +
  43992. +#define DWC_TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
  43993. + (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
  43994. + (elm)->field.tqe_next = (listelm); \
  43995. + *(listelm)->field.tqe_prev = (elm); \
  43996. + (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
  43997. +} while (0)
  43998. +
  43999. +#define DWC_TAILQ_REMOVE(head, elm, field) do { \
  44000. + if (((elm)->field.tqe_next) != NULL) \
  44001. + (elm)->field.tqe_next->field.tqe_prev = \
  44002. + (elm)->field.tqe_prev; \
  44003. + else \
  44004. + (head)->tqh_last = (elm)->field.tqe_prev; \
  44005. + *(elm)->field.tqe_prev = (elm)->field.tqe_next; \
  44006. +} while (0)
  44007. +
  44008. +#define DWC_TAILQ_REPLACE(head, elm, elm2, field) do { \
  44009. + if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL) \
  44010. + (elm2)->field.tqe_next->field.tqe_prev = \
  44011. + &(elm2)->field.tqe_next; \
  44012. + else \
  44013. + (head)->tqh_last = &(elm2)->field.tqe_next; \
  44014. + (elm2)->field.tqe_prev = (elm)->field.tqe_prev; \
  44015. + *(elm2)->field.tqe_prev = (elm2); \
  44016. +} while (0)
  44017. +
  44018. +/*
  44019. + * Circular queue definitions.
  44020. + */
  44021. +#define DWC_CIRCLEQ_HEAD(name, type) \
  44022. +struct name { \
  44023. + struct type *cqh_first; /* first element */ \
  44024. + struct type *cqh_last; /* last element */ \
  44025. +}
  44026. +
  44027. +#define DWC_CIRCLEQ_HEAD_INITIALIZER(head) \
  44028. + { DWC_CIRCLEQ_END(&head), DWC_CIRCLEQ_END(&head) }
  44029. +
  44030. +#define DWC_CIRCLEQ_ENTRY(type) \
  44031. +struct { \
  44032. + struct type *cqe_next; /* next element */ \
  44033. + struct type *cqe_prev; /* previous element */ \
  44034. +}
  44035. +
  44036. +/*
  44037. + * Circular queue access methods
  44038. + */
  44039. +#define DWC_CIRCLEQ_FIRST(head) ((head)->cqh_first)
  44040. +#define DWC_CIRCLEQ_LAST(head) ((head)->cqh_last)
  44041. +#define DWC_CIRCLEQ_END(head) ((void *)(head))
  44042. +#define DWC_CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next)
  44043. +#define DWC_CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev)
  44044. +#define DWC_CIRCLEQ_EMPTY(head) \
  44045. + (DWC_CIRCLEQ_FIRST(head) == DWC_CIRCLEQ_END(head))
  44046. +
  44047. +#define DWC_CIRCLEQ_EMPTY_ENTRY(elm, field) (((elm)->field.cqe_next == NULL) && ((elm)->field.cqe_prev == NULL))
  44048. +
  44049. +#define DWC_CIRCLEQ_FOREACH(var, head, field) \
  44050. + for((var) = DWC_CIRCLEQ_FIRST(head); \
  44051. + (var) != DWC_CIRCLEQ_END(head); \
  44052. + (var) = DWC_CIRCLEQ_NEXT(var, field))
  44053. +
  44054. +#define DWC_CIRCLEQ_FOREACH_SAFE(var, var2, head, field) \
  44055. + for((var) = DWC_CIRCLEQ_FIRST(head), var2 = DWC_CIRCLEQ_NEXT(var, field); \
  44056. + (var) != DWC_CIRCLEQ_END(head); \
  44057. + (var) = var2, var2 = DWC_CIRCLEQ_NEXT(var, field))
  44058. +
  44059. +#define DWC_CIRCLEQ_FOREACH_REVERSE(var, head, field) \
  44060. + for((var) = DWC_CIRCLEQ_LAST(head); \
  44061. + (var) != DWC_CIRCLEQ_END(head); \
  44062. + (var) = DWC_CIRCLEQ_PREV(var, field))
  44063. +
  44064. +/*
  44065. + * Circular queue functions.
  44066. + */
  44067. +#define DWC_CIRCLEQ_INIT(head) do { \
  44068. + (head)->cqh_first = DWC_CIRCLEQ_END(head); \
  44069. + (head)->cqh_last = DWC_CIRCLEQ_END(head); \
  44070. +} while (0)
  44071. +
  44072. +#define DWC_CIRCLEQ_INIT_ENTRY(elm, field) do { \
  44073. + (elm)->field.cqe_next = NULL; \
  44074. + (elm)->field.cqe_prev = NULL; \
  44075. +} while (0)
  44076. +
  44077. +#define DWC_CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
  44078. + (elm)->field.cqe_next = (listelm)->field.cqe_next; \
  44079. + (elm)->field.cqe_prev = (listelm); \
  44080. + if ((listelm)->field.cqe_next == DWC_CIRCLEQ_END(head)) \
  44081. + (head)->cqh_last = (elm); \
  44082. + else \
  44083. + (listelm)->field.cqe_next->field.cqe_prev = (elm); \
  44084. + (listelm)->field.cqe_next = (elm); \
  44085. +} while (0)
  44086. +
  44087. +#define DWC_CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \
  44088. + (elm)->field.cqe_next = (listelm); \
  44089. + (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
  44090. + if ((listelm)->field.cqe_prev == DWC_CIRCLEQ_END(head)) \
  44091. + (head)->cqh_first = (elm); \
  44092. + else \
  44093. + (listelm)->field.cqe_prev->field.cqe_next = (elm); \
  44094. + (listelm)->field.cqe_prev = (elm); \
  44095. +} while (0)
  44096. +
  44097. +#define DWC_CIRCLEQ_INSERT_HEAD(head, elm, field) do { \
  44098. + (elm)->field.cqe_next = (head)->cqh_first; \
  44099. + (elm)->field.cqe_prev = DWC_CIRCLEQ_END(head); \
  44100. + if ((head)->cqh_last == DWC_CIRCLEQ_END(head)) \
  44101. + (head)->cqh_last = (elm); \
  44102. + else \
  44103. + (head)->cqh_first->field.cqe_prev = (elm); \
  44104. + (head)->cqh_first = (elm); \
  44105. +} while (0)
  44106. +
  44107. +#define DWC_CIRCLEQ_INSERT_TAIL(head, elm, field) do { \
  44108. + (elm)->field.cqe_next = DWC_CIRCLEQ_END(head); \
  44109. + (elm)->field.cqe_prev = (head)->cqh_last; \
  44110. + if ((head)->cqh_first == DWC_CIRCLEQ_END(head)) \
  44111. + (head)->cqh_first = (elm); \
  44112. + else \
  44113. + (head)->cqh_last->field.cqe_next = (elm); \
  44114. + (head)->cqh_last = (elm); \
  44115. +} while (0)
  44116. +
  44117. +#define DWC_CIRCLEQ_REMOVE(head, elm, field) do { \
  44118. + if ((elm)->field.cqe_next == DWC_CIRCLEQ_END(head)) \
  44119. + (head)->cqh_last = (elm)->field.cqe_prev; \
  44120. + else \
  44121. + (elm)->field.cqe_next->field.cqe_prev = \
  44122. + (elm)->field.cqe_prev; \
  44123. + if ((elm)->field.cqe_prev == DWC_CIRCLEQ_END(head)) \
  44124. + (head)->cqh_first = (elm)->field.cqe_next; \
  44125. + else \
  44126. + (elm)->field.cqe_prev->field.cqe_next = \
  44127. + (elm)->field.cqe_next; \
  44128. +} while (0)
  44129. +
  44130. +#define DWC_CIRCLEQ_REMOVE_INIT(head, elm, field) do { \
  44131. + DWC_CIRCLEQ_REMOVE(head, elm, field); \
  44132. + DWC_CIRCLEQ_INIT_ENTRY(elm, field); \
  44133. +} while (0)
  44134. +
  44135. +#define DWC_CIRCLEQ_REPLACE(head, elm, elm2, field) do { \
  44136. + if (((elm2)->field.cqe_next = (elm)->field.cqe_next) == \
  44137. + DWC_CIRCLEQ_END(head)) \
  44138. + (head).cqh_last = (elm2); \
  44139. + else \
  44140. + (elm2)->field.cqe_next->field.cqe_prev = (elm2); \
  44141. + if (((elm2)->field.cqe_prev = (elm)->field.cqe_prev) == \
  44142. + DWC_CIRCLEQ_END(head)) \
  44143. + (head).cqh_first = (elm2); \
  44144. + else \
  44145. + (elm2)->field.cqe_prev->field.cqe_next = (elm2); \
  44146. +} while (0)
  44147. +
  44148. +#ifdef __cplusplus
  44149. +}
  44150. +#endif
  44151. +
  44152. +#endif /* _DWC_LIST_H_ */
  44153. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_common_port/dwc_mem.c linux-3.13.3/drivers/usb/host/dwc_common_port/dwc_mem.c
  44154. --- linux-3.13.3.orig/drivers/usb/host/dwc_common_port/dwc_mem.c 1970-01-01 01:00:00.000000000 +0100
  44155. +++ linux-3.13.3/drivers/usb/host/dwc_common_port/dwc_mem.c 2014-02-17 22:41:01.000000000 +0100
  44156. @@ -0,0 +1,245 @@
  44157. +/* Memory Debugging */
  44158. +#ifdef DWC_DEBUG_MEMORY
  44159. +
  44160. +#include "dwc_os.h"
  44161. +#include "dwc_list.h"
  44162. +
  44163. +struct allocation {
  44164. + void *addr;
  44165. + void *ctx;
  44166. + char *func;
  44167. + int line;
  44168. + uint32_t size;
  44169. + int dma;
  44170. + DWC_CIRCLEQ_ENTRY(allocation) entry;
  44171. +};
  44172. +
  44173. +DWC_CIRCLEQ_HEAD(allocation_queue, allocation);
  44174. +
  44175. +struct allocation_manager {
  44176. + void *mem_ctx;
  44177. + struct allocation_queue allocations;
  44178. +
  44179. + /* statistics */
  44180. + int num;
  44181. + int num_freed;
  44182. + int num_active;
  44183. + uint32_t total;
  44184. + uint32_t cur;
  44185. + uint32_t max;
  44186. +};
  44187. +
  44188. +static struct allocation_manager *manager = NULL;
  44189. +
  44190. +static int add_allocation(void *ctx, uint32_t size, char const *func, int line, void *addr,
  44191. + int dma)
  44192. +{
  44193. + struct allocation *a;
  44194. +
  44195. + DWC_ASSERT(manager != NULL, "manager not allocated");
  44196. +
  44197. + a = __DWC_ALLOC_ATOMIC(manager->mem_ctx, sizeof(*a));
  44198. + if (!a) {
  44199. + return -DWC_E_NO_MEMORY;
  44200. + }
  44201. +
  44202. + a->func = __DWC_ALLOC_ATOMIC(manager->mem_ctx, DWC_STRLEN(func) + 1);
  44203. + if (!a->func) {
  44204. + __DWC_FREE(manager->mem_ctx, a);
  44205. + return -DWC_E_NO_MEMORY;
  44206. + }
  44207. +
  44208. + DWC_MEMCPY(a->func, func, DWC_STRLEN(func) + 1);
  44209. + a->addr = addr;
  44210. + a->ctx = ctx;
  44211. + a->line = line;
  44212. + a->size = size;
  44213. + a->dma = dma;
  44214. + DWC_CIRCLEQ_INSERT_TAIL(&manager->allocations, a, entry);
  44215. +
  44216. + /* Update stats */
  44217. + manager->num++;
  44218. + manager->num_active++;
  44219. + manager->total += size;
  44220. + manager->cur += size;
  44221. +
  44222. + if (manager->max < manager->cur) {
  44223. + manager->max = manager->cur;
  44224. + }
  44225. +
  44226. + return 0;
  44227. +}
  44228. +
  44229. +static struct allocation *find_allocation(void *ctx, void *addr)
  44230. +{
  44231. + struct allocation *a;
  44232. +
  44233. + DWC_CIRCLEQ_FOREACH(a, &manager->allocations, entry) {
  44234. + if (a->ctx == ctx && a->addr == addr) {
  44235. + return a;
  44236. + }
  44237. + }
  44238. +
  44239. + return NULL;
  44240. +}
  44241. +
  44242. +static void free_allocation(void *ctx, void *addr, char const *func, int line)
  44243. +{
  44244. + struct allocation *a = find_allocation(ctx, addr);
  44245. +
  44246. + if (!a) {
  44247. + DWC_ASSERT(0,
  44248. + "Free of address %p that was never allocated or already freed %s:%d",
  44249. + addr, func, line);
  44250. + return;
  44251. + }
  44252. +
  44253. + DWC_CIRCLEQ_REMOVE(&manager->allocations, a, entry);
  44254. +
  44255. + manager->num_active--;
  44256. + manager->num_freed++;
  44257. + manager->cur -= a->size;
  44258. + __DWC_FREE(manager->mem_ctx, a->func);
  44259. + __DWC_FREE(manager->mem_ctx, a);
  44260. +}
  44261. +
  44262. +int dwc_memory_debug_start(void *mem_ctx)
  44263. +{
  44264. + DWC_ASSERT(manager == NULL, "Memory debugging has already started\n");
  44265. +
  44266. + if (manager) {
  44267. + return -DWC_E_BUSY;
  44268. + }
  44269. +
  44270. + manager = __DWC_ALLOC(mem_ctx, sizeof(*manager));
  44271. + if (!manager) {
  44272. + return -DWC_E_NO_MEMORY;
  44273. + }
  44274. +
  44275. + DWC_CIRCLEQ_INIT(&manager->allocations);
  44276. + manager->mem_ctx = mem_ctx;
  44277. + manager->num = 0;
  44278. + manager->num_freed = 0;
  44279. + manager->num_active = 0;
  44280. + manager->total = 0;
  44281. + manager->cur = 0;
  44282. + manager->max = 0;
  44283. +
  44284. + return 0;
  44285. +}
  44286. +
  44287. +void dwc_memory_debug_stop(void)
  44288. +{
  44289. + struct allocation *a;
  44290. +
  44291. + dwc_memory_debug_report();
  44292. +
  44293. + DWC_CIRCLEQ_FOREACH(a, &manager->allocations, entry) {
  44294. + DWC_ERROR("Memory leaked from %s:%d\n", a->func, a->line);
  44295. + free_allocation(a->ctx, a->addr, NULL, -1);
  44296. + }
  44297. +
  44298. + __DWC_FREE(manager->mem_ctx, manager);
  44299. +}
  44300. +
  44301. +void dwc_memory_debug_report(void)
  44302. +{
  44303. + struct allocation *a;
  44304. +
  44305. + DWC_PRINTF("\n\n\n----------------- Memory Debugging Report -----------------\n\n");
  44306. + DWC_PRINTF("Num Allocations = %d\n", manager->num);
  44307. + DWC_PRINTF("Freed = %d\n", manager->num_freed);
  44308. + DWC_PRINTF("Active = %d\n", manager->num_active);
  44309. + DWC_PRINTF("Current Memory Used = %d\n", manager->cur);
  44310. + DWC_PRINTF("Total Memory Used = %d\n", manager->total);
  44311. + DWC_PRINTF("Maximum Memory Used at Once = %d\n", manager->max);
  44312. + DWC_PRINTF("Unfreed allocations:\n");
  44313. +
  44314. + DWC_CIRCLEQ_FOREACH(a, &manager->allocations, entry) {
  44315. + DWC_PRINTF(" addr=%p, size=%d from %s:%d, DMA=%d\n",
  44316. + a->addr, a->size, a->func, a->line, a->dma);
  44317. + }
  44318. +}
  44319. +
  44320. +/* The replacement functions */
  44321. +void *dwc_alloc_debug(void *mem_ctx, uint32_t size, char const *func, int line)
  44322. +{
  44323. + void *addr = __DWC_ALLOC(mem_ctx, size);
  44324. +
  44325. + if (!addr) {
  44326. + return NULL;
  44327. + }
  44328. +
  44329. + if (add_allocation(mem_ctx, size, func, line, addr, 0)) {
  44330. + __DWC_FREE(mem_ctx, addr);
  44331. + return NULL;
  44332. + }
  44333. +
  44334. + return addr;
  44335. +}
  44336. +
  44337. +void *dwc_alloc_atomic_debug(void *mem_ctx, uint32_t size, char const *func,
  44338. + int line)
  44339. +{
  44340. + void *addr = __DWC_ALLOC_ATOMIC(mem_ctx, size);
  44341. +
  44342. + if (!addr) {
  44343. + return NULL;
  44344. + }
  44345. +
  44346. + if (add_allocation(mem_ctx, size, func, line, addr, 0)) {
  44347. + __DWC_FREE(mem_ctx, addr);
  44348. + return NULL;
  44349. + }
  44350. +
  44351. + return addr;
  44352. +}
  44353. +
  44354. +void dwc_free_debug(void *mem_ctx, void *addr, char const *func, int line)
  44355. +{
  44356. + free_allocation(mem_ctx, addr, func, line);
  44357. + __DWC_FREE(mem_ctx, addr);
  44358. +}
  44359. +
  44360. +void *dwc_dma_alloc_debug(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr,
  44361. + char const *func, int line)
  44362. +{
  44363. + void *addr = __DWC_DMA_ALLOC(dma_ctx, size, dma_addr);
  44364. +
  44365. + if (!addr) {
  44366. + return NULL;
  44367. + }
  44368. +
  44369. + if (add_allocation(dma_ctx, size, func, line, addr, 1)) {
  44370. + __DWC_DMA_FREE(dma_ctx, size, addr, *dma_addr);
  44371. + return NULL;
  44372. + }
  44373. +
  44374. + return addr;
  44375. +}
  44376. +
  44377. +void *dwc_dma_alloc_atomic_debug(void *dma_ctx, uint32_t size,
  44378. + dwc_dma_t *dma_addr, char const *func, int line)
  44379. +{
  44380. + void *addr = __DWC_DMA_ALLOC_ATOMIC(dma_ctx, size, dma_addr);
  44381. +
  44382. + if (!addr) {
  44383. + return NULL;
  44384. + }
  44385. +
  44386. + if (add_allocation(dma_ctx, size, func, line, addr, 1)) {
  44387. + __DWC_DMA_FREE(dma_ctx, size, addr, *dma_addr);
  44388. + return NULL;
  44389. + }
  44390. +
  44391. + return addr;
  44392. +}
  44393. +
  44394. +void dwc_dma_free_debug(void *dma_ctx, uint32_t size, void *virt_addr,
  44395. + dwc_dma_t dma_addr, char const *func, int line)
  44396. +{
  44397. + free_allocation(dma_ctx, virt_addr, func, line);
  44398. + __DWC_DMA_FREE(dma_ctx, size, virt_addr, dma_addr);
  44399. +}
  44400. +
  44401. +#endif /* DWC_DEBUG_MEMORY */
  44402. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_common_port/dwc_modpow.c linux-3.13.3/drivers/usb/host/dwc_common_port/dwc_modpow.c
  44403. --- linux-3.13.3.orig/drivers/usb/host/dwc_common_port/dwc_modpow.c 1970-01-01 01:00:00.000000000 +0100
  44404. +++ linux-3.13.3/drivers/usb/host/dwc_common_port/dwc_modpow.c 2014-02-17 22:41:01.000000000 +0100
  44405. @@ -0,0 +1,636 @@
  44406. +/* Bignum routines adapted from PUTTY sources. PuTTY copyright notice follows.
  44407. + *
  44408. + * PuTTY is copyright 1997-2007 Simon Tatham.
  44409. + *
  44410. + * Portions copyright Robert de Bath, Joris van Rantwijk, Delian
  44411. + * Delchev, Andreas Schultz, Jeroen Massar, Wez Furlong, Nicolas Barry,
  44412. + * Justin Bradford, Ben Harris, Malcolm Smith, Ahmad Khalifa, Markus
  44413. + * Kuhn, and CORE SDI S.A.
  44414. + *
  44415. + * Permission is hereby granted, free of charge, to any person
  44416. + * obtaining a copy of this software and associated documentation files
  44417. + * (the "Software"), to deal in the Software without restriction,
  44418. + * including without limitation the rights to use, copy, modify, merge,
  44419. + * publish, distribute, sublicense, and/or sell copies of the Software,
  44420. + * and to permit persons to whom the Software is furnished to do so,
  44421. + * subject to the following conditions:
  44422. + *
  44423. + * The above copyright notice and this permission notice shall be
  44424. + * included in all copies or substantial portions of the Software.
  44425. +
  44426. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  44427. + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  44428. + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  44429. + * NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE
  44430. + * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  44431. + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  44432. + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  44433. + *
  44434. + */
  44435. +#ifdef DWC_CRYPTOLIB
  44436. +
  44437. +#ifndef CONFIG_MACH_IPMATE
  44438. +
  44439. +#include "dwc_modpow.h"
  44440. +
  44441. +#define BIGNUM_INT_MASK 0xFFFFFFFFUL
  44442. +#define BIGNUM_TOP_BIT 0x80000000UL
  44443. +#define BIGNUM_INT_BITS 32
  44444. +
  44445. +
  44446. +static void *snmalloc(void *mem_ctx, size_t n, size_t size)
  44447. +{
  44448. + void *p;
  44449. + size *= n;
  44450. + if (size == 0) size = 1;
  44451. + p = dwc_alloc(mem_ctx, size);
  44452. + return p;
  44453. +}
  44454. +
  44455. +#define snewn(ctx, n, type) ((type *)snmalloc((ctx), (n), sizeof(type)))
  44456. +#define sfree dwc_free
  44457. +
  44458. +/*
  44459. + * Usage notes:
  44460. + * * Do not call the DIVMOD_WORD macro with expressions such as array
  44461. + * subscripts, as some implementations object to this (see below).
  44462. + * * Note that none of the division methods below will cope if the
  44463. + * quotient won't fit into BIGNUM_INT_BITS. Callers should be careful
  44464. + * to avoid this case.
  44465. + * If this condition occurs, in the case of the x86 DIV instruction,
  44466. + * an overflow exception will occur, which (according to a correspondent)
  44467. + * will manifest on Windows as something like
  44468. + * 0xC0000095: Integer overflow
  44469. + * The C variant won't give the right answer, either.
  44470. + */
  44471. +
  44472. +#define MUL_WORD(w1, w2) ((BignumDblInt)w1 * w2)
  44473. +
  44474. +#if defined __GNUC__ && defined __i386__
  44475. +#define DIVMOD_WORD(q, r, hi, lo, w) \
  44476. + __asm__("div %2" : \
  44477. + "=d" (r), "=a" (q) : \
  44478. + "r" (w), "d" (hi), "a" (lo))
  44479. +#else
  44480. +#define DIVMOD_WORD(q, r, hi, lo, w) do { \
  44481. + BignumDblInt n = (((BignumDblInt)hi) << BIGNUM_INT_BITS) | lo; \
  44482. + q = n / w; \
  44483. + r = n % w; \
  44484. +} while (0)
  44485. +#endif
  44486. +
  44487. +// q = n / w;
  44488. +// r = n % w;
  44489. +
  44490. +#define BIGNUM_INT_BYTES (BIGNUM_INT_BITS / 8)
  44491. +
  44492. +#define BIGNUM_INTERNAL
  44493. +
  44494. +static Bignum newbn(void *mem_ctx, int length)
  44495. +{
  44496. + Bignum b = snewn(mem_ctx, length + 1, BignumInt);
  44497. + //if (!b)
  44498. + //abort(); /* FIXME */
  44499. + DWC_MEMSET(b, 0, (length + 1) * sizeof(*b));
  44500. + b[0] = length;
  44501. + return b;
  44502. +}
  44503. +
  44504. +void freebn(void *mem_ctx, Bignum b)
  44505. +{
  44506. + /*
  44507. + * Burn the evidence, just in case.
  44508. + */
  44509. + DWC_MEMSET(b, 0, sizeof(b[0]) * (b[0] + 1));
  44510. + sfree(mem_ctx, b);
  44511. +}
  44512. +
  44513. +/*
  44514. + * Compute c = a * b.
  44515. + * Input is in the first len words of a and b.
  44516. + * Result is returned in the first 2*len words of c.
  44517. + */
  44518. +static void internal_mul(BignumInt *a, BignumInt *b,
  44519. + BignumInt *c, int len)
  44520. +{
  44521. + int i, j;
  44522. + BignumDblInt t;
  44523. +
  44524. + for (j = 0; j < 2 * len; j++)
  44525. + c[j] = 0;
  44526. +
  44527. + for (i = len - 1; i >= 0; i--) {
  44528. + t = 0;
  44529. + for (j = len - 1; j >= 0; j--) {
  44530. + t += MUL_WORD(a[i], (BignumDblInt) b[j]);
  44531. + t += (BignumDblInt) c[i + j + 1];
  44532. + c[i + j + 1] = (BignumInt) t;
  44533. + t = t >> BIGNUM_INT_BITS;
  44534. + }
  44535. + c[i] = (BignumInt) t;
  44536. + }
  44537. +}
  44538. +
  44539. +static void internal_add_shifted(BignumInt *number,
  44540. + unsigned n, int shift)
  44541. +{
  44542. + int word = 1 + (shift / BIGNUM_INT_BITS);
  44543. + int bshift = shift % BIGNUM_INT_BITS;
  44544. + BignumDblInt addend;
  44545. +
  44546. + addend = (BignumDblInt)n << bshift;
  44547. +
  44548. + while (addend) {
  44549. + addend += number[word];
  44550. + number[word] = (BignumInt) addend & BIGNUM_INT_MASK;
  44551. + addend >>= BIGNUM_INT_BITS;
  44552. + word++;
  44553. + }
  44554. +}
  44555. +
  44556. +/*
  44557. + * Compute a = a % m.
  44558. + * Input in first alen words of a and first mlen words of m.
  44559. + * Output in first alen words of a
  44560. + * (of which first alen-mlen words will be zero).
  44561. + * The MSW of m MUST have its high bit set.
  44562. + * Quotient is accumulated in the `quotient' array, which is a Bignum
  44563. + * rather than the internal bigendian format. Quotient parts are shifted
  44564. + * left by `qshift' before adding into quot.
  44565. + */
  44566. +static void internal_mod(BignumInt *a, int alen,
  44567. + BignumInt *m, int mlen,
  44568. + BignumInt *quot, int qshift)
  44569. +{
  44570. + BignumInt m0, m1;
  44571. + unsigned int h;
  44572. + int i, k;
  44573. +
  44574. + m0 = m[0];
  44575. + if (mlen > 1)
  44576. + m1 = m[1];
  44577. + else
  44578. + m1 = 0;
  44579. +
  44580. + for (i = 0; i <= alen - mlen; i++) {
  44581. + BignumDblInt t;
  44582. + unsigned int q, r, c, ai1;
  44583. +
  44584. + if (i == 0) {
  44585. + h = 0;
  44586. + } else {
  44587. + h = a[i - 1];
  44588. + a[i - 1] = 0;
  44589. + }
  44590. +
  44591. + if (i == alen - 1)
  44592. + ai1 = 0;
  44593. + else
  44594. + ai1 = a[i + 1];
  44595. +
  44596. + /* Find q = h:a[i] / m0 */
  44597. + if (h >= m0) {
  44598. + /*
  44599. + * Special case.
  44600. + *
  44601. + * To illustrate it, suppose a BignumInt is 8 bits, and
  44602. + * we are dividing (say) A1:23:45:67 by A1:B2:C3. Then
  44603. + * our initial division will be 0xA123 / 0xA1, which
  44604. + * will give a quotient of 0x100 and a divide overflow.
  44605. + * However, the invariants in this division algorithm
  44606. + * are not violated, since the full number A1:23:... is
  44607. + * _less_ than the quotient prefix A1:B2:... and so the
  44608. + * following correction loop would have sorted it out.
  44609. + *
  44610. + * In this situation we set q to be the largest
  44611. + * quotient we _can_ stomach (0xFF, of course).
  44612. + */
  44613. + q = BIGNUM_INT_MASK;
  44614. + } else {
  44615. + /* Macro doesn't want an array subscript expression passed
  44616. + * into it (see definition), so use a temporary. */
  44617. + BignumInt tmplo = a[i];
  44618. + DIVMOD_WORD(q, r, h, tmplo, m0);
  44619. +
  44620. + /* Refine our estimate of q by looking at
  44621. + h:a[i]:a[i+1] / m0:m1 */
  44622. + t = MUL_WORD(m1, q);
  44623. + if (t > ((BignumDblInt) r << BIGNUM_INT_BITS) + ai1) {
  44624. + q--;
  44625. + t -= m1;
  44626. + r = (r + m0) & BIGNUM_INT_MASK; /* overflow? */
  44627. + if (r >= (BignumDblInt) m0 &&
  44628. + t > ((BignumDblInt) r << BIGNUM_INT_BITS) + ai1) q--;
  44629. + }
  44630. + }
  44631. +
  44632. + /* Subtract q * m from a[i...] */
  44633. + c = 0;
  44634. + for (k = mlen - 1; k >= 0; k--) {
  44635. + t = MUL_WORD(q, m[k]);
  44636. + t += c;
  44637. + c = (unsigned)(t >> BIGNUM_INT_BITS);
  44638. + if ((BignumInt) t > a[i + k])
  44639. + c++;
  44640. + a[i + k] -= (BignumInt) t;
  44641. + }
  44642. +
  44643. + /* Add back m in case of borrow */
  44644. + if (c != h) {
  44645. + t = 0;
  44646. + for (k = mlen - 1; k >= 0; k--) {
  44647. + t += m[k];
  44648. + t += a[i + k];
  44649. + a[i + k] = (BignumInt) t;
  44650. + t = t >> BIGNUM_INT_BITS;
  44651. + }
  44652. + q--;
  44653. + }
  44654. + if (quot)
  44655. + internal_add_shifted(quot, q, qshift + BIGNUM_INT_BITS * (alen - mlen - i));
  44656. + }
  44657. +}
  44658. +
  44659. +/*
  44660. + * Compute p % mod.
  44661. + * The most significant word of mod MUST be non-zero.
  44662. + * We assume that the result array is the same size as the mod array.
  44663. + * We optionally write out a quotient if `quotient' is non-NULL.
  44664. + * We can avoid writing out the result if `result' is NULL.
  44665. + */
  44666. +void bigdivmod(void *mem_ctx, Bignum p, Bignum mod, Bignum result, Bignum quotient)
  44667. +{
  44668. + BignumInt *n, *m;
  44669. + int mshift;
  44670. + int plen, mlen, i, j;
  44671. +
  44672. + /* Allocate m of size mlen, copy mod to m */
  44673. + /* We use big endian internally */
  44674. + mlen = mod[0];
  44675. + m = snewn(mem_ctx, mlen, BignumInt);
  44676. + //if (!m)
  44677. + //abort(); /* FIXME */
  44678. + for (j = 0; j < mlen; j++)
  44679. + m[j] = mod[mod[0] - j];
  44680. +
  44681. + /* Shift m left to make msb bit set */
  44682. + for (mshift = 0; mshift < BIGNUM_INT_BITS-1; mshift++)
  44683. + if ((m[0] << mshift) & BIGNUM_TOP_BIT)
  44684. + break;
  44685. + if (mshift) {
  44686. + for (i = 0; i < mlen - 1; i++)
  44687. + m[i] = (m[i] << mshift) | (m[i + 1] >> (BIGNUM_INT_BITS - mshift));
  44688. + m[mlen - 1] = m[mlen - 1] << mshift;
  44689. + }
  44690. +
  44691. + plen = p[0];
  44692. + /* Ensure plen > mlen */
  44693. + if (plen <= mlen)
  44694. + plen = mlen + 1;
  44695. +
  44696. + /* Allocate n of size plen, copy p to n */
  44697. + n = snewn(mem_ctx, plen, BignumInt);
  44698. + //if (!n)
  44699. + //abort(); /* FIXME */
  44700. + for (j = 0; j < plen; j++)
  44701. + n[j] = 0;
  44702. + for (j = 1; j <= (int)p[0]; j++)
  44703. + n[plen - j] = p[j];
  44704. +
  44705. + /* Main computation */
  44706. + internal_mod(n, plen, m, mlen, quotient, mshift);
  44707. +
  44708. + /* Fixup result in case the modulus was shifted */
  44709. + if (mshift) {
  44710. + for (i = plen - mlen - 1; i < plen - 1; i++)
  44711. + n[i] = (n[i] << mshift) | (n[i + 1] >> (BIGNUM_INT_BITS - mshift));
  44712. + n[plen - 1] = n[plen - 1] << mshift;
  44713. + internal_mod(n, plen, m, mlen, quotient, 0);
  44714. + for (i = plen - 1; i >= plen - mlen; i--)
  44715. + n[i] = (n[i] >> mshift) | (n[i - 1] << (BIGNUM_INT_BITS - mshift));
  44716. + }
  44717. +
  44718. + /* Copy result to buffer */
  44719. + if (result) {
  44720. + for (i = 1; i <= (int)result[0]; i++) {
  44721. + int j = plen - i;
  44722. + result[i] = j >= 0 ? n[j] : 0;
  44723. + }
  44724. + }
  44725. +
  44726. + /* Free temporary arrays */
  44727. + for (i = 0; i < mlen; i++)
  44728. + m[i] = 0;
  44729. + sfree(mem_ctx, m);
  44730. + for (i = 0; i < plen; i++)
  44731. + n[i] = 0;
  44732. + sfree(mem_ctx, n);
  44733. +}
  44734. +
  44735. +/*
  44736. + * Simple remainder.
  44737. + */
  44738. +Bignum bigmod(void *mem_ctx, Bignum a, Bignum b)
  44739. +{
  44740. + Bignum r = newbn(mem_ctx, b[0]);
  44741. + bigdivmod(mem_ctx, a, b, r, NULL);
  44742. + return r;
  44743. +}
  44744. +
  44745. +/*
  44746. + * Compute (base ^ exp) % mod.
  44747. + */
  44748. +Bignum dwc_modpow(void *mem_ctx, Bignum base_in, Bignum exp, Bignum mod)
  44749. +{
  44750. + BignumInt *a, *b, *n, *m;
  44751. + int mshift;
  44752. + int mlen, i, j;
  44753. + Bignum base, result;
  44754. +
  44755. + /*
  44756. + * The most significant word of mod needs to be non-zero. It
  44757. + * should already be, but let's make sure.
  44758. + */
  44759. + //assert(mod[mod[0]] != 0);
  44760. +
  44761. + /*
  44762. + * Make sure the base is smaller than the modulus, by reducing
  44763. + * it modulo the modulus if not.
  44764. + */
  44765. + base = bigmod(mem_ctx, base_in, mod);
  44766. +
  44767. + /* Allocate m of size mlen, copy mod to m */
  44768. + /* We use big endian internally */
  44769. + mlen = mod[0];
  44770. + m = snewn(mem_ctx, mlen, BignumInt);
  44771. + //if (!m)
  44772. + //abort(); /* FIXME */
  44773. + for (j = 0; j < mlen; j++)
  44774. + m[j] = mod[mod[0] - j];
  44775. +
  44776. + /* Shift m left to make msb bit set */
  44777. + for (mshift = 0; mshift < BIGNUM_INT_BITS - 1; mshift++)
  44778. + if ((m[0] << mshift) & BIGNUM_TOP_BIT)
  44779. + break;
  44780. + if (mshift) {
  44781. + for (i = 0; i < mlen - 1; i++)
  44782. + m[i] =
  44783. + (m[i] << mshift) | (m[i + 1] >>
  44784. + (BIGNUM_INT_BITS - mshift));
  44785. + m[mlen - 1] = m[mlen - 1] << mshift;
  44786. + }
  44787. +
  44788. + /* Allocate n of size mlen, copy base to n */
  44789. + n = snewn(mem_ctx, mlen, BignumInt);
  44790. + //if (!n)
  44791. + //abort(); /* FIXME */
  44792. + i = mlen - base[0];
  44793. + for (j = 0; j < i; j++)
  44794. + n[j] = 0;
  44795. + for (j = 0; j < base[0]; j++)
  44796. + n[i + j] = base[base[0] - j];
  44797. +
  44798. + /* Allocate a and b of size 2*mlen. Set a = 1 */
  44799. + a = snewn(mem_ctx, 2 * mlen, BignumInt);
  44800. + //if (!a)
  44801. + //abort(); /* FIXME */
  44802. + b = snewn(mem_ctx, 2 * mlen, BignumInt);
  44803. + //if (!b)
  44804. + //abort(); /* FIXME */
  44805. + for (i = 0; i < 2 * mlen; i++)
  44806. + a[i] = 0;
  44807. + a[2 * mlen - 1] = 1;
  44808. +
  44809. + /* Skip leading zero bits of exp. */
  44810. + i = 0;
  44811. + j = BIGNUM_INT_BITS - 1;
  44812. + while (i < exp[0] && (exp[exp[0] - i] & (1 << j)) == 0) {
  44813. + j--;
  44814. + if (j < 0) {
  44815. + i++;
  44816. + j = BIGNUM_INT_BITS - 1;
  44817. + }
  44818. + }
  44819. +
  44820. + /* Main computation */
  44821. + while (i < exp[0]) {
  44822. + while (j >= 0) {
  44823. + internal_mul(a + mlen, a + mlen, b, mlen);
  44824. + internal_mod(b, mlen * 2, m, mlen, NULL, 0);
  44825. + if ((exp[exp[0] - i] & (1 << j)) != 0) {
  44826. + internal_mul(b + mlen, n, a, mlen);
  44827. + internal_mod(a, mlen * 2, m, mlen, NULL, 0);
  44828. + } else {
  44829. + BignumInt *t;
  44830. + t = a;
  44831. + a = b;
  44832. + b = t;
  44833. + }
  44834. + j--;
  44835. + }
  44836. + i++;
  44837. + j = BIGNUM_INT_BITS - 1;
  44838. + }
  44839. +
  44840. + /* Fixup result in case the modulus was shifted */
  44841. + if (mshift) {
  44842. + for (i = mlen - 1; i < 2 * mlen - 1; i++)
  44843. + a[i] =
  44844. + (a[i] << mshift) | (a[i + 1] >>
  44845. + (BIGNUM_INT_BITS - mshift));
  44846. + a[2 * mlen - 1] = a[2 * mlen - 1] << mshift;
  44847. + internal_mod(a, mlen * 2, m, mlen, NULL, 0);
  44848. + for (i = 2 * mlen - 1; i >= mlen; i--)
  44849. + a[i] =
  44850. + (a[i] >> mshift) | (a[i - 1] <<
  44851. + (BIGNUM_INT_BITS - mshift));
  44852. + }
  44853. +
  44854. + /* Copy result to buffer */
  44855. + result = newbn(mem_ctx, mod[0]);
  44856. + for (i = 0; i < mlen; i++)
  44857. + result[result[0] - i] = a[i + mlen];
  44858. + while (result[0] > 1 && result[result[0]] == 0)
  44859. + result[0]--;
  44860. +
  44861. + /* Free temporary arrays */
  44862. + for (i = 0; i < 2 * mlen; i++)
  44863. + a[i] = 0;
  44864. + sfree(mem_ctx, a);
  44865. + for (i = 0; i < 2 * mlen; i++)
  44866. + b[i] = 0;
  44867. + sfree(mem_ctx, b);
  44868. + for (i = 0; i < mlen; i++)
  44869. + m[i] = 0;
  44870. + sfree(mem_ctx, m);
  44871. + for (i = 0; i < mlen; i++)
  44872. + n[i] = 0;
  44873. + sfree(mem_ctx, n);
  44874. +
  44875. + freebn(mem_ctx, base);
  44876. +
  44877. + return result;
  44878. +}
  44879. +
  44880. +
  44881. +#ifdef UNITTEST
  44882. +
  44883. +static __u32 dh_p[] = {
  44884. + 96,
  44885. + 0xFFFFFFFF,
  44886. + 0xFFFFFFFF,
  44887. + 0xA93AD2CA,
  44888. + 0x4B82D120,
  44889. + 0xE0FD108E,
  44890. + 0x43DB5BFC,
  44891. + 0x74E5AB31,
  44892. + 0x08E24FA0,
  44893. + 0xBAD946E2,
  44894. + 0x770988C0,
  44895. + 0x7A615D6C,
  44896. + 0xBBE11757,
  44897. + 0x177B200C,
  44898. + 0x521F2B18,
  44899. + 0x3EC86A64,
  44900. + 0xD8760273,
  44901. + 0xD98A0864,
  44902. + 0xF12FFA06,
  44903. + 0x1AD2EE6B,
  44904. + 0xCEE3D226,
  44905. + 0x4A25619D,
  44906. + 0x1E8C94E0,
  44907. + 0xDB0933D7,
  44908. + 0xABF5AE8C,
  44909. + 0xA6E1E4C7,
  44910. + 0xB3970F85,
  44911. + 0x5D060C7D,
  44912. + 0x8AEA7157,
  44913. + 0x58DBEF0A,
  44914. + 0xECFB8504,
  44915. + 0xDF1CBA64,
  44916. + 0xA85521AB,
  44917. + 0x04507A33,
  44918. + 0xAD33170D,
  44919. + 0x8AAAC42D,
  44920. + 0x15728E5A,
  44921. + 0x98FA0510,
  44922. + 0x15D22618,
  44923. + 0xEA956AE5,
  44924. + 0x3995497C,
  44925. + 0x95581718,
  44926. + 0xDE2BCBF6,
  44927. + 0x6F4C52C9,
  44928. + 0xB5C55DF0,
  44929. + 0xEC07A28F,
  44930. + 0x9B2783A2,
  44931. + 0x180E8603,
  44932. + 0xE39E772C,
  44933. + 0x2E36CE3B,
  44934. + 0x32905E46,
  44935. + 0xCA18217C,
  44936. + 0xF1746C08,
  44937. + 0x4ABC9804,
  44938. + 0x670C354E,
  44939. + 0x7096966D,
  44940. + 0x9ED52907,
  44941. + 0x208552BB,
  44942. + 0x1C62F356,
  44943. + 0xDCA3AD96,
  44944. + 0x83655D23,
  44945. + 0xFD24CF5F,
  44946. + 0x69163FA8,
  44947. + 0x1C55D39A,
  44948. + 0x98DA4836,
  44949. + 0xA163BF05,
  44950. + 0xC2007CB8,
  44951. + 0xECE45B3D,
  44952. + 0x49286651,
  44953. + 0x7C4B1FE6,
  44954. + 0xAE9F2411,
  44955. + 0x5A899FA5,
  44956. + 0xEE386BFB,
  44957. + 0xF406B7ED,
  44958. + 0x0BFF5CB6,
  44959. + 0xA637ED6B,
  44960. + 0xF44C42E9,
  44961. + 0x625E7EC6,
  44962. + 0xE485B576,
  44963. + 0x6D51C245,
  44964. + 0x4FE1356D,
  44965. + 0xF25F1437,
  44966. + 0x302B0A6D,
  44967. + 0xCD3A431B,
  44968. + 0xEF9519B3,
  44969. + 0x8E3404DD,
  44970. + 0x514A0879,
  44971. + 0x3B139B22,
  44972. + 0x020BBEA6,
  44973. + 0x8A67CC74,
  44974. + 0x29024E08,
  44975. + 0x80DC1CD1,
  44976. + 0xC4C6628B,
  44977. + 0x2168C234,
  44978. + 0xC90FDAA2,
  44979. + 0xFFFFFFFF,
  44980. + 0xFFFFFFFF,
  44981. +};
  44982. +
  44983. +static __u32 dh_a[] = {
  44984. + 8,
  44985. + 0xdf367516,
  44986. + 0x86459caa,
  44987. + 0xe2d459a4,
  44988. + 0xd910dae0,
  44989. + 0x8a8b5e37,
  44990. + 0x67ab31c6,
  44991. + 0xf0b55ea9,
  44992. + 0x440051d6,
  44993. +};
  44994. +
  44995. +static __u32 dh_b[] = {
  44996. + 8,
  44997. + 0xded92656,
  44998. + 0xe07a048a,
  44999. + 0x6fa452cd,
  45000. + 0x2df89d30,
  45001. + 0xc75f1b0f,
  45002. + 0x8ce3578f,
  45003. + 0x7980a324,
  45004. + 0x5daec786,
  45005. +};
  45006. +
  45007. +static __u32 dh_g[] = {
  45008. + 1,
  45009. + 2,
  45010. +};
  45011. +
  45012. +int main(void)
  45013. +{
  45014. + int i;
  45015. + __u32 *k;
  45016. + k = dwc_modpow(NULL, dh_g, dh_a, dh_p);
  45017. +
  45018. + printf("\n\n");
  45019. + for (i=0; i<k[0]; i++) {
  45020. + __u32 word32 = k[k[0] - i];
  45021. + __u16 l = word32 & 0xffff;
  45022. + __u16 m = (word32 & 0xffff0000) >> 16;
  45023. + printf("%04x %04x ", m, l);
  45024. + if (!((i + 1)%13)) printf("\n");
  45025. + }
  45026. + printf("\n\n");
  45027. +
  45028. + if ((k[0] == 0x60) && (k[1] == 0x28e490e5) && (k[0x60] == 0x5a0d3d4e)) {
  45029. + printf("PASS\n\n");
  45030. + }
  45031. + else {
  45032. + printf("FAIL\n\n");
  45033. + }
  45034. +
  45035. +}
  45036. +
  45037. +#endif /* UNITTEST */
  45038. +
  45039. +#endif /* CONFIG_MACH_IPMATE */
  45040. +
  45041. +#endif /*DWC_CRYPTOLIB */
  45042. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_common_port/dwc_modpow.h linux-3.13.3/drivers/usb/host/dwc_common_port/dwc_modpow.h
  45043. --- linux-3.13.3.orig/drivers/usb/host/dwc_common_port/dwc_modpow.h 1970-01-01 01:00:00.000000000 +0100
  45044. +++ linux-3.13.3/drivers/usb/host/dwc_common_port/dwc_modpow.h 2014-02-17 22:41:01.000000000 +0100
  45045. @@ -0,0 +1,34 @@
  45046. +/*
  45047. + * dwc_modpow.h
  45048. + * See dwc_modpow.c for license and changes
  45049. + */
  45050. +#ifndef _DWC_MODPOW_H
  45051. +#define _DWC_MODPOW_H
  45052. +
  45053. +#ifdef __cplusplus
  45054. +extern "C" {
  45055. +#endif
  45056. +
  45057. +#include "dwc_os.h"
  45058. +
  45059. +/** @file
  45060. + *
  45061. + * This file defines the module exponentiation function which is only used
  45062. + * internally by the DWC UWB modules for calculation of PKs during numeric
  45063. + * association. The routine is taken from the PUTTY, an open source terminal
  45064. + * emulator. The PUTTY License is preserved in the dwc_modpow.c file.
  45065. + *
  45066. + */
  45067. +
  45068. +typedef uint32_t BignumInt;
  45069. +typedef uint64_t BignumDblInt;
  45070. +typedef BignumInt *Bignum;
  45071. +
  45072. +/* Compute modular exponentiaion */
  45073. +extern Bignum dwc_modpow(void *mem_ctx, Bignum base_in, Bignum exp, Bignum mod);
  45074. +
  45075. +#ifdef __cplusplus
  45076. +}
  45077. +#endif
  45078. +
  45079. +#endif /* _LINUX_BIGNUM_H */
  45080. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_common_port/dwc_notifier.c linux-3.13.3/drivers/usb/host/dwc_common_port/dwc_notifier.c
  45081. --- linux-3.13.3.orig/drivers/usb/host/dwc_common_port/dwc_notifier.c 1970-01-01 01:00:00.000000000 +0100
  45082. +++ linux-3.13.3/drivers/usb/host/dwc_common_port/dwc_notifier.c 2014-02-17 22:41:01.000000000 +0100
  45083. @@ -0,0 +1,319 @@
  45084. +#ifdef DWC_NOTIFYLIB
  45085. +
  45086. +#include "dwc_notifier.h"
  45087. +#include "dwc_list.h"
  45088. +
  45089. +typedef struct dwc_observer {
  45090. + void *observer;
  45091. + dwc_notifier_callback_t callback;
  45092. + void *data;
  45093. + char *notification;
  45094. + DWC_CIRCLEQ_ENTRY(dwc_observer) list_entry;
  45095. +} observer_t;
  45096. +
  45097. +DWC_CIRCLEQ_HEAD(observer_queue, dwc_observer);
  45098. +
  45099. +typedef struct dwc_notifier {
  45100. + void *mem_ctx;
  45101. + void *object;
  45102. + struct observer_queue observers;
  45103. + DWC_CIRCLEQ_ENTRY(dwc_notifier) list_entry;
  45104. +} notifier_t;
  45105. +
  45106. +DWC_CIRCLEQ_HEAD(notifier_queue, dwc_notifier);
  45107. +
  45108. +typedef struct manager {
  45109. + void *mem_ctx;
  45110. + void *wkq_ctx;
  45111. + dwc_workq_t *wq;
  45112. +// dwc_mutex_t *mutex;
  45113. + struct notifier_queue notifiers;
  45114. +} manager_t;
  45115. +
  45116. +static manager_t *manager = NULL;
  45117. +
  45118. +static int create_manager(void *mem_ctx, void *wkq_ctx)
  45119. +{
  45120. + manager = dwc_alloc(mem_ctx, sizeof(manager_t));
  45121. + if (!manager) {
  45122. + return -DWC_E_NO_MEMORY;
  45123. + }
  45124. +
  45125. + DWC_CIRCLEQ_INIT(&manager->notifiers);
  45126. +
  45127. + manager->wq = dwc_workq_alloc(wkq_ctx, "DWC Notification WorkQ");
  45128. + if (!manager->wq) {
  45129. + return -DWC_E_NO_MEMORY;
  45130. + }
  45131. +
  45132. + return 0;
  45133. +}
  45134. +
  45135. +static void free_manager(void)
  45136. +{
  45137. + dwc_workq_free(manager->wq);
  45138. +
  45139. + /* All notifiers must have unregistered themselves before this module
  45140. + * can be removed. Hitting this assertion indicates a programmer
  45141. + * error. */
  45142. + DWC_ASSERT(DWC_CIRCLEQ_EMPTY(&manager->notifiers),
  45143. + "Notification manager being freed before all notifiers have been removed");
  45144. + dwc_free(manager->mem_ctx, manager);
  45145. +}
  45146. +
  45147. +#ifdef DEBUG
  45148. +static void dump_manager(void)
  45149. +{
  45150. + notifier_t *n;
  45151. + observer_t *o;
  45152. +
  45153. + DWC_ASSERT(manager, "Notification manager not found");
  45154. +
  45155. + DWC_DEBUG("List of all notifiers and observers:\n");
  45156. + DWC_CIRCLEQ_FOREACH(n, &manager->notifiers, list_entry) {
  45157. + DWC_DEBUG("Notifier %p has observers:\n", n->object);
  45158. + DWC_CIRCLEQ_FOREACH(o, &n->observers, list_entry) {
  45159. + DWC_DEBUG(" %p watching %s\n", o->observer, o->notification);
  45160. + }
  45161. + }
  45162. +}
  45163. +#else
  45164. +#define dump_manager(...)
  45165. +#endif
  45166. +
  45167. +static observer_t *alloc_observer(void *mem_ctx, void *observer, char *notification,
  45168. + dwc_notifier_callback_t callback, void *data)
  45169. +{
  45170. + observer_t *new_observer = dwc_alloc(mem_ctx, sizeof(observer_t));
  45171. +
  45172. + if (!new_observer) {
  45173. + return NULL;
  45174. + }
  45175. +
  45176. + DWC_CIRCLEQ_INIT_ENTRY(new_observer, list_entry);
  45177. + new_observer->observer = observer;
  45178. + new_observer->notification = notification;
  45179. + new_observer->callback = callback;
  45180. + new_observer->data = data;
  45181. + return new_observer;
  45182. +}
  45183. +
  45184. +static void free_observer(void *mem_ctx, observer_t *observer)
  45185. +{
  45186. + dwc_free(mem_ctx, observer);
  45187. +}
  45188. +
  45189. +static notifier_t *alloc_notifier(void *mem_ctx, void *object)
  45190. +{
  45191. + notifier_t *notifier;
  45192. +
  45193. + if (!object) {
  45194. + return NULL;
  45195. + }
  45196. +
  45197. + notifier = dwc_alloc(mem_ctx, sizeof(notifier_t));
  45198. + if (!notifier) {
  45199. + return NULL;
  45200. + }
  45201. +
  45202. + DWC_CIRCLEQ_INIT(&notifier->observers);
  45203. + DWC_CIRCLEQ_INIT_ENTRY(notifier, list_entry);
  45204. +
  45205. + notifier->mem_ctx = mem_ctx;
  45206. + notifier->object = object;
  45207. + return notifier;
  45208. +}
  45209. +
  45210. +static void free_notifier(notifier_t *notifier)
  45211. +{
  45212. + observer_t *observer;
  45213. +
  45214. + DWC_CIRCLEQ_FOREACH(observer, &notifier->observers, list_entry) {
  45215. + free_observer(notifier->mem_ctx, observer);
  45216. + }
  45217. +
  45218. + dwc_free(notifier->mem_ctx, notifier);
  45219. +}
  45220. +
  45221. +static notifier_t *find_notifier(void *object)
  45222. +{
  45223. + notifier_t *notifier;
  45224. +
  45225. + DWC_ASSERT(manager, "Notification manager not found");
  45226. +
  45227. + if (!object) {
  45228. + return NULL;
  45229. + }
  45230. +
  45231. + DWC_CIRCLEQ_FOREACH(notifier, &manager->notifiers, list_entry) {
  45232. + if (notifier->object == object) {
  45233. + return notifier;
  45234. + }
  45235. + }
  45236. +
  45237. + return NULL;
  45238. +}
  45239. +
  45240. +int dwc_alloc_notification_manager(void *mem_ctx, void *wkq_ctx)
  45241. +{
  45242. + return create_manager(mem_ctx, wkq_ctx);
  45243. +}
  45244. +
  45245. +void dwc_free_notification_manager(void)
  45246. +{
  45247. + free_manager();
  45248. +}
  45249. +
  45250. +dwc_notifier_t *dwc_register_notifier(void *mem_ctx, void *object)
  45251. +{
  45252. + notifier_t *notifier;
  45253. +
  45254. + DWC_ASSERT(manager, "Notification manager not found");
  45255. +
  45256. + notifier = find_notifier(object);
  45257. + if (notifier) {
  45258. + DWC_ERROR("Notifier %p is already registered\n", object);
  45259. + return NULL;
  45260. + }
  45261. +
  45262. + notifier = alloc_notifier(mem_ctx, object);
  45263. + if (!notifier) {
  45264. + return NULL;
  45265. + }
  45266. +
  45267. + DWC_CIRCLEQ_INSERT_TAIL(&manager->notifiers, notifier, list_entry);
  45268. +
  45269. + DWC_INFO("Notifier %p registered", object);
  45270. + dump_manager();
  45271. +
  45272. + return notifier;
  45273. +}
  45274. +
  45275. +void dwc_unregister_notifier(dwc_notifier_t *notifier)
  45276. +{
  45277. + DWC_ASSERT(manager, "Notification manager not found");
  45278. +
  45279. + if (!DWC_CIRCLEQ_EMPTY(&notifier->observers)) {
  45280. + observer_t *o;
  45281. +
  45282. + DWC_ERROR("Notifier %p has active observers when removing\n", notifier->object);
  45283. + DWC_CIRCLEQ_FOREACH(o, &notifier->observers, list_entry) {
  45284. + DWC_DEBUGC(" %p watching %s\n", o->observer, o->notification);
  45285. + }
  45286. +
  45287. + DWC_ASSERT(DWC_CIRCLEQ_EMPTY(&notifier->observers),
  45288. + "Notifier %p has active observers when removing", notifier);
  45289. + }
  45290. +
  45291. + DWC_CIRCLEQ_REMOVE_INIT(&manager->notifiers, notifier, list_entry);
  45292. + free_notifier(notifier);
  45293. +
  45294. + DWC_INFO("Notifier unregistered");
  45295. + dump_manager();
  45296. +}
  45297. +
  45298. +/* Add an observer to observe the notifier for a particular state, event, or notification. */
  45299. +int dwc_add_observer(void *observer, void *object, char *notification,
  45300. + dwc_notifier_callback_t callback, void *data)
  45301. +{
  45302. + notifier_t *notifier = find_notifier(object);
  45303. + observer_t *new_observer;
  45304. +
  45305. + if (!notifier) {
  45306. + DWC_ERROR("Notifier %p is not found when adding observer\n", object);
  45307. + return -DWC_E_INVALID;
  45308. + }
  45309. +
  45310. + new_observer = alloc_observer(notifier->mem_ctx, observer, notification, callback, data);
  45311. + if (!new_observer) {
  45312. + return -DWC_E_NO_MEMORY;
  45313. + }
  45314. +
  45315. + DWC_CIRCLEQ_INSERT_TAIL(&notifier->observers, new_observer, list_entry);
  45316. +
  45317. + DWC_INFO("Added observer %p to notifier %p observing notification %s, callback=%p, data=%p",
  45318. + observer, object, notification, callback, data);
  45319. +
  45320. + dump_manager();
  45321. + return 0;
  45322. +}
  45323. +
  45324. +int dwc_remove_observer(void *observer)
  45325. +{
  45326. + notifier_t *n;
  45327. +
  45328. + DWC_ASSERT(manager, "Notification manager not found");
  45329. +
  45330. + DWC_CIRCLEQ_FOREACH(n, &manager->notifiers, list_entry) {
  45331. + observer_t *o;
  45332. + observer_t *o2;
  45333. +
  45334. + DWC_CIRCLEQ_FOREACH_SAFE(o, o2, &n->observers, list_entry) {
  45335. + if (o->observer == observer) {
  45336. + DWC_CIRCLEQ_REMOVE_INIT(&n->observers, o, list_entry);
  45337. + DWC_INFO("Removing observer %p from notifier %p watching notification %s:",
  45338. + o->observer, n->object, o->notification);
  45339. + free_observer(n->mem_ctx, o);
  45340. + }
  45341. + }
  45342. + }
  45343. +
  45344. + dump_manager();
  45345. + return 0;
  45346. +}
  45347. +
  45348. +typedef struct callback_data {
  45349. + void *mem_ctx;
  45350. + dwc_notifier_callback_t cb;
  45351. + void *observer;
  45352. + void *data;
  45353. + void *object;
  45354. + char *notification;
  45355. + void *notification_data;
  45356. +} cb_data_t;
  45357. +
  45358. +static void cb_task(void *data)
  45359. +{
  45360. + cb_data_t *cb = (cb_data_t *)data;
  45361. +
  45362. + cb->cb(cb->object, cb->notification, cb->observer, cb->notification_data, cb->data);
  45363. + dwc_free(cb->mem_ctx, cb);
  45364. +}
  45365. +
  45366. +void dwc_notify(dwc_notifier_t *notifier, char *notification, void *notification_data)
  45367. +{
  45368. + observer_t *o;
  45369. +
  45370. + DWC_ASSERT(manager, "Notification manager not found");
  45371. +
  45372. + DWC_CIRCLEQ_FOREACH(o, &notifier->observers, list_entry) {
  45373. + int len = DWC_STRLEN(notification);
  45374. +
  45375. + if (DWC_STRLEN(o->notification) != len) {
  45376. + continue;
  45377. + }
  45378. +
  45379. + if (DWC_STRNCMP(o->notification, notification, len) == 0) {
  45380. + cb_data_t *cb_data = dwc_alloc(notifier->mem_ctx, sizeof(cb_data_t));
  45381. +
  45382. + if (!cb_data) {
  45383. + DWC_ERROR("Failed to allocate callback data\n");
  45384. + return;
  45385. + }
  45386. +
  45387. + cb_data->mem_ctx = notifier->mem_ctx;
  45388. + cb_data->cb = o->callback;
  45389. + cb_data->observer = o->observer;
  45390. + cb_data->data = o->data;
  45391. + cb_data->object = notifier->object;
  45392. + cb_data->notification = notification;
  45393. + cb_data->notification_data = notification_data;
  45394. + DWC_DEBUGC("Observer found %p for notification %s\n", o->observer, notification);
  45395. + DWC_WORKQ_SCHEDULE(manager->wq, cb_task, cb_data,
  45396. + "Notify callback from %p for Notification %s, to observer %p",
  45397. + cb_data->object, notification, cb_data->observer);
  45398. + }
  45399. + }
  45400. +}
  45401. +
  45402. +#endif /* DWC_NOTIFYLIB */
  45403. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_common_port/dwc_notifier.h linux-3.13.3/drivers/usb/host/dwc_common_port/dwc_notifier.h
  45404. --- linux-3.13.3.orig/drivers/usb/host/dwc_common_port/dwc_notifier.h 1970-01-01 01:00:00.000000000 +0100
  45405. +++ linux-3.13.3/drivers/usb/host/dwc_common_port/dwc_notifier.h 2014-02-17 22:41:01.000000000 +0100
  45406. @@ -0,0 +1,122 @@
  45407. +
  45408. +#ifndef __DWC_NOTIFIER_H__
  45409. +#define __DWC_NOTIFIER_H__
  45410. +
  45411. +#ifdef __cplusplus
  45412. +extern "C" {
  45413. +#endif
  45414. +
  45415. +#include "dwc_os.h"
  45416. +
  45417. +/** @file
  45418. + *
  45419. + * A simple implementation of the Observer pattern. Any "module" can
  45420. + * register as an observer or notifier. The notion of "module" is abstract and
  45421. + * can mean anything used to identify either an observer or notifier. Usually
  45422. + * it will be a pointer to a data structure which contains some state, ie an
  45423. + * object.
  45424. + *
  45425. + * Before any notifiers can be added, the global notification manager must be
  45426. + * brought up with dwc_alloc_notification_manager().
  45427. + * dwc_free_notification_manager() will bring it down and free all resources.
  45428. + * These would typically be called upon module load and unload. The
  45429. + * notification manager is a single global instance that handles all registered
  45430. + * observable modules and observers so this should be done only once.
  45431. + *
  45432. + * A module can be observable by using Notifications to publicize some general
  45433. + * information about it's state or operation. It does not care who listens, or
  45434. + * even if anyone listens, or what they do with the information. The observable
  45435. + * modules do not need to know any information about it's observers or their
  45436. + * interface, or their state or data.
  45437. + *
  45438. + * Any module can register to emit Notifications. It should publish a list of
  45439. + * notifications that it can emit and their behavior, such as when they will get
  45440. + * triggered, and what information will be provided to the observer. Then it
  45441. + * should register itself as an observable module. See dwc_register_notifier().
  45442. + *
  45443. + * Any module can observe any observable, registered module, provided it has a
  45444. + * handle to the other module and knows what notifications to observe. See
  45445. + * dwc_add_observer().
  45446. + *
  45447. + * A function of type dwc_notifier_callback_t is called whenever a notification
  45448. + * is triggered with one or more observers observing it. This function is
  45449. + * called in it's own process so it may sleep or block if needed. It is
  45450. + * guaranteed to be called sometime after the notification has occurred and will
  45451. + * be called once per each time the notification is triggered. It will NOT be
  45452. + * called in the same process context used to trigger the notification.
  45453. + *
  45454. + * @section Limitiations
  45455. + *
  45456. + * Keep in mind that Notifications that can be triggered in rapid sucession may
  45457. + * schedule too many processes too handle. Be aware of this limitation when
  45458. + * designing to use notifications, and only add notifications for appropriate
  45459. + * observable information.
  45460. + *
  45461. + * Also Notification callbacks are not synchronous. If you need to synchronize
  45462. + * the behavior between module/observer you must use other means. And perhaps
  45463. + * that will mean Notifications are not the proper solution.
  45464. + */
  45465. +
  45466. +struct dwc_notifier;
  45467. +typedef struct dwc_notifier dwc_notifier_t;
  45468. +
  45469. +/** The callback function must be of this type.
  45470. + *
  45471. + * @param object This is the object that is being observed.
  45472. + * @param notification This is the notification that was triggered.
  45473. + * @param observer This is the observer
  45474. + * @param notification_data This is notification-specific data that the notifier
  45475. + * has included in this notification. The value of this should be published in
  45476. + * the documentation of the observable module with the notifications.
  45477. + * @param user_data This is any custom data that the observer provided when
  45478. + * adding itself as an observer to the notification. */
  45479. +typedef void (*dwc_notifier_callback_t)(void *object, char *notification, void *observer,
  45480. + void *notification_data, void *user_data);
  45481. +
  45482. +/** Brings up the notification manager. */
  45483. +extern int dwc_alloc_notification_manager(void *mem_ctx, void *wkq_ctx);
  45484. +/** Brings down the notification manager. */
  45485. +extern void dwc_free_notification_manager(void);
  45486. +
  45487. +/** This function registers an observable module. A dwc_notifier_t object is
  45488. + * returned to the observable module. This is an opaque object that is used by
  45489. + * the observable module to trigger notifications. This object should only be
  45490. + * accessible to functions that are authorized to trigger notifications for this
  45491. + * module. Observers do not need this object. */
  45492. +extern dwc_notifier_t *dwc_register_notifier(void *mem_ctx, void *object);
  45493. +
  45494. +/** This function unregisters an observable module. All observers have to be
  45495. + * removed prior to unregistration. */
  45496. +extern void dwc_unregister_notifier(dwc_notifier_t *notifier);
  45497. +
  45498. +/** Add a module as an observer to the observable module. The observable module
  45499. + * needs to have previously registered with the notification manager.
  45500. + *
  45501. + * @param observer The observer module
  45502. + * @param object The module to observe
  45503. + * @param notification The notification to observe
  45504. + * @param callback The callback function to call
  45505. + * @param user_data Any additional user data to pass into the callback function */
  45506. +extern int dwc_add_observer(void *observer, void *object, char *notification,
  45507. + dwc_notifier_callback_t callback, void *user_data);
  45508. +
  45509. +/** Removes the specified observer from all notifications that it is currently
  45510. + * observing. */
  45511. +extern int dwc_remove_observer(void *observer);
  45512. +
  45513. +/** This function triggers a Notification. It should be called by the
  45514. + * observable module, or any module or library which the observable module
  45515. + * allows to trigger notification on it's behalf. Such as the dwc_cc_t.
  45516. + *
  45517. + * dwc_notify is a non-blocking function. Callbacks are scheduled called in
  45518. + * their own process context for each trigger. Callbacks can be blocking.
  45519. + * dwc_notify can be called from interrupt context if needed.
  45520. + *
  45521. + */
  45522. +void dwc_notify(dwc_notifier_t *notifier, char *notification, void *notification_data);
  45523. +
  45524. +#ifdef __cplusplus
  45525. +}
  45526. +#endif
  45527. +
  45528. +#endif /* __DWC_NOTIFIER_H__ */
  45529. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_common_port/dwc_os.h linux-3.13.3/drivers/usb/host/dwc_common_port/dwc_os.h
  45530. --- linux-3.13.3.orig/drivers/usb/host/dwc_common_port/dwc_os.h 1970-01-01 01:00:00.000000000 +0100
  45531. +++ linux-3.13.3/drivers/usb/host/dwc_common_port/dwc_os.h 2014-02-17 22:41:01.000000000 +0100
  45532. @@ -0,0 +1,1262 @@
  45533. +/* =========================================================================
  45534. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_os.h $
  45535. + * $Revision: #14 $
  45536. + * $Date: 2010/11/04 $
  45537. + * $Change: 1621695 $
  45538. + *
  45539. + * Synopsys Portability Library Software and documentation
  45540. + * (hereinafter, "Software") is an Unsupported proprietary work of
  45541. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  45542. + * between Synopsys and you.
  45543. + *
  45544. + * The Software IS NOT an item of Licensed Software or Licensed Product
  45545. + * under any End User Software License Agreement or Agreement for
  45546. + * Licensed Product with Synopsys or any supplement thereto. You are
  45547. + * permitted to use and redistribute this Software in source and binary
  45548. + * forms, with or without modification, provided that redistributions
  45549. + * of source code must retain this notice. You may not view, use,
  45550. + * disclose, copy or distribute this file or any information contained
  45551. + * herein except pursuant to this license grant from Synopsys. If you
  45552. + * do not agree with this notice, including the disclaimer below, then
  45553. + * you are not authorized to use the Software.
  45554. + *
  45555. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  45556. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  45557. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  45558. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  45559. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  45560. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  45561. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  45562. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  45563. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  45564. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  45565. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  45566. + * DAMAGE.
  45567. + * ========================================================================= */
  45568. +#ifndef _DWC_OS_H_
  45569. +#define _DWC_OS_H_
  45570. +
  45571. +#ifdef __cplusplus
  45572. +extern "C" {
  45573. +#endif
  45574. +
  45575. +/** @file
  45576. + *
  45577. + * DWC portability library, low level os-wrapper functions
  45578. + *
  45579. + */
  45580. +
  45581. +/* These basic types need to be defined by some OS header file or custom header
  45582. + * file for your specific target architecture.
  45583. + *
  45584. + * uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t, uint64_t, int64_t
  45585. + *
  45586. + * Any custom or alternate header file must be added and enabled here.
  45587. + */
  45588. +
  45589. +#ifdef DWC_LINUX
  45590. +# include <linux/types.h>
  45591. +# ifdef CONFIG_DEBUG_MUTEXES
  45592. +# include <linux/mutex.h>
  45593. +# endif
  45594. +# include <linux/errno.h>
  45595. +# include <stdarg.h>
  45596. +#endif
  45597. +
  45598. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  45599. +# include <os_dep.h>
  45600. +#endif
  45601. +
  45602. +
  45603. +/** @name Primitive Types and Values */
  45604. +
  45605. +/** We define a boolean type for consistency. Can be either YES or NO */
  45606. +typedef uint8_t dwc_bool_t;
  45607. +#define YES 1
  45608. +#define NO 0
  45609. +
  45610. +#ifdef DWC_LINUX
  45611. +
  45612. +/** @name Error Codes */
  45613. +#define DWC_E_INVALID EINVAL
  45614. +#define DWC_E_NO_MEMORY ENOMEM
  45615. +#define DWC_E_NO_DEVICE ENODEV
  45616. +#define DWC_E_NOT_SUPPORTED EOPNOTSUPP
  45617. +#define DWC_E_TIMEOUT ETIMEDOUT
  45618. +#define DWC_E_BUSY EBUSY
  45619. +#define DWC_E_AGAIN EAGAIN
  45620. +#define DWC_E_RESTART ERESTART
  45621. +#define DWC_E_ABORT ECONNABORTED
  45622. +#define DWC_E_SHUTDOWN ESHUTDOWN
  45623. +#define DWC_E_NO_DATA ENODATA
  45624. +#define DWC_E_DISCONNECT ECONNRESET
  45625. +#define DWC_E_UNKNOWN EINVAL
  45626. +#define DWC_E_NO_STREAM_RES ENOSR
  45627. +#define DWC_E_COMMUNICATION ECOMM
  45628. +#define DWC_E_OVERFLOW EOVERFLOW
  45629. +#define DWC_E_PROTOCOL EPROTO
  45630. +#define DWC_E_IN_PROGRESS EINPROGRESS
  45631. +#define DWC_E_PIPE EPIPE
  45632. +#define DWC_E_IO EIO
  45633. +#define DWC_E_NO_SPACE ENOSPC
  45634. +
  45635. +#else
  45636. +
  45637. +/** @name Error Codes */
  45638. +#define DWC_E_INVALID 1001
  45639. +#define DWC_E_NO_MEMORY 1002
  45640. +#define DWC_E_NO_DEVICE 1003
  45641. +#define DWC_E_NOT_SUPPORTED 1004
  45642. +#define DWC_E_TIMEOUT 1005
  45643. +#define DWC_E_BUSY 1006
  45644. +#define DWC_E_AGAIN 1007
  45645. +#define DWC_E_RESTART 1008
  45646. +#define DWC_E_ABORT 1009
  45647. +#define DWC_E_SHUTDOWN 1010
  45648. +#define DWC_E_NO_DATA 1011
  45649. +#define DWC_E_DISCONNECT 2000
  45650. +#define DWC_E_UNKNOWN 3000
  45651. +#define DWC_E_NO_STREAM_RES 4001
  45652. +#define DWC_E_COMMUNICATION 4002
  45653. +#define DWC_E_OVERFLOW 4003
  45654. +#define DWC_E_PROTOCOL 4004
  45655. +#define DWC_E_IN_PROGRESS 4005
  45656. +#define DWC_E_PIPE 4006
  45657. +#define DWC_E_IO 4007
  45658. +#define DWC_E_NO_SPACE 4008
  45659. +
  45660. +#endif
  45661. +
  45662. +
  45663. +/** @name Tracing/Logging Functions
  45664. + *
  45665. + * These function provide the capability to add tracing, debugging, and error
  45666. + * messages, as well exceptions as assertions. The WUDEV uses these
  45667. + * extensively. These could be logged to the main console, the serial port, an
  45668. + * internal buffer, etc. These functions could also be no-op if they are too
  45669. + * expensive on your system. By default undefining the DEBUG macro already
  45670. + * no-ops some of these functions. */
  45671. +
  45672. +/** Returns non-zero if in interrupt context. */
  45673. +extern dwc_bool_t DWC_IN_IRQ(void);
  45674. +#define dwc_in_irq DWC_IN_IRQ
  45675. +
  45676. +/** Returns "IRQ" if DWC_IN_IRQ is true. */
  45677. +static inline char *dwc_irq(void) {
  45678. + return DWC_IN_IRQ() ? "IRQ" : "";
  45679. +}
  45680. +
  45681. +/** Returns non-zero if in bottom-half context. */
  45682. +extern dwc_bool_t DWC_IN_BH(void);
  45683. +#define dwc_in_bh DWC_IN_BH
  45684. +
  45685. +/** Returns "BH" if DWC_IN_BH is true. */
  45686. +static inline char *dwc_bh(void) {
  45687. + return DWC_IN_BH() ? "BH" : "";
  45688. +}
  45689. +
  45690. +/**
  45691. + * A vprintf() clone. Just call vprintf if you've got it.
  45692. + */
  45693. +extern void DWC_VPRINTF(char *format, va_list args);
  45694. +#define dwc_vprintf DWC_VPRINTF
  45695. +
  45696. +/**
  45697. + * A vsnprintf() clone. Just call vprintf if you've got it.
  45698. + */
  45699. +extern int DWC_VSNPRINTF(char *str, int size, char *format, va_list args);
  45700. +#define dwc_vsnprintf DWC_VSNPRINTF
  45701. +
  45702. +/**
  45703. + * printf() clone. Just call printf if you've go it.
  45704. + */
  45705. +extern void DWC_PRINTF(char *format, ...)
  45706. +/* This provides compiler level static checking of the parameters if you're
  45707. + * using GCC. */
  45708. +#ifdef __GNUC__
  45709. + __attribute__ ((format(printf, 1, 2)));
  45710. +#else
  45711. + ;
  45712. +#endif
  45713. +#define dwc_printf DWC_PRINTF
  45714. +
  45715. +/**
  45716. + * sprintf() clone. Just call sprintf if you've got it.
  45717. + */
  45718. +extern int DWC_SPRINTF(char *string, char *format, ...)
  45719. +#ifdef __GNUC__
  45720. + __attribute__ ((format(printf, 2, 3)));
  45721. +#else
  45722. + ;
  45723. +#endif
  45724. +#define dwc_sprintf DWC_SPRINTF
  45725. +
  45726. +/**
  45727. + * snprintf() clone. Just call snprintf if you've got it.
  45728. + */
  45729. +extern int DWC_SNPRINTF(char *string, int size, char *format, ...)
  45730. +#ifdef __GNUC__
  45731. + __attribute__ ((format(printf, 3, 4)));
  45732. +#else
  45733. + ;
  45734. +#endif
  45735. +#define dwc_snprintf DWC_SNPRINTF
  45736. +
  45737. +/**
  45738. + * Prints a WARNING message. On systems that don't differentiate between
  45739. + * warnings and regular log messages, just print it. Indicates that something
  45740. + * may be wrong with the driver. Works like printf().
  45741. + *
  45742. + * Use the DWC_WARN macro to call this function.
  45743. + */
  45744. +extern void __DWC_WARN(char *format, ...)
  45745. +#ifdef __GNUC__
  45746. + __attribute__ ((format(printf, 1, 2)));
  45747. +#else
  45748. + ;
  45749. +#endif
  45750. +
  45751. +/**
  45752. + * Prints an error message. On systems that don't differentiate between errors
  45753. + * and regular log messages, just print it. Indicates that something went wrong
  45754. + * with the driver. Works like printf().
  45755. + *
  45756. + * Use the DWC_ERROR macro to call this function.
  45757. + */
  45758. +extern void __DWC_ERROR(char *format, ...)
  45759. +#ifdef __GNUC__
  45760. + __attribute__ ((format(printf, 1, 2)));
  45761. +#else
  45762. + ;
  45763. +#endif
  45764. +
  45765. +/**
  45766. + * Prints an exception error message and takes some user-defined action such as
  45767. + * print out a backtrace or trigger a breakpoint. Indicates that something went
  45768. + * abnormally wrong with the driver such as programmer error, or other
  45769. + * exceptional condition. It should not be ignored so even on systems without
  45770. + * printing capability, some action should be taken to notify the developer of
  45771. + * it. Works like printf().
  45772. + */
  45773. +extern void DWC_EXCEPTION(char *format, ...)
  45774. +#ifdef __GNUC__
  45775. + __attribute__ ((format(printf, 1, 2)));
  45776. +#else
  45777. + ;
  45778. +#endif
  45779. +#define dwc_exception DWC_EXCEPTION
  45780. +
  45781. +#ifndef DWC_OTG_DEBUG_LEV
  45782. +#define DWC_OTG_DEBUG_LEV 0
  45783. +#endif
  45784. +
  45785. +#ifdef DEBUG
  45786. +/**
  45787. + * Prints out a debug message. Used for logging/trace messages.
  45788. + *
  45789. + * Use the DWC_DEBUG macro to call this function
  45790. + */
  45791. +extern void __DWC_DEBUG(char *format, ...)
  45792. +#ifdef __GNUC__
  45793. + __attribute__ ((format(printf, 1, 2)));
  45794. +#else
  45795. + ;
  45796. +#endif
  45797. +#else
  45798. +#define __DWC_DEBUG printk
  45799. +#endif
  45800. +
  45801. +/**
  45802. + * Prints out a Debug message.
  45803. + */
  45804. +#define DWC_DEBUG(_format, _args...) __DWC_DEBUG("DEBUG:%s:%s: " _format "\n", \
  45805. + __func__, dwc_irq(), ## _args)
  45806. +#define dwc_debug DWC_DEBUG
  45807. +/**
  45808. + * Prints out a Debug message if enabled at compile time.
  45809. + */
  45810. +#if DWC_OTG_DEBUG_LEV > 0
  45811. +#define DWC_DEBUGC(_format, _args...) DWC_DEBUG(_format, ##_args )
  45812. +#else
  45813. +#define DWC_DEBUGC(_format, _args...)
  45814. +#endif
  45815. +#define dwc_debugc DWC_DEBUGC
  45816. +/**
  45817. + * Prints out an informative message.
  45818. + */
  45819. +#define DWC_INFO(_format, _args...) DWC_PRINTF("INFO:%s: " _format "\n", \
  45820. + dwc_irq(), ## _args)
  45821. +#define dwc_info DWC_INFO
  45822. +/**
  45823. + * Prints out an informative message if enabled at compile time.
  45824. + */
  45825. +#if DWC_OTG_DEBUG_LEV > 1
  45826. +#define DWC_INFOC(_format, _args...) DWC_INFO(_format, ##_args )
  45827. +#else
  45828. +#define DWC_INFOC(_format, _args...)
  45829. +#endif
  45830. +#define dwc_infoc DWC_INFOC
  45831. +/**
  45832. + * Prints out a warning message.
  45833. + */
  45834. +#define DWC_WARN(_format, _args...) __DWC_WARN("WARN:%s:%s:%d: " _format "\n", \
  45835. + dwc_irq(), __func__, __LINE__, ## _args)
  45836. +#define dwc_warn DWC_WARN
  45837. +/**
  45838. + * Prints out an error message.
  45839. + */
  45840. +#define DWC_ERROR(_format, _args...) __DWC_ERROR("ERROR:%s:%s:%d: " _format "\n", \
  45841. + dwc_irq(), __func__, __LINE__, ## _args)
  45842. +#define dwc_error DWC_ERROR
  45843. +
  45844. +#define DWC_PROTO_ERROR(_format, _args...) __DWC_WARN("ERROR:%s:%s:%d: " _format "\n", \
  45845. + dwc_irq(), __func__, __LINE__, ## _args)
  45846. +#define dwc_proto_error DWC_PROTO_ERROR
  45847. +
  45848. +#ifdef DEBUG
  45849. +/** Prints out a exception error message if the _expr expression fails. Disabled
  45850. + * if DEBUG is not enabled. */
  45851. +#define DWC_ASSERT(_expr, _format, _args...) do { \
  45852. + if (!(_expr)) { DWC_EXCEPTION("%s:%s:%d: " _format "\n", dwc_irq(), \
  45853. + __FILE__, __LINE__, ## _args); } \
  45854. + } while (0)
  45855. +#else
  45856. +#define DWC_ASSERT(_x...)
  45857. +#endif
  45858. +#define dwc_assert DWC_ASSERT
  45859. +
  45860. +
  45861. +/** @name Byte Ordering
  45862. + * The following functions are for conversions between processor's byte ordering
  45863. + * and specific ordering you want.
  45864. + */
  45865. +
  45866. +/** Converts 32 bit data in CPU byte ordering to little endian. */
  45867. +extern uint32_t DWC_CPU_TO_LE32(uint32_t *p);
  45868. +#define dwc_cpu_to_le32 DWC_CPU_TO_LE32
  45869. +
  45870. +/** Converts 32 bit data in CPU byte orderint to big endian. */
  45871. +extern uint32_t DWC_CPU_TO_BE32(uint32_t *p);
  45872. +#define dwc_cpu_to_be32 DWC_CPU_TO_BE32
  45873. +
  45874. +/** Converts 32 bit little endian data to CPU byte ordering. */
  45875. +extern uint32_t DWC_LE32_TO_CPU(uint32_t *p);
  45876. +#define dwc_le32_to_cpu DWC_LE32_TO_CPU
  45877. +
  45878. +/** Converts 32 bit big endian data to CPU byte ordering. */
  45879. +extern uint32_t DWC_BE32_TO_CPU(uint32_t *p);
  45880. +#define dwc_be32_to_cpu DWC_BE32_TO_CPU
  45881. +
  45882. +/** Converts 16 bit data in CPU byte ordering to little endian. */
  45883. +extern uint16_t DWC_CPU_TO_LE16(uint16_t *p);
  45884. +#define dwc_cpu_to_le16 DWC_CPU_TO_LE16
  45885. +
  45886. +/** Converts 16 bit data in CPU byte orderint to big endian. */
  45887. +extern uint16_t DWC_CPU_TO_BE16(uint16_t *p);
  45888. +#define dwc_cpu_to_be16 DWC_CPU_TO_BE16
  45889. +
  45890. +/** Converts 16 bit little endian data to CPU byte ordering. */
  45891. +extern uint16_t DWC_LE16_TO_CPU(uint16_t *p);
  45892. +#define dwc_le16_to_cpu DWC_LE16_TO_CPU
  45893. +
  45894. +/** Converts 16 bit bi endian data to CPU byte ordering. */
  45895. +extern uint16_t DWC_BE16_TO_CPU(uint16_t *p);
  45896. +#define dwc_be16_to_cpu DWC_BE16_TO_CPU
  45897. +
  45898. +
  45899. +/** @name Register Read/Write
  45900. + *
  45901. + * The following six functions should be implemented to read/write registers of
  45902. + * 32-bit and 64-bit sizes. All modules use this to read/write register values.
  45903. + * The reg value is a pointer to the register calculated from the void *base
  45904. + * variable passed into the driver when it is started. */
  45905. +
  45906. +#ifdef DWC_LINUX
  45907. +/* Linux doesn't need any extra parameters for register read/write, so we
  45908. + * just throw away the IO context parameter.
  45909. + */
  45910. +/** Reads the content of a 32-bit register. */
  45911. +extern uint32_t DWC_READ_REG32(uint32_t volatile *reg);
  45912. +#define dwc_read_reg32(_ctx_,_reg_) DWC_READ_REG32(_reg_)
  45913. +
  45914. +/** Reads the content of a 64-bit register. */
  45915. +extern uint64_t DWC_READ_REG64(uint64_t volatile *reg);
  45916. +#define dwc_read_reg64(_ctx_,_reg_) DWC_READ_REG64(_reg_)
  45917. +
  45918. +/** Writes to a 32-bit register. */
  45919. +extern void DWC_WRITE_REG32(uint32_t volatile *reg, uint32_t value);
  45920. +#define dwc_write_reg32(_ctx_,_reg_,_val_) DWC_WRITE_REG32(_reg_, _val_)
  45921. +
  45922. +/** Writes to a 64-bit register. */
  45923. +extern void DWC_WRITE_REG64(uint64_t volatile *reg, uint64_t value);
  45924. +#define dwc_write_reg64(_ctx_,_reg_,_val_) DWC_WRITE_REG64(_reg_, _val_)
  45925. +
  45926. +/**
  45927. + * Modify bit values in a register. Using the
  45928. + * algorithm: (reg_contents & ~clear_mask) | set_mask.
  45929. + */
  45930. +extern void DWC_MODIFY_REG32(uint32_t volatile *reg, uint32_t clear_mask, uint32_t set_mask);
  45931. +#define dwc_modify_reg32(_ctx_,_reg_,_cmsk_,_smsk_) DWC_MODIFY_REG32(_reg_,_cmsk_,_smsk_)
  45932. +extern void DWC_MODIFY_REG64(uint64_t volatile *reg, uint64_t clear_mask, uint64_t set_mask);
  45933. +#define dwc_modify_reg64(_ctx_,_reg_,_cmsk_,_smsk_) DWC_MODIFY_REG64(_reg_,_cmsk_,_smsk_)
  45934. +
  45935. +#endif /* DWC_LINUX */
  45936. +
  45937. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  45938. +typedef struct dwc_ioctx {
  45939. + struct device *dev;
  45940. + bus_space_tag_t iot;
  45941. + bus_space_handle_t ioh;
  45942. +} dwc_ioctx_t;
  45943. +
  45944. +/** BSD needs two extra parameters for register read/write, so we pass
  45945. + * them in using the IO context parameter.
  45946. + */
  45947. +/** Reads the content of a 32-bit register. */
  45948. +extern uint32_t DWC_READ_REG32(void *io_ctx, uint32_t volatile *reg);
  45949. +#define dwc_read_reg32 DWC_READ_REG32
  45950. +
  45951. +/** Reads the content of a 64-bit register. */
  45952. +extern uint64_t DWC_READ_REG64(void *io_ctx, uint64_t volatile *reg);
  45953. +#define dwc_read_reg64 DWC_READ_REG64
  45954. +
  45955. +/** Writes to a 32-bit register. */
  45956. +extern void DWC_WRITE_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t value);
  45957. +#define dwc_write_reg32 DWC_WRITE_REG32
  45958. +
  45959. +/** Writes to a 64-bit register. */
  45960. +extern void DWC_WRITE_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t value);
  45961. +#define dwc_write_reg64 DWC_WRITE_REG64
  45962. +
  45963. +/**
  45964. + * Modify bit values in a register. Using the
  45965. + * algorithm: (reg_contents & ~clear_mask) | set_mask.
  45966. + */
  45967. +extern void DWC_MODIFY_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t clear_mask, uint32_t set_mask);
  45968. +#define dwc_modify_reg32 DWC_MODIFY_REG32
  45969. +extern void DWC_MODIFY_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t clear_mask, uint64_t set_mask);
  45970. +#define dwc_modify_reg64 DWC_MODIFY_REG64
  45971. +
  45972. +#endif /* DWC_FREEBSD || DWC_NETBSD */
  45973. +
  45974. +/** @cond */
  45975. +
  45976. +/** @name Some convenience MACROS used internally. Define DWC_DEBUG_REGS to log the
  45977. + * register writes. */
  45978. +
  45979. +#ifdef DWC_LINUX
  45980. +
  45981. +# ifdef DWC_DEBUG_REGS
  45982. +
  45983. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  45984. +static inline uint32_t dwc_read_##_reg##_n(_container_type *container, int num) { \
  45985. + return DWC_READ_REG32(&container->regs->_reg[num]); \
  45986. +} \
  45987. +static inline void dwc_write_##_reg##_n(_container_type *container, int num, uint32_t data) { \
  45988. + DWC_DEBUG("WRITING %8s[%d]: %p: %08x", #_reg, num, \
  45989. + &(((uint32_t*)container->regs->_reg)[num]), data); \
  45990. + DWC_WRITE_REG32(&(((uint32_t*)container->regs->_reg)[num]), data); \
  45991. +}
  45992. +
  45993. +#define dwc_define_read_write_reg(_reg,_container_type) \
  45994. +static inline uint32_t dwc_read_##_reg(_container_type *container) { \
  45995. + return DWC_READ_REG32(&container->regs->_reg); \
  45996. +} \
  45997. +static inline void dwc_write_##_reg(_container_type *container, uint32_t data) { \
  45998. + DWC_DEBUG("WRITING %11s: %p: %08x", #_reg, &container->regs->_reg, data); \
  45999. + DWC_WRITE_REG32(&container->regs->_reg, data); \
  46000. +}
  46001. +
  46002. +# else /* DWC_DEBUG_REGS */
  46003. +
  46004. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  46005. +static inline uint32_t dwc_read_##_reg##_n(_container_type *container, int num) { \
  46006. + return DWC_READ_REG32(&container->regs->_reg[num]); \
  46007. +} \
  46008. +static inline void dwc_write_##_reg##_n(_container_type *container, int num, uint32_t data) { \
  46009. + DWC_WRITE_REG32(&(((uint32_t*)container->regs->_reg)[num]), data); \
  46010. +}
  46011. +
  46012. +#define dwc_define_read_write_reg(_reg,_container_type) \
  46013. +static inline uint32_t dwc_read_##_reg(_container_type *container) { \
  46014. + return DWC_READ_REG32(&container->regs->_reg); \
  46015. +} \
  46016. +static inline void dwc_write_##_reg(_container_type *container, uint32_t data) { \
  46017. + DWC_WRITE_REG32(&container->regs->_reg, data); \
  46018. +}
  46019. +
  46020. +# endif /* DWC_DEBUG_REGS */
  46021. +
  46022. +#endif /* DWC_LINUX */
  46023. +
  46024. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  46025. +
  46026. +# ifdef DWC_DEBUG_REGS
  46027. +
  46028. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  46029. +static inline uint32_t dwc_read_##_reg##_n(void *io_ctx, _container_type *container, int num) { \
  46030. + return DWC_READ_REG32(io_ctx, &container->regs->_reg[num]); \
  46031. +} \
  46032. +static inline void dwc_write_##_reg##_n(void *io_ctx, _container_type *container, int num, uint32_t data) { \
  46033. + DWC_DEBUG("WRITING %8s[%d]: %p: %08x", #_reg, num, \
  46034. + &(((uint32_t*)container->regs->_reg)[num]), data); \
  46035. + DWC_WRITE_REG32(io_ctx, &(((uint32_t*)container->regs->_reg)[num]), data); \
  46036. +}
  46037. +
  46038. +#define dwc_define_read_write_reg(_reg,_container_type) \
  46039. +static inline uint32_t dwc_read_##_reg(void *io_ctx, _container_type *container) { \
  46040. + return DWC_READ_REG32(io_ctx, &container->regs->_reg); \
  46041. +} \
  46042. +static inline void dwc_write_##_reg(void *io_ctx, _container_type *container, uint32_t data) { \
  46043. + DWC_DEBUG("WRITING %11s: %p: %08x", #_reg, &container->regs->_reg, data); \
  46044. + DWC_WRITE_REG32(io_ctx, &container->regs->_reg, data); \
  46045. +}
  46046. +
  46047. +# else /* DWC_DEBUG_REGS */
  46048. +
  46049. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  46050. +static inline uint32_t dwc_read_##_reg##_n(void *io_ctx, _container_type *container, int num) { \
  46051. + return DWC_READ_REG32(io_ctx, &container->regs->_reg[num]); \
  46052. +} \
  46053. +static inline void dwc_write_##_reg##_n(void *io_ctx, _container_type *container, int num, uint32_t data) { \
  46054. + DWC_WRITE_REG32(io_ctx, &(((uint32_t*)container->regs->_reg)[num]), data); \
  46055. +}
  46056. +
  46057. +#define dwc_define_read_write_reg(_reg,_container_type) \
  46058. +static inline uint32_t dwc_read_##_reg(void *io_ctx, _container_type *container) { \
  46059. + return DWC_READ_REG32(io_ctx, &container->regs->_reg); \
  46060. +} \
  46061. +static inline void dwc_write_##_reg(void *io_ctx, _container_type *container, uint32_t data) { \
  46062. + DWC_WRITE_REG32(io_ctx, &container->regs->_reg, data); \
  46063. +}
  46064. +
  46065. +# endif /* DWC_DEBUG_REGS */
  46066. +
  46067. +#endif /* DWC_FREEBSD || DWC_NETBSD */
  46068. +
  46069. +/** @endcond */
  46070. +
  46071. +
  46072. +#ifdef DWC_CRYPTOLIB
  46073. +/** @name Crypto Functions
  46074. + *
  46075. + * These are the low-level cryptographic functions used by the driver. */
  46076. +
  46077. +/** Perform AES CBC */
  46078. +extern int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out);
  46079. +#define dwc_aes_cbc DWC_AES_CBC
  46080. +
  46081. +/** Fill the provided buffer with random bytes. These should be cryptographic grade random numbers. */
  46082. +extern void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length);
  46083. +#define dwc_random_bytes DWC_RANDOM_BYTES
  46084. +
  46085. +/** Perform the SHA-256 hash function */
  46086. +extern int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out);
  46087. +#define dwc_sha256 DWC_SHA256
  46088. +
  46089. +/** Calculated the HMAC-SHA256 */
  46090. +extern int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t *out);
  46091. +#define dwc_hmac_sha256 DWC_HMAC_SHA256
  46092. +
  46093. +#endif /* DWC_CRYPTOLIB */
  46094. +
  46095. +
  46096. +/** @name Memory Allocation
  46097. + *
  46098. + * These function provide access to memory allocation. There are only 2 DMA
  46099. + * functions and 3 Regular memory functions that need to be implemented. None
  46100. + * of the memory debugging routines need to be implemented. The allocation
  46101. + * routines all ZERO the contents of the memory.
  46102. + *
  46103. + * Defining DWC_DEBUG_MEMORY turns on memory debugging and statistic gathering.
  46104. + * This checks for memory leaks, keeping track of alloc/free pairs. It also
  46105. + * keeps track of how much memory the driver is using at any given time. */
  46106. +
  46107. +#define DWC_PAGE_SIZE 4096
  46108. +#define DWC_PAGE_OFFSET(addr) (((uint32_t)addr) & 0xfff)
  46109. +#define DWC_PAGE_ALIGNED(addr) ((((uint32_t)addr) & 0xfff) == 0)
  46110. +
  46111. +#define DWC_INVALID_DMA_ADDR 0x0
  46112. +
  46113. +#ifdef DWC_LINUX
  46114. +/** Type for a DMA address */
  46115. +typedef dma_addr_t dwc_dma_t;
  46116. +#endif
  46117. +
  46118. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  46119. +typedef bus_addr_t dwc_dma_t;
  46120. +#endif
  46121. +
  46122. +#ifdef DWC_FREEBSD
  46123. +typedef struct dwc_dmactx {
  46124. + struct device *dev;
  46125. + bus_dma_tag_t dma_tag;
  46126. + bus_dmamap_t dma_map;
  46127. + bus_addr_t dma_paddr;
  46128. + void *dma_vaddr;
  46129. +} dwc_dmactx_t;
  46130. +#endif
  46131. +
  46132. +#ifdef DWC_NETBSD
  46133. +typedef struct dwc_dmactx {
  46134. + struct device *dev;
  46135. + bus_dma_tag_t dma_tag;
  46136. + bus_dmamap_t dma_map;
  46137. + bus_dma_segment_t segs[1];
  46138. + int nsegs;
  46139. + bus_addr_t dma_paddr;
  46140. + void *dma_vaddr;
  46141. +} dwc_dmactx_t;
  46142. +#endif
  46143. +
  46144. +/* @todo these functions will be added in the future */
  46145. +#if 0
  46146. +/**
  46147. + * Creates a DMA pool from which you can allocate DMA buffers. Buffers
  46148. + * allocated from this pool will be guaranteed to meet the size, alignment, and
  46149. + * boundary requirements specified.
  46150. + *
  46151. + * @param[in] size Specifies the size of the buffers that will be allocated from
  46152. + * this pool.
  46153. + * @param[in] align Specifies the byte alignment requirements of the buffers
  46154. + * allocated from this pool. Must be a power of 2.
  46155. + * @param[in] boundary Specifies the N-byte boundary that buffers allocated from
  46156. + * this pool must not cross.
  46157. + *
  46158. + * @returns A pointer to an internal opaque structure which is not to be
  46159. + * accessed outside of these library functions. Use this handle to specify
  46160. + * which pools to allocate/free DMA buffers from and also to destroy the pool,
  46161. + * when you are done with it.
  46162. + */
  46163. +extern dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size, uint32_t align, uint32_t boundary);
  46164. +
  46165. +/**
  46166. + * Destroy a DMA pool. All buffers allocated from that pool must be freed first.
  46167. + */
  46168. +extern void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool);
  46169. +
  46170. +/**
  46171. + * Allocate a buffer from the specified DMA pool and zeros its contents.
  46172. + */
  46173. +extern void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr);
  46174. +
  46175. +/**
  46176. + * Free a previously allocated buffer from the DMA pool.
  46177. + */
  46178. +extern void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr);
  46179. +#endif
  46180. +
  46181. +/** Allocates a DMA capable buffer and zeroes its contents. */
  46182. +extern void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr);
  46183. +
  46184. +/** Allocates a DMA capable buffer and zeroes its contents in atomic contest */
  46185. +extern void *__DWC_DMA_ALLOC_ATOMIC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr);
  46186. +
  46187. +/** Frees a previously allocated buffer. */
  46188. +extern void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr);
  46189. +
  46190. +/** Allocates a block of memory and zeroes its contents. */
  46191. +extern void *__DWC_ALLOC(void *mem_ctx, uint32_t size);
  46192. +
  46193. +/** Allocates a block of memory and zeroes its contents, in an atomic manner
  46194. + * which can be used inside interrupt context. The size should be sufficiently
  46195. + * small, a few KB at most, such that failures are not likely to occur. Can just call
  46196. + * __DWC_ALLOC if it is atomic. */
  46197. +extern void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size);
  46198. +
  46199. +/** Frees a previously allocated buffer. */
  46200. +extern void __DWC_FREE(void *mem_ctx, void *addr);
  46201. +
  46202. +#ifndef DWC_DEBUG_MEMORY
  46203. +
  46204. +#define DWC_ALLOC(_size_) __DWC_ALLOC(NULL, _size_)
  46205. +#define DWC_ALLOC_ATOMIC(_size_) __DWC_ALLOC_ATOMIC(NULL, _size_)
  46206. +#define DWC_FREE(_addr_) __DWC_FREE(NULL, _addr_)
  46207. +
  46208. +# ifdef DWC_LINUX
  46209. +#define DWC_DMA_ALLOC(_size_,_dma_) __DWC_DMA_ALLOC(NULL, _size_, _dma_)
  46210. +#define DWC_DMA_ALLOC_ATOMIC(_size_,_dma_) __DWC_DMA_ALLOC_ATOMIC(NULL, _size_,_dma_)
  46211. +#define DWC_DMA_FREE(_size_,_virt_,_dma_) __DWC_DMA_FREE(NULL, _size_, _virt_, _dma_)
  46212. +# endif
  46213. +
  46214. +# if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  46215. +#define DWC_DMA_ALLOC __DWC_DMA_ALLOC
  46216. +#define DWC_DMA_FREE __DWC_DMA_FREE
  46217. +# endif
  46218. +extern void *dwc_dma_alloc_atomic_debug(uint32_t size, dwc_dma_t *dma_addr, char const *func, int line);
  46219. +
  46220. +#else /* DWC_DEBUG_MEMORY */
  46221. +
  46222. +extern void *dwc_alloc_debug(void *mem_ctx, uint32_t size, char const *func, int line);
  46223. +extern void *dwc_alloc_atomic_debug(void *mem_ctx, uint32_t size, char const *func, int line);
  46224. +extern void dwc_free_debug(void *mem_ctx, void *addr, char const *func, int line);
  46225. +extern void *dwc_dma_alloc_debug(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr,
  46226. + char const *func, int line);
  46227. +extern void *dwc_dma_alloc_atomic_debug(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr,
  46228. + char const *func, int line);
  46229. +extern void dwc_dma_free_debug(void *dma_ctx, uint32_t size, void *virt_addr,
  46230. + dwc_dma_t dma_addr, char const *func, int line);
  46231. +
  46232. +extern int dwc_memory_debug_start(void *mem_ctx);
  46233. +extern void dwc_memory_debug_stop(void);
  46234. +extern void dwc_memory_debug_report(void);
  46235. +
  46236. +#define DWC_ALLOC(_size_) dwc_alloc_debug(NULL, _size_, __func__, __LINE__)
  46237. +#define DWC_ALLOC_ATOMIC(_size_) dwc_alloc_atomic_debug(NULL, _size_, \
  46238. + __func__, __LINE__)
  46239. +#define DWC_FREE(_addr_) dwc_free_debug(NULL, _addr_, __func__, __LINE__)
  46240. +
  46241. +# ifdef DWC_LINUX
  46242. +#define DWC_DMA_ALLOC(_size_,_dma_) dwc_dma_alloc_debug(NULL, _size_, \
  46243. + _dma_, __func__, __LINE__)
  46244. +#define DWC_DMA_ALLOC_ATOMIC(_size_,_dma_) dwc_dma_alloc_atomic_debug(NULL, _size_, \
  46245. + _dma_, __func__, __LINE__)
  46246. +#define DWC_DMA_FREE(_size_,_virt_,_dma_) dwc_dma_free_debug(NULL, _size_, \
  46247. + _virt_, _dma_, __func__, __LINE__)
  46248. +# endif
  46249. +
  46250. +# if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  46251. +#define DWC_DMA_ALLOC(_ctx_,_size_,_dma_) dwc_dma_alloc_debug(_ctx_, _size_, \
  46252. + _dma_, __func__, __LINE__)
  46253. +#define DWC_DMA_FREE(_ctx_,_size_,_virt_,_dma_) dwc_dma_free_debug(_ctx_, _size_, \
  46254. + _virt_, _dma_, __func__, __LINE__)
  46255. +# endif
  46256. +
  46257. +#endif /* DWC_DEBUG_MEMORY */
  46258. +
  46259. +#define dwc_alloc(_ctx_,_size_) DWC_ALLOC(_size_)
  46260. +#define dwc_alloc_atomic(_ctx_,_size_) DWC_ALLOC_ATOMIC(_size_)
  46261. +#define dwc_free(_ctx_,_addr_) DWC_FREE(_addr_)
  46262. +
  46263. +#ifdef DWC_LINUX
  46264. +/* Linux doesn't need any extra parameters for DMA buffer allocation, so we
  46265. + * just throw away the DMA context parameter.
  46266. + */
  46267. +#define dwc_dma_alloc(_ctx_,_size_,_dma_) DWC_DMA_ALLOC(_size_, _dma_)
  46268. +#define dwc_dma_alloc_atomic(_ctx_,_size_,_dma_) DWC_DMA_ALLOC_ATOMIC(_size_, _dma_)
  46269. +#define dwc_dma_free(_ctx_,_size_,_virt_,_dma_) DWC_DMA_FREE(_size_, _virt_, _dma_)
  46270. +#endif
  46271. +
  46272. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  46273. +/** BSD needs several extra parameters for DMA buffer allocation, so we pass
  46274. + * them in using the DMA context parameter.
  46275. + */
  46276. +#define dwc_dma_alloc DWC_DMA_ALLOC
  46277. +#define dwc_dma_free DWC_DMA_FREE
  46278. +#endif
  46279. +
  46280. +
  46281. +/** @name Memory and String Processing */
  46282. +
  46283. +/** memset() clone */
  46284. +extern void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size);
  46285. +#define dwc_memset DWC_MEMSET
  46286. +
  46287. +/** memcpy() clone */
  46288. +extern void *DWC_MEMCPY(void *dest, void const *src, uint32_t size);
  46289. +#define dwc_memcpy DWC_MEMCPY
  46290. +
  46291. +/** memmove() clone */
  46292. +extern void *DWC_MEMMOVE(void *dest, void *src, uint32_t size);
  46293. +#define dwc_memmove DWC_MEMMOVE
  46294. +
  46295. +/** memcmp() clone */
  46296. +extern int DWC_MEMCMP(void *m1, void *m2, uint32_t size);
  46297. +#define dwc_memcmp DWC_MEMCMP
  46298. +
  46299. +/** strcmp() clone */
  46300. +extern int DWC_STRCMP(void *s1, void *s2);
  46301. +#define dwc_strcmp DWC_STRCMP
  46302. +
  46303. +/** strncmp() clone */
  46304. +extern int DWC_STRNCMP(void *s1, void *s2, uint32_t size);
  46305. +#define dwc_strncmp DWC_STRNCMP
  46306. +
  46307. +/** strlen() clone, for NULL terminated ASCII strings */
  46308. +extern int DWC_STRLEN(char const *str);
  46309. +#define dwc_strlen DWC_STRLEN
  46310. +
  46311. +/** strcpy() clone, for NULL terminated ASCII strings */
  46312. +extern char *DWC_STRCPY(char *to, const char *from);
  46313. +#define dwc_strcpy DWC_STRCPY
  46314. +
  46315. +/** strdup() clone. If you wish to use memory allocation debugging, this
  46316. + * implementation of strdup should use the DWC_* memory routines instead of
  46317. + * calling a predefined strdup. Otherwise the memory allocated by this routine
  46318. + * will not be seen by the debugging routines. */
  46319. +extern char *DWC_STRDUP(char const *str);
  46320. +#define dwc_strdup(_ctx_,_str_) DWC_STRDUP(_str_)
  46321. +
  46322. +/** NOT an atoi() clone. Read the description carefully. Returns an integer
  46323. + * converted from the string str in base 10 unless the string begins with a "0x"
  46324. + * in which case it is base 16. String must be a NULL terminated sequence of
  46325. + * ASCII characters and may optionally begin with whitespace, a + or -, and a
  46326. + * "0x" prefix if base 16. The remaining characters must be valid digits for
  46327. + * the number and end with a NULL character. If any invalid characters are
  46328. + * encountered or it returns with a negative error code and the results of the
  46329. + * conversion are undefined. On sucess it returns 0. Overflow conditions are
  46330. + * undefined. An example implementation using atoi() can be referenced from the
  46331. + * Linux implementation. */
  46332. +extern int DWC_ATOI(const char *str, int32_t *value);
  46333. +#define dwc_atoi DWC_ATOI
  46334. +
  46335. +/** Same as above but for unsigned. */
  46336. +extern int DWC_ATOUI(const char *str, uint32_t *value);
  46337. +#define dwc_atoui DWC_ATOUI
  46338. +
  46339. +#ifdef DWC_UTFLIB
  46340. +/** This routine returns a UTF16LE unicode encoded string from a UTF8 string. */
  46341. +extern int DWC_UTF8_TO_UTF16LE(uint8_t const *utf8string, uint16_t *utf16string, unsigned len);
  46342. +#define dwc_utf8_to_utf16le DWC_UTF8_TO_UTF16LE
  46343. +#endif
  46344. +
  46345. +
  46346. +/** @name Wait queues
  46347. + *
  46348. + * Wait queues provide a means of synchronizing between threads or processes. A
  46349. + * process can block on a waitq if some condition is not true, waiting for it to
  46350. + * become true. When the waitq is triggered all waiting process will get
  46351. + * unblocked and the condition will be check again. Waitqs should be triggered
  46352. + * every time a condition can potentially change.*/
  46353. +struct dwc_waitq;
  46354. +
  46355. +/** Type for a waitq */
  46356. +typedef struct dwc_waitq dwc_waitq_t;
  46357. +
  46358. +/** The type of waitq condition callback function. This is called every time
  46359. + * condition is evaluated. */
  46360. +typedef int (*dwc_waitq_condition_t)(void *data);
  46361. +
  46362. +/** Allocate a waitq */
  46363. +extern dwc_waitq_t *DWC_WAITQ_ALLOC(void);
  46364. +#define dwc_waitq_alloc(_ctx_) DWC_WAITQ_ALLOC()
  46365. +
  46366. +/** Free a waitq */
  46367. +extern void DWC_WAITQ_FREE(dwc_waitq_t *wq);
  46368. +#define dwc_waitq_free DWC_WAITQ_FREE
  46369. +
  46370. +/** Check the condition and if it is false, block on the waitq. When unblocked, check the
  46371. + * condition again. The function returns when the condition becomes true. The return value
  46372. + * is 0 on condition true, DWC_WAITQ_ABORTED on abort or killed, or DWC_WAITQ_UNKNOWN on error. */
  46373. +extern int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data);
  46374. +#define dwc_waitq_wait DWC_WAITQ_WAIT
  46375. +
  46376. +/** Check the condition and if it is false, block on the waitq. When unblocked,
  46377. + * check the condition again. The function returns when the condition become
  46378. + * true or the timeout has passed. The return value is 0 on condition true or
  46379. + * DWC_TIMED_OUT on timeout, or DWC_WAITQ_ABORTED, or DWC_WAITQ_UNKNOWN on
  46380. + * error. */
  46381. +extern int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  46382. + void *data, int32_t msecs);
  46383. +#define dwc_waitq_wait_timeout DWC_WAITQ_WAIT_TIMEOUT
  46384. +
  46385. +/** Trigger a waitq, unblocking all processes. This should be called whenever a condition
  46386. + * has potentially changed. */
  46387. +extern void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq);
  46388. +#define dwc_waitq_trigger DWC_WAITQ_TRIGGER
  46389. +
  46390. +/** Unblock all processes waiting on the waitq with an ABORTED result. */
  46391. +extern void DWC_WAITQ_ABORT(dwc_waitq_t *wq);
  46392. +#define dwc_waitq_abort DWC_WAITQ_ABORT
  46393. +
  46394. +
  46395. +/** @name Threads
  46396. + *
  46397. + * A thread must be explicitly stopped. It must check DWC_THREAD_SHOULD_STOP
  46398. + * whenever it is woken up, and then return. The DWC_THREAD_STOP function
  46399. + * returns the value from the thread.
  46400. + */
  46401. +
  46402. +struct dwc_thread;
  46403. +
  46404. +/** Type for a thread */
  46405. +typedef struct dwc_thread dwc_thread_t;
  46406. +
  46407. +/** The thread function */
  46408. +typedef int (*dwc_thread_function_t)(void *data);
  46409. +
  46410. +/** Create a thread and start it running the thread_function. Returns a handle
  46411. + * to the thread */
  46412. +extern dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data);
  46413. +#define dwc_thread_run(_ctx_,_func_,_name_,_data_) DWC_THREAD_RUN(_func_, _name_, _data_)
  46414. +
  46415. +/** Stops a thread. Return the value returned by the thread. Or will return
  46416. + * DWC_ABORT if the thread never started. */
  46417. +extern int DWC_THREAD_STOP(dwc_thread_t *thread);
  46418. +#define dwc_thread_stop DWC_THREAD_STOP
  46419. +
  46420. +/** Signifies to the thread that it must stop. */
  46421. +#ifdef DWC_LINUX
  46422. +/* Linux doesn't need any parameters for kthread_should_stop() */
  46423. +extern dwc_bool_t DWC_THREAD_SHOULD_STOP(void);
  46424. +#define dwc_thread_should_stop(_thrd_) DWC_THREAD_SHOULD_STOP()
  46425. +
  46426. +/* No thread_exit function in Linux */
  46427. +#define dwc_thread_exit(_thrd_)
  46428. +#endif
  46429. +
  46430. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  46431. +/** BSD needs the thread pointer for kthread_suspend_check() */
  46432. +extern dwc_bool_t DWC_THREAD_SHOULD_STOP(dwc_thread_t *thread);
  46433. +#define dwc_thread_should_stop DWC_THREAD_SHOULD_STOP
  46434. +
  46435. +/** The thread must call this to exit. */
  46436. +extern void DWC_THREAD_EXIT(dwc_thread_t *thread);
  46437. +#define dwc_thread_exit DWC_THREAD_EXIT
  46438. +#endif
  46439. +
  46440. +
  46441. +/** @name Work queues
  46442. + *
  46443. + * Workqs are used to queue a callback function to be called at some later time,
  46444. + * in another thread. */
  46445. +struct dwc_workq;
  46446. +
  46447. +/** Type for a workq */
  46448. +typedef struct dwc_workq dwc_workq_t;
  46449. +
  46450. +/** The type of the callback function to be called. */
  46451. +typedef void (*dwc_work_callback_t)(void *data);
  46452. +
  46453. +/** Allocate a workq */
  46454. +extern dwc_workq_t *DWC_WORKQ_ALLOC(char *name);
  46455. +#define dwc_workq_alloc(_ctx_,_name_) DWC_WORKQ_ALLOC(_name_)
  46456. +
  46457. +/** Free a workq. All work must be completed before being freed. */
  46458. +extern void DWC_WORKQ_FREE(dwc_workq_t *workq);
  46459. +#define dwc_workq_free DWC_WORKQ_FREE
  46460. +
  46461. +/** Schedule a callback on the workq, passing in data. The function will be
  46462. + * scheduled at some later time. */
  46463. +extern void DWC_WORKQ_SCHEDULE(dwc_workq_t *workq, dwc_work_callback_t cb,
  46464. + void *data, char *format, ...)
  46465. +#ifdef __GNUC__
  46466. + __attribute__ ((format(printf, 4, 5)));
  46467. +#else
  46468. + ;
  46469. +#endif
  46470. +#define dwc_workq_schedule DWC_WORKQ_SCHEDULE
  46471. +
  46472. +/** Schedule a callback on the workq, that will be called until at least
  46473. + * given number miliseconds have passed. */
  46474. +extern void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *workq, dwc_work_callback_t cb,
  46475. + void *data, uint32_t time, char *format, ...)
  46476. +#ifdef __GNUC__
  46477. + __attribute__ ((format(printf, 5, 6)));
  46478. +#else
  46479. + ;
  46480. +#endif
  46481. +#define dwc_workq_schedule_delayed DWC_WORKQ_SCHEDULE_DELAYED
  46482. +
  46483. +/** The number of processes in the workq */
  46484. +extern int DWC_WORKQ_PENDING(dwc_workq_t *workq);
  46485. +#define dwc_workq_pending DWC_WORKQ_PENDING
  46486. +
  46487. +/** Blocks until all the work in the workq is complete or timed out. Returns <
  46488. + * 0 on timeout. */
  46489. +extern int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout);
  46490. +#define dwc_workq_wait_work_done DWC_WORKQ_WAIT_WORK_DONE
  46491. +
  46492. +
  46493. +/** @name Tasklets
  46494. + *
  46495. + */
  46496. +struct dwc_tasklet;
  46497. +
  46498. +/** Type for a tasklet */
  46499. +typedef struct dwc_tasklet dwc_tasklet_t;
  46500. +
  46501. +/** The type of the callback function to be called */
  46502. +typedef void (*dwc_tasklet_callback_t)(void *data);
  46503. +
  46504. +/** Allocates a tasklet */
  46505. +extern dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data);
  46506. +#define dwc_task_alloc(_ctx_,_name_,_cb_,_data_) DWC_TASK_ALLOC(_name_, _cb_, _data_)
  46507. +
  46508. +/** Frees a tasklet */
  46509. +extern void DWC_TASK_FREE(dwc_tasklet_t *task);
  46510. +#define dwc_task_free DWC_TASK_FREE
  46511. +
  46512. +/** Schedules a tasklet to run */
  46513. +extern void DWC_TASK_SCHEDULE(dwc_tasklet_t *task);
  46514. +#define dwc_task_schedule DWC_TASK_SCHEDULE
  46515. +
  46516. +extern void DWC_TASK_HI_SCHEDULE(dwc_tasklet_t *task);
  46517. +#define dwc_task_hi_schedule DWC_TASK_HI_SCHEDULE
  46518. +
  46519. +/** @name Timer
  46520. + *
  46521. + * Callbacks must be small and atomic.
  46522. + */
  46523. +struct dwc_timer;
  46524. +
  46525. +/** Type for a timer */
  46526. +typedef struct dwc_timer dwc_timer_t;
  46527. +
  46528. +/** The type of the callback function to be called */
  46529. +typedef void (*dwc_timer_callback_t)(void *data);
  46530. +
  46531. +/** Allocates a timer */
  46532. +extern dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data);
  46533. +#define dwc_timer_alloc(_ctx_,_name_,_cb_,_data_) DWC_TIMER_ALLOC(_name_,_cb_,_data_)
  46534. +
  46535. +/** Frees a timer */
  46536. +extern void DWC_TIMER_FREE(dwc_timer_t *timer);
  46537. +#define dwc_timer_free DWC_TIMER_FREE
  46538. +
  46539. +/** Schedules the timer to run at time ms from now. And will repeat at every
  46540. + * repeat_interval msec therafter
  46541. + *
  46542. + * Modifies a timer that is still awaiting execution to a new expiration time.
  46543. + * The mod_time is added to the old time. */
  46544. +extern void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time);
  46545. +#define dwc_timer_schedule DWC_TIMER_SCHEDULE
  46546. +
  46547. +/** Disables the timer from execution. */
  46548. +extern void DWC_TIMER_CANCEL(dwc_timer_t *timer);
  46549. +#define dwc_timer_cancel DWC_TIMER_CANCEL
  46550. +
  46551. +
  46552. +/** @name Spinlocks
  46553. + *
  46554. + * These locks are used when the work between the lock/unlock is atomic and
  46555. + * short. Interrupts are also disabled during the lock/unlock and thus they are
  46556. + * suitable to lock between interrupt/non-interrupt context. They also lock
  46557. + * between processes if you have multiple CPUs or Preemption. If you don't have
  46558. + * multiple CPUS or Preemption, then the you can simply implement the
  46559. + * DWC_SPINLOCK and DWC_SPINUNLOCK to disable and enable interrupts. Because
  46560. + * the work between the lock/unlock is atomic, the process context will never
  46561. + * change, and so you never have to lock between processes. */
  46562. +
  46563. +struct dwc_spinlock;
  46564. +
  46565. +/** Type for a spinlock */
  46566. +typedef struct dwc_spinlock dwc_spinlock_t;
  46567. +
  46568. +/** Type for the 'flags' argument to spinlock funtions */
  46569. +typedef unsigned long dwc_irqflags_t;
  46570. +
  46571. +/** Returns an initialized lock variable. This function should allocate and
  46572. + * initialize the OS-specific data structure used for locking. This data
  46573. + * structure is to be used for the DWC_LOCK and DWC_UNLOCK functions and should
  46574. + * be freed by the DWC_FREE_LOCK when it is no longer used. */
  46575. +extern dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void);
  46576. +#define dwc_spinlock_alloc(_ctx_) DWC_SPINLOCK_ALLOC()
  46577. +
  46578. +/** Frees an initialized lock variable. */
  46579. +extern void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock);
  46580. +#define dwc_spinlock_free(_ctx_,_lock_) DWC_SPINLOCK_FREE(_lock_)
  46581. +
  46582. +/** Disables interrupts and blocks until it acquires the lock.
  46583. + *
  46584. + * @param lock Pointer to the spinlock.
  46585. + * @param flags Unsigned long for irq flags storage.
  46586. + */
  46587. +extern void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags);
  46588. +#define dwc_spinlock_irqsave DWC_SPINLOCK_IRQSAVE
  46589. +
  46590. +/** Re-enables the interrupt and releases the lock.
  46591. + *
  46592. + * @param lock Pointer to the spinlock.
  46593. + * @param flags Unsigned long for irq flags storage. Must be the same as was
  46594. + * passed into DWC_LOCK.
  46595. + */
  46596. +extern void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags);
  46597. +#define dwc_spinunlock_irqrestore DWC_SPINUNLOCK_IRQRESTORE
  46598. +
  46599. +/** Blocks until it acquires the lock.
  46600. + *
  46601. + * @param lock Pointer to the spinlock.
  46602. + */
  46603. +extern void DWC_SPINLOCK(dwc_spinlock_t *lock);
  46604. +#define dwc_spinlock DWC_SPINLOCK
  46605. +
  46606. +/** Releases the lock.
  46607. + *
  46608. + * @param lock Pointer to the spinlock.
  46609. + */
  46610. +extern void DWC_SPINUNLOCK(dwc_spinlock_t *lock);
  46611. +#define dwc_spinunlock DWC_SPINUNLOCK
  46612. +
  46613. +
  46614. +/** @name Mutexes
  46615. + *
  46616. + * Unlike spinlocks Mutexes lock only between processes and the work between the
  46617. + * lock/unlock CAN block, therefore it CANNOT be called from interrupt context.
  46618. + */
  46619. +
  46620. +struct dwc_mutex;
  46621. +
  46622. +/** Type for a mutex */
  46623. +typedef struct dwc_mutex dwc_mutex_t;
  46624. +
  46625. +/* For Linux Mutex Debugging make it inline because the debugging routines use
  46626. + * the symbol to determine recursive locking. This makes it falsely think
  46627. + * recursive locking occurs. */
  46628. +#if defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES)
  46629. +#define DWC_MUTEX_ALLOC_LINUX_DEBUG(__mutexp) ({ \
  46630. + __mutexp = (dwc_mutex_t *)DWC_ALLOC(sizeof(struct mutex)); \
  46631. + mutex_init((struct mutex *)__mutexp); \
  46632. +})
  46633. +#endif
  46634. +
  46635. +/** Allocate a mutex */
  46636. +extern dwc_mutex_t *DWC_MUTEX_ALLOC(void);
  46637. +#define dwc_mutex_alloc(_ctx_) DWC_MUTEX_ALLOC()
  46638. +
  46639. +/* For memory leak debugging when using Linux Mutex Debugging */
  46640. +#if defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES)
  46641. +#define DWC_MUTEX_FREE(__mutexp) do { \
  46642. + mutex_destroy((struct mutex *)__mutexp); \
  46643. + DWC_FREE(__mutexp); \
  46644. +} while(0)
  46645. +#else
  46646. +/** Free a mutex */
  46647. +extern void DWC_MUTEX_FREE(dwc_mutex_t *mutex);
  46648. +#define dwc_mutex_free(_ctx_,_mutex_) DWC_MUTEX_FREE(_mutex_)
  46649. +#endif
  46650. +
  46651. +/** Lock a mutex */
  46652. +extern void DWC_MUTEX_LOCK(dwc_mutex_t *mutex);
  46653. +#define dwc_mutex_lock DWC_MUTEX_LOCK
  46654. +
  46655. +/** Non-blocking lock returns 1 on successful lock. */
  46656. +extern int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex);
  46657. +#define dwc_mutex_trylock DWC_MUTEX_TRYLOCK
  46658. +
  46659. +/** Unlock a mutex */
  46660. +extern void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex);
  46661. +#define dwc_mutex_unlock DWC_MUTEX_UNLOCK
  46662. +
  46663. +
  46664. +/** @name Time */
  46665. +
  46666. +/** Microsecond delay.
  46667. + *
  46668. + * @param usecs Microseconds to delay.
  46669. + */
  46670. +extern void DWC_UDELAY(uint32_t usecs);
  46671. +#define dwc_udelay DWC_UDELAY
  46672. +
  46673. +/** Millisecond delay.
  46674. + *
  46675. + * @param msecs Milliseconds to delay.
  46676. + */
  46677. +extern void DWC_MDELAY(uint32_t msecs);
  46678. +#define dwc_mdelay DWC_MDELAY
  46679. +
  46680. +/** Non-busy waiting.
  46681. + * Sleeps for specified number of milliseconds.
  46682. + *
  46683. + * @param msecs Milliseconds to sleep.
  46684. + */
  46685. +extern void DWC_MSLEEP(uint32_t msecs);
  46686. +#define dwc_msleep DWC_MSLEEP
  46687. +
  46688. +/**
  46689. + * Returns number of milliseconds since boot.
  46690. + */
  46691. +extern uint32_t DWC_TIME(void);
  46692. +#define dwc_time DWC_TIME
  46693. +
  46694. +
  46695. +
  46696. +
  46697. +/* @mainpage DWC Portability and Common Library
  46698. + *
  46699. + * This is the documentation for the DWC Portability and Common Library.
  46700. + *
  46701. + * @section intro Introduction
  46702. + *
  46703. + * The DWC Portability library consists of wrapper calls and data structures to
  46704. + * all low-level functions which are typically provided by the OS. The WUDEV
  46705. + * driver uses only these functions. In order to port the WUDEV driver, only
  46706. + * the functions in this library need to be re-implemented, with the same
  46707. + * behavior as documented here.
  46708. + *
  46709. + * The Common library consists of higher level functions, which rely only on
  46710. + * calling the functions from the DWC Portability library. These common
  46711. + * routines are shared across modules. Some of the common libraries need to be
  46712. + * used directly by the driver programmer when porting WUDEV. Such as the
  46713. + * parameter and notification libraries.
  46714. + *
  46715. + * @section low Portability Library OS Wrapper Functions
  46716. + *
  46717. + * Any function starting with DWC and in all CAPS is a low-level OS-wrapper that
  46718. + * needs to be implemented when porting, for example DWC_MUTEX_ALLOC(). All of
  46719. + * these functions are included in the dwc_os.h file.
  46720. + *
  46721. + * There are many functions here covering a wide array of OS services. Please
  46722. + * see dwc_os.h for details, and implementation notes for each function.
  46723. + *
  46724. + * @section common Common Library Functions
  46725. + *
  46726. + * Any function starting with dwc and in all lowercase is a common library
  46727. + * routine. These functions have a portable implementation and do not need to
  46728. + * be reimplemented when porting. The common routines can be used by any
  46729. + * driver, and some must be used by the end user to control the drivers. For
  46730. + * example, you must use the Parameter common library in order to set the
  46731. + * parameters in the WUDEV module.
  46732. + *
  46733. + * The common libraries consist of the following:
  46734. + *
  46735. + * - Connection Contexts - Used internally and can be used by end-user. See dwc_cc.h
  46736. + * - Parameters - Used internally and can be used by end-user. See dwc_params.h
  46737. + * - Notifications - Used internally and can be used by end-user. See dwc_notifier.h
  46738. + * - Lists - Used internally and can be used by end-user. See dwc_list.h
  46739. + * - Memory Debugging - Used internally and can be used by end-user. See dwc_os.h
  46740. + * - Modpow - Used internally only. See dwc_modpow.h
  46741. + * - DH - Used internally only. See dwc_dh.h
  46742. + * - Crypto - Used internally only. See dwc_crypto.h
  46743. + *
  46744. + *
  46745. + * @section prereq Prerequistes For dwc_os.h
  46746. + * @subsection types Data Types
  46747. + *
  46748. + * The dwc_os.h file assumes that several low-level data types are pre defined for the
  46749. + * compilation environment. These data types are:
  46750. + *
  46751. + * - uint8_t - unsigned 8-bit data type
  46752. + * - int8_t - signed 8-bit data type
  46753. + * - uint16_t - unsigned 16-bit data type
  46754. + * - int16_t - signed 16-bit data type
  46755. + * - uint32_t - unsigned 32-bit data type
  46756. + * - int32_t - signed 32-bit data type
  46757. + * - uint64_t - unsigned 64-bit data type
  46758. + * - int64_t - signed 64-bit data type
  46759. + *
  46760. + * Ensure that these are defined before using dwc_os.h. The easiest way to do
  46761. + * that is to modify the top of the file to include the appropriate header.
  46762. + * This is already done for the Linux environment. If the DWC_LINUX macro is
  46763. + * defined, the correct header will be added. A standard header <stdint.h> is
  46764. + * also used for environments where standard C headers are available.
  46765. + *
  46766. + * @subsection stdarg Variable Arguments
  46767. + *
  46768. + * Variable arguments are provided by a standard C header <stdarg.h>. it is
  46769. + * available in Both the Linux and ANSI C enviornment. An equivalent must be
  46770. + * provided in your enviornment in order to use dwc_os.h with the debug and
  46771. + * tracing message functionality.
  46772. + *
  46773. + * @subsection thread Threading
  46774. + *
  46775. + * WUDEV Core must be run on an operating system that provides for multiple
  46776. + * threads/processes. Threading can be implemented in many ways, even in
  46777. + * embedded systems without an operating system. At the bare minimum, the
  46778. + * system should be able to start any number of processes at any time to handle
  46779. + * special work. It need not be a pre-emptive system. Process context can
  46780. + * change upon a call to a blocking function. The hardware interrupt context
  46781. + * that calls the module's ISR() function must be differentiable from process
  46782. + * context, even if your processes are impemented via a hardware interrupt.
  46783. + * Further locking mechanism between process must exist (or be implemented), and
  46784. + * process context must have a way to disable interrupts for a period of time to
  46785. + * lock them out. If all of this exists, the functions in dwc_os.h related to
  46786. + * threading should be able to be implemented with the defined behavior.
  46787. + *
  46788. + */
  46789. +
  46790. +#ifdef __cplusplus
  46791. +}
  46792. +#endif
  46793. +
  46794. +#endif /* _DWC_OS_H_ */
  46795. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_common_port/Makefile linux-3.13.3/drivers/usb/host/dwc_common_port/Makefile
  46796. --- linux-3.13.3.orig/drivers/usb/host/dwc_common_port/Makefile 1970-01-01 01:00:00.000000000 +0100
  46797. +++ linux-3.13.3/drivers/usb/host/dwc_common_port/Makefile 2014-02-17 22:41:01.000000000 +0100
  46798. @@ -0,0 +1,58 @@
  46799. +#
  46800. +# Makefile for DWC_common library
  46801. +#
  46802. +
  46803. +ifneq ($(KERNELRELEASE),)
  46804. +
  46805. +EXTRA_CFLAGS += -DDWC_LINUX
  46806. +#EXTRA_CFLAGS += -DDEBUG
  46807. +#EXTRA_CFLAGS += -DDWC_DEBUG_REGS
  46808. +#EXTRA_CFLAGS += -DDWC_DEBUG_MEMORY
  46809. +
  46810. +EXTRA_CFLAGS += -DDWC_LIBMODULE
  46811. +EXTRA_CFLAGS += -DDWC_CCLIB
  46812. +#EXTRA_CFLAGS += -DDWC_CRYPTOLIB
  46813. +EXTRA_CFLAGS += -DDWC_NOTIFYLIB
  46814. +EXTRA_CFLAGS += -DDWC_UTFLIB
  46815. +
  46816. +obj-$(CONFIG_USB_DWCOTG) += dwc_common_port_lib.o
  46817. +dwc_common_port_lib-objs := dwc_cc.o dwc_modpow.o dwc_dh.o \
  46818. + dwc_crypto.o dwc_notifier.o \
  46819. + dwc_common_linux.o dwc_mem.o
  46820. +
  46821. +kernrelwd := $(subst ., ,$(KERNELRELEASE))
  46822. +kernrel3 := $(word 1,$(kernrelwd)).$(word 2,$(kernrelwd)).$(word 3,$(kernrelwd))
  46823. +
  46824. +ifneq ($(kernrel3),2.6.20)
  46825. +# grayg - I only know that we use EXTRA_CFLAGS in 2.6.31 actually
  46826. +EXTRA_CFLAGS += $(CPPFLAGS)
  46827. +endif
  46828. +
  46829. +else
  46830. +
  46831. +#ifeq ($(KDIR),)
  46832. +#$(error Must give "KDIR=/path/to/kernel/source" on command line or in environment)
  46833. +#endif
  46834. +
  46835. +ifeq ($(ARCH),)
  46836. +$(error Must give "ARCH=<arch>" on command line or in environment. Also, if \
  46837. + cross-compiling, must give "CROSS_COMPILE=/path/to/compiler/plus/tool-prefix-")
  46838. +endif
  46839. +
  46840. +ifeq ($(DOXYGEN),)
  46841. +DOXYGEN := doxygen
  46842. +endif
  46843. +
  46844. +default:
  46845. + $(MAKE) -C$(KDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  46846. +
  46847. +docs: $(wildcard *.[hc]) doc/doxygen.cfg
  46848. + $(DOXYGEN) doc/doxygen.cfg
  46849. +
  46850. +tags: $(wildcard *.[hc])
  46851. + $(CTAGS) -e $(wildcard *.[hc]) $(wildcard linux/*.[hc]) $(wildcard $(KDIR)/include/linux/usb*.h)
  46852. +
  46853. +endif
  46854. +
  46855. +clean:
  46856. + rm -rf *.o *.ko .*.cmd *.mod.c .*.o.d .*.o.tmp modules.order Module.markers Module.symvers .tmp_versions/
  46857. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_common_port/Makefile.fbsd linux-3.13.3/drivers/usb/host/dwc_common_port/Makefile.fbsd
  46858. --- linux-3.13.3.orig/drivers/usb/host/dwc_common_port/Makefile.fbsd 1970-01-01 01:00:00.000000000 +0100
  46859. +++ linux-3.13.3/drivers/usb/host/dwc_common_port/Makefile.fbsd 2014-02-17 22:41:01.000000000 +0100
  46860. @@ -0,0 +1,17 @@
  46861. +CFLAGS += -I/sys/i386/compile/GENERIC -I/sys/i386/include -I/usr/include
  46862. +CFLAGS += -DDWC_FREEBSD
  46863. +CFLAGS += -DDEBUG
  46864. +#CFLAGS += -DDWC_DEBUG_REGS
  46865. +#CFLAGS += -DDWC_DEBUG_MEMORY
  46866. +
  46867. +#CFLAGS += -DDWC_LIBMODULE
  46868. +#CFLAGS += -DDWC_CCLIB
  46869. +#CFLAGS += -DDWC_CRYPTOLIB
  46870. +#CFLAGS += -DDWC_NOTIFYLIB
  46871. +#CFLAGS += -DDWC_UTFLIB
  46872. +
  46873. +KMOD = dwc_common_port_lib
  46874. +SRCS = dwc_cc.c dwc_modpow.c dwc_dh.c dwc_crypto.c dwc_notifier.c \
  46875. + dwc_common_fbsd.c dwc_mem.c
  46876. +
  46877. +.include <bsd.kmod.mk>
  46878. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_common_port/Makefile.linux linux-3.13.3/drivers/usb/host/dwc_common_port/Makefile.linux
  46879. --- linux-3.13.3.orig/drivers/usb/host/dwc_common_port/Makefile.linux 1970-01-01 01:00:00.000000000 +0100
  46880. +++ linux-3.13.3/drivers/usb/host/dwc_common_port/Makefile.linux 2014-02-17 22:41:01.000000000 +0100
  46881. @@ -0,0 +1,49 @@
  46882. +#
  46883. +# Makefile for DWC_common library
  46884. +#
  46885. +ifneq ($(KERNELRELEASE),)
  46886. +
  46887. +EXTRA_CFLAGS += -DDWC_LINUX
  46888. +#EXTRA_CFLAGS += -DDEBUG
  46889. +#EXTRA_CFLAGS += -DDWC_DEBUG_REGS
  46890. +#EXTRA_CFLAGS += -DDWC_DEBUG_MEMORY
  46891. +
  46892. +EXTRA_CFLAGS += -DDWC_LIBMODULE
  46893. +EXTRA_CFLAGS += -DDWC_CCLIB
  46894. +EXTRA_CFLAGS += -DDWC_CRYPTOLIB
  46895. +EXTRA_CFLAGS += -DDWC_NOTIFYLIB
  46896. +EXTRA_CFLAGS += -DDWC_UTFLIB
  46897. +
  46898. +obj-m := dwc_common_port_lib.o
  46899. +dwc_common_port_lib-objs := dwc_cc.o dwc_modpow.o dwc_dh.o \
  46900. + dwc_crypto.o dwc_notifier.o \
  46901. + dwc_common_linux.o dwc_mem.o
  46902. +
  46903. +else
  46904. +
  46905. +ifeq ($(KDIR),)
  46906. +$(error Must give "KDIR=/path/to/kernel/source" on command line or in environment)
  46907. +endif
  46908. +
  46909. +ifeq ($(ARCH),)
  46910. +$(error Must give "ARCH=<arch>" on command line or in environment. Also, if \
  46911. + cross-compiling, must give "CROSS_COMPILE=/path/to/compiler/plus/tool-prefix-")
  46912. +endif
  46913. +
  46914. +ifeq ($(DOXYGEN),)
  46915. +DOXYGEN := doxygen
  46916. +endif
  46917. +
  46918. +default:
  46919. + $(MAKE) -C$(KDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  46920. +
  46921. +docs: $(wildcard *.[hc]) doc/doxygen.cfg
  46922. + $(DOXYGEN) doc/doxygen.cfg
  46923. +
  46924. +tags: $(wildcard *.[hc])
  46925. + $(CTAGS) -e $(wildcard *.[hc]) $(wildcard linux/*.[hc]) $(wildcard $(KDIR)/include/linux/usb*.h)
  46926. +
  46927. +endif
  46928. +
  46929. +clean:
  46930. + rm -rf *.o *.ko .*.cmd *.mod.c .*.o.d .*.o.tmp modules.order Module.markers Module.symvers .tmp_versions/
  46931. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_common_port/usb.h linux-3.13.3/drivers/usb/host/dwc_common_port/usb.h
  46932. --- linux-3.13.3.orig/drivers/usb/host/dwc_common_port/usb.h 1970-01-01 01:00:00.000000000 +0100
  46933. +++ linux-3.13.3/drivers/usb/host/dwc_common_port/usb.h 2014-02-17 22:41:01.000000000 +0100
  46934. @@ -0,0 +1,946 @@
  46935. +/*
  46936. + * Copyright (c) 1998 The NetBSD Foundation, Inc.
  46937. + * All rights reserved.
  46938. + *
  46939. + * This code is derived from software contributed to The NetBSD Foundation
  46940. + * by Lennart Augustsson (lennart@augustsson.net) at
  46941. + * Carlstedt Research & Technology.
  46942. + *
  46943. + * Redistribution and use in source and binary forms, with or without
  46944. + * modification, are permitted provided that the following conditions
  46945. + * are met:
  46946. + * 1. Redistributions of source code must retain the above copyright
  46947. + * notice, this list of conditions and the following disclaimer.
  46948. + * 2. Redistributions in binary form must reproduce the above copyright
  46949. + * notice, this list of conditions and the following disclaimer in the
  46950. + * documentation and/or other materials provided with the distribution.
  46951. + * 3. All advertising materials mentioning features or use of this software
  46952. + * must display the following acknowledgement:
  46953. + * This product includes software developed by the NetBSD
  46954. + * Foundation, Inc. and its contributors.
  46955. + * 4. Neither the name of The NetBSD Foundation nor the names of its
  46956. + * contributors may be used to endorse or promote products derived
  46957. + * from this software without specific prior written permission.
  46958. + *
  46959. + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  46960. + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  46961. + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  46962. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  46963. + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  46964. + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  46965. + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  46966. + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  46967. + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  46968. + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  46969. + * POSSIBILITY OF SUCH DAMAGE.
  46970. + */
  46971. +
  46972. +/* Modified by Synopsys, Inc, 12/12/2007 */
  46973. +
  46974. +
  46975. +#ifndef _USB_H_
  46976. +#define _USB_H_
  46977. +
  46978. +#ifdef __cplusplus
  46979. +extern "C" {
  46980. +#endif
  46981. +
  46982. +/*
  46983. + * The USB records contain some unaligned little-endian word
  46984. + * components. The U[SG]ETW macros take care of both the alignment
  46985. + * and endian problem and should always be used to access non-byte
  46986. + * values.
  46987. + */
  46988. +typedef u_int8_t uByte;
  46989. +typedef u_int8_t uWord[2];
  46990. +typedef u_int8_t uDWord[4];
  46991. +
  46992. +#define USETW2(w,h,l) ((w)[0] = (u_int8_t)(l), (w)[1] = (u_int8_t)(h))
  46993. +#define UCONSTW(x) { (x) & 0xff, ((x) >> 8) & 0xff }
  46994. +#define UCONSTDW(x) { (x) & 0xff, ((x) >> 8) & 0xff, \
  46995. + ((x) >> 16) & 0xff, ((x) >> 24) & 0xff }
  46996. +
  46997. +#if 1
  46998. +#define UGETW(w) ((w)[0] | ((w)[1] << 8))
  46999. +#define USETW(w,v) ((w)[0] = (u_int8_t)(v), (w)[1] = (u_int8_t)((v) >> 8))
  47000. +#define UGETDW(w) ((w)[0] | ((w)[1] << 8) | ((w)[2] << 16) | ((w)[3] << 24))
  47001. +#define USETDW(w,v) ((w)[0] = (u_int8_t)(v), \
  47002. + (w)[1] = (u_int8_t)((v) >> 8), \
  47003. + (w)[2] = (u_int8_t)((v) >> 16), \
  47004. + (w)[3] = (u_int8_t)((v) >> 24))
  47005. +#else
  47006. +/*
  47007. + * On little-endian machines that can handle unanliged accesses
  47008. + * (e.g. i386) these macros can be replaced by the following.
  47009. + */
  47010. +#define UGETW(w) (*(u_int16_t *)(w))
  47011. +#define USETW(w,v) (*(u_int16_t *)(w) = (v))
  47012. +#define UGETDW(w) (*(u_int32_t *)(w))
  47013. +#define USETDW(w,v) (*(u_int32_t *)(w) = (v))
  47014. +#endif
  47015. +
  47016. +/*
  47017. + * Macros for accessing UAS IU fields, which are big-endian
  47018. + */
  47019. +#define IUSETW2(w,h,l) ((w)[0] = (u_int8_t)(h), (w)[1] = (u_int8_t)(l))
  47020. +#define IUCONSTW(x) { ((x) >> 8) & 0xff, (x) & 0xff }
  47021. +#define IUCONSTDW(x) { ((x) >> 24) & 0xff, ((x) >> 16) & 0xff, \
  47022. + ((x) >> 8) & 0xff, (x) & 0xff }
  47023. +#define IUGETW(w) (((w)[0] << 8) | (w)[1])
  47024. +#define IUSETW(w,v) ((w)[0] = (u_int8_t)((v) >> 8), (w)[1] = (u_int8_t)(v))
  47025. +#define IUGETDW(w) (((w)[0] << 24) | ((w)[1] << 16) | ((w)[2] << 8) | (w)[3])
  47026. +#define IUSETDW(w,v) ((w)[0] = (u_int8_t)((v) >> 24), \
  47027. + (w)[1] = (u_int8_t)((v) >> 16), \
  47028. + (w)[2] = (u_int8_t)((v) >> 8), \
  47029. + (w)[3] = (u_int8_t)(v))
  47030. +
  47031. +#define UPACKED __attribute__((__packed__))
  47032. +
  47033. +typedef struct {
  47034. + uByte bmRequestType;
  47035. + uByte bRequest;
  47036. + uWord wValue;
  47037. + uWord wIndex;
  47038. + uWord wLength;
  47039. +} UPACKED usb_device_request_t;
  47040. +
  47041. +#define UT_GET_DIR(a) ((a) & 0x80)
  47042. +#define UT_WRITE 0x00
  47043. +#define UT_READ 0x80
  47044. +
  47045. +#define UT_GET_TYPE(a) ((a) & 0x60)
  47046. +#define UT_STANDARD 0x00
  47047. +#define UT_CLASS 0x20
  47048. +#define UT_VENDOR 0x40
  47049. +
  47050. +#define UT_GET_RECIPIENT(a) ((a) & 0x1f)
  47051. +#define UT_DEVICE 0x00
  47052. +#define UT_INTERFACE 0x01
  47053. +#define UT_ENDPOINT 0x02
  47054. +#define UT_OTHER 0x03
  47055. +
  47056. +#define UT_READ_DEVICE (UT_READ | UT_STANDARD | UT_DEVICE)
  47057. +#define UT_READ_INTERFACE (UT_READ | UT_STANDARD | UT_INTERFACE)
  47058. +#define UT_READ_ENDPOINT (UT_READ | UT_STANDARD | UT_ENDPOINT)
  47059. +#define UT_WRITE_DEVICE (UT_WRITE | UT_STANDARD | UT_DEVICE)
  47060. +#define UT_WRITE_INTERFACE (UT_WRITE | UT_STANDARD | UT_INTERFACE)
  47061. +#define UT_WRITE_ENDPOINT (UT_WRITE | UT_STANDARD | UT_ENDPOINT)
  47062. +#define UT_READ_CLASS_DEVICE (UT_READ | UT_CLASS | UT_DEVICE)
  47063. +#define UT_READ_CLASS_INTERFACE (UT_READ | UT_CLASS | UT_INTERFACE)
  47064. +#define UT_READ_CLASS_OTHER (UT_READ | UT_CLASS | UT_OTHER)
  47065. +#define UT_READ_CLASS_ENDPOINT (UT_READ | UT_CLASS | UT_ENDPOINT)
  47066. +#define UT_WRITE_CLASS_DEVICE (UT_WRITE | UT_CLASS | UT_DEVICE)
  47067. +#define UT_WRITE_CLASS_INTERFACE (UT_WRITE | UT_CLASS | UT_INTERFACE)
  47068. +#define UT_WRITE_CLASS_OTHER (UT_WRITE | UT_CLASS | UT_OTHER)
  47069. +#define UT_WRITE_CLASS_ENDPOINT (UT_WRITE | UT_CLASS | UT_ENDPOINT)
  47070. +#define UT_READ_VENDOR_DEVICE (UT_READ | UT_VENDOR | UT_DEVICE)
  47071. +#define UT_READ_VENDOR_INTERFACE (UT_READ | UT_VENDOR | UT_INTERFACE)
  47072. +#define UT_READ_VENDOR_OTHER (UT_READ | UT_VENDOR | UT_OTHER)
  47073. +#define UT_READ_VENDOR_ENDPOINT (UT_READ | UT_VENDOR | UT_ENDPOINT)
  47074. +#define UT_WRITE_VENDOR_DEVICE (UT_WRITE | UT_VENDOR | UT_DEVICE)
  47075. +#define UT_WRITE_VENDOR_INTERFACE (UT_WRITE | UT_VENDOR | UT_INTERFACE)
  47076. +#define UT_WRITE_VENDOR_OTHER (UT_WRITE | UT_VENDOR | UT_OTHER)
  47077. +#define UT_WRITE_VENDOR_ENDPOINT (UT_WRITE | UT_VENDOR | UT_ENDPOINT)
  47078. +
  47079. +/* Requests */
  47080. +#define UR_GET_STATUS 0x00
  47081. +#define USTAT_STANDARD_STATUS 0x00
  47082. +#define WUSTAT_WUSB_FEATURE 0x01
  47083. +#define WUSTAT_CHANNEL_INFO 0x02
  47084. +#define WUSTAT_RECEIVED_DATA 0x03
  47085. +#define WUSTAT_MAS_AVAILABILITY 0x04
  47086. +#define WUSTAT_CURRENT_TRANSMIT_POWER 0x05
  47087. +#define UR_CLEAR_FEATURE 0x01
  47088. +#define UR_SET_FEATURE 0x03
  47089. +#define UR_SET_AND_TEST_FEATURE 0x0c
  47090. +#define UR_SET_ADDRESS 0x05
  47091. +#define UR_GET_DESCRIPTOR 0x06
  47092. +#define UDESC_DEVICE 0x01
  47093. +#define UDESC_CONFIG 0x02
  47094. +#define UDESC_STRING 0x03
  47095. +#define UDESC_INTERFACE 0x04
  47096. +#define UDESC_ENDPOINT 0x05
  47097. +#define UDESC_SS_USB_COMPANION 0x30
  47098. +#define UDESC_DEVICE_QUALIFIER 0x06
  47099. +#define UDESC_OTHER_SPEED_CONFIGURATION 0x07
  47100. +#define UDESC_INTERFACE_POWER 0x08
  47101. +#define UDESC_OTG 0x09
  47102. +#define WUDESC_SECURITY 0x0c
  47103. +#define WUDESC_KEY 0x0d
  47104. +#define WUD_GET_KEY_INDEX(_wValue_) ((_wValue_) & 0xf)
  47105. +#define WUD_GET_KEY_TYPE(_wValue_) (((_wValue_) & 0x30) >> 4)
  47106. +#define WUD_KEY_TYPE_ASSOC 0x01
  47107. +#define WUD_KEY_TYPE_GTK 0x02
  47108. +#define WUD_GET_KEY_ORIGIN(_wValue_) (((_wValue_) & 0x40) >> 6)
  47109. +#define WUD_KEY_ORIGIN_HOST 0x00
  47110. +#define WUD_KEY_ORIGIN_DEVICE 0x01
  47111. +#define WUDESC_ENCRYPTION_TYPE 0x0e
  47112. +#define WUDESC_BOS 0x0f
  47113. +#define WUDESC_DEVICE_CAPABILITY 0x10
  47114. +#define WUDESC_WIRELESS_ENDPOINT_COMPANION 0x11
  47115. +#define UDESC_BOS 0x0f
  47116. +#define UDESC_DEVICE_CAPABILITY 0x10
  47117. +#define UDESC_CS_DEVICE 0x21 /* class specific */
  47118. +#define UDESC_CS_CONFIG 0x22
  47119. +#define UDESC_CS_STRING 0x23
  47120. +#define UDESC_CS_INTERFACE 0x24
  47121. +#define UDESC_CS_ENDPOINT 0x25
  47122. +#define UDESC_HUB 0x29
  47123. +#define UR_SET_DESCRIPTOR 0x07
  47124. +#define UR_GET_CONFIG 0x08
  47125. +#define UR_SET_CONFIG 0x09
  47126. +#define UR_GET_INTERFACE 0x0a
  47127. +#define UR_SET_INTERFACE 0x0b
  47128. +#define UR_SYNCH_FRAME 0x0c
  47129. +#define WUR_SET_ENCRYPTION 0x0d
  47130. +#define WUR_GET_ENCRYPTION 0x0e
  47131. +#define WUR_SET_HANDSHAKE 0x0f
  47132. +#define WUR_GET_HANDSHAKE 0x10
  47133. +#define WUR_SET_CONNECTION 0x11
  47134. +#define WUR_SET_SECURITY_DATA 0x12
  47135. +#define WUR_GET_SECURITY_DATA 0x13
  47136. +#define WUR_SET_WUSB_DATA 0x14
  47137. +#define WUDATA_DRPIE_INFO 0x01
  47138. +#define WUDATA_TRANSMIT_DATA 0x02
  47139. +#define WUDATA_TRANSMIT_PARAMS 0x03
  47140. +#define WUDATA_RECEIVE_PARAMS 0x04
  47141. +#define WUDATA_TRANSMIT_POWER 0x05
  47142. +#define WUR_LOOPBACK_DATA_WRITE 0x15
  47143. +#define WUR_LOOPBACK_DATA_READ 0x16
  47144. +#define WUR_SET_INTERFACE_DS 0x17
  47145. +
  47146. +/* Feature numbers */
  47147. +#define UF_ENDPOINT_HALT 0
  47148. +#define UF_DEVICE_REMOTE_WAKEUP 1
  47149. +#define UF_TEST_MODE 2
  47150. +#define UF_DEVICE_B_HNP_ENABLE 3
  47151. +#define UF_DEVICE_A_HNP_SUPPORT 4
  47152. +#define UF_DEVICE_A_ALT_HNP_SUPPORT 5
  47153. +#define WUF_WUSB 3
  47154. +#define WUF_TX_DRPIE 0x0
  47155. +#define WUF_DEV_XMIT_PACKET 0x1
  47156. +#define WUF_COUNT_PACKETS 0x2
  47157. +#define WUF_CAPTURE_PACKETS 0x3
  47158. +#define UF_FUNCTION_SUSPEND 0
  47159. +#define UF_U1_ENABLE 48
  47160. +#define UF_U2_ENABLE 49
  47161. +#define UF_LTM_ENABLE 50
  47162. +
  47163. +/* Class requests from the USB 2.0 hub spec, table 11-15 */
  47164. +#define UCR_CLEAR_HUB_FEATURE (0x2000 | UR_CLEAR_FEATURE)
  47165. +#define UCR_CLEAR_PORT_FEATURE (0x2300 | UR_CLEAR_FEATURE)
  47166. +#define UCR_GET_HUB_DESCRIPTOR (0xa000 | UR_GET_DESCRIPTOR)
  47167. +#define UCR_GET_HUB_STATUS (0xa000 | UR_GET_STATUS)
  47168. +#define UCR_GET_PORT_STATUS (0xa300 | UR_GET_STATUS)
  47169. +#define UCR_SET_HUB_FEATURE (0x2000 | UR_SET_FEATURE)
  47170. +#define UCR_SET_PORT_FEATURE (0x2300 | UR_SET_FEATURE)
  47171. +#define UCR_SET_AND_TEST_PORT_FEATURE (0xa300 | UR_SET_AND_TEST_FEATURE)
  47172. +
  47173. +#ifdef _MSC_VER
  47174. +#include <pshpack1.h>
  47175. +#endif
  47176. +
  47177. +typedef struct {
  47178. + uByte bLength;
  47179. + uByte bDescriptorType;
  47180. + uByte bDescriptorSubtype;
  47181. +} UPACKED usb_descriptor_t;
  47182. +
  47183. +typedef struct {
  47184. + uByte bLength;
  47185. + uByte bDescriptorType;
  47186. +} UPACKED usb_descriptor_header_t;
  47187. +
  47188. +typedef struct {
  47189. + uByte bLength;
  47190. + uByte bDescriptorType;
  47191. + uWord bcdUSB;
  47192. +#define UD_USB_2_0 0x0200
  47193. +#define UD_IS_USB2(d) (UGETW((d)->bcdUSB) >= UD_USB_2_0)
  47194. + uByte bDeviceClass;
  47195. + uByte bDeviceSubClass;
  47196. + uByte bDeviceProtocol;
  47197. + uByte bMaxPacketSize;
  47198. + /* The fields below are not part of the initial descriptor. */
  47199. + uWord idVendor;
  47200. + uWord idProduct;
  47201. + uWord bcdDevice;
  47202. + uByte iManufacturer;
  47203. + uByte iProduct;
  47204. + uByte iSerialNumber;
  47205. + uByte bNumConfigurations;
  47206. +} UPACKED usb_device_descriptor_t;
  47207. +#define USB_DEVICE_DESCRIPTOR_SIZE 18
  47208. +
  47209. +typedef struct {
  47210. + uByte bLength;
  47211. + uByte bDescriptorType;
  47212. + uWord wTotalLength;
  47213. + uByte bNumInterface;
  47214. + uByte bConfigurationValue;
  47215. + uByte iConfiguration;
  47216. +#define UC_ATT_ONE (1 << 7) /* must be set */
  47217. +#define UC_ATT_SELFPOWER (1 << 6) /* self powered */
  47218. +#define UC_ATT_WAKEUP (1 << 5) /* can wakeup */
  47219. +#define UC_ATT_BATTERY (1 << 4) /* battery powered */
  47220. + uByte bmAttributes;
  47221. +#define UC_BUS_POWERED 0x80
  47222. +#define UC_SELF_POWERED 0x40
  47223. +#define UC_REMOTE_WAKEUP 0x20
  47224. + uByte bMaxPower; /* max current in 2 mA units */
  47225. +#define UC_POWER_FACTOR 2
  47226. +} UPACKED usb_config_descriptor_t;
  47227. +#define USB_CONFIG_DESCRIPTOR_SIZE 9
  47228. +
  47229. +typedef struct {
  47230. + uByte bLength;
  47231. + uByte bDescriptorType;
  47232. + uByte bInterfaceNumber;
  47233. + uByte bAlternateSetting;
  47234. + uByte bNumEndpoints;
  47235. + uByte bInterfaceClass;
  47236. + uByte bInterfaceSubClass;
  47237. + uByte bInterfaceProtocol;
  47238. + uByte iInterface;
  47239. +} UPACKED usb_interface_descriptor_t;
  47240. +#define USB_INTERFACE_DESCRIPTOR_SIZE 9
  47241. +
  47242. +typedef struct {
  47243. + uByte bLength;
  47244. + uByte bDescriptorType;
  47245. + uByte bEndpointAddress;
  47246. +#define UE_GET_DIR(a) ((a) & 0x80)
  47247. +#define UE_SET_DIR(a,d) ((a) | (((d)&1) << 7))
  47248. +#define UE_DIR_IN 0x80
  47249. +#define UE_DIR_OUT 0x00
  47250. +#define UE_ADDR 0x0f
  47251. +#define UE_GET_ADDR(a) ((a) & UE_ADDR)
  47252. + uByte bmAttributes;
  47253. +#define UE_XFERTYPE 0x03
  47254. +#define UE_CONTROL 0x00
  47255. +#define UE_ISOCHRONOUS 0x01
  47256. +#define UE_BULK 0x02
  47257. +#define UE_INTERRUPT 0x03
  47258. +#define UE_GET_XFERTYPE(a) ((a) & UE_XFERTYPE)
  47259. +#define UE_ISO_TYPE 0x0c
  47260. +#define UE_ISO_ASYNC 0x04
  47261. +#define UE_ISO_ADAPT 0x08
  47262. +#define UE_ISO_SYNC 0x0c
  47263. +#define UE_GET_ISO_TYPE(a) ((a) & UE_ISO_TYPE)
  47264. + uWord wMaxPacketSize;
  47265. + uByte bInterval;
  47266. +} UPACKED usb_endpoint_descriptor_t;
  47267. +#define USB_ENDPOINT_DESCRIPTOR_SIZE 7
  47268. +
  47269. +typedef struct ss_endpoint_companion_descriptor {
  47270. + uByte bLength;
  47271. + uByte bDescriptorType;
  47272. + uByte bMaxBurst;
  47273. +#define USSE_GET_MAX_STREAMS(a) ((a) & 0x1f)
  47274. +#define USSE_SET_MAX_STREAMS(a, b) ((a) | ((b) & 0x1f))
  47275. +#define USSE_GET_MAX_PACKET_NUM(a) ((a) & 0x03)
  47276. +#define USSE_SET_MAX_PACKET_NUM(a, b) ((a) | ((b) & 0x03))
  47277. + uByte bmAttributes;
  47278. + uWord wBytesPerInterval;
  47279. +} UPACKED ss_endpoint_companion_descriptor_t;
  47280. +#define USB_SS_ENDPOINT_COMPANION_DESCRIPTOR_SIZE 6
  47281. +
  47282. +typedef struct {
  47283. + uByte bLength;
  47284. + uByte bDescriptorType;
  47285. + uWord bString[127];
  47286. +} UPACKED usb_string_descriptor_t;
  47287. +#define USB_MAX_STRING_LEN 128
  47288. +#define USB_LANGUAGE_TABLE 0 /* # of the string language id table */
  47289. +
  47290. +/* Hub specific request */
  47291. +#define UR_GET_BUS_STATE 0x02
  47292. +#define UR_CLEAR_TT_BUFFER 0x08
  47293. +#define UR_RESET_TT 0x09
  47294. +#define UR_GET_TT_STATE 0x0a
  47295. +#define UR_STOP_TT 0x0b
  47296. +
  47297. +/* Hub features */
  47298. +#define UHF_C_HUB_LOCAL_POWER 0
  47299. +#define UHF_C_HUB_OVER_CURRENT 1
  47300. +#define UHF_PORT_CONNECTION 0
  47301. +#define UHF_PORT_ENABLE 1
  47302. +#define UHF_PORT_SUSPEND 2
  47303. +#define UHF_PORT_OVER_CURRENT 3
  47304. +#define UHF_PORT_RESET 4
  47305. +#define UHF_PORT_L1 5
  47306. +#define UHF_PORT_POWER 8
  47307. +#define UHF_PORT_LOW_SPEED 9
  47308. +#define UHF_PORT_HIGH_SPEED 10
  47309. +#define UHF_C_PORT_CONNECTION 16
  47310. +#define UHF_C_PORT_ENABLE 17
  47311. +#define UHF_C_PORT_SUSPEND 18
  47312. +#define UHF_C_PORT_OVER_CURRENT 19
  47313. +#define UHF_C_PORT_RESET 20
  47314. +#define UHF_C_PORT_L1 23
  47315. +#define UHF_PORT_TEST 21
  47316. +#define UHF_PORT_INDICATOR 22
  47317. +
  47318. +typedef struct {
  47319. + uByte bDescLength;
  47320. + uByte bDescriptorType;
  47321. + uByte bNbrPorts;
  47322. + uWord wHubCharacteristics;
  47323. +#define UHD_PWR 0x0003
  47324. +#define UHD_PWR_GANGED 0x0000
  47325. +#define UHD_PWR_INDIVIDUAL 0x0001
  47326. +#define UHD_PWR_NO_SWITCH 0x0002
  47327. +#define UHD_COMPOUND 0x0004
  47328. +#define UHD_OC 0x0018
  47329. +#define UHD_OC_GLOBAL 0x0000
  47330. +#define UHD_OC_INDIVIDUAL 0x0008
  47331. +#define UHD_OC_NONE 0x0010
  47332. +#define UHD_TT_THINK 0x0060
  47333. +#define UHD_TT_THINK_8 0x0000
  47334. +#define UHD_TT_THINK_16 0x0020
  47335. +#define UHD_TT_THINK_24 0x0040
  47336. +#define UHD_TT_THINK_32 0x0060
  47337. +#define UHD_PORT_IND 0x0080
  47338. + uByte bPwrOn2PwrGood; /* delay in 2 ms units */
  47339. +#define UHD_PWRON_FACTOR 2
  47340. + uByte bHubContrCurrent;
  47341. + uByte DeviceRemovable[32]; /* max 255 ports */
  47342. +#define UHD_NOT_REMOV(desc, i) \
  47343. + (((desc)->DeviceRemovable[(i)/8] >> ((i) % 8)) & 1)
  47344. + /* deprecated */ uByte PortPowerCtrlMask[1];
  47345. +} UPACKED usb_hub_descriptor_t;
  47346. +#define USB_HUB_DESCRIPTOR_SIZE 9 /* includes deprecated PortPowerCtrlMask */
  47347. +
  47348. +typedef struct {
  47349. + uByte bLength;
  47350. + uByte bDescriptorType;
  47351. + uWord bcdUSB;
  47352. + uByte bDeviceClass;
  47353. + uByte bDeviceSubClass;
  47354. + uByte bDeviceProtocol;
  47355. + uByte bMaxPacketSize0;
  47356. + uByte bNumConfigurations;
  47357. + uByte bReserved;
  47358. +} UPACKED usb_device_qualifier_t;
  47359. +#define USB_DEVICE_QUALIFIER_SIZE 10
  47360. +
  47361. +typedef struct {
  47362. + uByte bLength;
  47363. + uByte bDescriptorType;
  47364. + uByte bmAttributes;
  47365. +#define UOTG_SRP 0x01
  47366. +#define UOTG_HNP 0x02
  47367. +} UPACKED usb_otg_descriptor_t;
  47368. +
  47369. +/* OTG feature selectors */
  47370. +#define UOTG_B_HNP_ENABLE 3
  47371. +#define UOTG_A_HNP_SUPPORT 4
  47372. +#define UOTG_A_ALT_HNP_SUPPORT 5
  47373. +
  47374. +typedef struct {
  47375. + uWord wStatus;
  47376. +/* Device status flags */
  47377. +#define UDS_SELF_POWERED 0x0001
  47378. +#define UDS_REMOTE_WAKEUP 0x0002
  47379. +/* Endpoint status flags */
  47380. +#define UES_HALT 0x0001
  47381. +} UPACKED usb_status_t;
  47382. +
  47383. +typedef struct {
  47384. + uWord wHubStatus;
  47385. +#define UHS_LOCAL_POWER 0x0001
  47386. +#define UHS_OVER_CURRENT 0x0002
  47387. + uWord wHubChange;
  47388. +} UPACKED usb_hub_status_t;
  47389. +
  47390. +typedef struct {
  47391. + uWord wPortStatus;
  47392. +#define UPS_CURRENT_CONNECT_STATUS 0x0001
  47393. +#define UPS_PORT_ENABLED 0x0002
  47394. +#define UPS_SUSPEND 0x0004
  47395. +#define UPS_OVERCURRENT_INDICATOR 0x0008
  47396. +#define UPS_RESET 0x0010
  47397. +#define UPS_PORT_POWER 0x0100
  47398. +#define UPS_LOW_SPEED 0x0200
  47399. +#define UPS_HIGH_SPEED 0x0400
  47400. +#define UPS_PORT_TEST 0x0800
  47401. +#define UPS_PORT_INDICATOR 0x1000
  47402. + uWord wPortChange;
  47403. +#define UPS_C_CONNECT_STATUS 0x0001
  47404. +#define UPS_C_PORT_ENABLED 0x0002
  47405. +#define UPS_C_SUSPEND 0x0004
  47406. +#define UPS_C_OVERCURRENT_INDICATOR 0x0008
  47407. +#define UPS_C_PORT_RESET 0x0010
  47408. +} UPACKED usb_port_status_t;
  47409. +
  47410. +#ifdef _MSC_VER
  47411. +#include <poppack.h>
  47412. +#endif
  47413. +
  47414. +/* Device class codes */
  47415. +#define UDCLASS_IN_INTERFACE 0x00
  47416. +#define UDCLASS_COMM 0x02
  47417. +#define UDCLASS_HUB 0x09
  47418. +#define UDSUBCLASS_HUB 0x00
  47419. +#define UDPROTO_FSHUB 0x00
  47420. +#define UDPROTO_HSHUBSTT 0x01
  47421. +#define UDPROTO_HSHUBMTT 0x02
  47422. +#define UDCLASS_DIAGNOSTIC 0xdc
  47423. +#define UDCLASS_WIRELESS 0xe0
  47424. +#define UDSUBCLASS_RF 0x01
  47425. +#define UDPROTO_BLUETOOTH 0x01
  47426. +#define UDCLASS_VENDOR 0xff
  47427. +
  47428. +/* Interface class codes */
  47429. +#define UICLASS_UNSPEC 0x00
  47430. +
  47431. +#define UICLASS_AUDIO 0x01
  47432. +#define UISUBCLASS_AUDIOCONTROL 1
  47433. +#define UISUBCLASS_AUDIOSTREAM 2
  47434. +#define UISUBCLASS_MIDISTREAM 3
  47435. +
  47436. +#define UICLASS_CDC 0x02 /* communication */
  47437. +#define UISUBCLASS_DIRECT_LINE_CONTROL_MODEL 1
  47438. +#define UISUBCLASS_ABSTRACT_CONTROL_MODEL 2
  47439. +#define UISUBCLASS_TELEPHONE_CONTROL_MODEL 3
  47440. +#define UISUBCLASS_MULTICHANNEL_CONTROL_MODEL 4
  47441. +#define UISUBCLASS_CAPI_CONTROLMODEL 5
  47442. +#define UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL 6
  47443. +#define UISUBCLASS_ATM_NETWORKING_CONTROL_MODEL 7
  47444. +#define UIPROTO_CDC_AT 1
  47445. +
  47446. +#define UICLASS_HID 0x03
  47447. +#define UISUBCLASS_BOOT 1
  47448. +#define UIPROTO_BOOT_KEYBOARD 1
  47449. +
  47450. +#define UICLASS_PHYSICAL 0x05
  47451. +
  47452. +#define UICLASS_IMAGE 0x06
  47453. +
  47454. +#define UICLASS_PRINTER 0x07
  47455. +#define UISUBCLASS_PRINTER 1
  47456. +#define UIPROTO_PRINTER_UNI 1
  47457. +#define UIPROTO_PRINTER_BI 2
  47458. +#define UIPROTO_PRINTER_1284 3
  47459. +
  47460. +#define UICLASS_MASS 0x08
  47461. +#define UISUBCLASS_RBC 1
  47462. +#define UISUBCLASS_SFF8020I 2
  47463. +#define UISUBCLASS_QIC157 3
  47464. +#define UISUBCLASS_UFI 4
  47465. +#define UISUBCLASS_SFF8070I 5
  47466. +#define UISUBCLASS_SCSI 6
  47467. +#define UIPROTO_MASS_CBI_I 0
  47468. +#define UIPROTO_MASS_CBI 1
  47469. +#define UIPROTO_MASS_BBB_OLD 2 /* Not in the spec anymore */
  47470. +#define UIPROTO_MASS_BBB 80 /* 'P' for the Iomega Zip drive */
  47471. +
  47472. +#define UICLASS_HUB 0x09
  47473. +#define UISUBCLASS_HUB 0
  47474. +#define UIPROTO_FSHUB 0
  47475. +#define UIPROTO_HSHUBSTT 0 /* Yes, same as previous */
  47476. +#define UIPROTO_HSHUBMTT 1
  47477. +
  47478. +#define UICLASS_CDC_DATA 0x0a
  47479. +#define UISUBCLASS_DATA 0
  47480. +#define UIPROTO_DATA_ISDNBRI 0x30 /* Physical iface */
  47481. +#define UIPROTO_DATA_HDLC 0x31 /* HDLC */
  47482. +#define UIPROTO_DATA_TRANSPARENT 0x32 /* Transparent */
  47483. +#define UIPROTO_DATA_Q921M 0x50 /* Management for Q921 */
  47484. +#define UIPROTO_DATA_Q921 0x51 /* Data for Q921 */
  47485. +#define UIPROTO_DATA_Q921TM 0x52 /* TEI multiplexer for Q921 */
  47486. +#define UIPROTO_DATA_V42BIS 0x90 /* Data compression */
  47487. +#define UIPROTO_DATA_Q931 0x91 /* Euro-ISDN */
  47488. +#define UIPROTO_DATA_V120 0x92 /* V.24 rate adaption */
  47489. +#define UIPROTO_DATA_CAPI 0x93 /* CAPI 2.0 commands */
  47490. +#define UIPROTO_DATA_HOST_BASED 0xfd /* Host based driver */
  47491. +#define UIPROTO_DATA_PUF 0xfe /* see Prot. Unit Func. Desc.*/
  47492. +#define UIPROTO_DATA_VENDOR 0xff /* Vendor specific */
  47493. +
  47494. +#define UICLASS_SMARTCARD 0x0b
  47495. +
  47496. +/*#define UICLASS_FIRM_UPD 0x0c*/
  47497. +
  47498. +#define UICLASS_SECURITY 0x0d
  47499. +
  47500. +#define UICLASS_DIAGNOSTIC 0xdc
  47501. +
  47502. +#define UICLASS_WIRELESS 0xe0
  47503. +#define UISUBCLASS_RF 0x01
  47504. +#define UIPROTO_BLUETOOTH 0x01
  47505. +
  47506. +#define UICLASS_APPL_SPEC 0xfe
  47507. +#define UISUBCLASS_FIRMWARE_DOWNLOAD 1
  47508. +#define UISUBCLASS_IRDA 2
  47509. +#define UIPROTO_IRDA 0
  47510. +
  47511. +#define UICLASS_VENDOR 0xff
  47512. +
  47513. +#define USB_HUB_MAX_DEPTH 5
  47514. +
  47515. +/*
  47516. + * Minimum time a device needs to be powered down to go through
  47517. + * a power cycle. XXX Are these time in the spec?
  47518. + */
  47519. +#define USB_POWER_DOWN_TIME 200 /* ms */
  47520. +#define USB_PORT_POWER_DOWN_TIME 100 /* ms */
  47521. +
  47522. +#if 0
  47523. +/* These are the values from the spec. */
  47524. +#define USB_PORT_RESET_DELAY 10 /* ms */
  47525. +#define USB_PORT_ROOT_RESET_DELAY 50 /* ms */
  47526. +#define USB_PORT_RESET_RECOVERY 10 /* ms */
  47527. +#define USB_PORT_POWERUP_DELAY 100 /* ms */
  47528. +#define USB_SET_ADDRESS_SETTLE 2 /* ms */
  47529. +#define USB_RESUME_DELAY (20*5) /* ms */
  47530. +#define USB_RESUME_WAIT 10 /* ms */
  47531. +#define USB_RESUME_RECOVERY 10 /* ms */
  47532. +#define USB_EXTRA_POWER_UP_TIME 0 /* ms */
  47533. +#else
  47534. +/* Allow for marginal (i.e. non-conforming) devices. */
  47535. +#define USB_PORT_RESET_DELAY 50 /* ms */
  47536. +#define USB_PORT_ROOT_RESET_DELAY 250 /* ms */
  47537. +#define USB_PORT_RESET_RECOVERY 250 /* ms */
  47538. +#define USB_PORT_POWERUP_DELAY 300 /* ms */
  47539. +#define USB_SET_ADDRESS_SETTLE 10 /* ms */
  47540. +#define USB_RESUME_DELAY (50*5) /* ms */
  47541. +#define USB_RESUME_WAIT 50 /* ms */
  47542. +#define USB_RESUME_RECOVERY 50 /* ms */
  47543. +#define USB_EXTRA_POWER_UP_TIME 20 /* ms */
  47544. +#endif
  47545. +
  47546. +#define USB_MIN_POWER 100 /* mA */
  47547. +#define USB_MAX_POWER 500 /* mA */
  47548. +
  47549. +#define USB_BUS_RESET_DELAY 100 /* ms XXX?*/
  47550. +
  47551. +#define USB_UNCONFIG_NO 0
  47552. +#define USB_UNCONFIG_INDEX (-1)
  47553. +
  47554. +/*** ioctl() related stuff ***/
  47555. +
  47556. +struct usb_ctl_request {
  47557. + int ucr_addr;
  47558. + usb_device_request_t ucr_request;
  47559. + void *ucr_data;
  47560. + int ucr_flags;
  47561. +#define USBD_SHORT_XFER_OK 0x04 /* allow short reads */
  47562. + int ucr_actlen; /* actual length transferred */
  47563. +};
  47564. +
  47565. +struct usb_alt_interface {
  47566. + int uai_config_index;
  47567. + int uai_interface_index;
  47568. + int uai_alt_no;
  47569. +};
  47570. +
  47571. +#define USB_CURRENT_CONFIG_INDEX (-1)
  47572. +#define USB_CURRENT_ALT_INDEX (-1)
  47573. +
  47574. +struct usb_config_desc {
  47575. + int ucd_config_index;
  47576. + usb_config_descriptor_t ucd_desc;
  47577. +};
  47578. +
  47579. +struct usb_interface_desc {
  47580. + int uid_config_index;
  47581. + int uid_interface_index;
  47582. + int uid_alt_index;
  47583. + usb_interface_descriptor_t uid_desc;
  47584. +};
  47585. +
  47586. +struct usb_endpoint_desc {
  47587. + int ued_config_index;
  47588. + int ued_interface_index;
  47589. + int ued_alt_index;
  47590. + int ued_endpoint_index;
  47591. + usb_endpoint_descriptor_t ued_desc;
  47592. +};
  47593. +
  47594. +struct usb_full_desc {
  47595. + int ufd_config_index;
  47596. + u_int ufd_size;
  47597. + u_char *ufd_data;
  47598. +};
  47599. +
  47600. +struct usb_string_desc {
  47601. + int usd_string_index;
  47602. + int usd_language_id;
  47603. + usb_string_descriptor_t usd_desc;
  47604. +};
  47605. +
  47606. +struct usb_ctl_report_desc {
  47607. + int ucrd_size;
  47608. + u_char ucrd_data[1024]; /* filled data size will vary */
  47609. +};
  47610. +
  47611. +typedef struct { u_int32_t cookie; } usb_event_cookie_t;
  47612. +
  47613. +#define USB_MAX_DEVNAMES 4
  47614. +#define USB_MAX_DEVNAMELEN 16
  47615. +struct usb_device_info {
  47616. + u_int8_t udi_bus;
  47617. + u_int8_t udi_addr; /* device address */
  47618. + usb_event_cookie_t udi_cookie;
  47619. + char udi_product[USB_MAX_STRING_LEN];
  47620. + char udi_vendor[USB_MAX_STRING_LEN];
  47621. + char udi_release[8];
  47622. + u_int16_t udi_productNo;
  47623. + u_int16_t udi_vendorNo;
  47624. + u_int16_t udi_releaseNo;
  47625. + u_int8_t udi_class;
  47626. + u_int8_t udi_subclass;
  47627. + u_int8_t udi_protocol;
  47628. + u_int8_t udi_config;
  47629. + u_int8_t udi_speed;
  47630. +#define USB_SPEED_UNKNOWN 0
  47631. +#define USB_SPEED_LOW 1
  47632. +#define USB_SPEED_FULL 2
  47633. +#define USB_SPEED_HIGH 3
  47634. +#define USB_SPEED_VARIABLE 4
  47635. +#define USB_SPEED_SUPER 5
  47636. + int udi_power; /* power consumption in mA, 0 if selfpowered */
  47637. + int udi_nports;
  47638. + char udi_devnames[USB_MAX_DEVNAMES][USB_MAX_DEVNAMELEN];
  47639. + u_int8_t udi_ports[16];/* hub only: addresses of devices on ports */
  47640. +#define USB_PORT_ENABLED 0xff
  47641. +#define USB_PORT_SUSPENDED 0xfe
  47642. +#define USB_PORT_POWERED 0xfd
  47643. +#define USB_PORT_DISABLED 0xfc
  47644. +};
  47645. +
  47646. +struct usb_ctl_report {
  47647. + int ucr_report;
  47648. + u_char ucr_data[1024]; /* filled data size will vary */
  47649. +};
  47650. +
  47651. +struct usb_device_stats {
  47652. + u_long uds_requests[4]; /* indexed by transfer type UE_* */
  47653. +};
  47654. +
  47655. +#define WUSB_MIN_IE 0x80
  47656. +#define WUSB_WCTA_IE 0x80
  47657. +#define WUSB_WCONNECTACK_IE 0x81
  47658. +#define WUSB_WHOSTINFO_IE 0x82
  47659. +#define WUHI_GET_CA(_bmAttributes_) ((_bmAttributes_) & 0x3)
  47660. +#define WUHI_CA_RECONN 0x00
  47661. +#define WUHI_CA_LIMITED 0x01
  47662. +#define WUHI_CA_ALL 0x03
  47663. +#define WUHI_GET_MLSI(_bmAttributes_) (((_bmAttributes_) & 0x38) >> 3)
  47664. +#define WUSB_WCHCHANGEANNOUNCE_IE 0x83
  47665. +#define WUSB_WDEV_DISCONNECT_IE 0x84
  47666. +#define WUSB_WHOST_DISCONNECT_IE 0x85
  47667. +#define WUSB_WRELEASE_CHANNEL_IE 0x86
  47668. +#define WUSB_WWORK_IE 0x87
  47669. +#define WUSB_WCHANNEL_STOP_IE 0x88
  47670. +#define WUSB_WDEV_KEEPALIVE_IE 0x89
  47671. +#define WUSB_WISOCH_DISCARD_IE 0x8A
  47672. +#define WUSB_WRESETDEVICE_IE 0x8B
  47673. +#define WUSB_WXMIT_PACKET_ADJUST_IE 0x8C
  47674. +#define WUSB_MAX_IE 0x8C
  47675. +
  47676. +/* Device Notification Types */
  47677. +
  47678. +#define WUSB_DN_MIN 0x01
  47679. +#define WUSB_DN_CONNECT 0x01
  47680. +# define WUSB_DA_OLDCONN 0x00
  47681. +# define WUSB_DA_NEWCONN 0x01
  47682. +# define WUSB_DA_SELF_BEACON 0x02
  47683. +# define WUSB_DA_DIR_BEACON 0x04
  47684. +# define WUSB_DA_NO_BEACON 0x06
  47685. +#define WUSB_DN_DISCONNECT 0x02
  47686. +#define WUSB_DN_EPRDY 0x03
  47687. +#define WUSB_DN_MASAVAILCHANGED 0x04
  47688. +#define WUSB_DN_REMOTEWAKEUP 0x05
  47689. +#define WUSB_DN_SLEEP 0x06
  47690. +#define WUSB_DN_ALIVE 0x07
  47691. +#define WUSB_DN_MAX 0x07
  47692. +
  47693. +#ifdef _MSC_VER
  47694. +#include <pshpack1.h>
  47695. +#endif
  47696. +
  47697. +/* WUSB Handshake Data. Used during the SET/GET HANDSHAKE requests */
  47698. +typedef struct wusb_hndshk_data {
  47699. + uByte bMessageNumber;
  47700. + uByte bStatus;
  47701. + uByte tTKID[3];
  47702. + uByte bReserved;
  47703. + uByte CDID[16];
  47704. + uByte Nonce[16];
  47705. + uByte MIC[8];
  47706. +} UPACKED wusb_hndshk_data_t;
  47707. +#define WUSB_HANDSHAKE_LEN_FOR_MIC 38
  47708. +
  47709. +/* WUSB Connection Context */
  47710. +typedef struct wusb_conn_context {
  47711. + uByte CHID [16];
  47712. + uByte CDID [16];
  47713. + uByte CK [16];
  47714. +} UPACKED wusb_conn_context_t;
  47715. +
  47716. +/* WUSB Security Descriptor */
  47717. +typedef struct wusb_security_desc {
  47718. + uByte bLength;
  47719. + uByte bDescriptorType;
  47720. + uWord wTotalLength;
  47721. + uByte bNumEncryptionTypes;
  47722. +} UPACKED wusb_security_desc_t;
  47723. +
  47724. +/* WUSB Encryption Type Descriptor */
  47725. +typedef struct wusb_encrypt_type_desc {
  47726. + uByte bLength;
  47727. + uByte bDescriptorType;
  47728. +
  47729. + uByte bEncryptionType;
  47730. +#define WUETD_UNSECURE 0
  47731. +#define WUETD_WIRED 1
  47732. +#define WUETD_CCM_1 2
  47733. +#define WUETD_RSA_1 3
  47734. +
  47735. + uByte bEncryptionValue;
  47736. + uByte bAuthKeyIndex;
  47737. +} UPACKED wusb_encrypt_type_desc_t;
  47738. +
  47739. +/* WUSB Key Descriptor */
  47740. +typedef struct wusb_key_desc {
  47741. + uByte bLength;
  47742. + uByte bDescriptorType;
  47743. + uByte tTKID[3];
  47744. + uByte bReserved;
  47745. + uByte KeyData[1]; /* variable length */
  47746. +} UPACKED wusb_key_desc_t;
  47747. +
  47748. +/* WUSB BOS Descriptor (Binary device Object Store) */
  47749. +typedef struct wusb_bos_desc {
  47750. + uByte bLength;
  47751. + uByte bDescriptorType;
  47752. + uWord wTotalLength;
  47753. + uByte bNumDeviceCaps;
  47754. +} UPACKED wusb_bos_desc_t;
  47755. +
  47756. +#define USB_DEVICE_CAPABILITY_20_EXTENSION 0x02
  47757. +typedef struct usb_dev_cap_20_ext_desc {
  47758. + uByte bLength;
  47759. + uByte bDescriptorType;
  47760. + uByte bDevCapabilityType;
  47761. +#define USB_20_EXT_LPM 0x02
  47762. + uDWord bmAttributes;
  47763. +} UPACKED usb_dev_cap_20_ext_desc_t;
  47764. +
  47765. +#define USB_DEVICE_CAPABILITY_SS_USB 0x03
  47766. +typedef struct usb_dev_cap_ss_usb {
  47767. + uByte bLength;
  47768. + uByte bDescriptorType;
  47769. + uByte bDevCapabilityType;
  47770. +#define USB_DC_SS_USB_LTM_CAPABLE 0x02
  47771. + uByte bmAttributes;
  47772. +#define USB_DC_SS_USB_SPEED_SUPPORT_LOW 0x01
  47773. +#define USB_DC_SS_USB_SPEED_SUPPORT_FULL 0x02
  47774. +#define USB_DC_SS_USB_SPEED_SUPPORT_HIGH 0x04
  47775. +#define USB_DC_SS_USB_SPEED_SUPPORT_SS 0x08
  47776. + uWord wSpeedsSupported;
  47777. + uByte bFunctionalitySupport;
  47778. + uByte bU1DevExitLat;
  47779. + uWord wU2DevExitLat;
  47780. +} UPACKED usb_dev_cap_ss_usb_t;
  47781. +
  47782. +#define USB_DEVICE_CAPABILITY_CONTAINER_ID 0x04
  47783. +typedef struct usb_dev_cap_container_id {
  47784. + uByte bLength;
  47785. + uByte bDescriptorType;
  47786. + uByte bDevCapabilityType;
  47787. + uByte bReserved;
  47788. + uByte containerID[16];
  47789. +} UPACKED usb_dev_cap_container_id_t;
  47790. +
  47791. +/* Device Capability Type Codes */
  47792. +#define WUSB_DEVICE_CAPABILITY_WIRELESS_USB 0x01
  47793. +
  47794. +/* Device Capability Descriptor */
  47795. +typedef struct wusb_dev_cap_desc {
  47796. + uByte bLength;
  47797. + uByte bDescriptorType;
  47798. + uByte bDevCapabilityType;
  47799. + uByte caps[1]; /* Variable length */
  47800. +} UPACKED wusb_dev_cap_desc_t;
  47801. +
  47802. +/* Device Capability Descriptor */
  47803. +typedef struct wusb_dev_cap_uwb_desc {
  47804. + uByte bLength;
  47805. + uByte bDescriptorType;
  47806. + uByte bDevCapabilityType;
  47807. + uByte bmAttributes;
  47808. + uWord wPHYRates; /* Bitmap */
  47809. + uByte bmTFITXPowerInfo;
  47810. + uByte bmFFITXPowerInfo;
  47811. + uWord bmBandGroup;
  47812. + uByte bReserved;
  47813. +} UPACKED wusb_dev_cap_uwb_desc_t;
  47814. +
  47815. +/* Wireless USB Endpoint Companion Descriptor */
  47816. +typedef struct wusb_endpoint_companion_desc {
  47817. + uByte bLength;
  47818. + uByte bDescriptorType;
  47819. + uByte bMaxBurst;
  47820. + uByte bMaxSequence;
  47821. + uWord wMaxStreamDelay;
  47822. + uWord wOverTheAirPacketSize;
  47823. + uByte bOverTheAirInterval;
  47824. + uByte bmCompAttributes;
  47825. +} UPACKED wusb_endpoint_companion_desc_t;
  47826. +
  47827. +/* Wireless USB Numeric Association M1 Data Structure */
  47828. +typedef struct wusb_m1_data {
  47829. + uByte version;
  47830. + uWord langId;
  47831. + uByte deviceFriendlyNameLength;
  47832. + uByte sha_256_m3[32];
  47833. + uByte deviceFriendlyName[256];
  47834. +} UPACKED wusb_m1_data_t;
  47835. +
  47836. +typedef struct wusb_m2_data {
  47837. + uByte version;
  47838. + uWord langId;
  47839. + uByte hostFriendlyNameLength;
  47840. + uByte pkh[384];
  47841. + uByte hostFriendlyName[256];
  47842. +} UPACKED wusb_m2_data_t;
  47843. +
  47844. +typedef struct wusb_m3_data {
  47845. + uByte pkd[384];
  47846. + uByte nd;
  47847. +} UPACKED wusb_m3_data_t;
  47848. +
  47849. +typedef struct wusb_m4_data {
  47850. + uDWord _attributeTypeIdAndLength_1;
  47851. + uWord associationTypeId;
  47852. +
  47853. + uDWord _attributeTypeIdAndLength_2;
  47854. + uWord associationSubTypeId;
  47855. +
  47856. + uDWord _attributeTypeIdAndLength_3;
  47857. + uDWord length;
  47858. +
  47859. + uDWord _attributeTypeIdAndLength_4;
  47860. + uDWord associationStatus;
  47861. +
  47862. + uDWord _attributeTypeIdAndLength_5;
  47863. + uByte chid[16];
  47864. +
  47865. + uDWord _attributeTypeIdAndLength_6;
  47866. + uByte cdid[16];
  47867. +
  47868. + uDWord _attributeTypeIdAndLength_7;
  47869. + uByte bandGroups[2];
  47870. +} UPACKED wusb_m4_data_t;
  47871. +
  47872. +#ifdef _MSC_VER
  47873. +#include <poppack.h>
  47874. +#endif
  47875. +
  47876. +#ifdef __cplusplus
  47877. +}
  47878. +#endif
  47879. +
  47880. +#endif /* _USB_H_ */
  47881. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_otg/doc/doxygen.cfg linux-3.13.3/drivers/usb/host/dwc_otg/doc/doxygen.cfg
  47882. --- linux-3.13.3.orig/drivers/usb/host/dwc_otg/doc/doxygen.cfg 1970-01-01 01:00:00.000000000 +0100
  47883. +++ linux-3.13.3/drivers/usb/host/dwc_otg/doc/doxygen.cfg 2014-02-17 22:41:01.000000000 +0100
  47884. @@ -0,0 +1,224 @@
  47885. +# Doxyfile 1.3.9.1
  47886. +
  47887. +#---------------------------------------------------------------------------
  47888. +# Project related configuration options
  47889. +#---------------------------------------------------------------------------
  47890. +PROJECT_NAME = "DesignWare USB 2.0 OTG Controller (DWC_otg) Device Driver"
  47891. +PROJECT_NUMBER = v3.00a
  47892. +OUTPUT_DIRECTORY = ./doc/
  47893. +CREATE_SUBDIRS = NO
  47894. +OUTPUT_LANGUAGE = English
  47895. +BRIEF_MEMBER_DESC = YES
  47896. +REPEAT_BRIEF = YES
  47897. +ABBREVIATE_BRIEF = "The $name class" \
  47898. + "The $name widget" \
  47899. + "The $name file" \
  47900. + is \
  47901. + provides \
  47902. + specifies \
  47903. + contains \
  47904. + represents \
  47905. + a \
  47906. + an \
  47907. + the
  47908. +ALWAYS_DETAILED_SEC = NO
  47909. +INLINE_INHERITED_MEMB = NO
  47910. +FULL_PATH_NAMES = NO
  47911. +STRIP_FROM_PATH =
  47912. +STRIP_FROM_INC_PATH =
  47913. +SHORT_NAMES = NO
  47914. +JAVADOC_AUTOBRIEF = YES
  47915. +MULTILINE_CPP_IS_BRIEF = NO
  47916. +INHERIT_DOCS = YES
  47917. +DISTRIBUTE_GROUP_DOC = NO
  47918. +TAB_SIZE = 8
  47919. +ALIASES =
  47920. +OPTIMIZE_OUTPUT_FOR_C = YES
  47921. +OPTIMIZE_OUTPUT_JAVA = NO
  47922. +SUBGROUPING = YES
  47923. +#---------------------------------------------------------------------------
  47924. +# Build related configuration options
  47925. +#---------------------------------------------------------------------------
  47926. +EXTRACT_ALL = NO
  47927. +EXTRACT_PRIVATE = YES
  47928. +EXTRACT_STATIC = YES
  47929. +EXTRACT_LOCAL_CLASSES = YES
  47930. +EXTRACT_LOCAL_METHODS = NO
  47931. +HIDE_UNDOC_MEMBERS = NO
  47932. +HIDE_UNDOC_CLASSES = NO
  47933. +HIDE_FRIEND_COMPOUNDS = NO
  47934. +HIDE_IN_BODY_DOCS = NO
  47935. +INTERNAL_DOCS = NO
  47936. +CASE_SENSE_NAMES = NO
  47937. +HIDE_SCOPE_NAMES = NO
  47938. +SHOW_INCLUDE_FILES = YES
  47939. +INLINE_INFO = YES
  47940. +SORT_MEMBER_DOCS = NO
  47941. +SORT_BRIEF_DOCS = NO
  47942. +SORT_BY_SCOPE_NAME = NO
  47943. +GENERATE_TODOLIST = YES
  47944. +GENERATE_TESTLIST = YES
  47945. +GENERATE_BUGLIST = YES
  47946. +GENERATE_DEPRECATEDLIST= YES
  47947. +ENABLED_SECTIONS =
  47948. +MAX_INITIALIZER_LINES = 30
  47949. +SHOW_USED_FILES = YES
  47950. +SHOW_DIRECTORIES = YES
  47951. +#---------------------------------------------------------------------------
  47952. +# configuration options related to warning and progress messages
  47953. +#---------------------------------------------------------------------------
  47954. +QUIET = YES
  47955. +WARNINGS = YES
  47956. +WARN_IF_UNDOCUMENTED = NO
  47957. +WARN_IF_DOC_ERROR = YES
  47958. +WARN_FORMAT = "$file:$line: $text"
  47959. +WARN_LOGFILE =
  47960. +#---------------------------------------------------------------------------
  47961. +# configuration options related to the input files
  47962. +#---------------------------------------------------------------------------
  47963. +INPUT = .
  47964. +FILE_PATTERNS = *.c \
  47965. + *.h \
  47966. + ./linux/*.c \
  47967. + ./linux/*.h
  47968. +RECURSIVE = NO
  47969. +EXCLUDE = ./test/ \
  47970. + ./dwc_otg/.AppleDouble/
  47971. +EXCLUDE_SYMLINKS = YES
  47972. +EXCLUDE_PATTERNS = *.mod.*
  47973. +EXAMPLE_PATH =
  47974. +EXAMPLE_PATTERNS = *
  47975. +EXAMPLE_RECURSIVE = NO
  47976. +IMAGE_PATH =
  47977. +INPUT_FILTER =
  47978. +FILTER_PATTERNS =
  47979. +FILTER_SOURCE_FILES = NO
  47980. +#---------------------------------------------------------------------------
  47981. +# configuration options related to source browsing
  47982. +#---------------------------------------------------------------------------
  47983. +SOURCE_BROWSER = YES
  47984. +INLINE_SOURCES = NO
  47985. +STRIP_CODE_COMMENTS = YES
  47986. +REFERENCED_BY_RELATION = NO
  47987. +REFERENCES_RELATION = NO
  47988. +VERBATIM_HEADERS = NO
  47989. +#---------------------------------------------------------------------------
  47990. +# configuration options related to the alphabetical class index
  47991. +#---------------------------------------------------------------------------
  47992. +ALPHABETICAL_INDEX = NO
  47993. +COLS_IN_ALPHA_INDEX = 5
  47994. +IGNORE_PREFIX =
  47995. +#---------------------------------------------------------------------------
  47996. +# configuration options related to the HTML output
  47997. +#---------------------------------------------------------------------------
  47998. +GENERATE_HTML = YES
  47999. +HTML_OUTPUT = html
  48000. +HTML_FILE_EXTENSION = .html
  48001. +HTML_HEADER =
  48002. +HTML_FOOTER =
  48003. +HTML_STYLESHEET =
  48004. +HTML_ALIGN_MEMBERS = YES
  48005. +GENERATE_HTMLHELP = NO
  48006. +CHM_FILE =
  48007. +HHC_LOCATION =
  48008. +GENERATE_CHI = NO
  48009. +BINARY_TOC = NO
  48010. +TOC_EXPAND = NO
  48011. +DISABLE_INDEX = NO
  48012. +ENUM_VALUES_PER_LINE = 4
  48013. +GENERATE_TREEVIEW = YES
  48014. +TREEVIEW_WIDTH = 250
  48015. +#---------------------------------------------------------------------------
  48016. +# configuration options related to the LaTeX output
  48017. +#---------------------------------------------------------------------------
  48018. +GENERATE_LATEX = NO
  48019. +LATEX_OUTPUT = latex
  48020. +LATEX_CMD_NAME = latex
  48021. +MAKEINDEX_CMD_NAME = makeindex
  48022. +COMPACT_LATEX = NO
  48023. +PAPER_TYPE = a4wide
  48024. +EXTRA_PACKAGES =
  48025. +LATEX_HEADER =
  48026. +PDF_HYPERLINKS = NO
  48027. +USE_PDFLATEX = NO
  48028. +LATEX_BATCHMODE = NO
  48029. +LATEX_HIDE_INDICES = NO
  48030. +#---------------------------------------------------------------------------
  48031. +# configuration options related to the RTF output
  48032. +#---------------------------------------------------------------------------
  48033. +GENERATE_RTF = NO
  48034. +RTF_OUTPUT = rtf
  48035. +COMPACT_RTF = NO
  48036. +RTF_HYPERLINKS = NO
  48037. +RTF_STYLESHEET_FILE =
  48038. +RTF_EXTENSIONS_FILE =
  48039. +#---------------------------------------------------------------------------
  48040. +# configuration options related to the man page output
  48041. +#---------------------------------------------------------------------------
  48042. +GENERATE_MAN = NO
  48043. +MAN_OUTPUT = man
  48044. +MAN_EXTENSION = .3
  48045. +MAN_LINKS = NO
  48046. +#---------------------------------------------------------------------------
  48047. +# configuration options related to the XML output
  48048. +#---------------------------------------------------------------------------
  48049. +GENERATE_XML = NO
  48050. +XML_OUTPUT = xml
  48051. +XML_SCHEMA =
  48052. +XML_DTD =
  48053. +XML_PROGRAMLISTING = YES
  48054. +#---------------------------------------------------------------------------
  48055. +# configuration options for the AutoGen Definitions output
  48056. +#---------------------------------------------------------------------------
  48057. +GENERATE_AUTOGEN_DEF = NO
  48058. +#---------------------------------------------------------------------------
  48059. +# configuration options related to the Perl module output
  48060. +#---------------------------------------------------------------------------
  48061. +GENERATE_PERLMOD = NO
  48062. +PERLMOD_LATEX = NO
  48063. +PERLMOD_PRETTY = YES
  48064. +PERLMOD_MAKEVAR_PREFIX =
  48065. +#---------------------------------------------------------------------------
  48066. +# Configuration options related to the preprocessor
  48067. +#---------------------------------------------------------------------------
  48068. +ENABLE_PREPROCESSING = YES
  48069. +MACRO_EXPANSION = YES
  48070. +EXPAND_ONLY_PREDEF = YES
  48071. +SEARCH_INCLUDES = YES
  48072. +INCLUDE_PATH =
  48073. +INCLUDE_FILE_PATTERNS =
  48074. +PREDEFINED = DEVICE_ATTR DWC_EN_ISOC
  48075. +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
  48076. +SKIP_FUNCTION_MACROS = NO
  48077. +#---------------------------------------------------------------------------
  48078. +# Configuration::additions related to external references
  48079. +#---------------------------------------------------------------------------
  48080. +TAGFILES =
  48081. +GENERATE_TAGFILE =
  48082. +ALLEXTERNALS = NO
  48083. +EXTERNAL_GROUPS = YES
  48084. +PERL_PATH = /usr/bin/perl
  48085. +#---------------------------------------------------------------------------
  48086. +# Configuration options related to the dot tool
  48087. +#---------------------------------------------------------------------------
  48088. +CLASS_DIAGRAMS = YES
  48089. +HIDE_UNDOC_RELATIONS = YES
  48090. +HAVE_DOT = NO
  48091. +CLASS_GRAPH = YES
  48092. +COLLABORATION_GRAPH = YES
  48093. +UML_LOOK = NO
  48094. +TEMPLATE_RELATIONS = NO
  48095. +INCLUDE_GRAPH = YES
  48096. +INCLUDED_BY_GRAPH = YES
  48097. +CALL_GRAPH = NO
  48098. +GRAPHICAL_HIERARCHY = YES
  48099. +DOT_IMAGE_FORMAT = png
  48100. +DOT_PATH =
  48101. +DOTFILE_DIRS =
  48102. +MAX_DOT_GRAPH_DEPTH = 1000
  48103. +GENERATE_LEGEND = YES
  48104. +DOT_CLEANUP = YES
  48105. +#---------------------------------------------------------------------------
  48106. +# Configuration::additions related to the search engine
  48107. +#---------------------------------------------------------------------------
  48108. +SEARCHENGINE = NO
  48109. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_otg/dummy_audio.c linux-3.13.3/drivers/usb/host/dwc_otg/dummy_audio.c
  48110. --- linux-3.13.3.orig/drivers/usb/host/dwc_otg/dummy_audio.c 1970-01-01 01:00:00.000000000 +0100
  48111. +++ linux-3.13.3/drivers/usb/host/dwc_otg/dummy_audio.c 2014-02-17 22:41:01.000000000 +0100
  48112. @@ -0,0 +1,1575 @@
  48113. +/*
  48114. + * zero.c -- Gadget Zero, for USB development
  48115. + *
  48116. + * Copyright (C) 2003-2004 David Brownell
  48117. + * All rights reserved.
  48118. + *
  48119. + * Redistribution and use in source and binary forms, with or without
  48120. + * modification, are permitted provided that the following conditions
  48121. + * are met:
  48122. + * 1. Redistributions of source code must retain the above copyright
  48123. + * notice, this list of conditions, and the following disclaimer,
  48124. + * without modification.
  48125. + * 2. Redistributions in binary form must reproduce the above copyright
  48126. + * notice, this list of conditions and the following disclaimer in the
  48127. + * documentation and/or other materials provided with the distribution.
  48128. + * 3. The names of the above-listed copyright holders may not be used
  48129. + * to endorse or promote products derived from this software without
  48130. + * specific prior written permission.
  48131. + *
  48132. + * ALTERNATIVELY, this software may be distributed under the terms of the
  48133. + * GNU General Public License ("GPL") as published by the Free Software
  48134. + * Foundation, either version 2 of that License or (at your option) any
  48135. + * later version.
  48136. + *
  48137. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  48138. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  48139. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  48140. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  48141. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  48142. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  48143. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  48144. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  48145. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  48146. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  48147. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  48148. + */
  48149. +
  48150. +
  48151. +/*
  48152. + * Gadget Zero only needs two bulk endpoints, and is an example of how you
  48153. + * can write a hardware-agnostic gadget driver running inside a USB device.
  48154. + *
  48155. + * Hardware details are visible (see CONFIG_USB_ZERO_* below) but don't
  48156. + * affect most of the driver.
  48157. + *
  48158. + * Use it with the Linux host/master side "usbtest" driver to get a basic
  48159. + * functional test of your device-side usb stack, or with "usb-skeleton".
  48160. + *
  48161. + * It supports two similar configurations. One sinks whatever the usb host
  48162. + * writes, and in return sources zeroes. The other loops whatever the host
  48163. + * writes back, so the host can read it. Module options include:
  48164. + *
  48165. + * buflen=N default N=4096, buffer size used
  48166. + * qlen=N default N=32, how many buffers in the loopback queue
  48167. + * loopdefault default false, list loopback config first
  48168. + *
  48169. + * Many drivers will only have one configuration, letting them be much
  48170. + * simpler if they also don't support high speed operation (like this
  48171. + * driver does).
  48172. + */
  48173. +
  48174. +#include <linux/config.h>
  48175. +#include <linux/module.h>
  48176. +#include <linux/kernel.h>
  48177. +#include <linux/delay.h>
  48178. +#include <linux/ioport.h>
  48179. +#include <linux/sched.h>
  48180. +#include <linux/slab.h>
  48181. +#include <linux/smp_lock.h>
  48182. +#include <linux/errno.h>
  48183. +#include <linux/init.h>
  48184. +#include <linux/timer.h>
  48185. +#include <linux/list.h>
  48186. +#include <linux/interrupt.h>
  48187. +#include <linux/uts.h>
  48188. +#include <linux/version.h>
  48189. +#include <linux/device.h>
  48190. +#include <linux/moduleparam.h>
  48191. +#include <linux/proc_fs.h>
  48192. +
  48193. +#include <asm/byteorder.h>
  48194. +#include <asm/io.h>
  48195. +#include <asm/irq.h>
  48196. +#include <asm/system.h>
  48197. +#include <asm/unaligned.h>
  48198. +
  48199. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
  48200. +# include <linux/usb/ch9.h>
  48201. +#else
  48202. +# include <linux/usb_ch9.h>
  48203. +#endif
  48204. +
  48205. +#include <linux/usb_gadget.h>
  48206. +
  48207. +
  48208. +/*-------------------------------------------------------------------------*/
  48209. +/*-------------------------------------------------------------------------*/
  48210. +
  48211. +
  48212. +static int utf8_to_utf16le(const char *s, u16 *cp, unsigned len)
  48213. +{
  48214. + int count = 0;
  48215. + u8 c;
  48216. + u16 uchar;
  48217. +
  48218. + /* this insists on correct encodings, though not minimal ones.
  48219. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  48220. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  48221. + */
  48222. + while (len != 0 && (c = (u8) *s++) != 0) {
  48223. + if (unlikely(c & 0x80)) {
  48224. + // 2-byte sequence:
  48225. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  48226. + if ((c & 0xe0) == 0xc0) {
  48227. + uchar = (c & 0x1f) << 6;
  48228. +
  48229. + c = (u8) *s++;
  48230. + if ((c & 0xc0) != 0xc0)
  48231. + goto fail;
  48232. + c &= 0x3f;
  48233. + uchar |= c;
  48234. +
  48235. + // 3-byte sequence (most CJKV characters):
  48236. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  48237. + } else if ((c & 0xf0) == 0xe0) {
  48238. + uchar = (c & 0x0f) << 12;
  48239. +
  48240. + c = (u8) *s++;
  48241. + if ((c & 0xc0) != 0xc0)
  48242. + goto fail;
  48243. + c &= 0x3f;
  48244. + uchar |= c << 6;
  48245. +
  48246. + c = (u8) *s++;
  48247. + if ((c & 0xc0) != 0xc0)
  48248. + goto fail;
  48249. + c &= 0x3f;
  48250. + uchar |= c;
  48251. +
  48252. + /* no bogus surrogates */
  48253. + if (0xd800 <= uchar && uchar <= 0xdfff)
  48254. + goto fail;
  48255. +
  48256. + // 4-byte sequence (surrogate pairs, currently rare):
  48257. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  48258. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  48259. + // (uuuuu = wwww + 1)
  48260. + // FIXME accept the surrogate code points (only)
  48261. +
  48262. + } else
  48263. + goto fail;
  48264. + } else
  48265. + uchar = c;
  48266. + put_unaligned (cpu_to_le16 (uchar), cp++);
  48267. + count++;
  48268. + len--;
  48269. + }
  48270. + return count;
  48271. +fail:
  48272. + return -1;
  48273. +}
  48274. +
  48275. +
  48276. +/**
  48277. + * usb_gadget_get_string - fill out a string descriptor
  48278. + * @table: of c strings encoded using UTF-8
  48279. + * @id: string id, from low byte of wValue in get string descriptor
  48280. + * @buf: at least 256 bytes
  48281. + *
  48282. + * Finds the UTF-8 string matching the ID, and converts it into a
  48283. + * string descriptor in utf16-le.
  48284. + * Returns length of descriptor (always even) or negative errno
  48285. + *
  48286. + * If your driver needs stings in multiple languages, you'll probably
  48287. + * "switch (wIndex) { ... }" in your ep0 string descriptor logic,
  48288. + * using this routine after choosing which set of UTF-8 strings to use.
  48289. + * Note that US-ASCII is a strict subset of UTF-8; any string bytes with
  48290. + * the eighth bit set will be multibyte UTF-8 characters, not ISO-8859/1
  48291. + * characters (which are also widely used in C strings).
  48292. + */
  48293. +int
  48294. +usb_gadget_get_string (struct usb_gadget_strings *table, int id, u8 *buf)
  48295. +{
  48296. + struct usb_string *s;
  48297. + int len;
  48298. +
  48299. + /* descriptor 0 has the language id */
  48300. + if (id == 0) {
  48301. + buf [0] = 4;
  48302. + buf [1] = USB_DT_STRING;
  48303. + buf [2] = (u8) table->language;
  48304. + buf [3] = (u8) (table->language >> 8);
  48305. + return 4;
  48306. + }
  48307. + for (s = table->strings; s && s->s; s++)
  48308. + if (s->id == id)
  48309. + break;
  48310. +
  48311. + /* unrecognized: stall. */
  48312. + if (!s || !s->s)
  48313. + return -EINVAL;
  48314. +
  48315. + /* string descriptors have length, tag, then UTF16-LE text */
  48316. + len = min ((size_t) 126, strlen (s->s));
  48317. + memset (buf + 2, 0, 2 * len); /* zero all the bytes */
  48318. + len = utf8_to_utf16le(s->s, (u16 *)&buf[2], len);
  48319. + if (len < 0)
  48320. + return -EINVAL;
  48321. + buf [0] = (len + 1) * 2;
  48322. + buf [1] = USB_DT_STRING;
  48323. + return buf [0];
  48324. +}
  48325. +
  48326. +
  48327. +/*-------------------------------------------------------------------------*/
  48328. +/*-------------------------------------------------------------------------*/
  48329. +
  48330. +
  48331. +/**
  48332. + * usb_descriptor_fillbuf - fill buffer with descriptors
  48333. + * @buf: Buffer to be filled
  48334. + * @buflen: Size of buf
  48335. + * @src: Array of descriptor pointers, terminated by null pointer.
  48336. + *
  48337. + * Copies descriptors into the buffer, returning the length or a
  48338. + * negative error code if they can't all be copied. Useful when
  48339. + * assembling descriptors for an associated set of interfaces used
  48340. + * as part of configuring a composite device; or in other cases where
  48341. + * sets of descriptors need to be marshaled.
  48342. + */
  48343. +int
  48344. +usb_descriptor_fillbuf(void *buf, unsigned buflen,
  48345. + const struct usb_descriptor_header **src)
  48346. +{
  48347. + u8 *dest = buf;
  48348. +
  48349. + if (!src)
  48350. + return -EINVAL;
  48351. +
  48352. + /* fill buffer from src[] until null descriptor ptr */
  48353. + for (; 0 != *src; src++) {
  48354. + unsigned len = (*src)->bLength;
  48355. +
  48356. + if (len > buflen)
  48357. + return -EINVAL;
  48358. + memcpy(dest, *src, len);
  48359. + buflen -= len;
  48360. + dest += len;
  48361. + }
  48362. + return dest - (u8 *)buf;
  48363. +}
  48364. +
  48365. +
  48366. +/**
  48367. + * usb_gadget_config_buf - builts a complete configuration descriptor
  48368. + * @config: Header for the descriptor, including characteristics such
  48369. + * as power requirements and number of interfaces.
  48370. + * @desc: Null-terminated vector of pointers to the descriptors (interface,
  48371. + * endpoint, etc) defining all functions in this device configuration.
  48372. + * @buf: Buffer for the resulting configuration descriptor.
  48373. + * @length: Length of buffer. If this is not big enough to hold the
  48374. + * entire configuration descriptor, an error code will be returned.
  48375. + *
  48376. + * This copies descriptors into the response buffer, building a descriptor
  48377. + * for that configuration. It returns the buffer length or a negative
  48378. + * status code. The config.wTotalLength field is set to match the length
  48379. + * of the result, but other descriptor fields (including power usage and
  48380. + * interface count) must be set by the caller.
  48381. + *
  48382. + * Gadget drivers could use this when constructing a config descriptor
  48383. + * in response to USB_REQ_GET_DESCRIPTOR. They will need to patch the
  48384. + * resulting bDescriptorType value if USB_DT_OTHER_SPEED_CONFIG is needed.
  48385. + */
  48386. +int usb_gadget_config_buf(
  48387. + const struct usb_config_descriptor *config,
  48388. + void *buf,
  48389. + unsigned length,
  48390. + const struct usb_descriptor_header **desc
  48391. +)
  48392. +{
  48393. + struct usb_config_descriptor *cp = buf;
  48394. + int len;
  48395. +
  48396. + /* config descriptor first */
  48397. + if (length < USB_DT_CONFIG_SIZE || !desc)
  48398. + return -EINVAL;
  48399. + *cp = *config;
  48400. +
  48401. + /* then interface/endpoint/class/vendor/... */
  48402. + len = usb_descriptor_fillbuf(USB_DT_CONFIG_SIZE + (u8*)buf,
  48403. + length - USB_DT_CONFIG_SIZE, desc);
  48404. + if (len < 0)
  48405. + return len;
  48406. + len += USB_DT_CONFIG_SIZE;
  48407. + if (len > 0xffff)
  48408. + return -EINVAL;
  48409. +
  48410. + /* patch up the config descriptor */
  48411. + cp->bLength = USB_DT_CONFIG_SIZE;
  48412. + cp->bDescriptorType = USB_DT_CONFIG;
  48413. + cp->wTotalLength = cpu_to_le16(len);
  48414. + cp->bmAttributes |= USB_CONFIG_ATT_ONE;
  48415. + return len;
  48416. +}
  48417. +
  48418. +/*-------------------------------------------------------------------------*/
  48419. +/*-------------------------------------------------------------------------*/
  48420. +
  48421. +
  48422. +#define RBUF_LEN (1024*1024)
  48423. +static int rbuf_start;
  48424. +static int rbuf_len;
  48425. +static __u8 rbuf[RBUF_LEN];
  48426. +
  48427. +/*-------------------------------------------------------------------------*/
  48428. +
  48429. +#define DRIVER_VERSION "St Patrick's Day 2004"
  48430. +
  48431. +static const char shortname [] = "zero";
  48432. +static const char longname [] = "YAMAHA YST-MS35D USB Speaker ";
  48433. +
  48434. +static const char source_sink [] = "source and sink data";
  48435. +static const char loopback [] = "loop input to output";
  48436. +
  48437. +/*-------------------------------------------------------------------------*/
  48438. +
  48439. +/*
  48440. + * driver assumes self-powered hardware, and
  48441. + * has no way for users to trigger remote wakeup.
  48442. + *
  48443. + * this version autoconfigures as much as possible,
  48444. + * which is reasonable for most "bulk-only" drivers.
  48445. + */
  48446. +static const char *EP_IN_NAME; /* source */
  48447. +static const char *EP_OUT_NAME; /* sink */
  48448. +
  48449. +/*-------------------------------------------------------------------------*/
  48450. +
  48451. +/* big enough to hold our biggest descriptor */
  48452. +#define USB_BUFSIZ 512
  48453. +
  48454. +struct zero_dev {
  48455. + spinlock_t lock;
  48456. + struct usb_gadget *gadget;
  48457. + struct usb_request *req; /* for control responses */
  48458. +
  48459. + /* when configured, we have one of two configs:
  48460. + * - source data (in to host) and sink it (out from host)
  48461. + * - or loop it back (out from host back in to host)
  48462. + */
  48463. + u8 config;
  48464. + struct usb_ep *in_ep, *out_ep;
  48465. +
  48466. + /* autoresume timer */
  48467. + struct timer_list resume;
  48468. +};
  48469. +
  48470. +#define xprintk(d,level,fmt,args...) \
  48471. + dev_printk(level , &(d)->gadget->dev , fmt , ## args)
  48472. +
  48473. +#ifdef DEBUG
  48474. +#define DBG(dev,fmt,args...) \
  48475. + xprintk(dev , KERN_DEBUG , fmt , ## args)
  48476. +#else
  48477. +#define DBG(dev,fmt,args...) \
  48478. + do { } while (0)
  48479. +#endif /* DEBUG */
  48480. +
  48481. +#ifdef VERBOSE
  48482. +#define VDBG DBG
  48483. +#else
  48484. +#define VDBG(dev,fmt,args...) \
  48485. + do { } while (0)
  48486. +#endif /* VERBOSE */
  48487. +
  48488. +#define ERROR(dev,fmt,args...) \
  48489. + xprintk(dev , KERN_ERR , fmt , ## args)
  48490. +#define WARN(dev,fmt,args...) \
  48491. + xprintk(dev , KERN_WARNING , fmt , ## args)
  48492. +#define INFO(dev,fmt,args...) \
  48493. + xprintk(dev , KERN_INFO , fmt , ## args)
  48494. +
  48495. +/*-------------------------------------------------------------------------*/
  48496. +
  48497. +static unsigned buflen = 4096;
  48498. +static unsigned qlen = 32;
  48499. +static unsigned pattern = 0;
  48500. +
  48501. +module_param (buflen, uint, S_IRUGO|S_IWUSR);
  48502. +module_param (qlen, uint, S_IRUGO|S_IWUSR);
  48503. +module_param (pattern, uint, S_IRUGO|S_IWUSR);
  48504. +
  48505. +/*
  48506. + * if it's nonzero, autoresume says how many seconds to wait
  48507. + * before trying to wake up the host after suspend.
  48508. + */
  48509. +static unsigned autoresume = 0;
  48510. +module_param (autoresume, uint, 0);
  48511. +
  48512. +/*
  48513. + * Normally the "loopback" configuration is second (index 1) so
  48514. + * it's not the default. Here's where to change that order, to
  48515. + * work better with hosts where config changes are problematic.
  48516. + * Or controllers (like superh) that only support one config.
  48517. + */
  48518. +static int loopdefault = 0;
  48519. +
  48520. +module_param (loopdefault, bool, S_IRUGO|S_IWUSR);
  48521. +
  48522. +/*-------------------------------------------------------------------------*/
  48523. +
  48524. +/* Thanks to NetChip Technologies for donating this product ID.
  48525. + *
  48526. + * DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!!
  48527. + * Instead: allocate your own, using normal USB-IF procedures.
  48528. + */
  48529. +#ifndef CONFIG_USB_ZERO_HNPTEST
  48530. +#define DRIVER_VENDOR_NUM 0x0525 /* NetChip */
  48531. +#define DRIVER_PRODUCT_NUM 0xa4a0 /* Linux-USB "Gadget Zero" */
  48532. +#else
  48533. +#define DRIVER_VENDOR_NUM 0x1a0a /* OTG test device IDs */
  48534. +#define DRIVER_PRODUCT_NUM 0xbadd
  48535. +#endif
  48536. +
  48537. +/*-------------------------------------------------------------------------*/
  48538. +
  48539. +/*
  48540. + * DESCRIPTORS ... most are static, but strings and (full)
  48541. + * configuration descriptors are built on demand.
  48542. + */
  48543. +
  48544. +/*
  48545. +#define STRING_MANUFACTURER 25
  48546. +#define STRING_PRODUCT 42
  48547. +#define STRING_SERIAL 101
  48548. +*/
  48549. +#define STRING_MANUFACTURER 1
  48550. +#define STRING_PRODUCT 2
  48551. +#define STRING_SERIAL 3
  48552. +
  48553. +#define STRING_SOURCE_SINK 250
  48554. +#define STRING_LOOPBACK 251
  48555. +
  48556. +/*
  48557. + * This device advertises two configurations; these numbers work
  48558. + * on a pxa250 as well as more flexible hardware.
  48559. + */
  48560. +#define CONFIG_SOURCE_SINK 3
  48561. +#define CONFIG_LOOPBACK 2
  48562. +
  48563. +/*
  48564. +static struct usb_device_descriptor
  48565. +device_desc = {
  48566. + .bLength = sizeof device_desc,
  48567. + .bDescriptorType = USB_DT_DEVICE,
  48568. +
  48569. + .bcdUSB = __constant_cpu_to_le16 (0x0200),
  48570. + .bDeviceClass = USB_CLASS_VENDOR_SPEC,
  48571. +
  48572. + .idVendor = __constant_cpu_to_le16 (DRIVER_VENDOR_NUM),
  48573. + .idProduct = __constant_cpu_to_le16 (DRIVER_PRODUCT_NUM),
  48574. + .iManufacturer = STRING_MANUFACTURER,
  48575. + .iProduct = STRING_PRODUCT,
  48576. + .iSerialNumber = STRING_SERIAL,
  48577. + .bNumConfigurations = 2,
  48578. +};
  48579. +*/
  48580. +static struct usb_device_descriptor
  48581. +device_desc = {
  48582. + .bLength = sizeof device_desc,
  48583. + .bDescriptorType = USB_DT_DEVICE,
  48584. + .bcdUSB = __constant_cpu_to_le16 (0x0100),
  48585. + .bDeviceClass = USB_CLASS_PER_INTERFACE,
  48586. + .bDeviceSubClass = 0,
  48587. + .bDeviceProtocol = 0,
  48588. + .bMaxPacketSize0 = 64,
  48589. + .bcdDevice = __constant_cpu_to_le16 (0x0100),
  48590. + .idVendor = __constant_cpu_to_le16 (0x0499),
  48591. + .idProduct = __constant_cpu_to_le16 (0x3002),
  48592. + .iManufacturer = STRING_MANUFACTURER,
  48593. + .iProduct = STRING_PRODUCT,
  48594. + .iSerialNumber = STRING_SERIAL,
  48595. + .bNumConfigurations = 1,
  48596. +};
  48597. +
  48598. +static struct usb_config_descriptor
  48599. +z_config = {
  48600. + .bLength = sizeof z_config,
  48601. + .bDescriptorType = USB_DT_CONFIG,
  48602. +
  48603. + /* compute wTotalLength on the fly */
  48604. + .bNumInterfaces = 2,
  48605. + .bConfigurationValue = 1,
  48606. + .iConfiguration = 0,
  48607. + .bmAttributes = 0x40,
  48608. + .bMaxPower = 0, /* self-powered */
  48609. +};
  48610. +
  48611. +
  48612. +static struct usb_otg_descriptor
  48613. +otg_descriptor = {
  48614. + .bLength = sizeof otg_descriptor,
  48615. + .bDescriptorType = USB_DT_OTG,
  48616. +
  48617. + .bmAttributes = USB_OTG_SRP,
  48618. +};
  48619. +
  48620. +/* one interface in each configuration */
  48621. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  48622. +
  48623. +/*
  48624. + * usb 2.0 devices need to expose both high speed and full speed
  48625. + * descriptors, unless they only run at full speed.
  48626. + *
  48627. + * that means alternate endpoint descriptors (bigger packets)
  48628. + * and a "device qualifier" ... plus more construction options
  48629. + * for the config descriptor.
  48630. + */
  48631. +
  48632. +static struct usb_qualifier_descriptor
  48633. +dev_qualifier = {
  48634. + .bLength = sizeof dev_qualifier,
  48635. + .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
  48636. +
  48637. + .bcdUSB = __constant_cpu_to_le16 (0x0200),
  48638. + .bDeviceClass = USB_CLASS_VENDOR_SPEC,
  48639. +
  48640. + .bNumConfigurations = 2,
  48641. +};
  48642. +
  48643. +
  48644. +struct usb_cs_as_general_descriptor {
  48645. + __u8 bLength;
  48646. + __u8 bDescriptorType;
  48647. +
  48648. + __u8 bDescriptorSubType;
  48649. + __u8 bTerminalLink;
  48650. + __u8 bDelay;
  48651. + __u16 wFormatTag;
  48652. +} __attribute__ ((packed));
  48653. +
  48654. +struct usb_cs_as_format_descriptor {
  48655. + __u8 bLength;
  48656. + __u8 bDescriptorType;
  48657. +
  48658. + __u8 bDescriptorSubType;
  48659. + __u8 bFormatType;
  48660. + __u8 bNrChannels;
  48661. + __u8 bSubframeSize;
  48662. + __u8 bBitResolution;
  48663. + __u8 bSamfreqType;
  48664. + __u8 tLowerSamFreq[3];
  48665. + __u8 tUpperSamFreq[3];
  48666. +} __attribute__ ((packed));
  48667. +
  48668. +static const struct usb_interface_descriptor
  48669. +z_audio_control_if_desc = {
  48670. + .bLength = sizeof z_audio_control_if_desc,
  48671. + .bDescriptorType = USB_DT_INTERFACE,
  48672. + .bInterfaceNumber = 0,
  48673. + .bAlternateSetting = 0,
  48674. + .bNumEndpoints = 0,
  48675. + .bInterfaceClass = USB_CLASS_AUDIO,
  48676. + .bInterfaceSubClass = 0x1,
  48677. + .bInterfaceProtocol = 0,
  48678. + .iInterface = 0,
  48679. +};
  48680. +
  48681. +static const struct usb_interface_descriptor
  48682. +z_audio_if_desc = {
  48683. + .bLength = sizeof z_audio_if_desc,
  48684. + .bDescriptorType = USB_DT_INTERFACE,
  48685. + .bInterfaceNumber = 1,
  48686. + .bAlternateSetting = 0,
  48687. + .bNumEndpoints = 0,
  48688. + .bInterfaceClass = USB_CLASS_AUDIO,
  48689. + .bInterfaceSubClass = 0x2,
  48690. + .bInterfaceProtocol = 0,
  48691. + .iInterface = 0,
  48692. +};
  48693. +
  48694. +static const struct usb_interface_descriptor
  48695. +z_audio_if_desc2 = {
  48696. + .bLength = sizeof z_audio_if_desc,
  48697. + .bDescriptorType = USB_DT_INTERFACE,
  48698. + .bInterfaceNumber = 1,
  48699. + .bAlternateSetting = 1,
  48700. + .bNumEndpoints = 1,
  48701. + .bInterfaceClass = USB_CLASS_AUDIO,
  48702. + .bInterfaceSubClass = 0x2,
  48703. + .bInterfaceProtocol = 0,
  48704. + .iInterface = 0,
  48705. +};
  48706. +
  48707. +static const struct usb_cs_as_general_descriptor
  48708. +z_audio_cs_as_if_desc = {
  48709. + .bLength = 7,
  48710. + .bDescriptorType = 0x24,
  48711. +
  48712. + .bDescriptorSubType = 0x01,
  48713. + .bTerminalLink = 0x01,
  48714. + .bDelay = 0x0,
  48715. + .wFormatTag = __constant_cpu_to_le16 (0x0001)
  48716. +};
  48717. +
  48718. +
  48719. +static const struct usb_cs_as_format_descriptor
  48720. +z_audio_cs_as_format_desc = {
  48721. + .bLength = 0xe,
  48722. + .bDescriptorType = 0x24,
  48723. +
  48724. + .bDescriptorSubType = 2,
  48725. + .bFormatType = 1,
  48726. + .bNrChannels = 1,
  48727. + .bSubframeSize = 1,
  48728. + .bBitResolution = 8,
  48729. + .bSamfreqType = 0,
  48730. + .tLowerSamFreq = {0x7e, 0x13, 0x00},
  48731. + .tUpperSamFreq = {0xe2, 0xd6, 0x00},
  48732. +};
  48733. +
  48734. +static const struct usb_endpoint_descriptor
  48735. +z_iso_ep = {
  48736. + .bLength = 0x09,
  48737. + .bDescriptorType = 0x05,
  48738. + .bEndpointAddress = 0x04,
  48739. + .bmAttributes = 0x09,
  48740. + .wMaxPacketSize = 0x0038,
  48741. + .bInterval = 0x01,
  48742. + .bRefresh = 0x00,
  48743. + .bSynchAddress = 0x00,
  48744. +};
  48745. +
  48746. +static char z_iso_ep2[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  48747. +
  48748. +// 9 bytes
  48749. +static char z_ac_interface_header_desc[] =
  48750. +{ 0x09, 0x24, 0x01, 0x00, 0x01, 0x2b, 0x00, 0x01, 0x01 };
  48751. +
  48752. +// 12 bytes
  48753. +static char z_0[] = {0x0c, 0x24, 0x02, 0x01, 0x01, 0x01, 0x00, 0x02,
  48754. + 0x03, 0x00, 0x00, 0x00};
  48755. +// 13 bytes
  48756. +static char z_1[] = {0x0d, 0x24, 0x06, 0x02, 0x01, 0x02, 0x15, 0x00,
  48757. + 0x02, 0x00, 0x02, 0x00, 0x00};
  48758. +// 9 bytes
  48759. +static char z_2[] = {0x09, 0x24, 0x03, 0x03, 0x01, 0x03, 0x00, 0x02,
  48760. + 0x00};
  48761. +
  48762. +static char za_0[] = {0x09, 0x04, 0x01, 0x02, 0x01, 0x01, 0x02, 0x00,
  48763. + 0x00};
  48764. +
  48765. +static char za_1[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  48766. +
  48767. +static char za_2[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x01, 0x08, 0x00,
  48768. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  48769. +
  48770. +static char za_3[] = {0x09, 0x05, 0x04, 0x09, 0x70, 0x00, 0x01, 0x00,
  48771. + 0x00};
  48772. +
  48773. +static char za_4[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  48774. +
  48775. +static char za_5[] = {0x09, 0x04, 0x01, 0x03, 0x01, 0x01, 0x02, 0x00,
  48776. + 0x00};
  48777. +
  48778. +static char za_6[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  48779. +
  48780. +static char za_7[] = {0x0e, 0x24, 0x02, 0x01, 0x01, 0x02, 0x10, 0x00,
  48781. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  48782. +
  48783. +static char za_8[] = {0x09, 0x05, 0x04, 0x09, 0x70, 0x00, 0x01, 0x00,
  48784. + 0x00};
  48785. +
  48786. +static char za_9[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  48787. +
  48788. +static char za_10[] = {0x09, 0x04, 0x01, 0x04, 0x01, 0x01, 0x02, 0x00,
  48789. + 0x00};
  48790. +
  48791. +static char za_11[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  48792. +
  48793. +static char za_12[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x02, 0x10, 0x00,
  48794. + 0x73, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  48795. +
  48796. +static char za_13[] = {0x09, 0x05, 0x04, 0x09, 0xe0, 0x00, 0x01, 0x00,
  48797. + 0x00};
  48798. +
  48799. +static char za_14[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  48800. +
  48801. +static char za_15[] = {0x09, 0x04, 0x01, 0x05, 0x01, 0x01, 0x02, 0x00,
  48802. + 0x00};
  48803. +
  48804. +static char za_16[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  48805. +
  48806. +static char za_17[] = {0x0e, 0x24, 0x02, 0x01, 0x01, 0x03, 0x14, 0x00,
  48807. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  48808. +
  48809. +static char za_18[] = {0x09, 0x05, 0x04, 0x09, 0xa8, 0x00, 0x01, 0x00,
  48810. + 0x00};
  48811. +
  48812. +static char za_19[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  48813. +
  48814. +static char za_20[] = {0x09, 0x04, 0x01, 0x06, 0x01, 0x01, 0x02, 0x00,
  48815. + 0x00};
  48816. +
  48817. +static char za_21[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  48818. +
  48819. +static char za_22[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x03, 0x14, 0x00,
  48820. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  48821. +
  48822. +static char za_23[] = {0x09, 0x05, 0x04, 0x09, 0x50, 0x01, 0x01, 0x00,
  48823. + 0x00};
  48824. +
  48825. +static char za_24[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  48826. +
  48827. +
  48828. +
  48829. +static const struct usb_descriptor_header *z_function [] = {
  48830. + (struct usb_descriptor_header *) &z_audio_control_if_desc,
  48831. + (struct usb_descriptor_header *) &z_ac_interface_header_desc,
  48832. + (struct usb_descriptor_header *) &z_0,
  48833. + (struct usb_descriptor_header *) &z_1,
  48834. + (struct usb_descriptor_header *) &z_2,
  48835. + (struct usb_descriptor_header *) &z_audio_if_desc,
  48836. + (struct usb_descriptor_header *) &z_audio_if_desc2,
  48837. + (struct usb_descriptor_header *) &z_audio_cs_as_if_desc,
  48838. + (struct usb_descriptor_header *) &z_audio_cs_as_format_desc,
  48839. + (struct usb_descriptor_header *) &z_iso_ep,
  48840. + (struct usb_descriptor_header *) &z_iso_ep2,
  48841. + (struct usb_descriptor_header *) &za_0,
  48842. + (struct usb_descriptor_header *) &za_1,
  48843. + (struct usb_descriptor_header *) &za_2,
  48844. + (struct usb_descriptor_header *) &za_3,
  48845. + (struct usb_descriptor_header *) &za_4,
  48846. + (struct usb_descriptor_header *) &za_5,
  48847. + (struct usb_descriptor_header *) &za_6,
  48848. + (struct usb_descriptor_header *) &za_7,
  48849. + (struct usb_descriptor_header *) &za_8,
  48850. + (struct usb_descriptor_header *) &za_9,
  48851. + (struct usb_descriptor_header *) &za_10,
  48852. + (struct usb_descriptor_header *) &za_11,
  48853. + (struct usb_descriptor_header *) &za_12,
  48854. + (struct usb_descriptor_header *) &za_13,
  48855. + (struct usb_descriptor_header *) &za_14,
  48856. + (struct usb_descriptor_header *) &za_15,
  48857. + (struct usb_descriptor_header *) &za_16,
  48858. + (struct usb_descriptor_header *) &za_17,
  48859. + (struct usb_descriptor_header *) &za_18,
  48860. + (struct usb_descriptor_header *) &za_19,
  48861. + (struct usb_descriptor_header *) &za_20,
  48862. + (struct usb_descriptor_header *) &za_21,
  48863. + (struct usb_descriptor_header *) &za_22,
  48864. + (struct usb_descriptor_header *) &za_23,
  48865. + (struct usb_descriptor_header *) &za_24,
  48866. + NULL,
  48867. +};
  48868. +
  48869. +/* maxpacket and other transfer characteristics vary by speed. */
  48870. +#define ep_desc(g,hs,fs) (((g)->speed==USB_SPEED_HIGH)?(hs):(fs))
  48871. +
  48872. +#else
  48873. +
  48874. +/* if there's no high speed support, maxpacket doesn't change. */
  48875. +#define ep_desc(g,hs,fs) fs
  48876. +
  48877. +#endif /* !CONFIG_USB_GADGET_DUALSPEED */
  48878. +
  48879. +static char manufacturer [40];
  48880. +//static char serial [40];
  48881. +static char serial [] = "Ser 00 em";
  48882. +
  48883. +/* static strings, in UTF-8 */
  48884. +static struct usb_string strings [] = {
  48885. + { STRING_MANUFACTURER, manufacturer, },
  48886. + { STRING_PRODUCT, longname, },
  48887. + { STRING_SERIAL, serial, },
  48888. + { STRING_LOOPBACK, loopback, },
  48889. + { STRING_SOURCE_SINK, source_sink, },
  48890. + { } /* end of list */
  48891. +};
  48892. +
  48893. +static struct usb_gadget_strings stringtab = {
  48894. + .language = 0x0409, /* en-us */
  48895. + .strings = strings,
  48896. +};
  48897. +
  48898. +/*
  48899. + * config descriptors are also handcrafted. these must agree with code
  48900. + * that sets configurations, and with code managing interfaces and their
  48901. + * altsettings. other complexity may come from:
  48902. + *
  48903. + * - high speed support, including "other speed config" rules
  48904. + * - multiple configurations
  48905. + * - interfaces with alternate settings
  48906. + * - embedded class or vendor-specific descriptors
  48907. + *
  48908. + * this handles high speed, and has a second config that could as easily
  48909. + * have been an alternate interface setting (on most hardware).
  48910. + *
  48911. + * NOTE: to demonstrate (and test) more USB capabilities, this driver
  48912. + * should include an altsetting to test interrupt transfers, including
  48913. + * high bandwidth modes at high speed. (Maybe work like Intel's test
  48914. + * device?)
  48915. + */
  48916. +static int
  48917. +config_buf (struct usb_gadget *gadget, u8 *buf, u8 type, unsigned index)
  48918. +{
  48919. + int len;
  48920. + const struct usb_descriptor_header **function;
  48921. +
  48922. + function = z_function;
  48923. + len = usb_gadget_config_buf (&z_config, buf, USB_BUFSIZ, function);
  48924. + if (len < 0)
  48925. + return len;
  48926. + ((struct usb_config_descriptor *) buf)->bDescriptorType = type;
  48927. + return len;
  48928. +}
  48929. +
  48930. +/*-------------------------------------------------------------------------*/
  48931. +
  48932. +static struct usb_request *
  48933. +alloc_ep_req (struct usb_ep *ep, unsigned length)
  48934. +{
  48935. + struct usb_request *req;
  48936. +
  48937. + req = usb_ep_alloc_request (ep, GFP_ATOMIC);
  48938. + if (req) {
  48939. + req->length = length;
  48940. + req->buf = usb_ep_alloc_buffer (ep, length,
  48941. + &req->dma, GFP_ATOMIC);
  48942. + if (!req->buf) {
  48943. + usb_ep_free_request (ep, req);
  48944. + req = NULL;
  48945. + }
  48946. + }
  48947. + return req;
  48948. +}
  48949. +
  48950. +static void free_ep_req (struct usb_ep *ep, struct usb_request *req)
  48951. +{
  48952. + if (req->buf)
  48953. + usb_ep_free_buffer (ep, req->buf, req->dma, req->length);
  48954. + usb_ep_free_request (ep, req);
  48955. +}
  48956. +
  48957. +/*-------------------------------------------------------------------------*/
  48958. +
  48959. +/* optionally require specific source/sink data patterns */
  48960. +
  48961. +static int
  48962. +check_read_data (
  48963. + struct zero_dev *dev,
  48964. + struct usb_ep *ep,
  48965. + struct usb_request *req
  48966. +)
  48967. +{
  48968. + unsigned i;
  48969. + u8 *buf = req->buf;
  48970. +
  48971. + for (i = 0; i < req->actual; i++, buf++) {
  48972. + switch (pattern) {
  48973. + /* all-zeroes has no synchronization issues */
  48974. + case 0:
  48975. + if (*buf == 0)
  48976. + continue;
  48977. + break;
  48978. + /* mod63 stays in sync with short-terminated transfers,
  48979. + * or otherwise when host and gadget agree on how large
  48980. + * each usb transfer request should be. resync is done
  48981. + * with set_interface or set_config.
  48982. + */
  48983. + case 1:
  48984. + if (*buf == (u8)(i % 63))
  48985. + continue;
  48986. + break;
  48987. + }
  48988. + ERROR (dev, "bad OUT byte, buf [%d] = %d\n", i, *buf);
  48989. + usb_ep_set_halt (ep);
  48990. + return -EINVAL;
  48991. + }
  48992. + return 0;
  48993. +}
  48994. +
  48995. +/*-------------------------------------------------------------------------*/
  48996. +
  48997. +static void zero_reset_config (struct zero_dev *dev)
  48998. +{
  48999. + if (dev->config == 0)
  49000. + return;
  49001. +
  49002. + DBG (dev, "reset config\n");
  49003. +
  49004. + /* just disable endpoints, forcing completion of pending i/o.
  49005. + * all our completion handlers free their requests in this case.
  49006. + */
  49007. + if (dev->in_ep) {
  49008. + usb_ep_disable (dev->in_ep);
  49009. + dev->in_ep = NULL;
  49010. + }
  49011. + if (dev->out_ep) {
  49012. + usb_ep_disable (dev->out_ep);
  49013. + dev->out_ep = NULL;
  49014. + }
  49015. + dev->config = 0;
  49016. + del_timer (&dev->resume);
  49017. +}
  49018. +
  49019. +#define _write(f, buf, sz) (f->f_op->write(f, buf, sz, &f->f_pos))
  49020. +
  49021. +static void
  49022. +zero_isoc_complete (struct usb_ep *ep, struct usb_request *req)
  49023. +{
  49024. + struct zero_dev *dev = ep->driver_data;
  49025. + int status = req->status;
  49026. + int i, j;
  49027. +
  49028. + switch (status) {
  49029. +
  49030. + case 0: /* normal completion? */
  49031. + //printk ("\nzero ---------------> isoc normal completion %d bytes\n", req->actual);
  49032. + for (i=0, j=rbuf_start; i<req->actual; i++) {
  49033. + //printk ("%02x ", ((__u8*)req->buf)[i]);
  49034. + rbuf[j] = ((__u8*)req->buf)[i];
  49035. + j++;
  49036. + if (j >= RBUF_LEN) j=0;
  49037. + }
  49038. + rbuf_start = j;
  49039. + //printk ("\n\n");
  49040. +
  49041. + if (rbuf_len < RBUF_LEN) {
  49042. + rbuf_len += req->actual;
  49043. + if (rbuf_len > RBUF_LEN) {
  49044. + rbuf_len = RBUF_LEN;
  49045. + }
  49046. + }
  49047. +
  49048. + break;
  49049. +
  49050. + /* this endpoint is normally active while we're configured */
  49051. + case -ECONNABORTED: /* hardware forced ep reset */
  49052. + case -ECONNRESET: /* request dequeued */
  49053. + case -ESHUTDOWN: /* disconnect from host */
  49054. + VDBG (dev, "%s gone (%d), %d/%d\n", ep->name, status,
  49055. + req->actual, req->length);
  49056. + if (ep == dev->out_ep)
  49057. + check_read_data (dev, ep, req);
  49058. + free_ep_req (ep, req);
  49059. + return;
  49060. +
  49061. + case -EOVERFLOW: /* buffer overrun on read means that
  49062. + * we didn't provide a big enough
  49063. + * buffer.
  49064. + */
  49065. + default:
  49066. +#if 1
  49067. + DBG (dev, "%s complete --> %d, %d/%d\n", ep->name,
  49068. + status, req->actual, req->length);
  49069. +#endif
  49070. + case -EREMOTEIO: /* short read */
  49071. + break;
  49072. + }
  49073. +
  49074. + status = usb_ep_queue (ep, req, GFP_ATOMIC);
  49075. + if (status) {
  49076. + ERROR (dev, "kill %s: resubmit %d bytes --> %d\n",
  49077. + ep->name, req->length, status);
  49078. + usb_ep_set_halt (ep);
  49079. + /* FIXME recover later ... somehow */
  49080. + }
  49081. +}
  49082. +
  49083. +static struct usb_request *
  49084. +zero_start_isoc_ep (struct usb_ep *ep, int gfp_flags)
  49085. +{
  49086. + struct usb_request *req;
  49087. + int status;
  49088. +
  49089. + req = alloc_ep_req (ep, 512);
  49090. + if (!req)
  49091. + return NULL;
  49092. +
  49093. + req->complete = zero_isoc_complete;
  49094. +
  49095. + status = usb_ep_queue (ep, req, gfp_flags);
  49096. + if (status) {
  49097. + struct zero_dev *dev = ep->driver_data;
  49098. +
  49099. + ERROR (dev, "start %s --> %d\n", ep->name, status);
  49100. + free_ep_req (ep, req);
  49101. + req = NULL;
  49102. + }
  49103. +
  49104. + return req;
  49105. +}
  49106. +
  49107. +/* change our operational config. this code must agree with the code
  49108. + * that returns config descriptors, and altsetting code.
  49109. + *
  49110. + * it's also responsible for power management interactions. some
  49111. + * configurations might not work with our current power sources.
  49112. + *
  49113. + * note that some device controller hardware will constrain what this
  49114. + * code can do, perhaps by disallowing more than one configuration or
  49115. + * by limiting configuration choices (like the pxa2xx).
  49116. + */
  49117. +static int
  49118. +zero_set_config (struct zero_dev *dev, unsigned number, int gfp_flags)
  49119. +{
  49120. + int result = 0;
  49121. + struct usb_gadget *gadget = dev->gadget;
  49122. + const struct usb_endpoint_descriptor *d;
  49123. + struct usb_ep *ep;
  49124. +
  49125. + if (number == dev->config)
  49126. + return 0;
  49127. +
  49128. + zero_reset_config (dev);
  49129. +
  49130. + gadget_for_each_ep (ep, gadget) {
  49131. +
  49132. + if (strcmp (ep->name, "ep4") == 0) {
  49133. +
  49134. + d = (struct usb_endpoint_descripter *)&za_23; // isoc ep desc for audio i/f alt setting 6
  49135. + result = usb_ep_enable (ep, d);
  49136. +
  49137. + if (result == 0) {
  49138. + ep->driver_data = dev;
  49139. + dev->in_ep = ep;
  49140. +
  49141. + if (zero_start_isoc_ep (ep, gfp_flags) != 0) {
  49142. +
  49143. + dev->in_ep = ep;
  49144. + continue;
  49145. + }
  49146. +
  49147. + usb_ep_disable (ep);
  49148. + result = -EIO;
  49149. + }
  49150. + }
  49151. +
  49152. + }
  49153. +
  49154. + dev->config = number;
  49155. + return result;
  49156. +}
  49157. +
  49158. +/*-------------------------------------------------------------------------*/
  49159. +
  49160. +static void zero_setup_complete (struct usb_ep *ep, struct usb_request *req)
  49161. +{
  49162. + if (req->status || req->actual != req->length)
  49163. + DBG ((struct zero_dev *) ep->driver_data,
  49164. + "setup complete --> %d, %d/%d\n",
  49165. + req->status, req->actual, req->length);
  49166. +}
  49167. +
  49168. +/*
  49169. + * The setup() callback implements all the ep0 functionality that's
  49170. + * not handled lower down, in hardware or the hardware driver (like
  49171. + * device and endpoint feature flags, and their status). It's all
  49172. + * housekeeping for the gadget function we're implementing. Most of
  49173. + * the work is in config-specific setup.
  49174. + */
  49175. +static int
  49176. +zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
  49177. +{
  49178. + struct zero_dev *dev = get_gadget_data (gadget);
  49179. + struct usb_request *req = dev->req;
  49180. + int value = -EOPNOTSUPP;
  49181. +
  49182. + /* usually this stores reply data in the pre-allocated ep0 buffer,
  49183. + * but config change events will reconfigure hardware.
  49184. + */
  49185. + req->zero = 0;
  49186. + switch (ctrl->bRequest) {
  49187. +
  49188. + case USB_REQ_GET_DESCRIPTOR:
  49189. +
  49190. + switch (ctrl->wValue >> 8) {
  49191. +
  49192. + case USB_DT_DEVICE:
  49193. + value = min (ctrl->wLength, (u16) sizeof device_desc);
  49194. + memcpy (req->buf, &device_desc, value);
  49195. + break;
  49196. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  49197. + case USB_DT_DEVICE_QUALIFIER:
  49198. + if (!gadget->is_dualspeed)
  49199. + break;
  49200. + value = min (ctrl->wLength, (u16) sizeof dev_qualifier);
  49201. + memcpy (req->buf, &dev_qualifier, value);
  49202. + break;
  49203. +
  49204. + case USB_DT_OTHER_SPEED_CONFIG:
  49205. + if (!gadget->is_dualspeed)
  49206. + break;
  49207. + // FALLTHROUGH
  49208. +#endif /* CONFIG_USB_GADGET_DUALSPEED */
  49209. + case USB_DT_CONFIG:
  49210. + value = config_buf (gadget, req->buf,
  49211. + ctrl->wValue >> 8,
  49212. + ctrl->wValue & 0xff);
  49213. + if (value >= 0)
  49214. + value = min (ctrl->wLength, (u16) value);
  49215. + break;
  49216. +
  49217. + case USB_DT_STRING:
  49218. + /* wIndex == language code.
  49219. + * this driver only handles one language, you can
  49220. + * add string tables for other languages, using
  49221. + * any UTF-8 characters
  49222. + */
  49223. + value = usb_gadget_get_string (&stringtab,
  49224. + ctrl->wValue & 0xff, req->buf);
  49225. + if (value >= 0) {
  49226. + value = min (ctrl->wLength, (u16) value);
  49227. + }
  49228. + break;
  49229. + }
  49230. + break;
  49231. +
  49232. + /* currently two configs, two speeds */
  49233. + case USB_REQ_SET_CONFIGURATION:
  49234. + if (ctrl->bRequestType != 0)
  49235. + goto unknown;
  49236. +
  49237. + spin_lock (&dev->lock);
  49238. + value = zero_set_config (dev, ctrl->wValue, GFP_ATOMIC);
  49239. + spin_unlock (&dev->lock);
  49240. + break;
  49241. + case USB_REQ_GET_CONFIGURATION:
  49242. + if (ctrl->bRequestType != USB_DIR_IN)
  49243. + goto unknown;
  49244. + *(u8 *)req->buf = dev->config;
  49245. + value = min (ctrl->wLength, (u16) 1);
  49246. + break;
  49247. +
  49248. + /* until we add altsetting support, or other interfaces,
  49249. + * only 0/0 are possible. pxa2xx only supports 0/0 (poorly)
  49250. + * and already killed pending endpoint I/O.
  49251. + */
  49252. + case USB_REQ_SET_INTERFACE:
  49253. +
  49254. + if (ctrl->bRequestType != USB_RECIP_INTERFACE)
  49255. + goto unknown;
  49256. + spin_lock (&dev->lock);
  49257. + if (dev->config) {
  49258. + u8 config = dev->config;
  49259. +
  49260. + /* resets interface configuration, forgets about
  49261. + * previous transaction state (queued bufs, etc)
  49262. + * and re-inits endpoint state (toggle etc)
  49263. + * no response queued, just zero status == success.
  49264. + * if we had more than one interface we couldn't
  49265. + * use this "reset the config" shortcut.
  49266. + */
  49267. + zero_reset_config (dev);
  49268. + zero_set_config (dev, config, GFP_ATOMIC);
  49269. + value = 0;
  49270. + }
  49271. + spin_unlock (&dev->lock);
  49272. + break;
  49273. + case USB_REQ_GET_INTERFACE:
  49274. + if ((ctrl->bRequestType == 0x21) && (ctrl->wIndex == 0x02)) {
  49275. + value = ctrl->wLength;
  49276. + break;
  49277. + }
  49278. + else {
  49279. + if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE))
  49280. + goto unknown;
  49281. + if (!dev->config)
  49282. + break;
  49283. + if (ctrl->wIndex != 0) {
  49284. + value = -EDOM;
  49285. + break;
  49286. + }
  49287. + *(u8 *)req->buf = 0;
  49288. + value = min (ctrl->wLength, (u16) 1);
  49289. + }
  49290. + break;
  49291. +
  49292. + /*
  49293. + * These are the same vendor-specific requests supported by
  49294. + * Intel's USB 2.0 compliance test devices. We exceed that
  49295. + * device spec by allowing multiple-packet requests.
  49296. + */
  49297. + case 0x5b: /* control WRITE test -- fill the buffer */
  49298. + if (ctrl->bRequestType != (USB_DIR_OUT|USB_TYPE_VENDOR))
  49299. + goto unknown;
  49300. + if (ctrl->wValue || ctrl->wIndex)
  49301. + break;
  49302. + /* just read that many bytes into the buffer */
  49303. + if (ctrl->wLength > USB_BUFSIZ)
  49304. + break;
  49305. + value = ctrl->wLength;
  49306. + break;
  49307. + case 0x5c: /* control READ test -- return the buffer */
  49308. + if (ctrl->bRequestType != (USB_DIR_IN|USB_TYPE_VENDOR))
  49309. + goto unknown;
  49310. + if (ctrl->wValue || ctrl->wIndex)
  49311. + break;
  49312. + /* expect those bytes are still in the buffer; send back */
  49313. + if (ctrl->wLength > USB_BUFSIZ
  49314. + || ctrl->wLength != req->length)
  49315. + break;
  49316. + value = ctrl->wLength;
  49317. + break;
  49318. +
  49319. + case 0x01: // SET_CUR
  49320. + case 0x02:
  49321. + case 0x03:
  49322. + case 0x04:
  49323. + case 0x05:
  49324. + value = ctrl->wLength;
  49325. + break;
  49326. + case 0x81:
  49327. + switch (ctrl->wValue) {
  49328. + case 0x0201:
  49329. + case 0x0202:
  49330. + ((u8*)req->buf)[0] = 0x00;
  49331. + ((u8*)req->buf)[1] = 0xe3;
  49332. + break;
  49333. + case 0x0300:
  49334. + case 0x0500:
  49335. + ((u8*)req->buf)[0] = 0x00;
  49336. + break;
  49337. + }
  49338. + //((u8*)req->buf)[0] = 0x81;
  49339. + //((u8*)req->buf)[1] = 0x81;
  49340. + value = ctrl->wLength;
  49341. + break;
  49342. + case 0x82:
  49343. + switch (ctrl->wValue) {
  49344. + case 0x0201:
  49345. + case 0x0202:
  49346. + ((u8*)req->buf)[0] = 0x00;
  49347. + ((u8*)req->buf)[1] = 0xc3;
  49348. + break;
  49349. + case 0x0300:
  49350. + case 0x0500:
  49351. + ((u8*)req->buf)[0] = 0x00;
  49352. + break;
  49353. + }
  49354. + //((u8*)req->buf)[0] = 0x82;
  49355. + //((u8*)req->buf)[1] = 0x82;
  49356. + value = ctrl->wLength;
  49357. + break;
  49358. + case 0x83:
  49359. + switch (ctrl->wValue) {
  49360. + case 0x0201:
  49361. + case 0x0202:
  49362. + ((u8*)req->buf)[0] = 0x00;
  49363. + ((u8*)req->buf)[1] = 0x00;
  49364. + break;
  49365. + case 0x0300:
  49366. + ((u8*)req->buf)[0] = 0x60;
  49367. + break;
  49368. + case 0x0500:
  49369. + ((u8*)req->buf)[0] = 0x18;
  49370. + break;
  49371. + }
  49372. + //((u8*)req->buf)[0] = 0x83;
  49373. + //((u8*)req->buf)[1] = 0x83;
  49374. + value = ctrl->wLength;
  49375. + break;
  49376. + case 0x84:
  49377. + switch (ctrl->wValue) {
  49378. + case 0x0201:
  49379. + case 0x0202:
  49380. + ((u8*)req->buf)[0] = 0x00;
  49381. + ((u8*)req->buf)[1] = 0x01;
  49382. + break;
  49383. + case 0x0300:
  49384. + case 0x0500:
  49385. + ((u8*)req->buf)[0] = 0x08;
  49386. + break;
  49387. + }
  49388. + //((u8*)req->buf)[0] = 0x84;
  49389. + //((u8*)req->buf)[1] = 0x84;
  49390. + value = ctrl->wLength;
  49391. + break;
  49392. + case 0x85:
  49393. + ((u8*)req->buf)[0] = 0x85;
  49394. + ((u8*)req->buf)[1] = 0x85;
  49395. + value = ctrl->wLength;
  49396. + break;
  49397. +
  49398. +
  49399. + default:
  49400. +unknown:
  49401. + printk("unknown control req%02x.%02x v%04x i%04x l%d\n",
  49402. + ctrl->bRequestType, ctrl->bRequest,
  49403. + ctrl->wValue, ctrl->wIndex, ctrl->wLength);
  49404. + }
  49405. +
  49406. + /* respond with data transfer before status phase? */
  49407. + if (value >= 0) {
  49408. + req->length = value;
  49409. + req->zero = value < ctrl->wLength
  49410. + && (value % gadget->ep0->maxpacket) == 0;
  49411. + value = usb_ep_queue (gadget->ep0, req, GFP_ATOMIC);
  49412. + if (value < 0) {
  49413. + DBG (dev, "ep_queue < 0 --> %d\n", value);
  49414. + req->status = 0;
  49415. + zero_setup_complete (gadget->ep0, req);
  49416. + }
  49417. + }
  49418. +
  49419. + /* device either stalls (value < 0) or reports success */
  49420. + return value;
  49421. +}
  49422. +
  49423. +static void
  49424. +zero_disconnect (struct usb_gadget *gadget)
  49425. +{
  49426. + struct zero_dev *dev = get_gadget_data (gadget);
  49427. + unsigned long flags;
  49428. +
  49429. + spin_lock_irqsave (&dev->lock, flags);
  49430. + zero_reset_config (dev);
  49431. +
  49432. + /* a more significant application might have some non-usb
  49433. + * activities to quiesce here, saving resources like power
  49434. + * or pushing the notification up a network stack.
  49435. + */
  49436. + spin_unlock_irqrestore (&dev->lock, flags);
  49437. +
  49438. + /* next we may get setup() calls to enumerate new connections;
  49439. + * or an unbind() during shutdown (including removing module).
  49440. + */
  49441. +}
  49442. +
  49443. +static void
  49444. +zero_autoresume (unsigned long _dev)
  49445. +{
  49446. + struct zero_dev *dev = (struct zero_dev *) _dev;
  49447. + int status;
  49448. +
  49449. + /* normally the host would be woken up for something
  49450. + * more significant than just a timer firing...
  49451. + */
  49452. + if (dev->gadget->speed != USB_SPEED_UNKNOWN) {
  49453. + status = usb_gadget_wakeup (dev->gadget);
  49454. + DBG (dev, "wakeup --> %d\n", status);
  49455. + }
  49456. +}
  49457. +
  49458. +/*-------------------------------------------------------------------------*/
  49459. +
  49460. +static void
  49461. +zero_unbind (struct usb_gadget *gadget)
  49462. +{
  49463. + struct zero_dev *dev = get_gadget_data (gadget);
  49464. +
  49465. + DBG (dev, "unbind\n");
  49466. +
  49467. + /* we've already been disconnected ... no i/o is active */
  49468. + if (dev->req)
  49469. + free_ep_req (gadget->ep0, dev->req);
  49470. + del_timer_sync (&dev->resume);
  49471. + kfree (dev);
  49472. + set_gadget_data (gadget, NULL);
  49473. +}
  49474. +
  49475. +static int
  49476. +zero_bind (struct usb_gadget *gadget)
  49477. +{
  49478. + struct zero_dev *dev;
  49479. + //struct usb_ep *ep;
  49480. +
  49481. + printk("binding\n");
  49482. + /*
  49483. + * DRIVER POLICY CHOICE: you may want to do this differently.
  49484. + * One thing to avoid is reusing a bcdDevice revision code
  49485. + * with different host-visible configurations or behavior
  49486. + * restrictions -- using ep1in/ep2out vs ep1out/ep3in, etc
  49487. + */
  49488. + //device_desc.bcdDevice = __constant_cpu_to_le16 (0x0201);
  49489. +
  49490. +
  49491. + /* ok, we made sense of the hardware ... */
  49492. + dev = kmalloc (sizeof *dev, SLAB_KERNEL);
  49493. + if (!dev)
  49494. + return -ENOMEM;
  49495. + memset (dev, 0, sizeof *dev);
  49496. + spin_lock_init (&dev->lock);
  49497. + dev->gadget = gadget;
  49498. + set_gadget_data (gadget, dev);
  49499. +
  49500. + /* preallocate control response and buffer */
  49501. + dev->req = usb_ep_alloc_request (gadget->ep0, GFP_KERNEL);
  49502. + if (!dev->req)
  49503. + goto enomem;
  49504. + dev->req->buf = usb_ep_alloc_buffer (gadget->ep0, USB_BUFSIZ,
  49505. + &dev->req->dma, GFP_KERNEL);
  49506. + if (!dev->req->buf)
  49507. + goto enomem;
  49508. +
  49509. + dev->req->complete = zero_setup_complete;
  49510. +
  49511. + device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
  49512. +
  49513. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  49514. + /* assume ep0 uses the same value for both speeds ... */
  49515. + dev_qualifier.bMaxPacketSize0 = device_desc.bMaxPacketSize0;
  49516. +
  49517. + /* and that all endpoints are dual-speed */
  49518. + //hs_source_desc.bEndpointAddress = fs_source_desc.bEndpointAddress;
  49519. + //hs_sink_desc.bEndpointAddress = fs_sink_desc.bEndpointAddress;
  49520. +#endif
  49521. +
  49522. + usb_gadget_set_selfpowered (gadget);
  49523. +
  49524. + init_timer (&dev->resume);
  49525. + dev->resume.function = zero_autoresume;
  49526. + dev->resume.data = (unsigned long) dev;
  49527. +
  49528. + gadget->ep0->driver_data = dev;
  49529. +
  49530. + INFO (dev, "%s, version: " DRIVER_VERSION "\n", longname);
  49531. + INFO (dev, "using %s, OUT %s IN %s\n", gadget->name,
  49532. + EP_OUT_NAME, EP_IN_NAME);
  49533. +
  49534. + snprintf (manufacturer, sizeof manufacturer,
  49535. + UTS_SYSNAME " " UTS_RELEASE " with %s",
  49536. + gadget->name);
  49537. +
  49538. + return 0;
  49539. +
  49540. +enomem:
  49541. + zero_unbind (gadget);
  49542. + return -ENOMEM;
  49543. +}
  49544. +
  49545. +/*-------------------------------------------------------------------------*/
  49546. +
  49547. +static void
  49548. +zero_suspend (struct usb_gadget *gadget)
  49549. +{
  49550. + struct zero_dev *dev = get_gadget_data (gadget);
  49551. +
  49552. + if (gadget->speed == USB_SPEED_UNKNOWN)
  49553. + return;
  49554. +
  49555. + if (autoresume) {
  49556. + mod_timer (&dev->resume, jiffies + (HZ * autoresume));
  49557. + DBG (dev, "suspend, wakeup in %d seconds\n", autoresume);
  49558. + } else
  49559. + DBG (dev, "suspend\n");
  49560. +}
  49561. +
  49562. +static void
  49563. +zero_resume (struct usb_gadget *gadget)
  49564. +{
  49565. + struct zero_dev *dev = get_gadget_data (gadget);
  49566. +
  49567. + DBG (dev, "resume\n");
  49568. + del_timer (&dev->resume);
  49569. +}
  49570. +
  49571. +
  49572. +/*-------------------------------------------------------------------------*/
  49573. +
  49574. +static struct usb_gadget_driver zero_driver = {
  49575. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  49576. + .speed = USB_SPEED_HIGH,
  49577. +#else
  49578. + .speed = USB_SPEED_FULL,
  49579. +#endif
  49580. + .function = (char *) longname,
  49581. + .bind = zero_bind,
  49582. + .unbind = zero_unbind,
  49583. +
  49584. + .setup = zero_setup,
  49585. + .disconnect = zero_disconnect,
  49586. +
  49587. + .suspend = zero_suspend,
  49588. + .resume = zero_resume,
  49589. +
  49590. + .driver = {
  49591. + .name = (char *) shortname,
  49592. + // .shutdown = ...
  49593. + // .suspend = ...
  49594. + // .resume = ...
  49595. + },
  49596. +};
  49597. +
  49598. +MODULE_AUTHOR ("David Brownell");
  49599. +MODULE_LICENSE ("Dual BSD/GPL");
  49600. +
  49601. +static struct proc_dir_entry *pdir, *pfile;
  49602. +
  49603. +static int isoc_read_data (char *page, char **start,
  49604. + off_t off, int count,
  49605. + int *eof, void *data)
  49606. +{
  49607. + int i;
  49608. + static int c = 0;
  49609. + static int done = 0;
  49610. + static int s = 0;
  49611. +
  49612. +/*
  49613. + printk ("\ncount: %d\n", count);
  49614. + printk ("rbuf_start: %d\n", rbuf_start);
  49615. + printk ("rbuf_len: %d\n", rbuf_len);
  49616. + printk ("off: %d\n", off);
  49617. + printk ("start: %p\n\n", *start);
  49618. +*/
  49619. + if (done) {
  49620. + c = 0;
  49621. + done = 0;
  49622. + *eof = 1;
  49623. + return 0;
  49624. + }
  49625. +
  49626. + if (c == 0) {
  49627. + if (rbuf_len == RBUF_LEN)
  49628. + s = rbuf_start;
  49629. + else s = 0;
  49630. + }
  49631. +
  49632. + for (i=0; i<count && c<rbuf_len; i++, c++) {
  49633. + page[i] = rbuf[(c+s) % RBUF_LEN];
  49634. + }
  49635. + *start = page;
  49636. +
  49637. + if (c >= rbuf_len) {
  49638. + *eof = 1;
  49639. + done = 1;
  49640. + }
  49641. +
  49642. +
  49643. + return i;
  49644. +}
  49645. +
  49646. +static int __init init (void)
  49647. +{
  49648. +
  49649. + int retval = 0;
  49650. +
  49651. + pdir = proc_mkdir("isoc_test", NULL);
  49652. + if(pdir == NULL) {
  49653. + retval = -ENOMEM;
  49654. + printk("Error creating dir\n");
  49655. + goto done;
  49656. + }
  49657. + pdir->owner = THIS_MODULE;
  49658. +
  49659. + pfile = create_proc_read_entry("isoc_data",
  49660. + 0444, pdir,
  49661. + isoc_read_data,
  49662. + NULL);
  49663. + if (pfile == NULL) {
  49664. + retval = -ENOMEM;
  49665. + printk("Error creating file\n");
  49666. + goto no_file;
  49667. + }
  49668. + pfile->owner = THIS_MODULE;
  49669. +
  49670. + return usb_gadget_register_driver (&zero_driver);
  49671. +
  49672. + no_file:
  49673. + remove_proc_entry("isoc_data", NULL);
  49674. + done:
  49675. + return retval;
  49676. +}
  49677. +module_init (init);
  49678. +
  49679. +static void __exit cleanup (void)
  49680. +{
  49681. +
  49682. + usb_gadget_unregister_driver (&zero_driver);
  49683. +
  49684. + remove_proc_entry("isoc_data", pdir);
  49685. + remove_proc_entry("isoc_test", NULL);
  49686. +}
  49687. +module_exit (cleanup);
  49688. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_cfi_common.h linux-3.13.3/drivers/usb/host/dwc_otg/dwc_cfi_common.h
  49689. --- linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_cfi_common.h 1970-01-01 01:00:00.000000000 +0100
  49690. +++ linux-3.13.3/drivers/usb/host/dwc_otg/dwc_cfi_common.h 2014-02-17 22:41:01.000000000 +0100
  49691. @@ -0,0 +1,142 @@
  49692. +/* ==========================================================================
  49693. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  49694. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  49695. + * otherwise expressly agreed to in writing between Synopsys and you.
  49696. + *
  49697. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  49698. + * any End User Software License Agreement or Agreement for Licensed Product
  49699. + * with Synopsys or any supplement thereto. You are permitted to use and
  49700. + * redistribute this Software in source and binary forms, with or without
  49701. + * modification, provided that redistributions of source code must retain this
  49702. + * notice. You may not view, use, disclose, copy or distribute this file or
  49703. + * any information contained herein except pursuant to this license grant from
  49704. + * Synopsys. If you do not agree with this notice, including the disclaimer
  49705. + * below, then you are not authorized to use the Software.
  49706. + *
  49707. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  49708. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  49709. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  49710. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  49711. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  49712. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  49713. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  49714. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  49715. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  49716. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  49717. + * DAMAGE.
  49718. + * ========================================================================== */
  49719. +
  49720. +#if !defined(__DWC_CFI_COMMON_H__)
  49721. +#define __DWC_CFI_COMMON_H__
  49722. +
  49723. +//#include <linux/types.h>
  49724. +
  49725. +/**
  49726. + * @file
  49727. + *
  49728. + * This file contains the CFI specific common constants, interfaces
  49729. + * (functions and macros) and structures for Linux. No PCD specific
  49730. + * data structure or definition is to be included in this file.
  49731. + *
  49732. + */
  49733. +
  49734. +/** This is a request for all Core Features */
  49735. +#define VEN_CORE_GET_FEATURES 0xB1
  49736. +
  49737. +/** This is a request to get the value of a specific Core Feature */
  49738. +#define VEN_CORE_GET_FEATURE 0xB2
  49739. +
  49740. +/** This command allows the host to set the value of a specific Core Feature */
  49741. +#define VEN_CORE_SET_FEATURE 0xB3
  49742. +
  49743. +/** This command allows the host to set the default values of
  49744. + * either all or any specific Core Feature
  49745. + */
  49746. +#define VEN_CORE_RESET_FEATURES 0xB4
  49747. +
  49748. +/** This command forces the PCD to write the deferred values of a Core Features */
  49749. +#define VEN_CORE_ACTIVATE_FEATURES 0xB5
  49750. +
  49751. +/** This request reads a DWORD value from a register at the specified offset */
  49752. +#define VEN_CORE_READ_REGISTER 0xB6
  49753. +
  49754. +/** This request writes a DWORD value into a register at the specified offset */
  49755. +#define VEN_CORE_WRITE_REGISTER 0xB7
  49756. +
  49757. +/** This structure is the header of the Core Features dataset returned to
  49758. + * the Host
  49759. + */
  49760. +struct cfi_all_features_header {
  49761. +/** The features header structure length is */
  49762. +#define CFI_ALL_FEATURES_HDR_LEN 8
  49763. + /**
  49764. + * The total length of the features dataset returned to the Host
  49765. + */
  49766. + uint16_t wTotalLen;
  49767. +
  49768. + /**
  49769. + * CFI version number inBinary-Coded Decimal (i.e., 1.00 is 100H).
  49770. + * This field identifies the version of the CFI Specification with which
  49771. + * the device is compliant.
  49772. + */
  49773. + uint16_t wVersion;
  49774. +
  49775. + /** The ID of the Core */
  49776. + uint16_t wCoreID;
  49777. +#define CFI_CORE_ID_UDC 1
  49778. +#define CFI_CORE_ID_OTG 2
  49779. +#define CFI_CORE_ID_WUDEV 3
  49780. +
  49781. + /** Number of features returned by VEN_CORE_GET_FEATURES request */
  49782. + uint16_t wNumFeatures;
  49783. +} UPACKED;
  49784. +
  49785. +typedef struct cfi_all_features_header cfi_all_features_header_t;
  49786. +
  49787. +/** This structure is a header of the Core Feature descriptor dataset returned to
  49788. + * the Host after the VEN_CORE_GET_FEATURES request
  49789. + */
  49790. +struct cfi_feature_desc_header {
  49791. +#define CFI_FEATURE_DESC_HDR_LEN 8
  49792. +
  49793. + /** The feature ID */
  49794. + uint16_t wFeatureID;
  49795. +
  49796. + /** Length of this feature descriptor in bytes - including the
  49797. + * length of the feature name string
  49798. + */
  49799. + uint16_t wLength;
  49800. +
  49801. + /** The data length of this feature in bytes */
  49802. + uint16_t wDataLength;
  49803. +
  49804. + /**
  49805. + * Attributes of this features
  49806. + * D0: Access rights
  49807. + * 0 - Read/Write
  49808. + * 1 - Read only
  49809. + */
  49810. + uint8_t bmAttributes;
  49811. +#define CFI_FEATURE_ATTR_RO 1
  49812. +#define CFI_FEATURE_ATTR_RW 0
  49813. +
  49814. + /** Length of the feature name in bytes */
  49815. + uint8_t bNameLen;
  49816. +
  49817. + /** The feature name buffer */
  49818. + //uint8_t *name;
  49819. +} UPACKED;
  49820. +
  49821. +typedef struct cfi_feature_desc_header cfi_feature_desc_header_t;
  49822. +
  49823. +/**
  49824. + * This structure describes a NULL terminated string referenced by its id field.
  49825. + * It is very similar to usb_string structure but has the id field type set to 16-bit.
  49826. + */
  49827. +struct cfi_string {
  49828. + uint16_t id;
  49829. + const uint8_t *s;
  49830. +};
  49831. +typedef struct cfi_string cfi_string_t;
  49832. +
  49833. +#endif
  49834. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_adp.c linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_adp.c
  49835. --- linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_adp.c 1970-01-01 01:00:00.000000000 +0100
  49836. +++ linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_adp.c 2014-02-17 22:41:01.000000000 +0100
  49837. @@ -0,0 +1,854 @@
  49838. +/* ==========================================================================
  49839. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_adp.c $
  49840. + * $Revision: #12 $
  49841. + * $Date: 2011/10/26 $
  49842. + * $Change: 1873028 $
  49843. + *
  49844. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  49845. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  49846. + * otherwise expressly agreed to in writing between Synopsys and you.
  49847. + *
  49848. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  49849. + * any End User Software License Agreement or Agreement for Licensed Product
  49850. + * with Synopsys or any supplement thereto. You are permitted to use and
  49851. + * redistribute this Software in source and binary forms, with or without
  49852. + * modification, provided that redistributions of source code must retain this
  49853. + * notice. You may not view, use, disclose, copy or distribute this file or
  49854. + * any information contained herein except pursuant to this license grant from
  49855. + * Synopsys. If you do not agree with this notice, including the disclaimer
  49856. + * below, then you are not authorized to use the Software.
  49857. + *
  49858. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  49859. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  49860. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  49861. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  49862. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  49863. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  49864. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  49865. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  49866. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  49867. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  49868. + * DAMAGE.
  49869. + * ========================================================================== */
  49870. +
  49871. +#include "dwc_os.h"
  49872. +#include "dwc_otg_regs.h"
  49873. +#include "dwc_otg_cil.h"
  49874. +#include "dwc_otg_adp.h"
  49875. +
  49876. +/** @file
  49877. + *
  49878. + * This file contains the most of the Attach Detect Protocol implementation for
  49879. + * the driver to support OTG Rev2.0.
  49880. + *
  49881. + */
  49882. +
  49883. +void dwc_otg_adp_write_reg(dwc_otg_core_if_t * core_if, uint32_t value)
  49884. +{
  49885. + adpctl_data_t adpctl;
  49886. +
  49887. + adpctl.d32 = value;
  49888. + adpctl.b.ar = 0x2;
  49889. +
  49890. + DWC_WRITE_REG32(&core_if->core_global_regs->adpctl, adpctl.d32);
  49891. +
  49892. + while (adpctl.b.ar) {
  49893. + adpctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->adpctl);
  49894. + }
  49895. +
  49896. +}
  49897. +
  49898. +/**
  49899. + * Function is called to read ADP registers
  49900. + */
  49901. +uint32_t dwc_otg_adp_read_reg(dwc_otg_core_if_t * core_if)
  49902. +{
  49903. + adpctl_data_t adpctl;
  49904. +
  49905. + adpctl.d32 = 0;
  49906. + adpctl.b.ar = 0x1;
  49907. +
  49908. + DWC_WRITE_REG32(&core_if->core_global_regs->adpctl, adpctl.d32);
  49909. +
  49910. + while (adpctl.b.ar) {
  49911. + adpctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->adpctl);
  49912. + }
  49913. +
  49914. + return adpctl.d32;
  49915. +}
  49916. +
  49917. +/**
  49918. + * Function is called to read ADPCTL register and filter Write-clear bits
  49919. + */
  49920. +uint32_t dwc_otg_adp_read_reg_filter(dwc_otg_core_if_t * core_if)
  49921. +{
  49922. + adpctl_data_t adpctl;
  49923. +
  49924. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  49925. + adpctl.b.adp_tmout_int = 0;
  49926. + adpctl.b.adp_prb_int = 0;
  49927. + adpctl.b.adp_tmout_int = 0;
  49928. +
  49929. + return adpctl.d32;
  49930. +}
  49931. +
  49932. +/**
  49933. + * Function is called to write ADP registers
  49934. + */
  49935. +void dwc_otg_adp_modify_reg(dwc_otg_core_if_t * core_if, uint32_t clr,
  49936. + uint32_t set)
  49937. +{
  49938. + dwc_otg_adp_write_reg(core_if,
  49939. + (dwc_otg_adp_read_reg(core_if) & (~clr)) | set);
  49940. +}
  49941. +
  49942. +static void adp_sense_timeout(void *ptr)
  49943. +{
  49944. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  49945. + core_if->adp.sense_timer_started = 0;
  49946. + DWC_PRINTF("ADP SENSE TIMEOUT\n");
  49947. + if (core_if->adp_enable) {
  49948. + dwc_otg_adp_sense_stop(core_if);
  49949. + dwc_otg_adp_probe_start(core_if);
  49950. + }
  49951. +}
  49952. +
  49953. +/**
  49954. + * This function is called when the ADP vbus timer expires. Timeout is 1.1s.
  49955. + */
  49956. +static void adp_vbuson_timeout(void *ptr)
  49957. +{
  49958. + gpwrdn_data_t gpwrdn;
  49959. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  49960. + hprt0_data_t hprt0 = {.d32 = 0 };
  49961. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  49962. + DWC_PRINTF("%s: 1.1 seconds expire after turning on VBUS\n",__FUNCTION__);
  49963. + if (core_if) {
  49964. + core_if->adp.vbuson_timer_started = 0;
  49965. + /* Turn off vbus */
  49966. + hprt0.b.prtpwr = 1;
  49967. + DWC_MODIFY_REG32(core_if->host_if->hprt0, hprt0.d32, 0);
  49968. + gpwrdn.d32 = 0;
  49969. +
  49970. + /* Power off the core */
  49971. + if (core_if->power_down == 2) {
  49972. + /* Enable Wakeup Logic */
  49973. +// gpwrdn.b.wkupactiv = 1;
  49974. + gpwrdn.b.pmuactv = 0;
  49975. + gpwrdn.b.pwrdnrstn = 1;
  49976. + gpwrdn.b.pwrdnclmp = 1;
  49977. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  49978. + gpwrdn.d32);
  49979. +
  49980. + /* Suspend the Phy Clock */
  49981. + pcgcctl.b.stoppclk = 1;
  49982. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  49983. +
  49984. + /* Switch on VDD */
  49985. +// gpwrdn.b.wkupactiv = 1;
  49986. + gpwrdn.b.pmuactv = 1;
  49987. + gpwrdn.b.pwrdnrstn = 1;
  49988. + gpwrdn.b.pwrdnclmp = 1;
  49989. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  49990. + gpwrdn.d32);
  49991. + } else {
  49992. + /* Enable Power Down Logic */
  49993. + gpwrdn.b.pmuintsel = 1;
  49994. + gpwrdn.b.pmuactv = 1;
  49995. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  49996. + }
  49997. +
  49998. + /* Power off the core */
  49999. + if (core_if->power_down == 2) {
  50000. + gpwrdn.d32 = 0;
  50001. + gpwrdn.b.pwrdnswtch = 1;
  50002. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn,
  50003. + gpwrdn.d32, 0);
  50004. + }
  50005. +
  50006. + /* Unmask SRP detected interrupt from Power Down Logic */
  50007. + gpwrdn.d32 = 0;
  50008. + gpwrdn.b.srp_det_msk = 1;
  50009. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  50010. +
  50011. + dwc_otg_adp_probe_start(core_if);
  50012. + dwc_otg_dump_global_registers(core_if);
  50013. + dwc_otg_dump_host_registers(core_if);
  50014. + }
  50015. +
  50016. +}
  50017. +
  50018. +/**
  50019. + * Start the ADP Initial Probe timer to detect if Port Connected interrupt is
  50020. + * not asserted within 1.1 seconds.
  50021. + *
  50022. + * @param core_if the pointer to core_if strucure.
  50023. + */
  50024. +void dwc_otg_adp_vbuson_timer_start(dwc_otg_core_if_t * core_if)
  50025. +{
  50026. + core_if->adp.vbuson_timer_started = 1;
  50027. + if (core_if->adp.vbuson_timer)
  50028. + {
  50029. + DWC_PRINTF("SCHEDULING VBUSON TIMER\n");
  50030. + /* 1.1 secs + 60ms necessary for cil_hcd_start*/
  50031. + DWC_TIMER_SCHEDULE(core_if->adp.vbuson_timer, 1160);
  50032. + } else {
  50033. + DWC_WARN("VBUSON_TIMER = %p\n",core_if->adp.vbuson_timer);
  50034. + }
  50035. +}
  50036. +
  50037. +#if 0
  50038. +/**
  50039. + * Masks all DWC OTG core interrupts
  50040. + *
  50041. + */
  50042. +static void mask_all_interrupts(dwc_otg_core_if_t * core_if)
  50043. +{
  50044. + int i;
  50045. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  50046. +
  50047. + /* Mask Host Interrupts */
  50048. +
  50049. + /* Clear and disable HCINTs */
  50050. + for (i = 0; i < core_if->core_params->host_channels; i++) {
  50051. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[i]->hcintmsk, 0);
  50052. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[i]->hcint, 0xFFFFFFFF);
  50053. +
  50054. + }
  50055. +
  50056. + /* Clear and disable HAINT */
  50057. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->haintmsk, 0x0000);
  50058. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->haint, 0xFFFFFFFF);
  50059. +
  50060. + /* Mask Device Interrupts */
  50061. + if (!core_if->multiproc_int_enable) {
  50062. + /* Clear and disable IN Endpoint interrupts */
  50063. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->diepmsk, 0);
  50064. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  50065. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->
  50066. + diepint, 0xFFFFFFFF);
  50067. + }
  50068. +
  50069. + /* Clear and disable OUT Endpoint interrupts */
  50070. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->doepmsk, 0);
  50071. + for (i = 0; i <= core_if->dev_if->num_out_eps; i++) {
  50072. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->
  50073. + doepint, 0xFFFFFFFF);
  50074. + }
  50075. +
  50076. + /* Clear and disable DAINT */
  50077. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->daint,
  50078. + 0xFFFFFFFF);
  50079. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->daintmsk, 0);
  50080. + } else {
  50081. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  50082. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  50083. + diepeachintmsk[i], 0);
  50084. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->
  50085. + diepint, 0xFFFFFFFF);
  50086. + }
  50087. +
  50088. + for (i = 0; i < core_if->dev_if->num_out_eps; ++i) {
  50089. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  50090. + doepeachintmsk[i], 0);
  50091. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->
  50092. + doepint, 0xFFFFFFFF);
  50093. + }
  50094. +
  50095. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->deachintmsk,
  50096. + 0);
  50097. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->deachint,
  50098. + 0xFFFFFFFF);
  50099. +
  50100. + }
  50101. +
  50102. + /* Disable interrupts */
  50103. + ahbcfg.b.glblintrmsk = 1;
  50104. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, ahbcfg.d32, 0);
  50105. +
  50106. + /* Disable all interrupts. */
  50107. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, 0);
  50108. +
  50109. + /* Clear any pending interrupts */
  50110. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  50111. +
  50112. + /* Clear any pending OTG Interrupts */
  50113. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgint, 0xFFFFFFFF);
  50114. +}
  50115. +
  50116. +/**
  50117. + * Unmask Port Connection Detected interrupt
  50118. + *
  50119. + */
  50120. +static void unmask_conn_det_intr(dwc_otg_core_if_t * core_if)
  50121. +{
  50122. + gintmsk_data_t gintmsk = {.d32 = 0,.b.portintr = 1 };
  50123. +
  50124. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32);
  50125. +}
  50126. +#endif
  50127. +
  50128. +/**
  50129. + * Starts the ADP Probing
  50130. + *
  50131. + * @param core_if the pointer to core_if structure.
  50132. + */
  50133. +uint32_t dwc_otg_adp_probe_start(dwc_otg_core_if_t * core_if)
  50134. +{
  50135. +
  50136. + adpctl_data_t adpctl = {.d32 = 0};
  50137. + gpwrdn_data_t gpwrdn;
  50138. +#if 0
  50139. + adpctl_data_t adpctl_int = {.d32 = 0, .b.adp_prb_int = 1,
  50140. + .b.adp_sns_int = 1, b.adp_tmout_int};
  50141. +#endif
  50142. + dwc_otg_disable_global_interrupts(core_if);
  50143. + DWC_PRINTF("ADP Probe Start\n");
  50144. + core_if->adp.probe_enabled = 1;
  50145. +
  50146. + adpctl.b.adpres = 1;
  50147. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  50148. +
  50149. + while (adpctl.b.adpres) {
  50150. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  50151. + }
  50152. +
  50153. + adpctl.d32 = 0;
  50154. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  50155. +
  50156. + /* In Host mode unmask SRP detected interrupt */
  50157. + gpwrdn.d32 = 0;
  50158. + gpwrdn.b.sts_chngint_msk = 1;
  50159. + if (!gpwrdn.b.idsts) {
  50160. + gpwrdn.b.srp_det_msk = 1;
  50161. + }
  50162. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  50163. +
  50164. + adpctl.b.adp_tmout_int_msk = 1;
  50165. + adpctl.b.adp_prb_int_msk = 1;
  50166. + adpctl.b.prb_dschg = 1;
  50167. + adpctl.b.prb_delta = 1;
  50168. + adpctl.b.prb_per = 1;
  50169. + adpctl.b.adpen = 1;
  50170. + adpctl.b.enaprb = 1;
  50171. +
  50172. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  50173. + DWC_PRINTF("ADP Probe Finish\n");
  50174. + return 0;
  50175. +}
  50176. +
  50177. +/**
  50178. + * Starts the ADP Sense timer to detect if ADP Sense interrupt is not asserted
  50179. + * within 3 seconds.
  50180. + *
  50181. + * @param core_if the pointer to core_if strucure.
  50182. + */
  50183. +void dwc_otg_adp_sense_timer_start(dwc_otg_core_if_t * core_if)
  50184. +{
  50185. + core_if->adp.sense_timer_started = 1;
  50186. + DWC_TIMER_SCHEDULE(core_if->adp.sense_timer, 3000 /* 3 secs */ );
  50187. +}
  50188. +
  50189. +/**
  50190. + * Starts the ADP Sense
  50191. + *
  50192. + * @param core_if the pointer to core_if strucure.
  50193. + */
  50194. +uint32_t dwc_otg_adp_sense_start(dwc_otg_core_if_t * core_if)
  50195. +{
  50196. + adpctl_data_t adpctl;
  50197. +
  50198. + DWC_PRINTF("ADP Sense Start\n");
  50199. +
  50200. + /* Unmask ADP sense interrupt and mask all other from the core */
  50201. + adpctl.d32 = dwc_otg_adp_read_reg_filter(core_if);
  50202. + adpctl.b.adp_sns_int_msk = 1;
  50203. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  50204. + dwc_otg_disable_global_interrupts(core_if); // vahrama
  50205. +
  50206. + /* Set ADP reset bit*/
  50207. + adpctl.d32 = dwc_otg_adp_read_reg_filter(core_if);
  50208. + adpctl.b.adpres = 1;
  50209. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  50210. +
  50211. + while (adpctl.b.adpres) {
  50212. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  50213. + }
  50214. +
  50215. + adpctl.b.adpres = 0;
  50216. + adpctl.b.adpen = 1;
  50217. + adpctl.b.enasns = 1;
  50218. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  50219. +
  50220. + dwc_otg_adp_sense_timer_start(core_if);
  50221. +
  50222. + return 0;
  50223. +}
  50224. +
  50225. +/**
  50226. + * Stops the ADP Probing
  50227. + *
  50228. + * @param core_if the pointer to core_if strucure.
  50229. + */
  50230. +uint32_t dwc_otg_adp_probe_stop(dwc_otg_core_if_t * core_if)
  50231. +{
  50232. +
  50233. + adpctl_data_t adpctl;
  50234. + DWC_PRINTF("Stop ADP probe\n");
  50235. + core_if->adp.probe_enabled = 0;
  50236. + core_if->adp.probe_counter = 0;
  50237. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  50238. +
  50239. + adpctl.b.adpen = 0;
  50240. + adpctl.b.adp_prb_int = 1;
  50241. + adpctl.b.adp_tmout_int = 1;
  50242. + adpctl.b.adp_sns_int = 1;
  50243. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  50244. +
  50245. + return 0;
  50246. +}
  50247. +
  50248. +/**
  50249. + * Stops the ADP Sensing
  50250. + *
  50251. + * @param core_if the pointer to core_if strucure.
  50252. + */
  50253. +uint32_t dwc_otg_adp_sense_stop(dwc_otg_core_if_t * core_if)
  50254. +{
  50255. + adpctl_data_t adpctl;
  50256. +
  50257. + core_if->adp.sense_enabled = 0;
  50258. +
  50259. + adpctl.d32 = dwc_otg_adp_read_reg_filter(core_if);
  50260. + adpctl.b.enasns = 0;
  50261. + adpctl.b.adp_sns_int = 1;
  50262. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  50263. +
  50264. + return 0;
  50265. +}
  50266. +
  50267. +/**
  50268. + * Called to turn on the VBUS after initial ADP probe in host mode.
  50269. + * If port power was already enabled in cil_hcd_start function then
  50270. + * only schedule a timer.
  50271. + *
  50272. + * @param core_if the pointer to core_if structure.
  50273. + */
  50274. +void dwc_otg_adp_turnon_vbus(dwc_otg_core_if_t * core_if)
  50275. +{
  50276. + hprt0_data_t hprt0 = {.d32 = 0 };
  50277. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  50278. + DWC_PRINTF("Turn on VBUS for 1.1s, port power is %d\n", hprt0.b.prtpwr);
  50279. +
  50280. + if (hprt0.b.prtpwr == 0) {
  50281. + hprt0.b.prtpwr = 1;
  50282. + //DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  50283. + }
  50284. +
  50285. + dwc_otg_adp_vbuson_timer_start(core_if);
  50286. +}
  50287. +
  50288. +/**
  50289. + * Called right after driver is loaded
  50290. + * to perform initial actions for ADP
  50291. + *
  50292. + * @param core_if the pointer to core_if structure.
  50293. + * @param is_host - flag for current mode of operation either from GINTSTS or GPWRDN
  50294. + */
  50295. +void dwc_otg_adp_start(dwc_otg_core_if_t * core_if, uint8_t is_host)
  50296. +{
  50297. + gpwrdn_data_t gpwrdn;
  50298. +
  50299. + DWC_PRINTF("ADP Initial Start\n");
  50300. + core_if->adp.adp_started = 1;
  50301. +
  50302. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  50303. + dwc_otg_disable_global_interrupts(core_if);
  50304. + if (is_host) {
  50305. + DWC_PRINTF("HOST MODE\n");
  50306. + /* Enable Power Down Logic Interrupt*/
  50307. + gpwrdn.d32 = 0;
  50308. + gpwrdn.b.pmuintsel = 1;
  50309. + gpwrdn.b.pmuactv = 1;
  50310. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  50311. + /* Initialize first ADP probe to obtain Ramp Time value */
  50312. + core_if->adp.initial_probe = 1;
  50313. + dwc_otg_adp_probe_start(core_if);
  50314. + } else {
  50315. + gotgctl_data_t gotgctl;
  50316. + gotgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  50317. + DWC_PRINTF("DEVICE MODE\n");
  50318. + if (gotgctl.b.bsesvld == 0) {
  50319. + /* Enable Power Down Logic Interrupt*/
  50320. + gpwrdn.d32 = 0;
  50321. + DWC_PRINTF("VBUS is not valid - start ADP probe\n");
  50322. + gpwrdn.b.pmuintsel = 1;
  50323. + gpwrdn.b.pmuactv = 1;
  50324. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  50325. + core_if->adp.initial_probe = 1;
  50326. + dwc_otg_adp_probe_start(core_if);
  50327. + } else {
  50328. + DWC_PRINTF("VBUS is valid - initialize core as a Device\n");
  50329. + core_if->op_state = B_PERIPHERAL;
  50330. + dwc_otg_core_init(core_if);
  50331. + dwc_otg_enable_global_interrupts(core_if);
  50332. + cil_pcd_start(core_if);
  50333. + dwc_otg_dump_global_registers(core_if);
  50334. + dwc_otg_dump_dev_registers(core_if);
  50335. + }
  50336. + }
  50337. +}
  50338. +
  50339. +void dwc_otg_adp_init(dwc_otg_core_if_t * core_if)
  50340. +{
  50341. + core_if->adp.adp_started = 0;
  50342. + core_if->adp.initial_probe = 0;
  50343. + core_if->adp.probe_timer_values[0] = -1;
  50344. + core_if->adp.probe_timer_values[1] = -1;
  50345. + core_if->adp.probe_enabled = 0;
  50346. + core_if->adp.sense_enabled = 0;
  50347. + core_if->adp.sense_timer_started = 0;
  50348. + core_if->adp.vbuson_timer_started = 0;
  50349. + core_if->adp.probe_counter = 0;
  50350. + core_if->adp.gpwrdn = 0;
  50351. + core_if->adp.attached = DWC_OTG_ADP_UNKOWN;
  50352. + /* Initialize timers */
  50353. + core_if->adp.sense_timer =
  50354. + DWC_TIMER_ALLOC("ADP SENSE TIMER", adp_sense_timeout, core_if);
  50355. + core_if->adp.vbuson_timer =
  50356. + DWC_TIMER_ALLOC("ADP VBUS ON TIMER", adp_vbuson_timeout, core_if);
  50357. + if (!core_if->adp.sense_timer || !core_if->adp.vbuson_timer)
  50358. + {
  50359. + DWC_ERROR("Could not allocate memory for ADP timers\n");
  50360. + }
  50361. +}
  50362. +
  50363. +void dwc_otg_adp_remove(dwc_otg_core_if_t * core_if)
  50364. +{
  50365. + gpwrdn_data_t gpwrdn = { .d32 = 0 };
  50366. + gpwrdn.b.pmuintsel = 1;
  50367. + gpwrdn.b.pmuactv = 1;
  50368. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  50369. +
  50370. + if (core_if->adp.probe_enabled)
  50371. + dwc_otg_adp_probe_stop(core_if);
  50372. + if (core_if->adp.sense_enabled)
  50373. + dwc_otg_adp_sense_stop(core_if);
  50374. + if (core_if->adp.sense_timer_started)
  50375. + DWC_TIMER_CANCEL(core_if->adp.sense_timer);
  50376. + if (core_if->adp.vbuson_timer_started)
  50377. + DWC_TIMER_CANCEL(core_if->adp.vbuson_timer);
  50378. + DWC_TIMER_FREE(core_if->adp.sense_timer);
  50379. + DWC_TIMER_FREE(core_if->adp.vbuson_timer);
  50380. +}
  50381. +
  50382. +/////////////////////////////////////////////////////////////////////
  50383. +////////////// ADP Interrupt Handlers ///////////////////////////////
  50384. +/////////////////////////////////////////////////////////////////////
  50385. +/**
  50386. + * This function sets Ramp Timer values
  50387. + */
  50388. +static uint32_t set_timer_value(dwc_otg_core_if_t * core_if, uint32_t val)
  50389. +{
  50390. + if (core_if->adp.probe_timer_values[0] == -1) {
  50391. + core_if->adp.probe_timer_values[0] = val;
  50392. + core_if->adp.probe_timer_values[1] = -1;
  50393. + return 1;
  50394. + } else {
  50395. + core_if->adp.probe_timer_values[1] =
  50396. + core_if->adp.probe_timer_values[0];
  50397. + core_if->adp.probe_timer_values[0] = val;
  50398. + return 0;
  50399. + }
  50400. +}
  50401. +
  50402. +/**
  50403. + * This function compares Ramp Timer values
  50404. + */
  50405. +static uint32_t compare_timer_values(dwc_otg_core_if_t * core_if)
  50406. +{
  50407. + uint32_t diff;
  50408. + if (core_if->adp.probe_timer_values[0]>=core_if->adp.probe_timer_values[1])
  50409. + diff = core_if->adp.probe_timer_values[0]-core_if->adp.probe_timer_values[1];
  50410. + else
  50411. + diff = core_if->adp.probe_timer_values[1]-core_if->adp.probe_timer_values[0];
  50412. + if(diff < 2) {
  50413. + return 0;
  50414. + } else {
  50415. + return 1;
  50416. + }
  50417. +}
  50418. +
  50419. +/**
  50420. + * This function handles ADP Probe Interrupts
  50421. + */
  50422. +static int32_t dwc_otg_adp_handle_prb_intr(dwc_otg_core_if_t * core_if,
  50423. + uint32_t val)
  50424. +{
  50425. + adpctl_data_t adpctl = {.d32 = 0 };
  50426. + gpwrdn_data_t gpwrdn, temp;
  50427. + adpctl.d32 = val;
  50428. +
  50429. + temp.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  50430. + core_if->adp.probe_counter++;
  50431. + core_if->adp.gpwrdn = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  50432. + if (adpctl.b.rtim == 0 && !temp.b.idsts){
  50433. + DWC_PRINTF("RTIM value is 0\n");
  50434. + goto exit;
  50435. + }
  50436. + if (set_timer_value(core_if, adpctl.b.rtim) &&
  50437. + core_if->adp.initial_probe) {
  50438. + core_if->adp.initial_probe = 0;
  50439. + dwc_otg_adp_probe_stop(core_if);
  50440. + gpwrdn.d32 = 0;
  50441. + gpwrdn.b.pmuactv = 1;
  50442. + gpwrdn.b.pmuintsel = 1;
  50443. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  50444. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  50445. +
  50446. + /* check which value is for device mode and which for Host mode */
  50447. + if (!temp.b.idsts) { /* considered host mode value is 0 */
  50448. + /*
  50449. + * Turn on VBUS after initial ADP probe.
  50450. + */
  50451. + core_if->op_state = A_HOST;
  50452. + dwc_otg_enable_global_interrupts(core_if);
  50453. + DWC_SPINUNLOCK(core_if->lock);
  50454. + cil_hcd_start(core_if);
  50455. + dwc_otg_adp_turnon_vbus(core_if);
  50456. + DWC_SPINLOCK(core_if->lock);
  50457. + } else {
  50458. + /*
  50459. + * Initiate SRP after initial ADP probe.
  50460. + */
  50461. + dwc_otg_enable_global_interrupts(core_if);
  50462. + dwc_otg_initiate_srp(core_if);
  50463. + }
  50464. + } else if (core_if->adp.probe_counter > 2){
  50465. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  50466. + if (compare_timer_values(core_if)) {
  50467. + DWC_PRINTF("Difference in timer values !!! \n");
  50468. +// core_if->adp.attached = DWC_OTG_ADP_ATTACHED;
  50469. + dwc_otg_adp_probe_stop(core_if);
  50470. +
  50471. + /* Power on the core */
  50472. + if (core_if->power_down == 2) {
  50473. + gpwrdn.b.pwrdnswtch = 1;
  50474. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  50475. + gpwrdn, 0, gpwrdn.d32);
  50476. + }
  50477. +
  50478. + /* check which value is for device mode and which for Host mode */
  50479. + if (!temp.b.idsts) { /* considered host mode value is 0 */
  50480. + /* Disable Interrupt from Power Down Logic */
  50481. + gpwrdn.d32 = 0;
  50482. + gpwrdn.b.pmuintsel = 1;
  50483. + gpwrdn.b.pmuactv = 1;
  50484. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  50485. + gpwrdn, gpwrdn.d32, 0);
  50486. +
  50487. + /*
  50488. + * Initialize the Core for Host mode.
  50489. + */
  50490. + core_if->op_state = A_HOST;
  50491. + dwc_otg_core_init(core_if);
  50492. + dwc_otg_enable_global_interrupts(core_if);
  50493. + cil_hcd_start(core_if);
  50494. + } else {
  50495. + gotgctl_data_t gotgctl;
  50496. + /* Mask SRP detected interrupt from Power Down Logic */
  50497. + gpwrdn.d32 = 0;
  50498. + gpwrdn.b.srp_det_msk = 1;
  50499. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  50500. + gpwrdn, gpwrdn.d32, 0);
  50501. +
  50502. + /* Disable Power Down Logic */
  50503. + gpwrdn.d32 = 0;
  50504. + gpwrdn.b.pmuintsel = 1;
  50505. + gpwrdn.b.pmuactv = 1;
  50506. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  50507. + gpwrdn, gpwrdn.d32, 0);
  50508. +
  50509. + /*
  50510. + * Initialize the Core for Device mode.
  50511. + */
  50512. + core_if->op_state = B_PERIPHERAL;
  50513. + dwc_otg_core_init(core_if);
  50514. + dwc_otg_enable_global_interrupts(core_if);
  50515. + cil_pcd_start(core_if);
  50516. +
  50517. + gotgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  50518. + if (!gotgctl.b.bsesvld) {
  50519. + dwc_otg_initiate_srp(core_if);
  50520. + }
  50521. + }
  50522. + }
  50523. + if (core_if->power_down == 2) {
  50524. + if (gpwrdn.b.bsessvld) {
  50525. + /* Mask SRP detected interrupt from Power Down Logic */
  50526. + gpwrdn.d32 = 0;
  50527. + gpwrdn.b.srp_det_msk = 1;
  50528. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  50529. +
  50530. + /* Disable Power Down Logic */
  50531. + gpwrdn.d32 = 0;
  50532. + gpwrdn.b.pmuactv = 1;
  50533. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  50534. +
  50535. + /*
  50536. + * Initialize the Core for Device mode.
  50537. + */
  50538. + core_if->op_state = B_PERIPHERAL;
  50539. + dwc_otg_core_init(core_if);
  50540. + dwc_otg_enable_global_interrupts(core_if);
  50541. + cil_pcd_start(core_if);
  50542. + }
  50543. + }
  50544. + }
  50545. +exit:
  50546. + /* Clear interrupt */
  50547. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  50548. + adpctl.b.adp_prb_int = 1;
  50549. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  50550. +
  50551. + return 0;
  50552. +}
  50553. +
  50554. +/**
  50555. + * This function hadles ADP Sense Interrupt
  50556. + */
  50557. +static int32_t dwc_otg_adp_handle_sns_intr(dwc_otg_core_if_t * core_if)
  50558. +{
  50559. + adpctl_data_t adpctl;
  50560. + /* Stop ADP Sense timer */
  50561. + DWC_TIMER_CANCEL(core_if->adp.sense_timer);
  50562. +
  50563. + /* Restart ADP Sense timer */
  50564. + dwc_otg_adp_sense_timer_start(core_if);
  50565. +
  50566. + /* Clear interrupt */
  50567. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  50568. + adpctl.b.adp_sns_int = 1;
  50569. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  50570. +
  50571. + return 0;
  50572. +}
  50573. +
  50574. +/**
  50575. + * This function handles ADP Probe Interrupts
  50576. + */
  50577. +static int32_t dwc_otg_adp_handle_prb_tmout_intr(dwc_otg_core_if_t * core_if,
  50578. + uint32_t val)
  50579. +{
  50580. + adpctl_data_t adpctl = {.d32 = 0 };
  50581. + adpctl.d32 = val;
  50582. + set_timer_value(core_if, adpctl.b.rtim);
  50583. +
  50584. + /* Clear interrupt */
  50585. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  50586. + adpctl.b.adp_tmout_int = 1;
  50587. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  50588. +
  50589. + return 0;
  50590. +}
  50591. +
  50592. +/**
  50593. + * ADP Interrupt handler.
  50594. + *
  50595. + */
  50596. +int32_t dwc_otg_adp_handle_intr(dwc_otg_core_if_t * core_if)
  50597. +{
  50598. + int retval = 0;
  50599. + adpctl_data_t adpctl = {.d32 = 0};
  50600. +
  50601. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  50602. + DWC_PRINTF("ADPCTL = %08x\n",adpctl.d32);
  50603. +
  50604. + if (adpctl.b.adp_sns_int & adpctl.b.adp_sns_int_msk) {
  50605. + DWC_PRINTF("ADP Sense interrupt\n");
  50606. + retval |= dwc_otg_adp_handle_sns_intr(core_if);
  50607. + }
  50608. + if (adpctl.b.adp_tmout_int & adpctl.b.adp_tmout_int_msk) {
  50609. + DWC_PRINTF("ADP timeout interrupt\n");
  50610. + retval |= dwc_otg_adp_handle_prb_tmout_intr(core_if, adpctl.d32);
  50611. + }
  50612. + if (adpctl.b.adp_prb_int & adpctl.b.adp_prb_int_msk) {
  50613. + DWC_PRINTF("ADP Probe interrupt\n");
  50614. + adpctl.b.adp_prb_int = 1;
  50615. + retval |= dwc_otg_adp_handle_prb_intr(core_if, adpctl.d32);
  50616. + }
  50617. +
  50618. +// dwc_otg_adp_modify_reg(core_if, adpctl.d32, 0);
  50619. + //dwc_otg_adp_write_reg(core_if, adpctl.d32);
  50620. + DWC_PRINTF("RETURN FROM ADP ISR\n");
  50621. +
  50622. + return retval;
  50623. +}
  50624. +
  50625. +/**
  50626. + *
  50627. + * @param core_if Programming view of DWC_otg controller.
  50628. + */
  50629. +int32_t dwc_otg_adp_handle_srp_intr(dwc_otg_core_if_t * core_if)
  50630. +{
  50631. +
  50632. +#ifndef DWC_HOST_ONLY
  50633. + hprt0_data_t hprt0;
  50634. + gpwrdn_data_t gpwrdn;
  50635. + DWC_DEBUGPL(DBG_ANY, "++ Power Down Logic Session Request Interrupt++\n");
  50636. +
  50637. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  50638. + /* check which value is for device mode and which for Host mode */
  50639. + if (!gpwrdn.b.idsts) { /* considered host mode value is 0 */
  50640. + DWC_PRINTF("SRP: Host mode\n");
  50641. +
  50642. + if (core_if->adp_enable) {
  50643. + dwc_otg_adp_probe_stop(core_if);
  50644. +
  50645. + /* Power on the core */
  50646. + if (core_if->power_down == 2) {
  50647. + gpwrdn.b.pwrdnswtch = 1;
  50648. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  50649. + gpwrdn, 0, gpwrdn.d32);
  50650. + }
  50651. +
  50652. + core_if->op_state = A_HOST;
  50653. + dwc_otg_core_init(core_if);
  50654. + dwc_otg_enable_global_interrupts(core_if);
  50655. + cil_hcd_start(core_if);
  50656. + }
  50657. +
  50658. + /* Turn on the port power bit. */
  50659. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  50660. + hprt0.b.prtpwr = 1;
  50661. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  50662. +
  50663. + /* Start the Connection timer. So a message can be displayed
  50664. + * if connect does not occur within 10 seconds. */
  50665. + cil_hcd_session_start(core_if);
  50666. + } else {
  50667. + DWC_PRINTF("SRP: Device mode %s\n", __FUNCTION__);
  50668. + if (core_if->adp_enable) {
  50669. + dwc_otg_adp_probe_stop(core_if);
  50670. +
  50671. + /* Power on the core */
  50672. + if (core_if->power_down == 2) {
  50673. + gpwrdn.b.pwrdnswtch = 1;
  50674. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  50675. + gpwrdn, 0, gpwrdn.d32);
  50676. + }
  50677. +
  50678. + gpwrdn.d32 = 0;
  50679. + gpwrdn.b.pmuactv = 0;
  50680. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  50681. + gpwrdn.d32);
  50682. +
  50683. + core_if->op_state = B_PERIPHERAL;
  50684. + dwc_otg_core_init(core_if);
  50685. + dwc_otg_enable_global_interrupts(core_if);
  50686. + cil_pcd_start(core_if);
  50687. + }
  50688. + }
  50689. +#endif
  50690. + return 1;
  50691. +}
  50692. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_adp.h linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_adp.h
  50693. --- linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_adp.h 1970-01-01 01:00:00.000000000 +0100
  50694. +++ linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_adp.h 2014-02-17 22:41:01.000000000 +0100
  50695. @@ -0,0 +1,80 @@
  50696. +/* ==========================================================================
  50697. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_adp.h $
  50698. + * $Revision: #7 $
  50699. + * $Date: 2011/10/24 $
  50700. + * $Change: 1871159 $
  50701. + *
  50702. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  50703. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  50704. + * otherwise expressly agreed to in writing between Synopsys and you.
  50705. + *
  50706. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  50707. + * any End User Software License Agreement or Agreement for Licensed Product
  50708. + * with Synopsys or any supplement thereto. You are permitted to use and
  50709. + * redistribute this Software in source and binary forms, with or without
  50710. + * modification, provided that redistributions of source code must retain this
  50711. + * notice. You may not view, use, disclose, copy or distribute this file or
  50712. + * any information contained herein except pursuant to this license grant from
  50713. + * Synopsys. If you do not agree with this notice, including the disclaimer
  50714. + * below, then you are not authorized to use the Software.
  50715. + *
  50716. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  50717. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  50718. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  50719. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  50720. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  50721. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  50722. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  50723. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  50724. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  50725. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  50726. + * DAMAGE.
  50727. + * ========================================================================== */
  50728. +
  50729. +#ifndef __DWC_OTG_ADP_H__
  50730. +#define __DWC_OTG_ADP_H__
  50731. +
  50732. +/**
  50733. + * @file
  50734. + *
  50735. + * This file contains the Attach Detect Protocol interfaces and defines
  50736. + * (functions) and structures for Linux.
  50737. + *
  50738. + */
  50739. +
  50740. +#define DWC_OTG_ADP_UNATTACHED 0
  50741. +#define DWC_OTG_ADP_ATTACHED 1
  50742. +#define DWC_OTG_ADP_UNKOWN 2
  50743. +
  50744. +typedef struct dwc_otg_adp {
  50745. + uint32_t adp_started;
  50746. + uint32_t initial_probe;
  50747. + int32_t probe_timer_values[2];
  50748. + uint32_t probe_enabled;
  50749. + uint32_t sense_enabled;
  50750. + dwc_timer_t *sense_timer;
  50751. + uint32_t sense_timer_started;
  50752. + dwc_timer_t *vbuson_timer;
  50753. + uint32_t vbuson_timer_started;
  50754. + uint32_t attached;
  50755. + uint32_t probe_counter;
  50756. + uint32_t gpwrdn;
  50757. +} dwc_otg_adp_t;
  50758. +
  50759. +/**
  50760. + * Attach Detect Protocol functions
  50761. + */
  50762. +
  50763. +extern void dwc_otg_adp_write_reg(dwc_otg_core_if_t * core_if, uint32_t value);
  50764. +extern uint32_t dwc_otg_adp_read_reg(dwc_otg_core_if_t * core_if);
  50765. +extern uint32_t dwc_otg_adp_probe_start(dwc_otg_core_if_t * core_if);
  50766. +extern uint32_t dwc_otg_adp_sense_start(dwc_otg_core_if_t * core_if);
  50767. +extern uint32_t dwc_otg_adp_probe_stop(dwc_otg_core_if_t * core_if);
  50768. +extern uint32_t dwc_otg_adp_sense_stop(dwc_otg_core_if_t * core_if);
  50769. +extern void dwc_otg_adp_start(dwc_otg_core_if_t * core_if, uint8_t is_host);
  50770. +extern void dwc_otg_adp_init(dwc_otg_core_if_t * core_if);
  50771. +extern void dwc_otg_adp_remove(dwc_otg_core_if_t * core_if);
  50772. +extern int32_t dwc_otg_adp_handle_intr(dwc_otg_core_if_t * core_if);
  50773. +extern int32_t dwc_otg_adp_handle_srp_intr(dwc_otg_core_if_t * core_if);
  50774. +
  50775. +#endif //__DWC_OTG_ADP_H__
  50776. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_attr.c linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_attr.c
  50777. --- linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_attr.c 1970-01-01 01:00:00.000000000 +0100
  50778. +++ linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_attr.c 2014-02-17 22:41:01.000000000 +0100
  50779. @@ -0,0 +1,1210 @@
  50780. +/* ==========================================================================
  50781. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_attr.c $
  50782. + * $Revision: #44 $
  50783. + * $Date: 2010/11/29 $
  50784. + * $Change: 1636033 $
  50785. + *
  50786. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  50787. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  50788. + * otherwise expressly agreed to in writing between Synopsys and you.
  50789. + *
  50790. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  50791. + * any End User Software License Agreement or Agreement for Licensed Product
  50792. + * with Synopsys or any supplement thereto. You are permitted to use and
  50793. + * redistribute this Software in source and binary forms, with or without
  50794. + * modification, provided that redistributions of source code must retain this
  50795. + * notice. You may not view, use, disclose, copy or distribute this file or
  50796. + * any information contained herein except pursuant to this license grant from
  50797. + * Synopsys. If you do not agree with this notice, including the disclaimer
  50798. + * below, then you are not authorized to use the Software.
  50799. + *
  50800. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  50801. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  50802. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  50803. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  50804. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  50805. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  50806. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  50807. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  50808. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  50809. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  50810. + * DAMAGE.
  50811. + * ========================================================================== */
  50812. +
  50813. +/** @file
  50814. + *
  50815. + * The diagnostic interface will provide access to the controller for
  50816. + * bringing up the hardware and testing. The Linux driver attributes
  50817. + * feature will be used to provide the Linux Diagnostic
  50818. + * Interface. These attributes are accessed through sysfs.
  50819. + */
  50820. +
  50821. +/** @page "Linux Module Attributes"
  50822. + *
  50823. + * The Linux module attributes feature is used to provide the Linux
  50824. + * Diagnostic Interface. These attributes are accessed through sysfs.
  50825. + * The diagnostic interface will provide access to the controller for
  50826. + * bringing up the hardware and testing.
  50827. +
  50828. + The following table shows the attributes.
  50829. + <table>
  50830. + <tr>
  50831. + <td><b> Name</b></td>
  50832. + <td><b> Description</b></td>
  50833. + <td><b> Access</b></td>
  50834. + </tr>
  50835. +
  50836. + <tr>
  50837. + <td> mode </td>
  50838. + <td> Returns the current mode: 0 for device mode, 1 for host mode</td>
  50839. + <td> Read</td>
  50840. + </tr>
  50841. +
  50842. + <tr>
  50843. + <td> hnpcapable </td>
  50844. + <td> Gets or sets the "HNP-capable" bit in the Core USB Configuraton Register.
  50845. + Read returns the current value.</td>
  50846. + <td> Read/Write</td>
  50847. + </tr>
  50848. +
  50849. + <tr>
  50850. + <td> srpcapable </td>
  50851. + <td> Gets or sets the "SRP-capable" bit in the Core USB Configuraton Register.
  50852. + Read returns the current value.</td>
  50853. + <td> Read/Write</td>
  50854. + </tr>
  50855. +
  50856. + <tr>
  50857. + <td> hsic_connect </td>
  50858. + <td> Gets or sets the "HSIC-Connect" bit in the GLPMCFG Register.
  50859. + Read returns the current value.</td>
  50860. + <td> Read/Write</td>
  50861. + </tr>
  50862. +
  50863. + <tr>
  50864. + <td> inv_sel_hsic </td>
  50865. + <td> Gets or sets the "Invert Select HSIC" bit in the GLPMFG Register.
  50866. + Read returns the current value.</td>
  50867. + <td> Read/Write</td>
  50868. + </tr>
  50869. +
  50870. + <tr>
  50871. + <td> hnp </td>
  50872. + <td> Initiates the Host Negotiation Protocol. Read returns the status.</td>
  50873. + <td> Read/Write</td>
  50874. + </tr>
  50875. +
  50876. + <tr>
  50877. + <td> srp </td>
  50878. + <td> Initiates the Session Request Protocol. Read returns the status.</td>
  50879. + <td> Read/Write</td>
  50880. + </tr>
  50881. +
  50882. + <tr>
  50883. + <td> buspower </td>
  50884. + <td> Gets or sets the Power State of the bus (0 - Off or 1 - On)</td>
  50885. + <td> Read/Write</td>
  50886. + </tr>
  50887. +
  50888. + <tr>
  50889. + <td> bussuspend </td>
  50890. + <td> Suspends the USB bus.</td>
  50891. + <td> Read/Write</td>
  50892. + </tr>
  50893. +
  50894. + <tr>
  50895. + <td> busconnected </td>
  50896. + <td> Gets the connection status of the bus</td>
  50897. + <td> Read</td>
  50898. + </tr>
  50899. +
  50900. + <tr>
  50901. + <td> gotgctl </td>
  50902. + <td> Gets or sets the Core Control Status Register.</td>
  50903. + <td> Read/Write</td>
  50904. + </tr>
  50905. +
  50906. + <tr>
  50907. + <td> gusbcfg </td>
  50908. + <td> Gets or sets the Core USB Configuration Register</td>
  50909. + <td> Read/Write</td>
  50910. + </tr>
  50911. +
  50912. + <tr>
  50913. + <td> grxfsiz </td>
  50914. + <td> Gets or sets the Receive FIFO Size Register</td>
  50915. + <td> Read/Write</td>
  50916. + </tr>
  50917. +
  50918. + <tr>
  50919. + <td> gnptxfsiz </td>
  50920. + <td> Gets or sets the non-periodic Transmit Size Register</td>
  50921. + <td> Read/Write</td>
  50922. + </tr>
  50923. +
  50924. + <tr>
  50925. + <td> gpvndctl </td>
  50926. + <td> Gets or sets the PHY Vendor Control Register</td>
  50927. + <td> Read/Write</td>
  50928. + </tr>
  50929. +
  50930. + <tr>
  50931. + <td> ggpio </td>
  50932. + <td> Gets the value in the lower 16-bits of the General Purpose IO Register
  50933. + or sets the upper 16 bits.</td>
  50934. + <td> Read/Write</td>
  50935. + </tr>
  50936. +
  50937. + <tr>
  50938. + <td> guid </td>
  50939. + <td> Gets or sets the value of the User ID Register</td>
  50940. + <td> Read/Write</td>
  50941. + </tr>
  50942. +
  50943. + <tr>
  50944. + <td> gsnpsid </td>
  50945. + <td> Gets the value of the Synopsys ID Regester</td>
  50946. + <td> Read</td>
  50947. + </tr>
  50948. +
  50949. + <tr>
  50950. + <td> devspeed </td>
  50951. + <td> Gets or sets the device speed setting in the DCFG register</td>
  50952. + <td> Read/Write</td>
  50953. + </tr>
  50954. +
  50955. + <tr>
  50956. + <td> enumspeed </td>
  50957. + <td> Gets the device enumeration Speed.</td>
  50958. + <td> Read</td>
  50959. + </tr>
  50960. +
  50961. + <tr>
  50962. + <td> hptxfsiz </td>
  50963. + <td> Gets the value of the Host Periodic Transmit FIFO</td>
  50964. + <td> Read</td>
  50965. + </tr>
  50966. +
  50967. + <tr>
  50968. + <td> hprt0 </td>
  50969. + <td> Gets or sets the value in the Host Port Control and Status Register</td>
  50970. + <td> Read/Write</td>
  50971. + </tr>
  50972. +
  50973. + <tr>
  50974. + <td> regoffset </td>
  50975. + <td> Sets the register offset for the next Register Access</td>
  50976. + <td> Read/Write</td>
  50977. + </tr>
  50978. +
  50979. + <tr>
  50980. + <td> regvalue </td>
  50981. + <td> Gets or sets the value of the register at the offset in the regoffset attribute.</td>
  50982. + <td> Read/Write</td>
  50983. + </tr>
  50984. +
  50985. + <tr>
  50986. + <td> remote_wakeup </td>
  50987. + <td> On read, shows the status of Remote Wakeup. On write, initiates a remote
  50988. + wakeup of the host. When bit 0 is 1 and Remote Wakeup is enabled, the Remote
  50989. + Wakeup signalling bit in the Device Control Register is set for 1
  50990. + milli-second.</td>
  50991. + <td> Read/Write</td>
  50992. + </tr>
  50993. +
  50994. + <tr>
  50995. + <td> rem_wakeup_pwrdn </td>
  50996. + <td> On read, shows the status core - hibernated or not. On write, initiates
  50997. + a remote wakeup of the device from Hibernation. </td>
  50998. + <td> Read/Write</td>
  50999. + </tr>
  51000. +
  51001. + <tr>
  51002. + <td> mode_ch_tim_en </td>
  51003. + <td> This bit is used to enable or disable the host core to wait for 200 PHY
  51004. + clock cycles at the end of Resume to change the opmode signal to the PHY to 00
  51005. + after Suspend or LPM. </td>
  51006. + <td> Read/Write</td>
  51007. + </tr>
  51008. +
  51009. + <tr>
  51010. + <td> fr_interval </td>
  51011. + <td> On read, shows the value of HFIR Frame Interval. On write, dynamically
  51012. + reload HFIR register during runtime. The application can write a value to this
  51013. + register only after the Port Enable bit of the Host Port Control and Status
  51014. + register (HPRT.PrtEnaPort) has been set </td>
  51015. + <td> Read/Write</td>
  51016. + </tr>
  51017. +
  51018. + <tr>
  51019. + <td> disconnect_us </td>
  51020. + <td> On read, shows the status of disconnect_device_us. On write, sets disconnect_us
  51021. + which causes soft disconnect for 100us. Applicable only for device mode of operation.</td>
  51022. + <td> Read/Write</td>
  51023. + </tr>
  51024. +
  51025. + <tr>
  51026. + <td> regdump </td>
  51027. + <td> Dumps the contents of core registers.</td>
  51028. + <td> Read</td>
  51029. + </tr>
  51030. +
  51031. + <tr>
  51032. + <td> spramdump </td>
  51033. + <td> Dumps the contents of core registers.</td>
  51034. + <td> Read</td>
  51035. + </tr>
  51036. +
  51037. + <tr>
  51038. + <td> hcddump </td>
  51039. + <td> Dumps the current HCD state.</td>
  51040. + <td> Read</td>
  51041. + </tr>
  51042. +
  51043. + <tr>
  51044. + <td> hcd_frrem </td>
  51045. + <td> Shows the average value of the Frame Remaining
  51046. + field in the Host Frame Number/Frame Remaining register when an SOF interrupt
  51047. + occurs. This can be used to determine the average interrupt latency. Also
  51048. + shows the average Frame Remaining value for start_transfer and the "a" and
  51049. + "b" sample points. The "a" and "b" sample points may be used during debugging
  51050. + bto determine how long it takes to execute a section of the HCD code.</td>
  51051. + <td> Read</td>
  51052. + </tr>
  51053. +
  51054. + <tr>
  51055. + <td> rd_reg_test </td>
  51056. + <td> Displays the time required to read the GNPTXFSIZ register many times
  51057. + (the output shows the number of times the register is read).
  51058. + <td> Read</td>
  51059. + </tr>
  51060. +
  51061. + <tr>
  51062. + <td> wr_reg_test </td>
  51063. + <td> Displays the time required to write the GNPTXFSIZ register many times
  51064. + (the output shows the number of times the register is written).
  51065. + <td> Read</td>
  51066. + </tr>
  51067. +
  51068. + <tr>
  51069. + <td> lpm_response </td>
  51070. + <td> Gets or sets lpm_response mode. Applicable only in device mode.
  51071. + <td> Write</td>
  51072. + </tr>
  51073. +
  51074. + <tr>
  51075. + <td> sleep_status </td>
  51076. + <td> Shows sleep status of device.
  51077. + <td> Read</td>
  51078. + </tr>
  51079. +
  51080. + </table>
  51081. +
  51082. + Example usage:
  51083. + To get the current mode:
  51084. + cat /sys/devices/lm0/mode
  51085. +
  51086. + To power down the USB:
  51087. + echo 0 > /sys/devices/lm0/buspower
  51088. + */
  51089. +
  51090. +#include "dwc_otg_os_dep.h"
  51091. +#include "dwc_os.h"
  51092. +#include "dwc_otg_driver.h"
  51093. +#include "dwc_otg_attr.h"
  51094. +#include "dwc_otg_core_if.h"
  51095. +#include "dwc_otg_pcd_if.h"
  51096. +#include "dwc_otg_hcd_if.h"
  51097. +
  51098. +/*
  51099. + * MACROs for defining sysfs attribute
  51100. + */
  51101. +#ifdef LM_INTERFACE
  51102. +
  51103. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  51104. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  51105. +{ \
  51106. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  51107. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  51108. + uint32_t val; \
  51109. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  51110. + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
  51111. +}
  51112. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  51113. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  51114. + const char *buf, size_t count) \
  51115. +{ \
  51116. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  51117. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  51118. + uint32_t set = simple_strtoul(buf, NULL, 16); \
  51119. + dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
  51120. + return count; \
  51121. +}
  51122. +
  51123. +#elif defined(PCI_INTERFACE)
  51124. +
  51125. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  51126. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  51127. +{ \
  51128. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  51129. + uint32_t val; \
  51130. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  51131. + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
  51132. +}
  51133. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  51134. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  51135. + const char *buf, size_t count) \
  51136. +{ \
  51137. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  51138. + uint32_t set = simple_strtoul(buf, NULL, 16); \
  51139. + dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
  51140. + return count; \
  51141. +}
  51142. +
  51143. +#elif defined(PLATFORM_INTERFACE)
  51144. +
  51145. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  51146. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  51147. +{ \
  51148. + struct platform_device *platform_dev = \
  51149. + container_of(_dev, struct platform_device, dev); \
  51150. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  51151. + uint32_t val; \
  51152. + DWC_PRINTF("%s(%p) -> platform_dev %p, otg_dev %p\n", \
  51153. + __func__, _dev, platform_dev, otg_dev); \
  51154. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  51155. + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
  51156. +}
  51157. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  51158. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  51159. + const char *buf, size_t count) \
  51160. +{ \
  51161. + struct platform_device *platform_dev = container_of(_dev, struct platform_device, dev); \
  51162. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  51163. + uint32_t set = simple_strtoul(buf, NULL, 16); \
  51164. + dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
  51165. + return count; \
  51166. +}
  51167. +#endif
  51168. +
  51169. +/*
  51170. + * MACROs for defining sysfs attribute for 32-bit registers
  51171. + */
  51172. +#ifdef LM_INTERFACE
  51173. +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  51174. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  51175. +{ \
  51176. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  51177. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  51178. + uint32_t val; \
  51179. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  51180. + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
  51181. +}
  51182. +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  51183. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  51184. + const char *buf, size_t count) \
  51185. +{ \
  51186. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  51187. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  51188. + uint32_t val = simple_strtoul(buf, NULL, 16); \
  51189. + dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
  51190. + return count; \
  51191. +}
  51192. +#elif defined(PCI_INTERFACE)
  51193. +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  51194. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  51195. +{ \
  51196. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  51197. + uint32_t val; \
  51198. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  51199. + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
  51200. +}
  51201. +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  51202. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  51203. + const char *buf, size_t count) \
  51204. +{ \
  51205. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  51206. + uint32_t val = simple_strtoul(buf, NULL, 16); \
  51207. + dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
  51208. + return count; \
  51209. +}
  51210. +
  51211. +#elif defined(PLATFORM_INTERFACE)
  51212. +#include "dwc_otg_dbg.h"
  51213. +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  51214. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  51215. +{ \
  51216. + struct platform_device *platform_dev = container_of(_dev, struct platform_device, dev); \
  51217. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  51218. + uint32_t val; \
  51219. + DWC_PRINTF("%s(%p) -> platform_dev %p, otg_dev %p\n", \
  51220. + __func__, _dev, platform_dev, otg_dev); \
  51221. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  51222. + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
  51223. +}
  51224. +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  51225. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  51226. + const char *buf, size_t count) \
  51227. +{ \
  51228. + struct platform_device *platform_dev = container_of(_dev, struct platform_device, dev); \
  51229. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  51230. + uint32_t val = simple_strtoul(buf, NULL, 16); \
  51231. + dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
  51232. + return count; \
  51233. +}
  51234. +
  51235. +#endif
  51236. +
  51237. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_RW(_otg_attr_name_,_string_) \
  51238. +DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  51239. +DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  51240. +DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);
  51241. +
  51242. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_RO(_otg_attr_name_,_string_) \
  51243. +DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  51244. +DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);
  51245. +
  51246. +#define DWC_OTG_DEVICE_ATTR_REG32_RW(_otg_attr_name_,_addr_,_string_) \
  51247. +DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  51248. +DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  51249. +DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);
  51250. +
  51251. +#define DWC_OTG_DEVICE_ATTR_REG32_RO(_otg_attr_name_,_addr_,_string_) \
  51252. +DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  51253. +DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);
  51254. +
  51255. +/** @name Functions for Show/Store of Attributes */
  51256. +/**@{*/
  51257. +
  51258. +/**
  51259. + * Helper function returning the otg_device structure of the given device
  51260. + */
  51261. +static dwc_otg_device_t *dwc_otg_drvdev(struct device *_dev)
  51262. +{
  51263. + dwc_otg_device_t *otg_dev;
  51264. + DWC_OTG_GETDRVDEV(otg_dev, _dev);
  51265. + return otg_dev;
  51266. +}
  51267. +
  51268. +/**
  51269. + * Show the register offset of the Register Access.
  51270. + */
  51271. +static ssize_t regoffset_show(struct device *_dev,
  51272. + struct device_attribute *attr, char *buf)
  51273. +{
  51274. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  51275. + return snprintf(buf, sizeof("0xFFFFFFFF\n") + 1, "0x%08x\n",
  51276. + otg_dev->os_dep.reg_offset);
  51277. +}
  51278. +
  51279. +/**
  51280. + * Set the register offset for the next Register Access Read/Write
  51281. + */
  51282. +static ssize_t regoffset_store(struct device *_dev,
  51283. + struct device_attribute *attr,
  51284. + const char *buf, size_t count)
  51285. +{
  51286. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  51287. + uint32_t offset = simple_strtoul(buf, NULL, 16);
  51288. +#if defined(LM_INTERFACE) || defined(PLATFORM_INTERFACE)
  51289. + if (offset < SZ_256K) {
  51290. +#elif defined(PCI_INTERFACE)
  51291. + if (offset < 0x00040000) {
  51292. +#endif
  51293. + otg_dev->os_dep.reg_offset = offset;
  51294. + } else {
  51295. + dev_err(_dev, "invalid offset\n");
  51296. + }
  51297. +
  51298. + return count;
  51299. +}
  51300. +
  51301. +DEVICE_ATTR(regoffset, S_IRUGO | S_IWUSR, regoffset_show, regoffset_store);
  51302. +
  51303. +/**
  51304. + * Show the value of the register at the offset in the reg_offset
  51305. + * attribute.
  51306. + */
  51307. +static ssize_t regvalue_show(struct device *_dev,
  51308. + struct device_attribute *attr, char *buf)
  51309. +{
  51310. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  51311. + uint32_t val;
  51312. + volatile uint32_t *addr;
  51313. +
  51314. + if (otg_dev->os_dep.reg_offset != 0xFFFFFFFF && 0 != otg_dev->os_dep.base) {
  51315. + /* Calculate the address */
  51316. + addr = (uint32_t *) (otg_dev->os_dep.reg_offset +
  51317. + (uint8_t *) otg_dev->os_dep.base);
  51318. + val = DWC_READ_REG32(addr);
  51319. + return snprintf(buf,
  51320. + sizeof("Reg@0xFFFFFFFF = 0xFFFFFFFF\n") + 1,
  51321. + "Reg@0x%06x = 0x%08x\n", otg_dev->os_dep.reg_offset,
  51322. + val);
  51323. + } else {
  51324. + dev_err(_dev, "Invalid offset (0x%0x)\n", otg_dev->os_dep.reg_offset);
  51325. + return sprintf(buf, "invalid offset\n");
  51326. + }
  51327. +}
  51328. +
  51329. +/**
  51330. + * Store the value in the register at the offset in the reg_offset
  51331. + * attribute.
  51332. + *
  51333. + */
  51334. +static ssize_t regvalue_store(struct device *_dev,
  51335. + struct device_attribute *attr,
  51336. + const char *buf, size_t count)
  51337. +{
  51338. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  51339. + volatile uint32_t *addr;
  51340. + uint32_t val = simple_strtoul(buf, NULL, 16);
  51341. + //dev_dbg(_dev, "Offset=0x%08x Val=0x%08x\n", otg_dev->reg_offset, val);
  51342. + if (otg_dev->os_dep.reg_offset != 0xFFFFFFFF && 0 != otg_dev->os_dep.base) {
  51343. + /* Calculate the address */
  51344. + addr = (uint32_t *) (otg_dev->os_dep.reg_offset +
  51345. + (uint8_t *) otg_dev->os_dep.base);
  51346. + DWC_WRITE_REG32(addr, val);
  51347. + } else {
  51348. + dev_err(_dev, "Invalid Register Offset (0x%08x)\n",
  51349. + otg_dev->os_dep.reg_offset);
  51350. + }
  51351. + return count;
  51352. +}
  51353. +
  51354. +DEVICE_ATTR(regvalue, S_IRUGO | S_IWUSR, regvalue_show, regvalue_store);
  51355. +
  51356. +/*
  51357. + * Attributes
  51358. + */
  51359. +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(mode, "Mode");
  51360. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(hnpcapable, "HNPCapable");
  51361. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(srpcapable, "SRPCapable");
  51362. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(hsic_connect, "HSIC Connect");
  51363. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(inv_sel_hsic, "Invert Select HSIC");
  51364. +
  51365. +//DWC_OTG_DEVICE_ATTR_BITFIELD_RW(buspower,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");
  51366. +//DWC_OTG_DEVICE_ATTR_BITFIELD_RW(bussuspend,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");
  51367. +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(busconnected, "Bus Connected");
  51368. +
  51369. +DWC_OTG_DEVICE_ATTR_REG32_RW(gotgctl, 0, "GOTGCTL");
  51370. +DWC_OTG_DEVICE_ATTR_REG32_RW(gusbcfg,
  51371. + &(otg_dev->core_if->core_global_regs->gusbcfg),
  51372. + "GUSBCFG");
  51373. +DWC_OTG_DEVICE_ATTR_REG32_RW(grxfsiz,
  51374. + &(otg_dev->core_if->core_global_regs->grxfsiz),
  51375. + "GRXFSIZ");
  51376. +DWC_OTG_DEVICE_ATTR_REG32_RW(gnptxfsiz,
  51377. + &(otg_dev->core_if->core_global_regs->gnptxfsiz),
  51378. + "GNPTXFSIZ");
  51379. +DWC_OTG_DEVICE_ATTR_REG32_RW(gpvndctl,
  51380. + &(otg_dev->core_if->core_global_regs->gpvndctl),
  51381. + "GPVNDCTL");
  51382. +DWC_OTG_DEVICE_ATTR_REG32_RW(ggpio,
  51383. + &(otg_dev->core_if->core_global_regs->ggpio),
  51384. + "GGPIO");
  51385. +DWC_OTG_DEVICE_ATTR_REG32_RW(guid, &(otg_dev->core_if->core_global_regs->guid),
  51386. + "GUID");
  51387. +DWC_OTG_DEVICE_ATTR_REG32_RO(gsnpsid,
  51388. + &(otg_dev->core_if->core_global_regs->gsnpsid),
  51389. + "GSNPSID");
  51390. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(devspeed, "Device Speed");
  51391. +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(enumspeed, "Device Enumeration Speed");
  51392. +
  51393. +DWC_OTG_DEVICE_ATTR_REG32_RO(hptxfsiz,
  51394. + &(otg_dev->core_if->core_global_regs->hptxfsiz),
  51395. + "HPTXFSIZ");
  51396. +DWC_OTG_DEVICE_ATTR_REG32_RW(hprt0, otg_dev->core_if->host_if->hprt0, "HPRT0");
  51397. +
  51398. +/**
  51399. + * @todo Add code to initiate the HNP.
  51400. + */
  51401. +/**
  51402. + * Show the HNP status bit
  51403. + */
  51404. +static ssize_t hnp_show(struct device *_dev,
  51405. + struct device_attribute *attr, char *buf)
  51406. +{
  51407. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  51408. + return sprintf(buf, "HstNegScs = 0x%x\n",
  51409. + dwc_otg_get_hnpstatus(otg_dev->core_if));
  51410. +}
  51411. +
  51412. +/**
  51413. + * Set the HNP Request bit
  51414. + */
  51415. +static ssize_t hnp_store(struct device *_dev,
  51416. + struct device_attribute *attr,
  51417. + const char *buf, size_t count)
  51418. +{
  51419. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  51420. + uint32_t in = simple_strtoul(buf, NULL, 16);
  51421. + dwc_otg_set_hnpreq(otg_dev->core_if, in);
  51422. + return count;
  51423. +}
  51424. +
  51425. +DEVICE_ATTR(hnp, 0644, hnp_show, hnp_store);
  51426. +
  51427. +/**
  51428. + * @todo Add code to initiate the SRP.
  51429. + */
  51430. +/**
  51431. + * Show the SRP status bit
  51432. + */
  51433. +static ssize_t srp_show(struct device *_dev,
  51434. + struct device_attribute *attr, char *buf)
  51435. +{
  51436. +#ifndef DWC_HOST_ONLY
  51437. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  51438. + return sprintf(buf, "SesReqScs = 0x%x\n",
  51439. + dwc_otg_get_srpstatus(otg_dev->core_if));
  51440. +#else
  51441. + return sprintf(buf, "Host Only Mode!\n");
  51442. +#endif
  51443. +}
  51444. +
  51445. +/**
  51446. + * Set the SRP Request bit
  51447. + */
  51448. +static ssize_t srp_store(struct device *_dev,
  51449. + struct device_attribute *attr,
  51450. + const char *buf, size_t count)
  51451. +{
  51452. +#ifndef DWC_HOST_ONLY
  51453. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  51454. + dwc_otg_pcd_initiate_srp(otg_dev->pcd);
  51455. +#endif
  51456. + return count;
  51457. +}
  51458. +
  51459. +DEVICE_ATTR(srp, 0644, srp_show, srp_store);
  51460. +
  51461. +/**
  51462. + * @todo Need to do more for power on/off?
  51463. + */
  51464. +/**
  51465. + * Show the Bus Power status
  51466. + */
  51467. +static ssize_t buspower_show(struct device *_dev,
  51468. + struct device_attribute *attr, char *buf)
  51469. +{
  51470. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  51471. + return sprintf(buf, "Bus Power = 0x%x\n",
  51472. + dwc_otg_get_prtpower(otg_dev->core_if));
  51473. +}
  51474. +
  51475. +/**
  51476. + * Set the Bus Power status
  51477. + */
  51478. +static ssize_t buspower_store(struct device *_dev,
  51479. + struct device_attribute *attr,
  51480. + const char *buf, size_t count)
  51481. +{
  51482. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  51483. + uint32_t on = simple_strtoul(buf, NULL, 16);
  51484. + dwc_otg_set_prtpower(otg_dev->core_if, on);
  51485. + return count;
  51486. +}
  51487. +
  51488. +DEVICE_ATTR(buspower, 0644, buspower_show, buspower_store);
  51489. +
  51490. +/**
  51491. + * @todo Need to do more for suspend?
  51492. + */
  51493. +/**
  51494. + * Show the Bus Suspend status
  51495. + */
  51496. +static ssize_t bussuspend_show(struct device *_dev,
  51497. + struct device_attribute *attr, char *buf)
  51498. +{
  51499. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  51500. + return sprintf(buf, "Bus Suspend = 0x%x\n",
  51501. + dwc_otg_get_prtsuspend(otg_dev->core_if));
  51502. +}
  51503. +
  51504. +/**
  51505. + * Set the Bus Suspend status
  51506. + */
  51507. +static ssize_t bussuspend_store(struct device *_dev,
  51508. + struct device_attribute *attr,
  51509. + const char *buf, size_t count)
  51510. +{
  51511. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  51512. + uint32_t in = simple_strtoul(buf, NULL, 16);
  51513. + dwc_otg_set_prtsuspend(otg_dev->core_if, in);
  51514. + return count;
  51515. +}
  51516. +
  51517. +DEVICE_ATTR(bussuspend, 0644, bussuspend_show, bussuspend_store);
  51518. +
  51519. +/**
  51520. + * Show the Mode Change Ready Timer status
  51521. + */
  51522. +static ssize_t mode_ch_tim_en_show(struct device *_dev,
  51523. + struct device_attribute *attr, char *buf)
  51524. +{
  51525. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  51526. + return sprintf(buf, "Mode Change Ready Timer Enable = 0x%x\n",
  51527. + dwc_otg_get_mode_ch_tim(otg_dev->core_if));
  51528. +}
  51529. +
  51530. +/**
  51531. + * Set the Mode Change Ready Timer status
  51532. + */
  51533. +static ssize_t mode_ch_tim_en_store(struct device *_dev,
  51534. + struct device_attribute *attr,
  51535. + const char *buf, size_t count)
  51536. +{
  51537. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  51538. + uint32_t in = simple_strtoul(buf, NULL, 16);
  51539. + dwc_otg_set_mode_ch_tim(otg_dev->core_if, in);
  51540. + return count;
  51541. +}
  51542. +
  51543. +DEVICE_ATTR(mode_ch_tim_en, 0644, mode_ch_tim_en_show, mode_ch_tim_en_store);
  51544. +
  51545. +/**
  51546. + * Show the value of HFIR Frame Interval bitfield
  51547. + */
  51548. +static ssize_t fr_interval_show(struct device *_dev,
  51549. + struct device_attribute *attr, char *buf)
  51550. +{
  51551. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  51552. + return sprintf(buf, "Frame Interval = 0x%x\n",
  51553. + dwc_otg_get_fr_interval(otg_dev->core_if));
  51554. +}
  51555. +
  51556. +/**
  51557. + * Set the HFIR Frame Interval value
  51558. + */
  51559. +static ssize_t fr_interval_store(struct device *_dev,
  51560. + struct device_attribute *attr,
  51561. + const char *buf, size_t count)
  51562. +{
  51563. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  51564. + uint32_t in = simple_strtoul(buf, NULL, 10);
  51565. + dwc_otg_set_fr_interval(otg_dev->core_if, in);
  51566. + return count;
  51567. +}
  51568. +
  51569. +DEVICE_ATTR(fr_interval, 0644, fr_interval_show, fr_interval_store);
  51570. +
  51571. +/**
  51572. + * Show the status of Remote Wakeup.
  51573. + */
  51574. +static ssize_t remote_wakeup_show(struct device *_dev,
  51575. + struct device_attribute *attr, char *buf)
  51576. +{
  51577. +#ifndef DWC_HOST_ONLY
  51578. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  51579. +
  51580. + return sprintf(buf,
  51581. + "Remote Wakeup Sig = %d Enabled = %d LPM Remote Wakeup = %d\n",
  51582. + dwc_otg_get_remotewakesig(otg_dev->core_if),
  51583. + dwc_otg_pcd_get_rmwkup_enable(otg_dev->pcd),
  51584. + dwc_otg_get_lpm_remotewakeenabled(otg_dev->core_if));
  51585. +#else
  51586. + return sprintf(buf, "Host Only Mode!\n");
  51587. +#endif /* DWC_HOST_ONLY */
  51588. +}
  51589. +
  51590. +/**
  51591. + * Initiate a remote wakeup of the host. The Device control register
  51592. + * Remote Wakeup Signal bit is written if the PCD Remote wakeup enable
  51593. + * flag is set.
  51594. + *
  51595. + */
  51596. +static ssize_t remote_wakeup_store(struct device *_dev,
  51597. + struct device_attribute *attr,
  51598. + const char *buf, size_t count)
  51599. +{
  51600. +#ifndef DWC_HOST_ONLY
  51601. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  51602. + uint32_t val = simple_strtoul(buf, NULL, 16);
  51603. +
  51604. + if (val & 1) {
  51605. + dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 1);
  51606. + } else {
  51607. + dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 0);
  51608. + }
  51609. +#endif /* DWC_HOST_ONLY */
  51610. + return count;
  51611. +}
  51612. +
  51613. +DEVICE_ATTR(remote_wakeup, S_IRUGO | S_IWUSR, remote_wakeup_show,
  51614. + remote_wakeup_store);
  51615. +
  51616. +/**
  51617. + * Show the whether core is hibernated or not.
  51618. + */
  51619. +static ssize_t rem_wakeup_pwrdn_show(struct device *_dev,
  51620. + struct device_attribute *attr, char *buf)
  51621. +{
  51622. +#ifndef DWC_HOST_ONLY
  51623. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  51624. +
  51625. + if (dwc_otg_get_core_state(otg_dev->core_if)) {
  51626. + DWC_PRINTF("Core is in hibernation\n");
  51627. + } else {
  51628. + DWC_PRINTF("Core is not in hibernation\n");
  51629. + }
  51630. +#endif /* DWC_HOST_ONLY */
  51631. + return 0;
  51632. +}
  51633. +
  51634. +extern int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
  51635. + int rem_wakeup, int reset);
  51636. +
  51637. +/**
  51638. + * Initiate a remote wakeup of the device to exit from hibernation.
  51639. + */
  51640. +static ssize_t rem_wakeup_pwrdn_store(struct device *_dev,
  51641. + struct device_attribute *attr,
  51642. + const char *buf, size_t count)
  51643. +{
  51644. +#ifndef DWC_HOST_ONLY
  51645. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  51646. + dwc_otg_device_hibernation_restore(otg_dev->core_if, 1, 0);
  51647. +#endif
  51648. + return count;
  51649. +}
  51650. +
  51651. +DEVICE_ATTR(rem_wakeup_pwrdn, S_IRUGO | S_IWUSR, rem_wakeup_pwrdn_show,
  51652. + rem_wakeup_pwrdn_store);
  51653. +
  51654. +static ssize_t disconnect_us(struct device *_dev,
  51655. + struct device_attribute *attr,
  51656. + const char *buf, size_t count)
  51657. +{
  51658. +
  51659. +#ifndef DWC_HOST_ONLY
  51660. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  51661. + uint32_t val = simple_strtoul(buf, NULL, 16);
  51662. + DWC_PRINTF("The Passed value is %04x\n", val);
  51663. +
  51664. + dwc_otg_pcd_disconnect_us(otg_dev->pcd, 50);
  51665. +
  51666. +#endif /* DWC_HOST_ONLY */
  51667. + return count;
  51668. +}
  51669. +
  51670. +DEVICE_ATTR(disconnect_us, S_IWUSR, 0, disconnect_us);
  51671. +
  51672. +/**
  51673. + * Dump global registers and either host or device registers (depending on the
  51674. + * current mode of the core).
  51675. + */
  51676. +static ssize_t regdump_show(struct device *_dev,
  51677. + struct device_attribute *attr, char *buf)
  51678. +{
  51679. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  51680. +
  51681. + dwc_otg_dump_global_registers(otg_dev->core_if);
  51682. + if (dwc_otg_is_host_mode(otg_dev->core_if)) {
  51683. + dwc_otg_dump_host_registers(otg_dev->core_if);
  51684. + } else {
  51685. + dwc_otg_dump_dev_registers(otg_dev->core_if);
  51686. +
  51687. + }
  51688. + return sprintf(buf, "Register Dump\n");
  51689. +}
  51690. +
  51691. +DEVICE_ATTR(regdump, S_IRUGO, regdump_show, 0);
  51692. +
  51693. +/**
  51694. + * Dump global registers and either host or device registers (depending on the
  51695. + * current mode of the core).
  51696. + */
  51697. +static ssize_t spramdump_show(struct device *_dev,
  51698. + struct device_attribute *attr, char *buf)
  51699. +{
  51700. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  51701. +
  51702. + //dwc_otg_dump_spram(otg_dev->core_if);
  51703. +
  51704. + return sprintf(buf, "SPRAM Dump\n");
  51705. +}
  51706. +
  51707. +DEVICE_ATTR(spramdump, S_IRUGO, spramdump_show, 0);
  51708. +
  51709. +/**
  51710. + * Dump the current hcd state.
  51711. + */
  51712. +static ssize_t hcddump_show(struct device *_dev,
  51713. + struct device_attribute *attr, char *buf)
  51714. +{
  51715. +#ifndef DWC_DEVICE_ONLY
  51716. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  51717. + dwc_otg_hcd_dump_state(otg_dev->hcd);
  51718. +#endif /* DWC_DEVICE_ONLY */
  51719. + return sprintf(buf, "HCD Dump\n");
  51720. +}
  51721. +
  51722. +DEVICE_ATTR(hcddump, S_IRUGO, hcddump_show, 0);
  51723. +
  51724. +/**
  51725. + * Dump the average frame remaining at SOF. This can be used to
  51726. + * determine average interrupt latency. Frame remaining is also shown for
  51727. + * start transfer and two additional sample points.
  51728. + */
  51729. +static ssize_t hcd_frrem_show(struct device *_dev,
  51730. + struct device_attribute *attr, char *buf)
  51731. +{
  51732. +#ifndef DWC_DEVICE_ONLY
  51733. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  51734. +
  51735. + dwc_otg_hcd_dump_frrem(otg_dev->hcd);
  51736. +#endif /* DWC_DEVICE_ONLY */
  51737. + return sprintf(buf, "HCD Dump Frame Remaining\n");
  51738. +}
  51739. +
  51740. +DEVICE_ATTR(hcd_frrem, S_IRUGO, hcd_frrem_show, 0);
  51741. +
  51742. +/**
  51743. + * Displays the time required to read the GNPTXFSIZ register many times (the
  51744. + * output shows the number of times the register is read).
  51745. + */
  51746. +#define RW_REG_COUNT 10000000
  51747. +#define MSEC_PER_JIFFIE 1000/HZ
  51748. +static ssize_t rd_reg_test_show(struct device *_dev,
  51749. + struct device_attribute *attr, char *buf)
  51750. +{
  51751. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  51752. + int i;
  51753. + int time;
  51754. + int start_jiffies;
  51755. +
  51756. + printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
  51757. + HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
  51758. + start_jiffies = jiffies;
  51759. + for (i = 0; i < RW_REG_COUNT; i++) {
  51760. + dwc_otg_get_gnptxfsiz(otg_dev->core_if);
  51761. + }
  51762. + time = jiffies - start_jiffies;
  51763. + return sprintf(buf,
  51764. + "Time to read GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
  51765. + RW_REG_COUNT, time * MSEC_PER_JIFFIE, time);
  51766. +}
  51767. +
  51768. +DEVICE_ATTR(rd_reg_test, S_IRUGO, rd_reg_test_show, 0);
  51769. +
  51770. +/**
  51771. + * Displays the time required to write the GNPTXFSIZ register many times (the
  51772. + * output shows the number of times the register is written).
  51773. + */
  51774. +static ssize_t wr_reg_test_show(struct device *_dev,
  51775. + struct device_attribute *attr, char *buf)
  51776. +{
  51777. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  51778. + uint32_t reg_val;
  51779. + int i;
  51780. + int time;
  51781. + int start_jiffies;
  51782. +
  51783. + printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
  51784. + HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
  51785. + reg_val = dwc_otg_get_gnptxfsiz(otg_dev->core_if);
  51786. + start_jiffies = jiffies;
  51787. + for (i = 0; i < RW_REG_COUNT; i++) {
  51788. + dwc_otg_set_gnptxfsiz(otg_dev->core_if, reg_val);
  51789. + }
  51790. + time = jiffies - start_jiffies;
  51791. + return sprintf(buf,
  51792. + "Time to write GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
  51793. + RW_REG_COUNT, time * MSEC_PER_JIFFIE, time);
  51794. +}
  51795. +
  51796. +DEVICE_ATTR(wr_reg_test, S_IRUGO, wr_reg_test_show, 0);
  51797. +
  51798. +#ifdef CONFIG_USB_DWC_OTG_LPM
  51799. +
  51800. +/**
  51801. +* Show the lpm_response attribute.
  51802. +*/
  51803. +static ssize_t lpmresp_show(struct device *_dev,
  51804. + struct device_attribute *attr, char *buf)
  51805. +{
  51806. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  51807. +
  51808. + if (!dwc_otg_get_param_lpm_enable(otg_dev->core_if))
  51809. + return sprintf(buf, "** LPM is DISABLED **\n");
  51810. +
  51811. + if (!dwc_otg_is_device_mode(otg_dev->core_if)) {
  51812. + return sprintf(buf, "** Current mode is not device mode\n");
  51813. + }
  51814. + return sprintf(buf, "lpm_response = %d\n",
  51815. + dwc_otg_get_lpmresponse(otg_dev->core_if));
  51816. +}
  51817. +
  51818. +/**
  51819. +* Store the lpm_response attribute.
  51820. +*/
  51821. +static ssize_t lpmresp_store(struct device *_dev,
  51822. + struct device_attribute *attr,
  51823. + const char *buf, size_t count)
  51824. +{
  51825. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  51826. + uint32_t val = simple_strtoul(buf, NULL, 16);
  51827. +
  51828. + if (!dwc_otg_get_param_lpm_enable(otg_dev->core_if)) {
  51829. + return 0;
  51830. + }
  51831. +
  51832. + if (!dwc_otg_is_device_mode(otg_dev->core_if)) {
  51833. + return 0;
  51834. + }
  51835. +
  51836. + dwc_otg_set_lpmresponse(otg_dev->core_if, val);
  51837. + return count;
  51838. +}
  51839. +
  51840. +DEVICE_ATTR(lpm_response, S_IRUGO | S_IWUSR, lpmresp_show, lpmresp_store);
  51841. +
  51842. +/**
  51843. +* Show the sleep_status attribute.
  51844. +*/
  51845. +static ssize_t sleepstatus_show(struct device *_dev,
  51846. + struct device_attribute *attr, char *buf)
  51847. +{
  51848. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  51849. + return sprintf(buf, "Sleep Status = %d\n",
  51850. + dwc_otg_get_lpm_portsleepstatus(otg_dev->core_if));
  51851. +}
  51852. +
  51853. +/**
  51854. + * Store the sleep_status attribure.
  51855. + */
  51856. +static ssize_t sleepstatus_store(struct device *_dev,
  51857. + struct device_attribute *attr,
  51858. + const char *buf, size_t count)
  51859. +{
  51860. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  51861. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  51862. +
  51863. + if (dwc_otg_get_lpm_portsleepstatus(otg_dev->core_if)) {
  51864. + if (dwc_otg_is_host_mode(core_if)) {
  51865. +
  51866. + DWC_PRINTF("Host initiated resume\n");
  51867. + dwc_otg_set_prtresume(otg_dev->core_if, 1);
  51868. + }
  51869. + }
  51870. +
  51871. + return count;
  51872. +}
  51873. +
  51874. +DEVICE_ATTR(sleep_status, S_IRUGO | S_IWUSR, sleepstatus_show,
  51875. + sleepstatus_store);
  51876. +
  51877. +#endif /* CONFIG_USB_DWC_OTG_LPM_ENABLE */
  51878. +
  51879. +/**@}*/
  51880. +
  51881. +/**
  51882. + * Create the device files
  51883. + */
  51884. +void dwc_otg_attr_create(
  51885. +#ifdef LM_INTERFACE
  51886. + struct lm_device *dev
  51887. +#elif defined(PCI_INTERFACE)
  51888. + struct pci_dev *dev
  51889. +#elif defined(PLATFORM_INTERFACE)
  51890. + struct platform_device *dev
  51891. +#endif
  51892. + )
  51893. +{
  51894. + int error;
  51895. +
  51896. + error = device_create_file(&dev->dev, &dev_attr_regoffset);
  51897. + error = device_create_file(&dev->dev, &dev_attr_regvalue);
  51898. + error = device_create_file(&dev->dev, &dev_attr_mode);
  51899. + error = device_create_file(&dev->dev, &dev_attr_hnpcapable);
  51900. + error = device_create_file(&dev->dev, &dev_attr_srpcapable);
  51901. + error = device_create_file(&dev->dev, &dev_attr_hsic_connect);
  51902. + error = device_create_file(&dev->dev, &dev_attr_inv_sel_hsic);
  51903. + error = device_create_file(&dev->dev, &dev_attr_hnp);
  51904. + error = device_create_file(&dev->dev, &dev_attr_srp);
  51905. + error = device_create_file(&dev->dev, &dev_attr_buspower);
  51906. + error = device_create_file(&dev->dev, &dev_attr_bussuspend);
  51907. + error = device_create_file(&dev->dev, &dev_attr_mode_ch_tim_en);
  51908. + error = device_create_file(&dev->dev, &dev_attr_fr_interval);
  51909. + error = device_create_file(&dev->dev, &dev_attr_busconnected);
  51910. + error = device_create_file(&dev->dev, &dev_attr_gotgctl);
  51911. + error = device_create_file(&dev->dev, &dev_attr_gusbcfg);
  51912. + error = device_create_file(&dev->dev, &dev_attr_grxfsiz);
  51913. + error = device_create_file(&dev->dev, &dev_attr_gnptxfsiz);
  51914. + error = device_create_file(&dev->dev, &dev_attr_gpvndctl);
  51915. + error = device_create_file(&dev->dev, &dev_attr_ggpio);
  51916. + error = device_create_file(&dev->dev, &dev_attr_guid);
  51917. + error = device_create_file(&dev->dev, &dev_attr_gsnpsid);
  51918. + error = device_create_file(&dev->dev, &dev_attr_devspeed);
  51919. + error = device_create_file(&dev->dev, &dev_attr_enumspeed);
  51920. + error = device_create_file(&dev->dev, &dev_attr_hptxfsiz);
  51921. + error = device_create_file(&dev->dev, &dev_attr_hprt0);
  51922. + error = device_create_file(&dev->dev, &dev_attr_remote_wakeup);
  51923. + error = device_create_file(&dev->dev, &dev_attr_rem_wakeup_pwrdn);
  51924. + error = device_create_file(&dev->dev, &dev_attr_disconnect_us);
  51925. + error = device_create_file(&dev->dev, &dev_attr_regdump);
  51926. + error = device_create_file(&dev->dev, &dev_attr_spramdump);
  51927. + error = device_create_file(&dev->dev, &dev_attr_hcddump);
  51928. + error = device_create_file(&dev->dev, &dev_attr_hcd_frrem);
  51929. + error = device_create_file(&dev->dev, &dev_attr_rd_reg_test);
  51930. + error = device_create_file(&dev->dev, &dev_attr_wr_reg_test);
  51931. +#ifdef CONFIG_USB_DWC_OTG_LPM
  51932. + error = device_create_file(&dev->dev, &dev_attr_lpm_response);
  51933. + error = device_create_file(&dev->dev, &dev_attr_sleep_status);
  51934. +#endif
  51935. +}
  51936. +
  51937. +/**
  51938. + * Remove the device files
  51939. + */
  51940. +void dwc_otg_attr_remove(
  51941. +#ifdef LM_INTERFACE
  51942. + struct lm_device *dev
  51943. +#elif defined(PCI_INTERFACE)
  51944. + struct pci_dev *dev
  51945. +#elif defined(PLATFORM_INTERFACE)
  51946. + struct platform_device *dev
  51947. +#endif
  51948. + )
  51949. +{
  51950. + device_remove_file(&dev->dev, &dev_attr_regoffset);
  51951. + device_remove_file(&dev->dev, &dev_attr_regvalue);
  51952. + device_remove_file(&dev->dev, &dev_attr_mode);
  51953. + device_remove_file(&dev->dev, &dev_attr_hnpcapable);
  51954. + device_remove_file(&dev->dev, &dev_attr_srpcapable);
  51955. + device_remove_file(&dev->dev, &dev_attr_hsic_connect);
  51956. + device_remove_file(&dev->dev, &dev_attr_inv_sel_hsic);
  51957. + device_remove_file(&dev->dev, &dev_attr_hnp);
  51958. + device_remove_file(&dev->dev, &dev_attr_srp);
  51959. + device_remove_file(&dev->dev, &dev_attr_buspower);
  51960. + device_remove_file(&dev->dev, &dev_attr_bussuspend);
  51961. + device_remove_file(&dev->dev, &dev_attr_mode_ch_tim_en);
  51962. + device_remove_file(&dev->dev, &dev_attr_fr_interval);
  51963. + device_remove_file(&dev->dev, &dev_attr_busconnected);
  51964. + device_remove_file(&dev->dev, &dev_attr_gotgctl);
  51965. + device_remove_file(&dev->dev, &dev_attr_gusbcfg);
  51966. + device_remove_file(&dev->dev, &dev_attr_grxfsiz);
  51967. + device_remove_file(&dev->dev, &dev_attr_gnptxfsiz);
  51968. + device_remove_file(&dev->dev, &dev_attr_gpvndctl);
  51969. + device_remove_file(&dev->dev, &dev_attr_ggpio);
  51970. + device_remove_file(&dev->dev, &dev_attr_guid);
  51971. + device_remove_file(&dev->dev, &dev_attr_gsnpsid);
  51972. + device_remove_file(&dev->dev, &dev_attr_devspeed);
  51973. + device_remove_file(&dev->dev, &dev_attr_enumspeed);
  51974. + device_remove_file(&dev->dev, &dev_attr_hptxfsiz);
  51975. + device_remove_file(&dev->dev, &dev_attr_hprt0);
  51976. + device_remove_file(&dev->dev, &dev_attr_remote_wakeup);
  51977. + device_remove_file(&dev->dev, &dev_attr_rem_wakeup_pwrdn);
  51978. + device_remove_file(&dev->dev, &dev_attr_disconnect_us);
  51979. + device_remove_file(&dev->dev, &dev_attr_regdump);
  51980. + device_remove_file(&dev->dev, &dev_attr_spramdump);
  51981. + device_remove_file(&dev->dev, &dev_attr_hcddump);
  51982. + device_remove_file(&dev->dev, &dev_attr_hcd_frrem);
  51983. + device_remove_file(&dev->dev, &dev_attr_rd_reg_test);
  51984. + device_remove_file(&dev->dev, &dev_attr_wr_reg_test);
  51985. +#ifdef CONFIG_USB_DWC_OTG_LPM
  51986. + device_remove_file(&dev->dev, &dev_attr_lpm_response);
  51987. + device_remove_file(&dev->dev, &dev_attr_sleep_status);
  51988. +#endif
  51989. +}
  51990. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_attr.h linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_attr.h
  51991. --- linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_attr.h 1970-01-01 01:00:00.000000000 +0100
  51992. +++ linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_attr.h 2014-02-17 22:41:01.000000000 +0100
  51993. @@ -0,0 +1,89 @@
  51994. +/* ==========================================================================
  51995. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_attr.h $
  51996. + * $Revision: #13 $
  51997. + * $Date: 2010/06/21 $
  51998. + * $Change: 1532021 $
  51999. + *
  52000. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  52001. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  52002. + * otherwise expressly agreed to in writing between Synopsys and you.
  52003. + *
  52004. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  52005. + * any End User Software License Agreement or Agreement for Licensed Product
  52006. + * with Synopsys or any supplement thereto. You are permitted to use and
  52007. + * redistribute this Software in source and binary forms, with or without
  52008. + * modification, provided that redistributions of source code must retain this
  52009. + * notice. You may not view, use, disclose, copy or distribute this file or
  52010. + * any information contained herein except pursuant to this license grant from
  52011. + * Synopsys. If you do not agree with this notice, including the disclaimer
  52012. + * below, then you are not authorized to use the Software.
  52013. + *
  52014. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  52015. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  52016. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  52017. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  52018. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  52019. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  52020. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  52021. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  52022. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  52023. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  52024. + * DAMAGE.
  52025. + * ========================================================================== */
  52026. +
  52027. +#if !defined(__DWC_OTG_ATTR_H__)
  52028. +#define __DWC_OTG_ATTR_H__
  52029. +
  52030. +/** @file
  52031. + * This file contains the interface to the Linux device attributes.
  52032. + */
  52033. +extern struct device_attribute dev_attr_regoffset;
  52034. +extern struct device_attribute dev_attr_regvalue;
  52035. +
  52036. +extern struct device_attribute dev_attr_mode;
  52037. +extern struct device_attribute dev_attr_hnpcapable;
  52038. +extern struct device_attribute dev_attr_srpcapable;
  52039. +extern struct device_attribute dev_attr_hnp;
  52040. +extern struct device_attribute dev_attr_srp;
  52041. +extern struct device_attribute dev_attr_buspower;
  52042. +extern struct device_attribute dev_attr_bussuspend;
  52043. +extern struct device_attribute dev_attr_mode_ch_tim_en;
  52044. +extern struct device_attribute dev_attr_fr_interval;
  52045. +extern struct device_attribute dev_attr_busconnected;
  52046. +extern struct device_attribute dev_attr_gotgctl;
  52047. +extern struct device_attribute dev_attr_gusbcfg;
  52048. +extern struct device_attribute dev_attr_grxfsiz;
  52049. +extern struct device_attribute dev_attr_gnptxfsiz;
  52050. +extern struct device_attribute dev_attr_gpvndctl;
  52051. +extern struct device_attribute dev_attr_ggpio;
  52052. +extern struct device_attribute dev_attr_guid;
  52053. +extern struct device_attribute dev_attr_gsnpsid;
  52054. +extern struct device_attribute dev_attr_devspeed;
  52055. +extern struct device_attribute dev_attr_enumspeed;
  52056. +extern struct device_attribute dev_attr_hptxfsiz;
  52057. +extern struct device_attribute dev_attr_hprt0;
  52058. +#ifdef CONFIG_USB_DWC_OTG_LPM
  52059. +extern struct device_attribute dev_attr_lpm_response;
  52060. +extern struct device_attribute devi_attr_sleep_status;
  52061. +#endif
  52062. +
  52063. +void dwc_otg_attr_create(
  52064. +#ifdef LM_INTERFACE
  52065. + struct lm_device *dev
  52066. +#elif defined(PCI_INTERFACE)
  52067. + struct pci_dev *dev
  52068. +#elif defined(PLATFORM_INTERFACE)
  52069. + struct platform_device *dev
  52070. +#endif
  52071. + );
  52072. +
  52073. +void dwc_otg_attr_remove(
  52074. +#ifdef LM_INTERFACE
  52075. + struct lm_device *dev
  52076. +#elif defined(PCI_INTERFACE)
  52077. + struct pci_dev *dev
  52078. +#elif defined(PLATFORM_INTERFACE)
  52079. + struct platform_device *dev
  52080. +#endif
  52081. + );
  52082. +#endif
  52083. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_cfi.c linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_cfi.c
  52084. --- linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_cfi.c 1970-01-01 01:00:00.000000000 +0100
  52085. +++ linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_cfi.c 2014-02-17 22:41:01.000000000 +0100
  52086. @@ -0,0 +1,1876 @@
  52087. +/* ==========================================================================
  52088. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  52089. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  52090. + * otherwise expressly agreed to in writing between Synopsys and you.
  52091. + *
  52092. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  52093. + * any End User Software License Agreement or Agreement for Licensed Product
  52094. + * with Synopsys or any supplement thereto. You are permitted to use and
  52095. + * redistribute this Software in source and binary forms, with or without
  52096. + * modification, provided that redistributions of source code must retain this
  52097. + * notice. You may not view, use, disclose, copy or distribute this file or
  52098. + * any information contained herein except pursuant to this license grant from
  52099. + * Synopsys. If you do not agree with this notice, including the disclaimer
  52100. + * below, then you are not authorized to use the Software.
  52101. + *
  52102. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  52103. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  52104. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  52105. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  52106. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  52107. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  52108. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  52109. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  52110. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  52111. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  52112. + * DAMAGE.
  52113. + * ========================================================================== */
  52114. +
  52115. +/** @file
  52116. + *
  52117. + * This file contains the most of the CFI(Core Feature Interface)
  52118. + * implementation for the OTG.
  52119. + */
  52120. +
  52121. +#ifdef DWC_UTE_CFI
  52122. +
  52123. +#include "dwc_otg_pcd.h"
  52124. +#include "dwc_otg_cfi.h"
  52125. +
  52126. +/** This definition should actually migrate to the Portability Library */
  52127. +#define DWC_CONSTANT_CPU_TO_LE16(x) (x)
  52128. +
  52129. +extern dwc_otg_pcd_ep_t *get_ep_by_addr(dwc_otg_pcd_t * pcd, u16 wIndex);
  52130. +
  52131. +static int cfi_core_features_buf(uint8_t * buf, uint16_t buflen);
  52132. +static int cfi_get_feature_value(uint8_t * buf, uint16_t buflen,
  52133. + struct dwc_otg_pcd *pcd,
  52134. + struct cfi_usb_ctrlrequest *ctrl_req);
  52135. +static int cfi_set_feature_value(struct dwc_otg_pcd *pcd);
  52136. +static int cfi_ep_get_sg_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  52137. + struct cfi_usb_ctrlrequest *req);
  52138. +static int cfi_ep_get_concat_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  52139. + struct cfi_usb_ctrlrequest *req);
  52140. +static int cfi_ep_get_align_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  52141. + struct cfi_usb_ctrlrequest *req);
  52142. +static int cfi_preproc_reset(struct dwc_otg_pcd *pcd,
  52143. + struct cfi_usb_ctrlrequest *req);
  52144. +static void cfi_free_ep_bs_dyn_data(cfi_ep_t * cfiep);
  52145. +
  52146. +static uint16_t get_dfifo_size(dwc_otg_core_if_t * core_if);
  52147. +static int32_t get_rxfifo_size(dwc_otg_core_if_t * core_if, uint16_t wValue);
  52148. +static int32_t get_txfifo_size(struct dwc_otg_pcd *pcd, uint16_t wValue);
  52149. +
  52150. +static uint8_t resize_fifos(dwc_otg_core_if_t * core_if);
  52151. +
  52152. +/** This is the header of the all features descriptor */
  52153. +static cfi_all_features_header_t all_props_desc_header = {
  52154. + .wVersion = DWC_CONSTANT_CPU_TO_LE16(0x100),
  52155. + .wCoreID = DWC_CONSTANT_CPU_TO_LE16(CFI_CORE_ID_OTG),
  52156. + .wNumFeatures = DWC_CONSTANT_CPU_TO_LE16(9),
  52157. +};
  52158. +
  52159. +/** This is an array of statically allocated feature descriptors */
  52160. +static cfi_feature_desc_header_t prop_descs[] = {
  52161. +
  52162. + /* FT_ID_DMA_MODE */
  52163. + {
  52164. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_MODE),
  52165. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  52166. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(1),
  52167. + },
  52168. +
  52169. + /* FT_ID_DMA_BUFFER_SETUP */
  52170. + {
  52171. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_BUFFER_SETUP),
  52172. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  52173. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  52174. + },
  52175. +
  52176. + /* FT_ID_DMA_BUFF_ALIGN */
  52177. + {
  52178. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_BUFF_ALIGN),
  52179. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  52180. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  52181. + },
  52182. +
  52183. + /* FT_ID_DMA_CONCAT_SETUP */
  52184. + {
  52185. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_CONCAT_SETUP),
  52186. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  52187. + //.wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  52188. + },
  52189. +
  52190. + /* FT_ID_DMA_CIRCULAR */
  52191. + {
  52192. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_CIRCULAR),
  52193. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  52194. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  52195. + },
  52196. +
  52197. + /* FT_ID_THRESHOLD_SETUP */
  52198. + {
  52199. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_THRESHOLD_SETUP),
  52200. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  52201. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  52202. + },
  52203. +
  52204. + /* FT_ID_DFIFO_DEPTH */
  52205. + {
  52206. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DFIFO_DEPTH),
  52207. + .bmAttributes = CFI_FEATURE_ATTR_RO,
  52208. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  52209. + },
  52210. +
  52211. + /* FT_ID_TX_FIFO_DEPTH */
  52212. + {
  52213. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_TX_FIFO_DEPTH),
  52214. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  52215. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  52216. + },
  52217. +
  52218. + /* FT_ID_RX_FIFO_DEPTH */
  52219. + {
  52220. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_RX_FIFO_DEPTH),
  52221. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  52222. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  52223. + }
  52224. +};
  52225. +
  52226. +/** The table of feature names */
  52227. +cfi_string_t prop_name_table[] = {
  52228. + {FT_ID_DMA_MODE, "dma_mode"},
  52229. + {FT_ID_DMA_BUFFER_SETUP, "buffer_setup"},
  52230. + {FT_ID_DMA_BUFF_ALIGN, "buffer_align"},
  52231. + {FT_ID_DMA_CONCAT_SETUP, "concat_setup"},
  52232. + {FT_ID_DMA_CIRCULAR, "buffer_circular"},
  52233. + {FT_ID_THRESHOLD_SETUP, "threshold_setup"},
  52234. + {FT_ID_DFIFO_DEPTH, "dfifo_depth"},
  52235. + {FT_ID_TX_FIFO_DEPTH, "txfifo_depth"},
  52236. + {FT_ID_RX_FIFO_DEPTH, "rxfifo_depth"},
  52237. + {}
  52238. +};
  52239. +
  52240. +/************************************************************************/
  52241. +
  52242. +/**
  52243. + * Returns the name of the feature by its ID
  52244. + * or NULL if no featute ID matches.
  52245. + *
  52246. + */
  52247. +const uint8_t *get_prop_name(uint16_t prop_id, int *len)
  52248. +{
  52249. + cfi_string_t *pstr;
  52250. + *len = 0;
  52251. +
  52252. + for (pstr = prop_name_table; pstr && pstr->s; pstr++) {
  52253. + if (pstr->id == prop_id) {
  52254. + *len = DWC_STRLEN(pstr->s);
  52255. + return pstr->s;
  52256. + }
  52257. + }
  52258. + return NULL;
  52259. +}
  52260. +
  52261. +/**
  52262. + * This function handles all CFI specific control requests.
  52263. + *
  52264. + * Return a negative value to stall the DCE.
  52265. + */
  52266. +int cfi_setup(struct dwc_otg_pcd *pcd, struct cfi_usb_ctrlrequest *ctrl)
  52267. +{
  52268. + int retval = 0;
  52269. + dwc_otg_pcd_ep_t *ep = NULL;
  52270. + cfiobject_t *cfi = pcd->cfi;
  52271. + struct dwc_otg_core_if *coreif = GET_CORE_IF(pcd);
  52272. + uint16_t wLen = DWC_LE16_TO_CPU(&ctrl->wLength);
  52273. + uint16_t wValue = DWC_LE16_TO_CPU(&ctrl->wValue);
  52274. + uint16_t wIndex = DWC_LE16_TO_CPU(&ctrl->wIndex);
  52275. + uint32_t regaddr = 0;
  52276. + uint32_t regval = 0;
  52277. +
  52278. + /* Save this Control Request in the CFI object.
  52279. + * The data field will be assigned in the data stage completion CB function.
  52280. + */
  52281. + cfi->ctrl_req = *ctrl;
  52282. + cfi->ctrl_req.data = NULL;
  52283. +
  52284. + cfi->need_gadget_att = 0;
  52285. + cfi->need_status_in_complete = 0;
  52286. +
  52287. + switch (ctrl->bRequest) {
  52288. + case VEN_CORE_GET_FEATURES:
  52289. + retval = cfi_core_features_buf(cfi->buf_in.buf, CFI_IN_BUF_LEN);
  52290. + if (retval >= 0) {
  52291. + //dump_msg(cfi->buf_in.buf, retval);
  52292. + ep = &pcd->ep0;
  52293. +
  52294. + retval = min((uint16_t) retval, wLen);
  52295. + /* Transfer this buffer to the host through the EP0-IN EP */
  52296. + ep->dwc_ep.dma_addr = cfi->buf_in.addr;
  52297. + ep->dwc_ep.start_xfer_buff = cfi->buf_in.buf;
  52298. + ep->dwc_ep.xfer_buff = cfi->buf_in.buf;
  52299. + ep->dwc_ep.xfer_len = retval;
  52300. + ep->dwc_ep.xfer_count = 0;
  52301. + ep->dwc_ep.sent_zlp = 0;
  52302. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  52303. +
  52304. + pcd->ep0_pending = 1;
  52305. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  52306. + }
  52307. + retval = 0;
  52308. + break;
  52309. +
  52310. + case VEN_CORE_GET_FEATURE:
  52311. + CFI_INFO("VEN_CORE_GET_FEATURE\n");
  52312. + retval = cfi_get_feature_value(cfi->buf_in.buf, CFI_IN_BUF_LEN,
  52313. + pcd, ctrl);
  52314. + if (retval >= 0) {
  52315. + ep = &pcd->ep0;
  52316. +
  52317. + retval = min((uint16_t) retval, wLen);
  52318. + /* Transfer this buffer to the host through the EP0-IN EP */
  52319. + ep->dwc_ep.dma_addr = cfi->buf_in.addr;
  52320. + ep->dwc_ep.start_xfer_buff = cfi->buf_in.buf;
  52321. + ep->dwc_ep.xfer_buff = cfi->buf_in.buf;
  52322. + ep->dwc_ep.xfer_len = retval;
  52323. + ep->dwc_ep.xfer_count = 0;
  52324. + ep->dwc_ep.sent_zlp = 0;
  52325. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  52326. +
  52327. + pcd->ep0_pending = 1;
  52328. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  52329. + }
  52330. + CFI_INFO("VEN_CORE_GET_FEATURE=%d\n", retval);
  52331. + dump_msg(cfi->buf_in.buf, retval);
  52332. + break;
  52333. +
  52334. + case VEN_CORE_SET_FEATURE:
  52335. + CFI_INFO("VEN_CORE_SET_FEATURE\n");
  52336. + /* Set up an XFER to get the data stage of the control request,
  52337. + * which is the new value of the feature to be modified.
  52338. + */
  52339. + ep = &pcd->ep0;
  52340. + ep->dwc_ep.is_in = 0;
  52341. + ep->dwc_ep.dma_addr = cfi->buf_out.addr;
  52342. + ep->dwc_ep.start_xfer_buff = cfi->buf_out.buf;
  52343. + ep->dwc_ep.xfer_buff = cfi->buf_out.buf;
  52344. + ep->dwc_ep.xfer_len = wLen;
  52345. + ep->dwc_ep.xfer_count = 0;
  52346. + ep->dwc_ep.sent_zlp = 0;
  52347. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  52348. +
  52349. + pcd->ep0_pending = 1;
  52350. + /* Read the control write's data stage */
  52351. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  52352. + retval = 0;
  52353. + break;
  52354. +
  52355. + case VEN_CORE_RESET_FEATURES:
  52356. + CFI_INFO("VEN_CORE_RESET_FEATURES\n");
  52357. + cfi->need_gadget_att = 1;
  52358. + cfi->need_status_in_complete = 1;
  52359. + retval = cfi_preproc_reset(pcd, ctrl);
  52360. + CFI_INFO("VEN_CORE_RESET_FEATURES = (%d)\n", retval);
  52361. + break;
  52362. +
  52363. + case VEN_CORE_ACTIVATE_FEATURES:
  52364. + CFI_INFO("VEN_CORE_ACTIVATE_FEATURES\n");
  52365. + break;
  52366. +
  52367. + case VEN_CORE_READ_REGISTER:
  52368. + CFI_INFO("VEN_CORE_READ_REGISTER\n");
  52369. + /* wValue optionally contains the HI WORD of the register offset and
  52370. + * wIndex contains the LOW WORD of the register offset
  52371. + */
  52372. + if (wValue == 0) {
  52373. + /* @TODO - MAS - fix the access to the base field */
  52374. + regaddr = 0;
  52375. + //regaddr = (uint32_t) pcd->otg_dev->os_dep.base;
  52376. + //GET_CORE_IF(pcd)->co
  52377. + regaddr |= wIndex;
  52378. + } else {
  52379. + regaddr = (wValue << 16) | wIndex;
  52380. + }
  52381. +
  52382. + /* Read a 32-bit value of the memory at the regaddr */
  52383. + regval = DWC_READ_REG32((uint32_t *) regaddr);
  52384. +
  52385. + ep = &pcd->ep0;
  52386. + dwc_memcpy(cfi->buf_in.buf, &regval, sizeof(uint32_t));
  52387. + ep->dwc_ep.is_in = 1;
  52388. + ep->dwc_ep.dma_addr = cfi->buf_in.addr;
  52389. + ep->dwc_ep.start_xfer_buff = cfi->buf_in.buf;
  52390. + ep->dwc_ep.xfer_buff = cfi->buf_in.buf;
  52391. + ep->dwc_ep.xfer_len = wLen;
  52392. + ep->dwc_ep.xfer_count = 0;
  52393. + ep->dwc_ep.sent_zlp = 0;
  52394. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  52395. +
  52396. + pcd->ep0_pending = 1;
  52397. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  52398. + cfi->need_gadget_att = 0;
  52399. + retval = 0;
  52400. + break;
  52401. +
  52402. + case VEN_CORE_WRITE_REGISTER:
  52403. + CFI_INFO("VEN_CORE_WRITE_REGISTER\n");
  52404. + /* Set up an XFER to get the data stage of the control request,
  52405. + * which is the new value of the register to be modified.
  52406. + */
  52407. + ep = &pcd->ep0;
  52408. + ep->dwc_ep.is_in = 0;
  52409. + ep->dwc_ep.dma_addr = cfi->buf_out.addr;
  52410. + ep->dwc_ep.start_xfer_buff = cfi->buf_out.buf;
  52411. + ep->dwc_ep.xfer_buff = cfi->buf_out.buf;
  52412. + ep->dwc_ep.xfer_len = wLen;
  52413. + ep->dwc_ep.xfer_count = 0;
  52414. + ep->dwc_ep.sent_zlp = 0;
  52415. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  52416. +
  52417. + pcd->ep0_pending = 1;
  52418. + /* Read the control write's data stage */
  52419. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  52420. + retval = 0;
  52421. + break;
  52422. +
  52423. + default:
  52424. + retval = -DWC_E_NOT_SUPPORTED;
  52425. + break;
  52426. + }
  52427. +
  52428. + return retval;
  52429. +}
  52430. +
  52431. +/**
  52432. + * This function prepares the core features descriptors and copies its
  52433. + * raw representation into the buffer <buf>.
  52434. + *
  52435. + * The buffer structure is as follows:
  52436. + * all_features_header (8 bytes)
  52437. + * features_#1 (8 bytes + feature name string length)
  52438. + * features_#2 (8 bytes + feature name string length)
  52439. + * .....
  52440. + * features_#n - where n=the total count of feature descriptors
  52441. + */
  52442. +static int cfi_core_features_buf(uint8_t * buf, uint16_t buflen)
  52443. +{
  52444. + cfi_feature_desc_header_t *prop_hdr = prop_descs;
  52445. + cfi_feature_desc_header_t *prop;
  52446. + cfi_all_features_header_t *all_props_hdr = &all_props_desc_header;
  52447. + cfi_all_features_header_t *tmp;
  52448. + uint8_t *tmpbuf = buf;
  52449. + const uint8_t *pname = NULL;
  52450. + int i, j, namelen = 0, totlen;
  52451. +
  52452. + /* Prepare and copy the core features into the buffer */
  52453. + CFI_INFO("%s:\n", __func__);
  52454. +
  52455. + tmp = (cfi_all_features_header_t *) tmpbuf;
  52456. + *tmp = *all_props_hdr;
  52457. + tmpbuf += CFI_ALL_FEATURES_HDR_LEN;
  52458. +
  52459. + j = sizeof(prop_descs) / sizeof(cfi_all_features_header_t);
  52460. + for (i = 0; i < j; i++, prop_hdr++) {
  52461. + pname = get_prop_name(prop_hdr->wFeatureID, &namelen);
  52462. + prop = (cfi_feature_desc_header_t *) tmpbuf;
  52463. + *prop = *prop_hdr;
  52464. +
  52465. + prop->bNameLen = namelen;
  52466. + prop->wLength =
  52467. + DWC_CONSTANT_CPU_TO_LE16(CFI_FEATURE_DESC_HDR_LEN +
  52468. + namelen);
  52469. +
  52470. + tmpbuf += CFI_FEATURE_DESC_HDR_LEN;
  52471. + dwc_memcpy(tmpbuf, pname, namelen);
  52472. + tmpbuf += namelen;
  52473. + }
  52474. +
  52475. + totlen = tmpbuf - buf;
  52476. +
  52477. + if (totlen > 0) {
  52478. + tmp = (cfi_all_features_header_t *) buf;
  52479. + tmp->wTotalLen = DWC_CONSTANT_CPU_TO_LE16(totlen);
  52480. + }
  52481. +
  52482. + return totlen;
  52483. +}
  52484. +
  52485. +/**
  52486. + * This function releases all the dynamic memory in the CFI object.
  52487. + */
  52488. +static void cfi_release(cfiobject_t * cfiobj)
  52489. +{
  52490. + cfi_ep_t *cfiep;
  52491. + dwc_list_link_t *tmp;
  52492. +
  52493. + CFI_INFO("%s\n", __func__);
  52494. +
  52495. + if (cfiobj->buf_in.buf) {
  52496. + DWC_DMA_FREE(CFI_IN_BUF_LEN, cfiobj->buf_in.buf,
  52497. + cfiobj->buf_in.addr);
  52498. + cfiobj->buf_in.buf = NULL;
  52499. + }
  52500. +
  52501. + if (cfiobj->buf_out.buf) {
  52502. + DWC_DMA_FREE(CFI_OUT_BUF_LEN, cfiobj->buf_out.buf,
  52503. + cfiobj->buf_out.addr);
  52504. + cfiobj->buf_out.buf = NULL;
  52505. + }
  52506. +
  52507. + /* Free the Buffer Setup values for each EP */
  52508. + //list_for_each_entry(cfiep, &cfiobj->active_eps, lh) {
  52509. + DWC_LIST_FOREACH(tmp, &cfiobj->active_eps) {
  52510. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  52511. + cfi_free_ep_bs_dyn_data(cfiep);
  52512. + }
  52513. +}
  52514. +
  52515. +/**
  52516. + * This function frees the dynamically allocated EP buffer setup data.
  52517. + */
  52518. +static void cfi_free_ep_bs_dyn_data(cfi_ep_t * cfiep)
  52519. +{
  52520. + if (cfiep->bm_sg) {
  52521. + DWC_FREE(cfiep->bm_sg);
  52522. + cfiep->bm_sg = NULL;
  52523. + }
  52524. +
  52525. + if (cfiep->bm_align) {
  52526. + DWC_FREE(cfiep->bm_align);
  52527. + cfiep->bm_align = NULL;
  52528. + }
  52529. +
  52530. + if (cfiep->bm_concat) {
  52531. + if (NULL != cfiep->bm_concat->wTxBytes) {
  52532. + DWC_FREE(cfiep->bm_concat->wTxBytes);
  52533. + cfiep->bm_concat->wTxBytes = NULL;
  52534. + }
  52535. + DWC_FREE(cfiep->bm_concat);
  52536. + cfiep->bm_concat = NULL;
  52537. + }
  52538. +}
  52539. +
  52540. +/**
  52541. + * This function initializes the default values of the features
  52542. + * for a specific endpoint and should be called only once when
  52543. + * the EP is enabled first time.
  52544. + */
  52545. +static int cfi_ep_init_defaults(struct dwc_otg_pcd *pcd, cfi_ep_t * cfiep)
  52546. +{
  52547. + int retval = 0;
  52548. +
  52549. + cfiep->bm_sg = DWC_ALLOC(sizeof(ddma_sg_buffer_setup_t));
  52550. + if (NULL == cfiep->bm_sg) {
  52551. + CFI_INFO("Failed to allocate memory for SG feature value\n");
  52552. + return -DWC_E_NO_MEMORY;
  52553. + }
  52554. + dwc_memset(cfiep->bm_sg, 0, sizeof(ddma_sg_buffer_setup_t));
  52555. +
  52556. + /* For the Concatenation feature's default value we do not allocate
  52557. + * memory for the wTxBytes field - it will be done in the set_feature_value
  52558. + * request handler.
  52559. + */
  52560. + cfiep->bm_concat = DWC_ALLOC(sizeof(ddma_concat_buffer_setup_t));
  52561. + if (NULL == cfiep->bm_concat) {
  52562. + CFI_INFO
  52563. + ("Failed to allocate memory for CONCATENATION feature value\n");
  52564. + DWC_FREE(cfiep->bm_sg);
  52565. + return -DWC_E_NO_MEMORY;
  52566. + }
  52567. + dwc_memset(cfiep->bm_concat, 0, sizeof(ddma_concat_buffer_setup_t));
  52568. +
  52569. + cfiep->bm_align = DWC_ALLOC(sizeof(ddma_align_buffer_setup_t));
  52570. + if (NULL == cfiep->bm_align) {
  52571. + CFI_INFO
  52572. + ("Failed to allocate memory for Alignment feature value\n");
  52573. + DWC_FREE(cfiep->bm_sg);
  52574. + DWC_FREE(cfiep->bm_concat);
  52575. + return -DWC_E_NO_MEMORY;
  52576. + }
  52577. + dwc_memset(cfiep->bm_align, 0, sizeof(ddma_align_buffer_setup_t));
  52578. +
  52579. + return retval;
  52580. +}
  52581. +
  52582. +/**
  52583. + * The callback function that notifies the CFI on the activation of
  52584. + * an endpoint in the PCD. The following steps are done in this function:
  52585. + *
  52586. + * Create a dynamically allocated cfi_ep_t object (a CFI wrapper to the PCD's
  52587. + * active endpoint)
  52588. + * Create MAX_DMA_DESCS_PER_EP count DMA Descriptors for the EP
  52589. + * Set the Buffer Mode to standard
  52590. + * Initialize the default values for all EP modes (SG, Circular, Concat, Align)
  52591. + * Add the cfi_ep_t object to the list of active endpoints in the CFI object
  52592. + */
  52593. +static int cfi_ep_enable(struct cfiobject *cfi, struct dwc_otg_pcd *pcd,
  52594. + struct dwc_otg_pcd_ep *ep)
  52595. +{
  52596. + cfi_ep_t *cfiep;
  52597. + int retval = -DWC_E_NOT_SUPPORTED;
  52598. +
  52599. + CFI_INFO("%s: epname=%s; epnum=0x%02x\n", __func__,
  52600. + "EP_" /*ep->ep.name */ , ep->desc->bEndpointAddress);
  52601. + /* MAS - Check whether this endpoint already is in the list */
  52602. + cfiep = get_cfi_ep_by_pcd_ep(cfi, ep);
  52603. +
  52604. + if (NULL == cfiep) {
  52605. + /* Allocate a cfi_ep_t object */
  52606. + cfiep = DWC_ALLOC(sizeof(cfi_ep_t));
  52607. + if (NULL == cfiep) {
  52608. + CFI_INFO
  52609. + ("Unable to allocate memory for <cfiep> in function %s\n",
  52610. + __func__);
  52611. + return -DWC_E_NO_MEMORY;
  52612. + }
  52613. + dwc_memset(cfiep, 0, sizeof(cfi_ep_t));
  52614. +
  52615. + /* Save the dwc_otg_pcd_ep pointer in the cfiep object */
  52616. + cfiep->ep = ep;
  52617. +
  52618. + /* Allocate the DMA Descriptors chain of MAX_DMA_DESCS_PER_EP count */
  52619. + ep->dwc_ep.descs =
  52620. + DWC_DMA_ALLOC(MAX_DMA_DESCS_PER_EP *
  52621. + sizeof(dwc_otg_dma_desc_t),
  52622. + &ep->dwc_ep.descs_dma_addr);
  52623. +
  52624. + if (NULL == ep->dwc_ep.descs) {
  52625. + DWC_FREE(cfiep);
  52626. + return -DWC_E_NO_MEMORY;
  52627. + }
  52628. +
  52629. + DWC_LIST_INIT(&cfiep->lh);
  52630. +
  52631. + /* Set the buffer mode to BM_STANDARD. It will be modified
  52632. + * when building descriptors for a specific buffer mode */
  52633. + ep->dwc_ep.buff_mode = BM_STANDARD;
  52634. +
  52635. + /* Create and initialize the default values for this EP's Buffer modes */
  52636. + if ((retval = cfi_ep_init_defaults(pcd, cfiep)) < 0)
  52637. + return retval;
  52638. +
  52639. + /* Add the cfi_ep_t object to the CFI object's list of active endpoints */
  52640. + DWC_LIST_INSERT_TAIL(&cfi->active_eps, &cfiep->lh);
  52641. + retval = 0;
  52642. + } else { /* The sought EP already is in the list */
  52643. + CFI_INFO("%s: The sought EP already is in the list\n",
  52644. + __func__);
  52645. + }
  52646. +
  52647. + return retval;
  52648. +}
  52649. +
  52650. +/**
  52651. + * This function is called when the data stage of a 3-stage Control Write request
  52652. + * is complete.
  52653. + *
  52654. + */
  52655. +static int cfi_ctrl_write_complete(struct cfiobject *cfi,
  52656. + struct dwc_otg_pcd *pcd)
  52657. +{
  52658. + uint32_t addr, reg_value;
  52659. + uint16_t wIndex, wValue;
  52660. + uint8_t bRequest;
  52661. + uint8_t *buf = cfi->buf_out.buf;
  52662. + //struct usb_ctrlrequest *ctrl_req = &cfi->ctrl_req_saved;
  52663. + struct cfi_usb_ctrlrequest *ctrl_req = &cfi->ctrl_req;
  52664. + int retval = -DWC_E_NOT_SUPPORTED;
  52665. +
  52666. + CFI_INFO("%s\n", __func__);
  52667. +
  52668. + bRequest = ctrl_req->bRequest;
  52669. + wIndex = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wIndex);
  52670. + wValue = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wValue);
  52671. +
  52672. + /*
  52673. + * Save the pointer to the data stage in the ctrl_req's <data> field.
  52674. + * The request should be already saved in the command stage by now.
  52675. + */
  52676. + ctrl_req->data = cfi->buf_out.buf;
  52677. + cfi->need_status_in_complete = 0;
  52678. + cfi->need_gadget_att = 0;
  52679. +
  52680. + switch (bRequest) {
  52681. + case VEN_CORE_WRITE_REGISTER:
  52682. + /* The buffer contains raw data of the new value for the register */
  52683. + reg_value = *((uint32_t *) buf);
  52684. + if (wValue == 0) {
  52685. + addr = 0;
  52686. + //addr = (uint32_t) pcd->otg_dev->os_dep.base;
  52687. + addr += wIndex;
  52688. + } else {
  52689. + addr = (wValue << 16) | wIndex;
  52690. + }
  52691. +
  52692. + //writel(reg_value, addr);
  52693. +
  52694. + retval = 0;
  52695. + cfi->need_status_in_complete = 1;
  52696. + break;
  52697. +
  52698. + case VEN_CORE_SET_FEATURE:
  52699. + /* The buffer contains raw data of the new value of the feature */
  52700. + retval = cfi_set_feature_value(pcd);
  52701. + if (retval < 0)
  52702. + return retval;
  52703. +
  52704. + cfi->need_status_in_complete = 1;
  52705. + break;
  52706. +
  52707. + default:
  52708. + break;
  52709. + }
  52710. +
  52711. + return retval;
  52712. +}
  52713. +
  52714. +/**
  52715. + * This function builds the DMA descriptors for the SG buffer mode.
  52716. + */
  52717. +static void cfi_build_sg_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  52718. + dwc_otg_pcd_request_t * req)
  52719. +{
  52720. + struct dwc_otg_pcd_ep *ep = cfiep->ep;
  52721. + ddma_sg_buffer_setup_t *sgval = cfiep->bm_sg;
  52722. + struct dwc_otg_dma_desc *desc = cfiep->ep->dwc_ep.descs;
  52723. + struct dwc_otg_dma_desc *desc_last = cfiep->ep->dwc_ep.descs;
  52724. + dma_addr_t buff_addr = req->dma;
  52725. + int i;
  52726. + uint32_t txsize, off;
  52727. +
  52728. + txsize = sgval->wSize;
  52729. + off = sgval->bOffset;
  52730. +
  52731. +// CFI_INFO("%s: %s TXSIZE=0x%08x; OFFSET=0x%08x\n",
  52732. +// __func__, cfiep->ep->ep.name, txsize, off);
  52733. +
  52734. + for (i = 0; i < sgval->bCount; i++) {
  52735. + desc->status.b.bs = BS_HOST_BUSY;
  52736. + desc->buf = buff_addr;
  52737. + desc->status.b.l = 0;
  52738. + desc->status.b.ioc = 0;
  52739. + desc->status.b.sp = 0;
  52740. + desc->status.b.bytes = txsize;
  52741. + desc->status.b.bs = BS_HOST_READY;
  52742. +
  52743. + /* Set the next address of the buffer */
  52744. + buff_addr += txsize + off;
  52745. + desc_last = desc;
  52746. + desc++;
  52747. + }
  52748. +
  52749. + /* Set the last, ioc and sp bits on the Last DMA Descriptor */
  52750. + desc_last->status.b.l = 1;
  52751. + desc_last->status.b.ioc = 1;
  52752. + desc_last->status.b.sp = ep->dwc_ep.sent_zlp;
  52753. + /* Save the last DMA descriptor pointer */
  52754. + cfiep->dma_desc_last = desc_last;
  52755. + cfiep->desc_count = sgval->bCount;
  52756. +}
  52757. +
  52758. +/**
  52759. + * This function builds the DMA descriptors for the Concatenation buffer mode.
  52760. + */
  52761. +static void cfi_build_concat_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  52762. + dwc_otg_pcd_request_t * req)
  52763. +{
  52764. + struct dwc_otg_pcd_ep *ep = cfiep->ep;
  52765. + ddma_concat_buffer_setup_t *concatval = cfiep->bm_concat;
  52766. + struct dwc_otg_dma_desc *desc = cfiep->ep->dwc_ep.descs;
  52767. + struct dwc_otg_dma_desc *desc_last = cfiep->ep->dwc_ep.descs;
  52768. + dma_addr_t buff_addr = req->dma;
  52769. + int i;
  52770. + uint16_t *txsize;
  52771. +
  52772. + txsize = concatval->wTxBytes;
  52773. +
  52774. + for (i = 0; i < concatval->hdr.bDescCount; i++) {
  52775. + desc->buf = buff_addr;
  52776. + desc->status.b.bs = BS_HOST_BUSY;
  52777. + desc->status.b.l = 0;
  52778. + desc->status.b.ioc = 0;
  52779. + desc->status.b.sp = 0;
  52780. + desc->status.b.bytes = *txsize;
  52781. + desc->status.b.bs = BS_HOST_READY;
  52782. +
  52783. + txsize++;
  52784. + /* Set the next address of the buffer */
  52785. + buff_addr += UGETW(ep->desc->wMaxPacketSize);
  52786. + desc_last = desc;
  52787. + desc++;
  52788. + }
  52789. +
  52790. + /* Set the last, ioc and sp bits on the Last DMA Descriptor */
  52791. + desc_last->status.b.l = 1;
  52792. + desc_last->status.b.ioc = 1;
  52793. + desc_last->status.b.sp = ep->dwc_ep.sent_zlp;
  52794. + cfiep->dma_desc_last = desc_last;
  52795. + cfiep->desc_count = concatval->hdr.bDescCount;
  52796. +}
  52797. +
  52798. +/**
  52799. + * This function builds the DMA descriptors for the Circular buffer mode
  52800. + */
  52801. +static void cfi_build_circ_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  52802. + dwc_otg_pcd_request_t * req)
  52803. +{
  52804. + /* @todo: MAS - add implementation when this feature needs to be tested */
  52805. +}
  52806. +
  52807. +/**
  52808. + * This function builds the DMA descriptors for the Alignment buffer mode
  52809. + */
  52810. +static void cfi_build_align_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  52811. + dwc_otg_pcd_request_t * req)
  52812. +{
  52813. + struct dwc_otg_pcd_ep *ep = cfiep->ep;
  52814. + ddma_align_buffer_setup_t *alignval = cfiep->bm_align;
  52815. + struct dwc_otg_dma_desc *desc = cfiep->ep->dwc_ep.descs;
  52816. + dma_addr_t buff_addr = req->dma;
  52817. +
  52818. + desc->status.b.bs = BS_HOST_BUSY;
  52819. + desc->status.b.l = 1;
  52820. + desc->status.b.ioc = 1;
  52821. + desc->status.b.sp = ep->dwc_ep.sent_zlp;
  52822. + desc->status.b.bytes = req->length;
  52823. + /* Adjust the buffer alignment */
  52824. + desc->buf = (buff_addr + alignval->bAlign);
  52825. + desc->status.b.bs = BS_HOST_READY;
  52826. + cfiep->dma_desc_last = desc;
  52827. + cfiep->desc_count = 1;
  52828. +}
  52829. +
  52830. +/**
  52831. + * This function builds the DMA descriptors chain for different modes of the
  52832. + * buffer setup of an endpoint.
  52833. + */
  52834. +static void cfi_build_descriptors(struct cfiobject *cfi,
  52835. + struct dwc_otg_pcd *pcd,
  52836. + struct dwc_otg_pcd_ep *ep,
  52837. + dwc_otg_pcd_request_t * req)
  52838. +{
  52839. + cfi_ep_t *cfiep;
  52840. +
  52841. + /* Get the cfiep by the dwc_otg_pcd_ep */
  52842. + cfiep = get_cfi_ep_by_pcd_ep(cfi, ep);
  52843. + if (NULL == cfiep) {
  52844. + CFI_INFO("%s: Unable to find a matching active endpoint\n",
  52845. + __func__);
  52846. + return;
  52847. + }
  52848. +
  52849. + cfiep->xfer_len = req->length;
  52850. +
  52851. + /* Iterate through all the DMA descriptors */
  52852. + switch (cfiep->ep->dwc_ep.buff_mode) {
  52853. + case BM_SG:
  52854. + cfi_build_sg_descs(cfi, cfiep, req);
  52855. + break;
  52856. +
  52857. + case BM_CONCAT:
  52858. + cfi_build_concat_descs(cfi, cfiep, req);
  52859. + break;
  52860. +
  52861. + case BM_CIRCULAR:
  52862. + cfi_build_circ_descs(cfi, cfiep, req);
  52863. + break;
  52864. +
  52865. + case BM_ALIGN:
  52866. + cfi_build_align_descs(cfi, cfiep, req);
  52867. + break;
  52868. +
  52869. + default:
  52870. + break;
  52871. + }
  52872. +}
  52873. +
  52874. +/**
  52875. + * Allocate DMA buffer for different Buffer modes.
  52876. + */
  52877. +static void *cfi_ep_alloc_buf(struct cfiobject *cfi, struct dwc_otg_pcd *pcd,
  52878. + struct dwc_otg_pcd_ep *ep, dma_addr_t * dma,
  52879. + unsigned size, gfp_t flags)
  52880. +{
  52881. + return DWC_DMA_ALLOC(size, dma);
  52882. +}
  52883. +
  52884. +/**
  52885. + * This function initializes the CFI object.
  52886. + */
  52887. +int init_cfi(cfiobject_t * cfiobj)
  52888. +{
  52889. + CFI_INFO("%s\n", __func__);
  52890. +
  52891. + /* Allocate a buffer for IN XFERs */
  52892. + cfiobj->buf_in.buf =
  52893. + DWC_DMA_ALLOC(CFI_IN_BUF_LEN, &cfiobj->buf_in.addr);
  52894. + if (NULL == cfiobj->buf_in.buf) {
  52895. + CFI_INFO("Unable to allocate buffer for INs\n");
  52896. + return -DWC_E_NO_MEMORY;
  52897. + }
  52898. +
  52899. + /* Allocate a buffer for OUT XFERs */
  52900. + cfiobj->buf_out.buf =
  52901. + DWC_DMA_ALLOC(CFI_OUT_BUF_LEN, &cfiobj->buf_out.addr);
  52902. + if (NULL == cfiobj->buf_out.buf) {
  52903. + CFI_INFO("Unable to allocate buffer for OUT\n");
  52904. + return -DWC_E_NO_MEMORY;
  52905. + }
  52906. +
  52907. + /* Initialize the callback function pointers */
  52908. + cfiobj->ops.release = cfi_release;
  52909. + cfiobj->ops.ep_enable = cfi_ep_enable;
  52910. + cfiobj->ops.ctrl_write_complete = cfi_ctrl_write_complete;
  52911. + cfiobj->ops.build_descriptors = cfi_build_descriptors;
  52912. + cfiobj->ops.ep_alloc_buf = cfi_ep_alloc_buf;
  52913. +
  52914. + /* Initialize the list of active endpoints in the CFI object */
  52915. + DWC_LIST_INIT(&cfiobj->active_eps);
  52916. +
  52917. + return 0;
  52918. +}
  52919. +
  52920. +/**
  52921. + * This function reads the required feature's current value into the buffer
  52922. + *
  52923. + * @retval: Returns negative as error, or the data length of the feature
  52924. + */
  52925. +static int cfi_get_feature_value(uint8_t * buf, uint16_t buflen,
  52926. + struct dwc_otg_pcd *pcd,
  52927. + struct cfi_usb_ctrlrequest *ctrl_req)
  52928. +{
  52929. + int retval = -DWC_E_NOT_SUPPORTED;
  52930. + struct dwc_otg_core_if *coreif = GET_CORE_IF(pcd);
  52931. + uint16_t dfifo, rxfifo, txfifo;
  52932. +
  52933. + switch (ctrl_req->wIndex) {
  52934. + /* Whether the DDMA is enabled or not */
  52935. + case FT_ID_DMA_MODE:
  52936. + *buf = (coreif->dma_enable && coreif->dma_desc_enable) ? 1 : 0;
  52937. + retval = 1;
  52938. + break;
  52939. +
  52940. + case FT_ID_DMA_BUFFER_SETUP:
  52941. + retval = cfi_ep_get_sg_val(buf, pcd, ctrl_req);
  52942. + break;
  52943. +
  52944. + case FT_ID_DMA_BUFF_ALIGN:
  52945. + retval = cfi_ep_get_align_val(buf, pcd, ctrl_req);
  52946. + break;
  52947. +
  52948. + case FT_ID_DMA_CONCAT_SETUP:
  52949. + retval = cfi_ep_get_concat_val(buf, pcd, ctrl_req);
  52950. + break;
  52951. +
  52952. + case FT_ID_DMA_CIRCULAR:
  52953. + CFI_INFO("GetFeature value (FT_ID_DMA_CIRCULAR)\n");
  52954. + break;
  52955. +
  52956. + case FT_ID_THRESHOLD_SETUP:
  52957. + CFI_INFO("GetFeature value (FT_ID_THRESHOLD_SETUP)\n");
  52958. + break;
  52959. +
  52960. + case FT_ID_DFIFO_DEPTH:
  52961. + dfifo = get_dfifo_size(coreif);
  52962. + *((uint16_t *) buf) = dfifo;
  52963. + retval = sizeof(uint16_t);
  52964. + break;
  52965. +
  52966. + case FT_ID_TX_FIFO_DEPTH:
  52967. + retval = get_txfifo_size(pcd, ctrl_req->wValue);
  52968. + if (retval >= 0) {
  52969. + txfifo = retval;
  52970. + *((uint16_t *) buf) = txfifo;
  52971. + retval = sizeof(uint16_t);
  52972. + }
  52973. + break;
  52974. +
  52975. + case FT_ID_RX_FIFO_DEPTH:
  52976. + retval = get_rxfifo_size(coreif, ctrl_req->wValue);
  52977. + if (retval >= 0) {
  52978. + rxfifo = retval;
  52979. + *((uint16_t *) buf) = rxfifo;
  52980. + retval = sizeof(uint16_t);
  52981. + }
  52982. + break;
  52983. + }
  52984. +
  52985. + return retval;
  52986. +}
  52987. +
  52988. +/**
  52989. + * This function resets the SG for the specified EP to its default value
  52990. + */
  52991. +static int cfi_reset_sg_val(cfi_ep_t * cfiep)
  52992. +{
  52993. + dwc_memset(cfiep->bm_sg, 0, sizeof(ddma_sg_buffer_setup_t));
  52994. + return 0;
  52995. +}
  52996. +
  52997. +/**
  52998. + * This function resets the Alignment for the specified EP to its default value
  52999. + */
  53000. +static int cfi_reset_align_val(cfi_ep_t * cfiep)
  53001. +{
  53002. + dwc_memset(cfiep->bm_sg, 0, sizeof(ddma_sg_buffer_setup_t));
  53003. + return 0;
  53004. +}
  53005. +
  53006. +/**
  53007. + * This function resets the Concatenation for the specified EP to its default value
  53008. + * This function will also set the value of the wTxBytes field to NULL after
  53009. + * freeing the memory previously allocated for this field.
  53010. + */
  53011. +static int cfi_reset_concat_val(cfi_ep_t * cfiep)
  53012. +{
  53013. + /* First we need to free the wTxBytes field */
  53014. + if (cfiep->bm_concat->wTxBytes) {
  53015. + DWC_FREE(cfiep->bm_concat->wTxBytes);
  53016. + cfiep->bm_concat->wTxBytes = NULL;
  53017. + }
  53018. +
  53019. + dwc_memset(cfiep->bm_concat, 0, sizeof(ddma_concat_buffer_setup_t));
  53020. + return 0;
  53021. +}
  53022. +
  53023. +/**
  53024. + * This function resets all the buffer setups of the specified endpoint
  53025. + */
  53026. +static int cfi_ep_reset_all_setup_vals(cfi_ep_t * cfiep)
  53027. +{
  53028. + cfi_reset_sg_val(cfiep);
  53029. + cfi_reset_align_val(cfiep);
  53030. + cfi_reset_concat_val(cfiep);
  53031. + return 0;
  53032. +}
  53033. +
  53034. +static int cfi_handle_reset_fifo_val(struct dwc_otg_pcd *pcd, uint8_t ep_addr,
  53035. + uint8_t rx_rst, uint8_t tx_rst)
  53036. +{
  53037. + int retval = -DWC_E_INVALID;
  53038. + uint16_t tx_siz[15];
  53039. + uint16_t rx_siz = 0;
  53040. + dwc_otg_pcd_ep_t *ep = NULL;
  53041. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  53042. + dwc_otg_core_params_t *params = GET_CORE_IF(pcd)->core_params;
  53043. +
  53044. + if (rx_rst) {
  53045. + rx_siz = params->dev_rx_fifo_size;
  53046. + params->dev_rx_fifo_size = GET_CORE_IF(pcd)->init_rxfsiz;
  53047. + }
  53048. +
  53049. + if (tx_rst) {
  53050. + if (ep_addr == 0) {
  53051. + int i;
  53052. +
  53053. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  53054. + tx_siz[i] =
  53055. + core_if->core_params->dev_tx_fifo_size[i];
  53056. + core_if->core_params->dev_tx_fifo_size[i] =
  53057. + core_if->init_txfsiz[i];
  53058. + }
  53059. + } else {
  53060. +
  53061. + ep = get_ep_by_addr(pcd, ep_addr);
  53062. +
  53063. + if (NULL == ep) {
  53064. + CFI_INFO
  53065. + ("%s: Unable to get the endpoint addr=0x%02x\n",
  53066. + __func__, ep_addr);
  53067. + return -DWC_E_INVALID;
  53068. + }
  53069. +
  53070. + tx_siz[0] =
  53071. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num -
  53072. + 1];
  53073. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1] =
  53074. + GET_CORE_IF(pcd)->init_txfsiz[ep->
  53075. + dwc_ep.tx_fifo_num -
  53076. + 1];
  53077. + }
  53078. + }
  53079. +
  53080. + if (resize_fifos(GET_CORE_IF(pcd))) {
  53081. + retval = 0;
  53082. + } else {
  53083. + CFI_INFO
  53084. + ("%s: Error resetting the feature Reset All(FIFO size)\n",
  53085. + __func__);
  53086. + if (rx_rst) {
  53087. + params->dev_rx_fifo_size = rx_siz;
  53088. + }
  53089. +
  53090. + if (tx_rst) {
  53091. + if (ep_addr == 0) {
  53092. + int i;
  53093. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps;
  53094. + i++) {
  53095. + core_if->
  53096. + core_params->dev_tx_fifo_size[i] =
  53097. + tx_siz[i];
  53098. + }
  53099. + } else {
  53100. + params->dev_tx_fifo_size[ep->
  53101. + dwc_ep.tx_fifo_num -
  53102. + 1] = tx_siz[0];
  53103. + }
  53104. + }
  53105. + retval = -DWC_E_INVALID;
  53106. + }
  53107. + return retval;
  53108. +}
  53109. +
  53110. +static int cfi_handle_reset_all(struct dwc_otg_pcd *pcd, uint8_t addr)
  53111. +{
  53112. + int retval = 0;
  53113. + cfi_ep_t *cfiep;
  53114. + cfiobject_t *cfi = pcd->cfi;
  53115. + dwc_list_link_t *tmp;
  53116. +
  53117. + retval = cfi_handle_reset_fifo_val(pcd, addr, 1, 1);
  53118. + if (retval < 0) {
  53119. + return retval;
  53120. + }
  53121. +
  53122. + /* If the EP address is known then reset the features for only that EP */
  53123. + if (addr) {
  53124. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  53125. + if (NULL == cfiep) {
  53126. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  53127. + __func__, addr);
  53128. + return -DWC_E_INVALID;
  53129. + }
  53130. + retval = cfi_ep_reset_all_setup_vals(cfiep);
  53131. + cfiep->ep->dwc_ep.buff_mode = BM_STANDARD;
  53132. + }
  53133. + /* Otherwise (wValue == 0), reset all features of all EP's */
  53134. + else {
  53135. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  53136. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  53137. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  53138. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  53139. + retval = cfi_ep_reset_all_setup_vals(cfiep);
  53140. + cfiep->ep->dwc_ep.buff_mode = BM_STANDARD;
  53141. + if (retval < 0) {
  53142. + CFI_INFO
  53143. + ("%s: Error resetting the feature Reset All\n",
  53144. + __func__);
  53145. + return retval;
  53146. + }
  53147. + }
  53148. + }
  53149. + return retval;
  53150. +}
  53151. +
  53152. +static int cfi_handle_reset_dma_buff_setup(struct dwc_otg_pcd *pcd,
  53153. + uint8_t addr)
  53154. +{
  53155. + int retval = 0;
  53156. + cfi_ep_t *cfiep;
  53157. + cfiobject_t *cfi = pcd->cfi;
  53158. + dwc_list_link_t *tmp;
  53159. +
  53160. + /* If the EP address is known then reset the features for only that EP */
  53161. + if (addr) {
  53162. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  53163. + if (NULL == cfiep) {
  53164. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  53165. + __func__, addr);
  53166. + return -DWC_E_INVALID;
  53167. + }
  53168. + retval = cfi_reset_sg_val(cfiep);
  53169. + }
  53170. + /* Otherwise (wValue == 0), reset all features of all EP's */
  53171. + else {
  53172. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  53173. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  53174. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  53175. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  53176. + retval = cfi_reset_sg_val(cfiep);
  53177. + if (retval < 0) {
  53178. + CFI_INFO
  53179. + ("%s: Error resetting the feature Buffer Setup\n",
  53180. + __func__);
  53181. + return retval;
  53182. + }
  53183. + }
  53184. + }
  53185. + return retval;
  53186. +}
  53187. +
  53188. +static int cfi_handle_reset_concat_val(struct dwc_otg_pcd *pcd, uint8_t addr)
  53189. +{
  53190. + int retval = 0;
  53191. + cfi_ep_t *cfiep;
  53192. + cfiobject_t *cfi = pcd->cfi;
  53193. + dwc_list_link_t *tmp;
  53194. +
  53195. + /* If the EP address is known then reset the features for only that EP */
  53196. + if (addr) {
  53197. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  53198. + if (NULL == cfiep) {
  53199. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  53200. + __func__, addr);
  53201. + return -DWC_E_INVALID;
  53202. + }
  53203. + retval = cfi_reset_concat_val(cfiep);
  53204. + }
  53205. + /* Otherwise (wValue == 0), reset all features of all EP's */
  53206. + else {
  53207. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  53208. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  53209. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  53210. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  53211. + retval = cfi_reset_concat_val(cfiep);
  53212. + if (retval < 0) {
  53213. + CFI_INFO
  53214. + ("%s: Error resetting the feature Concatenation Value\n",
  53215. + __func__);
  53216. + return retval;
  53217. + }
  53218. + }
  53219. + }
  53220. + return retval;
  53221. +}
  53222. +
  53223. +static int cfi_handle_reset_align_val(struct dwc_otg_pcd *pcd, uint8_t addr)
  53224. +{
  53225. + int retval = 0;
  53226. + cfi_ep_t *cfiep;
  53227. + cfiobject_t *cfi = pcd->cfi;
  53228. + dwc_list_link_t *tmp;
  53229. +
  53230. + /* If the EP address is known then reset the features for only that EP */
  53231. + if (addr) {
  53232. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  53233. + if (NULL == cfiep) {
  53234. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  53235. + __func__, addr);
  53236. + return -DWC_E_INVALID;
  53237. + }
  53238. + retval = cfi_reset_align_val(cfiep);
  53239. + }
  53240. + /* Otherwise (wValue == 0), reset all features of all EP's */
  53241. + else {
  53242. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  53243. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  53244. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  53245. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  53246. + retval = cfi_reset_align_val(cfiep);
  53247. + if (retval < 0) {
  53248. + CFI_INFO
  53249. + ("%s: Error resetting the feature Aliignment Value\n",
  53250. + __func__);
  53251. + return retval;
  53252. + }
  53253. + }
  53254. + }
  53255. + return retval;
  53256. +
  53257. +}
  53258. +
  53259. +static int cfi_preproc_reset(struct dwc_otg_pcd *pcd,
  53260. + struct cfi_usb_ctrlrequest *req)
  53261. +{
  53262. + int retval = 0;
  53263. +
  53264. + switch (req->wIndex) {
  53265. + case 0:
  53266. + /* Reset all features */
  53267. + retval = cfi_handle_reset_all(pcd, req->wValue & 0xff);
  53268. + break;
  53269. +
  53270. + case FT_ID_DMA_BUFFER_SETUP:
  53271. + /* Reset the SG buffer setup */
  53272. + retval =
  53273. + cfi_handle_reset_dma_buff_setup(pcd, req->wValue & 0xff);
  53274. + break;
  53275. +
  53276. + case FT_ID_DMA_CONCAT_SETUP:
  53277. + /* Reset the Concatenation buffer setup */
  53278. + retval = cfi_handle_reset_concat_val(pcd, req->wValue & 0xff);
  53279. + break;
  53280. +
  53281. + case FT_ID_DMA_BUFF_ALIGN:
  53282. + /* Reset the Alignment buffer setup */
  53283. + retval = cfi_handle_reset_align_val(pcd, req->wValue & 0xff);
  53284. + break;
  53285. +
  53286. + case FT_ID_TX_FIFO_DEPTH:
  53287. + retval =
  53288. + cfi_handle_reset_fifo_val(pcd, req->wValue & 0xff, 0, 1);
  53289. + pcd->cfi->need_gadget_att = 0;
  53290. + break;
  53291. +
  53292. + case FT_ID_RX_FIFO_DEPTH:
  53293. + retval = cfi_handle_reset_fifo_val(pcd, 0, 1, 0);
  53294. + pcd->cfi->need_gadget_att = 0;
  53295. + break;
  53296. + default:
  53297. + break;
  53298. + }
  53299. + return retval;
  53300. +}
  53301. +
  53302. +/**
  53303. + * This function sets a new value for the SG buffer setup.
  53304. + */
  53305. +static int cfi_ep_set_sg_val(uint8_t * buf, struct dwc_otg_pcd *pcd)
  53306. +{
  53307. + uint8_t inaddr, outaddr;
  53308. + cfi_ep_t *epin, *epout;
  53309. + ddma_sg_buffer_setup_t *psgval;
  53310. + uint32_t desccount, size;
  53311. +
  53312. + CFI_INFO("%s\n", __func__);
  53313. +
  53314. + psgval = (ddma_sg_buffer_setup_t *) buf;
  53315. + desccount = (uint32_t) psgval->bCount;
  53316. + size = (uint32_t) psgval->wSize;
  53317. +
  53318. + /* Check the DMA descriptor count */
  53319. + if ((desccount > MAX_DMA_DESCS_PER_EP) || (desccount == 0)) {
  53320. + CFI_INFO
  53321. + ("%s: The count of DMA Descriptors should be between 1 and %d\n",
  53322. + __func__, MAX_DMA_DESCS_PER_EP);
  53323. + return -DWC_E_INVALID;
  53324. + }
  53325. +
  53326. + /* Check the DMA descriptor count */
  53327. +
  53328. + if (size == 0) {
  53329. +
  53330. + CFI_INFO("%s: The transfer size should be at least 1 byte\n",
  53331. + __func__);
  53332. +
  53333. + return -DWC_E_INVALID;
  53334. +
  53335. + }
  53336. +
  53337. + inaddr = psgval->bInEndpointAddress;
  53338. + outaddr = psgval->bOutEndpointAddress;
  53339. +
  53340. + epin = get_cfi_ep_by_addr(pcd->cfi, inaddr);
  53341. + epout = get_cfi_ep_by_addr(pcd->cfi, outaddr);
  53342. +
  53343. + if (NULL == epin || NULL == epout) {
  53344. + CFI_INFO
  53345. + ("%s: Unable to get the endpoints inaddr=0x%02x outaddr=0x%02x\n",
  53346. + __func__, inaddr, outaddr);
  53347. + return -DWC_E_INVALID;
  53348. + }
  53349. +
  53350. + epin->ep->dwc_ep.buff_mode = BM_SG;
  53351. + dwc_memcpy(epin->bm_sg, psgval, sizeof(ddma_sg_buffer_setup_t));
  53352. +
  53353. + epout->ep->dwc_ep.buff_mode = BM_SG;
  53354. + dwc_memcpy(epout->bm_sg, psgval, sizeof(ddma_sg_buffer_setup_t));
  53355. +
  53356. + return 0;
  53357. +}
  53358. +
  53359. +/**
  53360. + * This function sets a new value for the buffer Alignment setup.
  53361. + */
  53362. +static int cfi_ep_set_alignment_val(uint8_t * buf, struct dwc_otg_pcd *pcd)
  53363. +{
  53364. + cfi_ep_t *ep;
  53365. + uint8_t addr;
  53366. + ddma_align_buffer_setup_t *palignval;
  53367. +
  53368. + palignval = (ddma_align_buffer_setup_t *) buf;
  53369. + addr = palignval->bEndpointAddress;
  53370. +
  53371. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  53372. +
  53373. + if (NULL == ep) {
  53374. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  53375. + __func__, addr);
  53376. + return -DWC_E_INVALID;
  53377. + }
  53378. +
  53379. + ep->ep->dwc_ep.buff_mode = BM_ALIGN;
  53380. + dwc_memcpy(ep->bm_align, palignval, sizeof(ddma_align_buffer_setup_t));
  53381. +
  53382. + return 0;
  53383. +}
  53384. +
  53385. +/**
  53386. + * This function sets a new value for the Concatenation buffer setup.
  53387. + */
  53388. +static int cfi_ep_set_concat_val(uint8_t * buf, struct dwc_otg_pcd *pcd)
  53389. +{
  53390. + uint8_t addr;
  53391. + cfi_ep_t *ep;
  53392. + struct _ddma_concat_buffer_setup_hdr *pConcatValHdr;
  53393. + uint16_t *pVals;
  53394. + uint32_t desccount;
  53395. + int i;
  53396. + uint16_t mps;
  53397. +
  53398. + pConcatValHdr = (struct _ddma_concat_buffer_setup_hdr *)buf;
  53399. + desccount = (uint32_t) pConcatValHdr->bDescCount;
  53400. + pVals = (uint16_t *) (buf + BS_CONCAT_VAL_HDR_LEN);
  53401. +
  53402. + /* Check the DMA descriptor count */
  53403. + if (desccount > MAX_DMA_DESCS_PER_EP) {
  53404. + CFI_INFO("%s: Maximum DMA Descriptor count should be %d\n",
  53405. + __func__, MAX_DMA_DESCS_PER_EP);
  53406. + return -DWC_E_INVALID;
  53407. + }
  53408. +
  53409. + addr = pConcatValHdr->bEndpointAddress;
  53410. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  53411. + if (NULL == ep) {
  53412. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  53413. + __func__, addr);
  53414. + return -DWC_E_INVALID;
  53415. + }
  53416. +
  53417. + mps = UGETW(ep->ep->desc->wMaxPacketSize);
  53418. +
  53419. +#if 0
  53420. + for (i = 0; i < desccount; i++) {
  53421. + CFI_INFO("%s: wTxSize[%d]=0x%04x\n", __func__, i, pVals[i]);
  53422. + }
  53423. + CFI_INFO("%s: epname=%s; mps=%d\n", __func__, ep->ep->ep.name, mps);
  53424. +#endif
  53425. +
  53426. + /* Check the wTxSizes to be less than or equal to the mps */
  53427. + for (i = 0; i < desccount; i++) {
  53428. + if (pVals[i] > mps) {
  53429. + CFI_INFO
  53430. + ("%s: ERROR - the wTxSize[%d] should be <= MPS (wTxSize=%d)\n",
  53431. + __func__, i, pVals[i]);
  53432. + return -DWC_E_INVALID;
  53433. + }
  53434. + }
  53435. +
  53436. + ep->ep->dwc_ep.buff_mode = BM_CONCAT;
  53437. + dwc_memcpy(ep->bm_concat, pConcatValHdr, BS_CONCAT_VAL_HDR_LEN);
  53438. +
  53439. + /* Free the previously allocated storage for the wTxBytes */
  53440. + if (ep->bm_concat->wTxBytes) {
  53441. + DWC_FREE(ep->bm_concat->wTxBytes);
  53442. + }
  53443. +
  53444. + /* Allocate a new storage for the wTxBytes field */
  53445. + ep->bm_concat->wTxBytes =
  53446. + DWC_ALLOC(sizeof(uint16_t) * pConcatValHdr->bDescCount);
  53447. + if (NULL == ep->bm_concat->wTxBytes) {
  53448. + CFI_INFO("%s: Unable to allocate memory\n", __func__);
  53449. + return -DWC_E_NO_MEMORY;
  53450. + }
  53451. +
  53452. + /* Copy the new values into the wTxBytes filed */
  53453. + dwc_memcpy(ep->bm_concat->wTxBytes, buf + BS_CONCAT_VAL_HDR_LEN,
  53454. + sizeof(uint16_t) * pConcatValHdr->bDescCount);
  53455. +
  53456. + return 0;
  53457. +}
  53458. +
  53459. +/**
  53460. + * This function calculates the total of all FIFO sizes
  53461. + *
  53462. + * @param core_if Programming view of DWC_otg controller
  53463. + *
  53464. + * @return The total of data FIFO sizes.
  53465. + *
  53466. + */
  53467. +static uint16_t get_dfifo_size(dwc_otg_core_if_t * core_if)
  53468. +{
  53469. + dwc_otg_core_params_t *params = core_if->core_params;
  53470. + uint16_t dfifo_total = 0;
  53471. + int i;
  53472. +
  53473. + /* The shared RxFIFO size */
  53474. + dfifo_total =
  53475. + params->dev_rx_fifo_size + params->dev_nperio_tx_fifo_size;
  53476. +
  53477. + /* Add up each TxFIFO size to the total */
  53478. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  53479. + dfifo_total += params->dev_tx_fifo_size[i];
  53480. + }
  53481. +
  53482. + return dfifo_total;
  53483. +}
  53484. +
  53485. +/**
  53486. + * This function returns Rx FIFO size
  53487. + *
  53488. + * @param core_if Programming view of DWC_otg controller
  53489. + *
  53490. + * @return The total of data FIFO sizes.
  53491. + *
  53492. + */
  53493. +static int32_t get_rxfifo_size(dwc_otg_core_if_t * core_if, uint16_t wValue)
  53494. +{
  53495. + switch (wValue >> 8) {
  53496. + case 0:
  53497. + return (core_if->pwron_rxfsiz <
  53498. + 32768) ? core_if->pwron_rxfsiz : 32768;
  53499. + break;
  53500. + case 1:
  53501. + return core_if->core_params->dev_rx_fifo_size;
  53502. + break;
  53503. + default:
  53504. + return -DWC_E_INVALID;
  53505. + break;
  53506. + }
  53507. +}
  53508. +
  53509. +/**
  53510. + * This function returns Tx FIFO size for IN EP
  53511. + *
  53512. + * @param core_if Programming view of DWC_otg controller
  53513. + *
  53514. + * @return The total of data FIFO sizes.
  53515. + *
  53516. + */
  53517. +static int32_t get_txfifo_size(struct dwc_otg_pcd *pcd, uint16_t wValue)
  53518. +{
  53519. + dwc_otg_pcd_ep_t *ep;
  53520. +
  53521. + ep = get_ep_by_addr(pcd, wValue & 0xff);
  53522. +
  53523. + if (NULL == ep) {
  53524. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  53525. + __func__, wValue & 0xff);
  53526. + return -DWC_E_INVALID;
  53527. + }
  53528. +
  53529. + if (!ep->dwc_ep.is_in) {
  53530. + CFI_INFO
  53531. + ("%s: No Tx FIFO assingned to the Out endpoint addr=0x%02x\n",
  53532. + __func__, wValue & 0xff);
  53533. + return -DWC_E_INVALID;
  53534. + }
  53535. +
  53536. + switch (wValue >> 8) {
  53537. + case 0:
  53538. + return (GET_CORE_IF(pcd)->pwron_txfsiz
  53539. + [ep->dwc_ep.tx_fifo_num - 1] <
  53540. + 768) ? GET_CORE_IF(pcd)->pwron_txfsiz[ep->
  53541. + dwc_ep.tx_fifo_num
  53542. + - 1] : 32768;
  53543. + break;
  53544. + case 1:
  53545. + return GET_CORE_IF(pcd)->core_params->
  53546. + dev_tx_fifo_size[ep->dwc_ep.num - 1];
  53547. + break;
  53548. + default:
  53549. + return -DWC_E_INVALID;
  53550. + break;
  53551. + }
  53552. +}
  53553. +
  53554. +/**
  53555. + * This function checks if the submitted combination of
  53556. + * device mode FIFO sizes is possible or not.
  53557. + *
  53558. + * @param core_if Programming view of DWC_otg controller
  53559. + *
  53560. + * @return 1 if possible, 0 otherwise.
  53561. + *
  53562. + */
  53563. +static uint8_t check_fifo_sizes(dwc_otg_core_if_t * core_if)
  53564. +{
  53565. + uint16_t dfifo_actual = 0;
  53566. + dwc_otg_core_params_t *params = core_if->core_params;
  53567. + uint16_t start_addr = 0;
  53568. + int i;
  53569. +
  53570. + dfifo_actual =
  53571. + params->dev_rx_fifo_size + params->dev_nperio_tx_fifo_size;
  53572. +
  53573. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  53574. + dfifo_actual += params->dev_tx_fifo_size[i];
  53575. + }
  53576. +
  53577. + if (dfifo_actual > core_if->total_fifo_size) {
  53578. + return 0;
  53579. + }
  53580. +
  53581. + if (params->dev_rx_fifo_size > 32768 || params->dev_rx_fifo_size < 16)
  53582. + return 0;
  53583. +
  53584. + if (params->dev_nperio_tx_fifo_size > 32768
  53585. + || params->dev_nperio_tx_fifo_size < 16)
  53586. + return 0;
  53587. +
  53588. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  53589. +
  53590. + if (params->dev_tx_fifo_size[i] > 768
  53591. + || params->dev_tx_fifo_size[i] < 4)
  53592. + return 0;
  53593. + }
  53594. +
  53595. + if (params->dev_rx_fifo_size > core_if->pwron_rxfsiz)
  53596. + return 0;
  53597. + start_addr = params->dev_rx_fifo_size;
  53598. +
  53599. + if (params->dev_nperio_tx_fifo_size > core_if->pwron_gnptxfsiz)
  53600. + return 0;
  53601. + start_addr += params->dev_nperio_tx_fifo_size;
  53602. +
  53603. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  53604. +
  53605. + if (params->dev_tx_fifo_size[i] > core_if->pwron_txfsiz[i])
  53606. + return 0;
  53607. + start_addr += params->dev_tx_fifo_size[i];
  53608. + }
  53609. +
  53610. + return 1;
  53611. +}
  53612. +
  53613. +/**
  53614. + * This function resizes Device mode FIFOs
  53615. + *
  53616. + * @param core_if Programming view of DWC_otg controller
  53617. + *
  53618. + * @return 1 if successful, 0 otherwise
  53619. + *
  53620. + */
  53621. +static uint8_t resize_fifos(dwc_otg_core_if_t * core_if)
  53622. +{
  53623. + int i = 0;
  53624. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  53625. + dwc_otg_core_params_t *params = core_if->core_params;
  53626. + uint32_t rx_fifo_size;
  53627. + fifosize_data_t nptxfifosize;
  53628. + fifosize_data_t txfifosize[15];
  53629. +
  53630. + uint32_t rx_fsz_bak;
  53631. + uint32_t nptxfsz_bak;
  53632. + uint32_t txfsz_bak[15];
  53633. +
  53634. + uint16_t start_address;
  53635. + uint8_t retval = 1;
  53636. +
  53637. + if (!check_fifo_sizes(core_if)) {
  53638. + return 0;
  53639. + }
  53640. +
  53641. + /* Configure data FIFO sizes */
  53642. + if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
  53643. + rx_fsz_bak = DWC_READ_REG32(&global_regs->grxfsiz);
  53644. + rx_fifo_size = params->dev_rx_fifo_size;
  53645. + DWC_WRITE_REG32(&global_regs->grxfsiz, rx_fifo_size);
  53646. +
  53647. + /*
  53648. + * Tx FIFOs These FIFOs are numbered from 1 to 15.
  53649. + * Indexes of the FIFO size module parameters in the
  53650. + * dev_tx_fifo_size array and the FIFO size registers in
  53651. + * the dtxfsiz array run from 0 to 14.
  53652. + */
  53653. +
  53654. + /* Non-periodic Tx FIFO */
  53655. + nptxfsz_bak = DWC_READ_REG32(&global_regs->gnptxfsiz);
  53656. + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
  53657. + start_address = params->dev_rx_fifo_size;
  53658. + nptxfifosize.b.startaddr = start_address;
  53659. +
  53660. + DWC_WRITE_REG32(&global_regs->gnptxfsiz, nptxfifosize.d32);
  53661. +
  53662. + start_address += nptxfifosize.b.depth;
  53663. +
  53664. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  53665. + txfsz_bak[i] = DWC_READ_REG32(&global_regs->dtxfsiz[i]);
  53666. +
  53667. + txfifosize[i].b.depth = params->dev_tx_fifo_size[i];
  53668. + txfifosize[i].b.startaddr = start_address;
  53669. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  53670. + txfifosize[i].d32);
  53671. +
  53672. + start_address += txfifosize[i].b.depth;
  53673. + }
  53674. +
  53675. + /** Check if register values are set correctly */
  53676. + if (rx_fifo_size != DWC_READ_REG32(&global_regs->grxfsiz)) {
  53677. + retval = 0;
  53678. + }
  53679. +
  53680. + if (nptxfifosize.d32 != DWC_READ_REG32(&global_regs->gnptxfsiz)) {
  53681. + retval = 0;
  53682. + }
  53683. +
  53684. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  53685. + if (txfifosize[i].d32 !=
  53686. + DWC_READ_REG32(&global_regs->dtxfsiz[i])) {
  53687. + retval = 0;
  53688. + }
  53689. + }
  53690. +
  53691. + /** If register values are not set correctly, reset old values */
  53692. + if (retval == 0) {
  53693. + DWC_WRITE_REG32(&global_regs->grxfsiz, rx_fsz_bak);
  53694. +
  53695. + /* Non-periodic Tx FIFO */
  53696. + DWC_WRITE_REG32(&global_regs->gnptxfsiz, nptxfsz_bak);
  53697. +
  53698. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  53699. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  53700. + txfsz_bak[i]);
  53701. + }
  53702. + }
  53703. + } else {
  53704. + return 0;
  53705. + }
  53706. +
  53707. + /* Flush the FIFOs */
  53708. + dwc_otg_flush_tx_fifo(core_if, 0x10); /* all Tx FIFOs */
  53709. + dwc_otg_flush_rx_fifo(core_if);
  53710. +
  53711. + return retval;
  53712. +}
  53713. +
  53714. +/**
  53715. + * This function sets a new value for the buffer Alignment setup.
  53716. + */
  53717. +static int cfi_ep_set_tx_fifo_val(uint8_t * buf, dwc_otg_pcd_t * pcd)
  53718. +{
  53719. + int retval;
  53720. + uint32_t fsiz;
  53721. + uint16_t size;
  53722. + uint16_t ep_addr;
  53723. + dwc_otg_pcd_ep_t *ep;
  53724. + dwc_otg_core_params_t *params = GET_CORE_IF(pcd)->core_params;
  53725. + tx_fifo_size_setup_t *ptxfifoval;
  53726. +
  53727. + ptxfifoval = (tx_fifo_size_setup_t *) buf;
  53728. + ep_addr = ptxfifoval->bEndpointAddress;
  53729. + size = ptxfifoval->wDepth;
  53730. +
  53731. + ep = get_ep_by_addr(pcd, ep_addr);
  53732. +
  53733. + CFI_INFO
  53734. + ("%s: Set Tx FIFO size: endpoint addr=0x%02x, depth=%d, FIFO Num=%d\n",
  53735. + __func__, ep_addr, size, ep->dwc_ep.tx_fifo_num);
  53736. +
  53737. + if (NULL == ep) {
  53738. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  53739. + __func__, ep_addr);
  53740. + return -DWC_E_INVALID;
  53741. + }
  53742. +
  53743. + fsiz = params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1];
  53744. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1] = size;
  53745. +
  53746. + if (resize_fifos(GET_CORE_IF(pcd))) {
  53747. + retval = 0;
  53748. + } else {
  53749. + CFI_INFO
  53750. + ("%s: Error setting the feature Tx FIFO Size for EP%d\n",
  53751. + __func__, ep_addr);
  53752. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1] = fsiz;
  53753. + retval = -DWC_E_INVALID;
  53754. + }
  53755. +
  53756. + return retval;
  53757. +}
  53758. +
  53759. +/**
  53760. + * This function sets a new value for the buffer Alignment setup.
  53761. + */
  53762. +static int cfi_set_rx_fifo_val(uint8_t * buf, dwc_otg_pcd_t * pcd)
  53763. +{
  53764. + int retval;
  53765. + uint32_t fsiz;
  53766. + uint16_t size;
  53767. + dwc_otg_core_params_t *params = GET_CORE_IF(pcd)->core_params;
  53768. + rx_fifo_size_setup_t *prxfifoval;
  53769. +
  53770. + prxfifoval = (rx_fifo_size_setup_t *) buf;
  53771. + size = prxfifoval->wDepth;
  53772. +
  53773. + fsiz = params->dev_rx_fifo_size;
  53774. + params->dev_rx_fifo_size = size;
  53775. +
  53776. + if (resize_fifos(GET_CORE_IF(pcd))) {
  53777. + retval = 0;
  53778. + } else {
  53779. + CFI_INFO("%s: Error setting the feature Rx FIFO Size\n",
  53780. + __func__);
  53781. + params->dev_rx_fifo_size = fsiz;
  53782. + retval = -DWC_E_INVALID;
  53783. + }
  53784. +
  53785. + return retval;
  53786. +}
  53787. +
  53788. +/**
  53789. + * This function reads the SG of an EP's buffer setup into the buffer buf
  53790. + */
  53791. +static int cfi_ep_get_sg_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  53792. + struct cfi_usb_ctrlrequest *req)
  53793. +{
  53794. + int retval = -DWC_E_INVALID;
  53795. + uint8_t addr;
  53796. + cfi_ep_t *ep;
  53797. +
  53798. + /* The Low Byte of the wValue contains a non-zero address of the endpoint */
  53799. + addr = req->wValue & 0xFF;
  53800. + if (addr == 0) /* The address should be non-zero */
  53801. + return retval;
  53802. +
  53803. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  53804. + if (NULL == ep) {
  53805. + CFI_INFO("%s: Unable to get the endpoint address(0x%02x)\n",
  53806. + __func__, addr);
  53807. + return retval;
  53808. + }
  53809. +
  53810. + dwc_memcpy(buf, ep->bm_sg, BS_SG_VAL_DESC_LEN);
  53811. + retval = BS_SG_VAL_DESC_LEN;
  53812. + return retval;
  53813. +}
  53814. +
  53815. +/**
  53816. + * This function reads the Concatenation value of an EP's buffer mode into
  53817. + * the buffer buf
  53818. + */
  53819. +static int cfi_ep_get_concat_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  53820. + struct cfi_usb_ctrlrequest *req)
  53821. +{
  53822. + int retval = -DWC_E_INVALID;
  53823. + uint8_t addr;
  53824. + cfi_ep_t *ep;
  53825. + uint8_t desc_count;
  53826. +
  53827. + /* The Low Byte of the wValue contains a non-zero address of the endpoint */
  53828. + addr = req->wValue & 0xFF;
  53829. + if (addr == 0) /* The address should be non-zero */
  53830. + return retval;
  53831. +
  53832. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  53833. + if (NULL == ep) {
  53834. + CFI_INFO("%s: Unable to get the endpoint address(0x%02x)\n",
  53835. + __func__, addr);
  53836. + return retval;
  53837. + }
  53838. +
  53839. + /* Copy the header to the buffer */
  53840. + dwc_memcpy(buf, ep->bm_concat, BS_CONCAT_VAL_HDR_LEN);
  53841. + /* Advance the buffer pointer by the header size */
  53842. + buf += BS_CONCAT_VAL_HDR_LEN;
  53843. +
  53844. + desc_count = ep->bm_concat->hdr.bDescCount;
  53845. + /* Copy alll the wTxBytes to the buffer */
  53846. + dwc_memcpy(buf, ep->bm_concat->wTxBytes, sizeof(uid16_t) * desc_count);
  53847. +
  53848. + retval = BS_CONCAT_VAL_HDR_LEN + sizeof(uid16_t) * desc_count;
  53849. + return retval;
  53850. +}
  53851. +
  53852. +/**
  53853. + * This function reads the buffer Alignment value of an EP's buffer mode into
  53854. + * the buffer buf
  53855. + *
  53856. + * @return The total number of bytes copied to the buffer or negative error code.
  53857. + */
  53858. +static int cfi_ep_get_align_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  53859. + struct cfi_usb_ctrlrequest *req)
  53860. +{
  53861. + int retval = -DWC_E_INVALID;
  53862. + uint8_t addr;
  53863. + cfi_ep_t *ep;
  53864. +
  53865. + /* The Low Byte of the wValue contains a non-zero address of the endpoint */
  53866. + addr = req->wValue & 0xFF;
  53867. + if (addr == 0) /* The address should be non-zero */
  53868. + return retval;
  53869. +
  53870. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  53871. + if (NULL == ep) {
  53872. + CFI_INFO("%s: Unable to get the endpoint address(0x%02x)\n",
  53873. + __func__, addr);
  53874. + return retval;
  53875. + }
  53876. +
  53877. + dwc_memcpy(buf, ep->bm_align, BS_ALIGN_VAL_HDR_LEN);
  53878. + retval = BS_ALIGN_VAL_HDR_LEN;
  53879. +
  53880. + return retval;
  53881. +}
  53882. +
  53883. +/**
  53884. + * This function sets a new value for the specified feature
  53885. + *
  53886. + * @param pcd A pointer to the PCD object
  53887. + *
  53888. + * @return 0 if successful, negative error code otherwise to stall the DCE.
  53889. + */
  53890. +static int cfi_set_feature_value(struct dwc_otg_pcd *pcd)
  53891. +{
  53892. + int retval = -DWC_E_NOT_SUPPORTED;
  53893. + uint16_t wIndex, wValue;
  53894. + uint8_t bRequest;
  53895. + struct dwc_otg_core_if *coreif;
  53896. + cfiobject_t *cfi = pcd->cfi;
  53897. + struct cfi_usb_ctrlrequest *ctrl_req;
  53898. + uint8_t *buf;
  53899. + ctrl_req = &cfi->ctrl_req;
  53900. +
  53901. + buf = pcd->cfi->ctrl_req.data;
  53902. +
  53903. + coreif = GET_CORE_IF(pcd);
  53904. + bRequest = ctrl_req->bRequest;
  53905. + wIndex = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wIndex);
  53906. + wValue = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wValue);
  53907. +
  53908. + /* See which feature is to be modified */
  53909. + switch (wIndex) {
  53910. + case FT_ID_DMA_BUFFER_SETUP:
  53911. + /* Modify the feature */
  53912. + if ((retval = cfi_ep_set_sg_val(buf, pcd)) < 0)
  53913. + return retval;
  53914. +
  53915. + /* And send this request to the gadget */
  53916. + cfi->need_gadget_att = 1;
  53917. + break;
  53918. +
  53919. + case FT_ID_DMA_BUFF_ALIGN:
  53920. + if ((retval = cfi_ep_set_alignment_val(buf, pcd)) < 0)
  53921. + return retval;
  53922. + cfi->need_gadget_att = 1;
  53923. + break;
  53924. +
  53925. + case FT_ID_DMA_CONCAT_SETUP:
  53926. + /* Modify the feature */
  53927. + if ((retval = cfi_ep_set_concat_val(buf, pcd)) < 0)
  53928. + return retval;
  53929. + cfi->need_gadget_att = 1;
  53930. + break;
  53931. +
  53932. + case FT_ID_DMA_CIRCULAR:
  53933. + CFI_INFO("FT_ID_DMA_CIRCULAR\n");
  53934. + break;
  53935. +
  53936. + case FT_ID_THRESHOLD_SETUP:
  53937. + CFI_INFO("FT_ID_THRESHOLD_SETUP\n");
  53938. + break;
  53939. +
  53940. + case FT_ID_DFIFO_DEPTH:
  53941. + CFI_INFO("FT_ID_DFIFO_DEPTH\n");
  53942. + break;
  53943. +
  53944. + case FT_ID_TX_FIFO_DEPTH:
  53945. + CFI_INFO("FT_ID_TX_FIFO_DEPTH\n");
  53946. + if ((retval = cfi_ep_set_tx_fifo_val(buf, pcd)) < 0)
  53947. + return retval;
  53948. + cfi->need_gadget_att = 0;
  53949. + break;
  53950. +
  53951. + case FT_ID_RX_FIFO_DEPTH:
  53952. + CFI_INFO("FT_ID_RX_FIFO_DEPTH\n");
  53953. + if ((retval = cfi_set_rx_fifo_val(buf, pcd)) < 0)
  53954. + return retval;
  53955. + cfi->need_gadget_att = 0;
  53956. + break;
  53957. + }
  53958. +
  53959. + return retval;
  53960. +}
  53961. +
  53962. +#endif //DWC_UTE_CFI
  53963. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_cfi.h linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_cfi.h
  53964. --- linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_cfi.h 1970-01-01 01:00:00.000000000 +0100
  53965. +++ linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_cfi.h 2014-02-17 22:41:01.000000000 +0100
  53966. @@ -0,0 +1,320 @@
  53967. +/* ==========================================================================
  53968. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  53969. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  53970. + * otherwise expressly agreed to in writing between Synopsys and you.
  53971. + *
  53972. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  53973. + * any End User Software License Agreement or Agreement for Licensed Product
  53974. + * with Synopsys or any supplement thereto. You are permitted to use and
  53975. + * redistribute this Software in source and binary forms, with or without
  53976. + * modification, provided that redistributions of source code must retain this
  53977. + * notice. You may not view, use, disclose, copy or distribute this file or
  53978. + * any information contained herein except pursuant to this license grant from
  53979. + * Synopsys. If you do not agree with this notice, including the disclaimer
  53980. + * below, then you are not authorized to use the Software.
  53981. + *
  53982. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  53983. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  53984. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  53985. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  53986. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  53987. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  53988. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  53989. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  53990. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  53991. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  53992. + * DAMAGE.
  53993. + * ========================================================================== */
  53994. +
  53995. +#if !defined(__DWC_OTG_CFI_H__)
  53996. +#define __DWC_OTG_CFI_H__
  53997. +
  53998. +#include "dwc_otg_pcd.h"
  53999. +#include "dwc_cfi_common.h"
  54000. +
  54001. +/**
  54002. + * @file
  54003. + * This file contains the CFI related OTG PCD specific common constants,
  54004. + * interfaces(functions and macros) and data structures.The CFI Protocol is an
  54005. + * optional interface for internal testing purposes that a DUT may implement to
  54006. + * support testing of configurable features.
  54007. + *
  54008. + */
  54009. +
  54010. +struct dwc_otg_pcd;
  54011. +struct dwc_otg_pcd_ep;
  54012. +
  54013. +/** OTG CFI Features (properties) ID constants */
  54014. +/** This is a request for all Core Features */
  54015. +#define FT_ID_DMA_MODE 0x0001
  54016. +#define FT_ID_DMA_BUFFER_SETUP 0x0002
  54017. +#define FT_ID_DMA_BUFF_ALIGN 0x0003
  54018. +#define FT_ID_DMA_CONCAT_SETUP 0x0004
  54019. +#define FT_ID_DMA_CIRCULAR 0x0005
  54020. +#define FT_ID_THRESHOLD_SETUP 0x0006
  54021. +#define FT_ID_DFIFO_DEPTH 0x0007
  54022. +#define FT_ID_TX_FIFO_DEPTH 0x0008
  54023. +#define FT_ID_RX_FIFO_DEPTH 0x0009
  54024. +
  54025. +/**********************************************************/
  54026. +#define CFI_INFO_DEF
  54027. +
  54028. +#ifdef CFI_INFO_DEF
  54029. +#define CFI_INFO(fmt...) DWC_PRINTF("CFI: " fmt);
  54030. +#else
  54031. +#define CFI_INFO(fmt...)
  54032. +#endif
  54033. +
  54034. +#define min(x,y) ({ \
  54035. + x < y ? x : y; })
  54036. +
  54037. +#define max(x,y) ({ \
  54038. + x > y ? x : y; })
  54039. +
  54040. +/**
  54041. + * Descriptor DMA SG Buffer setup structure (SG buffer). This structure is
  54042. + * also used for setting up a buffer for Circular DDMA.
  54043. + */
  54044. +struct _ddma_sg_buffer_setup {
  54045. +#define BS_SG_VAL_DESC_LEN 6
  54046. + /* The OUT EP address */
  54047. + uint8_t bOutEndpointAddress;
  54048. + /* The IN EP address */
  54049. + uint8_t bInEndpointAddress;
  54050. + /* Number of bytes to put between transfer segments (must be DWORD boundaries) */
  54051. + uint8_t bOffset;
  54052. + /* The number of transfer segments (a DMA descriptors per each segment) */
  54053. + uint8_t bCount;
  54054. + /* Size (in byte) of each transfer segment */
  54055. + uint16_t wSize;
  54056. +} __attribute__ ((packed));
  54057. +typedef struct _ddma_sg_buffer_setup ddma_sg_buffer_setup_t;
  54058. +
  54059. +/** Descriptor DMA Concatenation Buffer setup structure */
  54060. +struct _ddma_concat_buffer_setup_hdr {
  54061. +#define BS_CONCAT_VAL_HDR_LEN 4
  54062. + /* The endpoint for which the buffer is to be set up */
  54063. + uint8_t bEndpointAddress;
  54064. + /* The count of descriptors to be used */
  54065. + uint8_t bDescCount;
  54066. + /* The total size of the transfer */
  54067. + uint16_t wSize;
  54068. +} __attribute__ ((packed));
  54069. +typedef struct _ddma_concat_buffer_setup_hdr ddma_concat_buffer_setup_hdr_t;
  54070. +
  54071. +/** Descriptor DMA Concatenation Buffer setup structure */
  54072. +struct _ddma_concat_buffer_setup {
  54073. + /* The SG header */
  54074. + ddma_concat_buffer_setup_hdr_t hdr;
  54075. +
  54076. + /* The XFER sizes pointer (allocated dynamically) */
  54077. + uint16_t *wTxBytes;
  54078. +} __attribute__ ((packed));
  54079. +typedef struct _ddma_concat_buffer_setup ddma_concat_buffer_setup_t;
  54080. +
  54081. +/** Descriptor DMA Alignment Buffer setup structure */
  54082. +struct _ddma_align_buffer_setup {
  54083. +#define BS_ALIGN_VAL_HDR_LEN 2
  54084. + uint8_t bEndpointAddress;
  54085. + uint8_t bAlign;
  54086. +} __attribute__ ((packed));
  54087. +typedef struct _ddma_align_buffer_setup ddma_align_buffer_setup_t;
  54088. +
  54089. +/** Transmit FIFO Size setup structure */
  54090. +struct _tx_fifo_size_setup {
  54091. + uint8_t bEndpointAddress;
  54092. + uint16_t wDepth;
  54093. +} __attribute__ ((packed));
  54094. +typedef struct _tx_fifo_size_setup tx_fifo_size_setup_t;
  54095. +
  54096. +/** Transmit FIFO Size setup structure */
  54097. +struct _rx_fifo_size_setup {
  54098. + uint16_t wDepth;
  54099. +} __attribute__ ((packed));
  54100. +typedef struct _rx_fifo_size_setup rx_fifo_size_setup_t;
  54101. +
  54102. +/**
  54103. + * struct cfi_usb_ctrlrequest - the CFI implementation of the struct usb_ctrlrequest
  54104. + * This structure encapsulates the standard usb_ctrlrequest and adds a pointer
  54105. + * to the data returned in the data stage of a 3-stage Control Write requests.
  54106. + */
  54107. +struct cfi_usb_ctrlrequest {
  54108. + uint8_t bRequestType;
  54109. + uint8_t bRequest;
  54110. + uint16_t wValue;
  54111. + uint16_t wIndex;
  54112. + uint16_t wLength;
  54113. + uint8_t *data;
  54114. +} UPACKED;
  54115. +
  54116. +/*---------------------------------------------------------------------------*/
  54117. +
  54118. +/**
  54119. + * The CFI wrapper of the enabled and activated dwc_otg_pcd_ep structures.
  54120. + * This structure is used to store the buffer setup data for any
  54121. + * enabled endpoint in the PCD.
  54122. + */
  54123. +struct cfi_ep {
  54124. + /* Entry for the list container */
  54125. + dwc_list_link_t lh;
  54126. + /* Pointer to the active PCD endpoint structure */
  54127. + struct dwc_otg_pcd_ep *ep;
  54128. + /* The last descriptor in the chain of DMA descriptors of the endpoint */
  54129. + struct dwc_otg_dma_desc *dma_desc_last;
  54130. + /* The SG feature value */
  54131. + ddma_sg_buffer_setup_t *bm_sg;
  54132. + /* The Circular feature value */
  54133. + ddma_sg_buffer_setup_t *bm_circ;
  54134. + /* The Concatenation feature value */
  54135. + ddma_concat_buffer_setup_t *bm_concat;
  54136. + /* The Alignment feature value */
  54137. + ddma_align_buffer_setup_t *bm_align;
  54138. + /* XFER length */
  54139. + uint32_t xfer_len;
  54140. + /*
  54141. + * Count of DMA descriptors currently used.
  54142. + * The total should not exceed the MAX_DMA_DESCS_PER_EP value
  54143. + * defined in the dwc_otg_cil.h
  54144. + */
  54145. + uint32_t desc_count;
  54146. +};
  54147. +typedef struct cfi_ep cfi_ep_t;
  54148. +
  54149. +typedef struct cfi_dma_buff {
  54150. +#define CFI_IN_BUF_LEN 1024
  54151. +#define CFI_OUT_BUF_LEN 1024
  54152. + dma_addr_t addr;
  54153. + uint8_t *buf;
  54154. +} cfi_dma_buff_t;
  54155. +
  54156. +struct cfiobject;
  54157. +
  54158. +/**
  54159. + * This is the interface for the CFI operations.
  54160. + *
  54161. + * @param ep_enable Called when any endpoint is enabled and activated.
  54162. + * @param release Called when the CFI object is released and it needs to correctly
  54163. + * deallocate the dynamic memory
  54164. + * @param ctrl_write_complete Called when the data stage of the request is complete
  54165. + */
  54166. +typedef struct cfi_ops {
  54167. + int (*ep_enable) (struct cfiobject * cfi, struct dwc_otg_pcd * pcd,
  54168. + struct dwc_otg_pcd_ep * ep);
  54169. + void *(*ep_alloc_buf) (struct cfiobject * cfi, struct dwc_otg_pcd * pcd,
  54170. + struct dwc_otg_pcd_ep * ep, dma_addr_t * dma,
  54171. + unsigned size, gfp_t flags);
  54172. + void (*release) (struct cfiobject * cfi);
  54173. + int (*ctrl_write_complete) (struct cfiobject * cfi,
  54174. + struct dwc_otg_pcd * pcd);
  54175. + void (*build_descriptors) (struct cfiobject * cfi,
  54176. + struct dwc_otg_pcd * pcd,
  54177. + struct dwc_otg_pcd_ep * ep,
  54178. + dwc_otg_pcd_request_t * req);
  54179. +} cfi_ops_t;
  54180. +
  54181. +struct cfiobject {
  54182. + cfi_ops_t ops;
  54183. + struct dwc_otg_pcd *pcd;
  54184. + struct usb_gadget *gadget;
  54185. +
  54186. + /* Buffers used to send/receive CFI-related request data */
  54187. + cfi_dma_buff_t buf_in;
  54188. + cfi_dma_buff_t buf_out;
  54189. +
  54190. + /* CFI specific Control request wrapper */
  54191. + struct cfi_usb_ctrlrequest ctrl_req;
  54192. +
  54193. + /* The list of active EP's in the PCD of type cfi_ep_t */
  54194. + dwc_list_link_t active_eps;
  54195. +
  54196. + /* This flag shall control the propagation of a specific request
  54197. + * to the gadget's processing routines.
  54198. + * 0 - no gadget handling
  54199. + * 1 - the gadget needs to know about this request (w/o completing a status
  54200. + * phase - just return a 0 to the _setup callback)
  54201. + */
  54202. + uint8_t need_gadget_att;
  54203. +
  54204. + /* Flag indicating whether the status IN phase needs to be
  54205. + * completed by the PCD
  54206. + */
  54207. + uint8_t need_status_in_complete;
  54208. +};
  54209. +typedef struct cfiobject cfiobject_t;
  54210. +
  54211. +#define DUMP_MSG
  54212. +
  54213. +#if defined(DUMP_MSG)
  54214. +static inline void dump_msg(const u8 * buf, unsigned int length)
  54215. +{
  54216. + unsigned int start, num, i;
  54217. + char line[52], *p;
  54218. +
  54219. + if (length >= 512)
  54220. + return;
  54221. +
  54222. + start = 0;
  54223. + while (length > 0) {
  54224. + num = min(length, 16u);
  54225. + p = line;
  54226. + for (i = 0; i < num; ++i) {
  54227. + if (i == 8)
  54228. + *p++ = ' ';
  54229. + DWC_SPRINTF(p, " %02x", buf[i]);
  54230. + p += 3;
  54231. + }
  54232. + *p = 0;
  54233. + DWC_DEBUG("%6x: %s\n", start, line);
  54234. + buf += num;
  54235. + start += num;
  54236. + length -= num;
  54237. + }
  54238. +}
  54239. +#else
  54240. +static inline void dump_msg(const u8 * buf, unsigned int length)
  54241. +{
  54242. +}
  54243. +#endif
  54244. +
  54245. +/**
  54246. + * This function returns a pointer to cfi_ep_t object with the addr address.
  54247. + */
  54248. +static inline struct cfi_ep *get_cfi_ep_by_addr(struct cfiobject *cfi,
  54249. + uint8_t addr)
  54250. +{
  54251. + struct cfi_ep *pcfiep;
  54252. + dwc_list_link_t *tmp;
  54253. +
  54254. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  54255. + pcfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  54256. +
  54257. + if (pcfiep->ep->desc->bEndpointAddress == addr) {
  54258. + return pcfiep;
  54259. + }
  54260. + }
  54261. +
  54262. + return NULL;
  54263. +}
  54264. +
  54265. +/**
  54266. + * This function returns a pointer to cfi_ep_t object that matches
  54267. + * the dwc_otg_pcd_ep object.
  54268. + */
  54269. +static inline struct cfi_ep *get_cfi_ep_by_pcd_ep(struct cfiobject *cfi,
  54270. + struct dwc_otg_pcd_ep *ep)
  54271. +{
  54272. + struct cfi_ep *pcfiep = NULL;
  54273. + dwc_list_link_t *tmp;
  54274. +
  54275. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  54276. + pcfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  54277. + if (pcfiep->ep == ep) {
  54278. + return pcfiep;
  54279. + }
  54280. + }
  54281. + return NULL;
  54282. +}
  54283. +
  54284. +int cfi_setup(struct dwc_otg_pcd *pcd, struct cfi_usb_ctrlrequest *ctrl);
  54285. +
  54286. +#endif /* (__DWC_OTG_CFI_H__) */
  54287. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_cil.c linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_cil.c
  54288. --- linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_cil.c 1970-01-01 01:00:00.000000000 +0100
  54289. +++ linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_cil.c 2014-02-17 22:41:01.000000000 +0100
  54290. @@ -0,0 +1,7151 @@
  54291. +/* ==========================================================================
  54292. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil.c $
  54293. + * $Revision: #191 $
  54294. + * $Date: 2012/08/10 $
  54295. + * $Change: 2047372 $
  54296. + *
  54297. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  54298. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  54299. + * otherwise expressly agreed to in writing between Synopsys and you.
  54300. + *
  54301. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  54302. + * any End User Software License Agreement or Agreement for Licensed Product
  54303. + * with Synopsys or any supplement thereto. You are permitted to use and
  54304. + * redistribute this Software in source and binary forms, with or without
  54305. + * modification, provided that redistributions of source code must retain this
  54306. + * notice. You may not view, use, disclose, copy or distribute this file or
  54307. + * any information contained herein except pursuant to this license grant from
  54308. + * Synopsys. If you do not agree with this notice, including the disclaimer
  54309. + * below, then you are not authorized to use the Software.
  54310. + *
  54311. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  54312. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  54313. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  54314. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  54315. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  54316. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  54317. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  54318. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  54319. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  54320. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  54321. + * DAMAGE.
  54322. + * ========================================================================== */
  54323. +
  54324. +/** @file
  54325. + *
  54326. + * The Core Interface Layer provides basic services for accessing and
  54327. + * managing the DWC_otg hardware. These services are used by both the
  54328. + * Host Controller Driver and the Peripheral Controller Driver.
  54329. + *
  54330. + * The CIL manages the memory map for the core so that the HCD and PCD
  54331. + * don't have to do this separately. It also handles basic tasks like
  54332. + * reading/writing the registers and data FIFOs in the controller.
  54333. + * Some of the data access functions provide encapsulation of several
  54334. + * operations required to perform a task, such as writing multiple
  54335. + * registers to start a transfer. Finally, the CIL performs basic
  54336. + * services that are not specific to either the host or device modes
  54337. + * of operation. These services include management of the OTG Host
  54338. + * Negotiation Protocol (HNP) and Session Request Protocol (SRP). A
  54339. + * Diagnostic API is also provided to allow testing of the controller
  54340. + * hardware.
  54341. + *
  54342. + * The Core Interface Layer has the following requirements:
  54343. + * - Provides basic controller operations.
  54344. + * - Minimal use of OS services.
  54345. + * - The OS services used will be abstracted by using inline functions
  54346. + * or macros.
  54347. + *
  54348. + */
  54349. +
  54350. +#include "dwc_os.h"
  54351. +#include "dwc_otg_regs.h"
  54352. +#include "dwc_otg_cil.h"
  54353. +
  54354. +static int dwc_otg_setup_params(dwc_otg_core_if_t * core_if);
  54355. +
  54356. +/**
  54357. + * This function is called to initialize the DWC_otg CSR data
  54358. + * structures. The register addresses in the device and host
  54359. + * structures are initialized from the base address supplied by the
  54360. + * caller. The calling function must make the OS calls to get the
  54361. + * base address of the DWC_otg controller registers. The core_params
  54362. + * argument holds the parameters that specify how the core should be
  54363. + * configured.
  54364. + *
  54365. + * @param reg_base_addr Base address of DWC_otg core registers
  54366. + *
  54367. + */
  54368. +dwc_otg_core_if_t *dwc_otg_cil_init(const uint32_t * reg_base_addr)
  54369. +{
  54370. + dwc_otg_core_if_t *core_if = 0;
  54371. + dwc_otg_dev_if_t *dev_if = 0;
  54372. + dwc_otg_host_if_t *host_if = 0;
  54373. + uint8_t *reg_base = (uint8_t *) reg_base_addr;
  54374. + int i = 0;
  54375. +
  54376. + DWC_DEBUGPL(DBG_CILV, "%s(%p)\n", __func__, reg_base_addr);
  54377. +
  54378. + core_if = DWC_ALLOC(sizeof(dwc_otg_core_if_t));
  54379. +
  54380. + if (core_if == NULL) {
  54381. + DWC_DEBUGPL(DBG_CIL,
  54382. + "Allocation of dwc_otg_core_if_t failed\n");
  54383. + return 0;
  54384. + }
  54385. + core_if->core_global_regs = (dwc_otg_core_global_regs_t *) reg_base;
  54386. +
  54387. + /*
  54388. + * Allocate the Device Mode structures.
  54389. + */
  54390. + dev_if = DWC_ALLOC(sizeof(dwc_otg_dev_if_t));
  54391. +
  54392. + if (dev_if == NULL) {
  54393. + DWC_DEBUGPL(DBG_CIL, "Allocation of dwc_otg_dev_if_t failed\n");
  54394. + DWC_FREE(core_if);
  54395. + return 0;
  54396. + }
  54397. +
  54398. + dev_if->dev_global_regs =
  54399. + (dwc_otg_device_global_regs_t *) (reg_base +
  54400. + DWC_DEV_GLOBAL_REG_OFFSET);
  54401. +
  54402. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  54403. + dev_if->in_ep_regs[i] = (dwc_otg_dev_in_ep_regs_t *)
  54404. + (reg_base + DWC_DEV_IN_EP_REG_OFFSET +
  54405. + (i * DWC_EP_REG_OFFSET));
  54406. +
  54407. + dev_if->out_ep_regs[i] = (dwc_otg_dev_out_ep_regs_t *)
  54408. + (reg_base + DWC_DEV_OUT_EP_REG_OFFSET +
  54409. + (i * DWC_EP_REG_OFFSET));
  54410. + DWC_DEBUGPL(DBG_CILV, "in_ep_regs[%d]->diepctl=%p\n",
  54411. + i, &dev_if->in_ep_regs[i]->diepctl);
  54412. + DWC_DEBUGPL(DBG_CILV, "out_ep_regs[%d]->doepctl=%p\n",
  54413. + i, &dev_if->out_ep_regs[i]->doepctl);
  54414. + }
  54415. +
  54416. + dev_if->speed = 0; // unknown
  54417. +
  54418. + core_if->dev_if = dev_if;
  54419. +
  54420. + /*
  54421. + * Allocate the Host Mode structures.
  54422. + */
  54423. + host_if = DWC_ALLOC(sizeof(dwc_otg_host_if_t));
  54424. +
  54425. + if (host_if == NULL) {
  54426. + DWC_DEBUGPL(DBG_CIL,
  54427. + "Allocation of dwc_otg_host_if_t failed\n");
  54428. + DWC_FREE(dev_if);
  54429. + DWC_FREE(core_if);
  54430. + return 0;
  54431. + }
  54432. +
  54433. + host_if->host_global_regs = (dwc_otg_host_global_regs_t *)
  54434. + (reg_base + DWC_OTG_HOST_GLOBAL_REG_OFFSET);
  54435. +
  54436. + host_if->hprt0 =
  54437. + (uint32_t *) (reg_base + DWC_OTG_HOST_PORT_REGS_OFFSET);
  54438. +
  54439. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  54440. + host_if->hc_regs[i] = (dwc_otg_hc_regs_t *)
  54441. + (reg_base + DWC_OTG_HOST_CHAN_REGS_OFFSET +
  54442. + (i * DWC_OTG_CHAN_REGS_OFFSET));
  54443. + DWC_DEBUGPL(DBG_CILV, "hc_reg[%d]->hcchar=%p\n",
  54444. + i, &host_if->hc_regs[i]->hcchar);
  54445. + }
  54446. +
  54447. + host_if->num_host_channels = MAX_EPS_CHANNELS;
  54448. + core_if->host_if = host_if;
  54449. +
  54450. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  54451. + core_if->data_fifo[i] =
  54452. + (uint32_t *) (reg_base + DWC_OTG_DATA_FIFO_OFFSET +
  54453. + (i * DWC_OTG_DATA_FIFO_SIZE));
  54454. + DWC_DEBUGPL(DBG_CILV, "data_fifo[%d]=0x%08lx\n",
  54455. + i, (unsigned long)core_if->data_fifo[i]);
  54456. + }
  54457. +
  54458. + core_if->pcgcctl = (uint32_t *) (reg_base + DWC_OTG_PCGCCTL_OFFSET);
  54459. +
  54460. + /* Initiate lx_state to L3 disconnected state */
  54461. + core_if->lx_state = DWC_OTG_L3;
  54462. + /*
  54463. + * Store the contents of the hardware configuration registers here for
  54464. + * easy access later.
  54465. + */
  54466. + core_if->hwcfg1.d32 =
  54467. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg1);
  54468. + core_if->hwcfg2.d32 =
  54469. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg2);
  54470. + core_if->hwcfg3.d32 =
  54471. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg3);
  54472. + core_if->hwcfg4.d32 =
  54473. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg4);
  54474. +
  54475. + /* Force host mode to get HPTXFSIZ exact power on value */
  54476. + {
  54477. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  54478. + gusbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  54479. + gusbcfg.b.force_host_mode = 1;
  54480. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gusbcfg.d32);
  54481. + dwc_mdelay(100);
  54482. + core_if->hptxfsiz.d32 =
  54483. + DWC_READ_REG32(&core_if->core_global_regs->hptxfsiz);
  54484. + gusbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  54485. + gusbcfg.b.force_host_mode = 0;
  54486. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gusbcfg.d32);
  54487. + dwc_mdelay(100);
  54488. + }
  54489. +
  54490. + DWC_DEBUGPL(DBG_CILV, "hwcfg1=%08x\n", core_if->hwcfg1.d32);
  54491. + DWC_DEBUGPL(DBG_CILV, "hwcfg2=%08x\n", core_if->hwcfg2.d32);
  54492. + DWC_DEBUGPL(DBG_CILV, "hwcfg3=%08x\n", core_if->hwcfg3.d32);
  54493. + DWC_DEBUGPL(DBG_CILV, "hwcfg4=%08x\n", core_if->hwcfg4.d32);
  54494. +
  54495. + core_if->hcfg.d32 =
  54496. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  54497. + core_if->dcfg.d32 =
  54498. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  54499. +
  54500. + DWC_DEBUGPL(DBG_CILV, "hcfg=%08x\n", core_if->hcfg.d32);
  54501. + DWC_DEBUGPL(DBG_CILV, "dcfg=%08x\n", core_if->dcfg.d32);
  54502. +
  54503. + DWC_DEBUGPL(DBG_CILV, "op_mode=%0x\n", core_if->hwcfg2.b.op_mode);
  54504. + DWC_DEBUGPL(DBG_CILV, "arch=%0x\n", core_if->hwcfg2.b.architecture);
  54505. + DWC_DEBUGPL(DBG_CILV, "num_dev_ep=%d\n", core_if->hwcfg2.b.num_dev_ep);
  54506. + DWC_DEBUGPL(DBG_CILV, "num_host_chan=%d\n",
  54507. + core_if->hwcfg2.b.num_host_chan);
  54508. + DWC_DEBUGPL(DBG_CILV, "nonperio_tx_q_depth=0x%0x\n",
  54509. + core_if->hwcfg2.b.nonperio_tx_q_depth);
  54510. + DWC_DEBUGPL(DBG_CILV, "host_perio_tx_q_depth=0x%0x\n",
  54511. + core_if->hwcfg2.b.host_perio_tx_q_depth);
  54512. + DWC_DEBUGPL(DBG_CILV, "dev_token_q_depth=0x%0x\n",
  54513. + core_if->hwcfg2.b.dev_token_q_depth);
  54514. +
  54515. + DWC_DEBUGPL(DBG_CILV, "Total FIFO SZ=%d\n",
  54516. + core_if->hwcfg3.b.dfifo_depth);
  54517. + DWC_DEBUGPL(DBG_CILV, "xfer_size_cntr_width=%0x\n",
  54518. + core_if->hwcfg3.b.xfer_size_cntr_width);
  54519. +
  54520. + /*
  54521. + * Set the SRP sucess bit for FS-I2c
  54522. + */
  54523. + core_if->srp_success = 0;
  54524. + core_if->srp_timer_started = 0;
  54525. +
  54526. + /*
  54527. + * Create new workqueue and init works
  54528. + */
  54529. + core_if->wq_otg = DWC_WORKQ_ALLOC("dwc_otg");
  54530. + if (core_if->wq_otg == 0) {
  54531. + DWC_WARN("DWC_WORKQ_ALLOC failed\n");
  54532. + DWC_FREE(host_if);
  54533. + DWC_FREE(dev_if);
  54534. + DWC_FREE(core_if);
  54535. + return 0;
  54536. + }
  54537. +
  54538. + core_if->snpsid = DWC_READ_REG32(&core_if->core_global_regs->gsnpsid);
  54539. +
  54540. + DWC_PRINTF("Core Release: %x.%x%x%x\n",
  54541. + (core_if->snpsid >> 12 & 0xF),
  54542. + (core_if->snpsid >> 8 & 0xF),
  54543. + (core_if->snpsid >> 4 & 0xF), (core_if->snpsid & 0xF));
  54544. +
  54545. + core_if->wkp_timer = DWC_TIMER_ALLOC("Wake Up Timer",
  54546. + w_wakeup_detected, core_if);
  54547. + if (core_if->wkp_timer == 0) {
  54548. + DWC_WARN("DWC_TIMER_ALLOC failed\n");
  54549. + DWC_FREE(host_if);
  54550. + DWC_FREE(dev_if);
  54551. + DWC_WORKQ_FREE(core_if->wq_otg);
  54552. + DWC_FREE(core_if);
  54553. + return 0;
  54554. + }
  54555. +
  54556. + if (dwc_otg_setup_params(core_if)) {
  54557. + DWC_WARN("Error while setting core params\n");
  54558. + }
  54559. +
  54560. + core_if->hibernation_suspend = 0;
  54561. +
  54562. + /** ADP initialization */
  54563. + dwc_otg_adp_init(core_if);
  54564. +
  54565. + return core_if;
  54566. +}
  54567. +
  54568. +/**
  54569. + * This function frees the structures allocated by dwc_otg_cil_init().
  54570. + *
  54571. + * @param core_if The core interface pointer returned from
  54572. + * dwc_otg_cil_init().
  54573. + *
  54574. + */
  54575. +void dwc_otg_cil_remove(dwc_otg_core_if_t * core_if)
  54576. +{
  54577. + dctl_data_t dctl = {.d32 = 0 };
  54578. + DWC_DEBUGPL(DBG_CILV, "%s(%p)\n", __func__, core_if);
  54579. +
  54580. + /* Disable all interrupts */
  54581. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, 1, 0);
  54582. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, 0);
  54583. +
  54584. + dctl.b.sftdiscon = 1;
  54585. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  54586. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0,
  54587. + dctl.d32);
  54588. + }
  54589. +
  54590. + if (core_if->wq_otg) {
  54591. + DWC_WORKQ_WAIT_WORK_DONE(core_if->wq_otg, 500);
  54592. + DWC_WORKQ_FREE(core_if->wq_otg);
  54593. + }
  54594. + if (core_if->dev_if) {
  54595. + DWC_FREE(core_if->dev_if);
  54596. + }
  54597. + if (core_if->host_if) {
  54598. + DWC_FREE(core_if->host_if);
  54599. + }
  54600. +
  54601. + /** Remove ADP Stuff */
  54602. + dwc_otg_adp_remove(core_if);
  54603. + if (core_if->core_params) {
  54604. + DWC_FREE(core_if->core_params);
  54605. + }
  54606. + if (core_if->wkp_timer) {
  54607. + DWC_TIMER_FREE(core_if->wkp_timer);
  54608. + }
  54609. + if (core_if->srp_timer) {
  54610. + DWC_TIMER_FREE(core_if->srp_timer);
  54611. + }
  54612. + DWC_FREE(core_if);
  54613. +}
  54614. +
  54615. +/**
  54616. + * This function enables the controller's Global Interrupt in the AHB Config
  54617. + * register.
  54618. + *
  54619. + * @param core_if Programming view of DWC_otg controller.
  54620. + */
  54621. +void dwc_otg_enable_global_interrupts(dwc_otg_core_if_t * core_if)
  54622. +{
  54623. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  54624. + ahbcfg.b.glblintrmsk = 1; /* Enable interrupts */
  54625. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, 0, ahbcfg.d32);
  54626. +}
  54627. +
  54628. +/**
  54629. + * This function disables the controller's Global Interrupt in the AHB Config
  54630. + * register.
  54631. + *
  54632. + * @param core_if Programming view of DWC_otg controller.
  54633. + */
  54634. +void dwc_otg_disable_global_interrupts(dwc_otg_core_if_t * core_if)
  54635. +{
  54636. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  54637. + ahbcfg.b.glblintrmsk = 1; /* Disable interrupts */
  54638. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, ahbcfg.d32, 0);
  54639. +}
  54640. +
  54641. +/**
  54642. + * This function initializes the commmon interrupts, used in both
  54643. + * device and host modes.
  54644. + *
  54645. + * @param core_if Programming view of the DWC_otg controller
  54646. + *
  54647. + */
  54648. +static void dwc_otg_enable_common_interrupts(dwc_otg_core_if_t * core_if)
  54649. +{
  54650. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  54651. + gintmsk_data_t intr_mask = {.d32 = 0 };
  54652. +
  54653. + /* Clear any pending OTG Interrupts */
  54654. + DWC_WRITE_REG32(&global_regs->gotgint, 0xFFFFFFFF);
  54655. +
  54656. + /* Clear any pending interrupts */
  54657. + DWC_WRITE_REG32(&global_regs->gintsts, 0xFFFFFFFF);
  54658. +
  54659. + /*
  54660. + * Enable the interrupts in the GINTMSK.
  54661. + */
  54662. + intr_mask.b.modemismatch = 1;
  54663. + intr_mask.b.otgintr = 1;
  54664. +
  54665. + if (!core_if->dma_enable) {
  54666. + intr_mask.b.rxstsqlvl = 1;
  54667. + }
  54668. +
  54669. + intr_mask.b.conidstschng = 1;
  54670. + intr_mask.b.wkupintr = 1;
  54671. + intr_mask.b.disconnect = 0;
  54672. + intr_mask.b.usbsuspend = 1;
  54673. + intr_mask.b.sessreqintr = 1;
  54674. +#ifdef CONFIG_USB_DWC_OTG_LPM
  54675. + if (core_if->core_params->lpm_enable) {
  54676. + intr_mask.b.lpmtranrcvd = 1;
  54677. + }
  54678. +#endif
  54679. + DWC_WRITE_REG32(&global_regs->gintmsk, intr_mask.d32);
  54680. +}
  54681. +
  54682. +/*
  54683. + * The restore operation is modified to support Synopsys Emulated Powerdown and
  54684. + * Hibernation. This function is for exiting from Device mode hibernation by
  54685. + * Host Initiated Resume/Reset and Device Initiated Remote-Wakeup.
  54686. + * @param core_if Programming view of DWC_otg controller.
  54687. + * @param rem_wakeup - indicates whether resume is initiated by Device or Host.
  54688. + * @param reset - indicates whether resume is initiated by Reset.
  54689. + */
  54690. +int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
  54691. + int rem_wakeup, int reset)
  54692. +{
  54693. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  54694. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  54695. + dctl_data_t dctl = {.d32 = 0 };
  54696. +
  54697. + int timeout = 2000;
  54698. +
  54699. + if (!core_if->hibernation_suspend) {
  54700. + DWC_PRINTF("Already exited from Hibernation\n");
  54701. + return 1;
  54702. + }
  54703. +
  54704. + DWC_DEBUGPL(DBG_PCD, "%s called\n", __FUNCTION__);
  54705. + /* Switch-on voltage to the core */
  54706. + gpwrdn.b.pwrdnswtch = 1;
  54707. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  54708. + dwc_udelay(10);
  54709. +
  54710. + /* Reset core */
  54711. + gpwrdn.d32 = 0;
  54712. + gpwrdn.b.pwrdnrstn = 1;
  54713. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  54714. + dwc_udelay(10);
  54715. +
  54716. + /* Assert Restore signal */
  54717. + gpwrdn.d32 = 0;
  54718. + gpwrdn.b.restore = 1;
  54719. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  54720. + dwc_udelay(10);
  54721. +
  54722. + /* Disable power clamps */
  54723. + gpwrdn.d32 = 0;
  54724. + gpwrdn.b.pwrdnclmp = 1;
  54725. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  54726. +
  54727. + if (rem_wakeup) {
  54728. + dwc_udelay(70);
  54729. + }
  54730. +
  54731. + /* Deassert Reset core */
  54732. + gpwrdn.d32 = 0;
  54733. + gpwrdn.b.pwrdnrstn = 1;
  54734. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  54735. + dwc_udelay(10);
  54736. +
  54737. + /* Disable PMU interrupt */
  54738. + gpwrdn.d32 = 0;
  54739. + gpwrdn.b.pmuintsel = 1;
  54740. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  54741. +
  54742. + /* Mask interrupts from gpwrdn */
  54743. + gpwrdn.d32 = 0;
  54744. + gpwrdn.b.connect_det_msk = 1;
  54745. + gpwrdn.b.srp_det_msk = 1;
  54746. + gpwrdn.b.disconn_det_msk = 1;
  54747. + gpwrdn.b.rst_det_msk = 1;
  54748. + gpwrdn.b.lnstchng_msk = 1;
  54749. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  54750. +
  54751. + /* Indicates that we are going out from hibernation */
  54752. + core_if->hibernation_suspend = 0;
  54753. +
  54754. + /*
  54755. + * Set Restore Essential Regs bit in PCGCCTL register, restore_mode = 1
  54756. + * indicates restore from remote_wakeup
  54757. + */
  54758. + restore_essential_regs(core_if, rem_wakeup, 0);
  54759. +
  54760. + /*
  54761. + * Wait a little for seeing new value of variable hibernation_suspend if
  54762. + * Restore done interrupt received before polling
  54763. + */
  54764. + dwc_udelay(10);
  54765. +
  54766. + if (core_if->hibernation_suspend == 0) {
  54767. + /*
  54768. + * Wait For Restore_done Interrupt. This mechanism of polling the
  54769. + * interrupt is introduced to avoid any possible race conditions
  54770. + */
  54771. + do {
  54772. + gintsts_data_t gintsts;
  54773. + gintsts.d32 =
  54774. + DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  54775. + if (gintsts.b.restoredone) {
  54776. + gintsts.d32 = 0;
  54777. + gintsts.b.restoredone = 1;
  54778. + DWC_WRITE_REG32(&core_if->core_global_regs->
  54779. + gintsts, gintsts.d32);
  54780. + DWC_PRINTF("Restore Done Interrupt seen\n");
  54781. + break;
  54782. + }
  54783. + dwc_udelay(10);
  54784. + } while (--timeout);
  54785. + if (!timeout) {
  54786. + DWC_PRINTF("Restore Done interrupt wasn't generated here\n");
  54787. + }
  54788. + }
  54789. + /* Clear all pending interupts */
  54790. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  54791. +
  54792. + /* De-assert Restore */
  54793. + gpwrdn.d32 = 0;
  54794. + gpwrdn.b.restore = 1;
  54795. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  54796. + dwc_udelay(10);
  54797. +
  54798. + if (!rem_wakeup) {
  54799. + pcgcctl.d32 = 0;
  54800. + pcgcctl.b.rstpdwnmodule = 1;
  54801. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  54802. + }
  54803. +
  54804. + /* Restore GUSBCFG and DCFG */
  54805. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg,
  54806. + core_if->gr_backup->gusbcfg_local);
  54807. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg,
  54808. + core_if->dr_backup->dcfg);
  54809. +
  54810. + /* De-assert Wakeup Logic */
  54811. + gpwrdn.d32 = 0;
  54812. + gpwrdn.b.pmuactv = 1;
  54813. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  54814. + dwc_udelay(10);
  54815. +
  54816. + if (!rem_wakeup) {
  54817. + /* Set Device programming done bit */
  54818. + dctl.b.pwronprgdone = 1;
  54819. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  54820. + } else {
  54821. + /* Start Remote Wakeup Signaling */
  54822. + dctl.d32 = core_if->dr_backup->dctl;
  54823. + dctl.b.rmtwkupsig = 1;
  54824. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  54825. + }
  54826. +
  54827. + dwc_mdelay(2);
  54828. + /* Clear all pending interupts */
  54829. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  54830. +
  54831. + /* Restore global registers */
  54832. + dwc_otg_restore_global_regs(core_if);
  54833. + /* Restore device global registers */
  54834. + dwc_otg_restore_dev_regs(core_if, rem_wakeup);
  54835. +
  54836. + if (rem_wakeup) {
  54837. + dwc_mdelay(7);
  54838. + dctl.d32 = 0;
  54839. + dctl.b.rmtwkupsig = 1;
  54840. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, 0);
  54841. + }
  54842. +
  54843. + core_if->hibernation_suspend = 0;
  54844. + /* The core will be in ON STATE */
  54845. + core_if->lx_state = DWC_OTG_L0;
  54846. + DWC_PRINTF("Hibernation recovery completes here\n");
  54847. +
  54848. + return 1;
  54849. +}
  54850. +
  54851. +/*
  54852. + * The restore operation is modified to support Synopsys Emulated Powerdown and
  54853. + * Hibernation. This function is for exiting from Host mode hibernation by
  54854. + * Host Initiated Resume/Reset and Device Initiated Remote-Wakeup.
  54855. + * @param core_if Programming view of DWC_otg controller.
  54856. + * @param rem_wakeup - indicates whether resume is initiated by Device or Host.
  54857. + * @param reset - indicates whether resume is initiated by Reset.
  54858. + */
  54859. +int dwc_otg_host_hibernation_restore(dwc_otg_core_if_t * core_if,
  54860. + int rem_wakeup, int reset)
  54861. +{
  54862. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  54863. + hprt0_data_t hprt0 = {.d32 = 0 };
  54864. +
  54865. + int timeout = 2000;
  54866. +
  54867. + DWC_DEBUGPL(DBG_HCD, "%s called\n", __FUNCTION__);
  54868. + /* Switch-on voltage to the core */
  54869. + gpwrdn.b.pwrdnswtch = 1;
  54870. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  54871. + dwc_udelay(10);
  54872. +
  54873. + /* Reset core */
  54874. + gpwrdn.d32 = 0;
  54875. + gpwrdn.b.pwrdnrstn = 1;
  54876. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  54877. + dwc_udelay(10);
  54878. +
  54879. + /* Assert Restore signal */
  54880. + gpwrdn.d32 = 0;
  54881. + gpwrdn.b.restore = 1;
  54882. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  54883. + dwc_udelay(10);
  54884. +
  54885. + /* Disable power clamps */
  54886. + gpwrdn.d32 = 0;
  54887. + gpwrdn.b.pwrdnclmp = 1;
  54888. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  54889. +
  54890. + if (!rem_wakeup) {
  54891. + dwc_udelay(50);
  54892. + }
  54893. +
  54894. + /* Deassert Reset core */
  54895. + gpwrdn.d32 = 0;
  54896. + gpwrdn.b.pwrdnrstn = 1;
  54897. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  54898. + dwc_udelay(10);
  54899. +
  54900. + /* Disable PMU interrupt */
  54901. + gpwrdn.d32 = 0;
  54902. + gpwrdn.b.pmuintsel = 1;
  54903. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  54904. +
  54905. + gpwrdn.d32 = 0;
  54906. + gpwrdn.b.connect_det_msk = 1;
  54907. + gpwrdn.b.srp_det_msk = 1;
  54908. + gpwrdn.b.disconn_det_msk = 1;
  54909. + gpwrdn.b.rst_det_msk = 1;
  54910. + gpwrdn.b.lnstchng_msk = 1;
  54911. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  54912. +
  54913. + /* Indicates that we are going out from hibernation */
  54914. + core_if->hibernation_suspend = 0;
  54915. +
  54916. + /* Set Restore Essential Regs bit in PCGCCTL register */
  54917. + restore_essential_regs(core_if, rem_wakeup, 1);
  54918. +
  54919. + /* Wait a little for seeing new value of variable hibernation_suspend if
  54920. + * Restore done interrupt received before polling */
  54921. + dwc_udelay(10);
  54922. +
  54923. + if (core_if->hibernation_suspend == 0) {
  54924. + /* Wait For Restore_done Interrupt. This mechanism of polling the
  54925. + * interrupt is introduced to avoid any possible race conditions
  54926. + */
  54927. + do {
  54928. + gintsts_data_t gintsts;
  54929. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  54930. + if (gintsts.b.restoredone) {
  54931. + gintsts.d32 = 0;
  54932. + gintsts.b.restoredone = 1;
  54933. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  54934. + DWC_DEBUGPL(DBG_HCD,"Restore Done Interrupt seen\n");
  54935. + break;
  54936. + }
  54937. + dwc_udelay(10);
  54938. + } while (--timeout);
  54939. + if (!timeout) {
  54940. + DWC_WARN("Restore Done interrupt wasn't generated\n");
  54941. + }
  54942. + }
  54943. +
  54944. + /* Set the flag's value to 0 again after receiving restore done interrupt */
  54945. + core_if->hibernation_suspend = 0;
  54946. +
  54947. + /* This step is not described in functional spec but if not wait for this
  54948. + * delay, mismatch interrupts occurred because just after restore core is
  54949. + * in Device mode(gintsts.curmode == 0) */
  54950. + dwc_mdelay(100);
  54951. +
  54952. + /* Clear all pending interrupts */
  54953. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  54954. +
  54955. + /* De-assert Restore */
  54956. + gpwrdn.d32 = 0;
  54957. + gpwrdn.b.restore = 1;
  54958. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  54959. + dwc_udelay(10);
  54960. +
  54961. + /* Restore GUSBCFG and HCFG */
  54962. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg,
  54963. + core_if->gr_backup->gusbcfg_local);
  54964. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg,
  54965. + core_if->hr_backup->hcfg_local);
  54966. +
  54967. + /* De-assert Wakeup Logic */
  54968. + gpwrdn.d32 = 0;
  54969. + gpwrdn.b.pmuactv = 1;
  54970. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  54971. + dwc_udelay(10);
  54972. +
  54973. + /* Start the Resume operation by programming HPRT0 */
  54974. + hprt0.d32 = core_if->hr_backup->hprt0_local;
  54975. + hprt0.b.prtpwr = 1;
  54976. + hprt0.b.prtena = 0;
  54977. + hprt0.b.prtsusp = 0;
  54978. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  54979. +
  54980. + DWC_PRINTF("Resume Starts Now\n");
  54981. + if (!reset) { // Indicates it is Resume Operation
  54982. + hprt0.d32 = core_if->hr_backup->hprt0_local;
  54983. + hprt0.b.prtres = 1;
  54984. + hprt0.b.prtpwr = 1;
  54985. + hprt0.b.prtena = 0;
  54986. + hprt0.b.prtsusp = 0;
  54987. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  54988. +
  54989. + if (!rem_wakeup)
  54990. + hprt0.b.prtres = 0;
  54991. + /* Wait for Resume time and then program HPRT again */
  54992. + dwc_mdelay(100);
  54993. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  54994. +
  54995. + } else { // Indicates it is Reset Operation
  54996. + hprt0.d32 = core_if->hr_backup->hprt0_local;
  54997. + hprt0.b.prtrst = 1;
  54998. + hprt0.b.prtpwr = 1;
  54999. + hprt0.b.prtena = 0;
  55000. + hprt0.b.prtsusp = 0;
  55001. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  55002. + /* Wait for Reset time and then program HPRT again */
  55003. + dwc_mdelay(60);
  55004. + hprt0.b.prtrst = 0;
  55005. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  55006. + }
  55007. + /* Clear all interrupt status */
  55008. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  55009. + hprt0.b.prtconndet = 1;
  55010. + hprt0.b.prtenchng = 1;
  55011. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  55012. +
  55013. + /* Clear all pending interupts */
  55014. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  55015. +
  55016. + /* Restore global registers */
  55017. + dwc_otg_restore_global_regs(core_if);
  55018. + /* Restore host global registers */
  55019. + dwc_otg_restore_host_regs(core_if, reset);
  55020. +
  55021. + /* The core will be in ON STATE */
  55022. + core_if->lx_state = DWC_OTG_L0;
  55023. + DWC_PRINTF("Hibernation recovery is complete here\n");
  55024. + return 0;
  55025. +}
  55026. +
  55027. +/** Saves some register values into system memory. */
  55028. +int dwc_otg_save_global_regs(dwc_otg_core_if_t * core_if)
  55029. +{
  55030. + struct dwc_otg_global_regs_backup *gr;
  55031. + int i;
  55032. +
  55033. + gr = core_if->gr_backup;
  55034. + if (!gr) {
  55035. + gr = DWC_ALLOC(sizeof(*gr));
  55036. + if (!gr) {
  55037. + return -DWC_E_NO_MEMORY;
  55038. + }
  55039. + core_if->gr_backup = gr;
  55040. + }
  55041. +
  55042. + gr->gotgctl_local = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  55043. + gr->gintmsk_local = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  55044. + gr->gahbcfg_local = DWC_READ_REG32(&core_if->core_global_regs->gahbcfg);
  55045. + gr->gusbcfg_local = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  55046. + gr->grxfsiz_local = DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  55047. + gr->gnptxfsiz_local = DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz);
  55048. + gr->hptxfsiz_local = DWC_READ_REG32(&core_if->core_global_regs->hptxfsiz);
  55049. +#ifdef CONFIG_USB_DWC_OTG_LPM
  55050. + gr->glpmcfg_local = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  55051. +#endif
  55052. + gr->gi2cctl_local = DWC_READ_REG32(&core_if->core_global_regs->gi2cctl);
  55053. + gr->pcgcctl_local = DWC_READ_REG32(core_if->pcgcctl);
  55054. + gr->gdfifocfg_local =
  55055. + DWC_READ_REG32(&core_if->core_global_regs->gdfifocfg);
  55056. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  55057. + gr->dtxfsiz_local[i] =
  55058. + DWC_READ_REG32(&(core_if->core_global_regs->dtxfsiz[i]));
  55059. + }
  55060. +
  55061. + DWC_DEBUGPL(DBG_ANY, "===========Backing Global registers==========\n");
  55062. + DWC_DEBUGPL(DBG_ANY, "Backed up gotgctl = %08x\n", gr->gotgctl_local);
  55063. + DWC_DEBUGPL(DBG_ANY, "Backed up gintmsk = %08x\n", gr->gintmsk_local);
  55064. + DWC_DEBUGPL(DBG_ANY, "Backed up gahbcfg = %08x\n", gr->gahbcfg_local);
  55065. + DWC_DEBUGPL(DBG_ANY, "Backed up gusbcfg = %08x\n", gr->gusbcfg_local);
  55066. + DWC_DEBUGPL(DBG_ANY, "Backed up grxfsiz = %08x\n", gr->grxfsiz_local);
  55067. + DWC_DEBUGPL(DBG_ANY, "Backed up gnptxfsiz = %08x\n",
  55068. + gr->gnptxfsiz_local);
  55069. + DWC_DEBUGPL(DBG_ANY, "Backed up hptxfsiz = %08x\n",
  55070. + gr->hptxfsiz_local);
  55071. +#ifdef CONFIG_USB_DWC_OTG_LPM
  55072. + DWC_DEBUGPL(DBG_ANY, "Backed up glpmcfg = %08x\n", gr->glpmcfg_local);
  55073. +#endif
  55074. + DWC_DEBUGPL(DBG_ANY, "Backed up gi2cctl = %08x\n", gr->gi2cctl_local);
  55075. + DWC_DEBUGPL(DBG_ANY, "Backed up pcgcctl = %08x\n", gr->pcgcctl_local);
  55076. + DWC_DEBUGPL(DBG_ANY,"Backed up gdfifocfg = %08x\n",gr->gdfifocfg_local);
  55077. +
  55078. + return 0;
  55079. +}
  55080. +
  55081. +/** Saves GINTMSK register before setting the msk bits. */
  55082. +int dwc_otg_save_gintmsk_reg(dwc_otg_core_if_t * core_if)
  55083. +{
  55084. + struct dwc_otg_global_regs_backup *gr;
  55085. +
  55086. + gr = core_if->gr_backup;
  55087. + if (!gr) {
  55088. + gr = DWC_ALLOC(sizeof(*gr));
  55089. + if (!gr) {
  55090. + return -DWC_E_NO_MEMORY;
  55091. + }
  55092. + core_if->gr_backup = gr;
  55093. + }
  55094. +
  55095. + gr->gintmsk_local = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  55096. +
  55097. + DWC_DEBUGPL(DBG_ANY,"=============Backing GINTMSK registers============\n");
  55098. + DWC_DEBUGPL(DBG_ANY, "Backed up gintmsk = %08x\n", gr->gintmsk_local);
  55099. +
  55100. + return 0;
  55101. +}
  55102. +
  55103. +int dwc_otg_save_dev_regs(dwc_otg_core_if_t * core_if)
  55104. +{
  55105. + struct dwc_otg_dev_regs_backup *dr;
  55106. + int i;
  55107. +
  55108. + dr = core_if->dr_backup;
  55109. + if (!dr) {
  55110. + dr = DWC_ALLOC(sizeof(*dr));
  55111. + if (!dr) {
  55112. + return -DWC_E_NO_MEMORY;
  55113. + }
  55114. + core_if->dr_backup = dr;
  55115. + }
  55116. +
  55117. + dr->dcfg = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  55118. + dr->dctl = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  55119. + dr->daintmsk =
  55120. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
  55121. + dr->diepmsk =
  55122. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->diepmsk);
  55123. + dr->doepmsk =
  55124. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->doepmsk);
  55125. +
  55126. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  55127. + dr->diepctl[i] =
  55128. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->diepctl);
  55129. + dr->dieptsiz[i] =
  55130. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->dieptsiz);
  55131. + dr->diepdma[i] =
  55132. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->diepdma);
  55133. + }
  55134. +
  55135. + DWC_DEBUGPL(DBG_ANY,
  55136. + "=============Backing Host registers==============\n");
  55137. + DWC_DEBUGPL(DBG_ANY, "Backed up dcfg = %08x\n", dr->dcfg);
  55138. + DWC_DEBUGPL(DBG_ANY, "Backed up dctl = %08x\n", dr->dctl);
  55139. + DWC_DEBUGPL(DBG_ANY, "Backed up daintmsk = %08x\n",
  55140. + dr->daintmsk);
  55141. + DWC_DEBUGPL(DBG_ANY, "Backed up diepmsk = %08x\n", dr->diepmsk);
  55142. + DWC_DEBUGPL(DBG_ANY, "Backed up doepmsk = %08x\n", dr->doepmsk);
  55143. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  55144. + DWC_DEBUGPL(DBG_ANY, "Backed up diepctl[%d] = %08x\n", i,
  55145. + dr->diepctl[i]);
  55146. + DWC_DEBUGPL(DBG_ANY, "Backed up dieptsiz[%d] = %08x\n",
  55147. + i, dr->dieptsiz[i]);
  55148. + DWC_DEBUGPL(DBG_ANY, "Backed up diepdma[%d] = %08x\n", i,
  55149. + dr->diepdma[i]);
  55150. + }
  55151. +
  55152. + return 0;
  55153. +}
  55154. +
  55155. +int dwc_otg_save_host_regs(dwc_otg_core_if_t * core_if)
  55156. +{
  55157. + struct dwc_otg_host_regs_backup *hr;
  55158. + int i;
  55159. +
  55160. + hr = core_if->hr_backup;
  55161. + if (!hr) {
  55162. + hr = DWC_ALLOC(sizeof(*hr));
  55163. + if (!hr) {
  55164. + return -DWC_E_NO_MEMORY;
  55165. + }
  55166. + core_if->hr_backup = hr;
  55167. + }
  55168. +
  55169. + hr->hcfg_local =
  55170. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  55171. + hr->haintmsk_local =
  55172. + DWC_READ_REG32(&core_if->host_if->host_global_regs->haintmsk);
  55173. + for (i = 0; i < dwc_otg_get_param_host_channels(core_if); ++i) {
  55174. + hr->hcintmsk_local[i] =
  55175. + DWC_READ_REG32(&core_if->host_if->hc_regs[i]->hcintmsk);
  55176. + }
  55177. + hr->hprt0_local = DWC_READ_REG32(core_if->host_if->hprt0);
  55178. + hr->hfir_local =
  55179. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hfir);
  55180. +
  55181. + DWC_DEBUGPL(DBG_ANY,
  55182. + "=============Backing Host registers===============\n");
  55183. + DWC_DEBUGPL(DBG_ANY, "Backed up hcfg = %08x\n",
  55184. + hr->hcfg_local);
  55185. + DWC_DEBUGPL(DBG_ANY, "Backed up haintmsk = %08x\n", hr->haintmsk_local);
  55186. + for (i = 0; i < dwc_otg_get_param_host_channels(core_if); ++i) {
  55187. + DWC_DEBUGPL(DBG_ANY, "Backed up hcintmsk[%02d]=%08x\n", i,
  55188. + hr->hcintmsk_local[i]);
  55189. + }
  55190. + DWC_DEBUGPL(DBG_ANY, "Backed up hprt0 = %08x\n",
  55191. + hr->hprt0_local);
  55192. + DWC_DEBUGPL(DBG_ANY, "Backed up hfir = %08x\n",
  55193. + hr->hfir_local);
  55194. +
  55195. + return 0;
  55196. +}
  55197. +
  55198. +int dwc_otg_restore_global_regs(dwc_otg_core_if_t *core_if)
  55199. +{
  55200. + struct dwc_otg_global_regs_backup *gr;
  55201. + int i;
  55202. +
  55203. + gr = core_if->gr_backup;
  55204. + if (!gr) {
  55205. + return -DWC_E_INVALID;
  55206. + }
  55207. +
  55208. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgctl, gr->gotgctl_local);
  55209. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gr->gintmsk_local);
  55210. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gr->gusbcfg_local);
  55211. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg, gr->gahbcfg_local);
  55212. + DWC_WRITE_REG32(&core_if->core_global_regs->grxfsiz, gr->grxfsiz_local);
  55213. + DWC_WRITE_REG32(&core_if->core_global_regs->gnptxfsiz,
  55214. + gr->gnptxfsiz_local);
  55215. + DWC_WRITE_REG32(&core_if->core_global_regs->hptxfsiz,
  55216. + gr->hptxfsiz_local);
  55217. + DWC_WRITE_REG32(&core_if->core_global_regs->gdfifocfg,
  55218. + gr->gdfifocfg_local);
  55219. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  55220. + DWC_WRITE_REG32(&core_if->core_global_regs->dtxfsiz[i],
  55221. + gr->dtxfsiz_local[i]);
  55222. + }
  55223. +
  55224. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  55225. + DWC_WRITE_REG32(core_if->host_if->hprt0, 0x0000100A);
  55226. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg,
  55227. + (gr->gahbcfg_local));
  55228. + return 0;
  55229. +}
  55230. +
  55231. +int dwc_otg_restore_dev_regs(dwc_otg_core_if_t * core_if, int rem_wakeup)
  55232. +{
  55233. + struct dwc_otg_dev_regs_backup *dr;
  55234. + int i;
  55235. +
  55236. + dr = core_if->dr_backup;
  55237. +
  55238. + if (!dr) {
  55239. + return -DWC_E_INVALID;
  55240. + }
  55241. +
  55242. + if (!rem_wakeup) {
  55243. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl,
  55244. + dr->dctl);
  55245. + }
  55246. +
  55247. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->daintmsk, dr->daintmsk);
  55248. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->diepmsk, dr->diepmsk);
  55249. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->doepmsk, dr->doepmsk);
  55250. +
  55251. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  55252. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->dieptsiz, dr->dieptsiz[i]);
  55253. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->diepdma, dr->diepdma[i]);
  55254. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->diepctl, dr->diepctl[i]);
  55255. + }
  55256. +
  55257. + return 0;
  55258. +}
  55259. +
  55260. +int dwc_otg_restore_host_regs(dwc_otg_core_if_t * core_if, int reset)
  55261. +{
  55262. + struct dwc_otg_host_regs_backup *hr;
  55263. + int i;
  55264. + hr = core_if->hr_backup;
  55265. +
  55266. + if (!hr) {
  55267. + return -DWC_E_INVALID;
  55268. + }
  55269. +
  55270. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg, hr->hcfg_local);
  55271. + //if (!reset)
  55272. + //{
  55273. + // DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hfir, hr->hfir_local);
  55274. + //}
  55275. +
  55276. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->haintmsk,
  55277. + hr->haintmsk_local);
  55278. + for (i = 0; i < dwc_otg_get_param_host_channels(core_if); ++i) {
  55279. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[i]->hcintmsk,
  55280. + hr->hcintmsk_local[i]);
  55281. + }
  55282. +
  55283. + return 0;
  55284. +}
  55285. +
  55286. +int restore_lpm_i2c_regs(dwc_otg_core_if_t * core_if)
  55287. +{
  55288. + struct dwc_otg_global_regs_backup *gr;
  55289. +
  55290. + gr = core_if->gr_backup;
  55291. +
  55292. + /* Restore values for LPM and I2C */
  55293. +#ifdef CONFIG_USB_DWC_OTG_LPM
  55294. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, gr->glpmcfg_local);
  55295. +#endif
  55296. + DWC_WRITE_REG32(&core_if->core_global_regs->gi2cctl, gr->gi2cctl_local);
  55297. +
  55298. + return 0;
  55299. +}
  55300. +
  55301. +int restore_essential_regs(dwc_otg_core_if_t * core_if, int rmode, int is_host)
  55302. +{
  55303. + struct dwc_otg_global_regs_backup *gr;
  55304. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  55305. + gahbcfg_data_t gahbcfg = {.d32 = 0 };
  55306. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  55307. + gintmsk_data_t gintmsk = {.d32 = 0 };
  55308. +
  55309. + /* Restore LPM and I2C registers */
  55310. + restore_lpm_i2c_regs(core_if);
  55311. +
  55312. + /* Set PCGCCTL to 0 */
  55313. + DWC_WRITE_REG32(core_if->pcgcctl, 0x00000000);
  55314. +
  55315. + gr = core_if->gr_backup;
  55316. + /* Load restore values for [31:14] bits */
  55317. + DWC_WRITE_REG32(core_if->pcgcctl,
  55318. + ((gr->pcgcctl_local & 0xffffc000) | 0x00020000));
  55319. +
  55320. + /* Umnask global Interrupt in GAHBCFG and restore it */
  55321. + gahbcfg.d32 = gr->gahbcfg_local;
  55322. + gahbcfg.b.glblintrmsk = 1;
  55323. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg, gahbcfg.d32);
  55324. +
  55325. + /* Clear all pending interupts */
  55326. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  55327. +
  55328. + /* Unmask restore done interrupt */
  55329. + gintmsk.b.restoredone = 1;
  55330. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32);
  55331. +
  55332. + /* Restore GUSBCFG and HCFG/DCFG */
  55333. + gusbcfg.d32 = core_if->gr_backup->gusbcfg_local;
  55334. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gusbcfg.d32);
  55335. +
  55336. + if (is_host) {
  55337. + hcfg_data_t hcfg = {.d32 = 0 };
  55338. + hcfg.d32 = core_if->hr_backup->hcfg_local;
  55339. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg,
  55340. + hcfg.d32);
  55341. +
  55342. + /* Load restore values for [31:14] bits */
  55343. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  55344. + pcgcctl.d32 = gr->pcgcctl_local | 0x00020000;
  55345. +
  55346. + if (rmode)
  55347. + pcgcctl.b.restoremode = 1;
  55348. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  55349. + dwc_udelay(10);
  55350. +
  55351. + /* Load restore values for [31:14] bits and set EssRegRestored bit */
  55352. + pcgcctl.d32 = gr->pcgcctl_local | 0xffffc000;
  55353. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  55354. + pcgcctl.b.ess_reg_restored = 1;
  55355. + if (rmode)
  55356. + pcgcctl.b.restoremode = 1;
  55357. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  55358. + } else {
  55359. + dcfg_data_t dcfg = {.d32 = 0 };
  55360. + dcfg.d32 = core_if->dr_backup->dcfg;
  55361. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
  55362. +
  55363. + /* Load restore values for [31:14] bits */
  55364. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  55365. + pcgcctl.d32 = gr->pcgcctl_local | 0x00020000;
  55366. + if (!rmode) {
  55367. + pcgcctl.d32 |= 0x208;
  55368. + }
  55369. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  55370. + dwc_udelay(10);
  55371. +
  55372. + /* Load restore values for [31:14] bits */
  55373. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  55374. + pcgcctl.d32 = gr->pcgcctl_local | 0x00020000;
  55375. + pcgcctl.b.ess_reg_restored = 1;
  55376. + if (!rmode)
  55377. + pcgcctl.d32 |= 0x208;
  55378. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  55379. + }
  55380. +
  55381. + return 0;
  55382. +}
  55383. +
  55384. +/**
  55385. + * Initializes the FSLSPClkSel field of the HCFG register depending on the PHY
  55386. + * type.
  55387. + */
  55388. +static void init_fslspclksel(dwc_otg_core_if_t * core_if)
  55389. +{
  55390. + uint32_t val;
  55391. + hcfg_data_t hcfg;
  55392. +
  55393. + if (((core_if->hwcfg2.b.hs_phy_type == 2) &&
  55394. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  55395. + (core_if->core_params->ulpi_fs_ls)) ||
  55396. + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
  55397. + /* Full speed PHY */
  55398. + val = DWC_HCFG_48_MHZ;
  55399. + } else {
  55400. + /* High speed PHY running at full speed or high speed */
  55401. + val = DWC_HCFG_30_60_MHZ;
  55402. + }
  55403. +
  55404. + DWC_DEBUGPL(DBG_CIL, "Initializing HCFG.FSLSPClkSel to 0x%1x\n", val);
  55405. + hcfg.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  55406. + hcfg.b.fslspclksel = val;
  55407. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  55408. +}
  55409. +
  55410. +/**
  55411. + * Initializes the DevSpd field of the DCFG register depending on the PHY type
  55412. + * and the enumeration speed of the device.
  55413. + */
  55414. +static void init_devspd(dwc_otg_core_if_t * core_if)
  55415. +{
  55416. + uint32_t val;
  55417. + dcfg_data_t dcfg;
  55418. +
  55419. + if (((core_if->hwcfg2.b.hs_phy_type == 2) &&
  55420. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  55421. + (core_if->core_params->ulpi_fs_ls)) ||
  55422. + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
  55423. + /* Full speed PHY */
  55424. + val = 0x3;
  55425. + } else if (core_if->core_params->speed == DWC_SPEED_PARAM_FULL) {
  55426. + /* High speed PHY running at full speed */
  55427. + val = 0x1;
  55428. + } else {
  55429. + /* High speed PHY running at high speed */
  55430. + val = 0x0;
  55431. + }
  55432. +
  55433. + DWC_DEBUGPL(DBG_CIL, "Initializing DCFG.DevSpd to 0x%1x\n", val);
  55434. +
  55435. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  55436. + dcfg.b.devspd = val;
  55437. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
  55438. +}
  55439. +
  55440. +/**
  55441. + * This function calculates the number of IN EPS
  55442. + * using GHWCFG1 and GHWCFG2 registers values
  55443. + *
  55444. + * @param core_if Programming view of the DWC_otg controller
  55445. + */
  55446. +static uint32_t calc_num_in_eps(dwc_otg_core_if_t * core_if)
  55447. +{
  55448. + uint32_t num_in_eps = 0;
  55449. + uint32_t num_eps = core_if->hwcfg2.b.num_dev_ep;
  55450. + uint32_t hwcfg1 = core_if->hwcfg1.d32 >> 3;
  55451. + uint32_t num_tx_fifos = core_if->hwcfg4.b.num_in_eps;
  55452. + int i;
  55453. +
  55454. + for (i = 0; i < num_eps; ++i) {
  55455. + if (!(hwcfg1 & 0x1))
  55456. + num_in_eps++;
  55457. +
  55458. + hwcfg1 >>= 2;
  55459. + }
  55460. +
  55461. + if (core_if->hwcfg4.b.ded_fifo_en) {
  55462. + num_in_eps =
  55463. + (num_in_eps > num_tx_fifos) ? num_tx_fifos : num_in_eps;
  55464. + }
  55465. +
  55466. + return num_in_eps;
  55467. +}
  55468. +
  55469. +/**
  55470. + * This function calculates the number of OUT EPS
  55471. + * using GHWCFG1 and GHWCFG2 registers values
  55472. + *
  55473. + * @param core_if Programming view of the DWC_otg controller
  55474. + */
  55475. +static uint32_t calc_num_out_eps(dwc_otg_core_if_t * core_if)
  55476. +{
  55477. + uint32_t num_out_eps = 0;
  55478. + uint32_t num_eps = core_if->hwcfg2.b.num_dev_ep;
  55479. + uint32_t hwcfg1 = core_if->hwcfg1.d32 >> 2;
  55480. + int i;
  55481. +
  55482. + for (i = 0; i < num_eps; ++i) {
  55483. + if (!(hwcfg1 & 0x1))
  55484. + num_out_eps++;
  55485. +
  55486. + hwcfg1 >>= 2;
  55487. + }
  55488. + return num_out_eps;
  55489. +}
  55490. +
  55491. +/**
  55492. + * This function initializes the DWC_otg controller registers and
  55493. + * prepares the core for device mode or host mode operation.
  55494. + *
  55495. + * @param core_if Programming view of the DWC_otg controller
  55496. + *
  55497. + */
  55498. +void dwc_otg_core_init(dwc_otg_core_if_t * core_if)
  55499. +{
  55500. + int i = 0;
  55501. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  55502. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  55503. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  55504. + gusbcfg_data_t usbcfg = {.d32 = 0 };
  55505. + gi2cctl_data_t i2cctl = {.d32 = 0 };
  55506. +
  55507. + DWC_DEBUGPL(DBG_CILV, "dwc_otg_core_init(%p) regs at %p\n",
  55508. + core_if, global_regs);
  55509. +
  55510. + /* Common Initialization */
  55511. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  55512. +
  55513. + /* Program the ULPI External VBUS bit if needed */
  55514. + usbcfg.b.ulpi_ext_vbus_drv =
  55515. + (core_if->core_params->phy_ulpi_ext_vbus ==
  55516. + DWC_PHY_ULPI_EXTERNAL_VBUS) ? 1 : 0;
  55517. +
  55518. + /* Set external TS Dline pulsing */
  55519. + usbcfg.b.term_sel_dl_pulse =
  55520. + (core_if->core_params->ts_dline == 1) ? 1 : 0;
  55521. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  55522. +
  55523. + /* Reset the Controller */
  55524. + dwc_otg_core_reset(core_if);
  55525. +
  55526. + core_if->adp_enable = core_if->core_params->adp_supp_enable;
  55527. + core_if->power_down = core_if->core_params->power_down;
  55528. + core_if->otg_sts = 0;
  55529. +
  55530. + /* Initialize parameters from Hardware configuration registers. */
  55531. + dev_if->num_in_eps = calc_num_in_eps(core_if);
  55532. + dev_if->num_out_eps = calc_num_out_eps(core_if);
  55533. +
  55534. + DWC_DEBUGPL(DBG_CIL, "num_dev_perio_in_ep=%d\n",
  55535. + core_if->hwcfg4.b.num_dev_perio_in_ep);
  55536. +
  55537. + for (i = 0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; i++) {
  55538. + dev_if->perio_tx_fifo_size[i] =
  55539. + DWC_READ_REG32(&global_regs->dtxfsiz[i]) >> 16;
  55540. + DWC_DEBUGPL(DBG_CIL, "Periodic Tx FIFO SZ #%d=0x%0x\n",
  55541. + i, dev_if->perio_tx_fifo_size[i]);
  55542. + }
  55543. +
  55544. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  55545. + dev_if->tx_fifo_size[i] =
  55546. + DWC_READ_REG32(&global_regs->dtxfsiz[i]) >> 16;
  55547. + DWC_DEBUGPL(DBG_CIL, "Tx FIFO SZ #%d=0x%0x\n",
  55548. + i, dev_if->tx_fifo_size[i]);
  55549. + }
  55550. +
  55551. + core_if->total_fifo_size = core_if->hwcfg3.b.dfifo_depth;
  55552. + core_if->rx_fifo_size = DWC_READ_REG32(&global_regs->grxfsiz);
  55553. + core_if->nperio_tx_fifo_size =
  55554. + DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16;
  55555. +
  55556. + DWC_DEBUGPL(DBG_CIL, "Total FIFO SZ=%d\n", core_if->total_fifo_size);
  55557. + DWC_DEBUGPL(DBG_CIL, "Rx FIFO SZ=%d\n", core_if->rx_fifo_size);
  55558. + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO SZ=%d\n",
  55559. + core_if->nperio_tx_fifo_size);
  55560. +
  55561. + /* This programming sequence needs to happen in FS mode before any other
  55562. + * programming occurs */
  55563. + if ((core_if->core_params->speed == DWC_SPEED_PARAM_FULL) &&
  55564. + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
  55565. + /* If FS mode with FS PHY */
  55566. +
  55567. + /* core_init() is now called on every switch so only call the
  55568. + * following for the first time through. */
  55569. + if (!core_if->phy_init_done) {
  55570. + core_if->phy_init_done = 1;
  55571. + DWC_DEBUGPL(DBG_CIL, "FS_PHY detected\n");
  55572. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  55573. + usbcfg.b.physel = 1;
  55574. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  55575. +
  55576. + /* Reset after a PHY select */
  55577. + dwc_otg_core_reset(core_if);
  55578. + }
  55579. +
  55580. + /* Program DCFG.DevSpd or HCFG.FSLSPclkSel to 48Mhz in FS. Also
  55581. + * do this on HNP Dev/Host mode switches (done in dev_init and
  55582. + * host_init). */
  55583. + if (dwc_otg_is_host_mode(core_if)) {
  55584. + init_fslspclksel(core_if);
  55585. + } else {
  55586. + init_devspd(core_if);
  55587. + }
  55588. +
  55589. + if (core_if->core_params->i2c_enable) {
  55590. + DWC_DEBUGPL(DBG_CIL, "FS_PHY Enabling I2c\n");
  55591. + /* Program GUSBCFG.OtgUtmifsSel to I2C */
  55592. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  55593. + usbcfg.b.otgutmifssel = 1;
  55594. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  55595. +
  55596. + /* Program GI2CCTL.I2CEn */
  55597. + i2cctl.d32 = DWC_READ_REG32(&global_regs->gi2cctl);
  55598. + i2cctl.b.i2cdevaddr = 1;
  55599. + i2cctl.b.i2cen = 0;
  55600. + DWC_WRITE_REG32(&global_regs->gi2cctl, i2cctl.d32);
  55601. + i2cctl.b.i2cen = 1;
  55602. + DWC_WRITE_REG32(&global_regs->gi2cctl, i2cctl.d32);
  55603. + }
  55604. +
  55605. + } /* endif speed == DWC_SPEED_PARAM_FULL */
  55606. + else {
  55607. + /* High speed PHY. */
  55608. + if (!core_if->phy_init_done) {
  55609. + core_if->phy_init_done = 1;
  55610. + /* HS PHY parameters. These parameters are preserved
  55611. + * during soft reset so only program the first time. Do
  55612. + * a soft reset immediately after setting phyif. */
  55613. +
  55614. + if (core_if->core_params->phy_type == 2) {
  55615. + /* ULPI interface */
  55616. + usbcfg.b.ulpi_utmi_sel = 1;
  55617. + usbcfg.b.phyif = 0;
  55618. + usbcfg.b.ddrsel =
  55619. + core_if->core_params->phy_ulpi_ddr;
  55620. + } else if (core_if->core_params->phy_type == 1) {
  55621. + /* UTMI+ interface */
  55622. + usbcfg.b.ulpi_utmi_sel = 0;
  55623. + if (core_if->core_params->phy_utmi_width == 16) {
  55624. + usbcfg.b.phyif = 1;
  55625. +
  55626. + } else {
  55627. + usbcfg.b.phyif = 0;
  55628. + }
  55629. + } else {
  55630. + DWC_ERROR("FS PHY TYPE\n");
  55631. + }
  55632. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  55633. + /* Reset after setting the PHY parameters */
  55634. + dwc_otg_core_reset(core_if);
  55635. + }
  55636. + }
  55637. +
  55638. + if ((core_if->hwcfg2.b.hs_phy_type == 2) &&
  55639. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  55640. + (core_if->core_params->ulpi_fs_ls)) {
  55641. + DWC_DEBUGPL(DBG_CIL, "Setting ULPI FSLS\n");
  55642. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  55643. + usbcfg.b.ulpi_fsls = 1;
  55644. + usbcfg.b.ulpi_clk_sus_m = 1;
  55645. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  55646. + } else {
  55647. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  55648. + usbcfg.b.ulpi_fsls = 0;
  55649. + usbcfg.b.ulpi_clk_sus_m = 0;
  55650. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  55651. + }
  55652. +
  55653. + /* Program the GAHBCFG Register. */
  55654. + switch (core_if->hwcfg2.b.architecture) {
  55655. +
  55656. + case DWC_SLAVE_ONLY_ARCH:
  55657. + DWC_DEBUGPL(DBG_CIL, "Slave Only Mode\n");
  55658. + ahbcfg.b.nptxfemplvl_txfemplvl =
  55659. + DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY;
  55660. + ahbcfg.b.ptxfemplvl = DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY;
  55661. + core_if->dma_enable = 0;
  55662. + core_if->dma_desc_enable = 0;
  55663. + break;
  55664. +
  55665. + case DWC_EXT_DMA_ARCH:
  55666. + DWC_DEBUGPL(DBG_CIL, "External DMA Mode\n");
  55667. + {
  55668. + uint8_t brst_sz = core_if->core_params->dma_burst_size;
  55669. + ahbcfg.b.hburstlen = 0;
  55670. + while (brst_sz > 1) {
  55671. + ahbcfg.b.hburstlen++;
  55672. + brst_sz >>= 1;
  55673. + }
  55674. + }
  55675. + core_if->dma_enable = (core_if->core_params->dma_enable != 0);
  55676. + core_if->dma_desc_enable =
  55677. + (core_if->core_params->dma_desc_enable != 0);
  55678. + break;
  55679. +
  55680. + case DWC_INT_DMA_ARCH:
  55681. + DWC_DEBUGPL(DBG_CIL, "Internal DMA Mode\n");
  55682. + /* Old value was DWC_GAHBCFG_INT_DMA_BURST_INCR - done for
  55683. + Host mode ISOC in issue fix - vahrama */
  55684. + /* Broadcom had altered to (1<<3)|(0<<0) - WRESP=1, max 4 beats */
  55685. + ahbcfg.b.hburstlen = (1<<3)|(0<<0);//DWC_GAHBCFG_INT_DMA_BURST_INCR4;
  55686. + core_if->dma_enable = (core_if->core_params->dma_enable != 0);
  55687. + core_if->dma_desc_enable =
  55688. + (core_if->core_params->dma_desc_enable != 0);
  55689. + break;
  55690. +
  55691. + }
  55692. + if (core_if->dma_enable) {
  55693. + if (core_if->dma_desc_enable) {
  55694. + DWC_PRINTF("Using Descriptor DMA mode\n");
  55695. + } else {
  55696. + DWC_PRINTF("Using Buffer DMA mode\n");
  55697. +
  55698. + }
  55699. + } else {
  55700. + DWC_PRINTF("Using Slave mode\n");
  55701. + core_if->dma_desc_enable = 0;
  55702. + }
  55703. +
  55704. + if (core_if->core_params->ahb_single) {
  55705. + ahbcfg.b.ahbsingle = 1;
  55706. + }
  55707. +
  55708. + ahbcfg.b.dmaenable = core_if->dma_enable;
  55709. + DWC_WRITE_REG32(&global_regs->gahbcfg, ahbcfg.d32);
  55710. +
  55711. + core_if->en_multiple_tx_fifo = core_if->hwcfg4.b.ded_fifo_en;
  55712. +
  55713. + core_if->pti_enh_enable = core_if->core_params->pti_enable != 0;
  55714. + core_if->multiproc_int_enable = core_if->core_params->mpi_enable;
  55715. + DWC_PRINTF("Periodic Transfer Interrupt Enhancement - %s\n",
  55716. + ((core_if->pti_enh_enable) ? "enabled" : "disabled"));
  55717. + DWC_PRINTF("Multiprocessor Interrupt Enhancement - %s\n",
  55718. + ((core_if->multiproc_int_enable) ? "enabled" : "disabled"));
  55719. +
  55720. + /*
  55721. + * Program the GUSBCFG register.
  55722. + */
  55723. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  55724. +
  55725. + switch (core_if->hwcfg2.b.op_mode) {
  55726. + case DWC_MODE_HNP_SRP_CAPABLE:
  55727. + usbcfg.b.hnpcap = (core_if->core_params->otg_cap ==
  55728. + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE);
  55729. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  55730. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  55731. + break;
  55732. +
  55733. + case DWC_MODE_SRP_ONLY_CAPABLE:
  55734. + usbcfg.b.hnpcap = 0;
  55735. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  55736. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  55737. + break;
  55738. +
  55739. + case DWC_MODE_NO_HNP_SRP_CAPABLE:
  55740. + usbcfg.b.hnpcap = 0;
  55741. + usbcfg.b.srpcap = 0;
  55742. + break;
  55743. +
  55744. + case DWC_MODE_SRP_CAPABLE_DEVICE:
  55745. + usbcfg.b.hnpcap = 0;
  55746. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  55747. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  55748. + break;
  55749. +
  55750. + case DWC_MODE_NO_SRP_CAPABLE_DEVICE:
  55751. + usbcfg.b.hnpcap = 0;
  55752. + usbcfg.b.srpcap = 0;
  55753. + break;
  55754. +
  55755. + case DWC_MODE_SRP_CAPABLE_HOST:
  55756. + usbcfg.b.hnpcap = 0;
  55757. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  55758. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  55759. + break;
  55760. +
  55761. + case DWC_MODE_NO_SRP_CAPABLE_HOST:
  55762. + usbcfg.b.hnpcap = 0;
  55763. + usbcfg.b.srpcap = 0;
  55764. + break;
  55765. + }
  55766. +
  55767. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  55768. +
  55769. +#ifdef CONFIG_USB_DWC_OTG_LPM
  55770. + if (core_if->core_params->lpm_enable) {
  55771. + glpmcfg_data_t lpmcfg = {.d32 = 0 };
  55772. +
  55773. + /* To enable LPM support set lpm_cap_en bit */
  55774. + lpmcfg.b.lpm_cap_en = 1;
  55775. +
  55776. + /* Make AppL1Res ACK */
  55777. + lpmcfg.b.appl_resp = 1;
  55778. +
  55779. + /* Retry 3 times */
  55780. + lpmcfg.b.retry_count = 3;
  55781. +
  55782. + DWC_MODIFY_REG32(&core_if->core_global_regs->glpmcfg,
  55783. + 0, lpmcfg.d32);
  55784. +
  55785. + }
  55786. +#endif
  55787. + if (core_if->core_params->ic_usb_cap) {
  55788. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  55789. + gusbcfg.b.ic_usb_cap = 1;
  55790. + DWC_MODIFY_REG32(&core_if->core_global_regs->gusbcfg,
  55791. + 0, gusbcfg.d32);
  55792. + }
  55793. + {
  55794. + gotgctl_data_t gotgctl = {.d32 = 0 };
  55795. + gotgctl.b.otgver = core_if->core_params->otg_ver;
  55796. + DWC_MODIFY_REG32(&core_if->core_global_regs->gotgctl, 0,
  55797. + gotgctl.d32);
  55798. + /* Set OTG version supported */
  55799. + core_if->otg_ver = core_if->core_params->otg_ver;
  55800. + DWC_PRINTF("OTG VER PARAM: %d, OTG VER FLAG: %d\n",
  55801. + core_if->core_params->otg_ver, core_if->otg_ver);
  55802. + }
  55803. +
  55804. +
  55805. + /* Enable common interrupts */
  55806. + dwc_otg_enable_common_interrupts(core_if);
  55807. +
  55808. + /* Do device or host intialization based on mode during PCD
  55809. + * and HCD initialization */
  55810. + if (dwc_otg_is_host_mode(core_if)) {
  55811. + DWC_DEBUGPL(DBG_ANY, "Host Mode\n");
  55812. + core_if->op_state = A_HOST;
  55813. + } else {
  55814. + DWC_DEBUGPL(DBG_ANY, "Device Mode\n");
  55815. + core_if->op_state = B_PERIPHERAL;
  55816. +#ifdef DWC_DEVICE_ONLY
  55817. + dwc_otg_core_dev_init(core_if);
  55818. +#endif
  55819. + }
  55820. +}
  55821. +
  55822. +/**
  55823. + * This function enables the Device mode interrupts.
  55824. + *
  55825. + * @param core_if Programming view of DWC_otg controller
  55826. + */
  55827. +void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t * core_if)
  55828. +{
  55829. + gintmsk_data_t intr_mask = {.d32 = 0 };
  55830. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  55831. +
  55832. + DWC_DEBUGPL(DBG_CIL, "%s()\n", __func__);
  55833. +
  55834. + /* Disable all interrupts. */
  55835. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  55836. +
  55837. + /* Clear any pending interrupts */
  55838. + DWC_WRITE_REG32(&global_regs->gintsts, 0xFFFFFFFF);
  55839. +
  55840. + /* Enable the common interrupts */
  55841. + dwc_otg_enable_common_interrupts(core_if);
  55842. +
  55843. + /* Enable interrupts */
  55844. + intr_mask.b.usbreset = 1;
  55845. + intr_mask.b.enumdone = 1;
  55846. + /* Disable Disconnect interrupt in Device mode */
  55847. + intr_mask.b.disconnect = 0;
  55848. +
  55849. + if (!core_if->multiproc_int_enable) {
  55850. + intr_mask.b.inepintr = 1;
  55851. + intr_mask.b.outepintr = 1;
  55852. + }
  55853. +
  55854. + intr_mask.b.erlysuspend = 1;
  55855. +
  55856. + if (core_if->en_multiple_tx_fifo == 0) {
  55857. + intr_mask.b.epmismatch = 1;
  55858. + }
  55859. +
  55860. + //intr_mask.b.incomplisoout = 1;
  55861. + intr_mask.b.incomplisoin = 1;
  55862. +
  55863. +/* Enable the ignore frame number for ISOC xfers - MAS */
  55864. +/* Disable to support high bandwith ISOC transfers - manukz */
  55865. +#if 0
  55866. +#ifdef DWC_UTE_PER_IO
  55867. + if (core_if->dma_enable) {
  55868. + if (core_if->dma_desc_enable) {
  55869. + dctl_data_t dctl1 = {.d32 = 0 };
  55870. + dctl1.b.ifrmnum = 1;
  55871. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  55872. + dctl, 0, dctl1.d32);
  55873. + DWC_DEBUG("----Enabled Ignore frame number (0x%08x)",
  55874. + DWC_READ_REG32(&core_if->dev_if->
  55875. + dev_global_regs->dctl));
  55876. + }
  55877. + }
  55878. +#endif
  55879. +#endif
  55880. +#ifdef DWC_EN_ISOC
  55881. + if (core_if->dma_enable) {
  55882. + if (core_if->dma_desc_enable == 0) {
  55883. + if (core_if->pti_enh_enable) {
  55884. + dctl_data_t dctl = {.d32 = 0 };
  55885. + dctl.b.ifrmnum = 1;
  55886. + DWC_MODIFY_REG32(&core_if->
  55887. + dev_if->dev_global_regs->dctl,
  55888. + 0, dctl.d32);
  55889. + } else {
  55890. + intr_mask.b.incomplisoin = 1;
  55891. + intr_mask.b.incomplisoout = 1;
  55892. + }
  55893. + }
  55894. + } else {
  55895. + intr_mask.b.incomplisoin = 1;
  55896. + intr_mask.b.incomplisoout = 1;
  55897. + }
  55898. +#endif /* DWC_EN_ISOC */
  55899. +
  55900. + /** @todo NGS: Should this be a module parameter? */
  55901. +#ifdef USE_PERIODIC_EP
  55902. + intr_mask.b.isooutdrop = 1;
  55903. + intr_mask.b.eopframe = 1;
  55904. + intr_mask.b.incomplisoin = 1;
  55905. + intr_mask.b.incomplisoout = 1;
  55906. +#endif
  55907. +
  55908. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
  55909. +
  55910. + DWC_DEBUGPL(DBG_CIL, "%s() gintmsk=%0x\n", __func__,
  55911. + DWC_READ_REG32(&global_regs->gintmsk));
  55912. +}
  55913. +
  55914. +/**
  55915. + * This function initializes the DWC_otg controller registers for
  55916. + * device mode.
  55917. + *
  55918. + * @param core_if Programming view of DWC_otg controller
  55919. + *
  55920. + */
  55921. +void dwc_otg_core_dev_init(dwc_otg_core_if_t * core_if)
  55922. +{
  55923. + int i;
  55924. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  55925. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  55926. + dwc_otg_core_params_t *params = core_if->core_params;
  55927. + dcfg_data_t dcfg = {.d32 = 0 };
  55928. + depctl_data_t diepctl = {.d32 = 0 };
  55929. + grstctl_t resetctl = {.d32 = 0 };
  55930. + uint32_t rx_fifo_size;
  55931. + fifosize_data_t nptxfifosize;
  55932. + fifosize_data_t txfifosize;
  55933. + dthrctl_data_t dthrctl;
  55934. + fifosize_data_t ptxfifosize;
  55935. + uint16_t rxfsiz, nptxfsiz;
  55936. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  55937. + hwcfg3_data_t hwcfg3 = {.d32 = 0 };
  55938. +
  55939. + /* Restart the Phy Clock */
  55940. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  55941. +
  55942. + /* Device configuration register */
  55943. + init_devspd(core_if);
  55944. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  55945. + dcfg.b.descdma = (core_if->dma_desc_enable) ? 1 : 0;
  55946. + dcfg.b.perfrint = DWC_DCFG_FRAME_INTERVAL_80;
  55947. + /* Enable Device OUT NAK in case of DDMA mode*/
  55948. + if (core_if->core_params->dev_out_nak) {
  55949. + dcfg.b.endevoutnak = 1;
  55950. + }
  55951. +
  55952. + if (core_if->core_params->cont_on_bna) {
  55953. + dctl_data_t dctl = {.d32 = 0 };
  55954. + dctl.b.encontonbna = 1;
  55955. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, 0, dctl.d32);
  55956. + }
  55957. +
  55958. +
  55959. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  55960. +
  55961. + /* Configure data FIFO sizes */
  55962. + if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
  55963. + DWC_DEBUGPL(DBG_CIL, "Total FIFO Size=%d\n",
  55964. + core_if->total_fifo_size);
  55965. + DWC_DEBUGPL(DBG_CIL, "Rx FIFO Size=%d\n",
  55966. + params->dev_rx_fifo_size);
  55967. + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO Size=%d\n",
  55968. + params->dev_nperio_tx_fifo_size);
  55969. +
  55970. + /* Rx FIFO */
  55971. + DWC_DEBUGPL(DBG_CIL, "initial grxfsiz=%08x\n",
  55972. + DWC_READ_REG32(&global_regs->grxfsiz));
  55973. +
  55974. +#ifdef DWC_UTE_CFI
  55975. + core_if->pwron_rxfsiz = DWC_READ_REG32(&global_regs->grxfsiz);
  55976. + core_if->init_rxfsiz = params->dev_rx_fifo_size;
  55977. +#endif
  55978. + rx_fifo_size = params->dev_rx_fifo_size;
  55979. + DWC_WRITE_REG32(&global_regs->grxfsiz, rx_fifo_size);
  55980. +
  55981. + DWC_DEBUGPL(DBG_CIL, "new grxfsiz=%08x\n",
  55982. + DWC_READ_REG32(&global_regs->grxfsiz));
  55983. +
  55984. + /** Set Periodic Tx FIFO Mask all bits 0 */
  55985. + core_if->p_tx_msk = 0;
  55986. +
  55987. + /** Set Tx FIFO Mask all bits 0 */
  55988. + core_if->tx_msk = 0;
  55989. +
  55990. + if (core_if->en_multiple_tx_fifo == 0) {
  55991. + /* Non-periodic Tx FIFO */
  55992. + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
  55993. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  55994. +
  55995. + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
  55996. + nptxfifosize.b.startaddr = params->dev_rx_fifo_size;
  55997. +
  55998. + DWC_WRITE_REG32(&global_regs->gnptxfsiz,
  55999. + nptxfifosize.d32);
  56000. +
  56001. + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
  56002. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  56003. +
  56004. + /**@todo NGS: Fix Periodic FIFO Sizing! */
  56005. + /*
  56006. + * Periodic Tx FIFOs These FIFOs are numbered from 1 to 15.
  56007. + * Indexes of the FIFO size module parameters in the
  56008. + * dev_perio_tx_fifo_size array and the FIFO size registers in
  56009. + * the dptxfsiz array run from 0 to 14.
  56010. + */
  56011. + /** @todo Finish debug of this */
  56012. + ptxfifosize.b.startaddr =
  56013. + nptxfifosize.b.startaddr + nptxfifosize.b.depth;
  56014. + for (i = 0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; i++) {
  56015. + ptxfifosize.b.depth =
  56016. + params->dev_perio_tx_fifo_size[i];
  56017. + DWC_DEBUGPL(DBG_CIL,
  56018. + "initial dtxfsiz[%d]=%08x\n", i,
  56019. + DWC_READ_REG32(&global_regs->dtxfsiz
  56020. + [i]));
  56021. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  56022. + ptxfifosize.d32);
  56023. + DWC_DEBUGPL(DBG_CIL, "new dtxfsiz[%d]=%08x\n",
  56024. + i,
  56025. + DWC_READ_REG32(&global_regs->dtxfsiz
  56026. + [i]));
  56027. + ptxfifosize.b.startaddr += ptxfifosize.b.depth;
  56028. + }
  56029. + } else {
  56030. + /*
  56031. + * Tx FIFOs These FIFOs are numbered from 1 to 15.
  56032. + * Indexes of the FIFO size module parameters in the
  56033. + * dev_tx_fifo_size array and the FIFO size registers in
  56034. + * the dtxfsiz array run from 0 to 14.
  56035. + */
  56036. +
  56037. + /* Non-periodic Tx FIFO */
  56038. + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
  56039. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  56040. +
  56041. +#ifdef DWC_UTE_CFI
  56042. + core_if->pwron_gnptxfsiz =
  56043. + (DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16);
  56044. + core_if->init_gnptxfsiz =
  56045. + params->dev_nperio_tx_fifo_size;
  56046. +#endif
  56047. + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
  56048. + nptxfifosize.b.startaddr = params->dev_rx_fifo_size;
  56049. +
  56050. + DWC_WRITE_REG32(&global_regs->gnptxfsiz,
  56051. + nptxfifosize.d32);
  56052. +
  56053. + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
  56054. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  56055. +
  56056. + txfifosize.b.startaddr =
  56057. + nptxfifosize.b.startaddr + nptxfifosize.b.depth;
  56058. +
  56059. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  56060. +
  56061. + txfifosize.b.depth =
  56062. + params->dev_tx_fifo_size[i];
  56063. +
  56064. + DWC_DEBUGPL(DBG_CIL,
  56065. + "initial dtxfsiz[%d]=%08x\n",
  56066. + i,
  56067. + DWC_READ_REG32(&global_regs->dtxfsiz
  56068. + [i]));
  56069. +
  56070. +#ifdef DWC_UTE_CFI
  56071. + core_if->pwron_txfsiz[i] =
  56072. + (DWC_READ_REG32
  56073. + (&global_regs->dtxfsiz[i]) >> 16);
  56074. + core_if->init_txfsiz[i] =
  56075. + params->dev_tx_fifo_size[i];
  56076. +#endif
  56077. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  56078. + txfifosize.d32);
  56079. +
  56080. + DWC_DEBUGPL(DBG_CIL,
  56081. + "new dtxfsiz[%d]=%08x\n",
  56082. + i,
  56083. + DWC_READ_REG32(&global_regs->dtxfsiz
  56084. + [i]));
  56085. +
  56086. + txfifosize.b.startaddr += txfifosize.b.depth;
  56087. + }
  56088. + if (core_if->snpsid <= OTG_CORE_REV_2_94a) {
  56089. + /* Calculating DFIFOCFG for Device mode to include RxFIFO and NPTXFIFO */
  56090. + gdfifocfg.d32 = DWC_READ_REG32(&global_regs->gdfifocfg);
  56091. + hwcfg3.d32 = DWC_READ_REG32(&global_regs->ghwcfg3);
  56092. + gdfifocfg.b.gdfifocfg = (DWC_READ_REG32(&global_regs->ghwcfg3) >> 16);
  56093. + DWC_WRITE_REG32(&global_regs->gdfifocfg, gdfifocfg.d32);
  56094. + rxfsiz = (DWC_READ_REG32(&global_regs->grxfsiz) & 0x0000ffff);
  56095. + nptxfsiz = (DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16);
  56096. + gdfifocfg.b.epinfobase = rxfsiz + nptxfsiz;
  56097. + DWC_WRITE_REG32(&global_regs->gdfifocfg, gdfifocfg.d32);
  56098. + }
  56099. + }
  56100. +
  56101. + /* Flush the FIFOs */
  56102. + dwc_otg_flush_tx_fifo(core_if, 0x10); /* all Tx FIFOs */
  56103. + dwc_otg_flush_rx_fifo(core_if);
  56104. +
  56105. + /* Flush the Learning Queue. */
  56106. + resetctl.b.intknqflsh = 1;
  56107. + DWC_WRITE_REG32(&core_if->core_global_regs->grstctl, resetctl.d32);
  56108. +
  56109. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable) {
  56110. + core_if->start_predict = 0;
  56111. + for (i = 0; i<= core_if->dev_if->num_in_eps; ++i) {
  56112. + core_if->nextep_seq[i] = 0xff; // 0xff - EP not active
  56113. + }
  56114. + core_if->nextep_seq[0] = 0;
  56115. + core_if->first_in_nextep_seq = 0;
  56116. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl);
  56117. + diepctl.b.nextep = 0;
  56118. + DWC_WRITE_REG32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
  56119. +
  56120. + /* Update IN Endpoint Mismatch Count by active IN NP EP count + 1 */
  56121. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  56122. + dcfg.b.epmscnt = 2;
  56123. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  56124. +
  56125. + DWC_DEBUGPL(DBG_CILV,"%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  56126. + __func__, core_if->first_in_nextep_seq);
  56127. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  56128. + DWC_DEBUGPL(DBG_CILV, "%2d ", core_if->nextep_seq[i]);
  56129. + }
  56130. + DWC_DEBUGPL(DBG_CILV,"\n");
  56131. + }
  56132. +
  56133. + /* Clear all pending Device Interrupts */
  56134. + /** @todo - if the condition needed to be checked
  56135. + * or in any case all pending interrutps should be cleared?
  56136. + */
  56137. + if (core_if->multiproc_int_enable) {
  56138. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  56139. + DWC_WRITE_REG32(&dev_if->
  56140. + dev_global_regs->diepeachintmsk[i], 0);
  56141. + }
  56142. + }
  56143. +
  56144. + for (i = 0; i < core_if->dev_if->num_out_eps; ++i) {
  56145. + DWC_WRITE_REG32(&dev_if->
  56146. + dev_global_regs->doepeachintmsk[i], 0);
  56147. + }
  56148. +
  56149. + DWC_WRITE_REG32(&dev_if->dev_global_regs->deachint, 0xFFFFFFFF);
  56150. + DWC_WRITE_REG32(&dev_if->dev_global_regs->deachintmsk, 0);
  56151. + } else {
  56152. + DWC_WRITE_REG32(&dev_if->dev_global_regs->diepmsk, 0);
  56153. + DWC_WRITE_REG32(&dev_if->dev_global_regs->doepmsk, 0);
  56154. + DWC_WRITE_REG32(&dev_if->dev_global_regs->daint, 0xFFFFFFFF);
  56155. + DWC_WRITE_REG32(&dev_if->dev_global_regs->daintmsk, 0);
  56156. + }
  56157. +
  56158. + for (i = 0; i <= dev_if->num_in_eps; i++) {
  56159. + depctl_data_t depctl;
  56160. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  56161. + if (depctl.b.epena) {
  56162. + depctl.d32 = 0;
  56163. + depctl.b.epdis = 1;
  56164. + depctl.b.snak = 1;
  56165. + } else {
  56166. + depctl.d32 = 0;
  56167. + }
  56168. +
  56169. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32);
  56170. +
  56171. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->dieptsiz, 0);
  56172. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepdma, 0);
  56173. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepint, 0xFF);
  56174. + }
  56175. +
  56176. + for (i = 0; i <= dev_if->num_out_eps; i++) {
  56177. + depctl_data_t depctl;
  56178. + depctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[i]->doepctl);
  56179. + if (depctl.b.epena) {
  56180. + dctl_data_t dctl = {.d32 = 0 };
  56181. + gintmsk_data_t gintsts = {.d32 = 0 };
  56182. + doepint_data_t doepint = {.d32 = 0 };
  56183. + dctl.b.sgoutnak = 1;
  56184. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  56185. + do {
  56186. + dwc_udelay(10);
  56187. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  56188. + } while (!gintsts.b.goutnakeff);
  56189. + gintsts.d32 = 0;
  56190. + gintsts.b.goutnakeff = 1;
  56191. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  56192. +
  56193. + depctl.d32 = 0;
  56194. + depctl.b.epdis = 1;
  56195. + depctl.b.snak = 1;
  56196. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->doepctl, depctl.d32);
  56197. + do {
  56198. + dwc_udelay(10);
  56199. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  56200. + out_ep_regs[i]->doepint);
  56201. + } while (!doepint.b.epdisabled);
  56202. +
  56203. + doepint.b.epdisabled = 1;
  56204. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->doepint, doepint.d32);
  56205. +
  56206. + dctl.d32 = 0;
  56207. + dctl.b.cgoutnak = 1;
  56208. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  56209. + } else {
  56210. + depctl.d32 = 0;
  56211. + }
  56212. +
  56213. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepctl, depctl.d32);
  56214. +
  56215. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doeptsiz, 0);
  56216. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepdma, 0);
  56217. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepint, 0xFF);
  56218. + }
  56219. +
  56220. + if (core_if->en_multiple_tx_fifo && core_if->dma_enable) {
  56221. + dev_if->non_iso_tx_thr_en = params->thr_ctl & 0x1;
  56222. + dev_if->iso_tx_thr_en = (params->thr_ctl >> 1) & 0x1;
  56223. + dev_if->rx_thr_en = (params->thr_ctl >> 2) & 0x1;
  56224. +
  56225. + dev_if->rx_thr_length = params->rx_thr_length;
  56226. + dev_if->tx_thr_length = params->tx_thr_length;
  56227. +
  56228. + dev_if->setup_desc_index = 0;
  56229. +
  56230. + dthrctl.d32 = 0;
  56231. + dthrctl.b.non_iso_thr_en = dev_if->non_iso_tx_thr_en;
  56232. + dthrctl.b.iso_thr_en = dev_if->iso_tx_thr_en;
  56233. + dthrctl.b.tx_thr_len = dev_if->tx_thr_length;
  56234. + dthrctl.b.rx_thr_en = dev_if->rx_thr_en;
  56235. + dthrctl.b.rx_thr_len = dev_if->rx_thr_length;
  56236. + dthrctl.b.ahb_thr_ratio = params->ahb_thr_ratio;
  56237. +
  56238. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dtknqr3_dthrctl,
  56239. + dthrctl.d32);
  56240. +
  56241. + DWC_DEBUGPL(DBG_CIL,
  56242. + "Non ISO Tx Thr - %d\nISO Tx Thr - %d\nRx Thr - %d\nTx Thr Len - %d\nRx Thr Len - %d\n",
  56243. + dthrctl.b.non_iso_thr_en, dthrctl.b.iso_thr_en,
  56244. + dthrctl.b.rx_thr_en, dthrctl.b.tx_thr_len,
  56245. + dthrctl.b.rx_thr_len);
  56246. +
  56247. + }
  56248. +
  56249. + dwc_otg_enable_device_interrupts(core_if);
  56250. +
  56251. + {
  56252. + diepmsk_data_t msk = {.d32 = 0 };
  56253. + msk.b.txfifoundrn = 1;
  56254. + if (core_if->multiproc_int_enable) {
  56255. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->
  56256. + diepeachintmsk[0], msk.d32, msk.d32);
  56257. + } else {
  56258. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->diepmsk,
  56259. + msk.d32, msk.d32);
  56260. + }
  56261. + }
  56262. +
  56263. + if (core_if->multiproc_int_enable) {
  56264. + /* Set NAK on Babble */
  56265. + dctl_data_t dctl = {.d32 = 0 };
  56266. + dctl.b.nakonbble = 1;
  56267. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, 0, dctl.d32);
  56268. + }
  56269. +
  56270. + if (core_if->snpsid >= OTG_CORE_REV_2_94a) {
  56271. + dctl_data_t dctl = {.d32 = 0 };
  56272. + dctl.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dctl);
  56273. + dctl.b.sftdiscon = 0;
  56274. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dctl, dctl.d32);
  56275. + }
  56276. +}
  56277. +
  56278. +/**
  56279. + * This function enables the Host mode interrupts.
  56280. + *
  56281. + * @param core_if Programming view of DWC_otg controller
  56282. + */
  56283. +void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t * core_if)
  56284. +{
  56285. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  56286. + gintmsk_data_t intr_mask = {.d32 = 0 };
  56287. +
  56288. + DWC_DEBUGPL(DBG_CIL, "%s(%p)\n", __func__, core_if);
  56289. +
  56290. + /* Disable all interrupts. */
  56291. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  56292. +
  56293. + /* Clear any pending interrupts. */
  56294. + DWC_WRITE_REG32(&global_regs->gintsts, 0xFFFFFFFF);
  56295. +
  56296. + /* Enable the common interrupts */
  56297. + dwc_otg_enable_common_interrupts(core_if);
  56298. +
  56299. + /*
  56300. + * Enable host mode interrupts without disturbing common
  56301. + * interrupts.
  56302. + */
  56303. +
  56304. + intr_mask.b.disconnect = 1;
  56305. + intr_mask.b.portintr = 1;
  56306. + intr_mask.b.hcintr = 1;
  56307. +
  56308. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
  56309. +}
  56310. +
  56311. +/**
  56312. + * This function disables the Host Mode interrupts.
  56313. + *
  56314. + * @param core_if Programming view of DWC_otg controller
  56315. + */
  56316. +void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t * core_if)
  56317. +{
  56318. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  56319. + gintmsk_data_t intr_mask = {.d32 = 0 };
  56320. +
  56321. + DWC_DEBUGPL(DBG_CILV, "%s()\n", __func__);
  56322. +
  56323. + /*
  56324. + * Disable host mode interrupts without disturbing common
  56325. + * interrupts.
  56326. + */
  56327. + intr_mask.b.sofintr = 1;
  56328. + intr_mask.b.portintr = 1;
  56329. + intr_mask.b.hcintr = 1;
  56330. + intr_mask.b.ptxfempty = 1;
  56331. + intr_mask.b.nptxfempty = 1;
  56332. +
  56333. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32, 0);
  56334. +}
  56335. +
  56336. +/**
  56337. + * This function initializes the DWC_otg controller registers for
  56338. + * host mode.
  56339. + *
  56340. + * This function flushes the Tx and Rx FIFOs and it flushes any entries in the
  56341. + * request queues. Host channels are reset to ensure that they are ready for
  56342. + * performing transfers.
  56343. + *
  56344. + * @param core_if Programming view of DWC_otg controller
  56345. + *
  56346. + */
  56347. +void dwc_otg_core_host_init(dwc_otg_core_if_t * core_if)
  56348. +{
  56349. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  56350. + dwc_otg_host_if_t *host_if = core_if->host_if;
  56351. + dwc_otg_core_params_t *params = core_if->core_params;
  56352. + hprt0_data_t hprt0 = {.d32 = 0 };
  56353. + fifosize_data_t nptxfifosize;
  56354. + fifosize_data_t ptxfifosize;
  56355. + uint16_t rxfsiz, nptxfsiz, hptxfsiz;
  56356. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  56357. + int i;
  56358. + hcchar_data_t hcchar;
  56359. + hcfg_data_t hcfg;
  56360. + hfir_data_t hfir;
  56361. + dwc_otg_hc_regs_t *hc_regs;
  56362. + int num_channels;
  56363. + gotgctl_data_t gotgctl = {.d32 = 0 };
  56364. +
  56365. + DWC_DEBUGPL(DBG_CILV, "%s(%p)\n", __func__, core_if);
  56366. +
  56367. + /* Restart the Phy Clock */
  56368. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  56369. +
  56370. + /* Initialize Host Configuration Register */
  56371. + init_fslspclksel(core_if);
  56372. + if (core_if->core_params->speed == DWC_SPEED_PARAM_FULL) {
  56373. + hcfg.d32 = DWC_READ_REG32(&host_if->host_global_regs->hcfg);
  56374. + hcfg.b.fslssupp = 1;
  56375. + DWC_WRITE_REG32(&host_if->host_global_regs->hcfg, hcfg.d32);
  56376. +
  56377. + }
  56378. +
  56379. + /* This bit allows dynamic reloading of the HFIR register
  56380. + * during runtime. This bit needs to be programmed during
  56381. + * initial configuration and its value must not be changed
  56382. + * during runtime.*/
  56383. + if (core_if->core_params->reload_ctl == 1) {
  56384. + hfir.d32 = DWC_READ_REG32(&host_if->host_global_regs->hfir);
  56385. + hfir.b.hfirrldctrl = 1;
  56386. + DWC_WRITE_REG32(&host_if->host_global_regs->hfir, hfir.d32);
  56387. + }
  56388. +
  56389. + if (core_if->core_params->dma_desc_enable) {
  56390. + uint8_t op_mode = core_if->hwcfg2.b.op_mode;
  56391. + if (!
  56392. + (core_if->hwcfg4.b.desc_dma
  56393. + && (core_if->snpsid >= OTG_CORE_REV_2_90a)
  56394. + && ((op_mode == DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  56395. + || (op_mode == DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG)
  56396. + || (op_mode ==
  56397. + DWC_HWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE_OTG)
  56398. + || (op_mode == DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)
  56399. + || (op_mode ==
  56400. + DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST)))) {
  56401. +
  56402. + DWC_ERROR("Host can't operate in Descriptor DMA mode.\n"
  56403. + "Either core version is below 2.90a or "
  56404. + "GHWCFG2, GHWCFG4 registers' values do not allow Descriptor DMA in host mode.\n"
  56405. + "To run the driver in Buffer DMA host mode set dma_desc_enable "
  56406. + "module parameter to 0.\n");
  56407. + return;
  56408. + }
  56409. + hcfg.d32 = DWC_READ_REG32(&host_if->host_global_regs->hcfg);
  56410. + hcfg.b.descdma = 1;
  56411. + DWC_WRITE_REG32(&host_if->host_global_regs->hcfg, hcfg.d32);
  56412. + }
  56413. +
  56414. + /* Configure data FIFO sizes */
  56415. + if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
  56416. + DWC_DEBUGPL(DBG_CIL, "Total FIFO Size=%d\n",
  56417. + core_if->total_fifo_size);
  56418. + DWC_DEBUGPL(DBG_CIL, "Rx FIFO Size=%d\n",
  56419. + params->host_rx_fifo_size);
  56420. + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO Size=%d\n",
  56421. + params->host_nperio_tx_fifo_size);
  56422. + DWC_DEBUGPL(DBG_CIL, "P Tx FIFO Size=%d\n",
  56423. + params->host_perio_tx_fifo_size);
  56424. +
  56425. + /* Rx FIFO */
  56426. + DWC_DEBUGPL(DBG_CIL, "initial grxfsiz=%08x\n",
  56427. + DWC_READ_REG32(&global_regs->grxfsiz));
  56428. + DWC_WRITE_REG32(&global_regs->grxfsiz,
  56429. + params->host_rx_fifo_size);
  56430. + DWC_DEBUGPL(DBG_CIL, "new grxfsiz=%08x\n",
  56431. + DWC_READ_REG32(&global_regs->grxfsiz));
  56432. +
  56433. + /* Non-periodic Tx FIFO */
  56434. + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
  56435. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  56436. + nptxfifosize.b.depth = params->host_nperio_tx_fifo_size;
  56437. + nptxfifosize.b.startaddr = params->host_rx_fifo_size;
  56438. + DWC_WRITE_REG32(&global_regs->gnptxfsiz, nptxfifosize.d32);
  56439. + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
  56440. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  56441. +
  56442. + /* Periodic Tx FIFO */
  56443. + DWC_DEBUGPL(DBG_CIL, "initial hptxfsiz=%08x\n",
  56444. + DWC_READ_REG32(&global_regs->hptxfsiz));
  56445. + ptxfifosize.b.depth = params->host_perio_tx_fifo_size;
  56446. + ptxfifosize.b.startaddr =
  56447. + nptxfifosize.b.startaddr + nptxfifosize.b.depth;
  56448. + DWC_WRITE_REG32(&global_regs->hptxfsiz, ptxfifosize.d32);
  56449. + DWC_DEBUGPL(DBG_CIL, "new hptxfsiz=%08x\n",
  56450. + DWC_READ_REG32(&global_regs->hptxfsiz));
  56451. +
  56452. + if (core_if->en_multiple_tx_fifo
  56453. + && core_if->snpsid <= OTG_CORE_REV_2_94a) {
  56454. + /* Global DFIFOCFG calculation for Host mode - include RxFIFO, NPTXFIFO and HPTXFIFO */
  56455. + gdfifocfg.d32 = DWC_READ_REG32(&global_regs->gdfifocfg);
  56456. + rxfsiz = (DWC_READ_REG32(&global_regs->grxfsiz) & 0x0000ffff);
  56457. + nptxfsiz = (DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16);
  56458. + hptxfsiz = (DWC_READ_REG32(&global_regs->hptxfsiz) >> 16);
  56459. + gdfifocfg.b.epinfobase = rxfsiz + nptxfsiz + hptxfsiz;
  56460. + DWC_WRITE_REG32(&global_regs->gdfifocfg, gdfifocfg.d32);
  56461. + }
  56462. + }
  56463. +
  56464. + /* TODO - check this */
  56465. + /* Clear Host Set HNP Enable in the OTG Control Register */
  56466. + gotgctl.b.hstsethnpen = 1;
  56467. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  56468. + /* Make sure the FIFOs are flushed. */
  56469. + dwc_otg_flush_tx_fifo(core_if, 0x10 /* all TX FIFOs */ );
  56470. + dwc_otg_flush_rx_fifo(core_if);
  56471. +
  56472. + /* Clear Host Set HNP Enable in the OTG Control Register */
  56473. + gotgctl.b.hstsethnpen = 1;
  56474. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  56475. +
  56476. + if (!core_if->core_params->dma_desc_enable) {
  56477. + /* Flush out any leftover queued requests. */
  56478. + num_channels = core_if->core_params->host_channels;
  56479. +
  56480. + for (i = 0; i < num_channels; i++) {
  56481. + hc_regs = core_if->host_if->hc_regs[i];
  56482. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  56483. + hcchar.b.chen = 0;
  56484. + hcchar.b.chdis = 1;
  56485. + hcchar.b.epdir = 0;
  56486. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  56487. + }
  56488. +
  56489. + /* Halt all channels to put them into a known state. */
  56490. + for (i = 0; i < num_channels; i++) {
  56491. + int count = 0;
  56492. + hc_regs = core_if->host_if->hc_regs[i];
  56493. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  56494. + hcchar.b.chen = 1;
  56495. + hcchar.b.chdis = 1;
  56496. + hcchar.b.epdir = 0;
  56497. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  56498. + DWC_DEBUGPL(DBG_HCDV, "%s: Halt channel %d regs %p\n", __func__, i, hc_regs);
  56499. + do {
  56500. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  56501. + if (++count > 1000) {
  56502. + DWC_ERROR
  56503. + ("%s: Unable to clear halt on channel %d (timeout HCCHAR 0x%X @%p)\n",
  56504. + __func__, i, hcchar.d32, &hc_regs->hcchar);
  56505. + break;
  56506. + }
  56507. + dwc_udelay(1);
  56508. + } while (hcchar.b.chen);
  56509. + }
  56510. + }
  56511. +
  56512. + /* Turn on the vbus power. */
  56513. + DWC_PRINTF("Init: Port Power? op_state=%d\n", core_if->op_state);
  56514. + if (core_if->op_state == A_HOST) {
  56515. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  56516. + DWC_PRINTF("Init: Power Port (%d)\n", hprt0.b.prtpwr);
  56517. + if (hprt0.b.prtpwr == 0) {
  56518. + hprt0.b.prtpwr = 1;
  56519. + DWC_WRITE_REG32(host_if->hprt0, hprt0.d32);
  56520. + }
  56521. + }
  56522. +
  56523. + dwc_otg_enable_host_interrupts(core_if);
  56524. +}
  56525. +
  56526. +/**
  56527. + * Prepares a host channel for transferring packets to/from a specific
  56528. + * endpoint. The HCCHARn register is set up with the characteristics specified
  56529. + * in _hc. Host channel interrupts that may need to be serviced while this
  56530. + * transfer is in progress are enabled.
  56531. + *
  56532. + * @param core_if Programming view of DWC_otg controller
  56533. + * @param hc Information needed to initialize the host channel
  56534. + */
  56535. +void dwc_otg_hc_init(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  56536. +{
  56537. + uint32_t intr_enable;
  56538. + hcintmsk_data_t hc_intr_mask;
  56539. + gintmsk_data_t gintmsk = {.d32 = 0 };
  56540. + hcchar_data_t hcchar;
  56541. + hcsplt_data_t hcsplt;
  56542. +
  56543. + uint8_t hc_num = hc->hc_num;
  56544. + dwc_otg_host_if_t *host_if = core_if->host_if;
  56545. + dwc_otg_hc_regs_t *hc_regs = host_if->hc_regs[hc_num];
  56546. +
  56547. + /* Clear old interrupt conditions for this host channel. */
  56548. + hc_intr_mask.d32 = 0xFFFFFFFF;
  56549. + hc_intr_mask.b.reserved14_31 = 0;
  56550. + DWC_WRITE_REG32(&hc_regs->hcint, hc_intr_mask.d32);
  56551. +
  56552. + /* Enable channel interrupts required for this transfer. */
  56553. + hc_intr_mask.d32 = 0;
  56554. + hc_intr_mask.b.chhltd = 1;
  56555. + if (core_if->dma_enable) {
  56556. + /* For Descriptor DMA mode core halts the channel on AHB error. Interrupt is not required */
  56557. + if (!core_if->dma_desc_enable)
  56558. + hc_intr_mask.b.ahberr = 1;
  56559. + else {
  56560. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  56561. + hc_intr_mask.b.xfercompl = 1;
  56562. + }
  56563. +
  56564. + if (hc->error_state && !hc->do_split &&
  56565. + hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
  56566. + hc_intr_mask.b.ack = 1;
  56567. + if (hc->ep_is_in) {
  56568. + hc_intr_mask.b.datatglerr = 1;
  56569. + if (hc->ep_type != DWC_OTG_EP_TYPE_INTR) {
  56570. + hc_intr_mask.b.nak = 1;
  56571. + }
  56572. + }
  56573. + }
  56574. + } else {
  56575. + switch (hc->ep_type) {
  56576. + case DWC_OTG_EP_TYPE_CONTROL:
  56577. + case DWC_OTG_EP_TYPE_BULK:
  56578. + hc_intr_mask.b.xfercompl = 1;
  56579. + hc_intr_mask.b.stall = 1;
  56580. + hc_intr_mask.b.xacterr = 1;
  56581. + hc_intr_mask.b.datatglerr = 1;
  56582. + if (hc->ep_is_in) {
  56583. + hc_intr_mask.b.bblerr = 1;
  56584. + } else {
  56585. + hc_intr_mask.b.nak = 1;
  56586. + hc_intr_mask.b.nyet = 1;
  56587. + if (hc->do_ping) {
  56588. + hc_intr_mask.b.ack = 1;
  56589. + }
  56590. + }
  56591. +
  56592. + if (hc->do_split) {
  56593. + hc_intr_mask.b.nak = 1;
  56594. + if (hc->complete_split) {
  56595. + hc_intr_mask.b.nyet = 1;
  56596. + } else {
  56597. + hc_intr_mask.b.ack = 1;
  56598. + }
  56599. + }
  56600. +
  56601. + if (hc->error_state) {
  56602. + hc_intr_mask.b.ack = 1;
  56603. + }
  56604. + break;
  56605. + case DWC_OTG_EP_TYPE_INTR:
  56606. + hc_intr_mask.b.xfercompl = 1;
  56607. + hc_intr_mask.b.nak = 1;
  56608. + hc_intr_mask.b.stall = 1;
  56609. + hc_intr_mask.b.xacterr = 1;
  56610. + hc_intr_mask.b.datatglerr = 1;
  56611. + hc_intr_mask.b.frmovrun = 1;
  56612. +
  56613. + if (hc->ep_is_in) {
  56614. + hc_intr_mask.b.bblerr = 1;
  56615. + }
  56616. + if (hc->error_state) {
  56617. + hc_intr_mask.b.ack = 1;
  56618. + }
  56619. + if (hc->do_split) {
  56620. + if (hc->complete_split) {
  56621. + hc_intr_mask.b.nyet = 1;
  56622. + } else {
  56623. + hc_intr_mask.b.ack = 1;
  56624. + }
  56625. + }
  56626. + break;
  56627. + case DWC_OTG_EP_TYPE_ISOC:
  56628. + hc_intr_mask.b.xfercompl = 1;
  56629. + hc_intr_mask.b.frmovrun = 1;
  56630. + hc_intr_mask.b.ack = 1;
  56631. +
  56632. + if (hc->ep_is_in) {
  56633. + hc_intr_mask.b.xacterr = 1;
  56634. + hc_intr_mask.b.bblerr = 1;
  56635. + }
  56636. + break;
  56637. + }
  56638. + }
  56639. + DWC_WRITE_REG32(&hc_regs->hcintmsk, hc_intr_mask.d32);
  56640. +
  56641. + /* Enable the top level host channel interrupt. */
  56642. + intr_enable = (1 << hc_num);
  56643. + DWC_MODIFY_REG32(&host_if->host_global_regs->haintmsk, 0, intr_enable);
  56644. +
  56645. + /* Make sure host channel interrupts are enabled. */
  56646. + gintmsk.b.hcintr = 1;
  56647. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, gintmsk.d32);
  56648. +
  56649. + /*
  56650. + * Program the HCCHARn register with the endpoint characteristics for
  56651. + * the current transfer.
  56652. + */
  56653. + hcchar.d32 = 0;
  56654. + hcchar.b.devaddr = hc->dev_addr;
  56655. + hcchar.b.epnum = hc->ep_num;
  56656. + hcchar.b.epdir = hc->ep_is_in;
  56657. + hcchar.b.lspddev = (hc->speed == DWC_OTG_EP_SPEED_LOW);
  56658. + hcchar.b.eptype = hc->ep_type;
  56659. + hcchar.b.mps = hc->max_packet;
  56660. +
  56661. + DWC_WRITE_REG32(&host_if->hc_regs[hc_num]->hcchar, hcchar.d32);
  56662. +
  56663. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d, Dev Addr %d, EP #%d\n",
  56664. + __func__, hc->hc_num, hcchar.b.devaddr, hcchar.b.epnum);
  56665. + DWC_DEBUGPL(DBG_HCDV, " Is In %d, Is Low Speed %d, EP Type %d, "
  56666. + "Max Pkt %d, Multi Cnt %d\n",
  56667. + hcchar.b.epdir, hcchar.b.lspddev, hcchar.b.eptype,
  56668. + hcchar.b.mps, hcchar.b.multicnt);
  56669. +
  56670. + /*
  56671. + * Program the HCSPLIT register for SPLITs
  56672. + */
  56673. + hcsplt.d32 = 0;
  56674. + if (hc->do_split) {
  56675. + DWC_DEBUGPL(DBG_HCDV, "Programming HC %d with split --> %s\n",
  56676. + hc->hc_num,
  56677. + hc->complete_split ? "CSPLIT" : "SSPLIT");
  56678. + hcsplt.b.compsplt = hc->complete_split;
  56679. + hcsplt.b.xactpos = hc->xact_pos;
  56680. + hcsplt.b.hubaddr = hc->hub_addr;
  56681. + hcsplt.b.prtaddr = hc->port_addr;
  56682. + DWC_DEBUGPL(DBG_HCDV, "\t comp split %d\n", hc->complete_split);
  56683. + DWC_DEBUGPL(DBG_HCDV, "\t xact pos %d\n", hc->xact_pos);
  56684. + DWC_DEBUGPL(DBG_HCDV, "\t hub addr %d\n", hc->hub_addr);
  56685. + DWC_DEBUGPL(DBG_HCDV, "\t port addr %d\n", hc->port_addr);
  56686. + DWC_DEBUGPL(DBG_HCDV, "\t is_in %d\n", hc->ep_is_in);
  56687. + DWC_DEBUGPL(DBG_HCDV, "\t Max Pkt: %d\n", hcchar.b.mps);
  56688. + DWC_DEBUGPL(DBG_HCDV, "\t xferlen: %d\n", hc->xfer_len);
  56689. + }
  56690. + DWC_WRITE_REG32(&host_if->hc_regs[hc_num]->hcsplt, hcsplt.d32);
  56691. +
  56692. +}
  56693. +
  56694. +/**
  56695. + * Attempts to halt a host channel. This function should only be called in
  56696. + * Slave mode or to abort a transfer in either Slave mode or DMA mode. Under
  56697. + * normal circumstances in DMA mode, the controller halts the channel when the
  56698. + * transfer is complete or a condition occurs that requires application
  56699. + * intervention.
  56700. + *
  56701. + * In slave mode, checks for a free request queue entry, then sets the Channel
  56702. + * Enable and Channel Disable bits of the Host Channel Characteristics
  56703. + * register of the specified channel to intiate the halt. If there is no free
  56704. + * request queue entry, sets only the Channel Disable bit of the HCCHARn
  56705. + * register to flush requests for this channel. In the latter case, sets a
  56706. + * flag to indicate that the host channel needs to be halted when a request
  56707. + * queue slot is open.
  56708. + *
  56709. + * In DMA mode, always sets the Channel Enable and Channel Disable bits of the
  56710. + * HCCHARn register. The controller ensures there is space in the request
  56711. + * queue before submitting the halt request.
  56712. + *
  56713. + * Some time may elapse before the core flushes any posted requests for this
  56714. + * host channel and halts. The Channel Halted interrupt handler completes the
  56715. + * deactivation of the host channel.
  56716. + *
  56717. + * @param core_if Controller register interface.
  56718. + * @param hc Host channel to halt.
  56719. + * @param halt_status Reason for halting the channel.
  56720. + */
  56721. +void dwc_otg_hc_halt(dwc_otg_core_if_t * core_if,
  56722. + dwc_hc_t * hc, dwc_otg_halt_status_e halt_status)
  56723. +{
  56724. + gnptxsts_data_t nptxsts;
  56725. + hptxsts_data_t hptxsts;
  56726. + hcchar_data_t hcchar;
  56727. + dwc_otg_hc_regs_t *hc_regs;
  56728. + dwc_otg_core_global_regs_t *global_regs;
  56729. + dwc_otg_host_global_regs_t *host_global_regs;
  56730. +
  56731. + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  56732. + global_regs = core_if->core_global_regs;
  56733. + host_global_regs = core_if->host_if->host_global_regs;
  56734. +
  56735. + DWC_ASSERT(!(halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS),
  56736. + "halt_status = %d\n", halt_status);
  56737. +
  56738. + if (halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE ||
  56739. + halt_status == DWC_OTG_HC_XFER_AHB_ERR) {
  56740. + /*
  56741. + * Disable all channel interrupts except Ch Halted. The QTD
  56742. + * and QH state associated with this transfer has been cleared
  56743. + * (in the case of URB_DEQUEUE), so the channel needs to be
  56744. + * shut down carefully to prevent crashes.
  56745. + */
  56746. + hcintmsk_data_t hcintmsk;
  56747. + hcintmsk.d32 = 0;
  56748. + hcintmsk.b.chhltd = 1;
  56749. + DWC_WRITE_REG32(&hc_regs->hcintmsk, hcintmsk.d32);
  56750. +
  56751. + /*
  56752. + * Make sure no other interrupts besides halt are currently
  56753. + * pending. Handling another interrupt could cause a crash due
  56754. + * to the QTD and QH state.
  56755. + */
  56756. + DWC_WRITE_REG32(&hc_regs->hcint, ~hcintmsk.d32);
  56757. +
  56758. + /*
  56759. + * Make sure the halt status is set to URB_DEQUEUE or AHB_ERR
  56760. + * even if the channel was already halted for some other
  56761. + * reason.
  56762. + */
  56763. + hc->halt_status = halt_status;
  56764. +
  56765. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  56766. + if (hcchar.b.chen == 0) {
  56767. + /*
  56768. + * The channel is either already halted or it hasn't
  56769. + * started yet. In DMA mode, the transfer may halt if
  56770. + * it finishes normally or a condition occurs that
  56771. + * requires driver intervention. Don't want to halt
  56772. + * the channel again. In either Slave or DMA mode,
  56773. + * it's possible that the transfer has been assigned
  56774. + * to a channel, but not started yet when an URB is
  56775. + * dequeued. Don't want to halt a channel that hasn't
  56776. + * started yet.
  56777. + */
  56778. + return;
  56779. + }
  56780. + }
  56781. + if (hc->halt_pending) {
  56782. + /*
  56783. + * A halt has already been issued for this channel. This might
  56784. + * happen when a transfer is aborted by a higher level in
  56785. + * the stack.
  56786. + */
  56787. +#ifdef DEBUG
  56788. + DWC_PRINTF
  56789. + ("*** %s: Channel %d, _hc->halt_pending already set ***\n",
  56790. + __func__, hc->hc_num);
  56791. +
  56792. +#endif
  56793. + return;
  56794. + }
  56795. +
  56796. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  56797. +
  56798. + /* No need to set the bit in DDMA for disabling the channel */
  56799. + //TODO check it everywhere channel is disabled
  56800. + if (!core_if->core_params->dma_desc_enable)
  56801. + hcchar.b.chen = 1;
  56802. + hcchar.b.chdis = 1;
  56803. +
  56804. + if (!core_if->dma_enable) {
  56805. + /* Check for space in the request queue to issue the halt. */
  56806. + if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
  56807. + hc->ep_type == DWC_OTG_EP_TYPE_BULK) {
  56808. + nptxsts.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  56809. + if (nptxsts.b.nptxqspcavail == 0) {
  56810. + hcchar.b.chen = 0;
  56811. + }
  56812. + } else {
  56813. + hptxsts.d32 =
  56814. + DWC_READ_REG32(&host_global_regs->hptxsts);
  56815. + if ((hptxsts.b.ptxqspcavail == 0)
  56816. + || (core_if->queuing_high_bandwidth)) {
  56817. + hcchar.b.chen = 0;
  56818. + }
  56819. + }
  56820. + }
  56821. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  56822. +
  56823. + hc->halt_status = halt_status;
  56824. +
  56825. + if (hcchar.b.chen) {
  56826. + hc->halt_pending = 1;
  56827. + hc->halt_on_queue = 0;
  56828. + } else {
  56829. + hc->halt_on_queue = 1;
  56830. + }
  56831. +
  56832. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  56833. + DWC_DEBUGPL(DBG_HCDV, " hcchar: 0x%08x\n", hcchar.d32);
  56834. + DWC_DEBUGPL(DBG_HCDV, " halt_pending: %d\n", hc->halt_pending);
  56835. + DWC_DEBUGPL(DBG_HCDV, " halt_on_queue: %d\n", hc->halt_on_queue);
  56836. + DWC_DEBUGPL(DBG_HCDV, " halt_status: %d\n", hc->halt_status);
  56837. +
  56838. + return;
  56839. +}
  56840. +
  56841. +/**
  56842. + * Clears the transfer state for a host channel. This function is normally
  56843. + * called after a transfer is done and the host channel is being released.
  56844. + *
  56845. + * @param core_if Programming view of DWC_otg controller.
  56846. + * @param hc Identifies the host channel to clean up.
  56847. + */
  56848. +void dwc_otg_hc_cleanup(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  56849. +{
  56850. + dwc_otg_hc_regs_t *hc_regs;
  56851. +
  56852. + hc->xfer_started = 0;
  56853. +
  56854. + /*
  56855. + * Clear channel interrupt enables and any unhandled channel interrupt
  56856. + * conditions.
  56857. + */
  56858. + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  56859. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0);
  56860. + DWC_WRITE_REG32(&hc_regs->hcint, 0xFFFFFFFF);
  56861. +#ifdef DEBUG
  56862. + DWC_TIMER_CANCEL(core_if->hc_xfer_timer[hc->hc_num]);
  56863. +#endif
  56864. +}
  56865. +
  56866. +/**
  56867. + * Sets the channel property that indicates in which frame a periodic transfer
  56868. + * should occur. This is always set to the _next_ frame. This function has no
  56869. + * effect on non-periodic transfers.
  56870. + *
  56871. + * @param core_if Programming view of DWC_otg controller.
  56872. + * @param hc Identifies the host channel to set up and its properties.
  56873. + * @param hcchar Current value of the HCCHAR register for the specified host
  56874. + * channel.
  56875. + */
  56876. +static inline void hc_set_even_odd_frame(dwc_otg_core_if_t * core_if,
  56877. + dwc_hc_t * hc, hcchar_data_t * hcchar)
  56878. +{
  56879. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  56880. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  56881. + hfnum_data_t hfnum;
  56882. + hfnum.d32 =
  56883. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hfnum);
  56884. +
  56885. + /* 1 if _next_ frame is odd, 0 if it's even */
  56886. + hcchar->b.oddfrm = (hfnum.b.frnum & 0x1) ? 0 : 1;
  56887. +#ifdef DEBUG
  56888. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR && hc->do_split
  56889. + && !hc->complete_split) {
  56890. + switch (hfnum.b.frnum & 0x7) {
  56891. + case 7:
  56892. + core_if->hfnum_7_samples++;
  56893. + core_if->hfnum_7_frrem_accum += hfnum.b.frrem;
  56894. + break;
  56895. + case 0:
  56896. + core_if->hfnum_0_samples++;
  56897. + core_if->hfnum_0_frrem_accum += hfnum.b.frrem;
  56898. + break;
  56899. + default:
  56900. + core_if->hfnum_other_samples++;
  56901. + core_if->hfnum_other_frrem_accum +=
  56902. + hfnum.b.frrem;
  56903. + break;
  56904. + }
  56905. + }
  56906. +#endif
  56907. + }
  56908. +}
  56909. +
  56910. +#ifdef DEBUG
  56911. +void hc_xfer_timeout(void *ptr)
  56912. +{
  56913. + hc_xfer_info_t *xfer_info = NULL;
  56914. + int hc_num = 0;
  56915. +
  56916. + if (ptr)
  56917. + xfer_info = (hc_xfer_info_t *) ptr;
  56918. +
  56919. + if (!xfer_info->hc) {
  56920. + DWC_ERROR("xfer_info->hc = %p\n", xfer_info->hc);
  56921. + return;
  56922. + }
  56923. +
  56924. + hc_num = xfer_info->hc->hc_num;
  56925. + DWC_WARN("%s: timeout on channel %d\n", __func__, hc_num);
  56926. + DWC_WARN(" start_hcchar_val 0x%08x\n",
  56927. + xfer_info->core_if->start_hcchar_val[hc_num]);
  56928. +}
  56929. +#endif
  56930. +
  56931. +void ep_xfer_timeout(void *ptr)
  56932. +{
  56933. + ep_xfer_info_t *xfer_info = NULL;
  56934. + int ep_num = 0;
  56935. + dctl_data_t dctl = {.d32 = 0 };
  56936. + gintsts_data_t gintsts = {.d32 = 0 };
  56937. + gintmsk_data_t gintmsk = {.d32 = 0 };
  56938. +
  56939. + if (ptr)
  56940. + xfer_info = (ep_xfer_info_t *) ptr;
  56941. +
  56942. + if (!xfer_info->ep) {
  56943. + DWC_ERROR("xfer_info->ep = %p\n", xfer_info->ep);
  56944. + return;
  56945. + }
  56946. +
  56947. + ep_num = xfer_info->ep->num;
  56948. + DWC_WARN("%s: timeout on endpoit %d\n", __func__, ep_num);
  56949. + /* Put the sate to 2 as it was time outed */
  56950. + xfer_info->state = 2;
  56951. +
  56952. + dctl.d32 =
  56953. + DWC_READ_REG32(&xfer_info->core_if->dev_if->dev_global_regs->dctl);
  56954. + gintsts.d32 =
  56955. + DWC_READ_REG32(&xfer_info->core_if->core_global_regs->gintsts);
  56956. + gintmsk.d32 =
  56957. + DWC_READ_REG32(&xfer_info->core_if->core_global_regs->gintmsk);
  56958. +
  56959. + if (!gintmsk.b.goutnakeff) {
  56960. + /* Unmask it */
  56961. + gintmsk.b.goutnakeff = 1;
  56962. + DWC_WRITE_REG32(&xfer_info->core_if->core_global_regs->gintmsk,
  56963. + gintmsk.d32);
  56964. +
  56965. + }
  56966. +
  56967. + if (!gintsts.b.goutnakeff) {
  56968. + dctl.b.sgoutnak = 1;
  56969. + }
  56970. + DWC_WRITE_REG32(&xfer_info->core_if->dev_if->dev_global_regs->dctl,
  56971. + dctl.d32);
  56972. +
  56973. +}
  56974. +
  56975. +void set_pid_isoc(dwc_hc_t * hc)
  56976. +{
  56977. + /* Set up the initial PID for the transfer. */
  56978. + if (hc->speed == DWC_OTG_EP_SPEED_HIGH) {
  56979. + if (hc->ep_is_in) {
  56980. + if (hc->multi_count == 1) {
  56981. + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
  56982. + } else if (hc->multi_count == 2) {
  56983. + hc->data_pid_start = DWC_OTG_HC_PID_DATA1;
  56984. + } else {
  56985. + hc->data_pid_start = DWC_OTG_HC_PID_DATA2;
  56986. + }
  56987. + } else {
  56988. + if (hc->multi_count == 1) {
  56989. + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
  56990. + } else {
  56991. + hc->data_pid_start = DWC_OTG_HC_PID_MDATA;
  56992. + }
  56993. + }
  56994. + } else {
  56995. + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
  56996. + }
  56997. +}
  56998. +
  56999. +/**
  57000. + * This function does the setup for a data transfer for a host channel and
  57001. + * starts the transfer. May be called in either Slave mode or DMA mode. In
  57002. + * Slave mode, the caller must ensure that there is sufficient space in the
  57003. + * request queue and Tx Data FIFO.
  57004. + *
  57005. + * For an OUT transfer in Slave mode, it loads a data packet into the
  57006. + * appropriate FIFO. If necessary, additional data packets will be loaded in
  57007. + * the Host ISR.
  57008. + *
  57009. + * For an IN transfer in Slave mode, a data packet is requested. The data
  57010. + * packets are unloaded from the Rx FIFO in the Host ISR. If necessary,
  57011. + * additional data packets are requested in the Host ISR.
  57012. + *
  57013. + * For a PING transfer in Slave mode, the Do Ping bit is set in the HCTSIZ
  57014. + * register along with a packet count of 1 and the channel is enabled. This
  57015. + * causes a single PING transaction to occur. Other fields in HCTSIZ are
  57016. + * simply set to 0 since no data transfer occurs in this case.
  57017. + *
  57018. + * For a PING transfer in DMA mode, the HCTSIZ register is initialized with
  57019. + * all the information required to perform the subsequent data transfer. In
  57020. + * addition, the Do Ping bit is set in the HCTSIZ register. In this case, the
  57021. + * controller performs the entire PING protocol, then starts the data
  57022. + * transfer.
  57023. + *
  57024. + * @param core_if Programming view of DWC_otg controller.
  57025. + * @param hc Information needed to initialize the host channel. The xfer_len
  57026. + * value may be reduced to accommodate the max widths of the XferSize and
  57027. + * PktCnt fields in the HCTSIZn register. The multi_count value may be changed
  57028. + * to reflect the final xfer_len value.
  57029. + */
  57030. +void dwc_otg_hc_start_transfer(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  57031. +{
  57032. + hcchar_data_t hcchar;
  57033. + hctsiz_data_t hctsiz;
  57034. + uint16_t num_packets;
  57035. + uint32_t max_hc_xfer_size = core_if->core_params->max_transfer_size;
  57036. + uint16_t max_hc_pkt_count = core_if->core_params->max_packet_count;
  57037. + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  57038. +
  57039. + hctsiz.d32 = 0;
  57040. +
  57041. + if (hc->do_ping) {
  57042. + if (!core_if->dma_enable) {
  57043. + dwc_otg_hc_do_ping(core_if, hc);
  57044. + hc->xfer_started = 1;
  57045. + return;
  57046. + } else {
  57047. + hctsiz.b.dopng = 1;
  57048. + }
  57049. + }
  57050. +
  57051. + if (hc->do_split) {
  57052. + num_packets = 1;
  57053. +
  57054. + if (hc->complete_split && !hc->ep_is_in) {
  57055. + /* For CSPLIT OUT Transfer, set the size to 0 so the
  57056. + * core doesn't expect any data written to the FIFO */
  57057. + hc->xfer_len = 0;
  57058. + } else if (hc->ep_is_in || (hc->xfer_len > hc->max_packet)) {
  57059. + hc->xfer_len = hc->max_packet;
  57060. + } else if (!hc->ep_is_in && (hc->xfer_len > 188)) {
  57061. + hc->xfer_len = 188;
  57062. + }
  57063. +
  57064. + hctsiz.b.xfersize = hc->xfer_len;
  57065. + } else {
  57066. + /*
  57067. + * Ensure that the transfer length and packet count will fit
  57068. + * in the widths allocated for them in the HCTSIZn register.
  57069. + */
  57070. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  57071. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  57072. + /*
  57073. + * Make sure the transfer size is no larger than one
  57074. + * (micro)frame's worth of data. (A check was done
  57075. + * when the periodic transfer was accepted to ensure
  57076. + * that a (micro)frame's worth of data can be
  57077. + * programmed into a channel.)
  57078. + */
  57079. + uint32_t max_periodic_len =
  57080. + hc->multi_count * hc->max_packet;
  57081. + if (hc->xfer_len > max_periodic_len) {
  57082. + hc->xfer_len = max_periodic_len;
  57083. + } else {
  57084. + }
  57085. + } else if (hc->xfer_len > max_hc_xfer_size) {
  57086. + /* Make sure that xfer_len is a multiple of max packet size. */
  57087. + hc->xfer_len = max_hc_xfer_size - hc->max_packet + 1;
  57088. + }
  57089. +
  57090. + if (hc->xfer_len > 0) {
  57091. + num_packets =
  57092. + (hc->xfer_len + hc->max_packet -
  57093. + 1) / hc->max_packet;
  57094. + if (num_packets > max_hc_pkt_count) {
  57095. + num_packets = max_hc_pkt_count;
  57096. + hc->xfer_len = num_packets * hc->max_packet;
  57097. + }
  57098. + } else {
  57099. + /* Need 1 packet for transfer length of 0. */
  57100. + num_packets = 1;
  57101. + }
  57102. +
  57103. + if (hc->ep_is_in) {
  57104. + /* Always program an integral # of max packets for IN transfers. */
  57105. + hc->xfer_len = num_packets * hc->max_packet;
  57106. + }
  57107. +
  57108. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  57109. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  57110. + /*
  57111. + * Make sure that the multi_count field matches the
  57112. + * actual transfer length.
  57113. + */
  57114. + hc->multi_count = num_packets;
  57115. + }
  57116. +
  57117. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  57118. + set_pid_isoc(hc);
  57119. +
  57120. + hctsiz.b.xfersize = hc->xfer_len;
  57121. + }
  57122. +
  57123. + hc->start_pkt_count = num_packets;
  57124. + hctsiz.b.pktcnt = num_packets;
  57125. + hctsiz.b.pid = hc->data_pid_start;
  57126. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  57127. +
  57128. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  57129. + DWC_DEBUGPL(DBG_HCDV, " Xfer Size: %d\n", hctsiz.b.xfersize);
  57130. + DWC_DEBUGPL(DBG_HCDV, " Num Pkts: %d\n", hctsiz.b.pktcnt);
  57131. + DWC_DEBUGPL(DBG_HCDV, " Start PID: %d\n", hctsiz.b.pid);
  57132. +
  57133. + if (core_if->dma_enable) {
  57134. + dwc_dma_t dma_addr;
  57135. + if (hc->align_buff) {
  57136. + dma_addr = hc->align_buff;
  57137. + } else {
  57138. + dma_addr = ((unsigned long)hc->xfer_buff & 0xffffffff);
  57139. + }
  57140. + DWC_WRITE_REG32(&hc_regs->hcdma, dma_addr);
  57141. + }
  57142. +
  57143. + /* Start the split */
  57144. + if (hc->do_split) {
  57145. + hcsplt_data_t hcsplt;
  57146. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  57147. + hcsplt.b.spltena = 1;
  57148. + DWC_WRITE_REG32(&hc_regs->hcsplt, hcsplt.d32);
  57149. + }
  57150. +
  57151. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  57152. + hcchar.b.multicnt = hc->multi_count;
  57153. + hc_set_even_odd_frame(core_if, hc, &hcchar);
  57154. +#ifdef DEBUG
  57155. + core_if->start_hcchar_val[hc->hc_num] = hcchar.d32;
  57156. + if (hcchar.b.chdis) {
  57157. + DWC_WARN("%s: chdis set, channel %d, hcchar 0x%08x\n",
  57158. + __func__, hc->hc_num, hcchar.d32);
  57159. + }
  57160. +#endif
  57161. +
  57162. + /* Set host channel enable after all other setup is complete. */
  57163. + hcchar.b.chen = 1;
  57164. + hcchar.b.chdis = 0;
  57165. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  57166. +
  57167. + hc->xfer_started = 1;
  57168. + hc->requests++;
  57169. +
  57170. + if (!core_if->dma_enable && !hc->ep_is_in && hc->xfer_len > 0) {
  57171. + /* Load OUT packet into the appropriate Tx FIFO. */
  57172. + dwc_otg_hc_write_packet(core_if, hc);
  57173. + }
  57174. +#ifdef DEBUG
  57175. + if (hc->ep_type != DWC_OTG_EP_TYPE_INTR) {
  57176. + DWC_DEBUGPL(DBG_HCDV, "transfer %d from core_if %p\n",
  57177. + hc->hc_num, core_if);//GRAYG
  57178. + core_if->hc_xfer_info[hc->hc_num].core_if = core_if;
  57179. + core_if->hc_xfer_info[hc->hc_num].hc = hc;
  57180. +
  57181. + /* Start a timer for this transfer. */
  57182. + DWC_TIMER_SCHEDULE(core_if->hc_xfer_timer[hc->hc_num], 10000);
  57183. + }
  57184. +#endif
  57185. +}
  57186. +
  57187. +/**
  57188. + * This function does the setup for a data transfer for a host channel
  57189. + * and starts the transfer in Descriptor DMA mode.
  57190. + *
  57191. + * Initializes HCTSIZ register. For a PING transfer the Do Ping bit is set.
  57192. + * Sets PID and NTD values. For periodic transfers
  57193. + * initializes SCHED_INFO field with micro-frame bitmap.
  57194. + *
  57195. + * Initializes HCDMA register with descriptor list address and CTD value
  57196. + * then starts the transfer via enabling the channel.
  57197. + *
  57198. + * @param core_if Programming view of DWC_otg controller.
  57199. + * @param hc Information needed to initialize the host channel.
  57200. + */
  57201. +void dwc_otg_hc_start_transfer_ddma(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  57202. +{
  57203. + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  57204. + hcchar_data_t hcchar;
  57205. + hctsiz_data_t hctsiz;
  57206. + hcdma_data_t hcdma;
  57207. +
  57208. + hctsiz.d32 = 0;
  57209. +
  57210. + if (hc->do_ping)
  57211. + hctsiz.b_ddma.dopng = 1;
  57212. +
  57213. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  57214. + set_pid_isoc(hc);
  57215. +
  57216. + /* Packet Count and Xfer Size are not used in Descriptor DMA mode */
  57217. + hctsiz.b_ddma.pid = hc->data_pid_start;
  57218. + hctsiz.b_ddma.ntd = hc->ntd - 1; /* 0 - 1 descriptor, 1 - 2 descriptors, etc. */
  57219. + hctsiz.b_ddma.schinfo = hc->schinfo; /* Non-zero only for high-speed interrupt endpoints */
  57220. +
  57221. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  57222. + DWC_DEBUGPL(DBG_HCDV, " Start PID: %d\n", hctsiz.b.pid);
  57223. + DWC_DEBUGPL(DBG_HCDV, " NTD: %d\n", hctsiz.b_ddma.ntd);
  57224. +
  57225. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  57226. +
  57227. + hcdma.d32 = 0;
  57228. + hcdma.b.dma_addr = ((uint32_t) hc->desc_list_addr) >> 11;
  57229. +
  57230. + /* Always start from first descriptor. */
  57231. + hcdma.b.ctd = 0;
  57232. + DWC_WRITE_REG32(&hc_regs->hcdma, hcdma.d32);
  57233. +
  57234. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  57235. + hcchar.b.multicnt = hc->multi_count;
  57236. +
  57237. +#ifdef DEBUG
  57238. + core_if->start_hcchar_val[hc->hc_num] = hcchar.d32;
  57239. + if (hcchar.b.chdis) {
  57240. + DWC_WARN("%s: chdis set, channel %d, hcchar 0x%08x\n",
  57241. + __func__, hc->hc_num, hcchar.d32);
  57242. + }
  57243. +#endif
  57244. +
  57245. + /* Set host channel enable after all other setup is complete. */
  57246. + hcchar.b.chen = 1;
  57247. + hcchar.b.chdis = 0;
  57248. +
  57249. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  57250. +
  57251. + hc->xfer_started = 1;
  57252. + hc->requests++;
  57253. +
  57254. +#ifdef DEBUG
  57255. + if ((hc->ep_type != DWC_OTG_EP_TYPE_INTR)
  57256. + && (hc->ep_type != DWC_OTG_EP_TYPE_ISOC)) {
  57257. + DWC_DEBUGPL(DBG_HCDV, "DMA transfer %d from core_if %p\n",
  57258. + hc->hc_num, core_if);//GRAYG
  57259. + core_if->hc_xfer_info[hc->hc_num].core_if = core_if;
  57260. + core_if->hc_xfer_info[hc->hc_num].hc = hc;
  57261. + /* Start a timer for this transfer. */
  57262. + DWC_TIMER_SCHEDULE(core_if->hc_xfer_timer[hc->hc_num], 10000);
  57263. + }
  57264. +#endif
  57265. +
  57266. +}
  57267. +
  57268. +/**
  57269. + * This function continues a data transfer that was started by previous call
  57270. + * to <code>dwc_otg_hc_start_transfer</code>. The caller must ensure there is
  57271. + * sufficient space in the request queue and Tx Data FIFO. This function
  57272. + * should only be called in Slave mode. In DMA mode, the controller acts
  57273. + * autonomously to complete transfers programmed to a host channel.
  57274. + *
  57275. + * For an OUT transfer, a new data packet is loaded into the appropriate FIFO
  57276. + * if there is any data remaining to be queued. For an IN transfer, another
  57277. + * data packet is always requested. For the SETUP phase of a control transfer,
  57278. + * this function does nothing.
  57279. + *
  57280. + * @return 1 if a new request is queued, 0 if no more requests are required
  57281. + * for this transfer.
  57282. + */
  57283. +int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  57284. +{
  57285. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  57286. +
  57287. + if (hc->do_split) {
  57288. + /* SPLITs always queue just once per channel */
  57289. + return 0;
  57290. + } else if (hc->data_pid_start == DWC_OTG_HC_PID_SETUP) {
  57291. + /* SETUPs are queued only once since they can't be NAKed. */
  57292. + return 0;
  57293. + } else if (hc->ep_is_in) {
  57294. + /*
  57295. + * Always queue another request for other IN transfers. If
  57296. + * back-to-back INs are issued and NAKs are received for both,
  57297. + * the driver may still be processing the first NAK when the
  57298. + * second NAK is received. When the interrupt handler clears
  57299. + * the NAK interrupt for the first NAK, the second NAK will
  57300. + * not be seen. So we can't depend on the NAK interrupt
  57301. + * handler to requeue a NAKed request. Instead, IN requests
  57302. + * are issued each time this function is called. When the
  57303. + * transfer completes, the extra requests for the channel will
  57304. + * be flushed.
  57305. + */
  57306. + hcchar_data_t hcchar;
  57307. + dwc_otg_hc_regs_t *hc_regs =
  57308. + core_if->host_if->hc_regs[hc->hc_num];
  57309. +
  57310. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  57311. + hc_set_even_odd_frame(core_if, hc, &hcchar);
  57312. + hcchar.b.chen = 1;
  57313. + hcchar.b.chdis = 0;
  57314. + DWC_DEBUGPL(DBG_HCDV, " IN xfer: hcchar = 0x%08x\n",
  57315. + hcchar.d32);
  57316. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  57317. + hc->requests++;
  57318. + return 1;
  57319. + } else {
  57320. + /* OUT transfers. */
  57321. + if (hc->xfer_count < hc->xfer_len) {
  57322. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  57323. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  57324. + hcchar_data_t hcchar;
  57325. + dwc_otg_hc_regs_t *hc_regs;
  57326. + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  57327. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  57328. + hc_set_even_odd_frame(core_if, hc, &hcchar);
  57329. + }
  57330. +
  57331. + /* Load OUT packet into the appropriate Tx FIFO. */
  57332. + dwc_otg_hc_write_packet(core_if, hc);
  57333. + hc->requests++;
  57334. + return 1;
  57335. + } else {
  57336. + return 0;
  57337. + }
  57338. + }
  57339. +}
  57340. +
  57341. +/**
  57342. + * Starts a PING transfer. This function should only be called in Slave mode.
  57343. + * The Do Ping bit is set in the HCTSIZ register, then the channel is enabled.
  57344. + */
  57345. +void dwc_otg_hc_do_ping(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  57346. +{
  57347. + hcchar_data_t hcchar;
  57348. + hctsiz_data_t hctsiz;
  57349. + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  57350. +
  57351. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  57352. +
  57353. + hctsiz.d32 = 0;
  57354. + hctsiz.b.dopng = 1;
  57355. + hctsiz.b.pktcnt = 1;
  57356. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  57357. +
  57358. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  57359. + hcchar.b.chen = 1;
  57360. + hcchar.b.chdis = 0;
  57361. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  57362. +}
  57363. +
  57364. +/*
  57365. + * This function writes a packet into the Tx FIFO associated with the Host
  57366. + * Channel. For a channel associated with a non-periodic EP, the non-periodic
  57367. + * Tx FIFO is written. For a channel associated with a periodic EP, the
  57368. + * periodic Tx FIFO is written. This function should only be called in Slave
  57369. + * mode.
  57370. + *
  57371. + * Upon return the xfer_buff and xfer_count fields in _hc are incremented by
  57372. + * then number of bytes written to the Tx FIFO.
  57373. + */
  57374. +void dwc_otg_hc_write_packet(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  57375. +{
  57376. + uint32_t i;
  57377. + uint32_t remaining_count;
  57378. + uint32_t byte_count;
  57379. + uint32_t dword_count;
  57380. +
  57381. + uint32_t *data_buff = (uint32_t *) (hc->xfer_buff);
  57382. + uint32_t *data_fifo = core_if->data_fifo[hc->hc_num];
  57383. +
  57384. + remaining_count = hc->xfer_len - hc->xfer_count;
  57385. + if (remaining_count > hc->max_packet) {
  57386. + byte_count = hc->max_packet;
  57387. + } else {
  57388. + byte_count = remaining_count;
  57389. + }
  57390. +
  57391. + dword_count = (byte_count + 3) / 4;
  57392. +
  57393. + if ((((unsigned long)data_buff) & 0x3) == 0) {
  57394. + /* xfer_buff is DWORD aligned. */
  57395. + for (i = 0; i < dword_count; i++, data_buff++) {
  57396. + DWC_WRITE_REG32(data_fifo, *data_buff);
  57397. + }
  57398. + } else {
  57399. + /* xfer_buff is not DWORD aligned. */
  57400. + for (i = 0; i < dword_count; i++, data_buff++) {
  57401. + uint32_t data;
  57402. + data =
  57403. + (data_buff[0] | data_buff[1] << 8 | data_buff[2] <<
  57404. + 16 | data_buff[3] << 24);
  57405. + DWC_WRITE_REG32(data_fifo, data);
  57406. + }
  57407. + }
  57408. +
  57409. + hc->xfer_count += byte_count;
  57410. + hc->xfer_buff += byte_count;
  57411. +}
  57412. +
  57413. +/**
  57414. + * Gets the current USB frame number. This is the frame number from the last
  57415. + * SOF packet.
  57416. + */
  57417. +uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t * core_if)
  57418. +{
  57419. + dsts_data_t dsts;
  57420. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  57421. +
  57422. + /* read current frame/microframe number from DSTS register */
  57423. + return dsts.b.soffn;
  57424. +}
  57425. +
  57426. +/**
  57427. + * Calculates and gets the frame Interval value of HFIR register according PHY
  57428. + * type and speed.The application can modify a value of HFIR register only after
  57429. + * the Port Enable bit of the Host Port Control and Status register
  57430. + * (HPRT.PrtEnaPort) has been set.
  57431. +*/
  57432. +
  57433. +uint32_t calc_frame_interval(dwc_otg_core_if_t * core_if)
  57434. +{
  57435. + gusbcfg_data_t usbcfg;
  57436. + hwcfg2_data_t hwcfg2;
  57437. + hprt0_data_t hprt0;
  57438. + int clock = 60; // default value
  57439. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  57440. + hwcfg2.d32 = DWC_READ_REG32(&core_if->core_global_regs->ghwcfg2);
  57441. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  57442. + if (!usbcfg.b.physel && usbcfg.b.ulpi_utmi_sel && !usbcfg.b.phyif)
  57443. + clock = 60;
  57444. + if (usbcfg.b.physel && hwcfg2.b.fs_phy_type == 3)
  57445. + clock = 48;
  57446. + if (!usbcfg.b.phylpwrclksel && !usbcfg.b.physel &&
  57447. + !usbcfg.b.ulpi_utmi_sel && usbcfg.b.phyif)
  57448. + clock = 30;
  57449. + if (!usbcfg.b.phylpwrclksel && !usbcfg.b.physel &&
  57450. + !usbcfg.b.ulpi_utmi_sel && !usbcfg.b.phyif)
  57451. + clock = 60;
  57452. + if (usbcfg.b.phylpwrclksel && !usbcfg.b.physel &&
  57453. + !usbcfg.b.ulpi_utmi_sel && usbcfg.b.phyif)
  57454. + clock = 48;
  57455. + if (usbcfg.b.physel && !usbcfg.b.phyif && hwcfg2.b.fs_phy_type == 2)
  57456. + clock = 48;
  57457. + if (usbcfg.b.physel && hwcfg2.b.fs_phy_type == 1)
  57458. + clock = 48;
  57459. + if (hprt0.b.prtspd == 0)
  57460. + /* High speed case */
  57461. + return 125 * clock;
  57462. + else
  57463. + /* FS/LS case */
  57464. + return 1000 * clock;
  57465. +}
  57466. +
  57467. +/**
  57468. + * This function reads a setup packet from the Rx FIFO into the destination
  57469. + * buffer. This function is called from the Rx Status Queue Level (RxStsQLvl)
  57470. + * Interrupt routine when a SETUP packet has been received in Slave mode.
  57471. + *
  57472. + * @param core_if Programming view of DWC_otg controller.
  57473. + * @param dest Destination buffer for packet data.
  57474. + */
  57475. +void dwc_otg_read_setup_packet(dwc_otg_core_if_t * core_if, uint32_t * dest)
  57476. +{
  57477. + device_grxsts_data_t status;
  57478. + /* Get the 8 bytes of a setup transaction data */
  57479. +
  57480. + /* Pop 2 DWORDS off the receive data FIFO into memory */
  57481. + dest[0] = DWC_READ_REG32(core_if->data_fifo[0]);
  57482. + dest[1] = DWC_READ_REG32(core_if->data_fifo[0]);
  57483. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  57484. + status.d32 =
  57485. + DWC_READ_REG32(&core_if->core_global_regs->grxstsp);
  57486. + DWC_DEBUGPL(DBG_ANY,
  57487. + "EP:%d BCnt:%d " "pktsts:%x Frame:%d(0x%0x)\n",
  57488. + status.b.epnum, status.b.bcnt, status.b.pktsts,
  57489. + status.b.fn, status.b.fn);
  57490. + }
  57491. +}
  57492. +
  57493. +/**
  57494. + * This function enables EP0 OUT to receive SETUP packets and configures EP0
  57495. + * IN for transmitting packets. It is normally called when the
  57496. + * "Enumeration Done" interrupt occurs.
  57497. + *
  57498. + * @param core_if Programming view of DWC_otg controller.
  57499. + * @param ep The EP0 data.
  57500. + */
  57501. +void dwc_otg_ep0_activate(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  57502. +{
  57503. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  57504. + dsts_data_t dsts;
  57505. + depctl_data_t diepctl;
  57506. + depctl_data_t doepctl;
  57507. + dctl_data_t dctl = {.d32 = 0 };
  57508. +
  57509. + ep->stp_rollover = 0;
  57510. + /* Read the Device Status and Endpoint 0 Control registers */
  57511. + dsts.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dsts);
  57512. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl);
  57513. + doepctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl);
  57514. +
  57515. + /* Set the MPS of the IN EP based on the enumeration speed */
  57516. + switch (dsts.b.enumspd) {
  57517. + case DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ:
  57518. + case DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ:
  57519. + case DWC_DSTS_ENUMSPD_FS_PHY_48MHZ:
  57520. + diepctl.b.mps = DWC_DEP0CTL_MPS_64;
  57521. + break;
  57522. + case DWC_DSTS_ENUMSPD_LS_PHY_6MHZ:
  57523. + diepctl.b.mps = DWC_DEP0CTL_MPS_8;
  57524. + break;
  57525. + }
  57526. +
  57527. + DWC_WRITE_REG32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
  57528. +
  57529. + /* Enable OUT EP for receive */
  57530. + if (core_if->snpsid <= OTG_CORE_REV_2_94a) {
  57531. + doepctl.b.epena = 1;
  57532. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepctl, doepctl.d32);
  57533. + }
  57534. +#ifdef VERBOSE
  57535. + DWC_DEBUGPL(DBG_PCDV, "doepctl0=%0x\n",
  57536. + DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl));
  57537. + DWC_DEBUGPL(DBG_PCDV, "diepctl0=%0x\n",
  57538. + DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl));
  57539. +#endif
  57540. + dctl.b.cgnpinnak = 1;
  57541. +
  57542. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  57543. + DWC_DEBUGPL(DBG_PCDV, "dctl=%0x\n",
  57544. + DWC_READ_REG32(&dev_if->dev_global_regs->dctl));
  57545. +
  57546. +}
  57547. +
  57548. +/**
  57549. + * This function activates an EP. The Device EP control register for
  57550. + * the EP is configured as defined in the ep structure. Note: This
  57551. + * function is not used for EP0.
  57552. + *
  57553. + * @param core_if Programming view of DWC_otg controller.
  57554. + * @param ep The EP to activate.
  57555. + */
  57556. +void dwc_otg_ep_activate(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  57557. +{
  57558. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  57559. + depctl_data_t depctl;
  57560. + volatile uint32_t *addr;
  57561. + daint_data_t daintmsk = {.d32 = 0 };
  57562. + dcfg_data_t dcfg;
  57563. + uint8_t i;
  57564. +
  57565. + DWC_DEBUGPL(DBG_PCDV, "%s() EP%d-%s\n", __func__, ep->num,
  57566. + (ep->is_in ? "IN" : "OUT"));
  57567. +
  57568. +#ifdef DWC_UTE_PER_IO
  57569. + ep->xiso_frame_num = 0xFFFFFFFF;
  57570. + ep->xiso_active_xfers = 0;
  57571. + ep->xiso_queued_xfers = 0;
  57572. +#endif
  57573. + /* Read DEPCTLn register */
  57574. + if (ep->is_in == 1) {
  57575. + addr = &dev_if->in_ep_regs[ep->num]->diepctl;
  57576. + daintmsk.ep.in = 1 << ep->num;
  57577. + } else {
  57578. + addr = &dev_if->out_ep_regs[ep->num]->doepctl;
  57579. + daintmsk.ep.out = 1 << ep->num;
  57580. + }
  57581. +
  57582. + /* If the EP is already active don't change the EP Control
  57583. + * register. */
  57584. + depctl.d32 = DWC_READ_REG32(addr);
  57585. + if (!depctl.b.usbactep) {
  57586. + depctl.b.mps = ep->maxpacket;
  57587. + depctl.b.eptype = ep->type;
  57588. + depctl.b.txfnum = ep->tx_fifo_num;
  57589. +
  57590. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  57591. + depctl.b.setd0pid = 1; // ???
  57592. + } else {
  57593. + depctl.b.setd0pid = 1;
  57594. + }
  57595. + depctl.b.usbactep = 1;
  57596. +
  57597. + /* Update nextep_seq array and EPMSCNT in DCFG*/
  57598. + if (!(depctl.b.eptype & 1) && (ep->is_in == 1)) { // NP IN EP
  57599. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  57600. + if (core_if->nextep_seq[i] == core_if->first_in_nextep_seq)
  57601. + break;
  57602. + }
  57603. + core_if->nextep_seq[i] = ep->num;
  57604. + core_if->nextep_seq[ep->num] = core_if->first_in_nextep_seq;
  57605. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  57606. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  57607. + dcfg.b.epmscnt++;
  57608. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  57609. +
  57610. + DWC_DEBUGPL(DBG_PCDV,
  57611. + "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  57612. + __func__, core_if->first_in_nextep_seq);
  57613. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  57614. + DWC_DEBUGPL(DBG_PCDV, "%2d\n",
  57615. + core_if->nextep_seq[i]);
  57616. + }
  57617. +
  57618. + }
  57619. +
  57620. +
  57621. + DWC_WRITE_REG32(addr, depctl.d32);
  57622. + DWC_DEBUGPL(DBG_PCDV, "DEPCTL=%08x\n", DWC_READ_REG32(addr));
  57623. + }
  57624. +
  57625. + /* Enable the Interrupt for this EP */
  57626. + if (core_if->multiproc_int_enable) {
  57627. + if (ep->is_in == 1) {
  57628. + diepmsk_data_t diepmsk = {.d32 = 0 };
  57629. + diepmsk.b.xfercompl = 1;
  57630. + diepmsk.b.timeout = 1;
  57631. + diepmsk.b.epdisabled = 1;
  57632. + diepmsk.b.ahberr = 1;
  57633. + diepmsk.b.intknepmis = 1;
  57634. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable)
  57635. + diepmsk.b.intknepmis = 0;
  57636. + diepmsk.b.txfifoundrn = 1; //?????
  57637. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  57638. + diepmsk.b.nak = 1;
  57639. + }
  57640. +
  57641. +
  57642. +
  57643. +/*
  57644. + if (core_if->dma_desc_enable) {
  57645. + diepmsk.b.bna = 1;
  57646. + }
  57647. +*/
  57648. +/*
  57649. + if (core_if->dma_enable) {
  57650. + doepmsk.b.nak = 1;
  57651. + }
  57652. +*/
  57653. + DWC_WRITE_REG32(&dev_if->dev_global_regs->
  57654. + diepeachintmsk[ep->num], diepmsk.d32);
  57655. +
  57656. + } else {
  57657. + doepmsk_data_t doepmsk = {.d32 = 0 };
  57658. + doepmsk.b.xfercompl = 1;
  57659. + doepmsk.b.ahberr = 1;
  57660. + doepmsk.b.epdisabled = 1;
  57661. + if (ep->type == DWC_OTG_EP_TYPE_ISOC)
  57662. + doepmsk.b.outtknepdis = 1;
  57663. +
  57664. +/*
  57665. +
  57666. + if (core_if->dma_desc_enable) {
  57667. + doepmsk.b.bna = 1;
  57668. + }
  57669. +*/
  57670. +/*
  57671. + doepmsk.b.babble = 1;
  57672. + doepmsk.b.nyet = 1;
  57673. + doepmsk.b.nak = 1;
  57674. +*/
  57675. + DWC_WRITE_REG32(&dev_if->dev_global_regs->
  57676. + doepeachintmsk[ep->num], doepmsk.d32);
  57677. + }
  57678. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->deachintmsk,
  57679. + 0, daintmsk.d32);
  57680. + } else {
  57681. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  57682. + if (ep->is_in) {
  57683. + diepmsk_data_t diepmsk = {.d32 = 0 };
  57684. + diepmsk.b.nak = 1;
  57685. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->diepmsk, 0, diepmsk.d32);
  57686. + } else {
  57687. + doepmsk_data_t doepmsk = {.d32 = 0 };
  57688. + doepmsk.b.outtknepdis = 1;
  57689. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->doepmsk, 0, doepmsk.d32);
  57690. + }
  57691. + }
  57692. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->daintmsk,
  57693. + 0, daintmsk.d32);
  57694. + }
  57695. +
  57696. + DWC_DEBUGPL(DBG_PCDV, "DAINTMSK=%0x\n",
  57697. + DWC_READ_REG32(&dev_if->dev_global_regs->daintmsk));
  57698. +
  57699. + ep->stall_clear_flag = 0;
  57700. +
  57701. + return;
  57702. +}
  57703. +
  57704. +/**
  57705. + * This function deactivates an EP. This is done by clearing the USB Active
  57706. + * EP bit in the Device EP control register. Note: This function is not used
  57707. + * for EP0. EP0 cannot be deactivated.
  57708. + *
  57709. + * @param core_if Programming view of DWC_otg controller.
  57710. + * @param ep The EP to deactivate.
  57711. + */
  57712. +void dwc_otg_ep_deactivate(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  57713. +{
  57714. + depctl_data_t depctl = {.d32 = 0 };
  57715. + volatile uint32_t *addr;
  57716. + daint_data_t daintmsk = {.d32 = 0 };
  57717. + dcfg_data_t dcfg;
  57718. + uint8_t i = 0;
  57719. +
  57720. +#ifdef DWC_UTE_PER_IO
  57721. + ep->xiso_frame_num = 0xFFFFFFFF;
  57722. + ep->xiso_active_xfers = 0;
  57723. + ep->xiso_queued_xfers = 0;
  57724. +#endif
  57725. +
  57726. + /* Read DEPCTLn register */
  57727. + if (ep->is_in == 1) {
  57728. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  57729. + daintmsk.ep.in = 1 << ep->num;
  57730. + } else {
  57731. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  57732. + daintmsk.ep.out = 1 << ep->num;
  57733. + }
  57734. +
  57735. + depctl.d32 = DWC_READ_REG32(addr);
  57736. +
  57737. + depctl.b.usbactep = 0;
  57738. +
  57739. + /* Update nextep_seq array and EPMSCNT in DCFG*/
  57740. + if (!(depctl.b.eptype & 1) && ep->is_in == 1) { // NP EP IN
  57741. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  57742. + if (core_if->nextep_seq[i] == ep->num)
  57743. + break;
  57744. + }
  57745. + core_if->nextep_seq[i] = core_if->nextep_seq[ep->num];
  57746. + if (core_if->first_in_nextep_seq == ep->num)
  57747. + core_if->first_in_nextep_seq = i;
  57748. + core_if->nextep_seq[ep->num] = 0xff;
  57749. + depctl.b.nextep = 0;
  57750. + dcfg.d32 =
  57751. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  57752. + dcfg.b.epmscnt--;
  57753. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg,
  57754. + dcfg.d32);
  57755. +
  57756. + DWC_DEBUGPL(DBG_PCDV,
  57757. + "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  57758. + __func__, core_if->first_in_nextep_seq);
  57759. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  57760. + DWC_DEBUGPL(DBG_PCDV, "%2d\n", core_if->nextep_seq[i]);
  57761. + }
  57762. + }
  57763. +
  57764. + if (ep->is_in == 1)
  57765. + depctl.b.txfnum = 0;
  57766. +
  57767. + if (core_if->dma_desc_enable)
  57768. + depctl.b.epdis = 1;
  57769. +
  57770. + DWC_WRITE_REG32(addr, depctl.d32);
  57771. + depctl.d32 = DWC_READ_REG32(addr);
  57772. + if (core_if->dma_enable && ep->type == DWC_OTG_EP_TYPE_ISOC
  57773. + && depctl.b.epena) {
  57774. + depctl_data_t depctl = {.d32 = 0};
  57775. + if (ep->is_in) {
  57776. + diepint_data_t diepint = {.d32 = 0};
  57777. +
  57778. + depctl.b.snak = 1;
  57779. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  57780. + diepctl, depctl.d32);
  57781. + do {
  57782. + dwc_udelay(10);
  57783. + diepint.d32 =
  57784. + DWC_READ_REG32(&core_if->
  57785. + dev_if->in_ep_regs[ep->num]->
  57786. + diepint);
  57787. + } while (!diepint.b.inepnakeff);
  57788. + diepint.b.inepnakeff = 1;
  57789. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  57790. + diepint, diepint.d32);
  57791. + depctl.d32 = 0;
  57792. + depctl.b.epdis = 1;
  57793. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  57794. + diepctl, depctl.d32);
  57795. + do {
  57796. + dwc_udelay(10);
  57797. + diepint.d32 =
  57798. + DWC_READ_REG32(&core_if->
  57799. + dev_if->in_ep_regs[ep->num]->
  57800. + diepint);
  57801. + } while (!diepint.b.epdisabled);
  57802. + diepint.b.epdisabled = 1;
  57803. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  57804. + diepint, diepint.d32);
  57805. + } else {
  57806. + dctl_data_t dctl = {.d32 = 0};
  57807. + gintmsk_data_t gintsts = {.d32 = 0};
  57808. + doepint_data_t doepint = {.d32 = 0};
  57809. + dctl.b.sgoutnak = 1;
  57810. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  57811. + dctl, 0, dctl.d32);
  57812. + do {
  57813. + dwc_udelay(10);
  57814. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  57815. + } while (!gintsts.b.goutnakeff);
  57816. + gintsts.d32 = 0;
  57817. + gintsts.b.goutnakeff = 1;
  57818. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  57819. +
  57820. + depctl.d32 = 0;
  57821. + depctl.b.epdis = 1;
  57822. + depctl.b.snak = 1;
  57823. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[ep->num]->doepctl, depctl.d32);
  57824. + do
  57825. + {
  57826. + dwc_udelay(10);
  57827. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  57828. + out_ep_regs[ep->num]->doepint);
  57829. + } while (!doepint.b.epdisabled);
  57830. +
  57831. + doepint.b.epdisabled = 1;
  57832. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[ep->num]->doepint, doepint.d32);
  57833. +
  57834. + dctl.d32 = 0;
  57835. + dctl.b.cgoutnak = 1;
  57836. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  57837. + }
  57838. + }
  57839. +
  57840. + /* Disable the Interrupt for this EP */
  57841. + if (core_if->multiproc_int_enable) {
  57842. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->deachintmsk,
  57843. + daintmsk.d32, 0);
  57844. +
  57845. + if (ep->is_in == 1) {
  57846. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  57847. + diepeachintmsk[ep->num], 0);
  57848. + } else {
  57849. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  57850. + doepeachintmsk[ep->num], 0);
  57851. + }
  57852. + } else {
  57853. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->daintmsk,
  57854. + daintmsk.d32, 0);
  57855. + }
  57856. +
  57857. +}
  57858. +
  57859. +/**
  57860. + * This function initializes dma descriptor chain.
  57861. + *
  57862. + * @param core_if Programming view of DWC_otg controller.
  57863. + * @param ep The EP to start the transfer on.
  57864. + */
  57865. +static void init_dma_desc_chain(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  57866. +{
  57867. + dwc_otg_dev_dma_desc_t *dma_desc;
  57868. + uint32_t offset;
  57869. + uint32_t xfer_est;
  57870. + int i;
  57871. + unsigned maxxfer_local, total_len;
  57872. +
  57873. + if (!ep->is_in && ep->type == DWC_OTG_EP_TYPE_INTR &&
  57874. + (ep->maxpacket%4)) {
  57875. + maxxfer_local = ep->maxpacket;
  57876. + total_len = ep->xfer_len;
  57877. + } else {
  57878. + maxxfer_local = ep->maxxfer;
  57879. + total_len = ep->total_len;
  57880. + }
  57881. +
  57882. + ep->desc_cnt = (total_len / maxxfer_local) +
  57883. + ((total_len % maxxfer_local) ? 1 : 0);
  57884. +
  57885. + if (!ep->desc_cnt)
  57886. + ep->desc_cnt = 1;
  57887. +
  57888. + if (ep->desc_cnt > MAX_DMA_DESC_CNT)
  57889. + ep->desc_cnt = MAX_DMA_DESC_CNT;
  57890. +
  57891. + dma_desc = ep->desc_addr;
  57892. + if (maxxfer_local == ep->maxpacket) {
  57893. + if ((total_len % maxxfer_local) &&
  57894. + (total_len/maxxfer_local < MAX_DMA_DESC_CNT)) {
  57895. + xfer_est = (ep->desc_cnt - 1) * maxxfer_local +
  57896. + (total_len % maxxfer_local);
  57897. + } else
  57898. + xfer_est = ep->desc_cnt * maxxfer_local;
  57899. + } else
  57900. + xfer_est = total_len;
  57901. + offset = 0;
  57902. + for (i = 0; i < ep->desc_cnt; ++i) {
  57903. + /** DMA Descriptor Setup */
  57904. + if (xfer_est > maxxfer_local) {
  57905. + dma_desc->status.b.bs = BS_HOST_BUSY;
  57906. + dma_desc->status.b.l = 0;
  57907. + dma_desc->status.b.ioc = 0;
  57908. + dma_desc->status.b.sp = 0;
  57909. + dma_desc->status.b.bytes = maxxfer_local;
  57910. + dma_desc->buf = ep->dma_addr + offset;
  57911. + dma_desc->status.b.sts = 0;
  57912. + dma_desc->status.b.bs = BS_HOST_READY;
  57913. +
  57914. + xfer_est -= maxxfer_local;
  57915. + offset += maxxfer_local;
  57916. + } else {
  57917. + dma_desc->status.b.bs = BS_HOST_BUSY;
  57918. + dma_desc->status.b.l = 1;
  57919. + dma_desc->status.b.ioc = 1;
  57920. + if (ep->is_in) {
  57921. + dma_desc->status.b.sp =
  57922. + (xfer_est %
  57923. + ep->maxpacket) ? 1 : ((ep->
  57924. + sent_zlp) ? 1 : 0);
  57925. + dma_desc->status.b.bytes = xfer_est;
  57926. + } else {
  57927. + if (maxxfer_local == ep->maxpacket)
  57928. + dma_desc->status.b.bytes = xfer_est;
  57929. + else
  57930. + dma_desc->status.b.bytes =
  57931. + xfer_est + ((4 - (xfer_est & 0x3)) & 0x3);
  57932. + }
  57933. +
  57934. + dma_desc->buf = ep->dma_addr + offset;
  57935. + dma_desc->status.b.sts = 0;
  57936. + dma_desc->status.b.bs = BS_HOST_READY;
  57937. + }
  57938. + dma_desc++;
  57939. + }
  57940. +}
  57941. +/**
  57942. + * This function is called when to write ISOC data into appropriate dedicated
  57943. + * periodic FIFO.
  57944. + */
  57945. +static int32_t write_isoc_tx_fifo(dwc_otg_core_if_t * core_if, dwc_ep_t * dwc_ep)
  57946. +{
  57947. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  57948. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  57949. + dtxfsts_data_t txstatus = {.d32 = 0 };
  57950. + uint32_t len = 0;
  57951. + int epnum = dwc_ep->num;
  57952. + int dwords;
  57953. +
  57954. + DWC_DEBUGPL(DBG_PCD, "Dedicated TxFifo Empty: %d \n", epnum);
  57955. +
  57956. + ep_regs = core_if->dev_if->in_ep_regs[epnum];
  57957. +
  57958. + len = dwc_ep->xfer_len - dwc_ep->xfer_count;
  57959. +
  57960. + if (len > dwc_ep->maxpacket) {
  57961. + len = dwc_ep->maxpacket;
  57962. + }
  57963. +
  57964. + dwords = (len + 3) / 4;
  57965. +
  57966. + /* While there is space in the queue and space in the FIFO and
  57967. + * More data to tranfer, Write packets to the Tx FIFO */
  57968. + txstatus.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  57969. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum, txstatus.d32);
  57970. +
  57971. + while (txstatus.b.txfspcavail > dwords &&
  57972. + dwc_ep->xfer_count < dwc_ep->xfer_len && dwc_ep->xfer_len != 0) {
  57973. + /* Write the FIFO */
  57974. + dwc_otg_ep_write_packet(core_if, dwc_ep, 0);
  57975. +
  57976. + len = dwc_ep->xfer_len - dwc_ep->xfer_count;
  57977. + if (len > dwc_ep->maxpacket) {
  57978. + len = dwc_ep->maxpacket;
  57979. + }
  57980. +
  57981. + dwords = (len + 3) / 4;
  57982. + txstatus.d32 =
  57983. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  57984. + DWC_DEBUGPL(DBG_PCDV, "dtxfsts[%d]=0x%08x\n", epnum,
  57985. + txstatus.d32);
  57986. + }
  57987. +
  57988. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum,
  57989. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts));
  57990. +
  57991. + return 1;
  57992. +}
  57993. +/**
  57994. + * This function does the setup for a data transfer for an EP and
  57995. + * starts the transfer. For an IN transfer, the packets will be
  57996. + * loaded into the appropriate Tx FIFO in the ISR. For OUT transfers,
  57997. + * the packets are unloaded from the Rx FIFO in the ISR. the ISR.
  57998. + *
  57999. + * @param core_if Programming view of DWC_otg controller.
  58000. + * @param ep The EP to start the transfer on.
  58001. + */
  58002. +
  58003. +void dwc_otg_ep_start_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  58004. +{
  58005. + depctl_data_t depctl;
  58006. + deptsiz_data_t deptsiz;
  58007. + gintmsk_data_t intr_mask = {.d32 = 0 };
  58008. +
  58009. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s()\n", __func__);
  58010. + DWC_DEBUGPL(DBG_PCD, "ep%d-%s xfer_len=%d xfer_cnt=%d "
  58011. + "xfer_buff=%p start_xfer_buff=%p, total_len = %d\n",
  58012. + ep->num, (ep->is_in ? "IN" : "OUT"), ep->xfer_len,
  58013. + ep->xfer_count, ep->xfer_buff, ep->start_xfer_buff,
  58014. + ep->total_len);
  58015. + /* IN endpoint */
  58016. + if (ep->is_in == 1) {
  58017. + dwc_otg_dev_in_ep_regs_t *in_regs =
  58018. + core_if->dev_if->in_ep_regs[ep->num];
  58019. +
  58020. + gnptxsts_data_t gtxstatus;
  58021. +
  58022. + gtxstatus.d32 =
  58023. + DWC_READ_REG32(&core_if->core_global_regs->gnptxsts);
  58024. +
  58025. + if (core_if->en_multiple_tx_fifo == 0
  58026. + && gtxstatus.b.nptxqspcavail == 0 && !core_if->dma_enable) {
  58027. +#ifdef DEBUG
  58028. + DWC_PRINTF("TX Queue Full (0x%0x)\n", gtxstatus.d32);
  58029. +#endif
  58030. + return;
  58031. + }
  58032. +
  58033. + depctl.d32 = DWC_READ_REG32(&(in_regs->diepctl));
  58034. + deptsiz.d32 = DWC_READ_REG32(&(in_regs->dieptsiz));
  58035. +
  58036. + if (ep->maxpacket > ep->maxxfer / MAX_PKT_CNT)
  58037. + ep->xfer_len += (ep->maxxfer < (ep->total_len - ep->xfer_len)) ?
  58038. + ep->maxxfer : (ep->total_len - ep->xfer_len);
  58039. + else
  58040. + ep->xfer_len += (MAX_PKT_CNT * ep->maxpacket < (ep->total_len - ep->xfer_len)) ?
  58041. + MAX_PKT_CNT * ep->maxpacket : (ep->total_len - ep->xfer_len);
  58042. +
  58043. +
  58044. + /* Zero Length Packet? */
  58045. + if ((ep->xfer_len - ep->xfer_count) == 0) {
  58046. + deptsiz.b.xfersize = 0;
  58047. + deptsiz.b.pktcnt = 1;
  58048. + } else {
  58049. + /* Program the transfer size and packet count
  58050. + * as follows: xfersize = N * maxpacket +
  58051. + * short_packet pktcnt = N + (short_packet
  58052. + * exist ? 1 : 0)
  58053. + */
  58054. + deptsiz.b.xfersize = ep->xfer_len - ep->xfer_count;
  58055. + deptsiz.b.pktcnt =
  58056. + (ep->xfer_len - ep->xfer_count - 1 +
  58057. + ep->maxpacket) / ep->maxpacket;
  58058. + if (deptsiz.b.pktcnt > MAX_PKT_CNT) {
  58059. + deptsiz.b.pktcnt = MAX_PKT_CNT;
  58060. + deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
  58061. + }
  58062. + if (ep->type == DWC_OTG_EP_TYPE_ISOC)
  58063. + deptsiz.b.mc = deptsiz.b.pktcnt;
  58064. + }
  58065. +
  58066. + /* Write the DMA register */
  58067. + if (core_if->dma_enable) {
  58068. + if (core_if->dma_desc_enable == 0) {
  58069. + if (ep->type != DWC_OTG_EP_TYPE_ISOC)
  58070. + deptsiz.b.mc = 1;
  58071. + DWC_WRITE_REG32(&in_regs->dieptsiz,
  58072. + deptsiz.d32);
  58073. + DWC_WRITE_REG32(&(in_regs->diepdma),
  58074. + (uint32_t) ep->dma_addr);
  58075. + } else {
  58076. +#ifdef DWC_UTE_CFI
  58077. + /* The descriptor chain should be already initialized by now */
  58078. + if (ep->buff_mode != BM_STANDARD) {
  58079. + DWC_WRITE_REG32(&in_regs->diepdma,
  58080. + ep->descs_dma_addr);
  58081. + } else {
  58082. +#endif
  58083. + init_dma_desc_chain(core_if, ep);
  58084. + /** DIEPDMAn Register write */
  58085. + DWC_WRITE_REG32(&in_regs->diepdma,
  58086. + ep->dma_desc_addr);
  58087. +#ifdef DWC_UTE_CFI
  58088. + }
  58089. +#endif
  58090. + }
  58091. + } else {
  58092. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  58093. + if (ep->type != DWC_OTG_EP_TYPE_ISOC) {
  58094. + /**
  58095. + * Enable the Non-Periodic Tx FIFO empty interrupt,
  58096. + * or the Tx FIFO epmty interrupt in dedicated Tx FIFO mode,
  58097. + * the data will be written into the fifo by the ISR.
  58098. + */
  58099. + if (core_if->en_multiple_tx_fifo == 0) {
  58100. + intr_mask.b.nptxfempty = 1;
  58101. + DWC_MODIFY_REG32
  58102. + (&core_if->core_global_regs->gintmsk,
  58103. + intr_mask.d32, intr_mask.d32);
  58104. + } else {
  58105. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  58106. + if (ep->xfer_len > 0) {
  58107. + uint32_t fifoemptymsk = 0;
  58108. + fifoemptymsk = 1 << ep->num;
  58109. + DWC_MODIFY_REG32
  58110. + (&core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  58111. + 0, fifoemptymsk);
  58112. +
  58113. + }
  58114. + }
  58115. + } else {
  58116. + write_isoc_tx_fifo(core_if, ep);
  58117. + }
  58118. + }
  58119. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  58120. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  58121. +
  58122. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  58123. + dsts_data_t dsts = {.d32 = 0};
  58124. + if (ep->bInterval == 1) {
  58125. + dsts.d32 =
  58126. + DWC_READ_REG32(&core_if->dev_if->
  58127. + dev_global_regs->dsts);
  58128. + ep->frame_num = dsts.b.soffn + ep->bInterval;
  58129. + if (ep->frame_num > 0x3FFF) {
  58130. + ep->frm_overrun = 1;
  58131. + ep->frame_num &= 0x3FFF;
  58132. + } else
  58133. + ep->frm_overrun = 0;
  58134. + if (ep->frame_num & 0x1) {
  58135. + depctl.b.setd1pid = 1;
  58136. + } else {
  58137. + depctl.b.setd0pid = 1;
  58138. + }
  58139. + }
  58140. + }
  58141. + /* EP enable, IN data in FIFO */
  58142. + depctl.b.cnak = 1;
  58143. + depctl.b.epena = 1;
  58144. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  58145. +
  58146. + } else {
  58147. + /* OUT endpoint */
  58148. + dwc_otg_dev_out_ep_regs_t *out_regs =
  58149. + core_if->dev_if->out_ep_regs[ep->num];
  58150. +
  58151. + depctl.d32 = DWC_READ_REG32(&(out_regs->doepctl));
  58152. + deptsiz.d32 = DWC_READ_REG32(&(out_regs->doeptsiz));
  58153. +
  58154. + if (!core_if->dma_desc_enable) {
  58155. + if (ep->maxpacket > ep->maxxfer / MAX_PKT_CNT)
  58156. + ep->xfer_len += (ep->maxxfer < (ep->total_len - ep->xfer_len)) ?
  58157. + ep->maxxfer : (ep->total_len - ep->xfer_len);
  58158. + else
  58159. + ep->xfer_len += (MAX_PKT_CNT * ep->maxpacket < (ep->total_len
  58160. + - ep->xfer_len)) ? MAX_PKT_CNT * ep->maxpacket : (ep->total_len - ep->xfer_len);
  58161. + }
  58162. +
  58163. + /* Program the transfer size and packet count as follows:
  58164. + *
  58165. + * pktcnt = N
  58166. + * xfersize = N * maxpacket
  58167. + */
  58168. + if ((ep->xfer_len - ep->xfer_count) == 0) {
  58169. + /* Zero Length Packet */
  58170. + deptsiz.b.xfersize = ep->maxpacket;
  58171. + deptsiz.b.pktcnt = 1;
  58172. + } else {
  58173. + deptsiz.b.pktcnt =
  58174. + (ep->xfer_len - ep->xfer_count +
  58175. + (ep->maxpacket - 1)) / ep->maxpacket;
  58176. + if (deptsiz.b.pktcnt > MAX_PKT_CNT) {
  58177. + deptsiz.b.pktcnt = MAX_PKT_CNT;
  58178. + }
  58179. + if (!core_if->dma_desc_enable) {
  58180. + ep->xfer_len =
  58181. + deptsiz.b.pktcnt * ep->maxpacket + ep->xfer_count;
  58182. + }
  58183. + deptsiz.b.xfersize = ep->xfer_len - ep->xfer_count;
  58184. + }
  58185. +
  58186. + DWC_DEBUGPL(DBG_PCDV, "ep%d xfersize=%d pktcnt=%d\n",
  58187. + ep->num, deptsiz.b.xfersize, deptsiz.b.pktcnt);
  58188. +
  58189. + if (core_if->dma_enable) {
  58190. + if (!core_if->dma_desc_enable) {
  58191. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  58192. + deptsiz.d32);
  58193. +
  58194. + DWC_WRITE_REG32(&(out_regs->doepdma),
  58195. + (uint32_t) ep->dma_addr);
  58196. + } else {
  58197. +#ifdef DWC_UTE_CFI
  58198. + /* The descriptor chain should be already initialized by now */
  58199. + if (ep->buff_mode != BM_STANDARD) {
  58200. + DWC_WRITE_REG32(&out_regs->doepdma,
  58201. + ep->descs_dma_addr);
  58202. + } else {
  58203. +#endif
  58204. + /** This is used for interrupt out transfers*/
  58205. + if (!ep->xfer_len)
  58206. + ep->xfer_len = ep->total_len;
  58207. + init_dma_desc_chain(core_if, ep);
  58208. +
  58209. + if (core_if->core_params->dev_out_nak) {
  58210. + if (ep->type == DWC_OTG_EP_TYPE_BULK) {
  58211. + deptsiz.b.pktcnt = (ep->total_len +
  58212. + (ep->maxpacket - 1)) / ep->maxpacket;
  58213. + deptsiz.b.xfersize = ep->total_len;
  58214. + /* Remember initial value of doeptsiz */
  58215. + core_if->start_doeptsiz_val[ep->num] = deptsiz.d32;
  58216. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  58217. + deptsiz.d32);
  58218. + }
  58219. + }
  58220. + /** DOEPDMAn Register write */
  58221. + DWC_WRITE_REG32(&out_regs->doepdma,
  58222. + ep->dma_desc_addr);
  58223. +#ifdef DWC_UTE_CFI
  58224. + }
  58225. +#endif
  58226. + }
  58227. + } else {
  58228. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  58229. + }
  58230. +
  58231. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  58232. + dsts_data_t dsts = {.d32 = 0};
  58233. + if (ep->bInterval == 1) {
  58234. + dsts.d32 =
  58235. + DWC_READ_REG32(&core_if->dev_if->
  58236. + dev_global_regs->dsts);
  58237. + ep->frame_num = dsts.b.soffn + ep->bInterval;
  58238. + if (ep->frame_num > 0x3FFF) {
  58239. + ep->frm_overrun = 1;
  58240. + ep->frame_num &= 0x3FFF;
  58241. + } else
  58242. + ep->frm_overrun = 0;
  58243. +
  58244. + if (ep->frame_num & 0x1) {
  58245. + depctl.b.setd1pid = 1;
  58246. + } else {
  58247. + depctl.b.setd0pid = 1;
  58248. + }
  58249. + }
  58250. + }
  58251. +
  58252. + /* EP enable */
  58253. + depctl.b.cnak = 1;
  58254. + depctl.b.epena = 1;
  58255. +
  58256. + DWC_WRITE_REG32(&out_regs->doepctl, depctl.d32);
  58257. +
  58258. + DWC_DEBUGPL(DBG_PCD, "DOEPCTL=%08x DOEPTSIZ=%08x\n",
  58259. + DWC_READ_REG32(&out_regs->doepctl),
  58260. + DWC_READ_REG32(&out_regs->doeptsiz));
  58261. + DWC_DEBUGPL(DBG_PCD, "DAINTMSK=%08x GINTMSK=%08x\n",
  58262. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->
  58263. + daintmsk),
  58264. + DWC_READ_REG32(&core_if->core_global_regs->
  58265. + gintmsk));
  58266. +
  58267. + /* Timer is scheduling only for out bulk transfers for
  58268. + * "Device DDMA OUT NAK Enhancement" feature to inform user
  58269. + * about received data payload in case of timeout
  58270. + */
  58271. + if (core_if->core_params->dev_out_nak) {
  58272. + if (ep->type == DWC_OTG_EP_TYPE_BULK) {
  58273. + core_if->ep_xfer_info[ep->num].core_if = core_if;
  58274. + core_if->ep_xfer_info[ep->num].ep = ep;
  58275. + core_if->ep_xfer_info[ep->num].state = 1;
  58276. +
  58277. + /* Start a timer for this transfer. */
  58278. + DWC_TIMER_SCHEDULE(core_if->ep_xfer_timer[ep->num], 10000);
  58279. + }
  58280. + }
  58281. + }
  58282. +}
  58283. +
  58284. +/**
  58285. + * This function setup a zero length transfer in Buffer DMA and
  58286. + * Slave modes for usb requests with zero field set
  58287. + *
  58288. + * @param core_if Programming view of DWC_otg controller.
  58289. + * @param ep The EP to start the transfer on.
  58290. + *
  58291. + */
  58292. +void dwc_otg_ep_start_zl_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  58293. +{
  58294. +
  58295. + depctl_data_t depctl;
  58296. + deptsiz_data_t deptsiz;
  58297. + gintmsk_data_t intr_mask = {.d32 = 0 };
  58298. +
  58299. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s()\n", __func__);
  58300. + DWC_PRINTF("zero length transfer is called\n");
  58301. +
  58302. + /* IN endpoint */
  58303. + if (ep->is_in == 1) {
  58304. + dwc_otg_dev_in_ep_regs_t *in_regs =
  58305. + core_if->dev_if->in_ep_regs[ep->num];
  58306. +
  58307. + depctl.d32 = DWC_READ_REG32(&(in_regs->diepctl));
  58308. + deptsiz.d32 = DWC_READ_REG32(&(in_regs->dieptsiz));
  58309. +
  58310. + deptsiz.b.xfersize = 0;
  58311. + deptsiz.b.pktcnt = 1;
  58312. +
  58313. + /* Write the DMA register */
  58314. + if (core_if->dma_enable) {
  58315. + if (core_if->dma_desc_enable == 0) {
  58316. + deptsiz.b.mc = 1;
  58317. + DWC_WRITE_REG32(&in_regs->dieptsiz,
  58318. + deptsiz.d32);
  58319. + DWC_WRITE_REG32(&(in_regs->diepdma),
  58320. + (uint32_t) ep->dma_addr);
  58321. + }
  58322. + } else {
  58323. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  58324. + /**
  58325. + * Enable the Non-Periodic Tx FIFO empty interrupt,
  58326. + * or the Tx FIFO epmty interrupt in dedicated Tx FIFO mode,
  58327. + * the data will be written into the fifo by the ISR.
  58328. + */
  58329. + if (core_if->en_multiple_tx_fifo == 0) {
  58330. + intr_mask.b.nptxfempty = 1;
  58331. + DWC_MODIFY_REG32(&core_if->
  58332. + core_global_regs->gintmsk,
  58333. + intr_mask.d32, intr_mask.d32);
  58334. + } else {
  58335. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  58336. + if (ep->xfer_len > 0) {
  58337. + uint32_t fifoemptymsk = 0;
  58338. + fifoemptymsk = 1 << ep->num;
  58339. + DWC_MODIFY_REG32(&core_if->
  58340. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  58341. + 0, fifoemptymsk);
  58342. + }
  58343. + }
  58344. + }
  58345. +
  58346. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  58347. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  58348. + /* EP enable, IN data in FIFO */
  58349. + depctl.b.cnak = 1;
  58350. + depctl.b.epena = 1;
  58351. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  58352. +
  58353. + } else {
  58354. + /* OUT endpoint */
  58355. + dwc_otg_dev_out_ep_regs_t *out_regs =
  58356. + core_if->dev_if->out_ep_regs[ep->num];
  58357. +
  58358. + depctl.d32 = DWC_READ_REG32(&(out_regs->doepctl));
  58359. + deptsiz.d32 = DWC_READ_REG32(&(out_regs->doeptsiz));
  58360. +
  58361. + /* Zero Length Packet */
  58362. + deptsiz.b.xfersize = ep->maxpacket;
  58363. + deptsiz.b.pktcnt = 1;
  58364. +
  58365. + if (core_if->dma_enable) {
  58366. + if (!core_if->dma_desc_enable) {
  58367. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  58368. + deptsiz.d32);
  58369. +
  58370. + DWC_WRITE_REG32(&(out_regs->doepdma),
  58371. + (uint32_t) ep->dma_addr);
  58372. + }
  58373. + } else {
  58374. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  58375. + }
  58376. +
  58377. + /* EP enable */
  58378. + depctl.b.cnak = 1;
  58379. + depctl.b.epena = 1;
  58380. +
  58381. + DWC_WRITE_REG32(&out_regs->doepctl, depctl.d32);
  58382. +
  58383. + }
  58384. +}
  58385. +
  58386. +/**
  58387. + * This function does the setup for a data transfer for EP0 and starts
  58388. + * the transfer. For an IN transfer, the packets will be loaded into
  58389. + * the appropriate Tx FIFO in the ISR. For OUT transfers, the packets are
  58390. + * unloaded from the Rx FIFO in the ISR.
  58391. + *
  58392. + * @param core_if Programming view of DWC_otg controller.
  58393. + * @param ep The EP0 data.
  58394. + */
  58395. +void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  58396. +{
  58397. + depctl_data_t depctl;
  58398. + deptsiz0_data_t deptsiz;
  58399. + gintmsk_data_t intr_mask = {.d32 = 0 };
  58400. + dwc_otg_dev_dma_desc_t *dma_desc;
  58401. +
  58402. + DWC_DEBUGPL(DBG_PCD, "ep%d-%s xfer_len=%d xfer_cnt=%d "
  58403. + "xfer_buff=%p start_xfer_buff=%p \n",
  58404. + ep->num, (ep->is_in ? "IN" : "OUT"), ep->xfer_len,
  58405. + ep->xfer_count, ep->xfer_buff, ep->start_xfer_buff);
  58406. +
  58407. + ep->total_len = ep->xfer_len;
  58408. +
  58409. + /* IN endpoint */
  58410. + if (ep->is_in == 1) {
  58411. + dwc_otg_dev_in_ep_regs_t *in_regs =
  58412. + core_if->dev_if->in_ep_regs[0];
  58413. +
  58414. + gnptxsts_data_t gtxstatus;
  58415. +
  58416. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  58417. + depctl.d32 = DWC_READ_REG32(&in_regs->diepctl);
  58418. + if (depctl.b.epena)
  58419. + return;
  58420. + }
  58421. +
  58422. + gtxstatus.d32 =
  58423. + DWC_READ_REG32(&core_if->core_global_regs->gnptxsts);
  58424. +
  58425. + /* If dedicated FIFO every time flush fifo before enable ep*/
  58426. + if (core_if->en_multiple_tx_fifo && core_if->snpsid >= OTG_CORE_REV_3_00a)
  58427. + dwc_otg_flush_tx_fifo(core_if, ep->tx_fifo_num);
  58428. +
  58429. + if (core_if->en_multiple_tx_fifo == 0
  58430. + && gtxstatus.b.nptxqspcavail == 0
  58431. + && !core_if->dma_enable) {
  58432. +#ifdef DEBUG
  58433. + deptsiz.d32 = DWC_READ_REG32(&in_regs->dieptsiz);
  58434. + DWC_DEBUGPL(DBG_PCD, "DIEPCTL0=%0x\n",
  58435. + DWC_READ_REG32(&in_regs->diepctl));
  58436. + DWC_DEBUGPL(DBG_PCD, "DIEPTSIZ0=%0x (sz=%d, pcnt=%d)\n",
  58437. + deptsiz.d32,
  58438. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  58439. + DWC_PRINTF("TX Queue or FIFO Full (0x%0x)\n",
  58440. + gtxstatus.d32);
  58441. +#endif
  58442. + return;
  58443. + }
  58444. +
  58445. + depctl.d32 = DWC_READ_REG32(&in_regs->diepctl);
  58446. + deptsiz.d32 = DWC_READ_REG32(&in_regs->dieptsiz);
  58447. +
  58448. + /* Zero Length Packet? */
  58449. + if (ep->xfer_len == 0) {
  58450. + deptsiz.b.xfersize = 0;
  58451. + deptsiz.b.pktcnt = 1;
  58452. + } else {
  58453. + /* Program the transfer size and packet count
  58454. + * as follows: xfersize = N * maxpacket +
  58455. + * short_packet pktcnt = N + (short_packet
  58456. + * exist ? 1 : 0)
  58457. + */
  58458. + if (ep->xfer_len > ep->maxpacket) {
  58459. + ep->xfer_len = ep->maxpacket;
  58460. + deptsiz.b.xfersize = ep->maxpacket;
  58461. + } else {
  58462. + deptsiz.b.xfersize = ep->xfer_len;
  58463. + }
  58464. + deptsiz.b.pktcnt = 1;
  58465. +
  58466. + }
  58467. + DWC_DEBUGPL(DBG_PCDV,
  58468. + "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
  58469. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt,
  58470. + deptsiz.d32);
  58471. +
  58472. + /* Write the DMA register */
  58473. + if (core_if->dma_enable) {
  58474. + if (core_if->dma_desc_enable == 0) {
  58475. + DWC_WRITE_REG32(&in_regs->dieptsiz,
  58476. + deptsiz.d32);
  58477. +
  58478. + DWC_WRITE_REG32(&(in_regs->diepdma),
  58479. + (uint32_t) ep->dma_addr);
  58480. + } else {
  58481. + dma_desc = core_if->dev_if->in_desc_addr;
  58482. +
  58483. + /** DMA Descriptor Setup */
  58484. + dma_desc->status.b.bs = BS_HOST_BUSY;
  58485. + dma_desc->status.b.l = 1;
  58486. + dma_desc->status.b.ioc = 1;
  58487. + dma_desc->status.b.sp =
  58488. + (ep->xfer_len == ep->maxpacket) ? 0 : 1;
  58489. + dma_desc->status.b.bytes = ep->xfer_len;
  58490. + dma_desc->buf = ep->dma_addr;
  58491. + dma_desc->status.b.sts = 0;
  58492. + dma_desc->status.b.bs = BS_HOST_READY;
  58493. +
  58494. + /** DIEPDMA0 Register write */
  58495. + DWC_WRITE_REG32(&in_regs->diepdma,
  58496. + core_if->
  58497. + dev_if->dma_in_desc_addr);
  58498. + }
  58499. + } else {
  58500. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  58501. + }
  58502. +
  58503. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  58504. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  58505. + /* EP enable, IN data in FIFO */
  58506. + depctl.b.cnak = 1;
  58507. + depctl.b.epena = 1;
  58508. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  58509. +
  58510. + /**
  58511. + * Enable the Non-Periodic Tx FIFO empty interrupt, the
  58512. + * data will be written into the fifo by the ISR.
  58513. + */
  58514. + if (!core_if->dma_enable) {
  58515. + if (core_if->en_multiple_tx_fifo == 0) {
  58516. + intr_mask.b.nptxfempty = 1;
  58517. + DWC_MODIFY_REG32(&core_if->
  58518. + core_global_regs->gintmsk,
  58519. + intr_mask.d32, intr_mask.d32);
  58520. + } else {
  58521. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  58522. + if (ep->xfer_len > 0) {
  58523. + uint32_t fifoemptymsk = 0;
  58524. + fifoemptymsk |= 1 << ep->num;
  58525. + DWC_MODIFY_REG32(&core_if->
  58526. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  58527. + 0, fifoemptymsk);
  58528. + }
  58529. + }
  58530. + }
  58531. + } else {
  58532. + /* OUT endpoint */
  58533. + dwc_otg_dev_out_ep_regs_t *out_regs =
  58534. + core_if->dev_if->out_ep_regs[0];
  58535. +
  58536. + depctl.d32 = DWC_READ_REG32(&out_regs->doepctl);
  58537. + deptsiz.d32 = DWC_READ_REG32(&out_regs->doeptsiz);
  58538. +
  58539. + /* Program the transfer size and packet count as follows:
  58540. + * xfersize = N * (maxpacket + 4 - (maxpacket % 4))
  58541. + * pktcnt = N */
  58542. + /* Zero Length Packet */
  58543. + deptsiz.b.xfersize = ep->maxpacket;
  58544. + deptsiz.b.pktcnt = 1;
  58545. + if (core_if->snpsid >= OTG_CORE_REV_3_00a)
  58546. + deptsiz.b.supcnt = 3;
  58547. +
  58548. + DWC_DEBUGPL(DBG_PCDV, "len=%d xfersize=%d pktcnt=%d\n",
  58549. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt);
  58550. +
  58551. + if (core_if->dma_enable) {
  58552. + if (!core_if->dma_desc_enable) {
  58553. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  58554. + deptsiz.d32);
  58555. +
  58556. + DWC_WRITE_REG32(&(out_regs->doepdma),
  58557. + (uint32_t) ep->dma_addr);
  58558. + } else {
  58559. + dma_desc = core_if->dev_if->out_desc_addr;
  58560. +
  58561. + /** DMA Descriptor Setup */
  58562. + dma_desc->status.b.bs = BS_HOST_BUSY;
  58563. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  58564. + dma_desc->status.b.mtrf = 0;
  58565. + dma_desc->status.b.sr = 0;
  58566. + }
  58567. + dma_desc->status.b.l = 1;
  58568. + dma_desc->status.b.ioc = 1;
  58569. + dma_desc->status.b.bytes = ep->maxpacket;
  58570. + dma_desc->buf = ep->dma_addr;
  58571. + dma_desc->status.b.sts = 0;
  58572. + dma_desc->status.b.bs = BS_HOST_READY;
  58573. +
  58574. + /** DOEPDMA0 Register write */
  58575. + DWC_WRITE_REG32(&out_regs->doepdma,
  58576. + core_if->dev_if->
  58577. + dma_out_desc_addr);
  58578. + }
  58579. + } else {
  58580. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  58581. + }
  58582. +
  58583. + /* EP enable */
  58584. + depctl.b.cnak = 1;
  58585. + depctl.b.epena = 1;
  58586. + DWC_WRITE_REG32(&(out_regs->doepctl), depctl.d32);
  58587. + }
  58588. +}
  58589. +
  58590. +/**
  58591. + * This function continues control IN transfers started by
  58592. + * dwc_otg_ep0_start_transfer, when the transfer does not fit in a
  58593. + * single packet. NOTE: The DIEPCTL0/DOEPCTL0 registers only have one
  58594. + * bit for the packet count.
  58595. + *
  58596. + * @param core_if Programming view of DWC_otg controller.
  58597. + * @param ep The EP0 data.
  58598. + */
  58599. +void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  58600. +{
  58601. + depctl_data_t depctl;
  58602. + deptsiz0_data_t deptsiz;
  58603. + gintmsk_data_t intr_mask = {.d32 = 0 };
  58604. + dwc_otg_dev_dma_desc_t *dma_desc;
  58605. +
  58606. + if (ep->is_in == 1) {
  58607. + dwc_otg_dev_in_ep_regs_t *in_regs =
  58608. + core_if->dev_if->in_ep_regs[0];
  58609. + gnptxsts_data_t tx_status = {.d32 = 0 };
  58610. +
  58611. + tx_status.d32 =
  58612. + DWC_READ_REG32(&core_if->core_global_regs->gnptxsts);
  58613. + /** @todo Should there be check for room in the Tx
  58614. + * Status Queue. If not remove the code above this comment. */
  58615. +
  58616. + depctl.d32 = DWC_READ_REG32(&in_regs->diepctl);
  58617. + deptsiz.d32 = DWC_READ_REG32(&in_regs->dieptsiz);
  58618. +
  58619. + /* Program the transfer size and packet count
  58620. + * as follows: xfersize = N * maxpacket +
  58621. + * short_packet pktcnt = N + (short_packet
  58622. + * exist ? 1 : 0)
  58623. + */
  58624. +
  58625. + if (core_if->dma_desc_enable == 0) {
  58626. + deptsiz.b.xfersize =
  58627. + (ep->total_len - ep->xfer_count) >
  58628. + ep->maxpacket ? ep->maxpacket : (ep->total_len -
  58629. + ep->xfer_count);
  58630. + deptsiz.b.pktcnt = 1;
  58631. + if (core_if->dma_enable == 0) {
  58632. + ep->xfer_len += deptsiz.b.xfersize;
  58633. + } else {
  58634. + ep->xfer_len = deptsiz.b.xfersize;
  58635. + }
  58636. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  58637. + } else {
  58638. + ep->xfer_len =
  58639. + (ep->total_len - ep->xfer_count) >
  58640. + ep->maxpacket ? ep->maxpacket : (ep->total_len -
  58641. + ep->xfer_count);
  58642. +
  58643. + dma_desc = core_if->dev_if->in_desc_addr;
  58644. +
  58645. + /** DMA Descriptor Setup */
  58646. + dma_desc->status.b.bs = BS_HOST_BUSY;
  58647. + dma_desc->status.b.l = 1;
  58648. + dma_desc->status.b.ioc = 1;
  58649. + dma_desc->status.b.sp =
  58650. + (ep->xfer_len == ep->maxpacket) ? 0 : 1;
  58651. + dma_desc->status.b.bytes = ep->xfer_len;
  58652. + dma_desc->buf = ep->dma_addr;
  58653. + dma_desc->status.b.sts = 0;
  58654. + dma_desc->status.b.bs = BS_HOST_READY;
  58655. +
  58656. + /** DIEPDMA0 Register write */
  58657. + DWC_WRITE_REG32(&in_regs->diepdma,
  58658. + core_if->dev_if->dma_in_desc_addr);
  58659. + }
  58660. +
  58661. + DWC_DEBUGPL(DBG_PCDV,
  58662. + "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
  58663. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt,
  58664. + deptsiz.d32);
  58665. +
  58666. + /* Write the DMA register */
  58667. + if (core_if->hwcfg2.b.architecture == DWC_INT_DMA_ARCH) {
  58668. + if (core_if->dma_desc_enable == 0)
  58669. + DWC_WRITE_REG32(&(in_regs->diepdma),
  58670. + (uint32_t) ep->dma_addr);
  58671. + }
  58672. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  58673. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  58674. + /* EP enable, IN data in FIFO */
  58675. + depctl.b.cnak = 1;
  58676. + depctl.b.epena = 1;
  58677. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  58678. +
  58679. + /**
  58680. + * Enable the Non-Periodic Tx FIFO empty interrupt, the
  58681. + * data will be written into the fifo by the ISR.
  58682. + */
  58683. + if (!core_if->dma_enable) {
  58684. + if (core_if->en_multiple_tx_fifo == 0) {
  58685. + /* First clear it from GINTSTS */
  58686. + intr_mask.b.nptxfempty = 1;
  58687. + DWC_MODIFY_REG32(&core_if->
  58688. + core_global_regs->gintmsk,
  58689. + intr_mask.d32, intr_mask.d32);
  58690. +
  58691. + } else {
  58692. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  58693. + if (ep->xfer_len > 0) {
  58694. + uint32_t fifoemptymsk = 0;
  58695. + fifoemptymsk |= 1 << ep->num;
  58696. + DWC_MODIFY_REG32(&core_if->
  58697. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  58698. + 0, fifoemptymsk);
  58699. + }
  58700. + }
  58701. + }
  58702. + } else {
  58703. + dwc_otg_dev_out_ep_regs_t *out_regs =
  58704. + core_if->dev_if->out_ep_regs[0];
  58705. +
  58706. + depctl.d32 = DWC_READ_REG32(&out_regs->doepctl);
  58707. + deptsiz.d32 = DWC_READ_REG32(&out_regs->doeptsiz);
  58708. +
  58709. + /* Program the transfer size and packet count
  58710. + * as follows: xfersize = N * maxpacket +
  58711. + * short_packet pktcnt = N + (short_packet
  58712. + * exist ? 1 : 0)
  58713. + */
  58714. + deptsiz.b.xfersize = ep->maxpacket;
  58715. + deptsiz.b.pktcnt = 1;
  58716. +
  58717. + if (core_if->dma_desc_enable == 0) {
  58718. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  58719. + } else {
  58720. + dma_desc = core_if->dev_if->out_desc_addr;
  58721. +
  58722. + /** DMA Descriptor Setup */
  58723. + dma_desc->status.b.bs = BS_HOST_BUSY;
  58724. + dma_desc->status.b.l = 1;
  58725. + dma_desc->status.b.ioc = 1;
  58726. + dma_desc->status.b.bytes = ep->maxpacket;
  58727. + dma_desc->buf = ep->dma_addr;
  58728. + dma_desc->status.b.sts = 0;
  58729. + dma_desc->status.b.bs = BS_HOST_READY;
  58730. +
  58731. + /** DOEPDMA0 Register write */
  58732. + DWC_WRITE_REG32(&out_regs->doepdma,
  58733. + core_if->dev_if->dma_out_desc_addr);
  58734. + }
  58735. +
  58736. + DWC_DEBUGPL(DBG_PCDV,
  58737. + "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
  58738. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt,
  58739. + deptsiz.d32);
  58740. +
  58741. + /* Write the DMA register */
  58742. + if (core_if->hwcfg2.b.architecture == DWC_INT_DMA_ARCH) {
  58743. + if (core_if->dma_desc_enable == 0)
  58744. + DWC_WRITE_REG32(&(out_regs->doepdma),
  58745. + (uint32_t) ep->dma_addr);
  58746. +
  58747. + }
  58748. +
  58749. + /* EP enable, IN data in FIFO */
  58750. + depctl.b.cnak = 1;
  58751. + depctl.b.epena = 1;
  58752. + DWC_WRITE_REG32(&out_regs->doepctl, depctl.d32);
  58753. +
  58754. + }
  58755. +}
  58756. +
  58757. +#ifdef DEBUG
  58758. +void dump_msg(const u8 * buf, unsigned int length)
  58759. +{
  58760. + unsigned int start, num, i;
  58761. + char line[52], *p;
  58762. +
  58763. + if (length >= 512)
  58764. + return;
  58765. + start = 0;
  58766. + while (length > 0) {
  58767. + num = length < 16u ? length : 16u;
  58768. + p = line;
  58769. + for (i = 0; i < num; ++i) {
  58770. + if (i == 8)
  58771. + *p++ = ' ';
  58772. + DWC_SPRINTF(p, " %02x", buf[i]);
  58773. + p += 3;
  58774. + }
  58775. + *p = 0;
  58776. + DWC_PRINTF("%6x: %s\n", start, line);
  58777. + buf += num;
  58778. + start += num;
  58779. + length -= num;
  58780. + }
  58781. +}
  58782. +#else
  58783. +static inline void dump_msg(const u8 * buf, unsigned int length)
  58784. +{
  58785. +}
  58786. +#endif
  58787. +
  58788. +/**
  58789. + * This function writes a packet into the Tx FIFO associated with the
  58790. + * EP. For non-periodic EPs the non-periodic Tx FIFO is written. For
  58791. + * periodic EPs the periodic Tx FIFO associated with the EP is written
  58792. + * with all packets for the next micro-frame.
  58793. + *
  58794. + * @param core_if Programming view of DWC_otg controller.
  58795. + * @param ep The EP to write packet for.
  58796. + * @param dma Indicates if DMA is being used.
  58797. + */
  58798. +void dwc_otg_ep_write_packet(dwc_otg_core_if_t * core_if, dwc_ep_t * ep,
  58799. + int dma)
  58800. +{
  58801. + /**
  58802. + * The buffer is padded to DWORD on a per packet basis in
  58803. + * slave/dma mode if the MPS is not DWORD aligned. The last
  58804. + * packet, if short, is also padded to a multiple of DWORD.
  58805. + *
  58806. + * ep->xfer_buff always starts DWORD aligned in memory and is a
  58807. + * multiple of DWORD in length
  58808. + *
  58809. + * ep->xfer_len can be any number of bytes
  58810. + *
  58811. + * ep->xfer_count is a multiple of ep->maxpacket until the last
  58812. + * packet
  58813. + *
  58814. + * FIFO access is DWORD */
  58815. +
  58816. + uint32_t i;
  58817. + uint32_t byte_count;
  58818. + uint32_t dword_count;
  58819. + uint32_t *fifo;
  58820. + uint32_t *data_buff = (uint32_t *) ep->xfer_buff;
  58821. +
  58822. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s(%p,%p)\n", __func__, core_if,
  58823. + ep);
  58824. + if (ep->xfer_count >= ep->xfer_len) {
  58825. + DWC_WARN("%s() No data for EP%d!!!\n", __func__, ep->num);
  58826. + return;
  58827. + }
  58828. +
  58829. + /* Find the byte length of the packet either short packet or MPS */
  58830. + if ((ep->xfer_len - ep->xfer_count) < ep->maxpacket) {
  58831. + byte_count = ep->xfer_len - ep->xfer_count;
  58832. + } else {
  58833. + byte_count = ep->maxpacket;
  58834. + }
  58835. +
  58836. + /* Find the DWORD length, padded by extra bytes as neccessary if MPS
  58837. + * is not a multiple of DWORD */
  58838. + dword_count = (byte_count + 3) / 4;
  58839. +
  58840. +#ifdef VERBOSE
  58841. + dump_msg(ep->xfer_buff, byte_count);
  58842. +#endif
  58843. +
  58844. + /**@todo NGS Where are the Periodic Tx FIFO addresses
  58845. + * intialized? What should this be? */
  58846. +
  58847. + fifo = core_if->data_fifo[ep->num];
  58848. +
  58849. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "fifo=%p buff=%p *p=%08x bc=%d\n",
  58850. + fifo, data_buff, *data_buff, byte_count);
  58851. +
  58852. + if (!dma) {
  58853. + for (i = 0; i < dword_count; i++, data_buff++) {
  58854. + DWC_WRITE_REG32(fifo, *data_buff);
  58855. + }
  58856. + }
  58857. +
  58858. + ep->xfer_count += byte_count;
  58859. + ep->xfer_buff += byte_count;
  58860. + ep->dma_addr += byte_count;
  58861. +}
  58862. +
  58863. +/**
  58864. + * Set the EP STALL.
  58865. + *
  58866. + * @param core_if Programming view of DWC_otg controller.
  58867. + * @param ep The EP to set the stall on.
  58868. + */
  58869. +void dwc_otg_ep_set_stall(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  58870. +{
  58871. + depctl_data_t depctl;
  58872. + volatile uint32_t *depctl_addr;
  58873. +
  58874. + DWC_DEBUGPL(DBG_PCD, "%s ep%d-%s\n", __func__, ep->num,
  58875. + (ep->is_in ? "IN" : "OUT"));
  58876. +
  58877. + if (ep->is_in == 1) {
  58878. + depctl_addr = &(core_if->dev_if->in_ep_regs[ep->num]->diepctl);
  58879. + depctl.d32 = DWC_READ_REG32(depctl_addr);
  58880. +
  58881. + /* set the disable and stall bits */
  58882. + if (depctl.b.epena) {
  58883. + depctl.b.epdis = 1;
  58884. + }
  58885. + depctl.b.stall = 1;
  58886. + DWC_WRITE_REG32(depctl_addr, depctl.d32);
  58887. + } else {
  58888. + depctl_addr = &(core_if->dev_if->out_ep_regs[ep->num]->doepctl);
  58889. + depctl.d32 = DWC_READ_REG32(depctl_addr);
  58890. +
  58891. + /* set the stall bit */
  58892. + depctl.b.stall = 1;
  58893. + DWC_WRITE_REG32(depctl_addr, depctl.d32);
  58894. + }
  58895. +
  58896. + DWC_DEBUGPL(DBG_PCD, "DEPCTL=%0x\n", DWC_READ_REG32(depctl_addr));
  58897. +
  58898. + return;
  58899. +}
  58900. +
  58901. +/**
  58902. + * Clear the EP STALL.
  58903. + *
  58904. + * @param core_if Programming view of DWC_otg controller.
  58905. + * @param ep The EP to clear stall from.
  58906. + */
  58907. +void dwc_otg_ep_clear_stall(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  58908. +{
  58909. + depctl_data_t depctl;
  58910. + volatile uint32_t *depctl_addr;
  58911. +
  58912. + DWC_DEBUGPL(DBG_PCD, "%s ep%d-%s\n", __func__, ep->num,
  58913. + (ep->is_in ? "IN" : "OUT"));
  58914. +
  58915. + if (ep->is_in == 1) {
  58916. + depctl_addr = &(core_if->dev_if->in_ep_regs[ep->num]->diepctl);
  58917. + } else {
  58918. + depctl_addr = &(core_if->dev_if->out_ep_regs[ep->num]->doepctl);
  58919. + }
  58920. +
  58921. + depctl.d32 = DWC_READ_REG32(depctl_addr);
  58922. +
  58923. + /* clear the stall bits */
  58924. + depctl.b.stall = 0;
  58925. +
  58926. + /*
  58927. + * USB Spec 9.4.5: For endpoints using data toggle, regardless
  58928. + * of whether an endpoint has the Halt feature set, a
  58929. + * ClearFeature(ENDPOINT_HALT) request always results in the
  58930. + * data toggle being reinitialized to DATA0.
  58931. + */
  58932. + if (ep->type == DWC_OTG_EP_TYPE_INTR ||
  58933. + ep->type == DWC_OTG_EP_TYPE_BULK) {
  58934. + depctl.b.setd0pid = 1; /* DATA0 */
  58935. + }
  58936. +
  58937. + DWC_WRITE_REG32(depctl_addr, depctl.d32);
  58938. + DWC_DEBUGPL(DBG_PCD, "DEPCTL=%0x\n", DWC_READ_REG32(depctl_addr));
  58939. + return;
  58940. +}
  58941. +
  58942. +/**
  58943. + * This function reads a packet from the Rx FIFO into the destination
  58944. + * buffer. To read SETUP data use dwc_otg_read_setup_packet.
  58945. + *
  58946. + * @param core_if Programming view of DWC_otg controller.
  58947. + * @param dest Destination buffer for the packet.
  58948. + * @param bytes Number of bytes to copy to the destination.
  58949. + */
  58950. +void dwc_otg_read_packet(dwc_otg_core_if_t * core_if,
  58951. + uint8_t * dest, uint16_t bytes)
  58952. +{
  58953. + int i;
  58954. + int word_count = (bytes + 3) / 4;
  58955. +
  58956. + volatile uint32_t *fifo = core_if->data_fifo[0];
  58957. + uint32_t *data_buff = (uint32_t *) dest;
  58958. +
  58959. + /**
  58960. + * @todo Account for the case where _dest is not dword aligned. This
  58961. + * requires reading data from the FIFO into a uint32_t temp buffer,
  58962. + * then moving it into the data buffer.
  58963. + */
  58964. +
  58965. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s(%p,%p,%d)\n", __func__,
  58966. + core_if, dest, bytes);
  58967. +
  58968. + for (i = 0; i < word_count; i++, data_buff++) {
  58969. + *data_buff = DWC_READ_REG32(fifo);
  58970. + }
  58971. +
  58972. + return;
  58973. +}
  58974. +
  58975. +/**
  58976. + * This functions reads the device registers and prints them
  58977. + *
  58978. + * @param core_if Programming view of DWC_otg controller.
  58979. + */
  58980. +void dwc_otg_dump_dev_registers(dwc_otg_core_if_t * core_if)
  58981. +{
  58982. + int i;
  58983. + volatile uint32_t *addr;
  58984. +
  58985. + DWC_PRINTF("Device Global Registers\n");
  58986. + addr = &core_if->dev_if->dev_global_regs->dcfg;
  58987. + DWC_PRINTF("DCFG @0x%08lX : 0x%08X\n",
  58988. + (unsigned long)addr, DWC_READ_REG32(addr));
  58989. + addr = &core_if->dev_if->dev_global_regs->dctl;
  58990. + DWC_PRINTF("DCTL @0x%08lX : 0x%08X\n",
  58991. + (unsigned long)addr, DWC_READ_REG32(addr));
  58992. + addr = &core_if->dev_if->dev_global_regs->dsts;
  58993. + DWC_PRINTF("DSTS @0x%08lX : 0x%08X\n",
  58994. + (unsigned long)addr, DWC_READ_REG32(addr));
  58995. + addr = &core_if->dev_if->dev_global_regs->diepmsk;
  58996. + DWC_PRINTF("DIEPMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  58997. + DWC_READ_REG32(addr));
  58998. + addr = &core_if->dev_if->dev_global_regs->doepmsk;
  58999. + DWC_PRINTF("DOEPMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59000. + DWC_READ_REG32(addr));
  59001. + addr = &core_if->dev_if->dev_global_regs->daint;
  59002. + DWC_PRINTF("DAINT @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59003. + DWC_READ_REG32(addr));
  59004. + addr = &core_if->dev_if->dev_global_regs->daintmsk;
  59005. + DWC_PRINTF("DAINTMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59006. + DWC_READ_REG32(addr));
  59007. + addr = &core_if->dev_if->dev_global_regs->dtknqr1;
  59008. + DWC_PRINTF("DTKNQR1 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59009. + DWC_READ_REG32(addr));
  59010. + if (core_if->hwcfg2.b.dev_token_q_depth > 6) {
  59011. + addr = &core_if->dev_if->dev_global_regs->dtknqr2;
  59012. + DWC_PRINTF("DTKNQR2 @0x%08lX : 0x%08X\n",
  59013. + (unsigned long)addr, DWC_READ_REG32(addr));
  59014. + }
  59015. +
  59016. + addr = &core_if->dev_if->dev_global_regs->dvbusdis;
  59017. + DWC_PRINTF("DVBUSID @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59018. + DWC_READ_REG32(addr));
  59019. +
  59020. + addr = &core_if->dev_if->dev_global_regs->dvbuspulse;
  59021. + DWC_PRINTF("DVBUSPULSE @0x%08lX : 0x%08X\n",
  59022. + (unsigned long)addr, DWC_READ_REG32(addr));
  59023. +
  59024. + addr = &core_if->dev_if->dev_global_regs->dtknqr3_dthrctl;
  59025. + DWC_PRINTF("DTKNQR3_DTHRCTL @0x%08lX : 0x%08X\n",
  59026. + (unsigned long)addr, DWC_READ_REG32(addr));
  59027. +
  59028. + if (core_if->hwcfg2.b.dev_token_q_depth > 22) {
  59029. + addr = &core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk;
  59030. + DWC_PRINTF("DTKNQR4 @0x%08lX : 0x%08X\n",
  59031. + (unsigned long)addr, DWC_READ_REG32(addr));
  59032. + }
  59033. +
  59034. + addr = &core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk;
  59035. + DWC_PRINTF("FIFOEMPMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59036. + DWC_READ_REG32(addr));
  59037. +
  59038. + if (core_if->hwcfg2.b.multi_proc_int) {
  59039. +
  59040. + addr = &core_if->dev_if->dev_global_regs->deachint;
  59041. + DWC_PRINTF("DEACHINT @0x%08lX : 0x%08X\n",
  59042. + (unsigned long)addr, DWC_READ_REG32(addr));
  59043. + addr = &core_if->dev_if->dev_global_regs->deachintmsk;
  59044. + DWC_PRINTF("DEACHINTMSK @0x%08lX : 0x%08X\n",
  59045. + (unsigned long)addr, DWC_READ_REG32(addr));
  59046. +
  59047. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  59048. + addr =
  59049. + &core_if->dev_if->
  59050. + dev_global_regs->diepeachintmsk[i];
  59051. + DWC_PRINTF("DIEPEACHINTMSK[%d] @0x%08lX : 0x%08X\n",
  59052. + i, (unsigned long)addr,
  59053. + DWC_READ_REG32(addr));
  59054. + }
  59055. +
  59056. + for (i = 0; i <= core_if->dev_if->num_out_eps; i++) {
  59057. + addr =
  59058. + &core_if->dev_if->
  59059. + dev_global_regs->doepeachintmsk[i];
  59060. + DWC_PRINTF("DOEPEACHINTMSK[%d] @0x%08lX : 0x%08X\n",
  59061. + i, (unsigned long)addr,
  59062. + DWC_READ_REG32(addr));
  59063. + }
  59064. + }
  59065. +
  59066. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  59067. + DWC_PRINTF("Device IN EP %d Registers\n", i);
  59068. + addr = &core_if->dev_if->in_ep_regs[i]->diepctl;
  59069. + DWC_PRINTF("DIEPCTL @0x%08lX : 0x%08X\n",
  59070. + (unsigned long)addr, DWC_READ_REG32(addr));
  59071. + addr = &core_if->dev_if->in_ep_regs[i]->diepint;
  59072. + DWC_PRINTF("DIEPINT @0x%08lX : 0x%08X\n",
  59073. + (unsigned long)addr, DWC_READ_REG32(addr));
  59074. + addr = &core_if->dev_if->in_ep_regs[i]->dieptsiz;
  59075. + DWC_PRINTF("DIETSIZ @0x%08lX : 0x%08X\n",
  59076. + (unsigned long)addr, DWC_READ_REG32(addr));
  59077. + addr = &core_if->dev_if->in_ep_regs[i]->diepdma;
  59078. + DWC_PRINTF("DIEPDMA @0x%08lX : 0x%08X\n",
  59079. + (unsigned long)addr, DWC_READ_REG32(addr));
  59080. + addr = &core_if->dev_if->in_ep_regs[i]->dtxfsts;
  59081. + DWC_PRINTF("DTXFSTS @0x%08lX : 0x%08X\n",
  59082. + (unsigned long)addr, DWC_READ_REG32(addr));
  59083. + addr = &core_if->dev_if->in_ep_regs[i]->diepdmab;
  59084. + DWC_PRINTF("DIEPDMAB @0x%08lX : 0x%08X\n",
  59085. + (unsigned long)addr, 0 /*DWC_READ_REG32(addr) */ );
  59086. + }
  59087. +
  59088. + for (i = 0; i <= core_if->dev_if->num_out_eps; i++) {
  59089. + DWC_PRINTF("Device OUT EP %d Registers\n", i);
  59090. + addr = &core_if->dev_if->out_ep_regs[i]->doepctl;
  59091. + DWC_PRINTF("DOEPCTL @0x%08lX : 0x%08X\n",
  59092. + (unsigned long)addr, DWC_READ_REG32(addr));
  59093. + addr = &core_if->dev_if->out_ep_regs[i]->doepint;
  59094. + DWC_PRINTF("DOEPINT @0x%08lX : 0x%08X\n",
  59095. + (unsigned long)addr, DWC_READ_REG32(addr));
  59096. + addr = &core_if->dev_if->out_ep_regs[i]->doeptsiz;
  59097. + DWC_PRINTF("DOETSIZ @0x%08lX : 0x%08X\n",
  59098. + (unsigned long)addr, DWC_READ_REG32(addr));
  59099. + addr = &core_if->dev_if->out_ep_regs[i]->doepdma;
  59100. + DWC_PRINTF("DOEPDMA @0x%08lX : 0x%08X\n",
  59101. + (unsigned long)addr, DWC_READ_REG32(addr));
  59102. + if (core_if->dma_enable) { /* Don't access this register in SLAVE mode */
  59103. + addr = &core_if->dev_if->out_ep_regs[i]->doepdmab;
  59104. + DWC_PRINTF("DOEPDMAB @0x%08lX : 0x%08X\n",
  59105. + (unsigned long)addr, DWC_READ_REG32(addr));
  59106. + }
  59107. +
  59108. + }
  59109. +}
  59110. +
  59111. +/**
  59112. + * This functions reads the SPRAM and prints its content
  59113. + *
  59114. + * @param core_if Programming view of DWC_otg controller.
  59115. + */
  59116. +void dwc_otg_dump_spram(dwc_otg_core_if_t * core_if)
  59117. +{
  59118. + volatile uint8_t *addr, *start_addr, *end_addr;
  59119. +
  59120. + DWC_PRINTF("SPRAM Data:\n");
  59121. + start_addr = (void *)core_if->core_global_regs;
  59122. + DWC_PRINTF("Base Address: 0x%8lX\n", (unsigned long)start_addr);
  59123. + start_addr += 0x00028000;
  59124. + end_addr = (void *)core_if->core_global_regs;
  59125. + end_addr += 0x000280e0;
  59126. +
  59127. + for (addr = start_addr; addr < end_addr; addr += 16) {
  59128. + DWC_PRINTF
  59129. + ("0x%8lX:\t%2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X\n",
  59130. + (unsigned long)addr, addr[0], addr[1], addr[2], addr[3],
  59131. + addr[4], addr[5], addr[6], addr[7], addr[8], addr[9],
  59132. + addr[10], addr[11], addr[12], addr[13], addr[14], addr[15]
  59133. + );
  59134. + }
  59135. +
  59136. + return;
  59137. +}
  59138. +
  59139. +/**
  59140. + * This function reads the host registers and prints them
  59141. + *
  59142. + * @param core_if Programming view of DWC_otg controller.
  59143. + */
  59144. +void dwc_otg_dump_host_registers(dwc_otg_core_if_t * core_if)
  59145. +{
  59146. + int i;
  59147. + volatile uint32_t *addr;
  59148. +
  59149. + DWC_PRINTF("Host Global Registers\n");
  59150. + addr = &core_if->host_if->host_global_regs->hcfg;
  59151. + DWC_PRINTF("HCFG @0x%08lX : 0x%08X\n",
  59152. + (unsigned long)addr, DWC_READ_REG32(addr));
  59153. + addr = &core_if->host_if->host_global_regs->hfir;
  59154. + DWC_PRINTF("HFIR @0x%08lX : 0x%08X\n",
  59155. + (unsigned long)addr, DWC_READ_REG32(addr));
  59156. + addr = &core_if->host_if->host_global_regs->hfnum;
  59157. + DWC_PRINTF("HFNUM @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59158. + DWC_READ_REG32(addr));
  59159. + addr = &core_if->host_if->host_global_regs->hptxsts;
  59160. + DWC_PRINTF("HPTXSTS @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59161. + DWC_READ_REG32(addr));
  59162. + addr = &core_if->host_if->host_global_regs->haint;
  59163. + DWC_PRINTF("HAINT @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59164. + DWC_READ_REG32(addr));
  59165. + addr = &core_if->host_if->host_global_regs->haintmsk;
  59166. + DWC_PRINTF("HAINTMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59167. + DWC_READ_REG32(addr));
  59168. + if (core_if->dma_desc_enable) {
  59169. + addr = &core_if->host_if->host_global_regs->hflbaddr;
  59170. + DWC_PRINTF("HFLBADDR @0x%08lX : 0x%08X\n",
  59171. + (unsigned long)addr, DWC_READ_REG32(addr));
  59172. + }
  59173. +
  59174. + addr = core_if->host_if->hprt0;
  59175. + DWC_PRINTF("HPRT0 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59176. + DWC_READ_REG32(addr));
  59177. +
  59178. + for (i = 0; i < core_if->core_params->host_channels; i++) {
  59179. + DWC_PRINTF("Host Channel %d Specific Registers\n", i);
  59180. + addr = &core_if->host_if->hc_regs[i]->hcchar;
  59181. + DWC_PRINTF("HCCHAR @0x%08lX : 0x%08X\n",
  59182. + (unsigned long)addr, DWC_READ_REG32(addr));
  59183. + addr = &core_if->host_if->hc_regs[i]->hcsplt;
  59184. + DWC_PRINTF("HCSPLT @0x%08lX : 0x%08X\n",
  59185. + (unsigned long)addr, DWC_READ_REG32(addr));
  59186. + addr = &core_if->host_if->hc_regs[i]->hcint;
  59187. + DWC_PRINTF("HCINT @0x%08lX : 0x%08X\n",
  59188. + (unsigned long)addr, DWC_READ_REG32(addr));
  59189. + addr = &core_if->host_if->hc_regs[i]->hcintmsk;
  59190. + DWC_PRINTF("HCINTMSK @0x%08lX : 0x%08X\n",
  59191. + (unsigned long)addr, DWC_READ_REG32(addr));
  59192. + addr = &core_if->host_if->hc_regs[i]->hctsiz;
  59193. + DWC_PRINTF("HCTSIZ @0x%08lX : 0x%08X\n",
  59194. + (unsigned long)addr, DWC_READ_REG32(addr));
  59195. + addr = &core_if->host_if->hc_regs[i]->hcdma;
  59196. + DWC_PRINTF("HCDMA @0x%08lX : 0x%08X\n",
  59197. + (unsigned long)addr, DWC_READ_REG32(addr));
  59198. + if (core_if->dma_desc_enable) {
  59199. + addr = &core_if->host_if->hc_regs[i]->hcdmab;
  59200. + DWC_PRINTF("HCDMAB @0x%08lX : 0x%08X\n",
  59201. + (unsigned long)addr, DWC_READ_REG32(addr));
  59202. + }
  59203. +
  59204. + }
  59205. + return;
  59206. +}
  59207. +
  59208. +/**
  59209. + * This function reads the core global registers and prints them
  59210. + *
  59211. + * @param core_if Programming view of DWC_otg controller.
  59212. + */
  59213. +void dwc_otg_dump_global_registers(dwc_otg_core_if_t * core_if)
  59214. +{
  59215. + int i, ep_num;
  59216. + volatile uint32_t *addr;
  59217. + char *txfsiz;
  59218. +
  59219. + DWC_PRINTF("Core Global Registers\n");
  59220. + addr = &core_if->core_global_regs->gotgctl;
  59221. + DWC_PRINTF("GOTGCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59222. + DWC_READ_REG32(addr));
  59223. + addr = &core_if->core_global_regs->gotgint;
  59224. + DWC_PRINTF("GOTGINT @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59225. + DWC_READ_REG32(addr));
  59226. + addr = &core_if->core_global_regs->gahbcfg;
  59227. + DWC_PRINTF("GAHBCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59228. + DWC_READ_REG32(addr));
  59229. + addr = &core_if->core_global_regs->gusbcfg;
  59230. + DWC_PRINTF("GUSBCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59231. + DWC_READ_REG32(addr));
  59232. + addr = &core_if->core_global_regs->grstctl;
  59233. + DWC_PRINTF("GRSTCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59234. + DWC_READ_REG32(addr));
  59235. + addr = &core_if->core_global_regs->gintsts;
  59236. + DWC_PRINTF("GINTSTS @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59237. + DWC_READ_REG32(addr));
  59238. + addr = &core_if->core_global_regs->gintmsk;
  59239. + DWC_PRINTF("GINTMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59240. + DWC_READ_REG32(addr));
  59241. + addr = &core_if->core_global_regs->grxstsr;
  59242. + DWC_PRINTF("GRXSTSR @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59243. + DWC_READ_REG32(addr));
  59244. + addr = &core_if->core_global_regs->grxfsiz;
  59245. + DWC_PRINTF("GRXFSIZ @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59246. + DWC_READ_REG32(addr));
  59247. + addr = &core_if->core_global_regs->gnptxfsiz;
  59248. + DWC_PRINTF("GNPTXFSIZ @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59249. + DWC_READ_REG32(addr));
  59250. + addr = &core_if->core_global_regs->gnptxsts;
  59251. + DWC_PRINTF("GNPTXSTS @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59252. + DWC_READ_REG32(addr));
  59253. + addr = &core_if->core_global_regs->gi2cctl;
  59254. + DWC_PRINTF("GI2CCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59255. + DWC_READ_REG32(addr));
  59256. + addr = &core_if->core_global_regs->gpvndctl;
  59257. + DWC_PRINTF("GPVNDCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59258. + DWC_READ_REG32(addr));
  59259. + addr = &core_if->core_global_regs->ggpio;
  59260. + DWC_PRINTF("GGPIO @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59261. + DWC_READ_REG32(addr));
  59262. + addr = &core_if->core_global_regs->guid;
  59263. + DWC_PRINTF("GUID @0x%08lX : 0x%08X\n",
  59264. + (unsigned long)addr, DWC_READ_REG32(addr));
  59265. + addr = &core_if->core_global_regs->gsnpsid;
  59266. + DWC_PRINTF("GSNPSID @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59267. + DWC_READ_REG32(addr));
  59268. + addr = &core_if->core_global_regs->ghwcfg1;
  59269. + DWC_PRINTF("GHWCFG1 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59270. + DWC_READ_REG32(addr));
  59271. + addr = &core_if->core_global_regs->ghwcfg2;
  59272. + DWC_PRINTF("GHWCFG2 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59273. + DWC_READ_REG32(addr));
  59274. + addr = &core_if->core_global_regs->ghwcfg3;
  59275. + DWC_PRINTF("GHWCFG3 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59276. + DWC_READ_REG32(addr));
  59277. + addr = &core_if->core_global_regs->ghwcfg4;
  59278. + DWC_PRINTF("GHWCFG4 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59279. + DWC_READ_REG32(addr));
  59280. + addr = &core_if->core_global_regs->glpmcfg;
  59281. + DWC_PRINTF("GLPMCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59282. + DWC_READ_REG32(addr));
  59283. + addr = &core_if->core_global_regs->gpwrdn;
  59284. + DWC_PRINTF("GPWRDN @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59285. + DWC_READ_REG32(addr));
  59286. + addr = &core_if->core_global_regs->gdfifocfg;
  59287. + DWC_PRINTF("GDFIFOCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59288. + DWC_READ_REG32(addr));
  59289. + addr = &core_if->core_global_regs->adpctl;
  59290. + DWC_PRINTF("ADPCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59291. + dwc_otg_adp_read_reg(core_if));
  59292. + addr = &core_if->core_global_regs->hptxfsiz;
  59293. + DWC_PRINTF("HPTXFSIZ @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59294. + DWC_READ_REG32(addr));
  59295. +
  59296. + if (core_if->en_multiple_tx_fifo == 0) {
  59297. + ep_num = core_if->hwcfg4.b.num_dev_perio_in_ep;
  59298. + txfsiz = "DPTXFSIZ";
  59299. + } else {
  59300. + ep_num = core_if->hwcfg4.b.num_in_eps;
  59301. + txfsiz = "DIENPTXF";
  59302. + }
  59303. + for (i = 0; i < ep_num; i++) {
  59304. + addr = &core_if->core_global_regs->dtxfsiz[i];
  59305. + DWC_PRINTF("%s[%d] @0x%08lX : 0x%08X\n", txfsiz, i + 1,
  59306. + (unsigned long)addr, DWC_READ_REG32(addr));
  59307. + }
  59308. + addr = core_if->pcgcctl;
  59309. + DWC_PRINTF("PCGCCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59310. + DWC_READ_REG32(addr));
  59311. +}
  59312. +
  59313. +/**
  59314. + * Flush a Tx FIFO.
  59315. + *
  59316. + * @param core_if Programming view of DWC_otg controller.
  59317. + * @param num Tx FIFO to flush.
  59318. + */
  59319. +void dwc_otg_flush_tx_fifo(dwc_otg_core_if_t * core_if, const int num)
  59320. +{
  59321. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  59322. + volatile grstctl_t greset = {.d32 = 0 };
  59323. + int count = 0;
  59324. +
  59325. + DWC_DEBUGPL((DBG_CIL | DBG_PCDV), "Flush Tx FIFO %d\n", num);
  59326. +
  59327. + greset.b.txfflsh = 1;
  59328. + greset.b.txfnum = num;
  59329. + DWC_WRITE_REG32(&global_regs->grstctl, greset.d32);
  59330. +
  59331. + do {
  59332. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  59333. + if (++count > 10000) {
  59334. + DWC_WARN("%s() HANG! GRSTCTL=%0x GNPTXSTS=0x%08x\n",
  59335. + __func__, greset.d32,
  59336. + DWC_READ_REG32(&global_regs->gnptxsts));
  59337. + break;
  59338. + }
  59339. + dwc_udelay(1);
  59340. + } while (greset.b.txfflsh == 1);
  59341. +
  59342. + /* Wait for 3 PHY Clocks */
  59343. + dwc_udelay(1);
  59344. +}
  59345. +
  59346. +/**
  59347. + * Flush Rx FIFO.
  59348. + *
  59349. + * @param core_if Programming view of DWC_otg controller.
  59350. + */
  59351. +void dwc_otg_flush_rx_fifo(dwc_otg_core_if_t * core_if)
  59352. +{
  59353. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  59354. + volatile grstctl_t greset = {.d32 = 0 };
  59355. + int count = 0;
  59356. +
  59357. + DWC_DEBUGPL((DBG_CIL | DBG_PCDV), "%s\n", __func__);
  59358. + /*
  59359. + *
  59360. + */
  59361. + greset.b.rxfflsh = 1;
  59362. + DWC_WRITE_REG32(&global_regs->grstctl, greset.d32);
  59363. +
  59364. + do {
  59365. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  59366. + if (++count > 10000) {
  59367. + DWC_WARN("%s() HANG! GRSTCTL=%0x\n", __func__,
  59368. + greset.d32);
  59369. + break;
  59370. + }
  59371. + dwc_udelay(1);
  59372. + } while (greset.b.rxfflsh == 1);
  59373. +
  59374. + /* Wait for 3 PHY Clocks */
  59375. + dwc_udelay(1);
  59376. +}
  59377. +
  59378. +/**
  59379. + * Do core a soft reset of the core. Be careful with this because it
  59380. + * resets all the internal state machines of the core.
  59381. + */
  59382. +void dwc_otg_core_reset(dwc_otg_core_if_t * core_if)
  59383. +{
  59384. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  59385. + volatile grstctl_t greset = {.d32 = 0 };
  59386. + int count = 0;
  59387. +
  59388. + DWC_DEBUGPL(DBG_CILV, "%s\n", __func__);
  59389. + /* Wait for AHB master IDLE state. */
  59390. + do {
  59391. + dwc_udelay(10);
  59392. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  59393. + if (++count > 100000) {
  59394. + DWC_WARN("%s() HANG! AHB Idle GRSTCTL=%0x\n", __func__,
  59395. + greset.d32);
  59396. + return;
  59397. + }
  59398. + }
  59399. + while (greset.b.ahbidle == 0);
  59400. +
  59401. + /* Core Soft Reset */
  59402. + count = 0;
  59403. + greset.b.csftrst = 1;
  59404. + DWC_WRITE_REG32(&global_regs->grstctl, greset.d32);
  59405. + do {
  59406. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  59407. + if (++count > 10000) {
  59408. + DWC_WARN("%s() HANG! Soft Reset GRSTCTL=%0x\n",
  59409. + __func__, greset.d32);
  59410. + break;
  59411. + }
  59412. + dwc_udelay(1);
  59413. + }
  59414. + while (greset.b.csftrst == 1);
  59415. +
  59416. + /* Wait for 3 PHY Clocks */
  59417. + dwc_mdelay(100);
  59418. +}
  59419. +
  59420. +uint8_t dwc_otg_is_device_mode(dwc_otg_core_if_t * _core_if)
  59421. +{
  59422. + return (dwc_otg_mode(_core_if) != DWC_HOST_MODE);
  59423. +}
  59424. +
  59425. +uint8_t dwc_otg_is_host_mode(dwc_otg_core_if_t * _core_if)
  59426. +{
  59427. + return (dwc_otg_mode(_core_if) == DWC_HOST_MODE);
  59428. +}
  59429. +
  59430. +/**
  59431. + * Register HCD callbacks. The callbacks are used to start and stop
  59432. + * the HCD for interrupt processing.
  59433. + *
  59434. + * @param core_if Programming view of DWC_otg controller.
  59435. + * @param cb the HCD callback structure.
  59436. + * @param p pointer to be passed to callback function (usb_hcd*).
  59437. + */
  59438. +void dwc_otg_cil_register_hcd_callbacks(dwc_otg_core_if_t * core_if,
  59439. + dwc_otg_cil_callbacks_t * cb, void *p)
  59440. +{
  59441. + core_if->hcd_cb = cb;
  59442. + cb->p = p;
  59443. +}
  59444. +
  59445. +/**
  59446. + * Register PCD callbacks. The callbacks are used to start and stop
  59447. + * the PCD for interrupt processing.
  59448. + *
  59449. + * @param core_if Programming view of DWC_otg controller.
  59450. + * @param cb the PCD callback structure.
  59451. + * @param p pointer to be passed to callback function (pcd*).
  59452. + */
  59453. +void dwc_otg_cil_register_pcd_callbacks(dwc_otg_core_if_t * core_if,
  59454. + dwc_otg_cil_callbacks_t * cb, void *p)
  59455. +{
  59456. + core_if->pcd_cb = cb;
  59457. + cb->p = p;
  59458. +}
  59459. +
  59460. +#ifdef DWC_EN_ISOC
  59461. +
  59462. +/**
  59463. + * This function writes isoc data per 1 (micro)frame into tx fifo
  59464. + *
  59465. + * @param core_if Programming view of DWC_otg controller.
  59466. + * @param ep The EP to start the transfer on.
  59467. + *
  59468. + */
  59469. +void write_isoc_frame_data(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  59470. +{
  59471. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  59472. + dtxfsts_data_t txstatus = {.d32 = 0 };
  59473. + uint32_t len = 0;
  59474. + uint32_t dwords;
  59475. +
  59476. + ep->xfer_len = ep->data_per_frame;
  59477. + ep->xfer_count = 0;
  59478. +
  59479. + ep_regs = core_if->dev_if->in_ep_regs[ep->num];
  59480. +
  59481. + len = ep->xfer_len - ep->xfer_count;
  59482. +
  59483. + if (len > ep->maxpacket) {
  59484. + len = ep->maxpacket;
  59485. + }
  59486. +
  59487. + dwords = (len + 3) / 4;
  59488. +
  59489. + /* While there is space in the queue and space in the FIFO and
  59490. + * More data to tranfer, Write packets to the Tx FIFO */
  59491. + txstatus.d32 =
  59492. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[ep->num]->dtxfsts);
  59493. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", ep->num, txstatus.d32);
  59494. +
  59495. + while (txstatus.b.txfspcavail > dwords &&
  59496. + ep->xfer_count < ep->xfer_len && ep->xfer_len != 0) {
  59497. + /* Write the FIFO */
  59498. + dwc_otg_ep_write_packet(core_if, ep, 0);
  59499. +
  59500. + len = ep->xfer_len - ep->xfer_count;
  59501. + if (len > ep->maxpacket) {
  59502. + len = ep->maxpacket;
  59503. + }
  59504. +
  59505. + dwords = (len + 3) / 4;
  59506. + txstatus.d32 =
  59507. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  59508. + dtxfsts);
  59509. + DWC_DEBUGPL(DBG_PCDV, "dtxfsts[%d]=0x%08x\n", ep->num,
  59510. + txstatus.d32);
  59511. + }
  59512. +}
  59513. +
  59514. +/**
  59515. + * This function initializes a descriptor chain for Isochronous transfer
  59516. + *
  59517. + * @param core_if Programming view of DWC_otg controller.
  59518. + * @param ep The EP to start the transfer on.
  59519. + *
  59520. + */
  59521. +void dwc_otg_iso_ep_start_frm_transfer(dwc_otg_core_if_t * core_if,
  59522. + dwc_ep_t * ep)
  59523. +{
  59524. + deptsiz_data_t deptsiz = {.d32 = 0 };
  59525. + depctl_data_t depctl = {.d32 = 0 };
  59526. + dsts_data_t dsts = {.d32 = 0 };
  59527. + volatile uint32_t *addr;
  59528. +
  59529. + if (ep->is_in) {
  59530. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  59531. + } else {
  59532. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  59533. + }
  59534. +
  59535. + ep->xfer_len = ep->data_per_frame;
  59536. + ep->xfer_count = 0;
  59537. + ep->xfer_buff = ep->cur_pkt_addr;
  59538. + ep->dma_addr = ep->cur_pkt_dma_addr;
  59539. +
  59540. + if (ep->is_in) {
  59541. + /* Program the transfer size and packet count
  59542. + * as follows: xfersize = N * maxpacket +
  59543. + * short_packet pktcnt = N + (short_packet
  59544. + * exist ? 1 : 0)
  59545. + */
  59546. + deptsiz.b.xfersize = ep->xfer_len;
  59547. + deptsiz.b.pktcnt =
  59548. + (ep->xfer_len - 1 + ep->maxpacket) / ep->maxpacket;
  59549. + deptsiz.b.mc = deptsiz.b.pktcnt;
  59550. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->dieptsiz,
  59551. + deptsiz.d32);
  59552. +
  59553. + /* Write the DMA register */
  59554. + if (core_if->dma_enable) {
  59555. + DWC_WRITE_REG32(&
  59556. + (core_if->dev_if->in_ep_regs[ep->num]->
  59557. + diepdma), (uint32_t) ep->dma_addr);
  59558. + }
  59559. + } else {
  59560. + deptsiz.b.pktcnt =
  59561. + (ep->xfer_len + (ep->maxpacket - 1)) / ep->maxpacket;
  59562. + deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
  59563. +
  59564. + DWC_WRITE_REG32(&core_if->dev_if->
  59565. + out_ep_regs[ep->num]->doeptsiz, deptsiz.d32);
  59566. +
  59567. + if (core_if->dma_enable) {
  59568. + DWC_WRITE_REG32(&
  59569. + (core_if->dev_if->
  59570. + out_ep_regs[ep->num]->doepdma),
  59571. + (uint32_t) ep->dma_addr);
  59572. + }
  59573. + }
  59574. +
  59575. + /** Enable endpoint, clear nak */
  59576. +
  59577. + depctl.d32 = 0;
  59578. + if (ep->bInterval == 1) {
  59579. + dsts.d32 =
  59580. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  59581. + ep->next_frame = dsts.b.soffn + ep->bInterval;
  59582. +
  59583. + if (ep->next_frame & 0x1) {
  59584. + depctl.b.setd1pid = 1;
  59585. + } else {
  59586. + depctl.b.setd0pid = 1;
  59587. + }
  59588. + } else {
  59589. + ep->next_frame += ep->bInterval;
  59590. +
  59591. + if (ep->next_frame & 0x1) {
  59592. + depctl.b.setd1pid = 1;
  59593. + } else {
  59594. + depctl.b.setd0pid = 1;
  59595. + }
  59596. + }
  59597. + depctl.b.epena = 1;
  59598. + depctl.b.cnak = 1;
  59599. +
  59600. + DWC_MODIFY_REG32(addr, 0, depctl.d32);
  59601. + depctl.d32 = DWC_READ_REG32(addr);
  59602. +
  59603. + if (ep->is_in && core_if->dma_enable == 0) {
  59604. + write_isoc_frame_data(core_if, ep);
  59605. + }
  59606. +
  59607. +}
  59608. +#endif /* DWC_EN_ISOC */
  59609. +
  59610. +static void dwc_otg_set_uninitialized(int32_t * p, int size)
  59611. +{
  59612. + int i;
  59613. + for (i = 0; i < size; i++) {
  59614. + p[i] = -1;
  59615. + }
  59616. +}
  59617. +
  59618. +static int dwc_otg_param_initialized(int32_t val)
  59619. +{
  59620. + return val != -1;
  59621. +}
  59622. +
  59623. +static int dwc_otg_setup_params(dwc_otg_core_if_t * core_if)
  59624. +{
  59625. + int i;
  59626. + core_if->core_params = DWC_ALLOC(sizeof(*core_if->core_params));
  59627. + if (!core_if->core_params) {
  59628. + return -DWC_E_NO_MEMORY;
  59629. + }
  59630. + dwc_otg_set_uninitialized((int32_t *) core_if->core_params,
  59631. + sizeof(*core_if->core_params) /
  59632. + sizeof(int32_t));
  59633. + DWC_PRINTF("Setting default values for core params\n");
  59634. + dwc_otg_set_param_otg_cap(core_if, dwc_param_otg_cap_default);
  59635. + dwc_otg_set_param_dma_enable(core_if, dwc_param_dma_enable_default);
  59636. + dwc_otg_set_param_dma_desc_enable(core_if,
  59637. + dwc_param_dma_desc_enable_default);
  59638. + dwc_otg_set_param_opt(core_if, dwc_param_opt_default);
  59639. + dwc_otg_set_param_dma_burst_size(core_if,
  59640. + dwc_param_dma_burst_size_default);
  59641. + dwc_otg_set_param_host_support_fs_ls_low_power(core_if,
  59642. + dwc_param_host_support_fs_ls_low_power_default);
  59643. + dwc_otg_set_param_enable_dynamic_fifo(core_if,
  59644. + dwc_param_enable_dynamic_fifo_default);
  59645. + dwc_otg_set_param_data_fifo_size(core_if,
  59646. + dwc_param_data_fifo_size_default);
  59647. + dwc_otg_set_param_dev_rx_fifo_size(core_if,
  59648. + dwc_param_dev_rx_fifo_size_default);
  59649. + dwc_otg_set_param_dev_nperio_tx_fifo_size(core_if,
  59650. + dwc_param_dev_nperio_tx_fifo_size_default);
  59651. + dwc_otg_set_param_host_rx_fifo_size(core_if,
  59652. + dwc_param_host_rx_fifo_size_default);
  59653. + dwc_otg_set_param_host_nperio_tx_fifo_size(core_if,
  59654. + dwc_param_host_nperio_tx_fifo_size_default);
  59655. + dwc_otg_set_param_host_perio_tx_fifo_size(core_if,
  59656. + dwc_param_host_perio_tx_fifo_size_default);
  59657. + dwc_otg_set_param_max_transfer_size(core_if,
  59658. + dwc_param_max_transfer_size_default);
  59659. + dwc_otg_set_param_max_packet_count(core_if,
  59660. + dwc_param_max_packet_count_default);
  59661. + dwc_otg_set_param_host_channels(core_if,
  59662. + dwc_param_host_channels_default);
  59663. + dwc_otg_set_param_dev_endpoints(core_if,
  59664. + dwc_param_dev_endpoints_default);
  59665. + dwc_otg_set_param_phy_type(core_if, dwc_param_phy_type_default);
  59666. + dwc_otg_set_param_speed(core_if, dwc_param_speed_default);
  59667. + dwc_otg_set_param_host_ls_low_power_phy_clk(core_if,
  59668. + dwc_param_host_ls_low_power_phy_clk_default);
  59669. + dwc_otg_set_param_phy_ulpi_ddr(core_if, dwc_param_phy_ulpi_ddr_default);
  59670. + dwc_otg_set_param_phy_ulpi_ext_vbus(core_if,
  59671. + dwc_param_phy_ulpi_ext_vbus_default);
  59672. + dwc_otg_set_param_phy_utmi_width(core_if,
  59673. + dwc_param_phy_utmi_width_default);
  59674. + dwc_otg_set_param_ts_dline(core_if, dwc_param_ts_dline_default);
  59675. + dwc_otg_set_param_i2c_enable(core_if, dwc_param_i2c_enable_default);
  59676. + dwc_otg_set_param_ulpi_fs_ls(core_if, dwc_param_ulpi_fs_ls_default);
  59677. + dwc_otg_set_param_en_multiple_tx_fifo(core_if,
  59678. + dwc_param_en_multiple_tx_fifo_default);
  59679. + for (i = 0; i < 15; i++) {
  59680. + dwc_otg_set_param_dev_perio_tx_fifo_size(core_if,
  59681. + dwc_param_dev_perio_tx_fifo_size_default,
  59682. + i);
  59683. + }
  59684. +
  59685. + for (i = 0; i < 15; i++) {
  59686. + dwc_otg_set_param_dev_tx_fifo_size(core_if,
  59687. + dwc_param_dev_tx_fifo_size_default,
  59688. + i);
  59689. + }
  59690. + dwc_otg_set_param_thr_ctl(core_if, dwc_param_thr_ctl_default);
  59691. + dwc_otg_set_param_mpi_enable(core_if, dwc_param_mpi_enable_default);
  59692. + dwc_otg_set_param_pti_enable(core_if, dwc_param_pti_enable_default);
  59693. + dwc_otg_set_param_lpm_enable(core_if, dwc_param_lpm_enable_default);
  59694. + dwc_otg_set_param_ic_usb_cap(core_if, dwc_param_ic_usb_cap_default);
  59695. + dwc_otg_set_param_tx_thr_length(core_if,
  59696. + dwc_param_tx_thr_length_default);
  59697. + dwc_otg_set_param_rx_thr_length(core_if,
  59698. + dwc_param_rx_thr_length_default);
  59699. + dwc_otg_set_param_ahb_thr_ratio(core_if,
  59700. + dwc_param_ahb_thr_ratio_default);
  59701. + dwc_otg_set_param_power_down(core_if, dwc_param_power_down_default);
  59702. + dwc_otg_set_param_reload_ctl(core_if, dwc_param_reload_ctl_default);
  59703. + dwc_otg_set_param_dev_out_nak(core_if, dwc_param_dev_out_nak_default);
  59704. + dwc_otg_set_param_cont_on_bna(core_if, dwc_param_cont_on_bna_default);
  59705. + dwc_otg_set_param_ahb_single(core_if, dwc_param_ahb_single_default);
  59706. + dwc_otg_set_param_otg_ver(core_if, dwc_param_otg_ver_default);
  59707. + dwc_otg_set_param_adp_enable(core_if, dwc_param_adp_enable_default);
  59708. + DWC_PRINTF("Finished setting default values for core params\n");
  59709. +
  59710. + return 0;
  59711. +}
  59712. +
  59713. +uint8_t dwc_otg_is_dma_enable(dwc_otg_core_if_t * core_if)
  59714. +{
  59715. + return core_if->dma_enable;
  59716. +}
  59717. +
  59718. +/* Checks if the parameter is outside of its valid range of values */
  59719. +#define DWC_OTG_PARAM_TEST(_param_, _low_, _high_) \
  59720. + (((_param_) < (_low_)) || \
  59721. + ((_param_) > (_high_)))
  59722. +
  59723. +/* Parameter access functions */
  59724. +int dwc_otg_set_param_otg_cap(dwc_otg_core_if_t * core_if, int32_t val)
  59725. +{
  59726. + int valid;
  59727. + int retval = 0;
  59728. + if (DWC_OTG_PARAM_TEST(val, 0, 2)) {
  59729. + DWC_WARN("Wrong value for otg_cap parameter\n");
  59730. + DWC_WARN("otg_cap parameter must be 0,1 or 2\n");
  59731. + retval = -DWC_E_INVALID;
  59732. + goto out;
  59733. + }
  59734. +
  59735. + valid = 1;
  59736. + switch (val) {
  59737. + case DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE:
  59738. + if (core_if->hwcfg2.b.op_mode !=
  59739. + DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  59740. + valid = 0;
  59741. + break;
  59742. + case DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE:
  59743. + if ((core_if->hwcfg2.b.op_mode !=
  59744. + DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  59745. + && (core_if->hwcfg2.b.op_mode !=
  59746. + DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG)
  59747. + && (core_if->hwcfg2.b.op_mode !=
  59748. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE)
  59749. + && (core_if->hwcfg2.b.op_mode !=
  59750. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)) {
  59751. + valid = 0;
  59752. + }
  59753. + break;
  59754. + case DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE:
  59755. + /* always valid */
  59756. + break;
  59757. + }
  59758. + if (!valid) {
  59759. + if (dwc_otg_param_initialized(core_if->core_params->otg_cap)) {
  59760. + DWC_ERROR
  59761. + ("%d invalid for otg_cap paremter. Check HW configuration.\n",
  59762. + val);
  59763. + }
  59764. + val =
  59765. + (((core_if->hwcfg2.b.op_mode ==
  59766. + DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  59767. + || (core_if->hwcfg2.b.op_mode ==
  59768. + DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG)
  59769. + || (core_if->hwcfg2.b.op_mode ==
  59770. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE)
  59771. + || (core_if->hwcfg2.b.op_mode ==
  59772. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)) ?
  59773. + DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE :
  59774. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  59775. + retval = -DWC_E_INVALID;
  59776. + }
  59777. +
  59778. + core_if->core_params->otg_cap = val;
  59779. +out:
  59780. + return retval;
  59781. +}
  59782. +
  59783. +int32_t dwc_otg_get_param_otg_cap(dwc_otg_core_if_t * core_if)
  59784. +{
  59785. + return core_if->core_params->otg_cap;
  59786. +}
  59787. +
  59788. +int dwc_otg_set_param_opt(dwc_otg_core_if_t * core_if, int32_t val)
  59789. +{
  59790. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  59791. + DWC_WARN("Wrong value for opt parameter\n");
  59792. + return -DWC_E_INVALID;
  59793. + }
  59794. + core_if->core_params->opt = val;
  59795. + return 0;
  59796. +}
  59797. +
  59798. +int32_t dwc_otg_get_param_opt(dwc_otg_core_if_t * core_if)
  59799. +{
  59800. + return core_if->core_params->opt;
  59801. +}
  59802. +
  59803. +int dwc_otg_set_param_dma_enable(dwc_otg_core_if_t * core_if, int32_t val)
  59804. +{
  59805. + int retval = 0;
  59806. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  59807. + DWC_WARN("Wrong value for dma enable\n");
  59808. + return -DWC_E_INVALID;
  59809. + }
  59810. +
  59811. + if ((val == 1) && (core_if->hwcfg2.b.architecture == 0)) {
  59812. + if (dwc_otg_param_initialized(core_if->core_params->dma_enable)) {
  59813. + DWC_ERROR
  59814. + ("%d invalid for dma_enable paremter. Check HW configuration.\n",
  59815. + val);
  59816. + }
  59817. + val = 0;
  59818. + retval = -DWC_E_INVALID;
  59819. + }
  59820. +
  59821. + core_if->core_params->dma_enable = val;
  59822. + if (val == 0) {
  59823. + dwc_otg_set_param_dma_desc_enable(core_if, 0);
  59824. + }
  59825. + return retval;
  59826. +}
  59827. +
  59828. +int32_t dwc_otg_get_param_dma_enable(dwc_otg_core_if_t * core_if)
  59829. +{
  59830. + return core_if->core_params->dma_enable;
  59831. +}
  59832. +
  59833. +int dwc_otg_set_param_dma_desc_enable(dwc_otg_core_if_t * core_if, int32_t val)
  59834. +{
  59835. + int retval = 0;
  59836. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  59837. + DWC_WARN("Wrong value for dma_enable\n");
  59838. + DWC_WARN("dma_desc_enable must be 0 or 1\n");
  59839. + return -DWC_E_INVALID;
  59840. + }
  59841. +
  59842. + if ((val == 1)
  59843. + && ((dwc_otg_get_param_dma_enable(core_if) == 0)
  59844. + || (core_if->hwcfg4.b.desc_dma == 0))) {
  59845. + if (dwc_otg_param_initialized
  59846. + (core_if->core_params->dma_desc_enable)) {
  59847. + DWC_ERROR
  59848. + ("%d invalid for dma_desc_enable paremter. Check HW configuration.\n",
  59849. + val);
  59850. + }
  59851. + val = 0;
  59852. + retval = -DWC_E_INVALID;
  59853. + }
  59854. + core_if->core_params->dma_desc_enable = val;
  59855. + return retval;
  59856. +}
  59857. +
  59858. +int32_t dwc_otg_get_param_dma_desc_enable(dwc_otg_core_if_t * core_if)
  59859. +{
  59860. + return core_if->core_params->dma_desc_enable;
  59861. +}
  59862. +
  59863. +int dwc_otg_set_param_host_support_fs_ls_low_power(dwc_otg_core_if_t * core_if,
  59864. + int32_t val)
  59865. +{
  59866. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  59867. + DWC_WARN("Wrong value for host_support_fs_low_power\n");
  59868. + DWC_WARN("host_support_fs_low_power must be 0 or 1\n");
  59869. + return -DWC_E_INVALID;
  59870. + }
  59871. + core_if->core_params->host_support_fs_ls_low_power = val;
  59872. + return 0;
  59873. +}
  59874. +
  59875. +int32_t dwc_otg_get_param_host_support_fs_ls_low_power(dwc_otg_core_if_t *
  59876. + core_if)
  59877. +{
  59878. + return core_if->core_params->host_support_fs_ls_low_power;
  59879. +}
  59880. +
  59881. +int dwc_otg_set_param_enable_dynamic_fifo(dwc_otg_core_if_t * core_if,
  59882. + int32_t val)
  59883. +{
  59884. + int retval = 0;
  59885. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  59886. + DWC_WARN("Wrong value for enable_dynamic_fifo\n");
  59887. + DWC_WARN("enable_dynamic_fifo must be 0 or 1\n");
  59888. + return -DWC_E_INVALID;
  59889. + }
  59890. +
  59891. + if ((val == 1) && (core_if->hwcfg2.b.dynamic_fifo == 0)) {
  59892. + if (dwc_otg_param_initialized
  59893. + (core_if->core_params->enable_dynamic_fifo)) {
  59894. + DWC_ERROR
  59895. + ("%d invalid for enable_dynamic_fifo paremter. Check HW configuration.\n",
  59896. + val);
  59897. + }
  59898. + val = 0;
  59899. + retval = -DWC_E_INVALID;
  59900. + }
  59901. + core_if->core_params->enable_dynamic_fifo = val;
  59902. + return retval;
  59903. +}
  59904. +
  59905. +int32_t dwc_otg_get_param_enable_dynamic_fifo(dwc_otg_core_if_t * core_if)
  59906. +{
  59907. + return core_if->core_params->enable_dynamic_fifo;
  59908. +}
  59909. +
  59910. +int dwc_otg_set_param_data_fifo_size(dwc_otg_core_if_t * core_if, int32_t val)
  59911. +{
  59912. + int retval = 0;
  59913. + if (DWC_OTG_PARAM_TEST(val, 32, 32768)) {
  59914. + DWC_WARN("Wrong value for data_fifo_size\n");
  59915. + DWC_WARN("data_fifo_size must be 32-32768\n");
  59916. + return -DWC_E_INVALID;
  59917. + }
  59918. +
  59919. + if (val > core_if->hwcfg3.b.dfifo_depth) {
  59920. + if (dwc_otg_param_initialized
  59921. + (core_if->core_params->data_fifo_size)) {
  59922. + DWC_ERROR
  59923. + ("%d invalid for data_fifo_size parameter. Check HW configuration.\n",
  59924. + val);
  59925. + }
  59926. + val = core_if->hwcfg3.b.dfifo_depth;
  59927. + retval = -DWC_E_INVALID;
  59928. + }
  59929. +
  59930. + core_if->core_params->data_fifo_size = val;
  59931. + return retval;
  59932. +}
  59933. +
  59934. +int32_t dwc_otg_get_param_data_fifo_size(dwc_otg_core_if_t * core_if)
  59935. +{
  59936. + return core_if->core_params->data_fifo_size;
  59937. +}
  59938. +
  59939. +int dwc_otg_set_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if, int32_t val)
  59940. +{
  59941. + int retval = 0;
  59942. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  59943. + DWC_WARN("Wrong value for dev_rx_fifo_size\n");
  59944. + DWC_WARN("dev_rx_fifo_size must be 16-32768\n");
  59945. + return -DWC_E_INVALID;
  59946. + }
  59947. +
  59948. + if (val > DWC_READ_REG32(&core_if->core_global_regs->grxfsiz)) {
  59949. + if (dwc_otg_param_initialized(core_if->core_params->dev_rx_fifo_size)) {
  59950. + DWC_WARN("%d invalid for dev_rx_fifo_size parameter\n", val);
  59951. + }
  59952. + val = DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  59953. + retval = -DWC_E_INVALID;
  59954. + }
  59955. +
  59956. + core_if->core_params->dev_rx_fifo_size = val;
  59957. + return retval;
  59958. +}
  59959. +
  59960. +int32_t dwc_otg_get_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if)
  59961. +{
  59962. + return core_if->core_params->dev_rx_fifo_size;
  59963. +}
  59964. +
  59965. +int dwc_otg_set_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  59966. + int32_t val)
  59967. +{
  59968. + int retval = 0;
  59969. +
  59970. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  59971. + DWC_WARN("Wrong value for dev_nperio_tx_fifo\n");
  59972. + DWC_WARN("dev_nperio_tx_fifo must be 16-32768\n");
  59973. + return -DWC_E_INVALID;
  59974. + }
  59975. +
  59976. + if (val > (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >> 16)) {
  59977. + if (dwc_otg_param_initialized
  59978. + (core_if->core_params->dev_nperio_tx_fifo_size)) {
  59979. + DWC_ERROR
  59980. + ("%d invalid for dev_nperio_tx_fifo_size. Check HW configuration.\n",
  59981. + val);
  59982. + }
  59983. + val =
  59984. + (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >>
  59985. + 16);
  59986. + retval = -DWC_E_INVALID;
  59987. + }
  59988. +
  59989. + core_if->core_params->dev_nperio_tx_fifo_size = val;
  59990. + return retval;
  59991. +}
  59992. +
  59993. +int32_t dwc_otg_get_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if)
  59994. +{
  59995. + return core_if->core_params->dev_nperio_tx_fifo_size;
  59996. +}
  59997. +
  59998. +int dwc_otg_set_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if,
  59999. + int32_t val)
  60000. +{
  60001. + int retval = 0;
  60002. +
  60003. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  60004. + DWC_WARN("Wrong value for host_rx_fifo_size\n");
  60005. + DWC_WARN("host_rx_fifo_size must be 16-32768\n");
  60006. + return -DWC_E_INVALID;
  60007. + }
  60008. +
  60009. + if (val > DWC_READ_REG32(&core_if->core_global_regs->grxfsiz)) {
  60010. + if (dwc_otg_param_initialized
  60011. + (core_if->core_params->host_rx_fifo_size)) {
  60012. + DWC_ERROR
  60013. + ("%d invalid for host_rx_fifo_size. Check HW configuration.\n",
  60014. + val);
  60015. + }
  60016. + val = DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  60017. + retval = -DWC_E_INVALID;
  60018. + }
  60019. +
  60020. + core_if->core_params->host_rx_fifo_size = val;
  60021. + return retval;
  60022. +
  60023. +}
  60024. +
  60025. +int32_t dwc_otg_get_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if)
  60026. +{
  60027. + return core_if->core_params->host_rx_fifo_size;
  60028. +}
  60029. +
  60030. +int dwc_otg_set_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  60031. + int32_t val)
  60032. +{
  60033. + int retval = 0;
  60034. +
  60035. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  60036. + DWC_WARN("Wrong value for host_nperio_tx_fifo_size\n");
  60037. + DWC_WARN("host_nperio_tx_fifo_size must be 16-32768\n");
  60038. + return -DWC_E_INVALID;
  60039. + }
  60040. +
  60041. + if (val > (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >> 16)) {
  60042. + if (dwc_otg_param_initialized
  60043. + (core_if->core_params->host_nperio_tx_fifo_size)) {
  60044. + DWC_ERROR
  60045. + ("%d invalid for host_nperio_tx_fifo_size. Check HW configuration.\n",
  60046. + val);
  60047. + }
  60048. + val =
  60049. + (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >>
  60050. + 16);
  60051. + retval = -DWC_E_INVALID;
  60052. + }
  60053. +
  60054. + core_if->core_params->host_nperio_tx_fifo_size = val;
  60055. + return retval;
  60056. +}
  60057. +
  60058. +int32_t dwc_otg_get_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if)
  60059. +{
  60060. + return core_if->core_params->host_nperio_tx_fifo_size;
  60061. +}
  60062. +
  60063. +int dwc_otg_set_param_host_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  60064. + int32_t val)
  60065. +{
  60066. + int retval = 0;
  60067. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  60068. + DWC_WARN("Wrong value for host_perio_tx_fifo_size\n");
  60069. + DWC_WARN("host_perio_tx_fifo_size must be 16-32768\n");
  60070. + return -DWC_E_INVALID;
  60071. + }
  60072. +
  60073. + if (val > ((core_if->hptxfsiz.d32) >> 16)) {
  60074. + if (dwc_otg_param_initialized
  60075. + (core_if->core_params->host_perio_tx_fifo_size)) {
  60076. + DWC_ERROR
  60077. + ("%d invalid for host_perio_tx_fifo_size. Check HW configuration.\n",
  60078. + val);
  60079. + }
  60080. + val = (core_if->hptxfsiz.d32) >> 16;
  60081. + retval = -DWC_E_INVALID;
  60082. + }
  60083. +
  60084. + core_if->core_params->host_perio_tx_fifo_size = val;
  60085. + return retval;
  60086. +}
  60087. +
  60088. +int32_t dwc_otg_get_param_host_perio_tx_fifo_size(dwc_otg_core_if_t * core_if)
  60089. +{
  60090. + return core_if->core_params->host_perio_tx_fifo_size;
  60091. +}
  60092. +
  60093. +int dwc_otg_set_param_max_transfer_size(dwc_otg_core_if_t * core_if,
  60094. + int32_t val)
  60095. +{
  60096. + int retval = 0;
  60097. +
  60098. + if (DWC_OTG_PARAM_TEST(val, 2047, 524288)) {
  60099. + DWC_WARN("Wrong value for max_transfer_size\n");
  60100. + DWC_WARN("max_transfer_size must be 2047-524288\n");
  60101. + return -DWC_E_INVALID;
  60102. + }
  60103. +
  60104. + if (val >= (1 << (core_if->hwcfg3.b.xfer_size_cntr_width + 11))) {
  60105. + if (dwc_otg_param_initialized
  60106. + (core_if->core_params->max_transfer_size)) {
  60107. + DWC_ERROR
  60108. + ("%d invalid for max_transfer_size. Check HW configuration.\n",
  60109. + val);
  60110. + }
  60111. + val =
  60112. + ((1 << (core_if->hwcfg3.b.packet_size_cntr_width + 11)) -
  60113. + 1);
  60114. + retval = -DWC_E_INVALID;
  60115. + }
  60116. +
  60117. + core_if->core_params->max_transfer_size = val;
  60118. + return retval;
  60119. +}
  60120. +
  60121. +int32_t dwc_otg_get_param_max_transfer_size(dwc_otg_core_if_t * core_if)
  60122. +{
  60123. + return core_if->core_params->max_transfer_size;
  60124. +}
  60125. +
  60126. +int dwc_otg_set_param_max_packet_count(dwc_otg_core_if_t * core_if, int32_t val)
  60127. +{
  60128. + int retval = 0;
  60129. +
  60130. + if (DWC_OTG_PARAM_TEST(val, 15, 511)) {
  60131. + DWC_WARN("Wrong value for max_packet_count\n");
  60132. + DWC_WARN("max_packet_count must be 15-511\n");
  60133. + return -DWC_E_INVALID;
  60134. + }
  60135. +
  60136. + if (val > (1 << (core_if->hwcfg3.b.packet_size_cntr_width + 4))) {
  60137. + if (dwc_otg_param_initialized
  60138. + (core_if->core_params->max_packet_count)) {
  60139. + DWC_ERROR
  60140. + ("%d invalid for max_packet_count. Check HW configuration.\n",
  60141. + val);
  60142. + }
  60143. + val =
  60144. + ((1 << (core_if->hwcfg3.b.packet_size_cntr_width + 4)) - 1);
  60145. + retval = -DWC_E_INVALID;
  60146. + }
  60147. +
  60148. + core_if->core_params->max_packet_count = val;
  60149. + return retval;
  60150. +}
  60151. +
  60152. +int32_t dwc_otg_get_param_max_packet_count(dwc_otg_core_if_t * core_if)
  60153. +{
  60154. + return core_if->core_params->max_packet_count;
  60155. +}
  60156. +
  60157. +int dwc_otg_set_param_host_channels(dwc_otg_core_if_t * core_if, int32_t val)
  60158. +{
  60159. + int retval = 0;
  60160. +
  60161. + if (DWC_OTG_PARAM_TEST(val, 1, 16)) {
  60162. + DWC_WARN("Wrong value for host_channels\n");
  60163. + DWC_WARN("host_channels must be 1-16\n");
  60164. + return -DWC_E_INVALID;
  60165. + }
  60166. +
  60167. + if (val > (core_if->hwcfg2.b.num_host_chan + 1)) {
  60168. + if (dwc_otg_param_initialized
  60169. + (core_if->core_params->host_channels)) {
  60170. + DWC_ERROR
  60171. + ("%d invalid for host_channels. Check HW configurations.\n",
  60172. + val);
  60173. + }
  60174. + val = (core_if->hwcfg2.b.num_host_chan + 1);
  60175. + retval = -DWC_E_INVALID;
  60176. + }
  60177. +
  60178. + core_if->core_params->host_channels = val;
  60179. + return retval;
  60180. +}
  60181. +
  60182. +int32_t dwc_otg_get_param_host_channels(dwc_otg_core_if_t * core_if)
  60183. +{
  60184. + return core_if->core_params->host_channels;
  60185. +}
  60186. +
  60187. +int dwc_otg_set_param_dev_endpoints(dwc_otg_core_if_t * core_if, int32_t val)
  60188. +{
  60189. + int retval = 0;
  60190. +
  60191. + if (DWC_OTG_PARAM_TEST(val, 1, 15)) {
  60192. + DWC_WARN("Wrong value for dev_endpoints\n");
  60193. + DWC_WARN("dev_endpoints must be 1-15\n");
  60194. + return -DWC_E_INVALID;
  60195. + }
  60196. +
  60197. + if (val > (core_if->hwcfg2.b.num_dev_ep)) {
  60198. + if (dwc_otg_param_initialized
  60199. + (core_if->core_params->dev_endpoints)) {
  60200. + DWC_ERROR
  60201. + ("%d invalid for dev_endpoints. Check HW configurations.\n",
  60202. + val);
  60203. + }
  60204. + val = core_if->hwcfg2.b.num_dev_ep;
  60205. + retval = -DWC_E_INVALID;
  60206. + }
  60207. +
  60208. + core_if->core_params->dev_endpoints = val;
  60209. + return retval;
  60210. +}
  60211. +
  60212. +int32_t dwc_otg_get_param_dev_endpoints(dwc_otg_core_if_t * core_if)
  60213. +{
  60214. + return core_if->core_params->dev_endpoints;
  60215. +}
  60216. +
  60217. +int dwc_otg_set_param_phy_type(dwc_otg_core_if_t * core_if, int32_t val)
  60218. +{
  60219. + int retval = 0;
  60220. + int valid = 0;
  60221. +
  60222. + if (DWC_OTG_PARAM_TEST(val, 0, 2)) {
  60223. + DWC_WARN("Wrong value for phy_type\n");
  60224. + DWC_WARN("phy_type must be 0,1 or 2\n");
  60225. + return -DWC_E_INVALID;
  60226. + }
  60227. +#ifndef NO_FS_PHY_HW_CHECKS
  60228. + if ((val == DWC_PHY_TYPE_PARAM_UTMI) &&
  60229. + ((core_if->hwcfg2.b.hs_phy_type == 1) ||
  60230. + (core_if->hwcfg2.b.hs_phy_type == 3))) {
  60231. + valid = 1;
  60232. + } else if ((val == DWC_PHY_TYPE_PARAM_ULPI) &&
  60233. + ((core_if->hwcfg2.b.hs_phy_type == 2) ||
  60234. + (core_if->hwcfg2.b.hs_phy_type == 3))) {
  60235. + valid = 1;
  60236. + } else if ((val == DWC_PHY_TYPE_PARAM_FS) &&
  60237. + (core_if->hwcfg2.b.fs_phy_type == 1)) {
  60238. + valid = 1;
  60239. + }
  60240. + if (!valid) {
  60241. + if (dwc_otg_param_initialized(core_if->core_params->phy_type)) {
  60242. + DWC_ERROR
  60243. + ("%d invalid for phy_type. Check HW configurations.\n",
  60244. + val);
  60245. + }
  60246. + if (core_if->hwcfg2.b.hs_phy_type) {
  60247. + if ((core_if->hwcfg2.b.hs_phy_type == 3) ||
  60248. + (core_if->hwcfg2.b.hs_phy_type == 1)) {
  60249. + val = DWC_PHY_TYPE_PARAM_UTMI;
  60250. + } else {
  60251. + val = DWC_PHY_TYPE_PARAM_ULPI;
  60252. + }
  60253. + }
  60254. + retval = -DWC_E_INVALID;
  60255. + }
  60256. +#endif
  60257. + core_if->core_params->phy_type = val;
  60258. + return retval;
  60259. +}
  60260. +
  60261. +int32_t dwc_otg_get_param_phy_type(dwc_otg_core_if_t * core_if)
  60262. +{
  60263. + return core_if->core_params->phy_type;
  60264. +}
  60265. +
  60266. +int dwc_otg_set_param_speed(dwc_otg_core_if_t * core_if, int32_t val)
  60267. +{
  60268. + int retval = 0;
  60269. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  60270. + DWC_WARN("Wrong value for speed parameter\n");
  60271. + DWC_WARN("max_speed parameter must be 0 or 1\n");
  60272. + return -DWC_E_INVALID;
  60273. + }
  60274. + if ((val == 0)
  60275. + && dwc_otg_get_param_phy_type(core_if) == DWC_PHY_TYPE_PARAM_FS) {
  60276. + if (dwc_otg_param_initialized(core_if->core_params->speed)) {
  60277. + DWC_ERROR
  60278. + ("%d invalid for speed paremter. Check HW configuration.\n",
  60279. + val);
  60280. + }
  60281. + val =
  60282. + (dwc_otg_get_param_phy_type(core_if) ==
  60283. + DWC_PHY_TYPE_PARAM_FS ? 1 : 0);
  60284. + retval = -DWC_E_INVALID;
  60285. + }
  60286. + core_if->core_params->speed = val;
  60287. + return retval;
  60288. +}
  60289. +
  60290. +int32_t dwc_otg_get_param_speed(dwc_otg_core_if_t * core_if)
  60291. +{
  60292. + return core_if->core_params->speed;
  60293. +}
  60294. +
  60295. +int dwc_otg_set_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t * core_if,
  60296. + int32_t val)
  60297. +{
  60298. + int retval = 0;
  60299. +
  60300. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  60301. + DWC_WARN
  60302. + ("Wrong value for host_ls_low_power_phy_clk parameter\n");
  60303. + DWC_WARN("host_ls_low_power_phy_clk must be 0 or 1\n");
  60304. + return -DWC_E_INVALID;
  60305. + }
  60306. +
  60307. + if ((val == DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ)
  60308. + && (dwc_otg_get_param_phy_type(core_if) == DWC_PHY_TYPE_PARAM_FS)) {
  60309. + if (dwc_otg_param_initialized
  60310. + (core_if->core_params->host_ls_low_power_phy_clk)) {
  60311. + DWC_ERROR
  60312. + ("%d invalid for host_ls_low_power_phy_clk. Check HW configuration.\n",
  60313. + val);
  60314. + }
  60315. + val =
  60316. + (dwc_otg_get_param_phy_type(core_if) ==
  60317. + DWC_PHY_TYPE_PARAM_FS) ?
  60318. + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ :
  60319. + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ;
  60320. + retval = -DWC_E_INVALID;
  60321. + }
  60322. +
  60323. + core_if->core_params->host_ls_low_power_phy_clk = val;
  60324. + return retval;
  60325. +}
  60326. +
  60327. +int32_t dwc_otg_get_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t * core_if)
  60328. +{
  60329. + return core_if->core_params->host_ls_low_power_phy_clk;
  60330. +}
  60331. +
  60332. +int dwc_otg_set_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if, int32_t val)
  60333. +{
  60334. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  60335. + DWC_WARN("Wrong value for phy_ulpi_ddr\n");
  60336. + DWC_WARN("phy_upli_ddr must be 0 or 1\n");
  60337. + return -DWC_E_INVALID;
  60338. + }
  60339. +
  60340. + core_if->core_params->phy_ulpi_ddr = val;
  60341. + return 0;
  60342. +}
  60343. +
  60344. +int32_t dwc_otg_get_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if)
  60345. +{
  60346. + return core_if->core_params->phy_ulpi_ddr;
  60347. +}
  60348. +
  60349. +int dwc_otg_set_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if,
  60350. + int32_t val)
  60351. +{
  60352. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  60353. + DWC_WARN("Wrong valaue for phy_ulpi_ext_vbus\n");
  60354. + DWC_WARN("phy_ulpi_ext_vbus must be 0 or 1\n");
  60355. + return -DWC_E_INVALID;
  60356. + }
  60357. +
  60358. + core_if->core_params->phy_ulpi_ext_vbus = val;
  60359. + return 0;
  60360. +}
  60361. +
  60362. +int32_t dwc_otg_get_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if)
  60363. +{
  60364. + return core_if->core_params->phy_ulpi_ext_vbus;
  60365. +}
  60366. +
  60367. +int dwc_otg_set_param_phy_utmi_width(dwc_otg_core_if_t * core_if, int32_t val)
  60368. +{
  60369. + if (DWC_OTG_PARAM_TEST(val, 8, 8) && DWC_OTG_PARAM_TEST(val, 16, 16)) {
  60370. + DWC_WARN("Wrong valaue for phy_utmi_width\n");
  60371. + DWC_WARN("phy_utmi_width must be 8 or 16\n");
  60372. + return -DWC_E_INVALID;
  60373. + }
  60374. +
  60375. + core_if->core_params->phy_utmi_width = val;
  60376. + return 0;
  60377. +}
  60378. +
  60379. +int32_t dwc_otg_get_param_phy_utmi_width(dwc_otg_core_if_t * core_if)
  60380. +{
  60381. + return core_if->core_params->phy_utmi_width;
  60382. +}
  60383. +
  60384. +int dwc_otg_set_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if, int32_t val)
  60385. +{
  60386. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  60387. + DWC_WARN("Wrong valaue for ulpi_fs_ls\n");
  60388. + DWC_WARN("ulpi_fs_ls must be 0 or 1\n");
  60389. + return -DWC_E_INVALID;
  60390. + }
  60391. +
  60392. + core_if->core_params->ulpi_fs_ls = val;
  60393. + return 0;
  60394. +}
  60395. +
  60396. +int32_t dwc_otg_get_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if)
  60397. +{
  60398. + return core_if->core_params->ulpi_fs_ls;
  60399. +}
  60400. +
  60401. +int dwc_otg_set_param_ts_dline(dwc_otg_core_if_t * core_if, int32_t val)
  60402. +{
  60403. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  60404. + DWC_WARN("Wrong valaue for ts_dline\n");
  60405. + DWC_WARN("ts_dline must be 0 or 1\n");
  60406. + return -DWC_E_INVALID;
  60407. + }
  60408. +
  60409. + core_if->core_params->ts_dline = val;
  60410. + return 0;
  60411. +}
  60412. +
  60413. +int32_t dwc_otg_get_param_ts_dline(dwc_otg_core_if_t * core_if)
  60414. +{
  60415. + return core_if->core_params->ts_dline;
  60416. +}
  60417. +
  60418. +int dwc_otg_set_param_i2c_enable(dwc_otg_core_if_t * core_if, int32_t val)
  60419. +{
  60420. + int retval = 0;
  60421. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  60422. + DWC_WARN("Wrong valaue for i2c_enable\n");
  60423. + DWC_WARN("i2c_enable must be 0 or 1\n");
  60424. + return -DWC_E_INVALID;
  60425. + }
  60426. +#ifndef NO_FS_PHY_HW_CHECK
  60427. + if (val == 1 && core_if->hwcfg3.b.i2c == 0) {
  60428. + if (dwc_otg_param_initialized(core_if->core_params->i2c_enable)) {
  60429. + DWC_ERROR
  60430. + ("%d invalid for i2c_enable. Check HW configuration.\n",
  60431. + val);
  60432. + }
  60433. + val = 0;
  60434. + retval = -DWC_E_INVALID;
  60435. + }
  60436. +#endif
  60437. +
  60438. + core_if->core_params->i2c_enable = val;
  60439. + return retval;
  60440. +}
  60441. +
  60442. +int32_t dwc_otg_get_param_i2c_enable(dwc_otg_core_if_t * core_if)
  60443. +{
  60444. + return core_if->core_params->i2c_enable;
  60445. +}
  60446. +
  60447. +int dwc_otg_set_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  60448. + int32_t val, int fifo_num)
  60449. +{
  60450. + int retval = 0;
  60451. +
  60452. + if (DWC_OTG_PARAM_TEST(val, 4, 768)) {
  60453. + DWC_WARN("Wrong value for dev_perio_tx_fifo_size\n");
  60454. + DWC_WARN("dev_perio_tx_fifo_size must be 4-768\n");
  60455. + return -DWC_E_INVALID;
  60456. + }
  60457. +
  60458. + if (val >
  60459. + (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]))) {
  60460. + if (dwc_otg_param_initialized
  60461. + (core_if->core_params->dev_perio_tx_fifo_size[fifo_num])) {
  60462. + DWC_ERROR
  60463. + ("`%d' invalid for parameter `dev_perio_fifo_size_%d'. Check HW configuration.\n",
  60464. + val, fifo_num);
  60465. + }
  60466. + val = (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]));
  60467. + retval = -DWC_E_INVALID;
  60468. + }
  60469. +
  60470. + core_if->core_params->dev_perio_tx_fifo_size[fifo_num] = val;
  60471. + return retval;
  60472. +}
  60473. +
  60474. +int32_t dwc_otg_get_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  60475. + int fifo_num)
  60476. +{
  60477. + return core_if->core_params->dev_perio_tx_fifo_size[fifo_num];
  60478. +}
  60479. +
  60480. +int dwc_otg_set_param_en_multiple_tx_fifo(dwc_otg_core_if_t * core_if,
  60481. + int32_t val)
  60482. +{
  60483. + int retval = 0;
  60484. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  60485. + DWC_WARN("Wrong valaue for en_multiple_tx_fifo,\n");
  60486. + DWC_WARN("en_multiple_tx_fifo must be 0 or 1\n");
  60487. + return -DWC_E_INVALID;
  60488. + }
  60489. +
  60490. + if (val == 1 && core_if->hwcfg4.b.ded_fifo_en == 0) {
  60491. + if (dwc_otg_param_initialized
  60492. + (core_if->core_params->en_multiple_tx_fifo)) {
  60493. + DWC_ERROR
  60494. + ("%d invalid for parameter en_multiple_tx_fifo. Check HW configuration.\n",
  60495. + val);
  60496. + }
  60497. + val = 0;
  60498. + retval = -DWC_E_INVALID;
  60499. + }
  60500. +
  60501. + core_if->core_params->en_multiple_tx_fifo = val;
  60502. + return retval;
  60503. +}
  60504. +
  60505. +int32_t dwc_otg_get_param_en_multiple_tx_fifo(dwc_otg_core_if_t * core_if)
  60506. +{
  60507. + return core_if->core_params->en_multiple_tx_fifo;
  60508. +}
  60509. +
  60510. +int dwc_otg_set_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if, int32_t val,
  60511. + int fifo_num)
  60512. +{
  60513. + int retval = 0;
  60514. +
  60515. + if (DWC_OTG_PARAM_TEST(val, 4, 768)) {
  60516. + DWC_WARN("Wrong value for dev_tx_fifo_size\n");
  60517. + DWC_WARN("dev_tx_fifo_size must be 4-768\n");
  60518. + return -DWC_E_INVALID;
  60519. + }
  60520. +
  60521. + if (val >
  60522. + (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]))) {
  60523. + if (dwc_otg_param_initialized
  60524. + (core_if->core_params->dev_tx_fifo_size[fifo_num])) {
  60525. + DWC_ERROR
  60526. + ("`%d' invalid for parameter `dev_tx_fifo_size_%d'. Check HW configuration.\n",
  60527. + val, fifo_num);
  60528. + }
  60529. + val = (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]));
  60530. + retval = -DWC_E_INVALID;
  60531. + }
  60532. +
  60533. + core_if->core_params->dev_tx_fifo_size[fifo_num] = val;
  60534. + return retval;
  60535. +}
  60536. +
  60537. +int32_t dwc_otg_get_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if,
  60538. + int fifo_num)
  60539. +{
  60540. + return core_if->core_params->dev_tx_fifo_size[fifo_num];
  60541. +}
  60542. +
  60543. +int dwc_otg_set_param_thr_ctl(dwc_otg_core_if_t * core_if, int32_t val)
  60544. +{
  60545. + int retval = 0;
  60546. +
  60547. + if (DWC_OTG_PARAM_TEST(val, 0, 7)) {
  60548. + DWC_WARN("Wrong value for thr_ctl\n");
  60549. + DWC_WARN("thr_ctl must be 0-7\n");
  60550. + return -DWC_E_INVALID;
  60551. + }
  60552. +
  60553. + if ((val != 0) &&
  60554. + (!dwc_otg_get_param_dma_enable(core_if) ||
  60555. + !core_if->hwcfg4.b.ded_fifo_en)) {
  60556. + if (dwc_otg_param_initialized(core_if->core_params->thr_ctl)) {
  60557. + DWC_ERROR
  60558. + ("%d invalid for parameter thr_ctl. Check HW configuration.\n",
  60559. + val);
  60560. + }
  60561. + val = 0;
  60562. + retval = -DWC_E_INVALID;
  60563. + }
  60564. +
  60565. + core_if->core_params->thr_ctl = val;
  60566. + return retval;
  60567. +}
  60568. +
  60569. +int32_t dwc_otg_get_param_thr_ctl(dwc_otg_core_if_t * core_if)
  60570. +{
  60571. + return core_if->core_params->thr_ctl;
  60572. +}
  60573. +
  60574. +int dwc_otg_set_param_lpm_enable(dwc_otg_core_if_t * core_if, int32_t val)
  60575. +{
  60576. + int retval = 0;
  60577. +
  60578. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  60579. + DWC_WARN("Wrong value for lpm_enable\n");
  60580. + DWC_WARN("lpm_enable must be 0 or 1\n");
  60581. + return -DWC_E_INVALID;
  60582. + }
  60583. +
  60584. + if (val && !core_if->hwcfg3.b.otg_lpm_en) {
  60585. + if (dwc_otg_param_initialized(core_if->core_params->lpm_enable)) {
  60586. + DWC_ERROR
  60587. + ("%d invalid for parameter lpm_enable. Check HW configuration.\n",
  60588. + val);
  60589. + }
  60590. + val = 0;
  60591. + retval = -DWC_E_INVALID;
  60592. + }
  60593. +
  60594. + core_if->core_params->lpm_enable = val;
  60595. + return retval;
  60596. +}
  60597. +
  60598. +int32_t dwc_otg_get_param_lpm_enable(dwc_otg_core_if_t * core_if)
  60599. +{
  60600. + return core_if->core_params->lpm_enable;
  60601. +}
  60602. +
  60603. +int dwc_otg_set_param_tx_thr_length(dwc_otg_core_if_t * core_if, int32_t val)
  60604. +{
  60605. + if (DWC_OTG_PARAM_TEST(val, 8, 128)) {
  60606. + DWC_WARN("Wrong valaue for tx_thr_length\n");
  60607. + DWC_WARN("tx_thr_length must be 8 - 128\n");
  60608. + return -DWC_E_INVALID;
  60609. + }
  60610. +
  60611. + core_if->core_params->tx_thr_length = val;
  60612. + return 0;
  60613. +}
  60614. +
  60615. +int32_t dwc_otg_get_param_tx_thr_length(dwc_otg_core_if_t * core_if)
  60616. +{
  60617. + return core_if->core_params->tx_thr_length;
  60618. +}
  60619. +
  60620. +int dwc_otg_set_param_rx_thr_length(dwc_otg_core_if_t * core_if, int32_t val)
  60621. +{
  60622. + if (DWC_OTG_PARAM_TEST(val, 8, 128)) {
  60623. + DWC_WARN("Wrong valaue for rx_thr_length\n");
  60624. + DWC_WARN("rx_thr_length must be 8 - 128\n");
  60625. + return -DWC_E_INVALID;
  60626. + }
  60627. +
  60628. + core_if->core_params->rx_thr_length = val;
  60629. + return 0;
  60630. +}
  60631. +
  60632. +int32_t dwc_otg_get_param_rx_thr_length(dwc_otg_core_if_t * core_if)
  60633. +{
  60634. + return core_if->core_params->rx_thr_length;
  60635. +}
  60636. +
  60637. +int dwc_otg_set_param_dma_burst_size(dwc_otg_core_if_t * core_if, int32_t val)
  60638. +{
  60639. + if (DWC_OTG_PARAM_TEST(val, 1, 1) &&
  60640. + DWC_OTG_PARAM_TEST(val, 4, 4) &&
  60641. + DWC_OTG_PARAM_TEST(val, 8, 8) &&
  60642. + DWC_OTG_PARAM_TEST(val, 16, 16) &&
  60643. + DWC_OTG_PARAM_TEST(val, 32, 32) &&
  60644. + DWC_OTG_PARAM_TEST(val, 64, 64) &&
  60645. + DWC_OTG_PARAM_TEST(val, 128, 128) &&
  60646. + DWC_OTG_PARAM_TEST(val, 256, 256)) {
  60647. + DWC_WARN("`%d' invalid for parameter `dma_burst_size'\n", val);
  60648. + return -DWC_E_INVALID;
  60649. + }
  60650. + core_if->core_params->dma_burst_size = val;
  60651. + return 0;
  60652. +}
  60653. +
  60654. +int32_t dwc_otg_get_param_dma_burst_size(dwc_otg_core_if_t * core_if)
  60655. +{
  60656. + return core_if->core_params->dma_burst_size;
  60657. +}
  60658. +
  60659. +int dwc_otg_set_param_pti_enable(dwc_otg_core_if_t * core_if, int32_t val)
  60660. +{
  60661. + int retval = 0;
  60662. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  60663. + DWC_WARN("`%d' invalid for parameter `pti_enable'\n", val);
  60664. + return -DWC_E_INVALID;
  60665. + }
  60666. + if (val && (core_if->snpsid < OTG_CORE_REV_2_72a)) {
  60667. + if (dwc_otg_param_initialized(core_if->core_params->pti_enable)) {
  60668. + DWC_ERROR
  60669. + ("%d invalid for parameter pti_enable. Check HW configuration.\n",
  60670. + val);
  60671. + }
  60672. + retval = -DWC_E_INVALID;
  60673. + val = 0;
  60674. + }
  60675. + core_if->core_params->pti_enable = val;
  60676. + return retval;
  60677. +}
  60678. +
  60679. +int32_t dwc_otg_get_param_pti_enable(dwc_otg_core_if_t * core_if)
  60680. +{
  60681. + return core_if->core_params->pti_enable;
  60682. +}
  60683. +
  60684. +int dwc_otg_set_param_mpi_enable(dwc_otg_core_if_t * core_if, int32_t val)
  60685. +{
  60686. + int retval = 0;
  60687. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  60688. + DWC_WARN("`%d' invalid for parameter `mpi_enable'\n", val);
  60689. + return -DWC_E_INVALID;
  60690. + }
  60691. + if (val && (core_if->hwcfg2.b.multi_proc_int == 0)) {
  60692. + if (dwc_otg_param_initialized(core_if->core_params->mpi_enable)) {
  60693. + DWC_ERROR
  60694. + ("%d invalid for parameter mpi_enable. Check HW configuration.\n",
  60695. + val);
  60696. + }
  60697. + retval = -DWC_E_INVALID;
  60698. + val = 0;
  60699. + }
  60700. + core_if->core_params->mpi_enable = val;
  60701. + return retval;
  60702. +}
  60703. +
  60704. +int32_t dwc_otg_get_param_mpi_enable(dwc_otg_core_if_t * core_if)
  60705. +{
  60706. + return core_if->core_params->mpi_enable;
  60707. +}
  60708. +
  60709. +int dwc_otg_set_param_adp_enable(dwc_otg_core_if_t * core_if, int32_t val)
  60710. +{
  60711. + int retval = 0;
  60712. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  60713. + DWC_WARN("`%d' invalid for parameter `adp_enable'\n", val);
  60714. + return -DWC_E_INVALID;
  60715. + }
  60716. + if (val && (core_if->hwcfg3.b.adp_supp == 0)) {
  60717. + if (dwc_otg_param_initialized
  60718. + (core_if->core_params->adp_supp_enable)) {
  60719. + DWC_ERROR
  60720. + ("%d invalid for parameter adp_enable. Check HW configuration.\n",
  60721. + val);
  60722. + }
  60723. + retval = -DWC_E_INVALID;
  60724. + val = 0;
  60725. + }
  60726. + core_if->core_params->adp_supp_enable = val;
  60727. + /*Set OTG version 2.0 in case of enabling ADP*/
  60728. + if (val)
  60729. + dwc_otg_set_param_otg_ver(core_if, 1);
  60730. +
  60731. + return retval;
  60732. +}
  60733. +
  60734. +int32_t dwc_otg_get_param_adp_enable(dwc_otg_core_if_t * core_if)
  60735. +{
  60736. + return core_if->core_params->adp_supp_enable;
  60737. +}
  60738. +
  60739. +int dwc_otg_set_param_ic_usb_cap(dwc_otg_core_if_t * core_if, int32_t val)
  60740. +{
  60741. + int retval = 0;
  60742. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  60743. + DWC_WARN("`%d' invalid for parameter `ic_usb_cap'\n", val);
  60744. + DWC_WARN("ic_usb_cap must be 0 or 1\n");
  60745. + return -DWC_E_INVALID;
  60746. + }
  60747. +
  60748. + if (val && (core_if->hwcfg2.b.otg_enable_ic_usb == 0)) {
  60749. + if (dwc_otg_param_initialized(core_if->core_params->ic_usb_cap)) {
  60750. + DWC_ERROR
  60751. + ("%d invalid for parameter ic_usb_cap. Check HW configuration.\n",
  60752. + val);
  60753. + }
  60754. + retval = -DWC_E_INVALID;
  60755. + val = 0;
  60756. + }
  60757. + core_if->core_params->ic_usb_cap = val;
  60758. + return retval;
  60759. +}
  60760. +
  60761. +int32_t dwc_otg_get_param_ic_usb_cap(dwc_otg_core_if_t * core_if)
  60762. +{
  60763. + return core_if->core_params->ic_usb_cap;
  60764. +}
  60765. +
  60766. +int dwc_otg_set_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if, int32_t val)
  60767. +{
  60768. + int retval = 0;
  60769. + int valid = 1;
  60770. +
  60771. + if (DWC_OTG_PARAM_TEST(val, 0, 3)) {
  60772. + DWC_WARN("`%d' invalid for parameter `ahb_thr_ratio'\n", val);
  60773. + DWC_WARN("ahb_thr_ratio must be 0 - 3\n");
  60774. + return -DWC_E_INVALID;
  60775. + }
  60776. +
  60777. + if (val
  60778. + && (core_if->snpsid < OTG_CORE_REV_2_81a
  60779. + || !dwc_otg_get_param_thr_ctl(core_if))) {
  60780. + valid = 0;
  60781. + } else if (val
  60782. + && ((dwc_otg_get_param_tx_thr_length(core_if) / (1 << val)) <
  60783. + 4)) {
  60784. + valid = 0;
  60785. + }
  60786. + if (valid == 0) {
  60787. + if (dwc_otg_param_initialized
  60788. + (core_if->core_params->ahb_thr_ratio)) {
  60789. + DWC_ERROR
  60790. + ("%d invalid for parameter ahb_thr_ratio. Check HW configuration.\n",
  60791. + val);
  60792. + }
  60793. + retval = -DWC_E_INVALID;
  60794. + val = 0;
  60795. + }
  60796. +
  60797. + core_if->core_params->ahb_thr_ratio = val;
  60798. + return retval;
  60799. +}
  60800. +
  60801. +int32_t dwc_otg_get_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if)
  60802. +{
  60803. + return core_if->core_params->ahb_thr_ratio;
  60804. +}
  60805. +
  60806. +int dwc_otg_set_param_power_down(dwc_otg_core_if_t * core_if, int32_t val)
  60807. +{
  60808. + int retval = 0;
  60809. + int valid = 1;
  60810. + hwcfg4_data_t hwcfg4 = {.d32 = 0 };
  60811. + hwcfg4.d32 = DWC_READ_REG32(&core_if->core_global_regs->ghwcfg4);
  60812. +
  60813. + if (DWC_OTG_PARAM_TEST(val, 0, 3)) {
  60814. + DWC_WARN("`%d' invalid for parameter `power_down'\n", val);
  60815. + DWC_WARN("power_down must be 0 - 2\n");
  60816. + return -DWC_E_INVALID;
  60817. + }
  60818. +
  60819. + if ((val == 2) && (core_if->snpsid < OTG_CORE_REV_2_91a)) {
  60820. + valid = 0;
  60821. + }
  60822. + if ((val == 3)
  60823. + && ((core_if->snpsid < OTG_CORE_REV_3_00a)
  60824. + || (hwcfg4.b.xhiber == 0))) {
  60825. + valid = 0;
  60826. + }
  60827. + if (valid == 0) {
  60828. + if (dwc_otg_param_initialized(core_if->core_params->power_down)) {
  60829. + DWC_ERROR
  60830. + ("%d invalid for parameter power_down. Check HW configuration.\n",
  60831. + val);
  60832. + }
  60833. + retval = -DWC_E_INVALID;
  60834. + val = 0;
  60835. + }
  60836. + core_if->core_params->power_down = val;
  60837. + return retval;
  60838. +}
  60839. +
  60840. +int32_t dwc_otg_get_param_power_down(dwc_otg_core_if_t * core_if)
  60841. +{
  60842. + return core_if->core_params->power_down;
  60843. +}
  60844. +
  60845. +int dwc_otg_set_param_reload_ctl(dwc_otg_core_if_t * core_if, int32_t val)
  60846. +{
  60847. + int retval = 0;
  60848. + int valid = 1;
  60849. +
  60850. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  60851. + DWC_WARN("`%d' invalid for parameter `reload_ctl'\n", val);
  60852. + DWC_WARN("reload_ctl must be 0 or 1\n");
  60853. + return -DWC_E_INVALID;
  60854. + }
  60855. +
  60856. + if ((val == 1) && (core_if->snpsid < OTG_CORE_REV_2_92a)) {
  60857. + valid = 0;
  60858. + }
  60859. + if (valid == 0) {
  60860. + if (dwc_otg_param_initialized(core_if->core_params->reload_ctl)) {
  60861. + DWC_ERROR("%d invalid for parameter reload_ctl."
  60862. + "Check HW configuration.\n", val);
  60863. + }
  60864. + retval = -DWC_E_INVALID;
  60865. + val = 0;
  60866. + }
  60867. + core_if->core_params->reload_ctl = val;
  60868. + return retval;
  60869. +}
  60870. +
  60871. +int32_t dwc_otg_get_param_reload_ctl(dwc_otg_core_if_t * core_if)
  60872. +{
  60873. + return core_if->core_params->reload_ctl;
  60874. +}
  60875. +
  60876. +int dwc_otg_set_param_dev_out_nak(dwc_otg_core_if_t * core_if, int32_t val)
  60877. +{
  60878. + int retval = 0;
  60879. + int valid = 1;
  60880. +
  60881. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  60882. + DWC_WARN("`%d' invalid for parameter `dev_out_nak'\n", val);
  60883. + DWC_WARN("dev_out_nak must be 0 or 1\n");
  60884. + return -DWC_E_INVALID;
  60885. + }
  60886. +
  60887. + if ((val == 1) && ((core_if->snpsid < OTG_CORE_REV_2_93a) ||
  60888. + !(core_if->core_params->dma_desc_enable))) {
  60889. + valid = 0;
  60890. + }
  60891. + if (valid == 0) {
  60892. + if (dwc_otg_param_initialized(core_if->core_params->dev_out_nak)) {
  60893. + DWC_ERROR("%d invalid for parameter dev_out_nak."
  60894. + "Check HW configuration.\n", val);
  60895. + }
  60896. + retval = -DWC_E_INVALID;
  60897. + val = 0;
  60898. + }
  60899. + core_if->core_params->dev_out_nak = val;
  60900. + return retval;
  60901. +}
  60902. +
  60903. +int32_t dwc_otg_get_param_dev_out_nak(dwc_otg_core_if_t * core_if)
  60904. +{
  60905. + return core_if->core_params->dev_out_nak;
  60906. +}
  60907. +
  60908. +int dwc_otg_set_param_cont_on_bna(dwc_otg_core_if_t * core_if, int32_t val)
  60909. +{
  60910. + int retval = 0;
  60911. + int valid = 1;
  60912. +
  60913. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  60914. + DWC_WARN("`%d' invalid for parameter `cont_on_bna'\n", val);
  60915. + DWC_WARN("cont_on_bna must be 0 or 1\n");
  60916. + return -DWC_E_INVALID;
  60917. + }
  60918. +
  60919. + if ((val == 1) && ((core_if->snpsid < OTG_CORE_REV_2_94a) ||
  60920. + !(core_if->core_params->dma_desc_enable))) {
  60921. + valid = 0;
  60922. + }
  60923. + if (valid == 0) {
  60924. + if (dwc_otg_param_initialized(core_if->core_params->cont_on_bna)) {
  60925. + DWC_ERROR("%d invalid for parameter cont_on_bna."
  60926. + "Check HW configuration.\n", val);
  60927. + }
  60928. + retval = -DWC_E_INVALID;
  60929. + val = 0;
  60930. + }
  60931. + core_if->core_params->cont_on_bna = val;
  60932. + return retval;
  60933. +}
  60934. +
  60935. +int32_t dwc_otg_get_param_cont_on_bna(dwc_otg_core_if_t * core_if)
  60936. +{
  60937. + return core_if->core_params->cont_on_bna;
  60938. +}
  60939. +
  60940. +int dwc_otg_set_param_ahb_single(dwc_otg_core_if_t * core_if, int32_t val)
  60941. +{
  60942. + int retval = 0;
  60943. + int valid = 1;
  60944. +
  60945. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  60946. + DWC_WARN("`%d' invalid for parameter `ahb_single'\n", val);
  60947. + DWC_WARN("ahb_single must be 0 or 1\n");
  60948. + return -DWC_E_INVALID;
  60949. + }
  60950. +
  60951. + if ((val == 1) && (core_if->snpsid < OTG_CORE_REV_2_94a)) {
  60952. + valid = 0;
  60953. + }
  60954. + if (valid == 0) {
  60955. + if (dwc_otg_param_initialized(core_if->core_params->ahb_single)) {
  60956. + DWC_ERROR("%d invalid for parameter ahb_single."
  60957. + "Check HW configuration.\n", val);
  60958. + }
  60959. + retval = -DWC_E_INVALID;
  60960. + val = 0;
  60961. + }
  60962. + core_if->core_params->ahb_single = val;
  60963. + return retval;
  60964. +}
  60965. +
  60966. +int32_t dwc_otg_get_param_ahb_single(dwc_otg_core_if_t * core_if)
  60967. +{
  60968. + return core_if->core_params->ahb_single;
  60969. +}
  60970. +
  60971. +int dwc_otg_set_param_otg_ver(dwc_otg_core_if_t * core_if, int32_t val)
  60972. +{
  60973. + int retval = 0;
  60974. +
  60975. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  60976. + DWC_WARN("`%d' invalid for parameter `otg_ver'\n", val);
  60977. + DWC_WARN
  60978. + ("otg_ver must be 0(for OTG 1.3 support) or 1(for OTG 2.0 support)\n");
  60979. + return -DWC_E_INVALID;
  60980. + }
  60981. +
  60982. + core_if->core_params->otg_ver = val;
  60983. + return retval;
  60984. +}
  60985. +
  60986. +int32_t dwc_otg_get_param_otg_ver(dwc_otg_core_if_t * core_if)
  60987. +{
  60988. + return core_if->core_params->otg_ver;
  60989. +}
  60990. +
  60991. +uint32_t dwc_otg_get_hnpstatus(dwc_otg_core_if_t * core_if)
  60992. +{
  60993. + gotgctl_data_t otgctl;
  60994. + otgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  60995. + return otgctl.b.hstnegscs;
  60996. +}
  60997. +
  60998. +uint32_t dwc_otg_get_srpstatus(dwc_otg_core_if_t * core_if)
  60999. +{
  61000. + gotgctl_data_t otgctl;
  61001. + otgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  61002. + return otgctl.b.sesreqscs;
  61003. +}
  61004. +
  61005. +void dwc_otg_set_hnpreq(dwc_otg_core_if_t * core_if, uint32_t val)
  61006. +{
  61007. + if(core_if->otg_ver == 0) {
  61008. + gotgctl_data_t otgctl;
  61009. + otgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  61010. + otgctl.b.hnpreq = val;
  61011. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgctl, otgctl.d32);
  61012. + } else {
  61013. + core_if->otg_sts = val;
  61014. + }
  61015. +}
  61016. +
  61017. +uint32_t dwc_otg_get_gsnpsid(dwc_otg_core_if_t * core_if)
  61018. +{
  61019. + return core_if->snpsid;
  61020. +}
  61021. +
  61022. +uint32_t dwc_otg_get_mode(dwc_otg_core_if_t * core_if)
  61023. +{
  61024. + gintsts_data_t gintsts;
  61025. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  61026. + return gintsts.b.curmode;
  61027. +}
  61028. +
  61029. +uint32_t dwc_otg_get_hnpcapable(dwc_otg_core_if_t * core_if)
  61030. +{
  61031. + gusbcfg_data_t usbcfg;
  61032. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  61033. + return usbcfg.b.hnpcap;
  61034. +}
  61035. +
  61036. +void dwc_otg_set_hnpcapable(dwc_otg_core_if_t * core_if, uint32_t val)
  61037. +{
  61038. + gusbcfg_data_t usbcfg;
  61039. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  61040. + usbcfg.b.hnpcap = val;
  61041. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, usbcfg.d32);
  61042. +}
  61043. +
  61044. +uint32_t dwc_otg_get_srpcapable(dwc_otg_core_if_t * core_if)
  61045. +{
  61046. + gusbcfg_data_t usbcfg;
  61047. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  61048. + return usbcfg.b.srpcap;
  61049. +}
  61050. +
  61051. +void dwc_otg_set_srpcapable(dwc_otg_core_if_t * core_if, uint32_t val)
  61052. +{
  61053. + gusbcfg_data_t usbcfg;
  61054. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  61055. + usbcfg.b.srpcap = val;
  61056. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, usbcfg.d32);
  61057. +}
  61058. +
  61059. +uint32_t dwc_otg_get_devspeed(dwc_otg_core_if_t * core_if)
  61060. +{
  61061. + dcfg_data_t dcfg;
  61062. + /* originally: dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg); */
  61063. +
  61064. + dcfg.d32 = -1; //GRAYG
  61065. + DWC_DEBUGPL(DBG_CILV, "%s - core_if(%p)\n", __func__, core_if);
  61066. + if (NULL == core_if)
  61067. + DWC_ERROR("reg request with NULL core_if\n");
  61068. + DWC_DEBUGPL(DBG_CILV, "%s - core_if(%p)->dev_if(%p)\n", __func__,
  61069. + core_if, core_if->dev_if);
  61070. + if (NULL == core_if->dev_if)
  61071. + DWC_ERROR("reg request with NULL dev_if\n");
  61072. + DWC_DEBUGPL(DBG_CILV, "%s - core_if(%p)->dev_if(%p)->"
  61073. + "dev_global_regs(%p)\n", __func__,
  61074. + core_if, core_if->dev_if,
  61075. + core_if->dev_if->dev_global_regs);
  61076. + if (NULL == core_if->dev_if->dev_global_regs)
  61077. + DWC_ERROR("reg request with NULL dev_global_regs\n");
  61078. + else {
  61079. + DWC_DEBUGPL(DBG_CILV, "%s - &core_if(%p)->dev_if(%p)->"
  61080. + "dev_global_regs(%p)->dcfg = %p\n", __func__,
  61081. + core_if, core_if->dev_if,
  61082. + core_if->dev_if->dev_global_regs,
  61083. + &core_if->dev_if->dev_global_regs->dcfg);
  61084. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  61085. + }
  61086. + return dcfg.b.devspd;
  61087. +}
  61088. +
  61089. +void dwc_otg_set_devspeed(dwc_otg_core_if_t * core_if, uint32_t val)
  61090. +{
  61091. + dcfg_data_t dcfg;
  61092. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  61093. + dcfg.b.devspd = val;
  61094. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
  61095. +}
  61096. +
  61097. +uint32_t dwc_otg_get_busconnected(dwc_otg_core_if_t * core_if)
  61098. +{
  61099. + hprt0_data_t hprt0;
  61100. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  61101. + return hprt0.b.prtconnsts;
  61102. +}
  61103. +
  61104. +uint32_t dwc_otg_get_enumspeed(dwc_otg_core_if_t * core_if)
  61105. +{
  61106. + dsts_data_t dsts;
  61107. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  61108. + return dsts.b.enumspd;
  61109. +}
  61110. +
  61111. +uint32_t dwc_otg_get_prtpower(dwc_otg_core_if_t * core_if)
  61112. +{
  61113. + hprt0_data_t hprt0;
  61114. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  61115. + return hprt0.b.prtpwr;
  61116. +
  61117. +}
  61118. +
  61119. +uint32_t dwc_otg_get_core_state(dwc_otg_core_if_t * core_if)
  61120. +{
  61121. + return core_if->hibernation_suspend;
  61122. +}
  61123. +
  61124. +void dwc_otg_set_prtpower(dwc_otg_core_if_t * core_if, uint32_t val)
  61125. +{
  61126. + hprt0_data_t hprt0;
  61127. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  61128. + hprt0.b.prtpwr = val;
  61129. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  61130. +}
  61131. +
  61132. +uint32_t dwc_otg_get_prtsuspend(dwc_otg_core_if_t * core_if)
  61133. +{
  61134. + hprt0_data_t hprt0;
  61135. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  61136. + return hprt0.b.prtsusp;
  61137. +
  61138. +}
  61139. +
  61140. +void dwc_otg_set_prtsuspend(dwc_otg_core_if_t * core_if, uint32_t val)
  61141. +{
  61142. + hprt0_data_t hprt0;
  61143. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  61144. + hprt0.b.prtsusp = val;
  61145. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  61146. +}
  61147. +
  61148. +uint32_t dwc_otg_get_fr_interval(dwc_otg_core_if_t * core_if)
  61149. +{
  61150. + hfir_data_t hfir;
  61151. + hfir.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hfir);
  61152. + return hfir.b.frint;
  61153. +
  61154. +}
  61155. +
  61156. +void dwc_otg_set_fr_interval(dwc_otg_core_if_t * core_if, uint32_t val)
  61157. +{
  61158. + hfir_data_t hfir;
  61159. + uint32_t fram_int;
  61160. + fram_int = calc_frame_interval(core_if);
  61161. + hfir.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hfir);
  61162. + if (!core_if->core_params->reload_ctl) {
  61163. + DWC_WARN("\nCannot reload HFIR register.HFIR.HFIRRldCtrl bit is"
  61164. + "not set to 1.\nShould load driver with reload_ctl=1"
  61165. + " module parameter\n");
  61166. + return;
  61167. + }
  61168. + switch (fram_int) {
  61169. + case 3750:
  61170. + if ((val < 3350) || (val > 4150)) {
  61171. + DWC_WARN("HFIR interval for HS core and 30 MHz"
  61172. + "clock freq should be from 3350 to 4150\n");
  61173. + return;
  61174. + }
  61175. + break;
  61176. + case 30000:
  61177. + if ((val < 26820) || (val > 33180)) {
  61178. + DWC_WARN("HFIR interval for FS/LS core and 30 MHz"
  61179. + "clock freq should be from 26820 to 33180\n");
  61180. + return;
  61181. + }
  61182. + break;
  61183. + case 6000:
  61184. + if ((val < 5360) || (val > 6640)) {
  61185. + DWC_WARN("HFIR interval for HS core and 48 MHz"
  61186. + "clock freq should be from 5360 to 6640\n");
  61187. + return;
  61188. + }
  61189. + break;
  61190. + case 48000:
  61191. + if ((val < 42912) || (val > 53088)) {
  61192. + DWC_WARN("HFIR interval for FS/LS core and 48 MHz"
  61193. + "clock freq should be from 42912 to 53088\n");
  61194. + return;
  61195. + }
  61196. + break;
  61197. + case 7500:
  61198. + if ((val < 6700) || (val > 8300)) {
  61199. + DWC_WARN("HFIR interval for HS core and 60 MHz"
  61200. + "clock freq should be from 6700 to 8300\n");
  61201. + return;
  61202. + }
  61203. + break;
  61204. + case 60000:
  61205. + if ((val < 53640) || (val > 65536)) {
  61206. + DWC_WARN("HFIR interval for FS/LS core and 60 MHz"
  61207. + "clock freq should be from 53640 to 65536\n");
  61208. + return;
  61209. + }
  61210. + break;
  61211. + default:
  61212. + DWC_WARN("Unknown frame interval\n");
  61213. + return;
  61214. + break;
  61215. +
  61216. + }
  61217. + hfir.b.frint = val;
  61218. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hfir, hfir.d32);
  61219. +}
  61220. +
  61221. +uint32_t dwc_otg_get_mode_ch_tim(dwc_otg_core_if_t * core_if)
  61222. +{
  61223. + hcfg_data_t hcfg;
  61224. + hcfg.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  61225. + return hcfg.b.modechtimen;
  61226. +
  61227. +}
  61228. +
  61229. +void dwc_otg_set_mode_ch_tim(dwc_otg_core_if_t * core_if, uint32_t val)
  61230. +{
  61231. + hcfg_data_t hcfg;
  61232. + hcfg.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  61233. + hcfg.b.modechtimen = val;
  61234. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  61235. +}
  61236. +
  61237. +void dwc_otg_set_prtresume(dwc_otg_core_if_t * core_if, uint32_t val)
  61238. +{
  61239. + hprt0_data_t hprt0;
  61240. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  61241. + hprt0.b.prtres = val;
  61242. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  61243. +}
  61244. +
  61245. +uint32_t dwc_otg_get_remotewakesig(dwc_otg_core_if_t * core_if)
  61246. +{
  61247. + dctl_data_t dctl;
  61248. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  61249. + return dctl.b.rmtwkupsig;
  61250. +}
  61251. +
  61252. +uint32_t dwc_otg_get_lpm_portsleepstatus(dwc_otg_core_if_t * core_if)
  61253. +{
  61254. + glpmcfg_data_t lpmcfg;
  61255. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  61256. +
  61257. + DWC_ASSERT(!
  61258. + ((core_if->lx_state == DWC_OTG_L1) ^ lpmcfg.b.prt_sleep_sts),
  61259. + "lx_state = %d, lmpcfg.prt_sleep_sts = %d\n",
  61260. + core_if->lx_state, lpmcfg.b.prt_sleep_sts);
  61261. +
  61262. + return lpmcfg.b.prt_sleep_sts;
  61263. +}
  61264. +
  61265. +uint32_t dwc_otg_get_lpm_remotewakeenabled(dwc_otg_core_if_t * core_if)
  61266. +{
  61267. + glpmcfg_data_t lpmcfg;
  61268. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  61269. + return lpmcfg.b.rem_wkup_en;
  61270. +}
  61271. +
  61272. +uint32_t dwc_otg_get_lpmresponse(dwc_otg_core_if_t * core_if)
  61273. +{
  61274. + glpmcfg_data_t lpmcfg;
  61275. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  61276. + return lpmcfg.b.appl_resp;
  61277. +}
  61278. +
  61279. +void dwc_otg_set_lpmresponse(dwc_otg_core_if_t * core_if, uint32_t val)
  61280. +{
  61281. + glpmcfg_data_t lpmcfg;
  61282. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  61283. + lpmcfg.b.appl_resp = val;
  61284. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  61285. +}
  61286. +
  61287. +uint32_t dwc_otg_get_hsic_connect(dwc_otg_core_if_t * core_if)
  61288. +{
  61289. + glpmcfg_data_t lpmcfg;
  61290. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  61291. + return lpmcfg.b.hsic_connect;
  61292. +}
  61293. +
  61294. +void dwc_otg_set_hsic_connect(dwc_otg_core_if_t * core_if, uint32_t val)
  61295. +{
  61296. + glpmcfg_data_t lpmcfg;
  61297. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  61298. + lpmcfg.b.hsic_connect = val;
  61299. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  61300. +}
  61301. +
  61302. +uint32_t dwc_otg_get_inv_sel_hsic(dwc_otg_core_if_t * core_if)
  61303. +{
  61304. + glpmcfg_data_t lpmcfg;
  61305. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  61306. + return lpmcfg.b.inv_sel_hsic;
  61307. +
  61308. +}
  61309. +
  61310. +void dwc_otg_set_inv_sel_hsic(dwc_otg_core_if_t * core_if, uint32_t val)
  61311. +{
  61312. + glpmcfg_data_t lpmcfg;
  61313. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  61314. + lpmcfg.b.inv_sel_hsic = val;
  61315. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  61316. +}
  61317. +
  61318. +uint32_t dwc_otg_get_gotgctl(dwc_otg_core_if_t * core_if)
  61319. +{
  61320. + return DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  61321. +}
  61322. +
  61323. +void dwc_otg_set_gotgctl(dwc_otg_core_if_t * core_if, uint32_t val)
  61324. +{
  61325. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgctl, val);
  61326. +}
  61327. +
  61328. +uint32_t dwc_otg_get_gusbcfg(dwc_otg_core_if_t * core_if)
  61329. +{
  61330. + return DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  61331. +}
  61332. +
  61333. +void dwc_otg_set_gusbcfg(dwc_otg_core_if_t * core_if, uint32_t val)
  61334. +{
  61335. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, val);
  61336. +}
  61337. +
  61338. +uint32_t dwc_otg_get_grxfsiz(dwc_otg_core_if_t * core_if)
  61339. +{
  61340. + return DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  61341. +}
  61342. +
  61343. +void dwc_otg_set_grxfsiz(dwc_otg_core_if_t * core_if, uint32_t val)
  61344. +{
  61345. + DWC_WRITE_REG32(&core_if->core_global_regs->grxfsiz, val);
  61346. +}
  61347. +
  61348. +uint32_t dwc_otg_get_gnptxfsiz(dwc_otg_core_if_t * core_if)
  61349. +{
  61350. + return DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz);
  61351. +}
  61352. +
  61353. +void dwc_otg_set_gnptxfsiz(dwc_otg_core_if_t * core_if, uint32_t val)
  61354. +{
  61355. + DWC_WRITE_REG32(&core_if->core_global_regs->gnptxfsiz, val);
  61356. +}
  61357. +
  61358. +uint32_t dwc_otg_get_gpvndctl(dwc_otg_core_if_t * core_if)
  61359. +{
  61360. + return DWC_READ_REG32(&core_if->core_global_regs->gpvndctl);
  61361. +}
  61362. +
  61363. +void dwc_otg_set_gpvndctl(dwc_otg_core_if_t * core_if, uint32_t val)
  61364. +{
  61365. + DWC_WRITE_REG32(&core_if->core_global_regs->gpvndctl, val);
  61366. +}
  61367. +
  61368. +uint32_t dwc_otg_get_ggpio(dwc_otg_core_if_t * core_if)
  61369. +{
  61370. + return DWC_READ_REG32(&core_if->core_global_regs->ggpio);
  61371. +}
  61372. +
  61373. +void dwc_otg_set_ggpio(dwc_otg_core_if_t * core_if, uint32_t val)
  61374. +{
  61375. + DWC_WRITE_REG32(&core_if->core_global_regs->ggpio, val);
  61376. +}
  61377. +
  61378. +uint32_t dwc_otg_get_hprt0(dwc_otg_core_if_t * core_if)
  61379. +{
  61380. + return DWC_READ_REG32(core_if->host_if->hprt0);
  61381. +
  61382. +}
  61383. +
  61384. +void dwc_otg_set_hprt0(dwc_otg_core_if_t * core_if, uint32_t val)
  61385. +{
  61386. + DWC_WRITE_REG32(core_if->host_if->hprt0, val);
  61387. +}
  61388. +
  61389. +uint32_t dwc_otg_get_guid(dwc_otg_core_if_t * core_if)
  61390. +{
  61391. + return DWC_READ_REG32(&core_if->core_global_regs->guid);
  61392. +}
  61393. +
  61394. +void dwc_otg_set_guid(dwc_otg_core_if_t * core_if, uint32_t val)
  61395. +{
  61396. + DWC_WRITE_REG32(&core_if->core_global_regs->guid, val);
  61397. +}
  61398. +
  61399. +uint32_t dwc_otg_get_hptxfsiz(dwc_otg_core_if_t * core_if)
  61400. +{
  61401. + return DWC_READ_REG32(&core_if->core_global_regs->hptxfsiz);
  61402. +}
  61403. +
  61404. +uint16_t dwc_otg_get_otg_version(dwc_otg_core_if_t * core_if)
  61405. +{
  61406. + return ((core_if->otg_ver == 1) ? (uint16_t)0x0200 : (uint16_t)0x0103);
  61407. +}
  61408. +
  61409. +/**
  61410. + * Start the SRP timer to detect when the SRP does not complete within
  61411. + * 6 seconds.
  61412. + *
  61413. + * @param core_if the pointer to core_if strucure.
  61414. + */
  61415. +void dwc_otg_pcd_start_srp_timer(dwc_otg_core_if_t * core_if)
  61416. +{
  61417. + core_if->srp_timer_started = 1;
  61418. + DWC_TIMER_SCHEDULE(core_if->srp_timer, 6000 /* 6 secs */ );
  61419. +}
  61420. +
  61421. +void dwc_otg_initiate_srp(dwc_otg_core_if_t * core_if)
  61422. +{
  61423. + uint32_t *addr = (uint32_t *) & (core_if->core_global_regs->gotgctl);
  61424. + gotgctl_data_t mem;
  61425. + gotgctl_data_t val;
  61426. +
  61427. + val.d32 = DWC_READ_REG32(addr);
  61428. + if (val.b.sesreq) {
  61429. + DWC_ERROR("Session Request Already active!\n");
  61430. + return;
  61431. + }
  61432. +
  61433. + DWC_INFO("Session Request Initated\n"); //NOTICE
  61434. + mem.d32 = DWC_READ_REG32(addr);
  61435. + mem.b.sesreq = 1;
  61436. + DWC_WRITE_REG32(addr, mem.d32);
  61437. +
  61438. + /* Start the SRP timer */
  61439. + dwc_otg_pcd_start_srp_timer(core_if);
  61440. + return;
  61441. +}
  61442. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_cil.h linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_cil.h
  61443. --- linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_cil.h 1970-01-01 01:00:00.000000000 +0100
  61444. +++ linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_cil.h 2014-02-17 22:41:01.000000000 +0100
  61445. @@ -0,0 +1,1464 @@
  61446. +/* ==========================================================================
  61447. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil.h $
  61448. + * $Revision: #123 $
  61449. + * $Date: 2012/08/10 $
  61450. + * $Change: 2047372 $
  61451. + *
  61452. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  61453. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  61454. + * otherwise expressly agreed to in writing between Synopsys and you.
  61455. + *
  61456. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  61457. + * any End User Software License Agreement or Agreement for Licensed Product
  61458. + * with Synopsys or any supplement thereto. You are permitted to use and
  61459. + * redistribute this Software in source and binary forms, with or without
  61460. + * modification, provided that redistributions of source code must retain this
  61461. + * notice. You may not view, use, disclose, copy or distribute this file or
  61462. + * any information contained herein except pursuant to this license grant from
  61463. + * Synopsys. If you do not agree with this notice, including the disclaimer
  61464. + * below, then you are not authorized to use the Software.
  61465. + *
  61466. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  61467. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  61468. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  61469. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  61470. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  61471. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  61472. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  61473. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  61474. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  61475. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  61476. + * DAMAGE.
  61477. + * ========================================================================== */
  61478. +
  61479. +#if !defined(__DWC_CIL_H__)
  61480. +#define __DWC_CIL_H__
  61481. +
  61482. +#include "dwc_list.h"
  61483. +#include "dwc_otg_dbg.h"
  61484. +#include "dwc_otg_regs.h"
  61485. +
  61486. +#include "dwc_otg_core_if.h"
  61487. +#include "dwc_otg_adp.h"
  61488. +
  61489. +/**
  61490. + * @file
  61491. + * This file contains the interface to the Core Interface Layer.
  61492. + */
  61493. +
  61494. +#ifdef DWC_UTE_CFI
  61495. +
  61496. +#define MAX_DMA_DESCS_PER_EP 256
  61497. +
  61498. +/**
  61499. + * Enumeration for the data buffer mode
  61500. + */
  61501. +typedef enum _data_buffer_mode {
  61502. + BM_STANDARD = 0, /* data buffer is in normal mode */
  61503. + BM_SG = 1, /* data buffer uses the scatter/gather mode */
  61504. + BM_CONCAT = 2, /* data buffer uses the concatenation mode */
  61505. + BM_CIRCULAR = 3, /* data buffer uses the circular DMA mode */
  61506. + BM_ALIGN = 4 /* data buffer is in buffer alignment mode */
  61507. +} data_buffer_mode_e;
  61508. +#endif //DWC_UTE_CFI
  61509. +
  61510. +/** Macros defined for DWC OTG HW Release version */
  61511. +
  61512. +#define OTG_CORE_REV_2_60a 0x4F54260A
  61513. +#define OTG_CORE_REV_2_71a 0x4F54271A
  61514. +#define OTG_CORE_REV_2_72a 0x4F54272A
  61515. +#define OTG_CORE_REV_2_80a 0x4F54280A
  61516. +#define OTG_CORE_REV_2_81a 0x4F54281A
  61517. +#define OTG_CORE_REV_2_90a 0x4F54290A
  61518. +#define OTG_CORE_REV_2_91a 0x4F54291A
  61519. +#define OTG_CORE_REV_2_92a 0x4F54292A
  61520. +#define OTG_CORE_REV_2_93a 0x4F54293A
  61521. +#define OTG_CORE_REV_2_94a 0x4F54294A
  61522. +#define OTG_CORE_REV_3_00a 0x4F54300A
  61523. +
  61524. +/**
  61525. + * Information for each ISOC packet.
  61526. + */
  61527. +typedef struct iso_pkt_info {
  61528. + uint32_t offset;
  61529. + uint32_t length;
  61530. + int32_t status;
  61531. +} iso_pkt_info_t;
  61532. +
  61533. +/**
  61534. + * The <code>dwc_ep</code> structure represents the state of a single
  61535. + * endpoint when acting in device mode. It contains the data items
  61536. + * needed for an endpoint to be activated and transfer packets.
  61537. + */
  61538. +typedef struct dwc_ep {
  61539. + /** EP number used for register address lookup */
  61540. + uint8_t num;
  61541. + /** EP direction 0 = OUT */
  61542. + unsigned is_in:1;
  61543. + /** EP active. */
  61544. + unsigned active:1;
  61545. +
  61546. + /**
  61547. + * Periodic Tx FIFO # for IN EPs For INTR EP set to 0 to use non-periodic
  61548. + * Tx FIFO. If dedicated Tx FIFOs are enabled Tx FIFO # FOR IN EPs*/
  61549. + unsigned tx_fifo_num:4;
  61550. + /** EP type: 0 - Control, 1 - ISOC, 2 - BULK, 3 - INTR */
  61551. + unsigned type:2;
  61552. +#define DWC_OTG_EP_TYPE_CONTROL 0
  61553. +#define DWC_OTG_EP_TYPE_ISOC 1
  61554. +#define DWC_OTG_EP_TYPE_BULK 2
  61555. +#define DWC_OTG_EP_TYPE_INTR 3
  61556. +
  61557. + /** DATA start PID for INTR and BULK EP */
  61558. + unsigned data_pid_start:1;
  61559. + /** Frame (even/odd) for ISOC EP */
  61560. + unsigned even_odd_frame:1;
  61561. + /** Max Packet bytes */
  61562. + unsigned maxpacket:11;
  61563. +
  61564. + /** Max Transfer size */
  61565. + uint32_t maxxfer;
  61566. +
  61567. + /** @name Transfer state */
  61568. + /** @{ */
  61569. +
  61570. + /**
  61571. + * Pointer to the beginning of the transfer buffer -- do not modify
  61572. + * during transfer.
  61573. + */
  61574. +
  61575. + dwc_dma_t dma_addr;
  61576. +
  61577. + dwc_dma_t dma_desc_addr;
  61578. + dwc_otg_dev_dma_desc_t *desc_addr;
  61579. +
  61580. + uint8_t *start_xfer_buff;
  61581. + /** pointer to the transfer buffer */
  61582. + uint8_t *xfer_buff;
  61583. + /** Number of bytes to transfer */
  61584. + unsigned xfer_len:19;
  61585. + /** Number of bytes transferred. */
  61586. + unsigned xfer_count:19;
  61587. + /** Sent ZLP */
  61588. + unsigned sent_zlp:1;
  61589. + /** Total len for control transfer */
  61590. + unsigned total_len:19;
  61591. +
  61592. + /** stall clear flag */
  61593. + unsigned stall_clear_flag:1;
  61594. +
  61595. + /** SETUP pkt cnt rollover flag for EP0 out*/
  61596. + unsigned stp_rollover;
  61597. +
  61598. +#ifdef DWC_UTE_CFI
  61599. + /* The buffer mode */
  61600. + data_buffer_mode_e buff_mode;
  61601. +
  61602. + /* The chain of DMA descriptors.
  61603. + * MAX_DMA_DESCS_PER_EP will be allocated for each active EP.
  61604. + */
  61605. + dwc_otg_dma_desc_t *descs;
  61606. +
  61607. + /* The DMA address of the descriptors chain start */
  61608. + dma_addr_t descs_dma_addr;
  61609. + /** This variable stores the length of the last enqueued request */
  61610. + uint32_t cfi_req_len;
  61611. +#endif //DWC_UTE_CFI
  61612. +
  61613. +/** Max DMA Descriptor count for any EP */
  61614. +#define MAX_DMA_DESC_CNT 256
  61615. + /** Allocated DMA Desc count */
  61616. + uint32_t desc_cnt;
  61617. +
  61618. + /** bInterval */
  61619. + uint32_t bInterval;
  61620. + /** Next frame num to setup next ISOC transfer */
  61621. + uint32_t frame_num;
  61622. + /** Indicates SOF number overrun in DSTS */
  61623. + uint8_t frm_overrun;
  61624. +
  61625. +#ifdef DWC_UTE_PER_IO
  61626. + /** Next frame num for which will be setup DMA Desc */
  61627. + uint32_t xiso_frame_num;
  61628. + /** bInterval */
  61629. + uint32_t xiso_bInterval;
  61630. + /** Count of currently active transfers - shall be either 0 or 1 */
  61631. + int xiso_active_xfers;
  61632. + int xiso_queued_xfers;
  61633. +#endif
  61634. +#ifdef DWC_EN_ISOC
  61635. + /**
  61636. + * Variables specific for ISOC EPs
  61637. + *
  61638. + */
  61639. + /** DMA addresses of ISOC buffers */
  61640. + dwc_dma_t dma_addr0;
  61641. + dwc_dma_t dma_addr1;
  61642. +
  61643. + dwc_dma_t iso_dma_desc_addr;
  61644. + dwc_otg_dev_dma_desc_t *iso_desc_addr;
  61645. +
  61646. + /** pointer to the transfer buffers */
  61647. + uint8_t *xfer_buff0;
  61648. + uint8_t *xfer_buff1;
  61649. +
  61650. + /** number of ISOC Buffer is processing */
  61651. + uint32_t proc_buf_num;
  61652. + /** Interval of ISOC Buffer processing */
  61653. + uint32_t buf_proc_intrvl;
  61654. + /** Data size for regular frame */
  61655. + uint32_t data_per_frame;
  61656. +
  61657. + /* todo - pattern data support is to be implemented in the future */
  61658. + /** Data size for pattern frame */
  61659. + uint32_t data_pattern_frame;
  61660. + /** Frame number of pattern data */
  61661. + uint32_t sync_frame;
  61662. +
  61663. + /** bInterval */
  61664. + uint32_t bInterval;
  61665. + /** ISO Packet number per frame */
  61666. + uint32_t pkt_per_frm;
  61667. + /** Next frame num for which will be setup DMA Desc */
  61668. + uint32_t next_frame;
  61669. + /** Number of packets per buffer processing */
  61670. + uint32_t pkt_cnt;
  61671. + /** Info for all isoc packets */
  61672. + iso_pkt_info_t *pkt_info;
  61673. + /** current pkt number */
  61674. + uint32_t cur_pkt;
  61675. + /** current pkt number */
  61676. + uint8_t *cur_pkt_addr;
  61677. + /** current pkt number */
  61678. + uint32_t cur_pkt_dma_addr;
  61679. +#endif /* DWC_EN_ISOC */
  61680. +
  61681. +/** @} */
  61682. +} dwc_ep_t;
  61683. +
  61684. +/*
  61685. + * Reasons for halting a host channel.
  61686. + */
  61687. +typedef enum dwc_otg_halt_status {
  61688. + DWC_OTG_HC_XFER_NO_HALT_STATUS,
  61689. + DWC_OTG_HC_XFER_COMPLETE,
  61690. + DWC_OTG_HC_XFER_URB_COMPLETE,
  61691. + DWC_OTG_HC_XFER_ACK,
  61692. + DWC_OTG_HC_XFER_NAK,
  61693. + DWC_OTG_HC_XFER_NYET,
  61694. + DWC_OTG_HC_XFER_STALL,
  61695. + DWC_OTG_HC_XFER_XACT_ERR,
  61696. + DWC_OTG_HC_XFER_FRAME_OVERRUN,
  61697. + DWC_OTG_HC_XFER_BABBLE_ERR,
  61698. + DWC_OTG_HC_XFER_DATA_TOGGLE_ERR,
  61699. + DWC_OTG_HC_XFER_AHB_ERR,
  61700. + DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE,
  61701. + DWC_OTG_HC_XFER_URB_DEQUEUE
  61702. +} dwc_otg_halt_status_e;
  61703. +
  61704. +/**
  61705. + * Host channel descriptor. This structure represents the state of a single
  61706. + * host channel when acting in host mode. It contains the data items needed to
  61707. + * transfer packets to an endpoint via a host channel.
  61708. + */
  61709. +typedef struct dwc_hc {
  61710. + /** Host channel number used for register address lookup */
  61711. + uint8_t hc_num;
  61712. +
  61713. + /** Device to access */
  61714. + unsigned dev_addr:7;
  61715. +
  61716. + /** EP to access */
  61717. + unsigned ep_num:4;
  61718. +
  61719. + /** EP direction. 0: OUT, 1: IN */
  61720. + unsigned ep_is_in:1;
  61721. +
  61722. + /**
  61723. + * EP speed.
  61724. + * One of the following values:
  61725. + * - DWC_OTG_EP_SPEED_LOW
  61726. + * - DWC_OTG_EP_SPEED_FULL
  61727. + * - DWC_OTG_EP_SPEED_HIGH
  61728. + */
  61729. + unsigned speed:2;
  61730. +#define DWC_OTG_EP_SPEED_LOW 0
  61731. +#define DWC_OTG_EP_SPEED_FULL 1
  61732. +#define DWC_OTG_EP_SPEED_HIGH 2
  61733. +
  61734. + /**
  61735. + * Endpoint type.
  61736. + * One of the following values:
  61737. + * - DWC_OTG_EP_TYPE_CONTROL: 0
  61738. + * - DWC_OTG_EP_TYPE_ISOC: 1
  61739. + * - DWC_OTG_EP_TYPE_BULK: 2
  61740. + * - DWC_OTG_EP_TYPE_INTR: 3
  61741. + */
  61742. + unsigned ep_type:2;
  61743. +
  61744. + /** Max packet size in bytes */
  61745. + unsigned max_packet:11;
  61746. +
  61747. + /**
  61748. + * PID for initial transaction.
  61749. + * 0: DATA0,<br>
  61750. + * 1: DATA2,<br>
  61751. + * 2: DATA1,<br>
  61752. + * 3: MDATA (non-Control EP),
  61753. + * SETUP (Control EP)
  61754. + */
  61755. + unsigned data_pid_start:2;
  61756. +#define DWC_OTG_HC_PID_DATA0 0
  61757. +#define DWC_OTG_HC_PID_DATA2 1
  61758. +#define DWC_OTG_HC_PID_DATA1 2
  61759. +#define DWC_OTG_HC_PID_MDATA 3
  61760. +#define DWC_OTG_HC_PID_SETUP 3
  61761. +
  61762. + /** Number of periodic transactions per (micro)frame */
  61763. + unsigned multi_count:2;
  61764. +
  61765. + /** @name Transfer State */
  61766. + /** @{ */
  61767. +
  61768. + /** Pointer to the current transfer buffer position. */
  61769. + uint8_t *xfer_buff;
  61770. + /**
  61771. + * In Buffer DMA mode this buffer will be used
  61772. + * if xfer_buff is not DWORD aligned.
  61773. + */
  61774. + dwc_dma_t align_buff;
  61775. + /** Total number of bytes to transfer. */
  61776. + uint32_t xfer_len;
  61777. + /** Number of bytes transferred so far. */
  61778. + uint32_t xfer_count;
  61779. + /** Packet count at start of transfer.*/
  61780. + uint16_t start_pkt_count;
  61781. +
  61782. + /**
  61783. + * Flag to indicate whether the transfer has been started. Set to 1 if
  61784. + * it has been started, 0 otherwise.
  61785. + */
  61786. + uint8_t xfer_started;
  61787. +
  61788. + /**
  61789. + * Set to 1 to indicate that a PING request should be issued on this
  61790. + * channel. If 0, process normally.
  61791. + */
  61792. + uint8_t do_ping;
  61793. +
  61794. + /**
  61795. + * Set to 1 to indicate that the error count for this transaction is
  61796. + * non-zero. Set to 0 if the error count is 0.
  61797. + */
  61798. + uint8_t error_state;
  61799. +
  61800. + /**
  61801. + * Set to 1 to indicate that this channel should be halted the next
  61802. + * time a request is queued for the channel. This is necessary in
  61803. + * slave mode if no request queue space is available when an attempt
  61804. + * is made to halt the channel.
  61805. + */
  61806. + uint8_t halt_on_queue;
  61807. +
  61808. + /**
  61809. + * Set to 1 if the host channel has been halted, but the core is not
  61810. + * finished flushing queued requests. Otherwise 0.
  61811. + */
  61812. + uint8_t halt_pending;
  61813. +
  61814. + /**
  61815. + * Reason for halting the host channel.
  61816. + */
  61817. + dwc_otg_halt_status_e halt_status;
  61818. +
  61819. + /*
  61820. + * Split settings for the host channel
  61821. + */
  61822. + uint8_t do_split; /**< Enable split for the channel */
  61823. + uint8_t complete_split; /**< Enable complete split */
  61824. + uint8_t hub_addr; /**< Address of high speed hub */
  61825. +
  61826. + uint8_t port_addr; /**< Port of the low/full speed device */
  61827. + /** Split transaction position
  61828. + * One of the following values:
  61829. + * - DWC_HCSPLIT_XACTPOS_MID
  61830. + * - DWC_HCSPLIT_XACTPOS_BEGIN
  61831. + * - DWC_HCSPLIT_XACTPOS_END
  61832. + * - DWC_HCSPLIT_XACTPOS_ALL */
  61833. + uint8_t xact_pos;
  61834. +
  61835. + /** Set when the host channel does a short read. */
  61836. + uint8_t short_read;
  61837. +
  61838. + /**
  61839. + * Number of requests issued for this channel since it was assigned to
  61840. + * the current transfer (not counting PINGs).
  61841. + */
  61842. + uint8_t requests;
  61843. +
  61844. + /**
  61845. + * Queue Head for the transfer being processed by this channel.
  61846. + */
  61847. + struct dwc_otg_qh *qh;
  61848. +
  61849. + /** @} */
  61850. +
  61851. + /** Entry in list of host channels. */
  61852. + DWC_CIRCLEQ_ENTRY(dwc_hc) hc_list_entry;
  61853. +
  61854. + /** @name Descriptor DMA support */
  61855. + /** @{ */
  61856. +
  61857. + /** Number of Transfer Descriptors */
  61858. + uint16_t ntd;
  61859. +
  61860. + /** Descriptor List DMA address */
  61861. + dwc_dma_t desc_list_addr;
  61862. +
  61863. + /** Scheduling micro-frame bitmap. */
  61864. + uint8_t schinfo;
  61865. +
  61866. + /** @} */
  61867. +} dwc_hc_t;
  61868. +
  61869. +/**
  61870. + * The following parameters may be specified when starting the module. These
  61871. + * parameters define how the DWC_otg controller should be configured.
  61872. + */
  61873. +typedef struct dwc_otg_core_params {
  61874. + int32_t opt;
  61875. +
  61876. + /**
  61877. + * Specifies the OTG capabilities. The driver will automatically
  61878. + * detect the value for this parameter if none is specified.
  61879. + * 0 - HNP and SRP capable (default)
  61880. + * 1 - SRP Only capable
  61881. + * 2 - No HNP/SRP capable
  61882. + */
  61883. + int32_t otg_cap;
  61884. +
  61885. + /**
  61886. + * Specifies whether to use slave or DMA mode for accessing the data
  61887. + * FIFOs. The driver will automatically detect the value for this
  61888. + * parameter if none is specified.
  61889. + * 0 - Slave
  61890. + * 1 - DMA (default, if available)
  61891. + */
  61892. + int32_t dma_enable;
  61893. +
  61894. + /**
  61895. + * When DMA mode is enabled specifies whether to use address DMA or DMA
  61896. + * Descriptor mode for accessing the data FIFOs in device mode. The driver
  61897. + * will automatically detect the value for this if none is specified.
  61898. + * 0 - address DMA
  61899. + * 1 - DMA Descriptor(default, if available)
  61900. + */
  61901. + int32_t dma_desc_enable;
  61902. + /** The DMA Burst size (applicable only for External DMA
  61903. + * Mode). 1, 4, 8 16, 32, 64, 128, 256 (default 32)
  61904. + */
  61905. + int32_t dma_burst_size; /* Translate this to GAHBCFG values */
  61906. +
  61907. + /**
  61908. + * Specifies the maximum speed of operation in host and device mode.
  61909. + * The actual speed depends on the speed of the attached device and
  61910. + * the value of phy_type. The actual speed depends on the speed of the
  61911. + * attached device.
  61912. + * 0 - High Speed (default)
  61913. + * 1 - Full Speed
  61914. + */
  61915. + int32_t speed;
  61916. + /** Specifies whether low power mode is supported when attached
  61917. + * to a Full Speed or Low Speed device in host mode.
  61918. + * 0 - Don't support low power mode (default)
  61919. + * 1 - Support low power mode
  61920. + */
  61921. + int32_t host_support_fs_ls_low_power;
  61922. +
  61923. + /** Specifies the PHY clock rate in low power mode when connected to a
  61924. + * Low Speed device in host mode. This parameter is applicable only if
  61925. + * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
  61926. + * then defaults to 6 MHZ otherwise 48 MHZ.
  61927. + *
  61928. + * 0 - 48 MHz
  61929. + * 1 - 6 MHz
  61930. + */
  61931. + int32_t host_ls_low_power_phy_clk;
  61932. +
  61933. + /**
  61934. + * 0 - Use cC FIFO size parameters
  61935. + * 1 - Allow dynamic FIFO sizing (default)
  61936. + */
  61937. + int32_t enable_dynamic_fifo;
  61938. +
  61939. + /** Total number of 4-byte words in the data FIFO memory. This
  61940. + * memory includes the Rx FIFO, non-periodic Tx FIFO, and periodic
  61941. + * Tx FIFOs.
  61942. + * 32 to 32768 (default 8192)
  61943. + * Note: The total FIFO memory depth in the FPGA configuration is 8192.
  61944. + */
  61945. + int32_t data_fifo_size;
  61946. +
  61947. + /** Number of 4-byte words in the Rx FIFO in device mode when dynamic
  61948. + * FIFO sizing is enabled.
  61949. + * 16 to 32768 (default 1064)
  61950. + */
  61951. + int32_t dev_rx_fifo_size;
  61952. +
  61953. + /** Number of 4-byte words in the non-periodic Tx FIFO in device mode
  61954. + * when dynamic FIFO sizing is enabled.
  61955. + * 16 to 32768 (default 1024)
  61956. + */
  61957. + int32_t dev_nperio_tx_fifo_size;
  61958. +
  61959. + /** Number of 4-byte words in each of the periodic Tx FIFOs in device
  61960. + * mode when dynamic FIFO sizing is enabled.
  61961. + * 4 to 768 (default 256)
  61962. + */
  61963. + uint32_t dev_perio_tx_fifo_size[MAX_PERIO_FIFOS];
  61964. +
  61965. + /** Number of 4-byte words in the Rx FIFO in host mode when dynamic
  61966. + * FIFO sizing is enabled.
  61967. + * 16 to 32768 (default 1024)
  61968. + */
  61969. + int32_t host_rx_fifo_size;
  61970. +
  61971. + /** Number of 4-byte words in the non-periodic Tx FIFO in host mode
  61972. + * when Dynamic FIFO sizing is enabled in the core.
  61973. + * 16 to 32768 (default 1024)
  61974. + */
  61975. + int32_t host_nperio_tx_fifo_size;
  61976. +
  61977. + /** Number of 4-byte words in the host periodic Tx FIFO when dynamic
  61978. + * FIFO sizing is enabled.
  61979. + * 16 to 32768 (default 1024)
  61980. + */
  61981. + int32_t host_perio_tx_fifo_size;
  61982. +
  61983. + /** The maximum transfer size supported in bytes.
  61984. + * 2047 to 65,535 (default 65,535)
  61985. + */
  61986. + int32_t max_transfer_size;
  61987. +
  61988. + /** The maximum number of packets in a transfer.
  61989. + * 15 to 511 (default 511)
  61990. + */
  61991. + int32_t max_packet_count;
  61992. +
  61993. + /** The number of host channel registers to use.
  61994. + * 1 to 16 (default 12)
  61995. + * Note: The FPGA configuration supports a maximum of 12 host channels.
  61996. + */
  61997. + int32_t host_channels;
  61998. +
  61999. + /** The number of endpoints in addition to EP0 available for device
  62000. + * mode operations.
  62001. + * 1 to 15 (default 6 IN and OUT)
  62002. + * Note: The FPGA configuration supports a maximum of 6 IN and OUT
  62003. + * endpoints in addition to EP0.
  62004. + */
  62005. + int32_t dev_endpoints;
  62006. +
  62007. + /**
  62008. + * Specifies the type of PHY interface to use. By default, the driver
  62009. + * will automatically detect the phy_type.
  62010. + *
  62011. + * 0 - Full Speed PHY
  62012. + * 1 - UTMI+ (default)
  62013. + * 2 - ULPI
  62014. + */
  62015. + int32_t phy_type;
  62016. +
  62017. + /**
  62018. + * Specifies the UTMI+ Data Width. This parameter is
  62019. + * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
  62020. + * PHY_TYPE, this parameter indicates the data width between
  62021. + * the MAC and the ULPI Wrapper.) Also, this parameter is
  62022. + * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
  62023. + * to "8 and 16 bits", meaning that the core has been
  62024. + * configured to work at either data path width.
  62025. + *
  62026. + * 8 or 16 bits (default 16)
  62027. + */
  62028. + int32_t phy_utmi_width;
  62029. +
  62030. + /**
  62031. + * Specifies whether the ULPI operates at double or single
  62032. + * data rate. This parameter is only applicable if PHY_TYPE is
  62033. + * ULPI.
  62034. + *
  62035. + * 0 - single data rate ULPI interface with 8 bit wide data
  62036. + * bus (default)
  62037. + * 1 - double data rate ULPI interface with 4 bit wide data
  62038. + * bus
  62039. + */
  62040. + int32_t phy_ulpi_ddr;
  62041. +
  62042. + /**
  62043. + * Specifies whether to use the internal or external supply to
  62044. + * drive the vbus with a ULPI phy.
  62045. + */
  62046. + int32_t phy_ulpi_ext_vbus;
  62047. +
  62048. + /**
  62049. + * Specifies whether to use the I2Cinterface for full speed PHY. This
  62050. + * parameter is only applicable if PHY_TYPE is FS.
  62051. + * 0 - No (default)
  62052. + * 1 - Yes
  62053. + */
  62054. + int32_t i2c_enable;
  62055. +
  62056. + int32_t ulpi_fs_ls;
  62057. +
  62058. + int32_t ts_dline;
  62059. +
  62060. + /**
  62061. + * Specifies whether dedicated transmit FIFOs are
  62062. + * enabled for non periodic IN endpoints in device mode
  62063. + * 0 - No
  62064. + * 1 - Yes
  62065. + */
  62066. + int32_t en_multiple_tx_fifo;
  62067. +
  62068. + /** Number of 4-byte words in each of the Tx FIFOs in device
  62069. + * mode when dynamic FIFO sizing is enabled.
  62070. + * 4 to 768 (default 256)
  62071. + */
  62072. + uint32_t dev_tx_fifo_size[MAX_TX_FIFOS];
  62073. +
  62074. + /** Thresholding enable flag-
  62075. + * bit 0 - enable non-ISO Tx thresholding
  62076. + * bit 1 - enable ISO Tx thresholding
  62077. + * bit 2 - enable Rx thresholding
  62078. + */
  62079. + uint32_t thr_ctl;
  62080. +
  62081. + /** Thresholding length for Tx
  62082. + * FIFOs in 32 bit DWORDs
  62083. + */
  62084. + uint32_t tx_thr_length;
  62085. +
  62086. + /** Thresholding length for Rx
  62087. + * FIFOs in 32 bit DWORDs
  62088. + */
  62089. + uint32_t rx_thr_length;
  62090. +
  62091. + /**
  62092. + * Specifies whether LPM (Link Power Management) support is enabled
  62093. + */
  62094. + int32_t lpm_enable;
  62095. +
  62096. + /** Per Transfer Interrupt
  62097. + * mode enable flag
  62098. + * 1 - Enabled
  62099. + * 0 - Disabled
  62100. + */
  62101. + int32_t pti_enable;
  62102. +
  62103. + /** Multi Processor Interrupt
  62104. + * mode enable flag
  62105. + * 1 - Enabled
  62106. + * 0 - Disabled
  62107. + */
  62108. + int32_t mpi_enable;
  62109. +
  62110. + /** IS_USB Capability
  62111. + * 1 - Enabled
  62112. + * 0 - Disabled
  62113. + */
  62114. + int32_t ic_usb_cap;
  62115. +
  62116. + /** AHB Threshold Ratio
  62117. + * 2'b00 AHB Threshold = MAC Threshold
  62118. + * 2'b01 AHB Threshold = 1/2 MAC Threshold
  62119. + * 2'b10 AHB Threshold = 1/4 MAC Threshold
  62120. + * 2'b11 AHB Threshold = 1/8 MAC Threshold
  62121. + */
  62122. + int32_t ahb_thr_ratio;
  62123. +
  62124. + /** ADP Support
  62125. + * 1 - Enabled
  62126. + * 0 - Disabled
  62127. + */
  62128. + int32_t adp_supp_enable;
  62129. +
  62130. + /** HFIR Reload Control
  62131. + * 0 - The HFIR cannot be reloaded dynamically.
  62132. + * 1 - Allow dynamic reloading of the HFIR register during runtime.
  62133. + */
  62134. + int32_t reload_ctl;
  62135. +
  62136. + /** DCFG: Enable device Out NAK
  62137. + * 0 - The core does not set NAK after Bulk Out transfer complete.
  62138. + * 1 - The core sets NAK after Bulk OUT transfer complete.
  62139. + */
  62140. + int32_t dev_out_nak;
  62141. +
  62142. + /** DCFG: Enable Continue on BNA
  62143. + * After receiving BNA interrupt the core disables the endpoint,when the
  62144. + * endpoint is re-enabled by the application the core starts processing
  62145. + * 0 - from the DOEPDMA descriptor
  62146. + * 1 - from the descriptor which received the BNA.
  62147. + */
  62148. + int32_t cont_on_bna;
  62149. +
  62150. + /** GAHBCFG: AHB Single Support
  62151. + * This bit when programmed supports SINGLE transfers for remainder
  62152. + * data in a transfer for DMA mode of operation.
  62153. + * 0 - in this case the remainder data will be sent using INCR burst size.
  62154. + * 1 - in this case the remainder data will be sent using SINGLE burst size.
  62155. + */
  62156. + int32_t ahb_single;
  62157. +
  62158. + /** Core Power down mode
  62159. + * 0 - No Power Down is enabled
  62160. + * 1 - Reserved
  62161. + * 2 - Complete Power Down (Hibernation)
  62162. + */
  62163. + int32_t power_down;
  62164. +
  62165. + /** OTG revision supported
  62166. + * 0 - OTG 1.3 revision
  62167. + * 1 - OTG 2.0 revision
  62168. + */
  62169. + int32_t otg_ver;
  62170. +
  62171. +} dwc_otg_core_params_t;
  62172. +
  62173. +#ifdef DEBUG
  62174. +struct dwc_otg_core_if;
  62175. +typedef struct hc_xfer_info {
  62176. + struct dwc_otg_core_if *core_if;
  62177. + dwc_hc_t *hc;
  62178. +} hc_xfer_info_t;
  62179. +#endif
  62180. +
  62181. +typedef struct ep_xfer_info {
  62182. + struct dwc_otg_core_if *core_if;
  62183. + dwc_ep_t *ep;
  62184. + uint8_t state;
  62185. +} ep_xfer_info_t;
  62186. +/*
  62187. + * Device States
  62188. + */
  62189. +typedef enum dwc_otg_lx_state {
  62190. + /** On state */
  62191. + DWC_OTG_L0,
  62192. + /** LPM sleep state*/
  62193. + DWC_OTG_L1,
  62194. + /** USB suspend state*/
  62195. + DWC_OTG_L2,
  62196. + /** Off state*/
  62197. + DWC_OTG_L3
  62198. +} dwc_otg_lx_state_e;
  62199. +
  62200. +struct dwc_otg_global_regs_backup {
  62201. + uint32_t gotgctl_local;
  62202. + uint32_t gintmsk_local;
  62203. + uint32_t gahbcfg_local;
  62204. + uint32_t gusbcfg_local;
  62205. + uint32_t grxfsiz_local;
  62206. + uint32_t gnptxfsiz_local;
  62207. +#ifdef CONFIG_USB_DWC_OTG_LPM
  62208. + uint32_t glpmcfg_local;
  62209. +#endif
  62210. + uint32_t gi2cctl_local;
  62211. + uint32_t hptxfsiz_local;
  62212. + uint32_t pcgcctl_local;
  62213. + uint32_t gdfifocfg_local;
  62214. + uint32_t dtxfsiz_local[MAX_EPS_CHANNELS];
  62215. + uint32_t gpwrdn_local;
  62216. + uint32_t xhib_pcgcctl;
  62217. + uint32_t xhib_gpwrdn;
  62218. +};
  62219. +
  62220. +struct dwc_otg_host_regs_backup {
  62221. + uint32_t hcfg_local;
  62222. + uint32_t haintmsk_local;
  62223. + uint32_t hcintmsk_local[MAX_EPS_CHANNELS];
  62224. + uint32_t hprt0_local;
  62225. + uint32_t hfir_local;
  62226. +};
  62227. +
  62228. +struct dwc_otg_dev_regs_backup {
  62229. + uint32_t dcfg;
  62230. + uint32_t dctl;
  62231. + uint32_t daintmsk;
  62232. + uint32_t diepmsk;
  62233. + uint32_t doepmsk;
  62234. + uint32_t diepctl[MAX_EPS_CHANNELS];
  62235. + uint32_t dieptsiz[MAX_EPS_CHANNELS];
  62236. + uint32_t diepdma[MAX_EPS_CHANNELS];
  62237. +};
  62238. +/**
  62239. + * The <code>dwc_otg_core_if</code> structure contains information needed to manage
  62240. + * the DWC_otg controller acting in either host or device mode. It
  62241. + * represents the programming view of the controller as a whole.
  62242. + */
  62243. +struct dwc_otg_core_if {
  62244. + /** Parameters that define how the core should be configured.*/
  62245. + dwc_otg_core_params_t *core_params;
  62246. +
  62247. + /** Core Global registers starting at offset 000h. */
  62248. + dwc_otg_core_global_regs_t *core_global_regs;
  62249. +
  62250. + /** Device-specific information */
  62251. + dwc_otg_dev_if_t *dev_if;
  62252. + /** Host-specific information */
  62253. + dwc_otg_host_if_t *host_if;
  62254. +
  62255. + /** Value from SNPSID register */
  62256. + uint32_t snpsid;
  62257. +
  62258. + /*
  62259. + * Set to 1 if the core PHY interface bits in USBCFG have been
  62260. + * initialized.
  62261. + */
  62262. + uint8_t phy_init_done;
  62263. +
  62264. + /*
  62265. + * SRP Success flag, set by srp success interrupt in FS I2C mode
  62266. + */
  62267. + uint8_t srp_success;
  62268. + uint8_t srp_timer_started;
  62269. + /** Timer for SRP. If it expires before SRP is successful
  62270. + * clear the SRP. */
  62271. + dwc_timer_t *srp_timer;
  62272. +
  62273. +#ifdef DWC_DEV_SRPCAP
  62274. + /* This timer is needed to power on the hibernated host core if SRP is not
  62275. + * initiated on connected SRP capable device for limited period of time
  62276. + */
  62277. + uint8_t pwron_timer_started;
  62278. + dwc_timer_t *pwron_timer;
  62279. +#endif
  62280. + /* Common configuration information */
  62281. + /** Power and Clock Gating Control Register */
  62282. + volatile uint32_t *pcgcctl;
  62283. +#define DWC_OTG_PCGCCTL_OFFSET 0xE00
  62284. +
  62285. + /** Push/pop addresses for endpoints or host channels.*/
  62286. + uint32_t *data_fifo[MAX_EPS_CHANNELS];
  62287. +#define DWC_OTG_DATA_FIFO_OFFSET 0x1000
  62288. +#define DWC_OTG_DATA_FIFO_SIZE 0x1000
  62289. +
  62290. + /** Total RAM for FIFOs (Bytes) */
  62291. + uint16_t total_fifo_size;
  62292. + /** Size of Rx FIFO (Bytes) */
  62293. + uint16_t rx_fifo_size;
  62294. + /** Size of Non-periodic Tx FIFO (Bytes) */
  62295. + uint16_t nperio_tx_fifo_size;
  62296. +
  62297. + /** 1 if DMA is enabled, 0 otherwise. */
  62298. + uint8_t dma_enable;
  62299. +
  62300. + /** 1 if DMA descriptor is enabled, 0 otherwise. */
  62301. + uint8_t dma_desc_enable;
  62302. +
  62303. + /** 1 if PTI Enhancement mode is enabled, 0 otherwise. */
  62304. + uint8_t pti_enh_enable;
  62305. +
  62306. + /** 1 if MPI Enhancement mode is enabled, 0 otherwise. */
  62307. + uint8_t multiproc_int_enable;
  62308. +
  62309. + /** 1 if dedicated Tx FIFOs are enabled, 0 otherwise. */
  62310. + uint8_t en_multiple_tx_fifo;
  62311. +
  62312. + /** Set to 1 if multiple packets of a high-bandwidth transfer is in
  62313. + * process of being queued */
  62314. + uint8_t queuing_high_bandwidth;
  62315. +
  62316. + /** Hardware Configuration -- stored here for convenience.*/
  62317. + hwcfg1_data_t hwcfg1;
  62318. + hwcfg2_data_t hwcfg2;
  62319. + hwcfg3_data_t hwcfg3;
  62320. + hwcfg4_data_t hwcfg4;
  62321. + fifosize_data_t hptxfsiz;
  62322. +
  62323. + /** Host and Device Configuration -- stored here for convenience.*/
  62324. + hcfg_data_t hcfg;
  62325. + dcfg_data_t dcfg;
  62326. +
  62327. + /** The operational State, during transations
  62328. + * (a_host>>a_peripherial and b_device=>b_host) this may not
  62329. + * match the core but allows the software to determine
  62330. + * transitions.
  62331. + */
  62332. + uint8_t op_state;
  62333. +
  62334. + /**
  62335. + * Set to 1 if the HCD needs to be restarted on a session request
  62336. + * interrupt. This is required if no connector ID status change has
  62337. + * occurred since the HCD was last disconnected.
  62338. + */
  62339. + uint8_t restart_hcd_on_session_req;
  62340. +
  62341. + /** HCD callbacks */
  62342. + /** A-Device is a_host */
  62343. +#define A_HOST (1)
  62344. + /** A-Device is a_suspend */
  62345. +#define A_SUSPEND (2)
  62346. + /** A-Device is a_peripherial */
  62347. +#define A_PERIPHERAL (3)
  62348. + /** B-Device is operating as a Peripheral. */
  62349. +#define B_PERIPHERAL (4)
  62350. + /** B-Device is operating as a Host. */
  62351. +#define B_HOST (5)
  62352. +
  62353. + /** HCD callbacks */
  62354. + struct dwc_otg_cil_callbacks *hcd_cb;
  62355. + /** PCD callbacks */
  62356. + struct dwc_otg_cil_callbacks *pcd_cb;
  62357. +
  62358. + /** Device mode Periodic Tx FIFO Mask */
  62359. + uint32_t p_tx_msk;
  62360. + /** Device mode Periodic Tx FIFO Mask */
  62361. + uint32_t tx_msk;
  62362. +
  62363. + /** Workqueue object used for handling several interrupts */
  62364. + dwc_workq_t *wq_otg;
  62365. +
  62366. + /** Timer object used for handling "Wakeup Detected" Interrupt */
  62367. + dwc_timer_t *wkp_timer;
  62368. + /** This arrays used for debug purposes for DEV OUT NAK enhancement */
  62369. + uint32_t start_doeptsiz_val[MAX_EPS_CHANNELS];
  62370. + ep_xfer_info_t ep_xfer_info[MAX_EPS_CHANNELS];
  62371. + dwc_timer_t *ep_xfer_timer[MAX_EPS_CHANNELS];
  62372. +#ifdef DEBUG
  62373. + uint32_t start_hcchar_val[MAX_EPS_CHANNELS];
  62374. +
  62375. + hc_xfer_info_t hc_xfer_info[MAX_EPS_CHANNELS];
  62376. + dwc_timer_t *hc_xfer_timer[MAX_EPS_CHANNELS];
  62377. +
  62378. + uint32_t hfnum_7_samples;
  62379. + uint64_t hfnum_7_frrem_accum;
  62380. + uint32_t hfnum_0_samples;
  62381. + uint64_t hfnum_0_frrem_accum;
  62382. + uint32_t hfnum_other_samples;
  62383. + uint64_t hfnum_other_frrem_accum;
  62384. +#endif
  62385. +
  62386. +#ifdef DWC_UTE_CFI
  62387. + uint16_t pwron_rxfsiz;
  62388. + uint16_t pwron_gnptxfsiz;
  62389. + uint16_t pwron_txfsiz[15];
  62390. +
  62391. + uint16_t init_rxfsiz;
  62392. + uint16_t init_gnptxfsiz;
  62393. + uint16_t init_txfsiz[15];
  62394. +#endif
  62395. +
  62396. + /** Lx state of device */
  62397. + dwc_otg_lx_state_e lx_state;
  62398. +
  62399. + /** Saved Core Global registers */
  62400. + struct dwc_otg_global_regs_backup *gr_backup;
  62401. + /** Saved Host registers */
  62402. + struct dwc_otg_host_regs_backup *hr_backup;
  62403. + /** Saved Device registers */
  62404. + struct dwc_otg_dev_regs_backup *dr_backup;
  62405. +
  62406. + /** Power Down Enable */
  62407. + uint32_t power_down;
  62408. +
  62409. + /** ADP support Enable */
  62410. + uint32_t adp_enable;
  62411. +
  62412. + /** ADP structure object */
  62413. + dwc_otg_adp_t adp;
  62414. +
  62415. + /** hibernation/suspend flag */
  62416. + int hibernation_suspend;
  62417. +
  62418. + /** Device mode extended hibernation flag */
  62419. + int xhib;
  62420. +
  62421. + /** OTG revision supported */
  62422. + uint32_t otg_ver;
  62423. +
  62424. + /** OTG status flag used for HNP polling */
  62425. + uint8_t otg_sts;
  62426. +
  62427. + /** Pointer to either hcd->lock or pcd->lock */
  62428. + dwc_spinlock_t *lock;
  62429. +
  62430. + /** Start predict NextEP based on Learning Queue if equal 1,
  62431. + * also used as counter of disabled NP IN EP's */
  62432. + uint8_t start_predict;
  62433. +
  62434. + /** NextEp sequence, including EP0: nextep_seq[] = EP if non-periodic and
  62435. + * active, 0xff otherwise */
  62436. + uint8_t nextep_seq[MAX_EPS_CHANNELS];
  62437. +
  62438. + /** Index of fisrt EP in nextep_seq array which should be re-enabled **/
  62439. + uint8_t first_in_nextep_seq;
  62440. +
  62441. + /** Frame number while entering to ISR - needed for ISOCs **/
  62442. + uint32_t frame_num;
  62443. +
  62444. +};
  62445. +
  62446. +#ifdef DEBUG
  62447. +/*
  62448. + * This function is called when transfer is timed out.
  62449. + */
  62450. +extern void hc_xfer_timeout(void *ptr);
  62451. +#endif
  62452. +
  62453. +/*
  62454. + * This function is called when transfer is timed out on endpoint.
  62455. + */
  62456. +extern void ep_xfer_timeout(void *ptr);
  62457. +
  62458. +/*
  62459. + * The following functions are functions for works
  62460. + * using during handling some interrupts
  62461. + */
  62462. +extern void w_conn_id_status_change(void *p);
  62463. +
  62464. +extern void w_wakeup_detected(void *p);
  62465. +
  62466. +/** Saves global register values into system memory. */
  62467. +extern int dwc_otg_save_global_regs(dwc_otg_core_if_t * core_if);
  62468. +/** Saves device register values into system memory. */
  62469. +extern int dwc_otg_save_dev_regs(dwc_otg_core_if_t * core_if);
  62470. +/** Saves host register values into system memory. */
  62471. +extern int dwc_otg_save_host_regs(dwc_otg_core_if_t * core_if);
  62472. +/** Restore global register values. */
  62473. +extern int dwc_otg_restore_global_regs(dwc_otg_core_if_t * core_if);
  62474. +/** Restore host register values. */
  62475. +extern int dwc_otg_restore_host_regs(dwc_otg_core_if_t * core_if, int reset);
  62476. +/** Restore device register values. */
  62477. +extern int dwc_otg_restore_dev_regs(dwc_otg_core_if_t * core_if,
  62478. + int rem_wakeup);
  62479. +extern int restore_lpm_i2c_regs(dwc_otg_core_if_t * core_if);
  62480. +extern int restore_essential_regs(dwc_otg_core_if_t * core_if, int rmode,
  62481. + int is_host);
  62482. +
  62483. +extern int dwc_otg_host_hibernation_restore(dwc_otg_core_if_t * core_if,
  62484. + int restore_mode, int reset);
  62485. +extern int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
  62486. + int rem_wakeup, int reset);
  62487. +
  62488. +/*
  62489. + * The following functions support initialization of the CIL driver component
  62490. + * and the DWC_otg controller.
  62491. + */
  62492. +extern void dwc_otg_core_host_init(dwc_otg_core_if_t * _core_if);
  62493. +extern void dwc_otg_core_dev_init(dwc_otg_core_if_t * _core_if);
  62494. +
  62495. +/** @name Device CIL Functions
  62496. + * The following functions support managing the DWC_otg controller in device
  62497. + * mode.
  62498. + */
  62499. +/**@{*/
  62500. +extern void dwc_otg_wakeup(dwc_otg_core_if_t * _core_if);
  62501. +extern void dwc_otg_read_setup_packet(dwc_otg_core_if_t * _core_if,
  62502. + uint32_t * _dest);
  62503. +extern uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t * _core_if);
  62504. +extern void dwc_otg_ep0_activate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  62505. +extern void dwc_otg_ep_activate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  62506. +extern void dwc_otg_ep_deactivate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  62507. +extern void dwc_otg_ep_start_transfer(dwc_otg_core_if_t * _core_if,
  62508. + dwc_ep_t * _ep);
  62509. +extern void dwc_otg_ep_start_zl_transfer(dwc_otg_core_if_t * _core_if,
  62510. + dwc_ep_t * _ep);
  62511. +extern void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t * _core_if,
  62512. + dwc_ep_t * _ep);
  62513. +extern void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t * _core_if,
  62514. + dwc_ep_t * _ep);
  62515. +extern void dwc_otg_ep_write_packet(dwc_otg_core_if_t * _core_if,
  62516. + dwc_ep_t * _ep, int _dma);
  62517. +extern void dwc_otg_ep_set_stall(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  62518. +extern void dwc_otg_ep_clear_stall(dwc_otg_core_if_t * _core_if,
  62519. + dwc_ep_t * _ep);
  62520. +extern void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t * _core_if);
  62521. +
  62522. +#ifdef DWC_EN_ISOC
  62523. +extern void dwc_otg_iso_ep_start_frm_transfer(dwc_otg_core_if_t * core_if,
  62524. + dwc_ep_t * ep);
  62525. +extern void dwc_otg_iso_ep_start_buf_transfer(dwc_otg_core_if_t * core_if,
  62526. + dwc_ep_t * ep);
  62527. +#endif /* DWC_EN_ISOC */
  62528. +/**@}*/
  62529. +
  62530. +/** @name Host CIL Functions
  62531. + * The following functions support managing the DWC_otg controller in host
  62532. + * mode.
  62533. + */
  62534. +/**@{*/
  62535. +extern void dwc_otg_hc_init(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
  62536. +extern void dwc_otg_hc_halt(dwc_otg_core_if_t * _core_if,
  62537. + dwc_hc_t * _hc, dwc_otg_halt_status_e _halt_status);
  62538. +extern void dwc_otg_hc_cleanup(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
  62539. +extern void dwc_otg_hc_start_transfer(dwc_otg_core_if_t * _core_if,
  62540. + dwc_hc_t * _hc);
  62541. +extern int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t * _core_if,
  62542. + dwc_hc_t * _hc);
  62543. +extern void dwc_otg_hc_do_ping(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
  62544. +extern void dwc_otg_hc_write_packet(dwc_otg_core_if_t * _core_if,
  62545. + dwc_hc_t * _hc);
  62546. +extern void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t * _core_if);
  62547. +extern void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t * _core_if);
  62548. +
  62549. +extern void dwc_otg_hc_start_transfer_ddma(dwc_otg_core_if_t * core_if,
  62550. + dwc_hc_t * hc);
  62551. +
  62552. +extern uint32_t calc_frame_interval(dwc_otg_core_if_t * core_if);
  62553. +
  62554. +/* Macro used to clear one channel interrupt */
  62555. +#define clear_hc_int(_hc_regs_, _intr_) \
  62556. +do { \
  62557. + hcint_data_t hcint_clear = {.d32 = 0}; \
  62558. + hcint_clear.b._intr_ = 1; \
  62559. + DWC_WRITE_REG32(&(_hc_regs_)->hcint, hcint_clear.d32); \
  62560. +} while (0)
  62561. +
  62562. +/*
  62563. + * Macro used to disable one channel interrupt. Channel interrupts are
  62564. + * disabled when the channel is halted or released by the interrupt handler.
  62565. + * There is no need to handle further interrupts of that type until the
  62566. + * channel is re-assigned. In fact, subsequent handling may cause crashes
  62567. + * because the channel structures are cleaned up when the channel is released.
  62568. + */
  62569. +#define disable_hc_int(_hc_regs_, _intr_) \
  62570. +do { \
  62571. + hcintmsk_data_t hcintmsk = {.d32 = 0}; \
  62572. + hcintmsk.b._intr_ = 1; \
  62573. + DWC_MODIFY_REG32(&(_hc_regs_)->hcintmsk, hcintmsk.d32, 0); \
  62574. +} while (0)
  62575. +
  62576. +/**
  62577. + * This function Reads HPRT0 in preparation to modify. It keeps the
  62578. + * WC bits 0 so that if they are read as 1, they won't clear when you
  62579. + * write it back
  62580. + */
  62581. +static inline uint32_t dwc_otg_read_hprt0(dwc_otg_core_if_t * _core_if)
  62582. +{
  62583. + hprt0_data_t hprt0;
  62584. + hprt0.d32 = DWC_READ_REG32(_core_if->host_if->hprt0);
  62585. + hprt0.b.prtena = 0;
  62586. + hprt0.b.prtconndet = 0;
  62587. + hprt0.b.prtenchng = 0;
  62588. + hprt0.b.prtovrcurrchng = 0;
  62589. + return hprt0.d32;
  62590. +}
  62591. +
  62592. +/**@}*/
  62593. +
  62594. +/** @name Common CIL Functions
  62595. + * The following functions support managing the DWC_otg controller in either
  62596. + * device or host mode.
  62597. + */
  62598. +/**@{*/
  62599. +
  62600. +extern void dwc_otg_read_packet(dwc_otg_core_if_t * core_if,
  62601. + uint8_t * dest, uint16_t bytes);
  62602. +
  62603. +extern void dwc_otg_flush_tx_fifo(dwc_otg_core_if_t * _core_if, const int _num);
  62604. +extern void dwc_otg_flush_rx_fifo(dwc_otg_core_if_t * _core_if);
  62605. +extern void dwc_otg_core_reset(dwc_otg_core_if_t * _core_if);
  62606. +
  62607. +/**
  62608. + * This function returns the Core Interrupt register.
  62609. + */
  62610. +static inline uint32_t dwc_otg_read_core_intr(dwc_otg_core_if_t * core_if)
  62611. +{
  62612. + return (DWC_READ_REG32(&core_if->core_global_regs->gintsts) &
  62613. + DWC_READ_REG32(&core_if->core_global_regs->gintmsk));
  62614. +}
  62615. +
  62616. +/**
  62617. + * This function returns the OTG Interrupt register.
  62618. + */
  62619. +static inline uint32_t dwc_otg_read_otg_intr(dwc_otg_core_if_t * core_if)
  62620. +{
  62621. + return (DWC_READ_REG32(&core_if->core_global_regs->gotgint));
  62622. +}
  62623. +
  62624. +/**
  62625. + * This function reads the Device All Endpoints Interrupt register and
  62626. + * returns the IN endpoint interrupt bits.
  62627. + */
  62628. +static inline uint32_t dwc_otg_read_dev_all_in_ep_intr(dwc_otg_core_if_t *
  62629. + core_if)
  62630. +{
  62631. +
  62632. + uint32_t v;
  62633. +
  62634. + if (core_if->multiproc_int_enable) {
  62635. + v = DWC_READ_REG32(&core_if->dev_if->
  62636. + dev_global_regs->deachint) &
  62637. + DWC_READ_REG32(&core_if->
  62638. + dev_if->dev_global_regs->deachintmsk);
  62639. + } else {
  62640. + v = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daint) &
  62641. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
  62642. + }
  62643. + return (v & 0xffff);
  62644. +}
  62645. +
  62646. +/**
  62647. + * This function reads the Device All Endpoints Interrupt register and
  62648. + * returns the OUT endpoint interrupt bits.
  62649. + */
  62650. +static inline uint32_t dwc_otg_read_dev_all_out_ep_intr(dwc_otg_core_if_t *
  62651. + core_if)
  62652. +{
  62653. + uint32_t v;
  62654. +
  62655. + if (core_if->multiproc_int_enable) {
  62656. + v = DWC_READ_REG32(&core_if->dev_if->
  62657. + dev_global_regs->deachint) &
  62658. + DWC_READ_REG32(&core_if->
  62659. + dev_if->dev_global_regs->deachintmsk);
  62660. + } else {
  62661. + v = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daint) &
  62662. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
  62663. + }
  62664. +
  62665. + return ((v & 0xffff0000) >> 16);
  62666. +}
  62667. +
  62668. +/**
  62669. + * This function returns the Device IN EP Interrupt register
  62670. + */
  62671. +static inline uint32_t dwc_otg_read_dev_in_ep_intr(dwc_otg_core_if_t * core_if,
  62672. + dwc_ep_t * ep)
  62673. +{
  62674. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  62675. + uint32_t v, msk, emp;
  62676. +
  62677. + if (core_if->multiproc_int_enable) {
  62678. + msk =
  62679. + DWC_READ_REG32(&dev_if->
  62680. + dev_global_regs->diepeachintmsk[ep->num]);
  62681. + emp =
  62682. + DWC_READ_REG32(&dev_if->
  62683. + dev_global_regs->dtknqr4_fifoemptymsk);
  62684. + msk |= ((emp >> ep->num) & 0x1) << 7;
  62685. + v = DWC_READ_REG32(&dev_if->in_ep_regs[ep->num]->diepint) & msk;
  62686. + } else {
  62687. + msk = DWC_READ_REG32(&dev_if->dev_global_regs->diepmsk);
  62688. + emp =
  62689. + DWC_READ_REG32(&dev_if->
  62690. + dev_global_regs->dtknqr4_fifoemptymsk);
  62691. + msk |= ((emp >> ep->num) & 0x1) << 7;
  62692. + v = DWC_READ_REG32(&dev_if->in_ep_regs[ep->num]->diepint) & msk;
  62693. + }
  62694. +
  62695. + return v;
  62696. +}
  62697. +
  62698. +/**
  62699. + * This function returns the Device OUT EP Interrupt register
  62700. + */
  62701. +static inline uint32_t dwc_otg_read_dev_out_ep_intr(dwc_otg_core_if_t *
  62702. + _core_if, dwc_ep_t * _ep)
  62703. +{
  62704. + dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
  62705. + uint32_t v;
  62706. + doepmsk_data_t msk = {.d32 = 0 };
  62707. +
  62708. + if (_core_if->multiproc_int_enable) {
  62709. + msk.d32 =
  62710. + DWC_READ_REG32(&dev_if->
  62711. + dev_global_regs->doepeachintmsk[_ep->num]);
  62712. + if (_core_if->pti_enh_enable) {
  62713. + msk.b.pktdrpsts = 1;
  62714. + }
  62715. + v = DWC_READ_REG32(&dev_if->
  62716. + out_ep_regs[_ep->num]->doepint) & msk.d32;
  62717. + } else {
  62718. + msk.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->doepmsk);
  62719. + if (_core_if->pti_enh_enable) {
  62720. + msk.b.pktdrpsts = 1;
  62721. + }
  62722. + v = DWC_READ_REG32(&dev_if->
  62723. + out_ep_regs[_ep->num]->doepint) & msk.d32;
  62724. + }
  62725. + return v;
  62726. +}
  62727. +
  62728. +/**
  62729. + * This function returns the Host All Channel Interrupt register
  62730. + */
  62731. +static inline uint32_t dwc_otg_read_host_all_channels_intr(dwc_otg_core_if_t *
  62732. + _core_if)
  62733. +{
  62734. + return (DWC_READ_REG32(&_core_if->host_if->host_global_regs->haint));
  62735. +}
  62736. +
  62737. +static inline uint32_t dwc_otg_read_host_channel_intr(dwc_otg_core_if_t *
  62738. + _core_if, dwc_hc_t * _hc)
  62739. +{
  62740. + return (DWC_READ_REG32
  62741. + (&_core_if->host_if->hc_regs[_hc->hc_num]->hcint));
  62742. +}
  62743. +
  62744. +/**
  62745. + * This function returns the mode of the operation, host or device.
  62746. + *
  62747. + * @return 0 - Device Mode, 1 - Host Mode
  62748. + */
  62749. +static inline uint32_t dwc_otg_mode(dwc_otg_core_if_t * _core_if)
  62750. +{
  62751. + return (DWC_READ_REG32(&_core_if->core_global_regs->gintsts) & 0x1);
  62752. +}
  62753. +
  62754. +/**@}*/
  62755. +
  62756. +/**
  62757. + * DWC_otg CIL callback structure. This structure allows the HCD and
  62758. + * PCD to register functions used for starting and stopping the PCD
  62759. + * and HCD for role change on for a DRD.
  62760. + */
  62761. +typedef struct dwc_otg_cil_callbacks {
  62762. + /** Start function for role change */
  62763. + int (*start) (void *_p);
  62764. + /** Stop Function for role change */
  62765. + int (*stop) (void *_p);
  62766. + /** Disconnect Function for role change */
  62767. + int (*disconnect) (void *_p);
  62768. + /** Resume/Remote wakeup Function */
  62769. + int (*resume_wakeup) (void *_p);
  62770. + /** Suspend function */
  62771. + int (*suspend) (void *_p);
  62772. + /** Session Start (SRP) */
  62773. + int (*session_start) (void *_p);
  62774. +#ifdef CONFIG_USB_DWC_OTG_LPM
  62775. + /** Sleep (switch to L0 state) */
  62776. + int (*sleep) (void *_p);
  62777. +#endif
  62778. + /** Pointer passed to start() and stop() */
  62779. + void *p;
  62780. +} dwc_otg_cil_callbacks_t;
  62781. +
  62782. +extern void dwc_otg_cil_register_pcd_callbacks(dwc_otg_core_if_t * _core_if,
  62783. + dwc_otg_cil_callbacks_t * _cb,
  62784. + void *_p);
  62785. +extern void dwc_otg_cil_register_hcd_callbacks(dwc_otg_core_if_t * _core_if,
  62786. + dwc_otg_cil_callbacks_t * _cb,
  62787. + void *_p);
  62788. +
  62789. +void dwc_otg_initiate_srp(dwc_otg_core_if_t * core_if);
  62790. +
  62791. +//////////////////////////////////////////////////////////////////////
  62792. +/** Start the HCD. Helper function for using the HCD callbacks.
  62793. + *
  62794. + * @param core_if Programming view of DWC_otg controller.
  62795. + */
  62796. +static inline void cil_hcd_start(dwc_otg_core_if_t * core_if)
  62797. +{
  62798. + if (core_if->hcd_cb && core_if->hcd_cb->start) {
  62799. + core_if->hcd_cb->start(core_if->hcd_cb->p);
  62800. + }
  62801. +}
  62802. +
  62803. +/** Stop the HCD. Helper function for using the HCD callbacks.
  62804. + *
  62805. + * @param core_if Programming view of DWC_otg controller.
  62806. + */
  62807. +static inline void cil_hcd_stop(dwc_otg_core_if_t * core_if)
  62808. +{
  62809. + if (core_if->hcd_cb && core_if->hcd_cb->stop) {
  62810. + core_if->hcd_cb->stop(core_if->hcd_cb->p);
  62811. + }
  62812. +}
  62813. +
  62814. +/** Disconnect the HCD. Helper function for using the HCD callbacks.
  62815. + *
  62816. + * @param core_if Programming view of DWC_otg controller.
  62817. + */
  62818. +static inline void cil_hcd_disconnect(dwc_otg_core_if_t * core_if)
  62819. +{
  62820. + if (core_if->hcd_cb && core_if->hcd_cb->disconnect) {
  62821. + core_if->hcd_cb->disconnect(core_if->hcd_cb->p);
  62822. + }
  62823. +}
  62824. +
  62825. +/** Inform the HCD the a New Session has begun. Helper function for
  62826. + * using the HCD callbacks.
  62827. + *
  62828. + * @param core_if Programming view of DWC_otg controller.
  62829. + */
  62830. +static inline void cil_hcd_session_start(dwc_otg_core_if_t * core_if)
  62831. +{
  62832. + if (core_if->hcd_cb && core_if->hcd_cb->session_start) {
  62833. + core_if->hcd_cb->session_start(core_if->hcd_cb->p);
  62834. + }
  62835. +}
  62836. +
  62837. +#ifdef CONFIG_USB_DWC_OTG_LPM
  62838. +/**
  62839. + * Inform the HCD about LPM sleep.
  62840. + * Helper function for using the HCD callbacks.
  62841. + *
  62842. + * @param core_if Programming view of DWC_otg controller.
  62843. + */
  62844. +static inline void cil_hcd_sleep(dwc_otg_core_if_t * core_if)
  62845. +{
  62846. + if (core_if->hcd_cb && core_if->hcd_cb->sleep) {
  62847. + core_if->hcd_cb->sleep(core_if->hcd_cb->p);
  62848. + }
  62849. +}
  62850. +#endif
  62851. +
  62852. +/** Resume the HCD. Helper function for using the HCD callbacks.
  62853. + *
  62854. + * @param core_if Programming view of DWC_otg controller.
  62855. + */
  62856. +static inline void cil_hcd_resume(dwc_otg_core_if_t * core_if)
  62857. +{
  62858. + if (core_if->hcd_cb && core_if->hcd_cb->resume_wakeup) {
  62859. + core_if->hcd_cb->resume_wakeup(core_if->hcd_cb->p);
  62860. + }
  62861. +}
  62862. +
  62863. +/** Start the PCD. Helper function for using the PCD callbacks.
  62864. + *
  62865. + * @param core_if Programming view of DWC_otg controller.
  62866. + */
  62867. +static inline void cil_pcd_start(dwc_otg_core_if_t * core_if)
  62868. +{
  62869. + if (core_if->pcd_cb && core_if->pcd_cb->start) {
  62870. + core_if->pcd_cb->start(core_if->pcd_cb->p);
  62871. + }
  62872. +}
  62873. +
  62874. +/** Stop the PCD. Helper function for using the PCD callbacks.
  62875. + *
  62876. + * @param core_if Programming view of DWC_otg controller.
  62877. + */
  62878. +static inline void cil_pcd_stop(dwc_otg_core_if_t * core_if)
  62879. +{
  62880. + if (core_if->pcd_cb && core_if->pcd_cb->stop) {
  62881. + core_if->pcd_cb->stop(core_if->pcd_cb->p);
  62882. + }
  62883. +}
  62884. +
  62885. +/** Suspend the PCD. Helper function for using the PCD callbacks.
  62886. + *
  62887. + * @param core_if Programming view of DWC_otg controller.
  62888. + */
  62889. +static inline void cil_pcd_suspend(dwc_otg_core_if_t * core_if)
  62890. +{
  62891. + if (core_if->pcd_cb && core_if->pcd_cb->suspend) {
  62892. + core_if->pcd_cb->suspend(core_if->pcd_cb->p);
  62893. + }
  62894. +}
  62895. +
  62896. +/** Resume the PCD. Helper function for using the PCD callbacks.
  62897. + *
  62898. + * @param core_if Programming view of DWC_otg controller.
  62899. + */
  62900. +static inline void cil_pcd_resume(dwc_otg_core_if_t * core_if)
  62901. +{
  62902. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  62903. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  62904. + }
  62905. +}
  62906. +
  62907. +//////////////////////////////////////////////////////////////////////
  62908. +
  62909. +#endif
  62910. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c
  62911. --- linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c 1970-01-01 01:00:00.000000000 +0100
  62912. +++ linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c 2014-02-17 22:41:01.000000000 +0100
  62913. @@ -0,0 +1,1588 @@
  62914. +/* ==========================================================================
  62915. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil_intr.c $
  62916. + * $Revision: #32 $
  62917. + * $Date: 2012/08/10 $
  62918. + * $Change: 2047372 $
  62919. + *
  62920. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  62921. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  62922. + * otherwise expressly agreed to in writing between Synopsys and you.
  62923. + *
  62924. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  62925. + * any End User Software License Agreement or Agreement for Licensed Product
  62926. + * with Synopsys or any supplement thereto. You are permitted to use and
  62927. + * redistribute this Software in source and binary forms, with or without
  62928. + * modification, provided that redistributions of source code must retain this
  62929. + * notice. You may not view, use, disclose, copy or distribute this file or
  62930. + * any information contained herein except pursuant to this license grant from
  62931. + * Synopsys. If you do not agree with this notice, including the disclaimer
  62932. + * below, then you are not authorized to use the Software.
  62933. + *
  62934. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  62935. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  62936. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  62937. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  62938. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  62939. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  62940. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  62941. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  62942. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  62943. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  62944. + * DAMAGE.
  62945. + * ========================================================================== */
  62946. +
  62947. +/** @file
  62948. + *
  62949. + * The Core Interface Layer provides basic services for accessing and
  62950. + * managing the DWC_otg hardware. These services are used by both the
  62951. + * Host Controller Driver and the Peripheral Controller Driver.
  62952. + *
  62953. + * This file contains the Common Interrupt handlers.
  62954. + */
  62955. +#include "dwc_os.h"
  62956. +#include "dwc_otg_regs.h"
  62957. +#include "dwc_otg_cil.h"
  62958. +#include "dwc_otg_driver.h"
  62959. +#include "dwc_otg_pcd.h"
  62960. +#include "dwc_otg_hcd.h"
  62961. +#include "dwc_otg_mphi_fix.h"
  62962. +
  62963. +#ifdef DEBUG
  62964. +inline const char *op_state_str(dwc_otg_core_if_t * core_if)
  62965. +{
  62966. + return (core_if->op_state == A_HOST ? "a_host" :
  62967. + (core_if->op_state == A_SUSPEND ? "a_suspend" :
  62968. + (core_if->op_state == A_PERIPHERAL ? "a_peripheral" :
  62969. + (core_if->op_state == B_PERIPHERAL ? "b_peripheral" :
  62970. + (core_if->op_state == B_HOST ? "b_host" : "unknown")))));
  62971. +}
  62972. +#endif
  62973. +
  62974. +/** This function will log a debug message
  62975. + *
  62976. + * @param core_if Programming view of DWC_otg controller.
  62977. + */
  62978. +int32_t dwc_otg_handle_mode_mismatch_intr(dwc_otg_core_if_t * core_if)
  62979. +{
  62980. + gintsts_data_t gintsts;
  62981. + DWC_WARN("Mode Mismatch Interrupt: currently in %s mode\n",
  62982. + dwc_otg_mode(core_if) ? "Host" : "Device");
  62983. +
  62984. + /* Clear interrupt */
  62985. + gintsts.d32 = 0;
  62986. + gintsts.b.modemismatch = 1;
  62987. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  62988. + return 1;
  62989. +}
  62990. +
  62991. +/**
  62992. + * This function handles the OTG Interrupts. It reads the OTG
  62993. + * Interrupt Register (GOTGINT) to determine what interrupt has
  62994. + * occurred.
  62995. + *
  62996. + * @param core_if Programming view of DWC_otg controller.
  62997. + */
  62998. +int32_t dwc_otg_handle_otg_intr(dwc_otg_core_if_t * core_if)
  62999. +{
  63000. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  63001. + gotgint_data_t gotgint;
  63002. + gotgctl_data_t gotgctl;
  63003. + gintmsk_data_t gintmsk;
  63004. + gpwrdn_data_t gpwrdn;
  63005. +
  63006. + gotgint.d32 = DWC_READ_REG32(&global_regs->gotgint);
  63007. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  63008. + DWC_DEBUGPL(DBG_CIL, "++OTG Interrupt gotgint=%0x [%s]\n", gotgint.d32,
  63009. + op_state_str(core_if));
  63010. +
  63011. + if (gotgint.b.sesenddet) {
  63012. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  63013. + "Session End Detected++ (%s)\n",
  63014. + op_state_str(core_if));
  63015. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  63016. +
  63017. + if (core_if->op_state == B_HOST) {
  63018. + cil_pcd_start(core_if);
  63019. + core_if->op_state = B_PERIPHERAL;
  63020. + } else {
  63021. + /* If not B_HOST and Device HNP still set. HNP
  63022. + * Did not succeed!*/
  63023. + if (gotgctl.b.devhnpen) {
  63024. + DWC_DEBUGPL(DBG_ANY, "Session End Detected\n");
  63025. + __DWC_ERROR("Device Not Connected/Responding!\n");
  63026. + }
  63027. +
  63028. + /* If Session End Detected the B-Cable has
  63029. + * been disconnected. */
  63030. + /* Reset PCD and Gadget driver to a
  63031. + * clean state. */
  63032. + core_if->lx_state = DWC_OTG_L0;
  63033. + DWC_SPINUNLOCK(core_if->lock);
  63034. + cil_pcd_stop(core_if);
  63035. + DWC_SPINLOCK(core_if->lock);
  63036. +
  63037. + if (core_if->adp_enable) {
  63038. + if (core_if->power_down == 2) {
  63039. + gpwrdn.d32 = 0;
  63040. + gpwrdn.b.pwrdnswtch = 1;
  63041. + DWC_MODIFY_REG32(&core_if->
  63042. + core_global_regs->
  63043. + gpwrdn, gpwrdn.d32, 0);
  63044. + }
  63045. +
  63046. + gpwrdn.d32 = 0;
  63047. + gpwrdn.b.pmuintsel = 1;
  63048. + gpwrdn.b.pmuactv = 1;
  63049. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  63050. + gpwrdn, 0, gpwrdn.d32);
  63051. +
  63052. + dwc_otg_adp_sense_start(core_if);
  63053. + }
  63054. + }
  63055. +
  63056. + gotgctl.d32 = 0;
  63057. + gotgctl.b.devhnpen = 1;
  63058. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  63059. + }
  63060. + if (gotgint.b.sesreqsucstschng) {
  63061. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  63062. + "Session Reqeust Success Status Change++\n");
  63063. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  63064. + if (gotgctl.b.sesreqscs) {
  63065. +
  63066. + if ((core_if->core_params->phy_type ==
  63067. + DWC_PHY_TYPE_PARAM_FS) && (core_if->core_params->i2c_enable)) {
  63068. + core_if->srp_success = 1;
  63069. + } else {
  63070. + DWC_SPINUNLOCK(core_if->lock);
  63071. + cil_pcd_resume(core_if);
  63072. + DWC_SPINLOCK(core_if->lock);
  63073. + /* Clear Session Request */
  63074. + gotgctl.d32 = 0;
  63075. + gotgctl.b.sesreq = 1;
  63076. + DWC_MODIFY_REG32(&global_regs->gotgctl,
  63077. + gotgctl.d32, 0);
  63078. + }
  63079. + }
  63080. + }
  63081. + if (gotgint.b.hstnegsucstschng) {
  63082. + /* Print statements during the HNP interrupt handling
  63083. + * can cause it to fail.*/
  63084. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  63085. + /* WA for 3.00a- HW is not setting cur_mode, even sometimes
  63086. + * this does not help*/
  63087. + if (core_if->snpsid >= OTG_CORE_REV_3_00a)
  63088. + dwc_udelay(100);
  63089. + if (gotgctl.b.hstnegscs) {
  63090. + if (dwc_otg_is_host_mode(core_if)) {
  63091. + core_if->op_state = B_HOST;
  63092. + /*
  63093. + * Need to disable SOF interrupt immediately.
  63094. + * When switching from device to host, the PCD
  63095. + * interrupt handler won't handle the
  63096. + * interrupt if host mode is already set. The
  63097. + * HCD interrupt handler won't get called if
  63098. + * the HCD state is HALT. This means that the
  63099. + * interrupt does not get handled and Linux
  63100. + * complains loudly.
  63101. + */
  63102. + gintmsk.d32 = 0;
  63103. + gintmsk.b.sofintr = 1;
  63104. + DWC_MODIFY_REG32(&global_regs->gintmsk,
  63105. + gintmsk.d32, 0);
  63106. + /* Call callback function with spin lock released */
  63107. + DWC_SPINUNLOCK(core_if->lock);
  63108. + cil_pcd_stop(core_if);
  63109. + /*
  63110. + * Initialize the Core for Host mode.
  63111. + */
  63112. + cil_hcd_start(core_if);
  63113. + DWC_SPINLOCK(core_if->lock);
  63114. + core_if->op_state = B_HOST;
  63115. + }
  63116. + } else {
  63117. + gotgctl.d32 = 0;
  63118. + gotgctl.b.hnpreq = 1;
  63119. + gotgctl.b.devhnpen = 1;
  63120. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  63121. + DWC_DEBUGPL(DBG_ANY, "HNP Failed\n");
  63122. + __DWC_ERROR("Device Not Connected/Responding\n");
  63123. + }
  63124. + }
  63125. + if (gotgint.b.hstnegdet) {
  63126. + /* The disconnect interrupt is set at the same time as
  63127. + * Host Negotiation Detected. During the mode
  63128. + * switch all interrupts are cleared so the disconnect
  63129. + * interrupt handler will not get executed.
  63130. + */
  63131. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  63132. + "Host Negotiation Detected++ (%s)\n",
  63133. + (dwc_otg_is_host_mode(core_if) ? "Host" :
  63134. + "Device"));
  63135. + if (dwc_otg_is_device_mode(core_if)) {
  63136. + DWC_DEBUGPL(DBG_ANY, "a_suspend->a_peripheral (%d)\n",
  63137. + core_if->op_state);
  63138. + DWC_SPINUNLOCK(core_if->lock);
  63139. + cil_hcd_disconnect(core_if);
  63140. + cil_pcd_start(core_if);
  63141. + DWC_SPINLOCK(core_if->lock);
  63142. + core_if->op_state = A_PERIPHERAL;
  63143. + } else {
  63144. + /*
  63145. + * Need to disable SOF interrupt immediately. When
  63146. + * switching from device to host, the PCD interrupt
  63147. + * handler won't handle the interrupt if host mode is
  63148. + * already set. The HCD interrupt handler won't get
  63149. + * called if the HCD state is HALT. This means that
  63150. + * the interrupt does not get handled and Linux
  63151. + * complains loudly.
  63152. + */
  63153. + gintmsk.d32 = 0;
  63154. + gintmsk.b.sofintr = 1;
  63155. + DWC_MODIFY_REG32(&global_regs->gintmsk, gintmsk.d32, 0);
  63156. + DWC_SPINUNLOCK(core_if->lock);
  63157. + cil_pcd_stop(core_if);
  63158. + cil_hcd_start(core_if);
  63159. + DWC_SPINLOCK(core_if->lock);
  63160. + core_if->op_state = A_HOST;
  63161. + }
  63162. + }
  63163. + if (gotgint.b.adevtoutchng) {
  63164. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  63165. + "A-Device Timeout Change++\n");
  63166. + }
  63167. + if (gotgint.b.debdone) {
  63168. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: " "Debounce Done++\n");
  63169. + }
  63170. +
  63171. + /* Clear GOTGINT */
  63172. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgint, gotgint.d32);
  63173. +
  63174. + return 1;
  63175. +}
  63176. +
  63177. +void w_conn_id_status_change(void *p)
  63178. +{
  63179. + dwc_otg_core_if_t *core_if = p;
  63180. + uint32_t count = 0;
  63181. + gotgctl_data_t gotgctl = {.d32 = 0 };
  63182. +
  63183. + gotgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  63184. + DWC_DEBUGPL(DBG_CIL, "gotgctl=%0x\n", gotgctl.d32);
  63185. + DWC_DEBUGPL(DBG_CIL, "gotgctl.b.conidsts=%d\n", gotgctl.b.conidsts);
  63186. +
  63187. + /* B-Device connector (Device Mode) */
  63188. + if (gotgctl.b.conidsts) {
  63189. + /* Wait for switch to device mode. */
  63190. + while (!dwc_otg_is_device_mode(core_if)) {
  63191. + DWC_PRINTF("Waiting for Peripheral Mode, Mode=%s\n",
  63192. + (dwc_otg_is_host_mode(core_if) ? "Host" :
  63193. + "Peripheral"));
  63194. + dwc_mdelay(100);
  63195. + if (++count > 10000)
  63196. + break;
  63197. + }
  63198. + DWC_ASSERT(++count < 10000,
  63199. + "Connection id status change timed out");
  63200. + core_if->op_state = B_PERIPHERAL;
  63201. + dwc_otg_core_init(core_if);
  63202. + dwc_otg_enable_global_interrupts(core_if);
  63203. + cil_pcd_start(core_if);
  63204. + } else {
  63205. + /* A-Device connector (Host Mode) */
  63206. + while (!dwc_otg_is_host_mode(core_if)) {
  63207. + DWC_PRINTF("Waiting for Host Mode, Mode=%s\n",
  63208. + (dwc_otg_is_host_mode(core_if) ? "Host" :
  63209. + "Peripheral"));
  63210. + dwc_mdelay(100);
  63211. + if (++count > 10000)
  63212. + break;
  63213. + }
  63214. + DWC_ASSERT(++count < 10000,
  63215. + "Connection id status change timed out");
  63216. + core_if->op_state = A_HOST;
  63217. + /*
  63218. + * Initialize the Core for Host mode.
  63219. + */
  63220. + dwc_otg_core_init(core_if);
  63221. + dwc_otg_enable_global_interrupts(core_if);
  63222. + cil_hcd_start(core_if);
  63223. + }
  63224. +}
  63225. +
  63226. +/**
  63227. + * This function handles the Connector ID Status Change Interrupt. It
  63228. + * reads the OTG Interrupt Register (GOTCTL) to determine whether this
  63229. + * is a Device to Host Mode transition or a Host Mode to Device
  63230. + * Transition.
  63231. + *
  63232. + * This only occurs when the cable is connected/removed from the PHY
  63233. + * connector.
  63234. + *
  63235. + * @param core_if Programming view of DWC_otg controller.
  63236. + */
  63237. +int32_t dwc_otg_handle_conn_id_status_change_intr(dwc_otg_core_if_t * core_if)
  63238. +{
  63239. +
  63240. + /*
  63241. + * Need to disable SOF interrupt immediately. If switching from device
  63242. + * to host, the PCD interrupt handler won't handle the interrupt if
  63243. + * host mode is already set. The HCD interrupt handler won't get
  63244. + * called if the HCD state is HALT. This means that the interrupt does
  63245. + * not get handled and Linux complains loudly.
  63246. + */
  63247. + gintmsk_data_t gintmsk = {.d32 = 0 };
  63248. + gintsts_data_t gintsts = {.d32 = 0 };
  63249. +
  63250. + gintmsk.b.sofintr = 1;
  63251. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32, 0);
  63252. +
  63253. + DWC_DEBUGPL(DBG_CIL,
  63254. + " ++Connector ID Status Change Interrupt++ (%s)\n",
  63255. + (dwc_otg_is_host_mode(core_if) ? "Host" : "Device"));
  63256. +
  63257. + DWC_SPINUNLOCK(core_if->lock);
  63258. +
  63259. + /*
  63260. + * Need to schedule a work, as there are possible DELAY function calls
  63261. + * Release lock before scheduling workq as it holds spinlock during scheduling
  63262. + */
  63263. +
  63264. + DWC_WORKQ_SCHEDULE(core_if->wq_otg, w_conn_id_status_change,
  63265. + core_if, "connection id status change");
  63266. + DWC_SPINLOCK(core_if->lock);
  63267. +
  63268. + /* Set flag and clear interrupt */
  63269. + gintsts.b.conidstschng = 1;
  63270. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  63271. +
  63272. + return 1;
  63273. +}
  63274. +
  63275. +/**
  63276. + * This interrupt indicates that a device is initiating the Session
  63277. + * Request Protocol to request the host to turn on bus power so a new
  63278. + * session can begin. The handler responds by turning on bus power. If
  63279. + * the DWC_otg controller is in low power mode, the handler brings the
  63280. + * controller out of low power mode before turning on bus power.
  63281. + *
  63282. + * @param core_if Programming view of DWC_otg controller.
  63283. + */
  63284. +int32_t dwc_otg_handle_session_req_intr(dwc_otg_core_if_t * core_if)
  63285. +{
  63286. + gintsts_data_t gintsts;
  63287. +
  63288. +#ifndef DWC_HOST_ONLY
  63289. + DWC_DEBUGPL(DBG_ANY, "++Session Request Interrupt++\n");
  63290. +
  63291. + if (dwc_otg_is_device_mode(core_if)) {
  63292. + DWC_PRINTF("SRP: Device mode\n");
  63293. + } else {
  63294. + hprt0_data_t hprt0;
  63295. + DWC_PRINTF("SRP: Host mode\n");
  63296. +
  63297. + /* Turn on the port power bit. */
  63298. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  63299. + hprt0.b.prtpwr = 1;
  63300. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  63301. +
  63302. + /* Start the Connection timer. So a message can be displayed
  63303. + * if connect does not occur within 10 seconds. */
  63304. + cil_hcd_session_start(core_if);
  63305. + }
  63306. +#endif
  63307. +
  63308. + /* Clear interrupt */
  63309. + gintsts.d32 = 0;
  63310. + gintsts.b.sessreqintr = 1;
  63311. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  63312. +
  63313. + return 1;
  63314. +}
  63315. +
  63316. +void w_wakeup_detected(void *p)
  63317. +{
  63318. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) p;
  63319. + /*
  63320. + * Clear the Resume after 70ms. (Need 20 ms minimum. Use 70 ms
  63321. + * so that OPT tests pass with all PHYs).
  63322. + */
  63323. + hprt0_data_t hprt0 = {.d32 = 0 };
  63324. +#if 0
  63325. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  63326. + /* Restart the Phy Clock */
  63327. + pcgcctl.b.stoppclk = 1;
  63328. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  63329. + dwc_udelay(10);
  63330. +#endif //0
  63331. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  63332. + DWC_DEBUGPL(DBG_ANY, "Resume: HPRT0=%0x\n", hprt0.d32);
  63333. +// dwc_mdelay(70);
  63334. + hprt0.b.prtres = 0; /* Resume */
  63335. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  63336. + DWC_DEBUGPL(DBG_ANY, "Clear Resume: HPRT0=%0x\n",
  63337. + DWC_READ_REG32(core_if->host_if->hprt0));
  63338. +
  63339. + cil_hcd_resume(core_if);
  63340. +
  63341. + /** Change to L0 state*/
  63342. + core_if->lx_state = DWC_OTG_L0;
  63343. +}
  63344. +
  63345. +/**
  63346. + * This interrupt indicates that the DWC_otg controller has detected a
  63347. + * resume or remote wakeup sequence. If the DWC_otg controller is in
  63348. + * low power mode, the handler must brings the controller out of low
  63349. + * power mode. The controller automatically begins resume
  63350. + * signaling. The handler schedules a time to stop resume signaling.
  63351. + */
  63352. +int32_t dwc_otg_handle_wakeup_detected_intr(dwc_otg_core_if_t * core_if)
  63353. +{
  63354. + gintsts_data_t gintsts;
  63355. +
  63356. + DWC_DEBUGPL(DBG_ANY,
  63357. + "++Resume and Remote Wakeup Detected Interrupt++\n");
  63358. +
  63359. + DWC_PRINTF("%s lxstate = %d\n", __func__, core_if->lx_state);
  63360. +
  63361. + if (dwc_otg_is_device_mode(core_if)) {
  63362. + dctl_data_t dctl = {.d32 = 0 };
  63363. + DWC_DEBUGPL(DBG_PCD, "DSTS=0x%0x\n",
  63364. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->
  63365. + dsts));
  63366. + if (core_if->lx_state == DWC_OTG_L2) {
  63367. +#ifdef PARTIAL_POWER_DOWN
  63368. + if (core_if->hwcfg4.b.power_optimiz) {
  63369. + pcgcctl_data_t power = {.d32 = 0 };
  63370. +
  63371. + power.d32 = DWC_READ_REG32(core_if->pcgcctl);
  63372. + DWC_DEBUGPL(DBG_CIL, "PCGCCTL=%0x\n",
  63373. + power.d32);
  63374. +
  63375. + power.b.stoppclk = 0;
  63376. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  63377. +
  63378. + power.b.pwrclmp = 0;
  63379. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  63380. +
  63381. + power.b.rstpdwnmodule = 0;
  63382. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  63383. + }
  63384. +#endif
  63385. + /* Clear the Remote Wakeup Signaling */
  63386. + dctl.b.rmtwkupsig = 1;
  63387. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  63388. + dctl, dctl.d32, 0);
  63389. +
  63390. + DWC_SPINUNLOCK(core_if->lock);
  63391. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  63392. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  63393. + }
  63394. + DWC_SPINLOCK(core_if->lock);
  63395. + } else {
  63396. + glpmcfg_data_t lpmcfg;
  63397. + lpmcfg.d32 =
  63398. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  63399. + lpmcfg.b.hird_thres &= (~(1 << 4));
  63400. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg,
  63401. + lpmcfg.d32);
  63402. + }
  63403. + /** Change to L0 state*/
  63404. + core_if->lx_state = DWC_OTG_L0;
  63405. + } else {
  63406. + if (core_if->lx_state != DWC_OTG_L1) {
  63407. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  63408. +
  63409. + /* Restart the Phy Clock */
  63410. + pcgcctl.b.stoppclk = 1;
  63411. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  63412. + DWC_TIMER_SCHEDULE(core_if->wkp_timer, 71);
  63413. + } else {
  63414. + /** Change to L0 state*/
  63415. + core_if->lx_state = DWC_OTG_L0;
  63416. + }
  63417. + }
  63418. +
  63419. + /* Clear interrupt */
  63420. + gintsts.d32 = 0;
  63421. + gintsts.b.wkupintr = 1;
  63422. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  63423. +
  63424. + return 1;
  63425. +}
  63426. +
  63427. +/**
  63428. + * This interrupt indicates that the Wakeup Logic has detected a
  63429. + * Device disconnect.
  63430. + */
  63431. +static int32_t dwc_otg_handle_pwrdn_disconnect_intr(dwc_otg_core_if_t *core_if)
  63432. +{
  63433. + gpwrdn_data_t gpwrdn = { .d32 = 0 };
  63434. + gpwrdn_data_t gpwrdn_temp = { .d32 = 0 };
  63435. + gpwrdn_temp.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  63436. +
  63437. + DWC_PRINTF("%s called\n", __FUNCTION__);
  63438. +
  63439. + if (!core_if->hibernation_suspend) {
  63440. + DWC_PRINTF("Already exited from Hibernation\n");
  63441. + return 1;
  63442. + }
  63443. +
  63444. + /* Switch on the voltage to the core */
  63445. + gpwrdn.b.pwrdnswtch = 1;
  63446. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  63447. + dwc_udelay(10);
  63448. +
  63449. + /* Reset the core */
  63450. + gpwrdn.d32 = 0;
  63451. + gpwrdn.b.pwrdnrstn = 1;
  63452. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  63453. + dwc_udelay(10);
  63454. +
  63455. + /* Disable power clamps*/
  63456. + gpwrdn.d32 = 0;
  63457. + gpwrdn.b.pwrdnclmp = 1;
  63458. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  63459. +
  63460. + /* Remove reset the core signal */
  63461. + gpwrdn.d32 = 0;
  63462. + gpwrdn.b.pwrdnrstn = 1;
  63463. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  63464. + dwc_udelay(10);
  63465. +
  63466. + /* Disable PMU interrupt */
  63467. + gpwrdn.d32 = 0;
  63468. + gpwrdn.b.pmuintsel = 1;
  63469. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  63470. +
  63471. + core_if->hibernation_suspend = 0;
  63472. +
  63473. + /* Disable PMU */
  63474. + gpwrdn.d32 = 0;
  63475. + gpwrdn.b.pmuactv = 1;
  63476. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  63477. + dwc_udelay(10);
  63478. +
  63479. + if (gpwrdn_temp.b.idsts) {
  63480. + core_if->op_state = B_PERIPHERAL;
  63481. + dwc_otg_core_init(core_if);
  63482. + dwc_otg_enable_global_interrupts(core_if);
  63483. + cil_pcd_start(core_if);
  63484. + } else {
  63485. + core_if->op_state = A_HOST;
  63486. + dwc_otg_core_init(core_if);
  63487. + dwc_otg_enable_global_interrupts(core_if);
  63488. + cil_hcd_start(core_if);
  63489. + }
  63490. +
  63491. + return 1;
  63492. +}
  63493. +
  63494. +/**
  63495. + * This interrupt indicates that the Wakeup Logic has detected a
  63496. + * remote wakeup sequence.
  63497. + */
  63498. +static int32_t dwc_otg_handle_pwrdn_wakeup_detected_intr(dwc_otg_core_if_t * core_if)
  63499. +{
  63500. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  63501. + DWC_DEBUGPL(DBG_ANY,
  63502. + "++Powerdown Remote Wakeup Detected Interrupt++\n");
  63503. +
  63504. + if (!core_if->hibernation_suspend) {
  63505. + DWC_PRINTF("Already exited from Hibernation\n");
  63506. + return 1;
  63507. + }
  63508. +
  63509. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  63510. + if (gpwrdn.b.idsts) { // Device Mode
  63511. + if ((core_if->power_down == 2)
  63512. + && (core_if->hibernation_suspend == 1)) {
  63513. + dwc_otg_device_hibernation_restore(core_if, 0, 0);
  63514. + }
  63515. + } else {
  63516. + if ((core_if->power_down == 2)
  63517. + && (core_if->hibernation_suspend == 1)) {
  63518. + dwc_otg_host_hibernation_restore(core_if, 1, 0);
  63519. + }
  63520. + }
  63521. + return 1;
  63522. +}
  63523. +
  63524. +static int32_t dwc_otg_handle_pwrdn_idsts_change(dwc_otg_device_t *otg_dev)
  63525. +{
  63526. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  63527. + gpwrdn_data_t gpwrdn_temp = {.d32 = 0 };
  63528. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  63529. +
  63530. + DWC_DEBUGPL(DBG_ANY, "%s called\n", __FUNCTION__);
  63531. + gpwrdn_temp.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  63532. + if (core_if->power_down == 2) {
  63533. + if (!core_if->hibernation_suspend) {
  63534. + DWC_PRINTF("Already exited from Hibernation\n");
  63535. + return 1;
  63536. + }
  63537. + DWC_DEBUGPL(DBG_ANY, "Exit from hibernation on ID sts change\n");
  63538. + /* Switch on the voltage to the core */
  63539. + gpwrdn.b.pwrdnswtch = 1;
  63540. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  63541. + dwc_udelay(10);
  63542. +
  63543. + /* Reset the core */
  63544. + gpwrdn.d32 = 0;
  63545. + gpwrdn.b.pwrdnrstn = 1;
  63546. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  63547. + dwc_udelay(10);
  63548. +
  63549. + /* Disable power clamps */
  63550. + gpwrdn.d32 = 0;
  63551. + gpwrdn.b.pwrdnclmp = 1;
  63552. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  63553. +
  63554. + /* Remove reset the core signal */
  63555. + gpwrdn.d32 = 0;
  63556. + gpwrdn.b.pwrdnrstn = 1;
  63557. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  63558. + dwc_udelay(10);
  63559. +
  63560. + /* Disable PMU interrupt */
  63561. + gpwrdn.d32 = 0;
  63562. + gpwrdn.b.pmuintsel = 1;
  63563. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  63564. +
  63565. + /*Indicates that we are exiting from hibernation */
  63566. + core_if->hibernation_suspend = 0;
  63567. +
  63568. + /* Disable PMU */
  63569. + gpwrdn.d32 = 0;
  63570. + gpwrdn.b.pmuactv = 1;
  63571. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  63572. + dwc_udelay(10);
  63573. +
  63574. + gpwrdn.d32 = core_if->gr_backup->gpwrdn_local;
  63575. + if (gpwrdn.b.dis_vbus == 1) {
  63576. + gpwrdn.d32 = 0;
  63577. + gpwrdn.b.dis_vbus = 1;
  63578. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  63579. + }
  63580. +
  63581. + if (gpwrdn_temp.b.idsts) {
  63582. + core_if->op_state = B_PERIPHERAL;
  63583. + dwc_otg_core_init(core_if);
  63584. + dwc_otg_enable_global_interrupts(core_if);
  63585. + cil_pcd_start(core_if);
  63586. + } else {
  63587. + core_if->op_state = A_HOST;
  63588. + dwc_otg_core_init(core_if);
  63589. + dwc_otg_enable_global_interrupts(core_if);
  63590. + cil_hcd_start(core_if);
  63591. + }
  63592. + }
  63593. +
  63594. + if (core_if->adp_enable) {
  63595. + uint8_t is_host = 0;
  63596. + DWC_SPINUNLOCK(core_if->lock);
  63597. + /* Change the core_if's lock to hcd/pcd lock depend on mode? */
  63598. +#ifndef DWC_HOST_ONLY
  63599. + if (gpwrdn_temp.b.idsts)
  63600. + core_if->lock = otg_dev->pcd->lock;
  63601. +#endif
  63602. +#ifndef DWC_DEVICE_ONLY
  63603. + if (!gpwrdn_temp.b.idsts) {
  63604. + core_if->lock = otg_dev->hcd->lock;
  63605. + is_host = 1;
  63606. + }
  63607. +#endif
  63608. + DWC_PRINTF("RESTART ADP\n");
  63609. + if (core_if->adp.probe_enabled)
  63610. + dwc_otg_adp_probe_stop(core_if);
  63611. + if (core_if->adp.sense_enabled)
  63612. + dwc_otg_adp_sense_stop(core_if);
  63613. + if (core_if->adp.sense_timer_started)
  63614. + DWC_TIMER_CANCEL(core_if->adp.sense_timer);
  63615. + if (core_if->adp.vbuson_timer_started)
  63616. + DWC_TIMER_CANCEL(core_if->adp.vbuson_timer);
  63617. + core_if->adp.probe_timer_values[0] = -1;
  63618. + core_if->adp.probe_timer_values[1] = -1;
  63619. + core_if->adp.sense_timer_started = 0;
  63620. + core_if->adp.vbuson_timer_started = 0;
  63621. + core_if->adp.probe_counter = 0;
  63622. + core_if->adp.gpwrdn = 0;
  63623. +
  63624. + /* Disable PMU and restart ADP */
  63625. + gpwrdn_temp.d32 = 0;
  63626. + gpwrdn_temp.b.pmuactv = 1;
  63627. + gpwrdn_temp.b.pmuintsel = 1;
  63628. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  63629. + DWC_PRINTF("Check point 1\n");
  63630. + dwc_mdelay(110);
  63631. + dwc_otg_adp_start(core_if, is_host);
  63632. + DWC_SPINLOCK(core_if->lock);
  63633. + }
  63634. +
  63635. +
  63636. + return 1;
  63637. +}
  63638. +
  63639. +static int32_t dwc_otg_handle_pwrdn_session_change(dwc_otg_core_if_t * core_if)
  63640. +{
  63641. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  63642. + int32_t otg_cap_param = core_if->core_params->otg_cap;
  63643. + DWC_DEBUGPL(DBG_ANY, "%s called\n", __FUNCTION__);
  63644. +
  63645. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  63646. + if (core_if->power_down == 2) {
  63647. + if (!core_if->hibernation_suspend) {
  63648. + DWC_PRINTF("Already exited from Hibernation\n");
  63649. + return 1;
  63650. + }
  63651. +
  63652. + if ((otg_cap_param != DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE ||
  63653. + otg_cap_param != DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE) &&
  63654. + gpwrdn.b.bsessvld == 0) {
  63655. + /* Save gpwrdn register for further usage if stschng interrupt */
  63656. + core_if->gr_backup->gpwrdn_local =
  63657. + DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  63658. + /*Exit from ISR and wait for stschng interrupt with bsessvld = 1 */
  63659. + return 1;
  63660. + }
  63661. +
  63662. + /* Switch on the voltage to the core */
  63663. + gpwrdn.d32 = 0;
  63664. + gpwrdn.b.pwrdnswtch = 1;
  63665. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  63666. + dwc_udelay(10);
  63667. +
  63668. + /* Reset the core */
  63669. + gpwrdn.d32 = 0;
  63670. + gpwrdn.b.pwrdnrstn = 1;
  63671. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  63672. + dwc_udelay(10);
  63673. +
  63674. + /* Disable power clamps */
  63675. + gpwrdn.d32 = 0;
  63676. + gpwrdn.b.pwrdnclmp = 1;
  63677. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  63678. +
  63679. + /* Remove reset the core signal */
  63680. + gpwrdn.d32 = 0;
  63681. + gpwrdn.b.pwrdnrstn = 1;
  63682. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  63683. + dwc_udelay(10);
  63684. +
  63685. + /* Disable PMU interrupt */
  63686. + gpwrdn.d32 = 0;
  63687. + gpwrdn.b.pmuintsel = 1;
  63688. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  63689. + dwc_udelay(10);
  63690. +
  63691. + /*Indicates that we are exiting from hibernation */
  63692. + core_if->hibernation_suspend = 0;
  63693. +
  63694. + /* Disable PMU */
  63695. + gpwrdn.d32 = 0;
  63696. + gpwrdn.b.pmuactv = 1;
  63697. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  63698. + dwc_udelay(10);
  63699. +
  63700. + core_if->op_state = B_PERIPHERAL;
  63701. + dwc_otg_core_init(core_if);
  63702. + dwc_otg_enable_global_interrupts(core_if);
  63703. + cil_pcd_start(core_if);
  63704. +
  63705. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE ||
  63706. + otg_cap_param == DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE) {
  63707. + /*
  63708. + * Initiate SRP after initial ADP probe.
  63709. + */
  63710. + dwc_otg_initiate_srp(core_if);
  63711. + }
  63712. + }
  63713. +
  63714. + return 1;
  63715. +}
  63716. +/**
  63717. + * This interrupt indicates that the Wakeup Logic has detected a
  63718. + * status change either on IDDIG or BSessVld.
  63719. + */
  63720. +static uint32_t dwc_otg_handle_pwrdn_stschng_intr(dwc_otg_device_t *otg_dev)
  63721. +{
  63722. + int retval;
  63723. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  63724. + gpwrdn_data_t gpwrdn_temp = {.d32 = 0 };
  63725. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  63726. +
  63727. + DWC_PRINTF("%s called\n", __FUNCTION__);
  63728. +
  63729. + if (core_if->power_down == 2) {
  63730. + if (core_if->hibernation_suspend <= 0) {
  63731. + DWC_PRINTF("Already exited from Hibernation\n");
  63732. + return 1;
  63733. + } else
  63734. + gpwrdn_temp.d32 = core_if->gr_backup->gpwrdn_local;
  63735. +
  63736. + } else {
  63737. + gpwrdn_temp.d32 = core_if->adp.gpwrdn;
  63738. + }
  63739. +
  63740. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  63741. +
  63742. + if (gpwrdn.b.idsts ^ gpwrdn_temp.b.idsts) {
  63743. + retval = dwc_otg_handle_pwrdn_idsts_change(otg_dev);
  63744. + } else if (gpwrdn.b.bsessvld ^ gpwrdn_temp.b.bsessvld) {
  63745. + retval = dwc_otg_handle_pwrdn_session_change(core_if);
  63746. + }
  63747. +
  63748. + return retval;
  63749. +}
  63750. +
  63751. +/**
  63752. + * This interrupt indicates that the Wakeup Logic has detected a
  63753. + * SRP.
  63754. + */
  63755. +static int32_t dwc_otg_handle_pwrdn_srp_intr(dwc_otg_core_if_t * core_if)
  63756. +{
  63757. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  63758. +
  63759. + DWC_PRINTF("%s called\n", __FUNCTION__);
  63760. +
  63761. + if (!core_if->hibernation_suspend) {
  63762. + DWC_PRINTF("Already exited from Hibernation\n");
  63763. + return 1;
  63764. + }
  63765. +#ifdef DWC_DEV_SRPCAP
  63766. + if (core_if->pwron_timer_started) {
  63767. + core_if->pwron_timer_started = 0;
  63768. + DWC_TIMER_CANCEL(core_if->pwron_timer);
  63769. + }
  63770. +#endif
  63771. +
  63772. + /* Switch on the voltage to the core */
  63773. + gpwrdn.b.pwrdnswtch = 1;
  63774. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  63775. + dwc_udelay(10);
  63776. +
  63777. + /* Reset the core */
  63778. + gpwrdn.d32 = 0;
  63779. + gpwrdn.b.pwrdnrstn = 1;
  63780. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  63781. + dwc_udelay(10);
  63782. +
  63783. + /* Disable power clamps */
  63784. + gpwrdn.d32 = 0;
  63785. + gpwrdn.b.pwrdnclmp = 1;
  63786. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  63787. +
  63788. + /* Remove reset the core signal */
  63789. + gpwrdn.d32 = 0;
  63790. + gpwrdn.b.pwrdnrstn = 1;
  63791. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  63792. + dwc_udelay(10);
  63793. +
  63794. + /* Disable PMU interrupt */
  63795. + gpwrdn.d32 = 0;
  63796. + gpwrdn.b.pmuintsel = 1;
  63797. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  63798. +
  63799. + /* Indicates that we are exiting from hibernation */
  63800. + core_if->hibernation_suspend = 0;
  63801. +
  63802. + /* Disable PMU */
  63803. + gpwrdn.d32 = 0;
  63804. + gpwrdn.b.pmuactv = 1;
  63805. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  63806. + dwc_udelay(10);
  63807. +
  63808. + /* Programm Disable VBUS to 0 */
  63809. + gpwrdn.d32 = 0;
  63810. + gpwrdn.b.dis_vbus = 1;
  63811. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  63812. +
  63813. + /*Initialize the core as Host */
  63814. + core_if->op_state = A_HOST;
  63815. + dwc_otg_core_init(core_if);
  63816. + dwc_otg_enable_global_interrupts(core_if);
  63817. + cil_hcd_start(core_if);
  63818. +
  63819. + return 1;
  63820. +}
  63821. +
  63822. +/** This interrupt indicates that restore command after Hibernation
  63823. + * was completed by the core. */
  63824. +int32_t dwc_otg_handle_restore_done_intr(dwc_otg_core_if_t * core_if)
  63825. +{
  63826. + pcgcctl_data_t pcgcctl;
  63827. + DWC_DEBUGPL(DBG_ANY, "++Restore Done Interrupt++\n");
  63828. +
  63829. + //TODO De-assert restore signal. 8.a
  63830. + pcgcctl.d32 = DWC_READ_REG32(core_if->pcgcctl);
  63831. + if (pcgcctl.b.restoremode == 1) {
  63832. + gintmsk_data_t gintmsk = {.d32 = 0 };
  63833. + /*
  63834. + * If restore mode is Remote Wakeup,
  63835. + * unmask Remote Wakeup interrupt.
  63836. + */
  63837. + gintmsk.b.wkupintr = 1;
  63838. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  63839. + 0, gintmsk.d32);
  63840. + }
  63841. +
  63842. + return 1;
  63843. +}
  63844. +
  63845. +/**
  63846. + * This interrupt indicates that a device has been disconnected from
  63847. + * the root port.
  63848. + */
  63849. +int32_t dwc_otg_handle_disconnect_intr(dwc_otg_core_if_t * core_if)
  63850. +{
  63851. + gintsts_data_t gintsts;
  63852. +
  63853. + DWC_DEBUGPL(DBG_ANY, "++Disconnect Detected Interrupt++ (%s) %s\n",
  63854. + (dwc_otg_is_host_mode(core_if) ? "Host" : "Device"),
  63855. + op_state_str(core_if));
  63856. +
  63857. +/** @todo Consolidate this if statement. */
  63858. +#ifndef DWC_HOST_ONLY
  63859. + if (core_if->op_state == B_HOST) {
  63860. + /* If in device mode Disconnect and stop the HCD, then
  63861. + * start the PCD. */
  63862. + DWC_SPINUNLOCK(core_if->lock);
  63863. + cil_hcd_disconnect(core_if);
  63864. + cil_pcd_start(core_if);
  63865. + DWC_SPINLOCK(core_if->lock);
  63866. + core_if->op_state = B_PERIPHERAL;
  63867. + } else if (dwc_otg_is_device_mode(core_if)) {
  63868. + gotgctl_data_t gotgctl = {.d32 = 0 };
  63869. + gotgctl.d32 =
  63870. + DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  63871. + if (gotgctl.b.hstsethnpen == 1) {
  63872. + /* Do nothing, if HNP in process the OTG
  63873. + * interrupt "Host Negotiation Detected"
  63874. + * interrupt will do the mode switch.
  63875. + */
  63876. + } else if (gotgctl.b.devhnpen == 0) {
  63877. + /* If in device mode Disconnect and stop the HCD, then
  63878. + * start the PCD. */
  63879. + DWC_SPINUNLOCK(core_if->lock);
  63880. + cil_hcd_disconnect(core_if);
  63881. + cil_pcd_start(core_if);
  63882. + DWC_SPINLOCK(core_if->lock);
  63883. + core_if->op_state = B_PERIPHERAL;
  63884. + } else {
  63885. + DWC_DEBUGPL(DBG_ANY, "!a_peripheral && !devhnpen\n");
  63886. + }
  63887. + } else {
  63888. + if (core_if->op_state == A_HOST) {
  63889. + /* A-Cable still connected but device disconnected. */
  63890. + cil_hcd_disconnect(core_if);
  63891. + if (core_if->adp_enable) {
  63892. + gpwrdn_data_t gpwrdn = { .d32 = 0 };
  63893. + cil_hcd_stop(core_if);
  63894. + /* Enable Power Down Logic */
  63895. + gpwrdn.b.pmuintsel = 1;
  63896. + gpwrdn.b.pmuactv = 1;
  63897. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  63898. + gpwrdn, 0, gpwrdn.d32);
  63899. + dwc_otg_adp_probe_start(core_if);
  63900. +
  63901. + /* Power off the core */
  63902. + if (core_if->power_down == 2) {
  63903. + gpwrdn.d32 = 0;
  63904. + gpwrdn.b.pwrdnswtch = 1;
  63905. + DWC_MODIFY_REG32
  63906. + (&core_if->core_global_regs->gpwrdn,
  63907. + gpwrdn.d32, 0);
  63908. + }
  63909. + }
  63910. + }
  63911. + }
  63912. +#endif
  63913. + /* Change to L3(OFF) state */
  63914. + core_if->lx_state = DWC_OTG_L3;
  63915. +
  63916. + gintsts.d32 = 0;
  63917. + gintsts.b.disconnect = 1;
  63918. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  63919. + return 1;
  63920. +}
  63921. +
  63922. +/**
  63923. + * This interrupt indicates that SUSPEND state has been detected on
  63924. + * the USB.
  63925. + *
  63926. + * For HNP the USB Suspend interrupt signals the change from
  63927. + * "a_peripheral" to "a_host".
  63928. + *
  63929. + * When power management is enabled the core will be put in low power
  63930. + * mode.
  63931. + */
  63932. +int32_t dwc_otg_handle_usb_suspend_intr(dwc_otg_core_if_t * core_if)
  63933. +{
  63934. + dsts_data_t dsts;
  63935. + gintsts_data_t gintsts;
  63936. + dcfg_data_t dcfg;
  63937. +
  63938. + DWC_DEBUGPL(DBG_ANY, "USB SUSPEND\n");
  63939. +
  63940. + if (dwc_otg_is_device_mode(core_if)) {
  63941. + /* Check the Device status register to determine if the Suspend
  63942. + * state is active. */
  63943. + dsts.d32 =
  63944. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  63945. + DWC_DEBUGPL(DBG_PCD, "DSTS=0x%0x\n", dsts.d32);
  63946. + DWC_DEBUGPL(DBG_PCD, "DSTS.Suspend Status=%d "
  63947. + "HWCFG4.power Optimize=%d\n",
  63948. + dsts.b.suspsts, core_if->hwcfg4.b.power_optimiz);
  63949. +
  63950. +#ifdef PARTIAL_POWER_DOWN
  63951. +/** @todo Add a module parameter for power management. */
  63952. +
  63953. + if (dsts.b.suspsts && core_if->hwcfg4.b.power_optimiz) {
  63954. + pcgcctl_data_t power = {.d32 = 0 };
  63955. + DWC_DEBUGPL(DBG_CIL, "suspend\n");
  63956. +
  63957. + power.b.pwrclmp = 1;
  63958. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  63959. +
  63960. + power.b.rstpdwnmodule = 1;
  63961. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, power.d32);
  63962. +
  63963. + power.b.stoppclk = 1;
  63964. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, power.d32);
  63965. +
  63966. + } else {
  63967. + DWC_DEBUGPL(DBG_ANY, "disconnect?\n");
  63968. + }
  63969. +#endif
  63970. + /* PCD callback for suspend. Release the lock inside of callback function */
  63971. + cil_pcd_suspend(core_if);
  63972. + if (core_if->power_down == 2)
  63973. + {
  63974. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  63975. + DWC_DEBUGPL(DBG_ANY,"lx_state = %08x\n",core_if->lx_state);
  63976. + DWC_DEBUGPL(DBG_ANY," device address = %08d\n",dcfg.b.devaddr);
  63977. +
  63978. + if (core_if->lx_state != DWC_OTG_L3 && dcfg.b.devaddr) {
  63979. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  63980. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  63981. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  63982. +
  63983. + /* Change to L2(suspend) state */
  63984. + core_if->lx_state = DWC_OTG_L2;
  63985. +
  63986. + /* Clear interrupt in gintsts */
  63987. + gintsts.d32 = 0;
  63988. + gintsts.b.usbsuspend = 1;
  63989. + DWC_WRITE_REG32(&core_if->core_global_regs->
  63990. + gintsts, gintsts.d32);
  63991. + DWC_PRINTF("Start of hibernation completed\n");
  63992. + dwc_otg_save_global_regs(core_if);
  63993. + dwc_otg_save_dev_regs(core_if);
  63994. +
  63995. + gusbcfg.d32 =
  63996. + DWC_READ_REG32(&core_if->core_global_regs->
  63997. + gusbcfg);
  63998. + if (gusbcfg.b.ulpi_utmi_sel == 1) {
  63999. + /* ULPI interface */
  64000. + /* Suspend the Phy Clock */
  64001. + pcgcctl.d32 = 0;
  64002. + pcgcctl.b.stoppclk = 1;
  64003. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  64004. + pcgcctl.d32);
  64005. + dwc_udelay(10);
  64006. + gpwrdn.b.pmuactv = 1;
  64007. + DWC_MODIFY_REG32(&core_if->
  64008. + core_global_regs->
  64009. + gpwrdn, 0, gpwrdn.d32);
  64010. + } else {
  64011. + /* UTMI+ Interface */
  64012. + gpwrdn.b.pmuactv = 1;
  64013. + DWC_MODIFY_REG32(&core_if->
  64014. + core_global_regs->
  64015. + gpwrdn, 0, gpwrdn.d32);
  64016. + dwc_udelay(10);
  64017. + pcgcctl.b.stoppclk = 1;
  64018. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  64019. + pcgcctl.d32);
  64020. + dwc_udelay(10);
  64021. + }
  64022. +
  64023. + /* Set flag to indicate that we are in hibernation */
  64024. + core_if->hibernation_suspend = 1;
  64025. + /* Enable interrupts from wake up logic */
  64026. + gpwrdn.d32 = 0;
  64027. + gpwrdn.b.pmuintsel = 1;
  64028. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  64029. + gpwrdn, 0, gpwrdn.d32);
  64030. + dwc_udelay(10);
  64031. +
  64032. + /* Unmask device mode interrupts in GPWRDN */
  64033. + gpwrdn.d32 = 0;
  64034. + gpwrdn.b.rst_det_msk = 1;
  64035. + gpwrdn.b.lnstchng_msk = 1;
  64036. + gpwrdn.b.sts_chngint_msk = 1;
  64037. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  64038. + gpwrdn, 0, gpwrdn.d32);
  64039. + dwc_udelay(10);
  64040. +
  64041. + /* Enable Power Down Clamp */
  64042. + gpwrdn.d32 = 0;
  64043. + gpwrdn.b.pwrdnclmp = 1;
  64044. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  64045. + gpwrdn, 0, gpwrdn.d32);
  64046. + dwc_udelay(10);
  64047. +
  64048. + /* Switch off VDD */
  64049. + gpwrdn.d32 = 0;
  64050. + gpwrdn.b.pwrdnswtch = 1;
  64051. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  64052. + gpwrdn, 0, gpwrdn.d32);
  64053. +
  64054. + /* Save gpwrdn register for further usage if stschng interrupt */
  64055. + core_if->gr_backup->gpwrdn_local =
  64056. + DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  64057. + DWC_PRINTF("Hibernation completed\n");
  64058. +
  64059. + return 1;
  64060. + }
  64061. + } else if (core_if->power_down == 3) {
  64062. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  64063. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  64064. + DWC_DEBUGPL(DBG_ANY, "lx_state = %08x\n",core_if->lx_state);
  64065. + DWC_DEBUGPL(DBG_ANY, " device address = %08d\n",dcfg.b.devaddr);
  64066. +
  64067. + if (core_if->lx_state != DWC_OTG_L3 && dcfg.b.devaddr) {
  64068. + DWC_DEBUGPL(DBG_ANY, "Start entering to extended hibernation\n");
  64069. + core_if->xhib = 1;
  64070. +
  64071. + /* Clear interrupt in gintsts */
  64072. + gintsts.d32 = 0;
  64073. + gintsts.b.usbsuspend = 1;
  64074. + DWC_WRITE_REG32(&core_if->core_global_regs->
  64075. + gintsts, gintsts.d32);
  64076. +
  64077. + dwc_otg_save_global_regs(core_if);
  64078. + dwc_otg_save_dev_regs(core_if);
  64079. +
  64080. + /* Wait for 10 PHY clocks */
  64081. + dwc_udelay(10);
  64082. +
  64083. + /* Program GPIO register while entering to xHib */
  64084. + DWC_WRITE_REG32(&core_if->core_global_regs->ggpio, 0x1);
  64085. +
  64086. + pcgcctl.b.enbl_extnd_hiber = 1;
  64087. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  64088. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  64089. +
  64090. + pcgcctl.d32 = 0;
  64091. + pcgcctl.b.extnd_hiber_pwrclmp = 1;
  64092. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  64093. +
  64094. + pcgcctl.d32 = 0;
  64095. + pcgcctl.b.extnd_hiber_switch = 1;
  64096. + core_if->gr_backup->xhib_gpwrdn = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  64097. + core_if->gr_backup->xhib_pcgcctl = DWC_READ_REG32(core_if->pcgcctl) | pcgcctl.d32;
  64098. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  64099. +
  64100. + DWC_DEBUGPL(DBG_ANY, "Finished entering to extended hibernation\n");
  64101. +
  64102. + return 1;
  64103. + }
  64104. + }
  64105. + } else {
  64106. + if (core_if->op_state == A_PERIPHERAL) {
  64107. + DWC_DEBUGPL(DBG_ANY, "a_peripheral->a_host\n");
  64108. + /* Clear the a_peripheral flag, back to a_host. */
  64109. + DWC_SPINUNLOCK(core_if->lock);
  64110. + cil_pcd_stop(core_if);
  64111. + cil_hcd_start(core_if);
  64112. + DWC_SPINLOCK(core_if->lock);
  64113. + core_if->op_state = A_HOST;
  64114. + }
  64115. + }
  64116. +
  64117. + /* Change to L2(suspend) state */
  64118. + core_if->lx_state = DWC_OTG_L2;
  64119. +
  64120. + /* Clear interrupt */
  64121. + gintsts.d32 = 0;
  64122. + gintsts.b.usbsuspend = 1;
  64123. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  64124. +
  64125. + return 1;
  64126. +}
  64127. +
  64128. +static int32_t dwc_otg_handle_xhib_exit_intr(dwc_otg_core_if_t * core_if)
  64129. +{
  64130. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  64131. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  64132. + gahbcfg_data_t gahbcfg = {.d32 = 0 };
  64133. +
  64134. + dwc_udelay(10);
  64135. +
  64136. + /* Program GPIO register while entering to xHib */
  64137. + DWC_WRITE_REG32(&core_if->core_global_regs->ggpio, 0x0);
  64138. +
  64139. + pcgcctl.d32 = core_if->gr_backup->xhib_pcgcctl;
  64140. + pcgcctl.b.extnd_hiber_pwrclmp = 0;
  64141. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  64142. + dwc_udelay(10);
  64143. +
  64144. + gpwrdn.d32 = core_if->gr_backup->xhib_gpwrdn;
  64145. + gpwrdn.b.restore = 1;
  64146. + DWC_WRITE_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32);
  64147. + dwc_udelay(10);
  64148. +
  64149. + restore_lpm_i2c_regs(core_if);
  64150. +
  64151. + pcgcctl.d32 = core_if->gr_backup->pcgcctl_local & (0x3FFFF << 14);
  64152. + pcgcctl.b.max_xcvrselect = 1;
  64153. + pcgcctl.b.ess_reg_restored = 0;
  64154. + pcgcctl.b.extnd_hiber_switch = 0;
  64155. + pcgcctl.b.extnd_hiber_pwrclmp = 0;
  64156. + pcgcctl.b.enbl_extnd_hiber = 1;
  64157. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  64158. +
  64159. + gahbcfg.d32 = core_if->gr_backup->gahbcfg_local;
  64160. + gahbcfg.b.glblintrmsk = 1;
  64161. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg, gahbcfg.d32);
  64162. +
  64163. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  64164. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, 0x1 << 16);
  64165. +
  64166. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg,
  64167. + core_if->gr_backup->gusbcfg_local);
  64168. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg,
  64169. + core_if->dr_backup->dcfg);
  64170. +
  64171. + pcgcctl.d32 = 0;
  64172. + pcgcctl.d32 = core_if->gr_backup->pcgcctl_local & (0x3FFFF << 14);
  64173. + pcgcctl.b.max_xcvrselect = 1;
  64174. + pcgcctl.d32 |= 0x608;
  64175. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  64176. + dwc_udelay(10);
  64177. +
  64178. + pcgcctl.d32 = 0;
  64179. + pcgcctl.d32 = core_if->gr_backup->pcgcctl_local & (0x3FFFF << 14);
  64180. + pcgcctl.b.max_xcvrselect = 1;
  64181. + pcgcctl.b.ess_reg_restored = 1;
  64182. + pcgcctl.b.enbl_extnd_hiber = 1;
  64183. + pcgcctl.b.rstpdwnmodule = 1;
  64184. + pcgcctl.b.restoremode = 1;
  64185. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  64186. +
  64187. + DWC_DEBUGPL(DBG_ANY, "%s called\n", __FUNCTION__);
  64188. +
  64189. + return 1;
  64190. +}
  64191. +
  64192. +#ifdef CONFIG_USB_DWC_OTG_LPM
  64193. +/**
  64194. + * This function hadles LPM transaction received interrupt.
  64195. + */
  64196. +static int32_t dwc_otg_handle_lpm_intr(dwc_otg_core_if_t * core_if)
  64197. +{
  64198. + glpmcfg_data_t lpmcfg;
  64199. + gintsts_data_t gintsts;
  64200. +
  64201. + if (!core_if->core_params->lpm_enable) {
  64202. + DWC_PRINTF("Unexpected LPM interrupt\n");
  64203. + }
  64204. +
  64205. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  64206. + DWC_PRINTF("LPM config register = 0x%08x\n", lpmcfg.d32);
  64207. +
  64208. + if (dwc_otg_is_host_mode(core_if)) {
  64209. + cil_hcd_sleep(core_if);
  64210. + } else {
  64211. + lpmcfg.b.hird_thres |= (1 << 4);
  64212. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg,
  64213. + lpmcfg.d32);
  64214. + }
  64215. +
  64216. + /* Examine prt_sleep_sts after TL1TokenTetry period max (10 us) */
  64217. + dwc_udelay(10);
  64218. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  64219. + if (lpmcfg.b.prt_sleep_sts) {
  64220. + /* Save the current state */
  64221. + core_if->lx_state = DWC_OTG_L1;
  64222. + }
  64223. +
  64224. + /* Clear interrupt */
  64225. + gintsts.d32 = 0;
  64226. + gintsts.b.lpmtranrcvd = 1;
  64227. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  64228. + return 1;
  64229. +}
  64230. +#endif /* CONFIG_USB_DWC_OTG_LPM */
  64231. +
  64232. +/**
  64233. + * This function returns the Core Interrupt register.
  64234. + */
  64235. +static inline uint32_t dwc_otg_read_common_intr(dwc_otg_core_if_t * core_if, gintmsk_data_t *reenable_gintmsk)
  64236. +{
  64237. + gahbcfg_data_t gahbcfg = {.d32 = 0 };
  64238. + gintsts_data_t gintsts;
  64239. + gintmsk_data_t gintmsk;
  64240. + gintmsk_data_t gintmsk_common = {.d32 = 0 };
  64241. + gintmsk_common.b.wkupintr = 1;
  64242. + gintmsk_common.b.sessreqintr = 1;
  64243. + gintmsk_common.b.conidstschng = 1;
  64244. + gintmsk_common.b.otgintr = 1;
  64245. + gintmsk_common.b.modemismatch = 1;
  64246. + gintmsk_common.b.disconnect = 1;
  64247. + gintmsk_common.b.usbsuspend = 1;
  64248. +#ifdef CONFIG_USB_DWC_OTG_LPM
  64249. + gintmsk_common.b.lpmtranrcvd = 1;
  64250. +#endif
  64251. + gintmsk_common.b.restoredone = 1;
  64252. + if(dwc_otg_is_device_mode(core_if))
  64253. + {
  64254. + /** @todo: The port interrupt occurs while in device
  64255. + * mode. Added code to CIL to clear the interrupt for now!
  64256. + */
  64257. + gintmsk_common.b.portintr = 1;
  64258. + }
  64259. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  64260. + gintmsk.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  64261. + {
  64262. + unsigned long flags;
  64263. +
  64264. + // Re-enable the saved interrupts
  64265. + local_irq_save(flags);
  64266. + local_fiq_disable();
  64267. + gintmsk.d32 |= gintmsk_common.d32;
  64268. + gintsts_saved.d32 &= ~gintmsk_common.d32;
  64269. + reenable_gintmsk->d32 = gintmsk.d32;
  64270. + local_irq_restore(flags);
  64271. + }
  64272. +
  64273. + gahbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gahbcfg);
  64274. +
  64275. +#ifdef DEBUG
  64276. + /* if any common interrupts set */
  64277. + if (gintsts.d32 & gintmsk_common.d32) {
  64278. + DWC_DEBUGPL(DBG_ANY, "common_intr: gintsts=%08x gintmsk=%08x\n",
  64279. + gintsts.d32, gintmsk.d32);
  64280. + }
  64281. +#endif
  64282. + if (!fiq_fix_enable){
  64283. + if (gahbcfg.b.glblintrmsk)
  64284. + return ((gintsts.d32 & gintmsk.d32) & gintmsk_common.d32);
  64285. + else
  64286. + return 0;
  64287. + }
  64288. + else {
  64289. + return ((gintsts.d32 & gintmsk.d32) & gintmsk_common.d32);
  64290. + }
  64291. +
  64292. +}
  64293. +
  64294. +/* MACRO for clearing interupt bits in GPWRDN register */
  64295. +#define CLEAR_GPWRDN_INTR(__core_if,__intr) \
  64296. +do { \
  64297. + gpwrdn_data_t gpwrdn = {.d32=0}; \
  64298. + gpwrdn.b.__intr = 1; \
  64299. + DWC_MODIFY_REG32(&__core_if->core_global_regs->gpwrdn, \
  64300. + 0, gpwrdn.d32); \
  64301. +} while (0)
  64302. +
  64303. +/**
  64304. + * Common interrupt handler.
  64305. + *
  64306. + * The common interrupts are those that occur in both Host and Device mode.
  64307. + * This handler handles the following interrupts:
  64308. + * - Mode Mismatch Interrupt
  64309. + * - Disconnect Interrupt
  64310. + * - OTG Interrupt
  64311. + * - Connector ID Status Change Interrupt
  64312. + * - Session Request Interrupt.
  64313. + * - Resume / Remote Wakeup Detected Interrupt.
  64314. + * - LPM Transaction Received Interrupt
  64315. + * - ADP Transaction Received Interrupt
  64316. + *
  64317. + */
  64318. +int32_t dwc_otg_handle_common_intr(void *dev)
  64319. +{
  64320. + int retval = 0;
  64321. + gintsts_data_t gintsts;
  64322. + gintmsk_data_t reenable_gintmsk;
  64323. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  64324. + dwc_otg_device_t *otg_dev = dev;
  64325. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  64326. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  64327. + if (dwc_otg_is_device_mode(core_if))
  64328. + core_if->frame_num = dwc_otg_get_frame_number(core_if);
  64329. +
  64330. + if (core_if->lock)
  64331. + DWC_SPINLOCK(core_if->lock);
  64332. +
  64333. + if (core_if->power_down == 3 && core_if->xhib == 1) {
  64334. + DWC_DEBUGPL(DBG_ANY, "Exiting from xHIB state\n");
  64335. + retval |= dwc_otg_handle_xhib_exit_intr(core_if);
  64336. + core_if->xhib = 2;
  64337. + if (core_if->lock)
  64338. + DWC_SPINUNLOCK(core_if->lock);
  64339. +
  64340. + return retval;
  64341. + }
  64342. +
  64343. + if (core_if->hibernation_suspend <= 0) {
  64344. + gintsts.d32 = dwc_otg_read_common_intr(core_if, &reenable_gintmsk);
  64345. +
  64346. + if (gintsts.b.modemismatch) {
  64347. + retval |= dwc_otg_handle_mode_mismatch_intr(core_if);
  64348. + }
  64349. + if (gintsts.b.otgintr) {
  64350. + retval |= dwc_otg_handle_otg_intr(core_if);
  64351. + }
  64352. + if (gintsts.b.conidstschng) {
  64353. + retval |=
  64354. + dwc_otg_handle_conn_id_status_change_intr(core_if);
  64355. + }
  64356. + if (gintsts.b.disconnect) {
  64357. + retval |= dwc_otg_handle_disconnect_intr(core_if);
  64358. + }
  64359. + if (gintsts.b.sessreqintr) {
  64360. + retval |= dwc_otg_handle_session_req_intr(core_if);
  64361. + }
  64362. + if (gintsts.b.wkupintr) {
  64363. + retval |= dwc_otg_handle_wakeup_detected_intr(core_if);
  64364. + }
  64365. + if (gintsts.b.usbsuspend) {
  64366. + retval |= dwc_otg_handle_usb_suspend_intr(core_if);
  64367. + }
  64368. +#ifdef CONFIG_USB_DWC_OTG_LPM
  64369. + if (gintsts.b.lpmtranrcvd) {
  64370. + retval |= dwc_otg_handle_lpm_intr(core_if);
  64371. + }
  64372. +#endif
  64373. + if (gintsts.b.restoredone) {
  64374. + gintsts.d32 = 0;
  64375. + if (core_if->power_down == 2)
  64376. + core_if->hibernation_suspend = -1;
  64377. + else if (core_if->power_down == 3 && core_if->xhib == 2) {
  64378. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  64379. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  64380. + dctl_data_t dctl = {.d32 = 0 };
  64381. +
  64382. + DWC_WRITE_REG32(&core_if->core_global_regs->
  64383. + gintsts, 0xFFFFFFFF);
  64384. +
  64385. + DWC_DEBUGPL(DBG_ANY,
  64386. + "RESTORE DONE generated\n");
  64387. +
  64388. + gpwrdn.b.restore = 1;
  64389. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64390. + dwc_udelay(10);
  64391. +
  64392. + pcgcctl.b.rstpdwnmodule = 1;
  64393. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  64394. +
  64395. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, core_if->gr_backup->gusbcfg_local);
  64396. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, core_if->dr_backup->dcfg);
  64397. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, core_if->dr_backup->dctl);
  64398. + dwc_udelay(50);
  64399. +
  64400. + dctl.b.pwronprgdone = 1;
  64401. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  64402. + dwc_udelay(10);
  64403. +
  64404. + dwc_otg_restore_global_regs(core_if);
  64405. + dwc_otg_restore_dev_regs(core_if, 0);
  64406. +
  64407. + dctl.d32 = 0;
  64408. + dctl.b.pwronprgdone = 1;
  64409. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, 0);
  64410. + dwc_udelay(10);
  64411. +
  64412. + pcgcctl.d32 = 0;
  64413. + pcgcctl.b.enbl_extnd_hiber = 1;
  64414. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  64415. +
  64416. + /* The core will be in ON STATE */
  64417. + core_if->lx_state = DWC_OTG_L0;
  64418. + core_if->xhib = 0;
  64419. +
  64420. + DWC_SPINUNLOCK(core_if->lock);
  64421. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  64422. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  64423. + }
  64424. + DWC_SPINLOCK(core_if->lock);
  64425. +
  64426. + }
  64427. +
  64428. + gintsts.b.restoredone = 1;
  64429. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts,gintsts.d32);
  64430. + DWC_PRINTF(" --Restore done interrupt received-- \n");
  64431. + retval |= 1;
  64432. + }
  64433. + if (gintsts.b.portintr && dwc_otg_is_device_mode(core_if)) {
  64434. + /* The port interrupt occurs while in device mode with HPRT0
  64435. + * Port Enable/Disable.
  64436. + */
  64437. + gintsts.d32 = 0;
  64438. + gintsts.b.portintr = 1;
  64439. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts,gintsts.d32);
  64440. + retval |= 1;
  64441. + reenable_gintmsk.b.portintr = 1;
  64442. +
  64443. + }
  64444. +
  64445. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, reenable_gintmsk.d32);
  64446. +
  64447. + } else {
  64448. + DWC_DEBUGPL(DBG_ANY, "gpwrdn=%08x\n", gpwrdn.d32);
  64449. +
  64450. + if (gpwrdn.b.disconn_det && gpwrdn.b.disconn_det_msk) {
  64451. + CLEAR_GPWRDN_INTR(core_if, disconn_det);
  64452. + if (gpwrdn.b.linestate == 0) {
  64453. + dwc_otg_handle_pwrdn_disconnect_intr(core_if);
  64454. + } else {
  64455. + DWC_PRINTF("Disconnect detected while linestate is not 0\n");
  64456. + }
  64457. +
  64458. + retval |= 1;
  64459. + }
  64460. + if (gpwrdn.b.lnstschng && gpwrdn.b.lnstchng_msk) {
  64461. + CLEAR_GPWRDN_INTR(core_if, lnstschng);
  64462. + /* remote wakeup from hibernation */
  64463. + if (gpwrdn.b.linestate == 2 || gpwrdn.b.linestate == 1) {
  64464. + dwc_otg_handle_pwrdn_wakeup_detected_intr(core_if);
  64465. + } else {
  64466. + DWC_PRINTF("gpwrdn.linestate = %d\n", gpwrdn.b.linestate);
  64467. + }
  64468. + retval |= 1;
  64469. + }
  64470. + if (gpwrdn.b.rst_det && gpwrdn.b.rst_det_msk) {
  64471. + CLEAR_GPWRDN_INTR(core_if, rst_det);
  64472. + if (gpwrdn.b.linestate == 0) {
  64473. + DWC_PRINTF("Reset detected\n");
  64474. + retval |= dwc_otg_device_hibernation_restore(core_if, 0, 1);
  64475. + }
  64476. + }
  64477. + if (gpwrdn.b.srp_det && gpwrdn.b.srp_det_msk) {
  64478. + CLEAR_GPWRDN_INTR(core_if, srp_det);
  64479. + dwc_otg_handle_pwrdn_srp_intr(core_if);
  64480. + retval |= 1;
  64481. + }
  64482. + }
  64483. + /* Handle ADP interrupt here */
  64484. + if (gpwrdn.b.adp_int) {
  64485. + DWC_PRINTF("ADP interrupt\n");
  64486. + CLEAR_GPWRDN_INTR(core_if, adp_int);
  64487. + dwc_otg_adp_handle_intr(core_if);
  64488. + retval |= 1;
  64489. + }
  64490. + if (gpwrdn.b.sts_chngint && gpwrdn.b.sts_chngint_msk) {
  64491. + DWC_PRINTF("STS CHNG interrupt asserted\n");
  64492. + CLEAR_GPWRDN_INTR(core_if, sts_chngint);
  64493. + dwc_otg_handle_pwrdn_stschng_intr(otg_dev);
  64494. +
  64495. + retval |= 1;
  64496. + }
  64497. + if (core_if->lock)
  64498. + DWC_SPINUNLOCK(core_if->lock);
  64499. +
  64500. + return retval;
  64501. +}
  64502. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_core_if.h linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_core_if.h
  64503. --- linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_core_if.h 1970-01-01 01:00:00.000000000 +0100
  64504. +++ linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_core_if.h 2014-02-17 22:41:01.000000000 +0100
  64505. @@ -0,0 +1,705 @@
  64506. +/* ==========================================================================
  64507. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_core_if.h $
  64508. + * $Revision: #13 $
  64509. + * $Date: 2012/08/10 $
  64510. + * $Change: 2047372 $
  64511. + *
  64512. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  64513. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  64514. + * otherwise expressly agreed to in writing between Synopsys and you.
  64515. + *
  64516. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  64517. + * any End User Software License Agreement or Agreement for Licensed Product
  64518. + * with Synopsys or any supplement thereto. You are permitted to use and
  64519. + * redistribute this Software in source and binary forms, with or without
  64520. + * modification, provided that redistributions of source code must retain this
  64521. + * notice. You may not view, use, disclose, copy or distribute this file or
  64522. + * any information contained herein except pursuant to this license grant from
  64523. + * Synopsys. If you do not agree with this notice, including the disclaimer
  64524. + * below, then you are not authorized to use the Software.
  64525. + *
  64526. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  64527. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  64528. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  64529. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  64530. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  64531. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  64532. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  64533. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  64534. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  64535. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  64536. + * DAMAGE.
  64537. + * ========================================================================== */
  64538. +#if !defined(__DWC_CORE_IF_H__)
  64539. +#define __DWC_CORE_IF_H__
  64540. +
  64541. +#include "dwc_os.h"
  64542. +
  64543. +/** @file
  64544. + * This file defines DWC_OTG Core API
  64545. + */
  64546. +
  64547. +struct dwc_otg_core_if;
  64548. +typedef struct dwc_otg_core_if dwc_otg_core_if_t;
  64549. +
  64550. +/** Maximum number of Periodic FIFOs */
  64551. +#define MAX_PERIO_FIFOS 15
  64552. +/** Maximum number of Periodic FIFOs */
  64553. +#define MAX_TX_FIFOS 15
  64554. +
  64555. +/** Maximum number of Endpoints/HostChannels */
  64556. +#define MAX_EPS_CHANNELS 16
  64557. +
  64558. +extern dwc_otg_core_if_t *dwc_otg_cil_init(const uint32_t * _reg_base_addr);
  64559. +extern void dwc_otg_core_init(dwc_otg_core_if_t * _core_if);
  64560. +extern void dwc_otg_cil_remove(dwc_otg_core_if_t * _core_if);
  64561. +
  64562. +extern void dwc_otg_enable_global_interrupts(dwc_otg_core_if_t * _core_if);
  64563. +extern void dwc_otg_disable_global_interrupts(dwc_otg_core_if_t * _core_if);
  64564. +
  64565. +extern uint8_t dwc_otg_is_device_mode(dwc_otg_core_if_t * _core_if);
  64566. +extern uint8_t dwc_otg_is_host_mode(dwc_otg_core_if_t * _core_if);
  64567. +
  64568. +extern uint8_t dwc_otg_is_dma_enable(dwc_otg_core_if_t * core_if);
  64569. +
  64570. +/** This function should be called on every hardware interrupt. */
  64571. +extern int32_t dwc_otg_handle_common_intr(void *otg_dev);
  64572. +
  64573. +/** @name OTG Core Parameters */
  64574. +/** @{ */
  64575. +
  64576. +/**
  64577. + * Specifies the OTG capabilities. The driver will automatically
  64578. + * detect the value for this parameter if none is specified.
  64579. + * 0 - HNP and SRP capable (default)
  64580. + * 1 - SRP Only capable
  64581. + * 2 - No HNP/SRP capable
  64582. + */
  64583. +extern int dwc_otg_set_param_otg_cap(dwc_otg_core_if_t * core_if, int32_t val);
  64584. +extern int32_t dwc_otg_get_param_otg_cap(dwc_otg_core_if_t * core_if);
  64585. +#define DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE 0
  64586. +#define DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE 1
  64587. +#define DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE 2
  64588. +#define dwc_param_otg_cap_default DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE
  64589. +
  64590. +extern int dwc_otg_set_param_opt(dwc_otg_core_if_t * core_if, int32_t val);
  64591. +extern int32_t dwc_otg_get_param_opt(dwc_otg_core_if_t * core_if);
  64592. +#define dwc_param_opt_default 1
  64593. +
  64594. +/**
  64595. + * Specifies whether to use slave or DMA mode for accessing the data
  64596. + * FIFOs. The driver will automatically detect the value for this
  64597. + * parameter if none is specified.
  64598. + * 0 - Slave
  64599. + * 1 - DMA (default, if available)
  64600. + */
  64601. +extern int dwc_otg_set_param_dma_enable(dwc_otg_core_if_t * core_if,
  64602. + int32_t val);
  64603. +extern int32_t dwc_otg_get_param_dma_enable(dwc_otg_core_if_t * core_if);
  64604. +#define dwc_param_dma_enable_default 1
  64605. +
  64606. +/**
  64607. + * When DMA mode is enabled specifies whether to use
  64608. + * address DMA or DMA Descritor mode for accessing the data
  64609. + * FIFOs in device mode. The driver will automatically detect
  64610. + * the value for this parameter if none is specified.
  64611. + * 0 - address DMA
  64612. + * 1 - DMA Descriptor(default, if available)
  64613. + */
  64614. +extern int dwc_otg_set_param_dma_desc_enable(dwc_otg_core_if_t * core_if,
  64615. + int32_t val);
  64616. +extern int32_t dwc_otg_get_param_dma_desc_enable(dwc_otg_core_if_t * core_if);
  64617. +//#define dwc_param_dma_desc_enable_default 1
  64618. +#define dwc_param_dma_desc_enable_default 0 // Broadcom BCM2708
  64619. +
  64620. +/** The DMA Burst size (applicable only for External DMA
  64621. + * Mode). 1, 4, 8 16, 32, 64, 128, 256 (default 32)
  64622. + */
  64623. +extern int dwc_otg_set_param_dma_burst_size(dwc_otg_core_if_t * core_if,
  64624. + int32_t val);
  64625. +extern int32_t dwc_otg_get_param_dma_burst_size(dwc_otg_core_if_t * core_if);
  64626. +#define dwc_param_dma_burst_size_default 32
  64627. +
  64628. +/**
  64629. + * Specifies the maximum speed of operation in host and device mode.
  64630. + * The actual speed depends on the speed of the attached device and
  64631. + * the value of phy_type. The actual speed depends on the speed of the
  64632. + * attached device.
  64633. + * 0 - High Speed (default)
  64634. + * 1 - Full Speed
  64635. + */
  64636. +extern int dwc_otg_set_param_speed(dwc_otg_core_if_t * core_if, int32_t val);
  64637. +extern int32_t dwc_otg_get_param_speed(dwc_otg_core_if_t * core_if);
  64638. +#define dwc_param_speed_default 0
  64639. +#define DWC_SPEED_PARAM_HIGH 0
  64640. +#define DWC_SPEED_PARAM_FULL 1
  64641. +
  64642. +/** Specifies whether low power mode is supported when attached
  64643. + * to a Full Speed or Low Speed device in host mode.
  64644. + * 0 - Don't support low power mode (default)
  64645. + * 1 - Support low power mode
  64646. + */
  64647. +extern int dwc_otg_set_param_host_support_fs_ls_low_power(dwc_otg_core_if_t *
  64648. + core_if, int32_t val);
  64649. +extern int32_t dwc_otg_get_param_host_support_fs_ls_low_power(dwc_otg_core_if_t
  64650. + * core_if);
  64651. +#define dwc_param_host_support_fs_ls_low_power_default 0
  64652. +
  64653. +/** Specifies the PHY clock rate in low power mode when connected to a
  64654. + * Low Speed device in host mode. This parameter is applicable only if
  64655. + * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
  64656. + * then defaults to 6 MHZ otherwise 48 MHZ.
  64657. + *
  64658. + * 0 - 48 MHz
  64659. + * 1 - 6 MHz
  64660. + */
  64661. +extern int dwc_otg_set_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t *
  64662. + core_if, int32_t val);
  64663. +extern int32_t dwc_otg_get_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t *
  64664. + core_if);
  64665. +#define dwc_param_host_ls_low_power_phy_clk_default 0
  64666. +#define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ 0
  64667. +#define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ 1
  64668. +
  64669. +/**
  64670. + * 0 - Use cC FIFO size parameters
  64671. + * 1 - Allow dynamic FIFO sizing (default)
  64672. + */
  64673. +extern int dwc_otg_set_param_enable_dynamic_fifo(dwc_otg_core_if_t * core_if,
  64674. + int32_t val);
  64675. +extern int32_t dwc_otg_get_param_enable_dynamic_fifo(dwc_otg_core_if_t *
  64676. + core_if);
  64677. +#define dwc_param_enable_dynamic_fifo_default 1
  64678. +
  64679. +/** Total number of 4-byte words in the data FIFO memory. This
  64680. + * memory includes the Rx FIFO, non-periodic Tx FIFO, and periodic
  64681. + * Tx FIFOs.
  64682. + * 32 to 32768 (default 8192)
  64683. + * Note: The total FIFO memory depth in the FPGA configuration is 8192.
  64684. + */
  64685. +extern int dwc_otg_set_param_data_fifo_size(dwc_otg_core_if_t * core_if,
  64686. + int32_t val);
  64687. +extern int32_t dwc_otg_get_param_data_fifo_size(dwc_otg_core_if_t * core_if);
  64688. +//#define dwc_param_data_fifo_size_default 8192
  64689. +#define dwc_param_data_fifo_size_default 0xFF0 // Broadcom BCM2708
  64690. +
  64691. +/** Number of 4-byte words in the Rx FIFO in device mode when dynamic
  64692. + * FIFO sizing is enabled.
  64693. + * 16 to 32768 (default 1064)
  64694. + */
  64695. +extern int dwc_otg_set_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if,
  64696. + int32_t val);
  64697. +extern int32_t dwc_otg_get_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if);
  64698. +#define dwc_param_dev_rx_fifo_size_default 1064
  64699. +
  64700. +/** Number of 4-byte words in the non-periodic Tx FIFO in device mode
  64701. + * when dynamic FIFO sizing is enabled.
  64702. + * 16 to 32768 (default 1024)
  64703. + */
  64704. +extern int dwc_otg_set_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t *
  64705. + core_if, int32_t val);
  64706. +extern int32_t dwc_otg_get_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t *
  64707. + core_if);
  64708. +#define dwc_param_dev_nperio_tx_fifo_size_default 1024
  64709. +
  64710. +/** Number of 4-byte words in each of the periodic Tx FIFOs in device
  64711. + * mode when dynamic FIFO sizing is enabled.
  64712. + * 4 to 768 (default 256)
  64713. + */
  64714. +extern int dwc_otg_set_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  64715. + int32_t val, int fifo_num);
  64716. +extern int32_t dwc_otg_get_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t *
  64717. + core_if, int fifo_num);
  64718. +#define dwc_param_dev_perio_tx_fifo_size_default 256
  64719. +
  64720. +/** Number of 4-byte words in the Rx FIFO in host mode when dynamic
  64721. + * FIFO sizing is enabled.
  64722. + * 16 to 32768 (default 1024)
  64723. + */
  64724. +extern int dwc_otg_set_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if,
  64725. + int32_t val);
  64726. +extern int32_t dwc_otg_get_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if);
  64727. +//#define dwc_param_host_rx_fifo_size_default 1024
  64728. +#define dwc_param_host_rx_fifo_size_default 774 // Broadcom BCM2708
  64729. +
  64730. +/** Number of 4-byte words in the non-periodic Tx FIFO in host mode
  64731. + * when Dynamic FIFO sizing is enabled in the core.
  64732. + * 16 to 32768 (default 1024)
  64733. + */
  64734. +extern int dwc_otg_set_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t *
  64735. + core_if, int32_t val);
  64736. +extern int32_t dwc_otg_get_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t *
  64737. + core_if);
  64738. +//#define dwc_param_host_nperio_tx_fifo_size_default 1024
  64739. +#define dwc_param_host_nperio_tx_fifo_size_default 0x100 // Broadcom BCM2708
  64740. +
  64741. +/** Number of 4-byte words in the host periodic Tx FIFO when dynamic
  64742. + * FIFO sizing is enabled.
  64743. + * 16 to 32768 (default 1024)
  64744. + */
  64745. +extern int dwc_otg_set_param_host_perio_tx_fifo_size(dwc_otg_core_if_t *
  64746. + core_if, int32_t val);
  64747. +extern int32_t dwc_otg_get_param_host_perio_tx_fifo_size(dwc_otg_core_if_t *
  64748. + core_if);
  64749. +//#define dwc_param_host_perio_tx_fifo_size_default 1024
  64750. +#define dwc_param_host_perio_tx_fifo_size_default 0x200 // Broadcom BCM2708
  64751. +
  64752. +/** The maximum transfer size supported in bytes.
  64753. + * 2047 to 65,535 (default 65,535)
  64754. + */
  64755. +extern int dwc_otg_set_param_max_transfer_size(dwc_otg_core_if_t * core_if,
  64756. + int32_t val);
  64757. +extern int32_t dwc_otg_get_param_max_transfer_size(dwc_otg_core_if_t * core_if);
  64758. +#define dwc_param_max_transfer_size_default 65535
  64759. +
  64760. +/** The maximum number of packets in a transfer.
  64761. + * 15 to 511 (default 511)
  64762. + */
  64763. +extern int dwc_otg_set_param_max_packet_count(dwc_otg_core_if_t * core_if,
  64764. + int32_t val);
  64765. +extern int32_t dwc_otg_get_param_max_packet_count(dwc_otg_core_if_t * core_if);
  64766. +#define dwc_param_max_packet_count_default 511
  64767. +
  64768. +/** The number of host channel registers to use.
  64769. + * 1 to 16 (default 12)
  64770. + * Note: The FPGA configuration supports a maximum of 12 host channels.
  64771. + */
  64772. +extern int dwc_otg_set_param_host_channels(dwc_otg_core_if_t * core_if,
  64773. + int32_t val);
  64774. +extern int32_t dwc_otg_get_param_host_channels(dwc_otg_core_if_t * core_if);
  64775. +//#define dwc_param_host_channels_default 12
  64776. +#define dwc_param_host_channels_default 8 // Broadcom BCM2708
  64777. +
  64778. +/** The number of endpoints in addition to EP0 available for device
  64779. + * mode operations.
  64780. + * 1 to 15 (default 6 IN and OUT)
  64781. + * Note: The FPGA configuration supports a maximum of 6 IN and OUT
  64782. + * endpoints in addition to EP0.
  64783. + */
  64784. +extern int dwc_otg_set_param_dev_endpoints(dwc_otg_core_if_t * core_if,
  64785. + int32_t val);
  64786. +extern int32_t dwc_otg_get_param_dev_endpoints(dwc_otg_core_if_t * core_if);
  64787. +#define dwc_param_dev_endpoints_default 6
  64788. +
  64789. +/**
  64790. + * Specifies the type of PHY interface to use. By default, the driver
  64791. + * will automatically detect the phy_type.
  64792. + *
  64793. + * 0 - Full Speed PHY
  64794. + * 1 - UTMI+ (default)
  64795. + * 2 - ULPI
  64796. + */
  64797. +extern int dwc_otg_set_param_phy_type(dwc_otg_core_if_t * core_if, int32_t val);
  64798. +extern int32_t dwc_otg_get_param_phy_type(dwc_otg_core_if_t * core_if);
  64799. +#define DWC_PHY_TYPE_PARAM_FS 0
  64800. +#define DWC_PHY_TYPE_PARAM_UTMI 1
  64801. +#define DWC_PHY_TYPE_PARAM_ULPI 2
  64802. +#define dwc_param_phy_type_default DWC_PHY_TYPE_PARAM_UTMI
  64803. +
  64804. +/**
  64805. + * Specifies the UTMI+ Data Width. This parameter is
  64806. + * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
  64807. + * PHY_TYPE, this parameter indicates the data width between
  64808. + * the MAC and the ULPI Wrapper.) Also, this parameter is
  64809. + * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
  64810. + * to "8 and 16 bits", meaning that the core has been
  64811. + * configured to work at either data path width.
  64812. + *
  64813. + * 8 or 16 bits (default 16)
  64814. + */
  64815. +extern int dwc_otg_set_param_phy_utmi_width(dwc_otg_core_if_t * core_if,
  64816. + int32_t val);
  64817. +extern int32_t dwc_otg_get_param_phy_utmi_width(dwc_otg_core_if_t * core_if);
  64818. +//#define dwc_param_phy_utmi_width_default 16
  64819. +#define dwc_param_phy_utmi_width_default 8 // Broadcom BCM2708
  64820. +
  64821. +/**
  64822. + * Specifies whether the ULPI operates at double or single
  64823. + * data rate. This parameter is only applicable if PHY_TYPE is
  64824. + * ULPI.
  64825. + *
  64826. + * 0 - single data rate ULPI interface with 8 bit wide data
  64827. + * bus (default)
  64828. + * 1 - double data rate ULPI interface with 4 bit wide data
  64829. + * bus
  64830. + */
  64831. +extern int dwc_otg_set_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if,
  64832. + int32_t val);
  64833. +extern int32_t dwc_otg_get_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if);
  64834. +#define dwc_param_phy_ulpi_ddr_default 0
  64835. +
  64836. +/**
  64837. + * Specifies whether to use the internal or external supply to
  64838. + * drive the vbus with a ULPI phy.
  64839. + */
  64840. +extern int dwc_otg_set_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if,
  64841. + int32_t val);
  64842. +extern int32_t dwc_otg_get_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if);
  64843. +#define DWC_PHY_ULPI_INTERNAL_VBUS 0
  64844. +#define DWC_PHY_ULPI_EXTERNAL_VBUS 1
  64845. +#define dwc_param_phy_ulpi_ext_vbus_default DWC_PHY_ULPI_INTERNAL_VBUS
  64846. +
  64847. +/**
  64848. + * Specifies whether to use the I2Cinterface for full speed PHY. This
  64849. + * parameter is only applicable if PHY_TYPE is FS.
  64850. + * 0 - No (default)
  64851. + * 1 - Yes
  64852. + */
  64853. +extern int dwc_otg_set_param_i2c_enable(dwc_otg_core_if_t * core_if,
  64854. + int32_t val);
  64855. +extern int32_t dwc_otg_get_param_i2c_enable(dwc_otg_core_if_t * core_if);
  64856. +#define dwc_param_i2c_enable_default 0
  64857. +
  64858. +extern int dwc_otg_set_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if,
  64859. + int32_t val);
  64860. +extern int32_t dwc_otg_get_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if);
  64861. +#define dwc_param_ulpi_fs_ls_default 0
  64862. +
  64863. +extern int dwc_otg_set_param_ts_dline(dwc_otg_core_if_t * core_if, int32_t val);
  64864. +extern int32_t dwc_otg_get_param_ts_dline(dwc_otg_core_if_t * core_if);
  64865. +#define dwc_param_ts_dline_default 0
  64866. +
  64867. +/**
  64868. + * Specifies whether dedicated transmit FIFOs are
  64869. + * enabled for non periodic IN endpoints in device mode
  64870. + * 0 - No
  64871. + * 1 - Yes
  64872. + */
  64873. +extern int dwc_otg_set_param_en_multiple_tx_fifo(dwc_otg_core_if_t * core_if,
  64874. + int32_t val);
  64875. +extern int32_t dwc_otg_get_param_en_multiple_tx_fifo(dwc_otg_core_if_t *
  64876. + core_if);
  64877. +#define dwc_param_en_multiple_tx_fifo_default 1
  64878. +
  64879. +/** Number of 4-byte words in each of the Tx FIFOs in device
  64880. + * mode when dynamic FIFO sizing is enabled.
  64881. + * 4 to 768 (default 256)
  64882. + */
  64883. +extern int dwc_otg_set_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if,
  64884. + int fifo_num, int32_t val);
  64885. +extern int32_t dwc_otg_get_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if,
  64886. + int fifo_num);
  64887. +#define dwc_param_dev_tx_fifo_size_default 768
  64888. +
  64889. +/** Thresholding enable flag-
  64890. + * bit 0 - enable non-ISO Tx thresholding
  64891. + * bit 1 - enable ISO Tx thresholding
  64892. + * bit 2 - enable Rx thresholding
  64893. + */
  64894. +extern int dwc_otg_set_param_thr_ctl(dwc_otg_core_if_t * core_if, int32_t val);
  64895. +extern int32_t dwc_otg_get_thr_ctl(dwc_otg_core_if_t * core_if, int fifo_num);
  64896. +#define dwc_param_thr_ctl_default 0
  64897. +
  64898. +/** Thresholding length for Tx
  64899. + * FIFOs in 32 bit DWORDs
  64900. + */
  64901. +extern int dwc_otg_set_param_tx_thr_length(dwc_otg_core_if_t * core_if,
  64902. + int32_t val);
  64903. +extern int32_t dwc_otg_get_tx_thr_length(dwc_otg_core_if_t * core_if);
  64904. +#define dwc_param_tx_thr_length_default 64
  64905. +
  64906. +/** Thresholding length for Rx
  64907. + * FIFOs in 32 bit DWORDs
  64908. + */
  64909. +extern int dwc_otg_set_param_rx_thr_length(dwc_otg_core_if_t * core_if,
  64910. + int32_t val);
  64911. +extern int32_t dwc_otg_get_rx_thr_length(dwc_otg_core_if_t * core_if);
  64912. +#define dwc_param_rx_thr_length_default 64
  64913. +
  64914. +/**
  64915. + * Specifies whether LPM (Link Power Management) support is enabled
  64916. + */
  64917. +extern int dwc_otg_set_param_lpm_enable(dwc_otg_core_if_t * core_if,
  64918. + int32_t val);
  64919. +extern int32_t dwc_otg_get_param_lpm_enable(dwc_otg_core_if_t * core_if);
  64920. +#define dwc_param_lpm_enable_default 1
  64921. +
  64922. +/**
  64923. + * Specifies whether PTI enhancement is enabled
  64924. + */
  64925. +extern int dwc_otg_set_param_pti_enable(dwc_otg_core_if_t * core_if,
  64926. + int32_t val);
  64927. +extern int32_t dwc_otg_get_param_pti_enable(dwc_otg_core_if_t * core_if);
  64928. +#define dwc_param_pti_enable_default 0
  64929. +
  64930. +/**
  64931. + * Specifies whether MPI enhancement is enabled
  64932. + */
  64933. +extern int dwc_otg_set_param_mpi_enable(dwc_otg_core_if_t * core_if,
  64934. + int32_t val);
  64935. +extern int32_t dwc_otg_get_param_mpi_enable(dwc_otg_core_if_t * core_if);
  64936. +#define dwc_param_mpi_enable_default 0
  64937. +
  64938. +/**
  64939. + * Specifies whether ADP capability is enabled
  64940. + */
  64941. +extern int dwc_otg_set_param_adp_enable(dwc_otg_core_if_t * core_if,
  64942. + int32_t val);
  64943. +extern int32_t dwc_otg_get_param_adp_enable(dwc_otg_core_if_t * core_if);
  64944. +#define dwc_param_adp_enable_default 0
  64945. +
  64946. +/**
  64947. + * Specifies whether IC_USB capability is enabled
  64948. + */
  64949. +
  64950. +extern int dwc_otg_set_param_ic_usb_cap(dwc_otg_core_if_t * core_if,
  64951. + int32_t val);
  64952. +extern int32_t dwc_otg_get_param_ic_usb_cap(dwc_otg_core_if_t * core_if);
  64953. +#define dwc_param_ic_usb_cap_default 0
  64954. +
  64955. +extern int dwc_otg_set_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if,
  64956. + int32_t val);
  64957. +extern int32_t dwc_otg_get_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if);
  64958. +#define dwc_param_ahb_thr_ratio_default 0
  64959. +
  64960. +extern int dwc_otg_set_param_power_down(dwc_otg_core_if_t * core_if,
  64961. + int32_t val);
  64962. +extern int32_t dwc_otg_get_param_power_down(dwc_otg_core_if_t * core_if);
  64963. +#define dwc_param_power_down_default 0
  64964. +
  64965. +extern int dwc_otg_set_param_reload_ctl(dwc_otg_core_if_t * core_if,
  64966. + int32_t val);
  64967. +extern int32_t dwc_otg_get_param_reload_ctl(dwc_otg_core_if_t * core_if);
  64968. +#define dwc_param_reload_ctl_default 0
  64969. +
  64970. +extern int dwc_otg_set_param_dev_out_nak(dwc_otg_core_if_t * core_if,
  64971. + int32_t val);
  64972. +extern int32_t dwc_otg_get_param_dev_out_nak(dwc_otg_core_if_t * core_if);
  64973. +#define dwc_param_dev_out_nak_default 0
  64974. +
  64975. +extern int dwc_otg_set_param_cont_on_bna(dwc_otg_core_if_t * core_if,
  64976. + int32_t val);
  64977. +extern int32_t dwc_otg_get_param_cont_on_bna(dwc_otg_core_if_t * core_if);
  64978. +#define dwc_param_cont_on_bna_default 0
  64979. +
  64980. +extern int dwc_otg_set_param_ahb_single(dwc_otg_core_if_t * core_if,
  64981. + int32_t val);
  64982. +extern int32_t dwc_otg_get_param_ahb_single(dwc_otg_core_if_t * core_if);
  64983. +#define dwc_param_ahb_single_default 0
  64984. +
  64985. +extern int dwc_otg_set_param_otg_ver(dwc_otg_core_if_t * core_if, int32_t val);
  64986. +extern int32_t dwc_otg_get_param_otg_ver(dwc_otg_core_if_t * core_if);
  64987. +#define dwc_param_otg_ver_default 0
  64988. +
  64989. +/** @} */
  64990. +
  64991. +/** @name Access to registers and bit-fields */
  64992. +
  64993. +/**
  64994. + * Dump core registers and SPRAM
  64995. + */
  64996. +extern void dwc_otg_dump_dev_registers(dwc_otg_core_if_t * _core_if);
  64997. +extern void dwc_otg_dump_spram(dwc_otg_core_if_t * _core_if);
  64998. +extern void dwc_otg_dump_host_registers(dwc_otg_core_if_t * _core_if);
  64999. +extern void dwc_otg_dump_global_registers(dwc_otg_core_if_t * _core_if);
  65000. +
  65001. +/**
  65002. + * Get host negotiation status.
  65003. + */
  65004. +extern uint32_t dwc_otg_get_hnpstatus(dwc_otg_core_if_t * core_if);
  65005. +
  65006. +/**
  65007. + * Get srp status
  65008. + */
  65009. +extern uint32_t dwc_otg_get_srpstatus(dwc_otg_core_if_t * core_if);
  65010. +
  65011. +/**
  65012. + * Set hnpreq bit in the GOTGCTL register.
  65013. + */
  65014. +extern void dwc_otg_set_hnpreq(dwc_otg_core_if_t * core_if, uint32_t val);
  65015. +
  65016. +/**
  65017. + * Get Content of SNPSID register.
  65018. + */
  65019. +extern uint32_t dwc_otg_get_gsnpsid(dwc_otg_core_if_t * core_if);
  65020. +
  65021. +/**
  65022. + * Get current mode.
  65023. + * Returns 0 if in device mode, and 1 if in host mode.
  65024. + */
  65025. +extern uint32_t dwc_otg_get_mode(dwc_otg_core_if_t * core_if);
  65026. +
  65027. +/**
  65028. + * Get value of hnpcapable field in the GUSBCFG register
  65029. + */
  65030. +extern uint32_t dwc_otg_get_hnpcapable(dwc_otg_core_if_t * core_if);
  65031. +/**
  65032. + * Set value of hnpcapable field in the GUSBCFG register
  65033. + */
  65034. +extern void dwc_otg_set_hnpcapable(dwc_otg_core_if_t * core_if, uint32_t val);
  65035. +
  65036. +/**
  65037. + * Get value of srpcapable field in the GUSBCFG register
  65038. + */
  65039. +extern uint32_t dwc_otg_get_srpcapable(dwc_otg_core_if_t * core_if);
  65040. +/**
  65041. + * Set value of srpcapable field in the GUSBCFG register
  65042. + */
  65043. +extern void dwc_otg_set_srpcapable(dwc_otg_core_if_t * core_if, uint32_t val);
  65044. +
  65045. +/**
  65046. + * Get value of devspeed field in the DCFG register
  65047. + */
  65048. +extern uint32_t dwc_otg_get_devspeed(dwc_otg_core_if_t * core_if);
  65049. +/**
  65050. + * Set value of devspeed field in the DCFG register
  65051. + */
  65052. +extern void dwc_otg_set_devspeed(dwc_otg_core_if_t * core_if, uint32_t val);
  65053. +
  65054. +/**
  65055. + * Get the value of busconnected field from the HPRT0 register
  65056. + */
  65057. +extern uint32_t dwc_otg_get_busconnected(dwc_otg_core_if_t * core_if);
  65058. +
  65059. +/**
  65060. + * Gets the device enumeration Speed.
  65061. + */
  65062. +extern uint32_t dwc_otg_get_enumspeed(dwc_otg_core_if_t * core_if);
  65063. +
  65064. +/**
  65065. + * Get value of prtpwr field from the HPRT0 register
  65066. + */
  65067. +extern uint32_t dwc_otg_get_prtpower(dwc_otg_core_if_t * core_if);
  65068. +
  65069. +/**
  65070. + * Get value of flag indicating core state - hibernated or not
  65071. + */
  65072. +extern uint32_t dwc_otg_get_core_state(dwc_otg_core_if_t * core_if);
  65073. +
  65074. +/**
  65075. + * Set value of prtpwr field from the HPRT0 register
  65076. + */
  65077. +extern void dwc_otg_set_prtpower(dwc_otg_core_if_t * core_if, uint32_t val);
  65078. +
  65079. +/**
  65080. + * Get value of prtsusp field from the HPRT0 regsiter
  65081. + */
  65082. +extern uint32_t dwc_otg_get_prtsuspend(dwc_otg_core_if_t * core_if);
  65083. +/**
  65084. + * Set value of prtpwr field from the HPRT0 register
  65085. + */
  65086. +extern void dwc_otg_set_prtsuspend(dwc_otg_core_if_t * core_if, uint32_t val);
  65087. +
  65088. +/**
  65089. + * Get value of ModeChTimEn field from the HCFG regsiter
  65090. + */
  65091. +extern uint32_t dwc_otg_get_mode_ch_tim(dwc_otg_core_if_t * core_if);
  65092. +/**
  65093. + * Set value of ModeChTimEn field from the HCFG regsiter
  65094. + */
  65095. +extern void dwc_otg_set_mode_ch_tim(dwc_otg_core_if_t * core_if, uint32_t val);
  65096. +
  65097. +/**
  65098. + * Get value of Fram Interval field from the HFIR regsiter
  65099. + */
  65100. +extern uint32_t dwc_otg_get_fr_interval(dwc_otg_core_if_t * core_if);
  65101. +/**
  65102. + * Set value of Frame Interval field from the HFIR regsiter
  65103. + */
  65104. +extern void dwc_otg_set_fr_interval(dwc_otg_core_if_t * core_if, uint32_t val);
  65105. +
  65106. +/**
  65107. + * Set value of prtres field from the HPRT0 register
  65108. + *FIXME Remove?
  65109. + */
  65110. +extern void dwc_otg_set_prtresume(dwc_otg_core_if_t * core_if, uint32_t val);
  65111. +
  65112. +/**
  65113. + * Get value of rmtwkupsig bit in DCTL register
  65114. + */
  65115. +extern uint32_t dwc_otg_get_remotewakesig(dwc_otg_core_if_t * core_if);
  65116. +
  65117. +/**
  65118. + * Get value of prt_sleep_sts field from the GLPMCFG register
  65119. + */
  65120. +extern uint32_t dwc_otg_get_lpm_portsleepstatus(dwc_otg_core_if_t * core_if);
  65121. +
  65122. +/**
  65123. + * Get value of rem_wkup_en field from the GLPMCFG register
  65124. + */
  65125. +extern uint32_t dwc_otg_get_lpm_remotewakeenabled(dwc_otg_core_if_t * core_if);
  65126. +
  65127. +/**
  65128. + * Get value of appl_resp field from the GLPMCFG register
  65129. + */
  65130. +extern uint32_t dwc_otg_get_lpmresponse(dwc_otg_core_if_t * core_if);
  65131. +/**
  65132. + * Set value of appl_resp field from the GLPMCFG register
  65133. + */
  65134. +extern void dwc_otg_set_lpmresponse(dwc_otg_core_if_t * core_if, uint32_t val);
  65135. +
  65136. +/**
  65137. + * Get value of hsic_connect field from the GLPMCFG register
  65138. + */
  65139. +extern uint32_t dwc_otg_get_hsic_connect(dwc_otg_core_if_t * core_if);
  65140. +/**
  65141. + * Set value of hsic_connect field from the GLPMCFG register
  65142. + */
  65143. +extern void dwc_otg_set_hsic_connect(dwc_otg_core_if_t * core_if, uint32_t val);
  65144. +
  65145. +/**
  65146. + * Get value of inv_sel_hsic field from the GLPMCFG register.
  65147. + */
  65148. +extern uint32_t dwc_otg_get_inv_sel_hsic(dwc_otg_core_if_t * core_if);
  65149. +/**
  65150. + * Set value of inv_sel_hsic field from the GLPMFG register.
  65151. + */
  65152. +extern void dwc_otg_set_inv_sel_hsic(dwc_otg_core_if_t * core_if, uint32_t val);
  65153. +
  65154. +/*
  65155. + * Some functions for accessing registers
  65156. + */
  65157. +
  65158. +/**
  65159. + * GOTGCTL register
  65160. + */
  65161. +extern uint32_t dwc_otg_get_gotgctl(dwc_otg_core_if_t * core_if);
  65162. +extern void dwc_otg_set_gotgctl(dwc_otg_core_if_t * core_if, uint32_t val);
  65163. +
  65164. +/**
  65165. + * GUSBCFG register
  65166. + */
  65167. +extern uint32_t dwc_otg_get_gusbcfg(dwc_otg_core_if_t * core_if);
  65168. +extern void dwc_otg_set_gusbcfg(dwc_otg_core_if_t * core_if, uint32_t val);
  65169. +
  65170. +/**
  65171. + * GRXFSIZ register
  65172. + */
  65173. +extern uint32_t dwc_otg_get_grxfsiz(dwc_otg_core_if_t * core_if);
  65174. +extern void dwc_otg_set_grxfsiz(dwc_otg_core_if_t * core_if, uint32_t val);
  65175. +
  65176. +/**
  65177. + * GNPTXFSIZ register
  65178. + */
  65179. +extern uint32_t dwc_otg_get_gnptxfsiz(dwc_otg_core_if_t * core_if);
  65180. +extern void dwc_otg_set_gnptxfsiz(dwc_otg_core_if_t * core_if, uint32_t val);
  65181. +
  65182. +extern uint32_t dwc_otg_get_gpvndctl(dwc_otg_core_if_t * core_if);
  65183. +extern void dwc_otg_set_gpvndctl(dwc_otg_core_if_t * core_if, uint32_t val);
  65184. +
  65185. +/**
  65186. + * GGPIO register
  65187. + */
  65188. +extern uint32_t dwc_otg_get_ggpio(dwc_otg_core_if_t * core_if);
  65189. +extern void dwc_otg_set_ggpio(dwc_otg_core_if_t * core_if, uint32_t val);
  65190. +
  65191. +/**
  65192. + * GUID register
  65193. + */
  65194. +extern uint32_t dwc_otg_get_guid(dwc_otg_core_if_t * core_if);
  65195. +extern void dwc_otg_set_guid(dwc_otg_core_if_t * core_if, uint32_t val);
  65196. +
  65197. +/**
  65198. + * HPRT0 register
  65199. + */
  65200. +extern uint32_t dwc_otg_get_hprt0(dwc_otg_core_if_t * core_if);
  65201. +extern void dwc_otg_set_hprt0(dwc_otg_core_if_t * core_if, uint32_t val);
  65202. +
  65203. +/**
  65204. + * GHPTXFSIZE
  65205. + */
  65206. +extern uint32_t dwc_otg_get_hptxfsiz(dwc_otg_core_if_t * core_if);
  65207. +
  65208. +/** @} */
  65209. +
  65210. +#endif /* __DWC_CORE_IF_H__ */
  65211. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_dbg.h linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_dbg.h
  65212. --- linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_dbg.h 1970-01-01 01:00:00.000000000 +0100
  65213. +++ linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_dbg.h 2014-02-17 22:41:01.000000000 +0100
  65214. @@ -0,0 +1,117 @@
  65215. +/* ==========================================================================
  65216. + *
  65217. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  65218. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  65219. + * otherwise expressly agreed to in writing between Synopsys and you.
  65220. + *
  65221. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  65222. + * any End User Software License Agreement or Agreement for Licensed Product
  65223. + * with Synopsys or any supplement thereto. You are permitted to use and
  65224. + * redistribute this Software in source and binary forms, with or without
  65225. + * modification, provided that redistributions of source code must retain this
  65226. + * notice. You may not view, use, disclose, copy or distribute this file or
  65227. + * any information contained herein except pursuant to this license grant from
  65228. + * Synopsys. If you do not agree with this notice, including the disclaimer
  65229. + * below, then you are not authorized to use the Software.
  65230. + *
  65231. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  65232. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  65233. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  65234. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  65235. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  65236. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  65237. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  65238. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  65239. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  65240. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  65241. + * DAMAGE.
  65242. + * ========================================================================== */
  65243. +
  65244. +#ifndef __DWC_OTG_DBG_H__
  65245. +#define __DWC_OTG_DBG_H__
  65246. +
  65247. +/** @file
  65248. + * This file defines debug levels.
  65249. + * Debugging support vanishes in non-debug builds.
  65250. + */
  65251. +
  65252. +/**
  65253. + * The Debug Level bit-mask variable.
  65254. + */
  65255. +extern uint32_t g_dbg_lvl;
  65256. +/**
  65257. + * Set the Debug Level variable.
  65258. + */
  65259. +static inline uint32_t SET_DEBUG_LEVEL(const uint32_t new)
  65260. +{
  65261. + uint32_t old = g_dbg_lvl;
  65262. + g_dbg_lvl = new;
  65263. + return old;
  65264. +}
  65265. +
  65266. +#define DBG_USER (0x1)
  65267. +/** When debug level has the DBG_CIL bit set, display CIL Debug messages. */
  65268. +#define DBG_CIL (0x2)
  65269. +/** When debug level has the DBG_CILV bit set, display CIL Verbose debug
  65270. + * messages */
  65271. +#define DBG_CILV (0x20)
  65272. +/** When debug level has the DBG_PCD bit set, display PCD (Device) debug
  65273. + * messages */
  65274. +#define DBG_PCD (0x4)
  65275. +/** When debug level has the DBG_PCDV set, display PCD (Device) Verbose debug
  65276. + * messages */
  65277. +#define DBG_PCDV (0x40)
  65278. +/** When debug level has the DBG_HCD bit set, display Host debug messages */
  65279. +#define DBG_HCD (0x8)
  65280. +/** When debug level has the DBG_HCDV bit set, display Verbose Host debug
  65281. + * messages */
  65282. +#define DBG_HCDV (0x80)
  65283. +/** When debug level has the DBG_HCD_URB bit set, display enqueued URBs in host
  65284. + * mode. */
  65285. +#define DBG_HCD_URB (0x800)
  65286. +/** When debug level has the DBG_HCDI bit set, display host interrupt
  65287. + * messages. */
  65288. +#define DBG_HCDI (0x1000)
  65289. +
  65290. +/** When debug level has any bit set, display debug messages */
  65291. +#define DBG_ANY (0xFF)
  65292. +
  65293. +/** All debug messages off */
  65294. +#define DBG_OFF 0
  65295. +
  65296. +/** Prefix string for DWC_DEBUG print macros. */
  65297. +#define USB_DWC "DWC_otg: "
  65298. +
  65299. +/**
  65300. + * Print a debug message when the Global debug level variable contains
  65301. + * the bit defined in <code>lvl</code>.
  65302. + *
  65303. + * @param[in] lvl - Debug level, use one of the DBG_ constants above.
  65304. + * @param[in] x - like printf
  65305. + *
  65306. + * Example:<p>
  65307. + * <code>
  65308. + * DWC_DEBUGPL( DBG_ANY, "%s(%p)\n", __func__, _reg_base_addr);
  65309. + * </code>
  65310. + * <br>
  65311. + * results in:<br>
  65312. + * <code>
  65313. + * usb-DWC_otg: dwc_otg_cil_init(ca867000)
  65314. + * </code>
  65315. + */
  65316. +#ifdef DEBUG
  65317. +
  65318. +# define DWC_DEBUGPL(lvl, x...) do{ if ((lvl)&g_dbg_lvl)__DWC_DEBUG(USB_DWC x ); }while(0)
  65319. +# define DWC_DEBUGP(x...) DWC_DEBUGPL(DBG_ANY, x )
  65320. +
  65321. +# define CHK_DEBUG_LEVEL(level) ((level) & g_dbg_lvl)
  65322. +
  65323. +#else
  65324. +
  65325. +# define DWC_DEBUGPL(lvl, x...) do{}while(0)
  65326. +# define DWC_DEBUGP(x...)
  65327. +
  65328. +# define CHK_DEBUG_LEVEL(level) (0)
  65329. +
  65330. +#endif /*DEBUG*/
  65331. +#endif
  65332. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_driver.c linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_driver.c
  65333. --- linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_driver.c 1970-01-01 01:00:00.000000000 +0100
  65334. +++ linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_driver.c 2014-02-17 22:41:01.000000000 +0100
  65335. @@ -0,0 +1,1742 @@
  65336. +/* ==========================================================================
  65337. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_driver.c $
  65338. + * $Revision: #92 $
  65339. + * $Date: 2012/08/10 $
  65340. + * $Change: 2047372 $
  65341. + *
  65342. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  65343. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  65344. + * otherwise expressly agreed to in writing between Synopsys and you.
  65345. + *
  65346. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  65347. + * any End User Software License Agreement or Agreement for Licensed Product
  65348. + * with Synopsys or any supplement thereto. You are permitted to use and
  65349. + * redistribute this Software in source and binary forms, with or without
  65350. + * modification, provided that redistributions of source code must retain this
  65351. + * notice. You may not view, use, disclose, copy or distribute this file or
  65352. + * any information contained herein except pursuant to this license grant from
  65353. + * Synopsys. If you do not agree with this notice, including the disclaimer
  65354. + * below, then you are not authorized to use the Software.
  65355. + *
  65356. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  65357. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  65358. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  65359. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  65360. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  65361. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  65362. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  65363. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  65364. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  65365. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  65366. + * DAMAGE.
  65367. + * ========================================================================== */
  65368. +
  65369. +/** @file
  65370. + * The dwc_otg_driver module provides the initialization and cleanup entry
  65371. + * points for the DWC_otg driver. This module will be dynamically installed
  65372. + * after Linux is booted using the insmod command. When the module is
  65373. + * installed, the dwc_otg_driver_init function is called. When the module is
  65374. + * removed (using rmmod), the dwc_otg_driver_cleanup function is called.
  65375. + *
  65376. + * This module also defines a data structure for the dwc_otg_driver, which is
  65377. + * used in conjunction with the standard ARM lm_device structure. These
  65378. + * structures allow the OTG driver to comply with the standard Linux driver
  65379. + * model in which devices and drivers are registered with a bus driver. This
  65380. + * has the benefit that Linux can expose attributes of the driver and device
  65381. + * in its special sysfs file system. Users can then read or write files in
  65382. + * this file system to perform diagnostics on the driver components or the
  65383. + * device.
  65384. + */
  65385. +
  65386. +#include "dwc_otg_os_dep.h"
  65387. +#include "dwc_os.h"
  65388. +#include "dwc_otg_dbg.h"
  65389. +#include "dwc_otg_driver.h"
  65390. +#include "dwc_otg_attr.h"
  65391. +#include "dwc_otg_core_if.h"
  65392. +#include "dwc_otg_pcd_if.h"
  65393. +#include "dwc_otg_hcd_if.h"
  65394. +
  65395. +#define DWC_DRIVER_VERSION "3.00a 10-AUG-2012"
  65396. +#define DWC_DRIVER_DESC "HS OTG USB Controller driver"
  65397. +
  65398. +bool microframe_schedule=true;
  65399. +
  65400. +static const char dwc_driver_name[] = "dwc_otg";
  65401. +
  65402. +extern void* dummy_send;
  65403. +
  65404. +extern int pcd_init(
  65405. +#ifdef LM_INTERFACE
  65406. + struct lm_device *_dev
  65407. +#elif defined(PCI_INTERFACE)
  65408. + struct pci_dev *_dev
  65409. +#elif defined(PLATFORM_INTERFACE)
  65410. + struct platform_device *dev
  65411. +#endif
  65412. + );
  65413. +extern int hcd_init(
  65414. +#ifdef LM_INTERFACE
  65415. + struct lm_device *_dev
  65416. +#elif defined(PCI_INTERFACE)
  65417. + struct pci_dev *_dev
  65418. +#elif defined(PLATFORM_INTERFACE)
  65419. + struct platform_device *dev
  65420. +#endif
  65421. + );
  65422. +
  65423. +extern int pcd_remove(
  65424. +#ifdef LM_INTERFACE
  65425. + struct lm_device *_dev
  65426. +#elif defined(PCI_INTERFACE)
  65427. + struct pci_dev *_dev
  65428. +#elif defined(PLATFORM_INTERFACE)
  65429. + struct platform_device *_dev
  65430. +#endif
  65431. + );
  65432. +
  65433. +extern void hcd_remove(
  65434. +#ifdef LM_INTERFACE
  65435. + struct lm_device *_dev
  65436. +#elif defined(PCI_INTERFACE)
  65437. + struct pci_dev *_dev
  65438. +#elif defined(PLATFORM_INTERFACE)
  65439. + struct platform_device *_dev
  65440. +#endif
  65441. + );
  65442. +
  65443. +extern void dwc_otg_adp_start(dwc_otg_core_if_t * core_if, uint8_t is_host);
  65444. +
  65445. +/*-------------------------------------------------------------------------*/
  65446. +/* Encapsulate the module parameter settings */
  65447. +
  65448. +struct dwc_otg_driver_module_params {
  65449. + int32_t opt;
  65450. + int32_t otg_cap;
  65451. + int32_t dma_enable;
  65452. + int32_t dma_desc_enable;
  65453. + int32_t dma_burst_size;
  65454. + int32_t speed;
  65455. + int32_t host_support_fs_ls_low_power;
  65456. + int32_t host_ls_low_power_phy_clk;
  65457. + int32_t enable_dynamic_fifo;
  65458. + int32_t data_fifo_size;
  65459. + int32_t dev_rx_fifo_size;
  65460. + int32_t dev_nperio_tx_fifo_size;
  65461. + uint32_t dev_perio_tx_fifo_size[MAX_PERIO_FIFOS];
  65462. + int32_t host_rx_fifo_size;
  65463. + int32_t host_nperio_tx_fifo_size;
  65464. + int32_t host_perio_tx_fifo_size;
  65465. + int32_t max_transfer_size;
  65466. + int32_t max_packet_count;
  65467. + int32_t host_channels;
  65468. + int32_t dev_endpoints;
  65469. + int32_t phy_type;
  65470. + int32_t phy_utmi_width;
  65471. + int32_t phy_ulpi_ddr;
  65472. + int32_t phy_ulpi_ext_vbus;
  65473. + int32_t i2c_enable;
  65474. + int32_t ulpi_fs_ls;
  65475. + int32_t ts_dline;
  65476. + int32_t en_multiple_tx_fifo;
  65477. + uint32_t dev_tx_fifo_size[MAX_TX_FIFOS];
  65478. + uint32_t thr_ctl;
  65479. + uint32_t tx_thr_length;
  65480. + uint32_t rx_thr_length;
  65481. + int32_t pti_enable;
  65482. + int32_t mpi_enable;
  65483. + int32_t lpm_enable;
  65484. + int32_t ic_usb_cap;
  65485. + int32_t ahb_thr_ratio;
  65486. + int32_t power_down;
  65487. + int32_t reload_ctl;
  65488. + int32_t dev_out_nak;
  65489. + int32_t cont_on_bna;
  65490. + int32_t ahb_single;
  65491. + int32_t otg_ver;
  65492. + int32_t adp_enable;
  65493. +};
  65494. +
  65495. +static struct dwc_otg_driver_module_params dwc_otg_module_params = {
  65496. + .opt = -1,
  65497. + .otg_cap = -1,
  65498. + .dma_enable = -1,
  65499. + .dma_desc_enable = -1,
  65500. + .dma_burst_size = -1,
  65501. + .speed = -1,
  65502. + .host_support_fs_ls_low_power = -1,
  65503. + .host_ls_low_power_phy_clk = -1,
  65504. + .enable_dynamic_fifo = -1,
  65505. + .data_fifo_size = -1,
  65506. + .dev_rx_fifo_size = -1,
  65507. + .dev_nperio_tx_fifo_size = -1,
  65508. + .dev_perio_tx_fifo_size = {
  65509. + /* dev_perio_tx_fifo_size_1 */
  65510. + -1,
  65511. + -1,
  65512. + -1,
  65513. + -1,
  65514. + -1,
  65515. + -1,
  65516. + -1,
  65517. + -1,
  65518. + -1,
  65519. + -1,
  65520. + -1,
  65521. + -1,
  65522. + -1,
  65523. + -1,
  65524. + -1
  65525. + /* 15 */
  65526. + },
  65527. + .host_rx_fifo_size = -1,
  65528. + .host_nperio_tx_fifo_size = -1,
  65529. + .host_perio_tx_fifo_size = -1,
  65530. + .max_transfer_size = -1,
  65531. + .max_packet_count = -1,
  65532. + .host_channels = -1,
  65533. + .dev_endpoints = -1,
  65534. + .phy_type = -1,
  65535. + .phy_utmi_width = -1,
  65536. + .phy_ulpi_ddr = -1,
  65537. + .phy_ulpi_ext_vbus = -1,
  65538. + .i2c_enable = -1,
  65539. + .ulpi_fs_ls = -1,
  65540. + .ts_dline = -1,
  65541. + .en_multiple_tx_fifo = -1,
  65542. + .dev_tx_fifo_size = {
  65543. + /* dev_tx_fifo_size */
  65544. + -1,
  65545. + -1,
  65546. + -1,
  65547. + -1,
  65548. + -1,
  65549. + -1,
  65550. + -1,
  65551. + -1,
  65552. + -1,
  65553. + -1,
  65554. + -1,
  65555. + -1,
  65556. + -1,
  65557. + -1,
  65558. + -1
  65559. + /* 15 */
  65560. + },
  65561. + .thr_ctl = -1,
  65562. + .tx_thr_length = -1,
  65563. + .rx_thr_length = -1,
  65564. + .pti_enable = -1,
  65565. + .mpi_enable = -1,
  65566. + .lpm_enable = 0,
  65567. + .ic_usb_cap = -1,
  65568. + .ahb_thr_ratio = -1,
  65569. + .power_down = -1,
  65570. + .reload_ctl = -1,
  65571. + .dev_out_nak = -1,
  65572. + .cont_on_bna = -1,
  65573. + .ahb_single = -1,
  65574. + .otg_ver = -1,
  65575. + .adp_enable = -1,
  65576. +};
  65577. +
  65578. +//Global variable to switch the fiq fix on or off (declared in bcm2708.c)
  65579. +extern bool fiq_fix_enable;
  65580. +// Global variable to enable the split transaction fix
  65581. +bool fiq_split_enable = true;
  65582. +//Global variable to switch the nak holdoff on or off
  65583. +bool nak_holdoff_enable = true;
  65584. +
  65585. +
  65586. +/**
  65587. + * This function shows the Driver Version.
  65588. + */
  65589. +static ssize_t version_show(struct device_driver *dev, char *buf)
  65590. +{
  65591. + return snprintf(buf, sizeof(DWC_DRIVER_VERSION) + 2, "%s\n",
  65592. + DWC_DRIVER_VERSION);
  65593. +}
  65594. +
  65595. +static DRIVER_ATTR(version, S_IRUGO, version_show, NULL);
  65596. +
  65597. +/**
  65598. + * Global Debug Level Mask.
  65599. + */
  65600. +uint32_t g_dbg_lvl = 0; /* OFF */
  65601. +
  65602. +/**
  65603. + * This function shows the driver Debug Level.
  65604. + */
  65605. +static ssize_t dbg_level_show(struct device_driver *drv, char *buf)
  65606. +{
  65607. + return sprintf(buf, "0x%0x\n", g_dbg_lvl);
  65608. +}
  65609. +
  65610. +/**
  65611. + * This function stores the driver Debug Level.
  65612. + */
  65613. +static ssize_t dbg_level_store(struct device_driver *drv, const char *buf,
  65614. + size_t count)
  65615. +{
  65616. + g_dbg_lvl = simple_strtoul(buf, NULL, 16);
  65617. + return count;
  65618. +}
  65619. +
  65620. +static DRIVER_ATTR(debuglevel, S_IRUGO | S_IWUSR, dbg_level_show,
  65621. + dbg_level_store);
  65622. +
  65623. +/**
  65624. + * This function is called during module intialization
  65625. + * to pass module parameters to the DWC_OTG CORE.
  65626. + */
  65627. +static int set_parameters(dwc_otg_core_if_t * core_if)
  65628. +{
  65629. + int retval = 0;
  65630. + int i;
  65631. +
  65632. + if (dwc_otg_module_params.otg_cap != -1) {
  65633. + retval +=
  65634. + dwc_otg_set_param_otg_cap(core_if,
  65635. + dwc_otg_module_params.otg_cap);
  65636. + }
  65637. + if (dwc_otg_module_params.dma_enable != -1) {
  65638. + retval +=
  65639. + dwc_otg_set_param_dma_enable(core_if,
  65640. + dwc_otg_module_params.
  65641. + dma_enable);
  65642. + }
  65643. + if (dwc_otg_module_params.dma_desc_enable != -1) {
  65644. + retval +=
  65645. + dwc_otg_set_param_dma_desc_enable(core_if,
  65646. + dwc_otg_module_params.
  65647. + dma_desc_enable);
  65648. + }
  65649. + if (dwc_otg_module_params.opt != -1) {
  65650. + retval +=
  65651. + dwc_otg_set_param_opt(core_if, dwc_otg_module_params.opt);
  65652. + }
  65653. + if (dwc_otg_module_params.dma_burst_size != -1) {
  65654. + retval +=
  65655. + dwc_otg_set_param_dma_burst_size(core_if,
  65656. + dwc_otg_module_params.
  65657. + dma_burst_size);
  65658. + }
  65659. + if (dwc_otg_module_params.host_support_fs_ls_low_power != -1) {
  65660. + retval +=
  65661. + dwc_otg_set_param_host_support_fs_ls_low_power(core_if,
  65662. + dwc_otg_module_params.
  65663. + host_support_fs_ls_low_power);
  65664. + }
  65665. + if (dwc_otg_module_params.enable_dynamic_fifo != -1) {
  65666. + retval +=
  65667. + dwc_otg_set_param_enable_dynamic_fifo(core_if,
  65668. + dwc_otg_module_params.
  65669. + enable_dynamic_fifo);
  65670. + }
  65671. + if (dwc_otg_module_params.data_fifo_size != -1) {
  65672. + retval +=
  65673. + dwc_otg_set_param_data_fifo_size(core_if,
  65674. + dwc_otg_module_params.
  65675. + data_fifo_size);
  65676. + }
  65677. + if (dwc_otg_module_params.dev_rx_fifo_size != -1) {
  65678. + retval +=
  65679. + dwc_otg_set_param_dev_rx_fifo_size(core_if,
  65680. + dwc_otg_module_params.
  65681. + dev_rx_fifo_size);
  65682. + }
  65683. + if (dwc_otg_module_params.dev_nperio_tx_fifo_size != -1) {
  65684. + retval +=
  65685. + dwc_otg_set_param_dev_nperio_tx_fifo_size(core_if,
  65686. + dwc_otg_module_params.
  65687. + dev_nperio_tx_fifo_size);
  65688. + }
  65689. + if (dwc_otg_module_params.host_rx_fifo_size != -1) {
  65690. + retval +=
  65691. + dwc_otg_set_param_host_rx_fifo_size(core_if,
  65692. + dwc_otg_module_params.host_rx_fifo_size);
  65693. + }
  65694. + if (dwc_otg_module_params.host_nperio_tx_fifo_size != -1) {
  65695. + retval +=
  65696. + dwc_otg_set_param_host_nperio_tx_fifo_size(core_if,
  65697. + dwc_otg_module_params.
  65698. + host_nperio_tx_fifo_size);
  65699. + }
  65700. + if (dwc_otg_module_params.host_perio_tx_fifo_size != -1) {
  65701. + retval +=
  65702. + dwc_otg_set_param_host_perio_tx_fifo_size(core_if,
  65703. + dwc_otg_module_params.
  65704. + host_perio_tx_fifo_size);
  65705. + }
  65706. + if (dwc_otg_module_params.max_transfer_size != -1) {
  65707. + retval +=
  65708. + dwc_otg_set_param_max_transfer_size(core_if,
  65709. + dwc_otg_module_params.
  65710. + max_transfer_size);
  65711. + }
  65712. + if (dwc_otg_module_params.max_packet_count != -1) {
  65713. + retval +=
  65714. + dwc_otg_set_param_max_packet_count(core_if,
  65715. + dwc_otg_module_params.
  65716. + max_packet_count);
  65717. + }
  65718. + if (dwc_otg_module_params.host_channels != -1) {
  65719. + retval +=
  65720. + dwc_otg_set_param_host_channels(core_if,
  65721. + dwc_otg_module_params.
  65722. + host_channels);
  65723. + }
  65724. + if (dwc_otg_module_params.dev_endpoints != -1) {
  65725. + retval +=
  65726. + dwc_otg_set_param_dev_endpoints(core_if,
  65727. + dwc_otg_module_params.
  65728. + dev_endpoints);
  65729. + }
  65730. + if (dwc_otg_module_params.phy_type != -1) {
  65731. + retval +=
  65732. + dwc_otg_set_param_phy_type(core_if,
  65733. + dwc_otg_module_params.phy_type);
  65734. + }
  65735. + if (dwc_otg_module_params.speed != -1) {
  65736. + retval +=
  65737. + dwc_otg_set_param_speed(core_if,
  65738. + dwc_otg_module_params.speed);
  65739. + }
  65740. + if (dwc_otg_module_params.host_ls_low_power_phy_clk != -1) {
  65741. + retval +=
  65742. + dwc_otg_set_param_host_ls_low_power_phy_clk(core_if,
  65743. + dwc_otg_module_params.
  65744. + host_ls_low_power_phy_clk);
  65745. + }
  65746. + if (dwc_otg_module_params.phy_ulpi_ddr != -1) {
  65747. + retval +=
  65748. + dwc_otg_set_param_phy_ulpi_ddr(core_if,
  65749. + dwc_otg_module_params.
  65750. + phy_ulpi_ddr);
  65751. + }
  65752. + if (dwc_otg_module_params.phy_ulpi_ext_vbus != -1) {
  65753. + retval +=
  65754. + dwc_otg_set_param_phy_ulpi_ext_vbus(core_if,
  65755. + dwc_otg_module_params.
  65756. + phy_ulpi_ext_vbus);
  65757. + }
  65758. + if (dwc_otg_module_params.phy_utmi_width != -1) {
  65759. + retval +=
  65760. + dwc_otg_set_param_phy_utmi_width(core_if,
  65761. + dwc_otg_module_params.
  65762. + phy_utmi_width);
  65763. + }
  65764. + if (dwc_otg_module_params.ulpi_fs_ls != -1) {
  65765. + retval +=
  65766. + dwc_otg_set_param_ulpi_fs_ls(core_if,
  65767. + dwc_otg_module_params.ulpi_fs_ls);
  65768. + }
  65769. + if (dwc_otg_module_params.ts_dline != -1) {
  65770. + retval +=
  65771. + dwc_otg_set_param_ts_dline(core_if,
  65772. + dwc_otg_module_params.ts_dline);
  65773. + }
  65774. + if (dwc_otg_module_params.i2c_enable != -1) {
  65775. + retval +=
  65776. + dwc_otg_set_param_i2c_enable(core_if,
  65777. + dwc_otg_module_params.
  65778. + i2c_enable);
  65779. + }
  65780. + if (dwc_otg_module_params.en_multiple_tx_fifo != -1) {
  65781. + retval +=
  65782. + dwc_otg_set_param_en_multiple_tx_fifo(core_if,
  65783. + dwc_otg_module_params.
  65784. + en_multiple_tx_fifo);
  65785. + }
  65786. + for (i = 0; i < 15; i++) {
  65787. + if (dwc_otg_module_params.dev_perio_tx_fifo_size[i] != -1) {
  65788. + retval +=
  65789. + dwc_otg_set_param_dev_perio_tx_fifo_size(core_if,
  65790. + dwc_otg_module_params.
  65791. + dev_perio_tx_fifo_size
  65792. + [i], i);
  65793. + }
  65794. + }
  65795. +
  65796. + for (i = 0; i < 15; i++) {
  65797. + if (dwc_otg_module_params.dev_tx_fifo_size[i] != -1) {
  65798. + retval += dwc_otg_set_param_dev_tx_fifo_size(core_if,
  65799. + dwc_otg_module_params.
  65800. + dev_tx_fifo_size
  65801. + [i], i);
  65802. + }
  65803. + }
  65804. + if (dwc_otg_module_params.thr_ctl != -1) {
  65805. + retval +=
  65806. + dwc_otg_set_param_thr_ctl(core_if,
  65807. + dwc_otg_module_params.thr_ctl);
  65808. + }
  65809. + if (dwc_otg_module_params.mpi_enable != -1) {
  65810. + retval +=
  65811. + dwc_otg_set_param_mpi_enable(core_if,
  65812. + dwc_otg_module_params.
  65813. + mpi_enable);
  65814. + }
  65815. + if (dwc_otg_module_params.pti_enable != -1) {
  65816. + retval +=
  65817. + dwc_otg_set_param_pti_enable(core_if,
  65818. + dwc_otg_module_params.
  65819. + pti_enable);
  65820. + }
  65821. + if (dwc_otg_module_params.lpm_enable != -1) {
  65822. + retval +=
  65823. + dwc_otg_set_param_lpm_enable(core_if,
  65824. + dwc_otg_module_params.
  65825. + lpm_enable);
  65826. + }
  65827. + if (dwc_otg_module_params.ic_usb_cap != -1) {
  65828. + retval +=
  65829. + dwc_otg_set_param_ic_usb_cap(core_if,
  65830. + dwc_otg_module_params.
  65831. + ic_usb_cap);
  65832. + }
  65833. + if (dwc_otg_module_params.tx_thr_length != -1) {
  65834. + retval +=
  65835. + dwc_otg_set_param_tx_thr_length(core_if,
  65836. + dwc_otg_module_params.tx_thr_length);
  65837. + }
  65838. + if (dwc_otg_module_params.rx_thr_length != -1) {
  65839. + retval +=
  65840. + dwc_otg_set_param_rx_thr_length(core_if,
  65841. + dwc_otg_module_params.
  65842. + rx_thr_length);
  65843. + }
  65844. + if (dwc_otg_module_params.ahb_thr_ratio != -1) {
  65845. + retval +=
  65846. + dwc_otg_set_param_ahb_thr_ratio(core_if,
  65847. + dwc_otg_module_params.ahb_thr_ratio);
  65848. + }
  65849. + if (dwc_otg_module_params.power_down != -1) {
  65850. + retval +=
  65851. + dwc_otg_set_param_power_down(core_if,
  65852. + dwc_otg_module_params.power_down);
  65853. + }
  65854. + if (dwc_otg_module_params.reload_ctl != -1) {
  65855. + retval +=
  65856. + dwc_otg_set_param_reload_ctl(core_if,
  65857. + dwc_otg_module_params.reload_ctl);
  65858. + }
  65859. +
  65860. + if (dwc_otg_module_params.dev_out_nak != -1) {
  65861. + retval +=
  65862. + dwc_otg_set_param_dev_out_nak(core_if,
  65863. + dwc_otg_module_params.dev_out_nak);
  65864. + }
  65865. +
  65866. + if (dwc_otg_module_params.cont_on_bna != -1) {
  65867. + retval +=
  65868. + dwc_otg_set_param_cont_on_bna(core_if,
  65869. + dwc_otg_module_params.cont_on_bna);
  65870. + }
  65871. +
  65872. + if (dwc_otg_module_params.ahb_single != -1) {
  65873. + retval +=
  65874. + dwc_otg_set_param_ahb_single(core_if,
  65875. + dwc_otg_module_params.ahb_single);
  65876. + }
  65877. +
  65878. + if (dwc_otg_module_params.otg_ver != -1) {
  65879. + retval +=
  65880. + dwc_otg_set_param_otg_ver(core_if,
  65881. + dwc_otg_module_params.otg_ver);
  65882. + }
  65883. + if (dwc_otg_module_params.adp_enable != -1) {
  65884. + retval +=
  65885. + dwc_otg_set_param_adp_enable(core_if,
  65886. + dwc_otg_module_params.
  65887. + adp_enable);
  65888. + }
  65889. + return retval;
  65890. +}
  65891. +
  65892. +/**
  65893. + * This function is the top level interrupt handler for the Common
  65894. + * (Device and host modes) interrupts.
  65895. + */
  65896. +static irqreturn_t dwc_otg_common_irq(int irq, void *dev)
  65897. +{
  65898. + int32_t retval = IRQ_NONE;
  65899. +
  65900. + retval = dwc_otg_handle_common_intr(dev);
  65901. + if (retval != 0) {
  65902. + S3C2410X_CLEAR_EINTPEND();
  65903. + }
  65904. + return IRQ_RETVAL(retval);
  65905. +}
  65906. +
  65907. +/**
  65908. + * This function is called when a lm_device is unregistered with the
  65909. + * dwc_otg_driver. This happens, for example, when the rmmod command is
  65910. + * executed. The device may or may not be electrically present. If it is
  65911. + * present, the driver stops device processing. Any resources used on behalf
  65912. + * of this device are freed.
  65913. + *
  65914. + * @param _dev
  65915. + */
  65916. +#ifdef LM_INTERFACE
  65917. +#define REM_RETVAL(n)
  65918. +static void dwc_otg_driver_remove( struct lm_device *_dev )
  65919. +{ dwc_otg_device_t *otg_dev = lm_get_drvdata(_dev);
  65920. +#elif defined(PCI_INTERFACE)
  65921. +#define REM_RETVAL(n)
  65922. +static void dwc_otg_driver_remove( struct pci_dev *_dev )
  65923. +{ dwc_otg_device_t *otg_dev = pci_get_drvdata(_dev);
  65924. +#elif defined(PLATFORM_INTERFACE)
  65925. +#define REM_RETVAL(n) n
  65926. +static int dwc_otg_driver_remove( struct platform_device *_dev )
  65927. +{ dwc_otg_device_t *otg_dev = platform_get_drvdata(_dev);
  65928. +#endif
  65929. +
  65930. + DWC_DEBUGPL(DBG_ANY, "%s(%p) otg_dev %p\n", __func__, _dev, otg_dev);
  65931. +
  65932. + if (!otg_dev) {
  65933. + /* Memory allocation for the dwc_otg_device failed. */
  65934. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev NULL!\n", __func__);
  65935. + return REM_RETVAL(-ENOMEM);
  65936. + }
  65937. +#ifndef DWC_DEVICE_ONLY
  65938. + if (otg_dev->hcd) {
  65939. + hcd_remove(_dev);
  65940. + } else {
  65941. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->hcd NULL!\n", __func__);
  65942. + return REM_RETVAL(-EINVAL);
  65943. + }
  65944. +#endif
  65945. +
  65946. +#ifndef DWC_HOST_ONLY
  65947. + if (otg_dev->pcd) {
  65948. + pcd_remove(_dev);
  65949. + } else {
  65950. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->pcd NULL!\n", __func__);
  65951. + return REM_RETVAL(-EINVAL);
  65952. + }
  65953. +#endif
  65954. + /*
  65955. + * Free the IRQ
  65956. + */
  65957. + if (otg_dev->common_irq_installed) {
  65958. +#ifdef PLATFORM_INTERFACE
  65959. + free_irq(platform_get_irq(_dev, 0), otg_dev);
  65960. +#else
  65961. + free_irq(_dev->irq, otg_dev);
  65962. +#endif
  65963. + } else {
  65964. + DWC_DEBUGPL(DBG_ANY, "%s: There is no installed irq!\n", __func__);
  65965. + return REM_RETVAL(-ENXIO);
  65966. + }
  65967. +
  65968. + if (otg_dev->core_if) {
  65969. + dwc_otg_cil_remove(otg_dev->core_if);
  65970. + } else {
  65971. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->core_if NULL!\n", __func__);
  65972. + return REM_RETVAL(-ENXIO);
  65973. + }
  65974. +
  65975. + /*
  65976. + * Remove the device attributes
  65977. + */
  65978. + dwc_otg_attr_remove(_dev);
  65979. +
  65980. + /*
  65981. + * Return the memory.
  65982. + */
  65983. + if (otg_dev->os_dep.base) {
  65984. + iounmap(otg_dev->os_dep.base);
  65985. + }
  65986. + DWC_FREE(otg_dev);
  65987. +
  65988. + /*
  65989. + * Clear the drvdata pointer.
  65990. + */
  65991. +#ifdef LM_INTERFACE
  65992. + lm_set_drvdata(_dev, 0);
  65993. +#elif defined(PCI_INTERFACE)
  65994. + release_mem_region(otg_dev->os_dep.rsrc_start,
  65995. + otg_dev->os_dep.rsrc_len);
  65996. + pci_set_drvdata(_dev, 0);
  65997. +#elif defined(PLATFORM_INTERFACE)
  65998. + platform_set_drvdata(_dev, 0);
  65999. +#endif
  66000. + return REM_RETVAL(0);
  66001. +}
  66002. +
  66003. +/**
  66004. + * This function is called when an lm_device is bound to a
  66005. + * dwc_otg_driver. It creates the driver components required to
  66006. + * control the device (CIL, HCD, and PCD) and it initializes the
  66007. + * device. The driver components are stored in a dwc_otg_device
  66008. + * structure. A reference to the dwc_otg_device is saved in the
  66009. + * lm_device. This allows the driver to access the dwc_otg_device
  66010. + * structure on subsequent calls to driver methods for this device.
  66011. + *
  66012. + * @param _dev Bus device
  66013. + */
  66014. +static int dwc_otg_driver_probe(
  66015. +#ifdef LM_INTERFACE
  66016. + struct lm_device *_dev
  66017. +#elif defined(PCI_INTERFACE)
  66018. + struct pci_dev *_dev,
  66019. + const struct pci_device_id *id
  66020. +#elif defined(PLATFORM_INTERFACE)
  66021. + struct platform_device *_dev
  66022. +#endif
  66023. + )
  66024. +{
  66025. + int retval = 0;
  66026. + dwc_otg_device_t *dwc_otg_device;
  66027. + int devirq;
  66028. +
  66029. + dev_dbg(&_dev->dev, "dwc_otg_driver_probe(%p)\n", _dev);
  66030. +#ifdef LM_INTERFACE
  66031. + dev_dbg(&_dev->dev, "start=0x%08x\n", (unsigned)_dev->resource.start);
  66032. +#elif defined(PCI_INTERFACE)
  66033. + if (!id) {
  66034. + DWC_ERROR("Invalid pci_device_id %p", id);
  66035. + return -EINVAL;
  66036. + }
  66037. +
  66038. + if (!_dev || (pci_enable_device(_dev) < 0)) {
  66039. + DWC_ERROR("Invalid pci_device %p", _dev);
  66040. + return -ENODEV;
  66041. + }
  66042. + dev_dbg(&_dev->dev, "start=0x%08x\n", (unsigned)pci_resource_start(_dev,0));
  66043. + /* other stuff needed as well? */
  66044. +
  66045. +#elif defined(PLATFORM_INTERFACE)
  66046. + dev_dbg(&_dev->dev, "start=0x%08x (len 0x%x)\n",
  66047. + (unsigned)_dev->resource->start,
  66048. + (unsigned)(_dev->resource->end - _dev->resource->start));
  66049. +#endif
  66050. +
  66051. + dwc_otg_device = DWC_ALLOC(sizeof(dwc_otg_device_t));
  66052. +
  66053. + if (!dwc_otg_device) {
  66054. + dev_err(&_dev->dev, "kmalloc of dwc_otg_device failed\n");
  66055. + return -ENOMEM;
  66056. + }
  66057. +
  66058. + memset(dwc_otg_device, 0, sizeof(*dwc_otg_device));
  66059. + dwc_otg_device->os_dep.reg_offset = 0xFFFFFFFF;
  66060. +
  66061. + /*
  66062. + * Map the DWC_otg Core memory into virtual address space.
  66063. + */
  66064. +#ifdef LM_INTERFACE
  66065. + dwc_otg_device->os_dep.base = ioremap(_dev->resource.start, SZ_256K);
  66066. +
  66067. + if (!dwc_otg_device->os_dep.base) {
  66068. + dev_err(&_dev->dev, "ioremap() failed\n");
  66069. + DWC_FREE(dwc_otg_device);
  66070. + return -ENOMEM;
  66071. + }
  66072. + dev_dbg(&_dev->dev, "base=0x%08x\n",
  66073. + (unsigned)dwc_otg_device->os_dep.base);
  66074. +#elif defined(PCI_INTERFACE)
  66075. + _dev->current_state = PCI_D0;
  66076. + _dev->dev.power.power_state = PMSG_ON;
  66077. +
  66078. + if (!_dev->irq) {
  66079. + DWC_ERROR("Found HC with no IRQ. Check BIOS/PCI %s setup!",
  66080. + pci_name(_dev));
  66081. + iounmap(dwc_otg_device->os_dep.base);
  66082. + DWC_FREE(dwc_otg_device);
  66083. + return -ENODEV;
  66084. + }
  66085. +
  66086. + dwc_otg_device->os_dep.rsrc_start = pci_resource_start(_dev, 0);
  66087. + dwc_otg_device->os_dep.rsrc_len = pci_resource_len(_dev, 0);
  66088. + DWC_DEBUGPL(DBG_ANY, "PCI resource: start=%08x, len=%08x\n",
  66089. + (unsigned)dwc_otg_device->os_dep.rsrc_start,
  66090. + (unsigned)dwc_otg_device->os_dep.rsrc_len);
  66091. + if (!request_mem_region
  66092. + (dwc_otg_device->os_dep.rsrc_start, dwc_otg_device->os_dep.rsrc_len,
  66093. + "dwc_otg")) {
  66094. + dev_dbg(&_dev->dev, "error requesting memory\n");
  66095. + iounmap(dwc_otg_device->os_dep.base);
  66096. + DWC_FREE(dwc_otg_device);
  66097. + return -EFAULT;
  66098. + }
  66099. +
  66100. + dwc_otg_device->os_dep.base =
  66101. + ioremap_nocache(dwc_otg_device->os_dep.rsrc_start,
  66102. + dwc_otg_device->os_dep.rsrc_len);
  66103. + if (dwc_otg_device->os_dep.base == NULL) {
  66104. + dev_dbg(&_dev->dev, "error mapping memory\n");
  66105. + release_mem_region(dwc_otg_device->os_dep.rsrc_start,
  66106. + dwc_otg_device->os_dep.rsrc_len);
  66107. + iounmap(dwc_otg_device->os_dep.base);
  66108. + DWC_FREE(dwc_otg_device);
  66109. + return -EFAULT;
  66110. + }
  66111. + dev_dbg(&_dev->dev, "base=0x%p (before adjust) \n",
  66112. + dwc_otg_device->os_dep.base);
  66113. + dwc_otg_device->os_dep.base = (char *)dwc_otg_device->os_dep.base;
  66114. + dev_dbg(&_dev->dev, "base=0x%p (after adjust) \n",
  66115. + dwc_otg_device->os_dep.base);
  66116. + dev_dbg(&_dev->dev, "%s: mapped PA 0x%x to VA 0x%p\n", __func__,
  66117. + (unsigned)dwc_otg_device->os_dep.rsrc_start,
  66118. + dwc_otg_device->os_dep.base);
  66119. +
  66120. + pci_set_master(_dev);
  66121. + pci_set_drvdata(_dev, dwc_otg_device);
  66122. +#elif defined(PLATFORM_INTERFACE)
  66123. + DWC_DEBUGPL(DBG_ANY,"Platform resource: start=%08x, len=%08x\n",
  66124. + _dev->resource->start,
  66125. + _dev->resource->end - _dev->resource->start + 1);
  66126. +#if 1
  66127. + if (!request_mem_region(_dev->resource[0].start,
  66128. + _dev->resource[0].end - _dev->resource[0].start + 1,
  66129. + "dwc_otg")) {
  66130. + dev_dbg(&_dev->dev, "error reserving mapped memory\n");
  66131. + retval = -EFAULT;
  66132. + goto fail;
  66133. + }
  66134. +
  66135. + dwc_otg_device->os_dep.base = ioremap_nocache(_dev->resource[0].start,
  66136. + _dev->resource[0].end -
  66137. + _dev->resource[0].start+1);
  66138. + if (fiq_fix_enable)
  66139. + {
  66140. + if (!request_mem_region(_dev->resource[1].start,
  66141. + _dev->resource[1].end - _dev->resource[1].start + 1,
  66142. + "dwc_otg")) {
  66143. + dev_dbg(&_dev->dev, "error reserving mapped memory\n");
  66144. + retval = -EFAULT;
  66145. + goto fail;
  66146. + }
  66147. +
  66148. + dwc_otg_device->os_dep.mphi_base = ioremap_nocache(_dev->resource[1].start,
  66149. + _dev->resource[1].end -
  66150. + _dev->resource[1].start + 1);
  66151. + dummy_send = (void *) kmalloc(16, GFP_ATOMIC);
  66152. + }
  66153. +
  66154. +#else
  66155. + {
  66156. + struct map_desc desc = {
  66157. + .virtual = IO_ADDRESS((unsigned)_dev->resource->start),
  66158. + .pfn = __phys_to_pfn((unsigned)_dev->resource->start),
  66159. + .length = SZ_128K,
  66160. + .type = MT_DEVICE
  66161. + };
  66162. + iotable_init(&desc, 1);
  66163. + dwc_otg_device->os_dep.base = (void *)desc.virtual;
  66164. + }
  66165. +#endif
  66166. + if (!dwc_otg_device->os_dep.base) {
  66167. + dev_err(&_dev->dev, "ioremap() failed\n");
  66168. + retval = -ENOMEM;
  66169. + goto fail;
  66170. + }
  66171. + dev_dbg(&_dev->dev, "base=0x%08x\n",
  66172. + (unsigned)dwc_otg_device->os_dep.base);
  66173. +#endif
  66174. +
  66175. + /*
  66176. + * Initialize driver data to point to the global DWC_otg
  66177. + * Device structure.
  66178. + */
  66179. +#ifdef LM_INTERFACE
  66180. + lm_set_drvdata(_dev, dwc_otg_device);
  66181. +#elif defined(PLATFORM_INTERFACE)
  66182. + platform_set_drvdata(_dev, dwc_otg_device);
  66183. +#endif
  66184. + dev_dbg(&_dev->dev, "dwc_otg_device=0x%p\n", dwc_otg_device);
  66185. +
  66186. + dwc_otg_device->core_if = dwc_otg_cil_init(dwc_otg_device->os_dep.base);
  66187. + DWC_DEBUGPL(DBG_HCDV, "probe of device %p given core_if %p\n",
  66188. + dwc_otg_device, dwc_otg_device->core_if);//GRAYG
  66189. +
  66190. + if (!dwc_otg_device->core_if) {
  66191. + dev_err(&_dev->dev, "CIL initialization failed!\n");
  66192. + retval = -ENOMEM;
  66193. + goto fail;
  66194. + }
  66195. +
  66196. + dev_dbg(&_dev->dev, "Calling get_gsnpsid\n");
  66197. + /*
  66198. + * Attempt to ensure this device is really a DWC_otg Controller.
  66199. + * Read and verify the SNPSID register contents. The value should be
  66200. + * 0x45F42XXX or 0x45F42XXX, which corresponds to either "OT2" or "OTG3",
  66201. + * as in "OTG version 2.XX" or "OTG version 3.XX".
  66202. + */
  66203. +
  66204. + if (((dwc_otg_get_gsnpsid(dwc_otg_device->core_if) & 0xFFFFF000) != 0x4F542000) &&
  66205. + ((dwc_otg_get_gsnpsid(dwc_otg_device->core_if) & 0xFFFFF000) != 0x4F543000)) {
  66206. + dev_err(&_dev->dev, "Bad value for SNPSID: 0x%08x\n",
  66207. + dwc_otg_get_gsnpsid(dwc_otg_device->core_if));
  66208. + retval = -EINVAL;
  66209. + goto fail;
  66210. + }
  66211. +
  66212. + /*
  66213. + * Validate parameter values.
  66214. + */
  66215. + dev_dbg(&_dev->dev, "Calling set_parameters\n");
  66216. + if (set_parameters(dwc_otg_device->core_if)) {
  66217. + retval = -EINVAL;
  66218. + goto fail;
  66219. + }
  66220. +
  66221. + /*
  66222. + * Create Device Attributes in sysfs
  66223. + */
  66224. + dev_dbg(&_dev->dev, "Calling attr_create\n");
  66225. + dwc_otg_attr_create(_dev);
  66226. +
  66227. + /*
  66228. + * Disable the global interrupt until all the interrupt
  66229. + * handlers are installed.
  66230. + */
  66231. + dev_dbg(&_dev->dev, "Calling disable_global_interrupts\n");
  66232. + dwc_otg_disable_global_interrupts(dwc_otg_device->core_if);
  66233. +
  66234. + /*
  66235. + * Install the interrupt handler for the common interrupts before
  66236. + * enabling common interrupts in core_init below.
  66237. + */
  66238. +
  66239. +#if defined(PLATFORM_INTERFACE)
  66240. + devirq = platform_get_irq(_dev, 0);
  66241. +#else
  66242. + devirq = _dev->irq;
  66243. +#endif
  66244. + DWC_DEBUGPL(DBG_CIL, "registering (common) handler for irq%d\n",
  66245. + devirq);
  66246. + dev_dbg(&_dev->dev, "Calling request_irq(%d)\n", devirq);
  66247. + retval = request_irq(devirq, dwc_otg_common_irq,
  66248. + IRQF_SHARED,
  66249. + "dwc_otg", dwc_otg_device);
  66250. + if (retval) {
  66251. + DWC_ERROR("request of irq%d failed\n", devirq);
  66252. + retval = -EBUSY;
  66253. + goto fail;
  66254. + } else {
  66255. + dwc_otg_device->common_irq_installed = 1;
  66256. + }
  66257. +
  66258. +#ifndef IRQF_TRIGGER_LOW
  66259. +#if defined(LM_INTERFACE) || defined(PLATFORM_INTERFACE)
  66260. + dev_dbg(&_dev->dev, "Calling set_irq_type\n");
  66261. + set_irq_type(devirq,
  66262. +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30))
  66263. + IRQT_LOW
  66264. +#else
  66265. + IRQ_TYPE_LEVEL_LOW
  66266. +#endif
  66267. + );
  66268. +#endif
  66269. +#endif /*IRQF_TRIGGER_LOW*/
  66270. +
  66271. + /*
  66272. + * Initialize the DWC_otg core.
  66273. + */
  66274. + dev_dbg(&_dev->dev, "Calling dwc_otg_core_init\n");
  66275. + dwc_otg_core_init(dwc_otg_device->core_if);
  66276. +
  66277. +#ifndef DWC_HOST_ONLY
  66278. + /*
  66279. + * Initialize the PCD
  66280. + */
  66281. + dev_dbg(&_dev->dev, "Calling pcd_init\n");
  66282. + retval = pcd_init(_dev);
  66283. + if (retval != 0) {
  66284. + DWC_ERROR("pcd_init failed\n");
  66285. + dwc_otg_device->pcd = NULL;
  66286. + goto fail;
  66287. + }
  66288. +#endif
  66289. +#ifndef DWC_DEVICE_ONLY
  66290. + /*
  66291. + * Initialize the HCD
  66292. + */
  66293. + dev_dbg(&_dev->dev, "Calling hcd_init\n");
  66294. + retval = hcd_init(_dev);
  66295. + if (retval != 0) {
  66296. + DWC_ERROR("hcd_init failed\n");
  66297. + dwc_otg_device->hcd = NULL;
  66298. + goto fail;
  66299. + }
  66300. +#endif
  66301. + /* Recover from drvdata having been overwritten by hcd_init() */
  66302. +#ifdef LM_INTERFACE
  66303. + lm_set_drvdata(_dev, dwc_otg_device);
  66304. +#elif defined(PLATFORM_INTERFACE)
  66305. + platform_set_drvdata(_dev, dwc_otg_device);
  66306. +#elif defined(PCI_INTERFACE)
  66307. + pci_set_drvdata(_dev, dwc_otg_device);
  66308. + dwc_otg_device->os_dep.pcidev = _dev;
  66309. +#endif
  66310. +
  66311. + /*
  66312. + * Enable the global interrupt after all the interrupt
  66313. + * handlers are installed if there is no ADP support else
  66314. + * perform initial actions required for Internal ADP logic.
  66315. + */
  66316. + if (!dwc_otg_get_param_adp_enable(dwc_otg_device->core_if)) {
  66317. + dev_dbg(&_dev->dev, "Calling enable_global_interrupts\n");
  66318. + dwc_otg_enable_global_interrupts(dwc_otg_device->core_if);
  66319. + dev_dbg(&_dev->dev, "Done\n");
  66320. + } else
  66321. + dwc_otg_adp_start(dwc_otg_device->core_if,
  66322. + dwc_otg_is_host_mode(dwc_otg_device->core_if));
  66323. +
  66324. + return 0;
  66325. +
  66326. +fail:
  66327. + dwc_otg_driver_remove(_dev);
  66328. + return retval;
  66329. +}
  66330. +
  66331. +/**
  66332. + * This structure defines the methods to be called by a bus driver
  66333. + * during the lifecycle of a device on that bus. Both drivers and
  66334. + * devices are registered with a bus driver. The bus driver matches
  66335. + * devices to drivers based on information in the device and driver
  66336. + * structures.
  66337. + *
  66338. + * The probe function is called when the bus driver matches a device
  66339. + * to this driver. The remove function is called when a device is
  66340. + * unregistered with the bus driver.
  66341. + */
  66342. +#ifdef LM_INTERFACE
  66343. +static struct lm_driver dwc_otg_driver = {
  66344. + .drv = {.name = (char *)dwc_driver_name,},
  66345. + .probe = dwc_otg_driver_probe,
  66346. + .remove = dwc_otg_driver_remove,
  66347. + // 'suspend' and 'resume' absent
  66348. +};
  66349. +#elif defined(PCI_INTERFACE)
  66350. +static const struct pci_device_id pci_ids[] = { {
  66351. + PCI_DEVICE(0x16c3, 0xabcd),
  66352. + .driver_data =
  66353. + (unsigned long)0xdeadbeef,
  66354. + }, { /* end: all zeroes */ }
  66355. +};
  66356. +
  66357. +MODULE_DEVICE_TABLE(pci, pci_ids);
  66358. +
  66359. +/* pci driver glue; this is a "new style" PCI driver module */
  66360. +static struct pci_driver dwc_otg_driver = {
  66361. + .name = "dwc_otg",
  66362. + .id_table = pci_ids,
  66363. +
  66364. + .probe = dwc_otg_driver_probe,
  66365. + .remove = dwc_otg_driver_remove,
  66366. +
  66367. + .driver = {
  66368. + .name = (char *)dwc_driver_name,
  66369. + },
  66370. +};
  66371. +#elif defined(PLATFORM_INTERFACE)
  66372. +static struct platform_device_id platform_ids[] = {
  66373. + {
  66374. + .name = "bcm2708_usb",
  66375. + .driver_data = (kernel_ulong_t) 0xdeadbeef,
  66376. + },
  66377. + { /* end: all zeroes */ }
  66378. +};
  66379. +MODULE_DEVICE_TABLE(platform, platform_ids);
  66380. +
  66381. +static struct platform_driver dwc_otg_driver = {
  66382. + .driver = {
  66383. + .name = (char *)dwc_driver_name,
  66384. + },
  66385. + .id_table = platform_ids,
  66386. +
  66387. + .probe = dwc_otg_driver_probe,
  66388. + .remove = dwc_otg_driver_remove,
  66389. + // no 'shutdown', 'suspend', 'resume', 'suspend_late' or 'resume_early'
  66390. +};
  66391. +#endif
  66392. +
  66393. +/**
  66394. + * This function is called when the dwc_otg_driver is installed with the
  66395. + * insmod command. It registers the dwc_otg_driver structure with the
  66396. + * appropriate bus driver. This will cause the dwc_otg_driver_probe function
  66397. + * to be called. In addition, the bus driver will automatically expose
  66398. + * attributes defined for the device and driver in the special sysfs file
  66399. + * system.
  66400. + *
  66401. + * @return
  66402. + */
  66403. +static int __init dwc_otg_driver_init(void)
  66404. +{
  66405. + int retval = 0;
  66406. + int error;
  66407. + struct device_driver *drv;
  66408. +
  66409. + if(fiq_split_enable && !fiq_fix_enable) {
  66410. + printk(KERN_WARNING "dwc_otg: fiq_split_enable was set without fiq_fix_enable! Correcting.\n");
  66411. + fiq_fix_enable = 1;
  66412. + }
  66413. +
  66414. + printk(KERN_INFO "%s: version %s (%s bus)\n", dwc_driver_name,
  66415. + DWC_DRIVER_VERSION,
  66416. +#ifdef LM_INTERFACE
  66417. + "logicmodule");
  66418. + retval = lm_driver_register(&dwc_otg_driver);
  66419. + drv = &dwc_otg_driver.drv;
  66420. +#elif defined(PCI_INTERFACE)
  66421. + "pci");
  66422. + retval = pci_register_driver(&dwc_otg_driver);
  66423. + drv = &dwc_otg_driver.driver;
  66424. +#elif defined(PLATFORM_INTERFACE)
  66425. + "platform");
  66426. + retval = platform_driver_register(&dwc_otg_driver);
  66427. + drv = &dwc_otg_driver.driver;
  66428. +#endif
  66429. + if (retval < 0) {
  66430. + printk(KERN_ERR "%s retval=%d\n", __func__, retval);
  66431. + return retval;
  66432. + }
  66433. + printk(KERN_DEBUG "dwc_otg: FIQ %s\n", fiq_fix_enable ? "enabled":"disabled");
  66434. + printk(KERN_DEBUG "dwc_otg: NAK holdoff %s\n", nak_holdoff_enable ? "enabled":"disabled");
  66435. + printk(KERN_DEBUG "dwc_otg: FIQ split fix %s\n", fiq_split_enable ? "enabled":"disabled");
  66436. +
  66437. + error = driver_create_file(drv, &driver_attr_version);
  66438. +#ifdef DEBUG
  66439. + error = driver_create_file(drv, &driver_attr_debuglevel);
  66440. +#endif
  66441. + return retval;
  66442. +}
  66443. +
  66444. +module_init(dwc_otg_driver_init);
  66445. +
  66446. +/**
  66447. + * This function is called when the driver is removed from the kernel
  66448. + * with the rmmod command. The driver unregisters itself with its bus
  66449. + * driver.
  66450. + *
  66451. + */
  66452. +static void __exit dwc_otg_driver_cleanup(void)
  66453. +{
  66454. + printk(KERN_DEBUG "dwc_otg_driver_cleanup()\n");
  66455. +
  66456. +#ifdef LM_INTERFACE
  66457. + driver_remove_file(&dwc_otg_driver.drv, &driver_attr_debuglevel);
  66458. + driver_remove_file(&dwc_otg_driver.drv, &driver_attr_version);
  66459. + lm_driver_unregister(&dwc_otg_driver);
  66460. +#elif defined(PCI_INTERFACE)
  66461. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_debuglevel);
  66462. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_version);
  66463. + pci_unregister_driver(&dwc_otg_driver);
  66464. +#elif defined(PLATFORM_INTERFACE)
  66465. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_debuglevel);
  66466. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_version);
  66467. + platform_driver_unregister(&dwc_otg_driver);
  66468. +#endif
  66469. +
  66470. + printk(KERN_INFO "%s module removed\n", dwc_driver_name);
  66471. +}
  66472. +
  66473. +module_exit(dwc_otg_driver_cleanup);
  66474. +
  66475. +MODULE_DESCRIPTION(DWC_DRIVER_DESC);
  66476. +MODULE_AUTHOR("Synopsys Inc.");
  66477. +MODULE_LICENSE("GPL");
  66478. +
  66479. +module_param_named(otg_cap, dwc_otg_module_params.otg_cap, int, 0444);
  66480. +MODULE_PARM_DESC(otg_cap, "OTG Capabilities 0=HNP&SRP 1=SRP Only 2=None");
  66481. +module_param_named(opt, dwc_otg_module_params.opt, int, 0444);
  66482. +MODULE_PARM_DESC(opt, "OPT Mode");
  66483. +module_param_named(dma_enable, dwc_otg_module_params.dma_enable, int, 0444);
  66484. +MODULE_PARM_DESC(dma_enable, "DMA Mode 0=Slave 1=DMA enabled");
  66485. +
  66486. +module_param_named(dma_desc_enable, dwc_otg_module_params.dma_desc_enable, int,
  66487. + 0444);
  66488. +MODULE_PARM_DESC(dma_desc_enable,
  66489. + "DMA Desc Mode 0=Address DMA 1=DMA Descriptor enabled");
  66490. +
  66491. +module_param_named(dma_burst_size, dwc_otg_module_params.dma_burst_size, int,
  66492. + 0444);
  66493. +MODULE_PARM_DESC(dma_burst_size,
  66494. + "DMA Burst Size 1, 4, 8, 16, 32, 64, 128, 256");
  66495. +module_param_named(speed, dwc_otg_module_params.speed, int, 0444);
  66496. +MODULE_PARM_DESC(speed, "Speed 0=High Speed 1=Full Speed");
  66497. +module_param_named(host_support_fs_ls_low_power,
  66498. + dwc_otg_module_params.host_support_fs_ls_low_power, int,
  66499. + 0444);
  66500. +MODULE_PARM_DESC(host_support_fs_ls_low_power,
  66501. + "Support Low Power w/FS or LS 0=Support 1=Don't Support");
  66502. +module_param_named(host_ls_low_power_phy_clk,
  66503. + dwc_otg_module_params.host_ls_low_power_phy_clk, int, 0444);
  66504. +MODULE_PARM_DESC(host_ls_low_power_phy_clk,
  66505. + "Low Speed Low Power Clock 0=48Mhz 1=6Mhz");
  66506. +module_param_named(enable_dynamic_fifo,
  66507. + dwc_otg_module_params.enable_dynamic_fifo, int, 0444);
  66508. +MODULE_PARM_DESC(enable_dynamic_fifo, "0=cC Setting 1=Allow Dynamic Sizing");
  66509. +module_param_named(data_fifo_size, dwc_otg_module_params.data_fifo_size, int,
  66510. + 0444);
  66511. +MODULE_PARM_DESC(data_fifo_size,
  66512. + "Total number of words in the data FIFO memory 32-32768");
  66513. +module_param_named(dev_rx_fifo_size, dwc_otg_module_params.dev_rx_fifo_size,
  66514. + int, 0444);
  66515. +MODULE_PARM_DESC(dev_rx_fifo_size, "Number of words in the Rx FIFO 16-32768");
  66516. +module_param_named(dev_nperio_tx_fifo_size,
  66517. + dwc_otg_module_params.dev_nperio_tx_fifo_size, int, 0444);
  66518. +MODULE_PARM_DESC(dev_nperio_tx_fifo_size,
  66519. + "Number of words in the non-periodic Tx FIFO 16-32768");
  66520. +module_param_named(dev_perio_tx_fifo_size_1,
  66521. + dwc_otg_module_params.dev_perio_tx_fifo_size[0], int, 0444);
  66522. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_1,
  66523. + "Number of words in the periodic Tx FIFO 4-768");
  66524. +module_param_named(dev_perio_tx_fifo_size_2,
  66525. + dwc_otg_module_params.dev_perio_tx_fifo_size[1], int, 0444);
  66526. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_2,
  66527. + "Number of words in the periodic Tx FIFO 4-768");
  66528. +module_param_named(dev_perio_tx_fifo_size_3,
  66529. + dwc_otg_module_params.dev_perio_tx_fifo_size[2], int, 0444);
  66530. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_3,
  66531. + "Number of words in the periodic Tx FIFO 4-768");
  66532. +module_param_named(dev_perio_tx_fifo_size_4,
  66533. + dwc_otg_module_params.dev_perio_tx_fifo_size[3], int, 0444);
  66534. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_4,
  66535. + "Number of words in the periodic Tx FIFO 4-768");
  66536. +module_param_named(dev_perio_tx_fifo_size_5,
  66537. + dwc_otg_module_params.dev_perio_tx_fifo_size[4], int, 0444);
  66538. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_5,
  66539. + "Number of words in the periodic Tx FIFO 4-768");
  66540. +module_param_named(dev_perio_tx_fifo_size_6,
  66541. + dwc_otg_module_params.dev_perio_tx_fifo_size[5], int, 0444);
  66542. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_6,
  66543. + "Number of words in the periodic Tx FIFO 4-768");
  66544. +module_param_named(dev_perio_tx_fifo_size_7,
  66545. + dwc_otg_module_params.dev_perio_tx_fifo_size[6], int, 0444);
  66546. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_7,
  66547. + "Number of words in the periodic Tx FIFO 4-768");
  66548. +module_param_named(dev_perio_tx_fifo_size_8,
  66549. + dwc_otg_module_params.dev_perio_tx_fifo_size[7], int, 0444);
  66550. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_8,
  66551. + "Number of words in the periodic Tx FIFO 4-768");
  66552. +module_param_named(dev_perio_tx_fifo_size_9,
  66553. + dwc_otg_module_params.dev_perio_tx_fifo_size[8], int, 0444);
  66554. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_9,
  66555. + "Number of words in the periodic Tx FIFO 4-768");
  66556. +module_param_named(dev_perio_tx_fifo_size_10,
  66557. + dwc_otg_module_params.dev_perio_tx_fifo_size[9], int, 0444);
  66558. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_10,
  66559. + "Number of words in the periodic Tx FIFO 4-768");
  66560. +module_param_named(dev_perio_tx_fifo_size_11,
  66561. + dwc_otg_module_params.dev_perio_tx_fifo_size[10], int, 0444);
  66562. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_11,
  66563. + "Number of words in the periodic Tx FIFO 4-768");
  66564. +module_param_named(dev_perio_tx_fifo_size_12,
  66565. + dwc_otg_module_params.dev_perio_tx_fifo_size[11], int, 0444);
  66566. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_12,
  66567. + "Number of words in the periodic Tx FIFO 4-768");
  66568. +module_param_named(dev_perio_tx_fifo_size_13,
  66569. + dwc_otg_module_params.dev_perio_tx_fifo_size[12], int, 0444);
  66570. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_13,
  66571. + "Number of words in the periodic Tx FIFO 4-768");
  66572. +module_param_named(dev_perio_tx_fifo_size_14,
  66573. + dwc_otg_module_params.dev_perio_tx_fifo_size[13], int, 0444);
  66574. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_14,
  66575. + "Number of words in the periodic Tx FIFO 4-768");
  66576. +module_param_named(dev_perio_tx_fifo_size_15,
  66577. + dwc_otg_module_params.dev_perio_tx_fifo_size[14], int, 0444);
  66578. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_15,
  66579. + "Number of words in the periodic Tx FIFO 4-768");
  66580. +module_param_named(host_rx_fifo_size, dwc_otg_module_params.host_rx_fifo_size,
  66581. + int, 0444);
  66582. +MODULE_PARM_DESC(host_rx_fifo_size, "Number of words in the Rx FIFO 16-32768");
  66583. +module_param_named(host_nperio_tx_fifo_size,
  66584. + dwc_otg_module_params.host_nperio_tx_fifo_size, int, 0444);
  66585. +MODULE_PARM_DESC(host_nperio_tx_fifo_size,
  66586. + "Number of words in the non-periodic Tx FIFO 16-32768");
  66587. +module_param_named(host_perio_tx_fifo_size,
  66588. + dwc_otg_module_params.host_perio_tx_fifo_size, int, 0444);
  66589. +MODULE_PARM_DESC(host_perio_tx_fifo_size,
  66590. + "Number of words in the host periodic Tx FIFO 16-32768");
  66591. +module_param_named(max_transfer_size, dwc_otg_module_params.max_transfer_size,
  66592. + int, 0444);
  66593. +/** @todo Set the max to 512K, modify checks */
  66594. +MODULE_PARM_DESC(max_transfer_size,
  66595. + "The maximum transfer size supported in bytes 2047-65535");
  66596. +module_param_named(max_packet_count, dwc_otg_module_params.max_packet_count,
  66597. + int, 0444);
  66598. +MODULE_PARM_DESC(max_packet_count,
  66599. + "The maximum number of packets in a transfer 15-511");
  66600. +module_param_named(host_channels, dwc_otg_module_params.host_channels, int,
  66601. + 0444);
  66602. +MODULE_PARM_DESC(host_channels,
  66603. + "The number of host channel registers to use 1-16");
  66604. +module_param_named(dev_endpoints, dwc_otg_module_params.dev_endpoints, int,
  66605. + 0444);
  66606. +MODULE_PARM_DESC(dev_endpoints,
  66607. + "The number of endpoints in addition to EP0 available for device mode 1-15");
  66608. +module_param_named(phy_type, dwc_otg_module_params.phy_type, int, 0444);
  66609. +MODULE_PARM_DESC(phy_type, "0=Reserved 1=UTMI+ 2=ULPI");
  66610. +module_param_named(phy_utmi_width, dwc_otg_module_params.phy_utmi_width, int,
  66611. + 0444);
  66612. +MODULE_PARM_DESC(phy_utmi_width, "Specifies the UTMI+ Data Width 8 or 16 bits");
  66613. +module_param_named(phy_ulpi_ddr, dwc_otg_module_params.phy_ulpi_ddr, int, 0444);
  66614. +MODULE_PARM_DESC(phy_ulpi_ddr,
  66615. + "ULPI at double or single data rate 0=Single 1=Double");
  66616. +module_param_named(phy_ulpi_ext_vbus, dwc_otg_module_params.phy_ulpi_ext_vbus,
  66617. + int, 0444);
  66618. +MODULE_PARM_DESC(phy_ulpi_ext_vbus,
  66619. + "ULPI PHY using internal or external vbus 0=Internal");
  66620. +module_param_named(i2c_enable, dwc_otg_module_params.i2c_enable, int, 0444);
  66621. +MODULE_PARM_DESC(i2c_enable, "FS PHY Interface");
  66622. +module_param_named(ulpi_fs_ls, dwc_otg_module_params.ulpi_fs_ls, int, 0444);
  66623. +MODULE_PARM_DESC(ulpi_fs_ls, "ULPI PHY FS/LS mode only");
  66624. +module_param_named(ts_dline, dwc_otg_module_params.ts_dline, int, 0444);
  66625. +MODULE_PARM_DESC(ts_dline, "Term select Dline pulsing for all PHYs");
  66626. +module_param_named(debug, g_dbg_lvl, int, 0444);
  66627. +MODULE_PARM_DESC(debug, "");
  66628. +
  66629. +module_param_named(en_multiple_tx_fifo,
  66630. + dwc_otg_module_params.en_multiple_tx_fifo, int, 0444);
  66631. +MODULE_PARM_DESC(en_multiple_tx_fifo,
  66632. + "Dedicated Non Periodic Tx FIFOs 0=disabled 1=enabled");
  66633. +module_param_named(dev_tx_fifo_size_1,
  66634. + dwc_otg_module_params.dev_tx_fifo_size[0], int, 0444);
  66635. +MODULE_PARM_DESC(dev_tx_fifo_size_1, "Number of words in the Tx FIFO 4-768");
  66636. +module_param_named(dev_tx_fifo_size_2,
  66637. + dwc_otg_module_params.dev_tx_fifo_size[1], int, 0444);
  66638. +MODULE_PARM_DESC(dev_tx_fifo_size_2, "Number of words in the Tx FIFO 4-768");
  66639. +module_param_named(dev_tx_fifo_size_3,
  66640. + dwc_otg_module_params.dev_tx_fifo_size[2], int, 0444);
  66641. +MODULE_PARM_DESC(dev_tx_fifo_size_3, "Number of words in the Tx FIFO 4-768");
  66642. +module_param_named(dev_tx_fifo_size_4,
  66643. + dwc_otg_module_params.dev_tx_fifo_size[3], int, 0444);
  66644. +MODULE_PARM_DESC(dev_tx_fifo_size_4, "Number of words in the Tx FIFO 4-768");
  66645. +module_param_named(dev_tx_fifo_size_5,
  66646. + dwc_otg_module_params.dev_tx_fifo_size[4], int, 0444);
  66647. +MODULE_PARM_DESC(dev_tx_fifo_size_5, "Number of words in the Tx FIFO 4-768");
  66648. +module_param_named(dev_tx_fifo_size_6,
  66649. + dwc_otg_module_params.dev_tx_fifo_size[5], int, 0444);
  66650. +MODULE_PARM_DESC(dev_tx_fifo_size_6, "Number of words in the Tx FIFO 4-768");
  66651. +module_param_named(dev_tx_fifo_size_7,
  66652. + dwc_otg_module_params.dev_tx_fifo_size[6], int, 0444);
  66653. +MODULE_PARM_DESC(dev_tx_fifo_size_7, "Number of words in the Tx FIFO 4-768");
  66654. +module_param_named(dev_tx_fifo_size_8,
  66655. + dwc_otg_module_params.dev_tx_fifo_size[7], int, 0444);
  66656. +MODULE_PARM_DESC(dev_tx_fifo_size_8, "Number of words in the Tx FIFO 4-768");
  66657. +module_param_named(dev_tx_fifo_size_9,
  66658. + dwc_otg_module_params.dev_tx_fifo_size[8], int, 0444);
  66659. +MODULE_PARM_DESC(dev_tx_fifo_size_9, "Number of words in the Tx FIFO 4-768");
  66660. +module_param_named(dev_tx_fifo_size_10,
  66661. + dwc_otg_module_params.dev_tx_fifo_size[9], int, 0444);
  66662. +MODULE_PARM_DESC(dev_tx_fifo_size_10, "Number of words in the Tx FIFO 4-768");
  66663. +module_param_named(dev_tx_fifo_size_11,
  66664. + dwc_otg_module_params.dev_tx_fifo_size[10], int, 0444);
  66665. +MODULE_PARM_DESC(dev_tx_fifo_size_11, "Number of words in the Tx FIFO 4-768");
  66666. +module_param_named(dev_tx_fifo_size_12,
  66667. + dwc_otg_module_params.dev_tx_fifo_size[11], int, 0444);
  66668. +MODULE_PARM_DESC(dev_tx_fifo_size_12, "Number of words in the Tx FIFO 4-768");
  66669. +module_param_named(dev_tx_fifo_size_13,
  66670. + dwc_otg_module_params.dev_tx_fifo_size[12], int, 0444);
  66671. +MODULE_PARM_DESC(dev_tx_fifo_size_13, "Number of words in the Tx FIFO 4-768");
  66672. +module_param_named(dev_tx_fifo_size_14,
  66673. + dwc_otg_module_params.dev_tx_fifo_size[13], int, 0444);
  66674. +MODULE_PARM_DESC(dev_tx_fifo_size_14, "Number of words in the Tx FIFO 4-768");
  66675. +module_param_named(dev_tx_fifo_size_15,
  66676. + dwc_otg_module_params.dev_tx_fifo_size[14], int, 0444);
  66677. +MODULE_PARM_DESC(dev_tx_fifo_size_15, "Number of words in the Tx FIFO 4-768");
  66678. +
  66679. +module_param_named(thr_ctl, dwc_otg_module_params.thr_ctl, int, 0444);
  66680. +MODULE_PARM_DESC(thr_ctl,
  66681. + "Thresholding enable flag bit 0 - non ISO Tx thr., 1 - ISO Tx thr., 2 - Rx thr.- bit 0=disabled 1=enabled");
  66682. +module_param_named(tx_thr_length, dwc_otg_module_params.tx_thr_length, int,
  66683. + 0444);
  66684. +MODULE_PARM_DESC(tx_thr_length, "Tx Threshold length in 32 bit DWORDs");
  66685. +module_param_named(rx_thr_length, dwc_otg_module_params.rx_thr_length, int,
  66686. + 0444);
  66687. +MODULE_PARM_DESC(rx_thr_length, "Rx Threshold length in 32 bit DWORDs");
  66688. +
  66689. +module_param_named(pti_enable, dwc_otg_module_params.pti_enable, int, 0444);
  66690. +module_param_named(mpi_enable, dwc_otg_module_params.mpi_enable, int, 0444);
  66691. +module_param_named(lpm_enable, dwc_otg_module_params.lpm_enable, int, 0444);
  66692. +MODULE_PARM_DESC(lpm_enable, "LPM Enable 0=LPM Disabled 1=LPM Enabled");
  66693. +module_param_named(ic_usb_cap, dwc_otg_module_params.ic_usb_cap, int, 0444);
  66694. +MODULE_PARM_DESC(ic_usb_cap,
  66695. + "IC_USB Capability 0=IC_USB Disabled 1=IC_USB Enabled");
  66696. +module_param_named(ahb_thr_ratio, dwc_otg_module_params.ahb_thr_ratio, int,
  66697. + 0444);
  66698. +MODULE_PARM_DESC(ahb_thr_ratio, "AHB Threshold Ratio");
  66699. +module_param_named(power_down, dwc_otg_module_params.power_down, int, 0444);
  66700. +MODULE_PARM_DESC(power_down, "Power Down Mode");
  66701. +module_param_named(reload_ctl, dwc_otg_module_params.reload_ctl, int, 0444);
  66702. +MODULE_PARM_DESC(reload_ctl, "HFIR Reload Control");
  66703. +module_param_named(dev_out_nak, dwc_otg_module_params.dev_out_nak, int, 0444);
  66704. +MODULE_PARM_DESC(dev_out_nak, "Enable Device OUT NAK");
  66705. +module_param_named(cont_on_bna, dwc_otg_module_params.cont_on_bna, int, 0444);
  66706. +MODULE_PARM_DESC(cont_on_bna, "Enable Enable Continue on BNA");
  66707. +module_param_named(ahb_single, dwc_otg_module_params.ahb_single, int, 0444);
  66708. +MODULE_PARM_DESC(ahb_single, "Enable AHB Single Support");
  66709. +module_param_named(adp_enable, dwc_otg_module_params.adp_enable, int, 0444);
  66710. +MODULE_PARM_DESC(adp_enable, "ADP Enable 0=ADP Disabled 1=ADP Enabled");
  66711. +module_param_named(otg_ver, dwc_otg_module_params.otg_ver, int, 0444);
  66712. +MODULE_PARM_DESC(otg_ver, "OTG revision supported 0=OTG 1.3 1=OTG 2.0");
  66713. +module_param(microframe_schedule, bool, 0444);
  66714. +MODULE_PARM_DESC(microframe_schedule, "Enable the microframe scheduler");
  66715. +
  66716. +module_param(fiq_fix_enable, bool, 0444);
  66717. +MODULE_PARM_DESC(fiq_fix_enable, "Enable the fiq fix");
  66718. +module_param(nak_holdoff_enable, bool, 0444);
  66719. +MODULE_PARM_DESC(nak_holdoff_enable, "Enable the NAK holdoff");
  66720. +module_param(fiq_split_enable, bool, 0444);
  66721. +MODULE_PARM_DESC(fiq_split_enable, "Enable the FIQ fix on split transactions");
  66722. +
  66723. +/** @page "Module Parameters"
  66724. + *
  66725. + * The following parameters may be specified when starting the module.
  66726. + * These parameters define how the DWC_otg controller should be
  66727. + * configured. Parameter values are passed to the CIL initialization
  66728. + * function dwc_otg_cil_init
  66729. + *
  66730. + * Example: <code>modprobe dwc_otg speed=1 otg_cap=1</code>
  66731. + *
  66732. +
  66733. + <table>
  66734. + <tr><td>Parameter Name</td><td>Meaning</td></tr>
  66735. +
  66736. + <tr>
  66737. + <td>otg_cap</td>
  66738. + <td>Specifies the OTG capabilities. The driver will automatically detect the
  66739. + value for this parameter if none is specified.
  66740. + - 0: HNP and SRP capable (default, if available)
  66741. + - 1: SRP Only capable
  66742. + - 2: No HNP/SRP capable
  66743. + </td></tr>
  66744. +
  66745. + <tr>
  66746. + <td>dma_enable</td>
  66747. + <td>Specifies whether to use slave or DMA mode for accessing the data FIFOs.
  66748. + The driver will automatically detect the value for this parameter if none is
  66749. + specified.
  66750. + - 0: Slave
  66751. + - 1: DMA (default, if available)
  66752. + </td></tr>
  66753. +
  66754. + <tr>
  66755. + <td>dma_burst_size</td>
  66756. + <td>The DMA Burst size (applicable only for External DMA Mode).
  66757. + - Values: 1, 4, 8 16, 32, 64, 128, 256 (default 32)
  66758. + </td></tr>
  66759. +
  66760. + <tr>
  66761. + <td>speed</td>
  66762. + <td>Specifies the maximum speed of operation in host and device mode. The
  66763. + actual speed depends on the speed of the attached device and the value of
  66764. + phy_type.
  66765. + - 0: High Speed (default)
  66766. + - 1: Full Speed
  66767. + </td></tr>
  66768. +
  66769. + <tr>
  66770. + <td>host_support_fs_ls_low_power</td>
  66771. + <td>Specifies whether low power mode is supported when attached to a Full
  66772. + Speed or Low Speed device in host mode.
  66773. + - 0: Don't support low power mode (default)
  66774. + - 1: Support low power mode
  66775. + </td></tr>
  66776. +
  66777. + <tr>
  66778. + <td>host_ls_low_power_phy_clk</td>
  66779. + <td>Specifies the PHY clock rate in low power mode when connected to a Low
  66780. + Speed device in host mode. This parameter is applicable only if
  66781. + HOST_SUPPORT_FS_LS_LOW_POWER is enabled.
  66782. + - 0: 48 MHz (default)
  66783. + - 1: 6 MHz
  66784. + </td></tr>
  66785. +
  66786. + <tr>
  66787. + <td>enable_dynamic_fifo</td>
  66788. + <td> Specifies whether FIFOs may be resized by the driver software.
  66789. + - 0: Use cC FIFO size parameters
  66790. + - 1: Allow dynamic FIFO sizing (default)
  66791. + </td></tr>
  66792. +
  66793. + <tr>
  66794. + <td>data_fifo_size</td>
  66795. + <td>Total number of 4-byte words in the data FIFO memory. This memory
  66796. + includes the Rx FIFO, non-periodic Tx FIFO, and periodic Tx FIFOs.
  66797. + - Values: 32 to 32768 (default 8192)
  66798. +
  66799. + Note: The total FIFO memory depth in the FPGA configuration is 8192.
  66800. + </td></tr>
  66801. +
  66802. + <tr>
  66803. + <td>dev_rx_fifo_size</td>
  66804. + <td>Number of 4-byte words in the Rx FIFO in device mode when dynamic
  66805. + FIFO sizing is enabled.
  66806. + - Values: 16 to 32768 (default 1064)
  66807. + </td></tr>
  66808. +
  66809. + <tr>
  66810. + <td>dev_nperio_tx_fifo_size</td>
  66811. + <td>Number of 4-byte words in the non-periodic Tx FIFO in device mode when
  66812. + dynamic FIFO sizing is enabled.
  66813. + - Values: 16 to 32768 (default 1024)
  66814. + </td></tr>
  66815. +
  66816. + <tr>
  66817. + <td>dev_perio_tx_fifo_size_n (n = 1 to 15)</td>
  66818. + <td>Number of 4-byte words in each of the periodic Tx FIFOs in device mode
  66819. + when dynamic FIFO sizing is enabled.
  66820. + - Values: 4 to 768 (default 256)
  66821. + </td></tr>
  66822. +
  66823. + <tr>
  66824. + <td>host_rx_fifo_size</td>
  66825. + <td>Number of 4-byte words in the Rx FIFO in host mode when dynamic FIFO
  66826. + sizing is enabled.
  66827. + - Values: 16 to 32768 (default 1024)
  66828. + </td></tr>
  66829. +
  66830. + <tr>
  66831. + <td>host_nperio_tx_fifo_size</td>
  66832. + <td>Number of 4-byte words in the non-periodic Tx FIFO in host mode when
  66833. + dynamic FIFO sizing is enabled in the core.
  66834. + - Values: 16 to 32768 (default 1024)
  66835. + </td></tr>
  66836. +
  66837. + <tr>
  66838. + <td>host_perio_tx_fifo_size</td>
  66839. + <td>Number of 4-byte words in the host periodic Tx FIFO when dynamic FIFO
  66840. + sizing is enabled.
  66841. + - Values: 16 to 32768 (default 1024)
  66842. + </td></tr>
  66843. +
  66844. + <tr>
  66845. + <td>max_transfer_size</td>
  66846. + <td>The maximum transfer size supported in bytes.
  66847. + - Values: 2047 to 65,535 (default 65,535)
  66848. + </td></tr>
  66849. +
  66850. + <tr>
  66851. + <td>max_packet_count</td>
  66852. + <td>The maximum number of packets in a transfer.
  66853. + - Values: 15 to 511 (default 511)
  66854. + </td></tr>
  66855. +
  66856. + <tr>
  66857. + <td>host_channels</td>
  66858. + <td>The number of host channel registers to use.
  66859. + - Values: 1 to 16 (default 12)
  66860. +
  66861. + Note: The FPGA configuration supports a maximum of 12 host channels.
  66862. + </td></tr>
  66863. +
  66864. + <tr>
  66865. + <td>dev_endpoints</td>
  66866. + <td>The number of endpoints in addition to EP0 available for device mode
  66867. + operations.
  66868. + - Values: 1 to 15 (default 6 IN and OUT)
  66869. +
  66870. + Note: The FPGA configuration supports a maximum of 6 IN and OUT endpoints in
  66871. + addition to EP0.
  66872. + </td></tr>
  66873. +
  66874. + <tr>
  66875. + <td>phy_type</td>
  66876. + <td>Specifies the type of PHY interface to use. By default, the driver will
  66877. + automatically detect the phy_type.
  66878. + - 0: Full Speed
  66879. + - 1: UTMI+ (default, if available)
  66880. + - 2: ULPI
  66881. + </td></tr>
  66882. +
  66883. + <tr>
  66884. + <td>phy_utmi_width</td>
  66885. + <td>Specifies the UTMI+ Data Width. This parameter is applicable for a
  66886. + phy_type of UTMI+. Also, this parameter is applicable only if the
  66887. + OTG_HSPHY_WIDTH cC parameter was set to "8 and 16 bits", meaning that the
  66888. + core has been configured to work at either data path width.
  66889. + - Values: 8 or 16 bits (default 16)
  66890. + </td></tr>
  66891. +
  66892. + <tr>
  66893. + <td>phy_ulpi_ddr</td>
  66894. + <td>Specifies whether the ULPI operates at double or single data rate. This
  66895. + parameter is only applicable if phy_type is ULPI.
  66896. + - 0: single data rate ULPI interface with 8 bit wide data bus (default)
  66897. + - 1: double data rate ULPI interface with 4 bit wide data bus
  66898. + </td></tr>
  66899. +
  66900. + <tr>
  66901. + <td>i2c_enable</td>
  66902. + <td>Specifies whether to use the I2C interface for full speed PHY. This
  66903. + parameter is only applicable if PHY_TYPE is FS.
  66904. + - 0: Disabled (default)
  66905. + - 1: Enabled
  66906. + </td></tr>
  66907. +
  66908. + <tr>
  66909. + <td>ulpi_fs_ls</td>
  66910. + <td>Specifies whether to use ULPI FS/LS mode only.
  66911. + - 0: Disabled (default)
  66912. + - 1: Enabled
  66913. + </td></tr>
  66914. +
  66915. + <tr>
  66916. + <td>ts_dline</td>
  66917. + <td>Specifies whether term select D-Line pulsing for all PHYs is enabled.
  66918. + - 0: Disabled (default)
  66919. + - 1: Enabled
  66920. + </td></tr>
  66921. +
  66922. + <tr>
  66923. + <td>en_multiple_tx_fifo</td>
  66924. + <td>Specifies whether dedicatedto tx fifos are enabled for non periodic IN EPs.
  66925. + The driver will automatically detect the value for this parameter if none is
  66926. + specified.
  66927. + - 0: Disabled
  66928. + - 1: Enabled (default, if available)
  66929. + </td></tr>
  66930. +
  66931. + <tr>
  66932. + <td>dev_tx_fifo_size_n (n = 1 to 15)</td>
  66933. + <td>Number of 4-byte words in each of the Tx FIFOs in device mode
  66934. + when dynamic FIFO sizing is enabled.
  66935. + - Values: 4 to 768 (default 256)
  66936. + </td></tr>
  66937. +
  66938. + <tr>
  66939. + <td>tx_thr_length</td>
  66940. + <td>Transmit Threshold length in 32 bit double words
  66941. + - Values: 8 to 128 (default 64)
  66942. + </td></tr>
  66943. +
  66944. + <tr>
  66945. + <td>rx_thr_length</td>
  66946. + <td>Receive Threshold length in 32 bit double words
  66947. + - Values: 8 to 128 (default 64)
  66948. + </td></tr>
  66949. +
  66950. +<tr>
  66951. + <td>thr_ctl</td>
  66952. + <td>Specifies whether to enable Thresholding for Device mode. Bits 0, 1, 2 of
  66953. + this parmater specifies if thresholding is enabled for non-Iso Tx, Iso Tx and
  66954. + Rx transfers accordingly.
  66955. + The driver will automatically detect the value for this parameter if none is
  66956. + specified.
  66957. + - Values: 0 to 7 (default 0)
  66958. + Bit values indicate:
  66959. + - 0: Thresholding disabled
  66960. + - 1: Thresholding enabled
  66961. + </td></tr>
  66962. +
  66963. +<tr>
  66964. + <td>dma_desc_enable</td>
  66965. + <td>Specifies whether to enable Descriptor DMA mode.
  66966. + The driver will automatically detect the value for this parameter if none is
  66967. + specified.
  66968. + - 0: Descriptor DMA disabled
  66969. + - 1: Descriptor DMA (default, if available)
  66970. + </td></tr>
  66971. +
  66972. +<tr>
  66973. + <td>mpi_enable</td>
  66974. + <td>Specifies whether to enable MPI enhancement mode.
  66975. + The driver will automatically detect the value for this parameter if none is
  66976. + specified.
  66977. + - 0: MPI disabled (default)
  66978. + - 1: MPI enable
  66979. + </td></tr>
  66980. +
  66981. +<tr>
  66982. + <td>pti_enable</td>
  66983. + <td>Specifies whether to enable PTI enhancement support.
  66984. + The driver will automatically detect the value for this parameter if none is
  66985. + specified.
  66986. + - 0: PTI disabled (default)
  66987. + - 1: PTI enable
  66988. + </td></tr>
  66989. +
  66990. +<tr>
  66991. + <td>lpm_enable</td>
  66992. + <td>Specifies whether to enable LPM support.
  66993. + The driver will automatically detect the value for this parameter if none is
  66994. + specified.
  66995. + - 0: LPM disabled
  66996. + - 1: LPM enable (default, if available)
  66997. + </td></tr>
  66998. +
  66999. +<tr>
  67000. + <td>ic_usb_cap</td>
  67001. + <td>Specifies whether to enable IC_USB capability.
  67002. + The driver will automatically detect the value for this parameter if none is
  67003. + specified.
  67004. + - 0: IC_USB disabled (default, if available)
  67005. + - 1: IC_USB enable
  67006. + </td></tr>
  67007. +
  67008. +<tr>
  67009. + <td>ahb_thr_ratio</td>
  67010. + <td>Specifies AHB Threshold ratio.
  67011. + - Values: 0 to 3 (default 0)
  67012. + </td></tr>
  67013. +
  67014. +<tr>
  67015. + <td>power_down</td>
  67016. + <td>Specifies Power Down(Hibernation) Mode.
  67017. + The driver will automatically detect the value for this parameter if none is
  67018. + specified.
  67019. + - 0: Power Down disabled (default)
  67020. + - 2: Power Down enabled
  67021. + </td></tr>
  67022. +
  67023. + <tr>
  67024. + <td>reload_ctl</td>
  67025. + <td>Specifies whether dynamic reloading of the HFIR register is allowed during
  67026. + run time. The driver will automatically detect the value for this parameter if
  67027. + none is specified. In case the HFIR value is reloaded when HFIR.RldCtrl == 1'b0
  67028. + the core might misbehave.
  67029. + - 0: Reload Control disabled (default)
  67030. + - 1: Reload Control enabled
  67031. + </td></tr>
  67032. +
  67033. + <tr>
  67034. + <td>dev_out_nak</td>
  67035. + <td>Specifies whether Device OUT NAK enhancement enabled or no.
  67036. + The driver will automatically detect the value for this parameter if
  67037. + none is specified. This parameter is valid only when OTG_EN_DESC_DMA == 1b1.
  67038. + - 0: The core does not set NAK after Bulk OUT transfer complete (default)
  67039. + - 1: The core sets NAK after Bulk OUT transfer complete
  67040. + </td></tr>
  67041. +
  67042. + <tr>
  67043. + <td>cont_on_bna</td>
  67044. + <td>Specifies whether Enable Continue on BNA enabled or no.
  67045. + After receiving BNA interrupt the core disables the endpoint,when the
  67046. + endpoint is re-enabled by the application the
  67047. + - 0: Core starts processing from the DOEPDMA descriptor (default)
  67048. + - 1: Core starts processing from the descriptor which received the BNA.
  67049. + This parameter is valid only when OTG_EN_DESC_DMA == 1b1.
  67050. + </td></tr>
  67051. +
  67052. + <tr>
  67053. + <td>ahb_single</td>
  67054. + <td>This bit when programmed supports SINGLE transfers for remainder data
  67055. + in a transfer for DMA mode of operation.
  67056. + - 0: The remainder data will be sent using INCR burst size (default)
  67057. + - 1: The remainder data will be sent using SINGLE burst size.
  67058. + </td></tr>
  67059. +
  67060. +<tr>
  67061. + <td>adp_enable</td>
  67062. + <td>Specifies whether ADP feature is enabled.
  67063. + The driver will automatically detect the value for this parameter if none is
  67064. + specified.
  67065. + - 0: ADP feature disabled (default)
  67066. + - 1: ADP feature enabled
  67067. + </td></tr>
  67068. +
  67069. + <tr>
  67070. + <td>otg_ver</td>
  67071. + <td>Specifies whether OTG is performing as USB OTG Revision 2.0 or Revision 1.3
  67072. + USB OTG device.
  67073. + - 0: OTG 2.0 support disabled (default)
  67074. + - 1: OTG 2.0 support enabled
  67075. + </td></tr>
  67076. +
  67077. +*/
  67078. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_driver.h linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_driver.h
  67079. --- linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_driver.h 1970-01-01 01:00:00.000000000 +0100
  67080. +++ linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_driver.h 2014-02-17 22:41:01.000000000 +0100
  67081. @@ -0,0 +1,86 @@
  67082. +/* ==========================================================================
  67083. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_driver.h $
  67084. + * $Revision: #19 $
  67085. + * $Date: 2010/11/15 $
  67086. + * $Change: 1627671 $
  67087. + *
  67088. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  67089. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  67090. + * otherwise expressly agreed to in writing between Synopsys and you.
  67091. + *
  67092. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  67093. + * any End User Software License Agreement or Agreement for Licensed Product
  67094. + * with Synopsys or any supplement thereto. You are permitted to use and
  67095. + * redistribute this Software in source and binary forms, with or without
  67096. + * modification, provided that redistributions of source code must retain this
  67097. + * notice. You may not view, use, disclose, copy or distribute this file or
  67098. + * any information contained herein except pursuant to this license grant from
  67099. + * Synopsys. If you do not agree with this notice, including the disclaimer
  67100. + * below, then you are not authorized to use the Software.
  67101. + *
  67102. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  67103. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  67104. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  67105. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  67106. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  67107. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  67108. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  67109. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  67110. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  67111. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  67112. + * DAMAGE.
  67113. + * ========================================================================== */
  67114. +
  67115. +#ifndef __DWC_OTG_DRIVER_H__
  67116. +#define __DWC_OTG_DRIVER_H__
  67117. +
  67118. +/** @file
  67119. + * This file contains the interface to the Linux driver.
  67120. + */
  67121. +#include "dwc_otg_os_dep.h"
  67122. +#include "dwc_otg_core_if.h"
  67123. +
  67124. +/* Type declarations */
  67125. +struct dwc_otg_pcd;
  67126. +struct dwc_otg_hcd;
  67127. +
  67128. +/**
  67129. + * This structure is a wrapper that encapsulates the driver components used to
  67130. + * manage a single DWC_otg controller.
  67131. + */
  67132. +typedef struct dwc_otg_device {
  67133. + /** Structure containing OS-dependent stuff. KEEP THIS STRUCT AT THE
  67134. + * VERY BEGINNING OF THE DEVICE STRUCT. OSes such as FreeBSD and NetBSD
  67135. + * require this. */
  67136. + struct os_dependent os_dep;
  67137. +
  67138. + /** Pointer to the core interface structure. */
  67139. + dwc_otg_core_if_t *core_if;
  67140. +
  67141. + /** Pointer to the PCD structure. */
  67142. + struct dwc_otg_pcd *pcd;
  67143. +
  67144. + /** Pointer to the HCD structure. */
  67145. + struct dwc_otg_hcd *hcd;
  67146. +
  67147. + /** Flag to indicate whether the common IRQ handler is installed. */
  67148. + uint8_t common_irq_installed;
  67149. +
  67150. +} dwc_otg_device_t;
  67151. +
  67152. +/*We must clear S3C24XX_EINTPEND external interrupt register
  67153. + * because after clearing in this register trigerred IRQ from
  67154. + * H/W core in kernel interrupt can be occured again before OTG
  67155. + * handlers clear all IRQ sources of Core registers because of
  67156. + * timing latencies and Low Level IRQ Type.
  67157. + */
  67158. +#ifdef CONFIG_MACH_IPMATE
  67159. +#define S3C2410X_CLEAR_EINTPEND() \
  67160. +do { \
  67161. + __raw_writel(1UL << 11,S3C24XX_EINTPEND); \
  67162. +} while (0)
  67163. +#else
  67164. +#define S3C2410X_CLEAR_EINTPEND() do { } while (0)
  67165. +#endif
  67166. +
  67167. +#endif
  67168. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd.c linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_hcd.c
  67169. --- linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd.c 1970-01-01 01:00:00.000000000 +0100
  67170. +++ linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_hcd.c 2014-02-17 22:41:01.000000000 +0100
  67171. @@ -0,0 +1,3685 @@
  67172. +
  67173. +/* ==========================================================================
  67174. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd.c $
  67175. + * $Revision: #104 $
  67176. + * $Date: 2011/10/24 $
  67177. + * $Change: 1871159 $
  67178. + *
  67179. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  67180. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  67181. + * otherwise expressly agreed to in writing between Synopsys and you.
  67182. + *
  67183. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  67184. + * any End User Software License Agreement or Agreement for Licensed Product
  67185. + * with Synopsys or any supplement thereto. You are permitted to use and
  67186. + * redistribute this Software in source and binary forms, with or without
  67187. + * modification, provided that redistributions of source code must retain this
  67188. + * notice. You may not view, use, disclose, copy or distribute this file or
  67189. + * any information contained herein except pursuant to this license grant from
  67190. + * Synopsys. If you do not agree with this notice, including the disclaimer
  67191. + * below, then you are not authorized to use the Software.
  67192. + *
  67193. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  67194. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  67195. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  67196. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  67197. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  67198. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  67199. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  67200. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  67201. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  67202. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  67203. + * DAMAGE.
  67204. + * ========================================================================== */
  67205. +#ifndef DWC_DEVICE_ONLY
  67206. +
  67207. +/** @file
  67208. + * This file implements HCD Core. All code in this file is portable and doesn't
  67209. + * use any OS specific functions.
  67210. + * Interface provided by HCD Core is defined in <code><hcd_if.h></code>
  67211. + * header file.
  67212. + */
  67213. +
  67214. +#include <linux/usb.h>
  67215. +#include <linux/usb/hcd.h>
  67216. +
  67217. +#include "dwc_otg_hcd.h"
  67218. +#include "dwc_otg_regs.h"
  67219. +#include "dwc_otg_mphi_fix.h"
  67220. +
  67221. +extern bool microframe_schedule, nak_holdoff_enable;
  67222. +
  67223. +//#define DEBUG_HOST_CHANNELS
  67224. +#ifdef DEBUG_HOST_CHANNELS
  67225. +static int last_sel_trans_num_per_scheduled = 0;
  67226. +static int last_sel_trans_num_nonper_scheduled = 0;
  67227. +static int last_sel_trans_num_avail_hc_at_start = 0;
  67228. +static int last_sel_trans_num_avail_hc_at_end = 0;
  67229. +#endif /* DEBUG_HOST_CHANNELS */
  67230. +
  67231. +extern int g_next_sched_frame, g_np_count, g_np_sent;
  67232. +
  67233. +extern haint_data_t haint_saved;
  67234. +extern hcintmsk_data_t hcintmsk_saved[MAX_EPS_CHANNELS];
  67235. +extern hcint_data_t hcint_saved[MAX_EPS_CHANNELS];
  67236. +extern gintsts_data_t ginsts_saved;
  67237. +
  67238. +dwc_otg_hcd_t *dwc_otg_hcd_alloc_hcd(void)
  67239. +{
  67240. + return DWC_ALLOC(sizeof(dwc_otg_hcd_t));
  67241. +}
  67242. +
  67243. +/**
  67244. + * Connection timeout function. An OTG host is required to display a
  67245. + * message if the device does not connect within 10 seconds.
  67246. + */
  67247. +void dwc_otg_hcd_connect_timeout(void *ptr)
  67248. +{
  67249. + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, ptr);
  67250. + DWC_PRINTF("Connect Timeout\n");
  67251. + __DWC_ERROR("Device Not Connected/Responding\n");
  67252. +}
  67253. +
  67254. +#if defined(DEBUG)
  67255. +static void dump_channel_info(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  67256. +{
  67257. + if (qh->channel != NULL) {
  67258. + dwc_hc_t *hc = qh->channel;
  67259. + dwc_list_link_t *item;
  67260. + dwc_otg_qh_t *qh_item;
  67261. + int num_channels = hcd->core_if->core_params->host_channels;
  67262. + int i;
  67263. +
  67264. + dwc_otg_hc_regs_t *hc_regs;
  67265. + hcchar_data_t hcchar;
  67266. + hcsplt_data_t hcsplt;
  67267. + hctsiz_data_t hctsiz;
  67268. + uint32_t hcdma;
  67269. +
  67270. + hc_regs = hcd->core_if->host_if->hc_regs[hc->hc_num];
  67271. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  67272. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  67273. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  67274. + hcdma = DWC_READ_REG32(&hc_regs->hcdma);
  67275. +
  67276. + DWC_PRINTF(" Assigned to channel %p:\n", hc);
  67277. + DWC_PRINTF(" hcchar 0x%08x, hcsplt 0x%08x\n", hcchar.d32,
  67278. + hcsplt.d32);
  67279. + DWC_PRINTF(" hctsiz 0x%08x, hcdma 0x%08x\n", hctsiz.d32,
  67280. + hcdma);
  67281. + DWC_PRINTF(" dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
  67282. + hc->dev_addr, hc->ep_num, hc->ep_is_in);
  67283. + DWC_PRINTF(" ep_type: %d\n", hc->ep_type);
  67284. + DWC_PRINTF(" max_packet: %d\n", hc->max_packet);
  67285. + DWC_PRINTF(" data_pid_start: %d\n", hc->data_pid_start);
  67286. + DWC_PRINTF(" xfer_started: %d\n", hc->xfer_started);
  67287. + DWC_PRINTF(" halt_status: %d\n", hc->halt_status);
  67288. + DWC_PRINTF(" xfer_buff: %p\n", hc->xfer_buff);
  67289. + DWC_PRINTF(" xfer_len: %d\n", hc->xfer_len);
  67290. + DWC_PRINTF(" qh: %p\n", hc->qh);
  67291. + DWC_PRINTF(" NP inactive sched:\n");
  67292. + DWC_LIST_FOREACH(item, &hcd->non_periodic_sched_inactive) {
  67293. + qh_item =
  67294. + DWC_LIST_ENTRY(item, dwc_otg_qh_t, qh_list_entry);
  67295. + DWC_PRINTF(" %p\n", qh_item);
  67296. + }
  67297. + DWC_PRINTF(" NP active sched:\n");
  67298. + DWC_LIST_FOREACH(item, &hcd->non_periodic_sched_active) {
  67299. + qh_item =
  67300. + DWC_LIST_ENTRY(item, dwc_otg_qh_t, qh_list_entry);
  67301. + DWC_PRINTF(" %p\n", qh_item);
  67302. + }
  67303. + DWC_PRINTF(" Channels: \n");
  67304. + for (i = 0; i < num_channels; i++) {
  67305. + dwc_hc_t *hc = hcd->hc_ptr_array[i];
  67306. + DWC_PRINTF(" %2d: %p\n", i, hc);
  67307. + }
  67308. + }
  67309. +}
  67310. +#else
  67311. +#define dump_channel_info(hcd, qh)
  67312. +#endif /* DEBUG */
  67313. +
  67314. +/**
  67315. + * Work queue function for starting the HCD when A-Cable is connected.
  67316. + * The hcd_start() must be called in a process context.
  67317. + */
  67318. +static void hcd_start_func(void *_vp)
  67319. +{
  67320. + dwc_otg_hcd_t *hcd = (dwc_otg_hcd_t *) _vp;
  67321. +
  67322. + DWC_DEBUGPL(DBG_HCDV, "%s() %p\n", __func__, hcd);
  67323. + if (hcd) {
  67324. + hcd->fops->start(hcd);
  67325. + }
  67326. +}
  67327. +
  67328. +static void del_xfer_timers(dwc_otg_hcd_t * hcd)
  67329. +{
  67330. +#ifdef DEBUG
  67331. + int i;
  67332. + int num_channels = hcd->core_if->core_params->host_channels;
  67333. + for (i = 0; i < num_channels; i++) {
  67334. + DWC_TIMER_CANCEL(hcd->core_if->hc_xfer_timer[i]);
  67335. + }
  67336. +#endif
  67337. +}
  67338. +
  67339. +static void del_timers(dwc_otg_hcd_t * hcd)
  67340. +{
  67341. + del_xfer_timers(hcd);
  67342. + DWC_TIMER_CANCEL(hcd->conn_timer);
  67343. +}
  67344. +
  67345. +/**
  67346. + * Processes all the URBs in a single list of QHs. Completes them with
  67347. + * -ESHUTDOWN and frees the QTD.
  67348. + */
  67349. +static void kill_urbs_in_qh_list(dwc_otg_hcd_t * hcd, dwc_list_link_t * qh_list)
  67350. +{
  67351. + dwc_list_link_t *qh_item, *qh_tmp;
  67352. + dwc_otg_qh_t *qh;
  67353. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  67354. +
  67355. + DWC_LIST_FOREACH_SAFE(qh_item, qh_tmp, qh_list) {
  67356. + qh = DWC_LIST_ENTRY(qh_item, dwc_otg_qh_t, qh_list_entry);
  67357. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp,
  67358. + &qh->qtd_list, qtd_list_entry) {
  67359. + qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  67360. + if (qtd->urb != NULL) {
  67361. + hcd->fops->complete(hcd, qtd->urb->priv,
  67362. + qtd->urb, -DWC_E_SHUTDOWN);
  67363. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  67364. + }
  67365. +
  67366. + }
  67367. + if(qh->channel) {
  67368. + /* Using hcchar.chen == 1 is not a reliable test.
  67369. + * It is possible that the channel has already halted
  67370. + * but not yet been through the IRQ handler.
  67371. + */
  67372. + dwc_otg_hc_halt(hcd->core_if, qh->channel,
  67373. + DWC_OTG_HC_XFER_URB_DEQUEUE);
  67374. + if(microframe_schedule)
  67375. + hcd->available_host_channels++;
  67376. + qh->channel = NULL;
  67377. + }
  67378. + dwc_otg_hcd_qh_remove(hcd, qh);
  67379. + }
  67380. +}
  67381. +
  67382. +/**
  67383. + * Responds with an error status of ESHUTDOWN to all URBs in the non-periodic
  67384. + * and periodic schedules. The QTD associated with each URB is removed from
  67385. + * the schedule and freed. This function may be called when a disconnect is
  67386. + * detected or when the HCD is being stopped.
  67387. + */
  67388. +static void kill_all_urbs(dwc_otg_hcd_t * hcd)
  67389. +{
  67390. + kill_urbs_in_qh_list(hcd, &hcd->non_periodic_sched_inactive);
  67391. + kill_urbs_in_qh_list(hcd, &hcd->non_periodic_sched_active);
  67392. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_inactive);
  67393. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_ready);
  67394. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_assigned);
  67395. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_queued);
  67396. +}
  67397. +
  67398. +/**
  67399. + * Start the connection timer. An OTG host is required to display a
  67400. + * message if the device does not connect within 10 seconds. The
  67401. + * timer is deleted if a port connect interrupt occurs before the
  67402. + * timer expires.
  67403. + */
  67404. +static void dwc_otg_hcd_start_connect_timer(dwc_otg_hcd_t * hcd)
  67405. +{
  67406. + DWC_TIMER_SCHEDULE(hcd->conn_timer, 10000 /* 10 secs */ );
  67407. +}
  67408. +
  67409. +/**
  67410. + * HCD Callback function for disconnect of the HCD.
  67411. + *
  67412. + * @param p void pointer to the <code>struct usb_hcd</code>
  67413. + */
  67414. +static int32_t dwc_otg_hcd_session_start_cb(void *p)
  67415. +{
  67416. + dwc_otg_hcd_t *dwc_otg_hcd;
  67417. + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, p);
  67418. + dwc_otg_hcd = p;
  67419. + dwc_otg_hcd_start_connect_timer(dwc_otg_hcd);
  67420. + return 1;
  67421. +}
  67422. +
  67423. +/**
  67424. + * HCD Callback function for starting the HCD when A-Cable is
  67425. + * connected.
  67426. + *
  67427. + * @param p void pointer to the <code>struct usb_hcd</code>
  67428. + */
  67429. +static int32_t dwc_otg_hcd_start_cb(void *p)
  67430. +{
  67431. + dwc_otg_hcd_t *dwc_otg_hcd = p;
  67432. + dwc_otg_core_if_t *core_if;
  67433. + hprt0_data_t hprt0;
  67434. +
  67435. + core_if = dwc_otg_hcd->core_if;
  67436. +
  67437. + if (core_if->op_state == B_HOST) {
  67438. + /*
  67439. + * Reset the port. During a HNP mode switch the reset
  67440. + * needs to occur within 1ms and have a duration of at
  67441. + * least 50ms.
  67442. + */
  67443. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  67444. + hprt0.b.prtrst = 1;
  67445. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  67446. + }
  67447. + DWC_WORKQ_SCHEDULE_DELAYED(core_if->wq_otg,
  67448. + hcd_start_func, dwc_otg_hcd, 50,
  67449. + "start hcd");
  67450. +
  67451. + return 1;
  67452. +}
  67453. +
  67454. +/**
  67455. + * HCD Callback function for disconnect of the HCD.
  67456. + *
  67457. + * @param p void pointer to the <code>struct usb_hcd</code>
  67458. + */
  67459. +static int32_t dwc_otg_hcd_disconnect_cb(void *p)
  67460. +{
  67461. + gintsts_data_t intr;
  67462. + dwc_otg_hcd_t *dwc_otg_hcd = p;
  67463. +
  67464. + /*
  67465. + * Set status flags for the hub driver.
  67466. + */
  67467. + dwc_otg_hcd->flags.b.port_connect_status_change = 1;
  67468. + dwc_otg_hcd->flags.b.port_connect_status = 0;
  67469. + if(fiq_fix_enable)
  67470. + local_fiq_disable();
  67471. + /*
  67472. + * Shutdown any transfers in process by clearing the Tx FIFO Empty
  67473. + * interrupt mask and status bits and disabling subsequent host
  67474. + * channel interrupts.
  67475. + */
  67476. + intr.d32 = 0;
  67477. + intr.b.nptxfempty = 1;
  67478. + intr.b.ptxfempty = 1;
  67479. + intr.b.hcintr = 1;
  67480. + DWC_MODIFY_REG32(&dwc_otg_hcd->core_if->core_global_regs->gintmsk,
  67481. + intr.d32, 0);
  67482. + DWC_MODIFY_REG32(&dwc_otg_hcd->core_if->core_global_regs->gintsts,
  67483. + intr.d32, 0);
  67484. +
  67485. + del_timers(dwc_otg_hcd);
  67486. +
  67487. + /*
  67488. + * Turn off the vbus power only if the core has transitioned to device
  67489. + * mode. If still in host mode, need to keep power on to detect a
  67490. + * reconnection.
  67491. + */
  67492. + if (dwc_otg_is_device_mode(dwc_otg_hcd->core_if)) {
  67493. + if (dwc_otg_hcd->core_if->op_state != A_SUSPEND) {
  67494. + hprt0_data_t hprt0 = {.d32 = 0 };
  67495. + DWC_PRINTF("Disconnect: PortPower off\n");
  67496. + hprt0.b.prtpwr = 0;
  67497. + DWC_WRITE_REG32(dwc_otg_hcd->core_if->host_if->hprt0,
  67498. + hprt0.d32);
  67499. + }
  67500. +
  67501. + dwc_otg_disable_host_interrupts(dwc_otg_hcd->core_if);
  67502. + }
  67503. +
  67504. + /* Respond with an error status to all URBs in the schedule. */
  67505. + kill_all_urbs(dwc_otg_hcd);
  67506. +
  67507. + if (dwc_otg_is_host_mode(dwc_otg_hcd->core_if)) {
  67508. + /* Clean up any host channels that were in use. */
  67509. + int num_channels;
  67510. + int i;
  67511. + dwc_hc_t *channel;
  67512. + dwc_otg_hc_regs_t *hc_regs;
  67513. + hcchar_data_t hcchar;
  67514. +
  67515. + num_channels = dwc_otg_hcd->core_if->core_params->host_channels;
  67516. +
  67517. + if (!dwc_otg_hcd->core_if->dma_enable) {
  67518. + /* Flush out any channel requests in slave mode. */
  67519. + for (i = 0; i < num_channels; i++) {
  67520. + channel = dwc_otg_hcd->hc_ptr_array[i];
  67521. + if (DWC_CIRCLEQ_EMPTY_ENTRY
  67522. + (channel, hc_list_entry)) {
  67523. + hc_regs =
  67524. + dwc_otg_hcd->core_if->
  67525. + host_if->hc_regs[i];
  67526. + hcchar.d32 =
  67527. + DWC_READ_REG32(&hc_regs->hcchar);
  67528. + if (hcchar.b.chen) {
  67529. + hcchar.b.chen = 0;
  67530. + hcchar.b.chdis = 1;
  67531. + hcchar.b.epdir = 0;
  67532. + DWC_WRITE_REG32
  67533. + (&hc_regs->hcchar,
  67534. + hcchar.d32);
  67535. + }
  67536. + }
  67537. + }
  67538. + }
  67539. +
  67540. + for (i = 0; i < num_channels; i++) {
  67541. + channel = dwc_otg_hcd->hc_ptr_array[i];
  67542. + if (DWC_CIRCLEQ_EMPTY_ENTRY(channel, hc_list_entry)) {
  67543. + hc_regs =
  67544. + dwc_otg_hcd->core_if->host_if->hc_regs[i];
  67545. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  67546. + if (hcchar.b.chen) {
  67547. + /* Halt the channel. */
  67548. + hcchar.b.chdis = 1;
  67549. + DWC_WRITE_REG32(&hc_regs->hcchar,
  67550. + hcchar.d32);
  67551. + }
  67552. +
  67553. + dwc_otg_hc_cleanup(dwc_otg_hcd->core_if,
  67554. + channel);
  67555. + DWC_CIRCLEQ_INSERT_TAIL
  67556. + (&dwc_otg_hcd->free_hc_list, channel,
  67557. + hc_list_entry);
  67558. + /*
  67559. + * Added for Descriptor DMA to prevent channel double cleanup
  67560. + * in release_channel_ddma(). Which called from ep_disable
  67561. + * when device disconnect.
  67562. + */
  67563. + channel->qh = NULL;
  67564. + }
  67565. + }
  67566. + if(fiq_split_enable) {
  67567. + for(i=0; i < 128; i++) {
  67568. + dwc_otg_hcd->hub_port[i] = 0;
  67569. + }
  67570. + haint_saved.d32 = 0;
  67571. + for(i=0; i < MAX_EPS_CHANNELS; i++) {
  67572. + hcint_saved[i].d32 = 0;
  67573. + hcintmsk_saved[i].d32 = 0;
  67574. + }
  67575. + }
  67576. +
  67577. + }
  67578. +
  67579. + if(fiq_fix_enable)
  67580. + local_fiq_enable();
  67581. +
  67582. + if (dwc_otg_hcd->fops->disconnect) {
  67583. + dwc_otg_hcd->fops->disconnect(dwc_otg_hcd);
  67584. + }
  67585. +
  67586. + return 1;
  67587. +}
  67588. +
  67589. +/**
  67590. + * HCD Callback function for stopping the HCD.
  67591. + *
  67592. + * @param p void pointer to the <code>struct usb_hcd</code>
  67593. + */
  67594. +static int32_t dwc_otg_hcd_stop_cb(void *p)
  67595. +{
  67596. + dwc_otg_hcd_t *dwc_otg_hcd = p;
  67597. +
  67598. + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, p);
  67599. + dwc_otg_hcd_stop(dwc_otg_hcd);
  67600. + return 1;
  67601. +}
  67602. +
  67603. +#ifdef CONFIG_USB_DWC_OTG_LPM
  67604. +/**
  67605. + * HCD Callback function for sleep of HCD.
  67606. + *
  67607. + * @param p void pointer to the <code>struct usb_hcd</code>
  67608. + */
  67609. +static int dwc_otg_hcd_sleep_cb(void *p)
  67610. +{
  67611. + dwc_otg_hcd_t *hcd = p;
  67612. +
  67613. + dwc_otg_hcd_free_hc_from_lpm(hcd);
  67614. +
  67615. + return 0;
  67616. +}
  67617. +#endif
  67618. +
  67619. +
  67620. +/**
  67621. + * HCD Callback function for Remote Wakeup.
  67622. + *
  67623. + * @param p void pointer to the <code>struct usb_hcd</code>
  67624. + */
  67625. +static int dwc_otg_hcd_rem_wakeup_cb(void *p)
  67626. +{
  67627. + dwc_otg_hcd_t *hcd = p;
  67628. +
  67629. + if (hcd->core_if->lx_state == DWC_OTG_L2) {
  67630. + hcd->flags.b.port_suspend_change = 1;
  67631. + }
  67632. +#ifdef CONFIG_USB_DWC_OTG_LPM
  67633. + else {
  67634. + hcd->flags.b.port_l1_change = 1;
  67635. + }
  67636. +#endif
  67637. + return 0;
  67638. +}
  67639. +
  67640. +/**
  67641. + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
  67642. + * stopped.
  67643. + */
  67644. +void dwc_otg_hcd_stop(dwc_otg_hcd_t * hcd)
  67645. +{
  67646. + hprt0_data_t hprt0 = {.d32 = 0 };
  67647. +
  67648. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD STOP\n");
  67649. +
  67650. + /*
  67651. + * The root hub should be disconnected before this function is called.
  67652. + * The disconnect will clear the QTD lists (via ..._hcd_urb_dequeue)
  67653. + * and the QH lists (via ..._hcd_endpoint_disable).
  67654. + */
  67655. +
  67656. + /* Turn off all host-specific interrupts. */
  67657. + dwc_otg_disable_host_interrupts(hcd->core_if);
  67658. +
  67659. + /* Turn off the vbus power */
  67660. + DWC_PRINTF("PortPower off\n");
  67661. + hprt0.b.prtpwr = 0;
  67662. + DWC_WRITE_REG32(hcd->core_if->host_if->hprt0, hprt0.d32);
  67663. + dwc_mdelay(1);
  67664. +}
  67665. +
  67666. +int dwc_otg_hcd_urb_enqueue(dwc_otg_hcd_t * hcd,
  67667. + dwc_otg_hcd_urb_t * dwc_otg_urb, void **ep_handle,
  67668. + int atomic_alloc)
  67669. +{
  67670. + int retval = 0;
  67671. + uint8_t needs_scheduling = 0;
  67672. + dwc_otg_transaction_type_e tr_type;
  67673. + dwc_otg_qtd_t *qtd;
  67674. + gintmsk_data_t intr_mask = {.d32 = 0 };
  67675. + hprt0_data_t hprt0 = { .d32 = 0 };
  67676. +
  67677. +#ifdef DEBUG /* integrity checks (Broadcom) */
  67678. + if (NULL == hcd->core_if) {
  67679. + DWC_ERROR("**** DWC OTG HCD URB Enqueue - HCD has NULL core_if\n");
  67680. + /* No longer connected. */
  67681. + return -DWC_E_INVALID;
  67682. + }
  67683. +#endif
  67684. + if (!hcd->flags.b.port_connect_status) {
  67685. + /* No longer connected. */
  67686. + DWC_ERROR("Not connected\n");
  67687. + return -DWC_E_NO_DEVICE;
  67688. + }
  67689. +
  67690. + /* Some core configurations cannot support LS traffic on a FS root port */
  67691. + if ((hcd->fops->speed(hcd, dwc_otg_urb->priv) == USB_SPEED_LOW) &&
  67692. + (hcd->core_if->hwcfg2.b.fs_phy_type == 1) &&
  67693. + (hcd->core_if->hwcfg2.b.hs_phy_type == 1)) {
  67694. + hprt0.d32 = DWC_READ_REG32(hcd->core_if->host_if->hprt0);
  67695. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_FULL_SPEED) {
  67696. + return -DWC_E_NO_DEVICE;
  67697. + }
  67698. + }
  67699. +
  67700. + qtd = dwc_otg_hcd_qtd_create(dwc_otg_urb, atomic_alloc);
  67701. + if (qtd == NULL) {
  67702. + DWC_ERROR("DWC OTG HCD URB Enqueue failed creating QTD\n");
  67703. + return -DWC_E_NO_MEMORY;
  67704. + }
  67705. +#ifdef DEBUG /* integrity checks (Broadcom) */
  67706. + if (qtd->urb == NULL) {
  67707. + DWC_ERROR("**** DWC OTG HCD URB Enqueue created QTD with no URBs\n");
  67708. + return -DWC_E_NO_MEMORY;
  67709. + }
  67710. + if (qtd->urb->priv == NULL) {
  67711. + DWC_ERROR("**** DWC OTG HCD URB Enqueue created QTD URB with no URB handle\n");
  67712. + return -DWC_E_NO_MEMORY;
  67713. + }
  67714. +#endif
  67715. + intr_mask.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->gintmsk);
  67716. + if(!intr_mask.b.sofintr) needs_scheduling = 1;
  67717. + if((((dwc_otg_qh_t *)ep_handle)->ep_type == UE_BULK) && !(qtd->urb->flags & URB_GIVEBACK_ASAP))
  67718. + /* Do not schedule SG transactions until qtd has URB_GIVEBACK_ASAP set */
  67719. + needs_scheduling = 0;
  67720. +
  67721. + retval = dwc_otg_hcd_qtd_add(qtd, hcd, (dwc_otg_qh_t **) ep_handle, atomic_alloc);
  67722. + // creates a new queue in ep_handle if it doesn't exist already
  67723. + if (retval < 0) {
  67724. + DWC_ERROR("DWC OTG HCD URB Enqueue failed adding QTD. "
  67725. + "Error status %d\n", retval);
  67726. + dwc_otg_hcd_qtd_free(qtd);
  67727. + return retval;
  67728. + }
  67729. +
  67730. + if(needs_scheduling) {
  67731. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  67732. + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
  67733. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  67734. + }
  67735. + }
  67736. + return retval;
  67737. +}
  67738. +
  67739. +int dwc_otg_hcd_urb_dequeue(dwc_otg_hcd_t * hcd,
  67740. + dwc_otg_hcd_urb_t * dwc_otg_urb)
  67741. +{
  67742. + dwc_otg_qh_t *qh;
  67743. + dwc_otg_qtd_t *urb_qtd;
  67744. + BUG_ON(!hcd);
  67745. + BUG_ON(!dwc_otg_urb);
  67746. +
  67747. +#ifdef DEBUG /* integrity checks (Broadcom) */
  67748. +
  67749. + if (hcd == NULL) {
  67750. + DWC_ERROR("**** DWC OTG HCD URB Dequeue has NULL HCD\n");
  67751. + return -DWC_E_INVALID;
  67752. + }
  67753. + if (dwc_otg_urb == NULL) {
  67754. + DWC_ERROR("**** DWC OTG HCD URB Dequeue has NULL URB\n");
  67755. + return -DWC_E_INVALID;
  67756. + }
  67757. + if (dwc_otg_urb->qtd == NULL) {
  67758. + DWC_ERROR("**** DWC OTG HCD URB Dequeue with NULL QTD\n");
  67759. + return -DWC_E_INVALID;
  67760. + }
  67761. + urb_qtd = dwc_otg_urb->qtd;
  67762. + BUG_ON(!urb_qtd);
  67763. + if (urb_qtd->qh == NULL) {
  67764. + DWC_ERROR("**** DWC OTG HCD URB Dequeue with QTD with NULL Q handler\n");
  67765. + return -DWC_E_INVALID;
  67766. + }
  67767. +#else
  67768. + urb_qtd = dwc_otg_urb->qtd;
  67769. + BUG_ON(!urb_qtd);
  67770. +#endif
  67771. + qh = urb_qtd->qh;
  67772. + BUG_ON(!qh);
  67773. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  67774. + if (urb_qtd->in_process) {
  67775. + dump_channel_info(hcd, qh);
  67776. + }
  67777. + }
  67778. +#ifdef DEBUG /* integrity checks (Broadcom) */
  67779. + if (hcd->core_if == NULL) {
  67780. + DWC_ERROR("**** DWC OTG HCD URB Dequeue HCD has NULL core_if\n");
  67781. + return -DWC_E_INVALID;
  67782. + }
  67783. +#endif
  67784. + if (urb_qtd->in_process && qh->channel) {
  67785. + /* The QTD is in process (it has been assigned to a channel). */
  67786. + if (hcd->flags.b.port_connect_status) {
  67787. + /*
  67788. + * If still connected (i.e. in host mode), halt the
  67789. + * channel so it can be used for other transfers. If
  67790. + * no longer connected, the host registers can't be
  67791. + * written to halt the channel since the core is in
  67792. + * device mode.
  67793. + */
  67794. + dwc_otg_hc_halt(hcd->core_if, qh->channel,
  67795. + DWC_OTG_HC_XFER_URB_DEQUEUE);
  67796. +
  67797. + dwc_otg_hcd_release_port(hcd, qh);
  67798. + }
  67799. + }
  67800. +
  67801. + /*
  67802. + * Free the QTD and clean up the associated QH. Leave the QH in the
  67803. + * schedule if it has any remaining QTDs.
  67804. + */
  67805. +
  67806. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue - "
  67807. + "delete %sQueue handler\n",
  67808. + hcd->core_if->dma_desc_enable?"DMA ":"");
  67809. + if (!hcd->core_if->dma_desc_enable) {
  67810. + uint8_t b = urb_qtd->in_process;
  67811. + dwc_otg_hcd_qtd_remove_and_free(hcd, urb_qtd, qh);
  67812. + if (b) {
  67813. + dwc_otg_hcd_qh_deactivate(hcd, qh, 0);
  67814. + qh->channel = NULL;
  67815. + } else if (DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  67816. + dwc_otg_hcd_qh_remove(hcd, qh);
  67817. + }
  67818. + } else {
  67819. + dwc_otg_hcd_qtd_remove_and_free(hcd, urb_qtd, qh);
  67820. + }
  67821. + return 0;
  67822. +}
  67823. +
  67824. +int dwc_otg_hcd_endpoint_disable(dwc_otg_hcd_t * hcd, void *ep_handle,
  67825. + int retry)
  67826. +{
  67827. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  67828. + int retval = 0;
  67829. + dwc_irqflags_t flags;
  67830. +
  67831. + if (retry < 0) {
  67832. + retval = -DWC_E_INVALID;
  67833. + goto done;
  67834. + }
  67835. +
  67836. + if (!qh) {
  67837. + retval = -DWC_E_INVALID;
  67838. + goto done;
  67839. + }
  67840. +
  67841. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  67842. +
  67843. + while (!DWC_CIRCLEQ_EMPTY(&qh->qtd_list) && retry) {
  67844. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  67845. + retry--;
  67846. + dwc_msleep(5);
  67847. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  67848. + }
  67849. +
  67850. + dwc_otg_hcd_qh_remove(hcd, qh);
  67851. +
  67852. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  67853. + /*
  67854. + * Split dwc_otg_hcd_qh_remove_and_free() into qh_remove
  67855. + * and qh_free to prevent stack dump on DWC_DMA_FREE() with
  67856. + * irq_disabled (spinlock_irqsave) in dwc_otg_hcd_desc_list_free()
  67857. + * and dwc_otg_hcd_frame_list_alloc().
  67858. + */
  67859. + dwc_otg_hcd_qh_free(hcd, qh);
  67860. +
  67861. +done:
  67862. + return retval;
  67863. +}
  67864. +
  67865. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  67866. +int dwc_otg_hcd_endpoint_reset(dwc_otg_hcd_t * hcd, void *ep_handle)
  67867. +{
  67868. + int retval = 0;
  67869. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  67870. + if (!qh)
  67871. + return -DWC_E_INVALID;
  67872. +
  67873. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  67874. + return retval;
  67875. +}
  67876. +#endif
  67877. +
  67878. +/**
  67879. + * HCD Callback structure for handling mode switching.
  67880. + */
  67881. +static dwc_otg_cil_callbacks_t hcd_cil_callbacks = {
  67882. + .start = dwc_otg_hcd_start_cb,
  67883. + .stop = dwc_otg_hcd_stop_cb,
  67884. + .disconnect = dwc_otg_hcd_disconnect_cb,
  67885. + .session_start = dwc_otg_hcd_session_start_cb,
  67886. + .resume_wakeup = dwc_otg_hcd_rem_wakeup_cb,
  67887. +#ifdef CONFIG_USB_DWC_OTG_LPM
  67888. + .sleep = dwc_otg_hcd_sleep_cb,
  67889. +#endif
  67890. + .p = 0,
  67891. +};
  67892. +
  67893. +/**
  67894. + * Reset tasklet function
  67895. + */
  67896. +static void reset_tasklet_func(void *data)
  67897. +{
  67898. + dwc_otg_hcd_t *dwc_otg_hcd = (dwc_otg_hcd_t *) data;
  67899. + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
  67900. + hprt0_data_t hprt0;
  67901. +
  67902. + DWC_DEBUGPL(DBG_HCDV, "USB RESET tasklet called\n");
  67903. +
  67904. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  67905. + hprt0.b.prtrst = 1;
  67906. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  67907. + dwc_mdelay(60);
  67908. +
  67909. + hprt0.b.prtrst = 0;
  67910. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  67911. + dwc_otg_hcd->flags.b.port_reset_change = 1;
  67912. +}
  67913. +
  67914. +static void completion_tasklet_func(void *ptr)
  67915. +{
  67916. + dwc_otg_hcd_t *hcd = (dwc_otg_hcd_t *) ptr;
  67917. + struct urb *urb;
  67918. + urb_tq_entry_t *item;
  67919. + dwc_irqflags_t flags;
  67920. +
  67921. + /* This could just be spin_lock_irq */
  67922. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  67923. + while (!DWC_TAILQ_EMPTY(&hcd->completed_urb_list)) {
  67924. + item = DWC_TAILQ_FIRST(&hcd->completed_urb_list);
  67925. + urb = item->urb;
  67926. + DWC_TAILQ_REMOVE(&hcd->completed_urb_list, item,
  67927. + urb_tq_entries);
  67928. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  67929. + DWC_FREE(item);
  67930. +
  67931. + usb_hcd_giveback_urb(hcd->priv, urb, urb->status);
  67932. +
  67933. + fiq_print(FIQDBG_PORTHUB, "COMPLETE");
  67934. +
  67935. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  67936. + }
  67937. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  67938. + return;
  67939. +}
  67940. +
  67941. +static void qh_list_free(dwc_otg_hcd_t * hcd, dwc_list_link_t * qh_list)
  67942. +{
  67943. + dwc_list_link_t *item;
  67944. + dwc_otg_qh_t *qh;
  67945. + dwc_irqflags_t flags;
  67946. +
  67947. + if (!qh_list->next) {
  67948. + /* The list hasn't been initialized yet. */
  67949. + return;
  67950. + }
  67951. + /*
  67952. + * Hold spinlock here. Not needed in that case if bellow
  67953. + * function is being called from ISR
  67954. + */
  67955. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  67956. + /* Ensure there are no QTDs or URBs left. */
  67957. + kill_urbs_in_qh_list(hcd, qh_list);
  67958. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  67959. +
  67960. + DWC_LIST_FOREACH(item, qh_list) {
  67961. + qh = DWC_LIST_ENTRY(item, dwc_otg_qh_t, qh_list_entry);
  67962. + dwc_otg_hcd_qh_remove_and_free(hcd, qh);
  67963. + }
  67964. +}
  67965. +
  67966. +/**
  67967. + * Exit from Hibernation if Host did not detect SRP from connected SRP capable
  67968. + * Device during SRP time by host power up.
  67969. + */
  67970. +void dwc_otg_hcd_power_up(void *ptr)
  67971. +{
  67972. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  67973. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  67974. +
  67975. + DWC_PRINTF("%s called\n", __FUNCTION__);
  67976. +
  67977. + if (!core_if->hibernation_suspend) {
  67978. + DWC_PRINTF("Already exited from Hibernation\n");
  67979. + return;
  67980. + }
  67981. +
  67982. + /* Switch on the voltage to the core */
  67983. + gpwrdn.b.pwrdnswtch = 1;
  67984. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  67985. + dwc_udelay(10);
  67986. +
  67987. + /* Reset the core */
  67988. + gpwrdn.d32 = 0;
  67989. + gpwrdn.b.pwrdnrstn = 1;
  67990. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  67991. + dwc_udelay(10);
  67992. +
  67993. + /* Disable power clamps */
  67994. + gpwrdn.d32 = 0;
  67995. + gpwrdn.b.pwrdnclmp = 1;
  67996. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  67997. +
  67998. + /* Remove reset the core signal */
  67999. + gpwrdn.d32 = 0;
  68000. + gpwrdn.b.pwrdnrstn = 1;
  68001. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  68002. + dwc_udelay(10);
  68003. +
  68004. + /* Disable PMU interrupt */
  68005. + gpwrdn.d32 = 0;
  68006. + gpwrdn.b.pmuintsel = 1;
  68007. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  68008. +
  68009. + core_if->hibernation_suspend = 0;
  68010. +
  68011. + /* Disable PMU */
  68012. + gpwrdn.d32 = 0;
  68013. + gpwrdn.b.pmuactv = 1;
  68014. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  68015. + dwc_udelay(10);
  68016. +
  68017. + /* Enable VBUS */
  68018. + gpwrdn.d32 = 0;
  68019. + gpwrdn.b.dis_vbus = 1;
  68020. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  68021. +
  68022. + core_if->op_state = A_HOST;
  68023. + dwc_otg_core_init(core_if);
  68024. + dwc_otg_enable_global_interrupts(core_if);
  68025. + cil_hcd_start(core_if);
  68026. +}
  68027. +
  68028. +/**
  68029. + * Frees secondary storage associated with the dwc_otg_hcd structure contained
  68030. + * in the struct usb_hcd field.
  68031. + */
  68032. +static void dwc_otg_hcd_free(dwc_otg_hcd_t * dwc_otg_hcd)
  68033. +{
  68034. + int i;
  68035. +
  68036. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD FREE\n");
  68037. +
  68038. + del_timers(dwc_otg_hcd);
  68039. +
  68040. + /* Free memory for QH/QTD lists */
  68041. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_inactive);
  68042. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_active);
  68043. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_inactive);
  68044. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_ready);
  68045. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_assigned);
  68046. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_queued);
  68047. +
  68048. + /* Free memory for the host channels. */
  68049. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  68050. + dwc_hc_t *hc = dwc_otg_hcd->hc_ptr_array[i];
  68051. +
  68052. +#ifdef DEBUG
  68053. + if (dwc_otg_hcd->core_if->hc_xfer_timer[i]) {
  68054. + DWC_TIMER_FREE(dwc_otg_hcd->core_if->hc_xfer_timer[i]);
  68055. + }
  68056. +#endif
  68057. + if (hc != NULL) {
  68058. + DWC_DEBUGPL(DBG_HCDV, "HCD Free channel #%i, hc=%p\n",
  68059. + i, hc);
  68060. + DWC_FREE(hc);
  68061. + }
  68062. + }
  68063. +
  68064. + if (dwc_otg_hcd->core_if->dma_enable) {
  68065. + if (dwc_otg_hcd->status_buf_dma) {
  68066. + DWC_DMA_FREE(DWC_OTG_HCD_STATUS_BUF_SIZE,
  68067. + dwc_otg_hcd->status_buf,
  68068. + dwc_otg_hcd->status_buf_dma);
  68069. + }
  68070. + } else if (dwc_otg_hcd->status_buf != NULL) {
  68071. + DWC_FREE(dwc_otg_hcd->status_buf);
  68072. + }
  68073. + DWC_SPINLOCK_FREE(dwc_otg_hcd->channel_lock);
  68074. + DWC_SPINLOCK_FREE(dwc_otg_hcd->lock);
  68075. + /* Set core_if's lock pointer to NULL */
  68076. + dwc_otg_hcd->core_if->lock = NULL;
  68077. +
  68078. + DWC_TIMER_FREE(dwc_otg_hcd->conn_timer);
  68079. + DWC_TASK_FREE(dwc_otg_hcd->reset_tasklet);
  68080. + DWC_TASK_FREE(dwc_otg_hcd->completion_tasklet);
  68081. +
  68082. +#ifdef DWC_DEV_SRPCAP
  68083. + if (dwc_otg_hcd->core_if->power_down == 2 &&
  68084. + dwc_otg_hcd->core_if->pwron_timer) {
  68085. + DWC_TIMER_FREE(dwc_otg_hcd->core_if->pwron_timer);
  68086. + }
  68087. +#endif
  68088. + DWC_FREE(dwc_otg_hcd);
  68089. +}
  68090. +
  68091. +int init_hcd_usecs(dwc_otg_hcd_t *_hcd);
  68092. +
  68093. +int dwc_otg_hcd_init(dwc_otg_hcd_t * hcd, dwc_otg_core_if_t * core_if)
  68094. +{
  68095. + int retval = 0;
  68096. + int num_channels;
  68097. + int i;
  68098. + dwc_hc_t *channel;
  68099. +
  68100. + hcd->lock = DWC_SPINLOCK_ALLOC();
  68101. + hcd->channel_lock = DWC_SPINLOCK_ALLOC();
  68102. + DWC_DEBUGPL(DBG_HCDV, "init of HCD %p given core_if %p\n",
  68103. + hcd, core_if);
  68104. + if (!hcd->lock) {
  68105. + DWC_ERROR("Could not allocate lock for pcd");
  68106. + DWC_FREE(hcd);
  68107. + retval = -DWC_E_NO_MEMORY;
  68108. + goto out;
  68109. + }
  68110. + hcd->core_if = core_if;
  68111. +
  68112. + /* Register the HCD CIL Callbacks */
  68113. + dwc_otg_cil_register_hcd_callbacks(hcd->core_if,
  68114. + &hcd_cil_callbacks, hcd);
  68115. +
  68116. + /* Initialize the non-periodic schedule. */
  68117. + DWC_LIST_INIT(&hcd->non_periodic_sched_inactive);
  68118. + DWC_LIST_INIT(&hcd->non_periodic_sched_active);
  68119. +
  68120. + /* Initialize the periodic schedule. */
  68121. + DWC_LIST_INIT(&hcd->periodic_sched_inactive);
  68122. + DWC_LIST_INIT(&hcd->periodic_sched_ready);
  68123. + DWC_LIST_INIT(&hcd->periodic_sched_assigned);
  68124. + DWC_LIST_INIT(&hcd->periodic_sched_queued);
  68125. + DWC_TAILQ_INIT(&hcd->completed_urb_list);
  68126. + /*
  68127. + * Create a host channel descriptor for each host channel implemented
  68128. + * in the controller. Initialize the channel descriptor array.
  68129. + */
  68130. + DWC_CIRCLEQ_INIT(&hcd->free_hc_list);
  68131. + num_channels = hcd->core_if->core_params->host_channels;
  68132. + DWC_MEMSET(hcd->hc_ptr_array, 0, sizeof(hcd->hc_ptr_array));
  68133. + for (i = 0; i < num_channels; i++) {
  68134. + channel = DWC_ALLOC(sizeof(dwc_hc_t));
  68135. + if (channel == NULL) {
  68136. + retval = -DWC_E_NO_MEMORY;
  68137. + DWC_ERROR("%s: host channel allocation failed\n",
  68138. + __func__);
  68139. + dwc_otg_hcd_free(hcd);
  68140. + goto out;
  68141. + }
  68142. + channel->hc_num = i;
  68143. + hcd->hc_ptr_array[i] = channel;
  68144. +#ifdef DEBUG
  68145. + hcd->core_if->hc_xfer_timer[i] =
  68146. + DWC_TIMER_ALLOC("hc timer", hc_xfer_timeout,
  68147. + &hcd->core_if->hc_xfer_info[i]);
  68148. +#endif
  68149. + DWC_DEBUGPL(DBG_HCDV, "HCD Added channel #%d, hc=%p\n", i,
  68150. + channel);
  68151. + }
  68152. +
  68153. + /* Initialize the Connection timeout timer. */
  68154. + hcd->conn_timer = DWC_TIMER_ALLOC("Connection timer",
  68155. + dwc_otg_hcd_connect_timeout, 0);
  68156. +
  68157. + printk(KERN_DEBUG "dwc_otg: Microframe scheduler %s\n", microframe_schedule ? "enabled":"disabled");
  68158. + if (microframe_schedule)
  68159. + init_hcd_usecs(hcd);
  68160. +
  68161. + /* Initialize reset tasklet. */
  68162. + hcd->reset_tasklet = DWC_TASK_ALLOC("reset_tasklet", reset_tasklet_func, hcd);
  68163. +
  68164. + hcd->completion_tasklet = DWC_TASK_ALLOC("completion_tasklet",
  68165. + completion_tasklet_func, hcd);
  68166. +#ifdef DWC_DEV_SRPCAP
  68167. + if (hcd->core_if->power_down == 2) {
  68168. + /* Initialize Power on timer for Host power up in case hibernation */
  68169. + hcd->core_if->pwron_timer = DWC_TIMER_ALLOC("PWRON TIMER",
  68170. + dwc_otg_hcd_power_up, core_if);
  68171. + }
  68172. +#endif
  68173. +
  68174. + /*
  68175. + * Allocate space for storing data on status transactions. Normally no
  68176. + * data is sent, but this space acts as a bit bucket. This must be
  68177. + * done after usb_add_hcd since that function allocates the DMA buffer
  68178. + * pool.
  68179. + */
  68180. + if (hcd->core_if->dma_enable) {
  68181. + hcd->status_buf =
  68182. + DWC_DMA_ALLOC(DWC_OTG_HCD_STATUS_BUF_SIZE,
  68183. + &hcd->status_buf_dma);
  68184. + } else {
  68185. + hcd->status_buf = DWC_ALLOC(DWC_OTG_HCD_STATUS_BUF_SIZE);
  68186. + }
  68187. + if (!hcd->status_buf) {
  68188. + retval = -DWC_E_NO_MEMORY;
  68189. + DWC_ERROR("%s: status_buf allocation failed\n", __func__);
  68190. + dwc_otg_hcd_free(hcd);
  68191. + goto out;
  68192. + }
  68193. +
  68194. + hcd->otg_port = 1;
  68195. + hcd->frame_list = NULL;
  68196. + hcd->frame_list_dma = 0;
  68197. + hcd->periodic_qh_count = 0;
  68198. +
  68199. + DWC_MEMSET(hcd->hub_port, 0, sizeof(hcd->hub_port));
  68200. +#ifdef FIQ_DEBUG
  68201. + DWC_MEMSET(hcd->hub_port_alloc, -1, sizeof(hcd->hub_port_alloc));
  68202. +#endif
  68203. +
  68204. +out:
  68205. + return retval;
  68206. +}
  68207. +
  68208. +void dwc_otg_hcd_remove(dwc_otg_hcd_t * hcd)
  68209. +{
  68210. + /* Turn off all host-specific interrupts. */
  68211. + dwc_otg_disable_host_interrupts(hcd->core_if);
  68212. +
  68213. + dwc_otg_hcd_free(hcd);
  68214. +}
  68215. +
  68216. +/**
  68217. + * Initializes dynamic portions of the DWC_otg HCD state.
  68218. + */
  68219. +static void dwc_otg_hcd_reinit(dwc_otg_hcd_t * hcd)
  68220. +{
  68221. + int num_channels;
  68222. + int i;
  68223. + dwc_hc_t *channel;
  68224. + dwc_hc_t *channel_tmp;
  68225. +
  68226. + hcd->flags.d32 = 0;
  68227. +
  68228. + hcd->non_periodic_qh_ptr = &hcd->non_periodic_sched_active;
  68229. + if (!microframe_schedule) {
  68230. + hcd->non_periodic_channels = 0;
  68231. + hcd->periodic_channels = 0;
  68232. + } else {
  68233. + hcd->available_host_channels = hcd->core_if->core_params->host_channels;
  68234. + }
  68235. + /*
  68236. + * Put all channels in the free channel list and clean up channel
  68237. + * states.
  68238. + */
  68239. + DWC_CIRCLEQ_FOREACH_SAFE(channel, channel_tmp,
  68240. + &hcd->free_hc_list, hc_list_entry) {
  68241. + DWC_CIRCLEQ_REMOVE(&hcd->free_hc_list, channel, hc_list_entry);
  68242. + }
  68243. +
  68244. + num_channels = hcd->core_if->core_params->host_channels;
  68245. + for (i = 0; i < num_channels; i++) {
  68246. + channel = hcd->hc_ptr_array[i];
  68247. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, channel,
  68248. + hc_list_entry);
  68249. + dwc_otg_hc_cleanup(hcd->core_if, channel);
  68250. + }
  68251. +
  68252. + /* Initialize the DWC core for host mode operation. */
  68253. + dwc_otg_core_host_init(hcd->core_if);
  68254. +
  68255. + /* Set core_if's lock pointer to the hcd->lock */
  68256. + hcd->core_if->lock = hcd->lock;
  68257. +}
  68258. +
  68259. +/**
  68260. + * Assigns transactions from a QTD to a free host channel and initializes the
  68261. + * host channel to perform the transactions. The host channel is removed from
  68262. + * the free list.
  68263. + *
  68264. + * @param hcd The HCD state structure.
  68265. + * @param qh Transactions from the first QTD for this QH are selected and
  68266. + * assigned to a free host channel.
  68267. + */
  68268. +static void assign_and_init_hc(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  68269. +{
  68270. + dwc_hc_t *hc;
  68271. + dwc_otg_qtd_t *qtd;
  68272. + dwc_otg_hcd_urb_t *urb;
  68273. + void* ptr = NULL;
  68274. +
  68275. + qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  68276. +
  68277. + urb = qtd->urb;
  68278. +
  68279. + DWC_DEBUGPL(DBG_HCDV, "%s(%p,%p) - urb %x, actual_length %d\n", __func__, hcd, qh, (unsigned int)urb, urb->actual_length);
  68280. +
  68281. + if (((urb->actual_length < 0) || (urb->actual_length > urb->length)) && !dwc_otg_hcd_is_pipe_in(&urb->pipe_info))
  68282. + urb->actual_length = urb->length;
  68283. +
  68284. +
  68285. + hc = DWC_CIRCLEQ_FIRST(&hcd->free_hc_list);
  68286. +
  68287. + /* Remove the host channel from the free list. */
  68288. + DWC_CIRCLEQ_REMOVE_INIT(&hcd->free_hc_list, hc, hc_list_entry);
  68289. +
  68290. + qh->channel = hc;
  68291. +
  68292. + qtd->in_process = 1;
  68293. +
  68294. + /*
  68295. + * Use usb_pipedevice to determine device address. This address is
  68296. + * 0 before the SET_ADDRESS command and the correct address afterward.
  68297. + */
  68298. + hc->dev_addr = dwc_otg_hcd_get_dev_addr(&urb->pipe_info);
  68299. + hc->ep_num = dwc_otg_hcd_get_ep_num(&urb->pipe_info);
  68300. + hc->speed = qh->dev_speed;
  68301. + hc->max_packet = dwc_max_packet(qh->maxp);
  68302. +
  68303. + hc->xfer_started = 0;
  68304. + hc->halt_status = DWC_OTG_HC_XFER_NO_HALT_STATUS;
  68305. + hc->error_state = (qtd->error_count > 0);
  68306. + hc->halt_on_queue = 0;
  68307. + hc->halt_pending = 0;
  68308. + hc->requests = 0;
  68309. +
  68310. + /*
  68311. + * The following values may be modified in the transfer type section
  68312. + * below. The xfer_len value may be reduced when the transfer is
  68313. + * started to accommodate the max widths of the XferSize and PktCnt
  68314. + * fields in the HCTSIZn register.
  68315. + */
  68316. +
  68317. + hc->ep_is_in = (dwc_otg_hcd_is_pipe_in(&urb->pipe_info) != 0);
  68318. + if (hc->ep_is_in) {
  68319. + hc->do_ping = 0;
  68320. + } else {
  68321. + hc->do_ping = qh->ping_state;
  68322. + }
  68323. +
  68324. + hc->data_pid_start = qh->data_toggle;
  68325. + hc->multi_count = 1;
  68326. +
  68327. + if (hcd->core_if->dma_enable) {
  68328. + hc->xfer_buff = (uint8_t *) urb->dma + urb->actual_length;
  68329. +
  68330. + /* For non-dword aligned case */
  68331. + if (((unsigned long)hc->xfer_buff & 0x3)
  68332. + && !hcd->core_if->dma_desc_enable) {
  68333. + ptr = (uint8_t *) urb->buf + urb->actual_length;
  68334. + }
  68335. + } else {
  68336. + hc->xfer_buff = (uint8_t *) urb->buf + urb->actual_length;
  68337. + }
  68338. + hc->xfer_len = urb->length - urb->actual_length;
  68339. + hc->xfer_count = 0;
  68340. +
  68341. + /*
  68342. + * Set the split attributes
  68343. + */
  68344. + hc->do_split = 0;
  68345. + if (qh->do_split) {
  68346. + uint32_t hub_addr, port_addr;
  68347. + hc->do_split = 1;
  68348. + hc->xact_pos = qtd->isoc_split_pos;
  68349. + /* We don't need to do complete splits anymore */
  68350. + if(fiq_split_enable)
  68351. + hc->complete_split = qtd->complete_split = 0;
  68352. + else
  68353. + hc->complete_split = qtd->complete_split;
  68354. +
  68355. + hcd->fops->hub_info(hcd, urb->priv, &hub_addr, &port_addr);
  68356. + hc->hub_addr = (uint8_t) hub_addr;
  68357. + hc->port_addr = (uint8_t) port_addr;
  68358. + }
  68359. +
  68360. + switch (dwc_otg_hcd_get_pipe_type(&urb->pipe_info)) {
  68361. + case UE_CONTROL:
  68362. + hc->ep_type = DWC_OTG_EP_TYPE_CONTROL;
  68363. + switch (qtd->control_phase) {
  68364. + case DWC_OTG_CONTROL_SETUP:
  68365. + DWC_DEBUGPL(DBG_HCDV, " Control setup transaction\n");
  68366. + hc->do_ping = 0;
  68367. + hc->ep_is_in = 0;
  68368. + hc->data_pid_start = DWC_OTG_HC_PID_SETUP;
  68369. + if (hcd->core_if->dma_enable) {
  68370. + hc->xfer_buff = (uint8_t *) urb->setup_dma;
  68371. + } else {
  68372. + hc->xfer_buff = (uint8_t *) urb->setup_packet;
  68373. + }
  68374. + hc->xfer_len = 8;
  68375. + ptr = NULL;
  68376. + break;
  68377. + case DWC_OTG_CONTROL_DATA:
  68378. + DWC_DEBUGPL(DBG_HCDV, " Control data transaction\n");
  68379. + hc->data_pid_start = qtd->data_toggle;
  68380. + break;
  68381. + case DWC_OTG_CONTROL_STATUS:
  68382. + /*
  68383. + * Direction is opposite of data direction or IN if no
  68384. + * data.
  68385. + */
  68386. + DWC_DEBUGPL(DBG_HCDV, " Control status transaction\n");
  68387. + if (urb->length == 0) {
  68388. + hc->ep_is_in = 1;
  68389. + } else {
  68390. + hc->ep_is_in =
  68391. + dwc_otg_hcd_is_pipe_out(&urb->pipe_info);
  68392. + }
  68393. + if (hc->ep_is_in) {
  68394. + hc->do_ping = 0;
  68395. + }
  68396. +
  68397. + hc->data_pid_start = DWC_OTG_HC_PID_DATA1;
  68398. +
  68399. + hc->xfer_len = 0;
  68400. + if (hcd->core_if->dma_enable) {
  68401. + hc->xfer_buff = (uint8_t *) hcd->status_buf_dma;
  68402. + } else {
  68403. + hc->xfer_buff = (uint8_t *) hcd->status_buf;
  68404. + }
  68405. + ptr = NULL;
  68406. + break;
  68407. + }
  68408. + break;
  68409. + case UE_BULK:
  68410. + hc->ep_type = DWC_OTG_EP_TYPE_BULK;
  68411. + break;
  68412. + case UE_INTERRUPT:
  68413. + hc->ep_type = DWC_OTG_EP_TYPE_INTR;
  68414. + break;
  68415. + case UE_ISOCHRONOUS:
  68416. + {
  68417. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  68418. +
  68419. + hc->ep_type = DWC_OTG_EP_TYPE_ISOC;
  68420. +
  68421. + if (hcd->core_if->dma_desc_enable)
  68422. + break;
  68423. +
  68424. + frame_desc = &urb->iso_descs[qtd->isoc_frame_index];
  68425. +
  68426. + frame_desc->status = 0;
  68427. +
  68428. + if (hcd->core_if->dma_enable) {
  68429. + hc->xfer_buff = (uint8_t *) urb->dma;
  68430. + } else {
  68431. + hc->xfer_buff = (uint8_t *) urb->buf;
  68432. + }
  68433. + hc->xfer_buff +=
  68434. + frame_desc->offset + qtd->isoc_split_offset;
  68435. + hc->xfer_len =
  68436. + frame_desc->length - qtd->isoc_split_offset;
  68437. +
  68438. + /* For non-dword aligned buffers */
  68439. + if (((unsigned long)hc->xfer_buff & 0x3)
  68440. + && hcd->core_if->dma_enable) {
  68441. + ptr =
  68442. + (uint8_t *) urb->buf + frame_desc->offset +
  68443. + qtd->isoc_split_offset;
  68444. + } else
  68445. + ptr = NULL;
  68446. +
  68447. + if (hc->xact_pos == DWC_HCSPLIT_XACTPOS_ALL) {
  68448. + if (hc->xfer_len <= 188) {
  68449. + hc->xact_pos = DWC_HCSPLIT_XACTPOS_ALL;
  68450. + } else {
  68451. + hc->xact_pos =
  68452. + DWC_HCSPLIT_XACTPOS_BEGIN;
  68453. + }
  68454. + }
  68455. + }
  68456. + break;
  68457. + }
  68458. + /* non DWORD-aligned buffer case */
  68459. + if (ptr) {
  68460. + uint32_t buf_size;
  68461. + if (hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
  68462. + buf_size = hcd->core_if->core_params->max_transfer_size;
  68463. + } else {
  68464. + buf_size = 4096;
  68465. + }
  68466. + if (!qh->dw_align_buf) {
  68467. + qh->dw_align_buf = DWC_DMA_ALLOC_ATOMIC(buf_size,
  68468. + &qh->dw_align_buf_dma);
  68469. + if (!qh->dw_align_buf) {
  68470. + DWC_ERROR
  68471. + ("%s: Failed to allocate memory to handle "
  68472. + "non-dword aligned buffer case\n",
  68473. + __func__);
  68474. + return;
  68475. + }
  68476. + }
  68477. + if (!hc->ep_is_in) {
  68478. + dwc_memcpy(qh->dw_align_buf, ptr, hc->xfer_len);
  68479. + }
  68480. + hc->align_buff = qh->dw_align_buf_dma;
  68481. + } else {
  68482. + hc->align_buff = 0;
  68483. + }
  68484. +
  68485. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  68486. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  68487. + /*
  68488. + * This value may be modified when the transfer is started to
  68489. + * reflect the actual transfer length.
  68490. + */
  68491. + hc->multi_count = dwc_hb_mult(qh->maxp);
  68492. + }
  68493. +
  68494. + if (hcd->core_if->dma_desc_enable)
  68495. + hc->desc_list_addr = qh->desc_list_dma;
  68496. +
  68497. + dwc_otg_hc_init(hcd->core_if, hc);
  68498. + hc->qh = qh;
  68499. +}
  68500. +
  68501. +/*
  68502. +** Check the transaction to see if the port / hub has already been assigned for
  68503. +** a split transaction
  68504. +**
  68505. +** Return 0 - Port is already in use
  68506. +*/
  68507. +int dwc_otg_hcd_allocate_port(dwc_otg_hcd_t * hcd, dwc_otg_qh_t *qh)
  68508. +{
  68509. + uint32_t hub_addr, port_addr;
  68510. +
  68511. + if(!fiq_split_enable)
  68512. + return 0;
  68513. +
  68514. + hcd->fops->hub_info(hcd, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->priv, &hub_addr, &port_addr);
  68515. +
  68516. + if(hcd->hub_port[hub_addr] & (1 << port_addr))
  68517. + {
  68518. + fiq_print(FIQDBG_PORTHUB, "H%dP%d:S%02d", hub_addr, port_addr, qh->skip_count);
  68519. +
  68520. + qh->skip_count++;
  68521. +
  68522. + if(qh->skip_count > 40000)
  68523. + {
  68524. + printk_once(KERN_ERR "Error: Having to skip port allocation");
  68525. + local_fiq_disable();
  68526. + BUG();
  68527. + return 0;
  68528. + }
  68529. + return 1;
  68530. + }
  68531. + else
  68532. + {
  68533. + qh->skip_count = 0;
  68534. + hcd->hub_port[hub_addr] |= 1 << port_addr;
  68535. + fiq_print(FIQDBG_PORTHUB, "H%dP%d:A %d", hub_addr, port_addr, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->pipe_info.ep_num);
  68536. +#ifdef FIQ_DEBUG
  68537. + hcd->hub_port_alloc[hub_addr * 16 + port_addr] = dwc_otg_hcd_get_frame_number(hcd);
  68538. +#endif
  68539. + return 0;
  68540. + }
  68541. +}
  68542. +void dwc_otg_hcd_release_port(dwc_otg_hcd_t * hcd, dwc_otg_qh_t *qh)
  68543. +{
  68544. + uint32_t hub_addr, port_addr;
  68545. +
  68546. + if(!fiq_split_enable)
  68547. + return;
  68548. +
  68549. + hcd->fops->hub_info(hcd, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->priv, &hub_addr, &port_addr);
  68550. +
  68551. + hcd->hub_port[hub_addr] &= ~(1 << port_addr);
  68552. +#ifdef FIQ_DEBUG
  68553. + hcd->hub_port_alloc[hub_addr * 16 + port_addr] = -1;
  68554. +#endif
  68555. + fiq_print(FIQDBG_PORTHUB, "H%dP%d:RO%d", hub_addr, port_addr, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->pipe_info.ep_num);
  68556. +
  68557. +}
  68558. +
  68559. +
  68560. +/**
  68561. + * This function selects transactions from the HCD transfer schedule and
  68562. + * assigns them to available host channels. It is called from HCD interrupt
  68563. + * handler functions.
  68564. + *
  68565. + * @param hcd The HCD state structure.
  68566. + *
  68567. + * @return The types of new transactions that were assigned to host channels.
  68568. + */
  68569. +dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t * hcd)
  68570. +{
  68571. + dwc_list_link_t *qh_ptr;
  68572. + dwc_otg_qh_t *qh;
  68573. + dwc_otg_qtd_t *qtd;
  68574. + int num_channels;
  68575. + dwc_irqflags_t flags;
  68576. + dwc_spinlock_t *channel_lock = hcd->channel_lock;
  68577. + dwc_otg_transaction_type_e ret_val = DWC_OTG_TRANSACTION_NONE;
  68578. +
  68579. +#ifdef DEBUG_SOF
  68580. + DWC_DEBUGPL(DBG_HCD, " Select Transactions\n");
  68581. +#endif
  68582. +
  68583. +#ifdef DEBUG_HOST_CHANNELS
  68584. + last_sel_trans_num_per_scheduled = 0;
  68585. + last_sel_trans_num_nonper_scheduled = 0;
  68586. + last_sel_trans_num_avail_hc_at_start = hcd->available_host_channels;
  68587. +#endif /* DEBUG_HOST_CHANNELS */
  68588. +
  68589. + /* Process entries in the periodic ready list. */
  68590. + qh_ptr = DWC_LIST_FIRST(&hcd->periodic_sched_ready);
  68591. +
  68592. + while (qh_ptr != &hcd->periodic_sched_ready &&
  68593. + !DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
  68594. +
  68595. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  68596. +
  68597. + if(qh->do_split) {
  68598. + qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  68599. + if(!(qh->ep_type == UE_ISOCHRONOUS &&
  68600. + (qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_MID ||
  68601. + qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_END))) {
  68602. + if(dwc_otg_hcd_allocate_port(hcd, qh))
  68603. + {
  68604. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  68605. + g_next_sched_frame = dwc_frame_num_inc(dwc_otg_hcd_get_frame_number(hcd), 1);
  68606. + continue;
  68607. + }
  68608. + }
  68609. + }
  68610. +
  68611. + if (microframe_schedule) {
  68612. + // Make sure we leave one channel for non periodic transactions.
  68613. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  68614. + if (hcd->available_host_channels <= 1) {
  68615. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  68616. + if(qh->do_split) dwc_otg_hcd_release_port(hcd, qh);
  68617. + break;
  68618. + }
  68619. + hcd->available_host_channels--;
  68620. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  68621. +#ifdef DEBUG_HOST_CHANNELS
  68622. + last_sel_trans_num_per_scheduled++;
  68623. +#endif /* DEBUG_HOST_CHANNELS */
  68624. + }
  68625. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  68626. + assign_and_init_hc(hcd, qh);
  68627. +
  68628. + /*
  68629. + * Move the QH from the periodic ready schedule to the
  68630. + * periodic assigned schedule.
  68631. + */
  68632. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  68633. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  68634. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_assigned,
  68635. + &qh->qh_list_entry);
  68636. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  68637. + }
  68638. +
  68639. + /*
  68640. + * Process entries in the inactive portion of the non-periodic
  68641. + * schedule. Some free host channels may not be used if they are
  68642. + * reserved for periodic transfers.
  68643. + */
  68644. + qh_ptr = hcd->non_periodic_sched_inactive.next;
  68645. + num_channels = hcd->core_if->core_params->host_channels;
  68646. + while (qh_ptr != &hcd->non_periodic_sched_inactive &&
  68647. + (microframe_schedule || hcd->non_periodic_channels <
  68648. + num_channels - hcd->periodic_channels) &&
  68649. + !DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
  68650. +
  68651. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  68652. +
  68653. + /*
  68654. + * Check to see if this is a NAK'd retransmit, in which case ignore for retransmission
  68655. + * we hold off on bulk retransmissions to reduce NAK interrupt overhead for full-speed
  68656. + * cheeky devices that just hold off using NAKs
  68657. + */
  68658. + if (nak_holdoff_enable && qh->do_split) {
  68659. + if (qh->nak_frame != 0xffff &&
  68660. + dwc_full_frame_num(qh->nak_frame) ==
  68661. + dwc_full_frame_num(dwc_otg_hcd_get_frame_number(hcd))) {
  68662. + /*
  68663. + * Revisit: Need to avoid trampling on periodic scheduling.
  68664. + * Currently we are safe because g_np_count != g_np_sent whenever we hit this,
  68665. + * but if this behaviour is changed then periodic endpoints will get a slower
  68666. + * polling rate.
  68667. + */
  68668. + g_next_sched_frame = ((qh->nak_frame + 8) & ~7) & DWC_HFNUM_MAX_FRNUM;
  68669. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  68670. + continue;
  68671. + } else {
  68672. + qh->nak_frame = 0xffff;
  68673. + }
  68674. + }
  68675. +
  68676. + if (microframe_schedule) {
  68677. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  68678. + if (hcd->available_host_channels < 1) {
  68679. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  68680. + break;
  68681. + }
  68682. + hcd->available_host_channels--;
  68683. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  68684. +#ifdef DEBUG_HOST_CHANNELS
  68685. + last_sel_trans_num_nonper_scheduled++;
  68686. +#endif /* DEBUG_HOST_CHANNELS */
  68687. + }
  68688. +
  68689. + assign_and_init_hc(hcd, qh);
  68690. +
  68691. + /*
  68692. + * Move the QH from the non-periodic inactive schedule to the
  68693. + * non-periodic active schedule.
  68694. + */
  68695. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  68696. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  68697. + DWC_LIST_MOVE_HEAD(&hcd->non_periodic_sched_active,
  68698. + &qh->qh_list_entry);
  68699. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  68700. +
  68701. + g_np_sent++;
  68702. +
  68703. + if (!microframe_schedule)
  68704. + hcd->non_periodic_channels++;
  68705. + }
  68706. +
  68707. + if(!DWC_LIST_EMPTY(&hcd->periodic_sched_assigned))
  68708. + ret_val |= DWC_OTG_TRANSACTION_PERIODIC;
  68709. +
  68710. + if(!DWC_LIST_EMPTY(&hcd->non_periodic_sched_active))
  68711. + ret_val |= DWC_OTG_TRANSACTION_NON_PERIODIC;
  68712. +
  68713. +
  68714. +#ifdef DEBUG_HOST_CHANNELS
  68715. + last_sel_trans_num_avail_hc_at_end = hcd->available_host_channels;
  68716. +#endif /* DEBUG_HOST_CHANNELS */
  68717. + return ret_val;
  68718. +}
  68719. +
  68720. +/**
  68721. + * Attempts to queue a single transaction request for a host channel
  68722. + * associated with either a periodic or non-periodic transfer. This function
  68723. + * assumes that there is space available in the appropriate request queue. For
  68724. + * an OUT transfer or SETUP transaction in Slave mode, it checks whether space
  68725. + * is available in the appropriate Tx FIFO.
  68726. + *
  68727. + * @param hcd The HCD state structure.
  68728. + * @param hc Host channel descriptor associated with either a periodic or
  68729. + * non-periodic transfer.
  68730. + * @param fifo_dwords_avail Number of DWORDs available in the periodic Tx
  68731. + * FIFO for periodic transfers or the non-periodic Tx FIFO for non-periodic
  68732. + * transfers.
  68733. + *
  68734. + * @return 1 if a request is queued and more requests may be needed to
  68735. + * complete the transfer, 0 if no more requests are required for this
  68736. + * transfer, -1 if there is insufficient space in the Tx FIFO.
  68737. + */
  68738. +static int queue_transaction(dwc_otg_hcd_t * hcd,
  68739. + dwc_hc_t * hc, uint16_t fifo_dwords_avail)
  68740. +{
  68741. + int retval;
  68742. +
  68743. + if (hcd->core_if->dma_enable) {
  68744. + if (hcd->core_if->dma_desc_enable) {
  68745. + if (!hc->xfer_started
  68746. + || (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)) {
  68747. + dwc_otg_hcd_start_xfer_ddma(hcd, hc->qh);
  68748. + hc->qh->ping_state = 0;
  68749. + }
  68750. + } else if (!hc->xfer_started) {
  68751. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  68752. + hc->qh->ping_state = 0;
  68753. + }
  68754. + retval = 0;
  68755. + } else if (hc->halt_pending) {
  68756. + /* Don't queue a request if the channel has been halted. */
  68757. + retval = 0;
  68758. + } else if (hc->halt_on_queue) {
  68759. + dwc_otg_hc_halt(hcd->core_if, hc, hc->halt_status);
  68760. + retval = 0;
  68761. + } else if (hc->do_ping) {
  68762. + if (!hc->xfer_started) {
  68763. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  68764. + }
  68765. + retval = 0;
  68766. + } else if (!hc->ep_is_in || hc->data_pid_start == DWC_OTG_HC_PID_SETUP) {
  68767. + if ((fifo_dwords_avail * 4) >= hc->max_packet) {
  68768. + if (!hc->xfer_started) {
  68769. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  68770. + retval = 1;
  68771. + } else {
  68772. + retval =
  68773. + dwc_otg_hc_continue_transfer(hcd->core_if,
  68774. + hc);
  68775. + }
  68776. + } else {
  68777. + retval = -1;
  68778. + }
  68779. + } else {
  68780. + if (!hc->xfer_started) {
  68781. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  68782. + retval = 1;
  68783. + } else {
  68784. + retval = dwc_otg_hc_continue_transfer(hcd->core_if, hc);
  68785. + }
  68786. + }
  68787. +
  68788. + return retval;
  68789. +}
  68790. +
  68791. +/**
  68792. + * Processes periodic channels for the next frame and queues transactions for
  68793. + * these channels to the DWC_otg controller. After queueing transactions, the
  68794. + * Periodic Tx FIFO Empty interrupt is enabled if there are more transactions
  68795. + * to queue as Periodic Tx FIFO or request queue space becomes available.
  68796. + * Otherwise, the Periodic Tx FIFO Empty interrupt is disabled.
  68797. + */
  68798. +static void process_periodic_channels(dwc_otg_hcd_t * hcd)
  68799. +{
  68800. + hptxsts_data_t tx_status;
  68801. + dwc_list_link_t *qh_ptr;
  68802. + dwc_otg_qh_t *qh;
  68803. + int status;
  68804. + int no_queue_space = 0;
  68805. + int no_fifo_space = 0;
  68806. +
  68807. + dwc_otg_host_global_regs_t *host_regs;
  68808. + host_regs = hcd->core_if->host_if->host_global_regs;
  68809. +
  68810. + DWC_DEBUGPL(DBG_HCDV, "Queue periodic transactions\n");
  68811. +#ifdef DEBUG
  68812. + tx_status.d32 = DWC_READ_REG32(&host_regs->hptxsts);
  68813. + DWC_DEBUGPL(DBG_HCDV,
  68814. + " P Tx Req Queue Space Avail (before queue): %d\n",
  68815. + tx_status.b.ptxqspcavail);
  68816. + DWC_DEBUGPL(DBG_HCDV, " P Tx FIFO Space Avail (before queue): %d\n",
  68817. + tx_status.b.ptxfspcavail);
  68818. +#endif
  68819. +
  68820. + qh_ptr = hcd->periodic_sched_assigned.next;
  68821. + while (qh_ptr != &hcd->periodic_sched_assigned) {
  68822. + tx_status.d32 = DWC_READ_REG32(&host_regs->hptxsts);
  68823. + if (tx_status.b.ptxqspcavail == 0) {
  68824. + no_queue_space = 1;
  68825. + break;
  68826. + }
  68827. +
  68828. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  68829. +
  68830. + // Do not send a split start transaction any later than frame .6
  68831. + // Note, we have to schedule a periodic in .5 to make it go in .6
  68832. + if(fiq_split_enable && qh->do_split && ((dwc_otg_hcd_get_frame_number(hcd) + 1) & 7) > 6)
  68833. + {
  68834. + qh_ptr = qh_ptr->next;
  68835. + g_next_sched_frame = dwc_otg_hcd_get_frame_number(hcd) | 7;
  68836. + continue;
  68837. + }
  68838. +
  68839. + /*
  68840. + * Set a flag if we're queuing high-bandwidth in slave mode.
  68841. + * The flag prevents any halts to get into the request queue in
  68842. + * the middle of multiple high-bandwidth packets getting queued.
  68843. + */
  68844. + if (!hcd->core_if->dma_enable && qh->channel->multi_count > 1) {
  68845. + hcd->core_if->queuing_high_bandwidth = 1;
  68846. + }
  68847. + status =
  68848. + queue_transaction(hcd, qh->channel,
  68849. + tx_status.b.ptxfspcavail);
  68850. + if (status < 0) {
  68851. + no_fifo_space = 1;
  68852. + break;
  68853. + }
  68854. +
  68855. + /*
  68856. + * In Slave mode, stay on the current transfer until there is
  68857. + * nothing more to do or the high-bandwidth request count is
  68858. + * reached. In DMA mode, only need to queue one request. The
  68859. + * controller automatically handles multiple packets for
  68860. + * high-bandwidth transfers.
  68861. + */
  68862. + if (hcd->core_if->dma_enable || status == 0 ||
  68863. + qh->channel->requests == qh->channel->multi_count) {
  68864. + qh_ptr = qh_ptr->next;
  68865. + /*
  68866. + * Move the QH from the periodic assigned schedule to
  68867. + * the periodic queued schedule.
  68868. + */
  68869. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_queued,
  68870. + &qh->qh_list_entry);
  68871. +
  68872. + /* done queuing high bandwidth */
  68873. + hcd->core_if->queuing_high_bandwidth = 0;
  68874. + }
  68875. + }
  68876. +
  68877. + if (!hcd->core_if->dma_enable) {
  68878. + dwc_otg_core_global_regs_t *global_regs;
  68879. + gintmsk_data_t intr_mask = {.d32 = 0 };
  68880. +
  68881. + global_regs = hcd->core_if->core_global_regs;
  68882. + intr_mask.b.ptxfempty = 1;
  68883. +#ifdef DEBUG
  68884. + tx_status.d32 = DWC_READ_REG32(&host_regs->hptxsts);
  68885. + DWC_DEBUGPL(DBG_HCDV,
  68886. + " P Tx Req Queue Space Avail (after queue): %d\n",
  68887. + tx_status.b.ptxqspcavail);
  68888. + DWC_DEBUGPL(DBG_HCDV,
  68889. + " P Tx FIFO Space Avail (after queue): %d\n",
  68890. + tx_status.b.ptxfspcavail);
  68891. +#endif
  68892. + if (!DWC_LIST_EMPTY(&hcd->periodic_sched_assigned) ||
  68893. + no_queue_space || no_fifo_space) {
  68894. + /*
  68895. + * May need to queue more transactions as the request
  68896. + * queue or Tx FIFO empties. Enable the periodic Tx
  68897. + * FIFO empty interrupt. (Always use the half-empty
  68898. + * level to ensure that new requests are loaded as
  68899. + * soon as possible.)
  68900. + */
  68901. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0,
  68902. + intr_mask.d32);
  68903. + } else {
  68904. + /*
  68905. + * Disable the Tx FIFO empty interrupt since there are
  68906. + * no more transactions that need to be queued right
  68907. + * now. This function is called from interrupt
  68908. + * handlers to queue more transactions as transfer
  68909. + * states change.
  68910. + */
  68911. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32,
  68912. + 0);
  68913. + }
  68914. + }
  68915. +}
  68916. +
  68917. +/**
  68918. + * Processes active non-periodic channels and queues transactions for these
  68919. + * channels to the DWC_otg controller. After queueing transactions, the NP Tx
  68920. + * FIFO Empty interrupt is enabled if there are more transactions to queue as
  68921. + * NP Tx FIFO or request queue space becomes available. Otherwise, the NP Tx
  68922. + * FIFO Empty interrupt is disabled.
  68923. + */
  68924. +static void process_non_periodic_channels(dwc_otg_hcd_t * hcd)
  68925. +{
  68926. + gnptxsts_data_t tx_status;
  68927. + dwc_list_link_t *orig_qh_ptr;
  68928. + dwc_otg_qh_t *qh;
  68929. + int status;
  68930. + int no_queue_space = 0;
  68931. + int no_fifo_space = 0;
  68932. + int more_to_do = 0;
  68933. +
  68934. + dwc_otg_core_global_regs_t *global_regs =
  68935. + hcd->core_if->core_global_regs;
  68936. +
  68937. + DWC_DEBUGPL(DBG_HCDV, "Queue non-periodic transactions\n");
  68938. +#ifdef DEBUG
  68939. + tx_status.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  68940. + DWC_DEBUGPL(DBG_HCDV,
  68941. + " NP Tx Req Queue Space Avail (before queue): %d\n",
  68942. + tx_status.b.nptxqspcavail);
  68943. + DWC_DEBUGPL(DBG_HCDV, " NP Tx FIFO Space Avail (before queue): %d\n",
  68944. + tx_status.b.nptxfspcavail);
  68945. +#endif
  68946. + /*
  68947. + * Keep track of the starting point. Skip over the start-of-list
  68948. + * entry.
  68949. + */
  68950. + if (hcd->non_periodic_qh_ptr == &hcd->non_periodic_sched_active) {
  68951. + hcd->non_periodic_qh_ptr = hcd->non_periodic_qh_ptr->next;
  68952. + }
  68953. + orig_qh_ptr = hcd->non_periodic_qh_ptr;
  68954. +
  68955. + /*
  68956. + * Process once through the active list or until no more space is
  68957. + * available in the request queue or the Tx FIFO.
  68958. + */
  68959. + do {
  68960. + tx_status.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  68961. + if (!hcd->core_if->dma_enable && tx_status.b.nptxqspcavail == 0) {
  68962. + no_queue_space = 1;
  68963. + break;
  68964. + }
  68965. +
  68966. + qh = DWC_LIST_ENTRY(hcd->non_periodic_qh_ptr, dwc_otg_qh_t,
  68967. + qh_list_entry);
  68968. +
  68969. + // Do not send a split start transaction any later than frame .5
  68970. + // non periodic transactions will start immediately in this uframe
  68971. + if(fiq_split_enable && qh->do_split && ((dwc_otg_hcd_get_frame_number(hcd) + 1) & 7) > 6)
  68972. + {
  68973. + g_next_sched_frame = dwc_otg_hcd_get_frame_number(hcd) | 7;
  68974. + break;
  68975. + }
  68976. +
  68977. + status =
  68978. + queue_transaction(hcd, qh->channel,
  68979. + tx_status.b.nptxfspcavail);
  68980. +
  68981. + if (status > 0) {
  68982. + more_to_do = 1;
  68983. + } else if (status < 0) {
  68984. + no_fifo_space = 1;
  68985. + break;
  68986. + }
  68987. +
  68988. + /* Advance to next QH, skipping start-of-list entry. */
  68989. + hcd->non_periodic_qh_ptr = hcd->non_periodic_qh_ptr->next;
  68990. + if (hcd->non_periodic_qh_ptr == &hcd->non_periodic_sched_active) {
  68991. + hcd->non_periodic_qh_ptr =
  68992. + hcd->non_periodic_qh_ptr->next;
  68993. + }
  68994. +
  68995. + } while (hcd->non_periodic_qh_ptr != orig_qh_ptr);
  68996. +
  68997. + if (!hcd->core_if->dma_enable) {
  68998. + gintmsk_data_t intr_mask = {.d32 = 0 };
  68999. + intr_mask.b.nptxfempty = 1;
  69000. +
  69001. +#ifdef DEBUG
  69002. + tx_status.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  69003. + DWC_DEBUGPL(DBG_HCDV,
  69004. + " NP Tx Req Queue Space Avail (after queue): %d\n",
  69005. + tx_status.b.nptxqspcavail);
  69006. + DWC_DEBUGPL(DBG_HCDV,
  69007. + " NP Tx FIFO Space Avail (after queue): %d\n",
  69008. + tx_status.b.nptxfspcavail);
  69009. +#endif
  69010. + if (more_to_do || no_queue_space || no_fifo_space) {
  69011. + /*
  69012. + * May need to queue more transactions as the request
  69013. + * queue or Tx FIFO empties. Enable the non-periodic
  69014. + * Tx FIFO empty interrupt. (Always use the half-empty
  69015. + * level to ensure that new requests are loaded as
  69016. + * soon as possible.)
  69017. + */
  69018. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0,
  69019. + intr_mask.d32);
  69020. + } else {
  69021. + /*
  69022. + * Disable the Tx FIFO empty interrupt since there are
  69023. + * no more transactions that need to be queued right
  69024. + * now. This function is called from interrupt
  69025. + * handlers to queue more transactions as transfer
  69026. + * states change.
  69027. + */
  69028. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32,
  69029. + 0);
  69030. + }
  69031. + }
  69032. +}
  69033. +
  69034. +/**
  69035. + * This function processes the currently active host channels and queues
  69036. + * transactions for these channels to the DWC_otg controller. It is called
  69037. + * from HCD interrupt handler functions.
  69038. + *
  69039. + * @param hcd The HCD state structure.
  69040. + * @param tr_type The type(s) of transactions to queue (non-periodic,
  69041. + * periodic, or both).
  69042. + */
  69043. +void dwc_otg_hcd_queue_transactions(dwc_otg_hcd_t * hcd,
  69044. + dwc_otg_transaction_type_e tr_type)
  69045. +{
  69046. +#ifdef DEBUG_SOF
  69047. + DWC_DEBUGPL(DBG_HCD, "Queue Transactions\n");
  69048. +#endif
  69049. + /* Process host channels associated with periodic transfers. */
  69050. + if ((tr_type == DWC_OTG_TRANSACTION_PERIODIC ||
  69051. + tr_type == DWC_OTG_TRANSACTION_ALL) &&
  69052. + !DWC_LIST_EMPTY(&hcd->periodic_sched_assigned)) {
  69053. +
  69054. + process_periodic_channels(hcd);
  69055. + }
  69056. +
  69057. + /* Process host channels associated with non-periodic transfers. */
  69058. + if (tr_type == DWC_OTG_TRANSACTION_NON_PERIODIC ||
  69059. + tr_type == DWC_OTG_TRANSACTION_ALL) {
  69060. + if (!DWC_LIST_EMPTY(&hcd->non_periodic_sched_active)) {
  69061. + process_non_periodic_channels(hcd);
  69062. + } else {
  69063. + /*
  69064. + * Ensure NP Tx FIFO empty interrupt is disabled when
  69065. + * there are no non-periodic transfers to process.
  69066. + */
  69067. + gintmsk_data_t gintmsk = {.d32 = 0 };
  69068. + gintmsk.b.nptxfempty = 1;
  69069. + DWC_MODIFY_REG32(&hcd->core_if->
  69070. + core_global_regs->gintmsk, gintmsk.d32,
  69071. + 0);
  69072. + }
  69073. + }
  69074. +}
  69075. +
  69076. +#ifdef DWC_HS_ELECT_TST
  69077. +/*
  69078. + * Quick and dirty hack to implement the HS Electrical Test
  69079. + * SINGLE_STEP_GET_DEVICE_DESCRIPTOR feature.
  69080. + *
  69081. + * This code was copied from our userspace app "hset". It sends a
  69082. + * Get Device Descriptor control sequence in two parts, first the
  69083. + * Setup packet by itself, followed some time later by the In and
  69084. + * Ack packets. Rather than trying to figure out how to add this
  69085. + * functionality to the normal driver code, we just hijack the
  69086. + * hardware, using these two function to drive the hardware
  69087. + * directly.
  69088. + */
  69089. +
  69090. +static dwc_otg_core_global_regs_t *global_regs;
  69091. +static dwc_otg_host_global_regs_t *hc_global_regs;
  69092. +static dwc_otg_hc_regs_t *hc_regs;
  69093. +static uint32_t *data_fifo;
  69094. +
  69095. +static void do_setup(void)
  69096. +{
  69097. + gintsts_data_t gintsts;
  69098. + hctsiz_data_t hctsiz;
  69099. + hcchar_data_t hcchar;
  69100. + haint_data_t haint;
  69101. + hcint_data_t hcint;
  69102. +
  69103. + /* Enable HAINTs */
  69104. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0001);
  69105. +
  69106. + /* Enable HCINTs */
  69107. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x04a3);
  69108. +
  69109. + /* Read GINTSTS */
  69110. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  69111. +
  69112. + /* Read HAINT */
  69113. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  69114. +
  69115. + /* Read HCINT */
  69116. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  69117. +
  69118. + /* Read HCCHAR */
  69119. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  69120. +
  69121. + /* Clear HCINT */
  69122. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  69123. +
  69124. + /* Clear HAINT */
  69125. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  69126. +
  69127. + /* Clear GINTSTS */
  69128. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  69129. +
  69130. + /* Read GINTSTS */
  69131. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  69132. +
  69133. + /*
  69134. + * Send Setup packet (Get Device Descriptor)
  69135. + */
  69136. +
  69137. + /* Make sure channel is disabled */
  69138. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  69139. + if (hcchar.b.chen) {
  69140. + hcchar.b.chdis = 1;
  69141. +// hcchar.b.chen = 1;
  69142. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  69143. + //sleep(1);
  69144. + dwc_mdelay(1000);
  69145. +
  69146. + /* Read GINTSTS */
  69147. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  69148. +
  69149. + /* Read HAINT */
  69150. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  69151. +
  69152. + /* Read HCINT */
  69153. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  69154. +
  69155. + /* Read HCCHAR */
  69156. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  69157. +
  69158. + /* Clear HCINT */
  69159. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  69160. +
  69161. + /* Clear HAINT */
  69162. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  69163. +
  69164. + /* Clear GINTSTS */
  69165. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  69166. +
  69167. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  69168. + }
  69169. +
  69170. + /* Set HCTSIZ */
  69171. + hctsiz.d32 = 0;
  69172. + hctsiz.b.xfersize = 8;
  69173. + hctsiz.b.pktcnt = 1;
  69174. + hctsiz.b.pid = DWC_OTG_HC_PID_SETUP;
  69175. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  69176. +
  69177. + /* Set HCCHAR */
  69178. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  69179. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  69180. + hcchar.b.epdir = 0;
  69181. + hcchar.b.epnum = 0;
  69182. + hcchar.b.mps = 8;
  69183. + hcchar.b.chen = 1;
  69184. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  69185. +
  69186. + /* Fill FIFO with Setup data for Get Device Descriptor */
  69187. + data_fifo = (uint32_t *) ((char *)global_regs + 0x1000);
  69188. + DWC_WRITE_REG32(data_fifo++, 0x01000680);
  69189. + DWC_WRITE_REG32(data_fifo++, 0x00080000);
  69190. +
  69191. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  69192. +
  69193. + /* Wait for host channel interrupt */
  69194. + do {
  69195. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  69196. + } while (gintsts.b.hcintr == 0);
  69197. +
  69198. + /* Disable HCINTs */
  69199. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x0000);
  69200. +
  69201. + /* Disable HAINTs */
  69202. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0000);
  69203. +
  69204. + /* Read HAINT */
  69205. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  69206. +
  69207. + /* Read HCINT */
  69208. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  69209. +
  69210. + /* Read HCCHAR */
  69211. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  69212. +
  69213. + /* Clear HCINT */
  69214. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  69215. +
  69216. + /* Clear HAINT */
  69217. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  69218. +
  69219. + /* Clear GINTSTS */
  69220. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  69221. +
  69222. + /* Read GINTSTS */
  69223. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  69224. +}
  69225. +
  69226. +static void do_in_ack(void)
  69227. +{
  69228. + gintsts_data_t gintsts;
  69229. + hctsiz_data_t hctsiz;
  69230. + hcchar_data_t hcchar;
  69231. + haint_data_t haint;
  69232. + hcint_data_t hcint;
  69233. + host_grxsts_data_t grxsts;
  69234. +
  69235. + /* Enable HAINTs */
  69236. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0001);
  69237. +
  69238. + /* Enable HCINTs */
  69239. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x04a3);
  69240. +
  69241. + /* Read GINTSTS */
  69242. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  69243. +
  69244. + /* Read HAINT */
  69245. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  69246. +
  69247. + /* Read HCINT */
  69248. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  69249. +
  69250. + /* Read HCCHAR */
  69251. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  69252. +
  69253. + /* Clear HCINT */
  69254. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  69255. +
  69256. + /* Clear HAINT */
  69257. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  69258. +
  69259. + /* Clear GINTSTS */
  69260. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  69261. +
  69262. + /* Read GINTSTS */
  69263. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  69264. +
  69265. + /*
  69266. + * Receive Control In packet
  69267. + */
  69268. +
  69269. + /* Make sure channel is disabled */
  69270. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  69271. + if (hcchar.b.chen) {
  69272. + hcchar.b.chdis = 1;
  69273. + hcchar.b.chen = 1;
  69274. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  69275. + //sleep(1);
  69276. + dwc_mdelay(1000);
  69277. +
  69278. + /* Read GINTSTS */
  69279. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  69280. +
  69281. + /* Read HAINT */
  69282. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  69283. +
  69284. + /* Read HCINT */
  69285. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  69286. +
  69287. + /* Read HCCHAR */
  69288. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  69289. +
  69290. + /* Clear HCINT */
  69291. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  69292. +
  69293. + /* Clear HAINT */
  69294. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  69295. +
  69296. + /* Clear GINTSTS */
  69297. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  69298. +
  69299. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  69300. + }
  69301. +
  69302. + /* Set HCTSIZ */
  69303. + hctsiz.d32 = 0;
  69304. + hctsiz.b.xfersize = 8;
  69305. + hctsiz.b.pktcnt = 1;
  69306. + hctsiz.b.pid = DWC_OTG_HC_PID_DATA1;
  69307. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  69308. +
  69309. + /* Set HCCHAR */
  69310. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  69311. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  69312. + hcchar.b.epdir = 1;
  69313. + hcchar.b.epnum = 0;
  69314. + hcchar.b.mps = 8;
  69315. + hcchar.b.chen = 1;
  69316. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  69317. +
  69318. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  69319. +
  69320. + /* Wait for receive status queue interrupt */
  69321. + do {
  69322. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  69323. + } while (gintsts.b.rxstsqlvl == 0);
  69324. +
  69325. + /* Read RXSTS */
  69326. + grxsts.d32 = DWC_READ_REG32(&global_regs->grxstsp);
  69327. +
  69328. + /* Clear RXSTSQLVL in GINTSTS */
  69329. + gintsts.d32 = 0;
  69330. + gintsts.b.rxstsqlvl = 1;
  69331. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  69332. +
  69333. + switch (grxsts.b.pktsts) {
  69334. + case DWC_GRXSTS_PKTSTS_IN:
  69335. + /* Read the data into the host buffer */
  69336. + if (grxsts.b.bcnt > 0) {
  69337. + int i;
  69338. + int word_count = (grxsts.b.bcnt + 3) / 4;
  69339. +
  69340. + data_fifo = (uint32_t *) ((char *)global_regs + 0x1000);
  69341. +
  69342. + for (i = 0; i < word_count; i++) {
  69343. + (void)DWC_READ_REG32(data_fifo++);
  69344. + }
  69345. + }
  69346. + break;
  69347. +
  69348. + default:
  69349. + break;
  69350. + }
  69351. +
  69352. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  69353. +
  69354. + /* Wait for receive status queue interrupt */
  69355. + do {
  69356. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  69357. + } while (gintsts.b.rxstsqlvl == 0);
  69358. +
  69359. + /* Read RXSTS */
  69360. + grxsts.d32 = DWC_READ_REG32(&global_regs->grxstsp);
  69361. +
  69362. + /* Clear RXSTSQLVL in GINTSTS */
  69363. + gintsts.d32 = 0;
  69364. + gintsts.b.rxstsqlvl = 1;
  69365. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  69366. +
  69367. + switch (grxsts.b.pktsts) {
  69368. + case DWC_GRXSTS_PKTSTS_IN_XFER_COMP:
  69369. + break;
  69370. +
  69371. + default:
  69372. + break;
  69373. + }
  69374. +
  69375. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  69376. +
  69377. + /* Wait for host channel interrupt */
  69378. + do {
  69379. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  69380. + } while (gintsts.b.hcintr == 0);
  69381. +
  69382. + /* Read HAINT */
  69383. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  69384. +
  69385. + /* Read HCINT */
  69386. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  69387. +
  69388. + /* Read HCCHAR */
  69389. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  69390. +
  69391. + /* Clear HCINT */
  69392. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  69393. +
  69394. + /* Clear HAINT */
  69395. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  69396. +
  69397. + /* Clear GINTSTS */
  69398. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  69399. +
  69400. + /* Read GINTSTS */
  69401. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  69402. +
  69403. +// usleep(100000);
  69404. +// mdelay(100);
  69405. + dwc_mdelay(1);
  69406. +
  69407. + /*
  69408. + * Send handshake packet
  69409. + */
  69410. +
  69411. + /* Read HAINT */
  69412. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  69413. +
  69414. + /* Read HCINT */
  69415. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  69416. +
  69417. + /* Read HCCHAR */
  69418. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  69419. +
  69420. + /* Clear HCINT */
  69421. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  69422. +
  69423. + /* Clear HAINT */
  69424. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  69425. +
  69426. + /* Clear GINTSTS */
  69427. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  69428. +
  69429. + /* Read GINTSTS */
  69430. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  69431. +
  69432. + /* Make sure channel is disabled */
  69433. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  69434. + if (hcchar.b.chen) {
  69435. + hcchar.b.chdis = 1;
  69436. + hcchar.b.chen = 1;
  69437. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  69438. + //sleep(1);
  69439. + dwc_mdelay(1000);
  69440. +
  69441. + /* Read GINTSTS */
  69442. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  69443. +
  69444. + /* Read HAINT */
  69445. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  69446. +
  69447. + /* Read HCINT */
  69448. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  69449. +
  69450. + /* Read HCCHAR */
  69451. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  69452. +
  69453. + /* Clear HCINT */
  69454. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  69455. +
  69456. + /* Clear HAINT */
  69457. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  69458. +
  69459. + /* Clear GINTSTS */
  69460. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  69461. +
  69462. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  69463. + }
  69464. +
  69465. + /* Set HCTSIZ */
  69466. + hctsiz.d32 = 0;
  69467. + hctsiz.b.xfersize = 0;
  69468. + hctsiz.b.pktcnt = 1;
  69469. + hctsiz.b.pid = DWC_OTG_HC_PID_DATA1;
  69470. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  69471. +
  69472. + /* Set HCCHAR */
  69473. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  69474. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  69475. + hcchar.b.epdir = 0;
  69476. + hcchar.b.epnum = 0;
  69477. + hcchar.b.mps = 8;
  69478. + hcchar.b.chen = 1;
  69479. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  69480. +
  69481. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  69482. +
  69483. + /* Wait for host channel interrupt */
  69484. + do {
  69485. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  69486. + } while (gintsts.b.hcintr == 0);
  69487. +
  69488. + /* Disable HCINTs */
  69489. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x0000);
  69490. +
  69491. + /* Disable HAINTs */
  69492. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0000);
  69493. +
  69494. + /* Read HAINT */
  69495. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  69496. +
  69497. + /* Read HCINT */
  69498. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  69499. +
  69500. + /* Read HCCHAR */
  69501. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  69502. +
  69503. + /* Clear HCINT */
  69504. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  69505. +
  69506. + /* Clear HAINT */
  69507. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  69508. +
  69509. + /* Clear GINTSTS */
  69510. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  69511. +
  69512. + /* Read GINTSTS */
  69513. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  69514. +}
  69515. +#endif
  69516. +
  69517. +/** Handles hub class-specific requests. */
  69518. +int dwc_otg_hcd_hub_control(dwc_otg_hcd_t * dwc_otg_hcd,
  69519. + uint16_t typeReq,
  69520. + uint16_t wValue,
  69521. + uint16_t wIndex, uint8_t * buf, uint16_t wLength)
  69522. +{
  69523. + int retval = 0;
  69524. +
  69525. + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
  69526. + usb_hub_descriptor_t *hub_desc;
  69527. + hprt0_data_t hprt0 = {.d32 = 0 };
  69528. +
  69529. + uint32_t port_status;
  69530. +
  69531. + switch (typeReq) {
  69532. + case UCR_CLEAR_HUB_FEATURE:
  69533. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  69534. + "ClearHubFeature 0x%x\n", wValue);
  69535. + switch (wValue) {
  69536. + case UHF_C_HUB_LOCAL_POWER:
  69537. + case UHF_C_HUB_OVER_CURRENT:
  69538. + /* Nothing required here */
  69539. + break;
  69540. + default:
  69541. + retval = -DWC_E_INVALID;
  69542. + DWC_ERROR("DWC OTG HCD - "
  69543. + "ClearHubFeature request %xh unknown\n",
  69544. + wValue);
  69545. + }
  69546. + break;
  69547. + case UCR_CLEAR_PORT_FEATURE:
  69548. +#ifdef CONFIG_USB_DWC_OTG_LPM
  69549. + if (wValue != UHF_PORT_L1)
  69550. +#endif
  69551. + if (!wIndex || wIndex > 1)
  69552. + goto error;
  69553. +
  69554. + switch (wValue) {
  69555. + case UHF_PORT_ENABLE:
  69556. + DWC_DEBUGPL(DBG_ANY, "DWC OTG HCD HUB CONTROL - "
  69557. + "ClearPortFeature USB_PORT_FEAT_ENABLE\n");
  69558. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  69559. + hprt0.b.prtena = 1;
  69560. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  69561. + break;
  69562. + case UHF_PORT_SUSPEND:
  69563. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  69564. + "ClearPortFeature USB_PORT_FEAT_SUSPEND\n");
  69565. +
  69566. + if (core_if->power_down == 2) {
  69567. + dwc_otg_host_hibernation_restore(core_if, 0, 0);
  69568. + } else {
  69569. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  69570. + dwc_mdelay(5);
  69571. +
  69572. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  69573. + hprt0.b.prtres = 1;
  69574. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  69575. + hprt0.b.prtsusp = 0;
  69576. + /* Clear Resume bit */
  69577. + dwc_mdelay(100);
  69578. + hprt0.b.prtres = 0;
  69579. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  69580. + }
  69581. + break;
  69582. +#ifdef CONFIG_USB_DWC_OTG_LPM
  69583. + case UHF_PORT_L1:
  69584. + {
  69585. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  69586. + glpmcfg_data_t lpmcfg = {.d32 = 0 };
  69587. +
  69588. + lpmcfg.d32 =
  69589. + DWC_READ_REG32(&core_if->
  69590. + core_global_regs->glpmcfg);
  69591. + lpmcfg.b.en_utmi_sleep = 0;
  69592. + lpmcfg.b.hird_thres &= (~(1 << 4));
  69593. + lpmcfg.b.prt_sleep_sts = 1;
  69594. + DWC_WRITE_REG32(&core_if->
  69595. + core_global_regs->glpmcfg,
  69596. + lpmcfg.d32);
  69597. +
  69598. + /* Clear Enbl_L1Gating bit. */
  69599. + pcgcctl.b.enbl_sleep_gating = 1;
  69600. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32,
  69601. + 0);
  69602. +
  69603. + dwc_mdelay(5);
  69604. +
  69605. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  69606. + hprt0.b.prtres = 1;
  69607. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  69608. + hprt0.d32);
  69609. + /* This bit will be cleared in wakeup interrupt handle */
  69610. + break;
  69611. + }
  69612. +#endif
  69613. + case UHF_PORT_POWER:
  69614. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  69615. + "ClearPortFeature USB_PORT_FEAT_POWER\n");
  69616. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  69617. + hprt0.b.prtpwr = 0;
  69618. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  69619. + break;
  69620. + case UHF_PORT_INDICATOR:
  69621. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  69622. + "ClearPortFeature USB_PORT_FEAT_INDICATOR\n");
  69623. + /* Port inidicator not supported */
  69624. + break;
  69625. + case UHF_C_PORT_CONNECTION:
  69626. + /* Clears drivers internal connect status change
  69627. + * flag */
  69628. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  69629. + "ClearPortFeature USB_PORT_FEAT_C_CONNECTION\n");
  69630. + dwc_otg_hcd->flags.b.port_connect_status_change = 0;
  69631. + break;
  69632. + case UHF_C_PORT_RESET:
  69633. + /* Clears the driver's internal Port Reset Change
  69634. + * flag */
  69635. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  69636. + "ClearPortFeature USB_PORT_FEAT_C_RESET\n");
  69637. + dwc_otg_hcd->flags.b.port_reset_change = 0;
  69638. + break;
  69639. + case UHF_C_PORT_ENABLE:
  69640. + /* Clears the driver's internal Port
  69641. + * Enable/Disable Change flag */
  69642. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  69643. + "ClearPortFeature USB_PORT_FEAT_C_ENABLE\n");
  69644. + dwc_otg_hcd->flags.b.port_enable_change = 0;
  69645. + break;
  69646. + case UHF_C_PORT_SUSPEND:
  69647. + /* Clears the driver's internal Port Suspend
  69648. + * Change flag, which is set when resume signaling on
  69649. + * the host port is complete */
  69650. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  69651. + "ClearPortFeature USB_PORT_FEAT_C_SUSPEND\n");
  69652. + dwc_otg_hcd->flags.b.port_suspend_change = 0;
  69653. + break;
  69654. +#ifdef CONFIG_USB_DWC_OTG_LPM
  69655. + case UHF_C_PORT_L1:
  69656. + dwc_otg_hcd->flags.b.port_l1_change = 0;
  69657. + break;
  69658. +#endif
  69659. + case UHF_C_PORT_OVER_CURRENT:
  69660. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  69661. + "ClearPortFeature USB_PORT_FEAT_C_OVER_CURRENT\n");
  69662. + dwc_otg_hcd->flags.b.port_over_current_change = 0;
  69663. + break;
  69664. + default:
  69665. + retval = -DWC_E_INVALID;
  69666. + DWC_ERROR("DWC OTG HCD - "
  69667. + "ClearPortFeature request %xh "
  69668. + "unknown or unsupported\n", wValue);
  69669. + }
  69670. + break;
  69671. + case UCR_GET_HUB_DESCRIPTOR:
  69672. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  69673. + "GetHubDescriptor\n");
  69674. + hub_desc = (usb_hub_descriptor_t *) buf;
  69675. + hub_desc->bDescLength = 9;
  69676. + hub_desc->bDescriptorType = 0x29;
  69677. + hub_desc->bNbrPorts = 1;
  69678. + USETW(hub_desc->wHubCharacteristics, 0x08);
  69679. + hub_desc->bPwrOn2PwrGood = 1;
  69680. + hub_desc->bHubContrCurrent = 0;
  69681. + hub_desc->DeviceRemovable[0] = 0;
  69682. + hub_desc->DeviceRemovable[1] = 0xff;
  69683. + break;
  69684. + case UCR_GET_HUB_STATUS:
  69685. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  69686. + "GetHubStatus\n");
  69687. + DWC_MEMSET(buf, 0, 4);
  69688. + break;
  69689. + case UCR_GET_PORT_STATUS:
  69690. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  69691. + "GetPortStatus wIndex = 0x%04x FLAGS=0x%08x\n",
  69692. + wIndex, dwc_otg_hcd->flags.d32);
  69693. + if (!wIndex || wIndex > 1)
  69694. + goto error;
  69695. +
  69696. + port_status = 0;
  69697. +
  69698. + if (dwc_otg_hcd->flags.b.port_connect_status_change)
  69699. + port_status |= (1 << UHF_C_PORT_CONNECTION);
  69700. +
  69701. + if (dwc_otg_hcd->flags.b.port_enable_change)
  69702. + port_status |= (1 << UHF_C_PORT_ENABLE);
  69703. +
  69704. + if (dwc_otg_hcd->flags.b.port_suspend_change)
  69705. + port_status |= (1 << UHF_C_PORT_SUSPEND);
  69706. +
  69707. + if (dwc_otg_hcd->flags.b.port_l1_change)
  69708. + port_status |= (1 << UHF_C_PORT_L1);
  69709. +
  69710. + if (dwc_otg_hcd->flags.b.port_reset_change) {
  69711. + port_status |= (1 << UHF_C_PORT_RESET);
  69712. + }
  69713. +
  69714. + if (dwc_otg_hcd->flags.b.port_over_current_change) {
  69715. + DWC_WARN("Overcurrent change detected\n");
  69716. + port_status |= (1 << UHF_C_PORT_OVER_CURRENT);
  69717. + }
  69718. +
  69719. + if (!dwc_otg_hcd->flags.b.port_connect_status) {
  69720. + /*
  69721. + * The port is disconnected, which means the core is
  69722. + * either in device mode or it soon will be. Just
  69723. + * return 0's for the remainder of the port status
  69724. + * since the port register can't be read if the core
  69725. + * is in device mode.
  69726. + */
  69727. + *((__le32 *) buf) = dwc_cpu_to_le32(&port_status);
  69728. + break;
  69729. + }
  69730. +
  69731. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  69732. + DWC_DEBUGPL(DBG_HCDV, " HPRT0: 0x%08x\n", hprt0.d32);
  69733. +
  69734. + if (hprt0.b.prtconnsts)
  69735. + port_status |= (1 << UHF_PORT_CONNECTION);
  69736. +
  69737. + if (hprt0.b.prtena)
  69738. + port_status |= (1 << UHF_PORT_ENABLE);
  69739. +
  69740. + if (hprt0.b.prtsusp)
  69741. + port_status |= (1 << UHF_PORT_SUSPEND);
  69742. +
  69743. + if (hprt0.b.prtovrcurract)
  69744. + port_status |= (1 << UHF_PORT_OVER_CURRENT);
  69745. +
  69746. + if (hprt0.b.prtrst)
  69747. + port_status |= (1 << UHF_PORT_RESET);
  69748. +
  69749. + if (hprt0.b.prtpwr)
  69750. + port_status |= (1 << UHF_PORT_POWER);
  69751. +
  69752. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED)
  69753. + port_status |= (1 << UHF_PORT_HIGH_SPEED);
  69754. + else if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED)
  69755. + port_status |= (1 << UHF_PORT_LOW_SPEED);
  69756. +
  69757. + if (hprt0.b.prttstctl)
  69758. + port_status |= (1 << UHF_PORT_TEST);
  69759. + if (dwc_otg_get_lpm_portsleepstatus(dwc_otg_hcd->core_if)) {
  69760. + port_status |= (1 << UHF_PORT_L1);
  69761. + }
  69762. + /*
  69763. + For Synopsys HW emulation of Power down wkup_control asserts the
  69764. + hreset_n and prst_n on suspned. This causes the HPRT0 to be zero.
  69765. + We intentionally tell the software that port is in L2Suspend state.
  69766. + Only for STE.
  69767. + */
  69768. + if ((core_if->power_down == 2)
  69769. + && (core_if->hibernation_suspend == 1)) {
  69770. + port_status |= (1 << UHF_PORT_SUSPEND);
  69771. + }
  69772. + /* USB_PORT_FEAT_INDICATOR unsupported always 0 */
  69773. +
  69774. + *((__le32 *) buf) = dwc_cpu_to_le32(&port_status);
  69775. +
  69776. + break;
  69777. + case UCR_SET_HUB_FEATURE:
  69778. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  69779. + "SetHubFeature\n");
  69780. + /* No HUB features supported */
  69781. + break;
  69782. + case UCR_SET_PORT_FEATURE:
  69783. + if (wValue != UHF_PORT_TEST && (!wIndex || wIndex > 1))
  69784. + goto error;
  69785. +
  69786. + if (!dwc_otg_hcd->flags.b.port_connect_status) {
  69787. + /*
  69788. + * The port is disconnected, which means the core is
  69789. + * either in device mode or it soon will be. Just
  69790. + * return without doing anything since the port
  69791. + * register can't be written if the core is in device
  69792. + * mode.
  69793. + */
  69794. + break;
  69795. + }
  69796. +
  69797. + switch (wValue) {
  69798. + case UHF_PORT_SUSPEND:
  69799. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  69800. + "SetPortFeature - USB_PORT_FEAT_SUSPEND\n");
  69801. + if (dwc_otg_hcd_otg_port(dwc_otg_hcd) != wIndex) {
  69802. + goto error;
  69803. + }
  69804. + if (core_if->power_down == 2) {
  69805. + int timeout = 300;
  69806. + dwc_irqflags_t flags;
  69807. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  69808. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  69809. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  69810. +#ifdef DWC_DEV_SRPCAP
  69811. + int32_t otg_cap_param = core_if->core_params->otg_cap;
  69812. +#endif
  69813. + DWC_PRINTF("Preparing for complete power-off\n");
  69814. +
  69815. + /* Save registers before hibernation */
  69816. + dwc_otg_save_global_regs(core_if);
  69817. + dwc_otg_save_host_regs(core_if);
  69818. +
  69819. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  69820. + hprt0.b.prtsusp = 1;
  69821. + hprt0.b.prtena = 0;
  69822. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  69823. + /* Spin hprt0.b.prtsusp to became 1 */
  69824. + do {
  69825. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  69826. + if (hprt0.b.prtsusp) {
  69827. + break;
  69828. + }
  69829. + dwc_mdelay(1);
  69830. + } while (--timeout);
  69831. + if (!timeout) {
  69832. + DWC_WARN("Suspend wasn't genereted\n");
  69833. + }
  69834. + dwc_udelay(10);
  69835. +
  69836. + /*
  69837. + * We need to disable interrupts to prevent servicing of any IRQ
  69838. + * during going to hibernation
  69839. + */
  69840. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  69841. + core_if->lx_state = DWC_OTG_L2;
  69842. +#ifdef DWC_DEV_SRPCAP
  69843. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  69844. + hprt0.b.prtpwr = 0;
  69845. + hprt0.b.prtena = 0;
  69846. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  69847. + hprt0.d32);
  69848. +#endif
  69849. + gusbcfg.d32 =
  69850. + DWC_READ_REG32(&core_if->core_global_regs->
  69851. + gusbcfg);
  69852. + if (gusbcfg.b.ulpi_utmi_sel == 1) {
  69853. + /* ULPI interface */
  69854. + /* Suspend the Phy Clock */
  69855. + pcgcctl.d32 = 0;
  69856. + pcgcctl.b.stoppclk = 1;
  69857. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  69858. + pcgcctl.d32);
  69859. + dwc_udelay(10);
  69860. + gpwrdn.b.pmuactv = 1;
  69861. + DWC_MODIFY_REG32(&core_if->
  69862. + core_global_regs->
  69863. + gpwrdn, 0, gpwrdn.d32);
  69864. + } else {
  69865. + /* UTMI+ Interface */
  69866. + gpwrdn.b.pmuactv = 1;
  69867. + DWC_MODIFY_REG32(&core_if->
  69868. + core_global_regs->
  69869. + gpwrdn, 0, gpwrdn.d32);
  69870. + dwc_udelay(10);
  69871. + pcgcctl.b.stoppclk = 1;
  69872. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  69873. + dwc_udelay(10);
  69874. + }
  69875. +#ifdef DWC_DEV_SRPCAP
  69876. + gpwrdn.d32 = 0;
  69877. + gpwrdn.b.dis_vbus = 1;
  69878. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  69879. + gpwrdn, 0, gpwrdn.d32);
  69880. +#endif
  69881. + gpwrdn.d32 = 0;
  69882. + gpwrdn.b.pmuintsel = 1;
  69883. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  69884. + gpwrdn, 0, gpwrdn.d32);
  69885. + dwc_udelay(10);
  69886. +
  69887. + gpwrdn.d32 = 0;
  69888. +#ifdef DWC_DEV_SRPCAP
  69889. + gpwrdn.b.srp_det_msk = 1;
  69890. +#endif
  69891. + gpwrdn.b.disconn_det_msk = 1;
  69892. + gpwrdn.b.lnstchng_msk = 1;
  69893. + gpwrdn.b.sts_chngint_msk = 1;
  69894. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  69895. + gpwrdn, 0, gpwrdn.d32);
  69896. + dwc_udelay(10);
  69897. +
  69898. + /* Enable Power Down Clamp and all interrupts in GPWRDN */
  69899. + gpwrdn.d32 = 0;
  69900. + gpwrdn.b.pwrdnclmp = 1;
  69901. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  69902. + gpwrdn, 0, gpwrdn.d32);
  69903. + dwc_udelay(10);
  69904. +
  69905. + /* Switch off VDD */
  69906. + gpwrdn.d32 = 0;
  69907. + gpwrdn.b.pwrdnswtch = 1;
  69908. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  69909. + gpwrdn, 0, gpwrdn.d32);
  69910. +
  69911. +#ifdef DWC_DEV_SRPCAP
  69912. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE)
  69913. + {
  69914. + core_if->pwron_timer_started = 1;
  69915. + DWC_TIMER_SCHEDULE(core_if->pwron_timer, 6000 /* 6 secs */ );
  69916. + }
  69917. +#endif
  69918. + /* Save gpwrdn register for further usage if stschng interrupt */
  69919. + core_if->gr_backup->gpwrdn_local =
  69920. + DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  69921. +
  69922. + /* Set flag to indicate that we are in hibernation */
  69923. + core_if->hibernation_suspend = 1;
  69924. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock,flags);
  69925. +
  69926. + DWC_PRINTF("Host hibernation completed\n");
  69927. + // Exit from case statement
  69928. + break;
  69929. +
  69930. + }
  69931. + if (dwc_otg_hcd_otg_port(dwc_otg_hcd) == wIndex &&
  69932. + dwc_otg_hcd->fops->get_b_hnp_enable(dwc_otg_hcd)) {
  69933. + gotgctl_data_t gotgctl = {.d32 = 0 };
  69934. + gotgctl.b.hstsethnpen = 1;
  69935. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  69936. + gotgctl, 0, gotgctl.d32);
  69937. + core_if->op_state = A_SUSPEND;
  69938. + }
  69939. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  69940. + hprt0.b.prtsusp = 1;
  69941. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  69942. + {
  69943. + dwc_irqflags_t flags;
  69944. + /* Update lx_state */
  69945. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  69946. + core_if->lx_state = DWC_OTG_L2;
  69947. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  69948. + }
  69949. + /* Suspend the Phy Clock */
  69950. + {
  69951. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  69952. + pcgcctl.b.stoppclk = 1;
  69953. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  69954. + pcgcctl.d32);
  69955. + dwc_udelay(10);
  69956. + }
  69957. +
  69958. + /* For HNP the bus must be suspended for at least 200ms. */
  69959. + if (dwc_otg_hcd->fops->get_b_hnp_enable(dwc_otg_hcd)) {
  69960. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  69961. + pcgcctl.b.stoppclk = 1;
  69962. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  69963. + dwc_mdelay(200);
  69964. + }
  69965. +
  69966. + /** @todo - check how sw can wait for 1 sec to check asesvld??? */
  69967. +#if 0 //vahrama !!!!!!!!!!!!!!!!!!
  69968. + if (core_if->adp_enable) {
  69969. + gotgctl_data_t gotgctl = {.d32 = 0 };
  69970. + gpwrdn_data_t gpwrdn;
  69971. +
  69972. + while (gotgctl.b.asesvld == 1) {
  69973. + gotgctl.d32 =
  69974. + DWC_READ_REG32(&core_if->
  69975. + core_global_regs->
  69976. + gotgctl);
  69977. + dwc_mdelay(100);
  69978. + }
  69979. +
  69980. + /* Enable Power Down Logic */
  69981. + gpwrdn.d32 = 0;
  69982. + gpwrdn.b.pmuactv = 1;
  69983. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  69984. + gpwrdn, 0, gpwrdn.d32);
  69985. +
  69986. + /* Unmask SRP detected interrupt from Power Down Logic */
  69987. + gpwrdn.d32 = 0;
  69988. + gpwrdn.b.srp_det_msk = 1;
  69989. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  69990. + gpwrdn, 0, gpwrdn.d32);
  69991. +
  69992. + dwc_otg_adp_probe_start(core_if);
  69993. + }
  69994. +#endif
  69995. + break;
  69996. + case UHF_PORT_POWER:
  69997. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  69998. + "SetPortFeature - USB_PORT_FEAT_POWER\n");
  69999. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  70000. + hprt0.b.prtpwr = 1;
  70001. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  70002. + break;
  70003. + case UHF_PORT_RESET:
  70004. + if ((core_if->power_down == 2)
  70005. + && (core_if->hibernation_suspend == 1)) {
  70006. + /* If we are going to exit from Hibernated
  70007. + * state via USB RESET.
  70008. + */
  70009. + dwc_otg_host_hibernation_restore(core_if, 0, 1);
  70010. + } else {
  70011. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  70012. +
  70013. + DWC_DEBUGPL(DBG_HCD,
  70014. + "DWC OTG HCD HUB CONTROL - "
  70015. + "SetPortFeature - USB_PORT_FEAT_RESET\n");
  70016. + {
  70017. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  70018. + pcgcctl.b.enbl_sleep_gating = 1;
  70019. + pcgcctl.b.stoppclk = 1;
  70020. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  70021. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  70022. + }
  70023. +#ifdef CONFIG_USB_DWC_OTG_LPM
  70024. + {
  70025. + glpmcfg_data_t lpmcfg;
  70026. + lpmcfg.d32 =
  70027. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  70028. + if (lpmcfg.b.prt_sleep_sts) {
  70029. + lpmcfg.b.en_utmi_sleep = 0;
  70030. + lpmcfg.b.hird_thres &= (~(1 << 4));
  70031. + DWC_WRITE_REG32
  70032. + (&core_if->core_global_regs->glpmcfg,
  70033. + lpmcfg.d32);
  70034. + dwc_mdelay(1);
  70035. + }
  70036. + }
  70037. +#endif
  70038. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  70039. + /* Clear suspend bit if resetting from suspended state. */
  70040. + hprt0.b.prtsusp = 0;
  70041. + /* When B-Host the Port reset bit is set in
  70042. + * the Start HCD Callback function, so that
  70043. + * the reset is started within 1ms of the HNP
  70044. + * success interrupt. */
  70045. + if (!dwc_otg_hcd_is_b_host(dwc_otg_hcd)) {
  70046. + hprt0.b.prtpwr = 1;
  70047. + hprt0.b.prtrst = 1;
  70048. + DWC_PRINTF("Indeed it is in host mode hprt0 = %08x\n",hprt0.d32);
  70049. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  70050. + hprt0.d32);
  70051. + }
  70052. + /* Clear reset bit in 10ms (FS/LS) or 50ms (HS) */
  70053. + dwc_mdelay(60);
  70054. + hprt0.b.prtrst = 0;
  70055. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  70056. + core_if->lx_state = DWC_OTG_L0; /* Now back to the on state */
  70057. + }
  70058. + break;
  70059. +#ifdef DWC_HS_ELECT_TST
  70060. + case UHF_PORT_TEST:
  70061. + {
  70062. + uint32_t t;
  70063. + gintmsk_data_t gintmsk;
  70064. +
  70065. + t = (wIndex >> 8); /* MSB wIndex USB */
  70066. + DWC_DEBUGPL(DBG_HCD,
  70067. + "DWC OTG HCD HUB CONTROL - "
  70068. + "SetPortFeature - USB_PORT_FEAT_TEST %d\n",
  70069. + t);
  70070. + DWC_WARN("USB_PORT_FEAT_TEST %d\n", t);
  70071. + if (t < 6) {
  70072. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  70073. + hprt0.b.prttstctl = t;
  70074. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  70075. + hprt0.d32);
  70076. + } else {
  70077. + /* Setup global vars with reg addresses (quick and
  70078. + * dirty hack, should be cleaned up)
  70079. + */
  70080. + global_regs = core_if->core_global_regs;
  70081. + hc_global_regs =
  70082. + core_if->host_if->host_global_regs;
  70083. + hc_regs =
  70084. + (dwc_otg_hc_regs_t *) ((char *)
  70085. + global_regs +
  70086. + 0x500);
  70087. + data_fifo =
  70088. + (uint32_t *) ((char *)global_regs +
  70089. + 0x1000);
  70090. +
  70091. + if (t == 6) { /* HS_HOST_PORT_SUSPEND_RESUME */
  70092. + /* Save current interrupt mask */
  70093. + gintmsk.d32 =
  70094. + DWC_READ_REG32
  70095. + (&global_regs->gintmsk);
  70096. +
  70097. + /* Disable all interrupts while we muck with
  70098. + * the hardware directly
  70099. + */
  70100. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  70101. +
  70102. + /* 15 second delay per the test spec */
  70103. + dwc_mdelay(15000);
  70104. +
  70105. + /* Drive suspend on the root port */
  70106. + hprt0.d32 =
  70107. + dwc_otg_read_hprt0(core_if);
  70108. + hprt0.b.prtsusp = 1;
  70109. + hprt0.b.prtres = 0;
  70110. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  70111. +
  70112. + /* 15 second delay per the test spec */
  70113. + dwc_mdelay(15000);
  70114. +
  70115. + /* Drive resume on the root port */
  70116. + hprt0.d32 =
  70117. + dwc_otg_read_hprt0(core_if);
  70118. + hprt0.b.prtsusp = 0;
  70119. + hprt0.b.prtres = 1;
  70120. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  70121. + dwc_mdelay(100);
  70122. +
  70123. + /* Clear the resume bit */
  70124. + hprt0.b.prtres = 0;
  70125. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  70126. +
  70127. + /* Restore interrupts */
  70128. + DWC_WRITE_REG32(&global_regs->gintmsk, gintmsk.d32);
  70129. + } else if (t == 7) { /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup */
  70130. + /* Save current interrupt mask */
  70131. + gintmsk.d32 =
  70132. + DWC_READ_REG32
  70133. + (&global_regs->gintmsk);
  70134. +
  70135. + /* Disable all interrupts while we muck with
  70136. + * the hardware directly
  70137. + */
  70138. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  70139. +
  70140. + /* 15 second delay per the test spec */
  70141. + dwc_mdelay(15000);
  70142. +
  70143. + /* Send the Setup packet */
  70144. + do_setup();
  70145. +
  70146. + /* 15 second delay so nothing else happens for awhile */
  70147. + dwc_mdelay(15000);
  70148. +
  70149. + /* Restore interrupts */
  70150. + DWC_WRITE_REG32(&global_regs->gintmsk, gintmsk.d32);
  70151. + } else if (t == 8) { /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute */
  70152. + /* Save current interrupt mask */
  70153. + gintmsk.d32 =
  70154. + DWC_READ_REG32
  70155. + (&global_regs->gintmsk);
  70156. +
  70157. + /* Disable all interrupts while we muck with
  70158. + * the hardware directly
  70159. + */
  70160. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  70161. +
  70162. + /* Send the Setup packet */
  70163. + do_setup();
  70164. +
  70165. + /* 15 second delay so nothing else happens for awhile */
  70166. + dwc_mdelay(15000);
  70167. +
  70168. + /* Send the In and Ack packets */
  70169. + do_in_ack();
  70170. +
  70171. + /* 15 second delay so nothing else happens for awhile */
  70172. + dwc_mdelay(15000);
  70173. +
  70174. + /* Restore interrupts */
  70175. + DWC_WRITE_REG32(&global_regs->gintmsk, gintmsk.d32);
  70176. + }
  70177. + }
  70178. + break;
  70179. + }
  70180. +#endif /* DWC_HS_ELECT_TST */
  70181. +
  70182. + case UHF_PORT_INDICATOR:
  70183. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  70184. + "SetPortFeature - USB_PORT_FEAT_INDICATOR\n");
  70185. + /* Not supported */
  70186. + break;
  70187. + default:
  70188. + retval = -DWC_E_INVALID;
  70189. + DWC_ERROR("DWC OTG HCD - "
  70190. + "SetPortFeature request %xh "
  70191. + "unknown or unsupported\n", wValue);
  70192. + break;
  70193. + }
  70194. + break;
  70195. +#ifdef CONFIG_USB_DWC_OTG_LPM
  70196. + case UCR_SET_AND_TEST_PORT_FEATURE:
  70197. + if (wValue != UHF_PORT_L1) {
  70198. + goto error;
  70199. + }
  70200. + {
  70201. + int portnum, hird, devaddr, remwake;
  70202. + glpmcfg_data_t lpmcfg;
  70203. + uint32_t time_usecs;
  70204. + gintsts_data_t gintsts;
  70205. + gintmsk_data_t gintmsk;
  70206. +
  70207. + if (!dwc_otg_get_param_lpm_enable(core_if)) {
  70208. + goto error;
  70209. + }
  70210. + if (wValue != UHF_PORT_L1 || wLength != 1) {
  70211. + goto error;
  70212. + }
  70213. + /* Check if the port currently is in SLEEP state */
  70214. + lpmcfg.d32 =
  70215. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  70216. + if (lpmcfg.b.prt_sleep_sts) {
  70217. + DWC_INFO("Port is already in sleep mode\n");
  70218. + buf[0] = 0; /* Return success */
  70219. + break;
  70220. + }
  70221. +
  70222. + portnum = wIndex & 0xf;
  70223. + hird = (wIndex >> 4) & 0xf;
  70224. + devaddr = (wIndex >> 8) & 0x7f;
  70225. + remwake = (wIndex >> 15);
  70226. +
  70227. + if (portnum != 1) {
  70228. + retval = -DWC_E_INVALID;
  70229. + DWC_WARN
  70230. + ("Wrong port number(%d) in SetandTestPortFeature request\n",
  70231. + portnum);
  70232. + break;
  70233. + }
  70234. +
  70235. + DWC_PRINTF
  70236. + ("SetandTestPortFeature request: portnum = %d, hird = %d, devaddr = %d, rewake = %d\n",
  70237. + portnum, hird, devaddr, remwake);
  70238. + /* Disable LPM interrupt */
  70239. + gintmsk.d32 = 0;
  70240. + gintmsk.b.lpmtranrcvd = 1;
  70241. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  70242. + gintmsk.d32, 0);
  70243. +
  70244. + if (dwc_otg_hcd_send_lpm
  70245. + (dwc_otg_hcd, devaddr, hird, remwake)) {
  70246. + retval = -DWC_E_INVALID;
  70247. + break;
  70248. + }
  70249. +
  70250. + time_usecs = 10 * (lpmcfg.b.retry_count + 1);
  70251. + /* We will consider timeout if time_usecs microseconds pass,
  70252. + * and we don't receive LPM transaction status.
  70253. + * After receiving non-error responce(ACK/NYET/STALL) from device,
  70254. + * core will set lpmtranrcvd bit.
  70255. + */
  70256. + do {
  70257. + gintsts.d32 =
  70258. + DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  70259. + if (gintsts.b.lpmtranrcvd) {
  70260. + break;
  70261. + }
  70262. + dwc_udelay(1);
  70263. + } while (--time_usecs);
  70264. + /* lpm_int bit will be cleared in LPM interrupt handler */
  70265. +
  70266. + /* Now fill status
  70267. + * 0x00 - Success
  70268. + * 0x10 - NYET
  70269. + * 0x11 - Timeout
  70270. + */
  70271. + if (!gintsts.b.lpmtranrcvd) {
  70272. + buf[0] = 0x3; /* Completion code is Timeout */
  70273. + dwc_otg_hcd_free_hc_from_lpm(dwc_otg_hcd);
  70274. + } else {
  70275. + lpmcfg.d32 =
  70276. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  70277. + if (lpmcfg.b.lpm_resp == 0x3) {
  70278. + /* ACK responce from the device */
  70279. + buf[0] = 0x00; /* Success */
  70280. + } else if (lpmcfg.b.lpm_resp == 0x2) {
  70281. + /* NYET responce from the device */
  70282. + buf[0] = 0x2;
  70283. + } else {
  70284. + /* Otherwise responce with Timeout */
  70285. + buf[0] = 0x3;
  70286. + }
  70287. + }
  70288. + DWC_PRINTF("Device responce to LPM trans is %x\n",
  70289. + lpmcfg.b.lpm_resp);
  70290. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0,
  70291. + gintmsk.d32);
  70292. +
  70293. + break;
  70294. + }
  70295. +#endif /* CONFIG_USB_DWC_OTG_LPM */
  70296. + default:
  70297. +error:
  70298. + retval = -DWC_E_INVALID;
  70299. + DWC_WARN("DWC OTG HCD - "
  70300. + "Unknown hub control request type or invalid typeReq: %xh wIndex: %xh wValue: %xh\n",
  70301. + typeReq, wIndex, wValue);
  70302. + break;
  70303. + }
  70304. +
  70305. + return retval;
  70306. +}
  70307. +
  70308. +#ifdef CONFIG_USB_DWC_OTG_LPM
  70309. +/** Returns index of host channel to perform LPM transaction. */
  70310. +int dwc_otg_hcd_get_hc_for_lpm_tran(dwc_otg_hcd_t * hcd, uint8_t devaddr)
  70311. +{
  70312. + dwc_otg_core_if_t *core_if = hcd->core_if;
  70313. + dwc_hc_t *hc;
  70314. + hcchar_data_t hcchar;
  70315. + gintmsk_data_t gintmsk = {.d32 = 0 };
  70316. +
  70317. + if (DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
  70318. + DWC_PRINTF("No free channel to select for LPM transaction\n");
  70319. + return -1;
  70320. + }
  70321. +
  70322. + hc = DWC_CIRCLEQ_FIRST(&hcd->free_hc_list);
  70323. +
  70324. + /* Mask host channel interrupts. */
  70325. + gintmsk.b.hcintr = 1;
  70326. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32, 0);
  70327. +
  70328. + /* Fill fields that core needs for LPM transaction */
  70329. + hcchar.b.devaddr = devaddr;
  70330. + hcchar.b.epnum = 0;
  70331. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  70332. + hcchar.b.mps = 64;
  70333. + hcchar.b.lspddev = (hc->speed == DWC_OTG_EP_SPEED_LOW);
  70334. + hcchar.b.epdir = 0; /* OUT */
  70335. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[hc->hc_num]->hcchar,
  70336. + hcchar.d32);
  70337. +
  70338. + /* Remove the host channel from the free list. */
  70339. + DWC_CIRCLEQ_REMOVE_INIT(&hcd->free_hc_list, hc, hc_list_entry);
  70340. +
  70341. + DWC_PRINTF("hcnum = %d devaddr = %d\n", hc->hc_num, devaddr);
  70342. +
  70343. + return hc->hc_num;
  70344. +}
  70345. +
  70346. +/** Release hc after performing LPM transaction */
  70347. +void dwc_otg_hcd_free_hc_from_lpm(dwc_otg_hcd_t * hcd)
  70348. +{
  70349. + dwc_hc_t *hc;
  70350. + glpmcfg_data_t lpmcfg;
  70351. + uint8_t hc_num;
  70352. +
  70353. + lpmcfg.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->glpmcfg);
  70354. + hc_num = lpmcfg.b.lpm_chan_index;
  70355. +
  70356. + hc = hcd->hc_ptr_array[hc_num];
  70357. +
  70358. + DWC_PRINTF("Freeing channel %d after LPM\n", hc_num);
  70359. + /* Return host channel to free list */
  70360. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, hc, hc_list_entry);
  70361. +}
  70362. +
  70363. +int dwc_otg_hcd_send_lpm(dwc_otg_hcd_t * hcd, uint8_t devaddr, uint8_t hird,
  70364. + uint8_t bRemoteWake)
  70365. +{
  70366. + glpmcfg_data_t lpmcfg;
  70367. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  70368. + int channel;
  70369. +
  70370. + channel = dwc_otg_hcd_get_hc_for_lpm_tran(hcd, devaddr);
  70371. + if (channel < 0) {
  70372. + return channel;
  70373. + }
  70374. +
  70375. + pcgcctl.b.enbl_sleep_gating = 1;
  70376. + DWC_MODIFY_REG32(hcd->core_if->pcgcctl, 0, pcgcctl.d32);
  70377. +
  70378. + /* Read LPM config register */
  70379. + lpmcfg.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->glpmcfg);
  70380. +
  70381. + /* Program LPM transaction fields */
  70382. + lpmcfg.b.rem_wkup_en = bRemoteWake;
  70383. + lpmcfg.b.hird = hird;
  70384. + lpmcfg.b.hird_thres = 0x1c;
  70385. + lpmcfg.b.lpm_chan_index = channel;
  70386. + lpmcfg.b.en_utmi_sleep = 1;
  70387. + /* Program LPM config register */
  70388. + DWC_WRITE_REG32(&hcd->core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  70389. +
  70390. + /* Send LPM transaction */
  70391. + lpmcfg.b.send_lpm = 1;
  70392. + DWC_WRITE_REG32(&hcd->core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  70393. +
  70394. + return 0;
  70395. +}
  70396. +
  70397. +#endif /* CONFIG_USB_DWC_OTG_LPM */
  70398. +
  70399. +int dwc_otg_hcd_is_status_changed(dwc_otg_hcd_t * hcd, int port)
  70400. +{
  70401. + int retval;
  70402. +
  70403. + if (port != 1) {
  70404. + return -DWC_E_INVALID;
  70405. + }
  70406. +
  70407. + retval = (hcd->flags.b.port_connect_status_change ||
  70408. + hcd->flags.b.port_reset_change ||
  70409. + hcd->flags.b.port_enable_change ||
  70410. + hcd->flags.b.port_suspend_change ||
  70411. + hcd->flags.b.port_over_current_change);
  70412. +#ifdef DEBUG
  70413. + if (retval) {
  70414. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB STATUS DATA:"
  70415. + " Root port status changed\n");
  70416. + DWC_DEBUGPL(DBG_HCDV, " port_connect_status_change: %d\n",
  70417. + hcd->flags.b.port_connect_status_change);
  70418. + DWC_DEBUGPL(DBG_HCDV, " port_reset_change: %d\n",
  70419. + hcd->flags.b.port_reset_change);
  70420. + DWC_DEBUGPL(DBG_HCDV, " port_enable_change: %d\n",
  70421. + hcd->flags.b.port_enable_change);
  70422. + DWC_DEBUGPL(DBG_HCDV, " port_suspend_change: %d\n",
  70423. + hcd->flags.b.port_suspend_change);
  70424. + DWC_DEBUGPL(DBG_HCDV, " port_over_current_change: %d\n",
  70425. + hcd->flags.b.port_over_current_change);
  70426. + }
  70427. +#endif
  70428. + return retval;
  70429. +}
  70430. +
  70431. +int dwc_otg_hcd_get_frame_number(dwc_otg_hcd_t * dwc_otg_hcd)
  70432. +{
  70433. + hfnum_data_t hfnum;
  70434. + hfnum.d32 =
  70435. + DWC_READ_REG32(&dwc_otg_hcd->core_if->host_if->host_global_regs->
  70436. + hfnum);
  70437. +
  70438. +#ifdef DEBUG_SOF
  70439. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD GET FRAME NUMBER %d\n",
  70440. + hfnum.b.frnum);
  70441. +#endif
  70442. + return hfnum.b.frnum;
  70443. +}
  70444. +
  70445. +int dwc_otg_hcd_start(dwc_otg_hcd_t * hcd,
  70446. + struct dwc_otg_hcd_function_ops *fops)
  70447. +{
  70448. + int retval = 0;
  70449. +
  70450. + hcd->fops = fops;
  70451. + if (!dwc_otg_is_device_mode(hcd->core_if) &&
  70452. + (!hcd->core_if->adp_enable || hcd->core_if->adp.adp_started)) {
  70453. + dwc_otg_hcd_reinit(hcd);
  70454. + } else {
  70455. + retval = -DWC_E_NO_DEVICE;
  70456. + }
  70457. +
  70458. + return retval;
  70459. +}
  70460. +
  70461. +void *dwc_otg_hcd_get_priv_data(dwc_otg_hcd_t * hcd)
  70462. +{
  70463. + return hcd->priv;
  70464. +}
  70465. +
  70466. +void dwc_otg_hcd_set_priv_data(dwc_otg_hcd_t * hcd, void *priv_data)
  70467. +{
  70468. + hcd->priv = priv_data;
  70469. +}
  70470. +
  70471. +uint32_t dwc_otg_hcd_otg_port(dwc_otg_hcd_t * hcd)
  70472. +{
  70473. + return hcd->otg_port;
  70474. +}
  70475. +
  70476. +uint32_t dwc_otg_hcd_is_b_host(dwc_otg_hcd_t * hcd)
  70477. +{
  70478. + uint32_t is_b_host;
  70479. + if (hcd->core_if->op_state == B_HOST) {
  70480. + is_b_host = 1;
  70481. + } else {
  70482. + is_b_host = 0;
  70483. + }
  70484. +
  70485. + return is_b_host;
  70486. +}
  70487. +
  70488. +dwc_otg_hcd_urb_t *dwc_otg_hcd_urb_alloc(dwc_otg_hcd_t * hcd,
  70489. + int iso_desc_count, int atomic_alloc)
  70490. +{
  70491. + dwc_otg_hcd_urb_t *dwc_otg_urb;
  70492. + uint32_t size;
  70493. +
  70494. + size =
  70495. + sizeof(*dwc_otg_urb) +
  70496. + iso_desc_count * sizeof(struct dwc_otg_hcd_iso_packet_desc);
  70497. + if (atomic_alloc)
  70498. + dwc_otg_urb = DWC_ALLOC_ATOMIC(size);
  70499. + else
  70500. + dwc_otg_urb = DWC_ALLOC(size);
  70501. +
  70502. + if (dwc_otg_urb)
  70503. + dwc_otg_urb->packet_count = iso_desc_count;
  70504. + else {
  70505. + DWC_ERROR("**** DWC OTG HCD URB alloc - "
  70506. + "%salloc of %db failed\n",
  70507. + atomic_alloc?"atomic ":"", size);
  70508. + }
  70509. + return dwc_otg_urb;
  70510. +}
  70511. +
  70512. +void dwc_otg_hcd_urb_set_pipeinfo(dwc_otg_hcd_urb_t * dwc_otg_urb,
  70513. + uint8_t dev_addr, uint8_t ep_num,
  70514. + uint8_t ep_type, uint8_t ep_dir, uint16_t mps)
  70515. +{
  70516. + dwc_otg_hcd_fill_pipe(&dwc_otg_urb->pipe_info, dev_addr, ep_num,
  70517. + ep_type, ep_dir, mps);
  70518. +#if 0
  70519. + DWC_PRINTF
  70520. + ("addr = %d, ep_num = %d, ep_dir = 0x%x, ep_type = 0x%x, mps = %d\n",
  70521. + dev_addr, ep_num, ep_dir, ep_type, mps);
  70522. +#endif
  70523. +}
  70524. +
  70525. +void dwc_otg_hcd_urb_set_params(dwc_otg_hcd_urb_t * dwc_otg_urb,
  70526. + void *urb_handle, void *buf, dwc_dma_t dma,
  70527. + uint32_t buflen, void *setup_packet,
  70528. + dwc_dma_t setup_dma, uint32_t flags,
  70529. + uint16_t interval)
  70530. +{
  70531. + dwc_otg_urb->priv = urb_handle;
  70532. + dwc_otg_urb->buf = buf;
  70533. + dwc_otg_urb->dma = dma;
  70534. + dwc_otg_urb->length = buflen;
  70535. + dwc_otg_urb->setup_packet = setup_packet;
  70536. + dwc_otg_urb->setup_dma = setup_dma;
  70537. + dwc_otg_urb->flags = flags;
  70538. + dwc_otg_urb->interval = interval;
  70539. + dwc_otg_urb->status = -DWC_E_IN_PROGRESS;
  70540. +}
  70541. +
  70542. +uint32_t dwc_otg_hcd_urb_get_status(dwc_otg_hcd_urb_t * dwc_otg_urb)
  70543. +{
  70544. + return dwc_otg_urb->status;
  70545. +}
  70546. +
  70547. +uint32_t dwc_otg_hcd_urb_get_actual_length(dwc_otg_hcd_urb_t * dwc_otg_urb)
  70548. +{
  70549. + return dwc_otg_urb->actual_length;
  70550. +}
  70551. +
  70552. +uint32_t dwc_otg_hcd_urb_get_error_count(dwc_otg_hcd_urb_t * dwc_otg_urb)
  70553. +{
  70554. + return dwc_otg_urb->error_count;
  70555. +}
  70556. +
  70557. +void dwc_otg_hcd_urb_set_iso_desc_params(dwc_otg_hcd_urb_t * dwc_otg_urb,
  70558. + int desc_num, uint32_t offset,
  70559. + uint32_t length)
  70560. +{
  70561. + dwc_otg_urb->iso_descs[desc_num].offset = offset;
  70562. + dwc_otg_urb->iso_descs[desc_num].length = length;
  70563. +}
  70564. +
  70565. +uint32_t dwc_otg_hcd_urb_get_iso_desc_status(dwc_otg_hcd_urb_t * dwc_otg_urb,
  70566. + int desc_num)
  70567. +{
  70568. + return dwc_otg_urb->iso_descs[desc_num].status;
  70569. +}
  70570. +
  70571. +uint32_t dwc_otg_hcd_urb_get_iso_desc_actual_length(dwc_otg_hcd_urb_t *
  70572. + dwc_otg_urb, int desc_num)
  70573. +{
  70574. + return dwc_otg_urb->iso_descs[desc_num].actual_length;
  70575. +}
  70576. +
  70577. +int dwc_otg_hcd_is_bandwidth_allocated(dwc_otg_hcd_t * hcd, void *ep_handle)
  70578. +{
  70579. + int allocated = 0;
  70580. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  70581. +
  70582. + if (qh) {
  70583. + if (!DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  70584. + allocated = 1;
  70585. + }
  70586. + }
  70587. + return allocated;
  70588. +}
  70589. +
  70590. +int dwc_otg_hcd_is_bandwidth_freed(dwc_otg_hcd_t * hcd, void *ep_handle)
  70591. +{
  70592. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  70593. + int freed = 0;
  70594. + DWC_ASSERT(qh, "qh is not allocated\n");
  70595. +
  70596. + if (DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  70597. + freed = 1;
  70598. + }
  70599. +
  70600. + return freed;
  70601. +}
  70602. +
  70603. +uint8_t dwc_otg_hcd_get_ep_bandwidth(dwc_otg_hcd_t * hcd, void *ep_handle)
  70604. +{
  70605. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  70606. + DWC_ASSERT(qh, "qh is not allocated\n");
  70607. + return qh->usecs;
  70608. +}
  70609. +
  70610. +void dwc_otg_hcd_dump_state(dwc_otg_hcd_t * hcd)
  70611. +{
  70612. +#ifdef DEBUG
  70613. + int num_channels;
  70614. + int i;
  70615. + gnptxsts_data_t np_tx_status;
  70616. + hptxsts_data_t p_tx_status;
  70617. +
  70618. + num_channels = hcd->core_if->core_params->host_channels;
  70619. + DWC_PRINTF("\n");
  70620. + DWC_PRINTF
  70621. + ("************************************************************\n");
  70622. + DWC_PRINTF("HCD State:\n");
  70623. + DWC_PRINTF(" Num channels: %d\n", num_channels);
  70624. + for (i = 0; i < num_channels; i++) {
  70625. + dwc_hc_t *hc = hcd->hc_ptr_array[i];
  70626. + DWC_PRINTF(" Channel %d:\n", i);
  70627. + DWC_PRINTF(" dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
  70628. + hc->dev_addr, hc->ep_num, hc->ep_is_in);
  70629. + DWC_PRINTF(" speed: %d\n", hc->speed);
  70630. + DWC_PRINTF(" ep_type: %d\n", hc->ep_type);
  70631. + DWC_PRINTF(" max_packet: %d\n", hc->max_packet);
  70632. + DWC_PRINTF(" data_pid_start: %d\n", hc->data_pid_start);
  70633. + DWC_PRINTF(" multi_count: %d\n", hc->multi_count);
  70634. + DWC_PRINTF(" xfer_started: %d\n", hc->xfer_started);
  70635. + DWC_PRINTF(" xfer_buff: %p\n", hc->xfer_buff);
  70636. + DWC_PRINTF(" xfer_len: %d\n", hc->xfer_len);
  70637. + DWC_PRINTF(" xfer_count: %d\n", hc->xfer_count);
  70638. + DWC_PRINTF(" halt_on_queue: %d\n", hc->halt_on_queue);
  70639. + DWC_PRINTF(" halt_pending: %d\n", hc->halt_pending);
  70640. + DWC_PRINTF(" halt_status: %d\n", hc->halt_status);
  70641. + DWC_PRINTF(" do_split: %d\n", hc->do_split);
  70642. + DWC_PRINTF(" complete_split: %d\n", hc->complete_split);
  70643. + DWC_PRINTF(" hub_addr: %d\n", hc->hub_addr);
  70644. + DWC_PRINTF(" port_addr: %d\n", hc->port_addr);
  70645. + DWC_PRINTF(" xact_pos: %d\n", hc->xact_pos);
  70646. + DWC_PRINTF(" requests: %d\n", hc->requests);
  70647. + DWC_PRINTF(" qh: %p\n", hc->qh);
  70648. + if (hc->xfer_started) {
  70649. + hfnum_data_t hfnum;
  70650. + hcchar_data_t hcchar;
  70651. + hctsiz_data_t hctsiz;
  70652. + hcint_data_t hcint;
  70653. + hcintmsk_data_t hcintmsk;
  70654. + hfnum.d32 =
  70655. + DWC_READ_REG32(&hcd->core_if->
  70656. + host_if->host_global_regs->hfnum);
  70657. + hcchar.d32 =
  70658. + DWC_READ_REG32(&hcd->core_if->host_if->
  70659. + hc_regs[i]->hcchar);
  70660. + hctsiz.d32 =
  70661. + DWC_READ_REG32(&hcd->core_if->host_if->
  70662. + hc_regs[i]->hctsiz);
  70663. + hcint.d32 =
  70664. + DWC_READ_REG32(&hcd->core_if->host_if->
  70665. + hc_regs[i]->hcint);
  70666. + hcintmsk.d32 =
  70667. + DWC_READ_REG32(&hcd->core_if->host_if->
  70668. + hc_regs[i]->hcintmsk);
  70669. + DWC_PRINTF(" hfnum: 0x%08x\n", hfnum.d32);
  70670. + DWC_PRINTF(" hcchar: 0x%08x\n", hcchar.d32);
  70671. + DWC_PRINTF(" hctsiz: 0x%08x\n", hctsiz.d32);
  70672. + DWC_PRINTF(" hcint: 0x%08x\n", hcint.d32);
  70673. + DWC_PRINTF(" hcintmsk: 0x%08x\n", hcintmsk.d32);
  70674. + }
  70675. + if (hc->xfer_started && hc->qh) {
  70676. + dwc_otg_qtd_t *qtd;
  70677. + dwc_otg_hcd_urb_t *urb;
  70678. +
  70679. + DWC_CIRCLEQ_FOREACH(qtd, &hc->qh->qtd_list, qtd_list_entry) {
  70680. + if (!qtd->in_process)
  70681. + break;
  70682. +
  70683. + urb = qtd->urb;
  70684. + DWC_PRINTF(" URB Info:\n");
  70685. + DWC_PRINTF(" qtd: %p, urb: %p\n", qtd, urb);
  70686. + if (urb) {
  70687. + DWC_PRINTF(" Dev: %d, EP: %d %s\n",
  70688. + dwc_otg_hcd_get_dev_addr(&urb->
  70689. + pipe_info),
  70690. + dwc_otg_hcd_get_ep_num(&urb->
  70691. + pipe_info),
  70692. + dwc_otg_hcd_is_pipe_in(&urb->
  70693. + pipe_info) ?
  70694. + "IN" : "OUT");
  70695. + DWC_PRINTF(" Max packet size: %d\n",
  70696. + dwc_otg_hcd_get_mps(&urb->
  70697. + pipe_info));
  70698. + DWC_PRINTF(" transfer_buffer: %p\n",
  70699. + urb->buf);
  70700. + DWC_PRINTF(" transfer_dma: %p\n",
  70701. + (void *)urb->dma);
  70702. + DWC_PRINTF(" transfer_buffer_length: %d\n",
  70703. + urb->length);
  70704. + DWC_PRINTF(" actual_length: %d\n",
  70705. + urb->actual_length);
  70706. + }
  70707. + }
  70708. + }
  70709. + }
  70710. + DWC_PRINTF(" non_periodic_channels: %d\n", hcd->non_periodic_channels);
  70711. + DWC_PRINTF(" periodic_channels: %d\n", hcd->periodic_channels);
  70712. + DWC_PRINTF(" periodic_usecs: %d\n", hcd->periodic_usecs);
  70713. + np_tx_status.d32 =
  70714. + DWC_READ_REG32(&hcd->core_if->core_global_regs->gnptxsts);
  70715. + DWC_PRINTF(" NP Tx Req Queue Space Avail: %d\n",
  70716. + np_tx_status.b.nptxqspcavail);
  70717. + DWC_PRINTF(" NP Tx FIFO Space Avail: %d\n",
  70718. + np_tx_status.b.nptxfspcavail);
  70719. + p_tx_status.d32 =
  70720. + DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hptxsts);
  70721. + DWC_PRINTF(" P Tx Req Queue Space Avail: %d\n",
  70722. + p_tx_status.b.ptxqspcavail);
  70723. + DWC_PRINTF(" P Tx FIFO Space Avail: %d\n", p_tx_status.b.ptxfspcavail);
  70724. + dwc_otg_hcd_dump_frrem(hcd);
  70725. + dwc_otg_dump_global_registers(hcd->core_if);
  70726. + dwc_otg_dump_host_registers(hcd->core_if);
  70727. + DWC_PRINTF
  70728. + ("************************************************************\n");
  70729. + DWC_PRINTF("\n");
  70730. +#endif
  70731. +}
  70732. +
  70733. +#ifdef DEBUG
  70734. +void dwc_print_setup_data(uint8_t * setup)
  70735. +{
  70736. + int i;
  70737. + if (CHK_DEBUG_LEVEL(DBG_HCD)) {
  70738. + DWC_PRINTF("Setup Data = MSB ");
  70739. + for (i = 7; i >= 0; i--)
  70740. + DWC_PRINTF("%02x ", setup[i]);
  70741. + DWC_PRINTF("\n");
  70742. + DWC_PRINTF(" bmRequestType Tranfer = %s\n",
  70743. + (setup[0] & 0x80) ? "Device-to-Host" :
  70744. + "Host-to-Device");
  70745. + DWC_PRINTF(" bmRequestType Type = ");
  70746. + switch ((setup[0] & 0x60) >> 5) {
  70747. + case 0:
  70748. + DWC_PRINTF("Standard\n");
  70749. + break;
  70750. + case 1:
  70751. + DWC_PRINTF("Class\n");
  70752. + break;
  70753. + case 2:
  70754. + DWC_PRINTF("Vendor\n");
  70755. + break;
  70756. + case 3:
  70757. + DWC_PRINTF("Reserved\n");
  70758. + break;
  70759. + }
  70760. + DWC_PRINTF(" bmRequestType Recipient = ");
  70761. + switch (setup[0] & 0x1f) {
  70762. + case 0:
  70763. + DWC_PRINTF("Device\n");
  70764. + break;
  70765. + case 1:
  70766. + DWC_PRINTF("Interface\n");
  70767. + break;
  70768. + case 2:
  70769. + DWC_PRINTF("Endpoint\n");
  70770. + break;
  70771. + case 3:
  70772. + DWC_PRINTF("Other\n");
  70773. + break;
  70774. + default:
  70775. + DWC_PRINTF("Reserved\n");
  70776. + break;
  70777. + }
  70778. + DWC_PRINTF(" bRequest = 0x%0x\n", setup[1]);
  70779. + DWC_PRINTF(" wValue = 0x%0x\n", *((uint16_t *) & setup[2]));
  70780. + DWC_PRINTF(" wIndex = 0x%0x\n", *((uint16_t *) & setup[4]));
  70781. + DWC_PRINTF(" wLength = 0x%0x\n\n", *((uint16_t *) & setup[6]));
  70782. + }
  70783. +}
  70784. +#endif
  70785. +
  70786. +void dwc_otg_hcd_dump_frrem(dwc_otg_hcd_t * hcd)
  70787. +{
  70788. +#if 0
  70789. + DWC_PRINTF("Frame remaining at SOF:\n");
  70790. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  70791. + hcd->frrem_samples, hcd->frrem_accum,
  70792. + (hcd->frrem_samples > 0) ?
  70793. + hcd->frrem_accum / hcd->frrem_samples : 0);
  70794. +
  70795. + DWC_PRINTF("\n");
  70796. + DWC_PRINTF("Frame remaining at start_transfer (uframe 7):\n");
  70797. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  70798. + hcd->core_if->hfnum_7_samples,
  70799. + hcd->core_if->hfnum_7_frrem_accum,
  70800. + (hcd->core_if->hfnum_7_samples >
  70801. + 0) ? hcd->core_if->hfnum_7_frrem_accum /
  70802. + hcd->core_if->hfnum_7_samples : 0);
  70803. + DWC_PRINTF("Frame remaining at start_transfer (uframe 0):\n");
  70804. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  70805. + hcd->core_if->hfnum_0_samples,
  70806. + hcd->core_if->hfnum_0_frrem_accum,
  70807. + (hcd->core_if->hfnum_0_samples >
  70808. + 0) ? hcd->core_if->hfnum_0_frrem_accum /
  70809. + hcd->core_if->hfnum_0_samples : 0);
  70810. + DWC_PRINTF("Frame remaining at start_transfer (uframe 1-6):\n");
  70811. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  70812. + hcd->core_if->hfnum_other_samples,
  70813. + hcd->core_if->hfnum_other_frrem_accum,
  70814. + (hcd->core_if->hfnum_other_samples >
  70815. + 0) ? hcd->core_if->hfnum_other_frrem_accum /
  70816. + hcd->core_if->hfnum_other_samples : 0);
  70817. +
  70818. + DWC_PRINTF("\n");
  70819. + DWC_PRINTF("Frame remaining at sample point A (uframe 7):\n");
  70820. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  70821. + hcd->hfnum_7_samples_a, hcd->hfnum_7_frrem_accum_a,
  70822. + (hcd->hfnum_7_samples_a > 0) ?
  70823. + hcd->hfnum_7_frrem_accum_a / hcd->hfnum_7_samples_a : 0);
  70824. + DWC_PRINTF("Frame remaining at sample point A (uframe 0):\n");
  70825. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  70826. + hcd->hfnum_0_samples_a, hcd->hfnum_0_frrem_accum_a,
  70827. + (hcd->hfnum_0_samples_a > 0) ?
  70828. + hcd->hfnum_0_frrem_accum_a / hcd->hfnum_0_samples_a : 0);
  70829. + DWC_PRINTF("Frame remaining at sample point A (uframe 1-6):\n");
  70830. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  70831. + hcd->hfnum_other_samples_a, hcd->hfnum_other_frrem_accum_a,
  70832. + (hcd->hfnum_other_samples_a > 0) ?
  70833. + hcd->hfnum_other_frrem_accum_a /
  70834. + hcd->hfnum_other_samples_a : 0);
  70835. +
  70836. + DWC_PRINTF("\n");
  70837. + DWC_PRINTF("Frame remaining at sample point B (uframe 7):\n");
  70838. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  70839. + hcd->hfnum_7_samples_b, hcd->hfnum_7_frrem_accum_b,
  70840. + (hcd->hfnum_7_samples_b > 0) ?
  70841. + hcd->hfnum_7_frrem_accum_b / hcd->hfnum_7_samples_b : 0);
  70842. + DWC_PRINTF("Frame remaining at sample point B (uframe 0):\n");
  70843. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  70844. + hcd->hfnum_0_samples_b, hcd->hfnum_0_frrem_accum_b,
  70845. + (hcd->hfnum_0_samples_b > 0) ?
  70846. + hcd->hfnum_0_frrem_accum_b / hcd->hfnum_0_samples_b : 0);
  70847. + DWC_PRINTF("Frame remaining at sample point B (uframe 1-6):\n");
  70848. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  70849. + hcd->hfnum_other_samples_b, hcd->hfnum_other_frrem_accum_b,
  70850. + (hcd->hfnum_other_samples_b > 0) ?
  70851. + hcd->hfnum_other_frrem_accum_b /
  70852. + hcd->hfnum_other_samples_b : 0);
  70853. +#endif
  70854. +}
  70855. +
  70856. +#endif /* DWC_DEVICE_ONLY */
  70857. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c
  70858. --- linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c 1970-01-01 01:00:00.000000000 +0100
  70859. +++ linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c 2014-02-17 22:41:01.000000000 +0100
  70860. @@ -0,0 +1,1132 @@
  70861. +/*==========================================================================
  70862. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_ddma.c $
  70863. + * $Revision: #10 $
  70864. + * $Date: 2011/10/20 $
  70865. + * $Change: 1869464 $
  70866. + *
  70867. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  70868. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  70869. + * otherwise expressly agreed to in writing between Synopsys and you.
  70870. + *
  70871. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  70872. + * any End User Software License Agreement or Agreement for Licensed Product
  70873. + * with Synopsys or any supplement thereto. You are permitted to use and
  70874. + * redistribute this Software in source and binary forms, with or without
  70875. + * modification, provided that redistributions of source code must retain this
  70876. + * notice. You may not view, use, disclose, copy or distribute this file or
  70877. + * any information contained herein except pursuant to this license grant from
  70878. + * Synopsys. If you do not agree with this notice, including the disclaimer
  70879. + * below, then you are not authorized to use the Software.
  70880. + *
  70881. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  70882. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  70883. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  70884. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  70885. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  70886. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  70887. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  70888. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  70889. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  70890. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  70891. + * DAMAGE.
  70892. + * ========================================================================== */
  70893. +#ifndef DWC_DEVICE_ONLY
  70894. +
  70895. +/** @file
  70896. + * This file contains Descriptor DMA support implementation for host mode.
  70897. + */
  70898. +
  70899. +#include "dwc_otg_hcd.h"
  70900. +#include "dwc_otg_regs.h"
  70901. +
  70902. +extern bool microframe_schedule;
  70903. +
  70904. +static inline uint8_t frame_list_idx(uint16_t frame)
  70905. +{
  70906. + return (frame & (MAX_FRLIST_EN_NUM - 1));
  70907. +}
  70908. +
  70909. +static inline uint16_t desclist_idx_inc(uint16_t idx, uint16_t inc, uint8_t speed)
  70910. +{
  70911. + return (idx + inc) &
  70912. + (((speed ==
  70913. + DWC_OTG_EP_SPEED_HIGH) ? MAX_DMA_DESC_NUM_HS_ISOC :
  70914. + MAX_DMA_DESC_NUM_GENERIC) - 1);
  70915. +}
  70916. +
  70917. +static inline uint16_t desclist_idx_dec(uint16_t idx, uint16_t inc, uint8_t speed)
  70918. +{
  70919. + return (idx - inc) &
  70920. + (((speed ==
  70921. + DWC_OTG_EP_SPEED_HIGH) ? MAX_DMA_DESC_NUM_HS_ISOC :
  70922. + MAX_DMA_DESC_NUM_GENERIC) - 1);
  70923. +}
  70924. +
  70925. +static inline uint16_t max_desc_num(dwc_otg_qh_t * qh)
  70926. +{
  70927. + return (((qh->ep_type == UE_ISOCHRONOUS)
  70928. + && (qh->dev_speed == DWC_OTG_EP_SPEED_HIGH))
  70929. + ? MAX_DMA_DESC_NUM_HS_ISOC : MAX_DMA_DESC_NUM_GENERIC);
  70930. +}
  70931. +static inline uint16_t frame_incr_val(dwc_otg_qh_t * qh)
  70932. +{
  70933. + return ((qh->dev_speed == DWC_OTG_EP_SPEED_HIGH)
  70934. + ? ((qh->interval + 8 - 1) / 8)
  70935. + : qh->interval);
  70936. +}
  70937. +
  70938. +static int desc_list_alloc(dwc_otg_qh_t * qh)
  70939. +{
  70940. + int retval = 0;
  70941. +
  70942. + qh->desc_list = (dwc_otg_host_dma_desc_t *)
  70943. + DWC_DMA_ALLOC(sizeof(dwc_otg_host_dma_desc_t) * max_desc_num(qh),
  70944. + &qh->desc_list_dma);
  70945. +
  70946. + if (!qh->desc_list) {
  70947. + retval = -DWC_E_NO_MEMORY;
  70948. + DWC_ERROR("%s: DMA descriptor list allocation failed\n", __func__);
  70949. +
  70950. + }
  70951. +
  70952. + dwc_memset(qh->desc_list, 0x00,
  70953. + sizeof(dwc_otg_host_dma_desc_t) * max_desc_num(qh));
  70954. +
  70955. + qh->n_bytes =
  70956. + (uint32_t *) DWC_ALLOC(sizeof(uint32_t) * max_desc_num(qh));
  70957. +
  70958. + if (!qh->n_bytes) {
  70959. + retval = -DWC_E_NO_MEMORY;
  70960. + DWC_ERROR
  70961. + ("%s: Failed to allocate array for descriptors' size actual values\n",
  70962. + __func__);
  70963. +
  70964. + }
  70965. + return retval;
  70966. +
  70967. +}
  70968. +
  70969. +static void desc_list_free(dwc_otg_qh_t * qh)
  70970. +{
  70971. + if (qh->desc_list) {
  70972. + DWC_DMA_FREE(max_desc_num(qh), qh->desc_list,
  70973. + qh->desc_list_dma);
  70974. + qh->desc_list = NULL;
  70975. + }
  70976. +
  70977. + if (qh->n_bytes) {
  70978. + DWC_FREE(qh->n_bytes);
  70979. + qh->n_bytes = NULL;
  70980. + }
  70981. +}
  70982. +
  70983. +static int frame_list_alloc(dwc_otg_hcd_t * hcd)
  70984. +{
  70985. + int retval = 0;
  70986. + if (hcd->frame_list)
  70987. + return 0;
  70988. +
  70989. + hcd->frame_list = DWC_DMA_ALLOC(4 * MAX_FRLIST_EN_NUM,
  70990. + &hcd->frame_list_dma);
  70991. + if (!hcd->frame_list) {
  70992. + retval = -DWC_E_NO_MEMORY;
  70993. + DWC_ERROR("%s: Frame List allocation failed\n", __func__);
  70994. + }
  70995. +
  70996. + dwc_memset(hcd->frame_list, 0x00, 4 * MAX_FRLIST_EN_NUM);
  70997. +
  70998. + return retval;
  70999. +}
  71000. +
  71001. +static void frame_list_free(dwc_otg_hcd_t * hcd)
  71002. +{
  71003. + if (!hcd->frame_list)
  71004. + return;
  71005. +
  71006. + DWC_DMA_FREE(4 * MAX_FRLIST_EN_NUM, hcd->frame_list, hcd->frame_list_dma);
  71007. + hcd->frame_list = NULL;
  71008. +}
  71009. +
  71010. +static void per_sched_enable(dwc_otg_hcd_t * hcd, uint16_t fr_list_en)
  71011. +{
  71012. +
  71013. + hcfg_data_t hcfg;
  71014. +
  71015. + hcfg.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hcfg);
  71016. +
  71017. + if (hcfg.b.perschedena) {
  71018. + /* already enabled */
  71019. + return;
  71020. + }
  71021. +
  71022. + DWC_WRITE_REG32(&hcd->core_if->host_if->host_global_regs->hflbaddr,
  71023. + hcd->frame_list_dma);
  71024. +
  71025. + switch (fr_list_en) {
  71026. + case 64:
  71027. + hcfg.b.frlisten = 3;
  71028. + break;
  71029. + case 32:
  71030. + hcfg.b.frlisten = 2;
  71031. + break;
  71032. + case 16:
  71033. + hcfg.b.frlisten = 1;
  71034. + break;
  71035. + case 8:
  71036. + hcfg.b.frlisten = 0;
  71037. + break;
  71038. + default:
  71039. + break;
  71040. + }
  71041. +
  71042. + hcfg.b.perschedena = 1;
  71043. +
  71044. + DWC_DEBUGPL(DBG_HCD, "Enabling Periodic schedule\n");
  71045. + DWC_WRITE_REG32(&hcd->core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  71046. +
  71047. +}
  71048. +
  71049. +static void per_sched_disable(dwc_otg_hcd_t * hcd)
  71050. +{
  71051. + hcfg_data_t hcfg;
  71052. +
  71053. + hcfg.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hcfg);
  71054. +
  71055. + if (!hcfg.b.perschedena) {
  71056. + /* already disabled */
  71057. + return;
  71058. + }
  71059. + hcfg.b.perschedena = 0;
  71060. +
  71061. + DWC_DEBUGPL(DBG_HCD, "Disabling Periodic schedule\n");
  71062. + DWC_WRITE_REG32(&hcd->core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  71063. +}
  71064. +
  71065. +/*
  71066. + * Activates/Deactivates FrameList entries for the channel
  71067. + * based on endpoint servicing period.
  71068. + */
  71069. +void update_frame_list(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh, uint8_t enable)
  71070. +{
  71071. + uint16_t i, j, inc;
  71072. + dwc_hc_t *hc = NULL;
  71073. +
  71074. + if (!qh->channel) {
  71075. + DWC_ERROR("qh->channel = %p", qh->channel);
  71076. + return;
  71077. + }
  71078. +
  71079. + if (!hcd) {
  71080. + DWC_ERROR("------hcd = %p", hcd);
  71081. + return;
  71082. + }
  71083. +
  71084. + if (!hcd->frame_list) {
  71085. + DWC_ERROR("-------hcd->frame_list = %p", hcd->frame_list);
  71086. + return;
  71087. + }
  71088. +
  71089. + hc = qh->channel;
  71090. + inc = frame_incr_val(qh);
  71091. + if (qh->ep_type == UE_ISOCHRONOUS)
  71092. + i = frame_list_idx(qh->sched_frame);
  71093. + else
  71094. + i = 0;
  71095. +
  71096. + j = i;
  71097. + do {
  71098. + if (enable)
  71099. + hcd->frame_list[j] |= (1 << hc->hc_num);
  71100. + else
  71101. + hcd->frame_list[j] &= ~(1 << hc->hc_num);
  71102. + j = (j + inc) & (MAX_FRLIST_EN_NUM - 1);
  71103. + }
  71104. + while (j != i);
  71105. + if (!enable)
  71106. + return;
  71107. + hc->schinfo = 0;
  71108. + if (qh->channel->speed == DWC_OTG_EP_SPEED_HIGH) {
  71109. + j = 1;
  71110. + /* TODO - check this */
  71111. + inc = (8 + qh->interval - 1) / qh->interval;
  71112. + for (i = 0; i < inc; i++) {
  71113. + hc->schinfo |= j;
  71114. + j = j << qh->interval;
  71115. + }
  71116. + } else {
  71117. + hc->schinfo = 0xff;
  71118. + }
  71119. +}
  71120. +
  71121. +#if 1
  71122. +void dump_frame_list(dwc_otg_hcd_t * hcd)
  71123. +{
  71124. + int i = 0;
  71125. + DWC_PRINTF("--FRAME LIST (hex) --\n");
  71126. + for (i = 0; i < MAX_FRLIST_EN_NUM; i++) {
  71127. + DWC_PRINTF("%x\t", hcd->frame_list[i]);
  71128. + if (!(i % 8) && i)
  71129. + DWC_PRINTF("\n");
  71130. + }
  71131. + DWC_PRINTF("\n----\n");
  71132. +
  71133. +}
  71134. +#endif
  71135. +
  71136. +static void release_channel_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  71137. +{
  71138. + dwc_irqflags_t flags;
  71139. + dwc_spinlock_t *channel_lock = hcd->channel_lock;
  71140. +
  71141. + dwc_hc_t *hc = qh->channel;
  71142. + if (dwc_qh_is_non_per(qh)) {
  71143. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  71144. + if (!microframe_schedule)
  71145. + hcd->non_periodic_channels--;
  71146. + else
  71147. + hcd->available_host_channels++;
  71148. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  71149. + } else
  71150. + update_frame_list(hcd, qh, 0);
  71151. +
  71152. + /*
  71153. + * The condition is added to prevent double cleanup try in case of device
  71154. + * disconnect. See channel cleanup in dwc_otg_hcd_disconnect_cb().
  71155. + */
  71156. + if (hc->qh) {
  71157. + dwc_otg_hc_cleanup(hcd->core_if, hc);
  71158. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, hc, hc_list_entry);
  71159. + hc->qh = NULL;
  71160. + }
  71161. +
  71162. + qh->channel = NULL;
  71163. + qh->ntd = 0;
  71164. +
  71165. + if (qh->desc_list) {
  71166. + dwc_memset(qh->desc_list, 0x00,
  71167. + sizeof(dwc_otg_host_dma_desc_t) * max_desc_num(qh));
  71168. + }
  71169. +}
  71170. +
  71171. +/**
  71172. + * Initializes a QH structure's Descriptor DMA related members.
  71173. + * Allocates memory for descriptor list.
  71174. + * On first periodic QH, allocates memory for FrameList
  71175. + * and enables periodic scheduling.
  71176. + *
  71177. + * @param hcd The HCD state structure for the DWC OTG controller.
  71178. + * @param qh The QH to init.
  71179. + *
  71180. + * @return 0 if successful, negative error code otherwise.
  71181. + */
  71182. +int dwc_otg_hcd_qh_init_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  71183. +{
  71184. + int retval = 0;
  71185. +
  71186. + if (qh->do_split) {
  71187. + DWC_ERROR("SPLIT Transfers are not supported in Descriptor DMA.\n");
  71188. + return -1;
  71189. + }
  71190. +
  71191. + retval = desc_list_alloc(qh);
  71192. +
  71193. + if ((retval == 0)
  71194. + && (qh->ep_type == UE_ISOCHRONOUS || qh->ep_type == UE_INTERRUPT)) {
  71195. + if (!hcd->frame_list) {
  71196. + retval = frame_list_alloc(hcd);
  71197. + /* Enable periodic schedule on first periodic QH */
  71198. + if (retval == 0)
  71199. + per_sched_enable(hcd, MAX_FRLIST_EN_NUM);
  71200. + }
  71201. + }
  71202. +
  71203. + qh->ntd = 0;
  71204. +
  71205. + return retval;
  71206. +}
  71207. +
  71208. +/**
  71209. + * Frees descriptor list memory associated with the QH.
  71210. + * If QH is periodic and the last, frees FrameList memory
  71211. + * and disables periodic scheduling.
  71212. + *
  71213. + * @param hcd The HCD state structure for the DWC OTG controller.
  71214. + * @param qh The QH to init.
  71215. + */
  71216. +void dwc_otg_hcd_qh_free_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  71217. +{
  71218. + desc_list_free(qh);
  71219. +
  71220. + /*
  71221. + * Channel still assigned due to some reasons.
  71222. + * Seen on Isoc URB dequeue. Channel halted but no subsequent
  71223. + * ChHalted interrupt to release the channel. Afterwards
  71224. + * when it comes here from endpoint disable routine
  71225. + * channel remains assigned.
  71226. + */
  71227. + if (qh->channel)
  71228. + release_channel_ddma(hcd, qh);
  71229. +
  71230. + if ((qh->ep_type == UE_ISOCHRONOUS || qh->ep_type == UE_INTERRUPT)
  71231. + && (microframe_schedule || !hcd->periodic_channels) && hcd->frame_list) {
  71232. +
  71233. + per_sched_disable(hcd);
  71234. + frame_list_free(hcd);
  71235. + }
  71236. +}
  71237. +
  71238. +static uint8_t frame_to_desc_idx(dwc_otg_qh_t * qh, uint16_t frame_idx)
  71239. +{
  71240. + if (qh->dev_speed == DWC_OTG_EP_SPEED_HIGH) {
  71241. + /*
  71242. + * Descriptor set(8 descriptors) index
  71243. + * which is 8-aligned.
  71244. + */
  71245. + return (frame_idx & ((MAX_DMA_DESC_NUM_HS_ISOC / 8) - 1)) * 8;
  71246. + } else {
  71247. + return (frame_idx & (MAX_DMA_DESC_NUM_GENERIC - 1));
  71248. + }
  71249. +}
  71250. +
  71251. +/*
  71252. + * Determine starting frame for Isochronous transfer.
  71253. + * Few frames skipped to prevent race condition with HC.
  71254. + */
  71255. +static uint8_t calc_starting_frame(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  71256. + uint8_t * skip_frames)
  71257. +{
  71258. + uint16_t frame = 0;
  71259. + hcd->frame_number = dwc_otg_hcd_get_frame_number(hcd);
  71260. +
  71261. + /* sched_frame is always frame number(not uFrame) both in FS and HS !! */
  71262. +
  71263. + /*
  71264. + * skip_frames is used to limit activated descriptors number
  71265. + * to avoid the situation when HC services the last activated
  71266. + * descriptor firstly.
  71267. + * Example for FS:
  71268. + * Current frame is 1, scheduled frame is 3. Since HC always fetches the descriptor
  71269. + * corresponding to curr_frame+1, the descriptor corresponding to frame 2
  71270. + * will be fetched. If the number of descriptors is max=64 (or greather) the
  71271. + * list will be fully programmed with Active descriptors and it is possible
  71272. + * case(rare) that the latest descriptor(considering rollback) corresponding
  71273. + * to frame 2 will be serviced first. HS case is more probable because, in fact,
  71274. + * up to 11 uframes(16 in the code) may be skipped.
  71275. + */
  71276. + if (qh->dev_speed == DWC_OTG_EP_SPEED_HIGH) {
  71277. + /*
  71278. + * Consider uframe counter also, to start xfer asap.
  71279. + * If half of the frame elapsed skip 2 frames otherwise
  71280. + * just 1 frame.
  71281. + * Starting descriptor index must be 8-aligned, so
  71282. + * if the current frame is near to complete the next one
  71283. + * is skipped as well.
  71284. + */
  71285. +
  71286. + if (dwc_micro_frame_num(hcd->frame_number) >= 5) {
  71287. + *skip_frames = 2 * 8;
  71288. + frame = dwc_frame_num_inc(hcd->frame_number, *skip_frames);
  71289. + } else {
  71290. + *skip_frames = 1 * 8;
  71291. + frame = dwc_frame_num_inc(hcd->frame_number, *skip_frames);
  71292. + }
  71293. +
  71294. + frame = dwc_full_frame_num(frame);
  71295. + } else {
  71296. + /*
  71297. + * Two frames are skipped for FS - the current and the next.
  71298. + * But for descriptor programming, 1 frame(descriptor) is enough,
  71299. + * see example above.
  71300. + */
  71301. + *skip_frames = 1;
  71302. + frame = dwc_frame_num_inc(hcd->frame_number, 2);
  71303. + }
  71304. +
  71305. + return frame;
  71306. +}
  71307. +
  71308. +/*
  71309. + * Calculate initial descriptor index for isochronous transfer
  71310. + * based on scheduled frame.
  71311. + */
  71312. +static uint8_t recalc_initial_desc_idx(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  71313. +{
  71314. + uint16_t frame = 0, fr_idx, fr_idx_tmp;
  71315. + uint8_t skip_frames = 0;
  71316. + /*
  71317. + * With current ISOC processing algorithm the channel is being
  71318. + * released when no more QTDs in the list(qh->ntd == 0).
  71319. + * Thus this function is called only when qh->ntd == 0 and qh->channel == 0.
  71320. + *
  71321. + * So qh->channel != NULL branch is not used and just not removed from the
  71322. + * source file. It is required for another possible approach which is,
  71323. + * do not disable and release the channel when ISOC session completed,
  71324. + * just move QH to inactive schedule until new QTD arrives.
  71325. + * On new QTD, the QH moved back to 'ready' schedule,
  71326. + * starting frame and therefore starting desc_index are recalculated.
  71327. + * In this case channel is released only on ep_disable.
  71328. + */
  71329. +
  71330. + /* Calculate starting descriptor index. For INTERRUPT endpoint it is always 0. */
  71331. + if (qh->channel) {
  71332. + frame = calc_starting_frame(hcd, qh, &skip_frames);
  71333. + /*
  71334. + * Calculate initial descriptor index based on FrameList current bitmap
  71335. + * and servicing period.
  71336. + */
  71337. + fr_idx_tmp = frame_list_idx(frame);
  71338. + fr_idx =
  71339. + (MAX_FRLIST_EN_NUM + frame_list_idx(qh->sched_frame) -
  71340. + fr_idx_tmp)
  71341. + % frame_incr_val(qh);
  71342. + fr_idx = (fr_idx + fr_idx_tmp) % MAX_FRLIST_EN_NUM;
  71343. + } else {
  71344. + qh->sched_frame = calc_starting_frame(hcd, qh, &skip_frames);
  71345. + fr_idx = frame_list_idx(qh->sched_frame);
  71346. + }
  71347. +
  71348. + qh->td_first = qh->td_last = frame_to_desc_idx(qh, fr_idx);
  71349. +
  71350. + return skip_frames;
  71351. +}
  71352. +
  71353. +#define ISOC_URB_GIVEBACK_ASAP
  71354. +
  71355. +#define MAX_ISOC_XFER_SIZE_FS 1023
  71356. +#define MAX_ISOC_XFER_SIZE_HS 3072
  71357. +#define DESCNUM_THRESHOLD 4
  71358. +
  71359. +static void init_isoc_dma_desc(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  71360. + uint8_t skip_frames)
  71361. +{
  71362. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  71363. + dwc_otg_qtd_t *qtd;
  71364. + dwc_otg_host_dma_desc_t *dma_desc;
  71365. + uint16_t idx, inc, n_desc, ntd_max, max_xfer_size;
  71366. +
  71367. + idx = qh->td_last;
  71368. + inc = qh->interval;
  71369. + n_desc = 0;
  71370. +
  71371. + ntd_max = (max_desc_num(qh) + qh->interval - 1) / qh->interval;
  71372. + if (skip_frames && !qh->channel)
  71373. + ntd_max = ntd_max - skip_frames / qh->interval;
  71374. +
  71375. + max_xfer_size =
  71376. + (qh->dev_speed ==
  71377. + DWC_OTG_EP_SPEED_HIGH) ? MAX_ISOC_XFER_SIZE_HS :
  71378. + MAX_ISOC_XFER_SIZE_FS;
  71379. +
  71380. + DWC_CIRCLEQ_FOREACH(qtd, &qh->qtd_list, qtd_list_entry) {
  71381. + while ((qh->ntd < ntd_max)
  71382. + && (qtd->isoc_frame_index_last <
  71383. + qtd->urb->packet_count)) {
  71384. +
  71385. + dma_desc = &qh->desc_list[idx];
  71386. + dwc_memset(dma_desc, 0x00, sizeof(dwc_otg_host_dma_desc_t));
  71387. +
  71388. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index_last];
  71389. +
  71390. + if (frame_desc->length > max_xfer_size)
  71391. + qh->n_bytes[idx] = max_xfer_size;
  71392. + else
  71393. + qh->n_bytes[idx] = frame_desc->length;
  71394. + dma_desc->status.b_isoc.n_bytes = qh->n_bytes[idx];
  71395. + dma_desc->status.b_isoc.a = 1;
  71396. + dma_desc->status.b_isoc.sts = 0;
  71397. +
  71398. + dma_desc->buf = qtd->urb->dma + frame_desc->offset;
  71399. +
  71400. + qh->ntd++;
  71401. +
  71402. + qtd->isoc_frame_index_last++;
  71403. +
  71404. +#ifdef ISOC_URB_GIVEBACK_ASAP
  71405. + /*
  71406. + * Set IOC for each descriptor corresponding to the
  71407. + * last frame of the URB.
  71408. + */
  71409. + if (qtd->isoc_frame_index_last ==
  71410. + qtd->urb->packet_count)
  71411. + dma_desc->status.b_isoc.ioc = 1;
  71412. +
  71413. +#endif
  71414. + idx = desclist_idx_inc(idx, inc, qh->dev_speed);
  71415. + n_desc++;
  71416. +
  71417. + }
  71418. + qtd->in_process = 1;
  71419. + }
  71420. +
  71421. + qh->td_last = idx;
  71422. +
  71423. +#ifdef ISOC_URB_GIVEBACK_ASAP
  71424. + /* Set IOC for the last descriptor if descriptor list is full */
  71425. + if (qh->ntd == ntd_max) {
  71426. + idx = desclist_idx_dec(qh->td_last, inc, qh->dev_speed);
  71427. + qh->desc_list[idx].status.b_isoc.ioc = 1;
  71428. + }
  71429. +#else
  71430. + /*
  71431. + * Set IOC bit only for one descriptor.
  71432. + * Always try to be ahead of HW processing,
  71433. + * i.e. on IOC generation driver activates next descriptors but
  71434. + * core continues to process descriptors followed the one with IOC set.
  71435. + */
  71436. +
  71437. + if (n_desc > DESCNUM_THRESHOLD) {
  71438. + /*
  71439. + * Move IOC "up". Required even if there is only one QTD
  71440. + * in the list, cause QTDs migth continue to be queued,
  71441. + * but during the activation it was only one queued.
  71442. + * Actually more than one QTD might be in the list if this function called
  71443. + * from XferCompletion - QTDs was queued during HW processing of the previous
  71444. + * descriptor chunk.
  71445. + */
  71446. + idx = dwc_desclist_idx_dec(idx, inc * ((qh->ntd + 1) / 2), qh->dev_speed);
  71447. + } else {
  71448. + /*
  71449. + * Set the IOC for the latest descriptor
  71450. + * if either number of descriptor is not greather than threshold
  71451. + * or no more new descriptors activated.
  71452. + */
  71453. + idx = dwc_desclist_idx_dec(qh->td_last, inc, qh->dev_speed);
  71454. + }
  71455. +
  71456. + qh->desc_list[idx].status.b_isoc.ioc = 1;
  71457. +#endif
  71458. +}
  71459. +
  71460. +static void init_non_isoc_dma_desc(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  71461. +{
  71462. +
  71463. + dwc_hc_t *hc;
  71464. + dwc_otg_host_dma_desc_t *dma_desc;
  71465. + dwc_otg_qtd_t *qtd;
  71466. + int num_packets, len, n_desc = 0;
  71467. +
  71468. + hc = qh->channel;
  71469. +
  71470. + /*
  71471. + * Start with hc->xfer_buff initialized in
  71472. + * assign_and_init_hc(), then if SG transfer consists of multiple URBs,
  71473. + * this pointer re-assigned to the buffer of the currently processed QTD.
  71474. + * For non-SG request there is always one QTD active.
  71475. + */
  71476. +
  71477. + DWC_CIRCLEQ_FOREACH(qtd, &qh->qtd_list, qtd_list_entry) {
  71478. +
  71479. + if (n_desc) {
  71480. + /* SG request - more than 1 QTDs */
  71481. + hc->xfer_buff = (uint8_t *)qtd->urb->dma + qtd->urb->actual_length;
  71482. + hc->xfer_len = qtd->urb->length - qtd->urb->actual_length;
  71483. + }
  71484. +
  71485. + qtd->n_desc = 0;
  71486. +
  71487. + do {
  71488. + dma_desc = &qh->desc_list[n_desc];
  71489. + len = hc->xfer_len;
  71490. +
  71491. + if (len > MAX_DMA_DESC_SIZE)
  71492. + len = MAX_DMA_DESC_SIZE - hc->max_packet + 1;
  71493. +
  71494. + if (hc->ep_is_in) {
  71495. + if (len > 0) {
  71496. + num_packets = (len + hc->max_packet - 1) / hc->max_packet;
  71497. + } else {
  71498. + /* Need 1 packet for transfer length of 0. */
  71499. + num_packets = 1;
  71500. + }
  71501. + /* Always program an integral # of max packets for IN transfers. */
  71502. + len = num_packets * hc->max_packet;
  71503. + }
  71504. +
  71505. + dma_desc->status.b.n_bytes = len;
  71506. +
  71507. + qh->n_bytes[n_desc] = len;
  71508. +
  71509. + if ((qh->ep_type == UE_CONTROL)
  71510. + && (qtd->control_phase == DWC_OTG_CONTROL_SETUP))
  71511. + dma_desc->status.b.sup = 1; /* Setup Packet */
  71512. +
  71513. + dma_desc->status.b.a = 1; /* Active descriptor */
  71514. + dma_desc->status.b.sts = 0;
  71515. +
  71516. + dma_desc->buf =
  71517. + ((unsigned long)hc->xfer_buff & 0xffffffff);
  71518. +
  71519. + /*
  71520. + * Last descriptor(or single) of IN transfer
  71521. + * with actual size less than MaxPacket.
  71522. + */
  71523. + if (len > hc->xfer_len) {
  71524. + hc->xfer_len = 0;
  71525. + } else {
  71526. + hc->xfer_buff += len;
  71527. + hc->xfer_len -= len;
  71528. + }
  71529. +
  71530. + qtd->n_desc++;
  71531. + n_desc++;
  71532. + }
  71533. + while ((hc->xfer_len > 0) && (n_desc != MAX_DMA_DESC_NUM_GENERIC));
  71534. +
  71535. +
  71536. + qtd->in_process = 1;
  71537. +
  71538. + if (qh->ep_type == UE_CONTROL)
  71539. + break;
  71540. +
  71541. + if (n_desc == MAX_DMA_DESC_NUM_GENERIC)
  71542. + break;
  71543. + }
  71544. +
  71545. + if (n_desc) {
  71546. + /* Request Transfer Complete interrupt for the last descriptor */
  71547. + qh->desc_list[n_desc - 1].status.b.ioc = 1;
  71548. + /* End of List indicator */
  71549. + qh->desc_list[n_desc - 1].status.b.eol = 1;
  71550. +
  71551. + hc->ntd = n_desc;
  71552. + }
  71553. +}
  71554. +
  71555. +/**
  71556. + * For Control and Bulk endpoints initializes descriptor list
  71557. + * and starts the transfer.
  71558. + *
  71559. + * For Interrupt and Isochronous endpoints initializes descriptor list
  71560. + * then updates FrameList, marking appropriate entries as active.
  71561. + * In case of Isochronous, the starting descriptor index is calculated based
  71562. + * on the scheduled frame, but only on the first transfer descriptor within a session.
  71563. + * Then starts the transfer via enabling the channel.
  71564. + * For Isochronous endpoint the channel is not halted on XferComplete
  71565. + * interrupt so remains assigned to the endpoint(QH) until session is done.
  71566. + *
  71567. + * @param hcd The HCD state structure for the DWC OTG controller.
  71568. + * @param qh The QH to init.
  71569. + *
  71570. + * @return 0 if successful, negative error code otherwise.
  71571. + */
  71572. +void dwc_otg_hcd_start_xfer_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  71573. +{
  71574. + /* Channel is already assigned */
  71575. + dwc_hc_t *hc = qh->channel;
  71576. + uint8_t skip_frames = 0;
  71577. +
  71578. + switch (hc->ep_type) {
  71579. + case DWC_OTG_EP_TYPE_CONTROL:
  71580. + case DWC_OTG_EP_TYPE_BULK:
  71581. + init_non_isoc_dma_desc(hcd, qh);
  71582. +
  71583. + dwc_otg_hc_start_transfer_ddma(hcd->core_if, hc);
  71584. + break;
  71585. + case DWC_OTG_EP_TYPE_INTR:
  71586. + init_non_isoc_dma_desc(hcd, qh);
  71587. +
  71588. + update_frame_list(hcd, qh, 1);
  71589. +
  71590. + dwc_otg_hc_start_transfer_ddma(hcd->core_if, hc);
  71591. + break;
  71592. + case DWC_OTG_EP_TYPE_ISOC:
  71593. +
  71594. + if (!qh->ntd)
  71595. + skip_frames = recalc_initial_desc_idx(hcd, qh);
  71596. +
  71597. + init_isoc_dma_desc(hcd, qh, skip_frames);
  71598. +
  71599. + if (!hc->xfer_started) {
  71600. +
  71601. + update_frame_list(hcd, qh, 1);
  71602. +
  71603. + /*
  71604. + * Always set to max, instead of actual size.
  71605. + * Otherwise ntd will be changed with
  71606. + * channel being enabled. Not recommended.
  71607. + *
  71608. + */
  71609. + hc->ntd = max_desc_num(qh);
  71610. + /* Enable channel only once for ISOC */
  71611. + dwc_otg_hc_start_transfer_ddma(hcd->core_if, hc);
  71612. + }
  71613. +
  71614. + break;
  71615. + default:
  71616. +
  71617. + break;
  71618. + }
  71619. +}
  71620. +
  71621. +static void complete_isoc_xfer_ddma(dwc_otg_hcd_t * hcd,
  71622. + dwc_hc_t * hc,
  71623. + dwc_otg_hc_regs_t * hc_regs,
  71624. + dwc_otg_halt_status_e halt_status)
  71625. +{
  71626. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  71627. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  71628. + dwc_otg_qh_t *qh;
  71629. + dwc_otg_host_dma_desc_t *dma_desc;
  71630. + uint16_t idx, remain;
  71631. + uint8_t urb_compl;
  71632. +
  71633. + qh = hc->qh;
  71634. + idx = qh->td_first;
  71635. +
  71636. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  71637. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry)
  71638. + qtd->in_process = 0;
  71639. + return;
  71640. + } else if ((halt_status == DWC_OTG_HC_XFER_AHB_ERR) ||
  71641. + (halt_status == DWC_OTG_HC_XFER_BABBLE_ERR)) {
  71642. + /*
  71643. + * Channel is halted in these error cases.
  71644. + * Considered as serious issues.
  71645. + * Complete all URBs marking all frames as failed,
  71646. + * irrespective whether some of the descriptors(frames) succeeded or no.
  71647. + * Pass error code to completion routine as well, to
  71648. + * update urb->status, some of class drivers might use it to stop
  71649. + * queing transfer requests.
  71650. + */
  71651. + int err = (halt_status == DWC_OTG_HC_XFER_AHB_ERR)
  71652. + ? (-DWC_E_IO)
  71653. + : (-DWC_E_OVERFLOW);
  71654. +
  71655. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry) {
  71656. + for (idx = 0; idx < qtd->urb->packet_count; idx++) {
  71657. + frame_desc = &qtd->urb->iso_descs[idx];
  71658. + frame_desc->status = err;
  71659. + }
  71660. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, err);
  71661. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  71662. + }
  71663. + return;
  71664. + }
  71665. +
  71666. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry) {
  71667. +
  71668. + if (!qtd->in_process)
  71669. + break;
  71670. +
  71671. + urb_compl = 0;
  71672. +
  71673. + do {
  71674. +
  71675. + dma_desc = &qh->desc_list[idx];
  71676. +
  71677. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  71678. + remain = hc->ep_is_in ? dma_desc->status.b_isoc.n_bytes : 0;
  71679. +
  71680. + if (dma_desc->status.b_isoc.sts == DMA_DESC_STS_PKTERR) {
  71681. + /*
  71682. + * XactError or, unable to complete all the transactions
  71683. + * in the scheduled micro-frame/frame,
  71684. + * both indicated by DMA_DESC_STS_PKTERR.
  71685. + */
  71686. + qtd->urb->error_count++;
  71687. + frame_desc->actual_length = qh->n_bytes[idx] - remain;
  71688. + frame_desc->status = -DWC_E_PROTOCOL;
  71689. + } else {
  71690. + /* Success */
  71691. +
  71692. + frame_desc->actual_length = qh->n_bytes[idx] - remain;
  71693. + frame_desc->status = 0;
  71694. + }
  71695. +
  71696. + if (++qtd->isoc_frame_index == qtd->urb->packet_count) {
  71697. + /*
  71698. + * urb->status is not used for isoc transfers here.
  71699. + * The individual frame_desc status are used instead.
  71700. + */
  71701. +
  71702. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  71703. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  71704. +
  71705. + /*
  71706. + * This check is necessary because urb_dequeue can be called
  71707. + * from urb complete callback(sound driver example).
  71708. + * All pending URBs are dequeued there, so no need for
  71709. + * further processing.
  71710. + */
  71711. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  71712. + return;
  71713. + }
  71714. +
  71715. + urb_compl = 1;
  71716. +
  71717. + }
  71718. +
  71719. + qh->ntd--;
  71720. +
  71721. + /* Stop if IOC requested descriptor reached */
  71722. + if (dma_desc->status.b_isoc.ioc) {
  71723. + idx = desclist_idx_inc(idx, qh->interval, hc->speed);
  71724. + goto stop_scan;
  71725. + }
  71726. +
  71727. + idx = desclist_idx_inc(idx, qh->interval, hc->speed);
  71728. +
  71729. + if (urb_compl)
  71730. + break;
  71731. + }
  71732. + while (idx != qh->td_first);
  71733. + }
  71734. +stop_scan:
  71735. + qh->td_first = idx;
  71736. +}
  71737. +
  71738. +uint8_t update_non_isoc_urb_state_ddma(dwc_otg_hcd_t * hcd,
  71739. + dwc_hc_t * hc,
  71740. + dwc_otg_qtd_t * qtd,
  71741. + dwc_otg_host_dma_desc_t * dma_desc,
  71742. + dwc_otg_halt_status_e halt_status,
  71743. + uint32_t n_bytes, uint8_t * xfer_done)
  71744. +{
  71745. +
  71746. + uint16_t remain = hc->ep_is_in ? dma_desc->status.b.n_bytes : 0;
  71747. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  71748. +
  71749. + if (halt_status == DWC_OTG_HC_XFER_AHB_ERR) {
  71750. + urb->status = -DWC_E_IO;
  71751. + return 1;
  71752. + }
  71753. + if (dma_desc->status.b.sts == DMA_DESC_STS_PKTERR) {
  71754. + switch (halt_status) {
  71755. + case DWC_OTG_HC_XFER_STALL:
  71756. + urb->status = -DWC_E_PIPE;
  71757. + break;
  71758. + case DWC_OTG_HC_XFER_BABBLE_ERR:
  71759. + urb->status = -DWC_E_OVERFLOW;
  71760. + break;
  71761. + case DWC_OTG_HC_XFER_XACT_ERR:
  71762. + urb->status = -DWC_E_PROTOCOL;
  71763. + break;
  71764. + default:
  71765. + DWC_ERROR("%s: Unhandled descriptor error status (%d)\n", __func__,
  71766. + halt_status);
  71767. + break;
  71768. + }
  71769. + return 1;
  71770. + }
  71771. +
  71772. + if (dma_desc->status.b.a == 1) {
  71773. + DWC_DEBUGPL(DBG_HCDV,
  71774. + "Active descriptor encountered on channel %d\n",
  71775. + hc->hc_num);
  71776. + return 0;
  71777. + }
  71778. +
  71779. + if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL) {
  71780. + if (qtd->control_phase == DWC_OTG_CONTROL_DATA) {
  71781. + urb->actual_length += n_bytes - remain;
  71782. + if (remain || urb->actual_length == urb->length) {
  71783. + /*
  71784. + * For Control Data stage do not set urb->status=0 to prevent
  71785. + * URB callback. Set it when Status phase done. See below.
  71786. + */
  71787. + *xfer_done = 1;
  71788. + }
  71789. +
  71790. + } else if (qtd->control_phase == DWC_OTG_CONTROL_STATUS) {
  71791. + urb->status = 0;
  71792. + *xfer_done = 1;
  71793. + }
  71794. + /* No handling for SETUP stage */
  71795. + } else {
  71796. + /* BULK and INTR */
  71797. + urb->actual_length += n_bytes - remain;
  71798. + if (remain || urb->actual_length == urb->length) {
  71799. + urb->status = 0;
  71800. + *xfer_done = 1;
  71801. + }
  71802. + }
  71803. +
  71804. + return 0;
  71805. +}
  71806. +
  71807. +static void complete_non_isoc_xfer_ddma(dwc_otg_hcd_t * hcd,
  71808. + dwc_hc_t * hc,
  71809. + dwc_otg_hc_regs_t * hc_regs,
  71810. + dwc_otg_halt_status_e halt_status)
  71811. +{
  71812. + dwc_otg_hcd_urb_t *urb = NULL;
  71813. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  71814. + dwc_otg_qh_t *qh;
  71815. + dwc_otg_host_dma_desc_t *dma_desc;
  71816. + uint32_t n_bytes, n_desc, i;
  71817. + uint8_t failed = 0, xfer_done;
  71818. +
  71819. + n_desc = 0;
  71820. +
  71821. + qh = hc->qh;
  71822. +
  71823. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  71824. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry) {
  71825. + qtd->in_process = 0;
  71826. + }
  71827. + return;
  71828. + }
  71829. +
  71830. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &qh->qtd_list, qtd_list_entry) {
  71831. +
  71832. + urb = qtd->urb;
  71833. +
  71834. + n_bytes = 0;
  71835. + xfer_done = 0;
  71836. +
  71837. + for (i = 0; i < qtd->n_desc; i++) {
  71838. + dma_desc = &qh->desc_list[n_desc];
  71839. +
  71840. + n_bytes = qh->n_bytes[n_desc];
  71841. +
  71842. + failed =
  71843. + update_non_isoc_urb_state_ddma(hcd, hc, qtd,
  71844. + dma_desc,
  71845. + halt_status, n_bytes,
  71846. + &xfer_done);
  71847. +
  71848. + if (failed
  71849. + || (xfer_done
  71850. + && (urb->status != -DWC_E_IN_PROGRESS))) {
  71851. +
  71852. + hcd->fops->complete(hcd, urb->priv, urb,
  71853. + urb->status);
  71854. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  71855. +
  71856. + if (failed)
  71857. + goto stop_scan;
  71858. + } else if (qh->ep_type == UE_CONTROL) {
  71859. + if (qtd->control_phase == DWC_OTG_CONTROL_SETUP) {
  71860. + if (urb->length > 0) {
  71861. + qtd->control_phase = DWC_OTG_CONTROL_DATA;
  71862. + } else {
  71863. + qtd->control_phase = DWC_OTG_CONTROL_STATUS;
  71864. + }
  71865. + DWC_DEBUGPL(DBG_HCDV, " Control setup transaction done\n");
  71866. + } else if (qtd->control_phase == DWC_OTG_CONTROL_DATA) {
  71867. + if (xfer_done) {
  71868. + qtd->control_phase = DWC_OTG_CONTROL_STATUS;
  71869. + DWC_DEBUGPL(DBG_HCDV, " Control data transfer done\n");
  71870. + } else if (i + 1 == qtd->n_desc) {
  71871. + /*
  71872. + * Last descriptor for Control data stage which is
  71873. + * not completed yet.
  71874. + */
  71875. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  71876. + }
  71877. + }
  71878. + }
  71879. +
  71880. + n_desc++;
  71881. + }
  71882. +
  71883. + }
  71884. +
  71885. +stop_scan:
  71886. +
  71887. + if (qh->ep_type != UE_CONTROL) {
  71888. + /*
  71889. + * Resetting the data toggle for bulk
  71890. + * and interrupt endpoints in case of stall. See handle_hc_stall_intr()
  71891. + */
  71892. + if (halt_status == DWC_OTG_HC_XFER_STALL)
  71893. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  71894. + else
  71895. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  71896. + }
  71897. +
  71898. + if (halt_status == DWC_OTG_HC_XFER_COMPLETE) {
  71899. + hcint_data_t hcint;
  71900. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  71901. + if (hcint.b.nyet) {
  71902. + /*
  71903. + * Got a NYET on the last transaction of the transfer. It
  71904. + * means that the endpoint should be in the PING state at the
  71905. + * beginning of the next transfer.
  71906. + */
  71907. + qh->ping_state = 1;
  71908. + clear_hc_int(hc_regs, nyet);
  71909. + }
  71910. +
  71911. + }
  71912. +
  71913. +}
  71914. +
  71915. +/**
  71916. + * This function is called from interrupt handlers.
  71917. + * Scans the descriptor list, updates URB's status and
  71918. + * calls completion routine for the URB if it's done.
  71919. + * Releases the channel to be used by other transfers.
  71920. + * In case of Isochronous endpoint the channel is not halted until
  71921. + * the end of the session, i.e. QTD list is empty.
  71922. + * If periodic channel released the FrameList is updated accordingly.
  71923. + *
  71924. + * Calls transaction selection routines to activate pending transfers.
  71925. + *
  71926. + * @param hcd The HCD state structure for the DWC OTG controller.
  71927. + * @param hc Host channel, the transfer is completed on.
  71928. + * @param hc_regs Host channel registers.
  71929. + * @param halt_status Reason the channel is being halted,
  71930. + * or just XferComplete for isochronous transfer
  71931. + */
  71932. +void dwc_otg_hcd_complete_xfer_ddma(dwc_otg_hcd_t * hcd,
  71933. + dwc_hc_t * hc,
  71934. + dwc_otg_hc_regs_t * hc_regs,
  71935. + dwc_otg_halt_status_e halt_status)
  71936. +{
  71937. + uint8_t continue_isoc_xfer = 0;
  71938. + dwc_otg_transaction_type_e tr_type;
  71939. + dwc_otg_qh_t *qh = hc->qh;
  71940. +
  71941. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  71942. +
  71943. + complete_isoc_xfer_ddma(hcd, hc, hc_regs, halt_status);
  71944. +
  71945. + /* Release the channel if halted or session completed */
  71946. + if (halt_status != DWC_OTG_HC_XFER_COMPLETE ||
  71947. + DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  71948. +
  71949. + /* Halt the channel if session completed */
  71950. + if (halt_status == DWC_OTG_HC_XFER_COMPLETE) {
  71951. + dwc_otg_hc_halt(hcd->core_if, hc, halt_status);
  71952. + }
  71953. +
  71954. + release_channel_ddma(hcd, qh);
  71955. + dwc_otg_hcd_qh_remove(hcd, qh);
  71956. + } else {
  71957. + /* Keep in assigned schedule to continue transfer */
  71958. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_assigned,
  71959. + &qh->qh_list_entry);
  71960. + continue_isoc_xfer = 1;
  71961. +
  71962. + }
  71963. + /** @todo Consider the case when period exceeds FrameList size.
  71964. + * Frame Rollover interrupt should be used.
  71965. + */
  71966. + } else {
  71967. + /* Scan descriptor list to complete the URB(s), then release the channel */
  71968. + complete_non_isoc_xfer_ddma(hcd, hc, hc_regs, halt_status);
  71969. +
  71970. + release_channel_ddma(hcd, qh);
  71971. + dwc_otg_hcd_qh_remove(hcd, qh);
  71972. +
  71973. + if (!DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  71974. + /* Add back to inactive non-periodic schedule on normal completion */
  71975. + dwc_otg_hcd_qh_add(hcd, qh);
  71976. + }
  71977. +
  71978. + }
  71979. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  71980. + if (tr_type != DWC_OTG_TRANSACTION_NONE || continue_isoc_xfer) {
  71981. + if (continue_isoc_xfer) {
  71982. + if (tr_type == DWC_OTG_TRANSACTION_NONE) {
  71983. + tr_type = DWC_OTG_TRANSACTION_PERIODIC;
  71984. + } else if (tr_type == DWC_OTG_TRANSACTION_NON_PERIODIC) {
  71985. + tr_type = DWC_OTG_TRANSACTION_ALL;
  71986. + }
  71987. + }
  71988. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  71989. + }
  71990. +}
  71991. +
  71992. +#endif /* DWC_DEVICE_ONLY */
  71993. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd.h linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_hcd.h
  71994. --- linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd.h 1970-01-01 01:00:00.000000000 +0100
  71995. +++ linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_hcd.h 2014-02-17 22:41:01.000000000 +0100
  71996. @@ -0,0 +1,851 @@
  71997. +/* ==========================================================================
  71998. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd.h $
  71999. + * $Revision: #58 $
  72000. + * $Date: 2011/09/15 $
  72001. + * $Change: 1846647 $
  72002. + *
  72003. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  72004. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  72005. + * otherwise expressly agreed to in writing between Synopsys and you.
  72006. + *
  72007. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  72008. + * any End User Software License Agreement or Agreement for Licensed Product
  72009. + * with Synopsys or any supplement thereto. You are permitted to use and
  72010. + * redistribute this Software in source and binary forms, with or without
  72011. + * modification, provided that redistributions of source code must retain this
  72012. + * notice. You may not view, use, disclose, copy or distribute this file or
  72013. + * any information contained herein except pursuant to this license grant from
  72014. + * Synopsys. If you do not agree with this notice, including the disclaimer
  72015. + * below, then you are not authorized to use the Software.
  72016. + *
  72017. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  72018. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  72019. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  72020. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  72021. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  72022. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  72023. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  72024. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  72025. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  72026. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  72027. + * DAMAGE.
  72028. + * ========================================================================== */
  72029. +#ifndef DWC_DEVICE_ONLY
  72030. +#ifndef __DWC_HCD_H__
  72031. +#define __DWC_HCD_H__
  72032. +
  72033. +#include "dwc_otg_os_dep.h"
  72034. +#include "usb.h"
  72035. +#include "dwc_otg_hcd_if.h"
  72036. +#include "dwc_otg_core_if.h"
  72037. +#include "dwc_list.h"
  72038. +#include "dwc_otg_cil.h"
  72039. +
  72040. +/**
  72041. + * @file
  72042. + *
  72043. + * This file contains the structures, constants, and interfaces for
  72044. + * the Host Contoller Driver (HCD).
  72045. + *
  72046. + * The Host Controller Driver (HCD) is responsible for translating requests
  72047. + * from the USB Driver into the appropriate actions on the DWC_otg controller.
  72048. + * It isolates the USBD from the specifics of the controller by providing an
  72049. + * API to the USBD.
  72050. + */
  72051. +
  72052. +struct dwc_otg_hcd_pipe_info {
  72053. + uint8_t dev_addr;
  72054. + uint8_t ep_num;
  72055. + uint8_t pipe_type;
  72056. + uint8_t pipe_dir;
  72057. + uint16_t mps;
  72058. +};
  72059. +
  72060. +struct dwc_otg_hcd_iso_packet_desc {
  72061. + uint32_t offset;
  72062. + uint32_t length;
  72063. + uint32_t actual_length;
  72064. + uint32_t status;
  72065. +};
  72066. +
  72067. +struct dwc_otg_qtd;
  72068. +
  72069. +struct dwc_otg_hcd_urb {
  72070. + void *priv;
  72071. + struct dwc_otg_qtd *qtd;
  72072. + void *buf;
  72073. + dwc_dma_t dma;
  72074. + void *setup_packet;
  72075. + dwc_dma_t setup_dma;
  72076. + uint32_t length;
  72077. + uint32_t actual_length;
  72078. + uint32_t status;
  72079. + uint32_t error_count;
  72080. + uint32_t packet_count;
  72081. + uint32_t flags;
  72082. + uint16_t interval;
  72083. + struct dwc_otg_hcd_pipe_info pipe_info;
  72084. + struct dwc_otg_hcd_iso_packet_desc iso_descs[0];
  72085. +};
  72086. +
  72087. +static inline uint8_t dwc_otg_hcd_get_ep_num(struct dwc_otg_hcd_pipe_info *pipe)
  72088. +{
  72089. + return pipe->ep_num;
  72090. +}
  72091. +
  72092. +static inline uint8_t dwc_otg_hcd_get_pipe_type(struct dwc_otg_hcd_pipe_info
  72093. + *pipe)
  72094. +{
  72095. + return pipe->pipe_type;
  72096. +}
  72097. +
  72098. +static inline uint16_t dwc_otg_hcd_get_mps(struct dwc_otg_hcd_pipe_info *pipe)
  72099. +{
  72100. + return pipe->mps;
  72101. +}
  72102. +
  72103. +static inline uint8_t dwc_otg_hcd_get_dev_addr(struct dwc_otg_hcd_pipe_info
  72104. + *pipe)
  72105. +{
  72106. + return pipe->dev_addr;
  72107. +}
  72108. +
  72109. +static inline uint8_t dwc_otg_hcd_is_pipe_isoc(struct dwc_otg_hcd_pipe_info
  72110. + *pipe)
  72111. +{
  72112. + return (pipe->pipe_type == UE_ISOCHRONOUS);
  72113. +}
  72114. +
  72115. +static inline uint8_t dwc_otg_hcd_is_pipe_int(struct dwc_otg_hcd_pipe_info
  72116. + *pipe)
  72117. +{
  72118. + return (pipe->pipe_type == UE_INTERRUPT);
  72119. +}
  72120. +
  72121. +static inline uint8_t dwc_otg_hcd_is_pipe_bulk(struct dwc_otg_hcd_pipe_info
  72122. + *pipe)
  72123. +{
  72124. + return (pipe->pipe_type == UE_BULK);
  72125. +}
  72126. +
  72127. +static inline uint8_t dwc_otg_hcd_is_pipe_control(struct dwc_otg_hcd_pipe_info
  72128. + *pipe)
  72129. +{
  72130. + return (pipe->pipe_type == UE_CONTROL);
  72131. +}
  72132. +
  72133. +static inline uint8_t dwc_otg_hcd_is_pipe_in(struct dwc_otg_hcd_pipe_info *pipe)
  72134. +{
  72135. + return (pipe->pipe_dir == UE_DIR_IN);
  72136. +}
  72137. +
  72138. +static inline uint8_t dwc_otg_hcd_is_pipe_out(struct dwc_otg_hcd_pipe_info
  72139. + *pipe)
  72140. +{
  72141. + return (!dwc_otg_hcd_is_pipe_in(pipe));
  72142. +}
  72143. +
  72144. +static inline void dwc_otg_hcd_fill_pipe(struct dwc_otg_hcd_pipe_info *pipe,
  72145. + uint8_t devaddr, uint8_t ep_num,
  72146. + uint8_t pipe_type, uint8_t pipe_dir,
  72147. + uint16_t mps)
  72148. +{
  72149. + pipe->dev_addr = devaddr;
  72150. + pipe->ep_num = ep_num;
  72151. + pipe->pipe_type = pipe_type;
  72152. + pipe->pipe_dir = pipe_dir;
  72153. + pipe->mps = mps;
  72154. +}
  72155. +
  72156. +/**
  72157. + * Phases for control transfers.
  72158. + */
  72159. +typedef enum dwc_otg_control_phase {
  72160. + DWC_OTG_CONTROL_SETUP,
  72161. + DWC_OTG_CONTROL_DATA,
  72162. + DWC_OTG_CONTROL_STATUS
  72163. +} dwc_otg_control_phase_e;
  72164. +
  72165. +/** Transaction types. */
  72166. +typedef enum dwc_otg_transaction_type {
  72167. + DWC_OTG_TRANSACTION_NONE = 0,
  72168. + DWC_OTG_TRANSACTION_PERIODIC = 1,
  72169. + DWC_OTG_TRANSACTION_NON_PERIODIC = 2,
  72170. + DWC_OTG_TRANSACTION_ALL = DWC_OTG_TRANSACTION_PERIODIC + DWC_OTG_TRANSACTION_NON_PERIODIC
  72171. +} dwc_otg_transaction_type_e;
  72172. +
  72173. +struct dwc_otg_qh;
  72174. +
  72175. +/**
  72176. + * A Queue Transfer Descriptor (QTD) holds the state of a bulk, control,
  72177. + * interrupt, or isochronous transfer. A single QTD is created for each URB
  72178. + * (of one of these types) submitted to the HCD. The transfer associated with
  72179. + * a QTD may require one or multiple transactions.
  72180. + *
  72181. + * A QTD is linked to a Queue Head, which is entered in either the
  72182. + * non-periodic or periodic schedule for execution. When a QTD is chosen for
  72183. + * execution, some or all of its transactions may be executed. After
  72184. + * execution, the state of the QTD is updated. The QTD may be retired if all
  72185. + * its transactions are complete or if an error occurred. Otherwise, it
  72186. + * remains in the schedule so more transactions can be executed later.
  72187. + */
  72188. +typedef struct dwc_otg_qtd {
  72189. + /**
  72190. + * Determines the PID of the next data packet for the data phase of
  72191. + * control transfers. Ignored for other transfer types.<br>
  72192. + * One of the following values:
  72193. + * - DWC_OTG_HC_PID_DATA0
  72194. + * - DWC_OTG_HC_PID_DATA1
  72195. + */
  72196. + uint8_t data_toggle;
  72197. +
  72198. + /** Current phase for control transfers (Setup, Data, or Status). */
  72199. + dwc_otg_control_phase_e control_phase;
  72200. +
  72201. + /** Keep track of the current split type
  72202. + * for FS/LS endpoints on a HS Hub */
  72203. + uint8_t complete_split;
  72204. +
  72205. + /** How many bytes transferred during SSPLIT OUT */
  72206. + uint32_t ssplit_out_xfer_count;
  72207. +
  72208. + /**
  72209. + * Holds the number of bus errors that have occurred for a transaction
  72210. + * within this transfer.
  72211. + */
  72212. + uint8_t error_count;
  72213. +
  72214. + /**
  72215. + * Index of the next frame descriptor for an isochronous transfer. A
  72216. + * frame descriptor describes the buffer position and length of the
  72217. + * data to be transferred in the next scheduled (micro)frame of an
  72218. + * isochronous transfer. It also holds status for that transaction.
  72219. + * The frame index starts at 0.
  72220. + */
  72221. + uint16_t isoc_frame_index;
  72222. +
  72223. + /** Position of the ISOC split on full/low speed */
  72224. + uint8_t isoc_split_pos;
  72225. +
  72226. + /** Position of the ISOC split in the buffer for the current frame */
  72227. + uint16_t isoc_split_offset;
  72228. +
  72229. + /** URB for this transfer */
  72230. + struct dwc_otg_hcd_urb *urb;
  72231. +
  72232. + struct dwc_otg_qh *qh;
  72233. +
  72234. + /** This list of QTDs */
  72235. + DWC_CIRCLEQ_ENTRY(dwc_otg_qtd) qtd_list_entry;
  72236. +
  72237. + /** Indicates if this QTD is currently processed by HW. */
  72238. + uint8_t in_process;
  72239. +
  72240. + /** Number of DMA descriptors for this QTD */
  72241. + uint8_t n_desc;
  72242. +
  72243. + /**
  72244. + * Last activated frame(packet) index.
  72245. + * Used in Descriptor DMA mode only.
  72246. + */
  72247. + uint16_t isoc_frame_index_last;
  72248. +
  72249. +} dwc_otg_qtd_t;
  72250. +
  72251. +DWC_CIRCLEQ_HEAD(dwc_otg_qtd_list, dwc_otg_qtd);
  72252. +
  72253. +/**
  72254. + * A Queue Head (QH) holds the static characteristics of an endpoint and
  72255. + * maintains a list of transfers (QTDs) for that endpoint. A QH structure may
  72256. + * be entered in either the non-periodic or periodic schedule.
  72257. + */
  72258. +typedef struct dwc_otg_qh {
  72259. + /**
  72260. + * Endpoint type.
  72261. + * One of the following values:
  72262. + * - UE_CONTROL
  72263. + * - UE_BULK
  72264. + * - UE_INTERRUPT
  72265. + * - UE_ISOCHRONOUS
  72266. + */
  72267. + uint8_t ep_type;
  72268. + uint8_t ep_is_in;
  72269. +
  72270. + /** wMaxPacketSize Field of Endpoint Descriptor. */
  72271. + uint16_t maxp;
  72272. +
  72273. + /**
  72274. + * Device speed.
  72275. + * One of the following values:
  72276. + * - DWC_OTG_EP_SPEED_LOW
  72277. + * - DWC_OTG_EP_SPEED_FULL
  72278. + * - DWC_OTG_EP_SPEED_HIGH
  72279. + */
  72280. + uint8_t dev_speed;
  72281. +
  72282. + /**
  72283. + * Determines the PID of the next data packet for non-control
  72284. + * transfers. Ignored for control transfers.<br>
  72285. + * One of the following values:
  72286. + * - DWC_OTG_HC_PID_DATA0
  72287. + * - DWC_OTG_HC_PID_DATA1
  72288. + */
  72289. + uint8_t data_toggle;
  72290. +
  72291. + /** Ping state if 1. */
  72292. + uint8_t ping_state;
  72293. +
  72294. + /**
  72295. + * List of QTDs for this QH.
  72296. + */
  72297. + struct dwc_otg_qtd_list qtd_list;
  72298. +
  72299. + /** Host channel currently processing transfers for this QH. */
  72300. + struct dwc_hc *channel;
  72301. +
  72302. + /** Full/low speed endpoint on high-speed hub requires split. */
  72303. + uint8_t do_split;
  72304. +
  72305. + /** @name Periodic schedule information */
  72306. + /** @{ */
  72307. +
  72308. + /** Bandwidth in microseconds per (micro)frame. */
  72309. + uint16_t usecs;
  72310. +
  72311. + /** Interval between transfers in (micro)frames. */
  72312. + uint16_t interval;
  72313. +
  72314. + /**
  72315. + * (micro)frame to initialize a periodic transfer. The transfer
  72316. + * executes in the following (micro)frame.
  72317. + */
  72318. + uint16_t sched_frame;
  72319. +
  72320. + /*
  72321. + ** Frame a NAK was received on this queue head, used to minimise NAK retransmission
  72322. + */
  72323. + uint16_t nak_frame;
  72324. +
  72325. + /** (micro)frame at which last start split was initialized. */
  72326. + uint16_t start_split_frame;
  72327. +
  72328. + /** @} */
  72329. +
  72330. + /**
  72331. + * Used instead of original buffer if
  72332. + * it(physical address) is not dword-aligned.
  72333. + */
  72334. + uint8_t *dw_align_buf;
  72335. + dwc_dma_t dw_align_buf_dma;
  72336. +
  72337. + /** Entry for QH in either the periodic or non-periodic schedule. */
  72338. + dwc_list_link_t qh_list_entry;
  72339. +
  72340. + /** @name Descriptor DMA support */
  72341. + /** @{ */
  72342. +
  72343. + /** Descriptor List. */
  72344. + dwc_otg_host_dma_desc_t *desc_list;
  72345. +
  72346. + /** Descriptor List physical address. */
  72347. + dwc_dma_t desc_list_dma;
  72348. +
  72349. + /**
  72350. + * Xfer Bytes array.
  72351. + * Each element corresponds to a descriptor and indicates
  72352. + * original XferSize size value for the descriptor.
  72353. + */
  72354. + uint32_t *n_bytes;
  72355. +
  72356. + /** Actual number of transfer descriptors in a list. */
  72357. + uint16_t ntd;
  72358. +
  72359. + /** First activated isochronous transfer descriptor index. */
  72360. + uint8_t td_first;
  72361. + /** Last activated isochronous transfer descriptor index. */
  72362. + uint8_t td_last;
  72363. +
  72364. + /** @} */
  72365. +
  72366. +
  72367. + uint16_t speed;
  72368. + uint16_t frame_usecs[8];
  72369. +
  72370. + uint32_t skip_count;
  72371. +} dwc_otg_qh_t;
  72372. +
  72373. +DWC_CIRCLEQ_HEAD(hc_list, dwc_hc);
  72374. +
  72375. +typedef struct urb_tq_entry {
  72376. + struct urb *urb;
  72377. + DWC_TAILQ_ENTRY(urb_tq_entry) urb_tq_entries;
  72378. +} urb_tq_entry_t;
  72379. +
  72380. +DWC_TAILQ_HEAD(urb_list, urb_tq_entry);
  72381. +
  72382. +/**
  72383. + * This structure holds the state of the HCD, including the non-periodic and
  72384. + * periodic schedules.
  72385. + */
  72386. +struct dwc_otg_hcd {
  72387. + /** The DWC otg device pointer */
  72388. + struct dwc_otg_device *otg_dev;
  72389. + /** DWC OTG Core Interface Layer */
  72390. + dwc_otg_core_if_t *core_if;
  72391. +
  72392. + /** Function HCD driver callbacks */
  72393. + struct dwc_otg_hcd_function_ops *fops;
  72394. +
  72395. + /** Internal DWC HCD Flags */
  72396. + volatile union dwc_otg_hcd_internal_flags {
  72397. + uint32_t d32;
  72398. + struct {
  72399. + unsigned port_connect_status_change:1;
  72400. + unsigned port_connect_status:1;
  72401. + unsigned port_reset_change:1;
  72402. + unsigned port_enable_change:1;
  72403. + unsigned port_suspend_change:1;
  72404. + unsigned port_over_current_change:1;
  72405. + unsigned port_l1_change:1;
  72406. + unsigned reserved:26;
  72407. + } b;
  72408. + } flags;
  72409. +
  72410. + /**
  72411. + * Inactive items in the non-periodic schedule. This is a list of
  72412. + * Queue Heads. Transfers associated with these Queue Heads are not
  72413. + * currently assigned to a host channel.
  72414. + */
  72415. + dwc_list_link_t non_periodic_sched_inactive;
  72416. +
  72417. + /**
  72418. + * Active items in the non-periodic schedule. This is a list of
  72419. + * Queue Heads. Transfers associated with these Queue Heads are
  72420. + * currently assigned to a host channel.
  72421. + */
  72422. + dwc_list_link_t non_periodic_sched_active;
  72423. +
  72424. + /**
  72425. + * Pointer to the next Queue Head to process in the active
  72426. + * non-periodic schedule.
  72427. + */
  72428. + dwc_list_link_t *non_periodic_qh_ptr;
  72429. +
  72430. + /**
  72431. + * Inactive items in the periodic schedule. This is a list of QHs for
  72432. + * periodic transfers that are _not_ scheduled for the next frame.
  72433. + * Each QH in the list has an interval counter that determines when it
  72434. + * needs to be scheduled for execution. This scheduling mechanism
  72435. + * allows only a simple calculation for periodic bandwidth used (i.e.
  72436. + * must assume that all periodic transfers may need to execute in the
  72437. + * same frame). However, it greatly simplifies scheduling and should
  72438. + * be sufficient for the vast majority of OTG hosts, which need to
  72439. + * connect to a small number of peripherals at one time.
  72440. + *
  72441. + * Items move from this list to periodic_sched_ready when the QH
  72442. + * interval counter is 0 at SOF.
  72443. + */
  72444. + dwc_list_link_t periodic_sched_inactive;
  72445. +
  72446. + /**
  72447. + * List of periodic QHs that are ready for execution in the next
  72448. + * frame, but have not yet been assigned to host channels.
  72449. + *
  72450. + * Items move from this list to periodic_sched_assigned as host
  72451. + * channels become available during the current frame.
  72452. + */
  72453. + dwc_list_link_t periodic_sched_ready;
  72454. +
  72455. + /**
  72456. + * List of periodic QHs to be executed in the next frame that are
  72457. + * assigned to host channels.
  72458. + *
  72459. + * Items move from this list to periodic_sched_queued as the
  72460. + * transactions for the QH are queued to the DWC_otg controller.
  72461. + */
  72462. + dwc_list_link_t periodic_sched_assigned;
  72463. +
  72464. + /**
  72465. + * List of periodic QHs that have been queued for execution.
  72466. + *
  72467. + * Items move from this list to either periodic_sched_inactive or
  72468. + * periodic_sched_ready when the channel associated with the transfer
  72469. + * is released. If the interval for the QH is 1, the item moves to
  72470. + * periodic_sched_ready because it must be rescheduled for the next
  72471. + * frame. Otherwise, the item moves to periodic_sched_inactive.
  72472. + */
  72473. + dwc_list_link_t periodic_sched_queued;
  72474. +
  72475. + /**
  72476. + * Total bandwidth claimed so far for periodic transfers. This value
  72477. + * is in microseconds per (micro)frame. The assumption is that all
  72478. + * periodic transfers may occur in the same (micro)frame.
  72479. + */
  72480. + uint16_t periodic_usecs;
  72481. +
  72482. + /**
  72483. + * Total bandwidth claimed so far for all periodic transfers
  72484. + * in a frame.
  72485. + * This will include a mixture of HS and FS transfers.
  72486. + * Units are microseconds per (micro)frame.
  72487. + * We have a budget per frame and have to schedule
  72488. + * transactions accordingly.
  72489. + * Watch out for the fact that things are actually scheduled for the
  72490. + * "next frame".
  72491. + */
  72492. + uint16_t frame_usecs[8];
  72493. +
  72494. +
  72495. + /**
  72496. + * Frame number read from the core at SOF. The value ranges from 0 to
  72497. + * DWC_HFNUM_MAX_FRNUM.
  72498. + */
  72499. + uint16_t frame_number;
  72500. +
  72501. + /**
  72502. + * Count of periodic QHs, if using several eps. For SOF enable/disable.
  72503. + */
  72504. + uint16_t periodic_qh_count;
  72505. +
  72506. + /**
  72507. + * Free host channels in the controller. This is a list of
  72508. + * dwc_hc_t items.
  72509. + */
  72510. + struct hc_list free_hc_list;
  72511. + /**
  72512. + * Number of host channels assigned to periodic transfers. Currently
  72513. + * assuming that there is a dedicated host channel for each periodic
  72514. + * transaction and at least one host channel available for
  72515. + * non-periodic transactions.
  72516. + */
  72517. + int periodic_channels; /* microframe_schedule==0 */
  72518. +
  72519. + /**
  72520. + * Number of host channels assigned to non-periodic transfers.
  72521. + */
  72522. + int non_periodic_channels; /* microframe_schedule==0 */
  72523. +
  72524. + /**
  72525. + * Number of host channels assigned to non-periodic transfers.
  72526. + */
  72527. + int available_host_channels;
  72528. +
  72529. + /**
  72530. + * Array of pointers to the host channel descriptors. Allows accessing
  72531. + * a host channel descriptor given the host channel number. This is
  72532. + * useful in interrupt handlers.
  72533. + */
  72534. + struct dwc_hc *hc_ptr_array[MAX_EPS_CHANNELS];
  72535. +
  72536. + /**
  72537. + * Buffer to use for any data received during the status phase of a
  72538. + * control transfer. Normally no data is transferred during the status
  72539. + * phase. This buffer is used as a bit bucket.
  72540. + */
  72541. + uint8_t *status_buf;
  72542. +
  72543. + /**
  72544. + * DMA address for status_buf.
  72545. + */
  72546. + dma_addr_t status_buf_dma;
  72547. +#define DWC_OTG_HCD_STATUS_BUF_SIZE 64
  72548. +
  72549. + /**
  72550. + * Connection timer. An OTG host must display a message if the device
  72551. + * does not connect. Started when the VBus power is turned on via
  72552. + * sysfs attribute "buspower".
  72553. + */
  72554. + dwc_timer_t *conn_timer;
  72555. +
  72556. + /* Tasket to do a reset */
  72557. + dwc_tasklet_t *reset_tasklet;
  72558. +
  72559. + dwc_tasklet_t *completion_tasklet;
  72560. + struct urb_list completed_urb_list;
  72561. +
  72562. + /* */
  72563. + dwc_spinlock_t *lock;
  72564. + dwc_spinlock_t *channel_lock;
  72565. + /**
  72566. + * Private data that could be used by OS wrapper.
  72567. + */
  72568. + void *priv;
  72569. +
  72570. + uint8_t otg_port;
  72571. +
  72572. + /** Frame List */
  72573. + uint32_t *frame_list;
  72574. +
  72575. + /** Hub - Port assignment */
  72576. + int hub_port[128];
  72577. +#ifdef FIQ_DEBUG
  72578. + int hub_port_alloc[2048];
  72579. +#endif
  72580. +
  72581. + /** Frame List DMA address */
  72582. + dma_addr_t frame_list_dma;
  72583. +
  72584. +#ifdef DEBUG
  72585. + uint32_t frrem_samples;
  72586. + uint64_t frrem_accum;
  72587. +
  72588. + uint32_t hfnum_7_samples_a;
  72589. + uint64_t hfnum_7_frrem_accum_a;
  72590. + uint32_t hfnum_0_samples_a;
  72591. + uint64_t hfnum_0_frrem_accum_a;
  72592. + uint32_t hfnum_other_samples_a;
  72593. + uint64_t hfnum_other_frrem_accum_a;
  72594. +
  72595. + uint32_t hfnum_7_samples_b;
  72596. + uint64_t hfnum_7_frrem_accum_b;
  72597. + uint32_t hfnum_0_samples_b;
  72598. + uint64_t hfnum_0_frrem_accum_b;
  72599. + uint32_t hfnum_other_samples_b;
  72600. + uint64_t hfnum_other_frrem_accum_b;
  72601. +#endif
  72602. +};
  72603. +
  72604. +/** @name Transaction Execution Functions */
  72605. +/** @{ */
  72606. +extern dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t
  72607. + * hcd);
  72608. +extern void dwc_otg_hcd_queue_transactions(dwc_otg_hcd_t * hcd,
  72609. + dwc_otg_transaction_type_e tr_type);
  72610. +
  72611. +int dwc_otg_hcd_allocate_port(dwc_otg_hcd_t * hcd, dwc_otg_qh_t *qh);
  72612. +void dwc_otg_hcd_release_port(dwc_otg_hcd_t * dwc_otg_hcd, dwc_otg_qh_t *qh);
  72613. +
  72614. +
  72615. +/** @} */
  72616. +
  72617. +/** @name Interrupt Handler Functions */
  72618. +/** @{ */
  72619. +extern int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  72620. +extern int32_t dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  72621. +extern int32_t dwc_otg_hcd_handle_rx_status_q_level_intr(dwc_otg_hcd_t *
  72622. + dwc_otg_hcd);
  72623. +extern int32_t dwc_otg_hcd_handle_np_tx_fifo_empty_intr(dwc_otg_hcd_t *
  72624. + dwc_otg_hcd);
  72625. +extern int32_t dwc_otg_hcd_handle_perio_tx_fifo_empty_intr(dwc_otg_hcd_t *
  72626. + dwc_otg_hcd);
  72627. +extern int32_t dwc_otg_hcd_handle_incomplete_periodic_intr(dwc_otg_hcd_t *
  72628. + dwc_otg_hcd);
  72629. +extern int32_t dwc_otg_hcd_handle_port_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  72630. +extern int32_t dwc_otg_hcd_handle_conn_id_status_change_intr(dwc_otg_hcd_t *
  72631. + dwc_otg_hcd);
  72632. +extern int32_t dwc_otg_hcd_handle_disconnect_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  72633. +extern int32_t dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  72634. +extern int32_t dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd_t * dwc_otg_hcd,
  72635. + uint32_t num);
  72636. +extern int32_t dwc_otg_hcd_handle_session_req_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  72637. +extern int32_t dwc_otg_hcd_handle_wakeup_detected_intr(dwc_otg_hcd_t *
  72638. + dwc_otg_hcd);
  72639. +/** @} */
  72640. +
  72641. +/** @name Schedule Queue Functions */
  72642. +/** @{ */
  72643. +
  72644. +/* Implemented in dwc_otg_hcd_queue.c */
  72645. +extern dwc_otg_qh_t *dwc_otg_hcd_qh_create(dwc_otg_hcd_t * hcd,
  72646. + dwc_otg_hcd_urb_t * urb, int atomic_alloc);
  72647. +extern void dwc_otg_hcd_qh_free(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  72648. +extern int dwc_otg_hcd_qh_add(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  72649. +extern void dwc_otg_hcd_qh_remove(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  72650. +extern void dwc_otg_hcd_qh_deactivate(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  72651. + int sched_csplit);
  72652. +
  72653. +/** Remove and free a QH */
  72654. +static inline void dwc_otg_hcd_qh_remove_and_free(dwc_otg_hcd_t * hcd,
  72655. + dwc_otg_qh_t * qh)
  72656. +{
  72657. + dwc_irqflags_t flags;
  72658. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  72659. + dwc_otg_hcd_qh_remove(hcd, qh);
  72660. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  72661. + dwc_otg_hcd_qh_free(hcd, qh);
  72662. +}
  72663. +
  72664. +/** Allocates memory for a QH structure.
  72665. + * @return Returns the memory allocate or NULL on error. */
  72666. +static inline dwc_otg_qh_t *dwc_otg_hcd_qh_alloc(int atomic_alloc)
  72667. +{
  72668. + if (atomic_alloc)
  72669. + return (dwc_otg_qh_t *) DWC_ALLOC_ATOMIC(sizeof(dwc_otg_qh_t));
  72670. + else
  72671. + return (dwc_otg_qh_t *) DWC_ALLOC(sizeof(dwc_otg_qh_t));
  72672. +}
  72673. +
  72674. +extern dwc_otg_qtd_t *dwc_otg_hcd_qtd_create(dwc_otg_hcd_urb_t * urb,
  72675. + int atomic_alloc);
  72676. +extern void dwc_otg_hcd_qtd_init(dwc_otg_qtd_t * qtd, dwc_otg_hcd_urb_t * urb);
  72677. +extern int dwc_otg_hcd_qtd_add(dwc_otg_qtd_t * qtd, dwc_otg_hcd_t * dwc_otg_hcd,
  72678. + dwc_otg_qh_t ** qh, int atomic_alloc);
  72679. +
  72680. +/** Allocates memory for a QTD structure.
  72681. + * @return Returns the memory allocate or NULL on error. */
  72682. +static inline dwc_otg_qtd_t *dwc_otg_hcd_qtd_alloc(int atomic_alloc)
  72683. +{
  72684. + if (atomic_alloc)
  72685. + return (dwc_otg_qtd_t *) DWC_ALLOC_ATOMIC(sizeof(dwc_otg_qtd_t));
  72686. + else
  72687. + return (dwc_otg_qtd_t *) DWC_ALLOC(sizeof(dwc_otg_qtd_t));
  72688. +}
  72689. +
  72690. +/** Frees the memory for a QTD structure. QTD should already be removed from
  72691. + * list.
  72692. + * @param qtd QTD to free.*/
  72693. +static inline void dwc_otg_hcd_qtd_free(dwc_otg_qtd_t * qtd)
  72694. +{
  72695. + DWC_FREE(qtd);
  72696. +}
  72697. +
  72698. +/** Removes a QTD from list.
  72699. + * @param hcd HCD instance.
  72700. + * @param qtd QTD to remove from list.
  72701. + * @param qh QTD belongs to.
  72702. + */
  72703. +static inline void dwc_otg_hcd_qtd_remove(dwc_otg_hcd_t * hcd,
  72704. + dwc_otg_qtd_t * qtd,
  72705. + dwc_otg_qh_t * qh)
  72706. +{
  72707. + DWC_CIRCLEQ_REMOVE(&qh->qtd_list, qtd, qtd_list_entry);
  72708. +}
  72709. +
  72710. +/** Remove and free a QTD
  72711. + * Need to disable IRQ and hold hcd lock while calling this function out of
  72712. + * interrupt servicing chain */
  72713. +static inline void dwc_otg_hcd_qtd_remove_and_free(dwc_otg_hcd_t * hcd,
  72714. + dwc_otg_qtd_t * qtd,
  72715. + dwc_otg_qh_t * qh)
  72716. +{
  72717. + dwc_otg_hcd_qtd_remove(hcd, qtd, qh);
  72718. + dwc_otg_hcd_qtd_free(qtd);
  72719. +}
  72720. +
  72721. +/** @} */
  72722. +
  72723. +/** @name Descriptor DMA Supporting Functions */
  72724. +/** @{ */
  72725. +
  72726. +extern void dwc_otg_hcd_start_xfer_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  72727. +extern void dwc_otg_hcd_complete_xfer_ddma(dwc_otg_hcd_t * hcd,
  72728. + dwc_hc_t * hc,
  72729. + dwc_otg_hc_regs_t * hc_regs,
  72730. + dwc_otg_halt_status_e halt_status);
  72731. +
  72732. +extern int dwc_otg_hcd_qh_init_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  72733. +extern void dwc_otg_hcd_qh_free_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  72734. +
  72735. +/** @} */
  72736. +
  72737. +/** @name Internal Functions */
  72738. +/** @{ */
  72739. +dwc_otg_qh_t *dwc_urb_to_qh(dwc_otg_hcd_urb_t * urb);
  72740. +/** @} */
  72741. +
  72742. +#ifdef CONFIG_USB_DWC_OTG_LPM
  72743. +extern int dwc_otg_hcd_get_hc_for_lpm_tran(dwc_otg_hcd_t * hcd,
  72744. + uint8_t devaddr);
  72745. +extern void dwc_otg_hcd_free_hc_from_lpm(dwc_otg_hcd_t * hcd);
  72746. +#endif
  72747. +
  72748. +/** Gets the QH that contains the list_head */
  72749. +#define dwc_list_to_qh(_list_head_ptr_) container_of(_list_head_ptr_, dwc_otg_qh_t, qh_list_entry)
  72750. +
  72751. +/** Gets the QTD that contains the list_head */
  72752. +#define dwc_list_to_qtd(_list_head_ptr_) container_of(_list_head_ptr_, dwc_otg_qtd_t, qtd_list_entry)
  72753. +
  72754. +/** Check if QH is non-periodic */
  72755. +#define dwc_qh_is_non_per(_qh_ptr_) ((_qh_ptr_->ep_type == UE_BULK) || \
  72756. + (_qh_ptr_->ep_type == UE_CONTROL))
  72757. +
  72758. +/** High bandwidth multiplier as encoded in highspeed endpoint descriptors */
  72759. +#define dwc_hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
  72760. +
  72761. +/** Packet size for any kind of endpoint descriptor */
  72762. +#define dwc_max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff)
  72763. +
  72764. +/**
  72765. + * Returns true if _frame1 is less than or equal to _frame2. The comparison is
  72766. + * done modulo DWC_HFNUM_MAX_FRNUM. This accounts for the rollover of the
  72767. + * frame number when the max frame number is reached.
  72768. + */
  72769. +static inline int dwc_frame_num_le(uint16_t frame1, uint16_t frame2)
  72770. +{
  72771. + return ((frame2 - frame1) & DWC_HFNUM_MAX_FRNUM) <=
  72772. + (DWC_HFNUM_MAX_FRNUM >> 1);
  72773. +}
  72774. +
  72775. +/**
  72776. + * Returns true if _frame1 is greater than _frame2. The comparison is done
  72777. + * modulo DWC_HFNUM_MAX_FRNUM. This accounts for the rollover of the frame
  72778. + * number when the max frame number is reached.
  72779. + */
  72780. +static inline int dwc_frame_num_gt(uint16_t frame1, uint16_t frame2)
  72781. +{
  72782. + return (frame1 != frame2) &&
  72783. + (((frame1 - frame2) & DWC_HFNUM_MAX_FRNUM) <
  72784. + (DWC_HFNUM_MAX_FRNUM >> 1));
  72785. +}
  72786. +
  72787. +/**
  72788. + * Increments _frame by the amount specified by _inc. The addition is done
  72789. + * modulo DWC_HFNUM_MAX_FRNUM. Returns the incremented value.
  72790. + */
  72791. +static inline uint16_t dwc_frame_num_inc(uint16_t frame, uint16_t inc)
  72792. +{
  72793. + return (frame + inc) & DWC_HFNUM_MAX_FRNUM;
  72794. +}
  72795. +
  72796. +static inline uint16_t dwc_full_frame_num(uint16_t frame)
  72797. +{
  72798. + return (frame & DWC_HFNUM_MAX_FRNUM) >> 3;
  72799. +}
  72800. +
  72801. +static inline uint16_t dwc_micro_frame_num(uint16_t frame)
  72802. +{
  72803. + return frame & 0x7;
  72804. +}
  72805. +
  72806. +void dwc_otg_hcd_save_data_toggle(dwc_hc_t * hc,
  72807. + dwc_otg_hc_regs_t * hc_regs,
  72808. + dwc_otg_qtd_t * qtd);
  72809. +
  72810. +#ifdef DEBUG
  72811. +/**
  72812. + * Macro to sample the remaining PHY clocks left in the current frame. This
  72813. + * may be used during debugging to determine the average time it takes to
  72814. + * execute sections of code. There are two possible sample points, "a" and
  72815. + * "b", so the _letter argument must be one of these values.
  72816. + *
  72817. + * To dump the average sample times, read the "hcd_frrem" sysfs attribute. For
  72818. + * example, "cat /sys/devices/lm0/hcd_frrem".
  72819. + */
  72820. +#define dwc_sample_frrem(_hcd, _qh, _letter) \
  72821. +{ \
  72822. + hfnum_data_t hfnum; \
  72823. + dwc_otg_qtd_t *qtd; \
  72824. + qtd = list_entry(_qh->qtd_list.next, dwc_otg_qtd_t, qtd_list_entry); \
  72825. + if (usb_pipeint(qtd->urb->pipe) && _qh->start_split_frame != 0 && !qtd->complete_split) { \
  72826. + hfnum.d32 = DWC_READ_REG32(&_hcd->core_if->host_if->host_global_regs->hfnum); \
  72827. + switch (hfnum.b.frnum & 0x7) { \
  72828. + case 7: \
  72829. + _hcd->hfnum_7_samples_##_letter++; \
  72830. + _hcd->hfnum_7_frrem_accum_##_letter += hfnum.b.frrem; \
  72831. + break; \
  72832. + case 0: \
  72833. + _hcd->hfnum_0_samples_##_letter++; \
  72834. + _hcd->hfnum_0_frrem_accum_##_letter += hfnum.b.frrem; \
  72835. + break; \
  72836. + default: \
  72837. + _hcd->hfnum_other_samples_##_letter++; \
  72838. + _hcd->hfnum_other_frrem_accum_##_letter += hfnum.b.frrem; \
  72839. + break; \
  72840. + } \
  72841. + } \
  72842. +}
  72843. +#else
  72844. +#define dwc_sample_frrem(_hcd, _qh, _letter)
  72845. +#endif
  72846. +#endif
  72847. +#endif /* DWC_DEVICE_ONLY */
  72848. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h
  72849. --- linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h 1970-01-01 01:00:00.000000000 +0100
  72850. +++ linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h 2014-02-17 22:41:01.000000000 +0100
  72851. @@ -0,0 +1,417 @@
  72852. +/* ==========================================================================
  72853. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_if.h $
  72854. + * $Revision: #12 $
  72855. + * $Date: 2011/10/26 $
  72856. + * $Change: 1873028 $
  72857. + *
  72858. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  72859. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  72860. + * otherwise expressly agreed to in writing between Synopsys and you.
  72861. + *
  72862. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  72863. + * any End User Software License Agreement or Agreement for Licensed Product
  72864. + * with Synopsys or any supplement thereto. You are permitted to use and
  72865. + * redistribute this Software in source and binary forms, with or without
  72866. + * modification, provided that redistributions of source code must retain this
  72867. + * notice. You may not view, use, disclose, copy or distribute this file or
  72868. + * any information contained herein except pursuant to this license grant from
  72869. + * Synopsys. If you do not agree with this notice, including the disclaimer
  72870. + * below, then you are not authorized to use the Software.
  72871. + *
  72872. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  72873. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  72874. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  72875. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  72876. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  72877. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  72878. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  72879. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  72880. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  72881. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  72882. + * DAMAGE.
  72883. + * ========================================================================== */
  72884. +#ifndef DWC_DEVICE_ONLY
  72885. +#ifndef __DWC_HCD_IF_H__
  72886. +#define __DWC_HCD_IF_H__
  72887. +
  72888. +#include "dwc_otg_core_if.h"
  72889. +
  72890. +/** @file
  72891. + * This file defines DWC_OTG HCD Core API.
  72892. + */
  72893. +
  72894. +struct dwc_otg_hcd;
  72895. +typedef struct dwc_otg_hcd dwc_otg_hcd_t;
  72896. +
  72897. +struct dwc_otg_hcd_urb;
  72898. +typedef struct dwc_otg_hcd_urb dwc_otg_hcd_urb_t;
  72899. +
  72900. +/** @name HCD Function Driver Callbacks */
  72901. +/** @{ */
  72902. +
  72903. +/** This function is called whenever core switches to host mode. */
  72904. +typedef int (*dwc_otg_hcd_start_cb_t) (dwc_otg_hcd_t * hcd);
  72905. +
  72906. +/** This function is called when device has been disconnected */
  72907. +typedef int (*dwc_otg_hcd_disconnect_cb_t) (dwc_otg_hcd_t * hcd);
  72908. +
  72909. +/** Wrapper provides this function to HCD to core, so it can get hub information to which device is connected */
  72910. +typedef int (*dwc_otg_hcd_hub_info_from_urb_cb_t) (dwc_otg_hcd_t * hcd,
  72911. + void *urb_handle,
  72912. + uint32_t * hub_addr,
  72913. + uint32_t * port_addr);
  72914. +/** Via this function HCD core gets device speed */
  72915. +typedef int (*dwc_otg_hcd_speed_from_urb_cb_t) (dwc_otg_hcd_t * hcd,
  72916. + void *urb_handle);
  72917. +
  72918. +/** This function is called when urb is completed */
  72919. +typedef int (*dwc_otg_hcd_complete_urb_cb_t) (dwc_otg_hcd_t * hcd,
  72920. + void *urb_handle,
  72921. + dwc_otg_hcd_urb_t * dwc_otg_urb,
  72922. + int32_t status);
  72923. +
  72924. +/** Via this function HCD core gets b_hnp_enable parameter */
  72925. +typedef int (*dwc_otg_hcd_get_b_hnp_enable) (dwc_otg_hcd_t * hcd);
  72926. +
  72927. +struct dwc_otg_hcd_function_ops {
  72928. + dwc_otg_hcd_start_cb_t start;
  72929. + dwc_otg_hcd_disconnect_cb_t disconnect;
  72930. + dwc_otg_hcd_hub_info_from_urb_cb_t hub_info;
  72931. + dwc_otg_hcd_speed_from_urb_cb_t speed;
  72932. + dwc_otg_hcd_complete_urb_cb_t complete;
  72933. + dwc_otg_hcd_get_b_hnp_enable get_b_hnp_enable;
  72934. +};
  72935. +/** @} */
  72936. +
  72937. +/** @name HCD Core API */
  72938. +/** @{ */
  72939. +/** This function allocates dwc_otg_hcd structure and returns pointer on it. */
  72940. +extern dwc_otg_hcd_t *dwc_otg_hcd_alloc_hcd(void);
  72941. +
  72942. +/** This function should be called to initiate HCD Core.
  72943. + *
  72944. + * @param hcd The HCD
  72945. + * @param core_if The DWC_OTG Core
  72946. + *
  72947. + * Returns -DWC_E_NO_MEMORY if no enough memory.
  72948. + * Returns 0 on success
  72949. + */
  72950. +extern int dwc_otg_hcd_init(dwc_otg_hcd_t * hcd, dwc_otg_core_if_t * core_if);
  72951. +
  72952. +/** Frees HCD
  72953. + *
  72954. + * @param hcd The HCD
  72955. + */
  72956. +extern void dwc_otg_hcd_remove(dwc_otg_hcd_t * hcd);
  72957. +
  72958. +/** This function should be called on every hardware interrupt.
  72959. + *
  72960. + * @param dwc_otg_hcd The HCD
  72961. + *
  72962. + * Returns non zero if interrupt is handled
  72963. + * Return 0 if interrupt is not handled
  72964. + */
  72965. +extern int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  72966. +
  72967. +/** This function is used to handle the fast interrupt
  72968. + *
  72969. + */
  72970. +extern void __attribute__ ((naked)) dwc_otg_hcd_handle_fiq(void);
  72971. +
  72972. +/**
  72973. + * Returns private data set by
  72974. + * dwc_otg_hcd_set_priv_data function.
  72975. + *
  72976. + * @param hcd The HCD
  72977. + */
  72978. +extern void *dwc_otg_hcd_get_priv_data(dwc_otg_hcd_t * hcd);
  72979. +
  72980. +/**
  72981. + * Set private data.
  72982. + *
  72983. + * @param hcd The HCD
  72984. + * @param priv_data pointer to be stored in private data
  72985. + */
  72986. +extern void dwc_otg_hcd_set_priv_data(dwc_otg_hcd_t * hcd, void *priv_data);
  72987. +
  72988. +/**
  72989. + * This function initializes the HCD Core.
  72990. + *
  72991. + * @param hcd The HCD
  72992. + * @param fops The Function Driver Operations data structure containing pointers to all callbacks.
  72993. + *
  72994. + * Returns -DWC_E_NO_DEVICE if Core is currently is in device mode.
  72995. + * Returns 0 on success
  72996. + */
  72997. +extern int dwc_otg_hcd_start(dwc_otg_hcd_t * hcd,
  72998. + struct dwc_otg_hcd_function_ops *fops);
  72999. +
  73000. +/**
  73001. + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
  73002. + * stopped.
  73003. + *
  73004. + * @param hcd The HCD
  73005. + */
  73006. +extern void dwc_otg_hcd_stop(dwc_otg_hcd_t * hcd);
  73007. +
  73008. +/**
  73009. + * Handles hub class-specific requests.
  73010. + *
  73011. + * @param dwc_otg_hcd The HCD
  73012. + * @param typeReq Request Type
  73013. + * @param wValue wValue from control request
  73014. + * @param wIndex wIndex from control request
  73015. + * @param buf data buffer
  73016. + * @param wLength data buffer length
  73017. + *
  73018. + * Returns -DWC_E_INVALID if invalid argument is passed
  73019. + * Returns 0 on success
  73020. + */
  73021. +extern int dwc_otg_hcd_hub_control(dwc_otg_hcd_t * dwc_otg_hcd,
  73022. + uint16_t typeReq, uint16_t wValue,
  73023. + uint16_t wIndex, uint8_t * buf,
  73024. + uint16_t wLength);
  73025. +
  73026. +/**
  73027. + * Returns otg port number.
  73028. + *
  73029. + * @param hcd The HCD
  73030. + */
  73031. +extern uint32_t dwc_otg_hcd_otg_port(dwc_otg_hcd_t * hcd);
  73032. +
  73033. +/**
  73034. + * Returns OTG version - either 1.3 or 2.0.
  73035. + *
  73036. + * @param core_if The core_if structure pointer
  73037. + */
  73038. +extern uint16_t dwc_otg_get_otg_version(dwc_otg_core_if_t * core_if);
  73039. +
  73040. +/**
  73041. + * Returns 1 if currently core is acting as B host, and 0 otherwise.
  73042. + *
  73043. + * @param hcd The HCD
  73044. + */
  73045. +extern uint32_t dwc_otg_hcd_is_b_host(dwc_otg_hcd_t * hcd);
  73046. +
  73047. +/**
  73048. + * Returns current frame number.
  73049. + *
  73050. + * @param hcd The HCD
  73051. + */
  73052. +extern int dwc_otg_hcd_get_frame_number(dwc_otg_hcd_t * hcd);
  73053. +
  73054. +/**
  73055. + * Dumps hcd state.
  73056. + *
  73057. + * @param hcd The HCD
  73058. + */
  73059. +extern void dwc_otg_hcd_dump_state(dwc_otg_hcd_t * hcd);
  73060. +
  73061. +/**
  73062. + * Dump the average frame remaining at SOF. This can be used to
  73063. + * determine average interrupt latency. Frame remaining is also shown for
  73064. + * start transfer and two additional sample points.
  73065. + * Currently this function is not implemented.
  73066. + *
  73067. + * @param hcd The HCD
  73068. + */
  73069. +extern void dwc_otg_hcd_dump_frrem(dwc_otg_hcd_t * hcd);
  73070. +
  73071. +/**
  73072. + * Sends LPM transaction to the local device.
  73073. + *
  73074. + * @param hcd The HCD
  73075. + * @param devaddr Device Address
  73076. + * @param hird Host initiated resume duration
  73077. + * @param bRemoteWake Value of bRemoteWake field in LPM transaction
  73078. + *
  73079. + * Returns negative value if sending LPM transaction was not succeeded.
  73080. + * Returns 0 on success.
  73081. + */
  73082. +extern int dwc_otg_hcd_send_lpm(dwc_otg_hcd_t * hcd, uint8_t devaddr,
  73083. + uint8_t hird, uint8_t bRemoteWake);
  73084. +
  73085. +/* URB interface */
  73086. +
  73087. +/**
  73088. + * Allocates memory for dwc_otg_hcd_urb structure.
  73089. + * Allocated memory should be freed by call of DWC_FREE.
  73090. + *
  73091. + * @param hcd The HCD
  73092. + * @param iso_desc_count Count of ISOC descriptors
  73093. + * @param atomic_alloc Specefies whether to perform atomic allocation.
  73094. + */
  73095. +extern dwc_otg_hcd_urb_t *dwc_otg_hcd_urb_alloc(dwc_otg_hcd_t * hcd,
  73096. + int iso_desc_count,
  73097. + int atomic_alloc);
  73098. +
  73099. +/**
  73100. + * Set pipe information in URB.
  73101. + *
  73102. + * @param hcd_urb DWC_OTG URB
  73103. + * @param devaddr Device Address
  73104. + * @param ep_num Endpoint Number
  73105. + * @param ep_type Endpoint Type
  73106. + * @param ep_dir Endpoint Direction
  73107. + * @param mps Max Packet Size
  73108. + */
  73109. +extern void dwc_otg_hcd_urb_set_pipeinfo(dwc_otg_hcd_urb_t * hcd_urb,
  73110. + uint8_t devaddr, uint8_t ep_num,
  73111. + uint8_t ep_type, uint8_t ep_dir,
  73112. + uint16_t mps);
  73113. +
  73114. +/* Transfer flags */
  73115. +#define URB_GIVEBACK_ASAP 0x1
  73116. +#define URB_SEND_ZERO_PACKET 0x2
  73117. +
  73118. +/**
  73119. + * Sets dwc_otg_hcd_urb parameters.
  73120. + *
  73121. + * @param urb DWC_OTG URB allocated by dwc_otg_hcd_urb_alloc function.
  73122. + * @param urb_handle Unique handle for request, this will be passed back
  73123. + * to function driver in completion callback.
  73124. + * @param buf The buffer for the data
  73125. + * @param dma The DMA buffer for the data
  73126. + * @param buflen Transfer length
  73127. + * @param sp Buffer for setup data
  73128. + * @param sp_dma DMA address of setup data buffer
  73129. + * @param flags Transfer flags
  73130. + * @param interval Polling interval for interrupt or isochronous transfers.
  73131. + */
  73132. +extern void dwc_otg_hcd_urb_set_params(dwc_otg_hcd_urb_t * urb,
  73133. + void *urb_handle, void *buf,
  73134. + dwc_dma_t dma, uint32_t buflen, void *sp,
  73135. + dwc_dma_t sp_dma, uint32_t flags,
  73136. + uint16_t interval);
  73137. +
  73138. +/** Gets status from dwc_otg_hcd_urb
  73139. + *
  73140. + * @param dwc_otg_urb DWC_OTG URB
  73141. + */
  73142. +extern uint32_t dwc_otg_hcd_urb_get_status(dwc_otg_hcd_urb_t * dwc_otg_urb);
  73143. +
  73144. +/** Gets actual length from dwc_otg_hcd_urb
  73145. + *
  73146. + * @param dwc_otg_urb DWC_OTG URB
  73147. + */
  73148. +extern uint32_t dwc_otg_hcd_urb_get_actual_length(dwc_otg_hcd_urb_t *
  73149. + dwc_otg_urb);
  73150. +
  73151. +/** Gets error count from dwc_otg_hcd_urb. Only for ISOC URBs
  73152. + *
  73153. + * @param dwc_otg_urb DWC_OTG URB
  73154. + */
  73155. +extern uint32_t dwc_otg_hcd_urb_get_error_count(dwc_otg_hcd_urb_t *
  73156. + dwc_otg_urb);
  73157. +
  73158. +/** Set ISOC descriptor offset and length
  73159. + *
  73160. + * @param dwc_otg_urb DWC_OTG URB
  73161. + * @param desc_num ISOC descriptor number
  73162. + * @param offset Offset from beginig of buffer.
  73163. + * @param length Transaction length
  73164. + */
  73165. +extern void dwc_otg_hcd_urb_set_iso_desc_params(dwc_otg_hcd_urb_t * dwc_otg_urb,
  73166. + int desc_num, uint32_t offset,
  73167. + uint32_t length);
  73168. +
  73169. +/** Get status of ISOC descriptor, specified by desc_num
  73170. + *
  73171. + * @param dwc_otg_urb DWC_OTG URB
  73172. + * @param desc_num ISOC descriptor number
  73173. + */
  73174. +extern uint32_t dwc_otg_hcd_urb_get_iso_desc_status(dwc_otg_hcd_urb_t *
  73175. + dwc_otg_urb, int desc_num);
  73176. +
  73177. +/** Get actual length of ISOC descriptor, specified by desc_num
  73178. + *
  73179. + * @param dwc_otg_urb DWC_OTG URB
  73180. + * @param desc_num ISOC descriptor number
  73181. + */
  73182. +extern uint32_t dwc_otg_hcd_urb_get_iso_desc_actual_length(dwc_otg_hcd_urb_t *
  73183. + dwc_otg_urb,
  73184. + int desc_num);
  73185. +
  73186. +/** Queue URB. After transfer is completes, the complete callback will be called with the URB status
  73187. + *
  73188. + * @param dwc_otg_hcd The HCD
  73189. + * @param dwc_otg_urb DWC_OTG URB
  73190. + * @param ep_handle Out parameter for returning endpoint handle
  73191. + * @param atomic_alloc Flag to do atomic allocation if needed
  73192. + *
  73193. + * Returns -DWC_E_NO_DEVICE if no device is connected.
  73194. + * Returns -DWC_E_NO_MEMORY if there is no enough memory.
  73195. + * Returns 0 on success.
  73196. + */
  73197. +extern int dwc_otg_hcd_urb_enqueue(dwc_otg_hcd_t * dwc_otg_hcd,
  73198. + dwc_otg_hcd_urb_t * dwc_otg_urb,
  73199. + void **ep_handle, int atomic_alloc);
  73200. +
  73201. +/** De-queue the specified URB
  73202. + *
  73203. + * @param dwc_otg_hcd The HCD
  73204. + * @param dwc_otg_urb DWC_OTG URB
  73205. + */
  73206. +extern int dwc_otg_hcd_urb_dequeue(dwc_otg_hcd_t * dwc_otg_hcd,
  73207. + dwc_otg_hcd_urb_t * dwc_otg_urb);
  73208. +
  73209. +/** Frees resources in the DWC_otg controller related to a given endpoint.
  73210. + * Any URBs for the endpoint must already be dequeued.
  73211. + *
  73212. + * @param hcd The HCD
  73213. + * @param ep_handle Endpoint handle, returned by dwc_otg_hcd_urb_enqueue function
  73214. + * @param retry Number of retries if there are queued transfers.
  73215. + *
  73216. + * Returns -DWC_E_INVALID if invalid arguments are passed.
  73217. + * Returns 0 on success
  73218. + */
  73219. +extern int dwc_otg_hcd_endpoint_disable(dwc_otg_hcd_t * hcd, void *ep_handle,
  73220. + int retry);
  73221. +
  73222. +/* Resets the data toggle in qh structure. This function can be called from
  73223. + * usb_clear_halt routine.
  73224. + *
  73225. + * @param hcd The HCD
  73226. + * @param ep_handle Endpoint handle, returned by dwc_otg_hcd_urb_enqueue function
  73227. + *
  73228. + * Returns -DWC_E_INVALID if invalid arguments are passed.
  73229. + * Returns 0 on success
  73230. + */
  73231. +extern int dwc_otg_hcd_endpoint_reset(dwc_otg_hcd_t * hcd, void *ep_handle);
  73232. +
  73233. +/** Returns 1 if status of specified port is changed and 0 otherwise.
  73234. + *
  73235. + * @param hcd The HCD
  73236. + * @param port Port number
  73237. + */
  73238. +extern int dwc_otg_hcd_is_status_changed(dwc_otg_hcd_t * hcd, int port);
  73239. +
  73240. +/** Call this function to check if bandwidth was allocated for specified endpoint.
  73241. + * Only for ISOC and INTERRUPT endpoints.
  73242. + *
  73243. + * @param hcd The HCD
  73244. + * @param ep_handle Endpoint handle
  73245. + */
  73246. +extern int dwc_otg_hcd_is_bandwidth_allocated(dwc_otg_hcd_t * hcd,
  73247. + void *ep_handle);
  73248. +
  73249. +/** Call this function to check if bandwidth was freed for specified endpoint.
  73250. + *
  73251. + * @param hcd The HCD
  73252. + * @param ep_handle Endpoint handle
  73253. + */
  73254. +extern int dwc_otg_hcd_is_bandwidth_freed(dwc_otg_hcd_t * hcd, void *ep_handle);
  73255. +
  73256. +/** Returns bandwidth allocated for specified endpoint in microseconds.
  73257. + * Only for ISOC and INTERRUPT endpoints.
  73258. + *
  73259. + * @param hcd The HCD
  73260. + * @param ep_handle Endpoint handle
  73261. + */
  73262. +extern uint8_t dwc_otg_hcd_get_ep_bandwidth(dwc_otg_hcd_t * hcd,
  73263. + void *ep_handle);
  73264. +
  73265. +/** @} */
  73266. +
  73267. +#endif /* __DWC_HCD_IF_H__ */
  73268. +#endif /* DWC_DEVICE_ONLY */
  73269. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c
  73270. --- linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c 1970-01-01 01:00:00.000000000 +0100
  73271. +++ linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c 2014-02-17 22:41:01.000000000 +0100
  73272. @@ -0,0 +1,2741 @@
  73273. +/* ==========================================================================
  73274. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_intr.c $
  73275. + * $Revision: #89 $
  73276. + * $Date: 2011/10/20 $
  73277. + * $Change: 1869487 $
  73278. + *
  73279. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  73280. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  73281. + * otherwise expressly agreed to in writing between Synopsys and you.
  73282. + *
  73283. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  73284. + * any End User Software License Agreement or Agreement for Licensed Product
  73285. + * with Synopsys or any supplement thereto. You are permitted to use and
  73286. + * redistribute this Software in source and binary forms, with or without
  73287. + * modification, provided that redistributions of source code must retain this
  73288. + * notice. You may not view, use, disclose, copy or distribute this file or
  73289. + * any information contained herein except pursuant to this license grant from
  73290. + * Synopsys. If you do not agree with this notice, including the disclaimer
  73291. + * below, then you are not authorized to use the Software.
  73292. + *
  73293. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  73294. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  73295. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  73296. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  73297. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  73298. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  73299. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  73300. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  73301. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  73302. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  73303. + * DAMAGE.
  73304. + * ========================================================================== */
  73305. +#ifndef DWC_DEVICE_ONLY
  73306. +
  73307. +#include "dwc_otg_hcd.h"
  73308. +#include "dwc_otg_regs.h"
  73309. +#include "dwc_otg_mphi_fix.h"
  73310. +
  73311. +#include <linux/jiffies.h>
  73312. +#include <mach/hardware.h>
  73313. +#include <asm/fiq.h>
  73314. +
  73315. +
  73316. +extern bool microframe_schedule;
  73317. +
  73318. +/** @file
  73319. + * This file contains the implementation of the HCD Interrupt handlers.
  73320. + */
  73321. +
  73322. +/*
  73323. + * Some globals to communicate between the FIQ and INTERRUPT
  73324. + */
  73325. +
  73326. +void * dummy_send;
  73327. +mphi_regs_t c_mphi_regs;
  73328. +volatile void *dwc_regs_base;
  73329. +int fiq_done, int_done;
  73330. +
  73331. +gintsts_data_t gintsts_saved = {.d32 = 0};
  73332. +hcint_data_t hcint_saved[MAX_EPS_CHANNELS];
  73333. +hcintmsk_data_t hcintmsk_saved[MAX_EPS_CHANNELS];
  73334. +int split_out_xfersize[MAX_EPS_CHANNELS];
  73335. +haint_data_t haint_saved;
  73336. +
  73337. +int g_next_sched_frame, g_np_count, g_np_sent;
  73338. +static int mphi_int_count = 0 ;
  73339. +
  73340. +hcchar_data_t nak_hcchar;
  73341. +hctsiz_data_t nak_hctsiz;
  73342. +hcsplt_data_t nak_hcsplt;
  73343. +int nak_count;
  73344. +
  73345. +int complete_sched[MAX_EPS_CHANNELS] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
  73346. +int split_start_frame[MAX_EPS_CHANNELS];
  73347. +int queued_port[MAX_EPS_CHANNELS];
  73348. +
  73349. +#ifdef FIQ_DEBUG
  73350. +char buffer[1000*16];
  73351. +int wptr;
  73352. +void notrace _fiq_print(FIQDBG_T dbg_lvl, char *fmt, ...)
  73353. +{
  73354. + FIQDBG_T dbg_lvl_req = FIQDBG_PORTHUB;
  73355. + va_list args;
  73356. + char text[17];
  73357. + hfnum_data_t hfnum = { .d32 = FIQ_READ(dwc_regs_base + 0x408) };
  73358. + unsigned long flags;
  73359. +
  73360. + local_irq_save(flags);
  73361. + local_fiq_disable();
  73362. + if(dbg_lvl & dbg_lvl_req || dbg_lvl == FIQDBG_ERR)
  73363. + {
  73364. + snprintf(text, 9, "%4d%d:%d ", hfnum.b.frnum/8, hfnum.b.frnum%8, 8 - hfnum.b.frrem/937);
  73365. + va_start(args, fmt);
  73366. + vsnprintf(text+8, 9, fmt, args);
  73367. + va_end(args);
  73368. +
  73369. + memcpy(buffer + wptr, text, 16);
  73370. + wptr = (wptr + 16) % sizeof(buffer);
  73371. + }
  73372. + local_irq_restore(flags);
  73373. +}
  73374. +#endif
  73375. +
  73376. +void notrace fiq_queue_request(int channel, int odd_frame)
  73377. +{
  73378. + hcchar_data_t hcchar = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x0) };
  73379. + hcsplt_data_t hcsplt = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x4) };
  73380. + hctsiz_data_t hctsiz = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x10) };
  73381. +
  73382. + if(hcsplt.b.spltena == 0)
  73383. + {
  73384. + fiq_print(FIQDBG_ERR, "SPLTENA ");
  73385. + BUG();
  73386. + }
  73387. +
  73388. + if(hcchar.b.epdir == 1)
  73389. + {
  73390. + fiq_print(FIQDBG_SCHED, "IN Ch %d", channel);
  73391. + }
  73392. + else
  73393. + {
  73394. + hctsiz.b.xfersize = 0;
  73395. + fiq_print(FIQDBG_SCHED, "OUT Ch %d", channel);
  73396. + }
  73397. + FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0x10), hctsiz.d32);
  73398. +
  73399. + hcsplt.b.compsplt = 1;
  73400. + FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0x4), hcsplt.d32);
  73401. +
  73402. + // Send the Split complete
  73403. + hcchar.b.chen = 1;
  73404. + hcchar.b.oddfrm = odd_frame ? 1 : 0;
  73405. +
  73406. + // Post this for transmit on the next frame for periodic or this frame for non-periodic
  73407. + fiq_print(FIQDBG_SCHED, "SND_%s", odd_frame ? "ODD " : "EVEN");
  73408. +
  73409. + FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0x0), hcchar.d32);
  73410. +}
  73411. +
  73412. +static int last_sof = -1;
  73413. +
  73414. +/*
  73415. +** Function to handle the start of frame interrupt, choose whether we need to do anything and
  73416. +** therefore trigger the main interrupt
  73417. +**
  73418. +** returns int != 0 - interrupt has been handled
  73419. +*/
  73420. +int diff;
  73421. +
  73422. +int notrace fiq_sof_handle(hfnum_data_t hfnum)
  73423. +{
  73424. + int handled = 0;
  73425. + int i;
  73426. +
  73427. + // Just check that once we're running we don't miss a SOF
  73428. + /*if(last_sof != -1 && (hfnum.b.frnum != ((last_sof + 1) & 0x3fff)))
  73429. + {
  73430. + fiq_print(FIQDBG_ERR, "LASTSOF ");
  73431. + fiq_print(FIQDBG_ERR, "%4d%d ", last_sof / 8, last_sof & 7);
  73432. + fiq_print(FIQDBG_ERR, "%4d%d ", hfnum.b.frnum / 8, hfnum.b.frnum & 7);
  73433. + BUG();
  73434. + }*/
  73435. +
  73436. + // Only start remembering the last sof when the interrupt has been
  73437. + // enabled (we don't check the mask to come in here...)
  73438. + if(last_sof != -1 || FIQ_READ(dwc_regs_base + 0x18) & (1<<3))
  73439. + last_sof = hfnum.b.frnum;
  73440. +
  73441. + for(i = 0; i < MAX_EPS_CHANNELS; i++)
  73442. + {
  73443. + if(complete_sched[i] != -1)
  73444. + {
  73445. + if(complete_sched[i] <= hfnum.b.frnum || (complete_sched[i] > 0x3f00 && hfnum.b.frnum < 0xf0))
  73446. + {
  73447. + fiq_queue_request(i, hfnum.b.frnum & 1);
  73448. + complete_sched[i] = -1;
  73449. + }
  73450. + }
  73451. +
  73452. + if(complete_sched[i] != -1)
  73453. + {
  73454. + // This is because we've seen a split complete occur with no start...
  73455. + // most likely because missed the complete 0x3fff frames ago!
  73456. +
  73457. + diff = (hfnum.b.frnum + 0x3fff - complete_sched[i]) & 0x3fff ;
  73458. + if(diff > 32 && diff < 0x3f00)
  73459. + {
  73460. + fiq_print(FIQDBG_ERR, "SPLTMISS");
  73461. + BUG();
  73462. + }
  73463. + }
  73464. + }
  73465. +
  73466. + if(g_np_count == g_np_sent && dwc_frame_num_gt(g_next_sched_frame, hfnum.b.frnum))
  73467. + {
  73468. + /*
  73469. + * If np_count != np_sent that means we need to queue non-periodic (bulk) packets this packet
  73470. + * g_next_sched_frame is the next frame we have periodic packets for
  73471. + *
  73472. + * if neither of these are required for this frame then just clear the interrupt
  73473. + */
  73474. + handled = 1;
  73475. +
  73476. + }
  73477. +
  73478. + return handled;
  73479. +}
  73480. +
  73481. +int notrace port_id(hcsplt_data_t hcsplt)
  73482. +{
  73483. + return hcsplt.b.prtaddr + (hcsplt.b.hubaddr << 8);
  73484. +}
  73485. +
  73486. +int notrace fiq_hcintr_handle(int channel, hfnum_data_t hfnum)
  73487. +{
  73488. + hcchar_data_t hcchar = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x0) };
  73489. + hcsplt_data_t hcsplt = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x4) };
  73490. + hcint_data_t hcint = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x8) };
  73491. + hcintmsk_data_t hcintmsk = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0xc) };
  73492. + hctsiz_data_t hctsiz = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x10)};
  73493. +
  73494. + hcint_saved[channel].d32 |= hcint.d32;
  73495. + hcintmsk_saved[channel].d32 = hcintmsk.d32;
  73496. +
  73497. + if(hcsplt.b.spltena)
  73498. + {
  73499. + fiq_print(FIQDBG_PORTHUB, "ph: %4x", port_id(hcsplt));
  73500. + if(hcint.b.chhltd)
  73501. + {
  73502. + fiq_print(FIQDBG_SCHED, "CH HLT %d", channel);
  73503. + fiq_print(FIQDBG_SCHED, "%08x", hcint_saved[channel]);
  73504. + }
  73505. + if(hcint.b.stall || hcint.b.xacterr || hcint.b.bblerr || hcint.b.frmovrun || hcint.b.datatglerr)
  73506. + {
  73507. + queued_port[channel] = 0;
  73508. + fiq_print(FIQDBG_ERR, "CHAN ERR");
  73509. + }
  73510. + if(hcint.b.xfercomp)
  73511. + {
  73512. + // Clear the port allocation and transmit anything also on this port
  73513. + queued_port[channel] = 0;
  73514. + fiq_print(FIQDBG_SCHED, "XFERCOMP");
  73515. + }
  73516. + if(hcint.b.nak)
  73517. + {
  73518. + queued_port[channel] = 0;
  73519. + fiq_print(FIQDBG_SCHED, "NAK");
  73520. + }
  73521. + if(hcint.b.ack && !hcsplt.b.compsplt)
  73522. + {
  73523. + int i;
  73524. +
  73525. + // Do not complete isochronous out transactions
  73526. + if(hcchar.b.eptype == 1 && hcchar.b.epdir == 0)
  73527. + {
  73528. + queued_port[channel] = 0;
  73529. + fiq_print(FIQDBG_SCHED, "ISOC_OUT");
  73530. + }
  73531. + else
  73532. + {
  73533. + // Make sure we check the port / hub combination that we sent this split on.
  73534. + // Do not queue a second request to the same port
  73535. + for(i = 0; i < MAX_EPS_CHANNELS; i++)
  73536. + {
  73537. + if(port_id(hcsplt) == queued_port[i])
  73538. + {
  73539. + fiq_print(FIQDBG_ERR, "PORTERR ");
  73540. + //BUG();
  73541. + }
  73542. + }
  73543. +
  73544. + split_start_frame[channel] = (hfnum.b.frnum + 1) & ~7;
  73545. +
  73546. + // Note, the size of an OUT is in the start split phase, not
  73547. + // the complete split
  73548. + split_out_xfersize[channel] = hctsiz.b.xfersize;
  73549. +
  73550. + hcint_saved[channel].b.chhltd = 0;
  73551. + hcint_saved[channel].b.ack = 0;
  73552. +
  73553. + queued_port[channel] = port_id(hcsplt);
  73554. +
  73555. + if(hcchar.b.eptype & 1)
  73556. + {
  73557. + // Send the periodic complete in the same oddness frame as the ACK went...
  73558. + fiq_queue_request(channel, !(hfnum.b.frnum & 1));
  73559. + // complete_sched[channel] = dwc_frame_num_inc(hfnum.b.frnum, 1);
  73560. + }
  73561. + else
  73562. + {
  73563. + // Schedule the split complete to occur later
  73564. + complete_sched[channel] = dwc_frame_num_inc(hfnum.b.frnum, 2);
  73565. + fiq_print(FIQDBG_SCHED, "ACK%04d%d", complete_sched[channel]/8, complete_sched[channel]%8);
  73566. + }
  73567. + }
  73568. + }
  73569. + if(hcint.b.nyet)
  73570. + {
  73571. + fiq_print(FIQDBG_ERR, "NYETERR1");
  73572. + //BUG();
  73573. + // Can transmit a split complete up to uframe .0 of the next frame
  73574. + if(hfnum.b.frnum <= dwc_frame_num_inc(split_start_frame[channel], 8))
  73575. + {
  73576. + // Send it next frame
  73577. + if(hcchar.b.eptype & 1) // type 1 & 3 are interrupt & isoc
  73578. + {
  73579. + fiq_print(FIQDBG_SCHED, "NYT:SEND");
  73580. + fiq_queue_request(channel, !(hfnum.b.frnum & 1));
  73581. + }
  73582. + else
  73583. + {
  73584. + // Schedule non-periodic access for next frame (the odd-even bit doesn't effect NP)
  73585. + complete_sched[channel] = dwc_frame_num_inc(hfnum.b.frnum, 1);
  73586. + fiq_print(FIQDBG_SCHED, "NYT%04d%d", complete_sched[channel]/8, complete_sched[channel]%8);
  73587. + }
  73588. + hcint_saved[channel].b.chhltd = 0;
  73589. + hcint_saved[channel].b.nyet = 0;
  73590. + }
  73591. + else
  73592. + {
  73593. + queued_port[channel] = 0;
  73594. + fiq_print(FIQDBG_ERR, "NYETERR2");
  73595. + //BUG();
  73596. + }
  73597. + }
  73598. + }
  73599. + else
  73600. + {
  73601. + /*
  73602. + * If we have any of NAK, ACK, Datatlgerr active on a
  73603. + * non-split channel, the sole reason is to reset error
  73604. + * counts for a previously broken transaction. The FIQ
  73605. + * will thrash on NAK IN and ACK OUT in particular so
  73606. + * handle it "once" and allow the IRQ to do the rest.
  73607. + */
  73608. + hcint.d32 &= hcintmsk.d32;
  73609. + if(hcint.b.nak)
  73610. + {
  73611. + hcintmsk.b.nak = 0;
  73612. + FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0xc), hcintmsk.d32);
  73613. + }
  73614. + if (hcint.b.ack)
  73615. + {
  73616. + hcintmsk.b.ack = 0;
  73617. + FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0xc), hcintmsk.d32);
  73618. + }
  73619. + }
  73620. +
  73621. + // Clear the interrupt, this will also clear the HAINT bit
  73622. + FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0x8), hcint.d32);
  73623. + return hcint_saved[channel].d32 == 0;
  73624. +}
  73625. +
  73626. +gintsts_data_t gintsts;
  73627. +gintmsk_data_t gintmsk;
  73628. +// triggered: The set of interrupts that were triggered
  73629. +// handled: The set of interrupts that have been handled (no IRQ is
  73630. +// required)
  73631. +// keep: The set of interrupts we want to keep unmasked even though we
  73632. +// want to trigger an IRQ to handle it (SOF and HCINTR)
  73633. +gintsts_data_t triggered, handled, keep;
  73634. +hfnum_data_t hfnum;
  73635. +
  73636. +void __attribute__ ((naked)) notrace dwc_otg_hcd_handle_fiq(void)
  73637. +{
  73638. +
  73639. + /* entry takes care to store registers we will be treading on here */
  73640. + asm __volatile__ (
  73641. + "mov ip, sp ;"
  73642. + /* stash FIQ and normal regs */
  73643. + "stmdb sp!, {r0-r12, lr};"
  73644. + /* !! THIS SETS THE FRAME, adjust to > sizeof locals */
  73645. + "sub fp, ip, #512 ;"
  73646. + );
  73647. +
  73648. + // Cannot put local variables at the beginning of the function
  73649. + // because otherwise 'C' will play with the stack pointer. any locals
  73650. + // need to be inside the following block
  73651. + do
  73652. + {
  73653. + fiq_done++;
  73654. + gintsts.d32 = FIQ_READ(dwc_regs_base + 0x14);
  73655. + gintmsk.d32 = FIQ_READ(dwc_regs_base + 0x18);
  73656. + hfnum.d32 = FIQ_READ(dwc_regs_base + 0x408);
  73657. + triggered.d32 = gintsts.d32 & gintmsk.d32;
  73658. + handled.d32 = 0;
  73659. + keep.d32 = 0;
  73660. + fiq_print(FIQDBG_INT, "FIQ ");
  73661. + fiq_print(FIQDBG_INT, "%08x", gintsts.d32);
  73662. + fiq_print(FIQDBG_INT, "%08x", gintmsk.d32);
  73663. + if(gintsts.d32)
  73664. + {
  73665. + // If port enabled
  73666. + if((FIQ_READ(dwc_regs_base + 0x440) & 0xf) == 0x5)
  73667. + {
  73668. + if(gintsts.b.sofintr)
  73669. + {
  73670. + if(fiq_sof_handle(hfnum))
  73671. + {
  73672. + handled.b.sofintr = 1; /* Handled in FIQ */
  73673. + }
  73674. + else
  73675. + {
  73676. + /* Keer interrupt unmasked */
  73677. + keep.b.sofintr = 1;
  73678. + }
  73679. + {
  73680. + // Need to make sure the read and clearing of the SOF interrupt is as close as possible to avoid the possibility of missing
  73681. + // a start of frame interrupt
  73682. + gintsts_data_t gintsts = { .b.sofintr = 1 };
  73683. + FIQ_WRITE((dwc_regs_base + 0x14), gintsts.d32);
  73684. + }
  73685. + }
  73686. +
  73687. + if(fiq_split_enable && gintsts.b.hcintr)
  73688. + {
  73689. + int i;
  73690. + haint_data_t haint;
  73691. + haintmsk_data_t haintmsk;
  73692. +
  73693. + haint.d32 = FIQ_READ(dwc_regs_base + 0x414);
  73694. + haintmsk.d32 = FIQ_READ(dwc_regs_base + 0x418);
  73695. + haint.d32 &= haintmsk.d32;
  73696. + haint_saved.d32 |= haint.d32;
  73697. +
  73698. + fiq_print(FIQDBG_INT, "hcintr");
  73699. + fiq_print(FIQDBG_INT, "%08x", FIQ_READ(dwc_regs_base + 0x414));
  73700. +
  73701. + // Go through each channel that has an enabled interrupt
  73702. + for(i = 0; i < 16; i++)
  73703. + if((haint.d32 >> i) & 1)
  73704. + if(fiq_hcintr_handle(i, hfnum))
  73705. + haint_saved.d32 &= ~(1 << i); /* this was handled */
  73706. +
  73707. + /* If we've handled all host channel interrupts then don't trigger the interrupt */
  73708. + if(haint_saved.d32 == 0)
  73709. + {
  73710. + handled.b.hcintr = 1;
  73711. + }
  73712. + else
  73713. + {
  73714. + /* Make sure we keep the channel interrupt unmasked when triggering the IRQ */
  73715. + keep.b.hcintr = 1;
  73716. + }
  73717. +
  73718. + {
  73719. + gintsts_data_t gintsts = { .b.hcintr = 1 };
  73720. +
  73721. + // Always clear the channel interrupt
  73722. + FIQ_WRITE((dwc_regs_base + 0x14), gintsts.d32);
  73723. + }
  73724. + }
  73725. + }
  73726. + else
  73727. + {
  73728. + last_sof = -1;
  73729. + }
  73730. + }
  73731. +
  73732. + // Mask out the interrupts triggered - those handled - don't mask out the ones we want to keep
  73733. + gintmsk.d32 = keep.d32 | (gintmsk.d32 & ~(triggered.d32 & ~handled.d32));
  73734. + // Save those that were triggered but not handled
  73735. + gintsts_saved.d32 |= triggered.d32 & ~handled.d32;
  73736. + FIQ_WRITE(dwc_regs_base + 0x18, gintmsk.d32);
  73737. +
  73738. + // Clear and save any unhandled interrupts and trigger the interrupt
  73739. + if(gintsts_saved.d32)
  73740. + {
  73741. + /* To enable the MPHI interrupt (INT 32)
  73742. + */
  73743. + FIQ_WRITE( c_mphi_regs.outdda, (int) dummy_send);
  73744. + FIQ_WRITE( c_mphi_regs.outddb, (1 << 29));
  73745. +
  73746. + mphi_int_count++;
  73747. + }
  73748. + }
  73749. + while(0);
  73750. +
  73751. + mb();
  73752. +
  73753. + /* exit back to normal mode restoring everything */
  73754. + asm __volatile__ (
  73755. + /* return FIQ regs back to pristine state
  73756. + * and get normal regs back
  73757. + */
  73758. + "ldmia sp!, {r0-r12, lr};"
  73759. +
  73760. + /* return */
  73761. + "subs pc, lr, #4;"
  73762. + );
  73763. +}
  73764. +
  73765. +/** This function handles interrupts for the HCD. */
  73766. +int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  73767. +{
  73768. + int retval = 0;
  73769. + static int last_time;
  73770. +
  73771. + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
  73772. + gintsts_data_t gintsts;
  73773. + gintmsk_data_t gintmsk;
  73774. + hfnum_data_t hfnum;
  73775. +
  73776. +#ifdef DEBUG
  73777. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  73778. +
  73779. +#endif
  73780. +
  73781. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  73782. + gintmsk.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  73783. +
  73784. + /* Exit from ISR if core is hibernated */
  73785. + if (core_if->hibernation_suspend == 1) {
  73786. + goto exit_handler_routine;
  73787. + }
  73788. + DWC_SPINLOCK(dwc_otg_hcd->lock);
  73789. + /* Check if HOST Mode */
  73790. + if (dwc_otg_is_host_mode(core_if)) {
  73791. + local_fiq_disable();
  73792. + gintmsk.d32 |= gintsts_saved.d32;
  73793. + gintsts.d32 |= gintsts_saved.d32;
  73794. + gintsts_saved.d32 = 0;
  73795. + local_fiq_enable();
  73796. + if (!gintsts.d32) {
  73797. + goto exit_handler_routine;
  73798. + }
  73799. + gintsts.d32 &= gintmsk.d32;
  73800. +
  73801. +#ifdef DEBUG
  73802. + // We should be OK doing this because the common interrupts should already have been serviced
  73803. + /* Don't print debug message in the interrupt handler on SOF */
  73804. +#ifndef DEBUG_SOF
  73805. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  73806. +#endif
  73807. + DWC_DEBUGPL(DBG_HCDI, "\n");
  73808. +#endif
  73809. +
  73810. +#ifdef DEBUG
  73811. +#ifndef DEBUG_SOF
  73812. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  73813. +#endif
  73814. + DWC_DEBUGPL(DBG_HCDI,
  73815. + "DWC OTG HCD Interrupt Detected gintsts&gintmsk=0x%08x core_if=%p\n",
  73816. + gintsts.d32, core_if);
  73817. +#endif
  73818. + hfnum.d32 = DWC_READ_REG32(&dwc_otg_hcd->core_if->host_if->host_global_regs->hfnum);
  73819. + if (gintsts.b.sofintr && g_np_count == g_np_sent && dwc_frame_num_gt(g_next_sched_frame, hfnum.b.frnum))
  73820. + {
  73821. + /* Note, we should never get here if the FIQ is doing it's job properly*/
  73822. + retval |= dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd);
  73823. + }
  73824. + else if (gintsts.b.sofintr) {
  73825. + retval |= dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd);
  73826. + }
  73827. +
  73828. + if (gintsts.b.rxstsqlvl) {
  73829. + retval |=
  73830. + dwc_otg_hcd_handle_rx_status_q_level_intr
  73831. + (dwc_otg_hcd);
  73832. + }
  73833. + if (gintsts.b.nptxfempty) {
  73834. + retval |=
  73835. + dwc_otg_hcd_handle_np_tx_fifo_empty_intr
  73836. + (dwc_otg_hcd);
  73837. + }
  73838. + if (gintsts.b.i2cintr) {
  73839. + /** @todo Implement i2cintr handler. */
  73840. + }
  73841. + if (gintsts.b.portintr) {
  73842. +
  73843. + gintmsk_data_t gintmsk = { .b.portintr = 1};
  73844. + retval |= dwc_otg_hcd_handle_port_intr(dwc_otg_hcd);
  73845. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, gintmsk.d32);
  73846. + }
  73847. + if (gintsts.b.hcintr) {
  73848. + retval |= dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd);
  73849. + }
  73850. + if (gintsts.b.ptxfempty) {
  73851. + retval |=
  73852. + dwc_otg_hcd_handle_perio_tx_fifo_empty_intr
  73853. + (dwc_otg_hcd);
  73854. + }
  73855. +#ifdef DEBUG
  73856. +#ifndef DEBUG_SOF
  73857. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  73858. +#endif
  73859. + {
  73860. + DWC_DEBUGPL(DBG_HCDI,
  73861. + "DWC OTG HCD Finished Servicing Interrupts\n");
  73862. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD gintsts=0x%08x\n",
  73863. + DWC_READ_REG32(&global_regs->gintsts));
  73864. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD gintmsk=0x%08x\n",
  73865. + DWC_READ_REG32(&global_regs->gintmsk));
  73866. + }
  73867. +#endif
  73868. +
  73869. +#ifdef DEBUG
  73870. +#ifndef DEBUG_SOF
  73871. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  73872. +#endif
  73873. + DWC_DEBUGPL(DBG_HCDI, "\n");
  73874. +#endif
  73875. +
  73876. + }
  73877. +
  73878. +exit_handler_routine:
  73879. +
  73880. + if (fiq_fix_enable)
  73881. + {
  73882. + local_fiq_disable();
  73883. + // Make sure that we don't clear the interrupt if we've still got pending work to do
  73884. + if(gintsts_saved.d32 == 0)
  73885. + {
  73886. + /* Clear the MPHI interrupt */
  73887. + DWC_WRITE_REG32(c_mphi_regs.intstat, (1<<16));
  73888. + if (mphi_int_count >= 60)
  73889. + {
  73890. + DWC_WRITE_REG32(c_mphi_regs.ctrl, ((1<<31) + (1<<16)));
  73891. + while(!(DWC_READ_REG32(c_mphi_regs.ctrl) & (1 << 17)))
  73892. + ;
  73893. + DWC_WRITE_REG32(c_mphi_regs.ctrl, (1<<31));
  73894. + mphi_int_count = 0;
  73895. + }
  73896. + int_done++;
  73897. + }
  73898. +
  73899. + // Unmask handled interrupts
  73900. + FIQ_WRITE(dwc_regs_base + 0x18, gintmsk.d32);
  73901. + //DWC_MODIFY_REG32((uint32_t *)IO_ADDRESS(USB_BASE + 0x8), 0 , 1);
  73902. +
  73903. + local_fiq_enable();
  73904. +
  73905. + if((jiffies / HZ) > last_time)
  73906. + {
  73907. + /* Once a second output the fiq and irq numbers, useful for debug */
  73908. + last_time = jiffies / HZ;
  73909. + DWC_DEBUGPL(DBG_USER, "int_done = %d fiq_done = %d\n", int_done, fiq_done);
  73910. + }
  73911. + }
  73912. +
  73913. + DWC_SPINUNLOCK(dwc_otg_hcd->lock);
  73914. + return retval;
  73915. +}
  73916. +
  73917. +#ifdef DWC_TRACK_MISSED_SOFS
  73918. +
  73919. +#warning Compiling code to track missed SOFs
  73920. +#define FRAME_NUM_ARRAY_SIZE 1000
  73921. +/**
  73922. + * This function is for debug only.
  73923. + */
  73924. +static inline void track_missed_sofs(uint16_t curr_frame_number)
  73925. +{
  73926. + static uint16_t frame_num_array[FRAME_NUM_ARRAY_SIZE];
  73927. + static uint16_t last_frame_num_array[FRAME_NUM_ARRAY_SIZE];
  73928. + static int frame_num_idx = 0;
  73929. + static uint16_t last_frame_num = DWC_HFNUM_MAX_FRNUM;
  73930. + static int dumped_frame_num_array = 0;
  73931. +
  73932. + if (frame_num_idx < FRAME_NUM_ARRAY_SIZE) {
  73933. + if (((last_frame_num + 1) & DWC_HFNUM_MAX_FRNUM) !=
  73934. + curr_frame_number) {
  73935. + frame_num_array[frame_num_idx] = curr_frame_number;
  73936. + last_frame_num_array[frame_num_idx++] = last_frame_num;
  73937. + }
  73938. + } else if (!dumped_frame_num_array) {
  73939. + int i;
  73940. + DWC_PRINTF("Frame Last Frame\n");
  73941. + DWC_PRINTF("----- ----------\n");
  73942. + for (i = 0; i < FRAME_NUM_ARRAY_SIZE; i++) {
  73943. + DWC_PRINTF("0x%04x 0x%04x\n",
  73944. + frame_num_array[i], last_frame_num_array[i]);
  73945. + }
  73946. + dumped_frame_num_array = 1;
  73947. + }
  73948. + last_frame_num = curr_frame_number;
  73949. +}
  73950. +#endif
  73951. +
  73952. +/**
  73953. + * Handles the start-of-frame interrupt in host mode. Non-periodic
  73954. + * transactions may be queued to the DWC_otg controller for the current
  73955. + * (micro)frame. Periodic transactions may be queued to the controller for the
  73956. + * next (micro)frame.
  73957. + */
  73958. +int32_t dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd_t * hcd)
  73959. +{
  73960. + hfnum_data_t hfnum;
  73961. + dwc_list_link_t *qh_entry;
  73962. + dwc_otg_qh_t *qh;
  73963. + dwc_otg_transaction_type_e tr_type;
  73964. + int did_something = 0;
  73965. + int32_t next_sched_frame = -1;
  73966. +
  73967. + hfnum.d32 =
  73968. + DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hfnum);
  73969. +
  73970. +#ifdef DEBUG_SOF
  73971. + DWC_DEBUGPL(DBG_HCD, "--Start of Frame Interrupt--\n");
  73972. +#endif
  73973. + hcd->frame_number = hfnum.b.frnum;
  73974. +
  73975. +#ifdef DEBUG
  73976. + hcd->frrem_accum += hfnum.b.frrem;
  73977. + hcd->frrem_samples++;
  73978. +#endif
  73979. +
  73980. +#ifdef DWC_TRACK_MISSED_SOFS
  73981. + track_missed_sofs(hcd->frame_number);
  73982. +#endif
  73983. + /* Determine whether any periodic QHs should be executed. */
  73984. + qh_entry = DWC_LIST_FIRST(&hcd->periodic_sched_inactive);
  73985. + while (qh_entry != &hcd->periodic_sched_inactive) {
  73986. + qh = DWC_LIST_ENTRY(qh_entry, dwc_otg_qh_t, qh_list_entry);
  73987. + qh_entry = qh_entry->next;
  73988. + if (dwc_frame_num_le(qh->sched_frame, hcd->frame_number)) {
  73989. +
  73990. + /*
  73991. + * Move QH to the ready list to be executed next
  73992. + * (micro)frame.
  73993. + */
  73994. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_ready,
  73995. + &qh->qh_list_entry);
  73996. +
  73997. + did_something = 1;
  73998. + }
  73999. + else
  74000. + {
  74001. + if(next_sched_frame < 0 || dwc_frame_num_le(qh->sched_frame, next_sched_frame))
  74002. + {
  74003. + next_sched_frame = qh->sched_frame;
  74004. + }
  74005. + }
  74006. + }
  74007. +
  74008. + g_next_sched_frame = next_sched_frame;
  74009. +
  74010. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  74011. + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
  74012. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  74013. + did_something = 1;
  74014. + }
  74015. +
  74016. + /* Clear interrupt */
  74017. + gintsts.b.sofintr = 1;
  74018. + DWC_WRITE_REG32(&hcd->core_if->core_global_regs->gintsts, gintsts.d32);
  74019. +
  74020. + return 1;
  74021. +}
  74022. +
  74023. +/** Handles the Rx Status Queue Level Interrupt, which indicates that there is at
  74024. + * least one packet in the Rx FIFO. The packets are moved from the FIFO to
  74025. + * memory if the DWC_otg controller is operating in Slave mode. */
  74026. +int32_t dwc_otg_hcd_handle_rx_status_q_level_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  74027. +{
  74028. + host_grxsts_data_t grxsts;
  74029. + dwc_hc_t *hc = NULL;
  74030. +
  74031. + DWC_DEBUGPL(DBG_HCD, "--RxStsQ Level Interrupt--\n");
  74032. +
  74033. + grxsts.d32 =
  74034. + DWC_READ_REG32(&dwc_otg_hcd->core_if->core_global_regs->grxstsp);
  74035. +
  74036. + hc = dwc_otg_hcd->hc_ptr_array[grxsts.b.chnum];
  74037. + if (!hc) {
  74038. + DWC_ERROR("Unable to get corresponding channel\n");
  74039. + return 0;
  74040. + }
  74041. +
  74042. + /* Packet Status */
  74043. + DWC_DEBUGPL(DBG_HCDV, " Ch num = %d\n", grxsts.b.chnum);
  74044. + DWC_DEBUGPL(DBG_HCDV, " Count = %d\n", grxsts.b.bcnt);
  74045. + DWC_DEBUGPL(DBG_HCDV, " DPID = %d, hc.dpid = %d\n", grxsts.b.dpid,
  74046. + hc->data_pid_start);
  74047. + DWC_DEBUGPL(DBG_HCDV, " PStatus = %d\n", grxsts.b.pktsts);
  74048. +
  74049. + switch (grxsts.b.pktsts) {
  74050. + case DWC_GRXSTS_PKTSTS_IN:
  74051. + /* Read the data into the host buffer. */
  74052. + if (grxsts.b.bcnt > 0) {
  74053. + dwc_otg_read_packet(dwc_otg_hcd->core_if,
  74054. + hc->xfer_buff, grxsts.b.bcnt);
  74055. +
  74056. + /* Update the HC fields for the next packet received. */
  74057. + hc->xfer_count += grxsts.b.bcnt;
  74058. + hc->xfer_buff += grxsts.b.bcnt;
  74059. + }
  74060. +
  74061. + case DWC_GRXSTS_PKTSTS_IN_XFER_COMP:
  74062. + case DWC_GRXSTS_PKTSTS_DATA_TOGGLE_ERR:
  74063. + case DWC_GRXSTS_PKTSTS_CH_HALTED:
  74064. + /* Handled in interrupt, just ignore data */
  74065. + break;
  74066. + default:
  74067. + DWC_ERROR("RX_STS_Q Interrupt: Unknown status %d\n",
  74068. + grxsts.b.pktsts);
  74069. + break;
  74070. + }
  74071. +
  74072. + return 1;
  74073. +}
  74074. +
  74075. +/** This interrupt occurs when the non-periodic Tx FIFO is half-empty. More
  74076. + * data packets may be written to the FIFO for OUT transfers. More requests
  74077. + * may be written to the non-periodic request queue for IN transfers. This
  74078. + * interrupt is enabled only in Slave mode. */
  74079. +int32_t dwc_otg_hcd_handle_np_tx_fifo_empty_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  74080. +{
  74081. + DWC_DEBUGPL(DBG_HCD, "--Non-Periodic TxFIFO Empty Interrupt--\n");
  74082. + dwc_otg_hcd_queue_transactions(dwc_otg_hcd,
  74083. + DWC_OTG_TRANSACTION_NON_PERIODIC);
  74084. + return 1;
  74085. +}
  74086. +
  74087. +/** This interrupt occurs when the periodic Tx FIFO is half-empty. More data
  74088. + * packets may be written to the FIFO for OUT transfers. More requests may be
  74089. + * written to the periodic request queue for IN transfers. This interrupt is
  74090. + * enabled only in Slave mode. */
  74091. +int32_t dwc_otg_hcd_handle_perio_tx_fifo_empty_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  74092. +{
  74093. + DWC_DEBUGPL(DBG_HCD, "--Periodic TxFIFO Empty Interrupt--\n");
  74094. + dwc_otg_hcd_queue_transactions(dwc_otg_hcd,
  74095. + DWC_OTG_TRANSACTION_PERIODIC);
  74096. + return 1;
  74097. +}
  74098. +
  74099. +/** There are multiple conditions that can cause a port interrupt. This function
  74100. + * determines which interrupt conditions have occurred and handles them
  74101. + * appropriately. */
  74102. +int32_t dwc_otg_hcd_handle_port_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  74103. +{
  74104. + int retval = 0;
  74105. + hprt0_data_t hprt0;
  74106. + hprt0_data_t hprt0_modify;
  74107. +
  74108. + hprt0.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  74109. + hprt0_modify.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  74110. +
  74111. + /* Clear appropriate bits in HPRT0 to clear the interrupt bit in
  74112. + * GINTSTS */
  74113. +
  74114. + hprt0_modify.b.prtena = 0;
  74115. + hprt0_modify.b.prtconndet = 0;
  74116. + hprt0_modify.b.prtenchng = 0;
  74117. + hprt0_modify.b.prtovrcurrchng = 0;
  74118. +
  74119. + /* Port Connect Detected
  74120. + * Set flag and clear if detected */
  74121. + if (dwc_otg_hcd->core_if->hibernation_suspend == 1) {
  74122. + // Dont modify port status if we are in hibernation state
  74123. + hprt0_modify.b.prtconndet = 1;
  74124. + hprt0_modify.b.prtenchng = 1;
  74125. + DWC_WRITE_REG32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0_modify.d32);
  74126. + hprt0.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  74127. + return retval;
  74128. + }
  74129. +
  74130. + if (hprt0.b.prtconndet) {
  74131. + /** @todo - check if steps performed in 'else' block should be perfromed regardles adp */
  74132. + if (dwc_otg_hcd->core_if->adp_enable &&
  74133. + dwc_otg_hcd->core_if->adp.vbuson_timer_started == 1) {
  74134. + DWC_PRINTF("PORT CONNECT DETECTED ----------------\n");
  74135. + DWC_TIMER_CANCEL(dwc_otg_hcd->core_if->adp.vbuson_timer);
  74136. + dwc_otg_hcd->core_if->adp.vbuson_timer_started = 0;
  74137. + /* TODO - check if this is required, as
  74138. + * host initialization was already performed
  74139. + * after initial ADP probing
  74140. + */
  74141. + /*dwc_otg_hcd->core_if->adp.vbuson_timer_started = 0;
  74142. + dwc_otg_core_init(dwc_otg_hcd->core_if);
  74143. + dwc_otg_enable_global_interrupts(dwc_otg_hcd->core_if);
  74144. + cil_hcd_start(dwc_otg_hcd->core_if);*/
  74145. + } else {
  74146. +
  74147. + DWC_DEBUGPL(DBG_HCD, "--Port Interrupt HPRT0=0x%08x "
  74148. + "Port Connect Detected--\n", hprt0.d32);
  74149. + dwc_otg_hcd->flags.b.port_connect_status_change = 1;
  74150. + dwc_otg_hcd->flags.b.port_connect_status = 1;
  74151. + hprt0_modify.b.prtconndet = 1;
  74152. +
  74153. + /* B-Device has connected, Delete the connection timer. */
  74154. + DWC_TIMER_CANCEL(dwc_otg_hcd->conn_timer);
  74155. + }
  74156. + /* The Hub driver asserts a reset when it sees port connect
  74157. + * status change flag */
  74158. + retval |= 1;
  74159. + }
  74160. +
  74161. + /* Port Enable Changed
  74162. + * Clear if detected - Set internal flag if disabled */
  74163. + if (hprt0.b.prtenchng) {
  74164. + DWC_DEBUGPL(DBG_HCD, " --Port Interrupt HPRT0=0x%08x "
  74165. + "Port Enable Changed--\n", hprt0.d32);
  74166. + hprt0_modify.b.prtenchng = 1;
  74167. + if (hprt0.b.prtena == 1) {
  74168. + hfir_data_t hfir;
  74169. + int do_reset = 0;
  74170. + dwc_otg_core_params_t *params =
  74171. + dwc_otg_hcd->core_if->core_params;
  74172. + dwc_otg_core_global_regs_t *global_regs =
  74173. + dwc_otg_hcd->core_if->core_global_regs;
  74174. + dwc_otg_host_if_t *host_if =
  74175. + dwc_otg_hcd->core_if->host_if;
  74176. +
  74177. + /* Every time when port enables calculate
  74178. + * HFIR.FrInterval
  74179. + */
  74180. + hfir.d32 = DWC_READ_REG32(&host_if->host_global_regs->hfir);
  74181. + hfir.b.frint = calc_frame_interval(dwc_otg_hcd->core_if);
  74182. + DWC_WRITE_REG32(&host_if->host_global_regs->hfir, hfir.d32);
  74183. +
  74184. + /* Check if we need to adjust the PHY clock speed for
  74185. + * low power and adjust it */
  74186. + if (params->host_support_fs_ls_low_power) {
  74187. + gusbcfg_data_t usbcfg;
  74188. +
  74189. + usbcfg.d32 =
  74190. + DWC_READ_REG32(&global_regs->gusbcfg);
  74191. +
  74192. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED
  74193. + || hprt0.b.prtspd ==
  74194. + DWC_HPRT0_PRTSPD_FULL_SPEED) {
  74195. + /*
  74196. + * Low power
  74197. + */
  74198. + hcfg_data_t hcfg;
  74199. + if (usbcfg.b.phylpwrclksel == 0) {
  74200. + /* Set PHY low power clock select for FS/LS devices */
  74201. + usbcfg.b.phylpwrclksel = 1;
  74202. + DWC_WRITE_REG32
  74203. + (&global_regs->gusbcfg,
  74204. + usbcfg.d32);
  74205. + do_reset = 1;
  74206. + }
  74207. +
  74208. + hcfg.d32 =
  74209. + DWC_READ_REG32
  74210. + (&host_if->host_global_regs->hcfg);
  74211. +
  74212. + if (hprt0.b.prtspd ==
  74213. + DWC_HPRT0_PRTSPD_LOW_SPEED
  74214. + && params->host_ls_low_power_phy_clk
  74215. + ==
  74216. + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ)
  74217. + {
  74218. + /* 6 MHZ */
  74219. + DWC_DEBUGPL(DBG_CIL,
  74220. + "FS_PHY programming HCFG to 6 MHz (Low Power)\n");
  74221. + if (hcfg.b.fslspclksel !=
  74222. + DWC_HCFG_6_MHZ) {
  74223. + hcfg.b.fslspclksel =
  74224. + DWC_HCFG_6_MHZ;
  74225. + DWC_WRITE_REG32
  74226. + (&host_if->host_global_regs->hcfg,
  74227. + hcfg.d32);
  74228. + do_reset = 1;
  74229. + }
  74230. + } else {
  74231. + /* 48 MHZ */
  74232. + DWC_DEBUGPL(DBG_CIL,
  74233. + "FS_PHY programming HCFG to 48 MHz ()\n");
  74234. + if (hcfg.b.fslspclksel !=
  74235. + DWC_HCFG_48_MHZ) {
  74236. + hcfg.b.fslspclksel =
  74237. + DWC_HCFG_48_MHZ;
  74238. + DWC_WRITE_REG32
  74239. + (&host_if->host_global_regs->hcfg,
  74240. + hcfg.d32);
  74241. + do_reset = 1;
  74242. + }
  74243. + }
  74244. + } else {
  74245. + /*
  74246. + * Not low power
  74247. + */
  74248. + if (usbcfg.b.phylpwrclksel == 1) {
  74249. + usbcfg.b.phylpwrclksel = 0;
  74250. + DWC_WRITE_REG32
  74251. + (&global_regs->gusbcfg,
  74252. + usbcfg.d32);
  74253. + do_reset = 1;
  74254. + }
  74255. + }
  74256. +
  74257. + if (do_reset) {
  74258. + DWC_TASK_SCHEDULE(dwc_otg_hcd->reset_tasklet);
  74259. + }
  74260. + }
  74261. +
  74262. + if (!do_reset) {
  74263. + /* Port has been enabled set the reset change flag */
  74264. + dwc_otg_hcd->flags.b.port_reset_change = 1;
  74265. + }
  74266. + } else {
  74267. + dwc_otg_hcd->flags.b.port_enable_change = 1;
  74268. + }
  74269. + retval |= 1;
  74270. + }
  74271. +
  74272. + /** Overcurrent Change Interrupt */
  74273. + if (hprt0.b.prtovrcurrchng) {
  74274. + DWC_DEBUGPL(DBG_HCD, " --Port Interrupt HPRT0=0x%08x "
  74275. + "Port Overcurrent Changed--\n", hprt0.d32);
  74276. + dwc_otg_hcd->flags.b.port_over_current_change = 1;
  74277. + hprt0_modify.b.prtovrcurrchng = 1;
  74278. + retval |= 1;
  74279. + }
  74280. +
  74281. + /* Clear Port Interrupts */
  74282. + DWC_WRITE_REG32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0_modify.d32);
  74283. +
  74284. + return retval;
  74285. +}
  74286. +
  74287. +/** This interrupt indicates that one or more host channels has a pending
  74288. + * interrupt. There are multiple conditions that can cause each host channel
  74289. + * interrupt. This function determines which conditions have occurred for each
  74290. + * host channel interrupt and handles them appropriately. */
  74291. +int32_t dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  74292. +{
  74293. + int i;
  74294. + int retval = 0;
  74295. + haint_data_t haint;
  74296. +
  74297. + /* Clear appropriate bits in HCINTn to clear the interrupt bit in
  74298. + * GINTSTS */
  74299. +
  74300. + haint.d32 = dwc_otg_read_host_all_channels_intr(dwc_otg_hcd->core_if);
  74301. +
  74302. + // Overwrite with saved interrupts from fiq handler
  74303. + if(fiq_split_enable)
  74304. + {
  74305. + local_fiq_disable();
  74306. + haint.d32 = haint_saved.d32;
  74307. + haint_saved.d32 = 0;
  74308. + local_fiq_enable();
  74309. + }
  74310. +
  74311. + for (i = 0; i < dwc_otg_hcd->core_if->core_params->host_channels; i++) {
  74312. + if (haint.b2.chint & (1 << i)) {
  74313. + retval |= dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd, i);
  74314. + }
  74315. + }
  74316. +
  74317. + return retval;
  74318. +}
  74319. +
  74320. +/**
  74321. + * Gets the actual length of a transfer after the transfer halts. _halt_status
  74322. + * holds the reason for the halt.
  74323. + *
  74324. + * For IN transfers where halt_status is DWC_OTG_HC_XFER_COMPLETE,
  74325. + * *short_read is set to 1 upon return if less than the requested
  74326. + * number of bytes were transferred. Otherwise, *short_read is set to 0 upon
  74327. + * return. short_read may also be NULL on entry, in which case it remains
  74328. + * unchanged.
  74329. + */
  74330. +static uint32_t get_actual_xfer_length(dwc_hc_t * hc,
  74331. + dwc_otg_hc_regs_t * hc_regs,
  74332. + dwc_otg_qtd_t * qtd,
  74333. + dwc_otg_halt_status_e halt_status,
  74334. + int *short_read)
  74335. +{
  74336. + hctsiz_data_t hctsiz;
  74337. + uint32_t length;
  74338. +
  74339. + if (short_read != NULL) {
  74340. + *short_read = 0;
  74341. + }
  74342. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  74343. +
  74344. + if (halt_status == DWC_OTG_HC_XFER_COMPLETE) {
  74345. + if (hc->ep_is_in) {
  74346. + length = hc->xfer_len - hctsiz.b.xfersize;
  74347. + if (short_read != NULL) {
  74348. + *short_read = (hctsiz.b.xfersize != 0);
  74349. + }
  74350. + } else if (hc->qh->do_split) {
  74351. + if(fiq_split_enable)
  74352. + length = split_out_xfersize[hc->hc_num];
  74353. + else
  74354. + length = qtd->ssplit_out_xfer_count;
  74355. + } else {
  74356. + length = hc->xfer_len;
  74357. + }
  74358. + } else {
  74359. + /*
  74360. + * Must use the hctsiz.pktcnt field to determine how much data
  74361. + * has been transferred. This field reflects the number of
  74362. + * packets that have been transferred via the USB. This is
  74363. + * always an integral number of packets if the transfer was
  74364. + * halted before its normal completion. (Can't use the
  74365. + * hctsiz.xfersize field because that reflects the number of
  74366. + * bytes transferred via the AHB, not the USB).
  74367. + */
  74368. + length =
  74369. + (hc->start_pkt_count - hctsiz.b.pktcnt) * hc->max_packet;
  74370. + }
  74371. +
  74372. + return length;
  74373. +}
  74374. +
  74375. +/**
  74376. + * Updates the state of the URB after a Transfer Complete interrupt on the
  74377. + * host channel. Updates the actual_length field of the URB based on the
  74378. + * number of bytes transferred via the host channel. Sets the URB status
  74379. + * if the data transfer is finished.
  74380. + *
  74381. + * @return 1 if the data transfer specified by the URB is completely finished,
  74382. + * 0 otherwise.
  74383. + */
  74384. +static int update_urb_state_xfer_comp(dwc_hc_t * hc,
  74385. + dwc_otg_hc_regs_t * hc_regs,
  74386. + dwc_otg_hcd_urb_t * urb,
  74387. + dwc_otg_qtd_t * qtd)
  74388. +{
  74389. + int xfer_done = 0;
  74390. + int short_read = 0;
  74391. +
  74392. + int xfer_length;
  74393. +
  74394. + xfer_length = get_actual_xfer_length(hc, hc_regs, qtd,
  74395. + DWC_OTG_HC_XFER_COMPLETE,
  74396. + &short_read);
  74397. +
  74398. + /* non DWORD-aligned buffer case handling. */
  74399. + if (hc->align_buff && xfer_length && hc->ep_is_in) {
  74400. + dwc_memcpy(urb->buf + urb->actual_length, hc->qh->dw_align_buf,
  74401. + xfer_length);
  74402. + }
  74403. +
  74404. + urb->actual_length += xfer_length;
  74405. +
  74406. + if (xfer_length && (hc->ep_type == DWC_OTG_EP_TYPE_BULK) &&
  74407. + (urb->flags & URB_SEND_ZERO_PACKET)
  74408. + && (urb->actual_length == urb->length)
  74409. + && !(urb->length % hc->max_packet)) {
  74410. + xfer_done = 0;
  74411. + } else if (short_read || urb->actual_length >= urb->length) {
  74412. + xfer_done = 1;
  74413. + urb->status = 0;
  74414. + }
  74415. +
  74416. +#ifdef DEBUG
  74417. + {
  74418. + hctsiz_data_t hctsiz;
  74419. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  74420. + DWC_DEBUGPL(DBG_HCDV, "DWC_otg: %s: %s, channel %d\n",
  74421. + __func__, (hc->ep_is_in ? "IN" : "OUT"),
  74422. + hc->hc_num);
  74423. + DWC_DEBUGPL(DBG_HCDV, " hc->xfer_len %d\n", hc->xfer_len);
  74424. + DWC_DEBUGPL(DBG_HCDV, " hctsiz.xfersize %d\n",
  74425. + hctsiz.b.xfersize);
  74426. + DWC_DEBUGPL(DBG_HCDV, " urb->transfer_buffer_length %d\n",
  74427. + urb->length);
  74428. + DWC_DEBUGPL(DBG_HCDV, " urb->actual_length %d\n",
  74429. + urb->actual_length);
  74430. + DWC_DEBUGPL(DBG_HCDV, " short_read %d, xfer_done %d\n",
  74431. + short_read, xfer_done);
  74432. + }
  74433. +#endif
  74434. +
  74435. + return xfer_done;
  74436. +}
  74437. +
  74438. +/*
  74439. + * Save the starting data toggle for the next transfer. The data toggle is
  74440. + * saved in the QH for non-control transfers and it's saved in the QTD for
  74441. + * control transfers.
  74442. + */
  74443. +void dwc_otg_hcd_save_data_toggle(dwc_hc_t * hc,
  74444. + dwc_otg_hc_regs_t * hc_regs, dwc_otg_qtd_t * qtd)
  74445. +{
  74446. + hctsiz_data_t hctsiz;
  74447. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  74448. +
  74449. + if (hc->ep_type != DWC_OTG_EP_TYPE_CONTROL) {
  74450. + dwc_otg_qh_t *qh = hc->qh;
  74451. + if (hctsiz.b.pid == DWC_HCTSIZ_DATA0) {
  74452. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  74453. + } else {
  74454. + qh->data_toggle = DWC_OTG_HC_PID_DATA1;
  74455. + }
  74456. + } else {
  74457. + if (hctsiz.b.pid == DWC_HCTSIZ_DATA0) {
  74458. + qtd->data_toggle = DWC_OTG_HC_PID_DATA0;
  74459. + } else {
  74460. + qtd->data_toggle = DWC_OTG_HC_PID_DATA1;
  74461. + }
  74462. + }
  74463. +}
  74464. +
  74465. +/**
  74466. + * Updates the state of an Isochronous URB when the transfer is stopped for
  74467. + * any reason. The fields of the current entry in the frame descriptor array
  74468. + * are set based on the transfer state and the input _halt_status. Completes
  74469. + * the Isochronous URB if all the URB frames have been completed.
  74470. + *
  74471. + * @return DWC_OTG_HC_XFER_COMPLETE if there are more frames remaining to be
  74472. + * transferred in the URB. Otherwise return DWC_OTG_HC_XFER_URB_COMPLETE.
  74473. + */
  74474. +static dwc_otg_halt_status_e
  74475. +update_isoc_urb_state(dwc_otg_hcd_t * hcd,
  74476. + dwc_hc_t * hc,
  74477. + dwc_otg_hc_regs_t * hc_regs,
  74478. + dwc_otg_qtd_t * qtd, dwc_otg_halt_status_e halt_status)
  74479. +{
  74480. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  74481. + dwc_otg_halt_status_e ret_val = halt_status;
  74482. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  74483. +
  74484. + frame_desc = &urb->iso_descs[qtd->isoc_frame_index];
  74485. + switch (halt_status) {
  74486. + case DWC_OTG_HC_XFER_COMPLETE:
  74487. + frame_desc->status = 0;
  74488. + frame_desc->actual_length =
  74489. + get_actual_xfer_length(hc, hc_regs, qtd, halt_status, NULL);
  74490. +
  74491. + /* non DWORD-aligned buffer case handling. */
  74492. + if (hc->align_buff && frame_desc->actual_length && hc->ep_is_in) {
  74493. + dwc_memcpy(urb->buf + frame_desc->offset + qtd->isoc_split_offset,
  74494. + hc->qh->dw_align_buf, frame_desc->actual_length);
  74495. + }
  74496. +
  74497. + break;
  74498. + case DWC_OTG_HC_XFER_FRAME_OVERRUN:
  74499. + urb->error_count++;
  74500. + if (hc->ep_is_in) {
  74501. + frame_desc->status = -DWC_E_NO_STREAM_RES;
  74502. + } else {
  74503. + frame_desc->status = -DWC_E_COMMUNICATION;
  74504. + }
  74505. + frame_desc->actual_length = 0;
  74506. + break;
  74507. + case DWC_OTG_HC_XFER_BABBLE_ERR:
  74508. + urb->error_count++;
  74509. + frame_desc->status = -DWC_E_OVERFLOW;
  74510. + /* Don't need to update actual_length in this case. */
  74511. + break;
  74512. + case DWC_OTG_HC_XFER_XACT_ERR:
  74513. + urb->error_count++;
  74514. + frame_desc->status = -DWC_E_PROTOCOL;
  74515. + frame_desc->actual_length =
  74516. + get_actual_xfer_length(hc, hc_regs, qtd, halt_status, NULL);
  74517. +
  74518. + /* non DWORD-aligned buffer case handling. */
  74519. + if (hc->align_buff && frame_desc->actual_length && hc->ep_is_in) {
  74520. + dwc_memcpy(urb->buf + frame_desc->offset + qtd->isoc_split_offset,
  74521. + hc->qh->dw_align_buf, frame_desc->actual_length);
  74522. + }
  74523. + /* Skip whole frame */
  74524. + if (hc->qh->do_split && (hc->ep_type == DWC_OTG_EP_TYPE_ISOC) &&
  74525. + hc->ep_is_in && hcd->core_if->dma_enable) {
  74526. + qtd->complete_split = 0;
  74527. + qtd->isoc_split_offset = 0;
  74528. + }
  74529. +
  74530. + break;
  74531. + default:
  74532. + DWC_ASSERT(1, "Unhandled _halt_status (%d)\n", halt_status);
  74533. + break;
  74534. + }
  74535. + if (++qtd->isoc_frame_index == urb->packet_count) {
  74536. + /*
  74537. + * urb->status is not used for isoc transfers.
  74538. + * The individual frame_desc statuses are used instead.
  74539. + */
  74540. + hcd->fops->complete(hcd, urb->priv, urb, 0);
  74541. + ret_val = DWC_OTG_HC_XFER_URB_COMPLETE;
  74542. + } else {
  74543. + ret_val = DWC_OTG_HC_XFER_COMPLETE;
  74544. + }
  74545. + return ret_val;
  74546. +}
  74547. +
  74548. +/**
  74549. + * Frees the first QTD in the QH's list if free_qtd is 1. For non-periodic
  74550. + * QHs, removes the QH from the active non-periodic schedule. If any QTDs are
  74551. + * still linked to the QH, the QH is added to the end of the inactive
  74552. + * non-periodic schedule. For periodic QHs, removes the QH from the periodic
  74553. + * schedule if no more QTDs are linked to the QH.
  74554. + */
  74555. +static void deactivate_qh(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh, int free_qtd)
  74556. +{
  74557. + int continue_split = 0;
  74558. + dwc_otg_qtd_t *qtd;
  74559. +
  74560. + DWC_DEBUGPL(DBG_HCDV, " %s(%p,%p,%d)\n", __func__, hcd, qh, free_qtd);
  74561. +
  74562. + qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  74563. +
  74564. + if (qtd->complete_split) {
  74565. + continue_split = 1;
  74566. + } else if (qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_MID ||
  74567. + qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_END) {
  74568. + continue_split = 1;
  74569. + }
  74570. +
  74571. + if (free_qtd) {
  74572. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  74573. + continue_split = 0;
  74574. + }
  74575. +
  74576. + qh->channel = NULL;
  74577. + dwc_otg_hcd_qh_deactivate(hcd, qh, continue_split);
  74578. +}
  74579. +
  74580. +/**
  74581. + * Releases a host channel for use by other transfers. Attempts to select and
  74582. + * queue more transactions since at least one host channel is available.
  74583. + *
  74584. + * @param hcd The HCD state structure.
  74585. + * @param hc The host channel to release.
  74586. + * @param qtd The QTD associated with the host channel. This QTD may be freed
  74587. + * if the transfer is complete or an error has occurred.
  74588. + * @param halt_status Reason the channel is being released. This status
  74589. + * determines the actions taken by this function.
  74590. + */
  74591. +static void release_channel(dwc_otg_hcd_t * hcd,
  74592. + dwc_hc_t * hc,
  74593. + dwc_otg_qtd_t * qtd,
  74594. + dwc_otg_halt_status_e halt_status)
  74595. +{
  74596. + dwc_otg_transaction_type_e tr_type;
  74597. + int free_qtd;
  74598. + dwc_irqflags_t flags;
  74599. + dwc_spinlock_t *channel_lock = hcd->channel_lock;
  74600. +#ifdef FIQ_DEBUG
  74601. + int endp = qtd->urb ? qtd->urb->pipe_info.ep_num : 0;
  74602. +#endif
  74603. + int hog_port = 0;
  74604. +
  74605. + DWC_DEBUGPL(DBG_HCDV, " %s: channel %d, halt_status %d, xfer_len %d\n",
  74606. + __func__, hc->hc_num, halt_status, hc->xfer_len);
  74607. +
  74608. + if(fiq_split_enable && hc->do_split) {
  74609. + if(!hc->ep_is_in && hc->ep_type == UE_ISOCHRONOUS) {
  74610. + if(hc->xact_pos == DWC_HCSPLIT_XACTPOS_MID ||
  74611. + hc->xact_pos == DWC_HCSPLIT_XACTPOS_BEGIN) {
  74612. + hog_port = 1;
  74613. + }
  74614. + }
  74615. + }
  74616. +
  74617. + switch (halt_status) {
  74618. + case DWC_OTG_HC_XFER_URB_COMPLETE:
  74619. + free_qtd = 1;
  74620. + break;
  74621. + case DWC_OTG_HC_XFER_AHB_ERR:
  74622. + case DWC_OTG_HC_XFER_STALL:
  74623. + case DWC_OTG_HC_XFER_BABBLE_ERR:
  74624. + free_qtd = 1;
  74625. + break;
  74626. + case DWC_OTG_HC_XFER_XACT_ERR:
  74627. + if (qtd->error_count >= 3) {
  74628. + DWC_DEBUGPL(DBG_HCDV,
  74629. + " Complete URB with transaction error\n");
  74630. + free_qtd = 1;
  74631. + qtd->urb->status = -DWC_E_PROTOCOL;
  74632. + hcd->fops->complete(hcd, qtd->urb->priv,
  74633. + qtd->urb, -DWC_E_PROTOCOL);
  74634. + } else {
  74635. + free_qtd = 0;
  74636. + }
  74637. + break;
  74638. + case DWC_OTG_HC_XFER_URB_DEQUEUE:
  74639. + /*
  74640. + * The QTD has already been removed and the QH has been
  74641. + * deactivated. Don't want to do anything except release the
  74642. + * host channel and try to queue more transfers.
  74643. + */
  74644. + goto cleanup;
  74645. + case DWC_OTG_HC_XFER_NO_HALT_STATUS:
  74646. + free_qtd = 0;
  74647. + break;
  74648. + case DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE:
  74649. + DWC_DEBUGPL(DBG_HCDV,
  74650. + " Complete URB with I/O error\n");
  74651. + free_qtd = 1;
  74652. + qtd->urb->status = -DWC_E_IO;
  74653. + hcd->fops->complete(hcd, qtd->urb->priv,
  74654. + qtd->urb, -DWC_E_IO);
  74655. + break;
  74656. + default:
  74657. + free_qtd = 0;
  74658. + break;
  74659. + }
  74660. +
  74661. + deactivate_qh(hcd, hc->qh, free_qtd);
  74662. +
  74663. +cleanup:
  74664. + /*
  74665. + * Release the host channel for use by other transfers. The cleanup
  74666. + * function clears the channel interrupt enables and conditions, so
  74667. + * there's no need to clear the Channel Halted interrupt separately.
  74668. + */
  74669. + dwc_otg_hc_cleanup(hcd->core_if, hc);
  74670. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, hc, hc_list_entry);
  74671. +
  74672. + if (!microframe_schedule) {
  74673. + switch (hc->ep_type) {
  74674. + case DWC_OTG_EP_TYPE_CONTROL:
  74675. + case DWC_OTG_EP_TYPE_BULK:
  74676. + hcd->non_periodic_channels--;
  74677. + break;
  74678. +
  74679. + default:
  74680. + /*
  74681. + * Don't release reservations for periodic channels here.
  74682. + * That's done when a periodic transfer is descheduled (i.e.
  74683. + * when the QH is removed from the periodic schedule).
  74684. + */
  74685. + break;
  74686. + }
  74687. + } else {
  74688. +
  74689. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  74690. + hcd->available_host_channels++;
  74691. + fiq_print(FIQDBG_PORTHUB, "AHC = %d ", hcd->available_host_channels);
  74692. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  74693. + }
  74694. +
  74695. + if(fiq_split_enable && hc->do_split)
  74696. + {
  74697. + if(!(hcd->hub_port[hc->hub_addr] & (1 << hc->port_addr)))
  74698. + {
  74699. + fiq_print(FIQDBG_ERR, "PRTNOTAL");
  74700. + //BUG();
  74701. + }
  74702. + if(!hog_port && (hc->ep_type == DWC_OTG_EP_TYPE_ISOC ||
  74703. + hc->ep_type == DWC_OTG_EP_TYPE_INTR)) {
  74704. + hcd->hub_port[hc->hub_addr] &= ~(1 << hc->port_addr);
  74705. +#ifdef FIQ_DEBUG
  74706. + hcd->hub_port_alloc[hc->hub_addr * 16 + hc->port_addr] = -1;
  74707. +#endif
  74708. + fiq_print(FIQDBG_PORTHUB, "H%dP%d:RR%d", hc->hub_addr, hc->port_addr, endp);
  74709. + }
  74710. + }
  74711. +
  74712. + /* Try to queue more transfers now that there's a free channel. */
  74713. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  74714. + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
  74715. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  74716. + }
  74717. +}
  74718. +
  74719. +/**
  74720. + * Halts a host channel. If the channel cannot be halted immediately because
  74721. + * the request queue is full, this function ensures that the FIFO empty
  74722. + * interrupt for the appropriate queue is enabled so that the halt request can
  74723. + * be queued when there is space in the request queue.
  74724. + *
  74725. + * This function may also be called in DMA mode. In that case, the channel is
  74726. + * simply released since the core always halts the channel automatically in
  74727. + * DMA mode.
  74728. + */
  74729. +static void halt_channel(dwc_otg_hcd_t * hcd,
  74730. + dwc_hc_t * hc,
  74731. + dwc_otg_qtd_t * qtd, dwc_otg_halt_status_e halt_status)
  74732. +{
  74733. + if (hcd->core_if->dma_enable) {
  74734. + release_channel(hcd, hc, qtd, halt_status);
  74735. + return;
  74736. + }
  74737. +
  74738. + /* Slave mode processing... */
  74739. + dwc_otg_hc_halt(hcd->core_if, hc, halt_status);
  74740. +
  74741. + if (hc->halt_on_queue) {
  74742. + gintmsk_data_t gintmsk = {.d32 = 0 };
  74743. + dwc_otg_core_global_regs_t *global_regs;
  74744. + global_regs = hcd->core_if->core_global_regs;
  74745. +
  74746. + if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
  74747. + hc->ep_type == DWC_OTG_EP_TYPE_BULK) {
  74748. + /*
  74749. + * Make sure the Non-periodic Tx FIFO empty interrupt
  74750. + * is enabled so that the non-periodic schedule will
  74751. + * be processed.
  74752. + */
  74753. + gintmsk.b.nptxfempty = 1;
  74754. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmsk.d32);
  74755. + } else {
  74756. + /*
  74757. + * Move the QH from the periodic queued schedule to
  74758. + * the periodic assigned schedule. This allows the
  74759. + * halt to be queued when the periodic schedule is
  74760. + * processed.
  74761. + */
  74762. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_assigned,
  74763. + &hc->qh->qh_list_entry);
  74764. +
  74765. + /*
  74766. + * Make sure the Periodic Tx FIFO Empty interrupt is
  74767. + * enabled so that the periodic schedule will be
  74768. + * processed.
  74769. + */
  74770. + gintmsk.b.ptxfempty = 1;
  74771. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmsk.d32);
  74772. + }
  74773. + }
  74774. +}
  74775. +
  74776. +/**
  74777. + * Performs common cleanup for non-periodic transfers after a Transfer
  74778. + * Complete interrupt. This function should be called after any endpoint type
  74779. + * specific handling is finished to release the host channel.
  74780. + */
  74781. +static void complete_non_periodic_xfer(dwc_otg_hcd_t * hcd,
  74782. + dwc_hc_t * hc,
  74783. + dwc_otg_hc_regs_t * hc_regs,
  74784. + dwc_otg_qtd_t * qtd,
  74785. + dwc_otg_halt_status_e halt_status)
  74786. +{
  74787. + hcint_data_t hcint;
  74788. +
  74789. + qtd->error_count = 0;
  74790. +
  74791. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  74792. + if (hcint.b.nyet) {
  74793. + /*
  74794. + * Got a NYET on the last transaction of the transfer. This
  74795. + * means that the endpoint should be in the PING state at the
  74796. + * beginning of the next transfer.
  74797. + */
  74798. + hc->qh->ping_state = 1;
  74799. + clear_hc_int(hc_regs, nyet);
  74800. + }
  74801. +
  74802. + /*
  74803. + * Always halt and release the host channel to make it available for
  74804. + * more transfers. There may still be more phases for a control
  74805. + * transfer or more data packets for a bulk transfer at this point,
  74806. + * but the host channel is still halted. A channel will be reassigned
  74807. + * to the transfer when the non-periodic schedule is processed after
  74808. + * the channel is released. This allows transactions to be queued
  74809. + * properly via dwc_otg_hcd_queue_transactions, which also enables the
  74810. + * Tx FIFO Empty interrupt if necessary.
  74811. + */
  74812. + if (hc->ep_is_in) {
  74813. + /*
  74814. + * IN transfers in Slave mode require an explicit disable to
  74815. + * halt the channel. (In DMA mode, this call simply releases
  74816. + * the channel.)
  74817. + */
  74818. + halt_channel(hcd, hc, qtd, halt_status);
  74819. + } else {
  74820. + /*
  74821. + * The channel is automatically disabled by the core for OUT
  74822. + * transfers in Slave mode.
  74823. + */
  74824. + release_channel(hcd, hc, qtd, halt_status);
  74825. + }
  74826. +}
  74827. +
  74828. +/**
  74829. + * Performs common cleanup for periodic transfers after a Transfer Complete
  74830. + * interrupt. This function should be called after any endpoint type specific
  74831. + * handling is finished to release the host channel.
  74832. + */
  74833. +static void complete_periodic_xfer(dwc_otg_hcd_t * hcd,
  74834. + dwc_hc_t * hc,
  74835. + dwc_otg_hc_regs_t * hc_regs,
  74836. + dwc_otg_qtd_t * qtd,
  74837. + dwc_otg_halt_status_e halt_status)
  74838. +{
  74839. + hctsiz_data_t hctsiz;
  74840. + qtd->error_count = 0;
  74841. +
  74842. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  74843. + if (!hc->ep_is_in || hctsiz.b.pktcnt == 0) {
  74844. + /* Core halts channel in these cases. */
  74845. + release_channel(hcd, hc, qtd, halt_status);
  74846. + } else {
  74847. + /* Flush any outstanding requests from the Tx queue. */
  74848. + halt_channel(hcd, hc, qtd, halt_status);
  74849. + }
  74850. +}
  74851. +
  74852. +static int32_t handle_xfercomp_isoc_split_in(dwc_otg_hcd_t * hcd,
  74853. + dwc_hc_t * hc,
  74854. + dwc_otg_hc_regs_t * hc_regs,
  74855. + dwc_otg_qtd_t * qtd)
  74856. +{
  74857. + uint32_t len;
  74858. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  74859. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  74860. +
  74861. + len = get_actual_xfer_length(hc, hc_regs, qtd,
  74862. + DWC_OTG_HC_XFER_COMPLETE, NULL);
  74863. +
  74864. + if (!len) {
  74865. + qtd->complete_split = 0;
  74866. + qtd->isoc_split_offset = 0;
  74867. + return 0;
  74868. + }
  74869. + frame_desc->actual_length += len;
  74870. +
  74871. + if (hc->align_buff && len)
  74872. + dwc_memcpy(qtd->urb->buf + frame_desc->offset +
  74873. + qtd->isoc_split_offset, hc->qh->dw_align_buf, len);
  74874. + qtd->isoc_split_offset += len;
  74875. +
  74876. + if (frame_desc->length == frame_desc->actual_length) {
  74877. + frame_desc->status = 0;
  74878. + qtd->isoc_frame_index++;
  74879. + qtd->complete_split = 0;
  74880. + qtd->isoc_split_offset = 0;
  74881. + }
  74882. +
  74883. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  74884. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  74885. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  74886. + } else {
  74887. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  74888. + }
  74889. +
  74890. + return 1; /* Indicates that channel released */
  74891. +}
  74892. +
  74893. +/**
  74894. + * Handles a host channel Transfer Complete interrupt. This handler may be
  74895. + * called in either DMA mode or Slave mode.
  74896. + */
  74897. +static int32_t handle_hc_xfercomp_intr(dwc_otg_hcd_t * hcd,
  74898. + dwc_hc_t * hc,
  74899. + dwc_otg_hc_regs_t * hc_regs,
  74900. + dwc_otg_qtd_t * qtd)
  74901. +{
  74902. + int urb_xfer_done;
  74903. + dwc_otg_halt_status_e halt_status = DWC_OTG_HC_XFER_COMPLETE;
  74904. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  74905. + int pipe_type = dwc_otg_hcd_get_pipe_type(&urb->pipe_info);
  74906. +
  74907. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  74908. + "Transfer Complete--\n", hc->hc_num);
  74909. +
  74910. + if (hcd->core_if->dma_desc_enable) {
  74911. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs, halt_status);
  74912. + if (pipe_type == UE_ISOCHRONOUS) {
  74913. + /* Do not disable the interrupt, just clear it */
  74914. + clear_hc_int(hc_regs, xfercomp);
  74915. + return 1;
  74916. + }
  74917. + goto handle_xfercomp_done;
  74918. + }
  74919. +
  74920. + /*
  74921. + * Handle xfer complete on CSPLIT.
  74922. + */
  74923. +
  74924. + if (hc->qh->do_split) {
  74925. + if ((hc->ep_type == DWC_OTG_EP_TYPE_ISOC) && hc->ep_is_in
  74926. + && hcd->core_if->dma_enable) {
  74927. + if (qtd->complete_split
  74928. + && handle_xfercomp_isoc_split_in(hcd, hc, hc_regs,
  74929. + qtd))
  74930. + goto handle_xfercomp_done;
  74931. + } else {
  74932. + qtd->complete_split = 0;
  74933. + }
  74934. + }
  74935. +
  74936. + /* Update the QTD and URB states. */
  74937. + switch (pipe_type) {
  74938. + case UE_CONTROL:
  74939. + switch (qtd->control_phase) {
  74940. + case DWC_OTG_CONTROL_SETUP:
  74941. + if (urb->length > 0) {
  74942. + qtd->control_phase = DWC_OTG_CONTROL_DATA;
  74943. + } else {
  74944. + qtd->control_phase = DWC_OTG_CONTROL_STATUS;
  74945. + }
  74946. + DWC_DEBUGPL(DBG_HCDV,
  74947. + " Control setup transaction done\n");
  74948. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  74949. + break;
  74950. + case DWC_OTG_CONTROL_DATA:{
  74951. + urb_xfer_done =
  74952. + update_urb_state_xfer_comp(hc, hc_regs, urb,
  74953. + qtd);
  74954. + if (urb_xfer_done) {
  74955. + qtd->control_phase =
  74956. + DWC_OTG_CONTROL_STATUS;
  74957. + DWC_DEBUGPL(DBG_HCDV,
  74958. + " Control data transfer done\n");
  74959. + } else {
  74960. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  74961. + }
  74962. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  74963. + break;
  74964. + }
  74965. + case DWC_OTG_CONTROL_STATUS:
  74966. + DWC_DEBUGPL(DBG_HCDV, " Control transfer complete\n");
  74967. + if (urb->status == -DWC_E_IN_PROGRESS) {
  74968. + urb->status = 0;
  74969. + }
  74970. + hcd->fops->complete(hcd, urb->priv, urb, urb->status);
  74971. + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
  74972. + break;
  74973. + }
  74974. +
  74975. + complete_non_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  74976. + break;
  74977. + case UE_BULK:
  74978. + DWC_DEBUGPL(DBG_HCDV, " Bulk transfer complete\n");
  74979. + urb_xfer_done =
  74980. + update_urb_state_xfer_comp(hc, hc_regs, urb, qtd);
  74981. + if (urb_xfer_done) {
  74982. + hcd->fops->complete(hcd, urb->priv, urb, urb->status);
  74983. + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
  74984. + } else {
  74985. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  74986. + }
  74987. +
  74988. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  74989. + complete_non_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  74990. + break;
  74991. + case UE_INTERRUPT:
  74992. + DWC_DEBUGPL(DBG_HCDV, " Interrupt transfer complete\n");
  74993. + urb_xfer_done =
  74994. + update_urb_state_xfer_comp(hc, hc_regs, urb, qtd);
  74995. +
  74996. + /*
  74997. + * Interrupt URB is done on the first transfer complete
  74998. + * interrupt.
  74999. + */
  75000. + if (urb_xfer_done) {
  75001. + hcd->fops->complete(hcd, urb->priv, urb, urb->status);
  75002. + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
  75003. + } else {
  75004. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  75005. + }
  75006. +
  75007. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  75008. + complete_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  75009. + break;
  75010. + case UE_ISOCHRONOUS:
  75011. + DWC_DEBUGPL(DBG_HCDV, " Isochronous transfer complete\n");
  75012. + if (qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_ALL) {
  75013. + halt_status =
  75014. + update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  75015. + DWC_OTG_HC_XFER_COMPLETE);
  75016. + }
  75017. + complete_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  75018. + break;
  75019. + }
  75020. +
  75021. +handle_xfercomp_done:
  75022. + disable_hc_int(hc_regs, xfercompl);
  75023. +
  75024. + return 1;
  75025. +}
  75026. +
  75027. +/**
  75028. + * Handles a host channel STALL interrupt. This handler may be called in
  75029. + * either DMA mode or Slave mode.
  75030. + */
  75031. +static int32_t handle_hc_stall_intr(dwc_otg_hcd_t * hcd,
  75032. + dwc_hc_t * hc,
  75033. + dwc_otg_hc_regs_t * hc_regs,
  75034. + dwc_otg_qtd_t * qtd)
  75035. +{
  75036. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  75037. + int pipe_type = dwc_otg_hcd_get_pipe_type(&urb->pipe_info);
  75038. +
  75039. + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
  75040. + "STALL Received--\n", hc->hc_num);
  75041. +
  75042. + if (hcd->core_if->dma_desc_enable) {
  75043. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs, DWC_OTG_HC_XFER_STALL);
  75044. + goto handle_stall_done;
  75045. + }
  75046. +
  75047. + if (pipe_type == UE_CONTROL) {
  75048. + hcd->fops->complete(hcd, urb->priv, urb, -DWC_E_PIPE);
  75049. + }
  75050. +
  75051. + if (pipe_type == UE_BULK || pipe_type == UE_INTERRUPT) {
  75052. + hcd->fops->complete(hcd, urb->priv, urb, -DWC_E_PIPE);
  75053. + /*
  75054. + * USB protocol requires resetting the data toggle for bulk
  75055. + * and interrupt endpoints when a CLEAR_FEATURE(ENDPOINT_HALT)
  75056. + * setup command is issued to the endpoint. Anticipate the
  75057. + * CLEAR_FEATURE command since a STALL has occurred and reset
  75058. + * the data toggle now.
  75059. + */
  75060. + hc->qh->data_toggle = 0;
  75061. + }
  75062. +
  75063. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_STALL);
  75064. +
  75065. +handle_stall_done:
  75066. + disable_hc_int(hc_regs, stall);
  75067. +
  75068. + return 1;
  75069. +}
  75070. +
  75071. +/*
  75072. + * Updates the state of the URB when a transfer has been stopped due to an
  75073. + * abnormal condition before the transfer completes. Modifies the
  75074. + * actual_length field of the URB to reflect the number of bytes that have
  75075. + * actually been transferred via the host channel.
  75076. + */
  75077. +static void update_urb_state_xfer_intr(dwc_hc_t * hc,
  75078. + dwc_otg_hc_regs_t * hc_regs,
  75079. + dwc_otg_hcd_urb_t * urb,
  75080. + dwc_otg_qtd_t * qtd,
  75081. + dwc_otg_halt_status_e halt_status)
  75082. +{
  75083. + uint32_t bytes_transferred = get_actual_xfer_length(hc, hc_regs, qtd,
  75084. + halt_status, NULL);
  75085. + /* non DWORD-aligned buffer case handling. */
  75086. + if (hc->align_buff && bytes_transferred && hc->ep_is_in) {
  75087. + dwc_memcpy(urb->buf + urb->actual_length, hc->qh->dw_align_buf,
  75088. + bytes_transferred);
  75089. + }
  75090. +
  75091. + urb->actual_length += bytes_transferred;
  75092. +
  75093. +#ifdef DEBUG
  75094. + {
  75095. + hctsiz_data_t hctsiz;
  75096. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  75097. + DWC_DEBUGPL(DBG_HCDV, "DWC_otg: %s: %s, channel %d\n",
  75098. + __func__, (hc->ep_is_in ? "IN" : "OUT"),
  75099. + hc->hc_num);
  75100. + DWC_DEBUGPL(DBG_HCDV, " hc->start_pkt_count %d\n",
  75101. + hc->start_pkt_count);
  75102. + DWC_DEBUGPL(DBG_HCDV, " hctsiz.pktcnt %d\n", hctsiz.b.pktcnt);
  75103. + DWC_DEBUGPL(DBG_HCDV, " hc->max_packet %d\n", hc->max_packet);
  75104. + DWC_DEBUGPL(DBG_HCDV, " bytes_transferred %d\n",
  75105. + bytes_transferred);
  75106. + DWC_DEBUGPL(DBG_HCDV, " urb->actual_length %d\n",
  75107. + urb->actual_length);
  75108. + DWC_DEBUGPL(DBG_HCDV, " urb->transfer_buffer_length %d\n",
  75109. + urb->length);
  75110. + }
  75111. +#endif
  75112. +}
  75113. +
  75114. +/**
  75115. + * Handles a host channel NAK interrupt. This handler may be called in either
  75116. + * DMA mode or Slave mode.
  75117. + */
  75118. +static int32_t handle_hc_nak_intr(dwc_otg_hcd_t * hcd,
  75119. + dwc_hc_t * hc,
  75120. + dwc_otg_hc_regs_t * hc_regs,
  75121. + dwc_otg_qtd_t * qtd)
  75122. +{
  75123. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  75124. + "NAK Received--\n", hc->hc_num);
  75125. +
  75126. + /*
  75127. + * When we get bulk NAKs then remember this so we holdoff on this qh until
  75128. + * the beginning of the next frame
  75129. + */
  75130. + switch(dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  75131. + case UE_BULK:
  75132. + case UE_CONTROL:
  75133. + if (nak_holdoff_enable)
  75134. + hc->qh->nak_frame = dwc_otg_hcd_get_frame_number(hcd);
  75135. + }
  75136. +
  75137. + /*
  75138. + * Handle NAK for IN/OUT SSPLIT/CSPLIT transfers, bulk, control, and
  75139. + * interrupt. Re-start the SSPLIT transfer.
  75140. + */
  75141. + if (hc->do_split) {
  75142. + if (hc->complete_split) {
  75143. + qtd->error_count = 0;
  75144. + }
  75145. + qtd->complete_split = 0;
  75146. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
  75147. + goto handle_nak_done;
  75148. + }
  75149. +
  75150. + switch (dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  75151. + case UE_CONTROL:
  75152. + case UE_BULK:
  75153. + if (hcd->core_if->dma_enable && hc->ep_is_in) {
  75154. + /*
  75155. + * NAK interrupts are enabled on bulk/control IN
  75156. + * transfers in DMA mode for the sole purpose of
  75157. + * resetting the error count after a transaction error
  75158. + * occurs. The core will continue transferring data.
  75159. + * Disable other interrupts unmasked for the same
  75160. + * reason.
  75161. + */
  75162. + disable_hc_int(hc_regs, datatglerr);
  75163. + disable_hc_int(hc_regs, ack);
  75164. + qtd->error_count = 0;
  75165. + goto handle_nak_done;
  75166. + }
  75167. +
  75168. + /*
  75169. + * NAK interrupts normally occur during OUT transfers in DMA
  75170. + * or Slave mode. For IN transfers, more requests will be
  75171. + * queued as request queue space is available.
  75172. + */
  75173. + qtd->error_count = 0;
  75174. +
  75175. + if (!hc->qh->ping_state) {
  75176. + update_urb_state_xfer_intr(hc, hc_regs,
  75177. + qtd->urb, qtd,
  75178. + DWC_OTG_HC_XFER_NAK);
  75179. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  75180. +
  75181. + if (hc->speed == DWC_OTG_EP_SPEED_HIGH)
  75182. + hc->qh->ping_state = 1;
  75183. + }
  75184. +
  75185. + /*
  75186. + * Halt the channel so the transfer can be re-started from
  75187. + * the appropriate point or the PING protocol will
  75188. + * start/continue.
  75189. + */
  75190. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
  75191. + break;
  75192. + case UE_INTERRUPT:
  75193. + qtd->error_count = 0;
  75194. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
  75195. + break;
  75196. + case UE_ISOCHRONOUS:
  75197. + /* Should never get called for isochronous transfers. */
  75198. + DWC_ASSERT(1, "NACK interrupt for ISOC transfer\n");
  75199. + break;
  75200. + }
  75201. +
  75202. +handle_nak_done:
  75203. + disable_hc_int(hc_regs, nak);
  75204. +
  75205. + return 1;
  75206. +}
  75207. +
  75208. +/**
  75209. + * Handles a host channel ACK interrupt. This interrupt is enabled when
  75210. + * performing the PING protocol in Slave mode, when errors occur during
  75211. + * either Slave mode or DMA mode, and during Start Split transactions.
  75212. + */
  75213. +static int32_t handle_hc_ack_intr(dwc_otg_hcd_t * hcd,
  75214. + dwc_hc_t * hc,
  75215. + dwc_otg_hc_regs_t * hc_regs,
  75216. + dwc_otg_qtd_t * qtd)
  75217. +{
  75218. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  75219. + "ACK Received--\n", hc->hc_num);
  75220. +
  75221. + if (hc->do_split) {
  75222. + /*
  75223. + * Handle ACK on SSPLIT.
  75224. + * ACK should not occur in CSPLIT.
  75225. + */
  75226. + if (!hc->ep_is_in && hc->data_pid_start != DWC_OTG_HC_PID_SETUP) {
  75227. + qtd->ssplit_out_xfer_count = hc->xfer_len;
  75228. + }
  75229. + if (!(hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in)) {
  75230. + /* Don't need complete for isochronous out transfers. */
  75231. + qtd->complete_split = 1;
  75232. + }
  75233. +
  75234. + /* ISOC OUT */
  75235. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in) {
  75236. + switch (hc->xact_pos) {
  75237. + case DWC_HCSPLIT_XACTPOS_ALL:
  75238. + break;
  75239. + case DWC_HCSPLIT_XACTPOS_END:
  75240. + qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_ALL;
  75241. + qtd->isoc_split_offset = 0;
  75242. + break;
  75243. + case DWC_HCSPLIT_XACTPOS_BEGIN:
  75244. + case DWC_HCSPLIT_XACTPOS_MID:
  75245. + /*
  75246. + * For BEGIN or MID, calculate the length for
  75247. + * the next microframe to determine the correct
  75248. + * SSPLIT token, either MID or END.
  75249. + */
  75250. + {
  75251. + struct dwc_otg_hcd_iso_packet_desc
  75252. + *frame_desc;
  75253. +
  75254. + frame_desc =
  75255. + &qtd->urb->
  75256. + iso_descs[qtd->isoc_frame_index];
  75257. + qtd->isoc_split_offset += 188;
  75258. +
  75259. + if ((frame_desc->length -
  75260. + qtd->isoc_split_offset) <= 188) {
  75261. + qtd->isoc_split_pos =
  75262. + DWC_HCSPLIT_XACTPOS_END;
  75263. + } else {
  75264. + qtd->isoc_split_pos =
  75265. + DWC_HCSPLIT_XACTPOS_MID;
  75266. + }
  75267. +
  75268. + }
  75269. + break;
  75270. + }
  75271. + } else {
  75272. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_ACK);
  75273. + }
  75274. + } else {
  75275. + /*
  75276. + * An unmasked ACK on a non-split DMA transaction is
  75277. + * for the sole purpose of resetting error counts. Disable other
  75278. + * interrupts unmasked for the same reason.
  75279. + */
  75280. + if(hcd->core_if->dma_enable) {
  75281. + disable_hc_int(hc_regs, datatglerr);
  75282. + disable_hc_int(hc_regs, nak);
  75283. + }
  75284. + qtd->error_count = 0;
  75285. +
  75286. + if (hc->qh->ping_state) {
  75287. + hc->qh->ping_state = 0;
  75288. + /*
  75289. + * Halt the channel so the transfer can be re-started
  75290. + * from the appropriate point. This only happens in
  75291. + * Slave mode. In DMA mode, the ping_state is cleared
  75292. + * when the transfer is started because the core
  75293. + * automatically executes the PING, then the transfer.
  75294. + */
  75295. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_ACK);
  75296. + }
  75297. + }
  75298. +
  75299. + /*
  75300. + * If the ACK occurred when _not_ in the PING state, let the channel
  75301. + * continue transferring data after clearing the error count.
  75302. + */
  75303. +
  75304. + disable_hc_int(hc_regs, ack);
  75305. +
  75306. + return 1;
  75307. +}
  75308. +
  75309. +/**
  75310. + * Handles a host channel NYET interrupt. This interrupt should only occur on
  75311. + * Bulk and Control OUT endpoints and for complete split transactions. If a
  75312. + * NYET occurs at the same time as a Transfer Complete interrupt, it is
  75313. + * handled in the xfercomp interrupt handler, not here. This handler may be
  75314. + * called in either DMA mode or Slave mode.
  75315. + */
  75316. +static int32_t handle_hc_nyet_intr(dwc_otg_hcd_t * hcd,
  75317. + dwc_hc_t * hc,
  75318. + dwc_otg_hc_regs_t * hc_regs,
  75319. + dwc_otg_qtd_t * qtd)
  75320. +{
  75321. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  75322. + "NYET Received--\n", hc->hc_num);
  75323. +
  75324. + /*
  75325. + * NYET on CSPLIT
  75326. + * re-do the CSPLIT immediately on non-periodic
  75327. + */
  75328. + if (hc->do_split && hc->complete_split) {
  75329. + if (hc->ep_is_in && (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  75330. + && hcd->core_if->dma_enable) {
  75331. + qtd->complete_split = 0;
  75332. + qtd->isoc_split_offset = 0;
  75333. + if (++qtd->isoc_frame_index == qtd->urb->packet_count) {
  75334. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  75335. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  75336. + }
  75337. + else
  75338. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  75339. + goto handle_nyet_done;
  75340. + }
  75341. +
  75342. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  75343. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  75344. + int frnum = dwc_otg_hcd_get_frame_number(hcd);
  75345. +
  75346. + // With the FIQ running we only ever see the failed NYET
  75347. + if (dwc_full_frame_num(frnum) !=
  75348. + dwc_full_frame_num(hc->qh->sched_frame) ||
  75349. + fiq_split_enable) {
  75350. + /*
  75351. + * No longer in the same full speed frame.
  75352. + * Treat this as a transaction error.
  75353. + */
  75354. +#if 0
  75355. + /** @todo Fix system performance so this can
  75356. + * be treated as an error. Right now complete
  75357. + * splits cannot be scheduled precisely enough
  75358. + * due to other system activity, so this error
  75359. + * occurs regularly in Slave mode.
  75360. + */
  75361. + qtd->error_count++;
  75362. +#endif
  75363. + qtd->complete_split = 0;
  75364. + halt_channel(hcd, hc, qtd,
  75365. + DWC_OTG_HC_XFER_XACT_ERR);
  75366. + /** @todo add support for isoc release */
  75367. + goto handle_nyet_done;
  75368. + }
  75369. + }
  75370. +
  75371. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NYET);
  75372. + goto handle_nyet_done;
  75373. + }
  75374. +
  75375. + hc->qh->ping_state = 1;
  75376. + qtd->error_count = 0;
  75377. +
  75378. + update_urb_state_xfer_intr(hc, hc_regs, qtd->urb, qtd,
  75379. + DWC_OTG_HC_XFER_NYET);
  75380. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  75381. +
  75382. + /*
  75383. + * Halt the channel and re-start the transfer so the PING
  75384. + * protocol will start.
  75385. + */
  75386. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NYET);
  75387. +
  75388. +handle_nyet_done:
  75389. + disable_hc_int(hc_regs, nyet);
  75390. + return 1;
  75391. +}
  75392. +
  75393. +/**
  75394. + * Handles a host channel babble interrupt. This handler may be called in
  75395. + * either DMA mode or Slave mode.
  75396. + */
  75397. +static int32_t handle_hc_babble_intr(dwc_otg_hcd_t * hcd,
  75398. + dwc_hc_t * hc,
  75399. + dwc_otg_hc_regs_t * hc_regs,
  75400. + dwc_otg_qtd_t * qtd)
  75401. +{
  75402. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  75403. + "Babble Error--\n", hc->hc_num);
  75404. +
  75405. + if (hcd->core_if->dma_desc_enable) {
  75406. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  75407. + DWC_OTG_HC_XFER_BABBLE_ERR);
  75408. + goto handle_babble_done;
  75409. + }
  75410. +
  75411. + if (hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
  75412. + hcd->fops->complete(hcd, qtd->urb->priv,
  75413. + qtd->urb, -DWC_E_OVERFLOW);
  75414. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_BABBLE_ERR);
  75415. + } else {
  75416. + dwc_otg_halt_status_e halt_status;
  75417. + halt_status = update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  75418. + DWC_OTG_HC_XFER_BABBLE_ERR);
  75419. + halt_channel(hcd, hc, qtd, halt_status);
  75420. + }
  75421. +
  75422. +handle_babble_done:
  75423. + disable_hc_int(hc_regs, bblerr);
  75424. + return 1;
  75425. +}
  75426. +
  75427. +/**
  75428. + * Handles a host channel AHB error interrupt. This handler is only called in
  75429. + * DMA mode.
  75430. + */
  75431. +static int32_t handle_hc_ahberr_intr(dwc_otg_hcd_t * hcd,
  75432. + dwc_hc_t * hc,
  75433. + dwc_otg_hc_regs_t * hc_regs,
  75434. + dwc_otg_qtd_t * qtd)
  75435. +{
  75436. + hcchar_data_t hcchar;
  75437. + hcsplt_data_t hcsplt;
  75438. + hctsiz_data_t hctsiz;
  75439. + uint32_t hcdma;
  75440. + char *pipetype, *speed;
  75441. +
  75442. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  75443. +
  75444. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  75445. + "AHB Error--\n", hc->hc_num);
  75446. +
  75447. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  75448. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  75449. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  75450. + hcdma = DWC_READ_REG32(&hc_regs->hcdma);
  75451. +
  75452. + DWC_ERROR("AHB ERROR, Channel %d\n", hc->hc_num);
  75453. + DWC_ERROR(" hcchar 0x%08x, hcsplt 0x%08x\n", hcchar.d32, hcsplt.d32);
  75454. + DWC_ERROR(" hctsiz 0x%08x, hcdma 0x%08x\n", hctsiz.d32, hcdma);
  75455. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Enqueue\n");
  75456. + DWC_ERROR(" Device address: %d\n",
  75457. + dwc_otg_hcd_get_dev_addr(&urb->pipe_info));
  75458. + DWC_ERROR(" Endpoint: %d, %s\n",
  75459. + dwc_otg_hcd_get_ep_num(&urb->pipe_info),
  75460. + (dwc_otg_hcd_is_pipe_in(&urb->pipe_info) ? "IN" : "OUT"));
  75461. +
  75462. + switch (dwc_otg_hcd_get_pipe_type(&urb->pipe_info)) {
  75463. + case UE_CONTROL:
  75464. + pipetype = "CONTROL";
  75465. + break;
  75466. + case UE_BULK:
  75467. + pipetype = "BULK";
  75468. + break;
  75469. + case UE_INTERRUPT:
  75470. + pipetype = "INTERRUPT";
  75471. + break;
  75472. + case UE_ISOCHRONOUS:
  75473. + pipetype = "ISOCHRONOUS";
  75474. + break;
  75475. + default:
  75476. + pipetype = "UNKNOWN";
  75477. + break;
  75478. + }
  75479. +
  75480. + DWC_ERROR(" Endpoint type: %s\n", pipetype);
  75481. +
  75482. + switch (hc->speed) {
  75483. + case DWC_OTG_EP_SPEED_HIGH:
  75484. + speed = "HIGH";
  75485. + break;
  75486. + case DWC_OTG_EP_SPEED_FULL:
  75487. + speed = "FULL";
  75488. + break;
  75489. + case DWC_OTG_EP_SPEED_LOW:
  75490. + speed = "LOW";
  75491. + break;
  75492. + default:
  75493. + speed = "UNKNOWN";
  75494. + break;
  75495. + };
  75496. +
  75497. + DWC_ERROR(" Speed: %s\n", speed);
  75498. +
  75499. + DWC_ERROR(" Max packet size: %d\n",
  75500. + dwc_otg_hcd_get_mps(&urb->pipe_info));
  75501. + DWC_ERROR(" Data buffer length: %d\n", urb->length);
  75502. + DWC_ERROR(" Transfer buffer: %p, Transfer DMA: %p\n",
  75503. + urb->buf, (void *)urb->dma);
  75504. + DWC_ERROR(" Setup buffer: %p, Setup DMA: %p\n",
  75505. + urb->setup_packet, (void *)urb->setup_dma);
  75506. + DWC_ERROR(" Interval: %d\n", urb->interval);
  75507. +
  75508. + /* Core haltes the channel for Descriptor DMA mode */
  75509. + if (hcd->core_if->dma_desc_enable) {
  75510. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  75511. + DWC_OTG_HC_XFER_AHB_ERR);
  75512. + goto handle_ahberr_done;
  75513. + }
  75514. +
  75515. + hcd->fops->complete(hcd, urb->priv, urb, -DWC_E_IO);
  75516. +
  75517. + /*
  75518. + * Force a channel halt. Don't call halt_channel because that won't
  75519. + * write to the HCCHARn register in DMA mode to force the halt.
  75520. + */
  75521. + dwc_otg_hc_halt(hcd->core_if, hc, DWC_OTG_HC_XFER_AHB_ERR);
  75522. +handle_ahberr_done:
  75523. + disable_hc_int(hc_regs, ahberr);
  75524. + return 1;
  75525. +}
  75526. +
  75527. +/**
  75528. + * Handles a host channel transaction error interrupt. This handler may be
  75529. + * called in either DMA mode or Slave mode.
  75530. + */
  75531. +static int32_t handle_hc_xacterr_intr(dwc_otg_hcd_t * hcd,
  75532. + dwc_hc_t * hc,
  75533. + dwc_otg_hc_regs_t * hc_regs,
  75534. + dwc_otg_qtd_t * qtd)
  75535. +{
  75536. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  75537. + "Transaction Error--\n", hc->hc_num);
  75538. +
  75539. + if (hcd->core_if->dma_desc_enable) {
  75540. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  75541. + DWC_OTG_HC_XFER_XACT_ERR);
  75542. + goto handle_xacterr_done;
  75543. + }
  75544. +
  75545. + switch (dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  75546. + case UE_CONTROL:
  75547. + case UE_BULK:
  75548. + qtd->error_count++;
  75549. + if (!hc->qh->ping_state) {
  75550. +
  75551. + update_urb_state_xfer_intr(hc, hc_regs,
  75552. + qtd->urb, qtd,
  75553. + DWC_OTG_HC_XFER_XACT_ERR);
  75554. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  75555. + if (!hc->ep_is_in && hc->speed == DWC_OTG_EP_SPEED_HIGH) {
  75556. + hc->qh->ping_state = 1;
  75557. + }
  75558. + }
  75559. +
  75560. + /*
  75561. + * Halt the channel so the transfer can be re-started from
  75562. + * the appropriate point or the PING protocol will start.
  75563. + */
  75564. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  75565. + break;
  75566. + case UE_INTERRUPT:
  75567. + qtd->error_count++;
  75568. + if (hc->do_split && hc->complete_split) {
  75569. + qtd->complete_split = 0;
  75570. + }
  75571. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  75572. + break;
  75573. + case UE_ISOCHRONOUS:
  75574. + {
  75575. + dwc_otg_halt_status_e halt_status;
  75576. + halt_status =
  75577. + update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  75578. + DWC_OTG_HC_XFER_XACT_ERR);
  75579. +
  75580. + halt_channel(hcd, hc, qtd, halt_status);
  75581. + }
  75582. + break;
  75583. + }
  75584. +handle_xacterr_done:
  75585. + disable_hc_int(hc_regs, xacterr);
  75586. +
  75587. + return 1;
  75588. +}
  75589. +
  75590. +/**
  75591. + * Handles a host channel frame overrun interrupt. This handler may be called
  75592. + * in either DMA mode or Slave mode.
  75593. + */
  75594. +static int32_t handle_hc_frmovrun_intr(dwc_otg_hcd_t * hcd,
  75595. + dwc_hc_t * hc,
  75596. + dwc_otg_hc_regs_t * hc_regs,
  75597. + dwc_otg_qtd_t * qtd)
  75598. +{
  75599. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  75600. + "Frame Overrun--\n", hc->hc_num);
  75601. +
  75602. + switch (dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  75603. + case UE_CONTROL:
  75604. + case UE_BULK:
  75605. + break;
  75606. + case UE_INTERRUPT:
  75607. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_FRAME_OVERRUN);
  75608. + break;
  75609. + case UE_ISOCHRONOUS:
  75610. + {
  75611. + dwc_otg_halt_status_e halt_status;
  75612. + halt_status =
  75613. + update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  75614. + DWC_OTG_HC_XFER_FRAME_OVERRUN);
  75615. +
  75616. + halt_channel(hcd, hc, qtd, halt_status);
  75617. + }
  75618. + break;
  75619. + }
  75620. +
  75621. + disable_hc_int(hc_regs, frmovrun);
  75622. +
  75623. + return 1;
  75624. +}
  75625. +
  75626. +/**
  75627. + * Handles a host channel data toggle error interrupt. This handler may be
  75628. + * called in either DMA mode or Slave mode.
  75629. + */
  75630. +static int32_t handle_hc_datatglerr_intr(dwc_otg_hcd_t * hcd,
  75631. + dwc_hc_t * hc,
  75632. + dwc_otg_hc_regs_t * hc_regs,
  75633. + dwc_otg_qtd_t * qtd)
  75634. +{
  75635. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  75636. + "Data Toggle Error on %s transfer--\n",
  75637. + hc->hc_num, (hc->ep_is_in ? "IN" : "OUT"));
  75638. +
  75639. + /* Data toggles on split transactions cause the hc to halt.
  75640. + * restart transfer */
  75641. + if(hc->qh->do_split)
  75642. + {
  75643. + qtd->error_count++;
  75644. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  75645. + update_urb_state_xfer_intr(hc, hc_regs,
  75646. + qtd->urb, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  75647. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  75648. + } else if (hc->ep_is_in) {
  75649. + /* An unmasked data toggle error on a non-split DMA transaction is
  75650. + * for the sole purpose of resetting error counts. Disable other
  75651. + * interrupts unmasked for the same reason.
  75652. + */
  75653. + if(hcd->core_if->dma_enable) {
  75654. + disable_hc_int(hc_regs, ack);
  75655. + disable_hc_int(hc_regs, nak);
  75656. + }
  75657. + qtd->error_count = 0;
  75658. + }
  75659. +
  75660. + disable_hc_int(hc_regs, datatglerr);
  75661. +
  75662. + return 1;
  75663. +}
  75664. +
  75665. +#ifdef DEBUG
  75666. +/**
  75667. + * This function is for debug only. It checks that a valid halt status is set
  75668. + * and that HCCHARn.chdis is clear. If there's a problem, corrective action is
  75669. + * taken and a warning is issued.
  75670. + * @return 1 if halt status is ok, 0 otherwise.
  75671. + */
  75672. +static inline int halt_status_ok(dwc_otg_hcd_t * hcd,
  75673. + dwc_hc_t * hc,
  75674. + dwc_otg_hc_regs_t * hc_regs,
  75675. + dwc_otg_qtd_t * qtd)
  75676. +{
  75677. + hcchar_data_t hcchar;
  75678. + hctsiz_data_t hctsiz;
  75679. + hcint_data_t hcint;
  75680. + hcintmsk_data_t hcintmsk;
  75681. + hcsplt_data_t hcsplt;
  75682. +
  75683. + if (hc->halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS) {
  75684. + /*
  75685. + * This code is here only as a check. This condition should
  75686. + * never happen. Ignore the halt if it does occur.
  75687. + */
  75688. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  75689. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  75690. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  75691. + hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
  75692. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  75693. + DWC_WARN
  75694. + ("%s: hc->halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS, "
  75695. + "channel %d, hcchar 0x%08x, hctsiz 0x%08x, "
  75696. + "hcint 0x%08x, hcintmsk 0x%08x, "
  75697. + "hcsplt 0x%08x, qtd->complete_split %d\n", __func__,
  75698. + hc->hc_num, hcchar.d32, hctsiz.d32, hcint.d32,
  75699. + hcintmsk.d32, hcsplt.d32, qtd->complete_split);
  75700. +
  75701. + DWC_WARN("%s: no halt status, channel %d, ignoring interrupt\n",
  75702. + __func__, hc->hc_num);
  75703. + DWC_WARN("\n");
  75704. + clear_hc_int(hc_regs, chhltd);
  75705. + return 0;
  75706. + }
  75707. +
  75708. + /*
  75709. + * This code is here only as a check. hcchar.chdis should
  75710. + * never be set when the halt interrupt occurs. Halt the
  75711. + * channel again if it does occur.
  75712. + */
  75713. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  75714. + if (hcchar.b.chdis) {
  75715. + DWC_WARN("%s: hcchar.chdis set unexpectedly, "
  75716. + "hcchar 0x%08x, trying to halt again\n",
  75717. + __func__, hcchar.d32);
  75718. + clear_hc_int(hc_regs, chhltd);
  75719. + hc->halt_pending = 0;
  75720. + halt_channel(hcd, hc, qtd, hc->halt_status);
  75721. + return 0;
  75722. + }
  75723. +
  75724. + return 1;
  75725. +}
  75726. +#endif
  75727. +
  75728. +/**
  75729. + * Handles a host Channel Halted interrupt in DMA mode. This handler
  75730. + * determines the reason the channel halted and proceeds accordingly.
  75731. + */
  75732. +static void handle_hc_chhltd_intr_dma(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. + hcint_data_t hcint,
  75737. + hcintmsk_data_t hcintmsk)
  75738. +{
  75739. + int out_nak_enh = 0;
  75740. +
  75741. + /* For core with OUT NAK enhancement, the flow for high-
  75742. + * speed CONTROL/BULK OUT is handled a little differently.
  75743. + */
  75744. + if (hcd->core_if->snpsid >= OTG_CORE_REV_2_71a) {
  75745. + if (hc->speed == DWC_OTG_EP_SPEED_HIGH && !hc->ep_is_in &&
  75746. + (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
  75747. + hc->ep_type == DWC_OTG_EP_TYPE_BULK)) {
  75748. + out_nak_enh = 1;
  75749. + }
  75750. + }
  75751. +
  75752. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE ||
  75753. + (hc->halt_status == DWC_OTG_HC_XFER_AHB_ERR
  75754. + && !hcd->core_if->dma_desc_enable)) {
  75755. + /*
  75756. + * Just release the channel. A dequeue can happen on a
  75757. + * transfer timeout. In the case of an AHB Error, the channel
  75758. + * was forced to halt because there's no way to gracefully
  75759. + * recover.
  75760. + */
  75761. + if (hcd->core_if->dma_desc_enable)
  75762. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  75763. + hc->halt_status);
  75764. + else
  75765. + release_channel(hcd, hc, qtd, hc->halt_status);
  75766. + return;
  75767. + }
  75768. +
  75769. + /* Read the HCINTn register to determine the cause for the halt. */
  75770. + if(!fiq_split_enable)
  75771. + {
  75772. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  75773. + hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
  75774. + }
  75775. +
  75776. + if (hcint.b.xfercomp) {
  75777. + /** @todo This is here because of a possible hardware bug. Spec
  75778. + * says that on SPLIT-ISOC OUT transfers in DMA mode that a HALT
  75779. + * interrupt w/ACK bit set should occur, but I only see the
  75780. + * XFERCOMP bit, even with it masked out. This is a workaround
  75781. + * for that behavior. Should fix this when hardware is fixed.
  75782. + */
  75783. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in) {
  75784. + handle_hc_ack_intr(hcd, hc, hc_regs, qtd);
  75785. + }
  75786. + handle_hc_xfercomp_intr(hcd, hc, hc_regs, qtd);
  75787. + } else if (hcint.b.stall) {
  75788. + handle_hc_stall_intr(hcd, hc, hc_regs, qtd);
  75789. + } else if (hcint.b.xacterr && !hcd->core_if->dma_desc_enable) {
  75790. + if (out_nak_enh) {
  75791. + if (hcint.b.nyet || hcint.b.nak || hcint.b.ack) {
  75792. + DWC_DEBUGPL(DBG_HCD, "XactErr with NYET/NAK/ACK\n");
  75793. + qtd->error_count = 0;
  75794. + } else {
  75795. + DWC_DEBUGPL(DBG_HCD, "XactErr without NYET/NAK/ACK\n");
  75796. + }
  75797. + }
  75798. +
  75799. + /*
  75800. + * Must handle xacterr before nak or ack. Could get a xacterr
  75801. + * at the same time as either of these on a BULK/CONTROL OUT
  75802. + * that started with a PING. The xacterr takes precedence.
  75803. + */
  75804. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  75805. + } else if (hcint.b.xcs_xact && hcd->core_if->dma_desc_enable) {
  75806. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  75807. + } else if (hcint.b.ahberr && hcd->core_if->dma_desc_enable) {
  75808. + handle_hc_ahberr_intr(hcd, hc, hc_regs, qtd);
  75809. + } else if (hcint.b.bblerr) {
  75810. + handle_hc_babble_intr(hcd, hc, hc_regs, qtd);
  75811. + } else if (hcint.b.frmovrun) {
  75812. + handle_hc_frmovrun_intr(hcd, hc, hc_regs, qtd);
  75813. + } else if (hcint.b.datatglerr) {
  75814. + handle_hc_datatglerr_intr(hcd, hc, hc_regs, qtd);
  75815. + } else if (!out_nak_enh) {
  75816. + if (hcint.b.nyet) {
  75817. + /*
  75818. + * Must handle nyet before nak or ack. Could get a nyet at the
  75819. + * same time as either of those on a BULK/CONTROL OUT that
  75820. + * started with a PING. The nyet takes precedence.
  75821. + */
  75822. + handle_hc_nyet_intr(hcd, hc, hc_regs, qtd);
  75823. + } else if (hcint.b.nak && !hcintmsk.b.nak) {
  75824. + /*
  75825. + * If nak is not masked, it's because a non-split IN transfer
  75826. + * is in an error state. In that case, the nak is handled by
  75827. + * the nak interrupt handler, not here. Handle nak here for
  75828. + * BULK/CONTROL OUT transfers, which halt on a NAK to allow
  75829. + * rewinding the buffer pointer.
  75830. + */
  75831. + handle_hc_nak_intr(hcd, hc, hc_regs, qtd);
  75832. + } else if (hcint.b.ack && !hcintmsk.b.ack) {
  75833. + /*
  75834. + * If ack is not masked, it's because a non-split IN transfer
  75835. + * is in an error state. In that case, the ack is handled by
  75836. + * the ack interrupt handler, not here. Handle ack here for
  75837. + * split transfers. Start splits halt on ACK.
  75838. + */
  75839. + handle_hc_ack_intr(hcd, hc, hc_regs, qtd);
  75840. + } else {
  75841. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  75842. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  75843. + /*
  75844. + * A periodic transfer halted with no other channel
  75845. + * interrupts set. Assume it was halted by the core
  75846. + * because it could not be completed in its scheduled
  75847. + * (micro)frame.
  75848. + */
  75849. +#ifdef DEBUG
  75850. + DWC_PRINTF
  75851. + ("%s: Halt channel %d (assume incomplete periodic transfer)\n",
  75852. + __func__, hc->hc_num);
  75853. +#endif
  75854. + halt_channel(hcd, hc, qtd,
  75855. + DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE);
  75856. + } else {
  75857. + DWC_ERROR
  75858. + ("%s: Channel %d, DMA Mode -- ChHltd set, but reason "
  75859. + "for halting is unknown, hcint 0x%08x, intsts 0x%08x\n",
  75860. + __func__, hc->hc_num, hcint.d32,
  75861. + DWC_READ_REG32(&hcd->
  75862. + core_if->core_global_regs->
  75863. + gintsts));
  75864. + /* Failthrough: use 3-strikes rule */
  75865. + qtd->error_count++;
  75866. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  75867. + update_urb_state_xfer_intr(hc, hc_regs,
  75868. + qtd->urb, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  75869. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  75870. + }
  75871. +
  75872. + }
  75873. + } else {
  75874. + DWC_PRINTF("NYET/NAK/ACK/other in non-error case, 0x%08x\n",
  75875. + hcint.d32);
  75876. + /* Failthrough: use 3-strikes rule */
  75877. + qtd->error_count++;
  75878. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  75879. + update_urb_state_xfer_intr(hc, hc_regs,
  75880. + qtd->urb, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  75881. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  75882. + }
  75883. +}
  75884. +
  75885. +/**
  75886. + * Handles a host channel Channel Halted interrupt.
  75887. + *
  75888. + * In slave mode, this handler is called only when the driver specifically
  75889. + * requests a halt. This occurs during handling other host channel interrupts
  75890. + * (e.g. nak, xacterr, stall, nyet, etc.).
  75891. + *
  75892. + * In DMA mode, this is the interrupt that occurs when the core has finished
  75893. + * processing a transfer on a channel. Other host channel interrupts (except
  75894. + * ahberr) are disabled in DMA mode.
  75895. + */
  75896. +static int32_t handle_hc_chhltd_intr(dwc_otg_hcd_t * hcd,
  75897. + dwc_hc_t * hc,
  75898. + dwc_otg_hc_regs_t * hc_regs,
  75899. + dwc_otg_qtd_t * qtd,
  75900. + hcint_data_t hcint,
  75901. + hcintmsk_data_t hcintmsk)
  75902. +{
  75903. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  75904. + "Channel Halted--\n", hc->hc_num);
  75905. +
  75906. + if (hcd->core_if->dma_enable) {
  75907. + handle_hc_chhltd_intr_dma(hcd, hc, hc_regs, qtd, hcint, hcintmsk);
  75908. + } else {
  75909. +#ifdef DEBUG
  75910. + if (!halt_status_ok(hcd, hc, hc_regs, qtd)) {
  75911. + return 1;
  75912. + }
  75913. +#endif
  75914. + release_channel(hcd, hc, qtd, hc->halt_status);
  75915. + }
  75916. +
  75917. + return 1;
  75918. +}
  75919. +
  75920. +/** Handles interrupt for a specific Host Channel */
  75921. +int32_t dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd_t * dwc_otg_hcd, uint32_t num)
  75922. +{
  75923. + int retval = 0;
  75924. + hcint_data_t hcint, hcint_orig;
  75925. + hcintmsk_data_t hcintmsk;
  75926. + dwc_hc_t *hc;
  75927. + dwc_otg_hc_regs_t *hc_regs;
  75928. + dwc_otg_qtd_t *qtd;
  75929. +
  75930. + DWC_DEBUGPL(DBG_HCDV, "--Host Channel Interrupt--, Channel %d\n", num);
  75931. +
  75932. + hc = dwc_otg_hcd->hc_ptr_array[num];
  75933. + hc_regs = dwc_otg_hcd->core_if->host_if->hc_regs[num];
  75934. + if(hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  75935. + /* We are responding to a channel disable. Driver
  75936. + * state is cleared - our qtd has gone away.
  75937. + */
  75938. + release_channel(dwc_otg_hcd, hc, NULL, hc->halt_status);
  75939. + return 1;
  75940. + }
  75941. + qtd = DWC_CIRCLEQ_FIRST(&hc->qh->qtd_list);
  75942. +
  75943. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  75944. + hcint_orig = hcint;
  75945. + hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
  75946. + DWC_DEBUGPL(DBG_HCDV,
  75947. + " hcint 0x%08x, hcintmsk 0x%08x, hcint&hcintmsk 0x%08x\n",
  75948. + hcint.d32, hcintmsk.d32, (hcint.d32 & hcintmsk.d32));
  75949. + hcint.d32 = hcint.d32 & hcintmsk.d32;
  75950. +
  75951. + if(fiq_split_enable)
  75952. + {
  75953. + // replace with the saved interrupts from the fiq handler
  75954. + local_fiq_disable();
  75955. + hcint_orig.d32 = hcint_saved[num].d32;
  75956. + hcint.d32 = hcint_orig.d32 & hcintmsk_saved[num].d32;
  75957. + hcint_saved[num].d32 = 0;
  75958. + local_fiq_enable();
  75959. + }
  75960. +
  75961. + if (!dwc_otg_hcd->core_if->dma_enable) {
  75962. + if (hcint.b.chhltd && hcint.d32 != 0x2) {
  75963. + hcint.b.chhltd = 0;
  75964. + }
  75965. + }
  75966. +
  75967. + if (hcint.b.xfercomp) {
  75968. + retval |=
  75969. + handle_hc_xfercomp_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  75970. + /*
  75971. + * If NYET occurred at same time as Xfer Complete, the NYET is
  75972. + * handled by the Xfer Complete interrupt handler. Don't want
  75973. + * to call the NYET interrupt handler in this case.
  75974. + */
  75975. + hcint.b.nyet = 0;
  75976. + }
  75977. + if (hcint.b.chhltd) {
  75978. + retval |= handle_hc_chhltd_intr(dwc_otg_hcd, hc, hc_regs, qtd, hcint_orig, hcintmsk_saved[num]);
  75979. + }
  75980. + if (hcint.b.ahberr) {
  75981. + retval |= handle_hc_ahberr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  75982. + }
  75983. + if (hcint.b.stall) {
  75984. + retval |= handle_hc_stall_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  75985. + }
  75986. + if (hcint.b.nak) {
  75987. + retval |= handle_hc_nak_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  75988. + }
  75989. + if (hcint.b.ack) {
  75990. + if(!hcint.b.chhltd)
  75991. + retval |= handle_hc_ack_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  75992. + }
  75993. + if (hcint.b.nyet) {
  75994. + retval |= handle_hc_nyet_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  75995. + }
  75996. + if (hcint.b.xacterr) {
  75997. + retval |= handle_hc_xacterr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  75998. + }
  75999. + if (hcint.b.bblerr) {
  76000. + retval |= handle_hc_babble_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  76001. + }
  76002. + if (hcint.b.frmovrun) {
  76003. + retval |=
  76004. + handle_hc_frmovrun_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  76005. + }
  76006. + if (hcint.b.datatglerr) {
  76007. + retval |=
  76008. + handle_hc_datatglerr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  76009. + }
  76010. +
  76011. + return retval;
  76012. +}
  76013. +#endif /* DWC_DEVICE_ONLY */
  76014. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c
  76015. --- linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c 1970-01-01 01:00:00.000000000 +0100
  76016. +++ linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c 2014-02-17 22:41:01.000000000 +0100
  76017. @@ -0,0 +1,972 @@
  76018. +
  76019. +/* ==========================================================================
  76020. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_linux.c $
  76021. + * $Revision: #20 $
  76022. + * $Date: 2011/10/26 $
  76023. + * $Change: 1872981 $
  76024. + *
  76025. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  76026. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  76027. + * otherwise expressly agreed to in writing between Synopsys and you.
  76028. + *
  76029. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  76030. + * any End User Software License Agreement or Agreement for Licensed Product
  76031. + * with Synopsys or any supplement thereto. You are permitted to use and
  76032. + * redistribute this Software in source and binary forms, with or without
  76033. + * modification, provided that redistributions of source code must retain this
  76034. + * notice. You may not view, use, disclose, copy or distribute this file or
  76035. + * any information contained herein except pursuant to this license grant from
  76036. + * Synopsys. If you do not agree with this notice, including the disclaimer
  76037. + * below, then you are not authorized to use the Software.
  76038. + *
  76039. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  76040. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  76041. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  76042. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  76043. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  76044. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  76045. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  76046. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  76047. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  76048. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  76049. + * DAMAGE.
  76050. + * ========================================================================== */
  76051. +#ifndef DWC_DEVICE_ONLY
  76052. +
  76053. +/**
  76054. + * @file
  76055. + *
  76056. + * This file contains the implementation of the HCD. In Linux, the HCD
  76057. + * implements the hc_driver API.
  76058. + */
  76059. +#include <linux/kernel.h>
  76060. +#include <linux/module.h>
  76061. +#include <linux/moduleparam.h>
  76062. +#include <linux/init.h>
  76063. +#include <linux/device.h>
  76064. +#include <linux/errno.h>
  76065. +#include <linux/list.h>
  76066. +#include <linux/interrupt.h>
  76067. +#include <linux/string.h>
  76068. +#include <linux/dma-mapping.h>
  76069. +#include <linux/version.h>
  76070. +#include <asm/io.h>
  76071. +#include <asm/fiq.h>
  76072. +#include <linux/usb.h>
  76073. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35)
  76074. +#include <../drivers/usb/core/hcd.h>
  76075. +#else
  76076. +#include <linux/usb/hcd.h>
  76077. +#endif
  76078. +
  76079. +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30))
  76080. +#define USB_URB_EP_LINKING 1
  76081. +#else
  76082. +#define USB_URB_EP_LINKING 0
  76083. +#endif
  76084. +
  76085. +#include "dwc_otg_hcd_if.h"
  76086. +#include "dwc_otg_dbg.h"
  76087. +#include "dwc_otg_driver.h"
  76088. +#include "dwc_otg_hcd.h"
  76089. +#include "dwc_otg_mphi_fix.h"
  76090. +
  76091. +/**
  76092. + * Gets the endpoint number from a _bEndpointAddress argument. The endpoint is
  76093. + * qualified with its direction (possible 32 endpoints per device).
  76094. + */
  76095. +#define dwc_ep_addr_to_endpoint(_bEndpointAddress_) ((_bEndpointAddress_ & USB_ENDPOINT_NUMBER_MASK) | \
  76096. + ((_bEndpointAddress_ & USB_DIR_IN) != 0) << 4)
  76097. +
  76098. +static const char dwc_otg_hcd_name[] = "dwc_otg_hcd";
  76099. +
  76100. +extern bool fiq_fix_enable;
  76101. +
  76102. +/** @name Linux HC Driver API Functions */
  76103. +/** @{ */
  76104. +/* manage i/o requests, device state */
  76105. +static int dwc_otg_urb_enqueue(struct usb_hcd *hcd,
  76106. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  76107. + struct usb_host_endpoint *ep,
  76108. +#endif
  76109. + struct urb *urb, gfp_t mem_flags);
  76110. +
  76111. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
  76112. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  76113. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd, struct urb *urb);
  76114. +#endif
  76115. +#else /* kernels at or post 2.6.30 */
  76116. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd,
  76117. + struct urb *urb, int status);
  76118. +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30) */
  76119. +
  76120. +static void endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *ep);
  76121. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  76122. +static void endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep);
  76123. +#endif
  76124. +static irqreturn_t dwc_otg_hcd_irq(struct usb_hcd *hcd);
  76125. +extern int hcd_start(struct usb_hcd *hcd);
  76126. +extern void hcd_stop(struct usb_hcd *hcd);
  76127. +static int get_frame_number(struct usb_hcd *hcd);
  76128. +extern int hub_status_data(struct usb_hcd *hcd, char *buf);
  76129. +extern int hub_control(struct usb_hcd *hcd,
  76130. + u16 typeReq,
  76131. + u16 wValue, u16 wIndex, char *buf, u16 wLength);
  76132. +
  76133. +struct wrapper_priv_data {
  76134. + dwc_otg_hcd_t *dwc_otg_hcd;
  76135. +};
  76136. +
  76137. +/** @} */
  76138. +
  76139. +static struct hc_driver dwc_otg_hc_driver = {
  76140. +
  76141. + .description = dwc_otg_hcd_name,
  76142. + .product_desc = "DWC OTG Controller",
  76143. + .hcd_priv_size = sizeof(struct wrapper_priv_data),
  76144. +
  76145. + .irq = dwc_otg_hcd_irq,
  76146. +
  76147. + .flags = HCD_MEMORY | HCD_USB2,
  76148. +
  76149. + //.reset =
  76150. + .start = hcd_start,
  76151. + //.suspend =
  76152. + //.resume =
  76153. + .stop = hcd_stop,
  76154. +
  76155. + .urb_enqueue = dwc_otg_urb_enqueue,
  76156. + .urb_dequeue = dwc_otg_urb_dequeue,
  76157. + .endpoint_disable = endpoint_disable,
  76158. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  76159. + .endpoint_reset = endpoint_reset,
  76160. +#endif
  76161. + .get_frame_number = get_frame_number,
  76162. +
  76163. + .hub_status_data = hub_status_data,
  76164. + .hub_control = hub_control,
  76165. + //.bus_suspend =
  76166. + //.bus_resume =
  76167. +};
  76168. +
  76169. +/** Gets the dwc_otg_hcd from a struct usb_hcd */
  76170. +static inline dwc_otg_hcd_t *hcd_to_dwc_otg_hcd(struct usb_hcd *hcd)
  76171. +{
  76172. + struct wrapper_priv_data *p;
  76173. + p = (struct wrapper_priv_data *)(hcd->hcd_priv);
  76174. + return p->dwc_otg_hcd;
  76175. +}
  76176. +
  76177. +/** Gets the struct usb_hcd that contains a dwc_otg_hcd_t. */
  76178. +static inline struct usb_hcd *dwc_otg_hcd_to_hcd(dwc_otg_hcd_t * dwc_otg_hcd)
  76179. +{
  76180. + return dwc_otg_hcd_get_priv_data(dwc_otg_hcd);
  76181. +}
  76182. +
  76183. +/** Gets the usb_host_endpoint associated with an URB. */
  76184. +inline struct usb_host_endpoint *dwc_urb_to_endpoint(struct urb *urb)
  76185. +{
  76186. + struct usb_device *dev = urb->dev;
  76187. + int ep_num = usb_pipeendpoint(urb->pipe);
  76188. +
  76189. + if (usb_pipein(urb->pipe))
  76190. + return dev->ep_in[ep_num];
  76191. + else
  76192. + return dev->ep_out[ep_num];
  76193. +}
  76194. +
  76195. +static int _disconnect(dwc_otg_hcd_t * hcd)
  76196. +{
  76197. + struct usb_hcd *usb_hcd = dwc_otg_hcd_to_hcd(hcd);
  76198. +
  76199. + usb_hcd->self.is_b_host = 0;
  76200. + return 0;
  76201. +}
  76202. +
  76203. +static int _start(dwc_otg_hcd_t * hcd)
  76204. +{
  76205. + struct usb_hcd *usb_hcd = dwc_otg_hcd_to_hcd(hcd);
  76206. +
  76207. + usb_hcd->self.is_b_host = dwc_otg_hcd_is_b_host(hcd);
  76208. + hcd_start(usb_hcd);
  76209. +
  76210. + return 0;
  76211. +}
  76212. +
  76213. +static int _hub_info(dwc_otg_hcd_t * hcd, void *urb_handle, uint32_t * hub_addr,
  76214. + uint32_t * port_addr)
  76215. +{
  76216. + struct urb *urb = (struct urb *)urb_handle;
  76217. + struct usb_bus *bus;
  76218. +#if 1 //GRAYG - temporary
  76219. + if (NULL == urb_handle)
  76220. + DWC_ERROR("**** %s - NULL URB handle\n", __func__);//GRAYG
  76221. + if (NULL == urb->dev)
  76222. + DWC_ERROR("**** %s - URB has no device\n", __func__);//GRAYG
  76223. + if (NULL == port_addr)
  76224. + DWC_ERROR("**** %s - NULL port_address\n", __func__);//GRAYG
  76225. +#endif
  76226. + if (urb->dev->tt) {
  76227. + if (NULL == urb->dev->tt->hub) {
  76228. + DWC_ERROR("**** %s - (URB's transactor has no TT - giving no hub)\n",
  76229. + __func__); //GRAYG
  76230. + //*hub_addr = (u8)usb_pipedevice(urb->pipe); //GRAYG
  76231. + *hub_addr = 0; //GRAYG
  76232. + // we probably shouldn't have a transaction translator if
  76233. + // there's no associated hub?
  76234. + } else {
  76235. + bus = hcd_to_bus(dwc_otg_hcd_to_hcd(hcd));
  76236. + if (urb->dev->tt->hub == bus->root_hub)
  76237. + *hub_addr = 0;
  76238. + else
  76239. + *hub_addr = urb->dev->tt->hub->devnum;
  76240. + }
  76241. + *port_addr = urb->dev->tt->multi ? urb->dev->ttport : 1;
  76242. + } else {
  76243. + *hub_addr = 0;
  76244. + *port_addr = urb->dev->ttport;
  76245. + }
  76246. + return 0;
  76247. +}
  76248. +
  76249. +static int _speed(dwc_otg_hcd_t * hcd, void *urb_handle)
  76250. +{
  76251. + struct urb *urb = (struct urb *)urb_handle;
  76252. + return urb->dev->speed;
  76253. +}
  76254. +
  76255. +static int _get_b_hnp_enable(dwc_otg_hcd_t * hcd)
  76256. +{
  76257. + struct usb_hcd *usb_hcd = dwc_otg_hcd_to_hcd(hcd);
  76258. + return usb_hcd->self.b_hnp_enable;
  76259. +}
  76260. +
  76261. +static void allocate_bus_bandwidth(struct usb_hcd *hcd, uint32_t bw,
  76262. + struct urb *urb)
  76263. +{
  76264. + hcd_to_bus(hcd)->bandwidth_allocated += bw / urb->interval;
  76265. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  76266. + hcd_to_bus(hcd)->bandwidth_isoc_reqs++;
  76267. + } else {
  76268. + hcd_to_bus(hcd)->bandwidth_int_reqs++;
  76269. + }
  76270. +}
  76271. +
  76272. +static void free_bus_bandwidth(struct usb_hcd *hcd, uint32_t bw,
  76273. + struct urb *urb)
  76274. +{
  76275. + hcd_to_bus(hcd)->bandwidth_allocated -= bw / urb->interval;
  76276. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  76277. + hcd_to_bus(hcd)->bandwidth_isoc_reqs--;
  76278. + } else {
  76279. + hcd_to_bus(hcd)->bandwidth_int_reqs--;
  76280. + }
  76281. +}
  76282. +
  76283. +/**
  76284. + * Sets the final status of an URB and returns it to the device driver. Any
  76285. + * required cleanup of the URB is performed. The HCD lock should be held on
  76286. + * entry.
  76287. + */
  76288. +static int _complete(dwc_otg_hcd_t * hcd, void *urb_handle,
  76289. + dwc_otg_hcd_urb_t * dwc_otg_urb, int32_t status)
  76290. +{
  76291. + struct urb *urb = (struct urb *)urb_handle;
  76292. + urb_tq_entry_t *new_entry;
  76293. + int rc = 0;
  76294. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  76295. + DWC_PRINTF("%s: urb %p, device %d, ep %d %s, status=%d\n",
  76296. + __func__, urb, usb_pipedevice(urb->pipe),
  76297. + usb_pipeendpoint(urb->pipe),
  76298. + usb_pipein(urb->pipe) ? "IN" : "OUT", status);
  76299. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  76300. + int i;
  76301. + for (i = 0; i < urb->number_of_packets; i++) {
  76302. + DWC_PRINTF(" ISO Desc %d status: %d\n",
  76303. + i, urb->iso_frame_desc[i].status);
  76304. + }
  76305. + }
  76306. + }
  76307. + new_entry = DWC_ALLOC_ATOMIC(sizeof(urb_tq_entry_t));
  76308. + urb->actual_length = dwc_otg_hcd_urb_get_actual_length(dwc_otg_urb);
  76309. + /* Convert status value. */
  76310. + switch (status) {
  76311. + case -DWC_E_PROTOCOL:
  76312. + status = -EPROTO;
  76313. + break;
  76314. + case -DWC_E_IN_PROGRESS:
  76315. + status = -EINPROGRESS;
  76316. + break;
  76317. + case -DWC_E_PIPE:
  76318. + status = -EPIPE;
  76319. + break;
  76320. + case -DWC_E_IO:
  76321. + status = -EIO;
  76322. + break;
  76323. + case -DWC_E_TIMEOUT:
  76324. + status = -ETIMEDOUT;
  76325. + break;
  76326. + case -DWC_E_OVERFLOW:
  76327. + status = -EOVERFLOW;
  76328. + break;
  76329. + case -DWC_E_SHUTDOWN:
  76330. + status = -ESHUTDOWN;
  76331. + break;
  76332. + default:
  76333. + if (status) {
  76334. + DWC_PRINTF("Uknown urb status %d\n", status);
  76335. +
  76336. + }
  76337. + }
  76338. +
  76339. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  76340. + int i;
  76341. +
  76342. + urb->error_count = dwc_otg_hcd_urb_get_error_count(dwc_otg_urb);
  76343. + for (i = 0; i < urb->number_of_packets; ++i) {
  76344. + urb->iso_frame_desc[i].actual_length =
  76345. + dwc_otg_hcd_urb_get_iso_desc_actual_length
  76346. + (dwc_otg_urb, i);
  76347. + urb->iso_frame_desc[i].status =
  76348. + dwc_otg_hcd_urb_get_iso_desc_status(dwc_otg_urb, i);
  76349. + }
  76350. + }
  76351. +
  76352. + urb->status = status;
  76353. + urb->hcpriv = NULL;
  76354. + if (!status) {
  76355. + if ((urb->transfer_flags & URB_SHORT_NOT_OK) &&
  76356. + (urb->actual_length < urb->transfer_buffer_length)) {
  76357. + urb->status = -EREMOTEIO;
  76358. + }
  76359. + }
  76360. +
  76361. + if ((usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) ||
  76362. + (usb_pipetype(urb->pipe) == PIPE_INTERRUPT)) {
  76363. + struct usb_host_endpoint *ep = dwc_urb_to_endpoint(urb);
  76364. + if (ep) {
  76365. + free_bus_bandwidth(dwc_otg_hcd_to_hcd(hcd),
  76366. + dwc_otg_hcd_get_ep_bandwidth(hcd,
  76367. + ep->hcpriv),
  76368. + urb);
  76369. + }
  76370. + }
  76371. +
  76372. + DWC_FREE(dwc_otg_urb);
  76373. + if (!new_entry) {
  76374. + DWC_ERROR("dwc_otg_hcd: complete: cannot allocate URB TQ entry\n");
  76375. + urb->status = -EPROTO;
  76376. + /* don't schedule the tasklet -
  76377. + * directly return the packet here with error. */
  76378. +#if USB_URB_EP_LINKING
  76379. + usb_hcd_unlink_urb_from_ep(dwc_otg_hcd_to_hcd(hcd), urb);
  76380. +#endif
  76381. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  76382. + usb_hcd_giveback_urb(dwc_otg_hcd_to_hcd(hcd), urb);
  76383. +#else
  76384. + usb_hcd_giveback_urb(dwc_otg_hcd_to_hcd(hcd), urb, urb->status);
  76385. +#endif
  76386. + } else {
  76387. + new_entry->urb = urb;
  76388. +#if USB_URB_EP_LINKING
  76389. + rc = usb_hcd_check_unlink_urb(dwc_otg_hcd_to_hcd(hcd), urb, urb->status);
  76390. + if(0 == rc) {
  76391. + usb_hcd_unlink_urb_from_ep(dwc_otg_hcd_to_hcd(hcd), urb);
  76392. + }
  76393. +#endif
  76394. + if(0 == rc) {
  76395. + DWC_TAILQ_INSERT_TAIL(&hcd->completed_urb_list, new_entry,
  76396. + urb_tq_entries);
  76397. + DWC_TASK_HI_SCHEDULE(hcd->completion_tasklet);
  76398. + }
  76399. + }
  76400. + return 0;
  76401. +}
  76402. +
  76403. +static struct dwc_otg_hcd_function_ops hcd_fops = {
  76404. + .start = _start,
  76405. + .disconnect = _disconnect,
  76406. + .hub_info = _hub_info,
  76407. + .speed = _speed,
  76408. + .complete = _complete,
  76409. + .get_b_hnp_enable = _get_b_hnp_enable,
  76410. +};
  76411. +
  76412. +static struct fiq_handler fh = {
  76413. + .name = "usb_fiq",
  76414. +};
  76415. +struct fiq_stack_s {
  76416. + int magic1;
  76417. + uint8_t stack[2048];
  76418. + int magic2;
  76419. +} fiq_stack;
  76420. +
  76421. +extern mphi_regs_t c_mphi_regs;
  76422. +/**
  76423. + * Initializes the HCD. This function allocates memory for and initializes the
  76424. + * static parts of the usb_hcd and dwc_otg_hcd structures. It also registers the
  76425. + * USB bus with the core and calls the hc_driver->start() function. It returns
  76426. + * a negative error on failure.
  76427. + */
  76428. +int hcd_init(dwc_bus_dev_t *_dev)
  76429. +{
  76430. + struct usb_hcd *hcd = NULL;
  76431. + dwc_otg_hcd_t *dwc_otg_hcd = NULL;
  76432. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  76433. + int retval = 0;
  76434. + u64 dmamask;
  76435. + struct pt_regs regs;
  76436. +
  76437. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD INIT otg_dev=%p\n", otg_dev);
  76438. +
  76439. + /* Set device flags indicating whether the HCD supports DMA. */
  76440. + if (dwc_otg_is_dma_enable(otg_dev->core_if))
  76441. + dmamask = DMA_BIT_MASK(32);
  76442. + else
  76443. + dmamask = 0;
  76444. +
  76445. +#if defined(LM_INTERFACE) || defined(PLATFORM_INTERFACE)
  76446. + dma_set_mask(&_dev->dev, dmamask);
  76447. + dma_set_coherent_mask(&_dev->dev, dmamask);
  76448. +#elif defined(PCI_INTERFACE)
  76449. + pci_set_dma_mask(_dev, dmamask);
  76450. + pci_set_consistent_dma_mask(_dev, dmamask);
  76451. +#endif
  76452. +
  76453. + if (fiq_fix_enable)
  76454. + {
  76455. + // Set up fiq
  76456. + claim_fiq(&fh);
  76457. + set_fiq_handler(__FIQ_Branch, 4);
  76458. + memset(&regs,0,sizeof(regs));
  76459. + regs.ARM_r8 = (long)dwc_otg_hcd_handle_fiq;
  76460. + regs.ARM_r9 = (long)0;
  76461. + regs.ARM_sp = (long)fiq_stack.stack + sizeof(fiq_stack.stack) - 4;
  76462. + set_fiq_regs(&regs);
  76463. + fiq_stack.magic1 = 0xdeadbeef;
  76464. + fiq_stack.magic2 = 0xaa995566;
  76465. + }
  76466. +
  76467. + /*
  76468. + * Allocate memory for the base HCD plus the DWC OTG HCD.
  76469. + * Initialize the base HCD.
  76470. + */
  76471. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
  76472. + hcd = usb_create_hcd(&dwc_otg_hc_driver, &_dev->dev, _dev->dev.bus_id);
  76473. +#else
  76474. + hcd = usb_create_hcd(&dwc_otg_hc_driver, &_dev->dev, dev_name(&_dev->dev));
  76475. + hcd->has_tt = 1;
  76476. +// hcd->uses_new_polling = 1;
  76477. +// hcd->poll_rh = 0;
  76478. +#endif
  76479. + if (!hcd) {
  76480. + retval = -ENOMEM;
  76481. + goto error1;
  76482. + }
  76483. +
  76484. + hcd->regs = otg_dev->os_dep.base;
  76485. +
  76486. + if (fiq_fix_enable)
  76487. + {
  76488. + volatile extern void *dwc_regs_base;
  76489. +
  76490. + //Set the mphi periph to the required registers
  76491. + c_mphi_regs.base = otg_dev->os_dep.mphi_base;
  76492. + c_mphi_regs.ctrl = otg_dev->os_dep.mphi_base + 0x4c;
  76493. + c_mphi_regs.outdda = otg_dev->os_dep.mphi_base + 0x28;
  76494. + c_mphi_regs.outddb = otg_dev->os_dep.mphi_base + 0x2c;
  76495. + c_mphi_regs.intstat = otg_dev->os_dep.mphi_base + 0x50;
  76496. +
  76497. + dwc_regs_base = otg_dev->os_dep.base;
  76498. +
  76499. + //Enable mphi peripheral
  76500. + writel((1<<31),c_mphi_regs.ctrl);
  76501. +#ifdef DEBUG
  76502. + if (readl(c_mphi_regs.ctrl) & 0x80000000)
  76503. + DWC_DEBUGPL(DBG_USER, "MPHI periph has been enabled\n");
  76504. + else
  76505. + DWC_DEBUGPL(DBG_USER, "MPHI periph has NOT been enabled\n");
  76506. +#endif
  76507. + // Enable FIQ interrupt from USB peripheral
  76508. + enable_fiq(INTERRUPT_VC_USB);
  76509. + }
  76510. + /* Initialize the DWC OTG HCD. */
  76511. + dwc_otg_hcd = dwc_otg_hcd_alloc_hcd();
  76512. + if (!dwc_otg_hcd) {
  76513. + goto error2;
  76514. + }
  76515. + ((struct wrapper_priv_data *)(hcd->hcd_priv))->dwc_otg_hcd =
  76516. + dwc_otg_hcd;
  76517. + otg_dev->hcd = dwc_otg_hcd;
  76518. +
  76519. + if (dwc_otg_hcd_init(dwc_otg_hcd, otg_dev->core_if)) {
  76520. + goto error2;
  76521. + }
  76522. +
  76523. + otg_dev->hcd->otg_dev = otg_dev;
  76524. + hcd->self.otg_port = dwc_otg_hcd_otg_port(dwc_otg_hcd);
  76525. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33) //don't support for LM(with 2.6.20.1 kernel)
  76526. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) //version field absent later
  76527. + hcd->self.otg_version = dwc_otg_get_otg_version(otg_dev->core_if);
  76528. +#endif
  76529. + /* Don't support SG list at this point */
  76530. + hcd->self.sg_tablesize = 0;
  76531. +#endif
  76532. + /*
  76533. + * Finish generic HCD initialization and start the HCD. This function
  76534. + * allocates the DMA buffer pool, registers the USB bus, requests the
  76535. + * IRQ line, and calls hcd_start method.
  76536. + */
  76537. +#ifdef PLATFORM_INTERFACE
  76538. + retval = usb_add_hcd(hcd, platform_get_irq(_dev, 0), IRQF_SHARED | IRQF_DISABLED);
  76539. +#else
  76540. + retval = usb_add_hcd(hcd, _dev->irq, IRQF_SHARED | IRQF_DISABLED);
  76541. +#endif
  76542. + if (retval < 0) {
  76543. + goto error2;
  76544. + }
  76545. +
  76546. + dwc_otg_hcd_set_priv_data(dwc_otg_hcd, hcd);
  76547. + return 0;
  76548. +
  76549. +error2:
  76550. + usb_put_hcd(hcd);
  76551. +error1:
  76552. + return retval;
  76553. +}
  76554. +
  76555. +/**
  76556. + * Removes the HCD.
  76557. + * Frees memory and resources associated with the HCD and deregisters the bus.
  76558. + */
  76559. +void hcd_remove(dwc_bus_dev_t *_dev)
  76560. +{
  76561. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  76562. + dwc_otg_hcd_t *dwc_otg_hcd;
  76563. + struct usb_hcd *hcd;
  76564. +
  76565. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD REMOVE otg_dev=%p\n", otg_dev);
  76566. +
  76567. + if (!otg_dev) {
  76568. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev NULL!\n", __func__);
  76569. + return;
  76570. + }
  76571. +
  76572. + dwc_otg_hcd = otg_dev->hcd;
  76573. +
  76574. + if (!dwc_otg_hcd) {
  76575. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->hcd NULL!\n", __func__);
  76576. + return;
  76577. + }
  76578. +
  76579. + hcd = dwc_otg_hcd_to_hcd(dwc_otg_hcd);
  76580. +
  76581. + if (!hcd) {
  76582. + DWC_DEBUGPL(DBG_ANY,
  76583. + "%s: dwc_otg_hcd_to_hcd(dwc_otg_hcd) NULL!\n",
  76584. + __func__);
  76585. + return;
  76586. + }
  76587. + usb_remove_hcd(hcd);
  76588. + dwc_otg_hcd_set_priv_data(dwc_otg_hcd, NULL);
  76589. + dwc_otg_hcd_remove(dwc_otg_hcd);
  76590. + usb_put_hcd(hcd);
  76591. +}
  76592. +
  76593. +/* =========================================================================
  76594. + * Linux HC Driver Functions
  76595. + * ========================================================================= */
  76596. +
  76597. +/** Initializes the DWC_otg controller and its root hub and prepares it for host
  76598. + * mode operation. Activates the root port. Returns 0 on success and a negative
  76599. + * error code on failure. */
  76600. +int hcd_start(struct usb_hcd *hcd)
  76601. +{
  76602. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  76603. + struct usb_bus *bus;
  76604. +
  76605. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD START\n");
  76606. + bus = hcd_to_bus(hcd);
  76607. +
  76608. + hcd->state = HC_STATE_RUNNING;
  76609. + if (dwc_otg_hcd_start(dwc_otg_hcd, &hcd_fops)) {
  76610. + return 0;
  76611. + }
  76612. +
  76613. + /* Initialize and connect root hub if one is not already attached */
  76614. + if (bus->root_hub) {
  76615. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Has Root Hub\n");
  76616. + /* Inform the HUB driver to resume. */
  76617. + usb_hcd_resume_root_hub(hcd);
  76618. + }
  76619. +
  76620. + return 0;
  76621. +}
  76622. +
  76623. +/**
  76624. + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
  76625. + * stopped.
  76626. + */
  76627. +void hcd_stop(struct usb_hcd *hcd)
  76628. +{
  76629. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  76630. +
  76631. + dwc_otg_hcd_stop(dwc_otg_hcd);
  76632. +}
  76633. +
  76634. +/** Returns the current frame number. */
  76635. +static int get_frame_number(struct usb_hcd *hcd)
  76636. +{
  76637. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  76638. +
  76639. + return dwc_otg_hcd_get_frame_number(dwc_otg_hcd);
  76640. +}
  76641. +
  76642. +#ifdef DEBUG
  76643. +static void dump_urb_info(struct urb *urb, char *fn_name)
  76644. +{
  76645. + DWC_PRINTF("%s, urb %p\n", fn_name, urb);
  76646. + DWC_PRINTF(" Device address: %d\n", usb_pipedevice(urb->pipe));
  76647. + DWC_PRINTF(" Endpoint: %d, %s\n", usb_pipeendpoint(urb->pipe),
  76648. + (usb_pipein(urb->pipe) ? "IN" : "OUT"));
  76649. + DWC_PRINTF(" Endpoint type: %s\n", ( {
  76650. + char *pipetype;
  76651. + switch (usb_pipetype(urb->pipe)) {
  76652. +case PIPE_CONTROL:
  76653. +pipetype = "CONTROL"; break; case PIPE_BULK:
  76654. +pipetype = "BULK"; break; case PIPE_INTERRUPT:
  76655. +pipetype = "INTERRUPT"; break; case PIPE_ISOCHRONOUS:
  76656. +pipetype = "ISOCHRONOUS"; break; default:
  76657. + pipetype = "UNKNOWN"; break;};
  76658. + pipetype;}
  76659. + )) ;
  76660. + DWC_PRINTF(" Speed: %s\n", ( {
  76661. + char *speed; switch (urb->dev->speed) {
  76662. +case USB_SPEED_HIGH:
  76663. +speed = "HIGH"; break; case USB_SPEED_FULL:
  76664. +speed = "FULL"; break; case USB_SPEED_LOW:
  76665. +speed = "LOW"; break; default:
  76666. + speed = "UNKNOWN"; break;};
  76667. + speed;}
  76668. + )) ;
  76669. + DWC_PRINTF(" Max packet size: %d\n",
  76670. + usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)));
  76671. + DWC_PRINTF(" Data buffer length: %d\n", urb->transfer_buffer_length);
  76672. + DWC_PRINTF(" Transfer buffer: %p, Transfer DMA: %p\n",
  76673. + urb->transfer_buffer, (void *)urb->transfer_dma);
  76674. + DWC_PRINTF(" Setup buffer: %p, Setup DMA: %p\n",
  76675. + urb->setup_packet, (void *)urb->setup_dma);
  76676. + DWC_PRINTF(" Interval: %d\n", urb->interval);
  76677. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  76678. + int i;
  76679. + for (i = 0; i < urb->number_of_packets; i++) {
  76680. + DWC_PRINTF(" ISO Desc %d:\n", i);
  76681. + DWC_PRINTF(" offset: %d, length %d\n",
  76682. + urb->iso_frame_desc[i].offset,
  76683. + urb->iso_frame_desc[i].length);
  76684. + }
  76685. + }
  76686. +}
  76687. +#endif
  76688. +
  76689. +/** Starts processing a USB transfer request specified by a USB Request Block
  76690. + * (URB). mem_flags indicates the type of memory allocation to use while
  76691. + * processing this URB. */
  76692. +static int dwc_otg_urb_enqueue(struct usb_hcd *hcd,
  76693. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  76694. + struct usb_host_endpoint *ep,
  76695. +#endif
  76696. + struct urb *urb, gfp_t mem_flags)
  76697. +{
  76698. + int retval = 0;
  76699. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)
  76700. + struct usb_host_endpoint *ep = urb->ep;
  76701. +#endif
  76702. + dwc_irqflags_t irqflags;
  76703. + void **ref_ep_hcpriv = &ep->hcpriv;
  76704. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  76705. + dwc_otg_hcd_urb_t *dwc_otg_urb;
  76706. + int i;
  76707. + int alloc_bandwidth = 0;
  76708. + uint8_t ep_type = 0;
  76709. + uint32_t flags = 0;
  76710. + void *buf;
  76711. +
  76712. +#ifdef DEBUG
  76713. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  76714. + dump_urb_info(urb, "dwc_otg_urb_enqueue");
  76715. + }
  76716. +#endif
  76717. +
  76718. + if (!urb->transfer_buffer && urb->transfer_buffer_length)
  76719. + return -EINVAL;
  76720. +
  76721. + if ((usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS)
  76722. + || (usb_pipetype(urb->pipe) == PIPE_INTERRUPT)) {
  76723. + if (!dwc_otg_hcd_is_bandwidth_allocated
  76724. + (dwc_otg_hcd, ref_ep_hcpriv)) {
  76725. + alloc_bandwidth = 1;
  76726. + }
  76727. + }
  76728. +
  76729. + switch (usb_pipetype(urb->pipe)) {
  76730. + case PIPE_CONTROL:
  76731. + ep_type = USB_ENDPOINT_XFER_CONTROL;
  76732. + break;
  76733. + case PIPE_ISOCHRONOUS:
  76734. + ep_type = USB_ENDPOINT_XFER_ISOC;
  76735. + break;
  76736. + case PIPE_BULK:
  76737. + ep_type = USB_ENDPOINT_XFER_BULK;
  76738. + break;
  76739. + case PIPE_INTERRUPT:
  76740. + ep_type = USB_ENDPOINT_XFER_INT;
  76741. + break;
  76742. + default:
  76743. + DWC_WARN("Wrong EP type - %d\n", usb_pipetype(urb->pipe));
  76744. + }
  76745. +
  76746. + /* # of packets is often 0 - do we really need to call this then? */
  76747. + dwc_otg_urb = dwc_otg_hcd_urb_alloc(dwc_otg_hcd,
  76748. + urb->number_of_packets,
  76749. + mem_flags == GFP_ATOMIC ? 1 : 0);
  76750. +
  76751. + if(dwc_otg_urb == NULL)
  76752. + return -ENOMEM;
  76753. +
  76754. + if (!dwc_otg_urb && urb->number_of_packets)
  76755. + return -ENOMEM;
  76756. +
  76757. + dwc_otg_hcd_urb_set_pipeinfo(dwc_otg_urb, usb_pipedevice(urb->pipe),
  76758. + usb_pipeendpoint(urb->pipe), ep_type,
  76759. + usb_pipein(urb->pipe),
  76760. + usb_maxpacket(urb->dev, urb->pipe,
  76761. + !(usb_pipein(urb->pipe))));
  76762. +
  76763. + buf = urb->transfer_buffer;
  76764. + if (hcd->self.uses_dma) {
  76765. + /*
  76766. + * Calculate virtual address from physical address,
  76767. + * because some class driver may not fill transfer_buffer.
  76768. + * In Buffer DMA mode virual address is used,
  76769. + * when handling non DWORD aligned buffers.
  76770. + */
  76771. + //buf = phys_to_virt(urb->transfer_dma);
  76772. + // DMA addresses are bus addresses not physical addresses!
  76773. + buf = dma_to_virt(&urb->dev->dev, urb->transfer_dma);
  76774. + }
  76775. +
  76776. + if (!(urb->transfer_flags & URB_NO_INTERRUPT))
  76777. + flags |= URB_GIVEBACK_ASAP;
  76778. + if (urb->transfer_flags & URB_ZERO_PACKET)
  76779. + flags |= URB_SEND_ZERO_PACKET;
  76780. +
  76781. + dwc_otg_hcd_urb_set_params(dwc_otg_urb, urb, buf,
  76782. + urb->transfer_dma,
  76783. + urb->transfer_buffer_length,
  76784. + urb->setup_packet,
  76785. + urb->setup_dma, flags, urb->interval);
  76786. +
  76787. + for (i = 0; i < urb->number_of_packets; ++i) {
  76788. + dwc_otg_hcd_urb_set_iso_desc_params(dwc_otg_urb, i,
  76789. + urb->
  76790. + iso_frame_desc[i].offset,
  76791. + urb->
  76792. + iso_frame_desc[i].length);
  76793. + }
  76794. +
  76795. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &irqflags);
  76796. + urb->hcpriv = dwc_otg_urb;
  76797. +#if USB_URB_EP_LINKING
  76798. + retval = usb_hcd_link_urb_to_ep(hcd, urb);
  76799. + if (0 == retval)
  76800. +#endif
  76801. + {
  76802. + retval = dwc_otg_hcd_urb_enqueue(dwc_otg_hcd, dwc_otg_urb,
  76803. + /*(dwc_otg_qh_t **)*/
  76804. + ref_ep_hcpriv, 1);
  76805. + if (0 == retval) {
  76806. + if (alloc_bandwidth) {
  76807. + allocate_bus_bandwidth(hcd,
  76808. + dwc_otg_hcd_get_ep_bandwidth(
  76809. + dwc_otg_hcd, *ref_ep_hcpriv),
  76810. + urb);
  76811. + }
  76812. + } else {
  76813. + DWC_DEBUGPL(DBG_HCD, "DWC OTG dwc_otg_hcd_urb_enqueue failed rc %d\n", retval);
  76814. +#if USB_URB_EP_LINKING
  76815. + usb_hcd_unlink_urb_from_ep(hcd, urb);
  76816. +#endif
  76817. + DWC_FREE(dwc_otg_urb);
  76818. + urb->hcpriv = NULL;
  76819. + if (retval == -DWC_E_NO_DEVICE)
  76820. + retval = -ENODEV;
  76821. + }
  76822. + }
  76823. +#if USB_URB_EP_LINKING
  76824. + else
  76825. + {
  76826. + DWC_FREE(dwc_otg_urb);
  76827. + urb->hcpriv = NULL;
  76828. + }
  76829. +#endif
  76830. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, irqflags);
  76831. + return retval;
  76832. +}
  76833. +
  76834. +/** Aborts/cancels a USB transfer request. Always returns 0 to indicate
  76835. + * success. */
  76836. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  76837. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
  76838. +#else
  76839. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
  76840. +#endif
  76841. +{
  76842. + dwc_irqflags_t flags;
  76843. + dwc_otg_hcd_t *dwc_otg_hcd;
  76844. + int rc;
  76845. +
  76846. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue\n");
  76847. +
  76848. + dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  76849. +
  76850. +#ifdef DEBUG
  76851. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  76852. + dump_urb_info(urb, "dwc_otg_urb_dequeue");
  76853. + }
  76854. +#endif
  76855. +
  76856. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  76857. + rc = usb_hcd_check_unlink_urb(hcd, urb, status);
  76858. + if (0 == rc) {
  76859. + if(urb->hcpriv != NULL) {
  76860. + dwc_otg_hcd_urb_dequeue(dwc_otg_hcd,
  76861. + (dwc_otg_hcd_urb_t *)urb->hcpriv);
  76862. +
  76863. + DWC_FREE(urb->hcpriv);
  76864. + urb->hcpriv = NULL;
  76865. + }
  76866. + }
  76867. +
  76868. + if (0 == rc) {
  76869. + /* Higher layer software sets URB status. */
  76870. +#if USB_URB_EP_LINKING
  76871. + usb_hcd_unlink_urb_from_ep(hcd, urb);
  76872. +#endif
  76873. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  76874. +
  76875. +
  76876. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  76877. + usb_hcd_giveback_urb(hcd, urb);
  76878. +#else
  76879. + usb_hcd_giveback_urb(hcd, urb, status);
  76880. +#endif
  76881. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  76882. + DWC_PRINTF("Called usb_hcd_giveback_urb() \n");
  76883. + DWC_PRINTF(" 1urb->status = %d\n", urb->status);
  76884. + }
  76885. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue OK\n");
  76886. + } else {
  76887. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  76888. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue failed - rc %d\n",
  76889. + rc);
  76890. + }
  76891. +
  76892. + return rc;
  76893. +}
  76894. +
  76895. +/* Frees resources in the DWC_otg controller related to a given endpoint. Also
  76896. + * clears state in the HCD related to the endpoint. Any URBs for the endpoint
  76897. + * must already be dequeued. */
  76898. +static void endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
  76899. +{
  76900. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  76901. +
  76902. + DWC_DEBUGPL(DBG_HCD,
  76903. + "DWC OTG HCD EP DISABLE: _bEndpointAddress=0x%02x, "
  76904. + "endpoint=%d\n", ep->desc.bEndpointAddress,
  76905. + dwc_ep_addr_to_endpoint(ep->desc.bEndpointAddress));
  76906. + dwc_otg_hcd_endpoint_disable(dwc_otg_hcd, ep->hcpriv, 250);
  76907. + ep->hcpriv = NULL;
  76908. +}
  76909. +
  76910. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  76911. +/* Resets endpoint specific parameter values, in current version used to reset
  76912. + * the data toggle(as a WA). This function can be called from usb_clear_halt routine */
  76913. +static void endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
  76914. +{
  76915. + dwc_irqflags_t flags;
  76916. + struct usb_device *udev = NULL;
  76917. + int epnum = usb_endpoint_num(&ep->desc);
  76918. + int is_out = usb_endpoint_dir_out(&ep->desc);
  76919. + int is_control = usb_endpoint_xfer_control(&ep->desc);
  76920. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  76921. + struct device *dev = DWC_OTG_OS_GETDEV(dwc_otg_hcd->otg_dev->os_dep);
  76922. +
  76923. + if (dev)
  76924. + udev = to_usb_device(dev);
  76925. + else
  76926. + return;
  76927. +
  76928. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD EP RESET: Endpoint Num=0x%02d\n", epnum);
  76929. +
  76930. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  76931. + usb_settoggle(udev, epnum, is_out, 0);
  76932. + if (is_control)
  76933. + usb_settoggle(udev, epnum, !is_out, 0);
  76934. +
  76935. + if (ep->hcpriv) {
  76936. + dwc_otg_hcd_endpoint_reset(dwc_otg_hcd, ep->hcpriv);
  76937. + }
  76938. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  76939. +}
  76940. +#endif
  76941. +
  76942. +/** Handles host mode interrupts for the DWC_otg controller. Returns IRQ_NONE if
  76943. + * there was no interrupt to handle. Returns IRQ_HANDLED if there was a valid
  76944. + * interrupt.
  76945. + *
  76946. + * This function is called by the USB core when an interrupt occurs */
  76947. +static irqreturn_t dwc_otg_hcd_irq(struct usb_hcd *hcd)
  76948. +{
  76949. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  76950. + int32_t retval = dwc_otg_hcd_handle_intr(dwc_otg_hcd);
  76951. + if (retval != 0) {
  76952. + S3C2410X_CLEAR_EINTPEND();
  76953. + }
  76954. + return IRQ_RETVAL(retval);
  76955. +}
  76956. +
  76957. +/** Creates Status Change bitmap for the root hub and root port. The bitmap is
  76958. + * returned in buf. Bit 0 is the status change indicator for the root hub. Bit 1
  76959. + * is the status change indicator for the single root port. Returns 1 if either
  76960. + * change indicator is 1, otherwise returns 0. */
  76961. +int hub_status_data(struct usb_hcd *hcd, char *buf)
  76962. +{
  76963. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  76964. +
  76965. + buf[0] = 0;
  76966. + buf[0] |= (dwc_otg_hcd_is_status_changed(dwc_otg_hcd, 1)) << 1;
  76967. +
  76968. + return (buf[0] != 0);
  76969. +}
  76970. +
  76971. +/** Handles hub class-specific requests. */
  76972. +int hub_control(struct usb_hcd *hcd,
  76973. + u16 typeReq, u16 wValue, u16 wIndex, char *buf, u16 wLength)
  76974. +{
  76975. + int retval;
  76976. +
  76977. + retval = dwc_otg_hcd_hub_control(hcd_to_dwc_otg_hcd(hcd),
  76978. + typeReq, wValue, wIndex, buf, wLength);
  76979. +
  76980. + switch (retval) {
  76981. + case -DWC_E_INVALID:
  76982. + retval = -EINVAL;
  76983. + break;
  76984. + }
  76985. +
  76986. + return retval;
  76987. +}
  76988. +
  76989. +#endif /* DWC_DEVICE_ONLY */
  76990. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c
  76991. --- linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c 1970-01-01 01:00:00.000000000 +0100
  76992. +++ linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c 2014-02-17 22:41:01.000000000 +0100
  76993. @@ -0,0 +1,959 @@
  76994. +/* ==========================================================================
  76995. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_queue.c $
  76996. + * $Revision: #44 $
  76997. + * $Date: 2011/10/26 $
  76998. + * $Change: 1873028 $
  76999. + *
  77000. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  77001. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  77002. + * otherwise expressly agreed to in writing between Synopsys and you.
  77003. + *
  77004. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  77005. + * any End User Software License Agreement or Agreement for Licensed Product
  77006. + * with Synopsys or any supplement thereto. You are permitted to use and
  77007. + * redistribute this Software in source and binary forms, with or without
  77008. + * modification, provided that redistributions of source code must retain this
  77009. + * notice. You may not view, use, disclose, copy or distribute this file or
  77010. + * any information contained herein except pursuant to this license grant from
  77011. + * Synopsys. If you do not agree with this notice, including the disclaimer
  77012. + * below, then you are not authorized to use the Software.
  77013. + *
  77014. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  77015. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  77016. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  77017. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  77018. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  77019. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  77020. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  77021. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  77022. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  77023. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  77024. + * DAMAGE.
  77025. + * ========================================================================== */
  77026. +#ifndef DWC_DEVICE_ONLY
  77027. +
  77028. +/**
  77029. + * @file
  77030. + *
  77031. + * This file contains the functions to manage Queue Heads and Queue
  77032. + * Transfer Descriptors.
  77033. + */
  77034. +
  77035. +#include "dwc_otg_hcd.h"
  77036. +#include "dwc_otg_regs.h"
  77037. +#include "dwc_otg_mphi_fix.h"
  77038. +
  77039. +extern bool microframe_schedule;
  77040. +
  77041. +/**
  77042. + * Free each QTD in the QH's QTD-list then free the QH. QH should already be
  77043. + * removed from a list. QTD list should already be empty if called from URB
  77044. + * Dequeue.
  77045. + *
  77046. + * @param hcd HCD instance.
  77047. + * @param qh The QH to free.
  77048. + */
  77049. +void dwc_otg_hcd_qh_free(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  77050. +{
  77051. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  77052. +
  77053. + /* Free each QTD in the QTD list */
  77054. + DWC_SPINLOCK(hcd->lock);
  77055. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &qh->qtd_list, qtd_list_entry) {
  77056. + DWC_CIRCLEQ_REMOVE(&qh->qtd_list, qtd, qtd_list_entry);
  77057. + dwc_otg_hcd_qtd_free(qtd);
  77058. + }
  77059. +
  77060. + if (hcd->core_if->dma_desc_enable) {
  77061. + dwc_otg_hcd_qh_free_ddma(hcd, qh);
  77062. + } else if (qh->dw_align_buf) {
  77063. + uint32_t buf_size;
  77064. + if (qh->ep_type == UE_ISOCHRONOUS) {
  77065. + buf_size = 4096;
  77066. + } else {
  77067. + buf_size = hcd->core_if->core_params->max_transfer_size;
  77068. + }
  77069. + DWC_DMA_FREE(buf_size, qh->dw_align_buf, qh->dw_align_buf_dma);
  77070. + }
  77071. +
  77072. + DWC_FREE(qh);
  77073. + DWC_SPINUNLOCK(hcd->lock);
  77074. + return;
  77075. +}
  77076. +
  77077. +#define BitStuffTime(bytecount) ((8 * 7* bytecount) / 6)
  77078. +#define HS_HOST_DELAY 5 /* nanoseconds */
  77079. +#define FS_LS_HOST_DELAY 1000 /* nanoseconds */
  77080. +#define HUB_LS_SETUP 333 /* nanoseconds */
  77081. +#define NS_TO_US(ns) ((ns + 500) / 1000)
  77082. + /* convert & round nanoseconds to microseconds */
  77083. +
  77084. +static uint32_t calc_bus_time(int speed, int is_in, int is_isoc, int bytecount)
  77085. +{
  77086. + unsigned long retval;
  77087. +
  77088. + switch (speed) {
  77089. + case USB_SPEED_HIGH:
  77090. + if (is_isoc) {
  77091. + retval =
  77092. + ((38 * 8 * 2083) +
  77093. + (2083 * (3 + BitStuffTime(bytecount)))) / 1000 +
  77094. + HS_HOST_DELAY;
  77095. + } else {
  77096. + retval =
  77097. + ((55 * 8 * 2083) +
  77098. + (2083 * (3 + BitStuffTime(bytecount)))) / 1000 +
  77099. + HS_HOST_DELAY;
  77100. + }
  77101. + break;
  77102. + case USB_SPEED_FULL:
  77103. + if (is_isoc) {
  77104. + retval =
  77105. + (8354 * (31 + 10 * BitStuffTime(bytecount))) / 1000;
  77106. + if (is_in) {
  77107. + retval = 7268 + FS_LS_HOST_DELAY + retval;
  77108. + } else {
  77109. + retval = 6265 + FS_LS_HOST_DELAY + retval;
  77110. + }
  77111. + } else {
  77112. + retval =
  77113. + (8354 * (31 + 10 * BitStuffTime(bytecount))) / 1000;
  77114. + retval = 9107 + FS_LS_HOST_DELAY + retval;
  77115. + }
  77116. + break;
  77117. + case USB_SPEED_LOW:
  77118. + if (is_in) {
  77119. + retval =
  77120. + (67667 * (31 + 10 * BitStuffTime(bytecount))) /
  77121. + 1000;
  77122. + retval =
  77123. + 64060 + (2 * HUB_LS_SETUP) + FS_LS_HOST_DELAY +
  77124. + retval;
  77125. + } else {
  77126. + retval =
  77127. + (66700 * (31 + 10 * BitStuffTime(bytecount))) /
  77128. + 1000;
  77129. + retval =
  77130. + 64107 + (2 * HUB_LS_SETUP) + FS_LS_HOST_DELAY +
  77131. + retval;
  77132. + }
  77133. + break;
  77134. + default:
  77135. + DWC_WARN("Unknown device speed\n");
  77136. + retval = -1;
  77137. + }
  77138. +
  77139. + return NS_TO_US(retval);
  77140. +}
  77141. +
  77142. +/**
  77143. + * Initializes a QH structure.
  77144. + *
  77145. + * @param hcd The HCD state structure for the DWC OTG controller.
  77146. + * @param qh The QH to init.
  77147. + * @param urb Holds the information about the device/endpoint that we need
  77148. + * to initialize the QH.
  77149. + */
  77150. +#define SCHEDULE_SLOP 10
  77151. +void qh_init(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh, dwc_otg_hcd_urb_t * urb)
  77152. +{
  77153. + char *speed, *type;
  77154. + int dev_speed;
  77155. + uint32_t hub_addr, hub_port;
  77156. +
  77157. + dwc_memset(qh, 0, sizeof(dwc_otg_qh_t));
  77158. +
  77159. + /* Initialize QH */
  77160. + qh->ep_type = dwc_otg_hcd_get_pipe_type(&urb->pipe_info);
  77161. + qh->ep_is_in = dwc_otg_hcd_is_pipe_in(&urb->pipe_info) ? 1 : 0;
  77162. +
  77163. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  77164. + qh->maxp = dwc_otg_hcd_get_mps(&urb->pipe_info);
  77165. + DWC_CIRCLEQ_INIT(&qh->qtd_list);
  77166. + DWC_LIST_INIT(&qh->qh_list_entry);
  77167. + qh->channel = NULL;
  77168. +
  77169. + /* FS/LS Enpoint on HS Hub
  77170. + * NOT virtual root hub */
  77171. + dev_speed = hcd->fops->speed(hcd, urb->priv);
  77172. +
  77173. + hcd->fops->hub_info(hcd, urb->priv, &hub_addr, &hub_port);
  77174. + qh->do_split = 0;
  77175. + if (microframe_schedule)
  77176. + qh->speed = dev_speed;
  77177. +
  77178. + qh->nak_frame = 0xffff;
  77179. +
  77180. + if (((dev_speed == USB_SPEED_LOW) ||
  77181. + (dev_speed == USB_SPEED_FULL)) &&
  77182. + (hub_addr != 0 && hub_addr != 1)) {
  77183. + DWC_DEBUGPL(DBG_HCD,
  77184. + "QH init: EP %d: TT found at hub addr %d, for port %d\n",
  77185. + dwc_otg_hcd_get_ep_num(&urb->pipe_info), hub_addr,
  77186. + hub_port);
  77187. + qh->do_split = 1;
  77188. + qh->skip_count = 0;
  77189. + }
  77190. +
  77191. + if (qh->ep_type == UE_INTERRUPT || qh->ep_type == UE_ISOCHRONOUS) {
  77192. + /* Compute scheduling parameters once and save them. */
  77193. + hprt0_data_t hprt;
  77194. +
  77195. + /** @todo Account for split transfers in the bus time. */
  77196. + int bytecount =
  77197. + dwc_hb_mult(qh->maxp) * dwc_max_packet(qh->maxp);
  77198. +
  77199. + qh->usecs =
  77200. + calc_bus_time((qh->do_split ? USB_SPEED_HIGH : dev_speed),
  77201. + qh->ep_is_in, (qh->ep_type == UE_ISOCHRONOUS),
  77202. + bytecount);
  77203. + /* Start in a slightly future (micro)frame. */
  77204. + qh->sched_frame = dwc_frame_num_inc(hcd->frame_number,
  77205. + SCHEDULE_SLOP);
  77206. + qh->interval = urb->interval;
  77207. +
  77208. +#if 0
  77209. + /* Increase interrupt polling rate for debugging. */
  77210. + if (qh->ep_type == UE_INTERRUPT) {
  77211. + qh->interval = 8;
  77212. + }
  77213. +#endif
  77214. + hprt.d32 = DWC_READ_REG32(hcd->core_if->host_if->hprt0);
  77215. + if ((hprt.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED) &&
  77216. + ((dev_speed == USB_SPEED_LOW) ||
  77217. + (dev_speed == USB_SPEED_FULL))) {
  77218. + qh->interval *= 8;
  77219. + qh->sched_frame |= 0x7;
  77220. + qh->start_split_frame = qh->sched_frame;
  77221. + }
  77222. +
  77223. + }
  77224. +
  77225. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD QH Initialized\n");
  77226. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - qh = %p\n", qh);
  77227. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Device Address = %d\n",
  77228. + dwc_otg_hcd_get_dev_addr(&urb->pipe_info));
  77229. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Endpoint %d, %s\n",
  77230. + dwc_otg_hcd_get_ep_num(&urb->pipe_info),
  77231. + dwc_otg_hcd_is_pipe_in(&urb->pipe_info) ? "IN" : "OUT");
  77232. + switch (dev_speed) {
  77233. + case USB_SPEED_LOW:
  77234. + qh->dev_speed = DWC_OTG_EP_SPEED_LOW;
  77235. + speed = "low";
  77236. + break;
  77237. + case USB_SPEED_FULL:
  77238. + qh->dev_speed = DWC_OTG_EP_SPEED_FULL;
  77239. + speed = "full";
  77240. + break;
  77241. + case USB_SPEED_HIGH:
  77242. + qh->dev_speed = DWC_OTG_EP_SPEED_HIGH;
  77243. + speed = "high";
  77244. + break;
  77245. + default:
  77246. + speed = "?";
  77247. + break;
  77248. + }
  77249. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Speed = %s\n", speed);
  77250. +
  77251. + switch (qh->ep_type) {
  77252. + case UE_ISOCHRONOUS:
  77253. + type = "isochronous";
  77254. + break;
  77255. + case UE_INTERRUPT:
  77256. + type = "interrupt";
  77257. + break;
  77258. + case UE_CONTROL:
  77259. + type = "control";
  77260. + break;
  77261. + case UE_BULK:
  77262. + type = "bulk";
  77263. + break;
  77264. + default:
  77265. + type = "?";
  77266. + break;
  77267. + }
  77268. +
  77269. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Type = %s\n", type);
  77270. +
  77271. +#ifdef DEBUG
  77272. + if (qh->ep_type == UE_INTERRUPT) {
  77273. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - usecs = %d\n",
  77274. + qh->usecs);
  77275. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - interval = %d\n",
  77276. + qh->interval);
  77277. + }
  77278. +#endif
  77279. +
  77280. +}
  77281. +
  77282. +/**
  77283. + * This function allocates and initializes a QH.
  77284. + *
  77285. + * @param hcd The HCD state structure for the DWC OTG controller.
  77286. + * @param urb Holds the information about the device/endpoint that we need
  77287. + * to initialize the QH.
  77288. + * @param atomic_alloc Flag to do atomic allocation if needed
  77289. + *
  77290. + * @return Returns pointer to the newly allocated QH, or NULL on error. */
  77291. +dwc_otg_qh_t *dwc_otg_hcd_qh_create(dwc_otg_hcd_t * hcd,
  77292. + dwc_otg_hcd_urb_t * urb, int atomic_alloc)
  77293. +{
  77294. + dwc_otg_qh_t *qh;
  77295. +
  77296. + /* Allocate memory */
  77297. + /** @todo add memflags argument */
  77298. + qh = dwc_otg_hcd_qh_alloc(atomic_alloc);
  77299. + if (qh == NULL) {
  77300. + DWC_ERROR("qh allocation failed");
  77301. + return NULL;
  77302. + }
  77303. +
  77304. + qh_init(hcd, qh, urb);
  77305. +
  77306. + if (hcd->core_if->dma_desc_enable
  77307. + && (dwc_otg_hcd_qh_init_ddma(hcd, qh) < 0)) {
  77308. + dwc_otg_hcd_qh_free(hcd, qh);
  77309. + return NULL;
  77310. + }
  77311. +
  77312. + return qh;
  77313. +}
  77314. +
  77315. +/* microframe_schedule=0 start */
  77316. +
  77317. +/**
  77318. + * Checks that a channel is available for a periodic transfer.
  77319. + *
  77320. + * @return 0 if successful, negative error code otherise.
  77321. + */
  77322. +static int periodic_channel_available(dwc_otg_hcd_t * hcd)
  77323. +{
  77324. + /*
  77325. + * Currently assuming that there is a dedicated host channnel for each
  77326. + * periodic transaction plus at least one host channel for
  77327. + * non-periodic transactions.
  77328. + */
  77329. + int status;
  77330. + int num_channels;
  77331. +
  77332. + num_channels = hcd->core_if->core_params->host_channels;
  77333. + if ((hcd->periodic_channels + hcd->non_periodic_channels < num_channels)
  77334. + && (hcd->periodic_channels < num_channels - 1)) {
  77335. + status = 0;
  77336. + } else {
  77337. + DWC_INFO("%s: Total channels: %d, Periodic: %d, Non-periodic: %d\n",
  77338. + __func__, num_channels, hcd->periodic_channels, hcd->non_periodic_channels); //NOTICE
  77339. + status = -DWC_E_NO_SPACE;
  77340. + }
  77341. +
  77342. + return status;
  77343. +}
  77344. +
  77345. +/**
  77346. + * Checks that there is sufficient bandwidth for the specified QH in the
  77347. + * periodic schedule. For simplicity, this calculation assumes that all the
  77348. + * transfers in the periodic schedule may occur in the same (micro)frame.
  77349. + *
  77350. + * @param hcd The HCD state structure for the DWC OTG controller.
  77351. + * @param qh QH containing periodic bandwidth required.
  77352. + *
  77353. + * @return 0 if successful, negative error code otherwise.
  77354. + */
  77355. +static int check_periodic_bandwidth(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  77356. +{
  77357. + int status;
  77358. + int16_t max_claimed_usecs;
  77359. +
  77360. + status = 0;
  77361. +
  77362. + if ((qh->dev_speed == DWC_OTG_EP_SPEED_HIGH) || qh->do_split) {
  77363. + /*
  77364. + * High speed mode.
  77365. + * Max periodic usecs is 80% x 125 usec = 100 usec.
  77366. + */
  77367. +
  77368. + max_claimed_usecs = 100 - qh->usecs;
  77369. + } else {
  77370. + /*
  77371. + * Full speed mode.
  77372. + * Max periodic usecs is 90% x 1000 usec = 900 usec.
  77373. + */
  77374. + max_claimed_usecs = 900 - qh->usecs;
  77375. + }
  77376. +
  77377. + if (hcd->periodic_usecs > max_claimed_usecs) {
  77378. + DWC_INFO("%s: already claimed usecs %d, required usecs %d\n", __func__, hcd->periodic_usecs, qh->usecs); //NOTICE
  77379. + status = -DWC_E_NO_SPACE;
  77380. + }
  77381. +
  77382. + return status;
  77383. +}
  77384. +
  77385. +/* microframe_schedule=0 end */
  77386. +
  77387. +/**
  77388. + * Microframe scheduler
  77389. + * track the total use in hcd->frame_usecs
  77390. + * keep each qh use in qh->frame_usecs
  77391. + * when surrendering the qh then donate the time back
  77392. + */
  77393. +const unsigned short max_uframe_usecs[]={ 100, 100, 100, 100, 100, 100, 30, 0 };
  77394. +
  77395. +/*
  77396. + * called from dwc_otg_hcd.c:dwc_otg_hcd_init
  77397. + */
  77398. +int init_hcd_usecs(dwc_otg_hcd_t *_hcd)
  77399. +{
  77400. + int i;
  77401. + for (i=0; i<8; i++) {
  77402. + _hcd->frame_usecs[i] = max_uframe_usecs[i];
  77403. + }
  77404. + return 0;
  77405. +}
  77406. +
  77407. +static int find_single_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
  77408. +{
  77409. + int i;
  77410. + unsigned short utime;
  77411. + int t_left;
  77412. + int ret;
  77413. + int done;
  77414. +
  77415. + ret = -1;
  77416. + utime = _qh->usecs;
  77417. + t_left = utime;
  77418. + i = 0;
  77419. + done = 0;
  77420. + while (done == 0) {
  77421. + /* At the start _hcd->frame_usecs[i] = max_uframe_usecs[i]; */
  77422. + if (utime <= _hcd->frame_usecs[i]) {
  77423. + _hcd->frame_usecs[i] -= utime;
  77424. + _qh->frame_usecs[i] += utime;
  77425. + t_left -= utime;
  77426. + ret = i;
  77427. + done = 1;
  77428. + return ret;
  77429. + } else {
  77430. + i++;
  77431. + if (i == 8) {
  77432. + done = 1;
  77433. + ret = -1;
  77434. + }
  77435. + }
  77436. + }
  77437. + return ret;
  77438. + }
  77439. +
  77440. +/*
  77441. + * use this for FS apps that can span multiple uframes
  77442. + */
  77443. +static int find_multi_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
  77444. +{
  77445. + int i;
  77446. + int j;
  77447. + unsigned short utime;
  77448. + int t_left;
  77449. + int ret;
  77450. + int done;
  77451. + unsigned short xtime;
  77452. +
  77453. + ret = -1;
  77454. + utime = _qh->usecs;
  77455. + t_left = utime;
  77456. + i = 0;
  77457. + done = 0;
  77458. +loop:
  77459. + while (done == 0) {
  77460. + if(_hcd->frame_usecs[i] <= 0) {
  77461. + i++;
  77462. + if (i == 8) {
  77463. + done = 1;
  77464. + ret = -1;
  77465. + }
  77466. + goto loop;
  77467. + }
  77468. +
  77469. + /*
  77470. + * we need n consecutive slots
  77471. + * so use j as a start slot j plus j+1 must be enough time (for now)
  77472. + */
  77473. + xtime= _hcd->frame_usecs[i];
  77474. + for (j = i+1 ; j < 8 ; j++ ) {
  77475. + /*
  77476. + * if we add this frame remaining time to xtime we may
  77477. + * be OK, if not we need to test j for a complete frame
  77478. + */
  77479. + if ((xtime+_hcd->frame_usecs[j]) < utime) {
  77480. + if (_hcd->frame_usecs[j] < max_uframe_usecs[j]) {
  77481. + j = 8;
  77482. + ret = -1;
  77483. + continue;
  77484. + }
  77485. + }
  77486. + if (xtime >= utime) {
  77487. + ret = i;
  77488. + j = 8; /* stop loop with a good value ret */
  77489. + continue;
  77490. + }
  77491. + /* add the frame time to x time */
  77492. + xtime += _hcd->frame_usecs[j];
  77493. + /* we must have a fully available next frame or break */
  77494. + if ((xtime < utime)
  77495. + && (_hcd->frame_usecs[j] == max_uframe_usecs[j])) {
  77496. + ret = -1;
  77497. + j = 8; /* stop loop with a bad value ret */
  77498. + continue;
  77499. + }
  77500. + }
  77501. + if (ret >= 0) {
  77502. + t_left = utime;
  77503. + for (j = i; (t_left>0) && (j < 8); j++ ) {
  77504. + t_left -= _hcd->frame_usecs[j];
  77505. + if ( t_left <= 0 ) {
  77506. + _qh->frame_usecs[j] += _hcd->frame_usecs[j] + t_left;
  77507. + _hcd->frame_usecs[j]= -t_left;
  77508. + ret = i;
  77509. + done = 1;
  77510. + } else {
  77511. + _qh->frame_usecs[j] += _hcd->frame_usecs[j];
  77512. + _hcd->frame_usecs[j] = 0;
  77513. + }
  77514. + }
  77515. + } else {
  77516. + i++;
  77517. + if (i == 8) {
  77518. + done = 1;
  77519. + ret = -1;
  77520. + }
  77521. + }
  77522. + }
  77523. + return ret;
  77524. +}
  77525. +
  77526. +static int find_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
  77527. +{
  77528. + int ret;
  77529. + ret = -1;
  77530. +
  77531. + if (_qh->speed == USB_SPEED_HIGH) {
  77532. + /* if this is a hs transaction we need a full frame */
  77533. + ret = find_single_uframe(_hcd, _qh);
  77534. + } else {
  77535. + /* if this is a fs transaction we may need a sequence of frames */
  77536. + ret = find_multi_uframe(_hcd, _qh);
  77537. + }
  77538. + return ret;
  77539. +}
  77540. +
  77541. +/**
  77542. + * Checks that the max transfer size allowed in a host channel is large enough
  77543. + * to handle the maximum data transfer in a single (micro)frame for a periodic
  77544. + * transfer.
  77545. + *
  77546. + * @param hcd The HCD state structure for the DWC OTG controller.
  77547. + * @param qh QH for a periodic endpoint.
  77548. + *
  77549. + * @return 0 if successful, negative error code otherwise.
  77550. + */
  77551. +static int check_max_xfer_size(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  77552. +{
  77553. + int status;
  77554. + uint32_t max_xfer_size;
  77555. + uint32_t max_channel_xfer_size;
  77556. +
  77557. + status = 0;
  77558. +
  77559. + max_xfer_size = dwc_max_packet(qh->maxp) * dwc_hb_mult(qh->maxp);
  77560. + max_channel_xfer_size = hcd->core_if->core_params->max_transfer_size;
  77561. +
  77562. + if (max_xfer_size > max_channel_xfer_size) {
  77563. + DWC_INFO("%s: Periodic xfer length %d > " "max xfer length for channel %d\n",
  77564. + __func__, max_xfer_size, max_channel_xfer_size); //NOTICE
  77565. + status = -DWC_E_NO_SPACE;
  77566. + }
  77567. +
  77568. + return status;
  77569. +}
  77570. +
  77571. +
  77572. +extern int g_next_sched_frame, g_np_count, g_np_sent;
  77573. +
  77574. +/**
  77575. + * Schedules an interrupt or isochronous transfer in the periodic schedule.
  77576. + *
  77577. + * @param hcd The HCD state structure for the DWC OTG controller.
  77578. + * @param qh QH for the periodic transfer. The QH should already contain the
  77579. + * scheduling information.
  77580. + *
  77581. + * @return 0 if successful, negative error code otherwise.
  77582. + */
  77583. +static int schedule_periodic(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  77584. +{
  77585. + int status = 0;
  77586. +
  77587. + if (microframe_schedule) {
  77588. + int frame;
  77589. + status = find_uframe(hcd, qh);
  77590. + frame = -1;
  77591. + if (status == 0) {
  77592. + frame = 7;
  77593. + } else {
  77594. + if (status > 0 )
  77595. + frame = status-1;
  77596. + }
  77597. +
  77598. + /* Set the new frame up */
  77599. + if (frame > -1) {
  77600. + qh->sched_frame &= ~0x7;
  77601. + qh->sched_frame |= (frame & 7);
  77602. + }
  77603. +
  77604. + if (status != -1)
  77605. + status = 0;
  77606. + } else {
  77607. + status = periodic_channel_available(hcd);
  77608. + if (status) {
  77609. + DWC_INFO("%s: No host channel available for periodic " "transfer.\n", __func__); //NOTICE
  77610. + return status;
  77611. + }
  77612. +
  77613. + status = check_periodic_bandwidth(hcd, qh);
  77614. + }
  77615. + if (status) {
  77616. + DWC_INFO("%s: Insufficient periodic bandwidth for "
  77617. + "periodic transfer.\n", __func__);
  77618. + return status;
  77619. + }
  77620. + status = check_max_xfer_size(hcd, qh);
  77621. + if (status) {
  77622. + DWC_INFO("%s: Channel max transfer size too small "
  77623. + "for periodic transfer.\n", __func__);
  77624. + return status;
  77625. + }
  77626. +
  77627. + if (hcd->core_if->dma_desc_enable) {
  77628. + /* Don't rely on SOF and start in ready schedule */
  77629. + DWC_LIST_INSERT_TAIL(&hcd->periodic_sched_ready, &qh->qh_list_entry);
  77630. + }
  77631. + else {
  77632. + if(DWC_LIST_EMPTY(&hcd->periodic_sched_inactive) || dwc_frame_num_le(qh->sched_frame, g_next_sched_frame))
  77633. + {
  77634. + g_next_sched_frame = qh->sched_frame;
  77635. +
  77636. + }
  77637. + /* Always start in the inactive schedule. */
  77638. + DWC_LIST_INSERT_TAIL(&hcd->periodic_sched_inactive, &qh->qh_list_entry);
  77639. + }
  77640. +
  77641. + if (!microframe_schedule) {
  77642. + /* Reserve the periodic channel. */
  77643. + hcd->periodic_channels++;
  77644. + }
  77645. +
  77646. + /* Update claimed usecs per (micro)frame. */
  77647. + hcd->periodic_usecs += qh->usecs;
  77648. +
  77649. + return status;
  77650. +}
  77651. +
  77652. +
  77653. +/**
  77654. + * This function adds a QH to either the non periodic or periodic schedule if
  77655. + * it is not already in the schedule. If the QH is already in the schedule, no
  77656. + * action is taken.
  77657. + *
  77658. + * @return 0 if successful, negative error code otherwise.
  77659. + */
  77660. +int dwc_otg_hcd_qh_add(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  77661. +{
  77662. + int status = 0;
  77663. + gintmsk_data_t intr_mask = {.d32 = 0 };
  77664. +
  77665. + if (!DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  77666. + /* QH already in a schedule. */
  77667. + return status;
  77668. + }
  77669. +
  77670. + /* Add the new QH to the appropriate schedule */
  77671. + if (dwc_qh_is_non_per(qh)) {
  77672. + /* Always start in the inactive schedule. */
  77673. + DWC_LIST_INSERT_TAIL(&hcd->non_periodic_sched_inactive,
  77674. + &qh->qh_list_entry);
  77675. + g_np_count++;
  77676. + } else {
  77677. + status = schedule_periodic(hcd, qh);
  77678. + if ( !hcd->periodic_qh_count ) {
  77679. + intr_mask.b.sofintr = 1;
  77680. + DWC_MODIFY_REG32(&hcd->core_if->core_global_regs->gintmsk,
  77681. + intr_mask.d32, intr_mask.d32);
  77682. + }
  77683. + hcd->periodic_qh_count++;
  77684. + }
  77685. +
  77686. + return status;
  77687. +}
  77688. +
  77689. +/**
  77690. + * Removes an interrupt or isochronous transfer from the periodic schedule.
  77691. + *
  77692. + * @param hcd The HCD state structure for the DWC OTG controller.
  77693. + * @param qh QH for the periodic transfer.
  77694. + */
  77695. +static void deschedule_periodic(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  77696. +{
  77697. + int i;
  77698. + DWC_LIST_REMOVE_INIT(&qh->qh_list_entry);
  77699. +
  77700. + /* Update claimed usecs per (micro)frame. */
  77701. + hcd->periodic_usecs -= qh->usecs;
  77702. +
  77703. + if (!microframe_schedule) {
  77704. + /* Release the periodic channel reservation. */
  77705. + hcd->periodic_channels--;
  77706. + } else {
  77707. + for (i = 0; i < 8; i++) {
  77708. + hcd->frame_usecs[i] += qh->frame_usecs[i];
  77709. + qh->frame_usecs[i] = 0;
  77710. + }
  77711. + }
  77712. +}
  77713. +
  77714. +/**
  77715. + * Removes a QH from either the non-periodic or periodic schedule. Memory is
  77716. + * not freed.
  77717. + *
  77718. + * @param hcd The HCD state structure.
  77719. + * @param qh QH to remove from schedule. */
  77720. +void dwc_otg_hcd_qh_remove(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  77721. +{
  77722. + gintmsk_data_t intr_mask = {.d32 = 0 };
  77723. +
  77724. + if (DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  77725. + /* QH is not in a schedule. */
  77726. + return;
  77727. + }
  77728. +
  77729. + if (dwc_qh_is_non_per(qh)) {
  77730. + if (hcd->non_periodic_qh_ptr == &qh->qh_list_entry) {
  77731. + hcd->non_periodic_qh_ptr =
  77732. + hcd->non_periodic_qh_ptr->next;
  77733. + }
  77734. + DWC_LIST_REMOVE_INIT(&qh->qh_list_entry);
  77735. +
  77736. + // If we've removed the last non-periodic entry then there are none left!
  77737. + g_np_count = g_np_sent;
  77738. + } else {
  77739. + deschedule_periodic(hcd, qh);
  77740. + hcd->periodic_qh_count--;
  77741. + if( !hcd->periodic_qh_count ) {
  77742. + intr_mask.b.sofintr = 1;
  77743. + DWC_MODIFY_REG32(&hcd->core_if->core_global_regs->gintmsk,
  77744. + intr_mask.d32, 0);
  77745. + }
  77746. + }
  77747. +}
  77748. +
  77749. +/**
  77750. + * Deactivates a QH. For non-periodic QHs, removes the QH from the active
  77751. + * non-periodic schedule. The QH is added to the inactive non-periodic
  77752. + * schedule if any QTDs are still attached to the QH.
  77753. + *
  77754. + * For periodic QHs, the QH is removed from the periodic queued schedule. If
  77755. + * there are any QTDs still attached to the QH, the QH is added to either the
  77756. + * periodic inactive schedule or the periodic ready schedule and its next
  77757. + * scheduled frame is calculated. The QH is placed in the ready schedule if
  77758. + * the scheduled frame has been reached already. Otherwise it's placed in the
  77759. + * inactive schedule. If there are no QTDs attached to the QH, the QH is
  77760. + * completely removed from the periodic schedule.
  77761. + */
  77762. +void dwc_otg_hcd_qh_deactivate(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  77763. + int sched_next_periodic_split)
  77764. +{
  77765. + if (dwc_qh_is_non_per(qh)) {
  77766. +
  77767. + dwc_otg_qh_t *qh_tmp;
  77768. + dwc_list_link_t *qh_list;
  77769. + DWC_LIST_FOREACH(qh_list, &hcd->non_periodic_sched_inactive)
  77770. + {
  77771. + qh_tmp = DWC_LIST_ENTRY(qh_list, struct dwc_otg_qh, qh_list_entry);
  77772. + if(qh_tmp == qh)
  77773. + {
  77774. + /*
  77775. + * FIQ is being disabled because this one nevers gets a np_count increment
  77776. + * This is still not absolutely correct, but it should fix itself with
  77777. + * just an unnecessary extra interrupt
  77778. + */
  77779. + g_np_sent = g_np_count;
  77780. + }
  77781. + }
  77782. +
  77783. +
  77784. + dwc_otg_hcd_qh_remove(hcd, qh);
  77785. + if (!DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  77786. + /* Add back to inactive non-periodic schedule. */
  77787. + dwc_otg_hcd_qh_add(hcd, qh);
  77788. + }
  77789. + } else {
  77790. + uint16_t frame_number = dwc_otg_hcd_get_frame_number(hcd);
  77791. +
  77792. + if (qh->do_split) {
  77793. + /* Schedule the next continuing periodic split transfer */
  77794. + if (sched_next_periodic_split) {
  77795. +
  77796. + qh->sched_frame = frame_number;
  77797. +
  77798. + if (dwc_frame_num_le(frame_number,
  77799. + dwc_frame_num_inc
  77800. + (qh->start_split_frame,
  77801. + 1))) {
  77802. + /*
  77803. + * Allow one frame to elapse after start
  77804. + * split microframe before scheduling
  77805. + * complete split, but DONT if we are
  77806. + * doing the next start split in the
  77807. + * same frame for an ISOC out.
  77808. + */
  77809. + if ((qh->ep_type != UE_ISOCHRONOUS) ||
  77810. + (qh->ep_is_in != 0)) {
  77811. + qh->sched_frame =
  77812. + dwc_frame_num_inc(qh->sched_frame, 1);
  77813. + }
  77814. + }
  77815. + } else {
  77816. + qh->sched_frame =
  77817. + dwc_frame_num_inc(qh->start_split_frame,
  77818. + qh->interval);
  77819. + if (dwc_frame_num_le
  77820. + (qh->sched_frame, frame_number)) {
  77821. + qh->sched_frame = frame_number;
  77822. + }
  77823. + qh->sched_frame |= 0x7;
  77824. + qh->start_split_frame = qh->sched_frame;
  77825. + }
  77826. + } else {
  77827. + qh->sched_frame =
  77828. + dwc_frame_num_inc(qh->sched_frame, qh->interval);
  77829. + if (dwc_frame_num_le(qh->sched_frame, frame_number)) {
  77830. + qh->sched_frame = frame_number;
  77831. + }
  77832. + }
  77833. +
  77834. + if (DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  77835. + dwc_otg_hcd_qh_remove(hcd, qh);
  77836. + } else {
  77837. + /*
  77838. + * Remove from periodic_sched_queued and move to
  77839. + * appropriate queue.
  77840. + */
  77841. + if ((microframe_schedule && dwc_frame_num_le(qh->sched_frame, frame_number)) ||
  77842. + (!microframe_schedule && qh->sched_frame == frame_number)) {
  77843. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_ready,
  77844. + &qh->qh_list_entry);
  77845. + } else {
  77846. + if(!dwc_frame_num_le(g_next_sched_frame, qh->sched_frame))
  77847. + {
  77848. + g_next_sched_frame = qh->sched_frame;
  77849. + }
  77850. +
  77851. + DWC_LIST_MOVE_HEAD
  77852. + (&hcd->periodic_sched_inactive,
  77853. + &qh->qh_list_entry);
  77854. + }
  77855. + }
  77856. + }
  77857. +}
  77858. +
  77859. +/**
  77860. + * This function allocates and initializes a QTD.
  77861. + *
  77862. + * @param urb The URB to create a QTD from. Each URB-QTD pair will end up
  77863. + * pointing to each other so each pair should have a unique correlation.
  77864. + * @param atomic_alloc Flag to do atomic alloc if needed
  77865. + *
  77866. + * @return Returns pointer to the newly allocated QTD, or NULL on error. */
  77867. +dwc_otg_qtd_t *dwc_otg_hcd_qtd_create(dwc_otg_hcd_urb_t * urb, int atomic_alloc)
  77868. +{
  77869. + dwc_otg_qtd_t *qtd;
  77870. +
  77871. + qtd = dwc_otg_hcd_qtd_alloc(atomic_alloc);
  77872. + if (qtd == NULL) {
  77873. + return NULL;
  77874. + }
  77875. +
  77876. + dwc_otg_hcd_qtd_init(qtd, urb);
  77877. + return qtd;
  77878. +}
  77879. +
  77880. +/**
  77881. + * Initializes a QTD structure.
  77882. + *
  77883. + * @param qtd The QTD to initialize.
  77884. + * @param urb The URB to use for initialization. */
  77885. +void dwc_otg_hcd_qtd_init(dwc_otg_qtd_t * qtd, dwc_otg_hcd_urb_t * urb)
  77886. +{
  77887. + dwc_memset(qtd, 0, sizeof(dwc_otg_qtd_t));
  77888. + qtd->urb = urb;
  77889. + if (dwc_otg_hcd_get_pipe_type(&urb->pipe_info) == UE_CONTROL) {
  77890. + /*
  77891. + * The only time the QTD data toggle is used is on the data
  77892. + * phase of control transfers. This phase always starts with
  77893. + * DATA1.
  77894. + */
  77895. + qtd->data_toggle = DWC_OTG_HC_PID_DATA1;
  77896. + qtd->control_phase = DWC_OTG_CONTROL_SETUP;
  77897. + }
  77898. +
  77899. + /* start split */
  77900. + qtd->complete_split = 0;
  77901. + qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_ALL;
  77902. + qtd->isoc_split_offset = 0;
  77903. + qtd->in_process = 0;
  77904. +
  77905. + /* Store the qtd ptr in the urb to reference what QTD. */
  77906. + urb->qtd = qtd;
  77907. + return;
  77908. +}
  77909. +
  77910. +/**
  77911. + * This function adds a QTD to the QTD-list of a QH. It will find the correct
  77912. + * QH to place the QTD into. If it does not find a QH, then it will create a
  77913. + * new QH. If the QH to which the QTD is added is not currently scheduled, it
  77914. + * is placed into the proper schedule based on its EP type.
  77915. + * HCD lock must be held and interrupts must be disabled on entry
  77916. + *
  77917. + * @param[in] qtd The QTD to add
  77918. + * @param[in] hcd The DWC HCD structure
  77919. + * @param[out] qh out parameter to return queue head
  77920. + * @param atomic_alloc Flag to do atomic alloc if needed
  77921. + *
  77922. + * @return 0 if successful, negative error code otherwise.
  77923. + */
  77924. +int dwc_otg_hcd_qtd_add(dwc_otg_qtd_t * qtd,
  77925. + dwc_otg_hcd_t * hcd, dwc_otg_qh_t ** qh, int atomic_alloc)
  77926. +{
  77927. + int retval = 0;
  77928. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  77929. +
  77930. + /*
  77931. + * Get the QH which holds the QTD-list to insert to. Create QH if it
  77932. + * doesn't exist.
  77933. + */
  77934. + if (*qh == NULL) {
  77935. + *qh = dwc_otg_hcd_qh_create(hcd, urb, atomic_alloc);
  77936. + if (*qh == NULL) {
  77937. + retval = -DWC_E_NO_MEMORY;
  77938. + goto done;
  77939. + }
  77940. + }
  77941. + retval = dwc_otg_hcd_qh_add(hcd, *qh);
  77942. + if (retval == 0) {
  77943. + DWC_CIRCLEQ_INSERT_TAIL(&((*qh)->qtd_list), qtd,
  77944. + qtd_list_entry);
  77945. + qtd->qh = *qh;
  77946. + }
  77947. +done:
  77948. +
  77949. + return retval;
  77950. +}
  77951. +
  77952. +#endif /* DWC_DEVICE_ONLY */
  77953. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.c linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.c
  77954. --- linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.c 1970-01-01 01:00:00.000000000 +0100
  77955. +++ linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.c 2014-02-17 22:41:01.000000000 +0100
  77956. @@ -0,0 +1,113 @@
  77957. +#include "dwc_otg_regs.h"
  77958. +#include "dwc_otg_dbg.h"
  77959. +
  77960. +void dwc_debug_print_core_int_reg(gintsts_data_t gintsts, const char* function_name)
  77961. +{
  77962. + DWC_DEBUGPL(DBG_USER, "*** Debugging from within the %s function: ***\n"
  77963. + "curmode: %1i Modemismatch: %1i otgintr: %1i sofintr: %1i\n"
  77964. + "rxstsqlvl: %1i nptxfempty : %1i ginnakeff: %1i goutnakeff: %1i\n"
  77965. + "ulpickint: %1i i2cintr: %1i erlysuspend:%1i usbsuspend: %1i\n"
  77966. + "usbreset: %1i enumdone: %1i isooutdrop: %1i eopframe: %1i\n"
  77967. + "restoredone: %1i epmismatch: %1i inepint: %1i outepintr: %1i\n"
  77968. + "incomplisoin:%1i incomplisoout:%1i fetsusp: %1i resetdet: %1i\n"
  77969. + "portintr: %1i hcintr: %1i ptxfempty: %1i lpmtranrcvd:%1i\n"
  77970. + "conidstschng:%1i disconnect: %1i sessreqintr:%1i wkupintr: %1i\n",
  77971. + function_name,
  77972. + gintsts.b.curmode,
  77973. + gintsts.b.modemismatch,
  77974. + gintsts.b.otgintr,
  77975. + gintsts.b.sofintr,
  77976. + gintsts.b.rxstsqlvl,
  77977. + gintsts.b.nptxfempty,
  77978. + gintsts.b.ginnakeff,
  77979. + gintsts.b.goutnakeff,
  77980. + gintsts.b.ulpickint,
  77981. + gintsts.b.i2cintr,
  77982. + gintsts.b.erlysuspend,
  77983. + gintsts.b.usbsuspend,
  77984. + gintsts.b.usbreset,
  77985. + gintsts.b.enumdone,
  77986. + gintsts.b.isooutdrop,
  77987. + gintsts.b.eopframe,
  77988. + gintsts.b.restoredone,
  77989. + gintsts.b.epmismatch,
  77990. + gintsts.b.inepint,
  77991. + gintsts.b.outepintr,
  77992. + gintsts.b.incomplisoin,
  77993. + gintsts.b.incomplisoout,
  77994. + gintsts.b.fetsusp,
  77995. + gintsts.b.resetdet,
  77996. + gintsts.b.portintr,
  77997. + gintsts.b.hcintr,
  77998. + gintsts.b.ptxfempty,
  77999. + gintsts.b.lpmtranrcvd,
  78000. + gintsts.b.conidstschng,
  78001. + gintsts.b.disconnect,
  78002. + gintsts.b.sessreqintr,
  78003. + gintsts.b.wkupintr);
  78004. + return;
  78005. +}
  78006. +
  78007. +void dwc_debug_core_int_mask(gintmsk_data_t gintmsk, const char* function_name)
  78008. +{
  78009. + DWC_DEBUGPL(DBG_USER, "Interrupt Mask status (called from %s) :\n"
  78010. + "modemismatch: %1i otgintr: %1i sofintr: %1i rxstsqlvl: %1i\n"
  78011. + "nptxfempty: %1i ginnakeff: %1i goutnakeff: %1i ulpickint: %1i\n"
  78012. + "i2cintr: %1i erlysuspend:%1i usbsuspend: %1i usbreset: %1i\n"
  78013. + "enumdone: %1i isooutdrop: %1i eopframe: %1i restoredone: %1i\n"
  78014. + "epmismatch: %1i inepintr: %1i outepintr: %1i incomplisoin:%1i\n"
  78015. + "incomplisoout:%1i fetsusp: %1i resetdet: %1i portintr: %1i\n"
  78016. + "hcintr: %1i ptxfempty: %1i lpmtranrcvd:%1i conidstschng:%1i\n"
  78017. + "disconnect: %1i sessreqintr:%1i wkupintr: %1i\n",
  78018. + function_name,
  78019. + gintmsk.b.modemismatch,
  78020. + gintmsk.b.otgintr,
  78021. + gintmsk.b.sofintr,
  78022. + gintmsk.b.rxstsqlvl,
  78023. + gintmsk.b.nptxfempty,
  78024. + gintmsk.b.ginnakeff,
  78025. + gintmsk.b.goutnakeff,
  78026. + gintmsk.b.ulpickint,
  78027. + gintmsk.b.i2cintr,
  78028. + gintmsk.b.erlysuspend,
  78029. + gintmsk.b.usbsuspend,
  78030. + gintmsk.b.usbreset,
  78031. + gintmsk.b.enumdone,
  78032. + gintmsk.b.isooutdrop,
  78033. + gintmsk.b.eopframe,
  78034. + gintmsk.b.restoredone,
  78035. + gintmsk.b.epmismatch,
  78036. + gintmsk.b.inepintr,
  78037. + gintmsk.b.outepintr,
  78038. + gintmsk.b.incomplisoin,
  78039. + gintmsk.b.incomplisoout,
  78040. + gintmsk.b.fetsusp,
  78041. + gintmsk.b.resetdet,
  78042. + gintmsk.b.portintr,
  78043. + gintmsk.b.hcintr,
  78044. + gintmsk.b.ptxfempty,
  78045. + gintmsk.b.lpmtranrcvd,
  78046. + gintmsk.b.conidstschng,
  78047. + gintmsk.b.disconnect,
  78048. + gintmsk.b.sessreqintr,
  78049. + gintmsk.b.wkupintr);
  78050. + return;
  78051. +}
  78052. +
  78053. +void dwc_debug_otg_int(gotgint_data_t gotgint, const char* function_name)
  78054. +{
  78055. + DWC_DEBUGPL(DBG_USER, "otg int register (from %s function):\n"
  78056. + "sesenddet:%1i sesreqsucstschung:%2i hstnegsucstschng:%1i\n"
  78057. + "hstnegdet:%1i adevtoutchng: %2i debdone: %1i\n"
  78058. + "mvic: %1i\n",
  78059. + function_name,
  78060. + gotgint.b.sesenddet,
  78061. + gotgint.b.sesreqsucstschng,
  78062. + gotgint.b.hstnegsucstschng,
  78063. + gotgint.b.hstnegdet,
  78064. + gotgint.b.adevtoutchng,
  78065. + gotgint.b.debdone,
  78066. + gotgint.b.mvic);
  78067. +
  78068. + return;
  78069. +}
  78070. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.h linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.h
  78071. --- linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.h 1970-01-01 01:00:00.000000000 +0100
  78072. +++ linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.h 2014-02-17 22:41:01.000000000 +0100
  78073. @@ -0,0 +1,48 @@
  78074. +#ifndef __DWC_OTG_MPHI_FIX_H__
  78075. +#define __DWC_OTG_MPHI_FIX_H__
  78076. +#define FIQ_WRITE(_addr_,_data_) (*(volatile uint32_t *) (_addr_) = (_data_))
  78077. +#define FIQ_READ(_addr_) (*(volatile uint32_t *) (_addr_))
  78078. +
  78079. +typedef struct {
  78080. + volatile void* base;
  78081. + volatile void* ctrl;
  78082. + volatile void* outdda;
  78083. + volatile void* outddb;
  78084. + volatile void* intstat;
  78085. +} mphi_regs_t;
  78086. +
  78087. +void dwc_debug_print_core_int_reg(gintsts_data_t gintsts, const char* function_name);
  78088. +void dwc_debug_core_int_mask(gintsts_data_t gintmsk, const char* function_name);
  78089. +void dwc_debug_otg_int(gotgint_data_t gotgint, const char* function_name);
  78090. +
  78091. +extern gintsts_data_t gintsts_saved;
  78092. +
  78093. +#ifdef DEBUG
  78094. +#define DWC_DBG_PRINT_CORE_INT(_arg_) dwc_debug_print_core_int_reg(_arg_,__func__)
  78095. +#define DWC_DBG_PRINT_CORE_INT_MASK(_arg_) dwc_debug_core_int_mask(_arg_,__func__)
  78096. +#define DWC_DBG_PRINT_OTG_INT(_arg_) dwc_debug_otg_int(_arg_,__func__)
  78097. +
  78098. +#else
  78099. +#define DWC_DBG_PRINT_CORE_INT(_arg_)
  78100. +#define DWC_DBG_PRINT_CORE_INT_MASK(_arg_)
  78101. +#define DWC_DBG_PRINT_OTG_INT(_arg_)
  78102. +
  78103. +#endif
  78104. +
  78105. +typedef enum {
  78106. + FIQDBG_SCHED = (1 << 0),
  78107. + FIQDBG_INT = (1 << 1),
  78108. + FIQDBG_ERR = (1 << 2),
  78109. + FIQDBG_PORTHUB = (1 << 3),
  78110. +} FIQDBG_T;
  78111. +
  78112. +void _fiq_print(FIQDBG_T dbg_lvl, char *fmt, ...);
  78113. +#ifdef FIQ_DEBUG
  78114. +#define fiq_print _fiq_print
  78115. +#else
  78116. +#define fiq_print(x, y, ...)
  78117. +#endif
  78118. +
  78119. +extern bool fiq_fix_enable, nak_holdoff_enable, fiq_split_enable;
  78120. +
  78121. +#endif
  78122. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h
  78123. --- linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h 1970-01-01 01:00:00.000000000 +0100
  78124. +++ linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h 2014-02-17 22:41:01.000000000 +0100
  78125. @@ -0,0 +1,188 @@
  78126. +#ifndef _DWC_OS_DEP_H_
  78127. +#define _DWC_OS_DEP_H_
  78128. +
  78129. +/**
  78130. + * @file
  78131. + *
  78132. + * This file contains OS dependent structures.
  78133. + *
  78134. + */
  78135. +
  78136. +#include <linux/kernel.h>
  78137. +#include <linux/module.h>
  78138. +#include <linux/moduleparam.h>
  78139. +#include <linux/init.h>
  78140. +#include <linux/device.h>
  78141. +#include <linux/errno.h>
  78142. +#include <linux/types.h>
  78143. +#include <linux/slab.h>
  78144. +#include <linux/list.h>
  78145. +#include <linux/interrupt.h>
  78146. +#include <linux/ctype.h>
  78147. +#include <linux/string.h>
  78148. +#include <linux/dma-mapping.h>
  78149. +#include <linux/jiffies.h>
  78150. +#include <linux/delay.h>
  78151. +#include <linux/timer.h>
  78152. +#include <linux/workqueue.h>
  78153. +#include <linux/stat.h>
  78154. +#include <linux/pci.h>
  78155. +
  78156. +#include <linux/version.h>
  78157. +
  78158. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
  78159. +# include <linux/irq.h>
  78160. +#endif
  78161. +
  78162. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
  78163. +# include <linux/usb/ch9.h>
  78164. +#else
  78165. +# include <linux/usb_ch9.h>
  78166. +#endif
  78167. +
  78168. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
  78169. +# include <linux/usb/gadget.h>
  78170. +#else
  78171. +# include <linux/usb_gadget.h>
  78172. +#endif
  78173. +
  78174. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
  78175. +# include <asm/irq.h>
  78176. +#endif
  78177. +
  78178. +#ifdef PCI_INTERFACE
  78179. +# include <asm/io.h>
  78180. +#endif
  78181. +
  78182. +#ifdef LM_INTERFACE
  78183. +# include <asm/unaligned.h>
  78184. +# include <asm/sizes.h>
  78185. +# include <asm/param.h>
  78186. +# include <asm/io.h>
  78187. +# if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30))
  78188. +# include <asm/arch/hardware.h>
  78189. +# include <asm/arch/lm.h>
  78190. +# include <asm/arch/irqs.h>
  78191. +# include <asm/arch/regs-irq.h>
  78192. +# else
  78193. +/* in 2.6.31, at least, we seem to have lost the generic LM infrastructure -
  78194. + here we assume that the machine architecture provides definitions
  78195. + in its own header
  78196. +*/
  78197. +# include <mach/lm.h>
  78198. +# include <mach/hardware.h>
  78199. +# endif
  78200. +#endif
  78201. +
  78202. +#ifdef PLATFORM_INTERFACE
  78203. +#include <linux/platform_device.h>
  78204. +#include <asm/mach/map.h>
  78205. +#endif
  78206. +
  78207. +/** The OS page size */
  78208. +#define DWC_OS_PAGE_SIZE PAGE_SIZE
  78209. +
  78210. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
  78211. +typedef int gfp_t;
  78212. +#endif
  78213. +
  78214. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
  78215. +# define IRQF_SHARED SA_SHIRQ
  78216. +#endif
  78217. +
  78218. +typedef struct os_dependent {
  78219. + /** Base address returned from ioremap() */
  78220. + void *base;
  78221. +
  78222. + /** Register offset for Diagnostic API */
  78223. + uint32_t reg_offset;
  78224. +
  78225. + /** Base address for MPHI peripheral */
  78226. + void *mphi_base;
  78227. +
  78228. +#ifdef LM_INTERFACE
  78229. + struct lm_device *lmdev;
  78230. +#elif defined(PCI_INTERFACE)
  78231. + struct pci_dev *pcidev;
  78232. +
  78233. + /** Start address of a PCI region */
  78234. + resource_size_t rsrc_start;
  78235. +
  78236. + /** Length address of a PCI region */
  78237. + resource_size_t rsrc_len;
  78238. +#elif defined(PLATFORM_INTERFACE)
  78239. + struct platform_device *platformdev;
  78240. +#endif
  78241. +
  78242. +} os_dependent_t;
  78243. +
  78244. +#ifdef __cplusplus
  78245. +}
  78246. +#endif
  78247. +
  78248. +
  78249. +
  78250. +/* Type for the our device on the chosen bus */
  78251. +#if defined(LM_INTERFACE)
  78252. +typedef struct lm_device dwc_bus_dev_t;
  78253. +#elif defined(PCI_INTERFACE)
  78254. +typedef struct pci_dev dwc_bus_dev_t;
  78255. +#elif defined(PLATFORM_INTERFACE)
  78256. +typedef struct platform_device dwc_bus_dev_t;
  78257. +#endif
  78258. +
  78259. +/* Helper macro to retrieve drvdata from the device on the chosen bus */
  78260. +#if defined(LM_INTERFACE)
  78261. +#define DWC_OTG_BUSDRVDATA(_dev) lm_get_drvdata(_dev)
  78262. +#elif defined(PCI_INTERFACE)
  78263. +#define DWC_OTG_BUSDRVDATA(_dev) pci_get_drvdata(_dev)
  78264. +#elif defined(PLATFORM_INTERFACE)
  78265. +#define DWC_OTG_BUSDRVDATA(_dev) platform_get_drvdata(_dev)
  78266. +#endif
  78267. +
  78268. +/**
  78269. + * Helper macro returning the otg_device structure of a given struct device
  78270. + *
  78271. + * c.f. static dwc_otg_device_t *dwc_otg_drvdev(struct device *_dev)
  78272. + */
  78273. +#ifdef LM_INTERFACE
  78274. +#define DWC_OTG_GETDRVDEV(_var, _dev) do { \
  78275. + struct lm_device *lm_dev = \
  78276. + container_of(_dev, struct lm_device, dev); \
  78277. + _var = lm_get_drvdata(lm_dev); \
  78278. + } while (0)
  78279. +
  78280. +#elif defined(PCI_INTERFACE)
  78281. +#define DWC_OTG_GETDRVDEV(_var, _dev) do { \
  78282. + _var = dev_get_drvdata(_dev); \
  78283. + } while (0)
  78284. +
  78285. +#elif defined(PLATFORM_INTERFACE)
  78286. +#define DWC_OTG_GETDRVDEV(_var, _dev) do { \
  78287. + struct platform_device *platform_dev = \
  78288. + container_of(_dev, struct platform_device, dev); \
  78289. + _var = platform_get_drvdata(platform_dev); \
  78290. + } while (0)
  78291. +#endif
  78292. +
  78293. +
  78294. +/**
  78295. + * Helper macro returning the struct dev of the given struct os_dependent
  78296. + *
  78297. + * c.f. static struct device *dwc_otg_getdev(struct os_dependent *osdep)
  78298. + */
  78299. +#ifdef LM_INTERFACE
  78300. +#define DWC_OTG_OS_GETDEV(_osdep) \
  78301. + ((_osdep).lmdev == NULL? NULL: &(_osdep).lmdev->dev)
  78302. +#elif defined(PCI_INTERFACE)
  78303. +#define DWC_OTG_OS_GETDEV(_osdep) \
  78304. + ((_osdep).pci_dev == NULL? NULL: &(_osdep).pci_dev->dev)
  78305. +#elif defined(PLATFORM_INTERFACE)
  78306. +#define DWC_OTG_OS_GETDEV(_osdep) \
  78307. + ((_osdep).platformdev == NULL? NULL: &(_osdep).platformdev->dev)
  78308. +#endif
  78309. +
  78310. +
  78311. +
  78312. +
  78313. +#endif /* _DWC_OS_DEP_H_ */
  78314. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_pcd.c linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_pcd.c
  78315. --- linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_pcd.c 1970-01-01 01:00:00.000000000 +0100
  78316. +++ linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_pcd.c 2014-02-17 22:41:01.000000000 +0100
  78317. @@ -0,0 +1,2708 @@
  78318. +/* ==========================================================================
  78319. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd.c $
  78320. + * $Revision: #101 $
  78321. + * $Date: 2012/08/10 $
  78322. + * $Change: 2047372 $
  78323. + *
  78324. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  78325. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  78326. + * otherwise expressly agreed to in writing between Synopsys and you.
  78327. + *
  78328. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  78329. + * any End User Software License Agreement or Agreement for Licensed Product
  78330. + * with Synopsys or any supplement thereto. You are permitted to use and
  78331. + * redistribute this Software in source and binary forms, with or without
  78332. + * modification, provided that redistributions of source code must retain this
  78333. + * notice. You may not view, use, disclose, copy or distribute this file or
  78334. + * any information contained herein except pursuant to this license grant from
  78335. + * Synopsys. If you do not agree with this notice, including the disclaimer
  78336. + * below, then you are not authorized to use the Software.
  78337. + *
  78338. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  78339. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  78340. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  78341. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  78342. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  78343. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  78344. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  78345. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  78346. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  78347. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  78348. + * DAMAGE.
  78349. + * ========================================================================== */
  78350. +#ifndef DWC_HOST_ONLY
  78351. +
  78352. +/** @file
  78353. + * This file implements PCD Core. All code in this file is portable and doesn't
  78354. + * use any OS specific functions.
  78355. + * PCD Core provides Interface, defined in <code><dwc_otg_pcd_if.h></code>
  78356. + * header file, which can be used to implement OS specific PCD interface.
  78357. + *
  78358. + * An important function of the PCD is managing interrupts generated
  78359. + * by the DWC_otg controller. The implementation of the DWC_otg device
  78360. + * mode interrupt service routines is in dwc_otg_pcd_intr.c.
  78361. + *
  78362. + * @todo Add Device Mode test modes (Test J mode, Test K mode, etc).
  78363. + * @todo Does it work when the request size is greater than DEPTSIZ
  78364. + * transfer size
  78365. + *
  78366. + */
  78367. +
  78368. +#include "dwc_otg_pcd.h"
  78369. +
  78370. +#ifdef DWC_UTE_CFI
  78371. +#include "dwc_otg_cfi.h"
  78372. +
  78373. +extern int init_cfi(cfiobject_t * cfiobj);
  78374. +#endif
  78375. +
  78376. +/**
  78377. + * Choose endpoint from ep arrays using usb_ep structure.
  78378. + */
  78379. +static dwc_otg_pcd_ep_t *get_ep_from_handle(dwc_otg_pcd_t * pcd, void *handle)
  78380. +{
  78381. + int i;
  78382. + if (pcd->ep0.priv == handle) {
  78383. + return &pcd->ep0;
  78384. + }
  78385. + for (i = 0; i < MAX_EPS_CHANNELS - 1; i++) {
  78386. + if (pcd->in_ep[i].priv == handle)
  78387. + return &pcd->in_ep[i];
  78388. + if (pcd->out_ep[i].priv == handle)
  78389. + return &pcd->out_ep[i];
  78390. + }
  78391. +
  78392. + return NULL;
  78393. +}
  78394. +
  78395. +/**
  78396. + * This function completes a request. It call's the request call back.
  78397. + */
  78398. +void dwc_otg_request_done(dwc_otg_pcd_ep_t * ep, dwc_otg_pcd_request_t * req,
  78399. + int32_t status)
  78400. +{
  78401. + unsigned stopped = ep->stopped;
  78402. +
  78403. + DWC_DEBUGPL(DBG_PCDV, "%s(ep %p req %p)\n", __func__, ep, req);
  78404. + DWC_CIRCLEQ_REMOVE_INIT(&ep->queue, req, queue_entry);
  78405. +
  78406. + /* don't modify queue heads during completion callback */
  78407. + ep->stopped = 1;
  78408. + /* spin_unlock/spin_lock now done in fops->complete() */
  78409. + ep->pcd->fops->complete(ep->pcd, ep->priv, req->priv, status,
  78410. + req->actual);
  78411. +
  78412. + if (ep->pcd->request_pending > 0) {
  78413. + --ep->pcd->request_pending;
  78414. + }
  78415. +
  78416. + ep->stopped = stopped;
  78417. + DWC_FREE(req);
  78418. +}
  78419. +
  78420. +/**
  78421. + * This function terminates all the requsts in the EP request queue.
  78422. + */
  78423. +void dwc_otg_request_nuke(dwc_otg_pcd_ep_t * ep)
  78424. +{
  78425. + dwc_otg_pcd_request_t *req;
  78426. +
  78427. + ep->stopped = 1;
  78428. +
  78429. + /* called with irqs blocked?? */
  78430. + while (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  78431. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  78432. + dwc_otg_request_done(ep, req, -DWC_E_SHUTDOWN);
  78433. + }
  78434. +}
  78435. +
  78436. +void dwc_otg_pcd_start(dwc_otg_pcd_t * pcd,
  78437. + const struct dwc_otg_pcd_function_ops *fops)
  78438. +{
  78439. + pcd->fops = fops;
  78440. +}
  78441. +
  78442. +/**
  78443. + * PCD Callback function for initializing the PCD when switching to
  78444. + * device mode.
  78445. + *
  78446. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  78447. + */
  78448. +static int32_t dwc_otg_pcd_start_cb(void *p)
  78449. +{
  78450. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  78451. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  78452. +
  78453. + /*
  78454. + * Initialized the Core for Device mode.
  78455. + */
  78456. + if (dwc_otg_is_device_mode(core_if)) {
  78457. + dwc_otg_core_dev_init(core_if);
  78458. + /* Set core_if's lock pointer to the pcd->lock */
  78459. + core_if->lock = pcd->lock;
  78460. + }
  78461. + return 1;
  78462. +}
  78463. +
  78464. +/** CFI-specific buffer allocation function for EP */
  78465. +#ifdef DWC_UTE_CFI
  78466. +uint8_t *cfiw_ep_alloc_buffer(dwc_otg_pcd_t * pcd, void *pep, dwc_dma_t * addr,
  78467. + size_t buflen, int flags)
  78468. +{
  78469. + dwc_otg_pcd_ep_t *ep;
  78470. + ep = get_ep_from_handle(pcd, pep);
  78471. + if (!ep) {
  78472. + DWC_WARN("bad ep\n");
  78473. + return -DWC_E_INVALID;
  78474. + }
  78475. +
  78476. + return pcd->cfi->ops.ep_alloc_buf(pcd->cfi, pcd, ep, addr, buflen,
  78477. + flags);
  78478. +}
  78479. +#else
  78480. +uint8_t *cfiw_ep_alloc_buffer(dwc_otg_pcd_t * pcd, void *pep, dwc_dma_t * addr,
  78481. + size_t buflen, int flags);
  78482. +#endif
  78483. +
  78484. +/**
  78485. + * PCD Callback function for notifying the PCD when resuming from
  78486. + * suspend.
  78487. + *
  78488. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  78489. + */
  78490. +static int32_t dwc_otg_pcd_resume_cb(void *p)
  78491. +{
  78492. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  78493. +
  78494. + if (pcd->fops->resume) {
  78495. + pcd->fops->resume(pcd);
  78496. + }
  78497. +
  78498. + /* Stop the SRP timeout timer. */
  78499. + if ((GET_CORE_IF(pcd)->core_params->phy_type != DWC_PHY_TYPE_PARAM_FS)
  78500. + || (!GET_CORE_IF(pcd)->core_params->i2c_enable)) {
  78501. + if (GET_CORE_IF(pcd)->srp_timer_started) {
  78502. + GET_CORE_IF(pcd)->srp_timer_started = 0;
  78503. + DWC_TIMER_CANCEL(GET_CORE_IF(pcd)->srp_timer);
  78504. + }
  78505. + }
  78506. + return 1;
  78507. +}
  78508. +
  78509. +/**
  78510. + * PCD Callback function for notifying the PCD device is suspended.
  78511. + *
  78512. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  78513. + */
  78514. +static int32_t dwc_otg_pcd_suspend_cb(void *p)
  78515. +{
  78516. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  78517. +
  78518. + if (pcd->fops->suspend) {
  78519. + DWC_SPINUNLOCK(pcd->lock);
  78520. + pcd->fops->suspend(pcd);
  78521. + DWC_SPINLOCK(pcd->lock);
  78522. + }
  78523. +
  78524. + return 1;
  78525. +}
  78526. +
  78527. +/**
  78528. + * PCD Callback function for stopping the PCD when switching to Host
  78529. + * mode.
  78530. + *
  78531. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  78532. + */
  78533. +static int32_t dwc_otg_pcd_stop_cb(void *p)
  78534. +{
  78535. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  78536. + extern void dwc_otg_pcd_stop(dwc_otg_pcd_t * _pcd);
  78537. +
  78538. + dwc_otg_pcd_stop(pcd);
  78539. + return 1;
  78540. +}
  78541. +
  78542. +/**
  78543. + * PCD Callback structure for handling mode switching.
  78544. + */
  78545. +static dwc_otg_cil_callbacks_t pcd_callbacks = {
  78546. + .start = dwc_otg_pcd_start_cb,
  78547. + .stop = dwc_otg_pcd_stop_cb,
  78548. + .suspend = dwc_otg_pcd_suspend_cb,
  78549. + .resume_wakeup = dwc_otg_pcd_resume_cb,
  78550. + .p = 0, /* Set at registration */
  78551. +};
  78552. +
  78553. +/**
  78554. + * This function allocates a DMA Descriptor chain for the Endpoint
  78555. + * buffer to be used for a transfer to/from the specified endpoint.
  78556. + */
  78557. +dwc_otg_dev_dma_desc_t *dwc_otg_ep_alloc_desc_chain(dwc_dma_t * dma_desc_addr,
  78558. + uint32_t count)
  78559. +{
  78560. + return DWC_DMA_ALLOC_ATOMIC(count * sizeof(dwc_otg_dev_dma_desc_t),
  78561. + dma_desc_addr);
  78562. +}
  78563. +
  78564. +/**
  78565. + * This function frees a DMA Descriptor chain that was allocated by ep_alloc_desc.
  78566. + */
  78567. +void dwc_otg_ep_free_desc_chain(dwc_otg_dev_dma_desc_t * desc_addr,
  78568. + uint32_t dma_desc_addr, uint32_t count)
  78569. +{
  78570. + DWC_DMA_FREE(count * sizeof(dwc_otg_dev_dma_desc_t), desc_addr,
  78571. + dma_desc_addr);
  78572. +}
  78573. +
  78574. +#ifdef DWC_EN_ISOC
  78575. +
  78576. +/**
  78577. + * This function initializes a descriptor chain for Isochronous transfer
  78578. + *
  78579. + * @param core_if Programming view of DWC_otg controller.
  78580. + * @param dwc_ep The EP to start the transfer on.
  78581. + *
  78582. + */
  78583. +void dwc_otg_iso_ep_start_ddma_transfer(dwc_otg_core_if_t * core_if,
  78584. + dwc_ep_t * dwc_ep)
  78585. +{
  78586. +
  78587. + dsts_data_t dsts = {.d32 = 0 };
  78588. + depctl_data_t depctl = {.d32 = 0 };
  78589. + volatile uint32_t *addr;
  78590. + int i, j;
  78591. + uint32_t len;
  78592. +
  78593. + if (dwc_ep->is_in)
  78594. + dwc_ep->desc_cnt = dwc_ep->buf_proc_intrvl / dwc_ep->bInterval;
  78595. + else
  78596. + dwc_ep->desc_cnt =
  78597. + dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm /
  78598. + dwc_ep->bInterval;
  78599. +
  78600. + /** Allocate descriptors for double buffering */
  78601. + dwc_ep->iso_desc_addr =
  78602. + dwc_otg_ep_alloc_desc_chain(&dwc_ep->iso_dma_desc_addr,
  78603. + dwc_ep->desc_cnt * 2);
  78604. + if (dwc_ep->desc_addr) {
  78605. + DWC_WARN("%s, can't allocate DMA descriptor chain\n", __func__);
  78606. + return;
  78607. + }
  78608. +
  78609. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  78610. +
  78611. + /** ISO OUT EP */
  78612. + if (dwc_ep->is_in == 0) {
  78613. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  78614. + dwc_otg_dev_dma_desc_t *dma_desc = dwc_ep->iso_desc_addr;
  78615. + dma_addr_t dma_ad;
  78616. + uint32_t data_per_desc;
  78617. + dwc_otg_dev_out_ep_regs_t *out_regs =
  78618. + core_if->dev_if->out_ep_regs[dwc_ep->num];
  78619. + int offset;
  78620. +
  78621. + addr = &core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl;
  78622. + dma_ad = (dma_addr_t) DWC_READ_REG32(&(out_regs->doepdma));
  78623. +
  78624. + /** Buffer 0 descriptors setup */
  78625. + dma_ad = dwc_ep->dma_addr0;
  78626. +
  78627. + sts.b_iso_out.bs = BS_HOST_READY;
  78628. + sts.b_iso_out.rxsts = 0;
  78629. + sts.b_iso_out.l = 0;
  78630. + sts.b_iso_out.sp = 0;
  78631. + sts.b_iso_out.ioc = 0;
  78632. + sts.b_iso_out.pid = 0;
  78633. + sts.b_iso_out.framenum = 0;
  78634. +
  78635. + offset = 0;
  78636. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  78637. + i += dwc_ep->pkt_per_frm) {
  78638. +
  78639. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  78640. + uint32_t len = (j + 1) * dwc_ep->maxpacket;
  78641. + if (len > dwc_ep->data_per_frame)
  78642. + data_per_desc =
  78643. + dwc_ep->data_per_frame -
  78644. + j * dwc_ep->maxpacket;
  78645. + else
  78646. + data_per_desc = dwc_ep->maxpacket;
  78647. + len = data_per_desc % 4;
  78648. + if (len)
  78649. + data_per_desc += 4 - len;
  78650. +
  78651. + sts.b_iso_out.rxbytes = data_per_desc;
  78652. + dma_desc->buf = dma_ad;
  78653. + dma_desc->status.d32 = sts.d32;
  78654. +
  78655. + offset += data_per_desc;
  78656. + dma_desc++;
  78657. + dma_ad += data_per_desc;
  78658. + }
  78659. + }
  78660. +
  78661. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  78662. + uint32_t len = (j + 1) * dwc_ep->maxpacket;
  78663. + if (len > dwc_ep->data_per_frame)
  78664. + data_per_desc =
  78665. + dwc_ep->data_per_frame -
  78666. + j * dwc_ep->maxpacket;
  78667. + else
  78668. + data_per_desc = dwc_ep->maxpacket;
  78669. + len = data_per_desc % 4;
  78670. + if (len)
  78671. + data_per_desc += 4 - len;
  78672. + sts.b_iso_out.rxbytes = data_per_desc;
  78673. + dma_desc->buf = dma_ad;
  78674. + dma_desc->status.d32 = sts.d32;
  78675. +
  78676. + offset += data_per_desc;
  78677. + dma_desc++;
  78678. + dma_ad += data_per_desc;
  78679. + }
  78680. +
  78681. + sts.b_iso_out.ioc = 1;
  78682. + len = (j + 1) * dwc_ep->maxpacket;
  78683. + if (len > dwc_ep->data_per_frame)
  78684. + data_per_desc =
  78685. + dwc_ep->data_per_frame - j * dwc_ep->maxpacket;
  78686. + else
  78687. + data_per_desc = dwc_ep->maxpacket;
  78688. + len = data_per_desc % 4;
  78689. + if (len)
  78690. + data_per_desc += 4 - len;
  78691. + sts.b_iso_out.rxbytes = data_per_desc;
  78692. +
  78693. + dma_desc->buf = dma_ad;
  78694. + dma_desc->status.d32 = sts.d32;
  78695. + dma_desc++;
  78696. +
  78697. + /** Buffer 1 descriptors setup */
  78698. + sts.b_iso_out.ioc = 0;
  78699. + dma_ad = dwc_ep->dma_addr1;
  78700. +
  78701. + offset = 0;
  78702. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  78703. + i += dwc_ep->pkt_per_frm) {
  78704. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  78705. + uint32_t len = (j + 1) * dwc_ep->maxpacket;
  78706. + if (len > dwc_ep->data_per_frame)
  78707. + data_per_desc =
  78708. + dwc_ep->data_per_frame -
  78709. + j * dwc_ep->maxpacket;
  78710. + else
  78711. + data_per_desc = dwc_ep->maxpacket;
  78712. + len = data_per_desc % 4;
  78713. + if (len)
  78714. + data_per_desc += 4 - len;
  78715. +
  78716. + data_per_desc =
  78717. + sts.b_iso_out.rxbytes = data_per_desc;
  78718. + dma_desc->buf = dma_ad;
  78719. + dma_desc->status.d32 = sts.d32;
  78720. +
  78721. + offset += data_per_desc;
  78722. + dma_desc++;
  78723. + dma_ad += data_per_desc;
  78724. + }
  78725. + }
  78726. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  78727. + data_per_desc =
  78728. + ((j + 1) * dwc_ep->maxpacket >
  78729. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  78730. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  78731. + data_per_desc +=
  78732. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  78733. + sts.b_iso_out.rxbytes = data_per_desc;
  78734. + dma_desc->buf = dma_ad;
  78735. + dma_desc->status.d32 = sts.d32;
  78736. +
  78737. + offset += data_per_desc;
  78738. + dma_desc++;
  78739. + dma_ad += data_per_desc;
  78740. + }
  78741. +
  78742. + sts.b_iso_out.ioc = 1;
  78743. + sts.b_iso_out.l = 1;
  78744. + data_per_desc =
  78745. + ((j + 1) * dwc_ep->maxpacket >
  78746. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  78747. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  78748. + data_per_desc +=
  78749. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  78750. + sts.b_iso_out.rxbytes = data_per_desc;
  78751. +
  78752. + dma_desc->buf = dma_ad;
  78753. + dma_desc->status.d32 = sts.d32;
  78754. +
  78755. + dwc_ep->next_frame = 0;
  78756. +
  78757. + /** Write dma_ad into DOEPDMA register */
  78758. + DWC_WRITE_REG32(&(out_regs->doepdma),
  78759. + (uint32_t) dwc_ep->iso_dma_desc_addr);
  78760. +
  78761. + }
  78762. + /** ISO IN EP */
  78763. + else {
  78764. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  78765. + dwc_otg_dev_dma_desc_t *dma_desc = dwc_ep->iso_desc_addr;
  78766. + dma_addr_t dma_ad;
  78767. + dwc_otg_dev_in_ep_regs_t *in_regs =
  78768. + core_if->dev_if->in_ep_regs[dwc_ep->num];
  78769. + unsigned int frmnumber;
  78770. + fifosize_data_t txfifosize, rxfifosize;
  78771. +
  78772. + txfifosize.d32 =
  78773. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[dwc_ep->num]->
  78774. + dtxfsts);
  78775. + rxfifosize.d32 =
  78776. + DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  78777. +
  78778. + addr = &core_if->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  78779. +
  78780. + dma_ad = dwc_ep->dma_addr0;
  78781. +
  78782. + dsts.d32 =
  78783. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  78784. +
  78785. + sts.b_iso_in.bs = BS_HOST_READY;
  78786. + sts.b_iso_in.txsts = 0;
  78787. + sts.b_iso_in.sp =
  78788. + (dwc_ep->data_per_frame % dwc_ep->maxpacket) ? 1 : 0;
  78789. + sts.b_iso_in.ioc = 0;
  78790. + sts.b_iso_in.pid = dwc_ep->pkt_per_frm;
  78791. +
  78792. + frmnumber = dwc_ep->next_frame;
  78793. +
  78794. + sts.b_iso_in.framenum = frmnumber;
  78795. + sts.b_iso_in.txbytes = dwc_ep->data_per_frame;
  78796. + sts.b_iso_in.l = 0;
  78797. +
  78798. + /** Buffer 0 descriptors setup */
  78799. + for (i = 0; i < dwc_ep->desc_cnt - 1; i++) {
  78800. + dma_desc->buf = dma_ad;
  78801. + dma_desc->status.d32 = sts.d32;
  78802. + dma_desc++;
  78803. +
  78804. + dma_ad += dwc_ep->data_per_frame;
  78805. + sts.b_iso_in.framenum += dwc_ep->bInterval;
  78806. + }
  78807. +
  78808. + sts.b_iso_in.ioc = 1;
  78809. + dma_desc->buf = dma_ad;
  78810. + dma_desc->status.d32 = sts.d32;
  78811. + ++dma_desc;
  78812. +
  78813. + /** Buffer 1 descriptors setup */
  78814. + sts.b_iso_in.ioc = 0;
  78815. + dma_ad = dwc_ep->dma_addr1;
  78816. +
  78817. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  78818. + i += dwc_ep->pkt_per_frm) {
  78819. + dma_desc->buf = dma_ad;
  78820. + dma_desc->status.d32 = sts.d32;
  78821. + dma_desc++;
  78822. +
  78823. + dma_ad += dwc_ep->data_per_frame;
  78824. + sts.b_iso_in.framenum += dwc_ep->bInterval;
  78825. +
  78826. + sts.b_iso_in.ioc = 0;
  78827. + }
  78828. + sts.b_iso_in.ioc = 1;
  78829. + sts.b_iso_in.l = 1;
  78830. +
  78831. + dma_desc->buf = dma_ad;
  78832. + dma_desc->status.d32 = sts.d32;
  78833. +
  78834. + dwc_ep->next_frame = sts.b_iso_in.framenum + dwc_ep->bInterval;
  78835. +
  78836. + /** Write dma_ad into diepdma register */
  78837. + DWC_WRITE_REG32(&(in_regs->diepdma),
  78838. + (uint32_t) dwc_ep->iso_dma_desc_addr);
  78839. + }
  78840. + /** Enable endpoint, clear nak */
  78841. + depctl.d32 = 0;
  78842. + depctl.b.epena = 1;
  78843. + depctl.b.usbactep = 1;
  78844. + depctl.b.cnak = 1;
  78845. +
  78846. + DWC_MODIFY_REG32(addr, depctl.d32, depctl.d32);
  78847. + depctl.d32 = DWC_READ_REG32(addr);
  78848. +}
  78849. +
  78850. +/**
  78851. + * This function initializes a descriptor chain for Isochronous transfer
  78852. + *
  78853. + * @param core_if Programming view of DWC_otg controller.
  78854. + * @param ep The EP to start the transfer on.
  78855. + *
  78856. + */
  78857. +void dwc_otg_iso_ep_start_buf_transfer(dwc_otg_core_if_t * core_if,
  78858. + dwc_ep_t * ep)
  78859. +{
  78860. + depctl_data_t depctl = {.d32 = 0 };
  78861. + volatile uint32_t *addr;
  78862. +
  78863. + if (ep->is_in) {
  78864. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  78865. + } else {
  78866. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  78867. + }
  78868. +
  78869. + if (core_if->dma_enable == 0 || core_if->dma_desc_enable != 0) {
  78870. + return;
  78871. + } else {
  78872. + deptsiz_data_t deptsiz = {.d32 = 0 };
  78873. +
  78874. + ep->xfer_len =
  78875. + ep->data_per_frame * ep->buf_proc_intrvl / ep->bInterval;
  78876. + ep->pkt_cnt =
  78877. + (ep->xfer_len - 1 + ep->maxpacket) / ep->maxpacket;
  78878. + ep->xfer_count = 0;
  78879. + ep->xfer_buff =
  78880. + (ep->proc_buf_num) ? ep->xfer_buff1 : ep->xfer_buff0;
  78881. + ep->dma_addr =
  78882. + (ep->proc_buf_num) ? ep->dma_addr1 : ep->dma_addr0;
  78883. +
  78884. + if (ep->is_in) {
  78885. + /* Program the transfer size and packet count
  78886. + * as follows: xfersize = N * maxpacket +
  78887. + * short_packet pktcnt = N + (short_packet
  78888. + * exist ? 1 : 0)
  78889. + */
  78890. + deptsiz.b.mc = ep->pkt_per_frm;
  78891. + deptsiz.b.xfersize = ep->xfer_len;
  78892. + deptsiz.b.pktcnt =
  78893. + (ep->xfer_len - 1 + ep->maxpacket) / ep->maxpacket;
  78894. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  78895. + dieptsiz, deptsiz.d32);
  78896. +
  78897. + /* Write the DMA register */
  78898. + DWC_WRITE_REG32(&
  78899. + (core_if->dev_if->in_ep_regs[ep->num]->
  78900. + diepdma), (uint32_t) ep->dma_addr);
  78901. +
  78902. + } else {
  78903. + deptsiz.b.pktcnt =
  78904. + (ep->xfer_len + (ep->maxpacket - 1)) /
  78905. + ep->maxpacket;
  78906. + deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
  78907. +
  78908. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[ep->num]->
  78909. + doeptsiz, deptsiz.d32);
  78910. +
  78911. + /* Write the DMA register */
  78912. + DWC_WRITE_REG32(&
  78913. + (core_if->dev_if->out_ep_regs[ep->num]->
  78914. + doepdma), (uint32_t) ep->dma_addr);
  78915. +
  78916. + }
  78917. + /** Enable endpoint, clear nak */
  78918. + depctl.d32 = 0;
  78919. + depctl.b.epena = 1;
  78920. + depctl.b.cnak = 1;
  78921. +
  78922. + DWC_MODIFY_REG32(addr, depctl.d32, depctl.d32);
  78923. + }
  78924. +}
  78925. +
  78926. +/**
  78927. + * This function does the setup for a data transfer for an EP and
  78928. + * starts the transfer. For an IN transfer, the packets will be
  78929. + * loaded into the appropriate Tx FIFO in the ISR. For OUT transfers,
  78930. + * the packets are unloaded from the Rx FIFO in the ISR.
  78931. + *
  78932. + * @param core_if Programming view of DWC_otg controller.
  78933. + * @param ep The EP to start the transfer on.
  78934. + */
  78935. +
  78936. +static void dwc_otg_iso_ep_start_transfer(dwc_otg_core_if_t * core_if,
  78937. + dwc_ep_t * ep)
  78938. +{
  78939. + if (core_if->dma_enable) {
  78940. + if (core_if->dma_desc_enable) {
  78941. + if (ep->is_in) {
  78942. + ep->desc_cnt = ep->pkt_cnt / ep->pkt_per_frm;
  78943. + } else {
  78944. + ep->desc_cnt = ep->pkt_cnt;
  78945. + }
  78946. + dwc_otg_iso_ep_start_ddma_transfer(core_if, ep);
  78947. + } else {
  78948. + if (core_if->pti_enh_enable) {
  78949. + dwc_otg_iso_ep_start_buf_transfer(core_if, ep);
  78950. + } else {
  78951. + ep->cur_pkt_addr =
  78952. + (ep->proc_buf_num) ? ep->xfer_buff1 : ep->
  78953. + xfer_buff0;
  78954. + ep->cur_pkt_dma_addr =
  78955. + (ep->proc_buf_num) ? ep->dma_addr1 : ep->
  78956. + dma_addr0;
  78957. + dwc_otg_iso_ep_start_frm_transfer(core_if, ep);
  78958. + }
  78959. + }
  78960. + } else {
  78961. + ep->cur_pkt_addr =
  78962. + (ep->proc_buf_num) ? ep->xfer_buff1 : ep->xfer_buff0;
  78963. + ep->cur_pkt_dma_addr =
  78964. + (ep->proc_buf_num) ? ep->dma_addr1 : ep->dma_addr0;
  78965. + dwc_otg_iso_ep_start_frm_transfer(core_if, ep);
  78966. + }
  78967. +}
  78968. +
  78969. +/**
  78970. + * This function stops transfer for an EP and
  78971. + * resets the ep's variables.
  78972. + *
  78973. + * @param core_if Programming view of DWC_otg controller.
  78974. + * @param ep The EP to start the transfer on.
  78975. + */
  78976. +
  78977. +void dwc_otg_iso_ep_stop_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  78978. +{
  78979. + depctl_data_t depctl = {.d32 = 0 };
  78980. + volatile uint32_t *addr;
  78981. +
  78982. + if (ep->is_in == 1) {
  78983. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  78984. + } else {
  78985. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  78986. + }
  78987. +
  78988. + /* disable the ep */
  78989. + depctl.d32 = DWC_READ_REG32(addr);
  78990. +
  78991. + depctl.b.epdis = 1;
  78992. + depctl.b.snak = 1;
  78993. +
  78994. + DWC_WRITE_REG32(addr, depctl.d32);
  78995. +
  78996. + if (core_if->dma_desc_enable &&
  78997. + ep->iso_desc_addr && ep->iso_dma_desc_addr) {
  78998. + dwc_otg_ep_free_desc_chain(ep->iso_desc_addr,
  78999. + ep->iso_dma_desc_addr,
  79000. + ep->desc_cnt * 2);
  79001. + }
  79002. +
  79003. + /* reset varibales */
  79004. + ep->dma_addr0 = 0;
  79005. + ep->dma_addr1 = 0;
  79006. + ep->xfer_buff0 = 0;
  79007. + ep->xfer_buff1 = 0;
  79008. + ep->data_per_frame = 0;
  79009. + ep->data_pattern_frame = 0;
  79010. + ep->sync_frame = 0;
  79011. + ep->buf_proc_intrvl = 0;
  79012. + ep->bInterval = 0;
  79013. + ep->proc_buf_num = 0;
  79014. + ep->pkt_per_frm = 0;
  79015. + ep->pkt_per_frm = 0;
  79016. + ep->desc_cnt = 0;
  79017. + ep->iso_desc_addr = 0;
  79018. + ep->iso_dma_desc_addr = 0;
  79019. +}
  79020. +
  79021. +int dwc_otg_pcd_iso_ep_start(dwc_otg_pcd_t * pcd, void *ep_handle,
  79022. + uint8_t * buf0, uint8_t * buf1, dwc_dma_t dma0,
  79023. + dwc_dma_t dma1, int sync_frame, int dp_frame,
  79024. + int data_per_frame, int start_frame,
  79025. + int buf_proc_intrvl, void *req_handle,
  79026. + int atomic_alloc)
  79027. +{
  79028. + dwc_otg_pcd_ep_t *ep;
  79029. + dwc_irqflags_t flags = 0;
  79030. + dwc_ep_t *dwc_ep;
  79031. + int32_t frm_data;
  79032. + dsts_data_t dsts;
  79033. + dwc_otg_core_if_t *core_if;
  79034. +
  79035. + ep = get_ep_from_handle(pcd, ep_handle);
  79036. +
  79037. + if (!ep || !ep->desc || ep->dwc_ep.num == 0) {
  79038. + DWC_WARN("bad ep\n");
  79039. + return -DWC_E_INVALID;
  79040. + }
  79041. +
  79042. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  79043. + core_if = GET_CORE_IF(pcd);
  79044. + dwc_ep = &ep->dwc_ep;
  79045. +
  79046. + if (ep->iso_req_handle) {
  79047. + DWC_WARN("ISO request in progress\n");
  79048. + }
  79049. +
  79050. + dwc_ep->dma_addr0 = dma0;
  79051. + dwc_ep->dma_addr1 = dma1;
  79052. +
  79053. + dwc_ep->xfer_buff0 = buf0;
  79054. + dwc_ep->xfer_buff1 = buf1;
  79055. +
  79056. + dwc_ep->data_per_frame = data_per_frame;
  79057. +
  79058. + /** @todo - pattern data support is to be implemented in the future */
  79059. + dwc_ep->data_pattern_frame = dp_frame;
  79060. + dwc_ep->sync_frame = sync_frame;
  79061. +
  79062. + dwc_ep->buf_proc_intrvl = buf_proc_intrvl;
  79063. +
  79064. + dwc_ep->bInterval = 1 << (ep->desc->bInterval - 1);
  79065. +
  79066. + dwc_ep->proc_buf_num = 0;
  79067. +
  79068. + dwc_ep->pkt_per_frm = 0;
  79069. + frm_data = ep->dwc_ep.data_per_frame;
  79070. + while (frm_data > 0) {
  79071. + dwc_ep->pkt_per_frm++;
  79072. + frm_data -= ep->dwc_ep.maxpacket;
  79073. + }
  79074. +
  79075. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  79076. +
  79077. + if (start_frame == -1) {
  79078. + dwc_ep->next_frame = dsts.b.soffn + 1;
  79079. + if (dwc_ep->bInterval != 1) {
  79080. + dwc_ep->next_frame =
  79081. + dwc_ep->next_frame + (dwc_ep->bInterval - 1 -
  79082. + dwc_ep->next_frame %
  79083. + dwc_ep->bInterval);
  79084. + }
  79085. + } else {
  79086. + dwc_ep->next_frame = start_frame;
  79087. + }
  79088. +
  79089. + if (!core_if->pti_enh_enable) {
  79090. + dwc_ep->pkt_cnt =
  79091. + dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm /
  79092. + dwc_ep->bInterval;
  79093. + } else {
  79094. + dwc_ep->pkt_cnt =
  79095. + (dwc_ep->data_per_frame *
  79096. + (dwc_ep->buf_proc_intrvl / dwc_ep->bInterval)
  79097. + - 1 + dwc_ep->maxpacket) / dwc_ep->maxpacket;
  79098. + }
  79099. +
  79100. + if (core_if->dma_desc_enable) {
  79101. + dwc_ep->desc_cnt =
  79102. + dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm /
  79103. + dwc_ep->bInterval;
  79104. + }
  79105. +
  79106. + if (atomic_alloc) {
  79107. + dwc_ep->pkt_info =
  79108. + DWC_ALLOC_ATOMIC(sizeof(iso_pkt_info_t) * dwc_ep->pkt_cnt);
  79109. + } else {
  79110. + dwc_ep->pkt_info =
  79111. + DWC_ALLOC(sizeof(iso_pkt_info_t) * dwc_ep->pkt_cnt);
  79112. + }
  79113. + if (!dwc_ep->pkt_info) {
  79114. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  79115. + return -DWC_E_NO_MEMORY;
  79116. + }
  79117. + if (core_if->pti_enh_enable) {
  79118. + dwc_memset(dwc_ep->pkt_info, 0,
  79119. + sizeof(iso_pkt_info_t) * dwc_ep->pkt_cnt);
  79120. + }
  79121. +
  79122. + dwc_ep->cur_pkt = 0;
  79123. + ep->iso_req_handle = req_handle;
  79124. +
  79125. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  79126. + dwc_otg_iso_ep_start_transfer(core_if, dwc_ep);
  79127. + return 0;
  79128. +}
  79129. +
  79130. +int dwc_otg_pcd_iso_ep_stop(dwc_otg_pcd_t * pcd, void *ep_handle,
  79131. + void *req_handle)
  79132. +{
  79133. + dwc_irqflags_t flags = 0;
  79134. + dwc_otg_pcd_ep_t *ep;
  79135. + dwc_ep_t *dwc_ep;
  79136. +
  79137. + ep = get_ep_from_handle(pcd, ep_handle);
  79138. + if (!ep || !ep->desc || ep->dwc_ep.num == 0) {
  79139. + DWC_WARN("bad ep\n");
  79140. + return -DWC_E_INVALID;
  79141. + }
  79142. + dwc_ep = &ep->dwc_ep;
  79143. +
  79144. + dwc_otg_iso_ep_stop_transfer(GET_CORE_IF(pcd), dwc_ep);
  79145. +
  79146. + DWC_FREE(dwc_ep->pkt_info);
  79147. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  79148. + if (ep->iso_req_handle != req_handle) {
  79149. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  79150. + return -DWC_E_INVALID;
  79151. + }
  79152. +
  79153. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  79154. +
  79155. + ep->iso_req_handle = 0;
  79156. + return 0;
  79157. +}
  79158. +
  79159. +/**
  79160. + * This function is used for perodical data exchnage between PCD and gadget drivers.
  79161. + * for Isochronous EPs
  79162. + *
  79163. + * - Every time a sync period completes this function is called to
  79164. + * perform data exchange between PCD and gadget
  79165. + */
  79166. +void dwc_otg_iso_buffer_done(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep,
  79167. + void *req_handle)
  79168. +{
  79169. + int i;
  79170. + dwc_ep_t *dwc_ep;
  79171. +
  79172. + dwc_ep = &ep->dwc_ep;
  79173. +
  79174. + DWC_SPINUNLOCK(ep->pcd->lock);
  79175. + pcd->fops->isoc_complete(pcd, ep->priv, ep->iso_req_handle,
  79176. + dwc_ep->proc_buf_num ^ 0x1);
  79177. + DWC_SPINLOCK(ep->pcd->lock);
  79178. +
  79179. + for (i = 0; i < dwc_ep->pkt_cnt; ++i) {
  79180. + dwc_ep->pkt_info[i].status = 0;
  79181. + dwc_ep->pkt_info[i].offset = 0;
  79182. + dwc_ep->pkt_info[i].length = 0;
  79183. + }
  79184. +}
  79185. +
  79186. +int dwc_otg_pcd_get_iso_packet_count(dwc_otg_pcd_t * pcd, void *ep_handle,
  79187. + void *iso_req_handle)
  79188. +{
  79189. + dwc_otg_pcd_ep_t *ep;
  79190. + dwc_ep_t *dwc_ep;
  79191. +
  79192. + ep = get_ep_from_handle(pcd, ep_handle);
  79193. + if (!ep->desc || ep->dwc_ep.num == 0) {
  79194. + DWC_WARN("bad ep\n");
  79195. + return -DWC_E_INVALID;
  79196. + }
  79197. + dwc_ep = &ep->dwc_ep;
  79198. +
  79199. + return dwc_ep->pkt_cnt;
  79200. +}
  79201. +
  79202. +void dwc_otg_pcd_get_iso_packet_params(dwc_otg_pcd_t * pcd, void *ep_handle,
  79203. + void *iso_req_handle, int packet,
  79204. + int *status, int *actual, int *offset)
  79205. +{
  79206. + dwc_otg_pcd_ep_t *ep;
  79207. + dwc_ep_t *dwc_ep;
  79208. +
  79209. + ep = get_ep_from_handle(pcd, ep_handle);
  79210. + if (!ep)
  79211. + DWC_WARN("bad ep\n");
  79212. +
  79213. + dwc_ep = &ep->dwc_ep;
  79214. +
  79215. + *status = dwc_ep->pkt_info[packet].status;
  79216. + *actual = dwc_ep->pkt_info[packet].length;
  79217. + *offset = dwc_ep->pkt_info[packet].offset;
  79218. +}
  79219. +
  79220. +#endif /* DWC_EN_ISOC */
  79221. +
  79222. +static void dwc_otg_pcd_init_ep(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * pcd_ep,
  79223. + uint32_t is_in, uint32_t ep_num)
  79224. +{
  79225. + /* Init EP structure */
  79226. + pcd_ep->desc = 0;
  79227. + pcd_ep->pcd = pcd;
  79228. + pcd_ep->stopped = 1;
  79229. + pcd_ep->queue_sof = 0;
  79230. +
  79231. + /* Init DWC ep structure */
  79232. + pcd_ep->dwc_ep.is_in = is_in;
  79233. + pcd_ep->dwc_ep.num = ep_num;
  79234. + pcd_ep->dwc_ep.active = 0;
  79235. + pcd_ep->dwc_ep.tx_fifo_num = 0;
  79236. + /* Control until ep is actvated */
  79237. + pcd_ep->dwc_ep.type = DWC_OTG_EP_TYPE_CONTROL;
  79238. + pcd_ep->dwc_ep.maxpacket = MAX_PACKET_SIZE;
  79239. + pcd_ep->dwc_ep.dma_addr = 0;
  79240. + pcd_ep->dwc_ep.start_xfer_buff = 0;
  79241. + pcd_ep->dwc_ep.xfer_buff = 0;
  79242. + pcd_ep->dwc_ep.xfer_len = 0;
  79243. + pcd_ep->dwc_ep.xfer_count = 0;
  79244. + pcd_ep->dwc_ep.sent_zlp = 0;
  79245. + pcd_ep->dwc_ep.total_len = 0;
  79246. + pcd_ep->dwc_ep.desc_addr = 0;
  79247. + pcd_ep->dwc_ep.dma_desc_addr = 0;
  79248. + DWC_CIRCLEQ_INIT(&pcd_ep->queue);
  79249. +}
  79250. +
  79251. +/**
  79252. + * Initialize ep's
  79253. + */
  79254. +static void dwc_otg_pcd_reinit(dwc_otg_pcd_t * pcd)
  79255. +{
  79256. + int i;
  79257. + uint32_t hwcfg1;
  79258. + dwc_otg_pcd_ep_t *ep;
  79259. + int in_ep_cntr, out_ep_cntr;
  79260. + uint32_t num_in_eps = (GET_CORE_IF(pcd))->dev_if->num_in_eps;
  79261. + uint32_t num_out_eps = (GET_CORE_IF(pcd))->dev_if->num_out_eps;
  79262. +
  79263. + /**
  79264. + * Initialize the EP0 structure.
  79265. + */
  79266. + ep = &pcd->ep0;
  79267. + dwc_otg_pcd_init_ep(pcd, ep, 0, 0);
  79268. +
  79269. + in_ep_cntr = 0;
  79270. + hwcfg1 = (GET_CORE_IF(pcd))->hwcfg1.d32 >> 3;
  79271. + for (i = 1; in_ep_cntr < num_in_eps; i++) {
  79272. + if ((hwcfg1 & 0x1) == 0) {
  79273. + dwc_otg_pcd_ep_t *ep = &pcd->in_ep[in_ep_cntr];
  79274. + in_ep_cntr++;
  79275. + /**
  79276. + * @todo NGS: Add direction to EP, based on contents
  79277. + * of HWCFG1. Need a copy of HWCFG1 in pcd structure?
  79278. + * sprintf(";r
  79279. + */
  79280. + dwc_otg_pcd_init_ep(pcd, ep, 1 /* IN */ , i);
  79281. +
  79282. + DWC_CIRCLEQ_INIT(&ep->queue);
  79283. + }
  79284. + hwcfg1 >>= 2;
  79285. + }
  79286. +
  79287. + out_ep_cntr = 0;
  79288. + hwcfg1 = (GET_CORE_IF(pcd))->hwcfg1.d32 >> 2;
  79289. + for (i = 1; out_ep_cntr < num_out_eps; i++) {
  79290. + if ((hwcfg1 & 0x1) == 0) {
  79291. + dwc_otg_pcd_ep_t *ep = &pcd->out_ep[out_ep_cntr];
  79292. + out_ep_cntr++;
  79293. + /**
  79294. + * @todo NGS: Add direction to EP, based on contents
  79295. + * of HWCFG1. Need a copy of HWCFG1 in pcd structure?
  79296. + * sprintf(";r
  79297. + */
  79298. + dwc_otg_pcd_init_ep(pcd, ep, 0 /* OUT */ , i);
  79299. + DWC_CIRCLEQ_INIT(&ep->queue);
  79300. + }
  79301. + hwcfg1 >>= 2;
  79302. + }
  79303. +
  79304. + pcd->ep0state = EP0_DISCONNECT;
  79305. + pcd->ep0.dwc_ep.maxpacket = MAX_EP0_SIZE;
  79306. + pcd->ep0.dwc_ep.type = DWC_OTG_EP_TYPE_CONTROL;
  79307. +}
  79308. +
  79309. +/**
  79310. + * This function is called when the SRP timer expires. The SRP should
  79311. + * complete within 6 seconds.
  79312. + */
  79313. +static void srp_timeout(void *ptr)
  79314. +{
  79315. + gotgctl_data_t gotgctl;
  79316. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  79317. + volatile uint32_t *addr = &core_if->core_global_regs->gotgctl;
  79318. +
  79319. + gotgctl.d32 = DWC_READ_REG32(addr);
  79320. +
  79321. + core_if->srp_timer_started = 0;
  79322. +
  79323. + if (core_if->adp_enable) {
  79324. + if (gotgctl.b.bsesvld == 0) {
  79325. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  79326. + DWC_PRINTF("SRP Timeout BSESSVLD = 0\n");
  79327. + /* Power off the core */
  79328. + if (core_if->power_down == 2) {
  79329. + gpwrdn.b.pwrdnswtch = 1;
  79330. + DWC_MODIFY_REG32(&core_if->
  79331. + core_global_regs->gpwrdn,
  79332. + gpwrdn.d32, 0);
  79333. + }
  79334. +
  79335. + gpwrdn.d32 = 0;
  79336. + gpwrdn.b.pmuintsel = 1;
  79337. + gpwrdn.b.pmuactv = 1;
  79338. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  79339. + gpwrdn.d32);
  79340. + dwc_otg_adp_probe_start(core_if);
  79341. + } else {
  79342. + DWC_PRINTF("SRP Timeout BSESSVLD = 1\n");
  79343. + core_if->op_state = B_PERIPHERAL;
  79344. + dwc_otg_core_init(core_if);
  79345. + dwc_otg_enable_global_interrupts(core_if);
  79346. + cil_pcd_start(core_if);
  79347. + }
  79348. + }
  79349. +
  79350. + if ((core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS) &&
  79351. + (core_if->core_params->i2c_enable)) {
  79352. + DWC_PRINTF("SRP Timeout\n");
  79353. +
  79354. + if ((core_if->srp_success) && (gotgctl.b.bsesvld)) {
  79355. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  79356. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  79357. + }
  79358. +
  79359. + /* Clear Session Request */
  79360. + gotgctl.d32 = 0;
  79361. + gotgctl.b.sesreq = 1;
  79362. + DWC_MODIFY_REG32(&core_if->core_global_regs->gotgctl,
  79363. + gotgctl.d32, 0);
  79364. +
  79365. + core_if->srp_success = 0;
  79366. + } else {
  79367. + __DWC_ERROR("Device not connected/responding\n");
  79368. + gotgctl.b.sesreq = 0;
  79369. + DWC_WRITE_REG32(addr, gotgctl.d32);
  79370. + }
  79371. + } else if (gotgctl.b.sesreq) {
  79372. + DWC_PRINTF("SRP Timeout\n");
  79373. +
  79374. + __DWC_ERROR("Device not connected/responding\n");
  79375. + gotgctl.b.sesreq = 0;
  79376. + DWC_WRITE_REG32(addr, gotgctl.d32);
  79377. + } else {
  79378. + DWC_PRINTF(" SRP GOTGCTL=%0x\n", gotgctl.d32);
  79379. + }
  79380. +}
  79381. +
  79382. +/**
  79383. + * Tasklet
  79384. + *
  79385. + */
  79386. +extern void start_next_request(dwc_otg_pcd_ep_t * ep);
  79387. +
  79388. +static void start_xfer_tasklet_func(void *data)
  79389. +{
  79390. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) data;
  79391. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  79392. +
  79393. + int i;
  79394. + depctl_data_t diepctl;
  79395. +
  79396. + DWC_DEBUGPL(DBG_PCDV, "Start xfer tasklet\n");
  79397. +
  79398. + diepctl.d32 = DWC_READ_REG32(&core_if->dev_if->in_ep_regs[0]->diepctl);
  79399. +
  79400. + if (pcd->ep0.queue_sof) {
  79401. + pcd->ep0.queue_sof = 0;
  79402. + start_next_request(&pcd->ep0);
  79403. + // break;
  79404. + }
  79405. +
  79406. + for (i = 0; i < core_if->dev_if->num_in_eps; i++) {
  79407. + depctl_data_t diepctl;
  79408. + diepctl.d32 =
  79409. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->diepctl);
  79410. +
  79411. + if (pcd->in_ep[i].queue_sof) {
  79412. + pcd->in_ep[i].queue_sof = 0;
  79413. + start_next_request(&pcd->in_ep[i]);
  79414. + // break;
  79415. + }
  79416. + }
  79417. +
  79418. + return;
  79419. +}
  79420. +
  79421. +/**
  79422. + * This function initialized the PCD portion of the driver.
  79423. + *
  79424. + */
  79425. +dwc_otg_pcd_t *dwc_otg_pcd_init(dwc_otg_core_if_t * core_if)
  79426. +{
  79427. + dwc_otg_pcd_t *pcd = NULL;
  79428. + dwc_otg_dev_if_t *dev_if;
  79429. + int i;
  79430. +
  79431. + /*
  79432. + * Allocate PCD structure
  79433. + */
  79434. + pcd = DWC_ALLOC(sizeof(dwc_otg_pcd_t));
  79435. +
  79436. + if (pcd == NULL) {
  79437. + return NULL;
  79438. + }
  79439. +
  79440. + pcd->lock = DWC_SPINLOCK_ALLOC();
  79441. + DWC_DEBUGPL(DBG_HCDV, "Init of PCD %p given core_if %p\n",
  79442. + pcd, core_if);//GRAYG
  79443. + if (!pcd->lock) {
  79444. + DWC_ERROR("Could not allocate lock for pcd");
  79445. + DWC_FREE(pcd);
  79446. + return NULL;
  79447. + }
  79448. + /* Set core_if's lock pointer to hcd->lock */
  79449. + core_if->lock = pcd->lock;
  79450. + pcd->core_if = core_if;
  79451. +
  79452. + dev_if = core_if->dev_if;
  79453. + dev_if->isoc_ep = NULL;
  79454. +
  79455. + if (core_if->hwcfg4.b.ded_fifo_en) {
  79456. + DWC_PRINTF("Dedicated Tx FIFOs mode\n");
  79457. + } else {
  79458. + DWC_PRINTF("Shared Tx FIFO mode\n");
  79459. + }
  79460. +
  79461. + /*
  79462. + * Initialized the Core for Device mode here if there is nod ADP support.
  79463. + * Otherwise it will be done later in dwc_otg_adp_start routine.
  79464. + */
  79465. + if (dwc_otg_is_device_mode(core_if) /*&& !core_if->adp_enable*/) {
  79466. + dwc_otg_core_dev_init(core_if);
  79467. + }
  79468. +
  79469. + /*
  79470. + * Register the PCD Callbacks.
  79471. + */
  79472. + dwc_otg_cil_register_pcd_callbacks(core_if, &pcd_callbacks, pcd);
  79473. +
  79474. + /*
  79475. + * Initialize the DMA buffer for SETUP packets
  79476. + */
  79477. + if (GET_CORE_IF(pcd)->dma_enable) {
  79478. + pcd->setup_pkt =
  79479. + DWC_DMA_ALLOC(sizeof(*pcd->setup_pkt) * 5,
  79480. + &pcd->setup_pkt_dma_handle);
  79481. + if (pcd->setup_pkt == NULL) {
  79482. + DWC_FREE(pcd);
  79483. + return NULL;
  79484. + }
  79485. +
  79486. + pcd->status_buf =
  79487. + DWC_DMA_ALLOC(sizeof(uint16_t),
  79488. + &pcd->status_buf_dma_handle);
  79489. + if (pcd->status_buf == NULL) {
  79490. + DWC_DMA_FREE(sizeof(*pcd->setup_pkt) * 5,
  79491. + pcd->setup_pkt, pcd->setup_pkt_dma_handle);
  79492. + DWC_FREE(pcd);
  79493. + return NULL;
  79494. + }
  79495. +
  79496. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  79497. + dev_if->setup_desc_addr[0] =
  79498. + dwc_otg_ep_alloc_desc_chain
  79499. + (&dev_if->dma_setup_desc_addr[0], 1);
  79500. + dev_if->setup_desc_addr[1] =
  79501. + dwc_otg_ep_alloc_desc_chain
  79502. + (&dev_if->dma_setup_desc_addr[1], 1);
  79503. + dev_if->in_desc_addr =
  79504. + dwc_otg_ep_alloc_desc_chain
  79505. + (&dev_if->dma_in_desc_addr, 1);
  79506. + dev_if->out_desc_addr =
  79507. + dwc_otg_ep_alloc_desc_chain
  79508. + (&dev_if->dma_out_desc_addr, 1);
  79509. + pcd->data_terminated = 0;
  79510. +
  79511. + if (dev_if->setup_desc_addr[0] == 0
  79512. + || dev_if->setup_desc_addr[1] == 0
  79513. + || dev_if->in_desc_addr == 0
  79514. + || dev_if->out_desc_addr == 0) {
  79515. +
  79516. + if (dev_if->out_desc_addr)
  79517. + dwc_otg_ep_free_desc_chain
  79518. + (dev_if->out_desc_addr,
  79519. + dev_if->dma_out_desc_addr, 1);
  79520. + if (dev_if->in_desc_addr)
  79521. + dwc_otg_ep_free_desc_chain
  79522. + (dev_if->in_desc_addr,
  79523. + dev_if->dma_in_desc_addr, 1);
  79524. + if (dev_if->setup_desc_addr[1])
  79525. + dwc_otg_ep_free_desc_chain
  79526. + (dev_if->setup_desc_addr[1],
  79527. + dev_if->dma_setup_desc_addr[1], 1);
  79528. + if (dev_if->setup_desc_addr[0])
  79529. + dwc_otg_ep_free_desc_chain
  79530. + (dev_if->setup_desc_addr[0],
  79531. + dev_if->dma_setup_desc_addr[0], 1);
  79532. +
  79533. + DWC_DMA_FREE(sizeof(*pcd->setup_pkt) * 5,
  79534. + pcd->setup_pkt,
  79535. + pcd->setup_pkt_dma_handle);
  79536. + DWC_DMA_FREE(sizeof(*pcd->status_buf),
  79537. + pcd->status_buf,
  79538. + pcd->status_buf_dma_handle);
  79539. +
  79540. + DWC_FREE(pcd);
  79541. +
  79542. + return NULL;
  79543. + }
  79544. + }
  79545. + } else {
  79546. + pcd->setup_pkt = DWC_ALLOC(sizeof(*pcd->setup_pkt) * 5);
  79547. + if (pcd->setup_pkt == NULL) {
  79548. + DWC_FREE(pcd);
  79549. + return NULL;
  79550. + }
  79551. +
  79552. + pcd->status_buf = DWC_ALLOC(sizeof(uint16_t));
  79553. + if (pcd->status_buf == NULL) {
  79554. + DWC_FREE(pcd->setup_pkt);
  79555. + DWC_FREE(pcd);
  79556. + return NULL;
  79557. + }
  79558. + }
  79559. +
  79560. + dwc_otg_pcd_reinit(pcd);
  79561. +
  79562. + /* Allocate the cfi object for the PCD */
  79563. +#ifdef DWC_UTE_CFI
  79564. + pcd->cfi = DWC_ALLOC(sizeof(cfiobject_t));
  79565. + if (NULL == pcd->cfi)
  79566. + goto fail;
  79567. + if (init_cfi(pcd->cfi)) {
  79568. + CFI_INFO("%s: Failed to init the CFI object\n", __func__);
  79569. + goto fail;
  79570. + }
  79571. +#endif
  79572. +
  79573. + /* Initialize tasklets */
  79574. + pcd->start_xfer_tasklet = DWC_TASK_ALLOC("xfer_tasklet",
  79575. + start_xfer_tasklet_func, pcd);
  79576. + pcd->test_mode_tasklet = DWC_TASK_ALLOC("test_mode_tasklet",
  79577. + do_test_mode, pcd);
  79578. +
  79579. + /* Initialize SRP timer */
  79580. + core_if->srp_timer = DWC_TIMER_ALLOC("SRP TIMER", srp_timeout, core_if);
  79581. +
  79582. + if (core_if->core_params->dev_out_nak) {
  79583. + /**
  79584. + * Initialize xfer timeout timer. Implemented for
  79585. + * 2.93a feature "Device DDMA OUT NAK Enhancement"
  79586. + */
  79587. + for(i = 0; i < MAX_EPS_CHANNELS; i++) {
  79588. + pcd->core_if->ep_xfer_timer[i] =
  79589. + DWC_TIMER_ALLOC("ep timer", ep_xfer_timeout,
  79590. + &pcd->core_if->ep_xfer_info[i]);
  79591. + }
  79592. + }
  79593. +
  79594. + return pcd;
  79595. +#ifdef DWC_UTE_CFI
  79596. +fail:
  79597. +#endif
  79598. + if (pcd->setup_pkt)
  79599. + DWC_FREE(pcd->setup_pkt);
  79600. + if (pcd->status_buf)
  79601. + DWC_FREE(pcd->status_buf);
  79602. +#ifdef DWC_UTE_CFI
  79603. + if (pcd->cfi)
  79604. + DWC_FREE(pcd->cfi);
  79605. +#endif
  79606. + if (pcd)
  79607. + DWC_FREE(pcd);
  79608. + return NULL;
  79609. +
  79610. +}
  79611. +
  79612. +/**
  79613. + * Remove PCD specific data
  79614. + */
  79615. +void dwc_otg_pcd_remove(dwc_otg_pcd_t * pcd)
  79616. +{
  79617. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  79618. + int i;
  79619. + if (pcd->core_if->core_params->dev_out_nak) {
  79620. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  79621. + DWC_TIMER_CANCEL(pcd->core_if->ep_xfer_timer[i]);
  79622. + pcd->core_if->ep_xfer_info[i].state = 0;
  79623. + }
  79624. + }
  79625. +
  79626. + if (GET_CORE_IF(pcd)->dma_enable) {
  79627. + DWC_DMA_FREE(sizeof(*pcd->setup_pkt) * 5, pcd->setup_pkt,
  79628. + pcd->setup_pkt_dma_handle);
  79629. + DWC_DMA_FREE(sizeof(uint16_t), pcd->status_buf,
  79630. + pcd->status_buf_dma_handle);
  79631. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  79632. + dwc_otg_ep_free_desc_chain(dev_if->setup_desc_addr[0],
  79633. + dev_if->dma_setup_desc_addr
  79634. + [0], 1);
  79635. + dwc_otg_ep_free_desc_chain(dev_if->setup_desc_addr[1],
  79636. + dev_if->dma_setup_desc_addr
  79637. + [1], 1);
  79638. + dwc_otg_ep_free_desc_chain(dev_if->in_desc_addr,
  79639. + dev_if->dma_in_desc_addr, 1);
  79640. + dwc_otg_ep_free_desc_chain(dev_if->out_desc_addr,
  79641. + dev_if->dma_out_desc_addr,
  79642. + 1);
  79643. + }
  79644. + } else {
  79645. + DWC_FREE(pcd->setup_pkt);
  79646. + DWC_FREE(pcd->status_buf);
  79647. + }
  79648. + DWC_SPINLOCK_FREE(pcd->lock);
  79649. + /* Set core_if's lock pointer to NULL */
  79650. + pcd->core_if->lock = NULL;
  79651. +
  79652. + DWC_TASK_FREE(pcd->start_xfer_tasklet);
  79653. + DWC_TASK_FREE(pcd->test_mode_tasklet);
  79654. + if (pcd->core_if->core_params->dev_out_nak) {
  79655. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  79656. + if (pcd->core_if->ep_xfer_timer[i]) {
  79657. + DWC_TIMER_FREE(pcd->core_if->ep_xfer_timer[i]);
  79658. + }
  79659. + }
  79660. + }
  79661. +
  79662. +/* Release the CFI object's dynamic memory */
  79663. +#ifdef DWC_UTE_CFI
  79664. + if (pcd->cfi->ops.release) {
  79665. + pcd->cfi->ops.release(pcd->cfi);
  79666. + }
  79667. +#endif
  79668. +
  79669. + DWC_FREE(pcd);
  79670. +}
  79671. +
  79672. +/**
  79673. + * Returns whether registered pcd is dual speed or not
  79674. + */
  79675. +uint32_t dwc_otg_pcd_is_dualspeed(dwc_otg_pcd_t * pcd)
  79676. +{
  79677. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  79678. +
  79679. + if ((core_if->core_params->speed == DWC_SPEED_PARAM_FULL) ||
  79680. + ((core_if->hwcfg2.b.hs_phy_type == 2) &&
  79681. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  79682. + (core_if->core_params->ulpi_fs_ls))) {
  79683. + return 0;
  79684. + }
  79685. +
  79686. + return 1;
  79687. +}
  79688. +
  79689. +/**
  79690. + * Returns whether registered pcd is OTG capable or not
  79691. + */
  79692. +uint32_t dwc_otg_pcd_is_otg(dwc_otg_pcd_t * pcd)
  79693. +{
  79694. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  79695. + gusbcfg_data_t usbcfg = {.d32 = 0 };
  79696. +
  79697. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  79698. + if (!usbcfg.b.srpcap || !usbcfg.b.hnpcap) {
  79699. + return 0;
  79700. + }
  79701. +
  79702. + return 1;
  79703. +}
  79704. +
  79705. +/**
  79706. + * This function assigns periodic Tx FIFO to an periodic EP
  79707. + * in shared Tx FIFO mode
  79708. + */
  79709. +static uint32_t assign_tx_fifo(dwc_otg_core_if_t * core_if)
  79710. +{
  79711. + uint32_t TxMsk = 1;
  79712. + int i;
  79713. +
  79714. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; ++i) {
  79715. + if ((TxMsk & core_if->tx_msk) == 0) {
  79716. + core_if->tx_msk |= TxMsk;
  79717. + return i + 1;
  79718. + }
  79719. + TxMsk <<= 1;
  79720. + }
  79721. + return 0;
  79722. +}
  79723. +
  79724. +/**
  79725. + * This function assigns periodic Tx FIFO to an periodic EP
  79726. + * in shared Tx FIFO mode
  79727. + */
  79728. +static uint32_t assign_perio_tx_fifo(dwc_otg_core_if_t * core_if)
  79729. +{
  79730. + uint32_t PerTxMsk = 1;
  79731. + int i;
  79732. + for (i = 0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; ++i) {
  79733. + if ((PerTxMsk & core_if->p_tx_msk) == 0) {
  79734. + core_if->p_tx_msk |= PerTxMsk;
  79735. + return i + 1;
  79736. + }
  79737. + PerTxMsk <<= 1;
  79738. + }
  79739. + return 0;
  79740. +}
  79741. +
  79742. +/**
  79743. + * This function releases periodic Tx FIFO
  79744. + * in shared Tx FIFO mode
  79745. + */
  79746. +static void release_perio_tx_fifo(dwc_otg_core_if_t * core_if,
  79747. + uint32_t fifo_num)
  79748. +{
  79749. + core_if->p_tx_msk =
  79750. + (core_if->p_tx_msk & (1 << (fifo_num - 1))) ^ core_if->p_tx_msk;
  79751. +}
  79752. +
  79753. +/**
  79754. + * This function releases periodic Tx FIFO
  79755. + * in shared Tx FIFO mode
  79756. + */
  79757. +static void release_tx_fifo(dwc_otg_core_if_t * core_if, uint32_t fifo_num)
  79758. +{
  79759. + core_if->tx_msk =
  79760. + (core_if->tx_msk & (1 << (fifo_num - 1))) ^ core_if->tx_msk;
  79761. +}
  79762. +
  79763. +/**
  79764. + * This function is being called from gadget
  79765. + * to enable PCD endpoint.
  79766. + */
  79767. +int dwc_otg_pcd_ep_enable(dwc_otg_pcd_t * pcd,
  79768. + const uint8_t * ep_desc, void *usb_ep)
  79769. +{
  79770. + int num, dir;
  79771. + dwc_otg_pcd_ep_t *ep = NULL;
  79772. + const usb_endpoint_descriptor_t *desc;
  79773. + dwc_irqflags_t flags;
  79774. + fifosize_data_t dptxfsiz = {.d32 = 0 };
  79775. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  79776. + gdfifocfg_data_t gdfifocfgbase = {.d32 = 0 };
  79777. + int retval = 0;
  79778. + int i, epcount;
  79779. +
  79780. + desc = (const usb_endpoint_descriptor_t *)ep_desc;
  79781. +
  79782. + if (!desc) {
  79783. + pcd->ep0.priv = usb_ep;
  79784. + ep = &pcd->ep0;
  79785. + retval = -DWC_E_INVALID;
  79786. + goto out;
  79787. + }
  79788. +
  79789. + num = UE_GET_ADDR(desc->bEndpointAddress);
  79790. + dir = UE_GET_DIR(desc->bEndpointAddress);
  79791. +
  79792. + if (!desc->wMaxPacketSize) {
  79793. + DWC_WARN("bad maxpacketsize\n");
  79794. + retval = -DWC_E_INVALID;
  79795. + goto out;
  79796. + }
  79797. +
  79798. + if (dir == UE_DIR_IN) {
  79799. + epcount = pcd->core_if->dev_if->num_in_eps;
  79800. + for (i = 0; i < epcount; i++) {
  79801. + if (num == pcd->in_ep[i].dwc_ep.num) {
  79802. + ep = &pcd->in_ep[i];
  79803. + break;
  79804. + }
  79805. + }
  79806. + } else {
  79807. + epcount = pcd->core_if->dev_if->num_out_eps;
  79808. + for (i = 0; i < epcount; i++) {
  79809. + if (num == pcd->out_ep[i].dwc_ep.num) {
  79810. + ep = &pcd->out_ep[i];
  79811. + break;
  79812. + }
  79813. + }
  79814. + }
  79815. +
  79816. + if (!ep) {
  79817. + DWC_WARN("bad address\n");
  79818. + retval = -DWC_E_INVALID;
  79819. + goto out;
  79820. + }
  79821. +
  79822. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  79823. +
  79824. + ep->desc = desc;
  79825. + ep->priv = usb_ep;
  79826. +
  79827. + /*
  79828. + * Activate the EP
  79829. + */
  79830. + ep->stopped = 0;
  79831. +
  79832. + ep->dwc_ep.is_in = (dir == UE_DIR_IN);
  79833. + ep->dwc_ep.maxpacket = UGETW(desc->wMaxPacketSize);
  79834. +
  79835. + ep->dwc_ep.type = desc->bmAttributes & UE_XFERTYPE;
  79836. +
  79837. + if (ep->dwc_ep.is_in) {
  79838. + if (!GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  79839. + ep->dwc_ep.tx_fifo_num = 0;
  79840. +
  79841. + if (ep->dwc_ep.type == UE_ISOCHRONOUS) {
  79842. + /*
  79843. + * if ISOC EP then assign a Periodic Tx FIFO.
  79844. + */
  79845. + ep->dwc_ep.tx_fifo_num =
  79846. + assign_perio_tx_fifo(GET_CORE_IF(pcd));
  79847. + }
  79848. + } else {
  79849. + /*
  79850. + * if Dedicated FIFOs mode is on then assign a Tx FIFO.
  79851. + */
  79852. + ep->dwc_ep.tx_fifo_num =
  79853. + assign_tx_fifo(GET_CORE_IF(pcd));
  79854. + }
  79855. +
  79856. + /* Calculating EP info controller base address */
  79857. + if (ep->dwc_ep.tx_fifo_num
  79858. + && GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  79859. + gdfifocfg.d32 =
  79860. + DWC_READ_REG32(&GET_CORE_IF(pcd)->
  79861. + core_global_regs->gdfifocfg);
  79862. + gdfifocfgbase.d32 = gdfifocfg.d32 >> 16;
  79863. + dptxfsiz.d32 =
  79864. + (DWC_READ_REG32
  79865. + (&GET_CORE_IF(pcd)->core_global_regs->
  79866. + dtxfsiz[ep->dwc_ep.tx_fifo_num - 1]) >> 16);
  79867. + gdfifocfg.b.epinfobase =
  79868. + gdfifocfgbase.d32 + dptxfsiz.d32;
  79869. + if (GET_CORE_IF(pcd)->snpsid <= OTG_CORE_REV_2_94a) {
  79870. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->
  79871. + core_global_regs->gdfifocfg,
  79872. + gdfifocfg.d32);
  79873. + }
  79874. + }
  79875. + }
  79876. + /* Set initial data PID. */
  79877. + if (ep->dwc_ep.type == UE_BULK) {
  79878. + ep->dwc_ep.data_pid_start = 0;
  79879. + }
  79880. +
  79881. + /* Alloc DMA Descriptors */
  79882. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  79883. +#ifndef DWC_UTE_PER_IO
  79884. + if (ep->dwc_ep.type != UE_ISOCHRONOUS) {
  79885. +#endif
  79886. + ep->dwc_ep.desc_addr =
  79887. + dwc_otg_ep_alloc_desc_chain(&ep->
  79888. + dwc_ep.dma_desc_addr,
  79889. + MAX_DMA_DESC_CNT);
  79890. + if (!ep->dwc_ep.desc_addr) {
  79891. + DWC_WARN("%s, can't allocate DMA descriptor\n",
  79892. + __func__);
  79893. + retval = -DWC_E_SHUTDOWN;
  79894. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  79895. + goto out;
  79896. + }
  79897. +#ifndef DWC_UTE_PER_IO
  79898. + }
  79899. +#endif
  79900. + }
  79901. +
  79902. + DWC_DEBUGPL(DBG_PCD, "Activate %s: type=%d, mps=%d desc=%p\n",
  79903. + (ep->dwc_ep.is_in ? "IN" : "OUT"),
  79904. + ep->dwc_ep.type, ep->dwc_ep.maxpacket, ep->desc);
  79905. +#ifdef DWC_UTE_PER_IO
  79906. + ep->dwc_ep.xiso_bInterval = 1 << (ep->desc->bInterval - 1);
  79907. +#endif
  79908. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  79909. + ep->dwc_ep.bInterval = 1 << (ep->desc->bInterval - 1);
  79910. + ep->dwc_ep.frame_num = 0xFFFFFFFF;
  79911. + }
  79912. +
  79913. + dwc_otg_ep_activate(GET_CORE_IF(pcd), &ep->dwc_ep);
  79914. +
  79915. +#ifdef DWC_UTE_CFI
  79916. + if (pcd->cfi->ops.ep_enable) {
  79917. + pcd->cfi->ops.ep_enable(pcd->cfi, pcd, ep);
  79918. + }
  79919. +#endif
  79920. +
  79921. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  79922. +
  79923. +out:
  79924. + return retval;
  79925. +}
  79926. +
  79927. +/**
  79928. + * This function is being called from gadget
  79929. + * to disable PCD endpoint.
  79930. + */
  79931. +int dwc_otg_pcd_ep_disable(dwc_otg_pcd_t * pcd, void *ep_handle)
  79932. +{
  79933. + dwc_otg_pcd_ep_t *ep;
  79934. + dwc_irqflags_t flags;
  79935. + dwc_otg_dev_dma_desc_t *desc_addr;
  79936. + dwc_dma_t dma_desc_addr;
  79937. + gdfifocfg_data_t gdfifocfgbase = {.d32 = 0 };
  79938. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  79939. + fifosize_data_t dptxfsiz = {.d32 = 0 };
  79940. +
  79941. + ep = get_ep_from_handle(pcd, ep_handle);
  79942. +
  79943. + if (!ep || !ep->desc) {
  79944. + DWC_DEBUGPL(DBG_PCD, "bad ep address\n");
  79945. + return -DWC_E_INVALID;
  79946. + }
  79947. +
  79948. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  79949. +
  79950. + dwc_otg_request_nuke(ep);
  79951. +
  79952. + dwc_otg_ep_deactivate(GET_CORE_IF(pcd), &ep->dwc_ep);
  79953. + if (pcd->core_if->core_params->dev_out_nak) {
  79954. + DWC_TIMER_CANCEL(pcd->core_if->ep_xfer_timer[ep->dwc_ep.num]);
  79955. + pcd->core_if->ep_xfer_info[ep->dwc_ep.num].state = 0;
  79956. + }
  79957. + ep->desc = NULL;
  79958. + ep->stopped = 1;
  79959. +
  79960. + gdfifocfg.d32 =
  79961. + DWC_READ_REG32(&GET_CORE_IF(pcd)->core_global_regs->gdfifocfg);
  79962. + gdfifocfgbase.d32 = gdfifocfg.d32 >> 16;
  79963. +
  79964. + if (ep->dwc_ep.is_in) {
  79965. + if (GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  79966. + /* Flush the Tx FIFO */
  79967. + dwc_otg_flush_tx_fifo(GET_CORE_IF(pcd),
  79968. + ep->dwc_ep.tx_fifo_num);
  79969. + }
  79970. + release_perio_tx_fifo(GET_CORE_IF(pcd), ep->dwc_ep.tx_fifo_num);
  79971. + release_tx_fifo(GET_CORE_IF(pcd), ep->dwc_ep.tx_fifo_num);
  79972. + if (GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  79973. + /* Decreasing EPinfo Base Addr */
  79974. + dptxfsiz.d32 =
  79975. + (DWC_READ_REG32
  79976. + (&GET_CORE_IF(pcd)->
  79977. + core_global_regs->dtxfsiz[ep->dwc_ep.tx_fifo_num-1]) >> 16);
  79978. + gdfifocfg.b.epinfobase = gdfifocfgbase.d32 - dptxfsiz.d32;
  79979. + if (GET_CORE_IF(pcd)->snpsid <= OTG_CORE_REV_2_94a) {
  79980. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gdfifocfg,
  79981. + gdfifocfg.d32);
  79982. + }
  79983. + }
  79984. + }
  79985. +
  79986. + /* Free DMA Descriptors */
  79987. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  79988. + if (ep->dwc_ep.type != UE_ISOCHRONOUS) {
  79989. + desc_addr = ep->dwc_ep.desc_addr;
  79990. + dma_desc_addr = ep->dwc_ep.dma_desc_addr;
  79991. +
  79992. + /* Cannot call dma_free_coherent() with IRQs disabled */
  79993. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  79994. + dwc_otg_ep_free_desc_chain(desc_addr, dma_desc_addr,
  79995. + MAX_DMA_DESC_CNT);
  79996. +
  79997. + goto out_unlocked;
  79998. + }
  79999. + }
  80000. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  80001. +
  80002. +out_unlocked:
  80003. + DWC_DEBUGPL(DBG_PCD, "%d %s disabled\n", ep->dwc_ep.num,
  80004. + ep->dwc_ep.is_in ? "IN" : "OUT");
  80005. + return 0;
  80006. +
  80007. +}
  80008. +
  80009. +/******************************************************************************/
  80010. +#ifdef DWC_UTE_PER_IO
  80011. +
  80012. +/**
  80013. + * Free the request and its extended parts
  80014. + *
  80015. + */
  80016. +void dwc_pcd_xiso_ereq_free(dwc_otg_pcd_ep_t * ep, dwc_otg_pcd_request_t * req)
  80017. +{
  80018. + DWC_FREE(req->ext_req.per_io_frame_descs);
  80019. + DWC_FREE(req);
  80020. +}
  80021. +
  80022. +/**
  80023. + * Start the next request in the endpoint's queue.
  80024. + *
  80025. + */
  80026. +int dwc_otg_pcd_xiso_start_next_request(dwc_otg_pcd_t * pcd,
  80027. + dwc_otg_pcd_ep_t * ep)
  80028. +{
  80029. + int i;
  80030. + dwc_otg_pcd_request_t *req = NULL;
  80031. + dwc_ep_t *dwcep = NULL;
  80032. + struct dwc_iso_xreq_port *ereq = NULL;
  80033. + struct dwc_iso_pkt_desc_port *ddesc_iso;
  80034. + uint16_t nat;
  80035. + depctl_data_t diepctl;
  80036. +
  80037. + dwcep = &ep->dwc_ep;
  80038. +
  80039. + if (dwcep->xiso_active_xfers > 0) {
  80040. +#if 0 //Disable this to decrease s/w overhead that is crucial for Isoc transfers
  80041. + DWC_WARN("There are currently active transfers for EP%d \
  80042. + (active=%d; queued=%d)", dwcep->num, dwcep->xiso_active_xfers,
  80043. + dwcep->xiso_queued_xfers);
  80044. +#endif
  80045. + return 0;
  80046. + }
  80047. +
  80048. + nat = UGETW(ep->desc->wMaxPacketSize);
  80049. + nat = (nat >> 11) & 0x03;
  80050. +
  80051. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  80052. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  80053. + ereq = &req->ext_req;
  80054. + ep->stopped = 0;
  80055. +
  80056. + /* Get the frame number */
  80057. + dwcep->xiso_frame_num =
  80058. + dwc_otg_get_frame_number(GET_CORE_IF(pcd));
  80059. + DWC_DEBUG("FRM_NUM=%d", dwcep->xiso_frame_num);
  80060. +
  80061. + ddesc_iso = ereq->per_io_frame_descs;
  80062. +
  80063. + if (dwcep->is_in) {
  80064. + /* Setup DMA Descriptor chain for IN Isoc request */
  80065. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  80066. + //if ((i % (nat + 1)) == 0)
  80067. + if ( i > 0 )
  80068. + dwcep->xiso_frame_num =
  80069. + (dwcep->xiso_bInterval +
  80070. + dwcep->xiso_frame_num) & 0x3FFF;
  80071. + dwcep->desc_addr[i].buf =
  80072. + req->dma + ddesc_iso[i].offset;
  80073. + dwcep->desc_addr[i].status.b_iso_in.txbytes =
  80074. + ddesc_iso[i].length;
  80075. + dwcep->desc_addr[i].status.b_iso_in.framenum =
  80076. + dwcep->xiso_frame_num;
  80077. + dwcep->desc_addr[i].status.b_iso_in.bs =
  80078. + BS_HOST_READY;
  80079. + dwcep->desc_addr[i].status.b_iso_in.txsts = 0;
  80080. + dwcep->desc_addr[i].status.b_iso_in.sp =
  80081. + (ddesc_iso[i].length %
  80082. + dwcep->maxpacket) ? 1 : 0;
  80083. + dwcep->desc_addr[i].status.b_iso_in.ioc = 0;
  80084. + dwcep->desc_addr[i].status.b_iso_in.pid = nat + 1;
  80085. + dwcep->desc_addr[i].status.b_iso_in.l = 0;
  80086. +
  80087. + /* Process the last descriptor */
  80088. + if (i == ereq->pio_pkt_count - 1) {
  80089. + dwcep->desc_addr[i].status.b_iso_in.ioc = 1;
  80090. + dwcep->desc_addr[i].status.b_iso_in.l = 1;
  80091. + }
  80092. + }
  80093. +
  80094. + /* Setup and start the transfer for this endpoint */
  80095. + dwcep->xiso_active_xfers++;
  80096. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->dev_if->
  80097. + in_ep_regs[dwcep->num]->diepdma,
  80098. + dwcep->dma_desc_addr);
  80099. + diepctl.d32 = 0;
  80100. + diepctl.b.epena = 1;
  80101. + diepctl.b.cnak = 1;
  80102. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->dev_if->
  80103. + in_ep_regs[dwcep->num]->diepctl, 0,
  80104. + diepctl.d32);
  80105. + } else {
  80106. + /* Setup DMA Descriptor chain for OUT Isoc request */
  80107. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  80108. + //if ((i % (nat + 1)) == 0)
  80109. + dwcep->xiso_frame_num = (dwcep->xiso_bInterval +
  80110. + dwcep->xiso_frame_num) & 0x3FFF;
  80111. + dwcep->desc_addr[i].buf =
  80112. + req->dma + ddesc_iso[i].offset;
  80113. + dwcep->desc_addr[i].status.b_iso_out.rxbytes =
  80114. + ddesc_iso[i].length;
  80115. + dwcep->desc_addr[i].status.b_iso_out.framenum =
  80116. + dwcep->xiso_frame_num;
  80117. + dwcep->desc_addr[i].status.b_iso_out.bs =
  80118. + BS_HOST_READY;
  80119. + dwcep->desc_addr[i].status.b_iso_out.rxsts = 0;
  80120. + dwcep->desc_addr[i].status.b_iso_out.sp =
  80121. + (ddesc_iso[i].length %
  80122. + dwcep->maxpacket) ? 1 : 0;
  80123. + dwcep->desc_addr[i].status.b_iso_out.ioc = 0;
  80124. + dwcep->desc_addr[i].status.b_iso_out.pid = nat + 1;
  80125. + dwcep->desc_addr[i].status.b_iso_out.l = 0;
  80126. +
  80127. + /* Process the last descriptor */
  80128. + if (i == ereq->pio_pkt_count - 1) {
  80129. + dwcep->desc_addr[i].status.b_iso_out.ioc = 1;
  80130. + dwcep->desc_addr[i].status.b_iso_out.l = 1;
  80131. + }
  80132. + }
  80133. +
  80134. + /* Setup and start the transfer for this endpoint */
  80135. + dwcep->xiso_active_xfers++;
  80136. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->
  80137. + dev_if->out_ep_regs[dwcep->num]->
  80138. + doepdma, dwcep->dma_desc_addr);
  80139. + diepctl.d32 = 0;
  80140. + diepctl.b.epena = 1;
  80141. + diepctl.b.cnak = 1;
  80142. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->
  80143. + dev_if->out_ep_regs[dwcep->num]->
  80144. + doepctl, 0, diepctl.d32);
  80145. + }
  80146. +
  80147. + } else {
  80148. + ep->stopped = 1;
  80149. + }
  80150. +
  80151. + return 0;
  80152. +}
  80153. +
  80154. +/**
  80155. + * - Remove the request from the queue
  80156. + */
  80157. +void complete_xiso_ep(dwc_otg_pcd_ep_t * ep)
  80158. +{
  80159. + dwc_otg_pcd_request_t *req = NULL;
  80160. + struct dwc_iso_xreq_port *ereq = NULL;
  80161. + struct dwc_iso_pkt_desc_port *ddesc_iso = NULL;
  80162. + dwc_ep_t *dwcep = NULL;
  80163. + int i;
  80164. +
  80165. + //DWC_DEBUG();
  80166. + dwcep = &ep->dwc_ep;
  80167. +
  80168. + /* Get the first pending request from the queue */
  80169. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  80170. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  80171. + if (!req) {
  80172. + DWC_PRINTF("complete_ep 0x%p, req = NULL!\n", ep);
  80173. + return;
  80174. + }
  80175. + dwcep->xiso_active_xfers--;
  80176. + dwcep->xiso_queued_xfers--;
  80177. + /* Remove this request from the queue */
  80178. + DWC_CIRCLEQ_REMOVE_INIT(&ep->queue, req, queue_entry);
  80179. + } else {
  80180. + DWC_PRINTF("complete_ep 0x%p, ep->queue empty!\n", ep);
  80181. + return;
  80182. + }
  80183. +
  80184. + ep->stopped = 1;
  80185. + ereq = &req->ext_req;
  80186. + ddesc_iso = ereq->per_io_frame_descs;
  80187. +
  80188. + if (dwcep->xiso_active_xfers < 0) {
  80189. + DWC_WARN("EP#%d (xiso_active_xfers=%d)", dwcep->num,
  80190. + dwcep->xiso_active_xfers);
  80191. + }
  80192. +
  80193. + /* Fill the Isoc descs of portable extended req from dma descriptors */
  80194. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  80195. + if (dwcep->is_in) { /* IN endpoints */
  80196. + ddesc_iso[i].actual_length = ddesc_iso[i].length -
  80197. + dwcep->desc_addr[i].status.b_iso_in.txbytes;
  80198. + ddesc_iso[i].status =
  80199. + dwcep->desc_addr[i].status.b_iso_in.txsts;
  80200. + } else { /* OUT endpoints */
  80201. + ddesc_iso[i].actual_length = ddesc_iso[i].length -
  80202. + dwcep->desc_addr[i].status.b_iso_out.rxbytes;
  80203. + ddesc_iso[i].status =
  80204. + dwcep->desc_addr[i].status.b_iso_out.rxsts;
  80205. + }
  80206. + }
  80207. +
  80208. + DWC_SPINUNLOCK(ep->pcd->lock);
  80209. +
  80210. + /* Call the completion function in the non-portable logic */
  80211. + ep->pcd->fops->xisoc_complete(ep->pcd, ep->priv, req->priv, 0,
  80212. + &req->ext_req);
  80213. +
  80214. + DWC_SPINLOCK(ep->pcd->lock);
  80215. +
  80216. + /* Free the request - specific freeing needed for extended request object */
  80217. + dwc_pcd_xiso_ereq_free(ep, req);
  80218. +
  80219. + /* Start the next request */
  80220. + dwc_otg_pcd_xiso_start_next_request(ep->pcd, ep);
  80221. +
  80222. + return;
  80223. +}
  80224. +
  80225. +/**
  80226. + * Create and initialize the Isoc pkt descriptors of the extended request.
  80227. + *
  80228. + */
  80229. +static int dwc_otg_pcd_xiso_create_pkt_descs(dwc_otg_pcd_request_t * req,
  80230. + void *ereq_nonport,
  80231. + int atomic_alloc)
  80232. +{
  80233. + struct dwc_iso_xreq_port *ereq = NULL;
  80234. + struct dwc_iso_xreq_port *req_mapped = NULL;
  80235. + struct dwc_iso_pkt_desc_port *ipds = NULL; /* To be created in this function */
  80236. + uint32_t pkt_count;
  80237. + int i;
  80238. +
  80239. + ereq = &req->ext_req;
  80240. + req_mapped = (struct dwc_iso_xreq_port *)ereq_nonport;
  80241. + pkt_count = req_mapped->pio_pkt_count;
  80242. +
  80243. + /* Create the isoc descs */
  80244. + if (atomic_alloc) {
  80245. + ipds = DWC_ALLOC_ATOMIC(sizeof(*ipds) * pkt_count);
  80246. + } else {
  80247. + ipds = DWC_ALLOC(sizeof(*ipds) * pkt_count);
  80248. + }
  80249. +
  80250. + if (!ipds) {
  80251. + DWC_ERROR("Failed to allocate isoc descriptors");
  80252. + return -DWC_E_NO_MEMORY;
  80253. + }
  80254. +
  80255. + /* Initialize the extended request fields */
  80256. + ereq->per_io_frame_descs = ipds;
  80257. + ereq->error_count = 0;
  80258. + ereq->pio_alloc_pkt_count = pkt_count;
  80259. + ereq->pio_pkt_count = pkt_count;
  80260. + ereq->tr_sub_flags = req_mapped->tr_sub_flags;
  80261. +
  80262. + /* Init the Isoc descriptors */
  80263. + for (i = 0; i < pkt_count; i++) {
  80264. + ipds[i].length = req_mapped->per_io_frame_descs[i].length;
  80265. + ipds[i].offset = req_mapped->per_io_frame_descs[i].offset;
  80266. + ipds[i].status = req_mapped->per_io_frame_descs[i].status; /* 0 */
  80267. + ipds[i].actual_length =
  80268. + req_mapped->per_io_frame_descs[i].actual_length;
  80269. + }
  80270. +
  80271. + return 0;
  80272. +}
  80273. +
  80274. +static void prn_ext_request(struct dwc_iso_xreq_port *ereq)
  80275. +{
  80276. + struct dwc_iso_pkt_desc_port *xfd = NULL;
  80277. + int i;
  80278. +
  80279. + DWC_DEBUG("per_io_frame_descs=%p", ereq->per_io_frame_descs);
  80280. + DWC_DEBUG("tr_sub_flags=%d", ereq->tr_sub_flags);
  80281. + DWC_DEBUG("error_count=%d", ereq->error_count);
  80282. + DWC_DEBUG("pio_alloc_pkt_count=%d", ereq->pio_alloc_pkt_count);
  80283. + DWC_DEBUG("pio_pkt_count=%d", ereq->pio_pkt_count);
  80284. + DWC_DEBUG("res=%d", ereq->res);
  80285. +
  80286. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  80287. + xfd = &ereq->per_io_frame_descs[0];
  80288. + DWC_DEBUG("FD #%d", i);
  80289. +
  80290. + DWC_DEBUG("xfd->actual_length=%d", xfd->actual_length);
  80291. + DWC_DEBUG("xfd->length=%d", xfd->length);
  80292. + DWC_DEBUG("xfd->offset=%d", xfd->offset);
  80293. + DWC_DEBUG("xfd->status=%d", xfd->status);
  80294. + }
  80295. +}
  80296. +
  80297. +/**
  80298. + *
  80299. + */
  80300. +int dwc_otg_pcd_xiso_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  80301. + uint8_t * buf, dwc_dma_t dma_buf, uint32_t buflen,
  80302. + int zero, void *req_handle, int atomic_alloc,
  80303. + void *ereq_nonport)
  80304. +{
  80305. + dwc_otg_pcd_request_t *req = NULL;
  80306. + dwc_otg_pcd_ep_t *ep;
  80307. + dwc_irqflags_t flags;
  80308. + int res;
  80309. +
  80310. + ep = get_ep_from_handle(pcd, ep_handle);
  80311. + if (!ep) {
  80312. + DWC_WARN("bad ep\n");
  80313. + return -DWC_E_INVALID;
  80314. + }
  80315. +
  80316. + /* We support this extension only for DDMA mode */
  80317. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC)
  80318. + if (!GET_CORE_IF(pcd)->dma_desc_enable)
  80319. + return -DWC_E_INVALID;
  80320. +
  80321. + /* Create a dwc_otg_pcd_request_t object */
  80322. + if (atomic_alloc) {
  80323. + req = DWC_ALLOC_ATOMIC(sizeof(*req));
  80324. + } else {
  80325. + req = DWC_ALLOC(sizeof(*req));
  80326. + }
  80327. +
  80328. + if (!req) {
  80329. + return -DWC_E_NO_MEMORY;
  80330. + }
  80331. +
  80332. + /* Create the Isoc descs for this request which shall be the exact match
  80333. + * of the structure sent to us from the non-portable logic */
  80334. + res =
  80335. + dwc_otg_pcd_xiso_create_pkt_descs(req, ereq_nonport, atomic_alloc);
  80336. + if (res) {
  80337. + DWC_WARN("Failed to init the Isoc descriptors");
  80338. + DWC_FREE(req);
  80339. + return res;
  80340. + }
  80341. +
  80342. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  80343. +
  80344. + DWC_CIRCLEQ_INIT_ENTRY(req, queue_entry);
  80345. + req->buf = buf;
  80346. + req->dma = dma_buf;
  80347. + req->length = buflen;
  80348. + req->sent_zlp = zero;
  80349. + req->priv = req_handle;
  80350. +
  80351. + //DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  80352. + ep->dwc_ep.dma_addr = dma_buf;
  80353. + ep->dwc_ep.start_xfer_buff = buf;
  80354. + ep->dwc_ep.xfer_buff = buf;
  80355. + ep->dwc_ep.xfer_len = 0;
  80356. + ep->dwc_ep.xfer_count = 0;
  80357. + ep->dwc_ep.sent_zlp = 0;
  80358. + ep->dwc_ep.total_len = buflen;
  80359. +
  80360. + /* Add this request to the tail */
  80361. + DWC_CIRCLEQ_INSERT_TAIL(&ep->queue, req, queue_entry);
  80362. + ep->dwc_ep.xiso_queued_xfers++;
  80363. +
  80364. +//DWC_DEBUG("CP_0");
  80365. +//DWC_DEBUG("req->ext_req.tr_sub_flags=%d", req->ext_req.tr_sub_flags);
  80366. +//prn_ext_request((struct dwc_iso_xreq_port *) ereq_nonport);
  80367. +//prn_ext_request(&req->ext_req);
  80368. +
  80369. + //DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  80370. +
  80371. + /* If the req->status == ASAP then check if there is any active transfer
  80372. + * for this endpoint. If no active transfers, then get the first entry
  80373. + * from the queue and start that transfer
  80374. + */
  80375. + if (req->ext_req.tr_sub_flags == DWC_EREQ_TF_ASAP) {
  80376. + res = dwc_otg_pcd_xiso_start_next_request(pcd, ep);
  80377. + if (res) {
  80378. + DWC_WARN("Failed to start the next Isoc transfer");
  80379. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  80380. + DWC_FREE(req);
  80381. + return res;
  80382. + }
  80383. + }
  80384. +
  80385. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  80386. + return 0;
  80387. +}
  80388. +
  80389. +#endif
  80390. +/* END ifdef DWC_UTE_PER_IO ***************************************************/
  80391. +int dwc_otg_pcd_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  80392. + uint8_t * buf, dwc_dma_t dma_buf, uint32_t buflen,
  80393. + int zero, void *req_handle, int atomic_alloc)
  80394. +{
  80395. + dwc_irqflags_t flags;
  80396. + dwc_otg_pcd_request_t *req;
  80397. + dwc_otg_pcd_ep_t *ep;
  80398. + uint32_t max_transfer;
  80399. +
  80400. + ep = get_ep_from_handle(pcd, ep_handle);
  80401. + if (!ep || (!ep->desc && ep->dwc_ep.num != 0)) {
  80402. + DWC_WARN("bad ep\n");
  80403. + return -DWC_E_INVALID;
  80404. + }
  80405. +
  80406. + if (atomic_alloc) {
  80407. + req = DWC_ALLOC_ATOMIC(sizeof(*req));
  80408. + } else {
  80409. + req = DWC_ALLOC(sizeof(*req));
  80410. + }
  80411. +
  80412. + if (!req) {
  80413. + return -DWC_E_NO_MEMORY;
  80414. + }
  80415. + DWC_CIRCLEQ_INIT_ENTRY(req, queue_entry);
  80416. + if (!GET_CORE_IF(pcd)->core_params->opt) {
  80417. + if (ep->dwc_ep.num != 0) {
  80418. + DWC_ERROR("queue req %p, len %d buf %p\n",
  80419. + req_handle, buflen, buf);
  80420. + }
  80421. + }
  80422. +
  80423. + req->buf = buf;
  80424. + req->dma = dma_buf;
  80425. + req->length = buflen;
  80426. + req->sent_zlp = zero;
  80427. + req->priv = req_handle;
  80428. + req->dw_align_buf = NULL;
  80429. + if ((dma_buf & 0x3) && GET_CORE_IF(pcd)->dma_enable
  80430. + && !GET_CORE_IF(pcd)->dma_desc_enable)
  80431. + req->dw_align_buf = DWC_DMA_ALLOC(buflen,
  80432. + &req->dw_align_buf_dma);
  80433. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  80434. +
  80435. + /*
  80436. + * After adding request to the queue for IN ISOC wait for In Token Received
  80437. + * when TX FIFO is empty interrupt and for OUT ISOC wait for OUT Token
  80438. + * Received when EP is disabled interrupt to obtain starting microframe
  80439. + * (odd/even) start transfer
  80440. + */
  80441. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  80442. + if (req != 0) {
  80443. + depctl_data_t depctl = {.d32 =
  80444. + DWC_READ_REG32(&pcd->core_if->dev_if->
  80445. + in_ep_regs[ep->dwc_ep.num]->
  80446. + diepctl) };
  80447. + ++pcd->request_pending;
  80448. +
  80449. + DWC_CIRCLEQ_INSERT_TAIL(&ep->queue, req, queue_entry);
  80450. + if (ep->dwc_ep.is_in) {
  80451. + depctl.b.cnak = 1;
  80452. + DWC_WRITE_REG32(&pcd->core_if->dev_if->
  80453. + in_ep_regs[ep->dwc_ep.num]->
  80454. + diepctl, depctl.d32);
  80455. + }
  80456. +
  80457. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  80458. + }
  80459. + return 0;
  80460. + }
  80461. +
  80462. + /*
  80463. + * For EP0 IN without premature status, zlp is required?
  80464. + */
  80465. + if (ep->dwc_ep.num == 0 && ep->dwc_ep.is_in) {
  80466. + DWC_DEBUGPL(DBG_PCDV, "%d-OUT ZLP\n", ep->dwc_ep.num);
  80467. + //_req->zero = 1;
  80468. + }
  80469. +
  80470. + /* Start the transfer */
  80471. + if (DWC_CIRCLEQ_EMPTY(&ep->queue) && !ep->stopped) {
  80472. + /* EP0 Transfer? */
  80473. + if (ep->dwc_ep.num == 0) {
  80474. + switch (pcd->ep0state) {
  80475. + case EP0_IN_DATA_PHASE:
  80476. + DWC_DEBUGPL(DBG_PCD,
  80477. + "%s ep0: EP0_IN_DATA_PHASE\n",
  80478. + __func__);
  80479. + break;
  80480. +
  80481. + case EP0_OUT_DATA_PHASE:
  80482. + DWC_DEBUGPL(DBG_PCD,
  80483. + "%s ep0: EP0_OUT_DATA_PHASE\n",
  80484. + __func__);
  80485. + if (pcd->request_config) {
  80486. + /* Complete STATUS PHASE */
  80487. + ep->dwc_ep.is_in = 1;
  80488. + pcd->ep0state = EP0_IN_STATUS_PHASE;
  80489. + }
  80490. + break;
  80491. +
  80492. + case EP0_IN_STATUS_PHASE:
  80493. + DWC_DEBUGPL(DBG_PCD,
  80494. + "%s ep0: EP0_IN_STATUS_PHASE\n",
  80495. + __func__);
  80496. + break;
  80497. +
  80498. + default:
  80499. + DWC_DEBUGPL(DBG_ANY, "ep0: odd state %d\n",
  80500. + pcd->ep0state);
  80501. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  80502. + return -DWC_E_SHUTDOWN;
  80503. + }
  80504. +
  80505. + ep->dwc_ep.dma_addr = dma_buf;
  80506. + ep->dwc_ep.start_xfer_buff = buf;
  80507. + ep->dwc_ep.xfer_buff = buf;
  80508. + ep->dwc_ep.xfer_len = buflen;
  80509. + ep->dwc_ep.xfer_count = 0;
  80510. + ep->dwc_ep.sent_zlp = 0;
  80511. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  80512. +
  80513. + if (zero) {
  80514. + if ((ep->dwc_ep.xfer_len %
  80515. + ep->dwc_ep.maxpacket == 0)
  80516. + && (ep->dwc_ep.xfer_len != 0)) {
  80517. + ep->dwc_ep.sent_zlp = 1;
  80518. + }
  80519. +
  80520. + }
  80521. +
  80522. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd),
  80523. + &ep->dwc_ep);
  80524. + } // non-ep0 endpoints
  80525. + else {
  80526. +#ifdef DWC_UTE_CFI
  80527. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  80528. + /* store the request length */
  80529. + ep->dwc_ep.cfi_req_len = buflen;
  80530. + pcd->cfi->ops.build_descriptors(pcd->cfi, pcd,
  80531. + ep, req);
  80532. + } else {
  80533. +#endif
  80534. + max_transfer =
  80535. + GET_CORE_IF(ep->pcd)->core_params->
  80536. + max_transfer_size;
  80537. +
  80538. + /* Setup and start the Transfer */
  80539. + if (req->dw_align_buf){
  80540. + if (ep->dwc_ep.is_in)
  80541. + dwc_memcpy(req->dw_align_buf,
  80542. + buf, buflen);
  80543. + ep->dwc_ep.dma_addr =
  80544. + req->dw_align_buf_dma;
  80545. + ep->dwc_ep.start_xfer_buff =
  80546. + req->dw_align_buf;
  80547. + ep->dwc_ep.xfer_buff =
  80548. + req->dw_align_buf;
  80549. + } else {
  80550. + ep->dwc_ep.dma_addr = dma_buf;
  80551. + ep->dwc_ep.start_xfer_buff = buf;
  80552. + ep->dwc_ep.xfer_buff = buf;
  80553. + }
  80554. + ep->dwc_ep.xfer_len = 0;
  80555. + ep->dwc_ep.xfer_count = 0;
  80556. + ep->dwc_ep.sent_zlp = 0;
  80557. + ep->dwc_ep.total_len = buflen;
  80558. +
  80559. + ep->dwc_ep.maxxfer = max_transfer;
  80560. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  80561. + uint32_t out_max_xfer =
  80562. + DDMA_MAX_TRANSFER_SIZE -
  80563. + (DDMA_MAX_TRANSFER_SIZE % 4);
  80564. + if (ep->dwc_ep.is_in) {
  80565. + if (ep->dwc_ep.maxxfer >
  80566. + DDMA_MAX_TRANSFER_SIZE) {
  80567. + ep->dwc_ep.maxxfer =
  80568. + DDMA_MAX_TRANSFER_SIZE;
  80569. + }
  80570. + } else {
  80571. + if (ep->dwc_ep.maxxfer >
  80572. + out_max_xfer) {
  80573. + ep->dwc_ep.maxxfer =
  80574. + out_max_xfer;
  80575. + }
  80576. + }
  80577. + }
  80578. + if (ep->dwc_ep.maxxfer < ep->dwc_ep.total_len) {
  80579. + ep->dwc_ep.maxxfer -=
  80580. + (ep->dwc_ep.maxxfer %
  80581. + ep->dwc_ep.maxpacket);
  80582. + }
  80583. +
  80584. + if (zero) {
  80585. + if ((ep->dwc_ep.total_len %
  80586. + ep->dwc_ep.maxpacket == 0)
  80587. + && (ep->dwc_ep.total_len != 0)) {
  80588. + ep->dwc_ep.sent_zlp = 1;
  80589. + }
  80590. + }
  80591. +#ifdef DWC_UTE_CFI
  80592. + }
  80593. +#endif
  80594. + dwc_otg_ep_start_transfer(GET_CORE_IF(pcd),
  80595. + &ep->dwc_ep);
  80596. + }
  80597. + }
  80598. +
  80599. + if (req != 0) {
  80600. + ++pcd->request_pending;
  80601. + DWC_CIRCLEQ_INSERT_TAIL(&ep->queue, req, queue_entry);
  80602. + if (ep->dwc_ep.is_in && ep->stopped
  80603. + && !(GET_CORE_IF(pcd)->dma_enable)) {
  80604. + /** @todo NGS Create a function for this. */
  80605. + diepmsk_data_t diepmsk = {.d32 = 0 };
  80606. + diepmsk.b.intktxfemp = 1;
  80607. + if (GET_CORE_IF(pcd)->multiproc_int_enable) {
  80608. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->
  80609. + dev_if->dev_global_regs->diepeachintmsk
  80610. + [ep->dwc_ep.num], 0,
  80611. + diepmsk.d32);
  80612. + } else {
  80613. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->
  80614. + dev_if->dev_global_regs->
  80615. + diepmsk, 0, diepmsk.d32);
  80616. + }
  80617. +
  80618. + }
  80619. + }
  80620. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  80621. +
  80622. + return 0;
  80623. +}
  80624. +
  80625. +int dwc_otg_pcd_ep_dequeue(dwc_otg_pcd_t * pcd, void *ep_handle,
  80626. + void *req_handle)
  80627. +{
  80628. + dwc_irqflags_t flags;
  80629. + dwc_otg_pcd_request_t *req;
  80630. + dwc_otg_pcd_ep_t *ep;
  80631. +
  80632. + ep = get_ep_from_handle(pcd, ep_handle);
  80633. + if (!ep || (!ep->desc && ep->dwc_ep.num != 0)) {
  80634. + DWC_WARN("bad argument\n");
  80635. + return -DWC_E_INVALID;
  80636. + }
  80637. +
  80638. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  80639. +
  80640. + /* make sure it's actually queued on this endpoint */
  80641. + DWC_CIRCLEQ_FOREACH(req, &ep->queue, queue_entry) {
  80642. + if (req->priv == (void *)req_handle) {
  80643. + break;
  80644. + }
  80645. + }
  80646. +
  80647. + if (req->priv != (void *)req_handle) {
  80648. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  80649. + return -DWC_E_INVALID;
  80650. + }
  80651. +
  80652. + if (!DWC_CIRCLEQ_EMPTY_ENTRY(req, queue_entry)) {
  80653. + dwc_otg_request_done(ep, req, -DWC_E_RESTART);
  80654. + } else {
  80655. + req = NULL;
  80656. + }
  80657. +
  80658. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  80659. +
  80660. + return req ? 0 : -DWC_E_SHUTDOWN;
  80661. +
  80662. +}
  80663. +
  80664. +/**
  80665. + * dwc_otg_pcd_ep_wedge - sets the halt feature and ignores clear requests
  80666. + *
  80667. + * Use this to stall an endpoint and ignore CLEAR_FEATURE(HALT_ENDPOINT)
  80668. + * requests. If the gadget driver clears the halt status, it will
  80669. + * automatically unwedge the endpoint.
  80670. + *
  80671. + * Returns zero on success, else negative DWC error code.
  80672. + */
  80673. +int dwc_otg_pcd_ep_wedge(dwc_otg_pcd_t * pcd, void *ep_handle)
  80674. +{
  80675. + dwc_otg_pcd_ep_t *ep;
  80676. + dwc_irqflags_t flags;
  80677. + int retval = 0;
  80678. +
  80679. + ep = get_ep_from_handle(pcd, ep_handle);
  80680. +
  80681. + if ((!ep->desc && ep != &pcd->ep0) ||
  80682. + (ep->desc && (ep->desc->bmAttributes == UE_ISOCHRONOUS))) {
  80683. + DWC_WARN("%s, bad ep\n", __func__);
  80684. + return -DWC_E_INVALID;
  80685. + }
  80686. +
  80687. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  80688. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  80689. + DWC_WARN("%d %s XFer In process\n", ep->dwc_ep.num,
  80690. + ep->dwc_ep.is_in ? "IN" : "OUT");
  80691. + retval = -DWC_E_AGAIN;
  80692. + } else {
  80693. + /* This code needs to be reviewed */
  80694. + if (ep->dwc_ep.is_in == 1 && GET_CORE_IF(pcd)->dma_desc_enable) {
  80695. + dtxfsts_data_t txstatus;
  80696. + fifosize_data_t txfifosize;
  80697. +
  80698. + txfifosize.d32 =
  80699. + DWC_READ_REG32(&GET_CORE_IF(pcd)->
  80700. + core_global_regs->dtxfsiz[ep->dwc_ep.
  80701. + tx_fifo_num]);
  80702. + txstatus.d32 =
  80703. + DWC_READ_REG32(&GET_CORE_IF(pcd)->
  80704. + dev_if->in_ep_regs[ep->dwc_ep.num]->
  80705. + dtxfsts);
  80706. +
  80707. + if (txstatus.b.txfspcavail < txfifosize.b.depth) {
  80708. + DWC_WARN("%s() Data In Tx Fifo\n", __func__);
  80709. + retval = -DWC_E_AGAIN;
  80710. + } else {
  80711. + if (ep->dwc_ep.num == 0) {
  80712. + pcd->ep0state = EP0_STALL;
  80713. + }
  80714. +
  80715. + ep->stopped = 1;
  80716. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd),
  80717. + &ep->dwc_ep);
  80718. + }
  80719. + } else {
  80720. + if (ep->dwc_ep.num == 0) {
  80721. + pcd->ep0state = EP0_STALL;
  80722. + }
  80723. +
  80724. + ep->stopped = 1;
  80725. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  80726. + }
  80727. + }
  80728. +
  80729. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  80730. +
  80731. + return retval;
  80732. +}
  80733. +
  80734. +int dwc_otg_pcd_ep_halt(dwc_otg_pcd_t * pcd, void *ep_handle, int value)
  80735. +{
  80736. + dwc_otg_pcd_ep_t *ep;
  80737. + dwc_irqflags_t flags;
  80738. + int retval = 0;
  80739. +
  80740. + ep = get_ep_from_handle(pcd, ep_handle);
  80741. +
  80742. + if (!ep || (!ep->desc && ep != &pcd->ep0) ||
  80743. + (ep->desc && (ep->desc->bmAttributes == UE_ISOCHRONOUS))) {
  80744. + DWC_WARN("%s, bad ep\n", __func__);
  80745. + return -DWC_E_INVALID;
  80746. + }
  80747. +
  80748. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  80749. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  80750. + DWC_WARN("%d %s XFer In process\n", ep->dwc_ep.num,
  80751. + ep->dwc_ep.is_in ? "IN" : "OUT");
  80752. + retval = -DWC_E_AGAIN;
  80753. + } else if (value == 0) {
  80754. + dwc_otg_ep_clear_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  80755. + } else if (value == 1) {
  80756. + if (ep->dwc_ep.is_in == 1 && GET_CORE_IF(pcd)->dma_desc_enable) {
  80757. + dtxfsts_data_t txstatus;
  80758. + fifosize_data_t txfifosize;
  80759. +
  80760. + txfifosize.d32 =
  80761. + DWC_READ_REG32(&GET_CORE_IF(pcd)->core_global_regs->
  80762. + dtxfsiz[ep->dwc_ep.tx_fifo_num]);
  80763. + txstatus.d32 =
  80764. + DWC_READ_REG32(&GET_CORE_IF(pcd)->dev_if->
  80765. + in_ep_regs[ep->dwc_ep.num]->dtxfsts);
  80766. +
  80767. + if (txstatus.b.txfspcavail < txfifosize.b.depth) {
  80768. + DWC_WARN("%s() Data In Tx Fifo\n", __func__);
  80769. + retval = -DWC_E_AGAIN;
  80770. + } else {
  80771. + if (ep->dwc_ep.num == 0) {
  80772. + pcd->ep0state = EP0_STALL;
  80773. + }
  80774. +
  80775. + ep->stopped = 1;
  80776. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd),
  80777. + &ep->dwc_ep);
  80778. + }
  80779. + } else {
  80780. + if (ep->dwc_ep.num == 0) {
  80781. + pcd->ep0state = EP0_STALL;
  80782. + }
  80783. +
  80784. + ep->stopped = 1;
  80785. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  80786. + }
  80787. + } else if (value == 2) {
  80788. + ep->dwc_ep.stall_clear_flag = 0;
  80789. + } else if (value == 3) {
  80790. + ep->dwc_ep.stall_clear_flag = 1;
  80791. + }
  80792. +
  80793. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  80794. +
  80795. + return retval;
  80796. +}
  80797. +
  80798. +/**
  80799. + * This function initiates remote wakeup of the host from suspend state.
  80800. + */
  80801. +void dwc_otg_pcd_rem_wkup_from_suspend(dwc_otg_pcd_t * pcd, int set)
  80802. +{
  80803. + dctl_data_t dctl = { 0 };
  80804. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  80805. + dsts_data_t dsts;
  80806. +
  80807. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  80808. + if (!dsts.b.suspsts) {
  80809. + DWC_WARN("Remote wakeup while is not in suspend state\n");
  80810. + }
  80811. + /* Check if DEVICE_REMOTE_WAKEUP feature enabled */
  80812. + if (pcd->remote_wakeup_enable) {
  80813. + if (set) {
  80814. +
  80815. + if (core_if->adp_enable) {
  80816. + gpwrdn_data_t gpwrdn;
  80817. +
  80818. + dwc_otg_adp_probe_stop(core_if);
  80819. +
  80820. + /* Mask SRP detected interrupt from Power Down Logic */
  80821. + gpwrdn.d32 = 0;
  80822. + gpwrdn.b.srp_det_msk = 1;
  80823. + DWC_MODIFY_REG32(&core_if->
  80824. + core_global_regs->gpwrdn,
  80825. + gpwrdn.d32, 0);
  80826. +
  80827. + /* Disable Power Down Logic */
  80828. + gpwrdn.d32 = 0;
  80829. + gpwrdn.b.pmuactv = 1;
  80830. + DWC_MODIFY_REG32(&core_if->
  80831. + core_global_regs->gpwrdn,
  80832. + gpwrdn.d32, 0);
  80833. +
  80834. + /*
  80835. + * Initialize the Core for Device mode.
  80836. + */
  80837. + core_if->op_state = B_PERIPHERAL;
  80838. + dwc_otg_core_init(core_if);
  80839. + dwc_otg_enable_global_interrupts(core_if);
  80840. + cil_pcd_start(core_if);
  80841. +
  80842. + dwc_otg_initiate_srp(core_if);
  80843. + }
  80844. +
  80845. + dctl.b.rmtwkupsig = 1;
  80846. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  80847. + dctl, 0, dctl.d32);
  80848. + DWC_DEBUGPL(DBG_PCD, "Set Remote Wakeup\n");
  80849. +
  80850. + dwc_mdelay(2);
  80851. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  80852. + dctl, dctl.d32, 0);
  80853. + DWC_DEBUGPL(DBG_PCD, "Clear Remote Wakeup\n");
  80854. + }
  80855. + } else {
  80856. + DWC_DEBUGPL(DBG_PCD, "Remote Wakeup is disabled\n");
  80857. + }
  80858. +}
  80859. +
  80860. +#ifdef CONFIG_USB_DWC_OTG_LPM
  80861. +/**
  80862. + * This function initiates remote wakeup of the host from L1 sleep state.
  80863. + */
  80864. +void dwc_otg_pcd_rem_wkup_from_sleep(dwc_otg_pcd_t * pcd, int set)
  80865. +{
  80866. + glpmcfg_data_t lpmcfg;
  80867. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  80868. +
  80869. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  80870. +
  80871. + /* Check if we are in L1 state */
  80872. + if (!lpmcfg.b.prt_sleep_sts) {
  80873. + DWC_DEBUGPL(DBG_PCD, "Device is not in sleep state\n");
  80874. + return;
  80875. + }
  80876. +
  80877. + /* Check if host allows remote wakeup */
  80878. + if (!lpmcfg.b.rem_wkup_en) {
  80879. + DWC_DEBUGPL(DBG_PCD, "Host does not allow remote wakeup\n");
  80880. + return;
  80881. + }
  80882. +
  80883. + /* Check if Resume OK */
  80884. + if (!lpmcfg.b.sleep_state_resumeok) {
  80885. + DWC_DEBUGPL(DBG_PCD, "Sleep state resume is not OK\n");
  80886. + return;
  80887. + }
  80888. +
  80889. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  80890. + lpmcfg.b.en_utmi_sleep = 0;
  80891. + lpmcfg.b.hird_thres &= (~(1 << 4));
  80892. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  80893. +
  80894. + if (set) {
  80895. + dctl_data_t dctl = {.d32 = 0 };
  80896. + dctl.b.rmtwkupsig = 1;
  80897. + /* Set RmtWkUpSig bit to start remote wakup signaling.
  80898. + * Hardware will automatically clear this bit.
  80899. + */
  80900. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl,
  80901. + 0, dctl.d32);
  80902. + DWC_DEBUGPL(DBG_PCD, "Set Remote Wakeup\n");
  80903. + }
  80904. +
  80905. +}
  80906. +#endif
  80907. +
  80908. +/**
  80909. + * Performs remote wakeup.
  80910. + */
  80911. +void dwc_otg_pcd_remote_wakeup(dwc_otg_pcd_t * pcd, int set)
  80912. +{
  80913. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  80914. + dwc_irqflags_t flags;
  80915. + if (dwc_otg_is_device_mode(core_if)) {
  80916. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  80917. +#ifdef CONFIG_USB_DWC_OTG_LPM
  80918. + if (core_if->lx_state == DWC_OTG_L1) {
  80919. + dwc_otg_pcd_rem_wkup_from_sleep(pcd, set);
  80920. + } else {
  80921. +#endif
  80922. + dwc_otg_pcd_rem_wkup_from_suspend(pcd, set);
  80923. +#ifdef CONFIG_USB_DWC_OTG_LPM
  80924. + }
  80925. +#endif
  80926. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  80927. + }
  80928. + return;
  80929. +}
  80930. +
  80931. +void dwc_otg_pcd_disconnect_us(dwc_otg_pcd_t * pcd, int no_of_usecs)
  80932. +{
  80933. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  80934. + dctl_data_t dctl = { 0 };
  80935. +
  80936. + if (dwc_otg_is_device_mode(core_if)) {
  80937. + dctl.b.sftdiscon = 1;
  80938. + DWC_PRINTF("Soft disconnect for %d useconds\n",no_of_usecs);
  80939. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  80940. + dwc_udelay(no_of_usecs);
  80941. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32,0);
  80942. +
  80943. + } else{
  80944. + DWC_PRINTF("NOT SUPPORTED IN HOST MODE\n");
  80945. + }
  80946. + return;
  80947. +
  80948. +}
  80949. +
  80950. +int dwc_otg_pcd_wakeup(dwc_otg_pcd_t * pcd)
  80951. +{
  80952. + dsts_data_t dsts;
  80953. + gotgctl_data_t gotgctl;
  80954. +
  80955. + /*
  80956. + * This function starts the Protocol if no session is in progress. If
  80957. + * a session is already in progress, but the device is suspended,
  80958. + * remote wakeup signaling is started.
  80959. + */
  80960. +
  80961. + /* Check if valid session */
  80962. + gotgctl.d32 =
  80963. + DWC_READ_REG32(&(GET_CORE_IF(pcd)->core_global_regs->gotgctl));
  80964. + if (gotgctl.b.bsesvld) {
  80965. + /* Check if suspend state */
  80966. + dsts.d32 =
  80967. + DWC_READ_REG32(&
  80968. + (GET_CORE_IF(pcd)->dev_if->
  80969. + dev_global_regs->dsts));
  80970. + if (dsts.b.suspsts) {
  80971. + dwc_otg_pcd_remote_wakeup(pcd, 1);
  80972. + }
  80973. + } else {
  80974. + dwc_otg_pcd_initiate_srp(pcd);
  80975. + }
  80976. +
  80977. + return 0;
  80978. +
  80979. +}
  80980. +
  80981. +/**
  80982. + * Start the SRP timer to detect when the SRP does not complete within
  80983. + * 6 seconds.
  80984. + *
  80985. + * @param pcd the pcd structure.
  80986. + */
  80987. +void dwc_otg_pcd_initiate_srp(dwc_otg_pcd_t * pcd)
  80988. +{
  80989. + dwc_irqflags_t flags;
  80990. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  80991. + dwc_otg_initiate_srp(GET_CORE_IF(pcd));
  80992. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  80993. +}
  80994. +
  80995. +int dwc_otg_pcd_get_frame_number(dwc_otg_pcd_t * pcd)
  80996. +{
  80997. + return dwc_otg_get_frame_number(GET_CORE_IF(pcd));
  80998. +}
  80999. +
  81000. +int dwc_otg_pcd_is_lpm_enabled(dwc_otg_pcd_t * pcd)
  81001. +{
  81002. + return GET_CORE_IF(pcd)->core_params->lpm_enable;
  81003. +}
  81004. +
  81005. +uint32_t get_b_hnp_enable(dwc_otg_pcd_t * pcd)
  81006. +{
  81007. + return pcd->b_hnp_enable;
  81008. +}
  81009. +
  81010. +uint32_t get_a_hnp_support(dwc_otg_pcd_t * pcd)
  81011. +{
  81012. + return pcd->a_hnp_support;
  81013. +}
  81014. +
  81015. +uint32_t get_a_alt_hnp_support(dwc_otg_pcd_t * pcd)
  81016. +{
  81017. + return pcd->a_alt_hnp_support;
  81018. +}
  81019. +
  81020. +int dwc_otg_pcd_get_rmwkup_enable(dwc_otg_pcd_t * pcd)
  81021. +{
  81022. + return pcd->remote_wakeup_enable;
  81023. +}
  81024. +
  81025. +#endif /* DWC_HOST_ONLY */
  81026. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_pcd.h linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_pcd.h
  81027. --- linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_pcd.h 1970-01-01 01:00:00.000000000 +0100
  81028. +++ linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_pcd.h 2014-02-17 22:41:01.000000000 +0100
  81029. @@ -0,0 +1,266 @@
  81030. +/* ==========================================================================
  81031. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd.h $
  81032. + * $Revision: #48 $
  81033. + * $Date: 2012/08/10 $
  81034. + * $Change: 2047372 $
  81035. + *
  81036. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  81037. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  81038. + * otherwise expressly agreed to in writing between Synopsys and you.
  81039. + *
  81040. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  81041. + * any End User Software License Agreement or Agreement for Licensed Product
  81042. + * with Synopsys or any supplement thereto. You are permitted to use and
  81043. + * redistribute this Software in source and binary forms, with or without
  81044. + * modification, provided that redistributions of source code must retain this
  81045. + * notice. You may not view, use, disclose, copy or distribute this file or
  81046. + * any information contained herein except pursuant to this license grant from
  81047. + * Synopsys. If you do not agree with this notice, including the disclaimer
  81048. + * below, then you are not authorized to use the Software.
  81049. + *
  81050. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  81051. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  81052. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  81053. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  81054. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  81055. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  81056. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  81057. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  81058. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  81059. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  81060. + * DAMAGE.
  81061. + * ========================================================================== */
  81062. +#ifndef DWC_HOST_ONLY
  81063. +#if !defined(__DWC_PCD_H__)
  81064. +#define __DWC_PCD_H__
  81065. +
  81066. +#include "dwc_otg_os_dep.h"
  81067. +#include "usb.h"
  81068. +#include "dwc_otg_cil.h"
  81069. +#include "dwc_otg_pcd_if.h"
  81070. +struct cfiobject;
  81071. +
  81072. +/**
  81073. + * @file
  81074. + *
  81075. + * This file contains the structures, constants, and interfaces for
  81076. + * the Perpherial Contoller Driver (PCD).
  81077. + *
  81078. + * The Peripheral Controller Driver (PCD) for Linux will implement the
  81079. + * Gadget API, so that the existing Gadget drivers can be used. For
  81080. + * the Mass Storage Function driver the File-backed USB Storage Gadget
  81081. + * (FBS) driver will be used. The FBS driver supports the
  81082. + * Control-Bulk (CB), Control-Bulk-Interrupt (CBI), and Bulk-Only
  81083. + * transports.
  81084. + *
  81085. + */
  81086. +
  81087. +/** Invalid DMA Address */
  81088. +#define DWC_DMA_ADDR_INVALID (~(dwc_dma_t)0)
  81089. +
  81090. +/** Max Transfer size for any EP */
  81091. +#define DDMA_MAX_TRANSFER_SIZE 65535
  81092. +
  81093. +/**
  81094. + * Get the pointer to the core_if from the pcd pointer.
  81095. + */
  81096. +#define GET_CORE_IF( _pcd ) (_pcd->core_if)
  81097. +
  81098. +/**
  81099. + * States of EP0.
  81100. + */
  81101. +typedef enum ep0_state {
  81102. + EP0_DISCONNECT, /* no host */
  81103. + EP0_IDLE,
  81104. + EP0_IN_DATA_PHASE,
  81105. + EP0_OUT_DATA_PHASE,
  81106. + EP0_IN_STATUS_PHASE,
  81107. + EP0_OUT_STATUS_PHASE,
  81108. + EP0_STALL,
  81109. +} ep0state_e;
  81110. +
  81111. +/** Fordward declaration.*/
  81112. +struct dwc_otg_pcd;
  81113. +
  81114. +/** DWC_otg iso request structure.
  81115. + *
  81116. + */
  81117. +typedef struct usb_iso_request dwc_otg_pcd_iso_request_t;
  81118. +
  81119. +#ifdef DWC_UTE_PER_IO
  81120. +
  81121. +/**
  81122. + * This shall be the exact analogy of the same type structure defined in the
  81123. + * usb_gadget.h. Each descriptor contains
  81124. + */
  81125. +struct dwc_iso_pkt_desc_port {
  81126. + uint32_t offset;
  81127. + uint32_t length; /* expected length */
  81128. + uint32_t actual_length;
  81129. + uint32_t status;
  81130. +};
  81131. +
  81132. +struct dwc_iso_xreq_port {
  81133. + /** transfer/submission flag */
  81134. + uint32_t tr_sub_flags;
  81135. + /** Start the request ASAP */
  81136. +#define DWC_EREQ_TF_ASAP 0x00000002
  81137. + /** Just enqueue the request w/o initiating a transfer */
  81138. +#define DWC_EREQ_TF_ENQUEUE 0x00000004
  81139. +
  81140. + /**
  81141. + * count of ISO packets attached to this request - shall
  81142. + * not exceed the pio_alloc_pkt_count
  81143. + */
  81144. + uint32_t pio_pkt_count;
  81145. + /** count of ISO packets allocated for this request */
  81146. + uint32_t pio_alloc_pkt_count;
  81147. + /** number of ISO packet errors */
  81148. + uint32_t error_count;
  81149. + /** reserved for future extension */
  81150. + uint32_t res;
  81151. + /** Will be allocated and freed in the UTE gadget and based on the CFC value */
  81152. + struct dwc_iso_pkt_desc_port *per_io_frame_descs;
  81153. +};
  81154. +#endif
  81155. +/** DWC_otg request structure.
  81156. + * This structure is a list of requests.
  81157. + */
  81158. +typedef struct dwc_otg_pcd_request {
  81159. + void *priv;
  81160. + void *buf;
  81161. + dwc_dma_t dma;
  81162. + uint32_t length;
  81163. + uint32_t actual;
  81164. + unsigned sent_zlp:1;
  81165. + /**
  81166. + * Used instead of original buffer if
  81167. + * it(physical address) is not dword-aligned.
  81168. + **/
  81169. + uint8_t *dw_align_buf;
  81170. + dwc_dma_t dw_align_buf_dma;
  81171. +
  81172. + DWC_CIRCLEQ_ENTRY(dwc_otg_pcd_request) queue_entry;
  81173. +#ifdef DWC_UTE_PER_IO
  81174. + struct dwc_iso_xreq_port ext_req;
  81175. + //void *priv_ereq_nport; /* */
  81176. +#endif
  81177. +} dwc_otg_pcd_request_t;
  81178. +
  81179. +DWC_CIRCLEQ_HEAD(req_list, dwc_otg_pcd_request);
  81180. +
  81181. +/** PCD EP structure.
  81182. + * This structure describes an EP, there is an array of EPs in the PCD
  81183. + * structure.
  81184. + */
  81185. +typedef struct dwc_otg_pcd_ep {
  81186. + /** USB EP Descriptor */
  81187. + const usb_endpoint_descriptor_t *desc;
  81188. +
  81189. + /** queue of dwc_otg_pcd_requests. */
  81190. + struct req_list queue;
  81191. + unsigned stopped:1;
  81192. + unsigned disabling:1;
  81193. + unsigned dma:1;
  81194. + unsigned queue_sof:1;
  81195. +
  81196. +#ifdef DWC_EN_ISOC
  81197. + /** ISOC req handle passed */
  81198. + void *iso_req_handle;
  81199. +#endif //_EN_ISOC_
  81200. +
  81201. + /** DWC_otg ep data. */
  81202. + dwc_ep_t dwc_ep;
  81203. +
  81204. + /** Pointer to PCD */
  81205. + struct dwc_otg_pcd *pcd;
  81206. +
  81207. + void *priv;
  81208. +} dwc_otg_pcd_ep_t;
  81209. +
  81210. +/** DWC_otg PCD Structure.
  81211. + * This structure encapsulates the data for the dwc_otg PCD.
  81212. + */
  81213. +struct dwc_otg_pcd {
  81214. + const struct dwc_otg_pcd_function_ops *fops;
  81215. + /** The DWC otg device pointer */
  81216. + struct dwc_otg_device *otg_dev;
  81217. + /** Core Interface */
  81218. + dwc_otg_core_if_t *core_if;
  81219. + /** State of EP0 */
  81220. + ep0state_e ep0state;
  81221. + /** EP0 Request is pending */
  81222. + unsigned ep0_pending:1;
  81223. + /** Indicates when SET CONFIGURATION Request is in process */
  81224. + unsigned request_config:1;
  81225. + /** The state of the Remote Wakeup Enable. */
  81226. + unsigned remote_wakeup_enable:1;
  81227. + /** The state of the B-Device HNP Enable. */
  81228. + unsigned b_hnp_enable:1;
  81229. + /** The state of A-Device HNP Support. */
  81230. + unsigned a_hnp_support:1;
  81231. + /** The state of the A-Device Alt HNP support. */
  81232. + unsigned a_alt_hnp_support:1;
  81233. + /** Count of pending Requests */
  81234. + unsigned request_pending;
  81235. +
  81236. + /** SETUP packet for EP0
  81237. + * This structure is allocated as a DMA buffer on PCD initialization
  81238. + * with enough space for up to 3 setup packets.
  81239. + */
  81240. + union {
  81241. + usb_device_request_t req;
  81242. + uint32_t d32[2];
  81243. + } *setup_pkt;
  81244. +
  81245. + dwc_dma_t setup_pkt_dma_handle;
  81246. +
  81247. + /* Additional buffer and flag for CTRL_WR premature case */
  81248. + uint8_t *backup_buf;
  81249. + unsigned data_terminated;
  81250. +
  81251. + /** 2-byte dma buffer used to return status from GET_STATUS */
  81252. + uint16_t *status_buf;
  81253. + dwc_dma_t status_buf_dma_handle;
  81254. +
  81255. + /** EP0 */
  81256. + dwc_otg_pcd_ep_t ep0;
  81257. +
  81258. + /** Array of IN EPs. */
  81259. + dwc_otg_pcd_ep_t in_ep[MAX_EPS_CHANNELS - 1];
  81260. + /** Array of OUT EPs. */
  81261. + dwc_otg_pcd_ep_t out_ep[MAX_EPS_CHANNELS - 1];
  81262. + /** number of valid EPs in the above array. */
  81263. +// unsigned num_eps : 4;
  81264. + dwc_spinlock_t *lock;
  81265. +
  81266. + /** Tasklet to defer starting of TEST mode transmissions until
  81267. + * Status Phase has been completed.
  81268. + */
  81269. + dwc_tasklet_t *test_mode_tasklet;
  81270. +
  81271. + /** Tasklet to delay starting of xfer in DMA mode */
  81272. + dwc_tasklet_t *start_xfer_tasklet;
  81273. +
  81274. + /** The test mode to enter when the tasklet is executed. */
  81275. + unsigned test_mode;
  81276. + /** The cfi_api structure that implements most of the CFI API
  81277. + * and OTG specific core configuration functionality
  81278. + */
  81279. +#ifdef DWC_UTE_CFI
  81280. + struct cfiobject *cfi;
  81281. +#endif
  81282. +
  81283. +};
  81284. +
  81285. +//FIXME this functions should be static, and this prototypes should be removed
  81286. +extern void dwc_otg_request_nuke(dwc_otg_pcd_ep_t * ep);
  81287. +extern void dwc_otg_request_done(dwc_otg_pcd_ep_t * ep,
  81288. + dwc_otg_pcd_request_t * req, int32_t status);
  81289. +
  81290. +void dwc_otg_iso_buffer_done(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep,
  81291. + void *req_handle);
  81292. +
  81293. +extern void do_test_mode(void *data);
  81294. +#endif
  81295. +#endif /* DWC_HOST_ONLY */
  81296. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h
  81297. --- linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h 1970-01-01 01:00:00.000000000 +0100
  81298. +++ linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h 2014-02-17 22:41:01.000000000 +0100
  81299. @@ -0,0 +1,360 @@
  81300. +/* ==========================================================================
  81301. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd_if.h $
  81302. + * $Revision: #11 $
  81303. + * $Date: 2011/10/26 $
  81304. + * $Change: 1873028 $
  81305. + *
  81306. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  81307. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  81308. + * otherwise expressly agreed to in writing between Synopsys and you.
  81309. + *
  81310. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  81311. + * any End User Software License Agreement or Agreement for Licensed Product
  81312. + * with Synopsys or any supplement thereto. You are permitted to use and
  81313. + * redistribute this Software in source and binary forms, with or without
  81314. + * modification, provided that redistributions of source code must retain this
  81315. + * notice. You may not view, use, disclose, copy or distribute this file or
  81316. + * any information contained herein except pursuant to this license grant from
  81317. + * Synopsys. If you do not agree with this notice, including the disclaimer
  81318. + * below, then you are not authorized to use the Software.
  81319. + *
  81320. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  81321. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  81322. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  81323. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  81324. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  81325. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  81326. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  81327. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  81328. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  81329. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  81330. + * DAMAGE.
  81331. + * ========================================================================== */
  81332. +#ifndef DWC_HOST_ONLY
  81333. +
  81334. +#if !defined(__DWC_PCD_IF_H__)
  81335. +#define __DWC_PCD_IF_H__
  81336. +
  81337. +//#include "dwc_os.h"
  81338. +#include "dwc_otg_core_if.h"
  81339. +
  81340. +/** @file
  81341. + * This file defines DWC_OTG PCD Core API.
  81342. + */
  81343. +
  81344. +struct dwc_otg_pcd;
  81345. +typedef struct dwc_otg_pcd dwc_otg_pcd_t;
  81346. +
  81347. +/** Maxpacket size for EP0 */
  81348. +#define MAX_EP0_SIZE 64
  81349. +/** Maxpacket size for any EP */
  81350. +#define MAX_PACKET_SIZE 1024
  81351. +
  81352. +/** @name Function Driver Callbacks */
  81353. +/** @{ */
  81354. +
  81355. +/** This function will be called whenever a previously queued request has
  81356. + * completed. The status value will be set to -DWC_E_SHUTDOWN to indicated a
  81357. + * failed or aborted transfer, or -DWC_E_RESTART to indicate the device was reset,
  81358. + * or -DWC_E_TIMEOUT to indicate it timed out, or -DWC_E_INVALID to indicate invalid
  81359. + * parameters. */
  81360. +typedef int (*dwc_completion_cb_t) (dwc_otg_pcd_t * pcd, void *ep_handle,
  81361. + void *req_handle, int32_t status,
  81362. + uint32_t actual);
  81363. +/**
  81364. + * This function will be called whenever a previousle queued ISOC request has
  81365. + * completed. Count of ISOC packets could be read using dwc_otg_pcd_get_iso_packet_count
  81366. + * function.
  81367. + * The status of each ISOC packet could be read using dwc_otg_pcd_get_iso_packet_*
  81368. + * functions.
  81369. + */
  81370. +typedef int (*dwc_isoc_completion_cb_t) (dwc_otg_pcd_t * pcd, void *ep_handle,
  81371. + void *req_handle, int proc_buf_num);
  81372. +/** This function should handle any SETUP request that cannot be handled by the
  81373. + * PCD Core. This includes most GET_DESCRIPTORs, SET_CONFIGS, Any
  81374. + * class-specific requests, etc. The function must non-blocking.
  81375. + *
  81376. + * Returns 0 on success.
  81377. + * Returns -DWC_E_NOT_SUPPORTED if the request is not supported.
  81378. + * Returns -DWC_E_INVALID if the setup request had invalid parameters or bytes.
  81379. + * Returns -DWC_E_SHUTDOWN on any other error. */
  81380. +typedef int (*dwc_setup_cb_t) (dwc_otg_pcd_t * pcd, uint8_t * bytes);
  81381. +/** This is called whenever the device has been disconnected. The function
  81382. + * driver should take appropriate action to clean up all pending requests in the
  81383. + * PCD Core, remove all endpoints (except ep0), and initialize back to reset
  81384. + * state. */
  81385. +typedef int (*dwc_disconnect_cb_t) (dwc_otg_pcd_t * pcd);
  81386. +/** This function is called when device has been connected. */
  81387. +typedef int (*dwc_connect_cb_t) (dwc_otg_pcd_t * pcd, int speed);
  81388. +/** This function is called when device has been suspended */
  81389. +typedef int (*dwc_suspend_cb_t) (dwc_otg_pcd_t * pcd);
  81390. +/** This function is called when device has received LPM tokens, i.e.
  81391. + * device has been sent to sleep state. */
  81392. +typedef int (*dwc_sleep_cb_t) (dwc_otg_pcd_t * pcd);
  81393. +/** This function is called when device has been resumed
  81394. + * from suspend(L2) or L1 sleep state. */
  81395. +typedef int (*dwc_resume_cb_t) (dwc_otg_pcd_t * pcd);
  81396. +/** This function is called whenever hnp params has been changed.
  81397. + * User can call get_b_hnp_enable, get_a_hnp_support, get_a_alt_hnp_support functions
  81398. + * to get hnp parameters. */
  81399. +typedef int (*dwc_hnp_params_changed_cb_t) (dwc_otg_pcd_t * pcd);
  81400. +/** This function is called whenever USB RESET is detected. */
  81401. +typedef int (*dwc_reset_cb_t) (dwc_otg_pcd_t * pcd);
  81402. +
  81403. +typedef int (*cfi_setup_cb_t) (dwc_otg_pcd_t * pcd, void *ctrl_req_bytes);
  81404. +
  81405. +/**
  81406. + *
  81407. + * @param ep_handle Void pointer to the usb_ep structure
  81408. + * @param ereq_port Pointer to the extended request structure created in the
  81409. + * portable part.
  81410. + */
  81411. +typedef int (*xiso_completion_cb_t) (dwc_otg_pcd_t * pcd, void *ep_handle,
  81412. + void *req_handle, int32_t status,
  81413. + void *ereq_port);
  81414. +/** Function Driver Ops Data Structure */
  81415. +struct dwc_otg_pcd_function_ops {
  81416. + dwc_connect_cb_t connect;
  81417. + dwc_disconnect_cb_t disconnect;
  81418. + dwc_setup_cb_t setup;
  81419. + dwc_completion_cb_t complete;
  81420. + dwc_isoc_completion_cb_t isoc_complete;
  81421. + dwc_suspend_cb_t suspend;
  81422. + dwc_sleep_cb_t sleep;
  81423. + dwc_resume_cb_t resume;
  81424. + dwc_reset_cb_t reset;
  81425. + dwc_hnp_params_changed_cb_t hnp_changed;
  81426. + cfi_setup_cb_t cfi_setup;
  81427. +#ifdef DWC_UTE_PER_IO
  81428. + xiso_completion_cb_t xisoc_complete;
  81429. +#endif
  81430. +};
  81431. +/** @} */
  81432. +
  81433. +/** @name Function Driver Functions */
  81434. +/** @{ */
  81435. +
  81436. +/** Call this function to get pointer on dwc_otg_pcd_t,
  81437. + * this pointer will be used for all PCD API functions.
  81438. + *
  81439. + * @param core_if The DWC_OTG Core
  81440. + */
  81441. +extern dwc_otg_pcd_t *dwc_otg_pcd_init(dwc_otg_core_if_t * core_if);
  81442. +
  81443. +/** Frees PCD allocated by dwc_otg_pcd_init
  81444. + *
  81445. + * @param pcd The PCD
  81446. + */
  81447. +extern void dwc_otg_pcd_remove(dwc_otg_pcd_t * pcd);
  81448. +
  81449. +/** Call this to bind the function driver to the PCD Core.
  81450. + *
  81451. + * @param pcd Pointer on dwc_otg_pcd_t returned by dwc_otg_pcd_init function.
  81452. + * @param fops The Function Driver Ops data structure containing pointers to all callbacks.
  81453. + */
  81454. +extern void dwc_otg_pcd_start(dwc_otg_pcd_t * pcd,
  81455. + const struct dwc_otg_pcd_function_ops *fops);
  81456. +
  81457. +/** Enables an endpoint for use. This function enables an endpoint in
  81458. + * the PCD. The endpoint is described by the ep_desc which has the
  81459. + * same format as a USB ep descriptor. The ep_handle parameter is used to refer
  81460. + * to the endpoint from other API functions and in callbacks. Normally this
  81461. + * should be called after a SET_CONFIGURATION/SET_INTERFACE to configure the
  81462. + * core for that interface.
  81463. + *
  81464. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  81465. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  81466. + * Returns 0 on success.
  81467. + *
  81468. + * @param pcd The PCD
  81469. + * @param ep_desc Endpoint descriptor
  81470. + * @param usb_ep Handle on endpoint, that will be used to identify endpoint.
  81471. + */
  81472. +extern int dwc_otg_pcd_ep_enable(dwc_otg_pcd_t * pcd,
  81473. + const uint8_t * ep_desc, void *usb_ep);
  81474. +
  81475. +/** Disable the endpoint referenced by ep_handle.
  81476. + *
  81477. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  81478. + * Returns -DWC_E_SHUTDOWN if any other error occurred.
  81479. + * Returns 0 on success. */
  81480. +extern int dwc_otg_pcd_ep_disable(dwc_otg_pcd_t * pcd, void *ep_handle);
  81481. +
  81482. +/** Queue a data transfer request on the endpoint referenced by ep_handle.
  81483. + * After the transfer is completes, the complete callback will be called with
  81484. + * the request status.
  81485. + *
  81486. + * @param pcd The PCD
  81487. + * @param ep_handle The handle of the endpoint
  81488. + * @param buf The buffer for the data
  81489. + * @param dma_buf The DMA buffer for the data
  81490. + * @param buflen The length of the data transfer
  81491. + * @param zero Specifies whether to send zero length last packet.
  81492. + * @param req_handle Set this handle to any value to use to reference this
  81493. + * request in the ep_dequeue function or from the complete callback
  81494. + * @param atomic_alloc If driver need to perform atomic allocations
  81495. + * for internal data structures.
  81496. + *
  81497. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  81498. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  81499. + * Returns 0 on success. */
  81500. +extern int dwc_otg_pcd_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  81501. + uint8_t * buf, dwc_dma_t dma_buf,
  81502. + uint32_t buflen, int zero, void *req_handle,
  81503. + int atomic_alloc);
  81504. +#ifdef DWC_UTE_PER_IO
  81505. +/**
  81506. + *
  81507. + * @param ereq_nonport Pointer to the extended request part of the
  81508. + * usb_request structure defined in usb_gadget.h file.
  81509. + */
  81510. +extern int dwc_otg_pcd_xiso_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  81511. + uint8_t * buf, dwc_dma_t dma_buf,
  81512. + uint32_t buflen, int zero,
  81513. + void *req_handle, int atomic_alloc,
  81514. + void *ereq_nonport);
  81515. +
  81516. +#endif
  81517. +
  81518. +/** De-queue the specified data transfer that has not yet completed.
  81519. + *
  81520. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  81521. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  81522. + * Returns 0 on success. */
  81523. +extern int dwc_otg_pcd_ep_dequeue(dwc_otg_pcd_t * pcd, void *ep_handle,
  81524. + void *req_handle);
  81525. +
  81526. +/** Halt (STALL) an endpoint or clear it.
  81527. + *
  81528. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  81529. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  81530. + * Returns -DWC_E_AGAIN if the STALL cannot be sent and must be tried again later
  81531. + * Returns 0 on success. */
  81532. +extern int dwc_otg_pcd_ep_halt(dwc_otg_pcd_t * pcd, void *ep_handle, int value);
  81533. +
  81534. +/** This function */
  81535. +extern int dwc_otg_pcd_ep_wedge(dwc_otg_pcd_t * pcd, void *ep_handle);
  81536. +
  81537. +/** This function should be called on every hardware interrupt */
  81538. +extern int32_t dwc_otg_pcd_handle_intr(dwc_otg_pcd_t * pcd);
  81539. +
  81540. +/** This function returns current frame number */
  81541. +extern int dwc_otg_pcd_get_frame_number(dwc_otg_pcd_t * pcd);
  81542. +
  81543. +/**
  81544. + * Start isochronous transfers on the endpoint referenced by ep_handle.
  81545. + * For isochronous transfers duble buffering is used.
  81546. + * After processing each of buffers comlete callback will be called with
  81547. + * status for each transaction.
  81548. + *
  81549. + * @param pcd The PCD
  81550. + * @param ep_handle The handle of the endpoint
  81551. + * @param buf0 The virtual address of first data buffer
  81552. + * @param buf1 The virtual address of second data buffer
  81553. + * @param dma0 The DMA address of first data buffer
  81554. + * @param dma1 The DMA address of second data buffer
  81555. + * @param sync_frame Data pattern frame number
  81556. + * @param dp_frame Data size for pattern frame
  81557. + * @param data_per_frame Data size for regular frame
  81558. + * @param start_frame Frame number to start transfers, if -1 then start transfers ASAP.
  81559. + * @param buf_proc_intrvl Interval of ISOC Buffer processing
  81560. + * @param req_handle Handle of ISOC request
  81561. + * @param atomic_alloc Specefies whether to perform atomic allocation for
  81562. + * internal data structures.
  81563. + *
  81564. + * Returns -DWC_E_NO_MEMORY if there is no enough memory.
  81565. + * Returns -DWC_E_INVALID if incorrect arguments are passed to the function.
  81566. + * Returns -DW_E_SHUTDOWN for any other error.
  81567. + * Returns 0 on success
  81568. + */
  81569. +extern int dwc_otg_pcd_iso_ep_start(dwc_otg_pcd_t * pcd, void *ep_handle,
  81570. + uint8_t * buf0, uint8_t * buf1,
  81571. + dwc_dma_t dma0, dwc_dma_t dma1,
  81572. + int sync_frame, int dp_frame,
  81573. + int data_per_frame, int start_frame,
  81574. + int buf_proc_intrvl, void *req_handle,
  81575. + int atomic_alloc);
  81576. +
  81577. +/** Stop ISOC transfers on endpoint referenced by ep_handle.
  81578. + *
  81579. + * @param pcd The PCD
  81580. + * @param ep_handle The handle of the endpoint
  81581. + * @param req_handle Handle of ISOC request
  81582. + *
  81583. + * Returns -DWC_E_INVALID if incorrect arguments are passed to the function
  81584. + * Returns 0 on success
  81585. + */
  81586. +int dwc_otg_pcd_iso_ep_stop(dwc_otg_pcd_t * pcd, void *ep_handle,
  81587. + void *req_handle);
  81588. +
  81589. +/** Get ISOC packet status.
  81590. + *
  81591. + * @param pcd The PCD
  81592. + * @param ep_handle The handle of the endpoint
  81593. + * @param iso_req_handle Isochronoush request handle
  81594. + * @param packet Number of packet
  81595. + * @param status Out parameter for returning status
  81596. + * @param actual Out parameter for returning actual length
  81597. + * @param offset Out parameter for returning offset
  81598. + *
  81599. + */
  81600. +extern void dwc_otg_pcd_get_iso_packet_params(dwc_otg_pcd_t * pcd,
  81601. + void *ep_handle,
  81602. + void *iso_req_handle, int packet,
  81603. + int *status, int *actual,
  81604. + int *offset);
  81605. +
  81606. +/** Get ISOC packet count.
  81607. + *
  81608. + * @param pcd The PCD
  81609. + * @param ep_handle The handle of the endpoint
  81610. + * @param iso_req_handle
  81611. + */
  81612. +extern int dwc_otg_pcd_get_iso_packet_count(dwc_otg_pcd_t * pcd,
  81613. + void *ep_handle,
  81614. + void *iso_req_handle);
  81615. +
  81616. +/** This function starts the SRP Protocol if no session is in progress. If
  81617. + * a session is already in progress, but the device is suspended,
  81618. + * remote wakeup signaling is started.
  81619. + */
  81620. +extern int dwc_otg_pcd_wakeup(dwc_otg_pcd_t * pcd);
  81621. +
  81622. +/** This function returns 1 if LPM support is enabled, and 0 otherwise. */
  81623. +extern int dwc_otg_pcd_is_lpm_enabled(dwc_otg_pcd_t * pcd);
  81624. +
  81625. +/** This function returns 1 if remote wakeup is allowed and 0, otherwise. */
  81626. +extern int dwc_otg_pcd_get_rmwkup_enable(dwc_otg_pcd_t * pcd);
  81627. +
  81628. +/** Initiate SRP */
  81629. +extern void dwc_otg_pcd_initiate_srp(dwc_otg_pcd_t * pcd);
  81630. +
  81631. +/** Starts remote wakeup signaling. */
  81632. +extern void dwc_otg_pcd_remote_wakeup(dwc_otg_pcd_t * pcd, int set);
  81633. +
  81634. +/** Starts micorsecond soft disconnect. */
  81635. +extern void dwc_otg_pcd_disconnect_us(dwc_otg_pcd_t * pcd, int no_of_usecs);
  81636. +/** This function returns whether device is dualspeed.*/
  81637. +extern uint32_t dwc_otg_pcd_is_dualspeed(dwc_otg_pcd_t * pcd);
  81638. +
  81639. +/** This function returns whether device is otg. */
  81640. +extern uint32_t dwc_otg_pcd_is_otg(dwc_otg_pcd_t * pcd);
  81641. +
  81642. +/** These functions allow to get hnp parameters */
  81643. +extern uint32_t get_b_hnp_enable(dwc_otg_pcd_t * pcd);
  81644. +extern uint32_t get_a_hnp_support(dwc_otg_pcd_t * pcd);
  81645. +extern uint32_t get_a_alt_hnp_support(dwc_otg_pcd_t * pcd);
  81646. +
  81647. +/** CFI specific Interface functions */
  81648. +/** Allocate a cfi buffer */
  81649. +extern uint8_t *cfiw_ep_alloc_buffer(dwc_otg_pcd_t * pcd, void *pep,
  81650. + dwc_dma_t * addr, size_t buflen,
  81651. + int flags);
  81652. +
  81653. +/******************************************************************************/
  81654. +
  81655. +/** @} */
  81656. +
  81657. +#endif /* __DWC_PCD_IF_H__ */
  81658. +
  81659. +#endif /* DWC_HOST_ONLY */
  81660. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c
  81661. --- linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c 1970-01-01 01:00:00.000000000 +0100
  81662. +++ linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c 2014-02-17 22:41:01.000000000 +0100
  81663. @@ -0,0 +1,5147 @@
  81664. +/* ==========================================================================
  81665. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd_intr.c $
  81666. + * $Revision: #116 $
  81667. + * $Date: 2012/08/10 $
  81668. + * $Change: 2047372 $
  81669. + *
  81670. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  81671. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  81672. + * otherwise expressly agreed to in writing between Synopsys and you.
  81673. + *
  81674. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  81675. + * any End User Software License Agreement or Agreement for Licensed Product
  81676. + * with Synopsys or any supplement thereto. You are permitted to use and
  81677. + * redistribute this Software in source and binary forms, with or without
  81678. + * modification, provided that redistributions of source code must retain this
  81679. + * notice. You may not view, use, disclose, copy or distribute this file or
  81680. + * any information contained herein except pursuant to this license grant from
  81681. + * Synopsys. If you do not agree with this notice, including the disclaimer
  81682. + * below, then you are not authorized to use the Software.
  81683. + *
  81684. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  81685. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  81686. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  81687. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  81688. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  81689. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  81690. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  81691. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  81692. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  81693. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  81694. + * DAMAGE.
  81695. + * ========================================================================== */
  81696. +#ifndef DWC_HOST_ONLY
  81697. +
  81698. +#include "dwc_otg_pcd.h"
  81699. +
  81700. +#ifdef DWC_UTE_CFI
  81701. +#include "dwc_otg_cfi.h"
  81702. +#endif
  81703. +
  81704. +#ifdef DWC_UTE_PER_IO
  81705. +extern void complete_xiso_ep(dwc_otg_pcd_ep_t * ep);
  81706. +#endif
  81707. +//#define PRINT_CFI_DMA_DESCS
  81708. +
  81709. +#define DEBUG_EP0
  81710. +
  81711. +/**
  81712. + * This function updates OTG.
  81713. + */
  81714. +static void dwc_otg_pcd_update_otg(dwc_otg_pcd_t * pcd, const unsigned reset)
  81715. +{
  81716. +
  81717. + if (reset) {
  81718. + pcd->b_hnp_enable = 0;
  81719. + pcd->a_hnp_support = 0;
  81720. + pcd->a_alt_hnp_support = 0;
  81721. + }
  81722. +
  81723. + if (pcd->fops->hnp_changed) {
  81724. + pcd->fops->hnp_changed(pcd);
  81725. + }
  81726. +}
  81727. +
  81728. +/** @file
  81729. + * This file contains the implementation of the PCD Interrupt handlers.
  81730. + *
  81731. + * The PCD handles the device interrupts. Many conditions can cause a
  81732. + * device interrupt. When an interrupt occurs, the device interrupt
  81733. + * service routine determines the cause of the interrupt and
  81734. + * dispatches handling to the appropriate function. These interrupt
  81735. + * handling functions are described below.
  81736. + * All interrupt registers are processed from LSB to MSB.
  81737. + */
  81738. +
  81739. +/**
  81740. + * This function prints the ep0 state for debug purposes.
  81741. + */
  81742. +static inline void print_ep0_state(dwc_otg_pcd_t * pcd)
  81743. +{
  81744. +#ifdef DEBUG
  81745. + char str[40];
  81746. +
  81747. + switch (pcd->ep0state) {
  81748. + case EP0_DISCONNECT:
  81749. + dwc_strcpy(str, "EP0_DISCONNECT");
  81750. + break;
  81751. + case EP0_IDLE:
  81752. + dwc_strcpy(str, "EP0_IDLE");
  81753. + break;
  81754. + case EP0_IN_DATA_PHASE:
  81755. + dwc_strcpy(str, "EP0_IN_DATA_PHASE");
  81756. + break;
  81757. + case EP0_OUT_DATA_PHASE:
  81758. + dwc_strcpy(str, "EP0_OUT_DATA_PHASE");
  81759. + break;
  81760. + case EP0_IN_STATUS_PHASE:
  81761. + dwc_strcpy(str, "EP0_IN_STATUS_PHASE");
  81762. + break;
  81763. + case EP0_OUT_STATUS_PHASE:
  81764. + dwc_strcpy(str, "EP0_OUT_STATUS_PHASE");
  81765. + break;
  81766. + case EP0_STALL:
  81767. + dwc_strcpy(str, "EP0_STALL");
  81768. + break;
  81769. + default:
  81770. + dwc_strcpy(str, "EP0_INVALID");
  81771. + }
  81772. +
  81773. + DWC_DEBUGPL(DBG_ANY, "%s(%d)\n", str, pcd->ep0state);
  81774. +#endif
  81775. +}
  81776. +
  81777. +/**
  81778. + * This function calculate the size of the payload in the memory
  81779. + * for out endpoints and prints size for debug purposes(used in
  81780. + * 2.93a DevOutNak feature).
  81781. + */
  81782. +static inline void print_memory_payload(dwc_otg_pcd_t * pcd, dwc_ep_t * ep)
  81783. +{
  81784. +#ifdef DEBUG
  81785. + deptsiz_data_t deptsiz_init = {.d32 = 0 };
  81786. + deptsiz_data_t deptsiz_updt = {.d32 = 0 };
  81787. + int pack_num;
  81788. + unsigned payload;
  81789. +
  81790. + deptsiz_init.d32 = pcd->core_if->start_doeptsiz_val[ep->num];
  81791. + deptsiz_updt.d32 =
  81792. + DWC_READ_REG32(&pcd->core_if->dev_if->
  81793. + out_ep_regs[ep->num]->doeptsiz);
  81794. + /* Payload will be */
  81795. + payload = deptsiz_init.b.xfersize - deptsiz_updt.b.xfersize;
  81796. + /* Packet count is decremented every time a packet
  81797. + * is written to the RxFIFO not in to the external memory
  81798. + * So, if payload == 0, then it means no packet was sent to ext memory*/
  81799. + pack_num = (!payload) ? 0 : (deptsiz_init.b.pktcnt - deptsiz_updt.b.pktcnt);
  81800. + DWC_DEBUGPL(DBG_PCDV,
  81801. + "Payload for EP%d-%s\n",
  81802. + ep->num, (ep->is_in ? "IN" : "OUT"));
  81803. + DWC_DEBUGPL(DBG_PCDV,
  81804. + "Number of transfered bytes = 0x%08x\n", payload);
  81805. + DWC_DEBUGPL(DBG_PCDV,
  81806. + "Number of transfered packets = %d\n", pack_num);
  81807. +#endif
  81808. +}
  81809. +
  81810. +
  81811. +#ifdef DWC_UTE_CFI
  81812. +static inline void print_desc(struct dwc_otg_dma_desc *ddesc,
  81813. + const uint8_t * epname, int descnum)
  81814. +{
  81815. + CFI_INFO
  81816. + ("%s DMA_DESC(%d) buf=0x%08x bytes=0x%04x; sp=0x%x; l=0x%x; sts=0x%02x; bs=0x%02x\n",
  81817. + epname, descnum, ddesc->buf, ddesc->status.b.bytes,
  81818. + ddesc->status.b.sp, ddesc->status.b.l, ddesc->status.b.sts,
  81819. + ddesc->status.b.bs);
  81820. +}
  81821. +#endif
  81822. +
  81823. +/**
  81824. + * This function returns pointer to in ep struct with number ep_num
  81825. + */
  81826. +static inline dwc_otg_pcd_ep_t *get_in_ep(dwc_otg_pcd_t * pcd, uint32_t ep_num)
  81827. +{
  81828. + int i;
  81829. + int num_in_eps = GET_CORE_IF(pcd)->dev_if->num_in_eps;
  81830. + if (ep_num == 0) {
  81831. + return &pcd->ep0;
  81832. + } else {
  81833. + for (i = 0; i < num_in_eps; ++i) {
  81834. + if (pcd->in_ep[i].dwc_ep.num == ep_num)
  81835. + return &pcd->in_ep[i];
  81836. + }
  81837. + return 0;
  81838. + }
  81839. +}
  81840. +
  81841. +/**
  81842. + * This function returns pointer to out ep struct with number ep_num
  81843. + */
  81844. +static inline dwc_otg_pcd_ep_t *get_out_ep(dwc_otg_pcd_t * pcd, uint32_t ep_num)
  81845. +{
  81846. + int i;
  81847. + int num_out_eps = GET_CORE_IF(pcd)->dev_if->num_out_eps;
  81848. + if (ep_num == 0) {
  81849. + return &pcd->ep0;
  81850. + } else {
  81851. + for (i = 0; i < num_out_eps; ++i) {
  81852. + if (pcd->out_ep[i].dwc_ep.num == ep_num)
  81853. + return &pcd->out_ep[i];
  81854. + }
  81855. + return 0;
  81856. + }
  81857. +}
  81858. +
  81859. +/**
  81860. + * This functions gets a pointer to an EP from the wIndex address
  81861. + * value of the control request.
  81862. + */
  81863. +dwc_otg_pcd_ep_t *get_ep_by_addr(dwc_otg_pcd_t * pcd, u16 wIndex)
  81864. +{
  81865. + dwc_otg_pcd_ep_t *ep;
  81866. + uint32_t ep_num = UE_GET_ADDR(wIndex);
  81867. +
  81868. + if (ep_num == 0) {
  81869. + ep = &pcd->ep0;
  81870. + } else if (UE_GET_DIR(wIndex) == UE_DIR_IN) { /* in ep */
  81871. + ep = &pcd->in_ep[ep_num - 1];
  81872. + } else {
  81873. + ep = &pcd->out_ep[ep_num - 1];
  81874. + }
  81875. +
  81876. + return ep;
  81877. +}
  81878. +
  81879. +/**
  81880. + * This function checks the EP request queue, if the queue is not
  81881. + * empty the next request is started.
  81882. + */
  81883. +void start_next_request(dwc_otg_pcd_ep_t * ep)
  81884. +{
  81885. + dwc_otg_pcd_request_t *req = 0;
  81886. + uint32_t max_transfer =
  81887. + GET_CORE_IF(ep->pcd)->core_params->max_transfer_size;
  81888. +
  81889. +#ifdef DWC_UTE_CFI
  81890. + struct dwc_otg_pcd *pcd;
  81891. + pcd = ep->pcd;
  81892. +#endif
  81893. +
  81894. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  81895. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  81896. +
  81897. +#ifdef DWC_UTE_CFI
  81898. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  81899. + ep->dwc_ep.cfi_req_len = req->length;
  81900. + pcd->cfi->ops.build_descriptors(pcd->cfi, pcd, ep, req);
  81901. + } else {
  81902. +#endif
  81903. + /* Setup and start the Transfer */
  81904. + if (req->dw_align_buf) {
  81905. + ep->dwc_ep.dma_addr = req->dw_align_buf_dma;
  81906. + ep->dwc_ep.start_xfer_buff = req->dw_align_buf;
  81907. + ep->dwc_ep.xfer_buff = req->dw_align_buf;
  81908. + } else {
  81909. + ep->dwc_ep.dma_addr = req->dma;
  81910. + ep->dwc_ep.start_xfer_buff = req->buf;
  81911. + ep->dwc_ep.xfer_buff = req->buf;
  81912. + }
  81913. + ep->dwc_ep.sent_zlp = 0;
  81914. + ep->dwc_ep.total_len = req->length;
  81915. + ep->dwc_ep.xfer_len = 0;
  81916. + ep->dwc_ep.xfer_count = 0;
  81917. +
  81918. + ep->dwc_ep.maxxfer = max_transfer;
  81919. + if (GET_CORE_IF(ep->pcd)->dma_desc_enable) {
  81920. + uint32_t out_max_xfer = DDMA_MAX_TRANSFER_SIZE
  81921. + - (DDMA_MAX_TRANSFER_SIZE % 4);
  81922. + if (ep->dwc_ep.is_in) {
  81923. + if (ep->dwc_ep.maxxfer >
  81924. + DDMA_MAX_TRANSFER_SIZE) {
  81925. + ep->dwc_ep.maxxfer =
  81926. + DDMA_MAX_TRANSFER_SIZE;
  81927. + }
  81928. + } else {
  81929. + if (ep->dwc_ep.maxxfer > out_max_xfer) {
  81930. + ep->dwc_ep.maxxfer =
  81931. + out_max_xfer;
  81932. + }
  81933. + }
  81934. + }
  81935. + if (ep->dwc_ep.maxxfer < ep->dwc_ep.total_len) {
  81936. + ep->dwc_ep.maxxfer -=
  81937. + (ep->dwc_ep.maxxfer % ep->dwc_ep.maxpacket);
  81938. + }
  81939. + if (req->sent_zlp) {
  81940. + if ((ep->dwc_ep.total_len %
  81941. + ep->dwc_ep.maxpacket == 0)
  81942. + && (ep->dwc_ep.total_len != 0)) {
  81943. + ep->dwc_ep.sent_zlp = 1;
  81944. + }
  81945. +
  81946. + }
  81947. +#ifdef DWC_UTE_CFI
  81948. + }
  81949. +#endif
  81950. + dwc_otg_ep_start_transfer(GET_CORE_IF(ep->pcd), &ep->dwc_ep);
  81951. + } else if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  81952. + DWC_PRINTF("There are no more ISOC requests \n");
  81953. + ep->dwc_ep.frame_num = 0xFFFFFFFF;
  81954. + }
  81955. +}
  81956. +
  81957. +/**
  81958. + * This function handles the SOF Interrupts. At this time the SOF
  81959. + * Interrupt is disabled.
  81960. + */
  81961. +int32_t dwc_otg_pcd_handle_sof_intr(dwc_otg_pcd_t * pcd)
  81962. +{
  81963. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  81964. +
  81965. + gintsts_data_t gintsts;
  81966. +
  81967. + DWC_DEBUGPL(DBG_PCD, "SOF\n");
  81968. +
  81969. + /* Clear interrupt */
  81970. + gintsts.d32 = 0;
  81971. + gintsts.b.sofintr = 1;
  81972. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  81973. +
  81974. + return 1;
  81975. +}
  81976. +
  81977. +/**
  81978. + * This function handles the Rx Status Queue Level Interrupt, which
  81979. + * indicates that there is a least one packet in the Rx FIFO. The
  81980. + * packets are moved from the FIFO to memory, where they will be
  81981. + * processed when the Endpoint Interrupt Register indicates Transfer
  81982. + * Complete or SETUP Phase Done.
  81983. + *
  81984. + * Repeat the following until the Rx Status Queue is empty:
  81985. + * -# Read the Receive Status Pop Register (GRXSTSP) to get Packet
  81986. + * info
  81987. + * -# If Receive FIFO is empty then skip to step Clear the interrupt
  81988. + * and exit
  81989. + * -# If SETUP Packet call dwc_otg_read_setup_packet to copy the
  81990. + * SETUP data to the buffer
  81991. + * -# If OUT Data Packet call dwc_otg_read_packet to copy the data
  81992. + * to the destination buffer
  81993. + */
  81994. +int32_t dwc_otg_pcd_handle_rx_status_q_level_intr(dwc_otg_pcd_t * pcd)
  81995. +{
  81996. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  81997. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  81998. + gintmsk_data_t gintmask = {.d32 = 0 };
  81999. + device_grxsts_data_t status;
  82000. + dwc_otg_pcd_ep_t *ep;
  82001. + gintsts_data_t gintsts;
  82002. +#ifdef DEBUG
  82003. + static char *dpid_str[] = { "D0", "D2", "D1", "MDATA" };
  82004. +#endif
  82005. +
  82006. + //DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, _pcd);
  82007. + /* Disable the Rx Status Queue Level interrupt */
  82008. + gintmask.b.rxstsqlvl = 1;
  82009. + DWC_MODIFY_REG32(&global_regs->gintmsk, gintmask.d32, 0);
  82010. +
  82011. + /* Get the Status from the top of the FIFO */
  82012. + status.d32 = DWC_READ_REG32(&global_regs->grxstsp);
  82013. +
  82014. + DWC_DEBUGPL(DBG_PCD, "EP:%d BCnt:%d DPID:%s "
  82015. + "pktsts:%x Frame:%d(0x%0x)\n",
  82016. + status.b.epnum, status.b.bcnt,
  82017. + dpid_str[status.b.dpid],
  82018. + status.b.pktsts, status.b.fn, status.b.fn);
  82019. + /* Get pointer to EP structure */
  82020. + ep = get_out_ep(pcd, status.b.epnum);
  82021. +
  82022. + switch (status.b.pktsts) {
  82023. + case DWC_DSTS_GOUT_NAK:
  82024. + DWC_DEBUGPL(DBG_PCDV, "Global OUT NAK\n");
  82025. + break;
  82026. + case DWC_STS_DATA_UPDT:
  82027. + DWC_DEBUGPL(DBG_PCDV, "OUT Data Packet\n");
  82028. + if (status.b.bcnt && ep->dwc_ep.xfer_buff) {
  82029. + /** @todo NGS Check for buffer overflow? */
  82030. + dwc_otg_read_packet(core_if,
  82031. + ep->dwc_ep.xfer_buff,
  82032. + status.b.bcnt);
  82033. + ep->dwc_ep.xfer_count += status.b.bcnt;
  82034. + ep->dwc_ep.xfer_buff += status.b.bcnt;
  82035. + }
  82036. + break;
  82037. + case DWC_STS_XFER_COMP:
  82038. + DWC_DEBUGPL(DBG_PCDV, "OUT Complete\n");
  82039. + break;
  82040. + case DWC_DSTS_SETUP_COMP:
  82041. +#ifdef DEBUG_EP0
  82042. + DWC_DEBUGPL(DBG_PCDV, "Setup Complete\n");
  82043. +#endif
  82044. + break;
  82045. + case DWC_DSTS_SETUP_UPDT:
  82046. + dwc_otg_read_setup_packet(core_if, pcd->setup_pkt->d32);
  82047. +#ifdef DEBUG_EP0
  82048. + DWC_DEBUGPL(DBG_PCD,
  82049. + "SETUP PKT: %02x.%02x v%04x i%04x l%04x\n",
  82050. + pcd->setup_pkt->req.bmRequestType,
  82051. + pcd->setup_pkt->req.bRequest,
  82052. + UGETW(pcd->setup_pkt->req.wValue),
  82053. + UGETW(pcd->setup_pkt->req.wIndex),
  82054. + UGETW(pcd->setup_pkt->req.wLength));
  82055. +#endif
  82056. + ep->dwc_ep.xfer_count += status.b.bcnt;
  82057. + break;
  82058. + default:
  82059. + DWC_DEBUGPL(DBG_PCDV, "Invalid Packet Status (0x%0x)\n",
  82060. + status.b.pktsts);
  82061. + break;
  82062. + }
  82063. +
  82064. + /* Enable the Rx Status Queue Level interrupt */
  82065. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmask.d32);
  82066. + /* Clear interrupt */
  82067. + gintsts.d32 = 0;
  82068. + gintsts.b.rxstsqlvl = 1;
  82069. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  82070. +
  82071. + //DWC_DEBUGPL(DBG_PCDV, "EXIT: %s\n", __func__);
  82072. + return 1;
  82073. +}
  82074. +
  82075. +/**
  82076. + * This function examines the Device IN Token Learning Queue to
  82077. + * determine the EP number of the last IN token received. This
  82078. + * implementation is for the Mass Storage device where there are only
  82079. + * 2 IN EPs (Control-IN and BULK-IN).
  82080. + *
  82081. + * The EP numbers for the first six IN Tokens are in DTKNQR1 and there
  82082. + * are 8 EP Numbers in each of the other possible DTKNQ Registers.
  82083. + *
  82084. + * @param core_if Programming view of DWC_otg controller.
  82085. + *
  82086. + */
  82087. +static inline int get_ep_of_last_in_token(dwc_otg_core_if_t * core_if)
  82088. +{
  82089. + dwc_otg_device_global_regs_t *dev_global_regs =
  82090. + core_if->dev_if->dev_global_regs;
  82091. + const uint32_t TOKEN_Q_DEPTH = core_if->hwcfg2.b.dev_token_q_depth;
  82092. + /* Number of Token Queue Registers */
  82093. + const int DTKNQ_REG_CNT = (TOKEN_Q_DEPTH + 7) / 8;
  82094. + dtknq1_data_t dtknqr1;
  82095. + uint32_t in_tkn_epnums[4];
  82096. + int ndx = 0;
  82097. + int i = 0;
  82098. + volatile uint32_t *addr = &dev_global_regs->dtknqr1;
  82099. + int epnum = 0;
  82100. +
  82101. + //DWC_DEBUGPL(DBG_PCD,"dev_token_q_depth=%d\n",TOKEN_Q_DEPTH);
  82102. +
  82103. + /* Read the DTKNQ Registers */
  82104. + for (i = 0; i < DTKNQ_REG_CNT; i++) {
  82105. + in_tkn_epnums[i] = DWC_READ_REG32(addr);
  82106. + DWC_DEBUGPL(DBG_PCDV, "DTKNQR%d=0x%08x\n", i + 1,
  82107. + in_tkn_epnums[i]);
  82108. + if (addr == &dev_global_regs->dvbusdis) {
  82109. + addr = &dev_global_regs->dtknqr3_dthrctl;
  82110. + } else {
  82111. + ++addr;
  82112. + }
  82113. +
  82114. + }
  82115. +
  82116. + /* Copy the DTKNQR1 data to the bit field. */
  82117. + dtknqr1.d32 = in_tkn_epnums[0];
  82118. + /* Get the EP numbers */
  82119. + in_tkn_epnums[0] = dtknqr1.b.epnums0_5;
  82120. + ndx = dtknqr1.b.intknwptr - 1;
  82121. +
  82122. + //DWC_DEBUGPL(DBG_PCDV,"ndx=%d\n",ndx);
  82123. + if (ndx == -1) {
  82124. + /** @todo Find a simpler way to calculate the max
  82125. + * queue position.*/
  82126. + int cnt = TOKEN_Q_DEPTH;
  82127. + if (TOKEN_Q_DEPTH <= 6) {
  82128. + cnt = TOKEN_Q_DEPTH - 1;
  82129. + } else if (TOKEN_Q_DEPTH <= 14) {
  82130. + cnt = TOKEN_Q_DEPTH - 7;
  82131. + } else if (TOKEN_Q_DEPTH <= 22) {
  82132. + cnt = TOKEN_Q_DEPTH - 15;
  82133. + } else {
  82134. + cnt = TOKEN_Q_DEPTH - 23;
  82135. + }
  82136. + epnum = (in_tkn_epnums[DTKNQ_REG_CNT - 1] >> (cnt * 4)) & 0xF;
  82137. + } else {
  82138. + if (ndx <= 5) {
  82139. + epnum = (in_tkn_epnums[0] >> (ndx * 4)) & 0xF;
  82140. + } else if (ndx <= 13) {
  82141. + ndx -= 6;
  82142. + epnum = (in_tkn_epnums[1] >> (ndx * 4)) & 0xF;
  82143. + } else if (ndx <= 21) {
  82144. + ndx -= 14;
  82145. + epnum = (in_tkn_epnums[2] >> (ndx * 4)) & 0xF;
  82146. + } else if (ndx <= 29) {
  82147. + ndx -= 22;
  82148. + epnum = (in_tkn_epnums[3] >> (ndx * 4)) & 0xF;
  82149. + }
  82150. + }
  82151. + //DWC_DEBUGPL(DBG_PCD,"epnum=%d\n",epnum);
  82152. + return epnum;
  82153. +}
  82154. +
  82155. +/**
  82156. + * This interrupt occurs when the non-periodic Tx FIFO is half-empty.
  82157. + * The active request is checked for the next packet to be loaded into
  82158. + * the non-periodic Tx FIFO.
  82159. + */
  82160. +int32_t dwc_otg_pcd_handle_np_tx_fifo_empty_intr(dwc_otg_pcd_t * pcd)
  82161. +{
  82162. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  82163. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  82164. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  82165. + gnptxsts_data_t txstatus = {.d32 = 0 };
  82166. + gintsts_data_t gintsts;
  82167. +
  82168. + int epnum = 0;
  82169. + dwc_otg_pcd_ep_t *ep = 0;
  82170. + uint32_t len = 0;
  82171. + int dwords;
  82172. +
  82173. + /* Get the epnum from the IN Token Learning Queue. */
  82174. + epnum = get_ep_of_last_in_token(core_if);
  82175. + ep = get_in_ep(pcd, epnum);
  82176. +
  82177. + DWC_DEBUGPL(DBG_PCD, "NP TxFifo Empty: %d \n", epnum);
  82178. +
  82179. + ep_regs = core_if->dev_if->in_ep_regs[epnum];
  82180. +
  82181. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  82182. + if (len > ep->dwc_ep.maxpacket) {
  82183. + len = ep->dwc_ep.maxpacket;
  82184. + }
  82185. + dwords = (len + 3) / 4;
  82186. +
  82187. + /* While there is space in the queue and space in the FIFO and
  82188. + * More data to tranfer, Write packets to the Tx FIFO */
  82189. + txstatus.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  82190. + DWC_DEBUGPL(DBG_PCDV, "b4 GNPTXSTS=0x%08x\n", txstatus.d32);
  82191. +
  82192. + while (txstatus.b.nptxqspcavail > 0 &&
  82193. + txstatus.b.nptxfspcavail > dwords &&
  82194. + ep->dwc_ep.xfer_count < ep->dwc_ep.xfer_len) {
  82195. + /* Write the FIFO */
  82196. + dwc_otg_ep_write_packet(core_if, &ep->dwc_ep, 0);
  82197. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  82198. +
  82199. + if (len > ep->dwc_ep.maxpacket) {
  82200. + len = ep->dwc_ep.maxpacket;
  82201. + }
  82202. +
  82203. + dwords = (len + 3) / 4;
  82204. + txstatus.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  82205. + DWC_DEBUGPL(DBG_PCDV, "GNPTXSTS=0x%08x\n", txstatus.d32);
  82206. + }
  82207. +
  82208. + DWC_DEBUGPL(DBG_PCDV, "GNPTXSTS=0x%08x\n",
  82209. + DWC_READ_REG32(&global_regs->gnptxsts));
  82210. +
  82211. + /* Clear interrupt */
  82212. + gintsts.d32 = 0;
  82213. + gintsts.b.nptxfempty = 1;
  82214. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  82215. +
  82216. + return 1;
  82217. +}
  82218. +
  82219. +/**
  82220. + * This function is called when dedicated Tx FIFO Empty interrupt occurs.
  82221. + * The active request is checked for the next packet to be loaded into
  82222. + * apropriate Tx FIFO.
  82223. + */
  82224. +static int32_t write_empty_tx_fifo(dwc_otg_pcd_t * pcd, uint32_t epnum)
  82225. +{
  82226. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  82227. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  82228. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  82229. + dtxfsts_data_t txstatus = {.d32 = 0 };
  82230. + dwc_otg_pcd_ep_t *ep = 0;
  82231. + uint32_t len = 0;
  82232. + int dwords;
  82233. +
  82234. + ep = get_in_ep(pcd, epnum);
  82235. +
  82236. + DWC_DEBUGPL(DBG_PCD, "Dedicated TxFifo Empty: %d \n", epnum);
  82237. +
  82238. + ep_regs = core_if->dev_if->in_ep_regs[epnum];
  82239. +
  82240. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  82241. +
  82242. + if (len > ep->dwc_ep.maxpacket) {
  82243. + len = ep->dwc_ep.maxpacket;
  82244. + }
  82245. +
  82246. + dwords = (len + 3) / 4;
  82247. +
  82248. + /* While there is space in the queue and space in the FIFO and
  82249. + * More data to tranfer, Write packets to the Tx FIFO */
  82250. + txstatus.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  82251. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum, txstatus.d32);
  82252. +
  82253. + while (txstatus.b.txfspcavail > dwords &&
  82254. + ep->dwc_ep.xfer_count < ep->dwc_ep.xfer_len &&
  82255. + ep->dwc_ep.xfer_len != 0) {
  82256. + /* Write the FIFO */
  82257. + dwc_otg_ep_write_packet(core_if, &ep->dwc_ep, 0);
  82258. +
  82259. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  82260. + if (len > ep->dwc_ep.maxpacket) {
  82261. + len = ep->dwc_ep.maxpacket;
  82262. + }
  82263. +
  82264. + dwords = (len + 3) / 4;
  82265. + txstatus.d32 =
  82266. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  82267. + DWC_DEBUGPL(DBG_PCDV, "dtxfsts[%d]=0x%08x\n", epnum,
  82268. + txstatus.d32);
  82269. + }
  82270. +
  82271. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum,
  82272. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts));
  82273. +
  82274. + return 1;
  82275. +}
  82276. +
  82277. +/**
  82278. + * This function is called when the Device is disconnected. It stops
  82279. + * any active requests and informs the Gadget driver of the
  82280. + * disconnect.
  82281. + */
  82282. +void dwc_otg_pcd_stop(dwc_otg_pcd_t * pcd)
  82283. +{
  82284. + int i, num_in_eps, num_out_eps;
  82285. + dwc_otg_pcd_ep_t *ep;
  82286. +
  82287. + gintmsk_data_t intr_mask = {.d32 = 0 };
  82288. +
  82289. + DWC_SPINLOCK(pcd->lock);
  82290. +
  82291. + num_in_eps = GET_CORE_IF(pcd)->dev_if->num_in_eps;
  82292. + num_out_eps = GET_CORE_IF(pcd)->dev_if->num_out_eps;
  82293. +
  82294. + DWC_DEBUGPL(DBG_PCDV, "%s() \n", __func__);
  82295. + /* don't disconnect drivers more than once */
  82296. + if (pcd->ep0state == EP0_DISCONNECT) {
  82297. + DWC_DEBUGPL(DBG_ANY, "%s() Already Disconnected\n", __func__);
  82298. + DWC_SPINUNLOCK(pcd->lock);
  82299. + return;
  82300. + }
  82301. + pcd->ep0state = EP0_DISCONNECT;
  82302. +
  82303. + /* Reset the OTG state. */
  82304. + dwc_otg_pcd_update_otg(pcd, 1);
  82305. +
  82306. + /* Disable the NP Tx Fifo Empty Interrupt. */
  82307. + intr_mask.b.nptxfempty = 1;
  82308. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  82309. + intr_mask.d32, 0);
  82310. +
  82311. + /* Flush the FIFOs */
  82312. + /**@todo NGS Flush Periodic FIFOs */
  82313. + dwc_otg_flush_tx_fifo(GET_CORE_IF(pcd), 0x10);
  82314. + dwc_otg_flush_rx_fifo(GET_CORE_IF(pcd));
  82315. +
  82316. + /* prevent new request submissions, kill any outstanding requests */
  82317. + ep = &pcd->ep0;
  82318. + dwc_otg_request_nuke(ep);
  82319. + /* prevent new request submissions, kill any outstanding requests */
  82320. + for (i = 0; i < num_in_eps; i++) {
  82321. + dwc_otg_pcd_ep_t *ep = &pcd->in_ep[i];
  82322. + dwc_otg_request_nuke(ep);
  82323. + }
  82324. + /* prevent new request submissions, kill any outstanding requests */
  82325. + for (i = 0; i < num_out_eps; i++) {
  82326. + dwc_otg_pcd_ep_t *ep = &pcd->out_ep[i];
  82327. + dwc_otg_request_nuke(ep);
  82328. + }
  82329. +
  82330. + /* report disconnect; the driver is already quiesced */
  82331. + if (pcd->fops->disconnect) {
  82332. + DWC_SPINUNLOCK(pcd->lock);
  82333. + pcd->fops->disconnect(pcd);
  82334. + DWC_SPINLOCK(pcd->lock);
  82335. + }
  82336. + DWC_SPINUNLOCK(pcd->lock);
  82337. +}
  82338. +
  82339. +/**
  82340. + * This interrupt indicates that ...
  82341. + */
  82342. +int32_t dwc_otg_pcd_handle_i2c_intr(dwc_otg_pcd_t * pcd)
  82343. +{
  82344. + gintmsk_data_t intr_mask = {.d32 = 0 };
  82345. + gintsts_data_t gintsts;
  82346. +
  82347. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "i2cintr");
  82348. + intr_mask.b.i2cintr = 1;
  82349. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  82350. + intr_mask.d32, 0);
  82351. +
  82352. + /* Clear interrupt */
  82353. + gintsts.d32 = 0;
  82354. + gintsts.b.i2cintr = 1;
  82355. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  82356. + gintsts.d32);
  82357. + return 1;
  82358. +}
  82359. +
  82360. +/**
  82361. + * This interrupt indicates that ...
  82362. + */
  82363. +int32_t dwc_otg_pcd_handle_early_suspend_intr(dwc_otg_pcd_t * pcd)
  82364. +{
  82365. + gintsts_data_t gintsts;
  82366. +#if defined(VERBOSE)
  82367. + DWC_PRINTF("Early Suspend Detected\n");
  82368. +#endif
  82369. +
  82370. + /* Clear interrupt */
  82371. + gintsts.d32 = 0;
  82372. + gintsts.b.erlysuspend = 1;
  82373. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  82374. + gintsts.d32);
  82375. + return 1;
  82376. +}
  82377. +
  82378. +/**
  82379. + * This function configures EPO to receive SETUP packets.
  82380. + *
  82381. + * @todo NGS: Update the comments from the HW FS.
  82382. + *
  82383. + * -# Program the following fields in the endpoint specific registers
  82384. + * for Control OUT EP 0, in order to receive a setup packet
  82385. + * - DOEPTSIZ0.Packet Count = 3 (To receive up to 3 back to back
  82386. + * setup packets)
  82387. + * - DOEPTSIZE0.Transfer Size = 24 Bytes (To receive up to 3 back
  82388. + * to back setup packets)
  82389. + * - In DMA mode, DOEPDMA0 Register with a memory address to
  82390. + * store any setup packets received
  82391. + *
  82392. + * @param core_if Programming view of DWC_otg controller.
  82393. + * @param pcd Programming view of the PCD.
  82394. + */
  82395. +static inline void ep0_out_start(dwc_otg_core_if_t * core_if,
  82396. + dwc_otg_pcd_t * pcd)
  82397. +{
  82398. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  82399. + deptsiz0_data_t doeptsize0 = {.d32 = 0 };
  82400. + dwc_otg_dev_dma_desc_t *dma_desc;
  82401. + depctl_data_t doepctl = {.d32 = 0 };
  82402. +
  82403. +#ifdef VERBOSE
  82404. + DWC_DEBUGPL(DBG_PCDV, "%s() doepctl0=%0x\n", __func__,
  82405. + DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl));
  82406. +#endif
  82407. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  82408. + doepctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl);
  82409. + if (doepctl.b.epena) {
  82410. + return;
  82411. + }
  82412. + }
  82413. +
  82414. + doeptsize0.b.supcnt = 3;
  82415. + doeptsize0.b.pktcnt = 1;
  82416. + doeptsize0.b.xfersize = 8 * 3;
  82417. +
  82418. + if (core_if->dma_enable) {
  82419. + if (!core_if->dma_desc_enable) {
  82420. + /** put here as for Hermes mode deptisz register should not be written */
  82421. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doeptsiz,
  82422. + doeptsize0.d32);
  82423. +
  82424. + /** @todo dma needs to handle multiple setup packets (up to 3) */
  82425. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepdma,
  82426. + pcd->setup_pkt_dma_handle);
  82427. + } else {
  82428. + dev_if->setup_desc_index =
  82429. + (dev_if->setup_desc_index + 1) & 1;
  82430. + dma_desc =
  82431. + dev_if->setup_desc_addr[dev_if->setup_desc_index];
  82432. +
  82433. + /** DMA Descriptor Setup */
  82434. + dma_desc->status.b.bs = BS_HOST_BUSY;
  82435. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  82436. + dma_desc->status.b.sr = 0;
  82437. + dma_desc->status.b.mtrf = 0;
  82438. + }
  82439. + dma_desc->status.b.l = 1;
  82440. + dma_desc->status.b.ioc = 1;
  82441. + dma_desc->status.b.bytes = pcd->ep0.dwc_ep.maxpacket;
  82442. + dma_desc->buf = pcd->setup_pkt_dma_handle;
  82443. + dma_desc->status.b.sts = 0;
  82444. + dma_desc->status.b.bs = BS_HOST_READY;
  82445. +
  82446. + /** DOEPDMA0 Register write */
  82447. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepdma,
  82448. + dev_if->dma_setup_desc_addr
  82449. + [dev_if->setup_desc_index]);
  82450. + }
  82451. +
  82452. + } else {
  82453. + /** put here as for Hermes mode deptisz register should not be written */
  82454. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doeptsiz,
  82455. + doeptsize0.d32);
  82456. + }
  82457. +
  82458. + /** DOEPCTL0 Register write cnak will be set after setup interrupt */
  82459. + doepctl.d32 = 0;
  82460. + doepctl.b.epena = 1;
  82461. + if (core_if->snpsid <= OTG_CORE_REV_2_94a) {
  82462. + doepctl.b.cnak = 1;
  82463. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepctl, doepctl.d32);
  82464. + } else {
  82465. + DWC_MODIFY_REG32(&dev_if->out_ep_regs[0]->doepctl, 0, doepctl.d32);
  82466. + }
  82467. +
  82468. +#ifdef VERBOSE
  82469. + DWC_DEBUGPL(DBG_PCDV, "doepctl0=%0x\n",
  82470. + DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl));
  82471. + DWC_DEBUGPL(DBG_PCDV, "diepctl0=%0x\n",
  82472. + DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl));
  82473. +#endif
  82474. +}
  82475. +
  82476. +/**
  82477. + * This interrupt occurs when a USB Reset is detected. When the USB
  82478. + * Reset Interrupt occurs the device state is set to DEFAULT and the
  82479. + * EP0 state is set to IDLE.
  82480. + * -# Set the NAK bit for all OUT endpoints (DOEPCTLn.SNAK = 1)
  82481. + * -# Unmask the following interrupt bits
  82482. + * - DAINTMSK.INEP0 = 1 (Control 0 IN endpoint)
  82483. + * - DAINTMSK.OUTEP0 = 1 (Control 0 OUT endpoint)
  82484. + * - DOEPMSK.SETUP = 1
  82485. + * - DOEPMSK.XferCompl = 1
  82486. + * - DIEPMSK.XferCompl = 1
  82487. + * - DIEPMSK.TimeOut = 1
  82488. + * -# Program the following fields in the endpoint specific registers
  82489. + * for Control OUT EP 0, in order to receive a setup packet
  82490. + * - DOEPTSIZ0.Packet Count = 3 (To receive up to 3 back to back
  82491. + * setup packets)
  82492. + * - DOEPTSIZE0.Transfer Size = 24 Bytes (To receive up to 3 back
  82493. + * to back setup packets)
  82494. + * - In DMA mode, DOEPDMA0 Register with a memory address to
  82495. + * store any setup packets received
  82496. + * At this point, all the required initialization, except for enabling
  82497. + * the control 0 OUT endpoint is done, for receiving SETUP packets.
  82498. + */
  82499. +int32_t dwc_otg_pcd_handle_usb_reset_intr(dwc_otg_pcd_t * pcd)
  82500. +{
  82501. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  82502. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  82503. + depctl_data_t doepctl = {.d32 = 0 };
  82504. + depctl_data_t diepctl = {.d32 = 0 };
  82505. + daint_data_t daintmsk = {.d32 = 0 };
  82506. + doepmsk_data_t doepmsk = {.d32 = 0 };
  82507. + diepmsk_data_t diepmsk = {.d32 = 0 };
  82508. + dcfg_data_t dcfg = {.d32 = 0 };
  82509. + grstctl_t resetctl = {.d32 = 0 };
  82510. + dctl_data_t dctl = {.d32 = 0 };
  82511. + int i = 0;
  82512. + gintsts_data_t gintsts;
  82513. + pcgcctl_data_t power = {.d32 = 0 };
  82514. +
  82515. + power.d32 = DWC_READ_REG32(core_if->pcgcctl);
  82516. + if (power.b.stoppclk) {
  82517. + power.d32 = 0;
  82518. + power.b.stoppclk = 1;
  82519. + DWC_MODIFY_REG32(core_if->pcgcctl, power.d32, 0);
  82520. +
  82521. + power.b.pwrclmp = 1;
  82522. + DWC_MODIFY_REG32(core_if->pcgcctl, power.d32, 0);
  82523. +
  82524. + power.b.rstpdwnmodule = 1;
  82525. + DWC_MODIFY_REG32(core_if->pcgcctl, power.d32, 0);
  82526. + }
  82527. +
  82528. + core_if->lx_state = DWC_OTG_L0;
  82529. +
  82530. + DWC_PRINTF("USB RESET\n");
  82531. +#ifdef DWC_EN_ISOC
  82532. + for (i = 1; i < 16; ++i) {
  82533. + dwc_otg_pcd_ep_t *ep;
  82534. + dwc_ep_t *dwc_ep;
  82535. + ep = get_in_ep(pcd, i);
  82536. + if (ep != 0) {
  82537. + dwc_ep = &ep->dwc_ep;
  82538. + dwc_ep->next_frame = 0xffffffff;
  82539. + }
  82540. + }
  82541. +#endif /* DWC_EN_ISOC */
  82542. +
  82543. + /* reset the HNP settings */
  82544. + dwc_otg_pcd_update_otg(pcd, 1);
  82545. +
  82546. + /* Clear the Remote Wakeup Signalling */
  82547. + dctl.b.rmtwkupsig = 1;
  82548. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, 0);
  82549. +
  82550. + /* Set NAK for all OUT EPs */
  82551. + doepctl.b.snak = 1;
  82552. + for (i = 0; i <= dev_if->num_out_eps; i++) {
  82553. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepctl, doepctl.d32);
  82554. + }
  82555. +
  82556. + /* Flush the NP Tx FIFO */
  82557. + dwc_otg_flush_tx_fifo(core_if, 0x10);
  82558. + /* Flush the Learning Queue */
  82559. + resetctl.b.intknqflsh = 1;
  82560. + DWC_WRITE_REG32(&core_if->core_global_regs->grstctl, resetctl.d32);
  82561. +
  82562. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable) {
  82563. + core_if->start_predict = 0;
  82564. + for (i = 0; i<= core_if->dev_if->num_in_eps; ++i) {
  82565. + core_if->nextep_seq[i] = 0xff; // 0xff - EP not active
  82566. + }
  82567. + core_if->nextep_seq[0] = 0;
  82568. + core_if->first_in_nextep_seq = 0;
  82569. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl);
  82570. + diepctl.b.nextep = 0;
  82571. + DWC_WRITE_REG32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
  82572. +
  82573. + /* Update IN Endpoint Mismatch Count by active IN NP EP count + 1 */
  82574. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  82575. + dcfg.b.epmscnt = 2;
  82576. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  82577. +
  82578. + DWC_DEBUGPL(DBG_PCDV,
  82579. + "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  82580. + __func__, core_if->first_in_nextep_seq);
  82581. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  82582. + DWC_DEBUGPL(DBG_PCDV, "%2d\n", core_if->nextep_seq[i]);
  82583. + }
  82584. + }
  82585. +
  82586. + if (core_if->multiproc_int_enable) {
  82587. + daintmsk.b.inep0 = 1;
  82588. + daintmsk.b.outep0 = 1;
  82589. + DWC_WRITE_REG32(&dev_if->dev_global_regs->deachintmsk,
  82590. + daintmsk.d32);
  82591. +
  82592. + doepmsk.b.setup = 1;
  82593. + doepmsk.b.xfercompl = 1;
  82594. + doepmsk.b.ahberr = 1;
  82595. + doepmsk.b.epdisabled = 1;
  82596. +
  82597. + if ((core_if->dma_desc_enable) ||
  82598. + (core_if->dma_enable
  82599. + && core_if->snpsid >= OTG_CORE_REV_3_00a)) {
  82600. + doepmsk.b.stsphsercvd = 1;
  82601. + }
  82602. + if (core_if->dma_desc_enable)
  82603. + doepmsk.b.bna = 1;
  82604. +/*
  82605. + doepmsk.b.babble = 1;
  82606. + doepmsk.b.nyet = 1;
  82607. +
  82608. + if (core_if->dma_enable) {
  82609. + doepmsk.b.nak = 1;
  82610. + }
  82611. +*/
  82612. + DWC_WRITE_REG32(&dev_if->dev_global_regs->doepeachintmsk[0],
  82613. + doepmsk.d32);
  82614. +
  82615. + diepmsk.b.xfercompl = 1;
  82616. + diepmsk.b.timeout = 1;
  82617. + diepmsk.b.epdisabled = 1;
  82618. + diepmsk.b.ahberr = 1;
  82619. + diepmsk.b.intknepmis = 1;
  82620. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable)
  82621. + diepmsk.b.intknepmis = 0;
  82622. +
  82623. +/* if (core_if->dma_desc_enable) {
  82624. + diepmsk.b.bna = 1;
  82625. + }
  82626. +*/
  82627. +/*
  82628. + if (core_if->dma_enable) {
  82629. + diepmsk.b.nak = 1;
  82630. + }
  82631. +*/
  82632. + DWC_WRITE_REG32(&dev_if->dev_global_regs->diepeachintmsk[0],
  82633. + diepmsk.d32);
  82634. + } else {
  82635. + daintmsk.b.inep0 = 1;
  82636. + daintmsk.b.outep0 = 1;
  82637. + DWC_WRITE_REG32(&dev_if->dev_global_regs->daintmsk,
  82638. + daintmsk.d32);
  82639. +
  82640. + doepmsk.b.setup = 1;
  82641. + doepmsk.b.xfercompl = 1;
  82642. + doepmsk.b.ahberr = 1;
  82643. + doepmsk.b.epdisabled = 1;
  82644. +
  82645. + if ((core_if->dma_desc_enable) ||
  82646. + (core_if->dma_enable
  82647. + && core_if->snpsid >= OTG_CORE_REV_3_00a)) {
  82648. + doepmsk.b.stsphsercvd = 1;
  82649. + }
  82650. + if (core_if->dma_desc_enable)
  82651. + doepmsk.b.bna = 1;
  82652. + DWC_WRITE_REG32(&dev_if->dev_global_regs->doepmsk, doepmsk.d32);
  82653. +
  82654. + diepmsk.b.xfercompl = 1;
  82655. + diepmsk.b.timeout = 1;
  82656. + diepmsk.b.epdisabled = 1;
  82657. + diepmsk.b.ahberr = 1;
  82658. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable)
  82659. + diepmsk.b.intknepmis = 0;
  82660. +/*
  82661. + if (core_if->dma_desc_enable) {
  82662. + diepmsk.b.bna = 1;
  82663. + }
  82664. +*/
  82665. +
  82666. + DWC_WRITE_REG32(&dev_if->dev_global_regs->diepmsk, diepmsk.d32);
  82667. + }
  82668. +
  82669. + /* Reset Device Address */
  82670. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  82671. + dcfg.b.devaddr = 0;
  82672. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  82673. +
  82674. + /* setup EP0 to receive SETUP packets */
  82675. + if (core_if->snpsid <= OTG_CORE_REV_2_94a)
  82676. + ep0_out_start(core_if, pcd);
  82677. +
  82678. + /* Clear interrupt */
  82679. + gintsts.d32 = 0;
  82680. + gintsts.b.usbreset = 1;
  82681. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  82682. +
  82683. + return 1;
  82684. +}
  82685. +
  82686. +/**
  82687. + * Get the device speed from the device status register and convert it
  82688. + * to USB speed constant.
  82689. + *
  82690. + * @param core_if Programming view of DWC_otg controller.
  82691. + */
  82692. +static int get_device_speed(dwc_otg_core_if_t * core_if)
  82693. +{
  82694. + dsts_data_t dsts;
  82695. + int speed = 0;
  82696. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  82697. +
  82698. + switch (dsts.b.enumspd) {
  82699. + case DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ:
  82700. + speed = USB_SPEED_HIGH;
  82701. + break;
  82702. + case DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ:
  82703. + case DWC_DSTS_ENUMSPD_FS_PHY_48MHZ:
  82704. + speed = USB_SPEED_FULL;
  82705. + break;
  82706. +
  82707. + case DWC_DSTS_ENUMSPD_LS_PHY_6MHZ:
  82708. + speed = USB_SPEED_LOW;
  82709. + break;
  82710. + }
  82711. +
  82712. + return speed;
  82713. +}
  82714. +
  82715. +/**
  82716. + * Read the device status register and set the device speed in the
  82717. + * data structure.
  82718. + * Set up EP0 to receive SETUP packets by calling dwc_ep0_activate.
  82719. + */
  82720. +int32_t dwc_otg_pcd_handle_enum_done_intr(dwc_otg_pcd_t * pcd)
  82721. +{
  82722. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  82723. + gintsts_data_t gintsts;
  82724. + gusbcfg_data_t gusbcfg;
  82725. + dwc_otg_core_global_regs_t *global_regs =
  82726. + GET_CORE_IF(pcd)->core_global_regs;
  82727. + uint8_t utmi16b, utmi8b;
  82728. + int speed;
  82729. + DWC_DEBUGPL(DBG_PCD, "SPEED ENUM\n");
  82730. +
  82731. + if (GET_CORE_IF(pcd)->snpsid >= OTG_CORE_REV_2_60a) {
  82732. + utmi16b = 6; //vahrama old value was 6;
  82733. + utmi8b = 9;
  82734. + } else {
  82735. + utmi16b = 4;
  82736. + utmi8b = 8;
  82737. + }
  82738. + dwc_otg_ep0_activate(GET_CORE_IF(pcd), &ep0->dwc_ep);
  82739. + if (GET_CORE_IF(pcd)->snpsid >= OTG_CORE_REV_3_00a) {
  82740. + ep0_out_start(GET_CORE_IF(pcd), pcd);
  82741. + }
  82742. +
  82743. +#ifdef DEBUG_EP0
  82744. + print_ep0_state(pcd);
  82745. +#endif
  82746. +
  82747. + if (pcd->ep0state == EP0_DISCONNECT) {
  82748. + pcd->ep0state = EP0_IDLE;
  82749. + } else if (pcd->ep0state == EP0_STALL) {
  82750. + pcd->ep0state = EP0_IDLE;
  82751. + }
  82752. +
  82753. + pcd->ep0state = EP0_IDLE;
  82754. +
  82755. + ep0->stopped = 0;
  82756. +
  82757. + speed = get_device_speed(GET_CORE_IF(pcd));
  82758. + pcd->fops->connect(pcd, speed);
  82759. +
  82760. + /* Set USB turnaround time based on device speed and PHY interface. */
  82761. + gusbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  82762. + if (speed == USB_SPEED_HIGH) {
  82763. + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type ==
  82764. + DWC_HWCFG2_HS_PHY_TYPE_ULPI) {
  82765. + /* ULPI interface */
  82766. + gusbcfg.b.usbtrdtim = 9;
  82767. + }
  82768. + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type ==
  82769. + DWC_HWCFG2_HS_PHY_TYPE_UTMI) {
  82770. + /* UTMI+ interface */
  82771. + if (GET_CORE_IF(pcd)->hwcfg4.b.utmi_phy_data_width == 0) {
  82772. + gusbcfg.b.usbtrdtim = utmi8b;
  82773. + } else if (GET_CORE_IF(pcd)->hwcfg4.
  82774. + b.utmi_phy_data_width == 1) {
  82775. + gusbcfg.b.usbtrdtim = utmi16b;
  82776. + } else if (GET_CORE_IF(pcd)->
  82777. + core_params->phy_utmi_width == 8) {
  82778. + gusbcfg.b.usbtrdtim = utmi8b;
  82779. + } else {
  82780. + gusbcfg.b.usbtrdtim = utmi16b;
  82781. + }
  82782. + }
  82783. + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type ==
  82784. + DWC_HWCFG2_HS_PHY_TYPE_UTMI_ULPI) {
  82785. + /* UTMI+ OR ULPI interface */
  82786. + if (gusbcfg.b.ulpi_utmi_sel == 1) {
  82787. + /* ULPI interface */
  82788. + gusbcfg.b.usbtrdtim = 9;
  82789. + } else {
  82790. + /* UTMI+ interface */
  82791. + if (GET_CORE_IF(pcd)->
  82792. + core_params->phy_utmi_width == 16) {
  82793. + gusbcfg.b.usbtrdtim = utmi16b;
  82794. + } else {
  82795. + gusbcfg.b.usbtrdtim = utmi8b;
  82796. + }
  82797. + }
  82798. + }
  82799. + } else {
  82800. + /* Full or low speed */
  82801. + gusbcfg.b.usbtrdtim = 9;
  82802. + }
  82803. + DWC_WRITE_REG32(&global_regs->gusbcfg, gusbcfg.d32);
  82804. +
  82805. + /* Clear interrupt */
  82806. + gintsts.d32 = 0;
  82807. + gintsts.b.enumdone = 1;
  82808. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  82809. + gintsts.d32);
  82810. + return 1;
  82811. +}
  82812. +
  82813. +/**
  82814. + * This interrupt indicates that the ISO OUT Packet was dropped due to
  82815. + * Rx FIFO full or Rx Status Queue Full. If this interrupt occurs
  82816. + * read all the data from the Rx FIFO.
  82817. + */
  82818. +int32_t dwc_otg_pcd_handle_isoc_out_packet_dropped_intr(dwc_otg_pcd_t * pcd)
  82819. +{
  82820. + gintmsk_data_t intr_mask = {.d32 = 0 };
  82821. + gintsts_data_t gintsts;
  82822. +
  82823. + DWC_WARN("INTERRUPT Handler not implemented for %s\n",
  82824. + "ISOC Out Dropped");
  82825. +
  82826. + intr_mask.b.isooutdrop = 1;
  82827. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  82828. + intr_mask.d32, 0);
  82829. +
  82830. + /* Clear interrupt */
  82831. + gintsts.d32 = 0;
  82832. + gintsts.b.isooutdrop = 1;
  82833. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  82834. + gintsts.d32);
  82835. +
  82836. + return 1;
  82837. +}
  82838. +
  82839. +/**
  82840. + * This interrupt indicates the end of the portion of the micro-frame
  82841. + * for periodic transactions. If there is a periodic transaction for
  82842. + * the next frame, load the packets into the EP periodic Tx FIFO.
  82843. + */
  82844. +int32_t dwc_otg_pcd_handle_end_periodic_frame_intr(dwc_otg_pcd_t * pcd)
  82845. +{
  82846. + gintmsk_data_t intr_mask = {.d32 = 0 };
  82847. + gintsts_data_t gintsts;
  82848. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "EOP");
  82849. +
  82850. + intr_mask.b.eopframe = 1;
  82851. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  82852. + intr_mask.d32, 0);
  82853. +
  82854. + /* Clear interrupt */
  82855. + gintsts.d32 = 0;
  82856. + gintsts.b.eopframe = 1;
  82857. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  82858. + gintsts.d32);
  82859. +
  82860. + return 1;
  82861. +}
  82862. +
  82863. +/**
  82864. + * This interrupt indicates that EP of the packet on the top of the
  82865. + * non-periodic Tx FIFO does not match EP of the IN Token received.
  82866. + *
  82867. + * The "Device IN Token Queue" Registers are read to determine the
  82868. + * order the IN Tokens have been received. The non-periodic Tx FIFO
  82869. + * is flushed, so it can be reloaded in the order seen in the IN Token
  82870. + * Queue.
  82871. + */
  82872. +int32_t dwc_otg_pcd_handle_ep_mismatch_intr(dwc_otg_pcd_t * pcd)
  82873. +{
  82874. + gintsts_data_t gintsts;
  82875. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  82876. + dctl_data_t dctl;
  82877. + gintmsk_data_t intr_mask = {.d32 = 0 };
  82878. +
  82879. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable) {
  82880. + core_if->start_predict = 1;
  82881. +
  82882. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, core_if);
  82883. +
  82884. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  82885. + if (!gintsts.b.ginnakeff) {
  82886. + /* Disable EP Mismatch interrupt */
  82887. + intr_mask.d32 = 0;
  82888. + intr_mask.b.epmismatch = 1;
  82889. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, intr_mask.d32, 0);
  82890. + /* Enable the Global IN NAK Effective Interrupt */
  82891. + intr_mask.d32 = 0;
  82892. + intr_mask.b.ginnakeff = 1;
  82893. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, intr_mask.d32);
  82894. + /* Set the global non-periodic IN NAK handshake */
  82895. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  82896. + dctl.b.sgnpinnak = 1;
  82897. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  82898. + } else {
  82899. + DWC_PRINTF("gintsts.b.ginnakeff = 1! dctl.b.sgnpinnak not set\n");
  82900. + }
  82901. + /* Disabling of all EP's will be done in dwc_otg_pcd_handle_in_nak_effective()
  82902. + * handler after Global IN NAK Effective interrupt will be asserted */
  82903. + }
  82904. + /* Clear interrupt */
  82905. + gintsts.d32 = 0;
  82906. + gintsts.b.epmismatch = 1;
  82907. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  82908. +
  82909. + return 1;
  82910. +}
  82911. +
  82912. +/**
  82913. + * This interrupt is valid only in DMA mode. This interrupt indicates that the
  82914. + * core has stopped fetching data for IN endpoints due to the unavailability of
  82915. + * TxFIFO space or Request Queue space. This interrupt is used by the
  82916. + * application for an endpoint mismatch algorithm.
  82917. + *
  82918. + * @param pcd The PCD
  82919. + */
  82920. +int32_t dwc_otg_pcd_handle_ep_fetsusp_intr(dwc_otg_pcd_t * pcd)
  82921. +{
  82922. + gintsts_data_t gintsts;
  82923. + gintmsk_data_t gintmsk_data;
  82924. + dctl_data_t dctl;
  82925. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  82926. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, core_if);
  82927. +
  82928. + /* Clear the global non-periodic IN NAK handshake */
  82929. + dctl.d32 = 0;
  82930. + dctl.b.cgnpinnak = 1;
  82931. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  82932. +
  82933. + /* Mask GINTSTS.FETSUSP interrupt */
  82934. + gintmsk_data.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  82935. + gintmsk_data.b.fetsusp = 0;
  82936. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk_data.d32);
  82937. +
  82938. + /* Clear interrupt */
  82939. + gintsts.d32 = 0;
  82940. + gintsts.b.fetsusp = 1;
  82941. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  82942. +
  82943. + return 1;
  82944. +}
  82945. +/**
  82946. + * This funcion stalls EP0.
  82947. + */
  82948. +static inline void ep0_do_stall(dwc_otg_pcd_t * pcd, const int err_val)
  82949. +{
  82950. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  82951. + usb_device_request_t *ctrl = &pcd->setup_pkt->req;
  82952. + DWC_WARN("req %02x.%02x protocol STALL; err %d\n",
  82953. + ctrl->bmRequestType, ctrl->bRequest, err_val);
  82954. +
  82955. + ep0->dwc_ep.is_in = 1;
  82956. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd), &ep0->dwc_ep);
  82957. + pcd->ep0.stopped = 1;
  82958. + pcd->ep0state = EP0_IDLE;
  82959. + ep0_out_start(GET_CORE_IF(pcd), pcd);
  82960. +}
  82961. +
  82962. +/**
  82963. + * This functions delegates the setup command to the gadget driver.
  82964. + */
  82965. +static inline void do_gadget_setup(dwc_otg_pcd_t * pcd,
  82966. + usb_device_request_t * ctrl)
  82967. +{
  82968. + int ret = 0;
  82969. + DWC_SPINUNLOCK(pcd->lock);
  82970. + ret = pcd->fops->setup(pcd, (uint8_t *) ctrl);
  82971. + DWC_SPINLOCK(pcd->lock);
  82972. + if (ret < 0) {
  82973. + ep0_do_stall(pcd, ret);
  82974. + }
  82975. +
  82976. + /** @todo This is a g_file_storage gadget driver specific
  82977. + * workaround: a DELAYED_STATUS result from the fsg_setup
  82978. + * routine will result in the gadget queueing a EP0 IN status
  82979. + * phase for a two-stage control transfer. Exactly the same as
  82980. + * a SET_CONFIGURATION/SET_INTERFACE except that this is a class
  82981. + * specific request. Need a generic way to know when the gadget
  82982. + * driver will queue the status phase. Can we assume when we
  82983. + * call the gadget driver setup() function that it will always
  82984. + * queue and require the following flag? Need to look into
  82985. + * this.
  82986. + */
  82987. +
  82988. + if (ret == 256 + 999) {
  82989. + pcd->request_config = 1;
  82990. + }
  82991. +}
  82992. +
  82993. +#ifdef DWC_UTE_CFI
  82994. +/**
  82995. + * This functions delegates the CFI setup commands to the gadget driver.
  82996. + * This function will return a negative value to indicate a failure.
  82997. + */
  82998. +static inline int cfi_gadget_setup(dwc_otg_pcd_t * pcd,
  82999. + struct cfi_usb_ctrlrequest *ctrl_req)
  83000. +{
  83001. + int ret = 0;
  83002. +
  83003. + if (pcd->fops && pcd->fops->cfi_setup) {
  83004. + DWC_SPINUNLOCK(pcd->lock);
  83005. + ret = pcd->fops->cfi_setup(pcd, ctrl_req);
  83006. + DWC_SPINLOCK(pcd->lock);
  83007. + if (ret < 0) {
  83008. + ep0_do_stall(pcd, ret);
  83009. + return ret;
  83010. + }
  83011. + }
  83012. +
  83013. + return ret;
  83014. +}
  83015. +#endif
  83016. +
  83017. +/**
  83018. + * This function starts the Zero-Length Packet for the IN status phase
  83019. + * of a 2 stage control transfer.
  83020. + */
  83021. +static inline void do_setup_in_status_phase(dwc_otg_pcd_t * pcd)
  83022. +{
  83023. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  83024. + if (pcd->ep0state == EP0_STALL) {
  83025. + return;
  83026. + }
  83027. +
  83028. + pcd->ep0state = EP0_IN_STATUS_PHASE;
  83029. +
  83030. + /* Prepare for more SETUP Packets */
  83031. + DWC_DEBUGPL(DBG_PCD, "EP0 IN ZLP\n");
  83032. + if ((GET_CORE_IF(pcd)->snpsid >= OTG_CORE_REV_3_00a)
  83033. + && (pcd->core_if->dma_desc_enable)
  83034. + && (ep0->dwc_ep.xfer_count < ep0->dwc_ep.total_len)) {
  83035. + DWC_DEBUGPL(DBG_PCDV,
  83036. + "Data terminated wait next packet in out_desc_addr\n");
  83037. + pcd->backup_buf = phys_to_virt(ep0->dwc_ep.dma_addr);
  83038. + pcd->data_terminated = 1;
  83039. + }
  83040. + ep0->dwc_ep.xfer_len = 0;
  83041. + ep0->dwc_ep.xfer_count = 0;
  83042. + ep0->dwc_ep.is_in = 1;
  83043. + ep0->dwc_ep.dma_addr = pcd->setup_pkt_dma_handle;
  83044. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
  83045. +
  83046. + /* Prepare for more SETUP Packets */
  83047. + //ep0_out_start(GET_CORE_IF(pcd), pcd);
  83048. +}
  83049. +
  83050. +/**
  83051. + * This function starts the Zero-Length Packet for the OUT status phase
  83052. + * of a 2 stage control transfer.
  83053. + */
  83054. +static inline void do_setup_out_status_phase(dwc_otg_pcd_t * pcd)
  83055. +{
  83056. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  83057. + if (pcd->ep0state == EP0_STALL) {
  83058. + DWC_DEBUGPL(DBG_PCD, "EP0 STALLED\n");
  83059. + return;
  83060. + }
  83061. + pcd->ep0state = EP0_OUT_STATUS_PHASE;
  83062. +
  83063. + DWC_DEBUGPL(DBG_PCD, "EP0 OUT ZLP\n");
  83064. + ep0->dwc_ep.xfer_len = 0;
  83065. + ep0->dwc_ep.xfer_count = 0;
  83066. + ep0->dwc_ep.is_in = 0;
  83067. + ep0->dwc_ep.dma_addr = pcd->setup_pkt_dma_handle;
  83068. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
  83069. +
  83070. + /* Prepare for more SETUP Packets */
  83071. + if (GET_CORE_IF(pcd)->dma_enable == 0) {
  83072. + ep0_out_start(GET_CORE_IF(pcd), pcd);
  83073. + }
  83074. +}
  83075. +
  83076. +/**
  83077. + * Clear the EP halt (STALL) and if pending requests start the
  83078. + * transfer.
  83079. + */
  83080. +static inline void pcd_clear_halt(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep)
  83081. +{
  83082. + if (ep->dwc_ep.stall_clear_flag == 0)
  83083. + dwc_otg_ep_clear_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  83084. +
  83085. + /* Reactive the EP */
  83086. + dwc_otg_ep_activate(GET_CORE_IF(pcd), &ep->dwc_ep);
  83087. + if (ep->stopped) {
  83088. + ep->stopped = 0;
  83089. + /* If there is a request in the EP queue start it */
  83090. +
  83091. + /** @todo FIXME: this causes an EP mismatch in DMA mode.
  83092. + * epmismatch not yet implemented. */
  83093. +
  83094. + /*
  83095. + * Above fixme is solved by implmenting a tasklet to call the
  83096. + * start_next_request(), outside of interrupt context at some
  83097. + * time after the current time, after a clear-halt setup packet.
  83098. + * Still need to implement ep mismatch in the future if a gadget
  83099. + * ever uses more than one endpoint at once
  83100. + */
  83101. + ep->queue_sof = 1;
  83102. + DWC_TASK_SCHEDULE(pcd->start_xfer_tasklet);
  83103. + }
  83104. + /* Start Control Status Phase */
  83105. + do_setup_in_status_phase(pcd);
  83106. +}
  83107. +
  83108. +/**
  83109. + * This function is called when the SET_FEATURE TEST_MODE Setup packet
  83110. + * is sent from the host. The Device Control register is written with
  83111. + * the Test Mode bits set to the specified Test Mode. This is done as
  83112. + * a tasklet so that the "Status" phase of the control transfer
  83113. + * completes before transmitting the TEST packets.
  83114. + *
  83115. + * @todo This has not been tested since the tasklet struct was put
  83116. + * into the PCD struct!
  83117. + *
  83118. + */
  83119. +void do_test_mode(void *data)
  83120. +{
  83121. + dctl_data_t dctl;
  83122. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) data;
  83123. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  83124. + int test_mode = pcd->test_mode;
  83125. +
  83126. +// DWC_WARN("%s() has not been tested since being rewritten!\n", __func__);
  83127. +
  83128. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  83129. + switch (test_mode) {
  83130. + case 1: // TEST_J
  83131. + dctl.b.tstctl = 1;
  83132. + break;
  83133. +
  83134. + case 2: // TEST_K
  83135. + dctl.b.tstctl = 2;
  83136. + break;
  83137. +
  83138. + case 3: // TEST_SE0_NAK
  83139. + dctl.b.tstctl = 3;
  83140. + break;
  83141. +
  83142. + case 4: // TEST_PACKET
  83143. + dctl.b.tstctl = 4;
  83144. + break;
  83145. +
  83146. + case 5: // TEST_FORCE_ENABLE
  83147. + dctl.b.tstctl = 5;
  83148. + break;
  83149. + }
  83150. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  83151. +}
  83152. +
  83153. +/**
  83154. + * This function process the GET_STATUS Setup Commands.
  83155. + */
  83156. +static inline void do_get_status(dwc_otg_pcd_t * pcd)
  83157. +{
  83158. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  83159. + dwc_otg_pcd_ep_t *ep;
  83160. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  83161. + uint16_t *status = pcd->status_buf;
  83162. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  83163. +
  83164. +#ifdef DEBUG_EP0
  83165. + DWC_DEBUGPL(DBG_PCD,
  83166. + "GET_STATUS %02x.%02x v%04x i%04x l%04x\n",
  83167. + ctrl.bmRequestType, ctrl.bRequest,
  83168. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  83169. + UGETW(ctrl.wLength));
  83170. +#endif
  83171. +
  83172. + switch (UT_GET_RECIPIENT(ctrl.bmRequestType)) {
  83173. + case UT_DEVICE:
  83174. + if(UGETW(ctrl.wIndex) == 0xF000) { /* OTG Status selector */
  83175. + DWC_PRINTF("wIndex - %d\n", UGETW(ctrl.wIndex));
  83176. + DWC_PRINTF("OTG VERSION - %d\n", core_if->otg_ver);
  83177. + DWC_PRINTF("OTG CAP - %d, %d\n",
  83178. + core_if->core_params->otg_cap,
  83179. + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE);
  83180. + if (core_if->otg_ver == 1
  83181. + && core_if->core_params->otg_cap ==
  83182. + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  83183. + uint8_t *otgsts = (uint8_t*)pcd->status_buf;
  83184. + *otgsts = (core_if->otg_sts & 0x1);
  83185. + pcd->ep0_pending = 1;
  83186. + ep0->dwc_ep.start_xfer_buff =
  83187. + (uint8_t *) otgsts;
  83188. + ep0->dwc_ep.xfer_buff = (uint8_t *) otgsts;
  83189. + ep0->dwc_ep.dma_addr =
  83190. + pcd->status_buf_dma_handle;
  83191. + ep0->dwc_ep.xfer_len = 1;
  83192. + ep0->dwc_ep.xfer_count = 0;
  83193. + ep0->dwc_ep.total_len = ep0->dwc_ep.xfer_len;
  83194. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd),
  83195. + &ep0->dwc_ep);
  83196. + return;
  83197. + } else {
  83198. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  83199. + return;
  83200. + }
  83201. + break;
  83202. + } else {
  83203. + *status = 0x1; /* Self powered */
  83204. + *status |= pcd->remote_wakeup_enable << 1;
  83205. + break;
  83206. + }
  83207. + case UT_INTERFACE:
  83208. + *status = 0;
  83209. + break;
  83210. +
  83211. + case UT_ENDPOINT:
  83212. + ep = get_ep_by_addr(pcd, UGETW(ctrl.wIndex));
  83213. + if (ep == 0 || UGETW(ctrl.wLength) > 2) {
  83214. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  83215. + return;
  83216. + }
  83217. + /** @todo check for EP stall */
  83218. + *status = ep->stopped;
  83219. + break;
  83220. + }
  83221. + pcd->ep0_pending = 1;
  83222. + ep0->dwc_ep.start_xfer_buff = (uint8_t *) status;
  83223. + ep0->dwc_ep.xfer_buff = (uint8_t *) status;
  83224. + ep0->dwc_ep.dma_addr = pcd->status_buf_dma_handle;
  83225. + ep0->dwc_ep.xfer_len = 2;
  83226. + ep0->dwc_ep.xfer_count = 0;
  83227. + ep0->dwc_ep.total_len = ep0->dwc_ep.xfer_len;
  83228. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
  83229. +}
  83230. +
  83231. +/**
  83232. + * This function process the SET_FEATURE Setup Commands.
  83233. + */
  83234. +static inline void do_set_feature(dwc_otg_pcd_t * pcd)
  83235. +{
  83236. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  83237. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  83238. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  83239. + dwc_otg_pcd_ep_t *ep = 0;
  83240. + int32_t otg_cap_param = core_if->core_params->otg_cap;
  83241. + gotgctl_data_t gotgctl = {.d32 = 0 };
  83242. +
  83243. + DWC_DEBUGPL(DBG_PCD, "SET_FEATURE:%02x.%02x v%04x i%04x l%04x\n",
  83244. + ctrl.bmRequestType, ctrl.bRequest,
  83245. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  83246. + UGETW(ctrl.wLength));
  83247. + DWC_DEBUGPL(DBG_PCD, "otg_cap=%d\n", otg_cap_param);
  83248. +
  83249. + switch (UT_GET_RECIPIENT(ctrl.bmRequestType)) {
  83250. + case UT_DEVICE:
  83251. + switch (UGETW(ctrl.wValue)) {
  83252. + case UF_DEVICE_REMOTE_WAKEUP:
  83253. + pcd->remote_wakeup_enable = 1;
  83254. + break;
  83255. +
  83256. + case UF_TEST_MODE:
  83257. + /* Setup the Test Mode tasklet to do the Test
  83258. + * Packet generation after the SETUP Status
  83259. + * phase has completed. */
  83260. +
  83261. + /** @todo This has not been tested since the
  83262. + * tasklet struct was put into the PCD
  83263. + * struct! */
  83264. + pcd->test_mode = UGETW(ctrl.wIndex) >> 8;
  83265. + DWC_TASK_SCHEDULE(pcd->test_mode_tasklet);
  83266. + break;
  83267. +
  83268. + case UF_DEVICE_B_HNP_ENABLE:
  83269. + DWC_DEBUGPL(DBG_PCDV,
  83270. + "SET_FEATURE: USB_DEVICE_B_HNP_ENABLE\n");
  83271. +
  83272. + /* dev may initiate HNP */
  83273. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  83274. + pcd->b_hnp_enable = 1;
  83275. + dwc_otg_pcd_update_otg(pcd, 0);
  83276. + DWC_DEBUGPL(DBG_PCD, "Request B HNP\n");
  83277. + /**@todo Is the gotgctl.devhnpen cleared
  83278. + * by a USB Reset? */
  83279. + gotgctl.b.devhnpen = 1;
  83280. + gotgctl.b.hnpreq = 1;
  83281. + DWC_WRITE_REG32(&global_regs->gotgctl,
  83282. + gotgctl.d32);
  83283. + } else {
  83284. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  83285. + return;
  83286. + }
  83287. + break;
  83288. +
  83289. + case UF_DEVICE_A_HNP_SUPPORT:
  83290. + /* RH port supports HNP */
  83291. + DWC_DEBUGPL(DBG_PCDV,
  83292. + "SET_FEATURE: USB_DEVICE_A_HNP_SUPPORT\n");
  83293. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  83294. + pcd->a_hnp_support = 1;
  83295. + dwc_otg_pcd_update_otg(pcd, 0);
  83296. + } else {
  83297. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  83298. + return;
  83299. + }
  83300. + break;
  83301. +
  83302. + case UF_DEVICE_A_ALT_HNP_SUPPORT:
  83303. + /* other RH port does */
  83304. + DWC_DEBUGPL(DBG_PCDV,
  83305. + "SET_FEATURE: USB_DEVICE_A_ALT_HNP_SUPPORT\n");
  83306. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  83307. + pcd->a_alt_hnp_support = 1;
  83308. + dwc_otg_pcd_update_otg(pcd, 0);
  83309. + } else {
  83310. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  83311. + return;
  83312. + }
  83313. + break;
  83314. +
  83315. + default:
  83316. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  83317. + return;
  83318. +
  83319. + }
  83320. + do_setup_in_status_phase(pcd);
  83321. + break;
  83322. +
  83323. + case UT_INTERFACE:
  83324. + do_gadget_setup(pcd, &ctrl);
  83325. + break;
  83326. +
  83327. + case UT_ENDPOINT:
  83328. + if (UGETW(ctrl.wValue) == UF_ENDPOINT_HALT) {
  83329. + ep = get_ep_by_addr(pcd, UGETW(ctrl.wIndex));
  83330. + if (ep == 0) {
  83331. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  83332. + return;
  83333. + }
  83334. + ep->stopped = 1;
  83335. + dwc_otg_ep_set_stall(core_if, &ep->dwc_ep);
  83336. + }
  83337. + do_setup_in_status_phase(pcd);
  83338. + break;
  83339. + }
  83340. +}
  83341. +
  83342. +/**
  83343. + * This function process the CLEAR_FEATURE Setup Commands.
  83344. + */
  83345. +static inline void do_clear_feature(dwc_otg_pcd_t * pcd)
  83346. +{
  83347. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  83348. + dwc_otg_pcd_ep_t *ep = 0;
  83349. +
  83350. + DWC_DEBUGPL(DBG_PCD,
  83351. + "CLEAR_FEATURE:%02x.%02x v%04x i%04x l%04x\n",
  83352. + ctrl.bmRequestType, ctrl.bRequest,
  83353. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  83354. + UGETW(ctrl.wLength));
  83355. +
  83356. + switch (UT_GET_RECIPIENT(ctrl.bmRequestType)) {
  83357. + case UT_DEVICE:
  83358. + switch (UGETW(ctrl.wValue)) {
  83359. + case UF_DEVICE_REMOTE_WAKEUP:
  83360. + pcd->remote_wakeup_enable = 0;
  83361. + break;
  83362. +
  83363. + case UF_TEST_MODE:
  83364. + /** @todo Add CLEAR_FEATURE for TEST modes. */
  83365. + break;
  83366. +
  83367. + default:
  83368. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  83369. + return;
  83370. + }
  83371. + do_setup_in_status_phase(pcd);
  83372. + break;
  83373. +
  83374. + case UT_ENDPOINT:
  83375. + ep = get_ep_by_addr(pcd, UGETW(ctrl.wIndex));
  83376. + if (ep == 0) {
  83377. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  83378. + return;
  83379. + }
  83380. +
  83381. + pcd_clear_halt(pcd, ep);
  83382. +
  83383. + break;
  83384. + }
  83385. +}
  83386. +
  83387. +/**
  83388. + * This function process the SET_ADDRESS Setup Commands.
  83389. + */
  83390. +static inline void do_set_address(dwc_otg_pcd_t * pcd)
  83391. +{
  83392. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  83393. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  83394. +
  83395. + if (ctrl.bmRequestType == UT_DEVICE) {
  83396. + dcfg_data_t dcfg = {.d32 = 0 };
  83397. +
  83398. +#ifdef DEBUG_EP0
  83399. +// DWC_DEBUGPL(DBG_PCDV, "SET_ADDRESS:%d\n", ctrl.wValue);
  83400. +#endif
  83401. + dcfg.b.devaddr = UGETW(ctrl.wValue);
  83402. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dcfg, 0, dcfg.d32);
  83403. + do_setup_in_status_phase(pcd);
  83404. + }
  83405. +}
  83406. +
  83407. +/**
  83408. + * This function processes SETUP commands. In Linux, the USB Command
  83409. + * processing is done in two places - the first being the PCD and the
  83410. + * second in the Gadget Driver (for example, the File-Backed Storage
  83411. + * Gadget Driver).
  83412. + *
  83413. + * <table>
  83414. + * <tr><td>Command </td><td>Driver </td><td>Description</td></tr>
  83415. + *
  83416. + * <tr><td>GET_STATUS </td><td>PCD </td><td>Command is processed as
  83417. + * defined in chapter 9 of the USB 2.0 Specification chapter 9
  83418. + * </td></tr>
  83419. + *
  83420. + * <tr><td>CLEAR_FEATURE </td><td>PCD </td><td>The Device and Endpoint
  83421. + * requests are the ENDPOINT_HALT feature is procesed, all others the
  83422. + * interface requests are ignored.</td></tr>
  83423. + *
  83424. + * <tr><td>SET_FEATURE </td><td>PCD </td><td>The Device and Endpoint
  83425. + * requests are processed by the PCD. Interface requests are passed
  83426. + * to the Gadget Driver.</td></tr>
  83427. + *
  83428. + * <tr><td>SET_ADDRESS </td><td>PCD </td><td>Program the DCFG reg,
  83429. + * with device address received </td></tr>
  83430. + *
  83431. + * <tr><td>GET_DESCRIPTOR </td><td>Gadget Driver </td><td>Return the
  83432. + * requested descriptor</td></tr>
  83433. + *
  83434. + * <tr><td>SET_DESCRIPTOR </td><td>Gadget Driver </td><td>Optional -
  83435. + * not implemented by any of the existing Gadget Drivers.</td></tr>
  83436. + *
  83437. + * <tr><td>SET_CONFIGURATION </td><td>Gadget Driver </td><td>Disable
  83438. + * all EPs and enable EPs for new configuration.</td></tr>
  83439. + *
  83440. + * <tr><td>GET_CONFIGURATION </td><td>Gadget Driver </td><td>Return
  83441. + * the current configuration</td></tr>
  83442. + *
  83443. + * <tr><td>SET_INTERFACE </td><td>Gadget Driver </td><td>Disable all
  83444. + * EPs and enable EPs for new configuration.</td></tr>
  83445. + *
  83446. + * <tr><td>GET_INTERFACE </td><td>Gadget Driver </td><td>Return the
  83447. + * current interface.</td></tr>
  83448. + *
  83449. + * <tr><td>SYNC_FRAME </td><td>PCD </td><td>Display debug
  83450. + * message.</td></tr>
  83451. + * </table>
  83452. + *
  83453. + * When the SETUP Phase Done interrupt occurs, the PCD SETUP commands are
  83454. + * processed by pcd_setup. Calling the Function Driver's setup function from
  83455. + * pcd_setup processes the gadget SETUP commands.
  83456. + */
  83457. +static inline void pcd_setup(dwc_otg_pcd_t * pcd)
  83458. +{
  83459. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  83460. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  83461. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  83462. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  83463. +
  83464. + deptsiz0_data_t doeptsize0 = {.d32 = 0 };
  83465. +
  83466. +#ifdef DWC_UTE_CFI
  83467. + int retval = 0;
  83468. + struct cfi_usb_ctrlrequest cfi_req;
  83469. +#endif
  83470. +
  83471. + doeptsize0.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[0]->doeptsiz);
  83472. +
  83473. + /** In BDMA more then 1 setup packet is not supported till 3.00a */
  83474. + if (core_if->dma_enable && core_if->dma_desc_enable == 0
  83475. + && (doeptsize0.b.supcnt < 2)
  83476. + && (core_if->snpsid < OTG_CORE_REV_2_94a)) {
  83477. + DWC_ERROR
  83478. + ("\n\n----------- CANNOT handle > 1 setup packet in DMA mode\n\n");
  83479. + }
  83480. + if ((core_if->snpsid >= OTG_CORE_REV_3_00a)
  83481. + && (core_if->dma_enable == 1) && (core_if->dma_desc_enable == 0)) {
  83482. + ctrl =
  83483. + (pcd->setup_pkt +
  83484. + (3 - doeptsize0.b.supcnt - 1 +
  83485. + ep0->dwc_ep.stp_rollover))->req;
  83486. + }
  83487. +#ifdef DEBUG_EP0
  83488. + DWC_DEBUGPL(DBG_PCD, "SETUP %02x.%02x v%04x i%04x l%04x\n",
  83489. + ctrl.bmRequestType, ctrl.bRequest,
  83490. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  83491. + UGETW(ctrl.wLength));
  83492. +#endif
  83493. +
  83494. + /* Clean up the request queue */
  83495. + dwc_otg_request_nuke(ep0);
  83496. + ep0->stopped = 0;
  83497. +
  83498. + if (ctrl.bmRequestType & UE_DIR_IN) {
  83499. + ep0->dwc_ep.is_in = 1;
  83500. + pcd->ep0state = EP0_IN_DATA_PHASE;
  83501. + } else {
  83502. + ep0->dwc_ep.is_in = 0;
  83503. + pcd->ep0state = EP0_OUT_DATA_PHASE;
  83504. + }
  83505. +
  83506. + if (UGETW(ctrl.wLength) == 0) {
  83507. + ep0->dwc_ep.is_in = 1;
  83508. + pcd->ep0state = EP0_IN_STATUS_PHASE;
  83509. + }
  83510. +
  83511. + if (UT_GET_TYPE(ctrl.bmRequestType) != UT_STANDARD) {
  83512. +
  83513. +#ifdef DWC_UTE_CFI
  83514. + DWC_MEMCPY(&cfi_req, &ctrl, sizeof(usb_device_request_t));
  83515. +
  83516. + //printk(KERN_ALERT "CFI: req_type=0x%02x; req=0x%02x\n",
  83517. + ctrl.bRequestType, ctrl.bRequest);
  83518. + if (UT_GET_TYPE(cfi_req.bRequestType) == UT_VENDOR) {
  83519. + if (cfi_req.bRequest > 0xB0 && cfi_req.bRequest < 0xBF) {
  83520. + retval = cfi_setup(pcd, &cfi_req);
  83521. + if (retval < 0) {
  83522. + ep0_do_stall(pcd, retval);
  83523. + pcd->ep0_pending = 0;
  83524. + return;
  83525. + }
  83526. +
  83527. + /* if need gadget setup then call it and check the retval */
  83528. + if (pcd->cfi->need_gadget_att) {
  83529. + retval =
  83530. + cfi_gadget_setup(pcd,
  83531. + &pcd->
  83532. + cfi->ctrl_req);
  83533. + if (retval < 0) {
  83534. + pcd->ep0_pending = 0;
  83535. + return;
  83536. + }
  83537. + }
  83538. +
  83539. + if (pcd->cfi->need_status_in_complete) {
  83540. + do_setup_in_status_phase(pcd);
  83541. + }
  83542. + return;
  83543. + }
  83544. + }
  83545. +#endif
  83546. +
  83547. + /* handle non-standard (class/vendor) requests in the gadget driver */
  83548. + do_gadget_setup(pcd, &ctrl);
  83549. + return;
  83550. + }
  83551. +
  83552. + /** @todo NGS: Handle bad setup packet? */
  83553. +
  83554. +///////////////////////////////////////////
  83555. +//// --- Standard Request handling --- ////
  83556. +
  83557. + switch (ctrl.bRequest) {
  83558. + case UR_GET_STATUS:
  83559. + do_get_status(pcd);
  83560. + break;
  83561. +
  83562. + case UR_CLEAR_FEATURE:
  83563. + do_clear_feature(pcd);
  83564. + break;
  83565. +
  83566. + case UR_SET_FEATURE:
  83567. + do_set_feature(pcd);
  83568. + break;
  83569. +
  83570. + case UR_SET_ADDRESS:
  83571. + do_set_address(pcd);
  83572. + break;
  83573. +
  83574. + case UR_SET_INTERFACE:
  83575. + case UR_SET_CONFIG:
  83576. +// _pcd->request_config = 1; /* Configuration changed */
  83577. + do_gadget_setup(pcd, &ctrl);
  83578. + break;
  83579. +
  83580. + case UR_SYNCH_FRAME:
  83581. + do_gadget_setup(pcd, &ctrl);
  83582. + break;
  83583. +
  83584. + default:
  83585. + /* Call the Gadget Driver's setup functions */
  83586. + do_gadget_setup(pcd, &ctrl);
  83587. + break;
  83588. + }
  83589. +}
  83590. +
  83591. +/**
  83592. + * This function completes the ep0 control transfer.
  83593. + */
  83594. +static int32_t ep0_complete_request(dwc_otg_pcd_ep_t * ep)
  83595. +{
  83596. + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
  83597. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  83598. + dwc_otg_dev_in_ep_regs_t *in_ep_regs =
  83599. + dev_if->in_ep_regs[ep->dwc_ep.num];
  83600. +#ifdef DEBUG_EP0
  83601. + dwc_otg_dev_out_ep_regs_t *out_ep_regs =
  83602. + dev_if->out_ep_regs[ep->dwc_ep.num];
  83603. +#endif
  83604. + deptsiz0_data_t deptsiz;
  83605. + dev_dma_desc_sts_t desc_sts;
  83606. + dwc_otg_pcd_request_t *req;
  83607. + int is_last = 0;
  83608. + dwc_otg_pcd_t *pcd = ep->pcd;
  83609. +
  83610. +#ifdef DWC_UTE_CFI
  83611. + struct cfi_usb_ctrlrequest *ctrlreq;
  83612. + int retval = -DWC_E_NOT_SUPPORTED;
  83613. +#endif
  83614. +
  83615. + desc_sts.b.bytes = 0;
  83616. +
  83617. + if (pcd->ep0_pending && DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  83618. + if (ep->dwc_ep.is_in) {
  83619. +#ifdef DEBUG_EP0
  83620. + DWC_DEBUGPL(DBG_PCDV, "Do setup OUT status phase\n");
  83621. +#endif
  83622. + do_setup_out_status_phase(pcd);
  83623. + } else {
  83624. +#ifdef DEBUG_EP0
  83625. + DWC_DEBUGPL(DBG_PCDV, "Do setup IN status phase\n");
  83626. +#endif
  83627. +
  83628. +#ifdef DWC_UTE_CFI
  83629. + ctrlreq = &pcd->cfi->ctrl_req;
  83630. +
  83631. + if (UT_GET_TYPE(ctrlreq->bRequestType) == UT_VENDOR) {
  83632. + if (ctrlreq->bRequest > 0xB0
  83633. + && ctrlreq->bRequest < 0xBF) {
  83634. +
  83635. + /* Return if the PCD failed to handle the request */
  83636. + if ((retval =
  83637. + pcd->cfi->ops.
  83638. + ctrl_write_complete(pcd->cfi,
  83639. + pcd)) < 0) {
  83640. + CFI_INFO
  83641. + ("ERROR setting a new value in the PCD(%d)\n",
  83642. + retval);
  83643. + ep0_do_stall(pcd, retval);
  83644. + pcd->ep0_pending = 0;
  83645. + return 0;
  83646. + }
  83647. +
  83648. + /* If the gadget needs to be notified on the request */
  83649. + if (pcd->cfi->need_gadget_att == 1) {
  83650. + //retval = do_gadget_setup(pcd, &pcd->cfi->ctrl_req);
  83651. + retval =
  83652. + cfi_gadget_setup(pcd,
  83653. + &pcd->cfi->
  83654. + ctrl_req);
  83655. +
  83656. + /* Return from the function if the gadget failed to process
  83657. + * the request properly - this should never happen !!!
  83658. + */
  83659. + if (retval < 0) {
  83660. + CFI_INFO
  83661. + ("ERROR setting a new value in the gadget(%d)\n",
  83662. + retval);
  83663. + pcd->ep0_pending = 0;
  83664. + return 0;
  83665. + }
  83666. + }
  83667. +
  83668. + CFI_INFO("%s: RETVAL=%d\n", __func__,
  83669. + retval);
  83670. + /* If we hit here then the PCD and the gadget has properly
  83671. + * handled the request - so send the ZLP IN to the host.
  83672. + */
  83673. + /* @todo: MAS - decide whether we need to start the setup
  83674. + * stage based on the need_setup value of the cfi object
  83675. + */
  83676. + do_setup_in_status_phase(pcd);
  83677. + pcd->ep0_pending = 0;
  83678. + return 1;
  83679. + }
  83680. + }
  83681. +#endif
  83682. +
  83683. + do_setup_in_status_phase(pcd);
  83684. + }
  83685. + pcd->ep0_pending = 0;
  83686. + return 1;
  83687. + }
  83688. +
  83689. + if (DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  83690. + return 0;
  83691. + }
  83692. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  83693. +
  83694. + if (pcd->ep0state == EP0_OUT_STATUS_PHASE
  83695. + || pcd->ep0state == EP0_IN_STATUS_PHASE) {
  83696. + is_last = 1;
  83697. + } else if (ep->dwc_ep.is_in) {
  83698. + deptsiz.d32 = DWC_READ_REG32(&in_ep_regs->dieptsiz);
  83699. + if (core_if->dma_desc_enable != 0)
  83700. + desc_sts = dev_if->in_desc_addr->status;
  83701. +#ifdef DEBUG_EP0
  83702. + DWC_DEBUGPL(DBG_PCDV, "%d len=%d xfersize=%d pktcnt=%d\n",
  83703. + ep->dwc_ep.num, ep->dwc_ep.xfer_len,
  83704. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  83705. +#endif
  83706. +
  83707. + if (((core_if->dma_desc_enable == 0)
  83708. + && (deptsiz.b.xfersize == 0))
  83709. + || ((core_if->dma_desc_enable != 0)
  83710. + && (desc_sts.b.bytes == 0))) {
  83711. + req->actual = ep->dwc_ep.xfer_count;
  83712. + /* Is a Zero Len Packet needed? */
  83713. + if (req->sent_zlp) {
  83714. +#ifdef DEBUG_EP0
  83715. + DWC_DEBUGPL(DBG_PCD, "Setup Rx ZLP\n");
  83716. +#endif
  83717. + req->sent_zlp = 0;
  83718. + }
  83719. + do_setup_out_status_phase(pcd);
  83720. + }
  83721. + } else {
  83722. + /* ep0-OUT */
  83723. +#ifdef DEBUG_EP0
  83724. + deptsiz.d32 = DWC_READ_REG32(&out_ep_regs->doeptsiz);
  83725. + DWC_DEBUGPL(DBG_PCDV, "%d len=%d xsize=%d pktcnt=%d\n",
  83726. + ep->dwc_ep.num, ep->dwc_ep.xfer_len,
  83727. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  83728. +#endif
  83729. + req->actual = ep->dwc_ep.xfer_count;
  83730. +
  83731. + /* Is a Zero Len Packet needed? */
  83732. + if (req->sent_zlp) {
  83733. +#ifdef DEBUG_EP0
  83734. + DWC_DEBUGPL(DBG_PCDV, "Setup Tx ZLP\n");
  83735. +#endif
  83736. + req->sent_zlp = 0;
  83737. + }
  83738. + /* For older cores do setup in status phase in Slave/BDMA modes,
  83739. + * starting from 3.00 do that only in slave, and for DMA modes
  83740. + * just re-enable ep 0 OUT here*/
  83741. + if (core_if->dma_enable == 0
  83742. + || (core_if->dma_desc_enable == 0
  83743. + && core_if->snpsid <= OTG_CORE_REV_2_94a)) {
  83744. + do_setup_in_status_phase(pcd);
  83745. + } else if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  83746. + DWC_DEBUGPL(DBG_PCDV,
  83747. + "Enable out ep before in status phase\n");
  83748. + ep0_out_start(core_if, pcd);
  83749. + }
  83750. + }
  83751. +
  83752. + /* Complete the request */
  83753. + if (is_last) {
  83754. + dwc_otg_request_done(ep, req, 0);
  83755. + ep->dwc_ep.start_xfer_buff = 0;
  83756. + ep->dwc_ep.xfer_buff = 0;
  83757. + ep->dwc_ep.xfer_len = 0;
  83758. + return 1;
  83759. + }
  83760. + return 0;
  83761. +}
  83762. +
  83763. +#ifdef DWC_UTE_CFI
  83764. +/**
  83765. + * This function calculates traverses all the CFI DMA descriptors and
  83766. + * and accumulates the bytes that are left to be transfered.
  83767. + *
  83768. + * @return The total bytes left to transfered, or a negative value as failure
  83769. + */
  83770. +static inline int cfi_calc_desc_residue(dwc_otg_pcd_ep_t * ep)
  83771. +{
  83772. + int32_t ret = 0;
  83773. + int i;
  83774. + struct dwc_otg_dma_desc *ddesc = NULL;
  83775. + struct cfi_ep *cfiep;
  83776. +
  83777. + /* See if the pcd_ep has its respective cfi_ep mapped */
  83778. + cfiep = get_cfi_ep_by_pcd_ep(ep->pcd->cfi, ep);
  83779. + if (!cfiep) {
  83780. + CFI_INFO("%s: Failed to find ep\n", __func__);
  83781. + return -1;
  83782. + }
  83783. +
  83784. + ddesc = ep->dwc_ep.descs;
  83785. +
  83786. + for (i = 0; (i < cfiep->desc_count) && (i < MAX_DMA_DESCS_PER_EP); i++) {
  83787. +
  83788. +#if defined(PRINT_CFI_DMA_DESCS)
  83789. + print_desc(ddesc, ep->ep.name, i);
  83790. +#endif
  83791. + ret += ddesc->status.b.bytes;
  83792. + ddesc++;
  83793. + }
  83794. +
  83795. + if (ret)
  83796. + CFI_INFO("!!!!!!!!!! WARNING (%s) - residue=%d\n", __func__,
  83797. + ret);
  83798. +
  83799. + return ret;
  83800. +}
  83801. +#endif
  83802. +
  83803. +/**
  83804. + * This function completes the request for the EP. If there are
  83805. + * additional requests for the EP in the queue they will be started.
  83806. + */
  83807. +static void complete_ep(dwc_otg_pcd_ep_t * ep)
  83808. +{
  83809. + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
  83810. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  83811. + dwc_otg_dev_in_ep_regs_t *in_ep_regs =
  83812. + dev_if->in_ep_regs[ep->dwc_ep.num];
  83813. + deptsiz_data_t deptsiz;
  83814. + dev_dma_desc_sts_t desc_sts;
  83815. + dwc_otg_pcd_request_t *req = 0;
  83816. + dwc_otg_dev_dma_desc_t *dma_desc;
  83817. + uint32_t byte_count = 0;
  83818. + int is_last = 0;
  83819. + int i;
  83820. +
  83821. + DWC_DEBUGPL(DBG_PCDV, "%s() %d-%s\n", __func__, ep->dwc_ep.num,
  83822. + (ep->dwc_ep.is_in ? "IN" : "OUT"));
  83823. +
  83824. + /* Get any pending requests */
  83825. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  83826. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  83827. + if (!req) {
  83828. + DWC_PRINTF("complete_ep 0x%p, req = NULL!\n", ep);
  83829. + return;
  83830. + }
  83831. + } else {
  83832. + DWC_PRINTF("complete_ep 0x%p, ep->queue empty!\n", ep);
  83833. + return;
  83834. + }
  83835. +
  83836. + DWC_DEBUGPL(DBG_PCD, "Requests %d\n", ep->pcd->request_pending);
  83837. +
  83838. + if (ep->dwc_ep.is_in) {
  83839. + deptsiz.d32 = DWC_READ_REG32(&in_ep_regs->dieptsiz);
  83840. +
  83841. + if (core_if->dma_enable) {
  83842. + if (core_if->dma_desc_enable == 0) {
  83843. + if (deptsiz.b.xfersize == 0
  83844. + && deptsiz.b.pktcnt == 0) {
  83845. + byte_count =
  83846. + ep->dwc_ep.xfer_len -
  83847. + ep->dwc_ep.xfer_count;
  83848. +
  83849. + ep->dwc_ep.xfer_buff += byte_count;
  83850. + ep->dwc_ep.dma_addr += byte_count;
  83851. + ep->dwc_ep.xfer_count += byte_count;
  83852. +
  83853. + DWC_DEBUGPL(DBG_PCDV,
  83854. + "%d-%s len=%d xfersize=%d pktcnt=%d\n",
  83855. + ep->dwc_ep.num,
  83856. + (ep->dwc_ep.
  83857. + is_in ? "IN" : "OUT"),
  83858. + ep->dwc_ep.xfer_len,
  83859. + deptsiz.b.xfersize,
  83860. + deptsiz.b.pktcnt);
  83861. +
  83862. + if (ep->dwc_ep.xfer_len <
  83863. + ep->dwc_ep.total_len) {
  83864. + dwc_otg_ep_start_transfer
  83865. + (core_if, &ep->dwc_ep);
  83866. + } else if (ep->dwc_ep.sent_zlp) {
  83867. + /*
  83868. + * This fragment of code should initiate 0
  83869. + * length transfer in case if it is queued
  83870. + * a transfer with size divisible to EPs max
  83871. + * packet size and with usb_request zero field
  83872. + * is set, which means that after data is transfered,
  83873. + * it is also should be transfered
  83874. + * a 0 length packet at the end. For Slave and
  83875. + * Buffer DMA modes in this case SW has
  83876. + * to initiate 2 transfers one with transfer size,
  83877. + * and the second with 0 size. For Descriptor
  83878. + * DMA mode SW is able to initiate a transfer,
  83879. + * which will handle all the packets including
  83880. + * the last 0 length.
  83881. + */
  83882. + ep->dwc_ep.sent_zlp = 0;
  83883. + dwc_otg_ep_start_zl_transfer
  83884. + (core_if, &ep->dwc_ep);
  83885. + } else {
  83886. + is_last = 1;
  83887. + }
  83888. + } else {
  83889. + if (ep->dwc_ep.type ==
  83890. + DWC_OTG_EP_TYPE_ISOC) {
  83891. + req->actual = 0;
  83892. + dwc_otg_request_done(ep, req, 0);
  83893. +
  83894. + ep->dwc_ep.start_xfer_buff = 0;
  83895. + ep->dwc_ep.xfer_buff = 0;
  83896. + ep->dwc_ep.xfer_len = 0;
  83897. +
  83898. + /* If there is a request in the queue start it. */
  83899. + start_next_request(ep);
  83900. + } else
  83901. + DWC_WARN
  83902. + ("Incomplete transfer (%d - %s [siz=%d pkt=%d])\n",
  83903. + ep->dwc_ep.num,
  83904. + (ep->dwc_ep.is_in ? "IN" : "OUT"),
  83905. + deptsiz.b.xfersize,
  83906. + deptsiz.b.pktcnt);
  83907. + }
  83908. + } else {
  83909. + dma_desc = ep->dwc_ep.desc_addr;
  83910. + byte_count = 0;
  83911. + ep->dwc_ep.sent_zlp = 0;
  83912. +
  83913. +#ifdef DWC_UTE_CFI
  83914. + CFI_INFO("%s: BUFFER_MODE=%d\n", __func__,
  83915. + ep->dwc_ep.buff_mode);
  83916. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  83917. + int residue;
  83918. +
  83919. + residue = cfi_calc_desc_residue(ep);
  83920. + if (residue < 0)
  83921. + return;
  83922. +
  83923. + byte_count = residue;
  83924. + } else {
  83925. +#endif
  83926. + for (i = 0; i < ep->dwc_ep.desc_cnt;
  83927. + ++i) {
  83928. + desc_sts = dma_desc->status;
  83929. + byte_count += desc_sts.b.bytes;
  83930. + dma_desc++;
  83931. + }
  83932. +#ifdef DWC_UTE_CFI
  83933. + }
  83934. +#endif
  83935. + if (byte_count == 0) {
  83936. + ep->dwc_ep.xfer_count =
  83937. + ep->dwc_ep.total_len;
  83938. + is_last = 1;
  83939. + } else {
  83940. + DWC_WARN("Incomplete transfer\n");
  83941. + }
  83942. + }
  83943. + } else {
  83944. + if (deptsiz.b.xfersize == 0 && deptsiz.b.pktcnt == 0) {
  83945. + DWC_DEBUGPL(DBG_PCDV,
  83946. + "%d-%s len=%d xfersize=%d pktcnt=%d\n",
  83947. + ep->dwc_ep.num,
  83948. + ep->dwc_ep.is_in ? "IN" : "OUT",
  83949. + ep->dwc_ep.xfer_len,
  83950. + deptsiz.b.xfersize,
  83951. + deptsiz.b.pktcnt);
  83952. +
  83953. + /* Check if the whole transfer was completed,
  83954. + * if no, setup transfer for next portion of data
  83955. + */
  83956. + if (ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
  83957. + dwc_otg_ep_start_transfer(core_if,
  83958. + &ep->dwc_ep);
  83959. + } else if (ep->dwc_ep.sent_zlp) {
  83960. + /*
  83961. + * This fragment of code should initiate 0
  83962. + * length trasfer in case if it is queued
  83963. + * a trasfer with size divisible to EPs max
  83964. + * packet size and with usb_request zero field
  83965. + * is set, which means that after data is transfered,
  83966. + * it is also should be transfered
  83967. + * a 0 length packet at the end. For Slave and
  83968. + * Buffer DMA modes in this case SW has
  83969. + * to initiate 2 transfers one with transfer size,
  83970. + * and the second with 0 size. For Desriptor
  83971. + * DMA mode SW is able to initiate a transfer,
  83972. + * which will handle all the packets including
  83973. + * the last 0 legth.
  83974. + */
  83975. + ep->dwc_ep.sent_zlp = 0;
  83976. + dwc_otg_ep_start_zl_transfer(core_if,
  83977. + &ep->dwc_ep);
  83978. + } else {
  83979. + is_last = 1;
  83980. + }
  83981. + } else {
  83982. + DWC_WARN
  83983. + ("Incomplete transfer (%d-%s [siz=%d pkt=%d])\n",
  83984. + ep->dwc_ep.num,
  83985. + (ep->dwc_ep.is_in ? "IN" : "OUT"),
  83986. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  83987. + }
  83988. + }
  83989. + } else {
  83990. + dwc_otg_dev_out_ep_regs_t *out_ep_regs =
  83991. + dev_if->out_ep_regs[ep->dwc_ep.num];
  83992. + desc_sts.d32 = 0;
  83993. + if (core_if->dma_enable) {
  83994. + if (core_if->dma_desc_enable) {
  83995. + dma_desc = ep->dwc_ep.desc_addr;
  83996. + byte_count = 0;
  83997. + ep->dwc_ep.sent_zlp = 0;
  83998. +
  83999. +#ifdef DWC_UTE_CFI
  84000. + CFI_INFO("%s: BUFFER_MODE=%d\n", __func__,
  84001. + ep->dwc_ep.buff_mode);
  84002. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  84003. + int residue;
  84004. + residue = cfi_calc_desc_residue(ep);
  84005. + if (residue < 0)
  84006. + return;
  84007. + byte_count = residue;
  84008. + } else {
  84009. +#endif
  84010. +
  84011. + for (i = 0; i < ep->dwc_ep.desc_cnt;
  84012. + ++i) {
  84013. + desc_sts = dma_desc->status;
  84014. + byte_count += desc_sts.b.bytes;
  84015. + dma_desc++;
  84016. + }
  84017. +
  84018. +#ifdef DWC_UTE_CFI
  84019. + }
  84020. +#endif
  84021. + /* Checking for interrupt Out transfers with not
  84022. + * dword aligned mps sizes
  84023. + */
  84024. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_INTR &&
  84025. + (ep->dwc_ep.maxpacket%4)) {
  84026. + ep->dwc_ep.xfer_count =
  84027. + ep->dwc_ep.total_len - byte_count;
  84028. + if ((ep->dwc_ep.xfer_len %
  84029. + ep->dwc_ep.maxpacket)
  84030. + && (ep->dwc_ep.xfer_len /
  84031. + ep->dwc_ep.maxpacket <
  84032. + MAX_DMA_DESC_CNT))
  84033. + ep->dwc_ep.xfer_len -=
  84034. + (ep->dwc_ep.desc_cnt -
  84035. + 1) * ep->dwc_ep.maxpacket +
  84036. + ep->dwc_ep.xfer_len %
  84037. + ep->dwc_ep.maxpacket;
  84038. + else
  84039. + ep->dwc_ep.xfer_len -=
  84040. + ep->dwc_ep.desc_cnt *
  84041. + ep->dwc_ep.maxpacket;
  84042. + if (ep->dwc_ep.xfer_len > 0) {
  84043. + dwc_otg_ep_start_transfer
  84044. + (core_if, &ep->dwc_ep);
  84045. + } else {
  84046. + is_last = 1;
  84047. + }
  84048. + } else {
  84049. + ep->dwc_ep.xfer_count =
  84050. + ep->dwc_ep.total_len - byte_count +
  84051. + ((4 -
  84052. + (ep->dwc_ep.
  84053. + total_len & 0x3)) & 0x3);
  84054. + is_last = 1;
  84055. + }
  84056. + } else {
  84057. + deptsiz.d32 = 0;
  84058. + deptsiz.d32 =
  84059. + DWC_READ_REG32(&out_ep_regs->doeptsiz);
  84060. +
  84061. + byte_count = (ep->dwc_ep.xfer_len -
  84062. + ep->dwc_ep.xfer_count -
  84063. + deptsiz.b.xfersize);
  84064. + ep->dwc_ep.xfer_buff += byte_count;
  84065. + ep->dwc_ep.dma_addr += byte_count;
  84066. + ep->dwc_ep.xfer_count += byte_count;
  84067. +
  84068. + /* Check if the whole transfer was completed,
  84069. + * if no, setup transfer for next portion of data
  84070. + */
  84071. + if (ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
  84072. + dwc_otg_ep_start_transfer(core_if,
  84073. + &ep->dwc_ep);
  84074. + } else if (ep->dwc_ep.sent_zlp) {
  84075. + /*
  84076. + * This fragment of code should initiate 0
  84077. + * length trasfer in case if it is queued
  84078. + * a trasfer with size divisible to EPs max
  84079. + * packet size and with usb_request zero field
  84080. + * is set, which means that after data is transfered,
  84081. + * it is also should be transfered
  84082. + * a 0 length packet at the end. For Slave and
  84083. + * Buffer DMA modes in this case SW has
  84084. + * to initiate 2 transfers one with transfer size,
  84085. + * and the second with 0 size. For Desriptor
  84086. + * DMA mode SW is able to initiate a transfer,
  84087. + * which will handle all the packets including
  84088. + * the last 0 legth.
  84089. + */
  84090. + ep->dwc_ep.sent_zlp = 0;
  84091. + dwc_otg_ep_start_zl_transfer(core_if,
  84092. + &ep->dwc_ep);
  84093. + } else {
  84094. + is_last = 1;
  84095. + }
  84096. + }
  84097. + } else {
  84098. + /* Check if the whole transfer was completed,
  84099. + * if no, setup transfer for next portion of data
  84100. + */
  84101. + if (ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
  84102. + dwc_otg_ep_start_transfer(core_if, &ep->dwc_ep);
  84103. + } else if (ep->dwc_ep.sent_zlp) {
  84104. + /*
  84105. + * This fragment of code should initiate 0
  84106. + * length transfer in case if it is queued
  84107. + * a transfer with size divisible to EPs max
  84108. + * packet size and with usb_request zero field
  84109. + * is set, which means that after data is transfered,
  84110. + * it is also should be transfered
  84111. + * a 0 length packet at the end. For Slave and
  84112. + * Buffer DMA modes in this case SW has
  84113. + * to initiate 2 transfers one with transfer size,
  84114. + * and the second with 0 size. For Descriptor
  84115. + * DMA mode SW is able to initiate a transfer,
  84116. + * which will handle all the packets including
  84117. + * the last 0 length.
  84118. + */
  84119. + ep->dwc_ep.sent_zlp = 0;
  84120. + dwc_otg_ep_start_zl_transfer(core_if,
  84121. + &ep->dwc_ep);
  84122. + } else {
  84123. + is_last = 1;
  84124. + }
  84125. + }
  84126. +
  84127. + DWC_DEBUGPL(DBG_PCDV,
  84128. + "addr %p, %d-%s len=%d cnt=%d xsize=%d pktcnt=%d\n",
  84129. + &out_ep_regs->doeptsiz, ep->dwc_ep.num,
  84130. + ep->dwc_ep.is_in ? "IN" : "OUT",
  84131. + ep->dwc_ep.xfer_len, ep->dwc_ep.xfer_count,
  84132. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  84133. + }
  84134. +
  84135. + /* Complete the request */
  84136. + if (is_last) {
  84137. +#ifdef DWC_UTE_CFI
  84138. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  84139. + req->actual = ep->dwc_ep.cfi_req_len - byte_count;
  84140. + } else {
  84141. +#endif
  84142. + req->actual = ep->dwc_ep.xfer_count;
  84143. +#ifdef DWC_UTE_CFI
  84144. + }
  84145. +#endif
  84146. + if (req->dw_align_buf) {
  84147. + if (!ep->dwc_ep.is_in) {
  84148. + dwc_memcpy(req->buf, req->dw_align_buf, req->length);
  84149. + }
  84150. + DWC_DMA_FREE(req->length, req->dw_align_buf,
  84151. + req->dw_align_buf_dma);
  84152. + }
  84153. +
  84154. + dwc_otg_request_done(ep, req, 0);
  84155. +
  84156. + ep->dwc_ep.start_xfer_buff = 0;
  84157. + ep->dwc_ep.xfer_buff = 0;
  84158. + ep->dwc_ep.xfer_len = 0;
  84159. +
  84160. + /* If there is a request in the queue start it. */
  84161. + start_next_request(ep);
  84162. + }
  84163. +}
  84164. +
  84165. +#ifdef DWC_EN_ISOC
  84166. +
  84167. +/**
  84168. + * This function BNA interrupt for Isochronous EPs
  84169. + *
  84170. + */
  84171. +static void dwc_otg_pcd_handle_iso_bna(dwc_otg_pcd_ep_t * ep)
  84172. +{
  84173. + dwc_ep_t *dwc_ep = &ep->dwc_ep;
  84174. + volatile uint32_t *addr;
  84175. + depctl_data_t depctl = {.d32 = 0 };
  84176. + dwc_otg_pcd_t *pcd = ep->pcd;
  84177. + dwc_otg_dev_dma_desc_t *dma_desc;
  84178. + int i;
  84179. +
  84180. + dma_desc =
  84181. + dwc_ep->iso_desc_addr + dwc_ep->desc_cnt * (dwc_ep->proc_buf_num);
  84182. +
  84183. + if (dwc_ep->is_in) {
  84184. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  84185. + for (i = 0; i < dwc_ep->desc_cnt; ++i, ++dma_desc) {
  84186. + sts.d32 = dma_desc->status.d32;
  84187. + sts.b_iso_in.bs = BS_HOST_READY;
  84188. + dma_desc->status.d32 = sts.d32;
  84189. + }
  84190. + } else {
  84191. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  84192. + for (i = 0; i < dwc_ep->desc_cnt; ++i, ++dma_desc) {
  84193. + sts.d32 = dma_desc->status.d32;
  84194. + sts.b_iso_out.bs = BS_HOST_READY;
  84195. + dma_desc->status.d32 = sts.d32;
  84196. + }
  84197. + }
  84198. +
  84199. + if (dwc_ep->is_in == 0) {
  84200. + addr =
  84201. + &GET_CORE_IF(pcd)->dev_if->out_ep_regs[dwc_ep->
  84202. + num]->doepctl;
  84203. + } else {
  84204. + addr =
  84205. + &GET_CORE_IF(pcd)->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  84206. + }
  84207. + depctl.b.epena = 1;
  84208. + DWC_MODIFY_REG32(addr, depctl.d32, depctl.d32);
  84209. +}
  84210. +
  84211. +/**
  84212. + * This function sets latest iso packet information(non-PTI mode)
  84213. + *
  84214. + * @param core_if Programming view of DWC_otg controller.
  84215. + * @param ep The EP to start the transfer on.
  84216. + *
  84217. + */
  84218. +void set_current_pkt_info(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  84219. +{
  84220. + deptsiz_data_t deptsiz = {.d32 = 0 };
  84221. + dma_addr_t dma_addr;
  84222. + uint32_t offset;
  84223. +
  84224. + if (ep->proc_buf_num)
  84225. + dma_addr = ep->dma_addr1;
  84226. + else
  84227. + dma_addr = ep->dma_addr0;
  84228. +
  84229. + if (ep->is_in) {
  84230. + deptsiz.d32 =
  84231. + DWC_READ_REG32(&core_if->dev_if->
  84232. + in_ep_regs[ep->num]->dieptsiz);
  84233. + offset = ep->data_per_frame;
  84234. + } else {
  84235. + deptsiz.d32 =
  84236. + DWC_READ_REG32(&core_if->dev_if->
  84237. + out_ep_regs[ep->num]->doeptsiz);
  84238. + offset =
  84239. + ep->data_per_frame +
  84240. + (0x4 & (0x4 - (ep->data_per_frame & 0x3)));
  84241. + }
  84242. +
  84243. + if (!deptsiz.b.xfersize) {
  84244. + ep->pkt_info[ep->cur_pkt].length = ep->data_per_frame;
  84245. + ep->pkt_info[ep->cur_pkt].offset =
  84246. + ep->cur_pkt_dma_addr - dma_addr;
  84247. + ep->pkt_info[ep->cur_pkt].status = 0;
  84248. + } else {
  84249. + ep->pkt_info[ep->cur_pkt].length = ep->data_per_frame;
  84250. + ep->pkt_info[ep->cur_pkt].offset =
  84251. + ep->cur_pkt_dma_addr - dma_addr;
  84252. + ep->pkt_info[ep->cur_pkt].status = -DWC_E_NO_DATA;
  84253. + }
  84254. + ep->cur_pkt_addr += offset;
  84255. + ep->cur_pkt_dma_addr += offset;
  84256. + ep->cur_pkt++;
  84257. +}
  84258. +
  84259. +/**
  84260. + * This function sets latest iso packet information(DDMA mode)
  84261. + *
  84262. + * @param core_if Programming view of DWC_otg controller.
  84263. + * @param dwc_ep The EP to start the transfer on.
  84264. + *
  84265. + */
  84266. +static void set_ddma_iso_pkts_info(dwc_otg_core_if_t * core_if,
  84267. + dwc_ep_t * dwc_ep)
  84268. +{
  84269. + dwc_otg_dev_dma_desc_t *dma_desc;
  84270. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  84271. + iso_pkt_info_t *iso_packet;
  84272. + uint32_t data_per_desc;
  84273. + uint32_t offset;
  84274. + int i, j;
  84275. +
  84276. + iso_packet = dwc_ep->pkt_info;
  84277. +
  84278. + /** Reinit closed DMA Descriptors*/
  84279. + /** ISO OUT EP */
  84280. + if (dwc_ep->is_in == 0) {
  84281. + dma_desc =
  84282. + dwc_ep->iso_desc_addr +
  84283. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  84284. + offset = 0;
  84285. +
  84286. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  84287. + i += dwc_ep->pkt_per_frm) {
  84288. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  84289. + data_per_desc =
  84290. + ((j + 1) * dwc_ep->maxpacket >
  84291. + dwc_ep->
  84292. + data_per_frame) ? dwc_ep->data_per_frame -
  84293. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  84294. + data_per_desc +=
  84295. + (data_per_desc % 4) ? (4 -
  84296. + data_per_desc %
  84297. + 4) : 0;
  84298. +
  84299. + sts.d32 = dma_desc->status.d32;
  84300. +
  84301. + /* Write status in iso_packet_decsriptor */
  84302. + iso_packet->status =
  84303. + sts.b_iso_out.rxsts +
  84304. + (sts.b_iso_out.bs ^ BS_DMA_DONE);
  84305. + if (iso_packet->status) {
  84306. + iso_packet->status = -DWC_E_NO_DATA;
  84307. + }
  84308. +
  84309. + /* Received data length */
  84310. + if (!sts.b_iso_out.rxbytes) {
  84311. + iso_packet->length =
  84312. + data_per_desc -
  84313. + sts.b_iso_out.rxbytes;
  84314. + } else {
  84315. + iso_packet->length =
  84316. + data_per_desc -
  84317. + sts.b_iso_out.rxbytes + (4 -
  84318. + dwc_ep->data_per_frame
  84319. + % 4);
  84320. + }
  84321. +
  84322. + iso_packet->offset = offset;
  84323. +
  84324. + offset += data_per_desc;
  84325. + dma_desc++;
  84326. + iso_packet++;
  84327. + }
  84328. + }
  84329. +
  84330. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  84331. + data_per_desc =
  84332. + ((j + 1) * dwc_ep->maxpacket >
  84333. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  84334. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  84335. + data_per_desc +=
  84336. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  84337. +
  84338. + sts.d32 = dma_desc->status.d32;
  84339. +
  84340. + /* Write status in iso_packet_decsriptor */
  84341. + iso_packet->status =
  84342. + sts.b_iso_out.rxsts +
  84343. + (sts.b_iso_out.bs ^ BS_DMA_DONE);
  84344. + if (iso_packet->status) {
  84345. + iso_packet->status = -DWC_E_NO_DATA;
  84346. + }
  84347. +
  84348. + /* Received data length */
  84349. + iso_packet->length =
  84350. + dwc_ep->data_per_frame - sts.b_iso_out.rxbytes;
  84351. +
  84352. + iso_packet->offset = offset;
  84353. +
  84354. + offset += data_per_desc;
  84355. + iso_packet++;
  84356. + dma_desc++;
  84357. + }
  84358. +
  84359. + sts.d32 = dma_desc->status.d32;
  84360. +
  84361. + /* Write status in iso_packet_decsriptor */
  84362. + iso_packet->status =
  84363. + sts.b_iso_out.rxsts + (sts.b_iso_out.bs ^ BS_DMA_DONE);
  84364. + if (iso_packet->status) {
  84365. + iso_packet->status = -DWC_E_NO_DATA;
  84366. + }
  84367. + /* Received data length */
  84368. + if (!sts.b_iso_out.rxbytes) {
  84369. + iso_packet->length =
  84370. + dwc_ep->data_per_frame - sts.b_iso_out.rxbytes;
  84371. + } else {
  84372. + iso_packet->length =
  84373. + dwc_ep->data_per_frame - sts.b_iso_out.rxbytes +
  84374. + (4 - dwc_ep->data_per_frame % 4);
  84375. + }
  84376. +
  84377. + iso_packet->offset = offset;
  84378. + } else {
  84379. +/** ISO IN EP */
  84380. +
  84381. + dma_desc =
  84382. + dwc_ep->iso_desc_addr +
  84383. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  84384. +
  84385. + for (i = 0; i < dwc_ep->desc_cnt - 1; i++) {
  84386. + sts.d32 = dma_desc->status.d32;
  84387. +
  84388. + /* Write status in iso packet descriptor */
  84389. + iso_packet->status =
  84390. + sts.b_iso_in.txsts +
  84391. + (sts.b_iso_in.bs ^ BS_DMA_DONE);
  84392. + if (iso_packet->status != 0) {
  84393. + iso_packet->status = -DWC_E_NO_DATA;
  84394. +
  84395. + }
  84396. + /* Bytes has been transfered */
  84397. + iso_packet->length =
  84398. + dwc_ep->data_per_frame - sts.b_iso_in.txbytes;
  84399. +
  84400. + dma_desc++;
  84401. + iso_packet++;
  84402. + }
  84403. +
  84404. + sts.d32 = dma_desc->status.d32;
  84405. + while (sts.b_iso_in.bs == BS_DMA_BUSY) {
  84406. + sts.d32 = dma_desc->status.d32;
  84407. + }
  84408. +
  84409. + /* Write status in iso packet descriptor ??? do be done with ERROR codes */
  84410. + iso_packet->status =
  84411. + sts.b_iso_in.txsts + (sts.b_iso_in.bs ^ BS_DMA_DONE);
  84412. + if (iso_packet->status != 0) {
  84413. + iso_packet->status = -DWC_E_NO_DATA;
  84414. + }
  84415. +
  84416. + /* Bytes has been transfered */
  84417. + iso_packet->length =
  84418. + dwc_ep->data_per_frame - sts.b_iso_in.txbytes;
  84419. + }
  84420. +}
  84421. +
  84422. +/**
  84423. + * This function reinitialize DMA Descriptors for Isochronous transfer
  84424. + *
  84425. + * @param core_if Programming view of DWC_otg controller.
  84426. + * @param dwc_ep The EP to start the transfer on.
  84427. + *
  84428. + */
  84429. +static void reinit_ddma_iso_xfer(dwc_otg_core_if_t * core_if, dwc_ep_t * dwc_ep)
  84430. +{
  84431. + int i, j;
  84432. + dwc_otg_dev_dma_desc_t *dma_desc;
  84433. + dma_addr_t dma_ad;
  84434. + volatile uint32_t *addr;
  84435. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  84436. + uint32_t data_per_desc;
  84437. +
  84438. + if (dwc_ep->is_in == 0) {
  84439. + addr = &core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl;
  84440. + } else {
  84441. + addr = &core_if->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  84442. + }
  84443. +
  84444. + if (dwc_ep->proc_buf_num == 0) {
  84445. + /** Buffer 0 descriptors setup */
  84446. + dma_ad = dwc_ep->dma_addr0;
  84447. + } else {
  84448. + /** Buffer 1 descriptors setup */
  84449. + dma_ad = dwc_ep->dma_addr1;
  84450. + }
  84451. +
  84452. + /** Reinit closed DMA Descriptors*/
  84453. + /** ISO OUT EP */
  84454. + if (dwc_ep->is_in == 0) {
  84455. + dma_desc =
  84456. + dwc_ep->iso_desc_addr +
  84457. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  84458. +
  84459. + sts.b_iso_out.bs = BS_HOST_READY;
  84460. + sts.b_iso_out.rxsts = 0;
  84461. + sts.b_iso_out.l = 0;
  84462. + sts.b_iso_out.sp = 0;
  84463. + sts.b_iso_out.ioc = 0;
  84464. + sts.b_iso_out.pid = 0;
  84465. + sts.b_iso_out.framenum = 0;
  84466. +
  84467. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  84468. + i += dwc_ep->pkt_per_frm) {
  84469. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  84470. + data_per_desc =
  84471. + ((j + 1) * dwc_ep->maxpacket >
  84472. + dwc_ep->
  84473. + data_per_frame) ? dwc_ep->data_per_frame -
  84474. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  84475. + data_per_desc +=
  84476. + (data_per_desc % 4) ? (4 -
  84477. + data_per_desc %
  84478. + 4) : 0;
  84479. + sts.b_iso_out.rxbytes = data_per_desc;
  84480. + dma_desc->buf = dma_ad;
  84481. + dma_desc->status.d32 = sts.d32;
  84482. +
  84483. + dma_ad += data_per_desc;
  84484. + dma_desc++;
  84485. + }
  84486. + }
  84487. +
  84488. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  84489. +
  84490. + data_per_desc =
  84491. + ((j + 1) * dwc_ep->maxpacket >
  84492. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  84493. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  84494. + data_per_desc +=
  84495. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  84496. + sts.b_iso_out.rxbytes = data_per_desc;
  84497. +
  84498. + dma_desc->buf = dma_ad;
  84499. + dma_desc->status.d32 = sts.d32;
  84500. +
  84501. + dma_desc++;
  84502. + dma_ad += data_per_desc;
  84503. + }
  84504. +
  84505. + sts.b_iso_out.ioc = 1;
  84506. + sts.b_iso_out.l = dwc_ep->proc_buf_num;
  84507. +
  84508. + data_per_desc =
  84509. + ((j + 1) * dwc_ep->maxpacket >
  84510. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  84511. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  84512. + data_per_desc +=
  84513. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  84514. + sts.b_iso_out.rxbytes = data_per_desc;
  84515. +
  84516. + dma_desc->buf = dma_ad;
  84517. + dma_desc->status.d32 = sts.d32;
  84518. + } else {
  84519. +/** ISO IN EP */
  84520. +
  84521. + dma_desc =
  84522. + dwc_ep->iso_desc_addr +
  84523. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  84524. +
  84525. + sts.b_iso_in.bs = BS_HOST_READY;
  84526. + sts.b_iso_in.txsts = 0;
  84527. + sts.b_iso_in.sp = 0;
  84528. + sts.b_iso_in.ioc = 0;
  84529. + sts.b_iso_in.pid = dwc_ep->pkt_per_frm;
  84530. + sts.b_iso_in.framenum = dwc_ep->next_frame;
  84531. + sts.b_iso_in.txbytes = dwc_ep->data_per_frame;
  84532. + sts.b_iso_in.l = 0;
  84533. +
  84534. + for (i = 0; i < dwc_ep->desc_cnt - 1; i++) {
  84535. + dma_desc->buf = dma_ad;
  84536. + dma_desc->status.d32 = sts.d32;
  84537. +
  84538. + sts.b_iso_in.framenum += dwc_ep->bInterval;
  84539. + dma_ad += dwc_ep->data_per_frame;
  84540. + dma_desc++;
  84541. + }
  84542. +
  84543. + sts.b_iso_in.ioc = 1;
  84544. + sts.b_iso_in.l = dwc_ep->proc_buf_num;
  84545. +
  84546. + dma_desc->buf = dma_ad;
  84547. + dma_desc->status.d32 = sts.d32;
  84548. +
  84549. + dwc_ep->next_frame =
  84550. + sts.b_iso_in.framenum + dwc_ep->bInterval * 1;
  84551. + }
  84552. + dwc_ep->proc_buf_num = (dwc_ep->proc_buf_num ^ 1) & 0x1;
  84553. +}
  84554. +
  84555. +/**
  84556. + * This function is to handle Iso EP transfer complete interrupt
  84557. + * in case Iso out packet was dropped
  84558. + *
  84559. + * @param core_if Programming view of DWC_otg controller.
  84560. + * @param dwc_ep The EP for wihich transfer complete was asserted
  84561. + *
  84562. + */
  84563. +static uint32_t handle_iso_out_pkt_dropped(dwc_otg_core_if_t * core_if,
  84564. + dwc_ep_t * dwc_ep)
  84565. +{
  84566. + uint32_t dma_addr;
  84567. + uint32_t drp_pkt;
  84568. + uint32_t drp_pkt_cnt;
  84569. + deptsiz_data_t deptsiz = {.d32 = 0 };
  84570. + depctl_data_t depctl = {.d32 = 0 };
  84571. + int i;
  84572. +
  84573. + deptsiz.d32 =
  84574. + DWC_READ_REG32(&core_if->dev_if->
  84575. + out_ep_regs[dwc_ep->num]->doeptsiz);
  84576. +
  84577. + drp_pkt = dwc_ep->pkt_cnt - deptsiz.b.pktcnt;
  84578. + drp_pkt_cnt = dwc_ep->pkt_per_frm - (drp_pkt % dwc_ep->pkt_per_frm);
  84579. +
  84580. + /* Setting dropped packets status */
  84581. + for (i = 0; i < drp_pkt_cnt; ++i) {
  84582. + dwc_ep->pkt_info[drp_pkt].status = -DWC_E_NO_DATA;
  84583. + drp_pkt++;
  84584. + deptsiz.b.pktcnt--;
  84585. + }
  84586. +
  84587. + if (deptsiz.b.pktcnt > 0) {
  84588. + deptsiz.b.xfersize =
  84589. + dwc_ep->xfer_len - (dwc_ep->pkt_cnt -
  84590. + deptsiz.b.pktcnt) * dwc_ep->maxpacket;
  84591. + } else {
  84592. + deptsiz.b.xfersize = 0;
  84593. + deptsiz.b.pktcnt = 0;
  84594. + }
  84595. +
  84596. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doeptsiz,
  84597. + deptsiz.d32);
  84598. +
  84599. + if (deptsiz.b.pktcnt > 0) {
  84600. + if (dwc_ep->proc_buf_num) {
  84601. + dma_addr =
  84602. + dwc_ep->dma_addr1 + dwc_ep->xfer_len -
  84603. + deptsiz.b.xfersize;
  84604. + } else {
  84605. + dma_addr =
  84606. + dwc_ep->dma_addr0 + dwc_ep->xfer_len -
  84607. + deptsiz.b.xfersize;;
  84608. + }
  84609. +
  84610. + DWC_WRITE_REG32(&core_if->dev_if->
  84611. + out_ep_regs[dwc_ep->num]->doepdma, dma_addr);
  84612. +
  84613. + /** Re-enable endpoint, clear nak */
  84614. + depctl.d32 = 0;
  84615. + depctl.b.epena = 1;
  84616. + depctl.b.cnak = 1;
  84617. +
  84618. + DWC_MODIFY_REG32(&core_if->dev_if->
  84619. + out_ep_regs[dwc_ep->num]->doepctl, depctl.d32,
  84620. + depctl.d32);
  84621. + return 0;
  84622. + } else {
  84623. + return 1;
  84624. + }
  84625. +}
  84626. +
  84627. +/**
  84628. + * This function sets iso packets information(PTI mode)
  84629. + *
  84630. + * @param core_if Programming view of DWC_otg controller.
  84631. + * @param ep The EP to start the transfer on.
  84632. + *
  84633. + */
  84634. +static uint32_t set_iso_pkts_info(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  84635. +{
  84636. + int i, j;
  84637. + dma_addr_t dma_ad;
  84638. + iso_pkt_info_t *packet_info = ep->pkt_info;
  84639. + uint32_t offset;
  84640. + uint32_t frame_data;
  84641. + deptsiz_data_t deptsiz;
  84642. +
  84643. + if (ep->proc_buf_num == 0) {
  84644. + /** Buffer 0 descriptors setup */
  84645. + dma_ad = ep->dma_addr0;
  84646. + } else {
  84647. + /** Buffer 1 descriptors setup */
  84648. + dma_ad = ep->dma_addr1;
  84649. + }
  84650. +
  84651. + if (ep->is_in) {
  84652. + deptsiz.d32 =
  84653. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  84654. + dieptsiz);
  84655. + } else {
  84656. + deptsiz.d32 =
  84657. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[ep->num]->
  84658. + doeptsiz);
  84659. + }
  84660. +
  84661. + if (!deptsiz.b.xfersize) {
  84662. + offset = 0;
  84663. + for (i = 0; i < ep->pkt_cnt; i += ep->pkt_per_frm) {
  84664. + frame_data = ep->data_per_frame;
  84665. + for (j = 0; j < ep->pkt_per_frm; ++j) {
  84666. +
  84667. + /* Packet status - is not set as initially
  84668. + * it is set to 0 and if packet was sent
  84669. + successfully, status field will remain 0*/
  84670. +
  84671. + /* Bytes has been transfered */
  84672. + packet_info->length =
  84673. + (ep->maxpacket <
  84674. + frame_data) ? ep->maxpacket : frame_data;
  84675. +
  84676. + /* Received packet offset */
  84677. + packet_info->offset = offset;
  84678. + offset += packet_info->length;
  84679. + frame_data -= packet_info->length;
  84680. +
  84681. + packet_info++;
  84682. + }
  84683. + }
  84684. + return 1;
  84685. + } else {
  84686. + /* This is a workaround for in case of Transfer Complete with
  84687. + * PktDrpSts interrupts merging - in this case Transfer complete
  84688. + * interrupt for Isoc Out Endpoint is asserted without PktDrpSts
  84689. + * set and with DOEPTSIZ register non zero. Investigations showed,
  84690. + * that this happens when Out packet is dropped, but because of
  84691. + * interrupts merging during first interrupt handling PktDrpSts
  84692. + * bit is cleared and for next merged interrupts it is not reset.
  84693. + * In this case SW hadles the interrupt as if PktDrpSts bit is set.
  84694. + */
  84695. + if (ep->is_in) {
  84696. + return 1;
  84697. + } else {
  84698. + return handle_iso_out_pkt_dropped(core_if, ep);
  84699. + }
  84700. + }
  84701. +}
  84702. +
  84703. +/**
  84704. + * This function is to handle Iso EP transfer complete interrupt
  84705. + *
  84706. + * @param pcd The PCD
  84707. + * @param ep The EP for which transfer complete was asserted
  84708. + *
  84709. + */
  84710. +static void complete_iso_ep(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep)
  84711. +{
  84712. + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
  84713. + dwc_ep_t *dwc_ep = &ep->dwc_ep;
  84714. + uint8_t is_last = 0;
  84715. +
  84716. + if (ep->dwc_ep.next_frame == 0xffffffff) {
  84717. + DWC_WARN("Next frame is not set!\n");
  84718. + return;
  84719. + }
  84720. +
  84721. + if (core_if->dma_enable) {
  84722. + if (core_if->dma_desc_enable) {
  84723. + set_ddma_iso_pkts_info(core_if, dwc_ep);
  84724. + reinit_ddma_iso_xfer(core_if, dwc_ep);
  84725. + is_last = 1;
  84726. + } else {
  84727. + if (core_if->pti_enh_enable) {
  84728. + if (set_iso_pkts_info(core_if, dwc_ep)) {
  84729. + dwc_ep->proc_buf_num =
  84730. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  84731. + dwc_otg_iso_ep_start_buf_transfer
  84732. + (core_if, dwc_ep);
  84733. + is_last = 1;
  84734. + }
  84735. + } else {
  84736. + set_current_pkt_info(core_if, dwc_ep);
  84737. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  84738. + is_last = 1;
  84739. + dwc_ep->cur_pkt = 0;
  84740. + dwc_ep->proc_buf_num =
  84741. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  84742. + if (dwc_ep->proc_buf_num) {
  84743. + dwc_ep->cur_pkt_addr =
  84744. + dwc_ep->xfer_buff1;
  84745. + dwc_ep->cur_pkt_dma_addr =
  84746. + dwc_ep->dma_addr1;
  84747. + } else {
  84748. + dwc_ep->cur_pkt_addr =
  84749. + dwc_ep->xfer_buff0;
  84750. + dwc_ep->cur_pkt_dma_addr =
  84751. + dwc_ep->dma_addr0;
  84752. + }
  84753. +
  84754. + }
  84755. + dwc_otg_iso_ep_start_frm_transfer(core_if,
  84756. + dwc_ep);
  84757. + }
  84758. + }
  84759. + } else {
  84760. + set_current_pkt_info(core_if, dwc_ep);
  84761. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  84762. + is_last = 1;
  84763. + dwc_ep->cur_pkt = 0;
  84764. + dwc_ep->proc_buf_num = (dwc_ep->proc_buf_num ^ 1) & 0x1;
  84765. + if (dwc_ep->proc_buf_num) {
  84766. + dwc_ep->cur_pkt_addr = dwc_ep->xfer_buff1;
  84767. + dwc_ep->cur_pkt_dma_addr = dwc_ep->dma_addr1;
  84768. + } else {
  84769. + dwc_ep->cur_pkt_addr = dwc_ep->xfer_buff0;
  84770. + dwc_ep->cur_pkt_dma_addr = dwc_ep->dma_addr0;
  84771. + }
  84772. +
  84773. + }
  84774. + dwc_otg_iso_ep_start_frm_transfer(core_if, dwc_ep);
  84775. + }
  84776. + if (is_last)
  84777. + dwc_otg_iso_buffer_done(pcd, ep, ep->iso_req_handle);
  84778. +}
  84779. +#endif /* DWC_EN_ISOC */
  84780. +
  84781. +/**
  84782. + * This function handle BNA interrupt for Non Isochronous EPs
  84783. + *
  84784. + */
  84785. +static void dwc_otg_pcd_handle_noniso_bna(dwc_otg_pcd_ep_t * ep)
  84786. +{
  84787. + dwc_ep_t *dwc_ep = &ep->dwc_ep;
  84788. + volatile uint32_t *addr;
  84789. + depctl_data_t depctl = {.d32 = 0 };
  84790. + dwc_otg_pcd_t *pcd = ep->pcd;
  84791. + dwc_otg_dev_dma_desc_t *dma_desc;
  84792. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  84793. + dwc_otg_core_if_t *core_if = ep->pcd->core_if;
  84794. + int i, start;
  84795. +
  84796. + if (!dwc_ep->desc_cnt)
  84797. + DWC_WARN("Ep%d %s Descriptor count = %d \n", dwc_ep->num,
  84798. + (dwc_ep->is_in ? "IN" : "OUT"), dwc_ep->desc_cnt);
  84799. +
  84800. + if (core_if->core_params->cont_on_bna && !dwc_ep->is_in
  84801. + && dwc_ep->type != DWC_OTG_EP_TYPE_CONTROL) {
  84802. + uint32_t doepdma;
  84803. + dwc_otg_dev_out_ep_regs_t *out_regs =
  84804. + core_if->dev_if->out_ep_regs[dwc_ep->num];
  84805. + doepdma = DWC_READ_REG32(&(out_regs->doepdma));
  84806. + start = (doepdma - dwc_ep->dma_desc_addr)/sizeof(dwc_otg_dev_dma_desc_t);
  84807. + dma_desc = &(dwc_ep->desc_addr[start]);
  84808. + } else {
  84809. + start = 0;
  84810. + dma_desc = dwc_ep->desc_addr;
  84811. + }
  84812. +
  84813. +
  84814. + for (i = start; i < dwc_ep->desc_cnt; ++i, ++dma_desc) {
  84815. + sts.d32 = dma_desc->status.d32;
  84816. + sts.b.bs = BS_HOST_READY;
  84817. + dma_desc->status.d32 = sts.d32;
  84818. + }
  84819. +
  84820. + if (dwc_ep->is_in == 0) {
  84821. + addr =
  84822. + &GET_CORE_IF(pcd)->dev_if->out_ep_regs[dwc_ep->num]->
  84823. + doepctl;
  84824. + } else {
  84825. + addr =
  84826. + &GET_CORE_IF(pcd)->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  84827. + }
  84828. + depctl.b.epena = 1;
  84829. + depctl.b.cnak = 1;
  84830. + DWC_MODIFY_REG32(addr, 0, depctl.d32);
  84831. +}
  84832. +
  84833. +/**
  84834. + * This function handles EP0 Control transfers.
  84835. + *
  84836. + * The state of the control transfers are tracked in
  84837. + * <code>ep0state</code>.
  84838. + */
  84839. +static void handle_ep0(dwc_otg_pcd_t * pcd)
  84840. +{
  84841. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  84842. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  84843. + dev_dma_desc_sts_t desc_sts;
  84844. + deptsiz0_data_t deptsiz;
  84845. + uint32_t byte_count;
  84846. +
  84847. +#ifdef DEBUG_EP0
  84848. + DWC_DEBUGPL(DBG_PCDV, "%s()\n", __func__);
  84849. + print_ep0_state(pcd);
  84850. +#endif
  84851. +
  84852. +// DWC_PRINTF("HANDLE EP0\n");
  84853. +
  84854. + switch (pcd->ep0state) {
  84855. + case EP0_DISCONNECT:
  84856. + break;
  84857. +
  84858. + case EP0_IDLE:
  84859. + pcd->request_config = 0;
  84860. +
  84861. + pcd_setup(pcd);
  84862. + break;
  84863. +
  84864. + case EP0_IN_DATA_PHASE:
  84865. +#ifdef DEBUG_EP0
  84866. + DWC_DEBUGPL(DBG_PCD, "DATA_IN EP%d-%s: type=%d, mps=%d\n",
  84867. + ep0->dwc_ep.num, (ep0->dwc_ep.is_in ? "IN" : "OUT"),
  84868. + ep0->dwc_ep.type, ep0->dwc_ep.maxpacket);
  84869. +#endif
  84870. +
  84871. + if (core_if->dma_enable != 0) {
  84872. + /*
  84873. + * For EP0 we can only program 1 packet at a time so we
  84874. + * need to do the make calculations after each complete.
  84875. + * Call write_packet to make the calculations, as in
  84876. + * slave mode, and use those values to determine if we
  84877. + * can complete.
  84878. + */
  84879. + if (core_if->dma_desc_enable == 0) {
  84880. + deptsiz.d32 =
  84881. + DWC_READ_REG32(&core_if->
  84882. + dev_if->in_ep_regs[0]->
  84883. + dieptsiz);
  84884. + byte_count =
  84885. + ep0->dwc_ep.xfer_len - deptsiz.b.xfersize;
  84886. + } else {
  84887. + desc_sts =
  84888. + core_if->dev_if->in_desc_addr->status;
  84889. + byte_count =
  84890. + ep0->dwc_ep.xfer_len - desc_sts.b.bytes;
  84891. + }
  84892. + ep0->dwc_ep.xfer_count += byte_count;
  84893. + ep0->dwc_ep.xfer_buff += byte_count;
  84894. + ep0->dwc_ep.dma_addr += byte_count;
  84895. + }
  84896. + if (ep0->dwc_ep.xfer_count < ep0->dwc_ep.total_len) {
  84897. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  84898. + &ep0->dwc_ep);
  84899. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER\n");
  84900. + } else if (ep0->dwc_ep.sent_zlp) {
  84901. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  84902. + &ep0->dwc_ep);
  84903. + ep0->dwc_ep.sent_zlp = 0;
  84904. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER sent zlp\n");
  84905. + } else {
  84906. + ep0_complete_request(ep0);
  84907. + DWC_DEBUGPL(DBG_PCD, "COMPLETE TRANSFER\n");
  84908. + }
  84909. + break;
  84910. + case EP0_OUT_DATA_PHASE:
  84911. +#ifdef DEBUG_EP0
  84912. + DWC_DEBUGPL(DBG_PCD, "DATA_OUT EP%d-%s: type=%d, mps=%d\n",
  84913. + ep0->dwc_ep.num, (ep0->dwc_ep.is_in ? "IN" : "OUT"),
  84914. + ep0->dwc_ep.type, ep0->dwc_ep.maxpacket);
  84915. +#endif
  84916. + if (core_if->dma_enable != 0) {
  84917. + if (core_if->dma_desc_enable == 0) {
  84918. + deptsiz.d32 =
  84919. + DWC_READ_REG32(&core_if->
  84920. + dev_if->out_ep_regs[0]->
  84921. + doeptsiz);
  84922. + byte_count =
  84923. + ep0->dwc_ep.maxpacket - deptsiz.b.xfersize;
  84924. + } else {
  84925. + desc_sts =
  84926. + core_if->dev_if->out_desc_addr->status;
  84927. + byte_count =
  84928. + ep0->dwc_ep.maxpacket - desc_sts.b.bytes;
  84929. + }
  84930. + ep0->dwc_ep.xfer_count += byte_count;
  84931. + ep0->dwc_ep.xfer_buff += byte_count;
  84932. + ep0->dwc_ep.dma_addr += byte_count;
  84933. + }
  84934. + if (ep0->dwc_ep.xfer_count < ep0->dwc_ep.total_len) {
  84935. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  84936. + &ep0->dwc_ep);
  84937. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER\n");
  84938. + } else if (ep0->dwc_ep.sent_zlp) {
  84939. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  84940. + &ep0->dwc_ep);
  84941. + ep0->dwc_ep.sent_zlp = 0;
  84942. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER sent zlp\n");
  84943. + } else {
  84944. + ep0_complete_request(ep0);
  84945. + DWC_DEBUGPL(DBG_PCD, "COMPLETE TRANSFER\n");
  84946. + }
  84947. + break;
  84948. +
  84949. + case EP0_IN_STATUS_PHASE:
  84950. + case EP0_OUT_STATUS_PHASE:
  84951. + DWC_DEBUGPL(DBG_PCD, "CASE: EP0_STATUS\n");
  84952. + ep0_complete_request(ep0);
  84953. + pcd->ep0state = EP0_IDLE;
  84954. + ep0->stopped = 1;
  84955. + ep0->dwc_ep.is_in = 0; /* OUT for next SETUP */
  84956. +
  84957. + /* Prepare for more SETUP Packets */
  84958. + if (core_if->dma_enable) {
  84959. + ep0_out_start(core_if, pcd);
  84960. + }
  84961. + break;
  84962. +
  84963. + case EP0_STALL:
  84964. + DWC_ERROR("EP0 STALLed, should not get here pcd_setup()\n");
  84965. + break;
  84966. + }
  84967. +#ifdef DEBUG_EP0
  84968. + print_ep0_state(pcd);
  84969. +#endif
  84970. +}
  84971. +
  84972. +/**
  84973. + * Restart transfer
  84974. + */
  84975. +static void restart_transfer(dwc_otg_pcd_t * pcd, const uint32_t epnum)
  84976. +{
  84977. + dwc_otg_core_if_t *core_if;
  84978. + dwc_otg_dev_if_t *dev_if;
  84979. + deptsiz_data_t dieptsiz = {.d32 = 0 };
  84980. + dwc_otg_pcd_ep_t *ep;
  84981. +
  84982. + ep = get_in_ep(pcd, epnum);
  84983. +
  84984. +#ifdef DWC_EN_ISOC
  84985. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  84986. + return;
  84987. + }
  84988. +#endif /* DWC_EN_ISOC */
  84989. +
  84990. + core_if = GET_CORE_IF(pcd);
  84991. + dev_if = core_if->dev_if;
  84992. +
  84993. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dieptsiz);
  84994. +
  84995. + DWC_DEBUGPL(DBG_PCD, "xfer_buff=%p xfer_count=%0x xfer_len=%0x"
  84996. + " stopped=%d\n", ep->dwc_ep.xfer_buff,
  84997. + ep->dwc_ep.xfer_count, ep->dwc_ep.xfer_len, ep->stopped);
  84998. + /*
  84999. + * If xfersize is 0 and pktcnt in not 0, resend the last packet.
  85000. + */
  85001. + if (dieptsiz.b.pktcnt && dieptsiz.b.xfersize == 0 &&
  85002. + ep->dwc_ep.start_xfer_buff != 0) {
  85003. + if (ep->dwc_ep.total_len <= ep->dwc_ep.maxpacket) {
  85004. + ep->dwc_ep.xfer_count = 0;
  85005. + ep->dwc_ep.xfer_buff = ep->dwc_ep.start_xfer_buff;
  85006. + ep->dwc_ep.xfer_len = ep->dwc_ep.xfer_count;
  85007. + } else {
  85008. + ep->dwc_ep.xfer_count -= ep->dwc_ep.maxpacket;
  85009. + /* convert packet size to dwords. */
  85010. + ep->dwc_ep.xfer_buff -= ep->dwc_ep.maxpacket;
  85011. + ep->dwc_ep.xfer_len = ep->dwc_ep.xfer_count;
  85012. + }
  85013. + ep->stopped = 0;
  85014. + DWC_DEBUGPL(DBG_PCD, "xfer_buff=%p xfer_count=%0x "
  85015. + "xfer_len=%0x stopped=%d\n",
  85016. + ep->dwc_ep.xfer_buff,
  85017. + ep->dwc_ep.xfer_count, ep->dwc_ep.xfer_len,
  85018. + ep->stopped);
  85019. + if (epnum == 0) {
  85020. + dwc_otg_ep0_start_transfer(core_if, &ep->dwc_ep);
  85021. + } else {
  85022. + dwc_otg_ep_start_transfer(core_if, &ep->dwc_ep);
  85023. + }
  85024. + }
  85025. +}
  85026. +
  85027. +/*
  85028. + * This function create new nextep sequnce based on Learn Queue.
  85029. + *
  85030. + * @param core_if Programming view of DWC_otg controller
  85031. + */
  85032. +void predict_nextep_seq( dwc_otg_core_if_t * core_if)
  85033. +{
  85034. + dwc_otg_device_global_regs_t *dev_global_regs =
  85035. + core_if->dev_if->dev_global_regs;
  85036. + const uint32_t TOKEN_Q_DEPTH = core_if->hwcfg2.b.dev_token_q_depth;
  85037. + /* Number of Token Queue Registers */
  85038. + const int DTKNQ_REG_CNT = (TOKEN_Q_DEPTH + 7) / 8;
  85039. + dtknq1_data_t dtknqr1;
  85040. + uint32_t in_tkn_epnums[4];
  85041. + uint8_t seqnum[MAX_EPS_CHANNELS];
  85042. + uint8_t intkn_seq[TOKEN_Q_DEPTH];
  85043. + grstctl_t resetctl = {.d32 = 0 };
  85044. + uint8_t temp;
  85045. + int ndx = 0;
  85046. + int start = 0;
  85047. + int end = 0;
  85048. + int sort_done = 0;
  85049. + int i = 0;
  85050. + volatile uint32_t *addr = &dev_global_regs->dtknqr1;
  85051. +
  85052. +
  85053. + DWC_DEBUGPL(DBG_PCD,"dev_token_q_depth=%d\n",TOKEN_Q_DEPTH);
  85054. +
  85055. + /* Read the DTKNQ Registers */
  85056. + for (i = 0; i < DTKNQ_REG_CNT; i++) {
  85057. + in_tkn_epnums[i] = DWC_READ_REG32(addr);
  85058. + DWC_DEBUGPL(DBG_PCDV, "DTKNQR%d=0x%08x\n", i + 1,
  85059. + in_tkn_epnums[i]);
  85060. + if (addr == &dev_global_regs->dvbusdis) {
  85061. + addr = &dev_global_regs->dtknqr3_dthrctl;
  85062. + } else {
  85063. + ++addr;
  85064. + }
  85065. +
  85066. + }
  85067. +
  85068. + /* Copy the DTKNQR1 data to the bit field. */
  85069. + dtknqr1.d32 = in_tkn_epnums[0];
  85070. + if (dtknqr1.b.wrap_bit) {
  85071. + ndx = dtknqr1.b.intknwptr;
  85072. + end = ndx -1;
  85073. + if (end < 0)
  85074. + end = TOKEN_Q_DEPTH -1;
  85075. + } else {
  85076. + ndx = 0;
  85077. + end = dtknqr1.b.intknwptr -1;
  85078. + if (end < 0)
  85079. + end = 0;
  85080. + }
  85081. + start = ndx;
  85082. +
  85083. + /* Fill seqnum[] by initial values: EP number + 31 */
  85084. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  85085. + seqnum[i] = i +31;
  85086. + }
  85087. +
  85088. + /* Fill intkn_seq[] from in_tkn_epnums[0] */
  85089. + for (i=0; i < 6; i++)
  85090. + intkn_seq[i] = (in_tkn_epnums[0] >> ((7-i) * 4)) & 0xf;
  85091. +
  85092. + if (TOKEN_Q_DEPTH > 6) {
  85093. + /* Fill intkn_seq[] from in_tkn_epnums[1] */
  85094. + for (i=6; i < 14; i++)
  85095. + intkn_seq[i] =
  85096. + (in_tkn_epnums[1] >> ((7 - (i - 6)) * 4)) & 0xf;
  85097. + }
  85098. +
  85099. + if (TOKEN_Q_DEPTH > 14) {
  85100. + /* Fill intkn_seq[] from in_tkn_epnums[1] */
  85101. + for (i=14; i < 22; i++)
  85102. + intkn_seq[i] =
  85103. + (in_tkn_epnums[2] >> ((7 - (i - 14)) * 4)) & 0xf;
  85104. + }
  85105. +
  85106. + if (TOKEN_Q_DEPTH > 22) {
  85107. + /* Fill intkn_seq[] from in_tkn_epnums[1] */
  85108. + for (i=22; i < 30; i++)
  85109. + intkn_seq[i] =
  85110. + (in_tkn_epnums[3] >> ((7 - (i - 22)) * 4)) & 0xf;
  85111. + }
  85112. +
  85113. + DWC_DEBUGPL(DBG_PCDV, "%s start=%d end=%d intkn_seq[]:\n", __func__,
  85114. + start, end);
  85115. + for (i=0; i<TOKEN_Q_DEPTH; i++)
  85116. + DWC_DEBUGPL(DBG_PCDV,"%d\n", intkn_seq[i]);
  85117. +
  85118. + /* Update seqnum based on intkn_seq[] */
  85119. + i = 0;
  85120. + do {
  85121. + seqnum[intkn_seq[ndx]] = i;
  85122. + ndx++;
  85123. + i++;
  85124. + if (ndx == TOKEN_Q_DEPTH)
  85125. + ndx = 0;
  85126. + } while ( i < TOKEN_Q_DEPTH );
  85127. +
  85128. + /* Mark non active EP's in seqnum[] by 0xff */
  85129. + for (i=0; i<=core_if->dev_if->num_in_eps; i++) {
  85130. + if (core_if->nextep_seq[i] == 0xff )
  85131. + seqnum[i] = 0xff;
  85132. + }
  85133. +
  85134. + /* Sort seqnum[] */
  85135. + sort_done = 0;
  85136. + while (!sort_done) {
  85137. + sort_done = 1;
  85138. + for (i=0; i<core_if->dev_if->num_in_eps; i++) {
  85139. + if (seqnum[i] > seqnum[i+1]) {
  85140. + temp = seqnum[i];
  85141. + seqnum[i] = seqnum[i+1];
  85142. + seqnum[i+1] = temp;
  85143. + sort_done = 0;
  85144. + }
  85145. + }
  85146. + }
  85147. +
  85148. + ndx = start + seqnum[0];
  85149. + if (ndx >= TOKEN_Q_DEPTH)
  85150. + ndx = ndx % TOKEN_Q_DEPTH;
  85151. + core_if->first_in_nextep_seq = intkn_seq[ndx];
  85152. +
  85153. + /* Update seqnum[] by EP numbers */
  85154. + for (i=0; i<=core_if->dev_if->num_in_eps; i++) {
  85155. + ndx = start + i;
  85156. + if (seqnum[i] < 31) {
  85157. + ndx = start + seqnum[i];
  85158. + if (ndx >= TOKEN_Q_DEPTH)
  85159. + ndx = ndx % TOKEN_Q_DEPTH;
  85160. + seqnum[i] = intkn_seq[ndx];
  85161. + } else {
  85162. + if (seqnum[i] < 0xff) {
  85163. + seqnum[i] = seqnum[i] - 31;
  85164. + } else {
  85165. + break;
  85166. + }
  85167. + }
  85168. + }
  85169. +
  85170. + /* Update nextep_seq[] based on seqnum[] */
  85171. + for (i=0; i<core_if->dev_if->num_in_eps; i++) {
  85172. + if (seqnum[i] != 0xff) {
  85173. + if (seqnum[i+1] != 0xff) {
  85174. + core_if->nextep_seq[seqnum[i]] = seqnum[i+1];
  85175. + } else {
  85176. + core_if->nextep_seq[seqnum[i]] = core_if->first_in_nextep_seq;
  85177. + break;
  85178. + }
  85179. + } else {
  85180. + break;
  85181. + }
  85182. + }
  85183. +
  85184. + DWC_DEBUGPL(DBG_PCDV, "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  85185. + __func__, core_if->first_in_nextep_seq);
  85186. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  85187. + DWC_DEBUGPL(DBG_PCDV,"%2d\n", core_if->nextep_seq[i]);
  85188. + }
  85189. +
  85190. + /* Flush the Learning Queue */
  85191. + resetctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->grstctl);
  85192. + resetctl.b.intknqflsh = 1;
  85193. + DWC_WRITE_REG32(&core_if->core_global_regs->grstctl, resetctl.d32);
  85194. +
  85195. +
  85196. +}
  85197. +
  85198. +/**
  85199. + * handle the IN EP disable interrupt.
  85200. + */
  85201. +static inline void handle_in_ep_disable_intr(dwc_otg_pcd_t * pcd,
  85202. + const uint32_t epnum)
  85203. +{
  85204. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  85205. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  85206. + deptsiz_data_t dieptsiz = {.d32 = 0 };
  85207. + dctl_data_t dctl = {.d32 = 0 };
  85208. + dwc_otg_pcd_ep_t *ep;
  85209. + dwc_ep_t *dwc_ep;
  85210. + gintmsk_data_t gintmsk_data;
  85211. + depctl_data_t depctl;
  85212. + uint32_t diepdma;
  85213. + uint32_t remain_to_transfer = 0;
  85214. + uint8_t i;
  85215. + uint32_t xfer_size;
  85216. +
  85217. + ep = get_in_ep(pcd, epnum);
  85218. + dwc_ep = &ep->dwc_ep;
  85219. +
  85220. + if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  85221. + dwc_otg_flush_tx_fifo(core_if, dwc_ep->tx_fifo_num);
  85222. + complete_ep(ep);
  85223. + return;
  85224. + }
  85225. +
  85226. + DWC_DEBUGPL(DBG_PCD, "diepctl%d=%0x\n", epnum,
  85227. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl));
  85228. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dieptsiz);
  85229. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl);
  85230. +
  85231. + DWC_DEBUGPL(DBG_ANY, "pktcnt=%d size=%d\n",
  85232. + dieptsiz.b.pktcnt, dieptsiz.b.xfersize);
  85233. +
  85234. + if ((core_if->start_predict == 0) || (depctl.b.eptype & 1)) {
  85235. + if (ep->stopped) {
  85236. + if (core_if->en_multiple_tx_fifo)
  85237. + /* Flush the Tx FIFO */
  85238. + dwc_otg_flush_tx_fifo(core_if, dwc_ep->tx_fifo_num);
  85239. + /* Clear the Global IN NP NAK */
  85240. + dctl.d32 = 0;
  85241. + dctl.b.cgnpinnak = 1;
  85242. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  85243. + /* Restart the transaction */
  85244. + if (dieptsiz.b.pktcnt != 0 || dieptsiz.b.xfersize != 0) {
  85245. + restart_transfer(pcd, epnum);
  85246. + }
  85247. + } else {
  85248. + /* Restart the transaction */
  85249. + if (dieptsiz.b.pktcnt != 0 || dieptsiz.b.xfersize != 0) {
  85250. + restart_transfer(pcd, epnum);
  85251. + }
  85252. + DWC_DEBUGPL(DBG_ANY, "STOPPED!!!\n");
  85253. + }
  85254. + return;
  85255. + }
  85256. +
  85257. + if (core_if->start_predict > 2) { // NP IN EP
  85258. + core_if->start_predict--;
  85259. + return;
  85260. + }
  85261. +
  85262. + core_if->start_predict--;
  85263. +
  85264. + if (core_if->start_predict == 1) { // All NP IN Ep's disabled now
  85265. +
  85266. + predict_nextep_seq(core_if);
  85267. +
  85268. + /* Update all active IN EP's NextEP field based of nextep_seq[] */
  85269. + for ( i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  85270. + depctl.d32 =
  85271. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  85272. + if (core_if->nextep_seq[i] != 0xff) { // Active NP IN EP
  85273. + depctl.b.nextep = core_if->nextep_seq[i];
  85274. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32);
  85275. + }
  85276. + }
  85277. + /* Flush Shared NP TxFIFO */
  85278. + dwc_otg_flush_tx_fifo(core_if, 0);
  85279. + /* Rewind buffers */
  85280. + if (!core_if->dma_desc_enable) {
  85281. + i = core_if->first_in_nextep_seq;
  85282. + do {
  85283. + ep = get_in_ep(pcd, i);
  85284. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->dieptsiz);
  85285. + xfer_size = ep->dwc_ep.total_len - ep->dwc_ep.xfer_count;
  85286. + if (xfer_size > ep->dwc_ep.maxxfer)
  85287. + xfer_size = ep->dwc_ep.maxxfer;
  85288. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  85289. + if (dieptsiz.b.pktcnt != 0) {
  85290. + if (xfer_size == 0) {
  85291. + remain_to_transfer = 0;
  85292. + } else {
  85293. + if ((xfer_size % ep->dwc_ep.maxpacket) == 0) {
  85294. + remain_to_transfer =
  85295. + dieptsiz.b.pktcnt * ep->dwc_ep.maxpacket;
  85296. + } else {
  85297. + remain_to_transfer = ((dieptsiz.b.pktcnt -1) * ep->dwc_ep.maxpacket)
  85298. + + (xfer_size % ep->dwc_ep.maxpacket);
  85299. + }
  85300. + }
  85301. + diepdma = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepdma);
  85302. + dieptsiz.b.xfersize = remain_to_transfer;
  85303. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->dieptsiz, dieptsiz.d32);
  85304. + diepdma = ep->dwc_ep.dma_addr + (xfer_size - remain_to_transfer);
  85305. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepdma, diepdma);
  85306. + }
  85307. + i = core_if->nextep_seq[i];
  85308. + } while (i != core_if->first_in_nextep_seq);
  85309. + } else { // dma_desc_enable
  85310. + DWC_PRINTF("%s Learning Queue not supported in DDMA\n", __func__);
  85311. + }
  85312. +
  85313. + /* Restart transfers in predicted sequences */
  85314. + i = core_if->first_in_nextep_seq;
  85315. + do {
  85316. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->dieptsiz);
  85317. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  85318. + if (dieptsiz.b.pktcnt != 0) {
  85319. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  85320. + depctl.b.epena = 1;
  85321. + depctl.b.cnak = 1;
  85322. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32);
  85323. + }
  85324. + i = core_if->nextep_seq[i];
  85325. + } while (i != core_if->first_in_nextep_seq);
  85326. +
  85327. + /* Clear the global non-periodic IN NAK handshake */
  85328. + dctl.d32 = 0;
  85329. + dctl.b.cgnpinnak = 1;
  85330. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  85331. +
  85332. + /* Unmask EP Mismatch interrupt */
  85333. + gintmsk_data.d32 = 0;
  85334. + gintmsk_data.b.epmismatch = 1;
  85335. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, gintmsk_data.d32);
  85336. +
  85337. + core_if->start_predict = 0;
  85338. +
  85339. + }
  85340. +}
  85341. +
  85342. +/**
  85343. + * Handler for the IN EP timeout handshake interrupt.
  85344. + */
  85345. +static inline void handle_in_ep_timeout_intr(dwc_otg_pcd_t * pcd,
  85346. + const uint32_t epnum)
  85347. +{
  85348. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  85349. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  85350. +
  85351. +#ifdef DEBUG
  85352. + deptsiz_data_t dieptsiz = {.d32 = 0 };
  85353. + uint32_t num = 0;
  85354. +#endif
  85355. + dctl_data_t dctl = {.d32 = 0 };
  85356. + dwc_otg_pcd_ep_t *ep;
  85357. +
  85358. + gintmsk_data_t intr_mask = {.d32 = 0 };
  85359. +
  85360. + ep = get_in_ep(pcd, epnum);
  85361. +
  85362. + /* Disable the NP Tx Fifo Empty Interrrupt */
  85363. + if (!core_if->dma_enable) {
  85364. + intr_mask.b.nptxfempty = 1;
  85365. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  85366. + intr_mask.d32, 0);
  85367. + }
  85368. + /** @todo NGS Check EP type.
  85369. + * Implement for Periodic EPs */
  85370. + /*
  85371. + * Non-periodic EP
  85372. + */
  85373. + /* Enable the Global IN NAK Effective Interrupt */
  85374. + intr_mask.b.ginnakeff = 1;
  85375. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, intr_mask.d32);
  85376. +
  85377. + /* Set Global IN NAK */
  85378. + dctl.b.sgnpinnak = 1;
  85379. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  85380. +
  85381. + ep->stopped = 1;
  85382. +
  85383. +#ifdef DEBUG
  85384. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[num]->dieptsiz);
  85385. + DWC_DEBUGPL(DBG_ANY, "pktcnt=%d size=%d\n",
  85386. + dieptsiz.b.pktcnt, dieptsiz.b.xfersize);
  85387. +#endif
  85388. +
  85389. +#ifdef DISABLE_PERIODIC_EP
  85390. + /*
  85391. + * Set the NAK bit for this EP to
  85392. + * start the disable process.
  85393. + */
  85394. + diepctl.d32 = 0;
  85395. + diepctl.b.snak = 1;
  85396. + DWC_MODIFY_REG32(&dev_if->in_ep_regs[num]->diepctl, diepctl.d32,
  85397. + diepctl.d32);
  85398. + ep->disabling = 1;
  85399. + ep->stopped = 1;
  85400. +#endif
  85401. +}
  85402. +
  85403. +/**
  85404. + * Handler for the IN EP NAK interrupt.
  85405. + */
  85406. +static inline int32_t handle_in_ep_nak_intr(dwc_otg_pcd_t * pcd,
  85407. + const uint32_t epnum)
  85408. +{
  85409. + /** @todo implement ISR */
  85410. + dwc_otg_core_if_t *core_if;
  85411. + diepmsk_data_t intr_mask = {.d32 = 0 };
  85412. +
  85413. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "IN EP NAK");
  85414. + core_if = GET_CORE_IF(pcd);
  85415. + intr_mask.b.nak = 1;
  85416. +
  85417. + if (core_if->multiproc_int_enable) {
  85418. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  85419. + diepeachintmsk[epnum], intr_mask.d32, 0);
  85420. + } else {
  85421. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->diepmsk,
  85422. + intr_mask.d32, 0);
  85423. + }
  85424. +
  85425. + return 1;
  85426. +}
  85427. +
  85428. +/**
  85429. + * Handler for the OUT EP Babble interrupt.
  85430. + */
  85431. +static inline int32_t handle_out_ep_babble_intr(dwc_otg_pcd_t * pcd,
  85432. + const uint32_t epnum)
  85433. +{
  85434. + /** @todo implement ISR */
  85435. + dwc_otg_core_if_t *core_if;
  85436. + doepmsk_data_t intr_mask = {.d32 = 0 };
  85437. +
  85438. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n",
  85439. + "OUT EP Babble");
  85440. + core_if = GET_CORE_IF(pcd);
  85441. + intr_mask.b.babble = 1;
  85442. +
  85443. + if (core_if->multiproc_int_enable) {
  85444. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  85445. + doepeachintmsk[epnum], intr_mask.d32, 0);
  85446. + } else {
  85447. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  85448. + intr_mask.d32, 0);
  85449. + }
  85450. +
  85451. + return 1;
  85452. +}
  85453. +
  85454. +/**
  85455. + * Handler for the OUT EP NAK interrupt.
  85456. + */
  85457. +static inline int32_t handle_out_ep_nak_intr(dwc_otg_pcd_t * pcd,
  85458. + const uint32_t epnum)
  85459. +{
  85460. + /** @todo implement ISR */
  85461. + dwc_otg_core_if_t *core_if;
  85462. + doepmsk_data_t intr_mask = {.d32 = 0 };
  85463. +
  85464. + DWC_DEBUGPL(DBG_ANY, "INTERRUPT Handler not implemented for %s\n", "OUT EP NAK");
  85465. + core_if = GET_CORE_IF(pcd);
  85466. + intr_mask.b.nak = 1;
  85467. +
  85468. + if (core_if->multiproc_int_enable) {
  85469. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  85470. + doepeachintmsk[epnum], intr_mask.d32, 0);
  85471. + } else {
  85472. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  85473. + intr_mask.d32, 0);
  85474. + }
  85475. +
  85476. + return 1;
  85477. +}
  85478. +
  85479. +/**
  85480. + * Handler for the OUT EP NYET interrupt.
  85481. + */
  85482. +static inline int32_t handle_out_ep_nyet_intr(dwc_otg_pcd_t * pcd,
  85483. + const uint32_t epnum)
  85484. +{
  85485. + /** @todo implement ISR */
  85486. + dwc_otg_core_if_t *core_if;
  85487. + doepmsk_data_t intr_mask = {.d32 = 0 };
  85488. +
  85489. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "OUT EP NYET");
  85490. + core_if = GET_CORE_IF(pcd);
  85491. + intr_mask.b.nyet = 1;
  85492. +
  85493. + if (core_if->multiproc_int_enable) {
  85494. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  85495. + doepeachintmsk[epnum], intr_mask.d32, 0);
  85496. + } else {
  85497. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  85498. + intr_mask.d32, 0);
  85499. + }
  85500. +
  85501. + return 1;
  85502. +}
  85503. +
  85504. +/**
  85505. + * This interrupt indicates that an IN EP has a pending Interrupt.
  85506. + * The sequence for handling the IN EP interrupt is shown below:
  85507. + * -# Read the Device All Endpoint Interrupt register
  85508. + * -# Repeat the following for each IN EP interrupt bit set (from
  85509. + * LSB to MSB).
  85510. + * -# Read the Device Endpoint Interrupt (DIEPINTn) register
  85511. + * -# If "Transfer Complete" call the request complete function
  85512. + * -# If "Endpoint Disabled" complete the EP disable procedure.
  85513. + * -# If "AHB Error Interrupt" log error
  85514. + * -# If "Time-out Handshake" log error
  85515. + * -# If "IN Token Received when TxFIFO Empty" write packet to Tx
  85516. + * FIFO.
  85517. + * -# If "IN Token EP Mismatch" (disable, this is handled by EP
  85518. + * Mismatch Interrupt)
  85519. + */
  85520. +static int32_t dwc_otg_pcd_handle_in_ep_intr(dwc_otg_pcd_t * pcd)
  85521. +{
  85522. +#define CLEAR_IN_EP_INTR(__core_if,__epnum,__intr) \
  85523. +do { \
  85524. + diepint_data_t diepint = {.d32=0}; \
  85525. + diepint.b.__intr = 1; \
  85526. + DWC_WRITE_REG32(&__core_if->dev_if->in_ep_regs[__epnum]->diepint, \
  85527. + diepint.d32); \
  85528. +} while (0)
  85529. +
  85530. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  85531. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  85532. + diepint_data_t diepint = {.d32 = 0 };
  85533. + depctl_data_t depctl = {.d32 = 0 };
  85534. + uint32_t ep_intr;
  85535. + uint32_t epnum = 0;
  85536. + dwc_otg_pcd_ep_t *ep;
  85537. + dwc_ep_t *dwc_ep;
  85538. + gintmsk_data_t intr_mask = {.d32 = 0 };
  85539. +
  85540. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, pcd);
  85541. +
  85542. + /* Read in the device interrupt bits */
  85543. + ep_intr = dwc_otg_read_dev_all_in_ep_intr(core_if);
  85544. +
  85545. + /* Service the Device IN interrupts for each endpoint */
  85546. + while (ep_intr) {
  85547. + if (ep_intr & 0x1) {
  85548. + uint32_t empty_msk;
  85549. + /* Get EP pointer */
  85550. + ep = get_in_ep(pcd, epnum);
  85551. + dwc_ep = &ep->dwc_ep;
  85552. +
  85553. + depctl.d32 =
  85554. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl);
  85555. + empty_msk =
  85556. + DWC_READ_REG32(&dev_if->
  85557. + dev_global_regs->dtknqr4_fifoemptymsk);
  85558. +
  85559. + DWC_DEBUGPL(DBG_PCDV,
  85560. + "IN EP INTERRUPT - %d\nepmty_msk - %8x diepctl - %8x\n",
  85561. + epnum, empty_msk, depctl.d32);
  85562. +
  85563. + DWC_DEBUGPL(DBG_PCD,
  85564. + "EP%d-%s: type=%d, mps=%d\n",
  85565. + dwc_ep->num, (dwc_ep->is_in ? "IN" : "OUT"),
  85566. + dwc_ep->type, dwc_ep->maxpacket);
  85567. +
  85568. + diepint.d32 =
  85569. + dwc_otg_read_dev_in_ep_intr(core_if, dwc_ep);
  85570. +
  85571. + DWC_DEBUGPL(DBG_PCDV,
  85572. + "EP %d Interrupt Register - 0x%x\n", epnum,
  85573. + diepint.d32);
  85574. + /* Transfer complete */
  85575. + if (diepint.b.xfercompl) {
  85576. + /* Disable the NP Tx FIFO Empty
  85577. + * Interrupt */
  85578. + if (core_if->en_multiple_tx_fifo == 0) {
  85579. + intr_mask.b.nptxfempty = 1;
  85580. + DWC_MODIFY_REG32
  85581. + (&core_if->core_global_regs->gintmsk,
  85582. + intr_mask.d32, 0);
  85583. + } else {
  85584. + /* Disable the Tx FIFO Empty Interrupt for this EP */
  85585. + uint32_t fifoemptymsk =
  85586. + 0x1 << dwc_ep->num;
  85587. + DWC_MODIFY_REG32(&core_if->
  85588. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  85589. + fifoemptymsk, 0);
  85590. + }
  85591. + /* Clear the bit in DIEPINTn for this interrupt */
  85592. + CLEAR_IN_EP_INTR(core_if, epnum, xfercompl);
  85593. +
  85594. + /* Complete the transfer */
  85595. + if (epnum == 0) {
  85596. + handle_ep0(pcd);
  85597. + }
  85598. +#ifdef DWC_EN_ISOC
  85599. + else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  85600. + if (!ep->stopped)
  85601. + complete_iso_ep(pcd, ep);
  85602. + }
  85603. +#endif /* DWC_EN_ISOC */
  85604. +#ifdef DWC_UTE_PER_IO
  85605. + else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  85606. + if (!ep->stopped)
  85607. + complete_xiso_ep(ep);
  85608. + }
  85609. +#endif /* DWC_UTE_PER_IO */
  85610. + else {
  85611. + if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC &&
  85612. + dwc_ep->bInterval > 1) {
  85613. + dwc_ep->frame_num += dwc_ep->bInterval;
  85614. + if (dwc_ep->frame_num > 0x3FFF)
  85615. + {
  85616. + dwc_ep->frm_overrun = 1;
  85617. + dwc_ep->frame_num &= 0x3FFF;
  85618. + } else
  85619. + dwc_ep->frm_overrun = 0;
  85620. + }
  85621. + complete_ep(ep);
  85622. + if(diepint.b.nak)
  85623. + CLEAR_IN_EP_INTR(core_if, epnum, nak);
  85624. + }
  85625. + }
  85626. + /* Endpoint disable */
  85627. + if (diepint.b.epdisabled) {
  85628. + DWC_DEBUGPL(DBG_ANY, "EP%d IN disabled\n",
  85629. + epnum);
  85630. + handle_in_ep_disable_intr(pcd, epnum);
  85631. +
  85632. + /* Clear the bit in DIEPINTn for this interrupt */
  85633. + CLEAR_IN_EP_INTR(core_if, epnum, epdisabled);
  85634. + }
  85635. + /* AHB Error */
  85636. + if (diepint.b.ahberr) {
  85637. + DWC_ERROR("EP%d IN AHB Error\n", epnum);
  85638. + /* Clear the bit in DIEPINTn for this interrupt */
  85639. + CLEAR_IN_EP_INTR(core_if, epnum, ahberr);
  85640. + }
  85641. + /* TimeOUT Handshake (non-ISOC IN EPs) */
  85642. + if (diepint.b.timeout) {
  85643. + DWC_ERROR("EP%d IN Time-out\n", epnum);
  85644. + handle_in_ep_timeout_intr(pcd, epnum);
  85645. +
  85646. + CLEAR_IN_EP_INTR(core_if, epnum, timeout);
  85647. + }
  85648. + /** IN Token received with TxF Empty */
  85649. + if (diepint.b.intktxfemp) {
  85650. + DWC_DEBUGPL(DBG_ANY,
  85651. + "EP%d IN TKN TxFifo Empty\n",
  85652. + epnum);
  85653. + if (!ep->stopped && epnum != 0) {
  85654. +
  85655. + diepmsk_data_t diepmsk = {.d32 = 0 };
  85656. + diepmsk.b.intktxfemp = 1;
  85657. +
  85658. + if (core_if->multiproc_int_enable) {
  85659. + DWC_MODIFY_REG32
  85660. + (&dev_if->dev_global_regs->diepeachintmsk
  85661. + [epnum], diepmsk.d32, 0);
  85662. + } else {
  85663. + DWC_MODIFY_REG32
  85664. + (&dev_if->dev_global_regs->diepmsk,
  85665. + diepmsk.d32, 0);
  85666. + }
  85667. + } else if (core_if->dma_desc_enable
  85668. + && epnum == 0
  85669. + && pcd->ep0state ==
  85670. + EP0_OUT_STATUS_PHASE) {
  85671. + // EP0 IN set STALL
  85672. + depctl.d32 =
  85673. + DWC_READ_REG32(&dev_if->in_ep_regs
  85674. + [epnum]->diepctl);
  85675. +
  85676. + /* set the disable and stall bits */
  85677. + if (depctl.b.epena) {
  85678. + depctl.b.epdis = 1;
  85679. + }
  85680. + depctl.b.stall = 1;
  85681. + DWC_WRITE_REG32(&dev_if->in_ep_regs
  85682. + [epnum]->diepctl,
  85683. + depctl.d32);
  85684. + }
  85685. + CLEAR_IN_EP_INTR(core_if, epnum, intktxfemp);
  85686. + }
  85687. + /** IN Token Received with EP mismatch */
  85688. + if (diepint.b.intknepmis) {
  85689. + DWC_DEBUGPL(DBG_ANY,
  85690. + "EP%d IN TKN EP Mismatch\n", epnum);
  85691. + CLEAR_IN_EP_INTR(core_if, epnum, intknepmis);
  85692. + }
  85693. + /** IN Endpoint NAK Effective */
  85694. + if (diepint.b.inepnakeff) {
  85695. + DWC_DEBUGPL(DBG_ANY,
  85696. + "EP%d IN EP NAK Effective\n",
  85697. + epnum);
  85698. + /* Periodic EP */
  85699. + if (ep->disabling) {
  85700. + depctl.d32 = 0;
  85701. + depctl.b.snak = 1;
  85702. + depctl.b.epdis = 1;
  85703. + DWC_MODIFY_REG32(&dev_if->in_ep_regs
  85704. + [epnum]->diepctl,
  85705. + depctl.d32,
  85706. + depctl.d32);
  85707. + }
  85708. + CLEAR_IN_EP_INTR(core_if, epnum, inepnakeff);
  85709. +
  85710. + }
  85711. +
  85712. + /** IN EP Tx FIFO Empty Intr */
  85713. + if (diepint.b.emptyintr) {
  85714. + DWC_DEBUGPL(DBG_ANY,
  85715. + "EP%d Tx FIFO Empty Intr \n",
  85716. + epnum);
  85717. + write_empty_tx_fifo(pcd, epnum);
  85718. +
  85719. + CLEAR_IN_EP_INTR(core_if, epnum, emptyintr);
  85720. +
  85721. + }
  85722. +
  85723. + /** IN EP BNA Intr */
  85724. + if (diepint.b.bna) {
  85725. + CLEAR_IN_EP_INTR(core_if, epnum, bna);
  85726. + if (core_if->dma_desc_enable) {
  85727. +#ifdef DWC_EN_ISOC
  85728. + if (dwc_ep->type ==
  85729. + DWC_OTG_EP_TYPE_ISOC) {
  85730. + /*
  85731. + * This checking is performed to prevent first "false" BNA
  85732. + * handling occuring right after reconnect
  85733. + */
  85734. + if (dwc_ep->next_frame !=
  85735. + 0xffffffff)
  85736. + dwc_otg_pcd_handle_iso_bna(ep);
  85737. + } else
  85738. +#endif /* DWC_EN_ISOC */
  85739. + {
  85740. + dwc_otg_pcd_handle_noniso_bna(ep);
  85741. + }
  85742. + }
  85743. + }
  85744. + /* NAK Interrutp */
  85745. + if (diepint.b.nak) {
  85746. + DWC_DEBUGPL(DBG_ANY, "EP%d IN NAK Interrupt\n",
  85747. + epnum);
  85748. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  85749. + depctl_data_t depctl;
  85750. + if (ep->dwc_ep.frame_num == 0xFFFFFFFF) {
  85751. + ep->dwc_ep.frame_num = core_if->frame_num;
  85752. + if (ep->dwc_ep.bInterval > 1) {
  85753. + depctl.d32 = 0;
  85754. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl);
  85755. + if (ep->dwc_ep.frame_num & 0x1) {
  85756. + depctl.b.setd1pid = 1;
  85757. + depctl.b.setd0pid = 0;
  85758. + } else {
  85759. + depctl.b.setd0pid = 1;
  85760. + depctl.b.setd1pid = 0;
  85761. + }
  85762. + DWC_WRITE_REG32(&dev_if->in_ep_regs[epnum]->diepctl, depctl.d32);
  85763. + }
  85764. + start_next_request(ep);
  85765. + }
  85766. + ep->dwc_ep.frame_num += ep->dwc_ep.bInterval;
  85767. + if (dwc_ep->frame_num > 0x3FFF) {
  85768. + dwc_ep->frm_overrun = 1;
  85769. + dwc_ep->frame_num &= 0x3FFF;
  85770. + } else
  85771. + dwc_ep->frm_overrun = 0;
  85772. + }
  85773. +
  85774. + CLEAR_IN_EP_INTR(core_if, epnum, nak);
  85775. + }
  85776. + }
  85777. + epnum++;
  85778. + ep_intr >>= 1;
  85779. + }
  85780. +
  85781. + return 1;
  85782. +#undef CLEAR_IN_EP_INTR
  85783. +}
  85784. +
  85785. +/**
  85786. + * This interrupt indicates that an OUT EP has a pending Interrupt.
  85787. + * The sequence for handling the OUT EP interrupt is shown below:
  85788. + * -# Read the Device All Endpoint Interrupt register
  85789. + * -# Repeat the following for each OUT EP interrupt bit set (from
  85790. + * LSB to MSB).
  85791. + * -# Read the Device Endpoint Interrupt (DOEPINTn) register
  85792. + * -# If "Transfer Complete" call the request complete function
  85793. + * -# If "Endpoint Disabled" complete the EP disable procedure.
  85794. + * -# If "AHB Error Interrupt" log error
  85795. + * -# If "Setup Phase Done" process Setup Packet (See Standard USB
  85796. + * Command Processing)
  85797. + */
  85798. +static int32_t dwc_otg_pcd_handle_out_ep_intr(dwc_otg_pcd_t * pcd)
  85799. +{
  85800. +#define CLEAR_OUT_EP_INTR(__core_if,__epnum,__intr) \
  85801. +do { \
  85802. + doepint_data_t doepint = {.d32=0}; \
  85803. + doepint.b.__intr = 1; \
  85804. + DWC_WRITE_REG32(&__core_if->dev_if->out_ep_regs[__epnum]->doepint, \
  85805. + doepint.d32); \
  85806. +} while (0)
  85807. +
  85808. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  85809. + uint32_t ep_intr;
  85810. + doepint_data_t doepint = {.d32 = 0 };
  85811. + uint32_t epnum = 0;
  85812. + dwc_otg_pcd_ep_t *ep;
  85813. + dwc_ep_t *dwc_ep;
  85814. + dctl_data_t dctl = {.d32 = 0 };
  85815. + gintmsk_data_t gintmsk = {.d32 = 0 };
  85816. +
  85817. +
  85818. + DWC_DEBUGPL(DBG_PCDV, "%s()\n", __func__);
  85819. +
  85820. + /* Read in the device interrupt bits */
  85821. + ep_intr = dwc_otg_read_dev_all_out_ep_intr(core_if);
  85822. +
  85823. + while (ep_intr) {
  85824. + if (ep_intr & 0x1) {
  85825. + /* Get EP pointer */
  85826. + ep = get_out_ep(pcd, epnum);
  85827. + dwc_ep = &ep->dwc_ep;
  85828. +
  85829. +#ifdef VERBOSE
  85830. + DWC_DEBUGPL(DBG_PCDV,
  85831. + "EP%d-%s: type=%d, mps=%d\n",
  85832. + dwc_ep->num, (dwc_ep->is_in ? "IN" : "OUT"),
  85833. + dwc_ep->type, dwc_ep->maxpacket);
  85834. +#endif
  85835. + doepint.d32 =
  85836. + dwc_otg_read_dev_out_ep_intr(core_if, dwc_ep);
  85837. + /* Moved this interrupt upper due to core deffect of asserting
  85838. + * OUT EP 0 xfercompl along with stsphsrcvd in BDMA */
  85839. + if (doepint.b.stsphsercvd) {
  85840. + deptsiz0_data_t deptsiz;
  85841. + CLEAR_OUT_EP_INTR(core_if, epnum, stsphsercvd);
  85842. + deptsiz.d32 =
  85843. + DWC_READ_REG32(&core_if->dev_if->
  85844. + out_ep_regs[0]->doeptsiz);
  85845. + if (core_if->snpsid >= OTG_CORE_REV_3_00a
  85846. + && core_if->dma_enable
  85847. + && core_if->dma_desc_enable == 0
  85848. + && doepint.b.xfercompl
  85849. + && deptsiz.b.xfersize == 24) {
  85850. + CLEAR_OUT_EP_INTR(core_if, epnum,
  85851. + xfercompl);
  85852. + doepint.b.xfercompl = 0;
  85853. + ep0_out_start(core_if, pcd);
  85854. + }
  85855. + if ((core_if->dma_desc_enable) ||
  85856. + (core_if->dma_enable
  85857. + && core_if->snpsid >=
  85858. + OTG_CORE_REV_3_00a)) {
  85859. + do_setup_in_status_phase(pcd);
  85860. + }
  85861. + }
  85862. + /* Transfer complete */
  85863. + if (doepint.b.xfercompl) {
  85864. +
  85865. + if (epnum == 0) {
  85866. + /* Clear the bit in DOEPINTn for this interrupt */
  85867. + CLEAR_OUT_EP_INTR(core_if, epnum, xfercompl);
  85868. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  85869. + DWC_DEBUGPL(DBG_PCDV, "DOEPINT=%x doepint=%x\n",
  85870. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[0]->doepint),
  85871. + doepint.d32);
  85872. + DWC_DEBUGPL(DBG_PCDV, "DOEPCTL=%x \n",
  85873. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[0]->doepctl));
  85874. +
  85875. + if (core_if->snpsid >= OTG_CORE_REV_3_00a
  85876. + && core_if->dma_enable == 0) {
  85877. + doepint_data_t doepint;
  85878. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  85879. + out_ep_regs[0]->doepint);
  85880. + if (pcd->ep0state == EP0_IDLE && doepint.b.sr) {
  85881. + CLEAR_OUT_EP_INTR(core_if, epnum, sr);
  85882. + goto exit_xfercompl;
  85883. + }
  85884. + }
  85885. + /* In case of DDMA look at SR bit to go to the Data Stage */
  85886. + if (core_if->dma_desc_enable) {
  85887. + dev_dma_desc_sts_t status = {.d32 = 0};
  85888. + if (pcd->ep0state == EP0_IDLE) {
  85889. + status.d32 = core_if->dev_if->setup_desc_addr[core_if->
  85890. + dev_if->setup_desc_index]->status.d32;
  85891. + if(pcd->data_terminated) {
  85892. + pcd->data_terminated = 0;
  85893. + status.d32 = core_if->dev_if->out_desc_addr->status.d32;
  85894. + dwc_memcpy(&pcd->setup_pkt->req, pcd->backup_buf, 8);
  85895. + }
  85896. + if (status.b.sr) {
  85897. + if (doepint.b.setup) {
  85898. + DWC_DEBUGPL(DBG_PCDV, "DMA DESC EP0_IDLE SR=1 setup=1\n");
  85899. + /* Already started data stage, clear setup */
  85900. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  85901. + doepint.b.setup = 0;
  85902. + handle_ep0(pcd);
  85903. + /* Prepare for more setup packets */
  85904. + if (pcd->ep0state == EP0_IN_STATUS_PHASE ||
  85905. + pcd->ep0state == EP0_IN_DATA_PHASE) {
  85906. + ep0_out_start(core_if, pcd);
  85907. + }
  85908. +
  85909. + goto exit_xfercompl;
  85910. + } else {
  85911. + /* Prepare for more setup packets */
  85912. + DWC_DEBUGPL(DBG_PCDV,
  85913. + "EP0_IDLE SR=1 setup=0 new setup comes\n");
  85914. + ep0_out_start(core_if, pcd);
  85915. + }
  85916. + }
  85917. + } else {
  85918. + dwc_otg_pcd_request_t *req;
  85919. + dev_dma_desc_sts_t status = {.d32 = 0};
  85920. + diepint_data_t diepint0;
  85921. + diepint0.d32 = DWC_READ_REG32(&core_if->dev_if->
  85922. + in_ep_regs[0]->diepint);
  85923. +
  85924. + if (pcd->ep0state == EP0_STALL || pcd->ep0state == EP0_DISCONNECT) {
  85925. + DWC_ERROR("EP0 is stalled/disconnected\n");
  85926. + }
  85927. +
  85928. + /* Clear IN xfercompl if set */
  85929. + if (diepint0.b.xfercompl && (pcd->ep0state == EP0_IN_STATUS_PHASE
  85930. + || pcd->ep0state == EP0_IN_DATA_PHASE)) {
  85931. + DWC_WRITE_REG32(&core_if->dev_if->
  85932. + in_ep_regs[0]->diepint, diepint0.d32);
  85933. + }
  85934. +
  85935. + status.d32 = core_if->dev_if->setup_desc_addr[core_if->
  85936. + dev_if->setup_desc_index]->status.d32;
  85937. +
  85938. + if (ep->dwc_ep.xfer_count != ep->dwc_ep.total_len
  85939. + && (pcd->ep0state == EP0_OUT_DATA_PHASE))
  85940. + status.d32 = core_if->dev_if->out_desc_addr->status.d32;
  85941. + if (pcd->ep0state == EP0_OUT_STATUS_PHASE)
  85942. + status.d32 = core_if->dev_if->
  85943. + out_desc_addr->status.d32;
  85944. +
  85945. + if (status.b.sr) {
  85946. + if (DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  85947. + DWC_DEBUGPL(DBG_PCDV, "Request queue empty!!\n");
  85948. + } else {
  85949. + DWC_DEBUGPL(DBG_PCDV, "complete req!!\n");
  85950. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  85951. + if (ep->dwc_ep.xfer_count != ep->dwc_ep.total_len &&
  85952. + pcd->ep0state == EP0_OUT_DATA_PHASE) {
  85953. + /* Read arrived setup packet from req->buf */
  85954. + dwc_memcpy(&pcd->setup_pkt->req,
  85955. + req->buf + ep->dwc_ep.xfer_count, 8);
  85956. + }
  85957. + req->actual = ep->dwc_ep.xfer_count;
  85958. + dwc_otg_request_done(ep, req, -ECONNRESET);
  85959. + ep->dwc_ep.start_xfer_buff = 0;
  85960. + ep->dwc_ep.xfer_buff = 0;
  85961. + ep->dwc_ep.xfer_len = 0;
  85962. + }
  85963. + pcd->ep0state = EP0_IDLE;
  85964. + if (doepint.b.setup) {
  85965. + DWC_DEBUGPL(DBG_PCDV, "EP0_IDLE SR=1 setup=1\n");
  85966. + /* Data stage started, clear setup */
  85967. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  85968. + doepint.b.setup = 0;
  85969. + handle_ep0(pcd);
  85970. + /* Prepare for setup packets if ep0in was enabled*/
  85971. + if (pcd->ep0state == EP0_IN_STATUS_PHASE) {
  85972. + ep0_out_start(core_if, pcd);
  85973. + }
  85974. +
  85975. + goto exit_xfercompl;
  85976. + } else {
  85977. + /* Prepare for more setup packets */
  85978. + DWC_DEBUGPL(DBG_PCDV,
  85979. + "EP0_IDLE SR=1 setup=0 new setup comes 2\n");
  85980. + ep0_out_start(core_if, pcd);
  85981. + }
  85982. + }
  85983. + }
  85984. + }
  85985. + if (core_if->snpsid >= OTG_CORE_REV_2_94a && core_if->dma_enable
  85986. + && core_if->dma_desc_enable == 0) {
  85987. + doepint_data_t doepint_temp = {.d32 = 0};
  85988. + deptsiz0_data_t doeptsize0 = {.d32 = 0 };
  85989. + doepint_temp.d32 = DWC_READ_REG32(&core_if->dev_if->
  85990. + out_ep_regs[ep->dwc_ep.num]->doepint);
  85991. + doeptsize0.d32 = DWC_READ_REG32(&core_if->dev_if->
  85992. + out_ep_regs[ep->dwc_ep.num]->doeptsiz);
  85993. + if (pcd->ep0state == EP0_IDLE) {
  85994. + if (doepint_temp.b.sr) {
  85995. + CLEAR_OUT_EP_INTR(core_if, epnum, sr);
  85996. + }
  85997. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  85998. + out_ep_regs[0]->doepint);
  85999. + if (doeptsize0.b.supcnt == 3) {
  86000. + DWC_DEBUGPL(DBG_ANY, "Rolling over!!!!!!!\n");
  86001. + ep->dwc_ep.stp_rollover = 1;
  86002. + }
  86003. + if (doepint.b.setup) {
  86004. +retry:
  86005. + /* Already started data stage, clear setup */
  86006. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  86007. + doepint.b.setup = 0;
  86008. + handle_ep0(pcd);
  86009. + ep->dwc_ep.stp_rollover = 0;
  86010. + /* Prepare for more setup packets */
  86011. + if (pcd->ep0state == EP0_IN_STATUS_PHASE ||
  86012. + pcd->ep0state == EP0_IN_DATA_PHASE) {
  86013. + ep0_out_start(core_if, pcd);
  86014. + }
  86015. + goto exit_xfercompl;
  86016. + } else {
  86017. + /* Prepare for more setup packets */
  86018. + DWC_DEBUGPL(DBG_ANY,
  86019. + "EP0_IDLE SR=1 setup=0 new setup comes\n");
  86020. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  86021. + out_ep_regs[0]->doepint);
  86022. + if(doepint.b.setup)
  86023. + goto retry;
  86024. + ep0_out_start(core_if, pcd);
  86025. + }
  86026. + } else {
  86027. + dwc_otg_pcd_request_t *req;
  86028. + diepint_data_t diepint0 = {.d32 = 0};
  86029. + doepint_data_t doepint_temp = {.d32 = 0};
  86030. + depctl_data_t diepctl0;
  86031. + diepint0.d32 = DWC_READ_REG32(&core_if->dev_if->
  86032. + in_ep_regs[0]->diepint);
  86033. + diepctl0.d32 = DWC_READ_REG32(&core_if->dev_if->
  86034. + in_ep_regs[0]->diepctl);
  86035. +
  86036. + if (pcd->ep0state == EP0_IN_DATA_PHASE
  86037. + || pcd->ep0state == EP0_IN_STATUS_PHASE) {
  86038. + if (diepint0.b.xfercompl) {
  86039. + DWC_WRITE_REG32(&core_if->dev_if->
  86040. + in_ep_regs[0]->diepint, diepint0.d32);
  86041. + }
  86042. + if (diepctl0.b.epena) {
  86043. + diepint_data_t diepint = {.d32 = 0};
  86044. + diepctl0.b.snak = 1;
  86045. + DWC_WRITE_REG32(&core_if->dev_if->
  86046. + in_ep_regs[0]->diepctl, diepctl0.d32);
  86047. + do {
  86048. + dwc_udelay(10);
  86049. + diepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  86050. + in_ep_regs[0]->diepint);
  86051. + } while (!diepint.b.inepnakeff);
  86052. + diepint.b.inepnakeff = 1;
  86053. + DWC_WRITE_REG32(&core_if->dev_if->
  86054. + in_ep_regs[0]->diepint, diepint.d32);
  86055. + diepctl0.d32 = 0;
  86056. + diepctl0.b.epdis = 1;
  86057. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[0]->diepctl,
  86058. + diepctl0.d32);
  86059. + do {
  86060. + dwc_udelay(10);
  86061. + diepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  86062. + in_ep_regs[0]->diepint);
  86063. + } while (!diepint.b.epdisabled);
  86064. + diepint.b.epdisabled = 1;
  86065. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[0]->diepint,
  86066. + diepint.d32);
  86067. + }
  86068. + }
  86069. + doepint_temp.d32 = DWC_READ_REG32(&core_if->dev_if->
  86070. + out_ep_regs[ep->dwc_ep.num]->doepint);
  86071. + if (doepint_temp.b.sr) {
  86072. + CLEAR_OUT_EP_INTR(core_if, epnum, sr);
  86073. + if (DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  86074. + DWC_DEBUGPL(DBG_PCDV, "Request queue empty!!\n");
  86075. + } else {
  86076. + DWC_DEBUGPL(DBG_PCDV, "complete req!!\n");
  86077. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  86078. + if (ep->dwc_ep.xfer_count != ep->dwc_ep.total_len &&
  86079. + pcd->ep0state == EP0_OUT_DATA_PHASE) {
  86080. + /* Read arrived setup packet from req->buf */
  86081. + dwc_memcpy(&pcd->setup_pkt->req,
  86082. + req->buf + ep->dwc_ep.xfer_count, 8);
  86083. + }
  86084. + req->actual = ep->dwc_ep.xfer_count;
  86085. + dwc_otg_request_done(ep, req, -ECONNRESET);
  86086. + ep->dwc_ep.start_xfer_buff = 0;
  86087. + ep->dwc_ep.xfer_buff = 0;
  86088. + ep->dwc_ep.xfer_len = 0;
  86089. + }
  86090. + pcd->ep0state = EP0_IDLE;
  86091. + if (doepint.b.setup) {
  86092. + DWC_DEBUGPL(DBG_PCDV, "EP0_IDLE SR=1 setup=1\n");
  86093. + /* Data stage started, clear setup */
  86094. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  86095. + doepint.b.setup = 0;
  86096. + handle_ep0(pcd);
  86097. + /* Prepare for setup packets if ep0in was enabled*/
  86098. + if (pcd->ep0state == EP0_IN_STATUS_PHASE) {
  86099. + ep0_out_start(core_if, pcd);
  86100. + }
  86101. + goto exit_xfercompl;
  86102. + } else {
  86103. + /* Prepare for more setup packets */
  86104. + DWC_DEBUGPL(DBG_PCDV,
  86105. + "EP0_IDLE SR=1 setup=0 new setup comes 2\n");
  86106. + ep0_out_start(core_if, pcd);
  86107. + }
  86108. + }
  86109. + }
  86110. + }
  86111. + if (core_if->dma_enable == 0 || pcd->ep0state != EP0_IDLE)
  86112. + handle_ep0(pcd);
  86113. +exit_xfercompl:
  86114. + DWC_DEBUGPL(DBG_PCDV, "DOEPINT=%x doepint=%x\n",
  86115. + dwc_otg_read_dev_out_ep_intr(core_if, dwc_ep), doepint.d32);
  86116. + } else {
  86117. + if (core_if->dma_desc_enable == 0
  86118. + || pcd->ep0state != EP0_IDLE)
  86119. + handle_ep0(pcd);
  86120. + }
  86121. +#ifdef DWC_EN_ISOC
  86122. + } else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  86123. + if (doepint.b.pktdrpsts == 0) {
  86124. + /* Clear the bit in DOEPINTn for this interrupt */
  86125. + CLEAR_OUT_EP_INTR(core_if,
  86126. + epnum,
  86127. + xfercompl);
  86128. + complete_iso_ep(pcd, ep);
  86129. + } else {
  86130. +
  86131. + doepint_data_t doepint = {.d32 = 0 };
  86132. + doepint.b.xfercompl = 1;
  86133. + doepint.b.pktdrpsts = 1;
  86134. + DWC_WRITE_REG32
  86135. + (&core_if->dev_if->out_ep_regs
  86136. + [epnum]->doepint,
  86137. + doepint.d32);
  86138. + if (handle_iso_out_pkt_dropped
  86139. + (core_if, dwc_ep)) {
  86140. + complete_iso_ep(pcd,
  86141. + ep);
  86142. + }
  86143. + }
  86144. +#endif /* DWC_EN_ISOC */
  86145. +#ifdef DWC_UTE_PER_IO
  86146. + } else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  86147. + CLEAR_OUT_EP_INTR(core_if, epnum, xfercompl);
  86148. + if (!ep->stopped)
  86149. + complete_xiso_ep(ep);
  86150. +#endif /* DWC_UTE_PER_IO */
  86151. + } else {
  86152. + /* Clear the bit in DOEPINTn for this interrupt */
  86153. + CLEAR_OUT_EP_INTR(core_if, epnum,
  86154. + xfercompl);
  86155. +
  86156. + if (core_if->core_params->dev_out_nak) {
  86157. + DWC_TIMER_CANCEL(pcd->core_if->ep_xfer_timer[epnum]);
  86158. + pcd->core_if->ep_xfer_info[epnum].state = 0;
  86159. +#ifdef DEBUG
  86160. + print_memory_payload(pcd, dwc_ep);
  86161. +#endif
  86162. + }
  86163. + complete_ep(ep);
  86164. + }
  86165. +
  86166. + }
  86167. +
  86168. + /* Endpoint disable */
  86169. + if (doepint.b.epdisabled) {
  86170. +
  86171. + /* Clear the bit in DOEPINTn for this interrupt */
  86172. + CLEAR_OUT_EP_INTR(core_if, epnum, epdisabled);
  86173. + if (core_if->core_params->dev_out_nak) {
  86174. +#ifdef DEBUG
  86175. + print_memory_payload(pcd, dwc_ep);
  86176. +#endif
  86177. + /* In case of timeout condition */
  86178. + if (core_if->ep_xfer_info[epnum].state == 2) {
  86179. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->
  86180. + dev_global_regs->dctl);
  86181. + dctl.b.cgoutnak = 1;
  86182. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl,
  86183. + dctl.d32);
  86184. + /* Unmask goutnakeff interrupt which was masked
  86185. + * during handle nak out interrupt */
  86186. + gintmsk.b.goutnakeff = 1;
  86187. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  86188. + 0, gintmsk.d32);
  86189. +
  86190. + complete_ep(ep);
  86191. + }
  86192. + }
  86193. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC)
  86194. + {
  86195. + dctl_data_t dctl;
  86196. + gintmsk_data_t intr_mask = {.d32 = 0};
  86197. + dwc_otg_pcd_request_t *req = 0;
  86198. +
  86199. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->
  86200. + dev_global_regs->dctl);
  86201. + dctl.b.cgoutnak = 1;
  86202. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl,
  86203. + dctl.d32);
  86204. +
  86205. + intr_mask.d32 = 0;
  86206. + intr_mask.b.incomplisoout = 1;
  86207. +
  86208. + /* Get any pending requests */
  86209. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  86210. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  86211. + if (!req) {
  86212. + DWC_PRINTF("complete_ep 0x%p, req = NULL!\n", ep);
  86213. + } else {
  86214. + dwc_otg_request_done(ep, req, 0);
  86215. + start_next_request(ep);
  86216. + }
  86217. + } else {
  86218. + DWC_PRINTF("complete_ep 0x%p, ep->queue empty!\n", ep);
  86219. + }
  86220. + }
  86221. + }
  86222. + /* AHB Error */
  86223. + if (doepint.b.ahberr) {
  86224. + DWC_ERROR("EP%d OUT AHB Error\n", epnum);
  86225. + DWC_ERROR("EP%d DEPDMA=0x%08x \n",
  86226. + epnum, core_if->dev_if->out_ep_regs[epnum]->doepdma);
  86227. + CLEAR_OUT_EP_INTR(core_if, epnum, ahberr);
  86228. + }
  86229. + /* Setup Phase Done (contorl EPs) */
  86230. + if (doepint.b.setup) {
  86231. +#ifdef DEBUG_EP0
  86232. + DWC_DEBUGPL(DBG_PCD, "EP%d SETUP Done\n", epnum);
  86233. +#endif
  86234. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  86235. +
  86236. + handle_ep0(pcd);
  86237. + }
  86238. +
  86239. + /** OUT EP BNA Intr */
  86240. + if (doepint.b.bna) {
  86241. + CLEAR_OUT_EP_INTR(core_if, epnum, bna);
  86242. + if (core_if->dma_desc_enable) {
  86243. +#ifdef DWC_EN_ISOC
  86244. + if (dwc_ep->type ==
  86245. + DWC_OTG_EP_TYPE_ISOC) {
  86246. + /*
  86247. + * This checking is performed to prevent first "false" BNA
  86248. + * handling occuring right after reconnect
  86249. + */
  86250. + if (dwc_ep->next_frame !=
  86251. + 0xffffffff)
  86252. + dwc_otg_pcd_handle_iso_bna(ep);
  86253. + } else
  86254. +#endif /* DWC_EN_ISOC */
  86255. + {
  86256. + dwc_otg_pcd_handle_noniso_bna(ep);
  86257. + }
  86258. + }
  86259. + }
  86260. + /* Babble Interrupt */
  86261. + if (doepint.b.babble) {
  86262. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT Babble\n",
  86263. + epnum);
  86264. + handle_out_ep_babble_intr(pcd, epnum);
  86265. +
  86266. + CLEAR_OUT_EP_INTR(core_if, epnum, babble);
  86267. + }
  86268. + if (doepint.b.outtknepdis) {
  86269. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT Token received when EP is \
  86270. + disabled\n",epnum);
  86271. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  86272. + doepmsk_data_t doepmsk = {.d32 = 0};
  86273. + ep->dwc_ep.frame_num = core_if->frame_num;
  86274. + if (ep->dwc_ep.bInterval > 1) {
  86275. + depctl_data_t depctl;
  86276. + depctl.d32 = DWC_READ_REG32(&core_if->dev_if->
  86277. + out_ep_regs[epnum]->doepctl);
  86278. + if (ep->dwc_ep.frame_num & 0x1) {
  86279. + depctl.b.setd1pid = 1;
  86280. + depctl.b.setd0pid = 0;
  86281. + } else {
  86282. + depctl.b.setd0pid = 1;
  86283. + depctl.b.setd1pid = 0;
  86284. + }
  86285. + DWC_WRITE_REG32(&core_if->dev_if->
  86286. + out_ep_regs[epnum]->doepctl, depctl.d32);
  86287. + }
  86288. + start_next_request(ep);
  86289. + doepmsk.b.outtknepdis = 1;
  86290. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  86291. + doepmsk.d32, 0);
  86292. + }
  86293. + CLEAR_OUT_EP_INTR(core_if, epnum, outtknepdis);
  86294. + }
  86295. +
  86296. + /* NAK Interrutp */
  86297. + if (doepint.b.nak) {
  86298. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT NAK\n", epnum);
  86299. + handle_out_ep_nak_intr(pcd, epnum);
  86300. +
  86301. + CLEAR_OUT_EP_INTR(core_if, epnum, nak);
  86302. + }
  86303. + /* NYET Interrutp */
  86304. + if (doepint.b.nyet) {
  86305. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT NYET\n", epnum);
  86306. + handle_out_ep_nyet_intr(pcd, epnum);
  86307. +
  86308. + CLEAR_OUT_EP_INTR(core_if, epnum, nyet);
  86309. + }
  86310. + }
  86311. +
  86312. + epnum++;
  86313. + ep_intr >>= 1;
  86314. + }
  86315. +
  86316. + return 1;
  86317. +
  86318. +#undef CLEAR_OUT_EP_INTR
  86319. +}
  86320. +static int drop_transfer(uint32_t trgt_fr, uint32_t curr_fr, uint8_t frm_overrun)
  86321. +{
  86322. + int retval = 0;
  86323. + if(!frm_overrun && curr_fr >= trgt_fr)
  86324. + retval = 1;
  86325. + else if (frm_overrun
  86326. + && (curr_fr >= trgt_fr && ((curr_fr - trgt_fr) < 0x3FFF / 2)))
  86327. + retval = 1;
  86328. + return retval;
  86329. +}
  86330. +/**
  86331. + * Incomplete ISO IN Transfer Interrupt.
  86332. + * This interrupt indicates one of the following conditions occurred
  86333. + * while transmitting an ISOC transaction.
  86334. + * - Corrupted IN Token for ISOC EP.
  86335. + * - Packet not complete in FIFO.
  86336. + * The follow actions will be taken:
  86337. + * -# Determine the EP
  86338. + * -# Set incomplete flag in dwc_ep structure
  86339. + * -# Disable EP; when "Endpoint Disabled" interrupt is received
  86340. + * Flush FIFO
  86341. + */
  86342. +int32_t dwc_otg_pcd_handle_incomplete_isoc_in_intr(dwc_otg_pcd_t * pcd)
  86343. +{
  86344. + gintsts_data_t gintsts;
  86345. +
  86346. +#ifdef DWC_EN_ISOC
  86347. + dwc_otg_dev_if_t *dev_if;
  86348. + deptsiz_data_t deptsiz = {.d32 = 0 };
  86349. + depctl_data_t depctl = {.d32 = 0 };
  86350. + dsts_data_t dsts = {.d32 = 0 };
  86351. + dwc_ep_t *dwc_ep;
  86352. + int i;
  86353. +
  86354. + dev_if = GET_CORE_IF(pcd)->dev_if;
  86355. +
  86356. + for (i = 1; i <= dev_if->num_in_eps; ++i) {
  86357. + dwc_ep = &pcd->in_ep[i].dwc_ep;
  86358. + if (dwc_ep->active && dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  86359. + deptsiz.d32 =
  86360. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->dieptsiz);
  86361. + depctl.d32 =
  86362. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  86363. +
  86364. + if (depctl.b.epdis && deptsiz.d32) {
  86365. + set_current_pkt_info(GET_CORE_IF(pcd), dwc_ep);
  86366. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  86367. + dwc_ep->cur_pkt = 0;
  86368. + dwc_ep->proc_buf_num =
  86369. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  86370. +
  86371. + if (dwc_ep->proc_buf_num) {
  86372. + dwc_ep->cur_pkt_addr =
  86373. + dwc_ep->xfer_buff1;
  86374. + dwc_ep->cur_pkt_dma_addr =
  86375. + dwc_ep->dma_addr1;
  86376. + } else {
  86377. + dwc_ep->cur_pkt_addr =
  86378. + dwc_ep->xfer_buff0;
  86379. + dwc_ep->cur_pkt_dma_addr =
  86380. + dwc_ep->dma_addr0;
  86381. + }
  86382. +
  86383. + }
  86384. +
  86385. + dsts.d32 =
  86386. + DWC_READ_REG32(&GET_CORE_IF(pcd)->dev_if->
  86387. + dev_global_regs->dsts);
  86388. + dwc_ep->next_frame = dsts.b.soffn;
  86389. +
  86390. + dwc_otg_iso_ep_start_frm_transfer(GET_CORE_IF
  86391. + (pcd),
  86392. + dwc_ep);
  86393. + }
  86394. + }
  86395. + }
  86396. +
  86397. +#else
  86398. + depctl_data_t depctl = {.d32 = 0 };
  86399. + dwc_ep_t *dwc_ep;
  86400. + dwc_otg_dev_if_t *dev_if;
  86401. + int i;
  86402. + dev_if = GET_CORE_IF(pcd)->dev_if;
  86403. +
  86404. + DWC_DEBUGPL(DBG_PCD,"Incomplete ISO IN \n");
  86405. +
  86406. + for (i = 1; i <= dev_if->num_in_eps; ++i) {
  86407. + dwc_ep = &pcd->in_ep[i-1].dwc_ep;
  86408. + depctl.d32 =
  86409. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  86410. + if (depctl.b.epena && dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  86411. + if (drop_transfer(dwc_ep->frame_num, GET_CORE_IF(pcd)->frame_num,
  86412. + dwc_ep->frm_overrun))
  86413. + {
  86414. + depctl.d32 =
  86415. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  86416. + depctl.b.snak = 1;
  86417. + depctl.b.epdis = 1;
  86418. + DWC_MODIFY_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32, depctl.d32);
  86419. + }
  86420. + }
  86421. + }
  86422. +
  86423. + /*intr_mask.b.incomplisoin = 1;
  86424. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  86425. + intr_mask.d32, 0); */
  86426. +#endif //DWC_EN_ISOC
  86427. +
  86428. + /* Clear interrupt */
  86429. + gintsts.d32 = 0;
  86430. + gintsts.b.incomplisoin = 1;
  86431. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  86432. + gintsts.d32);
  86433. +
  86434. + return 1;
  86435. +}
  86436. +
  86437. +/**
  86438. + * Incomplete ISO OUT Transfer Interrupt.
  86439. + *
  86440. + * This interrupt indicates that the core has dropped an ISO OUT
  86441. + * packet. The following conditions can be the cause:
  86442. + * - FIFO Full, the entire packet would not fit in the FIFO.
  86443. + * - CRC Error
  86444. + * - Corrupted Token
  86445. + * The follow actions will be taken:
  86446. + * -# Determine the EP
  86447. + * -# Set incomplete flag in dwc_ep structure
  86448. + * -# Read any data from the FIFO
  86449. + * -# Disable EP. When "Endpoint Disabled" interrupt is received
  86450. + * re-enable EP.
  86451. + */
  86452. +int32_t dwc_otg_pcd_handle_incomplete_isoc_out_intr(dwc_otg_pcd_t * pcd)
  86453. +{
  86454. +
  86455. + gintsts_data_t gintsts;
  86456. +
  86457. +#ifdef DWC_EN_ISOC
  86458. + dwc_otg_dev_if_t *dev_if;
  86459. + deptsiz_data_t deptsiz = {.d32 = 0 };
  86460. + depctl_data_t depctl = {.d32 = 0 };
  86461. + dsts_data_t dsts = {.d32 = 0 };
  86462. + dwc_ep_t *dwc_ep;
  86463. + int i;
  86464. +
  86465. + dev_if = GET_CORE_IF(pcd)->dev_if;
  86466. +
  86467. + for (i = 1; i <= dev_if->num_out_eps; ++i) {
  86468. + dwc_ep = &pcd->in_ep[i].dwc_ep;
  86469. + if (pcd->out_ep[i].dwc_ep.active &&
  86470. + pcd->out_ep[i].dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  86471. + deptsiz.d32 =
  86472. + DWC_READ_REG32(&dev_if->out_ep_regs[i]->doeptsiz);
  86473. + depctl.d32 =
  86474. + DWC_READ_REG32(&dev_if->out_ep_regs[i]->doepctl);
  86475. +
  86476. + if (depctl.b.epdis && deptsiz.d32) {
  86477. + set_current_pkt_info(GET_CORE_IF(pcd),
  86478. + &pcd->out_ep[i].dwc_ep);
  86479. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  86480. + dwc_ep->cur_pkt = 0;
  86481. + dwc_ep->proc_buf_num =
  86482. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  86483. +
  86484. + if (dwc_ep->proc_buf_num) {
  86485. + dwc_ep->cur_pkt_addr =
  86486. + dwc_ep->xfer_buff1;
  86487. + dwc_ep->cur_pkt_dma_addr =
  86488. + dwc_ep->dma_addr1;
  86489. + } else {
  86490. + dwc_ep->cur_pkt_addr =
  86491. + dwc_ep->xfer_buff0;
  86492. + dwc_ep->cur_pkt_dma_addr =
  86493. + dwc_ep->dma_addr0;
  86494. + }
  86495. +
  86496. + }
  86497. +
  86498. + dsts.d32 =
  86499. + DWC_READ_REG32(&GET_CORE_IF(pcd)->dev_if->
  86500. + dev_global_regs->dsts);
  86501. + dwc_ep->next_frame = dsts.b.soffn;
  86502. +
  86503. + dwc_otg_iso_ep_start_frm_transfer(GET_CORE_IF
  86504. + (pcd),
  86505. + dwc_ep);
  86506. + }
  86507. + }
  86508. + }
  86509. +#else
  86510. + /** @todo implement ISR */
  86511. + gintmsk_data_t intr_mask = {.d32 = 0 };
  86512. + dwc_otg_core_if_t *core_if;
  86513. + deptsiz_data_t deptsiz = {.d32 = 0 };
  86514. + depctl_data_t depctl = {.d32 = 0 };
  86515. + dctl_data_t dctl = {.d32 = 0 };
  86516. + dwc_ep_t *dwc_ep = NULL;
  86517. + int i;
  86518. + core_if = GET_CORE_IF(pcd);
  86519. +
  86520. + for (i = 0; i < core_if->dev_if->num_out_eps; ++i) {
  86521. + dwc_ep = &pcd->out_ep[i].dwc_ep;
  86522. + depctl.d32 =
  86523. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl);
  86524. + if (depctl.b.epena && depctl.b.dpid == (core_if->frame_num & 0x1)) {
  86525. + core_if->dev_if->isoc_ep = dwc_ep;
  86526. + deptsiz.d32 =
  86527. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doeptsiz);
  86528. + break;
  86529. + }
  86530. + }
  86531. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  86532. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  86533. + intr_mask.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  86534. +
  86535. + if (!intr_mask.b.goutnakeff) {
  86536. + /* Unmask it */
  86537. + intr_mask.b.goutnakeff = 1;
  86538. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, intr_mask.d32);
  86539. + }
  86540. + if (!gintsts.b.goutnakeff) {
  86541. + dctl.b.sgoutnak = 1;
  86542. + }
  86543. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  86544. +
  86545. + depctl.d32 = DWC_READ_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl);
  86546. + if (depctl.b.epena) {
  86547. + depctl.b.epdis = 1;
  86548. + depctl.b.snak = 1;
  86549. + }
  86550. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl, depctl.d32);
  86551. +
  86552. + intr_mask.d32 = 0;
  86553. + intr_mask.b.incomplisoout = 1;
  86554. +
  86555. +#endif /* DWC_EN_ISOC */
  86556. +
  86557. + /* Clear interrupt */
  86558. + gintsts.d32 = 0;
  86559. + gintsts.b.incomplisoout = 1;
  86560. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  86561. + gintsts.d32);
  86562. +
  86563. + return 1;
  86564. +}
  86565. +
  86566. +/**
  86567. + * This function handles the Global IN NAK Effective interrupt.
  86568. + *
  86569. + */
  86570. +int32_t dwc_otg_pcd_handle_in_nak_effective(dwc_otg_pcd_t * pcd)
  86571. +{
  86572. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  86573. + depctl_data_t diepctl = {.d32 = 0 };
  86574. + gintmsk_data_t intr_mask = {.d32 = 0 };
  86575. + gintsts_data_t gintsts;
  86576. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  86577. + int i;
  86578. +
  86579. + DWC_DEBUGPL(DBG_PCD, "Global IN NAK Effective\n");
  86580. +
  86581. + /* Disable all active IN EPs */
  86582. + for (i = 0; i <= dev_if->num_in_eps; i++) {
  86583. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  86584. + if (!(diepctl.b.eptype & 1) && diepctl.b.epena) {
  86585. + if (core_if->start_predict > 0)
  86586. + core_if->start_predict++;
  86587. + diepctl.b.epdis = 1;
  86588. + diepctl.b.snak = 1;
  86589. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, diepctl.d32);
  86590. + }
  86591. + }
  86592. +
  86593. +
  86594. + /* Disable the Global IN NAK Effective Interrupt */
  86595. + intr_mask.b.ginnakeff = 1;
  86596. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  86597. + intr_mask.d32, 0);
  86598. +
  86599. + /* Clear interrupt */
  86600. + gintsts.d32 = 0;
  86601. + gintsts.b.ginnakeff = 1;
  86602. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  86603. + gintsts.d32);
  86604. +
  86605. + return 1;
  86606. +}
  86607. +
  86608. +/**
  86609. + * OUT NAK Effective.
  86610. + *
  86611. + */
  86612. +int32_t dwc_otg_pcd_handle_out_nak_effective(dwc_otg_pcd_t * pcd)
  86613. +{
  86614. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  86615. + gintmsk_data_t intr_mask = {.d32 = 0 };
  86616. + gintsts_data_t gintsts;
  86617. + depctl_data_t doepctl;
  86618. + int i;
  86619. +
  86620. + /* Disable the Global OUT NAK Effective Interrupt */
  86621. + intr_mask.b.goutnakeff = 1;
  86622. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  86623. + intr_mask.d32, 0);
  86624. +
  86625. + /* If DEV OUT NAK enabled*/
  86626. + if (pcd->core_if->core_params->dev_out_nak) {
  86627. + /* Run over all out endpoints to determine the ep number on
  86628. + * which the timeout has happened
  86629. + */
  86630. + for (i = 0; i <= dev_if->num_out_eps; i++) {
  86631. + if ( pcd->core_if->ep_xfer_info[i].state == 2 )
  86632. + break;
  86633. + }
  86634. + if (i > dev_if->num_out_eps) {
  86635. + dctl_data_t dctl;
  86636. + dctl.d32 =
  86637. + DWC_READ_REG32(&dev_if->dev_global_regs->dctl);
  86638. + dctl.b.cgoutnak = 1;
  86639. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dctl,
  86640. + dctl.d32);
  86641. + goto out;
  86642. + }
  86643. +
  86644. + /* Disable the endpoint */
  86645. + doepctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[i]->doepctl);
  86646. + if (doepctl.b.epena) {
  86647. + doepctl.b.epdis = 1;
  86648. + doepctl.b.snak = 1;
  86649. + }
  86650. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepctl, doepctl.d32);
  86651. + return 1;
  86652. + }
  86653. + /* We come here from Incomplete ISO OUT handler */
  86654. + if (dev_if->isoc_ep) {
  86655. + dwc_ep_t *dwc_ep = (dwc_ep_t *)dev_if->isoc_ep;
  86656. + uint32_t epnum = dwc_ep->num;
  86657. + doepint_data_t doepint;
  86658. + doepint.d32 =
  86659. + DWC_READ_REG32(&dev_if->out_ep_regs[dwc_ep->num]->doepint);
  86660. + dev_if->isoc_ep = NULL;
  86661. + doepctl.d32 =
  86662. + DWC_READ_REG32(&dev_if->out_ep_regs[epnum]->doepctl);
  86663. + DWC_PRINTF("Before disable DOEPCTL = %08x\n", doepctl.d32);
  86664. + if (doepctl.b.epena) {
  86665. + doepctl.b.epdis = 1;
  86666. + doepctl.b.snak = 1;
  86667. + }
  86668. + DWC_WRITE_REG32(&dev_if->out_ep_regs[epnum]->doepctl,
  86669. + doepctl.d32);
  86670. + return 1;
  86671. + } else
  86672. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n",
  86673. + "Global OUT NAK Effective\n");
  86674. +
  86675. +out:
  86676. + /* Clear interrupt */
  86677. + gintsts.d32 = 0;
  86678. + gintsts.b.goutnakeff = 1;
  86679. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  86680. + gintsts.d32);
  86681. +
  86682. + return 1;
  86683. +}
  86684. +
  86685. +/**
  86686. + * PCD interrupt handler.
  86687. + *
  86688. + * The PCD handles the device interrupts. Many conditions can cause a
  86689. + * device interrupt. When an interrupt occurs, the device interrupt
  86690. + * service routine determines the cause of the interrupt and
  86691. + * dispatches handling to the appropriate function. These interrupt
  86692. + * handling functions are described below.
  86693. + *
  86694. + * All interrupt registers are processed from LSB to MSB.
  86695. + *
  86696. + */
  86697. +int32_t dwc_otg_pcd_handle_intr(dwc_otg_pcd_t * pcd)
  86698. +{
  86699. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  86700. +#ifdef VERBOSE
  86701. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  86702. +#endif
  86703. + gintsts_data_t gintr_status;
  86704. + int32_t retval = 0;
  86705. +
  86706. + /* Exit from ISR if core is hibernated */
  86707. + if (core_if->hibernation_suspend == 1) {
  86708. + return retval;
  86709. + }
  86710. +#ifdef VERBOSE
  86711. + DWC_DEBUGPL(DBG_ANY, "%s() gintsts=%08x gintmsk=%08x\n",
  86712. + __func__,
  86713. + DWC_READ_REG32(&global_regs->gintsts),
  86714. + DWC_READ_REG32(&global_regs->gintmsk));
  86715. +#endif
  86716. +
  86717. + if (dwc_otg_is_device_mode(core_if)) {
  86718. + DWC_SPINLOCK(pcd->lock);
  86719. +#ifdef VERBOSE
  86720. + DWC_DEBUGPL(DBG_PCDV, "%s() gintsts=%08x gintmsk=%08x\n",
  86721. + __func__,
  86722. + DWC_READ_REG32(&global_regs->gintsts),
  86723. + DWC_READ_REG32(&global_regs->gintmsk));
  86724. +#endif
  86725. +
  86726. + gintr_status.d32 = dwc_otg_read_core_intr(core_if);
  86727. +
  86728. + DWC_DEBUGPL(DBG_PCDV, "%s: gintsts&gintmsk=%08x\n",
  86729. + __func__, gintr_status.d32);
  86730. +
  86731. + if (gintr_status.b.sofintr) {
  86732. + retval |= dwc_otg_pcd_handle_sof_intr(pcd);
  86733. + }
  86734. + if (gintr_status.b.rxstsqlvl) {
  86735. + retval |=
  86736. + dwc_otg_pcd_handle_rx_status_q_level_intr(pcd);
  86737. + }
  86738. + if (gintr_status.b.nptxfempty) {
  86739. + retval |= dwc_otg_pcd_handle_np_tx_fifo_empty_intr(pcd);
  86740. + }
  86741. + if (gintr_status.b.goutnakeff) {
  86742. + retval |= dwc_otg_pcd_handle_out_nak_effective(pcd);
  86743. + }
  86744. + if (gintr_status.b.i2cintr) {
  86745. + retval |= dwc_otg_pcd_handle_i2c_intr(pcd);
  86746. + }
  86747. + if (gintr_status.b.erlysuspend) {
  86748. + retval |= dwc_otg_pcd_handle_early_suspend_intr(pcd);
  86749. + }
  86750. + if (gintr_status.b.usbreset) {
  86751. + retval |= dwc_otg_pcd_handle_usb_reset_intr(pcd);
  86752. + }
  86753. + if (gintr_status.b.enumdone) {
  86754. + retval |= dwc_otg_pcd_handle_enum_done_intr(pcd);
  86755. + }
  86756. + if (gintr_status.b.isooutdrop) {
  86757. + retval |=
  86758. + dwc_otg_pcd_handle_isoc_out_packet_dropped_intr
  86759. + (pcd);
  86760. + }
  86761. + if (gintr_status.b.eopframe) {
  86762. + retval |=
  86763. + dwc_otg_pcd_handle_end_periodic_frame_intr(pcd);
  86764. + }
  86765. + if (gintr_status.b.inepint) {
  86766. + if (!core_if->multiproc_int_enable) {
  86767. + retval |= dwc_otg_pcd_handle_in_ep_intr(pcd);
  86768. + }
  86769. + }
  86770. + if (gintr_status.b.outepintr) {
  86771. + if (!core_if->multiproc_int_enable) {
  86772. + retval |= dwc_otg_pcd_handle_out_ep_intr(pcd);
  86773. + }
  86774. + }
  86775. + if (gintr_status.b.epmismatch) {
  86776. + retval |= dwc_otg_pcd_handle_ep_mismatch_intr(pcd);
  86777. + }
  86778. + if (gintr_status.b.fetsusp) {
  86779. + retval |= dwc_otg_pcd_handle_ep_fetsusp_intr(pcd);
  86780. + }
  86781. + if (gintr_status.b.ginnakeff) {
  86782. + retval |= dwc_otg_pcd_handle_in_nak_effective(pcd);
  86783. + }
  86784. + if (gintr_status.b.incomplisoin) {
  86785. + retval |=
  86786. + dwc_otg_pcd_handle_incomplete_isoc_in_intr(pcd);
  86787. + }
  86788. + if (gintr_status.b.incomplisoout) {
  86789. + retval |=
  86790. + dwc_otg_pcd_handle_incomplete_isoc_out_intr(pcd);
  86791. + }
  86792. +
  86793. + /* In MPI mode Device Endpoints interrupts are asserted
  86794. + * without setting outepintr and inepint bits set, so these
  86795. + * Interrupt handlers are called without checking these bit-fields
  86796. + */
  86797. + if (core_if->multiproc_int_enable) {
  86798. + retval |= dwc_otg_pcd_handle_in_ep_intr(pcd);
  86799. + retval |= dwc_otg_pcd_handle_out_ep_intr(pcd);
  86800. + }
  86801. +#ifdef VERBOSE
  86802. + DWC_DEBUGPL(DBG_PCDV, "%s() gintsts=%0x\n", __func__,
  86803. + DWC_READ_REG32(&global_regs->gintsts));
  86804. +#endif
  86805. + DWC_SPINUNLOCK(pcd->lock);
  86806. + }
  86807. + return retval;
  86808. +}
  86809. +
  86810. +#endif /* DWC_HOST_ONLY */
  86811. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c
  86812. --- linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c 1970-01-01 01:00:00.000000000 +0100
  86813. +++ linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c 2014-02-17 22:41:01.000000000 +0100
  86814. @@ -0,0 +1,1358 @@
  86815. + /* ==========================================================================
  86816. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd_linux.c $
  86817. + * $Revision: #21 $
  86818. + * $Date: 2012/08/10 $
  86819. + * $Change: 2047372 $
  86820. + *
  86821. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  86822. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  86823. + * otherwise expressly agreed to in writing between Synopsys and you.
  86824. + *
  86825. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  86826. + * any End User Software License Agreement or Agreement for Licensed Product
  86827. + * with Synopsys or any supplement thereto. You are permitted to use and
  86828. + * redistribute this Software in source and binary forms, with or without
  86829. + * modification, provided that redistributions of source code must retain this
  86830. + * notice. You may not view, use, disclose, copy or distribute this file or
  86831. + * any information contained herein except pursuant to this license grant from
  86832. + * Synopsys. If you do not agree with this notice, including the disclaimer
  86833. + * below, then you are not authorized to use the Software.
  86834. + *
  86835. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  86836. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  86837. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  86838. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  86839. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  86840. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  86841. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  86842. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  86843. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  86844. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  86845. + * DAMAGE.
  86846. + * ========================================================================== */
  86847. +#ifndef DWC_HOST_ONLY
  86848. +
  86849. +/** @file
  86850. + * This file implements the Peripheral Controller Driver.
  86851. + *
  86852. + * The Peripheral Controller Driver (PCD) is responsible for
  86853. + * translating requests from the Function Driver into the appropriate
  86854. + * actions on the DWC_otg controller. It isolates the Function Driver
  86855. + * from the specifics of the controller by providing an API to the
  86856. + * Function Driver.
  86857. + *
  86858. + * The Peripheral Controller Driver for Linux will implement the
  86859. + * Gadget API, so that the existing Gadget drivers can be used.
  86860. + * (Gadget Driver is the Linux terminology for a Function Driver.)
  86861. + *
  86862. + * The Linux Gadget API is defined in the header file
  86863. + * <code><linux/usb_gadget.h></code>. The USB EP operations API is
  86864. + * defined in the structure <code>usb_ep_ops</code> and the USB
  86865. + * Controller API is defined in the structure
  86866. + * <code>usb_gadget_ops</code>.
  86867. + *
  86868. + */
  86869. +
  86870. +#include "dwc_otg_os_dep.h"
  86871. +#include "dwc_otg_pcd_if.h"
  86872. +#include "dwc_otg_pcd.h"
  86873. +#include "dwc_otg_driver.h"
  86874. +#include "dwc_otg_dbg.h"
  86875. +
  86876. +static struct gadget_wrapper {
  86877. + dwc_otg_pcd_t *pcd;
  86878. +
  86879. + struct usb_gadget gadget;
  86880. + struct usb_gadget_driver *driver;
  86881. +
  86882. + struct usb_ep ep0;
  86883. + struct usb_ep in_ep[16];
  86884. + struct usb_ep out_ep[16];
  86885. +
  86886. +} *gadget_wrapper;
  86887. +
  86888. +/* Display the contents of the buffer */
  86889. +extern void dump_msg(const u8 * buf, unsigned int length);
  86890. +/**
  86891. + * Get the dwc_otg_pcd_ep_t* from usb_ep* pointer - NULL in case
  86892. + * if the endpoint is not found
  86893. + */
  86894. +static struct dwc_otg_pcd_ep *ep_from_handle(dwc_otg_pcd_t * pcd, void *handle)
  86895. +{
  86896. + int i;
  86897. + if (pcd->ep0.priv == handle) {
  86898. + return &pcd->ep0;
  86899. + }
  86900. +
  86901. + for (i = 0; i < MAX_EPS_CHANNELS - 1; i++) {
  86902. + if (pcd->in_ep[i].priv == handle)
  86903. + return &pcd->in_ep[i];
  86904. + if (pcd->out_ep[i].priv == handle)
  86905. + return &pcd->out_ep[i];
  86906. + }
  86907. +
  86908. + return NULL;
  86909. +}
  86910. +
  86911. +/* USB Endpoint Operations */
  86912. +/*
  86913. + * The following sections briefly describe the behavior of the Gadget
  86914. + * API endpoint operations implemented in the DWC_otg driver
  86915. + * software. Detailed descriptions of the generic behavior of each of
  86916. + * these functions can be found in the Linux header file
  86917. + * include/linux/usb_gadget.h.
  86918. + *
  86919. + * The Gadget API provides wrapper functions for each of the function
  86920. + * pointers defined in usb_ep_ops. The Gadget Driver calls the wrapper
  86921. + * function, which then calls the underlying PCD function. The
  86922. + * following sections are named according to the wrapper
  86923. + * functions. Within each section, the corresponding DWC_otg PCD
  86924. + * function name is specified.
  86925. + *
  86926. + */
  86927. +
  86928. +/**
  86929. + * This function is called by the Gadget Driver for each EP to be
  86930. + * configured for the current configuration (SET_CONFIGURATION).
  86931. + *
  86932. + * This function initializes the dwc_otg_ep_t data structure, and then
  86933. + * calls dwc_otg_ep_activate.
  86934. + */
  86935. +static int ep_enable(struct usb_ep *usb_ep,
  86936. + const struct usb_endpoint_descriptor *ep_desc)
  86937. +{
  86938. + int retval;
  86939. +
  86940. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p)\n", __func__, usb_ep, ep_desc);
  86941. +
  86942. + if (!usb_ep || !ep_desc || ep_desc->bDescriptorType != USB_DT_ENDPOINT) {
  86943. + DWC_WARN("%s, bad ep or descriptor\n", __func__);
  86944. + return -EINVAL;
  86945. + }
  86946. + if (usb_ep == &gadget_wrapper->ep0) {
  86947. + DWC_WARN("%s, bad ep(0)\n", __func__);
  86948. + return -EINVAL;
  86949. + }
  86950. +
  86951. + /* Check FIFO size? */
  86952. + if (!ep_desc->wMaxPacketSize) {
  86953. + DWC_WARN("%s, bad %s maxpacket\n", __func__, usb_ep->name);
  86954. + return -ERANGE;
  86955. + }
  86956. +
  86957. + if (!gadget_wrapper->driver ||
  86958. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  86959. + DWC_WARN("%s, bogus device state\n", __func__);
  86960. + return -ESHUTDOWN;
  86961. + }
  86962. +
  86963. + /* Delete after check - MAS */
  86964. +#if 0
  86965. + nat = (uint32_t) ep_desc->wMaxPacketSize;
  86966. + printk(KERN_ALERT "%s: nat (before) =%d\n", __func__, nat);
  86967. + nat = (nat >> 11) & 0x03;
  86968. + printk(KERN_ALERT "%s: nat (after) =%d\n", __func__, nat);
  86969. +#endif
  86970. + retval = dwc_otg_pcd_ep_enable(gadget_wrapper->pcd,
  86971. + (const uint8_t *)ep_desc,
  86972. + (void *)usb_ep);
  86973. + if (retval) {
  86974. + DWC_WARN("dwc_otg_pcd_ep_enable failed\n");
  86975. + return -EINVAL;
  86976. + }
  86977. +
  86978. + usb_ep->maxpacket = le16_to_cpu(ep_desc->wMaxPacketSize);
  86979. +
  86980. + return 0;
  86981. +}
  86982. +
  86983. +/**
  86984. + * This function is called when an EP is disabled due to disconnect or
  86985. + * change in configuration. Any pending requests will terminate with a
  86986. + * status of -ESHUTDOWN.
  86987. + *
  86988. + * This function modifies the dwc_otg_ep_t data structure for this EP,
  86989. + * and then calls dwc_otg_ep_deactivate.
  86990. + */
  86991. +static int ep_disable(struct usb_ep *usb_ep)
  86992. +{
  86993. + int retval;
  86994. +
  86995. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, usb_ep);
  86996. + if (!usb_ep) {
  86997. + DWC_DEBUGPL(DBG_PCD, "%s, %s not enabled\n", __func__,
  86998. + usb_ep ? usb_ep->name : NULL);
  86999. + return -EINVAL;
  87000. + }
  87001. +
  87002. + retval = dwc_otg_pcd_ep_disable(gadget_wrapper->pcd, usb_ep);
  87003. + if (retval) {
  87004. + retval = -EINVAL;
  87005. + }
  87006. +
  87007. + return retval;
  87008. +}
  87009. +
  87010. +/**
  87011. + * This function allocates a request object to use with the specified
  87012. + * endpoint.
  87013. + *
  87014. + * @param ep The endpoint to be used with with the request
  87015. + * @param gfp_flags the GFP_* flags to use.
  87016. + */
  87017. +static struct usb_request *dwc_otg_pcd_alloc_request(struct usb_ep *ep,
  87018. + gfp_t gfp_flags)
  87019. +{
  87020. + struct usb_request *usb_req;
  87021. +
  87022. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%d)\n", __func__, ep, gfp_flags);
  87023. + if (0 == ep) {
  87024. + DWC_WARN("%s() %s\n", __func__, "Invalid EP!\n");
  87025. + return 0;
  87026. + }
  87027. + usb_req = kmalloc(sizeof(*usb_req), gfp_flags);
  87028. + if (0 == usb_req) {
  87029. + DWC_WARN("%s() %s\n", __func__, "request allocation failed!\n");
  87030. + return 0;
  87031. + }
  87032. + memset(usb_req, 0, sizeof(*usb_req));
  87033. + usb_req->dma = DWC_DMA_ADDR_INVALID;
  87034. +
  87035. + return usb_req;
  87036. +}
  87037. +
  87038. +/**
  87039. + * This function frees a request object.
  87040. + *
  87041. + * @param ep The endpoint associated with the request
  87042. + * @param req The request being freed
  87043. + */
  87044. +static void dwc_otg_pcd_free_request(struct usb_ep *ep, struct usb_request *req)
  87045. +{
  87046. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p)\n", __func__, ep, req);
  87047. +
  87048. + if (0 == ep || 0 == req) {
  87049. + DWC_WARN("%s() %s\n", __func__,
  87050. + "Invalid ep or req argument!\n");
  87051. + return;
  87052. + }
  87053. +
  87054. + kfree(req);
  87055. +}
  87056. +
  87057. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  87058. +/**
  87059. + * This function allocates an I/O buffer to be used for a transfer
  87060. + * to/from the specified endpoint.
  87061. + *
  87062. + * @param usb_ep The endpoint to be used with with the request
  87063. + * @param bytes The desired number of bytes for the buffer
  87064. + * @param dma Pointer to the buffer's DMA address; must be valid
  87065. + * @param gfp_flags the GFP_* flags to use.
  87066. + * @return address of a new buffer or null is buffer could not be allocated.
  87067. + */
  87068. +static void *dwc_otg_pcd_alloc_buffer(struct usb_ep *usb_ep, unsigned bytes,
  87069. + dma_addr_t * dma, gfp_t gfp_flags)
  87070. +{
  87071. + void *buf;
  87072. + dwc_otg_pcd_t *pcd = 0;
  87073. +
  87074. + pcd = gadget_wrapper->pcd;
  87075. +
  87076. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%d,%p,%0x)\n", __func__, usb_ep, bytes,
  87077. + dma, gfp_flags);
  87078. +
  87079. + /* Check dword alignment */
  87080. + if ((bytes & 0x3UL) != 0) {
  87081. + DWC_WARN("%s() Buffer size is not a multiple of"
  87082. + "DWORD size (%d)", __func__, bytes);
  87083. + }
  87084. +
  87085. + buf = dma_alloc_coherent(NULL, bytes, dma, gfp_flags);
  87086. +
  87087. + /* Check dword alignment */
  87088. + if (((int)buf & 0x3UL) != 0) {
  87089. + DWC_WARN("%s() Buffer is not DWORD aligned (%p)",
  87090. + __func__, buf);
  87091. + }
  87092. +
  87093. + return buf;
  87094. +}
  87095. +
  87096. +/**
  87097. + * This function frees an I/O buffer that was allocated by alloc_buffer.
  87098. + *
  87099. + * @param usb_ep the endpoint associated with the buffer
  87100. + * @param buf address of the buffer
  87101. + * @param dma The buffer's DMA address
  87102. + * @param bytes The number of bytes of the buffer
  87103. + */
  87104. +static void dwc_otg_pcd_free_buffer(struct usb_ep *usb_ep, void *buf,
  87105. + dma_addr_t dma, unsigned bytes)
  87106. +{
  87107. + dwc_otg_pcd_t *pcd = 0;
  87108. +
  87109. + pcd = gadget_wrapper->pcd;
  87110. +
  87111. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%0x,%d)\n", __func__, buf, dma, bytes);
  87112. +
  87113. + dma_free_coherent(NULL, bytes, buf, dma);
  87114. +}
  87115. +#endif
  87116. +
  87117. +/**
  87118. + * This function is used to submit an I/O Request to an EP.
  87119. + *
  87120. + * - When the request completes the request's completion callback
  87121. + * is called to return the request to the driver.
  87122. + * - An EP, except control EPs, may have multiple requests
  87123. + * pending.
  87124. + * - Once submitted the request cannot be examined or modified.
  87125. + * - Each request is turned into one or more packets.
  87126. + * - A BULK EP can queue any amount of data; the transfer is
  87127. + * packetized.
  87128. + * - Zero length Packets are specified with the request 'zero'
  87129. + * flag.
  87130. + */
  87131. +static int ep_queue(struct usb_ep *usb_ep, struct usb_request *usb_req,
  87132. + gfp_t gfp_flags)
  87133. +{
  87134. + dwc_otg_pcd_t *pcd;
  87135. + struct dwc_otg_pcd_ep *ep = NULL;
  87136. + int retval = 0, is_isoc_ep = 0;
  87137. + dma_addr_t dma_addr = DWC_DMA_ADDR_INVALID;
  87138. +
  87139. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p,%d)\n",
  87140. + __func__, usb_ep, usb_req, gfp_flags);
  87141. +
  87142. + if (!usb_req || !usb_req->complete || !usb_req->buf) {
  87143. + DWC_WARN("bad params\n");
  87144. + return -EINVAL;
  87145. + }
  87146. +
  87147. + if (!usb_ep) {
  87148. + DWC_WARN("bad ep\n");
  87149. + return -EINVAL;
  87150. + }
  87151. +
  87152. + pcd = gadget_wrapper->pcd;
  87153. + if (!gadget_wrapper->driver ||
  87154. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  87155. + DWC_DEBUGPL(DBG_PCDV, "gadget.speed=%d\n",
  87156. + gadget_wrapper->gadget.speed);
  87157. + DWC_WARN("bogus device state\n");
  87158. + return -ESHUTDOWN;
  87159. + }
  87160. +
  87161. + DWC_DEBUGPL(DBG_PCD, "%s queue req %p, len %d buf %p\n",
  87162. + usb_ep->name, usb_req, usb_req->length, usb_req->buf);
  87163. +
  87164. + usb_req->status = -EINPROGRESS;
  87165. + usb_req->actual = 0;
  87166. +
  87167. + ep = ep_from_handle(pcd, usb_ep);
  87168. + if (ep == NULL)
  87169. + is_isoc_ep = 0;
  87170. + else
  87171. + is_isoc_ep = (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) ? 1 : 0;
  87172. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  87173. + dma_addr = usb_req->dma;
  87174. +#else
  87175. + if (GET_CORE_IF(pcd)->dma_enable) {
  87176. + dwc_otg_device_t *otg_dev = gadget_wrapper->pcd->otg_dev;
  87177. + struct device *dev = NULL;
  87178. +
  87179. + if (otg_dev != NULL)
  87180. + dev = DWC_OTG_OS_GETDEV(otg_dev->os_dep);
  87181. +
  87182. + if (usb_req->length != 0 &&
  87183. + usb_req->dma == DWC_DMA_ADDR_INVALID) {
  87184. + dma_addr = dma_map_single(dev, usb_req->buf,
  87185. + usb_req->length,
  87186. + ep->dwc_ep.is_in ?
  87187. + DMA_TO_DEVICE:
  87188. + DMA_FROM_DEVICE);
  87189. + }
  87190. + }
  87191. +#endif
  87192. +
  87193. +#ifdef DWC_UTE_PER_IO
  87194. + if (is_isoc_ep == 1) {
  87195. + retval = dwc_otg_pcd_xiso_ep_queue(pcd, usb_ep, usb_req->buf, dma_addr,
  87196. + usb_req->length, usb_req->zero, usb_req,
  87197. + gfp_flags == GFP_ATOMIC ? 1 : 0, &usb_req->ext_req);
  87198. + if (retval)
  87199. + return -EINVAL;
  87200. +
  87201. + return 0;
  87202. + }
  87203. +#endif
  87204. + retval = dwc_otg_pcd_ep_queue(pcd, usb_ep, usb_req->buf, dma_addr,
  87205. + usb_req->length, usb_req->zero, usb_req,
  87206. + gfp_flags == GFP_ATOMIC ? 1 : 0);
  87207. + if (retval) {
  87208. + return -EINVAL;
  87209. + }
  87210. +
  87211. + return 0;
  87212. +}
  87213. +
  87214. +/**
  87215. + * This function cancels an I/O request from an EP.
  87216. + */
  87217. +static int ep_dequeue(struct usb_ep *usb_ep, struct usb_request *usb_req)
  87218. +{
  87219. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p)\n", __func__, usb_ep, usb_req);
  87220. +
  87221. + if (!usb_ep || !usb_req) {
  87222. + DWC_WARN("bad argument\n");
  87223. + return -EINVAL;
  87224. + }
  87225. + if (!gadget_wrapper->driver ||
  87226. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  87227. + DWC_WARN("bogus device state\n");
  87228. + return -ESHUTDOWN;
  87229. + }
  87230. + if (dwc_otg_pcd_ep_dequeue(gadget_wrapper->pcd, usb_ep, usb_req)) {
  87231. + return -EINVAL;
  87232. + }
  87233. +
  87234. + return 0;
  87235. +}
  87236. +
  87237. +/**
  87238. + * usb_ep_set_halt stalls an endpoint.
  87239. + *
  87240. + * usb_ep_clear_halt clears an endpoint halt and resets its data
  87241. + * toggle.
  87242. + *
  87243. + * Both of these functions are implemented with the same underlying
  87244. + * function. The behavior depends on the value argument.
  87245. + *
  87246. + * @param[in] usb_ep the Endpoint to halt or clear halt.
  87247. + * @param[in] value
  87248. + * - 0 means clear_halt.
  87249. + * - 1 means set_halt,
  87250. + * - 2 means clear stall lock flag.
  87251. + * - 3 means set stall lock flag.
  87252. + */
  87253. +static int ep_halt(struct usb_ep *usb_ep, int value)
  87254. +{
  87255. + int retval = 0;
  87256. +
  87257. + DWC_DEBUGPL(DBG_PCD, "HALT %s %d\n", usb_ep->name, value);
  87258. +
  87259. + if (!usb_ep) {
  87260. + DWC_WARN("bad ep\n");
  87261. + return -EINVAL;
  87262. + }
  87263. +
  87264. + retval = dwc_otg_pcd_ep_halt(gadget_wrapper->pcd, usb_ep, value);
  87265. + if (retval == -DWC_E_AGAIN) {
  87266. + return -EAGAIN;
  87267. + } else if (retval) {
  87268. + retval = -EINVAL;
  87269. + }
  87270. +
  87271. + return retval;
  87272. +}
  87273. +
  87274. +//#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30))
  87275. +#if 0
  87276. +/**
  87277. + * ep_wedge: sets the halt feature and ignores clear requests
  87278. + *
  87279. + * @usb_ep: the endpoint being wedged
  87280. + *
  87281. + * Use this to stall an endpoint and ignore CLEAR_FEATURE(HALT_ENDPOINT)
  87282. + * requests. If the gadget driver clears the halt status, it will
  87283. + * automatically unwedge the endpoint.
  87284. + *
  87285. + * Returns zero on success, else negative errno. *
  87286. + * Check usb_ep_set_wedge() at "usb_gadget.h" for details
  87287. + */
  87288. +static int ep_wedge(struct usb_ep *usb_ep)
  87289. +{
  87290. + int retval = 0;
  87291. +
  87292. + DWC_DEBUGPL(DBG_PCD, "WEDGE %s\n", usb_ep->name);
  87293. +
  87294. + if (!usb_ep) {
  87295. + DWC_WARN("bad ep\n");
  87296. + return -EINVAL;
  87297. + }
  87298. +
  87299. + retval = dwc_otg_pcd_ep_wedge(gadget_wrapper->pcd, usb_ep);
  87300. + if (retval == -DWC_E_AGAIN) {
  87301. + retval = -EAGAIN;
  87302. + } else if (retval) {
  87303. + retval = -EINVAL;
  87304. + }
  87305. +
  87306. + return retval;
  87307. +}
  87308. +#endif
  87309. +
  87310. +#ifdef DWC_EN_ISOC
  87311. +/**
  87312. + * This function is used to submit an ISOC Transfer Request to an EP.
  87313. + *
  87314. + * - Every time a sync period completes the request's completion callback
  87315. + * is called to provide data to the gadget driver.
  87316. + * - Once submitted the request cannot be modified.
  87317. + * - Each request is turned into periodic data packets untill ISO
  87318. + * Transfer is stopped..
  87319. + */
  87320. +static int iso_ep_start(struct usb_ep *usb_ep, struct usb_iso_request *req,
  87321. + gfp_t gfp_flags)
  87322. +{
  87323. + int retval = 0;
  87324. +
  87325. + if (!req || !req->process_buffer || !req->buf0 || !req->buf1) {
  87326. + DWC_WARN("bad params\n");
  87327. + return -EINVAL;
  87328. + }
  87329. +
  87330. + if (!usb_ep) {
  87331. + DWC_PRINTF("bad params\n");
  87332. + return -EINVAL;
  87333. + }
  87334. +
  87335. + req->status = -EINPROGRESS;
  87336. +
  87337. + retval =
  87338. + dwc_otg_pcd_iso_ep_start(gadget_wrapper->pcd, usb_ep, req->buf0,
  87339. + req->buf1, req->dma0, req->dma1,
  87340. + req->sync_frame, req->data_pattern_frame,
  87341. + req->data_per_frame,
  87342. + req->
  87343. + flags & USB_REQ_ISO_ASAP ? -1 :
  87344. + req->start_frame, req->buf_proc_intrvl,
  87345. + req, gfp_flags == GFP_ATOMIC ? 1 : 0);
  87346. +
  87347. + if (retval) {
  87348. + return -EINVAL;
  87349. + }
  87350. +
  87351. + return retval;
  87352. +}
  87353. +
  87354. +/**
  87355. + * This function stops ISO EP Periodic Data Transfer.
  87356. + */
  87357. +static int iso_ep_stop(struct usb_ep *usb_ep, struct usb_iso_request *req)
  87358. +{
  87359. + int retval = 0;
  87360. + if (!usb_ep) {
  87361. + DWC_WARN("bad ep\n");
  87362. + }
  87363. +
  87364. + if (!gadget_wrapper->driver ||
  87365. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  87366. + DWC_DEBUGPL(DBG_PCDV, "gadget.speed=%d\n",
  87367. + gadget_wrapper->gadget.speed);
  87368. + DWC_WARN("bogus device state\n");
  87369. + }
  87370. +
  87371. + dwc_otg_pcd_iso_ep_stop(gadget_wrapper->pcd, usb_ep, req);
  87372. + if (retval) {
  87373. + retval = -EINVAL;
  87374. + }
  87375. +
  87376. + return retval;
  87377. +}
  87378. +
  87379. +static struct usb_iso_request *alloc_iso_request(struct usb_ep *ep,
  87380. + int packets, gfp_t gfp_flags)
  87381. +{
  87382. + struct usb_iso_request *pReq = NULL;
  87383. + uint32_t req_size;
  87384. +
  87385. + req_size = sizeof(struct usb_iso_request);
  87386. + req_size +=
  87387. + (2 * packets * (sizeof(struct usb_gadget_iso_packet_descriptor)));
  87388. +
  87389. + pReq = kmalloc(req_size, gfp_flags);
  87390. + if (!pReq) {
  87391. + DWC_WARN("Can't allocate Iso Request\n");
  87392. + return 0;
  87393. + }
  87394. + pReq->iso_packet_desc0 = (void *)(pReq + 1);
  87395. +
  87396. + pReq->iso_packet_desc1 = pReq->iso_packet_desc0 + packets;
  87397. +
  87398. + return pReq;
  87399. +}
  87400. +
  87401. +static void free_iso_request(struct usb_ep *ep, struct usb_iso_request *req)
  87402. +{
  87403. + kfree(req);
  87404. +}
  87405. +
  87406. +static struct usb_isoc_ep_ops dwc_otg_pcd_ep_ops = {
  87407. + .ep_ops = {
  87408. + .enable = ep_enable,
  87409. + .disable = ep_disable,
  87410. +
  87411. + .alloc_request = dwc_otg_pcd_alloc_request,
  87412. + .free_request = dwc_otg_pcd_free_request,
  87413. +
  87414. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  87415. + .alloc_buffer = dwc_otg_pcd_alloc_buffer,
  87416. + .free_buffer = dwc_otg_pcd_free_buffer,
  87417. +#endif
  87418. +
  87419. + .queue = ep_queue,
  87420. + .dequeue = ep_dequeue,
  87421. +
  87422. + .set_halt = ep_halt,
  87423. + .fifo_status = 0,
  87424. + .fifo_flush = 0,
  87425. + },
  87426. + .iso_ep_start = iso_ep_start,
  87427. + .iso_ep_stop = iso_ep_stop,
  87428. + .alloc_iso_request = alloc_iso_request,
  87429. + .free_iso_request = free_iso_request,
  87430. +};
  87431. +
  87432. +#else
  87433. +
  87434. + int (*enable) (struct usb_ep *ep,
  87435. + const struct usb_endpoint_descriptor *desc);
  87436. + int (*disable) (struct usb_ep *ep);
  87437. +
  87438. + struct usb_request *(*alloc_request) (struct usb_ep *ep,
  87439. + gfp_t gfp_flags);
  87440. + void (*free_request) (struct usb_ep *ep, struct usb_request *req);
  87441. +
  87442. + int (*queue) (struct usb_ep *ep, struct usb_request *req,
  87443. + gfp_t gfp_flags);
  87444. + int (*dequeue) (struct usb_ep *ep, struct usb_request *req);
  87445. +
  87446. + int (*set_halt) (struct usb_ep *ep, int value);
  87447. + int (*set_wedge) (struct usb_ep *ep);
  87448. +
  87449. + int (*fifo_status) (struct usb_ep *ep);
  87450. + void (*fifo_flush) (struct usb_ep *ep);
  87451. +static struct usb_ep_ops dwc_otg_pcd_ep_ops = {
  87452. + .enable = ep_enable,
  87453. + .disable = ep_disable,
  87454. +
  87455. + .alloc_request = dwc_otg_pcd_alloc_request,
  87456. + .free_request = dwc_otg_pcd_free_request,
  87457. +
  87458. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  87459. + .alloc_buffer = dwc_otg_pcd_alloc_buffer,
  87460. + .free_buffer = dwc_otg_pcd_free_buffer,
  87461. +#else
  87462. + /* .set_wedge = ep_wedge, */
  87463. + .set_wedge = NULL, /* uses set_halt instead */
  87464. +#endif
  87465. +
  87466. + .queue = ep_queue,
  87467. + .dequeue = ep_dequeue,
  87468. +
  87469. + .set_halt = ep_halt,
  87470. + .fifo_status = 0,
  87471. + .fifo_flush = 0,
  87472. +
  87473. +};
  87474. +
  87475. +#endif /* _EN_ISOC_ */
  87476. +/* Gadget Operations */
  87477. +/**
  87478. + * The following gadget operations will be implemented in the DWC_otg
  87479. + * PCD. Functions in the API that are not described below are not
  87480. + * implemented.
  87481. + *
  87482. + * The Gadget API provides wrapper functions for each of the function
  87483. + * pointers defined in usb_gadget_ops. The Gadget Driver calls the
  87484. + * wrapper function, which then calls the underlying PCD function. The
  87485. + * following sections are named according to the wrapper functions
  87486. + * (except for ioctl, which doesn't have a wrapper function). Within
  87487. + * each section, the corresponding DWC_otg PCD function name is
  87488. + * specified.
  87489. + *
  87490. + */
  87491. +
  87492. +/**
  87493. + *Gets the USB Frame number of the last SOF.
  87494. + */
  87495. +static int get_frame_number(struct usb_gadget *gadget)
  87496. +{
  87497. + struct gadget_wrapper *d;
  87498. +
  87499. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, gadget);
  87500. +
  87501. + if (gadget == 0) {
  87502. + return -ENODEV;
  87503. + }
  87504. +
  87505. + d = container_of(gadget, struct gadget_wrapper, gadget);
  87506. + return dwc_otg_pcd_get_frame_number(d->pcd);
  87507. +}
  87508. +
  87509. +#ifdef CONFIG_USB_DWC_OTG_LPM
  87510. +static int test_lpm_enabled(struct usb_gadget *gadget)
  87511. +{
  87512. + struct gadget_wrapper *d;
  87513. +
  87514. + d = container_of(gadget, struct gadget_wrapper, gadget);
  87515. +
  87516. + return dwc_otg_pcd_is_lpm_enabled(d->pcd);
  87517. +}
  87518. +#endif
  87519. +
  87520. +/**
  87521. + * Initiates Session Request Protocol (SRP) to wakeup the host if no
  87522. + * session is in progress. If a session is already in progress, but
  87523. + * the device is suspended, remote wakeup signaling is started.
  87524. + *
  87525. + */
  87526. +static int wakeup(struct usb_gadget *gadget)
  87527. +{
  87528. + struct gadget_wrapper *d;
  87529. +
  87530. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, gadget);
  87531. +
  87532. + if (gadget == 0) {
  87533. + return -ENODEV;
  87534. + } else {
  87535. + d = container_of(gadget, struct gadget_wrapper, gadget);
  87536. + }
  87537. + dwc_otg_pcd_wakeup(d->pcd);
  87538. + return 0;
  87539. +}
  87540. +
  87541. +static const struct usb_gadget_ops dwc_otg_pcd_ops = {
  87542. + .get_frame = get_frame_number,
  87543. + .wakeup = wakeup,
  87544. +#ifdef CONFIG_USB_DWC_OTG_LPM
  87545. + .lpm_support = test_lpm_enabled,
  87546. +#endif
  87547. + // current versions must always be self-powered
  87548. +};
  87549. +
  87550. +static int _setup(dwc_otg_pcd_t * pcd, uint8_t * bytes)
  87551. +{
  87552. + int retval = -DWC_E_NOT_SUPPORTED;
  87553. + if (gadget_wrapper->driver && gadget_wrapper->driver->setup) {
  87554. + retval = gadget_wrapper->driver->setup(&gadget_wrapper->gadget,
  87555. + (struct usb_ctrlrequest
  87556. + *)bytes);
  87557. + }
  87558. +
  87559. + if (retval == -ENOTSUPP) {
  87560. + retval = -DWC_E_NOT_SUPPORTED;
  87561. + } else if (retval < 0) {
  87562. + retval = -DWC_E_INVALID;
  87563. + }
  87564. +
  87565. + return retval;
  87566. +}
  87567. +
  87568. +#ifdef DWC_EN_ISOC
  87569. +static int _isoc_complete(dwc_otg_pcd_t * pcd, void *ep_handle,
  87570. + void *req_handle, int proc_buf_num)
  87571. +{
  87572. + int i, packet_count;
  87573. + struct usb_gadget_iso_packet_descriptor *iso_packet = 0;
  87574. + struct usb_iso_request *iso_req = req_handle;
  87575. +
  87576. + if (proc_buf_num) {
  87577. + iso_packet = iso_req->iso_packet_desc1;
  87578. + } else {
  87579. + iso_packet = iso_req->iso_packet_desc0;
  87580. + }
  87581. + packet_count =
  87582. + dwc_otg_pcd_get_iso_packet_count(pcd, ep_handle, req_handle);
  87583. + for (i = 0; i < packet_count; ++i) {
  87584. + int status;
  87585. + int actual;
  87586. + int offset;
  87587. + dwc_otg_pcd_get_iso_packet_params(pcd, ep_handle, req_handle,
  87588. + i, &status, &actual, &offset);
  87589. + switch (status) {
  87590. + case -DWC_E_NO_DATA:
  87591. + status = -ENODATA;
  87592. + break;
  87593. + default:
  87594. + if (status) {
  87595. + DWC_PRINTF("unknown status in isoc packet\n");
  87596. + }
  87597. +
  87598. + }
  87599. + iso_packet[i].status = status;
  87600. + iso_packet[i].offset = offset;
  87601. + iso_packet[i].actual_length = actual;
  87602. + }
  87603. +
  87604. + iso_req->status = 0;
  87605. + iso_req->process_buffer(ep_handle, iso_req);
  87606. +
  87607. + return 0;
  87608. +}
  87609. +#endif /* DWC_EN_ISOC */
  87610. +
  87611. +#ifdef DWC_UTE_PER_IO
  87612. +/**
  87613. + * Copy the contents of the extended request to the Linux usb_request's
  87614. + * extended part and call the gadget's completion.
  87615. + *
  87616. + * @param pcd Pointer to the pcd structure
  87617. + * @param ep_handle Void pointer to the usb_ep structure
  87618. + * @param req_handle Void pointer to the usb_request structure
  87619. + * @param status Request status returned from the portable logic
  87620. + * @param ereq_port Void pointer to the extended request structure
  87621. + * created in the the portable part that contains the
  87622. + * results of the processed iso packets.
  87623. + */
  87624. +static int _xisoc_complete(dwc_otg_pcd_t * pcd, void *ep_handle,
  87625. + void *req_handle, int32_t status, void *ereq_port)
  87626. +{
  87627. + struct dwc_ute_iso_req_ext *ereqorg = NULL;
  87628. + struct dwc_iso_xreq_port *ereqport = NULL;
  87629. + struct dwc_ute_iso_packet_descriptor *desc_org = NULL;
  87630. + int i;
  87631. + struct usb_request *req;
  87632. + //struct dwc_ute_iso_packet_descriptor *
  87633. + //int status = 0;
  87634. +
  87635. + req = (struct usb_request *)req_handle;
  87636. + ereqorg = &req->ext_req;
  87637. + ereqport = (struct dwc_iso_xreq_port *)ereq_port;
  87638. + desc_org = ereqorg->per_io_frame_descs;
  87639. +
  87640. + if (req && req->complete) {
  87641. + /* Copy the request data from the portable logic to our request */
  87642. + for (i = 0; i < ereqport->pio_pkt_count; i++) {
  87643. + desc_org[i].actual_length =
  87644. + ereqport->per_io_frame_descs[i].actual_length;
  87645. + desc_org[i].status =
  87646. + ereqport->per_io_frame_descs[i].status;
  87647. + }
  87648. +
  87649. + switch (status) {
  87650. + case -DWC_E_SHUTDOWN:
  87651. + req->status = -ESHUTDOWN;
  87652. + break;
  87653. + case -DWC_E_RESTART:
  87654. + req->status = -ECONNRESET;
  87655. + break;
  87656. + case -DWC_E_INVALID:
  87657. + req->status = -EINVAL;
  87658. + break;
  87659. + case -DWC_E_TIMEOUT:
  87660. + req->status = -ETIMEDOUT;
  87661. + break;
  87662. + default:
  87663. + req->status = status;
  87664. + }
  87665. +
  87666. + /* And call the gadget's completion */
  87667. + req->complete(ep_handle, req);
  87668. + }
  87669. +
  87670. + return 0;
  87671. +}
  87672. +#endif /* DWC_UTE_PER_IO */
  87673. +
  87674. +static int _complete(dwc_otg_pcd_t * pcd, void *ep_handle,
  87675. + void *req_handle, int32_t status, uint32_t actual)
  87676. +{
  87677. + struct usb_request *req = (struct usb_request *)req_handle;
  87678. +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27)
  87679. + struct dwc_otg_pcd_ep *ep = NULL;
  87680. +#endif
  87681. +
  87682. + if (req && req->complete) {
  87683. + switch (status) {
  87684. + case -DWC_E_SHUTDOWN:
  87685. + req->status = -ESHUTDOWN;
  87686. + break;
  87687. + case -DWC_E_RESTART:
  87688. + req->status = -ECONNRESET;
  87689. + break;
  87690. + case -DWC_E_INVALID:
  87691. + req->status = -EINVAL;
  87692. + break;
  87693. + case -DWC_E_TIMEOUT:
  87694. + req->status = -ETIMEDOUT;
  87695. + break;
  87696. + default:
  87697. + req->status = status;
  87698. +
  87699. + }
  87700. +
  87701. + req->actual = actual;
  87702. + DWC_SPINUNLOCK(pcd->lock);
  87703. + req->complete(ep_handle, req);
  87704. + DWC_SPINLOCK(pcd->lock);
  87705. + }
  87706. +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27)
  87707. + ep = ep_from_handle(pcd, ep_handle);
  87708. + if (GET_CORE_IF(pcd)->dma_enable) {
  87709. + if (req->length != 0) {
  87710. + dwc_otg_device_t *otg_dev = gadget_wrapper->pcd->otg_dev;
  87711. + struct device *dev = NULL;
  87712. +
  87713. + if (otg_dev != NULL)
  87714. + dev = DWC_OTG_OS_GETDEV(otg_dev->os_dep);
  87715. +
  87716. + dma_unmap_single(dev, req->dma, req->length,
  87717. + ep->dwc_ep.is_in ?
  87718. + DMA_TO_DEVICE: DMA_FROM_DEVICE);
  87719. + }
  87720. + }
  87721. +#endif
  87722. +
  87723. + return 0;
  87724. +}
  87725. +
  87726. +static int _connect(dwc_otg_pcd_t * pcd, int speed)
  87727. +{
  87728. + gadget_wrapper->gadget.speed = speed;
  87729. + return 0;
  87730. +}
  87731. +
  87732. +static int _disconnect(dwc_otg_pcd_t * pcd)
  87733. +{
  87734. + if (gadget_wrapper->driver && gadget_wrapper->driver->disconnect) {
  87735. + gadget_wrapper->driver->disconnect(&gadget_wrapper->gadget);
  87736. + }
  87737. + return 0;
  87738. +}
  87739. +
  87740. +static int _resume(dwc_otg_pcd_t * pcd)
  87741. +{
  87742. + if (gadget_wrapper->driver && gadget_wrapper->driver->resume) {
  87743. + gadget_wrapper->driver->resume(&gadget_wrapper->gadget);
  87744. + }
  87745. +
  87746. + return 0;
  87747. +}
  87748. +
  87749. +static int _suspend(dwc_otg_pcd_t * pcd)
  87750. +{
  87751. + if (gadget_wrapper->driver && gadget_wrapper->driver->suspend) {
  87752. + gadget_wrapper->driver->suspend(&gadget_wrapper->gadget);
  87753. + }
  87754. + return 0;
  87755. +}
  87756. +
  87757. +/**
  87758. + * This function updates the otg values in the gadget structure.
  87759. + */
  87760. +static int _hnp_changed(dwc_otg_pcd_t * pcd)
  87761. +{
  87762. +
  87763. + if (!gadget_wrapper->gadget.is_otg)
  87764. + return 0;
  87765. +
  87766. + gadget_wrapper->gadget.b_hnp_enable = get_b_hnp_enable(pcd);
  87767. + gadget_wrapper->gadget.a_hnp_support = get_a_hnp_support(pcd);
  87768. + gadget_wrapper->gadget.a_alt_hnp_support = get_a_alt_hnp_support(pcd);
  87769. + return 0;
  87770. +}
  87771. +
  87772. +static int _reset(dwc_otg_pcd_t * pcd)
  87773. +{
  87774. + return 0;
  87775. +}
  87776. +
  87777. +#ifdef DWC_UTE_CFI
  87778. +static int _cfi_setup(dwc_otg_pcd_t * pcd, void *cfi_req)
  87779. +{
  87780. + int retval = -DWC_E_INVALID;
  87781. + if (gadget_wrapper->driver->cfi_feature_setup) {
  87782. + retval =
  87783. + gadget_wrapper->driver->
  87784. + cfi_feature_setup(&gadget_wrapper->gadget,
  87785. + (struct cfi_usb_ctrlrequest *)cfi_req);
  87786. + }
  87787. +
  87788. + return retval;
  87789. +}
  87790. +#endif
  87791. +
  87792. +static const struct dwc_otg_pcd_function_ops fops = {
  87793. + .complete = _complete,
  87794. +#ifdef DWC_EN_ISOC
  87795. + .isoc_complete = _isoc_complete,
  87796. +#endif
  87797. + .setup = _setup,
  87798. + .disconnect = _disconnect,
  87799. + .connect = _connect,
  87800. + .resume = _resume,
  87801. + .suspend = _suspend,
  87802. + .hnp_changed = _hnp_changed,
  87803. + .reset = _reset,
  87804. +#ifdef DWC_UTE_CFI
  87805. + .cfi_setup = _cfi_setup,
  87806. +#endif
  87807. +#ifdef DWC_UTE_PER_IO
  87808. + .xisoc_complete = _xisoc_complete,
  87809. +#endif
  87810. +};
  87811. +
  87812. +/**
  87813. + * This function is the top level PCD interrupt handler.
  87814. + */
  87815. +static irqreturn_t dwc_otg_pcd_irq(int irq, void *dev)
  87816. +{
  87817. + dwc_otg_pcd_t *pcd = dev;
  87818. + int32_t retval = IRQ_NONE;
  87819. +
  87820. + retval = dwc_otg_pcd_handle_intr(pcd);
  87821. + if (retval != 0) {
  87822. + S3C2410X_CLEAR_EINTPEND();
  87823. + }
  87824. + return IRQ_RETVAL(retval);
  87825. +}
  87826. +
  87827. +/**
  87828. + * This function initialized the usb_ep structures to there default
  87829. + * state.
  87830. + *
  87831. + * @param d Pointer on gadget_wrapper.
  87832. + */
  87833. +void gadget_add_eps(struct gadget_wrapper *d)
  87834. +{
  87835. + static const char *names[] = {
  87836. +
  87837. + "ep0",
  87838. + "ep1in",
  87839. + "ep2in",
  87840. + "ep3in",
  87841. + "ep4in",
  87842. + "ep5in",
  87843. + "ep6in",
  87844. + "ep7in",
  87845. + "ep8in",
  87846. + "ep9in",
  87847. + "ep10in",
  87848. + "ep11in",
  87849. + "ep12in",
  87850. + "ep13in",
  87851. + "ep14in",
  87852. + "ep15in",
  87853. + "ep1out",
  87854. + "ep2out",
  87855. + "ep3out",
  87856. + "ep4out",
  87857. + "ep5out",
  87858. + "ep6out",
  87859. + "ep7out",
  87860. + "ep8out",
  87861. + "ep9out",
  87862. + "ep10out",
  87863. + "ep11out",
  87864. + "ep12out",
  87865. + "ep13out",
  87866. + "ep14out",
  87867. + "ep15out"
  87868. + };
  87869. +
  87870. + int i;
  87871. + struct usb_ep *ep;
  87872. + int8_t dev_endpoints;
  87873. +
  87874. + DWC_DEBUGPL(DBG_PCDV, "%s\n", __func__);
  87875. +
  87876. + INIT_LIST_HEAD(&d->gadget.ep_list);
  87877. + d->gadget.ep0 = &d->ep0;
  87878. + d->gadget.speed = USB_SPEED_UNKNOWN;
  87879. +
  87880. + INIT_LIST_HEAD(&d->gadget.ep0->ep_list);
  87881. +
  87882. + /**
  87883. + * Initialize the EP0 structure.
  87884. + */
  87885. + ep = &d->ep0;
  87886. +
  87887. + /* Init the usb_ep structure. */
  87888. + ep->name = names[0];
  87889. + ep->ops = (struct usb_ep_ops *)&dwc_otg_pcd_ep_ops;
  87890. +
  87891. + /**
  87892. + * @todo NGS: What should the max packet size be set to
  87893. + * here? Before EP type is set?
  87894. + */
  87895. + ep->maxpacket = MAX_PACKET_SIZE;
  87896. + dwc_otg_pcd_ep_enable(d->pcd, NULL, ep);
  87897. +
  87898. + list_add_tail(&ep->ep_list, &d->gadget.ep_list);
  87899. +
  87900. + /**
  87901. + * Initialize the EP structures.
  87902. + */
  87903. + dev_endpoints = d->pcd->core_if->dev_if->num_in_eps;
  87904. +
  87905. + for (i = 0; i < dev_endpoints; i++) {
  87906. + ep = &d->in_ep[i];
  87907. +
  87908. + /* Init the usb_ep structure. */
  87909. + ep->name = names[d->pcd->in_ep[i].dwc_ep.num];
  87910. + ep->ops = (struct usb_ep_ops *)&dwc_otg_pcd_ep_ops;
  87911. +
  87912. + /**
  87913. + * @todo NGS: What should the max packet size be set to
  87914. + * here? Before EP type is set?
  87915. + */
  87916. + ep->maxpacket = MAX_PACKET_SIZE;
  87917. + list_add_tail(&ep->ep_list, &d->gadget.ep_list);
  87918. + }
  87919. +
  87920. + dev_endpoints = d->pcd->core_if->dev_if->num_out_eps;
  87921. +
  87922. + for (i = 0; i < dev_endpoints; i++) {
  87923. + ep = &d->out_ep[i];
  87924. +
  87925. + /* Init the usb_ep structure. */
  87926. + ep->name = names[15 + d->pcd->out_ep[i].dwc_ep.num];
  87927. + ep->ops = (struct usb_ep_ops *)&dwc_otg_pcd_ep_ops;
  87928. +
  87929. + /**
  87930. + * @todo NGS: What should the max packet size be set to
  87931. + * here? Before EP type is set?
  87932. + */
  87933. + ep->maxpacket = MAX_PACKET_SIZE;
  87934. +
  87935. + list_add_tail(&ep->ep_list, &d->gadget.ep_list);
  87936. + }
  87937. +
  87938. + /* remove ep0 from the list. There is a ep0 pointer. */
  87939. + list_del_init(&d->ep0.ep_list);
  87940. +
  87941. + d->ep0.maxpacket = MAX_EP0_SIZE;
  87942. +}
  87943. +
  87944. +/**
  87945. + * This function releases the Gadget device.
  87946. + * required by device_unregister().
  87947. + *
  87948. + * @todo Should this do something? Should it free the PCD?
  87949. + */
  87950. +static void dwc_otg_pcd_gadget_release(struct device *dev)
  87951. +{
  87952. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, dev);
  87953. +}
  87954. +
  87955. +static struct gadget_wrapper *alloc_wrapper(dwc_bus_dev_t *_dev)
  87956. +{
  87957. + static char pcd_name[] = "dwc_otg_pcd";
  87958. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  87959. + struct gadget_wrapper *d;
  87960. + int retval;
  87961. +
  87962. + d = DWC_ALLOC(sizeof(*d));
  87963. + if (d == NULL) {
  87964. + return NULL;
  87965. + }
  87966. +
  87967. + memset(d, 0, sizeof(*d));
  87968. +
  87969. + d->gadget.name = pcd_name;
  87970. + d->pcd = otg_dev->pcd;
  87971. +
  87972. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
  87973. + strcpy(d->gadget.dev.bus_id, "gadget");
  87974. +#else
  87975. + dev_set_name(&d->gadget.dev, "%s", "gadget");
  87976. +#endif
  87977. +
  87978. + d->gadget.dev.parent = &_dev->dev;
  87979. + d->gadget.dev.release = dwc_otg_pcd_gadget_release;
  87980. + d->gadget.ops = &dwc_otg_pcd_ops;
  87981. + d->gadget.max_speed = dwc_otg_pcd_is_dualspeed(otg_dev->pcd) ? USB_SPEED_HIGH:USB_SPEED_FULL;
  87982. + d->gadget.is_otg = dwc_otg_pcd_is_otg(otg_dev->pcd);
  87983. +
  87984. + d->driver = 0;
  87985. + /* Register the gadget device */
  87986. + retval = device_register(&d->gadget.dev);
  87987. + if (retval != 0) {
  87988. + DWC_ERROR("device_register failed\n");
  87989. + DWC_FREE(d);
  87990. + return NULL;
  87991. + }
  87992. +
  87993. + return d;
  87994. +}
  87995. +
  87996. +static void free_wrapper(struct gadget_wrapper *d)
  87997. +{
  87998. + if (d->driver) {
  87999. + /* should have been done already by driver model core */
  88000. + DWC_WARN("driver '%s' is still registered\n",
  88001. + d->driver->driver.name);
  88002. + usb_gadget_unregister_driver(d->driver);
  88003. + }
  88004. +
  88005. + device_unregister(&d->gadget.dev);
  88006. + DWC_FREE(d);
  88007. +}
  88008. +
  88009. +/**
  88010. + * This function initialized the PCD portion of the driver.
  88011. + *
  88012. + */
  88013. +int pcd_init(dwc_bus_dev_t *_dev)
  88014. +{
  88015. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  88016. + int retval = 0;
  88017. +
  88018. + DWC_DEBUGPL(DBG_PCDV, "%s(%p) otg_dev=%p\n", __func__, _dev, otg_dev);
  88019. +
  88020. + otg_dev->pcd = dwc_otg_pcd_init(otg_dev->core_if);
  88021. +
  88022. + if (!otg_dev->pcd) {
  88023. + DWC_ERROR("dwc_otg_pcd_init failed\n");
  88024. + return -ENOMEM;
  88025. + }
  88026. +
  88027. + otg_dev->pcd->otg_dev = otg_dev;
  88028. + gadget_wrapper = alloc_wrapper(_dev);
  88029. +
  88030. + /*
  88031. + * Initialize EP structures
  88032. + */
  88033. + gadget_add_eps(gadget_wrapper);
  88034. + /*
  88035. + * Setup interupt handler
  88036. + */
  88037. +#ifdef PLATFORM_INTERFACE
  88038. + DWC_DEBUGPL(DBG_ANY, "registering handler for irq%d\n",
  88039. + platform_get_irq(_dev, 0));
  88040. + retval = request_irq(platform_get_irq(_dev, 0), dwc_otg_pcd_irq,
  88041. + IRQF_SHARED, gadget_wrapper->gadget.name,
  88042. + otg_dev->pcd);
  88043. + if (retval != 0) {
  88044. + DWC_ERROR("request of irq%d failed\n",
  88045. + platform_get_irq(_dev, 0));
  88046. + free_wrapper(gadget_wrapper);
  88047. + return -EBUSY;
  88048. + }
  88049. +#else
  88050. + DWC_DEBUGPL(DBG_ANY, "registering handler for irq%d\n",
  88051. + _dev->irq);
  88052. + retval = request_irq(_dev->irq, dwc_otg_pcd_irq,
  88053. + IRQF_SHARED | IRQF_DISABLED,
  88054. + gadget_wrapper->gadget.name, otg_dev->pcd);
  88055. + if (retval != 0) {
  88056. + DWC_ERROR("request of irq%d failed\n", _dev->irq);
  88057. + free_wrapper(gadget_wrapper);
  88058. + return -EBUSY;
  88059. + }
  88060. +#endif
  88061. +
  88062. + dwc_otg_pcd_start(gadget_wrapper->pcd, &fops);
  88063. +
  88064. + return retval;
  88065. +}
  88066. +
  88067. +/**
  88068. + * Cleanup the PCD.
  88069. + */
  88070. +void pcd_remove(dwc_bus_dev_t *_dev)
  88071. +{
  88072. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  88073. + dwc_otg_pcd_t *pcd = otg_dev->pcd;
  88074. +
  88075. + DWC_DEBUGPL(DBG_PCDV, "%s(%p) otg_dev %p\n", __func__, _dev, otg_dev);
  88076. +
  88077. + /*
  88078. + * Free the IRQ
  88079. + */
  88080. +#ifdef PLATFORM_INTERFACE
  88081. + free_irq(platform_get_irq(_dev, 0), pcd);
  88082. +#else
  88083. + free_irq(_dev->irq, pcd);
  88084. +#endif
  88085. + dwc_otg_pcd_remove(otg_dev->pcd);
  88086. + free_wrapper(gadget_wrapper);
  88087. + otg_dev->pcd = 0;
  88088. +}
  88089. +
  88090. +/**
  88091. + * This function registers a gadget driver with the PCD.
  88092. + *
  88093. + * When a driver is successfully registered, it will receive control
  88094. + * requests including set_configuration(), which enables non-control
  88095. + * requests. then usb traffic follows until a disconnect is reported.
  88096. + * then a host may connect again, or the driver might get unbound.
  88097. + *
  88098. + * @param driver The driver being registered
  88099. + * @param bind The bind function of gadget driver
  88100. + */
  88101. +
  88102. +int usb_gadget_probe_driver(struct usb_gadget_driver *driver)
  88103. +{
  88104. + int retval;
  88105. +
  88106. + DWC_DEBUGPL(DBG_PCD, "registering gadget driver '%s'\n",
  88107. + driver->driver.name);
  88108. +
  88109. + if (!driver || driver->max_speed == USB_SPEED_UNKNOWN ||
  88110. + !driver->bind ||
  88111. + !driver->unbind || !driver->disconnect || !driver->setup) {
  88112. + DWC_DEBUGPL(DBG_PCDV, "EINVAL\n");
  88113. + return -EINVAL;
  88114. + }
  88115. + if (gadget_wrapper == 0) {
  88116. + DWC_DEBUGPL(DBG_PCDV, "ENODEV\n");
  88117. + return -ENODEV;
  88118. + }
  88119. + if (gadget_wrapper->driver != 0) {
  88120. + DWC_DEBUGPL(DBG_PCDV, "EBUSY (%p)\n", gadget_wrapper->driver);
  88121. + return -EBUSY;
  88122. + }
  88123. +
  88124. + /* hook up the driver */
  88125. + gadget_wrapper->driver = driver;
  88126. + gadget_wrapper->gadget.dev.driver = &driver->driver;
  88127. +
  88128. + DWC_DEBUGPL(DBG_PCD, "bind to driver %s\n", driver->driver.name);
  88129. + retval = driver->bind(&gadget_wrapper->gadget, gadget_wrapper->driver);
  88130. + if (retval) {
  88131. + DWC_ERROR("bind to driver %s --> error %d\n",
  88132. + driver->driver.name, retval);
  88133. + gadget_wrapper->driver = 0;
  88134. + gadget_wrapper->gadget.dev.driver = 0;
  88135. + return retval;
  88136. + }
  88137. + DWC_DEBUGPL(DBG_ANY, "registered gadget driver '%s'\n",
  88138. + driver->driver.name);
  88139. + return 0;
  88140. +}
  88141. +EXPORT_SYMBOL(usb_gadget_probe_driver);
  88142. +
  88143. +/**
  88144. + * This function unregisters a gadget driver
  88145. + *
  88146. + * @param driver The driver being unregistered
  88147. + */
  88148. +int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
  88149. +{
  88150. + //DWC_DEBUGPL(DBG_PCDV,"%s(%p)\n", __func__, _driver);
  88151. +
  88152. + if (gadget_wrapper == 0) {
  88153. + DWC_DEBUGPL(DBG_ANY, "%s Return(%d): s_pcd==0\n", __func__,
  88154. + -ENODEV);
  88155. + return -ENODEV;
  88156. + }
  88157. + if (driver == 0 || driver != gadget_wrapper->driver) {
  88158. + DWC_DEBUGPL(DBG_ANY, "%s Return(%d): driver?\n", __func__,
  88159. + -EINVAL);
  88160. + return -EINVAL;
  88161. + }
  88162. +
  88163. + driver->unbind(&gadget_wrapper->gadget);
  88164. + gadget_wrapper->driver = 0;
  88165. +
  88166. + DWC_DEBUGPL(DBG_ANY, "unregistered driver '%s'\n", driver->driver.name);
  88167. + return 0;
  88168. +}
  88169. +
  88170. +EXPORT_SYMBOL(usb_gadget_unregister_driver);
  88171. +
  88172. +#endif /* DWC_HOST_ONLY */
  88173. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_regs.h linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_regs.h
  88174. --- linux-3.13.3.orig/drivers/usb/host/dwc_otg/dwc_otg_regs.h 1970-01-01 01:00:00.000000000 +0100
  88175. +++ linux-3.13.3/drivers/usb/host/dwc_otg/dwc_otg_regs.h 2014-02-17 22:41:01.000000000 +0100
  88176. @@ -0,0 +1,2550 @@
  88177. +/* ==========================================================================
  88178. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_regs.h $
  88179. + * $Revision: #98 $
  88180. + * $Date: 2012/08/10 $
  88181. + * $Change: 2047372 $
  88182. + *
  88183. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  88184. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  88185. + * otherwise expressly agreed to in writing between Synopsys and you.
  88186. + *
  88187. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  88188. + * any End User Software License Agreement or Agreement for Licensed Product
  88189. + * with Synopsys or any supplement thereto. You are permitted to use and
  88190. + * redistribute this Software in source and binary forms, with or without
  88191. + * modification, provided that redistributions of source code must retain this
  88192. + * notice. You may not view, use, disclose, copy or distribute this file or
  88193. + * any information contained herein except pursuant to this license grant from
  88194. + * Synopsys. If you do not agree with this notice, including the disclaimer
  88195. + * below, then you are not authorized to use the Software.
  88196. + *
  88197. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  88198. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  88199. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  88200. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  88201. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  88202. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  88203. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  88204. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  88205. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  88206. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  88207. + * DAMAGE.
  88208. + * ========================================================================== */
  88209. +
  88210. +#ifndef __DWC_OTG_REGS_H__
  88211. +#define __DWC_OTG_REGS_H__
  88212. +
  88213. +#include "dwc_otg_core_if.h"
  88214. +
  88215. +/**
  88216. + * @file
  88217. + *
  88218. + * This file contains the data structures for accessing the DWC_otg core registers.
  88219. + *
  88220. + * The application interfaces with the HS OTG core by reading from and
  88221. + * writing to the Control and Status Register (CSR) space through the
  88222. + * AHB Slave interface. These registers are 32 bits wide, and the
  88223. + * addresses are 32-bit-block aligned.
  88224. + * CSRs are classified as follows:
  88225. + * - Core Global Registers
  88226. + * - Device Mode Registers
  88227. + * - Device Global Registers
  88228. + * - Device Endpoint Specific Registers
  88229. + * - Host Mode Registers
  88230. + * - Host Global Registers
  88231. + * - Host Port CSRs
  88232. + * - Host Channel Specific Registers
  88233. + *
  88234. + * Only the Core Global registers can be accessed in both Device and
  88235. + * Host modes. When the HS OTG core is operating in one mode, either
  88236. + * Device or Host, the application must not access registers from the
  88237. + * other mode. When the core switches from one mode to another, the
  88238. + * registers in the new mode of operation must be reprogrammed as they
  88239. + * would be after a power-on reset.
  88240. + */
  88241. +
  88242. +/****************************************************************************/
  88243. +/** DWC_otg Core registers .
  88244. + * The dwc_otg_core_global_regs structure defines the size
  88245. + * and relative field offsets for the Core Global registers.
  88246. + */
  88247. +typedef struct dwc_otg_core_global_regs {
  88248. + /** OTG Control and Status Register. <i>Offset: 000h</i> */
  88249. + volatile uint32_t gotgctl;
  88250. + /** OTG Interrupt Register. <i>Offset: 004h</i> */
  88251. + volatile uint32_t gotgint;
  88252. + /**Core AHB Configuration Register. <i>Offset: 008h</i> */
  88253. + volatile uint32_t gahbcfg;
  88254. +
  88255. +#define DWC_GLBINTRMASK 0x0001
  88256. +#define DWC_DMAENABLE 0x0020
  88257. +#define DWC_NPTXEMPTYLVL_EMPTY 0x0080
  88258. +#define DWC_NPTXEMPTYLVL_HALFEMPTY 0x0000
  88259. +#define DWC_PTXEMPTYLVL_EMPTY 0x0100
  88260. +#define DWC_PTXEMPTYLVL_HALFEMPTY 0x0000
  88261. +
  88262. + /**Core USB Configuration Register. <i>Offset: 00Ch</i> */
  88263. + volatile uint32_t gusbcfg;
  88264. + /**Core Reset Register. <i>Offset: 010h</i> */
  88265. + volatile uint32_t grstctl;
  88266. + /**Core Interrupt Register. <i>Offset: 014h</i> */
  88267. + volatile uint32_t gintsts;
  88268. + /**Core Interrupt Mask Register. <i>Offset: 018h</i> */
  88269. + volatile uint32_t gintmsk;
  88270. + /**Receive Status Queue Read Register (Read Only). <i>Offset: 01Ch</i> */
  88271. + volatile uint32_t grxstsr;
  88272. + /**Receive Status Queue Read & POP Register (Read Only). <i>Offset: 020h</i>*/
  88273. + volatile uint32_t grxstsp;
  88274. + /**Receive FIFO Size Register. <i>Offset: 024h</i> */
  88275. + volatile uint32_t grxfsiz;
  88276. + /**Non Periodic Transmit FIFO Size Register. <i>Offset: 028h</i> */
  88277. + volatile uint32_t gnptxfsiz;
  88278. + /**Non Periodic Transmit FIFO/Queue Status Register (Read
  88279. + * Only). <i>Offset: 02Ch</i> */
  88280. + volatile uint32_t gnptxsts;
  88281. + /**I2C Access Register. <i>Offset: 030h</i> */
  88282. + volatile uint32_t gi2cctl;
  88283. + /**PHY Vendor Control Register. <i>Offset: 034h</i> */
  88284. + volatile uint32_t gpvndctl;
  88285. + /**General Purpose Input/Output Register. <i>Offset: 038h</i> */
  88286. + volatile uint32_t ggpio;
  88287. + /**User ID Register. <i>Offset: 03Ch</i> */
  88288. + volatile uint32_t guid;
  88289. + /**Synopsys ID Register (Read Only). <i>Offset: 040h</i> */
  88290. + volatile uint32_t gsnpsid;
  88291. + /**User HW Config1 Register (Read Only). <i>Offset: 044h</i> */
  88292. + volatile uint32_t ghwcfg1;
  88293. + /**User HW Config2 Register (Read Only). <i>Offset: 048h</i> */
  88294. + volatile uint32_t ghwcfg2;
  88295. +#define DWC_SLAVE_ONLY_ARCH 0
  88296. +#define DWC_EXT_DMA_ARCH 1
  88297. +#define DWC_INT_DMA_ARCH 2
  88298. +
  88299. +#define DWC_MODE_HNP_SRP_CAPABLE 0
  88300. +#define DWC_MODE_SRP_ONLY_CAPABLE 1
  88301. +#define DWC_MODE_NO_HNP_SRP_CAPABLE 2
  88302. +#define DWC_MODE_SRP_CAPABLE_DEVICE 3
  88303. +#define DWC_MODE_NO_SRP_CAPABLE_DEVICE 4
  88304. +#define DWC_MODE_SRP_CAPABLE_HOST 5
  88305. +#define DWC_MODE_NO_SRP_CAPABLE_HOST 6
  88306. +
  88307. + /**User HW Config3 Register (Read Only). <i>Offset: 04Ch</i> */
  88308. + volatile uint32_t ghwcfg3;
  88309. + /**User HW Config4 Register (Read Only). <i>Offset: 050h</i>*/
  88310. + volatile uint32_t ghwcfg4;
  88311. + /** Core LPM Configuration register <i>Offset: 054h</i>*/
  88312. + volatile uint32_t glpmcfg;
  88313. + /** Global PowerDn Register <i>Offset: 058h</i> */
  88314. + volatile uint32_t gpwrdn;
  88315. + /** Global DFIFO SW Config Register <i>Offset: 05Ch</i> */
  88316. + volatile uint32_t gdfifocfg;
  88317. + /** ADP Control Register <i>Offset: 060h</i> */
  88318. + volatile uint32_t adpctl;
  88319. + /** Reserved <i>Offset: 064h-0FFh</i> */
  88320. + volatile uint32_t reserved39[39];
  88321. + /** Host Periodic Transmit FIFO Size Register. <i>Offset: 100h</i> */
  88322. + volatile uint32_t hptxfsiz;
  88323. + /** Device Periodic Transmit FIFO#n Register if dedicated fifos are disabled,
  88324. + otherwise Device Transmit FIFO#n Register.
  88325. + * <i>Offset: 104h + (FIFO_Number-1)*04h, 1 <= FIFO Number <= 15 (1<=n<=15).</i> */
  88326. + volatile uint32_t dtxfsiz[15];
  88327. +} dwc_otg_core_global_regs_t;
  88328. +
  88329. +/**
  88330. + * This union represents the bit fields of the Core OTG Control
  88331. + * and Status Register (GOTGCTL). Set the bits using the bit
  88332. + * fields then write the <i>d32</i> value to the register.
  88333. + */
  88334. +typedef union gotgctl_data {
  88335. + /** raw register data */
  88336. + uint32_t d32;
  88337. + /** register bits */
  88338. + struct {
  88339. + unsigned sesreqscs:1;
  88340. + unsigned sesreq:1;
  88341. + unsigned vbvalidoven:1;
  88342. + unsigned vbvalidovval:1;
  88343. + unsigned avalidoven:1;
  88344. + unsigned avalidovval:1;
  88345. + unsigned bvalidoven:1;
  88346. + unsigned bvalidovval:1;
  88347. + unsigned hstnegscs:1;
  88348. + unsigned hnpreq:1;
  88349. + unsigned hstsethnpen:1;
  88350. + unsigned devhnpen:1;
  88351. + unsigned reserved12_15:4;
  88352. + unsigned conidsts:1;
  88353. + unsigned dbnctime:1;
  88354. + unsigned asesvld:1;
  88355. + unsigned bsesvld:1;
  88356. + unsigned otgver:1;
  88357. + unsigned reserved1:1;
  88358. + unsigned multvalidbc:5;
  88359. + unsigned chirpen:1;
  88360. + unsigned reserved28_31:4;
  88361. + } b;
  88362. +} gotgctl_data_t;
  88363. +
  88364. +/**
  88365. + * This union represents the bit fields of the Core OTG Interrupt Register
  88366. + * (GOTGINT). Set/clear the bits using the bit fields then write the <i>d32</i>
  88367. + * value to the register.
  88368. + */
  88369. +typedef union gotgint_data {
  88370. + /** raw register data */
  88371. + uint32_t d32;
  88372. + /** register bits */
  88373. + struct {
  88374. + /** Current Mode */
  88375. + unsigned reserved0_1:2;
  88376. +
  88377. + /** Session End Detected */
  88378. + unsigned sesenddet:1;
  88379. +
  88380. + unsigned reserved3_7:5;
  88381. +
  88382. + /** Session Request Success Status Change */
  88383. + unsigned sesreqsucstschng:1;
  88384. + /** Host Negotiation Success Status Change */
  88385. + unsigned hstnegsucstschng:1;
  88386. +
  88387. + unsigned reserved10_16:7;
  88388. +
  88389. + /** Host Negotiation Detected */
  88390. + unsigned hstnegdet:1;
  88391. + /** A-Device Timeout Change */
  88392. + unsigned adevtoutchng:1;
  88393. + /** Debounce Done */
  88394. + unsigned debdone:1;
  88395. + /** Multi-Valued input changed */
  88396. + unsigned mvic:1;
  88397. +
  88398. + unsigned reserved31_21:11;
  88399. +
  88400. + } b;
  88401. +} gotgint_data_t;
  88402. +
  88403. +/**
  88404. + * This union represents the bit fields of the Core AHB Configuration
  88405. + * Register (GAHBCFG). Set/clear the bits using the bit fields then
  88406. + * write the <i>d32</i> value to the register.
  88407. + */
  88408. +typedef union gahbcfg_data {
  88409. + /** raw register data */
  88410. + uint32_t d32;
  88411. + /** register bits */
  88412. + struct {
  88413. + unsigned glblintrmsk:1;
  88414. +#define DWC_GAHBCFG_GLBINT_ENABLE 1
  88415. +
  88416. + unsigned hburstlen:4;
  88417. +#define DWC_GAHBCFG_INT_DMA_BURST_SINGLE 0
  88418. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR 1
  88419. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR4 3
  88420. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR8 5
  88421. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR16 7
  88422. +
  88423. + unsigned dmaenable:1;
  88424. +#define DWC_GAHBCFG_DMAENABLE 1
  88425. + unsigned reserved:1;
  88426. + unsigned nptxfemplvl_txfemplvl:1;
  88427. + unsigned ptxfemplvl:1;
  88428. +#define DWC_GAHBCFG_TXFEMPTYLVL_EMPTY 1
  88429. +#define DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY 0
  88430. + unsigned reserved9_20:12;
  88431. + unsigned remmemsupp:1;
  88432. + unsigned notialldmawrit:1;
  88433. + unsigned ahbsingle:1;
  88434. + unsigned reserved24_31:8;
  88435. + } b;
  88436. +} gahbcfg_data_t;
  88437. +
  88438. +/**
  88439. + * This union represents the bit fields of the Core USB Configuration
  88440. + * Register (GUSBCFG). Set the bits using the bit fields then write
  88441. + * the <i>d32</i> value to the register.
  88442. + */
  88443. +typedef union gusbcfg_data {
  88444. + /** raw register data */
  88445. + uint32_t d32;
  88446. + /** register bits */
  88447. + struct {
  88448. + unsigned toutcal:3;
  88449. + unsigned phyif:1;
  88450. + unsigned ulpi_utmi_sel:1;
  88451. + unsigned fsintf:1;
  88452. + unsigned physel:1;
  88453. + unsigned ddrsel:1;
  88454. + unsigned srpcap:1;
  88455. + unsigned hnpcap:1;
  88456. + unsigned usbtrdtim:4;
  88457. + unsigned reserved1:1;
  88458. + unsigned phylpwrclksel:1;
  88459. + unsigned otgutmifssel:1;
  88460. + unsigned ulpi_fsls:1;
  88461. + unsigned ulpi_auto_res:1;
  88462. + unsigned ulpi_clk_sus_m:1;
  88463. + unsigned ulpi_ext_vbus_drv:1;
  88464. + unsigned ulpi_int_vbus_indicator:1;
  88465. + unsigned term_sel_dl_pulse:1;
  88466. + unsigned indicator_complement:1;
  88467. + unsigned indicator_pass_through:1;
  88468. + unsigned ulpi_int_prot_dis:1;
  88469. + unsigned ic_usb_cap:1;
  88470. + unsigned ic_traffic_pull_remove:1;
  88471. + unsigned tx_end_delay:1;
  88472. + unsigned force_host_mode:1;
  88473. + unsigned force_dev_mode:1;
  88474. + unsigned reserved31:1;
  88475. + } b;
  88476. +} gusbcfg_data_t;
  88477. +
  88478. +/**
  88479. + * This union represents the bit fields of the Core Reset Register
  88480. + * (GRSTCTL). Set/clear the bits using the bit fields then write the
  88481. + * <i>d32</i> value to the register.
  88482. + */
  88483. +typedef union grstctl_data {
  88484. + /** raw register data */
  88485. + uint32_t d32;
  88486. + /** register bits */
  88487. + struct {
  88488. + /** Core Soft Reset (CSftRst) (Device and Host)
  88489. + *
  88490. + * The application can flush the control logic in the
  88491. + * entire core using this bit. This bit resets the
  88492. + * pipelines in the AHB Clock domain as well as the
  88493. + * PHY Clock domain.
  88494. + *
  88495. + * The state machines are reset to an IDLE state, the
  88496. + * control bits in the CSRs are cleared, all the
  88497. + * transmit FIFOs and the receive FIFO are flushed.
  88498. + *
  88499. + * The status mask bits that control the generation of
  88500. + * the interrupt, are cleared, to clear the
  88501. + * interrupt. The interrupt status bits are not
  88502. + * cleared, so the application can get the status of
  88503. + * any events that occurred in the core after it has
  88504. + * set this bit.
  88505. + *
  88506. + * Any transactions on the AHB are terminated as soon
  88507. + * as possible following the protocol. Any
  88508. + * transactions on the USB are terminated immediately.
  88509. + *
  88510. + * The configuration settings in the CSRs are
  88511. + * unchanged, so the software doesn't have to
  88512. + * reprogram these registers (Device
  88513. + * Configuration/Host Configuration/Core System
  88514. + * Configuration/Core PHY Configuration).
  88515. + *
  88516. + * The application can write to this bit, any time it
  88517. + * wants to reset the core. This is a self clearing
  88518. + * bit and the core clears this bit after all the
  88519. + * necessary logic is reset in the core, which may
  88520. + * take several clocks, depending on the current state
  88521. + * of the core.
  88522. + */
  88523. + unsigned csftrst:1;
  88524. + /** Hclk Soft Reset
  88525. + *
  88526. + * The application uses this bit to reset the control logic in
  88527. + * the AHB clock domain. Only AHB clock domain pipelines are
  88528. + * reset.
  88529. + */
  88530. + unsigned hsftrst:1;
  88531. + /** Host Frame Counter Reset (Host Only)<br>
  88532. + *
  88533. + * The application can reset the (micro)frame number
  88534. + * counter inside the core, using this bit. When the
  88535. + * (micro)frame counter is reset, the subsequent SOF
  88536. + * sent out by the core, will have a (micro)frame
  88537. + * number of 0.
  88538. + */
  88539. + unsigned hstfrm:1;
  88540. + /** In Token Sequence Learning Queue Flush
  88541. + * (INTknQFlsh) (Device Only)
  88542. + */
  88543. + unsigned intknqflsh:1;
  88544. + /** RxFIFO Flush (RxFFlsh) (Device and Host)
  88545. + *
  88546. + * The application can flush the entire Receive FIFO
  88547. + * using this bit. The application must first
  88548. + * ensure that the core is not in the middle of a
  88549. + * transaction. The application should write into
  88550. + * this bit, only after making sure that neither the
  88551. + * DMA engine is reading from the RxFIFO nor the MAC
  88552. + * is writing the data in to the FIFO. The
  88553. + * application should wait until the bit is cleared
  88554. + * before performing any other operations. This bit
  88555. + * will takes 8 clocks (slowest of PHY or AHB clock)
  88556. + * to clear.
  88557. + */
  88558. + unsigned rxfflsh:1;
  88559. + /** TxFIFO Flush (TxFFlsh) (Device and Host).
  88560. + *
  88561. + * This bit is used to selectively flush a single or
  88562. + * all transmit FIFOs. The application must first
  88563. + * ensure that the core is not in the middle of a
  88564. + * transaction. The application should write into
  88565. + * this bit, only after making sure that neither the
  88566. + * DMA engine is writing into the TxFIFO nor the MAC
  88567. + * is reading the data out of the FIFO. The
  88568. + * application should wait until the core clears this
  88569. + * bit, before performing any operations. This bit
  88570. + * will takes 8 clocks (slowest of PHY or AHB clock)
  88571. + * to clear.
  88572. + */
  88573. + unsigned txfflsh:1;
  88574. +
  88575. + /** TxFIFO Number (TxFNum) (Device and Host).
  88576. + *
  88577. + * This is the FIFO number which needs to be flushed,
  88578. + * using the TxFIFO Flush bit. This field should not
  88579. + * be changed until the TxFIFO Flush bit is cleared by
  88580. + * the core.
  88581. + * - 0x0 : Non Periodic TxFIFO Flush
  88582. + * - 0x1 : Periodic TxFIFO #1 Flush in device mode
  88583. + * or Periodic TxFIFO in host mode
  88584. + * - 0x2 : Periodic TxFIFO #2 Flush in device mode.
  88585. + * - ...
  88586. + * - 0xF : Periodic TxFIFO #15 Flush in device mode
  88587. + * - 0x10: Flush all the Transmit NonPeriodic and
  88588. + * Transmit Periodic FIFOs in the core
  88589. + */
  88590. + unsigned txfnum:5;
  88591. + /** Reserved */
  88592. + unsigned reserved11_29:19;
  88593. + /** DMA Request Signal. Indicated DMA request is in
  88594. + * probress. Used for debug purpose. */
  88595. + unsigned dmareq:1;
  88596. + /** AHB Master Idle. Indicates the AHB Master State
  88597. + * Machine is in IDLE condition. */
  88598. + unsigned ahbidle:1;
  88599. + } b;
  88600. +} grstctl_t;
  88601. +
  88602. +/**
  88603. + * This union represents the bit fields of the Core Interrupt Mask
  88604. + * Register (GINTMSK). Set/clear the bits using the bit fields then
  88605. + * write the <i>d32</i> value to the register.
  88606. + */
  88607. +typedef union gintmsk_data {
  88608. + /** raw register data */
  88609. + uint32_t d32;
  88610. + /** register bits */
  88611. + struct {
  88612. + unsigned reserved0:1;
  88613. + unsigned modemismatch:1;
  88614. + unsigned otgintr:1;
  88615. + unsigned sofintr:1;
  88616. + unsigned rxstsqlvl:1;
  88617. + unsigned nptxfempty:1;
  88618. + unsigned ginnakeff:1;
  88619. + unsigned goutnakeff:1;
  88620. + unsigned ulpickint:1;
  88621. + unsigned i2cintr:1;
  88622. + unsigned erlysuspend:1;
  88623. + unsigned usbsuspend:1;
  88624. + unsigned usbreset:1;
  88625. + unsigned enumdone:1;
  88626. + unsigned isooutdrop:1;
  88627. + unsigned eopframe:1;
  88628. + unsigned restoredone:1;
  88629. + unsigned epmismatch:1;
  88630. + unsigned inepintr:1;
  88631. + unsigned outepintr:1;
  88632. + unsigned incomplisoin:1;
  88633. + unsigned incomplisoout:1;
  88634. + unsigned fetsusp:1;
  88635. + unsigned resetdet:1;
  88636. + unsigned portintr:1;
  88637. + unsigned hcintr:1;
  88638. + unsigned ptxfempty:1;
  88639. + unsigned lpmtranrcvd:1;
  88640. + unsigned conidstschng:1;
  88641. + unsigned disconnect:1;
  88642. + unsigned sessreqintr:1;
  88643. + unsigned wkupintr:1;
  88644. + } b;
  88645. +} gintmsk_data_t;
  88646. +/**
  88647. + * This union represents the bit fields of the Core Interrupt Register
  88648. + * (GINTSTS). Set/clear the bits using the bit fields then write the
  88649. + * <i>d32</i> value to the register.
  88650. + */
  88651. +typedef union gintsts_data {
  88652. + /** raw register data */
  88653. + uint32_t d32;
  88654. +#define DWC_SOF_INTR_MASK 0x0008
  88655. + /** register bits */
  88656. + struct {
  88657. +#define DWC_HOST_MODE 1
  88658. + unsigned curmode:1;
  88659. + unsigned modemismatch:1;
  88660. + unsigned otgintr:1;
  88661. + unsigned sofintr:1;
  88662. + unsigned rxstsqlvl:1;
  88663. + unsigned nptxfempty:1;
  88664. + unsigned ginnakeff:1;
  88665. + unsigned goutnakeff:1;
  88666. + unsigned ulpickint:1;
  88667. + unsigned i2cintr:1;
  88668. + unsigned erlysuspend:1;
  88669. + unsigned usbsuspend:1;
  88670. + unsigned usbreset:1;
  88671. + unsigned enumdone:1;
  88672. + unsigned isooutdrop:1;
  88673. + unsigned eopframe:1;
  88674. + unsigned restoredone:1;
  88675. + unsigned epmismatch:1;
  88676. + unsigned inepint:1;
  88677. + unsigned outepintr:1;
  88678. + unsigned incomplisoin:1;
  88679. + unsigned incomplisoout:1;
  88680. + unsigned fetsusp:1;
  88681. + unsigned resetdet:1;
  88682. + unsigned portintr:1;
  88683. + unsigned hcintr:1;
  88684. + unsigned ptxfempty:1;
  88685. + unsigned lpmtranrcvd:1;
  88686. + unsigned conidstschng:1;
  88687. + unsigned disconnect:1;
  88688. + unsigned sessreqintr:1;
  88689. + unsigned wkupintr:1;
  88690. + } b;
  88691. +} gintsts_data_t;
  88692. +
  88693. +/**
  88694. + * This union represents the bit fields in the Device Receive Status Read and
  88695. + * Pop Registers (GRXSTSR, GRXSTSP) Read the register into the <i>d32</i>
  88696. + * element then read out the bits using the <i>b</i>it elements.
  88697. + */
  88698. +typedef union device_grxsts_data {
  88699. + /** raw register data */
  88700. + uint32_t d32;
  88701. + /** register bits */
  88702. + struct {
  88703. + unsigned epnum:4;
  88704. + unsigned bcnt:11;
  88705. + unsigned dpid:2;
  88706. +
  88707. +#define DWC_STS_DATA_UPDT 0x2 // OUT Data Packet
  88708. +#define DWC_STS_XFER_COMP 0x3 // OUT Data Transfer Complete
  88709. +
  88710. +#define DWC_DSTS_GOUT_NAK 0x1 // Global OUT NAK
  88711. +#define DWC_DSTS_SETUP_COMP 0x4 // Setup Phase Complete
  88712. +#define DWC_DSTS_SETUP_UPDT 0x6 // SETUP Packet
  88713. + unsigned pktsts:4;
  88714. + unsigned fn:4;
  88715. + unsigned reserved25_31:7;
  88716. + } b;
  88717. +} device_grxsts_data_t;
  88718. +
  88719. +/**
  88720. + * This union represents the bit fields in the Host Receive Status Read and
  88721. + * Pop Registers (GRXSTSR, GRXSTSP) Read the register into the <i>d32</i>
  88722. + * element then read out the bits using the <i>b</i>it elements.
  88723. + */
  88724. +typedef union host_grxsts_data {
  88725. + /** raw register data */
  88726. + uint32_t d32;
  88727. + /** register bits */
  88728. + struct {
  88729. + unsigned chnum:4;
  88730. + unsigned bcnt:11;
  88731. + unsigned dpid:2;
  88732. +
  88733. + unsigned pktsts:4;
  88734. +#define DWC_GRXSTS_PKTSTS_IN 0x2
  88735. +#define DWC_GRXSTS_PKTSTS_IN_XFER_COMP 0x3
  88736. +#define DWC_GRXSTS_PKTSTS_DATA_TOGGLE_ERR 0x5
  88737. +#define DWC_GRXSTS_PKTSTS_CH_HALTED 0x7
  88738. +
  88739. + unsigned reserved21_31:11;
  88740. + } b;
  88741. +} host_grxsts_data_t;
  88742. +
  88743. +/**
  88744. + * This union represents the bit fields in the FIFO Size Registers (HPTXFSIZ,
  88745. + * GNPTXFSIZ, DPTXFSIZn, DIEPTXFn). Read the register into the <i>d32</i> element
  88746. + * then read out the bits using the <i>b</i>it elements.
  88747. + */
  88748. +typedef union fifosize_data {
  88749. + /** raw register data */
  88750. + uint32_t d32;
  88751. + /** register bits */
  88752. + struct {
  88753. + unsigned startaddr:16;
  88754. + unsigned depth:16;
  88755. + } b;
  88756. +} fifosize_data_t;
  88757. +
  88758. +/**
  88759. + * This union represents the bit fields in the Non-Periodic Transmit
  88760. + * FIFO/Queue Status Register (GNPTXSTS). Read the register into the
  88761. + * <i>d32</i> element then read out the bits using the <i>b</i>it
  88762. + * elements.
  88763. + */
  88764. +typedef union gnptxsts_data {
  88765. + /** raw register data */
  88766. + uint32_t d32;
  88767. + /** register bits */
  88768. + struct {
  88769. + unsigned nptxfspcavail:16;
  88770. + unsigned nptxqspcavail:8;
  88771. + /** Top of the Non-Periodic Transmit Request Queue
  88772. + * - bit 24 - Terminate (Last entry for the selected
  88773. + * channel/EP)
  88774. + * - bits 26:25 - Token Type
  88775. + * - 2'b00 - IN/OUT
  88776. + * - 2'b01 - Zero Length OUT
  88777. + * - 2'b10 - PING/Complete Split
  88778. + * - 2'b11 - Channel Halt
  88779. + * - bits 30:27 - Channel/EP Number
  88780. + */
  88781. + unsigned nptxqtop_terminate:1;
  88782. + unsigned nptxqtop_token:2;
  88783. + unsigned nptxqtop_chnep:4;
  88784. + unsigned reserved:1;
  88785. + } b;
  88786. +} gnptxsts_data_t;
  88787. +
  88788. +/**
  88789. + * This union represents the bit fields in the Transmit
  88790. + * FIFO Status Register (DTXFSTS). Read the register into the
  88791. + * <i>d32</i> element then read out the bits using the <i>b</i>it
  88792. + * elements.
  88793. + */
  88794. +typedef union dtxfsts_data {
  88795. + /** raw register data */
  88796. + uint32_t d32;
  88797. + /** register bits */
  88798. + struct {
  88799. + unsigned txfspcavail:16;
  88800. + unsigned reserved:16;
  88801. + } b;
  88802. +} dtxfsts_data_t;
  88803. +
  88804. +/**
  88805. + * This union represents the bit fields in the I2C Control Register
  88806. + * (I2CCTL). Read the register into the <i>d32</i> element then read out the
  88807. + * bits using the <i>b</i>it elements.
  88808. + */
  88809. +typedef union gi2cctl_data {
  88810. + /** raw register data */
  88811. + uint32_t d32;
  88812. + /** register bits */
  88813. + struct {
  88814. + unsigned rwdata:8;
  88815. + unsigned regaddr:8;
  88816. + unsigned addr:7;
  88817. + unsigned i2cen:1;
  88818. + unsigned ack:1;
  88819. + unsigned i2csuspctl:1;
  88820. + unsigned i2cdevaddr:2;
  88821. + unsigned i2cdatse0:1;
  88822. + unsigned reserved:1;
  88823. + unsigned rw:1;
  88824. + unsigned bsydne:1;
  88825. + } b;
  88826. +} gi2cctl_data_t;
  88827. +
  88828. +/**
  88829. + * This union represents the bit fields in the PHY Vendor Control Register
  88830. + * (GPVNDCTL). Read the register into the <i>d32</i> element then read out the
  88831. + * bits using the <i>b</i>it elements.
  88832. + */
  88833. +typedef union gpvndctl_data {
  88834. + /** raw register data */
  88835. + uint32_t d32;
  88836. + /** register bits */
  88837. + struct {
  88838. + unsigned regdata:8;
  88839. + unsigned vctrl:8;
  88840. + unsigned regaddr16_21:6;
  88841. + unsigned regwr:1;
  88842. + unsigned reserved23_24:2;
  88843. + unsigned newregreq:1;
  88844. + unsigned vstsbsy:1;
  88845. + unsigned vstsdone:1;
  88846. + unsigned reserved28_30:3;
  88847. + unsigned disulpidrvr:1;
  88848. + } b;
  88849. +} gpvndctl_data_t;
  88850. +
  88851. +/**
  88852. + * This union represents the bit fields in the General Purpose
  88853. + * Input/Output Register (GGPIO).
  88854. + * Read the register into the <i>d32</i> element then read out the
  88855. + * bits using the <i>b</i>it elements.
  88856. + */
  88857. +typedef union ggpio_data {
  88858. + /** raw register data */
  88859. + uint32_t d32;
  88860. + /** register bits */
  88861. + struct {
  88862. + unsigned gpi:16;
  88863. + unsigned gpo:16;
  88864. + } b;
  88865. +} ggpio_data_t;
  88866. +
  88867. +/**
  88868. + * This union represents the bit fields in the User ID Register
  88869. + * (GUID). Read the register into the <i>d32</i> element then read out the
  88870. + * bits using the <i>b</i>it elements.
  88871. + */
  88872. +typedef union guid_data {
  88873. + /** raw register data */
  88874. + uint32_t d32;
  88875. + /** register bits */
  88876. + struct {
  88877. + unsigned rwdata:32;
  88878. + } b;
  88879. +} guid_data_t;
  88880. +
  88881. +/**
  88882. + * This union represents the bit fields in the Synopsys ID Register
  88883. + * (GSNPSID). Read the register into the <i>d32</i> element then read out the
  88884. + * bits using the <i>b</i>it elements.
  88885. + */
  88886. +typedef union gsnpsid_data {
  88887. + /** raw register data */
  88888. + uint32_t d32;
  88889. + /** register bits */
  88890. + struct {
  88891. + unsigned rwdata:32;
  88892. + } b;
  88893. +} gsnpsid_data_t;
  88894. +
  88895. +/**
  88896. + * This union represents the bit fields in the User HW Config1
  88897. + * Register. Read the register into the <i>d32</i> element then read
  88898. + * out the bits using the <i>b</i>it elements.
  88899. + */
  88900. +typedef union hwcfg1_data {
  88901. + /** raw register data */
  88902. + uint32_t d32;
  88903. + /** register bits */
  88904. + struct {
  88905. + unsigned ep_dir0:2;
  88906. + unsigned ep_dir1:2;
  88907. + unsigned ep_dir2:2;
  88908. + unsigned ep_dir3:2;
  88909. + unsigned ep_dir4:2;
  88910. + unsigned ep_dir5:2;
  88911. + unsigned ep_dir6:2;
  88912. + unsigned ep_dir7:2;
  88913. + unsigned ep_dir8:2;
  88914. + unsigned ep_dir9:2;
  88915. + unsigned ep_dir10:2;
  88916. + unsigned ep_dir11:2;
  88917. + unsigned ep_dir12:2;
  88918. + unsigned ep_dir13:2;
  88919. + unsigned ep_dir14:2;
  88920. + unsigned ep_dir15:2;
  88921. + } b;
  88922. +} hwcfg1_data_t;
  88923. +
  88924. +/**
  88925. + * This union represents the bit fields in the User HW Config2
  88926. + * Register. Read the register into the <i>d32</i> element then read
  88927. + * out the bits using the <i>b</i>it elements.
  88928. + */
  88929. +typedef union hwcfg2_data {
  88930. + /** raw register data */
  88931. + uint32_t d32;
  88932. + /** register bits */
  88933. + struct {
  88934. + /* GHWCFG2 */
  88935. + unsigned op_mode:3;
  88936. +#define DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG 0
  88937. +#define DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG 1
  88938. +#define DWC_HWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE_OTG 2
  88939. +#define DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE 3
  88940. +#define DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE 4
  88941. +#define DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST 5
  88942. +#define DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST 6
  88943. +
  88944. + unsigned architecture:2;
  88945. + unsigned point2point:1;
  88946. + unsigned hs_phy_type:2;
  88947. +#define DWC_HWCFG2_HS_PHY_TYPE_NOT_SUPPORTED 0
  88948. +#define DWC_HWCFG2_HS_PHY_TYPE_UTMI 1
  88949. +#define DWC_HWCFG2_HS_PHY_TYPE_ULPI 2
  88950. +#define DWC_HWCFG2_HS_PHY_TYPE_UTMI_ULPI 3
  88951. +
  88952. + unsigned fs_phy_type:2;
  88953. + unsigned num_dev_ep:4;
  88954. + unsigned num_host_chan:4;
  88955. + unsigned perio_ep_supported:1;
  88956. + unsigned dynamic_fifo:1;
  88957. + unsigned multi_proc_int:1;
  88958. + unsigned reserved21:1;
  88959. + unsigned nonperio_tx_q_depth:2;
  88960. + unsigned host_perio_tx_q_depth:2;
  88961. + unsigned dev_token_q_depth:5;
  88962. + unsigned otg_enable_ic_usb:1;
  88963. + } b;
  88964. +} hwcfg2_data_t;
  88965. +
  88966. +/**
  88967. + * This union represents the bit fields in the User HW Config3
  88968. + * Register. Read the register into the <i>d32</i> element then read
  88969. + * out the bits using the <i>b</i>it elements.
  88970. + */
  88971. +typedef union hwcfg3_data {
  88972. + /** raw register data */
  88973. + uint32_t d32;
  88974. + /** register bits */
  88975. + struct {
  88976. + /* GHWCFG3 */
  88977. + unsigned xfer_size_cntr_width:4;
  88978. + unsigned packet_size_cntr_width:3;
  88979. + unsigned otg_func:1;
  88980. + unsigned i2c:1;
  88981. + unsigned vendor_ctrl_if:1;
  88982. + unsigned optional_features:1;
  88983. + unsigned synch_reset_type:1;
  88984. + unsigned adp_supp:1;
  88985. + unsigned otg_enable_hsic:1;
  88986. + unsigned bc_support:1;
  88987. + unsigned otg_lpm_en:1;
  88988. + unsigned dfifo_depth:16;
  88989. + } b;
  88990. +} hwcfg3_data_t;
  88991. +
  88992. +/**
  88993. + * This union represents the bit fields in the User HW Config4
  88994. + * Register. Read the register into the <i>d32</i> element then read
  88995. + * out the bits using the <i>b</i>it elements.
  88996. + */
  88997. +typedef union hwcfg4_data {
  88998. + /** raw register data */
  88999. + uint32_t d32;
  89000. + /** register bits */
  89001. + struct {
  89002. + unsigned num_dev_perio_in_ep:4;
  89003. + unsigned power_optimiz:1;
  89004. + unsigned min_ahb_freq:1;
  89005. + unsigned hiber:1;
  89006. + unsigned xhiber:1;
  89007. + unsigned reserved:6;
  89008. + unsigned utmi_phy_data_width:2;
  89009. + unsigned num_dev_mode_ctrl_ep:4;
  89010. + unsigned iddig_filt_en:1;
  89011. + unsigned vbus_valid_filt_en:1;
  89012. + unsigned a_valid_filt_en:1;
  89013. + unsigned b_valid_filt_en:1;
  89014. + unsigned session_end_filt_en:1;
  89015. + unsigned ded_fifo_en:1;
  89016. + unsigned num_in_eps:4;
  89017. + unsigned desc_dma:1;
  89018. + unsigned desc_dma_dyn:1;
  89019. + } b;
  89020. +} hwcfg4_data_t;
  89021. +
  89022. +/**
  89023. + * This union represents the bit fields of the Core LPM Configuration
  89024. + * Register (GLPMCFG). Set the bits using bit fields then write
  89025. + * the <i>d32</i> value to the register.
  89026. + */
  89027. +typedef union glpmctl_data {
  89028. + /** raw register data */
  89029. + uint32_t d32;
  89030. + /** register bits */
  89031. + struct {
  89032. + /** LPM-Capable (LPMCap) (Device and Host)
  89033. + * The application uses this bit to control
  89034. + * the DWC_otg core LPM capabilities.
  89035. + */
  89036. + unsigned lpm_cap_en:1;
  89037. + /** LPM response programmed by application (AppL1Res) (Device)
  89038. + * Handshake response to LPM token pre-programmed
  89039. + * by device application software.
  89040. + */
  89041. + unsigned appl_resp:1;
  89042. + /** Host Initiated Resume Duration (HIRD) (Device and Host)
  89043. + * In Host mode this field indicates the value of HIRD
  89044. + * to be sent in an LPM transaction.
  89045. + * In Device mode this field is updated with the
  89046. + * Received LPM Token HIRD bmAttribute
  89047. + * when an ACK/NYET/STALL response is sent
  89048. + * to an LPM transaction.
  89049. + */
  89050. + unsigned hird:4;
  89051. + /** RemoteWakeEnable (bRemoteWake) (Device and Host)
  89052. + * In Host mode this bit indicates the value of remote
  89053. + * wake up to be sent in wIndex field of LPM transaction.
  89054. + * In Device mode this field is updated with the
  89055. + * Received LPM Token bRemoteWake bmAttribute
  89056. + * when an ACK/NYET/STALL response is sent
  89057. + * to an LPM transaction.
  89058. + */
  89059. + unsigned rem_wkup_en:1;
  89060. + /** Enable utmi_sleep_n (EnblSlpM) (Device and Host)
  89061. + * The application uses this bit to control
  89062. + * the utmi_sleep_n assertion to the PHY when in L1 state.
  89063. + */
  89064. + unsigned en_utmi_sleep:1;
  89065. + /** HIRD Threshold (HIRD_Thres) (Device and Host)
  89066. + */
  89067. + unsigned hird_thres:5;
  89068. + /** LPM Response (CoreL1Res) (Device and Host)
  89069. + * In Host mode this bit contains handsake response to
  89070. + * LPM transaction.
  89071. + * In Device mode the response of the core to
  89072. + * LPM transaction received is reflected in these two bits.
  89073. + - 0x0 : ERROR (No handshake response)
  89074. + - 0x1 : STALL
  89075. + - 0x2 : NYET
  89076. + - 0x3 : ACK
  89077. + */
  89078. + unsigned lpm_resp:2;
  89079. + /** Port Sleep Status (SlpSts) (Device and Host)
  89080. + * This bit is set as long as a Sleep condition
  89081. + * is present on the USB bus.
  89082. + */
  89083. + unsigned prt_sleep_sts:1;
  89084. + /** Sleep State Resume OK (L1ResumeOK) (Device and Host)
  89085. + * Indicates that the application or host
  89086. + * can start resume from Sleep state.
  89087. + */
  89088. + unsigned sleep_state_resumeok:1;
  89089. + /** LPM channel Index (LPM_Chnl_Indx) (Host)
  89090. + * The channel number on which the LPM transaction
  89091. + * has to be applied while sending
  89092. + * an LPM transaction to the local device.
  89093. + */
  89094. + unsigned lpm_chan_index:4;
  89095. + /** LPM Retry Count (LPM_Retry_Cnt) (Host)
  89096. + * Number host retries that would be performed
  89097. + * if the device response was not valid response.
  89098. + */
  89099. + unsigned retry_count:3;
  89100. + /** Send LPM Transaction (SndLPM) (Host)
  89101. + * When set by application software,
  89102. + * an LPM transaction containing two tokens
  89103. + * is sent.
  89104. + */
  89105. + unsigned send_lpm:1;
  89106. + /** LPM Retry status (LPM_RetryCnt_Sts) (Host)
  89107. + * Number of LPM Host Retries still remaining
  89108. + * to be transmitted for the current LPM sequence
  89109. + */
  89110. + unsigned retry_count_sts:3;
  89111. + unsigned reserved28_29:2;
  89112. + /** In host mode once this bit is set, the host
  89113. + * configures to drive the HSIC Idle state on the bus.
  89114. + * It then waits for the device to initiate the Connect sequence.
  89115. + * In device mode once this bit is set, the device waits for
  89116. + * the HSIC Idle line state on the bus. Upon receving the Idle
  89117. + * line state, it initiates the HSIC Connect sequence.
  89118. + */
  89119. + unsigned hsic_connect:1;
  89120. + /** This bit overrides and functionally inverts
  89121. + * the if_select_hsic input port signal.
  89122. + */
  89123. + unsigned inv_sel_hsic:1;
  89124. + } b;
  89125. +} glpmcfg_data_t;
  89126. +
  89127. +/**
  89128. + * This union represents the bit fields of the Core ADP Timer, Control and
  89129. + * Status Register (ADPTIMCTLSTS). Set the bits using bit fields then write
  89130. + * the <i>d32</i> value to the register.
  89131. + */
  89132. +typedef union adpctl_data {
  89133. + /** raw register data */
  89134. + uint32_t d32;
  89135. + /** register bits */
  89136. + struct {
  89137. + /** Probe Discharge (PRB_DSCHG)
  89138. + * These bits set the times for TADP_DSCHG.
  89139. + * These bits are defined as follows:
  89140. + * 2'b00 - 4 msec
  89141. + * 2'b01 - 8 msec
  89142. + * 2'b10 - 16 msec
  89143. + * 2'b11 - 32 msec
  89144. + */
  89145. + unsigned prb_dschg:2;
  89146. + /** Probe Delta (PRB_DELTA)
  89147. + * These bits set the resolution for RTIM value.
  89148. + * The bits are defined in units of 32 kHz clock cycles as follows:
  89149. + * 2'b00 - 1 cycles
  89150. + * 2'b01 - 2 cycles
  89151. + * 2'b10 - 3 cycles
  89152. + * 2'b11 - 4 cycles
  89153. + * For example if this value is chosen to 2'b01, it means that RTIM
  89154. + * increments for every 3(three) 32Khz clock cycles.
  89155. + */
  89156. + unsigned prb_delta:2;
  89157. + /** Probe Period (PRB_PER)
  89158. + * These bits sets the TADP_PRD as shown in Figure 4 as follows:
  89159. + * 2'b00 - 0.625 to 0.925 sec (typical 0.775 sec)
  89160. + * 2'b01 - 1.25 to 1.85 sec (typical 1.55 sec)
  89161. + * 2'b10 - 1.9 to 2.6 sec (typical 2.275 sec)
  89162. + * 2'b11 - Reserved
  89163. + */
  89164. + unsigned prb_per:2;
  89165. + /** These bits capture the latest time it took for VBUS to ramp from
  89166. + * VADP_SINK to VADP_PRB.
  89167. + * 0x000 - 1 cycles
  89168. + * 0x001 - 2 cycles
  89169. + * 0x002 - 3 cycles
  89170. + * etc
  89171. + * 0x7FF - 2048 cycles
  89172. + * A time of 1024 cycles at 32 kHz corresponds to a time of 32 msec.
  89173. + */
  89174. + unsigned rtim:11;
  89175. + /** Enable Probe (EnaPrb)
  89176. + * When programmed to 1'b1, the core performs a probe operation.
  89177. + * This bit is valid only if OTG_Ver = 1'b1.
  89178. + */
  89179. + unsigned enaprb:1;
  89180. + /** Enable Sense (EnaSns)
  89181. + * When programmed to 1'b1, the core performs a Sense operation.
  89182. + * This bit is valid only if OTG_Ver = 1'b1.
  89183. + */
  89184. + unsigned enasns:1;
  89185. + /** ADP Reset (ADPRes)
  89186. + * When set, ADP controller is reset.
  89187. + * This bit is valid only if OTG_Ver = 1'b1.
  89188. + */
  89189. + unsigned adpres:1;
  89190. + /** ADP Enable (ADPEn)
  89191. + * When set, the core performs either ADP probing or sensing
  89192. + * based on EnaPrb or EnaSns.
  89193. + * This bit is valid only if OTG_Ver = 1'b1.
  89194. + */
  89195. + unsigned adpen:1;
  89196. + /** ADP Probe Interrupt (ADP_PRB_INT)
  89197. + * When this bit is set, it means that the VBUS
  89198. + * voltage is greater than VADP_PRB or VADP_PRB is reached.
  89199. + * This bit is valid only if OTG_Ver = 1'b1.
  89200. + */
  89201. + unsigned adp_prb_int:1;
  89202. + /**
  89203. + * ADP Sense Interrupt (ADP_SNS_INT)
  89204. + * When this bit is set, it means that the VBUS voltage is greater than
  89205. + * VADP_SNS value or VADP_SNS is reached.
  89206. + * This bit is valid only if OTG_Ver = 1'b1.
  89207. + */
  89208. + unsigned adp_sns_int:1;
  89209. + /** ADP Tomeout Interrupt (ADP_TMOUT_INT)
  89210. + * This bit is relevant only for an ADP probe.
  89211. + * When this bit is set, it means that the ramp time has
  89212. + * completed ie ADPCTL.RTIM has reached its terminal value
  89213. + * of 0x7FF. This is a debug feature that allows software
  89214. + * to read the ramp time after each cycle.
  89215. + * This bit is valid only if OTG_Ver = 1'b1.
  89216. + */
  89217. + unsigned adp_tmout_int:1;
  89218. + /** ADP Probe Interrupt Mask (ADP_PRB_INT_MSK)
  89219. + * When this bit is set, it unmasks the interrupt due to ADP_PRB_INT.
  89220. + * This bit is valid only if OTG_Ver = 1'b1.
  89221. + */
  89222. + unsigned adp_prb_int_msk:1;
  89223. + /** ADP Sense Interrupt Mask (ADP_SNS_INT_MSK)
  89224. + * When this bit is set, it unmasks the interrupt due to ADP_SNS_INT.
  89225. + * This bit is valid only if OTG_Ver = 1'b1.
  89226. + */
  89227. + unsigned adp_sns_int_msk:1;
  89228. + /** ADP Timoeout Interrupt Mask (ADP_TMOUT_MSK)
  89229. + * When this bit is set, it unmasks the interrupt due to ADP_TMOUT_INT.
  89230. + * This bit is valid only if OTG_Ver = 1'b1.
  89231. + */
  89232. + unsigned adp_tmout_int_msk:1;
  89233. + /** Access Request
  89234. + * 2'b00 - Read/Write Valid (updated by the core)
  89235. + * 2'b01 - Read
  89236. + * 2'b00 - Write
  89237. + * 2'b00 - Reserved
  89238. + */
  89239. + unsigned ar:2;
  89240. + /** Reserved */
  89241. + unsigned reserved29_31:3;
  89242. + } b;
  89243. +} adpctl_data_t;
  89244. +
  89245. +////////////////////////////////////////////
  89246. +// Device Registers
  89247. +/**
  89248. + * Device Global Registers. <i>Offsets 800h-BFFh</i>
  89249. + *
  89250. + * The following structures define the size and relative field offsets
  89251. + * for the Device Mode Registers.
  89252. + *
  89253. + * <i>These registers are visible only in Device mode and must not be
  89254. + * accessed in Host mode, as the results are unknown.</i>
  89255. + */
  89256. +typedef struct dwc_otg_dev_global_regs {
  89257. + /** Device Configuration Register. <i>Offset 800h</i> */
  89258. + volatile uint32_t dcfg;
  89259. + /** Device Control Register. <i>Offset: 804h</i> */
  89260. + volatile uint32_t dctl;
  89261. + /** Device Status Register (Read Only). <i>Offset: 808h</i> */
  89262. + volatile uint32_t dsts;
  89263. + /** Reserved. <i>Offset: 80Ch</i> */
  89264. + uint32_t unused;
  89265. + /** Device IN Endpoint Common Interrupt Mask
  89266. + * Register. <i>Offset: 810h</i> */
  89267. + volatile uint32_t diepmsk;
  89268. + /** Device OUT Endpoint Common Interrupt Mask
  89269. + * Register. <i>Offset: 814h</i> */
  89270. + volatile uint32_t doepmsk;
  89271. + /** Device All Endpoints Interrupt Register. <i>Offset: 818h</i> */
  89272. + volatile uint32_t daint;
  89273. + /** Device All Endpoints Interrupt Mask Register. <i>Offset:
  89274. + * 81Ch</i> */
  89275. + volatile uint32_t daintmsk;
  89276. + /** Device IN Token Queue Read Register-1 (Read Only).
  89277. + * <i>Offset: 820h</i> */
  89278. + volatile uint32_t dtknqr1;
  89279. + /** Device IN Token Queue Read Register-2 (Read Only).
  89280. + * <i>Offset: 824h</i> */
  89281. + volatile uint32_t dtknqr2;
  89282. + /** Device VBUS discharge Register. <i>Offset: 828h</i> */
  89283. + volatile uint32_t dvbusdis;
  89284. + /** Device VBUS Pulse Register. <i>Offset: 82Ch</i> */
  89285. + volatile uint32_t dvbuspulse;
  89286. + /** Device IN Token Queue Read Register-3 (Read Only). /
  89287. + * Device Thresholding control register (Read/Write)
  89288. + * <i>Offset: 830h</i> */
  89289. + volatile uint32_t dtknqr3_dthrctl;
  89290. + /** Device IN Token Queue Read Register-4 (Read Only). /
  89291. + * Device IN EPs empty Inr. Mask Register (Read/Write)
  89292. + * <i>Offset: 834h</i> */
  89293. + volatile uint32_t dtknqr4_fifoemptymsk;
  89294. + /** Device Each Endpoint Interrupt Register (Read Only). /
  89295. + * <i>Offset: 838h</i> */
  89296. + volatile uint32_t deachint;
  89297. + /** Device Each Endpoint Interrupt mask Register (Read/Write). /
  89298. + * <i>Offset: 83Ch</i> */
  89299. + volatile uint32_t deachintmsk;
  89300. + /** Device Each In Endpoint Interrupt mask Register (Read/Write). /
  89301. + * <i>Offset: 840h</i> */
  89302. + volatile uint32_t diepeachintmsk[MAX_EPS_CHANNELS];
  89303. + /** Device Each Out Endpoint Interrupt mask Register (Read/Write). /
  89304. + * <i>Offset: 880h</i> */
  89305. + volatile uint32_t doepeachintmsk[MAX_EPS_CHANNELS];
  89306. +} dwc_otg_device_global_regs_t;
  89307. +
  89308. +/**
  89309. + * This union represents the bit fields in the Device Configuration
  89310. + * Register. Read the register into the <i>d32</i> member then
  89311. + * set/clear the bits using the <i>b</i>it elements. Write the
  89312. + * <i>d32</i> member to the dcfg register.
  89313. + */
  89314. +typedef union dcfg_data {
  89315. + /** raw register data */
  89316. + uint32_t d32;
  89317. + /** register bits */
  89318. + struct {
  89319. + /** Device Speed */
  89320. + unsigned devspd:2;
  89321. + /** Non Zero Length Status OUT Handshake */
  89322. + unsigned nzstsouthshk:1;
  89323. +#define DWC_DCFG_SEND_STALL 1
  89324. +
  89325. + unsigned ena32khzs:1;
  89326. + /** Device Addresses */
  89327. + unsigned devaddr:7;
  89328. + /** Periodic Frame Interval */
  89329. + unsigned perfrint:2;
  89330. +#define DWC_DCFG_FRAME_INTERVAL_80 0
  89331. +#define DWC_DCFG_FRAME_INTERVAL_85 1
  89332. +#define DWC_DCFG_FRAME_INTERVAL_90 2
  89333. +#define DWC_DCFG_FRAME_INTERVAL_95 3
  89334. +
  89335. + /** Enable Device OUT NAK for bulk in DDMA mode */
  89336. + unsigned endevoutnak:1;
  89337. +
  89338. + unsigned reserved14_17:4;
  89339. + /** In Endpoint Mis-match count */
  89340. + unsigned epmscnt:5;
  89341. + /** Enable Descriptor DMA in Device mode */
  89342. + unsigned descdma:1;
  89343. + unsigned perschintvl:2;
  89344. + unsigned resvalid:6;
  89345. + } b;
  89346. +} dcfg_data_t;
  89347. +
  89348. +/**
  89349. + * This union represents the bit fields in the Device Control
  89350. + * Register. Read the register into the <i>d32</i> member then
  89351. + * set/clear the bits using the <i>b</i>it elements.
  89352. + */
  89353. +typedef union dctl_data {
  89354. + /** raw register data */
  89355. + uint32_t d32;
  89356. + /** register bits */
  89357. + struct {
  89358. + /** Remote Wakeup */
  89359. + unsigned rmtwkupsig:1;
  89360. + /** Soft Disconnect */
  89361. + unsigned sftdiscon:1;
  89362. + /** Global Non-Periodic IN NAK Status */
  89363. + unsigned gnpinnaksts:1;
  89364. + /** Global OUT NAK Status */
  89365. + unsigned goutnaksts:1;
  89366. + /** Test Control */
  89367. + unsigned tstctl:3;
  89368. + /** Set Global Non-Periodic IN NAK */
  89369. + unsigned sgnpinnak:1;
  89370. + /** Clear Global Non-Periodic IN NAK */
  89371. + unsigned cgnpinnak:1;
  89372. + /** Set Global OUT NAK */
  89373. + unsigned sgoutnak:1;
  89374. + /** Clear Global OUT NAK */
  89375. + unsigned cgoutnak:1;
  89376. + /** Power-On Programming Done */
  89377. + unsigned pwronprgdone:1;
  89378. + /** Reserved */
  89379. + unsigned reserved:1;
  89380. + /** Global Multi Count */
  89381. + unsigned gmc:2;
  89382. + /** Ignore Frame Number for ISOC EPs */
  89383. + unsigned ifrmnum:1;
  89384. + /** NAK on Babble */
  89385. + unsigned nakonbble:1;
  89386. + /** Enable Continue on BNA */
  89387. + unsigned encontonbna:1;
  89388. +
  89389. + unsigned reserved18_31:14;
  89390. + } b;
  89391. +} dctl_data_t;
  89392. +
  89393. +/**
  89394. + * This union represents the bit fields in the Device Status
  89395. + * Register. Read the register into the <i>d32</i> member then
  89396. + * set/clear the bits using the <i>b</i>it elements.
  89397. + */
  89398. +typedef union dsts_data {
  89399. + /** raw register data */
  89400. + uint32_t d32;
  89401. + /** register bits */
  89402. + struct {
  89403. + /** Suspend Status */
  89404. + unsigned suspsts:1;
  89405. + /** Enumerated Speed */
  89406. + unsigned enumspd:2;
  89407. +#define DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ 0
  89408. +#define DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ 1
  89409. +#define DWC_DSTS_ENUMSPD_LS_PHY_6MHZ 2
  89410. +#define DWC_DSTS_ENUMSPD_FS_PHY_48MHZ 3
  89411. + /** Erratic Error */
  89412. + unsigned errticerr:1;
  89413. + unsigned reserved4_7:4;
  89414. + /** Frame or Microframe Number of the received SOF */
  89415. + unsigned soffn:14;
  89416. + unsigned reserved22_31:10;
  89417. + } b;
  89418. +} dsts_data_t;
  89419. +
  89420. +/**
  89421. + * This union represents the bit fields in the Device IN EP Interrupt
  89422. + * Register and the Device IN EP Common Mask Register.
  89423. + *
  89424. + * - Read the register into the <i>d32</i> member then set/clear the
  89425. + * bits using the <i>b</i>it elements.
  89426. + */
  89427. +typedef union diepint_data {
  89428. + /** raw register data */
  89429. + uint32_t d32;
  89430. + /** register bits */
  89431. + struct {
  89432. + /** Transfer complete mask */
  89433. + unsigned xfercompl:1;
  89434. + /** Endpoint disable mask */
  89435. + unsigned epdisabled:1;
  89436. + /** AHB Error mask */
  89437. + unsigned ahberr:1;
  89438. + /** TimeOUT Handshake mask (non-ISOC EPs) */
  89439. + unsigned timeout:1;
  89440. + /** IN Token received with TxF Empty mask */
  89441. + unsigned intktxfemp:1;
  89442. + /** IN Token Received with EP mismatch mask */
  89443. + unsigned intknepmis:1;
  89444. + /** IN Endpoint NAK Effective mask */
  89445. + unsigned inepnakeff:1;
  89446. + /** Reserved */
  89447. + unsigned emptyintr:1;
  89448. +
  89449. + unsigned txfifoundrn:1;
  89450. +
  89451. + /** BNA Interrupt mask */
  89452. + unsigned bna:1;
  89453. +
  89454. + unsigned reserved10_12:3;
  89455. + /** BNA Interrupt mask */
  89456. + unsigned nak:1;
  89457. +
  89458. + unsigned reserved14_31:18;
  89459. + } b;
  89460. +} diepint_data_t;
  89461. +
  89462. +/**
  89463. + * This union represents the bit fields in the Device IN EP
  89464. + * Common/Dedicated Interrupt Mask Register.
  89465. + */
  89466. +typedef union diepint_data diepmsk_data_t;
  89467. +
  89468. +/**
  89469. + * This union represents the bit fields in the Device OUT EP Interrupt
  89470. + * Registerand Device OUT EP Common Interrupt Mask Register.
  89471. + *
  89472. + * - Read the register into the <i>d32</i> member then set/clear the
  89473. + * bits using the <i>b</i>it elements.
  89474. + */
  89475. +typedef union doepint_data {
  89476. + /** raw register data */
  89477. + uint32_t d32;
  89478. + /** register bits */
  89479. + struct {
  89480. + /** Transfer complete */
  89481. + unsigned xfercompl:1;
  89482. + /** Endpoint disable */
  89483. + unsigned epdisabled:1;
  89484. + /** AHB Error */
  89485. + unsigned ahberr:1;
  89486. + /** Setup Phase Done (contorl EPs) */
  89487. + unsigned setup:1;
  89488. + /** OUT Token Received when Endpoint Disabled */
  89489. + unsigned outtknepdis:1;
  89490. +
  89491. + unsigned stsphsercvd:1;
  89492. + /** Back-to-Back SETUP Packets Received */
  89493. + unsigned back2backsetup:1;
  89494. +
  89495. + unsigned reserved7:1;
  89496. + /** OUT packet Error */
  89497. + unsigned outpkterr:1;
  89498. + /** BNA Interrupt */
  89499. + unsigned bna:1;
  89500. +
  89501. + unsigned reserved10:1;
  89502. + /** Packet Drop Status */
  89503. + unsigned pktdrpsts:1;
  89504. + /** Babble Interrupt */
  89505. + unsigned babble:1;
  89506. + /** NAK Interrupt */
  89507. + unsigned nak:1;
  89508. + /** NYET Interrupt */
  89509. + unsigned nyet:1;
  89510. + /** Bit indicating setup packet received */
  89511. + unsigned sr:1;
  89512. +
  89513. + unsigned reserved16_31:16;
  89514. + } b;
  89515. +} doepint_data_t;
  89516. +
  89517. +/**
  89518. + * This union represents the bit fields in the Device OUT EP
  89519. + * Common/Dedicated Interrupt Mask Register.
  89520. + */
  89521. +typedef union doepint_data doepmsk_data_t;
  89522. +
  89523. +/**
  89524. + * This union represents the bit fields in the Device All EP Interrupt
  89525. + * and Mask Registers.
  89526. + * - Read the register into the <i>d32</i> member then set/clear the
  89527. + * bits using the <i>b</i>it elements.
  89528. + */
  89529. +typedef union daint_data {
  89530. + /** raw register data */
  89531. + uint32_t d32;
  89532. + /** register bits */
  89533. + struct {
  89534. + /** IN Endpoint bits */
  89535. + unsigned in:16;
  89536. + /** OUT Endpoint bits */
  89537. + unsigned out:16;
  89538. + } ep;
  89539. + struct {
  89540. + /** IN Endpoint bits */
  89541. + unsigned inep0:1;
  89542. + unsigned inep1:1;
  89543. + unsigned inep2:1;
  89544. + unsigned inep3:1;
  89545. + unsigned inep4:1;
  89546. + unsigned inep5:1;
  89547. + unsigned inep6:1;
  89548. + unsigned inep7:1;
  89549. + unsigned inep8:1;
  89550. + unsigned inep9:1;
  89551. + unsigned inep10:1;
  89552. + unsigned inep11:1;
  89553. + unsigned inep12:1;
  89554. + unsigned inep13:1;
  89555. + unsigned inep14:1;
  89556. + unsigned inep15:1;
  89557. + /** OUT Endpoint bits */
  89558. + unsigned outep0:1;
  89559. + unsigned outep1:1;
  89560. + unsigned outep2:1;
  89561. + unsigned outep3:1;
  89562. + unsigned outep4:1;
  89563. + unsigned outep5:1;
  89564. + unsigned outep6:1;
  89565. + unsigned outep7:1;
  89566. + unsigned outep8:1;
  89567. + unsigned outep9:1;
  89568. + unsigned outep10:1;
  89569. + unsigned outep11:1;
  89570. + unsigned outep12:1;
  89571. + unsigned outep13:1;
  89572. + unsigned outep14:1;
  89573. + unsigned outep15:1;
  89574. + } b;
  89575. +} daint_data_t;
  89576. +
  89577. +/**
  89578. + * This union represents the bit fields in the Device IN Token Queue
  89579. + * Read Registers.
  89580. + * - Read the register into the <i>d32</i> member.
  89581. + * - READ-ONLY Register
  89582. + */
  89583. +typedef union dtknq1_data {
  89584. + /** raw register data */
  89585. + uint32_t d32;
  89586. + /** register bits */
  89587. + struct {
  89588. + /** In Token Queue Write Pointer */
  89589. + unsigned intknwptr:5;
  89590. + /** Reserved */
  89591. + unsigned reserved05_06:2;
  89592. + /** write pointer has wrapped. */
  89593. + unsigned wrap_bit:1;
  89594. + /** EP Numbers of IN Tokens 0 ... 4 */
  89595. + unsigned epnums0_5:24;
  89596. + } b;
  89597. +} dtknq1_data_t;
  89598. +
  89599. +/**
  89600. + * This union represents Threshold control Register
  89601. + * - Read and write the register into the <i>d32</i> member.
  89602. + * - READ-WRITABLE Register
  89603. + */
  89604. +typedef union dthrctl_data {
  89605. + /** raw register data */
  89606. + uint32_t d32;
  89607. + /** register bits */
  89608. + struct {
  89609. + /** non ISO Tx Thr. Enable */
  89610. + unsigned non_iso_thr_en:1;
  89611. + /** ISO Tx Thr. Enable */
  89612. + unsigned iso_thr_en:1;
  89613. + /** Tx Thr. Length */
  89614. + unsigned tx_thr_len:9;
  89615. + /** AHB Threshold ratio */
  89616. + unsigned ahb_thr_ratio:2;
  89617. + /** Reserved */
  89618. + unsigned reserved13_15:3;
  89619. + /** Rx Thr. Enable */
  89620. + unsigned rx_thr_en:1;
  89621. + /** Rx Thr. Length */
  89622. + unsigned rx_thr_len:9;
  89623. + unsigned reserved26:1;
  89624. + /** Arbiter Parking Enable*/
  89625. + unsigned arbprken:1;
  89626. + /** Reserved */
  89627. + unsigned reserved28_31:4;
  89628. + } b;
  89629. +} dthrctl_data_t;
  89630. +
  89631. +/**
  89632. + * Device Logical IN Endpoint-Specific Registers. <i>Offsets
  89633. + * 900h-AFCh</i>
  89634. + *
  89635. + * There will be one set of endpoint registers per logical endpoint
  89636. + * implemented.
  89637. + *
  89638. + * <i>These registers are visible only in Device mode and must not be
  89639. + * accessed in Host mode, as the results are unknown.</i>
  89640. + */
  89641. +typedef struct dwc_otg_dev_in_ep_regs {
  89642. + /** Device IN Endpoint Control Register. <i>Offset:900h +
  89643. + * (ep_num * 20h) + 00h</i> */
  89644. + volatile uint32_t diepctl;
  89645. + /** Reserved. <i>Offset:900h + (ep_num * 20h) + 04h</i> */
  89646. + uint32_t reserved04;
  89647. + /** Device IN Endpoint Interrupt Register. <i>Offset:900h +
  89648. + * (ep_num * 20h) + 08h</i> */
  89649. + volatile uint32_t diepint;
  89650. + /** Reserved. <i>Offset:900h + (ep_num * 20h) + 0Ch</i> */
  89651. + uint32_t reserved0C;
  89652. + /** Device IN Endpoint Transfer Size
  89653. + * Register. <i>Offset:900h + (ep_num * 20h) + 10h</i> */
  89654. + volatile uint32_t dieptsiz;
  89655. + /** Device IN Endpoint DMA Address Register. <i>Offset:900h +
  89656. + * (ep_num * 20h) + 14h</i> */
  89657. + volatile uint32_t diepdma;
  89658. + /** Device IN Endpoint Transmit FIFO Status Register. <i>Offset:900h +
  89659. + * (ep_num * 20h) + 18h</i> */
  89660. + volatile uint32_t dtxfsts;
  89661. + /** Device IN Endpoint DMA Buffer Register. <i>Offset:900h +
  89662. + * (ep_num * 20h) + 1Ch</i> */
  89663. + volatile uint32_t diepdmab;
  89664. +} dwc_otg_dev_in_ep_regs_t;
  89665. +
  89666. +/**
  89667. + * Device Logical OUT Endpoint-Specific Registers. <i>Offsets:
  89668. + * B00h-CFCh</i>
  89669. + *
  89670. + * There will be one set of endpoint registers per logical endpoint
  89671. + * implemented.
  89672. + *
  89673. + * <i>These registers are visible only in Device mode and must not be
  89674. + * accessed in Host mode, as the results are unknown.</i>
  89675. + */
  89676. +typedef struct dwc_otg_dev_out_ep_regs {
  89677. + /** Device OUT Endpoint Control Register. <i>Offset:B00h +
  89678. + * (ep_num * 20h) + 00h</i> */
  89679. + volatile uint32_t doepctl;
  89680. + /** Reserved. <i>Offset:B00h + (ep_num * 20h) + 04h</i> */
  89681. + uint32_t reserved04;
  89682. + /** Device OUT Endpoint Interrupt Register. <i>Offset:B00h +
  89683. + * (ep_num * 20h) + 08h</i> */
  89684. + volatile uint32_t doepint;
  89685. + /** Reserved. <i>Offset:B00h + (ep_num * 20h) + 0Ch</i> */
  89686. + uint32_t reserved0C;
  89687. + /** Device OUT Endpoint Transfer Size Register. <i>Offset:
  89688. + * B00h + (ep_num * 20h) + 10h</i> */
  89689. + volatile uint32_t doeptsiz;
  89690. + /** Device OUT Endpoint DMA Address Register. <i>Offset:B00h
  89691. + * + (ep_num * 20h) + 14h</i> */
  89692. + volatile uint32_t doepdma;
  89693. + /** Reserved. <i>Offset:B00h + * (ep_num * 20h) + 18h</i> */
  89694. + uint32_t unused;
  89695. + /** Device OUT Endpoint DMA Buffer Register. <i>Offset:B00h
  89696. + * + (ep_num * 20h) + 1Ch</i> */
  89697. + uint32_t doepdmab;
  89698. +} dwc_otg_dev_out_ep_regs_t;
  89699. +
  89700. +/**
  89701. + * This union represents the bit fields in the Device EP Control
  89702. + * Register. Read the register into the <i>d32</i> member then
  89703. + * set/clear the bits using the <i>b</i>it elements.
  89704. + */
  89705. +typedef union depctl_data {
  89706. + /** raw register data */
  89707. + uint32_t d32;
  89708. + /** register bits */
  89709. + struct {
  89710. + /** Maximum Packet Size
  89711. + * IN/OUT EPn
  89712. + * IN/OUT EP0 - 2 bits
  89713. + * 2'b00: 64 Bytes
  89714. + * 2'b01: 32
  89715. + * 2'b10: 16
  89716. + * 2'b11: 8 */
  89717. + unsigned mps:11;
  89718. +#define DWC_DEP0CTL_MPS_64 0
  89719. +#define DWC_DEP0CTL_MPS_32 1
  89720. +#define DWC_DEP0CTL_MPS_16 2
  89721. +#define DWC_DEP0CTL_MPS_8 3
  89722. +
  89723. + /** Next Endpoint
  89724. + * IN EPn/IN EP0
  89725. + * OUT EPn/OUT EP0 - reserved */
  89726. + unsigned nextep:4;
  89727. +
  89728. + /** USB Active Endpoint */
  89729. + unsigned usbactep:1;
  89730. +
  89731. + /** Endpoint DPID (INTR/Bulk IN and OUT endpoints)
  89732. + * This field contains the PID of the packet going to
  89733. + * be received or transmitted on this endpoint. The
  89734. + * application should program the PID of the first
  89735. + * packet going to be received or transmitted on this
  89736. + * endpoint , after the endpoint is
  89737. + * activated. Application use the SetD1PID and
  89738. + * SetD0PID fields of this register to program either
  89739. + * D0 or D1 PID.
  89740. + *
  89741. + * The encoding for this field is
  89742. + * - 0: D0
  89743. + * - 1: D1
  89744. + */
  89745. + unsigned dpid:1;
  89746. +
  89747. + /** NAK Status */
  89748. + unsigned naksts:1;
  89749. +
  89750. + /** Endpoint Type
  89751. + * 2'b00: Control
  89752. + * 2'b01: Isochronous
  89753. + * 2'b10: Bulk
  89754. + * 2'b11: Interrupt */
  89755. + unsigned eptype:2;
  89756. +
  89757. + /** Snoop Mode
  89758. + * OUT EPn/OUT EP0
  89759. + * IN EPn/IN EP0 - reserved */
  89760. + unsigned snp:1;
  89761. +
  89762. + /** Stall Handshake */
  89763. + unsigned stall:1;
  89764. +
  89765. + /** Tx Fifo Number
  89766. + * IN EPn/IN EP0
  89767. + * OUT EPn/OUT EP0 - reserved */
  89768. + unsigned txfnum:4;
  89769. +
  89770. + /** Clear NAK */
  89771. + unsigned cnak:1;
  89772. + /** Set NAK */
  89773. + unsigned snak:1;
  89774. + /** Set DATA0 PID (INTR/Bulk IN and OUT endpoints)
  89775. + * Writing to this field sets the Endpoint DPID (DPID)
  89776. + * field in this register to DATA0. Set Even
  89777. + * (micro)frame (SetEvenFr) (ISO IN and OUT Endpoints)
  89778. + * Writing to this field sets the Even/Odd
  89779. + * (micro)frame (EO_FrNum) field to even (micro)
  89780. + * frame.
  89781. + */
  89782. + unsigned setd0pid:1;
  89783. + /** Set DATA1 PID (INTR/Bulk IN and OUT endpoints)
  89784. + * Writing to this field sets the Endpoint DPID (DPID)
  89785. + * field in this register to DATA1 Set Odd
  89786. + * (micro)frame (SetOddFr) (ISO IN and OUT Endpoints)
  89787. + * Writing to this field sets the Even/Odd
  89788. + * (micro)frame (EO_FrNum) field to odd (micro) frame.
  89789. + */
  89790. + unsigned setd1pid:1;
  89791. +
  89792. + /** Endpoint Disable */
  89793. + unsigned epdis:1;
  89794. + /** Endpoint Enable */
  89795. + unsigned epena:1;
  89796. + } b;
  89797. +} depctl_data_t;
  89798. +
  89799. +/**
  89800. + * This union represents the bit fields in the Device EP Transfer
  89801. + * Size Register. Read the register into the <i>d32</i> member then
  89802. + * set/clear the bits using the <i>b</i>it elements.
  89803. + */
  89804. +typedef union deptsiz_data {
  89805. + /** raw register data */
  89806. + uint32_t d32;
  89807. + /** register bits */
  89808. + struct {
  89809. + /** Transfer size */
  89810. + unsigned xfersize:19;
  89811. +/** Max packet count for EP (pow(2,10)-1) */
  89812. +#define MAX_PKT_CNT 1023
  89813. + /** Packet Count */
  89814. + unsigned pktcnt:10;
  89815. + /** Multi Count - Periodic IN endpoints */
  89816. + unsigned mc:2;
  89817. + unsigned reserved:1;
  89818. + } b;
  89819. +} deptsiz_data_t;
  89820. +
  89821. +/**
  89822. + * This union represents the bit fields in the Device EP 0 Transfer
  89823. + * Size Register. Read the register into the <i>d32</i> member then
  89824. + * set/clear the bits using the <i>b</i>it elements.
  89825. + */
  89826. +typedef union deptsiz0_data {
  89827. + /** raw register data */
  89828. + uint32_t d32;
  89829. + /** register bits */
  89830. + struct {
  89831. + /** Transfer size */
  89832. + unsigned xfersize:7;
  89833. + /** Reserved */
  89834. + unsigned reserved7_18:12;
  89835. + /** Packet Count */
  89836. + unsigned pktcnt:2;
  89837. + /** Reserved */
  89838. + unsigned reserved21_28:8;
  89839. + /**Setup Packet Count (DOEPTSIZ0 Only) */
  89840. + unsigned supcnt:2;
  89841. + unsigned reserved31;
  89842. + } b;
  89843. +} deptsiz0_data_t;
  89844. +
  89845. +/////////////////////////////////////////////////
  89846. +// DMA Descriptor Specific Structures
  89847. +//
  89848. +
  89849. +/** Buffer status definitions */
  89850. +
  89851. +#define BS_HOST_READY 0x0
  89852. +#define BS_DMA_BUSY 0x1
  89853. +#define BS_DMA_DONE 0x2
  89854. +#define BS_HOST_BUSY 0x3
  89855. +
  89856. +/** Receive/Transmit status definitions */
  89857. +
  89858. +#define RTS_SUCCESS 0x0
  89859. +#define RTS_BUFFLUSH 0x1
  89860. +#define RTS_RESERVED 0x2
  89861. +#define RTS_BUFERR 0x3
  89862. +
  89863. +/**
  89864. + * This union represents the bit fields in the DMA Descriptor
  89865. + * status quadlet. Read the quadlet into the <i>d32</i> member then
  89866. + * set/clear the bits using the <i>b</i>it, <i>b_iso_out</i> and
  89867. + * <i>b_iso_in</i> elements.
  89868. + */
  89869. +typedef union dev_dma_desc_sts {
  89870. + /** raw register data */
  89871. + uint32_t d32;
  89872. + /** quadlet bits */
  89873. + struct {
  89874. + /** Received number of bytes */
  89875. + unsigned bytes:16;
  89876. + /** NAK bit - only for OUT EPs */
  89877. + unsigned nak:1;
  89878. + unsigned reserved17_22:6;
  89879. + /** Multiple Transfer - only for OUT EPs */
  89880. + unsigned mtrf:1;
  89881. + /** Setup Packet received - only for OUT EPs */
  89882. + unsigned sr:1;
  89883. + /** Interrupt On Complete */
  89884. + unsigned ioc:1;
  89885. + /** Short Packet */
  89886. + unsigned sp:1;
  89887. + /** Last */
  89888. + unsigned l:1;
  89889. + /** Receive Status */
  89890. + unsigned sts:2;
  89891. + /** Buffer Status */
  89892. + unsigned bs:2;
  89893. + } b;
  89894. +
  89895. +//#ifdef DWC_EN_ISOC
  89896. + /** iso out quadlet bits */
  89897. + struct {
  89898. + /** Received number of bytes */
  89899. + unsigned rxbytes:11;
  89900. +
  89901. + unsigned reserved11:1;
  89902. + /** Frame Number */
  89903. + unsigned framenum:11;
  89904. + /** Received ISO Data PID */
  89905. + unsigned pid:2;
  89906. + /** Interrupt On Complete */
  89907. + unsigned ioc:1;
  89908. + /** Short Packet */
  89909. + unsigned sp:1;
  89910. + /** Last */
  89911. + unsigned l:1;
  89912. + /** Receive Status */
  89913. + unsigned rxsts:2;
  89914. + /** Buffer Status */
  89915. + unsigned bs:2;
  89916. + } b_iso_out;
  89917. +
  89918. + /** iso in quadlet bits */
  89919. + struct {
  89920. + /** Transmited number of bytes */
  89921. + unsigned txbytes:12;
  89922. + /** Frame Number */
  89923. + unsigned framenum:11;
  89924. + /** Transmited ISO Data PID */
  89925. + unsigned pid:2;
  89926. + /** Interrupt On Complete */
  89927. + unsigned ioc:1;
  89928. + /** Short Packet */
  89929. + unsigned sp:1;
  89930. + /** Last */
  89931. + unsigned l:1;
  89932. + /** Transmit Status */
  89933. + unsigned txsts:2;
  89934. + /** Buffer Status */
  89935. + unsigned bs:2;
  89936. + } b_iso_in;
  89937. +//#endif /* DWC_EN_ISOC */
  89938. +} dev_dma_desc_sts_t;
  89939. +
  89940. +/**
  89941. + * DMA Descriptor structure
  89942. + *
  89943. + * DMA Descriptor structure contains two quadlets:
  89944. + * Status quadlet and Data buffer pointer.
  89945. + */
  89946. +typedef struct dwc_otg_dev_dma_desc {
  89947. + /** DMA Descriptor status quadlet */
  89948. + dev_dma_desc_sts_t status;
  89949. + /** DMA Descriptor data buffer pointer */
  89950. + uint32_t buf;
  89951. +} dwc_otg_dev_dma_desc_t;
  89952. +
  89953. +/**
  89954. + * The dwc_otg_dev_if structure contains information needed to manage
  89955. + * the DWC_otg controller acting in device mode. It represents the
  89956. + * programming view of the device-specific aspects of the controller.
  89957. + */
  89958. +typedef struct dwc_otg_dev_if {
  89959. + /** Pointer to device Global registers.
  89960. + * Device Global Registers starting at offset 800h
  89961. + */
  89962. + dwc_otg_device_global_regs_t *dev_global_regs;
  89963. +#define DWC_DEV_GLOBAL_REG_OFFSET 0x800
  89964. +
  89965. + /**
  89966. + * Device Logical IN Endpoint-Specific Registers 900h-AFCh
  89967. + */
  89968. + dwc_otg_dev_in_ep_regs_t *in_ep_regs[MAX_EPS_CHANNELS];
  89969. +#define DWC_DEV_IN_EP_REG_OFFSET 0x900
  89970. +#define DWC_EP_REG_OFFSET 0x20
  89971. +
  89972. + /** Device Logical OUT Endpoint-Specific Registers B00h-CFCh */
  89973. + dwc_otg_dev_out_ep_regs_t *out_ep_regs[MAX_EPS_CHANNELS];
  89974. +#define DWC_DEV_OUT_EP_REG_OFFSET 0xB00
  89975. +
  89976. + /* Device configuration information */
  89977. + uint8_t speed; /**< Device Speed 0: Unknown, 1: LS, 2:FS, 3: HS */
  89978. + uint8_t num_in_eps; /**< Number # of Tx EP range: 0-15 exept ep0 */
  89979. + uint8_t num_out_eps; /**< Number # of Rx EP range: 0-15 exept ep 0*/
  89980. +
  89981. + /** Size of periodic FIFOs (Bytes) */
  89982. + uint16_t perio_tx_fifo_size[MAX_PERIO_FIFOS];
  89983. +
  89984. + /** Size of Tx FIFOs (Bytes) */
  89985. + uint16_t tx_fifo_size[MAX_TX_FIFOS];
  89986. +
  89987. + /** Thresholding enable flags and length varaiables **/
  89988. + uint16_t rx_thr_en;
  89989. + uint16_t iso_tx_thr_en;
  89990. + uint16_t non_iso_tx_thr_en;
  89991. +
  89992. + uint16_t rx_thr_length;
  89993. + uint16_t tx_thr_length;
  89994. +
  89995. + /**
  89996. + * Pointers to the DMA Descriptors for EP0 Control
  89997. + * transfers (virtual and physical)
  89998. + */
  89999. +
  90000. + /** 2 descriptors for SETUP packets */
  90001. + dwc_dma_t dma_setup_desc_addr[2];
  90002. + dwc_otg_dev_dma_desc_t *setup_desc_addr[2];
  90003. +
  90004. + /** Pointer to Descriptor with latest SETUP packet */
  90005. + dwc_otg_dev_dma_desc_t *psetup;
  90006. +
  90007. + /** Index of current SETUP handler descriptor */
  90008. + uint32_t setup_desc_index;
  90009. +
  90010. + /** Descriptor for Data In or Status In phases */
  90011. + dwc_dma_t dma_in_desc_addr;
  90012. + dwc_otg_dev_dma_desc_t *in_desc_addr;
  90013. +
  90014. + /** Descriptor for Data Out or Status Out phases */
  90015. + dwc_dma_t dma_out_desc_addr;
  90016. + dwc_otg_dev_dma_desc_t *out_desc_addr;
  90017. +
  90018. + /** Setup Packet Detected - if set clear NAK when queueing */
  90019. + uint32_t spd;
  90020. + /** Isoc ep pointer on which incomplete happens */
  90021. + void *isoc_ep;
  90022. +
  90023. +} dwc_otg_dev_if_t;
  90024. +
  90025. +/////////////////////////////////////////////////
  90026. +// Host Mode Register Structures
  90027. +//
  90028. +/**
  90029. + * The Host Global Registers structure defines the size and relative
  90030. + * field offsets for the Host Mode Global Registers. Host Global
  90031. + * Registers offsets 400h-7FFh.
  90032. +*/
  90033. +typedef struct dwc_otg_host_global_regs {
  90034. + /** Host Configuration Register. <i>Offset: 400h</i> */
  90035. + volatile uint32_t hcfg;
  90036. + /** Host Frame Interval Register. <i>Offset: 404h</i> */
  90037. + volatile uint32_t hfir;
  90038. + /** Host Frame Number / Frame Remaining Register. <i>Offset: 408h</i> */
  90039. + volatile uint32_t hfnum;
  90040. + /** Reserved. <i>Offset: 40Ch</i> */
  90041. + uint32_t reserved40C;
  90042. + /** Host Periodic Transmit FIFO/ Queue Status Register. <i>Offset: 410h</i> */
  90043. + volatile uint32_t hptxsts;
  90044. + /** Host All Channels Interrupt Register. <i>Offset: 414h</i> */
  90045. + volatile uint32_t haint;
  90046. + /** Host All Channels Interrupt Mask Register. <i>Offset: 418h</i> */
  90047. + volatile uint32_t haintmsk;
  90048. + /** Host Frame List Base Address Register . <i>Offset: 41Ch</i> */
  90049. + volatile uint32_t hflbaddr;
  90050. +} dwc_otg_host_global_regs_t;
  90051. +
  90052. +/**
  90053. + * This union represents the bit fields in the Host Configuration Register.
  90054. + * Read the register into the <i>d32</i> member then set/clear the bits using
  90055. + * the <i>b</i>it elements. Write the <i>d32</i> member to the hcfg register.
  90056. + */
  90057. +typedef union hcfg_data {
  90058. + /** raw register data */
  90059. + uint32_t d32;
  90060. +
  90061. + /** register bits */
  90062. + struct {
  90063. + /** FS/LS Phy Clock Select */
  90064. + unsigned fslspclksel:2;
  90065. +#define DWC_HCFG_30_60_MHZ 0
  90066. +#define DWC_HCFG_48_MHZ 1
  90067. +#define DWC_HCFG_6_MHZ 2
  90068. +
  90069. + /** FS/LS Only Support */
  90070. + unsigned fslssupp:1;
  90071. + unsigned reserved3_6:4;
  90072. + /** Enable 32-KHz Suspend Mode */
  90073. + unsigned ena32khzs:1;
  90074. + /** Resume Validation Periiod */
  90075. + unsigned resvalid:8;
  90076. + unsigned reserved16_22:7;
  90077. + /** Enable Scatter/gather DMA in Host mode */
  90078. + unsigned descdma:1;
  90079. + /** Frame List Entries */
  90080. + unsigned frlisten:2;
  90081. + /** Enable Periodic Scheduling */
  90082. + unsigned perschedena:1;
  90083. + unsigned reserved27_30:4;
  90084. + unsigned modechtimen:1;
  90085. + } b;
  90086. +} hcfg_data_t;
  90087. +
  90088. +/**
  90089. + * This union represents the bit fields in the Host Frame Remaing/Number
  90090. + * Register.
  90091. + */
  90092. +typedef union hfir_data {
  90093. + /** raw register data */
  90094. + uint32_t d32;
  90095. +
  90096. + /** register bits */
  90097. + struct {
  90098. + unsigned frint:16;
  90099. + unsigned hfirrldctrl:1;
  90100. + unsigned reserved:15;
  90101. + } b;
  90102. +} hfir_data_t;
  90103. +
  90104. +/**
  90105. + * This union represents the bit fields in the Host Frame Remaing/Number
  90106. + * Register.
  90107. + */
  90108. +typedef union hfnum_data {
  90109. + /** raw register data */
  90110. + uint32_t d32;
  90111. +
  90112. + /** register bits */
  90113. + struct {
  90114. + unsigned frnum:16;
  90115. +#define DWC_HFNUM_MAX_FRNUM 0x3FFF
  90116. + unsigned frrem:16;
  90117. + } b;
  90118. +} hfnum_data_t;
  90119. +
  90120. +typedef union hptxsts_data {
  90121. + /** raw register data */
  90122. + uint32_t d32;
  90123. +
  90124. + /** register bits */
  90125. + struct {
  90126. + unsigned ptxfspcavail:16;
  90127. + unsigned ptxqspcavail:8;
  90128. + /** Top of the Periodic Transmit Request Queue
  90129. + * - bit 24 - Terminate (last entry for the selected channel)
  90130. + * - bits 26:25 - Token Type
  90131. + * - 2'b00 - Zero length
  90132. + * - 2'b01 - Ping
  90133. + * - 2'b10 - Disable
  90134. + * - bits 30:27 - Channel Number
  90135. + * - bit 31 - Odd/even microframe
  90136. + */
  90137. + unsigned ptxqtop_terminate:1;
  90138. + unsigned ptxqtop_token:2;
  90139. + unsigned ptxqtop_chnum:4;
  90140. + unsigned ptxqtop_odd:1;
  90141. + } b;
  90142. +} hptxsts_data_t;
  90143. +
  90144. +/**
  90145. + * This union represents the bit fields in the Host Port Control and Status
  90146. + * Register. Read the register into the <i>d32</i> member then set/clear the
  90147. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  90148. + * hprt0 register.
  90149. + */
  90150. +typedef union hprt0_data {
  90151. + /** raw register data */
  90152. + uint32_t d32;
  90153. + /** register bits */
  90154. + struct {
  90155. + unsigned prtconnsts:1;
  90156. + unsigned prtconndet:1;
  90157. + unsigned prtena:1;
  90158. + unsigned prtenchng:1;
  90159. + unsigned prtovrcurract:1;
  90160. + unsigned prtovrcurrchng:1;
  90161. + unsigned prtres:1;
  90162. + unsigned prtsusp:1;
  90163. + unsigned prtrst:1;
  90164. + unsigned reserved9:1;
  90165. + unsigned prtlnsts:2;
  90166. + unsigned prtpwr:1;
  90167. + unsigned prttstctl:4;
  90168. + unsigned prtspd:2;
  90169. +#define DWC_HPRT0_PRTSPD_HIGH_SPEED 0
  90170. +#define DWC_HPRT0_PRTSPD_FULL_SPEED 1
  90171. +#define DWC_HPRT0_PRTSPD_LOW_SPEED 2
  90172. + unsigned reserved19_31:13;
  90173. + } b;
  90174. +} hprt0_data_t;
  90175. +
  90176. +/**
  90177. + * This union represents the bit fields in the Host All Interrupt
  90178. + * Register.
  90179. + */
  90180. +typedef union haint_data {
  90181. + /** raw register data */
  90182. + uint32_t d32;
  90183. + /** register bits */
  90184. + struct {
  90185. + unsigned ch0:1;
  90186. + unsigned ch1:1;
  90187. + unsigned ch2:1;
  90188. + unsigned ch3:1;
  90189. + unsigned ch4:1;
  90190. + unsigned ch5:1;
  90191. + unsigned ch6:1;
  90192. + unsigned ch7:1;
  90193. + unsigned ch8:1;
  90194. + unsigned ch9:1;
  90195. + unsigned ch10:1;
  90196. + unsigned ch11:1;
  90197. + unsigned ch12:1;
  90198. + unsigned ch13:1;
  90199. + unsigned ch14:1;
  90200. + unsigned ch15:1;
  90201. + unsigned reserved:16;
  90202. + } b;
  90203. +
  90204. + struct {
  90205. + unsigned chint:16;
  90206. + unsigned reserved:16;
  90207. + } b2;
  90208. +} haint_data_t;
  90209. +
  90210. +/**
  90211. + * This union represents the bit fields in the Host All Interrupt
  90212. + * Register.
  90213. + */
  90214. +typedef union haintmsk_data {
  90215. + /** raw register data */
  90216. + uint32_t d32;
  90217. + /** register bits */
  90218. + struct {
  90219. + unsigned ch0:1;
  90220. + unsigned ch1:1;
  90221. + unsigned ch2:1;
  90222. + unsigned ch3:1;
  90223. + unsigned ch4:1;
  90224. + unsigned ch5:1;
  90225. + unsigned ch6:1;
  90226. + unsigned ch7:1;
  90227. + unsigned ch8:1;
  90228. + unsigned ch9:1;
  90229. + unsigned ch10:1;
  90230. + unsigned ch11:1;
  90231. + unsigned ch12:1;
  90232. + unsigned ch13:1;
  90233. + unsigned ch14:1;
  90234. + unsigned ch15:1;
  90235. + unsigned reserved:16;
  90236. + } b;
  90237. +
  90238. + struct {
  90239. + unsigned chint:16;
  90240. + unsigned reserved:16;
  90241. + } b2;
  90242. +} haintmsk_data_t;
  90243. +
  90244. +/**
  90245. + * Host Channel Specific Registers. <i>500h-5FCh</i>
  90246. + */
  90247. +typedef struct dwc_otg_hc_regs {
  90248. + /** Host Channel 0 Characteristic Register. <i>Offset: 500h + (chan_num * 20h) + 00h</i> */
  90249. + volatile uint32_t hcchar;
  90250. + /** Host Channel 0 Split Control Register. <i>Offset: 500h + (chan_num * 20h) + 04h</i> */
  90251. + volatile uint32_t hcsplt;
  90252. + /** Host Channel 0 Interrupt Register. <i>Offset: 500h + (chan_num * 20h) + 08h</i> */
  90253. + volatile uint32_t hcint;
  90254. + /** Host Channel 0 Interrupt Mask Register. <i>Offset: 500h + (chan_num * 20h) + 0Ch</i> */
  90255. + volatile uint32_t hcintmsk;
  90256. + /** Host Channel 0 Transfer Size Register. <i>Offset: 500h + (chan_num * 20h) + 10h</i> */
  90257. + volatile uint32_t hctsiz;
  90258. + /** Host Channel 0 DMA Address Register. <i>Offset: 500h + (chan_num * 20h) + 14h</i> */
  90259. + volatile uint32_t hcdma;
  90260. + volatile uint32_t reserved;
  90261. + /** Host Channel 0 DMA Buffer Address Register. <i>Offset: 500h + (chan_num * 20h) + 1Ch</i> */
  90262. + volatile uint32_t hcdmab;
  90263. +} dwc_otg_hc_regs_t;
  90264. +
  90265. +/**
  90266. + * This union represents the bit fields in the Host Channel Characteristics
  90267. + * Register. Read the register into the <i>d32</i> member then set/clear the
  90268. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  90269. + * hcchar register.
  90270. + */
  90271. +typedef union hcchar_data {
  90272. + /** raw register data */
  90273. + uint32_t d32;
  90274. +
  90275. + /** register bits */
  90276. + struct {
  90277. + /** Maximum packet size in bytes */
  90278. + unsigned mps:11;
  90279. +
  90280. + /** Endpoint number */
  90281. + unsigned epnum:4;
  90282. +
  90283. + /** 0: OUT, 1: IN */
  90284. + unsigned epdir:1;
  90285. +
  90286. + unsigned reserved:1;
  90287. +
  90288. + /** 0: Full/high speed device, 1: Low speed device */
  90289. + unsigned lspddev:1;
  90290. +
  90291. + /** 0: Control, 1: Isoc, 2: Bulk, 3: Intr */
  90292. + unsigned eptype:2;
  90293. +
  90294. + /** Packets per frame for periodic transfers. 0 is reserved. */
  90295. + unsigned multicnt:2;
  90296. +
  90297. + /** Device address */
  90298. + unsigned devaddr:7;
  90299. +
  90300. + /**
  90301. + * Frame to transmit periodic transaction.
  90302. + * 0: even, 1: odd
  90303. + */
  90304. + unsigned oddfrm:1;
  90305. +
  90306. + /** Channel disable */
  90307. + unsigned chdis:1;
  90308. +
  90309. + /** Channel enable */
  90310. + unsigned chen:1;
  90311. + } b;
  90312. +} hcchar_data_t;
  90313. +
  90314. +typedef union hcsplt_data {
  90315. + /** raw register data */
  90316. + uint32_t d32;
  90317. +
  90318. + /** register bits */
  90319. + struct {
  90320. + /** Port Address */
  90321. + unsigned prtaddr:7;
  90322. +
  90323. + /** Hub Address */
  90324. + unsigned hubaddr:7;
  90325. +
  90326. + /** Transaction Position */
  90327. + unsigned xactpos:2;
  90328. +#define DWC_HCSPLIT_XACTPOS_MID 0
  90329. +#define DWC_HCSPLIT_XACTPOS_END 1
  90330. +#define DWC_HCSPLIT_XACTPOS_BEGIN 2
  90331. +#define DWC_HCSPLIT_XACTPOS_ALL 3
  90332. +
  90333. + /** Do Complete Split */
  90334. + unsigned compsplt:1;
  90335. +
  90336. + /** Reserved */
  90337. + unsigned reserved:14;
  90338. +
  90339. + /** Split Enble */
  90340. + unsigned spltena:1;
  90341. + } b;
  90342. +} hcsplt_data_t;
  90343. +
  90344. +/**
  90345. + * This union represents the bit fields in the Host All Interrupt
  90346. + * Register.
  90347. + */
  90348. +typedef union hcint_data {
  90349. + /** raw register data */
  90350. + uint32_t d32;
  90351. + /** register bits */
  90352. + struct {
  90353. + /** Transfer Complete */
  90354. + unsigned xfercomp:1;
  90355. + /** Channel Halted */
  90356. + unsigned chhltd:1;
  90357. + /** AHB Error */
  90358. + unsigned ahberr:1;
  90359. + /** STALL Response Received */
  90360. + unsigned stall:1;
  90361. + /** NAK Response Received */
  90362. + unsigned nak:1;
  90363. + /** ACK Response Received */
  90364. + unsigned ack:1;
  90365. + /** NYET Response Received */
  90366. + unsigned nyet:1;
  90367. + /** Transaction Err */
  90368. + unsigned xacterr:1;
  90369. + /** Babble Error */
  90370. + unsigned bblerr:1;
  90371. + /** Frame Overrun */
  90372. + unsigned frmovrun:1;
  90373. + /** Data Toggle Error */
  90374. + unsigned datatglerr:1;
  90375. + /** Buffer Not Available (only for DDMA mode) */
  90376. + unsigned bna:1;
  90377. + /** Exessive transaction error (only for DDMA mode) */
  90378. + unsigned xcs_xact:1;
  90379. + /** Frame List Rollover interrupt */
  90380. + unsigned frm_list_roll:1;
  90381. + /** Reserved */
  90382. + unsigned reserved14_31:18;
  90383. + } b;
  90384. +} hcint_data_t;
  90385. +
  90386. +/**
  90387. + * This union represents the bit fields in the Host Channel Interrupt Mask
  90388. + * Register. Read the register into the <i>d32</i> member then set/clear the
  90389. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  90390. + * hcintmsk register.
  90391. + */
  90392. +typedef union hcintmsk_data {
  90393. + /** raw register data */
  90394. + uint32_t d32;
  90395. +
  90396. + /** register bits */
  90397. + struct {
  90398. + unsigned xfercompl:1;
  90399. + unsigned chhltd:1;
  90400. + unsigned ahberr:1;
  90401. + unsigned stall:1;
  90402. + unsigned nak:1;
  90403. + unsigned ack:1;
  90404. + unsigned nyet:1;
  90405. + unsigned xacterr:1;
  90406. + unsigned bblerr:1;
  90407. + unsigned frmovrun:1;
  90408. + unsigned datatglerr:1;
  90409. + unsigned bna:1;
  90410. + unsigned xcs_xact:1;
  90411. + unsigned frm_list_roll:1;
  90412. + unsigned reserved14_31:18;
  90413. + } b;
  90414. +} hcintmsk_data_t;
  90415. +
  90416. +/**
  90417. + * This union represents the bit fields in the Host Channel Transfer Size
  90418. + * Register. Read the register into the <i>d32</i> member then set/clear the
  90419. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  90420. + * hcchar register.
  90421. + */
  90422. +
  90423. +typedef union hctsiz_data {
  90424. + /** raw register data */
  90425. + uint32_t d32;
  90426. +
  90427. + /** register bits */
  90428. + struct {
  90429. + /** Total transfer size in bytes */
  90430. + unsigned xfersize:19;
  90431. +
  90432. + /** Data packets to transfer */
  90433. + unsigned pktcnt:10;
  90434. +
  90435. + /**
  90436. + * Packet ID for next data packet
  90437. + * 0: DATA0
  90438. + * 1: DATA2
  90439. + * 2: DATA1
  90440. + * 3: MDATA (non-Control), SETUP (Control)
  90441. + */
  90442. + unsigned pid:2;
  90443. +#define DWC_HCTSIZ_DATA0 0
  90444. +#define DWC_HCTSIZ_DATA1 2
  90445. +#define DWC_HCTSIZ_DATA2 1
  90446. +#define DWC_HCTSIZ_MDATA 3
  90447. +#define DWC_HCTSIZ_SETUP 3
  90448. +
  90449. + /** Do PING protocol when 1 */
  90450. + unsigned dopng:1;
  90451. + } b;
  90452. +
  90453. + /** register bits */
  90454. + struct {
  90455. + /** Scheduling information */
  90456. + unsigned schinfo:8;
  90457. +
  90458. + /** Number of transfer descriptors.
  90459. + * Max value:
  90460. + * 64 in general,
  90461. + * 256 only for HS isochronous endpoint.
  90462. + */
  90463. + unsigned ntd:8;
  90464. +
  90465. + /** Data packets to transfer */
  90466. + unsigned reserved16_28:13;
  90467. +
  90468. + /**
  90469. + * Packet ID for next data packet
  90470. + * 0: DATA0
  90471. + * 1: DATA2
  90472. + * 2: DATA1
  90473. + * 3: MDATA (non-Control)
  90474. + */
  90475. + unsigned pid:2;
  90476. +
  90477. + /** Do PING protocol when 1 */
  90478. + unsigned dopng:1;
  90479. + } b_ddma;
  90480. +} hctsiz_data_t;
  90481. +
  90482. +/**
  90483. + * This union represents the bit fields in the Host DMA Address
  90484. + * Register used in Descriptor DMA mode.
  90485. + */
  90486. +typedef union hcdma_data {
  90487. + /** raw register data */
  90488. + uint32_t d32;
  90489. + /** register bits */
  90490. + struct {
  90491. + unsigned reserved0_2:3;
  90492. + /** Current Transfer Descriptor. Not used for ISOC */
  90493. + unsigned ctd:8;
  90494. + /** Start Address of Descriptor List */
  90495. + unsigned dma_addr:21;
  90496. + } b;
  90497. +} hcdma_data_t;
  90498. +
  90499. +/**
  90500. + * This union represents the bit fields in the DMA Descriptor
  90501. + * status quadlet for host mode. Read the quadlet into the <i>d32</i> member then
  90502. + * set/clear the bits using the <i>b</i>it elements.
  90503. + */
  90504. +typedef union host_dma_desc_sts {
  90505. + /** raw register data */
  90506. + uint32_t d32;
  90507. + /** quadlet bits */
  90508. +
  90509. + /* for non-isochronous */
  90510. + struct {
  90511. + /** Number of bytes */
  90512. + unsigned n_bytes:17;
  90513. + /** QTD offset to jump when Short Packet received - only for IN EPs */
  90514. + unsigned qtd_offset:6;
  90515. + /**
  90516. + * Set to request the core to jump to alternate QTD if
  90517. + * Short Packet received - only for IN EPs
  90518. + */
  90519. + unsigned a_qtd:1;
  90520. + /**
  90521. + * Setup Packet bit. When set indicates that buffer contains
  90522. + * setup packet.
  90523. + */
  90524. + unsigned sup:1;
  90525. + /** Interrupt On Complete */
  90526. + unsigned ioc:1;
  90527. + /** End of List */
  90528. + unsigned eol:1;
  90529. + unsigned reserved27:1;
  90530. + /** Rx/Tx Status */
  90531. + unsigned sts:2;
  90532. +#define DMA_DESC_STS_PKTERR 1
  90533. + unsigned reserved30:1;
  90534. + /** Active Bit */
  90535. + unsigned a:1;
  90536. + } b;
  90537. + /* for isochronous */
  90538. + struct {
  90539. + /** Number of bytes */
  90540. + unsigned n_bytes:12;
  90541. + unsigned reserved12_24:13;
  90542. + /** Interrupt On Complete */
  90543. + unsigned ioc:1;
  90544. + unsigned reserved26_27:2;
  90545. + /** Rx/Tx Status */
  90546. + unsigned sts:2;
  90547. + unsigned reserved30:1;
  90548. + /** Active Bit */
  90549. + unsigned a:1;
  90550. + } b_isoc;
  90551. +} host_dma_desc_sts_t;
  90552. +
  90553. +#define MAX_DMA_DESC_SIZE 131071
  90554. +#define MAX_DMA_DESC_NUM_GENERIC 64
  90555. +#define MAX_DMA_DESC_NUM_HS_ISOC 256
  90556. +#define MAX_FRLIST_EN_NUM 64
  90557. +/**
  90558. + * Host-mode DMA Descriptor structure
  90559. + *
  90560. + * DMA Descriptor structure contains two quadlets:
  90561. + * Status quadlet and Data buffer pointer.
  90562. + */
  90563. +typedef struct dwc_otg_host_dma_desc {
  90564. + /** DMA Descriptor status quadlet */
  90565. + host_dma_desc_sts_t status;
  90566. + /** DMA Descriptor data buffer pointer */
  90567. + uint32_t buf;
  90568. +} dwc_otg_host_dma_desc_t;
  90569. +
  90570. +/** OTG Host Interface Structure.
  90571. + *
  90572. + * The OTG Host Interface Structure structure contains information
  90573. + * needed to manage the DWC_otg controller acting in host mode. It
  90574. + * represents the programming view of the host-specific aspects of the
  90575. + * controller.
  90576. + */
  90577. +typedef struct dwc_otg_host_if {
  90578. + /** Host Global Registers starting at offset 400h.*/
  90579. + dwc_otg_host_global_regs_t *host_global_regs;
  90580. +#define DWC_OTG_HOST_GLOBAL_REG_OFFSET 0x400
  90581. +
  90582. + /** Host Port 0 Control and Status Register */
  90583. + volatile uint32_t *hprt0;
  90584. +#define DWC_OTG_HOST_PORT_REGS_OFFSET 0x440
  90585. +
  90586. + /** Host Channel Specific Registers at offsets 500h-5FCh. */
  90587. + dwc_otg_hc_regs_t *hc_regs[MAX_EPS_CHANNELS];
  90588. +#define DWC_OTG_HOST_CHAN_REGS_OFFSET 0x500
  90589. +#define DWC_OTG_CHAN_REGS_OFFSET 0x20
  90590. +
  90591. + /* Host configuration information */
  90592. + /** Number of Host Channels (range: 1-16) */
  90593. + uint8_t num_host_channels;
  90594. + /** Periodic EPs supported (0: no, 1: yes) */
  90595. + uint8_t perio_eps_supported;
  90596. + /** Periodic Tx FIFO Size (Only 1 host periodic Tx FIFO) */
  90597. + uint16_t perio_tx_fifo_size;
  90598. +
  90599. +} dwc_otg_host_if_t;
  90600. +
  90601. +/**
  90602. + * This union represents the bit fields in the Power and Clock Gating Control
  90603. + * Register. Read the register into the <i>d32</i> member then set/clear the
  90604. + * bits using the <i>b</i>it elements.
  90605. + */
  90606. +typedef union pcgcctl_data {
  90607. + /** raw register data */
  90608. + uint32_t d32;
  90609. +
  90610. + /** register bits */
  90611. + struct {
  90612. + /** Stop Pclk */
  90613. + unsigned stoppclk:1;
  90614. + /** Gate Hclk */
  90615. + unsigned gatehclk:1;
  90616. + /** Power Clamp */
  90617. + unsigned pwrclmp:1;
  90618. + /** Reset Power Down Modules */
  90619. + unsigned rstpdwnmodule:1;
  90620. + /** Reserved */
  90621. + unsigned reserved:1;
  90622. + /** Enable Sleep Clock Gating (Enbl_L1Gating) */
  90623. + unsigned enbl_sleep_gating:1;
  90624. + /** PHY In Sleep (PhySleep) */
  90625. + unsigned phy_in_sleep:1;
  90626. + /** Deep Sleep*/
  90627. + unsigned deep_sleep:1;
  90628. + unsigned resetaftsusp:1;
  90629. + unsigned restoremode:1;
  90630. + unsigned enbl_extnd_hiber:1;
  90631. + unsigned extnd_hiber_pwrclmp:1;
  90632. + unsigned extnd_hiber_switch:1;
  90633. + unsigned ess_reg_restored:1;
  90634. + unsigned prt_clk_sel:2;
  90635. + unsigned port_power:1;
  90636. + unsigned max_xcvrselect:2;
  90637. + unsigned max_termsel:1;
  90638. + unsigned mac_dev_addr:7;
  90639. + unsigned p2hd_dev_enum_spd:2;
  90640. + unsigned p2hd_prt_spd:2;
  90641. + unsigned if_dev_mode:1;
  90642. + } b;
  90643. +} pcgcctl_data_t;
  90644. +
  90645. +/**
  90646. + * This union represents the bit fields in the Global Data FIFO Software
  90647. + * Configuration Register. Read the register into the <i>d32</i> member then
  90648. + * set/clear the bits using the <i>b</i>it elements.
  90649. + */
  90650. +typedef union gdfifocfg_data {
  90651. + /* raw register data */
  90652. + uint32_t d32;
  90653. + /** register bits */
  90654. + struct {
  90655. + /** OTG Data FIFO depth */
  90656. + unsigned gdfifocfg:16;
  90657. + /** Start address of EP info controller */
  90658. + unsigned epinfobase:16;
  90659. + } b;
  90660. +} gdfifocfg_data_t;
  90661. +
  90662. +/**
  90663. + * This union represents the bit fields in the Global Power Down Register
  90664. + * Register. Read the register into the <i>d32</i> member then set/clear the
  90665. + * bits using the <i>b</i>it elements.
  90666. + */
  90667. +typedef union gpwrdn_data {
  90668. + /* raw register data */
  90669. + uint32_t d32;
  90670. +
  90671. + /** register bits */
  90672. + struct {
  90673. + /** PMU Interrupt Select */
  90674. + unsigned pmuintsel:1;
  90675. + /** PMU Active */
  90676. + unsigned pmuactv:1;
  90677. + /** Restore */
  90678. + unsigned restore:1;
  90679. + /** Power Down Clamp */
  90680. + unsigned pwrdnclmp:1;
  90681. + /** Power Down Reset */
  90682. + unsigned pwrdnrstn:1;
  90683. + /** Power Down Switch */
  90684. + unsigned pwrdnswtch:1;
  90685. + /** Disable VBUS */
  90686. + unsigned dis_vbus:1;
  90687. + /** Line State Change */
  90688. + unsigned lnstschng:1;
  90689. + /** Line state change mask */
  90690. + unsigned lnstchng_msk:1;
  90691. + /** Reset Detected */
  90692. + unsigned rst_det:1;
  90693. + /** Reset Detect mask */
  90694. + unsigned rst_det_msk:1;
  90695. + /** Disconnect Detected */
  90696. + unsigned disconn_det:1;
  90697. + /** Disconnect Detect mask */
  90698. + unsigned disconn_det_msk:1;
  90699. + /** Connect Detected*/
  90700. + unsigned connect_det:1;
  90701. + /** Connect Detected Mask*/
  90702. + unsigned connect_det_msk:1;
  90703. + /** SRP Detected */
  90704. + unsigned srp_det:1;
  90705. + /** SRP Detect mask */
  90706. + unsigned srp_det_msk:1;
  90707. + /** Status Change Interrupt */
  90708. + unsigned sts_chngint:1;
  90709. + /** Status Change Interrupt Mask */
  90710. + unsigned sts_chngint_msk:1;
  90711. + /** Line State */
  90712. + unsigned linestate:2;
  90713. + /** Indicates current mode(status of IDDIG signal) */
  90714. + unsigned idsts:1;
  90715. + /** B Session Valid signal status*/
  90716. + unsigned bsessvld:1;
  90717. + /** ADP Event Detected */
  90718. + unsigned adp_int:1;
  90719. + /** Multi Valued ID pin */
  90720. + unsigned mult_val_id_bc:5;
  90721. + /** Reserved 24_31 */
  90722. + unsigned reserved29_31:3;
  90723. + } b;
  90724. +} gpwrdn_data_t;
  90725. +
  90726. +#endif
  90727. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_otg/Makefile linux-3.13.3/drivers/usb/host/dwc_otg/Makefile
  90728. --- linux-3.13.3.orig/drivers/usb/host/dwc_otg/Makefile 1970-01-01 01:00:00.000000000 +0100
  90729. +++ linux-3.13.3/drivers/usb/host/dwc_otg/Makefile 2014-02-17 22:41:01.000000000 +0100
  90730. @@ -0,0 +1,81 @@
  90731. +#
  90732. +# Makefile for DWC_otg Highspeed USB controller driver
  90733. +#
  90734. +
  90735. +ifneq ($(KERNELRELEASE),)
  90736. +
  90737. +# Use the BUS_INTERFACE variable to compile the software for either
  90738. +# PCI(PCI_INTERFACE) or LM(LM_INTERFACE) bus.
  90739. +ifeq ($(BUS_INTERFACE),)
  90740. +# BUS_INTERFACE = -DPCI_INTERFACE
  90741. +# BUS_INTERFACE = -DLM_INTERFACE
  90742. + BUS_INTERFACE = -DPLATFORM_INTERFACE
  90743. +endif
  90744. +
  90745. +#EXTRA_CFLAGS += -DDEBUG
  90746. +#EXTRA_CFLAGS += -DDWC_OTG_DEBUGLEV=1 # reduce common debug msgs
  90747. +
  90748. +# Use one of the following flags to compile the software in host-only or
  90749. +# device-only mode.
  90750. +#EXTRA_CFLAGS += -DDWC_HOST_ONLY
  90751. +#EXTRA_CFLAGS += -DDWC_DEVICE_ONLY
  90752. +
  90753. +EXTRA_CFLAGS += -Dlinux -DDWC_HS_ELECT_TST
  90754. +#EXTRA_CFLAGS += -DDWC_EN_ISOC
  90755. +EXTRA_CFLAGS += -I$(obj)/../dwc_common_port
  90756. +#EXTRA_CFLAGS += -I$(PORTLIB)
  90757. +EXTRA_CFLAGS += -DDWC_LINUX
  90758. +EXTRA_CFLAGS += $(CFI)
  90759. +EXTRA_CFLAGS += $(BUS_INTERFACE)
  90760. +#EXTRA_CFLAGS += -DDWC_DEV_SRPCAP
  90761. +
  90762. +obj-$(CONFIG_USB_DWCOTG) += dwc_otg.o
  90763. +
  90764. +dwc_otg-objs := dwc_otg_driver.o dwc_otg_attr.o
  90765. +dwc_otg-objs += dwc_otg_cil.o dwc_otg_cil_intr.o
  90766. +dwc_otg-objs += dwc_otg_pcd_linux.o dwc_otg_pcd.o dwc_otg_pcd_intr.o
  90767. +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
  90768. +dwc_otg-objs += dwc_otg_adp.o
  90769. +dwc_otg-objs += dwc_otg_mphi_fix.o
  90770. +ifneq ($(CFI),)
  90771. +dwc_otg-objs += dwc_otg_cfi.o
  90772. +endif
  90773. +
  90774. +kernrelwd := $(subst ., ,$(KERNELRELEASE))
  90775. +kernrel3 := $(word 1,$(kernrelwd)).$(word 2,$(kernrelwd)).$(word 3,$(kernrelwd))
  90776. +
  90777. +ifneq ($(kernrel3),2.6.20)
  90778. +EXTRA_CFLAGS += $(CPPFLAGS)
  90779. +endif
  90780. +
  90781. +else
  90782. +
  90783. +PWD := $(shell pwd)
  90784. +PORTLIB := $(PWD)/../dwc_common_port
  90785. +
  90786. +# Command paths
  90787. +CTAGS := $(CTAGS)
  90788. +DOXYGEN := $(DOXYGEN)
  90789. +
  90790. +default: portlib
  90791. + $(MAKE) -C$(KDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  90792. +
  90793. +install: default
  90794. + $(MAKE) -C$(KDIR) M=$(PORTLIB) modules_install
  90795. + $(MAKE) -C$(KDIR) M=$(PWD) modules_install
  90796. +
  90797. +portlib:
  90798. + $(MAKE) -C$(KDIR) M=$(PORTLIB) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  90799. + cp $(PORTLIB)/Module.symvers $(PWD)/
  90800. +
  90801. +docs: $(wildcard *.[hc]) doc/doxygen.cfg
  90802. + $(DOXYGEN) doc/doxygen.cfg
  90803. +
  90804. +tags: $(wildcard *.[hc])
  90805. + $(CTAGS) -e $(wildcard *.[hc]) $(wildcard linux/*.[hc]) $(wildcard $(KDIR)/include/linux/usb*.h)
  90806. +
  90807. +
  90808. +clean:
  90809. + rm -rf *.o *.ko .*cmd *.mod.c .tmp_versions Module.symvers
  90810. +
  90811. +endif
  90812. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm linux-3.13.3/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm
  90813. --- linux-3.13.3.orig/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm 1970-01-01 01:00:00.000000000 +0100
  90814. +++ linux-3.13.3/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm 2014-02-17 22:41:01.000000000 +0100
  90815. @@ -0,0 +1,337 @@
  90816. +package dwc_otg_test;
  90817. +
  90818. +use strict;
  90819. +use Exporter ();
  90820. +
  90821. +use vars qw(@ISA @EXPORT
  90822. +$sysfsdir $paramdir $errors $params
  90823. +);
  90824. +
  90825. +@ISA = qw(Exporter);
  90826. +
  90827. +#
  90828. +# Globals
  90829. +#
  90830. +$sysfsdir = "/sys/devices/lm0";
  90831. +$paramdir = "/sys/module/dwc_otg";
  90832. +$errors = 0;
  90833. +
  90834. +$params = [
  90835. + {
  90836. + NAME => "otg_cap",
  90837. + DEFAULT => 0,
  90838. + ENUM => [],
  90839. + LOW => 0,
  90840. + HIGH => 2
  90841. + },
  90842. + {
  90843. + NAME => "dma_enable",
  90844. + DEFAULT => 0,
  90845. + ENUM => [],
  90846. + LOW => 0,
  90847. + HIGH => 1
  90848. + },
  90849. + {
  90850. + NAME => "dma_burst_size",
  90851. + DEFAULT => 32,
  90852. + ENUM => [1, 4, 8, 16, 32, 64, 128, 256],
  90853. + LOW => 1,
  90854. + HIGH => 256
  90855. + },
  90856. + {
  90857. + NAME => "host_speed",
  90858. + DEFAULT => 0,
  90859. + ENUM => [],
  90860. + LOW => 0,
  90861. + HIGH => 1
  90862. + },
  90863. + {
  90864. + NAME => "host_support_fs_ls_low_power",
  90865. + DEFAULT => 0,
  90866. + ENUM => [],
  90867. + LOW => 0,
  90868. + HIGH => 1
  90869. + },
  90870. + {
  90871. + NAME => "host_ls_low_power_phy_clk",
  90872. + DEFAULT => 0,
  90873. + ENUM => [],
  90874. + LOW => 0,
  90875. + HIGH => 1
  90876. + },
  90877. + {
  90878. + NAME => "dev_speed",
  90879. + DEFAULT => 0,
  90880. + ENUM => [],
  90881. + LOW => 0,
  90882. + HIGH => 1
  90883. + },
  90884. + {
  90885. + NAME => "enable_dynamic_fifo",
  90886. + DEFAULT => 1,
  90887. + ENUM => [],
  90888. + LOW => 0,
  90889. + HIGH => 1
  90890. + },
  90891. + {
  90892. + NAME => "data_fifo_size",
  90893. + DEFAULT => 8192,
  90894. + ENUM => [],
  90895. + LOW => 32,
  90896. + HIGH => 32768
  90897. + },
  90898. + {
  90899. + NAME => "dev_rx_fifo_size",
  90900. + DEFAULT => 1064,
  90901. + ENUM => [],
  90902. + LOW => 16,
  90903. + HIGH => 32768
  90904. + },
  90905. + {
  90906. + NAME => "dev_nperio_tx_fifo_size",
  90907. + DEFAULT => 1024,
  90908. + ENUM => [],
  90909. + LOW => 16,
  90910. + HIGH => 32768
  90911. + },
  90912. + {
  90913. + NAME => "dev_perio_tx_fifo_size_1",
  90914. + DEFAULT => 256,
  90915. + ENUM => [],
  90916. + LOW => 4,
  90917. + HIGH => 768
  90918. + },
  90919. + {
  90920. + NAME => "dev_perio_tx_fifo_size_2",
  90921. + DEFAULT => 256,
  90922. + ENUM => [],
  90923. + LOW => 4,
  90924. + HIGH => 768
  90925. + },
  90926. + {
  90927. + NAME => "dev_perio_tx_fifo_size_3",
  90928. + DEFAULT => 256,
  90929. + ENUM => [],
  90930. + LOW => 4,
  90931. + HIGH => 768
  90932. + },
  90933. + {
  90934. + NAME => "dev_perio_tx_fifo_size_4",
  90935. + DEFAULT => 256,
  90936. + ENUM => [],
  90937. + LOW => 4,
  90938. + HIGH => 768
  90939. + },
  90940. + {
  90941. + NAME => "dev_perio_tx_fifo_size_5",
  90942. + DEFAULT => 256,
  90943. + ENUM => [],
  90944. + LOW => 4,
  90945. + HIGH => 768
  90946. + },
  90947. + {
  90948. + NAME => "dev_perio_tx_fifo_size_6",
  90949. + DEFAULT => 256,
  90950. + ENUM => [],
  90951. + LOW => 4,
  90952. + HIGH => 768
  90953. + },
  90954. + {
  90955. + NAME => "dev_perio_tx_fifo_size_7",
  90956. + DEFAULT => 256,
  90957. + ENUM => [],
  90958. + LOW => 4,
  90959. + HIGH => 768
  90960. + },
  90961. + {
  90962. + NAME => "dev_perio_tx_fifo_size_8",
  90963. + DEFAULT => 256,
  90964. + ENUM => [],
  90965. + LOW => 4,
  90966. + HIGH => 768
  90967. + },
  90968. + {
  90969. + NAME => "dev_perio_tx_fifo_size_9",
  90970. + DEFAULT => 256,
  90971. + ENUM => [],
  90972. + LOW => 4,
  90973. + HIGH => 768
  90974. + },
  90975. + {
  90976. + NAME => "dev_perio_tx_fifo_size_10",
  90977. + DEFAULT => 256,
  90978. + ENUM => [],
  90979. + LOW => 4,
  90980. + HIGH => 768
  90981. + },
  90982. + {
  90983. + NAME => "dev_perio_tx_fifo_size_11",
  90984. + DEFAULT => 256,
  90985. + ENUM => [],
  90986. + LOW => 4,
  90987. + HIGH => 768
  90988. + },
  90989. + {
  90990. + NAME => "dev_perio_tx_fifo_size_12",
  90991. + DEFAULT => 256,
  90992. + ENUM => [],
  90993. + LOW => 4,
  90994. + HIGH => 768
  90995. + },
  90996. + {
  90997. + NAME => "dev_perio_tx_fifo_size_13",
  90998. + DEFAULT => 256,
  90999. + ENUM => [],
  91000. + LOW => 4,
  91001. + HIGH => 768
  91002. + },
  91003. + {
  91004. + NAME => "dev_perio_tx_fifo_size_14",
  91005. + DEFAULT => 256,
  91006. + ENUM => [],
  91007. + LOW => 4,
  91008. + HIGH => 768
  91009. + },
  91010. + {
  91011. + NAME => "dev_perio_tx_fifo_size_15",
  91012. + DEFAULT => 256,
  91013. + ENUM => [],
  91014. + LOW => 4,
  91015. + HIGH => 768
  91016. + },
  91017. + {
  91018. + NAME => "host_rx_fifo_size",
  91019. + DEFAULT => 1024,
  91020. + ENUM => [],
  91021. + LOW => 16,
  91022. + HIGH => 32768
  91023. + },
  91024. + {
  91025. + NAME => "host_nperio_tx_fifo_size",
  91026. + DEFAULT => 1024,
  91027. + ENUM => [],
  91028. + LOW => 16,
  91029. + HIGH => 32768
  91030. + },
  91031. + {
  91032. + NAME => "host_perio_tx_fifo_size",
  91033. + DEFAULT => 1024,
  91034. + ENUM => [],
  91035. + LOW => 16,
  91036. + HIGH => 32768
  91037. + },
  91038. + {
  91039. + NAME => "max_transfer_size",
  91040. + DEFAULT => 65535,
  91041. + ENUM => [],
  91042. + LOW => 2047,
  91043. + HIGH => 65535
  91044. + },
  91045. + {
  91046. + NAME => "max_packet_count",
  91047. + DEFAULT => 511,
  91048. + ENUM => [],
  91049. + LOW => 15,
  91050. + HIGH => 511
  91051. + },
  91052. + {
  91053. + NAME => "host_channels",
  91054. + DEFAULT => 12,
  91055. + ENUM => [],
  91056. + LOW => 1,
  91057. + HIGH => 16
  91058. + },
  91059. + {
  91060. + NAME => "dev_endpoints",
  91061. + DEFAULT => 6,
  91062. + ENUM => [],
  91063. + LOW => 1,
  91064. + HIGH => 15
  91065. + },
  91066. + {
  91067. + NAME => "phy_type",
  91068. + DEFAULT => 1,
  91069. + ENUM => [],
  91070. + LOW => 0,
  91071. + HIGH => 2
  91072. + },
  91073. + {
  91074. + NAME => "phy_utmi_width",
  91075. + DEFAULT => 16,
  91076. + ENUM => [8, 16],
  91077. + LOW => 8,
  91078. + HIGH => 16
  91079. + },
  91080. + {
  91081. + NAME => "phy_ulpi_ddr",
  91082. + DEFAULT => 0,
  91083. + ENUM => [],
  91084. + LOW => 0,
  91085. + HIGH => 1
  91086. + },
  91087. + ];
  91088. +
  91089. +
  91090. +#
  91091. +#
  91092. +sub check_arch {
  91093. + $_ = `uname -m`;
  91094. + chomp;
  91095. + unless (m/armv4tl/) {
  91096. + warn "# \n# Can't execute on $_. Run on integrator platform.\n# \n";
  91097. + return 0;
  91098. + }
  91099. + return 1;
  91100. +}
  91101. +
  91102. +#
  91103. +#
  91104. +sub load_module {
  91105. + my $params = shift;
  91106. + print "\nRemoving Module\n";
  91107. + system "rmmod dwc_otg";
  91108. + print "Loading Module\n";
  91109. + if ($params ne "") {
  91110. + print "Module Parameters: $params\n";
  91111. + }
  91112. + if (system("modprobe dwc_otg $params")) {
  91113. + warn "Unable to load module\n";
  91114. + return 0;
  91115. + }
  91116. + return 1;
  91117. +}
  91118. +
  91119. +#
  91120. +#
  91121. +sub test_status {
  91122. + my $arg = shift;
  91123. +
  91124. + print "\n";
  91125. +
  91126. + if (defined $arg) {
  91127. + warn "WARNING: $arg\n";
  91128. + }
  91129. +
  91130. + if ($errors > 0) {
  91131. + warn "TEST FAILED with $errors errors\n";
  91132. + return 0;
  91133. + } else {
  91134. + print "TEST PASSED\n";
  91135. + return 0 if (defined $arg);
  91136. + }
  91137. + return 1;
  91138. +}
  91139. +
  91140. +#
  91141. +#
  91142. +@EXPORT = qw(
  91143. +$sysfsdir
  91144. +$paramdir
  91145. +$params
  91146. +$errors
  91147. +check_arch
  91148. +load_module
  91149. +test_status
  91150. +);
  91151. +
  91152. +1;
  91153. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_otg/test/Makefile linux-3.13.3/drivers/usb/host/dwc_otg/test/Makefile
  91154. --- linux-3.13.3.orig/drivers/usb/host/dwc_otg/test/Makefile 1970-01-01 01:00:00.000000000 +0100
  91155. +++ linux-3.13.3/drivers/usb/host/dwc_otg/test/Makefile 2014-02-17 22:41:01.000000000 +0100
  91156. @@ -0,0 +1,16 @@
  91157. +
  91158. +PERL=/usr/bin/perl
  91159. +PL_TESTS=test_sysfs.pl test_mod_param.pl
  91160. +
  91161. +.PHONY : test
  91162. +test : perl_tests
  91163. +
  91164. +perl_tests :
  91165. + @echo
  91166. + @echo Running perl tests
  91167. + @for test in $(PL_TESTS); do \
  91168. + if $(PERL) ./$$test ; then \
  91169. + echo "=======> $$test, PASSED" ; \
  91170. + else echo "=======> $$test, FAILED" ; \
  91171. + fi \
  91172. + done
  91173. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_otg/test/test_mod_param.pl linux-3.13.3/drivers/usb/host/dwc_otg/test/test_mod_param.pl
  91174. --- linux-3.13.3.orig/drivers/usb/host/dwc_otg/test/test_mod_param.pl 1970-01-01 01:00:00.000000000 +0100
  91175. +++ linux-3.13.3/drivers/usb/host/dwc_otg/test/test_mod_param.pl 2014-02-17 22:41:01.000000000 +0100
  91176. @@ -0,0 +1,133 @@
  91177. +#!/usr/bin/perl -w
  91178. +#
  91179. +# Run this program on the integrator.
  91180. +#
  91181. +# - Tests module parameter default values.
  91182. +# - Tests setting of valid module parameter values via modprobe.
  91183. +# - Tests invalid module parameter values.
  91184. +# -----------------------------------------------------------------------------
  91185. +use strict;
  91186. +use dwc_otg_test;
  91187. +
  91188. +check_arch() or die;
  91189. +
  91190. +#
  91191. +#
  91192. +sub test {
  91193. + my ($param,$expected) = @_;
  91194. + my $value = get($param);
  91195. +
  91196. + if ($value == $expected) {
  91197. + print "$param = $value, okay\n";
  91198. + }
  91199. +
  91200. + else {
  91201. + warn "ERROR: value of $param != $expected, $value\n";
  91202. + $errors ++;
  91203. + }
  91204. +}
  91205. +
  91206. +#
  91207. +#
  91208. +sub get {
  91209. + my $param = shift;
  91210. + my $tmp = `cat $paramdir/$param`;
  91211. + chomp $tmp;
  91212. + return $tmp;
  91213. +}
  91214. +
  91215. +#
  91216. +#
  91217. +sub test_main {
  91218. +
  91219. + print "\nTesting Module Parameters\n";
  91220. +
  91221. + load_module("") or die;
  91222. +
  91223. + # Test initial values
  91224. + print "\nTesting Default Values\n";
  91225. + foreach (@{$params}) {
  91226. + test ($_->{NAME}, $_->{DEFAULT});
  91227. + }
  91228. +
  91229. + # Test low value
  91230. + print "\nTesting Low Value\n";
  91231. + my $cmd_params = "";
  91232. + foreach (@{$params}) {
  91233. + $cmd_params = $cmd_params . "$_->{NAME}=$_->{LOW} ";
  91234. + }
  91235. + load_module($cmd_params) or die;
  91236. +
  91237. + foreach (@{$params}) {
  91238. + test ($_->{NAME}, $_->{LOW});
  91239. + }
  91240. +
  91241. + # Test high value
  91242. + print "\nTesting High Value\n";
  91243. + $cmd_params = "";
  91244. + foreach (@{$params}) {
  91245. + $cmd_params = $cmd_params . "$_->{NAME}=$_->{HIGH} ";
  91246. + }
  91247. + load_module($cmd_params) or die;
  91248. +
  91249. + foreach (@{$params}) {
  91250. + test ($_->{NAME}, $_->{HIGH});
  91251. + }
  91252. +
  91253. + # Test Enum
  91254. + print "\nTesting Enumerated\n";
  91255. + foreach (@{$params}) {
  91256. + if (defined $_->{ENUM}) {
  91257. + my $value;
  91258. + foreach $value (@{$_->{ENUM}}) {
  91259. + $cmd_params = "$_->{NAME}=$value";
  91260. + load_module($cmd_params) or die;
  91261. + test ($_->{NAME}, $value);
  91262. + }
  91263. + }
  91264. + }
  91265. +
  91266. + # Test Invalid Values
  91267. + print "\nTesting Invalid Values\n";
  91268. + $cmd_params = "";
  91269. + foreach (@{$params}) {
  91270. + $cmd_params = $cmd_params . sprintf "$_->{NAME}=%d ", $_->{LOW}-1;
  91271. + }
  91272. + load_module($cmd_params) or die;
  91273. +
  91274. + foreach (@{$params}) {
  91275. + test ($_->{NAME}, $_->{DEFAULT});
  91276. + }
  91277. +
  91278. + $cmd_params = "";
  91279. + foreach (@{$params}) {
  91280. + $cmd_params = $cmd_params . sprintf "$_->{NAME}=%d ", $_->{HIGH}+1;
  91281. + }
  91282. + load_module($cmd_params) or die;
  91283. +
  91284. + foreach (@{$params}) {
  91285. + test ($_->{NAME}, $_->{DEFAULT});
  91286. + }
  91287. +
  91288. + print "\nTesting Enumerated\n";
  91289. + foreach (@{$params}) {
  91290. + if (defined $_->{ENUM}) {
  91291. + my $value;
  91292. + foreach $value (@{$_->{ENUM}}) {
  91293. + $value = $value + 1;
  91294. + $cmd_params = "$_->{NAME}=$value";
  91295. + load_module($cmd_params) or die;
  91296. + test ($_->{NAME}, $_->{DEFAULT});
  91297. + $value = $value - 2;
  91298. + $cmd_params = "$_->{NAME}=$value";
  91299. + load_module($cmd_params) or die;
  91300. + test ($_->{NAME}, $_->{DEFAULT});
  91301. + }
  91302. + }
  91303. + }
  91304. +
  91305. + test_status() or die;
  91306. +}
  91307. +
  91308. +test_main();
  91309. +0;
  91310. diff -Nur linux-3.13.3.orig/drivers/usb/host/dwc_otg/test/test_sysfs.pl linux-3.13.3/drivers/usb/host/dwc_otg/test/test_sysfs.pl
  91311. --- linux-3.13.3.orig/drivers/usb/host/dwc_otg/test/test_sysfs.pl 1970-01-01 01:00:00.000000000 +0100
  91312. +++ linux-3.13.3/drivers/usb/host/dwc_otg/test/test_sysfs.pl 2014-02-17 22:41:01.000000000 +0100
  91313. @@ -0,0 +1,193 @@
  91314. +#!/usr/bin/perl -w
  91315. +#
  91316. +# Run this program on the integrator
  91317. +# - Tests select sysfs attributes.
  91318. +# - Todo ... test more attributes, hnp/srp, buspower/bussuspend, etc.
  91319. +# -----------------------------------------------------------------------------
  91320. +use strict;
  91321. +use dwc_otg_test;
  91322. +
  91323. +check_arch() or die;
  91324. +
  91325. +#
  91326. +#
  91327. +sub test {
  91328. + my ($attr,$expected) = @_;
  91329. + my $string = get($attr);
  91330. +
  91331. + if ($string eq $expected) {
  91332. + printf("$attr = $string, okay\n");
  91333. + }
  91334. + else {
  91335. + warn "ERROR: value of $attr != $expected, $string\n";
  91336. + $errors ++;
  91337. + }
  91338. +}
  91339. +
  91340. +#
  91341. +#
  91342. +sub set {
  91343. + my ($reg, $value) = @_;
  91344. + system "echo $value > $sysfsdir/$reg";
  91345. +}
  91346. +
  91347. +#
  91348. +#
  91349. +sub get {
  91350. + my $attr = shift;
  91351. + my $string = `cat $sysfsdir/$attr`;
  91352. + chomp $string;
  91353. + if ($string =~ m/\s\=\s/) {
  91354. + my $tmp;
  91355. + ($tmp, $string) = split /\s=\s/, $string;
  91356. + }
  91357. + return $string;
  91358. +}
  91359. +
  91360. +#
  91361. +#
  91362. +sub test_main {
  91363. + print("\nTesting Sysfs Attributes\n");
  91364. +
  91365. + load_module("") or die;
  91366. +
  91367. + # Test initial values of regoffset/regvalue/guid/gsnpsid
  91368. + print("\nTesting Default Values\n");
  91369. +
  91370. + test("regoffset", "0xffffffff");
  91371. + test("regvalue", "invalid offset");
  91372. + test("guid", "0x12345678"); # this will fail if it has been changed
  91373. + test("gsnpsid", "0x4f54200a");
  91374. +
  91375. + # Test operation of regoffset/regvalue
  91376. + print("\nTesting regoffset\n");
  91377. + set('regoffset', '5a5a5a5a');
  91378. + test("regoffset", "0xffffffff");
  91379. +
  91380. + set('regoffset', '0');
  91381. + test("regoffset", "0x00000000");
  91382. +
  91383. + set('regoffset', '40000');
  91384. + test("regoffset", "0x00000000");
  91385. +
  91386. + set('regoffset', '3ffff');
  91387. + test("regoffset", "0x0003ffff");
  91388. +
  91389. + set('regoffset', '1');
  91390. + test("regoffset", "0x00000001");
  91391. +
  91392. + print("\nTesting regvalue\n");
  91393. + set('regoffset', '3c');
  91394. + test("regvalue", "0x12345678");
  91395. + set('regvalue', '5a5a5a5a');
  91396. + test("regvalue", "0x5a5a5a5a");
  91397. + set('regvalue','a5a5a5a5');
  91398. + test("regvalue", "0xa5a5a5a5");
  91399. + set('guid','12345678');
  91400. +
  91401. + # Test HNP Capable
  91402. + print("\nTesting HNP Capable bit\n");
  91403. + set('hnpcapable', '1');
  91404. + test("hnpcapable", "0x1");
  91405. + set('hnpcapable','0');
  91406. + test("hnpcapable", "0x0");
  91407. +
  91408. + set('regoffset','0c');
  91409. +
  91410. + my $old = get('gusbcfg');
  91411. + print("setting hnpcapable\n");
  91412. + set('hnpcapable', '1');
  91413. + test("hnpcapable", "0x1");
  91414. + test('gusbcfg', sprintf "0x%08x", (oct ($old) | (1<<9)));
  91415. + test('regvalue', sprintf "0x%08x", (oct ($old) | (1<<9)));
  91416. +
  91417. + $old = get('gusbcfg');
  91418. + print("clearing hnpcapable\n");
  91419. + set('hnpcapable', '0');
  91420. + test("hnpcapable", "0x0");
  91421. + test ('gusbcfg', sprintf "0x%08x", oct ($old) & (~(1<<9)));
  91422. + test ('regvalue', sprintf "0x%08x", oct ($old) & (~(1<<9)));
  91423. +
  91424. + # Test SRP Capable
  91425. + print("\nTesting SRP Capable bit\n");
  91426. + set('srpcapable', '1');
  91427. + test("srpcapable", "0x1");
  91428. + set('srpcapable','0');
  91429. + test("srpcapable", "0x0");
  91430. +
  91431. + set('regoffset','0c');
  91432. +
  91433. + $old = get('gusbcfg');
  91434. + print("setting srpcapable\n");
  91435. + set('srpcapable', '1');
  91436. + test("srpcapable", "0x1");
  91437. + test('gusbcfg', sprintf "0x%08x", (oct ($old) | (1<<8)));
  91438. + test('regvalue', sprintf "0x%08x", (oct ($old) | (1<<8)));
  91439. +
  91440. + $old = get('gusbcfg');
  91441. + print("clearing srpcapable\n");
  91442. + set('srpcapable', '0');
  91443. + test("srpcapable", "0x0");
  91444. + test('gusbcfg', sprintf "0x%08x", oct ($old) & (~(1<<8)));
  91445. + test('regvalue', sprintf "0x%08x", oct ($old) & (~(1<<8)));
  91446. +
  91447. + # Test GGPIO
  91448. + print("\nTesting GGPIO\n");
  91449. + set('ggpio','5a5a5a5a');
  91450. + test('ggpio','0x5a5a0000');
  91451. + set('ggpio','a5a5a5a5');
  91452. + test('ggpio','0xa5a50000');
  91453. + set('ggpio','11110000');
  91454. + test('ggpio','0x11110000');
  91455. + set('ggpio','00001111');
  91456. + test('ggpio','0x00000000');
  91457. +
  91458. + # Test DEVSPEED
  91459. + print("\nTesting DEVSPEED\n");
  91460. + set('regoffset','800');
  91461. + $old = get('regvalue');
  91462. + set('devspeed','0');
  91463. + test('devspeed','0x0');
  91464. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3)));
  91465. + set('devspeed','1');
  91466. + test('devspeed','0x1');
  91467. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 1));
  91468. + set('devspeed','2');
  91469. + test('devspeed','0x2');
  91470. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 2));
  91471. + set('devspeed','3');
  91472. + test('devspeed','0x3');
  91473. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 3));
  91474. + set('devspeed','4');
  91475. + test('devspeed','0x0');
  91476. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3)));
  91477. + set('devspeed','5');
  91478. + test('devspeed','0x1');
  91479. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 1));
  91480. +
  91481. +
  91482. + # mode Returns the current mode:0 for device mode1 for host mode Read
  91483. + # hnp Initiate the Host Negotiation Protocol. Read returns the status. Read/Write
  91484. + # srp Initiate the Session Request Protocol. Read returns the status. Read/Write
  91485. + # buspower Get or Set the Power State of the bus (0 - Off or 1 - On) Read/Write
  91486. + # bussuspend Suspend the USB bus. Read/Write
  91487. + # busconnected Get the connection status of the bus Read
  91488. +
  91489. + # gotgctl Get or set the Core Control Status Register. Read/Write
  91490. + ## gusbcfg Get or set the Core USB Configuration Register Read/Write
  91491. + # grxfsiz Get or set the Receive FIFO Size Register Read/Write
  91492. + # gnptxfsiz Get or set the non-periodic Transmit Size Register Read/Write
  91493. + # gpvndctl Get or set the PHY Vendor Control Register Read/Write
  91494. + ## ggpio Get the value in the lower 16-bits of the General Purpose IO Register or Set the upper 16 bits. Read/Write
  91495. + ## guid Get or set the value of the User ID Register Read/Write
  91496. + ## gsnpsid Get the value of the Synopsys ID Regester Read
  91497. + ## devspeed Get or set the device speed setting in the DCFG register Read/Write
  91498. + # enumspeed Gets the device enumeration Speed. Read
  91499. + # hptxfsiz Get the value of the Host Periodic Transmit FIFO Read
  91500. + # hprt0 Get or Set the value in the Host Port Control and Status Register Read/Write
  91501. +
  91502. + test_status("TEST NYI") or die;
  91503. +}
  91504. +
  91505. +test_main();
  91506. +0;
  91507. diff -Nur linux-3.13.3.orig/drivers/usb/host/Kconfig linux-3.13.3/drivers/usb/host/Kconfig
  91508. --- linux-3.13.3.orig/drivers/usb/host/Kconfig 2014-02-13 23:00:14.000000000 +0100
  91509. +++ linux-3.13.3/drivers/usb/host/Kconfig 2014-02-17 22:41:02.000000000 +0100
  91510. @@ -689,6 +689,19 @@
  91511. To compile this driver a module, choose M here: the module
  91512. will be called "hwa-hc".
  91513. +config USB_DWCOTG
  91514. + tristate "Synopsis DWC host support"
  91515. + depends on USB
  91516. + help
  91517. + The Synopsis DWC controller is a dual-role
  91518. + host/peripheral/OTG ("On The Go") USB controllers.
  91519. +
  91520. + Enable this option to support this IP in host controller mode.
  91521. + If unsure, say N.
  91522. +
  91523. + To compile this driver as a module, choose M here: the
  91524. + modules built will be called dwc_otg and dwc_common_port.
  91525. +
  91526. config USB_IMX21_HCD
  91527. tristate "i.MX21 HCD support"
  91528. depends on ARM && ARCH_MXC
  91529. diff -Nur linux-3.13.3.orig/drivers/usb/host/Makefile linux-3.13.3/drivers/usb/host/Makefile
  91530. --- linux-3.13.3.orig/drivers/usb/host/Makefile 2014-02-13 23:00:14.000000000 +0100
  91531. +++ linux-3.13.3/drivers/usb/host/Makefile 2014-02-17 22:41:02.000000000 +0100
  91532. @@ -65,6 +65,8 @@
  91533. obj-$(CONFIG_USB_R8A66597_HCD) += r8a66597-hcd.o
  91534. obj-$(CONFIG_USB_ISP1760_HCD) += isp1760.o
  91535. obj-$(CONFIG_USB_HWA_HCD) += hwa-hc.o
  91536. +
  91537. +obj-$(CONFIG_USB_DWCOTG) += dwc_otg/ dwc_common_port/
  91538. obj-$(CONFIG_USB_IMX21_HCD) += imx21-hcd.o
  91539. obj-$(CONFIG_USB_FSL_MPH_DR_OF) += fsl-mph-dr-of.o
  91540. obj-$(CONFIG_USB_OCTEON2_COMMON) += octeon2-common.o
  91541. diff -Nur linux-3.13.3.orig/drivers/usb/Makefile linux-3.13.3/drivers/usb/Makefile
  91542. --- linux-3.13.3.orig/drivers/usb/Makefile 2014-02-13 23:00:14.000000000 +0100
  91543. +++ linux-3.13.3/drivers/usb/Makefile 2014-02-17 22:41:02.000000000 +0100
  91544. @@ -23,6 +23,7 @@
  91545. obj-$(CONFIG_USB_R8A66597_HCD) += host/
  91546. obj-$(CONFIG_USB_HWA_HCD) += host/
  91547. obj-$(CONFIG_USB_ISP1760_HCD) += host/
  91548. +obj-$(CONFIG_USB_DWCOTG) += host/
  91549. obj-$(CONFIG_USB_IMX21_HCD) += host/
  91550. obj-$(CONFIG_USB_FSL_MPH_DR_OF) += host/
  91551. obj-$(CONFIG_USB_FUSBH200_HCD) += host/
  91552. diff -Nur linux-3.13.3.orig/drivers/video/bcm2708_fb.c linux-3.13.3/drivers/video/bcm2708_fb.c
  91553. --- linux-3.13.3.orig/drivers/video/bcm2708_fb.c 1970-01-01 01:00:00.000000000 +0100
  91554. +++ linux-3.13.3/drivers/video/bcm2708_fb.c 2014-02-17 22:41:02.000000000 +0100
  91555. @@ -0,0 +1,765 @@
  91556. +/*
  91557. + * linux/drivers/video/bcm2708_fb.c
  91558. + *
  91559. + * Copyright (C) 2010 Broadcom
  91560. + *
  91561. + * This file is subject to the terms and conditions of the GNU General Public
  91562. + * License. See the file COPYING in the main directory of this archive
  91563. + * for more details.
  91564. + *
  91565. + * Broadcom simple framebuffer driver
  91566. + *
  91567. + * This file is derived from cirrusfb.c
  91568. + * Copyright 1999-2001 Jeff Garzik <jgarzik@pobox.com>
  91569. + *
  91570. + */
  91571. +#include <linux/module.h>
  91572. +#include <linux/kernel.h>
  91573. +#include <linux/errno.h>
  91574. +#include <linux/string.h>
  91575. +#include <linux/slab.h>
  91576. +#include <linux/mm.h>
  91577. +#include <linux/fb.h>
  91578. +#include <linux/init.h>
  91579. +#include <linux/interrupt.h>
  91580. +#include <linux/ioport.h>
  91581. +#include <linux/list.h>
  91582. +#include <linux/platform_device.h>
  91583. +#include <linux/clk.h>
  91584. +#include <linux/printk.h>
  91585. +#include <linux/console.h>
  91586. +#include <linux/debugfs.h>
  91587. +
  91588. +#include <mach/dma.h>
  91589. +#include <mach/platform.h>
  91590. +#include <mach/vcio.h>
  91591. +
  91592. +#include <asm/sizes.h>
  91593. +#include <linux/io.h>
  91594. +#include <linux/dma-mapping.h>
  91595. +
  91596. +#ifdef BCM2708_FB_DEBUG
  91597. +#define print_debug(fmt,...) pr_debug("%s:%s:%d: "fmt, MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  91598. +#else
  91599. +#define print_debug(fmt,...)
  91600. +#endif
  91601. +
  91602. +/* This is limited to 16 characters when displayed by X startup */
  91603. +static const char *bcm2708_name = "BCM2708 FB";
  91604. +
  91605. +#define DRIVER_NAME "bcm2708_fb"
  91606. +
  91607. +static u32 dma_busy_wait_threshold = 1<<15;
  91608. +module_param(dma_busy_wait_threshold, int, 0644);
  91609. +MODULE_PARM_DESC(dma_busy_wait_threshold, "Busy-wait for DMA completion below this area");
  91610. +
  91611. +static int fbwidth = 800; /* module parameter */
  91612. +static int fbheight = 480; /* module parameter */
  91613. +static int fbdepth = 16; /* module parameter */
  91614. +static int fbswap = 0; /* module parameter */
  91615. +
  91616. +/* this data structure describes each frame buffer device we find */
  91617. +
  91618. +struct fbinfo_s {
  91619. + u32 xres, yres, xres_virtual, yres_virtual;
  91620. + u32 pitch, bpp;
  91621. + u32 xoffset, yoffset;
  91622. + u32 base;
  91623. + u32 screen_size;
  91624. + u16 cmap[256];
  91625. +};
  91626. +
  91627. +struct bcm2708_fb_stats {
  91628. + struct debugfs_regset32 regset;
  91629. + u32 dma_copies;
  91630. + u32 dma_irqs;
  91631. +};
  91632. +
  91633. +struct bcm2708_fb {
  91634. + struct fb_info fb;
  91635. + struct platform_device *dev;
  91636. + struct fbinfo_s *info;
  91637. + dma_addr_t dma;
  91638. + u32 cmap[16];
  91639. + int dma_chan;
  91640. + int dma_irq;
  91641. + void __iomem *dma_chan_base;
  91642. + void *cb_base; /* DMA control blocks */
  91643. + dma_addr_t cb_handle;
  91644. + struct dentry *debugfs_dir;
  91645. + wait_queue_head_t dma_waitq;
  91646. + struct bcm2708_fb_stats stats;
  91647. +};
  91648. +
  91649. +#define to_bcm2708(info) container_of(info, struct bcm2708_fb, fb)
  91650. +
  91651. +static void bcm2708_fb_debugfs_deinit(struct bcm2708_fb *fb)
  91652. +{
  91653. + debugfs_remove_recursive(fb->debugfs_dir);
  91654. + fb->debugfs_dir = NULL;
  91655. +}
  91656. +
  91657. +static int bcm2708_fb_debugfs_init(struct bcm2708_fb *fb)
  91658. +{
  91659. + static struct debugfs_reg32 stats_registers[] = {
  91660. + {
  91661. + "dma_copies",
  91662. + offsetof(struct bcm2708_fb_stats, dma_copies)
  91663. + },
  91664. + {
  91665. + "dma_irqs",
  91666. + offsetof(struct bcm2708_fb_stats, dma_irqs)
  91667. + },
  91668. + };
  91669. +
  91670. + fb->debugfs_dir = debugfs_create_dir(DRIVER_NAME, NULL);
  91671. + if (!fb->debugfs_dir) {
  91672. + pr_warn("%s: could not create debugfs entry\n",
  91673. + __func__);
  91674. + return -EFAULT;
  91675. + }
  91676. +
  91677. + fb->stats.regset.regs = stats_registers;
  91678. + fb->stats.regset.nregs = ARRAY_SIZE(stats_registers);
  91679. + fb->stats.regset.base = &fb->stats;
  91680. +
  91681. + if (!debugfs_create_regset32(
  91682. + "stats", 0444, fb->debugfs_dir, &fb->stats.regset)) {
  91683. + pr_warn("%s: could not create statistics registers\n",
  91684. + __func__);
  91685. + goto fail;
  91686. + }
  91687. + return 0;
  91688. +
  91689. +fail:
  91690. + bcm2708_fb_debugfs_deinit(fb);
  91691. + return -EFAULT;
  91692. +}
  91693. +
  91694. +static int bcm2708_fb_set_bitfields(struct fb_var_screeninfo *var)
  91695. +{
  91696. + int ret = 0;
  91697. +
  91698. + memset(&var->transp, 0, sizeof(var->transp));
  91699. +
  91700. + var->red.msb_right = 0;
  91701. + var->green.msb_right = 0;
  91702. + var->blue.msb_right = 0;
  91703. +
  91704. + switch (var->bits_per_pixel) {
  91705. + case 1:
  91706. + case 2:
  91707. + case 4:
  91708. + case 8:
  91709. + var->red.length = var->bits_per_pixel;
  91710. + var->red.offset = 0;
  91711. + var->green.length = var->bits_per_pixel;
  91712. + var->green.offset = 0;
  91713. + var->blue.length = var->bits_per_pixel;
  91714. + var->blue.offset = 0;
  91715. + break;
  91716. + case 16:
  91717. + var->red.length = 5;
  91718. + var->blue.length = 5;
  91719. + /*
  91720. + * Green length can be 5 or 6 depending whether
  91721. + * we're operating in RGB555 or RGB565 mode.
  91722. + */
  91723. + if (var->green.length != 5 && var->green.length != 6)
  91724. + var->green.length = 6;
  91725. + break;
  91726. + case 24:
  91727. + var->red.length = 8;
  91728. + var->blue.length = 8;
  91729. + var->green.length = 8;
  91730. + break;
  91731. + case 32:
  91732. + var->red.length = 8;
  91733. + var->green.length = 8;
  91734. + var->blue.length = 8;
  91735. + var->transp.length = 8;
  91736. + break;
  91737. + default:
  91738. + ret = -EINVAL;
  91739. + break;
  91740. + }
  91741. +
  91742. + /*
  91743. + * >= 16bpp displays have separate colour component bitfields
  91744. + * encoded in the pixel data. Calculate their position from
  91745. + * the bitfield length defined above.
  91746. + */
  91747. + if (ret == 0 && var->bits_per_pixel >= 24 && fbswap) {
  91748. + var->blue.offset = 0;
  91749. + var->green.offset = var->blue.offset + var->blue.length;
  91750. + var->red.offset = var->green.offset + var->green.length;
  91751. + var->transp.offset = var->red.offset + var->red.length;
  91752. + } else if (ret == 0 && var->bits_per_pixel >= 24) {
  91753. + var->red.offset = 0;
  91754. + var->green.offset = var->red.offset + var->red.length;
  91755. + var->blue.offset = var->green.offset + var->green.length;
  91756. + var->transp.offset = var->blue.offset + var->blue.length;
  91757. + } else if (ret == 0 && var->bits_per_pixel >= 16) {
  91758. + var->blue.offset = 0;
  91759. + var->green.offset = var->blue.offset + var->blue.length;
  91760. + var->red.offset = var->green.offset + var->green.length;
  91761. + var->transp.offset = var->red.offset + var->red.length;
  91762. + }
  91763. +
  91764. + return ret;
  91765. +}
  91766. +
  91767. +static int bcm2708_fb_check_var(struct fb_var_screeninfo *var,
  91768. + struct fb_info *info)
  91769. +{
  91770. + /* info input, var output */
  91771. + int yres;
  91772. +
  91773. + /* info input, var output */
  91774. + print_debug("bcm2708_fb_check_var info(%p) %dx%d (%dx%d), %d, %d\n", info,
  91775. + info->var.xres, info->var.yres, info->var.xres_virtual,
  91776. + info->var.yres_virtual, (int)info->screen_size,
  91777. + info->var.bits_per_pixel);
  91778. + print_debug("bcm2708_fb_check_var var(%p) %dx%d (%dx%d), %d\n", var,
  91779. + var->xres, var->yres, var->xres_virtual, var->yres_virtual,
  91780. + var->bits_per_pixel);
  91781. +
  91782. + if (!var->bits_per_pixel)
  91783. + var->bits_per_pixel = 16;
  91784. +
  91785. + if (bcm2708_fb_set_bitfields(var) != 0) {
  91786. + pr_err("bcm2708_fb_check_var: invalid bits_per_pixel %d\n",
  91787. + var->bits_per_pixel);
  91788. + return -EINVAL;
  91789. + }
  91790. +
  91791. +
  91792. + if (var->xres_virtual < var->xres)
  91793. + var->xres_virtual = var->xres;
  91794. + /* use highest possible virtual resolution */
  91795. + if (var->yres_virtual == -1) {
  91796. + var->yres_virtual = 480;
  91797. +
  91798. + pr_err
  91799. + ("bcm2708_fb_check_var: virtual resolution set to maximum of %dx%d\n",
  91800. + var->xres_virtual, var->yres_virtual);
  91801. + }
  91802. + if (var->yres_virtual < var->yres)
  91803. + var->yres_virtual = var->yres;
  91804. +
  91805. + if (var->xoffset < 0)
  91806. + var->xoffset = 0;
  91807. + if (var->yoffset < 0)
  91808. + var->yoffset = 0;
  91809. +
  91810. + /* truncate xoffset and yoffset to maximum if too high */
  91811. + if (var->xoffset > var->xres_virtual - var->xres)
  91812. + var->xoffset = var->xres_virtual - var->xres - 1;
  91813. + if (var->yoffset > var->yres_virtual - var->yres)
  91814. + var->yoffset = var->yres_virtual - var->yres - 1;
  91815. +
  91816. + yres = var->yres;
  91817. + if (var->vmode & FB_VMODE_DOUBLE)
  91818. + yres *= 2;
  91819. + else if (var->vmode & FB_VMODE_INTERLACED)
  91820. + yres = (yres + 1) / 2;
  91821. +
  91822. + if (var->xres * yres > 1920 * 1200) {
  91823. + pr_err("bcm2708_fb_check_var: ERROR: Pixel size >= 1920x1200; "
  91824. + "special treatment required! (TODO)\n");
  91825. + return -EINVAL;
  91826. + }
  91827. +
  91828. + return 0;
  91829. +}
  91830. +
  91831. +static int bcm2708_fb_set_par(struct fb_info *info)
  91832. +{
  91833. + uint32_t val = 0;
  91834. + struct bcm2708_fb *fb = to_bcm2708(info);
  91835. + volatile struct fbinfo_s *fbinfo = fb->info;
  91836. + fbinfo->xres = info->var.xres;
  91837. + fbinfo->yres = info->var.yres;
  91838. + fbinfo->xres_virtual = info->var.xres_virtual;
  91839. + fbinfo->yres_virtual = info->var.yres_virtual;
  91840. + fbinfo->bpp = info->var.bits_per_pixel;
  91841. + fbinfo->xoffset = info->var.xoffset;
  91842. + fbinfo->yoffset = info->var.yoffset;
  91843. + fbinfo->base = 0; /* filled in by VC */
  91844. + fbinfo->pitch = 0; /* filled in by VC */
  91845. +
  91846. + print_debug("bcm2708_fb_set_par info(%p) %dx%d (%dx%d), %d, %d\n", info,
  91847. + info->var.xres, info->var.yres, info->var.xres_virtual,
  91848. + info->var.yres_virtual, (int)info->screen_size,
  91849. + info->var.bits_per_pixel);
  91850. +
  91851. + /* ensure last write to fbinfo is visible to GPU */
  91852. + wmb();
  91853. +
  91854. + /* inform vc about new framebuffer */
  91855. + bcm_mailbox_write(MBOX_CHAN_FB, fb->dma);
  91856. +
  91857. + /* TODO: replace fb driver with vchiq version */
  91858. + /* wait for response */
  91859. + bcm_mailbox_read(MBOX_CHAN_FB, &val);
  91860. +
  91861. + /* ensure GPU writes are visible to us */
  91862. + rmb();
  91863. +
  91864. + if (val == 0) {
  91865. + fb->fb.fix.line_length = fbinfo->pitch;
  91866. +
  91867. + if (info->var.bits_per_pixel <= 8)
  91868. + fb->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR;
  91869. + else
  91870. + fb->fb.fix.visual = FB_VISUAL_TRUECOLOR;
  91871. +
  91872. + fb->fb.fix.smem_start = fbinfo->base;
  91873. + fb->fb.fix.smem_len = fbinfo->pitch * fbinfo->yres_virtual;
  91874. + fb->fb.screen_size = fbinfo->screen_size;
  91875. + if (fb->fb.screen_base)
  91876. + iounmap(fb->fb.screen_base);
  91877. + fb->fb.screen_base =
  91878. + (void *)ioremap_wc(fb->fb.fix.smem_start, fb->fb.screen_size);
  91879. + if (!fb->fb.screen_base) {
  91880. + /* the console may currently be locked */
  91881. + console_trylock();
  91882. + console_unlock();
  91883. +
  91884. + BUG(); /* what can we do here */
  91885. + }
  91886. + }
  91887. + print_debug
  91888. + ("BCM2708FB: start = %p,%p width=%d, height=%d, bpp=%d, pitch=%d size=%d success=%d\n",
  91889. + (void *)fb->fb.screen_base, (void *)fb->fb.fix.smem_start,
  91890. + fbinfo->xres, fbinfo->yres, fbinfo->bpp,
  91891. + fbinfo->pitch, (int)fb->fb.screen_size, val);
  91892. +
  91893. + return val;
  91894. +}
  91895. +
  91896. +static inline u32 convert_bitfield(int val, struct fb_bitfield *bf)
  91897. +{
  91898. + unsigned int mask = (1 << bf->length) - 1;
  91899. +
  91900. + return (val >> (16 - bf->length) & mask) << bf->offset;
  91901. +}
  91902. +
  91903. +
  91904. +static int bcm2708_fb_setcolreg(unsigned int regno, unsigned int red,
  91905. + unsigned int green, unsigned int blue,
  91906. + unsigned int transp, struct fb_info *info)
  91907. +{
  91908. + struct bcm2708_fb *fb = to_bcm2708(info);
  91909. +
  91910. + /*print_debug("BCM2708FB: setcolreg %d:(%02x,%02x,%02x,%02x) %x\n", regno, red, green, blue, transp, fb->fb.fix.visual);*/
  91911. + if (fb->fb.var.bits_per_pixel <= 8) {
  91912. + if (regno < 256) {
  91913. + /* blue [0:4], green [5:10], red [11:15] */
  91914. + fb->info->cmap[regno] = ((red >> (16-5)) & 0x1f) << 11 |
  91915. + ((green >> (16-6)) & 0x3f) << 5 |
  91916. + ((blue >> (16-5)) & 0x1f) << 0;
  91917. + }
  91918. + /* 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 */
  91919. + /* So just call it for what looks like the last colour in a list for now. */
  91920. + if (regno == 15 || regno == 255)
  91921. + bcm2708_fb_set_par(info);
  91922. + } else if (regno < 16) {
  91923. + fb->cmap[regno] = convert_bitfield(transp, &fb->fb.var.transp) |
  91924. + convert_bitfield(blue, &fb->fb.var.blue) |
  91925. + convert_bitfield(green, &fb->fb.var.green) |
  91926. + convert_bitfield(red, &fb->fb.var.red);
  91927. + }
  91928. + return regno > 255;
  91929. +}
  91930. +
  91931. +static int bcm2708_fb_blank(int blank_mode, struct fb_info *info)
  91932. +{
  91933. + /*print_debug("bcm2708_fb_blank\n"); */
  91934. + return -1;
  91935. +}
  91936. +
  91937. +static void bcm2708_fb_fillrect(struct fb_info *info,
  91938. + const struct fb_fillrect *rect)
  91939. +{
  91940. + /* (is called) print_debug("bcm2708_fb_fillrect\n"); */
  91941. + cfb_fillrect(info, rect);
  91942. +}
  91943. +
  91944. +/* A helper function for configuring dma control block */
  91945. +static void set_dma_cb(struct bcm2708_dma_cb *cb,
  91946. + int burst_size,
  91947. + dma_addr_t dst,
  91948. + int dst_stride,
  91949. + dma_addr_t src,
  91950. + int src_stride,
  91951. + int w,
  91952. + int h)
  91953. +{
  91954. + cb->info = BCM2708_DMA_BURST(burst_size) | BCM2708_DMA_S_WIDTH |
  91955. + BCM2708_DMA_S_INC | BCM2708_DMA_D_WIDTH |
  91956. + BCM2708_DMA_D_INC | BCM2708_DMA_TDMODE;
  91957. + cb->dst = dst;
  91958. + cb->src = src;
  91959. + /*
  91960. + * This is not really obvious from the DMA documentation,
  91961. + * but the top 16 bits must be programmmed to "height -1"
  91962. + * and not "height" in 2D mode.
  91963. + */
  91964. + cb->length = ((h - 1) << 16) | w;
  91965. + cb->stride = ((dst_stride - w) << 16) | (u16)(src_stride - w);
  91966. + cb->pad[0] = 0;
  91967. + cb->pad[1] = 0;
  91968. +}
  91969. +
  91970. +static void bcm2708_fb_copyarea(struct fb_info *info,
  91971. + const struct fb_copyarea *region)
  91972. +{
  91973. + struct bcm2708_fb *fb = to_bcm2708(info);
  91974. + struct bcm2708_dma_cb *cb = fb->cb_base;
  91975. + int bytes_per_pixel = (info->var.bits_per_pixel + 7) >> 3;
  91976. + /* Channel 0 supports larger bursts and is a bit faster */
  91977. + int burst_size = (fb->dma_chan == 0) ? 8 : 2;
  91978. + int pixels = region->width * region->height;
  91979. +
  91980. + /* Fallback to cfb_copyarea() if we don't like something */
  91981. + if (bytes_per_pixel > 4 ||
  91982. + info->var.xres * info->var.yres > 1920 * 1200 ||
  91983. + region->width <= 0 || region->width > info->var.xres ||
  91984. + region->height <= 0 || region->height > info->var.yres ||
  91985. + region->sx < 0 || region->sx >= info->var.xres ||
  91986. + region->sy < 0 || region->sy >= info->var.yres ||
  91987. + region->dx < 0 || region->dx >= info->var.xres ||
  91988. + region->dy < 0 || region->dy >= info->var.yres ||
  91989. + region->sx + region->width > info->var.xres ||
  91990. + region->dx + region->width > info->var.xres ||
  91991. + region->sy + region->height > info->var.yres ||
  91992. + region->dy + region->height > info->var.yres) {
  91993. + cfb_copyarea(info, region);
  91994. + return;
  91995. + }
  91996. +
  91997. + if (region->dy == region->sy && region->dx > region->sx) {
  91998. + /*
  91999. + * A difficult case of overlapped copy. Because DMA can't
  92000. + * copy individual scanlines in backwards direction, we need
  92001. + * two-pass processing. We do it by programming a chain of dma
  92002. + * control blocks in the first 16K part of the buffer and use
  92003. + * the remaining 48K as the intermediate temporary scratch
  92004. + * buffer. The buffer size is sufficient to handle up to
  92005. + * 1920x1200 resolution at 32bpp pixel depth.
  92006. + */
  92007. + int y;
  92008. + dma_addr_t control_block_pa = fb->cb_handle;
  92009. + dma_addr_t scratchbuf = fb->cb_handle + 16 * 1024;
  92010. + int scanline_size = bytes_per_pixel * region->width;
  92011. + int scanlines_per_cb = (64 * 1024 - 16 * 1024) / scanline_size;
  92012. +
  92013. + for (y = 0; y < region->height; y += scanlines_per_cb) {
  92014. + dma_addr_t src =
  92015. + fb->fb.fix.smem_start +
  92016. + bytes_per_pixel * region->sx +
  92017. + (region->sy + y) * fb->fb.fix.line_length;
  92018. + dma_addr_t dst =
  92019. + fb->fb.fix.smem_start +
  92020. + bytes_per_pixel * region->dx +
  92021. + (region->dy + y) * fb->fb.fix.line_length;
  92022. +
  92023. + if (region->height - y < scanlines_per_cb)
  92024. + scanlines_per_cb = region->height - y;
  92025. +
  92026. + set_dma_cb(cb, burst_size, scratchbuf, scanline_size,
  92027. + src, fb->fb.fix.line_length,
  92028. + scanline_size, scanlines_per_cb);
  92029. + control_block_pa += sizeof(struct bcm2708_dma_cb);
  92030. + cb->next = control_block_pa;
  92031. + cb++;
  92032. +
  92033. + set_dma_cb(cb, burst_size, dst, fb->fb.fix.line_length,
  92034. + scratchbuf, scanline_size,
  92035. + scanline_size, scanlines_per_cb);
  92036. + control_block_pa += sizeof(struct bcm2708_dma_cb);
  92037. + cb->next = control_block_pa;
  92038. + cb++;
  92039. + }
  92040. + /* move the pointer back to the last dma control block */
  92041. + cb--;
  92042. + } else {
  92043. + /* A single dma control block is enough. */
  92044. + int sy, dy, stride;
  92045. + if (region->dy <= region->sy) {
  92046. + /* processing from top to bottom */
  92047. + dy = region->dy;
  92048. + sy = region->sy;
  92049. + stride = fb->fb.fix.line_length;
  92050. + } else {
  92051. + /* processing from bottom to top */
  92052. + dy = region->dy + region->height - 1;
  92053. + sy = region->sy + region->height - 1;
  92054. + stride = -fb->fb.fix.line_length;
  92055. + }
  92056. + set_dma_cb(cb, burst_size,
  92057. + fb->fb.fix.smem_start + dy * fb->fb.fix.line_length +
  92058. + bytes_per_pixel * region->dx,
  92059. + stride,
  92060. + fb->fb.fix.smem_start + sy * fb->fb.fix.line_length +
  92061. + bytes_per_pixel * region->sx,
  92062. + stride,
  92063. + region->width * bytes_per_pixel,
  92064. + region->height);
  92065. + }
  92066. +
  92067. + /* end of dma control blocks chain */
  92068. + cb->next = 0;
  92069. +
  92070. +
  92071. + if (pixels < dma_busy_wait_threshold) {
  92072. + bcm_dma_start(fb->dma_chan_base, fb->cb_handle);
  92073. + bcm_dma_wait_idle(fb->dma_chan_base);
  92074. + } else {
  92075. + void __iomem *dma_chan = fb->dma_chan_base;
  92076. + cb->info |= BCM2708_DMA_INT_EN;
  92077. + bcm_dma_start(fb->dma_chan_base, fb->cb_handle);
  92078. + while (bcm_dma_is_busy(dma_chan)) {
  92079. + wait_event_interruptible(
  92080. + fb->dma_waitq,
  92081. + !bcm_dma_is_busy(dma_chan));
  92082. + }
  92083. + fb->stats.dma_irqs++;
  92084. + }
  92085. + fb->stats.dma_copies++;
  92086. +}
  92087. +
  92088. +static void bcm2708_fb_imageblit(struct fb_info *info,
  92089. + const struct fb_image *image)
  92090. +{
  92091. + /* (is called) print_debug("bcm2708_fb_imageblit\n"); */
  92092. + cfb_imageblit(info, image);
  92093. +}
  92094. +
  92095. +static irqreturn_t bcm2708_fb_dma_irq(int irq, void *cxt)
  92096. +{
  92097. + struct bcm2708_fb *fb = cxt;
  92098. +
  92099. + /* FIXME: should read status register to check if this is
  92100. + * actually interrupting us or not, in case this interrupt
  92101. + * ever becomes shared amongst several DMA channels
  92102. + *
  92103. + * readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_IRQ;
  92104. + */
  92105. +
  92106. + /* acknowledge the interrupt */
  92107. + writel(BCM2708_DMA_INT, fb->dma_chan_base + BCM2708_DMA_CS);
  92108. +
  92109. + wake_up(&fb->dma_waitq);
  92110. + return IRQ_HANDLED;
  92111. +}
  92112. +
  92113. +static struct fb_ops bcm2708_fb_ops = {
  92114. + .owner = THIS_MODULE,
  92115. + .fb_check_var = bcm2708_fb_check_var,
  92116. + .fb_set_par = bcm2708_fb_set_par,
  92117. + .fb_setcolreg = bcm2708_fb_setcolreg,
  92118. + .fb_blank = bcm2708_fb_blank,
  92119. + .fb_fillrect = bcm2708_fb_fillrect,
  92120. + .fb_copyarea = bcm2708_fb_copyarea,
  92121. + .fb_imageblit = bcm2708_fb_imageblit,
  92122. +};
  92123. +
  92124. +static int bcm2708_fb_register(struct bcm2708_fb *fb)
  92125. +{
  92126. + int ret;
  92127. + dma_addr_t dma;
  92128. + void *mem;
  92129. +
  92130. + mem =
  92131. + dma_alloc_coherent(NULL, PAGE_ALIGN(sizeof(*fb->info)), &dma,
  92132. + GFP_KERNEL);
  92133. +
  92134. + if (NULL == mem) {
  92135. + pr_err(": unable to allocate fbinfo buffer\n");
  92136. + ret = -ENOMEM;
  92137. + } else {
  92138. + fb->info = (struct fbinfo_s *)mem;
  92139. + fb->dma = dma;
  92140. + }
  92141. + fb->fb.fbops = &bcm2708_fb_ops;
  92142. + fb->fb.flags = FBINFO_FLAG_DEFAULT | FBINFO_HWACCEL_COPYAREA;
  92143. + fb->fb.pseudo_palette = fb->cmap;
  92144. +
  92145. + strncpy(fb->fb.fix.id, bcm2708_name, sizeof(fb->fb.fix.id));
  92146. + fb->fb.fix.type = FB_TYPE_PACKED_PIXELS;
  92147. + fb->fb.fix.type_aux = 0;
  92148. + fb->fb.fix.xpanstep = 0;
  92149. + fb->fb.fix.ypanstep = 0;
  92150. + fb->fb.fix.ywrapstep = 0;
  92151. + fb->fb.fix.accel = FB_ACCEL_NONE;
  92152. +
  92153. + fb->fb.var.xres = fbwidth;
  92154. + fb->fb.var.yres = fbheight;
  92155. + fb->fb.var.xres_virtual = fbwidth;
  92156. + fb->fb.var.yres_virtual = fbheight;
  92157. + fb->fb.var.bits_per_pixel = fbdepth;
  92158. + fb->fb.var.vmode = FB_VMODE_NONINTERLACED;
  92159. + fb->fb.var.activate = FB_ACTIVATE_NOW;
  92160. + fb->fb.var.nonstd = 0;
  92161. + fb->fb.var.height = -1; /* height of picture in mm */
  92162. + fb->fb.var.width = -1; /* width of picture in mm */
  92163. + fb->fb.var.accel_flags = 0;
  92164. +
  92165. + fb->fb.monspecs.hfmin = 0;
  92166. + fb->fb.monspecs.hfmax = 100000;
  92167. + fb->fb.monspecs.vfmin = 0;
  92168. + fb->fb.monspecs.vfmax = 400;
  92169. + fb->fb.monspecs.dclkmin = 1000000;
  92170. + fb->fb.monspecs.dclkmax = 100000000;
  92171. +
  92172. + bcm2708_fb_set_bitfields(&fb->fb.var);
  92173. + init_waitqueue_head(&fb->dma_waitq);
  92174. +
  92175. + /*
  92176. + * Allocate colourmap.
  92177. + */
  92178. +
  92179. + fb_set_var(&fb->fb, &fb->fb.var);
  92180. +
  92181. + print_debug("BCM2708FB: registering framebuffer (%dx%d@%d) (%d)\n", fbwidth
  92182. + fbheight, fbdepth, fbswap);
  92183. +
  92184. + ret = register_framebuffer(&fb->fb);
  92185. + print_debug("BCM2708FB: register framebuffer (%d)\n", ret);
  92186. + if (ret == 0)
  92187. + goto out;
  92188. +
  92189. + print_debug("BCM2708FB: cannot register framebuffer (%d)\n", ret);
  92190. +out:
  92191. + return ret;
  92192. +}
  92193. +
  92194. +static int bcm2708_fb_probe(struct platform_device *dev)
  92195. +{
  92196. + struct bcm2708_fb *fb;
  92197. + int ret;
  92198. +
  92199. + fb = kzalloc(sizeof(struct bcm2708_fb), GFP_KERNEL);
  92200. + if (!fb) {
  92201. + dev_err(&dev->dev,
  92202. + "could not allocate new bcm2708_fb struct\n");
  92203. + ret = -ENOMEM;
  92204. + goto free_region;
  92205. + }
  92206. +
  92207. + bcm2708_fb_debugfs_init(fb);
  92208. +
  92209. +
  92210. + bcm2708_fb_debugfs_init(fb);
  92211. +
  92212. + fb->cb_base = dma_alloc_writecombine(&dev->dev, SZ_64K,
  92213. + &fb->cb_handle, GFP_KERNEL);
  92214. + if (!fb->cb_base) {
  92215. + dev_err(&dev->dev, "cannot allocate DMA CBs\n");
  92216. + ret = -ENOMEM;
  92217. + goto free_fb;
  92218. + }
  92219. +
  92220. + pr_info("BCM2708FB: allocated DMA memory %08x\n",
  92221. + fb->cb_handle);
  92222. +
  92223. + ret = bcm_dma_chan_alloc(BCM_DMA_FEATURE_BULK,
  92224. + &fb->dma_chan_base, &fb->dma_irq);
  92225. + if (ret < 0) {
  92226. + dev_err(&dev->dev, "couldn't allocate a DMA channel\n");
  92227. + goto free_cb;
  92228. + }
  92229. + fb->dma_chan = ret;
  92230. +
  92231. + ret = request_irq(fb->dma_irq, bcm2708_fb_dma_irq,
  92232. + 0, "bcm2708_fb dma", fb);
  92233. + if (ret) {
  92234. + pr_err("%s: failed to request DMA irq\n", __func__);
  92235. + goto free_dma_chan;
  92236. + }
  92237. +
  92238. +
  92239. + pr_info("BCM2708FB: allocated DMA channel %d @ %p\n",
  92240. + fb->dma_chan, fb->dma_chan_base);
  92241. +
  92242. + fb->dev = dev;
  92243. +
  92244. + ret = bcm2708_fb_register(fb);
  92245. + if (ret == 0) {
  92246. + platform_set_drvdata(dev, fb);
  92247. + goto out;
  92248. + }
  92249. +
  92250. +free_dma_chan:
  92251. + bcm_dma_chan_free(fb->dma_chan);
  92252. +free_cb:
  92253. + dma_free_writecombine(&dev->dev, SZ_64K, fb->cb_base, fb->cb_handle);
  92254. +free_fb:
  92255. + kfree(fb);
  92256. +free_region:
  92257. + dev_err(&dev->dev, "probe failed, err %d\n", ret);
  92258. +out:
  92259. + return ret;
  92260. +}
  92261. +
  92262. +static int bcm2708_fb_remove(struct platform_device *dev)
  92263. +{
  92264. + struct bcm2708_fb *fb = platform_get_drvdata(dev);
  92265. +
  92266. + platform_set_drvdata(dev, NULL);
  92267. +
  92268. + if (fb->fb.screen_base)
  92269. + iounmap(fb->fb.screen_base);
  92270. + unregister_framebuffer(&fb->fb);
  92271. +
  92272. + dma_free_writecombine(&dev->dev, SZ_64K, fb->cb_base, fb->cb_handle);
  92273. + bcm_dma_chan_free(fb->dma_chan);
  92274. +
  92275. + dma_free_coherent(NULL, PAGE_ALIGN(sizeof(*fb->info)), (void *)fb->info,
  92276. + fb->dma);
  92277. + bcm2708_fb_debugfs_deinit(fb);
  92278. +
  92279. + free_irq(fb->dma_irq, fb);
  92280. +
  92281. + kfree(fb);
  92282. +
  92283. + return 0;
  92284. +}
  92285. +
  92286. +static struct platform_driver bcm2708_fb_driver = {
  92287. + .probe = bcm2708_fb_probe,
  92288. + .remove = bcm2708_fb_remove,
  92289. + .driver = {
  92290. + .name = DRIVER_NAME,
  92291. + .owner = THIS_MODULE,
  92292. + },
  92293. +};
  92294. +
  92295. +static int __init bcm2708_fb_init(void)
  92296. +{
  92297. + return platform_driver_register(&bcm2708_fb_driver);
  92298. +}
  92299. +
  92300. +module_init(bcm2708_fb_init);
  92301. +
  92302. +static void __exit bcm2708_fb_exit(void)
  92303. +{
  92304. + platform_driver_unregister(&bcm2708_fb_driver);
  92305. +}
  92306. +
  92307. +module_exit(bcm2708_fb_exit);
  92308. +
  92309. +module_param(fbwidth, int, 0644);
  92310. +module_param(fbheight, int, 0644);
  92311. +module_param(fbdepth, int, 0644);
  92312. +module_param(fbswap, int, 0644);
  92313. +
  92314. +MODULE_DESCRIPTION("BCM2708 framebuffer driver");
  92315. +MODULE_LICENSE("GPL");
  92316. +
  92317. +MODULE_PARM_DESC(fbwidth, "Width of ARM Framebuffer");
  92318. +MODULE_PARM_DESC(fbheight, "Height of ARM Framebuffer");
  92319. +MODULE_PARM_DESC(fbdepth, "Bit depth of ARM Framebuffer");
  92320. +MODULE_PARM_DESC(fbswap, "Swap order of red and blue in 24 and 32 bit modes");
  92321. diff -Nur linux-3.13.3.orig/drivers/video/cfbimgblt.c linux-3.13.3/drivers/video/cfbimgblt.c
  92322. --- linux-3.13.3.orig/drivers/video/cfbimgblt.c 2014-02-13 23:00:14.000000000 +0100
  92323. +++ linux-3.13.3/drivers/video/cfbimgblt.c 2014-02-17 22:41:02.000000000 +0100
  92324. @@ -28,6 +28,11 @@
  92325. *
  92326. * Also need to add code to deal with cards endians that are different than
  92327. * the native cpu endians. I also need to deal with MSB position in the word.
  92328. + * Modified by Harm Hanemaaijer (fgenfb@yahoo.com) 2013:
  92329. + * - Provide optimized versions of fast_imageblit for 16 and 32bpp that are
  92330. + * significantly faster than the previous implementation.
  92331. + * - Simplify the fast/slow_imageblit selection code, avoiding integer
  92332. + * divides.
  92333. */
  92334. #include <linux/module.h>
  92335. #include <linux/string.h>
  92336. @@ -262,6 +267,133 @@
  92337. }
  92338. }
  92339. +/*
  92340. + * Optimized fast_imageblit for bpp == 16. ppw = 2, bit_mask = 3 folded
  92341. + * into the code, main loop unrolled.
  92342. + */
  92343. +
  92344. +static inline void fast_imageblit16(const struct fb_image *image,
  92345. + struct fb_info *p, u8 __iomem * dst1,
  92346. + u32 fgcolor, u32 bgcolor)
  92347. +{
  92348. + u32 fgx = fgcolor, bgx = bgcolor;
  92349. + u32 spitch = (image->width + 7) / 8;
  92350. + u32 end_mask, eorx;
  92351. + const char *s = image->data, *src;
  92352. + u32 __iomem *dst;
  92353. + const u32 *tab = NULL;
  92354. + int i, j, k;
  92355. +
  92356. + tab = fb_be_math(p) ? cfb_tab16_be : cfb_tab16_le;
  92357. +
  92358. + fgx <<= 16;
  92359. + bgx <<= 16;
  92360. + fgx |= fgcolor;
  92361. + bgx |= bgcolor;
  92362. +
  92363. + eorx = fgx ^ bgx;
  92364. + k = image->width / 2;
  92365. +
  92366. + for (i = image->height; i--;) {
  92367. + dst = (u32 __iomem *) dst1;
  92368. + src = s;
  92369. +
  92370. + j = k;
  92371. + while (j >= 4) {
  92372. + u8 bits = *src;
  92373. + end_mask = tab[(bits >> 6) & 3];
  92374. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  92375. + end_mask = tab[(bits >> 4) & 3];
  92376. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  92377. + end_mask = tab[(bits >> 2) & 3];
  92378. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  92379. + end_mask = tab[bits & 3];
  92380. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  92381. + src++;
  92382. + j -= 4;
  92383. + }
  92384. + if (j != 0) {
  92385. + u8 bits = *src;
  92386. + end_mask = tab[(bits >> 6) & 3];
  92387. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  92388. + if (j >= 2) {
  92389. + end_mask = tab[(bits >> 4) & 3];
  92390. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  92391. + if (j == 3) {
  92392. + end_mask = tab[(bits >> 2) & 3];
  92393. + FB_WRITEL((end_mask & eorx) ^ bgx, dst);
  92394. + }
  92395. + }
  92396. + }
  92397. + dst1 += p->fix.line_length;
  92398. + s += spitch;
  92399. + }
  92400. +}
  92401. +
  92402. +/*
  92403. + * Optimized fast_imageblit for bpp == 32. ppw = 1, bit_mask = 1 folded
  92404. + * into the code, main loop unrolled.
  92405. + */
  92406. +
  92407. +static inline void fast_imageblit32(const struct fb_image *image,
  92408. + struct fb_info *p, u8 __iomem * dst1,
  92409. + u32 fgcolor, u32 bgcolor)
  92410. +{
  92411. + u32 fgx = fgcolor, bgx = bgcolor;
  92412. + u32 spitch = (image->width + 7) / 8;
  92413. + u32 end_mask, eorx;
  92414. + const char *s = image->data, *src;
  92415. + u32 __iomem *dst;
  92416. + const u32 *tab = NULL;
  92417. + int i, j, k;
  92418. +
  92419. + tab = cfb_tab32;
  92420. +
  92421. + eorx = fgx ^ bgx;
  92422. + k = image->width;
  92423. +
  92424. + for (i = image->height; i--;) {
  92425. + dst = (u32 __iomem *) dst1;
  92426. + src = s;
  92427. +
  92428. + j = k;
  92429. + while (j >= 8) {
  92430. + u8 bits = *src;
  92431. + end_mask = tab[(bits >> 7) & 1];
  92432. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  92433. + end_mask = tab[(bits >> 6) & 1];
  92434. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  92435. + end_mask = tab[(bits >> 5) & 1];
  92436. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  92437. + end_mask = tab[(bits >> 4) & 1];
  92438. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  92439. + end_mask = tab[(bits >> 3) & 1];
  92440. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  92441. + end_mask = tab[(bits >> 2) & 1];
  92442. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  92443. + end_mask = tab[(bits >> 1) & 1];
  92444. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  92445. + end_mask = tab[bits & 1];
  92446. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  92447. + src++;
  92448. + j -= 8;
  92449. + }
  92450. + if (j != 0) {
  92451. + u32 bits = (u32) * src;
  92452. + while (j > 1) {
  92453. + end_mask = tab[(bits >> 7) & 1];
  92454. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  92455. + bits <<= 1;
  92456. + j--;
  92457. + }
  92458. + end_mask = tab[(bits >> 7) & 1];
  92459. + FB_WRITEL((end_mask & eorx) ^ bgx, dst);
  92460. + }
  92461. + dst1 += p->fix.line_length;
  92462. + s += spitch;
  92463. + }
  92464. +}
  92465. +
  92466. void cfb_imageblit(struct fb_info *p, const struct fb_image *image)
  92467. {
  92468. u32 fgcolor, bgcolor, start_index, bitstart, pitch_index = 0;
  92469. @@ -294,11 +426,21 @@
  92470. bgcolor = image->bg_color;
  92471. }
  92472. - if (32 % bpp == 0 && !start_index && !pitch_index &&
  92473. - ((width & (32/bpp-1)) == 0) &&
  92474. - bpp >= 8 && bpp <= 32)
  92475. - fast_imageblit(image, p, dst1, fgcolor, bgcolor);
  92476. - else
  92477. + if (!start_index && !pitch_index) {
  92478. + if (bpp == 32)
  92479. + fast_imageblit32(image, p, dst1, fgcolor,
  92480. + bgcolor);
  92481. + else if (bpp == 16 && (width & 1) == 0)
  92482. + fast_imageblit16(image, p, dst1, fgcolor,
  92483. + bgcolor);
  92484. + else if (bpp == 8 && (width & 3) == 0)
  92485. + fast_imageblit(image, p, dst1, fgcolor,
  92486. + bgcolor);
  92487. + else
  92488. + slow_imageblit(image, p, dst1, fgcolor,
  92489. + bgcolor,
  92490. + start_index, pitch_index);
  92491. + } else
  92492. slow_imageblit(image, p, dst1, fgcolor, bgcolor,
  92493. start_index, pitch_index);
  92494. } else
  92495. diff -Nur linux-3.13.3.orig/drivers/video/fbmem.c linux-3.13.3/drivers/video/fbmem.c
  92496. --- linux-3.13.3.orig/drivers/video/fbmem.c 2014-02-13 23:00:14.000000000 +0100
  92497. +++ linux-3.13.3/drivers/video/fbmem.c 2014-02-17 22:41:02.000000000 +0100
  92498. @@ -1083,6 +1083,25 @@
  92499. }
  92500. EXPORT_SYMBOL(fb_blank);
  92501. +static int fb_copyarea_user(struct fb_info *info,
  92502. + struct fb_copyarea *copy)
  92503. +{
  92504. + int ret = 0;
  92505. + if (!lock_fb_info(info))
  92506. + return -ENODEV;
  92507. + if (copy->dx + copy->width > info->var.xres ||
  92508. + copy->sx + copy->width > info->var.xres ||
  92509. + copy->dy + copy->height > info->var.yres ||
  92510. + copy->sy + copy->height > info->var.yres) {
  92511. + ret = -EINVAL;
  92512. + goto out;
  92513. + }
  92514. + info->fbops->fb_copyarea(info, copy);
  92515. +out:
  92516. + unlock_fb_info(info);
  92517. + return ret;
  92518. +}
  92519. +
  92520. static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
  92521. unsigned long arg)
  92522. {
  92523. @@ -1093,6 +1112,7 @@
  92524. struct fb_cmap cmap_from;
  92525. struct fb_cmap_user cmap;
  92526. struct fb_event event;
  92527. + struct fb_copyarea copy;
  92528. void __user *argp = (void __user *)arg;
  92529. long ret = 0;
  92530. @@ -1210,6 +1230,15 @@
  92531. unlock_fb_info(info);
  92532. console_unlock();
  92533. break;
  92534. + case FBIOCOPYAREA:
  92535. + if (info->flags & FBINFO_HWACCEL_COPYAREA) {
  92536. + /* only provide this ioctl if it is accelerated */
  92537. + if (copy_from_user(&copy, argp, sizeof(copy)))
  92538. + return -EFAULT;
  92539. + ret = fb_copyarea_user(info, &copy);
  92540. + break;
  92541. + }
  92542. + /* fall through */
  92543. default:
  92544. if (!lock_fb_info(info))
  92545. return -ENODEV;
  92546. @@ -1364,6 +1393,7 @@
  92547. case FBIOPAN_DISPLAY:
  92548. case FBIOGET_CON2FBMAP:
  92549. case FBIOPUT_CON2FBMAP:
  92550. + case FBIOCOPYAREA:
  92551. arg = (unsigned long) compat_ptr(arg);
  92552. case FBIOBLANK:
  92553. ret = do_fb_ioctl(info, cmd, arg);
  92554. diff -Nur linux-3.13.3.orig/drivers/video/Kconfig linux-3.13.3/drivers/video/Kconfig
  92555. --- linux-3.13.3.orig/drivers/video/Kconfig 2014-02-13 23:00:14.000000000 +0100
  92556. +++ linux-3.13.3/drivers/video/Kconfig 2014-02-17 22:41:02.000000000 +0100
  92557. @@ -310,6 +310,20 @@
  92558. help
  92559. Support the Permedia2 FIFO disconnect feature.
  92560. +config FB_BCM2708
  92561. + tristate "BCM2708 framebuffer support"
  92562. + depends on FB && ARM
  92563. + select FB_CFB_FILLRECT
  92564. + select FB_CFB_COPYAREA
  92565. + select FB_CFB_IMAGEBLIT
  92566. + help
  92567. + This framebuffer device driver is for the BCM2708 framebuffer.
  92568. +
  92569. + If you want to compile this as a module (=code which can be
  92570. + inserted into and removed from the running kernel), say M
  92571. + here and read <file:Documentation/kbuild/modules.txt>. The module
  92572. + will be called bcm2708_fb.
  92573. +
  92574. config FB_ARMCLCD
  92575. tristate "ARM PrimeCell PL110 support"
  92576. depends on FB && ARM && ARM_AMBA
  92577. diff -Nur linux-3.13.3.orig/drivers/video/logo/logo_linux_clut224.ppm linux-3.13.3/drivers/video/logo/logo_linux_clut224.ppm
  92578. --- linux-3.13.3.orig/drivers/video/logo/logo_linux_clut224.ppm 2014-02-13 23:00:14.000000000 +0100
  92579. +++ linux-3.13.3/drivers/video/logo/logo_linux_clut224.ppm 2014-02-17 22:41:02.000000000 +0100
  92580. @@ -1,1604 +1,883 @@
  92581. P3
  92582. -# Standard 224-color Linux logo
  92583. -80 80
  92584. +63 80
  92585. 255
  92586. - 0 0 0 0 0 0 0 0 0 0 0 0
  92587. - 0 0 0 0 0 0 0 0 0 0 0 0
  92588. - 0 0 0 0 0 0 0 0 0 0 0 0
  92589. - 0 0 0 0 0 0 0 0 0 0 0 0
  92590. - 0 0 0 0 0 0 0 0 0 0 0 0
  92591. - 0 0 0 0 0 0 0 0 0 0 0 0
  92592. - 0 0 0 0 0 0 0 0 0 0 0 0
  92593. - 0 0 0 0 0 0 0 0 0 0 0 0
  92594. - 0 0 0 0 0 0 0 0 0 0 0 0
  92595. - 6 6 6 6 6 6 10 10 10 10 10 10
  92596. - 10 10 10 6 6 6 6 6 6 6 6 6
  92597. - 0 0 0 0 0 0 0 0 0 0 0 0
  92598. - 0 0 0 0 0 0 0 0 0 0 0 0
  92599. - 0 0 0 0 0 0 0 0 0 0 0 0
  92600. - 0 0 0 0 0 0 0 0 0 0 0 0
  92601. - 0 0 0 0 0 0 0 0 0 0 0 0
  92602. - 0 0 0 0 0 0 0 0 0 0 0 0
  92603. - 0 0 0 0 0 0 0 0 0 0 0 0
  92604. - 0 0 0 0 0 0 0 0 0 0 0 0
  92605. - 0 0 0 0 0 0 0 0 0 0 0 0
  92606. - 0 0 0 0 0 0 0 0 0 0 0 0
  92607. - 0 0 0 0 0 0 0 0 0 0 0 0
  92608. - 0 0 0 0 0 0 0 0 0 0 0 0
  92609. - 0 0 0 0 0 0 0 0 0 0 0 0
  92610. - 0 0 0 0 0 0 0 0 0 0 0 0
  92611. - 0 0 0 0 0 0 0 0 0 0 0 0
  92612. - 0 0 0 0 0 0 0 0 0 0 0 0
  92613. - 0 0 0 0 0 0 0 0 0 0 0 0
  92614. - 0 0 0 6 6 6 10 10 10 14 14 14
  92615. - 22 22 22 26 26 26 30 30 30 34 34 34
  92616. - 30 30 30 30 30 30 26 26 26 18 18 18
  92617. - 14 14 14 10 10 10 6 6 6 0 0 0
  92618. - 0 0 0 0 0 0 0 0 0 0 0 0
  92619. - 0 0 0 0 0 0 0 0 0 0 0 0
  92620. - 0 0 0 0 0 0 0 0 0 0 0 0
  92621. - 0 0 0 0 0 0 0 0 0 0 0 0
  92622. - 0 0 0 0 0 0 0 0 0 0 0 0
  92623. - 0 0 0 0 0 0 0 0 0 0 0 0
  92624. - 0 0 0 0 0 0 0 0 0 0 0 0
  92625. - 0 0 0 0 0 0 0 0 0 0 0 0
  92626. - 0 0 0 0 0 0 0 0 0 0 0 0
  92627. - 0 0 0 0 0 1 0 0 1 0 0 0
  92628. - 0 0 0 0 0 0 0 0 0 0 0 0
  92629. - 0 0 0 0 0 0 0 0 0 0 0 0
  92630. - 0 0 0 0 0 0 0 0 0 0 0 0
  92631. - 0 0 0 0 0 0 0 0 0 0 0 0
  92632. - 0 0 0 0 0 0 0 0 0 0 0 0
  92633. - 0 0 0 0 0 0 0 0 0 0 0 0
  92634. - 6 6 6 14 14 14 26 26 26 42 42 42
  92635. - 54 54 54 66 66 66 78 78 78 78 78 78
  92636. - 78 78 78 74 74 74 66 66 66 54 54 54
  92637. - 42 42 42 26 26 26 18 18 18 10 10 10
  92638. - 6 6 6 0 0 0 0 0 0 0 0 0
  92639. - 0 0 0 0 0 0 0 0 0 0 0 0
  92640. - 0 0 0 0 0 0 0 0 0 0 0 0
  92641. - 0 0 0 0 0 0 0 0 0 0 0 0
  92642. - 0 0 0 0 0 0 0 0 0 0 0 0
  92643. - 0 0 0 0 0 0 0 0 0 0 0 0
  92644. - 0 0 0 0 0 0 0 0 0 0 0 0
  92645. - 0 0 0 0 0 0 0 0 0 0 0 0
  92646. - 0 0 0 0 0 0 0 0 0 0 0 0
  92647. - 0 0 1 0 0 0 0 0 0 0 0 0
  92648. - 0 0 0 0 0 0 0 0 0 0 0 0
  92649. - 0 0 0 0 0 0 0 0 0 0 0 0
  92650. - 0 0 0 0 0 0 0 0 0 0 0 0
  92651. - 0 0 0 0 0 0 0 0 0 0 0 0
  92652. - 0 0 0 0 0 0 0 0 0 0 0 0
  92653. - 0 0 0 0 0 0 0 0 0 10 10 10
  92654. - 22 22 22 42 42 42 66 66 66 86 86 86
  92655. - 66 66 66 38 38 38 38 38 38 22 22 22
  92656. - 26 26 26 34 34 34 54 54 54 66 66 66
  92657. - 86 86 86 70 70 70 46 46 46 26 26 26
  92658. - 14 14 14 6 6 6 0 0 0 0 0 0
  92659. - 0 0 0 0 0 0 0 0 0 0 0 0
  92660. - 0 0 0 0 0 0 0 0 0 0 0 0
  92661. - 0 0 0 0 0 0 0 0 0 0 0 0
  92662. - 0 0 0 0 0 0 0 0 0 0 0 0
  92663. - 0 0 0 0 0 0 0 0 0 0 0 0
  92664. - 0 0 0 0 0 0 0 0 0 0 0 0
  92665. - 0 0 0 0 0 0 0 0 0 0 0 0
  92666. - 0 0 0 0 0 0 0 0 0 0 0 0
  92667. - 0 0 1 0 0 1 0 0 1 0 0 0
  92668. - 0 0 0 0 0 0 0 0 0 0 0 0
  92669. - 0 0 0 0 0 0 0 0 0 0 0 0
  92670. - 0 0 0 0 0 0 0 0 0 0 0 0
  92671. - 0 0 0 0 0 0 0 0 0 0 0 0
  92672. - 0 0 0 0 0 0 0 0 0 0 0 0
  92673. - 0 0 0 0 0 0 10 10 10 26 26 26
  92674. - 50 50 50 82 82 82 58 58 58 6 6 6
  92675. - 2 2 6 2 2 6 2 2 6 2 2 6
  92676. - 2 2 6 2 2 6 2 2 6 2 2 6
  92677. - 6 6 6 54 54 54 86 86 86 66 66 66
  92678. - 38 38 38 18 18 18 6 6 6 0 0 0
  92679. - 0 0 0 0 0 0 0 0 0 0 0 0
  92680. - 0 0 0 0 0 0 0 0 0 0 0 0
  92681. - 0 0 0 0 0 0 0 0 0 0 0 0
  92682. - 0 0 0 0 0 0 0 0 0 0 0 0
  92683. - 0 0 0 0 0 0 0 0 0 0 0 0
  92684. - 0 0 0 0 0 0 0 0 0 0 0 0
  92685. - 0 0 0 0 0 0 0 0 0 0 0 0
  92686. - 0 0 0 0 0 0 0 0 0 0 0 0
  92687. - 0 0 0 0 0 0 0 0 0 0 0 0
  92688. - 0 0 0 0 0 0 0 0 0 0 0 0
  92689. - 0 0 0 0 0 0 0 0 0 0 0 0
  92690. - 0 0 0 0 0 0 0 0 0 0 0 0
  92691. - 0 0 0 0 0 0 0 0 0 0 0 0
  92692. - 0 0 0 0 0 0 0 0 0 0 0 0
  92693. - 0 0 0 6 6 6 22 22 22 50 50 50
  92694. - 78 78 78 34 34 34 2 2 6 2 2 6
  92695. - 2 2 6 2 2 6 2 2 6 2 2 6
  92696. - 2 2 6 2 2 6 2 2 6 2 2 6
  92697. - 2 2 6 2 2 6 6 6 6 70 70 70
  92698. - 78 78 78 46 46 46 22 22 22 6 6 6
  92699. - 0 0 0 0 0 0 0 0 0 0 0 0
  92700. - 0 0 0 0 0 0 0 0 0 0 0 0
  92701. - 0 0 0 0 0 0 0 0 0 0 0 0
  92702. - 0 0 0 0 0 0 0 0 0 0 0 0
  92703. - 0 0 0 0 0 0 0 0 0 0 0 0
  92704. - 0 0 0 0 0 0 0 0 0 0 0 0
  92705. - 0 0 0 0 0 0 0 0 0 0 0 0
  92706. - 0 0 0 0 0 0 0 0 0 0 0 0
  92707. - 0 0 1 0 0 1 0 0 1 0 0 0
  92708. - 0 0 0 0 0 0 0 0 0 0 0 0
  92709. - 0 0 0 0 0 0 0 0 0 0 0 0
  92710. - 0 0 0 0 0 0 0 0 0 0 0 0
  92711. - 0 0 0 0 0 0 0 0 0 0 0 0
  92712. - 0 0 0 0 0 0 0 0 0 0 0 0
  92713. - 6 6 6 18 18 18 42 42 42 82 82 82
  92714. - 26 26 26 2 2 6 2 2 6 2 2 6
  92715. - 2 2 6 2 2 6 2 2 6 2 2 6
  92716. - 2 2 6 2 2 6 2 2 6 14 14 14
  92717. - 46 46 46 34 34 34 6 6 6 2 2 6
  92718. - 42 42 42 78 78 78 42 42 42 18 18 18
  92719. - 6 6 6 0 0 0 0 0 0 0 0 0
  92720. - 0 0 0 0 0 0 0 0 0 0 0 0
  92721. - 0 0 0 0 0 0 0 0 0 0 0 0
  92722. - 0 0 0 0 0 0 0 0 0 0 0 0
  92723. - 0 0 0 0 0 0 0 0 0 0 0 0
  92724. - 0 0 0 0 0 0 0 0 0 0 0 0
  92725. - 0 0 0 0 0 0 0 0 0 0 0 0
  92726. - 0 0 0 0 0 0 0 0 0 0 0 0
  92727. - 0 0 1 0 0 0 0 0 1 0 0 0
  92728. - 0 0 0 0 0 0 0 0 0 0 0 0
  92729. - 0 0 0 0 0 0 0 0 0 0 0 0
  92730. - 0 0 0 0 0 0 0 0 0 0 0 0
  92731. - 0 0 0 0 0 0 0 0 0 0 0 0
  92732. - 0 0 0 0 0 0 0 0 0 0 0 0
  92733. - 10 10 10 30 30 30 66 66 66 58 58 58
  92734. - 2 2 6 2 2 6 2 2 6 2 2 6
  92735. - 2 2 6 2 2 6 2 2 6 2 2 6
  92736. - 2 2 6 2 2 6 2 2 6 26 26 26
  92737. - 86 86 86 101 101 101 46 46 46 10 10 10
  92738. - 2 2 6 58 58 58 70 70 70 34 34 34
  92739. - 10 10 10 0 0 0 0 0 0 0 0 0
  92740. - 0 0 0 0 0 0 0 0 0 0 0 0
  92741. - 0 0 0 0 0 0 0 0 0 0 0 0
  92742. - 0 0 0 0 0 0 0 0 0 0 0 0
  92743. - 0 0 0 0 0 0 0 0 0 0 0 0
  92744. - 0 0 0 0 0 0 0 0 0 0 0 0
  92745. - 0 0 0 0 0 0 0 0 0 0 0 0
  92746. - 0 0 0 0 0 0 0 0 0 0 0 0
  92747. - 0 0 1 0 0 1 0 0 1 0 0 0
  92748. - 0 0 0 0 0 0 0 0 0 0 0 0
  92749. - 0 0 0 0 0 0 0 0 0 0 0 0
  92750. - 0 0 0 0 0 0 0 0 0 0 0 0
  92751. - 0 0 0 0 0 0 0 0 0 0 0 0
  92752. - 0 0 0 0 0 0 0 0 0 0 0 0
  92753. - 14 14 14 42 42 42 86 86 86 10 10 10
  92754. - 2 2 6 2 2 6 2 2 6 2 2 6
  92755. - 2 2 6 2 2 6 2 2 6 2 2 6
  92756. - 2 2 6 2 2 6 2 2 6 30 30 30
  92757. - 94 94 94 94 94 94 58 58 58 26 26 26
  92758. - 2 2 6 6 6 6 78 78 78 54 54 54
  92759. - 22 22 22 6 6 6 0 0 0 0 0 0
  92760. - 0 0 0 0 0 0 0 0 0 0 0 0
  92761. - 0 0 0 0 0 0 0 0 0 0 0 0
  92762. - 0 0 0 0 0 0 0 0 0 0 0 0
  92763. - 0 0 0 0 0 0 0 0 0 0 0 0
  92764. - 0 0 0 0 0 0 0 0 0 0 0 0
  92765. - 0 0 0 0 0 0 0 0 0 0 0 0
  92766. - 0 0 0 0 0 0 0 0 0 0 0 0
  92767. - 0 0 0 0 0 0 0 0 0 0 0 0
  92768. - 0 0 0 0 0 0 0 0 0 0 0 0
  92769. - 0 0 0 0 0 0 0 0 0 0 0 0
  92770. - 0 0 0 0 0 0 0 0 0 0 0 0
  92771. - 0 0 0 0 0 0 0 0 0 0 0 0
  92772. - 0 0 0 0 0 0 0 0 0 6 6 6
  92773. - 22 22 22 62 62 62 62 62 62 2 2 6
  92774. - 2 2 6 2 2 6 2 2 6 2 2 6
  92775. - 2 2 6 2 2 6 2 2 6 2 2 6
  92776. - 2 2 6 2 2 6 2 2 6 26 26 26
  92777. - 54 54 54 38 38 38 18 18 18 10 10 10
  92778. - 2 2 6 2 2 6 34 34 34 82 82 82
  92779. - 38 38 38 14 14 14 0 0 0 0 0 0
  92780. - 0 0 0 0 0 0 0 0 0 0 0 0
  92781. - 0 0 0 0 0 0 0 0 0 0 0 0
  92782. - 0 0 0 0 0 0 0 0 0 0 0 0
  92783. - 0 0 0 0 0 0 0 0 0 0 0 0
  92784. - 0 0 0 0 0 0 0 0 0 0 0 0
  92785. - 0 0 0 0 0 0 0 0 0 0 0 0
  92786. - 0 0 0 0 0 0 0 0 0 0 0 0
  92787. - 0 0 0 0 0 1 0 0 1 0 0 0
  92788. - 0 0 0 0 0 0 0 0 0 0 0 0
  92789. - 0 0 0 0 0 0 0 0 0 0 0 0
  92790. - 0 0 0 0 0 0 0 0 0 0 0 0
  92791. - 0 0 0 0 0 0 0 0 0 0 0 0
  92792. - 0 0 0 0 0 0 0 0 0 6 6 6
  92793. - 30 30 30 78 78 78 30 30 30 2 2 6
  92794. - 2 2 6 2 2 6 2 2 6 2 2 6
  92795. - 2 2 6 2 2 6 2 2 6 2 2 6
  92796. - 2 2 6 2 2 6 2 2 6 10 10 10
  92797. - 10 10 10 2 2 6 2 2 6 2 2 6
  92798. - 2 2 6 2 2 6 2 2 6 78 78 78
  92799. - 50 50 50 18 18 18 6 6 6 0 0 0
  92800. - 0 0 0 0 0 0 0 0 0 0 0 0
  92801. - 0 0 0 0 0 0 0 0 0 0 0 0
  92802. - 0 0 0 0 0 0 0 0 0 0 0 0
  92803. - 0 0 0 0 0 0 0 0 0 0 0 0
  92804. - 0 0 0 0 0 0 0 0 0 0 0 0
  92805. - 0 0 0 0 0 0 0 0 0 0 0 0
  92806. - 0 0 0 0 0 0 0 0 0 0 0 0
  92807. - 0 0 1 0 0 0 0 0 0 0 0 0
  92808. - 0 0 0 0 0 0 0 0 0 0 0 0
  92809. - 0 0 0 0 0 0 0 0 0 0 0 0
  92810. - 0 0 0 0 0 0 0 0 0 0 0 0
  92811. - 0 0 0 0 0 0 0 0 0 0 0 0
  92812. - 0 0 0 0 0 0 0 0 0 10 10 10
  92813. - 38 38 38 86 86 86 14 14 14 2 2 6
  92814. - 2 2 6 2 2 6 2 2 6 2 2 6
  92815. - 2 2 6 2 2 6 2 2 6 2 2 6
  92816. - 2 2 6 2 2 6 2 2 6 2 2 6
  92817. - 2 2 6 2 2 6 2 2 6 2 2 6
  92818. - 2 2 6 2 2 6 2 2 6 54 54 54
  92819. - 66 66 66 26 26 26 6 6 6 0 0 0
  92820. - 0 0 0 0 0 0 0 0 0 0 0 0
  92821. - 0 0 0 0 0 0 0 0 0 0 0 0
  92822. - 0 0 0 0 0 0 0 0 0 0 0 0
  92823. - 0 0 0 0 0 0 0 0 0 0 0 0
  92824. - 0 0 0 0 0 0 0 0 0 0 0 0
  92825. - 0 0 0 0 0 0 0 0 0 0 0 0
  92826. - 0 0 0 0 0 0 0 0 0 0 0 0
  92827. - 0 0 0 0 0 1 0 0 1 0 0 0
  92828. - 0 0 0 0 0 0 0 0 0 0 0 0
  92829. - 0 0 0 0 0 0 0 0 0 0 0 0
  92830. - 0 0 0 0 0 0 0 0 0 0 0 0
  92831. - 0 0 0 0 0 0 0 0 0 0 0 0
  92832. - 0 0 0 0 0 0 0 0 0 14 14 14
  92833. - 42 42 42 82 82 82 2 2 6 2 2 6
  92834. - 2 2 6 6 6 6 10 10 10 2 2 6
  92835. - 2 2 6 2 2 6 2 2 6 2 2 6
  92836. - 2 2 6 2 2 6 2 2 6 6 6 6
  92837. - 14 14 14 10 10 10 2 2 6 2 2 6
  92838. - 2 2 6 2 2 6 2 2 6 18 18 18
  92839. - 82 82 82 34 34 34 10 10 10 0 0 0
  92840. - 0 0 0 0 0 0 0 0 0 0 0 0
  92841. - 0 0 0 0 0 0 0 0 0 0 0 0
  92842. - 0 0 0 0 0 0 0 0 0 0 0 0
  92843. - 0 0 0 0 0 0 0 0 0 0 0 0
  92844. - 0 0 0 0 0 0 0 0 0 0 0 0
  92845. - 0 0 0 0 0 0 0 0 0 0 0 0
  92846. - 0 0 0 0 0 0 0 0 0 0 0 0
  92847. - 0 0 1 0 0 0 0 0 0 0 0 0
  92848. - 0 0 0 0 0 0 0 0 0 0 0 0
  92849. - 0 0 0 0 0 0 0 0 0 0 0 0
  92850. - 0 0 0 0 0 0 0 0 0 0 0 0
  92851. - 0 0 0 0 0 0 0 0 0 0 0 0
  92852. - 0 0 0 0 0 0 0 0 0 14 14 14
  92853. - 46 46 46 86 86 86 2 2 6 2 2 6
  92854. - 6 6 6 6 6 6 22 22 22 34 34 34
  92855. - 6 6 6 2 2 6 2 2 6 2 2 6
  92856. - 2 2 6 2 2 6 18 18 18 34 34 34
  92857. - 10 10 10 50 50 50 22 22 22 2 2 6
  92858. - 2 2 6 2 2 6 2 2 6 10 10 10
  92859. - 86 86 86 42 42 42 14 14 14 0 0 0
  92860. - 0 0 0 0 0 0 0 0 0 0 0 0
  92861. - 0 0 0 0 0 0 0 0 0 0 0 0
  92862. - 0 0 0 0 0 0 0 0 0 0 0 0
  92863. - 0 0 0 0 0 0 0 0 0 0 0 0
  92864. - 0 0 0 0 0 0 0 0 0 0 0 0
  92865. - 0 0 0 0 0 0 0 0 0 0 0 0
  92866. - 0 0 0 0 0 0 0 0 0 0 0 0
  92867. - 0 0 1 0 0 1 0 0 1 0 0 0
  92868. - 0 0 0 0 0 0 0 0 0 0 0 0
  92869. - 0 0 0 0 0 0 0 0 0 0 0 0
  92870. - 0 0 0 0 0 0 0 0 0 0 0 0
  92871. - 0 0 0 0 0 0 0 0 0 0 0 0
  92872. - 0 0 0 0 0 0 0 0 0 14 14 14
  92873. - 46 46 46 86 86 86 2 2 6 2 2 6
  92874. - 38 38 38 116 116 116 94 94 94 22 22 22
  92875. - 22 22 22 2 2 6 2 2 6 2 2 6
  92876. - 14 14 14 86 86 86 138 138 138 162 162 162
  92877. -154 154 154 38 38 38 26 26 26 6 6 6
  92878. - 2 2 6 2 2 6 2 2 6 2 2 6
  92879. - 86 86 86 46 46 46 14 14 14 0 0 0
  92880. - 0 0 0 0 0 0 0 0 0 0 0 0
  92881. - 0 0 0 0 0 0 0 0 0 0 0 0
  92882. - 0 0 0 0 0 0 0 0 0 0 0 0
  92883. - 0 0 0 0 0 0 0 0 0 0 0 0
  92884. - 0 0 0 0 0 0 0 0 0 0 0 0
  92885. - 0 0 0 0 0 0 0 0 0 0 0 0
  92886. - 0 0 0 0 0 0 0 0 0 0 0 0
  92887. - 0 0 0 0 0 0 0 0 0 0 0 0
  92888. - 0 0 0 0 0 0 0 0 0 0 0 0
  92889. - 0 0 0 0 0 0 0 0 0 0 0 0
  92890. - 0 0 0 0 0 0 0 0 0 0 0 0
  92891. - 0 0 0 0 0 0 0 0 0 0 0 0
  92892. - 0 0 0 0 0 0 0 0 0 14 14 14
  92893. - 46 46 46 86 86 86 2 2 6 14 14 14
  92894. -134 134 134 198 198 198 195 195 195 116 116 116
  92895. - 10 10 10 2 2 6 2 2 6 6 6 6
  92896. -101 98 89 187 187 187 210 210 210 218 218 218
  92897. -214 214 214 134 134 134 14 14 14 6 6 6
  92898. - 2 2 6 2 2 6 2 2 6 2 2 6
  92899. - 86 86 86 50 50 50 18 18 18 6 6 6
  92900. - 0 0 0 0 0 0 0 0 0 0 0 0
  92901. - 0 0 0 0 0 0 0 0 0 0 0 0
  92902. - 0 0 0 0 0 0 0 0 0 0 0 0
  92903. - 0 0 0 0 0 0 0 0 0 0 0 0
  92904. - 0 0 0 0 0 0 0 0 0 0 0 0
  92905. - 0 0 0 0 0 0 0 0 0 0 0 0
  92906. - 0 0 0 0 0 0 0 0 1 0 0 0
  92907. - 0 0 1 0 0 1 0 0 1 0 0 0
  92908. - 0 0 0 0 0 0 0 0 0 0 0 0
  92909. - 0 0 0 0 0 0 0 0 0 0 0 0
  92910. - 0 0 0 0 0 0 0 0 0 0 0 0
  92911. - 0 0 0 0 0 0 0 0 0 0 0 0
  92912. - 0 0 0 0 0 0 0 0 0 14 14 14
  92913. - 46 46 46 86 86 86 2 2 6 54 54 54
  92914. -218 218 218 195 195 195 226 226 226 246 246 246
  92915. - 58 58 58 2 2 6 2 2 6 30 30 30
  92916. -210 210 210 253 253 253 174 174 174 123 123 123
  92917. -221 221 221 234 234 234 74 74 74 2 2 6
  92918. - 2 2 6 2 2 6 2 2 6 2 2 6
  92919. - 70 70 70 58 58 58 22 22 22 6 6 6
  92920. - 0 0 0 0 0 0 0 0 0 0 0 0
  92921. - 0 0 0 0 0 0 0 0 0 0 0 0
  92922. - 0 0 0 0 0 0 0 0 0 0 0 0
  92923. - 0 0 0 0 0 0 0 0 0 0 0 0
  92924. - 0 0 0 0 0 0 0 0 0 0 0 0
  92925. - 0 0 0 0 0 0 0 0 0 0 0 0
  92926. - 0 0 0 0 0 0 0 0 0 0 0 0
  92927. - 0 0 0 0 0 0 0 0 0 0 0 0
  92928. - 0 0 0 0 0 0 0 0 0 0 0 0
  92929. - 0 0 0 0 0 0 0 0 0 0 0 0
  92930. - 0 0 0 0 0 0 0 0 0 0 0 0
  92931. - 0 0 0 0 0 0 0 0 0 0 0 0
  92932. - 0 0 0 0 0 0 0 0 0 14 14 14
  92933. - 46 46 46 82 82 82 2 2 6 106 106 106
  92934. -170 170 170 26 26 26 86 86 86 226 226 226
  92935. -123 123 123 10 10 10 14 14 14 46 46 46
  92936. -231 231 231 190 190 190 6 6 6 70 70 70
  92937. - 90 90 90 238 238 238 158 158 158 2 2 6
  92938. - 2 2 6 2 2 6 2 2 6 2 2 6
  92939. - 70 70 70 58 58 58 22 22 22 6 6 6
  92940. - 0 0 0 0 0 0 0 0 0 0 0 0
  92941. - 0 0 0 0 0 0 0 0 0 0 0 0
  92942. - 0 0 0 0 0 0 0 0 0 0 0 0
  92943. - 0 0 0 0 0 0 0 0 0 0 0 0
  92944. - 0 0 0 0 0 0 0 0 0 0 0 0
  92945. - 0 0 0 0 0 0 0 0 0 0 0 0
  92946. - 0 0 0 0 0 0 0 0 1 0 0 0
  92947. - 0 0 1 0 0 1 0 0 1 0 0 0
  92948. - 0 0 0 0 0 0 0 0 0 0 0 0
  92949. - 0 0 0 0 0 0 0 0 0 0 0 0
  92950. - 0 0 0 0 0 0 0 0 0 0 0 0
  92951. - 0 0 0 0 0 0 0 0 0 0 0 0
  92952. - 0 0 0 0 0 0 0 0 0 14 14 14
  92953. - 42 42 42 86 86 86 6 6 6 116 116 116
  92954. -106 106 106 6 6 6 70 70 70 149 149 149
  92955. -128 128 128 18 18 18 38 38 38 54 54 54
  92956. -221 221 221 106 106 106 2 2 6 14 14 14
  92957. - 46 46 46 190 190 190 198 198 198 2 2 6
  92958. - 2 2 6 2 2 6 2 2 6 2 2 6
  92959. - 74 74 74 62 62 62 22 22 22 6 6 6
  92960. - 0 0 0 0 0 0 0 0 0 0 0 0
  92961. - 0 0 0 0 0 0 0 0 0 0 0 0
  92962. - 0 0 0 0 0 0 0 0 0 0 0 0
  92963. - 0 0 0 0 0 0 0 0 0 0 0 0
  92964. - 0 0 0 0 0 0 0 0 0 0 0 0
  92965. - 0 0 0 0 0 0 0 0 0 0 0 0
  92966. - 0 0 0 0 0 0 0 0 1 0 0 0
  92967. - 0 0 1 0 0 0 0 0 1 0 0 0
  92968. - 0 0 0 0 0 0 0 0 0 0 0 0
  92969. - 0 0 0 0 0 0 0 0 0 0 0 0
  92970. - 0 0 0 0 0 0 0 0 0 0 0 0
  92971. - 0 0 0 0 0 0 0 0 0 0 0 0
  92972. - 0 0 0 0 0 0 0 0 0 14 14 14
  92973. - 42 42 42 94 94 94 14 14 14 101 101 101
  92974. -128 128 128 2 2 6 18 18 18 116 116 116
  92975. -118 98 46 121 92 8 121 92 8 98 78 10
  92976. -162 162 162 106 106 106 2 2 6 2 2 6
  92977. - 2 2 6 195 195 195 195 195 195 6 6 6
  92978. - 2 2 6 2 2 6 2 2 6 2 2 6
  92979. - 74 74 74 62 62 62 22 22 22 6 6 6
  92980. - 0 0 0 0 0 0 0 0 0 0 0 0
  92981. - 0 0 0 0 0 0 0 0 0 0 0 0
  92982. - 0 0 0 0 0 0 0 0 0 0 0 0
  92983. - 0 0 0 0 0 0 0 0 0 0 0 0
  92984. - 0 0 0 0 0 0 0 0 0 0 0 0
  92985. - 0 0 0 0 0 0 0 0 0 0 0 0
  92986. - 0 0 0 0 0 0 0 0 1 0 0 1
  92987. - 0 0 1 0 0 0 0 0 1 0 0 0
  92988. - 0 0 0 0 0 0 0 0 0 0 0 0
  92989. - 0 0 0 0 0 0 0 0 0 0 0 0
  92990. - 0 0 0 0 0 0 0 0 0 0 0 0
  92991. - 0 0 0 0 0 0 0 0 0 0 0 0
  92992. - 0 0 0 0 0 0 0 0 0 10 10 10
  92993. - 38 38 38 90 90 90 14 14 14 58 58 58
  92994. -210 210 210 26 26 26 54 38 6 154 114 10
  92995. -226 170 11 236 186 11 225 175 15 184 144 12
  92996. -215 174 15 175 146 61 37 26 9 2 2 6
  92997. - 70 70 70 246 246 246 138 138 138 2 2 6
  92998. - 2 2 6 2 2 6 2 2 6 2 2 6
  92999. - 70 70 70 66 66 66 26 26 26 6 6 6
  93000. - 0 0 0 0 0 0 0 0 0 0 0 0
  93001. - 0 0 0 0 0 0 0 0 0 0 0 0
  93002. - 0 0 0 0 0 0 0 0 0 0 0 0
  93003. - 0 0 0 0 0 0 0 0 0 0 0 0
  93004. - 0 0 0 0 0 0 0 0 0 0 0 0
  93005. - 0 0 0 0 0 0 0 0 0 0 0 0
  93006. - 0 0 0 0 0 0 0 0 0 0 0 0
  93007. - 0 0 0 0 0 0 0 0 0 0 0 0
  93008. - 0 0 0 0 0 0 0 0 0 0 0 0
  93009. - 0 0 0 0 0 0 0 0 0 0 0 0
  93010. - 0 0 0 0 0 0 0 0 0 0 0 0
  93011. - 0 0 0 0 0 0 0 0 0 0 0 0
  93012. - 0 0 0 0 0 0 0 0 0 10 10 10
  93013. - 38 38 38 86 86 86 14 14 14 10 10 10
  93014. -195 195 195 188 164 115 192 133 9 225 175 15
  93015. -239 182 13 234 190 10 232 195 16 232 200 30
  93016. -245 207 45 241 208 19 232 195 16 184 144 12
  93017. -218 194 134 211 206 186 42 42 42 2 2 6
  93018. - 2 2 6 2 2 6 2 2 6 2 2 6
  93019. - 50 50 50 74 74 74 30 30 30 6 6 6
  93020. - 0 0 0 0 0 0 0 0 0 0 0 0
  93021. - 0 0 0 0 0 0 0 0 0 0 0 0
  93022. - 0 0 0 0 0 0 0 0 0 0 0 0
  93023. - 0 0 0 0 0 0 0 0 0 0 0 0
  93024. - 0 0 0 0 0 0 0 0 0 0 0 0
  93025. - 0 0 0 0 0 0 0 0 0 0 0 0
  93026. - 0 0 0 0 0 0 0 0 0 0 0 0
  93027. - 0 0 0 0 0 0 0 0 0 0 0 0
  93028. - 0 0 0 0 0 0 0 0 0 0 0 0
  93029. - 0 0 0 0 0 0 0 0 0 0 0 0
  93030. - 0 0 0 0 0 0 0 0 0 0 0 0
  93031. - 0 0 0 0 0 0 0 0 0 0 0 0
  93032. - 0 0 0 0 0 0 0 0 0 10 10 10
  93033. - 34 34 34 86 86 86 14 14 14 2 2 6
  93034. -121 87 25 192 133 9 219 162 10 239 182 13
  93035. -236 186 11 232 195 16 241 208 19 244 214 54
  93036. -246 218 60 246 218 38 246 215 20 241 208 19
  93037. -241 208 19 226 184 13 121 87 25 2 2 6
  93038. - 2 2 6 2 2 6 2 2 6 2 2 6
  93039. - 50 50 50 82 82 82 34 34 34 10 10 10
  93040. - 0 0 0 0 0 0 0 0 0 0 0 0
  93041. - 0 0 0 0 0 0 0 0 0 0 0 0
  93042. - 0 0 0 0 0 0 0 0 0 0 0 0
  93043. - 0 0 0 0 0 0 0 0 0 0 0 0
  93044. - 0 0 0 0 0 0 0 0 0 0 0 0
  93045. - 0 0 0 0 0 0 0 0 0 0 0 0
  93046. - 0 0 0 0 0 0 0 0 0 0 0 0
  93047. - 0 0 0 0 0 0 0 0 0 0 0 0
  93048. - 0 0 0 0 0 0 0 0 0 0 0 0
  93049. - 0 0 0 0 0 0 0 0 0 0 0 0
  93050. - 0 0 0 0 0 0 0 0 0 0 0 0
  93051. - 0 0 0 0 0 0 0 0 0 0 0 0
  93052. - 0 0 0 0 0 0 0 0 0 10 10 10
  93053. - 34 34 34 82 82 82 30 30 30 61 42 6
  93054. -180 123 7 206 145 10 230 174 11 239 182 13
  93055. -234 190 10 238 202 15 241 208 19 246 218 74
  93056. -246 218 38 246 215 20 246 215 20 246 215 20
  93057. -226 184 13 215 174 15 184 144 12 6 6 6
  93058. - 2 2 6 2 2 6 2 2 6 2 2 6
  93059. - 26 26 26 94 94 94 42 42 42 14 14 14
  93060. - 0 0 0 0 0 0 0 0 0 0 0 0
  93061. - 0 0 0 0 0 0 0 0 0 0 0 0
  93062. - 0 0 0 0 0 0 0 0 0 0 0 0
  93063. - 0 0 0 0 0 0 0 0 0 0 0 0
  93064. - 0 0 0 0 0 0 0 0 0 0 0 0
  93065. - 0 0 0 0 0 0 0 0 0 0 0 0
  93066. - 0 0 0 0 0 0 0 0 0 0 0 0
  93067. - 0 0 0 0 0 0 0 0 0 0 0 0
  93068. - 0 0 0 0 0 0 0 0 0 0 0 0
  93069. - 0 0 0 0 0 0 0 0 0 0 0 0
  93070. - 0 0 0 0 0 0 0 0 0 0 0 0
  93071. - 0 0 0 0 0 0 0 0 0 0 0 0
  93072. - 0 0 0 0 0 0 0 0 0 10 10 10
  93073. - 30 30 30 78 78 78 50 50 50 104 69 6
  93074. -192 133 9 216 158 10 236 178 12 236 186 11
  93075. -232 195 16 241 208 19 244 214 54 245 215 43
  93076. -246 215 20 246 215 20 241 208 19 198 155 10
  93077. -200 144 11 216 158 10 156 118 10 2 2 6
  93078. - 2 2 6 2 2 6 2 2 6 2 2 6
  93079. - 6 6 6 90 90 90 54 54 54 18 18 18
  93080. - 6 6 6 0 0 0 0 0 0 0 0 0
  93081. - 0 0 0 0 0 0 0 0 0 0 0 0
  93082. - 0 0 0 0 0 0 0 0 0 0 0 0
  93083. - 0 0 0 0 0 0 0 0 0 0 0 0
  93084. - 0 0 0 0 0 0 0 0 0 0 0 0
  93085. - 0 0 0 0 0 0 0 0 0 0 0 0
  93086. - 0 0 0 0 0 0 0 0 0 0 0 0
  93087. - 0 0 0 0 0 0 0 0 0 0 0 0
  93088. - 0 0 0 0 0 0 0 0 0 0 0 0
  93089. - 0 0 0 0 0 0 0 0 0 0 0 0
  93090. - 0 0 0 0 0 0 0 0 0 0 0 0
  93091. - 0 0 0 0 0 0 0 0 0 0 0 0
  93092. - 0 0 0 0 0 0 0 0 0 10 10 10
  93093. - 30 30 30 78 78 78 46 46 46 22 22 22
  93094. -137 92 6 210 162 10 239 182 13 238 190 10
  93095. -238 202 15 241 208 19 246 215 20 246 215 20
  93096. -241 208 19 203 166 17 185 133 11 210 150 10
  93097. -216 158 10 210 150 10 102 78 10 2 2 6
  93098. - 6 6 6 54 54 54 14 14 14 2 2 6
  93099. - 2 2 6 62 62 62 74 74 74 30 30 30
  93100. - 10 10 10 0 0 0 0 0 0 0 0 0
  93101. - 0 0 0 0 0 0 0 0 0 0 0 0
  93102. - 0 0 0 0 0 0 0 0 0 0 0 0
  93103. - 0 0 0 0 0 0 0 0 0 0 0 0
  93104. - 0 0 0 0 0 0 0 0 0 0 0 0
  93105. - 0 0 0 0 0 0 0 0 0 0 0 0
  93106. - 0 0 0 0 0 0 0 0 0 0 0 0
  93107. - 0 0 0 0 0 0 0 0 0 0 0 0
  93108. - 0 0 0 0 0 0 0 0 0 0 0 0
  93109. - 0 0 0 0 0 0 0 0 0 0 0 0
  93110. - 0 0 0 0 0 0 0 0 0 0 0 0
  93111. - 0 0 0 0 0 0 0 0 0 0 0 0
  93112. - 0 0 0 0 0 0 0 0 0 10 10 10
  93113. - 34 34 34 78 78 78 50 50 50 6 6 6
  93114. - 94 70 30 139 102 15 190 146 13 226 184 13
  93115. -232 200 30 232 195 16 215 174 15 190 146 13
  93116. -168 122 10 192 133 9 210 150 10 213 154 11
  93117. -202 150 34 182 157 106 101 98 89 2 2 6
  93118. - 2 2 6 78 78 78 116 116 116 58 58 58
  93119. - 2 2 6 22 22 22 90 90 90 46 46 46
  93120. - 18 18 18 6 6 6 0 0 0 0 0 0
  93121. - 0 0 0 0 0 0 0 0 0 0 0 0
  93122. - 0 0 0 0 0 0 0 0 0 0 0 0
  93123. - 0 0 0 0 0 0 0 0 0 0 0 0
  93124. - 0 0 0 0 0 0 0 0 0 0 0 0
  93125. - 0 0 0 0 0 0 0 0 0 0 0 0
  93126. - 0 0 0 0 0 0 0 0 0 0 0 0
  93127. - 0 0 0 0 0 0 0 0 0 0 0 0
  93128. - 0 0 0 0 0 0 0 0 0 0 0 0
  93129. - 0 0 0 0 0 0 0 0 0 0 0 0
  93130. - 0 0 0 0 0 0 0 0 0 0 0 0
  93131. - 0 0 0 0 0 0 0 0 0 0 0 0
  93132. - 0 0 0 0 0 0 0 0 0 10 10 10
  93133. - 38 38 38 86 86 86 50 50 50 6 6 6
  93134. -128 128 128 174 154 114 156 107 11 168 122 10
  93135. -198 155 10 184 144 12 197 138 11 200 144 11
  93136. -206 145 10 206 145 10 197 138 11 188 164 115
  93137. -195 195 195 198 198 198 174 174 174 14 14 14
  93138. - 2 2 6 22 22 22 116 116 116 116 116 116
  93139. - 22 22 22 2 2 6 74 74 74 70 70 70
  93140. - 30 30 30 10 10 10 0 0 0 0 0 0
  93141. - 0 0 0 0 0 0 0 0 0 0 0 0
  93142. - 0 0 0 0 0 0 0 0 0 0 0 0
  93143. - 0 0 0 0 0 0 0 0 0 0 0 0
  93144. - 0 0 0 0 0 0 0 0 0 0 0 0
  93145. - 0 0 0 0 0 0 0 0 0 0 0 0
  93146. - 0 0 0 0 0 0 0 0 0 0 0 0
  93147. - 0 0 0 0 0 0 0 0 0 0 0 0
  93148. - 0 0 0 0 0 0 0 0 0 0 0 0
  93149. - 0 0 0 0 0 0 0 0 0 0 0 0
  93150. - 0 0 0 0 0 0 0 0 0 0 0 0
  93151. - 0 0 0 0 0 0 0 0 0 0 0 0
  93152. - 0 0 0 0 0 0 6 6 6 18 18 18
  93153. - 50 50 50 101 101 101 26 26 26 10 10 10
  93154. -138 138 138 190 190 190 174 154 114 156 107 11
  93155. -197 138 11 200 144 11 197 138 11 192 133 9
  93156. -180 123 7 190 142 34 190 178 144 187 187 187
  93157. -202 202 202 221 221 221 214 214 214 66 66 66
  93158. - 2 2 6 2 2 6 50 50 50 62 62 62
  93159. - 6 6 6 2 2 6 10 10 10 90 90 90
  93160. - 50 50 50 18 18 18 6 6 6 0 0 0
  93161. - 0 0 0 0 0 0 0 0 0 0 0 0
  93162. - 0 0 0 0 0 0 0 0 0 0 0 0
  93163. - 0 0 0 0 0 0 0 0 0 0 0 0
  93164. - 0 0 0 0 0 0 0 0 0 0 0 0
  93165. - 0 0 0 0 0 0 0 0 0 0 0 0
  93166. - 0 0 0 0 0 0 0 0 0 0 0 0
  93167. - 0 0 0 0 0 0 0 0 0 0 0 0
  93168. - 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
  93170. - 0 0 0 0 0 0 0 0 0 0 0 0
  93171. - 0 0 0 0 0 0 0 0 0 0 0 0
  93172. - 0 0 0 0 0 0 10 10 10 34 34 34
  93173. - 74 74 74 74 74 74 2 2 6 6 6 6
  93174. -144 144 144 198 198 198 190 190 190 178 166 146
  93175. -154 121 60 156 107 11 156 107 11 168 124 44
  93176. -174 154 114 187 187 187 190 190 190 210 210 210
  93177. -246 246 246 253 253 253 253 253 253 182 182 182
  93178. - 6 6 6 2 2 6 2 2 6 2 2 6
  93179. - 2 2 6 2 2 6 2 2 6 62 62 62
  93180. - 74 74 74 34 34 34 14 14 14 0 0 0
  93181. - 0 0 0 0 0 0 0 0 0 0 0 0
  93182. - 0 0 0 0 0 0 0 0 0 0 0 0
  93183. - 0 0 0 0 0 0 0 0 0 0 0 0
  93184. - 0 0 0 0 0 0 0 0 0 0 0 0
  93185. - 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
  93187. - 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
  93189. - 0 0 0 0 0 0 0 0 0 0 0 0
  93190. - 0 0 0 0 0 0 0 0 0 0 0 0
  93191. - 0 0 0 0 0 0 0 0 0 0 0 0
  93192. - 0 0 0 10 10 10 22 22 22 54 54 54
  93193. - 94 94 94 18 18 18 2 2 6 46 46 46
  93194. -234 234 234 221 221 221 190 190 190 190 190 190
  93195. -190 190 190 187 187 187 187 187 187 190 190 190
  93196. -190 190 190 195 195 195 214 214 214 242 242 242
  93197. -253 253 253 253 253 253 253 253 253 253 253 253
  93198. - 82 82 82 2 2 6 2 2 6 2 2 6
  93199. - 2 2 6 2 2 6 2 2 6 14 14 14
  93200. - 86 86 86 54 54 54 22 22 22 6 6 6
  93201. - 0 0 0 0 0 0 0 0 0 0 0 0
  93202. - 0 0 0 0 0 0 0 0 0 0 0 0
  93203. - 0 0 0 0 0 0 0 0 0 0 0 0
  93204. - 0 0 0 0 0 0 0 0 0 0 0 0
  93205. - 0 0 0 0 0 0 0 0 0 0 0 0
  93206. - 0 0 0 0 0 0 0 0 0 0 0 0
  93207. - 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
  93209. - 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
  93211. - 0 0 0 0 0 0 0 0 0 0 0 0
  93212. - 6 6 6 18 18 18 46 46 46 90 90 90
  93213. - 46 46 46 18 18 18 6 6 6 182 182 182
  93214. -253 253 253 246 246 246 206 206 206 190 190 190
  93215. -190 190 190 190 190 190 190 190 190 190 190 190
  93216. -206 206 206 231 231 231 250 250 250 253 253 253
  93217. -253 253 253 253 253 253 253 253 253 253 253 253
  93218. -202 202 202 14 14 14 2 2 6 2 2 6
  93219. - 2 2 6 2 2 6 2 2 6 2 2 6
  93220. - 42 42 42 86 86 86 42 42 42 18 18 18
  93221. - 6 6 6 0 0 0 0 0 0 0 0 0
  93222. - 0 0 0 0 0 0 0 0 0 0 0 0
  93223. - 0 0 0 0 0 0 0 0 0 0 0 0
  93224. - 0 0 0 0 0 0 0 0 0 0 0 0
  93225. - 0 0 0 0 0 0 0 0 0 0 0 0
  93226. - 0 0 0 0 0 0 0 0 0 0 0 0
  93227. - 0 0 0 0 0 0 0 0 0 0 0 0
  93228. - 0 0 0 0 0 0 0 0 0 0 0 0
  93229. - 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
  93231. - 0 0 0 0 0 0 0 0 0 6 6 6
  93232. - 14 14 14 38 38 38 74 74 74 66 66 66
  93233. - 2 2 6 6 6 6 90 90 90 250 250 250
  93234. -253 253 253 253 253 253 238 238 238 198 198 198
  93235. -190 190 190 190 190 190 195 195 195 221 221 221
  93236. -246 246 246 253 253 253 253 253 253 253 253 253
  93237. -253 253 253 253 253 253 253 253 253 253 253 253
  93238. -253 253 253 82 82 82 2 2 6 2 2 6
  93239. - 2 2 6 2 2 6 2 2 6 2 2 6
  93240. - 2 2 6 78 78 78 70 70 70 34 34 34
  93241. - 14 14 14 6 6 6 0 0 0 0 0 0
  93242. - 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
  93244. - 0 0 0 0 0 0 0 0 0 0 0 0
  93245. - 0 0 0 0 0 0 0 0 0 0 0 0
  93246. - 0 0 0 0 0 0 0 0 0 0 0 0
  93247. - 0 0 0 0 0 0 0 0 0 0 0 0
  93248. - 0 0 0 0 0 0 0 0 0 0 0 0
  93249. - 0 0 0 0 0 0 0 0 0 0 0 0
  93250. - 0 0 0 0 0 0 0 0 0 0 0 0
  93251. - 0 0 0 0 0 0 0 0 0 14 14 14
  93252. - 34 34 34 66 66 66 78 78 78 6 6 6
  93253. - 2 2 6 18 18 18 218 218 218 253 253 253
  93254. -253 253 253 253 253 253 253 253 253 246 246 246
  93255. -226 226 226 231 231 231 246 246 246 253 253 253
  93256. -253 253 253 253 253 253 253 253 253 253 253 253
  93257. -253 253 253 253 253 253 253 253 253 253 253 253
  93258. -253 253 253 178 178 178 2 2 6 2 2 6
  93259. - 2 2 6 2 2 6 2 2 6 2 2 6
  93260. - 2 2 6 18 18 18 90 90 90 62 62 62
  93261. - 30 30 30 10 10 10 0 0 0 0 0 0
  93262. - 0 0 0 0 0 0 0 0 0 0 0 0
  93263. - 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
  93265. - 0 0 0 0 0 0 0 0 0 0 0 0
  93266. - 0 0 0 0 0 0 0 0 0 0 0 0
  93267. - 0 0 0 0 0 0 0 0 0 0 0 0
  93268. - 0 0 0 0 0 0 0 0 0 0 0 0
  93269. - 0 0 0 0 0 0 0 0 0 0 0 0
  93270. - 0 0 0 0 0 0 0 0 0 0 0 0
  93271. - 0 0 0 0 0 0 10 10 10 26 26 26
  93272. - 58 58 58 90 90 90 18 18 18 2 2 6
  93273. - 2 2 6 110 110 110 253 253 253 253 253 253
  93274. -253 253 253 253 253 253 253 253 253 253 253 253
  93275. -250 250 250 253 253 253 253 253 253 253 253 253
  93276. -253 253 253 253 253 253 253 253 253 253 253 253
  93277. -253 253 253 253 253 253 253 253 253 253 253 253
  93278. -253 253 253 231 231 231 18 18 18 2 2 6
  93279. - 2 2 6 2 2 6 2 2 6 2 2 6
  93280. - 2 2 6 2 2 6 18 18 18 94 94 94
  93281. - 54 54 54 26 26 26 10 10 10 0 0 0
  93282. - 0 0 0 0 0 0 0 0 0 0 0 0
  93283. - 0 0 0 0 0 0 0 0 0 0 0 0
  93284. - 0 0 0 0 0 0 0 0 0 0 0 0
  93285. - 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
  93287. - 0 0 0 0 0 0 0 0 0 0 0 0
  93288. - 0 0 0 0 0 0 0 0 0 0 0 0
  93289. - 0 0 0 0 0 0 0 0 0 0 0 0
  93290. - 0 0 0 0 0 0 0 0 0 0 0 0
  93291. - 0 0 0 6 6 6 22 22 22 50 50 50
  93292. - 90 90 90 26 26 26 2 2 6 2 2 6
  93293. - 14 14 14 195 195 195 250 250 250 253 253 253
  93294. -253 253 253 253 253 253 253 253 253 253 253 253
  93295. -253 253 253 253 253 253 253 253 253 253 253 253
  93296. -253 253 253 253 253 253 253 253 253 253 253 253
  93297. -253 253 253 253 253 253 253 253 253 253 253 253
  93298. -250 250 250 242 242 242 54 54 54 2 2 6
  93299. - 2 2 6 2 2 6 2 2 6 2 2 6
  93300. - 2 2 6 2 2 6 2 2 6 38 38 38
  93301. - 86 86 86 50 50 50 22 22 22 6 6 6
  93302. - 0 0 0 0 0 0 0 0 0 0 0 0
  93303. - 0 0 0 0 0 0 0 0 0 0 0 0
  93304. - 0 0 0 0 0 0 0 0 0 0 0 0
  93305. - 0 0 0 0 0 0 0 0 0 0 0 0
  93306. - 0 0 0 0 0 0 0 0 0 0 0 0
  93307. - 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
  93309. - 0 0 0 0 0 0 0 0 0 0 0 0
  93310. - 0 0 0 0 0 0 0 0 0 0 0 0
  93311. - 6 6 6 14 14 14 38 38 38 82 82 82
  93312. - 34 34 34 2 2 6 2 2 6 2 2 6
  93313. - 42 42 42 195 195 195 246 246 246 253 253 253
  93314. -253 253 253 253 253 253 253 253 253 250 250 250
  93315. -242 242 242 242 242 242 250 250 250 253 253 253
  93316. -253 253 253 253 253 253 253 253 253 253 253 253
  93317. -253 253 253 250 250 250 246 246 246 238 238 238
  93318. -226 226 226 231 231 231 101 101 101 6 6 6
  93319. - 2 2 6 2 2 6 2 2 6 2 2 6
  93320. - 2 2 6 2 2 6 2 2 6 2 2 6
  93321. - 38 38 38 82 82 82 42 42 42 14 14 14
  93322. - 6 6 6 0 0 0 0 0 0 0 0 0
  93323. - 0 0 0 0 0 0 0 0 0 0 0 0
  93324. - 0 0 0 0 0 0 0 0 0 0 0 0
  93325. - 0 0 0 0 0 0 0 0 0 0 0 0
  93326. - 0 0 0 0 0 0 0 0 0 0 0 0
  93327. - 0 0 0 0 0 0 0 0 0 0 0 0
  93328. - 0 0 0 0 0 0 0 0 0 0 0 0
  93329. - 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
  93331. - 10 10 10 26 26 26 62 62 62 66 66 66
  93332. - 2 2 6 2 2 6 2 2 6 6 6 6
  93333. - 70 70 70 170 170 170 206 206 206 234 234 234
  93334. -246 246 246 250 250 250 250 250 250 238 238 238
  93335. -226 226 226 231 231 231 238 238 238 250 250 250
  93336. -250 250 250 250 250 250 246 246 246 231 231 231
  93337. -214 214 214 206 206 206 202 202 202 202 202 202
  93338. -198 198 198 202 202 202 182 182 182 18 18 18
  93339. - 2 2 6 2 2 6 2 2 6 2 2 6
  93340. - 2 2 6 2 2 6 2 2 6 2 2 6
  93341. - 2 2 6 62 62 62 66 66 66 30 30 30
  93342. - 10 10 10 0 0 0 0 0 0 0 0 0
  93343. - 0 0 0 0 0 0 0 0 0 0 0 0
  93344. - 0 0 0 0 0 0 0 0 0 0 0 0
  93345. - 0 0 0 0 0 0 0 0 0 0 0 0
  93346. - 0 0 0 0 0 0 0 0 0 0 0 0
  93347. - 0 0 0 0 0 0 0 0 0 0 0 0
  93348. - 0 0 0 0 0 0 0 0 0 0 0 0
  93349. - 0 0 0 0 0 0 0 0 0 0 0 0
  93350. - 0 0 0 0 0 0 0 0 0 0 0 0
  93351. - 14 14 14 42 42 42 82 82 82 18 18 18
  93352. - 2 2 6 2 2 6 2 2 6 10 10 10
  93353. - 94 94 94 182 182 182 218 218 218 242 242 242
  93354. -250 250 250 253 253 253 253 253 253 250 250 250
  93355. -234 234 234 253 253 253 253 253 253 253 253 253
  93356. -253 253 253 253 253 253 253 253 253 246 246 246
  93357. -238 238 238 226 226 226 210 210 210 202 202 202
  93358. -195 195 195 195 195 195 210 210 210 158 158 158
  93359. - 6 6 6 14 14 14 50 50 50 14 14 14
  93360. - 2 2 6 2 2 6 2 2 6 2 2 6
  93361. - 2 2 6 6 6 6 86 86 86 46 46 46
  93362. - 18 18 18 6 6 6 0 0 0 0 0 0
  93363. - 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
  93365. - 0 0 0 0 0 0 0 0 0 0 0 0
  93366. - 0 0 0 0 0 0 0 0 0 0 0 0
  93367. - 0 0 0 0 0 0 0 0 0 0 0 0
  93368. - 0 0 0 0 0 0 0 0 0 0 0 0
  93369. - 0 0 0 0 0 0 0 0 0 0 0 0
  93370. - 0 0 0 0 0 0 0 0 0 6 6 6
  93371. - 22 22 22 54 54 54 70 70 70 2 2 6
  93372. - 2 2 6 10 10 10 2 2 6 22 22 22
  93373. -166 166 166 231 231 231 250 250 250 253 253 253
  93374. -253 253 253 253 253 253 253 253 253 250 250 250
  93375. -242 242 242 253 253 253 253 253 253 253 253 253
  93376. -253 253 253 253 253 253 253 253 253 253 253 253
  93377. -253 253 253 253 253 253 253 253 253 246 246 246
  93378. -231 231 231 206 206 206 198 198 198 226 226 226
  93379. - 94 94 94 2 2 6 6 6 6 38 38 38
  93380. - 30 30 30 2 2 6 2 2 6 2 2 6
  93381. - 2 2 6 2 2 6 62 62 62 66 66 66
  93382. - 26 26 26 10 10 10 0 0 0 0 0 0
  93383. - 0 0 0 0 0 0 0 0 0 0 0 0
  93384. - 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
  93386. - 0 0 0 0 0 0 0 0 0 0 0 0
  93387. - 0 0 0 0 0 0 0 0 0 0 0 0
  93388. - 0 0 0 0 0 0 0 0 0 0 0 0
  93389. - 0 0 0 0 0 0 0 0 0 0 0 0
  93390. - 0 0 0 0 0 0 0 0 0 10 10 10
  93391. - 30 30 30 74 74 74 50 50 50 2 2 6
  93392. - 26 26 26 26 26 26 2 2 6 106 106 106
  93393. -238 238 238 253 253 253 253 253 253 253 253 253
  93394. -253 253 253 253 253 253 253 253 253 253 253 253
  93395. -253 253 253 253 253 253 253 253 253 253 253 253
  93396. -253 253 253 253 253 253 253 253 253 253 253 253
  93397. -253 253 253 253 253 253 253 253 253 253 253 253
  93398. -253 253 253 246 246 246 218 218 218 202 202 202
  93399. -210 210 210 14 14 14 2 2 6 2 2 6
  93400. - 30 30 30 22 22 22 2 2 6 2 2 6
  93401. - 2 2 6 2 2 6 18 18 18 86 86 86
  93402. - 42 42 42 14 14 14 0 0 0 0 0 0
  93403. - 0 0 0 0 0 0 0 0 0 0 0 0
  93404. - 0 0 0 0 0 0 0 0 0 0 0 0
  93405. - 0 0 0 0 0 0 0 0 0 0 0 0
  93406. - 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
  93408. - 0 0 0 0 0 0 0 0 0 0 0 0
  93409. - 0 0 0 0 0 0 0 0 0 0 0 0
  93410. - 0 0 0 0 0 0 0 0 0 14 14 14
  93411. - 42 42 42 90 90 90 22 22 22 2 2 6
  93412. - 42 42 42 2 2 6 18 18 18 218 218 218
  93413. -253 253 253 253 253 253 253 253 253 253 253 253
  93414. -253 253 253 253 253 253 253 253 253 253 253 253
  93415. -253 253 253 253 253 253 253 253 253 253 253 253
  93416. -253 253 253 253 253 253 253 253 253 253 253 253
  93417. -253 253 253 253 253 253 253 253 253 253 253 253
  93418. -253 253 253 253 253 253 250 250 250 221 221 221
  93419. -218 218 218 101 101 101 2 2 6 14 14 14
  93420. - 18 18 18 38 38 38 10 10 10 2 2 6
  93421. - 2 2 6 2 2 6 2 2 6 78 78 78
  93422. - 58 58 58 22 22 22 6 6 6 0 0 0
  93423. - 0 0 0 0 0 0 0 0 0 0 0 0
  93424. - 0 0 0 0 0 0 0 0 0 0 0 0
  93425. - 0 0 0 0 0 0 0 0 0 0 0 0
  93426. - 0 0 0 0 0 0 0 0 0 0 0 0
  93427. - 0 0 0 0 0 0 0 0 0 0 0 0
  93428. - 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
  93430. - 0 0 0 0 0 0 6 6 6 18 18 18
  93431. - 54 54 54 82 82 82 2 2 6 26 26 26
  93432. - 22 22 22 2 2 6 123 123 123 253 253 253
  93433. -253 253 253 253 253 253 253 253 253 253 253 253
  93434. -253 253 253 253 253 253 253 253 253 253 253 253
  93435. -253 253 253 253 253 253 253 253 253 253 253 253
  93436. -253 253 253 253 253 253 253 253 253 253 253 253
  93437. -253 253 253 253 253 253 253 253 253 253 253 253
  93438. -253 253 253 253 253 253 253 253 253 250 250 250
  93439. -238 238 238 198 198 198 6 6 6 38 38 38
  93440. - 58 58 58 26 26 26 38 38 38 2 2 6
  93441. - 2 2 6 2 2 6 2 2 6 46 46 46
  93442. - 78 78 78 30 30 30 10 10 10 0 0 0
  93443. - 0 0 0 0 0 0 0 0 0 0 0 0
  93444. - 0 0 0 0 0 0 0 0 0 0 0 0
  93445. - 0 0 0 0 0 0 0 0 0 0 0 0
  93446. - 0 0 0 0 0 0 0 0 0 0 0 0
  93447. - 0 0 0 0 0 0 0 0 0 0 0 0
  93448. - 0 0 0 0 0 0 0 0 0 0 0 0
  93449. - 0 0 0 0 0 0 0 0 0 0 0 0
  93450. - 0 0 0 0 0 0 10 10 10 30 30 30
  93451. - 74 74 74 58 58 58 2 2 6 42 42 42
  93452. - 2 2 6 22 22 22 231 231 231 253 253 253
  93453. -253 253 253 253 253 253 253 253 253 253 253 253
  93454. -253 253 253 253 253 253 253 253 253 250 250 250
  93455. -253 253 253 253 253 253 253 253 253 253 253 253
  93456. -253 253 253 253 253 253 253 253 253 253 253 253
  93457. -253 253 253 253 253 253 253 253 253 253 253 253
  93458. -253 253 253 253 253 253 253 253 253 253 253 253
  93459. -253 253 253 246 246 246 46 46 46 38 38 38
  93460. - 42 42 42 14 14 14 38 38 38 14 14 14
  93461. - 2 2 6 2 2 6 2 2 6 6 6 6
  93462. - 86 86 86 46 46 46 14 14 14 0 0 0
  93463. - 0 0 0 0 0 0 0 0 0 0 0 0
  93464. - 0 0 0 0 0 0 0 0 0 0 0 0
  93465. - 0 0 0 0 0 0 0 0 0 0 0 0
  93466. - 0 0 0 0 0 0 0 0 0 0 0 0
  93467. - 0 0 0 0 0 0 0 0 0 0 0 0
  93468. - 0 0 0 0 0 0 0 0 0 0 0 0
  93469. - 0 0 0 0 0 0 0 0 0 0 0 0
  93470. - 0 0 0 6 6 6 14 14 14 42 42 42
  93471. - 90 90 90 18 18 18 18 18 18 26 26 26
  93472. - 2 2 6 116 116 116 253 253 253 253 253 253
  93473. -253 253 253 253 253 253 253 253 253 253 253 253
  93474. -253 253 253 253 253 253 250 250 250 238 238 238
  93475. -253 253 253 253 253 253 253 253 253 253 253 253
  93476. -253 253 253 253 253 253 253 253 253 253 253 253
  93477. -253 253 253 253 253 253 253 253 253 253 253 253
  93478. -253 253 253 253 253 253 253 253 253 253 253 253
  93479. -253 253 253 253 253 253 94 94 94 6 6 6
  93480. - 2 2 6 2 2 6 10 10 10 34 34 34
  93481. - 2 2 6 2 2 6 2 2 6 2 2 6
  93482. - 74 74 74 58 58 58 22 22 22 6 6 6
  93483. - 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
  93485. - 0 0 0 0 0 0 0 0 0 0 0 0
  93486. - 0 0 0 0 0 0 0 0 0 0 0 0
  93487. - 0 0 0 0 0 0 0 0 0 0 0 0
  93488. - 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
  93490. - 0 0 0 10 10 10 26 26 26 66 66 66
  93491. - 82 82 82 2 2 6 38 38 38 6 6 6
  93492. - 14 14 14 210 210 210 253 253 253 253 253 253
  93493. -253 253 253 253 253 253 253 253 253 253 253 253
  93494. -253 253 253 253 253 253 246 246 246 242 242 242
  93495. -253 253 253 253 253 253 253 253 253 253 253 253
  93496. -253 253 253 253 253 253 253 253 253 253 253 253
  93497. -253 253 253 253 253 253 253 253 253 253 253 253
  93498. -253 253 253 253 253 253 253 253 253 253 253 253
  93499. -253 253 253 253 253 253 144 144 144 2 2 6
  93500. - 2 2 6 2 2 6 2 2 6 46 46 46
  93501. - 2 2 6 2 2 6 2 2 6 2 2 6
  93502. - 42 42 42 74 74 74 30 30 30 10 10 10
  93503. - 0 0 0 0 0 0 0 0 0 0 0 0
  93504. - 0 0 0 0 0 0 0 0 0 0 0 0
  93505. - 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
  93507. - 0 0 0 0 0 0 0 0 0 0 0 0
  93508. - 0 0 0 0 0 0 0 0 0 0 0 0
  93509. - 0 0 0 0 0 0 0 0 0 0 0 0
  93510. - 6 6 6 14 14 14 42 42 42 90 90 90
  93511. - 26 26 26 6 6 6 42 42 42 2 2 6
  93512. - 74 74 74 250 250 250 253 253 253 253 253 253
  93513. -253 253 253 253 253 253 253 253 253 253 253 253
  93514. -253 253 253 253 253 253 242 242 242 242 242 242
  93515. -253 253 253 253 253 253 253 253 253 253 253 253
  93516. -253 253 253 253 253 253 253 253 253 253 253 253
  93517. -253 253 253 253 253 253 253 253 253 253 253 253
  93518. -253 253 253 253 253 253 253 253 253 253 253 253
  93519. -253 253 253 253 253 253 182 182 182 2 2 6
  93520. - 2 2 6 2 2 6 2 2 6 46 46 46
  93521. - 2 2 6 2 2 6 2 2 6 2 2 6
  93522. - 10 10 10 86 86 86 38 38 38 10 10 10
  93523. - 0 0 0 0 0 0 0 0 0 0 0 0
  93524. - 0 0 0 0 0 0 0 0 0 0 0 0
  93525. - 0 0 0 0 0 0 0 0 0 0 0 0
  93526. - 0 0 0 0 0 0 0 0 0 0 0 0
  93527. - 0 0 0 0 0 0 0 0 0 0 0 0
  93528. - 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
  93530. - 10 10 10 26 26 26 66 66 66 82 82 82
  93531. - 2 2 6 22 22 22 18 18 18 2 2 6
  93532. -149 149 149 253 253 253 253 253 253 253 253 253
  93533. -253 253 253 253 253 253 253 253 253 253 253 253
  93534. -253 253 253 253 253 253 234 234 234 242 242 242
  93535. -253 253 253 253 253 253 253 253 253 253 253 253
  93536. -253 253 253 253 253 253 253 253 253 253 253 253
  93537. -253 253 253 253 253 253 253 253 253 253 253 253
  93538. -253 253 253 253 253 253 253 253 253 253 253 253
  93539. -253 253 253 253 253 253 206 206 206 2 2 6
  93540. - 2 2 6 2 2 6 2 2 6 38 38 38
  93541. - 2 2 6 2 2 6 2 2 6 2 2 6
  93542. - 6 6 6 86 86 86 46 46 46 14 14 14
  93543. - 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
  93545. - 0 0 0 0 0 0 0 0 0 0 0 0
  93546. - 0 0 0 0 0 0 0 0 0 0 0 0
  93547. - 0 0 0 0 0 0 0 0 0 0 0 0
  93548. - 0 0 0 0 0 0 0 0 0 0 0 0
  93549. - 0 0 0 0 0 0 0 0 0 6 6 6
  93550. - 18 18 18 46 46 46 86 86 86 18 18 18
  93551. - 2 2 6 34 34 34 10 10 10 6 6 6
  93552. -210 210 210 253 253 253 253 253 253 253 253 253
  93553. -253 253 253 253 253 253 253 253 253 253 253 253
  93554. -253 253 253 253 253 253 234 234 234 242 242 242
  93555. -253 253 253 253 253 253 253 253 253 253 253 253
  93556. -253 253 253 253 253 253 253 253 253 253 253 253
  93557. -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
  93559. -253 253 253 253 253 253 221 221 221 6 6 6
  93560. - 2 2 6 2 2 6 6 6 6 30 30 30
  93561. - 2 2 6 2 2 6 2 2 6 2 2 6
  93562. - 2 2 6 82 82 82 54 54 54 18 18 18
  93563. - 6 6 6 0 0 0 0 0 0 0 0 0
  93564. - 0 0 0 0 0 0 0 0 0 0 0 0
  93565. - 0 0 0 0 0 0 0 0 0 0 0 0
  93566. - 0 0 0 0 0 0 0 0 0 0 0 0
  93567. - 0 0 0 0 0 0 0 0 0 0 0 0
  93568. - 0 0 0 0 0 0 0 0 0 0 0 0
  93569. - 0 0 0 0 0 0 0 0 0 10 10 10
  93570. - 26 26 26 66 66 66 62 62 62 2 2 6
  93571. - 2 2 6 38 38 38 10 10 10 26 26 26
  93572. -238 238 238 253 253 253 253 253 253 253 253 253
  93573. -253 253 253 253 253 253 253 253 253 253 253 253
  93574. -253 253 253 253 253 253 231 231 231 238 238 238
  93575. -253 253 253 253 253 253 253 253 253 253 253 253
  93576. -253 253 253 253 253 253 253 253 253 253 253 253
  93577. -253 253 253 253 253 253 253 253 253 253 253 253
  93578. -253 253 253 253 253 253 253 253 253 253 253 253
  93579. -253 253 253 253 253 253 231 231 231 6 6 6
  93580. - 2 2 6 2 2 6 10 10 10 30 30 30
  93581. - 2 2 6 2 2 6 2 2 6 2 2 6
  93582. - 2 2 6 66 66 66 58 58 58 22 22 22
  93583. - 6 6 6 0 0 0 0 0 0 0 0 0
  93584. - 0 0 0 0 0 0 0 0 0 0 0 0
  93585. - 0 0 0 0 0 0 0 0 0 0 0 0
  93586. - 0 0 0 0 0 0 0 0 0 0 0 0
  93587. - 0 0 0 0 0 0 0 0 0 0 0 0
  93588. - 0 0 0 0 0 0 0 0 0 0 0 0
  93589. - 0 0 0 0 0 0 0 0 0 10 10 10
  93590. - 38 38 38 78 78 78 6 6 6 2 2 6
  93591. - 2 2 6 46 46 46 14 14 14 42 42 42
  93592. -246 246 246 253 253 253 253 253 253 253 253 253
  93593. -253 253 253 253 253 253 253 253 253 253 253 253
  93594. -253 253 253 253 253 253 231 231 231 242 242 242
  93595. -253 253 253 253 253 253 253 253 253 253 253 253
  93596. -253 253 253 253 253 253 253 253 253 253 253 253
  93597. -253 253 253 253 253 253 253 253 253 253 253 253
  93598. -253 253 253 253 253 253 253 253 253 253 253 253
  93599. -253 253 253 253 253 253 234 234 234 10 10 10
  93600. - 2 2 6 2 2 6 22 22 22 14 14 14
  93601. - 2 2 6 2 2 6 2 2 6 2 2 6
  93602. - 2 2 6 66 66 66 62 62 62 22 22 22
  93603. - 6 6 6 0 0 0 0 0 0 0 0 0
  93604. - 0 0 0 0 0 0 0 0 0 0 0 0
  93605. - 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
  93607. - 0 0 0 0 0 0 0 0 0 0 0 0
  93608. - 0 0 0 0 0 0 0 0 0 0 0 0
  93609. - 0 0 0 0 0 0 6 6 6 18 18 18
  93610. - 50 50 50 74 74 74 2 2 6 2 2 6
  93611. - 14 14 14 70 70 70 34 34 34 62 62 62
  93612. -250 250 250 253 253 253 253 253 253 253 253 253
  93613. -253 253 253 253 253 253 253 253 253 253 253 253
  93614. -253 253 253 253 253 253 231 231 231 246 246 246
  93615. -253 253 253 253 253 253 253 253 253 253 253 253
  93616. -253 253 253 253 253 253 253 253 253 253 253 253
  93617. -253 253 253 253 253 253 253 253 253 253 253 253
  93618. -253 253 253 253 253 253 253 253 253 253 253 253
  93619. -253 253 253 253 253 253 234 234 234 14 14 14
  93620. - 2 2 6 2 2 6 30 30 30 2 2 6
  93621. - 2 2 6 2 2 6 2 2 6 2 2 6
  93622. - 2 2 6 66 66 66 62 62 62 22 22 22
  93623. - 6 6 6 0 0 0 0 0 0 0 0 0
  93624. - 0 0 0 0 0 0 0 0 0 0 0 0
  93625. - 0 0 0 0 0 0 0 0 0 0 0 0
  93626. - 0 0 0 0 0 0 0 0 0 0 0 0
  93627. - 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
  93629. - 0 0 0 0 0 0 6 6 6 18 18 18
  93630. - 54 54 54 62 62 62 2 2 6 2 2 6
  93631. - 2 2 6 30 30 30 46 46 46 70 70 70
  93632. -250 250 250 253 253 253 253 253 253 253 253 253
  93633. -253 253 253 253 253 253 253 253 253 253 253 253
  93634. -253 253 253 253 253 253 231 231 231 246 246 246
  93635. -253 253 253 253 253 253 253 253 253 253 253 253
  93636. -253 253 253 253 253 253 253 253 253 253 253 253
  93637. -253 253 253 253 253 253 253 253 253 253 253 253
  93638. -253 253 253 253 253 253 253 253 253 253 253 253
  93639. -253 253 253 253 253 253 226 226 226 10 10 10
  93640. - 2 2 6 6 6 6 30 30 30 2 2 6
  93641. - 2 2 6 2 2 6 2 2 6 2 2 6
  93642. - 2 2 6 66 66 66 58 58 58 22 22 22
  93643. - 6 6 6 0 0 0 0 0 0 0 0 0
  93644. - 0 0 0 0 0 0 0 0 0 0 0 0
  93645. - 0 0 0 0 0 0 0 0 0 0 0 0
  93646. - 0 0 0 0 0 0 0 0 0 0 0 0
  93647. - 0 0 0 0 0 0 0 0 0 0 0 0
  93648. - 0 0 0 0 0 0 0 0 0 0 0 0
  93649. - 0 0 0 0 0 0 6 6 6 22 22 22
  93650. - 58 58 58 62 62 62 2 2 6 2 2 6
  93651. - 2 2 6 2 2 6 30 30 30 78 78 78
  93652. -250 250 250 253 253 253 253 253 253 253 253 253
  93653. -253 253 253 253 253 253 253 253 253 253 253 253
  93654. -253 253 253 253 253 253 231 231 231 246 246 246
  93655. -253 253 253 253 253 253 253 253 253 253 253 253
  93656. -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
  93658. -253 253 253 253 253 253 253 253 253 253 253 253
  93659. -253 253 253 253 253 253 206 206 206 2 2 6
  93660. - 22 22 22 34 34 34 18 14 6 22 22 22
  93661. - 26 26 26 18 18 18 6 6 6 2 2 6
  93662. - 2 2 6 82 82 82 54 54 54 18 18 18
  93663. - 6 6 6 0 0 0 0 0 0 0 0 0
  93664. - 0 0 0 0 0 0 0 0 0 0 0 0
  93665. - 0 0 0 0 0 0 0 0 0 0 0 0
  93666. - 0 0 0 0 0 0 0 0 0 0 0 0
  93667. - 0 0 0 0 0 0 0 0 0 0 0 0
  93668. - 0 0 0 0 0 0 0 0 0 0 0 0
  93669. - 0 0 0 0 0 0 6 6 6 26 26 26
  93670. - 62 62 62 106 106 106 74 54 14 185 133 11
  93671. -210 162 10 121 92 8 6 6 6 62 62 62
  93672. -238 238 238 253 253 253 253 253 253 253 253 253
  93673. -253 253 253 253 253 253 253 253 253 253 253 253
  93674. -253 253 253 253 253 253 231 231 231 246 246 246
  93675. -253 253 253 253 253 253 253 253 253 253 253 253
  93676. -253 253 253 253 253 253 253 253 253 253 253 253
  93677. -253 253 253 253 253 253 253 253 253 253 253 253
  93678. -253 253 253 253 253 253 253 253 253 253 253 253
  93679. -253 253 253 253 253 253 158 158 158 18 18 18
  93680. - 14 14 14 2 2 6 2 2 6 2 2 6
  93681. - 6 6 6 18 18 18 66 66 66 38 38 38
  93682. - 6 6 6 94 94 94 50 50 50 18 18 18
  93683. - 6 6 6 0 0 0 0 0 0 0 0 0
  93684. - 0 0 0 0 0 0 0 0 0 0 0 0
  93685. - 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
  93687. - 0 0 0 0 0 0 0 0 0 0 0 0
  93688. - 0 0 0 0 0 0 0 0 0 6 6 6
  93689. - 10 10 10 10 10 10 18 18 18 38 38 38
  93690. - 78 78 78 142 134 106 216 158 10 242 186 14
  93691. -246 190 14 246 190 14 156 118 10 10 10 10
  93692. - 90 90 90 238 238 238 253 253 253 253 253 253
  93693. -253 253 253 253 253 253 253 253 253 253 253 253
  93694. -253 253 253 253 253 253 231 231 231 250 250 250
  93695. -253 253 253 253 253 253 253 253 253 253 253 253
  93696. -253 253 253 253 253 253 253 253 253 253 253 253
  93697. -253 253 253 253 253 253 253 253 253 253 253 253
  93698. -253 253 253 253 253 253 253 253 253 246 230 190
  93699. -238 204 91 238 204 91 181 142 44 37 26 9
  93700. - 2 2 6 2 2 6 2 2 6 2 2 6
  93701. - 2 2 6 2 2 6 38 38 38 46 46 46
  93702. - 26 26 26 106 106 106 54 54 54 18 18 18
  93703. - 6 6 6 0 0 0 0 0 0 0 0 0
  93704. - 0 0 0 0 0 0 0 0 0 0 0 0
  93705. - 0 0 0 0 0 0 0 0 0 0 0 0
  93706. - 0 0 0 0 0 0 0 0 0 0 0 0
  93707. - 0 0 0 0 0 0 0 0 0 0 0 0
  93708. - 0 0 0 6 6 6 14 14 14 22 22 22
  93709. - 30 30 30 38 38 38 50 50 50 70 70 70
  93710. -106 106 106 190 142 34 226 170 11 242 186 14
  93711. -246 190 14 246 190 14 246 190 14 154 114 10
  93712. - 6 6 6 74 74 74 226 226 226 253 253 253
  93713. -253 253 253 253 253 253 253 253 253 253 253 253
  93714. -253 253 253 253 253 253 231 231 231 250 250 250
  93715. -253 253 253 253 253 253 253 253 253 253 253 253
  93716. -253 253 253 253 253 253 253 253 253 253 253 253
  93717. -253 253 253 253 253 253 253 253 253 253 253 253
  93718. -253 253 253 253 253 253 253 253 253 228 184 62
  93719. -241 196 14 241 208 19 232 195 16 38 30 10
  93720. - 2 2 6 2 2 6 2 2 6 2 2 6
  93721. - 2 2 6 6 6 6 30 30 30 26 26 26
  93722. -203 166 17 154 142 90 66 66 66 26 26 26
  93723. - 6 6 6 0 0 0 0 0 0 0 0 0
  93724. - 0 0 0 0 0 0 0 0 0 0 0 0
  93725. - 0 0 0 0 0 0 0 0 0 0 0 0
  93726. - 0 0 0 0 0 0 0 0 0 0 0 0
  93727. - 0 0 0 0 0 0 0 0 0 0 0 0
  93728. - 6 6 6 18 18 18 38 38 38 58 58 58
  93729. - 78 78 78 86 86 86 101 101 101 123 123 123
  93730. -175 146 61 210 150 10 234 174 13 246 186 14
  93731. -246 190 14 246 190 14 246 190 14 238 190 10
  93732. -102 78 10 2 2 6 46 46 46 198 198 198
  93733. -253 253 253 253 253 253 253 253 253 253 253 253
  93734. -253 253 253 253 253 253 234 234 234 242 242 242
  93735. -253 253 253 253 253 253 253 253 253 253 253 253
  93736. -253 253 253 253 253 253 253 253 253 253 253 253
  93737. -253 253 253 253 253 253 253 253 253 253 253 253
  93738. -253 253 253 253 253 253 253 253 253 224 178 62
  93739. -242 186 14 241 196 14 210 166 10 22 18 6
  93740. - 2 2 6 2 2 6 2 2 6 2 2 6
  93741. - 2 2 6 2 2 6 6 6 6 121 92 8
  93742. -238 202 15 232 195 16 82 82 82 34 34 34
  93743. - 10 10 10 0 0 0 0 0 0 0 0 0
  93744. - 0 0 0 0 0 0 0 0 0 0 0 0
  93745. - 0 0 0 0 0 0 0 0 0 0 0 0
  93746. - 0 0 0 0 0 0 0 0 0 0 0 0
  93747. - 0 0 0 0 0 0 0 0 0 0 0 0
  93748. - 14 14 14 38 38 38 70 70 70 154 122 46
  93749. -190 142 34 200 144 11 197 138 11 197 138 11
  93750. -213 154 11 226 170 11 242 186 14 246 190 14
  93751. -246 190 14 246 190 14 246 190 14 246 190 14
  93752. -225 175 15 46 32 6 2 2 6 22 22 22
  93753. -158 158 158 250 250 250 253 253 253 253 253 253
  93754. -253 253 253 253 253 253 253 253 253 253 253 253
  93755. -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
  93757. -253 253 253 253 253 253 253 253 253 253 253 253
  93758. -253 253 253 250 250 250 242 242 242 224 178 62
  93759. -239 182 13 236 186 11 213 154 11 46 32 6
  93760. - 2 2 6 2 2 6 2 2 6 2 2 6
  93761. - 2 2 6 2 2 6 61 42 6 225 175 15
  93762. -238 190 10 236 186 11 112 100 78 42 42 42
  93763. - 14 14 14 0 0 0 0 0 0 0 0 0
  93764. - 0 0 0 0 0 0 0 0 0 0 0 0
  93765. - 0 0 0 0 0 0 0 0 0 0 0 0
  93766. - 0 0 0 0 0 0 0 0 0 0 0 0
  93767. - 0 0 0 0 0 0 0 0 0 6 6 6
  93768. - 22 22 22 54 54 54 154 122 46 213 154 11
  93769. -226 170 11 230 174 11 226 170 11 226 170 11
  93770. -236 178 12 242 186 14 246 190 14 246 190 14
  93771. -246 190 14 246 190 14 246 190 14 246 190 14
  93772. -241 196 14 184 144 12 10 10 10 2 2 6
  93773. - 6 6 6 116 116 116 242 242 242 253 253 253
  93774. -253 253 253 253 253 253 253 253 253 253 253 253
  93775. -253 253 253 253 253 253 253 253 253 253 253 253
  93776. -253 253 253 253 253 253 253 253 253 253 253 253
  93777. -253 253 253 253 253 253 253 253 253 253 253 253
  93778. -253 253 253 231 231 231 198 198 198 214 170 54
  93779. -236 178 12 236 178 12 210 150 10 137 92 6
  93780. - 18 14 6 2 2 6 2 2 6 2 2 6
  93781. - 6 6 6 70 47 6 200 144 11 236 178 12
  93782. -239 182 13 239 182 13 124 112 88 58 58 58
  93783. - 22 22 22 6 6 6 0 0 0 0 0 0
  93784. - 0 0 0 0 0 0 0 0 0 0 0 0
  93785. - 0 0 0 0 0 0 0 0 0 0 0 0
  93786. - 0 0 0 0 0 0 0 0 0 0 0 0
  93787. - 0 0 0 0 0 0 0 0 0 10 10 10
  93788. - 30 30 30 70 70 70 180 133 36 226 170 11
  93789. -239 182 13 242 186 14 242 186 14 246 186 14
  93790. -246 190 14 246 190 14 246 190 14 246 190 14
  93791. -246 190 14 246 190 14 246 190 14 246 190 14
  93792. -246 190 14 232 195 16 98 70 6 2 2 6
  93793. - 2 2 6 2 2 6 66 66 66 221 221 221
  93794. -253 253 253 253 253 253 253 253 253 253 253 253
  93795. -253 253 253 253 253 253 253 253 253 253 253 253
  93796. -253 253 253 253 253 253 253 253 253 253 253 253
  93797. -253 253 253 253 253 253 253 253 253 253 253 253
  93798. -253 253 253 206 206 206 198 198 198 214 166 58
  93799. -230 174 11 230 174 11 216 158 10 192 133 9
  93800. -163 110 8 116 81 8 102 78 10 116 81 8
  93801. -167 114 7 197 138 11 226 170 11 239 182 13
  93802. -242 186 14 242 186 14 162 146 94 78 78 78
  93803. - 34 34 34 14 14 14 6 6 6 0 0 0
  93804. - 0 0 0 0 0 0 0 0 0 0 0 0
  93805. - 0 0 0 0 0 0 0 0 0 0 0 0
  93806. - 0 0 0 0 0 0 0 0 0 0 0 0
  93807. - 0 0 0 0 0 0 0 0 0 6 6 6
  93808. - 30 30 30 78 78 78 190 142 34 226 170 11
  93809. -239 182 13 246 190 14 246 190 14 246 190 14
  93810. -246 190 14 246 190 14 246 190 14 246 190 14
  93811. -246 190 14 246 190 14 246 190 14 246 190 14
  93812. -246 190 14 241 196 14 203 166 17 22 18 6
  93813. - 2 2 6 2 2 6 2 2 6 38 38 38
  93814. -218 218 218 253 253 253 253 253 253 253 253 253
  93815. -253 253 253 253 253 253 253 253 253 253 253 253
  93816. -253 253 253 253 253 253 253 253 253 253 253 253
  93817. -253 253 253 253 253 253 253 253 253 253 253 253
  93818. -250 250 250 206 206 206 198 198 198 202 162 69
  93819. -226 170 11 236 178 12 224 166 10 210 150 10
  93820. -200 144 11 197 138 11 192 133 9 197 138 11
  93821. -210 150 10 226 170 11 242 186 14 246 190 14
  93822. -246 190 14 246 186 14 225 175 15 124 112 88
  93823. - 62 62 62 30 30 30 14 14 14 6 6 6
  93824. - 0 0 0 0 0 0 0 0 0 0 0 0
  93825. - 0 0 0 0 0 0 0 0 0 0 0 0
  93826. - 0 0 0 0 0 0 0 0 0 0 0 0
  93827. - 0 0 0 0 0 0 0 0 0 10 10 10
  93828. - 30 30 30 78 78 78 174 135 50 224 166 10
  93829. -239 182 13 246 190 14 246 190 14 246 190 14
  93830. -246 190 14 246 190 14 246 190 14 246 190 14
  93831. -246 190 14 246 190 14 246 190 14 246 190 14
  93832. -246 190 14 246 190 14 241 196 14 139 102 15
  93833. - 2 2 6 2 2 6 2 2 6 2 2 6
  93834. - 78 78 78 250 250 250 253 253 253 253 253 253
  93835. -253 253 253 253 253 253 253 253 253 253 253 253
  93836. -253 253 253 253 253 253 253 253 253 253 253 253
  93837. -253 253 253 253 253 253 253 253 253 253 253 253
  93838. -250 250 250 214 214 214 198 198 198 190 150 46
  93839. -219 162 10 236 178 12 234 174 13 224 166 10
  93840. -216 158 10 213 154 11 213 154 11 216 158 10
  93841. -226 170 11 239 182 13 246 190 14 246 190 14
  93842. -246 190 14 246 190 14 242 186 14 206 162 42
  93843. -101 101 101 58 58 58 30 30 30 14 14 14
  93844. - 6 6 6 0 0 0 0 0 0 0 0 0
  93845. - 0 0 0 0 0 0 0 0 0 0 0 0
  93846. - 0 0 0 0 0 0 0 0 0 0 0 0
  93847. - 0 0 0 0 0 0 0 0 0 10 10 10
  93848. - 30 30 30 74 74 74 174 135 50 216 158 10
  93849. -236 178 12 246 190 14 246 190 14 246 190 14
  93850. -246 190 14 246 190 14 246 190 14 246 190 14
  93851. -246 190 14 246 190 14 246 190 14 246 190 14
  93852. -246 190 14 246 190 14 241 196 14 226 184 13
  93853. - 61 42 6 2 2 6 2 2 6 2 2 6
  93854. - 22 22 22 238 238 238 253 253 253 253 253 253
  93855. -253 253 253 253 253 253 253 253 253 253 253 253
  93856. -253 253 253 253 253 253 253 253 253 253 253 253
  93857. -253 253 253 253 253 253 253 253 253 253 253 253
  93858. -253 253 253 226 226 226 187 187 187 180 133 36
  93859. -216 158 10 236 178 12 239 182 13 236 178 12
  93860. -230 174 11 226 170 11 226 170 11 230 174 11
  93861. -236 178 12 242 186 14 246 190 14 246 190 14
  93862. -246 190 14 246 190 14 246 186 14 239 182 13
  93863. -206 162 42 106 106 106 66 66 66 34 34 34
  93864. - 14 14 14 6 6 6 0 0 0 0 0 0
  93865. - 0 0 0 0 0 0 0 0 0 0 0 0
  93866. - 0 0 0 0 0 0 0 0 0 0 0 0
  93867. - 0 0 0 0 0 0 0 0 0 6 6 6
  93868. - 26 26 26 70 70 70 163 133 67 213 154 11
  93869. -236 178 12 246 190 14 246 190 14 246 190 14
  93870. -246 190 14 246 190 14 246 190 14 246 190 14
  93871. -246 190 14 246 190 14 246 190 14 246 190 14
  93872. -246 190 14 246 190 14 246 190 14 241 196 14
  93873. -190 146 13 18 14 6 2 2 6 2 2 6
  93874. - 46 46 46 246 246 246 253 253 253 253 253 253
  93875. -253 253 253 253 253 253 253 253 253 253 253 253
  93876. -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
  93878. -253 253 253 221 221 221 86 86 86 156 107 11
  93879. -216 158 10 236 178 12 242 186 14 246 186 14
  93880. -242 186 14 239 182 13 239 182 13 242 186 14
  93881. -242 186 14 246 186 14 246 190 14 246 190 14
  93882. -246 190 14 246 190 14 246 190 14 246 190 14
  93883. -242 186 14 225 175 15 142 122 72 66 66 66
  93884. - 30 30 30 10 10 10 0 0 0 0 0 0
  93885. - 0 0 0 0 0 0 0 0 0 0 0 0
  93886. - 0 0 0 0 0 0 0 0 0 0 0 0
  93887. - 0 0 0 0 0 0 0 0 0 6 6 6
  93888. - 26 26 26 70 70 70 163 133 67 210 150 10
  93889. -236 178 12 246 190 14 246 190 14 246 190 14
  93890. -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
  93892. -246 190 14 246 190 14 246 190 14 246 190 14
  93893. -232 195 16 121 92 8 34 34 34 106 106 106
  93894. -221 221 221 253 253 253 253 253 253 253 253 253
  93895. -253 253 253 253 253 253 253 253 253 253 253 253
  93896. -253 253 253 253 253 253 253 253 253 253 253 253
  93897. -253 253 253 253 253 253 253 253 253 253 253 253
  93898. -242 242 242 82 82 82 18 14 6 163 110 8
  93899. -216 158 10 236 178 12 242 186 14 246 190 14
  93900. -246 190 14 246 190 14 246 190 14 246 190 14
  93901. -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
  93903. -246 190 14 246 190 14 242 186 14 163 133 67
  93904. - 46 46 46 18 18 18 6 6 6 0 0 0
  93905. - 0 0 0 0 0 0 0 0 0 0 0 0
  93906. - 0 0 0 0 0 0 0 0 0 0 0 0
  93907. - 0 0 0 0 0 0 0 0 0 10 10 10
  93908. - 30 30 30 78 78 78 163 133 67 210 150 10
  93909. -236 178 12 246 186 14 246 190 14 246 190 14
  93910. -246 190 14 246 190 14 246 190 14 246 190 14
  93911. -246 190 14 246 190 14 246 190 14 246 190 14
  93912. -246 190 14 246 190 14 246 190 14 246 190 14
  93913. -241 196 14 215 174 15 190 178 144 253 253 253
  93914. -253 253 253 253 253 253 253 253 253 253 253 253
  93915. -253 253 253 253 253 253 253 253 253 253 253 253
  93916. -253 253 253 253 253 253 253 253 253 253 253 253
  93917. -253 253 253 253 253 253 253 253 253 218 218 218
  93918. - 58 58 58 2 2 6 22 18 6 167 114 7
  93919. -216 158 10 236 178 12 246 186 14 246 190 14
  93920. -246 190 14 246 190 14 246 190 14 246 190 14
  93921. -246 190 14 246 190 14 246 190 14 246 190 14
  93922. -246 190 14 246 190 14 246 190 14 246 190 14
  93923. -246 190 14 246 186 14 242 186 14 190 150 46
  93924. - 54 54 54 22 22 22 6 6 6 0 0 0
  93925. - 0 0 0 0 0 0 0 0 0 0 0 0
  93926. - 0 0 0 0 0 0 0 0 0 0 0 0
  93927. - 0 0 0 0 0 0 0 0 0 14 14 14
  93928. - 38 38 38 86 86 86 180 133 36 213 154 11
  93929. -236 178 12 246 186 14 246 190 14 246 190 14
  93930. -246 190 14 246 190 14 246 190 14 246 190 14
  93931. -246 190 14 246 190 14 246 190 14 246 190 14
  93932. -246 190 14 246 190 14 246 190 14 246 190 14
  93933. -246 190 14 232 195 16 190 146 13 214 214 214
  93934. -253 253 253 253 253 253 253 253 253 253 253 253
  93935. -253 253 253 253 253 253 253 253 253 253 253 253
  93936. -253 253 253 253 253 253 253 253 253 253 253 253
  93937. -253 253 253 250 250 250 170 170 170 26 26 26
  93938. - 2 2 6 2 2 6 37 26 9 163 110 8
  93939. -219 162 10 239 182 13 246 186 14 246 190 14
  93940. -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
  93942. -246 190 14 246 190 14 246 190 14 246 190 14
  93943. -246 186 14 236 178 12 224 166 10 142 122 72
  93944. - 46 46 46 18 18 18 6 6 6 0 0 0
  93945. - 0 0 0 0 0 0 0 0 0 0 0 0
  93946. - 0 0 0 0 0 0 0 0 0 0 0 0
  93947. - 0 0 0 0 0 0 6 6 6 18 18 18
  93948. - 50 50 50 109 106 95 192 133 9 224 166 10
  93949. -242 186 14 246 190 14 246 190 14 246 190 14
  93950. -246 190 14 246 190 14 246 190 14 246 190 14
  93951. -246 190 14 246 190 14 246 190 14 246 190 14
  93952. -246 190 14 246 190 14 246 190 14 246 190 14
  93953. -242 186 14 226 184 13 210 162 10 142 110 46
  93954. -226 226 226 253 253 253 253 253 253 253 253 253
  93955. -253 253 253 253 253 253 253 253 253 253 253 253
  93956. -253 253 253 253 253 253 253 253 253 253 253 253
  93957. -198 198 198 66 66 66 2 2 6 2 2 6
  93958. - 2 2 6 2 2 6 50 34 6 156 107 11
  93959. -219 162 10 239 182 13 246 186 14 246 190 14
  93960. -246 190 14 246 190 14 246 190 14 246 190 14
  93961. -246 190 14 246 190 14 246 190 14 246 190 14
  93962. -246 190 14 246 190 14 246 190 14 242 186 14
  93963. -234 174 13 213 154 11 154 122 46 66 66 66
  93964. - 30 30 30 10 10 10 0 0 0 0 0 0
  93965. - 0 0 0 0 0 0 0 0 0 0 0 0
  93966. - 0 0 0 0 0 0 0 0 0 0 0 0
  93967. - 0 0 0 0 0 0 6 6 6 22 22 22
  93968. - 58 58 58 154 121 60 206 145 10 234 174 13
  93969. -242 186 14 246 186 14 246 190 14 246 190 14
  93970. -246 190 14 246 190 14 246 190 14 246 190 14
  93971. -246 190 14 246 190 14 246 190 14 246 190 14
  93972. -246 190 14 246 190 14 246 190 14 246 190 14
  93973. -246 186 14 236 178 12 210 162 10 163 110 8
  93974. - 61 42 6 138 138 138 218 218 218 250 250 250
  93975. -253 253 253 253 253 253 253 253 253 250 250 250
  93976. -242 242 242 210 210 210 144 144 144 66 66 66
  93977. - 6 6 6 2 2 6 2 2 6 2 2 6
  93978. - 2 2 6 2 2 6 61 42 6 163 110 8
  93979. -216 158 10 236 178 12 246 190 14 246 190 14
  93980. -246 190 14 246 190 14 246 190 14 246 190 14
  93981. -246 190 14 246 190 14 246 190 14 246 190 14
  93982. -246 190 14 239 182 13 230 174 11 216 158 10
  93983. -190 142 34 124 112 88 70 70 70 38 38 38
  93984. - 18 18 18 6 6 6 0 0 0 0 0 0
  93985. - 0 0 0 0 0 0 0 0 0 0 0 0
  93986. - 0 0 0 0 0 0 0 0 0 0 0 0
  93987. - 0 0 0 0 0 0 6 6 6 22 22 22
  93988. - 62 62 62 168 124 44 206 145 10 224 166 10
  93989. -236 178 12 239 182 13 242 186 14 242 186 14
  93990. -246 186 14 246 190 14 246 190 14 246 190 14
  93991. -246 190 14 246 190 14 246 190 14 246 190 14
  93992. -246 190 14 246 190 14 246 190 14 246 190 14
  93993. -246 190 14 236 178 12 216 158 10 175 118 6
  93994. - 80 54 7 2 2 6 6 6 6 30 30 30
  93995. - 54 54 54 62 62 62 50 50 50 38 38 38
  93996. - 14 14 14 2 2 6 2 2 6 2 2 6
  93997. - 2 2 6 2 2 6 2 2 6 2 2 6
  93998. - 2 2 6 6 6 6 80 54 7 167 114 7
  93999. -213 154 11 236 178 12 246 190 14 246 190 14
  94000. -246 190 14 246 190 14 246 190 14 246 190 14
  94001. -246 190 14 242 186 14 239 182 13 239 182 13
  94002. -230 174 11 210 150 10 174 135 50 124 112 88
  94003. - 82 82 82 54 54 54 34 34 34 18 18 18
  94004. - 6 6 6 0 0 0 0 0 0 0 0 0
  94005. - 0 0 0 0 0 0 0 0 0 0 0 0
  94006. - 0 0 0 0 0 0 0 0 0 0 0 0
  94007. - 0 0 0 0 0 0 6 6 6 18 18 18
  94008. - 50 50 50 158 118 36 192 133 9 200 144 11
  94009. -216 158 10 219 162 10 224 166 10 226 170 11
  94010. -230 174 11 236 178 12 239 182 13 239 182 13
  94011. -242 186 14 246 186 14 246 190 14 246 190 14
  94012. -246 190 14 246 190 14 246 190 14 246 190 14
  94013. -246 186 14 230 174 11 210 150 10 163 110 8
  94014. -104 69 6 10 10 10 2 2 6 2 2 6
  94015. - 2 2 6 2 2 6 2 2 6 2 2 6
  94016. - 2 2 6 2 2 6 2 2 6 2 2 6
  94017. - 2 2 6 2 2 6 2 2 6 2 2 6
  94018. - 2 2 6 6 6 6 91 60 6 167 114 7
  94019. -206 145 10 230 174 11 242 186 14 246 190 14
  94020. -246 190 14 246 190 14 246 186 14 242 186 14
  94021. -239 182 13 230 174 11 224 166 10 213 154 11
  94022. -180 133 36 124 112 88 86 86 86 58 58 58
  94023. - 38 38 38 22 22 22 10 10 10 6 6 6
  94024. - 0 0 0 0 0 0 0 0 0 0 0 0
  94025. - 0 0 0 0 0 0 0 0 0 0 0 0
  94026. - 0 0 0 0 0 0 0 0 0 0 0 0
  94027. - 0 0 0 0 0 0 0 0 0 14 14 14
  94028. - 34 34 34 70 70 70 138 110 50 158 118 36
  94029. -167 114 7 180 123 7 192 133 9 197 138 11
  94030. -200 144 11 206 145 10 213 154 11 219 162 10
  94031. -224 166 10 230 174 11 239 182 13 242 186 14
  94032. -246 186 14 246 186 14 246 186 14 246 186 14
  94033. -239 182 13 216 158 10 185 133 11 152 99 6
  94034. -104 69 6 18 14 6 2 2 6 2 2 6
  94035. - 2 2 6 2 2 6 2 2 6 2 2 6
  94036. - 2 2 6 2 2 6 2 2 6 2 2 6
  94037. - 2 2 6 2 2 6 2 2 6 2 2 6
  94038. - 2 2 6 6 6 6 80 54 7 152 99 6
  94039. -192 133 9 219 162 10 236 178 12 239 182 13
  94040. -246 186 14 242 186 14 239 182 13 236 178 12
  94041. -224 166 10 206 145 10 192 133 9 154 121 60
  94042. - 94 94 94 62 62 62 42 42 42 22 22 22
  94043. - 14 14 14 6 6 6 0 0 0 0 0 0
  94044. - 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
  94046. - 0 0 0 0 0 0 0 0 0 0 0 0
  94047. - 0 0 0 0 0 0 0 0 0 6 6 6
  94048. - 18 18 18 34 34 34 58 58 58 78 78 78
  94049. -101 98 89 124 112 88 142 110 46 156 107 11
  94050. -163 110 8 167 114 7 175 118 6 180 123 7
  94051. -185 133 11 197 138 11 210 150 10 219 162 10
  94052. -226 170 11 236 178 12 236 178 12 234 174 13
  94053. -219 162 10 197 138 11 163 110 8 130 83 6
  94054. - 91 60 6 10 10 10 2 2 6 2 2 6
  94055. - 18 18 18 38 38 38 38 38 38 38 38 38
  94056. - 38 38 38 38 38 38 38 38 38 38 38 38
  94057. - 38 38 38 38 38 38 26 26 26 2 2 6
  94058. - 2 2 6 6 6 6 70 47 6 137 92 6
  94059. -175 118 6 200 144 11 219 162 10 230 174 11
  94060. -234 174 13 230 174 11 219 162 10 210 150 10
  94061. -192 133 9 163 110 8 124 112 88 82 82 82
  94062. - 50 50 50 30 30 30 14 14 14 6 6 6
  94063. - 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
  94065. - 0 0 0 0 0 0 0 0 0 0 0 0
  94066. - 0 0 0 0 0 0 0 0 0 0 0 0
  94067. - 0 0 0 0 0 0 0 0 0 0 0 0
  94068. - 6 6 6 14 14 14 22 22 22 34 34 34
  94069. - 42 42 42 58 58 58 74 74 74 86 86 86
  94070. -101 98 89 122 102 70 130 98 46 121 87 25
  94071. -137 92 6 152 99 6 163 110 8 180 123 7
  94072. -185 133 11 197 138 11 206 145 10 200 144 11
  94073. -180 123 7 156 107 11 130 83 6 104 69 6
  94074. - 50 34 6 54 54 54 110 110 110 101 98 89
  94075. - 86 86 86 82 82 82 78 78 78 78 78 78
  94076. - 78 78 78 78 78 78 78 78 78 78 78 78
  94077. - 78 78 78 82 82 82 86 86 86 94 94 94
  94078. -106 106 106 101 101 101 86 66 34 124 80 6
  94079. -156 107 11 180 123 7 192 133 9 200 144 11
  94080. -206 145 10 200 144 11 192 133 9 175 118 6
  94081. -139 102 15 109 106 95 70 70 70 42 42 42
  94082. - 22 22 22 10 10 10 0 0 0 0 0 0
  94083. - 0 0 0 0 0 0 0 0 0 0 0 0
  94084. - 0 0 0 0 0 0 0 0 0 0 0 0
  94085. - 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
  94087. - 0 0 0 0 0 0 0 0 0 0 0 0
  94088. - 0 0 0 0 0 0 6 6 6 10 10 10
  94089. - 14 14 14 22 22 22 30 30 30 38 38 38
  94090. - 50 50 50 62 62 62 74 74 74 90 90 90
  94091. -101 98 89 112 100 78 121 87 25 124 80 6
  94092. -137 92 6 152 99 6 152 99 6 152 99 6
  94093. -138 86 6 124 80 6 98 70 6 86 66 30
  94094. -101 98 89 82 82 82 58 58 58 46 46 46
  94095. - 38 38 38 34 34 34 34 34 34 34 34 34
  94096. - 34 34 34 34 34 34 34 34 34 34 34 34
  94097. - 34 34 34 34 34 34 38 38 38 42 42 42
  94098. - 54 54 54 82 82 82 94 86 76 91 60 6
  94099. -134 86 6 156 107 11 167 114 7 175 118 6
  94100. -175 118 6 167 114 7 152 99 6 121 87 25
  94101. -101 98 89 62 62 62 34 34 34 18 18 18
  94102. - 6 6 6 0 0 0 0 0 0 0 0 0
  94103. - 0 0 0 0 0 0 0 0 0 0 0 0
  94104. - 0 0 0 0 0 0 0 0 0 0 0 0
  94105. - 0 0 0 0 0 0 0 0 0 0 0 0
  94106. - 0 0 0 0 0 0 0 0 0 0 0 0
  94107. - 0 0 0 0 0 0 0 0 0 0 0 0
  94108. - 0 0 0 0 0 0 0 0 0 0 0 0
  94109. - 0 0 0 6 6 6 6 6 6 10 10 10
  94110. - 18 18 18 22 22 22 30 30 30 42 42 42
  94111. - 50 50 50 66 66 66 86 86 86 101 98 89
  94112. -106 86 58 98 70 6 104 69 6 104 69 6
  94113. -104 69 6 91 60 6 82 62 34 90 90 90
  94114. - 62 62 62 38 38 38 22 22 22 14 14 14
  94115. - 10 10 10 10 10 10 10 10 10 10 10 10
  94116. - 10 10 10 10 10 10 6 6 6 10 10 10
  94117. - 10 10 10 10 10 10 10 10 10 14 14 14
  94118. - 22 22 22 42 42 42 70 70 70 89 81 66
  94119. - 80 54 7 104 69 6 124 80 6 137 92 6
  94120. -134 86 6 116 81 8 100 82 52 86 86 86
  94121. - 58 58 58 30 30 30 14 14 14 6 6 6
  94122. - 0 0 0 0 0 0 0 0 0 0 0 0
  94123. - 0 0 0 0 0 0 0 0 0 0 0 0
  94124. - 0 0 0 0 0 0 0 0 0 0 0 0
  94125. - 0 0 0 0 0 0 0 0 0 0 0 0
  94126. - 0 0 0 0 0 0 0 0 0 0 0 0
  94127. - 0 0 0 0 0 0 0 0 0 0 0 0
  94128. - 0 0 0 0 0 0 0 0 0 0 0 0
  94129. - 0 0 0 0 0 0 0 0 0 0 0 0
  94130. - 0 0 0 6 6 6 10 10 10 14 14 14
  94131. - 18 18 18 26 26 26 38 38 38 54 54 54
  94132. - 70 70 70 86 86 86 94 86 76 89 81 66
  94133. - 89 81 66 86 86 86 74 74 74 50 50 50
  94134. - 30 30 30 14 14 14 6 6 6 0 0 0
  94135. - 0 0 0 0 0 0 0 0 0 0 0 0
  94136. - 0 0 0 0 0 0 0 0 0 0 0 0
  94137. - 0 0 0 0 0 0 0 0 0 0 0 0
  94138. - 6 6 6 18 18 18 34 34 34 58 58 58
  94139. - 82 82 82 89 81 66 89 81 66 89 81 66
  94140. - 94 86 66 94 86 76 74 74 74 50 50 50
  94141. - 26 26 26 14 14 14 6 6 6 0 0 0
  94142. - 0 0 0 0 0 0 0 0 0 0 0 0
  94143. - 0 0 0 0 0 0 0 0 0 0 0 0
  94144. - 0 0 0 0 0 0 0 0 0 0 0 0
  94145. - 0 0 0 0 0 0 0 0 0 0 0 0
  94146. - 0 0 0 0 0 0 0 0 0 0 0 0
  94147. - 0 0 0 0 0 0 0 0 0 0 0 0
  94148. - 0 0 0 0 0 0 0 0 0 0 0 0
  94149. - 0 0 0 0 0 0 0 0 0 0 0 0
  94150. - 0 0 0 0 0 0 0 0 0 0 0 0
  94151. - 6 6 6 6 6 6 14 14 14 18 18 18
  94152. - 30 30 30 38 38 38 46 46 46 54 54 54
  94153. - 50 50 50 42 42 42 30 30 30 18 18 18
  94154. - 10 10 10 0 0 0 0 0 0 0 0 0
  94155. - 0 0 0 0 0 0 0 0 0 0 0 0
  94156. - 0 0 0 0 0 0 0 0 0 0 0 0
  94157. - 0 0 0 0 0 0 0 0 0 0 0 0
  94158. - 0 0 0 6 6 6 14 14 14 26 26 26
  94159. - 38 38 38 50 50 50 58 58 58 58 58 58
  94160. - 54 54 54 42 42 42 30 30 30 18 18 18
  94161. - 10 10 10 0 0 0 0 0 0 0 0 0
  94162. - 0 0 0 0 0 0 0 0 0 0 0 0
  94163. - 0 0 0 0 0 0 0 0 0 0 0 0
  94164. - 0 0 0 0 0 0 0 0 0 0 0 0
  94165. - 0 0 0 0 0 0 0 0 0 0 0 0
  94166. - 0 0 0 0 0 0 0 0 0 0 0 0
  94167. - 0 0 0 0 0 0 0 0 0 0 0 0
  94168. - 0 0 0 0 0 0 0 0 0 0 0 0
  94169. - 0 0 0 0 0 0 0 0 0 0 0 0
  94170. - 0 0 0 0 0 0 0 0 0 0 0 0
  94171. - 0 0 0 0 0 0 0 0 0 6 6 6
  94172. - 6 6 6 10 10 10 14 14 14 18 18 18
  94173. - 18 18 18 14 14 14 10 10 10 6 6 6
  94174. - 0 0 0 0 0 0 0 0 0 0 0 0
  94175. - 0 0 0 0 0 0 0 0 0 0 0 0
  94176. - 0 0 0 0 0 0 0 0 0 0 0 0
  94177. - 0 0 0 0 0 0 0 0 0 0 0 0
  94178. - 0 0 0 0 0 0 0 0 0 6 6 6
  94179. - 14 14 14 18 18 18 22 22 22 22 22 22
  94180. - 18 18 18 14 14 14 10 10 10 6 6 6
  94181. - 0 0 0 0 0 0 0 0 0 0 0 0
  94182. - 0 0 0 0 0 0 0 0 0 0 0 0
  94183. - 0 0 0 0 0 0 0 0 0 0 0 0
  94184. - 0 0 0 0 0 0 0 0 0 0 0 0
  94185. - 0 0 0 0 0 0 0 0 0 0 0 0
  94186. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94187. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94188. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94189. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94190. +0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94193. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94194. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94195. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94196. +0 0 0 0 0 0 0 0 0
  94197. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94198. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94199. +0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 1 0
  94200. +0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94201. +0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94204. +0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0
  94205. +0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94206. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94207. +0 0 0 0 0 0 0 0 0
  94208. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94209. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
  94210. +10 15 3 2 3 1 12 18 4 42 61 14 19 27 6 11 16 4
  94211. +38 55 13 10 15 3 3 4 1 10 15 3 0 0 0 0 0 0
  94212. +0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 2 3 1
  94215. +12 18 4 1 1 0 23 34 8 31 45 11 10 15 3 32 47 11
  94216. +34 49 12 3 4 1 3 4 1 3 4 1 0 0 0 0 0 0
  94217. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94218. +0 0 0 0 0 0 0 0 0
  94219. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94220. +0 0 0 0 0 0 10 15 3 29 42 10 26 37 9 12 18 4
  94221. +55 80 19 81 118 28 55 80 19 92 132 31 106 153 36 69 100 23
  94222. +100 144 34 80 116 27 42 61 14 81 118 28 23 34 8 27 40 9
  94223. +15 21 5 0 0 0 0 0 0 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 1 1 0 29 42 10 15 21 5 50 72 17
  94226. +74 107 25 45 64 15 102 148 35 80 116 27 84 121 28 111 160 38
  94227. +69 100 23 65 94 22 81 118 28 29 42 10 17 25 6 29 42 10
  94228. +23 34 8 2 3 1 0 0 0 0 0 0 0 0 0 0 0 0
  94229. +0 0 0 0 0 0 0 0 0
  94230. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 4 1
  94231. +15 21 5 15 21 5 34 49 12 101 146 34 111 161 38 97 141 33
  94232. +97 141 33 119 172 41 117 170 40 116 167 40 118 170 40 118 171 40
  94233. +117 169 40 118 170 40 111 160 38 118 170 40 96 138 32 89 128 30
  94234. +81 118 28 11 16 4 10 15 3 1 1 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. +3 4 1 3 4 1 34 49 12 101 146 34 79 115 27 111 160 38
  94237. +114 165 39 113 163 39 118 170 40 117 169 40 118 171 40 117 169 40
  94238. +116 167 40 119 172 41 113 163 39 92 132 31 105 151 36 113 163 39
  94239. +75 109 26 19 27 6 16 23 5 11 16 4 0 1 0 0 0 0
  94240. +0 0 0 0 0 0 0 0 0
  94241. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 15 3
  94242. +80 116 27 106 153 36 105 151 36 114 165 39 118 170 40 118 171 40
  94243. +118 171 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94244. +117 169 40 117 169 40 117 170 40 117 169 40 118 170 40 118 170 40
  94245. +117 170 40 75 109 26 75 109 26 34 49 12 0 0 0 0 0 0
  94246. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 4 1
  94247. +64 92 22 65 94 22 100 144 34 118 171 40 118 170 40 117 169 40
  94248. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94249. +117 169 40 117 169 40 117 169 40 118 171 41 118 170 40 117 169 40
  94250. +109 158 37 105 151 36 104 150 35 47 69 16 0 0 0 0 0 0
  94251. +0 0 0 0 0 0 0 0 0
  94252. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94253. +42 61 14 115 167 39 118 170 40 117 169 40 117 169 40 117 169 40
  94254. +117 170 40 117 170 40 117 169 40 117 169 40 117 169 40 117 169 40
  94255. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94256. +117 169 40 117 169 40 118 170 40 96 138 32 17 25 6 0 0 0
  94257. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 47 69 16
  94258. +114 165 39 117 168 40 117 170 40 117 169 40 117 169 40 117 169 40
  94259. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94260. +117 169 40 117 169 40 118 170 40 117 169 40 117 169 40 117 169 40
  94261. +117 170 40 119 172 41 96 138 32 12 18 4 0 0 0 0 0 0
  94262. +0 0 0 0 0 0 0 0 0
  94263. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 15 3
  94264. +32 47 11 105 151 36 118 170 40 117 169 40 117 169 40 116 168 40
  94265. +109 157 37 111 160 38 117 169 40 118 171 40 117 169 40 117 169 40
  94266. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94267. +117 169 40 117 169 40 117 169 40 118 171 40 69 100 23 2 3 1
  94268. +0 0 0 0 0 0 0 0 0 0 0 0 19 27 6 101 146 34
  94269. +118 171 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94270. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 170 40
  94271. +118 171 40 115 166 39 107 154 36 111 161 38 117 169 40 117 169 40
  94272. +117 169 40 118 171 40 75 109 26 19 27 6 2 3 1 0 0 0
  94273. +0 0 0 0 0 0 0 0 0
  94274. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 16 23 5
  94275. +89 128 30 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94276. +111 160 38 92 132 31 79 115 27 96 138 32 115 166 39 119 171 41
  94277. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94278. +117 169 40 117 169 40 117 169 40 118 170 40 109 157 37 26 37 9
  94279. +0 0 0 0 0 0 0 0 0 0 0 0 64 92 22 118 171 40
  94280. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94281. +117 169 40 117 169 40 117 169 40 118 170 40 118 171 40 109 157 37
  94282. +89 128 30 81 118 28 100 144 34 115 166 39 117 169 40 117 169 40
  94283. +117 169 40 117 170 40 113 163 39 60 86 20 1 1 0 0 0 0
  94284. +0 0 0 0 0 0 0 0 0
  94285. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94286. +27 40 9 96 138 32 118 170 40 117 169 40 117 169 40 117 169 40
  94287. +117 170 40 117 169 40 101 146 34 67 96 23 55 80 19 84 121 28
  94288. +113 163 39 119 171 41 117 169 40 117 169 40 117 169 40 117 169 40
  94289. +117 169 40 117 169 40 117 169 40 117 169 40 119 171 41 65 94 22
  94290. +0 0 0 0 0 0 0 0 0 15 21 5 101 146 34 118 171 40
  94291. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94292. +117 169 40 118 170 40 118 171 40 104 150 35 69 100 23 53 76 18
  94293. +81 118 28 111 160 38 118 170 40 117 169 40 117 169 40 117 169 40
  94294. +117 169 40 114 165 39 69 100 23 10 15 3 0 0 0 0 0 0
  94295. +0 0 0 0 0 0 0 0 0
  94296. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
  94297. +31 45 11 77 111 26 117 169 40 117 169 40 117 169 40 117 169 40
  94298. +117 169 40 117 169 40 118 170 40 116 168 40 92 132 31 47 69 16
  94299. +38 55 13 81 118 28 113 163 39 119 171 41 117 169 40 117 169 40
  94300. +117 169 40 117 169 40 117 169 40 117 169 40 118 171 41 92 132 31
  94301. +10 15 3 0 0 0 0 0 0 36 52 12 115 166 39 117 169 40
  94302. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 118 170 40
  94303. +118 171 40 102 148 35 64 92 22 34 49 12 65 94 22 106 153 36
  94304. +118 171 40 117 170 40 117 169 40 117 169 40 117 169 40 117 169 40
  94305. +118 170 40 107 154 36 55 80 19 15 21 5 0 0 0 0 0 0
  94306. +0 0 0 0 0 0 0 0 0
  94307. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94308. +29 42 10 101 146 34 118 171 40 117 169 40 117 169 40 117 169 40
  94309. +117 169 40 117 169 40 117 169 40 117 169 40 118 171 40 113 163 39
  94310. +75 109 26 27 40 9 36 52 12 89 128 30 116 167 40 118 171 40
  94311. +117 169 40 117 169 40 117 169 40 117 169 40 118 170 40 104 150 35
  94312. +16 23 5 0 0 0 0 0 0 53 76 18 118 171 40 117 169 40
  94313. +117 169 40 117 169 40 117 169 40 117 169 40 119 171 41 109 157 37
  94314. +67 96 23 23 34 8 42 61 14 96 138 32 118 170 40 118 170 40
  94315. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94316. +117 169 40 117 169 40 74 107 25 10 15 3 0 0 0 0 0 0
  94317. +0 0 0 0 0 0 0 0 0
  94318. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94319. +0 0 0 31 45 11 101 146 34 118 170 40 117 169 40 117 169 40
  94320. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94321. +119 171 41 102 148 35 47 69 16 14 20 5 50 72 17 102 148 35
  94322. +118 171 40 117 169 40 117 169 40 117 169 40 118 170 40 102 148 35
  94323. +15 21 5 0 0 0 0 0 0 50 72 17 118 170 40 117 169 40
  94324. +117 169 40 117 169 40 118 170 40 116 167 40 84 121 28 27 40 9
  94325. +19 27 6 74 107 25 114 165 39 118 171 40 117 169 40 117 169 40
  94326. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94327. +117 169 40 75 109 26 10 15 4 0 0 0 0 0 0 0 0 0
  94328. +0 0 0 0 0 0 0 0 0
  94329. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94330. +0 0 0 38 55 13 102 148 35 118 171 40 117 169 40 117 169 40
  94331. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94332. +117 169 40 118 170 40 115 167 39 77 111 26 17 25 6 19 27 6
  94333. +77 111 26 115 166 39 118 170 40 117 169 40 119 172 41 81 118 28
  94334. +3 4 1 0 0 0 0 0 0 27 40 9 111 160 38 118 170 40
  94335. +117 169 40 118 171 40 105 151 36 50 72 17 10 15 3 38 55 13
  94336. +100 144 34 118 171 40 117 169 40 117 169 40 117 169 40 117 169 40
  94337. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94338. +117 169 40 79 115 27 15 21 5 0 0 0 0 0 0 0 0 0
  94339. +0 0 0 0 0 0 0 0 0
  94340. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94341. +0 0 0 10 15 3 64 92 22 111 160 38 117 169 40 117 169 40
  94342. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94343. +117 169 40 117 169 40 117 169 40 118 171 40 96 138 32 32 47 11
  94344. +3 4 1 50 72 17 107 154 36 120 173 41 105 151 36 31 45 11
  94345. +0 0 0 0 0 0 0 0 0 3 4 1 65 94 22 117 169 40
  94346. +118 170 40 89 128 30 26 37 9 3 4 1 60 86 20 111 161 38
  94347. +118 171 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94348. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94349. +97 141 33 36 52 12 1 1 0 0 0 0 0 0 0 0 0 0
  94350. +0 0 0 0 0 0 0 0 0
  94351. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94352. +0 0 0 0 0 0 14 20 5 75 109 26 117 168 40 117 169 40
  94353. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94354. +117 169 40 117 169 40 117 169 40 117 169 40 118 171 40 107 154 36
  94355. +45 64 15 2 3 1 31 45 11 75 109 26 32 47 11 0 1 0
  94356. +0 0 0 0 0 0 0 0 0 0 0 0 10 15 3 55 80 19
  94357. +65 94 22 11 16 4 11 16 4 75 109 26 116 168 40 118 170 40
  94358. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94359. +117 169 40 117 169 40 117 169 40 117 169 40 118 170 40 107 154 36
  94360. +47 69 16 3 4 1 0 0 0 0 0 0 0 0 0 0 0 0
  94361. +0 0 0 0 0 0 0 0 0
  94362. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94363. +0 0 0 0 0 0 12 18 4 69 100 23 111 161 38 118 171 40
  94364. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94365. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 118 170 40
  94366. +111 160 38 50 72 17 2 3 1 2 3 1 0 0 0 0 0 0
  94367. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
  94368. +1 1 0 12 18 4 81 118 28 118 170 40 117 169 40 117 169 40
  94369. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94370. +117 169 40 117 169 40 117 169 40 117 170 40 118 171 40 101 146 34
  94371. +42 61 14 2 3 1 0 0 0 0 0 0 0 0 0 0 0 0
  94372. +0 0 0 0 0 0 0 0 0
  94373. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94374. +0 0 0 0 0 0 0 0 0 3 4 1 36 52 12 89 128 30
  94375. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94376. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94377. +118 171 41 101 146 34 14 20 5 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 47 69 16 118 170 40 117 169 40 117 169 40 117 169 40
  94380. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94381. +117 169 40 117 169 40 117 170 40 111 160 38 69 100 23 19 27 6
  94382. +0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94383. +0 0 0 0 0 0 0 0 0
  94384. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94385. +0 0 0 0 0 0 0 0 0 0 0 0 11 16 4 69 100 23
  94386. +115 167 39 119 172 41 117 169 40 117 169 40 117 169 40 117 169 40
  94387. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94388. +119 172 41 75 109 26 3 4 1 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 23 34 8 106 153 36 118 170 40 117 169 40 117 169 40
  94391. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94392. +117 169 40 118 170 40 119 172 41 105 151 36 42 61 14 2 3 1
  94393. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94394. +0 0 0 0 0 0 0 0 0
  94395. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94396. +0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 15 21 5
  94397. +45 64 15 80 116 27 114 165 39 118 170 40 117 169 40 117 169 40
  94398. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 119 172 41
  94399. +97 141 33 20 30 7 0 0 0 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 1 1 0 53 76 18 114 165 39 118 171 40 117 169 40
  94402. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94403. +118 171 40 104 150 35 64 92 22 31 45 11 10 15 3 0 0 0
  94404. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94405. +0 0 0 0 0 0 0 0 0
  94406. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94407. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94408. +0 0 0 36 52 12 97 141 33 109 158 37 113 163 39 116 168 40
  94409. +117 169 40 117 170 40 118 170 40 119 172 41 115 167 39 84 121 28
  94410. +23 34 8 0 0 0 0 0 0 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 3 4 1 50 72 17 102 148 35 118 171 40
  94413. +119 171 41 118 170 40 117 169 40 117 169 40 115 166 39 111 161 38
  94414. +109 157 37 79 115 27 12 18 4 0 0 0 0 0 0 0 0 0
  94415. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94416. +0 0 0 0 0 0 0 0 0
  94417. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94418. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94419. +0 0 0 3 4 1 15 21 5 23 34 8 45 64 15 106 153 36
  94420. +116 167 40 111 160 38 101 146 34 79 115 27 42 61 14 10 15 3
  94421. +0 0 0 0 0 0 0 0 0 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 0 0 0 1 1 0 20 30 7 60 86 20
  94424. +89 128 30 106 153 36 113 163 39 117 169 40 84 121 28 29 42 10
  94425. +19 27 6 10 15 3 2 3 1 0 0 0 0 0 0 0 0 0
  94426. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94427. +0 0 0 0 0 0 0 0 0
  94428. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94429. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94430. +0 0 0 0 0 0 0 0 0 0 0 0 16 23 5 38 55 13
  94431. +36 52 12 26 37 9 12 18 4 2 3 1 0 0 0 0 0 0
  94432. +0 0 0 0 0 0 0 0 0 1 0 0 19 2 7 52 5 18
  94433. +78 7 27 88 8 31 81 7 29 56 5 19 25 2 9 3 0 1
  94434. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94435. +3 4 1 19 27 6 31 45 11 38 55 13 32 47 11 3 4 1
  94436. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94437. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94438. +0 0 0 0 0 0 0 0 0
  94439. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94440. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94441. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 1
  94442. +9 0 3 12 1 4 9 0 3 4 0 1 0 0 0 0 0 0
  94443. +0 0 0 0 0 0 28 3 10 99 9 35 156 14 55 182 16 64
  94444. +189 17 66 190 17 67 189 17 66 184 17 65 166 15 58 118 13 41
  94445. +45 4 16 3 0 1 0 0 0 0 0 0 0 0 0 0 0 0
  94446. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94447. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94448. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94449. +0 0 0 0 0 0 0 0 0
  94450. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94451. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94452. +0 0 0 0 0 0 11 1 4 52 5 18 101 9 35 134 12 47
  94453. +151 14 53 154 14 54 151 14 53 113 10 40 11 1 4 0 0 0
  94454. +3 0 1 67 6 24 159 14 56 190 17 67 190 17 67 188 17 66
  94455. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 191 17 67
  94456. +174 16 61 101 9 35 14 1 5 0 0 0 35 3 12 108 10 38
  94457. +122 11 43 122 11 43 112 10 39 87 8 30 50 5 17 13 1 5
  94458. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94459. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94460. +0 0 0 0 0 0 0 0 0
  94461. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94462. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94463. +3 0 1 56 5 19 141 13 49 182 16 64 191 17 67 191 17 67
  94464. +190 17 67 190 17 67 191 17 67 113 10 40 3 0 1 1 0 0
  94465. +79 7 28 180 16 63 190 17 67 188 17 66 188 17 66 188 17 66
  94466. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94467. +189 17 66 188 17 66 122 11 43 11 1 4 41 4 14 176 16 62
  94468. +191 17 67 191 17 67 191 17 67 190 17 67 181 16 63 146 13 51
  94469. +75 7 26 10 1 4 0 0 0 0 0 0 0 0 0 0 0 0
  94470. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94471. +0 0 0 0 0 0 0 0 0
  94472. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94473. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 1 2
  94474. +90 8 32 178 16 62 191 17 67 188 17 66 188 17 66 188 17 66
  94475. +188 17 66 190 17 67 141 13 49 22 2 8 0 0 0 41 4 14
  94476. +173 16 61 190 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  94477. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94478. +188 17 66 188 17 66 188 17 66 88 8 31 1 0 0 89 8 31
  94479. +185 17 65 189 17 66 188 17 66 188 17 66 189 17 66 191 17 67
  94480. +186 17 65 124 11 43 25 2 9 0 0 0 0 0 0 0 0 0
  94481. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94482. +0 0 0 0 0 0 0 0 0
  94483. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94484. +0 0 0 0 0 0 0 0 0 0 0 0 2 0 1 89 8 31
  94485. +184 17 65 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94486. +190 17 67 151 14 53 34 3 12 0 0 0 0 0 0 79 7 28
  94487. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94488. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94489. +188 17 66 188 17 66 191 17 67 146 13 51 9 1 3 7 1 2
  94490. +108 10 38 187 17 66 189 17 66 188 17 66 188 17 66 188 17 66
  94491. +188 17 66 190 17 67 141 13 49 22 2 8 0 0 0 0 0 0
  94492. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94493. +0 0 0 0 0 0 0 0 0
  94494. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94495. +0 0 0 0 0 0 0 0 0 0 0 0 52 5 18 176 16 62
  94496. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  94497. +151 14 53 38 3 13 0 0 0 0 0 0 0 0 0 50 5 17
  94498. +180 16 63 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94499. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94500. +188 17 66 188 17 66 191 17 67 141 13 49 7 1 3 0 0 0
  94501. +11 1 4 112 10 39 187 17 66 189 17 66 188 17 66 188 17 66
  94502. +188 17 66 188 17 66 190 17 67 113 10 40 5 0 2 0 0 0
  94503. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94504. +0 0 0 0 0 0 0 0 0
  94505. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94506. +0 0 0 0 0 0 0 0 0 7 1 3 132 12 46 191 17 67
  94507. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 146 13 51
  94508. +35 3 12 0 0 0 0 0 0 0 0 0 0 0 0 5 0 2
  94509. +101 9 35 185 17 65 190 17 67 188 17 66 188 17 66 188 17 66
  94510. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94511. +188 17 66 190 17 67 180 16 63 67 6 24 0 0 0 0 0 0
  94512. +0 0 0 11 1 4 108 10 38 186 17 65 189 17 66 188 17 66
  94513. +188 17 66 188 17 66 189 17 66 180 16 63 56 5 19 0 0 0
  94514. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94515. +0 0 0 0 0 0 0 0 0
  94516. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94517. +0 0 0 0 0 0 0 0 0 44 4 15 177 16 62 189 17 66
  94518. +188 17 66 188 17 66 189 17 66 189 17 66 134 12 47 28 3 10
  94519. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94520. +8 1 3 79 7 28 159 14 56 188 17 66 191 17 67 190 17 67
  94521. +189 17 66 189 17 66 189 17 66 189 17 66 190 17 67 191 17 67
  94522. +188 17 66 158 14 55 72 7 25 4 0 1 0 0 0 0 0 0
  94523. +0 0 0 0 0 0 8 1 3 95 9 33 182 16 64 189 17 67
  94524. +188 17 66 188 17 66 188 17 66 191 17 67 122 11 43 3 0 1
  94525. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94526. +0 0 0 0 0 0 0 0 0
  94527. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94528. +0 0 0 0 0 0 0 0 0 88 8 31 190 17 67 188 17 66
  94529. +188 17 66 189 17 66 185 17 65 113 10 40 18 2 6 0 0 0
  94530. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94531. +0 0 0 1 0 0 24 2 8 77 7 27 124 11 43 154 14 54
  94532. +168 15 59 173 16 61 173 16 61 168 15 59 154 14 54 124 11 43
  94533. +77 7 27 22 2 8 0 0 0 0 0 0 0 0 0 0 0 0
  94534. +0 0 0 0 0 0 0 0 0 5 0 2 77 7 27 173 16 61
  94535. +190 17 67 188 17 66 188 17 66 190 17 67 164 15 57 23 2 8
  94536. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94537. +0 0 0 0 0 0 0 0 0
  94538. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94539. +0 0 0 0 0 0 1 0 0 118 13 41 191 17 67 188 17 66
  94540. +190 17 67 174 16 61 87 8 30 8 1 3 0 0 0 0 0 0
  94541. +0 0 0 0 0 0 10 1 4 29 3 10 40 4 14 36 3 13
  94542. +18 2 6 2 0 1 0 0 0 0 0 0 3 0 1 14 1 5
  94543. +26 2 9 33 3 11 32 3 11 25 2 9 13 1 5 3 0 1
  94544. +0 0 0 14 1 5 56 5 19 95 9 33 109 10 38 101 9 35
  94545. +77 7 27 35 3 12 5 0 2 0 0 0 1 0 0 56 5 19
  94546. +156 14 55 190 17 67 188 17 66 188 17 66 182 16 64 50 5 17
  94547. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94548. +0 0 0 0 0 0 0 0 0
  94549. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94550. +0 0 0 0 0 0 5 0 2 134 12 47 191 17 67 189 17 66
  94551. +151 14 53 52 5 18 2 0 1 0 0 0 0 0 0 1 0 0
  94552. +28 3 10 90 8 32 146 13 51 170 15 60 178 16 62 174 16 61
  94553. +158 14 55 112 10 39 40 4 14 1 0 0 0 0 0 0 0 0
  94554. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 1
  94555. +56 5 19 146 13 51 183 17 64 191 17 67 191 17 67 191 17 67
  94556. +188 17 66 173 16 61 122 11 43 41 4 14 1 0 0 0 0 0
  94557. +30 3 10 124 11 43 185 17 65 190 17 67 187 17 66 67 6 24
  94558. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94559. +0 0 0 0 0 0 0 0 0
  94560. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94561. +0 0 0 0 0 0 6 1 2 134 12 47 168 15 59 99 9 35
  94562. +21 2 7 0 0 0 0 0 0 0 0 0 6 1 2 77 7 27
  94563. +162 15 57 190 17 67 191 17 67 189 17 66 189 17 66 189 17 66
  94564. +190 17 67 191 17 67 169 15 59 75 7 26 3 0 1 0 0 0
  94565. +0 0 0 0 0 0 0 0 0 0 0 0 2 0 1 79 7 28
  94566. +178 16 62 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  94567. +188 17 66 189 17 66 191 17 67 170 15 60 79 7 28 5 0 2
  94568. +0 0 0 10 1 3 78 7 27 159 14 56 188 17 66 75 7 26
  94569. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94570. +0 0 0 0 0 0 0 0 0
  94571. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94572. +0 0 0 0 0 0 1 0 0 35 3 12 29 3 10 2 0 1
  94573. +0 0 0 0 0 0 0 0 0 9 1 3 101 9 35 183 17 64
  94574. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94575. +188 17 66 188 17 66 190 17 67 178 16 63 67 6 23 0 0 0
  94576. +0 0 0 0 0 0 0 0 0 0 0 0 52 5 18 174 16 61
  94577. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94578. +188 17 66 188 17 66 188 17 66 190 17 67 182 16 64 89 8 31
  94579. +4 0 1 0 0 0 0 0 0 25 2 9 73 7 26 31 3 11
  94580. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94581. +0 0 0 0 0 0 0 0 0
  94582. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94583. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94584. +0 0 0 0 0 0 4 0 1 98 9 34 187 17 66 189 17 66
  94585. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94586. +188 17 66 188 17 66 188 17 66 190 17 67 158 14 55 25 2 9
  94587. +0 0 0 0 0 0 0 0 0 8 1 3 134 12 47 191 17 67
  94588. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94589. +188 17 66 188 17 66 188 17 66 188 17 66 189 17 66 180 16 63
  94590. +68 6 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94591. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94592. +0 0 0 0 0 0 0 0 0
  94593. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94594. +0 0 0 6 1 2 19 2 7 3 0 1 0 0 0 0 0 0
  94595. +0 0 0 0 0 0 65 6 23 180 16 63 189 17 66 188 17 66
  94596. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94597. +188 17 66 188 17 66 188 17 66 188 17 66 189 17 66 83 8 29
  94598. +0 0 0 0 0 0 0 0 0 41 4 14 177 16 62 189 17 66
  94599. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94600. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  94601. +159 14 56 28 3 10 0 0 0 0 0 0 0 0 0 23 2 8
  94602. +41 4 14 5 0 2 0 0 0 0 0 0 0 0 0 0 0 0
  94603. +0 0 0 0 0 0 0 0 0
  94604. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94605. +23 2 8 113 10 40 159 14 56 65 6 23 0 0 0 0 0 0
  94606. +0 0 0 16 1 6 146 13 51 191 17 67 188 17 66 188 17 66
  94607. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94608. +188 17 66 188 17 66 188 17 66 188 17 66 191 17 67 132 12 46
  94609. +5 0 2 0 0 0 0 0 0 77 7 27 189 17 66 188 17 66
  94610. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94611. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94612. +190 17 67 98 9 34 0 0 0 0 0 0 12 1 4 134 12 47
  94613. +178 16 63 108 10 38 16 1 6 0 0 0 0 0 0 0 0 0
  94614. +0 0 0 0 0 0 0 0 0
  94615. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 30 3 10
  94616. +141 13 49 190 17 67 191 17 67 134 12 47 6 1 2 0 0 0
  94617. +0 0 0 68 6 24 186 17 65 188 17 66 188 17 66 188 17 66
  94618. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94619. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 156 14 55
  94620. +14 1 5 0 0 0 0 0 0 98 9 34 191 17 67 188 17 66
  94621. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94622. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94623. +190 17 67 156 14 55 19 2 7 0 0 0 47 4 16 181 16 63
  94624. +190 17 67 189 17 66 126 14 44 17 2 6 0 0 0 0 0 0
  94625. +0 0 0 0 0 0 0 0 0
  94626. +0 0 0 0 0 0 0 0 0 0 0 0 16 1 6 134 12 47
  94627. +191 17 67 188 17 66 190 17 67 162 15 57 19 2 7 0 0 0
  94628. +3 0 1 123 11 43 191 17 67 188 17 66 188 17 66 188 17 66
  94629. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94630. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 163 15 57
  94631. +20 2 7 0 0 0 0 0 0 101 9 35 191 17 67 188 17 66
  94632. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94633. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94634. +188 17 66 182 16 64 52 5 18 0 0 0 73 7 26 188 17 66
  94635. +188 17 66 188 17 66 189 17 66 109 10 38 5 0 2 0 0 0
  94636. +0 0 0 0 0 0 0 0 0
  94637. +0 0 0 0 0 0 0 0 0 0 0 0 95 9 33 189 17 66
  94638. +188 17 66 188 17 66 189 17 66 171 15 60 29 3 10 0 0 0
  94639. +16 1 6 156 14 55 190 17 67 188 17 66 188 17 66 188 17 66
  94640. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94641. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 158 14 55
  94642. +17 2 6 0 0 0 0 0 0 85 8 30 190 17 67 188 17 66
  94643. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94644. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94645. +188 17 66 189 17 66 81 7 29 0 0 0 85 8 30 190 17 67
  94646. +188 17 66 188 17 66 189 17 66 180 16 63 56 5 19 0 0 0
  94647. +0 0 0 0 0 0 0 0 0
  94648. +0 0 0 0 0 0 0 0 0 25 2 9 162 15 57 190 17 67
  94649. +188 17 66 188 17 66 189 17 66 173 16 61 31 3 11 0 0 0
  94650. +30 3 10 171 15 60 189 17 66 188 17 66 188 17 66 188 17 66
  94651. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94652. +188 17 66 188 17 66 188 17 66 188 17 66 191 17 67 141 13 49
  94653. +7 1 2 0 0 0 0 0 0 56 5 19 183 17 64 188 17 66
  94654. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94655. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94656. +188 17 66 191 17 67 98 9 34 0 0 0 88 8 31 190 17 67
  94657. +188 17 66 188 17 66 188 17 66 191 17 67 124 11 43 5 0 2
  94658. +0 0 0 0 0 0 0 0 0
  94659. +0 0 0 0 0 0 0 0 0 68 6 24 187 17 66 188 17 66
  94660. +188 17 66 188 17 66 189 17 66 170 15 60 28 3 10 0 0 0
  94661. +34 3 12 174 16 61 189 17 66 188 17 66 188 17 66 188 17 66
  94662. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94663. +188 17 66 188 17 66 188 17 66 188 17 66 191 17 67 101 9 35
  94664. +0 0 0 0 0 0 0 0 0 21 2 7 159 14 56 190 17 67
  94665. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94666. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94667. +188 17 66 191 17 67 98 9 34 0 0 0 81 7 29 189 17 66
  94668. +188 17 66 188 17 66 188 17 66 189 17 66 168 15 59 28 3 10
  94669. +0 0 0 0 0 0 0 0 0
  94670. +0 0 0 0 0 0 0 0 0 109 10 38 191 17 67 188 17 66
  94671. +188 17 66 188 17 66 190 17 67 163 15 57 21 2 7 0 0 0
  94672. +26 2 9 168 15 59 189 17 66 188 17 66 188 17 66 188 17 66
  94673. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94674. +188 17 66 188 17 66 188 17 66 189 17 66 180 16 63 47 4 16
  94675. +0 0 0 0 0 0 0 0 0 0 0 0 108 10 38 190 17 67
  94676. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94677. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94678. +188 17 66 189 17 66 78 7 27 0 0 0 68 6 24 187 17 66
  94679. +188 17 66 188 17 66 188 17 66 188 17 66 183 17 64 56 5 19
  94680. +0 0 0 0 0 0 0 0 0
  94681. +0 0 0 0 0 0 3 0 1 131 12 46 191 17 67 188 17 66
  94682. +188 17 66 188 17 66 190 17 67 151 14 53 12 1 4 0 0 0
  94683. +11 1 4 146 13 51 190 17 67 188 17 66 188 17 66 188 17 66
  94684. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94685. +188 17 66 188 17 66 188 17 66 191 17 67 126 14 44 7 1 2
  94686. +0 0 0 0 0 0 0 0 0 0 0 0 32 3 11 164 15 58
  94687. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94688. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94689. +189 17 66 178 16 62 44 4 15 0 0 0 50 5 17 182 16 64
  94690. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 72 7 25
  94691. +0 0 0 0 0 0 0 0 0
  94692. +0 0 0 0 0 0 5 0 2 134 12 47 191 17 67 188 17 66
  94693. +188 17 66 188 17 66 191 17 67 131 12 46 3 0 1 0 0 0
  94694. +0 0 0 101 9 35 190 17 67 188 17 66 188 17 66 188 17 66
  94695. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94696. +188 17 66 188 17 66 190 17 67 170 15 60 44 4 15 0 0 0
  94697. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 77 7 27
  94698. +183 17 64 189 17 66 188 17 66 188 17 66 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. +191 17 67 134 12 47 9 1 3 0 0 0 31 3 11 171 15 60
  94701. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 72 7 25
  94702. +0 0 0 0 0 0 0 0 0
  94703. +0 0 0 0 0 0 2 0 1 124 11 43 191 17 67 188 17 66
  94704. +188 17 66 188 17 66 191 17 67 101 9 35 0 0 0 0 0 0
  94705. +0 0 0 35 3 12 168 15 59 190 17 67 188 17 66 188 17 66
  94706. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94707. +188 17 66 189 17 66 182 16 64 77 7 27 0 0 0 0 0 0
  94708. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 1 2
  94709. +99 9 35 185 17 65 189 17 66 188 17 66 188 17 66 188 17 66
  94710. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 189 17 66
  94711. +177 16 62 56 5 19 0 0 0 0 0 0 13 1 5 151 14 53
  94712. +190 17 67 188 17 66 188 17 66 188 17 66 185 17 65 56 5 19
  94713. +0 0 0 0 0 0 0 0 0
  94714. +0 0 0 0 0 0 0 0 0 99 9 35 191 17 67 188 17 66
  94715. +188 17 66 188 17 66 186 17 65 65 6 23 0 0 0 0 0 0
  94716. +0 0 0 0 0 0 79 7 28 182 16 64 190 17 67 188 17 66
  94717. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94718. +191 17 67 177 16 62 83 8 29 4 0 1 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. +8 1 3 89 8 31 175 16 62 191 17 67 189 17 66 188 17 66
  94721. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 181 16 63
  94722. +85 8 30 3 0 1 0 0 0 0 0 0 1 0 0 118 13 41
  94723. +191 17 67 188 17 66 188 17 66 189 17 66 173 16 61 34 3 12
  94724. +0 0 0 0 0 0 0 0 0
  94725. +0 0 0 0 0 0 0 0 0 56 5 19 183 17 64 188 17 66
  94726. +188 17 66 189 17 66 169 15 59 30 3 10 0 0 0 0 0 0
  94727. +0 0 0 0 0 0 5 0 2 83 8 29 173 16 61 191 17 67
  94728. +190 17 67 189 17 66 189 17 66 190 17 67 191 17 67 187 17 66
  94729. +151 14 53 56 5 19 3 0 1 0 0 0 16 1 6 50 5 17
  94730. +79 7 28 95 9 33 95 9 33 75 7 26 41 4 14 10 1 4
  94731. +0 0 0 2 0 1 50 5 17 132 12 46 178 16 62 190 17 67
  94732. +191 17 67 191 17 67 191 17 67 186 17 65 154 14 54 68 6 24
  94733. +4 0 1 0 0 0 0 0 0 0 0 0 0 0 0 72 7 25
  94734. +187 17 66 188 17 66 188 17 66 191 17 67 141 13 49 9 1 3
  94735. +0 0 0 0 0 0 0 0 0
  94736. +0 0 0 0 0 0 0 0 0 14 1 5 151 14 53 190 17 67
  94737. +188 17 66 191 17 67 131 12 46 5 0 2 0 0 0 0 0 0
  94738. +0 0 0 0 0 0 0 0 0 2 0 1 44 4 15 113 10 40
  94739. +156 14 55 173 16 61 174 16 61 164 15 58 134 12 47 77 7 27
  94740. +18 2 6 0 0 0 16 1 6 85 8 30 151 14 53 182 16 64
  94741. +189 17 66 191 17 67 190 17 67 188 17 66 177 16 62 141 13 49
  94742. +68 6 24 8 1 3 0 0 0 8 1 3 44 4 15 88 8 31
  94743. +113 10 40 122 11 43 108 10 38 67 6 24 20 2 7 0 0 0
  94744. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 28 3 10
  94745. +166 15 58 190 17 67 188 17 66 187 17 66 79 7 28 0 0 0
  94746. +0 0 0 0 0 0 0 0 0
  94747. +0 0 0 0 0 0 0 0 0 0 0 0 73 7 26 185 17 65
  94748. +189 17 66 184 17 65 65 6 23 0 0 0 0 0 0 0 0 0
  94749. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 1
  94750. +17 2 6 32 3 11 34 3 12 22 2 8 6 1 2 0 0 0
  94751. +0 0 0 38 3 13 141 13 49 188 17 66 190 17 67 188 17 66
  94752. +188 17 66 188 17 66 188 17 66 188 17 66 189 17 66 191 17 67
  94753. +184 17 65 122 11 43 21 2 7 0 0 0 0 0 0 0 0 0
  94754. +0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94755. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
  94756. +108 10 38 191 17 67 191 17 67 141 13 49 16 1 6 0 0 0
  94757. +0 0 0 0 0 0 0 0 0
  94758. +0 0 0 0 0 0 0 0 0 0 0 0 8 1 3 112 10 39
  94759. +186 17 65 124 11 43 10 1 4 0 0 0 0 0 0 0 0 0
  94760. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94761. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94762. +36 3 13 156 14 55 191 17 67 188 17 66 188 17 66 188 17 66
  94763. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94764. +189 17 66 190 17 67 134 12 47 18 2 6 0 0 0 0 0 0
  94765. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94766. +0 0 0 7 1 2 41 4 14 75 7 26 66 5 23 19 2 7
  94767. +26 2 9 144 13 50 154 14 54 40 4 14 0 0 0 0 0 0
  94768. +0 0 0 0 0 0 0 0 0
  94769. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 13 1 5
  94770. +56 5 19 19 2 7 0 0 0 7 1 2 29 3 10 35 3 12
  94771. +19 2 7 2 0 1 0 0 0 0 0 0 0 0 0 0 0 0
  94772. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 13 1 5
  94773. +134 12 47 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  94774. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94775. +188 17 66 188 17 66 189 17 67 108 10 38 3 0 1 0 0 0
  94776. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
  94777. +40 4 14 124 11 43 177 16 62 188 17 66 187 17 66 144 13 50
  94778. +24 2 8 17 2 6 22 2 8 0 0 0 0 0 0 0 0 0
  94779. +0 0 0 0 0 0 0 0 0
  94780. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94781. +0 0 0 0 0 0 19 2 7 122 11 43 171 15 60 175 16 62
  94782. +159 14 56 112 10 39 40 4 14 2 0 1 0 0 0 0 0 0
  94783. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 72 7 25
  94784. +186 17 65 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94785. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94786. +188 17 66 188 17 66 189 17 66 174 16 61 41 4 14 0 0 0
  94787. +0 0 0 0 0 0 0 0 0 0 0 0 3 0 1 72 7 25
  94788. +168 15 59 191 17 67 189 17 66 188 17 66 188 17 66 190 17 67
  94789. +95 9 33 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
  94791. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94792. +0 0 0 0 0 0 95 9 33 191 17 67 189 17 66 189 17 66
  94793. +190 17 67 191 17 67 171 15 60 90 8 32 12 1 4 0 0 0
  94794. +0 0 0 0 0 0 0 0 0 0 0 0 5 0 2 132 12 46
  94795. +191 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94796. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94797. +188 17 66 188 17 66 188 17 66 190 17 67 98 9 34 0 0 0
  94798. +0 0 0 0 0 0 0 0 0 5 0 2 88 8 31 180 16 63
  94799. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 191 17 67
  94800. +146 13 51 11 1 4 0 0 0 0 0 0 0 0 0 0 0 0
  94801. +0 0 0 0 0 0 0 0 0
  94802. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94803. +0 0 0 9 1 3 144 13 50 191 17 67 188 17 66 188 17 66
  94804. +188 17 66 188 17 66 189 17 66 187 17 66 123 11 43 20 2 7
  94805. +0 0 0 0 0 0 0 0 0 0 0 0 21 2 7 163 15 57
  94806. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94807. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94808. +188 17 66 188 17 66 188 17 66 191 17 67 134 12 47 5 0 2
  94809. +0 0 0 0 0 0 3 0 1 88 8 31 182 16 64 189 17 66
  94810. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 189 17 66
  94811. +171 15 60 31 3 11 0 0 0 0 0 0 0 0 0 0 0 0
  94812. +0 0 0 0 0 0 0 0 0
  94813. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94814. +0 0 0 20 2 7 162 15 57 190 17 67 188 17 66 188 17 66
  94815. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 132 12 46
  94816. +20 2 7 0 0 0 0 0 0 0 0 0 32 3 11 173 16 61
  94817. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94818. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94819. +188 17 66 188 17 66 188 17 66 190 17 67 151 14 53 12 1 4
  94820. +0 0 0 0 0 0 72 7 25 180 16 63 189 17 66 188 17 66
  94821. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94822. +181 16 63 47 4 16 0 0 0 0 0 0 0 0 0 0 0 0
  94823. +0 0 0 0 0 0 0 0 0
  94824. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94825. +0 0 0 21 2 7 163 15 57 190 17 67 188 17 66 188 17 66
  94826. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  94827. +122 11 43 9 1 3 0 0 0 0 0 0 30 3 10 171 15 60
  94828. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94829. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94830. +188 17 66 188 17 66 188 17 66 190 17 67 146 13 51 10 1 4
  94831. +0 0 0 38 3 13 166 15 58 190 17 67 188 17 66 188 17 66
  94832. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94833. +183 17 64 52 5 18 0 0 0 0 0 0 0 0 0 0 0 0
  94834. +0 0 0 0 0 0 0 0 0
  94835. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94836. +0 0 0 13 1 5 154 14 54 190 17 67 188 17 66 188 17 66
  94837. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94838. +186 17 65 79 7 28 0 0 0 0 0 0 14 1 5 156 14 54
  94839. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94840. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94841. +188 17 66 188 17 66 188 17 66 191 17 67 124 11 43 2 0 1
  94842. +5 0 2 122 11 43 191 17 67 188 17 66 188 17 66 188 17 66
  94843. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94844. +182 16 64 47 4 16 0 0 0 0 0 0 0 0 0 0 0 0
  94845. +0 0 0 0 0 0 0 0 0
  94846. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94847. +0 0 0 3 0 1 126 14 44 191 17 67 188 17 66 188 17 66
  94848. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94849. +190 17 67 158 14 55 23 2 8 0 0 0 1 0 0 113 10 40
  94850. +191 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94851. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94852. +188 17 66 188 17 66 188 17 66 188 17 66 78 7 27 0 0 0
  94853. +47 4 16 177 16 62 189 17 66 188 17 66 188 17 66 188 17 66
  94854. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 189 17 66
  94855. +173 16 61 34 3 12 0 0 0 0 0 0 0 0 0 0 0 0
  94856. +0 0 0 0 0 0 0 0 0
  94857. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94858. +0 0 0 0 0 0 85 8 30 189 17 66 188 17 66 188 17 66
  94859. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94860. +188 17 66 188 17 66 79 7 28 0 0 0 0 0 0 47 4 16
  94861. +175 16 62 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94862. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94863. +188 17 66 188 17 66 190 17 67 156 14 55 22 2 8 0 0 0
  94864. +109 10 38 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  94865. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  94866. +151 14 53 13 1 5 0 0 0 0 0 0 0 0 0 0 0 0
  94867. +0 0 0 0 0 0 0 0 0
  94868. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94869. +0 0 0 0 0 0 35 3 12 173 16 61 189 17 66 188 17 66
  94870. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94871. +188 17 66 191 17 67 134 12 47 7 1 2 0 0 0 3 0 1
  94872. +99 9 35 188 17 66 189 17 66 188 17 66 188 17 66 188 17 66
  94873. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94874. +188 17 66 189 17 66 181 16 63 68 6 24 0 0 0 18 2 6
  94875. +156 14 55 190 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  94876. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  94877. +101 9 35 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94878. +0 0 0 0 0 0 0 0 0
  94879. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94880. +0 0 0 0 0 0 3 0 1 118 13 41 191 17 67 188 17 66
  94881. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94882. +188 17 66 189 17 66 168 15 59 28 3 10 0 0 0 0 0 0
  94883. +12 1 4 113 10 40 187 17 66 189 17 67 188 17 66 188 17 66
  94884. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94885. +190 17 67 180 16 63 88 8 31 4 0 1 0 0 0 47 4 16
  94886. +180 16 63 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94887. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 168 15 59
  94888. +36 3 13 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94889. +0 0 0 0 0 0 0 0 0
  94890. +0 0 0 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 38 3 13 164 15 58 190 17 67
  94892. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94893. +188 17 66 188 17 66 182 16 64 50 5 17 0 0 0 0 0 0
  94894. +0 0 0 11 1 4 90 8 32 169 15 59 190 17 67 190 17 67
  94895. +189 17 66 189 17 66 189 17 66 189 17 66 191 17 67 189 17 66
  94896. +158 14 55 68 6 24 4 0 1 0 0 0 0 0 0 73 7 26
  94897. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94898. +188 17 66 188 17 66 188 17 66 189 17 66 185 17 65 83 8 29
  94899. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94900. +0 0 0 0 0 0 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 65 6 23 174 16 61
  94903. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94904. +188 17 66 188 17 66 185 17 65 56 5 19 0 0 0 0 0 0
  94905. +0 0 0 0 0 0 2 0 1 35 3 12 99 9 35 146 13 51
  94906. +170 15 60 177 16 62 177 16 62 166 15 58 141 13 49 85 8 30
  94907. +24 2 8 0 0 0 0 0 0 0 0 0 0 0 0 85 8 30
  94908. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94909. +188 17 66 188 17 66 188 17 66 189 17 66 112 10 39 8 1 3
  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
  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 1 0 0 68 6 24
  94914. +170 15 60 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  94915. +188 17 66 188 17 66 182 16 64 50 5 17 0 0 0 0 0 0
  94916. +0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 11 1 4
  94917. +28 3 10 40 4 14 38 3 13 25 2 9 8 1 3 0 0 0
  94918. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 78 7 27
  94919. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94920. +188 17 66 189 17 66 187 17 66 113 10 40 14 1 5 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
  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 1 0 0
  94925. +47 4 16 141 13 49 186 17 65 191 17 67 190 17 67 189 17 66
  94926. +189 17 66 191 17 67 156 14 55 20 2 7 0 0 0 0 0 0
  94927. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94928. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94929. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 44 4 15
  94930. +178 16 62 190 17 67 188 17 66 188 17 66 188 17 66 190 17 67
  94931. +191 17 67 173 16 61 90 8 32 10 1 4 0 0 0 0 0 0
  94932. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94933. +0 0 0 0 0 0 0 0 0
  94934. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94935. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94936. +0 0 0 14 1 5 68 6 24 131 12 46 162 15 57 174 16 61
  94937. +171 15 60 146 13 51 56 5 19 0 0 0 0 0 0 0 0 0
  94938. +0 0 0 0 0 0 0 0 0 3 0 1 14 1 5 29 3 10
  94939. +41 4 14 47 4 16 50 5 17 45 4 16 34 3 12 18 2 6
  94940. +5 0 2 0 0 0 0 0 0 0 0 0 0 0 0 5 0 2
  94941. +90 8 32 169 15 59 185 17 65 187 17 66 182 16 64 163 15 57
  94942. +113 10 40 41 4 14 2 0 1 0 0 0 0 0 0 0 0 0
  94943. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94944. +0 0 0 0 0 0 0 0 0
  94945. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94946. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94947. +0 0 0 0 0 0 0 0 0 5 0 2 21 2 7 34 3 12
  94948. +29 3 10 11 1 4 0 0 0 0 0 0 0 0 0 0 0 0
  94949. +3 0 1 32 3 11 79 7 28 124 11 43 154 14 54 171 15 60
  94950. +180 16 63 182 16 64 182 16 64 180 16 63 174 16 61 159 14 56
  94951. +132 12 46 88 8 31 34 3 12 3 0 1 0 0 0 0 0 0
  94952. +3 0 1 29 3 10 56 5 19 65 6 23 50 5 17 23 2 8
  94953. +3 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94954. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94955. +0 0 0 0 0 0 0 0 0
  94956. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94957. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94958. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94959. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 25 2 9
  94960. +109 10 38 169 15 59 189 17 66 191 17 67 190 17 67 189 17 66
  94961. +189 17 66 188 17 66 188 17 66 188 17 66 189 17 66 190 17 67
  94962. +191 17 67 190 17 67 171 15 60 98 9 34 10 1 3 0 0 0
  94963. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94964. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94965. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94966. +0 0 0 0 0 0 0 0 0
  94967. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94968. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94969. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94970. +0 0 0 0 0 0 0 0 0 0 0 0 14 1 5 141 13 49
  94971. +191 17 67 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94972. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94973. +188 17 66 188 17 66 189 17 67 186 17 65 65 6 23 0 0 0
  94974. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94975. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94976. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94977. +0 0 0 0 0 0 0 0 0
  94978. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94979. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94980. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94981. +0 0 0 0 0 0 0 0 0 0 0 0 23 2 8 166 15 58
  94982. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94983. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94984. +188 17 66 188 17 66 189 17 66 176 16 62 45 4 16 0 0 0
  94985. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94986. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94987. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94988. +0 0 0 0 0 0 0 0 0
  94989. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94990. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94991. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94992. +0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 83 8 29
  94993. +183 17 64 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94994. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94995. +188 17 66 189 17 66 185 17 65 95 9 33 3 0 1 0 0 0
  94996. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94997. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94998. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94999. +0 0 0 0 0 0 0 0 0
  95000. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95001. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95002. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95003. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 0 2
  95004. +85 8 30 176 16 62 191 17 67 188 17 66 188 17 66 188 17 66
  95005. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95006. +191 17 67 180 16 63 95 9 33 7 1 3 0 0 0 0 0 0
  95007. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95008. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95009. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95010. +0 0 0 0 0 0 0 0 0
  95011. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95012. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95013. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95014. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95015. +2 0 1 52 5 18 141 13 49 185 17 65 191 17 67 189 17 67
  95016. +189 17 66 188 17 66 188 17 66 189 17 66 191 17 67 187 17 66
  95017. +146 13 51 56 5 19 4 0 1 0 0 0 0 0 0 0 0 0
  95018. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95019. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95020. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95021. +0 0 0 0 0 0 0 0 0
  95022. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95023. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95024. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95025. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95026. +0 0 0 0 0 0 14 1 5 68 6 24 131 12 46 166 15 58
  95027. +180 16 63 183 17 64 180 16 63 168 15 59 134 12 47 75 7 26
  95028. +17 2 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95029. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95030. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95031. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95032. +0 0 0 0 0 0 0 0 0
  95033. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95034. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95035. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95036. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95037. +0 0 0 0 0 0 0 0 0 0 0 0 5 0 2 24 2 8
  95038. +44 4 15 52 5 18 45 4 16 26 2 9 6 1 2 0 0 0
  95039. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95040. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95041. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95042. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95043. +0 0 0 0 0 0 0 0 0
  95044. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95045. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95046. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95047. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95048. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95049. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95050. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95051. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95052. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95053. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95054. +0 0 0 0 0 0 0 0 0
  95055. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95056. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95057. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95058. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95059. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95060. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95061. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95062. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95063. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95064. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95065. +0 0 0 0 0 0 0 0 0
  95066. diff -Nur linux-3.13.3.orig/drivers/video/Makefile linux-3.13.3/drivers/video/Makefile
  95067. --- linux-3.13.3.orig/drivers/video/Makefile 2014-02-13 23:00:14.000000000 +0100
  95068. +++ linux-3.13.3/drivers/video/Makefile 2014-02-17 22:41:02.000000000 +0100
  95069. @@ -100,6 +100,7 @@
  95070. obj-$(CONFIG_FB_VOODOO1) += sstfb.o
  95071. obj-$(CONFIG_FB_ARMCLCD) += amba-clcd.o
  95072. obj-$(CONFIG_FB_GOLDFISH) += goldfishfb.o
  95073. +obj-$(CONFIG_FB_BCM2708) += bcm2708_fb.o
  95074. obj-$(CONFIG_FB_68328) += 68328fb.o
  95075. obj-$(CONFIG_FB_GBE) += gbefb.o
  95076. obj-$(CONFIG_FB_CIRRUS) += cirrusfb.o
  95077. diff -Nur linux-3.13.3.orig/drivers/w1/masters/w1-gpio.c linux-3.13.3/drivers/w1/masters/w1-gpio.c
  95078. --- linux-3.13.3.orig/drivers/w1/masters/w1-gpio.c 2014-02-13 23:00:14.000000000 +0100
  95079. +++ linux-3.13.3/drivers/w1/masters/w1-gpio.c 2014-02-17 22:41:02.000000000 +0100
  95080. @@ -22,6 +22,9 @@
  95081. #include "../w1.h"
  95082. #include "../w1_int.h"
  95083. +static int w1_gpio_pullup = 0;
  95084. +module_param_named(pullup, w1_gpio_pullup, int, 0);
  95085. +
  95086. static void w1_gpio_write_bit_dir(void *data, u8 bit)
  95087. {
  95088. struct w1_gpio_platform_data *pdata = data;
  95089. @@ -46,6 +49,16 @@
  95090. return gpio_get_value(pdata->pin) ? 1 : 0;
  95091. }
  95092. +static void w1_gpio_bitbang_pullup(void *data, u8 on)
  95093. +{
  95094. + struct w1_gpio_platform_data *pdata = data;
  95095. +
  95096. + if (on)
  95097. + gpio_direction_output(pdata->pin, 1);
  95098. + else
  95099. + gpio_direction_input(pdata->pin);
  95100. +}
  95101. +
  95102. #if defined(CONFIG_OF)
  95103. static struct of_device_id w1_gpio_dt_ids[] = {
  95104. { .compatible = "w1-gpio" },
  95105. @@ -134,6 +147,13 @@
  95106. master->write_bit = w1_gpio_write_bit_dir;
  95107. }
  95108. + if (w1_gpio_pullup)
  95109. + if (pdata->is_open_drain)
  95110. + printk(KERN_ERR "w1-gpio 'pullup' option "
  95111. + "doesn't work with open drain GPIO\n");
  95112. + else
  95113. + master->bitbang_pullup = w1_gpio_bitbang_pullup;
  95114. +
  95115. err = w1_add_master_device(master);
  95116. if (err) {
  95117. dev_err(&pdev->dev, "w1_add_master device failed\n");
  95118. diff -Nur linux-3.13.3.orig/drivers/w1/w1.h linux-3.13.3/drivers/w1/w1.h
  95119. --- linux-3.13.3.orig/drivers/w1/w1.h 2014-02-13 23:00:14.000000000 +0100
  95120. +++ linux-3.13.3/drivers/w1/w1.h 2014-02-17 22:41:02.000000000 +0100
  95121. @@ -148,6 +148,12 @@
  95122. */
  95123. u8 (*set_pullup)(void *, int);
  95124. + /**
  95125. + * Turns the pullup on/off in bitbanging mode, takes an on/off argument.
  95126. + * @return -1=Error, 0=completed
  95127. + */
  95128. + void (*bitbang_pullup) (void *, u8);
  95129. +
  95130. /** Really nice hardware can handles the different types of ROM search
  95131. * w1_master* is passed to the slave found callback.
  95132. */
  95133. diff -Nur linux-3.13.3.orig/drivers/w1/w1_int.c linux-3.13.3/drivers/w1/w1_int.c
  95134. --- linux-3.13.3.orig/drivers/w1/w1_int.c 2014-02-13 23:00:14.000000000 +0100
  95135. +++ linux-3.13.3/drivers/w1/w1_int.c 2014-02-17 22:41:02.000000000 +0100
  95136. @@ -117,19 +117,21 @@
  95137. printk(KERN_ERR "w1_add_master_device: invalid function set\n");
  95138. return(-EINVAL);
  95139. }
  95140. - /* While it would be electrically possible to make a device that
  95141. - * generated a strong pullup in bit bang mode, only hardware that
  95142. - * controls 1-wire time frames are even expected to support a strong
  95143. - * pullup. w1_io.c would need to support calling set_pullup before
  95144. - * the last write_bit operation of a w1_write_8 which it currently
  95145. - * doesn't.
  95146. - */
  95147. +
  95148. + /* bitbanging hardware uses bitbang_pullup, other hardware uses set_pullup
  95149. + * and takes care of timing itself */
  95150. if (!master->write_byte && !master->touch_bit && master->set_pullup) {
  95151. printk(KERN_ERR "w1_add_master_device: set_pullup requires "
  95152. "write_byte or touch_bit, disabling\n");
  95153. master->set_pullup = NULL;
  95154. }
  95155. + if (master->set_pullup && master->bitbang_pullup) {
  95156. + printk(KERN_ERR "w1_add_master_device: set_pullup should not "
  95157. + "be set when bitbang_pullup is used, disabling\n");
  95158. + master->set_pullup = NULL;
  95159. + }
  95160. +
  95161. /* Lock until the device is added (or not) to w1_masters. */
  95162. mutex_lock(&w1_mlock);
  95163. /* Search for the first available id (starting at 1). */
  95164. diff -Nur linux-3.13.3.orig/drivers/w1/w1_io.c linux-3.13.3/drivers/w1/w1_io.c
  95165. --- linux-3.13.3.orig/drivers/w1/w1_io.c 2014-02-13 23:00:14.000000000 +0100
  95166. +++ linux-3.13.3/drivers/w1/w1_io.c 2014-02-17 22:41:02.000000000 +0100
  95167. @@ -127,10 +127,22 @@
  95168. static void w1_post_write(struct w1_master *dev)
  95169. {
  95170. if (dev->pullup_duration) {
  95171. - if (dev->enable_pullup && dev->bus_master->set_pullup)
  95172. - dev->bus_master->set_pullup(dev->bus_master->data, 0);
  95173. - else
  95174. + if (dev->enable_pullup) {
  95175. + if (dev->bus_master->set_pullup) {
  95176. + dev->bus_master->set_pullup(dev->
  95177. + bus_master->data,
  95178. + 0);
  95179. + } else if (dev->bus_master->bitbang_pullup) {
  95180. + dev->bus_master->
  95181. + bitbang_pullup(dev->bus_master->data, 1);
  95182. msleep(dev->pullup_duration);
  95183. + dev->bus_master->
  95184. + bitbang_pullup(dev->bus_master->data, 0);
  95185. + }
  95186. + } else {
  95187. + msleep(dev->pullup_duration);
  95188. + }
  95189. +
  95190. dev->pullup_duration = 0;
  95191. }
  95192. }
  95193. diff -Nur linux-3.13.3.orig/drivers/watchdog/bcm2708_wdog.c linux-3.13.3/drivers/watchdog/bcm2708_wdog.c
  95194. --- linux-3.13.3.orig/drivers/watchdog/bcm2708_wdog.c 1970-01-01 01:00:00.000000000 +0100
  95195. +++ linux-3.13.3/drivers/watchdog/bcm2708_wdog.c 2014-02-17 22:41:02.000000000 +0100
  95196. @@ -0,0 +1,384 @@
  95197. +/*
  95198. + * Broadcom BCM2708 watchdog driver.
  95199. + *
  95200. + * (c) Copyright 2010 Broadcom Europe Ltd
  95201. + *
  95202. + * This program is free software; you can redistribute it and/or
  95203. + * modify it under the terms of the GNU General Public License
  95204. + * as published by the Free Software Foundation; either version
  95205. + * 2 of the License, or (at your option) any later version.
  95206. + *
  95207. + * BCM2708 watchdog driver. Loosely based on wdt driver.
  95208. + */
  95209. +
  95210. +#include <linux/interrupt.h>
  95211. +#include <linux/module.h>
  95212. +#include <linux/moduleparam.h>
  95213. +#include <linux/types.h>
  95214. +#include <linux/miscdevice.h>
  95215. +#include <linux/watchdog.h>
  95216. +#include <linux/fs.h>
  95217. +#include <linux/ioport.h>
  95218. +#include <linux/notifier.h>
  95219. +#include <linux/reboot.h>
  95220. +#include <linux/init.h>
  95221. +#include <linux/io.h>
  95222. +#include <linux/uaccess.h>
  95223. +#include <mach/platform.h>
  95224. +
  95225. +#include <asm/system.h>
  95226. +
  95227. +#define SECS_TO_WDOG_TICKS(x) ((x) << 16)
  95228. +#define WDOG_TICKS_TO_SECS(x) ((x) >> 16)
  95229. +
  95230. +static unsigned long wdog_is_open;
  95231. +static uint32_t wdog_ticks; /* Ticks to load into wdog timer */
  95232. +static char expect_close;
  95233. +
  95234. +/*
  95235. + * Module parameters
  95236. + */
  95237. +
  95238. +#define WD_TIMO 10 /* Default heartbeat = 60 seconds */
  95239. +static int heartbeat = WD_TIMO; /* Heartbeat in seconds */
  95240. +
  95241. +module_param(heartbeat, int, 0);
  95242. +MODULE_PARM_DESC(heartbeat,
  95243. + "Watchdog heartbeat in seconds. (0 < heartbeat < 65536, default="
  95244. + __MODULE_STRING(WD_TIMO) ")");
  95245. +
  95246. +static int nowayout = WATCHDOG_NOWAYOUT;
  95247. +module_param(nowayout, int, 0);
  95248. +MODULE_PARM_DESC(nowayout,
  95249. + "Watchdog cannot be stopped once started (default="
  95250. + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
  95251. +
  95252. +static DEFINE_SPINLOCK(wdog_lock);
  95253. +
  95254. +/**
  95255. + * Start the watchdog driver.
  95256. + */
  95257. +
  95258. +static int wdog_start(unsigned long timeout)
  95259. +{
  95260. + uint32_t cur;
  95261. + unsigned long flags;
  95262. + spin_lock_irqsave(&wdog_lock, flags);
  95263. +
  95264. + /* enable the watchdog */
  95265. + iowrite32(PM_PASSWORD | (timeout & PM_WDOG_TIME_SET),
  95266. + __io_address(PM_WDOG));
  95267. + cur = ioread32(__io_address(PM_RSTC));
  95268. + iowrite32(PM_PASSWORD | (cur & PM_RSTC_WRCFG_CLR) |
  95269. + PM_RSTC_WRCFG_FULL_RESET, __io_address(PM_RSTC));
  95270. +
  95271. + spin_unlock_irqrestore(&wdog_lock, flags);
  95272. + return 0;
  95273. +}
  95274. +
  95275. +/**
  95276. + * Stop the watchdog driver.
  95277. + */
  95278. +
  95279. +static int wdog_stop(void)
  95280. +{
  95281. + iowrite32(PM_PASSWORD | PM_RSTC_RESET, __io_address(PM_RSTC));
  95282. + printk(KERN_INFO "watchdog stopped\n");
  95283. + return 0;
  95284. +}
  95285. +
  95286. +/**
  95287. + * Reload counter one with the watchdog heartbeat. We don't bother
  95288. + * reloading the cascade counter.
  95289. + */
  95290. +
  95291. +static void wdog_ping(void)
  95292. +{
  95293. + wdog_start(wdog_ticks);
  95294. +}
  95295. +
  95296. +/**
  95297. + * @t: the new heartbeat value that needs to be set.
  95298. + *
  95299. + * Set a new heartbeat value for the watchdog device. If the heartbeat
  95300. + * value is incorrect we keep the old value and return -EINVAL. If
  95301. + * successful we return 0.
  95302. + */
  95303. +
  95304. +static int wdog_set_heartbeat(int t)
  95305. +{
  95306. + if (t < 1 || t > WDOG_TICKS_TO_SECS(PM_WDOG_TIME_SET))
  95307. + return -EINVAL;
  95308. +
  95309. + heartbeat = t;
  95310. + wdog_ticks = SECS_TO_WDOG_TICKS(t);
  95311. + return 0;
  95312. +}
  95313. +
  95314. +/**
  95315. + * @file: file handle to the watchdog
  95316. + * @buf: buffer to write (unused as data does not matter here
  95317. + * @count: count of bytes
  95318. + * @ppos: pointer to the position to write. No seeks allowed
  95319. + *
  95320. + * A write to a watchdog device is defined as a keepalive signal.
  95321. + *
  95322. + * if 'nowayout' is set then normally a close() is ignored. But
  95323. + * if you write 'V' first then the close() will stop the timer.
  95324. + */
  95325. +
  95326. +static ssize_t wdog_write(struct file *file, const char __user *buf,
  95327. + size_t count, loff_t *ppos)
  95328. +{
  95329. + if (count) {
  95330. + if (!nowayout) {
  95331. + size_t i;
  95332. +
  95333. + /* In case it was set long ago */
  95334. + expect_close = 0;
  95335. +
  95336. + for (i = 0; i != count; i++) {
  95337. + char c;
  95338. + if (get_user(c, buf + i))
  95339. + return -EFAULT;
  95340. + if (c == 'V')
  95341. + expect_close = 42;
  95342. + }
  95343. + }
  95344. + wdog_ping();
  95345. + }
  95346. + return count;
  95347. +}
  95348. +
  95349. +static int wdog_get_status(void)
  95350. +{
  95351. + unsigned long flags;
  95352. + int status = 0;
  95353. + spin_lock_irqsave(&wdog_lock, flags);
  95354. + /* FIXME: readback reset reason */
  95355. + spin_unlock_irqrestore(&wdog_lock, flags);
  95356. + return status;
  95357. +}
  95358. +
  95359. +static uint32_t wdog_get_remaining(void)
  95360. +{
  95361. + uint32_t ret = ioread32(__io_address(PM_WDOG));
  95362. + return ret & PM_WDOG_TIME_SET;
  95363. +}
  95364. +
  95365. +/**
  95366. + * @file: file handle to the device
  95367. + * @cmd: watchdog command
  95368. + * @arg: argument pointer
  95369. + *
  95370. + * The watchdog API defines a common set of functions for all watchdogs
  95371. + * according to their available features. We only actually usefully support
  95372. + * querying capabilities and current status.
  95373. + */
  95374. +
  95375. +static long wdog_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  95376. +{
  95377. + void __user *argp = (void __user *)arg;
  95378. + int __user *p = argp;
  95379. + int new_heartbeat;
  95380. + int status;
  95381. + int options;
  95382. + uint32_t remaining;
  95383. +
  95384. + struct watchdog_info ident = {
  95385. + .options = WDIOF_SETTIMEOUT|
  95386. + WDIOF_MAGICCLOSE|
  95387. + WDIOF_KEEPALIVEPING,
  95388. + .firmware_version = 1,
  95389. + .identity = "BCM2708",
  95390. + };
  95391. +
  95392. + switch (cmd) {
  95393. + case WDIOC_GETSUPPORT:
  95394. + return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0;
  95395. + case WDIOC_GETSTATUS:
  95396. + status = wdog_get_status();
  95397. + return put_user(status, p);
  95398. + case WDIOC_GETBOOTSTATUS:
  95399. + return put_user(0, p);
  95400. + case WDIOC_KEEPALIVE:
  95401. + wdog_ping();
  95402. + return 0;
  95403. + case WDIOC_SETTIMEOUT:
  95404. + if (get_user(new_heartbeat, p))
  95405. + return -EFAULT;
  95406. + if (wdog_set_heartbeat(new_heartbeat))
  95407. + return -EINVAL;
  95408. + wdog_ping();
  95409. + /* Fall */
  95410. + case WDIOC_GETTIMEOUT:
  95411. + return put_user(heartbeat, p);
  95412. + case WDIOC_GETTIMELEFT:
  95413. + remaining = WDOG_TICKS_TO_SECS(wdog_get_remaining());
  95414. + return put_user(remaining, p);
  95415. + case WDIOC_SETOPTIONS:
  95416. + if (get_user(options, p))
  95417. + return -EFAULT;
  95418. + if (options & WDIOS_DISABLECARD)
  95419. + wdog_stop();
  95420. + if (options & WDIOS_ENABLECARD)
  95421. + wdog_start(wdog_ticks);
  95422. + return 0;
  95423. + default:
  95424. + return -ENOTTY;
  95425. + }
  95426. +}
  95427. +
  95428. +/**
  95429. + * @inode: inode of device
  95430. + * @file: file handle to device
  95431. + *
  95432. + * The watchdog device has been opened. The watchdog device is single
  95433. + * open and on opening we load the counters.
  95434. + */
  95435. +
  95436. +static int wdog_open(struct inode *inode, struct file *file)
  95437. +{
  95438. + if (test_and_set_bit(0, &wdog_is_open))
  95439. + return -EBUSY;
  95440. + /*
  95441. + * Activate
  95442. + */
  95443. + wdog_start(wdog_ticks);
  95444. + return nonseekable_open(inode, file);
  95445. +}
  95446. +
  95447. +/**
  95448. + * @inode: inode to board
  95449. + * @file: file handle to board
  95450. + *
  95451. + * The watchdog has a configurable API. There is a religious dispute
  95452. + * between people who want their watchdog to be able to shut down and
  95453. + * those who want to be sure if the watchdog manager dies the machine
  95454. + * reboots. In the former case we disable the counters, in the latter
  95455. + * case you have to open it again very soon.
  95456. + */
  95457. +
  95458. +static int wdog_release(struct inode *inode, struct file *file)
  95459. +{
  95460. + if (expect_close == 42) {
  95461. + wdog_stop();
  95462. + } else {
  95463. + printk(KERN_CRIT
  95464. + "wdt: WDT device closed unexpectedly. WDT will not stop!\n");
  95465. + wdog_ping();
  95466. + }
  95467. + clear_bit(0, &wdog_is_open);
  95468. + expect_close = 0;
  95469. + return 0;
  95470. +}
  95471. +
  95472. +/**
  95473. + * @this: our notifier block
  95474. + * @code: the event being reported
  95475. + * @unused: unused
  95476. + *
  95477. + * Our notifier is called on system shutdowns. Turn the watchdog
  95478. + * off so that it does not fire during the next reboot.
  95479. + */
  95480. +
  95481. +static int wdog_notify_sys(struct notifier_block *this, unsigned long code,
  95482. + void *unused)
  95483. +{
  95484. + if (code == SYS_DOWN || code == SYS_HALT)
  95485. + wdog_stop();
  95486. + return NOTIFY_DONE;
  95487. +}
  95488. +
  95489. +/*
  95490. + * Kernel Interfaces
  95491. + */
  95492. +
  95493. +
  95494. +static const struct file_operations wdog_fops = {
  95495. + .owner = THIS_MODULE,
  95496. + .llseek = no_llseek,
  95497. + .write = wdog_write,
  95498. + .unlocked_ioctl = wdog_ioctl,
  95499. + .open = wdog_open,
  95500. + .release = wdog_release,
  95501. +};
  95502. +
  95503. +static struct miscdevice wdog_miscdev = {
  95504. + .minor = WATCHDOG_MINOR,
  95505. + .name = "watchdog",
  95506. + .fops = &wdog_fops,
  95507. +};
  95508. +
  95509. +/*
  95510. + * The WDT card needs to learn about soft shutdowns in order to
  95511. + * turn the timebomb registers off.
  95512. + */
  95513. +
  95514. +static struct notifier_block wdog_notifier = {
  95515. + .notifier_call = wdog_notify_sys,
  95516. +};
  95517. +
  95518. +/**
  95519. + * cleanup_module:
  95520. + *
  95521. + * Unload the watchdog. You cannot do this with any file handles open.
  95522. + * If your watchdog is set to continue ticking on close and you unload
  95523. + * it, well it keeps ticking. We won't get the interrupt but the board
  95524. + * will not touch PC memory so all is fine. You just have to load a new
  95525. + * module in 60 seconds or reboot.
  95526. + */
  95527. +
  95528. +static void __exit wdog_exit(void)
  95529. +{
  95530. + misc_deregister(&wdog_miscdev);
  95531. + unregister_reboot_notifier(&wdog_notifier);
  95532. +}
  95533. +
  95534. +static int __init wdog_init(void)
  95535. +{
  95536. + int ret;
  95537. +
  95538. + /* Check that the heartbeat value is within it's range;
  95539. + if not reset to the default */
  95540. + if (wdog_set_heartbeat(heartbeat)) {
  95541. + wdog_set_heartbeat(WD_TIMO);
  95542. + printk(KERN_INFO "bcm2708_wdog: heartbeat value must be "
  95543. + "0 < heartbeat < %d, using %d\n",
  95544. + WDOG_TICKS_TO_SECS(PM_WDOG_TIME_SET),
  95545. + WD_TIMO);
  95546. + }
  95547. +
  95548. + ret = register_reboot_notifier(&wdog_notifier);
  95549. + if (ret) {
  95550. + printk(KERN_ERR
  95551. + "wdt: cannot register reboot notifier (err=%d)\n", ret);
  95552. + goto out_reboot;
  95553. + }
  95554. +
  95555. + ret = misc_register(&wdog_miscdev);
  95556. + if (ret) {
  95557. + printk(KERN_ERR
  95558. + "wdt: cannot register miscdev on minor=%d (err=%d)\n",
  95559. + WATCHDOG_MINOR, ret);
  95560. + goto out_misc;
  95561. + }
  95562. +
  95563. + printk(KERN_INFO "bcm2708 watchdog, heartbeat=%d sec (nowayout=%d)\n",
  95564. + heartbeat, nowayout);
  95565. + return 0;
  95566. +
  95567. +out_misc:
  95568. + unregister_reboot_notifier(&wdog_notifier);
  95569. +out_reboot:
  95570. + return ret;
  95571. +}
  95572. +
  95573. +module_init(wdog_init);
  95574. +module_exit(wdog_exit);
  95575. +
  95576. +MODULE_AUTHOR("Luke Diamand");
  95577. +MODULE_DESCRIPTION("Driver for BCM2708 watchdog");
  95578. +MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
  95579. +MODULE_ALIAS_MISCDEV(TEMP_MINOR);
  95580. +MODULE_LICENSE("GPL");
  95581. diff -Nur linux-3.13.3.orig/drivers/watchdog/Kconfig linux-3.13.3/drivers/watchdog/Kconfig
  95582. --- linux-3.13.3.orig/drivers/watchdog/Kconfig 2014-02-13 23:00:14.000000000 +0100
  95583. +++ linux-3.13.3/drivers/watchdog/Kconfig 2014-02-17 22:41:02.000000000 +0100
  95584. @@ -392,6 +392,12 @@
  95585. To compile this driver as a module, choose M here: the
  95586. module will be called retu_wdt.
  95587. +config BCM2708_WDT
  95588. + tristate "BCM2708 Watchdog"
  95589. + depends on ARCH_BCM2708
  95590. + help
  95591. + Enables BCM2708 watchdog support.
  95592. +
  95593. config MOXART_WDT
  95594. tristate "MOXART watchdog"
  95595. depends on ARCH_MOXART
  95596. diff -Nur linux-3.13.3.orig/drivers/watchdog/Makefile linux-3.13.3/drivers/watchdog/Makefile
  95597. --- linux-3.13.3.orig/drivers/watchdog/Makefile 2014-02-13 23:00:14.000000000 +0100
  95598. +++ linux-3.13.3/drivers/watchdog/Makefile 2014-02-17 22:41:02.000000000 +0100
  95599. @@ -54,6 +54,7 @@
  95600. obj-$(CONFIG_IMX2_WDT) += imx2_wdt.o
  95601. obj-$(CONFIG_UX500_WATCHDOG) += ux500_wdt.o
  95602. obj-$(CONFIG_RETU_WATCHDOG) += retu_wdt.o
  95603. +obj-$(CONFIG_BCM2708_WDT) += bcm2708_wdog.o
  95604. obj-$(CONFIG_BCM2835_WDT) += bcm2835_wdt.o
  95605. obj-$(CONFIG_MOXART_WDT) += moxart_wdt.o
  95606. obj-$(CONFIG_SIRFSOC_WATCHDOG) += sirfsoc_wdt.o
  95607. diff -Nur linux-3.13.3.orig/include/linux/broadcom/vc_cma.h linux-3.13.3/include/linux/broadcom/vc_cma.h
  95608. --- linux-3.13.3.orig/include/linux/broadcom/vc_cma.h 1970-01-01 01:00:00.000000000 +0100
  95609. +++ linux-3.13.3/include/linux/broadcom/vc_cma.h 2014-02-17 22:41:02.000000000 +0100
  95610. @@ -0,0 +1,29 @@
  95611. +/*****************************************************************************
  95612. +* Copyright 2012 Broadcom Corporation. All rights reserved.
  95613. +*
  95614. +* Unless you and Broadcom execute a separate written software license
  95615. +* agreement governing use of this software, this software is licensed to you
  95616. +* under the terms of the GNU General Public License version 2, available at
  95617. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  95618. +*
  95619. +* Notwithstanding the above, under no circumstances may you combine this
  95620. +* software in any way with any other Broadcom software provided under a
  95621. +* license other than the GPL, without Broadcom's express prior written
  95622. +* consent.
  95623. +*****************************************************************************/
  95624. +
  95625. +#if !defined( VC_CMA_H )
  95626. +#define VC_CMA_H
  95627. +
  95628. +#include <linux/ioctl.h>
  95629. +
  95630. +#define VC_CMA_IOC_MAGIC 0xc5
  95631. +
  95632. +#define VC_CMA_IOC_RESERVE _IO(VC_CMA_IOC_MAGIC, 0)
  95633. +
  95634. +#ifdef __KERNEL__
  95635. +extern void __init vc_cma_early_init(void);
  95636. +extern void __init vc_cma_reserve(void);
  95637. +#endif
  95638. +
  95639. +#endif /* VC_CMA_H */
  95640. diff -Nur linux-3.13.3.orig/include/linux/mmc/host.h linux-3.13.3/include/linux/mmc/host.h
  95641. --- linux-3.13.3.orig/include/linux/mmc/host.h 2014-02-13 23:00:14.000000000 +0100
  95642. +++ linux-3.13.3/include/linux/mmc/host.h 2014-02-17 22:41:02.000000000 +0100
  95643. @@ -282,6 +282,7 @@
  95644. MMC_CAP2_PACKED_WR)
  95645. #define MMC_CAP2_NO_PRESCAN_POWERUP (1 << 14) /* Don't power up before scan */
  95646. #define MMC_CAP2_SANITIZE (1 << 15) /* Support Sanitize */
  95647. +#define MMC_CAP2_FORCE_MULTIBLOCK (1 << 31) /* Always use multiblock transfers */
  95648. mmc_pm_flag_t pm_caps; /* supported pm features */
  95649. diff -Nur linux-3.13.3.orig/include/linux/mmc/sdhci.h linux-3.13.3/include/linux/mmc/sdhci.h
  95650. --- linux-3.13.3.orig/include/linux/mmc/sdhci.h 2014-02-13 23:00:14.000000000 +0100
  95651. +++ linux-3.13.3/include/linux/mmc/sdhci.h 2014-02-17 22:41:02.000000000 +0100
  95652. @@ -102,6 +102,7 @@
  95653. #define SDHCI_QUIRK2_BROKEN_HS200 (1<<6)
  95654. int irq; /* Device IRQ */
  95655. + int second_irq; /* Additional IRQ to disable/enable in low-latency mode */
  95656. void __iomem *ioaddr; /* Mapped address */
  95657. const struct sdhci_ops *ops; /* Low level hw interface */
  95658. @@ -133,6 +134,7 @@
  95659. #define SDHCI_SDIO_IRQ_ENABLED (1<<9) /* SDIO irq enabled */
  95660. #define SDHCI_SDR104_NEEDS_TUNING (1<<10) /* SDR104/HS200 needs tuning */
  95661. #define SDHCI_USING_RETUNING_TIMER (1<<11) /* Host is using a retuning timer for the card */
  95662. +#define SDHCI_USE_PLATDMA (1<<12) /* Host uses 3rd party DMA */
  95663. unsigned int version; /* SDHCI spec. version */
  95664. @@ -148,6 +150,7 @@
  95665. struct mmc_request *mrq; /* Current request */
  95666. struct mmc_command *cmd; /* Current command */
  95667. + int last_cmdop; /* Opcode of last cmd sent */
  95668. struct mmc_data *data; /* Current data request */
  95669. unsigned int data_early:1; /* Data finished before cmd */
  95670. diff -Nur linux-3.13.3.orig/include/uapi/linux/fb.h linux-3.13.3/include/uapi/linux/fb.h
  95671. --- linux-3.13.3.orig/include/uapi/linux/fb.h 2014-02-13 23:00:14.000000000 +0100
  95672. +++ linux-3.13.3/include/uapi/linux/fb.h 2014-02-17 22:41:02.000000000 +0100
  95673. @@ -34,6 +34,11 @@
  95674. #define FBIOPUT_MODEINFO 0x4617
  95675. #define FBIOGET_DISPINFO 0x4618
  95676. #define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32)
  95677. +/*
  95678. + * HACK: use 'z' in order not to clash with any other ioctl numbers which might
  95679. + * be concurrently added to the mainline kernel
  95680. + */
  95681. +#define FBIOCOPYAREA _IOW('z', 0x21, struct fb_copyarea)
  95682. #define FB_TYPE_PACKED_PIXELS 0 /* Packed Pixels */
  95683. #define FB_TYPE_PLANES 1 /* Non interleaved planes */
  95684. diff -Nur linux-3.13.3.orig/kernel/cgroup.c linux-3.13.3/kernel/cgroup.c
  95685. --- linux-3.13.3.orig/kernel/cgroup.c 2014-02-13 23:00:14.000000000 +0100
  95686. +++ linux-3.13.3/kernel/cgroup.c 2014-02-17 22:41:02.000000000 +0100
  95687. @@ -5483,6 +5483,33 @@
  95688. }
  95689. __setup("cgroup_disable=", cgroup_disable);
  95690. +static int __init cgroup_enable(char *str)
  95691. +{
  95692. + struct cgroup_subsys *ss;
  95693. + char *token;
  95694. + int i;
  95695. +
  95696. + while ((token = strsep(&str, ",")) != NULL) {
  95697. + if (!*token)
  95698. + continue;
  95699. +
  95700. + /*
  95701. + * cgroup_disable, being at boot time, can't know about
  95702. + * module subsystems, so we don't worry about them.
  95703. + */
  95704. + for_each_builtin_subsys(ss, i) {
  95705. + if (!strcmp(token, ss->name)) {
  95706. + ss->disabled = 0;
  95707. + printk(KERN_INFO "Disabling %s control group"
  95708. + " subsystem\n", ss->name);
  95709. + break;
  95710. + }
  95711. + }
  95712. + }
  95713. + return 1;
  95714. +}
  95715. +__setup("cgroup_enable=", cgroup_enable);
  95716. +
  95717. /**
  95718. * css_from_dir - get corresponding css from the dentry of a cgroup dir
  95719. * @dentry: directory dentry of interest
  95720. diff -Nur linux-3.13.3.orig/mm/memcontrol.c linux-3.13.3/mm/memcontrol.c
  95721. --- linux-3.13.3.orig/mm/memcontrol.c 2014-02-13 23:00:14.000000000 +0100
  95722. +++ linux-3.13.3/mm/memcontrol.c 2014-02-17 22:41:02.000000000 +0100
  95723. @@ -7030,6 +7030,7 @@
  95724. .bind = mem_cgroup_bind,
  95725. .base_cftypes = mem_cgroup_files,
  95726. .early_init = 0,
  95727. + .disabled = 1,
  95728. };
  95729. #ifdef CONFIG_MEMCG_SWAP
  95730. diff -Nur linux-3.13.3.orig/sound/arm/bcm2835.c linux-3.13.3/sound/arm/bcm2835.c
  95731. --- linux-3.13.3.orig/sound/arm/bcm2835.c 1970-01-01 01:00:00.000000000 +0100
  95732. +++ linux-3.13.3/sound/arm/bcm2835.c 2014-02-17 22:41:02.000000000 +0100
  95733. @@ -0,0 +1,413 @@
  95734. +/*****************************************************************************
  95735. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  95736. +*
  95737. +* Unless you and Broadcom execute a separate written software license
  95738. +* agreement governing use of this software, this software is licensed to you
  95739. +* under the terms of the GNU General Public License version 2, available at
  95740. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  95741. +*
  95742. +* Notwithstanding the above, under no circumstances may you combine this
  95743. +* software in any way with any other Broadcom software provided under a
  95744. +* license other than the GPL, without Broadcom's express prior written
  95745. +* consent.
  95746. +*****************************************************************************/
  95747. +
  95748. +#include <linux/platform_device.h>
  95749. +
  95750. +#include <linux/init.h>
  95751. +#include <linux/slab.h>
  95752. +#include <linux/module.h>
  95753. +
  95754. +#include "bcm2835.h"
  95755. +
  95756. +/* module parameters (see "Module Parameters") */
  95757. +/* SNDRV_CARDS: maximum number of cards supported by this module */
  95758. +static int index[MAX_SUBSTREAMS] = {[0 ... (MAX_SUBSTREAMS - 1)] = -1 };
  95759. +static char *id[MAX_SUBSTREAMS] = {[0 ... (MAX_SUBSTREAMS - 1)] = NULL };
  95760. +static int enable[MAX_SUBSTREAMS] = {[0 ... (MAX_SUBSTREAMS - 1)] = 1 };
  95761. +
  95762. +/* HACKY global pointers needed for successive probes to work : ssp
  95763. + * But compared against the changes we will have to do in VC audio_ipc code
  95764. + * to export 8 audio_ipc devices as a single IPC device and then monitor all
  95765. + * four devices in a thread, this gets things done quickly and should be easier
  95766. + * to debug if we run into issues
  95767. + */
  95768. +
  95769. +static struct snd_card *g_card = NULL;
  95770. +static bcm2835_chip_t *g_chip = NULL;
  95771. +
  95772. +static int snd_bcm2835_free(bcm2835_chip_t * chip)
  95773. +{
  95774. + kfree(chip);
  95775. + return 0;
  95776. +}
  95777. +
  95778. +/* component-destructor
  95779. + * (see "Management of Cards and Components")
  95780. + */
  95781. +static int snd_bcm2835_dev_free(struct snd_device *device)
  95782. +{
  95783. + return snd_bcm2835_free(device->device_data);
  95784. +}
  95785. +
  95786. +/* chip-specific constructor
  95787. + * (see "Management of Cards and Components")
  95788. + */
  95789. +static int snd_bcm2835_create(struct snd_card *card,
  95790. + struct platform_device *pdev,
  95791. + bcm2835_chip_t ** rchip)
  95792. +{
  95793. + bcm2835_chip_t *chip;
  95794. + int err;
  95795. + static struct snd_device_ops ops = {
  95796. + .dev_free = snd_bcm2835_dev_free,
  95797. + };
  95798. +
  95799. + *rchip = NULL;
  95800. +
  95801. + chip = kzalloc(sizeof(*chip), GFP_KERNEL);
  95802. + if (chip == NULL)
  95803. + return -ENOMEM;
  95804. +
  95805. + chip->card = card;
  95806. +
  95807. + err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
  95808. + if (err < 0) {
  95809. + snd_bcm2835_free(chip);
  95810. + return err;
  95811. + }
  95812. +
  95813. + *rchip = chip;
  95814. + return 0;
  95815. +}
  95816. +
  95817. +static int snd_bcm2835_alsa_probe(struct platform_device *pdev)
  95818. +{
  95819. + static int dev;
  95820. + bcm2835_chip_t *chip;
  95821. + struct snd_card *card;
  95822. + int err;
  95823. +
  95824. + if (dev >= MAX_SUBSTREAMS)
  95825. + return -ENODEV;
  95826. +
  95827. + if (!enable[dev]) {
  95828. + dev++;
  95829. + return -ENOENT;
  95830. + }
  95831. +
  95832. + if (dev > 0)
  95833. + goto add_register_map;
  95834. +
  95835. + err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &g_card);
  95836. + if (err < 0)
  95837. + goto out;
  95838. +
  95839. + snd_card_set_dev(g_card, &pdev->dev);
  95840. + strcpy(g_card->driver, "BRCM bcm2835 ALSA Driver");
  95841. + strcpy(g_card->shortname, "bcm2835 ALSA");
  95842. + sprintf(g_card->longname, "%s", g_card->shortname);
  95843. +
  95844. + err = snd_bcm2835_create(g_card, pdev, &chip);
  95845. + if (err < 0) {
  95846. + dev_err(&pdev->dev, "Failed to create bcm2835 chip\n");
  95847. + goto out_bcm2835_create;
  95848. + }
  95849. +
  95850. + g_chip = chip;
  95851. + err = snd_bcm2835_new_pcm(chip);
  95852. + if (err < 0) {
  95853. + dev_err(&pdev->dev, "Failed to create new BCM2835 pcm device\n");
  95854. + goto out_bcm2835_new_pcm;
  95855. + }
  95856. +
  95857. + err = snd_bcm2835_new_ctl(chip);
  95858. + if (err < 0) {
  95859. + dev_err(&pdev->dev, "Failed to create new BCM2835 ctl\n");
  95860. + goto out_bcm2835_new_ctl;
  95861. + }
  95862. +
  95863. +add_register_map:
  95864. + card = g_card;
  95865. + chip = g_chip;
  95866. +
  95867. + BUG_ON(!(card && chip));
  95868. +
  95869. + chip->avail_substreams |= (1 << dev);
  95870. + chip->pdev[dev] = pdev;
  95871. +
  95872. + if (dev == 0) {
  95873. + err = snd_card_register(card);
  95874. + if (err < 0) {
  95875. + dev_err(&pdev->dev,
  95876. + "Failed to register bcm2835 ALSA card \n");
  95877. + goto out_card_register;
  95878. + }
  95879. + platform_set_drvdata(pdev, card);
  95880. + audio_info("bcm2835 ALSA card created!\n");
  95881. + } else {
  95882. + audio_info("bcm2835 ALSA chip created!\n");
  95883. + platform_set_drvdata(pdev, (void *)dev);
  95884. + }
  95885. +
  95886. + dev++;
  95887. +
  95888. + return 0;
  95889. +
  95890. +out_card_register:
  95891. +out_bcm2835_new_ctl:
  95892. +out_bcm2835_new_pcm:
  95893. +out_bcm2835_create:
  95894. + BUG_ON(!g_card);
  95895. + if (snd_card_free(g_card))
  95896. + dev_err(&pdev->dev, "Failed to free Registered alsa card\n");
  95897. + g_card = NULL;
  95898. +out:
  95899. + dev = SNDRV_CARDS; /* stop more avail_substreams from being probed */
  95900. + dev_err(&pdev->dev, "BCM2835 ALSA Probe failed !!\n");
  95901. + return err;
  95902. +}
  95903. +
  95904. +static int snd_bcm2835_alsa_remove(struct platform_device *pdev)
  95905. +{
  95906. + uint32_t idx;
  95907. + void *drv_data;
  95908. +
  95909. + drv_data = platform_get_drvdata(pdev);
  95910. +
  95911. + if (drv_data == (void *)g_card) {
  95912. + /* This is the card device */
  95913. + snd_card_free((struct snd_card *)drv_data);
  95914. + g_card = NULL;
  95915. + g_chip = NULL;
  95916. + } else {
  95917. + idx = (uint32_t) drv_data;
  95918. + if (g_card != NULL) {
  95919. + BUG_ON(!g_chip);
  95920. + /* We pass chip device numbers in audio ipc devices
  95921. + * other than the one we registered our card with
  95922. + */
  95923. + idx = (uint32_t) drv_data;
  95924. + BUG_ON(!idx || idx > MAX_SUBSTREAMS);
  95925. + g_chip->avail_substreams &= ~(1 << idx);
  95926. + /* There should be atleast one substream registered
  95927. + * after we are done here, as it wil be removed when
  95928. + * the *remove* is called for the card device
  95929. + */
  95930. + BUG_ON(!g_chip->avail_substreams);
  95931. + }
  95932. + }
  95933. +
  95934. + platform_set_drvdata(pdev, NULL);
  95935. +
  95936. + return 0;
  95937. +}
  95938. +
  95939. +#ifdef CONFIG_PM
  95940. +static int snd_bcm2835_alsa_suspend(struct platform_device *pdev,
  95941. + pm_message_t state)
  95942. +{
  95943. + return 0;
  95944. +}
  95945. +
  95946. +static int snd_bcm2835_alsa_resume(struct platform_device *pdev)
  95947. +{
  95948. + return 0;
  95949. +}
  95950. +
  95951. +#endif
  95952. +
  95953. +static struct platform_driver bcm2835_alsa0_driver = {
  95954. + .probe = snd_bcm2835_alsa_probe,
  95955. + .remove = snd_bcm2835_alsa_remove,
  95956. +#ifdef CONFIG_PM
  95957. + .suspend = snd_bcm2835_alsa_suspend,
  95958. + .resume = snd_bcm2835_alsa_resume,
  95959. +#endif
  95960. + .driver = {
  95961. + .name = "bcm2835_AUD0",
  95962. + .owner = THIS_MODULE,
  95963. + },
  95964. +};
  95965. +
  95966. +static struct platform_driver bcm2835_alsa1_driver = {
  95967. + .probe = snd_bcm2835_alsa_probe,
  95968. + .remove = snd_bcm2835_alsa_remove,
  95969. +#ifdef CONFIG_PM
  95970. + .suspend = snd_bcm2835_alsa_suspend,
  95971. + .resume = snd_bcm2835_alsa_resume,
  95972. +#endif
  95973. + .driver = {
  95974. + .name = "bcm2835_AUD1",
  95975. + .owner = THIS_MODULE,
  95976. + },
  95977. +};
  95978. +
  95979. +static struct platform_driver bcm2835_alsa2_driver = {
  95980. + .probe = snd_bcm2835_alsa_probe,
  95981. + .remove = snd_bcm2835_alsa_remove,
  95982. +#ifdef CONFIG_PM
  95983. + .suspend = snd_bcm2835_alsa_suspend,
  95984. + .resume = snd_bcm2835_alsa_resume,
  95985. +#endif
  95986. + .driver = {
  95987. + .name = "bcm2835_AUD2",
  95988. + .owner = THIS_MODULE,
  95989. + },
  95990. +};
  95991. +
  95992. +static struct platform_driver bcm2835_alsa3_driver = {
  95993. + .probe = snd_bcm2835_alsa_probe,
  95994. + .remove = snd_bcm2835_alsa_remove,
  95995. +#ifdef CONFIG_PM
  95996. + .suspend = snd_bcm2835_alsa_suspend,
  95997. + .resume = snd_bcm2835_alsa_resume,
  95998. +#endif
  95999. + .driver = {
  96000. + .name = "bcm2835_AUD3",
  96001. + .owner = THIS_MODULE,
  96002. + },
  96003. +};
  96004. +
  96005. +static struct platform_driver bcm2835_alsa4_driver = {
  96006. + .probe = snd_bcm2835_alsa_probe,
  96007. + .remove = snd_bcm2835_alsa_remove,
  96008. +#ifdef CONFIG_PM
  96009. + .suspend = snd_bcm2835_alsa_suspend,
  96010. + .resume = snd_bcm2835_alsa_resume,
  96011. +#endif
  96012. + .driver = {
  96013. + .name = "bcm2835_AUD4",
  96014. + .owner = THIS_MODULE,
  96015. + },
  96016. +};
  96017. +
  96018. +static struct platform_driver bcm2835_alsa5_driver = {
  96019. + .probe = snd_bcm2835_alsa_probe,
  96020. + .remove = snd_bcm2835_alsa_remove,
  96021. +#ifdef CONFIG_PM
  96022. + .suspend = snd_bcm2835_alsa_suspend,
  96023. + .resume = snd_bcm2835_alsa_resume,
  96024. +#endif
  96025. + .driver = {
  96026. + .name = "bcm2835_AUD5",
  96027. + .owner = THIS_MODULE,
  96028. + },
  96029. +};
  96030. +
  96031. +static struct platform_driver bcm2835_alsa6_driver = {
  96032. + .probe = snd_bcm2835_alsa_probe,
  96033. + .remove = snd_bcm2835_alsa_remove,
  96034. +#ifdef CONFIG_PM
  96035. + .suspend = snd_bcm2835_alsa_suspend,
  96036. + .resume = snd_bcm2835_alsa_resume,
  96037. +#endif
  96038. + .driver = {
  96039. + .name = "bcm2835_AUD6",
  96040. + .owner = THIS_MODULE,
  96041. + },
  96042. +};
  96043. +
  96044. +static struct platform_driver bcm2835_alsa7_driver = {
  96045. + .probe = snd_bcm2835_alsa_probe,
  96046. + .remove = snd_bcm2835_alsa_remove,
  96047. +#ifdef CONFIG_PM
  96048. + .suspend = snd_bcm2835_alsa_suspend,
  96049. + .resume = snd_bcm2835_alsa_resume,
  96050. +#endif
  96051. + .driver = {
  96052. + .name = "bcm2835_AUD7",
  96053. + .owner = THIS_MODULE,
  96054. + },
  96055. +};
  96056. +
  96057. +static int bcm2835_alsa_device_init(void)
  96058. +{
  96059. + int err;
  96060. + err = platform_driver_register(&bcm2835_alsa0_driver);
  96061. + if (err) {
  96062. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  96063. + goto out;
  96064. + }
  96065. +
  96066. + err = platform_driver_register(&bcm2835_alsa1_driver);
  96067. + if (err) {
  96068. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  96069. + goto unregister_0;
  96070. + }
  96071. +
  96072. + err = platform_driver_register(&bcm2835_alsa2_driver);
  96073. + if (err) {
  96074. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  96075. + goto unregister_1;
  96076. + }
  96077. +
  96078. + err = platform_driver_register(&bcm2835_alsa3_driver);
  96079. + if (err) {
  96080. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  96081. + goto unregister_2;
  96082. + }
  96083. +
  96084. + err = platform_driver_register(&bcm2835_alsa4_driver);
  96085. + if (err) {
  96086. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  96087. + goto unregister_3;
  96088. + }
  96089. +
  96090. + err = platform_driver_register(&bcm2835_alsa5_driver);
  96091. + if (err) {
  96092. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  96093. + goto unregister_4;
  96094. + }
  96095. +
  96096. + err = platform_driver_register(&bcm2835_alsa6_driver);
  96097. + if (err) {
  96098. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  96099. + goto unregister_5;
  96100. + }
  96101. +
  96102. + err = platform_driver_register(&bcm2835_alsa7_driver);
  96103. + if (err) {
  96104. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  96105. + goto unregister_6;
  96106. + }
  96107. +
  96108. + return 0;
  96109. +
  96110. +unregister_6:
  96111. + platform_driver_unregister(&bcm2835_alsa6_driver);
  96112. +unregister_5:
  96113. + platform_driver_unregister(&bcm2835_alsa5_driver);
  96114. +unregister_4:
  96115. + platform_driver_unregister(&bcm2835_alsa4_driver);
  96116. +unregister_3:
  96117. + platform_driver_unregister(&bcm2835_alsa3_driver);
  96118. +unregister_2:
  96119. + platform_driver_unregister(&bcm2835_alsa2_driver);
  96120. +unregister_1:
  96121. + platform_driver_unregister(&bcm2835_alsa1_driver);
  96122. +unregister_0:
  96123. + platform_driver_unregister(&bcm2835_alsa0_driver);
  96124. +out:
  96125. + return err;
  96126. +}
  96127. +
  96128. +static void bcm2835_alsa_device_exit(void)
  96129. +{
  96130. + platform_driver_unregister(&bcm2835_alsa0_driver);
  96131. + platform_driver_unregister(&bcm2835_alsa1_driver);
  96132. + platform_driver_unregister(&bcm2835_alsa2_driver);
  96133. + platform_driver_unregister(&bcm2835_alsa3_driver);
  96134. + platform_driver_unregister(&bcm2835_alsa4_driver);
  96135. + platform_driver_unregister(&bcm2835_alsa5_driver);
  96136. + platform_driver_unregister(&bcm2835_alsa6_driver);
  96137. + platform_driver_unregister(&bcm2835_alsa7_driver);
  96138. +}
  96139. +
  96140. +late_initcall(bcm2835_alsa_device_init);
  96141. +module_exit(bcm2835_alsa_device_exit);
  96142. +
  96143. +MODULE_AUTHOR("Dom Cobley");
  96144. +MODULE_DESCRIPTION("Alsa driver for BCM2835 chip");
  96145. +MODULE_LICENSE("GPL");
  96146. +MODULE_ALIAS("platform:bcm2835_alsa");
  96147. diff -Nur linux-3.13.3.orig/sound/arm/bcm2835-ctl.c linux-3.13.3/sound/arm/bcm2835-ctl.c
  96148. --- linux-3.13.3.orig/sound/arm/bcm2835-ctl.c 1970-01-01 01:00:00.000000000 +0100
  96149. +++ linux-3.13.3/sound/arm/bcm2835-ctl.c 2014-02-17 22:41:02.000000000 +0100
  96150. @@ -0,0 +1,200 @@
  96151. +/*****************************************************************************
  96152. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  96153. +*
  96154. +* Unless you and Broadcom execute a separate written software license
  96155. +* agreement governing use of this software, this software is licensed to you
  96156. +* under the terms of the GNU General Public License version 2, available at
  96157. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  96158. +*
  96159. +* Notwithstanding the above, under no circumstances may you combine this
  96160. +* software in any way with any other Broadcom software provided under a
  96161. +* license other than the GPL, without Broadcom's express prior written
  96162. +* consent.
  96163. +*****************************************************************************/
  96164. +
  96165. +#include <linux/platform_device.h>
  96166. +#include <linux/init.h>
  96167. +#include <linux/io.h>
  96168. +#include <linux/jiffies.h>
  96169. +#include <linux/slab.h>
  96170. +#include <linux/time.h>
  96171. +#include <linux/wait.h>
  96172. +#include <linux/delay.h>
  96173. +#include <linux/moduleparam.h>
  96174. +#include <linux/sched.h>
  96175. +
  96176. +#include <sound/core.h>
  96177. +#include <sound/control.h>
  96178. +#include <sound/pcm.h>
  96179. +#include <sound/pcm_params.h>
  96180. +#include <sound/rawmidi.h>
  96181. +#include <sound/initval.h>
  96182. +#include <sound/tlv.h>
  96183. +
  96184. +#include "bcm2835.h"
  96185. +
  96186. +/* volume maximum and minimum in terms of 0.01dB */
  96187. +#define CTRL_VOL_MAX 400
  96188. +#define CTRL_VOL_MIN -10239 /* originally -10240 */
  96189. +
  96190. +
  96191. +static int snd_bcm2835_ctl_info(struct snd_kcontrol *kcontrol,
  96192. + struct snd_ctl_elem_info *uinfo)
  96193. +{
  96194. + audio_info(" ... IN\n");
  96195. + if (kcontrol->private_value == PCM_PLAYBACK_VOLUME) {
  96196. + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  96197. + uinfo->count = 1;
  96198. + uinfo->value.integer.min = CTRL_VOL_MIN;
  96199. + uinfo->value.integer.max = CTRL_VOL_MAX; /* 2303 */
  96200. + } else if (kcontrol->private_value == PCM_PLAYBACK_MUTE) {
  96201. + uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  96202. + uinfo->count = 1;
  96203. + uinfo->value.integer.min = 0;
  96204. + uinfo->value.integer.max = 1;
  96205. + } else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE) {
  96206. + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  96207. + uinfo->count = 1;
  96208. + uinfo->value.integer.min = 0;
  96209. + uinfo->value.integer.max = AUDIO_DEST_MAX-1;
  96210. + }
  96211. + audio_info(" ... OUT\n");
  96212. + return 0;
  96213. +}
  96214. +
  96215. +/* toggles mute on or off depending on the value of nmute, and returns
  96216. + * 1 if the mute value was changed, otherwise 0
  96217. + */
  96218. +static int toggle_mute(struct bcm2835_chip *chip, int nmute)
  96219. +{
  96220. + /* if settings are ok, just return 0 */
  96221. + if(chip->mute == nmute)
  96222. + return 0;
  96223. +
  96224. + /* if the sound is muted then we need to unmute */
  96225. + if(chip->mute == CTRL_VOL_MUTE)
  96226. + {
  96227. + chip->volume = chip->old_volume; /* copy the old volume back */
  96228. + audio_info("Unmuting, old_volume = %d, volume = %d ...\n", chip->old_volume, chip->volume);
  96229. + }
  96230. + else /* otherwise we mute */
  96231. + {
  96232. + chip->old_volume = chip->volume;
  96233. + chip->volume = 26214; /* set volume to minimum level AKA mute */
  96234. + audio_info("Muting, old_volume = %d, volume = %d ...\n", chip->old_volume, chip->volume);
  96235. + }
  96236. +
  96237. + chip->mute = nmute;
  96238. + return 1;
  96239. +}
  96240. +
  96241. +static int snd_bcm2835_ctl_get(struct snd_kcontrol *kcontrol,
  96242. + struct snd_ctl_elem_value *ucontrol)
  96243. +{
  96244. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  96245. +
  96246. + BUG_ON(!chip && !(chip->avail_substreams & AVAIL_SUBSTREAMS_MASK));
  96247. +
  96248. + if (kcontrol->private_value == PCM_PLAYBACK_VOLUME)
  96249. + ucontrol->value.integer.value[0] = chip2alsa(chip->volume);
  96250. + else if (kcontrol->private_value == PCM_PLAYBACK_MUTE)
  96251. + ucontrol->value.integer.value[0] = chip->mute;
  96252. + else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE)
  96253. + ucontrol->value.integer.value[0] = chip->dest;
  96254. +
  96255. + return 0;
  96256. +}
  96257. +
  96258. +static int snd_bcm2835_ctl_put(struct snd_kcontrol *kcontrol,
  96259. + struct snd_ctl_elem_value *ucontrol)
  96260. +{
  96261. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  96262. + int changed = 0;
  96263. +
  96264. + if (kcontrol->private_value == PCM_PLAYBACK_VOLUME) {
  96265. + audio_info("Volume change attempted.. volume = %d new_volume = %d\n", chip->volume, (int)ucontrol->value.integer.value[0]);
  96266. + if (chip->mute == CTRL_VOL_MUTE) {
  96267. + /* changed = toggle_mute(chip, CTRL_VOL_UNMUTE); */
  96268. + return 1; /* should return 0 to signify no change but the mixer takes this as the opposite sign (no idea why) */
  96269. + }
  96270. + if (changed
  96271. + || (ucontrol->value.integer.value[0] != chip2alsa(chip->volume))) {
  96272. +
  96273. + chip->volume = alsa2chip(ucontrol->value.integer.value[0]);
  96274. + changed = 1;
  96275. + }
  96276. +
  96277. + } else if (kcontrol->private_value == PCM_PLAYBACK_MUTE) {
  96278. + /* Now implemented */
  96279. + audio_info(" Mute attempted\n");
  96280. + changed = toggle_mute(chip, ucontrol->value.integer.value[0]);
  96281. +
  96282. + } else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE) {
  96283. + if (ucontrol->value.integer.value[0] != chip->dest) {
  96284. + chip->dest = ucontrol->value.integer.value[0];
  96285. + changed = 1;
  96286. + }
  96287. + }
  96288. +
  96289. + if (changed) {
  96290. + if (bcm2835_audio_set_ctls(chip))
  96291. + printk(KERN_ERR "Failed to set ALSA controls..\n");
  96292. + }
  96293. +
  96294. + return changed;
  96295. +}
  96296. +
  96297. +static DECLARE_TLV_DB_SCALE(snd_bcm2835_db_scale, CTRL_VOL_MIN, 1, 1);
  96298. +
  96299. +static struct snd_kcontrol_new snd_bcm2835_ctl[] = {
  96300. + {
  96301. + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  96302. + .name = "PCM Playback Volume",
  96303. + .index = 0,
  96304. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
  96305. + .private_value = PCM_PLAYBACK_VOLUME,
  96306. + .info = snd_bcm2835_ctl_info,
  96307. + .get = snd_bcm2835_ctl_get,
  96308. + .put = snd_bcm2835_ctl_put,
  96309. + .count = 1,
  96310. + .tlv = {.p = snd_bcm2835_db_scale}
  96311. + },
  96312. + {
  96313. + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  96314. + .name = "PCM Playback Switch",
  96315. + .index = 0,
  96316. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  96317. + .private_value = PCM_PLAYBACK_MUTE,
  96318. + .info = snd_bcm2835_ctl_info,
  96319. + .get = snd_bcm2835_ctl_get,
  96320. + .put = snd_bcm2835_ctl_put,
  96321. + .count = 1,
  96322. + },
  96323. + {
  96324. + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  96325. + .name = "PCM Playback Route",
  96326. + .index = 0,
  96327. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  96328. + .private_value = PCM_PLAYBACK_DEVICE,
  96329. + .info = snd_bcm2835_ctl_info,
  96330. + .get = snd_bcm2835_ctl_get,
  96331. + .put = snd_bcm2835_ctl_put,
  96332. + .count = 1,
  96333. + },
  96334. +};
  96335. +
  96336. +int snd_bcm2835_new_ctl(bcm2835_chip_t * chip)
  96337. +{
  96338. + int err;
  96339. + unsigned int idx;
  96340. +
  96341. + strcpy(chip->card->mixername, "Broadcom Mixer");
  96342. + for (idx = 0; idx < ARRAY_SIZE(snd_bcm2835_ctl); idx++) {
  96343. + err =
  96344. + snd_ctl_add(chip->card,
  96345. + snd_ctl_new1(&snd_bcm2835_ctl[idx], chip));
  96346. + if (err < 0)
  96347. + return err;
  96348. + }
  96349. + return 0;
  96350. +}
  96351. diff -Nur linux-3.13.3.orig/sound/arm/bcm2835.h linux-3.13.3/sound/arm/bcm2835.h
  96352. --- linux-3.13.3.orig/sound/arm/bcm2835.h 1970-01-01 01:00:00.000000000 +0100
  96353. +++ linux-3.13.3/sound/arm/bcm2835.h 2014-02-17 22:41:02.000000000 +0100
  96354. @@ -0,0 +1,157 @@
  96355. +/*****************************************************************************
  96356. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  96357. +*
  96358. +* Unless you and Broadcom execute a separate written software license
  96359. +* agreement governing use of this software, this software is licensed to you
  96360. +* under the terms of the GNU General Public License version 2, available at
  96361. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  96362. +*
  96363. +* Notwithstanding the above, under no circumstances may you combine this
  96364. +* software in any way with any other Broadcom software provided under a
  96365. +* license other than the GPL, without Broadcom's express prior written
  96366. +* consent.
  96367. +*****************************************************************************/
  96368. +
  96369. +#ifndef __SOUND_ARM_BCM2835_H
  96370. +#define __SOUND_ARM_BCM2835_H
  96371. +
  96372. +#include <linux/device.h>
  96373. +#include <linux/list.h>
  96374. +#include <linux/interrupt.h>
  96375. +#include <linux/wait.h>
  96376. +#include <sound/core.h>
  96377. +#include <sound/initval.h>
  96378. +#include <sound/pcm.h>
  96379. +#include <sound/pcm_params.h>
  96380. +#include <sound/pcm-indirect.h>
  96381. +#include <linux/workqueue.h>
  96382. +
  96383. +/*
  96384. +#define AUDIO_DEBUG_ENABLE
  96385. +#define AUDIO_VERBOSE_DEBUG_ENABLE
  96386. +*/
  96387. +
  96388. +/* Debug macros */
  96389. +
  96390. +#ifdef AUDIO_DEBUG_ENABLE
  96391. +#ifdef AUDIO_VERBOSE_DEBUG_ENABLE
  96392. +
  96393. +#define audio_debug(fmt, arg...) \
  96394. + printk(KERN_INFO"%s:%d " fmt, __func__, __LINE__, ##arg)
  96395. +
  96396. +#define audio_info(fmt, arg...) \
  96397. + printk(KERN_INFO"%s:%d " fmt, __func__, __LINE__, ##arg)
  96398. +
  96399. +#else
  96400. +
  96401. +#define audio_debug(fmt, arg...)
  96402. +
  96403. +#define audio_info(fmt, arg...)
  96404. +
  96405. +#endif /* AUDIO_VERBOSE_DEBUG_ENABLE */
  96406. +
  96407. +#else
  96408. +
  96409. +#define audio_debug(fmt, arg...)
  96410. +
  96411. +#define audio_info(fmt, arg...)
  96412. +
  96413. +#endif /* AUDIO_DEBUG_ENABLE */
  96414. +
  96415. +#define audio_error(fmt, arg...) \
  96416. + printk(KERN_ERR"%s:%d " fmt, __func__, __LINE__, ##arg)
  96417. +
  96418. +#define audio_warning(fmt, arg...) \
  96419. + printk(KERN_WARNING"%s:%d " fmt, __func__, __LINE__, ##arg)
  96420. +
  96421. +#define audio_alert(fmt, arg...) \
  96422. + printk(KERN_ALERT"%s:%d " fmt, __func__, __LINE__, ##arg)
  96423. +
  96424. +#define MAX_SUBSTREAMS (8)
  96425. +#define AVAIL_SUBSTREAMS_MASK (0xff)
  96426. +enum {
  96427. + CTRL_VOL_MUTE,
  96428. + CTRL_VOL_UNMUTE
  96429. +};
  96430. +
  96431. +/* macros for alsa2chip and chip2alsa, instead of functions */
  96432. +
  96433. +#define alsa2chip(vol) (uint)(-((vol << 8) / 100)) /* convert alsa to chip volume (defined as macro rather than function call) */
  96434. +#define chip2alsa(vol) -((vol * 100) >> 8) /* convert chip to alsa volume */
  96435. +
  96436. +/* Some constants for values .. */
  96437. +typedef enum {
  96438. + AUDIO_DEST_AUTO = 0,
  96439. + AUDIO_DEST_HEADPHONES = 1,
  96440. + AUDIO_DEST_HDMI = 2,
  96441. + AUDIO_DEST_MAX,
  96442. +} SND_BCM2835_ROUTE_T;
  96443. +
  96444. +typedef enum {
  96445. + PCM_PLAYBACK_VOLUME,
  96446. + PCM_PLAYBACK_MUTE,
  96447. + PCM_PLAYBACK_DEVICE,
  96448. +} SND_BCM2835_CTRL_T;
  96449. +
  96450. +/* definition of the chip-specific record */
  96451. +typedef struct bcm2835_chip {
  96452. + struct snd_card *card;
  96453. + struct snd_pcm *pcm;
  96454. + /* Bitmat for valid reg_base and irq numbers */
  96455. + uint32_t avail_substreams;
  96456. + struct platform_device *pdev[MAX_SUBSTREAMS];
  96457. + struct bcm2835_alsa_stream *alsa_stream[MAX_SUBSTREAMS];
  96458. +
  96459. + int volume;
  96460. + int old_volume; /* stores the volume value whist muted */
  96461. + int dest;
  96462. + int mute;
  96463. +} bcm2835_chip_t;
  96464. +
  96465. +typedef struct bcm2835_alsa_stream {
  96466. + bcm2835_chip_t *chip;
  96467. + struct snd_pcm_substream *substream;
  96468. + struct snd_pcm_indirect pcm_indirect;
  96469. +
  96470. + struct semaphore buffers_update_sem;
  96471. + struct semaphore control_sem;
  96472. + spinlock_t lock;
  96473. + volatile uint32_t control;
  96474. + volatile uint32_t status;
  96475. +
  96476. + int open;
  96477. + int running;
  96478. + int draining;
  96479. +
  96480. + unsigned int pos;
  96481. + unsigned int buffer_size;
  96482. + unsigned int period_size;
  96483. +
  96484. + uint32_t enable_fifo_irq;
  96485. + irq_handler_t fifo_irq_handler;
  96486. +
  96487. + atomic_t retrieved;
  96488. + struct opaque_AUDIO_INSTANCE_T *instance;
  96489. + struct workqueue_struct *my_wq;
  96490. + int idx;
  96491. +} bcm2835_alsa_stream_t;
  96492. +
  96493. +int snd_bcm2835_new_ctl(bcm2835_chip_t * chip);
  96494. +int snd_bcm2835_new_pcm(bcm2835_chip_t * chip);
  96495. +
  96496. +int bcm2835_audio_open(bcm2835_alsa_stream_t * alsa_stream);
  96497. +int bcm2835_audio_close(bcm2835_alsa_stream_t * alsa_stream);
  96498. +int bcm2835_audio_set_params(bcm2835_alsa_stream_t * alsa_stream,
  96499. + uint32_t channels, uint32_t samplerate,
  96500. + uint32_t bps);
  96501. +int bcm2835_audio_setup(bcm2835_alsa_stream_t * alsa_stream);
  96502. +int bcm2835_audio_start(bcm2835_alsa_stream_t * alsa_stream);
  96503. +int bcm2835_audio_stop(bcm2835_alsa_stream_t * alsa_stream);
  96504. +int bcm2835_audio_set_ctls(bcm2835_chip_t * chip);
  96505. +int bcm2835_audio_write(bcm2835_alsa_stream_t * alsa_stream, uint32_t count,
  96506. + void *src);
  96507. +uint32_t bcm2835_audio_retrieve_buffers(bcm2835_alsa_stream_t * alsa_stream);
  96508. +void bcm2835_audio_flush_buffers(bcm2835_alsa_stream_t * alsa_stream);
  96509. +void bcm2835_audio_flush_playback_buffers(bcm2835_alsa_stream_t * alsa_stream);
  96510. +
  96511. +#endif /* __SOUND_ARM_BCM2835_H */
  96512. diff -Nur linux-3.13.3.orig/sound/arm/bcm2835-pcm.c linux-3.13.3/sound/arm/bcm2835-pcm.c
  96513. --- linux-3.13.3.orig/sound/arm/bcm2835-pcm.c 1970-01-01 01:00:00.000000000 +0100
  96514. +++ linux-3.13.3/sound/arm/bcm2835-pcm.c 2014-02-17 22:41:02.000000000 +0100
  96515. @@ -0,0 +1,426 @@
  96516. +/*****************************************************************************
  96517. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  96518. +*
  96519. +* Unless you and Broadcom execute a separate written software license
  96520. +* agreement governing use of this software, this software is licensed to you
  96521. +* under the terms of the GNU General Public License version 2, available at
  96522. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  96523. +*
  96524. +* Notwithstanding the above, under no circumstances may you combine this
  96525. +* software in any way with any other Broadcom software provided under a
  96526. +* license other than the GPL, without Broadcom's express prior written
  96527. +* consent.
  96528. +*****************************************************************************/
  96529. +
  96530. +#include <linux/interrupt.h>
  96531. +#include <linux/slab.h>
  96532. +
  96533. +#include "bcm2835.h"
  96534. +
  96535. +/* hardware definition */
  96536. +static struct snd_pcm_hardware snd_bcm2835_playback_hw = {
  96537. + .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
  96538. + SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID),
  96539. + .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
  96540. + .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
  96541. + .rate_min = 8000,
  96542. + .rate_max = 48000,
  96543. + .channels_min = 1,
  96544. + .channels_max = 2,
  96545. + .buffer_bytes_max = 128 * 1024,
  96546. + .period_bytes_min = 1 * 1024,
  96547. + .period_bytes_max = 128 * 1024,
  96548. + .periods_min = 1,
  96549. + .periods_max = 128,
  96550. +};
  96551. +
  96552. +static void snd_bcm2835_playback_free(struct snd_pcm_runtime *runtime)
  96553. +{
  96554. + audio_info("Freeing up alsa stream here ..\n");
  96555. + if (runtime->private_data)
  96556. + kfree(runtime->private_data);
  96557. + runtime->private_data = NULL;
  96558. +}
  96559. +
  96560. +static irqreturn_t bcm2835_playback_fifo_irq(int irq, void *dev_id)
  96561. +{
  96562. + bcm2835_alsa_stream_t *alsa_stream = (bcm2835_alsa_stream_t *) dev_id;
  96563. + uint32_t consumed = 0;
  96564. + int new_period = 0;
  96565. +
  96566. + audio_info(" .. IN\n");
  96567. +
  96568. + audio_info("alsa_stream=%p substream=%p\n", alsa_stream,
  96569. + alsa_stream ? alsa_stream->substream : 0);
  96570. +
  96571. + if (alsa_stream->open)
  96572. + consumed = bcm2835_audio_retrieve_buffers(alsa_stream);
  96573. +
  96574. + /* We get called only if playback was triggered, So, the number of buffers we retrieve in
  96575. + * each iteration are the buffers that have been played out already
  96576. + */
  96577. +
  96578. + if (alsa_stream->period_size) {
  96579. + if ((alsa_stream->pos / alsa_stream->period_size) !=
  96580. + ((alsa_stream->pos + consumed) / alsa_stream->period_size))
  96581. + new_period = 1;
  96582. + }
  96583. + audio_debug("updating pos cur: %d + %d max:%d period_bytes:%d, hw_ptr: %d new_period:%d\n",
  96584. + alsa_stream->pos,
  96585. + consumed,
  96586. + alsa_stream->buffer_size,
  96587. + (int)(alsa_stream->period_size*alsa_stream->substream->runtime->periods),
  96588. + frames_to_bytes(alsa_stream->substream->runtime, alsa_stream->substream->runtime->status->hw_ptr),
  96589. + new_period);
  96590. + if (alsa_stream->buffer_size) {
  96591. + alsa_stream->pos += consumed &~ (1<<30);
  96592. + alsa_stream->pos %= alsa_stream->buffer_size;
  96593. + }
  96594. +
  96595. + if (alsa_stream->substream) {
  96596. + if (new_period)
  96597. + snd_pcm_period_elapsed(alsa_stream->substream);
  96598. + } else {
  96599. + audio_warning(" unexpected NULL substream\n");
  96600. + }
  96601. + audio_info(" .. OUT\n");
  96602. +
  96603. + return IRQ_HANDLED;
  96604. +}
  96605. +
  96606. +/* open callback */
  96607. +static int snd_bcm2835_playback_open(struct snd_pcm_substream *substream)
  96608. +{
  96609. + bcm2835_chip_t *chip = snd_pcm_substream_chip(substream);
  96610. + struct snd_pcm_runtime *runtime = substream->runtime;
  96611. + bcm2835_alsa_stream_t *alsa_stream;
  96612. + int idx;
  96613. + int err;
  96614. +
  96615. + audio_info(" .. IN (%d)\n", substream->number);
  96616. +
  96617. + audio_info("Alsa open (%d)\n", substream->number);
  96618. + idx = substream->number;
  96619. +
  96620. + if (idx > MAX_SUBSTREAMS) {
  96621. + audio_error
  96622. + ("substream(%d) device doesn't exist max(%d) substreams allowed\n",
  96623. + idx, MAX_SUBSTREAMS);
  96624. + err = -ENODEV;
  96625. + goto out;
  96626. + }
  96627. +
  96628. + /* Check if we are ready */
  96629. + if (!(chip->avail_substreams & (1 << idx))) {
  96630. + /* We are not ready yet */
  96631. + audio_error("substream(%d) device is not ready yet\n", idx);
  96632. + err = -EAGAIN;
  96633. + goto out;
  96634. + }
  96635. +
  96636. + alsa_stream = kzalloc(sizeof(bcm2835_alsa_stream_t), GFP_KERNEL);
  96637. + if (alsa_stream == NULL) {
  96638. + return -ENOMEM;
  96639. + }
  96640. +
  96641. + /* Initialise alsa_stream */
  96642. + alsa_stream->chip = chip;
  96643. + alsa_stream->substream = substream;
  96644. + alsa_stream->idx = idx;
  96645. + chip->alsa_stream[idx] = alsa_stream;
  96646. +
  96647. + sema_init(&alsa_stream->buffers_update_sem, 0);
  96648. + sema_init(&alsa_stream->control_sem, 0);
  96649. + spin_lock_init(&alsa_stream->lock);
  96650. +
  96651. + /* Enabled in start trigger, called on each "fifo irq" after that */
  96652. + alsa_stream->enable_fifo_irq = 0;
  96653. + alsa_stream->fifo_irq_handler = bcm2835_playback_fifo_irq;
  96654. +
  96655. + runtime->private_data = alsa_stream;
  96656. + runtime->private_free = snd_bcm2835_playback_free;
  96657. + runtime->hw = snd_bcm2835_playback_hw;
  96658. + /* minimum 16 bytes alignment (for vchiq bulk transfers) */
  96659. + snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
  96660. + 16);
  96661. +
  96662. + err = bcm2835_audio_open(alsa_stream);
  96663. + if (err != 0) {
  96664. + kfree(alsa_stream);
  96665. + return err;
  96666. + }
  96667. +
  96668. + alsa_stream->open = 1;
  96669. + alsa_stream->draining = 1;
  96670. +
  96671. +out:
  96672. + audio_info(" .. OUT =%d\n", err);
  96673. +
  96674. + return err;
  96675. +}
  96676. +
  96677. +/* close callback */
  96678. +static int snd_bcm2835_playback_close(struct snd_pcm_substream *substream)
  96679. +{
  96680. + /* the hardware-specific codes will be here */
  96681. +
  96682. + struct snd_pcm_runtime *runtime = substream->runtime;
  96683. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  96684. +
  96685. + audio_info(" .. IN\n");
  96686. + audio_info("Alsa close\n");
  96687. +
  96688. + /*
  96689. + * Call stop if it's still running. This happens when app
  96690. + * is force killed and we don't get a stop trigger.
  96691. + */
  96692. + if (alsa_stream->running) {
  96693. + int err;
  96694. + err = bcm2835_audio_stop(alsa_stream);
  96695. + alsa_stream->running = 0;
  96696. + if (err != 0)
  96697. + audio_error(" Failed to STOP alsa device\n");
  96698. + }
  96699. +
  96700. + alsa_stream->period_size = 0;
  96701. + alsa_stream->buffer_size = 0;
  96702. +
  96703. + if (alsa_stream->open) {
  96704. + alsa_stream->open = 0;
  96705. + bcm2835_audio_close(alsa_stream);
  96706. + }
  96707. + if (alsa_stream->chip)
  96708. + alsa_stream->chip->alsa_stream[alsa_stream->idx] = NULL;
  96709. + /*
  96710. + * Do not free up alsa_stream here, it will be freed up by
  96711. + * runtime->private_free callback we registered in *_open above
  96712. + */
  96713. +
  96714. + audio_info(" .. OUT\n");
  96715. +
  96716. + return 0;
  96717. +}
  96718. +
  96719. +/* hw_params callback */
  96720. +static int snd_bcm2835_pcm_hw_params(struct snd_pcm_substream *substream,
  96721. + struct snd_pcm_hw_params *params)
  96722. +{
  96723. + int err;
  96724. + struct snd_pcm_runtime *runtime = substream->runtime;
  96725. + bcm2835_alsa_stream_t *alsa_stream =
  96726. + (bcm2835_alsa_stream_t *) runtime->private_data;
  96727. +
  96728. + audio_info(" .. IN\n");
  96729. +
  96730. + err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
  96731. + if (err < 0) {
  96732. + audio_error
  96733. + (" pcm_lib_malloc failed to allocated pages for buffers\n");
  96734. + return err;
  96735. + }
  96736. +
  96737. + err = bcm2835_audio_set_params(alsa_stream, params_channels(params),
  96738. + params_rate(params),
  96739. + snd_pcm_format_width(params_format
  96740. + (params)));
  96741. + if (err < 0) {
  96742. + audio_error(" error setting hw params\n");
  96743. + }
  96744. +
  96745. + bcm2835_audio_setup(alsa_stream);
  96746. +
  96747. + /* in preparation of the stream, set the controls (volume level) of the stream */
  96748. + bcm2835_audio_set_ctls(alsa_stream->chip);
  96749. +
  96750. + audio_info(" .. OUT\n");
  96751. +
  96752. + return err;
  96753. +}
  96754. +
  96755. +/* hw_free callback */
  96756. +static int snd_bcm2835_pcm_hw_free(struct snd_pcm_substream *substream)
  96757. +{
  96758. + audio_info(" .. IN\n");
  96759. + return snd_pcm_lib_free_pages(substream);
  96760. +}
  96761. +
  96762. +/* prepare callback */
  96763. +static int snd_bcm2835_pcm_prepare(struct snd_pcm_substream *substream)
  96764. +{
  96765. + struct snd_pcm_runtime *runtime = substream->runtime;
  96766. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  96767. +
  96768. + audio_info(" .. IN\n");
  96769. +
  96770. + memset(&alsa_stream->pcm_indirect, 0, sizeof(alsa_stream->pcm_indirect));
  96771. +
  96772. + alsa_stream->pcm_indirect.hw_buffer_size =
  96773. + alsa_stream->pcm_indirect.sw_buffer_size =
  96774. + snd_pcm_lib_buffer_bytes(substream);
  96775. +
  96776. + alsa_stream->buffer_size = snd_pcm_lib_buffer_bytes(substream);
  96777. + alsa_stream->period_size = snd_pcm_lib_period_bytes(substream);
  96778. + alsa_stream->pos = 0;
  96779. +
  96780. + audio_debug("buffer_size=%d, period_size=%d pos=%d frame_bits=%d\n",
  96781. + alsa_stream->buffer_size, alsa_stream->period_size,
  96782. + alsa_stream->pos, runtime->frame_bits);
  96783. +
  96784. + audio_info(" .. OUT\n");
  96785. + return 0;
  96786. +}
  96787. +
  96788. +static void snd_bcm2835_pcm_transfer(struct snd_pcm_substream *substream,
  96789. + struct snd_pcm_indirect *rec, size_t bytes)
  96790. +{
  96791. + struct snd_pcm_runtime *runtime = substream->runtime;
  96792. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  96793. + void *src = (void *)(substream->runtime->dma_area + rec->sw_data);
  96794. + int err;
  96795. +
  96796. + err = bcm2835_audio_write(alsa_stream, bytes, src);
  96797. + if (err)
  96798. + audio_error(" Failed to transfer to alsa device (%d)\n", err);
  96799. +
  96800. +}
  96801. +
  96802. +static int snd_bcm2835_pcm_ack(struct snd_pcm_substream *substream)
  96803. +{
  96804. + struct snd_pcm_runtime *runtime = substream->runtime;
  96805. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  96806. + struct snd_pcm_indirect *pcm_indirect = &alsa_stream->pcm_indirect;
  96807. +
  96808. + pcm_indirect->hw_queue_size = runtime->hw.buffer_bytes_max;
  96809. + snd_pcm_indirect_playback_transfer(substream, pcm_indirect,
  96810. + snd_bcm2835_pcm_transfer);
  96811. + return 0;
  96812. +}
  96813. +
  96814. +/* trigger callback */
  96815. +static int snd_bcm2835_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
  96816. +{
  96817. + struct snd_pcm_runtime *runtime = substream->runtime;
  96818. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  96819. + int err = 0;
  96820. +
  96821. + audio_info(" .. IN\n");
  96822. +
  96823. + switch (cmd) {
  96824. + case SNDRV_PCM_TRIGGER_START:
  96825. + audio_debug("bcm2835_AUDIO_TRIGGER_START running=%d\n",
  96826. + alsa_stream->running);
  96827. + if (!alsa_stream->running) {
  96828. + err = bcm2835_audio_start(alsa_stream);
  96829. + if (err == 0) {
  96830. + alsa_stream->pcm_indirect.hw_io =
  96831. + alsa_stream->pcm_indirect.hw_data =
  96832. + bytes_to_frames(runtime,
  96833. + alsa_stream->pos);
  96834. + substream->ops->ack(substream);
  96835. + alsa_stream->running = 1;
  96836. + alsa_stream->draining = 1;
  96837. + } else {
  96838. + audio_error(" Failed to START alsa device (%d)\n", err);
  96839. + }
  96840. + }
  96841. + break;
  96842. + case SNDRV_PCM_TRIGGER_STOP:
  96843. + audio_debug
  96844. + ("bcm2835_AUDIO_TRIGGER_STOP running=%d draining=%d\n",
  96845. + alsa_stream->running, runtime->status->state == SNDRV_PCM_STATE_DRAINING);
  96846. + if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
  96847. + audio_info("DRAINING\n");
  96848. + alsa_stream->draining = 1;
  96849. + } else {
  96850. + audio_info("DROPPING\n");
  96851. + alsa_stream->draining = 0;
  96852. + }
  96853. + if (alsa_stream->running) {
  96854. + err = bcm2835_audio_stop(alsa_stream);
  96855. + if (err != 0)
  96856. + audio_error(" Failed to STOP alsa device (%d)\n", err);
  96857. + alsa_stream->running = 0;
  96858. + }
  96859. + break;
  96860. + default:
  96861. + err = -EINVAL;
  96862. + }
  96863. +
  96864. + audio_info(" .. OUT\n");
  96865. + return err;
  96866. +}
  96867. +
  96868. +/* pointer callback */
  96869. +static snd_pcm_uframes_t
  96870. +snd_bcm2835_pcm_pointer(struct snd_pcm_substream *substream)
  96871. +{
  96872. + struct snd_pcm_runtime *runtime = substream->runtime;
  96873. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  96874. +
  96875. + audio_info(" .. IN\n");
  96876. +
  96877. + audio_debug("pcm_pointer... (%d) hwptr=%d appl=%d pos=%d\n", 0,
  96878. + frames_to_bytes(runtime, runtime->status->hw_ptr),
  96879. + frames_to_bytes(runtime, runtime->control->appl_ptr),
  96880. + alsa_stream->pos);
  96881. +
  96882. + audio_info(" .. OUT\n");
  96883. + return snd_pcm_indirect_playback_pointer(substream,
  96884. + &alsa_stream->pcm_indirect,
  96885. + alsa_stream->pos);
  96886. +}
  96887. +
  96888. +static int snd_bcm2835_pcm_lib_ioctl(struct snd_pcm_substream *substream,
  96889. + unsigned int cmd, void *arg)
  96890. +{
  96891. + int ret = snd_pcm_lib_ioctl(substream, cmd, arg);
  96892. + audio_info(" .. substream=%p, cmd=%d, arg=%p (%x) ret=%d\n", substream,
  96893. + cmd, arg, arg ? *(unsigned *)arg : 0, ret);
  96894. + return ret;
  96895. +}
  96896. +
  96897. +/* operators */
  96898. +static struct snd_pcm_ops snd_bcm2835_playback_ops = {
  96899. + .open = snd_bcm2835_playback_open,
  96900. + .close = snd_bcm2835_playback_close,
  96901. + .ioctl = snd_bcm2835_pcm_lib_ioctl,
  96902. + .hw_params = snd_bcm2835_pcm_hw_params,
  96903. + .hw_free = snd_bcm2835_pcm_hw_free,
  96904. + .prepare = snd_bcm2835_pcm_prepare,
  96905. + .trigger = snd_bcm2835_pcm_trigger,
  96906. + .pointer = snd_bcm2835_pcm_pointer,
  96907. + .ack = snd_bcm2835_pcm_ack,
  96908. +};
  96909. +
  96910. +/* create a pcm device */
  96911. +int snd_bcm2835_new_pcm(bcm2835_chip_t * chip)
  96912. +{
  96913. + struct snd_pcm *pcm;
  96914. + int err;
  96915. +
  96916. + audio_info(" .. IN\n");
  96917. + err =
  96918. + snd_pcm_new(chip->card, "bcm2835 ALSA", 0, MAX_SUBSTREAMS, 0, &pcm);
  96919. + if (err < 0)
  96920. + return err;
  96921. + pcm->private_data = chip;
  96922. + strcpy(pcm->name, "bcm2835 ALSA");
  96923. + chip->pcm = pcm;
  96924. + chip->dest = AUDIO_DEST_AUTO;
  96925. + chip->volume = alsa2chip(0);
  96926. + chip->mute = CTRL_VOL_UNMUTE; /*disable mute on startup */
  96927. + /* set operators */
  96928. + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
  96929. + &snd_bcm2835_playback_ops);
  96930. +
  96931. + /* pre-allocation of buffers */
  96932. + /* NOTE: this may fail */
  96933. + snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
  96934. + snd_dma_continuous_data
  96935. + (GFP_KERNEL), 64 * 1024,
  96936. + 64 * 1024);
  96937. +
  96938. + audio_info(" .. OUT\n");
  96939. +
  96940. + return 0;
  96941. +}
  96942. diff -Nur linux-3.13.3.orig/sound/arm/bcm2835-vchiq.c linux-3.13.3/sound/arm/bcm2835-vchiq.c
  96943. --- linux-3.13.3.orig/sound/arm/bcm2835-vchiq.c 1970-01-01 01:00:00.000000000 +0100
  96944. +++ linux-3.13.3/sound/arm/bcm2835-vchiq.c 2014-02-17 22:41:02.000000000 +0100
  96945. @@ -0,0 +1,879 @@
  96946. +/*****************************************************************************
  96947. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  96948. +*
  96949. +* Unless you and Broadcom execute a separate written software license
  96950. +* agreement governing use of this software, this software is licensed to you
  96951. +* under the terms of the GNU General Public License version 2, available at
  96952. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  96953. +*
  96954. +* Notwithstanding the above, under no circumstances may you combine this
  96955. +* software in any way with any other Broadcom software provided under a
  96956. +* license other than the GPL, without Broadcom's express prior written
  96957. +* consent.
  96958. +*****************************************************************************/
  96959. +
  96960. +#include <linux/device.h>
  96961. +#include <sound/core.h>
  96962. +#include <sound/initval.h>
  96963. +#include <sound/pcm.h>
  96964. +#include <linux/io.h>
  96965. +#include <linux/interrupt.h>
  96966. +#include <linux/fs.h>
  96967. +#include <linux/file.h>
  96968. +#include <linux/mm.h>
  96969. +#include <linux/syscalls.h>
  96970. +#include <asm/uaccess.h>
  96971. +#include <linux/slab.h>
  96972. +#include <linux/delay.h>
  96973. +#include <linux/atomic.h>
  96974. +#include <linux/module.h>
  96975. +#include <linux/completion.h>
  96976. +
  96977. +#include "bcm2835.h"
  96978. +
  96979. +/* ---- Include Files -------------------------------------------------------- */
  96980. +
  96981. +#include "interface/vchi/vchi.h"
  96982. +#include "vc_vchi_audioserv_defs.h"
  96983. +
  96984. +/* ---- Private Constants and Types ------------------------------------------ */
  96985. +
  96986. +#define BCM2835_AUDIO_STOP 0
  96987. +#define BCM2835_AUDIO_START 1
  96988. +#define BCM2835_AUDIO_WRITE 2
  96989. +
  96990. +/* Logging macros (for remapping to other logging mechanisms, i.e., printf) */
  96991. +#ifdef AUDIO_DEBUG_ENABLE
  96992. + #define LOG_ERR( fmt, arg... ) pr_err( "%s:%d " fmt, __func__, __LINE__, ##arg)
  96993. + #define LOG_WARN( fmt, arg... ) pr_info( "%s:%d " fmt, __func__, __LINE__, ##arg)
  96994. + #define LOG_INFO( fmt, arg... ) pr_info( "%s:%d " fmt, __func__, __LINE__, ##arg)
  96995. + #define LOG_DBG( fmt, arg... ) pr_info( "%s:%d " fmt, __func__, __LINE__, ##arg)
  96996. +#else
  96997. + #define LOG_ERR( fmt, arg... ) pr_err( "%s:%d " fmt, __func__, __LINE__, ##arg)
  96998. + #define LOG_WARN( fmt, arg... )
  96999. + #define LOG_INFO( fmt, arg... )
  97000. + #define LOG_DBG( fmt, arg... )
  97001. +#endif
  97002. +
  97003. +typedef struct opaque_AUDIO_INSTANCE_T {
  97004. + uint32_t num_connections;
  97005. + VCHI_SERVICE_HANDLE_T vchi_handle[VCHI_MAX_NUM_CONNECTIONS];
  97006. + struct completion msg_avail_comp;
  97007. + struct mutex vchi_mutex;
  97008. + bcm2835_alsa_stream_t *alsa_stream;
  97009. + int32_t result;
  97010. + short peer_version;
  97011. +} AUDIO_INSTANCE_T;
  97012. +
  97013. +bool force_bulk = false;
  97014. +
  97015. +/* ---- Private Variables ---------------------------------------------------- */
  97016. +
  97017. +/* ---- Private Function Prototypes ------------------------------------------ */
  97018. +
  97019. +/* ---- Private Functions ---------------------------------------------------- */
  97020. +
  97021. +static int bcm2835_audio_stop_worker(bcm2835_alsa_stream_t * alsa_stream);
  97022. +static int bcm2835_audio_start_worker(bcm2835_alsa_stream_t * alsa_stream);
  97023. +static int bcm2835_audio_write_worker(bcm2835_alsa_stream_t *alsa_stream,
  97024. + uint32_t count, void *src);
  97025. +
  97026. +typedef struct {
  97027. + struct work_struct my_work;
  97028. + bcm2835_alsa_stream_t *alsa_stream;
  97029. + int cmd;
  97030. + void *src;
  97031. + uint32_t count;
  97032. +} my_work_t;
  97033. +
  97034. +static void my_wq_function(struct work_struct *work)
  97035. +{
  97036. + my_work_t *w = (my_work_t *) work;
  97037. + int ret = -9;
  97038. + LOG_DBG(" .. IN %p:%d\n", w->alsa_stream, w->cmd);
  97039. + switch (w->cmd) {
  97040. + case BCM2835_AUDIO_START:
  97041. + ret = bcm2835_audio_start_worker(w->alsa_stream);
  97042. + break;
  97043. + case BCM2835_AUDIO_STOP:
  97044. + ret = bcm2835_audio_stop_worker(w->alsa_stream);
  97045. + break;
  97046. + case BCM2835_AUDIO_WRITE:
  97047. + ret = bcm2835_audio_write_worker(w->alsa_stream, w->count,
  97048. + w->src);
  97049. + break;
  97050. + default:
  97051. + LOG_ERR(" Unexpected work: %p:%d\n", w->alsa_stream, w->cmd);
  97052. + break;
  97053. + }
  97054. + kfree((void *)work);
  97055. + LOG_DBG(" .. OUT %d\n", ret);
  97056. +}
  97057. +
  97058. +int bcm2835_audio_start(bcm2835_alsa_stream_t * alsa_stream)
  97059. +{
  97060. + int ret = -1;
  97061. + LOG_DBG(" .. IN\n");
  97062. + if (alsa_stream->my_wq) {
  97063. + my_work_t *work = kmalloc(sizeof(my_work_t), GFP_ATOMIC);
  97064. + /*--- Queue some work (item 1) ---*/
  97065. + if (work) {
  97066. + INIT_WORK((struct work_struct *)work, my_wq_function);
  97067. + work->alsa_stream = alsa_stream;
  97068. + work->cmd = BCM2835_AUDIO_START;
  97069. + if (queue_work
  97070. + (alsa_stream->my_wq, (struct work_struct *)work))
  97071. + ret = 0;
  97072. + } else
  97073. + LOG_ERR(" .. Error: NULL work kmalloc\n");
  97074. + }
  97075. + LOG_DBG(" .. OUT %d\n", ret);
  97076. + return ret;
  97077. +}
  97078. +
  97079. +int bcm2835_audio_stop(bcm2835_alsa_stream_t * alsa_stream)
  97080. +{
  97081. + int ret = -1;
  97082. + LOG_DBG(" .. IN\n");
  97083. + if (alsa_stream->my_wq) {
  97084. + my_work_t *work = kmalloc(sizeof(my_work_t), GFP_ATOMIC);
  97085. + /*--- Queue some work (item 1) ---*/
  97086. + if (work) {
  97087. + INIT_WORK((struct work_struct *)work, my_wq_function);
  97088. + work->alsa_stream = alsa_stream;
  97089. + work->cmd = BCM2835_AUDIO_STOP;
  97090. + if (queue_work
  97091. + (alsa_stream->my_wq, (struct work_struct *)work))
  97092. + ret = 0;
  97093. + } else
  97094. + LOG_ERR(" .. Error: NULL work kmalloc\n");
  97095. + }
  97096. + LOG_DBG(" .. OUT %d\n", ret);
  97097. + return ret;
  97098. +}
  97099. +
  97100. +int bcm2835_audio_write(bcm2835_alsa_stream_t *alsa_stream,
  97101. + uint32_t count, void *src)
  97102. +{
  97103. + int ret = -1;
  97104. + LOG_DBG(" .. IN\n");
  97105. + if (alsa_stream->my_wq) {
  97106. + my_work_t *work = kmalloc(sizeof(my_work_t), GFP_ATOMIC);
  97107. + /*--- Queue some work (item 1) ---*/
  97108. + if (work) {
  97109. + INIT_WORK((struct work_struct *)work, my_wq_function);
  97110. + work->alsa_stream = alsa_stream;
  97111. + work->cmd = BCM2835_AUDIO_WRITE;
  97112. + work->src = src;
  97113. + work->count = count;
  97114. + if (queue_work
  97115. + (alsa_stream->my_wq, (struct work_struct *)work))
  97116. + ret = 0;
  97117. + } else
  97118. + LOG_ERR(" .. Error: NULL work kmalloc\n");
  97119. + }
  97120. + LOG_DBG(" .. OUT %d\n", ret);
  97121. + return ret;
  97122. +}
  97123. +
  97124. +void my_workqueue_init(bcm2835_alsa_stream_t * alsa_stream)
  97125. +{
  97126. + alsa_stream->my_wq = create_workqueue("my_queue");
  97127. + return;
  97128. +}
  97129. +
  97130. +void my_workqueue_quit(bcm2835_alsa_stream_t * alsa_stream)
  97131. +{
  97132. + if (alsa_stream->my_wq) {
  97133. + flush_workqueue(alsa_stream->my_wq);
  97134. + destroy_workqueue(alsa_stream->my_wq);
  97135. + alsa_stream->my_wq = NULL;
  97136. + }
  97137. + return;
  97138. +}
  97139. +
  97140. +static void audio_vchi_callback(void *param,
  97141. + const VCHI_CALLBACK_REASON_T reason,
  97142. + void *msg_handle)
  97143. +{
  97144. + AUDIO_INSTANCE_T *instance = (AUDIO_INSTANCE_T *) param;
  97145. + int32_t status;
  97146. + int32_t msg_len;
  97147. + VC_AUDIO_MSG_T m;
  97148. + bcm2835_alsa_stream_t *alsa_stream = 0;
  97149. + LOG_DBG(" .. IN instance=%p, param=%p, reason=%d, handle=%p\n",
  97150. + instance, param, reason, msg_handle);
  97151. +
  97152. + if (!instance || reason != VCHI_CALLBACK_MSG_AVAILABLE) {
  97153. + return;
  97154. + }
  97155. + alsa_stream = instance->alsa_stream;
  97156. + status = vchi_msg_dequeue(instance->vchi_handle[0],
  97157. + &m, sizeof m, &msg_len, VCHI_FLAGS_NONE);
  97158. + if (m.type == VC_AUDIO_MSG_TYPE_RESULT) {
  97159. + LOG_DBG
  97160. + (" .. instance=%p, m.type=VC_AUDIO_MSG_TYPE_RESULT, success=%d\n",
  97161. + instance, m.u.result.success);
  97162. + instance->result = m.u.result.success;
  97163. + complete(&instance->msg_avail_comp);
  97164. + } else if (m.type == VC_AUDIO_MSG_TYPE_COMPLETE) {
  97165. + irq_handler_t callback = (irq_handler_t) m.u.complete.callback;
  97166. + LOG_DBG
  97167. + (" .. instance=%p, m.type=VC_AUDIO_MSG_TYPE_COMPLETE, complete=%d\n",
  97168. + instance, m.u.complete.count);
  97169. + if (alsa_stream && callback) {
  97170. + atomic_add(m.u.complete.count, &alsa_stream->retrieved);
  97171. + callback(0, alsa_stream);
  97172. + } else {
  97173. + LOG_DBG(" .. unexpected alsa_stream=%p, callback=%p\n",
  97174. + alsa_stream, callback);
  97175. + }
  97176. + } else {
  97177. + LOG_DBG(" .. unexpected m.type=%d\n", m.type);
  97178. + }
  97179. + LOG_DBG(" .. OUT\n");
  97180. +}
  97181. +
  97182. +static AUDIO_INSTANCE_T *vc_vchi_audio_init(VCHI_INSTANCE_T vchi_instance,
  97183. + VCHI_CONNECTION_T **
  97184. + vchi_connections,
  97185. + uint32_t num_connections)
  97186. +{
  97187. + uint32_t i;
  97188. + AUDIO_INSTANCE_T *instance;
  97189. + int status;
  97190. +
  97191. + LOG_DBG("%s: start", __func__);
  97192. +
  97193. + if (num_connections > VCHI_MAX_NUM_CONNECTIONS) {
  97194. + LOG_ERR("%s: unsupported number of connections %u (max=%u)\n",
  97195. + __func__, num_connections, VCHI_MAX_NUM_CONNECTIONS);
  97196. +
  97197. + return NULL;
  97198. + }
  97199. + /* Allocate memory for this instance */
  97200. + instance = kmalloc(sizeof(*instance), GFP_KERNEL);
  97201. +
  97202. + memset(instance, 0, sizeof(*instance));
  97203. + instance->num_connections = num_connections;
  97204. +
  97205. + /* Create a lock for exclusive, serialized VCHI connection access */
  97206. + mutex_init(&instance->vchi_mutex);
  97207. + /* Open the VCHI service connections */
  97208. + for (i = 0; i < num_connections; i++) {
  97209. + SERVICE_CREATION_T params = {
  97210. + VCHI_VERSION_EX(VC_AUDIOSERV_VER, VC_AUDIOSERV_MIN_VER),
  97211. + VC_AUDIO_SERVER_NAME, // 4cc service code
  97212. + vchi_connections[i], // passed in fn pointers
  97213. + 0, // rx fifo size (unused)
  97214. + 0, // tx fifo size (unused)
  97215. + audio_vchi_callback, // service callback
  97216. + instance, // service callback parameter
  97217. + 1, //TODO: remove VCOS_FALSE, // unaligned bulk recieves
  97218. + 1, //TODO: remove VCOS_FALSE, // unaligned bulk transmits
  97219. + 0 // want crc check on bulk transfers
  97220. + };
  97221. +
  97222. + status = vchi_service_open(vchi_instance, &params,
  97223. + &instance->vchi_handle[i]);
  97224. + if (status) {
  97225. + LOG_ERR
  97226. + ("%s: failed to open VCHI service connection (status=%d)\n",
  97227. + __func__, status);
  97228. +
  97229. + goto err_close_services;
  97230. + }
  97231. + /* Finished with the service for now */
  97232. + vchi_service_release(instance->vchi_handle[i]);
  97233. + }
  97234. +
  97235. + return instance;
  97236. +
  97237. +err_close_services:
  97238. + for (i = 0; i < instance->num_connections; i++) {
  97239. + vchi_service_close(instance->vchi_handle[i]);
  97240. + }
  97241. +
  97242. + kfree(instance);
  97243. +
  97244. + return NULL;
  97245. +}
  97246. +
  97247. +static int32_t vc_vchi_audio_deinit(AUDIO_INSTANCE_T * instance)
  97248. +{
  97249. + uint32_t i;
  97250. +
  97251. + LOG_DBG(" .. IN\n");
  97252. +
  97253. + if (instance == NULL) {
  97254. + LOG_ERR("%s: invalid handle %p\n", __func__, instance);
  97255. +
  97256. + return -1;
  97257. + }
  97258. +
  97259. + LOG_DBG(" .. about to lock (%d)\n", instance->num_connections);
  97260. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  97261. + {
  97262. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  97263. + return -EINTR;
  97264. + }
  97265. +
  97266. + /* Close all VCHI service connections */
  97267. + for (i = 0; i < instance->num_connections; i++) {
  97268. + int32_t success;
  97269. + LOG_DBG(" .. %i:closing %p\n", i, instance->vchi_handle[i]);
  97270. + vchi_service_use(instance->vchi_handle[i]);
  97271. +
  97272. + success = vchi_service_close(instance->vchi_handle[i]);
  97273. + if (success != 0) {
  97274. + LOG_ERR
  97275. + ("%s: failed to close VCHI service connection (status=%d)\n",
  97276. + __func__, success);
  97277. + }
  97278. + }
  97279. +
  97280. + mutex_unlock(&instance->vchi_mutex);
  97281. +
  97282. + kfree(instance);
  97283. +
  97284. + LOG_DBG(" .. OUT\n");
  97285. +
  97286. + return 0;
  97287. +}
  97288. +
  97289. +static int bcm2835_audio_open_connection(bcm2835_alsa_stream_t * alsa_stream)
  97290. +{
  97291. + static VCHI_INSTANCE_T vchi_instance;
  97292. + static VCHI_CONNECTION_T *vchi_connection;
  97293. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  97294. + int ret;
  97295. + LOG_DBG(" .. IN\n");
  97296. +
  97297. + LOG_INFO("%s: start", __func__);
  97298. + //BUG_ON(instance);
  97299. + if (instance) {
  97300. + LOG_ERR("%s: VCHI instance already open (%p)\n",
  97301. + __func__, instance);
  97302. + instance->alsa_stream = alsa_stream;
  97303. + alsa_stream->instance = instance;
  97304. + ret = 0; // xxx todo -1;
  97305. + goto err_free_mem;
  97306. + }
  97307. +
  97308. + /* Initialize and create a VCHI connection */
  97309. + ret = vchi_initialise(&vchi_instance);
  97310. + if (ret != 0) {
  97311. + LOG_ERR("%s: failed to initialise VCHI instance (ret=%d)\n",
  97312. + __func__, ret);
  97313. +
  97314. + ret = -EIO;
  97315. + goto err_free_mem;
  97316. + }
  97317. + ret = vchi_connect(NULL, 0, vchi_instance);
  97318. + if (ret != 0) {
  97319. + LOG_ERR("%s: failed to connect VCHI instance (ret=%d)\n",
  97320. + __func__, ret);
  97321. +
  97322. + ret = -EIO;
  97323. + goto err_free_mem;
  97324. + }
  97325. +
  97326. + /* Initialize an instance of the audio service */
  97327. + instance = vc_vchi_audio_init(vchi_instance, &vchi_connection, 1);
  97328. +
  97329. + if (instance == NULL /*|| audio_handle != instance */ ) {
  97330. + LOG_ERR("%s: failed to initialize audio service\n", __func__);
  97331. +
  97332. + ret = -EPERM;
  97333. + goto err_free_mem;
  97334. + }
  97335. +
  97336. + instance->alsa_stream = alsa_stream;
  97337. + alsa_stream->instance = instance;
  97338. +
  97339. + LOG_DBG(" success !\n");
  97340. +err_free_mem:
  97341. + LOG_DBG(" .. OUT\n");
  97342. +
  97343. + return ret;
  97344. +}
  97345. +
  97346. +int bcm2835_audio_open(bcm2835_alsa_stream_t * alsa_stream)
  97347. +{
  97348. + AUDIO_INSTANCE_T *instance;
  97349. + VC_AUDIO_MSG_T m;
  97350. + int32_t success;
  97351. + int ret;
  97352. + LOG_DBG(" .. IN\n");
  97353. +
  97354. + my_workqueue_init(alsa_stream);
  97355. +
  97356. + ret = bcm2835_audio_open_connection(alsa_stream);
  97357. + if (ret != 0) {
  97358. + ret = -1;
  97359. + goto exit;
  97360. + }
  97361. + instance = alsa_stream->instance;
  97362. +
  97363. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  97364. + {
  97365. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  97366. + return -EINTR;
  97367. + }
  97368. + vchi_service_use(instance->vchi_handle[0]);
  97369. +
  97370. + m.type = VC_AUDIO_MSG_TYPE_OPEN;
  97371. +
  97372. + /* Send the message to the videocore */
  97373. + success = vchi_msg_queue(instance->vchi_handle[0],
  97374. + &m, sizeof m,
  97375. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  97376. +
  97377. + if (success != 0) {
  97378. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  97379. + __func__, success);
  97380. +
  97381. + ret = -1;
  97382. + goto unlock;
  97383. + }
  97384. +
  97385. + ret = 0;
  97386. +
  97387. +unlock:
  97388. + vchi_service_release(instance->vchi_handle[0]);
  97389. + mutex_unlock(&instance->vchi_mutex);
  97390. +exit:
  97391. + LOG_DBG(" .. OUT\n");
  97392. + return ret;
  97393. +}
  97394. +
  97395. +static int bcm2835_audio_set_ctls_chan(bcm2835_alsa_stream_t * alsa_stream,
  97396. + bcm2835_chip_t * chip)
  97397. +{
  97398. + VC_AUDIO_MSG_T m;
  97399. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  97400. + int32_t success;
  97401. + int ret;
  97402. + LOG_DBG(" .. IN\n");
  97403. +
  97404. + LOG_INFO
  97405. + (" Setting ALSA dest(%d), volume(%d)\n", chip->dest, chip->volume);
  97406. +
  97407. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  97408. + {
  97409. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  97410. + return -EINTR;
  97411. + }
  97412. + vchi_service_use(instance->vchi_handle[0]);
  97413. +
  97414. + instance->result = -1;
  97415. +
  97416. + m.type = VC_AUDIO_MSG_TYPE_CONTROL;
  97417. + m.u.control.dest = chip->dest;
  97418. + m.u.control.volume = chip->volume;
  97419. +
  97420. + /* Create the message available completion */
  97421. + init_completion(&instance->msg_avail_comp);
  97422. +
  97423. + /* Send the message to the videocore */
  97424. + success = vchi_msg_queue(instance->vchi_handle[0],
  97425. + &m, sizeof m,
  97426. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  97427. +
  97428. + if (success != 0) {
  97429. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  97430. + __func__, success);
  97431. +
  97432. + ret = -1;
  97433. + goto unlock;
  97434. + }
  97435. +
  97436. + /* We are expecting a reply from the videocore */
  97437. + ret = wait_for_completion_interruptible(&instance->msg_avail_comp);
  97438. + if (ret) {
  97439. + LOG_ERR("%s: failed on waiting for event (status=%d)\n",
  97440. + __func__, success);
  97441. + goto unlock;
  97442. + }
  97443. +
  97444. + if (instance->result != 0) {
  97445. + LOG_ERR("%s: result=%d\n", __func__, instance->result);
  97446. +
  97447. + ret = -1;
  97448. + goto unlock;
  97449. + }
  97450. +
  97451. + ret = 0;
  97452. +
  97453. +unlock:
  97454. + vchi_service_release(instance->vchi_handle[0]);
  97455. + mutex_unlock(&instance->vchi_mutex);
  97456. +
  97457. + LOG_DBG(" .. OUT\n");
  97458. + return ret;
  97459. +}
  97460. +
  97461. +int bcm2835_audio_set_ctls(bcm2835_chip_t * chip)
  97462. +{
  97463. + int i;
  97464. + int ret = 0;
  97465. + LOG_DBG(" .. IN\n");
  97466. +
  97467. + /* change ctls for all substreams */
  97468. + for (i = 0; i < MAX_SUBSTREAMS; i++) {
  97469. + if (chip->avail_substreams & (1 << i)) {
  97470. + if (!chip->alsa_stream[i])
  97471. + {
  97472. + LOG_DBG(" No ALSA stream available?! %i:%p (%x)\n", i, chip->alsa_stream[i], chip->avail_substreams);
  97473. + ret = 0;
  97474. + }
  97475. + else if (bcm2835_audio_set_ctls_chan /* returns 0 on success */
  97476. + (chip->alsa_stream[i], chip) != 0)
  97477. + {
  97478. + LOG_DBG("Couldn't set the controls for stream %d\n", i);
  97479. + ret = -1;
  97480. + }
  97481. + else LOG_DBG(" Controls set for stream %d\n", i);
  97482. + }
  97483. + }
  97484. + LOG_DBG(" .. OUT ret=%d\n", ret);
  97485. + return ret;
  97486. +}
  97487. +
  97488. +int bcm2835_audio_set_params(bcm2835_alsa_stream_t * alsa_stream,
  97489. + uint32_t channels, uint32_t samplerate,
  97490. + uint32_t bps)
  97491. +{
  97492. + VC_AUDIO_MSG_T m;
  97493. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  97494. + int32_t success;
  97495. + int ret;
  97496. + LOG_DBG(" .. IN\n");
  97497. +
  97498. + LOG_INFO
  97499. + (" Setting ALSA channels(%d), samplerate(%d), bits-per-sample(%d)\n",
  97500. + channels, samplerate, bps);
  97501. +
  97502. + /* resend ctls - alsa_stream may not have been open when first send */
  97503. + ret = bcm2835_audio_set_ctls_chan(alsa_stream, alsa_stream->chip);
  97504. + if (ret != 0) {
  97505. + LOG_ERR(" Alsa controls not supported\n");
  97506. + return -EINVAL;
  97507. + }
  97508. +
  97509. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  97510. + {
  97511. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  97512. + return -EINTR;
  97513. + }
  97514. + vchi_service_use(instance->vchi_handle[0]);
  97515. +
  97516. + instance->result = -1;
  97517. +
  97518. + m.type = VC_AUDIO_MSG_TYPE_CONFIG;
  97519. + m.u.config.channels = channels;
  97520. + m.u.config.samplerate = samplerate;
  97521. + m.u.config.bps = bps;
  97522. +
  97523. + /* Create the message available completion */
  97524. + init_completion(&instance->msg_avail_comp);
  97525. +
  97526. + /* Send the message to the videocore */
  97527. + success = vchi_msg_queue(instance->vchi_handle[0],
  97528. + &m, sizeof m,
  97529. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  97530. +
  97531. + if (success != 0) {
  97532. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  97533. + __func__, success);
  97534. +
  97535. + ret = -1;
  97536. + goto unlock;
  97537. + }
  97538. +
  97539. + /* We are expecting a reply from the videocore */
  97540. + ret = wait_for_completion_interruptible(&instance->msg_avail_comp);
  97541. + if (ret) {
  97542. + LOG_ERR("%s: failed on waiting for event (status=%d)\n",
  97543. + __func__, success);
  97544. + goto unlock;
  97545. + }
  97546. +
  97547. + if (instance->result != 0) {
  97548. + LOG_ERR("%s: result=%d", __func__, instance->result);
  97549. +
  97550. + ret = -1;
  97551. + goto unlock;
  97552. + }
  97553. +
  97554. + ret = 0;
  97555. +
  97556. +unlock:
  97557. + vchi_service_release(instance->vchi_handle[0]);
  97558. + mutex_unlock(&instance->vchi_mutex);
  97559. +
  97560. + LOG_DBG(" .. OUT\n");
  97561. + return ret;
  97562. +}
  97563. +
  97564. +int bcm2835_audio_setup(bcm2835_alsa_stream_t * alsa_stream)
  97565. +{
  97566. + LOG_DBG(" .. IN\n");
  97567. +
  97568. + LOG_DBG(" .. OUT\n");
  97569. +
  97570. + return 0;
  97571. +}
  97572. +
  97573. +static int bcm2835_audio_start_worker(bcm2835_alsa_stream_t * alsa_stream)
  97574. +{
  97575. + VC_AUDIO_MSG_T m;
  97576. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  97577. + int32_t success;
  97578. + int ret;
  97579. + LOG_DBG(" .. IN\n");
  97580. +
  97581. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  97582. + {
  97583. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  97584. + return -EINTR;
  97585. + }
  97586. + vchi_service_use(instance->vchi_handle[0]);
  97587. +
  97588. + m.type = VC_AUDIO_MSG_TYPE_START;
  97589. +
  97590. + /* Send the message to the videocore */
  97591. + success = vchi_msg_queue(instance->vchi_handle[0],
  97592. + &m, sizeof m,
  97593. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  97594. +
  97595. + if (success != 0) {
  97596. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)",
  97597. + __func__, success);
  97598. +
  97599. + ret = -1;
  97600. + goto unlock;
  97601. + }
  97602. +
  97603. + ret = 0;
  97604. +
  97605. +unlock:
  97606. + vchi_service_release(instance->vchi_handle[0]);
  97607. + mutex_unlock(&instance->vchi_mutex);
  97608. + LOG_DBG(" .. OUT\n");
  97609. + return ret;
  97610. +}
  97611. +
  97612. +static int bcm2835_audio_stop_worker(bcm2835_alsa_stream_t * alsa_stream)
  97613. +{
  97614. + VC_AUDIO_MSG_T m;
  97615. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  97616. + int32_t success;
  97617. + int ret;
  97618. + LOG_DBG(" .. IN\n");
  97619. +
  97620. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  97621. + {
  97622. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  97623. + return -EINTR;
  97624. + }
  97625. + vchi_service_use(instance->vchi_handle[0]);
  97626. +
  97627. + m.type = VC_AUDIO_MSG_TYPE_STOP;
  97628. + m.u.stop.draining = alsa_stream->draining;
  97629. +
  97630. + /* Send the message to the videocore */
  97631. + success = vchi_msg_queue(instance->vchi_handle[0],
  97632. + &m, sizeof m,
  97633. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  97634. +
  97635. + if (success != 0) {
  97636. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)",
  97637. + __func__, success);
  97638. +
  97639. + ret = -1;
  97640. + goto unlock;
  97641. + }
  97642. +
  97643. + ret = 0;
  97644. +
  97645. +unlock:
  97646. + vchi_service_release(instance->vchi_handle[0]);
  97647. + mutex_unlock(&instance->vchi_mutex);
  97648. + LOG_DBG(" .. OUT\n");
  97649. + return ret;
  97650. +}
  97651. +
  97652. +int bcm2835_audio_close(bcm2835_alsa_stream_t * alsa_stream)
  97653. +{
  97654. + VC_AUDIO_MSG_T m;
  97655. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  97656. + int32_t success;
  97657. + int ret;
  97658. + LOG_DBG(" .. IN\n");
  97659. +
  97660. + my_workqueue_quit(alsa_stream);
  97661. +
  97662. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  97663. + {
  97664. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  97665. + return -EINTR;
  97666. + }
  97667. + vchi_service_use(instance->vchi_handle[0]);
  97668. +
  97669. + m.type = VC_AUDIO_MSG_TYPE_CLOSE;
  97670. +
  97671. + /* Create the message available completion */
  97672. + init_completion(&instance->msg_avail_comp);
  97673. +
  97674. + /* Send the message to the videocore */
  97675. + success = vchi_msg_queue(instance->vchi_handle[0],
  97676. + &m, sizeof m,
  97677. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  97678. +
  97679. + if (success != 0) {
  97680. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)",
  97681. + __func__, success);
  97682. + ret = -1;
  97683. + goto unlock;
  97684. + }
  97685. +
  97686. + ret = wait_for_completion_interruptible(&instance->msg_avail_comp);
  97687. + if (ret) {
  97688. + LOG_ERR("%s: failed on waiting for event (status=%d)",
  97689. + __func__, success);
  97690. + goto unlock;
  97691. + }
  97692. + if (instance->result != 0) {
  97693. + LOG_ERR("%s: failed result (status=%d)",
  97694. + __func__, instance->result);
  97695. +
  97696. + ret = -1;
  97697. + goto unlock;
  97698. + }
  97699. +
  97700. + ret = 0;
  97701. +
  97702. +unlock:
  97703. + vchi_service_release(instance->vchi_handle[0]);
  97704. + mutex_unlock(&instance->vchi_mutex);
  97705. +
  97706. + /* Stop the audio service */
  97707. + if (instance) {
  97708. + vc_vchi_audio_deinit(instance);
  97709. + alsa_stream->instance = NULL;
  97710. + }
  97711. + LOG_DBG(" .. OUT\n");
  97712. + return ret;
  97713. +}
  97714. +
  97715. +int bcm2835_audio_write_worker(bcm2835_alsa_stream_t *alsa_stream,
  97716. + uint32_t count, void *src)
  97717. +{
  97718. + VC_AUDIO_MSG_T m;
  97719. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  97720. + int32_t success;
  97721. + int ret;
  97722. +
  97723. + LOG_DBG(" .. IN\n");
  97724. +
  97725. + LOG_INFO(" Writing %d bytes from %p\n", count, src);
  97726. +
  97727. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  97728. + {
  97729. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  97730. + return -EINTR;
  97731. + }
  97732. + vchi_service_use(instance->vchi_handle[0]);
  97733. +
  97734. + if ( instance->peer_version==0 && vchi_get_peer_version(instance->vchi_handle[0], &instance->peer_version) == 0 ) {
  97735. + LOG_DBG("%s: client version %d connected\n", __func__, instance->peer_version);
  97736. + }
  97737. + m.type = VC_AUDIO_MSG_TYPE_WRITE;
  97738. + m.u.write.count = count;
  97739. + // old version uses bulk, new version uses control
  97740. + m.u.write.max_packet = instance->peer_version < 2 || force_bulk ? 0:4000;
  97741. + m.u.write.callback = alsa_stream->fifo_irq_handler;
  97742. + m.u.write.cookie = alsa_stream;
  97743. + m.u.write.silence = src == NULL;
  97744. +
  97745. + /* Send the message to the videocore */
  97746. + success = vchi_msg_queue(instance->vchi_handle[0],
  97747. + &m, sizeof m,
  97748. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  97749. +
  97750. + if (success != 0) {
  97751. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)",
  97752. + __func__, success);
  97753. +
  97754. + ret = -1;
  97755. + goto unlock;
  97756. + }
  97757. + if (!m.u.write.silence) {
  97758. + if (m.u.write.max_packet == 0) {
  97759. + /* Send the message to the videocore */
  97760. + success = vchi_bulk_queue_transmit(instance->vchi_handle[0],
  97761. + src, count,
  97762. + 0 *
  97763. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED
  97764. + +
  97765. + 1 *
  97766. + VCHI_FLAGS_BLOCK_UNTIL_DATA_READ,
  97767. + NULL);
  97768. + } else {
  97769. + while (count > 0) {
  97770. + int bytes = min((int)m.u.write.max_packet, (int)count);
  97771. + success = vchi_msg_queue(instance->vchi_handle[0],
  97772. + src, bytes,
  97773. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  97774. + src = (char *)src + bytes;
  97775. + count -= bytes;
  97776. + }
  97777. + }
  97778. + if (success != 0) {
  97779. + LOG_ERR
  97780. + ("%s: failed on vchi_bulk_queue_transmit (status=%d)",
  97781. + __func__, success);
  97782. +
  97783. + ret = -1;
  97784. + goto unlock;
  97785. + }
  97786. + }
  97787. + ret = 0;
  97788. +
  97789. +unlock:
  97790. + vchi_service_release(instance->vchi_handle[0]);
  97791. + mutex_unlock(&instance->vchi_mutex);
  97792. + LOG_DBG(" .. OUT\n");
  97793. + return ret;
  97794. +}
  97795. +
  97796. +/**
  97797. + * Returns all buffers from arm->vc
  97798. + */
  97799. +void bcm2835_audio_flush_buffers(bcm2835_alsa_stream_t * alsa_stream)
  97800. +{
  97801. + LOG_DBG(" .. IN\n");
  97802. + LOG_DBG(" .. OUT\n");
  97803. + return;
  97804. +}
  97805. +
  97806. +/**
  97807. + * Forces VC to flush(drop) its filled playback buffers and
  97808. + * return them the us. (VC->ARM)
  97809. + */
  97810. +void bcm2835_audio_flush_playback_buffers(bcm2835_alsa_stream_t * alsa_stream)
  97811. +{
  97812. + LOG_DBG(" .. IN\n");
  97813. + LOG_DBG(" .. OUT\n");
  97814. +}
  97815. +
  97816. +uint32_t bcm2835_audio_retrieve_buffers(bcm2835_alsa_stream_t * alsa_stream)
  97817. +{
  97818. + uint32_t count = atomic_read(&alsa_stream->retrieved);
  97819. + atomic_sub(count, &alsa_stream->retrieved);
  97820. + return count;
  97821. +}
  97822. +
  97823. +module_param(force_bulk, bool, 0444);
  97824. +MODULE_PARM_DESC(force_bulk, "Force use of vchiq bulk for audio");
  97825. diff -Nur linux-3.13.3.orig/sound/arm/Kconfig linux-3.13.3/sound/arm/Kconfig
  97826. --- linux-3.13.3.orig/sound/arm/Kconfig 2014-02-13 23:00:14.000000000 +0100
  97827. +++ linux-3.13.3/sound/arm/Kconfig 2014-02-17 22:41:02.000000000 +0100
  97828. @@ -39,5 +39,12 @@
  97829. Say Y or M if you want to support any AC97 codec attached to
  97830. the PXA2xx AC97 interface.
  97831. +config SND_BCM2835
  97832. + tristate "BCM2835 ALSA driver"
  97833. + depends on ARCH_BCM2708 && BCM2708_VCHIQ && SND
  97834. + select SND_PCM
  97835. + help
  97836. + Say Y or M if you want to support BCM2835 Alsa pcm card driver
  97837. +
  97838. endif # SND_ARM
  97839. diff -Nur linux-3.13.3.orig/sound/arm/Makefile linux-3.13.3/sound/arm/Makefile
  97840. --- linux-3.13.3.orig/sound/arm/Makefile 2014-02-13 23:00:14.000000000 +0100
  97841. +++ linux-3.13.3/sound/arm/Makefile 2014-02-17 22:41:02.000000000 +0100
  97842. @@ -14,3 +14,8 @@
  97843. obj-$(CONFIG_SND_PXA2XX_AC97) += snd-pxa2xx-ac97.o
  97844. snd-pxa2xx-ac97-objs := pxa2xx-ac97.o
  97845. +
  97846. +obj-$(CONFIG_SND_BCM2835) += snd-bcm2835.o
  97847. +snd-bcm2835-objs := bcm2835.o bcm2835-ctl.o bcm2835-pcm.o bcm2835-vchiq.o
  97848. +
  97849. +EXTRA_CFLAGS += -Idrivers/misc/vc04_services -Idrivers/misc/vc04_services/interface/vcos/linuxkernel -D__VCCOREVER__=0x04000000
  97850. diff -Nur linux-3.13.3.orig/sound/arm/vc_vchi_audioserv_defs.h linux-3.13.3/sound/arm/vc_vchi_audioserv_defs.h
  97851. --- linux-3.13.3.orig/sound/arm/vc_vchi_audioserv_defs.h 1970-01-01 01:00:00.000000000 +0100
  97852. +++ linux-3.13.3/sound/arm/vc_vchi_audioserv_defs.h 2014-02-17 22:41:02.000000000 +0100
  97853. @@ -0,0 +1,116 @@
  97854. +/*****************************************************************************
  97855. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  97856. +*
  97857. +* Unless you and Broadcom execute a separate written software license
  97858. +* agreement governing use of this software, this software is licensed to you
  97859. +* under the terms of the GNU General Public License version 2, available at
  97860. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  97861. +*
  97862. +* Notwithstanding the above, under no circumstances may you combine this
  97863. +* software in any way with any other Broadcom software provided under a
  97864. +* license other than the GPL, without Broadcom's express prior written
  97865. +* consent.
  97866. +*****************************************************************************/
  97867. +
  97868. +#ifndef _VC_AUDIO_DEFS_H_
  97869. +#define _VC_AUDIO_DEFS_H_
  97870. +
  97871. +#define VC_AUDIOSERV_MIN_VER 1
  97872. +#define VC_AUDIOSERV_VER 2
  97873. +
  97874. +// FourCC code used for VCHI connection
  97875. +#define VC_AUDIO_SERVER_NAME MAKE_FOURCC("AUDS")
  97876. +
  97877. +// Maximum message length
  97878. +#define VC_AUDIO_MAX_MSG_LEN (sizeof( VC_AUDIO_MSG_T ))
  97879. +
  97880. +// List of screens that are currently supported
  97881. +// All message types supported for HOST->VC direction
  97882. +typedef enum {
  97883. + VC_AUDIO_MSG_TYPE_RESULT, // Generic result
  97884. + VC_AUDIO_MSG_TYPE_COMPLETE, // Generic result
  97885. + VC_AUDIO_MSG_TYPE_CONFIG, // Configure audio
  97886. + VC_AUDIO_MSG_TYPE_CONTROL, // Configure audio
  97887. + VC_AUDIO_MSG_TYPE_OPEN, // Configure audio
  97888. + VC_AUDIO_MSG_TYPE_CLOSE, // Configure audio
  97889. + VC_AUDIO_MSG_TYPE_START, // Configure audio
  97890. + VC_AUDIO_MSG_TYPE_STOP, // Configure audio
  97891. + VC_AUDIO_MSG_TYPE_WRITE, // Configure audio
  97892. + VC_AUDIO_MSG_TYPE_MAX
  97893. +} VC_AUDIO_MSG_TYPE;
  97894. +
  97895. +// configure the audio
  97896. +typedef struct {
  97897. + uint32_t channels;
  97898. + uint32_t samplerate;
  97899. + uint32_t bps;
  97900. +
  97901. +} VC_AUDIO_CONFIG_T;
  97902. +
  97903. +typedef struct {
  97904. + uint32_t volume;
  97905. + uint32_t dest;
  97906. +
  97907. +} VC_AUDIO_CONTROL_T;
  97908. +
  97909. +// audio
  97910. +typedef struct {
  97911. + uint32_t dummy;
  97912. +
  97913. +} VC_AUDIO_OPEN_T;
  97914. +
  97915. +// audio
  97916. +typedef struct {
  97917. + uint32_t dummy;
  97918. +
  97919. +} VC_AUDIO_CLOSE_T;
  97920. +// audio
  97921. +typedef struct {
  97922. + uint32_t dummy;
  97923. +
  97924. +} VC_AUDIO_START_T;
  97925. +// audio
  97926. +typedef struct {
  97927. + uint32_t draining;
  97928. +
  97929. +} VC_AUDIO_STOP_T;
  97930. +
  97931. +// configure the write audio samples
  97932. +typedef struct {
  97933. + uint32_t count; // in bytes
  97934. + void *callback;
  97935. + void *cookie;
  97936. + uint16_t silence;
  97937. + uint16_t max_packet;
  97938. +} VC_AUDIO_WRITE_T;
  97939. +
  97940. +// Generic result for a request (VC->HOST)
  97941. +typedef struct {
  97942. + int32_t success; // Success value
  97943. +
  97944. +} VC_AUDIO_RESULT_T;
  97945. +
  97946. +// Generic result for a request (VC->HOST)
  97947. +typedef struct {
  97948. + int32_t count; // Success value
  97949. + void *callback;
  97950. + void *cookie;
  97951. +} VC_AUDIO_COMPLETE_T;
  97952. +
  97953. +// Message header for all messages in HOST->VC direction
  97954. +typedef struct {
  97955. + int32_t type; // Message type (VC_AUDIO_MSG_TYPE)
  97956. + union {
  97957. + VC_AUDIO_CONFIG_T config;
  97958. + VC_AUDIO_CONTROL_T control;
  97959. + VC_AUDIO_OPEN_T open;
  97960. + VC_AUDIO_CLOSE_T close;
  97961. + VC_AUDIO_START_T start;
  97962. + VC_AUDIO_STOP_T stop;
  97963. + VC_AUDIO_WRITE_T write;
  97964. + VC_AUDIO_RESULT_T result;
  97965. + VC_AUDIO_COMPLETE_T complete;
  97966. + } u;
  97967. +} VC_AUDIO_MSG_T;
  97968. +
  97969. +#endif // _VC_AUDIO_DEFS_H_
  97970. diff -Nur linux-3.13.3.orig/sound/soc/bcm/bcm2708-i2s.c linux-3.13.3/sound/soc/bcm/bcm2708-i2s.c
  97971. --- linux-3.13.3.orig/sound/soc/bcm/bcm2708-i2s.c 1970-01-01 01:00:00.000000000 +0100
  97972. +++ linux-3.13.3/sound/soc/bcm/bcm2708-i2s.c 2014-02-17 22:41:02.000000000 +0100
  97973. @@ -0,0 +1,945 @@
  97974. +/*
  97975. + * ALSA SoC I2S Audio Layer for Broadcom BCM2708 SoC
  97976. + *
  97977. + * Author: Florian Meier <florian.meier@koalo.de>
  97978. + * Copyright 2013
  97979. + *
  97980. + * Based on
  97981. + * Raspberry Pi PCM I2S ALSA Driver
  97982. + * Copyright (c) by Phil Poole 2013
  97983. + *
  97984. + * ALSA SoC I2S (McBSP) Audio Layer for TI DAVINCI processor
  97985. + * Vladimir Barinov, <vbarinov@embeddedalley.com>
  97986. + * Copyright (C) 2007 MontaVista Software, Inc., <source@mvista.com>
  97987. + *
  97988. + * OMAP ALSA SoC DAI driver using McBSP port
  97989. + * Copyright (C) 2008 Nokia Corporation
  97990. + * Contact: Jarkko Nikula <jarkko.nikula@bitmer.com>
  97991. + * Peter Ujfalusi <peter.ujfalusi@ti.com>
  97992. + *
  97993. + * Freescale SSI ALSA SoC Digital Audio Interface (DAI) driver
  97994. + * Author: Timur Tabi <timur@freescale.com>
  97995. + * Copyright 2007-2010 Freescale Semiconductor, Inc.
  97996. + *
  97997. + * This program is free software; you can redistribute it and/or
  97998. + * modify it under the terms of the GNU General Public License
  97999. + * version 2 as published by the Free Software Foundation.
  98000. + *
  98001. + * This program is distributed in the hope that it will be useful, but
  98002. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  98003. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  98004. + * General Public License for more details.
  98005. + */
  98006. +
  98007. +#include <linux/init.h>
  98008. +#include <linux/module.h>
  98009. +#include <linux/device.h>
  98010. +#include <linux/slab.h>
  98011. +#include <linux/delay.h>
  98012. +#include <linux/io.h>
  98013. +#include <linux/clk.h>
  98014. +
  98015. +#include <sound/core.h>
  98016. +#include <sound/pcm.h>
  98017. +#include <sound/pcm_params.h>
  98018. +#include <sound/initval.h>
  98019. +#include <sound/soc.h>
  98020. +#include <sound/dmaengine_pcm.h>
  98021. +
  98022. +/* Clock registers */
  98023. +#define BCM2708_CLK_PCMCTL_REG 0x00
  98024. +#define BCM2708_CLK_PCMDIV_REG 0x04
  98025. +
  98026. +/* Clock register settings */
  98027. +#define BCM2708_CLK_PASSWD (0x5a000000)
  98028. +#define BCM2708_CLK_PASSWD_MASK (0xff000000)
  98029. +#define BCM2708_CLK_MASH(v) ((v) << 9)
  98030. +#define BCM2708_CLK_FLIP BIT(8)
  98031. +#define BCM2708_CLK_BUSY BIT(7)
  98032. +#define BCM2708_CLK_KILL BIT(5)
  98033. +#define BCM2708_CLK_ENAB BIT(4)
  98034. +#define BCM2708_CLK_SRC(v) (v)
  98035. +
  98036. +#define BCM2708_CLK_SHIFT (12)
  98037. +#define BCM2708_CLK_DIVI(v) ((v) << BCM2708_CLK_SHIFT)
  98038. +#define BCM2708_CLK_DIVF(v) (v)
  98039. +#define BCM2708_CLK_DIVF_MASK (0xFFF)
  98040. +
  98041. +enum {
  98042. + BCM2708_CLK_MASH_0 = 0,
  98043. + BCM2708_CLK_MASH_1,
  98044. + BCM2708_CLK_MASH_2,
  98045. + BCM2708_CLK_MASH_3,
  98046. +};
  98047. +
  98048. +enum {
  98049. + BCM2708_CLK_SRC_GND = 0,
  98050. + BCM2708_CLK_SRC_OSC,
  98051. + BCM2708_CLK_SRC_DBG0,
  98052. + BCM2708_CLK_SRC_DBG1,
  98053. + BCM2708_CLK_SRC_PLLA,
  98054. + BCM2708_CLK_SRC_PLLC,
  98055. + BCM2708_CLK_SRC_PLLD,
  98056. + BCM2708_CLK_SRC_HDMI,
  98057. +};
  98058. +
  98059. +/* Most clocks are not useable (freq = 0) */
  98060. +static const unsigned int bcm2708_clk_freq[BCM2708_CLK_SRC_HDMI+1] = {
  98061. + [BCM2708_CLK_SRC_GND] = 0,
  98062. + [BCM2708_CLK_SRC_OSC] = 19200000,
  98063. + [BCM2708_CLK_SRC_DBG0] = 0,
  98064. + [BCM2708_CLK_SRC_DBG1] = 0,
  98065. + [BCM2708_CLK_SRC_PLLA] = 0,
  98066. + [BCM2708_CLK_SRC_PLLC] = 0,
  98067. + [BCM2708_CLK_SRC_PLLD] = 500000000,
  98068. + [BCM2708_CLK_SRC_HDMI] = 0,
  98069. +};
  98070. +
  98071. +/* I2S registers */
  98072. +#define BCM2708_I2S_CS_A_REG 0x00
  98073. +#define BCM2708_I2S_FIFO_A_REG 0x04
  98074. +#define BCM2708_I2S_MODE_A_REG 0x08
  98075. +#define BCM2708_I2S_RXC_A_REG 0x0c
  98076. +#define BCM2708_I2S_TXC_A_REG 0x10
  98077. +#define BCM2708_I2S_DREQ_A_REG 0x14
  98078. +#define BCM2708_I2S_INTEN_A_REG 0x18
  98079. +#define BCM2708_I2S_INTSTC_A_REG 0x1c
  98080. +#define BCM2708_I2S_GRAY_REG 0x20
  98081. +
  98082. +/* I2S register settings */
  98083. +#define BCM2708_I2S_STBY BIT(25)
  98084. +#define BCM2708_I2S_SYNC BIT(24)
  98085. +#define BCM2708_I2S_RXSEX BIT(23)
  98086. +#define BCM2708_I2S_RXF BIT(22)
  98087. +#define BCM2708_I2S_TXE BIT(21)
  98088. +#define BCM2708_I2S_RXD BIT(20)
  98089. +#define BCM2708_I2S_TXD BIT(19)
  98090. +#define BCM2708_I2S_RXR BIT(18)
  98091. +#define BCM2708_I2S_TXW BIT(17)
  98092. +#define BCM2708_I2S_CS_RXERR BIT(16)
  98093. +#define BCM2708_I2S_CS_TXERR BIT(15)
  98094. +#define BCM2708_I2S_RXSYNC BIT(14)
  98095. +#define BCM2708_I2S_TXSYNC BIT(13)
  98096. +#define BCM2708_I2S_DMAEN BIT(9)
  98097. +#define BCM2708_I2S_RXTHR(v) ((v) << 7)
  98098. +#define BCM2708_I2S_TXTHR(v) ((v) << 5)
  98099. +#define BCM2708_I2S_RXCLR BIT(4)
  98100. +#define BCM2708_I2S_TXCLR BIT(3)
  98101. +#define BCM2708_I2S_TXON BIT(2)
  98102. +#define BCM2708_I2S_RXON BIT(1)
  98103. +#define BCM2708_I2S_EN (1)
  98104. +
  98105. +#define BCM2708_I2S_CLKDIS BIT(28)
  98106. +#define BCM2708_I2S_PDMN BIT(27)
  98107. +#define BCM2708_I2S_PDME BIT(26)
  98108. +#define BCM2708_I2S_FRXP BIT(25)
  98109. +#define BCM2708_I2S_FTXP BIT(24)
  98110. +#define BCM2708_I2S_CLKM BIT(23)
  98111. +#define BCM2708_I2S_CLKI BIT(22)
  98112. +#define BCM2708_I2S_FSM BIT(21)
  98113. +#define BCM2708_I2S_FSI BIT(20)
  98114. +#define BCM2708_I2S_FLEN(v) ((v) << 10)
  98115. +#define BCM2708_I2S_FSLEN(v) (v)
  98116. +
  98117. +#define BCM2708_I2S_CHWEX BIT(15)
  98118. +#define BCM2708_I2S_CHEN BIT(14)
  98119. +#define BCM2708_I2S_CHPOS(v) ((v) << 4)
  98120. +#define BCM2708_I2S_CHWID(v) (v)
  98121. +#define BCM2708_I2S_CH1(v) ((v) << 16)
  98122. +#define BCM2708_I2S_CH2(v) (v)
  98123. +
  98124. +#define BCM2708_I2S_TX_PANIC(v) ((v) << 24)
  98125. +#define BCM2708_I2S_RX_PANIC(v) ((v) << 16)
  98126. +#define BCM2708_I2S_TX(v) ((v) << 8)
  98127. +#define BCM2708_I2S_RX(v) (v)
  98128. +
  98129. +#define BCM2708_I2S_INT_RXERR BIT(3)
  98130. +#define BCM2708_I2S_INT_TXERR BIT(2)
  98131. +#define BCM2708_I2S_INT_RXR BIT(1)
  98132. +#define BCM2708_I2S_INT_TXW BIT(0)
  98133. +
  98134. +/* I2S DMA interface */
  98135. +#define BCM2708_I2S_FIFO_PHYSICAL_ADDR 0x7E203004
  98136. +#define BCM2708_DMA_DREQ_PCM_TX 2
  98137. +#define BCM2708_DMA_DREQ_PCM_RX 3
  98138. +
  98139. +/* General device struct */
  98140. +struct bcm2708_i2s_dev {
  98141. + struct device *dev;
  98142. + struct snd_dmaengine_dai_dma_data dma_data[2];
  98143. + unsigned int fmt;
  98144. + unsigned int bclk_ratio;
  98145. +
  98146. + struct regmap *i2s_regmap;
  98147. + struct regmap *clk_regmap;
  98148. +};
  98149. +
  98150. +static void bcm2708_i2s_start_clock(struct bcm2708_i2s_dev *dev)
  98151. +{
  98152. + /* Start the clock if in master mode */
  98153. + unsigned int master = dev->fmt & SND_SOC_DAIFMT_MASTER_MASK;
  98154. +
  98155. + switch (master) {
  98156. + case SND_SOC_DAIFMT_CBS_CFS:
  98157. + case SND_SOC_DAIFMT_CBS_CFM:
  98158. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  98159. + BCM2708_CLK_PASSWD_MASK | BCM2708_CLK_ENAB,
  98160. + BCM2708_CLK_PASSWD | BCM2708_CLK_ENAB);
  98161. + break;
  98162. + default:
  98163. + break;
  98164. + }
  98165. +}
  98166. +
  98167. +static void bcm2708_i2s_stop_clock(struct bcm2708_i2s_dev *dev)
  98168. +{
  98169. + uint32_t clkreg;
  98170. + int timeout = 1000;
  98171. +
  98172. + /* Stop clock */
  98173. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  98174. + BCM2708_CLK_PASSWD_MASK | BCM2708_CLK_ENAB,
  98175. + BCM2708_CLK_PASSWD);
  98176. +
  98177. + /* Wait for the BUSY flag going down */
  98178. + while (--timeout) {
  98179. + regmap_read(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG, &clkreg);
  98180. + if (!(clkreg & BCM2708_CLK_BUSY))
  98181. + break;
  98182. + }
  98183. +
  98184. + if (!timeout) {
  98185. + /* KILL the clock */
  98186. + dev_err(dev->dev, "I2S clock didn't stop. Kill the clock!\n");
  98187. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  98188. + BCM2708_CLK_KILL | BCM2708_CLK_PASSWD_MASK,
  98189. + BCM2708_CLK_KILL | BCM2708_CLK_PASSWD);
  98190. + }
  98191. +}
  98192. +
  98193. +static void bcm2708_i2s_clear_fifos(struct bcm2708_i2s_dev *dev,
  98194. + bool tx, bool rx)
  98195. +{
  98196. + int timeout = 1000;
  98197. + uint32_t syncval;
  98198. + uint32_t csreg;
  98199. + uint32_t i2s_active_state;
  98200. + uint32_t clkreg;
  98201. + uint32_t clk_active_state;
  98202. + uint32_t off;
  98203. + uint32_t clr;
  98204. +
  98205. + off = tx ? BCM2708_I2S_TXON : 0;
  98206. + off |= rx ? BCM2708_I2S_RXON : 0;
  98207. +
  98208. + clr = tx ? BCM2708_I2S_TXCLR : 0;
  98209. + clr |= rx ? BCM2708_I2S_RXCLR : 0;
  98210. +
  98211. + /* Backup the current state */
  98212. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &csreg);
  98213. + i2s_active_state = csreg & (BCM2708_I2S_RXON | BCM2708_I2S_TXON);
  98214. +
  98215. + regmap_read(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG, &clkreg);
  98216. + clk_active_state = clkreg & BCM2708_CLK_ENAB;
  98217. +
  98218. + /* Start clock if not running */
  98219. + if (!clk_active_state) {
  98220. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  98221. + BCM2708_CLK_PASSWD_MASK | BCM2708_CLK_ENAB,
  98222. + BCM2708_CLK_PASSWD | BCM2708_CLK_ENAB);
  98223. + }
  98224. +
  98225. + /* Stop I2S module */
  98226. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, off, 0);
  98227. +
  98228. + /*
  98229. + * Clear the FIFOs
  98230. + * Requires at least 2 PCM clock cycles to take effect
  98231. + */
  98232. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, clr, clr);
  98233. +
  98234. + /* Wait for 2 PCM clock cycles */
  98235. +
  98236. + /*
  98237. + * Toggle the SYNC flag. After 2 PCM clock cycles it can be read back
  98238. + * FIXME: This does not seem to work for slave mode!
  98239. + */
  98240. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &syncval);
  98241. + syncval &= BCM2708_I2S_SYNC;
  98242. +
  98243. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  98244. + BCM2708_I2S_SYNC, ~syncval);
  98245. +
  98246. + /* Wait for the SYNC flag changing it's state */
  98247. + while (--timeout) {
  98248. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &csreg);
  98249. + if ((csreg & BCM2708_I2S_SYNC) != syncval)
  98250. + break;
  98251. + }
  98252. +
  98253. + if (!timeout)
  98254. + dev_err(dev->dev, "I2S SYNC error!\n");
  98255. +
  98256. + /* Stop clock if it was not running before */
  98257. + if (!clk_active_state)
  98258. + bcm2708_i2s_stop_clock(dev);
  98259. +
  98260. + /* Restore I2S state */
  98261. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  98262. + BCM2708_I2S_RXON | BCM2708_I2S_TXON, i2s_active_state);
  98263. +}
  98264. +
  98265. +static int bcm2708_i2s_set_dai_fmt(struct snd_soc_dai *dai,
  98266. + unsigned int fmt)
  98267. +{
  98268. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  98269. + dev->fmt = fmt;
  98270. + return 0;
  98271. +}
  98272. +
  98273. +static int bcm2708_i2s_set_dai_bclk_ratio(struct snd_soc_dai *dai,
  98274. + unsigned int ratio)
  98275. +{
  98276. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  98277. + dev->bclk_ratio = ratio;
  98278. + return 0;
  98279. +}
  98280. +
  98281. +static int bcm2708_i2s_hw_params(struct snd_pcm_substream *substream,
  98282. + struct snd_pcm_hw_params *params,
  98283. + struct snd_soc_dai *dai)
  98284. +{
  98285. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  98286. +
  98287. + unsigned int sampling_rate = params_rate(params);
  98288. + unsigned int data_length, data_delay, bclk_ratio;
  98289. + unsigned int ch1pos, ch2pos, mode, format;
  98290. + unsigned int mash = BCM2708_CLK_MASH_1;
  98291. + unsigned int divi, divf, target_frequency;
  98292. + int clk_src = -1;
  98293. + unsigned int master = dev->fmt & SND_SOC_DAIFMT_MASTER_MASK;
  98294. + bool bit_master = (master == SND_SOC_DAIFMT_CBS_CFS
  98295. + || master == SND_SOC_DAIFMT_CBS_CFM);
  98296. +
  98297. + bool frame_master = (master == SND_SOC_DAIFMT_CBS_CFS
  98298. + || master == SND_SOC_DAIFMT_CBM_CFS);
  98299. + uint32_t csreg;
  98300. +
  98301. + /*
  98302. + * If a stream is already enabled,
  98303. + * the registers are already set properly.
  98304. + */
  98305. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &csreg);
  98306. +
  98307. + if (csreg & (BCM2708_I2S_TXON | BCM2708_I2S_RXON))
  98308. + return 0;
  98309. +
  98310. + /*
  98311. + * Adjust the data length according to the format.
  98312. + * We prefill the half frame length with an integer
  98313. + * divider of 2400 as explained at the clock settings.
  98314. + * Maybe it is overwritten there, if the Integer mode
  98315. + * does not apply.
  98316. + */
  98317. + switch (params_format(params)) {
  98318. + case SNDRV_PCM_FORMAT_S16_LE:
  98319. + data_length = 16;
  98320. + bclk_ratio = 40;
  98321. + break;
  98322. + case SNDRV_PCM_FORMAT_S24_LE:
  98323. + data_length = 24;
  98324. + bclk_ratio = 40;
  98325. + break;
  98326. + case SNDRV_PCM_FORMAT_S32_LE:
  98327. + data_length = 32;
  98328. + bclk_ratio = 80;
  98329. + break;
  98330. + default:
  98331. + return -EINVAL;
  98332. + }
  98333. +
  98334. + /* If bclk_ratio already set, use that one. */
  98335. + if (dev->bclk_ratio)
  98336. + bclk_ratio = dev->bclk_ratio;
  98337. +
  98338. + /*
  98339. + * Clock Settings
  98340. + *
  98341. + * The target frequency of the bit clock is
  98342. + * sampling rate * frame length
  98343. + *
  98344. + * Integer mode:
  98345. + * Sampling rates that are multiples of 8000 kHz
  98346. + * can be driven by the oscillator of 19.2 MHz
  98347. + * with an integer divider as long as the frame length
  98348. + * is an integer divider of 19200000/8000=2400 as set up above.
  98349. + * This is no longer possible if the sampling rate
  98350. + * is too high (e.g. 192 kHz), because the oscillator is too slow.
  98351. + *
  98352. + * MASH mode:
  98353. + * For all other sampling rates, it is not possible to
  98354. + * have an integer divider. Approximate the clock
  98355. + * with the MASH module that induces a slight frequency
  98356. + * variance. To minimize that it is best to have the fastest
  98357. + * clock here. That is PLLD with 500 MHz.
  98358. + */
  98359. + target_frequency = sampling_rate * bclk_ratio;
  98360. + clk_src = BCM2708_CLK_SRC_OSC;
  98361. + mash = BCM2708_CLK_MASH_0;
  98362. +
  98363. + if (bcm2708_clk_freq[clk_src] % target_frequency == 0
  98364. + && bit_master && frame_master) {
  98365. + divi = bcm2708_clk_freq[clk_src] / target_frequency;
  98366. + divf = 0;
  98367. + } else {
  98368. + uint64_t dividend;
  98369. +
  98370. + if (!dev->bclk_ratio) {
  98371. + /*
  98372. + * Overwrite bclk_ratio, because the
  98373. + * above trick is not needed or can
  98374. + * not be used.
  98375. + */
  98376. + bclk_ratio = 2 * data_length;
  98377. + }
  98378. +
  98379. + target_frequency = sampling_rate * bclk_ratio;
  98380. +
  98381. + clk_src = BCM2708_CLK_SRC_PLLD;
  98382. + mash = BCM2708_CLK_MASH_1;
  98383. +
  98384. + dividend = bcm2708_clk_freq[clk_src];
  98385. + dividend <<= BCM2708_CLK_SHIFT;
  98386. + do_div(dividend, target_frequency);
  98387. + divi = dividend >> BCM2708_CLK_SHIFT;
  98388. + divf = dividend & BCM2708_CLK_DIVF_MASK;
  98389. + }
  98390. +
  98391. + /* Set clock divider */
  98392. + regmap_write(dev->clk_regmap, BCM2708_CLK_PCMDIV_REG, BCM2708_CLK_PASSWD
  98393. + | BCM2708_CLK_DIVI(divi)
  98394. + | BCM2708_CLK_DIVF(divf));
  98395. +
  98396. + /* Setup clock, but don't start it yet */
  98397. + regmap_write(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG, BCM2708_CLK_PASSWD
  98398. + | BCM2708_CLK_MASH(mash)
  98399. + | BCM2708_CLK_SRC(clk_src));
  98400. +
  98401. + /* Setup the frame format */
  98402. + format = BCM2708_I2S_CHEN;
  98403. +
  98404. + if (data_length >= 24)
  98405. + format |= BCM2708_I2S_CHWEX;
  98406. +
  98407. + format |= BCM2708_I2S_CHWID((data_length-8)&0xf);
  98408. +
  98409. + switch (dev->fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  98410. + case SND_SOC_DAIFMT_I2S:
  98411. + data_delay = 1;
  98412. + break;
  98413. + default:
  98414. + /*
  98415. + * TODO
  98416. + * Others are possible but are not implemented at the moment.
  98417. + */
  98418. + dev_err(dev->dev, "%s:bad format\n", __func__);
  98419. + return -EINVAL;
  98420. + }
  98421. +
  98422. + ch1pos = data_delay;
  98423. + ch2pos = bclk_ratio / 2 + data_delay;
  98424. +
  98425. + switch (params_channels(params)) {
  98426. + case 2:
  98427. + format = BCM2708_I2S_CH1(format) | BCM2708_I2S_CH2(format);
  98428. + format |= BCM2708_I2S_CH1(BCM2708_I2S_CHPOS(ch1pos));
  98429. + format |= BCM2708_I2S_CH2(BCM2708_I2S_CHPOS(ch2pos));
  98430. + break;
  98431. + default:
  98432. + return -EINVAL;
  98433. + }
  98434. +
  98435. + /*
  98436. + * Set format for both streams.
  98437. + * We cannot set another frame length
  98438. + * (and therefore word length) anyway,
  98439. + * so the format will be the same.
  98440. + */
  98441. + regmap_write(dev->i2s_regmap, BCM2708_I2S_RXC_A_REG, format);
  98442. + regmap_write(dev->i2s_regmap, BCM2708_I2S_TXC_A_REG, format);
  98443. +
  98444. + /* Setup the I2S mode */
  98445. + mode = 0;
  98446. +
  98447. + if (data_length <= 16) {
  98448. + /*
  98449. + * Use frame packed mode (2 channels per 32 bit word)
  98450. + * We cannot set another frame length in the second stream
  98451. + * (and therefore word length) anyway,
  98452. + * so the format will be the same.
  98453. + */
  98454. + mode |= BCM2708_I2S_FTXP | BCM2708_I2S_FRXP;
  98455. + }
  98456. +
  98457. + mode |= BCM2708_I2S_FLEN(bclk_ratio - 1);
  98458. + mode |= BCM2708_I2S_FSLEN(bclk_ratio / 2);
  98459. +
  98460. + /* Master or slave? */
  98461. + switch (dev->fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  98462. + case SND_SOC_DAIFMT_CBS_CFS:
  98463. + /* CPU is master */
  98464. + break;
  98465. + case SND_SOC_DAIFMT_CBM_CFS:
  98466. + /*
  98467. + * CODEC is bit clock master
  98468. + * CPU is frame master
  98469. + */
  98470. + mode |= BCM2708_I2S_CLKM;
  98471. + break;
  98472. + case SND_SOC_DAIFMT_CBS_CFM:
  98473. + /*
  98474. + * CODEC is frame master
  98475. + * CPU is bit clock master
  98476. + */
  98477. + mode |= BCM2708_I2S_FSM;
  98478. + break;
  98479. + case SND_SOC_DAIFMT_CBM_CFM:
  98480. + /* CODEC is master */
  98481. + mode |= BCM2708_I2S_CLKM;
  98482. + mode |= BCM2708_I2S_FSM;
  98483. + break;
  98484. + default:
  98485. + dev_err(dev->dev, "%s:bad master\n", __func__);
  98486. + return -EINVAL;
  98487. + }
  98488. +
  98489. + /*
  98490. + * Invert clocks?
  98491. + *
  98492. + * The BCM approach seems to be inverted to the classical I2S approach.
  98493. + */
  98494. + switch (dev->fmt & SND_SOC_DAIFMT_INV_MASK) {
  98495. + case SND_SOC_DAIFMT_NB_NF:
  98496. + /* None. Therefore, both for BCM */
  98497. + mode |= BCM2708_I2S_CLKI;
  98498. + mode |= BCM2708_I2S_FSI;
  98499. + break;
  98500. + case SND_SOC_DAIFMT_IB_IF:
  98501. + /* Both. Therefore, none for BCM */
  98502. + break;
  98503. + case SND_SOC_DAIFMT_NB_IF:
  98504. + /*
  98505. + * Invert only frame sync. Therefore,
  98506. + * invert only bit clock for BCM
  98507. + */
  98508. + mode |= BCM2708_I2S_CLKI;
  98509. + break;
  98510. + case SND_SOC_DAIFMT_IB_NF:
  98511. + /*
  98512. + * Invert only bit clock. Therefore,
  98513. + * invert only frame sync for BCM
  98514. + */
  98515. + mode |= BCM2708_I2S_FSI;
  98516. + break;
  98517. + default:
  98518. + return -EINVAL;
  98519. + }
  98520. +
  98521. + regmap_write(dev->i2s_regmap, BCM2708_I2S_MODE_A_REG, mode);
  98522. +
  98523. + /* Setup the DMA parameters */
  98524. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  98525. + BCM2708_I2S_RXTHR(1)
  98526. + | BCM2708_I2S_TXTHR(1)
  98527. + | BCM2708_I2S_DMAEN, 0xffffffff);
  98528. +
  98529. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_DREQ_A_REG,
  98530. + BCM2708_I2S_TX_PANIC(0x10)
  98531. + | BCM2708_I2S_RX_PANIC(0x30)
  98532. + | BCM2708_I2S_TX(0x30)
  98533. + | BCM2708_I2S_RX(0x20), 0xffffffff);
  98534. +
  98535. + /* Clear FIFOs */
  98536. + bcm2708_i2s_clear_fifos(dev, true, true);
  98537. +
  98538. + return 0;
  98539. +}
  98540. +
  98541. +static int bcm2708_i2s_prepare(struct snd_pcm_substream *substream,
  98542. + struct snd_soc_dai *dai)
  98543. +{
  98544. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  98545. + uint32_t cs_reg;
  98546. +
  98547. + bcm2708_i2s_start_clock(dev);
  98548. +
  98549. + /*
  98550. + * Clear both FIFOs if the one that should be started
  98551. + * is not empty at the moment. This should only happen
  98552. + * after overrun. Otherwise, hw_params would have cleared
  98553. + * the FIFO.
  98554. + */
  98555. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &cs_reg);
  98556. +
  98557. + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK
  98558. + && !(cs_reg & BCM2708_I2S_TXE))
  98559. + bcm2708_i2s_clear_fifos(dev, true, false);
  98560. + else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE
  98561. + && (cs_reg & BCM2708_I2S_RXD))
  98562. + bcm2708_i2s_clear_fifos(dev, false, true);
  98563. +
  98564. + return 0;
  98565. +}
  98566. +
  98567. +static void bcm2708_i2s_stop(struct bcm2708_i2s_dev *dev,
  98568. + struct snd_pcm_substream *substream,
  98569. + struct snd_soc_dai *dai)
  98570. +{
  98571. + uint32_t mask;
  98572. +
  98573. + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  98574. + mask = BCM2708_I2S_RXON;
  98575. + else
  98576. + mask = BCM2708_I2S_TXON;
  98577. +
  98578. + regmap_update_bits(dev->i2s_regmap,
  98579. + BCM2708_I2S_CS_A_REG, mask, 0);
  98580. +
  98581. + /* Stop also the clock when not SND_SOC_DAIFMT_CONT */
  98582. + if (!dai->active && !(dev->fmt & SND_SOC_DAIFMT_CONT))
  98583. + bcm2708_i2s_stop_clock(dev);
  98584. +}
  98585. +
  98586. +static int bcm2708_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
  98587. + struct snd_soc_dai *dai)
  98588. +{
  98589. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  98590. + uint32_t mask;
  98591. +
  98592. + switch (cmd) {
  98593. + case SNDRV_PCM_TRIGGER_START:
  98594. + case SNDRV_PCM_TRIGGER_RESUME:
  98595. + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  98596. + bcm2708_i2s_start_clock(dev);
  98597. +
  98598. + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  98599. + mask = BCM2708_I2S_RXON;
  98600. + else
  98601. + mask = BCM2708_I2S_TXON;
  98602. +
  98603. + regmap_update_bits(dev->i2s_regmap,
  98604. + BCM2708_I2S_CS_A_REG, mask, mask);
  98605. + break;
  98606. +
  98607. + case SNDRV_PCM_TRIGGER_STOP:
  98608. + case SNDRV_PCM_TRIGGER_SUSPEND:
  98609. + case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  98610. + bcm2708_i2s_stop(dev, substream, dai);
  98611. + break;
  98612. + default:
  98613. + return -EINVAL;
  98614. + }
  98615. +
  98616. + return 0;
  98617. +}
  98618. +
  98619. +static int bcm2708_i2s_startup(struct snd_pcm_substream *substream,
  98620. + struct snd_soc_dai *dai)
  98621. +{
  98622. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  98623. +
  98624. + if (dai->active)
  98625. + return 0;
  98626. +
  98627. + /* Should this still be running stop it */
  98628. + bcm2708_i2s_stop_clock(dev);
  98629. +
  98630. + /* Enable PCM block */
  98631. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  98632. + BCM2708_I2S_EN, BCM2708_I2S_EN);
  98633. +
  98634. + /*
  98635. + * Disable STBY.
  98636. + * Requires at least 4 PCM clock cycles to take effect.
  98637. + */
  98638. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  98639. + BCM2708_I2S_STBY, BCM2708_I2S_STBY);
  98640. +
  98641. + return 0;
  98642. +}
  98643. +
  98644. +static void bcm2708_i2s_shutdown(struct snd_pcm_substream *substream,
  98645. + struct snd_soc_dai *dai)
  98646. +{
  98647. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  98648. +
  98649. + bcm2708_i2s_stop(dev, substream, dai);
  98650. +
  98651. + /* If both streams are stopped, disable module and clock */
  98652. + if (dai->active)
  98653. + return;
  98654. +
  98655. + /* Disable the module */
  98656. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  98657. + BCM2708_I2S_EN, 0);
  98658. +
  98659. + /*
  98660. + * Stopping clock is necessary, because stop does
  98661. + * not stop the clock when SND_SOC_DAIFMT_CONT
  98662. + */
  98663. + bcm2708_i2s_stop_clock(dev);
  98664. +}
  98665. +
  98666. +static const struct snd_soc_dai_ops bcm2708_i2s_dai_ops = {
  98667. + .startup = bcm2708_i2s_startup,
  98668. + .shutdown = bcm2708_i2s_shutdown,
  98669. + .prepare = bcm2708_i2s_prepare,
  98670. + .trigger = bcm2708_i2s_trigger,
  98671. + .hw_params = bcm2708_i2s_hw_params,
  98672. + .set_fmt = bcm2708_i2s_set_dai_fmt,
  98673. + .set_bclk_ratio = bcm2708_i2s_set_dai_bclk_ratio
  98674. +};
  98675. +
  98676. +static int bcm2708_i2s_dai_probe(struct snd_soc_dai *dai)
  98677. +{
  98678. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  98679. +
  98680. + dai->playback_dma_data = &dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK];
  98681. + dai->capture_dma_data = &dev->dma_data[SNDRV_PCM_STREAM_CAPTURE];
  98682. +
  98683. + return 0;
  98684. +}
  98685. +
  98686. +static struct snd_soc_dai_driver bcm2708_i2s_dai = {
  98687. + .name = "bcm2708-i2s",
  98688. + .probe = bcm2708_i2s_dai_probe,
  98689. + .playback = {
  98690. + .channels_min = 2,
  98691. + .channels_max = 2,
  98692. + .rates = SNDRV_PCM_RATE_8000_192000,
  98693. + .formats = SNDRV_PCM_FMTBIT_S16_LE
  98694. + | SNDRV_PCM_FMTBIT_S24_LE
  98695. + | SNDRV_PCM_FMTBIT_S32_LE
  98696. + },
  98697. + .capture = {
  98698. + .channels_min = 2,
  98699. + .channels_max = 2,
  98700. + .rates = SNDRV_PCM_RATE_8000_192000,
  98701. + .formats = SNDRV_PCM_FMTBIT_S16_LE
  98702. + | SNDRV_PCM_FMTBIT_S24_LE
  98703. + | SNDRV_PCM_FMTBIT_S32_LE
  98704. + },
  98705. + .ops = &bcm2708_i2s_dai_ops,
  98706. + .symmetric_rates = 1
  98707. +};
  98708. +
  98709. +static bool bcm2708_i2s_volatile_reg(struct device *dev, unsigned int reg)
  98710. +{
  98711. + switch (reg) {
  98712. + case BCM2708_I2S_CS_A_REG:
  98713. + case BCM2708_I2S_FIFO_A_REG:
  98714. + case BCM2708_I2S_INTSTC_A_REG:
  98715. + case BCM2708_I2S_GRAY_REG:
  98716. + return true;
  98717. + default:
  98718. + return false;
  98719. + };
  98720. +}
  98721. +
  98722. +static bool bcm2708_i2s_precious_reg(struct device *dev, unsigned int reg)
  98723. +{
  98724. + switch (reg) {
  98725. + case BCM2708_I2S_FIFO_A_REG:
  98726. + return true;
  98727. + default:
  98728. + return false;
  98729. + };
  98730. +}
  98731. +
  98732. +static bool bcm2708_clk_volatile_reg(struct device *dev, unsigned int reg)
  98733. +{
  98734. + switch (reg) {
  98735. + case BCM2708_CLK_PCMCTL_REG:
  98736. + return true;
  98737. + default:
  98738. + return false;
  98739. + };
  98740. +}
  98741. +
  98742. +static const struct regmap_config bcm2708_regmap_config[] = {
  98743. + {
  98744. + .reg_bits = 32,
  98745. + .reg_stride = 4,
  98746. + .val_bits = 32,
  98747. + .max_register = BCM2708_I2S_GRAY_REG,
  98748. + .precious_reg = bcm2708_i2s_precious_reg,
  98749. + .volatile_reg = bcm2708_i2s_volatile_reg,
  98750. + .cache_type = REGCACHE_RBTREE,
  98751. + },
  98752. + {
  98753. + .reg_bits = 32,
  98754. + .reg_stride = 4,
  98755. + .val_bits = 32,
  98756. + .max_register = BCM2708_CLK_PCMDIV_REG,
  98757. + .volatile_reg = bcm2708_clk_volatile_reg,
  98758. + .cache_type = REGCACHE_RBTREE,
  98759. + },
  98760. +};
  98761. +
  98762. +static const struct snd_soc_component_driver bcm2708_i2s_component = {
  98763. + .name = "bcm2708-i2s-comp",
  98764. +};
  98765. +
  98766. +
  98767. +static void bcm2708_i2s_setup_gpio(void)
  98768. +{
  98769. + /*
  98770. + * This is the common way to handle the GPIO pins for
  98771. + * the Raspberry Pi.
  98772. + * TODO Better way would be to handle
  98773. + * this in the device tree!
  98774. + */
  98775. +#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
  98776. +#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
  98777. +
  98778. + unsigned int *gpio;
  98779. + int pin;
  98780. + gpio = ioremap(GPIO_BASE, SZ_16K);
  98781. +
  98782. + /* SPI is on GPIO 7..11 */
  98783. + for (pin = 28; pin <= 31; pin++) {
  98784. + INP_GPIO(pin); /* set mode to GPIO input first */
  98785. + SET_GPIO_ALT(pin, 2); /* set mode to ALT 0 */
  98786. + }
  98787. +#undef INP_GPIO
  98788. +#undef SET_GPIO_ALT
  98789. +}
  98790. +
  98791. +static const struct snd_pcm_hardware bcm2708_pcm_hardware = {
  98792. + .info = SNDRV_PCM_INFO_INTERLEAVED |
  98793. + SNDRV_PCM_INFO_JOINT_DUPLEX,
  98794. + .formats = SNDRV_PCM_FMTBIT_S16_LE |
  98795. + SNDRV_PCM_FMTBIT_S24_LE |
  98796. + SNDRV_PCM_FMTBIT_S32_LE,
  98797. + .period_bytes_min = 32,
  98798. + .period_bytes_max = 64 * PAGE_SIZE,
  98799. + .periods_min = 2,
  98800. + .periods_max = 255,
  98801. + .buffer_bytes_max = 128 * PAGE_SIZE,
  98802. +};
  98803. +
  98804. +static const struct snd_dmaengine_pcm_config bcm2708_dmaengine_pcm_config = {
  98805. + .prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config,
  98806. + .pcm_hardware = &bcm2708_pcm_hardware,
  98807. + .prealloc_buffer_size = 256 * PAGE_SIZE,
  98808. +};
  98809. +
  98810. +
  98811. +static int bcm2708_i2s_probe(struct platform_device *pdev)
  98812. +{
  98813. + struct bcm2708_i2s_dev *dev;
  98814. + int i;
  98815. + int ret;
  98816. + struct regmap *regmap[2];
  98817. + struct resource *mem[2];
  98818. +
  98819. + /* Request both ioareas */
  98820. + for (i = 0; i <= 1; i++) {
  98821. + void __iomem *base;
  98822. +
  98823. + mem[i] = platform_get_resource(pdev, IORESOURCE_MEM, i);
  98824. + base = devm_ioremap_resource(&pdev->dev, mem[i]);
  98825. + if (IS_ERR(base))
  98826. + return PTR_ERR(base);
  98827. +
  98828. + regmap[i] = devm_regmap_init_mmio(&pdev->dev, base,
  98829. + &bcm2708_regmap_config[i]);
  98830. + if (IS_ERR(regmap[i])) {
  98831. + dev_err(&pdev->dev, "I2S probe: regmap init failed\n");
  98832. + return PTR_ERR(regmap[i]);
  98833. + }
  98834. + }
  98835. +
  98836. + dev = devm_kzalloc(&pdev->dev, sizeof(*dev),
  98837. + GFP_KERNEL);
  98838. + if (IS_ERR(dev))
  98839. + return PTR_ERR(dev);
  98840. +
  98841. + bcm2708_i2s_setup_gpio();
  98842. +
  98843. + dev->i2s_regmap = regmap[0];
  98844. + dev->clk_regmap = regmap[1];
  98845. +
  98846. + /* Set the DMA address */
  98847. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].addr =
  98848. + (dma_addr_t)BCM2708_I2S_FIFO_PHYSICAL_ADDR;
  98849. +
  98850. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].addr =
  98851. + (dma_addr_t)BCM2708_I2S_FIFO_PHYSICAL_ADDR;
  98852. +
  98853. + /* Set the DREQ */
  98854. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].slave_id =
  98855. + BCM2708_DMA_DREQ_PCM_TX;
  98856. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].slave_id =
  98857. + BCM2708_DMA_DREQ_PCM_RX;
  98858. +
  98859. + /* Set the bus width */
  98860. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].addr_width =
  98861. + DMA_SLAVE_BUSWIDTH_4_BYTES;
  98862. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].addr_width =
  98863. + DMA_SLAVE_BUSWIDTH_4_BYTES;
  98864. +
  98865. + /* Set burst */
  98866. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].maxburst = 2;
  98867. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].maxburst = 2;
  98868. +
  98869. + /* BCLK ratio - use default */
  98870. + dev->bclk_ratio = 0;
  98871. +
  98872. + /* Store the pdev */
  98873. + dev->dev = &pdev->dev;
  98874. + dev_set_drvdata(&pdev->dev, dev);
  98875. +
  98876. + ret = snd_soc_register_component(&pdev->dev,
  98877. + &bcm2708_i2s_component, &bcm2708_i2s_dai, 1);
  98878. +
  98879. + if (ret) {
  98880. + dev_err(&pdev->dev, "Could not register DAI: %d\n", ret);
  98881. + ret = -ENOMEM;
  98882. + return ret;
  98883. + }
  98884. +
  98885. + ret = snd_dmaengine_pcm_register(&pdev->dev,
  98886. + &bcm2708_dmaengine_pcm_config,
  98887. + SND_DMAENGINE_PCM_FLAG_COMPAT);
  98888. + if (ret) {
  98889. + dev_err(&pdev->dev, "Could not register PCM: %d\n", ret);
  98890. + snd_soc_unregister_component(&pdev->dev);
  98891. + return ret;
  98892. + }
  98893. +
  98894. + return 0;
  98895. +}
  98896. +
  98897. +static int bcm2708_i2s_remove(struct platform_device *pdev)
  98898. +{
  98899. + snd_dmaengine_pcm_unregister(&pdev->dev);
  98900. + snd_soc_unregister_component(&pdev->dev);
  98901. + return 0;
  98902. +}
  98903. +
  98904. +static struct platform_driver bcm2708_i2s_driver = {
  98905. + .probe = bcm2708_i2s_probe,
  98906. + .remove = bcm2708_i2s_remove,
  98907. + .driver = {
  98908. + .name = "bcm2708-i2s",
  98909. + .owner = THIS_MODULE,
  98910. + },
  98911. +};
  98912. +
  98913. +module_platform_driver(bcm2708_i2s_driver);
  98914. +
  98915. +MODULE_ALIAS("platform:bcm2708-i2s");
  98916. +MODULE_DESCRIPTION("BCM2708 I2S interface");
  98917. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  98918. +MODULE_LICENSE("GPL v2");
  98919. diff -Nur linux-3.13.3.orig/sound/soc/bcm/hifiberry_dac.c linux-3.13.3/sound/soc/bcm/hifiberry_dac.c
  98920. --- linux-3.13.3.orig/sound/soc/bcm/hifiberry_dac.c 1970-01-01 01:00:00.000000000 +0100
  98921. +++ linux-3.13.3/sound/soc/bcm/hifiberry_dac.c 2014-02-17 22:41:02.000000000 +0100
  98922. @@ -0,0 +1,100 @@
  98923. +/*
  98924. + * ASoC Driver for HifiBerry DAC
  98925. + *
  98926. + * Author: Florian Meier <florian.meier@koalo.de>
  98927. + * Copyright 2013
  98928. + *
  98929. + * This program is free software; you can redistribute it and/or
  98930. + * modify it under the terms of the GNU General Public License
  98931. + * version 2 as published by the Free Software Foundation.
  98932. + *
  98933. + * This program is distributed in the hope that it will be useful, but
  98934. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  98935. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  98936. + * General Public License for more details.
  98937. + */
  98938. +
  98939. +#include <linux/module.h>
  98940. +#include <linux/platform_device.h>
  98941. +
  98942. +#include <sound/core.h>
  98943. +#include <sound/pcm.h>
  98944. +#include <sound/pcm_params.h>
  98945. +#include <sound/soc.h>
  98946. +#include <sound/jack.h>
  98947. +
  98948. +static int snd_rpi_hifiberry_dac_init(struct snd_soc_pcm_runtime *rtd)
  98949. +{
  98950. + return 0;
  98951. +}
  98952. +
  98953. +static int snd_rpi_hifiberry_dac_hw_params(struct snd_pcm_substream *substream,
  98954. + struct snd_pcm_hw_params *params)
  98955. +{
  98956. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  98957. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  98958. +
  98959. + unsigned int sample_bits =
  98960. + snd_pcm_format_physical_width(params_format(params));
  98961. +
  98962. + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
  98963. +}
  98964. +
  98965. +/* machine stream operations */
  98966. +static struct snd_soc_ops snd_rpi_hifiberry_dac_ops = {
  98967. + .hw_params = snd_rpi_hifiberry_dac_hw_params,
  98968. +};
  98969. +
  98970. +static struct snd_soc_dai_link snd_rpi_hifiberry_dac_dai[] = {
  98971. +{
  98972. + .name = "HifiBerry DAC",
  98973. + .stream_name = "HifiBerry DAC HiFi",
  98974. + .cpu_dai_name = "bcm2708-i2s.0",
  98975. + .codec_dai_name = "pcm5102a-hifi",
  98976. + .platform_name = "bcm2708-i2s.0",
  98977. + .codec_name = "pcm5102a-codec",
  98978. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  98979. + SND_SOC_DAIFMT_CBS_CFS,
  98980. + .ops = &snd_rpi_hifiberry_dac_ops,
  98981. + .init = snd_rpi_hifiberry_dac_init,
  98982. +},
  98983. +};
  98984. +
  98985. +/* audio machine driver */
  98986. +static struct snd_soc_card snd_rpi_hifiberry_dac = {
  98987. + .name = "snd_rpi_hifiberry_dac",
  98988. + .dai_link = snd_rpi_hifiberry_dac_dai,
  98989. + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dac_dai),
  98990. +};
  98991. +
  98992. +static int snd_rpi_hifiberry_dac_probe(struct platform_device *pdev)
  98993. +{
  98994. + int ret = 0;
  98995. +
  98996. + snd_rpi_hifiberry_dac.dev = &pdev->dev;
  98997. + ret = snd_soc_register_card(&snd_rpi_hifiberry_dac);
  98998. + if (ret)
  98999. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  99000. +
  99001. + return ret;
  99002. +}
  99003. +
  99004. +static int snd_rpi_hifiberry_dac_remove(struct platform_device *pdev)
  99005. +{
  99006. + return snd_soc_unregister_card(&snd_rpi_hifiberry_dac);
  99007. +}
  99008. +
  99009. +static struct platform_driver snd_rpi_hifiberry_dac_driver = {
  99010. + .driver = {
  99011. + .name = "snd-hifiberry-dac",
  99012. + .owner = THIS_MODULE,
  99013. + },
  99014. + .probe = snd_rpi_hifiberry_dac_probe,
  99015. + .remove = snd_rpi_hifiberry_dac_remove,
  99016. +};
  99017. +
  99018. +module_platform_driver(snd_rpi_hifiberry_dac_driver);
  99019. +
  99020. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  99021. +MODULE_DESCRIPTION("ASoC Driver for HifiBerry DAC");
  99022. +MODULE_LICENSE("GPL v2");
  99023. diff -Nur linux-3.13.3.orig/sound/soc/bcm/hifiberry_digi.c linux-3.13.3/sound/soc/bcm/hifiberry_digi.c
  99024. --- linux-3.13.3.orig/sound/soc/bcm/hifiberry_digi.c 1970-01-01 01:00:00.000000000 +0100
  99025. +++ linux-3.13.3/sound/soc/bcm/hifiberry_digi.c 2014-02-17 22:41:02.000000000 +0100
  99026. @@ -0,0 +1,153 @@
  99027. +/*
  99028. + * ASoC Driver for HifiBerry Digi
  99029. + *
  99030. + * Author: Daniel Matuschek <info@crazy-audio.com>
  99031. + * based on the HifiBerry DAC driver by Florian Meier <florian.meier@koalo.de>
  99032. + * Copyright 2013
  99033. + *
  99034. + * This program is free software; you can redistribute it and/or
  99035. + * modify it under the terms of the GNU General Public License
  99036. + * version 2 as published by the Free Software Foundation.
  99037. + *
  99038. + * This program is distributed in the hope that it will be useful, but
  99039. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  99040. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  99041. + * General Public License for more details.
  99042. + */
  99043. +
  99044. +#include <linux/module.h>
  99045. +#include <linux/platform_device.h>
  99046. +
  99047. +#include <sound/core.h>
  99048. +#include <sound/pcm.h>
  99049. +#include <sound/pcm_params.h>
  99050. +#include <sound/soc.h>
  99051. +#include <sound/jack.h>
  99052. +
  99053. +#include "../codecs/wm8804.h"
  99054. +
  99055. +static int samplerate=44100;
  99056. +
  99057. +static int snd_rpi_hifiberry_digi_init(struct snd_soc_pcm_runtime *rtd)
  99058. +{
  99059. + struct snd_soc_codec *codec = rtd->codec;
  99060. +
  99061. + /* enable TX output */
  99062. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
  99063. +
  99064. + return 0;
  99065. +}
  99066. +
  99067. +static int snd_rpi_hifiberry_digi_hw_params(struct snd_pcm_substream *substream,
  99068. + struct snd_pcm_hw_params *params)
  99069. +{
  99070. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  99071. + struct snd_soc_dai *codec_dai = rtd->codec_dai;
  99072. + struct snd_soc_codec *codec = rtd->codec;
  99073. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  99074. +
  99075. + int sysclk = 27000000; /* This is fixed on this board */
  99076. +
  99077. + long mclk_freq=0;
  99078. + int mclk_div=1;
  99079. +
  99080. + int ret;
  99081. +
  99082. + samplerate = params_rate(params);
  99083. +
  99084. + switch (samplerate) {
  99085. + case 44100:
  99086. + case 48000:
  99087. + case 88200:
  99088. + case 96000:
  99089. + mclk_freq=samplerate*256;
  99090. + mclk_div=WM8804_MCLKDIV_256FS;
  99091. + break;
  99092. + case 176400:
  99093. + case 192000:
  99094. + mclk_freq=samplerate*128;
  99095. + mclk_div=WM8804_MCLKDIV_128FS;
  99096. + break;
  99097. + default:
  99098. + dev_err(substream->pcm->dev,
  99099. + "Failed to set WM8804 SYSCLK, unsupported samplerate\n");
  99100. + }
  99101. +
  99102. + snd_soc_dai_set_clkdiv(codec_dai, WM8804_MCLK_DIV, mclk_div);
  99103. + snd_soc_dai_set_pll(codec_dai, 0, 0, sysclk, mclk_freq);
  99104. +
  99105. + ret = snd_soc_dai_set_sysclk(codec_dai, WM8804_TX_CLKSRC_PLL,
  99106. + sysclk, SND_SOC_CLOCK_OUT);
  99107. + if (ret < 0) {
  99108. + dev_err(substream->pcm->dev,
  99109. + "Failed to set WM8804 SYSCLK: %d\n", ret);
  99110. + return ret;
  99111. + }
  99112. +
  99113. + /* Enable TX output */
  99114. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
  99115. +
  99116. + /* Power on */
  99117. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x9, 0);
  99118. +
  99119. + return snd_soc_dai_set_bclk_ratio(cpu_dai,64);
  99120. +}
  99121. +
  99122. +/* machine stream operations */
  99123. +static struct snd_soc_ops snd_rpi_hifiberry_digi_ops = {
  99124. + .hw_params = snd_rpi_hifiberry_digi_hw_params,
  99125. +};
  99126. +
  99127. +static struct snd_soc_dai_link snd_rpi_hifiberry_digi_dai[] = {
  99128. +{
  99129. + .name = "HifiBerry Digi",
  99130. + .stream_name = "HifiBerry Digi HiFi",
  99131. + .cpu_dai_name = "bcm2708-i2s.0",
  99132. + .codec_dai_name = "wm8804-spdif",
  99133. + .platform_name = "bcm2708-i2s.0",
  99134. + .codec_name = "wm8804.1-003b",
  99135. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  99136. + SND_SOC_DAIFMT_CBM_CFM,
  99137. + .ops = &snd_rpi_hifiberry_digi_ops,
  99138. + .init = snd_rpi_hifiberry_digi_init,
  99139. +},
  99140. +};
  99141. +
  99142. +/* audio machine driver */
  99143. +static struct snd_soc_card snd_rpi_hifiberry_digi = {
  99144. + .name = "snd_rpi_hifiberry_digi",
  99145. + .dai_link = snd_rpi_hifiberry_digi_dai,
  99146. + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_digi_dai),
  99147. +};
  99148. +
  99149. +static int snd_rpi_hifiberry_digi_probe(struct platform_device *pdev)
  99150. +{
  99151. + int ret = 0;
  99152. +
  99153. + snd_rpi_hifiberry_digi.dev = &pdev->dev;
  99154. + ret = snd_soc_register_card(&snd_rpi_hifiberry_digi);
  99155. + if (ret)
  99156. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  99157. +
  99158. + return ret;
  99159. +}
  99160. +
  99161. +static int snd_rpi_hifiberry_digi_remove(struct platform_device *pdev)
  99162. +{
  99163. + return snd_soc_unregister_card(&snd_rpi_hifiberry_digi);
  99164. +}
  99165. +
  99166. +static struct platform_driver snd_rpi_hifiberry_digi_driver = {
  99167. + .driver = {
  99168. + .name = "snd-hifiberry-digi",
  99169. + .owner = THIS_MODULE,
  99170. + },
  99171. + .probe = snd_rpi_hifiberry_digi_probe,
  99172. + .remove = snd_rpi_hifiberry_digi_remove,
  99173. +};
  99174. +
  99175. +module_platform_driver(snd_rpi_hifiberry_digi_driver);
  99176. +
  99177. +MODULE_AUTHOR("Daniel Matuschek <info@crazy-audio.com>");
  99178. +MODULE_DESCRIPTION("ASoC Driver for HifiBerry Digi");
  99179. +MODULE_LICENSE("GPL v2");
  99180. diff -Nur linux-3.13.3.orig/sound/soc/bcm/Kconfig linux-3.13.3/sound/soc/bcm/Kconfig
  99181. --- linux-3.13.3.orig/sound/soc/bcm/Kconfig 1970-01-01 01:00:00.000000000 +0100
  99182. +++ linux-3.13.3/sound/soc/bcm/Kconfig 2014-02-17 22:41:02.000000000 +0100
  99183. @@ -0,0 +1,84 @@
  99184. +config SND_BCM2708_SOC_I2S
  99185. + tristate "SoC Audio support for the Broadcom BCM2708 I2S module"
  99186. + depends on MACH_BCM2708
  99187. + select REGMAP_MMIO
  99188. + select SND_SOC_DMAENGINE_PCM
  99189. + select SND_SOC_GENERIC_DMAENGINE_PCM
  99190. + help
  99191. + Say Y or M if you want to add support for codecs attached to
  99192. + the BCM2708 I2S interface. You will also need
  99193. + to select the audio interfaces to support below.
  99194. +
  99195. +config SND_BCM2708_SOC_HIFIBERRY_DAC
  99196. + tristate "Support for HifiBerry DAC"
  99197. + depends on SND_BCM2708_SOC_I2S
  99198. + select SND_SOC_PCM5102A
  99199. + help
  99200. + Say Y or M if you want to add support for HifiBerry DAC.
  99201. +
  99202. +config SND_BCM2708_SOC_HIFIBERRY_DIGI
  99203. + tristate "Support for HifiBerry Digi"
  99204. + depends on SND_BCM2708_SOC_I2S
  99205. + select SND_SOC_WM8804
  99206. + help
  99207. + Say Y or M if you want to add support for HifiBerry Digi S/PDIF output board.
  99208. +
  99209. +config SND_BCM2708_SOC_RPI_DAC
  99210. + tristate "Support for RPi-DAC"
  99211. + depends on SND_BCM2708_SOC_I2S
  99212. + select SND_SOC_PCM1794A
  99213. + help
  99214. + Say Y or M if you want to add support for RPi-DAC.
  99215. +
  99216. +config SND_BCM2708_SOC_I2S
  99217. + tristate "SoC Audio support for the Broadcom BCM2708 I2S module"
  99218. + depends on MACH_BCM2708
  99219. + select REGMAP_MMIO
  99220. + select SND_SOC_DMAENGINE_PCM
  99221. + select SND_SOC_GENERIC_DMAENGINE_PCM
  99222. + help
  99223. + Say Y or M if you want to add support for codecs attached to
  99224. + the BCM2708 I2S interface. You will also need
  99225. + to select the audio interfaces to support below.
  99226. +
  99227. +config SND_BCM2708_SOC_HIFIBERRY_MINI
  99228. + tristate "Support for HifiBerry Mini"
  99229. + depends on SND_BCM2708_SOC_I2S
  99230. + select SND_SOC_PCM5102A
  99231. + help
  99232. + Say Y or M if you want to add support for HifiBerry Mini.
  99233. +
  99234. +config SND_BCM2708_SOC_RPI_CODEC_MBED
  99235. + tristate "Support for AudioCODEC for mbed (TLV320AIC32B)"
  99236. + depends on SND_BCM2708_SOC_I2S
  99237. + select SND_SOC_TLV320AIC3X
  99238. + help
  99239. + Say Y if you want to add support for AudioCODEC for mbed (TLV320AIC32B)
  99240. +
  99241. +config SND_BCM2708_SOC_RPI_CODEC_TDA1541A
  99242. + tristate "Support for TDA1541A"
  99243. + depends on SND_BCM2708_SOC_I2S
  99244. + select SND_SOC_TDA1541A
  99245. + help
  99246. + Say Y if you want to add support for TDA1541A
  99247. +
  99248. +config SND_BCM2708_SOC_RPI_CODEC_PROTO
  99249. + tristate "Support for Audio Codec Board - PROTO (WM8731)"
  99250. + depends on SND_BCM2708_SOC_I2S
  99251. + select SND_SOC_WM8731
  99252. + help
  99253. + Say Y if you want to add support for Audio Codec Board - PROTO (WM8731)
  99254. +
  99255. +config SND_BCM2708_SOC_RPI_CODEC_ESS9018
  99256. + tristate "Support for ESS9018"
  99257. + depends on SND_BCM2708_SOC_I2S
  99258. + select SND_SOC_ESS9018
  99259. + help
  99260. + Say Y if you want to add support for ESS9018
  99261. +
  99262. +config SND_BCM2708_SOC_RPI_CODEC_PCM5102A
  99263. + tristate "Support for PCM5102A"
  99264. + depends on SND_BCM2708_SOC_I2S
  99265. + select SND_SOC_PCM5102A
  99266. + help
  99267. + Say Y if you want to add support for PCM5102A
  99268. diff -Nur linux-3.13.3.orig/sound/soc/bcm/Makefile linux-3.13.3/sound/soc/bcm/Makefile
  99269. --- linux-3.13.3.orig/sound/soc/bcm/Makefile 1970-01-01 01:00:00.000000000 +0100
  99270. +++ linux-3.13.3/sound/soc/bcm/Makefile 2014-02-17 22:41:02.000000000 +0100
  99271. @@ -0,0 +1,23 @@
  99272. +# BCM2708 Platform Support
  99273. +snd-soc-bcm2708-i2s-objs := bcm2708-i2s.o
  99274. +
  99275. +obj-$(CONFIG_SND_BCM2708_SOC_I2S) += snd-soc-bcm2708-i2s.o
  99276. +
  99277. +# BCM2708 Machine Support
  99278. +snd-soc-hifiberry-dac-objs := hifiberry_dac.o
  99279. +snd-soc-hifiberry-digi-objs := hifiberry_digi.o
  99280. +snd-soc-rpi-dac-objs := rpi-dac.o
  99281. +snd-soc-rpi-mbed-objs := rpi-mbed.o
  99282. +snd-soc-rpi-tda1541a-objs := rpi-tda1541a.o
  99283. +snd-soc-rpi-proto-objs := rpi-proto.o
  99284. +snd-soc-rpi-ess9018-objs := rpi-ess9018.o
  99285. +snd-soc-rpi-pcm5102a-objs := rpi-pcm5102a.o
  99286. +
  99287. +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
  99288. +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) += snd-soc-hifiberry-digi.o
  99289. +obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
  99290. +obj-$(CONFIG_SND_BCM2708_SOC_RPI_CODEC_MBED) += snd-soc-rpi-mbed.o
  99291. +obj-$(CONFIG_SND_BCM2708_SOC_RPI_CODEC_TDA1541A) += snd-soc-rpi-tda1541a.o
  99292. +obj-$(CONFIG_SND_BCM2708_SOC_RPI_CODEC_PROTO) += snd-soc-rpi-proto.o
  99293. +obj-$(CONFIG_SND_BCM2708_SOC_RPI_CODEC_ESS9018) += snd-soc-rpi-ess9018.o
  99294. +obj-$(CONFIG_SND_BCM2708_SOC_RPI_CODEC_PCM5102A) += snd-soc-rpi-pcm5102a.o
  99295. diff -Nur linux-3.13.3.orig/sound/soc/bcm/rpi-cs534x.c linux-3.13.3/sound/soc/bcm/rpi-cs534x.c
  99296. --- linux-3.13.3.orig/sound/soc/bcm/rpi-cs534x.c 1970-01-01 01:00:00.000000000 +0100
  99297. +++ linux-3.13.3/sound/soc/bcm/rpi-cs534x.c 2014-02-17 22:41:02.000000000 +0100
  99298. @@ -0,0 +1,105 @@
  99299. +/*
  99300. + * ASoC driver for CS5343/CS5344 ADC
  99301. + * connected to a Raspberry Pi
  99302. + *
  99303. + * Author: Wojciech M. Zabolotny <wzab01@gmail.com>
  99304. + * Based on rpi-ess9018.c by: Florian Meier, <koalo@koalo.de>
  99305. + * Copyright 2013
  99306. + *
  99307. + * This program is free software; you can redistribute it and/or modify
  99308. + * it under the terms of the GNU General Public License version 2 as
  99309. + * published by the Free Software Foundation.
  99310. + */
  99311. +
  99312. +#include <linux/module.h>
  99313. +#include <linux/platform_device.h>
  99314. +
  99315. +#include <sound/core.h>
  99316. +#include <sound/pcm.h>
  99317. +#include <sound/soc.h>
  99318. +#include <sound/jack.h>
  99319. +
  99320. +static int snd_rpi_cs534x_init(struct snd_soc_pcm_runtime *rtd)
  99321. +{
  99322. + return 0;
  99323. +}
  99324. +
  99325. +static int snd_rpi_cs534x_hw_params(struct snd_pcm_substream *substream,
  99326. + struct snd_pcm_hw_params *params)
  99327. +{
  99328. + return 0;
  99329. +}
  99330. +
  99331. +/* machine stream operations */
  99332. +static struct snd_soc_ops snd_rpi_cs534x_ops = {
  99333. + .hw_params = snd_rpi_cs534x_hw_params,
  99334. +};
  99335. +
  99336. +static struct snd_soc_dai_link snd_rpi_cs534x_dai[] = {
  99337. +{
  99338. + .name = "cs5343",
  99339. + .stream_name = "cs5343 HiFi",
  99340. + .cpu_dai_name = "bcm2708-i2s.0",
  99341. + .codec_dai_name = "cs534x-hifi",
  99342. + .platform_name = "bcm2708-pcm-audio.0",
  99343. + .codec_name = "cs534x-codec",
  99344. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  99345. + SND_SOC_DAIFMT_CBM_CFM,
  99346. + .ops = &snd_rpi_cs534x_ops,
  99347. + .init = snd_rpi_cs534x_init,
  99348. +},
  99349. +{
  99350. + .name = "cs5344",
  99351. + .stream_name = "cs5344 HiFi",
  99352. + .cpu_dai_name = "bcm2708-i2s.0",
  99353. + .codec_dai_name = "cs534x-hifi",
  99354. + .platform_name = "bcm2708-pcm-audio.0",
  99355. + .codec_name = "cs534x-codec",
  99356. + .dai_fmt = SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_NB_NF |
  99357. + SND_SOC_DAIFMT_CBM_CFM,
  99358. + .ops = &snd_rpi_cs534x_ops,
  99359. + .init = snd_rpi_cs534x_init,
  99360. +},
  99361. +};
  99362. +
  99363. +/* audio machine driver */
  99364. +static struct snd_soc_card snd_rpi_cs534x = {
  99365. + .name = "snd_rpi_cs534x",
  99366. + .dai_link = snd_rpi_cs534x_dai,
  99367. + .num_links = ARRAY_SIZE(snd_rpi_cs534x_dai),
  99368. +};
  99369. +
  99370. +static int snd_rpi_cs534x_probe(struct platform_device *pdev)
  99371. +{
  99372. + int ret = 0;
  99373. +
  99374. + snd_rpi_cs534x.dev = &pdev->dev;
  99375. + ret = snd_soc_register_card(&snd_rpi_cs534x);
  99376. + if (ret)
  99377. + {
  99378. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  99379. + }
  99380. +
  99381. + return ret;
  99382. +}
  99383. +
  99384. +
  99385. +static int snd_rpi_cs534x_remove(struct platform_device *pdev)
  99386. +{
  99387. + return snd_soc_unregister_card(&snd_rpi_cs534x);
  99388. +}
  99389. +
  99390. +static struct platform_driver snd_rpi_cs534x_driver = {
  99391. + .driver = {
  99392. + .name = "snd-rpi-cs534x",
  99393. + .owner = THIS_MODULE,
  99394. + },
  99395. + .probe = snd_rpi_cs534x_probe,
  99396. + .remove = snd_rpi_cs534x_remove,
  99397. +};
  99398. +
  99399. +module_platform_driver(snd_rpi_cs534x_driver);
  99400. +
  99401. +MODULE_AUTHOR("Wojciech M. Zabolotny");
  99402. +MODULE_DESCRIPTION("ASoC Driver for Raspberry Pi connected to a cs534x");
  99403. +MODULE_LICENSE("GPL");
  99404. diff -Nur linux-3.13.3.orig/sound/soc/bcm/rpi-dac.c linux-3.13.3/sound/soc/bcm/rpi-dac.c
  99405. --- linux-3.13.3.orig/sound/soc/bcm/rpi-dac.c 1970-01-01 01:00:00.000000000 +0100
  99406. +++ linux-3.13.3/sound/soc/bcm/rpi-dac.c 2014-02-17 22:41:02.000000000 +0100
  99407. @@ -0,0 +1,97 @@
  99408. +/*
  99409. + * ASoC Driver for RPi-DAC.
  99410. + *
  99411. + * Author: Florian Meier <florian.meier@koalo.de>
  99412. + * Copyright 2013
  99413. + *
  99414. + * This program is free software; you can redistribute it and/or
  99415. + * modify it under the terms of the GNU General Public License
  99416. + * version 2 as published by the Free Software Foundation.
  99417. + *
  99418. + * This program is distributed in the hope that it will be useful, but
  99419. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  99420. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  99421. + * General Public License for more details.
  99422. + */
  99423. +
  99424. +#include <linux/module.h>
  99425. +#include <linux/platform_device.h>
  99426. +
  99427. +#include <sound/core.h>
  99428. +#include <sound/pcm.h>
  99429. +#include <sound/pcm_params.h>
  99430. +#include <sound/soc.h>
  99431. +#include <sound/jack.h>
  99432. +
  99433. +static int snd_rpi_rpi_dac_init(struct snd_soc_pcm_runtime *rtd)
  99434. +{
  99435. + return 0;
  99436. +}
  99437. +
  99438. +static int snd_rpi_rpi_dac_hw_params(struct snd_pcm_substream *substream,
  99439. + struct snd_pcm_hw_params *params)
  99440. +{
  99441. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  99442. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  99443. +
  99444. + return snd_soc_dai_set_bclk_ratio(cpu_dai, 32*2);
  99445. +}
  99446. +
  99447. +/* machine stream operations */
  99448. +static struct snd_soc_ops snd_rpi_rpi_dac_ops = {
  99449. + .hw_params = snd_rpi_rpi_dac_hw_params,
  99450. +};
  99451. +
  99452. +static struct snd_soc_dai_link snd_rpi_rpi_dac_dai[] = {
  99453. +{
  99454. + .name = "HifiBerry Mini",
  99455. + .stream_name = "HifiBerry Mini HiFi",
  99456. + .cpu_dai_name = "bcm2708-i2s.0",
  99457. + .codec_dai_name = "pcm1794a-hifi",
  99458. + .platform_name = "bcm2708-i2s.0",
  99459. + .codec_name = "pcm1794a-codec",
  99460. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  99461. + SND_SOC_DAIFMT_CBS_CFS,
  99462. + .ops = &snd_rpi_rpi_dac_ops,
  99463. + .init = snd_rpi_rpi_dac_init,
  99464. +},
  99465. +};
  99466. +
  99467. +/* audio machine driver */
  99468. +static struct snd_soc_card snd_rpi_rpi_dac = {
  99469. + .name = "snd_rpi_rpi_dac",
  99470. + .dai_link = snd_rpi_rpi_dac_dai,
  99471. + .num_links = ARRAY_SIZE(snd_rpi_rpi_dac_dai),
  99472. +};
  99473. +
  99474. +static int snd_rpi_rpi_dac_probe(struct platform_device *pdev)
  99475. +{
  99476. + int ret = 0;
  99477. +
  99478. + snd_rpi_rpi_dac.dev = &pdev->dev;
  99479. + ret = snd_soc_register_card(&snd_rpi_rpi_dac);
  99480. + if (ret)
  99481. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  99482. +
  99483. + return ret;
  99484. +}
  99485. +
  99486. +static int snd_rpi_rpi_dac_remove(struct platform_device *pdev)
  99487. +{
  99488. + return snd_soc_unregister_card(&snd_rpi_rpi_dac);
  99489. +}
  99490. +
  99491. +static struct platform_driver snd_rpi_rpi_dac_driver = {
  99492. + .driver = {
  99493. + .name = "snd-rpi-dac",
  99494. + .owner = THIS_MODULE,
  99495. + },
  99496. + .probe = snd_rpi_rpi_dac_probe,
  99497. + .remove = snd_rpi_rpi_dac_remove,
  99498. +};
  99499. +
  99500. +module_platform_driver(snd_rpi_rpi_dac_driver);
  99501. +
  99502. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  99503. +MODULE_DESCRIPTION("ASoC Driver for RPi-DAC");
  99504. +MODULE_LICENSE("GPL v2");
  99505. diff -Nur linux-3.13.3.orig/sound/soc/bcm/rpi-ess9018.c linux-3.13.3/sound/soc/bcm/rpi-ess9018.c
  99506. --- linux-3.13.3.orig/sound/soc/bcm/rpi-ess9018.c 1970-01-01 01:00:00.000000000 +0100
  99507. +++ linux-3.13.3/sound/soc/bcm/rpi-ess9018.c 2014-02-17 22:41:02.000000000 +0100
  99508. @@ -0,0 +1,92 @@
  99509. +/*
  99510. + * ASoC driver for ESS9018 codec
  99511. + * connected to a Raspberry Pi
  99512. + *
  99513. + * Author: Florian Meier, <koalo@koalo.de>
  99514. + * Copyright 2013
  99515. + *
  99516. + * This program is free software; you can redistribute it and/or modify
  99517. + * it under the terms of the GNU General Public License version 2 as
  99518. + * published by the Free Software Foundation.
  99519. + */
  99520. +
  99521. +#include <linux/module.h>
  99522. +#include <linux/platform_device.h>
  99523. +
  99524. +#include <sound/core.h>
  99525. +#include <sound/pcm.h>
  99526. +#include <sound/soc.h>
  99527. +#include <sound/jack.h>
  99528. +
  99529. +static int snd_rpi_ess9018_init(struct snd_soc_pcm_runtime *rtd)
  99530. +{
  99531. + return 0;
  99532. +}
  99533. +
  99534. +static int snd_rpi_ess9018_hw_params(struct snd_pcm_substream *substream,
  99535. + struct snd_pcm_hw_params *params)
  99536. +{
  99537. + return 0;
  99538. +}
  99539. +
  99540. +/* machine stream operations */
  99541. +static struct snd_soc_ops snd_rpi_ess9018_ops = {
  99542. + .hw_params = snd_rpi_ess9018_hw_params,
  99543. +};
  99544. +
  99545. +static struct snd_soc_dai_link snd_rpi_ess9018_dai[] = {
  99546. +{
  99547. + .name = "ESS9018",
  99548. + .stream_name = "ESS9018 HiFi",
  99549. + .cpu_dai_name = "bcm2708-i2s.0",
  99550. + .codec_dai_name = "ess9018-hifi",
  99551. + .platform_name = "bcm2708-i2s.0",
  99552. + .codec_name = "ess9018-codec",
  99553. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  99554. + SND_SOC_DAIFMT_CBS_CFS,
  99555. + .ops = &snd_rpi_ess9018_ops,
  99556. + .init = snd_rpi_ess9018_init,
  99557. +},
  99558. +};
  99559. +
  99560. +/* audio machine driver */
  99561. +static struct snd_soc_card snd_rpi_ess9018 = {
  99562. + .name = "snd_rpi_ess9018",
  99563. + .dai_link = snd_rpi_ess9018_dai,
  99564. + .num_links = ARRAY_SIZE(snd_rpi_ess9018_dai),
  99565. +};
  99566. +
  99567. +static int snd_rpi_ess9018_probe(struct platform_device *pdev)
  99568. +{
  99569. + int ret = 0;
  99570. +
  99571. + snd_rpi_ess9018.dev = &pdev->dev;
  99572. + ret = snd_soc_register_card(&snd_rpi_ess9018);
  99573. + if (ret)
  99574. + {
  99575. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  99576. + }
  99577. +
  99578. + return ret;
  99579. +}
  99580. +
  99581. +
  99582. +static int snd_rpi_ess9018_remove(struct platform_device *pdev)
  99583. +{
  99584. + return snd_soc_unregister_card(&snd_rpi_ess9018);
  99585. +}
  99586. +
  99587. +static struct platform_driver snd_rpi_ess9018_driver = {
  99588. + .driver = {
  99589. + .name = "snd-rpi-ess9018",
  99590. + .owner = THIS_MODULE,
  99591. + },
  99592. + .probe = snd_rpi_ess9018_probe,
  99593. + .remove = snd_rpi_ess9018_remove,
  99594. +};
  99595. +
  99596. +module_platform_driver(snd_rpi_ess9018_driver);
  99597. +
  99598. +MODULE_AUTHOR("Florian Meier");
  99599. +MODULE_DESCRIPTION("ASoC Driver for Raspberry Pi connected to a ESS9018");
  99600. +MODULE_LICENSE("GPL");
  99601. diff -Nur linux-3.13.3.orig/sound/soc/bcm/rpi-mbed.c linux-3.13.3/sound/soc/bcm/rpi-mbed.c
  99602. --- linux-3.13.3.orig/sound/soc/bcm/rpi-mbed.c 1970-01-01 01:00:00.000000000 +0100
  99603. +++ linux-3.13.3/sound/soc/bcm/rpi-mbed.c 2014-02-17 22:41:02.000000000 +0100
  99604. @@ -0,0 +1,103 @@
  99605. +/*
  99606. + * ASoC driver for mbed AudioCODEC (with a TLV320AIC23b)
  99607. + * connected to a Raspberry Pi
  99608. + *
  99609. + * Author: Florian Meier, <koalo@koalo.de>
  99610. + * Copyright 2013
  99611. + *
  99612. + * This program is free software; you can redistribute it and/or modify
  99613. + * it under the terms of the GNU General Public License version 2 as
  99614. + * published by the Free Software Foundation.
  99615. + */
  99616. +
  99617. +#include <linux/module.h>
  99618. +#include <linux/platform_device.h>
  99619. +
  99620. +#include <sound/core.h>
  99621. +#include <sound/pcm.h>
  99622. +#include <sound/soc.h>
  99623. +#include <sound/jack.h>
  99624. +
  99625. +#include "../codecs/tlv320aic23.h"
  99626. +
  99627. +static int snd_rpi_mbed_init(struct snd_soc_pcm_runtime *rtd)
  99628. +{
  99629. + return 0;
  99630. +}
  99631. +
  99632. +static int snd_rpi_mbed_hw_params(struct snd_pcm_substream *substream,
  99633. + struct snd_pcm_hw_params *params)
  99634. +{
  99635. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  99636. + struct snd_soc_dai *codec_dai = rtd->codec_dai;
  99637. + int sysclk;
  99638. +
  99639. + sysclk = 12000000; /* this is fixed on this board */
  99640. +
  99641. + /* set tlv320aic23 sysclk */
  99642. + snd_soc_dai_set_sysclk(codec_dai, 0, sysclk, 0);
  99643. +
  99644. + return 0;
  99645. +}
  99646. +
  99647. +/* machine stream operations */
  99648. +static struct snd_soc_ops snd_rpi_mbed_ops = {
  99649. + .hw_params = snd_rpi_mbed_hw_params,
  99650. +};
  99651. +
  99652. +static struct snd_soc_dai_link snd_rpi_mbed_dai[] = {
  99653. +{
  99654. + .name = "TLV320AIC23",
  99655. + .stream_name = "TLV320AIC23 HiFi",
  99656. + .cpu_dai_name = "bcm2708-i2s.0",
  99657. + .codec_dai_name = "tlv320aic23-hifi",
  99658. + .platform_name = "bcm2708-i2s.0",
  99659. + .codec_name = "tlv320aic23-codec.1-001b",
  99660. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  99661. + SND_SOC_DAIFMT_CBS_CFS,
  99662. + .ops = &snd_rpi_mbed_ops,
  99663. + .init = snd_rpi_mbed_init,
  99664. +},
  99665. +};
  99666. +
  99667. +/* audio machine driver */
  99668. +static struct snd_soc_card snd_rpi_mbed = {
  99669. + .name = "snd_rpi_mbed",
  99670. + .dai_link = snd_rpi_mbed_dai,
  99671. + .num_links = ARRAY_SIZE(snd_rpi_mbed_dai),
  99672. +};
  99673. +
  99674. +static int snd_rpi_mbed_probe(struct platform_device *pdev)
  99675. +{
  99676. + int ret = 0;
  99677. +
  99678. + snd_rpi_mbed.dev = &pdev->dev;
  99679. + ret = snd_soc_register_card(&snd_rpi_mbed);
  99680. + if (ret) {
  99681. + dev_err(&pdev->dev,
  99682. + "snd_soc_register_card() failed: %d\n", ret);
  99683. + }
  99684. +
  99685. + return ret;
  99686. +}
  99687. +
  99688. +
  99689. +static int snd_rpi_mbed_remove(struct platform_device *pdev)
  99690. +{
  99691. + return snd_soc_unregister_card(&snd_rpi_mbed);
  99692. +}
  99693. +
  99694. +static struct platform_driver snd_rpi_mbed_driver = {
  99695. + .driver = {
  99696. + .name = "snd-rpi-mbed",
  99697. + .owner = THIS_MODULE,
  99698. + },
  99699. + .probe = snd_rpi_mbed_probe,
  99700. + .remove = snd_rpi_mbed_remove,
  99701. +};
  99702. +
  99703. +module_platform_driver(snd_rpi_mbed_driver);
  99704. +
  99705. +MODULE_AUTHOR("Florian Meier");
  99706. +MODULE_DESCRIPTION("ASoC Driver for Raspberry Pi connected to mbed AudioCODEC");
  99707. +MODULE_LICENSE("GPL");
  99708. diff -Nur linux-3.13.3.orig/sound/soc/bcm/rpi-pcm5102a.c linux-3.13.3/sound/soc/bcm/rpi-pcm5102a.c
  99709. --- linux-3.13.3.orig/sound/soc/bcm/rpi-pcm5102a.c 1970-01-01 01:00:00.000000000 +0100
  99710. +++ linux-3.13.3/sound/soc/bcm/rpi-pcm5102a.c 2014-02-17 22:41:02.000000000 +0100
  99711. @@ -0,0 +1,93 @@
  99712. +/*
  99713. + * ASoC driver for PCM5102A codec
  99714. + * connected to a Raspberry Pi
  99715. + *
  99716. + * Author: Francesco Valla, <valla.francesco@gmail.com>
  99717. + * Based on rpi-ess9018.c by: Florian Meier, <koalo@koalo.de>
  99718. + * Copyright 2013
  99719. + *
  99720. + * This program is free software; you can redistribute it and/or modify
  99721. + * it under the terms of the GNU General Public License version 2 as
  99722. + * published by the Free Software Foundation.
  99723. + */
  99724. +
  99725. +#include <linux/module.h>
  99726. +#include <linux/platform_device.h>
  99727. +
  99728. +#include <sound/core.h>
  99729. +#include <sound/pcm.h>
  99730. +#include <sound/soc.h>
  99731. +#include <sound/jack.h>
  99732. +
  99733. +static int snd_rpi_pcm5102a_init(struct snd_soc_pcm_runtime *rtd)
  99734. +{
  99735. + return 0;
  99736. +}
  99737. +
  99738. +static int snd_rpi_pcm5102a_hw_params(struct snd_pcm_substream *substream,
  99739. + struct snd_pcm_hw_params *params)
  99740. +{
  99741. + return 0;
  99742. +}
  99743. +
  99744. +/* machine stream operations */
  99745. +static struct snd_soc_ops snd_rpi_pcm5102a_ops = {
  99746. + .hw_params = snd_rpi_pcm5102a_hw_params,
  99747. +};
  99748. +
  99749. +static struct snd_soc_dai_link snd_rpi_pcm5102a_dai[] = {
  99750. +{
  99751. + .name = "PCM5102A",
  99752. + .stream_name = "PCM5102A HiFi",
  99753. + .cpu_dai_name = "bcm2708-i2s.0",
  99754. + .codec_dai_name = "pcm5102a-hifi",
  99755. + .platform_name = "bcm2708-pcm-audio.0",
  99756. + .codec_name = "pcm5102a-codec",
  99757. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  99758. + SND_SOC_DAIFMT_CBS_CFS,
  99759. + .ops = &snd_rpi_pcm5102a_ops,
  99760. + .init = snd_rpi_pcm5102a_init,
  99761. +},
  99762. +};
  99763. +
  99764. +/* audio machine driver */
  99765. +static struct snd_soc_card snd_rpi_pcm5102a = {
  99766. + .name = "snd_rpi_pcm5102a",
  99767. + .dai_link = snd_rpi_pcm5102a_dai,
  99768. + .num_links = ARRAY_SIZE(snd_rpi_pcm5102a_dai),
  99769. +};
  99770. +
  99771. +static int snd_rpi_pcm5102a_probe(struct platform_device *pdev)
  99772. +{
  99773. + int ret = 0;
  99774. +
  99775. + snd_rpi_pcm5102a.dev = &pdev->dev;
  99776. + ret = snd_soc_register_card(&snd_rpi_pcm5102a);
  99777. + if (ret)
  99778. + {
  99779. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  99780. + }
  99781. +
  99782. + return ret;
  99783. +}
  99784. +
  99785. +
  99786. +static int snd_rpi_pcm5102a_remove(struct platform_device *pdev)
  99787. +{
  99788. + return snd_soc_unregister_card(&snd_rpi_pcm5102a);
  99789. +}
  99790. +
  99791. +static struct platform_driver snd_rpi_pcm5102a_driver = {
  99792. + .driver = {
  99793. + .name = "snd-rpi-pcm5102a",
  99794. + .owner = THIS_MODULE,
  99795. + },
  99796. + .probe = snd_rpi_pcm5102a_probe,
  99797. + .remove = snd_rpi_pcm5102a_remove,
  99798. +};
  99799. +
  99800. +module_platform_driver(snd_rpi_pcm5102a_driver);
  99801. +
  99802. +MODULE_AUTHOR("Francesco Valla");
  99803. +MODULE_DESCRIPTION("ASoC Driver for Raspberry Pi connected to a PCM5102A");
  99804. +MODULE_LICENSE("GPL");
  99805. diff -Nur linux-3.13.3.orig/sound/soc/bcm/rpi-proto.c linux-3.13.3/sound/soc/bcm/rpi-proto.c
  99806. --- linux-3.13.3.orig/sound/soc/bcm/rpi-proto.c 1970-01-01 01:00:00.000000000 +0100
  99807. +++ linux-3.13.3/sound/soc/bcm/rpi-proto.c 2014-02-17 22:41:02.000000000 +0100
  99808. @@ -0,0 +1,130 @@
  99809. +/*
  99810. + * ASoC driver for PROTO AudioCODEC (with a WM8731)
  99811. + * connected to a Raspberry Pi
  99812. + *
  99813. + * Author: Florian Meier, <koalo@koalo.de>
  99814. + * Copyright 2013
  99815. + *
  99816. + * This program is free software; you can redistribute it and/or modify
  99817. + * it under the terms of the GNU General Public License version 2 as
  99818. + * published by the Free Software Foundation.
  99819. + */
  99820. +
  99821. +#include <linux/module.h>
  99822. +#include <linux/platform_device.h>
  99823. +
  99824. +#include <sound/core.h>
  99825. +#include <sound/pcm.h>
  99826. +#include <sound/soc.h>
  99827. +#include <sound/jack.h>
  99828. +
  99829. +#include "../codecs/wm8731.h"
  99830. +
  99831. +static const unsigned int wm8731_rates_12288000[] = {
  99832. + 8000, 32000, 48000, 96000,
  99833. +};
  99834. +
  99835. +static struct snd_pcm_hw_constraint_list wm8731_constraints_12288000 = {
  99836. + .list = wm8731_rates_12288000,
  99837. + .count = ARRAY_SIZE(wm8731_rates_12288000),
  99838. +};
  99839. +
  99840. +static int snd_rpi_proto_startup(struct snd_pcm_substream *substream)
  99841. +{
  99842. + /* Setup constraints, because there is a 12.288 MHz XTAL on the board */
  99843. + snd_pcm_hw_constraint_list(substream->runtime, 0,
  99844. + SNDRV_PCM_HW_PARAM_RATE,
  99845. + &wm8731_constraints_12288000);
  99846. + return 0;
  99847. +}
  99848. +
  99849. +static int snd_rpi_proto_hw_params(struct snd_pcm_substream *substream,
  99850. + struct snd_pcm_hw_params *params)
  99851. +{
  99852. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  99853. + struct snd_soc_dai *codec_dai = rtd->codec_dai;
  99854. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  99855. + int sysclk = 12288000; /* This is fixed on this board */
  99856. +
  99857. + /* Set proto bclk */
  99858. + int ret = snd_soc_dai_set_bclk_ratio(cpu_dai,32*2);
  99859. + if (ret < 0){
  99860. + dev_err(substream->pcm->dev,
  99861. + "Failed to set WM8731 BCLK ratio %d\n", ret);
  99862. + return ret;
  99863. + }
  99864. +
  99865. + /* Set proto sysclk */
  99866. + ret = snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK_XTAL,
  99867. + sysclk, SND_SOC_CLOCK_IN);
  99868. + if (ret < 0) {
  99869. + dev_err(substream->pcm->dev,
  99870. + "Failed to set WM8731 SYSCLK: %d\n", ret);
  99871. + return ret;
  99872. + }
  99873. +
  99874. + return 0;
  99875. +}
  99876. +
  99877. +/* machine stream operations */
  99878. +static struct snd_soc_ops snd_rpi_proto_ops = {
  99879. + .startup = snd_rpi_proto_startup,
  99880. + .hw_params = snd_rpi_proto_hw_params,
  99881. +};
  99882. +
  99883. +static struct snd_soc_dai_link snd_rpi_proto_dai[] = {
  99884. +{
  99885. + .name = "WM8731",
  99886. + .stream_name = "WM8731 HiFi",
  99887. + .cpu_dai_name = "bcm2708-i2s.0",
  99888. + .codec_dai_name = "wm8731-hifi",
  99889. + .platform_name = "bcm2708-i2s.0",
  99890. + .codec_name = "wm8731.1-001a",
  99891. + .dai_fmt = SND_SOC_DAIFMT_I2S
  99892. + | SND_SOC_DAIFMT_NB_NF
  99893. + | SND_SOC_DAIFMT_CBM_CFM,
  99894. + .ops = &snd_rpi_proto_ops,
  99895. +},
  99896. +};
  99897. +
  99898. +/* audio machine driver */
  99899. +static struct snd_soc_card snd_rpi_proto = {
  99900. + .name = "snd_rpi_proto",
  99901. + .dai_link = snd_rpi_proto_dai,
  99902. + .num_links = ARRAY_SIZE(snd_rpi_proto_dai),
  99903. +};
  99904. +
  99905. +static int snd_rpi_proto_probe(struct platform_device *pdev)
  99906. +{
  99907. + int ret = 0;
  99908. +
  99909. + snd_rpi_proto.dev = &pdev->dev;
  99910. + ret = snd_soc_register_card(&snd_rpi_proto);
  99911. + if (ret) {
  99912. + dev_err(&pdev->dev,
  99913. + "snd_soc_register_card() failed: %d\n", ret);
  99914. + }
  99915. +
  99916. + return ret;
  99917. +}
  99918. +
  99919. +
  99920. +static int snd_rpi_proto_remove(struct platform_device *pdev)
  99921. +{
  99922. + return snd_soc_unregister_card(&snd_rpi_proto);
  99923. +}
  99924. +
  99925. +static struct platform_driver snd_rpi_proto_driver = {
  99926. + .driver = {
  99927. + .name = "snd-rpi-proto",
  99928. + .owner = THIS_MODULE,
  99929. + },
  99930. + .probe = snd_rpi_proto_probe,
  99931. + .remove = snd_rpi_proto_remove,
  99932. +};
  99933. +
  99934. +module_platform_driver(snd_rpi_proto_driver);
  99935. +
  99936. +MODULE_AUTHOR("Florian Meier");
  99937. +MODULE_DESCRIPTION("ASoC Driver for Raspberry Pi connected to PROTO board (WM8731)");
  99938. +MODULE_LICENSE("GPL");
  99939. diff -Nur linux-3.13.3.orig/sound/soc/bcm/rpi-tda1541a.c linux-3.13.3/sound/soc/bcm/rpi-tda1541a.c
  99940. --- linux-3.13.3.orig/sound/soc/bcm/rpi-tda1541a.c 1970-01-01 01:00:00.000000000 +0100
  99941. +++ linux-3.13.3/sound/soc/bcm/rpi-tda1541a.c 2014-02-17 22:41:02.000000000 +0100
  99942. @@ -0,0 +1,92 @@
  99943. +/*
  99944. + * ASoC driver for TDA1541A codec
  99945. + * connected to a Raspberry Pi
  99946. + *
  99947. + * Author: Florian Meier, <koalo@koalo.de>
  99948. + * Copyright 2013
  99949. + *
  99950. + * This program is free software; you can redistribute it and/or modify
  99951. + * it under the terms of the GNU General Public License version 2 as
  99952. + * published by the Free Software Foundation.
  99953. + */
  99954. +
  99955. +#include <linux/module.h>
  99956. +#include <linux/platform_device.h>
  99957. +
  99958. +#include <sound/core.h>
  99959. +#include <sound/pcm.h>
  99960. +#include <sound/soc.h>
  99961. +#include <sound/jack.h>
  99962. +
  99963. +static int snd_rpi_tda1541a_init(struct snd_soc_pcm_runtime *rtd)
  99964. +{
  99965. + return 0;
  99966. +}
  99967. +
  99968. +static int snd_rpi_tda1541a_hw_params(struct snd_pcm_substream *substream,
  99969. + struct snd_pcm_hw_params *params)
  99970. +{
  99971. + return 0;
  99972. +}
  99973. +
  99974. +/* machine stream operations */
  99975. +static struct snd_soc_ops snd_rpi_tda1541a_ops = {
  99976. + .hw_params = snd_rpi_tda1541a_hw_params,
  99977. +};
  99978. +
  99979. +static struct snd_soc_dai_link snd_rpi_tda1541a_dai[] = {
  99980. +{
  99981. + .name = "TDA1541A",
  99982. + .stream_name = "TDA1541A HiFi",
  99983. + .cpu_dai_name = "bcm2708-i2s.0",
  99984. + .codec_dai_name = "tda1541a-hifi",
  99985. + .platform_name = "bcm2708-i2s.0",
  99986. + .codec_name = "tda1541a-codec",
  99987. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  99988. + SND_SOC_DAIFMT_CBS_CFS,
  99989. + .ops = &snd_rpi_tda1541a_ops,
  99990. + .init = snd_rpi_tda1541a_init,
  99991. +},
  99992. +};
  99993. +
  99994. +/* audio machine driver */
  99995. +static struct snd_soc_card snd_rpi_tda1541a = {
  99996. + .name = "snd_rpi_tda1541a",
  99997. + .dai_link = snd_rpi_tda1541a_dai,
  99998. + .num_links = ARRAY_SIZE(snd_rpi_tda1541a_dai),
  99999. +};
  100000. +
  100001. +static int snd_rpi_tda1541a_probe(struct platform_device *pdev)
  100002. +{
  100003. + int ret = 0;
  100004. +
  100005. + snd_rpi_tda1541a.dev = &pdev->dev;
  100006. + ret = snd_soc_register_card(&snd_rpi_tda1541a);
  100007. + if (ret)
  100008. + {
  100009. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  100010. + }
  100011. +
  100012. + return ret;
  100013. +}
  100014. +
  100015. +
  100016. +static int snd_rpi_tda1541a_remove(struct platform_device *pdev)
  100017. +{
  100018. + return snd_soc_unregister_card(&snd_rpi_tda1541a);
  100019. +}
  100020. +
  100021. +static struct platform_driver snd_rpi_tda1541a_driver = {
  100022. + .driver = {
  100023. + .name = "snd-rpi-tda1541a",
  100024. + .owner = THIS_MODULE,
  100025. + },
  100026. + .probe = snd_rpi_tda1541a_probe,
  100027. + .remove = snd_rpi_tda1541a_remove,
  100028. +};
  100029. +
  100030. +module_platform_driver(snd_rpi_tda1541a_driver);
  100031. +
  100032. +MODULE_AUTHOR("Florian Meier");
  100033. +MODULE_DESCRIPTION("ASoC Driver for Raspberry Pi connected to a TDA1541A");
  100034. +MODULE_LICENSE("GPL");
  100035. diff -Nur linux-3.13.3.orig/sound/soc/codecs/Kconfig linux-3.13.3/sound/soc/codecs/Kconfig
  100036. --- linux-3.13.3.orig/sound/soc/codecs/Kconfig 2014-02-13 23:00:14.000000000 +0100
  100037. +++ linux-3.13.3/sound/soc/codecs/Kconfig 2014-02-17 22:41:02.000000000 +0100
  100038. @@ -59,6 +59,8 @@
  100039. select SND_SOC_PCM1681 if I2C
  100040. select SND_SOC_PCM1792A if SPI_MASTER
  100041. select SND_SOC_PCM3008
  100042. + select SND_SOC_PCM1794A
  100043. + select SND_SOC_PCM5102A
  100044. select SND_SOC_RT5631 if I2C
  100045. select SND_SOC_RT5640 if I2C
  100046. select SND_SOC_SGTL5000 if I2C
  100047. @@ -311,6 +313,12 @@
  100048. config SND_SOC_PCM3008
  100049. tristate
  100050. +config SND_SOC_PCM1794A
  100051. + tristate
  100052. +
  100053. +config SND_SOC_PCM5102A
  100054. + tristate
  100055. +
  100056. config SND_SOC_RT5631
  100057. tristate
  100058. diff -Nur linux-3.13.3.orig/sound/soc/codecs/Makefile linux-3.13.3/sound/soc/codecs/Makefile
  100059. --- linux-3.13.3.orig/sound/soc/codecs/Makefile 2014-02-13 23:00:14.000000000 +0100
  100060. +++ linux-3.13.3/sound/soc/codecs/Makefile 2014-02-17 22:41:02.000000000 +0100
  100061. @@ -46,6 +46,8 @@
  100062. snd-soc-pcm1681-objs := pcm1681.o
  100063. snd-soc-pcm1792a-codec-objs := pcm1792a.o
  100064. snd-soc-pcm3008-objs := pcm3008.o
  100065. +snd-soc-pcm1794a-objs := pcm1794a.o
  100066. +snd-soc-pcm5102a-objs := pcm5102a.o
  100067. snd-soc-rt5631-objs := rt5631.o
  100068. snd-soc-rt5640-objs := rt5640.o
  100069. snd-soc-sgtl5000-objs := sgtl5000.o
  100070. @@ -179,6 +181,8 @@
  100071. obj-$(CONFIG_SND_SOC_PCM1681) += snd-soc-pcm1681.o
  100072. obj-$(CONFIG_SND_SOC_PCM1792A) += snd-soc-pcm1792a-codec.o
  100073. obj-$(CONFIG_SND_SOC_PCM3008) += snd-soc-pcm3008.o
  100074. +obj-$(CONFIG_SND_SOC_PCM1794A) += snd-soc-pcm1794a.o
  100075. +obj-$(CONFIG_SND_SOC_PCM5102A) += snd-soc-pcm5102a.o
  100076. obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o
  100077. obj-$(CONFIG_SND_SOC_RT5640) += snd-soc-rt5640.o
  100078. obj-$(CONFIG_SND_SOC_SGTL5000) += snd-soc-sgtl5000.o
  100079. diff -Nur linux-3.13.3.orig/sound/soc/codecs/pcm1794a.c linux-3.13.3/sound/soc/codecs/pcm1794a.c
  100080. --- linux-3.13.3.orig/sound/soc/codecs/pcm1794a.c 1970-01-01 01:00:00.000000000 +0100
  100081. +++ linux-3.13.3/sound/soc/codecs/pcm1794a.c 2014-02-17 22:41:02.000000000 +0100
  100082. @@ -0,0 +1,62 @@
  100083. +/*
  100084. + * Driver for the PCM1794A codec
  100085. + *
  100086. + * Author: Florian Meier <florian.meier@koalo.de>
  100087. + * Copyright 2013
  100088. + *
  100089. + * This program is free software; you can redistribute it and/or
  100090. + * modify it under the terms of the GNU General Public License
  100091. + * version 2 as published by the Free Software Foundation.
  100092. + *
  100093. + * This program is distributed in the hope that it will be useful, but
  100094. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  100095. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  100096. + * General Public License for more details.
  100097. + */
  100098. +
  100099. +
  100100. +#include <linux/init.h>
  100101. +#include <linux/module.h>
  100102. +#include <linux/platform_device.h>
  100103. +
  100104. +#include <sound/soc.h>
  100105. +
  100106. +static struct snd_soc_dai_driver pcm1794a_dai = {
  100107. + .name = "pcm1794a-hifi",
  100108. + .playback = {
  100109. + .channels_min = 2,
  100110. + .channels_max = 2,
  100111. + .rates = SNDRV_PCM_RATE_8000_192000,
  100112. + .formats = SNDRV_PCM_FMTBIT_S16_LE |
  100113. + SNDRV_PCM_FMTBIT_S24_LE
  100114. + },
  100115. +};
  100116. +
  100117. +static struct snd_soc_codec_driver soc_codec_dev_pcm1794a;
  100118. +
  100119. +static int pcm1794a_probe(struct platform_device *pdev)
  100120. +{
  100121. + return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_pcm1794a,
  100122. + &pcm1794a_dai, 1);
  100123. +}
  100124. +
  100125. +static int pcm1794a_remove(struct platform_device *pdev)
  100126. +{
  100127. + snd_soc_unregister_codec(&pdev->dev);
  100128. + return 0;
  100129. +}
  100130. +
  100131. +static struct platform_driver pcm1794a_codec_driver = {
  100132. + .probe = pcm1794a_probe,
  100133. + .remove = pcm1794a_remove,
  100134. + .driver = {
  100135. + .name = "pcm1794a-codec",
  100136. + .owner = THIS_MODULE,
  100137. + },
  100138. +};
  100139. +
  100140. +module_platform_driver(pcm1794a_codec_driver);
  100141. +
  100142. +MODULE_DESCRIPTION("ASoC PCM1794A codec driver");
  100143. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  100144. +MODULE_LICENSE("GPL v2");
  100145. diff -Nur linux-3.13.3.orig/sound/soc/codecs/pcm5102a.c linux-3.13.3/sound/soc/codecs/pcm5102a.c
  100146. --- linux-3.13.3.orig/sound/soc/codecs/pcm5102a.c 1970-01-01 01:00:00.000000000 +0100
  100147. +++ linux-3.13.3/sound/soc/codecs/pcm5102a.c 2014-02-17 22:41:02.000000000 +0100
  100148. @@ -0,0 +1,63 @@
  100149. +/*
  100150. + * Driver for the PCM5102A codec
  100151. + *
  100152. + * Author: Florian Meier <florian.meier@koalo.de>
  100153. + * Copyright 2013
  100154. + *
  100155. + * This program is free software; you can redistribute it and/or
  100156. + * modify it under the terms of the GNU General Public License
  100157. + * version 2 as published by the Free Software Foundation.
  100158. + *
  100159. + * This program is distributed in the hope that it will be useful, but
  100160. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  100161. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  100162. + * General Public License for more details.
  100163. + */
  100164. +
  100165. +
  100166. +#include <linux/init.h>
  100167. +#include <linux/module.h>
  100168. +#include <linux/platform_device.h>
  100169. +
  100170. +#include <sound/soc.h>
  100171. +
  100172. +static struct snd_soc_dai_driver pcm5102a_dai = {
  100173. + .name = "pcm5102a-hifi",
  100174. + .playback = {
  100175. + .channels_min = 2,
  100176. + .channels_max = 2,
  100177. + .rates = SNDRV_PCM_RATE_8000_192000,
  100178. + .formats = SNDRV_PCM_FMTBIT_S16_LE |
  100179. + SNDRV_PCM_FMTBIT_S24_LE |
  100180. + SNDRV_PCM_FMTBIT_S32_LE
  100181. + },
  100182. +};
  100183. +
  100184. +static struct snd_soc_codec_driver soc_codec_dev_pcm5102a;
  100185. +
  100186. +static int pcm5102a_probe(struct platform_device *pdev)
  100187. +{
  100188. + return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_pcm5102a,
  100189. + &pcm5102a_dai, 1);
  100190. +}
  100191. +
  100192. +static int pcm5102a_remove(struct platform_device *pdev)
  100193. +{
  100194. + snd_soc_unregister_codec(&pdev->dev);
  100195. + return 0;
  100196. +}
  100197. +
  100198. +static struct platform_driver pcm5102a_codec_driver = {
  100199. + .probe = pcm5102a_probe,
  100200. + .remove = pcm5102a_remove,
  100201. + .driver = {
  100202. + .name = "pcm5102a-codec",
  100203. + .owner = THIS_MODULE,
  100204. + },
  100205. +};
  100206. +
  100207. +module_platform_driver(pcm5102a_codec_driver);
  100208. +
  100209. +MODULE_DESCRIPTION("ASoC PCM5102A codec driver");
  100210. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  100211. +MODULE_LICENSE("GPL v2");
  100212. diff -Nur linux-3.13.3.orig/sound/soc/codecs/wm8804.c linux-3.13.3/sound/soc/codecs/wm8804.c
  100213. --- linux-3.13.3.orig/sound/soc/codecs/wm8804.c 2014-02-13 23:00:14.000000000 +0100
  100214. +++ linux-3.13.3/sound/soc/codecs/wm8804.c 2014-02-17 22:41:02.000000000 +0100
  100215. @@ -63,6 +63,7 @@
  100216. struct regmap *regmap;
  100217. struct regulator_bulk_data supplies[WM8804_NUM_SUPPLIES];
  100218. struct notifier_block disable_nb[WM8804_NUM_SUPPLIES];
  100219. + int mclk_div;
  100220. };
  100221. static int txsrc_get(struct snd_kcontrol *kcontrol,
  100222. @@ -277,6 +278,7 @@
  100223. blen = 0x1;
  100224. break;
  100225. case SNDRV_PCM_FORMAT_S24_LE:
  100226. + case SNDRV_PCM_FORMAT_S32_LE:
  100227. blen = 0x2;
  100228. break;
  100229. default:
  100230. @@ -318,7 +320,7 @@
  100231. #define FIXED_PLL_SIZE ((1ULL << 22) * 10)
  100232. static int pll_factors(struct pll_div *pll_div, unsigned int target,
  100233. - unsigned int source)
  100234. + unsigned int source, unsigned int mclk_div)
  100235. {
  100236. u64 Kpart;
  100237. unsigned long int K, Ndiv, Nmod, tmp;
  100238. @@ -330,7 +332,8 @@
  100239. */
  100240. for (i = 0; i < ARRAY_SIZE(post_table); i++) {
  100241. tmp = target * post_table[i].div;
  100242. - if (tmp >= 90000000 && tmp <= 100000000) {
  100243. + if ((tmp >= 90000000 && tmp <= 100000000) &&
  100244. + (mclk_div == post_table[i].mclkdiv)) {
  100245. pll_div->freqmode = post_table[i].freqmode;
  100246. pll_div->mclkdiv = post_table[i].mclkdiv;
  100247. target *= post_table[i].div;
  100248. @@ -387,8 +390,11 @@
  100249. } else {
  100250. int ret;
  100251. struct pll_div pll_div;
  100252. + struct wm8804_priv *wm8804;
  100253. - ret = pll_factors(&pll_div, freq_out, freq_in);
  100254. + wm8804 = snd_soc_codec_get_drvdata(codec);
  100255. +
  100256. + ret = pll_factors(&pll_div, freq_out, freq_in, wm8804->mclk_div);
  100257. if (ret)
  100258. return ret;
  100259. @@ -452,6 +458,7 @@
  100260. int div_id, int div)
  100261. {
  100262. struct snd_soc_codec *codec;
  100263. + struct wm8804_priv *wm8804;
  100264. codec = dai->codec;
  100265. switch (div_id) {
  100266. @@ -459,6 +466,10 @@
  100267. snd_soc_update_bits(codec, WM8804_PLL5, 0x30,
  100268. (div & 0x3) << 4);
  100269. break;
  100270. + case WM8804_MCLK_DIV:
  100271. + wm8804 = snd_soc_codec_get_drvdata(codec);
  100272. + wm8804->mclk_div = div;
  100273. + break;
  100274. default:
  100275. dev_err(dai->dev, "Unknown clock divider: %d\n", div_id);
  100276. return -EINVAL;
  100277. @@ -641,7 +652,7 @@
  100278. };
  100279. #define WM8804_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
  100280. - SNDRV_PCM_FMTBIT_S24_LE)
  100281. + SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE)
  100282. #define WM8804_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
  100283. SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_64000 | \
  100284. @@ -674,7 +685,7 @@
  100285. .suspend = wm8804_suspend,
  100286. .resume = wm8804_resume,
  100287. .set_bias_level = wm8804_set_bias_level,
  100288. - .idle_bias_off = true,
  100289. + .idle_bias_off = false,
  100290. .controls = wm8804_snd_controls,
  100291. .num_controls = ARRAY_SIZE(wm8804_snd_controls),
  100292. diff -Nur linux-3.13.3.orig/sound/soc/codecs/wm8804.h linux-3.13.3/sound/soc/codecs/wm8804.h
  100293. --- linux-3.13.3.orig/sound/soc/codecs/wm8804.h 2014-02-13 23:00:14.000000000 +0100
  100294. +++ linux-3.13.3/sound/soc/codecs/wm8804.h 2014-02-17 22:41:02.000000000 +0100
  100295. @@ -57,5 +57,9 @@
  100296. #define WM8804_CLKOUT_SRC_OSCCLK 4
  100297. #define WM8804_CLKOUT_DIV 1
  100298. +#define WM8804_MCLK_DIV 2
  100299. +
  100300. +#define WM8804_MCLKDIV_256FS 0
  100301. +#define WM8804_MCLKDIV_128FS 1
  100302. #endif /* _WM8804_H */
  100303. diff -Nur linux-3.13.3.orig/sound/soc/Kconfig linux-3.13.3/sound/soc/Kconfig
  100304. --- linux-3.13.3.orig/sound/soc/Kconfig 2014-02-13 23:00:14.000000000 +0100
  100305. +++ linux-3.13.3/sound/soc/Kconfig 2014-02-17 22:41:02.000000000 +0100
  100306. @@ -33,6 +33,7 @@
  100307. # All the supported SoCs
  100308. source "sound/soc/atmel/Kconfig"
  100309. source "sound/soc/au1x/Kconfig"
  100310. +source "sound/soc/bcm/Kconfig"
  100311. source "sound/soc/blackfin/Kconfig"
  100312. source "sound/soc/cirrus/Kconfig"
  100313. source "sound/soc/davinci/Kconfig"
  100314. diff -Nur linux-3.13.3.orig/sound/soc/Makefile linux-3.13.3/sound/soc/Makefile
  100315. --- linux-3.13.3.orig/sound/soc/Makefile 2014-02-13 23:00:14.000000000 +0100
  100316. +++ linux-3.13.3/sound/soc/Makefile 2014-02-17 22:41:02.000000000 +0100
  100317. @@ -10,6 +10,7 @@
  100318. obj-$(CONFIG_SND_SOC) += generic/
  100319. obj-$(CONFIG_SND_SOC) += atmel/
  100320. obj-$(CONFIG_SND_SOC) += au1x/
  100321. +obj-$(CONFIG_SND_SOC) += bcm/
  100322. obj-$(CONFIG_SND_SOC) += blackfin/
  100323. obj-$(CONFIG_SND_SOC) += cirrus/
  100324. obj-$(CONFIG_SND_SOC) += davinci/