raspberry-pi.patch 3.1 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319503205032150322503235032450325503265032750328503295033050331503325033350334503355033650337503385033950340503415034250343503445034550346503475034850349503505035150352503535035450355503565035750358503595036050361503625036350364503655036650367503685036950370503715037250373503745037550376503775037850379503805038150382503835038450385503865038750388503895039050391503925039350394503955039650397503985039950400504015040250403504045040550406504075040850409504105041150412504135041450415504165041750418504195042050421504225042350424504255042650427504285042950430504315043250433504345043550436504375043850439504405044150442504435044450445504465044750448504495045050451504525045350454504555045650457504585045950460504615046250463504645046550466504675046850469504705047150472504735047450475504765047750478504795048050481504825048350484504855048650487504885048950490504915049250493504945049550496504975049850499505005050150502505035050450505505065050750508505095051050511505125051350514505155051650517505185051950520505215052250523505245052550526505275052850529505305053150532505335053450535505365053750538505395054050541505425054350544505455054650547505485054950550505515055250553505545055550556505575055850559505605056150562505635056450565505665056750568505695057050571505725057350574505755057650577505785057950580505815058250583505845058550586505875058850589505905059150592505935059450595505965059750598505995060050601506025060350604506055060650607506085060950610506115061250613506145061550616506175061850619506205062150622506235062450625506265062750628506295063050631506325063350634506355063650637506385063950640506415064250643506445064550646506475064850649506505065150652506535065450655506565065750658506595066050661506625066350664506655066650667506685066950670506715067250673506745067550676506775067850679506805068150682506835068450685506865068750688506895069050691506925069350694506955069650697506985069950700507015070250703507045070550706507075070850709507105071150712507135071450715507165071750718507195072050721507225072350724507255072650727507285072950730507315073250733507345073550736507375073850739507405074150742507435074450745507465074750748507495075050751507525075350754507555075650757507585075950760507615076250763507645076550766507675076850769507705077150772507735077450775507765077750778507795078050781507825078350784507855078650787507885078950790507915079250793507945079550796507975079850799508005080150802508035080450805508065080750808508095081050811508125081350814508155081650817508185081950820508215082250823508245082550826508275082850829508305083150832508335083450835508365083750838508395084050841508425084350844508455084650847508485084950850508515085250853508545085550856508575085850859508605086150862508635086450865508665086750868508695087050871508725087350874508755087650877508785087950880508815088250883508845088550886508875088850889508905089150892508935089450895508965089750898508995090050901509025090350904509055090650907509085090950910509115091250913509145091550916509175091850919509205092150922509235092450925509265092750928509295093050931509325093350934509355093650937509385093950940509415094250943509445094550946509475094850949509505095150952509535095450955509565095750958509595096050961509625096350964509655096650967509685096950970509715097250973509745097550976509775097850979509805098150982509835098450985509865098750988509895099050991509925099350994509955099650997509985099951000510015100251003510045100551006510075100851009510105101151012510135101451015510165101751018510195102051021510225102351024510255102651027510285102951030510315103251033510345103551036510375103851039510405104151042510435104451045510465104751048510495105051051510525105351054510555105651057510585105951060510615106251063510645106551066510675106851069510705107151072510735107451075510765107751078510795108051081510825108351084510855108651087510885108951090510915109251093510945109551096510975109851099511005110151102511035110451105511065110751108511095111051111511125111351114511155111651117511185111951120511215112251123511245112551126511275112851129511305113151132511335113451135511365113751138511395114051141511425114351144511455114651147511485114951150511515115251153511545115551156511575115851159511605116151162511635116451165511665116751168511695117051171511725117351174511755117651177511785117951180511815118251183511845118551186511875118851189511905119151192511935119451195511965119751198511995120051201512025120351204512055120651207512085120951210512115121251213512145121551216512175121851219512205122151222512235122451225512265122751228512295123051231512325123351234512355123651237512385123951240512415124251243512445124551246512475124851249512505125151252512535125451255512565125751258512595126051261512625126351264512655126651267512685126951270512715127251273512745127551276512775127851279512805128151282512835128451285512865128751288512895129051291512925129351294512955129651297512985129951300513015130251303513045130551306513075130851309513105131151312513135131451315513165131751318513195132051321513225132351324513255132651327513285132951330513315133251333513345133551336513375133851339513405134151342513435134451345513465134751348513495135051351513525135351354513555135651357513585135951360513615136251363513645136551366513675136851369513705137151372513735137451375513765137751378513795138051381513825138351384513855138651387513885138951390513915139251393513945139551396513975139851399514005140151402514035140451405514065140751408514095141051411514125141351414514155141651417514185141951420514215142251423514245142551426514275142851429514305143151432514335143451435514365143751438514395144051441514425144351444514455144651447514485144951450514515145251453514545145551456514575145851459514605146151462514635146451465514665146751468514695147051471514725147351474514755147651477514785147951480514815148251483514845148551486514875148851489514905149151492514935149451495514965149751498514995150051501515025150351504515055150651507515085150951510515115151251513515145151551516515175151851519515205152151522515235152451525515265152751528515295153051531515325153351534515355153651537515385153951540515415154251543515445154551546515475154851549515505155151552515535155451555515565155751558515595156051561515625156351564515655156651567515685156951570515715157251573515745157551576515775157851579515805158151582515835158451585515865158751588515895159051591515925159351594515955159651597515985159951600516015160251603516045160551606516075160851609516105161151612516135161451615516165161751618516195162051621516225162351624516255162651627516285162951630516315163251633516345163551636516375163851639516405164151642516435164451645516465164751648516495165051651516525165351654516555165651657516585165951660516615166251663516645166551666516675166851669516705167151672516735167451675516765167751678516795168051681516825168351684516855168651687516885168951690516915169251693516945169551696516975169851699517005170151702517035170451705517065170751708517095171051711517125171351714517155171651717517185171951720517215172251723517245172551726517275172851729517305173151732517335173451735517365173751738517395174051741517425174351744517455174651747517485174951750517515175251753517545175551756517575175851759517605176151762517635176451765517665176751768517695177051771517725177351774517755177651777517785177951780517815178251783517845178551786517875178851789517905179151792517935179451795517965179751798517995180051801518025180351804518055180651807518085180951810518115181251813518145181551816518175181851819518205182151822518235182451825518265182751828518295183051831518325183351834518355183651837518385183951840518415184251843518445184551846518475184851849518505185151852518535185451855518565185751858518595186051861518625186351864518655186651867518685186951870518715187251873518745187551876518775187851879518805188151882518835188451885518865188751888518895189051891518925189351894518955189651897518985189951900519015190251903519045190551906519075190851909519105191151912519135191451915519165191751918519195192051921519225192351924519255192651927519285192951930519315193251933519345193551936519375193851939519405194151942519435194451945519465194751948519495195051951519525195351954519555195651957519585195951960519615196251963519645196551966519675196851969519705197151972519735197451975519765197751978519795198051981519825198351984519855198651987519885198951990519915199251993519945199551996519975199851999520005200152002520035200452005520065200752008520095201052011520125201352014520155201652017520185201952020520215202252023520245202552026520275202852029520305203152032520335203452035520365203752038520395204052041520425204352044520455204652047520485204952050520515205252053520545205552056520575205852059520605206152062520635206452065520665206752068520695207052071520725207352074520755207652077520785207952080520815208252083520845208552086520875208852089520905209152092520935209452095520965209752098520995210052101521025210352104521055210652107521085210952110521115211252113521145211552116521175211852119521205212152122521235212452125521265212752128521295213052131521325213352134521355213652137521385213952140521415214252143521445214552146521475214852149521505215152152521535215452155521565215752158521595216052161521625216352164521655216652167521685216952170521715217252173521745217552176521775217852179521805218152182521835218452185521865218752188521895219052191521925219352194521955219652197521985219952200522015220252203522045220552206522075220852209522105221152212522135221452215522165221752218522195222052221522225222352224522255222652227522285222952230522315223252233522345223552236522375223852239522405224152242522435224452245522465224752248522495225052251522525225352254522555225652257522585225952260522615226252263522645226552266522675226852269522705227152272522735227452275522765227752278522795228052281522825228352284522855228652287522885228952290522915229252293522945229552296522975229852299523005230152302523035230452305523065230752308523095231052311523125231352314523155231652317523185231952320523215232252323523245232552326523275232852329523305233152332523335233452335523365233752338523395234052341523425234352344523455234652347523485234952350523515235252353523545235552356523575235852359523605236152362523635236452365523665236752368523695237052371523725237352374523755237652377523785237952380523815238252383523845238552386523875238852389523905239152392523935239452395523965239752398523995240052401524025240352404524055240652407524085240952410524115241252413524145241552416524175241852419524205242152422524235242452425524265242752428524295243052431524325243352434524355243652437524385243952440524415244252443524445244552446524475244852449524505245152452524535245452455524565245752458524595246052461524625246352464524655246652467524685246952470524715247252473524745247552476524775247852479524805248152482524835248452485524865248752488524895249052491524925249352494524955249652497524985249952500525015250252503525045250552506525075250852509525105251152512525135251452515525165251752518525195252052521525225252352524525255252652527525285252952530525315253252533525345253552536525375253852539525405254152542525435254452545525465254752548525495255052551525525255352554525555255652557525585255952560525615256252563525645256552566525675256852569525705257152572525735257452575525765257752578525795258052581525825258352584525855258652587525885258952590525915259252593525945259552596525975259852599526005260152602526035260452605526065260752608526095261052611526125261352614526155261652617526185261952620526215262252623526245262552626526275262852629526305263152632526335263452635526365263752638526395264052641526425264352644526455264652647526485264952650526515265252653526545265552656526575265852659526605266152662526635266452665526665266752668526695267052671526725267352674526755267652677526785267952680526815268252683526845268552686526875268852689526905269152692526935269452695526965269752698526995270052701527025270352704527055270652707527085270952710527115271252713527145271552716527175271852719527205272152722527235272452725527265272752728527295273052731527325273352734527355273652737527385273952740527415274252743527445274552746527475274852749527505275152752527535275452755527565275752758527595276052761527625276352764527655276652767527685276952770527715277252773527745277552776527775277852779527805278152782527835278452785527865278752788527895279052791527925279352794527955279652797527985279952800528015280252803528045280552806528075280852809528105281152812528135281452815528165281752818528195282052821528225282352824528255282652827528285282952830528315283252833528345283552836528375283852839528405284152842528435284452845528465284752848528495285052851528525285352854528555285652857528585285952860528615286252863528645286552866528675286852869528705287152872528735287452875528765287752878528795288052881528825288352884528855288652887528885288952890528915289252893528945289552896528975289852899529005290152902529035290452905529065290752908529095291052911529125291352914529155291652917529185291952920529215292252923529245292552926529275292852929529305293152932529335293452935529365293752938529395294052941529425294352944529455294652947529485294952950529515295252953529545295552956529575295852959529605296152962529635296452965529665296752968529695297052971529725297352974529755297652977529785297952980529815298252983529845298552986529875298852989529905299152992529935299452995529965299752998529995300053001530025300353004530055300653007530085300953010530115301253013530145301553016530175301853019530205302153022530235302453025530265302753028530295303053031530325303353034530355303653037530385303953040530415304253043530445304553046530475304853049530505305153052530535305453055530565305753058530595306053061530625306353064530655306653067530685306953070530715307253073530745307553076530775307853079530805308153082530835308453085530865308753088530895309053091530925309353094530955309653097530985309953100531015310253103531045310553106531075310853109531105311153112531135311453115531165311753118531195312053121531225312353124531255312653127531285312953130531315313253133531345313553136531375313853139531405314153142531435314453145531465314753148531495315053151531525315353154531555315653157531585315953160531615316253163531645316553166531675316853169531705317153172531735317453175531765317753178531795318053181531825318353184531855318653187531885318953190531915319253193531945319553196531975319853199532005320153202532035320453205532065320753208532095321053211532125321353214532155321653217532185321953220532215322253223532245322553226532275322853229532305323153232532335323453235532365323753238532395324053241532425324353244532455324653247532485324953250532515325253253532545325553256532575325853259532605326153262532635326453265532665326753268532695327053271532725327353274532755327653277532785327953280532815328253283532845328553286532875328853289532905329153292532935329453295532965329753298532995330053301533025330353304533055330653307533085330953310533115331253313533145331553316533175331853319533205332153322533235332453325533265332753328533295333053331533325333353334533355333653337533385333953340533415334253343533445334553346533475334853349533505335153352533535335453355533565335753358533595336053361533625336353364533655336653367533685336953370533715337253373533745337553376533775337853379533805338153382533835338453385533865338753388533895339053391533925339353394533955339653397533985339953400534015340253403534045340553406534075340853409534105341153412534135341453415534165341753418534195342053421534225342353424534255342653427534285342953430534315343253433534345343553436534375343853439534405344153442534435344453445534465344753448534495345053451534525345353454534555345653457534585345953460534615346253463534645346553466534675346853469534705347153472534735347453475534765347753478534795348053481534825348353484534855348653487534885348953490534915349253493534945349553496534975349853499535005350153502535035350453505535065350753508535095351053511535125351353514535155351653517535185351953520535215352253523535245352553526535275352853529535305353153532535335353453535535365353753538535395354053541535425354353544535455354653547535485354953550535515355253553535545355553556535575355853559535605356153562535635356453565535665356753568535695357053571535725357353574535755357653577535785357953580535815358253583535845358553586535875358853589535905359153592535935359453595535965359753598535995360053601536025360353604536055360653607536085360953610536115361253613536145361553616536175361853619536205362153622536235362453625536265362753628536295363053631536325363353634536355363653637536385363953640536415364253643536445364553646536475364853649536505365153652536535365453655536565365753658536595366053661536625366353664536655366653667536685366953670536715367253673536745367553676536775367853679536805368153682536835368453685536865368753688536895369053691536925369353694536955369653697536985369953700537015370253703537045370553706537075370853709537105371153712537135371453715537165371753718537195372053721537225372353724537255372653727537285372953730537315373253733537345373553736537375373853739537405374153742537435374453745537465374753748537495375053751537525375353754537555375653757537585375953760537615376253763537645376553766537675376853769537705377153772537735377453775537765377753778537795378053781537825378353784537855378653787537885378953790537915379253793537945379553796537975379853799538005380153802538035380453805538065380753808538095381053811538125381353814538155381653817538185381953820538215382253823538245382553826538275382853829538305383153832538335383453835538365383753838538395384053841538425384353844538455384653847538485384953850538515385253853538545385553856538575385853859538605386153862538635386453865538665386753868538695387053871538725387353874538755387653877538785387953880538815388253883538845388553886538875388853889538905389153892538935389453895538965389753898538995390053901539025390353904539055390653907539085390953910539115391253913539145391553916539175391853919539205392153922539235392453925539265392753928539295393053931539325393353934539355393653937539385393953940539415394253943539445394553946539475394853949539505395153952539535395453955539565395753958539595396053961539625396353964539655396653967539685396953970539715397253973539745397553976539775397853979539805398153982539835398453985539865398753988539895399053991539925399353994539955399653997539985399954000540015400254003540045400554006540075400854009540105401154012540135401454015540165401754018540195402054021540225402354024540255402654027540285402954030540315403254033540345403554036540375403854039540405404154042540435404454045540465404754048540495405054051540525405354054540555405654057540585405954060540615406254063540645406554066540675406854069540705407154072540735407454075540765407754078540795408054081540825408354084540855408654087540885408954090540915409254093540945409554096540975409854099541005410154102541035410454105541065410754108541095411054111541125411354114541155411654117541185411954120541215412254123541245412554126541275412854129541305413154132541335413454135541365413754138541395414054141541425414354144541455414654147541485414954150541515415254153541545415554156541575415854159541605416154162541635416454165541665416754168541695417054171541725417354174541755417654177541785417954180541815418254183541845418554186541875418854189541905419154192541935419454195541965419754198541995420054201542025420354204542055420654207542085420954210542115421254213542145421554216542175421854219542205422154222542235422454225542265422754228542295423054231542325423354234542355423654237542385423954240542415424254243542445424554246542475424854249542505425154252542535425454255542565425754258542595426054261542625426354264542655426654267542685426954270542715427254273542745427554276542775427854279542805428154282542835428454285542865428754288542895429054291542925429354294542955429654297542985429954300543015430254303543045430554306543075430854309543105431154312543135431454315543165431754318543195432054321543225432354324543255432654327543285432954330543315433254333543345433554336543375433854339543405434154342543435434454345543465434754348543495435054351543525435354354543555435654357543585435954360543615436254363543645436554366543675436854369543705437154372543735437454375543765437754378543795438054381543825438354384543855438654387543885438954390543915439254393543945439554396543975439854399544005440154402544035440454405544065440754408544095441054411544125441354414544155441654417544185441954420544215442254423544245442554426544275442854429544305443154432544335443454435544365443754438544395444054441544425444354444544455444654447544485444954450544515445254453544545445554456544575445854459544605446154462544635446454465544665446754468544695447054471544725447354474544755447654477544785447954480544815448254483544845448554486544875448854489544905449154492544935449454495544965449754498544995450054501545025450354504545055450654507545085450954510545115451254513545145451554516545175451854519545205452154522545235452454525545265452754528545295453054531545325453354534545355453654537545385453954540545415454254543545445454554546545475454854549545505455154552545535455454555545565455754558545595456054561545625456354564545655456654567545685456954570545715457254573545745457554576545775457854579545805458154582545835458454585545865458754588545895459054591545925459354594545955459654597545985459954600546015460254603546045460554606546075460854609546105461154612546135461454615546165461754618546195462054621546225462354624546255462654627546285462954630546315463254633546345463554636546375463854639546405464154642546435464454645546465464754648546495465054651546525465354654546555465654657546585465954660546615466254663546645466554666546675466854669546705467154672546735467454675546765467754678546795468054681546825468354684546855468654687546885468954690546915469254693546945469554696546975469854699547005470154702547035470454705547065470754708547095471054711547125471354714547155471654717547185471954720547215472254723547245472554726547275472854729547305473154732547335473454735547365473754738547395474054741547425474354744547455474654747547485474954750547515475254753547545475554756547575475854759547605476154762547635476454765547665476754768547695477054771547725477354774547755477654777547785477954780547815478254783547845478554786547875478854789547905479154792547935479454795547965479754798547995480054801548025480354804548055480654807548085480954810548115481254813548145481554816548175481854819548205482154822548235482454825548265482754828548295483054831548325483354834548355483654837548385483954840548415484254843548445484554846548475484854849548505485154852548535485454855548565485754858548595486054861548625486354864548655486654867548685486954870548715487254873548745487554876548775487854879548805488154882548835488454885548865488754888548895489054891548925489354894548955489654897548985489954900549015490254903549045490554906549075490854909549105491154912549135491454915549165491754918549195492054921549225492354924549255492654927549285492954930549315493254933549345493554936549375493854939549405494154942549435494454945549465494754948549495495054951549525495354954549555495654957549585495954960549615496254963549645496554966549675496854969549705497154972549735497454975549765497754978549795498054981549825498354984549855498654987549885498954990549915499254993549945499554996549975499854999550005500155002550035500455005550065500755008550095501055011550125501355014550155501655017550185501955020550215502255023550245502555026550275502855029550305503155032550335503455035550365503755038550395504055041550425504355044550455504655047550485504955050550515505255053550545505555056550575505855059550605506155062550635506455065550665506755068550695507055071550725507355074550755507655077550785507955080550815508255083550845508555086550875508855089550905509155092550935509455095550965509755098550995510055101551025510355104551055510655107551085510955110551115511255113551145511555116551175511855119551205512155122551235512455125551265512755128551295513055131551325513355134551355513655137551385513955140551415514255143551445514555146551475514855149551505515155152551535515455155551565515755158551595516055161551625516355164551655516655167551685516955170551715517255173551745517555176551775517855179551805518155182551835518455185551865518755188551895519055191551925519355194551955519655197551985519955200552015520255203552045520555206552075520855209552105521155212552135521455215552165521755218552195522055221552225522355224552255522655227552285522955230552315523255233552345523555236552375523855239552405524155242552435524455245552465524755248552495525055251552525525355254552555525655257552585525955260552615526255263552645526555266552675526855269552705527155272552735527455275552765527755278552795528055281552825528355284552855528655287552885528955290552915529255293552945529555296552975529855299553005530155302553035530455305553065530755308553095531055311553125531355314553155531655317553185531955320553215532255323553245532555326553275532855329553305533155332553335533455335553365533755338553395534055341553425534355344553455534655347553485534955350553515535255353553545535555356553575535855359553605536155362553635536455365553665536755368553695537055371553725537355374553755537655377553785537955380553815538255383553845538555386553875538855389553905539155392553935539455395553965539755398553995540055401554025540355404554055540655407554085540955410554115541255413554145541555416554175541855419554205542155422554235542455425554265542755428554295543055431554325543355434554355543655437554385543955440554415544255443554445544555446554475544855449554505545155452554535545455455554565545755458554595546055461554625546355464554655546655467554685546955470554715547255473554745547555476554775547855479554805548155482554835548455485554865548755488554895549055491554925549355494554955549655497554985549955500555015550255503555045550555506555075550855509555105551155512555135551455515555165551755518555195552055521555225552355524555255552655527555285552955530555315553255533555345553555536555375553855539555405554155542555435554455545555465554755548555495555055551555525555355554555555555655557555585555955560555615556255563555645556555566555675556855569555705557155572555735557455575555765557755578555795558055581555825558355584555855558655587555885558955590555915559255593555945559555596555975559855599556005560155602556035560455605556065560755608556095561055611556125561355614556155561655617556185561955620556215562255623556245562555626556275562855629556305563155632556335563455635556365563755638556395564055641556425564355644556455564655647556485564955650556515565255653556545565555656556575565855659556605566155662556635566455665556665566755668556695567055671556725567355674556755567655677556785567955680556815568255683556845568555686556875568855689556905569155692556935569455695556965569755698556995570055701557025570355704557055570655707557085570955710557115571255713557145571555716557175571855719557205572155722557235572455725557265572755728557295573055731557325573355734557355573655737557385573955740557415574255743557445574555746557475574855749557505575155752557535575455755557565575755758557595576055761557625576355764557655576655767557685576955770557715577255773557745577555776557775577855779557805578155782557835578455785557865578755788557895579055791557925579355794557955579655797557985579955800558015580255803558045580555806558075580855809558105581155812558135581455815558165581755818558195582055821558225582355824558255582655827558285582955830558315583255833558345583555836558375583855839558405584155842558435584455845558465584755848558495585055851558525585355854558555585655857558585585955860558615586255863558645586555866558675586855869558705587155872558735587455875558765587755878558795588055881558825588355884558855588655887558885588955890558915589255893558945589555896558975589855899559005590155902559035590455905559065590755908559095591055911559125591355914559155591655917559185591955920559215592255923559245592555926559275592855929559305593155932559335593455935559365593755938559395594055941559425594355944559455594655947559485594955950559515595255953559545595555956559575595855959559605596155962559635596455965559665596755968559695597055971559725597355974559755597655977559785597955980559815598255983559845598555986559875598855989559905599155992559935599455995559965599755998559995600056001560025600356004560055600656007560085600956010560115601256013560145601556016560175601856019560205602156022560235602456025560265602756028560295603056031560325603356034560355603656037560385603956040560415604256043560445604556046560475604856049560505605156052560535605456055560565605756058560595606056061560625606356064560655606656067560685606956070560715607256073560745607556076560775607856079560805608156082560835608456085560865608756088560895609056091560925609356094560955609656097560985609956100561015610256103561045610556106561075610856109561105611156112561135611456115561165611756118561195612056121561225612356124561255612656127561285612956130561315613256133561345613556136561375613856139561405614156142561435614456145561465614756148561495615056151561525615356154561555615656157561585615956160561615616256163561645616556166561675616856169561705617156172561735617456175561765617756178561795618056181561825618356184561855618656187561885618956190561915619256193561945619556196561975619856199562005620156202562035620456205562065620756208562095621056211562125621356214562155621656217562185621956220562215622256223562245622556226562275622856229562305623156232562335623456235562365623756238562395624056241562425624356244562455624656247562485624956250562515625256253562545625556256562575625856259562605626156262562635626456265562665626756268562695627056271562725627356274562755627656277562785627956280562815628256283562845628556286562875628856289562905629156292562935629456295562965629756298562995630056301563025630356304563055630656307563085630956310563115631256313563145631556316563175631856319563205632156322563235632456325563265632756328563295633056331563325633356334563355633656337563385633956340563415634256343563445634556346563475634856349563505635156352563535635456355563565635756358563595636056361563625636356364563655636656367563685636956370563715637256373563745637556376563775637856379563805638156382563835638456385563865638756388563895639056391563925639356394563955639656397563985639956400564015640256403564045640556406564075640856409564105641156412564135641456415564165641756418564195642056421564225642356424564255642656427564285642956430564315643256433564345643556436564375643856439564405644156442564435644456445564465644756448564495645056451564525645356454564555645656457564585645956460564615646256463564645646556466564675646856469564705647156472564735647456475564765647756478564795648056481564825648356484564855648656487564885648956490564915649256493564945649556496564975649856499565005650156502565035650456505565065650756508565095651056511565125651356514565155651656517565185651956520565215652256523565245652556526565275652856529565305653156532565335653456535565365653756538565395654056541565425654356544565455654656547565485654956550565515655256553565545655556556565575655856559565605656156562565635656456565565665656756568565695657056571565725657356574565755657656577565785657956580565815658256583565845658556586565875658856589565905659156592565935659456595565965659756598565995660056601566025660356604566055660656607566085660956610566115661256613566145661556616566175661856619566205662156622566235662456625566265662756628566295663056631566325663356634566355663656637566385663956640566415664256643566445664556646566475664856649566505665156652566535665456655566565665756658566595666056661566625666356664566655666656667566685666956670566715667256673566745667556676566775667856679566805668156682566835668456685566865668756688566895669056691566925669356694566955669656697566985669956700567015670256703567045670556706567075670856709567105671156712567135671456715567165671756718567195672056721567225672356724567255672656727567285672956730567315673256733567345673556736567375673856739567405674156742567435674456745567465674756748567495675056751567525675356754567555675656757567585675956760567615676256763567645676556766567675676856769567705677156772567735677456775567765677756778567795678056781567825678356784567855678656787567885678956790567915679256793567945679556796567975679856799568005680156802568035680456805568065680756808568095681056811568125681356814568155681656817568185681956820568215682256823568245682556826568275682856829568305683156832568335683456835568365683756838568395684056841568425684356844568455684656847568485684956850568515685256853568545685556856568575685856859568605686156862568635686456865568665686756868568695687056871568725687356874568755687656877568785687956880568815688256883568845688556886568875688856889568905689156892568935689456895568965689756898568995690056901569025690356904569055690656907569085690956910569115691256913569145691556916569175691856919569205692156922569235692456925569265692756928569295693056931569325693356934569355693656937569385693956940569415694256943569445694556946569475694856949569505695156952569535695456955569565695756958569595696056961569625696356964569655696656967569685696956970569715697256973569745697556976569775697856979569805698156982569835698456985569865698756988569895699056991569925699356994569955699656997569985699957000570015700257003570045700557006570075700857009570105701157012570135701457015570165701757018570195702057021570225702357024570255702657027570285702957030570315703257033570345703557036570375703857039570405704157042570435704457045570465704757048570495705057051570525705357054570555705657057570585705957060570615706257063570645706557066570675706857069570705707157072570735707457075570765707757078570795708057081570825708357084570855708657087570885708957090570915709257093570945709557096570975709857099571005710157102571035710457105571065710757108571095711057111571125711357114571155711657117571185711957120571215712257123571245712557126571275712857129571305713157132571335713457135571365713757138571395714057141571425714357144571455714657147571485714957150571515715257153571545715557156571575715857159571605716157162571635716457165571665716757168571695717057171571725717357174571755717657177571785717957180571815718257183571845718557186571875718857189571905719157192571935719457195571965719757198571995720057201572025720357204572055720657207572085720957210572115721257213572145721557216572175721857219572205722157222572235722457225572265722757228572295723057231572325723357234572355723657237572385723957240572415724257243572445724557246572475724857249572505725157252572535725457255572565725757258572595726057261572625726357264572655726657267572685726957270572715727257273572745727557276572775727857279572805728157282572835728457285572865728757288572895729057291572925729357294572955729657297572985729957300573015730257303573045730557306573075730857309573105731157312573135731457315573165731757318573195732057321573225732357324573255732657327573285732957330573315733257333573345733557336573375733857339573405734157342573435734457345573465734757348573495735057351573525735357354573555735657357573585735957360573615736257363573645736557366573675736857369573705737157372573735737457375573765737757378573795738057381573825738357384573855738657387573885738957390573915739257393573945739557396573975739857399574005740157402574035740457405574065740757408574095741057411574125741357414574155741657417574185741957420574215742257423574245742557426574275742857429574305743157432574335743457435574365743757438574395744057441574425744357444574455744657447574485744957450574515745257453574545745557456574575745857459574605746157462574635746457465574665746757468574695747057471574725747357474574755747657477574785747957480574815748257483574845748557486574875748857489574905749157492574935749457495574965749757498574995750057501575025750357504575055750657507575085750957510575115751257513575145751557516575175751857519575205752157522575235752457525575265752757528575295753057531575325753357534575355753657537575385753957540575415754257543575445754557546575475754857549575505755157552575535755457555575565755757558575595756057561575625756357564575655756657567575685756957570575715757257573575745757557576575775757857579575805758157582575835758457585575865758757588575895759057591575925759357594575955759657597575985759957600576015760257603576045760557606576075760857609576105761157612576135761457615576165761757618576195762057621576225762357624576255762657627576285762957630576315763257633576345763557636576375763857639576405764157642576435764457645576465764757648576495765057651576525765357654576555765657657576585765957660576615766257663576645766557666576675766857669576705767157672576735767457675576765767757678576795768057681576825768357684576855768657687576885768957690576915769257693576945769557696576975769857699577005770157702577035770457705577065770757708577095771057711577125771357714577155771657717577185771957720577215772257723577245772557726577275772857729577305773157732577335773457735577365773757738577395774057741577425774357744577455774657747577485774957750577515775257753577545775557756577575775857759577605776157762577635776457765577665776757768577695777057771577725777357774577755777657777577785777957780577815778257783577845778557786577875778857789577905779157792577935779457795577965779757798577995780057801578025780357804578055780657807578085780957810578115781257813578145781557816578175781857819578205782157822578235782457825578265782757828578295783057831578325783357834578355783657837578385783957840578415784257843578445784557846578475784857849578505785157852578535785457855578565785757858578595786057861578625786357864578655786657867578685786957870578715787257873578745787557876578775787857879578805788157882578835788457885578865788757888578895789057891578925789357894578955789657897578985789957900579015790257903579045790557906579075790857909579105791157912579135791457915579165791757918579195792057921579225792357924579255792657927579285792957930579315793257933579345793557936579375793857939579405794157942579435794457945579465794757948579495795057951579525795357954579555795657957579585795957960579615796257963579645796557966579675796857969579705797157972579735797457975579765797757978579795798057981579825798357984579855798657987579885798957990579915799257993579945799557996579975799857999580005800158002580035800458005580065800758008580095801058011580125801358014580155801658017580185801958020580215802258023580245802558026580275802858029580305803158032580335803458035580365803758038580395804058041580425804358044580455804658047580485804958050580515805258053580545805558056580575805858059580605806158062580635806458065580665806758068580695807058071580725807358074580755807658077580785807958080580815808258083580845808558086580875808858089580905809158092580935809458095580965809758098580995810058101581025810358104581055810658107581085810958110581115811258113581145811558116581175811858119581205812158122581235812458125581265812758128581295813058131581325813358134581355813658137581385813958140581415814258143581445814558146581475814858149581505815158152581535815458155581565815758158581595816058161581625816358164581655816658167581685816958170581715817258173581745817558176581775817858179581805818158182581835818458185581865818758188581895819058191581925819358194581955819658197581985819958200582015820258203582045820558206582075820858209582105821158212582135821458215582165821758218582195822058221582225822358224582255822658227582285822958230582315823258233582345823558236582375823858239582405824158242582435824458245582465824758248582495825058251582525825358254582555825658257582585825958260582615826258263582645826558266582675826858269582705827158272582735827458275582765827758278582795828058281582825828358284582855828658287582885828958290582915829258293582945829558296582975829858299583005830158302583035830458305583065830758308583095831058311583125831358314583155831658317583185831958320583215832258323583245832558326583275832858329583305833158332583335833458335583365833758338583395834058341583425834358344583455834658347583485834958350583515835258353583545835558356583575835858359583605836158362583635836458365583665836758368583695837058371583725837358374583755837658377583785837958380583815838258383583845838558386583875838858389583905839158392583935839458395583965839758398583995840058401584025840358404584055840658407584085840958410584115841258413584145841558416584175841858419584205842158422584235842458425584265842758428584295843058431584325843358434584355843658437584385843958440584415844258443584445844558446584475844858449584505845158452584535845458455584565845758458584595846058461584625846358464584655846658467584685846958470584715847258473584745847558476584775847858479584805848158482584835848458485584865848758488584895849058491584925849358494584955849658497584985849958500585015850258503585045850558506585075850858509585105851158512585135851458515585165851758518585195852058521585225852358524585255852658527585285852958530585315853258533585345853558536585375853858539585405854158542585435854458545585465854758548585495855058551585525855358554585555855658557585585855958560585615856258563585645856558566585675856858569585705857158572585735857458575585765857758578585795858058581585825858358584585855858658587585885858958590585915859258593585945859558596585975859858599586005860158602586035860458605586065860758608586095861058611586125861358614586155861658617586185861958620586215862258623586245862558626586275862858629586305863158632586335863458635586365863758638586395864058641586425864358644586455864658647586485864958650586515865258653586545865558656586575865858659586605866158662586635866458665586665866758668586695867058671586725867358674586755867658677586785867958680586815868258683586845868558686586875868858689586905869158692586935869458695586965869758698586995870058701587025870358704587055870658707587085870958710587115871258713587145871558716587175871858719587205872158722587235872458725587265872758728587295873058731587325873358734587355873658737587385873958740587415874258743587445874558746587475874858749587505875158752587535875458755587565875758758587595876058761587625876358764587655876658767587685876958770587715877258773587745877558776587775877858779587805878158782587835878458785587865878758788587895879058791587925879358794587955879658797587985879958800588015880258803588045880558806588075880858809588105881158812588135881458815588165881758818588195882058821588225882358824588255882658827588285882958830588315883258833588345883558836588375883858839588405884158842588435884458845588465884758848588495885058851588525885358854588555885658857588585885958860588615886258863588645886558866588675886858869588705887158872588735887458875588765887758878588795888058881588825888358884588855888658887588885888958890588915889258893588945889558896588975889858899589005890158902589035890458905589065890758908589095891058911589125891358914589155891658917589185891958920589215892258923589245892558926589275892858929589305893158932589335893458935589365893758938589395894058941589425894358944589455894658947589485894958950589515895258953589545895558956589575895858959589605896158962589635896458965589665896758968589695897058971589725897358974589755897658977589785897958980589815898258983589845898558986589875898858989589905899158992589935899458995589965899758998589995900059001590025900359004590055900659007590085900959010590115901259013590145901559016590175901859019590205902159022590235902459025590265902759028590295903059031590325903359034590355903659037590385903959040590415904259043590445904559046590475904859049590505905159052590535905459055590565905759058590595906059061590625906359064590655906659067590685906959070590715907259073590745907559076590775907859079590805908159082590835908459085590865908759088590895909059091590925909359094590955909659097590985909959100591015910259103591045910559106591075910859109591105911159112591135911459115591165911759118591195912059121591225912359124591255912659127591285912959130591315913259133591345913559136591375913859139591405914159142591435914459145591465914759148591495915059151591525915359154591555915659157591585915959160591615916259163591645916559166591675916859169591705917159172591735917459175591765917759178591795918059181591825918359184591855918659187591885918959190591915919259193591945919559196591975919859199592005920159202592035920459205592065920759208592095921059211592125921359214592155921659217592185921959220592215922259223592245922559226592275922859229592305923159232592335923459235592365923759238592395924059241592425924359244592455924659247592485924959250592515925259253592545925559256592575925859259592605926159262592635926459265592665926759268592695927059271592725927359274592755927659277592785927959280592815928259283592845928559286592875928859289592905929159292592935929459295592965929759298592995930059301593025930359304593055930659307593085930959310593115931259313593145931559316593175931859319593205932159322593235932459325593265932759328593295933059331593325933359334593355933659337593385933959340593415934259343593445934559346593475934859349593505935159352593535935459355593565935759358593595936059361593625936359364593655936659367593685936959370593715937259373593745937559376593775937859379593805938159382593835938459385593865938759388593895939059391593925939359394593955939659397593985939959400594015940259403594045940559406594075940859409594105941159412594135941459415594165941759418594195942059421594225942359424594255942659427594285942959430594315943259433594345943559436594375943859439594405944159442594435944459445594465944759448594495945059451594525945359454594555945659457594585945959460594615946259463594645946559466594675946859469594705947159472594735947459475594765947759478594795948059481594825948359484594855948659487594885948959490594915949259493594945949559496594975949859499595005950159502595035950459505595065950759508595095951059511595125951359514595155951659517595185951959520595215952259523595245952559526595275952859529595305953159532595335953459535595365953759538595395954059541595425954359544595455954659547595485954959550595515955259553595545955559556595575955859559595605956159562595635956459565595665956759568595695957059571595725957359574595755957659577595785957959580595815958259583595845958559586595875958859589595905959159592595935959459595595965959759598595995960059601596025960359604596055960659607596085960959610596115961259613596145961559616596175961859619596205962159622596235962459625596265962759628596295963059631596325963359634596355963659637596385963959640596415964259643596445964559646596475964859649596505965159652596535965459655596565965759658596595966059661596625966359664596655966659667596685966959670596715967259673596745967559676596775967859679596805968159682596835968459685596865968759688596895969059691596925969359694596955969659697596985969959700597015970259703597045970559706597075970859709597105971159712597135971459715597165971759718597195972059721597225972359724597255972659727597285972959730597315973259733597345973559736597375973859739597405974159742597435974459745597465974759748597495975059751597525975359754597555975659757597585975959760597615976259763597645976559766597675976859769597705977159772597735977459775597765977759778597795978059781597825978359784597855978659787597885978959790597915979259793597945979559796597975979859799598005980159802598035980459805598065980759808598095981059811598125981359814598155981659817598185981959820598215982259823598245982559826598275982859829598305983159832598335983459835598365983759838598395984059841598425984359844598455984659847598485984959850598515985259853598545985559856598575985859859598605986159862598635986459865598665986759868598695987059871598725987359874598755987659877598785987959880598815988259883598845988559886598875988859889598905989159892598935989459895598965989759898598995990059901599025990359904599055990659907599085990959910599115991259913599145991559916599175991859919599205992159922599235992459925599265992759928599295993059931599325993359934599355993659937599385993959940599415994259943599445994559946599475994859949599505995159952599535995459955599565995759958599595996059961599625996359964599655996659967599685996959970599715997259973599745997559976599775997859979599805998159982599835998459985599865998759988599895999059991599925999359994599955999659997599985999960000600016000260003600046000560006600076000860009600106001160012600136001460015600166001760018600196002060021600226002360024600256002660027600286002960030600316003260033600346003560036600376003860039600406004160042600436004460045600466004760048600496005060051600526005360054600556005660057600586005960060600616006260063600646006560066600676006860069600706007160072600736007460075600766007760078600796008060081600826008360084600856008660087600886008960090600916009260093600946009560096600976009860099601006010160102601036010460105601066010760108601096011060111601126011360114601156011660117601186011960120601216012260123601246012560126601276012860129601306013160132601336013460135601366013760138601396014060141601426014360144601456014660147601486014960150601516015260153601546015560156601576015860159601606016160162601636016460165601666016760168601696017060171601726017360174601756017660177601786017960180601816018260183601846018560186601876018860189601906019160192601936019460195601966019760198601996020060201602026020360204602056020660207602086020960210602116021260213602146021560216602176021860219602206022160222602236022460225602266022760228602296023060231602326023360234602356023660237602386023960240602416024260243602446024560246602476024860249602506025160252602536025460255602566025760258602596026060261602626026360264602656026660267602686026960270602716027260273602746027560276602776027860279602806028160282602836028460285602866028760288602896029060291602926029360294602956029660297602986029960300603016030260303603046030560306603076030860309603106031160312603136031460315603166031760318603196032060321603226032360324603256032660327603286032960330603316033260333603346033560336603376033860339603406034160342603436034460345603466034760348603496035060351603526035360354603556035660357603586035960360603616036260363603646036560366603676036860369603706037160372603736037460375603766037760378603796038060381603826038360384603856038660387603886038960390603916039260393603946039560396603976039860399604006040160402604036040460405604066040760408604096041060411604126041360414604156041660417604186041960420604216042260423604246042560426604276042860429604306043160432604336043460435604366043760438604396044060441604426044360444604456044660447604486044960450604516045260453604546045560456604576045860459604606046160462604636046460465604666046760468604696047060471604726047360474604756047660477604786047960480604816048260483604846048560486604876048860489604906049160492604936049460495604966049760498604996050060501605026050360504605056050660507605086050960510605116051260513605146051560516605176051860519605206052160522605236052460525605266052760528605296053060531605326053360534605356053660537605386053960540605416054260543605446054560546605476054860549605506055160552605536055460555605566055760558605596056060561605626056360564605656056660567605686056960570605716057260573605746057560576605776057860579605806058160582605836058460585605866058760588605896059060591605926059360594605956059660597605986059960600606016060260603606046060560606606076060860609606106061160612606136061460615606166061760618606196062060621606226062360624606256062660627606286062960630606316063260633606346063560636606376063860639606406064160642606436064460645606466064760648606496065060651606526065360654606556065660657606586065960660606616066260663606646066560666606676066860669606706067160672606736067460675606766067760678606796068060681606826068360684606856068660687606886068960690606916069260693606946069560696606976069860699607006070160702607036070460705607066070760708607096071060711607126071360714607156071660717607186071960720607216072260723607246072560726607276072860729607306073160732607336073460735607366073760738607396074060741607426074360744607456074660747607486074960750607516075260753607546075560756607576075860759607606076160762607636076460765607666076760768607696077060771607726077360774607756077660777607786077960780607816078260783607846078560786607876078860789607906079160792607936079460795607966079760798607996080060801608026080360804608056080660807608086080960810608116081260813608146081560816608176081860819608206082160822608236082460825608266082760828608296083060831608326083360834608356083660837608386083960840608416084260843608446084560846608476084860849608506085160852608536085460855608566085760858608596086060861608626086360864608656086660867608686086960870608716087260873608746087560876608776087860879608806088160882608836088460885608866088760888608896089060891608926089360894608956089660897608986089960900609016090260903609046090560906609076090860909609106091160912609136091460915609166091760918609196092060921609226092360924609256092660927609286092960930609316093260933609346093560936609376093860939609406094160942609436094460945609466094760948609496095060951609526095360954609556095660957609586095960960609616096260963609646096560966609676096860969609706097160972609736097460975609766097760978609796098060981609826098360984609856098660987609886098960990609916099260993609946099560996609976099860999610006100161002610036100461005610066100761008610096101061011610126101361014610156101661017610186101961020610216102261023610246102561026610276102861029610306103161032610336103461035610366103761038610396104061041610426104361044610456104661047610486104961050610516105261053610546105561056610576105861059610606106161062610636106461065610666106761068610696107061071610726107361074610756107661077610786107961080610816108261083610846108561086610876108861089610906109161092610936109461095610966109761098610996110061101611026110361104611056110661107611086110961110611116111261113611146111561116611176111861119611206112161122611236112461125611266112761128611296113061131611326113361134611356113661137611386113961140611416114261143611446114561146611476114861149611506115161152611536115461155611566115761158611596116061161611626116361164611656116661167611686116961170611716117261173611746117561176611776117861179611806118161182611836118461185611866118761188611896119061191611926119361194611956119661197611986119961200612016120261203612046120561206612076120861209612106121161212612136121461215612166121761218612196122061221612226122361224612256122661227612286122961230612316123261233612346123561236612376123861239612406124161242612436124461245612466124761248612496125061251612526125361254612556125661257612586125961260612616126261263612646126561266612676126861269612706127161272612736127461275612766127761278612796128061281612826128361284612856128661287612886128961290612916129261293612946129561296612976129861299613006130161302613036130461305613066130761308613096131061311613126131361314613156131661317613186131961320613216132261323613246132561326613276132861329613306133161332613336133461335613366133761338613396134061341613426134361344613456134661347613486134961350613516135261353613546135561356613576135861359613606136161362613636136461365613666136761368613696137061371613726137361374613756137661377613786137961380613816138261383613846138561386613876138861389613906139161392613936139461395613966139761398613996140061401614026140361404614056140661407614086140961410614116141261413614146141561416614176141861419614206142161422614236142461425614266142761428614296143061431614326143361434614356143661437614386143961440614416144261443614446144561446614476144861449614506145161452614536145461455614566145761458614596146061461614626146361464614656146661467614686146961470614716147261473614746147561476614776147861479614806148161482614836148461485614866148761488614896149061491614926149361494614956149661497614986149961500615016150261503615046150561506615076150861509615106151161512615136151461515615166151761518615196152061521615226152361524615256152661527615286152961530615316153261533615346153561536615376153861539615406154161542615436154461545615466154761548615496155061551615526155361554615556155661557615586155961560615616156261563615646156561566615676156861569615706157161572615736157461575615766157761578615796158061581615826158361584615856158661587615886158961590615916159261593615946159561596615976159861599616006160161602616036160461605616066160761608616096161061611616126161361614616156161661617616186161961620616216162261623616246162561626616276162861629616306163161632616336163461635616366163761638616396164061641616426164361644616456164661647616486164961650616516165261653616546165561656616576165861659616606166161662616636166461665616666166761668616696167061671616726167361674616756167661677616786167961680616816168261683616846168561686616876168861689616906169161692616936169461695616966169761698616996170061701617026170361704617056170661707617086170961710617116171261713617146171561716617176171861719617206172161722617236172461725617266172761728617296173061731617326173361734617356173661737617386173961740617416174261743617446174561746617476174861749617506175161752617536175461755617566175761758617596176061761617626176361764617656176661767617686176961770617716177261773617746177561776617776177861779617806178161782617836178461785617866178761788617896179061791617926179361794617956179661797617986179961800618016180261803618046180561806618076180861809618106181161812618136181461815618166181761818618196182061821618226182361824618256182661827618286182961830618316183261833618346183561836618376183861839618406184161842618436184461845618466184761848618496185061851618526185361854618556185661857618586185961860618616186261863618646186561866618676186861869618706187161872618736187461875618766187761878618796188061881618826188361884618856188661887618886188961890618916189261893618946189561896618976189861899619006190161902619036190461905619066190761908619096191061911619126191361914619156191661917619186191961920619216192261923619246192561926619276192861929619306193161932619336193461935619366193761938619396194061941619426194361944619456194661947619486194961950619516195261953619546195561956619576195861959619606196161962619636196461965619666196761968619696197061971619726197361974619756197661977619786197961980619816198261983619846198561986619876198861989619906199161992619936199461995619966199761998619996200062001620026200362004620056200662007620086200962010620116201262013620146201562016620176201862019620206202162022620236202462025620266202762028620296203062031620326203362034620356203662037620386203962040620416204262043620446204562046620476204862049620506205162052620536205462055620566205762058620596206062061620626206362064620656206662067620686206962070620716207262073620746207562076620776207862079620806208162082620836208462085620866208762088620896209062091620926209362094620956209662097620986209962100621016210262103621046210562106621076210862109621106211162112621136211462115621166211762118621196212062121621226212362124621256212662127621286212962130621316213262133621346213562136621376213862139621406214162142621436214462145621466214762148621496215062151621526215362154621556215662157621586215962160621616216262163621646216562166621676216862169621706217162172621736217462175621766217762178621796218062181621826218362184621856218662187621886218962190621916219262193621946219562196621976219862199622006220162202622036220462205622066220762208622096221062211622126221362214622156221662217622186221962220622216222262223622246222562226622276222862229622306223162232622336223462235622366223762238622396224062241622426224362244622456224662247622486224962250622516225262253622546225562256622576225862259622606226162262622636226462265622666226762268622696227062271622726227362274622756227662277622786227962280622816228262283622846228562286622876228862289622906229162292622936229462295622966229762298622996230062301623026230362304623056230662307623086230962310623116231262313623146231562316623176231862319623206232162322623236232462325623266232762328623296233062331623326233362334623356233662337623386233962340623416234262343623446234562346623476234862349623506235162352623536235462355623566235762358623596236062361623626236362364623656236662367623686236962370623716237262373623746237562376623776237862379623806238162382623836238462385623866238762388623896239062391623926239362394623956239662397623986239962400624016240262403624046240562406624076240862409624106241162412624136241462415624166241762418624196242062421624226242362424624256242662427624286242962430624316243262433624346243562436624376243862439624406244162442624436244462445624466244762448624496245062451624526245362454624556245662457624586245962460624616246262463624646246562466624676246862469624706247162472624736247462475624766247762478624796248062481624826248362484624856248662487624886248962490624916249262493624946249562496624976249862499625006250162502625036250462505625066250762508625096251062511625126251362514625156251662517625186251962520625216252262523625246252562526625276252862529625306253162532625336253462535625366253762538625396254062541625426254362544625456254662547625486254962550625516255262553625546255562556625576255862559625606256162562625636256462565625666256762568625696257062571625726257362574625756257662577625786257962580625816258262583625846258562586625876258862589625906259162592625936259462595625966259762598625996260062601626026260362604626056260662607626086260962610626116261262613626146261562616626176261862619626206262162622626236262462625626266262762628626296263062631626326263362634626356263662637626386263962640626416264262643626446264562646626476264862649626506265162652626536265462655626566265762658626596266062661626626266362664626656266662667626686266962670626716267262673626746267562676626776267862679626806268162682626836268462685626866268762688626896269062691626926269362694626956269662697626986269962700627016270262703627046270562706627076270862709627106271162712627136271462715627166271762718627196272062721627226272362724627256272662727627286272962730627316273262733627346273562736627376273862739627406274162742627436274462745627466274762748627496275062751627526275362754627556275662757627586275962760627616276262763627646276562766627676276862769627706277162772627736277462775627766277762778627796278062781627826278362784627856278662787627886278962790627916279262793627946279562796627976279862799628006280162802628036280462805628066280762808628096281062811628126281362814628156281662817628186281962820628216282262823628246282562826628276282862829628306283162832628336283462835628366283762838628396284062841628426284362844628456284662847628486284962850628516285262853628546285562856628576285862859628606286162862628636286462865628666286762868628696287062871628726287362874628756287662877628786287962880628816288262883628846288562886628876288862889628906289162892628936289462895628966289762898628996290062901629026290362904629056290662907629086290962910629116291262913629146291562916629176291862919629206292162922629236292462925629266292762928629296293062931629326293362934629356293662937629386293962940629416294262943629446294562946629476294862949629506295162952629536295462955629566295762958629596296062961629626296362964629656296662967629686296962970629716297262973629746297562976629776297862979629806298162982629836298462985629866298762988629896299062991629926299362994629956299662997629986299963000630016300263003630046300563006630076300863009630106301163012630136301463015630166301763018630196302063021630226302363024630256302663027630286302963030630316303263033630346303563036630376303863039630406304163042630436304463045630466304763048630496305063051630526305363054630556305663057630586305963060630616306263063630646306563066630676306863069630706307163072630736307463075630766307763078630796308063081630826308363084630856308663087630886308963090630916309263093630946309563096630976309863099631006310163102631036310463105631066310763108631096311063111631126311363114631156311663117631186311963120631216312263123631246312563126631276312863129631306313163132631336313463135631366313763138631396314063141631426314363144631456314663147631486314963150631516315263153631546315563156631576315863159631606316163162631636316463165631666316763168631696317063171631726317363174631756317663177631786317963180631816318263183631846318563186631876318863189631906319163192631936319463195631966319763198631996320063201632026320363204632056320663207632086320963210632116321263213632146321563216632176321863219632206322163222632236322463225632266322763228632296323063231632326323363234632356323663237632386323963240632416324263243632446324563246632476324863249632506325163252632536325463255632566325763258632596326063261632626326363264632656326663267632686326963270632716327263273632746327563276632776327863279632806328163282632836328463285632866328763288632896329063291632926329363294632956329663297632986329963300633016330263303633046330563306633076330863309633106331163312633136331463315633166331763318633196332063321633226332363324633256332663327633286332963330633316333263333633346333563336633376333863339633406334163342633436334463345633466334763348633496335063351633526335363354633556335663357633586335963360633616336263363633646336563366633676336863369633706337163372633736337463375633766337763378633796338063381633826338363384633856338663387633886338963390633916339263393633946339563396633976339863399634006340163402634036340463405634066340763408634096341063411634126341363414634156341663417634186341963420634216342263423634246342563426634276342863429634306343163432634336343463435634366343763438634396344063441634426344363444634456344663447634486344963450634516345263453634546345563456634576345863459634606346163462634636346463465634666346763468634696347063471634726347363474634756347663477634786347963480634816348263483634846348563486634876348863489634906349163492634936349463495634966349763498634996350063501635026350363504635056350663507635086350963510635116351263513635146351563516635176351863519635206352163522635236352463525635266352763528635296353063531635326353363534635356353663537635386353963540635416354263543635446354563546635476354863549635506355163552635536355463555635566355763558635596356063561635626356363564635656356663567635686356963570635716357263573635746357563576635776357863579635806358163582635836358463585635866358763588635896359063591635926359363594635956359663597635986359963600636016360263603636046360563606636076360863609636106361163612636136361463615636166361763618636196362063621636226362363624636256362663627636286362963630636316363263633636346363563636636376363863639636406364163642636436364463645636466364763648636496365063651636526365363654636556365663657636586365963660636616366263663636646366563666636676366863669636706367163672636736367463675636766367763678636796368063681636826368363684636856368663687636886368963690636916369263693636946369563696636976369863699637006370163702637036370463705637066370763708637096371063711637126371363714637156371663717637186371963720637216372263723637246372563726637276372863729637306373163732637336373463735637366373763738637396374063741637426374363744637456374663747637486374963750637516375263753637546375563756637576375863759637606376163762637636376463765637666376763768637696377063771637726377363774637756377663777637786377963780637816378263783637846378563786637876378863789637906379163792637936379463795637966379763798637996380063801638026380363804638056380663807638086380963810638116381263813638146381563816638176381863819638206382163822638236382463825638266382763828638296383063831638326383363834638356383663837638386383963840638416384263843638446384563846638476384863849638506385163852638536385463855638566385763858638596386063861638626386363864638656386663867638686386963870638716387263873638746387563876638776387863879638806388163882638836388463885638866388763888638896389063891638926389363894638956389663897638986389963900639016390263903639046390563906639076390863909639106391163912639136391463915639166391763918639196392063921639226392363924639256392663927639286392963930639316393263933639346393563936639376393863939639406394163942639436394463945639466394763948639496395063951639526395363954639556395663957639586395963960639616396263963639646396563966639676396863969639706397163972639736397463975639766397763978639796398063981639826398363984639856398663987639886398963990639916399263993639946399563996639976399863999640006400164002640036400464005640066400764008640096401064011640126401364014640156401664017640186401964020640216402264023640246402564026640276402864029640306403164032640336403464035640366403764038640396404064041640426404364044640456404664047640486404964050640516405264053640546405564056640576405864059640606406164062640636406464065640666406764068640696407064071640726407364074640756407664077640786407964080640816408264083640846408564086640876408864089640906409164092640936409464095640966409764098640996410064101641026410364104641056410664107641086410964110641116411264113641146411564116641176411864119641206412164122641236412464125641266412764128641296413064131641326413364134641356413664137641386413964140641416414264143641446414564146641476414864149641506415164152641536415464155641566415764158641596416064161641626416364164641656416664167641686416964170641716417264173641746417564176641776417864179641806418164182641836418464185641866418764188641896419064191641926419364194641956419664197641986419964200642016420264203642046420564206642076420864209642106421164212642136421464215642166421764218642196422064221642226422364224642256422664227642286422964230642316423264233642346423564236642376423864239642406424164242642436424464245642466424764248642496425064251642526425364254642556425664257642586425964260642616426264263642646426564266642676426864269642706427164272642736427464275642766427764278642796428064281642826428364284642856428664287642886428964290642916429264293642946429564296642976429864299643006430164302643036430464305643066430764308643096431064311643126431364314643156431664317643186431964320643216432264323643246432564326643276432864329643306433164332643336433464335643366433764338643396434064341643426434364344643456434664347643486434964350643516435264353643546435564356643576435864359643606436164362643636436464365643666436764368643696437064371643726437364374643756437664377643786437964380643816438264383643846438564386643876438864389643906439164392643936439464395643966439764398643996440064401644026440364404644056440664407644086440964410644116441264413644146441564416644176441864419644206442164422644236442464425644266442764428644296443064431644326443364434644356443664437644386443964440644416444264443644446444564446644476444864449644506445164452644536445464455644566445764458644596446064461644626446364464644656446664467644686446964470644716447264473644746447564476644776447864479644806448164482644836448464485644866448764488644896449064491644926449364494644956449664497644986449964500645016450264503645046450564506645076450864509645106451164512645136451464515645166451764518645196452064521645226452364524645256452664527645286452964530645316453264533645346453564536645376453864539645406454164542645436454464545645466454764548645496455064551645526455364554645556455664557645586455964560645616456264563645646456564566645676456864569645706457164572645736457464575645766457764578645796458064581645826458364584645856458664587645886458964590645916459264593645946459564596645976459864599646006460164602646036460464605646066460764608646096461064611646126461364614646156461664617646186461964620646216462264623646246462564626646276462864629646306463164632646336463464635646366463764638646396464064641646426464364644646456464664647646486464964650646516465264653646546465564656646576465864659646606466164662646636466464665646666466764668646696467064671646726467364674646756467664677646786467964680646816468264683646846468564686646876468864689646906469164692646936469464695646966469764698646996470064701647026470364704647056470664707647086470964710647116471264713647146471564716647176471864719647206472164722647236472464725647266472764728647296473064731647326473364734647356473664737647386473964740647416474264743647446474564746647476474864749647506475164752647536475464755647566475764758647596476064761647626476364764647656476664767647686476964770647716477264773647746477564776647776477864779647806478164782647836478464785647866478764788647896479064791647926479364794647956479664797647986479964800648016480264803648046480564806648076480864809648106481164812648136481464815648166481764818648196482064821648226482364824648256482664827648286482964830648316483264833648346483564836648376483864839648406484164842648436484464845648466484764848648496485064851648526485364854648556485664857648586485964860648616486264863648646486564866648676486864869648706487164872648736487464875648766487764878648796488064881648826488364884648856488664887648886488964890648916489264893648946489564896648976489864899649006490164902649036490464905649066490764908649096491064911649126491364914649156491664917649186491964920649216492264923649246492564926649276492864929649306493164932649336493464935649366493764938649396494064941649426494364944649456494664947649486494964950649516495264953649546495564956649576495864959649606496164962649636496464965649666496764968649696497064971649726497364974649756497664977649786497964980649816498264983649846498564986649876498864989649906499164992649936499464995649966499764998649996500065001650026500365004650056500665007650086500965010650116501265013650146501565016650176501865019650206502165022650236502465025650266502765028650296503065031650326503365034650356503665037650386503965040650416504265043650446504565046650476504865049650506505165052650536505465055650566505765058650596506065061650626506365064650656506665067650686506965070650716507265073650746507565076650776507865079650806508165082650836508465085650866508765088650896509065091650926509365094650956509665097650986509965100651016510265103651046510565106651076510865109651106511165112651136511465115651166511765118651196512065121651226512365124651256512665127651286512965130651316513265133651346513565136651376513865139651406514165142651436514465145651466514765148651496515065151651526515365154651556515665157651586515965160651616516265163651646516565166651676516865169651706517165172651736517465175651766517765178651796518065181651826518365184651856518665187651886518965190651916519265193651946519565196651976519865199652006520165202652036520465205652066520765208652096521065211652126521365214652156521665217652186521965220652216522265223652246522565226652276522865229652306523165232652336523465235652366523765238652396524065241652426524365244652456524665247652486524965250652516525265253652546525565256652576525865259652606526165262652636526465265652666526765268652696527065271652726527365274652756527665277652786527965280652816528265283652846528565286652876528865289652906529165292652936529465295652966529765298652996530065301653026530365304653056530665307653086530965310653116531265313653146531565316653176531865319653206532165322653236532465325653266532765328653296533065331653326533365334653356533665337653386533965340653416534265343653446534565346653476534865349653506535165352653536535465355653566535765358653596536065361653626536365364653656536665367653686536965370653716537265373653746537565376653776537865379653806538165382653836538465385653866538765388653896539065391653926539365394653956539665397653986539965400654016540265403654046540565406654076540865409654106541165412654136541465415654166541765418654196542065421654226542365424654256542665427654286542965430654316543265433654346543565436654376543865439654406544165442654436544465445654466544765448654496545065451654526545365454654556545665457654586545965460654616546265463654646546565466654676546865469654706547165472654736547465475654766547765478654796548065481654826548365484654856548665487654886548965490654916549265493654946549565496654976549865499655006550165502655036550465505655066550765508655096551065511655126551365514655156551665517655186551965520655216552265523655246552565526655276552865529655306553165532655336553465535655366553765538655396554065541655426554365544655456554665547655486554965550655516555265553655546555565556655576555865559655606556165562655636556465565655666556765568655696557065571655726557365574655756557665577655786557965580655816558265583655846558565586655876558865589655906559165592655936559465595655966559765598655996560065601656026560365604656056560665607656086560965610656116561265613656146561565616656176561865619656206562165622656236562465625656266562765628656296563065631656326563365634656356563665637656386563965640656416564265643656446564565646656476564865649656506565165652656536565465655656566565765658656596566065661656626566365664656656566665667656686566965670656716567265673656746567565676656776567865679656806568165682656836568465685656866568765688656896569065691656926569365694656956569665697656986569965700657016570265703657046570565706657076570865709657106571165712657136571465715657166571765718657196572065721657226572365724657256572665727657286572965730657316573265733657346573565736657376573865739657406574165742657436574465745657466574765748657496575065751657526575365754657556575665757657586575965760657616576265763657646576565766657676576865769657706577165772657736577465775657766577765778657796578065781657826578365784657856578665787657886578965790657916579265793657946579565796657976579865799658006580165802658036580465805658066580765808658096581065811658126581365814658156581665817658186581965820658216582265823658246582565826658276582865829658306583165832658336583465835658366583765838658396584065841658426584365844658456584665847658486584965850658516585265853658546585565856658576585865859658606586165862658636586465865658666586765868658696587065871658726587365874658756587665877658786587965880658816588265883658846588565886658876588865889658906589165892658936589465895658966589765898658996590065901659026590365904659056590665907659086590965910659116591265913659146591565916659176591865919659206592165922659236592465925659266592765928659296593065931659326593365934659356593665937659386593965940659416594265943659446594565946659476594865949659506595165952659536595465955659566595765958659596596065961659626596365964659656596665967659686596965970659716597265973659746597565976659776597865979659806598165982659836598465985659866598765988659896599065991659926599365994659956599665997659986599966000660016600266003660046600566006660076600866009660106601166012660136601466015660166601766018660196602066021660226602366024660256602666027660286602966030660316603266033660346603566036660376603866039660406604166042660436604466045660466604766048660496605066051660526605366054660556605666057660586605966060660616606266063660646606566066660676606866069660706607166072660736607466075660766607766078660796608066081660826608366084660856608666087660886608966090660916609266093660946609566096660976609866099661006610166102661036610466105661066610766108661096611066111661126611366114661156611666117661186611966120661216612266123661246612566126661276612866129661306613166132661336613466135661366613766138661396614066141661426614366144661456614666147661486614966150661516615266153661546615566156661576615866159661606616166162661636616466165661666616766168661696617066171661726617366174661756617666177661786617966180661816618266183661846618566186661876618866189661906619166192661936619466195661966619766198661996620066201662026620366204662056620666207662086620966210662116621266213662146621566216662176621866219662206622166222662236622466225662266622766228662296623066231662326623366234662356623666237662386623966240662416624266243662446624566246662476624866249662506625166252662536625466255662566625766258662596626066261662626626366264662656626666267662686626966270662716627266273662746627566276662776627866279662806628166282662836628466285662866628766288662896629066291662926629366294662956629666297662986629966300663016630266303663046630566306663076630866309663106631166312663136631466315663166631766318663196632066321663226632366324663256632666327663286632966330663316633266333663346633566336663376633866339663406634166342663436634466345663466634766348663496635066351663526635366354663556635666357663586635966360663616636266363663646636566366663676636866369663706637166372663736637466375663766637766378663796638066381663826638366384663856638666387663886638966390663916639266393663946639566396663976639866399664006640166402664036640466405664066640766408664096641066411664126641366414664156641666417664186641966420664216642266423664246642566426664276642866429664306643166432664336643466435664366643766438664396644066441664426644366444664456644666447664486644966450664516645266453664546645566456664576645866459664606646166462664636646466465664666646766468664696647066471664726647366474664756647666477664786647966480664816648266483664846648566486664876648866489664906649166492664936649466495664966649766498664996650066501665026650366504665056650666507665086650966510665116651266513665146651566516665176651866519665206652166522665236652466525665266652766528665296653066531665326653366534665356653666537665386653966540665416654266543665446654566546665476654866549665506655166552665536655466555665566655766558665596656066561665626656366564665656656666567665686656966570665716657266573665746657566576665776657866579665806658166582665836658466585665866658766588665896659066591665926659366594665956659666597665986659966600666016660266603666046660566606666076660866609666106661166612666136661466615666166661766618666196662066621666226662366624666256662666627666286662966630666316663266633666346663566636666376663866639666406664166642666436664466645666466664766648666496665066651666526665366654666556665666657666586665966660666616666266663666646666566666666676666866669666706667166672666736667466675666766667766678666796668066681666826668366684666856668666687666886668966690666916669266693666946669566696666976669866699667006670166702667036670466705667066670766708667096671066711667126671366714667156671666717667186671966720667216672266723667246672566726667276672866729667306673166732667336673466735667366673766738667396674066741667426674366744667456674666747667486674966750667516675266753667546675566756667576675866759667606676166762667636676466765667666676766768667696677066771667726677366774667756677666777667786677966780667816678266783667846678566786667876678866789667906679166792667936679466795667966679766798667996680066801668026680366804668056680666807668086680966810668116681266813668146681566816668176681866819668206682166822668236682466825668266682766828668296683066831668326683366834668356683666837668386683966840668416684266843668446684566846668476684866849668506685166852668536685466855668566685766858668596686066861668626686366864668656686666867668686686966870668716687266873668746687566876668776687866879668806688166882668836688466885668866688766888668896689066891668926689366894668956689666897668986689966900669016690266903669046690566906669076690866909669106691166912669136691466915669166691766918669196692066921669226692366924669256692666927669286692966930669316693266933669346693566936669376693866939669406694166942669436694466945669466694766948669496695066951669526695366954669556695666957669586695966960669616696266963669646696566966669676696866969669706697166972669736697466975669766697766978669796698066981669826698366984669856698666987669886698966990669916699266993669946699566996669976699866999670006700167002670036700467005670066700767008670096701067011670126701367014670156701667017670186701967020670216702267023670246702567026670276702867029670306703167032670336703467035670366703767038670396704067041670426704367044670456704667047670486704967050670516705267053670546705567056670576705867059670606706167062670636706467065670666706767068670696707067071670726707367074670756707667077670786707967080670816708267083670846708567086670876708867089670906709167092670936709467095670966709767098670996710067101671026710367104671056710667107671086710967110671116711267113671146711567116671176711867119671206712167122671236712467125671266712767128671296713067131671326713367134671356713667137671386713967140671416714267143671446714567146671476714867149671506715167152671536715467155671566715767158671596716067161671626716367164671656716667167671686716967170671716717267173671746717567176671776717867179671806718167182671836718467185671866718767188671896719067191671926719367194671956719667197671986719967200672016720267203672046720567206672076720867209672106721167212672136721467215672166721767218672196722067221672226722367224672256722667227672286722967230672316723267233672346723567236672376723867239672406724167242672436724467245672466724767248672496725067251672526725367254672556725667257672586725967260672616726267263672646726567266672676726867269672706727167272672736727467275672766727767278672796728067281672826728367284672856728667287672886728967290672916729267293672946729567296672976729867299673006730167302673036730467305673066730767308673096731067311673126731367314673156731667317673186731967320673216732267323673246732567326673276732867329673306733167332673336733467335673366733767338673396734067341673426734367344673456734667347673486734967350673516735267353673546735567356673576735867359673606736167362673636736467365673666736767368673696737067371673726737367374673756737667377673786737967380673816738267383673846738567386673876738867389673906739167392673936739467395673966739767398673996740067401674026740367404674056740667407674086740967410674116741267413674146741567416674176741867419674206742167422674236742467425674266742767428674296743067431674326743367434674356743667437674386743967440674416744267443674446744567446674476744867449674506745167452674536745467455674566745767458674596746067461674626746367464674656746667467674686746967470674716747267473674746747567476674776747867479674806748167482674836748467485674866748767488674896749067491674926749367494674956749667497674986749967500675016750267503675046750567506675076750867509675106751167512675136751467515675166751767518675196752067521675226752367524675256752667527675286752967530675316753267533675346753567536675376753867539675406754167542675436754467545675466754767548675496755067551675526755367554675556755667557675586755967560675616756267563675646756567566675676756867569675706757167572675736757467575675766757767578675796758067581675826758367584675856758667587675886758967590675916759267593675946759567596675976759867599676006760167602676036760467605676066760767608676096761067611676126761367614676156761667617676186761967620676216762267623676246762567626676276762867629676306763167632676336763467635676366763767638676396764067641676426764367644676456764667647676486764967650676516765267653676546765567656676576765867659676606766167662676636766467665676666766767668676696767067671676726767367674676756767667677676786767967680676816768267683676846768567686676876768867689676906769167692676936769467695676966769767698676996770067701677026770367704677056770667707677086770967710677116771267713677146771567716677176771867719677206772167722677236772467725677266772767728677296773067731677326773367734677356773667737677386773967740677416774267743677446774567746677476774867749677506775167752677536775467755677566775767758677596776067761677626776367764677656776667767677686776967770677716777267773677746777567776677776777867779677806778167782677836778467785677866778767788677896779067791677926779367794677956779667797677986779967800678016780267803678046780567806678076780867809678106781167812678136781467815678166781767818678196782067821678226782367824678256782667827678286782967830678316783267833678346783567836678376783867839678406784167842678436784467845678466784767848678496785067851678526785367854678556785667857678586785967860678616786267863678646786567866678676786867869678706787167872678736787467875678766787767878678796788067881678826788367884678856788667887678886788967890678916789267893678946789567896678976789867899679006790167902679036790467905679066790767908679096791067911679126791367914679156791667917679186791967920679216792267923679246792567926679276792867929679306793167932679336793467935679366793767938679396794067941679426794367944679456794667947679486794967950679516795267953679546795567956679576795867959679606796167962679636796467965679666796767968679696797067971679726797367974679756797667977679786797967980679816798267983679846798567986679876798867989679906799167992679936799467995679966799767998679996800068001680026800368004680056800668007680086800968010680116801268013680146801568016680176801868019680206802168022680236802468025680266802768028680296803068031680326803368034680356803668037680386803968040680416804268043680446804568046680476804868049680506805168052680536805468055680566805768058680596806068061680626806368064680656806668067680686806968070680716807268073680746807568076680776807868079680806808168082680836808468085680866808768088680896809068091680926809368094680956809668097680986809968100681016810268103681046810568106681076810868109681106811168112681136811468115681166811768118681196812068121681226812368124681256812668127681286812968130681316813268133681346813568136681376813868139681406814168142681436814468145681466814768148681496815068151681526815368154681556815668157681586815968160681616816268163681646816568166681676816868169681706817168172681736817468175681766817768178681796818068181681826818368184681856818668187681886818968190681916819268193681946819568196681976819868199682006820168202682036820468205682066820768208682096821068211682126821368214682156821668217682186821968220682216822268223682246822568226682276822868229682306823168232682336823468235682366823768238682396824068241682426824368244682456824668247682486824968250682516825268253682546825568256682576825868259682606826168262682636826468265682666826768268682696827068271682726827368274682756827668277682786827968280682816828268283682846828568286682876828868289682906829168292682936829468295682966829768298682996830068301683026830368304683056830668307683086830968310683116831268313683146831568316683176831868319683206832168322683236832468325683266832768328683296833068331683326833368334683356833668337683386833968340683416834268343683446834568346683476834868349683506835168352683536835468355683566835768358683596836068361683626836368364683656836668367683686836968370683716837268373683746837568376683776837868379683806838168382683836838468385683866838768388683896839068391683926839368394683956839668397683986839968400684016840268403684046840568406684076840868409684106841168412684136841468415684166841768418684196842068421684226842368424684256842668427684286842968430684316843268433684346843568436684376843868439684406844168442684436844468445684466844768448684496845068451684526845368454684556845668457684586845968460684616846268463684646846568466684676846868469684706847168472684736847468475684766847768478684796848068481684826848368484684856848668487684886848968490684916849268493684946849568496684976849868499685006850168502685036850468505685066850768508685096851068511685126851368514685156851668517685186851968520685216852268523685246852568526685276852868529685306853168532685336853468535685366853768538685396854068541685426854368544685456854668547685486854968550685516855268553685546855568556685576855868559685606856168562685636856468565685666856768568685696857068571685726857368574685756857668577685786857968580685816858268583685846858568586685876858868589685906859168592685936859468595685966859768598685996860068601686026860368604686056860668607686086860968610686116861268613686146861568616686176861868619686206862168622686236862468625686266862768628686296863068631686326863368634686356863668637686386863968640686416864268643686446864568646686476864868649686506865168652686536865468655686566865768658686596866068661686626866368664686656866668667686686866968670686716867268673686746867568676686776867868679686806868168682686836868468685686866868768688686896869068691686926869368694686956869668697686986869968700687016870268703687046870568706687076870868709687106871168712687136871468715687166871768718687196872068721687226872368724687256872668727687286872968730687316873268733687346873568736687376873868739687406874168742687436874468745687466874768748687496875068751687526875368754687556875668757687586875968760687616876268763687646876568766687676876868769687706877168772687736877468775687766877768778687796878068781687826878368784687856878668787687886878968790687916879268793687946879568796687976879868799688006880168802688036880468805688066880768808688096881068811688126881368814688156881668817688186881968820688216882268823688246882568826688276882868829688306883168832688336883468835688366883768838688396884068841688426884368844688456884668847688486884968850688516885268853688546885568856688576885868859688606886168862688636886468865688666886768868688696887068871688726887368874688756887668877688786887968880688816888268883688846888568886688876888868889688906889168892688936889468895688966889768898688996890068901689026890368904689056890668907689086890968910689116891268913689146891568916689176891868919689206892168922689236892468925689266892768928689296893068931689326893368934689356893668937689386893968940689416894268943689446894568946689476894868949689506895168952689536895468955689566895768958689596896068961689626896368964689656896668967689686896968970689716897268973689746897568976689776897868979689806898168982689836898468985689866898768988689896899068991689926899368994689956899668997689986899969000690016900269003690046900569006690076900869009690106901169012690136901469015690166901769018690196902069021690226902369024690256902669027690286902969030690316903269033690346903569036690376903869039690406904169042690436904469045690466904769048690496905069051690526905369054690556905669057690586905969060690616906269063690646906569066690676906869069690706907169072690736907469075690766907769078690796908069081690826908369084690856908669087690886908969090690916909269093690946909569096690976909869099691006910169102691036910469105691066910769108691096911069111691126911369114691156911669117691186911969120691216912269123691246912569126691276912869129691306913169132691336913469135691366913769138691396914069141691426914369144691456914669147691486914969150691516915269153691546915569156691576915869159691606916169162691636916469165691666916769168691696917069171691726917369174691756917669177691786917969180691816918269183691846918569186691876918869189691906919169192691936919469195691966919769198691996920069201692026920369204692056920669207692086920969210692116921269213692146921569216692176921869219692206922169222692236922469225692266922769228692296923069231692326923369234692356923669237692386923969240692416924269243692446924569246692476924869249692506925169252692536925469255692566925769258692596926069261692626926369264692656926669267692686926969270692716927269273692746927569276692776927869279692806928169282692836928469285692866928769288692896929069291692926929369294692956929669297692986929969300693016930269303693046930569306693076930869309693106931169312693136931469315693166931769318693196932069321693226932369324693256932669327693286932969330693316933269333693346933569336693376933869339693406934169342693436934469345693466934769348693496935069351693526935369354693556935669357693586935969360693616936269363693646936569366693676936869369693706937169372693736937469375693766937769378693796938069381693826938369384693856938669387693886938969390693916939269393693946939569396693976939869399694006940169402694036940469405694066940769408694096941069411694126941369414694156941669417694186941969420694216942269423694246942569426694276942869429694306943169432694336943469435694366943769438694396944069441694426944369444694456944669447694486944969450694516945269453694546945569456694576945869459694606946169462694636946469465694666946769468694696947069471694726947369474694756947669477694786947969480694816948269483694846948569486694876948869489694906949169492694936949469495694966949769498694996950069501695026950369504695056950669507695086950969510695116951269513695146951569516695176951869519695206952169522695236952469525695266952769528695296953069531695326953369534695356953669537695386953969540695416954269543695446954569546695476954869549695506955169552695536955469555695566955769558695596956069561695626956369564695656956669567695686956969570695716957269573695746957569576695776957869579695806958169582695836958469585695866958769588695896959069591695926959369594695956959669597695986959969600696016960269603696046960569606696076960869609696106961169612696136961469615696166961769618696196962069621696226962369624696256962669627696286962969630696316963269633696346963569636696376963869639696406964169642696436964469645696466964769648696496965069651696526965369654696556965669657696586965969660696616966269663696646966569666696676966869669696706967169672696736967469675696766967769678696796968069681696826968369684696856968669687696886968969690696916969269693696946969569696696976969869699697006970169702697036970469705697066970769708697096971069711697126971369714697156971669717697186971969720697216972269723697246972569726697276972869729697306973169732697336973469735697366973769738697396974069741697426974369744697456974669747697486974969750697516975269753697546975569756697576975869759697606976169762697636976469765697666976769768697696977069771697726977369774697756977669777697786977969780697816978269783697846978569786697876978869789697906979169792697936979469795697966979769798697996980069801698026980369804698056980669807698086980969810698116981269813698146981569816698176981869819698206982169822698236982469825698266982769828698296983069831698326983369834698356983669837698386983969840698416984269843698446984569846698476984869849698506985169852698536985469855698566985769858698596986069861698626986369864698656986669867698686986969870698716987269873698746987569876698776987869879698806988169882698836988469885698866988769888698896989069891698926989369894698956989669897698986989969900699016990269903699046990569906699076990869909699106991169912699136991469915699166991769918699196992069921699226992369924699256992669927699286992969930699316993269933699346993569936699376993869939699406994169942699436994469945699466994769948699496995069951699526995369954699556995669957699586995969960699616996269963699646996569966699676996869969699706997169972699736997469975699766997769978699796998069981699826998369984699856998669987699886998969990699916999269993699946999569996699976999869999700007000170002700037000470005700067000770008700097001070011700127001370014700157001670017700187001970020700217002270023700247002570026700277002870029700307003170032700337003470035700367003770038700397004070041700427004370044700457004670047700487004970050700517005270053700547005570056700577005870059700607006170062700637006470065700667006770068700697007070071700727007370074700757007670077700787007970080700817008270083700847008570086700877008870089700907009170092700937009470095700967009770098700997010070101701027010370104701057010670107701087010970110701117011270113701147011570116701177011870119701207012170122701237012470125701267012770128701297013070131701327013370134701357013670137701387013970140701417014270143701447014570146701477014870149701507015170152701537015470155701567015770158701597016070161701627016370164701657016670167701687016970170701717017270173701747017570176701777017870179701807018170182701837018470185701867018770188701897019070191701927019370194701957019670197701987019970200702017020270203702047020570206702077020870209702107021170212702137021470215702167021770218702197022070221702227022370224702257022670227702287022970230702317023270233702347023570236702377023870239702407024170242702437024470245702467024770248702497025070251702527025370254702557025670257702587025970260702617026270263702647026570266702677026870269702707027170272702737027470275702767027770278702797028070281702827028370284702857028670287702887028970290702917029270293702947029570296702977029870299703007030170302703037030470305703067030770308703097031070311703127031370314703157031670317703187031970320703217032270323703247032570326703277032870329703307033170332703337033470335703367033770338703397034070341703427034370344703457034670347703487034970350703517035270353703547035570356703577035870359703607036170362703637036470365703667036770368703697037070371703727037370374703757037670377703787037970380703817038270383703847038570386703877038870389703907039170392703937039470395703967039770398703997040070401704027040370404704057040670407704087040970410704117041270413704147041570416704177041870419704207042170422704237042470425704267042770428704297043070431704327043370434704357043670437704387043970440704417044270443704447044570446704477044870449704507045170452704537045470455704567045770458704597046070461704627046370464704657046670467704687046970470704717047270473704747047570476704777047870479704807048170482704837048470485704867048770488704897049070491704927049370494704957049670497704987049970500705017050270503705047050570506705077050870509705107051170512705137051470515705167051770518705197052070521705227052370524705257052670527705287052970530705317053270533705347053570536705377053870539705407054170542705437054470545705467054770548705497055070551705527055370554705557055670557705587055970560705617056270563705647056570566705677056870569705707057170572705737057470575705767057770578705797058070581705827058370584705857058670587705887058970590705917059270593705947059570596705977059870599706007060170602706037060470605706067060770608706097061070611706127061370614706157061670617706187061970620706217062270623706247062570626706277062870629706307063170632706337063470635706367063770638706397064070641706427064370644706457064670647706487064970650706517065270653706547065570656706577065870659706607066170662706637066470665706667066770668706697067070671706727067370674706757067670677706787067970680706817068270683706847068570686706877068870689706907069170692706937069470695706967069770698706997070070701707027070370704707057070670707707087070970710707117071270713707147071570716707177071870719707207072170722707237072470725707267072770728707297073070731707327073370734707357073670737707387073970740707417074270743707447074570746707477074870749707507075170752707537075470755707567075770758707597076070761707627076370764707657076670767707687076970770707717077270773707747077570776707777077870779707807078170782707837078470785707867078770788707897079070791707927079370794707957079670797707987079970800708017080270803708047080570806708077080870809708107081170812708137081470815708167081770818708197082070821708227082370824708257082670827708287082970830708317083270833708347083570836708377083870839708407084170842708437084470845708467084770848708497085070851708527085370854708557085670857708587085970860708617086270863708647086570866708677086870869708707087170872708737087470875708767087770878708797088070881708827088370884708857088670887708887088970890708917089270893708947089570896708977089870899709007090170902709037090470905709067090770908709097091070911709127091370914709157091670917709187091970920709217092270923709247092570926709277092870929709307093170932709337093470935709367093770938709397094070941709427094370944709457094670947709487094970950709517095270953709547095570956709577095870959709607096170962709637096470965709667096770968709697097070971709727097370974709757097670977709787097970980709817098270983709847098570986709877098870989709907099170992709937099470995709967099770998709997100071001710027100371004710057100671007710087100971010710117101271013710147101571016710177101871019710207102171022710237102471025710267102771028710297103071031710327103371034710357103671037710387103971040710417104271043710447104571046710477104871049710507105171052710537105471055710567105771058710597106071061710627106371064710657106671067710687106971070710717107271073710747107571076710777107871079710807108171082710837108471085710867108771088710897109071091710927109371094710957109671097710987109971100711017110271103711047110571106711077110871109711107111171112711137111471115711167111771118711197112071121711227112371124711257112671127711287112971130711317113271133711347113571136711377113871139711407114171142711437114471145711467114771148711497115071151711527115371154711557115671157711587115971160711617116271163711647116571166711677116871169711707117171172711737117471175711767117771178711797118071181711827118371184711857118671187711887118971190711917119271193711947119571196711977119871199712007120171202712037120471205712067120771208712097121071211712127121371214712157121671217712187121971220712217122271223712247122571226712277122871229712307123171232712337123471235712367123771238712397124071241712427124371244712457124671247712487124971250712517125271253712547125571256712577125871259712607126171262712637126471265712667126771268712697127071271712727127371274712757127671277712787127971280712817128271283712847128571286712877128871289712907129171292712937129471295712967129771298712997130071301713027130371304713057130671307713087130971310713117131271313713147131571316713177131871319713207132171322713237132471325713267132771328713297133071331713327133371334713357133671337713387133971340713417134271343713447134571346713477134871349713507135171352713537135471355713567135771358713597136071361713627136371364713657136671367713687136971370713717137271373713747137571376713777137871379713807138171382713837138471385713867138771388713897139071391713927139371394713957139671397713987139971400714017140271403714047140571406714077140871409714107141171412714137141471415714167141771418714197142071421714227142371424714257142671427714287142971430714317143271433714347143571436714377143871439714407144171442714437144471445714467144771448714497145071451714527145371454714557145671457714587145971460714617146271463714647146571466714677146871469714707147171472714737147471475714767147771478714797148071481714827148371484714857148671487714887148971490714917149271493714947149571496714977149871499715007150171502715037150471505715067150771508715097151071511715127151371514715157151671517715187151971520715217152271523715247152571526715277152871529715307153171532715337153471535715367153771538715397154071541715427154371544715457154671547715487154971550715517155271553715547155571556715577155871559715607156171562715637156471565715667156771568715697157071571715727157371574715757157671577715787157971580715817158271583715847158571586715877158871589715907159171592715937159471595715967159771598715997160071601716027160371604716057160671607716087160971610716117161271613716147161571616716177161871619716207162171622716237162471625716267162771628716297163071631716327163371634716357163671637716387163971640716417164271643716447164571646716477164871649716507165171652716537165471655716567165771658716597166071661716627166371664716657166671667716687166971670716717167271673716747167571676716777167871679716807168171682716837168471685716867168771688716897169071691716927169371694716957169671697716987169971700717017170271703717047170571706717077170871709717107171171712717137171471715717167171771718717197172071721717227172371724717257172671727717287172971730717317173271733717347173571736717377173871739717407174171742717437174471745717467174771748717497175071751717527175371754717557175671757717587175971760717617176271763717647176571766717677176871769717707177171772717737177471775717767177771778717797178071781717827178371784717857178671787717887178971790717917179271793717947179571796717977179871799718007180171802718037180471805718067180771808718097181071811718127181371814718157181671817718187181971820718217182271823718247182571826718277182871829718307183171832718337183471835718367183771838718397184071841718427184371844718457184671847718487184971850718517185271853718547185571856718577185871859718607186171862718637186471865718667186771868718697187071871718727187371874718757187671877718787187971880718817188271883718847188571886718877188871889718907189171892718937189471895718967189771898718997190071901719027190371904719057190671907719087190971910719117191271913719147191571916719177191871919719207192171922719237192471925719267192771928719297193071931719327193371934719357193671937719387193971940719417194271943719447194571946719477194871949719507195171952719537195471955719567195771958719597196071961719627196371964719657196671967719687196971970719717197271973719747197571976719777197871979719807198171982719837198471985719867198771988719897199071991719927199371994719957199671997719987199972000720017200272003720047200572006720077200872009720107201172012720137201472015720167201772018720197202072021720227202372024720257202672027720287202972030720317203272033720347203572036720377203872039720407204172042720437204472045720467204772048720497205072051720527205372054720557205672057720587205972060720617206272063720647206572066720677206872069720707207172072720737207472075720767207772078720797208072081720827208372084720857208672087720887208972090720917209272093720947209572096720977209872099721007210172102721037210472105721067210772108721097211072111721127211372114721157211672117721187211972120721217212272123721247212572126721277212872129721307213172132721337213472135721367213772138721397214072141721427214372144721457214672147721487214972150721517215272153721547215572156721577215872159721607216172162721637216472165721667216772168721697217072171721727217372174721757217672177721787217972180721817218272183721847218572186721877218872189721907219172192721937219472195721967219772198721997220072201722027220372204722057220672207722087220972210722117221272213722147221572216722177221872219722207222172222722237222472225722267222772228722297223072231722327223372234722357223672237722387223972240722417224272243722447224572246722477224872249722507225172252722537225472255722567225772258722597226072261722627226372264722657226672267722687226972270722717227272273722747227572276722777227872279722807228172282722837228472285722867228772288722897229072291722927229372294722957229672297722987229972300723017230272303723047230572306723077230872309723107231172312723137231472315723167231772318723197232072321723227232372324723257232672327723287232972330723317233272333723347233572336723377233872339723407234172342723437234472345723467234772348723497235072351723527235372354723557235672357723587235972360723617236272363723647236572366723677236872369723707237172372723737237472375723767237772378723797238072381723827238372384723857238672387723887238972390723917239272393723947239572396723977239872399724007240172402724037240472405724067240772408724097241072411724127241372414724157241672417724187241972420724217242272423724247242572426724277242872429724307243172432724337243472435724367243772438724397244072441724427244372444724457244672447724487244972450724517245272453724547245572456724577245872459724607246172462724637246472465724667246772468724697247072471724727247372474724757247672477724787247972480724817248272483724847248572486724877248872489724907249172492724937249472495724967249772498724997250072501725027250372504725057250672507725087250972510725117251272513725147251572516725177251872519725207252172522725237252472525725267252772528725297253072531725327253372534725357253672537725387253972540725417254272543725447254572546725477254872549725507255172552725537255472555725567255772558725597256072561725627256372564725657256672567725687256972570725717257272573725747257572576725777257872579725807258172582725837258472585725867258772588725897259072591725927259372594725957259672597725987259972600726017260272603726047260572606726077260872609726107261172612726137261472615726167261772618726197262072621726227262372624726257262672627726287262972630726317263272633726347263572636726377263872639726407264172642726437264472645726467264772648726497265072651726527265372654726557265672657726587265972660726617266272663726647266572666726677266872669726707267172672726737267472675726767267772678726797268072681726827268372684726857268672687726887268972690726917269272693726947269572696726977269872699727007270172702727037270472705727067270772708727097271072711727127271372714727157271672717727187271972720727217272272723727247272572726727277272872729727307273172732727337273472735727367273772738727397274072741727427274372744727457274672747727487274972750727517275272753727547275572756727577275872759727607276172762727637276472765727667276772768727697277072771727727277372774727757277672777727787277972780727817278272783727847278572786727877278872789727907279172792727937279472795727967279772798727997280072801728027280372804728057280672807728087280972810728117281272813728147281572816728177281872819728207282172822728237282472825728267282772828728297283072831728327283372834728357283672837728387283972840728417284272843728447284572846728477284872849728507285172852728537285472855728567285772858728597286072861728627286372864728657286672867728687286972870728717287272873728747287572876728777287872879728807288172882728837288472885728867288772888728897289072891728927289372894728957289672897728987289972900729017290272903729047290572906729077290872909729107291172912729137291472915729167291772918729197292072921729227292372924729257292672927729287292972930729317293272933729347293572936729377293872939729407294172942729437294472945729467294772948729497295072951729527295372954729557295672957729587295972960729617296272963729647296572966729677296872969729707297172972729737297472975729767297772978729797298072981729827298372984729857298672987729887298972990729917299272993729947299572996729977299872999730007300173002730037300473005730067300773008730097301073011730127301373014730157301673017730187301973020730217302273023730247302573026730277302873029730307303173032730337303473035730367303773038730397304073041730427304373044730457304673047730487304973050730517305273053730547305573056730577305873059730607306173062730637306473065730667306773068730697307073071730727307373074730757307673077730787307973080730817308273083730847308573086730877308873089730907309173092730937309473095730967309773098730997310073101731027310373104731057310673107731087310973110731117311273113731147311573116731177311873119731207312173122731237312473125731267312773128731297313073131731327313373134731357313673137731387313973140731417314273143731447314573146731477314873149731507315173152731537315473155731567315773158731597316073161731627316373164731657316673167731687316973170731717317273173731747317573176731777317873179731807318173182731837318473185731867318773188731897319073191731927319373194731957319673197731987319973200732017320273203732047320573206732077320873209732107321173212732137321473215732167321773218732197322073221732227322373224732257322673227732287322973230732317323273233732347323573236732377323873239732407324173242732437324473245732467324773248732497325073251732527325373254732557325673257732587325973260732617326273263732647326573266732677326873269732707327173272732737327473275732767327773278732797328073281732827328373284732857328673287732887328973290732917329273293732947329573296732977329873299733007330173302733037330473305733067330773308733097331073311733127331373314733157331673317733187331973320733217332273323733247332573326733277332873329733307333173332733337333473335733367333773338733397334073341733427334373344733457334673347733487334973350733517335273353733547335573356733577335873359733607336173362733637336473365733667336773368733697337073371733727337373374733757337673377733787337973380733817338273383733847338573386733877338873389733907339173392733937339473395733967339773398733997340073401734027340373404734057340673407734087340973410734117341273413734147341573416734177341873419734207342173422734237342473425734267342773428734297343073431734327343373434734357343673437734387343973440734417344273443734447344573446734477344873449734507345173452734537345473455734567345773458734597346073461734627346373464734657346673467734687346973470734717347273473734747347573476734777347873479734807348173482734837348473485734867348773488734897349073491734927349373494734957349673497734987349973500735017350273503735047350573506735077350873509735107351173512735137351473515735167351773518735197352073521735227352373524735257352673527735287352973530735317353273533735347353573536735377353873539735407354173542735437354473545735467354773548735497355073551735527355373554735557355673557735587355973560735617356273563735647356573566735677356873569735707357173572735737357473575735767357773578735797358073581735827358373584735857358673587735887358973590735917359273593735947359573596735977359873599736007360173602736037360473605736067360773608736097361073611736127361373614736157361673617736187361973620736217362273623736247362573626736277362873629736307363173632736337363473635736367363773638736397364073641736427364373644736457364673647736487364973650736517365273653736547365573656736577365873659736607366173662736637366473665736667366773668736697367073671736727367373674736757367673677736787367973680736817368273683736847368573686736877368873689736907369173692736937369473695736967369773698736997370073701737027370373704737057370673707737087370973710737117371273713737147371573716737177371873719737207372173722737237372473725737267372773728737297373073731737327373373734737357373673737737387373973740737417374273743737447374573746737477374873749737507375173752737537375473755737567375773758737597376073761737627376373764737657376673767737687376973770737717377273773737747377573776737777377873779737807378173782737837378473785737867378773788737897379073791737927379373794737957379673797737987379973800738017380273803738047380573806738077380873809738107381173812738137381473815738167381773818738197382073821738227382373824738257382673827738287382973830738317383273833738347383573836738377383873839738407384173842738437384473845738467384773848738497385073851738527385373854738557385673857738587385973860738617386273863738647386573866738677386873869738707387173872738737387473875738767387773878738797388073881738827388373884738857388673887738887388973890738917389273893738947389573896738977389873899739007390173902739037390473905739067390773908739097391073911739127391373914739157391673917739187391973920739217392273923739247392573926739277392873929739307393173932739337393473935739367393773938739397394073941739427394373944739457394673947739487394973950739517395273953739547395573956739577395873959739607396173962739637396473965739667396773968739697397073971739727397373974739757397673977739787397973980739817398273983739847398573986739877398873989739907399173992739937399473995739967399773998739997400074001740027400374004740057400674007740087400974010740117401274013740147401574016740177401874019740207402174022740237402474025740267402774028740297403074031740327403374034740357403674037740387403974040740417404274043740447404574046740477404874049740507405174052740537405474055740567405774058740597406074061740627406374064740657406674067740687406974070740717407274073740747407574076740777407874079740807408174082740837408474085740867408774088740897409074091740927409374094740957409674097740987409974100741017410274103741047410574106741077410874109741107411174112741137411474115741167411774118741197412074121741227412374124741257412674127741287412974130741317413274133741347413574136741377413874139741407414174142741437414474145741467414774148741497415074151741527415374154741557415674157741587415974160741617416274163741647416574166741677416874169741707417174172741737417474175741767417774178741797418074181741827418374184741857418674187741887418974190741917419274193741947419574196741977419874199742007420174202742037420474205742067420774208742097421074211742127421374214742157421674217742187421974220742217422274223742247422574226742277422874229742307423174232742337423474235742367423774238742397424074241742427424374244742457424674247742487424974250742517425274253742547425574256742577425874259742607426174262742637426474265742667426774268742697427074271742727427374274742757427674277742787427974280742817428274283742847428574286742877428874289742907429174292742937429474295742967429774298742997430074301743027430374304743057430674307743087430974310743117431274313743147431574316743177431874319743207432174322743237432474325743267432774328743297433074331743327433374334743357433674337743387433974340743417434274343743447434574346743477434874349743507435174352743537435474355743567435774358743597436074361743627436374364743657436674367743687436974370743717437274373743747437574376743777437874379743807438174382743837438474385743867438774388743897439074391743927439374394743957439674397743987439974400744017440274403744047440574406744077440874409744107441174412744137441474415744167441774418744197442074421744227442374424744257442674427744287442974430744317443274433744347443574436744377443874439744407444174442744437444474445744467444774448744497445074451744527445374454744557445674457744587445974460744617446274463744647446574466744677446874469744707447174472744737447474475744767447774478744797448074481744827448374484744857448674487744887448974490744917449274493744947449574496744977449874499745007450174502745037450474505745067450774508745097451074511745127451374514745157451674517745187451974520745217452274523745247452574526745277452874529745307453174532745337453474535745367453774538745397454074541745427454374544745457454674547745487454974550745517455274553745547455574556745577455874559745607456174562745637456474565745667456774568745697457074571745727457374574745757457674577745787457974580745817458274583745847458574586745877458874589745907459174592745937459474595745967459774598745997460074601746027460374604746057460674607746087460974610746117461274613746147461574616746177461874619746207462174622746237462474625746267462774628746297463074631746327463374634746357463674637746387463974640746417464274643746447464574646746477464874649746507465174652746537465474655746567465774658746597466074661746627466374664746657466674667746687466974670746717467274673746747467574676746777467874679746807468174682746837468474685746867468774688746897469074691746927469374694746957469674697746987469974700747017470274703747047470574706747077470874709747107471174712747137471474715747167471774718747197472074721747227472374724747257472674727747287472974730747317473274733747347473574736747377473874739747407474174742747437474474745747467474774748747497475074751747527475374754747557475674757747587475974760747617476274763747647476574766747677476874769747707477174772747737477474775747767477774778747797478074781747827478374784747857478674787747887478974790747917479274793747947479574796747977479874799748007480174802748037480474805748067480774808748097481074811748127481374814748157481674817748187481974820748217482274823748247482574826748277482874829748307483174832748337483474835748367483774838748397484074841748427484374844748457484674847748487484974850748517485274853748547485574856748577485874859748607486174862748637486474865748667486774868748697487074871748727487374874748757487674877748787487974880748817488274883748847488574886748877488874889748907489174892748937489474895748967489774898748997490074901749027490374904749057490674907749087490974910749117491274913749147491574916749177491874919749207492174922749237492474925749267492774928749297493074931749327493374934749357493674937749387493974940749417494274943749447494574946749477494874949749507495174952749537495474955749567495774958749597496074961749627496374964749657496674967749687496974970749717497274973749747497574976749777497874979749807498174982749837498474985749867498774988749897499074991749927499374994749957499674997749987499975000750017500275003750047500575006750077500875009750107501175012750137501475015750167501775018750197502075021750227502375024750257502675027750287502975030750317503275033750347503575036750377503875039750407504175042750437504475045750467504775048750497505075051750527505375054750557505675057750587505975060750617506275063750647506575066750677506875069750707507175072750737507475075750767507775078750797508075081750827508375084750857508675087750887508975090750917509275093750947509575096750977509875099751007510175102751037510475105751067510775108751097511075111751127511375114751157511675117751187511975120751217512275123751247512575126751277512875129751307513175132751337513475135751367513775138751397514075141751427514375144751457514675147751487514975150751517515275153751547515575156751577515875159751607516175162751637516475165751667516775168751697517075171751727517375174751757517675177751787517975180751817518275183751847518575186751877518875189751907519175192751937519475195751967519775198751997520075201752027520375204752057520675207752087520975210752117521275213752147521575216752177521875219752207522175222752237522475225752267522775228752297523075231752327523375234752357523675237752387523975240752417524275243752447524575246752477524875249752507525175252752537525475255752567525775258752597526075261752627526375264752657526675267752687526975270752717527275273752747527575276752777527875279752807528175282752837528475285752867528775288752897529075291752927529375294752957529675297752987529975300753017530275303753047530575306753077530875309753107531175312753137531475315753167531775318753197532075321753227532375324753257532675327753287532975330753317533275333753347533575336753377533875339753407534175342753437534475345753467534775348753497535075351753527535375354753557535675357753587535975360753617536275363753647536575366753677536875369753707537175372753737537475375753767537775378753797538075381753827538375384753857538675387753887538975390753917539275393753947539575396753977539875399754007540175402754037540475405754067540775408754097541075411754127541375414754157541675417754187541975420754217542275423754247542575426754277542875429754307543175432754337543475435754367543775438754397544075441754427544375444754457544675447754487544975450754517545275453754547545575456754577545875459754607546175462754637546475465754667546775468754697547075471754727547375474754757547675477754787547975480754817548275483754847548575486754877548875489754907549175492754937549475495754967549775498754997550075501755027550375504755057550675507755087550975510755117551275513755147551575516755177551875519755207552175522755237552475525755267552775528755297553075531755327553375534755357553675537755387553975540755417554275543755447554575546755477554875549755507555175552755537555475555755567555775558755597556075561755627556375564755657556675567755687556975570755717557275573755747557575576755777557875579755807558175582755837558475585755867558775588755897559075591755927559375594755957559675597755987559975600756017560275603756047560575606756077560875609756107561175612756137561475615756167561775618756197562075621756227562375624756257562675627756287562975630756317563275633756347563575636756377563875639756407564175642756437564475645756467564775648756497565075651756527565375654756557565675657756587565975660756617566275663756647566575666756677566875669756707567175672756737567475675756767567775678756797568075681756827568375684756857568675687756887568975690756917569275693756947569575696756977569875699757007570175702757037570475705757067570775708757097571075711757127571375714757157571675717757187571975720757217572275723757247572575726757277572875729757307573175732757337573475735757367573775738757397574075741757427574375744757457574675747757487574975750757517575275753757547575575756757577575875759757607576175762757637576475765757667576775768757697577075771757727577375774757757577675777757787577975780757817578275783757847578575786757877578875789757907579175792757937579475795757967579775798757997580075801758027580375804758057580675807758087580975810758117581275813758147581575816758177581875819758207582175822758237582475825758267582775828758297583075831758327583375834758357583675837758387583975840758417584275843758447584575846758477584875849758507585175852758537585475855758567585775858758597586075861758627586375864758657586675867758687586975870758717587275873758747587575876758777587875879758807588175882758837588475885758867588775888758897589075891758927589375894758957589675897758987589975900759017590275903759047590575906759077590875909759107591175912759137591475915759167591775918759197592075921759227592375924759257592675927759287592975930759317593275933759347593575936759377593875939759407594175942759437594475945759467594775948759497595075951759527595375954759557595675957759587595975960759617596275963759647596575966759677596875969759707597175972759737597475975759767597775978759797598075981759827598375984759857598675987759887598975990759917599275993759947599575996759977599875999760007600176002760037600476005760067600776008760097601076011760127601376014760157601676017760187601976020760217602276023760247602576026760277602876029760307603176032760337603476035760367603776038760397604076041760427604376044760457604676047760487604976050760517605276053760547605576056760577605876059760607606176062760637606476065760667606776068760697607076071760727607376074760757607676077760787607976080760817608276083760847608576086760877608876089760907609176092760937609476095760967609776098760997610076101761027610376104761057610676107761087610976110761117611276113761147611576116761177611876119761207612176122761237612476125761267612776128761297613076131761327613376134761357613676137761387613976140761417614276143761447614576146761477614876149761507615176152761537615476155761567615776158761597616076161761627616376164761657616676167761687616976170761717617276173761747617576176761777617876179761807618176182761837618476185761867618776188761897619076191761927619376194761957619676197761987619976200762017620276203762047620576206762077620876209762107621176212762137621476215762167621776218762197622076221762227622376224762257622676227762287622976230762317623276233762347623576236762377623876239762407624176242762437624476245762467624776248762497625076251762527625376254762557625676257762587625976260762617626276263762647626576266762677626876269762707627176272762737627476275762767627776278762797628076281762827628376284762857628676287762887628976290762917629276293762947629576296762977629876299763007630176302763037630476305763067630776308763097631076311763127631376314763157631676317763187631976320763217632276323763247632576326763277632876329763307633176332763337633476335763367633776338763397634076341763427634376344763457634676347763487634976350763517635276353763547635576356763577635876359763607636176362763637636476365763667636776368763697637076371763727637376374763757637676377763787637976380763817638276383763847638576386763877638876389763907639176392763937639476395763967639776398763997640076401764027640376404764057640676407764087640976410764117641276413764147641576416764177641876419764207642176422764237642476425764267642776428764297643076431764327643376434764357643676437764387643976440764417644276443764447644576446764477644876449764507645176452764537645476455764567645776458764597646076461764627646376464764657646676467764687646976470764717647276473764747647576476764777647876479764807648176482764837648476485764867648776488764897649076491764927649376494764957649676497764987649976500765017650276503765047650576506765077650876509765107651176512765137651476515765167651776518765197652076521765227652376524765257652676527765287652976530765317653276533765347653576536765377653876539765407654176542765437654476545765467654776548765497655076551765527655376554765557655676557765587655976560765617656276563765647656576566765677656876569765707657176572765737657476575765767657776578765797658076581765827658376584765857658676587765887658976590765917659276593765947659576596765977659876599766007660176602766037660476605766067660776608766097661076611766127661376614766157661676617766187661976620766217662276623766247662576626766277662876629766307663176632766337663476635766367663776638766397664076641766427664376644766457664676647766487664976650766517665276653766547665576656766577665876659766607666176662766637666476665766667666776668766697667076671766727667376674766757667676677766787667976680766817668276683766847668576686766877668876689766907669176692766937669476695766967669776698766997670076701767027670376704767057670676707767087670976710767117671276713767147671576716767177671876719767207672176722767237672476725767267672776728767297673076731767327673376734767357673676737767387673976740767417674276743767447674576746767477674876749767507675176752767537675476755767567675776758767597676076761767627676376764767657676676767767687676976770767717677276773767747677576776767777677876779767807678176782767837678476785767867678776788767897679076791767927679376794767957679676797767987679976800768017680276803768047680576806768077680876809768107681176812768137681476815768167681776818768197682076821768227682376824768257682676827768287682976830768317683276833768347683576836768377683876839768407684176842768437684476845768467684776848768497685076851768527685376854768557685676857768587685976860768617686276863768647686576866768677686876869768707687176872768737687476875768767687776878768797688076881768827688376884768857688676887768887688976890768917689276893768947689576896768977689876899769007690176902769037690476905769067690776908769097691076911769127691376914769157691676917769187691976920769217692276923769247692576926769277692876929769307693176932769337693476935769367693776938769397694076941769427694376944769457694676947769487694976950769517695276953769547695576956769577695876959769607696176962769637696476965769667696776968769697697076971769727697376974769757697676977769787697976980769817698276983769847698576986769877698876989769907699176992769937699476995769967699776998769997700077001770027700377004770057700677007770087700977010770117701277013770147701577016770177701877019770207702177022770237702477025770267702777028770297703077031770327703377034770357703677037770387703977040770417704277043770447704577046770477704877049770507705177052770537705477055770567705777058770597706077061770627706377064770657706677067770687706977070770717707277073770747707577076770777707877079770807708177082770837708477085770867708777088770897709077091770927709377094770957709677097770987709977100771017710277103771047710577106771077710877109771107711177112771137711477115771167711777118771197712077121771227712377124771257712677127771287712977130771317713277133771347713577136771377713877139771407714177142771437714477145771467714777148771497715077151771527715377154771557715677157771587715977160771617716277163771647716577166771677716877169771707717177172771737717477175771767717777178771797718077181771827718377184771857718677187771887718977190771917719277193771947719577196771977719877199772007720177202772037720477205772067720777208772097721077211772127721377214772157721677217772187721977220772217722277223772247722577226772277722877229772307723177232772337723477235772367723777238772397724077241772427724377244772457724677247772487724977250772517725277253772547725577256772577725877259772607726177262772637726477265772667726777268772697727077271772727727377274772757727677277772787727977280772817728277283772847728577286772877728877289772907729177292772937729477295772967729777298772997730077301773027730377304773057730677307773087730977310773117731277313773147731577316773177731877319773207732177322773237732477325773267732777328773297733077331773327733377334773357733677337773387733977340773417734277343773447734577346773477734877349773507735177352773537735477355773567735777358773597736077361773627736377364773657736677367773687736977370773717737277373773747737577376773777737877379773807738177382773837738477385773867738777388773897739077391773927739377394773957739677397773987739977400774017740277403774047740577406774077740877409774107741177412774137741477415774167741777418774197742077421774227742377424774257742677427774287742977430774317743277433774347743577436774377743877439774407744177442774437744477445774467744777448774497745077451774527745377454774557745677457774587745977460774617746277463774647746577466774677746877469774707747177472774737747477475774767747777478774797748077481774827748377484774857748677487774887748977490774917749277493774947749577496774977749877499775007750177502775037750477505775067750777508775097751077511775127751377514775157751677517775187751977520775217752277523775247752577526775277752877529775307753177532775337753477535775367753777538775397754077541775427754377544775457754677547775487754977550775517755277553775547755577556775577755877559775607756177562775637756477565775667756777568775697757077571775727757377574775757757677577775787757977580775817758277583775847758577586775877758877589775907759177592775937759477595775967759777598775997760077601776027760377604776057760677607776087760977610776117761277613776147761577616776177761877619776207762177622776237762477625776267762777628776297763077631776327763377634776357763677637776387763977640776417764277643776447764577646776477764877649776507765177652776537765477655776567765777658776597766077661776627766377664776657766677667776687766977670776717767277673776747767577676776777767877679776807768177682776837768477685776867768777688776897769077691776927769377694776957769677697776987769977700777017770277703777047770577706777077770877709777107771177712777137771477715777167771777718777197772077721777227772377724777257772677727777287772977730777317773277733777347773577736777377773877739777407774177742777437774477745777467774777748777497775077751777527775377754777557775677757777587775977760777617776277763777647776577766777677776877769777707777177772777737777477775777767777777778777797778077781777827778377784777857778677787777887778977790777917779277793777947779577796777977779877799778007780177802778037780477805778067780777808778097781077811778127781377814778157781677817778187781977820778217782277823778247782577826778277782877829778307783177832778337783477835778367783777838778397784077841778427784377844778457784677847778487784977850778517785277853778547785577856778577785877859778607786177862778637786477865778667786777868778697787077871778727787377874778757787677877778787787977880778817788277883778847788577886778877788877889778907789177892778937789477895778967789777898778997790077901779027790377904779057790677907779087790977910779117791277913779147791577916779177791877919779207792177922779237792477925779267792777928779297793077931779327793377934779357793677937779387793977940779417794277943779447794577946779477794877949779507795177952779537795477955779567795777958779597796077961779627796377964779657796677967779687796977970779717797277973779747797577976779777797877979779807798177982779837798477985779867798777988779897799077991779927799377994779957799677997779987799978000780017800278003780047800578006780077800878009780107801178012780137801478015780167801778018780197802078021780227802378024780257802678027780287802978030780317803278033780347803578036780377803878039780407804178042780437804478045780467804778048780497805078051780527805378054780557805678057780587805978060780617806278063780647806578066780677806878069780707807178072780737807478075780767807778078780797808078081780827808378084780857808678087780887808978090780917809278093780947809578096780977809878099781007810178102781037810478105781067810778108781097811078111781127811378114781157811678117781187811978120781217812278123781247812578126781277812878129781307813178132781337813478135781367813778138781397814078141781427814378144781457814678147781487814978150781517815278153781547815578156781577815878159781607816178162781637816478165781667816778168781697817078171781727817378174781757817678177781787817978180781817818278183781847818578186781877818878189781907819178192781937819478195781967819778198781997820078201782027820378204782057820678207782087820978210782117821278213782147821578216782177821878219782207822178222782237822478225782267822778228782297823078231782327823378234782357823678237782387823978240782417824278243782447824578246782477824878249782507825178252782537825478255782567825778258782597826078261782627826378264782657826678267782687826978270782717827278273782747827578276782777827878279782807828178282782837828478285782867828778288782897829078291782927829378294782957829678297782987829978300783017830278303783047830578306783077830878309783107831178312783137831478315783167831778318783197832078321783227832378324783257832678327783287832978330783317833278333783347833578336783377833878339783407834178342783437834478345783467834778348783497835078351783527835378354783557835678357783587835978360783617836278363783647836578366783677836878369783707837178372783737837478375783767837778378783797838078381783827838378384783857838678387783887838978390783917839278393783947839578396783977839878399784007840178402784037840478405784067840778408784097841078411784127841378414784157841678417784187841978420784217842278423784247842578426784277842878429784307843178432784337843478435784367843778438784397844078441784427844378444784457844678447784487844978450784517845278453784547845578456784577845878459784607846178462784637846478465784667846778468784697847078471784727847378474784757847678477784787847978480784817848278483784847848578486784877848878489784907849178492784937849478495784967849778498784997850078501785027850378504785057850678507785087850978510785117851278513785147851578516785177851878519785207852178522785237852478525785267852778528785297853078531785327853378534785357853678537785387853978540785417854278543785447854578546785477854878549785507855178552785537855478555785567855778558785597856078561785627856378564785657856678567785687856978570785717857278573785747857578576785777857878579785807858178582785837858478585785867858778588785897859078591785927859378594785957859678597785987859978600786017860278603786047860578606786077860878609786107861178612786137861478615786167861778618786197862078621786227862378624786257862678627786287862978630786317863278633786347863578636786377863878639786407864178642786437864478645786467864778648786497865078651786527865378654786557865678657786587865978660786617866278663786647866578666786677866878669786707867178672786737867478675786767867778678786797868078681786827868378684786857868678687786887868978690786917869278693786947869578696786977869878699787007870178702787037870478705787067870778708787097871078711787127871378714787157871678717787187871978720787217872278723787247872578726787277872878729787307873178732787337873478735787367873778738787397874078741787427874378744787457874678747787487874978750787517875278753787547875578756787577875878759787607876178762787637876478765787667876778768787697877078771787727877378774787757877678777787787877978780787817878278783787847878578786787877878878789787907879178792787937879478795787967879778798787997880078801788027880378804788057880678807788087880978810788117881278813788147881578816788177881878819788207882178822788237882478825788267882778828788297883078831788327883378834788357883678837788387883978840788417884278843788447884578846788477884878849788507885178852788537885478855788567885778858788597886078861788627886378864788657886678867788687886978870788717887278873788747887578876788777887878879788807888178882788837888478885788867888778888788897889078891788927889378894788957889678897788987889978900789017890278903789047890578906789077890878909789107891178912789137891478915789167891778918789197892078921789227892378924789257892678927789287892978930789317893278933789347893578936789377893878939789407894178942789437894478945789467894778948789497895078951789527895378954789557895678957789587895978960789617896278963789647896578966789677896878969789707897178972789737897478975789767897778978789797898078981789827898378984789857898678987789887898978990789917899278993789947899578996789977899878999790007900179002790037900479005790067900779008790097901079011790127901379014790157901679017790187901979020790217902279023790247902579026790277902879029790307903179032790337903479035790367903779038790397904079041790427904379044790457904679047790487904979050790517905279053790547905579056790577905879059790607906179062790637906479065790667906779068790697907079071790727907379074790757907679077790787907979080790817908279083790847908579086790877908879089790907909179092790937909479095790967909779098790997910079101791027910379104791057910679107791087910979110791117911279113791147911579116791177911879119791207912179122791237912479125791267912779128791297913079131791327913379134791357913679137791387913979140791417914279143791447914579146791477914879149791507915179152791537915479155791567915779158791597916079161791627916379164791657916679167791687916979170791717917279173791747917579176791777917879179791807918179182791837918479185791867918779188791897919079191791927919379194791957919679197791987919979200792017920279203792047920579206792077920879209792107921179212792137921479215792167921779218792197922079221792227922379224792257922679227792287922979230792317923279233792347923579236792377923879239792407924179242792437924479245792467924779248792497925079251792527925379254792557925679257792587925979260792617926279263792647926579266792677926879269792707927179272792737927479275792767927779278792797928079281792827928379284792857928679287792887928979290792917929279293792947929579296792977929879299793007930179302793037930479305793067930779308793097931079311793127931379314793157931679317793187931979320793217932279323793247932579326793277932879329793307933179332793337933479335793367933779338793397934079341793427934379344793457934679347793487934979350793517935279353793547935579356793577935879359793607936179362793637936479365793667936779368793697937079371793727937379374793757937679377793787937979380793817938279383793847938579386793877938879389793907939179392793937939479395793967939779398793997940079401794027940379404794057940679407794087940979410794117941279413794147941579416794177941879419794207942179422794237942479425794267942779428794297943079431794327943379434794357943679437794387943979440794417944279443794447944579446794477944879449794507945179452794537945479455794567945779458794597946079461794627946379464794657946679467794687946979470794717947279473794747947579476794777947879479794807948179482794837948479485794867948779488794897949079491794927949379494794957949679497794987949979500795017950279503795047950579506795077950879509795107951179512795137951479515795167951779518795197952079521795227952379524795257952679527795287952979530795317953279533795347953579536795377953879539795407954179542795437954479545795467954779548795497955079551795527955379554795557955679557795587955979560795617956279563795647956579566795677956879569795707957179572795737957479575795767957779578795797958079581795827958379584795857958679587795887958979590795917959279593795947959579596795977959879599796007960179602796037960479605796067960779608796097961079611796127961379614796157961679617796187961979620796217962279623796247962579626796277962879629796307963179632796337963479635796367963779638796397964079641796427964379644796457964679647796487964979650796517965279653796547965579656796577965879659796607966179662796637966479665796667966779668796697967079671796727967379674796757967679677796787967979680796817968279683796847968579686796877968879689796907969179692796937969479695796967969779698796997970079701797027970379704797057970679707797087970979710797117971279713797147971579716797177971879719797207972179722797237972479725797267972779728797297973079731797327973379734797357973679737797387973979740797417974279743797447974579746797477974879749797507975179752797537975479755797567975779758797597976079761797627976379764797657976679767797687976979770797717977279773797747977579776797777977879779797807978179782797837978479785797867978779788797897979079791797927979379794797957979679797797987979979800798017980279803798047980579806798077980879809798107981179812798137981479815798167981779818798197982079821798227982379824798257982679827798287982979830798317983279833798347983579836798377983879839798407984179842798437984479845798467984779848798497985079851798527985379854798557985679857798587985979860798617986279863798647986579866798677986879869798707987179872798737987479875798767987779878798797988079881798827988379884798857988679887798887988979890798917989279893798947989579896798977989879899799007990179902799037990479905799067990779908799097991079911799127991379914799157991679917799187991979920799217992279923799247992579926799277992879929799307993179932799337993479935799367993779938799397994079941799427994379944799457994679947799487994979950799517995279953799547995579956799577995879959799607996179962799637996479965799667996779968799697997079971799727997379974799757997679977799787997979980799817998279983799847998579986799877998879989799907999179992799937999479995799967999779998799998000080001800028000380004800058000680007800088000980010800118001280013800148001580016800178001880019800208002180022800238002480025800268002780028800298003080031800328003380034800358003680037800388003980040800418004280043800448004580046800478004880049800508005180052800538005480055800568005780058800598006080061800628006380064800658006680067800688006980070800718007280073800748007580076800778007880079800808008180082800838008480085800868008780088800898009080091800928009380094800958009680097800988009980100801018010280103801048010580106801078010880109801108011180112801138011480115801168011780118801198012080121801228012380124801258012680127801288012980130801318013280133801348013580136801378013880139801408014180142801438014480145801468014780148801498015080151801528015380154801558015680157801588015980160801618016280163801648016580166801678016880169801708017180172801738017480175801768017780178801798018080181801828018380184801858018680187801888018980190801918019280193801948019580196801978019880199802008020180202802038020480205802068020780208802098021080211802128021380214802158021680217802188021980220802218022280223802248022580226802278022880229802308023180232802338023480235802368023780238802398024080241802428024380244802458024680247802488024980250802518025280253802548025580256802578025880259802608026180262802638026480265802668026780268802698027080271802728027380274802758027680277802788027980280802818028280283802848028580286802878028880289802908029180292802938029480295802968029780298802998030080301803028030380304803058030680307803088030980310803118031280313803148031580316803178031880319803208032180322803238032480325803268032780328803298033080331803328033380334803358033680337803388033980340803418034280343803448034580346803478034880349803508035180352803538035480355803568035780358803598036080361803628036380364803658036680367803688036980370803718037280373803748037580376803778037880379803808038180382803838038480385803868038780388803898039080391803928039380394803958039680397803988039980400804018040280403804048040580406804078040880409804108041180412804138041480415804168041780418804198042080421804228042380424804258042680427804288042980430804318043280433804348043580436804378043880439804408044180442804438044480445804468044780448804498045080451804528045380454804558045680457804588045980460804618046280463804648046580466804678046880469804708047180472804738047480475804768047780478804798048080481804828048380484804858048680487804888048980490804918049280493804948049580496804978049880499805008050180502805038050480505805068050780508805098051080511805128051380514805158051680517805188051980520805218052280523805248052580526805278052880529805308053180532805338053480535805368053780538805398054080541805428054380544805458054680547805488054980550805518055280553805548055580556805578055880559805608056180562805638056480565805668056780568805698057080571805728057380574805758057680577805788057980580805818058280583805848058580586805878058880589805908059180592805938059480595805968059780598805998060080601806028060380604806058060680607806088060980610806118061280613806148061580616806178061880619806208062180622806238062480625806268062780628806298063080631806328063380634806358063680637806388063980640806418064280643806448064580646806478064880649806508065180652806538065480655806568065780658806598066080661806628066380664806658066680667806688066980670806718067280673806748067580676806778067880679806808068180682806838068480685806868068780688806898069080691806928069380694806958069680697806988069980700807018070280703807048070580706807078070880709807108071180712807138071480715807168071780718807198072080721807228072380724807258072680727807288072980730807318073280733807348073580736807378073880739807408074180742807438074480745807468074780748807498075080751807528075380754807558075680757807588075980760807618076280763807648076580766807678076880769807708077180772807738077480775807768077780778807798078080781807828078380784807858078680787807888078980790807918079280793807948079580796807978079880799808008080180802808038080480805808068080780808808098081080811808128081380814808158081680817808188081980820808218082280823808248082580826808278082880829808308083180832808338083480835808368083780838808398084080841808428084380844808458084680847808488084980850808518085280853808548085580856808578085880859808608086180862808638086480865808668086780868808698087080871808728087380874808758087680877808788087980880808818088280883808848088580886808878088880889808908089180892808938089480895808968089780898808998090080901809028090380904809058090680907809088090980910809118091280913809148091580916809178091880919809208092180922809238092480925809268092780928809298093080931809328093380934809358093680937809388093980940809418094280943809448094580946809478094880949809508095180952809538095480955809568095780958809598096080961809628096380964809658096680967809688096980970809718097280973809748097580976809778097880979809808098180982809838098480985809868098780988809898099080991809928099380994809958099680997809988099981000810018100281003810048100581006810078100881009810108101181012810138101481015810168101781018810198102081021810228102381024810258102681027810288102981030810318103281033810348103581036810378103881039810408104181042810438104481045810468104781048810498105081051810528105381054810558105681057810588105981060810618106281063810648106581066810678106881069810708107181072810738107481075810768107781078810798108081081810828108381084810858108681087810888108981090810918109281093810948109581096810978109881099811008110181102811038110481105811068110781108811098111081111811128111381114811158111681117811188111981120811218112281123811248112581126811278112881129811308113181132811338113481135811368113781138811398114081141811428114381144811458114681147811488114981150811518115281153811548115581156811578115881159811608116181162811638116481165811668116781168811698117081171811728117381174811758117681177811788117981180811818118281183811848118581186811878118881189811908119181192811938119481195811968119781198811998120081201812028120381204812058120681207812088120981210812118121281213812148121581216812178121881219812208122181222812238122481225812268122781228812298123081231812328123381234812358123681237812388123981240812418124281243812448124581246812478124881249812508125181252812538125481255812568125781258812598126081261812628126381264812658126681267812688126981270812718127281273812748127581276812778127881279812808128181282812838128481285812868128781288812898129081291812928129381294812958129681297812988129981300813018130281303813048130581306813078130881309813108131181312813138131481315813168131781318813198132081321813228132381324813258132681327813288132981330813318133281333813348133581336813378133881339813408134181342813438134481345813468134781348813498135081351813528135381354813558135681357813588135981360813618136281363813648136581366813678136881369813708137181372813738137481375813768137781378813798138081381813828138381384813858138681387813888138981390813918139281393813948139581396813978139881399814008140181402814038140481405814068140781408814098141081411814128141381414814158141681417814188141981420814218142281423814248142581426814278142881429814308143181432814338143481435814368143781438814398144081441814428144381444814458144681447814488144981450814518145281453814548145581456814578145881459814608146181462814638146481465814668146781468814698147081471814728147381474814758147681477814788147981480814818148281483814848148581486814878148881489814908149181492814938149481495814968149781498814998150081501815028150381504815058150681507815088150981510815118151281513815148151581516815178151881519815208152181522815238152481525815268152781528815298153081531815328153381534815358153681537815388153981540815418154281543815448154581546815478154881549815508155181552815538155481555815568155781558815598156081561815628156381564815658156681567815688156981570815718157281573815748157581576815778157881579815808158181582815838158481585815868158781588815898159081591815928159381594815958159681597815988159981600816018160281603816048160581606816078160881609816108161181612816138161481615816168161781618816198162081621816228162381624816258162681627816288162981630816318163281633816348163581636816378163881639816408164181642816438164481645816468164781648816498165081651816528165381654816558165681657816588165981660816618166281663816648166581666816678166881669816708167181672816738167481675816768167781678816798168081681816828168381684816858168681687816888168981690816918169281693816948169581696816978169881699817008170181702817038170481705817068170781708817098171081711817128171381714817158171681717817188171981720817218172281723817248172581726817278172881729817308173181732817338173481735817368173781738817398174081741817428174381744817458174681747817488174981750817518175281753817548175581756817578175881759817608176181762817638176481765817668176781768817698177081771817728177381774817758177681777817788177981780817818178281783817848178581786817878178881789817908179181792817938179481795817968179781798817998180081801818028180381804818058180681807818088180981810818118181281813818148181581816818178181881819818208182181822818238182481825818268182781828818298183081831818328183381834818358183681837818388183981840818418184281843818448184581846818478184881849818508185181852818538185481855818568185781858818598186081861818628186381864818658186681867818688186981870818718187281873818748187581876818778187881879818808188181882818838188481885818868188781888818898189081891818928189381894818958189681897818988189981900819018190281903819048190581906819078190881909819108191181912819138191481915819168191781918819198192081921819228192381924819258192681927819288192981930819318193281933819348193581936819378193881939819408194181942819438194481945819468194781948819498195081951819528195381954819558195681957819588195981960819618196281963819648196581966819678196881969819708197181972819738197481975819768197781978819798198081981819828198381984819858198681987819888198981990819918199281993819948199581996819978199881999820008200182002820038200482005820068200782008820098201082011820128201382014820158201682017820188201982020820218202282023820248202582026820278202882029820308203182032820338203482035820368203782038820398204082041820428204382044820458204682047820488204982050820518205282053820548205582056820578205882059820608206182062820638206482065820668206782068820698207082071820728207382074820758207682077820788207982080820818208282083820848208582086820878208882089820908209182092820938209482095820968209782098820998210082101821028210382104821058210682107821088210982110821118211282113821148211582116821178211882119821208212182122821238212482125821268212782128821298213082131821328213382134821358213682137821388213982140821418214282143821448214582146821478214882149821508215182152821538215482155821568215782158821598216082161821628216382164821658216682167821688216982170821718217282173821748217582176821778217882179821808218182182821838218482185821868218782188821898219082191821928219382194821958219682197821988219982200822018220282203822048220582206822078220882209822108221182212822138221482215822168221782218822198222082221822228222382224822258222682227822288222982230822318223282233822348223582236822378223882239822408224182242822438224482245822468224782248822498225082251822528225382254822558225682257822588225982260822618226282263822648226582266822678226882269822708227182272822738227482275822768227782278822798228082281822828228382284822858228682287822888228982290822918229282293822948229582296822978229882299823008230182302823038230482305823068230782308823098231082311823128231382314823158231682317823188231982320823218232282323823248232582326823278232882329823308233182332823338233482335823368233782338823398234082341823428234382344823458234682347823488234982350823518235282353823548235582356823578235882359823608236182362823638236482365823668236782368823698237082371823728237382374823758237682377823788237982380823818238282383823848238582386823878238882389823908239182392823938239482395823968239782398823998240082401824028240382404824058240682407824088240982410824118241282413824148241582416824178241882419824208242182422824238242482425824268242782428824298243082431824328243382434824358243682437824388243982440824418244282443824448244582446824478244882449824508245182452824538245482455824568245782458824598246082461824628246382464824658246682467824688246982470824718247282473824748247582476824778247882479824808248182482824838248482485824868248782488824898249082491824928249382494824958249682497824988249982500825018250282503825048250582506825078250882509825108251182512825138251482515825168251782518825198252082521825228252382524825258252682527825288252982530825318253282533825348253582536825378253882539825408254182542825438254482545825468254782548825498255082551825528255382554825558255682557825588255982560825618256282563825648256582566825678256882569825708257182572825738257482575825768257782578825798258082581825828258382584825858258682587825888258982590825918259282593825948259582596825978259882599826008260182602826038260482605826068260782608826098261082611826128261382614826158261682617826188261982620826218262282623826248262582626826278262882629826308263182632826338263482635826368263782638826398264082641826428264382644826458264682647826488264982650826518265282653826548265582656826578265882659826608266182662826638266482665826668266782668826698267082671826728267382674826758267682677826788267982680826818268282683826848268582686826878268882689826908269182692826938269482695826968269782698826998270082701827028270382704827058270682707827088270982710827118271282713827148271582716827178271882719827208272182722827238272482725827268272782728827298273082731827328273382734827358273682737827388273982740827418274282743827448274582746827478274882749827508275182752827538275482755827568275782758827598276082761827628276382764827658276682767827688276982770827718277282773827748277582776827778277882779827808278182782827838278482785827868278782788827898279082791827928279382794827958279682797827988279982800828018280282803828048280582806828078280882809828108281182812828138281482815828168281782818828198282082821828228282382824828258282682827828288282982830828318283282833828348283582836828378283882839828408284182842828438284482845828468284782848828498285082851828528285382854828558285682857828588285982860828618286282863828648286582866828678286882869828708287182872828738287482875828768287782878828798288082881828828288382884828858288682887828888288982890828918289282893828948289582896828978289882899829008290182902829038290482905829068290782908829098291082911829128291382914829158291682917829188291982920829218292282923829248292582926829278292882929829308293182932829338293482935829368293782938829398294082941829428294382944829458294682947829488294982950829518295282953829548295582956829578295882959829608296182962829638296482965829668296782968829698297082971829728297382974829758297682977829788297982980829818298282983829848298582986829878298882989829908299182992829938299482995829968299782998829998300083001830028300383004830058300683007830088300983010830118301283013830148301583016830178301883019830208302183022830238302483025830268302783028830298303083031830328303383034830358303683037830388303983040830418304283043830448304583046830478304883049830508305183052830538305483055830568305783058830598306083061830628306383064830658306683067830688306983070830718307283073830748307583076830778307883079830808308183082830838308483085830868308783088830898309083091830928309383094830958309683097830988309983100831018310283103831048310583106831078310883109831108311183112831138311483115831168311783118831198312083121831228312383124831258312683127831288312983130831318313283133831348313583136831378313883139831408314183142831438314483145831468314783148831498315083151831528315383154831558315683157831588315983160831618316283163831648316583166831678316883169831708317183172831738317483175831768317783178831798318083181831828318383184831858318683187831888318983190831918319283193831948319583196831978319883199832008320183202832038320483205832068320783208832098321083211832128321383214832158321683217832188321983220832218322283223832248322583226832278322883229832308323183232832338323483235832368323783238832398324083241832428324383244832458324683247832488324983250832518325283253832548325583256832578325883259832608326183262832638326483265832668326783268832698327083271832728327383274832758327683277832788327983280832818328283283832848328583286832878328883289832908329183292832938329483295832968329783298832998330083301833028330383304833058330683307833088330983310833118331283313833148331583316833178331883319833208332183322833238332483325833268332783328833298333083331833328333383334833358333683337833388333983340833418334283343833448334583346833478334883349833508335183352833538335483355833568335783358833598336083361833628336383364833658336683367833688336983370833718337283373833748337583376833778337883379833808338183382833838338483385833868338783388833898339083391833928339383394833958339683397833988339983400834018340283403834048340583406834078340883409834108341183412834138341483415834168341783418834198342083421834228342383424834258342683427834288342983430834318343283433834348343583436834378343883439834408344183442834438344483445834468344783448834498345083451834528345383454834558345683457834588345983460834618346283463834648346583466834678346883469834708347183472834738347483475834768347783478834798348083481834828348383484834858348683487834888348983490834918349283493834948349583496834978349883499835008350183502835038350483505835068350783508835098351083511835128351383514835158351683517835188351983520835218352283523835248352583526835278352883529835308353183532835338353483535835368353783538835398354083541835428354383544835458354683547835488354983550835518355283553835548355583556835578355883559835608356183562835638356483565835668356783568835698357083571835728357383574835758357683577835788357983580835818358283583835848358583586835878358883589835908359183592835938359483595835968359783598835998360083601836028360383604836058360683607836088360983610836118361283613836148361583616836178361883619836208362183622836238362483625836268362783628836298363083631836328363383634836358363683637836388363983640836418364283643836448364583646836478364883649836508365183652836538365483655836568365783658836598366083661836628366383664836658366683667836688366983670836718367283673836748367583676836778367883679836808368183682836838368483685836868368783688836898369083691836928369383694836958369683697836988369983700837018370283703837048370583706837078370883709837108371183712837138371483715837168371783718837198372083721837228372383724837258372683727837288372983730837318373283733837348373583736837378373883739837408374183742837438374483745837468374783748837498375083751837528375383754837558375683757837588375983760837618376283763837648376583766837678376883769837708377183772837738377483775837768377783778837798378083781837828378383784837858378683787837888378983790837918379283793837948379583796837978379883799838008380183802838038380483805838068380783808838098381083811838128381383814838158381683817838188381983820838218382283823838248382583826838278382883829838308383183832838338383483835838368383783838838398384083841838428384383844838458384683847838488384983850838518385283853838548385583856838578385883859838608386183862838638386483865838668386783868838698387083871838728387383874838758387683877838788387983880838818388283883838848388583886838878388883889838908389183892838938389483895838968389783898838998390083901839028390383904839058390683907839088390983910839118391283913839148391583916839178391883919839208392183922839238392483925839268392783928839298393083931839328393383934839358393683937839388393983940839418394283943839448394583946839478394883949839508395183952839538395483955839568395783958839598396083961839628396383964839658396683967839688396983970839718397283973839748397583976839778397883979839808398183982839838398483985839868398783988839898399083991839928399383994839958399683997839988399984000840018400284003840048400584006840078400884009840108401184012840138401484015840168401784018840198402084021840228402384024840258402684027840288402984030840318403284033840348403584036840378403884039840408404184042840438404484045840468404784048840498405084051840528405384054840558405684057840588405984060840618406284063840648406584066840678406884069840708407184072840738407484075840768407784078840798408084081840828408384084840858408684087840888408984090840918409284093840948409584096840978409884099841008410184102841038410484105841068410784108841098411084111841128411384114841158411684117841188411984120841218412284123841248412584126841278412884129841308413184132841338413484135841368413784138841398414084141841428414384144841458414684147841488414984150841518415284153841548415584156841578415884159841608416184162841638416484165841668416784168841698417084171841728417384174841758417684177841788417984180841818418284183841848418584186841878418884189841908419184192841938419484195841968419784198841998420084201842028420384204842058420684207842088420984210842118421284213842148421584216842178421884219842208422184222842238422484225842268422784228842298423084231842328423384234842358423684237842388423984240842418424284243842448424584246842478424884249842508425184252842538425484255842568425784258842598426084261842628426384264842658426684267842688426984270842718427284273842748427584276842778427884279842808428184282842838428484285842868428784288842898429084291842928429384294842958429684297842988429984300843018430284303843048430584306843078430884309843108431184312843138431484315843168431784318843198432084321843228432384324843258432684327843288432984330843318433284333843348433584336843378433884339843408434184342843438434484345843468434784348843498435084351843528435384354843558435684357843588435984360843618436284363843648436584366843678436884369843708437184372843738437484375843768437784378843798438084381843828438384384843858438684387843888438984390843918439284393843948439584396843978439884399844008440184402844038440484405844068440784408844098441084411844128441384414844158441684417844188441984420844218442284423844248442584426844278442884429844308443184432844338443484435844368443784438844398444084441844428444384444844458444684447844488444984450844518445284453844548445584456844578445884459844608446184462844638446484465844668446784468844698447084471844728447384474844758447684477844788447984480844818448284483844848448584486844878448884489844908449184492844938449484495844968449784498844998450084501845028450384504845058450684507845088450984510845118451284513845148451584516845178451884519845208452184522845238452484525845268452784528845298453084531845328453384534845358453684537845388453984540845418454284543845448454584546845478454884549845508455184552845538455484555845568455784558845598456084561845628456384564845658456684567845688456984570845718457284573845748457584576845778457884579845808458184582845838458484585845868458784588845898459084591845928459384594845958459684597845988459984600846018460284603846048460584606846078460884609846108461184612846138461484615846168461784618846198462084621846228462384624846258462684627846288462984630846318463284633846348463584636846378463884639846408464184642846438464484645846468464784648846498465084651846528465384654846558465684657846588465984660846618466284663846648466584666846678466884669846708467184672846738467484675846768467784678846798468084681846828468384684846858468684687846888468984690846918469284693846948469584696846978469884699847008470184702847038470484705847068470784708847098471084711847128471384714847158471684717847188471984720847218472284723847248472584726847278472884729847308473184732847338473484735847368473784738847398474084741847428474384744847458474684747847488474984750847518475284753847548475584756847578475884759847608476184762847638476484765847668476784768847698477084771847728477384774847758477684777847788477984780847818478284783847848478584786847878478884789847908479184792847938479484795847968479784798847998480084801848028480384804848058480684807848088480984810848118481284813848148481584816848178481884819848208482184822848238482484825848268482784828848298483084831848328483384834848358483684837848388483984840848418484284843848448484584846848478484884849848508485184852848538485484855848568485784858848598486084861848628486384864848658486684867848688486984870848718487284873848748487584876848778487884879848808488184882848838488484885848868488784888848898489084891848928489384894848958489684897848988489984900849018490284903849048490584906849078490884909849108491184912849138491484915849168491784918849198492084921849228492384924849258492684927849288492984930849318493284933849348493584936849378493884939849408494184942849438494484945849468494784948849498495084951849528495384954849558495684957849588495984960849618496284963849648496584966849678496884969849708497184972849738497484975849768497784978849798498084981849828498384984849858498684987849888498984990849918499284993849948499584996849978499884999850008500185002850038500485005850068500785008850098501085011850128501385014850158501685017850188501985020850218502285023850248502585026850278502885029850308503185032850338503485035850368503785038850398504085041850428504385044850458504685047850488504985050850518505285053850548505585056850578505885059850608506185062850638506485065850668506785068850698507085071850728507385074850758507685077850788507985080850818508285083850848508585086850878508885089850908509185092850938509485095850968509785098850998510085101851028510385104851058510685107851088510985110851118511285113851148511585116851178511885119851208512185122851238512485125851268512785128851298513085131851328513385134851358513685137851388513985140851418514285143851448514585146851478514885149851508515185152851538515485155851568515785158851598516085161851628516385164851658516685167851688516985170851718517285173851748517585176851778517885179851808518185182851838518485185851868518785188851898519085191851928519385194851958519685197851988519985200852018520285203852048520585206852078520885209852108521185212852138521485215852168521785218852198522085221852228522385224852258522685227852288522985230852318523285233852348523585236852378523885239852408524185242852438524485245852468524785248852498525085251852528525385254852558525685257852588525985260852618526285263852648526585266852678526885269852708527185272852738527485275852768527785278852798528085281852828528385284852858528685287852888528985290852918529285293852948529585296852978529885299853008530185302853038530485305853068530785308853098531085311853128531385314853158531685317853188531985320853218532285323853248532585326853278532885329853308533185332853338533485335853368533785338853398534085341853428534385344853458534685347853488534985350853518535285353853548535585356853578535885359853608536185362853638536485365853668536785368853698537085371853728537385374853758537685377853788537985380853818538285383853848538585386853878538885389853908539185392853938539485395853968539785398853998540085401854028540385404854058540685407854088540985410854118541285413854148541585416854178541885419854208542185422854238542485425854268542785428854298543085431854328543385434854358543685437854388543985440854418544285443854448544585446854478544885449854508545185452854538545485455854568545785458854598546085461854628546385464854658546685467854688546985470854718547285473854748547585476854778547885479854808548185482854838548485485854868548785488854898549085491854928549385494854958549685497854988549985500855018550285503855048550585506855078550885509855108551185512855138551485515855168551785518855198552085521855228552385524855258552685527855288552985530855318553285533855348553585536855378553885539855408554185542855438554485545855468554785548855498555085551855528555385554855558555685557855588555985560855618556285563855648556585566855678556885569855708557185572855738557485575855768557785578855798558085581855828558385584855858558685587855888558985590855918559285593855948559585596855978559885599856008560185602856038560485605856068560785608856098561085611856128561385614856158561685617856188561985620856218562285623856248562585626856278562885629856308563185632856338563485635856368563785638856398564085641856428564385644856458564685647856488564985650856518565285653856548565585656856578565885659856608566185662856638566485665856668566785668856698567085671856728567385674856758567685677856788567985680856818568285683856848568585686856878568885689856908569185692856938569485695856968569785698856998570085701857028570385704857058570685707857088570985710857118571285713857148571585716857178571885719857208572185722857238572485725857268572785728857298573085731857328573385734857358573685737857388573985740857418574285743857448574585746857478574885749857508575185752857538575485755857568575785758857598576085761857628576385764857658576685767857688576985770857718577285773857748577585776857778577885779857808578185782857838578485785857868578785788857898579085791857928579385794857958579685797857988579985800858018580285803858048580585806858078580885809858108581185812858138581485815858168581785818858198582085821858228582385824858258582685827858288582985830858318583285833858348583585836858378583885839858408584185842858438584485845858468584785848858498585085851858528585385854858558585685857858588585985860858618586285863858648586585866858678586885869858708587185872858738587485875858768587785878858798588085881858828588385884858858588685887858888588985890858918589285893858948589585896858978589885899859008590185902859038590485905859068590785908859098591085911859128591385914859158591685917859188591985920859218592285923859248592585926859278592885929859308593185932859338593485935859368593785938859398594085941859428594385944859458594685947859488594985950859518595285953859548595585956859578595885959859608596185962859638596485965859668596785968859698597085971859728597385974859758597685977859788597985980859818598285983859848598585986859878598885989859908599185992859938599485995859968599785998859998600086001860028600386004860058600686007860088600986010860118601286013860148601586016860178601886019860208602186022860238602486025860268602786028860298603086031860328603386034860358603686037860388603986040860418604286043860448604586046860478604886049860508605186052860538605486055860568605786058860598606086061860628606386064860658606686067860688606986070860718607286073860748607586076860778607886079860808608186082860838608486085860868608786088860898609086091860928609386094860958609686097860988609986100861018610286103861048610586106861078610886109861108611186112861138611486115861168611786118861198612086121861228612386124861258612686127861288612986130861318613286133861348613586136861378613886139861408614186142861438614486145861468614786148861498615086151861528615386154861558615686157861588615986160861618616286163861648616586166861678616886169861708617186172861738617486175861768617786178861798618086181861828618386184861858618686187861888618986190861918619286193861948619586196861978619886199862008620186202862038620486205862068620786208862098621086211862128621386214862158621686217862188621986220862218622286223862248622586226862278622886229862308623186232862338623486235862368623786238862398624086241862428624386244862458624686247862488624986250862518625286253862548625586256862578625886259862608626186262862638626486265862668626786268862698627086271862728627386274862758627686277862788627986280862818628286283862848628586286862878628886289862908629186292862938629486295862968629786298862998630086301863028630386304863058630686307863088630986310863118631286313863148631586316863178631886319863208632186322863238632486325863268632786328863298633086331863328633386334863358633686337863388633986340863418634286343863448634586346863478634886349863508635186352863538635486355863568635786358863598636086361863628636386364863658636686367863688636986370863718637286373863748637586376863778637886379863808638186382863838638486385863868638786388863898639086391863928639386394863958639686397863988639986400864018640286403864048640586406864078640886409864108641186412864138641486415864168641786418864198642086421864228642386424864258642686427864288642986430864318643286433864348643586436864378643886439864408644186442864438644486445864468644786448864498645086451864528645386454864558645686457864588645986460864618646286463864648646586466864678646886469864708647186472864738647486475864768647786478864798648086481864828648386484864858648686487864888648986490864918649286493864948649586496864978649886499865008650186502865038650486505865068650786508865098651086511865128651386514865158651686517865188651986520865218652286523865248652586526865278652886529865308653186532865338653486535865368653786538865398654086541865428654386544865458654686547865488654986550865518655286553865548655586556865578655886559865608656186562865638656486565865668656786568865698657086571865728657386574865758657686577865788657986580865818658286583865848658586586865878658886589865908659186592865938659486595865968659786598865998660086601866028660386604866058660686607866088660986610866118661286613866148661586616866178661886619866208662186622866238662486625866268662786628866298663086631866328663386634866358663686637866388663986640866418664286643866448664586646866478664886649866508665186652866538665486655866568665786658866598666086661866628666386664866658666686667866688666986670866718667286673866748667586676866778667886679866808668186682866838668486685866868668786688866898669086691866928669386694866958669686697866988669986700867018670286703867048670586706867078670886709867108671186712867138671486715867168671786718867198672086721867228672386724867258672686727867288672986730867318673286733867348673586736867378673886739867408674186742867438674486745867468674786748867498675086751867528675386754867558675686757867588675986760867618676286763867648676586766867678676886769867708677186772867738677486775867768677786778867798678086781867828678386784867858678686787867888678986790867918679286793867948679586796867978679886799868008680186802868038680486805868068680786808868098681086811868128681386814868158681686817868188681986820868218682286823868248682586826868278682886829868308683186832868338683486835868368683786838868398684086841868428684386844868458684686847868488684986850868518685286853868548685586856868578685886859868608686186862868638686486865868668686786868868698687086871868728687386874868758687686877868788687986880868818688286883868848688586886868878688886889868908689186892868938689486895868968689786898868998690086901869028690386904869058690686907869088690986910869118691286913869148691586916869178691886919869208692186922869238692486925869268692786928869298693086931869328693386934869358693686937869388693986940869418694286943869448694586946869478694886949869508695186952869538695486955869568695786958869598696086961869628696386964869658696686967869688696986970869718697286973869748697586976869778697886979869808698186982869838698486985869868698786988869898699086991869928699386994869958699686997869988699987000870018700287003870048700587006870078700887009870108701187012870138701487015870168701787018870198702087021870228702387024870258702687027870288702987030870318703287033870348703587036870378703887039870408704187042870438704487045870468704787048870498705087051870528705387054870558705687057870588705987060870618706287063870648706587066870678706887069870708707187072870738707487075870768707787078870798708087081870828708387084870858708687087870888708987090870918709287093870948709587096870978709887099871008710187102871038710487105871068710787108871098711087111871128711387114871158711687117871188711987120871218712287123871248712587126871278712887129871308713187132871338713487135871368713787138871398714087141871428714387144871458714687147871488714987150871518715287153871548715587156871578715887159871608716187162871638716487165871668716787168871698717087171871728717387174871758717687177871788717987180871818718287183871848718587186871878718887189871908719187192871938719487195871968719787198871998720087201872028720387204872058720687207872088720987210872118721287213872148721587216872178721887219872208722187222872238722487225872268722787228872298723087231872328723387234872358723687237872388723987240872418724287243872448724587246872478724887249872508725187252872538725487255872568725787258872598726087261872628726387264872658726687267872688726987270872718727287273872748727587276872778727887279872808728187282872838728487285872868728787288872898729087291872928729387294872958729687297872988729987300873018730287303873048730587306873078730887309873108731187312873138731487315873168731787318873198732087321873228732387324873258732687327873288732987330873318733287333873348733587336873378733887339873408734187342873438734487345873468734787348873498735087351873528735387354873558735687357873588735987360873618736287363873648736587366873678736887369873708737187372873738737487375873768737787378873798738087381873828738387384873858738687387873888738987390873918739287393873948739587396873978739887399874008740187402874038740487405874068740787408874098741087411874128741387414874158741687417874188741987420874218742287423874248742587426874278742887429874308743187432874338743487435874368743787438874398744087441874428744387444874458744687447874488744987450874518745287453874548745587456874578745887459874608746187462874638746487465874668746787468874698747087471874728747387474874758747687477874788747987480874818748287483874848748587486874878748887489874908749187492874938749487495874968749787498874998750087501875028750387504875058750687507875088750987510875118751287513875148751587516875178751887519875208752187522875238752487525875268752787528875298753087531875328753387534875358753687537875388753987540875418754287543875448754587546875478754887549875508755187552875538755487555875568755787558875598756087561875628756387564875658756687567875688756987570875718757287573875748757587576875778757887579875808758187582875838758487585875868758787588875898759087591875928759387594875958759687597875988759987600876018760287603876048760587606876078760887609876108761187612876138761487615876168761787618876198762087621876228762387624876258762687627876288762987630876318763287633876348763587636876378763887639876408764187642876438764487645876468764787648876498765087651876528765387654876558765687657876588765987660876618766287663876648766587666876678766887669876708767187672876738767487675876768767787678876798768087681876828768387684876858768687687876888768987690876918769287693876948769587696876978769887699877008770187702877038770487705877068770787708877098771087711877128771387714877158771687717877188771987720877218772287723877248772587726877278772887729877308773187732877338773487735877368773787738877398774087741877428774387744877458774687747877488774987750877518775287753877548775587756877578775887759877608776187762877638776487765877668776787768877698777087771877728777387774877758777687777877788777987780877818778287783877848778587786877878778887789877908779187792877938779487795877968779787798877998780087801878028780387804878058780687807878088780987810878118781287813878148781587816878178781887819878208782187822878238782487825878268782787828878298783087831878328783387834878358783687837878388783987840878418784287843878448784587846878478784887849878508785187852878538785487855878568785787858878598786087861878628786387864878658786687867878688786987870878718787287873878748787587876878778787887879878808788187882878838788487885878868788787888878898789087891878928789387894878958789687897878988789987900879018790287903879048790587906879078790887909879108791187912879138791487915879168791787918879198792087921879228792387924879258792687927879288792987930879318793287933879348793587936879378793887939879408794187942879438794487945879468794787948879498795087951879528795387954879558795687957879588795987960879618796287963879648796587966879678796887969879708797187972879738797487975879768797787978879798798087981879828798387984879858798687987879888798987990879918799287993879948799587996879978799887999880008800188002880038800488005880068800788008880098801088011880128801388014880158801688017880188801988020880218802288023880248802588026880278802888029880308803188032880338803488035880368803788038880398804088041880428804388044880458804688047880488804988050880518805288053880548805588056880578805888059880608806188062880638806488065880668806788068880698807088071880728807388074880758807688077880788807988080880818808288083880848808588086880878808888089880908809188092880938809488095880968809788098880998810088101881028810388104881058810688107881088810988110881118811288113881148811588116881178811888119881208812188122881238812488125881268812788128881298813088131881328813388134881358813688137881388813988140881418814288143881448814588146881478814888149881508815188152881538815488155881568815788158881598816088161881628816388164881658816688167881688816988170881718817288173881748817588176881778817888179881808818188182881838818488185881868818788188881898819088191881928819388194881958819688197881988819988200882018820288203882048820588206882078820888209882108821188212882138821488215882168821788218882198822088221882228822388224882258822688227882288822988230882318823288233882348823588236882378823888239882408824188242882438824488245882468824788248882498825088251882528825388254882558825688257882588825988260882618826288263882648826588266882678826888269882708827188272882738827488275882768827788278882798828088281882828828388284882858828688287882888828988290882918829288293882948829588296882978829888299883008830188302883038830488305883068830788308883098831088311883128831388314883158831688317883188831988320883218832288323883248832588326883278832888329883308833188332883338833488335883368833788338883398834088341883428834388344883458834688347883488834988350883518835288353883548835588356883578835888359883608836188362883638836488365883668836788368883698837088371883728837388374883758837688377883788837988380883818838288383883848838588386883878838888389883908839188392883938839488395883968839788398883998840088401884028840388404884058840688407884088840988410884118841288413884148841588416884178841888419884208842188422884238842488425884268842788428884298843088431884328843388434884358843688437884388843988440884418844288443884448844588446884478844888449884508845188452884538845488455884568845788458884598846088461884628846388464884658846688467884688846988470884718847288473884748847588476884778847888479884808848188482884838848488485884868848788488884898849088491884928849388494884958849688497884988849988500885018850288503885048850588506885078850888509885108851188512885138851488515885168851788518885198852088521885228852388524885258852688527885288852988530885318853288533885348853588536885378853888539885408854188542885438854488545885468854788548885498855088551885528855388554885558855688557885588855988560885618856288563885648856588566885678856888569885708857188572885738857488575885768857788578885798858088581885828858388584885858858688587885888858988590885918859288593885948859588596885978859888599886008860188602886038860488605886068860788608886098861088611886128861388614886158861688617886188861988620886218862288623886248862588626886278862888629886308863188632886338863488635886368863788638886398864088641886428864388644886458864688647886488864988650886518865288653886548865588656886578865888659886608866188662886638866488665886668866788668886698867088671886728867388674886758867688677886788867988680886818868288683886848868588686886878868888689886908869188692886938869488695886968869788698886998870088701887028870388704887058870688707887088870988710887118871288713887148871588716887178871888719887208872188722887238872488725887268872788728887298873088731887328873388734887358873688737887388873988740887418874288743887448874588746887478874888749887508875188752887538875488755887568875788758887598876088761887628876388764887658876688767887688876988770887718877288773887748877588776887778877888779887808878188782887838878488785887868878788788887898879088791887928879388794887958879688797887988879988800888018880288803888048880588806888078880888809888108881188812888138881488815888168881788818888198882088821888228882388824888258882688827888288882988830888318883288833888348883588836888378883888839888408884188842888438884488845888468884788848888498885088851888528885388854888558885688857888588885988860888618886288863888648886588866888678886888869888708887188872888738887488875888768887788878888798888088881888828888388884888858888688887888888888988890888918889288893888948889588896888978889888899889008890188902889038890488905889068890788908889098891088911889128891388914889158891688917889188891988920889218892288923889248892588926889278892888929889308893188932889338893488935889368893788938889398894088941889428894388944889458894688947889488894988950889518895288953889548895588956889578895888959889608896188962889638896488965889668896788968889698897088971889728897388974889758897688977889788897988980889818898288983889848898588986889878898888989889908899188992889938899488995889968899788998889998900089001890028900389004890058900689007890088900989010890118901289013890148901589016890178901889019890208902189022890238902489025890268902789028890298903089031890328903389034890358903689037890388903989040890418904289043890448904589046890478904889049890508905189052890538905489055890568905789058890598906089061890628906389064890658906689067890688906989070890718907289073890748907589076890778907889079890808908189082890838908489085890868908789088890898909089091890928909389094890958909689097890988909989100891018910289103891048910589106891078910889109891108911189112891138911489115891168911789118891198912089121891228912389124891258912689127891288912989130891318913289133891348913589136891378913889139891408914189142891438914489145891468914789148891498915089151891528915389154891558915689157891588915989160891618916289163891648916589166891678916889169891708917189172891738917489175891768917789178891798918089181891828918389184891858918689187891888918989190891918919289193891948919589196891978919889199892008920189202892038920489205892068920789208892098921089211892128921389214892158921689217892188921989220892218922289223892248922589226892278922889229892308923189232892338923489235892368923789238892398924089241892428924389244892458924689247892488924989250892518925289253892548925589256892578925889259892608926189262892638926489265892668926789268892698927089271892728927389274892758927689277892788927989280892818928289283892848928589286892878928889289892908929189292892938929489295892968929789298892998930089301893028930389304893058930689307893088930989310893118931289313893148931589316893178931889319893208932189322893238932489325893268932789328893298933089331893328933389334893358933689337893388933989340893418934289343893448934589346893478934889349893508935189352893538935489355893568935789358893598936089361893628936389364893658936689367893688936989370893718937289373893748937589376893778937889379893808938189382893838938489385893868938789388893898939089391893928939389394893958939689397893988939989400894018940289403894048940589406894078940889409894108941189412894138941489415894168941789418894198942089421894228942389424894258942689427894288942989430894318943289433894348943589436894378943889439894408944189442894438944489445894468944789448894498945089451894528945389454894558945689457894588945989460894618946289463894648946589466894678946889469894708947189472894738947489475894768947789478894798948089481894828948389484894858948689487894888948989490894918949289493894948949589496894978949889499895008950189502895038950489505895068950789508895098951089511895128951389514895158951689517895188951989520895218952289523895248952589526895278952889529895308953189532895338953489535895368953789538895398954089541895428954389544895458954689547895488954989550895518955289553895548955589556895578955889559895608956189562895638956489565895668956789568895698957089571895728957389574895758957689577895788957989580895818958289583895848958589586895878958889589895908959189592895938959489595895968959789598895998960089601896028960389604896058960689607896088960989610896118961289613896148961589616896178961889619896208962189622896238962489625896268962789628896298963089631896328963389634896358963689637896388963989640896418964289643896448964589646896478964889649896508965189652896538965489655896568965789658896598966089661896628966389664896658966689667896688966989670896718967289673896748967589676896778967889679896808968189682896838968489685896868968789688896898969089691896928969389694896958969689697896988969989700897018970289703897048970589706897078970889709897108971189712897138971489715897168971789718897198972089721897228972389724897258972689727897288972989730897318973289733897348973589736897378973889739897408974189742897438974489745897468974789748897498975089751897528975389754897558975689757897588975989760897618976289763897648976589766897678976889769897708977189772897738977489775897768977789778897798978089781897828978389784897858978689787897888978989790897918979289793897948979589796897978979889799898008980189802898038980489805898068980789808898098981089811898128981389814898158981689817898188981989820898218982289823898248982589826898278982889829898308983189832898338983489835898368983789838898398984089841898428984389844898458984689847898488984989850898518985289853898548985589856898578985889859898608986189862898638986489865898668986789868898698987089871898728987389874898758987689877898788987989880898818988289883898848988589886898878988889889898908989189892898938989489895898968989789898898998990089901899028990389904899058990689907899088990989910899118991289913899148991589916899178991889919899208992189922899238992489925899268992789928899298993089931899328993389934899358993689937899388993989940899418994289943899448994589946899478994889949899508995189952899538995489955899568995789958899598996089961899628996389964899658996689967899688996989970899718997289973899748997589976899778997889979899808998189982899838998489985899868998789988899898999089991899928999389994899958999689997899988999990000900019000290003900049000590006900079000890009900109001190012900139001490015900169001790018900199002090021900229002390024900259002690027900289002990030900319003290033900349003590036900379003890039900409004190042900439004490045900469004790048900499005090051900529005390054900559005690057900589005990060900619006290063900649006590066900679006890069900709007190072900739007490075900769007790078900799008090081900829008390084900859008690087900889008990090900919009290093900949009590096900979009890099901009010190102901039010490105901069010790108901099011090111901129011390114901159011690117901189011990120901219012290123901249012590126901279012890129901309013190132901339013490135901369013790138901399014090141901429014390144901459014690147901489014990150901519015290153901549015590156901579015890159901609016190162901639016490165901669016790168901699017090171901729017390174901759017690177901789017990180901819018290183901849018590186901879018890189901909019190192901939019490195901969019790198901999020090201902029020390204902059020690207902089020990210902119021290213902149021590216902179021890219902209022190222902239022490225902269022790228902299023090231902329023390234902359023690237902389023990240902419024290243902449024590246902479024890249902509025190252902539025490255902569025790258902599026090261902629026390264902659026690267902689026990270902719027290273902749027590276902779027890279902809028190282902839028490285902869028790288902899029090291902929029390294902959029690297902989029990300903019030290303903049030590306903079030890309903109031190312903139031490315903169031790318903199032090321903229032390324903259032690327903289032990330903319033290333903349033590336903379033890339903409034190342903439034490345903469034790348903499035090351903529035390354903559035690357903589035990360903619036290363903649036590366903679036890369903709037190372903739037490375903769037790378903799038090381903829038390384903859038690387903889038990390903919039290393903949039590396903979039890399904009040190402904039040490405904069040790408904099041090411904129041390414904159041690417904189041990420904219042290423904249042590426904279042890429904309043190432904339043490435904369043790438904399044090441904429044390444904459044690447904489044990450904519045290453904549045590456904579045890459904609046190462904639046490465904669046790468904699047090471904729047390474904759047690477904789047990480904819048290483904849048590486904879048890489904909049190492904939049490495904969049790498904999050090501905029050390504905059050690507905089050990510905119051290513905149051590516905179051890519905209052190522905239052490525905269052790528905299053090531905329053390534905359053690537905389053990540905419054290543905449054590546905479054890549905509055190552905539055490555905569055790558905599056090561905629056390564905659056690567905689056990570905719057290573905749057590576905779057890579905809058190582905839058490585905869058790588905899059090591905929059390594905959059690597905989059990600906019060290603906049060590606906079060890609906109061190612906139061490615906169061790618906199062090621906229062390624906259062690627906289062990630906319063290633906349063590636906379063890639906409064190642906439064490645906469064790648906499065090651906529065390654906559065690657906589065990660906619066290663906649066590666906679066890669906709067190672906739067490675906769067790678906799068090681906829068390684906859068690687906889068990690906919069290693906949069590696906979069890699907009070190702907039070490705907069070790708907099071090711907129071390714907159071690717907189071990720907219072290723907249072590726907279072890729907309073190732907339073490735907369073790738907399074090741907429074390744907459074690747907489074990750907519075290753907549075590756907579075890759907609076190762907639076490765907669076790768907699077090771907729077390774907759077690777907789077990780907819078290783907849078590786907879078890789907909079190792907939079490795907969079790798907999080090801908029080390804908059080690807908089080990810908119081290813908149081590816908179081890819908209082190822908239082490825908269082790828908299083090831908329083390834908359083690837908389083990840908419084290843908449084590846908479084890849908509085190852908539085490855908569085790858908599086090861908629086390864908659086690867908689086990870908719087290873908749087590876908779087890879908809088190882908839088490885908869088790888908899089090891908929089390894908959089690897908989089990900909019090290903909049090590906909079090890909909109091190912909139091490915909169091790918909199092090921909229092390924909259092690927909289092990930909319093290933909349093590936909379093890939909409094190942909439094490945909469094790948909499095090951909529095390954909559095690957909589095990960909619096290963909649096590966909679096890969909709097190972909739097490975909769097790978909799098090981909829098390984909859098690987909889098990990909919099290993909949099590996909979099890999910009100191002910039100491005910069100791008910099101091011910129101391014910159101691017910189101991020910219102291023910249102591026910279102891029910309103191032910339103491035910369103791038910399104091041910429104391044910459104691047910489104991050910519105291053910549105591056910579105891059910609106191062910639106491065910669106791068910699107091071910729107391074910759107691077910789107991080910819108291083910849108591086910879108891089910909109191092910939109491095910969109791098910999110091101911029110391104911059110691107911089110991110911119111291113911149111591116911179111891119911209112191122911239112491125911269112791128911299113091131911329113391134911359113691137911389113991140911419114291143911449114591146911479114891149911509115191152911539115491155911569115791158911599116091161911629116391164911659116691167911689116991170911719117291173911749117591176911779117891179911809118191182911839118491185911869118791188911899119091191911929119391194911959119691197911989119991200912019120291203912049120591206912079120891209912109121191212912139121491215912169121791218912199122091221912229122391224912259122691227912289122991230912319123291233912349123591236912379123891239912409124191242912439124491245912469124791248912499125091251912529125391254912559125691257912589125991260912619126291263912649126591266912679126891269912709127191272912739127491275912769127791278912799128091281912829128391284912859128691287912889128991290912919129291293912949129591296912979129891299913009130191302913039130491305913069130791308913099131091311913129131391314913159131691317913189131991320913219132291323913249132591326913279132891329913309133191332913339133491335913369133791338913399134091341913429134391344913459134691347913489134991350913519135291353913549135591356913579135891359913609136191362913639136491365913669136791368913699137091371913729137391374913759137691377913789137991380913819138291383913849138591386913879138891389913909139191392913939139491395913969139791398913999140091401914029140391404914059140691407914089140991410914119141291413914149141591416914179141891419914209142191422914239142491425914269142791428914299143091431914329143391434914359143691437914389143991440914419144291443914449144591446914479144891449914509145191452914539145491455914569145791458914599146091461914629146391464914659146691467914689146991470914719147291473914749147591476914779147891479914809148191482914839148491485914869148791488914899149091491914929149391494914959149691497914989149991500915019150291503915049150591506915079150891509915109151191512915139151491515915169151791518915199152091521915229152391524915259152691527915289152991530915319153291533915349153591536915379153891539915409154191542915439154491545915469154791548915499155091551915529155391554915559155691557915589155991560915619156291563915649156591566915679156891569915709157191572915739157491575915769157791578915799158091581915829158391584915859158691587915889158991590915919159291593915949159591596915979159891599916009160191602916039160491605916069160791608916099161091611916129161391614916159161691617916189161991620916219162291623916249162591626916279162891629916309163191632916339163491635916369163791638916399164091641916429164391644916459164691647916489164991650916519165291653916549165591656916579165891659916609166191662916639166491665916669166791668916699167091671916729167391674916759167691677916789167991680916819168291683916849168591686916879168891689916909169191692916939169491695916969169791698916999170091701917029170391704917059170691707917089170991710917119171291713917149171591716917179171891719917209172191722917239172491725917269172791728917299173091731917329173391734917359173691737917389173991740917419174291743917449174591746917479174891749917509175191752917539175491755917569175791758917599176091761917629176391764917659176691767917689176991770917719177291773917749177591776917779177891779917809178191782917839178491785917869178791788917899179091791917929179391794917959179691797917989179991800918019180291803918049180591806918079180891809918109181191812918139181491815918169181791818918199182091821918229182391824918259182691827918289182991830918319183291833918349183591836918379183891839918409184191842918439184491845918469184791848918499185091851918529185391854918559185691857918589185991860918619186291863918649186591866918679186891869918709187191872918739187491875918769187791878918799188091881918829188391884918859188691887918889188991890918919189291893918949189591896918979189891899919009190191902919039190491905919069190791908919099191091911919129191391914919159191691917919189191991920919219192291923919249192591926919279192891929919309193191932919339193491935919369193791938919399194091941919429194391944919459194691947919489194991950919519195291953919549195591956919579195891959919609196191962919639196491965919669196791968919699197091971919729197391974919759197691977919789197991980919819198291983919849198591986919879198891989919909199191992919939199491995919969199791998919999200092001920029200392004920059200692007920089200992010920119201292013920149201592016920179201892019920209202192022920239202492025920269202792028920299203092031920329203392034920359203692037920389203992040920419204292043920449204592046920479204892049920509205192052920539205492055920569205792058920599206092061920629206392064920659206692067920689206992070920719207292073920749207592076920779207892079920809208192082920839208492085920869208792088920899209092091920929209392094920959209692097920989209992100921019210292103921049210592106921079210892109921109211192112921139211492115921169211792118921199212092121921229212392124921259212692127921289212992130921319213292133921349213592136921379213892139921409214192142921439214492145921469214792148921499215092151921529215392154921559215692157921589215992160921619216292163921649216592166921679216892169921709217192172921739217492175921769217792178921799218092181921829218392184921859218692187921889218992190921919219292193921949219592196921979219892199922009220192202922039220492205922069220792208922099221092211922129221392214922159221692217922189221992220922219222292223922249222592226922279222892229922309223192232922339223492235922369223792238922399224092241922429224392244922459224692247922489224992250922519225292253922549225592256922579225892259922609226192262922639226492265922669226792268922699227092271922729227392274922759227692277922789227992280922819228292283922849228592286922879228892289922909229192292922939229492295922969229792298922999230092301923029230392304923059230692307923089230992310923119231292313923149231592316923179231892319923209232192322923239232492325923269232792328923299233092331923329233392334923359233692337923389233992340923419234292343923449234592346923479234892349923509235192352923539235492355923569235792358923599236092361923629236392364923659236692367923689236992370923719237292373923749237592376923779237892379923809238192382923839238492385923869238792388923899239092391923929239392394923959239692397923989239992400924019240292403924049240592406924079240892409924109241192412924139241492415924169241792418924199242092421924229242392424924259242692427924289242992430924319243292433924349243592436924379243892439924409244192442924439244492445924469244792448924499245092451924529245392454924559245692457924589245992460924619246292463924649246592466924679246892469924709247192472924739247492475924769247792478924799248092481924829248392484924859248692487924889248992490924919249292493924949249592496924979249892499925009250192502925039250492505925069250792508925099251092511925129251392514925159251692517925189251992520925219252292523925249252592526925279252892529925309253192532925339253492535925369253792538925399254092541925429254392544925459254692547925489254992550925519255292553925549255592556925579255892559925609256192562925639256492565925669256792568925699257092571925729257392574925759257692577925789257992580925819258292583925849258592586925879258892589925909259192592925939259492595925969259792598925999260092601926029260392604926059260692607926089260992610926119261292613926149261592616926179261892619926209262192622926239262492625926269262792628926299263092631926329263392634926359263692637926389263992640926419264292643926449264592646926479264892649926509265192652926539265492655926569265792658926599266092661926629266392664926659266692667926689266992670926719267292673926749267592676926779267892679926809268192682926839268492685926869268792688926899269092691926929269392694926959269692697926989269992700927019270292703927049270592706927079270892709927109271192712927139271492715927169271792718927199272092721927229272392724927259272692727927289272992730927319273292733927349273592736927379273892739927409274192742927439274492745927469274792748927499275092751927529275392754927559275692757927589275992760927619276292763927649276592766927679276892769927709277192772927739277492775927769277792778927799278092781927829278392784927859278692787927889278992790927919279292793927949279592796927979279892799928009280192802928039280492805928069280792808928099281092811928129281392814928159281692817928189281992820928219282292823928249282592826928279282892829928309283192832928339283492835928369283792838928399284092841928429284392844928459284692847928489284992850928519285292853928549285592856928579285892859928609286192862928639286492865928669286792868928699287092871928729287392874928759287692877928789287992880928819288292883928849288592886928879288892889928909289192892928939289492895928969289792898928999290092901929029290392904929059290692907929089290992910929119291292913929149291592916929179291892919929209292192922929239292492925929269292792928929299293092931929329293392934929359293692937929389293992940929419294292943929449294592946929479294892949929509295192952929539295492955929569295792958929599296092961929629296392964929659296692967929689296992970929719297292973929749297592976929779297892979929809298192982929839298492985929869298792988929899299092991929929299392994929959299692997929989299993000930019300293003930049300593006930079300893009930109301193012930139301493015930169301793018930199302093021930229302393024930259302693027930289302993030930319303293033930349303593036930379303893039930409304193042930439304493045930469304793048930499305093051930529305393054930559305693057930589305993060930619306293063930649306593066930679306893069930709307193072930739307493075930769307793078930799308093081930829308393084930859308693087930889308993090930919309293093930949309593096930979309893099931009310193102931039310493105931069310793108931099311093111931129311393114931159311693117931189311993120931219312293123931249312593126931279312893129931309313193132931339313493135931369313793138931399314093141931429314393144931459314693147931489314993150931519315293153931549315593156931579315893159931609316193162931639316493165931669316793168931699317093171931729317393174931759317693177931789317993180931819318293183931849318593186931879318893189931909319193192931939319493195931969319793198931999320093201932029320393204932059320693207932089320993210932119321293213932149321593216932179321893219932209322193222932239322493225932269322793228932299323093231932329323393234932359323693237932389323993240932419324293243932449324593246932479324893249932509325193252932539325493255932569325793258932599326093261932629326393264932659326693267932689326993270932719327293273932749327593276932779327893279932809328193282932839328493285932869328793288932899329093291932929329393294932959329693297932989329993300933019330293303933049330593306933079330893309933109331193312933139331493315933169331793318933199332093321933229332393324933259332693327933289332993330933319333293333933349333593336933379333893339933409334193342933439334493345933469334793348933499335093351933529335393354933559335693357933589335993360933619336293363933649336593366933679336893369933709337193372933739337493375933769337793378933799338093381933829338393384933859338693387933889338993390933919339293393933949339593396933979339893399934009340193402934039340493405934069340793408934099341093411934129341393414934159341693417934189341993420934219342293423934249342593426934279342893429934309343193432934339343493435934369343793438934399344093441934429344393444934459344693447934489344993450934519345293453934549345593456934579345893459934609346193462934639346493465934669346793468934699347093471934729347393474934759347693477934789347993480934819348293483934849348593486934879348893489934909349193492934939349493495934969349793498934999350093501935029350393504935059350693507935089350993510935119351293513935149351593516935179351893519935209352193522935239352493525935269352793528935299353093531935329353393534935359353693537935389353993540935419354293543935449354593546935479354893549935509355193552935539355493555935569355793558935599356093561935629356393564935659356693567935689356993570935719357293573935749357593576935779357893579935809358193582935839358493585935869358793588935899359093591935929359393594935959359693597935989359993600936019360293603936049360593606936079360893609936109361193612936139361493615936169361793618936199362093621936229362393624936259362693627936289362993630936319363293633936349363593636936379363893639936409364193642936439364493645936469364793648936499365093651936529365393654936559365693657936589365993660936619366293663936649366593666936679366893669936709367193672936739367493675936769367793678936799368093681936829368393684936859368693687936889368993690936919369293693936949369593696936979369893699937009370193702937039370493705937069370793708937099371093711937129371393714937159371693717937189371993720937219372293723937249372593726937279372893729937309373193732937339373493735937369373793738937399374093741937429374393744937459374693747937489374993750937519375293753937549375593756937579375893759937609376193762937639376493765937669376793768937699377093771937729377393774937759377693777937789377993780937819378293783937849378593786937879378893789937909379193792937939379493795937969379793798937999380093801938029380393804938059380693807938089380993810938119381293813938149381593816938179381893819938209382193822938239382493825938269382793828938299383093831938329383393834938359383693837938389383993840938419384293843938449384593846938479384893849938509385193852938539385493855938569385793858938599386093861938629386393864938659386693867938689386993870938719387293873938749387593876938779387893879938809388193882938839388493885938869388793888938899389093891938929389393894938959389693897938989389993900939019390293903939049390593906939079390893909939109391193912939139391493915939169391793918939199392093921939229392393924939259392693927939289392993930939319393293933939349393593936939379393893939939409394193942939439394493945939469394793948939499395093951939529395393954939559395693957939589395993960939619396293963939649396593966939679396893969939709397193972939739397493975939769397793978939799398093981939829398393984939859398693987939889398993990939919399293993939949399593996939979399893999940009400194002940039400494005940069400794008940099401094011940129401394014940159401694017940189401994020940219402294023940249402594026940279402894029940309403194032940339403494035940369403794038940399404094041940429404394044940459404694047940489404994050940519405294053940549405594056940579405894059940609406194062940639406494065940669406794068940699407094071940729407394074940759407694077940789407994080940819408294083940849408594086940879408894089940909409194092940939409494095940969409794098940999410094101941029410394104941059410694107941089410994110941119411294113941149411594116941179411894119941209412194122941239412494125941269412794128941299413094131941329413394134941359413694137941389413994140941419414294143941449414594146941479414894149941509415194152941539415494155941569415794158941599416094161941629416394164941659416694167941689416994170941719417294173941749417594176941779417894179941809418194182941839418494185941869418794188941899419094191941929419394194941959419694197941989419994200942019420294203942049420594206942079420894209942109421194212942139421494215942169421794218942199422094221942229422394224942259422694227942289422994230942319423294233942349423594236942379423894239942409424194242942439424494245942469424794248942499425094251942529425394254942559425694257942589425994260942619426294263942649426594266942679426894269942709427194272942739427494275942769427794278942799428094281942829428394284942859428694287942889428994290942919429294293942949429594296942979429894299943009430194302943039430494305943069430794308943099431094311943129431394314943159431694317943189431994320943219432294323943249432594326943279432894329943309433194332943339433494335943369433794338943399434094341943429434394344943459434694347943489434994350943519435294353943549435594356943579435894359943609436194362943639436494365943669436794368943699437094371943729437394374943759437694377943789437994380943819438294383943849438594386943879438894389943909439194392943939439494395943969439794398943999440094401944029440394404944059440694407944089440994410944119441294413944149441594416944179441894419944209442194422944239442494425944269442794428944299443094431944329443394434944359443694437944389443994440944419444294443944449444594446944479444894449944509445194452944539445494455944569445794458944599446094461944629446394464944659446694467944689446994470944719447294473944749447594476944779447894479944809448194482944839448494485944869448794488944899449094491944929449394494944959449694497944989449994500945019450294503945049450594506945079450894509945109451194512945139451494515945169451794518945199452094521945229452394524945259452694527945289452994530945319453294533945349453594536945379453894539945409454194542945439454494545945469454794548945499455094551945529455394554945559455694557945589455994560945619456294563945649456594566945679456894569945709457194572945739457494575945769457794578945799458094581945829458394584945859458694587945889458994590945919459294593945949459594596945979459894599946009460194602946039460494605946069460794608946099461094611946129461394614946159461694617946189461994620946219462294623946249462594626946279462894629946309463194632946339463494635946369463794638946399464094641946429464394644946459464694647946489464994650946519465294653946549465594656946579465894659946609466194662946639466494665946669466794668946699467094671946729467394674946759467694677946789467994680946819468294683946849468594686946879468894689946909469194692946939469494695946969469794698946999470094701947029470394704947059470694707947089470994710947119471294713947149471594716947179471894719947209472194722947239472494725947269472794728947299473094731947329473394734947359473694737947389473994740947419474294743947449474594746947479474894749947509475194752947539475494755947569475794758947599476094761947629476394764947659476694767947689476994770947719477294773947749477594776947779477894779947809478194782947839478494785947869478794788947899479094791947929479394794947959479694797947989479994800948019480294803948049480594806948079480894809948109481194812948139481494815948169481794818948199482094821948229482394824948259482694827948289482994830948319483294833948349483594836948379483894839948409484194842948439484494845948469484794848948499485094851948529485394854948559485694857948589485994860948619486294863948649486594866948679486894869948709487194872948739487494875948769487794878948799488094881948829488394884948859488694887948889488994890948919489294893948949489594896948979489894899949009490194902949039490494905949069490794908949099491094911949129491394914949159491694917949189491994920949219492294923949249492594926949279492894929949309493194932949339493494935949369493794938949399494094941949429494394944949459494694947949489494994950949519495294953949549495594956949579495894959949609496194962949639496494965949669496794968949699497094971949729497394974949759497694977949789497994980949819498294983949849498594986949879498894989949909499194992949939499494995949969499794998949999500095001950029500395004950059500695007950089500995010950119501295013950149501595016950179501895019950209502195022950239502495025950269502795028950299503095031950329503395034950359503695037950389503995040950419504295043950449504595046950479504895049950509505195052950539505495055950569505795058950599506095061950629506395064950659506695067950689506995070950719507295073950749507595076950779507895079950809508195082950839508495085950869508795088950899509095091950929509395094950959509695097950989509995100951019510295103951049510595106951079510895109951109511195112951139511495115951169511795118951199512095121951229512395124951259512695127951289512995130951319513295133951349513595136951379513895139951409514195142951439514495145951469514795148951499515095151951529515395154951559515695157951589515995160951619516295163951649516595166951679516895169951709517195172951739517495175951769517795178951799518095181951829518395184951859518695187951889518995190951919519295193951949519595196951979519895199952009520195202952039520495205952069520795208952099521095211952129521395214952159521695217952189521995220952219522295223952249522595226952279522895229952309523195232952339523495235952369523795238952399524095241952429524395244952459524695247952489524995250952519525295253952549525595256952579525895259952609526195262952639526495265952669526795268952699527095271952729527395274952759527695277952789527995280952819528295283952849528595286952879528895289952909529195292952939529495295952969529795298952999530095301953029530395304953059530695307953089530995310953119531295313953149531595316953179531895319953209532195322953239532495325953269532795328953299533095331953329533395334953359533695337953389533995340953419534295343953449534595346953479534895349953509535195352953539535495355953569535795358953599536095361953629536395364953659536695367953689536995370953719537295373953749537595376953779537895379953809538195382953839538495385953869538795388953899539095391953929539395394953959539695397953989539995400954019540295403954049540595406954079540895409954109541195412954139541495415954169541795418954199542095421954229542395424954259542695427954289542995430954319543295433954349543595436954379543895439954409544195442954439544495445954469544795448954499545095451954529545395454954559545695457954589545995460954619546295463954649546595466954679546895469954709547195472954739547495475954769547795478954799548095481954829548395484954859548695487954889548995490954919549295493954949549595496954979549895499955009550195502955039550495505955069550795508955099551095511955129551395514955159551695517955189551995520955219552295523955249552595526955279552895529955309553195532955339553495535955369553795538955399554095541955429554395544955459554695547955489554995550955519555295553955549555595556955579555895559955609556195562955639556495565955669556795568955699557095571955729557395574955759557695577955789557995580955819558295583955849558595586955879558895589955909559195592955939559495595955969559795598955999560095601956029560395604956059560695607956089560995610956119561295613956149561595616956179561895619956209562195622956239562495625956269562795628956299563095631956329563395634956359563695637956389563995640956419564295643956449564595646956479564895649956509565195652956539565495655956569565795658956599566095661956629566395664956659566695667956689566995670956719567295673956749567595676956779567895679956809568195682956839568495685956869568795688956899569095691956929569395694956959569695697956989569995700957019570295703957049570595706957079570895709957109571195712957139571495715957169571795718957199572095721957229572395724957259572695727957289572995730957319573295733957349573595736957379573895739957409574195742957439574495745957469574795748957499575095751957529575395754957559575695757957589575995760957619576295763957649576595766957679576895769957709577195772957739577495775957769577795778957799578095781957829578395784957859578695787957889578995790957919579295793957949579595796957979579895799958009580195802958039580495805958069580795808958099581095811958129581395814958159581695817958189581995820958219582295823958249582595826958279582895829958309583195832958339583495835958369583795838958399584095841958429584395844958459584695847958489584995850958519585295853958549585595856958579585895859958609586195862958639586495865958669586795868958699587095871958729587395874958759587695877958789587995880958819588295883958849588595886958879588895889958909589195892958939589495895958969589795898958999590095901959029590395904959059590695907959089590995910959119591295913959149591595916959179591895919959209592195922959239592495925959269592795928959299593095931959329593395934959359593695937959389593995940959419594295943959449594595946959479594895949959509595195952959539595495955959569595795958959599596095961959629596395964959659596695967959689596995970959719597295973959749597595976959779597895979959809598195982959839598495985959869598795988959899599095991959929599395994959959599695997959989599996000960019600296003960049600596006960079600896009960109601196012960139601496015960169601796018960199602096021960229602396024960259602696027960289602996030960319603296033960349603596036960379603896039960409604196042960439604496045960469604796048960499605096051960529605396054960559605696057960589605996060960619606296063960649606596066960679606896069960709607196072960739607496075960769607796078960799608096081960829608396084960859608696087960889608996090960919609296093960949609596096960979609896099961009610196102961039610496105961069610796108961099611096111961129611396114961159611696117961189611996120961219612296123961249612596126961279612896129961309613196132961339613496135961369613796138961399614096141961429614396144961459614696147961489614996150961519615296153961549615596156961579615896159961609616196162961639616496165961669616796168961699617096171961729617396174961759617696177961789617996180961819618296183961849618596186961879618896189961909619196192961939619496195961969619796198961999620096201962029620396204962059620696207962089620996210962119621296213962149621596216962179621896219962209622196222962239622496225962269622796228962299623096231962329623396234962359623696237962389623996240962419624296243962449624596246962479624896249962509625196252962539625496255962569625796258962599626096261962629626396264962659626696267962689626996270962719627296273962749627596276962779627896279962809628196282962839628496285962869628796288962899629096291962929629396294962959629696297962989629996300963019630296303963049630596306963079630896309963109631196312963139631496315963169631796318963199632096321963229632396324963259632696327963289632996330963319633296333963349633596336963379633896339963409634196342963439634496345963469634796348963499635096351963529635396354963559635696357963589635996360963619636296363963649636596366963679636896369963709637196372963739637496375963769637796378963799638096381963829638396384963859638696387963889638996390963919639296393963949639596396963979639896399964009640196402964039640496405964069640796408964099641096411964129641396414964159641696417964189641996420964219642296423964249642596426964279642896429964309643196432964339643496435964369643796438964399644096441964429644396444964459644696447964489644996450964519645296453964549645596456964579645896459964609646196462964639646496465964669646796468964699647096471964729647396474964759647696477964789647996480964819648296483964849648596486964879648896489964909649196492964939649496495964969649796498964999650096501965029650396504965059650696507965089650996510965119651296513965149651596516965179651896519965209652196522965239652496525965269652796528965299653096531965329653396534965359653696537965389653996540965419654296543965449654596546965479654896549965509655196552965539655496555965569655796558965599656096561965629656396564965659656696567965689656996570965719657296573965749657596576965779657896579965809658196582965839658496585965869658796588965899659096591965929659396594965959659696597965989659996600966019660296603966049660596606966079660896609966109661196612966139661496615966169661796618966199662096621966229662396624966259662696627966289662996630966319663296633966349663596636966379663896639966409664196642966439664496645966469664796648966499665096651966529665396654966559665696657966589665996660966619666296663966649666596666966679666896669966709667196672966739667496675966769667796678966799668096681966829668396684966859668696687966889668996690966919669296693966949669596696966979669896699967009670196702967039670496705967069670796708967099671096711967129671396714967159671696717967189671996720967219672296723967249672596726967279672896729967309673196732967339673496735967369673796738967399674096741967429674396744967459674696747967489674996750967519675296753967549675596756967579675896759967609676196762967639676496765967669676796768967699677096771967729677396774967759677696777967789677996780967819678296783967849678596786967879678896789967909679196792967939679496795967969679796798967999680096801968029680396804968059680696807968089680996810968119681296813968149681596816968179681896819968209682196822968239682496825968269682796828968299683096831968329683396834968359683696837968389683996840968419684296843968449684596846968479684896849968509685196852968539685496855968569685796858968599686096861968629686396864968659686696867968689686996870968719687296873968749687596876968779687896879968809688196882968839688496885968869688796888968899689096891968929689396894968959689696897968989689996900969019690296903969049690596906969079690896909969109691196912969139691496915969169691796918969199692096921969229692396924969259692696927969289692996930969319693296933969349693596936969379693896939969409694196942969439694496945969469694796948969499695096951969529695396954969559695696957969589695996960969619696296963969649696596966969679696896969969709697196972969739697496975969769697796978969799698096981969829698396984969859698696987969889698996990969919699296993969949699596996969979699896999970009700197002970039700497005970069700797008970099701097011970129701397014970159701697017970189701997020970219702297023970249702597026970279702897029970309703197032970339703497035970369703797038970399704097041970429704397044970459704697047970489704997050970519705297053970549705597056970579705897059970609706197062970639706497065970669706797068970699707097071970729707397074970759707697077970789707997080970819708297083970849708597086970879708897089970909709197092970939709497095970969709797098970999710097101971029710397104971059710697107971089710997110971119711297113971149711597116971179711897119971209712197122971239712497125971269712797128971299713097131971329713397134971359713697137971389713997140971419714297143971449714597146971479714897149971509715197152971539715497155971569715797158971599716097161971629716397164971659716697167971689716997170971719717297173971749717597176971779717897179971809718197182971839718497185971869718797188971899719097191971929719397194971959719697197971989719997200972019720297203972049720597206972079720897209972109721197212972139721497215972169721797218972199722097221972229722397224972259722697227972289722997230972319723297233972349723597236972379723897239972409724197242972439724497245972469724797248972499725097251972529725397254972559725697257972589725997260972619726297263972649726597266972679726897269972709727197272972739727497275972769727797278972799728097281972829728397284972859728697287972889728997290972919729297293972949729597296972979729897299973009730197302973039730497305973069730797308973099731097311973129731397314973159731697317973189731997320973219732297323973249732597326973279732897329973309733197332973339733497335973369733797338973399734097341973429734397344973459734697347973489734997350973519735297353973549735597356973579735897359973609736197362973639736497365973669736797368973699737097371973729737397374973759737697377973789737997380973819738297383973849738597386973879738897389973909739197392973939739497395973969739797398973999740097401974029740397404974059740697407974089740997410974119741297413974149741597416974179741897419974209742197422974239742497425974269742797428974299743097431974329743397434974359743697437974389743997440974419744297443974449744597446974479744897449974509745197452974539745497455974569745797458974599746097461974629746397464974659746697467974689746997470974719747297473974749747597476974779747897479974809748197482974839748497485974869748797488974899749097491974929749397494974959749697497974989749997500975019750297503975049750597506975079750897509975109751197512975139751497515975169751797518975199752097521975229752397524975259752697527975289752997530975319753297533975349753597536975379753897539975409754197542975439754497545975469754797548975499755097551975529755397554975559755697557975589755997560975619756297563975649756597566975679756897569975709757197572975739757497575975769757797578975799758097581975829758397584975859758697587975889758997590975919759297593975949759597596975979759897599976009760197602976039760497605976069760797608976099761097611976129761397614976159761697617976189761997620976219762297623976249762597626976279762897629976309763197632976339763497635976369763797638976399764097641976429764397644976459764697647976489764997650976519765297653976549765597656976579765897659976609766197662976639766497665976669766797668976699767097671976729767397674976759767697677976789767997680976819768297683976849768597686976879768897689976909769197692976939769497695976969769797698976999770097701977029770397704977059770697707977089770997710977119771297713977149771597716977179771897719977209772197722977239772497725977269772797728977299773097731977329773397734977359773697737977389773997740977419774297743977449774597746977479774897749977509775197752977539775497755977569775797758977599776097761977629776397764977659776697767977689776997770977719777297773977749777597776977779777897779977809778197782977839778497785977869778797788977899779097791977929779397794977959779697797977989779997800978019780297803978049780597806978079780897809978109781197812978139781497815978169781797818978199782097821978229782397824978259782697827978289782997830978319783297833978349783597836978379783897839978409784197842978439784497845978469784797848978499785097851978529785397854978559785697857978589785997860978619786297863978649786597866978679786897869978709787197872978739787497875978769787797878978799788097881978829788397884978859788697887978889788997890978919789297893978949789597896978979789897899979009790197902979039790497905979069790797908979099791097911979129791397914979159791697917979189791997920979219792297923979249792597926979279792897929979309793197932979339793497935979369793797938979399794097941979429794397944979459794697947979489794997950979519795297953979549795597956979579795897959979609796197962979639796497965979669796797968979699797097971979729797397974979759797697977979789797997980979819798297983979849798597986979879798897989979909799197992979939799497995979969799797998979999800098001980029800398004980059800698007980089800998010980119801298013980149801598016980179801898019980209802198022980239802498025980269802798028980299803098031980329803398034980359803698037980389803998040980419804298043980449804598046980479804898049980509805198052980539805498055980569805798058980599806098061980629806398064980659806698067980689806998070980719807298073980749807598076980779807898079980809808198082980839808498085980869808798088980899809098091980929809398094980959809698097980989809998100981019810298103981049810598106981079810898109981109811198112981139811498115981169811798118981199812098121981229812398124981259812698127981289812998130981319813298133981349813598136981379813898139981409814198142981439814498145981469814798148981499815098151981529815398154981559815698157981589815998160981619816298163981649816598166981679816898169981709817198172981739817498175981769817798178981799818098181981829818398184981859818698187981889818998190981919819298193981949819598196981979819898199982009820198202982039820498205982069820798208982099821098211982129821398214982159821698217982189821998220982219822298223982249822598226982279822898229982309823198232982339823498235982369823798238982399824098241982429824398244982459824698247982489824998250982519825298253982549825598256982579825898259982609826198262982639826498265982669826798268982699827098271982729827398274982759827698277982789827998280982819828298283982849828598286982879828898289982909829198292982939829498295982969829798298982999830098301983029830398304983059830698307983089830998310983119831298313983149831598316983179831898319983209832198322983239832498325983269832798328983299833098331983329833398334983359833698337983389833998340983419834298343983449834598346983479834898349983509835198352983539835498355983569835798358983599836098361983629836398364983659836698367983689836998370983719837298373983749837598376983779837898379983809838198382983839838498385983869838798388983899839098391983929839398394983959839698397983989839998400984019840298403984049840598406984079840898409984109841198412984139841498415984169841798418984199842098421984229842398424984259842698427984289842998430984319843298433984349843598436984379843898439984409844198442984439844498445984469844798448984499845098451984529845398454984559845698457984589845998460984619846298463984649846598466984679846898469984709847198472984739847498475984769847798478984799848098481984829848398484984859848698487984889848998490984919849298493984949849598496984979849898499985009850198502985039850498505985069850798508985099851098511985129851398514985159851698517985189851998520985219852298523985249852598526985279852898529985309853198532985339853498535985369853798538985399854098541985429854398544985459854698547985489854998550985519855298553985549855598556985579855898559985609856198562985639856498565985669856798568985699857098571985729857398574985759857698577985789857998580985819858298583985849858598586985879858898589985909859198592985939859498595985969859798598985999860098601986029860398604986059860698607986089860998610986119861298613986149861598616986179861898619986209862198622986239862498625986269862798628986299863098631986329863398634986359863698637986389863998640986419864298643986449864598646986479864898649986509865198652986539865498655986569865798658986599866098661986629866398664986659866698667986689866998670986719867298673986749867598676986779867898679986809868198682986839868498685986869868798688986899869098691986929869398694986959869698697986989869998700987019870298703987049870598706987079870898709987109871198712987139871498715987169871798718987199872098721987229872398724987259872698727987289872998730987319873298733987349873598736987379873898739987409874198742987439874498745987469874798748987499875098751987529875398754987559875698757987589875998760987619876298763987649876598766987679876898769987709877198772987739877498775987769877798778987799878098781987829878398784987859878698787987889878998790987919879298793987949879598796987979879898799988009880198802988039880498805988069880798808988099881098811988129881398814988159881698817988189881998820988219882298823988249882598826988279882898829988309883198832988339883498835988369883798838988399884098841988429884398844988459884698847988489884998850988519885298853988549885598856988579885898859988609886198862988639886498865988669886798868988699887098871988729887398874988759887698877988789887998880988819888298883988849888598886988879888898889988909889198892988939889498895988969889798898988999890098901989029890398904989059890698907989089890998910989119891298913989149891598916989179891898919989209892198922989239892498925989269892798928989299893098931989329893398934989359893698937989389893998940989419894298943989449894598946989479894898949989509895198952989539895498955989569895798958989599896098961989629896398964989659896698967989689896998970989719897298973989749897598976989779897898979989809898198982989839898498985989869898798988989899899098991989929899398994989959899698997989989899999000990019900299003990049900599006990079900899009990109901199012990139901499015990169901799018990199902099021990229902399024990259902699027990289902999030990319903299033990349903599036990379903899039990409904199042990439904499045990469904799048990499905099051990529905399054990559905699057990589905999060990619906299063990649906599066990679906899069990709907199072990739907499075990769907799078990799908099081990829908399084990859908699087990889908999090990919909299093990949909599096990979909899099991009910199102991039910499105991069910799108991099911099111991129911399114991159911699117991189911999120991219912299123991249912599126991279912899129991309913199132991339913499135991369913799138991399914099141991429914399144991459914699147991489914999150991519915299153991549915599156991579915899159991609916199162991639916499165991669916799168991699917099171991729917399174991759917699177991789917999180991819918299183991849918599186991879918899189991909919199192991939919499195991969919799198991999920099201992029920399204992059920699207992089920999210992119921299213992149921599216992179921899219992209922199222992239922499225992269922799228992299923099231992329923399234992359923699237992389923999240992419924299243992449924599246992479924899249992509925199252992539925499255992569925799258992599926099261992629926399264992659926699267992689926999270992719927299273992749927599276992779927899279992809928199282992839928499285992869928799288992899929099291992929929399294992959929699297992989929999300993019930299303993049930599306993079930899309993109931199312993139931499315993169931799318993199932099321993229932399324993259932699327993289932999330993319933299333993349933599336993379933899339993409934199342993439934499345993469934799348993499935099351993529935399354993559935699357993589935999360993619936299363993649936599366993679936899369993709937199372993739937499375993769937799378993799938099381993829938399384993859938699387993889938999390993919939299393993949939599396993979939899399994009940199402994039940499405994069940799408994099941099411994129941399414994159941699417994189941999420994219942299423994249942599426994279942899429994309943199432994339943499435994369943799438994399944099441994429944399444994459944699447994489944999450994519945299453994549945599456994579945899459994609946199462994639946499465994669946799468994699947099471994729947399474994759947699477994789947999480994819948299483994849948599486994879948899489994909949199492994939949499495994969949799498994999950099501995029950399504995059950699507995089950999510995119951299513995149951599516995179951899519995209952199522995239952499525995269952799528995299953099531995329953399534995359953699537995389953999540995419954299543995449954599546995479954899549995509955199552995539955499555995569955799558995599956099561995629956399564995659956699567995689956999570995719957299573995749957599576995779957899579995809958199582995839958499585995869958799588995899959099591995929959399594995959959699597995989959999600996019960299603996049960599606996079960899609996109961199612996139961499615996169961799618996199962099621996229962399624996259962699627996289962999630996319963299633996349963599636996379963899639996409964199642996439964499645996469964799648996499965099651996529965399654996559965699657996589965999660996619966299663996649966599666996679966899669996709967199672996739967499675996769967799678996799968099681996829968399684996859968699687996889968999690996919969299693996949969599696996979969899699997009970199702997039970499705997069970799708997099971099711997129971399714997159971699717997189971999720997219972299723997249972599726997279972899729997309973199732997339973499735997369973799738997399974099741997429974399744997459974699747997489974999750997519975299753997549975599756997579975899759997609976199762997639976499765997669976799768997699977099771997729977399774997759977699777997789977999780997819978299783997849978599786997879978899789997909979199792997939979499795997969979799798997999980099801998029980399804998059980699807998089980999810998119981299813998149981599816998179981899819998209982199822998239982499825998269982799828998299983099831998329983399834998359983699837998389983999840998419984299843998449984599846998479984899849998509985199852998539985499855998569985799858998599986099861998629986399864998659986699867998689986999870998719987299873998749987599876998779987899879998809988199882998839988499885998869988799888998899989099891998929989399894998959989699897998989989999900999019990299903999049990599906999079990899909999109991199912999139991499915999169991799918999199992099921999229992399924999259992699927999289992999930999319993299933999349993599936999379993899939999409994199942999439994499945999469994799948999499995099951999529995399954999559995699957999589995999960999619996299963999649996599966999679996899969999709997199972999739997499975999769997799978999799998099981999829998399984999859998699987999889998999990999919999299993999949999599996999979999899999100000100001100002100003100004100005100006100007100008100009100010100011100012100013100014100015100016100017100018100019100020100021100022100023100024100025100026100027100028100029100030100031100032100033100034100035100036100037100038100039100040100041100042100043100044100045100046100047100048100049100050100051100052100053100054100055100056100057100058100059100060100061100062100063100064100065100066100067100068100069100070100071100072100073100074100075100076100077100078100079100080100081100082100083100084100085100086100087100088100089100090100091100092100093100094100095100096100097100098100099100100100101100102100103100104100105100106100107100108100109100110100111100112100113100114100115100116100117100118100119100120100121100122100123100124100125100126100127100128100129100130100131100132100133100134100135100136100137100138100139100140100141100142100143100144100145100146100147100148100149100150100151100152100153100154100155100156100157100158100159100160100161100162100163100164100165100166100167100168100169100170100171100172100173100174100175100176100177100178100179100180100181100182100183100184100185100186100187100188100189100190100191100192100193100194100195100196100197100198100199100200100201100202100203100204100205100206100207100208100209100210100211100212100213100214100215100216100217100218100219100220100221100222100223100224100225100226100227100228100229100230100231100232100233100234100235100236100237100238100239100240100241100242100243100244100245100246100247100248100249100250100251100252100253100254100255100256100257100258100259100260100261100262100263100264100265100266100267100268100269100270100271100272100273100274100275100276100277100278100279100280100281100282100283100284100285100286100287100288100289100290100291100292100293100294100295100296100297100298100299100300100301100302100303100304100305100306100307100308100309100310100311100312100313100314100315100316100317100318100319100320100321100322100323100324100325100326100327100328100329100330100331100332100333100334100335100336100337100338100339100340100341100342100343100344100345100346100347100348100349100350100351100352100353100354100355100356100357100358100359100360100361100362100363100364100365100366100367100368100369100370100371100372100373100374100375100376100377100378100379100380100381100382100383100384100385100386100387100388100389100390100391100392100393100394100395100396100397100398100399100400100401100402100403100404100405100406100407100408100409100410100411100412100413100414100415100416100417100418100419100420100421100422100423100424100425100426100427100428100429100430100431100432100433100434100435100436100437100438100439100440100441100442100443100444100445100446100447100448100449100450100451100452100453100454100455100456100457100458100459100460100461100462100463100464100465100466100467100468100469100470100471100472100473100474100475100476100477100478100479100480100481100482100483100484100485100486100487100488100489100490100491100492100493100494100495100496100497100498100499100500100501100502100503100504100505100506100507100508100509100510100511100512100513100514100515100516100517100518100519100520100521100522100523100524100525100526100527100528100529100530100531100532100533100534100535100536100537100538100539100540100541100542100543100544100545100546100547100548100549100550100551100552100553100554100555100556100557100558100559100560100561100562100563100564100565100566100567100568100569100570100571100572100573100574100575100576100577100578100579100580100581100582100583100584100585100586100587100588100589100590100591100592100593100594100595100596100597100598100599100600100601100602100603100604100605100606100607100608100609100610100611100612100613100614100615100616100617100618100619100620100621100622100623100624100625100626100627100628100629100630100631100632100633100634100635100636100637100638100639100640100641100642100643100644100645100646100647100648100649100650100651100652100653100654100655100656100657100658100659100660100661100662100663100664100665100666100667100668100669100670100671100672100673100674100675100676100677100678100679100680100681100682100683100684100685100686100687100688100689100690100691100692100693100694100695100696100697100698100699100700100701100702100703100704100705100706100707100708100709100710100711100712100713100714100715100716100717100718100719100720100721100722100723100724100725100726100727100728100729100730100731100732100733100734100735100736100737100738100739100740100741100742100743100744100745100746100747100748100749100750100751100752100753100754100755100756100757100758100759100760100761100762100763100764100765100766100767100768100769100770100771100772100773100774100775100776100777100778100779100780100781100782100783100784100785100786100787100788100789100790100791100792100793100794100795100796100797100798100799100800100801100802100803100804100805100806100807100808100809100810100811100812100813100814100815100816100817100818100819100820100821100822100823100824100825100826100827100828100829100830100831100832100833100834100835100836100837100838100839100840100841100842100843100844100845100846100847100848100849100850100851100852100853100854100855100856100857100858100859100860100861100862100863100864100865100866100867100868100869100870100871100872100873100874100875100876100877100878100879100880100881100882100883100884100885100886100887100888100889100890100891100892100893100894100895100896100897100898100899100900100901100902100903100904100905100906100907100908100909100910100911100912100913100914100915100916100917100918100919100920100921100922100923100924100925100926100927100928100929100930100931100932100933100934100935100936100937100938100939100940100941100942100943100944100945100946100947100948100949100950100951100952100953100954100955100956100957100958100959100960100961100962100963100964100965100966100967100968100969100970100971100972100973100974100975100976100977100978100979100980100981100982100983100984100985100986100987100988100989100990100991100992100993100994100995100996100997100998100999101000101001101002101003101004101005101006101007101008101009101010101011101012101013101014101015101016101017101018101019101020101021101022101023101024101025101026101027101028101029101030101031101032101033101034101035101036101037101038101039101040101041101042101043101044101045101046101047101048101049101050101051101052101053101054101055101056101057101058101059101060101061101062101063101064101065101066101067101068101069101070101071101072101073101074101075101076101077101078101079101080101081101082101083101084101085101086101087101088101089101090101091101092101093101094101095101096101097101098101099101100101101101102101103101104101105101106101107101108101109101110101111101112101113101114101115101116101117101118101119101120101121101122101123101124101125101126101127101128101129101130101131101132101133101134101135101136101137101138101139101140101141101142101143101144101145101146101147101148101149101150101151101152101153101154101155101156101157101158101159101160101161101162101163101164101165101166101167101168101169101170101171101172101173101174101175101176101177101178101179101180101181101182101183101184101185101186101187101188101189101190101191101192101193101194101195101196101197101198101199101200101201101202101203101204101205101206101207101208101209101210101211101212101213101214101215101216101217101218101219101220101221101222101223101224101225101226101227101228101229101230101231101232101233101234101235101236101237101238101239101240101241101242101243101244101245101246101247101248101249101250101251101252101253101254101255101256101257101258101259101260101261101262101263101264101265101266101267101268101269101270101271101272101273101274101275101276101277101278101279101280101281101282101283101284101285101286101287101288101289101290101291101292101293101294101295101296101297101298101299101300101301101302101303101304101305101306101307101308101309101310101311101312101313101314101315101316101317101318101319101320101321101322101323101324101325101326101327101328101329101330101331101332101333101334101335101336101337101338101339101340101341101342101343101344101345101346101347101348101349101350101351101352101353101354101355101356101357101358101359101360101361101362101363101364101365101366101367101368101369101370101371101372101373101374101375101376101377101378101379101380101381101382101383101384101385101386101387101388101389101390101391101392101393101394101395101396101397101398101399101400101401101402101403101404101405101406101407101408101409101410101411101412101413101414101415101416101417101418101419101420101421101422101423101424101425101426101427101428101429101430101431101432101433101434101435101436101437101438101439101440101441101442101443101444101445101446101447101448101449101450101451101452101453101454101455101456101457101458101459101460101461101462101463101464101465101466101467101468101469101470101471101472101473101474101475101476101477101478101479101480101481101482101483101484101485101486101487101488101489101490101491101492101493101494101495101496101497101498101499101500101501101502101503101504101505101506101507101508101509101510101511101512101513101514101515101516101517101518101519101520101521101522101523101524101525101526101527101528101529101530101531101532101533101534101535101536101537101538101539101540101541101542101543101544101545101546101547101548101549101550101551101552101553101554101555101556101557101558101559101560101561101562101563101564101565101566101567101568101569101570101571101572101573101574101575101576101577101578101579101580101581101582101583101584101585101586101587101588101589101590101591101592101593101594101595101596101597101598101599101600101601101602101603101604101605101606101607101608101609101610101611101612101613101614101615101616101617101618101619101620101621101622101623101624101625101626101627101628101629101630101631101632101633101634101635101636101637101638101639101640101641101642101643101644101645101646101647101648101649101650101651101652101653101654101655101656101657101658101659101660101661101662101663101664101665101666101667101668101669101670101671101672101673101674101675101676101677101678101679101680101681101682101683101684101685101686101687101688101689101690101691101692101693101694101695101696101697101698101699101700101701101702101703101704101705101706101707101708101709101710101711101712101713101714101715101716101717101718101719101720101721101722101723101724101725101726101727101728101729101730101731101732101733101734101735101736101737101738101739101740101741101742101743101744101745101746101747101748101749101750101751101752101753101754101755101756101757101758101759101760101761101762101763101764101765101766101767101768101769101770101771101772101773101774101775101776101777101778101779101780101781101782101783101784101785101786101787101788101789101790101791101792101793101794101795101796101797101798101799101800101801101802101803101804101805101806101807101808101809101810101811101812101813101814101815101816101817101818101819101820101821101822101823101824101825101826101827101828101829101830101831101832101833101834101835101836101837101838101839101840101841101842101843101844101845101846101847101848101849101850101851101852101853101854101855101856101857101858101859101860101861101862101863101864101865101866101867101868101869101870101871101872101873101874101875101876101877101878101879101880101881101882101883101884101885101886101887101888101889101890101891101892101893101894101895101896101897101898101899101900101901101902101903101904101905101906101907101908101909101910101911101912101913101914101915101916101917101918101919101920101921101922101923101924101925101926101927101928101929101930101931101932101933101934101935101936101937101938101939101940101941101942101943101944101945101946101947101948101949101950101951101952101953101954101955101956101957101958101959101960101961101962101963101964101965101966101967101968101969101970101971101972101973101974101975101976101977101978101979101980101981101982101983101984101985101986101987101988101989101990101991101992101993101994101995101996101997101998101999102000102001102002102003102004102005102006102007102008102009102010102011102012102013102014102015102016102017102018102019102020102021102022102023102024102025102026102027102028102029102030102031102032102033102034102035102036102037102038102039102040102041102042102043102044102045102046102047102048102049102050102051102052102053102054102055102056102057102058102059102060102061102062102063102064102065102066102067102068102069102070102071102072102073102074102075102076102077102078102079102080102081102082102083102084102085102086102087102088102089102090102091102092102093102094102095102096102097102098102099102100102101102102102103102104102105102106102107102108102109102110102111102112102113102114102115102116102117102118102119102120102121102122102123102124102125102126102127102128102129102130102131102132102133102134102135102136102137102138102139102140102141102142102143102144102145102146102147102148102149102150102151102152102153102154102155102156102157102158102159102160102161102162102163102164102165102166102167102168102169102170102171102172102173102174102175102176102177102178102179102180102181102182102183102184102185102186102187102188102189102190102191102192102193102194102195102196102197102198102199102200102201102202102203102204102205102206102207102208102209102210102211102212102213102214102215102216102217102218102219102220102221102222102223102224102225102226102227102228102229102230102231102232102233102234102235102236102237102238102239102240102241102242102243102244102245102246102247102248102249102250102251102252102253102254102255102256102257102258102259102260102261102262102263102264102265102266102267102268102269102270102271102272102273102274102275102276102277102278102279102280102281102282102283102284102285102286102287102288102289102290102291102292102293102294102295102296102297102298102299102300102301102302102303102304102305102306102307102308102309102310102311102312102313102314102315102316102317102318102319102320102321102322102323102324102325102326102327102328102329102330102331102332102333102334102335102336102337102338102339102340102341102342102343102344102345102346102347102348102349102350102351102352102353102354102355102356102357102358102359102360102361102362102363102364102365102366102367102368102369102370102371102372102373102374102375102376102377102378102379102380102381102382102383102384102385102386102387102388102389102390102391102392102393102394102395102396102397102398102399102400102401102402102403102404102405102406102407102408102409102410102411102412102413102414102415102416102417102418102419102420102421102422102423102424102425102426102427102428102429102430102431102432102433102434102435102436102437102438102439102440102441102442102443102444102445102446102447102448102449102450102451102452102453102454102455102456102457102458102459102460102461102462102463102464102465102466102467102468102469102470102471102472102473102474102475102476102477102478102479102480102481102482102483102484102485102486102487102488102489102490102491102492102493102494102495102496102497102498102499102500102501102502102503102504102505102506102507102508102509102510102511102512102513102514102515102516102517102518102519102520102521102522102523102524102525102526102527102528102529102530102531102532102533102534102535102536102537102538102539102540102541102542102543102544102545102546102547102548102549102550102551102552102553102554102555102556102557102558102559102560102561102562102563102564102565102566102567102568102569102570102571102572102573102574102575102576102577102578102579102580102581102582102583102584102585102586102587102588102589102590102591102592102593102594102595102596102597102598102599102600102601102602102603102604102605102606102607102608102609102610102611102612102613102614102615102616102617102618102619102620102621102622102623102624102625102626102627102628102629102630102631102632102633102634102635102636102637102638102639102640102641102642102643102644102645102646102647102648102649102650102651102652102653102654102655102656102657102658102659102660102661102662102663102664102665102666102667102668102669102670102671102672102673102674102675102676102677102678102679102680102681102682102683102684102685102686102687102688102689102690102691102692102693102694102695102696102697102698102699102700102701102702102703102704102705102706102707102708102709102710102711102712102713102714102715102716102717102718102719102720102721102722102723102724102725102726102727102728102729102730102731102732102733102734102735102736102737102738102739102740102741102742102743102744102745102746102747102748102749102750102751102752102753102754102755102756102757102758102759102760102761102762102763102764102765102766102767102768102769102770102771102772102773102774102775102776102777102778102779102780102781102782102783102784102785102786102787102788102789102790102791102792102793102794102795102796102797102798102799102800102801102802102803102804102805102806102807102808102809102810102811102812102813102814102815102816102817102818102819102820102821102822102823102824102825102826102827102828102829102830102831102832102833102834102835102836102837102838102839102840102841102842102843102844102845102846102847102848102849102850102851102852102853102854102855102856102857102858102859102860102861102862102863102864102865102866102867102868102869102870102871102872102873102874102875102876102877102878102879102880102881102882102883102884102885102886102887102888102889102890102891102892102893102894102895102896102897102898102899102900102901102902102903102904102905102906102907102908102909102910102911102912102913102914102915102916102917102918102919102920102921102922102923102924102925102926102927102928102929102930102931102932102933102934102935102936102937102938102939102940102941102942102943102944102945102946102947102948102949102950102951102952102953102954102955102956102957102958102959102960102961102962102963102964102965102966102967102968102969102970102971102972102973102974102975102976102977102978102979102980102981102982102983102984102985102986102987102988102989102990102991102992102993102994102995102996102997102998102999103000103001103002103003103004103005103006103007103008103009103010103011103012103013103014103015103016103017103018103019103020103021103022103023103024103025103026103027103028103029103030103031103032103033103034103035103036103037103038103039103040103041103042103043103044103045103046103047103048103049103050103051103052103053103054103055103056103057103058103059103060103061103062103063103064103065103066103067103068103069103070103071103072103073103074103075103076103077103078103079103080103081103082103083103084103085103086103087103088103089103090103091103092103093103094103095103096103097103098103099103100103101103102103103103104103105103106103107103108103109103110103111103112103113103114103115103116103117103118103119103120103121103122103123103124103125103126103127103128103129103130103131103132103133103134103135103136103137103138103139103140103141103142103143103144103145103146103147103148103149103150103151103152103153103154103155103156103157103158103159103160103161103162103163103164103165103166103167103168103169103170103171103172103173103174103175103176103177103178103179103180103181103182103183103184103185103186103187103188103189103190103191103192103193103194103195103196103197103198103199103200103201103202103203103204103205103206103207103208103209103210103211103212103213103214103215103216103217103218103219103220103221103222103223103224103225103226103227103228103229103230103231103232103233103234103235103236103237103238103239103240103241103242103243103244103245103246103247103248103249103250103251103252103253103254103255103256103257103258103259103260103261103262103263103264103265103266103267103268103269103270103271103272103273103274103275103276103277103278103279103280103281103282103283103284103285103286103287103288103289103290103291103292103293103294103295103296103297103298103299103300103301103302103303103304103305103306103307103308103309103310103311103312103313103314103315103316103317103318103319103320103321103322103323103324103325103326103327103328103329103330103331103332103333103334103335103336103337103338103339103340103341103342103343103344103345103346103347103348103349103350103351103352103353103354103355103356103357103358103359103360103361103362103363103364103365103366103367103368103369103370103371103372103373103374103375103376103377103378103379103380103381103382103383103384103385103386103387103388103389103390103391103392103393103394103395103396103397103398103399103400103401103402103403103404103405103406103407103408103409103410103411103412103413103414103415103416103417103418103419103420103421103422103423103424103425103426103427103428103429103430103431103432103433103434103435103436103437103438103439103440103441103442103443103444103445103446103447103448103449103450103451103452103453103454103455103456103457103458103459103460103461103462103463103464103465103466103467103468103469103470103471103472103473103474103475103476103477103478103479103480103481103482103483103484103485103486103487103488103489103490103491103492103493103494103495103496103497103498103499103500103501103502103503103504103505103506103507103508103509103510103511103512103513103514103515103516103517103518103519103520103521103522103523103524103525103526103527103528103529103530103531103532103533103534103535103536103537103538103539103540103541103542103543103544103545103546103547103548103549103550103551103552103553103554103555103556103557103558103559103560103561103562103563103564103565103566103567103568103569103570103571103572103573103574103575103576103577103578103579103580103581103582103583103584103585103586103587103588103589103590103591103592103593103594103595103596103597103598103599103600103601103602103603103604103605103606103607103608103609103610103611103612103613103614103615103616103617103618103619103620103621103622103623103624103625103626103627103628103629103630103631103632103633103634103635103636103637103638103639103640103641103642103643103644103645103646103647103648103649103650103651103652103653103654103655103656103657103658103659103660103661103662103663103664103665103666103667103668103669103670103671103672103673103674103675103676103677103678103679103680103681103682103683103684103685103686103687103688103689103690103691103692103693103694103695103696103697103698103699103700103701103702103703103704103705103706103707103708103709103710103711103712103713103714103715103716103717103718103719103720103721103722103723103724103725103726103727103728103729103730103731103732103733103734103735103736103737103738103739103740103741103742103743103744103745103746103747103748103749103750103751103752103753103754103755103756103757103758103759103760103761103762103763103764103765103766103767103768103769103770103771103772103773103774103775103776103777103778103779103780103781103782103783103784103785103786103787103788103789103790103791103792103793103794103795103796103797103798103799103800103801103802103803103804103805103806103807103808103809103810103811103812103813103814103815103816103817103818103819103820103821103822103823103824103825103826103827103828103829103830103831103832103833103834103835103836103837103838103839103840103841103842103843103844103845103846103847103848103849103850103851103852103853103854103855103856103857103858103859103860103861103862103863103864103865103866103867103868103869103870103871103872103873103874103875103876103877103878103879103880103881103882103883103884103885103886103887103888103889103890103891103892103893103894103895103896103897103898103899103900103901103902103903103904103905103906103907103908103909103910103911103912103913103914103915103916103917103918103919103920103921103922103923103924103925103926103927103928103929103930103931103932103933103934103935103936103937103938103939103940103941103942103943103944103945103946103947103948103949103950103951103952103953103954103955103956103957103958103959103960103961103962103963103964103965103966103967103968103969103970103971103972103973103974103975103976103977103978103979103980103981103982103983103984103985103986103987103988103989103990103991103992103993103994103995103996103997103998103999104000104001104002104003104004104005104006104007104008104009104010104011104012104013104014104015104016104017104018104019104020104021104022104023104024104025104026104027104028104029104030104031104032104033104034104035104036104037104038104039104040104041104042104043104044104045104046104047104048104049104050104051104052104053104054104055104056104057104058104059104060104061104062104063104064104065104066104067104068104069104070104071104072104073104074104075104076104077104078104079104080104081104082104083104084104085104086104087104088104089104090104091104092104093104094104095104096104097104098104099104100104101104102104103104104104105104106104107104108104109104110104111104112104113104114104115104116104117104118104119104120104121104122104123104124104125104126104127104128104129104130104131104132104133104134104135104136104137104138104139104140104141104142104143104144104145104146104147104148104149104150104151104152104153104154104155104156104157104158104159104160104161104162104163104164104165104166104167104168104169104170104171104172104173104174104175104176104177104178104179104180104181104182104183104184104185104186104187104188104189104190104191104192104193104194104195104196104197104198104199104200104201104202104203104204104205104206104207104208104209104210104211104212104213104214104215104216104217104218104219104220104221104222104223104224104225104226104227104228104229104230104231104232104233104234104235104236104237104238104239104240104241104242104243104244104245104246104247104248104249104250104251104252104253104254104255104256104257104258104259104260104261104262104263104264104265104266104267104268104269104270104271104272104273104274104275104276104277104278104279104280104281104282104283104284104285104286104287104288104289104290104291104292104293104294104295104296104297104298104299104300104301104302104303104304104305104306104307104308104309104310104311104312104313104314104315104316104317104318104319104320104321104322104323104324104325104326104327104328104329104330104331104332104333104334104335104336104337104338104339104340104341104342104343104344104345104346104347104348104349104350104351104352104353104354104355104356104357104358104359104360104361104362104363104364104365104366104367104368104369104370104371104372104373104374104375104376104377104378104379104380104381104382104383104384104385104386104387104388104389104390104391104392104393104394104395104396104397104398104399104400104401104402104403104404104405104406104407104408104409104410104411104412104413104414104415104416104417104418104419104420104421104422104423104424104425104426104427104428104429104430104431104432104433104434104435104436104437104438104439104440104441104442104443104444104445104446104447104448104449104450104451104452104453104454104455104456104457104458104459104460104461104462104463104464104465104466104467104468104469104470104471104472104473104474104475104476104477104478104479104480104481104482104483104484104485104486104487104488104489104490104491104492104493104494104495104496104497104498104499104500104501104502104503104504104505104506104507104508104509104510104511104512104513104514104515104516104517104518104519104520104521104522104523104524104525104526104527104528104529104530104531104532104533104534104535104536104537104538104539104540104541104542104543104544104545104546104547104548104549104550104551104552104553104554104555104556104557104558104559104560104561104562104563104564104565104566104567104568104569104570104571104572104573104574104575104576104577104578104579104580104581104582104583104584104585104586104587104588104589104590104591104592104593104594104595104596104597104598104599104600104601104602104603104604104605104606104607104608104609104610104611104612104613104614104615104616104617104618104619104620104621104622104623104624104625104626104627104628104629104630104631104632104633104634104635104636104637104638104639104640104641104642104643104644104645104646104647104648104649104650104651104652104653104654104655104656104657104658104659104660104661104662104663104664104665104666104667104668104669104670104671104672104673104674104675104676104677104678104679104680104681104682104683104684104685104686104687104688104689104690104691104692104693104694104695104696104697104698104699104700104701104702104703104704104705104706104707104708104709104710104711104712104713104714104715104716104717104718104719104720104721104722104723104724104725104726104727104728104729104730104731104732104733104734104735104736104737104738104739104740104741104742104743104744104745104746104747104748104749104750104751104752104753104754104755104756104757104758104759104760104761104762104763104764104765104766104767104768104769104770104771104772104773104774104775104776104777104778104779104780104781104782104783104784104785104786104787104788104789104790104791104792104793104794104795104796104797104798104799104800104801104802104803104804104805104806104807104808104809104810104811104812104813104814104815104816104817104818104819104820104821104822104823104824104825104826104827104828104829104830104831104832104833104834104835104836104837104838104839104840104841104842104843104844104845104846104847104848104849104850104851104852104853104854104855104856104857104858104859104860104861104862104863104864104865104866104867104868104869104870104871104872104873104874104875104876104877104878104879104880104881104882104883104884104885104886104887104888104889104890104891104892104893104894104895104896104897104898104899104900104901104902104903104904104905104906104907104908104909104910104911104912104913104914104915104916104917104918104919104920104921104922104923104924104925104926104927104928104929104930104931104932104933104934104935104936104937104938104939104940104941104942104943104944104945104946104947104948104949104950104951104952104953104954104955104956104957104958104959104960104961104962104963104964104965104966104967104968104969104970104971104972104973104974104975104976104977104978104979104980104981104982104983104984104985104986104987104988104989104990104991104992104993104994104995104996104997104998104999105000105001105002105003105004105005105006105007105008105009105010105011105012105013105014105015105016105017105018105019105020105021105022105023105024105025105026105027105028105029105030105031105032105033105034105035105036105037105038105039105040105041105042105043105044105045105046105047105048105049105050105051105052105053105054105055105056105057105058105059105060105061105062105063105064105065105066105067105068105069105070105071105072105073105074105075105076105077105078105079105080105081105082105083105084105085105086105087105088105089105090105091105092105093105094105095105096105097105098105099105100105101105102105103105104105105105106105107105108105109105110105111105112105113105114105115105116105117105118105119105120105121105122105123105124105125105126105127105128105129105130105131105132105133105134105135105136105137105138105139105140105141105142105143105144105145105146105147105148105149105150105151105152105153105154105155105156105157105158105159105160105161105162105163105164105165105166105167105168105169105170105171105172105173105174105175105176105177105178105179105180105181105182105183105184105185105186105187105188105189105190105191105192105193105194105195105196105197105198105199105200105201105202105203105204105205105206105207105208105209105210105211105212105213105214105215105216105217105218105219105220105221105222105223105224105225105226105227105228105229105230105231105232105233105234105235105236105237105238105239105240105241105242105243105244105245105246105247105248105249105250105251105252105253105254105255105256105257105258105259105260105261105262105263105264105265105266105267105268105269105270105271105272105273105274105275105276105277105278105279105280105281105282105283105284105285105286105287105288105289105290105291105292105293105294105295105296105297105298105299105300105301105302105303105304105305105306105307105308105309105310105311105312105313105314105315105316105317105318105319105320105321105322105323105324105325105326105327105328105329105330105331105332105333105334105335105336105337105338105339105340105341105342105343105344105345105346105347105348105349105350105351105352105353105354105355105356105357105358105359105360105361105362105363105364105365105366105367105368105369105370105371105372105373105374105375105376105377105378105379105380105381105382105383105384105385105386105387105388105389105390105391105392105393105394105395105396105397105398105399105400105401105402105403105404105405105406105407105408105409105410105411105412105413105414105415105416105417105418105419105420105421105422105423105424105425105426105427105428105429105430105431105432105433105434105435105436105437105438105439105440105441105442105443105444105445105446105447105448105449105450105451105452105453105454105455105456105457105458105459105460105461105462105463105464105465105466105467105468105469105470105471105472105473105474105475105476105477105478105479105480105481105482105483105484105485105486105487105488105489105490105491105492105493105494105495105496105497105498105499105500105501105502105503105504105505105506105507105508105509105510105511105512105513105514105515105516105517105518105519105520105521105522105523105524105525105526105527105528105529105530105531105532105533105534105535105536105537105538105539105540105541105542105543105544105545105546105547105548105549105550105551105552105553105554105555105556105557105558105559105560105561105562105563105564105565105566105567105568105569105570105571105572105573105574105575105576105577105578105579105580105581105582105583105584105585105586105587105588105589105590105591105592105593105594105595105596105597105598105599105600105601105602105603105604105605105606105607105608105609105610105611105612105613105614105615105616105617105618105619105620105621105622105623105624105625105626105627105628105629105630105631105632105633105634105635105636105637105638105639105640105641105642105643105644105645105646105647105648105649105650105651105652105653105654105655105656105657105658105659105660105661105662105663105664105665105666105667105668105669105670105671105672105673105674105675105676105677105678105679105680105681105682105683105684105685105686105687105688105689105690105691105692105693105694105695105696105697105698105699105700105701105702105703105704105705105706105707105708105709105710105711105712105713105714105715105716105717105718105719105720105721105722105723105724105725105726105727105728105729105730105731105732105733105734105735105736105737105738105739105740105741105742105743105744105745105746105747105748105749105750105751105752105753105754105755105756105757105758105759105760105761105762105763105764105765105766105767105768105769105770105771105772105773105774105775105776105777105778105779105780105781105782105783105784105785105786105787105788105789105790105791105792105793105794105795105796105797105798105799105800105801105802105803105804105805105806105807105808105809105810105811105812105813105814105815105816105817105818105819105820105821105822105823105824105825105826105827105828105829105830105831105832105833105834105835105836105837105838105839105840105841105842105843105844105845105846105847105848105849105850105851105852105853105854105855105856105857105858105859105860105861105862105863105864105865105866105867105868105869105870105871105872105873105874105875105876105877105878105879105880105881105882105883105884105885105886105887105888105889105890105891105892105893105894105895105896105897105898105899105900105901105902105903105904105905105906105907105908105909105910105911105912105913105914105915105916105917105918105919105920105921105922105923105924105925105926105927105928105929105930105931105932105933105934105935105936105937105938105939105940105941105942105943105944105945105946105947105948105949105950105951105952105953105954105955105956105957105958105959105960105961105962105963105964105965105966105967105968105969105970105971105972105973105974105975105976105977105978105979105980105981105982105983105984105985105986105987105988105989105990105991105992105993105994105995105996105997105998105999106000106001106002106003106004106005106006106007106008106009106010106011106012106013106014106015106016106017106018106019106020106021106022106023106024106025106026106027106028106029106030106031106032106033106034106035106036106037106038106039106040106041106042106043106044106045106046106047106048106049106050106051106052106053106054106055106056106057106058106059106060106061106062106063106064106065106066106067106068106069106070106071106072106073106074106075106076106077106078106079106080106081106082106083106084106085106086106087106088106089106090106091106092106093106094106095106096106097106098106099106100106101106102106103106104106105106106106107106108106109106110106111106112106113106114106115106116106117106118106119106120106121106122106123106124106125106126106127106128106129106130106131106132106133106134106135106136106137106138106139106140106141106142106143106144106145106146106147106148106149106150106151106152106153106154106155106156106157106158106159106160106161106162106163106164106165106166106167106168106169106170106171106172106173106174106175106176106177106178106179106180106181106182106183106184106185106186106187106188106189106190106191106192106193106194106195106196106197106198106199106200106201106202106203106204106205106206106207106208106209106210106211106212106213106214106215106216106217106218106219106220106221106222106223106224106225106226106227106228106229106230106231106232106233106234106235106236106237106238106239106240106241106242106243106244106245106246106247106248106249106250106251106252106253106254106255106256106257106258106259106260106261106262106263106264106265106266106267106268106269106270106271106272106273106274106275106276106277106278106279106280106281106282106283106284106285106286106287106288106289106290106291106292106293106294106295106296106297106298106299106300106301106302106303106304106305106306106307106308106309106310106311106312106313106314106315106316106317106318106319106320106321106322106323106324106325106326106327106328106329106330
  1. diff -Nur linux-3.12.26.orig/arch/arc/boot/dts/nsimosci.dts linux-3.12.26/arch/arc/boot/dts/nsimosci.dts
  2. --- linux-3.12.26.orig/arch/arc/boot/dts/nsimosci.dts 2014-07-30 18:02:44.000000000 +0200
  3. +++ linux-3.12.26/arch/arc/boot/dts/nsimosci.dts 2014-08-06 16:50:13.737956371 +0200
  4. @@ -11,16 +11,13 @@
  5. / {
  6. compatible = "snps,nsimosci";
  7. - clock-frequency = <20000000>; /* 20 MHZ */
  8. + clock-frequency = <80000000>; /* 80 MHZ */
  9. #address-cells = <1>;
  10. #size-cells = <1>;
  11. interrupt-parent = <&intc>;
  12. chosen {
  13. - /* this is for console on PGU */
  14. - /* bootargs = "console=tty0 consoleblank=0"; */
  15. - /* this is for console on serial */
  16. - bootargs = "earlycon=uart8250,mmio32,0xc0000000,115200n8 console=ttyS0,115200n8 consoleblank=0 debug";
  17. + bootargs = "console=tty0 consoleblank=0";
  18. };
  19. aliases {
  20. @@ -47,14 +44,15 @@
  21. };
  22. uart0: serial@c0000000 {
  23. - compatible = "ns8250";
  24. + compatible = "snps,dw-apb-uart";
  25. reg = <0xc0000000 0x2000>;
  26. interrupts = <11>;
  27. + #clock-frequency = <80000000>;
  28. clock-frequency = <3686400>;
  29. baud = <115200>;
  30. reg-shift = <2>;
  31. reg-io-width = <4>;
  32. - no-loopback-test = <1>;
  33. + status = "okay";
  34. };
  35. pgu0: pgu@c9000000 {
  36. diff -Nur linux-3.12.26.orig/arch/arc/configs/nsimosci_defconfig linux-3.12.26/arch/arc/configs/nsimosci_defconfig
  37. --- linux-3.12.26.orig/arch/arc/configs/nsimosci_defconfig 2014-07-30 18:02:44.000000000 +0200
  38. +++ linux-3.12.26/arch/arc/configs/nsimosci_defconfig 2014-08-06 16:50:13.737956371 +0200
  39. @@ -54,7 +54,6 @@
  40. CONFIG_SERIAL_8250=y
  41. CONFIG_SERIAL_8250_CONSOLE=y
  42. CONFIG_SERIAL_8250_DW=y
  43. -CONFIG_SERIAL_OF_PLATFORM=y
  44. CONFIG_SERIAL_ARC=y
  45. CONFIG_SERIAL_ARC_CONSOLE=y
  46. # CONFIG_HW_RANDOM is not set
  47. diff -Nur linux-3.12.26.orig/arch/arm/configs/bcmrpi_cutdown_defconfig linux-3.12.26/arch/arm/configs/bcmrpi_cutdown_defconfig
  48. --- linux-3.12.26.orig/arch/arm/configs/bcmrpi_cutdown_defconfig 1970-01-01 01:00:00.000000000 +0100
  49. +++ linux-3.12.26/arch/arm/configs/bcmrpi_cutdown_defconfig 2014-08-06 16:50:13.737956371 +0200
  50. @@ -0,0 +1,503 @@
  51. +CONFIG_EXPERIMENTAL=y
  52. +# CONFIG_LOCALVERSION_AUTO is not set
  53. +CONFIG_SYSVIPC=y
  54. +CONFIG_POSIX_MQUEUE=y
  55. +CONFIG_IKCONFIG=y
  56. +CONFIG_IKCONFIG_PROC=y
  57. +# CONFIG_UID16 is not set
  58. +# CONFIG_KALLSYMS is not set
  59. +CONFIG_EMBEDDED=y
  60. +# CONFIG_VM_EVENT_COUNTERS is not set
  61. +# CONFIG_COMPAT_BRK is not set
  62. +CONFIG_SLAB=y
  63. +CONFIG_MODULES=y
  64. +CONFIG_MODULE_UNLOAD=y
  65. +CONFIG_MODVERSIONS=y
  66. +CONFIG_MODULE_SRCVERSION_ALL=y
  67. +# CONFIG_BLK_DEV_BSG is not set
  68. +CONFIG_ARCH_BCM2708=y
  69. +CONFIG_NO_HZ=y
  70. +CONFIG_HIGH_RES_TIMERS=y
  71. +CONFIG_AEABI=y
  72. +CONFIG_ZBOOT_ROM_TEXT=0x0
  73. +CONFIG_ZBOOT_ROM_BSS=0x0
  74. +CONFIG_CMDLINE="dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext3 rootwait"
  75. +CONFIG_CPU_IDLE=y
  76. +CONFIG_VFP=y
  77. +CONFIG_BINFMT_MISC=m
  78. +CONFIG_NET=y
  79. +CONFIG_PACKET=y
  80. +CONFIG_UNIX=y
  81. +CONFIG_XFRM_USER=y
  82. +CONFIG_NET_KEY=m
  83. +CONFIG_INET=y
  84. +CONFIG_IP_MULTICAST=y
  85. +CONFIG_IP_PNP=y
  86. +CONFIG_IP_PNP_DHCP=y
  87. +CONFIG_IP_PNP_RARP=y
  88. +CONFIG_SYN_COOKIES=y
  89. +# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
  90. +# CONFIG_INET_XFRM_MODE_TUNNEL is not set
  91. +# CONFIG_INET_XFRM_MODE_BEET is not set
  92. +# CONFIG_INET_LRO is not set
  93. +# CONFIG_INET_DIAG is not set
  94. +# CONFIG_IPV6 is not set
  95. +CONFIG_NET_PKTGEN=m
  96. +CONFIG_IRDA=m
  97. +CONFIG_IRLAN=m
  98. +CONFIG_IRCOMM=m
  99. +CONFIG_IRDA_ULTRA=y
  100. +CONFIG_IRDA_CACHE_LAST_LSAP=y
  101. +CONFIG_IRDA_FAST_RR=y
  102. +CONFIG_IRTTY_SIR=m
  103. +CONFIG_KINGSUN_DONGLE=m
  104. +CONFIG_KSDAZZLE_DONGLE=m
  105. +CONFIG_KS959_DONGLE=m
  106. +CONFIG_USB_IRDA=m
  107. +CONFIG_SIGMATEL_FIR=m
  108. +CONFIG_MCS_FIR=m
  109. +CONFIG_BT=m
  110. +CONFIG_BT_L2CAP=y
  111. +CONFIG_BT_SCO=y
  112. +CONFIG_BT_RFCOMM=m
  113. +CONFIG_BT_RFCOMM_TTY=y
  114. +CONFIG_BT_BNEP=m
  115. +CONFIG_BT_BNEP_MC_FILTER=y
  116. +CONFIG_BT_BNEP_PROTO_FILTER=y
  117. +CONFIG_BT_HIDP=m
  118. +CONFIG_BT_HCIBTUSB=m
  119. +CONFIG_BT_HCIBCM203X=m
  120. +CONFIG_BT_HCIBPA10X=m
  121. +CONFIG_BT_HCIBFUSB=m
  122. +CONFIG_BT_HCIVHCI=m
  123. +CONFIG_BT_MRVL=m
  124. +CONFIG_BT_MRVL_SDIO=m
  125. +CONFIG_BT_ATH3K=m
  126. +CONFIG_CFG80211=m
  127. +CONFIG_MAC80211=m
  128. +CONFIG_MAC80211_RC_PID=y
  129. +CONFIG_MAC80211_MESH=y
  130. +CONFIG_WIMAX=m
  131. +CONFIG_NET_9P=m
  132. +CONFIG_NFC=m
  133. +CONFIG_NFC_PN533=m
  134. +CONFIG_DEVTMPFS=y
  135. +CONFIG_BLK_DEV_LOOP=y
  136. +CONFIG_BLK_DEV_CRYPTOLOOP=m
  137. +CONFIG_BLK_DEV_NBD=m
  138. +CONFIG_BLK_DEV_RAM=y
  139. +CONFIG_CDROM_PKTCDVD=m
  140. +CONFIG_MISC_DEVICES=y
  141. +CONFIG_SCSI=y
  142. +# CONFIG_SCSI_PROC_FS is not set
  143. +CONFIG_BLK_DEV_SD=m
  144. +CONFIG_BLK_DEV_SR=m
  145. +CONFIG_SCSI_MULTI_LUN=y
  146. +# CONFIG_SCSI_LOWLEVEL is not set
  147. +CONFIG_NETDEVICES=y
  148. +CONFIG_TUN=m
  149. +CONFIG_PHYLIB=m
  150. +CONFIG_MDIO_BITBANG=m
  151. +CONFIG_NET_ETHERNET=y
  152. +# CONFIG_NETDEV_1000 is not set
  153. +# CONFIG_NETDEV_10000 is not set
  154. +CONFIG_LIBERTAS_THINFIRM=m
  155. +CONFIG_LIBERTAS_THINFIRM_USB=m
  156. +CONFIG_AT76C50X_USB=m
  157. +CONFIG_USB_ZD1201=m
  158. +CONFIG_USB_NET_RNDIS_WLAN=m
  159. +CONFIG_RTL8187=m
  160. +CONFIG_MAC80211_HWSIM=m
  161. +CONFIG_ATH_COMMON=m
  162. +CONFIG_ATH9K=m
  163. +CONFIG_ATH9K_HTC=m
  164. +CONFIG_CARL9170=m
  165. +CONFIG_B43=m
  166. +CONFIG_B43LEGACY=m
  167. +CONFIG_HOSTAP=m
  168. +CONFIG_IWM=m
  169. +CONFIG_LIBERTAS=m
  170. +CONFIG_LIBERTAS_USB=m
  171. +CONFIG_LIBERTAS_SDIO=m
  172. +CONFIG_P54_COMMON=m
  173. +CONFIG_P54_USB=m
  174. +CONFIG_RT2X00=m
  175. +CONFIG_RT2500USB=m
  176. +CONFIG_RT73USB=m
  177. +CONFIG_RT2800USB=m
  178. +CONFIG_RT2800USB_RT53XX=y
  179. +CONFIG_RTL8192CU=m
  180. +CONFIG_WL1251=m
  181. +CONFIG_WL12XX_MENU=m
  182. +CONFIG_ZD1211RW=m
  183. +CONFIG_MWIFIEX=m
  184. +CONFIG_MWIFIEX_SDIO=m
  185. +CONFIG_WIMAX_I2400M_USB=m
  186. +CONFIG_USB_CATC=m
  187. +CONFIG_USB_KAWETH=m
  188. +CONFIG_USB_PEGASUS=m
  189. +CONFIG_USB_RTL8150=m
  190. +CONFIG_USB_USBNET=y
  191. +CONFIG_USB_NET_AX8817X=m
  192. +CONFIG_USB_NET_CDCETHER=m
  193. +CONFIG_USB_NET_CDC_EEM=m
  194. +CONFIG_USB_NET_DM9601=m
  195. +CONFIG_USB_NET_SMSC75XX=m
  196. +CONFIG_USB_NET_SMSC95XX=y
  197. +CONFIG_USB_NET_GL620A=m
  198. +CONFIG_USB_NET_NET1080=m
  199. +CONFIG_USB_NET_PLUSB=m
  200. +CONFIG_USB_NET_MCS7830=m
  201. +CONFIG_USB_NET_CDC_SUBSET=m
  202. +CONFIG_USB_ALI_M5632=y
  203. +CONFIG_USB_AN2720=y
  204. +CONFIG_USB_KC2190=y
  205. +# CONFIG_USB_NET_ZAURUS is not set
  206. +CONFIG_USB_NET_CX82310_ETH=m
  207. +CONFIG_USB_NET_KALMIA=m
  208. +CONFIG_USB_NET_INT51X1=m
  209. +CONFIG_USB_IPHETH=m
  210. +CONFIG_USB_SIERRA_NET=m
  211. +CONFIG_USB_VL600=m
  212. +CONFIG_PPP=m
  213. +CONFIG_PPP_ASYNC=m
  214. +CONFIG_PPP_SYNC_TTY=m
  215. +CONFIG_PPP_DEFLATE=m
  216. +CONFIG_PPP_BSDCOMP=m
  217. +CONFIG_SLIP=m
  218. +CONFIG_SLIP_COMPRESSED=y
  219. +CONFIG_NETCONSOLE=m
  220. +CONFIG_INPUT_POLLDEV=m
  221. +# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
  222. +CONFIG_INPUT_JOYDEV=m
  223. +CONFIG_INPUT_EVDEV=m
  224. +# CONFIG_INPUT_KEYBOARD is not set
  225. +# CONFIG_INPUT_MOUSE is not set
  226. +CONFIG_INPUT_MISC=y
  227. +CONFIG_INPUT_AD714X=m
  228. +CONFIG_INPUT_ATI_REMOTE=m
  229. +CONFIG_INPUT_ATI_REMOTE2=m
  230. +CONFIG_INPUT_KEYSPAN_REMOTE=m
  231. +CONFIG_INPUT_POWERMATE=m
  232. +CONFIG_INPUT_YEALINK=m
  233. +CONFIG_INPUT_CM109=m
  234. +CONFIG_INPUT_UINPUT=m
  235. +CONFIG_INPUT_GPIO_ROTARY_ENCODER=m
  236. +CONFIG_INPUT_ADXL34X=m
  237. +CONFIG_INPUT_CMA3000=m
  238. +CONFIG_SERIO=m
  239. +CONFIG_SERIO_RAW=m
  240. +CONFIG_GAMEPORT=m
  241. +CONFIG_GAMEPORT_NS558=m
  242. +CONFIG_GAMEPORT_L4=m
  243. +CONFIG_VT_HW_CONSOLE_BINDING=y
  244. +# CONFIG_LEGACY_PTYS is not set
  245. +# CONFIG_DEVKMEM is not set
  246. +CONFIG_SERIAL_AMBA_PL011=y
  247. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  248. +# CONFIG_HW_RANDOM is not set
  249. +CONFIG_RAW_DRIVER=y
  250. +CONFIG_GPIO_SYSFS=y
  251. +# CONFIG_HWMON is not set
  252. +CONFIG_WATCHDOG=y
  253. +CONFIG_BCM2708_WDT=m
  254. +# CONFIG_MFD_SUPPORT is not set
  255. +CONFIG_FB=y
  256. +CONFIG_FB_BCM2708=y
  257. +CONFIG_FRAMEBUFFER_CONSOLE=y
  258. +CONFIG_LOGO=y
  259. +# CONFIG_LOGO_LINUX_MONO is not set
  260. +# CONFIG_LOGO_LINUX_VGA16 is not set
  261. +CONFIG_SOUND=y
  262. +CONFIG_SND=m
  263. +CONFIG_SND_SEQUENCER=m
  264. +CONFIG_SND_SEQ_DUMMY=m
  265. +CONFIG_SND_MIXER_OSS=m
  266. +CONFIG_SND_PCM_OSS=m
  267. +CONFIG_SND_SEQUENCER_OSS=y
  268. +CONFIG_SND_HRTIMER=m
  269. +CONFIG_SND_DUMMY=m
  270. +CONFIG_SND_ALOOP=m
  271. +CONFIG_SND_VIRMIDI=m
  272. +CONFIG_SND_MTPAV=m
  273. +CONFIG_SND_SERIAL_U16550=m
  274. +CONFIG_SND_MPU401=m
  275. +CONFIG_SND_BCM2835=m
  276. +CONFIG_SND_USB_AUDIO=m
  277. +CONFIG_SND_USB_UA101=m
  278. +CONFIG_SND_USB_CAIAQ=m
  279. +CONFIG_SND_USB_6FIRE=m
  280. +CONFIG_SOUND_PRIME=m
  281. +CONFIG_HID_PID=y
  282. +CONFIG_USB_HIDDEV=y
  283. +CONFIG_HID_A4TECH=m
  284. +CONFIG_HID_ACRUX=m
  285. +CONFIG_HID_APPLE=m
  286. +CONFIG_HID_BELKIN=m
  287. +CONFIG_HID_CHERRY=m
  288. +CONFIG_HID_CHICONY=m
  289. +CONFIG_HID_CYPRESS=m
  290. +CONFIG_HID_DRAGONRISE=m
  291. +CONFIG_HID_EMS_FF=m
  292. +CONFIG_HID_ELECOM=m
  293. +CONFIG_HID_EZKEY=m
  294. +CONFIG_HID_HOLTEK=m
  295. +CONFIG_HID_KEYTOUCH=m
  296. +CONFIG_HID_KYE=m
  297. +CONFIG_HID_UCLOGIC=m
  298. +CONFIG_HID_WALTOP=m
  299. +CONFIG_HID_GYRATION=m
  300. +CONFIG_HID_TWINHAN=m
  301. +CONFIG_HID_KENSINGTON=m
  302. +CONFIG_HID_LCPOWER=m
  303. +CONFIG_HID_LOGITECH=m
  304. +CONFIG_HID_MAGICMOUSE=m
  305. +CONFIG_HID_MICROSOFT=m
  306. +CONFIG_HID_MONTEREY=m
  307. +CONFIG_HID_MULTITOUCH=m
  308. +CONFIG_HID_NTRIG=m
  309. +CONFIG_HID_ORTEK=m
  310. +CONFIG_HID_PANTHERLORD=m
  311. +CONFIG_HID_PETALYNX=m
  312. +CONFIG_HID_PICOLCD=m
  313. +CONFIG_HID_QUANTA=m
  314. +CONFIG_HID_ROCCAT=m
  315. +CONFIG_HID_SAMSUNG=m
  316. +CONFIG_HID_SONY=m
  317. +CONFIG_HID_SPEEDLINK=m
  318. +CONFIG_HID_SUNPLUS=m
  319. +CONFIG_HID_GREENASIA=m
  320. +CONFIG_HID_SMARTJOYPLUS=m
  321. +CONFIG_HID_TOPSEED=m
  322. +CONFIG_HID_THRUSTMASTER=m
  323. +CONFIG_HID_WACOM=m
  324. +CONFIG_HID_WIIMOTE=m
  325. +CONFIG_HID_ZEROPLUS=m
  326. +CONFIG_HID_ZYDACRON=m
  327. +CONFIG_USB=y
  328. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  329. +CONFIG_USB_MON=m
  330. +CONFIG_USB_DWCOTG=y
  331. +CONFIG_USB_STORAGE=y
  332. +CONFIG_USB_STORAGE_REALTEK=m
  333. +CONFIG_USB_STORAGE_DATAFAB=m
  334. +CONFIG_USB_STORAGE_FREECOM=m
  335. +CONFIG_USB_STORAGE_ISD200=m
  336. +CONFIG_USB_STORAGE_USBAT=m
  337. +CONFIG_USB_STORAGE_SDDR09=m
  338. +CONFIG_USB_STORAGE_SDDR55=m
  339. +CONFIG_USB_STORAGE_JUMPSHOT=m
  340. +CONFIG_USB_STORAGE_ALAUDA=m
  341. +CONFIG_USB_STORAGE_ONETOUCH=m
  342. +CONFIG_USB_STORAGE_KARMA=m
  343. +CONFIG_USB_STORAGE_CYPRESS_ATACB=m
  344. +CONFIG_USB_STORAGE_ENE_UB6250=m
  345. +CONFIG_USB_UAS=m
  346. +CONFIG_USB_LIBUSUAL=y
  347. +CONFIG_USB_MDC800=m
  348. +CONFIG_USB_MICROTEK=m
  349. +CONFIG_USB_SERIAL=m
  350. +CONFIG_USB_SERIAL_GENERIC=y
  351. +CONFIG_USB_SERIAL_AIRCABLE=m
  352. +CONFIG_USB_SERIAL_ARK3116=m
  353. +CONFIG_USB_SERIAL_BELKIN=m
  354. +CONFIG_USB_SERIAL_CH341=m
  355. +CONFIG_USB_SERIAL_WHITEHEAT=m
  356. +CONFIG_USB_SERIAL_DIGI_ACCELEPORT=m
  357. +CONFIG_USB_SERIAL_CP210X=m
  358. +CONFIG_USB_SERIAL_CYPRESS_M8=m
  359. +CONFIG_USB_SERIAL_EMPEG=m
  360. +CONFIG_USB_SERIAL_FTDI_SIO=m
  361. +CONFIG_USB_SERIAL_FUNSOFT=m
  362. +CONFIG_USB_SERIAL_VISOR=m
  363. +CONFIG_USB_SERIAL_IPAQ=m
  364. +CONFIG_USB_SERIAL_IR=m
  365. +CONFIG_USB_SERIAL_EDGEPORT=m
  366. +CONFIG_USB_SERIAL_EDGEPORT_TI=m
  367. +CONFIG_USB_SERIAL_GARMIN=m
  368. +CONFIG_USB_SERIAL_IPW=m
  369. +CONFIG_USB_SERIAL_IUU=m
  370. +CONFIG_USB_SERIAL_KEYSPAN_PDA=m
  371. +CONFIG_USB_SERIAL_KEYSPAN=m
  372. +CONFIG_USB_SERIAL_KLSI=m
  373. +CONFIG_USB_SERIAL_KOBIL_SCT=m
  374. +CONFIG_USB_SERIAL_MCT_U232=m
  375. +CONFIG_USB_SERIAL_MOS7720=m
  376. +CONFIG_USB_SERIAL_MOS7840=m
  377. +CONFIG_USB_SERIAL_MOTOROLA=m
  378. +CONFIG_USB_SERIAL_NAVMAN=m
  379. +CONFIG_USB_SERIAL_PL2303=m
  380. +CONFIG_USB_SERIAL_OTI6858=m
  381. +CONFIG_USB_SERIAL_QCAUX=m
  382. +CONFIG_USB_SERIAL_QUALCOMM=m
  383. +CONFIG_USB_SERIAL_SPCP8X5=m
  384. +CONFIG_USB_SERIAL_HP4X=m
  385. +CONFIG_USB_SERIAL_SAFE=m
  386. +CONFIG_USB_SERIAL_SIEMENS_MPI=m
  387. +CONFIG_USB_SERIAL_SIERRAWIRELESS=m
  388. +CONFIG_USB_SERIAL_SYMBOL=m
  389. +CONFIG_USB_SERIAL_TI=m
  390. +CONFIG_USB_SERIAL_CYBERJACK=m
  391. +CONFIG_USB_SERIAL_XIRCOM=m
  392. +CONFIG_USB_SERIAL_OPTION=m
  393. +CONFIG_USB_SERIAL_OMNINET=m
  394. +CONFIG_USB_SERIAL_OPTICON=m
  395. +CONFIG_USB_SERIAL_VIVOPAY_SERIAL=m
  396. +CONFIG_USB_SERIAL_ZIO=m
  397. +CONFIG_USB_SERIAL_SSU100=m
  398. +CONFIG_USB_SERIAL_DEBUG=m
  399. +CONFIG_USB_EMI62=m
  400. +CONFIG_USB_EMI26=m
  401. +CONFIG_USB_ADUTUX=m
  402. +CONFIG_USB_SEVSEG=m
  403. +CONFIG_USB_RIO500=m
  404. +CONFIG_USB_LEGOTOWER=m
  405. +CONFIG_USB_LCD=m
  406. +CONFIG_USB_LED=m
  407. +CONFIG_USB_CYPRESS_CY7C63=m
  408. +CONFIG_USB_CYTHERM=m
  409. +CONFIG_USB_IDMOUSE=m
  410. +CONFIG_USB_FTDI_ELAN=m
  411. +CONFIG_USB_APPLEDISPLAY=m
  412. +CONFIG_USB_LD=m
  413. +CONFIG_USB_TRANCEVIBRATOR=m
  414. +CONFIG_USB_IOWARRIOR=m
  415. +CONFIG_USB_TEST=m
  416. +CONFIG_USB_ISIGHTFW=m
  417. +CONFIG_USB_YUREX=m
  418. +CONFIG_MMC=y
  419. +CONFIG_MMC_SDHCI=y
  420. +CONFIG_MMC_SDHCI_PLTFM=y
  421. +CONFIG_MMC_SDHCI_BCM2708=y
  422. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  423. +CONFIG_LEDS_GPIO=y
  424. +CONFIG_LEDS_TRIGGER_TIMER=m
  425. +CONFIG_LEDS_TRIGGER_HEARTBEAT=m
  426. +CONFIG_LEDS_TRIGGER_DEFAULT_ON=m
  427. +CONFIG_UIO=m
  428. +CONFIG_UIO_PDRV=m
  429. +CONFIG_UIO_PDRV_GENIRQ=m
  430. +# CONFIG_IOMMU_SUPPORT is not set
  431. +CONFIG_EXT4_FS=y
  432. +CONFIG_EXT4_FS_POSIX_ACL=y
  433. +CONFIG_EXT4_FS_SECURITY=y
  434. +CONFIG_REISERFS_FS=m
  435. +CONFIG_REISERFS_FS_XATTR=y
  436. +CONFIG_REISERFS_FS_POSIX_ACL=y
  437. +CONFIG_REISERFS_FS_SECURITY=y
  438. +CONFIG_JFS_FS=m
  439. +CONFIG_JFS_POSIX_ACL=y
  440. +CONFIG_JFS_SECURITY=y
  441. +CONFIG_XFS_FS=m
  442. +CONFIG_XFS_QUOTA=y
  443. +CONFIG_XFS_POSIX_ACL=y
  444. +CONFIG_XFS_RT=y
  445. +CONFIG_GFS2_FS=m
  446. +CONFIG_OCFS2_FS=m
  447. +CONFIG_BTRFS_FS=m
  448. +CONFIG_BTRFS_FS_POSIX_ACL=y
  449. +CONFIG_NILFS2_FS=m
  450. +CONFIG_AUTOFS4_FS=y
  451. +CONFIG_FUSE_FS=m
  452. +CONFIG_CUSE=m
  453. +CONFIG_FSCACHE=y
  454. +CONFIG_CACHEFILES=y
  455. +CONFIG_ISO9660_FS=m
  456. +CONFIG_JOLIET=y
  457. +CONFIG_ZISOFS=y
  458. +CONFIG_UDF_FS=m
  459. +CONFIG_MSDOS_FS=y
  460. +CONFIG_VFAT_FS=y
  461. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  462. +CONFIG_NTFS_FS=m
  463. +CONFIG_TMPFS=y
  464. +CONFIG_TMPFS_POSIX_ACL=y
  465. +CONFIG_CONFIGFS_FS=y
  466. +CONFIG_SQUASHFS=m
  467. +CONFIG_SQUASHFS_XATTR=y
  468. +CONFIG_SQUASHFS_LZO=y
  469. +CONFIG_SQUASHFS_XZ=y
  470. +CONFIG_NFS_FS=y
  471. +CONFIG_NFS_V3=y
  472. +CONFIG_NFS_V3_ACL=y
  473. +CONFIG_NFS_V4=y
  474. +CONFIG_ROOT_NFS=y
  475. +CONFIG_NFS_FSCACHE=y
  476. +CONFIG_CIFS=m
  477. +CONFIG_CIFS_WEAK_PW_HASH=y
  478. +CONFIG_CIFS_XATTR=y
  479. +CONFIG_CIFS_POSIX=y
  480. +CONFIG_9P_FS=m
  481. +CONFIG_PARTITION_ADVANCED=y
  482. +CONFIG_MAC_PARTITION=y
  483. +CONFIG_EFI_PARTITION=y
  484. +CONFIG_NLS_DEFAULT="utf8"
  485. +CONFIG_NLS_CODEPAGE_437=y
  486. +CONFIG_NLS_CODEPAGE_737=m
  487. +CONFIG_NLS_CODEPAGE_775=m
  488. +CONFIG_NLS_CODEPAGE_850=m
  489. +CONFIG_NLS_CODEPAGE_852=m
  490. +CONFIG_NLS_CODEPAGE_855=m
  491. +CONFIG_NLS_CODEPAGE_857=m
  492. +CONFIG_NLS_CODEPAGE_860=m
  493. +CONFIG_NLS_CODEPAGE_861=m
  494. +CONFIG_NLS_CODEPAGE_862=m
  495. +CONFIG_NLS_CODEPAGE_863=m
  496. +CONFIG_NLS_CODEPAGE_864=m
  497. +CONFIG_NLS_CODEPAGE_865=m
  498. +CONFIG_NLS_CODEPAGE_866=m
  499. +CONFIG_NLS_CODEPAGE_869=m
  500. +CONFIG_NLS_CODEPAGE_936=m
  501. +CONFIG_NLS_CODEPAGE_950=m
  502. +CONFIG_NLS_CODEPAGE_932=m
  503. +CONFIG_NLS_CODEPAGE_949=m
  504. +CONFIG_NLS_CODEPAGE_874=m
  505. +CONFIG_NLS_ISO8859_8=m
  506. +CONFIG_NLS_CODEPAGE_1250=m
  507. +CONFIG_NLS_CODEPAGE_1251=m
  508. +CONFIG_NLS_ASCII=y
  509. +CONFIG_NLS_ISO8859_1=m
  510. +CONFIG_NLS_ISO8859_2=m
  511. +CONFIG_NLS_ISO8859_3=m
  512. +CONFIG_NLS_ISO8859_4=m
  513. +CONFIG_NLS_ISO8859_5=m
  514. +CONFIG_NLS_ISO8859_6=m
  515. +CONFIG_NLS_ISO8859_7=m
  516. +CONFIG_NLS_ISO8859_9=m
  517. +CONFIG_NLS_ISO8859_13=m
  518. +CONFIG_NLS_ISO8859_14=m
  519. +CONFIG_NLS_ISO8859_15=m
  520. +CONFIG_NLS_KOI8_R=m
  521. +CONFIG_NLS_KOI8_U=m
  522. +CONFIG_NLS_UTF8=m
  523. +# CONFIG_SCHED_DEBUG is not set
  524. +# CONFIG_DEBUG_BUGVERBOSE is not set
  525. +# CONFIG_FTRACE is not set
  526. +# CONFIG_ARM_UNWIND is not set
  527. +CONFIG_CRYPTO_AUTHENC=m
  528. +CONFIG_CRYPTO_SEQIV=m
  529. +CONFIG_CRYPTO_CBC=y
  530. +CONFIG_CRYPTO_HMAC=y
  531. +CONFIG_CRYPTO_XCBC=m
  532. +CONFIG_CRYPTO_MD5=y
  533. +CONFIG_CRYPTO_SHA1=y
  534. +CONFIG_CRYPTO_SHA256=m
  535. +CONFIG_CRYPTO_SHA512=m
  536. +CONFIG_CRYPTO_TGR192=m
  537. +CONFIG_CRYPTO_WP512=m
  538. +CONFIG_CRYPTO_CAST5=m
  539. +CONFIG_CRYPTO_DES=y
  540. +CONFIG_CRYPTO_DEFLATE=m
  541. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  542. +# CONFIG_CRYPTO_HW is not set
  543. +CONFIG_CRC_ITU_T=y
  544. +CONFIG_LIBCRC32C=y
  545. +CONFIG_I2C=y
  546. +CONFIG_I2C_BOARDINFO=y
  547. +CONFIG_I2C_COMPAT=y
  548. +CONFIG_I2C_CHARDEV=m
  549. +CONFIG_I2C_HELPER_AUTO=y
  550. +CONFIG_I2C_BCM2708=m
  551. +CONFIG_SPI=y
  552. +CONFIG_SPI_MASTER=y
  553. +CONFIG_SPI_BCM2708=m
  554. diff -Nur linux-3.12.26.orig/arch/arm/configs/bcmrpi_defconfig linux-3.12.26/arch/arm/configs/bcmrpi_defconfig
  555. --- linux-3.12.26.orig/arch/arm/configs/bcmrpi_defconfig 1970-01-01 01:00:00.000000000 +0100
  556. +++ linux-3.12.26/arch/arm/configs/bcmrpi_defconfig 2014-08-06 16:50:13.753956496 +0200
  557. @@ -0,0 +1,1097 @@
  558. +# CONFIG_ARM_PATCH_PHYS_VIRT is not set
  559. +# CONFIG_LOCALVERSION_AUTO is not set
  560. +CONFIG_SYSVIPC=y
  561. +CONFIG_POSIX_MQUEUE=y
  562. +CONFIG_FHANDLE=y
  563. +CONFIG_AUDIT=y
  564. +CONFIG_NO_HZ=y
  565. +CONFIG_HIGH_RES_TIMERS=y
  566. +CONFIG_BSD_PROCESS_ACCT=y
  567. +CONFIG_BSD_PROCESS_ACCT_V3=y
  568. +CONFIG_TASKSTATS=y
  569. +CONFIG_TASK_DELAY_ACCT=y
  570. +CONFIG_TASK_XACCT=y
  571. +CONFIG_TASK_IO_ACCOUNTING=y
  572. +CONFIG_IKCONFIG=y
  573. +CONFIG_IKCONFIG_PROC=y
  574. +CONFIG_CGROUP_FREEZER=y
  575. +CONFIG_CGROUP_DEVICE=y
  576. +CONFIG_CGROUP_CPUACCT=y
  577. +CONFIG_RESOURCE_COUNTERS=y
  578. +CONFIG_MEMCG=y
  579. +CONFIG_BLK_CGROUP=y
  580. +CONFIG_NAMESPACES=y
  581. +CONFIG_SCHED_AUTOGROUP=y
  582. +CONFIG_RELAY=y
  583. +CONFIG_BLK_DEV_INITRD=y
  584. +CONFIG_EMBEDDED=y
  585. +# CONFIG_COMPAT_BRK is not set
  586. +CONFIG_PROFILING=y
  587. +CONFIG_OPROFILE=m
  588. +CONFIG_KPROBES=y
  589. +CONFIG_JUMP_LABEL=y
  590. +CONFIG_MODULES=y
  591. +CONFIG_MODULE_UNLOAD=y
  592. +CONFIG_MODVERSIONS=y
  593. +CONFIG_MODULE_SRCVERSION_ALL=y
  594. +CONFIG_BLK_DEV_THROTTLING=y
  595. +CONFIG_PARTITION_ADVANCED=y
  596. +CONFIG_MAC_PARTITION=y
  597. +CONFIG_CFQ_GROUP_IOSCHED=y
  598. +CONFIG_ARCH_BCM2708=y
  599. +CONFIG_PREEMPT=y
  600. +CONFIG_AEABI=y
  601. +CONFIG_CLEANCACHE=y
  602. +CONFIG_FRONTSWAP=y
  603. +CONFIG_CMA=y
  604. +CONFIG_UACCESS_WITH_MEMCPY=y
  605. +CONFIG_SECCOMP=y
  606. +CONFIG_CC_STACKPROTECTOR=y
  607. +CONFIG_ZBOOT_ROM_TEXT=0x0
  608. +CONFIG_ZBOOT_ROM_BSS=0x0
  609. +CONFIG_CMDLINE="console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait"
  610. +CONFIG_KEXEC=y
  611. +CONFIG_CPU_FREQ=y
  612. +CONFIG_CPU_FREQ_STAT=m
  613. +CONFIG_CPU_FREQ_STAT_DETAILS=y
  614. +CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE=y
  615. +CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
  616. +CONFIG_CPU_FREQ_GOV_USERSPACE=y
  617. +CONFIG_CPU_FREQ_GOV_ONDEMAND=y
  618. +CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
  619. +CONFIG_CPU_IDLE=y
  620. +CONFIG_VFP=y
  621. +CONFIG_BINFMT_MISC=m
  622. +CONFIG_NET=y
  623. +CONFIG_PACKET=y
  624. +CONFIG_UNIX=y
  625. +CONFIG_XFRM_USER=y
  626. +CONFIG_NET_KEY=m
  627. +CONFIG_INET=y
  628. +CONFIG_IP_MULTICAST=y
  629. +CONFIG_IP_ADVANCED_ROUTER=y
  630. +CONFIG_IP_MULTIPLE_TABLES=y
  631. +CONFIG_IP_ROUTE_MULTIPATH=y
  632. +CONFIG_IP_ROUTE_VERBOSE=y
  633. +CONFIG_IP_PNP=y
  634. +CONFIG_IP_PNP_DHCP=y
  635. +CONFIG_IP_PNP_RARP=y
  636. +CONFIG_NET_IPIP=m
  637. +CONFIG_NET_IPGRE_DEMUX=m
  638. +CONFIG_NET_IPGRE=m
  639. +CONFIG_IP_MROUTE=y
  640. +CONFIG_IP_MROUTE_MULTIPLE_TABLES=y
  641. +CONFIG_IP_PIMSM_V1=y
  642. +CONFIG_IP_PIMSM_V2=y
  643. +CONFIG_SYN_COOKIES=y
  644. +CONFIG_INET_AH=m
  645. +CONFIG_INET_ESP=m
  646. +CONFIG_INET_IPCOMP=m
  647. +CONFIG_INET_XFRM_MODE_TRANSPORT=m
  648. +CONFIG_INET_XFRM_MODE_TUNNEL=m
  649. +CONFIG_INET_XFRM_MODE_BEET=m
  650. +CONFIG_INET_LRO=m
  651. +CONFIG_INET_DIAG=m
  652. +CONFIG_INET6_AH=m
  653. +CONFIG_INET6_ESP=m
  654. +CONFIG_INET6_IPCOMP=m
  655. +CONFIG_IPV6_TUNNEL=m
  656. +CONFIG_IPV6_MULTIPLE_TABLES=y
  657. +CONFIG_IPV6_MROUTE=y
  658. +CONFIG_IPV6_MROUTE_MULTIPLE_TABLES=y
  659. +CONFIG_IPV6_PIMSM_V2=y
  660. +CONFIG_NETFILTER=y
  661. +CONFIG_NF_CONNTRACK=m
  662. +CONFIG_NF_CONNTRACK_ZONES=y
  663. +CONFIG_NF_CONNTRACK_EVENTS=y
  664. +CONFIG_NF_CONNTRACK_TIMESTAMP=y
  665. +CONFIG_NF_CT_PROTO_DCCP=m
  666. +CONFIG_NF_CT_PROTO_UDPLITE=m
  667. +CONFIG_NF_CONNTRACK_AMANDA=m
  668. +CONFIG_NF_CONNTRACK_FTP=m
  669. +CONFIG_NF_CONNTRACK_H323=m
  670. +CONFIG_NF_CONNTRACK_IRC=m
  671. +CONFIG_NF_CONNTRACK_NETBIOS_NS=m
  672. +CONFIG_NF_CONNTRACK_SNMP=m
  673. +CONFIG_NF_CONNTRACK_PPTP=m
  674. +CONFIG_NF_CONNTRACK_SANE=m
  675. +CONFIG_NF_CONNTRACK_SIP=m
  676. +CONFIG_NF_CONNTRACK_TFTP=m
  677. +CONFIG_NF_CT_NETLINK=m
  678. +CONFIG_NETFILTER_XT_SET=m
  679. +CONFIG_NETFILTER_XT_TARGET_AUDIT=m
  680. +CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m
  681. +CONFIG_NETFILTER_XT_TARGET_CLASSIFY=m
  682. +CONFIG_NETFILTER_XT_TARGET_CONNMARK=m
  683. +CONFIG_NETFILTER_XT_TARGET_DSCP=m
  684. +CONFIG_NETFILTER_XT_TARGET_HMARK=m
  685. +CONFIG_NETFILTER_XT_TARGET_IDLETIMER=m
  686. +CONFIG_NETFILTER_XT_TARGET_LED=m
  687. +CONFIG_NETFILTER_XT_TARGET_LOG=m
  688. +CONFIG_NETFILTER_XT_TARGET_MARK=m
  689. +CONFIG_NETFILTER_XT_TARGET_NFLOG=m
  690. +CONFIG_NETFILTER_XT_TARGET_NFQUEUE=m
  691. +CONFIG_NETFILTER_XT_TARGET_NOTRACK=m
  692. +CONFIG_NETFILTER_XT_TARGET_TEE=m
  693. +CONFIG_NETFILTER_XT_TARGET_TPROXY=m
  694. +CONFIG_NETFILTER_XT_TARGET_TRACE=m
  695. +CONFIG_NETFILTER_XT_TARGET_TCPMSS=m
  696. +CONFIG_NETFILTER_XT_TARGET_TCPOPTSTRIP=m
  697. +CONFIG_NETFILTER_XT_MATCH_ADDRTYPE=m
  698. +CONFIG_NETFILTER_XT_MATCH_BPF=m
  699. +CONFIG_NETFILTER_XT_MATCH_CLUSTER=m
  700. +CONFIG_NETFILTER_XT_MATCH_COMMENT=m
  701. +CONFIG_NETFILTER_XT_MATCH_CONNBYTES=m
  702. +CONFIG_NETFILTER_XT_MATCH_CONNLABEL=m
  703. +CONFIG_NETFILTER_XT_MATCH_CONNLIMIT=m
  704. +CONFIG_NETFILTER_XT_MATCH_CONNMARK=m
  705. +CONFIG_NETFILTER_XT_MATCH_CONNTRACK=m
  706. +CONFIG_NETFILTER_XT_MATCH_CPU=m
  707. +CONFIG_NETFILTER_XT_MATCH_DCCP=m
  708. +CONFIG_NETFILTER_XT_MATCH_DEVGROUP=m
  709. +CONFIG_NETFILTER_XT_MATCH_DSCP=m
  710. +CONFIG_NETFILTER_XT_MATCH_ESP=m
  711. +CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m
  712. +CONFIG_NETFILTER_XT_MATCH_HELPER=m
  713. +CONFIG_NETFILTER_XT_MATCH_IPRANGE=m
  714. +CONFIG_NETFILTER_XT_MATCH_IPVS=m
  715. +CONFIG_NETFILTER_XT_MATCH_LENGTH=m
  716. +CONFIG_NETFILTER_XT_MATCH_LIMIT=m
  717. +CONFIG_NETFILTER_XT_MATCH_MAC=m
  718. +CONFIG_NETFILTER_XT_MATCH_MARK=m
  719. +CONFIG_NETFILTER_XT_MATCH_MULTIPORT=m
  720. +CONFIG_NETFILTER_XT_MATCH_NFACCT=m
  721. +CONFIG_NETFILTER_XT_MATCH_OSF=m
  722. +CONFIG_NETFILTER_XT_MATCH_OWNER=m
  723. +CONFIG_NETFILTER_XT_MATCH_POLICY=m
  724. +CONFIG_NETFILTER_XT_MATCH_PHYSDEV=m
  725. +CONFIG_NETFILTER_XT_MATCH_PKTTYPE=m
  726. +CONFIG_NETFILTER_XT_MATCH_QUOTA=m
  727. +CONFIG_NETFILTER_XT_MATCH_RATEEST=m
  728. +CONFIG_NETFILTER_XT_MATCH_REALM=m
  729. +CONFIG_NETFILTER_XT_MATCH_RECENT=m
  730. +CONFIG_NETFILTER_XT_MATCH_SOCKET=m
  731. +CONFIG_NETFILTER_XT_MATCH_STATE=m
  732. +CONFIG_NETFILTER_XT_MATCH_STATISTIC=m
  733. +CONFIG_NETFILTER_XT_MATCH_STRING=m
  734. +CONFIG_NETFILTER_XT_MATCH_TCPMSS=m
  735. +CONFIG_NETFILTER_XT_MATCH_TIME=m
  736. +CONFIG_NETFILTER_XT_MATCH_U32=m
  737. +CONFIG_IP_SET=m
  738. +CONFIG_IP_SET_BITMAP_IP=m
  739. +CONFIG_IP_SET_BITMAP_IPMAC=m
  740. +CONFIG_IP_SET_BITMAP_PORT=m
  741. +CONFIG_IP_SET_HASH_IP=m
  742. +CONFIG_IP_SET_HASH_IPPORT=m
  743. +CONFIG_IP_SET_HASH_IPPORTIP=m
  744. +CONFIG_IP_SET_HASH_IPPORTNET=m
  745. +CONFIG_IP_SET_HASH_NET=m
  746. +CONFIG_IP_SET_HASH_NETPORT=m
  747. +CONFIG_IP_SET_HASH_NETIFACE=m
  748. +CONFIG_IP_SET_LIST_SET=m
  749. +CONFIG_IP_VS=m
  750. +CONFIG_IP_VS_PROTO_TCP=y
  751. +CONFIG_IP_VS_PROTO_UDP=y
  752. +CONFIG_IP_VS_PROTO_ESP=y
  753. +CONFIG_IP_VS_PROTO_AH=y
  754. +CONFIG_IP_VS_PROTO_SCTP=y
  755. +CONFIG_IP_VS_RR=m
  756. +CONFIG_IP_VS_WRR=m
  757. +CONFIG_IP_VS_LC=m
  758. +CONFIG_IP_VS_WLC=m
  759. +CONFIG_IP_VS_LBLC=m
  760. +CONFIG_IP_VS_LBLCR=m
  761. +CONFIG_IP_VS_DH=m
  762. +CONFIG_IP_VS_SH=m
  763. +CONFIG_IP_VS_SED=m
  764. +CONFIG_IP_VS_NQ=m
  765. +CONFIG_IP_VS_FTP=m
  766. +CONFIG_IP_VS_PE_SIP=m
  767. +CONFIG_NF_CONNTRACK_IPV4=m
  768. +CONFIG_IP_NF_IPTABLES=m
  769. +CONFIG_IP_NF_MATCH_AH=m
  770. +CONFIG_IP_NF_MATCH_ECN=m
  771. +CONFIG_IP_NF_MATCH_TTL=m
  772. +CONFIG_IP_NF_FILTER=m
  773. +CONFIG_IP_NF_TARGET_REJECT=m
  774. +CONFIG_IP_NF_TARGET_ULOG=m
  775. +CONFIG_NF_NAT_IPV4=m
  776. +CONFIG_IP_NF_TARGET_MASQUERADE=m
  777. +CONFIG_IP_NF_TARGET_NETMAP=m
  778. +CONFIG_IP_NF_TARGET_REDIRECT=m
  779. +CONFIG_IP_NF_MANGLE=m
  780. +CONFIG_IP_NF_TARGET_ECN=m
  781. +CONFIG_IP_NF_TARGET_TTL=m
  782. +CONFIG_IP_NF_RAW=m
  783. +CONFIG_IP_NF_ARPTABLES=m
  784. +CONFIG_IP_NF_ARPFILTER=m
  785. +CONFIG_IP_NF_ARP_MANGLE=m
  786. +CONFIG_NF_CONNTRACK_IPV6=m
  787. +CONFIG_IP6_NF_IPTABLES=m
  788. +CONFIG_IP6_NF_MATCH_AH=m
  789. +CONFIG_IP6_NF_MATCH_EUI64=m
  790. +CONFIG_IP6_NF_MATCH_FRAG=m
  791. +CONFIG_IP6_NF_MATCH_OPTS=m
  792. +CONFIG_IP6_NF_MATCH_HL=m
  793. +CONFIG_IP6_NF_MATCH_IPV6HEADER=m
  794. +CONFIG_IP6_NF_MATCH_MH=m
  795. +CONFIG_IP6_NF_MATCH_RT=m
  796. +CONFIG_IP6_NF_TARGET_HL=m
  797. +CONFIG_IP6_NF_FILTER=m
  798. +CONFIG_IP6_NF_TARGET_REJECT=m
  799. +CONFIG_IP6_NF_MANGLE=m
  800. +CONFIG_IP6_NF_RAW=m
  801. +CONFIG_NF_NAT_IPV6=m
  802. +CONFIG_IP6_NF_TARGET_MASQUERADE=m
  803. +CONFIG_IP6_NF_TARGET_NPT=m
  804. +CONFIG_BRIDGE_NF_EBTABLES=m
  805. +CONFIG_BRIDGE_EBT_BROUTE=m
  806. +CONFIG_BRIDGE_EBT_T_FILTER=m
  807. +CONFIG_BRIDGE_EBT_T_NAT=m
  808. +CONFIG_BRIDGE_EBT_802_3=m
  809. +CONFIG_BRIDGE_EBT_AMONG=m
  810. +CONFIG_BRIDGE_EBT_ARP=m
  811. +CONFIG_BRIDGE_EBT_IP=m
  812. +CONFIG_BRIDGE_EBT_IP6=m
  813. +CONFIG_BRIDGE_EBT_LIMIT=m
  814. +CONFIG_BRIDGE_EBT_MARK=m
  815. +CONFIG_BRIDGE_EBT_PKTTYPE=m
  816. +CONFIG_BRIDGE_EBT_STP=m
  817. +CONFIG_BRIDGE_EBT_VLAN=m
  818. +CONFIG_BRIDGE_EBT_ARPREPLY=m
  819. +CONFIG_BRIDGE_EBT_DNAT=m
  820. +CONFIG_BRIDGE_EBT_MARK_T=m
  821. +CONFIG_BRIDGE_EBT_REDIRECT=m
  822. +CONFIG_BRIDGE_EBT_SNAT=m
  823. +CONFIG_BRIDGE_EBT_LOG=m
  824. +CONFIG_BRIDGE_EBT_ULOG=m
  825. +CONFIG_BRIDGE_EBT_NFLOG=m
  826. +CONFIG_SCTP_COOKIE_HMAC_SHA1=y
  827. +CONFIG_L2TP=m
  828. +CONFIG_L2TP_V3=y
  829. +CONFIG_L2TP_IP=m
  830. +CONFIG_L2TP_ETH=m
  831. +CONFIG_BRIDGE=m
  832. +CONFIG_VLAN_8021Q=m
  833. +CONFIG_VLAN_8021Q_GVRP=y
  834. +CONFIG_ATALK=m
  835. +CONFIG_NET_SCHED=y
  836. +CONFIG_NET_SCH_CBQ=m
  837. +CONFIG_NET_SCH_HTB=m
  838. +CONFIG_NET_SCH_HFSC=m
  839. +CONFIG_NET_SCH_PRIO=m
  840. +CONFIG_NET_SCH_MULTIQ=m
  841. +CONFIG_NET_SCH_RED=m
  842. +CONFIG_NET_SCH_SFB=m
  843. +CONFIG_NET_SCH_SFQ=m
  844. +CONFIG_NET_SCH_TEQL=m
  845. +CONFIG_NET_SCH_TBF=m
  846. +CONFIG_NET_SCH_GRED=m
  847. +CONFIG_NET_SCH_DSMARK=m
  848. +CONFIG_NET_SCH_NETEM=m
  849. +CONFIG_NET_SCH_DRR=m
  850. +CONFIG_NET_SCH_MQPRIO=m
  851. +CONFIG_NET_SCH_CHOKE=m
  852. +CONFIG_NET_SCH_QFQ=m
  853. +CONFIG_NET_SCH_CODEL=m
  854. +CONFIG_NET_SCH_FQ_CODEL=m
  855. +CONFIG_NET_SCH_INGRESS=m
  856. +CONFIG_NET_SCH_PLUG=m
  857. +CONFIG_NET_CLS_BASIC=m
  858. +CONFIG_NET_CLS_TCINDEX=m
  859. +CONFIG_NET_CLS_ROUTE4=m
  860. +CONFIG_NET_CLS_FW=m
  861. +CONFIG_NET_CLS_U32=m
  862. +CONFIG_CLS_U32_MARK=y
  863. +CONFIG_NET_CLS_RSVP=m
  864. +CONFIG_NET_CLS_RSVP6=m
  865. +CONFIG_NET_CLS_FLOW=m
  866. +CONFIG_NET_CLS_CGROUP=m
  867. +CONFIG_NET_EMATCH=y
  868. +CONFIG_NET_EMATCH_CMP=m
  869. +CONFIG_NET_EMATCH_NBYTE=m
  870. +CONFIG_NET_EMATCH_U32=m
  871. +CONFIG_NET_EMATCH_META=m
  872. +CONFIG_NET_EMATCH_TEXT=m
  873. +CONFIG_NET_EMATCH_IPSET=m
  874. +CONFIG_NET_CLS_ACT=y
  875. +CONFIG_NET_ACT_POLICE=m
  876. +CONFIG_NET_ACT_GACT=m
  877. +CONFIG_GACT_PROB=y
  878. +CONFIG_NET_ACT_MIRRED=m
  879. +CONFIG_NET_ACT_IPT=m
  880. +CONFIG_NET_ACT_NAT=m
  881. +CONFIG_NET_ACT_PEDIT=m
  882. +CONFIG_NET_ACT_SIMP=m
  883. +CONFIG_NET_ACT_SKBEDIT=m
  884. +CONFIG_NET_ACT_CSUM=m
  885. +CONFIG_BATMAN_ADV=m
  886. +CONFIG_OPENVSWITCH=m
  887. +CONFIG_NET_PKTGEN=m
  888. +CONFIG_HAMRADIO=y
  889. +CONFIG_AX25=m
  890. +CONFIG_NETROM=m
  891. +CONFIG_ROSE=m
  892. +CONFIG_MKISS=m
  893. +CONFIG_6PACK=m
  894. +CONFIG_BPQETHER=m
  895. +CONFIG_BAYCOM_SER_FDX=m
  896. +CONFIG_BAYCOM_SER_HDX=m
  897. +CONFIG_YAM=m
  898. +CONFIG_IRDA=m
  899. +CONFIG_IRLAN=m
  900. +CONFIG_IRNET=m
  901. +CONFIG_IRCOMM=m
  902. +CONFIG_IRDA_ULTRA=y
  903. +CONFIG_IRDA_CACHE_LAST_LSAP=y
  904. +CONFIG_IRDA_FAST_RR=y
  905. +CONFIG_IRTTY_SIR=m
  906. +CONFIG_KINGSUN_DONGLE=m
  907. +CONFIG_KSDAZZLE_DONGLE=m
  908. +CONFIG_KS959_DONGLE=m
  909. +CONFIG_USB_IRDA=m
  910. +CONFIG_SIGMATEL_FIR=m
  911. +CONFIG_MCS_FIR=m
  912. +CONFIG_BT=m
  913. +CONFIG_BT_RFCOMM=m
  914. +CONFIG_BT_RFCOMM_TTY=y
  915. +CONFIG_BT_BNEP=m
  916. +CONFIG_BT_BNEP_MC_FILTER=y
  917. +CONFIG_BT_BNEP_PROTO_FILTER=y
  918. +CONFIG_BT_HIDP=m
  919. +CONFIG_BT_HCIBTUSB=m
  920. +CONFIG_BT_HCIBCM203X=m
  921. +CONFIG_BT_HCIBPA10X=m
  922. +CONFIG_BT_HCIBFUSB=m
  923. +CONFIG_BT_HCIVHCI=m
  924. +CONFIG_BT_MRVL=m
  925. +CONFIG_BT_MRVL_SDIO=m
  926. +CONFIG_BT_ATH3K=m
  927. +CONFIG_BT_WILINK=m
  928. +CONFIG_CFG80211=m
  929. +CONFIG_CFG80211_WEXT=y
  930. +CONFIG_MAC80211=m
  931. +CONFIG_MAC80211_RC_PID=y
  932. +CONFIG_MAC80211_MESH=y
  933. +CONFIG_WIMAX=m
  934. +CONFIG_RFKILL=m
  935. +CONFIG_RFKILL_INPUT=y
  936. +CONFIG_NET_9P=m
  937. +CONFIG_NFC=m
  938. +CONFIG_NFC_PN533=m
  939. +CONFIG_DEVTMPFS=y
  940. +CONFIG_DEVTMPFS_MOUNT=y
  941. +CONFIG_BLK_DEV_LOOP=y
  942. +CONFIG_BLK_DEV_CRYPTOLOOP=m
  943. +CONFIG_BLK_DEV_DRBD=m
  944. +CONFIG_BLK_DEV_NBD=m
  945. +CONFIG_BLK_DEV_RAM=y
  946. +CONFIG_CDROM_PKTCDVD=m
  947. +CONFIG_SCSI=y
  948. +# CONFIG_SCSI_PROC_FS is not set
  949. +CONFIG_BLK_DEV_SD=y
  950. +CONFIG_CHR_DEV_ST=m
  951. +CONFIG_CHR_DEV_OSST=m
  952. +CONFIG_BLK_DEV_SR=m
  953. +CONFIG_CHR_DEV_SG=m
  954. +CONFIG_SCSI_MULTI_LUN=y
  955. +CONFIG_SCSI_ISCSI_ATTRS=y
  956. +CONFIG_ISCSI_TCP=m
  957. +CONFIG_ISCSI_BOOT_SYSFS=m
  958. +CONFIG_MD=y
  959. +CONFIG_MD_LINEAR=m
  960. +CONFIG_MD_RAID0=m
  961. +CONFIG_BLK_DEV_DM=m
  962. +CONFIG_DM_CRYPT=m
  963. +CONFIG_DM_SNAPSHOT=m
  964. +CONFIG_DM_MIRROR=m
  965. +CONFIG_DM_LOG_USERSPACE=m
  966. +CONFIG_DM_RAID=m
  967. +CONFIG_DM_ZERO=m
  968. +CONFIG_DM_DELAY=m
  969. +CONFIG_NETDEVICES=y
  970. +CONFIG_BONDING=m
  971. +CONFIG_DUMMY=m
  972. +CONFIG_IFB=m
  973. +CONFIG_MACVLAN=m
  974. +CONFIG_NETCONSOLE=m
  975. +CONFIG_TUN=m
  976. +CONFIG_VETH=m
  977. +CONFIG_MDIO_BITBANG=m
  978. +CONFIG_PPP=m
  979. +CONFIG_PPP_BSDCOMP=m
  980. +CONFIG_PPP_DEFLATE=m
  981. +CONFIG_PPP_FILTER=y
  982. +CONFIG_PPP_MPPE=m
  983. +CONFIG_PPP_MULTILINK=y
  984. +CONFIG_PPPOE=m
  985. +CONFIG_PPPOL2TP=m
  986. +CONFIG_PPP_ASYNC=m
  987. +CONFIG_PPP_SYNC_TTY=m
  988. +CONFIG_SLIP=m
  989. +CONFIG_SLIP_COMPRESSED=y
  990. +CONFIG_SLIP_SMART=y
  991. +CONFIG_USB_CATC=m
  992. +CONFIG_USB_KAWETH=m
  993. +CONFIG_USB_PEGASUS=m
  994. +CONFIG_USB_RTL8150=m
  995. +CONFIG_USB_RTL8152=m
  996. +CONFIG_USB_USBNET=y
  997. +CONFIG_USB_NET_AX8817X=m
  998. +CONFIG_USB_NET_AX88179_178A=m
  999. +CONFIG_USB_NET_CDCETHER=m
  1000. +CONFIG_USB_NET_CDC_EEM=m
  1001. +CONFIG_USB_NET_CDC_NCM=m
  1002. +CONFIG_USB_NET_CDC_MBIM=m
  1003. +CONFIG_USB_NET_DM9601=m
  1004. +CONFIG_USB_NET_SMSC75XX=m
  1005. +CONFIG_USB_NET_SMSC95XX=y
  1006. +CONFIG_USB_NET_GL620A=m
  1007. +CONFIG_USB_NET_NET1080=m
  1008. +CONFIG_USB_NET_PLUSB=m
  1009. +CONFIG_USB_NET_MCS7830=m
  1010. +CONFIG_USB_NET_CDC_SUBSET=m
  1011. +CONFIG_USB_ALI_M5632=y
  1012. +CONFIG_USB_AN2720=y
  1013. +CONFIG_USB_EPSON2888=y
  1014. +CONFIG_USB_KC2190=y
  1015. +CONFIG_USB_NET_ZAURUS=m
  1016. +CONFIG_USB_NET_CX82310_ETH=m
  1017. +CONFIG_USB_NET_KALMIA=m
  1018. +CONFIG_USB_NET_QMI_WWAN=m
  1019. +CONFIG_USB_NET_INT51X1=m
  1020. +CONFIG_USB_IPHETH=m
  1021. +CONFIG_USB_SIERRA_NET=m
  1022. +CONFIG_USB_VL600=m
  1023. +CONFIG_LIBERTAS_THINFIRM=m
  1024. +CONFIG_LIBERTAS_THINFIRM_USB=m
  1025. +CONFIG_AT76C50X_USB=m
  1026. +CONFIG_USB_ZD1201=m
  1027. +CONFIG_USB_NET_RNDIS_WLAN=m
  1028. +CONFIG_RTL8187=m
  1029. +CONFIG_MAC80211_HWSIM=m
  1030. +CONFIG_ATH_CARDS=m
  1031. +CONFIG_ATH9K=m
  1032. +CONFIG_ATH9K_HTC=m
  1033. +CONFIG_CARL9170=m
  1034. +CONFIG_ATH6KL=m
  1035. +CONFIG_ATH6KL_USB=m
  1036. +CONFIG_AR5523=m
  1037. +CONFIG_B43=m
  1038. +# CONFIG_B43_PHY_N is not set
  1039. +CONFIG_B43LEGACY=m
  1040. +CONFIG_BRCMFMAC=m
  1041. +# CONFIG_BRCMFMAC_SDIO is not set
  1042. +CONFIG_BRCMFMAC_USB=y
  1043. +CONFIG_HOSTAP=m
  1044. +CONFIG_LIBERTAS=m
  1045. +CONFIG_LIBERTAS_USB=m
  1046. +CONFIG_LIBERTAS_SDIO=m
  1047. +CONFIG_P54_COMMON=m
  1048. +CONFIG_P54_USB=m
  1049. +CONFIG_RT2X00=m
  1050. +CONFIG_RT2500USB=m
  1051. +CONFIG_RT73USB=m
  1052. +CONFIG_RT2800USB=m
  1053. +CONFIG_RT2800USB_RT3573=y
  1054. +CONFIG_RT2800USB_RT53XX=y
  1055. +CONFIG_RT2800USB_RT55XX=y
  1056. +CONFIG_RT2800USB_UNKNOWN=y
  1057. +CONFIG_RTL8192CU=m
  1058. +CONFIG_ZD1211RW=m
  1059. +CONFIG_MWIFIEX=m
  1060. +CONFIG_MWIFIEX_SDIO=m
  1061. +CONFIG_WIMAX_I2400M_USB=m
  1062. +CONFIG_INPUT_POLLDEV=m
  1063. +# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
  1064. +CONFIG_INPUT_JOYDEV=m
  1065. +CONFIG_INPUT_EVDEV=m
  1066. +# CONFIG_INPUT_KEYBOARD is not set
  1067. +# CONFIG_INPUT_MOUSE is not set
  1068. +CONFIG_INPUT_JOYSTICK=y
  1069. +CONFIG_JOYSTICK_IFORCE=m
  1070. +CONFIG_JOYSTICK_IFORCE_USB=y
  1071. +CONFIG_JOYSTICK_XPAD=m
  1072. +CONFIG_JOYSTICK_XPAD_FF=y
  1073. +CONFIG_INPUT_MISC=y
  1074. +CONFIG_INPUT_AD714X=m
  1075. +CONFIG_INPUT_ATI_REMOTE2=m
  1076. +CONFIG_INPUT_KEYSPAN_REMOTE=m
  1077. +CONFIG_INPUT_POWERMATE=m
  1078. +CONFIG_INPUT_YEALINK=m
  1079. +CONFIG_INPUT_CM109=m
  1080. +CONFIG_INPUT_UINPUT=m
  1081. +CONFIG_INPUT_GPIO_ROTARY_ENCODER=m
  1082. +CONFIG_INPUT_ADXL34X=m
  1083. +CONFIG_INPUT_CMA3000=m
  1084. +CONFIG_SERIO=m
  1085. +CONFIG_SERIO_RAW=m
  1086. +CONFIG_GAMEPORT=m
  1087. +CONFIG_GAMEPORT_NS558=m
  1088. +CONFIG_GAMEPORT_L4=m
  1089. +# CONFIG_LEGACY_PTYS is not set
  1090. +# CONFIG_DEVKMEM is not set
  1091. +CONFIG_SERIAL_AMBA_PL011=y
  1092. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  1093. +CONFIG_TTY_PRINTK=y
  1094. +CONFIG_HW_RANDOM=y
  1095. +CONFIG_HW_RANDOM_BCM2708=m
  1096. +CONFIG_RAW_DRIVER=y
  1097. +CONFIG_BRCM_CHAR_DRIVERS=y
  1098. +CONFIG_BCM_VC_CMA=y
  1099. +CONFIG_I2C=y
  1100. +CONFIG_I2C_CHARDEV=m
  1101. +CONFIG_I2C_BCM2708=m
  1102. +CONFIG_SPI=y
  1103. +CONFIG_SPI_BCM2708=m
  1104. +CONFIG_SPI_SPIDEV=y
  1105. +CONFIG_GPIO_SYSFS=y
  1106. +CONFIG_W1=m
  1107. +CONFIG_W1_MASTER_DS2490=m
  1108. +CONFIG_W1_MASTER_DS2482=m
  1109. +CONFIG_W1_MASTER_DS1WM=m
  1110. +CONFIG_W1_MASTER_GPIO=m
  1111. +CONFIG_W1_SLAVE_THERM=m
  1112. +CONFIG_W1_SLAVE_SMEM=m
  1113. +CONFIG_W1_SLAVE_DS2408=m
  1114. +CONFIG_W1_SLAVE_DS2413=m
  1115. +CONFIG_W1_SLAVE_DS2423=m
  1116. +CONFIG_W1_SLAVE_DS2431=m
  1117. +CONFIG_W1_SLAVE_DS2433=m
  1118. +CONFIG_W1_SLAVE_DS2760=m
  1119. +CONFIG_W1_SLAVE_DS2780=m
  1120. +CONFIG_W1_SLAVE_DS2781=m
  1121. +CONFIG_W1_SLAVE_DS28E04=m
  1122. +CONFIG_W1_SLAVE_BQ27000=m
  1123. +CONFIG_BATTERY_DS2760=m
  1124. +# CONFIG_HWMON is not set
  1125. +CONFIG_THERMAL=y
  1126. +CONFIG_THERMAL_BCM2835=y
  1127. +CONFIG_WATCHDOG=y
  1128. +CONFIG_BCM2708_WDT=m
  1129. +CONFIG_MEDIA_SUPPORT=m
  1130. +CONFIG_MEDIA_CAMERA_SUPPORT=y
  1131. +CONFIG_MEDIA_ANALOG_TV_SUPPORT=y
  1132. +CONFIG_MEDIA_DIGITAL_TV_SUPPORT=y
  1133. +CONFIG_MEDIA_RADIO_SUPPORT=y
  1134. +CONFIG_MEDIA_RC_SUPPORT=y
  1135. +CONFIG_MEDIA_CONTROLLER=y
  1136. +CONFIG_LIRC=m
  1137. +CONFIG_RC_DEVICES=y
  1138. +CONFIG_RC_ATI_REMOTE=m
  1139. +CONFIG_IR_IMON=m
  1140. +CONFIG_IR_MCEUSB=m
  1141. +CONFIG_IR_REDRAT3=m
  1142. +CONFIG_IR_STREAMZAP=m
  1143. +CONFIG_IR_IGUANA=m
  1144. +CONFIG_IR_TTUSBIR=m
  1145. +CONFIG_RC_LOOPBACK=m
  1146. +CONFIG_IR_GPIO_CIR=m
  1147. +CONFIG_MEDIA_USB_SUPPORT=y
  1148. +CONFIG_USB_VIDEO_CLASS=m
  1149. +CONFIG_USB_M5602=m
  1150. +CONFIG_USB_STV06XX=m
  1151. +CONFIG_USB_GL860=m
  1152. +CONFIG_USB_GSPCA_BENQ=m
  1153. +CONFIG_USB_GSPCA_CONEX=m
  1154. +CONFIG_USB_GSPCA_CPIA1=m
  1155. +CONFIG_USB_GSPCA_ETOMS=m
  1156. +CONFIG_USB_GSPCA_FINEPIX=m
  1157. +CONFIG_USB_GSPCA_JEILINJ=m
  1158. +CONFIG_USB_GSPCA_JL2005BCD=m
  1159. +CONFIG_USB_GSPCA_KINECT=m
  1160. +CONFIG_USB_GSPCA_KONICA=m
  1161. +CONFIG_USB_GSPCA_MARS=m
  1162. +CONFIG_USB_GSPCA_MR97310A=m
  1163. +CONFIG_USB_GSPCA_NW80X=m
  1164. +CONFIG_USB_GSPCA_OV519=m
  1165. +CONFIG_USB_GSPCA_OV534=m
  1166. +CONFIG_USB_GSPCA_OV534_9=m
  1167. +CONFIG_USB_GSPCA_PAC207=m
  1168. +CONFIG_USB_GSPCA_PAC7302=m
  1169. +CONFIG_USB_GSPCA_PAC7311=m
  1170. +CONFIG_USB_GSPCA_SE401=m
  1171. +CONFIG_USB_GSPCA_SN9C2028=m
  1172. +CONFIG_USB_GSPCA_SN9C20X=m
  1173. +CONFIG_USB_GSPCA_SONIXB=m
  1174. +CONFIG_USB_GSPCA_SONIXJ=m
  1175. +CONFIG_USB_GSPCA_SPCA500=m
  1176. +CONFIG_USB_GSPCA_SPCA501=m
  1177. +CONFIG_USB_GSPCA_SPCA505=m
  1178. +CONFIG_USB_GSPCA_SPCA506=m
  1179. +CONFIG_USB_GSPCA_SPCA508=m
  1180. +CONFIG_USB_GSPCA_SPCA561=m
  1181. +CONFIG_USB_GSPCA_SPCA1528=m
  1182. +CONFIG_USB_GSPCA_SQ905=m
  1183. +CONFIG_USB_GSPCA_SQ905C=m
  1184. +CONFIG_USB_GSPCA_SQ930X=m
  1185. +CONFIG_USB_GSPCA_STK014=m
  1186. +CONFIG_USB_GSPCA_STV0680=m
  1187. +CONFIG_USB_GSPCA_SUNPLUS=m
  1188. +CONFIG_USB_GSPCA_T613=m
  1189. +CONFIG_USB_GSPCA_TOPRO=m
  1190. +CONFIG_USB_GSPCA_TV8532=m
  1191. +CONFIG_USB_GSPCA_VC032X=m
  1192. +CONFIG_USB_GSPCA_VICAM=m
  1193. +CONFIG_USB_GSPCA_XIRLINK_CIT=m
  1194. +CONFIG_USB_GSPCA_ZC3XX=m
  1195. +CONFIG_USB_PWC=m
  1196. +CONFIG_VIDEO_CPIA2=m
  1197. +CONFIG_USB_ZR364XX=m
  1198. +CONFIG_USB_STKWEBCAM=m
  1199. +CONFIG_USB_S2255=m
  1200. +CONFIG_USB_SN9C102=m
  1201. +CONFIG_VIDEO_PVRUSB2=m
  1202. +CONFIG_VIDEO_HDPVR=m
  1203. +CONFIG_VIDEO_TLG2300=m
  1204. +CONFIG_VIDEO_USBVISION=m
  1205. +CONFIG_VIDEO_AU0828=m
  1206. +CONFIG_VIDEO_CX231XX=m
  1207. +CONFIG_VIDEO_CX231XX_ALSA=m
  1208. +CONFIG_VIDEO_CX231XX_DVB=m
  1209. +CONFIG_VIDEO_TM6000=m
  1210. +CONFIG_VIDEO_TM6000_ALSA=m
  1211. +CONFIG_VIDEO_TM6000_DVB=m
  1212. +CONFIG_DVB_USB=m
  1213. +CONFIG_DVB_USB_A800=m
  1214. +CONFIG_DVB_USB_DIBUSB_MB=m
  1215. +CONFIG_DVB_USB_DIBUSB_MB_FAULTY=y
  1216. +CONFIG_DVB_USB_DIBUSB_MC=m
  1217. +CONFIG_DVB_USB_DIB0700=m
  1218. +CONFIG_DVB_USB_UMT_010=m
  1219. +CONFIG_DVB_USB_CXUSB=m
  1220. +CONFIG_DVB_USB_M920X=m
  1221. +CONFIG_DVB_USB_DIGITV=m
  1222. +CONFIG_DVB_USB_VP7045=m
  1223. +CONFIG_DVB_USB_VP702X=m
  1224. +CONFIG_DVB_USB_GP8PSK=m
  1225. +CONFIG_DVB_USB_NOVA_T_USB2=m
  1226. +CONFIG_DVB_USB_TTUSB2=m
  1227. +CONFIG_DVB_USB_DTT200U=m
  1228. +CONFIG_DVB_USB_OPERA1=m
  1229. +CONFIG_DVB_USB_AF9005=m
  1230. +CONFIG_DVB_USB_AF9005_REMOTE=m
  1231. +CONFIG_DVB_USB_PCTV452E=m
  1232. +CONFIG_DVB_USB_DW2102=m
  1233. +CONFIG_DVB_USB_CINERGY_T2=m
  1234. +CONFIG_DVB_USB_DTV5100=m
  1235. +CONFIG_DVB_USB_FRIIO=m
  1236. +CONFIG_DVB_USB_AZ6027=m
  1237. +CONFIG_DVB_USB_TECHNISAT_USB2=m
  1238. +CONFIG_DVB_USB_V2=m
  1239. +CONFIG_DVB_USB_AF9015=m
  1240. +CONFIG_DVB_USB_AF9035=m
  1241. +CONFIG_DVB_USB_ANYSEE=m
  1242. +CONFIG_DVB_USB_AU6610=m
  1243. +CONFIG_DVB_USB_AZ6007=m
  1244. +CONFIG_DVB_USB_CE6230=m
  1245. +CONFIG_DVB_USB_EC168=m
  1246. +CONFIG_DVB_USB_GL861=m
  1247. +CONFIG_DVB_USB_IT913X=m
  1248. +CONFIG_DVB_USB_LME2510=m
  1249. +CONFIG_DVB_USB_MXL111SF=m
  1250. +CONFIG_DVB_USB_RTL28XXU=m
  1251. +CONFIG_SMS_USB_DRV=m
  1252. +CONFIG_DVB_B2C2_FLEXCOP_USB=m
  1253. +CONFIG_VIDEO_EM28XX=m
  1254. +CONFIG_VIDEO_EM28XX_ALSA=m
  1255. +CONFIG_VIDEO_EM28XX_DVB=m
  1256. +CONFIG_V4L_PLATFORM_DRIVERS=y
  1257. +CONFIG_VIDEO_BCM2835=y
  1258. +CONFIG_VIDEO_BCM2835_MMAL=m
  1259. +CONFIG_RADIO_SI470X=y
  1260. +CONFIG_USB_SI470X=m
  1261. +CONFIG_I2C_SI470X=m
  1262. +CONFIG_USB_MR800=m
  1263. +CONFIG_USB_DSBR=m
  1264. +CONFIG_RADIO_SHARK=m
  1265. +CONFIG_RADIO_SHARK2=m
  1266. +CONFIG_RADIO_SI4713=m
  1267. +CONFIG_USB_KEENE=m
  1268. +CONFIG_USB_MA901=m
  1269. +CONFIG_RADIO_TEA5764=m
  1270. +CONFIG_RADIO_SAA7706H=m
  1271. +CONFIG_RADIO_TEF6862=m
  1272. +CONFIG_RADIO_WL1273=m
  1273. +CONFIG_RADIO_WL128X=m
  1274. +CONFIG_FB=y
  1275. +CONFIG_FB_BCM2708=y
  1276. +# CONFIG_BACKLIGHT_GENERIC is not set
  1277. +CONFIG_FRAMEBUFFER_CONSOLE=y
  1278. +CONFIG_LOGO=y
  1279. +# CONFIG_LOGO_LINUX_MONO is not set
  1280. +# CONFIG_LOGO_LINUX_VGA16 is not set
  1281. +CONFIG_SOUND=y
  1282. +CONFIG_SND=m
  1283. +CONFIG_SND_SEQUENCER=m
  1284. +CONFIG_SND_SEQ_DUMMY=m
  1285. +CONFIG_SND_MIXER_OSS=m
  1286. +CONFIG_SND_PCM_OSS=m
  1287. +CONFIG_SND_SEQUENCER_OSS=y
  1288. +CONFIG_SND_HRTIMER=m
  1289. +CONFIG_SND_DUMMY=m
  1290. +CONFIG_SND_ALOOP=m
  1291. +CONFIG_SND_VIRMIDI=m
  1292. +CONFIG_SND_MTPAV=m
  1293. +CONFIG_SND_SERIAL_U16550=m
  1294. +CONFIG_SND_MPU401=m
  1295. +CONFIG_SND_BCM2835=m
  1296. +CONFIG_SND_USB_AUDIO=m
  1297. +CONFIG_SND_USB_UA101=m
  1298. +CONFIG_SND_USB_CAIAQ=m
  1299. +CONFIG_SND_USB_CAIAQ_INPUT=y
  1300. +CONFIG_SND_USB_6FIRE=m
  1301. +CONFIG_SND_SOC=m
  1302. +CONFIG_SND_SOC_DMAENGINE_PCM=y
  1303. +CONFIG_SND_SOC_GENERIC_DMAENGINE_PCM=y
  1304. +CONFIG_SND_SOC_WM8804=m
  1305. +CONFIG_SND_BCM2708_SOC_I2S=m
  1306. +CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC=m
  1307. +CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI=m
  1308. +CONFIG_SND_BCM2708_SOC_RPI_DAC=m
  1309. +CONFIG_SND_SOC_I2C_AND_SPI=m
  1310. +CONFIG_SND_SOC_PCM5102A=m
  1311. +CONFIG_SND_SOC_PCM1794A=m
  1312. +CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m
  1313. +CONFIG_SOUND_PRIME=m
  1314. +CONFIG_HIDRAW=y
  1315. +CONFIG_HID_A4TECH=m
  1316. +CONFIG_HID_ACRUX=m
  1317. +CONFIG_HID_APPLE=m
  1318. +CONFIG_HID_BELKIN=m
  1319. +CONFIG_HID_CHERRY=m
  1320. +CONFIG_HID_CHICONY=m
  1321. +CONFIG_HID_CYPRESS=m
  1322. +CONFIG_HID_DRAGONRISE=m
  1323. +CONFIG_HID_EMS_FF=m
  1324. +CONFIG_HID_ELECOM=m
  1325. +CONFIG_HID_EZKEY=m
  1326. +CONFIG_HID_HOLTEK=m
  1327. +CONFIG_HID_KEYTOUCH=m
  1328. +CONFIG_HID_KYE=m
  1329. +CONFIG_HID_UCLOGIC=m
  1330. +CONFIG_HID_WALTOP=m
  1331. +CONFIG_HID_GYRATION=m
  1332. +CONFIG_HID_TWINHAN=m
  1333. +CONFIG_HID_KENSINGTON=m
  1334. +CONFIG_HID_LCPOWER=m
  1335. +CONFIG_HID_LOGITECH=m
  1336. +CONFIG_HID_MAGICMOUSE=m
  1337. +CONFIG_HID_MICROSOFT=m
  1338. +CONFIG_HID_MONTEREY=m
  1339. +CONFIG_HID_MULTITOUCH=m
  1340. +CONFIG_HID_NTRIG=m
  1341. +CONFIG_HID_ORTEK=m
  1342. +CONFIG_HID_PANTHERLORD=m
  1343. +CONFIG_HID_PETALYNX=m
  1344. +CONFIG_HID_PICOLCD=m
  1345. +CONFIG_HID_ROCCAT=m
  1346. +CONFIG_HID_SAMSUNG=m
  1347. +CONFIG_HID_SONY=m
  1348. +CONFIG_HID_SPEEDLINK=m
  1349. +CONFIG_HID_SUNPLUS=m
  1350. +CONFIG_HID_GREENASIA=m
  1351. +CONFIG_HID_SMARTJOYPLUS=m
  1352. +CONFIG_HID_TOPSEED=m
  1353. +CONFIG_HID_THINGM=m
  1354. +CONFIG_HID_THRUSTMASTER=m
  1355. +CONFIG_HID_WACOM=m
  1356. +CONFIG_HID_WIIMOTE=m
  1357. +CONFIG_HID_ZEROPLUS=m
  1358. +CONFIG_HID_ZYDACRON=m
  1359. +CONFIG_HID_PID=y
  1360. +CONFIG_USB_HIDDEV=y
  1361. +CONFIG_USB=y
  1362. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  1363. +CONFIG_USB_MON=m
  1364. +CONFIG_USB_DWCOTG=y
  1365. +CONFIG_USB_PRINTER=m
  1366. +CONFIG_USB_STORAGE=y
  1367. +CONFIG_USB_STORAGE_REALTEK=m
  1368. +CONFIG_USB_STORAGE_DATAFAB=m
  1369. +CONFIG_USB_STORAGE_FREECOM=m
  1370. +CONFIG_USB_STORAGE_ISD200=m
  1371. +CONFIG_USB_STORAGE_USBAT=m
  1372. +CONFIG_USB_STORAGE_SDDR09=m
  1373. +CONFIG_USB_STORAGE_SDDR55=m
  1374. +CONFIG_USB_STORAGE_JUMPSHOT=m
  1375. +CONFIG_USB_STORAGE_ALAUDA=m
  1376. +CONFIG_USB_STORAGE_ONETOUCH=m
  1377. +CONFIG_USB_STORAGE_KARMA=m
  1378. +CONFIG_USB_STORAGE_CYPRESS_ATACB=m
  1379. +CONFIG_USB_STORAGE_ENE_UB6250=m
  1380. +CONFIG_USB_MDC800=m
  1381. +CONFIG_USB_MICROTEK=m
  1382. +CONFIG_USB_SERIAL=m
  1383. +CONFIG_USB_SERIAL_GENERIC=y
  1384. +CONFIG_USB_SERIAL_AIRCABLE=m
  1385. +CONFIG_USB_SERIAL_ARK3116=m
  1386. +CONFIG_USB_SERIAL_BELKIN=m
  1387. +CONFIG_USB_SERIAL_CH341=m
  1388. +CONFIG_USB_SERIAL_WHITEHEAT=m
  1389. +CONFIG_USB_SERIAL_DIGI_ACCELEPORT=m
  1390. +CONFIG_USB_SERIAL_CP210X=m
  1391. +CONFIG_USB_SERIAL_CYPRESS_M8=m
  1392. +CONFIG_USB_SERIAL_EMPEG=m
  1393. +CONFIG_USB_SERIAL_FTDI_SIO=m
  1394. +CONFIG_USB_SERIAL_VISOR=m
  1395. +CONFIG_USB_SERIAL_IPAQ=m
  1396. +CONFIG_USB_SERIAL_IR=m
  1397. +CONFIG_USB_SERIAL_EDGEPORT=m
  1398. +CONFIG_USB_SERIAL_EDGEPORT_TI=m
  1399. +CONFIG_USB_SERIAL_F81232=m
  1400. +CONFIG_USB_SERIAL_GARMIN=m
  1401. +CONFIG_USB_SERIAL_IPW=m
  1402. +CONFIG_USB_SERIAL_IUU=m
  1403. +CONFIG_USB_SERIAL_KEYSPAN_PDA=m
  1404. +CONFIG_USB_SERIAL_KEYSPAN=m
  1405. +CONFIG_USB_SERIAL_KLSI=m
  1406. +CONFIG_USB_SERIAL_KOBIL_SCT=m
  1407. +CONFIG_USB_SERIAL_MCT_U232=m
  1408. +CONFIG_USB_SERIAL_METRO=m
  1409. +CONFIG_USB_SERIAL_MOS7720=m
  1410. +CONFIG_USB_SERIAL_MOS7840=m
  1411. +CONFIG_USB_SERIAL_NAVMAN=m
  1412. +CONFIG_USB_SERIAL_PL2303=m
  1413. +CONFIG_USB_SERIAL_OTI6858=m
  1414. +CONFIG_USB_SERIAL_QCAUX=m
  1415. +CONFIG_USB_SERIAL_QUALCOMM=m
  1416. +CONFIG_USB_SERIAL_SPCP8X5=m
  1417. +CONFIG_USB_SERIAL_SAFE=m
  1418. +CONFIG_USB_SERIAL_SIERRAWIRELESS=m
  1419. +CONFIG_USB_SERIAL_SYMBOL=m
  1420. +CONFIG_USB_SERIAL_TI=m
  1421. +CONFIG_USB_SERIAL_CYBERJACK=m
  1422. +CONFIG_USB_SERIAL_XIRCOM=m
  1423. +CONFIG_USB_SERIAL_OPTION=m
  1424. +CONFIG_USB_SERIAL_OMNINET=m
  1425. +CONFIG_USB_SERIAL_OPTICON=m
  1426. +CONFIG_USB_SERIAL_XSENS_MT=m
  1427. +CONFIG_USB_SERIAL_WISHBONE=m
  1428. +CONFIG_USB_SERIAL_ZTE=m
  1429. +CONFIG_USB_SERIAL_SSU100=m
  1430. +CONFIG_USB_SERIAL_QT2=m
  1431. +CONFIG_USB_SERIAL_DEBUG=m
  1432. +CONFIG_USB_EMI62=m
  1433. +CONFIG_USB_EMI26=m
  1434. +CONFIG_USB_ADUTUX=m
  1435. +CONFIG_USB_SEVSEG=m
  1436. +CONFIG_USB_RIO500=m
  1437. +CONFIG_USB_LEGOTOWER=m
  1438. +CONFIG_USB_LCD=m
  1439. +CONFIG_USB_LED=m
  1440. +CONFIG_USB_CYPRESS_CY7C63=m
  1441. +CONFIG_USB_CYTHERM=m
  1442. +CONFIG_USB_IDMOUSE=m
  1443. +CONFIG_USB_FTDI_ELAN=m
  1444. +CONFIG_USB_APPLEDISPLAY=m
  1445. +CONFIG_USB_LD=m
  1446. +CONFIG_USB_TRANCEVIBRATOR=m
  1447. +CONFIG_USB_IOWARRIOR=m
  1448. +CONFIG_USB_TEST=m
  1449. +CONFIG_USB_ISIGHTFW=m
  1450. +CONFIG_USB_YUREX=m
  1451. +CONFIG_MMC=y
  1452. +CONFIG_MMC_BLOCK_MINORS=32
  1453. +CONFIG_MMC_SDHCI=y
  1454. +CONFIG_MMC_SDHCI_PLTFM=y
  1455. +CONFIG_MMC_SDHCI_BCM2708=y
  1456. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  1457. +CONFIG_MMC_SPI=m
  1458. +CONFIG_LEDS_GPIO=m
  1459. +CONFIG_LEDS_TRIGGER_TIMER=y
  1460. +CONFIG_LEDS_TRIGGER_ONESHOT=y
  1461. +CONFIG_LEDS_TRIGGER_HEARTBEAT=y
  1462. +CONFIG_LEDS_TRIGGER_BACKLIGHT=y
  1463. +CONFIG_LEDS_TRIGGER_CPU=y
  1464. +CONFIG_LEDS_TRIGGER_GPIO=y
  1465. +CONFIG_LEDS_TRIGGER_DEFAULT_ON=y
  1466. +CONFIG_LEDS_TRIGGER_TRANSIENT=m
  1467. +CONFIG_LEDS_TRIGGER_CAMERA=m
  1468. +CONFIG_RTC_CLASS=y
  1469. +# CONFIG_RTC_HCTOSYS is not set
  1470. +CONFIG_RTC_DRV_DS1307=m
  1471. +CONFIG_RTC_DRV_DS1374=m
  1472. +CONFIG_RTC_DRV_DS1672=m
  1473. +CONFIG_RTC_DRV_DS3232=m
  1474. +CONFIG_RTC_DRV_MAX6900=m
  1475. +CONFIG_RTC_DRV_RS5C372=m
  1476. +CONFIG_RTC_DRV_ISL1208=m
  1477. +CONFIG_RTC_DRV_ISL12022=m
  1478. +CONFIG_RTC_DRV_X1205=m
  1479. +CONFIG_RTC_DRV_PCF8523=m
  1480. +CONFIG_RTC_DRV_PCF8563=m
  1481. +CONFIG_RTC_DRV_PCF8583=m
  1482. +CONFIG_RTC_DRV_M41T80=m
  1483. +CONFIG_RTC_DRV_BQ32K=m
  1484. +CONFIG_RTC_DRV_S35390A=m
  1485. +CONFIG_RTC_DRV_FM3130=m
  1486. +CONFIG_RTC_DRV_RX8581=m
  1487. +CONFIG_RTC_DRV_RX8025=m
  1488. +CONFIG_RTC_DRV_EM3027=m
  1489. +CONFIG_RTC_DRV_RV3029C2=m
  1490. +CONFIG_RTC_DRV_M41T93=m
  1491. +CONFIG_RTC_DRV_M41T94=m
  1492. +CONFIG_RTC_DRV_DS1305=m
  1493. +CONFIG_RTC_DRV_DS1390=m
  1494. +CONFIG_RTC_DRV_MAX6902=m
  1495. +CONFIG_RTC_DRV_R9701=m
  1496. +CONFIG_RTC_DRV_RS5C348=m
  1497. +CONFIG_RTC_DRV_DS3234=m
  1498. +CONFIG_RTC_DRV_PCF2123=m
  1499. +CONFIG_RTC_DRV_RX4581=m
  1500. +CONFIG_DMADEVICES=y
  1501. +CONFIG_DMA_BCM2708=m
  1502. +CONFIG_DMA_ENGINE=y
  1503. +CONFIG_DMA_VIRTUAL_CHANNELS=m
  1504. +CONFIG_UIO=m
  1505. +CONFIG_UIO_PDRV_GENIRQ=m
  1506. +CONFIG_STAGING=y
  1507. +CONFIG_W35UND=m
  1508. +CONFIG_PRISM2_USB=m
  1509. +CONFIG_R8712U=m
  1510. +CONFIG_VT6656=m
  1511. +CONFIG_SPEAKUP=m
  1512. +CONFIG_SPEAKUP_SYNTH_SOFT=m
  1513. +CONFIG_STAGING_MEDIA=y
  1514. +CONFIG_DVB_AS102=m
  1515. +CONFIG_LIRC_STAGING=y
  1516. +CONFIG_LIRC_IGORPLUGUSB=m
  1517. +CONFIG_LIRC_IMON=m
  1518. +CONFIG_LIRC_RPI=m
  1519. +CONFIG_LIRC_SASEM=m
  1520. +CONFIG_LIRC_SERIAL=m
  1521. +# CONFIG_IOMMU_SUPPORT is not set
  1522. +CONFIG_EXT4_FS=y
  1523. +CONFIG_EXT4_FS_POSIX_ACL=y
  1524. +CONFIG_EXT4_FS_SECURITY=y
  1525. +CONFIG_REISERFS_FS=m
  1526. +CONFIG_REISERFS_FS_XATTR=y
  1527. +CONFIG_REISERFS_FS_POSIX_ACL=y
  1528. +CONFIG_REISERFS_FS_SECURITY=y
  1529. +CONFIG_JFS_FS=m
  1530. +CONFIG_JFS_POSIX_ACL=y
  1531. +CONFIG_JFS_SECURITY=y
  1532. +CONFIG_JFS_STATISTICS=y
  1533. +CONFIG_XFS_FS=m
  1534. +CONFIG_XFS_QUOTA=y
  1535. +CONFIG_XFS_POSIX_ACL=y
  1536. +CONFIG_XFS_RT=y
  1537. +CONFIG_GFS2_FS=m
  1538. +CONFIG_OCFS2_FS=m
  1539. +CONFIG_BTRFS_FS=m
  1540. +CONFIG_BTRFS_FS_POSIX_ACL=y
  1541. +CONFIG_NILFS2_FS=m
  1542. +CONFIG_FANOTIFY=y
  1543. +CONFIG_QFMT_V1=m
  1544. +CONFIG_QFMT_V2=m
  1545. +CONFIG_AUTOFS4_FS=y
  1546. +CONFIG_FUSE_FS=m
  1547. +CONFIG_CUSE=m
  1548. +CONFIG_FSCACHE=y
  1549. +CONFIG_FSCACHE_STATS=y
  1550. +CONFIG_FSCACHE_HISTOGRAM=y
  1551. +CONFIG_CACHEFILES=y
  1552. +CONFIG_ISO9660_FS=m
  1553. +CONFIG_JOLIET=y
  1554. +CONFIG_ZISOFS=y
  1555. +CONFIG_UDF_FS=m
  1556. +CONFIG_MSDOS_FS=y
  1557. +CONFIG_VFAT_FS=y
  1558. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  1559. +CONFIG_NTFS_FS=m
  1560. +CONFIG_NTFS_RW=y
  1561. +CONFIG_TMPFS=y
  1562. +CONFIG_TMPFS_POSIX_ACL=y
  1563. +CONFIG_CONFIGFS_FS=y
  1564. +CONFIG_ECRYPT_FS=m
  1565. +CONFIG_HFS_FS=m
  1566. +CONFIG_HFSPLUS_FS=m
  1567. +CONFIG_SQUASHFS=m
  1568. +CONFIG_SQUASHFS_XATTR=y
  1569. +CONFIG_SQUASHFS_LZO=y
  1570. +CONFIG_SQUASHFS_XZ=y
  1571. +CONFIG_F2FS_FS=y
  1572. +CONFIG_NFS_FS=y
  1573. +CONFIG_NFS_V3_ACL=y
  1574. +CONFIG_NFS_V4=y
  1575. +CONFIG_ROOT_NFS=y
  1576. +CONFIG_NFS_FSCACHE=y
  1577. +CONFIG_NFSD=m
  1578. +CONFIG_NFSD_V3_ACL=y
  1579. +CONFIG_NFSD_V4=y
  1580. +CONFIG_CIFS=m
  1581. +CONFIG_CIFS_WEAK_PW_HASH=y
  1582. +CONFIG_CIFS_XATTR=y
  1583. +CONFIG_CIFS_POSIX=y
  1584. +CONFIG_9P_FS=m
  1585. +CONFIG_9P_FS_POSIX_ACL=y
  1586. +CONFIG_NLS_DEFAULT="utf8"
  1587. +CONFIG_NLS_CODEPAGE_437=y
  1588. +CONFIG_NLS_CODEPAGE_737=m
  1589. +CONFIG_NLS_CODEPAGE_775=m
  1590. +CONFIG_NLS_CODEPAGE_850=m
  1591. +CONFIG_NLS_CODEPAGE_852=m
  1592. +CONFIG_NLS_CODEPAGE_855=m
  1593. +CONFIG_NLS_CODEPAGE_857=m
  1594. +CONFIG_NLS_CODEPAGE_860=m
  1595. +CONFIG_NLS_CODEPAGE_861=m
  1596. +CONFIG_NLS_CODEPAGE_862=m
  1597. +CONFIG_NLS_CODEPAGE_863=m
  1598. +CONFIG_NLS_CODEPAGE_864=m
  1599. +CONFIG_NLS_CODEPAGE_865=m
  1600. +CONFIG_NLS_CODEPAGE_866=m
  1601. +CONFIG_NLS_CODEPAGE_869=m
  1602. +CONFIG_NLS_CODEPAGE_936=m
  1603. +CONFIG_NLS_CODEPAGE_950=m
  1604. +CONFIG_NLS_CODEPAGE_932=m
  1605. +CONFIG_NLS_CODEPAGE_949=m
  1606. +CONFIG_NLS_CODEPAGE_874=m
  1607. +CONFIG_NLS_ISO8859_8=m
  1608. +CONFIG_NLS_CODEPAGE_1250=m
  1609. +CONFIG_NLS_CODEPAGE_1251=m
  1610. +CONFIG_NLS_ASCII=y
  1611. +CONFIG_NLS_ISO8859_1=m
  1612. +CONFIG_NLS_ISO8859_2=m
  1613. +CONFIG_NLS_ISO8859_3=m
  1614. +CONFIG_NLS_ISO8859_4=m
  1615. +CONFIG_NLS_ISO8859_5=m
  1616. +CONFIG_NLS_ISO8859_6=m
  1617. +CONFIG_NLS_ISO8859_7=m
  1618. +CONFIG_NLS_ISO8859_9=m
  1619. +CONFIG_NLS_ISO8859_13=m
  1620. +CONFIG_NLS_ISO8859_14=m
  1621. +CONFIG_NLS_ISO8859_15=m
  1622. +CONFIG_NLS_KOI8_R=m
  1623. +CONFIG_NLS_KOI8_U=m
  1624. +CONFIG_DLM=m
  1625. +CONFIG_PRINTK_TIME=y
  1626. +CONFIG_BOOT_PRINTK_DELAY=y
  1627. +CONFIG_DEBUG_FS=y
  1628. +CONFIG_DEBUG_MEMORY_INIT=y
  1629. +CONFIG_DETECT_HUNG_TASK=y
  1630. +CONFIG_TIMER_STATS=y
  1631. +# CONFIG_DEBUG_PREEMPT is not set
  1632. +CONFIG_LATENCYTOP=y
  1633. +# CONFIG_KPROBE_EVENT is not set
  1634. +CONFIG_KGDB=y
  1635. +CONFIG_KGDB_KDB=y
  1636. +CONFIG_KDB_KEYBOARD=y
  1637. +CONFIG_STRICT_DEVMEM=y
  1638. +CONFIG_CRYPTO_USER=m
  1639. +CONFIG_CRYPTO_NULL=m
  1640. +CONFIG_CRYPTO_CRYPTD=m
  1641. +CONFIG_CRYPTO_CBC=y
  1642. +CONFIG_CRYPTO_XTS=m
  1643. +CONFIG_CRYPTO_XCBC=m
  1644. +CONFIG_CRYPTO_SHA1_ARM=m
  1645. +CONFIG_CRYPTO_SHA512=m
  1646. +CONFIG_CRYPTO_TGR192=m
  1647. +CONFIG_CRYPTO_WP512=m
  1648. +CONFIG_CRYPTO_AES_ARM=m
  1649. +CONFIG_CRYPTO_CAST5=m
  1650. +CONFIG_CRYPTO_DES=y
  1651. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  1652. +# CONFIG_CRYPTO_HW is not set
  1653. +CONFIG_CRC_ITU_T=y
  1654. +CONFIG_LIBCRC32C=y
  1655. diff -Nur linux-3.12.26.orig/arch/arm/configs/bcmrpi_emergency_defconfig linux-3.12.26/arch/arm/configs/bcmrpi_emergency_defconfig
  1656. --- linux-3.12.26.orig/arch/arm/configs/bcmrpi_emergency_defconfig 1970-01-01 01:00:00.000000000 +0100
  1657. +++ linux-3.12.26/arch/arm/configs/bcmrpi_emergency_defconfig 2014-08-06 16:50:13.777956685 +0200
  1658. @@ -0,0 +1,532 @@
  1659. +CONFIG_EXPERIMENTAL=y
  1660. +# CONFIG_LOCALVERSION_AUTO is not set
  1661. +CONFIG_SYSVIPC=y
  1662. +CONFIG_POSIX_MQUEUE=y
  1663. +CONFIG_BSD_PROCESS_ACCT=y
  1664. +CONFIG_BSD_PROCESS_ACCT_V3=y
  1665. +CONFIG_FHANDLE=y
  1666. +CONFIG_AUDIT=y
  1667. +CONFIG_IKCONFIG=y
  1668. +CONFIG_IKCONFIG_PROC=y
  1669. +CONFIG_BLK_DEV_INITRD=y
  1670. +CONFIG_INITRAMFS_SOURCE="../target_fs"
  1671. +CONFIG_CGROUP_FREEZER=y
  1672. +CONFIG_CGROUP_DEVICE=y
  1673. +CONFIG_CGROUP_CPUACCT=y
  1674. +CONFIG_RESOURCE_COUNTERS=y
  1675. +CONFIG_BLK_CGROUP=y
  1676. +CONFIG_NAMESPACES=y
  1677. +CONFIG_SCHED_AUTOGROUP=y
  1678. +CONFIG_EMBEDDED=y
  1679. +# CONFIG_COMPAT_BRK is not set
  1680. +CONFIG_SLAB=y
  1681. +CONFIG_PROFILING=y
  1682. +CONFIG_OPROFILE=m
  1683. +CONFIG_KPROBES=y
  1684. +CONFIG_MODULES=y
  1685. +CONFIG_MODULE_UNLOAD=y
  1686. +CONFIG_MODVERSIONS=y
  1687. +CONFIG_MODULE_SRCVERSION_ALL=y
  1688. +# CONFIG_BLK_DEV_BSG is not set
  1689. +CONFIG_BLK_DEV_THROTTLING=y
  1690. +CONFIG_CFQ_GROUP_IOSCHED=y
  1691. +CONFIG_ARCH_BCM2708=y
  1692. +CONFIG_NO_HZ=y
  1693. +CONFIG_HIGH_RES_TIMERS=y
  1694. +CONFIG_AEABI=y
  1695. +CONFIG_SECCOMP=y
  1696. +CONFIG_CC_STACKPROTECTOR=y
  1697. +CONFIG_ZBOOT_ROM_TEXT=0x0
  1698. +CONFIG_ZBOOT_ROM_BSS=0x0
  1699. +CONFIG_CMDLINE="dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext3 rootwait"
  1700. +CONFIG_KEXEC=y
  1701. +CONFIG_CPU_IDLE=y
  1702. +CONFIG_VFP=y
  1703. +CONFIG_BINFMT_MISC=m
  1704. +CONFIG_NET=y
  1705. +CONFIG_PACKET=y
  1706. +CONFIG_UNIX=y
  1707. +CONFIG_XFRM_USER=y
  1708. +CONFIG_NET_KEY=m
  1709. +CONFIG_INET=y
  1710. +CONFIG_IP_MULTICAST=y
  1711. +CONFIG_IP_PNP=y
  1712. +CONFIG_IP_PNP_DHCP=y
  1713. +CONFIG_IP_PNP_RARP=y
  1714. +CONFIG_SYN_COOKIES=y
  1715. +# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
  1716. +# CONFIG_INET_XFRM_MODE_TUNNEL is not set
  1717. +# CONFIG_INET_XFRM_MODE_BEET is not set
  1718. +# CONFIG_INET_LRO is not set
  1719. +# CONFIG_INET_DIAG is not set
  1720. +# CONFIG_IPV6 is not set
  1721. +CONFIG_NET_PKTGEN=m
  1722. +CONFIG_IRDA=m
  1723. +CONFIG_IRLAN=m
  1724. +CONFIG_IRCOMM=m
  1725. +CONFIG_IRDA_ULTRA=y
  1726. +CONFIG_IRDA_CACHE_LAST_LSAP=y
  1727. +CONFIG_IRDA_FAST_RR=y
  1728. +CONFIG_IRTTY_SIR=m
  1729. +CONFIG_KINGSUN_DONGLE=m
  1730. +CONFIG_KSDAZZLE_DONGLE=m
  1731. +CONFIG_KS959_DONGLE=m
  1732. +CONFIG_USB_IRDA=m
  1733. +CONFIG_SIGMATEL_FIR=m
  1734. +CONFIG_MCS_FIR=m
  1735. +CONFIG_BT=m
  1736. +CONFIG_BT_L2CAP=y
  1737. +CONFIG_BT_SCO=y
  1738. +CONFIG_BT_RFCOMM=m
  1739. +CONFIG_BT_RFCOMM_TTY=y
  1740. +CONFIG_BT_BNEP=m
  1741. +CONFIG_BT_BNEP_MC_FILTER=y
  1742. +CONFIG_BT_BNEP_PROTO_FILTER=y
  1743. +CONFIG_BT_HIDP=m
  1744. +CONFIG_BT_HCIBTUSB=m
  1745. +CONFIG_BT_HCIBCM203X=m
  1746. +CONFIG_BT_HCIBPA10X=m
  1747. +CONFIG_BT_HCIBFUSB=m
  1748. +CONFIG_BT_HCIVHCI=m
  1749. +CONFIG_BT_MRVL=m
  1750. +CONFIG_BT_MRVL_SDIO=m
  1751. +CONFIG_BT_ATH3K=m
  1752. +CONFIG_CFG80211=m
  1753. +CONFIG_MAC80211=m
  1754. +CONFIG_MAC80211_RC_PID=y
  1755. +CONFIG_MAC80211_MESH=y
  1756. +CONFIG_WIMAX=m
  1757. +CONFIG_NET_9P=m
  1758. +CONFIG_NFC=m
  1759. +CONFIG_NFC_PN533=m
  1760. +CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
  1761. +CONFIG_BLK_DEV_LOOP=y
  1762. +CONFIG_BLK_DEV_CRYPTOLOOP=m
  1763. +CONFIG_BLK_DEV_NBD=m
  1764. +CONFIG_BLK_DEV_RAM=y
  1765. +CONFIG_CDROM_PKTCDVD=m
  1766. +CONFIG_MISC_DEVICES=y
  1767. +CONFIG_SCSI=y
  1768. +# CONFIG_SCSI_PROC_FS is not set
  1769. +CONFIG_BLK_DEV_SD=y
  1770. +CONFIG_BLK_DEV_SR=m
  1771. +CONFIG_SCSI_MULTI_LUN=y
  1772. +# CONFIG_SCSI_LOWLEVEL is not set
  1773. +CONFIG_MD=y
  1774. +CONFIG_NETDEVICES=y
  1775. +CONFIG_TUN=m
  1776. +CONFIG_PHYLIB=m
  1777. +CONFIG_MDIO_BITBANG=m
  1778. +CONFIG_NET_ETHERNET=y
  1779. +# CONFIG_NETDEV_1000 is not set
  1780. +# CONFIG_NETDEV_10000 is not set
  1781. +CONFIG_LIBERTAS_THINFIRM=m
  1782. +CONFIG_LIBERTAS_THINFIRM_USB=m
  1783. +CONFIG_AT76C50X_USB=m
  1784. +CONFIG_USB_ZD1201=m
  1785. +CONFIG_USB_NET_RNDIS_WLAN=m
  1786. +CONFIG_RTL8187=m
  1787. +CONFIG_MAC80211_HWSIM=m
  1788. +CONFIG_ATH_COMMON=m
  1789. +CONFIG_ATH9K=m
  1790. +CONFIG_ATH9K_HTC=m
  1791. +CONFIG_CARL9170=m
  1792. +CONFIG_B43=m
  1793. +CONFIG_B43LEGACY=m
  1794. +CONFIG_HOSTAP=m
  1795. +CONFIG_IWM=m
  1796. +CONFIG_LIBERTAS=m
  1797. +CONFIG_LIBERTAS_USB=m
  1798. +CONFIG_LIBERTAS_SDIO=m
  1799. +CONFIG_P54_COMMON=m
  1800. +CONFIG_P54_USB=m
  1801. +CONFIG_RT2X00=m
  1802. +CONFIG_RT2500USB=m
  1803. +CONFIG_RT73USB=m
  1804. +CONFIG_RT2800USB=m
  1805. +CONFIG_RT2800USB_RT53XX=y
  1806. +CONFIG_RTL8192CU=m
  1807. +CONFIG_WL1251=m
  1808. +CONFIG_WL12XX_MENU=m
  1809. +CONFIG_ZD1211RW=m
  1810. +CONFIG_MWIFIEX=m
  1811. +CONFIG_MWIFIEX_SDIO=m
  1812. +CONFIG_WIMAX_I2400M_USB=m
  1813. +CONFIG_USB_CATC=m
  1814. +CONFIG_USB_KAWETH=m
  1815. +CONFIG_USB_PEGASUS=m
  1816. +CONFIG_USB_RTL8150=m
  1817. +CONFIG_USB_USBNET=y
  1818. +CONFIG_USB_NET_AX8817X=m
  1819. +CONFIG_USB_NET_CDCETHER=m
  1820. +CONFIG_USB_NET_CDC_EEM=m
  1821. +CONFIG_USB_NET_DM9601=m
  1822. +CONFIG_USB_NET_SMSC75XX=m
  1823. +CONFIG_USB_NET_SMSC95XX=y
  1824. +CONFIG_USB_NET_GL620A=m
  1825. +CONFIG_USB_NET_NET1080=m
  1826. +CONFIG_USB_NET_PLUSB=m
  1827. +CONFIG_USB_NET_MCS7830=m
  1828. +CONFIG_USB_NET_CDC_SUBSET=m
  1829. +CONFIG_USB_ALI_M5632=y
  1830. +CONFIG_USB_AN2720=y
  1831. +CONFIG_USB_KC2190=y
  1832. +# CONFIG_USB_NET_ZAURUS is not set
  1833. +CONFIG_USB_NET_CX82310_ETH=m
  1834. +CONFIG_USB_NET_KALMIA=m
  1835. +CONFIG_USB_NET_INT51X1=m
  1836. +CONFIG_USB_IPHETH=m
  1837. +CONFIG_USB_SIERRA_NET=m
  1838. +CONFIG_USB_VL600=m
  1839. +CONFIG_PPP=m
  1840. +CONFIG_PPP_ASYNC=m
  1841. +CONFIG_PPP_SYNC_TTY=m
  1842. +CONFIG_PPP_DEFLATE=m
  1843. +CONFIG_PPP_BSDCOMP=m
  1844. +CONFIG_SLIP=m
  1845. +CONFIG_SLIP_COMPRESSED=y
  1846. +CONFIG_NETCONSOLE=m
  1847. +CONFIG_INPUT_POLLDEV=m
  1848. +# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
  1849. +CONFIG_INPUT_JOYDEV=m
  1850. +CONFIG_INPUT_EVDEV=m
  1851. +# CONFIG_INPUT_KEYBOARD is not set
  1852. +# CONFIG_INPUT_MOUSE is not set
  1853. +CONFIG_INPUT_MISC=y
  1854. +CONFIG_INPUT_AD714X=m
  1855. +CONFIG_INPUT_ATI_REMOTE=m
  1856. +CONFIG_INPUT_ATI_REMOTE2=m
  1857. +CONFIG_INPUT_KEYSPAN_REMOTE=m
  1858. +CONFIG_INPUT_POWERMATE=m
  1859. +CONFIG_INPUT_YEALINK=m
  1860. +CONFIG_INPUT_CM109=m
  1861. +CONFIG_INPUT_UINPUT=m
  1862. +CONFIG_INPUT_GPIO_ROTARY_ENCODER=m
  1863. +CONFIG_INPUT_ADXL34X=m
  1864. +CONFIG_INPUT_CMA3000=m
  1865. +CONFIG_SERIO=m
  1866. +CONFIG_SERIO_RAW=m
  1867. +CONFIG_GAMEPORT=m
  1868. +CONFIG_GAMEPORT_NS558=m
  1869. +CONFIG_GAMEPORT_L4=m
  1870. +CONFIG_VT_HW_CONSOLE_BINDING=y
  1871. +# CONFIG_LEGACY_PTYS is not set
  1872. +# CONFIG_DEVKMEM is not set
  1873. +CONFIG_SERIAL_AMBA_PL011=y
  1874. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  1875. +# CONFIG_HW_RANDOM is not set
  1876. +CONFIG_RAW_DRIVER=y
  1877. +CONFIG_GPIO_SYSFS=y
  1878. +# CONFIG_HWMON is not set
  1879. +CONFIG_WATCHDOG=y
  1880. +CONFIG_BCM2708_WDT=m
  1881. +# CONFIG_MFD_SUPPORT is not set
  1882. +CONFIG_FB=y
  1883. +CONFIG_FB_BCM2708=y
  1884. +CONFIG_FRAMEBUFFER_CONSOLE=y
  1885. +CONFIG_LOGO=y
  1886. +# CONFIG_LOGO_LINUX_MONO is not set
  1887. +# CONFIG_LOGO_LINUX_VGA16 is not set
  1888. +CONFIG_SOUND=y
  1889. +CONFIG_SND=m
  1890. +CONFIG_SND_SEQUENCER=m
  1891. +CONFIG_SND_SEQ_DUMMY=m
  1892. +CONFIG_SND_MIXER_OSS=m
  1893. +CONFIG_SND_PCM_OSS=m
  1894. +CONFIG_SND_SEQUENCER_OSS=y
  1895. +CONFIG_SND_HRTIMER=m
  1896. +CONFIG_SND_DUMMY=m
  1897. +CONFIG_SND_ALOOP=m
  1898. +CONFIG_SND_VIRMIDI=m
  1899. +CONFIG_SND_MTPAV=m
  1900. +CONFIG_SND_SERIAL_U16550=m
  1901. +CONFIG_SND_MPU401=m
  1902. +CONFIG_SND_BCM2835=m
  1903. +CONFIG_SND_USB_AUDIO=m
  1904. +CONFIG_SND_USB_UA101=m
  1905. +CONFIG_SND_USB_CAIAQ=m
  1906. +CONFIG_SND_USB_6FIRE=m
  1907. +CONFIG_SOUND_PRIME=m
  1908. +CONFIG_HID_PID=y
  1909. +CONFIG_USB_HIDDEV=y
  1910. +CONFIG_HID_A4TECH=m
  1911. +CONFIG_HID_ACRUX=m
  1912. +CONFIG_HID_APPLE=m
  1913. +CONFIG_HID_BELKIN=m
  1914. +CONFIG_HID_CHERRY=m
  1915. +CONFIG_HID_CHICONY=m
  1916. +CONFIG_HID_CYPRESS=m
  1917. +CONFIG_HID_DRAGONRISE=m
  1918. +CONFIG_HID_EMS_FF=m
  1919. +CONFIG_HID_ELECOM=m
  1920. +CONFIG_HID_EZKEY=m
  1921. +CONFIG_HID_HOLTEK=m
  1922. +CONFIG_HID_KEYTOUCH=m
  1923. +CONFIG_HID_KYE=m
  1924. +CONFIG_HID_UCLOGIC=m
  1925. +CONFIG_HID_WALTOP=m
  1926. +CONFIG_HID_GYRATION=m
  1927. +CONFIG_HID_TWINHAN=m
  1928. +CONFIG_HID_KENSINGTON=m
  1929. +CONFIG_HID_LCPOWER=m
  1930. +CONFIG_HID_LOGITECH=m
  1931. +CONFIG_HID_MAGICMOUSE=m
  1932. +CONFIG_HID_MICROSOFT=m
  1933. +CONFIG_HID_MONTEREY=m
  1934. +CONFIG_HID_MULTITOUCH=m
  1935. +CONFIG_HID_NTRIG=m
  1936. +CONFIG_HID_ORTEK=m
  1937. +CONFIG_HID_PANTHERLORD=m
  1938. +CONFIG_HID_PETALYNX=m
  1939. +CONFIG_HID_PICOLCD=m
  1940. +CONFIG_HID_QUANTA=m
  1941. +CONFIG_HID_ROCCAT=m
  1942. +CONFIG_HID_SAMSUNG=m
  1943. +CONFIG_HID_SONY=m
  1944. +CONFIG_HID_SPEEDLINK=m
  1945. +CONFIG_HID_SUNPLUS=m
  1946. +CONFIG_HID_GREENASIA=m
  1947. +CONFIG_HID_SMARTJOYPLUS=m
  1948. +CONFIG_HID_TOPSEED=m
  1949. +CONFIG_HID_THRUSTMASTER=m
  1950. +CONFIG_HID_WACOM=m
  1951. +CONFIG_HID_WIIMOTE=m
  1952. +CONFIG_HID_ZEROPLUS=m
  1953. +CONFIG_HID_ZYDACRON=m
  1954. +CONFIG_USB=y
  1955. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  1956. +CONFIG_USB_MON=m
  1957. +CONFIG_USB_DWCOTG=y
  1958. +CONFIG_USB_STORAGE=y
  1959. +CONFIG_USB_STORAGE_REALTEK=m
  1960. +CONFIG_USB_STORAGE_DATAFAB=m
  1961. +CONFIG_USB_STORAGE_FREECOM=m
  1962. +CONFIG_USB_STORAGE_ISD200=m
  1963. +CONFIG_USB_STORAGE_USBAT=m
  1964. +CONFIG_USB_STORAGE_SDDR09=m
  1965. +CONFIG_USB_STORAGE_SDDR55=m
  1966. +CONFIG_USB_STORAGE_JUMPSHOT=m
  1967. +CONFIG_USB_STORAGE_ALAUDA=m
  1968. +CONFIG_USB_STORAGE_ONETOUCH=m
  1969. +CONFIG_USB_STORAGE_KARMA=m
  1970. +CONFIG_USB_STORAGE_CYPRESS_ATACB=m
  1971. +CONFIG_USB_STORAGE_ENE_UB6250=m
  1972. +CONFIG_USB_UAS=y
  1973. +CONFIG_USB_LIBUSUAL=y
  1974. +CONFIG_USB_MDC800=m
  1975. +CONFIG_USB_MICROTEK=m
  1976. +CONFIG_USB_SERIAL=m
  1977. +CONFIG_USB_SERIAL_GENERIC=y
  1978. +CONFIG_USB_SERIAL_AIRCABLE=m
  1979. +CONFIG_USB_SERIAL_ARK3116=m
  1980. +CONFIG_USB_SERIAL_BELKIN=m
  1981. +CONFIG_USB_SERIAL_CH341=m
  1982. +CONFIG_USB_SERIAL_WHITEHEAT=m
  1983. +CONFIG_USB_SERIAL_DIGI_ACCELEPORT=m
  1984. +CONFIG_USB_SERIAL_CP210X=m
  1985. +CONFIG_USB_SERIAL_CYPRESS_M8=m
  1986. +CONFIG_USB_SERIAL_EMPEG=m
  1987. +CONFIG_USB_SERIAL_FTDI_SIO=m
  1988. +CONFIG_USB_SERIAL_FUNSOFT=m
  1989. +CONFIG_USB_SERIAL_VISOR=m
  1990. +CONFIG_USB_SERIAL_IPAQ=m
  1991. +CONFIG_USB_SERIAL_IR=m
  1992. +CONFIG_USB_SERIAL_EDGEPORT=m
  1993. +CONFIG_USB_SERIAL_EDGEPORT_TI=m
  1994. +CONFIG_USB_SERIAL_GARMIN=m
  1995. +CONFIG_USB_SERIAL_IPW=m
  1996. +CONFIG_USB_SERIAL_IUU=m
  1997. +CONFIG_USB_SERIAL_KEYSPAN_PDA=m
  1998. +CONFIG_USB_SERIAL_KEYSPAN=m
  1999. +CONFIG_USB_SERIAL_KLSI=m
  2000. +CONFIG_USB_SERIAL_KOBIL_SCT=m
  2001. +CONFIG_USB_SERIAL_MCT_U232=m
  2002. +CONFIG_USB_SERIAL_MOS7720=m
  2003. +CONFIG_USB_SERIAL_MOS7840=m
  2004. +CONFIG_USB_SERIAL_MOTOROLA=m
  2005. +CONFIG_USB_SERIAL_NAVMAN=m
  2006. +CONFIG_USB_SERIAL_PL2303=m
  2007. +CONFIG_USB_SERIAL_OTI6858=m
  2008. +CONFIG_USB_SERIAL_QCAUX=m
  2009. +CONFIG_USB_SERIAL_QUALCOMM=m
  2010. +CONFIG_USB_SERIAL_SPCP8X5=m
  2011. +CONFIG_USB_SERIAL_HP4X=m
  2012. +CONFIG_USB_SERIAL_SAFE=m
  2013. +CONFIG_USB_SERIAL_SIEMENS_MPI=m
  2014. +CONFIG_USB_SERIAL_SIERRAWIRELESS=m
  2015. +CONFIG_USB_SERIAL_SYMBOL=m
  2016. +CONFIG_USB_SERIAL_TI=m
  2017. +CONFIG_USB_SERIAL_CYBERJACK=m
  2018. +CONFIG_USB_SERIAL_XIRCOM=m
  2019. +CONFIG_USB_SERIAL_OPTION=m
  2020. +CONFIG_USB_SERIAL_OMNINET=m
  2021. +CONFIG_USB_SERIAL_OPTICON=m
  2022. +CONFIG_USB_SERIAL_VIVOPAY_SERIAL=m
  2023. +CONFIG_USB_SERIAL_ZIO=m
  2024. +CONFIG_USB_SERIAL_SSU100=m
  2025. +CONFIG_USB_SERIAL_DEBUG=m
  2026. +CONFIG_USB_EMI62=m
  2027. +CONFIG_USB_EMI26=m
  2028. +CONFIG_USB_ADUTUX=m
  2029. +CONFIG_USB_SEVSEG=m
  2030. +CONFIG_USB_RIO500=m
  2031. +CONFIG_USB_LEGOTOWER=m
  2032. +CONFIG_USB_LCD=m
  2033. +CONFIG_USB_LED=m
  2034. +CONFIG_USB_CYPRESS_CY7C63=m
  2035. +CONFIG_USB_CYTHERM=m
  2036. +CONFIG_USB_IDMOUSE=m
  2037. +CONFIG_USB_FTDI_ELAN=m
  2038. +CONFIG_USB_APPLEDISPLAY=m
  2039. +CONFIG_USB_LD=m
  2040. +CONFIG_USB_TRANCEVIBRATOR=m
  2041. +CONFIG_USB_IOWARRIOR=m
  2042. +CONFIG_USB_TEST=m
  2043. +CONFIG_USB_ISIGHTFW=m
  2044. +CONFIG_USB_YUREX=m
  2045. +CONFIG_MMC=y
  2046. +CONFIG_MMC_SDHCI=y
  2047. +CONFIG_MMC_SDHCI_PLTFM=y
  2048. +CONFIG_MMC_SDHCI_BCM2708=y
  2049. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  2050. +CONFIG_LEDS_GPIO=y
  2051. +CONFIG_LEDS_TRIGGER_TIMER=m
  2052. +CONFIG_LEDS_TRIGGER_HEARTBEAT=m
  2053. +CONFIG_LEDS_TRIGGER_DEFAULT_ON=m
  2054. +CONFIG_UIO=m
  2055. +CONFIG_UIO_PDRV=m
  2056. +CONFIG_UIO_PDRV_GENIRQ=m
  2057. +# CONFIG_IOMMU_SUPPORT is not set
  2058. +CONFIG_EXT4_FS=y
  2059. +CONFIG_EXT4_FS_POSIX_ACL=y
  2060. +CONFIG_EXT4_FS_SECURITY=y
  2061. +CONFIG_REISERFS_FS=m
  2062. +CONFIG_REISERFS_FS_XATTR=y
  2063. +CONFIG_REISERFS_FS_POSIX_ACL=y
  2064. +CONFIG_REISERFS_FS_SECURITY=y
  2065. +CONFIG_JFS_FS=m
  2066. +CONFIG_JFS_POSIX_ACL=y
  2067. +CONFIG_JFS_SECURITY=y
  2068. +CONFIG_JFS_STATISTICS=y
  2069. +CONFIG_XFS_FS=m
  2070. +CONFIG_XFS_QUOTA=y
  2071. +CONFIG_XFS_POSIX_ACL=y
  2072. +CONFIG_XFS_RT=y
  2073. +CONFIG_GFS2_FS=m
  2074. +CONFIG_OCFS2_FS=m
  2075. +CONFIG_BTRFS_FS=m
  2076. +CONFIG_BTRFS_FS_POSIX_ACL=y
  2077. +CONFIG_NILFS2_FS=m
  2078. +CONFIG_FANOTIFY=y
  2079. +CONFIG_AUTOFS4_FS=y
  2080. +CONFIG_FUSE_FS=m
  2081. +CONFIG_CUSE=m
  2082. +CONFIG_FSCACHE=y
  2083. +CONFIG_FSCACHE_STATS=y
  2084. +CONFIG_FSCACHE_HISTOGRAM=y
  2085. +CONFIG_CACHEFILES=y
  2086. +CONFIG_ISO9660_FS=m
  2087. +CONFIG_JOLIET=y
  2088. +CONFIG_ZISOFS=y
  2089. +CONFIG_UDF_FS=m
  2090. +CONFIG_MSDOS_FS=y
  2091. +CONFIG_VFAT_FS=y
  2092. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  2093. +CONFIG_NTFS_FS=m
  2094. +CONFIG_TMPFS=y
  2095. +CONFIG_TMPFS_POSIX_ACL=y
  2096. +CONFIG_CONFIGFS_FS=y
  2097. +CONFIG_SQUASHFS=m
  2098. +CONFIG_SQUASHFS_XATTR=y
  2099. +CONFIG_SQUASHFS_LZO=y
  2100. +CONFIG_SQUASHFS_XZ=y
  2101. +CONFIG_NFS_FS=y
  2102. +CONFIG_NFS_V3=y
  2103. +CONFIG_NFS_V3_ACL=y
  2104. +CONFIG_NFS_V4=y
  2105. +CONFIG_ROOT_NFS=y
  2106. +CONFIG_NFS_FSCACHE=y
  2107. +CONFIG_CIFS=m
  2108. +CONFIG_CIFS_WEAK_PW_HASH=y
  2109. +CONFIG_CIFS_XATTR=y
  2110. +CONFIG_CIFS_POSIX=y
  2111. +CONFIG_9P_FS=m
  2112. +CONFIG_9P_FS_POSIX_ACL=y
  2113. +CONFIG_PARTITION_ADVANCED=y
  2114. +CONFIG_MAC_PARTITION=y
  2115. +CONFIG_EFI_PARTITION=y
  2116. +CONFIG_NLS_DEFAULT="utf8"
  2117. +CONFIG_NLS_CODEPAGE_437=y
  2118. +CONFIG_NLS_CODEPAGE_737=m
  2119. +CONFIG_NLS_CODEPAGE_775=m
  2120. +CONFIG_NLS_CODEPAGE_850=m
  2121. +CONFIG_NLS_CODEPAGE_852=m
  2122. +CONFIG_NLS_CODEPAGE_855=m
  2123. +CONFIG_NLS_CODEPAGE_857=m
  2124. +CONFIG_NLS_CODEPAGE_860=m
  2125. +CONFIG_NLS_CODEPAGE_861=m
  2126. +CONFIG_NLS_CODEPAGE_862=m
  2127. +CONFIG_NLS_CODEPAGE_863=m
  2128. +CONFIG_NLS_CODEPAGE_864=m
  2129. +CONFIG_NLS_CODEPAGE_865=m
  2130. +CONFIG_NLS_CODEPAGE_866=m
  2131. +CONFIG_NLS_CODEPAGE_869=m
  2132. +CONFIG_NLS_CODEPAGE_936=m
  2133. +CONFIG_NLS_CODEPAGE_950=m
  2134. +CONFIG_NLS_CODEPAGE_932=m
  2135. +CONFIG_NLS_CODEPAGE_949=m
  2136. +CONFIG_NLS_CODEPAGE_874=m
  2137. +CONFIG_NLS_ISO8859_8=m
  2138. +CONFIG_NLS_CODEPAGE_1250=m
  2139. +CONFIG_NLS_CODEPAGE_1251=m
  2140. +CONFIG_NLS_ASCII=y
  2141. +CONFIG_NLS_ISO8859_1=m
  2142. +CONFIG_NLS_ISO8859_2=m
  2143. +CONFIG_NLS_ISO8859_3=m
  2144. +CONFIG_NLS_ISO8859_4=m
  2145. +CONFIG_NLS_ISO8859_5=m
  2146. +CONFIG_NLS_ISO8859_6=m
  2147. +CONFIG_NLS_ISO8859_7=m
  2148. +CONFIG_NLS_ISO8859_9=m
  2149. +CONFIG_NLS_ISO8859_13=m
  2150. +CONFIG_NLS_ISO8859_14=m
  2151. +CONFIG_NLS_ISO8859_15=m
  2152. +CONFIG_NLS_KOI8_R=m
  2153. +CONFIG_NLS_KOI8_U=m
  2154. +CONFIG_NLS_UTF8=m
  2155. +CONFIG_PRINTK_TIME=y
  2156. +CONFIG_DETECT_HUNG_TASK=y
  2157. +CONFIG_TIMER_STATS=y
  2158. +CONFIG_DEBUG_STACK_USAGE=y
  2159. +CONFIG_DEBUG_INFO=y
  2160. +CONFIG_DEBUG_MEMORY_INIT=y
  2161. +CONFIG_BOOT_PRINTK_DELAY=y
  2162. +CONFIG_LATENCYTOP=y
  2163. +CONFIG_SYSCTL_SYSCALL_CHECK=y
  2164. +CONFIG_IRQSOFF_TRACER=y
  2165. +CONFIG_SCHED_TRACER=y
  2166. +CONFIG_STACK_TRACER=y
  2167. +CONFIG_BLK_DEV_IO_TRACE=y
  2168. +CONFIG_FUNCTION_PROFILER=y
  2169. +CONFIG_KGDB=y
  2170. +CONFIG_KGDB_KDB=y
  2171. +CONFIG_KDB_KEYBOARD=y
  2172. +CONFIG_STRICT_DEVMEM=y
  2173. +CONFIG_CRYPTO_AUTHENC=m
  2174. +CONFIG_CRYPTO_SEQIV=m
  2175. +CONFIG_CRYPTO_CBC=y
  2176. +CONFIG_CRYPTO_HMAC=y
  2177. +CONFIG_CRYPTO_XCBC=m
  2178. +CONFIG_CRYPTO_MD5=y
  2179. +CONFIG_CRYPTO_SHA1=y
  2180. +CONFIG_CRYPTO_SHA256=m
  2181. +CONFIG_CRYPTO_SHA512=m
  2182. +CONFIG_CRYPTO_TGR192=m
  2183. +CONFIG_CRYPTO_WP512=m
  2184. +CONFIG_CRYPTO_CAST5=m
  2185. +CONFIG_CRYPTO_DES=y
  2186. +CONFIG_CRYPTO_DEFLATE=m
  2187. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  2188. +# CONFIG_CRYPTO_HW is not set
  2189. +CONFIG_CRC_ITU_T=y
  2190. +CONFIG_LIBCRC32C=y
  2191. diff -Nur linux-3.12.26.orig/arch/arm/configs/bcmrpi_quick_defconfig linux-3.12.26/arch/arm/configs/bcmrpi_quick_defconfig
  2192. --- linux-3.12.26.orig/arch/arm/configs/bcmrpi_quick_defconfig 1970-01-01 01:00:00.000000000 +0100
  2193. +++ linux-3.12.26/arch/arm/configs/bcmrpi_quick_defconfig 2014-08-06 16:50:13.777956685 +0200
  2194. @@ -0,0 +1,197 @@
  2195. +# CONFIG_ARM_PATCH_PHYS_VIRT is not set
  2196. +CONFIG_LOCALVERSION="-quick"
  2197. +# CONFIG_LOCALVERSION_AUTO is not set
  2198. +# CONFIG_SWAP is not set
  2199. +CONFIG_SYSVIPC=y
  2200. +CONFIG_POSIX_MQUEUE=y
  2201. +CONFIG_NO_HZ=y
  2202. +CONFIG_HIGH_RES_TIMERS=y
  2203. +CONFIG_IKCONFIG=y
  2204. +CONFIG_IKCONFIG_PROC=y
  2205. +CONFIG_KALLSYMS_ALL=y
  2206. +CONFIG_EMBEDDED=y
  2207. +CONFIG_PERF_EVENTS=y
  2208. +# CONFIG_COMPAT_BRK is not set
  2209. +CONFIG_SLAB=y
  2210. +CONFIG_MODULES=y
  2211. +CONFIG_MODULE_UNLOAD=y
  2212. +CONFIG_MODVERSIONS=y
  2213. +CONFIG_MODULE_SRCVERSION_ALL=y
  2214. +# CONFIG_BLK_DEV_BSG is not set
  2215. +CONFIG_ARCH_BCM2708=y
  2216. +CONFIG_PREEMPT=y
  2217. +CONFIG_AEABI=y
  2218. +CONFIG_UACCESS_WITH_MEMCPY=y
  2219. +CONFIG_ZBOOT_ROM_TEXT=0x0
  2220. +CONFIG_ZBOOT_ROM_BSS=0x0
  2221. +CONFIG_CMDLINE="dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait"
  2222. +CONFIG_CPU_FREQ=y
  2223. +CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE=y
  2224. +CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
  2225. +CONFIG_CPU_FREQ_GOV_USERSPACE=y
  2226. +CONFIG_CPU_FREQ_GOV_ONDEMAND=y
  2227. +CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
  2228. +CONFIG_CPU_IDLE=y
  2229. +CONFIG_VFP=y
  2230. +CONFIG_BINFMT_MISC=y
  2231. +CONFIG_NET=y
  2232. +CONFIG_PACKET=y
  2233. +CONFIG_UNIX=y
  2234. +CONFIG_INET=y
  2235. +CONFIG_IP_MULTICAST=y
  2236. +CONFIG_IP_PNP=y
  2237. +CONFIG_IP_PNP_DHCP=y
  2238. +CONFIG_IP_PNP_RARP=y
  2239. +CONFIG_SYN_COOKIES=y
  2240. +# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
  2241. +# CONFIG_INET_XFRM_MODE_TUNNEL is not set
  2242. +# CONFIG_INET_XFRM_MODE_BEET is not set
  2243. +# CONFIG_INET_LRO is not set
  2244. +# CONFIG_INET_DIAG is not set
  2245. +# CONFIG_IPV6 is not set
  2246. +# CONFIG_WIRELESS is not set
  2247. +CONFIG_DEVTMPFS=y
  2248. +CONFIG_DEVTMPFS_MOUNT=y
  2249. +CONFIG_BLK_DEV_LOOP=y
  2250. +CONFIG_BLK_DEV_RAM=y
  2251. +CONFIG_SCSI=y
  2252. +# CONFIG_SCSI_PROC_FS is not set
  2253. +# CONFIG_SCSI_LOWLEVEL is not set
  2254. +CONFIG_NETDEVICES=y
  2255. +# CONFIG_NET_VENDOR_BROADCOM is not set
  2256. +# CONFIG_NET_VENDOR_CIRRUS is not set
  2257. +# CONFIG_NET_VENDOR_FARADAY is not set
  2258. +# CONFIG_NET_VENDOR_INTEL is not set
  2259. +# CONFIG_NET_VENDOR_MARVELL is not set
  2260. +# CONFIG_NET_VENDOR_MICREL is not set
  2261. +# CONFIG_NET_VENDOR_NATSEMI is not set
  2262. +# CONFIG_NET_VENDOR_SEEQ is not set
  2263. +# CONFIG_NET_VENDOR_STMICRO is not set
  2264. +# CONFIG_NET_VENDOR_WIZNET is not set
  2265. +CONFIG_USB_USBNET=y
  2266. +# CONFIG_USB_NET_AX8817X is not set
  2267. +# CONFIG_USB_NET_CDCETHER is not set
  2268. +# CONFIG_USB_NET_CDC_NCM is not set
  2269. +CONFIG_USB_NET_SMSC95XX=y
  2270. +# CONFIG_USB_NET_NET1080 is not set
  2271. +# CONFIG_USB_NET_CDC_SUBSET is not set
  2272. +# CONFIG_USB_NET_ZAURUS is not set
  2273. +# CONFIG_WLAN is not set
  2274. +# CONFIG_INPUT_MOUSEDEV is not set
  2275. +CONFIG_INPUT_EVDEV=y
  2276. +# CONFIG_INPUT_KEYBOARD is not set
  2277. +# CONFIG_INPUT_MOUSE is not set
  2278. +# CONFIG_SERIO is not set
  2279. +CONFIG_VT_HW_CONSOLE_BINDING=y
  2280. +# CONFIG_LEGACY_PTYS is not set
  2281. +# CONFIG_DEVKMEM is not set
  2282. +CONFIG_SERIAL_AMBA_PL011=y
  2283. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  2284. +CONFIG_TTY_PRINTK=y
  2285. +CONFIG_HW_RANDOM=y
  2286. +CONFIG_HW_RANDOM_BCM2708=y
  2287. +CONFIG_RAW_DRIVER=y
  2288. +CONFIG_THERMAL=y
  2289. +CONFIG_THERMAL_BCM2835=y
  2290. +CONFIG_WATCHDOG=y
  2291. +CONFIG_BCM2708_WDT=y
  2292. +CONFIG_REGULATOR=y
  2293. +CONFIG_REGULATOR_DEBUG=y
  2294. +CONFIG_REGULATOR_FIXED_VOLTAGE=y
  2295. +CONFIG_REGULATOR_VIRTUAL_CONSUMER=y
  2296. +CONFIG_REGULATOR_USERSPACE_CONSUMER=y
  2297. +CONFIG_FB=y
  2298. +CONFIG_FB_BCM2708=y
  2299. +CONFIG_FRAMEBUFFER_CONSOLE=y
  2300. +CONFIG_LOGO=y
  2301. +# CONFIG_LOGO_LINUX_MONO is not set
  2302. +# CONFIG_LOGO_LINUX_VGA16 is not set
  2303. +CONFIG_SOUND=y
  2304. +CONFIG_SND=y
  2305. +CONFIG_SND_BCM2835=y
  2306. +# CONFIG_SND_USB is not set
  2307. +CONFIG_USB=y
  2308. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  2309. +CONFIG_USB_DWCOTG=y
  2310. +CONFIG_MMC=y
  2311. +CONFIG_MMC_SDHCI=y
  2312. +CONFIG_MMC_SDHCI_PLTFM=y
  2313. +CONFIG_MMC_SDHCI_BCM2708=y
  2314. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  2315. +CONFIG_NEW_LEDS=y
  2316. +CONFIG_LEDS_CLASS=y
  2317. +CONFIG_LEDS_TRIGGERS=y
  2318. +# CONFIG_IOMMU_SUPPORT is not set
  2319. +CONFIG_EXT4_FS=y
  2320. +CONFIG_EXT4_FS_POSIX_ACL=y
  2321. +CONFIG_EXT4_FS_SECURITY=y
  2322. +CONFIG_AUTOFS4_FS=y
  2323. +CONFIG_FSCACHE=y
  2324. +CONFIG_CACHEFILES=y
  2325. +CONFIG_MSDOS_FS=y
  2326. +CONFIG_VFAT_FS=y
  2327. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  2328. +CONFIG_TMPFS=y
  2329. +CONFIG_TMPFS_POSIX_ACL=y
  2330. +CONFIG_CONFIGFS_FS=y
  2331. +# CONFIG_MISC_FILESYSTEMS is not set
  2332. +CONFIG_NFS_FS=y
  2333. +CONFIG_NFS_V3_ACL=y
  2334. +CONFIG_NFS_V4=y
  2335. +CONFIG_ROOT_NFS=y
  2336. +CONFIG_NFS_FSCACHE=y
  2337. +CONFIG_NLS_DEFAULT="utf8"
  2338. +CONFIG_NLS_CODEPAGE_437=y
  2339. +CONFIG_NLS_CODEPAGE_737=y
  2340. +CONFIG_NLS_CODEPAGE_775=y
  2341. +CONFIG_NLS_CODEPAGE_850=y
  2342. +CONFIG_NLS_CODEPAGE_852=y
  2343. +CONFIG_NLS_CODEPAGE_855=y
  2344. +CONFIG_NLS_CODEPAGE_857=y
  2345. +CONFIG_NLS_CODEPAGE_860=y
  2346. +CONFIG_NLS_CODEPAGE_861=y
  2347. +CONFIG_NLS_CODEPAGE_862=y
  2348. +CONFIG_NLS_CODEPAGE_863=y
  2349. +CONFIG_NLS_CODEPAGE_864=y
  2350. +CONFIG_NLS_CODEPAGE_865=y
  2351. +CONFIG_NLS_CODEPAGE_866=y
  2352. +CONFIG_NLS_CODEPAGE_869=y
  2353. +CONFIG_NLS_CODEPAGE_936=y
  2354. +CONFIG_NLS_CODEPAGE_950=y
  2355. +CONFIG_NLS_CODEPAGE_932=y
  2356. +CONFIG_NLS_CODEPAGE_949=y
  2357. +CONFIG_NLS_CODEPAGE_874=y
  2358. +CONFIG_NLS_ISO8859_8=y
  2359. +CONFIG_NLS_CODEPAGE_1250=y
  2360. +CONFIG_NLS_CODEPAGE_1251=y
  2361. +CONFIG_NLS_ASCII=y
  2362. +CONFIG_NLS_ISO8859_1=y
  2363. +CONFIG_NLS_ISO8859_2=y
  2364. +CONFIG_NLS_ISO8859_3=y
  2365. +CONFIG_NLS_ISO8859_4=y
  2366. +CONFIG_NLS_ISO8859_5=y
  2367. +CONFIG_NLS_ISO8859_6=y
  2368. +CONFIG_NLS_ISO8859_7=y
  2369. +CONFIG_NLS_ISO8859_9=y
  2370. +CONFIG_NLS_ISO8859_13=y
  2371. +CONFIG_NLS_ISO8859_14=y
  2372. +CONFIG_NLS_ISO8859_15=y
  2373. +CONFIG_NLS_UTF8=y
  2374. +CONFIG_PRINTK_TIME=y
  2375. +CONFIG_DEBUG_FS=y
  2376. +CONFIG_DETECT_HUNG_TASK=y
  2377. +# CONFIG_DEBUG_PREEMPT is not set
  2378. +# CONFIG_DEBUG_BUGVERBOSE is not set
  2379. +# CONFIG_FTRACE is not set
  2380. +CONFIG_KGDB=y
  2381. +CONFIG_KGDB_KDB=y
  2382. +# CONFIG_ARM_UNWIND is not set
  2383. +CONFIG_CRYPTO_CBC=y
  2384. +CONFIG_CRYPTO_HMAC=y
  2385. +CONFIG_CRYPTO_MD5=y
  2386. +CONFIG_CRYPTO_SHA1=y
  2387. +CONFIG_CRYPTO_DES=y
  2388. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  2389. +# CONFIG_CRYPTO_HW is not set
  2390. +CONFIG_CRC_ITU_T=y
  2391. +CONFIG_LIBCRC32C=y
  2392. diff -Nur linux-3.12.26.orig/arch/arm/include/asm/irqflags.h linux-3.12.26/arch/arm/include/asm/irqflags.h
  2393. --- linux-3.12.26.orig/arch/arm/include/asm/irqflags.h 2014-07-30 18:02:44.000000000 +0200
  2394. +++ linux-3.12.26/arch/arm/include/asm/irqflags.h 2014-08-06 16:50:13.777956685 +0200
  2395. @@ -145,12 +145,22 @@
  2396. }
  2397. /*
  2398. - * restore saved IRQ & FIQ state
  2399. + * restore saved IRQ state
  2400. */
  2401. static inline void arch_local_irq_restore(unsigned long flags)
  2402. {
  2403. - asm volatile(
  2404. - " msr " IRQMASK_REG_NAME_W ", %0 @ local_irq_restore"
  2405. + unsigned long temp = 0;
  2406. + flags &= ~(1 << 6);
  2407. + asm volatile (
  2408. + " mrs %0, cpsr"
  2409. + : "=r" (temp)
  2410. + :
  2411. + : "memory", "cc");
  2412. + /* Preserve FIQ bit */
  2413. + temp &= (1 << 6);
  2414. + flags = flags | temp;
  2415. + asm volatile (
  2416. + " msr cpsr_c, %0 @ local_irq_restore"
  2417. :
  2418. : "r" (flags)
  2419. : "memory", "cc");
  2420. diff -Nur linux-3.12.26.orig/arch/arm/Kconfig linux-3.12.26/arch/arm/Kconfig
  2421. --- linux-3.12.26.orig/arch/arm/Kconfig 2014-07-30 18:02:44.000000000 +0200
  2422. +++ linux-3.12.26/arch/arm/Kconfig 2014-08-06 16:50:13.777956685 +0200
  2423. @@ -369,6 +369,24 @@
  2424. This enables support for systems based on Atmel
  2425. AT91RM9200 and AT91SAM9* processors.
  2426. +config ARCH_BCM2708
  2427. + bool "Broadcom BCM2708 family"
  2428. + select CPU_V6
  2429. + select ARM_AMBA
  2430. + select HAVE_CLK
  2431. + select HAVE_SCHED_CLOCK
  2432. + select NEED_MACH_GPIO_H
  2433. + select NEED_MACH_MEMORY_H
  2434. + select CLKDEV_LOOKUP
  2435. + select ARCH_HAS_CPUFREQ
  2436. + select GENERIC_CLOCKEVENTS
  2437. + select ARM_ERRATA_411920
  2438. + select MACH_BCM2708
  2439. + select VC4
  2440. + select FIQ
  2441. + help
  2442. + This enables support for Broadcom BCM2708 boards.
  2443. +
  2444. config ARCH_CLPS711X
  2445. bool "Cirrus Logic CLPS711x/EP721x/EP731x-based"
  2446. select ARCH_REQUIRE_GPIOLIB
  2447. @@ -1044,6 +1062,7 @@
  2448. source "arch/arm/mach-vt8500/Kconfig"
  2449. source "arch/arm/mach-w90x900/Kconfig"
  2450. +source "arch/arm/mach-bcm2708/Kconfig"
  2451. source "arch/arm/mach-zynq/Kconfig"
  2452. diff -Nur linux-3.12.26.orig/arch/arm/Kconfig.debug linux-3.12.26/arch/arm/Kconfig.debug
  2453. --- linux-3.12.26.orig/arch/arm/Kconfig.debug 2014-07-30 18:02:44.000000000 +0200
  2454. +++ linux-3.12.26/arch/arm/Kconfig.debug 2014-08-06 16:50:13.781956717 +0200
  2455. @@ -847,6 +847,14 @@
  2456. options; the platform specific options are deprecated
  2457. and will be soon removed.
  2458. + config DEBUG_BCM2708_UART0
  2459. + bool "Broadcom BCM2708 UART0 (PL011)"
  2460. + depends on MACH_BCM2708
  2461. + help
  2462. + Say Y here if you want the debug print routines to direct
  2463. + their output to UART 0. The port must have been initialised
  2464. + by the boot-loader before use.
  2465. +
  2466. endchoice
  2467. config DEBUG_EXYNOS_UART
  2468. diff -Nur linux-3.12.26.orig/arch/arm/kernel/fiqasm.S linux-3.12.26/arch/arm/kernel/fiqasm.S
  2469. --- linux-3.12.26.orig/arch/arm/kernel/fiqasm.S 2014-07-30 18:02:44.000000000 +0200
  2470. +++ linux-3.12.26/arch/arm/kernel/fiqasm.S 2014-08-06 16:50:13.817956999 +0200
  2471. @@ -47,3 +47,7 @@
  2472. mov r0, r0 @ avoid hazard prior to ARMv4
  2473. mov pc, lr
  2474. ENDPROC(__get_fiq_regs)
  2475. +
  2476. +ENTRY(__FIQ_Branch)
  2477. + mov pc, r8
  2478. +ENDPROC(__FIQ_Branch)
  2479. diff -Nur linux-3.12.26.orig/arch/arm/kernel/process.c linux-3.12.26/arch/arm/kernel/process.c
  2480. --- linux-3.12.26.orig/arch/arm/kernel/process.c 2014-07-30 18:02:44.000000000 +0200
  2481. +++ linux-3.12.26/arch/arm/kernel/process.c 2014-08-06 16:50:13.817956999 +0200
  2482. @@ -176,6 +176,16 @@
  2483. default_idle();
  2484. }
  2485. +char bcm2708_reboot_mode = 'h';
  2486. +
  2487. +int __init reboot_setup(char *str)
  2488. +{
  2489. + bcm2708_reboot_mode = str[0];
  2490. + return 1;
  2491. +}
  2492. +
  2493. +__setup("reboot=", reboot_setup);
  2494. +
  2495. /*
  2496. * Called by kexec, immediately prior to machine_kexec().
  2497. *
  2498. diff -Nur linux-3.12.26.orig/arch/arm/mach-bcm2708/armctrl.c linux-3.12.26/arch/arm/mach-bcm2708/armctrl.c
  2499. --- linux-3.12.26.orig/arch/arm/mach-bcm2708/armctrl.c 1970-01-01 01:00:00.000000000 +0100
  2500. +++ linux-3.12.26/arch/arm/mach-bcm2708/armctrl.c 2014-08-06 16:50:13.821957030 +0200
  2501. @@ -0,0 +1,219 @@
  2502. +/*
  2503. + * linux/arch/arm/mach-bcm2708/armctrl.c
  2504. + *
  2505. + * Copyright (C) 2010 Broadcom
  2506. + *
  2507. + * This program is free software; you can redistribute it and/or modify
  2508. + * it under the terms of the GNU General Public License as published by
  2509. + * the Free Software Foundation; either version 2 of the License, or
  2510. + * (at your option) any later version.
  2511. + *
  2512. + * This program is distributed in the hope that it will be useful,
  2513. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2514. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2515. + * GNU General Public License for more details.
  2516. + *
  2517. + * You should have received a copy of the GNU General Public License
  2518. + * along with this program; if not, write to the Free Software
  2519. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  2520. + */
  2521. +#include <linux/init.h>
  2522. +#include <linux/list.h>
  2523. +#include <linux/io.h>
  2524. +#include <linux/version.h>
  2525. +#include <linux/syscore_ops.h>
  2526. +#include <linux/interrupt.h>
  2527. +
  2528. +#include <asm/mach/irq.h>
  2529. +#include <mach/hardware.h>
  2530. +#include "armctrl.h"
  2531. +
  2532. +/* For support of kernels >= 3.0 assume only one VIC for now*/
  2533. +static unsigned int remap_irqs[(INTERRUPT_ARASANSDIO + 1) - INTERRUPT_JPEG] = {
  2534. + INTERRUPT_VC_JPEG,
  2535. + INTERRUPT_VC_USB,
  2536. + INTERRUPT_VC_3D,
  2537. + INTERRUPT_VC_DMA2,
  2538. + INTERRUPT_VC_DMA3,
  2539. + INTERRUPT_VC_I2C,
  2540. + INTERRUPT_VC_SPI,
  2541. + INTERRUPT_VC_I2SPCM,
  2542. + INTERRUPT_VC_SDIO,
  2543. + INTERRUPT_VC_UART,
  2544. + INTERRUPT_VC_ARASANSDIO
  2545. +};
  2546. +
  2547. +static void armctrl_mask_irq(struct irq_data *d)
  2548. +{
  2549. + static const unsigned int disables[4] = {
  2550. + ARM_IRQ_DIBL1,
  2551. + ARM_IRQ_DIBL2,
  2552. + ARM_IRQ_DIBL3,
  2553. + 0
  2554. + };
  2555. +
  2556. + if (d->irq >= FIQ_START) {
  2557. + writel(0, __io_address(ARM_IRQ_FAST));
  2558. + } else {
  2559. + unsigned int data = (unsigned int)irq_get_chip_data(d->irq);
  2560. + writel(1 << (data & 0x1f), __io_address(disables[(data >> 5) & 0x3]));
  2561. + }
  2562. +}
  2563. +
  2564. +static void armctrl_unmask_irq(struct irq_data *d)
  2565. +{
  2566. + static const unsigned int enables[4] = {
  2567. + ARM_IRQ_ENBL1,
  2568. + ARM_IRQ_ENBL2,
  2569. + ARM_IRQ_ENBL3,
  2570. + 0
  2571. + };
  2572. +
  2573. + if (d->irq >= FIQ_START) {
  2574. + unsigned int data =
  2575. + (unsigned int)irq_get_chip_data(d->irq) - FIQ_START;
  2576. + writel(0x80 | data, __io_address(ARM_IRQ_FAST));
  2577. + } else {
  2578. + unsigned int data = (unsigned int)irq_get_chip_data(d->irq);
  2579. + writel(1 << (data & 0x1f), __io_address(enables[(data >> 5) & 0x3]));
  2580. + }
  2581. +}
  2582. +
  2583. +#if defined(CONFIG_PM)
  2584. +
  2585. +/* for kernels 3.xx use the new syscore_ops apis but for older kernels use the sys dev class */
  2586. +
  2587. +/* Static defines
  2588. + * struct armctrl_device - VIC PM device (< 3.xx)
  2589. + * @sysdev: The system device which is registered. (< 3.xx)
  2590. + * @irq: The IRQ number for the base of the VIC.
  2591. + * @base: The register base for the VIC.
  2592. + * @resume_sources: A bitmask of interrupts for resume.
  2593. + * @resume_irqs: The IRQs enabled for resume.
  2594. + * @int_select: Save for VIC_INT_SELECT.
  2595. + * @int_enable: Save for VIC_INT_ENABLE.
  2596. + * @soft_int: Save for VIC_INT_SOFT.
  2597. + * @protect: Save for VIC_PROTECT.
  2598. + */
  2599. +struct armctrl_info {
  2600. + void __iomem *base;
  2601. + int irq;
  2602. + u32 resume_sources;
  2603. + u32 resume_irqs;
  2604. + u32 int_select;
  2605. + u32 int_enable;
  2606. + u32 soft_int;
  2607. + u32 protect;
  2608. +} armctrl;
  2609. +
  2610. +static int armctrl_suspend(void)
  2611. +{
  2612. + return 0;
  2613. +}
  2614. +
  2615. +static void armctrl_resume(void)
  2616. +{
  2617. + return;
  2618. +}
  2619. +
  2620. +/**
  2621. + * armctrl_pm_register - Register a VIC for later power management control
  2622. + * @base: The base address of the VIC.
  2623. + * @irq: The base IRQ for the VIC.
  2624. + * @resume_sources: bitmask of interrupts allowed for resume sources.
  2625. + *
  2626. + * For older kernels (< 3.xx) do -
  2627. + * Register the VIC with the system device tree so that it can be notified
  2628. + * of suspend and resume requests and ensure that the correct actions are
  2629. + * taken to re-instate the settings on resume.
  2630. + */
  2631. +static void __init armctrl_pm_register(void __iomem * base, unsigned int irq,
  2632. + u32 resume_sources)
  2633. +{
  2634. + armctrl.base = base;
  2635. + armctrl.resume_sources = resume_sources;
  2636. + armctrl.irq = irq;
  2637. +}
  2638. +
  2639. +static int armctrl_set_wake(struct irq_data *d, unsigned int on)
  2640. +{
  2641. + unsigned int off = d->irq & 31;
  2642. + u32 bit = 1 << off;
  2643. +
  2644. + if (!(bit & armctrl.resume_sources))
  2645. + return -EINVAL;
  2646. +
  2647. + if (on)
  2648. + armctrl.resume_irqs |= bit;
  2649. + else
  2650. + armctrl.resume_irqs &= ~bit;
  2651. +
  2652. + return 0;
  2653. +}
  2654. +
  2655. +#else
  2656. +static inline void armctrl_pm_register(void __iomem * base, unsigned int irq,
  2657. + u32 arg1)
  2658. +{
  2659. +}
  2660. +
  2661. +#define armctrl_suspend NULL
  2662. +#define armctrl_resume NULL
  2663. +#define armctrl_set_wake NULL
  2664. +#endif /* CONFIG_PM */
  2665. +
  2666. +static struct syscore_ops armctrl_syscore_ops = {
  2667. + .suspend = armctrl_suspend,
  2668. + .resume = armctrl_resume,
  2669. +};
  2670. +
  2671. +/**
  2672. + * armctrl_syscore_init - initicall to register VIC pm functions
  2673. + *
  2674. + * This is called via late_initcall() to register
  2675. + * the resources for the VICs due to the early
  2676. + * nature of the VIC's registration.
  2677. +*/
  2678. +static int __init armctrl_syscore_init(void)
  2679. +{
  2680. + register_syscore_ops(&armctrl_syscore_ops);
  2681. + return 0;
  2682. +}
  2683. +
  2684. +late_initcall(armctrl_syscore_init);
  2685. +
  2686. +static struct irq_chip armctrl_chip = {
  2687. + .name = "ARMCTRL",
  2688. + .irq_ack = armctrl_mask_irq,
  2689. + .irq_mask = armctrl_mask_irq,
  2690. + .irq_unmask = armctrl_unmask_irq,
  2691. + .irq_set_wake = armctrl_set_wake,
  2692. +};
  2693. +
  2694. +/**
  2695. + * armctrl_init - initialise a vectored interrupt controller
  2696. + * @base: iomem base address
  2697. + * @irq_start: starting interrupt number, must be muliple of 32
  2698. + * @armctrl_sources: bitmask of interrupt sources to allow
  2699. + * @resume_sources: bitmask of interrupt sources to allow for resume
  2700. + */
  2701. +int __init armctrl_init(void __iomem * base, unsigned int irq_start,
  2702. + u32 armctrl_sources, u32 resume_sources)
  2703. +{
  2704. + unsigned int irq;
  2705. +
  2706. + for (irq = 0; irq < NR_IRQS; irq++) {
  2707. + unsigned int data = irq;
  2708. + if (irq >= INTERRUPT_JPEG && irq <= INTERRUPT_ARASANSDIO)
  2709. + data = remap_irqs[irq - INTERRUPT_JPEG];
  2710. +
  2711. + irq_set_chip(irq, &armctrl_chip);
  2712. + irq_set_chip_data(irq, (void *)data);
  2713. + irq_set_handler(irq, handle_level_irq);
  2714. + set_irq_flags(irq, IRQF_VALID | IRQF_PROBE | IRQF_DISABLED);
  2715. + }
  2716. +
  2717. + armctrl_pm_register(base, irq_start, resume_sources);
  2718. + init_FIQ(FIQ_START);
  2719. + return 0;
  2720. +}
  2721. diff -Nur linux-3.12.26.orig/arch/arm/mach-bcm2708/armctrl.h linux-3.12.26/arch/arm/mach-bcm2708/armctrl.h
  2722. --- linux-3.12.26.orig/arch/arm/mach-bcm2708/armctrl.h 1970-01-01 01:00:00.000000000 +0100
  2723. +++ linux-3.12.26/arch/arm/mach-bcm2708/armctrl.h 2014-08-06 16:50:13.821957030 +0200
  2724. @@ -0,0 +1,27 @@
  2725. +/*
  2726. + * linux/arch/arm/mach-bcm2708/armctrl.h
  2727. + *
  2728. + * Copyright (C) 2010 Broadcom
  2729. + *
  2730. + * This program is free software; you can redistribute it and/or modify
  2731. + * it under the terms of the GNU General Public License as published by
  2732. + * the Free Software Foundation; either version 2 of the License, or
  2733. + * (at your option) any later version.
  2734. + *
  2735. + * This program is distributed in the hope that it will be useful,
  2736. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2737. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2738. + * GNU General Public License for more details.
  2739. + *
  2740. + * You should have received a copy of the GNU General Public License
  2741. + * along with this program; if not, write to the Free Software
  2742. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  2743. + */
  2744. +
  2745. +#ifndef __BCM2708_ARMCTRL_H
  2746. +#define __BCM2708_ARMCTRL_H
  2747. +
  2748. +extern int __init armctrl_init(void __iomem * base, unsigned int irq_start,
  2749. + u32 armctrl_sources, u32 resume_sources);
  2750. +
  2751. +#endif
  2752. diff -Nur linux-3.12.26.orig/arch/arm/mach-bcm2708/bcm2708.c linux-3.12.26/arch/arm/mach-bcm2708/bcm2708.c
  2753. --- linux-3.12.26.orig/arch/arm/mach-bcm2708/bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  2754. +++ linux-3.12.26/arch/arm/mach-bcm2708/bcm2708.c 2014-08-06 16:50:13.821957030 +0200
  2755. @@ -0,0 +1,1017 @@
  2756. +/*
  2757. + * linux/arch/arm/mach-bcm2708/bcm2708.c
  2758. + *
  2759. + * Copyright (C) 2010 Broadcom
  2760. + *
  2761. + * This program is free software; you can redistribute it and/or modify
  2762. + * it under the terms of the GNU General Public License as published by
  2763. + * the Free Software Foundation; either version 2 of the License, or
  2764. + * (at your option) any later version.
  2765. + *
  2766. + * This program is distributed in the hope that it will be useful,
  2767. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2768. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2769. + * GNU General Public License for more details.
  2770. + *
  2771. + * You should have received a copy of the GNU General Public License
  2772. + * along with this program; if not, write to the Free Software
  2773. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  2774. + */
  2775. +
  2776. +#include <linux/init.h>
  2777. +#include <linux/device.h>
  2778. +#include <linux/dma-mapping.h>
  2779. +#include <linux/serial_8250.h>
  2780. +#include <linux/platform_device.h>
  2781. +#include <linux/syscore_ops.h>
  2782. +#include <linux/interrupt.h>
  2783. +#include <linux/amba/bus.h>
  2784. +#include <linux/amba/clcd.h>
  2785. +#include <linux/clockchips.h>
  2786. +#include <linux/cnt32_to_63.h>
  2787. +#include <linux/io.h>
  2788. +#include <linux/module.h>
  2789. +#include <linux/spi/spi.h>
  2790. +#include <linux/w1-gpio.h>
  2791. +
  2792. +#include <linux/version.h>
  2793. +#include <linux/clkdev.h>
  2794. +#include <asm/system.h>
  2795. +#include <mach/hardware.h>
  2796. +#include <asm/irq.h>
  2797. +#include <linux/leds.h>
  2798. +#include <asm/mach-types.h>
  2799. +#include <linux/sched_clock.h>
  2800. +
  2801. +#include <asm/mach/arch.h>
  2802. +#include <asm/mach/flash.h>
  2803. +#include <asm/mach/irq.h>
  2804. +#include <asm/mach/time.h>
  2805. +#include <asm/mach/map.h>
  2806. +
  2807. +#include <mach/timex.h>
  2808. +#include <mach/dma.h>
  2809. +#include <mach/vcio.h>
  2810. +#include <mach/system.h>
  2811. +
  2812. +#include <linux/delay.h>
  2813. +
  2814. +#include "bcm2708.h"
  2815. +#include "armctrl.h"
  2816. +#include "clock.h"
  2817. +
  2818. +#ifdef CONFIG_BCM_VC_CMA
  2819. +#include <linux/broadcom/vc_cma.h>
  2820. +#endif
  2821. +
  2822. +
  2823. +/* Effectively we have an IOMMU (ARM<->VideoCore map) that is set up to
  2824. + * give us IO access only to 64Mbytes of physical memory (26 bits). We could
  2825. + * represent this window by setting our dmamasks to 26 bits but, in fact
  2826. + * we're not going to use addresses outside this range (they're not in real
  2827. + * memory) so we don't bother.
  2828. + *
  2829. + * In the future we might include code to use this IOMMU to remap other
  2830. + * physical addresses onto VideoCore memory then the use of 32-bits would be
  2831. + * more legitimate.
  2832. + */
  2833. +#define DMA_MASK_BITS_COMMON 32
  2834. +
  2835. +// use GPIO 4 for the one-wire GPIO pin, if enabled
  2836. +#define W1_GPIO 4
  2837. +
  2838. +/* command line parameters */
  2839. +static unsigned boardrev, serial;
  2840. +static unsigned uart_clock;
  2841. +static unsigned disk_led_gpio = 16;
  2842. +static unsigned disk_led_active_low = 1;
  2843. +static unsigned reboot_part = 0;
  2844. +static unsigned w1_gpio_pin = W1_GPIO;
  2845. +
  2846. +static void __init bcm2708_init_led(void);
  2847. +
  2848. +void __init bcm2708_init_irq(void)
  2849. +{
  2850. + armctrl_init(__io_address(ARMCTRL_IC_BASE), 0, 0, 0);
  2851. +}
  2852. +
  2853. +static struct map_desc bcm2708_io_desc[] __initdata = {
  2854. + {
  2855. + .virtual = IO_ADDRESS(ARMCTRL_BASE),
  2856. + .pfn = __phys_to_pfn(ARMCTRL_BASE),
  2857. + .length = SZ_4K,
  2858. + .type = MT_DEVICE},
  2859. + {
  2860. + .virtual = IO_ADDRESS(UART0_BASE),
  2861. + .pfn = __phys_to_pfn(UART0_BASE),
  2862. + .length = SZ_4K,
  2863. + .type = MT_DEVICE},
  2864. + {
  2865. + .virtual = IO_ADDRESS(UART1_BASE),
  2866. + .pfn = __phys_to_pfn(UART1_BASE),
  2867. + .length = SZ_4K,
  2868. + .type = MT_DEVICE},
  2869. + {
  2870. + .virtual = IO_ADDRESS(DMA_BASE),
  2871. + .pfn = __phys_to_pfn(DMA_BASE),
  2872. + .length = SZ_4K,
  2873. + .type = MT_DEVICE},
  2874. + {
  2875. + .virtual = IO_ADDRESS(MCORE_BASE),
  2876. + .pfn = __phys_to_pfn(MCORE_BASE),
  2877. + .length = SZ_4K,
  2878. + .type = MT_DEVICE},
  2879. + {
  2880. + .virtual = IO_ADDRESS(ST_BASE),
  2881. + .pfn = __phys_to_pfn(ST_BASE),
  2882. + .length = SZ_4K,
  2883. + .type = MT_DEVICE},
  2884. + {
  2885. + .virtual = IO_ADDRESS(USB_BASE),
  2886. + .pfn = __phys_to_pfn(USB_BASE),
  2887. + .length = SZ_128K,
  2888. + .type = MT_DEVICE},
  2889. + {
  2890. + .virtual = IO_ADDRESS(PM_BASE),
  2891. + .pfn = __phys_to_pfn(PM_BASE),
  2892. + .length = SZ_4K,
  2893. + .type = MT_DEVICE},
  2894. + {
  2895. + .virtual = IO_ADDRESS(GPIO_BASE),
  2896. + .pfn = __phys_to_pfn(GPIO_BASE),
  2897. + .length = SZ_4K,
  2898. + .type = MT_DEVICE}
  2899. +};
  2900. +
  2901. +void __init bcm2708_map_io(void)
  2902. +{
  2903. + iotable_init(bcm2708_io_desc, ARRAY_SIZE(bcm2708_io_desc));
  2904. +}
  2905. +
  2906. +/* The STC is a free running counter that increments at the rate of 1MHz */
  2907. +#define STC_FREQ_HZ 1000000
  2908. +
  2909. +static inline uint32_t timer_read(void)
  2910. +{
  2911. + /* STC: a free running counter that increments at the rate of 1MHz */
  2912. + return readl(__io_address(ST_BASE + 0x04));
  2913. +}
  2914. +
  2915. +static unsigned long bcm2708_read_current_timer(void)
  2916. +{
  2917. + return timer_read();
  2918. +}
  2919. +
  2920. +static u32 notrace bcm2708_read_sched_clock(void)
  2921. +{
  2922. + return timer_read();
  2923. +}
  2924. +
  2925. +static cycle_t clksrc_read(struct clocksource *cs)
  2926. +{
  2927. + return timer_read();
  2928. +}
  2929. +
  2930. +static struct clocksource clocksource_stc = {
  2931. + .name = "stc",
  2932. + .rating = 300,
  2933. + .read = clksrc_read,
  2934. + .mask = CLOCKSOURCE_MASK(32),
  2935. + .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  2936. +};
  2937. +
  2938. +unsigned long frc_clock_ticks32(void)
  2939. +{
  2940. + return timer_read();
  2941. +}
  2942. +
  2943. +static void __init bcm2708_clocksource_init(void)
  2944. +{
  2945. + if (clocksource_register_hz(&clocksource_stc, STC_FREQ_HZ)) {
  2946. + printk(KERN_ERR "timer: failed to initialize clock "
  2947. + "source %s\n", clocksource_stc.name);
  2948. + }
  2949. +}
  2950. +
  2951. +
  2952. +/*
  2953. + * These are fixed clocks.
  2954. + */
  2955. +static struct clk ref24_clk = {
  2956. + .rate = UART0_CLOCK, /* The UART is clocked at 3MHz via APB_CLK */
  2957. +};
  2958. +
  2959. +static struct clk osc_clk = {
  2960. +#ifdef CONFIG_ARCH_BCM2708_CHIPIT
  2961. + .rate = 27000000,
  2962. +#else
  2963. + .rate = 500000000, /* ARM clock is set from the VideoCore booter */
  2964. +#endif
  2965. +};
  2966. +
  2967. +/* warning - the USB needs a clock > 34MHz */
  2968. +
  2969. +static struct clk sdhost_clk = {
  2970. +#ifdef CONFIG_ARCH_BCM2708_CHIPIT
  2971. + .rate = 4000000, /* 4MHz */
  2972. +#else
  2973. + .rate = 250000000, /* 250MHz */
  2974. +#endif
  2975. +};
  2976. +
  2977. +static struct clk_lookup lookups[] = {
  2978. + { /* UART0 */
  2979. + .dev_id = "dev:f1",
  2980. + .clk = &ref24_clk,
  2981. + },
  2982. + { /* USB */
  2983. + .dev_id = "bcm2708_usb",
  2984. + .clk = &osc_clk,
  2985. + }, { /* SPI */
  2986. + .dev_id = "bcm2708_spi.0",
  2987. + .clk = &sdhost_clk,
  2988. + }, { /* BSC0 */
  2989. + .dev_id = "bcm2708_i2c.0",
  2990. + .clk = &sdhost_clk,
  2991. + }, { /* BSC1 */
  2992. + .dev_id = "bcm2708_i2c.1",
  2993. + .clk = &sdhost_clk,
  2994. + }
  2995. +};
  2996. +
  2997. +#define UART0_IRQ { IRQ_UART, 0 /*NO_IRQ*/ }
  2998. +#define UART0_DMA { 15, 14 }
  2999. +
  3000. +AMBA_DEVICE(uart0, "dev:f1", UART0, NULL);
  3001. +
  3002. +static struct amba_device *amba_devs[] __initdata = {
  3003. + &uart0_device,
  3004. +};
  3005. +
  3006. +static struct resource bcm2708_dmaman_resources[] = {
  3007. + {
  3008. + .start = DMA_BASE,
  3009. + .end = DMA_BASE + SZ_4K - 1,
  3010. + .flags = IORESOURCE_MEM,
  3011. + }
  3012. +};
  3013. +
  3014. +static struct platform_device bcm2708_dmaman_device = {
  3015. + .name = BCM_DMAMAN_DRIVER_NAME,
  3016. + .id = 0, /* first bcm2708_dma */
  3017. + .resource = bcm2708_dmaman_resources,
  3018. + .num_resources = ARRAY_SIZE(bcm2708_dmaman_resources),
  3019. +};
  3020. +
  3021. +#if defined(CONFIG_W1_MASTER_GPIO) || defined(CONFIG_W1_MASTER_GPIO_MODULE)
  3022. +static struct w1_gpio_platform_data w1_gpio_pdata = {
  3023. + .pin = W1_GPIO,
  3024. + .is_open_drain = 0,
  3025. +};
  3026. +
  3027. +static struct platform_device w1_device = {
  3028. + .name = "w1-gpio",
  3029. + .id = -1,
  3030. + .dev.platform_data = &w1_gpio_pdata,
  3031. +};
  3032. +#endif
  3033. +
  3034. +static u64 fb_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3035. +
  3036. +static struct platform_device bcm2708_fb_device = {
  3037. + .name = "bcm2708_fb",
  3038. + .id = -1, /* only one bcm2708_fb */
  3039. + .resource = NULL,
  3040. + .num_resources = 0,
  3041. + .dev = {
  3042. + .dma_mask = &fb_dmamask,
  3043. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  3044. + },
  3045. +};
  3046. +
  3047. +static struct plat_serial8250_port bcm2708_uart1_platform_data[] = {
  3048. + {
  3049. + .mapbase = UART1_BASE + 0x40,
  3050. + .irq = IRQ_AUX,
  3051. + .uartclk = 125000000,
  3052. + .regshift = 2,
  3053. + .iotype = UPIO_MEM,
  3054. + .flags = UPF_FIXED_TYPE | UPF_IOREMAP | UPF_SKIP_TEST,
  3055. + .type = PORT_8250,
  3056. + },
  3057. + {},
  3058. +};
  3059. +
  3060. +static struct platform_device bcm2708_uart1_device = {
  3061. + .name = "serial8250",
  3062. + .id = PLAT8250_DEV_PLATFORM,
  3063. + .dev = {
  3064. + .platform_data = bcm2708_uart1_platform_data,
  3065. + },
  3066. +};
  3067. +
  3068. +static struct resource bcm2708_usb_resources[] = {
  3069. + [0] = {
  3070. + .start = USB_BASE,
  3071. + .end = USB_BASE + SZ_128K - 1,
  3072. + .flags = IORESOURCE_MEM,
  3073. + },
  3074. + [1] = {
  3075. + .start = MPHI_BASE,
  3076. + .end = MPHI_BASE + SZ_4K - 1,
  3077. + .flags = IORESOURCE_MEM,
  3078. + },
  3079. + [2] = {
  3080. + .start = IRQ_HOSTPORT,
  3081. + .end = IRQ_HOSTPORT,
  3082. + .flags = IORESOURCE_IRQ,
  3083. + },
  3084. +};
  3085. +
  3086. +
  3087. +static u64 usb_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3088. +
  3089. +static struct platform_device bcm2708_usb_device = {
  3090. + .name = "bcm2708_usb",
  3091. + .id = -1, /* only one bcm2708_usb */
  3092. + .resource = bcm2708_usb_resources,
  3093. + .num_resources = ARRAY_SIZE(bcm2708_usb_resources),
  3094. + .dev = {
  3095. + .dma_mask = &usb_dmamask,
  3096. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  3097. + },
  3098. +};
  3099. +
  3100. +static struct resource bcm2708_vcio_resources[] = {
  3101. + [0] = { /* mailbox/semaphore/doorbell access */
  3102. + .start = MCORE_BASE,
  3103. + .end = MCORE_BASE + SZ_4K - 1,
  3104. + .flags = IORESOURCE_MEM,
  3105. + },
  3106. +};
  3107. +
  3108. +static u64 vcio_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3109. +
  3110. +static struct platform_device bcm2708_vcio_device = {
  3111. + .name = BCM_VCIO_DRIVER_NAME,
  3112. + .id = -1, /* only one VideoCore I/O area */
  3113. + .resource = bcm2708_vcio_resources,
  3114. + .num_resources = ARRAY_SIZE(bcm2708_vcio_resources),
  3115. + .dev = {
  3116. + .dma_mask = &vcio_dmamask,
  3117. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  3118. + },
  3119. +};
  3120. +
  3121. +#ifdef CONFIG_BCM2708_GPIO
  3122. +#define BCM_GPIO_DRIVER_NAME "bcm2708_gpio"
  3123. +
  3124. +static struct resource bcm2708_gpio_resources[] = {
  3125. + [0] = { /* general purpose I/O */
  3126. + .start = GPIO_BASE,
  3127. + .end = GPIO_BASE + SZ_4K - 1,
  3128. + .flags = IORESOURCE_MEM,
  3129. + },
  3130. +};
  3131. +
  3132. +static u64 gpio_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3133. +
  3134. +static struct platform_device bcm2708_gpio_device = {
  3135. + .name = BCM_GPIO_DRIVER_NAME,
  3136. + .id = -1, /* only one VideoCore I/O area */
  3137. + .resource = bcm2708_gpio_resources,
  3138. + .num_resources = ARRAY_SIZE(bcm2708_gpio_resources),
  3139. + .dev = {
  3140. + .dma_mask = &gpio_dmamask,
  3141. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  3142. + },
  3143. +};
  3144. +#endif
  3145. +
  3146. +static struct resource bcm2708_systemtimer_resources[] = {
  3147. + [0] = { /* system timer access */
  3148. + .start = ST_BASE,
  3149. + .end = ST_BASE + SZ_4K - 1,
  3150. + .flags = IORESOURCE_MEM,
  3151. + },
  3152. + {
  3153. + .start = IRQ_TIMER3,
  3154. + .end = IRQ_TIMER3,
  3155. + .flags = IORESOURCE_IRQ,
  3156. + }
  3157. +
  3158. +};
  3159. +
  3160. +static u64 systemtimer_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3161. +
  3162. +static struct platform_device bcm2708_systemtimer_device = {
  3163. + .name = "bcm2708_systemtimer",
  3164. + .id = -1, /* only one VideoCore I/O area */
  3165. + .resource = bcm2708_systemtimer_resources,
  3166. + .num_resources = ARRAY_SIZE(bcm2708_systemtimer_resources),
  3167. + .dev = {
  3168. + .dma_mask = &systemtimer_dmamask,
  3169. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  3170. + },
  3171. +};
  3172. +
  3173. +#ifdef CONFIG_MMC_SDHCI_BCM2708 /* Arasan emmc SD */
  3174. +static struct resource bcm2708_emmc_resources[] = {
  3175. + [0] = {
  3176. + .start = EMMC_BASE,
  3177. + .end = EMMC_BASE + SZ_256 - 1, /* we only need this area */
  3178. + /* the memory map actually makes SZ_4K available */
  3179. + .flags = IORESOURCE_MEM,
  3180. + },
  3181. + [1] = {
  3182. + .start = IRQ_ARASANSDIO,
  3183. + .end = IRQ_ARASANSDIO,
  3184. + .flags = IORESOURCE_IRQ,
  3185. + },
  3186. +};
  3187. +
  3188. +static u64 bcm2708_emmc_dmamask = 0xffffffffUL;
  3189. +
  3190. +struct platform_device bcm2708_emmc_device = {
  3191. + .name = "bcm2708_sdhci",
  3192. + .id = 0,
  3193. + .num_resources = ARRAY_SIZE(bcm2708_emmc_resources),
  3194. + .resource = bcm2708_emmc_resources,
  3195. + .dev = {
  3196. + .dma_mask = &bcm2708_emmc_dmamask,
  3197. + .coherent_dma_mask = 0xffffffffUL},
  3198. +};
  3199. +#endif /* CONFIG_MMC_SDHCI_BCM2708 */
  3200. +
  3201. +static struct resource bcm2708_powerman_resources[] = {
  3202. + [0] = {
  3203. + .start = PM_BASE,
  3204. + .end = PM_BASE + SZ_256 - 1,
  3205. + .flags = IORESOURCE_MEM,
  3206. + },
  3207. +};
  3208. +
  3209. +static u64 powerman_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3210. +
  3211. +struct platform_device bcm2708_powerman_device = {
  3212. + .name = "bcm2708_powerman",
  3213. + .id = 0,
  3214. + .num_resources = ARRAY_SIZE(bcm2708_powerman_resources),
  3215. + .resource = bcm2708_powerman_resources,
  3216. + .dev = {
  3217. + .dma_mask = &powerman_dmamask,
  3218. + .coherent_dma_mask = 0xffffffffUL},
  3219. +};
  3220. +
  3221. +
  3222. +static struct platform_device bcm2708_alsa_devices[] = {
  3223. + [0] = {
  3224. + .name = "bcm2835_AUD0",
  3225. + .id = 0, /* first audio device */
  3226. + .resource = 0,
  3227. + .num_resources = 0,
  3228. + },
  3229. + [1] = {
  3230. + .name = "bcm2835_AUD1",
  3231. + .id = 1, /* second audio device */
  3232. + .resource = 0,
  3233. + .num_resources = 0,
  3234. + },
  3235. + [2] = {
  3236. + .name = "bcm2835_AUD2",
  3237. + .id = 2, /* third audio device */
  3238. + .resource = 0,
  3239. + .num_resources = 0,
  3240. + },
  3241. + [3] = {
  3242. + .name = "bcm2835_AUD3",
  3243. + .id = 3, /* forth audio device */
  3244. + .resource = 0,
  3245. + .num_resources = 0,
  3246. + },
  3247. + [4] = {
  3248. + .name = "bcm2835_AUD4",
  3249. + .id = 4, /* fifth audio device */
  3250. + .resource = 0,
  3251. + .num_resources = 0,
  3252. + },
  3253. + [5] = {
  3254. + .name = "bcm2835_AUD5",
  3255. + .id = 5, /* sixth audio device */
  3256. + .resource = 0,
  3257. + .num_resources = 0,
  3258. + },
  3259. + [6] = {
  3260. + .name = "bcm2835_AUD6",
  3261. + .id = 6, /* seventh audio device */
  3262. + .resource = 0,
  3263. + .num_resources = 0,
  3264. + },
  3265. + [7] = {
  3266. + .name = "bcm2835_AUD7",
  3267. + .id = 7, /* eighth audio device */
  3268. + .resource = 0,
  3269. + .num_resources = 0,
  3270. + },
  3271. +};
  3272. +
  3273. +static struct resource bcm2708_spi_resources[] = {
  3274. + {
  3275. + .start = SPI0_BASE,
  3276. + .end = SPI0_BASE + SZ_256 - 1,
  3277. + .flags = IORESOURCE_MEM,
  3278. + }, {
  3279. + .start = IRQ_SPI,
  3280. + .end = IRQ_SPI,
  3281. + .flags = IORESOURCE_IRQ,
  3282. + }
  3283. +};
  3284. +
  3285. +
  3286. +static u64 bcm2708_spi_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3287. +static struct platform_device bcm2708_spi_device = {
  3288. + .name = "bcm2708_spi",
  3289. + .id = 0,
  3290. + .num_resources = ARRAY_SIZE(bcm2708_spi_resources),
  3291. + .resource = bcm2708_spi_resources,
  3292. + .dev = {
  3293. + .dma_mask = &bcm2708_spi_dmamask,
  3294. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON)},
  3295. +};
  3296. +
  3297. +#ifdef CONFIG_BCM2708_SPIDEV
  3298. +static struct spi_board_info bcm2708_spi_devices[] = {
  3299. +#ifdef CONFIG_SPI_SPIDEV
  3300. + {
  3301. + .modalias = "spidev",
  3302. + .max_speed_hz = 500000,
  3303. + .bus_num = 0,
  3304. + .chip_select = 0,
  3305. + .mode = SPI_MODE_0,
  3306. + }, {
  3307. + .modalias = "spidev",
  3308. + .max_speed_hz = 500000,
  3309. + .bus_num = 0,
  3310. + .chip_select = 1,
  3311. + .mode = SPI_MODE_0,
  3312. + }
  3313. +#endif
  3314. +};
  3315. +#endif
  3316. +
  3317. +static struct resource bcm2708_bsc0_resources[] = {
  3318. + {
  3319. + .start = BSC0_BASE,
  3320. + .end = BSC0_BASE + SZ_256 - 1,
  3321. + .flags = IORESOURCE_MEM,
  3322. + }, {
  3323. + .start = INTERRUPT_I2C,
  3324. + .end = INTERRUPT_I2C,
  3325. + .flags = IORESOURCE_IRQ,
  3326. + }
  3327. +};
  3328. +
  3329. +static struct platform_device bcm2708_bsc0_device = {
  3330. + .name = "bcm2708_i2c",
  3331. + .id = 0,
  3332. + .num_resources = ARRAY_SIZE(bcm2708_bsc0_resources),
  3333. + .resource = bcm2708_bsc0_resources,
  3334. +};
  3335. +
  3336. +
  3337. +static struct resource bcm2708_bsc1_resources[] = {
  3338. + {
  3339. + .start = BSC1_BASE,
  3340. + .end = BSC1_BASE + SZ_256 - 1,
  3341. + .flags = IORESOURCE_MEM,
  3342. + }, {
  3343. + .start = INTERRUPT_I2C,
  3344. + .end = INTERRUPT_I2C,
  3345. + .flags = IORESOURCE_IRQ,
  3346. + }
  3347. +};
  3348. +
  3349. +static struct platform_device bcm2708_bsc1_device = {
  3350. + .name = "bcm2708_i2c",
  3351. + .id = 1,
  3352. + .num_resources = ARRAY_SIZE(bcm2708_bsc1_resources),
  3353. + .resource = bcm2708_bsc1_resources,
  3354. +};
  3355. +
  3356. +static struct platform_device bcm2835_hwmon_device = {
  3357. + .name = "bcm2835_hwmon",
  3358. +};
  3359. +
  3360. +static struct platform_device bcm2835_thermal_device = {
  3361. + .name = "bcm2835_thermal",
  3362. +};
  3363. +
  3364. +#ifdef CONFIG_SND_BCM2708_SOC_I2S_MODULE
  3365. +static struct resource bcm2708_i2s_resources[] = {
  3366. + {
  3367. + .start = I2S_BASE,
  3368. + .end = I2S_BASE + 0x20,
  3369. + .flags = IORESOURCE_MEM,
  3370. + },
  3371. + {
  3372. + .start = PCM_CLOCK_BASE,
  3373. + .end = PCM_CLOCK_BASE + 0x02,
  3374. + .flags = IORESOURCE_MEM,
  3375. + }
  3376. +};
  3377. +
  3378. +static struct platform_device bcm2708_i2s_device = {
  3379. + .name = "bcm2708-i2s",
  3380. + .id = 0,
  3381. + .num_resources = ARRAY_SIZE(bcm2708_i2s_resources),
  3382. + .resource = bcm2708_i2s_resources,
  3383. +};
  3384. +#endif
  3385. +
  3386. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC_MODULE)
  3387. +static struct platform_device snd_hifiberry_dac_device = {
  3388. + .name = "snd-hifiberry-dac",
  3389. + .id = 0,
  3390. + .num_resources = 0,
  3391. +};
  3392. +
  3393. +static struct platform_device snd_pcm5102a_codec_device = {
  3394. + .name = "pcm5102a-codec",
  3395. + .id = -1,
  3396. + .num_resources = 0,
  3397. +};
  3398. +#endif
  3399. +
  3400. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI_MODULE)
  3401. +static struct platform_device snd_hifiberry_digi_device = {
  3402. + .name = "snd-hifiberry-digi",
  3403. + .id = 0,
  3404. + .num_resources = 0,
  3405. +};
  3406. +
  3407. +static struct i2c_board_info __initdata snd_wm8804_i2c_devices[] = {
  3408. + {
  3409. + I2C_BOARD_INFO("wm8804", 0x3b)
  3410. + },
  3411. +};
  3412. +
  3413. +#endif
  3414. +
  3415. +#if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
  3416. +static struct platform_device snd_rpi_dac_device = {
  3417. + .name = "snd-rpi-dac",
  3418. + .id = 0,
  3419. + .num_resources = 0,
  3420. +};
  3421. +
  3422. +static struct platform_device snd_pcm1794a_codec_device = {
  3423. + .name = "pcm1794a-codec",
  3424. + .id = -1,
  3425. + .num_resources = 0,
  3426. +};
  3427. +#endif
  3428. +
  3429. +
  3430. +#if defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) || defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC_MODULE)
  3431. +static struct platform_device snd_rpi_iqaudio_dac_device = {
  3432. + .name = "snd-rpi-iqaudio-dac",
  3433. + .id = 0,
  3434. + .num_resources = 0,
  3435. +};
  3436. +
  3437. +// Use the actual device name rather than generic driver name
  3438. +static struct i2c_board_info __initdata snd_pcm512x_i2c_devices[] = {
  3439. + {
  3440. + I2C_BOARD_INFO("pcm5122", 0x4c)
  3441. + },
  3442. +};
  3443. +#endif
  3444. +
  3445. +int __init bcm_register_device(struct platform_device *pdev)
  3446. +{
  3447. + int ret;
  3448. +
  3449. + ret = platform_device_register(pdev);
  3450. + if (ret)
  3451. + pr_debug("Unable to register platform device '%s': %d\n",
  3452. + pdev->name, ret);
  3453. +
  3454. + return ret;
  3455. +}
  3456. +
  3457. +int calc_rsts(int partition)
  3458. +{
  3459. + return PM_PASSWORD |
  3460. + ((partition & (1 << 0)) << 0) |
  3461. + ((partition & (1 << 1)) << 1) |
  3462. + ((partition & (1 << 2)) << 2) |
  3463. + ((partition & (1 << 3)) << 3) |
  3464. + ((partition & (1 << 4)) << 4) |
  3465. + ((partition & (1 << 5)) << 5);
  3466. +}
  3467. +
  3468. +static void bcm2708_restart(enum reboot_mode mode, const char *cmd)
  3469. +{
  3470. + extern char bcm2708_reboot_mode;
  3471. + uint32_t pm_rstc, pm_wdog;
  3472. + uint32_t timeout = 10;
  3473. + uint32_t pm_rsts = 0;
  3474. +
  3475. + if(bcm2708_reboot_mode == 'q')
  3476. + {
  3477. + // NOOBS < 1.3 booting with reboot=q
  3478. + pm_rsts = readl(__io_address(PM_RSTS));
  3479. + pm_rsts = PM_PASSWORD | pm_rsts | PM_RSTS_HADWRQ_SET;
  3480. + }
  3481. + else if(bcm2708_reboot_mode == 'p')
  3482. + {
  3483. + // NOOBS < 1.3 halting
  3484. + pm_rsts = readl(__io_address(PM_RSTS));
  3485. + pm_rsts = PM_PASSWORD | pm_rsts | PM_RSTS_HADWRH_SET;
  3486. + }
  3487. + else
  3488. + {
  3489. + pm_rsts = calc_rsts(reboot_part);
  3490. + }
  3491. +
  3492. + writel(pm_rsts, __io_address(PM_RSTS));
  3493. +
  3494. + /* Setup watchdog for reset */
  3495. + pm_rstc = readl(__io_address(PM_RSTC));
  3496. +
  3497. + pm_wdog = PM_PASSWORD | (timeout & PM_WDOG_TIME_SET); // watchdog timer = timer clock / 16; need password (31:16) + value (11:0)
  3498. + pm_rstc = PM_PASSWORD | (pm_rstc & PM_RSTC_WRCFG_CLR) | PM_RSTC_WRCFG_FULL_RESET;
  3499. +
  3500. + writel(pm_wdog, __io_address(PM_WDOG));
  3501. + writel(pm_rstc, __io_address(PM_RSTC));
  3502. +}
  3503. +
  3504. +/* 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 */
  3505. +static void bcm2708_power_off(void)
  3506. +{
  3507. + extern char bcm2708_reboot_mode;
  3508. + if(bcm2708_reboot_mode == 'q')
  3509. + {
  3510. + // NOOBS < v1.3
  3511. + bcm2708_restart('p', "");
  3512. + }
  3513. + else
  3514. + {
  3515. + /* partition 63 is special code for HALT the bootloader knows not to boot*/
  3516. + reboot_part = 63;
  3517. + /* continue with normal reset mechanism */
  3518. + bcm2708_restart(0, "");
  3519. + }
  3520. +}
  3521. +
  3522. +void __init bcm2708_init(void)
  3523. +{
  3524. + int i;
  3525. +
  3526. +#if defined(CONFIG_BCM_VC_CMA)
  3527. + vc_cma_early_init();
  3528. +#endif
  3529. + printk("bcm2708.uart_clock = %d\n", uart_clock);
  3530. + pm_power_off = bcm2708_power_off;
  3531. +
  3532. + if (uart_clock)
  3533. + lookups[0].clk->rate = uart_clock;
  3534. +
  3535. + for (i = 0; i < ARRAY_SIZE(lookups); i++)
  3536. + clkdev_add(&lookups[i]);
  3537. +
  3538. + bcm_register_device(&bcm2708_dmaman_device);
  3539. + bcm_register_device(&bcm2708_vcio_device);
  3540. +#ifdef CONFIG_BCM2708_GPIO
  3541. + bcm_register_device(&bcm2708_gpio_device);
  3542. +#endif
  3543. +#if defined(CONFIG_W1_MASTER_GPIO) || defined(CONFIG_W1_MASTER_GPIO_MODULE)
  3544. + w1_gpio_pdata.pin = w1_gpio_pin;
  3545. + platform_device_register(&w1_device);
  3546. +#endif
  3547. + bcm_register_device(&bcm2708_systemtimer_device);
  3548. + bcm_register_device(&bcm2708_fb_device);
  3549. + bcm_register_device(&bcm2708_usb_device);
  3550. + bcm_register_device(&bcm2708_uart1_device);
  3551. + bcm_register_device(&bcm2708_powerman_device);
  3552. +
  3553. +#ifdef CONFIG_MMC_SDHCI_BCM2708
  3554. + bcm_register_device(&bcm2708_emmc_device);
  3555. +#endif
  3556. + bcm2708_init_led();
  3557. + for (i = 0; i < ARRAY_SIZE(bcm2708_alsa_devices); i++)
  3558. + bcm_register_device(&bcm2708_alsa_devices[i]);
  3559. +
  3560. + bcm_register_device(&bcm2708_spi_device);
  3561. + bcm_register_device(&bcm2708_bsc0_device);
  3562. + bcm_register_device(&bcm2708_bsc1_device);
  3563. +
  3564. + bcm_register_device(&bcm2835_hwmon_device);
  3565. + bcm_register_device(&bcm2835_thermal_device);
  3566. +
  3567. +#ifdef CONFIG_SND_BCM2708_SOC_I2S_MODULE
  3568. + bcm_register_device(&bcm2708_i2s_device);
  3569. +#endif
  3570. +
  3571. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC_MODULE)
  3572. + bcm_register_device(&snd_hifiberry_dac_device);
  3573. + bcm_register_device(&snd_pcm5102a_codec_device);
  3574. +#endif
  3575. +
  3576. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI_MODULE)
  3577. + bcm_register_device(&snd_hifiberry_digi_device);
  3578. + i2c_register_board_info(1, snd_wm8804_i2c_devices, ARRAY_SIZE(snd_wm8804_i2c_devices));
  3579. +#endif
  3580. +
  3581. +#if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
  3582. + bcm_register_device(&snd_rpi_dac_device);
  3583. + bcm_register_device(&snd_pcm1794a_codec_device);
  3584. +#endif
  3585. +
  3586. +#if defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) || defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC_MODULE)
  3587. + bcm_register_device(&snd_rpi_iqaudio_dac_device);
  3588. + i2c_register_board_info(1, snd_pcm512x_i2c_devices, ARRAY_SIZE(snd_pcm512x_i2c_devices));
  3589. +#endif
  3590. +
  3591. +
  3592. + for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
  3593. + struct amba_device *d = amba_devs[i];
  3594. + amba_device_register(d, &iomem_resource);
  3595. + }
  3596. + system_rev = boardrev;
  3597. + system_serial_low = serial;
  3598. +
  3599. +#ifdef CONFIG_BCM2708_SPIDEV
  3600. + spi_register_board_info(bcm2708_spi_devices,
  3601. + ARRAY_SIZE(bcm2708_spi_devices));
  3602. +#endif
  3603. +}
  3604. +
  3605. +static void timer_set_mode(enum clock_event_mode mode,
  3606. + struct clock_event_device *clk)
  3607. +{
  3608. + switch (mode) {
  3609. + case CLOCK_EVT_MODE_ONESHOT: /* Leave the timer disabled, .set_next_event will enable it */
  3610. + case CLOCK_EVT_MODE_SHUTDOWN:
  3611. + break;
  3612. + case CLOCK_EVT_MODE_PERIODIC:
  3613. +
  3614. + case CLOCK_EVT_MODE_UNUSED:
  3615. + case CLOCK_EVT_MODE_RESUME:
  3616. +
  3617. + default:
  3618. + printk(KERN_ERR "timer_set_mode: unhandled mode:%d\n",
  3619. + (int)mode);
  3620. + break;
  3621. + }
  3622. +
  3623. +}
  3624. +
  3625. +static int timer_set_next_event(unsigned long cycles,
  3626. + struct clock_event_device *unused)
  3627. +{
  3628. + unsigned long stc;
  3629. +
  3630. + stc = readl(__io_address(ST_BASE + 0x04));
  3631. + writel(stc + cycles, __io_address(ST_BASE + 0x18)); /* stc3 */
  3632. + return 0;
  3633. +}
  3634. +
  3635. +static struct clock_event_device timer0_clockevent = {
  3636. + .name = "timer0",
  3637. + .shift = 32,
  3638. + .features = CLOCK_EVT_FEAT_ONESHOT,
  3639. + .set_mode = timer_set_mode,
  3640. + .set_next_event = timer_set_next_event,
  3641. +};
  3642. +
  3643. +/*
  3644. + * IRQ handler for the timer
  3645. + */
  3646. +static irqreturn_t bcm2708_timer_interrupt(int irq, void *dev_id)
  3647. +{
  3648. + struct clock_event_device *evt = &timer0_clockevent;
  3649. +
  3650. + writel(1 << 3, __io_address(ST_BASE + 0x00)); /* stcs clear timer int */
  3651. +
  3652. + evt->event_handler(evt);
  3653. +
  3654. + return IRQ_HANDLED;
  3655. +}
  3656. +
  3657. +static struct irqaction bcm2708_timer_irq = {
  3658. + .name = "BCM2708 Timer Tick",
  3659. + .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  3660. + .handler = bcm2708_timer_interrupt,
  3661. +};
  3662. +
  3663. +/*
  3664. + * Set up timer interrupt, and return the current time in seconds.
  3665. + */
  3666. +
  3667. +static struct delay_timer bcm2708_delay_timer = {
  3668. + .read_current_timer = bcm2708_read_current_timer,
  3669. + .freq = STC_FREQ_HZ,
  3670. +};
  3671. +
  3672. +static void __init bcm2708_timer_init(void)
  3673. +{
  3674. + /* init high res timer */
  3675. + bcm2708_clocksource_init();
  3676. +
  3677. + /*
  3678. + * Initialise to a known state (all timers off)
  3679. + */
  3680. + writel(0, __io_address(ARM_T_CONTROL));
  3681. + /*
  3682. + * Make irqs happen for the system timer
  3683. + */
  3684. + setup_irq(IRQ_TIMER3, &bcm2708_timer_irq);
  3685. +
  3686. + setup_sched_clock(bcm2708_read_sched_clock, 32, STC_FREQ_HZ);
  3687. +
  3688. + timer0_clockevent.mult =
  3689. + div_sc(STC_FREQ_HZ, NSEC_PER_SEC, timer0_clockevent.shift);
  3690. + timer0_clockevent.max_delta_ns =
  3691. + clockevent_delta2ns(0xffffffff, &timer0_clockevent);
  3692. + timer0_clockevent.min_delta_ns =
  3693. + clockevent_delta2ns(0xf, &timer0_clockevent);
  3694. +
  3695. + timer0_clockevent.cpumask = cpumask_of(0);
  3696. + clockevents_register_device(&timer0_clockevent);
  3697. +
  3698. + register_current_timer_delay(&bcm2708_delay_timer);
  3699. +}
  3700. +
  3701. +#if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
  3702. +#include <linux/leds.h>
  3703. +
  3704. +static struct gpio_led bcm2708_leds[] = {
  3705. + [0] = {
  3706. + .gpio = 16,
  3707. + .name = "led0",
  3708. + .default_trigger = "mmc0",
  3709. + .active_low = 1,
  3710. + },
  3711. +};
  3712. +
  3713. +static struct gpio_led_platform_data bcm2708_led_pdata = {
  3714. + .num_leds = ARRAY_SIZE(bcm2708_leds),
  3715. + .leds = bcm2708_leds,
  3716. +};
  3717. +
  3718. +static struct platform_device bcm2708_led_device = {
  3719. + .name = "leds-gpio",
  3720. + .id = -1,
  3721. + .dev = {
  3722. + .platform_data = &bcm2708_led_pdata,
  3723. + },
  3724. +};
  3725. +
  3726. +static void __init bcm2708_init_led(void)
  3727. +{
  3728. + bcm2708_leds[0].gpio = disk_led_gpio;
  3729. + bcm2708_leds[0].active_low = disk_led_active_low;
  3730. + platform_device_register(&bcm2708_led_device);
  3731. +}
  3732. +#else
  3733. +static inline void bcm2708_init_led(void)
  3734. +{
  3735. +}
  3736. +#endif
  3737. +
  3738. +void __init bcm2708_init_early(void)
  3739. +{
  3740. + /*
  3741. + * Some devices allocate their coherent buffers from atomic
  3742. + * context. Increase size of atomic coherent pool to make sure such
  3743. + * the allocations won't fail.
  3744. + */
  3745. + init_dma_coherent_pool_size(SZ_4M);
  3746. +}
  3747. +
  3748. +static void __init board_reserve(void)
  3749. +{
  3750. +#if defined(CONFIG_BCM_VC_CMA)
  3751. + vc_cma_reserve();
  3752. +#endif
  3753. +}
  3754. +
  3755. +MACHINE_START(BCM2708, "BCM2708")
  3756. + /* Maintainer: Broadcom Europe Ltd. */
  3757. + .map_io = bcm2708_map_io,
  3758. + .init_irq = bcm2708_init_irq,
  3759. + .init_time = bcm2708_timer_init,
  3760. + .init_machine = bcm2708_init,
  3761. + .init_early = bcm2708_init_early,
  3762. + .reserve = board_reserve,
  3763. + .restart = bcm2708_restart,
  3764. +MACHINE_END
  3765. +
  3766. +module_param(boardrev, uint, 0644);
  3767. +module_param(serial, uint, 0644);
  3768. +module_param(uart_clock, uint, 0644);
  3769. +module_param(disk_led_gpio, uint, 0644);
  3770. +module_param(disk_led_active_low, uint, 0644);
  3771. +module_param(reboot_part, uint, 0644);
  3772. +module_param(w1_gpio_pin, uint, 0644);
  3773. diff -Nur linux-3.12.26.orig/arch/arm/mach-bcm2708/bcm2708_gpio.c linux-3.12.26/arch/arm/mach-bcm2708/bcm2708_gpio.c
  3774. --- linux-3.12.26.orig/arch/arm/mach-bcm2708/bcm2708_gpio.c 1970-01-01 01:00:00.000000000 +0100
  3775. +++ linux-3.12.26/arch/arm/mach-bcm2708/bcm2708_gpio.c 2014-08-06 16:50:13.821957030 +0200
  3776. @@ -0,0 +1,361 @@
  3777. +/*
  3778. + * linux/arch/arm/mach-bcm2708/bcm2708_gpio.c
  3779. + *
  3780. + * Copyright (C) 2010 Broadcom
  3781. + *
  3782. + * This program is free software; you can redistribute it and/or modify
  3783. + * it under the terms of the GNU General Public License version 2 as
  3784. + * published by the Free Software Foundation.
  3785. + *
  3786. + */
  3787. +
  3788. +#include <linux/spinlock.h>
  3789. +#include <linux/module.h>
  3790. +#include <linux/list.h>
  3791. +#include <linux/io.h>
  3792. +#include <linux/irq.h>
  3793. +#include <linux/interrupt.h>
  3794. +#include <linux/slab.h>
  3795. +#include <mach/gpio.h>
  3796. +#include <linux/gpio.h>
  3797. +#include <linux/platform_device.h>
  3798. +#include <mach/platform.h>
  3799. +
  3800. +#define BCM_GPIO_DRIVER_NAME "bcm2708_gpio"
  3801. +#define DRIVER_NAME BCM_GPIO_DRIVER_NAME
  3802. +#define BCM_GPIO_USE_IRQ 1
  3803. +
  3804. +#define GPIOFSEL(x) (0x00+(x)*4)
  3805. +#define GPIOSET(x) (0x1c+(x)*4)
  3806. +#define GPIOCLR(x) (0x28+(x)*4)
  3807. +#define GPIOLEV(x) (0x34+(x)*4)
  3808. +#define GPIOEDS(x) (0x40+(x)*4)
  3809. +#define GPIOREN(x) (0x4c+(x)*4)
  3810. +#define GPIOFEN(x) (0x58+(x)*4)
  3811. +#define GPIOHEN(x) (0x64+(x)*4)
  3812. +#define GPIOLEN(x) (0x70+(x)*4)
  3813. +#define GPIOAREN(x) (0x7c+(x)*4)
  3814. +#define GPIOAFEN(x) (0x88+(x)*4)
  3815. +#define GPIOUD(x) (0x94+(x)*4)
  3816. +#define GPIOUDCLK(x) (0x98+(x)*4)
  3817. +
  3818. +enum { GPIO_FSEL_INPUT, GPIO_FSEL_OUTPUT,
  3819. + GPIO_FSEL_ALT5, GPIO_FSEL_ALT_4,
  3820. + GPIO_FSEL_ALT0, GPIO_FSEL_ALT1,
  3821. + GPIO_FSEL_ALT2, GPIO_FSEL_ALT3,
  3822. +};
  3823. +
  3824. + /* Each of the two spinlocks protects a different set of hardware
  3825. + * regiters and data structurs. This decouples the code of the IRQ from
  3826. + * the GPIO code. This also makes the case of a GPIO routine call from
  3827. + * the IRQ code simpler.
  3828. + */
  3829. +static DEFINE_SPINLOCK(lock); /* GPIO registers */
  3830. +
  3831. +struct bcm2708_gpio {
  3832. + struct list_head list;
  3833. + void __iomem *base;
  3834. + struct gpio_chip gc;
  3835. + unsigned long rising;
  3836. + unsigned long falling;
  3837. + unsigned long high;
  3838. + unsigned long low;
  3839. +};
  3840. +
  3841. +static int bcm2708_set_function(struct gpio_chip *gc, unsigned offset,
  3842. + int function)
  3843. +{
  3844. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  3845. + unsigned long flags;
  3846. + unsigned gpiodir;
  3847. + unsigned gpio_bank = offset / 10;
  3848. + unsigned gpio_field_offset = (offset - 10 * gpio_bank) * 3;
  3849. +
  3850. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_set_function %p (%d,%d)\n", gc, offset, function);
  3851. + if (offset >= BCM2708_NR_GPIOS)
  3852. + return -EINVAL;
  3853. +
  3854. + spin_lock_irqsave(&lock, flags);
  3855. +
  3856. + gpiodir = readl(gpio->base + GPIOFSEL(gpio_bank));
  3857. + gpiodir &= ~(7 << gpio_field_offset);
  3858. + gpiodir |= function << gpio_field_offset;
  3859. + writel(gpiodir, gpio->base + GPIOFSEL(gpio_bank));
  3860. + spin_unlock_irqrestore(&lock, flags);
  3861. + gpiodir = readl(gpio->base + GPIOFSEL(gpio_bank));
  3862. +
  3863. + return 0;
  3864. +}
  3865. +
  3866. +static int bcm2708_gpio_dir_in(struct gpio_chip *gc, unsigned offset)
  3867. +{
  3868. + return bcm2708_set_function(gc, offset, GPIO_FSEL_INPUT);
  3869. +}
  3870. +
  3871. +static void bcm2708_gpio_set(struct gpio_chip *gc, unsigned offset, int value);
  3872. +static int bcm2708_gpio_dir_out(struct gpio_chip *gc, unsigned offset,
  3873. + int value)
  3874. +{
  3875. + int ret;
  3876. + ret = bcm2708_set_function(gc, offset, GPIO_FSEL_OUTPUT);
  3877. + if (ret >= 0)
  3878. + bcm2708_gpio_set(gc, offset, value);
  3879. + return ret;
  3880. +}
  3881. +
  3882. +static int bcm2708_gpio_get(struct gpio_chip *gc, unsigned offset)
  3883. +{
  3884. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  3885. + unsigned gpio_bank = offset / 32;
  3886. + unsigned gpio_field_offset = (offset - 32 * gpio_bank);
  3887. + unsigned lev;
  3888. +
  3889. + if (offset >= BCM2708_NR_GPIOS)
  3890. + return 0;
  3891. + lev = readl(gpio->base + GPIOLEV(gpio_bank));
  3892. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_get %p (%d)=%d\n", gc, offset, 0x1 & (lev>>gpio_field_offset));
  3893. + return 0x1 & (lev >> gpio_field_offset);
  3894. +}
  3895. +
  3896. +static void bcm2708_gpio_set(struct gpio_chip *gc, unsigned offset, int value)
  3897. +{
  3898. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  3899. + unsigned gpio_bank = offset / 32;
  3900. + unsigned gpio_field_offset = (offset - 32 * gpio_bank);
  3901. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_set %p (%d=%d)\n", gc, offset, value);
  3902. + if (offset >= BCM2708_NR_GPIOS)
  3903. + return;
  3904. + if (value)
  3905. + writel(1 << gpio_field_offset, gpio->base + GPIOSET(gpio_bank));
  3906. + else
  3907. + writel(1 << gpio_field_offset, gpio->base + GPIOCLR(gpio_bank));
  3908. +}
  3909. +
  3910. +/*************************************************************************************************************************
  3911. + * bcm2708 GPIO IRQ
  3912. + */
  3913. +
  3914. +#if BCM_GPIO_USE_IRQ
  3915. +
  3916. +static int bcm2708_gpio_to_irq(struct gpio_chip *chip, unsigned gpio)
  3917. +{
  3918. + return gpio_to_irq(gpio);
  3919. +}
  3920. +
  3921. +static int bcm2708_gpio_irq_set_type(struct irq_data *d, unsigned type)
  3922. +{
  3923. + unsigned irq = d->irq;
  3924. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  3925. +
  3926. + gpio->rising &= ~(1 << irq_to_gpio(irq));
  3927. + gpio->falling &= ~(1 << irq_to_gpio(irq));
  3928. + gpio->high &= ~(1 << irq_to_gpio(irq));
  3929. + gpio->low &= ~(1 << irq_to_gpio(irq));
  3930. +
  3931. + if (type & ~(IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING | IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
  3932. + return -EINVAL;
  3933. +
  3934. + if (type & IRQ_TYPE_EDGE_RISING)
  3935. + gpio->rising |= (1 << irq_to_gpio(irq));
  3936. + if (type & IRQ_TYPE_EDGE_FALLING)
  3937. + gpio->falling |= (1 << irq_to_gpio(irq));
  3938. + if (type & IRQ_TYPE_LEVEL_HIGH)
  3939. + gpio->high |= (1 << irq_to_gpio(irq));
  3940. + if (type & IRQ_TYPE_LEVEL_LOW)
  3941. + gpio->low |= (1 << irq_to_gpio(irq));
  3942. + return 0;
  3943. +}
  3944. +
  3945. +static void bcm2708_gpio_irq_mask(struct irq_data *d)
  3946. +{
  3947. + unsigned irq = d->irq;
  3948. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  3949. + unsigned gn = irq_to_gpio(irq);
  3950. + unsigned gb = gn / 32;
  3951. + unsigned long rising = readl(gpio->base + GPIOREN(gb));
  3952. + unsigned long falling = readl(gpio->base + GPIOFEN(gb));
  3953. + unsigned long high = readl(gpio->base + GPIOHEN(gb));
  3954. + unsigned long low = readl(gpio->base + GPIOLEN(gb));
  3955. +
  3956. + gn = gn % 32;
  3957. +
  3958. + writel(rising & ~(1 << gn), gpio->base + GPIOREN(gb));
  3959. + writel(falling & ~(1 << gn), gpio->base + GPIOFEN(gb));
  3960. + writel(high & ~(1 << gn), gpio->base + GPIOHEN(gb));
  3961. + writel(low & ~(1 << gn), gpio->base + GPIOLEN(gb));
  3962. +}
  3963. +
  3964. +static void bcm2708_gpio_irq_unmask(struct irq_data *d)
  3965. +{
  3966. + unsigned irq = d->irq;
  3967. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  3968. + unsigned gn = irq_to_gpio(irq);
  3969. + unsigned gb = gn / 32;
  3970. + unsigned long rising = readl(gpio->base + GPIOREN(gb));
  3971. + unsigned long falling = readl(gpio->base + GPIOFEN(gb));
  3972. + unsigned long high = readl(gpio->base + GPIOHEN(gb));
  3973. + unsigned long low = readl(gpio->base + GPIOLEN(gb));
  3974. +
  3975. + gn = gn % 32;
  3976. +
  3977. + writel(1 << gn, gpio->base + GPIOEDS(gb));
  3978. +
  3979. + if (gpio->rising & (1 << gn)) {
  3980. + writel(rising | (1 << gn), gpio->base + GPIOREN(gb));
  3981. + } else {
  3982. + writel(rising & ~(1 << gn), gpio->base + GPIOREN(gb));
  3983. + }
  3984. +
  3985. + if (gpio->falling & (1 << gn)) {
  3986. + writel(falling | (1 << gn), gpio->base + GPIOFEN(gb));
  3987. + } else {
  3988. + writel(falling & ~(1 << gn), gpio->base + GPIOFEN(gb));
  3989. + }
  3990. +
  3991. + if (gpio->high & (1 << gn)) {
  3992. + writel(high | (1 << gn), gpio->base + GPIOHEN(gb));
  3993. + } else {
  3994. + writel(high & ~(1 << gn), gpio->base + GPIOHEN(gb));
  3995. + }
  3996. +
  3997. + if (gpio->low & (1 << gn)) {
  3998. + writel(low | (1 << gn), gpio->base + GPIOLEN(gb));
  3999. + } else {
  4000. + writel(low & ~(1 << gn), gpio->base + GPIOLEN(gb));
  4001. + }
  4002. +}
  4003. +
  4004. +static struct irq_chip bcm2708_irqchip = {
  4005. + .name = "GPIO",
  4006. + .irq_enable = bcm2708_gpio_irq_unmask,
  4007. + .irq_disable = bcm2708_gpio_irq_mask,
  4008. + .irq_unmask = bcm2708_gpio_irq_unmask,
  4009. + .irq_mask = bcm2708_gpio_irq_mask,
  4010. + .irq_set_type = bcm2708_gpio_irq_set_type,
  4011. +};
  4012. +
  4013. +static irqreturn_t bcm2708_gpio_interrupt(int irq, void *dev_id)
  4014. +{
  4015. + unsigned long edsr;
  4016. + unsigned bank;
  4017. + int i;
  4018. + unsigned gpio;
  4019. + for (bank = 0; bank <= 1; bank++) {
  4020. + edsr = readl(__io_address(GPIO_BASE) + GPIOEDS(bank));
  4021. + for_each_set_bit(i, &edsr, 32) {
  4022. + gpio = i + bank * 32;
  4023. + generic_handle_irq(gpio_to_irq(gpio));
  4024. + }
  4025. + writel(0xffffffff, __io_address(GPIO_BASE) + GPIOEDS(bank));
  4026. + }
  4027. + return IRQ_HANDLED;
  4028. +}
  4029. +
  4030. +static struct irqaction bcm2708_gpio_irq = {
  4031. + .name = "BCM2708 GPIO catchall handler",
  4032. + .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  4033. + .handler = bcm2708_gpio_interrupt,
  4034. +};
  4035. +
  4036. +static void bcm2708_gpio_irq_init(struct bcm2708_gpio *ucb)
  4037. +{
  4038. + unsigned irq;
  4039. +
  4040. + ucb->gc.to_irq = bcm2708_gpio_to_irq;
  4041. +
  4042. + for (irq = GPIO_IRQ_START; irq < (GPIO_IRQ_START + GPIO_IRQS); irq++) {
  4043. + irq_set_chip_data(irq, ucb);
  4044. + irq_set_chip(irq, &bcm2708_irqchip);
  4045. + set_irq_flags(irq, IRQF_VALID);
  4046. + }
  4047. + setup_irq(IRQ_GPIO3, &bcm2708_gpio_irq);
  4048. +}
  4049. +
  4050. +#else
  4051. +
  4052. +static void bcm2708_gpio_irq_init(struct bcm2708_gpio *ucb)
  4053. +{
  4054. +}
  4055. +
  4056. +#endif /* #if BCM_GPIO_USE_IRQ ***************************************************************************************************************** */
  4057. +
  4058. +static int bcm2708_gpio_probe(struct platform_device *dev)
  4059. +{
  4060. + struct bcm2708_gpio *ucb;
  4061. + struct resource *res;
  4062. + int err = 0;
  4063. +
  4064. + printk(KERN_INFO DRIVER_NAME ": bcm2708_gpio_probe %p\n", dev);
  4065. +
  4066. + ucb = kzalloc(sizeof(*ucb), GFP_KERNEL);
  4067. + if (NULL == ucb) {
  4068. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  4069. + "mailbox memory\n");
  4070. + err = -ENOMEM;
  4071. + goto err;
  4072. + }
  4073. +
  4074. + res = platform_get_resource(dev, IORESOURCE_MEM, 0);
  4075. +
  4076. + platform_set_drvdata(dev, ucb);
  4077. + ucb->base = __io_address(GPIO_BASE);
  4078. +
  4079. + ucb->gc.label = "bcm2708_gpio";
  4080. + ucb->gc.base = 0;
  4081. + ucb->gc.ngpio = BCM2708_NR_GPIOS;
  4082. + ucb->gc.owner = THIS_MODULE;
  4083. +
  4084. + ucb->gc.direction_input = bcm2708_gpio_dir_in;
  4085. + ucb->gc.direction_output = bcm2708_gpio_dir_out;
  4086. + ucb->gc.get = bcm2708_gpio_get;
  4087. + ucb->gc.set = bcm2708_gpio_set;
  4088. + ucb->gc.can_sleep = 0;
  4089. +
  4090. + bcm2708_gpio_irq_init(ucb);
  4091. +
  4092. + err = gpiochip_add(&ucb->gc);
  4093. + if (err)
  4094. + goto err;
  4095. +
  4096. +err:
  4097. + return err;
  4098. +
  4099. +}
  4100. +
  4101. +static int bcm2708_gpio_remove(struct platform_device *dev)
  4102. +{
  4103. + int err = 0;
  4104. + struct bcm2708_gpio *ucb = platform_get_drvdata(dev);
  4105. +
  4106. + printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_remove %p\n", dev);
  4107. +
  4108. + err = gpiochip_remove(&ucb->gc);
  4109. +
  4110. + platform_set_drvdata(dev, NULL);
  4111. + kfree(ucb);
  4112. +
  4113. + return err;
  4114. +}
  4115. +
  4116. +static struct platform_driver bcm2708_gpio_driver = {
  4117. + .probe = bcm2708_gpio_probe,
  4118. + .remove = bcm2708_gpio_remove,
  4119. + .driver = {
  4120. + .name = "bcm2708_gpio"},
  4121. +};
  4122. +
  4123. +static int __init bcm2708_gpio_init(void)
  4124. +{
  4125. + return platform_driver_register(&bcm2708_gpio_driver);
  4126. +}
  4127. +
  4128. +static void __exit bcm2708_gpio_exit(void)
  4129. +{
  4130. + platform_driver_unregister(&bcm2708_gpio_driver);
  4131. +}
  4132. +
  4133. +module_init(bcm2708_gpio_init);
  4134. +module_exit(bcm2708_gpio_exit);
  4135. +
  4136. +MODULE_DESCRIPTION("Broadcom BCM2708 GPIO driver");
  4137. +MODULE_LICENSE("GPL");
  4138. diff -Nur linux-3.12.26.orig/arch/arm/mach-bcm2708/bcm2708.h linux-3.12.26/arch/arm/mach-bcm2708/bcm2708.h
  4139. --- linux-3.12.26.orig/arch/arm/mach-bcm2708/bcm2708.h 1970-01-01 01:00:00.000000000 +0100
  4140. +++ linux-3.12.26/arch/arm/mach-bcm2708/bcm2708.h 2014-08-06 16:50:13.821957030 +0200
  4141. @@ -0,0 +1,49 @@
  4142. +/*
  4143. + * linux/arch/arm/mach-bcm2708/bcm2708.h
  4144. + *
  4145. + * BCM2708 machine support header
  4146. + *
  4147. + * Copyright (C) 2010 Broadcom
  4148. + *
  4149. + * This program is free software; you can redistribute it and/or modify
  4150. + * it under the terms of the GNU General Public License as published by
  4151. + * the Free Software Foundation; either version 2 of the License, or
  4152. + * (at your option) any later version.
  4153. + *
  4154. + * This program is distributed in the hope that it will be useful,
  4155. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4156. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4157. + * GNU General Public License for more details.
  4158. + *
  4159. + * You should have received a copy of the GNU General Public License
  4160. + * along with this program; if not, write to the Free Software
  4161. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  4162. + */
  4163. +
  4164. +#ifndef __BCM2708_BCM2708_H
  4165. +#define __BCM2708_BCM2708_H
  4166. +
  4167. +#include <linux/amba/bus.h>
  4168. +
  4169. +extern void __init bcm2708_init(void);
  4170. +extern void __init bcm2708_init_irq(void);
  4171. +extern void __init bcm2708_map_io(void);
  4172. +extern struct sys_timer bcm2708_timer;
  4173. +extern unsigned int mmc_status(struct device *dev);
  4174. +
  4175. +#define AMBA_DEVICE(name, busid, base, plat) \
  4176. +static struct amba_device name##_device = { \
  4177. + .dev = { \
  4178. + .coherent_dma_mask = ~0, \
  4179. + .init_name = busid, \
  4180. + .platform_data = plat, \
  4181. + }, \
  4182. + .res = { \
  4183. + .start = base##_BASE, \
  4184. + .end = (base##_BASE) + SZ_4K - 1,\
  4185. + .flags = IORESOURCE_MEM, \
  4186. + }, \
  4187. + .irq = base##_IRQ, \
  4188. +}
  4189. +
  4190. +#endif
  4191. diff -Nur linux-3.12.26.orig/arch/arm/mach-bcm2708/clock.c linux-3.12.26/arch/arm/mach-bcm2708/clock.c
  4192. --- linux-3.12.26.orig/arch/arm/mach-bcm2708/clock.c 1970-01-01 01:00:00.000000000 +0100
  4193. +++ linux-3.12.26/arch/arm/mach-bcm2708/clock.c 2014-08-06 16:50:13.821957030 +0200
  4194. @@ -0,0 +1,61 @@
  4195. +/*
  4196. + * linux/arch/arm/mach-bcm2708/clock.c
  4197. + *
  4198. + * Copyright (C) 2010 Broadcom
  4199. + *
  4200. + * This program is free software; you can redistribute it and/or modify
  4201. + * it under the terms of the GNU General Public License as published by
  4202. + * the Free Software Foundation; either version 2 of the License, or
  4203. + * (at your option) any later version.
  4204. + *
  4205. + * This program is distributed in the hope that it will be useful,
  4206. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4207. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4208. + * GNU General Public License for more details.
  4209. + *
  4210. + * You should have received a copy of the GNU General Public License
  4211. + * along with this program; if not, write to the Free Software
  4212. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  4213. + */
  4214. +#include <linux/module.h>
  4215. +#include <linux/kernel.h>
  4216. +#include <linux/device.h>
  4217. +#include <linux/list.h>
  4218. +#include <linux/errno.h>
  4219. +#include <linux/err.h>
  4220. +#include <linux/string.h>
  4221. +#include <linux/clk.h>
  4222. +#include <linux/mutex.h>
  4223. +
  4224. +#include <asm/clkdev.h>
  4225. +
  4226. +#include "clock.h"
  4227. +
  4228. +int clk_enable(struct clk *clk)
  4229. +{
  4230. + return 0;
  4231. +}
  4232. +EXPORT_SYMBOL(clk_enable);
  4233. +
  4234. +void clk_disable(struct clk *clk)
  4235. +{
  4236. +}
  4237. +EXPORT_SYMBOL(clk_disable);
  4238. +
  4239. +unsigned long clk_get_rate(struct clk *clk)
  4240. +{
  4241. + return clk->rate;
  4242. +}
  4243. +EXPORT_SYMBOL(clk_get_rate);
  4244. +
  4245. +long clk_round_rate(struct clk *clk, unsigned long rate)
  4246. +{
  4247. + return clk->rate;
  4248. +}
  4249. +EXPORT_SYMBOL(clk_round_rate);
  4250. +
  4251. +int clk_set_rate(struct clk *clk, unsigned long rate)
  4252. +{
  4253. + return -EIO;
  4254. +}
  4255. +EXPORT_SYMBOL(clk_set_rate);
  4256. diff -Nur linux-3.12.26.orig/arch/arm/mach-bcm2708/clock.h linux-3.12.26/arch/arm/mach-bcm2708/clock.h
  4257. --- linux-3.12.26.orig/arch/arm/mach-bcm2708/clock.h 1970-01-01 01:00:00.000000000 +0100
  4258. +++ linux-3.12.26/arch/arm/mach-bcm2708/clock.h 2014-08-06 16:50:13.821957030 +0200
  4259. @@ -0,0 +1,24 @@
  4260. +/*
  4261. + * linux/arch/arm/mach-bcm2708/clock.h
  4262. + *
  4263. + * Copyright (C) 2010 Broadcom
  4264. + *
  4265. + * This program is free software; you can redistribute it and/or modify
  4266. + * it under the terms of the GNU General Public License as published by
  4267. + * the Free Software Foundation; either version 2 of the License, or
  4268. + * (at your option) any later version.
  4269. + *
  4270. + * This program is distributed in the hope that it will be useful,
  4271. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4272. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4273. + * GNU General Public License for more details.
  4274. + *
  4275. + * You should have received a copy of the GNU General Public License
  4276. + * along with this program; if not, write to the Free Software
  4277. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  4278. + */
  4279. +struct module;
  4280. +
  4281. +struct clk {
  4282. + unsigned long rate;
  4283. +};
  4284. diff -Nur linux-3.12.26.orig/arch/arm/mach-bcm2708/dma.c linux-3.12.26/arch/arm/mach-bcm2708/dma.c
  4285. --- linux-3.12.26.orig/arch/arm/mach-bcm2708/dma.c 1970-01-01 01:00:00.000000000 +0100
  4286. +++ linux-3.12.26/arch/arm/mach-bcm2708/dma.c 2014-08-06 16:50:13.821957030 +0200
  4287. @@ -0,0 +1,407 @@
  4288. +/*
  4289. + * linux/arch/arm/mach-bcm2708/dma.c
  4290. + *
  4291. + * Copyright (C) 2010 Broadcom
  4292. + *
  4293. + * This program is free software; you can redistribute it and/or modify
  4294. + * it under the terms of the GNU General Public License version 2 as
  4295. + * published by the Free Software Foundation.
  4296. + */
  4297. +
  4298. +#include <linux/slab.h>
  4299. +#include <linux/device.h>
  4300. +#include <linux/platform_device.h>
  4301. +#include <linux/module.h>
  4302. +#include <linux/scatterlist.h>
  4303. +
  4304. +#include <mach/dma.h>
  4305. +#include <mach/irqs.h>
  4306. +
  4307. +/*****************************************************************************\
  4308. + * *
  4309. + * Configuration *
  4310. + * *
  4311. +\*****************************************************************************/
  4312. +
  4313. +#define CACHE_LINE_MASK 31
  4314. +#define DRIVER_NAME BCM_DMAMAN_DRIVER_NAME
  4315. +#define DEFAULT_DMACHAN_BITMAP 0x10 /* channel 4 only */
  4316. +
  4317. +/* valid only for channels 0 - 14, 15 has its own base address */
  4318. +#define BCM2708_DMA_CHAN(n) ((n)<<8) /* base address */
  4319. +#define BCM2708_DMA_CHANIO(dma_base, n) \
  4320. + ((void __iomem *)((char *)(dma_base)+BCM2708_DMA_CHAN(n)))
  4321. +
  4322. +
  4323. +/*****************************************************************************\
  4324. + * *
  4325. + * DMA Auxilliary Functions *
  4326. + * *
  4327. +\*****************************************************************************/
  4328. +
  4329. +/* A DMA buffer on an arbitrary boundary may separate a cache line into a
  4330. + section inside the DMA buffer and another section outside it.
  4331. + Even if we flush DMA buffers from the cache there is always the chance that
  4332. + during a DMA someone will access the part of a cache line that is outside
  4333. + the DMA buffer - which will then bring in unwelcome data.
  4334. + Without being able to dictate our own buffer pools we must insist that
  4335. + DMA buffers consist of a whole number of cache lines.
  4336. +*/
  4337. +
  4338. +extern int
  4339. +bcm_sg_suitable_for_dma(struct scatterlist *sg_ptr, int sg_len)
  4340. +{
  4341. + int i;
  4342. +
  4343. + for (i = 0; i < sg_len; i++) {
  4344. + if (sg_ptr[i].offset & CACHE_LINE_MASK ||
  4345. + sg_ptr[i].length & CACHE_LINE_MASK)
  4346. + return 0;
  4347. + }
  4348. +
  4349. + return 1;
  4350. +}
  4351. +EXPORT_SYMBOL_GPL(bcm_sg_suitable_for_dma);
  4352. +
  4353. +extern void
  4354. +bcm_dma_start(void __iomem *dma_chan_base, dma_addr_t control_block)
  4355. +{
  4356. + dsb(); /* ARM data synchronization (push) operation */
  4357. +
  4358. + writel(control_block, dma_chan_base + BCM2708_DMA_ADDR);
  4359. + writel(BCM2708_DMA_ACTIVE, dma_chan_base + BCM2708_DMA_CS);
  4360. +}
  4361. +
  4362. +extern void bcm_dma_wait_idle(void __iomem *dma_chan_base)
  4363. +{
  4364. + dsb();
  4365. +
  4366. + /* ugly busy wait only option for now */
  4367. + while (readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_ACTIVE)
  4368. + cpu_relax();
  4369. +}
  4370. +
  4371. +EXPORT_SYMBOL_GPL(bcm_dma_start);
  4372. +
  4373. +extern bool bcm_dma_is_busy(void __iomem *dma_chan_base)
  4374. +{
  4375. + dsb();
  4376. +
  4377. + return readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_ACTIVE;
  4378. +}
  4379. +EXPORT_SYMBOL_GPL(bcm_dma_is_busy);
  4380. +
  4381. +/* Complete an ongoing DMA (assuming its results are to be ignored)
  4382. + Does nothing if there is no DMA in progress.
  4383. + This routine waits for the current AXI transfer to complete before
  4384. + terminating the current DMA. If the current transfer is hung on a DREQ used
  4385. + by an uncooperative peripheral the AXI transfer may never complete. In this
  4386. + case the routine times out and return a non-zero error code.
  4387. + Use of this routine doesn't guarantee that the ongoing or aborted DMA
  4388. + does not produce an interrupt.
  4389. +*/
  4390. +extern int
  4391. +bcm_dma_abort(void __iomem *dma_chan_base)
  4392. +{
  4393. + unsigned long int cs;
  4394. + int rc = 0;
  4395. +
  4396. + cs = readl(dma_chan_base + BCM2708_DMA_CS);
  4397. +
  4398. + if (BCM2708_DMA_ACTIVE & cs) {
  4399. + long int timeout = 10000;
  4400. +
  4401. + /* write 0 to the active bit - pause the DMA */
  4402. + writel(0, dma_chan_base + BCM2708_DMA_CS);
  4403. +
  4404. + /* wait for any current AXI transfer to complete */
  4405. + while (0 != (cs & BCM2708_DMA_ISPAUSED) && --timeout >= 0)
  4406. + cs = readl(dma_chan_base + BCM2708_DMA_CS);
  4407. +
  4408. + if (0 != (cs & BCM2708_DMA_ISPAUSED)) {
  4409. + /* we'll un-pause when we set of our next DMA */
  4410. + rc = -ETIMEDOUT;
  4411. +
  4412. + } else if (BCM2708_DMA_ACTIVE & cs) {
  4413. + /* terminate the control block chain */
  4414. + writel(0, dma_chan_base + BCM2708_DMA_NEXTCB);
  4415. +
  4416. + /* abort the whole DMA */
  4417. + writel(BCM2708_DMA_ABORT | BCM2708_DMA_ACTIVE,
  4418. + dma_chan_base + BCM2708_DMA_CS);
  4419. + }
  4420. + }
  4421. +
  4422. + return rc;
  4423. +}
  4424. +EXPORT_SYMBOL_GPL(bcm_dma_abort);
  4425. +
  4426. +
  4427. +/***************************************************************************** \
  4428. + * *
  4429. + * DMA Manager Device Methods *
  4430. + * *
  4431. +\*****************************************************************************/
  4432. +
  4433. +struct vc_dmaman {
  4434. + void __iomem *dma_base;
  4435. + u32 chan_available; /* bitmap of available channels */
  4436. + u32 has_feature[BCM_DMA_FEATURE_COUNT]; /* bitmap of feature presence */
  4437. +};
  4438. +
  4439. +static void vc_dmaman_init(struct vc_dmaman *dmaman, void __iomem *dma_base,
  4440. + u32 chans_available)
  4441. +{
  4442. + dmaman->dma_base = dma_base;
  4443. + dmaman->chan_available = chans_available;
  4444. + dmaman->has_feature[BCM_DMA_FEATURE_FAST_ORD] = 0x0c; /* chans 2 & 3 */
  4445. + dmaman->has_feature[BCM_DMA_FEATURE_BULK_ORD] = 0x01; /* chan 0 */
  4446. +}
  4447. +
  4448. +static int vc_dmaman_chan_alloc(struct vc_dmaman *dmaman,
  4449. + unsigned preferred_feature_set)
  4450. +{
  4451. + u32 chans;
  4452. + int feature;
  4453. +
  4454. + chans = dmaman->chan_available;
  4455. + for (feature = 0; feature < BCM_DMA_FEATURE_COUNT; feature++)
  4456. + /* select the subset of available channels with the desired
  4457. + feature so long as some of the candidate channels have that
  4458. + feature */
  4459. + if ((preferred_feature_set & (1 << feature)) &&
  4460. + (chans & dmaman->has_feature[feature]))
  4461. + chans &= dmaman->has_feature[feature];
  4462. +
  4463. + if (chans) {
  4464. + int chan = 0;
  4465. + /* return the ordinal of the first channel in the bitmap */
  4466. + while (chans != 0 && (chans & 1) == 0) {
  4467. + chans >>= 1;
  4468. + chan++;
  4469. + }
  4470. + /* claim the channel */
  4471. + dmaman->chan_available &= ~(1 << chan);
  4472. + return chan;
  4473. + } else
  4474. + return -ENOMEM;
  4475. +}
  4476. +
  4477. +static int vc_dmaman_chan_free(struct vc_dmaman *dmaman, int chan)
  4478. +{
  4479. + if (chan < 0)
  4480. + return -EINVAL;
  4481. + else if ((1 << chan) & dmaman->chan_available)
  4482. + return -EIDRM;
  4483. + else {
  4484. + dmaman->chan_available |= (1 << chan);
  4485. + return 0;
  4486. + }
  4487. +}
  4488. +
  4489. +/*****************************************************************************\
  4490. + * *
  4491. + * DMA IRQs *
  4492. + * *
  4493. +\*****************************************************************************/
  4494. +
  4495. +static unsigned char bcm_dma_irqs[] = {
  4496. + IRQ_DMA0,
  4497. + IRQ_DMA1,
  4498. + IRQ_DMA2,
  4499. + IRQ_DMA3,
  4500. + IRQ_DMA4,
  4501. + IRQ_DMA5,
  4502. + IRQ_DMA6,
  4503. + IRQ_DMA7,
  4504. + IRQ_DMA8,
  4505. + IRQ_DMA9,
  4506. + IRQ_DMA10,
  4507. + IRQ_DMA11,
  4508. + IRQ_DMA12
  4509. +};
  4510. +
  4511. +
  4512. +/***************************************************************************** \
  4513. + * *
  4514. + * DMA Manager Monitor *
  4515. + * *
  4516. +\*****************************************************************************/
  4517. +
  4518. +static struct device *dmaman_dev; /* we assume there's only one! */
  4519. +
  4520. +extern int bcm_dma_chan_alloc(unsigned preferred_feature_set,
  4521. + void __iomem **out_dma_base, int *out_dma_irq)
  4522. +{
  4523. + if (!dmaman_dev)
  4524. + return -ENODEV;
  4525. + else {
  4526. + struct vc_dmaman *dmaman = dev_get_drvdata(dmaman_dev);
  4527. + int rc;
  4528. +
  4529. + device_lock(dmaman_dev);
  4530. + rc = vc_dmaman_chan_alloc(dmaman, preferred_feature_set);
  4531. + if (rc >= 0) {
  4532. + *out_dma_base = BCM2708_DMA_CHANIO(dmaman->dma_base,
  4533. + rc);
  4534. + *out_dma_irq = bcm_dma_irqs[rc];
  4535. + }
  4536. + device_unlock(dmaman_dev);
  4537. +
  4538. + return rc;
  4539. + }
  4540. +}
  4541. +EXPORT_SYMBOL_GPL(bcm_dma_chan_alloc);
  4542. +
  4543. +extern int bcm_dma_chan_free(int channel)
  4544. +{
  4545. + if (dmaman_dev) {
  4546. + struct vc_dmaman *dmaman = dev_get_drvdata(dmaman_dev);
  4547. + int rc;
  4548. +
  4549. + device_lock(dmaman_dev);
  4550. + rc = vc_dmaman_chan_free(dmaman, channel);
  4551. + device_unlock(dmaman_dev);
  4552. +
  4553. + return rc;
  4554. + } else
  4555. + return -ENODEV;
  4556. +}
  4557. +EXPORT_SYMBOL_GPL(bcm_dma_chan_free);
  4558. +
  4559. +static int dev_dmaman_register(const char *dev_name, struct device *dev)
  4560. +{
  4561. + int rc = dmaman_dev ? -EINVAL : 0;
  4562. + dmaman_dev = dev;
  4563. + return rc;
  4564. +}
  4565. +
  4566. +static void dev_dmaman_deregister(const char *dev_name, struct device *dev)
  4567. +{
  4568. + dmaman_dev = NULL;
  4569. +}
  4570. +
  4571. +/*****************************************************************************\
  4572. + * *
  4573. + * DMA Device *
  4574. + * *
  4575. +\*****************************************************************************/
  4576. +
  4577. +static int dmachans = -1; /* module parameter */
  4578. +
  4579. +static int bcm_dmaman_probe(struct platform_device *pdev)
  4580. +{
  4581. + int ret = 0;
  4582. + struct vc_dmaman *dmaman;
  4583. + struct resource *dma_res = NULL;
  4584. + void __iomem *dma_base = NULL;
  4585. + int have_dma_region = 0;
  4586. +
  4587. + dmaman = kzalloc(sizeof(*dmaman), GFP_KERNEL);
  4588. + if (NULL == dmaman) {
  4589. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  4590. + "DMA management memory\n");
  4591. + ret = -ENOMEM;
  4592. + } else {
  4593. +
  4594. + dma_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  4595. + if (dma_res == NULL) {
  4596. + printk(KERN_ERR DRIVER_NAME ": failed to obtain memory "
  4597. + "resource\n");
  4598. + ret = -ENODEV;
  4599. + } else if (!request_mem_region(dma_res->start,
  4600. + resource_size(dma_res),
  4601. + DRIVER_NAME)) {
  4602. + dev_err(&pdev->dev, "cannot obtain DMA region\n");
  4603. + ret = -EBUSY;
  4604. + } else {
  4605. + have_dma_region = 1;
  4606. + dma_base = ioremap(dma_res->start,
  4607. + resource_size(dma_res));
  4608. + if (!dma_base) {
  4609. + dev_err(&pdev->dev, "cannot map DMA region\n");
  4610. + ret = -ENOMEM;
  4611. + } else {
  4612. + /* use module parameter if one was provided */
  4613. + if (dmachans > 0)
  4614. + vc_dmaman_init(dmaman, dma_base,
  4615. + dmachans);
  4616. + else
  4617. + vc_dmaman_init(dmaman, dma_base,
  4618. + DEFAULT_DMACHAN_BITMAP);
  4619. +
  4620. + platform_set_drvdata(pdev, dmaman);
  4621. + dev_dmaman_register(DRIVER_NAME, &pdev->dev);
  4622. +
  4623. + printk(KERN_INFO DRIVER_NAME ": DMA manager "
  4624. + "at %p\n", dma_base);
  4625. + }
  4626. + }
  4627. + }
  4628. + if (ret != 0) {
  4629. + if (dma_base)
  4630. + iounmap(dma_base);
  4631. + if (dma_res && have_dma_region)
  4632. + release_mem_region(dma_res->start,
  4633. + resource_size(dma_res));
  4634. + if (dmaman)
  4635. + kfree(dmaman);
  4636. + }
  4637. + return ret;
  4638. +}
  4639. +
  4640. +static int bcm_dmaman_remove(struct platform_device *pdev)
  4641. +{
  4642. + struct vc_dmaman *dmaman = platform_get_drvdata(pdev);
  4643. +
  4644. + platform_set_drvdata(pdev, NULL);
  4645. + dev_dmaman_deregister(DRIVER_NAME, &pdev->dev);
  4646. + kfree(dmaman);
  4647. +
  4648. + return 0;
  4649. +}
  4650. +
  4651. +static struct platform_driver bcm_dmaman_driver = {
  4652. + .probe = bcm_dmaman_probe,
  4653. + .remove = bcm_dmaman_remove,
  4654. +
  4655. + .driver = {
  4656. + .name = DRIVER_NAME,
  4657. + .owner = THIS_MODULE,
  4658. + },
  4659. +};
  4660. +
  4661. +/*****************************************************************************\
  4662. + * *
  4663. + * Driver init/exit *
  4664. + * *
  4665. +\*****************************************************************************/
  4666. +
  4667. +static int __init bcm_dmaman_drv_init(void)
  4668. +{
  4669. + int ret;
  4670. +
  4671. + ret = platform_driver_register(&bcm_dmaman_driver);
  4672. + if (ret != 0) {
  4673. + printk(KERN_ERR DRIVER_NAME ": failed to register "
  4674. + "on platform\n");
  4675. + }
  4676. +
  4677. + return ret;
  4678. +}
  4679. +
  4680. +static void __exit bcm_dmaman_drv_exit(void)
  4681. +{
  4682. + platform_driver_unregister(&bcm_dmaman_driver);
  4683. +}
  4684. +
  4685. +module_init(bcm_dmaman_drv_init);
  4686. +module_exit(bcm_dmaman_drv_exit);
  4687. +
  4688. +module_param(dmachans, int, 0644);
  4689. +
  4690. +MODULE_AUTHOR("Gray Girling <grayg@broadcom.com>");
  4691. +MODULE_DESCRIPTION("DMA channel manager driver");
  4692. +MODULE_LICENSE("GPL");
  4693. +
  4694. +MODULE_PARM_DESC(dmachans, "Bitmap of DMA channels available to the ARM");
  4695. diff -Nur linux-3.12.26.orig/arch/arm/mach-bcm2708/include/mach/arm_control.h linux-3.12.26/arch/arm/mach-bcm2708/include/mach/arm_control.h
  4696. --- linux-3.12.26.orig/arch/arm/mach-bcm2708/include/mach/arm_control.h 1970-01-01 01:00:00.000000000 +0100
  4697. +++ linux-3.12.26/arch/arm/mach-bcm2708/include/mach/arm_control.h 2014-08-06 16:50:13.825957062 +0200
  4698. @@ -0,0 +1,419 @@
  4699. +/*
  4700. + * linux/arch/arm/mach-bcm2708/arm_control.h
  4701. + *
  4702. + * Copyright (C) 2010 Broadcom
  4703. + *
  4704. + * This program is free software; you can redistribute it and/or modify
  4705. + * it under the terms of the GNU General Public License as published by
  4706. + * the Free Software Foundation; either version 2 of the License, or
  4707. + * (at your option) any later version.
  4708. + *
  4709. + * This program is distributed in the hope that it will be useful,
  4710. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4711. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4712. + * GNU General Public License for more details.
  4713. + *
  4714. + * You should have received a copy of the GNU General Public License
  4715. + * along with this program; if not, write to the Free Software
  4716. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  4717. + */
  4718. +
  4719. +#ifndef __BCM2708_ARM_CONTROL_H
  4720. +#define __BCM2708_ARM_CONTROL_H
  4721. +
  4722. +/*
  4723. + * Definitions and addresses for the ARM CONTROL logic
  4724. + * This file is manually generated.
  4725. + */
  4726. +
  4727. +#define ARM_BASE 0x7E00B000
  4728. +
  4729. +/* Basic configuration */
  4730. +#define ARM_CONTROL0 HW_REGISTER_RW(ARM_BASE+0x000)
  4731. +#define ARM_C0_SIZ128M 0x00000000
  4732. +#define ARM_C0_SIZ256M 0x00000001
  4733. +#define ARM_C0_SIZ512M 0x00000002
  4734. +#define ARM_C0_SIZ1G 0x00000003
  4735. +#define ARM_C0_BRESP0 0x00000000
  4736. +#define ARM_C0_BRESP1 0x00000004
  4737. +#define ARM_C0_BRESP2 0x00000008
  4738. +#define ARM_C0_BOOTHI 0x00000010
  4739. +#define ARM_C0_UNUSED05 0x00000020 /* free */
  4740. +#define ARM_C0_FULLPERI 0x00000040
  4741. +#define ARM_C0_UNUSED78 0x00000180 /* free */
  4742. +#define ARM_C0_JTAGMASK 0x00000E00
  4743. +#define ARM_C0_JTAGOFF 0x00000000
  4744. +#define ARM_C0_JTAGBASH 0x00000800 /* Debug on GPIO off */
  4745. +#define ARM_C0_JTAGGPIO 0x00000C00 /* Debug on GPIO on */
  4746. +#define ARM_C0_APROTMSK 0x0000F000
  4747. +#define ARM_C0_DBG0SYNC 0x00010000 /* VPU0 halt sync */
  4748. +#define ARM_C0_DBG1SYNC 0x00020000 /* VPU1 halt sync */
  4749. +#define ARM_C0_SWDBGREQ 0x00040000 /* HW debug request */
  4750. +#define ARM_C0_PASSHALT 0x00080000 /* ARM halt passed to debugger */
  4751. +#define ARM_C0_PRIO_PER 0x00F00000 /* per priority mask */
  4752. +#define ARM_C0_PRIO_L2 0x0F000000
  4753. +#define ARM_C0_PRIO_UC 0xF0000000
  4754. +
  4755. +#define ARM_C0_APROTPASS 0x0000A000 /* Translate 1:1 */
  4756. +#define ARM_C0_APROTUSER 0x00000000 /* Only user mode */
  4757. +#define ARM_C0_APROTSYST 0x0000F000 /* Only system mode */
  4758. +
  4759. +
  4760. +#define ARM_CONTROL1 HW_REGISTER_RW(ARM_BASE+0x440)
  4761. +#define ARM_C1_TIMER 0x00000001 /* re-route timer IRQ to VC */
  4762. +#define ARM_C1_MAIL 0x00000002 /* re-route Mail IRQ to VC */
  4763. +#define ARM_C1_BELL0 0x00000004 /* re-route Doorbell 0 to VC */
  4764. +#define ARM_C1_BELL1 0x00000008 /* re-route Doorbell 1 to VC */
  4765. +#define ARM_C1_PERSON 0x00000100 /* peripherals on */
  4766. +#define ARM_C1_REQSTOP 0x00000200 /* ASYNC bridge request stop */
  4767. +
  4768. +#define ARM_STATUS HW_REGISTER_RW(ARM_BASE+0x444)
  4769. +#define ARM_S_ACKSTOP 0x80000000 /* Bridge stopped */
  4770. +#define ARM_S_READPEND 0x000003FF /* pending reads counter */
  4771. +#define ARM_S_WRITPEND 0x000FFC00 /* pending writes counter */
  4772. +
  4773. +#define ARM_ERRHALT HW_REGISTER_RW(ARM_BASE+0x448)
  4774. +#define ARM_EH_PERIBURST 0x00000001 /* Burst write seen on peri bus */
  4775. +#define ARM_EH_ILLADDRS1 0x00000002 /* Address bits 25-27 error */
  4776. +#define ARM_EH_ILLADDRS2 0x00000004 /* Address bits 31-28 error */
  4777. +#define ARM_EH_VPU0HALT 0x00000008 /* VPU0 halted & in debug mode */
  4778. +#define ARM_EH_VPU1HALT 0x00000010 /* VPU1 halted & in debug mode */
  4779. +#define ARM_EH_ARMHALT 0x00000020 /* ARM in halted debug mode */
  4780. +
  4781. +#define ARM_ID_SECURE HW_REGISTER_RW(ARM_BASE+0x00C)
  4782. +#define ARM_ID HW_REGISTER_RW(ARM_BASE+0x44C)
  4783. +#define ARM_IDVAL 0x364D5241
  4784. +
  4785. +/* Translation memory */
  4786. +#define ARM_TRANSLATE HW_REGISTER_RW(ARM_BASE+0x100)
  4787. +/* 32 locations: 0x100.. 0x17F */
  4788. +/* 32 spare means we CAN go to 64 pages.... */
  4789. +
  4790. +
  4791. +/* Interrupts */
  4792. +#define ARM_IRQ_PEND0 HW_REGISTER_RW(ARM_BASE+0x200) /* Top IRQ bits */
  4793. +#define ARM_I0_TIMER 0x00000001 /* timer IRQ */
  4794. +#define ARM_I0_MAIL 0x00000002 /* Mail IRQ */
  4795. +#define ARM_I0_BELL0 0x00000004 /* Doorbell 0 */
  4796. +#define ARM_I0_BELL1 0x00000008 /* Doorbell 1 */
  4797. +#define ARM_I0_BANK1 0x00000100 /* Bank1 IRQ */
  4798. +#define ARM_I0_BANK2 0x00000200 /* Bank2 IRQ */
  4799. +
  4800. +#define ARM_IRQ_PEND1 HW_REGISTER_RW(ARM_BASE+0x204) /* All bank1 IRQ bits */
  4801. +/* todo: all I1_interrupt sources */
  4802. +#define ARM_IRQ_PEND2 HW_REGISTER_RW(ARM_BASE+0x208) /* All bank2 IRQ bits */
  4803. +/* todo: all I2_interrupt sources */
  4804. +
  4805. +#define ARM_IRQ_FAST HW_REGISTER_RW(ARM_BASE+0x20C) /* FIQ control */
  4806. +#define ARM_IF_INDEX 0x0000007F /* FIQ select */
  4807. +#define ARM_IF_ENABLE 0x00000080 /* FIQ enable */
  4808. +#define ARM_IF_VCMASK 0x0000003F /* FIQ = (index from VC source) */
  4809. +#define ARM_IF_TIMER 0x00000040 /* FIQ = ARM timer */
  4810. +#define ARM_IF_MAIL 0x00000041 /* FIQ = ARM Mail */
  4811. +#define ARM_IF_BELL0 0x00000042 /* FIQ = ARM Doorbell 0 */
  4812. +#define ARM_IF_BELL1 0x00000043 /* FIQ = ARM Doorbell 1 */
  4813. +#define ARM_IF_VP0HALT 0x00000044 /* FIQ = VPU0 Halt seen */
  4814. +#define ARM_IF_VP1HALT 0x00000045 /* FIQ = VPU1 Halt seen */
  4815. +#define ARM_IF_ILLEGAL 0x00000046 /* FIQ = Illegal access seen */
  4816. +
  4817. +#define ARM_IRQ_ENBL1 HW_REGISTER_RW(ARM_BASE+0x210) /* Bank1 enable bits */
  4818. +#define ARM_IRQ_ENBL2 HW_REGISTER_RW(ARM_BASE+0x214) /* Bank2 enable bits */
  4819. +#define ARM_IRQ_ENBL3 HW_REGISTER_RW(ARM_BASE+0x218) /* ARM irqs enable bits */
  4820. +#define ARM_IRQ_DIBL1 HW_REGISTER_RW(ARM_BASE+0x21C) /* Bank1 disable bits */
  4821. +#define ARM_IRQ_DIBL2 HW_REGISTER_RW(ARM_BASE+0x220) /* Bank2 disable bits */
  4822. +#define ARM_IRQ_DIBL3 HW_REGISTER_RW(ARM_BASE+0x224) /* ARM irqs disable bits */
  4823. +#define ARM_IE_TIMER 0x00000001 /* Timer IRQ */
  4824. +#define ARM_IE_MAIL 0x00000002 /* Mail IRQ */
  4825. +#define ARM_IE_BELL0 0x00000004 /* Doorbell 0 */
  4826. +#define ARM_IE_BELL1 0x00000008 /* Doorbell 1 */
  4827. +#define ARM_IE_VP0HALT 0x00000010 /* VPU0 Halt */
  4828. +#define ARM_IE_VP1HALT 0x00000020 /* VPU1 Halt */
  4829. +#define ARM_IE_ILLEGAL 0x00000040 /* Illegal access seen */
  4830. +
  4831. +/* Timer */
  4832. +/* For reg. fields see sp804 spec. */
  4833. +#define ARM_T_LOAD HW_REGISTER_RW(ARM_BASE+0x400)
  4834. +#define ARM_T_VALUE HW_REGISTER_RW(ARM_BASE+0x404)
  4835. +#define ARM_T_CONTROL HW_REGISTER_RW(ARM_BASE+0x408)
  4836. +#define ARM_T_IRQCNTL HW_REGISTER_RW(ARM_BASE+0x40C)
  4837. +#define ARM_T_RAWIRQ HW_REGISTER_RW(ARM_BASE+0x410)
  4838. +#define ARM_T_MSKIRQ HW_REGISTER_RW(ARM_BASE+0x414)
  4839. +#define ARM_T_RELOAD HW_REGISTER_RW(ARM_BASE+0x418)
  4840. +#define ARM_T_PREDIV HW_REGISTER_RW(ARM_BASE+0x41c)
  4841. +#define ARM_T_FREECNT HW_REGISTER_RW(ARM_BASE+0x420)
  4842. +
  4843. +#define TIMER_CTRL_ONESHOT (1 << 0)
  4844. +#define TIMER_CTRL_32BIT (1 << 1)
  4845. +#define TIMER_CTRL_DIV1 (0 << 2)
  4846. +#define TIMER_CTRL_DIV16 (1 << 2)
  4847. +#define TIMER_CTRL_DIV256 (2 << 2)
  4848. +#define TIMER_CTRL_IE (1 << 5)
  4849. +#define TIMER_CTRL_PERIODIC (1 << 6)
  4850. +#define TIMER_CTRL_ENABLE (1 << 7)
  4851. +#define TIMER_CTRL_DBGHALT (1 << 8)
  4852. +#define TIMER_CTRL_ENAFREE (1 << 9)
  4853. +#define TIMER_CTRL_FREEDIV_SHIFT 16)
  4854. +#define TIMER_CTRL_FREEDIV_MASK 0xff
  4855. +
  4856. +/* Semaphores, Doorbells, Mailboxes */
  4857. +#define ARM_SBM_OWN0 (ARM_BASE+0x800)
  4858. +#define ARM_SBM_OWN1 (ARM_BASE+0x900)
  4859. +#define ARM_SBM_OWN2 (ARM_BASE+0xA00)
  4860. +#define ARM_SBM_OWN3 (ARM_BASE+0xB00)
  4861. +
  4862. +/* MAILBOXES
  4863. + * Register flags are common across all
  4864. + * owner registers. See end of this section
  4865. + *
  4866. + * Semaphores, Doorbells, Mailboxes Owner 0
  4867. + *
  4868. + */
  4869. +
  4870. +#define ARM_0_SEMS HW_REGISTER_RW(ARM_SBM_OWN0+0x00)
  4871. +#define ARM_0_SEM0 HW_REGISTER_RW(ARM_SBM_OWN0+0x00)
  4872. +#define ARM_0_SEM1 HW_REGISTER_RW(ARM_SBM_OWN0+0x04)
  4873. +#define ARM_0_SEM2 HW_REGISTER_RW(ARM_SBM_OWN0+0x08)
  4874. +#define ARM_0_SEM3 HW_REGISTER_RW(ARM_SBM_OWN0+0x0C)
  4875. +#define ARM_0_SEM4 HW_REGISTER_RW(ARM_SBM_OWN0+0x10)
  4876. +#define ARM_0_SEM5 HW_REGISTER_RW(ARM_SBM_OWN0+0x14)
  4877. +#define ARM_0_SEM6 HW_REGISTER_RW(ARM_SBM_OWN0+0x18)
  4878. +#define ARM_0_SEM7 HW_REGISTER_RW(ARM_SBM_OWN0+0x1C)
  4879. +#define ARM_0_BELL0 HW_REGISTER_RW(ARM_SBM_OWN0+0x40)
  4880. +#define ARM_0_BELL1 HW_REGISTER_RW(ARM_SBM_OWN0+0x44)
  4881. +#define ARM_0_BELL2 HW_REGISTER_RW(ARM_SBM_OWN0+0x48)
  4882. +#define ARM_0_BELL3 HW_REGISTER_RW(ARM_SBM_OWN0+0x4C)
  4883. +/* MAILBOX 0 access in Owner 0 area */
  4884. +/* Some addresses should ONLY be used by owner 0 */
  4885. +#define ARM_0_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN0+0x80) /* .. 0x8C (4 locations) */
  4886. +#define ARM_0_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN0+0x80) /* .. 0x8C (4 locations) Normal read */
  4887. +#define ARM_0_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN0+0x90) /* none-pop read */
  4888. +#define ARM_0_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN0+0x94) /* Sender read (only LS 2 bits) */
  4889. +#define ARM_0_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN0+0x98) /* Status read */
  4890. +#define ARM_0_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN0+0x9C) /* Config read/write */
  4891. +/* MAILBOX 1 access in Owner 0 area */
  4892. +/* Owner 0 should only WRITE to this mailbox */
  4893. +#define ARM_0_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN0+0xA0) /* .. 0xAC (4 locations) */
  4894. +/*#define ARM_0_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN0+0xA0) */ /* DO NOT USE THIS !!!!! */
  4895. +/*#define ARM_0_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN0+0xB0) */ /* DO NOT USE THIS !!!!! */
  4896. +/*#define ARM_0_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN0+0xB4) */ /* DO NOT USE THIS !!!!! */
  4897. +#define ARM_0_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN0+0xB8) /* Status read */
  4898. +/*#define ARM_0_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN0+0xBC) */ /* DO NOT USE THIS !!!!! */
  4899. +/* General SEM, BELL, MAIL config/status */
  4900. +#define ARM_0_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN0+0xE0) /* semaphore clear/debug register */
  4901. +#define ARM_0_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN0+0xE4) /* Doorbells clear/debug register */
  4902. +#define ARM_0_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN0+0xF8) /* ALL interrupts */
  4903. +#define ARM_0_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN0+0xFC) /* IRQS pending for owner 0 */
  4904. +
  4905. +/* Semaphores, Doorbells, Mailboxes Owner 1 */
  4906. +#define ARM_1_SEMS HW_REGISTER_RW(ARM_SBM_OWN1+0x00)
  4907. +#define ARM_1_SEM0 HW_REGISTER_RW(ARM_SBM_OWN1+0x00)
  4908. +#define ARM_1_SEM1 HW_REGISTER_RW(ARM_SBM_OWN1+0x04)
  4909. +#define ARM_1_SEM2 HW_REGISTER_RW(ARM_SBM_OWN1+0x08)
  4910. +#define ARM_1_SEM3 HW_REGISTER_RW(ARM_SBM_OWN1+0x0C)
  4911. +#define ARM_1_SEM4 HW_REGISTER_RW(ARM_SBM_OWN1+0x10)
  4912. +#define ARM_1_SEM5 HW_REGISTER_RW(ARM_SBM_OWN1+0x14)
  4913. +#define ARM_1_SEM6 HW_REGISTER_RW(ARM_SBM_OWN1+0x18)
  4914. +#define ARM_1_SEM7 HW_REGISTER_RW(ARM_SBM_OWN1+0x1C)
  4915. +#define ARM_1_BELL0 HW_REGISTER_RW(ARM_SBM_OWN1+0x40)
  4916. +#define ARM_1_BELL1 HW_REGISTER_RW(ARM_SBM_OWN1+0x44)
  4917. +#define ARM_1_BELL2 HW_REGISTER_RW(ARM_SBM_OWN1+0x48)
  4918. +#define ARM_1_BELL3 HW_REGISTER_RW(ARM_SBM_OWN1+0x4C)
  4919. +/* MAILBOX 0 access in Owner 0 area */
  4920. +/* Owner 1 should only WRITE to this mailbox */
  4921. +#define ARM_1_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN1+0x80) /* .. 0x8C (4 locations) */
  4922. +/*#define ARM_1_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN1+0x80) */ /* DO NOT USE THIS !!!!! */
  4923. +/*#define ARM_1_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN1+0x90) */ /* DO NOT USE THIS !!!!! */
  4924. +/*#define ARM_1_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN1+0x94) */ /* DO NOT USE THIS !!!!! */
  4925. +#define ARM_1_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN1+0x98) /* Status read */
  4926. +/*#define ARM_1_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN1+0x9C) */ /* DO NOT USE THIS !!!!! */
  4927. +/* MAILBOX 1 access in Owner 0 area */
  4928. +#define ARM_1_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN1+0xA0) /* .. 0xAC (4 locations) */
  4929. +#define ARM_1_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN1+0xA0) /* .. 0xAC (4 locations) Normal read */
  4930. +#define ARM_1_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN1+0xB0) /* none-pop read */
  4931. +#define ARM_1_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN1+0xB4) /* Sender read (only LS 2 bits) */
  4932. +#define ARM_1_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN1+0xB8) /* Status read */
  4933. +#define ARM_1_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN1+0xBC)
  4934. +/* General SEM, BELL, MAIL config/status */
  4935. +#define ARM_1_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN1+0xE0) /* semaphore clear/debug register */
  4936. +#define ARM_1_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN1+0xE4) /* Doorbells clear/debug register */
  4937. +#define ARM_1_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN1+0xFC) /* IRQS pending for owner 1 */
  4938. +#define ARM_1_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN1+0xF8) /* ALL interrupts */
  4939. +
  4940. +/* Semaphores, Doorbells, Mailboxes Owner 2 */
  4941. +#define ARM_2_SEMS HW_REGISTER_RW(ARM_SBM_OWN2+0x00)
  4942. +#define ARM_2_SEM0 HW_REGISTER_RW(ARM_SBM_OWN2+0x00)
  4943. +#define ARM_2_SEM1 HW_REGISTER_RW(ARM_SBM_OWN2+0x04)
  4944. +#define ARM_2_SEM2 HW_REGISTER_RW(ARM_SBM_OWN2+0x08)
  4945. +#define ARM_2_SEM3 HW_REGISTER_RW(ARM_SBM_OWN2+0x0C)
  4946. +#define ARM_2_SEM4 HW_REGISTER_RW(ARM_SBM_OWN2+0x10)
  4947. +#define ARM_2_SEM5 HW_REGISTER_RW(ARM_SBM_OWN2+0x14)
  4948. +#define ARM_2_SEM6 HW_REGISTER_RW(ARM_SBM_OWN2+0x18)
  4949. +#define ARM_2_SEM7 HW_REGISTER_RW(ARM_SBM_OWN2+0x1C)
  4950. +#define ARM_2_BELL0 HW_REGISTER_RW(ARM_SBM_OWN2+0x40)
  4951. +#define ARM_2_BELL1 HW_REGISTER_RW(ARM_SBM_OWN2+0x44)
  4952. +#define ARM_2_BELL2 HW_REGISTER_RW(ARM_SBM_OWN2+0x48)
  4953. +#define ARM_2_BELL3 HW_REGISTER_RW(ARM_SBM_OWN2+0x4C)
  4954. +/* MAILBOX 0 access in Owner 2 area */
  4955. +/* Owner 2 should only WRITE to this mailbox */
  4956. +#define ARM_2_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN2+0x80) /* .. 0x8C (4 locations) */
  4957. +/*#define ARM_2_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN2+0x80) */ /* DO NOT USE THIS !!!!! */
  4958. +/*#define ARM_2_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN2+0x90) */ /* DO NOT USE THIS !!!!! */
  4959. +/*#define ARM_2_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN2+0x94) */ /* DO NOT USE THIS !!!!! */
  4960. +#define ARM_2_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN2+0x98) /* Status read */
  4961. +/*#define ARM_2_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN2+0x9C) */ /* DO NOT USE THIS !!!!! */
  4962. +/* MAILBOX 1 access in Owner 2 area */
  4963. +/* Owner 2 should only WRITE to this mailbox */
  4964. +#define ARM_2_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN2+0xA0) /* .. 0xAC (4 locations) */
  4965. +/*#define ARM_2_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN2+0xA0) */ /* DO NOT USE THIS !!!!! */
  4966. +/*#define ARM_2_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN2+0xB0) */ /* DO NOT USE THIS !!!!! */
  4967. +/*#define ARM_2_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN2+0xB4) */ /* DO NOT USE THIS !!!!! */
  4968. +#define ARM_2_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN2+0xB8) /* Status read */
  4969. +/*#define ARM_2_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN2+0xBC) */ /* DO NOT USE THIS !!!!! */
  4970. +/* General SEM, BELL, MAIL config/status */
  4971. +#define ARM_2_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN2+0xE0) /* semaphore clear/debug register */
  4972. +#define ARM_2_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN2+0xE4) /* Doorbells clear/debug register */
  4973. +#define ARM_2_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN2+0xFC) /* IRQS pending for owner 2 */
  4974. +#define ARM_2_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN2+0xF8) /* ALL interrupts */
  4975. +
  4976. +/* Semaphores, Doorbells, Mailboxes Owner 3 */
  4977. +#define ARM_3_SEMS HW_REGISTER_RW(ARM_SBM_OWN3+0x00)
  4978. +#define ARM_3_SEM0 HW_REGISTER_RW(ARM_SBM_OWN3+0x00)
  4979. +#define ARM_3_SEM1 HW_REGISTER_RW(ARM_SBM_OWN3+0x04)
  4980. +#define ARM_3_SEM2 HW_REGISTER_RW(ARM_SBM_OWN3+0x08)
  4981. +#define ARM_3_SEM3 HW_REGISTER_RW(ARM_SBM_OWN3+0x0C)
  4982. +#define ARM_3_SEM4 HW_REGISTER_RW(ARM_SBM_OWN3+0x10)
  4983. +#define ARM_3_SEM5 HW_REGISTER_RW(ARM_SBM_OWN3+0x14)
  4984. +#define ARM_3_SEM6 HW_REGISTER_RW(ARM_SBM_OWN3+0x18)
  4985. +#define ARM_3_SEM7 HW_REGISTER_RW(ARM_SBM_OWN3+0x1C)
  4986. +#define ARM_3_BELL0 HW_REGISTER_RW(ARM_SBM_OWN3+0x40)
  4987. +#define ARM_3_BELL1 HW_REGISTER_RW(ARM_SBM_OWN3+0x44)
  4988. +#define ARM_3_BELL2 HW_REGISTER_RW(ARM_SBM_OWN3+0x48)
  4989. +#define ARM_3_BELL3 HW_REGISTER_RW(ARM_SBM_OWN3+0x4C)
  4990. +/* MAILBOX 0 access in Owner 3 area */
  4991. +/* Owner 3 should only WRITE to this mailbox */
  4992. +#define ARM_3_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN3+0x80) /* .. 0x8C (4 locations) */
  4993. +/*#define ARM_3_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN3+0x80) */ /* DO NOT USE THIS !!!!! */
  4994. +/*#define ARM_3_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN3+0x90) */ /* DO NOT USE THIS !!!!! */
  4995. +/*#define ARM_3_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN3+0x94) */ /* DO NOT USE THIS !!!!! */
  4996. +#define ARM_3_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN3+0x98) /* Status read */
  4997. +/*#define ARM_3_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN3+0x9C) */ /* DO NOT USE THIS !!!!! */
  4998. +/* MAILBOX 1 access in Owner 3 area */
  4999. +/* Owner 3 should only WRITE to this mailbox */
  5000. +#define ARM_3_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN3+0xA0) /* .. 0xAC (4 locations) */
  5001. +/*#define ARM_3_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN3+0xA0) */ /* DO NOT USE THIS !!!!! */
  5002. +/*#define ARM_3_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN3+0xB0) */ /* DO NOT USE THIS !!!!! */
  5003. +/*#define ARM_3_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN3+0xB4) */ /* DO NOT USE THIS !!!!! */
  5004. +#define ARM_3_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN3+0xB8) /* Status read */
  5005. +/*#define ARM_3_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN3+0xBC) */ /* DO NOT USE THIS !!!!! */
  5006. +/* General SEM, BELL, MAIL config/status */
  5007. +#define ARM_3_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN3+0xE0) /* semaphore clear/debug register */
  5008. +#define ARM_3_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN3+0xE4) /* Doorbells clear/debug register */
  5009. +#define ARM_3_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN3+0xFC) /* IRQS pending for owner 3 */
  5010. +#define ARM_3_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN3+0xF8) /* ALL interrupts */
  5011. +
  5012. +
  5013. +
  5014. +/* Mailbox flags. Valid for all owners */
  5015. +
  5016. +/* Mailbox status register (...0x98) */
  5017. +#define ARM_MS_FULL 0x80000000
  5018. +#define ARM_MS_EMPTY 0x40000000
  5019. +#define ARM_MS_LEVEL 0x400000FF /* Max. value depdnds on mailbox depth parameter */
  5020. +
  5021. +/* MAILBOX config/status register (...0x9C) */
  5022. +/* ANY write to this register clears the error bits! */
  5023. +#define ARM_MC_IHAVEDATAIRQEN 0x00000001 /* mailbox irq enable: has data */
  5024. +#define ARM_MC_IHAVESPACEIRQEN 0x00000002 /* mailbox irq enable: has space */
  5025. +#define ARM_MC_OPPISEMPTYIRQEN 0x00000004 /* mailbox irq enable: Opp. is empty */
  5026. +#define ARM_MC_MAIL_CLEAR 0x00000008 /* mailbox clear write 1, then 0 */
  5027. +#define ARM_MC_IHAVEDATAIRQPEND 0x00000010 /* mailbox irq pending: has space */
  5028. +#define ARM_MC_IHAVESPACEIRQPEND 0x00000020 /* mailbox irq pending: Opp. is empty */
  5029. +#define ARM_MC_OPPISEMPTYIRQPEND 0x00000040 /* mailbox irq pending */
  5030. +/* Bit 7 is unused */
  5031. +#define ARM_MC_ERRNOOWN 0x00000100 /* error : none owner read from mailbox */
  5032. +#define ARM_MC_ERROVERFLW 0x00000200 /* error : write to fill mailbox */
  5033. +#define ARM_MC_ERRUNDRFLW 0x00000400 /* error : read from empty mailbox */
  5034. +
  5035. +/* Semaphore clear/debug register (...0xE0) */
  5036. +#define ARM_SD_OWN0 0x00000003 /* Owner of sem 0 */
  5037. +#define ARM_SD_OWN1 0x0000000C /* Owner of sem 1 */
  5038. +#define ARM_SD_OWN2 0x00000030 /* Owner of sem 2 */
  5039. +#define ARM_SD_OWN3 0x000000C0 /* Owner of sem 3 */
  5040. +#define ARM_SD_OWN4 0x00000300 /* Owner of sem 4 */
  5041. +#define ARM_SD_OWN5 0x00000C00 /* Owner of sem 5 */
  5042. +#define ARM_SD_OWN6 0x00003000 /* Owner of sem 6 */
  5043. +#define ARM_SD_OWN7 0x0000C000 /* Owner of sem 7 */
  5044. +#define ARM_SD_SEM0 0x00010000 /* Status of sem 0 */
  5045. +#define ARM_SD_SEM1 0x00020000 /* Status of sem 1 */
  5046. +#define ARM_SD_SEM2 0x00040000 /* Status of sem 2 */
  5047. +#define ARM_SD_SEM3 0x00080000 /* Status of sem 3 */
  5048. +#define ARM_SD_SEM4 0x00100000 /* Status of sem 4 */
  5049. +#define ARM_SD_SEM5 0x00200000 /* Status of sem 5 */
  5050. +#define ARM_SD_SEM6 0x00400000 /* Status of sem 6 */
  5051. +#define ARM_SD_SEM7 0x00800000 /* Status of sem 7 */
  5052. +
  5053. +/* Doorbells clear/debug register (...0xE4) */
  5054. +#define ARM_BD_OWN0 0x00000003 /* Owner of doorbell 0 */
  5055. +#define ARM_BD_OWN1 0x0000000C /* Owner of doorbell 1 */
  5056. +#define ARM_BD_OWN2 0x00000030 /* Owner of doorbell 2 */
  5057. +#define ARM_BD_OWN3 0x000000C0 /* Owner of doorbell 3 */
  5058. +#define ARM_BD_BELL0 0x00000100 /* Status of doorbell 0 */
  5059. +#define ARM_BD_BELL1 0x00000200 /* Status of doorbell 1 */
  5060. +#define ARM_BD_BELL2 0x00000400 /* Status of doorbell 2 */
  5061. +#define ARM_BD_BELL3 0x00000800 /* Status of doorbell 3 */
  5062. +
  5063. +/* MY IRQS register (...0xF8) */
  5064. +#define ARM_MYIRQ_BELL 0x00000001 /* This owner has a doorbell IRQ */
  5065. +#define ARM_MYIRQ_MAIL 0x00000002 /* This owner has a mailbox IRQ */
  5066. +
  5067. +/* ALL IRQS register (...0xF8) */
  5068. +#define ARM_AIS_BELL0 0x00000001 /* Doorbell 0 IRQ pending */
  5069. +#define ARM_AIS_BELL1 0x00000002 /* Doorbell 1 IRQ pending */
  5070. +#define ARM_AIS_BELL2 0x00000004 /* Doorbell 2 IRQ pending */
  5071. +#define ARM_AIS_BELL3 0x00000008 /* Doorbell 3 IRQ pending */
  5072. +#define ARM_AIS0_HAVEDATA 0x00000010 /* MAIL 0 has data IRQ pending */
  5073. +#define ARM_AIS0_HAVESPAC 0x00000020 /* MAIL 0 has space IRQ pending */
  5074. +#define ARM_AIS0_OPPEMPTY 0x00000040 /* MAIL 0 opposite is empty IRQ */
  5075. +#define ARM_AIS1_HAVEDATA 0x00000080 /* MAIL 1 has data IRQ pending */
  5076. +#define ARM_AIS1_HAVESPAC 0x00000100 /* MAIL 1 has space IRQ pending */
  5077. +#define ARM_AIS1_OPPEMPTY 0x00000200 /* MAIL 1 opposite is empty IRQ */
  5078. +/* Note that bell-0, bell-1 and MAIL0 IRQ go only to the ARM */
  5079. +/* Whilst that bell-2, bell-3 and MAIL1 IRQ go only to the VC */
  5080. +/* */
  5081. +/* ARM JTAG BASH */
  5082. +/* */
  5083. +#define AJB_BASE 0x7e2000c0
  5084. +
  5085. +#define AJBCONF HW_REGISTER_RW(AJB_BASE+0x00)
  5086. +#define AJB_BITS0 0x000000
  5087. +#define AJB_BITS4 0x000004
  5088. +#define AJB_BITS8 0x000008
  5089. +#define AJB_BITS12 0x00000C
  5090. +#define AJB_BITS16 0x000010
  5091. +#define AJB_BITS20 0x000014
  5092. +#define AJB_BITS24 0x000018
  5093. +#define AJB_BITS28 0x00001C
  5094. +#define AJB_BITS32 0x000020
  5095. +#define AJB_BITS34 0x000022
  5096. +#define AJB_OUT_MS 0x000040
  5097. +#define AJB_OUT_LS 0x000000
  5098. +#define AJB_INV_CLK 0x000080
  5099. +#define AJB_D0_RISE 0x000100
  5100. +#define AJB_D0_FALL 0x000000
  5101. +#define AJB_D1_RISE 0x000200
  5102. +#define AJB_D1_FALL 0x000000
  5103. +#define AJB_IN_RISE 0x000400
  5104. +#define AJB_IN_FALL 0x000000
  5105. +#define AJB_ENABLE 0x000800
  5106. +#define AJB_HOLD0 0x000000
  5107. +#define AJB_HOLD1 0x001000
  5108. +#define AJB_HOLD2 0x002000
  5109. +#define AJB_HOLD3 0x003000
  5110. +#define AJB_RESETN 0x004000
  5111. +#define AJB_CLKSHFT 16
  5112. +#define AJB_BUSY 0x80000000
  5113. +#define AJBTMS HW_REGISTER_RW(AJB_BASE+0x04)
  5114. +#define AJBTDI HW_REGISTER_RW(AJB_BASE+0x08)
  5115. +#define AJBTDO HW_REGISTER_RW(AJB_BASE+0x0c)
  5116. +
  5117. +#endif
  5118. diff -Nur linux-3.12.26.orig/arch/arm/mach-bcm2708/include/mach/arm_power.h linux-3.12.26/arch/arm/mach-bcm2708/include/mach/arm_power.h
  5119. --- linux-3.12.26.orig/arch/arm/mach-bcm2708/include/mach/arm_power.h 1970-01-01 01:00:00.000000000 +0100
  5120. +++ linux-3.12.26/arch/arm/mach-bcm2708/include/mach/arm_power.h 2014-08-06 16:50:13.825957062 +0200
  5121. @@ -0,0 +1,60 @@
  5122. +/*
  5123. + * linux/arch/arm/mach-bcm2708/include/mach/arm_power.h
  5124. + *
  5125. + * Copyright (C) 2010 Broadcom
  5126. + *
  5127. + * This program is free software; you can redistribute it and/or modify
  5128. + * it under the terms of the GNU General Public License as published by
  5129. + * the Free Software Foundation; either version 2 of the License, or
  5130. + * (at your option) any later version.
  5131. + *
  5132. + * This program is distributed in the hope that it will be useful,
  5133. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5134. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5135. + * GNU General Public License for more details.
  5136. + *
  5137. + * You should have received a copy of the GNU General Public License
  5138. + * along with this program; if not, write to the Free Software
  5139. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5140. + */
  5141. +
  5142. +#ifndef _ARM_POWER_H
  5143. +#define _ARM_POWER_H
  5144. +
  5145. +/* Use meaningful names on each side */
  5146. +#ifdef __VIDEOCORE__
  5147. +#define PREFIX(x) ARM_##x
  5148. +#else
  5149. +#define PREFIX(x) BCM_##x
  5150. +#endif
  5151. +
  5152. +enum {
  5153. + PREFIX(POWER_SDCARD_BIT),
  5154. + PREFIX(POWER_UART_BIT),
  5155. + PREFIX(POWER_MINIUART_BIT),
  5156. + PREFIX(POWER_USB_BIT),
  5157. + PREFIX(POWER_I2C0_BIT),
  5158. + PREFIX(POWER_I2C1_BIT),
  5159. + PREFIX(POWER_I2C2_BIT),
  5160. + PREFIX(POWER_SPI_BIT),
  5161. + PREFIX(POWER_CCP2TX_BIT),
  5162. +
  5163. + PREFIX(POWER_MAX)
  5164. +};
  5165. +
  5166. +enum {
  5167. + PREFIX(POWER_SDCARD) = (1 << PREFIX(POWER_SDCARD_BIT)),
  5168. + PREFIX(POWER_UART) = (1 << PREFIX(POWER_UART_BIT)),
  5169. + PREFIX(POWER_MINIUART) = (1 << PREFIX(POWER_MINIUART_BIT)),
  5170. + PREFIX(POWER_USB) = (1 << PREFIX(POWER_USB_BIT)),
  5171. + PREFIX(POWER_I2C0) = (1 << PREFIX(POWER_I2C0_BIT)),
  5172. + PREFIX(POWER_I2C1_MASK) = (1 << PREFIX(POWER_I2C1_BIT)),
  5173. + PREFIX(POWER_I2C2_MASK) = (1 << PREFIX(POWER_I2C2_BIT)),
  5174. + PREFIX(POWER_SPI_MASK) = (1 << PREFIX(POWER_SPI_BIT)),
  5175. + PREFIX(POWER_CCP2TX_MASK) = (1 << PREFIX(POWER_CCP2TX_BIT)),
  5176. +
  5177. + PREFIX(POWER_MASK) = (1 << PREFIX(POWER_MAX)) - 1,
  5178. + PREFIX(POWER_NONE) = 0
  5179. +};
  5180. +
  5181. +#endif
  5182. diff -Nur linux-3.12.26.orig/arch/arm/mach-bcm2708/include/mach/clkdev.h linux-3.12.26/arch/arm/mach-bcm2708/include/mach/clkdev.h
  5183. --- linux-3.12.26.orig/arch/arm/mach-bcm2708/include/mach/clkdev.h 1970-01-01 01:00:00.000000000 +0100
  5184. +++ linux-3.12.26/arch/arm/mach-bcm2708/include/mach/clkdev.h 2014-08-06 16:50:13.825957062 +0200
  5185. @@ -0,0 +1,7 @@
  5186. +#ifndef __ASM_MACH_CLKDEV_H
  5187. +#define __ASM_MACH_CLKDEV_H
  5188. +
  5189. +#define __clk_get(clk) ({ 1; })
  5190. +#define __clk_put(clk) do { } while (0)
  5191. +
  5192. +#endif
  5193. diff -Nur linux-3.12.26.orig/arch/arm/mach-bcm2708/include/mach/debug-macro.S linux-3.12.26/arch/arm/mach-bcm2708/include/mach/debug-macro.S
  5194. --- linux-3.12.26.orig/arch/arm/mach-bcm2708/include/mach/debug-macro.S 1970-01-01 01:00:00.000000000 +0100
  5195. +++ linux-3.12.26/arch/arm/mach-bcm2708/include/mach/debug-macro.S 2014-08-06 16:50:13.825957062 +0200
  5196. @@ -0,0 +1,22 @@
  5197. +/* arch/arm/mach-bcm2708/include/mach/debug-macro.S
  5198. + *
  5199. + * Debugging macro include header
  5200. + *
  5201. + * Copyright (C) 2010 Broadcom
  5202. + * Copyright (C) 1994-1999 Russell King
  5203. + * Moved from linux/arch/arm/kernel/debug.S by Ben Dooks
  5204. + *
  5205. + * This program is free software; you can redistribute it and/or modify
  5206. + * it under the terms of the GNU General Public License version 2 as
  5207. + * published by the Free Software Foundation.
  5208. + *
  5209. +*/
  5210. +
  5211. +#include <mach/platform.h>
  5212. +
  5213. + .macro addruart, rp, rv, tmp
  5214. + ldr \rp, =UART0_BASE
  5215. + ldr \rv, =IO_ADDRESS(UART0_BASE)
  5216. + .endm
  5217. +
  5218. +#include <debug/pl01x.S>
  5219. diff -Nur linux-3.12.26.orig/arch/arm/mach-bcm2708/include/mach/dma.h linux-3.12.26/arch/arm/mach-bcm2708/include/mach/dma.h
  5220. --- linux-3.12.26.orig/arch/arm/mach-bcm2708/include/mach/dma.h 1970-01-01 01:00:00.000000000 +0100
  5221. +++ linux-3.12.26/arch/arm/mach-bcm2708/include/mach/dma.h 2014-08-06 16:50:13.825957062 +0200
  5222. @@ -0,0 +1,90 @@
  5223. +/*
  5224. + * linux/arch/arm/mach-bcm2708/include/mach/dma.h
  5225. + *
  5226. + * Copyright (C) 2010 Broadcom
  5227. + *
  5228. + * This program is free software; you can redistribute it and/or modify
  5229. + * it under the terms of the GNU General Public License version 2 as
  5230. + * published by the Free Software Foundation.
  5231. + */
  5232. +
  5233. +
  5234. +#ifndef _MACH_BCM2708_DMA_H
  5235. +#define _MACH_BCM2708_DMA_H
  5236. +
  5237. +#define BCM_DMAMAN_DRIVER_NAME "bcm2708_dma"
  5238. +
  5239. +/* DMA CS Control and Status bits */
  5240. +#define BCM2708_DMA_ACTIVE (1 << 0)
  5241. +#define BCM2708_DMA_INT (1 << 2)
  5242. +#define BCM2708_DMA_ISPAUSED (1 << 4) /* Pause requested or not active */
  5243. +#define BCM2708_DMA_ISHELD (1 << 5) /* Is held by DREQ flow control */
  5244. +#define BCM2708_DMA_ERR (1 << 8)
  5245. +#define BCM2708_DMA_ABORT (1 << 30) /* stop current CB, go to next, WO */
  5246. +#define BCM2708_DMA_RESET (1 << 31) /* WO, self clearing */
  5247. +
  5248. +/* DMA control block "info" field bits */
  5249. +#define BCM2708_DMA_INT_EN (1 << 0)
  5250. +#define BCM2708_DMA_TDMODE (1 << 1)
  5251. +#define BCM2708_DMA_WAIT_RESP (1 << 3)
  5252. +#define BCM2708_DMA_D_INC (1 << 4)
  5253. +#define BCM2708_DMA_D_WIDTH (1 << 5)
  5254. +#define BCM2708_DMA_D_DREQ (1 << 6)
  5255. +#define BCM2708_DMA_S_INC (1 << 8)
  5256. +#define BCM2708_DMA_S_WIDTH (1 << 9)
  5257. +#define BCM2708_DMA_S_DREQ (1 << 10)
  5258. +
  5259. +#define BCM2708_DMA_BURST(x) (((x)&0xf) << 12)
  5260. +#define BCM2708_DMA_PER_MAP(x) ((x) << 16)
  5261. +#define BCM2708_DMA_WAITS(x) (((x)&0x1f) << 21)
  5262. +
  5263. +#define BCM2708_DMA_DREQ_EMMC 11
  5264. +#define BCM2708_DMA_DREQ_SDHOST 13
  5265. +
  5266. +#define BCM2708_DMA_CS 0x00 /* Control and Status */
  5267. +#define BCM2708_DMA_ADDR 0x04
  5268. +/* the current control block appears in the following registers - read only */
  5269. +#define BCM2708_DMA_INFO 0x08
  5270. +#define BCM2708_DMA_SOURCE_AD 0x0c
  5271. +#define BCM2708_DMA_DEST_AD 0x10
  5272. +#define BCM2708_DMA_NEXTCB 0x1C
  5273. +#define BCM2708_DMA_DEBUG 0x20
  5274. +
  5275. +#define BCM2708_DMA4_CS (BCM2708_DMA_CHAN(4)+BCM2708_DMA_CS)
  5276. +#define BCM2708_DMA4_ADDR (BCM2708_DMA_CHAN(4)+BCM2708_DMA_ADDR)
  5277. +
  5278. +#define BCM2708_DMA_TDMODE_LEN(w, h) ((h) << 16 | (w))
  5279. +
  5280. +struct bcm2708_dma_cb {
  5281. + unsigned long info;
  5282. + unsigned long src;
  5283. + unsigned long dst;
  5284. + unsigned long length;
  5285. + unsigned long stride;
  5286. + unsigned long next;
  5287. + unsigned long pad[2];
  5288. +};
  5289. +struct scatterlist;
  5290. +
  5291. +extern int bcm_sg_suitable_for_dma(struct scatterlist *sg_ptr, int sg_len);
  5292. +extern void bcm_dma_start(void __iomem *dma_chan_base,
  5293. + dma_addr_t control_block);
  5294. +extern void bcm_dma_wait_idle(void __iomem *dma_chan_base);
  5295. +extern bool bcm_dma_is_busy(void __iomem *dma_chan_base);
  5296. +extern int /*rc*/ bcm_dma_abort(void __iomem *dma_chan_base);
  5297. +
  5298. +/* When listing features we can ask for when allocating DMA channels give
  5299. + those with higher priority smaller ordinal numbers */
  5300. +#define BCM_DMA_FEATURE_FAST_ORD 0
  5301. +#define BCM_DMA_FEATURE_BULK_ORD 1
  5302. +#define BCM_DMA_FEATURE_FAST (1<<BCM_DMA_FEATURE_FAST_ORD)
  5303. +#define BCM_DMA_FEATURE_BULK (1<<BCM_DMA_FEATURE_BULK_ORD)
  5304. +#define BCM_DMA_FEATURE_COUNT 2
  5305. +
  5306. +/* return channel no or -ve error */
  5307. +extern int bcm_dma_chan_alloc(unsigned preferred_feature_set,
  5308. + void __iomem **out_dma_base, int *out_dma_irq);
  5309. +extern int bcm_dma_chan_free(int channel);
  5310. +
  5311. +
  5312. +#endif /* _MACH_BCM2708_DMA_H */
  5313. diff -Nur linux-3.12.26.orig/arch/arm/mach-bcm2708/include/mach/entry-macro.S linux-3.12.26/arch/arm/mach-bcm2708/include/mach/entry-macro.S
  5314. --- linux-3.12.26.orig/arch/arm/mach-bcm2708/include/mach/entry-macro.S 1970-01-01 01:00:00.000000000 +0100
  5315. +++ linux-3.12.26/arch/arm/mach-bcm2708/include/mach/entry-macro.S 2014-08-06 16:50:13.829957093 +0200
  5316. @@ -0,0 +1,69 @@
  5317. +/*
  5318. + * arch/arm/mach-bcm2708/include/mach/entry-macro.S
  5319. + *
  5320. + * Low-level IRQ helper macros for BCM2708 platforms
  5321. + *
  5322. + * Copyright (C) 2010 Broadcom
  5323. + *
  5324. + * This program is free software; you can redistribute it and/or modify
  5325. + * it under the terms of the GNU General Public License as published by
  5326. + * the Free Software Foundation; either version 2 of the License, or
  5327. + * (at your option) any later version.
  5328. + *
  5329. + * This program is distributed in the hope that it will be useful,
  5330. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5331. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5332. + * GNU General Public License for more details.
  5333. + *
  5334. + * You should have received a copy of the GNU General Public License
  5335. + * along with this program; if not, write to the Free Software
  5336. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5337. + */
  5338. +#include <mach/hardware.h>
  5339. +
  5340. + .macro disable_fiq
  5341. + .endm
  5342. +
  5343. + .macro get_irqnr_preamble, base, tmp
  5344. + ldr \base, =IO_ADDRESS(ARMCTRL_IC_BASE)
  5345. + .endm
  5346. +
  5347. + .macro arch_ret_to_user, tmp1, tmp2
  5348. + .endm
  5349. +
  5350. + .macro get_irqnr_and_base, irqnr, irqstat, base, tmp
  5351. + /* get masked status */
  5352. + ldr \irqstat, [\base, #(ARM_IRQ_PEND0 - ARMCTRL_IC_BASE)]
  5353. + mov \irqnr, #(ARM_IRQ0_BASE + 31)
  5354. + and \tmp, \irqstat, #0x300 @ save bits 8 and 9
  5355. + /* clear bits 8 and 9, and test */
  5356. + bics \irqstat, \irqstat, #0x300
  5357. + bne 1010f
  5358. +
  5359. + tst \tmp, #0x100
  5360. + ldrne \irqstat, [\base, #(ARM_IRQ_PEND1 - ARMCTRL_IC_BASE)]
  5361. + movne \irqnr, #(ARM_IRQ1_BASE + 31)
  5362. + @ Mask out the interrupts also present in PEND0 - see SW-5809
  5363. + bicne \irqstat, #((1<<7) | (1<<9) | (1<<10))
  5364. + bicne \irqstat, #((1<<18) | (1<<19))
  5365. + bne 1010f
  5366. +
  5367. + tst \tmp, #0x200
  5368. + ldrne \irqstat, [\base, #(ARM_IRQ_PEND2 - ARMCTRL_IC_BASE)]
  5369. + movne \irqnr, #(ARM_IRQ2_BASE + 31)
  5370. + @ Mask out the interrupts also present in PEND0 - see SW-5809
  5371. + bicne \irqstat, #((1<<21) | (1<<22) | (1<<23) | (1<<24) | (1<<25))
  5372. + bicne \irqstat, #((1<<30))
  5373. + beq 1020f
  5374. +
  5375. +1010:
  5376. + @ For non-zero x, LSB(x) = 31 - CLZ(x^(x-1))
  5377. + @ N.B. CLZ is an ARM5 instruction.
  5378. + sub \tmp, \irqstat, #1
  5379. + eor \irqstat, \irqstat, \tmp
  5380. + clz \tmp, \irqstat
  5381. + sub \irqnr, \tmp
  5382. +
  5383. +1020: @ EQ will be set if no irqs pending
  5384. +
  5385. + .endm
  5386. diff -Nur linux-3.12.26.orig/arch/arm/mach-bcm2708/include/mach/frc.h linux-3.12.26/arch/arm/mach-bcm2708/include/mach/frc.h
  5387. --- linux-3.12.26.orig/arch/arm/mach-bcm2708/include/mach/frc.h 1970-01-01 01:00:00.000000000 +0100
  5388. +++ linux-3.12.26/arch/arm/mach-bcm2708/include/mach/frc.h 2014-08-06 16:50:13.829957093 +0200
  5389. @@ -0,0 +1,38 @@
  5390. +/*
  5391. + * arch/arm/mach-bcm2708/include/mach/timex.h
  5392. + *
  5393. + * BCM2708 free running counter (timer)
  5394. + *
  5395. + * Copyright (C) 2010 Broadcom
  5396. + *
  5397. + * This program is free software; you can redistribute it and/or modify
  5398. + * it under the terms of the GNU General Public License as published by
  5399. + * the Free Software Foundation; either version 2 of the License, or
  5400. + * (at your option) any later version.
  5401. + *
  5402. + * This program is distributed in the hope that it will be useful,
  5403. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5404. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5405. + * GNU General Public License for more details.
  5406. + *
  5407. + * You should have received a copy of the GNU General Public License
  5408. + * along with this program; if not, write to the Free Software
  5409. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5410. + */
  5411. +
  5412. +#ifndef _MACH_FRC_H
  5413. +#define _MACH_FRC_H
  5414. +
  5415. +#define FRC_TICK_RATE (1000000)
  5416. +
  5417. +/*! Free running counter incrementing at the CLOCK_TICK_RATE
  5418. + (slightly faster than frc_clock_ticks63()
  5419. + */
  5420. +extern unsigned long frc_clock_ticks32(void);
  5421. +
  5422. +/*! Free running counter incrementing at the CLOCK_TICK_RATE
  5423. + * Note - top bit should be ignored (see cnt32_to_63)
  5424. + */
  5425. +extern unsigned long long frc_clock_ticks63(void);
  5426. +
  5427. +#endif
  5428. diff -Nur linux-3.12.26.orig/arch/arm/mach-bcm2708/include/mach/gpio.h linux-3.12.26/arch/arm/mach-bcm2708/include/mach/gpio.h
  5429. --- linux-3.12.26.orig/arch/arm/mach-bcm2708/include/mach/gpio.h 1970-01-01 01:00:00.000000000 +0100
  5430. +++ linux-3.12.26/arch/arm/mach-bcm2708/include/mach/gpio.h 2014-08-06 16:50:13.829957093 +0200
  5431. @@ -0,0 +1,17 @@
  5432. +/*
  5433. + * arch/arm/mach-bcm2708/include/mach/gpio.h
  5434. + *
  5435. + * This file is licensed under the terms of the GNU General Public
  5436. + * License version 2. This program is licensed "as is" without any
  5437. + * warranty of any kind, whether express or implied.
  5438. + */
  5439. +
  5440. +#ifndef __ASM_ARCH_GPIO_H
  5441. +#define __ASM_ARCH_GPIO_H
  5442. +
  5443. +#define BCM2708_NR_GPIOS 54 // number of gpio lines
  5444. +
  5445. +#define gpio_to_irq(x) ((x) + GPIO_IRQ_START)
  5446. +#define irq_to_gpio(x) ((x) - GPIO_IRQ_START)
  5447. +
  5448. +#endif
  5449. diff -Nur linux-3.12.26.orig/arch/arm/mach-bcm2708/include/mach/hardware.h linux-3.12.26/arch/arm/mach-bcm2708/include/mach/hardware.h
  5450. --- linux-3.12.26.orig/arch/arm/mach-bcm2708/include/mach/hardware.h 1970-01-01 01:00:00.000000000 +0100
  5451. +++ linux-3.12.26/arch/arm/mach-bcm2708/include/mach/hardware.h 2014-08-06 16:50:13.857957313 +0200
  5452. @@ -0,0 +1,28 @@
  5453. +/*
  5454. + * arch/arm/mach-bcm2708/include/mach/hardware.h
  5455. + *
  5456. + * This file contains the hardware definitions of the BCM2708 devices.
  5457. + *
  5458. + * Copyright (C) 2010 Broadcom
  5459. + *
  5460. + * This program is free software; you can redistribute it and/or modify
  5461. + * it under the terms of the GNU General Public License as published by
  5462. + * the Free Software Foundation; either version 2 of the License, or
  5463. + * (at your option) any later version.
  5464. + *
  5465. + * This program is distributed in the hope that it will be useful,
  5466. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5467. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5468. + * GNU General Public License for more details.
  5469. + *
  5470. + * You should have received a copy of the GNU General Public License
  5471. + * along with this program; if not, write to the Free Software
  5472. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5473. + */
  5474. +#ifndef __ASM_ARCH_HARDWARE_H
  5475. +#define __ASM_ARCH_HARDWARE_H
  5476. +
  5477. +#include <asm/sizes.h>
  5478. +#include <mach/platform.h>
  5479. +
  5480. +#endif
  5481. diff -Nur linux-3.12.26.orig/arch/arm/mach-bcm2708/include/mach/io.h linux-3.12.26/arch/arm/mach-bcm2708/include/mach/io.h
  5482. --- linux-3.12.26.orig/arch/arm/mach-bcm2708/include/mach/io.h 1970-01-01 01:00:00.000000000 +0100
  5483. +++ linux-3.12.26/arch/arm/mach-bcm2708/include/mach/io.h 2014-08-06 16:50:13.865957376 +0200
  5484. @@ -0,0 +1,27 @@
  5485. +/*
  5486. + * arch/arm/mach-bcm2708/include/mach/io.h
  5487. + *
  5488. + * Copyright (C) 2003 ARM Limited
  5489. + *
  5490. + * This program is free software; you can redistribute it and/or modify
  5491. + * it under the terms of the GNU General Public License as published by
  5492. + * the Free Software Foundation; either version 2 of the License, or
  5493. + * (at your option) any later version.
  5494. + *
  5495. + * This program is distributed in the hope that it will be useful,
  5496. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5497. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5498. + * GNU General Public License for more details.
  5499. + *
  5500. + * You should have received a copy of the GNU General Public License
  5501. + * along with this program; if not, write to the Free Software
  5502. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5503. + */
  5504. +#ifndef __ASM_ARM_ARCH_IO_H
  5505. +#define __ASM_ARM_ARCH_IO_H
  5506. +
  5507. +#define IO_SPACE_LIMIT 0xffffffff
  5508. +
  5509. +#define __io(a) __typesafe_io(a)
  5510. +
  5511. +#endif
  5512. diff -Nur linux-3.12.26.orig/arch/arm/mach-bcm2708/include/mach/irqs.h linux-3.12.26/arch/arm/mach-bcm2708/include/mach/irqs.h
  5513. --- linux-3.12.26.orig/arch/arm/mach-bcm2708/include/mach/irqs.h 1970-01-01 01:00:00.000000000 +0100
  5514. +++ linux-3.12.26/arch/arm/mach-bcm2708/include/mach/irqs.h 2014-08-06 16:50:13.865957376 +0200
  5515. @@ -0,0 +1,200 @@
  5516. +/*
  5517. + * arch/arm/mach-bcm2708/include/mach/irqs.h
  5518. + *
  5519. + * Copyright (C) 2010 Broadcom
  5520. + * Copyright (C) 2003 ARM Limited
  5521. + * Copyright (C) 2000 Deep Blue Solutions Ltd.
  5522. + *
  5523. + * This program is free software; you can redistribute it and/or modify
  5524. + * it under the terms of the GNU General Public License as published by
  5525. + * the Free Software Foundation; either version 2 of the License, or
  5526. + * (at your option) any later version.
  5527. + *
  5528. + * This program is distributed in the hope that it will be useful,
  5529. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5530. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5531. + * GNU General Public License for more details.
  5532. + *
  5533. + * You should have received a copy of the GNU General Public License
  5534. + * along with this program; if not, write to the Free Software
  5535. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5536. + */
  5537. +
  5538. +#ifndef _BCM2708_IRQS_H_
  5539. +#define _BCM2708_IRQS_H_
  5540. +
  5541. +#include <mach/platform.h>
  5542. +
  5543. +/*
  5544. + * IRQ interrupts definitions are the same as the INT definitions
  5545. + * held within platform.h
  5546. + */
  5547. +#define IRQ_ARMCTRL_START 0
  5548. +#define IRQ_TIMER0 (IRQ_ARMCTRL_START + INTERRUPT_TIMER0)
  5549. +#define IRQ_TIMER1 (IRQ_ARMCTRL_START + INTERRUPT_TIMER1)
  5550. +#define IRQ_TIMER2 (IRQ_ARMCTRL_START + INTERRUPT_TIMER2)
  5551. +#define IRQ_TIMER3 (IRQ_ARMCTRL_START + INTERRUPT_TIMER3)
  5552. +#define IRQ_CODEC0 (IRQ_ARMCTRL_START + INTERRUPT_CODEC0)
  5553. +#define IRQ_CODEC1 (IRQ_ARMCTRL_START + INTERRUPT_CODEC1)
  5554. +#define IRQ_CODEC2 (IRQ_ARMCTRL_START + INTERRUPT_CODEC2)
  5555. +#define IRQ_JPEG (IRQ_ARMCTRL_START + INTERRUPT_JPEG)
  5556. +#define IRQ_ISP (IRQ_ARMCTRL_START + INTERRUPT_ISP)
  5557. +#define IRQ_USB (IRQ_ARMCTRL_START + INTERRUPT_USB)
  5558. +#define IRQ_3D (IRQ_ARMCTRL_START + INTERRUPT_3D)
  5559. +#define IRQ_TRANSPOSER (IRQ_ARMCTRL_START + INTERRUPT_TRANSPOSER)
  5560. +#define IRQ_MULTICORESYNC0 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC0)
  5561. +#define IRQ_MULTICORESYNC1 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC1)
  5562. +#define IRQ_MULTICORESYNC2 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC2)
  5563. +#define IRQ_MULTICORESYNC3 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC3)
  5564. +#define IRQ_DMA0 (IRQ_ARMCTRL_START + INTERRUPT_DMA0)
  5565. +#define IRQ_DMA1 (IRQ_ARMCTRL_START + INTERRUPT_DMA1)
  5566. +#define IRQ_DMA2 (IRQ_ARMCTRL_START + INTERRUPT_DMA2)
  5567. +#define IRQ_DMA3 (IRQ_ARMCTRL_START + INTERRUPT_DMA3)
  5568. +#define IRQ_DMA4 (IRQ_ARMCTRL_START + INTERRUPT_DMA4)
  5569. +#define IRQ_DMA5 (IRQ_ARMCTRL_START + INTERRUPT_DMA5)
  5570. +#define IRQ_DMA6 (IRQ_ARMCTRL_START + INTERRUPT_DMA6)
  5571. +#define IRQ_DMA7 (IRQ_ARMCTRL_START + INTERRUPT_DMA7)
  5572. +#define IRQ_DMA8 (IRQ_ARMCTRL_START + INTERRUPT_DMA8)
  5573. +#define IRQ_DMA9 (IRQ_ARMCTRL_START + INTERRUPT_DMA9)
  5574. +#define IRQ_DMA10 (IRQ_ARMCTRL_START + INTERRUPT_DMA10)
  5575. +#define IRQ_DMA11 (IRQ_ARMCTRL_START + INTERRUPT_DMA11)
  5576. +#define IRQ_DMA12 (IRQ_ARMCTRL_START + INTERRUPT_DMA12)
  5577. +#define IRQ_AUX (IRQ_ARMCTRL_START + INTERRUPT_AUX)
  5578. +#define IRQ_ARM (IRQ_ARMCTRL_START + INTERRUPT_ARM)
  5579. +#define IRQ_VPUDMA (IRQ_ARMCTRL_START + INTERRUPT_VPUDMA)
  5580. +#define IRQ_HOSTPORT (IRQ_ARMCTRL_START + INTERRUPT_HOSTPORT)
  5581. +#define IRQ_VIDEOSCALER (IRQ_ARMCTRL_START + INTERRUPT_VIDEOSCALER)
  5582. +#define IRQ_CCP2TX (IRQ_ARMCTRL_START + INTERRUPT_CCP2TX)
  5583. +#define IRQ_SDC (IRQ_ARMCTRL_START + INTERRUPT_SDC)
  5584. +#define IRQ_DSI0 (IRQ_ARMCTRL_START + INTERRUPT_DSI0)
  5585. +#define IRQ_AVE (IRQ_ARMCTRL_START + INTERRUPT_AVE)
  5586. +#define IRQ_CAM0 (IRQ_ARMCTRL_START + INTERRUPT_CAM0)
  5587. +#define IRQ_CAM1 (IRQ_ARMCTRL_START + INTERRUPT_CAM1)
  5588. +#define IRQ_HDMI0 (IRQ_ARMCTRL_START + INTERRUPT_HDMI0)
  5589. +#define IRQ_HDMI1 (IRQ_ARMCTRL_START + INTERRUPT_HDMI1)
  5590. +#define IRQ_PIXELVALVE1 (IRQ_ARMCTRL_START + INTERRUPT_PIXELVALVE1)
  5591. +#define IRQ_I2CSPISLV (IRQ_ARMCTRL_START + INTERRUPT_I2CSPISLV)
  5592. +#define IRQ_DSI1 (IRQ_ARMCTRL_START + INTERRUPT_DSI1)
  5593. +#define IRQ_PWA0 (IRQ_ARMCTRL_START + INTERRUPT_PWA0)
  5594. +#define IRQ_PWA1 (IRQ_ARMCTRL_START + INTERRUPT_PWA1)
  5595. +#define IRQ_CPR (IRQ_ARMCTRL_START + INTERRUPT_CPR)
  5596. +#define IRQ_SMI (IRQ_ARMCTRL_START + INTERRUPT_SMI)
  5597. +#define IRQ_GPIO0 (IRQ_ARMCTRL_START + INTERRUPT_GPIO0)
  5598. +#define IRQ_GPIO1 (IRQ_ARMCTRL_START + INTERRUPT_GPIO1)
  5599. +#define IRQ_GPIO2 (IRQ_ARMCTRL_START + INTERRUPT_GPIO2)
  5600. +#define IRQ_GPIO3 (IRQ_ARMCTRL_START + INTERRUPT_GPIO3)
  5601. +#define IRQ_I2C (IRQ_ARMCTRL_START + INTERRUPT_I2C)
  5602. +#define IRQ_SPI (IRQ_ARMCTRL_START + INTERRUPT_SPI)
  5603. +#define IRQ_I2SPCM (IRQ_ARMCTRL_START + INTERRUPT_I2SPCM)
  5604. +#define IRQ_SDIO (IRQ_ARMCTRL_START + INTERRUPT_SDIO)
  5605. +#define IRQ_UART (IRQ_ARMCTRL_START + INTERRUPT_UART)
  5606. +#define IRQ_SLIMBUS (IRQ_ARMCTRL_START + INTERRUPT_SLIMBUS)
  5607. +#define IRQ_VEC (IRQ_ARMCTRL_START + INTERRUPT_VEC)
  5608. +#define IRQ_CPG (IRQ_ARMCTRL_START + INTERRUPT_CPG)
  5609. +#define IRQ_RNG (IRQ_ARMCTRL_START + INTERRUPT_RNG)
  5610. +#define IRQ_ARASANSDIO (IRQ_ARMCTRL_START + INTERRUPT_ARASANSDIO)
  5611. +#define IRQ_AVSPMON (IRQ_ARMCTRL_START + INTERRUPT_AVSPMON)
  5612. +
  5613. +#define IRQ_ARM_TIMER (IRQ_ARMCTRL_START + INTERRUPT_ARM_TIMER)
  5614. +#define IRQ_ARM_MAILBOX (IRQ_ARMCTRL_START + INTERRUPT_ARM_MAILBOX)
  5615. +#define IRQ_ARM_DOORBELL_0 (IRQ_ARMCTRL_START + INTERRUPT_ARM_DOORBELL_0)
  5616. +#define IRQ_ARM_DOORBELL_1 (IRQ_ARMCTRL_START + INTERRUPT_ARM_DOORBELL_1)
  5617. +#define IRQ_VPU0_HALTED (IRQ_ARMCTRL_START + INTERRUPT_VPU0_HALTED)
  5618. +#define IRQ_VPU1_HALTED (IRQ_ARMCTRL_START + INTERRUPT_VPU1_HALTED)
  5619. +#define IRQ_ILLEGAL_TYPE0 (IRQ_ARMCTRL_START + INTERRUPT_ILLEGAL_TYPE0)
  5620. +#define IRQ_ILLEGAL_TYPE1 (IRQ_ARMCTRL_START + INTERRUPT_ILLEGAL_TYPE1)
  5621. +#define IRQ_PENDING1 (IRQ_ARMCTRL_START + INTERRUPT_PENDING1)
  5622. +#define IRQ_PENDING2 (IRQ_ARMCTRL_START + INTERRUPT_PENDING2)
  5623. +
  5624. +#define FIQ_START HARD_IRQS
  5625. +
  5626. +/*
  5627. + * FIQ interrupts definitions are the same as the INT definitions.
  5628. + */
  5629. +#define FIQ_TIMER0 (FIQ_START+INTERRUPT_TIMER0)
  5630. +#define FIQ_TIMER1 (FIQ_START+INTERRUPT_TIMER1)
  5631. +#define FIQ_TIMER2 (FIQ_START+INTERRUPT_TIMER2)
  5632. +#define FIQ_TIMER3 (FIQ_START+INTERRUPT_TIMER3)
  5633. +#define FIQ_CODEC0 (FIQ_START+INTERRUPT_CODEC0)
  5634. +#define FIQ_CODEC1 (FIQ_START+INTERRUPT_CODEC1)
  5635. +#define FIQ_CODEC2 (FIQ_START+INTERRUPT_CODEC2)
  5636. +#define FIQ_JPEG (FIQ_START+INTERRUPT_JPEG)
  5637. +#define FIQ_ISP (FIQ_START+INTERRUPT_ISP)
  5638. +#define FIQ_USB (FIQ_START+INTERRUPT_USB)
  5639. +#define FIQ_3D (FIQ_START+INTERRUPT_3D)
  5640. +#define FIQ_TRANSPOSER (FIQ_START+INTERRUPT_TRANSPOSER)
  5641. +#define FIQ_MULTICORESYNC0 (FIQ_START+INTERRUPT_MULTICORESYNC0)
  5642. +#define FIQ_MULTICORESYNC1 (FIQ_START+INTERRUPT_MULTICORESYNC1)
  5643. +#define FIQ_MULTICORESYNC2 (FIQ_START+INTERRUPT_MULTICORESYNC2)
  5644. +#define FIQ_MULTICORESYNC3 (FIQ_START+INTERRUPT_MULTICORESYNC3)
  5645. +#define FIQ_DMA0 (FIQ_START+INTERRUPT_DMA0)
  5646. +#define FIQ_DMA1 (FIQ_START+INTERRUPT_DMA1)
  5647. +#define FIQ_DMA2 (FIQ_START+INTERRUPT_DMA2)
  5648. +#define FIQ_DMA3 (FIQ_START+INTERRUPT_DMA3)
  5649. +#define FIQ_DMA4 (FIQ_START+INTERRUPT_DMA4)
  5650. +#define FIQ_DMA5 (FIQ_START+INTERRUPT_DMA5)
  5651. +#define FIQ_DMA6 (FIQ_START+INTERRUPT_DMA6)
  5652. +#define FIQ_DMA7 (FIQ_START+INTERRUPT_DMA7)
  5653. +#define FIQ_DMA8 (FIQ_START+INTERRUPT_DMA8)
  5654. +#define FIQ_DMA9 (FIQ_START+INTERRUPT_DMA9)
  5655. +#define FIQ_DMA10 (FIQ_START+INTERRUPT_DMA10)
  5656. +#define FIQ_DMA11 (FIQ_START+INTERRUPT_DMA11)
  5657. +#define FIQ_DMA12 (FIQ_START+INTERRUPT_DMA12)
  5658. +#define FIQ_AUX (FIQ_START+INTERRUPT_AUX)
  5659. +#define FIQ_ARM (FIQ_START+INTERRUPT_ARM)
  5660. +#define FIQ_VPUDMA (FIQ_START+INTERRUPT_VPUDMA)
  5661. +#define FIQ_HOSTPORT (FIQ_START+INTERRUPT_HOSTPORT)
  5662. +#define FIQ_VIDEOSCALER (FIQ_START+INTERRUPT_VIDEOSCALER)
  5663. +#define FIQ_CCP2TX (FIQ_START+INTERRUPT_CCP2TX)
  5664. +#define FIQ_SDC (FIQ_START+INTERRUPT_SDC)
  5665. +#define FIQ_DSI0 (FIQ_START+INTERRUPT_DSI0)
  5666. +#define FIQ_AVE (FIQ_START+INTERRUPT_AVE)
  5667. +#define FIQ_CAM0 (FIQ_START+INTERRUPT_CAM0)
  5668. +#define FIQ_CAM1 (FIQ_START+INTERRUPT_CAM1)
  5669. +#define FIQ_HDMI0 (FIQ_START+INTERRUPT_HDMI0)
  5670. +#define FIQ_HDMI1 (FIQ_START+INTERRUPT_HDMI1)
  5671. +#define FIQ_PIXELVALVE1 (FIQ_START+INTERRUPT_PIXELVALVE1)
  5672. +#define FIQ_I2CSPISLV (FIQ_START+INTERRUPT_I2CSPISLV)
  5673. +#define FIQ_DSI1 (FIQ_START+INTERRUPT_DSI1)
  5674. +#define FIQ_PWA0 (FIQ_START+INTERRUPT_PWA0)
  5675. +#define FIQ_PWA1 (FIQ_START+INTERRUPT_PWA1)
  5676. +#define FIQ_CPR (FIQ_START+INTERRUPT_CPR)
  5677. +#define FIQ_SMI (FIQ_START+INTERRUPT_SMI)
  5678. +#define FIQ_GPIO0 (FIQ_START+INTERRUPT_GPIO0)
  5679. +#define FIQ_GPIO1 (FIQ_START+INTERRUPT_GPIO1)
  5680. +#define FIQ_GPIO2 (FIQ_START+INTERRUPT_GPIO2)
  5681. +#define FIQ_GPIO3 (FIQ_START+INTERRUPT_GPIO3)
  5682. +#define FIQ_I2C (FIQ_START+INTERRUPT_I2C)
  5683. +#define FIQ_SPI (FIQ_START+INTERRUPT_SPI)
  5684. +#define FIQ_I2SPCM (FIQ_START+INTERRUPT_I2SPCM)
  5685. +#define FIQ_SDIO (FIQ_START+INTERRUPT_SDIO)
  5686. +#define FIQ_UART (FIQ_START+INTERRUPT_UART)
  5687. +#define FIQ_SLIMBUS (FIQ_START+INTERRUPT_SLIMBUS)
  5688. +#define FIQ_VEC (FIQ_START+INTERRUPT_VEC)
  5689. +#define FIQ_CPG (FIQ_START+INTERRUPT_CPG)
  5690. +#define FIQ_RNG (FIQ_START+INTERRUPT_RNG)
  5691. +#define FIQ_ARASANSDIO (FIQ_START+INTERRUPT_ARASANSDIO)
  5692. +#define FIQ_AVSPMON (FIQ_START+INTERRUPT_AVSPMON)
  5693. +
  5694. +#define FIQ_ARM_TIMER (FIQ_START+INTERRUPT_ARM_TIMER)
  5695. +#define FIQ_ARM_MAILBOX (FIQ_START+INTERRUPT_ARM_MAILBOX)
  5696. +#define FIQ_ARM_DOORBELL_0 (FIQ_START+INTERRUPT_ARM_DOORBELL_0)
  5697. +#define FIQ_ARM_DOORBELL_1 (FIQ_START+INTERRUPT_ARM_DOORBELL_1)
  5698. +#define FIQ_VPU0_HALTED (FIQ_START+INTERRUPT_VPU0_HALTED)
  5699. +#define FIQ_VPU1_HALTED (FIQ_START+INTERRUPT_VPU1_HALTED)
  5700. +#define FIQ_ILLEGAL_TYPE0 (FIQ_START+INTERRUPT_ILLEGAL_TYPE0)
  5701. +#define FIQ_ILLEGAL_TYPE1 (FIQ_START+INTERRUPT_ILLEGAL_TYPE1)
  5702. +#define FIQ_PENDING1 (FIQ_START+INTERRUPT_PENDING1)
  5703. +#define FIQ_PENDING2 (FIQ_START+INTERRUPT_PENDING2)
  5704. +
  5705. +#define GPIO_IRQ_START (HARD_IRQS + FIQ_IRQS)
  5706. +
  5707. +#define HARD_IRQS (64 + 21)
  5708. +#define FIQ_IRQS (64 + 21)
  5709. +#define GPIO_IRQS (32*5)
  5710. +#define SPARE_IRQS (64)
  5711. +
  5712. +#define NR_IRQS HARD_IRQS+FIQ_IRQS+GPIO_IRQS+SPARE_IRQS
  5713. +
  5714. +
  5715. +#endif /* _BCM2708_IRQS_H_ */
  5716. diff -Nur linux-3.12.26.orig/arch/arm/mach-bcm2708/include/mach/memory.h linux-3.12.26/arch/arm/mach-bcm2708/include/mach/memory.h
  5717. --- linux-3.12.26.orig/arch/arm/mach-bcm2708/include/mach/memory.h 1970-01-01 01:00:00.000000000 +0100
  5718. +++ linux-3.12.26/arch/arm/mach-bcm2708/include/mach/memory.h 2014-08-06 16:50:13.869957407 +0200
  5719. @@ -0,0 +1,57 @@
  5720. +/*
  5721. + * arch/arm/mach-bcm2708/include/mach/memory.h
  5722. + *
  5723. + * Copyright (C) 2010 Broadcom
  5724. + *
  5725. + * This program is free software; you can redistribute it and/or modify
  5726. + * it under the terms of the GNU General Public License as published by
  5727. + * the Free Software Foundation; either version 2 of the License, or
  5728. + * (at your option) any later version.
  5729. + *
  5730. + * This program is distributed in the hope that it will be useful,
  5731. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5732. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5733. + * GNU General Public License for more details.
  5734. + *
  5735. + * You should have received a copy of the GNU General Public License
  5736. + * along with this program; if not, write to the Free Software
  5737. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5738. + */
  5739. +#ifndef __ASM_ARCH_MEMORY_H
  5740. +#define __ASM_ARCH_MEMORY_H
  5741. +
  5742. +/* Memory overview:
  5743. +
  5744. + [ARMcore] <--virtual addr-->
  5745. + [ARMmmu] <--physical addr-->
  5746. + [GERTmap] <--bus add-->
  5747. + [VCperiph]
  5748. +
  5749. +*/
  5750. +
  5751. +/*
  5752. + * Physical DRAM offset.
  5753. + */
  5754. +#define PLAT_PHYS_OFFSET UL(0x00000000)
  5755. +#define VC_ARMMEM_OFFSET UL(0x00000000) /* offset in VC of ARM memory */
  5756. +
  5757. +#ifdef CONFIG_BCM2708_NOL2CACHE
  5758. + #define _REAL_BUS_OFFSET UL(0xC0000000) /* don't use L1 or L2 caches */
  5759. +#else
  5760. + #define _REAL_BUS_OFFSET UL(0x40000000) /* use L2 cache */
  5761. +#endif
  5762. +
  5763. +/* We're using the memory at 64M in the VideoCore for Linux - this adjustment
  5764. + * will provide the offset into this area as well as setting the bits that
  5765. + * stop the L1 and L2 cache from being used
  5766. + *
  5767. + * WARNING: this only works because the ARM is given memory at a fixed location
  5768. + * (ARMMEM_OFFSET)
  5769. + */
  5770. +#define BUS_OFFSET (VC_ARMMEM_OFFSET + _REAL_BUS_OFFSET)
  5771. +#define __virt_to_bus(x) ((x) + (BUS_OFFSET - PAGE_OFFSET))
  5772. +#define __bus_to_virt(x) ((x) - (BUS_OFFSET - PAGE_OFFSET))
  5773. +#define __pfn_to_bus(x) (__pfn_to_phys(x) + (BUS_OFFSET - PLAT_PHYS_OFFSET))
  5774. +#define __bus_to_pfn(x) __phys_to_pfn((x) - (BUS_OFFSET - PLAT_PHYS_OFFSET))
  5775. +
  5776. +#endif
  5777. diff -Nur linux-3.12.26.orig/arch/arm/mach-bcm2708/include/mach/platform.h linux-3.12.26/arch/arm/mach-bcm2708/include/mach/platform.h
  5778. --- linux-3.12.26.orig/arch/arm/mach-bcm2708/include/mach/platform.h 1970-01-01 01:00:00.000000000 +0100
  5779. +++ linux-3.12.26/arch/arm/mach-bcm2708/include/mach/platform.h 2014-08-06 16:50:13.869957407 +0200
  5780. @@ -0,0 +1,228 @@
  5781. +/*
  5782. + * arch/arm/mach-bcm2708/include/mach/platform.h
  5783. + *
  5784. + * Copyright (C) 2010 Broadcom
  5785. + *
  5786. + * This program is free software; you can redistribute it and/or modify
  5787. + * it under the terms of the GNU General Public License as published by
  5788. + * the Free Software Foundation; either version 2 of the License, or
  5789. + * (at your option) any later version.
  5790. + *
  5791. + * This program is distributed in the hope that it will be useful,
  5792. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5793. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5794. + * GNU General Public License for more details.
  5795. + *
  5796. + * You should have received a copy of the GNU General Public License
  5797. + * along with this program; if not, write to the Free Software
  5798. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5799. + */
  5800. +
  5801. +#ifndef _BCM2708_PLATFORM_H
  5802. +#define _BCM2708_PLATFORM_H
  5803. +
  5804. +
  5805. +/* macros to get at IO space when running virtually */
  5806. +#define IO_ADDRESS(x) (((x) & 0x0fffffff) + (((x) >> 4) & 0x0f000000) + 0xf0000000)
  5807. +
  5808. +#define __io_address(n) IOMEM(IO_ADDRESS(n))
  5809. +
  5810. +
  5811. +/*
  5812. + * SDRAM
  5813. + */
  5814. +#define BCM2708_SDRAM_BASE 0x00000000
  5815. +
  5816. +/*
  5817. + * Logic expansion modules
  5818. + *
  5819. + */
  5820. +
  5821. +
  5822. +/* ------------------------------------------------------------------------
  5823. + * BCM2708 ARMCTRL Registers
  5824. + * ------------------------------------------------------------------------
  5825. + */
  5826. +
  5827. +#define HW_REGISTER_RW(addr) (addr)
  5828. +#define HW_REGISTER_RO(addr) (addr)
  5829. +
  5830. +#include "arm_control.h"
  5831. +#undef ARM_BASE
  5832. +
  5833. +/*
  5834. + * Definitions and addresses for the ARM CONTROL logic
  5835. + * This file is manually generated.
  5836. + */
  5837. +
  5838. +#define BCM2708_PERI_BASE 0x20000000
  5839. +#define IC0_BASE (BCM2708_PERI_BASE + 0x2000)
  5840. +#define ST_BASE (BCM2708_PERI_BASE + 0x3000) /* System Timer */
  5841. +#define MPHI_BASE (BCM2708_PERI_BASE + 0x6000) /* Message -based Parallel Host Interface */
  5842. +#define DMA_BASE (BCM2708_PERI_BASE + 0x7000) /* DMA controller */
  5843. +#define ARM_BASE (BCM2708_PERI_BASE + 0xB000) /* BCM2708 ARM control block */
  5844. +#define PM_BASE (BCM2708_PERI_BASE + 0x100000) /* Power Management, Reset controller and Watchdog registers */
  5845. +#define PCM_CLOCK_BASE (BCM2708_PERI_BASE + 0x101098) /* PCM Clock */
  5846. +#define RNG_BASE (BCM2708_PERI_BASE + 0x104000) /* Hardware RNG */
  5847. +#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) /* GPIO */
  5848. +#define UART0_BASE (BCM2708_PERI_BASE + 0x201000) /* Uart 0 */
  5849. +#define MMCI0_BASE (BCM2708_PERI_BASE + 0x202000) /* MMC interface */
  5850. +#define I2S_BASE (BCM2708_PERI_BASE + 0x203000) /* I2S */
  5851. +#define SPI0_BASE (BCM2708_PERI_BASE + 0x204000) /* SPI0 */
  5852. +#define BSC0_BASE (BCM2708_PERI_BASE + 0x205000) /* BSC0 I2C/TWI */
  5853. +#define UART1_BASE (BCM2708_PERI_BASE + 0x215000) /* Uart 1 */
  5854. +#define EMMC_BASE (BCM2708_PERI_BASE + 0x300000) /* eMMC interface */
  5855. +#define SMI_BASE (BCM2708_PERI_BASE + 0x600000) /* SMI */
  5856. +#define BSC1_BASE (BCM2708_PERI_BASE + 0x804000) /* BSC1 I2C/TWI */
  5857. +#define USB_BASE (BCM2708_PERI_BASE + 0x980000) /* DTC_OTG USB controller */
  5858. +#define MCORE_BASE (BCM2708_PERI_BASE + 0x0000) /* Fake frame buffer device (actually the multicore sync block*/
  5859. +
  5860. +#define ARMCTRL_BASE (ARM_BASE + 0x000)
  5861. +#define ARMCTRL_IC_BASE (ARM_BASE + 0x200) /* ARM interrupt controller */
  5862. +#define ARMCTRL_TIMER0_1_BASE (ARM_BASE + 0x400) /* Timer 0 and 1 */
  5863. +#define ARMCTRL_0_SBM_BASE (ARM_BASE + 0x800) /* User 0 (ARM)'s Semaphores Doorbells and Mailboxes */
  5864. +
  5865. +
  5866. +/*
  5867. + * Interrupt assignments
  5868. + */
  5869. +
  5870. +#define ARM_IRQ1_BASE 0
  5871. +#define INTERRUPT_TIMER0 (ARM_IRQ1_BASE + 0)
  5872. +#define INTERRUPT_TIMER1 (ARM_IRQ1_BASE + 1)
  5873. +#define INTERRUPT_TIMER2 (ARM_IRQ1_BASE + 2)
  5874. +#define INTERRUPT_TIMER3 (ARM_IRQ1_BASE + 3)
  5875. +#define INTERRUPT_CODEC0 (ARM_IRQ1_BASE + 4)
  5876. +#define INTERRUPT_CODEC1 (ARM_IRQ1_BASE + 5)
  5877. +#define INTERRUPT_CODEC2 (ARM_IRQ1_BASE + 6)
  5878. +#define INTERRUPT_VC_JPEG (ARM_IRQ1_BASE + 7)
  5879. +#define INTERRUPT_ISP (ARM_IRQ1_BASE + 8)
  5880. +#define INTERRUPT_VC_USB (ARM_IRQ1_BASE + 9)
  5881. +#define INTERRUPT_VC_3D (ARM_IRQ1_BASE + 10)
  5882. +#define INTERRUPT_TRANSPOSER (ARM_IRQ1_BASE + 11)
  5883. +#define INTERRUPT_MULTICORESYNC0 (ARM_IRQ1_BASE + 12)
  5884. +#define INTERRUPT_MULTICORESYNC1 (ARM_IRQ1_BASE + 13)
  5885. +#define INTERRUPT_MULTICORESYNC2 (ARM_IRQ1_BASE + 14)
  5886. +#define INTERRUPT_MULTICORESYNC3 (ARM_IRQ1_BASE + 15)
  5887. +#define INTERRUPT_DMA0 (ARM_IRQ1_BASE + 16)
  5888. +#define INTERRUPT_DMA1 (ARM_IRQ1_BASE + 17)
  5889. +#define INTERRUPT_VC_DMA2 (ARM_IRQ1_BASE + 18)
  5890. +#define INTERRUPT_VC_DMA3 (ARM_IRQ1_BASE + 19)
  5891. +#define INTERRUPT_DMA4 (ARM_IRQ1_BASE + 20)
  5892. +#define INTERRUPT_DMA5 (ARM_IRQ1_BASE + 21)
  5893. +#define INTERRUPT_DMA6 (ARM_IRQ1_BASE + 22)
  5894. +#define INTERRUPT_DMA7 (ARM_IRQ1_BASE + 23)
  5895. +#define INTERRUPT_DMA8 (ARM_IRQ1_BASE + 24)
  5896. +#define INTERRUPT_DMA9 (ARM_IRQ1_BASE + 25)
  5897. +#define INTERRUPT_DMA10 (ARM_IRQ1_BASE + 26)
  5898. +#define INTERRUPT_DMA11 (ARM_IRQ1_BASE + 27)
  5899. +#define INTERRUPT_DMA12 (ARM_IRQ1_BASE + 28)
  5900. +#define INTERRUPT_AUX (ARM_IRQ1_BASE + 29)
  5901. +#define INTERRUPT_ARM (ARM_IRQ1_BASE + 30)
  5902. +#define INTERRUPT_VPUDMA (ARM_IRQ1_BASE + 31)
  5903. +
  5904. +#define ARM_IRQ2_BASE 32
  5905. +#define INTERRUPT_HOSTPORT (ARM_IRQ2_BASE + 0)
  5906. +#define INTERRUPT_VIDEOSCALER (ARM_IRQ2_BASE + 1)
  5907. +#define INTERRUPT_CCP2TX (ARM_IRQ2_BASE + 2)
  5908. +#define INTERRUPT_SDC (ARM_IRQ2_BASE + 3)
  5909. +#define INTERRUPT_DSI0 (ARM_IRQ2_BASE + 4)
  5910. +#define INTERRUPT_AVE (ARM_IRQ2_BASE + 5)
  5911. +#define INTERRUPT_CAM0 (ARM_IRQ2_BASE + 6)
  5912. +#define INTERRUPT_CAM1 (ARM_IRQ2_BASE + 7)
  5913. +#define INTERRUPT_HDMI0 (ARM_IRQ2_BASE + 8)
  5914. +#define INTERRUPT_HDMI1 (ARM_IRQ2_BASE + 9)
  5915. +#define INTERRUPT_PIXELVALVE1 (ARM_IRQ2_BASE + 10)
  5916. +#define INTERRUPT_I2CSPISLV (ARM_IRQ2_BASE + 11)
  5917. +#define INTERRUPT_DSI1 (ARM_IRQ2_BASE + 12)
  5918. +#define INTERRUPT_PWA0 (ARM_IRQ2_BASE + 13)
  5919. +#define INTERRUPT_PWA1 (ARM_IRQ2_BASE + 14)
  5920. +#define INTERRUPT_CPR (ARM_IRQ2_BASE + 15)
  5921. +#define INTERRUPT_SMI (ARM_IRQ2_BASE + 16)
  5922. +#define INTERRUPT_GPIO0 (ARM_IRQ2_BASE + 17)
  5923. +#define INTERRUPT_GPIO1 (ARM_IRQ2_BASE + 18)
  5924. +#define INTERRUPT_GPIO2 (ARM_IRQ2_BASE + 19)
  5925. +#define INTERRUPT_GPIO3 (ARM_IRQ2_BASE + 20)
  5926. +#define INTERRUPT_VC_I2C (ARM_IRQ2_BASE + 21)
  5927. +#define INTERRUPT_VC_SPI (ARM_IRQ2_BASE + 22)
  5928. +#define INTERRUPT_VC_I2SPCM (ARM_IRQ2_BASE + 23)
  5929. +#define INTERRUPT_VC_SDIO (ARM_IRQ2_BASE + 24)
  5930. +#define INTERRUPT_VC_UART (ARM_IRQ2_BASE + 25)
  5931. +#define INTERRUPT_SLIMBUS (ARM_IRQ2_BASE + 26)
  5932. +#define INTERRUPT_VEC (ARM_IRQ2_BASE + 27)
  5933. +#define INTERRUPT_CPG (ARM_IRQ2_BASE + 28)
  5934. +#define INTERRUPT_RNG (ARM_IRQ2_BASE + 29)
  5935. +#define INTERRUPT_VC_ARASANSDIO (ARM_IRQ2_BASE + 30)
  5936. +#define INTERRUPT_AVSPMON (ARM_IRQ2_BASE + 31)
  5937. +
  5938. +#define ARM_IRQ0_BASE 64
  5939. +#define INTERRUPT_ARM_TIMER (ARM_IRQ0_BASE + 0)
  5940. +#define INTERRUPT_ARM_MAILBOX (ARM_IRQ0_BASE + 1)
  5941. +#define INTERRUPT_ARM_DOORBELL_0 (ARM_IRQ0_BASE + 2)
  5942. +#define INTERRUPT_ARM_DOORBELL_1 (ARM_IRQ0_BASE + 3)
  5943. +#define INTERRUPT_VPU0_HALTED (ARM_IRQ0_BASE + 4)
  5944. +#define INTERRUPT_VPU1_HALTED (ARM_IRQ0_BASE + 5)
  5945. +#define INTERRUPT_ILLEGAL_TYPE0 (ARM_IRQ0_BASE + 6)
  5946. +#define INTERRUPT_ILLEGAL_TYPE1 (ARM_IRQ0_BASE + 7)
  5947. +#define INTERRUPT_PENDING1 (ARM_IRQ0_BASE + 8)
  5948. +#define INTERRUPT_PENDING2 (ARM_IRQ0_BASE + 9)
  5949. +#define INTERRUPT_JPEG (ARM_IRQ0_BASE + 10)
  5950. +#define INTERRUPT_USB (ARM_IRQ0_BASE + 11)
  5951. +#define INTERRUPT_3D (ARM_IRQ0_BASE + 12)
  5952. +#define INTERRUPT_DMA2 (ARM_IRQ0_BASE + 13)
  5953. +#define INTERRUPT_DMA3 (ARM_IRQ0_BASE + 14)
  5954. +#define INTERRUPT_I2C (ARM_IRQ0_BASE + 15)
  5955. +#define INTERRUPT_SPI (ARM_IRQ0_BASE + 16)
  5956. +#define INTERRUPT_I2SPCM (ARM_IRQ0_BASE + 17)
  5957. +#define INTERRUPT_SDIO (ARM_IRQ0_BASE + 18)
  5958. +#define INTERRUPT_UART (ARM_IRQ0_BASE + 19)
  5959. +#define INTERRUPT_ARASANSDIO (ARM_IRQ0_BASE + 20)
  5960. +
  5961. +#define MAXIRQNUM (32 + 32 + 20)
  5962. +#define MAXFIQNUM (32 + 32 + 20)
  5963. +
  5964. +#define MAX_TIMER 2
  5965. +#define MAX_PERIOD 699050
  5966. +#define TICKS_PER_uSEC 1
  5967. +
  5968. +/*
  5969. + * These are useconds NOT ticks.
  5970. + *
  5971. + */
  5972. +#define mSEC_1 1000
  5973. +#define mSEC_5 (mSEC_1 * 5)
  5974. +#define mSEC_10 (mSEC_1 * 10)
  5975. +#define mSEC_25 (mSEC_1 * 25)
  5976. +#define SEC_1 (mSEC_1 * 1000)
  5977. +
  5978. +/*
  5979. + * Watchdog
  5980. + */
  5981. +#define PM_RSTC (PM_BASE+0x1c)
  5982. +#define PM_RSTS (PM_BASE+0x20)
  5983. +#define PM_WDOG (PM_BASE+0x24)
  5984. +
  5985. +#define PM_WDOG_RESET 0000000000
  5986. +#define PM_PASSWORD 0x5a000000
  5987. +#define PM_WDOG_TIME_SET 0x000fffff
  5988. +#define PM_RSTC_WRCFG_CLR 0xffffffcf
  5989. +#define PM_RSTC_WRCFG_SET 0x00000030
  5990. +#define PM_RSTC_WRCFG_FULL_RESET 0x00000020
  5991. +#define PM_RSTC_RESET 0x00000102
  5992. +
  5993. +#define PM_RSTS_HADPOR_SET 0x00001000
  5994. +#define PM_RSTS_HADSRH_SET 0x00000400
  5995. +#define PM_RSTS_HADSRF_SET 0x00000200
  5996. +#define PM_RSTS_HADSRQ_SET 0x00000100
  5997. +#define PM_RSTS_HADWRH_SET 0x00000040
  5998. +#define PM_RSTS_HADWRF_SET 0x00000020
  5999. +#define PM_RSTS_HADWRQ_SET 0x00000010
  6000. +#define PM_RSTS_HADDRH_SET 0x00000004
  6001. +#define PM_RSTS_HADDRF_SET 0x00000002
  6002. +#define PM_RSTS_HADDRQ_SET 0x00000001
  6003. +
  6004. +#define UART0_CLOCK 3000000
  6005. +
  6006. +#endif
  6007. +
  6008. +/* END */
  6009. diff -Nur linux-3.12.26.orig/arch/arm/mach-bcm2708/include/mach/power.h linux-3.12.26/arch/arm/mach-bcm2708/include/mach/power.h
  6010. --- linux-3.12.26.orig/arch/arm/mach-bcm2708/include/mach/power.h 1970-01-01 01:00:00.000000000 +0100
  6011. +++ linux-3.12.26/arch/arm/mach-bcm2708/include/mach/power.h 2014-08-06 16:50:13.869957407 +0200
  6012. @@ -0,0 +1,26 @@
  6013. +/*
  6014. + * linux/arch/arm/mach-bcm2708/power.h
  6015. + *
  6016. + * Copyright (C) 2010 Broadcom
  6017. + *
  6018. + * This program is free software; you can redistribute it and/or modify
  6019. + * it under the terms of the GNU General Public License version 2 as
  6020. + * published by the Free Software Foundation.
  6021. + *
  6022. + * This device provides a shared mechanism for controlling the power to
  6023. + * VideoCore subsystems.
  6024. + */
  6025. +
  6026. +#ifndef _MACH_BCM2708_POWER_H
  6027. +#define _MACH_BCM2708_POWER_H
  6028. +
  6029. +#include <linux/types.h>
  6030. +#include <mach/arm_power.h>
  6031. +
  6032. +typedef unsigned int BCM_POWER_HANDLE_T;
  6033. +
  6034. +extern int bcm_power_open(BCM_POWER_HANDLE_T *handle);
  6035. +extern int bcm_power_request(BCM_POWER_HANDLE_T handle, uint32_t request);
  6036. +extern int bcm_power_close(BCM_POWER_HANDLE_T handle);
  6037. +
  6038. +#endif
  6039. diff -Nur linux-3.12.26.orig/arch/arm/mach-bcm2708/include/mach/system.h linux-3.12.26/arch/arm/mach-bcm2708/include/mach/system.h
  6040. --- linux-3.12.26.orig/arch/arm/mach-bcm2708/include/mach/system.h 1970-01-01 01:00:00.000000000 +0100
  6041. +++ linux-3.12.26/arch/arm/mach-bcm2708/include/mach/system.h 2014-08-06 16:50:13.869957407 +0200
  6042. @@ -0,0 +1,38 @@
  6043. +/*
  6044. + * arch/arm/mach-bcm2708/include/mach/system.h
  6045. + *
  6046. + * Copyright (C) 2010 Broadcom
  6047. + * Copyright (C) 2003 ARM Limited
  6048. + * Copyright (C) 2000 Deep Blue Solutions Ltd
  6049. + *
  6050. + * This program is free software; you can redistribute it and/or modify
  6051. + * it under the terms of the GNU General Public License as published by
  6052. + * the Free Software Foundation; either version 2 of the License, or
  6053. + * (at your option) any later version.
  6054. + *
  6055. + * This program is distributed in the hope that it will be useful,
  6056. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6057. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6058. + * GNU General Public License for more details.
  6059. + *
  6060. + * You should have received a copy of the GNU General Public License
  6061. + * along with this program; if not, write to the Free Software
  6062. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6063. + */
  6064. +#ifndef __ASM_ARCH_SYSTEM_H
  6065. +#define __ASM_ARCH_SYSTEM_H
  6066. +
  6067. +#include <linux/io.h>
  6068. +#include <mach/hardware.h>
  6069. +#include <mach/platform.h>
  6070. +
  6071. +static inline void arch_idle(void)
  6072. +{
  6073. + /*
  6074. + * This should do all the clock switching
  6075. + * and wait for interrupt tricks
  6076. + */
  6077. + cpu_do_idle();
  6078. +}
  6079. +
  6080. +#endif
  6081. diff -Nur linux-3.12.26.orig/arch/arm/mach-bcm2708/include/mach/timex.h linux-3.12.26/arch/arm/mach-bcm2708/include/mach/timex.h
  6082. --- linux-3.12.26.orig/arch/arm/mach-bcm2708/include/mach/timex.h 1970-01-01 01:00:00.000000000 +0100
  6083. +++ linux-3.12.26/arch/arm/mach-bcm2708/include/mach/timex.h 2014-08-06 16:50:13.873957439 +0200
  6084. @@ -0,0 +1,23 @@
  6085. +/*
  6086. + * arch/arm/mach-bcm2708/include/mach/timex.h
  6087. + *
  6088. + * BCM2708 sysem clock frequency
  6089. + *
  6090. + * Copyright (C) 2010 Broadcom
  6091. + *
  6092. + * This program is free software; you can redistribute it and/or modify
  6093. + * it under the terms of the GNU General Public License as published by
  6094. + * the Free Software Foundation; either version 2 of the License, or
  6095. + * (at your option) any later version.
  6096. + *
  6097. + * This program is distributed in the hope that it will be useful,
  6098. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6099. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6100. + * GNU General Public License for more details.
  6101. + *
  6102. + * You should have received a copy of the GNU General Public License
  6103. + * along with this program; if not, write to the Free Software
  6104. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6105. + */
  6106. +
  6107. +#define CLOCK_TICK_RATE (1000000)
  6108. diff -Nur linux-3.12.26.orig/arch/arm/mach-bcm2708/include/mach/uncompress.h linux-3.12.26/arch/arm/mach-bcm2708/include/mach/uncompress.h
  6109. --- linux-3.12.26.orig/arch/arm/mach-bcm2708/include/mach/uncompress.h 1970-01-01 01:00:00.000000000 +0100
  6110. +++ linux-3.12.26/arch/arm/mach-bcm2708/include/mach/uncompress.h 2014-08-06 16:50:13.873957439 +0200
  6111. @@ -0,0 +1,84 @@
  6112. +/*
  6113. + * arch/arm/mach-bcn2708/include/mach/uncompress.h
  6114. + *
  6115. + * Copyright (C) 2010 Broadcom
  6116. + * Copyright (C) 2003 ARM Limited
  6117. + *
  6118. + * This program is free software; you can redistribute it and/or modify
  6119. + * it under the terms of the GNU General Public License as published by
  6120. + * the Free Software Foundation; either version 2 of the License, or
  6121. + * (at your option) any later version.
  6122. + *
  6123. + * This program is distributed in the hope that it will be useful,
  6124. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6125. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6126. + * GNU General Public License for more details.
  6127. + *
  6128. + * You should have received a copy of the GNU General Public License
  6129. + * along with this program; if not, write to the Free Software
  6130. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6131. + */
  6132. +
  6133. +#include <linux/io.h>
  6134. +#include <linux/amba/serial.h>
  6135. +#include <mach/hardware.h>
  6136. +
  6137. +#define UART_BAUD 115200
  6138. +
  6139. +#define BCM2708_UART_DR __io(UART0_BASE + UART01x_DR)
  6140. +#define BCM2708_UART_FR __io(UART0_BASE + UART01x_FR)
  6141. +#define BCM2708_UART_IBRD __io(UART0_BASE + UART011_IBRD)
  6142. +#define BCM2708_UART_FBRD __io(UART0_BASE + UART011_FBRD)
  6143. +#define BCM2708_UART_LCRH __io(UART0_BASE + UART011_LCRH)
  6144. +#define BCM2708_UART_CR __io(UART0_BASE + UART011_CR)
  6145. +
  6146. +/*
  6147. + * This does not append a newline
  6148. + */
  6149. +static inline void putc(int c)
  6150. +{
  6151. + while (__raw_readl(BCM2708_UART_FR) & UART01x_FR_TXFF)
  6152. + barrier();
  6153. +
  6154. + __raw_writel(c, BCM2708_UART_DR);
  6155. +}
  6156. +
  6157. +static inline void flush(void)
  6158. +{
  6159. + int fr;
  6160. +
  6161. + do {
  6162. + fr = __raw_readl(BCM2708_UART_FR);
  6163. + barrier();
  6164. + } while ((fr & (UART011_FR_TXFE | UART01x_FR_BUSY)) != UART011_FR_TXFE);
  6165. +}
  6166. +
  6167. +static inline void arch_decomp_setup(void)
  6168. +{
  6169. + int temp, div, rem, frac;
  6170. +
  6171. + temp = 16 * UART_BAUD;
  6172. + div = UART0_CLOCK / temp;
  6173. + rem = UART0_CLOCK % temp;
  6174. + temp = (8 * rem) / UART_BAUD;
  6175. + frac = (temp >> 1) + (temp & 1);
  6176. +
  6177. + /* Make sure the UART is disabled before we start */
  6178. + __raw_writel(0, BCM2708_UART_CR);
  6179. +
  6180. + /* Set the baud rate */
  6181. + __raw_writel(div, BCM2708_UART_IBRD);
  6182. + __raw_writel(frac, BCM2708_UART_FBRD);
  6183. +
  6184. + /* Set the UART to 8n1, FIFO enabled */
  6185. + __raw_writel(UART01x_LCRH_WLEN_8 | UART01x_LCRH_FEN, BCM2708_UART_LCRH);
  6186. +
  6187. + /* Enable the UART */
  6188. + __raw_writel(UART01x_CR_UARTEN | UART011_CR_TXE | UART011_CR_RXE,
  6189. + BCM2708_UART_CR);
  6190. +}
  6191. +
  6192. +/*
  6193. + * nothing to do
  6194. + */
  6195. +#define arch_decomp_wdog()
  6196. diff -Nur linux-3.12.26.orig/arch/arm/mach-bcm2708/include/mach/vcio.h linux-3.12.26/arch/arm/mach-bcm2708/include/mach/vcio.h
  6197. --- linux-3.12.26.orig/arch/arm/mach-bcm2708/include/mach/vcio.h 1970-01-01 01:00:00.000000000 +0100
  6198. +++ linux-3.12.26/arch/arm/mach-bcm2708/include/mach/vcio.h 2014-08-06 16:50:13.873957439 +0200
  6199. @@ -0,0 +1,141 @@
  6200. +/*
  6201. + * arch/arm/mach-bcm2708/include/mach/vcio.h
  6202. + *
  6203. + * Copyright (C) 2010 Broadcom
  6204. + *
  6205. + * This program is free software; you can redistribute it and/or modify
  6206. + * it under the terms of the GNU General Public License as published by
  6207. + * the Free Software Foundation; either version 2 of the License, or
  6208. + * (at your option) any later version.
  6209. + *
  6210. + * This program is distributed in the hope that it will be useful,
  6211. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6212. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6213. + * GNU General Public License for more details.
  6214. + *
  6215. + * You should have received a copy of the GNU General Public License
  6216. + * along with this program; if not, write to the Free Software
  6217. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6218. + */
  6219. +#ifndef _MACH_BCM2708_VCIO_H
  6220. +#define _MACH_BCM2708_VCIO_H
  6221. +
  6222. +/* Routines to handle I/O via the VideoCore "ARM control" registers
  6223. + * (semaphores, doorbells, mailboxes)
  6224. + */
  6225. +
  6226. +#define BCM_VCIO_DRIVER_NAME "bcm2708_vcio"
  6227. +
  6228. +/* Constants shared with the ARM identifying separate mailbox channels */
  6229. +#define MBOX_CHAN_POWER 0 /* for use by the power management interface */
  6230. +#define MBOX_CHAN_FB 1 /* for use by the frame buffer */
  6231. +#define MBOX_CHAN_VCHIQ 3 /* for use by the VCHIQ interface */
  6232. +#define MBOX_CHAN_PROPERTY 8 /* for use by the property channel */
  6233. +#define MBOX_CHAN_COUNT 9
  6234. +
  6235. +/* Mailbox property tags */
  6236. +enum {
  6237. + VCMSG_PROPERTY_END = 0x00000000,
  6238. + VCMSG_GET_FIRMWARE_REVISION = 0x00000001,
  6239. + VCMSG_GET_BOARD_MODEL = 0x00010001,
  6240. + VCMSG_GET_BOARD_REVISION = 0x00020002,
  6241. + VCMSG_GET_BOARD_MAC_ADDRESS = 0x00020003,
  6242. + VCMSG_GET_BOARD_SERIAL = 0x00020004,
  6243. + VCMSG_GET_ARM_MEMORY = 0x00020005,
  6244. + VCMSG_GET_VC_MEMORY = 0x00020006,
  6245. + VCMSG_GET_CLOCKS = 0x00020007,
  6246. + VCMSG_GET_COMMAND_LINE = 0x00050001,
  6247. + VCMSG_GET_DMA_CHANNELS = 0x00060001,
  6248. + VCMSG_GET_POWER_STATE = 0x00020001,
  6249. + VCMSG_GET_TIMING = 0x00020002,
  6250. + VCMSG_SET_POWER_STATE = 0x00028001,
  6251. + VCMSG_GET_CLOCK_STATE = 0x00030001,
  6252. + VCMSG_SET_CLOCK_STATE = 0x00038001,
  6253. + VCMSG_GET_CLOCK_RATE = 0x00030002,
  6254. + VCMSG_SET_CLOCK_RATE = 0x00038002,
  6255. + VCMSG_GET_VOLTAGE = 0x00030003,
  6256. + VCMSG_SET_VOLTAGE = 0x00038003,
  6257. + VCMSG_GET_MAX_CLOCK = 0x00030004,
  6258. + VCMSG_GET_MAX_VOLTAGE = 0x00030005,
  6259. + VCMSG_GET_TEMPERATURE = 0x00030006,
  6260. + VCMSG_GET_MIN_CLOCK = 0x00030007,
  6261. + VCMSG_GET_MIN_VOLTAGE = 0x00030008,
  6262. + VCMSG_GET_TURBO = 0x00030009,
  6263. + VCMSG_SET_TURBO = 0x00038009,
  6264. + VCMSG_SET_ALLOCATE_BUFFER = 0x00040001,
  6265. + VCMSG_SET_RELEASE_BUFFER = 0x00048001,
  6266. + VCMSG_SET_BLANK_SCREEN = 0x00040002,
  6267. + VCMSG_TST_BLANK_SCREEN = 0x00044002,
  6268. + VCMSG_GET_PHYSICAL_WIDTH_HEIGHT = 0x00040003,
  6269. + VCMSG_TST_PHYSICAL_WIDTH_HEIGHT = 0x00044003,
  6270. + VCMSG_SET_PHYSICAL_WIDTH_HEIGHT = 0x00048003,
  6271. + VCMSG_GET_VIRTUAL_WIDTH_HEIGHT = 0x00040004,
  6272. + VCMSG_TST_VIRTUAL_WIDTH_HEIGHT = 0x00044004,
  6273. + VCMSG_SET_VIRTUAL_WIDTH_HEIGHT = 0x00048004,
  6274. + VCMSG_GET_DEPTH = 0x00040005,
  6275. + VCMSG_TST_DEPTH = 0x00044005,
  6276. + VCMSG_SET_DEPTH = 0x00048005,
  6277. + VCMSG_GET_PIXEL_ORDER = 0x00040006,
  6278. + VCMSG_TST_PIXEL_ORDER = 0x00044006,
  6279. + VCMSG_SET_PIXEL_ORDER = 0x00048006,
  6280. + VCMSG_GET_ALPHA_MODE = 0x00040007,
  6281. + VCMSG_TST_ALPHA_MODE = 0x00044007,
  6282. + VCMSG_SET_ALPHA_MODE = 0x00048007,
  6283. + VCMSG_GET_PITCH = 0x00040008,
  6284. + VCMSG_TST_PITCH = 0x00044008,
  6285. + VCMSG_SET_PITCH = 0x00048008,
  6286. + VCMSG_GET_VIRTUAL_OFFSET = 0x00040009,
  6287. + VCMSG_TST_VIRTUAL_OFFSET = 0x00044009,
  6288. + VCMSG_SET_VIRTUAL_OFFSET = 0x00048009,
  6289. + VCMSG_GET_OVERSCAN = 0x0004000a,
  6290. + VCMSG_TST_OVERSCAN = 0x0004400a,
  6291. + VCMSG_SET_OVERSCAN = 0x0004800a,
  6292. + VCMSG_GET_PALETTE = 0x0004000b,
  6293. + VCMSG_TST_PALETTE = 0x0004400b,
  6294. + VCMSG_SET_PALETTE = 0x0004800b,
  6295. + VCMSG_GET_LAYER = 0x0004000c,
  6296. + VCMSG_TST_LAYER = 0x0004400c,
  6297. + VCMSG_SET_LAYER = 0x0004800c,
  6298. + VCMSG_GET_TRANSFORM = 0x0004000d,
  6299. + VCMSG_TST_TRANSFORM = 0x0004400d,
  6300. + VCMSG_SET_TRANSFORM = 0x0004800d,
  6301. +};
  6302. +
  6303. +extern int /*rc*/ bcm_mailbox_read(unsigned chan, uint32_t *data28);
  6304. +extern int /*rc*/ bcm_mailbox_write(unsigned chan, uint32_t data28);
  6305. +extern int /*rc*/ bcm_mailbox_property(void *data, int size);
  6306. +
  6307. +#include <linux/ioctl.h>
  6308. +
  6309. +/*
  6310. + * The major device number. We can't rely on dynamic
  6311. + * registration any more, because ioctls need to know
  6312. + * it.
  6313. + */
  6314. +#define MAJOR_NUM 100
  6315. +
  6316. +/*
  6317. + * Set the message of the device driver
  6318. + */
  6319. +#define IOCTL_MBOX_PROPERTY _IOWR(MAJOR_NUM, 0, char *)
  6320. +/*
  6321. + * _IOWR means that we're creating an ioctl command
  6322. + * number for passing information from a user process
  6323. + * to the kernel module and from the kernel module to user process
  6324. + *
  6325. + * The first arguments, MAJOR_NUM, is the major device
  6326. + * number we're using.
  6327. + *
  6328. + * The second argument is the number of the command
  6329. + * (there could be several with different meanings).
  6330. + *
  6331. + * The third argument is the type we want to get from
  6332. + * the process to the kernel.
  6333. + */
  6334. +
  6335. +/*
  6336. + * The name of the device file
  6337. + */
  6338. +#define DEVICE_FILE_NAME "char_dev"
  6339. +
  6340. +#endif
  6341. diff -Nur linux-3.12.26.orig/arch/arm/mach-bcm2708/include/mach/vc_mem.h linux-3.12.26/arch/arm/mach-bcm2708/include/mach/vc_mem.h
  6342. --- linux-3.12.26.orig/arch/arm/mach-bcm2708/include/mach/vc_mem.h 1970-01-01 01:00:00.000000000 +0100
  6343. +++ linux-3.12.26/arch/arm/mach-bcm2708/include/mach/vc_mem.h 2014-08-06 16:50:13.873957439 +0200
  6344. @@ -0,0 +1,35 @@
  6345. +/*****************************************************************************
  6346. +* Copyright 2010 - 2011 Broadcom Corporation. All rights reserved.
  6347. +*
  6348. +* Unless you and Broadcom execute a separate written software license
  6349. +* agreement governing use of this software, this software is licensed to you
  6350. +* under the terms of the GNU General Public License version 2, available at
  6351. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  6352. +*
  6353. +* Notwithstanding the above, under no circumstances may you combine this
  6354. +* software in any way with any other Broadcom software provided under a
  6355. +* license other than the GPL, without Broadcom's express prior written
  6356. +* consent.
  6357. +*****************************************************************************/
  6358. +
  6359. +#if !defined( VC_MEM_H )
  6360. +#define VC_MEM_H
  6361. +
  6362. +#include <linux/ioctl.h>
  6363. +
  6364. +#define VC_MEM_IOC_MAGIC 'v'
  6365. +
  6366. +#define VC_MEM_IOC_MEM_PHYS_ADDR _IOR( VC_MEM_IOC_MAGIC, 0, unsigned long )
  6367. +#define VC_MEM_IOC_MEM_SIZE _IOR( VC_MEM_IOC_MAGIC, 1, unsigned int )
  6368. +#define VC_MEM_IOC_MEM_BASE _IOR( VC_MEM_IOC_MAGIC, 2, unsigned int )
  6369. +#define VC_MEM_IOC_MEM_LOAD _IOR( VC_MEM_IOC_MAGIC, 3, unsigned int )
  6370. +
  6371. +#if defined( __KERNEL__ )
  6372. +#define VC_MEM_TO_ARM_ADDR_MASK 0x3FFFFFFF
  6373. +
  6374. +extern unsigned long mm_vc_mem_phys_addr;
  6375. +extern unsigned int mm_vc_mem_size;
  6376. +extern int vc_mem_get_current_size( void );
  6377. +#endif
  6378. +
  6379. +#endif /* VC_MEM_H */
  6380. diff -Nur linux-3.12.26.orig/arch/arm/mach-bcm2708/include/mach/vmalloc.h linux-3.12.26/arch/arm/mach-bcm2708/include/mach/vmalloc.h
  6381. --- linux-3.12.26.orig/arch/arm/mach-bcm2708/include/mach/vmalloc.h 1970-01-01 01:00:00.000000000 +0100
  6382. +++ linux-3.12.26/arch/arm/mach-bcm2708/include/mach/vmalloc.h 2014-08-06 16:50:13.893957595 +0200
  6383. @@ -0,0 +1,20 @@
  6384. +/*
  6385. + * arch/arm/mach-bcm2708/include/mach/vmalloc.h
  6386. + *
  6387. + * Copyright (C) 2010 Broadcom
  6388. + *
  6389. + * This program is free software; you can redistribute it and/or modify
  6390. + * it under the terms of the GNU General Public License as published by
  6391. + * the Free Software Foundation; either version 2 of the License, or
  6392. + * (at your option) any later version.
  6393. + *
  6394. + * This program is distributed in the hope that it will be useful,
  6395. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6396. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6397. + * GNU General Public License for more details.
  6398. + *
  6399. + * You should have received a copy of the GNU General Public License
  6400. + * along with this program; if not, write to the Free Software
  6401. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6402. + */
  6403. +#define VMALLOC_END (0xe8000000)
  6404. diff -Nur linux-3.12.26.orig/arch/arm/mach-bcm2708/Kconfig linux-3.12.26/arch/arm/mach-bcm2708/Kconfig
  6405. --- linux-3.12.26.orig/arch/arm/mach-bcm2708/Kconfig 1970-01-01 01:00:00.000000000 +0100
  6406. +++ linux-3.12.26/arch/arm/mach-bcm2708/Kconfig 2014-08-06 16:50:13.893957595 +0200
  6407. @@ -0,0 +1,41 @@
  6408. +menu "Broadcom BCM2708 Implementations"
  6409. + depends on ARCH_BCM2708
  6410. +
  6411. +config MACH_BCM2708
  6412. + bool "Broadcom BCM2708 Development Platform"
  6413. + select NEED_MACH_MEMORY_H
  6414. + select NEED_MACH_IO_H
  6415. + select CPU_V6
  6416. + help
  6417. + Include support for the Broadcom(R) BCM2708 platform.
  6418. +
  6419. +config BCM2708_GPIO
  6420. + bool "BCM2708 gpio support"
  6421. + depends on MACH_BCM2708
  6422. + select ARCH_REQUIRE_GPIOLIB
  6423. + default y
  6424. + help
  6425. + Include support for the Broadcom(R) BCM2708 gpio.
  6426. +
  6427. +config BCM2708_VCMEM
  6428. + bool "Videocore Memory"
  6429. + depends on MACH_BCM2708
  6430. + default y
  6431. + help
  6432. + Helper for videocore memory access and total size allocation.
  6433. +
  6434. +config BCM2708_NOL2CACHE
  6435. + bool "Videocore L2 cache disable"
  6436. + depends on MACH_BCM2708
  6437. + default n
  6438. + help
  6439. + Do not allow ARM to use GPU's L2 cache. Requires disable_l2cache in config.txt.
  6440. +
  6441. +config BCM2708_SPIDEV
  6442. + bool "Bind spidev to SPI0 master"
  6443. + depends on MACH_BCM2708
  6444. + depends on SPI
  6445. + default y
  6446. + help
  6447. + Binds spidev driver to the SPI0 master
  6448. +endmenu
  6449. diff -Nur linux-3.12.26.orig/arch/arm/mach-bcm2708/Makefile linux-3.12.26/arch/arm/mach-bcm2708/Makefile
  6450. --- linux-3.12.26.orig/arch/arm/mach-bcm2708/Makefile 1970-01-01 01:00:00.000000000 +0100
  6451. +++ linux-3.12.26/arch/arm/mach-bcm2708/Makefile 2014-08-06 16:50:13.893957595 +0200
  6452. @@ -0,0 +1,7 @@
  6453. +#
  6454. +# Makefile for the linux kernel.
  6455. +#
  6456. +
  6457. +obj-$(CONFIG_MACH_BCM2708) += clock.o bcm2708.o armctrl.o vcio.o power.o dma.o
  6458. +obj-$(CONFIG_BCM2708_GPIO) += bcm2708_gpio.o
  6459. +obj-$(CONFIG_BCM2708_VCMEM) += vc_mem.o
  6460. diff -Nur linux-3.12.26.orig/arch/arm/mach-bcm2708/Makefile.boot linux-3.12.26/arch/arm/mach-bcm2708/Makefile.boot
  6461. --- linux-3.12.26.orig/arch/arm/mach-bcm2708/Makefile.boot 1970-01-01 01:00:00.000000000 +0100
  6462. +++ linux-3.12.26/arch/arm/mach-bcm2708/Makefile.boot 2014-08-06 16:50:13.893957595 +0200
  6463. @@ -0,0 +1,3 @@
  6464. + zreladdr-y := 0x00008000
  6465. +params_phys-y := 0x00000100
  6466. +initrd_phys-y := 0x00800000
  6467. diff -Nur linux-3.12.26.orig/arch/arm/mach-bcm2708/power.c linux-3.12.26/arch/arm/mach-bcm2708/power.c
  6468. --- linux-3.12.26.orig/arch/arm/mach-bcm2708/power.c 1970-01-01 01:00:00.000000000 +0100
  6469. +++ linux-3.12.26/arch/arm/mach-bcm2708/power.c 2014-08-06 16:50:13.897957627 +0200
  6470. @@ -0,0 +1,194 @@
  6471. +/*
  6472. + * linux/arch/arm/mach-bcm2708/power.c
  6473. + *
  6474. + * Copyright (C) 2010 Broadcom
  6475. + *
  6476. + * This program is free software; you can redistribute it and/or modify
  6477. + * it under the terms of the GNU General Public License version 2 as
  6478. + * published by the Free Software Foundation.
  6479. + *
  6480. + * This device provides a shared mechanism for controlling the power to
  6481. + * VideoCore subsystems.
  6482. + */
  6483. +
  6484. +#include <linux/module.h>
  6485. +#include <linux/semaphore.h>
  6486. +#include <linux/bug.h>
  6487. +#include <mach/power.h>
  6488. +#include <mach/vcio.h>
  6489. +#include <mach/arm_power.h>
  6490. +
  6491. +#define DRIVER_NAME "bcm2708_power"
  6492. +
  6493. +#define BCM_POWER_MAXCLIENTS 4
  6494. +#define BCM_POWER_NOCLIENT (1<<31)
  6495. +
  6496. +/* Some drivers expect there devices to be permanently powered */
  6497. +#define BCM_POWER_ALWAYS_ON (BCM_POWER_USB)
  6498. +
  6499. +#if 1
  6500. +#define DPRINTK printk
  6501. +#else
  6502. +#define DPRINTK if (0) printk
  6503. +#endif
  6504. +
  6505. +struct state_struct {
  6506. + uint32_t global_request;
  6507. + uint32_t client_request[BCM_POWER_MAXCLIENTS];
  6508. + struct semaphore client_mutex;
  6509. + struct semaphore mutex;
  6510. +} g_state;
  6511. +
  6512. +int bcm_power_open(BCM_POWER_HANDLE_T *handle)
  6513. +{
  6514. + BCM_POWER_HANDLE_T i;
  6515. + int ret = -EBUSY;
  6516. +
  6517. + down(&g_state.client_mutex);
  6518. +
  6519. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++) {
  6520. + if (g_state.client_request[i] == BCM_POWER_NOCLIENT) {
  6521. + g_state.client_request[i] = BCM_POWER_NONE;
  6522. + *handle = i;
  6523. + ret = 0;
  6524. + break;
  6525. + }
  6526. + }
  6527. +
  6528. + up(&g_state.client_mutex);
  6529. +
  6530. + DPRINTK("bcm_power_open() -> %d\n", *handle);
  6531. +
  6532. + return ret;
  6533. +}
  6534. +EXPORT_SYMBOL_GPL(bcm_power_open);
  6535. +
  6536. +int bcm_power_request(BCM_POWER_HANDLE_T handle, uint32_t request)
  6537. +{
  6538. + int rc = 0;
  6539. +
  6540. + DPRINTK("bcm_power_request(%d, %x)\n", handle, request);
  6541. +
  6542. + if ((handle < BCM_POWER_MAXCLIENTS) &&
  6543. + (g_state.client_request[handle] != BCM_POWER_NOCLIENT)) {
  6544. + if (down_interruptible(&g_state.mutex) != 0) {
  6545. + DPRINTK("bcm_power_request -> interrupted\n");
  6546. + return -EINTR;
  6547. + }
  6548. +
  6549. + if (request != g_state.client_request[handle]) {
  6550. + uint32_t others_request = 0;
  6551. + uint32_t global_request;
  6552. + BCM_POWER_HANDLE_T i;
  6553. +
  6554. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++) {
  6555. + if (i != handle)
  6556. + others_request |=
  6557. + g_state.client_request[i];
  6558. + }
  6559. + others_request &= ~BCM_POWER_NOCLIENT;
  6560. +
  6561. + global_request = request | others_request;
  6562. + if (global_request != g_state.global_request) {
  6563. + uint32_t actual;
  6564. +
  6565. + /* Send a request to VideoCore */
  6566. + bcm_mailbox_write(MBOX_CHAN_POWER,
  6567. + global_request << 4);
  6568. +
  6569. + /* Wait for a response during power-up */
  6570. + if (global_request & ~g_state.global_request) {
  6571. + rc = bcm_mailbox_read(MBOX_CHAN_POWER,
  6572. + &actual);
  6573. + DPRINTK
  6574. + ("bcm_mailbox_read -> %08x, %d\n",
  6575. + actual, rc);
  6576. + actual >>= 4;
  6577. + } else {
  6578. + rc = 0;
  6579. + actual = global_request;
  6580. + }
  6581. +
  6582. + if (rc == 0) {
  6583. + if (actual != global_request) {
  6584. + printk(KERN_ERR
  6585. + "%s: prev global %x, new global %x, actual %x, request %x, others_request %x\n",
  6586. + __func__,
  6587. + g_state.global_request,
  6588. + global_request, actual, request, others_request);
  6589. + /* A failure */
  6590. + BUG_ON((others_request & actual)
  6591. + != others_request);
  6592. + request &= actual;
  6593. + rc = -EIO;
  6594. + }
  6595. +
  6596. + g_state.global_request = actual;
  6597. + g_state.client_request[handle] =
  6598. + request;
  6599. + }
  6600. + }
  6601. + }
  6602. + up(&g_state.mutex);
  6603. + } else {
  6604. + rc = -EINVAL;
  6605. + }
  6606. + DPRINTK("bcm_power_request -> %d\n", rc);
  6607. + return rc;
  6608. +}
  6609. +EXPORT_SYMBOL_GPL(bcm_power_request);
  6610. +
  6611. +int bcm_power_close(BCM_POWER_HANDLE_T handle)
  6612. +{
  6613. + int rc;
  6614. +
  6615. + DPRINTK("bcm_power_close(%d)\n", handle);
  6616. +
  6617. + rc = bcm_power_request(handle, BCM_POWER_NONE);
  6618. + if (rc == 0)
  6619. + g_state.client_request[handle] = BCM_POWER_NOCLIENT;
  6620. +
  6621. + return rc;
  6622. +}
  6623. +EXPORT_SYMBOL_GPL(bcm_power_close);
  6624. +
  6625. +static int __init bcm_power_init(void)
  6626. +{
  6627. +#if defined(BCM_POWER_ALWAYS_ON)
  6628. + BCM_POWER_HANDLE_T always_on_handle;
  6629. +#endif
  6630. + int rc = 0;
  6631. + int i;
  6632. +
  6633. + printk(KERN_INFO "bcm_power: Broadcom power driver\n");
  6634. + bcm_mailbox_write(MBOX_CHAN_POWER, 0);
  6635. +
  6636. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++)
  6637. + g_state.client_request[i] = BCM_POWER_NOCLIENT;
  6638. +
  6639. + sema_init(&g_state.client_mutex, 1);
  6640. + sema_init(&g_state.mutex, 1);
  6641. +
  6642. + g_state.global_request = 0;
  6643. +
  6644. +#if defined(BCM_POWER_ALWAYS_ON)
  6645. + if (BCM_POWER_ALWAYS_ON) {
  6646. + bcm_power_open(&always_on_handle);
  6647. + bcm_power_request(always_on_handle, BCM_POWER_ALWAYS_ON);
  6648. + }
  6649. +#endif
  6650. +
  6651. + return rc;
  6652. +}
  6653. +
  6654. +static void __exit bcm_power_exit(void)
  6655. +{
  6656. + bcm_mailbox_write(MBOX_CHAN_POWER, 0);
  6657. +}
  6658. +
  6659. +arch_initcall(bcm_power_init); /* Initialize early */
  6660. +module_exit(bcm_power_exit);
  6661. +
  6662. +MODULE_AUTHOR("Phil Elwell");
  6663. +MODULE_DESCRIPTION("Interface to BCM2708 power management");
  6664. +MODULE_LICENSE("GPL");
  6665. diff -Nur linux-3.12.26.orig/arch/arm/mach-bcm2708/vcio.c linux-3.12.26/arch/arm/mach-bcm2708/vcio.c
  6666. --- linux-3.12.26.orig/arch/arm/mach-bcm2708/vcio.c 1970-01-01 01:00:00.000000000 +0100
  6667. +++ linux-3.12.26/arch/arm/mach-bcm2708/vcio.c 2014-08-06 16:50:13.897957627 +0200
  6668. @@ -0,0 +1,474 @@
  6669. +/*
  6670. + * linux/arch/arm/mach-bcm2708/vcio.c
  6671. + *
  6672. + * Copyright (C) 2010 Broadcom
  6673. + *
  6674. + * This program is free software; you can redistribute it and/or modify
  6675. + * it under the terms of the GNU General Public License version 2 as
  6676. + * published by the Free Software Foundation.
  6677. + *
  6678. + * This device provides a shared mechanism for writing to the mailboxes,
  6679. + * semaphores, doorbells etc. that are shared between the ARM and the
  6680. + * VideoCore processor
  6681. + */
  6682. +
  6683. +#if defined(CONFIG_SERIAL_BCM_MBOX_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
  6684. +#define SUPPORT_SYSRQ
  6685. +#endif
  6686. +
  6687. +#include <linux/module.h>
  6688. +#include <linux/console.h>
  6689. +#include <linux/serial_core.h>
  6690. +#include <linux/serial.h>
  6691. +#include <linux/errno.h>
  6692. +#include <linux/device.h>
  6693. +#include <linux/init.h>
  6694. +#include <linux/mm.h>
  6695. +#include <linux/dma-mapping.h>
  6696. +#include <linux/platform_device.h>
  6697. +#include <linux/sysrq.h>
  6698. +#include <linux/delay.h>
  6699. +#include <linux/slab.h>
  6700. +#include <linux/interrupt.h>
  6701. +#include <linux/irq.h>
  6702. +
  6703. +#include <linux/io.h>
  6704. +
  6705. +#include <mach/vcio.h>
  6706. +#include <mach/platform.h>
  6707. +
  6708. +#include <asm/uaccess.h>
  6709. +
  6710. +
  6711. +#define DRIVER_NAME BCM_VCIO_DRIVER_NAME
  6712. +
  6713. +/* ----------------------------------------------------------------------
  6714. + * Mailbox
  6715. + * -------------------------------------------------------------------- */
  6716. +
  6717. +/* offsets from a mail box base address */
  6718. +#define MAIL_WRT 0x00 /* write - and next 4 words */
  6719. +#define MAIL_RD 0x00 /* read - and next 4 words */
  6720. +#define MAIL_POL 0x10 /* read without popping the fifo */
  6721. +#define MAIL_SND 0x14 /* sender ID (bottom two bits) */
  6722. +#define MAIL_STA 0x18 /* status */
  6723. +#define MAIL_CNF 0x1C /* configuration */
  6724. +
  6725. +#define MBOX_MSG(chan, data28) (((data28) & ~0xf) | ((chan) & 0xf))
  6726. +#define MBOX_MSG_LSB(chan, data28) (((data28) << 4) | ((chan) & 0xf))
  6727. +#define MBOX_CHAN(msg) ((msg) & 0xf)
  6728. +#define MBOX_DATA28(msg) ((msg) & ~0xf)
  6729. +#define MBOX_DATA28_LSB(msg) (((uint32_t)msg) >> 4)
  6730. +
  6731. +#define MBOX_MAGIC 0xd0d0c0de
  6732. +
  6733. +struct vc_mailbox {
  6734. + struct device *dev; /* parent device */
  6735. + void __iomem *status;
  6736. + void __iomem *config;
  6737. + void __iomem *read;
  6738. + void __iomem *write;
  6739. + uint32_t msg[MBOX_CHAN_COUNT];
  6740. + struct semaphore sema[MBOX_CHAN_COUNT];
  6741. + uint32_t magic;
  6742. +};
  6743. +
  6744. +static void mbox_init(struct vc_mailbox *mbox_out, struct device *dev,
  6745. + uint32_t addr_mbox)
  6746. +{
  6747. + int i;
  6748. +
  6749. + mbox_out->dev = dev;
  6750. + mbox_out->status = __io_address(addr_mbox + MAIL_STA);
  6751. + mbox_out->config = __io_address(addr_mbox + MAIL_CNF);
  6752. + mbox_out->read = __io_address(addr_mbox + MAIL_RD);
  6753. + /* Write to the other mailbox */
  6754. + mbox_out->write =
  6755. + __io_address((addr_mbox ^ ARM_0_MAIL0_WRT ^ ARM_0_MAIL1_WRT) +
  6756. + MAIL_WRT);
  6757. +
  6758. + for (i = 0; i < MBOX_CHAN_COUNT; i++) {
  6759. + mbox_out->msg[i] = 0;
  6760. + sema_init(&mbox_out->sema[i], 0);
  6761. + }
  6762. +
  6763. + /* Enable the interrupt on data reception */
  6764. + writel(ARM_MC_IHAVEDATAIRQEN, mbox_out->config);
  6765. +
  6766. + mbox_out->magic = MBOX_MAGIC;
  6767. +}
  6768. +
  6769. +static int mbox_write(struct vc_mailbox *mbox, unsigned chan, uint32_t data28)
  6770. +{
  6771. + int rc;
  6772. +
  6773. + if (mbox->magic != MBOX_MAGIC)
  6774. + rc = -EINVAL;
  6775. + else {
  6776. + /* wait for the mailbox FIFO to have some space in it */
  6777. + while (0 != (readl(mbox->status) & ARM_MS_FULL))
  6778. + cpu_relax();
  6779. +
  6780. + writel(MBOX_MSG(chan, data28), mbox->write);
  6781. + rc = 0;
  6782. + }
  6783. + return rc;
  6784. +}
  6785. +
  6786. +static int mbox_read(struct vc_mailbox *mbox, unsigned chan, uint32_t *data28)
  6787. +{
  6788. + int rc;
  6789. +
  6790. + if (mbox->magic != MBOX_MAGIC)
  6791. + rc = -EINVAL;
  6792. + else {
  6793. + down(&mbox->sema[chan]);
  6794. + *data28 = MBOX_DATA28(mbox->msg[chan]);
  6795. + mbox->msg[chan] = 0;
  6796. + rc = 0;
  6797. + }
  6798. + return rc;
  6799. +}
  6800. +
  6801. +static irqreturn_t mbox_irq(int irq, void *dev_id)
  6802. +{
  6803. + /* wait for the mailbox FIFO to have some data in it */
  6804. + struct vc_mailbox *mbox = (struct vc_mailbox *) dev_id;
  6805. + int status = readl(mbox->status);
  6806. + int ret = IRQ_NONE;
  6807. +
  6808. + while (!(status & ARM_MS_EMPTY)) {
  6809. + uint32_t msg = readl(mbox->read);
  6810. + int chan = MBOX_CHAN(msg);
  6811. + if (chan < MBOX_CHAN_COUNT) {
  6812. + if (mbox->msg[chan]) {
  6813. + /* Overflow */
  6814. + printk(KERN_ERR DRIVER_NAME
  6815. + ": mbox chan %d overflow - drop %08x\n",
  6816. + chan, msg);
  6817. + } else {
  6818. + mbox->msg[chan] = (msg | 0xf);
  6819. + up(&mbox->sema[chan]);
  6820. + }
  6821. + } else {
  6822. + printk(KERN_ERR DRIVER_NAME
  6823. + ": invalid channel selector (msg %08x)\n", msg);
  6824. + }
  6825. + ret = IRQ_HANDLED;
  6826. + status = readl(mbox->status);
  6827. + }
  6828. + return ret;
  6829. +}
  6830. +
  6831. +static struct irqaction mbox_irqaction = {
  6832. + .name = "ARM Mailbox IRQ",
  6833. + .flags = IRQF_DISABLED | IRQF_IRQPOLL,
  6834. + .handler = mbox_irq,
  6835. +};
  6836. +
  6837. +/* ----------------------------------------------------------------------
  6838. + * Mailbox Methods
  6839. + * -------------------------------------------------------------------- */
  6840. +
  6841. +static struct device *mbox_dev; /* we assume there's only one! */
  6842. +
  6843. +static int dev_mbox_write(struct device *dev, unsigned chan, uint32_t data28)
  6844. +{
  6845. + int rc;
  6846. +
  6847. + struct vc_mailbox *mailbox = dev_get_drvdata(dev);
  6848. + device_lock(dev);
  6849. + rc = mbox_write(mailbox, chan, data28);
  6850. + device_unlock(dev);
  6851. +
  6852. + return rc;
  6853. +}
  6854. +
  6855. +static int dev_mbox_read(struct device *dev, unsigned chan, uint32_t *data28)
  6856. +{
  6857. + int rc;
  6858. +
  6859. + struct vc_mailbox *mailbox = dev_get_drvdata(dev);
  6860. + device_lock(dev);
  6861. + rc = mbox_read(mailbox, chan, data28);
  6862. + device_unlock(dev);
  6863. +
  6864. + return rc;
  6865. +}
  6866. +
  6867. +extern int bcm_mailbox_write(unsigned chan, uint32_t data28)
  6868. +{
  6869. + if (mbox_dev)
  6870. + return dev_mbox_write(mbox_dev, chan, data28);
  6871. + else
  6872. + return -ENODEV;
  6873. +}
  6874. +EXPORT_SYMBOL_GPL(bcm_mailbox_write);
  6875. +
  6876. +extern int bcm_mailbox_read(unsigned chan, uint32_t *data28)
  6877. +{
  6878. + if (mbox_dev)
  6879. + return dev_mbox_read(mbox_dev, chan, data28);
  6880. + else
  6881. + return -ENODEV;
  6882. +}
  6883. +EXPORT_SYMBOL_GPL(bcm_mailbox_read);
  6884. +
  6885. +static void dev_mbox_register(const char *dev_name, struct device *dev)
  6886. +{
  6887. + mbox_dev = dev;
  6888. +}
  6889. +
  6890. +static int mbox_copy_from_user(void *dst, const void *src, int size)
  6891. +{
  6892. + if ( (uint32_t)src < TASK_SIZE)
  6893. + {
  6894. + return copy_from_user(dst, src, size);
  6895. + }
  6896. + else
  6897. + {
  6898. + memcpy( dst, src, size );
  6899. + return 0;
  6900. + }
  6901. +}
  6902. +
  6903. +static int mbox_copy_to_user(void *dst, const void *src, int size)
  6904. +{
  6905. + if ( (uint32_t)dst < TASK_SIZE)
  6906. + {
  6907. + return copy_to_user(dst, src, size);
  6908. + }
  6909. + else
  6910. + {
  6911. + memcpy( dst, src, size );
  6912. + return 0;
  6913. + }
  6914. +}
  6915. +
  6916. +static DEFINE_MUTEX(mailbox_lock);
  6917. +extern int bcm_mailbox_property(void *data, int size)
  6918. +{
  6919. + uint32_t success;
  6920. + dma_addr_t mem_bus; /* the memory address accessed from videocore */
  6921. + void *mem_kern; /* the memory address accessed from driver */
  6922. + int s = 0;
  6923. +
  6924. + mutex_lock(&mailbox_lock);
  6925. + /* allocate some memory for the messages communicating with GPU */
  6926. + mem_kern = dma_alloc_coherent(NULL, PAGE_ALIGN(size), &mem_bus, GFP_ATOMIC);
  6927. + if (mem_kern) {
  6928. + /* create the message */
  6929. + mbox_copy_from_user(mem_kern, data, size);
  6930. +
  6931. + /* send the message */
  6932. + wmb();
  6933. + s = bcm_mailbox_write(MBOX_CHAN_PROPERTY, (uint32_t)mem_bus);
  6934. + if (s == 0) {
  6935. + s = bcm_mailbox_read(MBOX_CHAN_PROPERTY, &success);
  6936. + }
  6937. + if (s == 0) {
  6938. + /* copy the response */
  6939. + rmb();
  6940. + mbox_copy_to_user(data, mem_kern, size);
  6941. + }
  6942. + dma_free_coherent(NULL, PAGE_ALIGN(size), mem_kern, mem_bus);
  6943. + } else {
  6944. + s = -ENOMEM;
  6945. + }
  6946. + if (s != 0)
  6947. + printk(KERN_ERR DRIVER_NAME ": %s failed (%d)\n", __func__, s);
  6948. +
  6949. + mutex_unlock(&mailbox_lock);
  6950. + return s;
  6951. +}
  6952. +EXPORT_SYMBOL_GPL(bcm_mailbox_property);
  6953. +
  6954. +/* ----------------------------------------------------------------------
  6955. + * Platform Device for Mailbox
  6956. + * -------------------------------------------------------------------- */
  6957. +
  6958. +/*
  6959. + * Is the device open right now? Used to prevent
  6960. + * concurent access into the same device
  6961. + */
  6962. +static int Device_Open = 0;
  6963. +
  6964. +/*
  6965. + * This is called whenever a process attempts to open the device file
  6966. + */
  6967. +static int device_open(struct inode *inode, struct file *file)
  6968. +{
  6969. + /*
  6970. + * We don't want to talk to two processes at the same time
  6971. + */
  6972. + if (Device_Open)
  6973. + return -EBUSY;
  6974. +
  6975. + Device_Open++;
  6976. + /*
  6977. + * Initialize the message
  6978. + */
  6979. + try_module_get(THIS_MODULE);
  6980. + return 0;
  6981. +}
  6982. +
  6983. +static int device_release(struct inode *inode, struct file *file)
  6984. +{
  6985. + /*
  6986. + * We're now ready for our next caller
  6987. + */
  6988. + Device_Open--;
  6989. +
  6990. + module_put(THIS_MODULE);
  6991. + return 0;
  6992. +}
  6993. +
  6994. +/*
  6995. + * This function is called whenever a process tries to do an ioctl on our
  6996. + * device file. We get two extra parameters (additional to the inode and file
  6997. + * structures, which all device functions get): the number of the ioctl called
  6998. + * and the parameter given to the ioctl function.
  6999. + *
  7000. + * If the ioctl is write or read/write (meaning output is returned to the
  7001. + * calling process), the ioctl call returns the output of this function.
  7002. + *
  7003. + */
  7004. +static long device_ioctl(struct file *file, /* see include/linux/fs.h */
  7005. + unsigned int ioctl_num, /* number and param for ioctl */
  7006. + unsigned long ioctl_param)
  7007. +{
  7008. + unsigned size;
  7009. + /*
  7010. + * Switch according to the ioctl called
  7011. + */
  7012. + switch (ioctl_num) {
  7013. + case IOCTL_MBOX_PROPERTY:
  7014. + /*
  7015. + * Receive a pointer to a message (in user space) and set that
  7016. + * to be the device's message. Get the parameter given to
  7017. + * ioctl by the process.
  7018. + */
  7019. + mbox_copy_from_user(&size, (void *)ioctl_param, sizeof size);
  7020. + return bcm_mailbox_property((void *)ioctl_param, size);
  7021. + break;
  7022. + default:
  7023. + printk(KERN_ERR DRIVER_NAME "unknown ioctl: %d\n", ioctl_num);
  7024. + return -EINVAL;
  7025. + }
  7026. +
  7027. + return 0;
  7028. +}
  7029. +
  7030. +/* Module Declarations */
  7031. +
  7032. +/*
  7033. + * This structure will hold the functions to be called
  7034. + * when a process does something to the device we
  7035. + * created. Since a pointer to this structure is kept in
  7036. + * the devices table, it can't be local to
  7037. + * init_module. NULL is for unimplemented functios.
  7038. + */
  7039. +struct file_operations fops = {
  7040. + .unlocked_ioctl = device_ioctl,
  7041. + .open = device_open,
  7042. + .release = device_release, /* a.k.a. close */
  7043. +};
  7044. +
  7045. +static int bcm_vcio_probe(struct platform_device *pdev)
  7046. +{
  7047. + int ret = 0;
  7048. + struct vc_mailbox *mailbox;
  7049. +
  7050. + mailbox = kzalloc(sizeof(*mailbox), GFP_KERNEL);
  7051. + if (NULL == mailbox) {
  7052. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  7053. + "mailbox memory\n");
  7054. + ret = -ENOMEM;
  7055. + } else {
  7056. + struct resource *res;
  7057. +
  7058. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  7059. + if (res == NULL) {
  7060. + printk(KERN_ERR DRIVER_NAME ": failed to obtain memory "
  7061. + "resource\n");
  7062. + ret = -ENODEV;
  7063. + kfree(mailbox);
  7064. + } else {
  7065. + /* should be based on the registers from res really */
  7066. + mbox_init(mailbox, &pdev->dev, ARM_0_MAIL0_RD);
  7067. +
  7068. + platform_set_drvdata(pdev, mailbox);
  7069. + dev_mbox_register(DRIVER_NAME, &pdev->dev);
  7070. +
  7071. + mbox_irqaction.dev_id = mailbox;
  7072. + setup_irq(IRQ_ARM_MAILBOX, &mbox_irqaction);
  7073. + printk(KERN_INFO DRIVER_NAME ": mailbox at %p\n",
  7074. + __io_address(ARM_0_MAIL0_RD));
  7075. + }
  7076. + }
  7077. +
  7078. + if (ret == 0) {
  7079. + /*
  7080. + * Register the character device
  7081. + */
  7082. + ret = register_chrdev(MAJOR_NUM, DEVICE_FILE_NAME, &fops);
  7083. +
  7084. + /*
  7085. + * Negative values signify an error
  7086. + */
  7087. + if (ret < 0) {
  7088. + printk(KERN_ERR DRIVER_NAME
  7089. + "Failed registering the character device %d\n", ret);
  7090. + return ret;
  7091. + }
  7092. + }
  7093. + return ret;
  7094. +}
  7095. +
  7096. +static int bcm_vcio_remove(struct platform_device *pdev)
  7097. +{
  7098. + struct vc_mailbox *mailbox = platform_get_drvdata(pdev);
  7099. +
  7100. + platform_set_drvdata(pdev, NULL);
  7101. + kfree(mailbox);
  7102. +
  7103. + return 0;
  7104. +}
  7105. +
  7106. +static struct platform_driver bcm_mbox_driver = {
  7107. + .probe = bcm_vcio_probe,
  7108. + .remove = bcm_vcio_remove,
  7109. +
  7110. + .driver = {
  7111. + .name = DRIVER_NAME,
  7112. + .owner = THIS_MODULE,
  7113. + },
  7114. +};
  7115. +
  7116. +static int __init bcm_mbox_init(void)
  7117. +{
  7118. + int ret;
  7119. +
  7120. + printk(KERN_INFO "mailbox: Broadcom VideoCore Mailbox driver\n");
  7121. +
  7122. + ret = platform_driver_register(&bcm_mbox_driver);
  7123. + if (ret != 0) {
  7124. + printk(KERN_ERR DRIVER_NAME ": failed to register "
  7125. + "on platform\n");
  7126. + }
  7127. +
  7128. + return ret;
  7129. +}
  7130. +
  7131. +static void __exit bcm_mbox_exit(void)
  7132. +{
  7133. + platform_driver_unregister(&bcm_mbox_driver);
  7134. +}
  7135. +
  7136. +arch_initcall(bcm_mbox_init); /* Initialize early */
  7137. +module_exit(bcm_mbox_exit);
  7138. +
  7139. +MODULE_AUTHOR("Gray Girling");
  7140. +MODULE_DESCRIPTION("ARM I/O to VideoCore processor");
  7141. +MODULE_LICENSE("GPL");
  7142. +MODULE_ALIAS("platform:bcm-mbox");
  7143. diff -Nur linux-3.12.26.orig/arch/arm/mach-bcm2708/vc_mem.c linux-3.12.26/arch/arm/mach-bcm2708/vc_mem.c
  7144. --- linux-3.12.26.orig/arch/arm/mach-bcm2708/vc_mem.c 1970-01-01 01:00:00.000000000 +0100
  7145. +++ linux-3.12.26/arch/arm/mach-bcm2708/vc_mem.c 2014-08-06 16:50:13.897957627 +0200
  7146. @@ -0,0 +1,432 @@
  7147. +/*****************************************************************************
  7148. +* Copyright 2010 - 2011 Broadcom Corporation. All rights reserved.
  7149. +*
  7150. +* Unless you and Broadcom execute a separate written software license
  7151. +* agreement governing use of this software, this software is licensed to you
  7152. +* under the terms of the GNU General Public License version 2, available at
  7153. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  7154. +*
  7155. +* Notwithstanding the above, under no circumstances may you combine this
  7156. +* software in any way with any other Broadcom software provided under a
  7157. +* license other than the GPL, without Broadcom's express prior written
  7158. +* consent.
  7159. +*****************************************************************************/
  7160. +
  7161. +#include <linux/kernel.h>
  7162. +#include <linux/module.h>
  7163. +#include <linux/fs.h>
  7164. +#include <linux/device.h>
  7165. +#include <linux/cdev.h>
  7166. +#include <linux/mm.h>
  7167. +#include <linux/slab.h>
  7168. +#include <linux/debugfs.h>
  7169. +#include <asm/uaccess.h>
  7170. +#include <linux/dma-mapping.h>
  7171. +
  7172. +#ifdef CONFIG_ARCH_KONA
  7173. +#include <chal/chal_ipc.h>
  7174. +#elif CONFIG_ARCH_BCM2708
  7175. +#else
  7176. +#include <csp/chal_ipc.h>
  7177. +#endif
  7178. +
  7179. +#include "mach/vc_mem.h"
  7180. +#include <mach/vcio.h>
  7181. +
  7182. +#define DRIVER_NAME "vc-mem"
  7183. +
  7184. +// Device (/dev) related variables
  7185. +static dev_t vc_mem_devnum = 0;
  7186. +static struct class *vc_mem_class = NULL;
  7187. +static struct cdev vc_mem_cdev;
  7188. +static int vc_mem_inited = 0;
  7189. +
  7190. +#ifdef CONFIG_DEBUG_FS
  7191. +static struct dentry *vc_mem_debugfs_entry;
  7192. +#endif
  7193. +
  7194. +/*
  7195. + * Videocore memory addresses and size
  7196. + *
  7197. + * Drivers that wish to know the videocore memory addresses and sizes should
  7198. + * use these variables instead of the MM_IO_BASE and MM_ADDR_IO defines in
  7199. + * headers. This allows the other drivers to not be tied down to a a certain
  7200. + * address/size at compile time.
  7201. + *
  7202. + * In the future, the goal is to have the videocore memory virtual address and
  7203. + * size be calculated at boot time rather than at compile time. The decision of
  7204. + * where the videocore memory resides and its size would be in the hands of the
  7205. + * bootloader (and/or kernel). When that happens, the values of these variables
  7206. + * would be calculated and assigned in the init function.
  7207. + */
  7208. +// in the 2835 VC in mapped above ARM, but ARM has full access to VC space
  7209. +unsigned long mm_vc_mem_phys_addr = 0x00000000;
  7210. +unsigned int mm_vc_mem_size = 0;
  7211. +unsigned int mm_vc_mem_base = 0;
  7212. +
  7213. +EXPORT_SYMBOL(mm_vc_mem_phys_addr);
  7214. +EXPORT_SYMBOL(mm_vc_mem_size);
  7215. +EXPORT_SYMBOL(mm_vc_mem_base);
  7216. +
  7217. +static uint phys_addr = 0;
  7218. +static uint mem_size = 0;
  7219. +static uint mem_base = 0;
  7220. +
  7221. +
  7222. +/****************************************************************************
  7223. +*
  7224. +* vc_mem_open
  7225. +*
  7226. +***************************************************************************/
  7227. +
  7228. +static int
  7229. +vc_mem_open(struct inode *inode, struct file *file)
  7230. +{
  7231. + (void) inode;
  7232. + (void) file;
  7233. +
  7234. + pr_debug("%s: called file = 0x%p\n", __func__, file);
  7235. +
  7236. + return 0;
  7237. +}
  7238. +
  7239. +/****************************************************************************
  7240. +*
  7241. +* vc_mem_release
  7242. +*
  7243. +***************************************************************************/
  7244. +
  7245. +static int
  7246. +vc_mem_release(struct inode *inode, struct file *file)
  7247. +{
  7248. + (void) inode;
  7249. + (void) file;
  7250. +
  7251. + pr_debug("%s: called file = 0x%p\n", __func__, file);
  7252. +
  7253. + return 0;
  7254. +}
  7255. +
  7256. +/****************************************************************************
  7257. +*
  7258. +* vc_mem_get_size
  7259. +*
  7260. +***************************************************************************/
  7261. +
  7262. +static void
  7263. +vc_mem_get_size(void)
  7264. +{
  7265. +}
  7266. +
  7267. +/****************************************************************************
  7268. +*
  7269. +* vc_mem_get_base
  7270. +*
  7271. +***************************************************************************/
  7272. +
  7273. +static void
  7274. +vc_mem_get_base(void)
  7275. +{
  7276. +}
  7277. +
  7278. +/****************************************************************************
  7279. +*
  7280. +* vc_mem_get_current_size
  7281. +*
  7282. +***************************************************************************/
  7283. +
  7284. +int
  7285. +vc_mem_get_current_size(void)
  7286. +{
  7287. + return mm_vc_mem_size;
  7288. +}
  7289. +
  7290. +EXPORT_SYMBOL_GPL(vc_mem_get_current_size);
  7291. +
  7292. +/****************************************************************************
  7293. +*
  7294. +* vc_mem_ioctl
  7295. +*
  7296. +***************************************************************************/
  7297. +
  7298. +static long
  7299. +vc_mem_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  7300. +{
  7301. + int rc = 0;
  7302. +
  7303. + (void) cmd;
  7304. + (void) arg;
  7305. +
  7306. + pr_debug("%s: called file = 0x%p\n", __func__, file);
  7307. +
  7308. + switch (cmd) {
  7309. + case VC_MEM_IOC_MEM_PHYS_ADDR:
  7310. + {
  7311. + pr_debug("%s: VC_MEM_IOC_MEM_PHYS_ADDR=0x%p\n",
  7312. + __func__, (void *) mm_vc_mem_phys_addr);
  7313. +
  7314. + if (copy_to_user((void *) arg, &mm_vc_mem_phys_addr,
  7315. + sizeof (mm_vc_mem_phys_addr)) != 0) {
  7316. + rc = -EFAULT;
  7317. + }
  7318. + break;
  7319. + }
  7320. + case VC_MEM_IOC_MEM_SIZE:
  7321. + {
  7322. + // Get the videocore memory size first
  7323. + vc_mem_get_size();
  7324. +
  7325. + pr_debug("%s: VC_MEM_IOC_MEM_SIZE=%u\n", __func__,
  7326. + mm_vc_mem_size);
  7327. +
  7328. + if (copy_to_user((void *) arg, &mm_vc_mem_size,
  7329. + sizeof (mm_vc_mem_size)) != 0) {
  7330. + rc = -EFAULT;
  7331. + }
  7332. + break;
  7333. + }
  7334. + case VC_MEM_IOC_MEM_BASE:
  7335. + {
  7336. + // Get the videocore memory base
  7337. + vc_mem_get_base();
  7338. +
  7339. + pr_debug("%s: VC_MEM_IOC_MEM_BASE=%u\n", __func__,
  7340. + mm_vc_mem_base);
  7341. +
  7342. + if (copy_to_user((void *) arg, &mm_vc_mem_base,
  7343. + sizeof (mm_vc_mem_base)) != 0) {
  7344. + rc = -EFAULT;
  7345. + }
  7346. + break;
  7347. + }
  7348. + case VC_MEM_IOC_MEM_LOAD:
  7349. + {
  7350. + // Get the videocore memory base
  7351. + vc_mem_get_base();
  7352. +
  7353. + pr_debug("%s: VC_MEM_IOC_MEM_LOAD=%u\n", __func__,
  7354. + mm_vc_mem_base);
  7355. +
  7356. + if (copy_to_user((void *) arg, &mm_vc_mem_base,
  7357. + sizeof (mm_vc_mem_base)) != 0) {
  7358. + rc = -EFAULT;
  7359. + }
  7360. + break;
  7361. + }
  7362. + default:
  7363. + {
  7364. + return -ENOTTY;
  7365. + }
  7366. + }
  7367. + pr_debug("%s: file = 0x%p returning %d\n", __func__, file, rc);
  7368. +
  7369. + return rc;
  7370. +}
  7371. +
  7372. +/****************************************************************************
  7373. +*
  7374. +* vc_mem_mmap
  7375. +*
  7376. +***************************************************************************/
  7377. +
  7378. +static int
  7379. +vc_mem_mmap(struct file *filp, struct vm_area_struct *vma)
  7380. +{
  7381. + int rc = 0;
  7382. + unsigned long length = vma->vm_end - vma->vm_start;
  7383. + unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
  7384. +
  7385. + pr_debug("%s: vm_start = 0x%08lx vm_end = 0x%08lx vm_pgoff = 0x%08lx\n",
  7386. + __func__, (long) vma->vm_start, (long) vma->vm_end,
  7387. + (long) vma->vm_pgoff);
  7388. +
  7389. + if (offset + length > mm_vc_mem_size) {
  7390. + pr_err("%s: length %ld is too big\n", __func__, length);
  7391. + return -EINVAL;
  7392. + }
  7393. + // Do not cache the memory map
  7394. + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  7395. +
  7396. + rc = remap_pfn_range(vma, vma->vm_start,
  7397. + (mm_vc_mem_phys_addr >> PAGE_SHIFT) +
  7398. + vma->vm_pgoff, length, vma->vm_page_prot);
  7399. + if (rc != 0) {
  7400. + pr_err("%s: remap_pfn_range failed (rc=%d)\n", __func__, rc);
  7401. + }
  7402. +
  7403. + return rc;
  7404. +}
  7405. +
  7406. +/****************************************************************************
  7407. +*
  7408. +* File Operations for the driver.
  7409. +*
  7410. +***************************************************************************/
  7411. +
  7412. +static const struct file_operations vc_mem_fops = {
  7413. + .owner = THIS_MODULE,
  7414. + .open = vc_mem_open,
  7415. + .release = vc_mem_release,
  7416. + .unlocked_ioctl = vc_mem_ioctl,
  7417. + .mmap = vc_mem_mmap,
  7418. +};
  7419. +
  7420. +#ifdef CONFIG_DEBUG_FS
  7421. +static void vc_mem_debugfs_deinit(void)
  7422. +{
  7423. + debugfs_remove_recursive(vc_mem_debugfs_entry);
  7424. + vc_mem_debugfs_entry = NULL;
  7425. +}
  7426. +
  7427. +
  7428. +static int vc_mem_debugfs_init(
  7429. + struct device *dev)
  7430. +{
  7431. + vc_mem_debugfs_entry = debugfs_create_dir(DRIVER_NAME, NULL);
  7432. + if (!vc_mem_debugfs_entry) {
  7433. + dev_warn(dev, "could not create debugfs entry\n");
  7434. + return -EFAULT;
  7435. + }
  7436. +
  7437. + if (!debugfs_create_x32("vc_mem_phys_addr",
  7438. + 0444,
  7439. + vc_mem_debugfs_entry,
  7440. + (u32 *)&mm_vc_mem_phys_addr)) {
  7441. + dev_warn(dev, "%s:could not create vc_mem_phys entry\n",
  7442. + __func__);
  7443. + goto fail;
  7444. + }
  7445. +
  7446. + if (!debugfs_create_x32("vc_mem_size",
  7447. + 0444,
  7448. + vc_mem_debugfs_entry,
  7449. + (u32 *)&mm_vc_mem_size)) {
  7450. + dev_warn(dev, "%s:could not create vc_mem_size entry\n",
  7451. + __func__);
  7452. + goto fail;
  7453. + }
  7454. +
  7455. + if (!debugfs_create_x32("vc_mem_base",
  7456. + 0444,
  7457. + vc_mem_debugfs_entry,
  7458. + (u32 *)&mm_vc_mem_base)) {
  7459. + dev_warn(dev, "%s:could not create vc_mem_base entry\n",
  7460. + __func__);
  7461. + goto fail;
  7462. + }
  7463. +
  7464. + return 0;
  7465. +
  7466. +fail:
  7467. + vc_mem_debugfs_deinit();
  7468. + return -EFAULT;
  7469. +}
  7470. +
  7471. +#endif /* CONFIG_DEBUG_FS */
  7472. +
  7473. +
  7474. +/****************************************************************************
  7475. +*
  7476. +* vc_mem_init
  7477. +*
  7478. +***************************************************************************/
  7479. +
  7480. +static int __init
  7481. +vc_mem_init(void)
  7482. +{
  7483. + int rc = -EFAULT;
  7484. + struct device *dev;
  7485. +
  7486. + pr_debug("%s: called\n", __func__);
  7487. +
  7488. + mm_vc_mem_phys_addr = phys_addr;
  7489. + mm_vc_mem_size = mem_size;
  7490. + mm_vc_mem_base = mem_base;
  7491. +
  7492. + vc_mem_get_size();
  7493. +
  7494. + pr_info("vc-mem: phys_addr:0x%08lx mem_base=0x%08x mem_size:0x%08x(%u MiB)\n",
  7495. + mm_vc_mem_phys_addr, mm_vc_mem_base, mm_vc_mem_size, mm_vc_mem_size / (1024 * 1024));
  7496. +
  7497. + if ((rc = alloc_chrdev_region(&vc_mem_devnum, 0, 1, DRIVER_NAME)) < 0) {
  7498. + pr_err("%s: alloc_chrdev_region failed (rc=%d)\n",
  7499. + __func__, rc);
  7500. + goto out_err;
  7501. + }
  7502. +
  7503. + cdev_init(&vc_mem_cdev, &vc_mem_fops);
  7504. + if ((rc = cdev_add(&vc_mem_cdev, vc_mem_devnum, 1)) != 0) {
  7505. + pr_err("%s: cdev_add failed (rc=%d)\n", __func__, rc);
  7506. + goto out_unregister;
  7507. + }
  7508. +
  7509. + vc_mem_class = class_create(THIS_MODULE, DRIVER_NAME);
  7510. + if (IS_ERR(vc_mem_class)) {
  7511. + rc = PTR_ERR(vc_mem_class);
  7512. + pr_err("%s: class_create failed (rc=%d)\n", __func__, rc);
  7513. + goto out_cdev_del;
  7514. + }
  7515. +
  7516. + dev = device_create(vc_mem_class, NULL, vc_mem_devnum, NULL,
  7517. + DRIVER_NAME);
  7518. + if (IS_ERR(dev)) {
  7519. + rc = PTR_ERR(dev);
  7520. + pr_err("%s: device_create failed (rc=%d)\n", __func__, rc);
  7521. + goto out_class_destroy;
  7522. + }
  7523. +
  7524. +#ifdef CONFIG_DEBUG_FS
  7525. + /* don't fail if the debug entries cannot be created */
  7526. + vc_mem_debugfs_init(dev);
  7527. +#endif
  7528. +
  7529. + vc_mem_inited = 1;
  7530. + return 0;
  7531. +
  7532. + device_destroy(vc_mem_class, vc_mem_devnum);
  7533. +
  7534. + out_class_destroy:
  7535. + class_destroy(vc_mem_class);
  7536. + vc_mem_class = NULL;
  7537. +
  7538. + out_cdev_del:
  7539. + cdev_del(&vc_mem_cdev);
  7540. +
  7541. + out_unregister:
  7542. + unregister_chrdev_region(vc_mem_devnum, 1);
  7543. +
  7544. + out_err:
  7545. + return -1;
  7546. +}
  7547. +
  7548. +/****************************************************************************
  7549. +*
  7550. +* vc_mem_exit
  7551. +*
  7552. +***************************************************************************/
  7553. +
  7554. +static void __exit
  7555. +vc_mem_exit(void)
  7556. +{
  7557. + pr_debug("%s: called\n", __func__);
  7558. +
  7559. + if (vc_mem_inited) {
  7560. +#if CONFIG_DEBUG_FS
  7561. + vc_mem_debugfs_deinit();
  7562. +#endif
  7563. + device_destroy(vc_mem_class, vc_mem_devnum);
  7564. + class_destroy(vc_mem_class);
  7565. + cdev_del(&vc_mem_cdev);
  7566. + unregister_chrdev_region(vc_mem_devnum, 1);
  7567. + }
  7568. +}
  7569. +
  7570. +module_init(vc_mem_init);
  7571. +module_exit(vc_mem_exit);
  7572. +MODULE_LICENSE("GPL");
  7573. +MODULE_AUTHOR("Broadcom Corporation");
  7574. +
  7575. +module_param(phys_addr, uint, 0644);
  7576. +module_param(mem_size, uint, 0644);
  7577. +module_param(mem_base, uint, 0644);
  7578. +
  7579. diff -Nur linux-3.12.26.orig/arch/arm/Makefile linux-3.12.26/arch/arm/Makefile
  7580. --- linux-3.12.26.orig/arch/arm/Makefile 2014-07-30 18:02:44.000000000 +0200
  7581. +++ linux-3.12.26/arch/arm/Makefile 2014-08-06 16:50:13.897957627 +0200
  7582. @@ -146,6 +146,7 @@
  7583. # by CONFIG_* macro name.
  7584. machine-$(CONFIG_ARCH_AT91) += at91
  7585. machine-$(CONFIG_ARCH_BCM) += bcm
  7586. +machine-$(CONFIG_ARCH_BCM2708) += bcm2708
  7587. machine-$(CONFIG_ARCH_BCM2835) += bcm2835
  7588. machine-$(CONFIG_ARCH_CLPS711X) += clps711x
  7589. machine-$(CONFIG_ARCH_CNS3XXX) += cns3xxx
  7590. diff -Nur linux-3.12.26.orig/arch/arm/mm/Kconfig linux-3.12.26/arch/arm/mm/Kconfig
  7591. --- linux-3.12.26.orig/arch/arm/mm/Kconfig 2014-07-30 18:02:44.000000000 +0200
  7592. +++ linux-3.12.26/arch/arm/mm/Kconfig 2014-08-06 16:50:13.897957627 +0200
  7593. @@ -358,7 +358,7 @@
  7594. # ARMv6
  7595. config CPU_V6
  7596. - bool "Support ARM V6 processor" if ARCH_INTEGRATOR || MACH_REALVIEW_EB || MACH_REALVIEW_PBX
  7597. + bool "Support ARM V6 processor" if ARCH_INTEGRATOR || MACH_REALVIEW_EB || MACH_REALVIEW_PBX || MACH_BCM2708
  7598. select CPU_32v6
  7599. select CPU_ABRT_EV6
  7600. select CPU_CACHE_V6
  7601. diff -Nur linux-3.12.26.orig/arch/arm/mm/proc-v6.S linux-3.12.26/arch/arm/mm/proc-v6.S
  7602. --- linux-3.12.26.orig/arch/arm/mm/proc-v6.S 2014-07-30 18:02:44.000000000 +0200
  7603. +++ linux-3.12.26/arch/arm/mm/proc-v6.S 2014-08-06 16:50:13.897957627 +0200
  7604. @@ -73,10 +73,19 @@
  7605. *
  7606. * IRQs are already disabled.
  7607. */
  7608. +
  7609. +/* See jira SW-5991 for details of this workaround */
  7610. ENTRY(cpu_v6_do_idle)
  7611. - mov r1, #0
  7612. - mcr p15, 0, r1, c7, c10, 4 @ DWB - WFI may enter a low-power mode
  7613. - mcr p15, 0, r1, c7, c0, 4 @ wait for interrupt
  7614. + .align 5
  7615. + mov r1, #2
  7616. +1: subs r1, #1
  7617. + nop
  7618. + mcreq p15, 0, r1, c7, c10, 4 @ DWB - WFI may enter a low-power mode
  7619. + mcreq p15, 0, r1, c7, c0, 4 @ wait for interrupt
  7620. + nop
  7621. + nop
  7622. + nop
  7623. + bne 1b
  7624. mov pc, lr
  7625. ENTRY(cpu_v6_dcache_clean_area)
  7626. diff -Nur linux-3.12.26.orig/arch/arm/tools/mach-types linux-3.12.26/arch/arm/tools/mach-types
  7627. --- linux-3.12.26.orig/arch/arm/tools/mach-types 2014-07-30 18:02:44.000000000 +0200
  7628. +++ linux-3.12.26/arch/arm/tools/mach-types 2014-08-06 16:50:13.901957659 +0200
  7629. @@ -522,6 +522,7 @@
  7630. prima2_evb MACH_PRIMA2_EVB PRIMA2_EVB 3103
  7631. paz00 MACH_PAZ00 PAZ00 3128
  7632. acmenetusfoxg20 MACH_ACMENETUSFOXG20 ACMENETUSFOXG20 3129
  7633. +bcm2708 MACH_BCM2708 BCM2708 3138
  7634. ag5evm MACH_AG5EVM AG5EVM 3189
  7635. ics_if_voip MACH_ICS_IF_VOIP ICS_IF_VOIP 3206
  7636. wlf_cragg_6410 MACH_WLF_CRAGG_6410 WLF_CRAGG_6410 3207
  7637. diff -Nur linux-3.12.26.orig/arch/m68k/Kconfig linux-3.12.26/arch/m68k/Kconfig
  7638. --- linux-3.12.26.orig/arch/m68k/Kconfig 2014-07-30 18:02:44.000000000 +0200
  7639. +++ linux-3.12.26/arch/m68k/Kconfig 2014-08-06 16:50:13.901957659 +0200
  7640. @@ -16,7 +16,6 @@
  7641. select FPU if MMU
  7642. select ARCH_WANT_IPC_PARSE_VERSION
  7643. select ARCH_USES_GETTIMEOFFSET if MMU && !COLDFIRE
  7644. - select HAVE_FUTEX_CMPXCHG if MMU && FUTEX
  7645. select HAVE_MOD_ARCH_SPECIFIC
  7646. select MODULES_USE_ELF_REL
  7647. select MODULES_USE_ELF_RELA
  7648. diff -Nur linux-3.12.26.orig/arch/s390/Kconfig linux-3.12.26/arch/s390/Kconfig
  7649. --- linux-3.12.26.orig/arch/s390/Kconfig 2014-07-30 18:02:44.000000000 +0200
  7650. +++ linux-3.12.26/arch/s390/Kconfig 2014-08-06 16:50:13.901957659 +0200
  7651. @@ -116,7 +116,6 @@
  7652. select HAVE_FUNCTION_GRAPH_TRACER
  7653. select HAVE_FUNCTION_TRACER
  7654. select HAVE_FUNCTION_TRACE_MCOUNT_TEST
  7655. - select HAVE_FUTEX_CMPXCHG if FUTEX
  7656. select HAVE_KERNEL_BZIP2
  7657. select HAVE_KERNEL_GZIP
  7658. select HAVE_KERNEL_LZ4
  7659. diff -Nur linux-3.12.26.orig/arch/x86/crypto/ghash-clmulni-intel_asm.S linux-3.12.26/arch/x86/crypto/ghash-clmulni-intel_asm.S
  7660. --- linux-3.12.26.orig/arch/x86/crypto/ghash-clmulni-intel_asm.S 2014-07-30 18:02:44.000000000 +0200
  7661. +++ linux-3.12.26/arch/x86/crypto/ghash-clmulni-intel_asm.S 2014-08-06 16:50:13.905957690 +0200
  7662. @@ -24,6 +24,10 @@
  7663. .align 16
  7664. .Lbswap_mask:
  7665. .octa 0x000102030405060708090a0b0c0d0e0f
  7666. +.Lpoly:
  7667. + .octa 0xc2000000000000000000000000000001
  7668. +.Ltwo_one:
  7669. + .octa 0x00000001000000000000000000000001
  7670. #define DATA %xmm0
  7671. #define SHASH %xmm1
  7672. @@ -130,3 +134,28 @@
  7673. .Lupdate_just_ret:
  7674. ret
  7675. ENDPROC(clmul_ghash_update)
  7676. +
  7677. +/*
  7678. + * void clmul_ghash_setkey(be128 *shash, const u8 *key);
  7679. + *
  7680. + * Calculate hash_key << 1 mod poly
  7681. + */
  7682. +ENTRY(clmul_ghash_setkey)
  7683. + movaps .Lbswap_mask, BSWAP
  7684. + movups (%rsi), %xmm0
  7685. + PSHUFB_XMM BSWAP %xmm0
  7686. + movaps %xmm0, %xmm1
  7687. + psllq $1, %xmm0
  7688. + psrlq $63, %xmm1
  7689. + movaps %xmm1, %xmm2
  7690. + pslldq $8, %xmm1
  7691. + psrldq $8, %xmm2
  7692. + por %xmm1, %xmm0
  7693. + # reduction
  7694. + pshufd $0b00100100, %xmm2, %xmm1
  7695. + pcmpeqd .Ltwo_one, %xmm1
  7696. + pand .Lpoly, %xmm1
  7697. + pxor %xmm1, %xmm0
  7698. + movups %xmm0, (%rdi)
  7699. + ret
  7700. +ENDPROC(clmul_ghash_setkey)
  7701. diff -Nur linux-3.12.26.orig/arch/x86/crypto/ghash-clmulni-intel_glue.c linux-3.12.26/arch/x86/crypto/ghash-clmulni-intel_glue.c
  7702. --- linux-3.12.26.orig/arch/x86/crypto/ghash-clmulni-intel_glue.c 2014-07-30 18:02:44.000000000 +0200
  7703. +++ linux-3.12.26/arch/x86/crypto/ghash-clmulni-intel_glue.c 2014-08-06 16:50:13.905957690 +0200
  7704. @@ -30,6 +30,8 @@
  7705. void clmul_ghash_update(char *dst, const char *src, unsigned int srclen,
  7706. const be128 *shash);
  7707. +void clmul_ghash_setkey(be128 *shash, const u8 *key);
  7708. +
  7709. struct ghash_async_ctx {
  7710. struct cryptd_ahash *cryptd_tfm;
  7711. };
  7712. @@ -56,23 +58,13 @@
  7713. const u8 *key, unsigned int keylen)
  7714. {
  7715. struct ghash_ctx *ctx = crypto_shash_ctx(tfm);
  7716. - be128 *x = (be128 *)key;
  7717. - u64 a, b;
  7718. if (keylen != GHASH_BLOCK_SIZE) {
  7719. crypto_shash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
  7720. return -EINVAL;
  7721. }
  7722. - /* perform multiplication by 'x' in GF(2^128) */
  7723. - a = be64_to_cpu(x->a);
  7724. - b = be64_to_cpu(x->b);
  7725. -
  7726. - ctx->shash.a = (__be64)((b << 1) | (a >> 63));
  7727. - ctx->shash.b = (__be64)((a << 1) | (b >> 63));
  7728. -
  7729. - if (a >> 63)
  7730. - ctx->shash.b ^= cpu_to_be64(0xc2);
  7731. + clmul_ghash_setkey(&ctx->shash, key);
  7732. return 0;
  7733. }
  7734. diff -Nur linux-3.12.26.orig/Documentation/devicetree/bindings/net/micrel-ks8851.txt linux-3.12.26/Documentation/devicetree/bindings/net/micrel-ks8851.txt
  7735. --- linux-3.12.26.orig/Documentation/devicetree/bindings/net/micrel-ks8851.txt 2014-07-30 18:02:44.000000000 +0200
  7736. +++ linux-3.12.26/Documentation/devicetree/bindings/net/micrel-ks8851.txt 2014-08-06 16:50:13.905957690 +0200
  7737. @@ -7,4 +7,3 @@
  7738. Optional properties:
  7739. - local-mac-address : Ethernet mac address to use
  7740. -- vdd-supply: supply for Ethernet mac
  7741. diff -Nur linux-3.12.26.orig/Documentation/video4linux/bcm2835-v4l2.txt linux-3.12.26/Documentation/video4linux/bcm2835-v4l2.txt
  7742. --- linux-3.12.26.orig/Documentation/video4linux/bcm2835-v4l2.txt 1970-01-01 01:00:00.000000000 +0100
  7743. +++ linux-3.12.26/Documentation/video4linux/bcm2835-v4l2.txt 2014-08-06 16:50:13.905957690 +0200
  7744. @@ -0,0 +1,60 @@
  7745. +
  7746. +BCM2835 (aka Raspberry Pi) V4L2 driver
  7747. +======================================
  7748. +
  7749. +1. Copyright
  7750. +============
  7751. +
  7752. +Copyright © 2013 Raspberry Pi (Trading) Ltd.
  7753. +
  7754. +2. License
  7755. +==========
  7756. +
  7757. +This program is free software; you can redistribute it and/or modify
  7758. +it under the terms of the GNU General Public License as published by
  7759. +the Free Software Foundation; either version 2 of the License, or
  7760. +(at your option) any later version.
  7761. +
  7762. +This program is distributed in the hope that it will be useful,
  7763. +but WITHOUT ANY WARRANTY; without even the implied warranty of
  7764. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  7765. +GNU General Public License for more details.
  7766. +
  7767. +You should have received a copy of the GNU General Public License
  7768. +along with this program; if not, write to the Free Software
  7769. +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  7770. +
  7771. +3. Quick Start
  7772. +==============
  7773. +
  7774. +You need a version 1.0 or later of v4l2-ctl, available from:
  7775. + git://git.linuxtv.org/v4l-utils.git
  7776. +
  7777. +$ sudo modprobe bcm2835-v4l2
  7778. +
  7779. +Turn on the overlay:
  7780. +
  7781. +$ v4l2-ctl --overlay=1
  7782. +
  7783. +Turn off the overlay:
  7784. +
  7785. +$ v4l2-ctl --overlay=0
  7786. +
  7787. +Set the capture format for video:
  7788. +
  7789. +$ v4l2-ctl --set-fmt-video=width=1920,height=1088,pixelformat=4
  7790. +
  7791. +(Note: 1088 not 1080).
  7792. +
  7793. +Capture:
  7794. +
  7795. +$ v4l2-ctl --stream-mmap=3 --stream-count=100 --stream-to=somefile.h264
  7796. +
  7797. +Stills capture:
  7798. +
  7799. +$ v4l2-ctl --set-fmt-video=width=2592,height=1944,pixelformat=3
  7800. +$ v4l2-ctl --stream-mmap=3 --stream-count=1 --stream-to=somefile.jpg
  7801. +
  7802. +List of available formats:
  7803. +
  7804. +$ v4l2-ctl --list-formats
  7805. diff -Nur linux-3.12.26.orig/drivers/char/broadcom/Kconfig linux-3.12.26/drivers/char/broadcom/Kconfig
  7806. --- linux-3.12.26.orig/drivers/char/broadcom/Kconfig 1970-01-01 01:00:00.000000000 +0100
  7807. +++ linux-3.12.26/drivers/char/broadcom/Kconfig 2014-08-06 16:50:13.933957910 +0200
  7808. @@ -0,0 +1,16 @@
  7809. +#
  7810. +# Broadcom char driver config
  7811. +#
  7812. +
  7813. +menuconfig BRCM_CHAR_DRIVERS
  7814. + bool "Broadcom Char Drivers"
  7815. + help
  7816. + Broadcom's char drivers
  7817. +
  7818. +config BCM_VC_CMA
  7819. + bool "Videocore CMA"
  7820. + depends on CMA && BRCM_CHAR_DRIVERS && BCM2708_VCHIQ
  7821. + default n
  7822. + help
  7823. + Helper for videocore CMA access.
  7824. +
  7825. diff -Nur linux-3.12.26.orig/drivers/char/broadcom/Makefile linux-3.12.26/drivers/char/broadcom/Makefile
  7826. --- linux-3.12.26.orig/drivers/char/broadcom/Makefile 1970-01-01 01:00:00.000000000 +0100
  7827. +++ linux-3.12.26/drivers/char/broadcom/Makefile 2014-08-06 16:50:13.933957910 +0200
  7828. @@ -0,0 +1 @@
  7829. +obj-$(CONFIG_BCM_VC_CMA) += vc_cma/
  7830. diff -Nur linux-3.12.26.orig/drivers/char/broadcom/vc_cma/Makefile linux-3.12.26/drivers/char/broadcom/vc_cma/Makefile
  7831. --- linux-3.12.26.orig/drivers/char/broadcom/vc_cma/Makefile 1970-01-01 01:00:00.000000000 +0100
  7832. +++ linux-3.12.26/drivers/char/broadcom/vc_cma/Makefile 2014-08-06 16:50:13.933957910 +0200
  7833. @@ -0,0 +1,14 @@
  7834. +ccflags-y += -Wall -Wstrict-prototypes -Wno-trigraphs
  7835. +ccflags-y += -Werror
  7836. +ccflags-y += -Iinclude/linux/broadcom
  7837. +ccflags-y += -Idrivers/misc/vc04_services
  7838. +ccflags-y += -Idrivers/misc/vc04_services/interface/vchi
  7839. +ccflags-y += -Idrivers/misc/vc04_services/interface/vchiq_arm
  7840. +
  7841. +ccflags-y += -D__KERNEL__
  7842. +ccflags-y += -D__linux__
  7843. +ccflags-y += -Werror
  7844. +
  7845. +obj-$(CONFIG_BCM_VC_CMA) += vc-cma.o
  7846. +
  7847. +vc-cma-objs := vc_cma.o
  7848. diff -Nur linux-3.12.26.orig/drivers/char/broadcom/vc_cma/vc_cma.c linux-3.12.26/drivers/char/broadcom/vc_cma/vc_cma.c
  7849. --- linux-3.12.26.orig/drivers/char/broadcom/vc_cma/vc_cma.c 1970-01-01 01:00:00.000000000 +0100
  7850. +++ linux-3.12.26/drivers/char/broadcom/vc_cma/vc_cma.c 2014-08-06 16:50:13.933957910 +0200
  7851. @@ -0,0 +1,1143 @@
  7852. +/**
  7853. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  7854. + *
  7855. + * Redistribution and use in source and binary forms, with or without
  7856. + * modification, are permitted provided that the following conditions
  7857. + * are met:
  7858. + * 1. Redistributions of source code must retain the above copyright
  7859. + * notice, this list of conditions, and the following disclaimer,
  7860. + * without modification.
  7861. + * 2. Redistributions in binary form must reproduce the above copyright
  7862. + * notice, this list of conditions and the following disclaimer in the
  7863. + * documentation and/or other materials provided with the distribution.
  7864. + * 3. The names of the above-listed copyright holders may not be used
  7865. + * to endorse or promote products derived from this software without
  7866. + * specific prior written permission.
  7867. + *
  7868. + * ALTERNATIVELY, this software may be distributed under the terms of the
  7869. + * GNU General Public License ("GPL") version 2, as published by the Free
  7870. + * Software Foundation.
  7871. + *
  7872. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  7873. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  7874. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  7875. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  7876. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  7877. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  7878. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  7879. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  7880. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  7881. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  7882. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7883. + */
  7884. +
  7885. +#include <linux/kernel.h>
  7886. +#include <linux/module.h>
  7887. +#include <linux/kthread.h>
  7888. +#include <linux/fs.h>
  7889. +#include <linux/device.h>
  7890. +#include <linux/cdev.h>
  7891. +#include <linux/mm.h>
  7892. +#include <linux/proc_fs.h>
  7893. +#include <linux/seq_file.h>
  7894. +#include <linux/dma-mapping.h>
  7895. +#include <linux/dma-contiguous.h>
  7896. +#include <linux/platform_device.h>
  7897. +#include <linux/uaccess.h>
  7898. +#include <asm/cacheflush.h>
  7899. +
  7900. +#include "vc_cma.h"
  7901. +
  7902. +#include "vchiq_util.h"
  7903. +#include "vchiq_connected.h"
  7904. +//#include "debug_sym.h"
  7905. +//#include "vc_mem.h"
  7906. +
  7907. +#define DRIVER_NAME "vc-cma"
  7908. +
  7909. +#define LOG_DBG(fmt, ...) \
  7910. + if (vc_cma_debug) \
  7911. + printk(KERN_INFO fmt "\n", ##__VA_ARGS__)
  7912. +#define LOG_ERR(fmt, ...) \
  7913. + printk(KERN_ERR fmt "\n", ##__VA_ARGS__)
  7914. +
  7915. +#define VC_CMA_FOURCC VCHIQ_MAKE_FOURCC('C', 'M', 'A', ' ')
  7916. +#define VC_CMA_VERSION 2
  7917. +
  7918. +#define VC_CMA_CHUNK_ORDER 6 /* 256K */
  7919. +#define VC_CMA_CHUNK_SIZE (4096 << VC_CMA_CHUNK_ORDER)
  7920. +#define VC_CMA_MAX_PARAMS_PER_MSG \
  7921. + ((VCHIQ_MAX_MSG_SIZE - sizeof(unsigned short))/sizeof(unsigned short))
  7922. +#define VC_CMA_RESERVE_COUNT_MAX 16
  7923. +
  7924. +#define PAGES_PER_CHUNK (VC_CMA_CHUNK_SIZE / PAGE_SIZE)
  7925. +
  7926. +#define VCADDR_TO_PHYSADDR(vcaddr) (mm_vc_mem_phys_addr + vcaddr)
  7927. +
  7928. +#define loud_error(...) \
  7929. + LOG_ERR("===== " __VA_ARGS__)
  7930. +
  7931. +enum {
  7932. + VC_CMA_MSG_QUIT,
  7933. + VC_CMA_MSG_OPEN,
  7934. + VC_CMA_MSG_TICK,
  7935. + VC_CMA_MSG_ALLOC, /* chunk count */
  7936. + VC_CMA_MSG_FREE, /* chunk, chunk, ... */
  7937. + VC_CMA_MSG_ALLOCATED, /* chunk, chunk, ... */
  7938. + VC_CMA_MSG_REQUEST_ALLOC, /* chunk count */
  7939. + VC_CMA_MSG_REQUEST_FREE, /* chunk count */
  7940. + VC_CMA_MSG_RESERVE, /* bytes lo, bytes hi */
  7941. + VC_CMA_MSG_UPDATE_RESERVE,
  7942. + VC_CMA_MSG_MAX
  7943. +};
  7944. +
  7945. +struct cma_msg {
  7946. + unsigned short type;
  7947. + unsigned short params[VC_CMA_MAX_PARAMS_PER_MSG];
  7948. +};
  7949. +
  7950. +struct vc_cma_reserve_user {
  7951. + unsigned int pid;
  7952. + unsigned int reserve;
  7953. +};
  7954. +
  7955. +/* Device (/dev) related variables */
  7956. +static dev_t vc_cma_devnum;
  7957. +static struct class *vc_cma_class;
  7958. +static struct cdev vc_cma_cdev;
  7959. +static int vc_cma_inited;
  7960. +static int vc_cma_debug;
  7961. +
  7962. +/* Proc entry */
  7963. +static struct proc_dir_entry *vc_cma_proc_entry;
  7964. +
  7965. +phys_addr_t vc_cma_base;
  7966. +struct page *vc_cma_base_page;
  7967. +unsigned int vc_cma_size;
  7968. +EXPORT_SYMBOL(vc_cma_size);
  7969. +unsigned int vc_cma_initial;
  7970. +unsigned int vc_cma_chunks;
  7971. +unsigned int vc_cma_chunks_used;
  7972. +unsigned int vc_cma_chunks_reserved;
  7973. +
  7974. +static int in_loud_error;
  7975. +
  7976. +unsigned int vc_cma_reserve_total;
  7977. +unsigned int vc_cma_reserve_count;
  7978. +struct vc_cma_reserve_user vc_cma_reserve_users[VC_CMA_RESERVE_COUNT_MAX];
  7979. +static DEFINE_SEMAPHORE(vc_cma_reserve_mutex);
  7980. +static DEFINE_SEMAPHORE(vc_cma_worker_queue_push_mutex);
  7981. +
  7982. +static u64 vc_cma_dma_mask = DMA_BIT_MASK(32);
  7983. +static struct platform_device vc_cma_device = {
  7984. + .name = "vc-cma",
  7985. + .id = 0,
  7986. + .dev = {
  7987. + .dma_mask = &vc_cma_dma_mask,
  7988. + .coherent_dma_mask = DMA_BIT_MASK(32),
  7989. + },
  7990. +};
  7991. +
  7992. +static VCHIQ_INSTANCE_T cma_instance;
  7993. +static VCHIQ_SERVICE_HANDLE_T cma_service;
  7994. +static VCHIU_QUEUE_T cma_msg_queue;
  7995. +static struct task_struct *cma_worker;
  7996. +
  7997. +static int vc_cma_set_reserve(unsigned int reserve, unsigned int pid);
  7998. +static int vc_cma_alloc_chunks(int num_chunks, struct cma_msg *reply);
  7999. +static VCHIQ_STATUS_T cma_service_callback(VCHIQ_REASON_T reason,
  8000. + VCHIQ_HEADER_T * header,
  8001. + VCHIQ_SERVICE_HANDLE_T service,
  8002. + void *bulk_userdata);
  8003. +static void send_vc_msg(unsigned short type,
  8004. + unsigned short param1, unsigned short param2);
  8005. +static bool send_worker_msg(VCHIQ_HEADER_T * msg);
  8006. +
  8007. +static int early_vc_cma_mem(char *p)
  8008. +{
  8009. + unsigned int new_size;
  8010. + printk(KERN_NOTICE "early_vc_cma_mem(%s)", p);
  8011. + vc_cma_size = memparse(p, &p);
  8012. + vc_cma_initial = vc_cma_size;
  8013. + if (*p == '/')
  8014. + vc_cma_size = memparse(p + 1, &p);
  8015. + if (*p == '@')
  8016. + vc_cma_base = memparse(p + 1, &p);
  8017. +
  8018. + new_size = (vc_cma_size - ((-vc_cma_base) & (VC_CMA_CHUNK_SIZE - 1)))
  8019. + & ~(VC_CMA_CHUNK_SIZE - 1);
  8020. + if (new_size > vc_cma_size)
  8021. + vc_cma_size = 0;
  8022. + vc_cma_initial = (vc_cma_initial + VC_CMA_CHUNK_SIZE - 1)
  8023. + & ~(VC_CMA_CHUNK_SIZE - 1);
  8024. + if (vc_cma_initial > vc_cma_size)
  8025. + vc_cma_initial = vc_cma_size;
  8026. + vc_cma_base = (vc_cma_base + VC_CMA_CHUNK_SIZE - 1)
  8027. + & ~(VC_CMA_CHUNK_SIZE - 1);
  8028. +
  8029. + printk(KERN_NOTICE " -> initial %x, size %x, base %x", vc_cma_initial,
  8030. + vc_cma_size, (unsigned int)vc_cma_base);
  8031. +
  8032. + return 0;
  8033. +}
  8034. +
  8035. +early_param("vc-cma-mem", early_vc_cma_mem);
  8036. +
  8037. +void vc_cma_early_init(void)
  8038. +{
  8039. + LOG_DBG("vc_cma_early_init - vc_cma_chunks = %d", vc_cma_chunks);
  8040. + if (vc_cma_size) {
  8041. + int rc = platform_device_register(&vc_cma_device);
  8042. + LOG_DBG("platform_device_register -> %d", rc);
  8043. + }
  8044. +}
  8045. +
  8046. +void vc_cma_reserve(void)
  8047. +{
  8048. + /* if vc_cma_size is set, then declare vc CMA area of the same
  8049. + * size from the end of memory
  8050. + */
  8051. + if (vc_cma_size) {
  8052. + if (dma_declare_contiguous(NULL /*&vc_cma_device.dev*/, vc_cma_size,
  8053. + vc_cma_base, 0) == 0) {
  8054. + } else {
  8055. + LOG_ERR("vc_cma: dma_declare_contiguous(%x,%x) failed",
  8056. + vc_cma_size, (unsigned int)vc_cma_base);
  8057. + vc_cma_size = 0;
  8058. + }
  8059. + }
  8060. + vc_cma_chunks = vc_cma_size / VC_CMA_CHUNK_SIZE;
  8061. +}
  8062. +
  8063. +/****************************************************************************
  8064. +*
  8065. +* vc_cma_open
  8066. +*
  8067. +***************************************************************************/
  8068. +
  8069. +static int vc_cma_open(struct inode *inode, struct file *file)
  8070. +{
  8071. + (void)inode;
  8072. + (void)file;
  8073. +
  8074. + return 0;
  8075. +}
  8076. +
  8077. +/****************************************************************************
  8078. +*
  8079. +* vc_cma_release
  8080. +*
  8081. +***************************************************************************/
  8082. +
  8083. +static int vc_cma_release(struct inode *inode, struct file *file)
  8084. +{
  8085. + (void)inode;
  8086. + (void)file;
  8087. +
  8088. + vc_cma_set_reserve(0, current->tgid);
  8089. +
  8090. + return 0;
  8091. +}
  8092. +
  8093. +/****************************************************************************
  8094. +*
  8095. +* vc_cma_ioctl
  8096. +*
  8097. +***************************************************************************/
  8098. +
  8099. +static long vc_cma_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  8100. +{
  8101. + int rc = 0;
  8102. +
  8103. + (void)cmd;
  8104. + (void)arg;
  8105. +
  8106. + switch (cmd) {
  8107. + case VC_CMA_IOC_RESERVE:
  8108. + rc = vc_cma_set_reserve((unsigned int)arg, current->tgid);
  8109. + if (rc >= 0)
  8110. + rc = 0;
  8111. + break;
  8112. + default:
  8113. + LOG_ERR("vc-cma: Unknown ioctl %x", cmd);
  8114. + return -ENOTTY;
  8115. + }
  8116. +
  8117. + return rc;
  8118. +}
  8119. +
  8120. +/****************************************************************************
  8121. +*
  8122. +* File Operations for the driver.
  8123. +*
  8124. +***************************************************************************/
  8125. +
  8126. +static const struct file_operations vc_cma_fops = {
  8127. + .owner = THIS_MODULE,
  8128. + .open = vc_cma_open,
  8129. + .release = vc_cma_release,
  8130. + .unlocked_ioctl = vc_cma_ioctl,
  8131. +};
  8132. +
  8133. +/****************************************************************************
  8134. +*
  8135. +* vc_cma_proc_open
  8136. +*
  8137. +***************************************************************************/
  8138. +
  8139. +static int vc_cma_show_info(struct seq_file *m, void *v)
  8140. +{
  8141. + int i;
  8142. +
  8143. + seq_printf(m, "Videocore CMA:\n");
  8144. + seq_printf(m, " Base : %08x\n", (unsigned int)vc_cma_base);
  8145. + seq_printf(m, " Length : %08x\n", vc_cma_size);
  8146. + seq_printf(m, " Initial : %08x\n", vc_cma_initial);
  8147. + seq_printf(m, " Chunk size : %08x\n", VC_CMA_CHUNK_SIZE);
  8148. + seq_printf(m, " Chunks : %4d (%d bytes)\n",
  8149. + (int)vc_cma_chunks,
  8150. + (int)(vc_cma_chunks * VC_CMA_CHUNK_SIZE));
  8151. + seq_printf(m, " Used : %4d (%d bytes)\n",
  8152. + (int)vc_cma_chunks_used,
  8153. + (int)(vc_cma_chunks_used * VC_CMA_CHUNK_SIZE));
  8154. + seq_printf(m, " Reserved : %4d (%d bytes)\n",
  8155. + (unsigned int)vc_cma_chunks_reserved,
  8156. + (int)(vc_cma_chunks_reserved * VC_CMA_CHUNK_SIZE));
  8157. +
  8158. + for (i = 0; i < vc_cma_reserve_count; i++) {
  8159. + struct vc_cma_reserve_user *user = &vc_cma_reserve_users[i];
  8160. + seq_printf(m, " PID %5d: %d bytes\n", user->pid,
  8161. + user->reserve);
  8162. + }
  8163. +
  8164. + seq_printf(m, "\n");
  8165. +
  8166. + return 0;
  8167. +}
  8168. +
  8169. +static int vc_cma_proc_open(struct inode *inode, struct file *file)
  8170. +{
  8171. + return single_open(file, vc_cma_show_info, NULL);
  8172. +}
  8173. +
  8174. +/****************************************************************************
  8175. +*
  8176. +* vc_cma_proc_write
  8177. +*
  8178. +***************************************************************************/
  8179. +
  8180. +static int vc_cma_proc_write(struct file *file,
  8181. + const char __user *buffer,
  8182. + size_t size, loff_t *ppos)
  8183. +{
  8184. + int rc = -EFAULT;
  8185. + char input_str[20];
  8186. +
  8187. + memset(input_str, 0, sizeof(input_str));
  8188. +
  8189. + if (size > sizeof(input_str)) {
  8190. + LOG_ERR("%s: input string length too long", __func__);
  8191. + goto out;
  8192. + }
  8193. +
  8194. + if (copy_from_user(input_str, buffer, size - 1)) {
  8195. + LOG_ERR("%s: failed to get input string", __func__);
  8196. + goto out;
  8197. + }
  8198. +#define ALLOC_STR "alloc"
  8199. +#define FREE_STR "free"
  8200. +#define DEBUG_STR "debug"
  8201. +#define RESERVE_STR "reserve"
  8202. + if (strncmp(input_str, ALLOC_STR, strlen(ALLOC_STR)) == 0) {
  8203. + int size;
  8204. + char *p = input_str + strlen(ALLOC_STR);
  8205. +
  8206. + while (*p == ' ')
  8207. + p++;
  8208. + size = memparse(p, NULL);
  8209. + LOG_ERR("/proc/vc-cma: alloc %d", size);
  8210. + if (size)
  8211. + send_vc_msg(VC_CMA_MSG_REQUEST_FREE,
  8212. + size / VC_CMA_CHUNK_SIZE, 0);
  8213. + else
  8214. + LOG_ERR("invalid size '%s'", p);
  8215. + rc = size;
  8216. + } else if (strncmp(input_str, FREE_STR, strlen(FREE_STR)) == 0) {
  8217. + int size;
  8218. + char *p = input_str + strlen(FREE_STR);
  8219. +
  8220. + while (*p == ' ')
  8221. + p++;
  8222. + size = memparse(p, NULL);
  8223. + LOG_ERR("/proc/vc-cma: free %d", size);
  8224. + if (size)
  8225. + send_vc_msg(VC_CMA_MSG_REQUEST_ALLOC,
  8226. + size / VC_CMA_CHUNK_SIZE, 0);
  8227. + else
  8228. + LOG_ERR("invalid size '%s'", p);
  8229. + rc = size;
  8230. + } else if (strncmp(input_str, DEBUG_STR, strlen(DEBUG_STR)) == 0) {
  8231. + char *p = input_str + strlen(DEBUG_STR);
  8232. + while (*p == ' ')
  8233. + p++;
  8234. + if ((strcmp(p, "on") == 0) || (strcmp(p, "1") == 0))
  8235. + vc_cma_debug = 1;
  8236. + else if ((strcmp(p, "off") == 0) || (strcmp(p, "0") == 0))
  8237. + vc_cma_debug = 0;
  8238. + LOG_ERR("/proc/vc-cma: debug %s", vc_cma_debug ? "on" : "off");
  8239. + rc = size;
  8240. + } else if (strncmp(input_str, RESERVE_STR, strlen(RESERVE_STR)) == 0) {
  8241. + int size;
  8242. + int reserved;
  8243. + char *p = input_str + strlen(RESERVE_STR);
  8244. + while (*p == ' ')
  8245. + p++;
  8246. + size = memparse(p, NULL);
  8247. +
  8248. + reserved = vc_cma_set_reserve(size, current->tgid);
  8249. + rc = (reserved >= 0) ? size : reserved;
  8250. + }
  8251. +
  8252. +out:
  8253. + return rc;
  8254. +}
  8255. +
  8256. +/****************************************************************************
  8257. +*
  8258. +* File Operations for /proc interface.
  8259. +*
  8260. +***************************************************************************/
  8261. +
  8262. +static const struct file_operations vc_cma_proc_fops = {
  8263. + .open = vc_cma_proc_open,
  8264. + .read = seq_read,
  8265. + .write = vc_cma_proc_write,
  8266. + .llseek = seq_lseek,
  8267. + .release = single_release
  8268. +};
  8269. +
  8270. +static int vc_cma_set_reserve(unsigned int reserve, unsigned int pid)
  8271. +{
  8272. + struct vc_cma_reserve_user *user = NULL;
  8273. + int delta = 0;
  8274. + int i;
  8275. +
  8276. + if (down_interruptible(&vc_cma_reserve_mutex))
  8277. + return -ERESTARTSYS;
  8278. +
  8279. + for (i = 0; i < vc_cma_reserve_count; i++) {
  8280. + if (pid == vc_cma_reserve_users[i].pid) {
  8281. + user = &vc_cma_reserve_users[i];
  8282. + delta = reserve - user->reserve;
  8283. + if (reserve)
  8284. + user->reserve = reserve;
  8285. + else {
  8286. + /* Remove this entry by copying downwards */
  8287. + while ((i + 1) < vc_cma_reserve_count) {
  8288. + user[0].pid = user[1].pid;
  8289. + user[0].reserve = user[1].reserve;
  8290. + user++;
  8291. + i++;
  8292. + }
  8293. + vc_cma_reserve_count--;
  8294. + user = NULL;
  8295. + }
  8296. + break;
  8297. + }
  8298. + }
  8299. +
  8300. + if (reserve && !user) {
  8301. + if (vc_cma_reserve_count == VC_CMA_RESERVE_COUNT_MAX) {
  8302. + LOG_ERR("vc-cma: Too many reservations - "
  8303. + "increase CMA_RESERVE_COUNT_MAX");
  8304. + up(&vc_cma_reserve_mutex);
  8305. + return -EBUSY;
  8306. + }
  8307. + user = &vc_cma_reserve_users[vc_cma_reserve_count];
  8308. + user->pid = pid;
  8309. + user->reserve = reserve;
  8310. + delta = reserve;
  8311. + vc_cma_reserve_count++;
  8312. + }
  8313. +
  8314. + vc_cma_reserve_total += delta;
  8315. +
  8316. + send_vc_msg(VC_CMA_MSG_RESERVE,
  8317. + vc_cma_reserve_total & 0xffff, vc_cma_reserve_total >> 16);
  8318. +
  8319. + send_worker_msg((VCHIQ_HEADER_T *) VC_CMA_MSG_UPDATE_RESERVE);
  8320. +
  8321. + LOG_DBG("/proc/vc-cma: reserve %d (PID %d) - total %u",
  8322. + reserve, pid, vc_cma_reserve_total);
  8323. +
  8324. + up(&vc_cma_reserve_mutex);
  8325. +
  8326. + return vc_cma_reserve_total;
  8327. +}
  8328. +
  8329. +static VCHIQ_STATUS_T cma_service_callback(VCHIQ_REASON_T reason,
  8330. + VCHIQ_HEADER_T * header,
  8331. + VCHIQ_SERVICE_HANDLE_T service,
  8332. + void *bulk_userdata)
  8333. +{
  8334. + switch (reason) {
  8335. + case VCHIQ_MESSAGE_AVAILABLE:
  8336. + if (!send_worker_msg(header))
  8337. + return VCHIQ_RETRY;
  8338. + break;
  8339. + case VCHIQ_SERVICE_CLOSED:
  8340. + LOG_DBG("CMA service closed");
  8341. + break;
  8342. + default:
  8343. + LOG_ERR("Unexpected CMA callback reason %d", reason);
  8344. + break;
  8345. + }
  8346. + return VCHIQ_SUCCESS;
  8347. +}
  8348. +
  8349. +static void send_vc_msg(unsigned short type,
  8350. + unsigned short param1, unsigned short param2)
  8351. +{
  8352. + unsigned short msg[] = { type, param1, param2 };
  8353. + VCHIQ_ELEMENT_T elem = { &msg, sizeof(msg) };
  8354. + VCHIQ_STATUS_T ret;
  8355. + vchiq_use_service(cma_service);
  8356. + ret = vchiq_queue_message(cma_service, &elem, 1);
  8357. + vchiq_release_service(cma_service);
  8358. + if (ret != VCHIQ_SUCCESS)
  8359. + LOG_ERR("vchiq_queue_message returned %x", ret);
  8360. +}
  8361. +
  8362. +static bool send_worker_msg(VCHIQ_HEADER_T * msg)
  8363. +{
  8364. + if (down_interruptible(&vc_cma_worker_queue_push_mutex))
  8365. + return false;
  8366. + vchiu_queue_push(&cma_msg_queue, msg);
  8367. + up(&vc_cma_worker_queue_push_mutex);
  8368. + return true;
  8369. +}
  8370. +
  8371. +static int vc_cma_alloc_chunks(int num_chunks, struct cma_msg *reply)
  8372. +{
  8373. + int i;
  8374. + for (i = 0; i < num_chunks; i++) {
  8375. + struct page *chunk;
  8376. + unsigned int chunk_num;
  8377. + uint8_t *chunk_addr;
  8378. + size_t chunk_size = PAGES_PER_CHUNK << PAGE_SHIFT;
  8379. +
  8380. + chunk = dma_alloc_from_contiguous(NULL /*&vc_cma_device.dev*/,
  8381. + PAGES_PER_CHUNK,
  8382. + VC_CMA_CHUNK_ORDER);
  8383. + if (!chunk)
  8384. + break;
  8385. +
  8386. + chunk_addr = page_address(chunk);
  8387. + dmac_flush_range(chunk_addr, chunk_addr + chunk_size);
  8388. + outer_inv_range(__pa(chunk_addr), __pa(chunk_addr) +
  8389. + chunk_size);
  8390. +
  8391. + chunk_num =
  8392. + (page_to_phys(chunk) - vc_cma_base) / VC_CMA_CHUNK_SIZE;
  8393. + BUG_ON(((page_to_phys(chunk) - vc_cma_base) %
  8394. + VC_CMA_CHUNK_SIZE) != 0);
  8395. + if (chunk_num >= vc_cma_chunks) {
  8396. + LOG_ERR("%s: ===============================",
  8397. + __func__);
  8398. + LOG_ERR("%s: chunk phys %x, vc_cma %x-%x - "
  8399. + "bad SPARSEMEM configuration?",
  8400. + __func__, (unsigned int)page_to_phys(chunk),
  8401. + vc_cma_base, vc_cma_base + vc_cma_size - 1);
  8402. + LOG_ERR("%s: dev->cma_area = %p\n", __func__,
  8403. + (void*)0/*vc_cma_device.dev.cma_area*/);
  8404. + LOG_ERR("%s: ===============================",
  8405. + __func__);
  8406. + break;
  8407. + }
  8408. + reply->params[i] = chunk_num;
  8409. + vc_cma_chunks_used++;
  8410. + }
  8411. +
  8412. + if (i < num_chunks) {
  8413. + LOG_ERR("%s: dma_alloc_from_contiguous failed "
  8414. + "for %x bytes (alloc %d of %d, %d free)",
  8415. + __func__, VC_CMA_CHUNK_SIZE, i,
  8416. + num_chunks, vc_cma_chunks - vc_cma_chunks_used);
  8417. + num_chunks = i;
  8418. + }
  8419. +
  8420. + LOG_DBG("CMA allocated %d chunks -> %d used",
  8421. + num_chunks, vc_cma_chunks_used);
  8422. + reply->type = VC_CMA_MSG_ALLOCATED;
  8423. +
  8424. + {
  8425. + VCHIQ_ELEMENT_T elem = {
  8426. + reply,
  8427. + offsetof(struct cma_msg, params[0]) +
  8428. + num_chunks * sizeof(reply->params[0])
  8429. + };
  8430. + VCHIQ_STATUS_T ret;
  8431. + vchiq_use_service(cma_service);
  8432. + ret = vchiq_queue_message(cma_service, &elem, 1);
  8433. + vchiq_release_service(cma_service);
  8434. + if (ret != VCHIQ_SUCCESS)
  8435. + LOG_ERR("vchiq_queue_message return " "%x", ret);
  8436. + }
  8437. +
  8438. + return num_chunks;
  8439. +}
  8440. +
  8441. +static int cma_worker_proc(void *param)
  8442. +{
  8443. + static struct cma_msg reply;
  8444. + (void)param;
  8445. +
  8446. + while (1) {
  8447. + VCHIQ_HEADER_T *msg;
  8448. + static struct cma_msg msg_copy;
  8449. + struct cma_msg *cma_msg = &msg_copy;
  8450. + int type, msg_size;
  8451. +
  8452. + msg = vchiu_queue_pop(&cma_msg_queue);
  8453. + if ((unsigned int)msg >= VC_CMA_MSG_MAX) {
  8454. + msg_size = msg->size;
  8455. + memcpy(&msg_copy, msg->data, msg_size);
  8456. + type = cma_msg->type;
  8457. + vchiq_release_message(cma_service, msg);
  8458. + } else {
  8459. + msg_size = 0;
  8460. + type = (int)msg;
  8461. + if (type == VC_CMA_MSG_QUIT)
  8462. + break;
  8463. + else if (type == VC_CMA_MSG_UPDATE_RESERVE) {
  8464. + msg = NULL;
  8465. + cma_msg = NULL;
  8466. + } else {
  8467. + BUG();
  8468. + continue;
  8469. + }
  8470. + }
  8471. +
  8472. + switch (type) {
  8473. + case VC_CMA_MSG_ALLOC:{
  8474. + int num_chunks, free_chunks;
  8475. + num_chunks = cma_msg->params[0];
  8476. + free_chunks =
  8477. + vc_cma_chunks - vc_cma_chunks_used;
  8478. + LOG_DBG("CMA_MSG_ALLOC(%d chunks)", num_chunks);
  8479. + if (num_chunks > VC_CMA_MAX_PARAMS_PER_MSG) {
  8480. + LOG_ERR
  8481. + ("CMA_MSG_ALLOC - chunk count (%d) "
  8482. + "exceeds VC_CMA_MAX_PARAMS_PER_MSG (%d)",
  8483. + num_chunks,
  8484. + VC_CMA_MAX_PARAMS_PER_MSG);
  8485. + num_chunks = VC_CMA_MAX_PARAMS_PER_MSG;
  8486. + }
  8487. +
  8488. + if (num_chunks > free_chunks) {
  8489. + LOG_ERR
  8490. + ("CMA_MSG_ALLOC - chunk count (%d) "
  8491. + "exceeds free chunks (%d)",
  8492. + num_chunks, free_chunks);
  8493. + num_chunks = free_chunks;
  8494. + }
  8495. +
  8496. + vc_cma_alloc_chunks(num_chunks, &reply);
  8497. + }
  8498. + break;
  8499. +
  8500. + case VC_CMA_MSG_FREE:{
  8501. + int chunk_count =
  8502. + (msg_size -
  8503. + offsetof(struct cma_msg,
  8504. + params)) /
  8505. + sizeof(cma_msg->params[0]);
  8506. + int i;
  8507. + BUG_ON(chunk_count <= 0);
  8508. +
  8509. + LOG_DBG("CMA_MSG_FREE(%d chunks - %x, ...)",
  8510. + chunk_count, cma_msg->params[0]);
  8511. + for (i = 0; i < chunk_count; i++) {
  8512. + int chunk_num = cma_msg->params[i];
  8513. + struct page *page = vc_cma_base_page +
  8514. + chunk_num * PAGES_PER_CHUNK;
  8515. + if (chunk_num >= vc_cma_chunks) {
  8516. + LOG_ERR
  8517. + ("CMA_MSG_FREE - chunk %d of %d"
  8518. + " (value %x) exceeds maximum "
  8519. + "(%x)", i, chunk_count,
  8520. + chunk_num,
  8521. + vc_cma_chunks - 1);
  8522. + break;
  8523. + }
  8524. +
  8525. + if (!dma_release_from_contiguous
  8526. + (NULL /*&vc_cma_device.dev*/, page,
  8527. + PAGES_PER_CHUNK)) {
  8528. + LOG_ERR
  8529. + ("CMA_MSG_FREE - failed to "
  8530. + "release chunk %d (phys %x, "
  8531. + "page %x)", chunk_num,
  8532. + page_to_phys(page),
  8533. + (unsigned int)page);
  8534. + }
  8535. + vc_cma_chunks_used--;
  8536. + }
  8537. + LOG_DBG("CMA released %d chunks -> %d used",
  8538. + i, vc_cma_chunks_used);
  8539. + }
  8540. + break;
  8541. +
  8542. + case VC_CMA_MSG_UPDATE_RESERVE:{
  8543. + int chunks_needed =
  8544. + ((vc_cma_reserve_total + VC_CMA_CHUNK_SIZE -
  8545. + 1)
  8546. + / VC_CMA_CHUNK_SIZE) -
  8547. + vc_cma_chunks_reserved;
  8548. +
  8549. + LOG_DBG
  8550. + ("CMA_MSG_UPDATE_RESERVE(%d chunks needed)",
  8551. + chunks_needed);
  8552. +
  8553. + /* Cap the reservations to what is available */
  8554. + if (chunks_needed > 0) {
  8555. + if (chunks_needed >
  8556. + (vc_cma_chunks -
  8557. + vc_cma_chunks_used))
  8558. + chunks_needed =
  8559. + (vc_cma_chunks -
  8560. + vc_cma_chunks_used);
  8561. +
  8562. + chunks_needed =
  8563. + vc_cma_alloc_chunks(chunks_needed,
  8564. + &reply);
  8565. + }
  8566. +
  8567. + LOG_DBG
  8568. + ("CMA_MSG_UPDATE_RESERVE(%d chunks allocated)",
  8569. + chunks_needed);
  8570. + vc_cma_chunks_reserved += chunks_needed;
  8571. + }
  8572. + break;
  8573. +
  8574. + default:
  8575. + LOG_ERR("unexpected msg type %d", type);
  8576. + break;
  8577. + }
  8578. + }
  8579. +
  8580. + LOG_DBG("quitting...");
  8581. + return 0;
  8582. +}
  8583. +
  8584. +/****************************************************************************
  8585. +*
  8586. +* vc_cma_connected_init
  8587. +*
  8588. +* This function is called once the videocore has been connected.
  8589. +*
  8590. +***************************************************************************/
  8591. +
  8592. +static void vc_cma_connected_init(void)
  8593. +{
  8594. + VCHIQ_SERVICE_PARAMS_T service_params;
  8595. +
  8596. + LOG_DBG("vc_cma_connected_init");
  8597. +
  8598. + if (!vchiu_queue_init(&cma_msg_queue, 16)) {
  8599. + LOG_ERR("could not create CMA msg queue");
  8600. + goto fail_queue;
  8601. + }
  8602. +
  8603. + if (vchiq_initialise(&cma_instance) != VCHIQ_SUCCESS)
  8604. + goto fail_vchiq_init;
  8605. +
  8606. + vchiq_connect(cma_instance);
  8607. +
  8608. + service_params.fourcc = VC_CMA_FOURCC;
  8609. + service_params.callback = cma_service_callback;
  8610. + service_params.userdata = NULL;
  8611. + service_params.version = VC_CMA_VERSION;
  8612. + service_params.version_min = VC_CMA_VERSION;
  8613. +
  8614. + if (vchiq_open_service(cma_instance, &service_params,
  8615. + &cma_service) != VCHIQ_SUCCESS) {
  8616. + LOG_ERR("failed to open service - already in use?");
  8617. + goto fail_vchiq_open;
  8618. + }
  8619. +
  8620. + vchiq_release_service(cma_service);
  8621. +
  8622. + cma_worker = kthread_create(cma_worker_proc, NULL, "cma_worker");
  8623. + if (!cma_worker) {
  8624. + LOG_ERR("could not create CMA worker thread");
  8625. + goto fail_worker;
  8626. + }
  8627. + set_user_nice(cma_worker, -20);
  8628. + wake_up_process(cma_worker);
  8629. +
  8630. + return;
  8631. +
  8632. +fail_worker:
  8633. + vchiq_close_service(cma_service);
  8634. +fail_vchiq_open:
  8635. + vchiq_shutdown(cma_instance);
  8636. +fail_vchiq_init:
  8637. + vchiu_queue_delete(&cma_msg_queue);
  8638. +fail_queue:
  8639. + return;
  8640. +}
  8641. +
  8642. +void
  8643. +loud_error_header(void)
  8644. +{
  8645. + if (in_loud_error)
  8646. + return;
  8647. +
  8648. + LOG_ERR("============================================================"
  8649. + "================");
  8650. + LOG_ERR("============================================================"
  8651. + "================");
  8652. + LOG_ERR("=====");
  8653. +
  8654. + in_loud_error = 1;
  8655. +}
  8656. +
  8657. +void
  8658. +loud_error_footer(void)
  8659. +{
  8660. + if (!in_loud_error)
  8661. + return;
  8662. +
  8663. + LOG_ERR("=====");
  8664. + LOG_ERR("============================================================"
  8665. + "================");
  8666. + LOG_ERR("============================================================"
  8667. + "================");
  8668. +
  8669. + in_loud_error = 0;
  8670. +}
  8671. +
  8672. +#if 1
  8673. +static int check_cma_config(void) { return 1; }
  8674. +#else
  8675. +static int
  8676. +read_vc_debug_var(VC_MEM_ACCESS_HANDLE_T handle,
  8677. + const char *symbol,
  8678. + void *buf, size_t bufsize)
  8679. +{
  8680. + VC_MEM_ADDR_T vcMemAddr;
  8681. + size_t vcMemSize;
  8682. + uint8_t *mapAddr;
  8683. + off_t vcMapAddr;
  8684. +
  8685. + if (!LookupVideoCoreSymbol(handle, symbol,
  8686. + &vcMemAddr,
  8687. + &vcMemSize)) {
  8688. + loud_error_header();
  8689. + loud_error(
  8690. + "failed to find VC symbol \"%s\".",
  8691. + symbol);
  8692. + loud_error_footer();
  8693. + return 0;
  8694. + }
  8695. +
  8696. + if (vcMemSize != bufsize) {
  8697. + loud_error_header();
  8698. + loud_error(
  8699. + "VC symbol \"%s\" is the wrong size.",
  8700. + symbol);
  8701. + loud_error_footer();
  8702. + return 0;
  8703. + }
  8704. +
  8705. + vcMapAddr = (off_t)vcMemAddr & VC_MEM_TO_ARM_ADDR_MASK;
  8706. + vcMapAddr += mm_vc_mem_phys_addr;
  8707. + mapAddr = ioremap_nocache(vcMapAddr, vcMemSize);
  8708. + if (mapAddr == 0) {
  8709. + loud_error_header();
  8710. + loud_error(
  8711. + "failed to ioremap \"%s\" @ 0x%x "
  8712. + "(phys: 0x%x, size: %u).",
  8713. + symbol,
  8714. + (unsigned int)vcMapAddr,
  8715. + (unsigned int)vcMemAddr,
  8716. + (unsigned int)vcMemSize);
  8717. + loud_error_footer();
  8718. + return 0;
  8719. + }
  8720. +
  8721. + memcpy(buf, mapAddr, bufsize);
  8722. + iounmap(mapAddr);
  8723. +
  8724. + return 1;
  8725. +}
  8726. +
  8727. +
  8728. +static int
  8729. +check_cma_config(void)
  8730. +{
  8731. + VC_MEM_ACCESS_HANDLE_T mem_hndl;
  8732. + VC_MEM_ADDR_T mempool_start;
  8733. + VC_MEM_ADDR_T mempool_end;
  8734. + VC_MEM_ADDR_T mempool_offline_start;
  8735. + VC_MEM_ADDR_T mempool_offline_end;
  8736. + VC_MEM_ADDR_T cam_alloc_base;
  8737. + VC_MEM_ADDR_T cam_alloc_size;
  8738. + VC_MEM_ADDR_T cam_alloc_end;
  8739. + int success = 0;
  8740. +
  8741. + if (OpenVideoCoreMemory(&mem_hndl) != 0)
  8742. + goto out;
  8743. +
  8744. + /* Read the relevant VideoCore variables */
  8745. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_START",
  8746. + &mempool_start,
  8747. + sizeof(mempool_start)))
  8748. + goto close;
  8749. +
  8750. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_END",
  8751. + &mempool_end,
  8752. + sizeof(mempool_end)))
  8753. + goto close;
  8754. +
  8755. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_OFFLINE_START",
  8756. + &mempool_offline_start,
  8757. + sizeof(mempool_offline_start)))
  8758. + goto close;
  8759. +
  8760. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_OFFLINE_END",
  8761. + &mempool_offline_end,
  8762. + sizeof(mempool_offline_end)))
  8763. + goto close;
  8764. +
  8765. + if (!read_vc_debug_var(mem_hndl, "cam_alloc_base",
  8766. + &cam_alloc_base,
  8767. + sizeof(cam_alloc_base)))
  8768. + goto close;
  8769. +
  8770. + if (!read_vc_debug_var(mem_hndl, "cam_alloc_size",
  8771. + &cam_alloc_size,
  8772. + sizeof(cam_alloc_size)))
  8773. + goto close;
  8774. +
  8775. + cam_alloc_end = cam_alloc_base + cam_alloc_size;
  8776. +
  8777. + success = 1;
  8778. +
  8779. + /* Now the sanity checks */
  8780. + if (!mempool_offline_start)
  8781. + mempool_offline_start = mempool_start;
  8782. + if (!mempool_offline_end)
  8783. + mempool_offline_end = mempool_end;
  8784. +
  8785. + if (VCADDR_TO_PHYSADDR(mempool_offline_start) != vc_cma_base) {
  8786. + loud_error_header();
  8787. + loud_error(
  8788. + "__MEMPOOL_OFFLINE_START(%x -> %lx) doesn't match "
  8789. + "vc_cma_base(%x)",
  8790. + mempool_offline_start,
  8791. + VCADDR_TO_PHYSADDR(mempool_offline_start),
  8792. + vc_cma_base);
  8793. + success = 0;
  8794. + }
  8795. +
  8796. + if (VCADDR_TO_PHYSADDR(mempool_offline_end) !=
  8797. + (vc_cma_base + vc_cma_size)) {
  8798. + loud_error_header();
  8799. + loud_error(
  8800. + "__MEMPOOL_OFFLINE_END(%x -> %lx) doesn't match "
  8801. + "vc_cma_base(%x) + vc_cma_size(%x) = %x",
  8802. + mempool_offline_start,
  8803. + VCADDR_TO_PHYSADDR(mempool_offline_end),
  8804. + vc_cma_base, vc_cma_size, vc_cma_base + vc_cma_size);
  8805. + success = 0;
  8806. + }
  8807. +
  8808. + if (mempool_end < mempool_start) {
  8809. + loud_error_header();
  8810. + loud_error(
  8811. + "__MEMPOOL_END(%x) must not be before "
  8812. + "__MEMPOOL_START(%x)",
  8813. + mempool_end,
  8814. + mempool_start);
  8815. + success = 0;
  8816. + }
  8817. +
  8818. + if (mempool_offline_end < mempool_offline_start) {
  8819. + loud_error_header();
  8820. + loud_error(
  8821. + "__MEMPOOL_OFFLINE_END(%x) must not be before "
  8822. + "__MEMPOOL_OFFLINE_START(%x)",
  8823. + mempool_offline_end,
  8824. + mempool_offline_start);
  8825. + success = 0;
  8826. + }
  8827. +
  8828. + if (mempool_offline_start < mempool_start) {
  8829. + loud_error_header();
  8830. + loud_error(
  8831. + "__MEMPOOL_OFFLINE_START(%x) must not be before "
  8832. + "__MEMPOOL_START(%x)",
  8833. + mempool_offline_start,
  8834. + mempool_start);
  8835. + success = 0;
  8836. + }
  8837. +
  8838. + if (mempool_offline_end > mempool_end) {
  8839. + loud_error_header();
  8840. + loud_error(
  8841. + "__MEMPOOL_OFFLINE_END(%x) must not be after "
  8842. + "__MEMPOOL_END(%x)",
  8843. + mempool_offline_end,
  8844. + mempool_end);
  8845. + success = 0;
  8846. + }
  8847. +
  8848. + if ((cam_alloc_base < mempool_end) &&
  8849. + (cam_alloc_end > mempool_start)) {
  8850. + loud_error_header();
  8851. + loud_error(
  8852. + "cam_alloc pool(%x-%x) overlaps "
  8853. + "mempool(%x-%x)",
  8854. + cam_alloc_base, cam_alloc_end,
  8855. + mempool_start, mempool_end);
  8856. + success = 0;
  8857. + }
  8858. +
  8859. + loud_error_footer();
  8860. +
  8861. +close:
  8862. + CloseVideoCoreMemory(mem_hndl);
  8863. +
  8864. +out:
  8865. + return success;
  8866. +}
  8867. +#endif
  8868. +
  8869. +static int vc_cma_init(void)
  8870. +{
  8871. + int rc = -EFAULT;
  8872. + struct device *dev;
  8873. +
  8874. + if (!check_cma_config())
  8875. + goto out_release;
  8876. +
  8877. + printk(KERN_INFO "vc-cma: Videocore CMA driver\n");
  8878. + printk(KERN_INFO "vc-cma: vc_cma_base = 0x%08x\n", vc_cma_base);
  8879. + printk(KERN_INFO "vc-cma: vc_cma_size = 0x%08x (%u MiB)\n",
  8880. + vc_cma_size, vc_cma_size / (1024 * 1024));
  8881. + printk(KERN_INFO "vc-cma: vc_cma_initial = 0x%08x (%u MiB)\n",
  8882. + vc_cma_initial, vc_cma_initial / (1024 * 1024));
  8883. +
  8884. + vc_cma_base_page = phys_to_page(vc_cma_base);
  8885. +
  8886. + if (vc_cma_chunks) {
  8887. + int chunks_needed = vc_cma_initial / VC_CMA_CHUNK_SIZE;
  8888. +
  8889. + for (vc_cma_chunks_used = 0;
  8890. + vc_cma_chunks_used < chunks_needed; vc_cma_chunks_used++) {
  8891. + struct page *chunk;
  8892. + chunk = dma_alloc_from_contiguous(NULL /*&vc_cma_device.dev*/,
  8893. + PAGES_PER_CHUNK,
  8894. + VC_CMA_CHUNK_ORDER);
  8895. + if (!chunk)
  8896. + break;
  8897. + BUG_ON(((page_to_phys(chunk) - vc_cma_base) %
  8898. + VC_CMA_CHUNK_SIZE) != 0);
  8899. + }
  8900. + if (vc_cma_chunks_used != chunks_needed) {
  8901. + LOG_ERR("%s: dma_alloc_from_contiguous failed (%d "
  8902. + "bytes, allocation %d of %d)",
  8903. + __func__, VC_CMA_CHUNK_SIZE,
  8904. + vc_cma_chunks_used, chunks_needed);
  8905. + goto out_release;
  8906. + }
  8907. +
  8908. + vchiq_add_connected_callback(vc_cma_connected_init);
  8909. + }
  8910. +
  8911. + rc = alloc_chrdev_region(&vc_cma_devnum, 0, 1, DRIVER_NAME);
  8912. + if (rc < 0) {
  8913. + LOG_ERR("%s: alloc_chrdev_region failed (rc=%d)", __func__, rc);
  8914. + goto out_release;
  8915. + }
  8916. +
  8917. + cdev_init(&vc_cma_cdev, &vc_cma_fops);
  8918. + rc = cdev_add(&vc_cma_cdev, vc_cma_devnum, 1);
  8919. + if (rc != 0) {
  8920. + LOG_ERR("%s: cdev_add failed (rc=%d)", __func__, rc);
  8921. + goto out_unregister;
  8922. + }
  8923. +
  8924. + vc_cma_class = class_create(THIS_MODULE, DRIVER_NAME);
  8925. + if (IS_ERR(vc_cma_class)) {
  8926. + rc = PTR_ERR(vc_cma_class);
  8927. + LOG_ERR("%s: class_create failed (rc=%d)", __func__, rc);
  8928. + goto out_cdev_del;
  8929. + }
  8930. +
  8931. + dev = device_create(vc_cma_class, NULL, vc_cma_devnum, NULL,
  8932. + DRIVER_NAME);
  8933. + if (IS_ERR(dev)) {
  8934. + rc = PTR_ERR(dev);
  8935. + LOG_ERR("%s: device_create failed (rc=%d)", __func__, rc);
  8936. + goto out_class_destroy;
  8937. + }
  8938. +
  8939. + vc_cma_proc_entry = proc_create(DRIVER_NAME, 0444, NULL, &vc_cma_proc_fops);
  8940. + if (vc_cma_proc_entry == NULL) {
  8941. + rc = -EFAULT;
  8942. + LOG_ERR("%s: proc_create failed", __func__);
  8943. + goto out_device_destroy;
  8944. + }
  8945. +
  8946. + vc_cma_inited = 1;
  8947. + return 0;
  8948. +
  8949. +out_device_destroy:
  8950. + device_destroy(vc_cma_class, vc_cma_devnum);
  8951. +
  8952. +out_class_destroy:
  8953. + class_destroy(vc_cma_class);
  8954. + vc_cma_class = NULL;
  8955. +
  8956. +out_cdev_del:
  8957. + cdev_del(&vc_cma_cdev);
  8958. +
  8959. +out_unregister:
  8960. + unregister_chrdev_region(vc_cma_devnum, 1);
  8961. +
  8962. +out_release:
  8963. + /* It is tempting to try to clean up by calling
  8964. + dma_release_from_contiguous for all allocated chunks, but it isn't
  8965. + a very safe thing to do. If vc_cma_initial is non-zero it is because
  8966. + VideoCore is already using that memory, so giving it back to Linux
  8967. + is likely to be fatal.
  8968. + */
  8969. + return -1;
  8970. +}
  8971. +
  8972. +/****************************************************************************
  8973. +*
  8974. +* vc_cma_exit
  8975. +*
  8976. +***************************************************************************/
  8977. +
  8978. +static void __exit vc_cma_exit(void)
  8979. +{
  8980. + LOG_DBG("%s: called", __func__);
  8981. +
  8982. + if (vc_cma_inited) {
  8983. + remove_proc_entry(DRIVER_NAME, NULL);
  8984. + device_destroy(vc_cma_class, vc_cma_devnum);
  8985. + class_destroy(vc_cma_class);
  8986. + cdev_del(&vc_cma_cdev);
  8987. + unregister_chrdev_region(vc_cma_devnum, 1);
  8988. + }
  8989. +}
  8990. +
  8991. +module_init(vc_cma_init);
  8992. +module_exit(vc_cma_exit);
  8993. +MODULE_LICENSE("GPL");
  8994. +MODULE_AUTHOR("Broadcom Corporation");
  8995. diff -Nur linux-3.12.26.orig/drivers/char/hw_random/bcm2708-rng.c linux-3.12.26/drivers/char/hw_random/bcm2708-rng.c
  8996. --- linux-3.12.26.orig/drivers/char/hw_random/bcm2708-rng.c 1970-01-01 01:00:00.000000000 +0100
  8997. +++ linux-3.12.26/drivers/char/hw_random/bcm2708-rng.c 2014-08-06 16:50:13.937957941 +0200
  8998. @@ -0,0 +1,117 @@
  8999. +/**
  9000. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  9001. + *
  9002. + * Redistribution and use in source and binary forms, with or without
  9003. + * modification, are permitted provided that the following conditions
  9004. + * are met:
  9005. + * 1. Redistributions of source code must retain the above copyright
  9006. + * notice, this list of conditions, and the following disclaimer,
  9007. + * without modification.
  9008. + * 2. Redistributions in binary form must reproduce the above copyright
  9009. + * notice, this list of conditions and the following disclaimer in the
  9010. + * documentation and/or other materials provided with the distribution.
  9011. + * 3. The names of the above-listed copyright holders may not be used
  9012. + * to endorse or promote products derived from this software without
  9013. + * specific prior written permission.
  9014. + *
  9015. + * ALTERNATIVELY, this software may be distributed under the terms of the
  9016. + * GNU General Public License ("GPL") version 2, as published by the Free
  9017. + * Software Foundation.
  9018. + *
  9019. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  9020. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  9021. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  9022. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  9023. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  9024. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  9025. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  9026. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  9027. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  9028. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  9029. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  9030. + */
  9031. +
  9032. +#include <linux/kernel.h>
  9033. +#include <linux/module.h>
  9034. +#include <linux/init.h>
  9035. +#include <linux/hw_random.h>
  9036. +#include <linux/printk.h>
  9037. +
  9038. +#include <asm/io.h>
  9039. +#include <mach/hardware.h>
  9040. +#include <mach/platform.h>
  9041. +
  9042. +#define RNG_CTRL (0x0)
  9043. +#define RNG_STATUS (0x4)
  9044. +#define RNG_DATA (0x8)
  9045. +#define RNG_FF_THRESHOLD (0xc)
  9046. +
  9047. +/* enable rng */
  9048. +#define RNG_RBGEN 0x1
  9049. +/* double speed, less random mode */
  9050. +#define RNG_RBG2X 0x2
  9051. +
  9052. +/* the initial numbers generated are "less random" so will be discarded */
  9053. +#define RNG_WARMUP_COUNT 0x40000
  9054. +
  9055. +static int bcm2708_rng_data_read(struct hwrng *rng, u32 *buffer)
  9056. +{
  9057. + void __iomem *rng_base = (void __iomem *)rng->priv;
  9058. + unsigned words;
  9059. + /* wait for a random number to be in fifo */
  9060. + do {
  9061. + words = __raw_readl(rng_base + RNG_STATUS)>>24;
  9062. + }
  9063. + while (words == 0);
  9064. + /* read the random number */
  9065. + *buffer = __raw_readl(rng_base + RNG_DATA);
  9066. + return 4;
  9067. +}
  9068. +
  9069. +static struct hwrng bcm2708_rng_ops = {
  9070. + .name = "bcm2708",
  9071. + .data_read = bcm2708_rng_data_read,
  9072. +};
  9073. +
  9074. +static int __init bcm2708_rng_init(void)
  9075. +{
  9076. + void __iomem *rng_base;
  9077. + int err;
  9078. +
  9079. + /* map peripheral */
  9080. + rng_base = ioremap(RNG_BASE, 0x10);
  9081. + pr_info("bcm2708_rng_init=%p\n", rng_base);
  9082. + if (!rng_base) {
  9083. + pr_err("bcm2708_rng_init failed to ioremap\n");
  9084. + return -ENOMEM;
  9085. + }
  9086. + bcm2708_rng_ops.priv = (unsigned long)rng_base;
  9087. + /* register driver */
  9088. + err = hwrng_register(&bcm2708_rng_ops);
  9089. + if (err) {
  9090. + pr_err("bcm2708_rng_init hwrng_register()=%d\n", err);
  9091. + iounmap(rng_base);
  9092. + } else {
  9093. + /* set warm-up count & enable */
  9094. + __raw_writel(RNG_WARMUP_COUNT, rng_base + RNG_STATUS);
  9095. + __raw_writel(RNG_RBGEN, rng_base + RNG_CTRL);
  9096. + }
  9097. + return err;
  9098. +}
  9099. +
  9100. +static void __exit bcm2708_rng_exit(void)
  9101. +{
  9102. + void __iomem *rng_base = (void __iomem *)bcm2708_rng_ops.priv;
  9103. + pr_info("bcm2708_rng_exit\n");
  9104. + /* disable rng hardware */
  9105. + __raw_writel(0, rng_base + RNG_CTRL);
  9106. + /* unregister driver */
  9107. + hwrng_unregister(&bcm2708_rng_ops);
  9108. + iounmap(rng_base);
  9109. +}
  9110. +
  9111. +module_init(bcm2708_rng_init);
  9112. +module_exit(bcm2708_rng_exit);
  9113. +
  9114. +MODULE_DESCRIPTION("BCM2708 H/W Random Number Generator (RNG) driver");
  9115. +MODULE_LICENSE("GPL and additional rights");
  9116. diff -Nur linux-3.12.26.orig/drivers/char/hw_random/Kconfig linux-3.12.26/drivers/char/hw_random/Kconfig
  9117. --- linux-3.12.26.orig/drivers/char/hw_random/Kconfig 2014-07-30 18:02:44.000000000 +0200
  9118. +++ linux-3.12.26/drivers/char/hw_random/Kconfig 2014-08-06 16:50:13.945958005 +0200
  9119. @@ -314,3 +314,14 @@
  9120. module will be called tpm-rng.
  9121. If unsure, say Y.
  9122. +
  9123. +config HW_RANDOM_BCM2708
  9124. + tristate "BCM2708 generic true random number generator support"
  9125. + depends on HW_RANDOM && ARCH_BCM2708
  9126. + ---help---
  9127. + This driver provides the kernel-side support for the BCM2708 hardware.
  9128. +
  9129. + To compile this driver as a module, choose M here: the
  9130. + module will be called bcm2708-rng.
  9131. +
  9132. + If unsure, say N.
  9133. diff -Nur linux-3.12.26.orig/drivers/char/hw_random/Makefile linux-3.12.26/drivers/char/hw_random/Makefile
  9134. --- linux-3.12.26.orig/drivers/char/hw_random/Makefile 2014-07-30 18:02:44.000000000 +0200
  9135. +++ linux-3.12.26/drivers/char/hw_random/Makefile 2014-08-06 16:50:13.945958005 +0200
  9136. @@ -27,3 +27,4 @@
  9137. obj-$(CONFIG_HW_RANDOM_EXYNOS) += exynos-rng.o
  9138. obj-$(CONFIG_HW_RANDOM_TPM) += tpm-rng.o
  9139. obj-$(CONFIG_HW_RANDOM_BCM2835) += bcm2835-rng.o
  9140. +obj-$(CONFIG_HW_RANDOM_BCM2708) += bcm2708-rng.o
  9141. diff -Nur linux-3.12.26.orig/drivers/char/ipmi/ipmi_bt_sm.c linux-3.12.26/drivers/char/ipmi/ipmi_bt_sm.c
  9142. --- linux-3.12.26.orig/drivers/char/ipmi/ipmi_bt_sm.c 2014-07-30 18:02:44.000000000 +0200
  9143. +++ linux-3.12.26/drivers/char/ipmi/ipmi_bt_sm.c 2014-08-06 16:50:13.961958130 +0200
  9144. @@ -352,7 +352,7 @@
  9145. static inline int read_all_bytes(struct si_sm_data *bt)
  9146. {
  9147. - unsigned int i;
  9148. + unsigned char i;
  9149. /*
  9150. * length is "framing info", minimum = 4: NetFn, Seq, Cmd, cCode.
  9151. diff -Nur linux-3.12.26.orig/drivers/char/Kconfig linux-3.12.26/drivers/char/Kconfig
  9152. --- linux-3.12.26.orig/drivers/char/Kconfig 2014-07-30 18:02:44.000000000 +0200
  9153. +++ linux-3.12.26/drivers/char/Kconfig 2014-08-06 16:50:14.009958507 +0200
  9154. @@ -574,6 +574,8 @@
  9155. source "drivers/s390/char/Kconfig"
  9156. +source "drivers/char/broadcom/Kconfig"
  9157. +
  9158. config MSM_SMD_PKT
  9159. bool "Enable device interface for some SMD packet ports"
  9160. default n
  9161. diff -Nur linux-3.12.26.orig/drivers/char/Makefile linux-3.12.26/drivers/char/Makefile
  9162. --- linux-3.12.26.orig/drivers/char/Makefile 2014-07-30 18:02:44.000000000 +0200
  9163. +++ linux-3.12.26/drivers/char/Makefile 2014-08-06 16:50:14.021958601 +0200
  9164. @@ -62,3 +62,5 @@
  9165. js-rtc-y = rtc.o
  9166. obj-$(CONFIG_TILE_SROM) += tile-srom.o
  9167. +
  9168. +obj-$(CONFIG_BRCM_CHAR_DRIVERS) += broadcom/
  9169. diff -Nur linux-3.12.26.orig/drivers/cpufreq/bcm2835-cpufreq.c linux-3.12.26/drivers/cpufreq/bcm2835-cpufreq.c
  9170. --- linux-3.12.26.orig/drivers/cpufreq/bcm2835-cpufreq.c 1970-01-01 01:00:00.000000000 +0100
  9171. +++ linux-3.12.26/drivers/cpufreq/bcm2835-cpufreq.c 2014-08-06 16:50:14.021958601 +0200
  9172. @@ -0,0 +1,239 @@
  9173. +/*****************************************************************************
  9174. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  9175. +*
  9176. +* Unless you and Broadcom execute a separate written software license
  9177. +* agreement governing use of this software, this software is licensed to you
  9178. +* under the terms of the GNU General Public License version 2, available at
  9179. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  9180. +*
  9181. +* Notwithstanding the above, under no circumstances may you combine this
  9182. +* software in any way with any other Broadcom software provided under a
  9183. +* license other than the GPL, without Broadcom's express prior written
  9184. +* consent.
  9185. +*****************************************************************************/
  9186. +
  9187. +/*****************************************************************************
  9188. +* FILENAME: bcm2835-cpufreq.h
  9189. +* DESCRIPTION: This driver dynamically manages the CPU Frequency of the ARM
  9190. +* processor. Messages are sent to Videocore either setting or requesting the
  9191. +* frequency of the ARM in order to match an appropiate frequency to the current
  9192. +* usage of the processor. The policy which selects the frequency to use is
  9193. +* defined in the kernel .config file, but can be changed during runtime.
  9194. +*****************************************************************************/
  9195. +
  9196. +/* ---------- INCLUDES ---------- */
  9197. +#include <linux/kernel.h>
  9198. +#include <linux/init.h>
  9199. +#include <linux/module.h>
  9200. +#include <linux/cpufreq.h>
  9201. +#include <mach/vcio.h>
  9202. +
  9203. +/* ---------- DEFINES ---------- */
  9204. +/*#define CPUFREQ_DEBUG_ENABLE*/ /* enable debugging */
  9205. +#define MODULE_NAME "bcm2835-cpufreq"
  9206. +
  9207. +#define VCMSG_ID_ARM_CLOCK 0x000000003 /* Clock/Voltage ID's */
  9208. +
  9209. +/* debug printk macros */
  9210. +#ifdef CPUFREQ_DEBUG_ENABLE
  9211. +#define print_debug(fmt,...) pr_debug("%s:%s:%d: "fmt, MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  9212. +#else
  9213. +#define print_debug(fmt,...)
  9214. +#endif
  9215. +#define print_err(fmt,...) pr_err("%s:%s:%d: "fmt, MODULE_NAME, __func__,__LINE__, ##__VA_ARGS__)
  9216. +#define print_info(fmt,...) pr_info("%s: "fmt, MODULE_NAME, ##__VA_ARGS__)
  9217. +
  9218. +/* tag part of the message */
  9219. +struct vc_msg_tag {
  9220. + uint32_t tag_id; /* the message id */
  9221. + uint32_t buffer_size; /* size of the buffer (which in this case is always 8 bytes) */
  9222. + uint32_t data_size; /* amount of data being sent or received */
  9223. + uint32_t dev_id; /* the ID of the clock/voltage to get or set */
  9224. + uint32_t val; /* the value (e.g. rate (in Hz)) to set */
  9225. +};
  9226. +
  9227. +/* message structure to be sent to videocore */
  9228. +struct vc_msg {
  9229. + uint32_t msg_size; /* simply, sizeof(struct vc_msg) */
  9230. + uint32_t request_code; /* holds various information like the success and number of bytes returned (refer to mailboxes wiki) */
  9231. + struct vc_msg_tag tag; /* the tag structure above to make */
  9232. + uint32_t end_tag; /* an end identifier, should be set to NULL */
  9233. +};
  9234. +
  9235. +/* ---------- GLOBALS ---------- */
  9236. +static struct cpufreq_driver bcm2835_cpufreq_driver; /* the cpufreq driver global */
  9237. +
  9238. +/*
  9239. + ===============================================
  9240. + clk_rate either gets or sets the clock rates.
  9241. + ===============================================
  9242. +*/
  9243. +static uint32_t bcm2835_cpufreq_set_clock(int cur_rate, int arm_rate)
  9244. +{
  9245. + int s, actual_rate=0;
  9246. + struct vc_msg msg;
  9247. +
  9248. + /* wipe all previous message data */
  9249. + memset(&msg, 0, sizeof msg);
  9250. +
  9251. + msg.msg_size = sizeof msg;
  9252. +
  9253. + msg.tag.tag_id = VCMSG_SET_CLOCK_RATE;
  9254. + msg.tag.buffer_size = 8;
  9255. + msg.tag.data_size = 8; /* we're sending the clock ID and the new rates which is a total of 2 words */
  9256. + msg.tag.dev_id = VCMSG_ID_ARM_CLOCK;
  9257. + msg.tag.val = arm_rate * 1000;
  9258. +
  9259. + /* send the message */
  9260. + s = bcm_mailbox_property(&msg, sizeof msg);
  9261. +
  9262. + /* check if it was all ok and return the rate in KHz */
  9263. + if (s == 0 && (msg.request_code & 0x80000000))
  9264. + actual_rate = msg.tag.val/1000;
  9265. +
  9266. + print_debug("Setting new frequency = %d -> %d (actual %d)\n", cur_rate, arm_rate, actual_rate);
  9267. + return actual_rate;
  9268. +}
  9269. +
  9270. +static uint32_t bcm2835_cpufreq_get_clock(int tag)
  9271. +{
  9272. + int s;
  9273. + int arm_rate = 0;
  9274. + struct vc_msg msg;
  9275. +
  9276. + /* wipe all previous message data */
  9277. + memset(&msg, 0, sizeof msg);
  9278. +
  9279. + msg.msg_size = sizeof msg;
  9280. + msg.tag.tag_id = tag;
  9281. + msg.tag.buffer_size = 8;
  9282. + msg.tag.data_size = 4; /* we're just sending the clock ID which is one word long */
  9283. + msg.tag.dev_id = VCMSG_ID_ARM_CLOCK;
  9284. +
  9285. + /* send the message */
  9286. + s = bcm_mailbox_property(&msg, sizeof msg);
  9287. +
  9288. + /* check if it was all ok and return the rate in KHz */
  9289. + if (s == 0 && (msg.request_code & 0x80000000))
  9290. + arm_rate = msg.tag.val/1000;
  9291. +
  9292. + print_debug("%s frequency = %d\n",
  9293. + tag == VCMSG_GET_CLOCK_RATE ? "Current":
  9294. + tag == VCMSG_GET_MIN_CLOCK ? "Min":
  9295. + tag == VCMSG_GET_MAX_CLOCK ? "Max":
  9296. + "Unexpected", arm_rate);
  9297. +
  9298. + return arm_rate;
  9299. +}
  9300. +
  9301. +/*
  9302. + ====================================================
  9303. + Module Initialisation registers the cpufreq driver
  9304. + ====================================================
  9305. +*/
  9306. +static int __init bcm2835_cpufreq_module_init(void)
  9307. +{
  9308. + print_debug("IN\n");
  9309. + return cpufreq_register_driver(&bcm2835_cpufreq_driver);
  9310. +}
  9311. +
  9312. +/*
  9313. + =============
  9314. + Module exit
  9315. + =============
  9316. +*/
  9317. +static void __exit bcm2835_cpufreq_module_exit(void)
  9318. +{
  9319. + print_debug("IN\n");
  9320. + cpufreq_unregister_driver(&bcm2835_cpufreq_driver);
  9321. + return;
  9322. +}
  9323. +
  9324. +/*
  9325. + ==============================================================
  9326. + Initialisation function sets up the CPU policy for first use
  9327. + ==============================================================
  9328. +*/
  9329. +static int bcm2835_cpufreq_driver_init(struct cpufreq_policy *policy)
  9330. +{
  9331. + /* measured value of how long it takes to change frequency */
  9332. + policy->cpuinfo.transition_latency = 355000; /* ns */
  9333. +
  9334. + /* now find out what the maximum and minimum frequencies are */
  9335. + policy->min = policy->cpuinfo.min_freq = bcm2835_cpufreq_get_clock(VCMSG_GET_MIN_CLOCK);
  9336. + policy->max = policy->cpuinfo.max_freq = bcm2835_cpufreq_get_clock(VCMSG_GET_MAX_CLOCK);
  9337. + policy->cur = bcm2835_cpufreq_get_clock(VCMSG_GET_CLOCK_RATE);
  9338. +
  9339. + print_info("min=%d max=%d cur=%d\n", policy->min, policy->max, policy->cur);
  9340. + return 0;
  9341. +}
  9342. +
  9343. +/*
  9344. + =================================================================================
  9345. + Target function chooses the most appropriate frequency from the table to enable
  9346. + =================================================================================
  9347. +*/
  9348. +
  9349. +static int bcm2835_cpufreq_driver_target(struct cpufreq_policy *policy, unsigned int target_freq, unsigned int relation)
  9350. +{
  9351. + unsigned int target = target_freq;
  9352. +#ifdef CPUFREQ_DEBUG_ENABLE
  9353. + unsigned int cur = policy->cur;
  9354. +#endif
  9355. + print_debug("%s: min=%d max=%d cur=%d target=%d\n",policy->governor->name,policy->min,policy->max,policy->cur,target_freq);
  9356. +
  9357. + /* if we are above min and using ondemand, then just use max */
  9358. + if (strcmp("ondemand", policy->governor->name)==0 && target > policy->min)
  9359. + target = policy->max;
  9360. + /* if the frequency is the same, just quit */
  9361. + if (target == policy->cur)
  9362. + return 0;
  9363. +
  9364. + /* otherwise were good to set the clock frequency */
  9365. + policy->cur = bcm2835_cpufreq_set_clock(policy->cur, target);
  9366. +
  9367. + if (!policy->cur)
  9368. + {
  9369. + print_err("Error occurred setting a new frequency (%d)!\n", target);
  9370. + policy->cur = bcm2835_cpufreq_get_clock(VCMSG_GET_CLOCK_RATE);
  9371. + return -EINVAL;
  9372. + }
  9373. + print_debug("Freq %d->%d (min=%d max=%d target=%d request=%d)\n", cur, policy->cur, policy->min, policy->max, target_freq, target);
  9374. + return 0;
  9375. +}
  9376. +
  9377. +static unsigned int bcm2835_cpufreq_driver_get(unsigned int cpu)
  9378. +{
  9379. + unsigned int actual_rate = bcm2835_cpufreq_get_clock(VCMSG_GET_CLOCK_RATE);
  9380. + print_debug("cpu=%d\n", actual_rate);
  9381. + return actual_rate;
  9382. +}
  9383. +
  9384. +/*
  9385. + =================================================================================
  9386. + Verify ensures that when a policy is changed, it is suitable for the CPU to use
  9387. + =================================================================================
  9388. +*/
  9389. +
  9390. +static int bcm2835_cpufreq_driver_verify(struct cpufreq_policy *policy)
  9391. +{
  9392. + print_info("switching to governor %s\n", policy->governor->name);
  9393. + return 0;
  9394. +}
  9395. +
  9396. +
  9397. +/* the CPUFreq driver */
  9398. +static struct cpufreq_driver bcm2835_cpufreq_driver = {
  9399. + .name = "BCM2835 CPUFreq",
  9400. + .init = bcm2835_cpufreq_driver_init,
  9401. + .verify = bcm2835_cpufreq_driver_verify,
  9402. + .target = bcm2835_cpufreq_driver_target,
  9403. + .get = bcm2835_cpufreq_driver_get
  9404. +};
  9405. +
  9406. +MODULE_AUTHOR("Dorian Peake and Dom Cobley");
  9407. +MODULE_DESCRIPTION("CPU frequency driver for BCM2835 chip");
  9408. +MODULE_LICENSE("GPL");
  9409. +
  9410. +module_init(bcm2835_cpufreq_module_init);
  9411. +module_exit(bcm2835_cpufreq_module_exit);
  9412. diff -Nur linux-3.12.26.orig/drivers/cpufreq/Kconfig.arm linux-3.12.26/drivers/cpufreq/Kconfig.arm
  9413. --- linux-3.12.26.orig/drivers/cpufreq/Kconfig.arm 2014-07-30 18:02:44.000000000 +0200
  9414. +++ linux-3.12.26/drivers/cpufreq/Kconfig.arm 2014-08-06 16:50:14.021958601 +0200
  9415. @@ -228,6 +228,14 @@
  9416. help
  9417. This adds the CPUFreq driver support for SPEAr SOCs.
  9418. +config ARM_BCM2835_CPUFREQ
  9419. + bool "BCM2835 Driver"
  9420. + default y
  9421. + help
  9422. + This adds the CPUFreq driver for BCM2835
  9423. +
  9424. + If in doubt, say N.
  9425. +
  9426. config ARM_TEGRA_CPUFREQ
  9427. bool "TEGRA CPUFreq support"
  9428. depends on ARCH_TEGRA
  9429. diff -Nur linux-3.12.26.orig/drivers/cpufreq/Makefile linux-3.12.26/drivers/cpufreq/Makefile
  9430. --- linux-3.12.26.orig/drivers/cpufreq/Makefile 2014-07-30 18:02:44.000000000 +0200
  9431. +++ linux-3.12.26/drivers/cpufreq/Makefile 2014-08-06 16:50:14.021958601 +0200
  9432. @@ -76,6 +76,7 @@
  9433. obj-$(CONFIG_ARM_SA1100_CPUFREQ) += sa1100-cpufreq.o
  9434. obj-$(CONFIG_ARM_SA1110_CPUFREQ) += sa1110-cpufreq.o
  9435. obj-$(CONFIG_ARM_SPEAR_CPUFREQ) += spear-cpufreq.o
  9436. +obj-$(CONFIG_ARM_BCM2835_CPUFREQ) += bcm2835-cpufreq.o
  9437. obj-$(CONFIG_ARM_TEGRA_CPUFREQ) += tegra-cpufreq.o
  9438. ##################################################################################
  9439. diff -Nur linux-3.12.26.orig/drivers/cpufreq/powernow-k6.c linux-3.12.26/drivers/cpufreq/powernow-k6.c
  9440. --- linux-3.12.26.orig/drivers/cpufreq/powernow-k6.c 2014-07-30 18:02:44.000000000 +0200
  9441. +++ linux-3.12.26/drivers/cpufreq/powernow-k6.c 2014-08-06 16:50:14.025958632 +0200
  9442. @@ -26,108 +26,41 @@
  9443. static unsigned int busfreq; /* FSB, in 10 kHz */
  9444. static unsigned int max_multiplier;
  9445. -static unsigned int param_busfreq = 0;
  9446. -static unsigned int param_max_multiplier = 0;
  9447. -
  9448. -module_param_named(max_multiplier, param_max_multiplier, uint, S_IRUGO);
  9449. -MODULE_PARM_DESC(max_multiplier, "Maximum multiplier (allowed values: 20 30 35 40 45 50 55 60)");
  9450. -
  9451. -module_param_named(bus_frequency, param_busfreq, uint, S_IRUGO);
  9452. -MODULE_PARM_DESC(bus_frequency, "Bus frequency in kHz");
  9453. /* Clock ratio multiplied by 10 - see table 27 in AMD#23446 */
  9454. static struct cpufreq_frequency_table clock_ratio[] = {
  9455. - {60, /* 110 -> 6.0x */ 0},
  9456. - {55, /* 011 -> 5.5x */ 0},
  9457. - {50, /* 001 -> 5.0x */ 0},
  9458. {45, /* 000 -> 4.5x */ 0},
  9459. + {50, /* 001 -> 5.0x */ 0},
  9460. {40, /* 010 -> 4.0x */ 0},
  9461. - {35, /* 111 -> 3.5x */ 0},
  9462. - {30, /* 101 -> 3.0x */ 0},
  9463. + {55, /* 011 -> 5.5x */ 0},
  9464. {20, /* 100 -> 2.0x */ 0},
  9465. + {30, /* 101 -> 3.0x */ 0},
  9466. + {60, /* 110 -> 6.0x */ 0},
  9467. + {35, /* 111 -> 3.5x */ 0},
  9468. {0, CPUFREQ_TABLE_END}
  9469. };
  9470. -static const u8 index_to_register[8] = { 6, 3, 1, 0, 2, 7, 5, 4 };
  9471. -static const u8 register_to_index[8] = { 3, 2, 4, 1, 7, 6, 0, 5 };
  9472. -
  9473. -static const struct {
  9474. - unsigned freq;
  9475. - unsigned mult;
  9476. -} usual_frequency_table[] = {
  9477. - { 400000, 40 }, // 100 * 4
  9478. - { 450000, 45 }, // 100 * 4.5
  9479. - { 475000, 50 }, // 95 * 5
  9480. - { 500000, 50 }, // 100 * 5
  9481. - { 506250, 45 }, // 112.5 * 4.5
  9482. - { 533500, 55 }, // 97 * 5.5
  9483. - { 550000, 55 }, // 100 * 5.5
  9484. - { 562500, 50 }, // 112.5 * 5
  9485. - { 570000, 60 }, // 95 * 6
  9486. - { 600000, 60 }, // 100 * 6
  9487. - { 618750, 55 }, // 112.5 * 5.5
  9488. - { 660000, 55 }, // 120 * 5.5
  9489. - { 675000, 60 }, // 112.5 * 6
  9490. - { 720000, 60 }, // 120 * 6
  9491. -};
  9492. -
  9493. -#define FREQ_RANGE 3000
  9494. /**
  9495. * powernow_k6_get_cpu_multiplier - returns the current FSB multiplier
  9496. *
  9497. - * Returns the current setting of the frequency multiplier. Core clock
  9498. + * Returns the current setting of the frequency multiplier. Core clock
  9499. * speed is frequency of the Front-Side Bus multiplied with this value.
  9500. */
  9501. static int powernow_k6_get_cpu_multiplier(void)
  9502. {
  9503. - unsigned long invalue = 0;
  9504. + u64 invalue = 0;
  9505. u32 msrval;
  9506. - local_irq_disable();
  9507. -
  9508. msrval = POWERNOW_IOPORT + 0x1;
  9509. wrmsr(MSR_K6_EPMR, msrval, 0); /* enable the PowerNow port */
  9510. invalue = inl(POWERNOW_IOPORT + 0x8);
  9511. msrval = POWERNOW_IOPORT + 0x0;
  9512. wrmsr(MSR_K6_EPMR, msrval, 0); /* disable it again */
  9513. - local_irq_enable();
  9514. -
  9515. - return clock_ratio[register_to_index[(invalue >> 5)&7]].driver_data;
  9516. + return clock_ratio[(invalue >> 5)&7].driver_data;
  9517. }
  9518. -static void powernow_k6_set_cpu_multiplier(unsigned int best_i)
  9519. -{
  9520. - unsigned long outvalue, invalue;
  9521. - unsigned long msrval;
  9522. - unsigned long cr0;
  9523. -
  9524. - /* we now need to transform best_i to the BVC format, see AMD#23446 */
  9525. -
  9526. - /*
  9527. - * The processor doesn't respond to inquiry cycles while changing the
  9528. - * frequency, so we must disable cache.
  9529. - */
  9530. - local_irq_disable();
  9531. - cr0 = read_cr0();
  9532. - write_cr0(cr0 | X86_CR0_CD);
  9533. - wbinvd();
  9534. -
  9535. - outvalue = (1<<12) | (1<<10) | (1<<9) | (index_to_register[best_i]<<5);
  9536. -
  9537. - msrval = POWERNOW_IOPORT + 0x1;
  9538. - wrmsr(MSR_K6_EPMR, msrval, 0); /* enable the PowerNow port */
  9539. - invalue = inl(POWERNOW_IOPORT + 0x8);
  9540. - invalue = invalue & 0x1f;
  9541. - outvalue = outvalue | invalue;
  9542. - outl(outvalue, (POWERNOW_IOPORT + 0x8));
  9543. - msrval = POWERNOW_IOPORT + 0x0;
  9544. - wrmsr(MSR_K6_EPMR, msrval, 0); /* disable it again */
  9545. -
  9546. - write_cr0(cr0);
  9547. - local_irq_enable();
  9548. -}
  9549. /**
  9550. * powernow_k6_set_state - set the PowerNow! multiplier
  9551. @@ -138,6 +71,8 @@
  9552. static void powernow_k6_set_state(struct cpufreq_policy *policy,
  9553. unsigned int best_i)
  9554. {
  9555. + unsigned long outvalue = 0, invalue = 0;
  9556. + unsigned long msrval;
  9557. struct cpufreq_freqs freqs;
  9558. if (clock_ratio[best_i].driver_data > max_multiplier) {
  9559. @@ -150,7 +85,18 @@
  9560. cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE);
  9561. - powernow_k6_set_cpu_multiplier(best_i);
  9562. + /* we now need to transform best_i to the BVC format, see AMD#23446 */
  9563. +
  9564. + outvalue = (1<<12) | (1<<10) | (1<<9) | (best_i<<5);
  9565. +
  9566. + msrval = POWERNOW_IOPORT + 0x1;
  9567. + wrmsr(MSR_K6_EPMR, msrval, 0); /* enable the PowerNow port */
  9568. + invalue = inl(POWERNOW_IOPORT + 0x8);
  9569. + invalue = invalue & 0xf;
  9570. + outvalue = outvalue | invalue;
  9571. + outl(outvalue , (POWERNOW_IOPORT + 0x8));
  9572. + msrval = POWERNOW_IOPORT + 0x0;
  9573. + wrmsr(MSR_K6_EPMR, msrval, 0); /* disable it again */
  9574. cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE);
  9575. @@ -195,57 +141,18 @@
  9576. return 0;
  9577. }
  9578. +
  9579. static int powernow_k6_cpu_init(struct cpufreq_policy *policy)
  9580. {
  9581. unsigned int i, f;
  9582. int result;
  9583. - unsigned khz;
  9584. if (policy->cpu != 0)
  9585. return -ENODEV;
  9586. - max_multiplier = 0;
  9587. - khz = cpu_khz;
  9588. - for (i = 0; i < ARRAY_SIZE(usual_frequency_table); i++) {
  9589. - if (khz >= usual_frequency_table[i].freq - FREQ_RANGE &&
  9590. - khz <= usual_frequency_table[i].freq + FREQ_RANGE) {
  9591. - khz = usual_frequency_table[i].freq;
  9592. - max_multiplier = usual_frequency_table[i].mult;
  9593. - break;
  9594. - }
  9595. - }
  9596. - if (param_max_multiplier) {
  9597. - for (i = 0; (clock_ratio[i].frequency != CPUFREQ_TABLE_END); i++) {
  9598. - if (clock_ratio[i].driver_data == param_max_multiplier) {
  9599. - max_multiplier = param_max_multiplier;
  9600. - goto have_max_multiplier;
  9601. - }
  9602. - }
  9603. - printk(KERN_ERR "powernow-k6: invalid max_multiplier parameter, valid parameters 20, 30, 35, 40, 45, 50, 55, 60\n");
  9604. - return -EINVAL;
  9605. - }
  9606. -
  9607. - if (!max_multiplier) {
  9608. - printk(KERN_WARNING "powernow-k6: unknown frequency %u, cannot determine current multiplier\n", khz);
  9609. - printk(KERN_WARNING "powernow-k6: use module parameters max_multiplier and bus_frequency\n");
  9610. - return -EOPNOTSUPP;
  9611. - }
  9612. -
  9613. -have_max_multiplier:
  9614. - param_max_multiplier = max_multiplier;
  9615. -
  9616. - if (param_busfreq) {
  9617. - if (param_busfreq >= 50000 && param_busfreq <= 150000) {
  9618. - busfreq = param_busfreq / 10;
  9619. - goto have_busfreq;
  9620. - }
  9621. - printk(KERN_ERR "powernow-k6: invalid bus_frequency parameter, allowed range 50000 - 150000 kHz\n");
  9622. - return -EINVAL;
  9623. - }
  9624. -
  9625. - busfreq = khz / max_multiplier;
  9626. -have_busfreq:
  9627. - param_busfreq = busfreq * 10;
  9628. + /* get frequencies */
  9629. + max_multiplier = powernow_k6_get_cpu_multiplier();
  9630. + busfreq = cpu_khz / max_multiplier;
  9631. /* table init */
  9632. for (i = 0; (clock_ratio[i].frequency != CPUFREQ_TABLE_END); i++) {
  9633. @@ -257,7 +164,7 @@
  9634. }
  9635. /* cpuinfo and default policy values */
  9636. - policy->cpuinfo.transition_latency = 500000;
  9637. + policy->cpuinfo.transition_latency = 200000;
  9638. policy->cur = busfreq * max_multiplier;
  9639. result = cpufreq_frequency_table_cpuinfo(policy, clock_ratio);
  9640. diff -Nur linux-3.12.26.orig/drivers/dma/bcm2708-dmaengine.c linux-3.12.26/drivers/dma/bcm2708-dmaengine.c
  9641. --- linux-3.12.26.orig/drivers/dma/bcm2708-dmaengine.c 1970-01-01 01:00:00.000000000 +0100
  9642. +++ linux-3.12.26/drivers/dma/bcm2708-dmaengine.c 2014-08-06 16:50:14.025958632 +0200
  9643. @@ -0,0 +1,588 @@
  9644. +/*
  9645. + * BCM2708 DMA engine support
  9646. + *
  9647. + * This driver only supports cyclic DMA transfers
  9648. + * as needed for the I2S module.
  9649. + *
  9650. + * Author: Florian Meier <florian.meier@koalo.de>
  9651. + * Copyright 2013
  9652. + *
  9653. + * Based on
  9654. + * OMAP DMAengine support by Russell King
  9655. + *
  9656. + * BCM2708 DMA Driver
  9657. + * Copyright (C) 2010 Broadcom
  9658. + *
  9659. + * Raspberry Pi PCM I2S ALSA Driver
  9660. + * Copyright (c) by Phil Poole 2013
  9661. + *
  9662. + * MARVELL MMP Peripheral DMA Driver
  9663. + * Copyright 2012 Marvell International Ltd.
  9664. + *
  9665. + * This program is free software; you can redistribute it and/or modify
  9666. + * it under the terms of the GNU General Public License as published by
  9667. + * the Free Software Foundation; either version 2 of the License, or
  9668. + * (at your option) any later version.
  9669. + *
  9670. + * This program is distributed in the hope that it will be useful,
  9671. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9672. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9673. + * GNU General Public License for more details.
  9674. + */
  9675. +#include <linux/dmaengine.h>
  9676. +#include <linux/dma-mapping.h>
  9677. +#include <linux/err.h>
  9678. +#include <linux/init.h>
  9679. +#include <linux/interrupt.h>
  9680. +#include <linux/list.h>
  9681. +#include <linux/module.h>
  9682. +#include <linux/platform_device.h>
  9683. +#include <linux/slab.h>
  9684. +#include <linux/io.h>
  9685. +#include <linux/spinlock.h>
  9686. +#include <linux/irq.h>
  9687. +
  9688. +#include "virt-dma.h"
  9689. +
  9690. +#include <mach/dma.h>
  9691. +#include <mach/irqs.h>
  9692. +
  9693. +struct bcm2708_dmadev {
  9694. + struct dma_device ddev;
  9695. + spinlock_t lock;
  9696. + void __iomem *base;
  9697. + struct device_dma_parameters dma_parms;
  9698. +};
  9699. +
  9700. +struct bcm2708_chan {
  9701. + struct virt_dma_chan vc;
  9702. + struct list_head node;
  9703. +
  9704. + struct dma_slave_config cfg;
  9705. + bool cyclic;
  9706. +
  9707. + int ch;
  9708. + struct bcm2708_desc *desc;
  9709. +
  9710. + void __iomem *chan_base;
  9711. + int irq_number;
  9712. +};
  9713. +
  9714. +struct bcm2708_desc {
  9715. + struct virt_dma_desc vd;
  9716. + enum dma_transfer_direction dir;
  9717. +
  9718. + unsigned int control_block_size;
  9719. + struct bcm2708_dma_cb *control_block_base;
  9720. + dma_addr_t control_block_base_phys;
  9721. +
  9722. + unsigned frames;
  9723. + size_t size;
  9724. +};
  9725. +
  9726. +#define BCM2708_DMA_DATA_TYPE_S8 1
  9727. +#define BCM2708_DMA_DATA_TYPE_S16 2
  9728. +#define BCM2708_DMA_DATA_TYPE_S32 4
  9729. +#define BCM2708_DMA_DATA_TYPE_S128 16
  9730. +
  9731. +static inline struct bcm2708_dmadev *to_bcm2708_dma_dev(struct dma_device *d)
  9732. +{
  9733. + return container_of(d, struct bcm2708_dmadev, ddev);
  9734. +}
  9735. +
  9736. +static inline struct bcm2708_chan *to_bcm2708_dma_chan(struct dma_chan *c)
  9737. +{
  9738. + return container_of(c, struct bcm2708_chan, vc.chan);
  9739. +}
  9740. +
  9741. +static inline struct bcm2708_desc *to_bcm2708_dma_desc(
  9742. + struct dma_async_tx_descriptor *t)
  9743. +{
  9744. + return container_of(t, struct bcm2708_desc, vd.tx);
  9745. +}
  9746. +
  9747. +static void bcm2708_dma_desc_free(struct virt_dma_desc *vd)
  9748. +{
  9749. + struct bcm2708_desc *desc = container_of(vd, struct bcm2708_desc, vd);
  9750. + dma_free_coherent(desc->vd.tx.chan->device->dev,
  9751. + desc->control_block_size,
  9752. + desc->control_block_base,
  9753. + desc->control_block_base_phys);
  9754. + kfree(desc);
  9755. +}
  9756. +
  9757. +static void bcm2708_dma_start_desc(struct bcm2708_chan *c)
  9758. +{
  9759. + struct virt_dma_desc *vd = vchan_next_desc(&c->vc);
  9760. + struct bcm2708_desc *d;
  9761. +
  9762. + if (!vd) {
  9763. + c->desc = NULL;
  9764. + return;
  9765. + }
  9766. +
  9767. + list_del(&vd->node);
  9768. +
  9769. + c->desc = d = to_bcm2708_dma_desc(&vd->tx);
  9770. +
  9771. + bcm_dma_start(c->chan_base, d->control_block_base_phys);
  9772. +}
  9773. +
  9774. +static irqreturn_t bcm2708_dma_callback(int irq, void *data)
  9775. +{
  9776. + struct bcm2708_chan *c = data;
  9777. + struct bcm2708_desc *d;
  9778. + unsigned long flags;
  9779. +
  9780. + spin_lock_irqsave(&c->vc.lock, flags);
  9781. +
  9782. + /* Acknowledge interrupt */
  9783. + writel(BCM2708_DMA_INT, c->chan_base + BCM2708_DMA_CS);
  9784. +
  9785. + d = c->desc;
  9786. +
  9787. + if (d) {
  9788. + /* TODO Only works for cyclic DMA */
  9789. + vchan_cyclic_callback(&d->vd);
  9790. + }
  9791. +
  9792. + /* Keep the DMA engine running */
  9793. + dsb(); /* ARM synchronization barrier */
  9794. + writel(BCM2708_DMA_ACTIVE, c->chan_base + BCM2708_DMA_CS);
  9795. +
  9796. + spin_unlock_irqrestore(&c->vc.lock, flags);
  9797. +
  9798. + return IRQ_HANDLED;
  9799. +}
  9800. +
  9801. +static int bcm2708_dma_alloc_chan_resources(struct dma_chan *chan)
  9802. +{
  9803. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  9804. +
  9805. + return request_irq(c->irq_number,
  9806. + bcm2708_dma_callback, 0, "DMA IRQ", c);
  9807. +}
  9808. +
  9809. +static void bcm2708_dma_free_chan_resources(struct dma_chan *chan)
  9810. +{
  9811. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  9812. +
  9813. + vchan_free_chan_resources(&c->vc);
  9814. + free_irq(c->irq_number, c);
  9815. +
  9816. + dev_dbg(c->vc.chan.device->dev, "Freeing DMA channel %u\n", c->ch);
  9817. +}
  9818. +
  9819. +static size_t bcm2708_dma_desc_size(struct bcm2708_desc *d)
  9820. +{
  9821. + return d->size;
  9822. +}
  9823. +
  9824. +static size_t bcm2708_dma_desc_size_pos(struct bcm2708_desc *d, dma_addr_t addr)
  9825. +{
  9826. + unsigned i;
  9827. + size_t size;
  9828. +
  9829. + for (size = i = 0; i < d->frames; i++) {
  9830. + struct bcm2708_dma_cb *control_block =
  9831. + &d->control_block_base[i];
  9832. + size_t this_size = control_block->length;
  9833. + dma_addr_t dma;
  9834. +
  9835. + if (d->dir == DMA_DEV_TO_MEM)
  9836. + dma = control_block->dst;
  9837. + else
  9838. + dma = control_block->src;
  9839. +
  9840. + if (size)
  9841. + size += this_size;
  9842. + else if (addr >= dma && addr < dma + this_size)
  9843. + size += dma + this_size - addr;
  9844. + }
  9845. +
  9846. + return size;
  9847. +}
  9848. +
  9849. +static enum dma_status bcm2708_dma_tx_status(struct dma_chan *chan,
  9850. + dma_cookie_t cookie, struct dma_tx_state *txstate)
  9851. +{
  9852. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  9853. + struct virt_dma_desc *vd;
  9854. + enum dma_status ret;
  9855. + unsigned long flags;
  9856. +
  9857. + ret = dma_cookie_status(chan, cookie, txstate);
  9858. + if (ret == DMA_SUCCESS || !txstate)
  9859. + return ret;
  9860. +
  9861. + spin_lock_irqsave(&c->vc.lock, flags);
  9862. + vd = vchan_find_desc(&c->vc, cookie);
  9863. + if (vd) {
  9864. + txstate->residue =
  9865. + bcm2708_dma_desc_size(to_bcm2708_dma_desc(&vd->tx));
  9866. + } else if (c->desc && c->desc->vd.tx.cookie == cookie) {
  9867. + struct bcm2708_desc *d = c->desc;
  9868. + dma_addr_t pos;
  9869. +
  9870. + if (d->dir == DMA_MEM_TO_DEV)
  9871. + pos = readl(c->chan_base + BCM2708_DMA_SOURCE_AD);
  9872. + else if (d->dir == DMA_DEV_TO_MEM)
  9873. + pos = readl(c->chan_base + BCM2708_DMA_DEST_AD);
  9874. + else
  9875. + pos = 0;
  9876. +
  9877. + txstate->residue = bcm2708_dma_desc_size_pos(d, pos);
  9878. + } else {
  9879. + txstate->residue = 0;
  9880. + }
  9881. +
  9882. + spin_unlock_irqrestore(&c->vc.lock, flags);
  9883. +
  9884. + return ret;
  9885. +}
  9886. +
  9887. +static void bcm2708_dma_issue_pending(struct dma_chan *chan)
  9888. +{
  9889. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  9890. + unsigned long flags;
  9891. +
  9892. + c->cyclic = true; /* Nothing else is implemented */
  9893. +
  9894. + spin_lock_irqsave(&c->vc.lock, flags);
  9895. + if (vchan_issue_pending(&c->vc) && !c->desc)
  9896. + bcm2708_dma_start_desc(c);
  9897. +
  9898. + spin_unlock_irqrestore(&c->vc.lock, flags);
  9899. +}
  9900. +
  9901. +static struct dma_async_tx_descriptor *bcm2708_dma_prep_dma_cyclic(
  9902. + struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len,
  9903. + size_t period_len, enum dma_transfer_direction direction,
  9904. + unsigned long flags, void *context)
  9905. +{
  9906. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  9907. + enum dma_slave_buswidth dev_width;
  9908. + struct bcm2708_desc *d;
  9909. + dma_addr_t dev_addr;
  9910. + unsigned es, sync_type;
  9911. + unsigned frame;
  9912. +
  9913. + /* Grab configuration */
  9914. + if (direction == DMA_DEV_TO_MEM) {
  9915. + dev_addr = c->cfg.src_addr;
  9916. + dev_width = c->cfg.src_addr_width;
  9917. + sync_type = BCM2708_DMA_S_DREQ;
  9918. + } else if (direction == DMA_MEM_TO_DEV) {
  9919. + dev_addr = c->cfg.dst_addr;
  9920. + dev_width = c->cfg.dst_addr_width;
  9921. + sync_type = BCM2708_DMA_D_DREQ;
  9922. + } else {
  9923. + dev_err(chan->device->dev, "%s: bad direction?\n", __func__);
  9924. + return NULL;
  9925. + }
  9926. +
  9927. + /* Bus width translates to the element size (ES) */
  9928. + switch (dev_width) {
  9929. + case DMA_SLAVE_BUSWIDTH_4_BYTES:
  9930. + es = BCM2708_DMA_DATA_TYPE_S32;
  9931. + break;
  9932. + default:
  9933. + return NULL;
  9934. + }
  9935. +
  9936. + /* Now allocate and setup the descriptor. */
  9937. + d = kzalloc(sizeof(*d), GFP_NOWAIT);
  9938. + if (!d)
  9939. + return NULL;
  9940. +
  9941. + d->dir = direction;
  9942. + d->frames = buf_len / period_len;
  9943. +
  9944. + /* Allocate memory for control blocks */
  9945. + d->control_block_size = d->frames * sizeof(struct bcm2708_dma_cb);
  9946. + d->control_block_base = dma_zalloc_coherent(chan->device->dev,
  9947. + d->control_block_size, &d->control_block_base_phys,
  9948. + GFP_NOWAIT);
  9949. +
  9950. + if (!d->control_block_base) {
  9951. + kfree(d);
  9952. + return NULL;
  9953. + }
  9954. +
  9955. + /*
  9956. + * Iterate over all frames, create a control block
  9957. + * for each frame and link them together.
  9958. + */
  9959. + for (frame = 0; frame < d->frames; frame++) {
  9960. + struct bcm2708_dma_cb *control_block =
  9961. + &d->control_block_base[frame];
  9962. +
  9963. + /* Setup adresses */
  9964. + if (d->dir == DMA_DEV_TO_MEM) {
  9965. + control_block->info = BCM2708_DMA_D_INC;
  9966. + control_block->src = dev_addr;
  9967. + control_block->dst = buf_addr + frame * period_len;
  9968. + } else {
  9969. + control_block->info = BCM2708_DMA_S_INC;
  9970. + control_block->src = buf_addr + frame * period_len;
  9971. + control_block->dst = dev_addr;
  9972. + }
  9973. +
  9974. + /* Enable interrupt */
  9975. + control_block->info |= BCM2708_DMA_INT_EN;
  9976. +
  9977. + /* Setup synchronization */
  9978. + if (sync_type != 0)
  9979. + control_block->info |= sync_type;
  9980. +
  9981. + /* Setup DREQ channel */
  9982. + if (c->cfg.slave_id != 0)
  9983. + control_block->info |=
  9984. + BCM2708_DMA_PER_MAP(c->cfg.slave_id);
  9985. +
  9986. + /* Length of a frame */
  9987. + control_block->length = period_len;
  9988. + d->size += control_block->length;
  9989. +
  9990. + /*
  9991. + * Next block is the next frame.
  9992. + * This DMA engine driver currently only supports cyclic DMA.
  9993. + * Therefore, wrap around at number of frames.
  9994. + */
  9995. + control_block->next = d->control_block_base_phys +
  9996. + sizeof(struct bcm2708_dma_cb)
  9997. + * ((frame + 1) % d->frames);
  9998. + }
  9999. +
  10000. + return vchan_tx_prep(&c->vc, &d->vd, flags);
  10001. +}
  10002. +
  10003. +static int bcm2708_dma_slave_config(struct bcm2708_chan *c,
  10004. + struct dma_slave_config *cfg)
  10005. +{
  10006. + if ((cfg->direction == DMA_DEV_TO_MEM &&
  10007. + cfg->src_addr_width != DMA_SLAVE_BUSWIDTH_4_BYTES) ||
  10008. + (cfg->direction == DMA_MEM_TO_DEV &&
  10009. + cfg->dst_addr_width != DMA_SLAVE_BUSWIDTH_4_BYTES) ||
  10010. + !is_slave_direction(cfg->direction)) {
  10011. + return -EINVAL;
  10012. + }
  10013. +
  10014. + c->cfg = *cfg;
  10015. +
  10016. + return 0;
  10017. +}
  10018. +
  10019. +static int bcm2708_dma_terminate_all(struct bcm2708_chan *c)
  10020. +{
  10021. + struct bcm2708_dmadev *d = to_bcm2708_dma_dev(c->vc.chan.device);
  10022. + unsigned long flags;
  10023. + int timeout = 10000;
  10024. + LIST_HEAD(head);
  10025. +
  10026. + spin_lock_irqsave(&c->vc.lock, flags);
  10027. +
  10028. + /* Prevent this channel being scheduled */
  10029. + spin_lock(&d->lock);
  10030. + list_del_init(&c->node);
  10031. + spin_unlock(&d->lock);
  10032. +
  10033. + /*
  10034. + * Stop DMA activity: we assume the callback will not be called
  10035. + * after bcm_dma_abort() returns (even if it does, it will see
  10036. + * c->desc is NULL and exit.)
  10037. + */
  10038. + if (c->desc) {
  10039. + c->desc = NULL;
  10040. + bcm_dma_abort(c->chan_base);
  10041. +
  10042. + /* Wait for stopping */
  10043. + while (timeout > 0) {
  10044. + timeout--;
  10045. + if (!(readl(c->chan_base + BCM2708_DMA_CS) &
  10046. + BCM2708_DMA_ACTIVE))
  10047. + break;
  10048. +
  10049. + cpu_relax();
  10050. + }
  10051. +
  10052. + if (timeout <= 0)
  10053. + dev_err(d->ddev.dev, "DMA transfer could not be terminated\n");
  10054. + }
  10055. +
  10056. + vchan_get_all_descriptors(&c->vc, &head);
  10057. + spin_unlock_irqrestore(&c->vc.lock, flags);
  10058. + vchan_dma_desc_free_list(&c->vc, &head);
  10059. +
  10060. + return 0;
  10061. +}
  10062. +
  10063. +static int bcm2708_dma_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
  10064. + unsigned long arg)
  10065. +{
  10066. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  10067. +
  10068. + switch (cmd) {
  10069. + case DMA_SLAVE_CONFIG:
  10070. + return bcm2708_dma_slave_config(c,
  10071. + (struct dma_slave_config *)arg);
  10072. +
  10073. + case DMA_TERMINATE_ALL:
  10074. + return bcm2708_dma_terminate_all(c);
  10075. +
  10076. + default:
  10077. + return -ENXIO;
  10078. + }
  10079. +}
  10080. +
  10081. +static int bcm2708_dma_chan_init(struct bcm2708_dmadev *d, void __iomem* chan_base,
  10082. + int chan_id, int irq)
  10083. +{
  10084. + struct bcm2708_chan *c;
  10085. +
  10086. + c = devm_kzalloc(d->ddev.dev, sizeof(*c), GFP_KERNEL);
  10087. + if (!c)
  10088. + return -ENOMEM;
  10089. +
  10090. + c->vc.desc_free = bcm2708_dma_desc_free;
  10091. + vchan_init(&c->vc, &d->ddev);
  10092. + INIT_LIST_HEAD(&c->node);
  10093. +
  10094. + d->ddev.chancnt++;
  10095. +
  10096. + c->chan_base = chan_base;
  10097. + c->ch = chan_id;
  10098. + c->irq_number = irq;
  10099. +
  10100. + return 0;
  10101. +}
  10102. +
  10103. +static void bcm2708_dma_free(struct bcm2708_dmadev *od)
  10104. +{
  10105. + while (!list_empty(&od->ddev.channels)) {
  10106. + struct bcm2708_chan *c = list_first_entry(&od->ddev.channels,
  10107. + struct bcm2708_chan, vc.chan.device_node);
  10108. +
  10109. + list_del(&c->vc.chan.device_node);
  10110. + tasklet_kill(&c->vc.task);
  10111. + }
  10112. +}
  10113. +
  10114. +static int bcm2708_dma_probe(struct platform_device *pdev)
  10115. +{
  10116. + struct bcm2708_dmadev *od;
  10117. + int rc, i;
  10118. +
  10119. + if (!pdev->dev.dma_mask)
  10120. + pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
  10121. +
  10122. + rc = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
  10123. + if (rc)
  10124. + return rc;
  10125. + dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
  10126. +
  10127. + od = devm_kzalloc(&pdev->dev, sizeof(*od), GFP_KERNEL);
  10128. + if (!od)
  10129. + return -ENOMEM;
  10130. +
  10131. + pdev->dev.dma_parms = &od->dma_parms;
  10132. + dma_set_max_seg_size(&pdev->dev, 0x3FFFFFFF);
  10133. +
  10134. + dma_cap_set(DMA_SLAVE, od->ddev.cap_mask);
  10135. + dma_cap_set(DMA_CYCLIC, od->ddev.cap_mask);
  10136. + od->ddev.device_alloc_chan_resources = bcm2708_dma_alloc_chan_resources;
  10137. + od->ddev.device_free_chan_resources = bcm2708_dma_free_chan_resources;
  10138. + od->ddev.device_tx_status = bcm2708_dma_tx_status;
  10139. + od->ddev.device_issue_pending = bcm2708_dma_issue_pending;
  10140. + od->ddev.device_prep_dma_cyclic = bcm2708_dma_prep_dma_cyclic;
  10141. + od->ddev.device_control = bcm2708_dma_control;
  10142. + od->ddev.dev = &pdev->dev;
  10143. + INIT_LIST_HEAD(&od->ddev.channels);
  10144. + spin_lock_init(&od->lock);
  10145. +
  10146. + platform_set_drvdata(pdev, od);
  10147. +
  10148. + for (i = 0; i < 16; i++) {
  10149. + void __iomem* chan_base;
  10150. + int chan_id, irq;
  10151. +
  10152. + chan_id = bcm_dma_chan_alloc(BCM_DMA_FEATURE_FAST,
  10153. + &chan_base,
  10154. + &irq);
  10155. +
  10156. + if (chan_id < 0)
  10157. + break;
  10158. +
  10159. + rc = bcm2708_dma_chan_init(od, chan_base, chan_id, irq);
  10160. + if (rc) {
  10161. + bcm2708_dma_free(od);
  10162. + return rc;
  10163. + }
  10164. + }
  10165. +
  10166. + rc = dma_async_device_register(&od->ddev);
  10167. + if (rc) {
  10168. + dev_err(&pdev->dev,
  10169. + "Failed to register slave DMA engine device: %d\n", rc);
  10170. + bcm2708_dma_free(od);
  10171. + return rc;
  10172. + }
  10173. +
  10174. + dev_dbg(&pdev->dev, "Load BCM2708 DMA engine driver\n");
  10175. +
  10176. + return rc;
  10177. +}
  10178. +
  10179. +static int bcm2708_dma_remove(struct platform_device *pdev)
  10180. +{
  10181. + struct bcm2708_dmadev *od = platform_get_drvdata(pdev);
  10182. +
  10183. + dma_async_device_unregister(&od->ddev);
  10184. + bcm2708_dma_free(od);
  10185. +
  10186. + return 0;
  10187. +}
  10188. +
  10189. +static struct platform_driver bcm2708_dma_driver = {
  10190. + .probe = bcm2708_dma_probe,
  10191. + .remove = bcm2708_dma_remove,
  10192. + .driver = {
  10193. + .name = "bcm2708-dmaengine",
  10194. + .owner = THIS_MODULE,
  10195. + },
  10196. +};
  10197. +
  10198. +static struct platform_device *pdev;
  10199. +
  10200. +static const struct platform_device_info bcm2708_dma_dev_info = {
  10201. + .name = "bcm2708-dmaengine",
  10202. + .id = -1,
  10203. +};
  10204. +
  10205. +static int bcm2708_dma_init(void)
  10206. +{
  10207. + int rc = platform_driver_register(&bcm2708_dma_driver);
  10208. +
  10209. + if (rc == 0) {
  10210. + pdev = platform_device_register_full(&bcm2708_dma_dev_info);
  10211. + if (IS_ERR(pdev)) {
  10212. + platform_driver_unregister(&bcm2708_dma_driver);
  10213. + rc = PTR_ERR(pdev);
  10214. + }
  10215. + }
  10216. +
  10217. + return rc;
  10218. +}
  10219. +subsys_initcall(bcm2708_dma_init);
  10220. +
  10221. +static void __exit bcm2708_dma_exit(void)
  10222. +{
  10223. + platform_device_unregister(pdev);
  10224. + platform_driver_unregister(&bcm2708_dma_driver);
  10225. +}
  10226. +module_exit(bcm2708_dma_exit);
  10227. +
  10228. +MODULE_ALIAS("platform:bcm2708-dma");
  10229. +MODULE_DESCRIPTION("BCM2708 DMA engine driver");
  10230. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  10231. +MODULE_LICENSE("GPL v2");
  10232. diff -Nur linux-3.12.26.orig/drivers/dma/Kconfig linux-3.12.26/drivers/dma/Kconfig
  10233. --- linux-3.12.26.orig/drivers/dma/Kconfig 2014-07-30 18:02:44.000000000 +0200
  10234. +++ linux-3.12.26/drivers/dma/Kconfig 2014-08-06 16:50:14.053958853 +0200
  10235. @@ -288,6 +288,12 @@
  10236. select DMA_ENGINE
  10237. select DMA_VIRTUAL_CHANNELS
  10238. +config DMA_BCM2708
  10239. + tristate "BCM2708 DMA engine support"
  10240. + depends on MACH_BCM2708
  10241. + select DMA_ENGINE
  10242. + select DMA_VIRTUAL_CHANNELS
  10243. +
  10244. config TI_CPPI41
  10245. tristate "AM33xx CPPI41 DMA support"
  10246. depends on ARCH_OMAP
  10247. diff -Nur linux-3.12.26.orig/drivers/dma/Makefile linux-3.12.26/drivers/dma/Makefile
  10248. --- linux-3.12.26.orig/drivers/dma/Makefile 2014-07-30 18:02:44.000000000 +0200
  10249. +++ linux-3.12.26/drivers/dma/Makefile 2014-08-06 16:50:14.053958853 +0200
  10250. @@ -37,6 +37,7 @@
  10251. obj-$(CONFIG_DMA_SA11X0) += sa11x0-dma.o
  10252. obj-$(CONFIG_MMP_TDMA) += mmp_tdma.o
  10253. obj-$(CONFIG_DMA_OMAP) += omap-dma.o
  10254. +obj-$(CONFIG_DMA_BCM2708) += bcm2708-dmaengine.o
  10255. obj-$(CONFIG_MMP_PDMA) += mmp_pdma.o
  10256. obj-$(CONFIG_DMA_JZ4740) += dma-jz4740.o
  10257. obj-$(CONFIG_TI_CPPI41) += cppi41.o
  10258. diff -Nur linux-3.12.26.orig/drivers/gpu/drm/cirrus/cirrus_fbdev.c linux-3.12.26/drivers/gpu/drm/cirrus/cirrus_fbdev.c
  10259. --- linux-3.12.26.orig/drivers/gpu/drm/cirrus/cirrus_fbdev.c 2014-07-30 18:02:44.000000000 +0200
  10260. +++ linux-3.12.26/drivers/gpu/drm/cirrus/cirrus_fbdev.c 2014-08-06 16:50:14.081959072 +0200
  10261. @@ -233,9 +233,6 @@
  10262. info->apertures->ranges[0].base = cdev->dev->mode_config.fb_base;
  10263. info->apertures->ranges[0].size = cdev->mc.vram_size;
  10264. - info->fix.smem_start = cdev->dev->mode_config.fb_base;
  10265. - info->fix.smem_len = cdev->mc.vram_size;
  10266. -
  10267. info->screen_base = sysram;
  10268. info->screen_size = size;
  10269. diff -Nur linux-3.12.26.orig/drivers/gpu/drm/cirrus/cirrus_mode.c linux-3.12.26/drivers/gpu/drm/cirrus/cirrus_mode.c
  10270. --- linux-3.12.26.orig/drivers/gpu/drm/cirrus/cirrus_mode.c 2014-07-30 18:02:44.000000000 +0200
  10271. +++ linux-3.12.26/drivers/gpu/drm/cirrus/cirrus_mode.c 2014-08-06 16:50:14.109959292 +0200
  10272. @@ -497,12 +497,13 @@
  10273. int cirrus_vga_get_modes(struct drm_connector *connector)
  10274. {
  10275. - int count;
  10276. -
  10277. /* Just add a static list of modes */
  10278. - count = drm_add_modes_noedid(connector, 1280, 1024);
  10279. - drm_set_preferred_mode(connector, 1024, 768);
  10280. - return count;
  10281. + drm_add_modes_noedid(connector, 640, 480);
  10282. + drm_add_modes_noedid(connector, 800, 600);
  10283. + drm_add_modes_noedid(connector, 1024, 768);
  10284. + drm_add_modes_noedid(connector, 1280, 1024);
  10285. +
  10286. + return 4;
  10287. }
  10288. static int cirrus_vga_mode_valid(struct drm_connector *connector,
  10289. diff -Nur linux-3.12.26.orig/drivers/gpu/drm/drm_edid.c linux-3.12.26/drivers/gpu/drm/drm_edid.c
  10290. --- linux-3.12.26.orig/drivers/gpu/drm/drm_edid.c 2014-07-30 18:02:44.000000000 +0200
  10291. +++ linux-3.12.26/drivers/gpu/drm/drm_edid.c 2014-08-06 16:50:14.129959449 +0200
  10292. @@ -3296,19 +3296,6 @@
  10293. }
  10294. EXPORT_SYMBOL(drm_add_modes_noedid);
  10295. -void drm_set_preferred_mode(struct drm_connector *connector,
  10296. - int hpref, int vpref)
  10297. -{
  10298. - struct drm_display_mode *mode;
  10299. -
  10300. - list_for_each_entry(mode, &connector->probed_modes, head) {
  10301. - if (drm_mode_width(mode) == hpref &&
  10302. - drm_mode_height(mode) == vpref)
  10303. - mode->type |= DRM_MODE_TYPE_PREFERRED;
  10304. - }
  10305. -}
  10306. -EXPORT_SYMBOL(drm_set_preferred_mode);
  10307. -
  10308. /**
  10309. * drm_hdmi_avi_infoframe_from_display_mode() - fill an HDMI AVI infoframe with
  10310. * data from a DRM display mode
  10311. diff -Nur linux-3.12.26.orig/drivers/gpu/drm/drm_fb_helper.c linux-3.12.26/drivers/gpu/drm/drm_fb_helper.c
  10312. --- linux-3.12.26.orig/drivers/gpu/drm/drm_fb_helper.c 2014-07-30 18:02:44.000000000 +0200
  10313. +++ linux-3.12.26/drivers/gpu/drm/drm_fb_helper.c 2014-08-06 16:50:14.181959858 +0200
  10314. @@ -1163,7 +1163,6 @@
  10315. {
  10316. struct drm_cmdline_mode *cmdline_mode;
  10317. struct drm_display_mode *mode = NULL;
  10318. - bool prefer_non_interlace;
  10319. cmdline_mode = &fb_helper_conn->cmdline_mode;
  10320. if (cmdline_mode->specified == false)
  10321. @@ -1175,8 +1174,6 @@
  10322. if (cmdline_mode->rb || cmdline_mode->margins)
  10323. goto create_mode;
  10324. - prefer_non_interlace = !cmdline_mode->interlace;
  10325. - again:
  10326. list_for_each_entry(mode, &fb_helper_conn->connector->modes, head) {
  10327. /* check width/height */
  10328. if (mode->hdisplay != cmdline_mode->xres ||
  10329. @@ -1191,18 +1188,10 @@
  10330. if (cmdline_mode->interlace) {
  10331. if (!(mode->flags & DRM_MODE_FLAG_INTERLACE))
  10332. continue;
  10333. - } else if (prefer_non_interlace) {
  10334. - if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  10335. - continue;
  10336. }
  10337. return mode;
  10338. }
  10339. - if (prefer_non_interlace) {
  10340. - prefer_non_interlace = false;
  10341. - goto again;
  10342. - }
  10343. -
  10344. create_mode:
  10345. mode = drm_mode_create_from_cmdline_mode(fb_helper_conn->connector->dev,
  10346. cmdline_mode);
  10347. diff -Nur linux-3.12.26.orig/drivers/gpu/drm/i915/intel_display.c linux-3.12.26/drivers/gpu/drm/i915/intel_display.c
  10348. --- linux-3.12.26.orig/drivers/gpu/drm/i915/intel_display.c 2014-07-30 18:02:44.000000000 +0200
  10349. +++ linux-3.12.26/drivers/gpu/drm/i915/intel_display.c 2014-08-06 16:50:14.209960077 +0200
  10350. @@ -10084,7 +10084,8 @@
  10351. /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
  10352. { 0x2782, 0x17aa, 0x201a, quirk_pipea_force },
  10353. - /* 830 needs to leave pipe A & dpll A up */
  10354. + /* 830/845 need to leave pipe A & dpll A up */
  10355. + { 0x2562, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force },
  10356. { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force },
  10357. /* Lenovo U160 cannot use SSC on LVDS */
  10358. diff -Nur linux-3.12.26.orig/drivers/gpu/drm/radeon/dce6_afmt.c linux-3.12.26/drivers/gpu/drm/radeon/dce6_afmt.c
  10359. --- linux-3.12.26.orig/drivers/gpu/drm/radeon/dce6_afmt.c 2014-07-30 18:02:44.000000000 +0200
  10360. +++ linux-3.12.26/drivers/gpu/drm/radeon/dce6_afmt.c 2014-08-06 16:50:14.209960077 +0200
  10361. @@ -226,15 +226,13 @@
  10362. return !ASIC_IS_NODCE(rdev);
  10363. }
  10364. -void dce6_audio_enable(struct radeon_device *rdev,
  10365. - struct r600_audio_pin *pin,
  10366. - bool enable)
  10367. +static void dce6_audio_enable(struct radeon_device *rdev,
  10368. + struct r600_audio_pin *pin,
  10369. + bool enable)
  10370. {
  10371. - if (!pin)
  10372. - return;
  10373. -
  10374. WREG32_ENDPOINT(pin->offset, AZ_F0_CODEC_PIN_CONTROL_HOTPLUG_CONTROL,
  10375. enable ? AUDIO_ENABLED : 0);
  10376. + DRM_INFO("%s audio %d support\n", enable ? "Enabling" : "Disabling", pin->id);
  10377. }
  10378. static const u32 pin_offsets[7] =
  10379. @@ -271,8 +269,7 @@
  10380. rdev->audio.pin[i].connected = false;
  10381. rdev->audio.pin[i].offset = pin_offsets[i];
  10382. rdev->audio.pin[i].id = i;
  10383. - /* disable audio. it will be set up later */
  10384. - dce6_audio_enable(rdev, &rdev->audio.pin[i], false);
  10385. + dce6_audio_enable(rdev, &rdev->audio.pin[i], true);
  10386. }
  10387. return 0;
  10388. diff -Nur linux-3.12.26.orig/drivers/gpu/drm/radeon/evergreen_hdmi.c linux-3.12.26/drivers/gpu/drm/radeon/evergreen_hdmi.c
  10389. --- linux-3.12.26.orig/drivers/gpu/drm/radeon/evergreen_hdmi.c 2014-07-30 18:02:44.000000000 +0200
  10390. +++ linux-3.12.26/drivers/gpu/drm/radeon/evergreen_hdmi.c 2014-08-06 16:50:14.237960297 +0200
  10391. @@ -257,15 +257,6 @@
  10392. return;
  10393. offset = dig->afmt->offset;
  10394. - /* disable audio prior to setting up hw */
  10395. - if (ASIC_IS_DCE6(rdev)) {
  10396. - dig->afmt->pin = dce6_audio_get_pin(rdev);
  10397. - dce6_audio_enable(rdev, dig->afmt->pin, false);
  10398. - } else {
  10399. - dig->afmt->pin = r600_audio_get_pin(rdev);
  10400. - r600_audio_enable(rdev, dig->afmt->pin, false);
  10401. - }
  10402. -
  10403. evergreen_audio_set_dto(encoder, mode->clock);
  10404. WREG32(HDMI_VBI_PACKET_CONTROL + offset,
  10405. @@ -367,16 +358,12 @@
  10406. WREG32(AFMT_RAMP_CONTROL1 + offset, 0x007FFFFF);
  10407. WREG32(AFMT_RAMP_CONTROL2 + offset, 0x00000001);
  10408. WREG32(AFMT_RAMP_CONTROL3 + offset, 0x00000001);
  10409. -
  10410. - /* enable audio after to setting up hw */
  10411. - if (ASIC_IS_DCE6(rdev))
  10412. - dce6_audio_enable(rdev, dig->afmt->pin, true);
  10413. - else
  10414. - r600_audio_enable(rdev, dig->afmt->pin, true);
  10415. }
  10416. void evergreen_hdmi_enable(struct drm_encoder *encoder, bool enable)
  10417. {
  10418. + struct drm_device *dev = encoder->dev;
  10419. + struct radeon_device *rdev = dev->dev_private;
  10420. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  10421. struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
  10422. @@ -389,6 +376,15 @@
  10423. if (!enable && !dig->afmt->enabled)
  10424. return;
  10425. + if (enable) {
  10426. + if (ASIC_IS_DCE6(rdev))
  10427. + dig->afmt->pin = dce6_audio_get_pin(rdev);
  10428. + else
  10429. + dig->afmt->pin = r600_audio_get_pin(rdev);
  10430. + } else {
  10431. + dig->afmt->pin = NULL;
  10432. + }
  10433. +
  10434. dig->afmt->enabled = enable;
  10435. DRM_DEBUG("%sabling HDMI interface @ 0x%04X for encoder 0x%x\n",
  10436. diff -Nur linux-3.12.26.orig/drivers/gpu/drm/radeon/r600_audio.c linux-3.12.26/drivers/gpu/drm/radeon/r600_audio.c
  10437. --- linux-3.12.26.orig/drivers/gpu/drm/radeon/r600_audio.c 2014-07-30 18:02:44.000000000 +0200
  10438. +++ linux-3.12.26/drivers/gpu/drm/radeon/r600_audio.c 2014-08-06 16:50:14.245960360 +0200
  10439. @@ -142,15 +142,12 @@
  10440. }
  10441. /* enable the audio stream */
  10442. -void r600_audio_enable(struct radeon_device *rdev,
  10443. - struct r600_audio_pin *pin,
  10444. - bool enable)
  10445. +static void r600_audio_enable(struct radeon_device *rdev,
  10446. + struct r600_audio_pin *pin,
  10447. + bool enable)
  10448. {
  10449. u32 value = 0;
  10450. - if (!pin)
  10451. - return;
  10452. -
  10453. if (ASIC_IS_DCE4(rdev)) {
  10454. if (enable) {
  10455. value |= 0x81000000; /* Required to enable audio */
  10456. @@ -161,6 +158,7 @@
  10457. WREG32_P(R600_AUDIO_ENABLE,
  10458. enable ? 0x81000000 : 0x0, ~0x81000000);
  10459. }
  10460. + DRM_INFO("%s audio %d support\n", enable ? "Enabling" : "Disabling", pin->id);
  10461. }
  10462. /*
  10463. @@ -180,8 +178,8 @@
  10464. rdev->audio.pin[0].status_bits = 0;
  10465. rdev->audio.pin[0].category_code = 0;
  10466. rdev->audio.pin[0].id = 0;
  10467. - /* disable audio. it will be set up later */
  10468. - r600_audio_enable(rdev, &rdev->audio.pin[0], false);
  10469. +
  10470. + r600_audio_enable(rdev, &rdev->audio.pin[0], true);
  10471. return 0;
  10472. }
  10473. diff -Nur linux-3.12.26.orig/drivers/gpu/drm/radeon/r600_hdmi.c linux-3.12.26/drivers/gpu/drm/radeon/r600_hdmi.c
  10474. --- linux-3.12.26.orig/drivers/gpu/drm/radeon/r600_hdmi.c 2014-07-30 18:02:44.000000000 +0200
  10475. +++ linux-3.12.26/drivers/gpu/drm/radeon/r600_hdmi.c 2014-08-06 16:50:14.257960454 +0200
  10476. @@ -329,6 +329,9 @@
  10477. u8 *sadb;
  10478. int sad_count;
  10479. + /* XXX: setting this register causes hangs on some asics */
  10480. + return;
  10481. +
  10482. list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) {
  10483. if (connector->encoder == encoder)
  10484. radeon_connector = to_radeon_connector(connector);
  10485. @@ -443,10 +446,6 @@
  10486. return;
  10487. offset = dig->afmt->offset;
  10488. - /* disable audio prior to setting up hw */
  10489. - dig->afmt->pin = r600_audio_get_pin(rdev);
  10490. - r600_audio_enable(rdev, dig->afmt->pin, false);
  10491. -
  10492. r600_audio_set_dto(encoder, mode->clock);
  10493. WREG32(HDMI0_VBI_PACKET_CONTROL + offset,
  10494. @@ -518,9 +517,6 @@
  10495. WREG32(HDMI0_RAMP_CONTROL3 + offset, 0x00000001);
  10496. r600_hdmi_audio_workaround(encoder);
  10497. -
  10498. - /* enable audio after to setting up hw */
  10499. - r600_audio_enable(rdev, dig->afmt->pin, true);
  10500. }
  10501. /*
  10502. @@ -641,6 +637,11 @@
  10503. if (!enable && !dig->afmt->enabled)
  10504. return;
  10505. + if (enable)
  10506. + dig->afmt->pin = r600_audio_get_pin(rdev);
  10507. + else
  10508. + dig->afmt->pin = NULL;
  10509. +
  10510. /* Older chipsets require setting HDMI and routing manually */
  10511. if (!ASIC_IS_DCE3(rdev)) {
  10512. if (enable)
  10513. diff -Nur linux-3.12.26.orig/drivers/gpu/drm/radeon/radeon.h linux-3.12.26/drivers/gpu/drm/radeon/radeon.h
  10514. --- linux-3.12.26.orig/drivers/gpu/drm/radeon/radeon.h 2014-07-30 18:02:44.000000000 +0200
  10515. +++ linux-3.12.26/drivers/gpu/drm/radeon/radeon.h 2014-08-06 16:50:14.257960454 +0200
  10516. @@ -2723,12 +2723,6 @@
  10517. void r600_audio_update_hdmi(struct work_struct *work);
  10518. struct r600_audio_pin *r600_audio_get_pin(struct radeon_device *rdev);
  10519. struct r600_audio_pin *dce6_audio_get_pin(struct radeon_device *rdev);
  10520. -void r600_audio_enable(struct radeon_device *rdev,
  10521. - struct r600_audio_pin *pin,
  10522. - bool enable);
  10523. -void dce6_audio_enable(struct radeon_device *rdev,
  10524. - struct r600_audio_pin *pin,
  10525. - bool enable);
  10526. /*
  10527. * R600 vram scratch functions
  10528. diff -Nur linux-3.12.26.orig/drivers/hwmon/bcm2835-hwmon.c linux-3.12.26/drivers/hwmon/bcm2835-hwmon.c
  10529. --- linux-3.12.26.orig/drivers/hwmon/bcm2835-hwmon.c 1970-01-01 01:00:00.000000000 +0100
  10530. +++ linux-3.12.26/drivers/hwmon/bcm2835-hwmon.c 2014-08-06 16:50:14.257960454 +0200
  10531. @@ -0,0 +1,219 @@
  10532. +/*****************************************************************************
  10533. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  10534. +*
  10535. +* Unless you and Broadcom execute a separate written software license
  10536. +* agreement governing use of this software, this software is licensed to you
  10537. +* under the terms of the GNU General Public License version 2, available at
  10538. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  10539. +*
  10540. +* Notwithstanding the above, under no circumstances may you combine this
  10541. +* software in any way with any other Broadcom software provided under a
  10542. +* license other than the GPL, without Broadcom's express prior written
  10543. +* consent.
  10544. +*****************************************************************************/
  10545. +
  10546. +#include <linux/kernel.h>
  10547. +#include <linux/module.h>
  10548. +#include <linux/init.h>
  10549. +#include <linux/hwmon.h>
  10550. +#include <linux/hwmon-sysfs.h>
  10551. +#include <linux/platform_device.h>
  10552. +#include <linux/sysfs.h>
  10553. +#include <mach/vcio.h>
  10554. +#include <linux/slab.h>
  10555. +#include <linux/err.h>
  10556. +
  10557. +#define MODULE_NAME "bcm2835_hwmon"
  10558. +
  10559. +/*#define HWMON_DEBUG_ENABLE*/
  10560. +
  10561. +#ifdef HWMON_DEBUG_ENABLE
  10562. +#define print_debug(fmt,...) printk(KERN_INFO "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  10563. +#else
  10564. +#define print_debug(fmt,...)
  10565. +#endif
  10566. +#define print_err(fmt,...) printk(KERN_ERR "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__,__LINE__, ##__VA_ARGS__)
  10567. +#define print_info(fmt,...) printk(KERN_INFO "%s: "fmt"\n", MODULE_NAME, ##__VA_ARGS__)
  10568. +
  10569. +#define VC_TAG_GET_TEMP 0x00030006
  10570. +#define VC_TAG_GET_MAX_TEMP 0x0003000A
  10571. +
  10572. +/* --- STRUCTS --- */
  10573. +struct bcm2835_hwmon_data {
  10574. + struct device *hwmon_dev;
  10575. +};
  10576. +
  10577. +/* tag part of the message */
  10578. +struct vc_msg_tag {
  10579. + uint32_t tag_id; /* the tag ID for the temperature */
  10580. + uint32_t buffer_size; /* size of the buffer (should be 8) */
  10581. + uint32_t request_code; /* identifies message as a request (should be 0) */
  10582. + uint32_t id; /* extra ID field (should be 0) */
  10583. + uint32_t val; /* returned value of the temperature */
  10584. +};
  10585. +
  10586. +/* message structure to be sent to videocore */
  10587. +struct vc_msg {
  10588. + uint32_t msg_size; /* simply, sizeof(struct vc_msg) */
  10589. + uint32_t request_code; /* holds various information like the success and number of bytes returned (refer to mailboxes wiki) */
  10590. + struct vc_msg_tag tag; /* the tag structure above to make */
  10591. + uint32_t end_tag; /* an end identifier, should be set to NULL */
  10592. +};
  10593. +
  10594. +typedef enum {
  10595. + TEMP,
  10596. + MAX_TEMP,
  10597. +} temp_type;
  10598. +
  10599. +/* --- PROTOTYPES --- */
  10600. +static ssize_t bcm2835_get_temp(struct device *dev, struct device_attribute *attr, char *buf);
  10601. +static ssize_t bcm2835_get_name(struct device *dev, struct device_attribute *attr, char *buf);
  10602. +
  10603. +/* --- GLOBALS --- */
  10604. +
  10605. +static struct bcm2835_hwmon_data *bcm2835_data;
  10606. +static struct platform_driver bcm2835_hwmon_driver;
  10607. +
  10608. +static SENSOR_DEVICE_ATTR(name, S_IRUGO,bcm2835_get_name,NULL,0);
  10609. +static SENSOR_DEVICE_ATTR(temp1_input,S_IRUGO,bcm2835_get_temp,NULL,TEMP);
  10610. +static SENSOR_DEVICE_ATTR(temp1_max,S_IRUGO,bcm2835_get_temp,NULL,MAX_TEMP);
  10611. +
  10612. +static struct attribute* bcm2835_attributes[] = {
  10613. + &sensor_dev_attr_name.dev_attr.attr,
  10614. + &sensor_dev_attr_temp1_input.dev_attr.attr,
  10615. + &sensor_dev_attr_temp1_max.dev_attr.attr,
  10616. + NULL,
  10617. +};
  10618. +
  10619. +static struct attribute_group bcm2835_attr_group = {
  10620. + .attrs = bcm2835_attributes,
  10621. +};
  10622. +
  10623. +/* --- FUNCTIONS --- */
  10624. +
  10625. +static ssize_t bcm2835_get_name(struct device *dev, struct device_attribute *attr, char *buf)
  10626. +{
  10627. + return sprintf(buf,"bcm2835_hwmon\n");
  10628. +}
  10629. +
  10630. +static ssize_t bcm2835_get_temp(struct device *dev, struct device_attribute *attr, char *buf)
  10631. +{
  10632. + struct vc_msg msg;
  10633. + int result;
  10634. + uint temp = 0;
  10635. + int index = ((struct sensor_device_attribute*)to_sensor_dev_attr(attr))->index;
  10636. +
  10637. + print_debug("IN");
  10638. +
  10639. + /* wipe all previous message data */
  10640. + memset(&msg, 0, sizeof msg);
  10641. +
  10642. + /* determine the message type */
  10643. + if(index == TEMP)
  10644. + msg.tag.tag_id = VC_TAG_GET_TEMP;
  10645. + else if (index == MAX_TEMP)
  10646. + msg.tag.tag_id = VC_TAG_GET_MAX_TEMP;
  10647. + else
  10648. + {
  10649. + print_debug("Unknown temperature message!");
  10650. + return -EINVAL;
  10651. + }
  10652. +
  10653. + msg.msg_size = sizeof msg;
  10654. + msg.tag.buffer_size = 8;
  10655. +
  10656. + /* send the message */
  10657. + result = bcm_mailbox_property(&msg, sizeof msg);
  10658. +
  10659. + /* check if it was all ok and return the rate in milli degrees C */
  10660. + if (result == 0 && (msg.request_code & 0x80000000))
  10661. + temp = (uint)msg.tag.val;
  10662. + #ifdef HWMON_DEBUG_ENABLE
  10663. + else
  10664. + print_debug("Failed to get temperature!");
  10665. + #endif
  10666. + print_debug("Got temperature as %u",temp);
  10667. + print_debug("OUT");
  10668. + return sprintf(buf, "%u\n", temp);
  10669. +}
  10670. +
  10671. +
  10672. +static int bcm2835_hwmon_probe(struct platform_device *pdev)
  10673. +{
  10674. + int err;
  10675. +
  10676. + print_debug("IN");
  10677. + print_debug("HWMON Driver has been probed!");
  10678. +
  10679. + /* check that the device isn't null!*/
  10680. + if(pdev == NULL)
  10681. + {
  10682. + print_debug("Platform device is empty!");
  10683. + return -ENODEV;
  10684. + }
  10685. +
  10686. + /* allocate memory for neccessary data */
  10687. + bcm2835_data = kzalloc(sizeof(struct bcm2835_hwmon_data),GFP_KERNEL);
  10688. + if(!bcm2835_data)
  10689. + {
  10690. + print_debug("Unable to allocate memory for hwmon data!");
  10691. + err = -ENOMEM;
  10692. + goto kzalloc_error;
  10693. + }
  10694. +
  10695. + /* create the sysfs files */
  10696. + if(sysfs_create_group(&pdev->dev.kobj, &bcm2835_attr_group))
  10697. + {
  10698. + print_debug("Unable to create sysfs files!");
  10699. + err = -EFAULT;
  10700. + goto sysfs_error;
  10701. + }
  10702. +
  10703. + /* register the hwmon device */
  10704. + bcm2835_data->hwmon_dev = hwmon_device_register(&pdev->dev);
  10705. + if (IS_ERR(bcm2835_data->hwmon_dev))
  10706. + {
  10707. + err = PTR_ERR(bcm2835_data->hwmon_dev);
  10708. + goto hwmon_error;
  10709. + }
  10710. + print_debug("OUT");
  10711. + return 0;
  10712. +
  10713. + /* error goto's */
  10714. + hwmon_error:
  10715. + sysfs_remove_group(&pdev->dev.kobj, &bcm2835_attr_group);
  10716. +
  10717. + sysfs_error:
  10718. + kfree(bcm2835_data);
  10719. +
  10720. + kzalloc_error:
  10721. +
  10722. + return err;
  10723. +
  10724. +}
  10725. +
  10726. +static int bcm2835_hwmon_remove(struct platform_device *pdev)
  10727. +{
  10728. + print_debug("IN");
  10729. + hwmon_device_unregister(bcm2835_data->hwmon_dev);
  10730. +
  10731. + sysfs_remove_group(&pdev->dev.kobj, &bcm2835_attr_group);
  10732. + print_debug("OUT");
  10733. + return 0;
  10734. +}
  10735. +
  10736. +/* Hwmon Driver */
  10737. +static struct platform_driver bcm2835_hwmon_driver = {
  10738. + .probe = bcm2835_hwmon_probe,
  10739. + .remove = bcm2835_hwmon_remove,
  10740. + .driver = {
  10741. + .name = "bcm2835_hwmon",
  10742. + .owner = THIS_MODULE,
  10743. + },
  10744. +};
  10745. +
  10746. +MODULE_LICENSE("GPL");
  10747. +MODULE_AUTHOR("Dorian Peake");
  10748. +MODULE_DESCRIPTION("HW Monitor driver for bcm2835 chip");
  10749. +
  10750. +module_platform_driver(bcm2835_hwmon_driver);
  10751. diff -Nur linux-3.12.26.orig/drivers/hwmon/Kconfig linux-3.12.26/drivers/hwmon/Kconfig
  10752. --- linux-3.12.26.orig/drivers/hwmon/Kconfig 2014-07-30 18:02:44.000000000 +0200
  10753. +++ linux-3.12.26/drivers/hwmon/Kconfig 2014-08-06 16:50:14.281960643 +0200
  10754. @@ -1553,6 +1553,16 @@
  10755. help
  10756. Support for the A/D converter on MC13783 and MC13892 PMIC.
  10757. +config SENSORS_BCM2835
  10758. + depends on THERMAL_BCM2835=n
  10759. + tristate "Broadcom BCM2835 HWMON Driver"
  10760. + help
  10761. + If you say yes here you get support for the hardware
  10762. + monitoring features of the BCM2835 Chip
  10763. +
  10764. + This driver can also be built as a module. If so, the module
  10765. + will be called bcm2835-hwmon.
  10766. +
  10767. if ACPI
  10768. comment "ACPI drivers"
  10769. diff -Nur linux-3.12.26.orig/drivers/hwmon/Makefile linux-3.12.26/drivers/hwmon/Makefile
  10770. --- linux-3.12.26.orig/drivers/hwmon/Makefile 2014-07-30 18:02:44.000000000 +0200
  10771. +++ linux-3.12.26/drivers/hwmon/Makefile 2014-08-06 16:50:14.281960643 +0200
  10772. @@ -142,6 +142,7 @@
  10773. obj-$(CONFIG_SENSORS_W83L786NG) += w83l786ng.o
  10774. obj-$(CONFIG_SENSORS_WM831X) += wm831x-hwmon.o
  10775. obj-$(CONFIG_SENSORS_WM8350) += wm8350-hwmon.o
  10776. +obj-$(CONFIG_SENSORS_BCM2835) += bcm2835-hwmon.o
  10777. obj-$(CONFIG_PMBUS) += pmbus/
  10778. diff -Nur linux-3.12.26.orig/drivers/i2c/busses/i2c-bcm2708.c linux-3.12.26/drivers/i2c/busses/i2c-bcm2708.c
  10779. --- linux-3.12.26.orig/drivers/i2c/busses/i2c-bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  10780. +++ linux-3.12.26/drivers/i2c/busses/i2c-bcm2708.c 2014-08-06 16:50:14.285960674 +0200
  10781. @@ -0,0 +1,408 @@
  10782. +/*
  10783. + * Driver for Broadcom BCM2708 BSC Controllers
  10784. + *
  10785. + * Copyright (C) 2012 Chris Boot & Frank Buss
  10786. + *
  10787. + * This driver is inspired by:
  10788. + * i2c-ocores.c, by Peter Korsgaard <jacmet@sunsite.dk>
  10789. + *
  10790. + * This program is free software; you can redistribute it and/or modify
  10791. + * it under the terms of the GNU General Public License as published by
  10792. + * the Free Software Foundation; either version 2 of the License, or
  10793. + * (at your option) any later version.
  10794. + *
  10795. + * This program is distributed in the hope that it will be useful,
  10796. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10797. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10798. + * GNU General Public License for more details.
  10799. + *
  10800. + * You should have received a copy of the GNU General Public License
  10801. + * along with this program; if not, write to the Free Software
  10802. + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  10803. + */
  10804. +
  10805. +#include <linux/kernel.h>
  10806. +#include <linux/module.h>
  10807. +#include <linux/spinlock.h>
  10808. +#include <linux/clk.h>
  10809. +#include <linux/err.h>
  10810. +#include <linux/platform_device.h>
  10811. +#include <linux/io.h>
  10812. +#include <linux/slab.h>
  10813. +#include <linux/i2c.h>
  10814. +#include <linux/interrupt.h>
  10815. +#include <linux/sched.h>
  10816. +#include <linux/wait.h>
  10817. +
  10818. +/* BSC register offsets */
  10819. +#define BSC_C 0x00
  10820. +#define BSC_S 0x04
  10821. +#define BSC_DLEN 0x08
  10822. +#define BSC_A 0x0c
  10823. +#define BSC_FIFO 0x10
  10824. +#define BSC_DIV 0x14
  10825. +#define BSC_DEL 0x18
  10826. +#define BSC_CLKT 0x1c
  10827. +
  10828. +/* Bitfields in BSC_C */
  10829. +#define BSC_C_I2CEN 0x00008000
  10830. +#define BSC_C_INTR 0x00000400
  10831. +#define BSC_C_INTT 0x00000200
  10832. +#define BSC_C_INTD 0x00000100
  10833. +#define BSC_C_ST 0x00000080
  10834. +#define BSC_C_CLEAR_1 0x00000020
  10835. +#define BSC_C_CLEAR_2 0x00000010
  10836. +#define BSC_C_READ 0x00000001
  10837. +
  10838. +/* Bitfields in BSC_S */
  10839. +#define BSC_S_CLKT 0x00000200
  10840. +#define BSC_S_ERR 0x00000100
  10841. +#define BSC_S_RXF 0x00000080
  10842. +#define BSC_S_TXE 0x00000040
  10843. +#define BSC_S_RXD 0x00000020
  10844. +#define BSC_S_TXD 0x00000010
  10845. +#define BSC_S_RXR 0x00000008
  10846. +#define BSC_S_TXW 0x00000004
  10847. +#define BSC_S_DONE 0x00000002
  10848. +#define BSC_S_TA 0x00000001
  10849. +
  10850. +#define I2C_TIMEOUT_MS 150
  10851. +
  10852. +#define DRV_NAME "bcm2708_i2c"
  10853. +
  10854. +static unsigned int baudrate = CONFIG_I2C_BCM2708_BAUDRATE;
  10855. +module_param(baudrate, uint, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
  10856. +MODULE_PARM_DESC(baudrate, "The I2C baudrate");
  10857. +
  10858. +
  10859. +struct bcm2708_i2c {
  10860. + struct i2c_adapter adapter;
  10861. +
  10862. + spinlock_t lock;
  10863. + void __iomem *base;
  10864. + int irq;
  10865. + struct clk *clk;
  10866. +
  10867. + struct completion done;
  10868. +
  10869. + struct i2c_msg *msg;
  10870. + int pos;
  10871. + int nmsgs;
  10872. + bool error;
  10873. +};
  10874. +
  10875. +/*
  10876. + * This function sets the ALT mode on the I2C pins so that we can use them with
  10877. + * the BSC hardware.
  10878. + *
  10879. + * FIXME: This is a hack. Use pinmux / pinctrl.
  10880. + */
  10881. +static void bcm2708_i2c_init_pinmode(int id)
  10882. +{
  10883. +#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
  10884. +#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
  10885. +
  10886. + int pin;
  10887. + u32 *gpio = ioremap(0x20200000, SZ_16K);
  10888. +
  10889. + BUG_ON(id != 0 && id != 1);
  10890. + /* BSC0 is on GPIO 0 & 1, BSC1 is on GPIO 2 & 3 */
  10891. + for (pin = id*2+0; pin <= id*2+1; pin++) {
  10892. +printk("bcm2708_i2c_init_pinmode(%d,%d)\n", id, pin);
  10893. + INP_GPIO(pin); /* set mode to GPIO input first */
  10894. + SET_GPIO_ALT(pin, 0); /* set mode to ALT 0 */
  10895. + }
  10896. +
  10897. + iounmap(gpio);
  10898. +
  10899. +#undef INP_GPIO
  10900. +#undef SET_GPIO_ALT
  10901. +}
  10902. +
  10903. +static inline u32 bcm2708_rd(struct bcm2708_i2c *bi, unsigned reg)
  10904. +{
  10905. + return readl(bi->base + reg);
  10906. +}
  10907. +
  10908. +static inline void bcm2708_wr(struct bcm2708_i2c *bi, unsigned reg, u32 val)
  10909. +{
  10910. + writel(val, bi->base + reg);
  10911. +}
  10912. +
  10913. +static inline void bcm2708_bsc_reset(struct bcm2708_i2c *bi)
  10914. +{
  10915. + bcm2708_wr(bi, BSC_C, 0);
  10916. + bcm2708_wr(bi, BSC_S, BSC_S_CLKT | BSC_S_ERR | BSC_S_DONE);
  10917. +}
  10918. +
  10919. +static inline void bcm2708_bsc_fifo_drain(struct bcm2708_i2c *bi)
  10920. +{
  10921. + while ((bcm2708_rd(bi, BSC_S) & BSC_S_RXD) && (bi->pos < bi->msg->len))
  10922. + bi->msg->buf[bi->pos++] = bcm2708_rd(bi, BSC_FIFO);
  10923. +}
  10924. +
  10925. +static inline void bcm2708_bsc_fifo_fill(struct bcm2708_i2c *bi)
  10926. +{
  10927. + while ((bcm2708_rd(bi, BSC_S) & BSC_S_TXD) && (bi->pos < bi->msg->len))
  10928. + bcm2708_wr(bi, BSC_FIFO, bi->msg->buf[bi->pos++]);
  10929. +}
  10930. +
  10931. +static inline void bcm2708_bsc_setup(struct bcm2708_i2c *bi)
  10932. +{
  10933. + unsigned long bus_hz;
  10934. + u32 cdiv;
  10935. + u32 c = BSC_C_I2CEN | BSC_C_INTD | BSC_C_ST | BSC_C_CLEAR_1;
  10936. +
  10937. + bus_hz = clk_get_rate(bi->clk);
  10938. + cdiv = bus_hz / baudrate;
  10939. +
  10940. + if (bi->msg->flags & I2C_M_RD)
  10941. + c |= BSC_C_INTR | BSC_C_READ;
  10942. + else
  10943. + c |= BSC_C_INTT;
  10944. +
  10945. + bcm2708_wr(bi, BSC_DIV, cdiv);
  10946. + bcm2708_wr(bi, BSC_A, bi->msg->addr);
  10947. + bcm2708_wr(bi, BSC_DLEN, bi->msg->len);
  10948. + bcm2708_wr(bi, BSC_C, c);
  10949. +}
  10950. +
  10951. +static irqreturn_t bcm2708_i2c_interrupt(int irq, void *dev_id)
  10952. +{
  10953. + struct bcm2708_i2c *bi = dev_id;
  10954. + bool handled = true;
  10955. + u32 s;
  10956. +
  10957. + spin_lock(&bi->lock);
  10958. +
  10959. + /* we may see camera interrupts on the "other" I2C channel
  10960. + Just return if we've not sent anything */
  10961. + if (!bi->nmsgs || !bi->msg )
  10962. + goto early_exit;
  10963. +
  10964. + s = bcm2708_rd(bi, BSC_S);
  10965. +
  10966. + if (s & (BSC_S_CLKT | BSC_S_ERR)) {
  10967. + bcm2708_bsc_reset(bi);
  10968. + bi->error = true;
  10969. +
  10970. + /* wake up our bh */
  10971. + complete(&bi->done);
  10972. + } else if (s & BSC_S_DONE) {
  10973. + bi->nmsgs--;
  10974. +
  10975. + if (bi->msg->flags & I2C_M_RD)
  10976. + bcm2708_bsc_fifo_drain(bi);
  10977. +
  10978. + bcm2708_bsc_reset(bi);
  10979. +
  10980. + if (bi->nmsgs) {
  10981. + /* advance to next message */
  10982. + bi->msg++;
  10983. + bi->pos = 0;
  10984. + bcm2708_bsc_setup(bi);
  10985. + } else {
  10986. + /* wake up our bh */
  10987. + complete(&bi->done);
  10988. + }
  10989. + } else if (s & BSC_S_TXW) {
  10990. + bcm2708_bsc_fifo_fill(bi);
  10991. + } else if (s & BSC_S_RXR) {
  10992. + bcm2708_bsc_fifo_drain(bi);
  10993. + } else {
  10994. + handled = false;
  10995. + }
  10996. +
  10997. +early_exit:
  10998. + spin_unlock(&bi->lock);
  10999. +
  11000. + return handled ? IRQ_HANDLED : IRQ_NONE;
  11001. +}
  11002. +
  11003. +static int bcm2708_i2c_master_xfer(struct i2c_adapter *adap,
  11004. + struct i2c_msg *msgs, int num)
  11005. +{
  11006. + struct bcm2708_i2c *bi = adap->algo_data;
  11007. + unsigned long flags;
  11008. + int ret;
  11009. +
  11010. + spin_lock_irqsave(&bi->lock, flags);
  11011. +
  11012. + INIT_COMPLETION(bi->done);
  11013. + bi->msg = msgs;
  11014. + bi->pos = 0;
  11015. + bi->nmsgs = num;
  11016. + bi->error = false;
  11017. +
  11018. + spin_unlock_irqrestore(&bi->lock, flags);
  11019. +
  11020. + bcm2708_bsc_setup(bi);
  11021. +
  11022. + ret = wait_for_completion_timeout(&bi->done,
  11023. + msecs_to_jiffies(I2C_TIMEOUT_MS));
  11024. + if (ret == 0) {
  11025. + dev_err(&adap->dev, "transfer timed out\n");
  11026. + spin_lock_irqsave(&bi->lock, flags);
  11027. + bcm2708_bsc_reset(bi);
  11028. + spin_unlock_irqrestore(&bi->lock, flags);
  11029. + return -ETIMEDOUT;
  11030. + }
  11031. +
  11032. + return bi->error ? -EIO : num;
  11033. +}
  11034. +
  11035. +static u32 bcm2708_i2c_functionality(struct i2c_adapter *adap)
  11036. +{
  11037. + return I2C_FUNC_I2C | /*I2C_FUNC_10BIT_ADDR |*/ I2C_FUNC_SMBUS_EMUL;
  11038. +}
  11039. +
  11040. +static struct i2c_algorithm bcm2708_i2c_algorithm = {
  11041. + .master_xfer = bcm2708_i2c_master_xfer,
  11042. + .functionality = bcm2708_i2c_functionality,
  11043. +};
  11044. +
  11045. +static int bcm2708_i2c_probe(struct platform_device *pdev)
  11046. +{
  11047. + struct resource *regs;
  11048. + int irq, err = -ENOMEM;
  11049. + struct clk *clk;
  11050. + struct bcm2708_i2c *bi;
  11051. + struct i2c_adapter *adap;
  11052. +
  11053. + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  11054. + if (!regs) {
  11055. + dev_err(&pdev->dev, "could not get IO memory\n");
  11056. + return -ENXIO;
  11057. + }
  11058. +
  11059. + irq = platform_get_irq(pdev, 0);
  11060. + if (irq < 0) {
  11061. + dev_err(&pdev->dev, "could not get IRQ\n");
  11062. + return irq;
  11063. + }
  11064. +
  11065. + clk = clk_get(&pdev->dev, NULL);
  11066. + if (IS_ERR(clk)) {
  11067. + dev_err(&pdev->dev, "could not find clk: %ld\n", PTR_ERR(clk));
  11068. + return PTR_ERR(clk);
  11069. + }
  11070. +
  11071. + bcm2708_i2c_init_pinmode(pdev->id);
  11072. +
  11073. + bi = kzalloc(sizeof(*bi), GFP_KERNEL);
  11074. + if (!bi)
  11075. + goto out_clk_put;
  11076. +
  11077. + platform_set_drvdata(pdev, bi);
  11078. +
  11079. + adap = &bi->adapter;
  11080. + adap->class = I2C_CLASS_HWMON | I2C_CLASS_DDC;
  11081. + adap->algo = &bcm2708_i2c_algorithm;
  11082. + adap->algo_data = bi;
  11083. + adap->dev.parent = &pdev->dev;
  11084. + adap->nr = pdev->id;
  11085. + strlcpy(adap->name, dev_name(&pdev->dev), sizeof(adap->name));
  11086. +
  11087. + switch (pdev->id) {
  11088. + case 0:
  11089. + adap->class = I2C_CLASS_HWMON;
  11090. + break;
  11091. + case 1:
  11092. + adap->class = I2C_CLASS_DDC;
  11093. + break;
  11094. + default:
  11095. + dev_err(&pdev->dev, "can only bind to BSC 0 or 1\n");
  11096. + err = -ENXIO;
  11097. + goto out_free_bi;
  11098. + }
  11099. +
  11100. + spin_lock_init(&bi->lock);
  11101. + init_completion(&bi->done);
  11102. +
  11103. + bi->base = ioremap(regs->start, resource_size(regs));
  11104. + if (!bi->base) {
  11105. + dev_err(&pdev->dev, "could not remap memory\n");
  11106. + goto out_free_bi;
  11107. + }
  11108. +
  11109. + bi->irq = irq;
  11110. + bi->clk = clk;
  11111. +
  11112. + err = request_irq(irq, bcm2708_i2c_interrupt, IRQF_SHARED,
  11113. + dev_name(&pdev->dev), bi);
  11114. + if (err) {
  11115. + dev_err(&pdev->dev, "could not request IRQ: %d\n", err);
  11116. + goto out_iounmap;
  11117. + }
  11118. +
  11119. + bcm2708_bsc_reset(bi);
  11120. +
  11121. + err = i2c_add_numbered_adapter(adap);
  11122. + if (err < 0) {
  11123. + dev_err(&pdev->dev, "could not add I2C adapter: %d\n", err);
  11124. + goto out_free_irq;
  11125. + }
  11126. +
  11127. + dev_info(&pdev->dev, "BSC%d Controller at 0x%08lx (irq %d) (baudrate %dk)\n",
  11128. + pdev->id, (unsigned long)regs->start, irq, baudrate/1000);
  11129. +
  11130. + return 0;
  11131. +
  11132. +out_free_irq:
  11133. + free_irq(bi->irq, bi);
  11134. +out_iounmap:
  11135. + iounmap(bi->base);
  11136. +out_free_bi:
  11137. + kfree(bi);
  11138. +out_clk_put:
  11139. + clk_put(clk);
  11140. + return err;
  11141. +}
  11142. +
  11143. +static int bcm2708_i2c_remove(struct platform_device *pdev)
  11144. +{
  11145. + struct bcm2708_i2c *bi = platform_get_drvdata(pdev);
  11146. +
  11147. + platform_set_drvdata(pdev, NULL);
  11148. +
  11149. + i2c_del_adapter(&bi->adapter);
  11150. + free_irq(bi->irq, bi);
  11151. + iounmap(bi->base);
  11152. + clk_disable(bi->clk);
  11153. + clk_put(bi->clk);
  11154. + kfree(bi);
  11155. +
  11156. + return 0;
  11157. +}
  11158. +
  11159. +static struct platform_driver bcm2708_i2c_driver = {
  11160. + .driver = {
  11161. + .name = DRV_NAME,
  11162. + .owner = THIS_MODULE,
  11163. + },
  11164. + .probe = bcm2708_i2c_probe,
  11165. + .remove = bcm2708_i2c_remove,
  11166. +};
  11167. +
  11168. +// module_platform_driver(bcm2708_i2c_driver);
  11169. +
  11170. +
  11171. +static int __init bcm2708_i2c_init(void)
  11172. +{
  11173. + return platform_driver_register(&bcm2708_i2c_driver);
  11174. +}
  11175. +
  11176. +static void __exit bcm2708_i2c_exit(void)
  11177. +{
  11178. + platform_driver_unregister(&bcm2708_i2c_driver);
  11179. +}
  11180. +
  11181. +module_init(bcm2708_i2c_init);
  11182. +module_exit(bcm2708_i2c_exit);
  11183. +
  11184. +
  11185. +
  11186. +MODULE_DESCRIPTION("BSC controller driver for Broadcom BCM2708");
  11187. +MODULE_AUTHOR("Chris Boot <bootc@bootc.net>");
  11188. +MODULE_LICENSE("GPL v2");
  11189. +MODULE_ALIAS("platform:" DRV_NAME);
  11190. diff -Nur linux-3.12.26.orig/drivers/i2c/busses/Kconfig linux-3.12.26/drivers/i2c/busses/Kconfig
  11191. --- linux-3.12.26.orig/drivers/i2c/busses/Kconfig 2014-07-30 18:02:44.000000000 +0200
  11192. +++ linux-3.12.26/drivers/i2c/busses/Kconfig 2014-08-06 16:50:14.309960862 +0200
  11193. @@ -348,6 +348,25 @@
  11194. This support is also available as a module. If so, the module
  11195. will be called i2c-bcm2835.
  11196. +config I2C_BCM2708
  11197. + tristate "BCM2708 BSC"
  11198. + depends on MACH_BCM2708
  11199. + help
  11200. + Enabling this option will add BSC (Broadcom Serial Controller)
  11201. + support for the BCM2708. BSC is a Broadcom proprietary bus compatible
  11202. + with I2C/TWI/SMBus.
  11203. +
  11204. +config I2C_BCM2708_BAUDRATE
  11205. + prompt "BCM2708 I2C baudrate"
  11206. + depends on I2C_BCM2708
  11207. + int
  11208. + default 100000
  11209. + help
  11210. + Set the I2C baudrate. This will alter the default value. A
  11211. + different baudrate can be set by using a module parameter as well. If
  11212. + no parameter is provided when loading, this is the value that will be
  11213. + used.
  11214. +
  11215. config I2C_BLACKFIN_TWI
  11216. tristate "Blackfin TWI I2C support"
  11217. depends on BLACKFIN
  11218. diff -Nur linux-3.12.26.orig/drivers/i2c/busses/Makefile linux-3.12.26/drivers/i2c/busses/Makefile
  11219. --- linux-3.12.26.orig/drivers/i2c/busses/Makefile 2014-07-30 18:02:44.000000000 +0200
  11220. +++ linux-3.12.26/drivers/i2c/busses/Makefile 2014-08-06 16:50:14.309960862 +0200
  11221. @@ -32,6 +32,7 @@
  11222. obj-$(CONFIG_I2C_AT91) += i2c-at91.o
  11223. obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o
  11224. obj-$(CONFIG_I2C_BCM2835) += i2c-bcm2835.o
  11225. +obj-$(CONFIG_I2C_BCM2708) += i2c-bcm2708.o
  11226. obj-$(CONFIG_I2C_BLACKFIN_TWI) += i2c-bfin-twi.o
  11227. obj-$(CONFIG_I2C_CBUS_GPIO) += i2c-cbus-gpio.o
  11228. obj-$(CONFIG_I2C_CPM) += i2c-cpm.o
  11229. diff -Nur linux-3.12.26.orig/drivers/isdn/isdnloop/isdnloop.c linux-3.12.26/drivers/isdn/isdnloop/isdnloop.c
  11230. --- linux-3.12.26.orig/drivers/isdn/isdnloop/isdnloop.c 2014-07-30 18:02:44.000000000 +0200
  11231. +++ linux-3.12.26/drivers/isdn/isdnloop/isdnloop.c 2014-08-06 16:50:14.333961051 +0200
  11232. @@ -518,9 +518,9 @@
  11233. static void
  11234. isdnloop_fake_err(isdnloop_card *card)
  11235. {
  11236. - char buf[64];
  11237. + char buf[60];
  11238. - snprintf(buf, sizeof(buf), "E%s", card->omsg);
  11239. + sprintf(buf, "E%s", card->omsg);
  11240. isdnloop_fake(card, buf, -1);
  11241. isdnloop_fake(card, "NAK", -1);
  11242. }
  11243. @@ -903,8 +903,6 @@
  11244. case 7:
  11245. /* 0x;EAZ */
  11246. p += 3;
  11247. - if (strlen(p) >= sizeof(card->eazlist[0]))
  11248. - break;
  11249. strcpy(card->eazlist[ch - 1], p);
  11250. break;
  11251. case 8:
  11252. @@ -1072,12 +1070,6 @@
  11253. return -EBUSY;
  11254. if (copy_from_user((char *) &sdef, (char *) sdefp, sizeof(sdef)))
  11255. return -EFAULT;
  11256. -
  11257. - for (i = 0; i < 3; i++) {
  11258. - if (!memchr(sdef.num[i], 0, sizeof(sdef.num[i])))
  11259. - return -EINVAL;
  11260. - }
  11261. -
  11262. spin_lock_irqsave(&card->isdnloop_lock, flags);
  11263. switch (sdef.ptype) {
  11264. case ISDN_PTYPE_EURO:
  11265. @@ -1135,7 +1127,7 @@
  11266. {
  11267. ulong a;
  11268. int i;
  11269. - char cbuf[80];
  11270. + char cbuf[60];
  11271. isdn_ctrl cmd;
  11272. isdnloop_cdef cdef;
  11273. @@ -1200,6 +1192,7 @@
  11274. break;
  11275. if ((c->arg & 255) < ISDNLOOP_BCH) {
  11276. char *p;
  11277. + char dial[50];
  11278. char dcode[4];
  11279. a = c->arg;
  11280. @@ -1211,10 +1204,10 @@
  11281. } else
  11282. /* Normal Dial */
  11283. strcpy(dcode, "CAL");
  11284. - snprintf(cbuf, sizeof(cbuf),
  11285. - "%02d;D%s_R%s,%02d,%02d,%s\n", (int) (a + 1),
  11286. - dcode, p, c->parm.setup.si1,
  11287. - c->parm.setup.si2, c->parm.setup.eazmsn);
  11288. + strcpy(dial, p);
  11289. + sprintf(cbuf, "%02d;D%s_R%s,%02d,%02d,%s\n", (int) (a + 1),
  11290. + dcode, dial, c->parm.setup.si1,
  11291. + c->parm.setup.si2, c->parm.setup.eazmsn);
  11292. i = isdnloop_writecmd(cbuf, strlen(cbuf), 0, card);
  11293. }
  11294. break;
  11295. diff -Nur linux-3.12.26.orig/drivers/media/platform/bcm2835/bcm2835-camera.c linux-3.12.26/drivers/media/platform/bcm2835/bcm2835-camera.c
  11296. --- linux-3.12.26.orig/drivers/media/platform/bcm2835/bcm2835-camera.c 1970-01-01 01:00:00.000000000 +0100
  11297. +++ linux-3.12.26/drivers/media/platform/bcm2835/bcm2835-camera.c 2014-08-06 16:50:14.349961177 +0200
  11298. @@ -0,0 +1,1719 @@
  11299. +/*
  11300. + * Broadcom BM2835 V4L2 driver
  11301. + *
  11302. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  11303. + *
  11304. + * This file is subject to the terms and conditions of the GNU General Public
  11305. + * License. See the file COPYING in the main directory of this archive
  11306. + * for more details.
  11307. + *
  11308. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  11309. + * Dave Stevenson <dsteve@broadcom.com>
  11310. + * Simon Mellor <simellor@broadcom.com>
  11311. + * Luke Diamand <luked@broadcom.com>
  11312. + */
  11313. +
  11314. +#include <linux/errno.h>
  11315. +#include <linux/kernel.h>
  11316. +#include <linux/module.h>
  11317. +#include <linux/slab.h>
  11318. +#include <media/videobuf2-vmalloc.h>
  11319. +#include <media/videobuf2-dma-contig.h>
  11320. +#include <media/v4l2-device.h>
  11321. +#include <media/v4l2-ioctl.h>
  11322. +#include <media/v4l2-ctrls.h>
  11323. +#include <media/v4l2-fh.h>
  11324. +#include <media/v4l2-event.h>
  11325. +#include <media/v4l2-common.h>
  11326. +#include <linux/delay.h>
  11327. +
  11328. +#include "mmal-common.h"
  11329. +#include "mmal-encodings.h"
  11330. +#include "mmal-vchiq.h"
  11331. +#include "mmal-msg.h"
  11332. +#include "mmal-parameters.h"
  11333. +#include "bcm2835-camera.h"
  11334. +
  11335. +#define BM2835_MMAL_VERSION "0.0.2"
  11336. +#define BM2835_MMAL_MODULE_NAME "bcm2835-v4l2"
  11337. +#define MIN_WIDTH 16
  11338. +#define MIN_HEIGHT 16
  11339. +#define MAX_WIDTH 2592
  11340. +#define MAX_HEIGHT 1944
  11341. +#define MIN_BUFFER_SIZE (80*1024)
  11342. +
  11343. +#define MAX_VIDEO_MODE_WIDTH 1280
  11344. +#define MAX_VIDEO_MODE_HEIGHT 720
  11345. +
  11346. +MODULE_DESCRIPTION("Broadcom 2835 MMAL video capture");
  11347. +MODULE_AUTHOR("Vincent Sanders");
  11348. +MODULE_LICENSE("GPL");
  11349. +MODULE_VERSION(BM2835_MMAL_VERSION);
  11350. +
  11351. +int bcm2835_v4l2_debug;
  11352. +module_param_named(debug, bcm2835_v4l2_debug, int, 0644);
  11353. +MODULE_PARM_DESC(bcm2835_v4l2_debug, "Debug level 0-2");
  11354. +
  11355. +static struct bm2835_mmal_dev *gdev; /* global device data */
  11356. +
  11357. +#define FPS_MIN 1
  11358. +#define FPS_MAX 90
  11359. +
  11360. +/* timeperframe: min/max and default */
  11361. +static const struct v4l2_fract
  11362. + tpf_min = {.numerator = 1, .denominator = FPS_MAX},
  11363. + tpf_max = {.numerator = 1, .denominator = FPS_MIN},
  11364. + tpf_default = {.numerator = 1000, .denominator = 30000};
  11365. +
  11366. +/* video formats */
  11367. +static struct mmal_fmt formats[] = {
  11368. + {
  11369. + .name = "4:2:0, packed YUV",
  11370. + .fourcc = V4L2_PIX_FMT_YUV420,
  11371. + .flags = 0,
  11372. + .mmal = MMAL_ENCODING_I420,
  11373. + .depth = 12,
  11374. + .mmal_component = MMAL_COMPONENT_CAMERA,
  11375. + },
  11376. + {
  11377. + .name = "4:2:2, packed, YUYV",
  11378. + .fourcc = V4L2_PIX_FMT_YUYV,
  11379. + .flags = 0,
  11380. + .mmal = MMAL_ENCODING_YUYV,
  11381. + .depth = 16,
  11382. + .mmal_component = MMAL_COMPONENT_CAMERA,
  11383. + },
  11384. + {
  11385. + .name = "RGB24 (LE)",
  11386. + .fourcc = V4L2_PIX_FMT_RGB24,
  11387. + .flags = 0,
  11388. + .mmal = MMAL_ENCODING_BGR24,
  11389. + .depth = 24,
  11390. + .mmal_component = MMAL_COMPONENT_CAMERA,
  11391. + },
  11392. + {
  11393. + .name = "JPEG",
  11394. + .fourcc = V4L2_PIX_FMT_JPEG,
  11395. + .flags = V4L2_FMT_FLAG_COMPRESSED,
  11396. + .mmal = MMAL_ENCODING_JPEG,
  11397. + .depth = 8,
  11398. + .mmal_component = MMAL_COMPONENT_IMAGE_ENCODE,
  11399. + },
  11400. + {
  11401. + .name = "H264",
  11402. + .fourcc = V4L2_PIX_FMT_H264,
  11403. + .flags = V4L2_FMT_FLAG_COMPRESSED,
  11404. + .mmal = MMAL_ENCODING_H264,
  11405. + .depth = 8,
  11406. + .mmal_component = MMAL_COMPONENT_VIDEO_ENCODE,
  11407. + },
  11408. + {
  11409. + .name = "MJPEG",
  11410. + .fourcc = V4L2_PIX_FMT_MJPEG,
  11411. + .flags = V4L2_FMT_FLAG_COMPRESSED,
  11412. + .mmal = MMAL_ENCODING_MJPEG,
  11413. + .depth = 8,
  11414. + .mmal_component = MMAL_COMPONENT_VIDEO_ENCODE,
  11415. + },
  11416. + {
  11417. + .name = "4:2:2, packed, YVYU",
  11418. + .fourcc = V4L2_PIX_FMT_YVYU,
  11419. + .flags = 0,
  11420. + .mmal = MMAL_ENCODING_YVYU,
  11421. + .depth = 16,
  11422. + .mmal_component = MMAL_COMPONENT_CAMERA,
  11423. + },
  11424. + {
  11425. + .name = "4:2:2, packed, VYUY",
  11426. + .fourcc = V4L2_PIX_FMT_VYUY,
  11427. + .flags = 0,
  11428. + .mmal = MMAL_ENCODING_VYUY,
  11429. + .depth = 16,
  11430. + .mmal_component = MMAL_COMPONENT_CAMERA,
  11431. + },
  11432. + {
  11433. + .name = "4:2:2, packed, UYVY",
  11434. + .fourcc = V4L2_PIX_FMT_UYVY,
  11435. + .flags = 0,
  11436. + .mmal = MMAL_ENCODING_UYVY,
  11437. + .depth = 16,
  11438. + .mmal_component = MMAL_COMPONENT_CAMERA,
  11439. + },
  11440. + {
  11441. + .name = "4:2:0, packed, NV12",
  11442. + .fourcc = V4L2_PIX_FMT_NV12,
  11443. + .flags = 0,
  11444. + .mmal = MMAL_ENCODING_NV12,
  11445. + .depth = 12,
  11446. + .mmal_component = MMAL_COMPONENT_CAMERA,
  11447. + },
  11448. + {
  11449. + .name = "RGB24 (BE)",
  11450. + .fourcc = V4L2_PIX_FMT_BGR24,
  11451. + .flags = 0,
  11452. + .mmal = MMAL_ENCODING_RGB24,
  11453. + .depth = 24,
  11454. + .mmal_component = MMAL_COMPONENT_CAMERA,
  11455. + },
  11456. + {
  11457. + .name = "4:2:0, packed YVU",
  11458. + .fourcc = V4L2_PIX_FMT_YVU420,
  11459. + .flags = 0,
  11460. + .mmal = MMAL_ENCODING_YV12,
  11461. + .depth = 12,
  11462. + .mmal_component = MMAL_COMPONENT_CAMERA,
  11463. + },
  11464. + {
  11465. + .name = "4:2:0, packed, NV21",
  11466. + .fourcc = V4L2_PIX_FMT_NV21,
  11467. + .flags = 0,
  11468. + .mmal = MMAL_ENCODING_NV21,
  11469. + .depth = 12,
  11470. + .mmal_component = MMAL_COMPONENT_CAMERA,
  11471. + },
  11472. +};
  11473. +
  11474. +static struct mmal_fmt *get_format(struct v4l2_format *f)
  11475. +{
  11476. + struct mmal_fmt *fmt;
  11477. + unsigned int k;
  11478. +
  11479. + for (k = 0; k < ARRAY_SIZE(formats); k++) {
  11480. + fmt = &formats[k];
  11481. + if (fmt->fourcc == f->fmt.pix.pixelformat)
  11482. + break;
  11483. + }
  11484. +
  11485. + if (k == ARRAY_SIZE(formats))
  11486. + return NULL;
  11487. +
  11488. + return &formats[k];
  11489. +}
  11490. +
  11491. +/* ------------------------------------------------------------------
  11492. + Videobuf queue operations
  11493. + ------------------------------------------------------------------*/
  11494. +
  11495. +static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
  11496. + unsigned int *nbuffers, unsigned int *nplanes,
  11497. + unsigned int sizes[], void *alloc_ctxs[])
  11498. +{
  11499. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  11500. + unsigned long size;
  11501. +
  11502. + /* refuse queue setup if port is not configured */
  11503. + if (dev->capture.port == NULL) {
  11504. + v4l2_err(&dev->v4l2_dev,
  11505. + "%s: capture port not configured\n", __func__);
  11506. + return -EINVAL;
  11507. + }
  11508. +
  11509. + size = dev->capture.port->current_buffer.size;
  11510. + if (size == 0) {
  11511. + v4l2_err(&dev->v4l2_dev,
  11512. + "%s: capture port buffer size is zero\n", __func__);
  11513. + return -EINVAL;
  11514. + }
  11515. +
  11516. + if (*nbuffers < (dev->capture.port->current_buffer.num + 2))
  11517. + *nbuffers = (dev->capture.port->current_buffer.num + 2);
  11518. +
  11519. + *nplanes = 1;
  11520. +
  11521. + sizes[0] = size;
  11522. +
  11523. + /*
  11524. + * videobuf2-vmalloc allocator is context-less so no need to set
  11525. + * alloc_ctxs array.
  11526. + */
  11527. +
  11528. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  11529. + __func__, dev);
  11530. +
  11531. + return 0;
  11532. +}
  11533. +
  11534. +static int buffer_prepare(struct vb2_buffer *vb)
  11535. +{
  11536. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
  11537. + unsigned long size;
  11538. +
  11539. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  11540. + __func__, dev);
  11541. +
  11542. + BUG_ON(dev->capture.port == NULL);
  11543. + BUG_ON(dev->capture.fmt == NULL);
  11544. +
  11545. + size = dev->capture.stride * dev->capture.height;
  11546. + if (vb2_plane_size(vb, 0) < size) {
  11547. + v4l2_err(&dev->v4l2_dev,
  11548. + "%s data will not fit into plane (%lu < %lu)\n",
  11549. + __func__, vb2_plane_size(vb, 0), size);
  11550. + return -EINVAL;
  11551. + }
  11552. +
  11553. + return 0;
  11554. +}
  11555. +
  11556. +static inline bool is_capturing(struct bm2835_mmal_dev *dev)
  11557. +{
  11558. + return dev->capture.camera_port ==
  11559. + &dev->
  11560. + component[MMAL_COMPONENT_CAMERA]->output[MMAL_CAMERA_PORT_CAPTURE];
  11561. +}
  11562. +
  11563. +static void buffer_cb(struct vchiq_mmal_instance *instance,
  11564. + struct vchiq_mmal_port *port,
  11565. + int status,
  11566. + struct mmal_buffer *buf,
  11567. + unsigned long length, u32 mmal_flags, s64 dts, s64 pts)
  11568. +{
  11569. + struct bm2835_mmal_dev *dev = port->cb_ctx;
  11570. +
  11571. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11572. + "%s: status:%d, buf:%p, length:%lu, flags %u, pts %lld\n",
  11573. + __func__, status, buf, length, mmal_flags, pts);
  11574. +
  11575. + if (status != 0) {
  11576. + /* error in transfer */
  11577. + if (buf != NULL) {
  11578. + /* there was a buffer with the error so return it */
  11579. + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
  11580. + }
  11581. + return;
  11582. + } else if (length == 0) {
  11583. + /* stream ended */
  11584. + if (buf != NULL) {
  11585. + /* this should only ever happen if the port is
  11586. + * disabled and there are buffers still queued
  11587. + */
  11588. + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
  11589. + pr_debug("Empty buffer");
  11590. + } else if (dev->capture.frame_count) {
  11591. + /* grab another frame */
  11592. + if (is_capturing(dev)) {
  11593. + pr_debug("Grab another frame");
  11594. + vchiq_mmal_port_parameter_set(
  11595. + instance,
  11596. + dev->capture.
  11597. + camera_port,
  11598. + MMAL_PARAMETER_CAPTURE,
  11599. + &dev->capture.
  11600. + frame_count,
  11601. + sizeof(dev->capture.frame_count));
  11602. + }
  11603. + } else {
  11604. + /* signal frame completion */
  11605. + complete(&dev->capture.frame_cmplt);
  11606. + }
  11607. + } else {
  11608. + if (dev->capture.frame_count) {
  11609. + if (dev->capture.vc_start_timestamp != -1 &&
  11610. + pts != 0) {
  11611. + s64 runtime_us = pts -
  11612. + dev->capture.vc_start_timestamp;
  11613. + u32 div = 0;
  11614. + u32 rem = 0;
  11615. +
  11616. + div =
  11617. + div_u64_rem(runtime_us, USEC_PER_SEC, &rem);
  11618. + buf->vb.v4l2_buf.timestamp.tv_sec =
  11619. + dev->capture.kernel_start_ts.tv_sec - 1 +
  11620. + div;
  11621. + buf->vb.v4l2_buf.timestamp.tv_usec =
  11622. + dev->capture.kernel_start_ts.tv_usec + rem;
  11623. +
  11624. + if (buf->vb.v4l2_buf.timestamp.tv_usec >=
  11625. + USEC_PER_SEC) {
  11626. + buf->vb.v4l2_buf.timestamp.tv_sec++;
  11627. + buf->vb.v4l2_buf.timestamp.tv_usec -=
  11628. + USEC_PER_SEC;
  11629. + }
  11630. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11631. + "Convert start time %d.%06d and %llu "
  11632. + "with offset %llu to %d.%06d\n",
  11633. + (int)dev->capture.kernel_start_ts.
  11634. + tv_sec,
  11635. + (int)dev->capture.kernel_start_ts.
  11636. + tv_usec,
  11637. + dev->capture.vc_start_timestamp, pts,
  11638. + (int)buf->vb.v4l2_buf.timestamp.tv_sec,
  11639. + (int)buf->vb.v4l2_buf.timestamp.
  11640. + tv_usec);
  11641. + } else {
  11642. + v4l2_get_timestamp(&buf->vb.v4l2_buf.timestamp);
  11643. + }
  11644. +
  11645. + vb2_set_plane_payload(&buf->vb, 0, length);
  11646. + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_DONE);
  11647. +
  11648. + if (mmal_flags & MMAL_BUFFER_HEADER_FLAG_EOS &&
  11649. + is_capturing(dev)) {
  11650. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11651. + "Grab another frame as buffer has EOS");
  11652. + vchiq_mmal_port_parameter_set(
  11653. + instance,
  11654. + dev->capture.
  11655. + camera_port,
  11656. + MMAL_PARAMETER_CAPTURE,
  11657. + &dev->capture.
  11658. + frame_count,
  11659. + sizeof(dev->capture.frame_count));
  11660. + }
  11661. + } else {
  11662. + /* signal frame completion */
  11663. + complete(&dev->capture.frame_cmplt);
  11664. + }
  11665. + }
  11666. +}
  11667. +
  11668. +static int enable_camera(struct bm2835_mmal_dev *dev)
  11669. +{
  11670. + int ret;
  11671. + if (!dev->camera_use_count) {
  11672. + ret = vchiq_mmal_component_enable(
  11673. + dev->instance,
  11674. + dev->component[MMAL_COMPONENT_CAMERA]);
  11675. + if (ret < 0) {
  11676. + v4l2_err(&dev->v4l2_dev,
  11677. + "Failed enabling camera, ret %d\n", ret);
  11678. + return -EINVAL;
  11679. + }
  11680. + }
  11681. + dev->camera_use_count++;
  11682. + v4l2_dbg(1, bcm2835_v4l2_debug,
  11683. + &dev->v4l2_dev, "enabled camera (refcount %d)\n",
  11684. + dev->camera_use_count);
  11685. + return 0;
  11686. +}
  11687. +
  11688. +static int disable_camera(struct bm2835_mmal_dev *dev)
  11689. +{
  11690. + int ret;
  11691. + if (!dev->camera_use_count) {
  11692. + v4l2_err(&dev->v4l2_dev,
  11693. + "Disabled the camera when already disabled\n");
  11694. + return -EINVAL;
  11695. + }
  11696. + dev->camera_use_count--;
  11697. + if (!dev->camera_use_count) {
  11698. + unsigned int i = 0xFFFFFFFF;
  11699. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11700. + "Disabling camera\n");
  11701. + ret =
  11702. + vchiq_mmal_component_disable(
  11703. + dev->instance,
  11704. + dev->component[MMAL_COMPONENT_CAMERA]);
  11705. + if (ret < 0) {
  11706. + v4l2_err(&dev->v4l2_dev,
  11707. + "Failed disabling camera, ret %d\n", ret);
  11708. + return -EINVAL;
  11709. + }
  11710. + vchiq_mmal_port_parameter_set(
  11711. + dev->instance,
  11712. + &dev->component[MMAL_COMPONENT_CAMERA]->control,
  11713. + MMAL_PARAMETER_CAMERA_NUM, &i,
  11714. + sizeof(i));
  11715. + }
  11716. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11717. + "Camera refcount now %d\n", dev->camera_use_count);
  11718. + return 0;
  11719. +}
  11720. +
  11721. +static void buffer_queue(struct vb2_buffer *vb)
  11722. +{
  11723. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
  11724. + struct mmal_buffer *buf = container_of(vb, struct mmal_buffer, vb);
  11725. + int ret;
  11726. +
  11727. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11728. + "%s: dev:%p buf:%p\n", __func__, dev, buf);
  11729. +
  11730. + buf->buffer = vb2_plane_vaddr(&buf->vb, 0);
  11731. + buf->buffer_size = vb2_plane_size(&buf->vb, 0);
  11732. +
  11733. + ret = vchiq_mmal_submit_buffer(dev->instance, dev->capture.port, buf);
  11734. + if (ret < 0)
  11735. + v4l2_err(&dev->v4l2_dev, "%s: error submitting buffer\n",
  11736. + __func__);
  11737. +}
  11738. +
  11739. +static int start_streaming(struct vb2_queue *vq, unsigned int count)
  11740. +{
  11741. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  11742. + int ret;
  11743. + int parameter_size;
  11744. +
  11745. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  11746. + __func__, dev);
  11747. +
  11748. + /* ensure a format has actually been set */
  11749. + if (dev->capture.port == NULL)
  11750. + return -EINVAL;
  11751. +
  11752. + if (enable_camera(dev) < 0) {
  11753. + v4l2_err(&dev->v4l2_dev, "Failed to enable camera\n");
  11754. + return -EINVAL;
  11755. + }
  11756. +
  11757. + /*init_completion(&dev->capture.frame_cmplt); */
  11758. +
  11759. + /* enable frame capture */
  11760. + dev->capture.frame_count = 1;
  11761. +
  11762. + /* if the preview is not already running, wait for a few frames for AGC
  11763. + * to settle down.
  11764. + */
  11765. + if (!dev->component[MMAL_COMPONENT_PREVIEW]->enabled)
  11766. + msleep(300);
  11767. +
  11768. + /* enable the connection from camera to encoder (if applicable) */
  11769. + if (dev->capture.camera_port != dev->capture.port
  11770. + && dev->capture.camera_port) {
  11771. + ret = vchiq_mmal_port_enable(dev->instance,
  11772. + dev->capture.camera_port, NULL);
  11773. + if (ret) {
  11774. + v4l2_err(&dev->v4l2_dev,
  11775. + "Failed to enable encode tunnel - error %d\n",
  11776. + ret);
  11777. + return -1;
  11778. + }
  11779. + }
  11780. +
  11781. + /* Get VC timestamp at this point in time */
  11782. + parameter_size = sizeof(dev->capture.vc_start_timestamp);
  11783. + if (vchiq_mmal_port_parameter_get(dev->instance,
  11784. + dev->capture.camera_port,
  11785. + MMAL_PARAMETER_SYSTEM_TIME,
  11786. + &dev->capture.vc_start_timestamp,
  11787. + &parameter_size)) {
  11788. + v4l2_err(&dev->v4l2_dev,
  11789. + "Failed to get VC start time - update your VC f/w\n");
  11790. +
  11791. + /* Flag to indicate just to rely on kernel timestamps */
  11792. + dev->capture.vc_start_timestamp = -1;
  11793. + } else
  11794. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11795. + "Start time %lld size %d\n",
  11796. + dev->capture.vc_start_timestamp, parameter_size);
  11797. +
  11798. + v4l2_get_timestamp(&dev->capture.kernel_start_ts);
  11799. +
  11800. + /* enable the camera port */
  11801. + dev->capture.port->cb_ctx = dev;
  11802. + ret =
  11803. + vchiq_mmal_port_enable(dev->instance, dev->capture.port, buffer_cb);
  11804. + if (ret) {
  11805. + v4l2_err(&dev->v4l2_dev,
  11806. + "Failed to enable capture port - error %d. "
  11807. + "Disabling camera port again\n", ret);
  11808. +
  11809. + vchiq_mmal_port_disable(dev->instance,
  11810. + dev->capture.camera_port);
  11811. + if (disable_camera(dev) < 0) {
  11812. + v4l2_err(&dev->v4l2_dev, "Failed to disable camera");
  11813. + return -EINVAL;
  11814. + }
  11815. + return -1;
  11816. + }
  11817. +
  11818. + /* capture the first frame */
  11819. + vchiq_mmal_port_parameter_set(dev->instance,
  11820. + dev->capture.camera_port,
  11821. + MMAL_PARAMETER_CAPTURE,
  11822. + &dev->capture.frame_count,
  11823. + sizeof(dev->capture.frame_count));
  11824. + return 0;
  11825. +}
  11826. +
  11827. +/* abort streaming and wait for last buffer */
  11828. +static int stop_streaming(struct vb2_queue *vq)
  11829. +{
  11830. + int ret;
  11831. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  11832. +
  11833. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  11834. + __func__, dev);
  11835. +
  11836. + init_completion(&dev->capture.frame_cmplt);
  11837. + dev->capture.frame_count = 0;
  11838. +
  11839. + /* ensure a format has actually been set */
  11840. + if (dev->capture.port == NULL)
  11841. + return -EINVAL;
  11842. +
  11843. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "stopping capturing\n");
  11844. +
  11845. + /* stop capturing frames */
  11846. + vchiq_mmal_port_parameter_set(dev->instance,
  11847. + dev->capture.camera_port,
  11848. + MMAL_PARAMETER_CAPTURE,
  11849. + &dev->capture.frame_count,
  11850. + sizeof(dev->capture.frame_count));
  11851. +
  11852. + /* wait for last frame to complete */
  11853. + ret = wait_for_completion_timeout(&dev->capture.frame_cmplt, HZ);
  11854. + if (ret <= 0)
  11855. + v4l2_err(&dev->v4l2_dev,
  11856. + "error %d waiting for frame completion\n", ret);
  11857. +
  11858. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11859. + "disabling connection\n");
  11860. +
  11861. + /* disable the connection from camera to encoder */
  11862. + ret = vchiq_mmal_port_disable(dev->instance, dev->capture.camera_port);
  11863. + if (!ret && dev->capture.camera_port != dev->capture.port) {
  11864. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11865. + "disabling port\n");
  11866. + ret = vchiq_mmal_port_disable(dev->instance, dev->capture.port);
  11867. + } else if (dev->capture.camera_port != dev->capture.port) {
  11868. + v4l2_err(&dev->v4l2_dev, "port_disable failed, error %d\n",
  11869. + ret);
  11870. + }
  11871. +
  11872. + if (disable_camera(dev) < 0) {
  11873. + v4l2_err(&dev->v4l2_dev, "Failed to disable camera");
  11874. + return -EINVAL;
  11875. + }
  11876. +
  11877. + return ret;
  11878. +}
  11879. +
  11880. +static void bm2835_mmal_lock(struct vb2_queue *vq)
  11881. +{
  11882. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  11883. + mutex_lock(&dev->mutex);
  11884. +}
  11885. +
  11886. +static void bm2835_mmal_unlock(struct vb2_queue *vq)
  11887. +{
  11888. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  11889. + mutex_unlock(&dev->mutex);
  11890. +}
  11891. +
  11892. +static struct vb2_ops bm2835_mmal_video_qops = {
  11893. + .queue_setup = queue_setup,
  11894. + .buf_prepare = buffer_prepare,
  11895. + .buf_queue = buffer_queue,
  11896. + .start_streaming = start_streaming,
  11897. + .stop_streaming = stop_streaming,
  11898. + .wait_prepare = bm2835_mmal_unlock,
  11899. + .wait_finish = bm2835_mmal_lock,
  11900. +};
  11901. +
  11902. +/* ------------------------------------------------------------------
  11903. + IOCTL operations
  11904. + ------------------------------------------------------------------*/
  11905. +
  11906. +/* overlay ioctl */
  11907. +static int vidioc_enum_fmt_vid_overlay(struct file *file, void *priv,
  11908. + struct v4l2_fmtdesc *f)
  11909. +{
  11910. + struct mmal_fmt *fmt;
  11911. +
  11912. + if (f->index >= ARRAY_SIZE(formats))
  11913. + return -EINVAL;
  11914. +
  11915. + fmt = &formats[f->index];
  11916. +
  11917. + strlcpy(f->description, fmt->name, sizeof(f->description));
  11918. + f->pixelformat = fmt->fourcc;
  11919. + f->flags = fmt->flags;
  11920. +
  11921. + return 0;
  11922. +}
  11923. +
  11924. +static int vidioc_g_fmt_vid_overlay(struct file *file, void *priv,
  11925. + struct v4l2_format *f)
  11926. +{
  11927. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  11928. +
  11929. + f->fmt.win = dev->overlay;
  11930. +
  11931. + return 0;
  11932. +}
  11933. +
  11934. +static int vidioc_try_fmt_vid_overlay(struct file *file, void *priv,
  11935. + struct v4l2_format *f)
  11936. +{
  11937. + /* Only support one format so get the current one. */
  11938. + vidioc_g_fmt_vid_overlay(file, priv, f);
  11939. +
  11940. + /* todo: allow the size and/or offset to be changed. */
  11941. + return 0;
  11942. +}
  11943. +
  11944. +static int vidioc_s_fmt_vid_overlay(struct file *file, void *priv,
  11945. + struct v4l2_format *f)
  11946. +{
  11947. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  11948. +
  11949. + vidioc_try_fmt_vid_overlay(file, priv, f);
  11950. +
  11951. + dev->overlay = f->fmt.win;
  11952. +
  11953. + /* todo: program the preview port parameters */
  11954. + return 0;
  11955. +}
  11956. +
  11957. +static int vidioc_overlay(struct file *file, void *f, unsigned int on)
  11958. +{
  11959. + int ret;
  11960. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  11961. + struct vchiq_mmal_port *src;
  11962. + struct vchiq_mmal_port *dst;
  11963. + struct mmal_parameter_displayregion prev_config = {
  11964. + .set = MMAL_DISPLAY_SET_LAYER | MMAL_DISPLAY_SET_ALPHA |
  11965. + MMAL_DISPLAY_SET_DEST_RECT | MMAL_DISPLAY_SET_FULLSCREEN,
  11966. + .layer = PREVIEW_LAYER,
  11967. + .alpha = 255,
  11968. + .fullscreen = 0,
  11969. + .dest_rect = {
  11970. + .x = dev->overlay.w.left,
  11971. + .y = dev->overlay.w.top,
  11972. + .width = dev->overlay.w.width,
  11973. + .height = dev->overlay.w.height,
  11974. + },
  11975. + };
  11976. +
  11977. + if ((on && dev->component[MMAL_COMPONENT_PREVIEW]->enabled) ||
  11978. + (!on && !dev->component[MMAL_COMPONENT_PREVIEW]->enabled))
  11979. + return 0; /* already in requested state */
  11980. +
  11981. + src =
  11982. + &dev->component[MMAL_COMPONENT_CAMERA]->
  11983. + output[MMAL_CAMERA_PORT_PREVIEW];
  11984. +
  11985. + if (!on) {
  11986. + /* disconnect preview ports and disable component */
  11987. + ret = vchiq_mmal_port_disable(dev->instance, src);
  11988. + if (!ret)
  11989. + ret =
  11990. + vchiq_mmal_port_connect_tunnel(dev->instance, src,
  11991. + NULL);
  11992. + if (ret >= 0)
  11993. + ret = vchiq_mmal_component_disable(
  11994. + dev->instance,
  11995. + dev->component[MMAL_COMPONENT_PREVIEW]);
  11996. +
  11997. + disable_camera(dev);
  11998. + return ret;
  11999. + }
  12000. +
  12001. + /* set preview port format and connect it to output */
  12002. + dst = &dev->component[MMAL_COMPONENT_PREVIEW]->input[0];
  12003. +
  12004. + ret = vchiq_mmal_port_set_format(dev->instance, src);
  12005. + if (ret < 0)
  12006. + goto error;
  12007. +
  12008. + ret = vchiq_mmal_port_parameter_set(dev->instance, dst,
  12009. + MMAL_PARAMETER_DISPLAYREGION,
  12010. + &prev_config, sizeof(prev_config));
  12011. + if (ret < 0)
  12012. + goto error;
  12013. +
  12014. + if (enable_camera(dev) < 0)
  12015. + goto error;
  12016. +
  12017. + ret = vchiq_mmal_component_enable(
  12018. + dev->instance,
  12019. + dev->component[MMAL_COMPONENT_PREVIEW]);
  12020. + if (ret < 0)
  12021. + goto error;
  12022. +
  12023. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "connecting %p to %p\n",
  12024. + src, dst);
  12025. + ret = vchiq_mmal_port_connect_tunnel(dev->instance, src, dst);
  12026. + if (!ret)
  12027. + ret = vchiq_mmal_port_enable(dev->instance, src, NULL);
  12028. +error:
  12029. + return ret;
  12030. +}
  12031. +
  12032. +static int vidioc_g_fbuf(struct file *file, void *fh,
  12033. + struct v4l2_framebuffer *a)
  12034. +{
  12035. + /* The video overlay must stay within the framebuffer and can't be
  12036. + positioned independently. */
  12037. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  12038. + struct vchiq_mmal_port *preview_port =
  12039. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12040. + output[MMAL_CAMERA_PORT_PREVIEW];
  12041. + a->flags = V4L2_FBUF_FLAG_OVERLAY;
  12042. + a->fmt.width = preview_port->es.video.width;
  12043. + a->fmt.height = preview_port->es.video.height;
  12044. + a->fmt.pixelformat = V4L2_PIX_FMT_YUV420;
  12045. + a->fmt.bytesperline = (preview_port->es.video.width * 3)>>1;
  12046. + a->fmt.sizeimage = (preview_port->es.video.width *
  12047. + preview_port->es.video.height * 3)>>1;
  12048. + a->fmt.colorspace = V4L2_COLORSPACE_JPEG;
  12049. +
  12050. + return 0;
  12051. +}
  12052. +
  12053. +/* input ioctls */
  12054. +static int vidioc_enum_input(struct file *file, void *priv,
  12055. + struct v4l2_input *inp)
  12056. +{
  12057. + /* only a single camera input */
  12058. + if (inp->index != 0)
  12059. + return -EINVAL;
  12060. +
  12061. + inp->type = V4L2_INPUT_TYPE_CAMERA;
  12062. + sprintf(inp->name, "Camera %u", inp->index);
  12063. + return 0;
  12064. +}
  12065. +
  12066. +static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
  12067. +{
  12068. + *i = 0;
  12069. + return 0;
  12070. +}
  12071. +
  12072. +static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
  12073. +{
  12074. + if (i != 0)
  12075. + return -EINVAL;
  12076. +
  12077. + return 0;
  12078. +}
  12079. +
  12080. +/* capture ioctls */
  12081. +static int vidioc_querycap(struct file *file, void *priv,
  12082. + struct v4l2_capability *cap)
  12083. +{
  12084. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  12085. + u32 major;
  12086. + u32 minor;
  12087. +
  12088. + vchiq_mmal_version(dev->instance, &major, &minor);
  12089. +
  12090. + strcpy(cap->driver, "bm2835 mmal");
  12091. + snprintf(cap->card, sizeof(cap->card), "mmal service %d.%d",
  12092. + major, minor);
  12093. +
  12094. + snprintf(cap->bus_info, sizeof(cap->bus_info),
  12095. + "platform:%s", dev->v4l2_dev.name);
  12096. + cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OVERLAY |
  12097. + V4L2_CAP_STREAMING | V4L2_CAP_READWRITE;
  12098. + cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
  12099. +
  12100. + return 0;
  12101. +}
  12102. +
  12103. +static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
  12104. + struct v4l2_fmtdesc *f)
  12105. +{
  12106. + struct mmal_fmt *fmt;
  12107. +
  12108. + if (f->index >= ARRAY_SIZE(formats))
  12109. + return -EINVAL;
  12110. +
  12111. + fmt = &formats[f->index];
  12112. +
  12113. + strlcpy(f->description, fmt->name, sizeof(f->description));
  12114. + f->pixelformat = fmt->fourcc;
  12115. + f->flags = fmt->flags;
  12116. +
  12117. + return 0;
  12118. +}
  12119. +
  12120. +static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
  12121. + struct v4l2_format *f)
  12122. +{
  12123. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  12124. +
  12125. + f->fmt.pix.width = dev->capture.width;
  12126. + f->fmt.pix.height = dev->capture.height;
  12127. + f->fmt.pix.field = V4L2_FIELD_NONE;
  12128. + f->fmt.pix.pixelformat = dev->capture.fmt->fourcc;
  12129. + f->fmt.pix.bytesperline =
  12130. + (f->fmt.pix.width * dev->capture.fmt->depth) >> 3;
  12131. + f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
  12132. + if (dev->capture.fmt->fourcc == V4L2_PIX_FMT_JPEG
  12133. + && f->fmt.pix.sizeimage < (100 << 10)) {
  12134. + /* Need a minimum size for JPEG to account for EXIF. */
  12135. + f->fmt.pix.sizeimage = (100 << 10);
  12136. + }
  12137. +
  12138. + if (dev->capture.fmt->fourcc == V4L2_PIX_FMT_YUYV ||
  12139. + dev->capture.fmt->fourcc == V4L2_PIX_FMT_UYVY)
  12140. + f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
  12141. + else
  12142. + f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
  12143. + f->fmt.pix.priv = 0;
  12144. +
  12145. + v4l2_dump_pix_format(1, bcm2835_v4l2_debug, &dev->v4l2_dev, &f->fmt.pix,
  12146. + __func__);
  12147. + return 0;
  12148. +}
  12149. +
  12150. +static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
  12151. + struct v4l2_format *f)
  12152. +{
  12153. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  12154. + struct mmal_fmt *mfmt;
  12155. +
  12156. + mfmt = get_format(f);
  12157. + if (!mfmt) {
  12158. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12159. + "Fourcc format (0x%08x) unknown.\n",
  12160. + f->fmt.pix.pixelformat);
  12161. + f->fmt.pix.pixelformat = formats[0].fourcc;
  12162. + mfmt = get_format(f);
  12163. + }
  12164. +
  12165. + f->fmt.pix.field = V4L2_FIELD_NONE;
  12166. + /* image must be a multiple of 32 pixels wide and 16 lines high */
  12167. + v4l_bound_align_image(&f->fmt.pix.width, 48, MAX_WIDTH, 5,
  12168. + &f->fmt.pix.height, 32, MAX_HEIGHT, 4, 0);
  12169. + f->fmt.pix.bytesperline = (f->fmt.pix.width * mfmt->depth) >> 3;
  12170. + f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
  12171. + if (f->fmt.pix.sizeimage < MIN_BUFFER_SIZE)
  12172. + f->fmt.pix.sizeimage = MIN_BUFFER_SIZE;
  12173. +
  12174. + if (mfmt->fourcc == V4L2_PIX_FMT_YUYV ||
  12175. + mfmt->fourcc == V4L2_PIX_FMT_UYVY)
  12176. + f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
  12177. + else
  12178. + f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
  12179. + f->fmt.pix.priv = 0;
  12180. +
  12181. + v4l2_dump_pix_format(1, bcm2835_v4l2_debug, &dev->v4l2_dev, &f->fmt.pix,
  12182. + __func__);
  12183. + return 0;
  12184. +}
  12185. +
  12186. +static int mmal_setup_components(struct bm2835_mmal_dev *dev,
  12187. + struct v4l2_format *f)
  12188. +{
  12189. + int ret;
  12190. + struct vchiq_mmal_port *port = NULL, *camera_port = NULL;
  12191. + struct vchiq_mmal_component *encode_component = NULL;
  12192. + struct mmal_fmt *mfmt = get_format(f);
  12193. +
  12194. + BUG_ON(!mfmt);
  12195. +
  12196. + if (dev->capture.encode_component) {
  12197. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12198. + "vid_cap - disconnect previous tunnel\n");
  12199. +
  12200. + /* Disconnect any previous connection */
  12201. + vchiq_mmal_port_connect_tunnel(dev->instance,
  12202. + dev->capture.camera_port, NULL);
  12203. + dev->capture.camera_port = NULL;
  12204. + ret = vchiq_mmal_component_disable(dev->instance,
  12205. + dev->capture.
  12206. + encode_component);
  12207. + if (ret)
  12208. + v4l2_err(&dev->v4l2_dev,
  12209. + "Failed to disable encode component %d\n",
  12210. + ret);
  12211. +
  12212. + dev->capture.encode_component = NULL;
  12213. + }
  12214. + /* format dependant port setup */
  12215. + switch (mfmt->mmal_component) {
  12216. + case MMAL_COMPONENT_CAMERA:
  12217. + /* Make a further decision on port based on resolution */
  12218. + if (f->fmt.pix.width <= MAX_VIDEO_MODE_WIDTH
  12219. + && f->fmt.pix.height <= MAX_VIDEO_MODE_HEIGHT)
  12220. + camera_port = port =
  12221. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12222. + output[MMAL_CAMERA_PORT_VIDEO];
  12223. + else
  12224. + camera_port = port =
  12225. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12226. + output[MMAL_CAMERA_PORT_CAPTURE];
  12227. + break;
  12228. + case MMAL_COMPONENT_IMAGE_ENCODE:
  12229. + encode_component = dev->component[MMAL_COMPONENT_IMAGE_ENCODE];
  12230. + port = &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->output[0];
  12231. + camera_port =
  12232. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12233. + output[MMAL_CAMERA_PORT_CAPTURE];
  12234. + break;
  12235. + case MMAL_COMPONENT_VIDEO_ENCODE:
  12236. + encode_component = dev->component[MMAL_COMPONENT_VIDEO_ENCODE];
  12237. + port = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  12238. + camera_port =
  12239. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12240. + output[MMAL_CAMERA_PORT_VIDEO];
  12241. + break;
  12242. + default:
  12243. + break;
  12244. + }
  12245. +
  12246. + if (!port)
  12247. + return -EINVAL;
  12248. +
  12249. + if (encode_component)
  12250. + camera_port->format.encoding = MMAL_ENCODING_OPAQUE;
  12251. + else
  12252. + camera_port->format.encoding = mfmt->mmal;
  12253. +
  12254. + camera_port->format.encoding_variant = 0;
  12255. + camera_port->es.video.width = f->fmt.pix.width;
  12256. + camera_port->es.video.height = f->fmt.pix.height;
  12257. + camera_port->es.video.crop.x = 0;
  12258. + camera_port->es.video.crop.y = 0;
  12259. + camera_port->es.video.crop.width = f->fmt.pix.width;
  12260. + camera_port->es.video.crop.height = f->fmt.pix.height;
  12261. + camera_port->es.video.frame_rate.num = 0;
  12262. + camera_port->es.video.frame_rate.den = 1;
  12263. +
  12264. + ret = vchiq_mmal_port_set_format(dev->instance, camera_port);
  12265. +
  12266. + if (!ret
  12267. + && camera_port ==
  12268. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12269. + output[MMAL_CAMERA_PORT_VIDEO]) {
  12270. + bool overlay_enabled =
  12271. + !!dev->component[MMAL_COMPONENT_PREVIEW]->enabled;
  12272. + struct vchiq_mmal_port *preview_port =
  12273. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12274. + output[MMAL_CAMERA_PORT_PREVIEW];
  12275. + /* Preview and encode ports need to match on resolution */
  12276. + if (overlay_enabled) {
  12277. + /* Need to disable the overlay before we can update
  12278. + * the resolution
  12279. + */
  12280. + ret =
  12281. + vchiq_mmal_port_disable(dev->instance,
  12282. + preview_port);
  12283. + if (!ret)
  12284. + ret =
  12285. + vchiq_mmal_port_connect_tunnel(
  12286. + dev->instance,
  12287. + preview_port,
  12288. + NULL);
  12289. + }
  12290. + preview_port->es.video.width = f->fmt.pix.width;
  12291. + preview_port->es.video.height = f->fmt.pix.height;
  12292. + preview_port->es.video.crop.x = 0;
  12293. + preview_port->es.video.crop.y = 0;
  12294. + preview_port->es.video.crop.width = f->fmt.pix.width;
  12295. + preview_port->es.video.crop.height = f->fmt.pix.height;
  12296. + preview_port->es.video.frame_rate.num =
  12297. + dev->capture.timeperframe.denominator;
  12298. + preview_port->es.video.frame_rate.den =
  12299. + dev->capture.timeperframe.numerator;
  12300. + ret = vchiq_mmal_port_set_format(dev->instance, preview_port);
  12301. + if (overlay_enabled) {
  12302. + ret = vchiq_mmal_port_connect_tunnel(
  12303. + dev->instance,
  12304. + preview_port,
  12305. + &dev->component[MMAL_COMPONENT_PREVIEW]->input[0]);
  12306. + if (!ret)
  12307. + ret = vchiq_mmal_port_enable(dev->instance,
  12308. + preview_port,
  12309. + NULL);
  12310. + }
  12311. + }
  12312. +
  12313. + if (ret) {
  12314. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12315. + "%s failed to set format\n", __func__);
  12316. + /* ensure capture is not going to be tried */
  12317. + dev->capture.port = NULL;
  12318. + } else {
  12319. + if (encode_component) {
  12320. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12321. + "vid_cap - set up encode comp\n");
  12322. +
  12323. + /* configure buffering */
  12324. + camera_port->current_buffer.size =
  12325. + camera_port->recommended_buffer.size;
  12326. + camera_port->current_buffer.num =
  12327. + camera_port->recommended_buffer.num;
  12328. +
  12329. + ret =
  12330. + vchiq_mmal_port_connect_tunnel(
  12331. + dev->instance,
  12332. + camera_port,
  12333. + &encode_component->input[0]);
  12334. + if (ret) {
  12335. + v4l2_dbg(1, bcm2835_v4l2_debug,
  12336. + &dev->v4l2_dev,
  12337. + "%s failed to create connection\n",
  12338. + __func__);
  12339. + /* ensure capture is not going to be tried */
  12340. + dev->capture.port = NULL;
  12341. + } else {
  12342. + port->es.video.width = f->fmt.pix.width;
  12343. + port->es.video.height = f->fmt.pix.height;
  12344. + port->es.video.crop.x = 0;
  12345. + port->es.video.crop.y = 0;
  12346. + port->es.video.crop.width = f->fmt.pix.width;
  12347. + port->es.video.crop.height = f->fmt.pix.height;
  12348. + port->es.video.frame_rate.num =
  12349. + dev->capture.timeperframe.denominator;
  12350. + port->es.video.frame_rate.den =
  12351. + dev->capture.timeperframe.numerator;
  12352. +
  12353. + port->format.encoding = mfmt->mmal;
  12354. + port->format.encoding_variant = 0;
  12355. + /* Set any encoding specific parameters */
  12356. + switch (mfmt->mmal_component) {
  12357. + case MMAL_COMPONENT_VIDEO_ENCODE:
  12358. + port->format.bitrate =
  12359. + dev->capture.encode_bitrate;
  12360. + break;
  12361. + case MMAL_COMPONENT_IMAGE_ENCODE:
  12362. + /* Could set EXIF parameters here */
  12363. + break;
  12364. + default:
  12365. + break;
  12366. + }
  12367. + ret = vchiq_mmal_port_set_format(dev->instance,
  12368. + port);
  12369. + if (ret)
  12370. + v4l2_dbg(1, bcm2835_v4l2_debug,
  12371. + &dev->v4l2_dev,
  12372. + "%s failed to set format\n",
  12373. + __func__);
  12374. + }
  12375. +
  12376. + if (!ret) {
  12377. + ret = vchiq_mmal_component_enable(
  12378. + dev->instance,
  12379. + encode_component);
  12380. + if (ret) {
  12381. + v4l2_dbg(1, bcm2835_v4l2_debug,
  12382. + &dev->v4l2_dev,
  12383. + "%s Failed to enable encode components\n",
  12384. + __func__);
  12385. + }
  12386. + }
  12387. + if (!ret) {
  12388. + /* configure buffering */
  12389. + port->current_buffer.num = 1;
  12390. + port->current_buffer.size =
  12391. + f->fmt.pix.sizeimage;
  12392. + if (port->format.encoding ==
  12393. + MMAL_ENCODING_JPEG) {
  12394. + v4l2_dbg(1, bcm2835_v4l2_debug,
  12395. + &dev->v4l2_dev,
  12396. + "JPG - buf size now %d was %d\n",
  12397. + f->fmt.pix.sizeimage,
  12398. + port->current_buffer.size);
  12399. + port->current_buffer.size =
  12400. + (f->fmt.pix.sizeimage <
  12401. + (100 << 10))
  12402. + ? (100 << 10) : f->fmt.pix.
  12403. + sizeimage;
  12404. + }
  12405. + v4l2_dbg(1, bcm2835_v4l2_debug,
  12406. + &dev->v4l2_dev,
  12407. + "vid_cap - cur_buf.size set to %d\n",
  12408. + f->fmt.pix.sizeimage);
  12409. + port->current_buffer.alignment = 0;
  12410. + }
  12411. + } else {
  12412. + /* configure buffering */
  12413. + camera_port->current_buffer.num = 1;
  12414. + camera_port->current_buffer.size = f->fmt.pix.sizeimage;
  12415. + camera_port->current_buffer.alignment = 0;
  12416. + }
  12417. +
  12418. + if (!ret) {
  12419. + dev->capture.fmt = mfmt;
  12420. + dev->capture.stride = f->fmt.pix.bytesperline;
  12421. + dev->capture.width = camera_port->es.video.crop.width;
  12422. + dev->capture.height = camera_port->es.video.crop.height;
  12423. +
  12424. + /* select port for capture */
  12425. + dev->capture.port = port;
  12426. + dev->capture.camera_port = camera_port;
  12427. + dev->capture.encode_component = encode_component;
  12428. + v4l2_dbg(1, bcm2835_v4l2_debug,
  12429. + &dev->v4l2_dev,
  12430. + "Set dev->capture.fmt %08X, %dx%d, stride %d",
  12431. + port->format.encoding,
  12432. + dev->capture.width, dev->capture.height,
  12433. + dev->capture.stride);
  12434. + }
  12435. + }
  12436. +
  12437. + /* todo: Need to convert the vchiq/mmal error into a v4l2 error. */
  12438. + return ret;
  12439. +}
  12440. +
  12441. +static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
  12442. + struct v4l2_format *f)
  12443. +{
  12444. + int ret;
  12445. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  12446. + struct mmal_fmt *mfmt;
  12447. +
  12448. + /* try the format to set valid parameters */
  12449. + ret = vidioc_try_fmt_vid_cap(file, priv, f);
  12450. + if (ret) {
  12451. + v4l2_err(&dev->v4l2_dev,
  12452. + "vid_cap - vidioc_try_fmt_vid_cap failed\n");
  12453. + return ret;
  12454. + }
  12455. +
  12456. + /* if a capture is running refuse to set format */
  12457. + if (vb2_is_busy(&dev->capture.vb_vidq)) {
  12458. + v4l2_info(&dev->v4l2_dev, "%s device busy\n", __func__);
  12459. + return -EBUSY;
  12460. + }
  12461. +
  12462. + /* If the format is unsupported v4l2 says we should switch to
  12463. + * a supported one and not return an error. */
  12464. + mfmt = get_format(f);
  12465. + if (!mfmt) {
  12466. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12467. + "Fourcc format (0x%08x) unknown.\n",
  12468. + f->fmt.pix.pixelformat);
  12469. + f->fmt.pix.pixelformat = formats[0].fourcc;
  12470. + mfmt = get_format(f);
  12471. + }
  12472. +
  12473. + ret = mmal_setup_components(dev, f);
  12474. + if (ret != 0) {
  12475. + v4l2_err(&dev->v4l2_dev,
  12476. + "%s: failed to setup mmal components: %d\n",
  12477. + __func__, ret);
  12478. + ret = -EINVAL;
  12479. + }
  12480. +
  12481. + return ret;
  12482. +}
  12483. +
  12484. +int vidioc_enum_framesizes(struct file *file, void *fh,
  12485. + struct v4l2_frmsizeenum *fsize)
  12486. +{
  12487. + static const struct v4l2_frmsize_stepwise sizes = {
  12488. + MIN_WIDTH, MAX_WIDTH, 2,
  12489. + MIN_HEIGHT, MAX_HEIGHT, 2
  12490. + };
  12491. + int i;
  12492. +
  12493. + if (fsize->index)
  12494. + return -EINVAL;
  12495. + for (i = 0; i < ARRAY_SIZE(formats); i++)
  12496. + if (formats[i].fourcc == fsize->pixel_format)
  12497. + break;
  12498. + if (i == ARRAY_SIZE(formats))
  12499. + return -EINVAL;
  12500. + fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
  12501. + fsize->stepwise = sizes;
  12502. + return 0;
  12503. +}
  12504. +
  12505. +/* timeperframe is arbitrary and continous */
  12506. +static int vidioc_enum_frameintervals(struct file *file, void *priv,
  12507. + struct v4l2_frmivalenum *fival)
  12508. +{
  12509. + int i;
  12510. +
  12511. + if (fival->index)
  12512. + return -EINVAL;
  12513. +
  12514. + for (i = 0; i < ARRAY_SIZE(formats); i++)
  12515. + if (formats[i].fourcc == fival->pixel_format)
  12516. + break;
  12517. + if (i == ARRAY_SIZE(formats))
  12518. + return -EINVAL;
  12519. +
  12520. + /* regarding width & height - we support any within range */
  12521. + if (fival->width < MIN_WIDTH || fival->width > MAX_WIDTH ||
  12522. + fival->height < MIN_HEIGHT || fival->height > MAX_HEIGHT)
  12523. + return -EINVAL;
  12524. +
  12525. + fival->type = V4L2_FRMIVAL_TYPE_CONTINUOUS;
  12526. +
  12527. + /* fill in stepwise (step=1.0 is requred by V4L2 spec) */
  12528. + fival->stepwise.min = tpf_min;
  12529. + fival->stepwise.max = tpf_max;
  12530. + fival->stepwise.step = (struct v4l2_fract) {1, 1};
  12531. +
  12532. + return 0;
  12533. +}
  12534. +
  12535. +static int vidioc_g_parm(struct file *file, void *priv,
  12536. + struct v4l2_streamparm *parm)
  12537. +{
  12538. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  12539. +
  12540. + if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  12541. + return -EINVAL;
  12542. +
  12543. + parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
  12544. + parm->parm.capture.timeperframe = dev->capture.timeperframe;
  12545. + parm->parm.capture.readbuffers = 1;
  12546. + return 0;
  12547. +}
  12548. +
  12549. +#define FRACT_CMP(a, OP, b) \
  12550. + ((u64)(a).numerator * (b).denominator OP \
  12551. + (u64)(b).numerator * (a).denominator)
  12552. +
  12553. +static int vidioc_s_parm(struct file *file, void *priv,
  12554. + struct v4l2_streamparm *parm)
  12555. +{
  12556. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  12557. + struct v4l2_fract tpf;
  12558. + struct mmal_parameter_rational fps_param;
  12559. +
  12560. + if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  12561. + return -EINVAL;
  12562. +
  12563. + tpf = parm->parm.capture.timeperframe;
  12564. +
  12565. + /* tpf: {*, 0} resets timing; clip to [min, max]*/
  12566. + tpf = tpf.denominator ? tpf : tpf_default;
  12567. + tpf = FRACT_CMP(tpf, <, tpf_min) ? tpf_min : tpf;
  12568. + tpf = FRACT_CMP(tpf, >, tpf_max) ? tpf_max : tpf;
  12569. +
  12570. + dev->capture.timeperframe = tpf;
  12571. + parm->parm.capture.timeperframe = tpf;
  12572. + parm->parm.capture.readbuffers = 1;
  12573. +
  12574. + fps_param.num = 0; /* Select variable fps, and then use
  12575. + * FPS_RANGE to select the actual limits.
  12576. + */
  12577. + fps_param.den = 1;
  12578. + set_framerate_params(dev);
  12579. +
  12580. + return 0;
  12581. +}
  12582. +
  12583. +static const struct v4l2_ioctl_ops camera0_ioctl_ops = {
  12584. + /* overlay */
  12585. + .vidioc_enum_fmt_vid_overlay = vidioc_enum_fmt_vid_overlay,
  12586. + .vidioc_g_fmt_vid_overlay = vidioc_g_fmt_vid_overlay,
  12587. + .vidioc_try_fmt_vid_overlay = vidioc_try_fmt_vid_overlay,
  12588. + .vidioc_s_fmt_vid_overlay = vidioc_s_fmt_vid_overlay,
  12589. + .vidioc_overlay = vidioc_overlay,
  12590. + .vidioc_g_fbuf = vidioc_g_fbuf,
  12591. +
  12592. + /* inputs */
  12593. + .vidioc_enum_input = vidioc_enum_input,
  12594. + .vidioc_g_input = vidioc_g_input,
  12595. + .vidioc_s_input = vidioc_s_input,
  12596. +
  12597. + /* capture */
  12598. + .vidioc_querycap = vidioc_querycap,
  12599. + .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
  12600. + .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
  12601. + .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
  12602. + .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
  12603. +
  12604. + /* buffer management */
  12605. + .vidioc_reqbufs = vb2_ioctl_reqbufs,
  12606. + .vidioc_create_bufs = vb2_ioctl_create_bufs,
  12607. + .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
  12608. + .vidioc_querybuf = vb2_ioctl_querybuf,
  12609. + .vidioc_qbuf = vb2_ioctl_qbuf,
  12610. + .vidioc_dqbuf = vb2_ioctl_dqbuf,
  12611. + .vidioc_enum_framesizes = vidioc_enum_framesizes,
  12612. + .vidioc_enum_frameintervals = vidioc_enum_frameintervals,
  12613. + .vidioc_g_parm = vidioc_g_parm,
  12614. + .vidioc_s_parm = vidioc_s_parm,
  12615. + .vidioc_streamon = vb2_ioctl_streamon,
  12616. + .vidioc_streamoff = vb2_ioctl_streamoff,
  12617. +
  12618. + .vidioc_log_status = v4l2_ctrl_log_status,
  12619. + .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
  12620. + .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
  12621. +};
  12622. +
  12623. +/* ------------------------------------------------------------------
  12624. + Driver init/finalise
  12625. + ------------------------------------------------------------------*/
  12626. +
  12627. +static const struct v4l2_file_operations camera0_fops = {
  12628. + .owner = THIS_MODULE,
  12629. + .open = v4l2_fh_open,
  12630. + .release = vb2_fop_release,
  12631. + .read = vb2_fop_read,
  12632. + .poll = vb2_fop_poll,
  12633. + .unlocked_ioctl = video_ioctl2, /* V4L2 ioctl handler */
  12634. + .mmap = vb2_fop_mmap,
  12635. +};
  12636. +
  12637. +static struct video_device vdev_template = {
  12638. + .name = "camera0",
  12639. + .fops = &camera0_fops,
  12640. + .ioctl_ops = &camera0_ioctl_ops,
  12641. + .release = video_device_release_empty,
  12642. +};
  12643. +
  12644. +static int set_camera_parameters(struct vchiq_mmal_instance *instance,
  12645. + struct vchiq_mmal_component *camera)
  12646. +{
  12647. + int ret;
  12648. + struct mmal_parameter_camera_config cam_config = {
  12649. + .max_stills_w = MAX_WIDTH,
  12650. + .max_stills_h = MAX_HEIGHT,
  12651. + .stills_yuv422 = 1,
  12652. + .one_shot_stills = 1,
  12653. + .max_preview_video_w = 1920,
  12654. + .max_preview_video_h = 1088,
  12655. + .num_preview_video_frames = 3,
  12656. + .stills_capture_circular_buffer_height = 0,
  12657. + .fast_preview_resume = 0,
  12658. + .use_stc_timestamp = MMAL_PARAM_TIMESTAMP_MODE_RAW_STC
  12659. + };
  12660. +
  12661. + ret = vchiq_mmal_port_parameter_set(instance, &camera->control,
  12662. + MMAL_PARAMETER_CAMERA_CONFIG,
  12663. + &cam_config, sizeof(cam_config));
  12664. + return ret;
  12665. +}
  12666. +
  12667. +/* MMAL instance and component init */
  12668. +static int __init mmal_init(struct bm2835_mmal_dev *dev)
  12669. +{
  12670. + int ret;
  12671. + struct mmal_es_format *format;
  12672. +
  12673. + ret = vchiq_mmal_init(&dev->instance);
  12674. + if (ret < 0)
  12675. + return ret;
  12676. +
  12677. + /* get the camera component ready */
  12678. + ret = vchiq_mmal_component_init(dev->instance, "ril.camera",
  12679. + &dev->component[MMAL_COMPONENT_CAMERA]);
  12680. + if (ret < 0)
  12681. + goto unreg_mmal;
  12682. +
  12683. + if (dev->component[MMAL_COMPONENT_CAMERA]->outputs <
  12684. + MMAL_CAMERA_PORT_COUNT) {
  12685. + ret = -EINVAL;
  12686. + goto unreg_camera;
  12687. + }
  12688. +
  12689. + ret = set_camera_parameters(dev->instance,
  12690. + dev->component[MMAL_COMPONENT_CAMERA]);
  12691. + if (ret < 0)
  12692. + goto unreg_camera;
  12693. +
  12694. + format =
  12695. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12696. + output[MMAL_CAMERA_PORT_PREVIEW].format;
  12697. +
  12698. + format->encoding = MMAL_ENCODING_OPAQUE;
  12699. + format->encoding_variant = MMAL_ENCODING_I420;
  12700. +
  12701. + format->es->video.width = 1024;
  12702. + format->es->video.height = 768;
  12703. + format->es->video.crop.x = 0;
  12704. + format->es->video.crop.y = 0;
  12705. + format->es->video.crop.width = 1024;
  12706. + format->es->video.crop.height = 768;
  12707. + format->es->video.frame_rate.num = 0; /* Rely on fps_range */
  12708. + format->es->video.frame_rate.den = 1;
  12709. +
  12710. + format =
  12711. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12712. + output[MMAL_CAMERA_PORT_VIDEO].format;
  12713. +
  12714. + format->encoding = MMAL_ENCODING_OPAQUE;
  12715. + format->encoding_variant = MMAL_ENCODING_I420;
  12716. +
  12717. + format->es->video.width = 1024;
  12718. + format->es->video.height = 768;
  12719. + format->es->video.crop.x = 0;
  12720. + format->es->video.crop.y = 0;
  12721. + format->es->video.crop.width = 1024;
  12722. + format->es->video.crop.height = 768;
  12723. + format->es->video.frame_rate.num = 0; /* Rely on fps_range */
  12724. + format->es->video.frame_rate.den = 1;
  12725. +
  12726. + format =
  12727. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12728. + output[MMAL_CAMERA_PORT_CAPTURE].format;
  12729. +
  12730. + format->encoding = MMAL_ENCODING_OPAQUE;
  12731. +
  12732. + format->es->video.width = 2592;
  12733. + format->es->video.height = 1944;
  12734. + format->es->video.crop.x = 0;
  12735. + format->es->video.crop.y = 0;
  12736. + format->es->video.crop.width = 2592;
  12737. + format->es->video.crop.height = 1944;
  12738. + format->es->video.frame_rate.num = 0; /* Rely on fps_range */
  12739. + format->es->video.frame_rate.den = 1;
  12740. +
  12741. + dev->capture.width = format->es->video.width;
  12742. + dev->capture.height = format->es->video.height;
  12743. + dev->capture.fmt = &formats[0];
  12744. + dev->capture.encode_component = NULL;
  12745. + dev->capture.timeperframe = tpf_default;
  12746. + dev->capture.enc_profile = V4L2_MPEG_VIDEO_H264_PROFILE_HIGH;
  12747. + dev->capture.enc_level = V4L2_MPEG_VIDEO_H264_LEVEL_4_0;
  12748. +
  12749. + /* get the preview component ready */
  12750. + ret = vchiq_mmal_component_init(
  12751. + dev->instance, "ril.video_render",
  12752. + &dev->component[MMAL_COMPONENT_PREVIEW]);
  12753. + if (ret < 0)
  12754. + goto unreg_camera;
  12755. +
  12756. + if (dev->component[MMAL_COMPONENT_PREVIEW]->inputs < 1) {
  12757. + ret = -EINVAL;
  12758. + pr_debug("too few input ports %d needed %d\n",
  12759. + dev->component[MMAL_COMPONENT_PREVIEW]->inputs, 1);
  12760. + goto unreg_preview;
  12761. + }
  12762. +
  12763. + /* get the image encoder component ready */
  12764. + ret = vchiq_mmal_component_init(
  12765. + dev->instance, "ril.image_encode",
  12766. + &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]);
  12767. + if (ret < 0)
  12768. + goto unreg_preview;
  12769. +
  12770. + if (dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->inputs < 1) {
  12771. + ret = -EINVAL;
  12772. + v4l2_err(&dev->v4l2_dev, "too few input ports %d needed %d\n",
  12773. + dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->inputs,
  12774. + 1);
  12775. + goto unreg_image_encoder;
  12776. + }
  12777. +
  12778. + /* get the video encoder component ready */
  12779. + ret = vchiq_mmal_component_init(dev->instance, "ril.video_encode",
  12780. + &dev->
  12781. + component[MMAL_COMPONENT_VIDEO_ENCODE]);
  12782. + if (ret < 0)
  12783. + goto unreg_image_encoder;
  12784. +
  12785. + if (dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->inputs < 1) {
  12786. + ret = -EINVAL;
  12787. + v4l2_err(&dev->v4l2_dev, "too few input ports %d needed %d\n",
  12788. + dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->inputs,
  12789. + 1);
  12790. + goto unreg_vid_encoder;
  12791. + }
  12792. +
  12793. + {
  12794. + struct vchiq_mmal_port *encoder_port =
  12795. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  12796. + encoder_port->format.encoding = MMAL_ENCODING_H264;
  12797. + ret = vchiq_mmal_port_set_format(dev->instance,
  12798. + encoder_port);
  12799. + }
  12800. +
  12801. + {
  12802. + unsigned int enable = 1;
  12803. + vchiq_mmal_port_parameter_set(
  12804. + dev->instance,
  12805. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->control,
  12806. + MMAL_PARAMETER_VIDEO_IMMUTABLE_INPUT,
  12807. + &enable, sizeof(enable));
  12808. +
  12809. + vchiq_mmal_port_parameter_set(dev->instance,
  12810. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->control,
  12811. + MMAL_PARAMETER_MINIMISE_FRAGMENTATION,
  12812. + &enable,
  12813. + sizeof(enable));
  12814. + }
  12815. + ret = bm2835_mmal_set_all_camera_controls(dev);
  12816. + if (ret < 0)
  12817. + goto unreg_vid_encoder;
  12818. +
  12819. + return 0;
  12820. +
  12821. +unreg_vid_encoder:
  12822. + pr_err("Cleanup: Destroy video encoder\n");
  12823. + vchiq_mmal_component_finalise(
  12824. + dev->instance,
  12825. + dev->component[MMAL_COMPONENT_VIDEO_ENCODE]);
  12826. +
  12827. +unreg_image_encoder:
  12828. + pr_err("Cleanup: Destroy image encoder\n");
  12829. + vchiq_mmal_component_finalise(
  12830. + dev->instance,
  12831. + dev->component[MMAL_COMPONENT_IMAGE_ENCODE]);
  12832. +
  12833. +unreg_preview:
  12834. + pr_err("Cleanup: Destroy video render\n");
  12835. + vchiq_mmal_component_finalise(dev->instance,
  12836. + dev->component[MMAL_COMPONENT_PREVIEW]);
  12837. +
  12838. +unreg_camera:
  12839. + pr_err("Cleanup: Destroy camera\n");
  12840. + vchiq_mmal_component_finalise(dev->instance,
  12841. + dev->component[MMAL_COMPONENT_CAMERA]);
  12842. +
  12843. +unreg_mmal:
  12844. + vchiq_mmal_finalise(dev->instance);
  12845. + return ret;
  12846. +}
  12847. +
  12848. +static int __init bm2835_mmal_init_device(struct bm2835_mmal_dev *dev,
  12849. + struct video_device *vfd)
  12850. +{
  12851. + int ret;
  12852. +
  12853. + *vfd = vdev_template;
  12854. +
  12855. + vfd->v4l2_dev = &dev->v4l2_dev;
  12856. +
  12857. + vfd->lock = &dev->mutex;
  12858. +
  12859. + vfd->queue = &dev->capture.vb_vidq;
  12860. +
  12861. + set_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
  12862. +
  12863. + /* video device needs to be able to access instance data */
  12864. + video_set_drvdata(vfd, dev);
  12865. +
  12866. + ret = video_register_device(vfd, VFL_TYPE_GRABBER, -1);
  12867. + if (ret < 0)
  12868. + return ret;
  12869. +
  12870. + v4l2_info(vfd->v4l2_dev, "V4L2 device registered as %s\n",
  12871. + video_device_node_name(vfd));
  12872. +
  12873. + return 0;
  12874. +}
  12875. +
  12876. +static struct v4l2_format default_v4l2_format = {
  12877. + .fmt.pix.pixelformat = V4L2_PIX_FMT_JPEG,
  12878. + .fmt.pix.width = 1024,
  12879. + .fmt.pix.bytesperline = 1024 * 3 / 2,
  12880. + .fmt.pix.height = 768,
  12881. + .fmt.pix.sizeimage = 1<<18,
  12882. +};
  12883. +
  12884. +static int __init bm2835_mmal_init(void)
  12885. +{
  12886. + int ret;
  12887. + struct bm2835_mmal_dev *dev;
  12888. + struct vb2_queue *q;
  12889. +
  12890. + dev = kzalloc(sizeof(*gdev), GFP_KERNEL);
  12891. + if (!dev)
  12892. + return -ENOMEM;
  12893. +
  12894. + /* setup device defaults */
  12895. + dev->overlay.w.left = 150;
  12896. + dev->overlay.w.top = 50;
  12897. + dev->overlay.w.width = 1024;
  12898. + dev->overlay.w.height = 768;
  12899. + dev->overlay.clipcount = 0;
  12900. + dev->overlay.field = V4L2_FIELD_NONE;
  12901. +
  12902. + dev->capture.fmt = &formats[3]; /* JPEG */
  12903. +
  12904. + /* v4l device registration */
  12905. + snprintf(dev->v4l2_dev.name, sizeof(dev->v4l2_dev.name),
  12906. + "%s", BM2835_MMAL_MODULE_NAME);
  12907. + ret = v4l2_device_register(NULL, &dev->v4l2_dev);
  12908. + if (ret)
  12909. + goto free_dev;
  12910. +
  12911. + /* setup v4l controls */
  12912. + ret = bm2835_mmal_init_controls(dev, &dev->ctrl_handler);
  12913. + if (ret < 0)
  12914. + goto unreg_dev;
  12915. + dev->v4l2_dev.ctrl_handler = &dev->ctrl_handler;
  12916. +
  12917. + /* mmal init */
  12918. + ret = mmal_init(dev);
  12919. + if (ret < 0)
  12920. + goto unreg_dev;
  12921. +
  12922. + /* initialize queue */
  12923. + q = &dev->capture.vb_vidq;
  12924. + memset(q, 0, sizeof(*q));
  12925. + q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  12926. + q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ;
  12927. + q->drv_priv = dev;
  12928. + q->buf_struct_size = sizeof(struct mmal_buffer);
  12929. + q->ops = &bm2835_mmal_video_qops;
  12930. + q->mem_ops = &vb2_vmalloc_memops;
  12931. + q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
  12932. + ret = vb2_queue_init(q);
  12933. + if (ret < 0)
  12934. + goto unreg_dev;
  12935. +
  12936. + /* v4l2 core mutex used to protect all fops and v4l2 ioctls. */
  12937. + mutex_init(&dev->mutex);
  12938. +
  12939. + /* initialise video devices */
  12940. + ret = bm2835_mmal_init_device(dev, &dev->vdev);
  12941. + if (ret < 0)
  12942. + goto unreg_dev;
  12943. +
  12944. + ret = mmal_setup_components(dev, &default_v4l2_format);
  12945. + if (ret < 0) {
  12946. + v4l2_err(&dev->v4l2_dev,
  12947. + "%s: could not setup components\n", __func__);
  12948. + goto unreg_dev;
  12949. + }
  12950. +
  12951. + v4l2_info(&dev->v4l2_dev,
  12952. + "Broadcom 2835 MMAL video capture ver %s loaded.\n",
  12953. + BM2835_MMAL_VERSION);
  12954. +
  12955. + gdev = dev;
  12956. + return 0;
  12957. +
  12958. +unreg_dev:
  12959. + v4l2_ctrl_handler_free(&dev->ctrl_handler);
  12960. + v4l2_device_unregister(&dev->v4l2_dev);
  12961. +
  12962. +free_dev:
  12963. + kfree(dev);
  12964. +
  12965. + v4l2_err(&dev->v4l2_dev,
  12966. + "%s: error %d while loading driver\n",
  12967. + BM2835_MMAL_MODULE_NAME, ret);
  12968. +
  12969. + return ret;
  12970. +}
  12971. +
  12972. +static void __exit bm2835_mmal_exit(void)
  12973. +{
  12974. + if (!gdev)
  12975. + return;
  12976. +
  12977. + v4l2_info(&gdev->v4l2_dev, "unregistering %s\n",
  12978. + video_device_node_name(&gdev->vdev));
  12979. +
  12980. + video_unregister_device(&gdev->vdev);
  12981. +
  12982. + if (gdev->capture.encode_component) {
  12983. + v4l2_dbg(1, bcm2835_v4l2_debug, &gdev->v4l2_dev,
  12984. + "mmal_exit - disconnect tunnel\n");
  12985. + vchiq_mmal_port_connect_tunnel(gdev->instance,
  12986. + gdev->capture.camera_port, NULL);
  12987. + vchiq_mmal_component_disable(gdev->instance,
  12988. + gdev->capture.encode_component);
  12989. + }
  12990. + vchiq_mmal_component_disable(gdev->instance,
  12991. + gdev->component[MMAL_COMPONENT_CAMERA]);
  12992. +
  12993. + vchiq_mmal_component_finalise(gdev->instance,
  12994. + gdev->
  12995. + component[MMAL_COMPONENT_VIDEO_ENCODE]);
  12996. +
  12997. + vchiq_mmal_component_finalise(gdev->instance,
  12998. + gdev->
  12999. + component[MMAL_COMPONENT_IMAGE_ENCODE]);
  13000. +
  13001. + vchiq_mmal_component_finalise(gdev->instance,
  13002. + gdev->component[MMAL_COMPONENT_PREVIEW]);
  13003. +
  13004. + vchiq_mmal_component_finalise(gdev->instance,
  13005. + gdev->component[MMAL_COMPONENT_CAMERA]);
  13006. +
  13007. + vchiq_mmal_finalise(gdev->instance);
  13008. +
  13009. + v4l2_ctrl_handler_free(&gdev->ctrl_handler);
  13010. +
  13011. + v4l2_device_unregister(&gdev->v4l2_dev);
  13012. +
  13013. + kfree(gdev);
  13014. +}
  13015. +
  13016. +module_init(bm2835_mmal_init);
  13017. +module_exit(bm2835_mmal_exit);
  13018. diff -Nur linux-3.12.26.orig/drivers/media/platform/bcm2835/bcm2835-camera.h linux-3.12.26/drivers/media/platform/bcm2835/bcm2835-camera.h
  13019. --- linux-3.12.26.orig/drivers/media/platform/bcm2835/bcm2835-camera.h 1970-01-01 01:00:00.000000000 +0100
  13020. +++ linux-3.12.26/drivers/media/platform/bcm2835/bcm2835-camera.h 2014-08-06 16:50:14.349961177 +0200
  13021. @@ -0,0 +1,125 @@
  13022. +/*
  13023. + * Broadcom BM2835 V4L2 driver
  13024. + *
  13025. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  13026. + *
  13027. + * This file is subject to the terms and conditions of the GNU General Public
  13028. + * License. See the file COPYING in the main directory of this archive
  13029. + * for more details.
  13030. + *
  13031. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  13032. + * Dave Stevenson <dsteve@broadcom.com>
  13033. + * Simon Mellor <simellor@broadcom.com>
  13034. + * Luke Diamand <luked@broadcom.com>
  13035. + *
  13036. + * core driver device
  13037. + */
  13038. +
  13039. +#define V4L2_CTRL_COUNT 27 /* number of v4l controls */
  13040. +
  13041. +enum {
  13042. + MMAL_COMPONENT_CAMERA = 0,
  13043. + MMAL_COMPONENT_PREVIEW,
  13044. + MMAL_COMPONENT_IMAGE_ENCODE,
  13045. + MMAL_COMPONENT_VIDEO_ENCODE,
  13046. + MMAL_COMPONENT_COUNT
  13047. +};
  13048. +
  13049. +enum {
  13050. + MMAL_CAMERA_PORT_PREVIEW = 0,
  13051. + MMAL_CAMERA_PORT_VIDEO,
  13052. + MMAL_CAMERA_PORT_CAPTURE,
  13053. + MMAL_CAMERA_PORT_COUNT
  13054. +};
  13055. +
  13056. +#define PREVIEW_LAYER 2
  13057. +
  13058. +extern int bcm2835_v4l2_debug;
  13059. +
  13060. +struct bm2835_mmal_dev {
  13061. + /* v4l2 devices */
  13062. + struct v4l2_device v4l2_dev;
  13063. + struct video_device vdev;
  13064. + struct mutex mutex;
  13065. +
  13066. + /* controls */
  13067. + struct v4l2_ctrl_handler ctrl_handler;
  13068. + struct v4l2_ctrl *ctrls[V4L2_CTRL_COUNT];
  13069. + enum v4l2_scene_mode scene_mode;
  13070. + struct mmal_colourfx colourfx;
  13071. + int hflip;
  13072. + int vflip;
  13073. + int red_gain;
  13074. + int blue_gain;
  13075. + enum mmal_parameter_exposuremode exposure_mode_user;
  13076. + enum v4l2_exposure_auto_type exposure_mode_v4l2_user;
  13077. + /* active exposure mode may differ if selected via a scene mode */
  13078. + enum mmal_parameter_exposuremode exposure_mode_active;
  13079. + enum mmal_parameter_exposuremeteringmode metering_mode;
  13080. + unsigned int manual_shutter_speed;
  13081. + bool exp_auto_priority;
  13082. +
  13083. + /* allocated mmal instance and components */
  13084. + struct vchiq_mmal_instance *instance;
  13085. + struct vchiq_mmal_component *component[MMAL_COMPONENT_COUNT];
  13086. + int camera_use_count;
  13087. +
  13088. + struct v4l2_window overlay;
  13089. +
  13090. + struct {
  13091. + unsigned int width; /* width */
  13092. + unsigned int height; /* height */
  13093. + unsigned int stride; /* stride */
  13094. + struct mmal_fmt *fmt;
  13095. + struct v4l2_fract timeperframe;
  13096. +
  13097. + /* H264 encode bitrate */
  13098. + int encode_bitrate;
  13099. + /* H264 bitrate mode. CBR/VBR */
  13100. + int encode_bitrate_mode;
  13101. + /* H264 profile */
  13102. + enum v4l2_mpeg_video_h264_profile enc_profile;
  13103. + /* H264 level */
  13104. + enum v4l2_mpeg_video_h264_level enc_level;
  13105. + /* JPEG Q-factor */
  13106. + int q_factor;
  13107. +
  13108. + struct vb2_queue vb_vidq;
  13109. +
  13110. + /* VC start timestamp for streaming */
  13111. + s64 vc_start_timestamp;
  13112. + /* Kernel start timestamp for streaming */
  13113. + struct timeval kernel_start_ts;
  13114. +
  13115. + struct vchiq_mmal_port *port; /* port being used for capture */
  13116. + /* camera port being used for capture */
  13117. + struct vchiq_mmal_port *camera_port;
  13118. + /* component being used for encode */
  13119. + struct vchiq_mmal_component *encode_component;
  13120. + /* number of frames remaining which driver should capture */
  13121. + unsigned int frame_count;
  13122. + /* last frame completion */
  13123. + struct completion frame_cmplt;
  13124. +
  13125. + } capture;
  13126. +
  13127. +};
  13128. +
  13129. +int bm2835_mmal_init_controls(
  13130. + struct bm2835_mmal_dev *dev,
  13131. + struct v4l2_ctrl_handler *hdl);
  13132. +
  13133. +int bm2835_mmal_set_all_camera_controls(struct bm2835_mmal_dev *dev);
  13134. +int set_framerate_params(struct bm2835_mmal_dev *dev);
  13135. +
  13136. +/* Debug helpers */
  13137. +
  13138. +#define v4l2_dump_pix_format(level, debug, dev, pix_fmt, desc) \
  13139. +{ \
  13140. + v4l2_dbg(level, debug, dev, \
  13141. +"%s: w %u h %u field %u pfmt 0x%x bpl %u sz_img %u colorspace 0x%x priv %u\n", \
  13142. + desc == NULL ? "" : desc, \
  13143. + (pix_fmt)->width, (pix_fmt)->height, (pix_fmt)->field, \
  13144. + (pix_fmt)->pixelformat, (pix_fmt)->bytesperline, \
  13145. + (pix_fmt)->sizeimage, (pix_fmt)->colorspace, (pix_fmt)->priv); \
  13146. +}
  13147. diff -Nur linux-3.12.26.orig/drivers/media/platform/bcm2835/controls.c linux-3.12.26/drivers/media/platform/bcm2835/controls.c
  13148. --- linux-3.12.26.orig/drivers/media/platform/bcm2835/controls.c 1970-01-01 01:00:00.000000000 +0100
  13149. +++ linux-3.12.26/drivers/media/platform/bcm2835/controls.c 2014-08-06 16:50:14.349961177 +0200
  13150. @@ -0,0 +1,1315 @@
  13151. +/*
  13152. + * Broadcom BM2835 V4L2 driver
  13153. + *
  13154. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  13155. + *
  13156. + * This file is subject to the terms and conditions of the GNU General Public
  13157. + * License. See the file COPYING in the main directory of this archive
  13158. + * for more details.
  13159. + *
  13160. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  13161. + * Dave Stevenson <dsteve@broadcom.com>
  13162. + * Simon Mellor <simellor@broadcom.com>
  13163. + * Luke Diamand <luked@broadcom.com>
  13164. + */
  13165. +
  13166. +#include <linux/errno.h>
  13167. +#include <linux/kernel.h>
  13168. +#include <linux/module.h>
  13169. +#include <linux/slab.h>
  13170. +#include <media/videobuf2-vmalloc.h>
  13171. +#include <media/v4l2-device.h>
  13172. +#include <media/v4l2-ioctl.h>
  13173. +#include <media/v4l2-ctrls.h>
  13174. +#include <media/v4l2-fh.h>
  13175. +#include <media/v4l2-event.h>
  13176. +#include <media/v4l2-common.h>
  13177. +
  13178. +#include "mmal-common.h"
  13179. +#include "mmal-vchiq.h"
  13180. +#include "mmal-parameters.h"
  13181. +#include "bcm2835-camera.h"
  13182. +
  13183. +/* The supported V4L2_CID_AUTO_EXPOSURE_BIAS values are from -4.0 to +4.0.
  13184. + * MMAL values are in 1/6th increments so the MMAL range is -24 to +24.
  13185. + * V4L2 docs say value "is expressed in terms of EV, drivers should interpret
  13186. + * the values as 0.001 EV units, where the value 1000 stands for +1 EV."
  13187. + * V4L2 is limited to a max of 32 values in a menu, so count in 1/3rds from
  13188. + * -4 to +4
  13189. + */
  13190. +static const s64 ev_bias_qmenu[] = {
  13191. + -4000, -3667, -3333,
  13192. + -3000, -2667, -2333,
  13193. + -2000, -1667, -1333,
  13194. + -1000, -667, -333,
  13195. + 0, 333, 667,
  13196. + 1000, 1333, 1667,
  13197. + 2000, 2333, 2667,
  13198. + 3000, 3333, 3667,
  13199. + 4000
  13200. +};
  13201. +
  13202. +/* Supported ISO values
  13203. + * ISOO = auto ISO
  13204. + */
  13205. +static const s64 iso_qmenu[] = {
  13206. + 0, 100, 200, 400, 800,
  13207. +};
  13208. +
  13209. +static const s64 mains_freq_qmenu[] = {
  13210. + V4L2_CID_POWER_LINE_FREQUENCY_DISABLED,
  13211. + V4L2_CID_POWER_LINE_FREQUENCY_50HZ,
  13212. + V4L2_CID_POWER_LINE_FREQUENCY_60HZ,
  13213. + V4L2_CID_POWER_LINE_FREQUENCY_AUTO
  13214. +};
  13215. +
  13216. +/* Supported video encode modes */
  13217. +static const s64 bitrate_mode_qmenu[] = {
  13218. + (s64)V4L2_MPEG_VIDEO_BITRATE_MODE_VBR,
  13219. + (s64)V4L2_MPEG_VIDEO_BITRATE_MODE_CBR,
  13220. +};
  13221. +
  13222. +enum bm2835_mmal_ctrl_type {
  13223. + MMAL_CONTROL_TYPE_STD,
  13224. + MMAL_CONTROL_TYPE_STD_MENU,
  13225. + MMAL_CONTROL_TYPE_INT_MENU,
  13226. + MMAL_CONTROL_TYPE_CLUSTER, /* special cluster entry */
  13227. +};
  13228. +
  13229. +struct bm2835_mmal_v4l2_ctrl;
  13230. +
  13231. +typedef int(bm2835_mmal_v4l2_ctrl_cb)(
  13232. + struct bm2835_mmal_dev *dev,
  13233. + struct v4l2_ctrl *ctrl,
  13234. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl);
  13235. +
  13236. +struct bm2835_mmal_v4l2_ctrl {
  13237. + u32 id; /* v4l2 control identifier */
  13238. + enum bm2835_mmal_ctrl_type type;
  13239. + /* control minimum value or
  13240. + * mask for MMAL_CONTROL_TYPE_STD_MENU */
  13241. + s32 min;
  13242. + s32 max; /* maximum value of control */
  13243. + s32 def; /* default value of control */
  13244. + s32 step; /* step size of the control */
  13245. + const s64 *imenu; /* integer menu array */
  13246. + u32 mmal_id; /* mmal parameter id */
  13247. + bm2835_mmal_v4l2_ctrl_cb *setter;
  13248. + bool ignore_errors;
  13249. +};
  13250. +
  13251. +struct v4l2_to_mmal_effects_setting {
  13252. + u32 v4l2_effect;
  13253. + u32 mmal_effect;
  13254. + s32 col_fx_enable;
  13255. + s32 col_fx_fixed_cbcr;
  13256. + u32 u;
  13257. + u32 v;
  13258. + u32 num_effect_params;
  13259. + u32 effect_params[MMAL_MAX_IMAGEFX_PARAMETERS];
  13260. +};
  13261. +
  13262. +static const struct v4l2_to_mmal_effects_setting
  13263. + v4l2_to_mmal_effects_values[] = {
  13264. + { V4L2_COLORFX_NONE, MMAL_PARAM_IMAGEFX_NONE,
  13265. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  13266. + { V4L2_COLORFX_BW, MMAL_PARAM_IMAGEFX_NONE,
  13267. + 1, 0, 128, 128, 0, {0, 0, 0, 0, 0} },
  13268. + { V4L2_COLORFX_SEPIA, MMAL_PARAM_IMAGEFX_NONE,
  13269. + 1, 0, 87, 151, 0, {0, 0, 0, 0, 0} },
  13270. + { V4L2_COLORFX_NEGATIVE, MMAL_PARAM_IMAGEFX_NEGATIVE,
  13271. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  13272. + { V4L2_COLORFX_EMBOSS, MMAL_PARAM_IMAGEFX_EMBOSS,
  13273. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  13274. + { V4L2_COLORFX_SKETCH, MMAL_PARAM_IMAGEFX_SKETCH,
  13275. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  13276. + { V4L2_COLORFX_SKY_BLUE, MMAL_PARAM_IMAGEFX_PASTEL,
  13277. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  13278. + { V4L2_COLORFX_GRASS_GREEN, MMAL_PARAM_IMAGEFX_WATERCOLOUR,
  13279. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  13280. + { V4L2_COLORFX_SKIN_WHITEN, MMAL_PARAM_IMAGEFX_WASHEDOUT,
  13281. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  13282. + { V4L2_COLORFX_VIVID, MMAL_PARAM_IMAGEFX_SATURATION,
  13283. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  13284. + { V4L2_COLORFX_AQUA, MMAL_PARAM_IMAGEFX_NONE,
  13285. + 1, 0, 171, 121, 0, {0, 0, 0, 0, 0} },
  13286. + { V4L2_COLORFX_ART_FREEZE, MMAL_PARAM_IMAGEFX_HATCH,
  13287. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  13288. + { V4L2_COLORFX_SILHOUETTE, MMAL_PARAM_IMAGEFX_FILM,
  13289. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  13290. + { V4L2_COLORFX_SOLARIZATION, MMAL_PARAM_IMAGEFX_SOLARIZE,
  13291. + 0, 0, 0, 0, 5, {1, 128, 160, 160, 48} },
  13292. + { V4L2_COLORFX_ANTIQUE, MMAL_PARAM_IMAGEFX_COLOURBALANCE,
  13293. + 0, 0, 0, 0, 3, {108, 274, 238, 0, 0} },
  13294. + { V4L2_COLORFX_SET_CBCR, MMAL_PARAM_IMAGEFX_NONE,
  13295. + 1, 1, 0, 0, 0, {0, 0, 0, 0, 0} }
  13296. +};
  13297. +
  13298. +struct v4l2_mmal_scene_config {
  13299. + enum v4l2_scene_mode v4l2_scene;
  13300. + enum mmal_parameter_exposuremode exposure_mode;
  13301. + enum mmal_parameter_exposuremeteringmode metering_mode;
  13302. +};
  13303. +
  13304. +static const struct v4l2_mmal_scene_config scene_configs[] = {
  13305. + /* V4L2_SCENE_MODE_NONE automatically added */
  13306. + {
  13307. + V4L2_SCENE_MODE_NIGHT,
  13308. + MMAL_PARAM_EXPOSUREMODE_NIGHT,
  13309. + MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE
  13310. + },
  13311. + {
  13312. + V4L2_SCENE_MODE_SPORTS,
  13313. + MMAL_PARAM_EXPOSUREMODE_SPORTS,
  13314. + MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE
  13315. + },
  13316. +};
  13317. +
  13318. +/* control handlers*/
  13319. +
  13320. +static int ctrl_set_rational(struct bm2835_mmal_dev *dev,
  13321. + struct v4l2_ctrl *ctrl,
  13322. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13323. +{
  13324. + struct mmal_parameter_rational rational_value;
  13325. + struct vchiq_mmal_port *control;
  13326. +
  13327. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13328. +
  13329. + rational_value.num = ctrl->val;
  13330. + rational_value.den = 100;
  13331. +
  13332. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  13333. + mmal_ctrl->mmal_id,
  13334. + &rational_value,
  13335. + sizeof(rational_value));
  13336. +}
  13337. +
  13338. +static int ctrl_set_value(struct bm2835_mmal_dev *dev,
  13339. + struct v4l2_ctrl *ctrl,
  13340. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13341. +{
  13342. + u32 u32_value;
  13343. + struct vchiq_mmal_port *control;
  13344. +
  13345. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13346. +
  13347. + u32_value = ctrl->val;
  13348. +
  13349. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  13350. + mmal_ctrl->mmal_id,
  13351. + &u32_value, sizeof(u32_value));
  13352. +}
  13353. +
  13354. +static int ctrl_set_value_menu(struct bm2835_mmal_dev *dev,
  13355. + struct v4l2_ctrl *ctrl,
  13356. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13357. +{
  13358. + u32 u32_value;
  13359. + struct vchiq_mmal_port *control;
  13360. +
  13361. + if (ctrl->val > mmal_ctrl->max || ctrl->val < mmal_ctrl->min)
  13362. + return 1;
  13363. +
  13364. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13365. +
  13366. + u32_value = mmal_ctrl->imenu[ctrl->val];
  13367. +
  13368. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  13369. + mmal_ctrl->mmal_id,
  13370. + &u32_value, sizeof(u32_value));
  13371. +}
  13372. +
  13373. +static int ctrl_set_value_ev(struct bm2835_mmal_dev *dev,
  13374. + struct v4l2_ctrl *ctrl,
  13375. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13376. +{
  13377. + s32 s32_value;
  13378. + struct vchiq_mmal_port *control;
  13379. +
  13380. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13381. +
  13382. + s32_value = (ctrl->val-12)*2; /* Convert from index to 1/6ths */
  13383. +
  13384. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  13385. + mmal_ctrl->mmal_id,
  13386. + &s32_value, sizeof(s32_value));
  13387. +}
  13388. +
  13389. +static int ctrl_set_rotate(struct bm2835_mmal_dev *dev,
  13390. + struct v4l2_ctrl *ctrl,
  13391. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13392. +{
  13393. + int ret;
  13394. + u32 u32_value;
  13395. + struct vchiq_mmal_component *camera;
  13396. +
  13397. + camera = dev->component[MMAL_COMPONENT_CAMERA];
  13398. +
  13399. + u32_value = ((ctrl->val % 360) / 90) * 90;
  13400. +
  13401. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[0],
  13402. + mmal_ctrl->mmal_id,
  13403. + &u32_value, sizeof(u32_value));
  13404. + if (ret < 0)
  13405. + return ret;
  13406. +
  13407. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[1],
  13408. + mmal_ctrl->mmal_id,
  13409. + &u32_value, sizeof(u32_value));
  13410. + if (ret < 0)
  13411. + return ret;
  13412. +
  13413. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[2],
  13414. + mmal_ctrl->mmal_id,
  13415. + &u32_value, sizeof(u32_value));
  13416. +
  13417. + return ret;
  13418. +}
  13419. +
  13420. +static int ctrl_set_flip(struct bm2835_mmal_dev *dev,
  13421. + struct v4l2_ctrl *ctrl,
  13422. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13423. +{
  13424. + int ret;
  13425. + u32 u32_value;
  13426. + struct vchiq_mmal_component *camera;
  13427. +
  13428. + if (ctrl->id == V4L2_CID_HFLIP)
  13429. + dev->hflip = ctrl->val;
  13430. + else
  13431. + dev->vflip = ctrl->val;
  13432. +
  13433. + camera = dev->component[MMAL_COMPONENT_CAMERA];
  13434. +
  13435. + if (dev->hflip && dev->vflip)
  13436. + u32_value = MMAL_PARAM_MIRROR_BOTH;
  13437. + else if (dev->hflip)
  13438. + u32_value = MMAL_PARAM_MIRROR_HORIZONTAL;
  13439. + else if (dev->vflip)
  13440. + u32_value = MMAL_PARAM_MIRROR_VERTICAL;
  13441. + else
  13442. + u32_value = MMAL_PARAM_MIRROR_NONE;
  13443. +
  13444. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[0],
  13445. + mmal_ctrl->mmal_id,
  13446. + &u32_value, sizeof(u32_value));
  13447. + if (ret < 0)
  13448. + return ret;
  13449. +
  13450. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[1],
  13451. + mmal_ctrl->mmal_id,
  13452. + &u32_value, sizeof(u32_value));
  13453. + if (ret < 0)
  13454. + return ret;
  13455. +
  13456. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[2],
  13457. + mmal_ctrl->mmal_id,
  13458. + &u32_value, sizeof(u32_value));
  13459. +
  13460. + return ret;
  13461. +
  13462. +}
  13463. +
  13464. +static int ctrl_set_exposure(struct bm2835_mmal_dev *dev,
  13465. + struct v4l2_ctrl *ctrl,
  13466. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13467. +{
  13468. + enum mmal_parameter_exposuremode exp_mode = dev->exposure_mode_user;
  13469. + u32 shutter_speed = 0;
  13470. + struct vchiq_mmal_port *control;
  13471. + int ret = 0;
  13472. +
  13473. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13474. +
  13475. + if (mmal_ctrl->mmal_id == MMAL_PARAMETER_SHUTTER_SPEED) {
  13476. + /* V4L2 is in 100usec increments.
  13477. + * MMAL is 1usec.
  13478. + */
  13479. + dev->manual_shutter_speed = ctrl->val * 100;
  13480. + } else if (mmal_ctrl->mmal_id == MMAL_PARAMETER_EXPOSURE_MODE) {
  13481. + switch (ctrl->val) {
  13482. + case V4L2_EXPOSURE_AUTO:
  13483. + exp_mode = MMAL_PARAM_EXPOSUREMODE_AUTO;
  13484. + break;
  13485. +
  13486. + case V4L2_EXPOSURE_MANUAL:
  13487. + exp_mode = MMAL_PARAM_EXPOSUREMODE_OFF;
  13488. + break;
  13489. + }
  13490. + dev->exposure_mode_user = exp_mode;
  13491. + dev->exposure_mode_v4l2_user = ctrl->val;
  13492. + } else if (mmal_ctrl->id == V4L2_CID_EXPOSURE_AUTO_PRIORITY) {
  13493. + dev->exp_auto_priority = ctrl->val;
  13494. + }
  13495. +
  13496. + if (dev->scene_mode == V4L2_SCENE_MODE_NONE) {
  13497. + if (exp_mode == MMAL_PARAM_EXPOSUREMODE_OFF)
  13498. + shutter_speed = dev->manual_shutter_speed;
  13499. +
  13500. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  13501. + control,
  13502. + MMAL_PARAMETER_SHUTTER_SPEED,
  13503. + &shutter_speed,
  13504. + sizeof(shutter_speed));
  13505. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  13506. + control,
  13507. + MMAL_PARAMETER_EXPOSURE_MODE,
  13508. + &exp_mode,
  13509. + sizeof(u32));
  13510. + dev->exposure_mode_active = exp_mode;
  13511. + }
  13512. + /* exposure_dynamic_framerate (V4L2_CID_EXPOSURE_AUTO_PRIORITY) should
  13513. + * always apply irrespective of scene mode.
  13514. + */
  13515. + ret += set_framerate_params(dev);
  13516. +
  13517. + return ret;
  13518. +}
  13519. +
  13520. +static int ctrl_set_metering_mode(struct bm2835_mmal_dev *dev,
  13521. + struct v4l2_ctrl *ctrl,
  13522. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13523. +{
  13524. + switch (ctrl->val) {
  13525. + case V4L2_EXPOSURE_METERING_AVERAGE:
  13526. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE;
  13527. + break;
  13528. +
  13529. + case V4L2_EXPOSURE_METERING_CENTER_WEIGHTED:
  13530. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_BACKLIT;
  13531. + break;
  13532. +
  13533. + case V4L2_EXPOSURE_METERING_SPOT:
  13534. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_SPOT;
  13535. + break;
  13536. +
  13537. + /* todo matrix weighting not added to Linux API till 3.9
  13538. + case V4L2_EXPOSURE_METERING_MATRIX:
  13539. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_MATRIX;
  13540. + break;
  13541. + */
  13542. +
  13543. + }
  13544. +
  13545. + if (dev->scene_mode == V4L2_SCENE_MODE_NONE) {
  13546. + struct vchiq_mmal_port *control;
  13547. + u32 u32_value = dev->metering_mode;
  13548. +
  13549. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13550. +
  13551. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  13552. + mmal_ctrl->mmal_id,
  13553. + &u32_value, sizeof(u32_value));
  13554. + } else
  13555. + return 0;
  13556. +}
  13557. +
  13558. +static int ctrl_set_flicker_avoidance(struct bm2835_mmal_dev *dev,
  13559. + struct v4l2_ctrl *ctrl,
  13560. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13561. +{
  13562. + u32 u32_value;
  13563. + struct vchiq_mmal_port *control;
  13564. +
  13565. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13566. +
  13567. + switch (ctrl->val) {
  13568. + case V4L2_CID_POWER_LINE_FREQUENCY_DISABLED:
  13569. + u32_value = MMAL_PARAM_FLICKERAVOID_OFF;
  13570. + break;
  13571. + case V4L2_CID_POWER_LINE_FREQUENCY_50HZ:
  13572. + u32_value = MMAL_PARAM_FLICKERAVOID_50HZ;
  13573. + break;
  13574. + case V4L2_CID_POWER_LINE_FREQUENCY_60HZ:
  13575. + u32_value = MMAL_PARAM_FLICKERAVOID_60HZ;
  13576. + break;
  13577. + case V4L2_CID_POWER_LINE_FREQUENCY_AUTO:
  13578. + u32_value = MMAL_PARAM_FLICKERAVOID_AUTO;
  13579. + break;
  13580. + }
  13581. +
  13582. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  13583. + mmal_ctrl->mmal_id,
  13584. + &u32_value, sizeof(u32_value));
  13585. +}
  13586. +
  13587. +static int ctrl_set_awb_mode(struct bm2835_mmal_dev *dev,
  13588. + struct v4l2_ctrl *ctrl,
  13589. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13590. +{
  13591. + u32 u32_value;
  13592. + struct vchiq_mmal_port *control;
  13593. +
  13594. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13595. +
  13596. + switch (ctrl->val) {
  13597. + case V4L2_WHITE_BALANCE_MANUAL:
  13598. + u32_value = MMAL_PARAM_AWBMODE_OFF;
  13599. + break;
  13600. +
  13601. + case V4L2_WHITE_BALANCE_AUTO:
  13602. + u32_value = MMAL_PARAM_AWBMODE_AUTO;
  13603. + break;
  13604. +
  13605. + case V4L2_WHITE_BALANCE_INCANDESCENT:
  13606. + u32_value = MMAL_PARAM_AWBMODE_INCANDESCENT;
  13607. + break;
  13608. +
  13609. + case V4L2_WHITE_BALANCE_FLUORESCENT:
  13610. + u32_value = MMAL_PARAM_AWBMODE_FLUORESCENT;
  13611. + break;
  13612. +
  13613. + case V4L2_WHITE_BALANCE_FLUORESCENT_H:
  13614. + u32_value = MMAL_PARAM_AWBMODE_TUNGSTEN;
  13615. + break;
  13616. +
  13617. + case V4L2_WHITE_BALANCE_HORIZON:
  13618. + u32_value = MMAL_PARAM_AWBMODE_HORIZON;
  13619. + break;
  13620. +
  13621. + case V4L2_WHITE_BALANCE_DAYLIGHT:
  13622. + u32_value = MMAL_PARAM_AWBMODE_SUNLIGHT;
  13623. + break;
  13624. +
  13625. + case V4L2_WHITE_BALANCE_FLASH:
  13626. + u32_value = MMAL_PARAM_AWBMODE_FLASH;
  13627. + break;
  13628. +
  13629. + case V4L2_WHITE_BALANCE_CLOUDY:
  13630. + u32_value = MMAL_PARAM_AWBMODE_CLOUDY;
  13631. + break;
  13632. +
  13633. + case V4L2_WHITE_BALANCE_SHADE:
  13634. + u32_value = MMAL_PARAM_AWBMODE_SHADE;
  13635. + break;
  13636. +
  13637. + }
  13638. +
  13639. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  13640. + mmal_ctrl->mmal_id,
  13641. + &u32_value, sizeof(u32_value));
  13642. +}
  13643. +
  13644. +static int ctrl_set_awb_gains(struct bm2835_mmal_dev *dev,
  13645. + struct v4l2_ctrl *ctrl,
  13646. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13647. +{
  13648. + struct vchiq_mmal_port *control;
  13649. + struct mmal_parameter_awbgains gains;
  13650. +
  13651. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13652. +
  13653. + if (ctrl->id == V4L2_CID_RED_BALANCE)
  13654. + dev->red_gain = ctrl->val;
  13655. + else if (ctrl->id == V4L2_CID_BLUE_BALANCE)
  13656. + dev->blue_gain = ctrl->val;
  13657. +
  13658. + gains.r_gain.num = dev->red_gain;
  13659. + gains.b_gain.num = dev->blue_gain;
  13660. + gains.r_gain.den = gains.b_gain.den = 1000;
  13661. +
  13662. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  13663. + mmal_ctrl->mmal_id,
  13664. + &gains, sizeof(gains));
  13665. +}
  13666. +
  13667. +static int ctrl_set_image_effect(struct bm2835_mmal_dev *dev,
  13668. + struct v4l2_ctrl *ctrl,
  13669. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13670. +{
  13671. + int ret = -EINVAL;
  13672. + int i, j;
  13673. + struct vchiq_mmal_port *control;
  13674. + struct mmal_parameter_imagefx_parameters imagefx;
  13675. +
  13676. + for (i = 0; i < ARRAY_SIZE(v4l2_to_mmal_effects_values); i++) {
  13677. + if (ctrl->val == v4l2_to_mmal_effects_values[i].v4l2_effect) {
  13678. +
  13679. + imagefx.effect =
  13680. + v4l2_to_mmal_effects_values[i].mmal_effect;
  13681. + imagefx.num_effect_params =
  13682. + v4l2_to_mmal_effects_values[i].num_effect_params;
  13683. +
  13684. + if (imagefx.num_effect_params > MMAL_MAX_IMAGEFX_PARAMETERS)
  13685. + imagefx.num_effect_params = MMAL_MAX_IMAGEFX_PARAMETERS;
  13686. +
  13687. + for (j = 0; j < imagefx.num_effect_params; j++)
  13688. + imagefx.effect_parameter[j] =
  13689. + v4l2_to_mmal_effects_values[i].effect_params[j];
  13690. +
  13691. + dev->colourfx.enable =
  13692. + v4l2_to_mmal_effects_values[i].col_fx_enable;
  13693. + if (!v4l2_to_mmal_effects_values[i].col_fx_fixed_cbcr) {
  13694. + dev->colourfx.u =
  13695. + v4l2_to_mmal_effects_values[i].u;
  13696. + dev->colourfx.v =
  13697. + v4l2_to_mmal_effects_values[i].v;
  13698. + }
  13699. +
  13700. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13701. +
  13702. + ret = vchiq_mmal_port_parameter_set(
  13703. + dev->instance, control,
  13704. + MMAL_PARAMETER_IMAGE_EFFECT_PARAMETERS,
  13705. + &imagefx, sizeof(imagefx));
  13706. + if (ret)
  13707. + goto exit;
  13708. +
  13709. + ret = vchiq_mmal_port_parameter_set(
  13710. + dev->instance, control,
  13711. + MMAL_PARAMETER_COLOUR_EFFECT,
  13712. + &dev->colourfx, sizeof(dev->colourfx));
  13713. + }
  13714. + }
  13715. +
  13716. +exit:
  13717. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  13718. + "mmal_ctrl:%p ctrl id:0x%x ctrl val:%d imagefx:0x%x color_effect:%s u:%d v:%d ret %d(%d)\n",
  13719. + mmal_ctrl, ctrl->id, ctrl->val, imagefx.effect,
  13720. + dev->colourfx.enable ? "true" : "false",
  13721. + dev->colourfx.u, dev->colourfx.v,
  13722. + ret, (ret == 0 ? 0 : -EINVAL));
  13723. + return (ret == 0 ? 0 : EINVAL);
  13724. +}
  13725. +
  13726. +static int ctrl_set_colfx(struct bm2835_mmal_dev *dev,
  13727. + struct v4l2_ctrl *ctrl,
  13728. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13729. +{
  13730. + int ret = -EINVAL;
  13731. + struct vchiq_mmal_port *control;
  13732. +
  13733. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13734. +
  13735. + dev->colourfx.enable = (ctrl->val & 0xff00) >> 8;
  13736. + dev->colourfx.enable = ctrl->val & 0xff;
  13737. +
  13738. + ret = vchiq_mmal_port_parameter_set(dev->instance, control,
  13739. + MMAL_PARAMETER_COLOUR_EFFECT,
  13740. + &dev->colourfx, sizeof(dev->colourfx));
  13741. +
  13742. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  13743. + "%s: After: mmal_ctrl:%p ctrl id:0x%x ctrl val:%d ret %d(%d)\n",
  13744. + __func__, mmal_ctrl, ctrl->id, ctrl->val, ret,
  13745. + (ret == 0 ? 0 : -EINVAL));
  13746. + return (ret == 0 ? 0 : EINVAL);
  13747. +}
  13748. +
  13749. +static int ctrl_set_bitrate(struct bm2835_mmal_dev *dev,
  13750. + struct v4l2_ctrl *ctrl,
  13751. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13752. +{
  13753. + int ret;
  13754. + struct vchiq_mmal_port *encoder_out;
  13755. +
  13756. + dev->capture.encode_bitrate = ctrl->val;
  13757. +
  13758. + encoder_out = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  13759. +
  13760. + ret = vchiq_mmal_port_parameter_set(dev->instance, encoder_out,
  13761. + mmal_ctrl->mmal_id,
  13762. + &ctrl->val, sizeof(ctrl->val));
  13763. + ret = 0;
  13764. + return ret;
  13765. +}
  13766. +
  13767. +static int ctrl_set_bitrate_mode(struct bm2835_mmal_dev *dev,
  13768. + struct v4l2_ctrl *ctrl,
  13769. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13770. +{
  13771. + u32 bitrate_mode;
  13772. + struct vchiq_mmal_port *encoder_out;
  13773. +
  13774. + encoder_out = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  13775. +
  13776. + dev->capture.encode_bitrate_mode = ctrl->val;
  13777. + switch (ctrl->val) {
  13778. + default:
  13779. + case V4L2_MPEG_VIDEO_BITRATE_MODE_VBR:
  13780. + bitrate_mode = MMAL_VIDEO_RATECONTROL_VARIABLE;
  13781. + break;
  13782. + case V4L2_MPEG_VIDEO_BITRATE_MODE_CBR:
  13783. + bitrate_mode = MMAL_VIDEO_RATECONTROL_CONSTANT;
  13784. + break;
  13785. + }
  13786. +
  13787. + vchiq_mmal_port_parameter_set(dev->instance, encoder_out,
  13788. + mmal_ctrl->mmal_id,
  13789. + &bitrate_mode,
  13790. + sizeof(bitrate_mode));
  13791. + return 0;
  13792. +}
  13793. +
  13794. +static int ctrl_set_image_encode_output(struct bm2835_mmal_dev *dev,
  13795. + struct v4l2_ctrl *ctrl,
  13796. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13797. +{
  13798. + u32 u32_value;
  13799. + struct vchiq_mmal_port *jpeg_out;
  13800. +
  13801. + jpeg_out = &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->output[0];
  13802. +
  13803. + u32_value = ctrl->val;
  13804. +
  13805. + return vchiq_mmal_port_parameter_set(dev->instance, jpeg_out,
  13806. + mmal_ctrl->mmal_id,
  13807. + &u32_value, sizeof(u32_value));
  13808. +}
  13809. +
  13810. +static int ctrl_set_video_encode_param_output(struct bm2835_mmal_dev *dev,
  13811. + struct v4l2_ctrl *ctrl,
  13812. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13813. +{
  13814. + u32 u32_value;
  13815. + struct vchiq_mmal_port *vid_enc_ctl;
  13816. +
  13817. + vid_enc_ctl = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  13818. +
  13819. + u32_value = ctrl->val;
  13820. +
  13821. + return vchiq_mmal_port_parameter_set(dev->instance, vid_enc_ctl,
  13822. + mmal_ctrl->mmal_id,
  13823. + &u32_value, sizeof(u32_value));
  13824. +}
  13825. +
  13826. +static int ctrl_set_video_encode_profile_level(struct bm2835_mmal_dev *dev,
  13827. + struct v4l2_ctrl *ctrl,
  13828. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13829. +{
  13830. + struct mmal_parameter_video_profile param;
  13831. + int ret = 0;
  13832. +
  13833. + if (ctrl->id == V4L2_CID_MPEG_VIDEO_H264_PROFILE) {
  13834. + switch (ctrl->val) {
  13835. + case V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE:
  13836. + case V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE:
  13837. + case V4L2_MPEG_VIDEO_H264_PROFILE_MAIN:
  13838. + case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH:
  13839. + dev->capture.enc_profile = ctrl->val;
  13840. + break;
  13841. + default:
  13842. + ret = -EINVAL;
  13843. + break;
  13844. + }
  13845. + } else if (ctrl->id == V4L2_CID_MPEG_VIDEO_H264_LEVEL) {
  13846. + switch (ctrl->val) {
  13847. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_0:
  13848. + case V4L2_MPEG_VIDEO_H264_LEVEL_1B:
  13849. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_1:
  13850. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_2:
  13851. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_3:
  13852. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_0:
  13853. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_1:
  13854. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_2:
  13855. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_0:
  13856. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_1:
  13857. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_2:
  13858. + case V4L2_MPEG_VIDEO_H264_LEVEL_4_0:
  13859. + dev->capture.enc_level = ctrl->val;
  13860. + break;
  13861. + default:
  13862. + ret = -EINVAL;
  13863. + break;
  13864. + }
  13865. + }
  13866. +
  13867. + if (!ret) {
  13868. + switch (dev->capture.enc_profile) {
  13869. + case V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE:
  13870. + param.profile = MMAL_VIDEO_PROFILE_H264_BASELINE;
  13871. + break;
  13872. + case V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE:
  13873. + param.profile =
  13874. + MMAL_VIDEO_PROFILE_H264_CONSTRAINED_BASELINE;
  13875. + break;
  13876. + case V4L2_MPEG_VIDEO_H264_PROFILE_MAIN:
  13877. + param.profile = MMAL_VIDEO_PROFILE_H264_MAIN;
  13878. + break;
  13879. + case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH:
  13880. + param.profile = MMAL_VIDEO_PROFILE_H264_HIGH;
  13881. + break;
  13882. + default:
  13883. + /* Should never get here */
  13884. + break;
  13885. + }
  13886. +
  13887. + switch (dev->capture.enc_level) {
  13888. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_0:
  13889. + param.level = MMAL_VIDEO_LEVEL_H264_1;
  13890. + break;
  13891. + case V4L2_MPEG_VIDEO_H264_LEVEL_1B:
  13892. + param.level = MMAL_VIDEO_LEVEL_H264_1b;
  13893. + break;
  13894. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_1:
  13895. + param.level = MMAL_VIDEO_LEVEL_H264_11;
  13896. + break;
  13897. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_2:
  13898. + param.level = MMAL_VIDEO_LEVEL_H264_12;
  13899. + break;
  13900. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_3:
  13901. + param.level = MMAL_VIDEO_LEVEL_H264_13;
  13902. + break;
  13903. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_0:
  13904. + param.level = MMAL_VIDEO_LEVEL_H264_2;
  13905. + break;
  13906. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_1:
  13907. + param.level = MMAL_VIDEO_LEVEL_H264_21;
  13908. + break;
  13909. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_2:
  13910. + param.level = MMAL_VIDEO_LEVEL_H264_22;
  13911. + break;
  13912. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_0:
  13913. + param.level = MMAL_VIDEO_LEVEL_H264_3;
  13914. + break;
  13915. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_1:
  13916. + param.level = MMAL_VIDEO_LEVEL_H264_31;
  13917. + break;
  13918. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_2:
  13919. + param.level = MMAL_VIDEO_LEVEL_H264_32;
  13920. + break;
  13921. + case V4L2_MPEG_VIDEO_H264_LEVEL_4_0:
  13922. + param.level = MMAL_VIDEO_LEVEL_H264_4;
  13923. + break;
  13924. + default:
  13925. + /* Should never get here */
  13926. + break;
  13927. + }
  13928. +
  13929. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  13930. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0],
  13931. + mmal_ctrl->mmal_id,
  13932. + &param, sizeof(param));
  13933. + }
  13934. + return ret;
  13935. +}
  13936. +
  13937. +static int ctrl_set_scene_mode(struct bm2835_mmal_dev *dev,
  13938. + struct v4l2_ctrl *ctrl,
  13939. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13940. +{
  13941. + int ret = 0;
  13942. + int shutter_speed;
  13943. + struct vchiq_mmal_port *control;
  13944. +
  13945. + v4l2_dbg(0, bcm2835_v4l2_debug, &dev->v4l2_dev,
  13946. + "scene mode selected %d, was %d\n", ctrl->val,
  13947. + dev->scene_mode);
  13948. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13949. +
  13950. + if (ctrl->val == dev->scene_mode)
  13951. + return 0;
  13952. +
  13953. + if (ctrl->val == V4L2_SCENE_MODE_NONE) {
  13954. + /* Restore all user selections */
  13955. + dev->scene_mode = V4L2_SCENE_MODE_NONE;
  13956. +
  13957. + if (dev->exposure_mode_user == MMAL_PARAM_EXPOSUREMODE_OFF)
  13958. + shutter_speed = dev->manual_shutter_speed;
  13959. + else
  13960. + shutter_speed = 0;
  13961. +
  13962. + v4l2_dbg(0, bcm2835_v4l2_debug, &dev->v4l2_dev,
  13963. + "%s: scene mode none: shut_speed %d, exp_mode %d, metering %d\n",
  13964. + __func__, shutter_speed, dev->exposure_mode_user,
  13965. + dev->metering_mode);
  13966. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  13967. + control,
  13968. + MMAL_PARAMETER_SHUTTER_SPEED,
  13969. + &shutter_speed,
  13970. + sizeof(shutter_speed));
  13971. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  13972. + control,
  13973. + MMAL_PARAMETER_EXPOSURE_MODE,
  13974. + &dev->exposure_mode_user,
  13975. + sizeof(u32));
  13976. + dev->exposure_mode_active = dev->exposure_mode_user;
  13977. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  13978. + control,
  13979. + MMAL_PARAMETER_EXP_METERING_MODE,
  13980. + &dev->metering_mode,
  13981. + sizeof(u32));
  13982. + ret += set_framerate_params(dev);
  13983. + } else {
  13984. + /* Set up scene mode */
  13985. + int i;
  13986. + const struct v4l2_mmal_scene_config *scene = NULL;
  13987. + int shutter_speed;
  13988. + enum mmal_parameter_exposuremode exposure_mode;
  13989. + enum mmal_parameter_exposuremeteringmode metering_mode;
  13990. +
  13991. + for (i = 0; i < ARRAY_SIZE(scene_configs); i++) {
  13992. + if (scene_configs[i].v4l2_scene ==
  13993. + ctrl->val) {
  13994. + scene = &scene_configs[i];
  13995. + break;
  13996. + }
  13997. + }
  13998. + if (i >= ARRAY_SIZE(scene_configs))
  13999. + return -EINVAL;
  14000. +
  14001. + /* Set all the values */
  14002. + dev->scene_mode = ctrl->val;
  14003. +
  14004. + if (scene->exposure_mode == MMAL_PARAM_EXPOSUREMODE_OFF)
  14005. + shutter_speed = dev->manual_shutter_speed;
  14006. + else
  14007. + shutter_speed = 0;
  14008. + exposure_mode = scene->exposure_mode;
  14009. + metering_mode = scene->metering_mode;
  14010. +
  14011. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  14012. + "%s: scene mode none: shut_speed %d, exp_mode %d, metering %d\n",
  14013. + __func__, shutter_speed, exposure_mode, metering_mode);
  14014. +
  14015. + ret = vchiq_mmal_port_parameter_set(dev->instance, control,
  14016. + MMAL_PARAMETER_SHUTTER_SPEED,
  14017. + &shutter_speed,
  14018. + sizeof(shutter_speed));
  14019. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  14020. + control,
  14021. + MMAL_PARAMETER_EXPOSURE_MODE,
  14022. + &exposure_mode,
  14023. + sizeof(u32));
  14024. + dev->exposure_mode_active = exposure_mode;
  14025. + ret += vchiq_mmal_port_parameter_set(dev->instance, control,
  14026. + MMAL_PARAMETER_EXPOSURE_MODE,
  14027. + &exposure_mode,
  14028. + sizeof(u32));
  14029. + ret += vchiq_mmal_port_parameter_set(dev->instance, control,
  14030. + MMAL_PARAMETER_EXP_METERING_MODE,
  14031. + &metering_mode,
  14032. + sizeof(u32));
  14033. + ret += set_framerate_params(dev);
  14034. + }
  14035. + if (ret) {
  14036. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  14037. + "%s: Setting scene to %d, ret=%d\n",
  14038. + __func__, ctrl->val, ret);
  14039. + ret = -EINVAL;
  14040. + }
  14041. + return 0;
  14042. +}
  14043. +
  14044. +static int bm2835_mmal_s_ctrl(struct v4l2_ctrl *ctrl)
  14045. +{
  14046. + struct bm2835_mmal_dev *dev =
  14047. + container_of(ctrl->handler, struct bm2835_mmal_dev,
  14048. + ctrl_handler);
  14049. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl = ctrl->priv;
  14050. + int ret;
  14051. +
  14052. + if ((mmal_ctrl == NULL) ||
  14053. + (mmal_ctrl->id != ctrl->id) ||
  14054. + (mmal_ctrl->setter == NULL)) {
  14055. + pr_warn("mmal_ctrl:%p ctrl id:%d\n", mmal_ctrl, ctrl->id);
  14056. + return -EINVAL;
  14057. + }
  14058. +
  14059. + ret = mmal_ctrl->setter(dev, ctrl, mmal_ctrl);
  14060. + if (ret)
  14061. + pr_warn("ctrl id:%d/MMAL param %08X- returned ret %d\n",
  14062. + ctrl->id, mmal_ctrl->mmal_id, ret);
  14063. + if (mmal_ctrl->ignore_errors)
  14064. + ret = 0;
  14065. + return ret;
  14066. +}
  14067. +
  14068. +static const struct v4l2_ctrl_ops bm2835_mmal_ctrl_ops = {
  14069. + .s_ctrl = bm2835_mmal_s_ctrl,
  14070. +};
  14071. +
  14072. +
  14073. +
  14074. +static const struct bm2835_mmal_v4l2_ctrl v4l2_ctrls[V4L2_CTRL_COUNT] = {
  14075. + {
  14076. + V4L2_CID_SATURATION, MMAL_CONTROL_TYPE_STD,
  14077. + -100, 100, 0, 1, NULL,
  14078. + MMAL_PARAMETER_SATURATION,
  14079. + &ctrl_set_rational,
  14080. + false
  14081. + },
  14082. + {
  14083. + V4L2_CID_SHARPNESS, MMAL_CONTROL_TYPE_STD,
  14084. + -100, 100, 0, 1, NULL,
  14085. + MMAL_PARAMETER_SHARPNESS,
  14086. + &ctrl_set_rational,
  14087. + false
  14088. + },
  14089. + {
  14090. + V4L2_CID_CONTRAST, MMAL_CONTROL_TYPE_STD,
  14091. + -100, 100, 0, 1, NULL,
  14092. + MMAL_PARAMETER_CONTRAST,
  14093. + &ctrl_set_rational,
  14094. + false
  14095. + },
  14096. + {
  14097. + V4L2_CID_BRIGHTNESS, MMAL_CONTROL_TYPE_STD,
  14098. + 0, 100, 50, 1, NULL,
  14099. + MMAL_PARAMETER_BRIGHTNESS,
  14100. + &ctrl_set_rational,
  14101. + false
  14102. + },
  14103. + {
  14104. + V4L2_CID_ISO_SENSITIVITY, MMAL_CONTROL_TYPE_INT_MENU,
  14105. + 0, ARRAY_SIZE(iso_qmenu) - 1, 0, 1, iso_qmenu,
  14106. + MMAL_PARAMETER_ISO,
  14107. + &ctrl_set_value_menu,
  14108. + false
  14109. + },
  14110. + {
  14111. + V4L2_CID_IMAGE_STABILIZATION, MMAL_CONTROL_TYPE_STD,
  14112. + 0, 1, 0, 1, NULL,
  14113. + MMAL_PARAMETER_VIDEO_STABILISATION,
  14114. + &ctrl_set_value,
  14115. + false
  14116. + },
  14117. +/* {
  14118. + 0, MMAL_CONTROL_TYPE_CLUSTER, 3, 1, 0, NULL, 0, NULL
  14119. + },
  14120. +*/ {
  14121. + V4L2_CID_EXPOSURE_AUTO, MMAL_CONTROL_TYPE_STD_MENU,
  14122. + ~0x03, 3, V4L2_EXPOSURE_AUTO, 0, NULL,
  14123. + MMAL_PARAMETER_EXPOSURE_MODE,
  14124. + &ctrl_set_exposure,
  14125. + false
  14126. + },
  14127. +/* todo this needs mixing in with set exposure
  14128. + {
  14129. + V4L2_CID_SCENE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
  14130. + },
  14131. + */
  14132. + {
  14133. + V4L2_CID_EXPOSURE_ABSOLUTE, MMAL_CONTROL_TYPE_STD,
  14134. + /* Units of 100usecs */
  14135. + 1, 1*1000*10, 100*10, 1, NULL,
  14136. + MMAL_PARAMETER_SHUTTER_SPEED,
  14137. + &ctrl_set_exposure,
  14138. + false
  14139. + },
  14140. + {
  14141. + V4L2_CID_AUTO_EXPOSURE_BIAS, MMAL_CONTROL_TYPE_INT_MENU,
  14142. + 0, ARRAY_SIZE(ev_bias_qmenu) - 1,
  14143. + (ARRAY_SIZE(ev_bias_qmenu)+1)/2 - 1, 0, ev_bias_qmenu,
  14144. + MMAL_PARAMETER_EXPOSURE_COMP,
  14145. + &ctrl_set_value_ev,
  14146. + false
  14147. + },
  14148. + {
  14149. + V4L2_CID_EXPOSURE_AUTO_PRIORITY, MMAL_CONTROL_TYPE_STD,
  14150. + 0, 1,
  14151. + 0, 1, NULL,
  14152. + 0, /* Dummy MMAL ID as it gets mapped into FPS range*/
  14153. + &ctrl_set_exposure,
  14154. + false
  14155. + },
  14156. + {
  14157. + V4L2_CID_EXPOSURE_METERING,
  14158. + MMAL_CONTROL_TYPE_STD_MENU,
  14159. + ~0x7, 2, V4L2_EXPOSURE_METERING_AVERAGE, 0, NULL,
  14160. + MMAL_PARAMETER_EXP_METERING_MODE,
  14161. + &ctrl_set_metering_mode,
  14162. + false
  14163. + },
  14164. + {
  14165. + V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE,
  14166. + MMAL_CONTROL_TYPE_STD_MENU,
  14167. + ~0x3ff, 9, V4L2_WHITE_BALANCE_AUTO, 0, NULL,
  14168. + MMAL_PARAMETER_AWB_MODE,
  14169. + &ctrl_set_awb_mode,
  14170. + false
  14171. + },
  14172. + {
  14173. + V4L2_CID_RED_BALANCE, MMAL_CONTROL_TYPE_STD,
  14174. + 1, 7999, 1000, 1, NULL,
  14175. + MMAL_PARAMETER_CUSTOM_AWB_GAINS,
  14176. + &ctrl_set_awb_gains,
  14177. + false
  14178. + },
  14179. + {
  14180. + V4L2_CID_BLUE_BALANCE, MMAL_CONTROL_TYPE_STD,
  14181. + 1, 7999, 1000, 1, NULL,
  14182. + MMAL_PARAMETER_CUSTOM_AWB_GAINS,
  14183. + &ctrl_set_awb_gains,
  14184. + false
  14185. + },
  14186. + {
  14187. + V4L2_CID_COLORFX, MMAL_CONTROL_TYPE_STD_MENU,
  14188. + 0, 15, V4L2_COLORFX_NONE, 0, NULL,
  14189. + MMAL_PARAMETER_IMAGE_EFFECT,
  14190. + &ctrl_set_image_effect,
  14191. + false
  14192. + },
  14193. + {
  14194. + V4L2_CID_COLORFX_CBCR, MMAL_CONTROL_TYPE_STD,
  14195. + 0, 0xffff, 0x8080, 1, NULL,
  14196. + MMAL_PARAMETER_COLOUR_EFFECT,
  14197. + &ctrl_set_colfx,
  14198. + false
  14199. + },
  14200. + {
  14201. + V4L2_CID_ROTATE, MMAL_CONTROL_TYPE_STD,
  14202. + 0, 360, 0, 90, NULL,
  14203. + MMAL_PARAMETER_ROTATION,
  14204. + &ctrl_set_rotate,
  14205. + false
  14206. + },
  14207. + {
  14208. + V4L2_CID_HFLIP, MMAL_CONTROL_TYPE_STD,
  14209. + 0, 1, 0, 1, NULL,
  14210. + MMAL_PARAMETER_MIRROR,
  14211. + &ctrl_set_flip,
  14212. + false
  14213. + },
  14214. + {
  14215. + V4L2_CID_VFLIP, MMAL_CONTROL_TYPE_STD,
  14216. + 0, 1, 0, 1, NULL,
  14217. + MMAL_PARAMETER_MIRROR,
  14218. + &ctrl_set_flip,
  14219. + false
  14220. + },
  14221. + {
  14222. + V4L2_CID_MPEG_VIDEO_BITRATE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
  14223. + 0, ARRAY_SIZE(bitrate_mode_qmenu) - 1,
  14224. + 0, 0, bitrate_mode_qmenu,
  14225. + MMAL_PARAMETER_RATECONTROL,
  14226. + &ctrl_set_bitrate_mode,
  14227. + false
  14228. + },
  14229. + {
  14230. + V4L2_CID_MPEG_VIDEO_BITRATE, MMAL_CONTROL_TYPE_STD,
  14231. + 25*1000, 25*1000*1000, 10*1000*1000, 25*1000, NULL,
  14232. + MMAL_PARAMETER_VIDEO_BIT_RATE,
  14233. + &ctrl_set_bitrate,
  14234. + false
  14235. + },
  14236. + {
  14237. + V4L2_CID_JPEG_COMPRESSION_QUALITY, MMAL_CONTROL_TYPE_STD,
  14238. + 1, 100,
  14239. + 30, 1, NULL,
  14240. + MMAL_PARAMETER_JPEG_Q_FACTOR,
  14241. + &ctrl_set_image_encode_output,
  14242. + false
  14243. + },
  14244. + {
  14245. + V4L2_CID_POWER_LINE_FREQUENCY, MMAL_CONTROL_TYPE_STD_MENU,
  14246. + 0, ARRAY_SIZE(mains_freq_qmenu) - 1,
  14247. + 1, 1, NULL,
  14248. + MMAL_PARAMETER_FLICKER_AVOID,
  14249. + &ctrl_set_flicker_avoidance,
  14250. + false
  14251. + },
  14252. + {
  14253. + V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER, MMAL_CONTROL_TYPE_STD,
  14254. + 0, 1,
  14255. + 0, 1, NULL,
  14256. + MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER,
  14257. + &ctrl_set_video_encode_param_output,
  14258. + true /* Errors ignored as requires latest firmware to work */
  14259. + },
  14260. + {
  14261. + V4L2_CID_MPEG_VIDEO_H264_PROFILE,
  14262. + MMAL_CONTROL_TYPE_STD_MENU,
  14263. + ~((1<<V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE) |
  14264. + (1<<V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE) |
  14265. + (1<<V4L2_MPEG_VIDEO_H264_PROFILE_MAIN) |
  14266. + (1<<V4L2_MPEG_VIDEO_H264_PROFILE_HIGH)),
  14267. + V4L2_MPEG_VIDEO_H264_PROFILE_HIGH,
  14268. + V4L2_MPEG_VIDEO_H264_PROFILE_HIGH, 1, NULL,
  14269. + MMAL_PARAMETER_PROFILE,
  14270. + &ctrl_set_video_encode_profile_level,
  14271. + false
  14272. + },
  14273. + {
  14274. + V4L2_CID_MPEG_VIDEO_H264_LEVEL, MMAL_CONTROL_TYPE_STD_MENU,
  14275. + ~((1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_0) |
  14276. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1B) |
  14277. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_1) |
  14278. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_2) |
  14279. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_3) |
  14280. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_2_0) |
  14281. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_2_1) |
  14282. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_2_2) |
  14283. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_3_0) |
  14284. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_3_1) |
  14285. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_3_2) |
  14286. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_4_0)),
  14287. + V4L2_MPEG_VIDEO_H264_LEVEL_4_0,
  14288. + V4L2_MPEG_VIDEO_H264_LEVEL_4_0, 1, NULL,
  14289. + MMAL_PARAMETER_PROFILE,
  14290. + &ctrl_set_video_encode_profile_level,
  14291. + false
  14292. + },
  14293. + {
  14294. + V4L2_CID_SCENE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
  14295. + -1, /* Min is computed at runtime */
  14296. + V4L2_SCENE_MODE_TEXT,
  14297. + V4L2_SCENE_MODE_NONE, 1, NULL,
  14298. + MMAL_PARAMETER_PROFILE,
  14299. + &ctrl_set_scene_mode,
  14300. + false
  14301. + },
  14302. +};
  14303. +
  14304. +int bm2835_mmal_set_all_camera_controls(struct bm2835_mmal_dev *dev)
  14305. +{
  14306. + int c;
  14307. + int ret = 0;
  14308. +
  14309. + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
  14310. + if ((dev->ctrls[c]) && (v4l2_ctrls[c].setter)) {
  14311. + ret = v4l2_ctrls[c].setter(dev, dev->ctrls[c],
  14312. + &v4l2_ctrls[c]);
  14313. + if (!v4l2_ctrls[c].ignore_errors && ret) {
  14314. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  14315. + "Failed when setting default values for ctrl %d\n",
  14316. + c);
  14317. + break;
  14318. + }
  14319. + }
  14320. + }
  14321. + return ret;
  14322. +}
  14323. +
  14324. +int set_framerate_params(struct bm2835_mmal_dev *dev)
  14325. +{
  14326. + struct mmal_parameter_fps_range fps_range;
  14327. + int ret;
  14328. +
  14329. + if ((dev->exposure_mode_active != MMAL_PARAM_EXPOSUREMODE_OFF) &&
  14330. + (dev->exp_auto_priority)) {
  14331. + /* Variable FPS. Define min FPS as 1fps.
  14332. + * Max as max defined FPS.
  14333. + */
  14334. + fps_range.fps_low.num = 1;
  14335. + fps_range.fps_low.den = 1;
  14336. + fps_range.fps_high.num = dev->capture.timeperframe.denominator;
  14337. + fps_range.fps_high.den = dev->capture.timeperframe.numerator;
  14338. + } else {
  14339. + /* Fixed FPS - set min and max to be the same */
  14340. + fps_range.fps_low.num = fps_range.fps_high.num =
  14341. + dev->capture.timeperframe.denominator;
  14342. + fps_range.fps_low.den = fps_range.fps_high.den =
  14343. + dev->capture.timeperframe.numerator;
  14344. + }
  14345. +
  14346. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  14347. + "Set fps range to %d/%d to %d/%d\n",
  14348. + fps_range.fps_low.num,
  14349. + fps_range.fps_low.den,
  14350. + fps_range.fps_high.num,
  14351. + fps_range.fps_high.den
  14352. + );
  14353. +
  14354. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  14355. + &dev->component[MMAL_COMPONENT_CAMERA]->
  14356. + output[MMAL_CAMERA_PORT_PREVIEW],
  14357. + MMAL_PARAMETER_FPS_RANGE,
  14358. + &fps_range, sizeof(fps_range));
  14359. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  14360. + &dev->component[MMAL_COMPONENT_CAMERA]->
  14361. + output[MMAL_CAMERA_PORT_VIDEO],
  14362. + MMAL_PARAMETER_FPS_RANGE,
  14363. + &fps_range, sizeof(fps_range));
  14364. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  14365. + &dev->component[MMAL_COMPONENT_CAMERA]->
  14366. + output[MMAL_CAMERA_PORT_CAPTURE],
  14367. + MMAL_PARAMETER_FPS_RANGE,
  14368. + &fps_range, sizeof(fps_range));
  14369. + if (ret)
  14370. + v4l2_dbg(0, bcm2835_v4l2_debug, &dev->v4l2_dev,
  14371. + "Failed to set fps ret %d\n",
  14372. + ret);
  14373. +
  14374. + return ret;
  14375. +
  14376. +}
  14377. +
  14378. +int bm2835_mmal_init_controls(struct bm2835_mmal_dev *dev,
  14379. + struct v4l2_ctrl_handler *hdl)
  14380. +{
  14381. + int c;
  14382. + const struct bm2835_mmal_v4l2_ctrl *ctrl;
  14383. +
  14384. + v4l2_ctrl_handler_init(hdl, V4L2_CTRL_COUNT);
  14385. +
  14386. + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
  14387. + ctrl = &v4l2_ctrls[c];
  14388. +
  14389. + switch (ctrl->type) {
  14390. + case MMAL_CONTROL_TYPE_STD:
  14391. + dev->ctrls[c] = v4l2_ctrl_new_std(hdl,
  14392. + &bm2835_mmal_ctrl_ops, ctrl->id,
  14393. + ctrl->min, ctrl->max, ctrl->step, ctrl->def);
  14394. + break;
  14395. +
  14396. + case MMAL_CONTROL_TYPE_STD_MENU:
  14397. + {
  14398. + int mask = ctrl->min;
  14399. +
  14400. + if (ctrl->id == V4L2_CID_SCENE_MODE) {
  14401. + /* Special handling to work out the mask
  14402. + * value based on the scene_configs array
  14403. + * at runtime. Reduces the chance of
  14404. + * mismatches.
  14405. + */
  14406. + int i;
  14407. + mask = 1<<V4L2_SCENE_MODE_NONE;
  14408. + for (i = 0;
  14409. + i < ARRAY_SIZE(scene_configs);
  14410. + i++) {
  14411. + mask |= 1<<scene_configs[i].v4l2_scene;
  14412. + }
  14413. + mask = ~mask;
  14414. + }
  14415. +
  14416. + dev->ctrls[c] = v4l2_ctrl_new_std_menu(hdl,
  14417. + &bm2835_mmal_ctrl_ops, ctrl->id,
  14418. + ctrl->max, mask, ctrl->def);
  14419. + break;
  14420. + }
  14421. +
  14422. + case MMAL_CONTROL_TYPE_INT_MENU:
  14423. + dev->ctrls[c] = v4l2_ctrl_new_int_menu(hdl,
  14424. + &bm2835_mmal_ctrl_ops, ctrl->id,
  14425. + ctrl->max, ctrl->def, ctrl->imenu);
  14426. + break;
  14427. +
  14428. + case MMAL_CONTROL_TYPE_CLUSTER:
  14429. + /* skip this entry when constructing controls */
  14430. + continue;
  14431. + }
  14432. +
  14433. + if (hdl->error)
  14434. + break;
  14435. +
  14436. + dev->ctrls[c]->priv = (void *)ctrl;
  14437. + }
  14438. +
  14439. + if (hdl->error) {
  14440. + pr_err("error adding control %d/%d id 0x%x\n", c,
  14441. + V4L2_CTRL_COUNT, ctrl->id);
  14442. + return hdl->error;
  14443. + }
  14444. +
  14445. + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
  14446. + ctrl = &v4l2_ctrls[c];
  14447. +
  14448. + switch (ctrl->type) {
  14449. + case MMAL_CONTROL_TYPE_CLUSTER:
  14450. + v4l2_ctrl_auto_cluster(ctrl->min,
  14451. + &dev->ctrls[c+1],
  14452. + ctrl->max,
  14453. + ctrl->def);
  14454. + break;
  14455. +
  14456. + case MMAL_CONTROL_TYPE_STD:
  14457. + case MMAL_CONTROL_TYPE_STD_MENU:
  14458. + case MMAL_CONTROL_TYPE_INT_MENU:
  14459. + break;
  14460. + }
  14461. +
  14462. + }
  14463. +
  14464. + return 0;
  14465. +}
  14466. diff -Nur linux-3.12.26.orig/drivers/media/platform/bcm2835/Kconfig linux-3.12.26/drivers/media/platform/bcm2835/Kconfig
  14467. --- linux-3.12.26.orig/drivers/media/platform/bcm2835/Kconfig 1970-01-01 01:00:00.000000000 +0100
  14468. +++ linux-3.12.26/drivers/media/platform/bcm2835/Kconfig 2014-08-06 16:50:14.353961208 +0200
  14469. @@ -0,0 +1,25 @@
  14470. +# Broadcom VideoCore IV v4l2 camera support
  14471. +
  14472. +config VIDEO_BCM2835
  14473. + bool "Broadcom BCM2835 camera interface driver"
  14474. + depends on VIDEO_V4L2 && ARCH_BCM2708
  14475. + ---help---
  14476. + Say Y here to enable camera host interface devices for
  14477. + Broadcom BCM2835 SoC. This operates over the VCHIQ interface
  14478. + to a service running on VideoCore.
  14479. +
  14480. +
  14481. +if VIDEO_BCM2835
  14482. +
  14483. +config VIDEO_BCM2835_MMAL
  14484. + tristate "Broadcom BM2835 MMAL camera interface driver"
  14485. + depends on BCM2708_VCHIQ
  14486. + select VIDEOBUF2_VMALLOC
  14487. + ---help---
  14488. + This is a V4L2 driver for the Broadcom BCM2835 MMAL camera host interface
  14489. +
  14490. + To compile this driver as a module, choose M here: the
  14491. + module will be called bcm2835-v4l2.o
  14492. +
  14493. +
  14494. +endif # VIDEO_BM2835
  14495. diff -Nur linux-3.12.26.orig/drivers/media/platform/bcm2835/Makefile linux-3.12.26/drivers/media/platform/bcm2835/Makefile
  14496. --- linux-3.12.26.orig/drivers/media/platform/bcm2835/Makefile 1970-01-01 01:00:00.000000000 +0100
  14497. +++ linux-3.12.26/drivers/media/platform/bcm2835/Makefile 2014-08-06 16:50:14.353961208 +0200
  14498. @@ -0,0 +1,5 @@
  14499. +bcm2835-v4l2-objs := bcm2835-camera.o controls.o mmal-vchiq.o
  14500. +
  14501. +obj-$(CONFIG_VIDEO_BCM2835_MMAL) += bcm2835-v4l2.o
  14502. +
  14503. +ccflags-$(CONFIG_VIDEO_BCM2835) += -Idrivers/misc/vc04_services -Idrivers/misc/vc04_services/interface/vcos/linuxkernel -D__VCCOREVER__=0x04000000
  14504. diff -Nur linux-3.12.26.orig/drivers/media/platform/bcm2835/mmal-common.h linux-3.12.26/drivers/media/platform/bcm2835/mmal-common.h
  14505. --- linux-3.12.26.orig/drivers/media/platform/bcm2835/mmal-common.h 1970-01-01 01:00:00.000000000 +0100
  14506. +++ linux-3.12.26/drivers/media/platform/bcm2835/mmal-common.h 2014-08-06 16:50:14.353961208 +0200
  14507. @@ -0,0 +1,53 @@
  14508. +/*
  14509. + * Broadcom BM2835 V4L2 driver
  14510. + *
  14511. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  14512. + *
  14513. + * This file is subject to the terms and conditions of the GNU General Public
  14514. + * License. See the file COPYING in the main directory of this archive
  14515. + * for more details.
  14516. + *
  14517. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  14518. + * Dave Stevenson <dsteve@broadcom.com>
  14519. + * Simon Mellor <simellor@broadcom.com>
  14520. + * Luke Diamand <luked@broadcom.com>
  14521. + *
  14522. + * MMAL structures
  14523. + *
  14524. + */
  14525. +
  14526. +#define MMAL_FOURCC(a, b, c, d) ((a) | (b << 8) | (c << 16) | (d << 24))
  14527. +#define MMAL_MAGIC MMAL_FOURCC('m', 'm', 'a', 'l')
  14528. +
  14529. +/** Special value signalling that time is not known */
  14530. +#define MMAL_TIME_UNKNOWN (1LL<<63)
  14531. +
  14532. +/* mapping between v4l and mmal video modes */
  14533. +struct mmal_fmt {
  14534. + char *name;
  14535. + u32 fourcc; /* v4l2 format id */
  14536. + int flags; /* v4l2 flags field */
  14537. + u32 mmal;
  14538. + int depth;
  14539. + u32 mmal_component; /* MMAL component index to be used to encode */
  14540. +};
  14541. +
  14542. +/* buffer for one video frame */
  14543. +struct mmal_buffer {
  14544. + /* v4l buffer data -- must be first */
  14545. + struct vb2_buffer vb;
  14546. +
  14547. + /* list of buffers available */
  14548. + struct list_head list;
  14549. +
  14550. + void *buffer; /* buffer pointer */
  14551. + unsigned long buffer_size; /* size of allocated buffer */
  14552. +};
  14553. +
  14554. +/* */
  14555. +struct mmal_colourfx {
  14556. + s32 enable;
  14557. + u32 u;
  14558. + u32 v;
  14559. +};
  14560. +
  14561. diff -Nur linux-3.12.26.orig/drivers/media/platform/bcm2835/mmal-encodings.h linux-3.12.26/drivers/media/platform/bcm2835/mmal-encodings.h
  14562. --- linux-3.12.26.orig/drivers/media/platform/bcm2835/mmal-encodings.h 1970-01-01 01:00:00.000000000 +0100
  14563. +++ linux-3.12.26/drivers/media/platform/bcm2835/mmal-encodings.h 2014-08-06 16:50:14.353961208 +0200
  14564. @@ -0,0 +1,94 @@
  14565. +/*
  14566. + * Broadcom BM2835 V4L2 driver
  14567. + *
  14568. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  14569. + *
  14570. + * This file is subject to the terms and conditions of the GNU General Public
  14571. + * License. See the file COPYING in the main directory of this archive
  14572. + * for more details.
  14573. + *
  14574. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  14575. + * Dave Stevenson <dsteve@broadcom.com>
  14576. + * Simon Mellor <simellor@broadcom.com>
  14577. + * Luke Diamand <luked@broadcom.com>
  14578. + */
  14579. +
  14580. +#define MMAL_ENCODING_H264 MMAL_FOURCC('H', '2', '6', '4')
  14581. +#define MMAL_ENCODING_H263 MMAL_FOURCC('H', '2', '6', '3')
  14582. +#define MMAL_ENCODING_MP4V MMAL_FOURCC('M', 'P', '4', 'V')
  14583. +#define MMAL_ENCODING_MP2V MMAL_FOURCC('M', 'P', '2', 'V')
  14584. +#define MMAL_ENCODING_MP1V MMAL_FOURCC('M', 'P', '1', 'V')
  14585. +#define MMAL_ENCODING_WMV3 MMAL_FOURCC('W', 'M', 'V', '3')
  14586. +#define MMAL_ENCODING_WMV2 MMAL_FOURCC('W', 'M', 'V', '2')
  14587. +#define MMAL_ENCODING_WMV1 MMAL_FOURCC('W', 'M', 'V', '1')
  14588. +#define MMAL_ENCODING_WVC1 MMAL_FOURCC('W', 'V', 'C', '1')
  14589. +#define MMAL_ENCODING_VP8 MMAL_FOURCC('V', 'P', '8', ' ')
  14590. +#define MMAL_ENCODING_VP7 MMAL_FOURCC('V', 'P', '7', ' ')
  14591. +#define MMAL_ENCODING_VP6 MMAL_FOURCC('V', 'P', '6', ' ')
  14592. +#define MMAL_ENCODING_THEORA MMAL_FOURCC('T', 'H', 'E', 'O')
  14593. +#define MMAL_ENCODING_SPARK MMAL_FOURCC('S', 'P', 'R', 'K')
  14594. +#define MMAL_ENCODING_MJPEG MMAL_FOURCC('M', 'J', 'P', 'G')
  14595. +
  14596. +#define MMAL_ENCODING_JPEG MMAL_FOURCC('J', 'P', 'E', 'G')
  14597. +#define MMAL_ENCODING_GIF MMAL_FOURCC('G', 'I', 'F', ' ')
  14598. +#define MMAL_ENCODING_PNG MMAL_FOURCC('P', 'N', 'G', ' ')
  14599. +#define MMAL_ENCODING_PPM MMAL_FOURCC('P', 'P', 'M', ' ')
  14600. +#define MMAL_ENCODING_TGA MMAL_FOURCC('T', 'G', 'A', ' ')
  14601. +#define MMAL_ENCODING_BMP MMAL_FOURCC('B', 'M', 'P', ' ')
  14602. +
  14603. +#define MMAL_ENCODING_I420 MMAL_FOURCC('I', '4', '2', '0')
  14604. +#define MMAL_ENCODING_I420_SLICE MMAL_FOURCC('S', '4', '2', '0')
  14605. +#define MMAL_ENCODING_YV12 MMAL_FOURCC('Y', 'V', '1', '2')
  14606. +#define MMAL_ENCODING_I422 MMAL_FOURCC('I', '4', '2', '2')
  14607. +#define MMAL_ENCODING_I422_SLICE MMAL_FOURCC('S', '4', '2', '2')
  14608. +#define MMAL_ENCODING_YUYV MMAL_FOURCC('Y', 'U', 'Y', 'V')
  14609. +#define MMAL_ENCODING_YVYU MMAL_FOURCC('Y', 'V', 'Y', 'U')
  14610. +#define MMAL_ENCODING_UYVY MMAL_FOURCC('U', 'Y', 'V', 'Y')
  14611. +#define MMAL_ENCODING_VYUY MMAL_FOURCC('V', 'Y', 'U', 'Y')
  14612. +#define MMAL_ENCODING_NV12 MMAL_FOURCC('N', 'V', '1', '2')
  14613. +#define MMAL_ENCODING_NV21 MMAL_FOURCC('N', 'V', '2', '1')
  14614. +#define MMAL_ENCODING_ARGB MMAL_FOURCC('A', 'R', 'G', 'B')
  14615. +#define MMAL_ENCODING_RGBA MMAL_FOURCC('R', 'G', 'B', 'A')
  14616. +#define MMAL_ENCODING_ABGR MMAL_FOURCC('A', 'B', 'G', 'R')
  14617. +#define MMAL_ENCODING_BGRA MMAL_FOURCC('B', 'G', 'R', 'A')
  14618. +#define MMAL_ENCODING_RGB16 MMAL_FOURCC('R', 'G', 'B', '2')
  14619. +#define MMAL_ENCODING_RGB24 MMAL_FOURCC('R', 'G', 'B', '3')
  14620. +#define MMAL_ENCODING_RGB32 MMAL_FOURCC('R', 'G', 'B', '4')
  14621. +#define MMAL_ENCODING_BGR16 MMAL_FOURCC('B', 'G', 'R', '2')
  14622. +#define MMAL_ENCODING_BGR24 MMAL_FOURCC('B', 'G', 'R', '3')
  14623. +#define MMAL_ENCODING_BGR32 MMAL_FOURCC('B', 'G', 'R', '4')
  14624. +
  14625. +/** SAND Video (YUVUV128) format, native format understood by VideoCore.
  14626. + * This format is *not* opaque - if requested you will receive full frames
  14627. + * of YUV_UV video.
  14628. + */
  14629. +#define MMAL_ENCODING_YUVUV128 MMAL_FOURCC('S', 'A', 'N', 'D')
  14630. +
  14631. +/** VideoCore opaque image format, image handles are returned to
  14632. + * the host but not the actual image data.
  14633. + */
  14634. +#define MMAL_ENCODING_OPAQUE MMAL_FOURCC('O', 'P', 'Q', 'V')
  14635. +
  14636. +/** An EGL image handle
  14637. + */
  14638. +#define MMAL_ENCODING_EGL_IMAGE MMAL_FOURCC('E', 'G', 'L', 'I')
  14639. +
  14640. +/* }@ */
  14641. +
  14642. +/** \name Pre-defined audio encodings */
  14643. +/* @{ */
  14644. +#define MMAL_ENCODING_PCM_UNSIGNED_BE MMAL_FOURCC('P', 'C', 'M', 'U')
  14645. +#define MMAL_ENCODING_PCM_UNSIGNED_LE MMAL_FOURCC('p', 'c', 'm', 'u')
  14646. +#define MMAL_ENCODING_PCM_SIGNED_BE MMAL_FOURCC('P', 'C', 'M', 'S')
  14647. +#define MMAL_ENCODING_PCM_SIGNED_LE MMAL_FOURCC('p', 'c', 'm', 's')
  14648. +#define MMAL_ENCODING_PCM_FLOAT_BE MMAL_FOURCC('P', 'C', 'M', 'F')
  14649. +#define MMAL_ENCODING_PCM_FLOAT_LE MMAL_FOURCC('p', 'c', 'm', 'f')
  14650. +
  14651. +/* Pre-defined H264 encoding variants */
  14652. +
  14653. +/** ISO 14496-10 Annex B byte stream format */
  14654. +#define MMAL_ENCODING_VARIANT_H264_DEFAULT 0
  14655. +/** ISO 14496-15 AVC stream format */
  14656. +#define MMAL_ENCODING_VARIANT_H264_AVC1 MMAL_FOURCC('A', 'V', 'C', '1')
  14657. +/** Implicitly delineated NAL units without emulation prevention */
  14658. +#define MMAL_ENCODING_VARIANT_H264_RAW MMAL_FOURCC('R', 'A', 'W', ' ')
  14659. diff -Nur linux-3.12.26.orig/drivers/media/platform/bcm2835/mmal-msg-common.h linux-3.12.26/drivers/media/platform/bcm2835/mmal-msg-common.h
  14660. --- linux-3.12.26.orig/drivers/media/platform/bcm2835/mmal-msg-common.h 1970-01-01 01:00:00.000000000 +0100
  14661. +++ linux-3.12.26/drivers/media/platform/bcm2835/mmal-msg-common.h 2014-08-06 16:50:14.389961491 +0200
  14662. @@ -0,0 +1,50 @@
  14663. +/*
  14664. + * Broadcom BM2835 V4L2 driver
  14665. + *
  14666. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  14667. + *
  14668. + * This file is subject to the terms and conditions of the GNU General Public
  14669. + * License. See the file COPYING in the main directory of this archive
  14670. + * for more details.
  14671. + *
  14672. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  14673. + * Dave Stevenson <dsteve@broadcom.com>
  14674. + * Simon Mellor <simellor@broadcom.com>
  14675. + * Luke Diamand <luked@broadcom.com>
  14676. + */
  14677. +
  14678. +#ifndef MMAL_MSG_COMMON_H
  14679. +#define MMAL_MSG_COMMON_H
  14680. +
  14681. +enum mmal_msg_status {
  14682. + MMAL_MSG_STATUS_SUCCESS = 0, /**< Success */
  14683. + MMAL_MSG_STATUS_ENOMEM, /**< Out of memory */
  14684. + MMAL_MSG_STATUS_ENOSPC, /**< Out of resources other than memory */
  14685. + MMAL_MSG_STATUS_EINVAL, /**< Argument is invalid */
  14686. + MMAL_MSG_STATUS_ENOSYS, /**< Function not implemented */
  14687. + MMAL_MSG_STATUS_ENOENT, /**< No such file or directory */
  14688. + MMAL_MSG_STATUS_ENXIO, /**< No such device or address */
  14689. + MMAL_MSG_STATUS_EIO, /**< I/O error */
  14690. + MMAL_MSG_STATUS_ESPIPE, /**< Illegal seek */
  14691. + MMAL_MSG_STATUS_ECORRUPT, /**< Data is corrupt \attention */
  14692. + MMAL_MSG_STATUS_ENOTREADY, /**< Component is not ready */
  14693. + MMAL_MSG_STATUS_ECONFIG, /**< Component is not configured */
  14694. + MMAL_MSG_STATUS_EISCONN, /**< Port is already connected */
  14695. + MMAL_MSG_STATUS_ENOTCONN, /**< Port is disconnected */
  14696. + MMAL_MSG_STATUS_EAGAIN, /**< Resource temporarily unavailable. */
  14697. + MMAL_MSG_STATUS_EFAULT, /**< Bad address */
  14698. +};
  14699. +
  14700. +struct mmal_rect {
  14701. + s32 x; /**< x coordinate (from left) */
  14702. + s32 y; /**< y coordinate (from top) */
  14703. + s32 width; /**< width */
  14704. + s32 height; /**< height */
  14705. +};
  14706. +
  14707. +struct mmal_rational {
  14708. + s32 num; /**< Numerator */
  14709. + s32 den; /**< Denominator */
  14710. +};
  14711. +
  14712. +#endif /* MMAL_MSG_COMMON_H */
  14713. diff -Nur linux-3.12.26.orig/drivers/media/platform/bcm2835/mmal-msg-format.h linux-3.12.26/drivers/media/platform/bcm2835/mmal-msg-format.h
  14714. --- linux-3.12.26.orig/drivers/media/platform/bcm2835/mmal-msg-format.h 1970-01-01 01:00:00.000000000 +0100
  14715. +++ linux-3.12.26/drivers/media/platform/bcm2835/mmal-msg-format.h 2014-08-06 16:50:14.393961522 +0200
  14716. @@ -0,0 +1,81 @@
  14717. +/*
  14718. + * Broadcom BM2835 V4L2 driver
  14719. + *
  14720. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  14721. + *
  14722. + * This file is subject to the terms and conditions of the GNU General Public
  14723. + * License. See the file COPYING in the main directory of this archive
  14724. + * for more details.
  14725. + *
  14726. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  14727. + * Dave Stevenson <dsteve@broadcom.com>
  14728. + * Simon Mellor <simellor@broadcom.com>
  14729. + * Luke Diamand <luked@broadcom.com>
  14730. + */
  14731. +
  14732. +#ifndef MMAL_MSG_FORMAT_H
  14733. +#define MMAL_MSG_FORMAT_H
  14734. +
  14735. +#include "mmal-msg-common.h"
  14736. +
  14737. +/* MMAL_ES_FORMAT_T */
  14738. +
  14739. +
  14740. +struct mmal_audio_format {
  14741. + u32 channels; /**< Number of audio channels */
  14742. + u32 sample_rate; /**< Sample rate */
  14743. +
  14744. + u32 bits_per_sample; /**< Bits per sample */
  14745. + u32 block_align; /**< Size of a block of data */
  14746. +};
  14747. +
  14748. +struct mmal_video_format {
  14749. + u32 width; /**< Width of frame in pixels */
  14750. + u32 height; /**< Height of frame in rows of pixels */
  14751. + struct mmal_rect crop; /**< Visible region of the frame */
  14752. + struct mmal_rational frame_rate; /**< Frame rate */
  14753. + struct mmal_rational par; /**< Pixel aspect ratio */
  14754. +
  14755. + /* FourCC specifying the color space of the video stream. See the
  14756. + * \ref MmalColorSpace "pre-defined color spaces" for some examples.
  14757. + */
  14758. + u32 color_space;
  14759. +};
  14760. +
  14761. +struct mmal_subpicture_format {
  14762. + u32 x_offset;
  14763. + u32 y_offset;
  14764. +};
  14765. +
  14766. +union mmal_es_specific_format {
  14767. + struct mmal_audio_format audio;
  14768. + struct mmal_video_format video;
  14769. + struct mmal_subpicture_format subpicture;
  14770. +};
  14771. +
  14772. +/** Definition of an elementary stream format (MMAL_ES_FORMAT_T) */
  14773. +struct mmal_es_format {
  14774. + u32 type; /* enum mmal_es_type */
  14775. +
  14776. + u32 encoding; /* FourCC specifying encoding of the elementary stream.*/
  14777. + u32 encoding_variant; /* FourCC specifying the specific
  14778. + * encoding variant of the elementary
  14779. + * stream.
  14780. + */
  14781. +
  14782. + union mmal_es_specific_format *es; /* TODO: pointers in
  14783. + * message serialisation?!?
  14784. + */
  14785. + /* Type specific
  14786. + * information for the
  14787. + * elementary stream
  14788. + */
  14789. +
  14790. + u32 bitrate; /**< Bitrate in bits per second */
  14791. + u32 flags; /**< Flags describing properties of the elementary stream. */
  14792. +
  14793. + u32 extradata_size; /**< Size of the codec specific data */
  14794. + u8 *extradata; /**< Codec specific data */
  14795. +};
  14796. +
  14797. +#endif /* MMAL_MSG_FORMAT_H */
  14798. diff -Nur linux-3.12.26.orig/drivers/media/platform/bcm2835/mmal-msg.h linux-3.12.26/drivers/media/platform/bcm2835/mmal-msg.h
  14799. --- linux-3.12.26.orig/drivers/media/platform/bcm2835/mmal-msg.h 1970-01-01 01:00:00.000000000 +0100
  14800. +++ linux-3.12.26/drivers/media/platform/bcm2835/mmal-msg.h 2014-08-06 16:50:14.393961522 +0200
  14801. @@ -0,0 +1,404 @@
  14802. +/*
  14803. + * Broadcom BM2835 V4L2 driver
  14804. + *
  14805. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  14806. + *
  14807. + * This file is subject to the terms and conditions of the GNU General Public
  14808. + * License. See the file COPYING in the main directory of this archive
  14809. + * for more details.
  14810. + *
  14811. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  14812. + * Dave Stevenson <dsteve@broadcom.com>
  14813. + * Simon Mellor <simellor@broadcom.com>
  14814. + * Luke Diamand <luked@broadcom.com>
  14815. + */
  14816. +
  14817. +/* all the data structures which serialise the MMAL protocol. note
  14818. + * these are directly mapped onto the recived message data.
  14819. + *
  14820. + * BEWARE: They seem to *assume* pointers are u32 and that there is no
  14821. + * structure padding!
  14822. + *
  14823. + * NOTE: this implementation uses kernel types to ensure sizes. Rather
  14824. + * than assigning values to enums to force their size the
  14825. + * implementation uses fixed size types and not the enums (though the
  14826. + * comments have the actual enum type
  14827. + */
  14828. +
  14829. +#define VC_MMAL_VER 15
  14830. +#define VC_MMAL_MIN_VER 10
  14831. +#define VC_MMAL_SERVER_NAME MAKE_FOURCC("mmal")
  14832. +
  14833. +/* max total message size is 512 bytes */
  14834. +#define MMAL_MSG_MAX_SIZE 512
  14835. +/* with six 32bit header elements max payload is therefore 488 bytes */
  14836. +#define MMAL_MSG_MAX_PAYLOAD 488
  14837. +
  14838. +#include "mmal-msg-common.h"
  14839. +#include "mmal-msg-format.h"
  14840. +#include "mmal-msg-port.h"
  14841. +
  14842. +enum mmal_msg_type {
  14843. + MMAL_MSG_TYPE_QUIT = 1,
  14844. + MMAL_MSG_TYPE_SERVICE_CLOSED,
  14845. + MMAL_MSG_TYPE_GET_VERSION,
  14846. + MMAL_MSG_TYPE_COMPONENT_CREATE,
  14847. + MMAL_MSG_TYPE_COMPONENT_DESTROY, /* 5 */
  14848. + MMAL_MSG_TYPE_COMPONENT_ENABLE,
  14849. + MMAL_MSG_TYPE_COMPONENT_DISABLE,
  14850. + MMAL_MSG_TYPE_PORT_INFO_GET,
  14851. + MMAL_MSG_TYPE_PORT_INFO_SET,
  14852. + MMAL_MSG_TYPE_PORT_ACTION, /* 10 */
  14853. + MMAL_MSG_TYPE_BUFFER_FROM_HOST,
  14854. + MMAL_MSG_TYPE_BUFFER_TO_HOST,
  14855. + MMAL_MSG_TYPE_GET_STATS,
  14856. + MMAL_MSG_TYPE_PORT_PARAMETER_SET,
  14857. + MMAL_MSG_TYPE_PORT_PARAMETER_GET, /* 15 */
  14858. + MMAL_MSG_TYPE_EVENT_TO_HOST,
  14859. + MMAL_MSG_TYPE_GET_CORE_STATS_FOR_PORT,
  14860. + MMAL_MSG_TYPE_OPAQUE_ALLOCATOR,
  14861. + MMAL_MSG_TYPE_CONSUME_MEM,
  14862. + MMAL_MSG_TYPE_LMK, /* 20 */
  14863. + MMAL_MSG_TYPE_OPAQUE_ALLOCATOR_DESC,
  14864. + MMAL_MSG_TYPE_DRM_GET_LHS32,
  14865. + MMAL_MSG_TYPE_DRM_GET_TIME,
  14866. + MMAL_MSG_TYPE_BUFFER_FROM_HOST_ZEROLEN,
  14867. + MMAL_MSG_TYPE_PORT_FLUSH, /* 25 */
  14868. + MMAL_MSG_TYPE_HOST_LOG,
  14869. + MMAL_MSG_TYPE_MSG_LAST
  14870. +};
  14871. +
  14872. +/* port action request messages differ depending on the action type */
  14873. +enum mmal_msg_port_action_type {
  14874. + MMAL_MSG_PORT_ACTION_TYPE_UNKNOWN = 0, /* Unkown action */
  14875. + MMAL_MSG_PORT_ACTION_TYPE_ENABLE, /* Enable a port */
  14876. + MMAL_MSG_PORT_ACTION_TYPE_DISABLE, /* Disable a port */
  14877. + MMAL_MSG_PORT_ACTION_TYPE_FLUSH, /* Flush a port */
  14878. + MMAL_MSG_PORT_ACTION_TYPE_CONNECT, /* Connect ports */
  14879. + MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT, /* Disconnect ports */
  14880. + MMAL_MSG_PORT_ACTION_TYPE_SET_REQUIREMENTS, /* Set buffer requirements*/
  14881. +};
  14882. +
  14883. +struct mmal_msg_header {
  14884. + u32 magic;
  14885. + u32 type; /** enum mmal_msg_type */
  14886. +
  14887. + /* Opaque handle to the control service */
  14888. + struct mmal_control_service *control_service;
  14889. +
  14890. + struct mmal_msg_context *context; /** a u32 per message context */
  14891. + u32 status; /** The status of the vchiq operation */
  14892. + u32 padding;
  14893. +};
  14894. +
  14895. +/* Send from VC to host to report version */
  14896. +struct mmal_msg_version {
  14897. + u32 flags;
  14898. + u32 major;
  14899. + u32 minor;
  14900. + u32 minimum;
  14901. +};
  14902. +
  14903. +/* request to VC to create component */
  14904. +struct mmal_msg_component_create {
  14905. + void *client_component; /* component context */
  14906. + char name[128];
  14907. + u32 pid; /* For debug */
  14908. +};
  14909. +
  14910. +/* reply from VC to component creation request */
  14911. +struct mmal_msg_component_create_reply {
  14912. + u32 status; /** enum mmal_msg_status - how does this differ to
  14913. + * the one in the header?
  14914. + */
  14915. + u32 component_handle; /* VideoCore handle for component */
  14916. + u32 input_num; /* Number of input ports */
  14917. + u32 output_num; /* Number of output ports */
  14918. + u32 clock_num; /* Number of clock ports */
  14919. +};
  14920. +
  14921. +/* request to VC to destroy a component */
  14922. +struct mmal_msg_component_destroy {
  14923. + u32 component_handle;
  14924. +};
  14925. +
  14926. +struct mmal_msg_component_destroy_reply {
  14927. + u32 status; /** The component destruction status */
  14928. +};
  14929. +
  14930. +
  14931. +/* request and reply to VC to enable a component */
  14932. +struct mmal_msg_component_enable {
  14933. + u32 component_handle;
  14934. +};
  14935. +
  14936. +struct mmal_msg_component_enable_reply {
  14937. + u32 status; /** The component enable status */
  14938. +};
  14939. +
  14940. +
  14941. +/* request and reply to VC to disable a component */
  14942. +struct mmal_msg_component_disable {
  14943. + u32 component_handle;
  14944. +};
  14945. +
  14946. +struct mmal_msg_component_disable_reply {
  14947. + u32 status; /** The component disable status */
  14948. +};
  14949. +
  14950. +/* request to VC to get port information */
  14951. +struct mmal_msg_port_info_get {
  14952. + u32 component_handle; /* component handle port is associated with */
  14953. + u32 port_type; /* enum mmal_msg_port_type */
  14954. + u32 index; /* port index to query */
  14955. +};
  14956. +
  14957. +/* reply from VC to get port info request */
  14958. +struct mmal_msg_port_info_get_reply {
  14959. + u32 status; /** enum mmal_msg_status */
  14960. + u32 component_handle; /* component handle port is associated with */
  14961. + u32 port_type; /* enum mmal_msg_port_type */
  14962. + u32 port_index; /* port indexed in query */
  14963. + s32 found; /* unused */
  14964. + u32 port_handle; /**< Handle to use for this port */
  14965. + struct mmal_port port;
  14966. + struct mmal_es_format format; /* elementry stream format */
  14967. + union mmal_es_specific_format es; /* es type specific data */
  14968. + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE]; /* es extra data */
  14969. +};
  14970. +
  14971. +/* request to VC to set port information */
  14972. +struct mmal_msg_port_info_set {
  14973. + u32 component_handle;
  14974. + u32 port_type; /* enum mmal_msg_port_type */
  14975. + u32 port_index; /* port indexed in query */
  14976. + struct mmal_port port;
  14977. + struct mmal_es_format format;
  14978. + union mmal_es_specific_format es;
  14979. + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
  14980. +};
  14981. +
  14982. +/* reply from VC to port info set request */
  14983. +struct mmal_msg_port_info_set_reply {
  14984. + u32 status;
  14985. + u32 component_handle; /* component handle port is associated with */
  14986. + u32 port_type; /* enum mmal_msg_port_type */
  14987. + u32 index; /* port indexed in query */
  14988. + s32 found; /* unused */
  14989. + u32 port_handle; /**< Handle to use for this port */
  14990. + struct mmal_port port;
  14991. + struct mmal_es_format format;
  14992. + union mmal_es_specific_format es;
  14993. + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
  14994. +};
  14995. +
  14996. +
  14997. +/* port action requests that take a mmal_port as a parameter */
  14998. +struct mmal_msg_port_action_port {
  14999. + u32 component_handle;
  15000. + u32 port_handle;
  15001. + u32 action; /* enum mmal_msg_port_action_type */
  15002. + struct mmal_port port;
  15003. +};
  15004. +
  15005. +/* port action requests that take handles as a parameter */
  15006. +struct mmal_msg_port_action_handle {
  15007. + u32 component_handle;
  15008. + u32 port_handle;
  15009. + u32 action; /* enum mmal_msg_port_action_type */
  15010. + u32 connect_component_handle;
  15011. + u32 connect_port_handle;
  15012. +};
  15013. +
  15014. +struct mmal_msg_port_action_reply {
  15015. + u32 status; /** The port action operation status */
  15016. +};
  15017. +
  15018. +
  15019. +
  15020. +
  15021. +/* MMAL buffer transfer */
  15022. +
  15023. +/** Size of space reserved in a buffer message for short messages. */
  15024. +#define MMAL_VC_SHORT_DATA 128
  15025. +
  15026. +/** Signals that the current payload is the end of the stream of data */
  15027. +#define MMAL_BUFFER_HEADER_FLAG_EOS (1<<0)
  15028. +/** Signals that the start of the current payload starts a frame */
  15029. +#define MMAL_BUFFER_HEADER_FLAG_FRAME_START (1<<1)
  15030. +/** Signals that the end of the current payload ends a frame */
  15031. +#define MMAL_BUFFER_HEADER_FLAG_FRAME_END (1<<2)
  15032. +/** Signals that the current payload contains only complete frames (>1) */
  15033. +#define MMAL_BUFFER_HEADER_FLAG_FRAME \
  15034. + (MMAL_BUFFER_HEADER_FLAG_FRAME_START|MMAL_BUFFER_HEADER_FLAG_FRAME_END)
  15035. +/** Signals that the current payload is a keyframe (i.e. self decodable) */
  15036. +#define MMAL_BUFFER_HEADER_FLAG_KEYFRAME (1<<3)
  15037. +/** Signals a discontinuity in the stream of data (e.g. after a seek).
  15038. + * Can be used for instance by a decoder to reset its state */
  15039. +#define MMAL_BUFFER_HEADER_FLAG_DISCONTINUITY (1<<4)
  15040. +/** Signals a buffer containing some kind of config data for the component
  15041. + * (e.g. codec config data) */
  15042. +#define MMAL_BUFFER_HEADER_FLAG_CONFIG (1<<5)
  15043. +/** Signals an encrypted payload */
  15044. +#define MMAL_BUFFER_HEADER_FLAG_ENCRYPTED (1<<6)
  15045. +/** Signals a buffer containing side information */
  15046. +#define MMAL_BUFFER_HEADER_FLAG_CODECSIDEINFO (1<<7)
  15047. +/** Signals a buffer which is the snapshot/postview image from a stills
  15048. + * capture
  15049. + */
  15050. +#define MMAL_BUFFER_HEADER_FLAGS_SNAPSHOT (1<<8)
  15051. +/** Signals a buffer which contains data known to be corrupted */
  15052. +#define MMAL_BUFFER_HEADER_FLAG_CORRUPTED (1<<9)
  15053. +/** Signals that a buffer failed to be transmitted */
  15054. +#define MMAL_BUFFER_HEADER_FLAG_TRANSMISSION_FAILED (1<<10)
  15055. +
  15056. +struct mmal_driver_buffer {
  15057. + u32 magic;
  15058. + u32 component_handle;
  15059. + u32 port_handle;
  15060. + void *client_context;
  15061. +};
  15062. +
  15063. +/* buffer header */
  15064. +struct mmal_buffer_header {
  15065. + struct mmal_buffer_header *next; /* next header */
  15066. + void *priv; /* framework private data */
  15067. + u32 cmd;
  15068. + void *data;
  15069. + u32 alloc_size;
  15070. + u32 length;
  15071. + u32 offset;
  15072. + u32 flags;
  15073. + s64 pts;
  15074. + s64 dts;
  15075. + void *type;
  15076. + void *user_data;
  15077. +};
  15078. +
  15079. +struct mmal_buffer_header_type_specific {
  15080. + union {
  15081. + struct {
  15082. + u32 planes;
  15083. + u32 offset[4];
  15084. + u32 pitch[4];
  15085. + u32 flags;
  15086. + } video;
  15087. + } u;
  15088. +};
  15089. +
  15090. +struct mmal_msg_buffer_from_host {
  15091. + /* The front 32 bytes of the buffer header are copied
  15092. + * back to us in the reply to allow for context. This
  15093. + * area is used to store two mmal_driver_buffer structures to
  15094. + * allow for multiple concurrent service users.
  15095. + */
  15096. + /* control data */
  15097. + struct mmal_driver_buffer drvbuf;
  15098. +
  15099. + /* referenced control data for passthrough buffer management */
  15100. + struct mmal_driver_buffer drvbuf_ref;
  15101. + struct mmal_buffer_header buffer_header; /* buffer header itself */
  15102. + struct mmal_buffer_header_type_specific buffer_header_type_specific;
  15103. + s32 is_zero_copy;
  15104. + s32 has_reference;
  15105. +
  15106. + /** allows short data to be xfered in control message */
  15107. + u32 payload_in_message;
  15108. + u8 short_data[MMAL_VC_SHORT_DATA];
  15109. +};
  15110. +
  15111. +
  15112. +/* port parameter setting */
  15113. +
  15114. +#define MMAL_WORKER_PORT_PARAMETER_SPACE 96
  15115. +
  15116. +struct mmal_msg_port_parameter_set {
  15117. + u32 component_handle; /* component */
  15118. + u32 port_handle; /* port */
  15119. + u32 id; /* Parameter ID */
  15120. + u32 size; /* Parameter size */
  15121. + uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
  15122. +};
  15123. +
  15124. +struct mmal_msg_port_parameter_set_reply {
  15125. + u32 status; /** enum mmal_msg_status todo: how does this
  15126. + * differ to the one in the header?
  15127. + */
  15128. +};
  15129. +
  15130. +/* port parameter getting */
  15131. +
  15132. +struct mmal_msg_port_parameter_get {
  15133. + u32 component_handle; /* component */
  15134. + u32 port_handle; /* port */
  15135. + u32 id; /* Parameter ID */
  15136. + u32 size; /* Parameter size */
  15137. +};
  15138. +
  15139. +struct mmal_msg_port_parameter_get_reply {
  15140. + u32 status; /* Status of mmal_port_parameter_get call */
  15141. + u32 id; /* Parameter ID */
  15142. + u32 size; /* Parameter size */
  15143. + uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
  15144. +};
  15145. +
  15146. +/* event messages */
  15147. +#define MMAL_WORKER_EVENT_SPACE 256
  15148. +
  15149. +struct mmal_msg_event_to_host {
  15150. + void *client_component; /* component context */
  15151. +
  15152. + u32 port_type;
  15153. + u32 port_num;
  15154. +
  15155. + u32 cmd;
  15156. + u32 length;
  15157. + u8 data[MMAL_WORKER_EVENT_SPACE];
  15158. + struct mmal_buffer_header *delayed_buffer;
  15159. +};
  15160. +
  15161. +/* all mmal messages are serialised through this structure */
  15162. +struct mmal_msg {
  15163. + /* header */
  15164. + struct mmal_msg_header h;
  15165. + /* payload */
  15166. + union {
  15167. + struct mmal_msg_version version;
  15168. +
  15169. + struct mmal_msg_component_create component_create;
  15170. + struct mmal_msg_component_create_reply component_create_reply;
  15171. +
  15172. + struct mmal_msg_component_destroy component_destroy;
  15173. + struct mmal_msg_component_destroy_reply component_destroy_reply;
  15174. +
  15175. + struct mmal_msg_component_enable component_enable;
  15176. + struct mmal_msg_component_enable_reply component_enable_reply;
  15177. +
  15178. + struct mmal_msg_component_disable component_disable;
  15179. + struct mmal_msg_component_disable_reply component_disable_reply;
  15180. +
  15181. + struct mmal_msg_port_info_get port_info_get;
  15182. + struct mmal_msg_port_info_get_reply port_info_get_reply;
  15183. +
  15184. + struct mmal_msg_port_info_set port_info_set;
  15185. + struct mmal_msg_port_info_set_reply port_info_set_reply;
  15186. +
  15187. + struct mmal_msg_port_action_port port_action_port;
  15188. + struct mmal_msg_port_action_handle port_action_handle;
  15189. + struct mmal_msg_port_action_reply port_action_reply;
  15190. +
  15191. + struct mmal_msg_buffer_from_host buffer_from_host;
  15192. +
  15193. + struct mmal_msg_port_parameter_set port_parameter_set;
  15194. + struct mmal_msg_port_parameter_set_reply
  15195. + port_parameter_set_reply;
  15196. + struct mmal_msg_port_parameter_get
  15197. + port_parameter_get;
  15198. + struct mmal_msg_port_parameter_get_reply
  15199. + port_parameter_get_reply;
  15200. +
  15201. + struct mmal_msg_event_to_host event_to_host;
  15202. +
  15203. + u8 payload[MMAL_MSG_MAX_PAYLOAD];
  15204. + } u;
  15205. +};
  15206. diff -Nur linux-3.12.26.orig/drivers/media/platform/bcm2835/mmal-msg-port.h linux-3.12.26/drivers/media/platform/bcm2835/mmal-msg-port.h
  15207. --- linux-3.12.26.orig/drivers/media/platform/bcm2835/mmal-msg-port.h 1970-01-01 01:00:00.000000000 +0100
  15208. +++ linux-3.12.26/drivers/media/platform/bcm2835/mmal-msg-port.h 2014-08-06 16:50:14.393961522 +0200
  15209. @@ -0,0 +1,107 @@
  15210. +/*
  15211. + * Broadcom BM2835 V4L2 driver
  15212. + *
  15213. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  15214. + *
  15215. + * This file is subject to the terms and conditions of the GNU General Public
  15216. + * License. See the file COPYING in the main directory of this archive
  15217. + * for more details.
  15218. + *
  15219. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  15220. + * Dave Stevenson <dsteve@broadcom.com>
  15221. + * Simon Mellor <simellor@broadcom.com>
  15222. + * Luke Diamand <luked@broadcom.com>
  15223. + */
  15224. +
  15225. +/* MMAL_PORT_TYPE_T */
  15226. +enum mmal_port_type {
  15227. + MMAL_PORT_TYPE_UNKNOWN = 0, /**< Unknown port type */
  15228. + MMAL_PORT_TYPE_CONTROL, /**< Control port */
  15229. + MMAL_PORT_TYPE_INPUT, /**< Input port */
  15230. + MMAL_PORT_TYPE_OUTPUT, /**< Output port */
  15231. + MMAL_PORT_TYPE_CLOCK, /**< Clock port */
  15232. +};
  15233. +
  15234. +/** The port is pass-through and doesn't need buffer headers allocated */
  15235. +#define MMAL_PORT_CAPABILITY_PASSTHROUGH 0x01
  15236. +/** The port wants to allocate the buffer payloads.
  15237. + * This signals a preference that payload allocation should be done
  15238. + * on this port for efficiency reasons. */
  15239. +#define MMAL_PORT_CAPABILITY_ALLOCATION 0x02
  15240. +/** The port supports format change events.
  15241. + * This applies to input ports and is used to let the client know
  15242. + * whether the port supports being reconfigured via a format
  15243. + * change event (i.e. without having to disable the port). */
  15244. +#define MMAL_PORT_CAPABILITY_SUPPORTS_EVENT_FORMAT_CHANGE 0x04
  15245. +
  15246. +/* mmal port structure (MMAL_PORT_T)
  15247. + *
  15248. + * most elements are informational only, the pointer values for
  15249. + * interogation messages are generally provided as additional
  15250. + * strucures within the message. When used to set values only teh
  15251. + * buffer_num, buffer_size and userdata parameters are writable.
  15252. + */
  15253. +struct mmal_port {
  15254. + void *priv; /* Private member used by the framework */
  15255. + const char *name; /* Port name. Used for debugging purposes (RO) */
  15256. +
  15257. + u32 type; /* Type of the port (RO) enum mmal_port_type */
  15258. + u16 index; /* Index of the port in its type list (RO) */
  15259. + u16 index_all; /* Index of the port in the list of all ports (RO) */
  15260. +
  15261. + u32 is_enabled; /* Indicates whether the port is enabled or not (RO) */
  15262. + struct mmal_es_format *format; /* Format of the elementary stream */
  15263. +
  15264. + u32 buffer_num_min; /* Minimum number of buffers the port
  15265. + * requires (RO). This is set by the
  15266. + * component.
  15267. + */
  15268. +
  15269. + u32 buffer_size_min; /* Minimum size of buffers the port
  15270. + * requires (RO). This is set by the
  15271. + * component.
  15272. + */
  15273. +
  15274. + u32 buffer_alignment_min; /* Minimum alignment requirement for
  15275. + * the buffers (RO). A value of
  15276. + * zero means no special alignment
  15277. + * requirements. This is set by the
  15278. + * component.
  15279. + */
  15280. +
  15281. + u32 buffer_num_recommended; /* Number of buffers the port
  15282. + * recommends for optimal
  15283. + * performance (RO). A value of
  15284. + * zero means no special
  15285. + * recommendation. This is set
  15286. + * by the component.
  15287. + */
  15288. +
  15289. + u32 buffer_size_recommended; /* Size of buffers the port
  15290. + * recommends for optimal
  15291. + * performance (RO). A value of
  15292. + * zero means no special
  15293. + * recommendation. This is set
  15294. + * by the component.
  15295. + */
  15296. +
  15297. + u32 buffer_num; /* Actual number of buffers the port will use.
  15298. + * This is set by the client.
  15299. + */
  15300. +
  15301. + u32 buffer_size; /* Actual maximum size of the buffers that
  15302. + * will be sent to the port. This is set by
  15303. + * the client.
  15304. + */
  15305. +
  15306. + void *component; /* Component this port belongs to (Read Only) */
  15307. +
  15308. + void *userdata; /* Field reserved for use by the client */
  15309. +
  15310. + u32 capabilities; /* Flags describing the capabilities of a
  15311. + * port (RO). Bitwise combination of \ref
  15312. + * portcapabilities "Port capabilities"
  15313. + * values.
  15314. + */
  15315. +
  15316. +};
  15317. diff -Nur linux-3.12.26.orig/drivers/media/platform/bcm2835/mmal-parameters.h linux-3.12.26/drivers/media/platform/bcm2835/mmal-parameters.h
  15318. --- linux-3.12.26.orig/drivers/media/platform/bcm2835/mmal-parameters.h 1970-01-01 01:00:00.000000000 +0100
  15319. +++ linux-3.12.26/drivers/media/platform/bcm2835/mmal-parameters.h 2014-08-06 16:50:14.393961522 +0200
  15320. @@ -0,0 +1,655 @@
  15321. +/*
  15322. + * Broadcom BM2835 V4L2 driver
  15323. + *
  15324. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  15325. + *
  15326. + * This file is subject to the terms and conditions of the GNU General Public
  15327. + * License. See the file COPYING in the main directory of this archive
  15328. + * for more details.
  15329. + *
  15330. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  15331. + * Dave Stevenson <dsteve@broadcom.com>
  15332. + * Simon Mellor <simellor@broadcom.com>
  15333. + * Luke Diamand <luked@broadcom.com>
  15334. + */
  15335. +
  15336. +/* common parameters */
  15337. +
  15338. +/** @name Parameter groups
  15339. + * Parameters are divided into groups, and then allocated sequentially within
  15340. + * a group using an enum.
  15341. + * @{
  15342. + */
  15343. +
  15344. +/** Common parameter ID group, used with many types of component. */
  15345. +#define MMAL_PARAMETER_GROUP_COMMON (0<<16)
  15346. +/** Camera-specific parameter ID group. */
  15347. +#define MMAL_PARAMETER_GROUP_CAMERA (1<<16)
  15348. +/** Video-specific parameter ID group. */
  15349. +#define MMAL_PARAMETER_GROUP_VIDEO (2<<16)
  15350. +/** Audio-specific parameter ID group. */
  15351. +#define MMAL_PARAMETER_GROUP_AUDIO (3<<16)
  15352. +/** Clock-specific parameter ID group. */
  15353. +#define MMAL_PARAMETER_GROUP_CLOCK (4<<16)
  15354. +/** Miracast-specific parameter ID group. */
  15355. +#define MMAL_PARAMETER_GROUP_MIRACAST (5<<16)
  15356. +
  15357. +/* Common parameters */
  15358. +enum mmal_parameter_common_type {
  15359. + MMAL_PARAMETER_UNUSED /**< Never a valid parameter ID */
  15360. + = MMAL_PARAMETER_GROUP_COMMON,
  15361. + MMAL_PARAMETER_SUPPORTED_ENCODINGS, /**< MMAL_PARAMETER_ENCODING_T */
  15362. + MMAL_PARAMETER_URI, /**< MMAL_PARAMETER_URI_T */
  15363. +
  15364. + /** MMAL_PARAMETER_CHANGE_EVENT_REQUEST_T */
  15365. + MMAL_PARAMETER_CHANGE_EVENT_REQUEST,
  15366. +
  15367. + /** MMAL_PARAMETER_BOOLEAN_T */
  15368. + MMAL_PARAMETER_ZERO_COPY,
  15369. +
  15370. + /**< MMAL_PARAMETER_BUFFER_REQUIREMENTS_T */
  15371. + MMAL_PARAMETER_BUFFER_REQUIREMENTS,
  15372. +
  15373. + MMAL_PARAMETER_STATISTICS, /**< MMAL_PARAMETER_STATISTICS_T */
  15374. + MMAL_PARAMETER_CORE_STATISTICS, /**< MMAL_PARAMETER_CORE_STATISTICS_T */
  15375. + MMAL_PARAMETER_MEM_USAGE, /**< MMAL_PARAMETER_MEM_USAGE_T */
  15376. + MMAL_PARAMETER_BUFFER_FLAG_FILTER, /**< MMAL_PARAMETER_UINT32_T */
  15377. + MMAL_PARAMETER_SEEK, /**< MMAL_PARAMETER_SEEK_T */
  15378. + MMAL_PARAMETER_POWERMON_ENABLE, /**< MMAL_PARAMETER_BOOLEAN_T */
  15379. + MMAL_PARAMETER_LOGGING, /**< MMAL_PARAMETER_LOGGING_T */
  15380. + MMAL_PARAMETER_SYSTEM_TIME /**< MMAL_PARAMETER_UINT64_T */
  15381. +};
  15382. +
  15383. +/* camera parameters */
  15384. +
  15385. +enum mmal_parameter_camera_type {
  15386. + /* 0 */
  15387. + /** @ref MMAL_PARAMETER_THUMBNAIL_CONFIG_T */
  15388. + MMAL_PARAMETER_THUMBNAIL_CONFIGURATION
  15389. + = MMAL_PARAMETER_GROUP_CAMERA,
  15390. + MMAL_PARAMETER_CAPTURE_QUALITY, /**< Unused? */
  15391. + MMAL_PARAMETER_ROTATION, /**< @ref MMAL_PARAMETER_INT32_T */
  15392. + MMAL_PARAMETER_EXIF_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15393. + MMAL_PARAMETER_EXIF, /**< @ref MMAL_PARAMETER_EXIF_T */
  15394. + MMAL_PARAMETER_AWB_MODE, /**< @ref MMAL_PARAM_AWBMODE_T */
  15395. + MMAL_PARAMETER_IMAGE_EFFECT, /**< @ref MMAL_PARAMETER_IMAGEFX_T */
  15396. + MMAL_PARAMETER_COLOUR_EFFECT, /**< @ref MMAL_PARAMETER_COLOURFX_T */
  15397. + MMAL_PARAMETER_FLICKER_AVOID, /**< @ref MMAL_PARAMETER_FLICKERAVOID_T */
  15398. + MMAL_PARAMETER_FLASH, /**< @ref MMAL_PARAMETER_FLASH_T */
  15399. + MMAL_PARAMETER_REDEYE, /**< @ref MMAL_PARAMETER_REDEYE_T */
  15400. + MMAL_PARAMETER_FOCUS, /**< @ref MMAL_PARAMETER_FOCUS_T */
  15401. + MMAL_PARAMETER_FOCAL_LENGTHS, /**< Unused? */
  15402. + MMAL_PARAMETER_EXPOSURE_COMP, /**< @ref MMAL_PARAMETER_INT32_T */
  15403. + MMAL_PARAMETER_ZOOM, /**< @ref MMAL_PARAMETER_SCALEFACTOR_T */
  15404. + MMAL_PARAMETER_MIRROR, /**< @ref MMAL_PARAMETER_MIRROR_T */
  15405. +
  15406. + /* 0x10 */
  15407. + MMAL_PARAMETER_CAMERA_NUM, /**< @ref MMAL_PARAMETER_UINT32_T */
  15408. + MMAL_PARAMETER_CAPTURE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15409. + MMAL_PARAMETER_EXPOSURE_MODE, /**< @ref MMAL_PARAMETER_EXPOSUREMODE_T */
  15410. + MMAL_PARAMETER_EXP_METERING_MODE, /**< @ref MMAL_PARAMETER_EXPOSUREMETERINGMODE_T */
  15411. + MMAL_PARAMETER_FOCUS_STATUS, /**< @ref MMAL_PARAMETER_FOCUS_STATUS_T */
  15412. + MMAL_PARAMETER_CAMERA_CONFIG, /**< @ref MMAL_PARAMETER_CAMERA_CONFIG_T */
  15413. + MMAL_PARAMETER_CAPTURE_STATUS, /**< @ref MMAL_PARAMETER_CAPTURE_STATUS_T */
  15414. + MMAL_PARAMETER_FACE_TRACK, /**< @ref MMAL_PARAMETER_FACE_TRACK_T */
  15415. + MMAL_PARAMETER_DRAW_BOX_FACES_AND_FOCUS, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15416. + MMAL_PARAMETER_JPEG_Q_FACTOR, /**< @ref MMAL_PARAMETER_UINT32_T */
  15417. + MMAL_PARAMETER_FRAME_RATE, /**< @ref MMAL_PARAMETER_FRAME_RATE_T */
  15418. + MMAL_PARAMETER_USE_STC, /**< @ref MMAL_PARAMETER_CAMERA_STC_MODE_T */
  15419. + MMAL_PARAMETER_CAMERA_INFO, /**< @ref MMAL_PARAMETER_CAMERA_INFO_T */
  15420. + MMAL_PARAMETER_VIDEO_STABILISATION, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15421. + MMAL_PARAMETER_FACE_TRACK_RESULTS, /**< @ref MMAL_PARAMETER_FACE_TRACK_RESULTS_T */
  15422. + MMAL_PARAMETER_ENABLE_RAW_CAPTURE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15423. +
  15424. + /* 0x20 */
  15425. + MMAL_PARAMETER_DPF_FILE, /**< @ref MMAL_PARAMETER_URI_T */
  15426. + MMAL_PARAMETER_ENABLE_DPF_FILE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15427. + MMAL_PARAMETER_DPF_FAIL_IS_FATAL, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15428. + MMAL_PARAMETER_CAPTURE_MODE, /**< @ref MMAL_PARAMETER_CAPTUREMODE_T */
  15429. + MMAL_PARAMETER_FOCUS_REGIONS, /**< @ref MMAL_PARAMETER_FOCUS_REGIONS_T */
  15430. + MMAL_PARAMETER_INPUT_CROP, /**< @ref MMAL_PARAMETER_INPUT_CROP_T */
  15431. + MMAL_PARAMETER_SENSOR_INFORMATION, /**< @ref MMAL_PARAMETER_SENSOR_INFORMATION_T */
  15432. + MMAL_PARAMETER_FLASH_SELECT, /**< @ref MMAL_PARAMETER_FLASH_SELECT_T */
  15433. + MMAL_PARAMETER_FIELD_OF_VIEW, /**< @ref MMAL_PARAMETER_FIELD_OF_VIEW_T */
  15434. + MMAL_PARAMETER_HIGH_DYNAMIC_RANGE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15435. + MMAL_PARAMETER_DYNAMIC_RANGE_COMPRESSION, /**< @ref MMAL_PARAMETER_DRC_T */
  15436. + MMAL_PARAMETER_ALGORITHM_CONTROL, /**< @ref MMAL_PARAMETER_ALGORITHM_CONTROL_T */
  15437. + MMAL_PARAMETER_SHARPNESS, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  15438. + MMAL_PARAMETER_CONTRAST, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  15439. + MMAL_PARAMETER_BRIGHTNESS, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  15440. + MMAL_PARAMETER_SATURATION, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  15441. +
  15442. + /* 0x30 */
  15443. + MMAL_PARAMETER_ISO, /**< @ref MMAL_PARAMETER_UINT32_T */
  15444. + MMAL_PARAMETER_ANTISHAKE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15445. +
  15446. + /** @ref MMAL_PARAMETER_IMAGEFX_PARAMETERS_T */
  15447. + MMAL_PARAMETER_IMAGE_EFFECT_PARAMETERS,
  15448. +
  15449. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  15450. + MMAL_PARAMETER_CAMERA_BURST_CAPTURE,
  15451. +
  15452. + /** @ref MMAL_PARAMETER_UINT32_T */
  15453. + MMAL_PARAMETER_CAMERA_MIN_ISO,
  15454. +
  15455. + /** @ref MMAL_PARAMETER_CAMERA_USE_CASE_T */
  15456. + MMAL_PARAMETER_CAMERA_USE_CASE,
  15457. +
  15458. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15459. + MMAL_PARAMETER_CAPTURE_STATS_PASS,
  15460. +
  15461. + /** @ref MMAL_PARAMETER_UINT32_T */
  15462. + MMAL_PARAMETER_CAMERA_CUSTOM_SENSOR_CONFIG,
  15463. +
  15464. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  15465. + MMAL_PARAMETER_ENABLE_REGISTER_FILE,
  15466. +
  15467. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  15468. + MMAL_PARAMETER_REGISTER_FAIL_IS_FATAL,
  15469. +
  15470. + /** @ref MMAL_PARAMETER_CONFIGFILE_T */
  15471. + MMAL_PARAMETER_CONFIGFILE_REGISTERS,
  15472. +
  15473. + /** @ref MMAL_PARAMETER_CONFIGFILE_CHUNK_T */
  15474. + MMAL_PARAMETER_CONFIGFILE_CHUNK_REGISTERS,
  15475. + MMAL_PARAMETER_JPEG_ATTACH_LOG, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15476. + MMAL_PARAMETER_ZERO_SHUTTER_LAG, /**< @ref MMAL_PARAMETER_ZEROSHUTTERLAG_T */
  15477. + MMAL_PARAMETER_FPS_RANGE, /**< @ref MMAL_PARAMETER_FPS_RANGE_T */
  15478. + MMAL_PARAMETER_CAPTURE_EXPOSURE_COMP, /**< @ref MMAL_PARAMETER_INT32_T */
  15479. +
  15480. + /* 0x40 */
  15481. + MMAL_PARAMETER_SW_SHARPEN_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15482. + MMAL_PARAMETER_FLASH_REQUIRED, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15483. + MMAL_PARAMETER_SW_SATURATION_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15484. + MMAL_PARAMETER_SHUTTER_SPEED, /**< Takes a @ref MMAL_PARAMETER_UINT32_T */
  15485. + MMAL_PARAMETER_CUSTOM_AWB_GAINS, /**< Takes a @ref MMAL_PARAMETER_AWB_GAINS_T */
  15486. +};
  15487. +
  15488. +struct mmal_parameter_rational {
  15489. + s32 num; /**< Numerator */
  15490. + s32 den; /**< Denominator */
  15491. +};
  15492. +
  15493. +enum mmal_parameter_camera_config_timestamp_mode {
  15494. + MMAL_PARAM_TIMESTAMP_MODE_ZERO = 0, /* Always timestamp frames as 0 */
  15495. + MMAL_PARAM_TIMESTAMP_MODE_RAW_STC, /* Use the raw STC value
  15496. + * for the frame timestamp
  15497. + */
  15498. + MMAL_PARAM_TIMESTAMP_MODE_RESET_STC, /* Use the STC timestamp
  15499. + * but subtract the
  15500. + * timestamp of the first
  15501. + * frame sent to give a
  15502. + * zero based timestamp.
  15503. + */
  15504. +};
  15505. +
  15506. +struct mmal_parameter_fps_range {
  15507. + /**< Low end of the permitted framerate range */
  15508. + struct mmal_parameter_rational fps_low;
  15509. + /**< High end of the permitted framerate range */
  15510. + struct mmal_parameter_rational fps_high;
  15511. +};
  15512. +
  15513. +
  15514. +/* camera configuration parameter */
  15515. +struct mmal_parameter_camera_config {
  15516. + /* Parameters for setting up the image pools */
  15517. + u32 max_stills_w; /* Max size of stills capture */
  15518. + u32 max_stills_h;
  15519. + u32 stills_yuv422; /* Allow YUV422 stills capture */
  15520. + u32 one_shot_stills; /* Continuous or one shot stills captures. */
  15521. +
  15522. + u32 max_preview_video_w; /* Max size of the preview or video
  15523. + * capture frames
  15524. + */
  15525. + u32 max_preview_video_h;
  15526. + u32 num_preview_video_frames;
  15527. +
  15528. + /** Sets the height of the circular buffer for stills capture. */
  15529. + u32 stills_capture_circular_buffer_height;
  15530. +
  15531. + /** Allows preview/encode to resume as fast as possible after the stills
  15532. + * input frame has been received, and then processes the still frame in
  15533. + * the background whilst preview/encode has resumed.
  15534. + * Actual mode is controlled by MMAL_PARAMETER_CAPTURE_MODE.
  15535. + */
  15536. + u32 fast_preview_resume;
  15537. +
  15538. + /** Selects algorithm for timestamping frames if
  15539. + * there is no clock component connected.
  15540. + * enum mmal_parameter_camera_config_timestamp_mode
  15541. + */
  15542. + s32 use_stc_timestamp;
  15543. +};
  15544. +
  15545. +
  15546. +enum mmal_parameter_exposuremode {
  15547. + MMAL_PARAM_EXPOSUREMODE_OFF,
  15548. + MMAL_PARAM_EXPOSUREMODE_AUTO,
  15549. + MMAL_PARAM_EXPOSUREMODE_NIGHT,
  15550. + MMAL_PARAM_EXPOSUREMODE_NIGHTPREVIEW,
  15551. + MMAL_PARAM_EXPOSUREMODE_BACKLIGHT,
  15552. + MMAL_PARAM_EXPOSUREMODE_SPOTLIGHT,
  15553. + MMAL_PARAM_EXPOSUREMODE_SPORTS,
  15554. + MMAL_PARAM_EXPOSUREMODE_SNOW,
  15555. + MMAL_PARAM_EXPOSUREMODE_BEACH,
  15556. + MMAL_PARAM_EXPOSUREMODE_VERYLONG,
  15557. + MMAL_PARAM_EXPOSUREMODE_FIXEDFPS,
  15558. + MMAL_PARAM_EXPOSUREMODE_ANTISHAKE,
  15559. + MMAL_PARAM_EXPOSUREMODE_FIREWORKS,
  15560. +};
  15561. +
  15562. +enum mmal_parameter_exposuremeteringmode {
  15563. + MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE,
  15564. + MMAL_PARAM_EXPOSUREMETERINGMODE_SPOT,
  15565. + MMAL_PARAM_EXPOSUREMETERINGMODE_BACKLIT,
  15566. + MMAL_PARAM_EXPOSUREMETERINGMODE_MATRIX,
  15567. +};
  15568. +
  15569. +enum mmal_parameter_awbmode {
  15570. + MMAL_PARAM_AWBMODE_OFF,
  15571. + MMAL_PARAM_AWBMODE_AUTO,
  15572. + MMAL_PARAM_AWBMODE_SUNLIGHT,
  15573. + MMAL_PARAM_AWBMODE_CLOUDY,
  15574. + MMAL_PARAM_AWBMODE_SHADE,
  15575. + MMAL_PARAM_AWBMODE_TUNGSTEN,
  15576. + MMAL_PARAM_AWBMODE_FLUORESCENT,
  15577. + MMAL_PARAM_AWBMODE_INCANDESCENT,
  15578. + MMAL_PARAM_AWBMODE_FLASH,
  15579. + MMAL_PARAM_AWBMODE_HORIZON,
  15580. +};
  15581. +
  15582. +enum mmal_parameter_imagefx {
  15583. + MMAL_PARAM_IMAGEFX_NONE,
  15584. + MMAL_PARAM_IMAGEFX_NEGATIVE,
  15585. + MMAL_PARAM_IMAGEFX_SOLARIZE,
  15586. + MMAL_PARAM_IMAGEFX_POSTERIZE,
  15587. + MMAL_PARAM_IMAGEFX_WHITEBOARD,
  15588. + MMAL_PARAM_IMAGEFX_BLACKBOARD,
  15589. + MMAL_PARAM_IMAGEFX_SKETCH,
  15590. + MMAL_PARAM_IMAGEFX_DENOISE,
  15591. + MMAL_PARAM_IMAGEFX_EMBOSS,
  15592. + MMAL_PARAM_IMAGEFX_OILPAINT,
  15593. + MMAL_PARAM_IMAGEFX_HATCH,
  15594. + MMAL_PARAM_IMAGEFX_GPEN,
  15595. + MMAL_PARAM_IMAGEFX_PASTEL,
  15596. + MMAL_PARAM_IMAGEFX_WATERCOLOUR,
  15597. + MMAL_PARAM_IMAGEFX_FILM,
  15598. + MMAL_PARAM_IMAGEFX_BLUR,
  15599. + MMAL_PARAM_IMAGEFX_SATURATION,
  15600. + MMAL_PARAM_IMAGEFX_COLOURSWAP,
  15601. + MMAL_PARAM_IMAGEFX_WASHEDOUT,
  15602. + MMAL_PARAM_IMAGEFX_POSTERISE,
  15603. + MMAL_PARAM_IMAGEFX_COLOURPOINT,
  15604. + MMAL_PARAM_IMAGEFX_COLOURBALANCE,
  15605. + MMAL_PARAM_IMAGEFX_CARTOON,
  15606. +};
  15607. +
  15608. +enum MMAL_PARAM_FLICKERAVOID_T {
  15609. + MMAL_PARAM_FLICKERAVOID_OFF,
  15610. + MMAL_PARAM_FLICKERAVOID_AUTO,
  15611. + MMAL_PARAM_FLICKERAVOID_50HZ,
  15612. + MMAL_PARAM_FLICKERAVOID_60HZ,
  15613. + MMAL_PARAM_FLICKERAVOID_MAX = 0x7FFFFFFF
  15614. +};
  15615. +
  15616. +struct mmal_parameter_awbgains {
  15617. + struct mmal_parameter_rational r_gain; /**< Red gain */
  15618. + struct mmal_parameter_rational b_gain; /**< Blue gain */
  15619. +};
  15620. +
  15621. +/** Manner of video rate control */
  15622. +enum mmal_parameter_rate_control_mode {
  15623. + MMAL_VIDEO_RATECONTROL_DEFAULT,
  15624. + MMAL_VIDEO_RATECONTROL_VARIABLE,
  15625. + MMAL_VIDEO_RATECONTROL_CONSTANT,
  15626. + MMAL_VIDEO_RATECONTROL_VARIABLE_SKIP_FRAMES,
  15627. + MMAL_VIDEO_RATECONTROL_CONSTANT_SKIP_FRAMES
  15628. +};
  15629. +
  15630. +enum mmal_video_profile {
  15631. + MMAL_VIDEO_PROFILE_H263_BASELINE,
  15632. + MMAL_VIDEO_PROFILE_H263_H320CODING,
  15633. + MMAL_VIDEO_PROFILE_H263_BACKWARDCOMPATIBLE,
  15634. + MMAL_VIDEO_PROFILE_H263_ISWV2,
  15635. + MMAL_VIDEO_PROFILE_H263_ISWV3,
  15636. + MMAL_VIDEO_PROFILE_H263_HIGHCOMPRESSION,
  15637. + MMAL_VIDEO_PROFILE_H263_INTERNET,
  15638. + MMAL_VIDEO_PROFILE_H263_INTERLACE,
  15639. + MMAL_VIDEO_PROFILE_H263_HIGHLATENCY,
  15640. + MMAL_VIDEO_PROFILE_MP4V_SIMPLE,
  15641. + MMAL_VIDEO_PROFILE_MP4V_SIMPLESCALABLE,
  15642. + MMAL_VIDEO_PROFILE_MP4V_CORE,
  15643. + MMAL_VIDEO_PROFILE_MP4V_MAIN,
  15644. + MMAL_VIDEO_PROFILE_MP4V_NBIT,
  15645. + MMAL_VIDEO_PROFILE_MP4V_SCALABLETEXTURE,
  15646. + MMAL_VIDEO_PROFILE_MP4V_SIMPLEFACE,
  15647. + MMAL_VIDEO_PROFILE_MP4V_SIMPLEFBA,
  15648. + MMAL_VIDEO_PROFILE_MP4V_BASICANIMATED,
  15649. + MMAL_VIDEO_PROFILE_MP4V_HYBRID,
  15650. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDREALTIME,
  15651. + MMAL_VIDEO_PROFILE_MP4V_CORESCALABLE,
  15652. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDCODING,
  15653. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDCORE,
  15654. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDSCALABLE,
  15655. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDSIMPLE,
  15656. + MMAL_VIDEO_PROFILE_H264_BASELINE,
  15657. + MMAL_VIDEO_PROFILE_H264_MAIN,
  15658. + MMAL_VIDEO_PROFILE_H264_EXTENDED,
  15659. + MMAL_VIDEO_PROFILE_H264_HIGH,
  15660. + MMAL_VIDEO_PROFILE_H264_HIGH10,
  15661. + MMAL_VIDEO_PROFILE_H264_HIGH422,
  15662. + MMAL_VIDEO_PROFILE_H264_HIGH444,
  15663. + MMAL_VIDEO_PROFILE_H264_CONSTRAINED_BASELINE,
  15664. + MMAL_VIDEO_PROFILE_DUMMY = 0x7FFFFFFF
  15665. +};
  15666. +
  15667. +enum mmal_video_level {
  15668. + MMAL_VIDEO_LEVEL_H263_10,
  15669. + MMAL_VIDEO_LEVEL_H263_20,
  15670. + MMAL_VIDEO_LEVEL_H263_30,
  15671. + MMAL_VIDEO_LEVEL_H263_40,
  15672. + MMAL_VIDEO_LEVEL_H263_45,
  15673. + MMAL_VIDEO_LEVEL_H263_50,
  15674. + MMAL_VIDEO_LEVEL_H263_60,
  15675. + MMAL_VIDEO_LEVEL_H263_70,
  15676. + MMAL_VIDEO_LEVEL_MP4V_0,
  15677. + MMAL_VIDEO_LEVEL_MP4V_0b,
  15678. + MMAL_VIDEO_LEVEL_MP4V_1,
  15679. + MMAL_VIDEO_LEVEL_MP4V_2,
  15680. + MMAL_VIDEO_LEVEL_MP4V_3,
  15681. + MMAL_VIDEO_LEVEL_MP4V_4,
  15682. + MMAL_VIDEO_LEVEL_MP4V_4a,
  15683. + MMAL_VIDEO_LEVEL_MP4V_5,
  15684. + MMAL_VIDEO_LEVEL_MP4V_6,
  15685. + MMAL_VIDEO_LEVEL_H264_1,
  15686. + MMAL_VIDEO_LEVEL_H264_1b,
  15687. + MMAL_VIDEO_LEVEL_H264_11,
  15688. + MMAL_VIDEO_LEVEL_H264_12,
  15689. + MMAL_VIDEO_LEVEL_H264_13,
  15690. + MMAL_VIDEO_LEVEL_H264_2,
  15691. + MMAL_VIDEO_LEVEL_H264_21,
  15692. + MMAL_VIDEO_LEVEL_H264_22,
  15693. + MMAL_VIDEO_LEVEL_H264_3,
  15694. + MMAL_VIDEO_LEVEL_H264_31,
  15695. + MMAL_VIDEO_LEVEL_H264_32,
  15696. + MMAL_VIDEO_LEVEL_H264_4,
  15697. + MMAL_VIDEO_LEVEL_H264_41,
  15698. + MMAL_VIDEO_LEVEL_H264_42,
  15699. + MMAL_VIDEO_LEVEL_H264_5,
  15700. + MMAL_VIDEO_LEVEL_H264_51,
  15701. + MMAL_VIDEO_LEVEL_DUMMY = 0x7FFFFFFF
  15702. +};
  15703. +
  15704. +struct mmal_parameter_video_profile {
  15705. + enum mmal_video_profile profile;
  15706. + enum mmal_video_level level;
  15707. +};
  15708. +
  15709. +/* video parameters */
  15710. +
  15711. +enum mmal_parameter_video_type {
  15712. + /** @ref MMAL_DISPLAYREGION_T */
  15713. + MMAL_PARAMETER_DISPLAYREGION = MMAL_PARAMETER_GROUP_VIDEO,
  15714. +
  15715. + /** @ref MMAL_PARAMETER_VIDEO_PROFILE_T */
  15716. + MMAL_PARAMETER_SUPPORTED_PROFILES,
  15717. +
  15718. + /** @ref MMAL_PARAMETER_VIDEO_PROFILE_T */
  15719. + MMAL_PARAMETER_PROFILE,
  15720. +
  15721. + /** @ref MMAL_PARAMETER_UINT32_T */
  15722. + MMAL_PARAMETER_INTRAPERIOD,
  15723. +
  15724. + /** @ref MMAL_PARAMETER_VIDEO_RATECONTROL_T */
  15725. + MMAL_PARAMETER_RATECONTROL,
  15726. +
  15727. + /** @ref MMAL_PARAMETER_VIDEO_NALUNITFORMAT_T */
  15728. + MMAL_PARAMETER_NALUNITFORMAT,
  15729. +
  15730. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  15731. + MMAL_PARAMETER_MINIMISE_FRAGMENTATION,
  15732. +
  15733. + /** @ref MMAL_PARAMETER_UINT32_T.
  15734. + * Setting the value to zero resets to the default (one slice per frame).
  15735. + */
  15736. + MMAL_PARAMETER_MB_ROWS_PER_SLICE,
  15737. +
  15738. + /** @ref MMAL_PARAMETER_VIDEO_LEVEL_EXTENSION_T */
  15739. + MMAL_PARAMETER_VIDEO_LEVEL_EXTENSION,
  15740. +
  15741. + /** @ref MMAL_PARAMETER_VIDEO_EEDE_ENABLE_T */
  15742. + MMAL_PARAMETER_VIDEO_EEDE_ENABLE,
  15743. +
  15744. + /** @ref MMAL_PARAMETER_VIDEO_EEDE_LOSSRATE_T */
  15745. + MMAL_PARAMETER_VIDEO_EEDE_LOSSRATE,
  15746. +
  15747. + /** @ref MMAL_PARAMETER_BOOLEAN_T. Request an I-frame. */
  15748. + MMAL_PARAMETER_VIDEO_REQUEST_I_FRAME,
  15749. + /** @ref MMAL_PARAMETER_VIDEO_INTRA_REFRESH_T */
  15750. + MMAL_PARAMETER_VIDEO_INTRA_REFRESH,
  15751. +
  15752. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  15753. + MMAL_PARAMETER_VIDEO_IMMUTABLE_INPUT,
  15754. +
  15755. + /** @ref MMAL_PARAMETER_UINT32_T. Run-time bit rate control */
  15756. + MMAL_PARAMETER_VIDEO_BIT_RATE,
  15757. +
  15758. + /** @ref MMAL_PARAMETER_FRAME_RATE_T */
  15759. + MMAL_PARAMETER_VIDEO_FRAME_RATE,
  15760. +
  15761. + /** @ref MMAL_PARAMETER_UINT32_T. */
  15762. + MMAL_PARAMETER_VIDEO_ENCODE_MIN_QUANT,
  15763. +
  15764. + /** @ref MMAL_PARAMETER_UINT32_T. */
  15765. + MMAL_PARAMETER_VIDEO_ENCODE_MAX_QUANT,
  15766. +
  15767. + /** @ref MMAL_PARAMETER_VIDEO_ENCODE_RC_MODEL_T. */
  15768. + MMAL_PARAMETER_VIDEO_ENCODE_RC_MODEL,
  15769. +
  15770. + MMAL_PARAMETER_EXTRA_BUFFERS, /**< @ref MMAL_PARAMETER_UINT32_T. */
  15771. + /** @ref MMAL_PARAMETER_UINT32_T.
  15772. + * Changing this parameter from the default can reduce frame rate
  15773. + * because image buffers need to be re-pitched.
  15774. + */
  15775. + MMAL_PARAMETER_VIDEO_ALIGN_HORIZ,
  15776. +
  15777. + /** @ref MMAL_PARAMETER_UINT32_T.
  15778. + * Changing this parameter from the default can reduce frame rate
  15779. + * because image buffers need to be re-pitched.
  15780. + */
  15781. + MMAL_PARAMETER_VIDEO_ALIGN_VERT,
  15782. +
  15783. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  15784. + MMAL_PARAMETER_VIDEO_DROPPABLE_PFRAMES,
  15785. +
  15786. + /** @ref MMAL_PARAMETER_UINT32_T. */
  15787. + MMAL_PARAMETER_VIDEO_ENCODE_INITIAL_QUANT,
  15788. +
  15789. + /**< @ref MMAL_PARAMETER_UINT32_T. */
  15790. + MMAL_PARAMETER_VIDEO_ENCODE_QP_P,
  15791. +
  15792. + /**< @ref MMAL_PARAMETER_UINT32_T. */
  15793. + MMAL_PARAMETER_VIDEO_ENCODE_RC_SLICE_DQUANT,
  15794. +
  15795. + /** @ref MMAL_PARAMETER_UINT32_T */
  15796. + MMAL_PARAMETER_VIDEO_ENCODE_FRAME_LIMIT_BITS,
  15797. +
  15798. + /** @ref MMAL_PARAMETER_UINT32_T. */
  15799. + MMAL_PARAMETER_VIDEO_ENCODE_PEAK_RATE,
  15800. +
  15801. + /* H264 specific parameters */
  15802. +
  15803. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  15804. + MMAL_PARAMETER_VIDEO_ENCODE_H264_DISABLE_CABAC,
  15805. +
  15806. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  15807. + MMAL_PARAMETER_VIDEO_ENCODE_H264_LOW_LATENCY,
  15808. +
  15809. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  15810. + MMAL_PARAMETER_VIDEO_ENCODE_H264_AU_DELIMITERS,
  15811. +
  15812. + /** @ref MMAL_PARAMETER_UINT32_T. */
  15813. + MMAL_PARAMETER_VIDEO_ENCODE_H264_DEBLOCK_IDC,
  15814. +
  15815. + /** @ref MMAL_PARAMETER_VIDEO_ENCODER_H264_MB_INTRA_MODES_T. */
  15816. + MMAL_PARAMETER_VIDEO_ENCODE_H264_MB_INTRA_MODE,
  15817. +
  15818. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  15819. + MMAL_PARAMETER_VIDEO_ENCODE_HEADER_ON_OPEN,
  15820. +
  15821. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  15822. + MMAL_PARAMETER_VIDEO_ENCODE_PRECODE_FOR_QP,
  15823. +
  15824. + /** @ref MMAL_PARAMETER_VIDEO_DRM_INIT_INFO_T. */
  15825. + MMAL_PARAMETER_VIDEO_DRM_INIT_INFO,
  15826. +
  15827. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  15828. + MMAL_PARAMETER_VIDEO_TIMESTAMP_FIFO,
  15829. +
  15830. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  15831. + MMAL_PARAMETER_VIDEO_DECODE_ERROR_CONCEALMENT,
  15832. +
  15833. + /** @ref MMAL_PARAMETER_VIDEO_DRM_PROTECT_BUFFER_T. */
  15834. + MMAL_PARAMETER_VIDEO_DRM_PROTECT_BUFFER,
  15835. +
  15836. + /** @ref MMAL_PARAMETER_BYTES_T */
  15837. + MMAL_PARAMETER_VIDEO_DECODE_CONFIG_VD3,
  15838. +
  15839. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15840. + MMAL_PARAMETER_VIDEO_ENCODE_H264_VCL_HRD_PARAMETERS,
  15841. +
  15842. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15843. + MMAL_PARAMETER_VIDEO_ENCODE_H264_LOW_DELAY_HRD_FLAG,
  15844. +
  15845. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15846. + MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER
  15847. +};
  15848. +
  15849. +/** Valid mirror modes */
  15850. +enum mmal_parameter_mirror {
  15851. + MMAL_PARAM_MIRROR_NONE,
  15852. + MMAL_PARAM_MIRROR_VERTICAL,
  15853. + MMAL_PARAM_MIRROR_HORIZONTAL,
  15854. + MMAL_PARAM_MIRROR_BOTH,
  15855. +};
  15856. +
  15857. +enum mmal_parameter_displaytransform {
  15858. + MMAL_DISPLAY_ROT0 = 0,
  15859. + MMAL_DISPLAY_MIRROR_ROT0 = 1,
  15860. + MMAL_DISPLAY_MIRROR_ROT180 = 2,
  15861. + MMAL_DISPLAY_ROT180 = 3,
  15862. + MMAL_DISPLAY_MIRROR_ROT90 = 4,
  15863. + MMAL_DISPLAY_ROT270 = 5,
  15864. + MMAL_DISPLAY_ROT90 = 6,
  15865. + MMAL_DISPLAY_MIRROR_ROT270 = 7,
  15866. +};
  15867. +
  15868. +enum mmal_parameter_displaymode {
  15869. + MMAL_DISPLAY_MODE_FILL = 0,
  15870. + MMAL_DISPLAY_MODE_LETTERBOX = 1,
  15871. +};
  15872. +
  15873. +enum mmal_parameter_displayset {
  15874. + MMAL_DISPLAY_SET_NONE = 0,
  15875. + MMAL_DISPLAY_SET_NUM = 1,
  15876. + MMAL_DISPLAY_SET_FULLSCREEN = 2,
  15877. + MMAL_DISPLAY_SET_TRANSFORM = 4,
  15878. + MMAL_DISPLAY_SET_DEST_RECT = 8,
  15879. + MMAL_DISPLAY_SET_SRC_RECT = 0x10,
  15880. + MMAL_DISPLAY_SET_MODE = 0x20,
  15881. + MMAL_DISPLAY_SET_PIXEL = 0x40,
  15882. + MMAL_DISPLAY_SET_NOASPECT = 0x80,
  15883. + MMAL_DISPLAY_SET_LAYER = 0x100,
  15884. + MMAL_DISPLAY_SET_COPYPROTECT = 0x200,
  15885. + MMAL_DISPLAY_SET_ALPHA = 0x400,
  15886. +};
  15887. +
  15888. +struct mmal_parameter_displayregion {
  15889. + /** Bitfield that indicates which fields are set and should be
  15890. + * used. All other fields will maintain their current value.
  15891. + * \ref MMAL_DISPLAYSET_T defines the bits that can be
  15892. + * combined.
  15893. + */
  15894. + u32 set;
  15895. +
  15896. + /** Describes the display output device, with 0 typically
  15897. + * being a directly connected LCD display. The actual values
  15898. + * will depend on the hardware. Code using hard-wired numbers
  15899. + * (e.g. 2) is certain to fail.
  15900. + */
  15901. +
  15902. + u32 display_num;
  15903. + /** Indicates that we are using the full device screen area,
  15904. + * rather than a window of the display. If zero, then
  15905. + * dest_rect is used to specify a region of the display to
  15906. + * use.
  15907. + */
  15908. +
  15909. + s32 fullscreen;
  15910. + /** Indicates any rotation or flipping used to map frames onto
  15911. + * the natural display orientation.
  15912. + */
  15913. + u32 transform; /* enum mmal_parameter_displaytransform */
  15914. +
  15915. + /** Where to display the frame within the screen, if
  15916. + * fullscreen is zero.
  15917. + */
  15918. + struct vchiq_mmal_rect dest_rect;
  15919. +
  15920. + /** Indicates which area of the frame to display. If all
  15921. + * values are zero, the whole frame will be used.
  15922. + */
  15923. + struct vchiq_mmal_rect src_rect;
  15924. +
  15925. + /** If set to non-zero, indicates that any display scaling
  15926. + * should disregard the aspect ratio of the frame region being
  15927. + * displayed.
  15928. + */
  15929. + s32 noaspect;
  15930. +
  15931. + /** Indicates how the image should be scaled to fit the
  15932. + * display. \code MMAL_DISPLAY_MODE_FILL \endcode indicates
  15933. + * that the image should fill the screen by potentially
  15934. + * cropping the frames. Setting \code mode \endcode to \code
  15935. + * MMAL_DISPLAY_MODE_LETTERBOX \endcode indicates that all the
  15936. + * source region should be displayed and black bars added if
  15937. + * necessary.
  15938. + */
  15939. + u32 mode; /* enum mmal_parameter_displaymode */
  15940. +
  15941. + /** If non-zero, defines the width of a source pixel relative
  15942. + * to \code pixel_y \endcode. If zero, then pixels default to
  15943. + * being square.
  15944. + */
  15945. + u32 pixel_x;
  15946. +
  15947. + /** If non-zero, defines the height of a source pixel relative
  15948. + * to \code pixel_x \endcode. If zero, then pixels default to
  15949. + * being square.
  15950. + */
  15951. + u32 pixel_y;
  15952. +
  15953. + /** Sets the relative depth of the images, with greater values
  15954. + * being in front of smaller values.
  15955. + */
  15956. + u32 layer;
  15957. +
  15958. + /** Set to non-zero to ensure copy protection is used on
  15959. + * output.
  15960. + */
  15961. + s32 copyprotect_required;
  15962. +
  15963. + /** Level of opacity of the layer, where zero is fully
  15964. + * transparent and 255 is fully opaque.
  15965. + */
  15966. + u32 alpha;
  15967. +};
  15968. +
  15969. +#define MMAL_MAX_IMAGEFX_PARAMETERS 5
  15970. +
  15971. +struct mmal_parameter_imagefx_parameters {
  15972. + enum mmal_parameter_imagefx effect;
  15973. + u32 num_effect_params;
  15974. + u32 effect_parameter[MMAL_MAX_IMAGEFX_PARAMETERS];
  15975. +};
  15976. diff -Nur linux-3.12.26.orig/drivers/media/platform/bcm2835/mmal-vchiq.c linux-3.12.26/drivers/media/platform/bcm2835/mmal-vchiq.c
  15977. --- linux-3.12.26.orig/drivers/media/platform/bcm2835/mmal-vchiq.c 1970-01-01 01:00:00.000000000 +0100
  15978. +++ linux-3.12.26/drivers/media/platform/bcm2835/mmal-vchiq.c 2014-08-06 16:50:14.397961554 +0200
  15979. @@ -0,0 +1,1916 @@
  15980. +/*
  15981. + * Broadcom BM2835 V4L2 driver
  15982. + *
  15983. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  15984. + *
  15985. + * This file is subject to the terms and conditions of the GNU General Public
  15986. + * License. See the file COPYING in the main directory of this archive
  15987. + * for more details.
  15988. + *
  15989. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  15990. + * Dave Stevenson <dsteve@broadcom.com>
  15991. + * Simon Mellor <simellor@broadcom.com>
  15992. + * Luke Diamand <luked@broadcom.com>
  15993. + *
  15994. + * V4L2 driver MMAL vchiq interface code
  15995. + */
  15996. +
  15997. +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  15998. +
  15999. +#include <linux/errno.h>
  16000. +#include <linux/kernel.h>
  16001. +#include <linux/mutex.h>
  16002. +#include <linux/mm.h>
  16003. +#include <linux/slab.h>
  16004. +#include <linux/completion.h>
  16005. +#include <linux/vmalloc.h>
  16006. +#include <asm/cacheflush.h>
  16007. +#include <media/videobuf2-vmalloc.h>
  16008. +
  16009. +#include "mmal-common.h"
  16010. +#include "mmal-vchiq.h"
  16011. +#include "mmal-msg.h"
  16012. +
  16013. +#define USE_VCHIQ_ARM
  16014. +#include "interface/vchi/vchi.h"
  16015. +
  16016. +/* maximum number of components supported */
  16017. +#define VCHIQ_MMAL_MAX_COMPONENTS 4
  16018. +
  16019. +/*#define FULL_MSG_DUMP 1*/
  16020. +
  16021. +#ifdef DEBUG
  16022. +static const char *const msg_type_names[] = {
  16023. + "UNKNOWN",
  16024. + "QUIT",
  16025. + "SERVICE_CLOSED",
  16026. + "GET_VERSION",
  16027. + "COMPONENT_CREATE",
  16028. + "COMPONENT_DESTROY",
  16029. + "COMPONENT_ENABLE",
  16030. + "COMPONENT_DISABLE",
  16031. + "PORT_INFO_GET",
  16032. + "PORT_INFO_SET",
  16033. + "PORT_ACTION",
  16034. + "BUFFER_FROM_HOST",
  16035. + "BUFFER_TO_HOST",
  16036. + "GET_STATS",
  16037. + "PORT_PARAMETER_SET",
  16038. + "PORT_PARAMETER_GET",
  16039. + "EVENT_TO_HOST",
  16040. + "GET_CORE_STATS_FOR_PORT",
  16041. + "OPAQUE_ALLOCATOR",
  16042. + "CONSUME_MEM",
  16043. + "LMK",
  16044. + "OPAQUE_ALLOCATOR_DESC",
  16045. + "DRM_GET_LHS32",
  16046. + "DRM_GET_TIME",
  16047. + "BUFFER_FROM_HOST_ZEROLEN",
  16048. + "PORT_FLUSH",
  16049. + "HOST_LOG",
  16050. +};
  16051. +#endif
  16052. +
  16053. +static const char *const port_action_type_names[] = {
  16054. + "UNKNOWN",
  16055. + "ENABLE",
  16056. + "DISABLE",
  16057. + "FLUSH",
  16058. + "CONNECT",
  16059. + "DISCONNECT",
  16060. + "SET_REQUIREMENTS",
  16061. +};
  16062. +
  16063. +#if defined(DEBUG)
  16064. +#if defined(FULL_MSG_DUMP)
  16065. +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE) \
  16066. + do { \
  16067. + pr_debug(TITLE" type:%s(%d) length:%d\n", \
  16068. + msg_type_names[(MSG)->h.type], \
  16069. + (MSG)->h.type, (MSG_LEN)); \
  16070. + print_hex_dump(KERN_DEBUG, "<<h: ", DUMP_PREFIX_OFFSET, \
  16071. + 16, 4, (MSG), \
  16072. + sizeof(struct mmal_msg_header), 1); \
  16073. + print_hex_dump(KERN_DEBUG, "<<p: ", DUMP_PREFIX_OFFSET, \
  16074. + 16, 4, \
  16075. + ((u8 *)(MSG)) + sizeof(struct mmal_msg_header),\
  16076. + (MSG_LEN) - sizeof(struct mmal_msg_header), 1); \
  16077. + } while (0)
  16078. +#else
  16079. +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE) \
  16080. + { \
  16081. + pr_debug(TITLE" type:%s(%d) length:%d\n", \
  16082. + msg_type_names[(MSG)->h.type], \
  16083. + (MSG)->h.type, (MSG_LEN)); \
  16084. + }
  16085. +#endif
  16086. +#else
  16087. +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE)
  16088. +#endif
  16089. +
  16090. +/* normal message context */
  16091. +struct mmal_msg_context {
  16092. + union {
  16093. + struct {
  16094. + /* work struct for defered callback - must come first */
  16095. + struct work_struct work;
  16096. + /* mmal instance */
  16097. + struct vchiq_mmal_instance *instance;
  16098. + /* mmal port */
  16099. + struct vchiq_mmal_port *port;
  16100. + /* actual buffer used to store bulk reply */
  16101. + struct mmal_buffer *buffer;
  16102. + /* amount of buffer used */
  16103. + unsigned long buffer_used;
  16104. + /* MMAL buffer flags */
  16105. + u32 mmal_flags;
  16106. + /* Presentation and Decode timestamps */
  16107. + s64 pts;
  16108. + s64 dts;
  16109. +
  16110. + int status; /* context status */
  16111. +
  16112. + } bulk; /* bulk data */
  16113. +
  16114. + struct {
  16115. + /* message handle to release */
  16116. + VCHI_HELD_MSG_T msg_handle;
  16117. + /* pointer to received message */
  16118. + struct mmal_msg *msg;
  16119. + /* received message length */
  16120. + u32 msg_len;
  16121. + /* completion upon reply */
  16122. + struct completion cmplt;
  16123. + } sync; /* synchronous response */
  16124. + } u;
  16125. +
  16126. +};
  16127. +
  16128. +struct vchiq_mmal_instance {
  16129. + VCHI_SERVICE_HANDLE_T handle;
  16130. +
  16131. + /* ensure serialised access to service */
  16132. + struct mutex vchiq_mutex;
  16133. +
  16134. + /* ensure serialised access to bulk operations */
  16135. + struct mutex bulk_mutex;
  16136. +
  16137. + /* vmalloc page to receive scratch bulk xfers into */
  16138. + void *bulk_scratch;
  16139. +
  16140. + /* component to use next */
  16141. + int component_idx;
  16142. + struct vchiq_mmal_component component[VCHIQ_MMAL_MAX_COMPONENTS];
  16143. +};
  16144. +
  16145. +static struct mmal_msg_context *get_msg_context(struct vchiq_mmal_instance
  16146. + *instance)
  16147. +{
  16148. + struct mmal_msg_context *msg_context;
  16149. +
  16150. + /* todo: should this be allocated from a pool to avoid kmalloc */
  16151. + msg_context = kmalloc(sizeof(*msg_context), GFP_KERNEL);
  16152. + memset(msg_context, 0, sizeof(*msg_context));
  16153. +
  16154. + return msg_context;
  16155. +}
  16156. +
  16157. +static void release_msg_context(struct mmal_msg_context *msg_context)
  16158. +{
  16159. + kfree(msg_context);
  16160. +}
  16161. +
  16162. +/* deals with receipt of event to host message */
  16163. +static void event_to_host_cb(struct vchiq_mmal_instance *instance,
  16164. + struct mmal_msg *msg, u32 msg_len)
  16165. +{
  16166. + pr_debug("unhandled event\n");
  16167. + pr_debug("component:%p port type:%d num:%d cmd:0x%x length:%d\n",
  16168. + msg->u.event_to_host.client_component,
  16169. + msg->u.event_to_host.port_type,
  16170. + msg->u.event_to_host.port_num,
  16171. + msg->u.event_to_host.cmd, msg->u.event_to_host.length);
  16172. +}
  16173. +
  16174. +/* workqueue scheduled callback
  16175. + *
  16176. + * we do this because it is important we do not call any other vchiq
  16177. + * sync calls from witin the message delivery thread
  16178. + */
  16179. +static void buffer_work_cb(struct work_struct *work)
  16180. +{
  16181. + struct mmal_msg_context *msg_context = (struct mmal_msg_context *)work;
  16182. +
  16183. + msg_context->u.bulk.port->buffer_cb(msg_context->u.bulk.instance,
  16184. + msg_context->u.bulk.port,
  16185. + msg_context->u.bulk.status,
  16186. + msg_context->u.bulk.buffer,
  16187. + msg_context->u.bulk.buffer_used,
  16188. + msg_context->u.bulk.mmal_flags,
  16189. + msg_context->u.bulk.dts,
  16190. + msg_context->u.bulk.pts);
  16191. +
  16192. + /* release message context */
  16193. + release_msg_context(msg_context);
  16194. +}
  16195. +
  16196. +/* enqueue a bulk receive for a given message context */
  16197. +static int bulk_receive(struct vchiq_mmal_instance *instance,
  16198. + struct mmal_msg *msg,
  16199. + struct mmal_msg_context *msg_context)
  16200. +{
  16201. + unsigned long rd_len;
  16202. + unsigned long flags = 0;
  16203. + int ret;
  16204. +
  16205. + /* bulk mutex stops other bulk operations while we have a
  16206. + * receive in progress - released in callback
  16207. + */
  16208. + ret = mutex_lock_interruptible(&instance->bulk_mutex);
  16209. + if (ret != 0)
  16210. + return ret;
  16211. +
  16212. + rd_len = msg->u.buffer_from_host.buffer_header.length;
  16213. +
  16214. + /* take buffer from queue */
  16215. + spin_lock_irqsave(&msg_context->u.bulk.port->slock, flags);
  16216. + if (list_empty(&msg_context->u.bulk.port->buffers)) {
  16217. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  16218. + pr_err("buffer list empty trying to submit bulk receive\n");
  16219. +
  16220. + /* todo: this is a serious error, we should never have
  16221. + * commited a buffer_to_host operation to the mmal
  16222. + * port without the buffer to back it up (underflow
  16223. + * handling) and there is no obvious way to deal with
  16224. + * this - how is the mmal servie going to react when
  16225. + * we fail to do the xfer and reschedule a buffer when
  16226. + * it arrives? perhaps a starved flag to indicate a
  16227. + * waiting bulk receive?
  16228. + */
  16229. +
  16230. + mutex_unlock(&instance->bulk_mutex);
  16231. +
  16232. + return -EINVAL;
  16233. + }
  16234. +
  16235. + msg_context->u.bulk.buffer =
  16236. + list_entry(msg_context->u.bulk.port->buffers.next,
  16237. + struct mmal_buffer, list);
  16238. + list_del(&msg_context->u.bulk.buffer->list);
  16239. +
  16240. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  16241. +
  16242. + /* ensure we do not overrun the available buffer */
  16243. + if (rd_len > msg_context->u.bulk.buffer->buffer_size) {
  16244. + rd_len = msg_context->u.bulk.buffer->buffer_size;
  16245. + pr_warn("short read as not enough receive buffer space\n");
  16246. + /* todo: is this the correct response, what happens to
  16247. + * the rest of the message data?
  16248. + */
  16249. + }
  16250. +
  16251. + /* store length */
  16252. + msg_context->u.bulk.buffer_used = rd_len;
  16253. + msg_context->u.bulk.mmal_flags =
  16254. + msg->u.buffer_from_host.buffer_header.flags;
  16255. + msg_context->u.bulk.dts = msg->u.buffer_from_host.buffer_header.dts;
  16256. + msg_context->u.bulk.pts = msg->u.buffer_from_host.buffer_header.pts;
  16257. +
  16258. + // only need to flush L1 cache here, as VCHIQ takes care of the L2
  16259. + // cache.
  16260. + __cpuc_flush_dcache_area(msg_context->u.bulk.buffer->buffer, rd_len);
  16261. +
  16262. + /* queue the bulk submission */
  16263. + vchi_service_use(instance->handle);
  16264. + ret = vchi_bulk_queue_receive(instance->handle,
  16265. + msg_context->u.bulk.buffer->buffer,
  16266. + /* Actual receive needs to be a multiple
  16267. + * of 4 bytes
  16268. + */
  16269. + (rd_len + 3) & ~3,
  16270. + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE |
  16271. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED,
  16272. + msg_context);
  16273. +
  16274. + vchi_service_release(instance->handle);
  16275. +
  16276. + if (ret != 0) {
  16277. + /* callback will not be clearing the mutex */
  16278. + mutex_unlock(&instance->bulk_mutex);
  16279. + }
  16280. +
  16281. + return ret;
  16282. +}
  16283. +
  16284. +/* enque a dummy bulk receive for a given message context */
  16285. +static int dummy_bulk_receive(struct vchiq_mmal_instance *instance,
  16286. + struct mmal_msg_context *msg_context)
  16287. +{
  16288. + int ret;
  16289. +
  16290. + /* bulk mutex stops other bulk operations while we have a
  16291. + * receive in progress - released in callback
  16292. + */
  16293. + ret = mutex_lock_interruptible(&instance->bulk_mutex);
  16294. + if (ret != 0)
  16295. + return ret;
  16296. +
  16297. + /* zero length indicates this was a dummy transfer */
  16298. + msg_context->u.bulk.buffer_used = 0;
  16299. +
  16300. + /* queue the bulk submission */
  16301. + vchi_service_use(instance->handle);
  16302. +
  16303. + ret = vchi_bulk_queue_receive(instance->handle,
  16304. + instance->bulk_scratch,
  16305. + 8,
  16306. + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE |
  16307. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED,
  16308. + msg_context);
  16309. +
  16310. + vchi_service_release(instance->handle);
  16311. +
  16312. + if (ret != 0) {
  16313. + /* callback will not be clearing the mutex */
  16314. + mutex_unlock(&instance->bulk_mutex);
  16315. + }
  16316. +
  16317. + return ret;
  16318. +}
  16319. +
  16320. +/* data in message, memcpy from packet into output buffer */
  16321. +static int inline_receive(struct vchiq_mmal_instance *instance,
  16322. + struct mmal_msg *msg,
  16323. + struct mmal_msg_context *msg_context)
  16324. +{
  16325. + unsigned long flags = 0;
  16326. +
  16327. + /* take buffer from queue */
  16328. + spin_lock_irqsave(&msg_context->u.bulk.port->slock, flags);
  16329. + if (list_empty(&msg_context->u.bulk.port->buffers)) {
  16330. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  16331. + pr_err("buffer list empty trying to receive inline\n");
  16332. +
  16333. + /* todo: this is a serious error, we should never have
  16334. + * commited a buffer_to_host operation to the mmal
  16335. + * port without the buffer to back it up (with
  16336. + * underflow handling) and there is no obvious way to
  16337. + * deal with this. Less bad than the bulk case as we
  16338. + * can just drop this on the floor but...unhelpful
  16339. + */
  16340. + return -EINVAL;
  16341. + }
  16342. +
  16343. + msg_context->u.bulk.buffer =
  16344. + list_entry(msg_context->u.bulk.port->buffers.next,
  16345. + struct mmal_buffer, list);
  16346. + list_del(&msg_context->u.bulk.buffer->list);
  16347. +
  16348. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  16349. +
  16350. + memcpy(msg_context->u.bulk.buffer->buffer,
  16351. + msg->u.buffer_from_host.short_data,
  16352. + msg->u.buffer_from_host.payload_in_message);
  16353. +
  16354. + msg_context->u.bulk.buffer_used =
  16355. + msg->u.buffer_from_host.payload_in_message;
  16356. +
  16357. + return 0;
  16358. +}
  16359. +
  16360. +/* queue the buffer availability with MMAL_MSG_TYPE_BUFFER_FROM_HOST */
  16361. +static int
  16362. +buffer_from_host(struct vchiq_mmal_instance *instance,
  16363. + struct vchiq_mmal_port *port, struct mmal_buffer *buf)
  16364. +{
  16365. + struct mmal_msg_context *msg_context;
  16366. + struct mmal_msg m;
  16367. + int ret;
  16368. +
  16369. + pr_debug("instance:%p buffer:%p\n", instance->handle, buf);
  16370. +
  16371. + /* bulk mutex stops other bulk operations while we
  16372. + * have a receive in progress
  16373. + */
  16374. + if (mutex_lock_interruptible(&instance->bulk_mutex))
  16375. + return -EINTR;
  16376. +
  16377. + /* get context */
  16378. + msg_context = get_msg_context(instance);
  16379. + if (msg_context == NULL)
  16380. + return -ENOMEM;
  16381. +
  16382. + /* store bulk message context for when data arrives */
  16383. + msg_context->u.bulk.instance = instance;
  16384. + msg_context->u.bulk.port = port;
  16385. + msg_context->u.bulk.buffer = NULL; /* not valid until bulk xfer */
  16386. + msg_context->u.bulk.buffer_used = 0;
  16387. +
  16388. + /* initialise work structure ready to schedule callback */
  16389. + INIT_WORK(&msg_context->u.bulk.work, buffer_work_cb);
  16390. +
  16391. + /* prep the buffer from host message */
  16392. + memset(&m, 0xbc, sizeof(m)); /* just to make debug clearer */
  16393. +
  16394. + m.h.type = MMAL_MSG_TYPE_BUFFER_FROM_HOST;
  16395. + m.h.magic = MMAL_MAGIC;
  16396. + m.h.context = msg_context;
  16397. + m.h.status = 0;
  16398. +
  16399. + /* drvbuf is our private data passed back */
  16400. + m.u.buffer_from_host.drvbuf.magic = MMAL_MAGIC;
  16401. + m.u.buffer_from_host.drvbuf.component_handle = port->component->handle;
  16402. + m.u.buffer_from_host.drvbuf.port_handle = port->handle;
  16403. + m.u.buffer_from_host.drvbuf.client_context = msg_context;
  16404. +
  16405. + /* buffer header */
  16406. + m.u.buffer_from_host.buffer_header.cmd = 0;
  16407. + m.u.buffer_from_host.buffer_header.data = buf->buffer;
  16408. + m.u.buffer_from_host.buffer_header.alloc_size = buf->buffer_size;
  16409. + m.u.buffer_from_host.buffer_header.length = 0; /* nothing used yet */
  16410. + m.u.buffer_from_host.buffer_header.offset = 0; /* no offset */
  16411. + m.u.buffer_from_host.buffer_header.flags = 0; /* no flags */
  16412. + m.u.buffer_from_host.buffer_header.pts = MMAL_TIME_UNKNOWN;
  16413. + m.u.buffer_from_host.buffer_header.dts = MMAL_TIME_UNKNOWN;
  16414. +
  16415. + /* clear buffer type sepecific data */
  16416. + memset(&m.u.buffer_from_host.buffer_header_type_specific, 0,
  16417. + sizeof(m.u.buffer_from_host.buffer_header_type_specific));
  16418. +
  16419. + /* no payload in message */
  16420. + m.u.buffer_from_host.payload_in_message = 0;
  16421. +
  16422. + vchi_service_use(instance->handle);
  16423. +
  16424. + ret = vchi_msg_queue(instance->handle, &m,
  16425. + sizeof(struct mmal_msg_header) +
  16426. + sizeof(m.u.buffer_from_host),
  16427. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  16428. +
  16429. + if (ret != 0) {
  16430. + release_msg_context(msg_context);
  16431. + /* todo: is this correct error value? */
  16432. + }
  16433. +
  16434. + vchi_service_release(instance->handle);
  16435. +
  16436. + mutex_unlock(&instance->bulk_mutex);
  16437. +
  16438. + return ret;
  16439. +}
  16440. +
  16441. +/* submit a buffer to the mmal sevice
  16442. + *
  16443. + * the buffer_from_host uses size data from the ports next available
  16444. + * mmal_buffer and deals with there being no buffer available by
  16445. + * incrementing the underflow for later
  16446. + */
  16447. +static int port_buffer_from_host(struct vchiq_mmal_instance *instance,
  16448. + struct vchiq_mmal_port *port)
  16449. +{
  16450. + int ret;
  16451. + struct mmal_buffer *buf;
  16452. + unsigned long flags = 0;
  16453. +
  16454. + if (!port->enabled)
  16455. + return -EINVAL;
  16456. +
  16457. + /* peek buffer from queue */
  16458. + spin_lock_irqsave(&port->slock, flags);
  16459. + if (list_empty(&port->buffers)) {
  16460. + port->buffer_underflow++;
  16461. + spin_unlock_irqrestore(&port->slock, flags);
  16462. + return -ENOSPC;
  16463. + }
  16464. +
  16465. + buf = list_entry(port->buffers.next, struct mmal_buffer, list);
  16466. +
  16467. + spin_unlock_irqrestore(&port->slock, flags);
  16468. +
  16469. + /* issue buffer to mmal service */
  16470. + ret = buffer_from_host(instance, port, buf);
  16471. + if (ret) {
  16472. + pr_err("adding buffer header failed\n");
  16473. + /* todo: how should this be dealt with */
  16474. + }
  16475. +
  16476. + return ret;
  16477. +}
  16478. +
  16479. +/* deals with receipt of buffer to host message */
  16480. +static void buffer_to_host_cb(struct vchiq_mmal_instance *instance,
  16481. + struct mmal_msg *msg, u32 msg_len)
  16482. +{
  16483. + struct mmal_msg_context *msg_context;
  16484. +
  16485. + pr_debug("buffer_to_host_cb: instance:%p msg:%p msg_len:%d\n",
  16486. + instance, msg, msg_len);
  16487. +
  16488. + if (msg->u.buffer_from_host.drvbuf.magic == MMAL_MAGIC) {
  16489. + msg_context = msg->u.buffer_from_host.drvbuf.client_context;
  16490. + } else {
  16491. + pr_err("MMAL_MSG_TYPE_BUFFER_TO_HOST with bad magic\n");
  16492. + return;
  16493. + }
  16494. +
  16495. + if (msg->h.status != MMAL_MSG_STATUS_SUCCESS) {
  16496. + /* message reception had an error */
  16497. + pr_warn("error %d in reply\n", msg->h.status);
  16498. +
  16499. + msg_context->u.bulk.status = msg->h.status;
  16500. +
  16501. + } else if (msg->u.buffer_from_host.buffer_header.length == 0) {
  16502. + /* empty buffer */
  16503. + if (msg->u.buffer_from_host.buffer_header.flags &
  16504. + MMAL_BUFFER_HEADER_FLAG_EOS) {
  16505. + msg_context->u.bulk.status =
  16506. + dummy_bulk_receive(instance, msg_context);
  16507. + if (msg_context->u.bulk.status == 0)
  16508. + return; /* successful bulk submission, bulk
  16509. + * completion will trigger callback
  16510. + */
  16511. + } else {
  16512. + /* do callback with empty buffer - not EOS though */
  16513. + msg_context->u.bulk.status = 0;
  16514. + msg_context->u.bulk.buffer_used = 0;
  16515. + }
  16516. + } else if (msg->u.buffer_from_host.payload_in_message == 0) {
  16517. + /* data is not in message, queue a bulk receive */
  16518. + msg_context->u.bulk.status =
  16519. + bulk_receive(instance, msg, msg_context);
  16520. + if (msg_context->u.bulk.status == 0)
  16521. + return; /* successful bulk submission, bulk
  16522. + * completion will trigger callback
  16523. + */
  16524. +
  16525. + /* failed to submit buffer, this will end badly */
  16526. + pr_err("error %d on bulk submission\n",
  16527. + msg_context->u.bulk.status);
  16528. +
  16529. + } else if (msg->u.buffer_from_host.payload_in_message <=
  16530. + MMAL_VC_SHORT_DATA) {
  16531. + /* data payload within message */
  16532. + msg_context->u.bulk.status = inline_receive(instance, msg,
  16533. + msg_context);
  16534. + } else {
  16535. + pr_err("message with invalid short payload\n");
  16536. +
  16537. + /* signal error */
  16538. + msg_context->u.bulk.status = -EINVAL;
  16539. + msg_context->u.bulk.buffer_used =
  16540. + msg->u.buffer_from_host.payload_in_message;
  16541. + }
  16542. +
  16543. + /* replace the buffer header */
  16544. + port_buffer_from_host(instance, msg_context->u.bulk.port);
  16545. +
  16546. + /* schedule the port callback */
  16547. + schedule_work(&msg_context->u.bulk.work);
  16548. +}
  16549. +
  16550. +static void bulk_receive_cb(struct vchiq_mmal_instance *instance,
  16551. + struct mmal_msg_context *msg_context)
  16552. +{
  16553. + /* bulk receive operation complete */
  16554. + mutex_unlock(&msg_context->u.bulk.instance->bulk_mutex);
  16555. +
  16556. + /* replace the buffer header */
  16557. + port_buffer_from_host(msg_context->u.bulk.instance,
  16558. + msg_context->u.bulk.port);
  16559. +
  16560. + msg_context->u.bulk.status = 0;
  16561. +
  16562. + /* schedule the port callback */
  16563. + schedule_work(&msg_context->u.bulk.work);
  16564. +}
  16565. +
  16566. +static void bulk_abort_cb(struct vchiq_mmal_instance *instance,
  16567. + struct mmal_msg_context *msg_context)
  16568. +{
  16569. + pr_err("%s: bulk ABORTED msg_context:%p\n", __func__, msg_context);
  16570. +
  16571. + /* bulk receive operation complete */
  16572. + mutex_unlock(&msg_context->u.bulk.instance->bulk_mutex);
  16573. +
  16574. + /* replace the buffer header */
  16575. + port_buffer_from_host(msg_context->u.bulk.instance,
  16576. + msg_context->u.bulk.port);
  16577. +
  16578. + msg_context->u.bulk.status = -EINTR;
  16579. +
  16580. + schedule_work(&msg_context->u.bulk.work);
  16581. +}
  16582. +
  16583. +/* incoming event service callback */
  16584. +static void service_callback(void *param,
  16585. + const VCHI_CALLBACK_REASON_T reason,
  16586. + void *bulk_ctx)
  16587. +{
  16588. + struct vchiq_mmal_instance *instance = param;
  16589. + int status;
  16590. + u32 msg_len;
  16591. + struct mmal_msg *msg;
  16592. + VCHI_HELD_MSG_T msg_handle;
  16593. +
  16594. + if (!instance) {
  16595. + pr_err("Message callback passed NULL instance\n");
  16596. + return;
  16597. + }
  16598. +
  16599. + switch (reason) {
  16600. + case VCHI_CALLBACK_MSG_AVAILABLE:
  16601. + status = vchi_msg_hold(instance->handle, (void **)&msg,
  16602. + &msg_len, VCHI_FLAGS_NONE, &msg_handle);
  16603. + if (status) {
  16604. + pr_err("Unable to dequeue a message (%d)\n", status);
  16605. + break;
  16606. + }
  16607. +
  16608. + DBG_DUMP_MSG(msg, msg_len, "<<< reply message");
  16609. +
  16610. + /* handling is different for buffer messages */
  16611. + switch (msg->h.type) {
  16612. +
  16613. + case MMAL_MSG_TYPE_BUFFER_FROM_HOST:
  16614. + vchi_held_msg_release(&msg_handle);
  16615. + break;
  16616. +
  16617. + case MMAL_MSG_TYPE_EVENT_TO_HOST:
  16618. + event_to_host_cb(instance, msg, msg_len);
  16619. + vchi_held_msg_release(&msg_handle);
  16620. +
  16621. + break;
  16622. +
  16623. + case MMAL_MSG_TYPE_BUFFER_TO_HOST:
  16624. + buffer_to_host_cb(instance, msg, msg_len);
  16625. + vchi_held_msg_release(&msg_handle);
  16626. + break;
  16627. +
  16628. + default:
  16629. + /* messages dependant on header context to complete */
  16630. +
  16631. + /* todo: the msg.context really ought to be sanity
  16632. + * checked before we just use it, afaict it comes back
  16633. + * and is used raw from the videocore. Perhaps it
  16634. + * should be verified the address lies in the kernel
  16635. + * address space.
  16636. + */
  16637. + if (msg->h.context == NULL) {
  16638. + pr_err("received message context was null!\n");
  16639. + vchi_held_msg_release(&msg_handle);
  16640. + break;
  16641. + }
  16642. +
  16643. + /* fill in context values */
  16644. + msg->h.context->u.sync.msg_handle = msg_handle;
  16645. + msg->h.context->u.sync.msg = msg;
  16646. + msg->h.context->u.sync.msg_len = msg_len;
  16647. +
  16648. + /* todo: should this check (completion_done()
  16649. + * == 1) for no one waiting? or do we need a
  16650. + * flag to tell us the completion has been
  16651. + * interrupted so we can free the message and
  16652. + * its context. This probably also solves the
  16653. + * message arriving after interruption todo
  16654. + * below
  16655. + */
  16656. +
  16657. + /* complete message so caller knows it happened */
  16658. + complete(&msg->h.context->u.sync.cmplt);
  16659. + break;
  16660. + }
  16661. +
  16662. + break;
  16663. +
  16664. + case VCHI_CALLBACK_BULK_RECEIVED:
  16665. + bulk_receive_cb(instance, bulk_ctx);
  16666. + break;
  16667. +
  16668. + case VCHI_CALLBACK_BULK_RECEIVE_ABORTED:
  16669. + bulk_abort_cb(instance, bulk_ctx);
  16670. + break;
  16671. +
  16672. + case VCHI_CALLBACK_SERVICE_CLOSED:
  16673. + /* TODO: consider if this requires action if received when
  16674. + * driver is not explicitly closing the service
  16675. + */
  16676. + break;
  16677. +
  16678. + default:
  16679. + pr_err("Received unhandled message reason %d\n", reason);
  16680. + break;
  16681. + }
  16682. +}
  16683. +
  16684. +static int send_synchronous_mmal_msg(struct vchiq_mmal_instance *instance,
  16685. + struct mmal_msg *msg,
  16686. + unsigned int payload_len,
  16687. + struct mmal_msg **msg_out,
  16688. + VCHI_HELD_MSG_T *msg_handle_out)
  16689. +{
  16690. + struct mmal_msg_context msg_context;
  16691. + int ret;
  16692. +
  16693. + /* payload size must not cause message to exceed max size */
  16694. + if (payload_len >
  16695. + (MMAL_MSG_MAX_SIZE - sizeof(struct mmal_msg_header))) {
  16696. + pr_err("payload length %d exceeds max:%d\n", payload_len,
  16697. + (MMAL_MSG_MAX_SIZE - sizeof(struct mmal_msg_header)));
  16698. + return -EINVAL;
  16699. + }
  16700. +
  16701. + init_completion(&msg_context.u.sync.cmplt);
  16702. +
  16703. + msg->h.magic = MMAL_MAGIC;
  16704. + msg->h.context = &msg_context;
  16705. + msg->h.status = 0;
  16706. +
  16707. + DBG_DUMP_MSG(msg, (sizeof(struct mmal_msg_header) + payload_len),
  16708. + ">>> sync message");
  16709. +
  16710. + vchi_service_use(instance->handle);
  16711. +
  16712. + ret = vchi_msg_queue(instance->handle,
  16713. + msg,
  16714. + sizeof(struct mmal_msg_header) + payload_len,
  16715. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  16716. +
  16717. + vchi_service_release(instance->handle);
  16718. +
  16719. + if (ret) {
  16720. + pr_err("error %d queuing message\n", ret);
  16721. + return ret;
  16722. + }
  16723. +
  16724. + ret = wait_for_completion_timeout(&msg_context.u.sync.cmplt, HZ);
  16725. + if (ret <= 0) {
  16726. + pr_err("error %d waiting for sync completion\n", ret);
  16727. + if (ret == 0)
  16728. + ret = -ETIME;
  16729. + /* todo: what happens if the message arrives after aborting */
  16730. + return ret;
  16731. + }
  16732. +
  16733. + *msg_out = msg_context.u.sync.msg;
  16734. + *msg_handle_out = msg_context.u.sync.msg_handle;
  16735. +
  16736. + return 0;
  16737. +}
  16738. +
  16739. +static void dump_port_info(struct vchiq_mmal_port *port)
  16740. +{
  16741. + pr_debug("port handle:0x%x enabled:%d\n", port->handle, port->enabled);
  16742. +
  16743. + pr_debug("buffer minimum num:%d size:%d align:%d\n",
  16744. + port->minimum_buffer.num,
  16745. + port->minimum_buffer.size, port->minimum_buffer.alignment);
  16746. +
  16747. + pr_debug("buffer recommended num:%d size:%d align:%d\n",
  16748. + port->recommended_buffer.num,
  16749. + port->recommended_buffer.size,
  16750. + port->recommended_buffer.alignment);
  16751. +
  16752. + pr_debug("buffer current values num:%d size:%d align:%d\n",
  16753. + port->current_buffer.num,
  16754. + port->current_buffer.size, port->current_buffer.alignment);
  16755. +
  16756. + pr_debug("elementry stream: type:%d encoding:0x%x varient:0x%x\n",
  16757. + port->format.type,
  16758. + port->format.encoding, port->format.encoding_variant);
  16759. +
  16760. + pr_debug(" bitrate:%d flags:0x%x\n",
  16761. + port->format.bitrate, port->format.flags);
  16762. +
  16763. + if (port->format.type == MMAL_ES_TYPE_VIDEO) {
  16764. + pr_debug
  16765. + ("es video format: width:%d height:%d colourspace:0x%x\n",
  16766. + port->es.video.width, port->es.video.height,
  16767. + port->es.video.color_space);
  16768. +
  16769. + pr_debug(" : crop xywh %d,%d,%d,%d\n",
  16770. + port->es.video.crop.x,
  16771. + port->es.video.crop.y,
  16772. + port->es.video.crop.width, port->es.video.crop.height);
  16773. + pr_debug(" : framerate %d/%d aspect %d/%d\n",
  16774. + port->es.video.frame_rate.num,
  16775. + port->es.video.frame_rate.den,
  16776. + port->es.video.par.num, port->es.video.par.den);
  16777. + }
  16778. +}
  16779. +
  16780. +static void port_to_mmal_msg(struct vchiq_mmal_port *port, struct mmal_port *p)
  16781. +{
  16782. +
  16783. + /* todo do readonly fields need setting at all? */
  16784. + p->type = port->type;
  16785. + p->index = port->index;
  16786. + p->index_all = 0;
  16787. + p->is_enabled = port->enabled;
  16788. + p->buffer_num_min = port->minimum_buffer.num;
  16789. + p->buffer_size_min = port->minimum_buffer.size;
  16790. + p->buffer_alignment_min = port->minimum_buffer.alignment;
  16791. + p->buffer_num_recommended = port->recommended_buffer.num;
  16792. + p->buffer_size_recommended = port->recommended_buffer.size;
  16793. +
  16794. + /* only three writable fields in a port */
  16795. + p->buffer_num = port->current_buffer.num;
  16796. + p->buffer_size = port->current_buffer.size;
  16797. + p->userdata = port;
  16798. +}
  16799. +
  16800. +static int port_info_set(struct vchiq_mmal_instance *instance,
  16801. + struct vchiq_mmal_port *port)
  16802. +{
  16803. + int ret;
  16804. + struct mmal_msg m;
  16805. + struct mmal_msg *rmsg;
  16806. + VCHI_HELD_MSG_T rmsg_handle;
  16807. +
  16808. + pr_debug("setting port info port %p\n", port);
  16809. + if (!port)
  16810. + return -1;
  16811. + dump_port_info(port);
  16812. +
  16813. + m.h.type = MMAL_MSG_TYPE_PORT_INFO_SET;
  16814. +
  16815. + m.u.port_info_set.component_handle = port->component->handle;
  16816. + m.u.port_info_set.port_type = port->type;
  16817. + m.u.port_info_set.port_index = port->index;
  16818. +
  16819. + port_to_mmal_msg(port, &m.u.port_info_set.port);
  16820. +
  16821. + /* elementry stream format setup */
  16822. + m.u.port_info_set.format.type = port->format.type;
  16823. + m.u.port_info_set.format.encoding = port->format.encoding;
  16824. + m.u.port_info_set.format.encoding_variant =
  16825. + port->format.encoding_variant;
  16826. + m.u.port_info_set.format.bitrate = port->format.bitrate;
  16827. + m.u.port_info_set.format.flags = port->format.flags;
  16828. +
  16829. + memcpy(&m.u.port_info_set.es, &port->es,
  16830. + sizeof(union mmal_es_specific_format));
  16831. +
  16832. + m.u.port_info_set.format.extradata_size = port->format.extradata_size;
  16833. + memcpy(rmsg->u.port_info_set.extradata, port->format.extradata,
  16834. + port->format.extradata_size);
  16835. +
  16836. + ret = send_synchronous_mmal_msg(instance, &m,
  16837. + sizeof(m.u.port_info_set),
  16838. + &rmsg, &rmsg_handle);
  16839. + if (ret)
  16840. + return ret;
  16841. +
  16842. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_INFO_SET) {
  16843. + /* got an unexpected message type in reply */
  16844. + ret = -EINVAL;
  16845. + goto release_msg;
  16846. + }
  16847. +
  16848. + /* return operation status */
  16849. + ret = -rmsg->u.port_info_get_reply.status;
  16850. +
  16851. + pr_debug("%s:result:%d component:0x%x port:%d\n", __func__, ret,
  16852. + port->component->handle, port->handle);
  16853. +
  16854. +release_msg:
  16855. + vchi_held_msg_release(&rmsg_handle);
  16856. +
  16857. + return ret;
  16858. +
  16859. +}
  16860. +
  16861. +/* use port info get message to retrive port information */
  16862. +static int port_info_get(struct vchiq_mmal_instance *instance,
  16863. + struct vchiq_mmal_port *port)
  16864. +{
  16865. + int ret;
  16866. + struct mmal_msg m;
  16867. + struct mmal_msg *rmsg;
  16868. + VCHI_HELD_MSG_T rmsg_handle;
  16869. +
  16870. + /* port info time */
  16871. + m.h.type = MMAL_MSG_TYPE_PORT_INFO_GET;
  16872. + m.u.port_info_get.component_handle = port->component->handle;
  16873. + m.u.port_info_get.port_type = port->type;
  16874. + m.u.port_info_get.index = port->index;
  16875. +
  16876. + ret = send_synchronous_mmal_msg(instance, &m,
  16877. + sizeof(m.u.port_info_get),
  16878. + &rmsg, &rmsg_handle);
  16879. + if (ret)
  16880. + return ret;
  16881. +
  16882. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_INFO_GET) {
  16883. + /* got an unexpected message type in reply */
  16884. + ret = -EINVAL;
  16885. + goto release_msg;
  16886. + }
  16887. +
  16888. + /* return operation status */
  16889. + ret = -rmsg->u.port_info_get_reply.status;
  16890. + if (ret != MMAL_MSG_STATUS_SUCCESS)
  16891. + goto release_msg;
  16892. +
  16893. + if (rmsg->u.port_info_get_reply.port.is_enabled == 0)
  16894. + port->enabled = false;
  16895. + else
  16896. + port->enabled = true;
  16897. +
  16898. + /* copy the values out of the message */
  16899. + port->handle = rmsg->u.port_info_get_reply.port_handle;
  16900. +
  16901. + /* port type and index cached to use on port info set becuase
  16902. + * it does not use a port handle
  16903. + */
  16904. + port->type = rmsg->u.port_info_get_reply.port_type;
  16905. + port->index = rmsg->u.port_info_get_reply.port_index;
  16906. +
  16907. + port->minimum_buffer.num =
  16908. + rmsg->u.port_info_get_reply.port.buffer_num_min;
  16909. + port->minimum_buffer.size =
  16910. + rmsg->u.port_info_get_reply.port.buffer_size_min;
  16911. + port->minimum_buffer.alignment =
  16912. + rmsg->u.port_info_get_reply.port.buffer_alignment_min;
  16913. +
  16914. + port->recommended_buffer.alignment =
  16915. + rmsg->u.port_info_get_reply.port.buffer_alignment_min;
  16916. + port->recommended_buffer.num =
  16917. + rmsg->u.port_info_get_reply.port.buffer_num_recommended;
  16918. +
  16919. + port->current_buffer.num = rmsg->u.port_info_get_reply.port.buffer_num;
  16920. + port->current_buffer.size =
  16921. + rmsg->u.port_info_get_reply.port.buffer_size;
  16922. +
  16923. + /* stream format */
  16924. + port->format.type = rmsg->u.port_info_get_reply.format.type;
  16925. + port->format.encoding = rmsg->u.port_info_get_reply.format.encoding;
  16926. + port->format.encoding_variant =
  16927. + rmsg->u.port_info_get_reply.format.encoding_variant;
  16928. + port->format.bitrate = rmsg->u.port_info_get_reply.format.bitrate;
  16929. + port->format.flags = rmsg->u.port_info_get_reply.format.flags;
  16930. +
  16931. + /* elementry stream format */
  16932. + memcpy(&port->es,
  16933. + &rmsg->u.port_info_get_reply.es,
  16934. + sizeof(union mmal_es_specific_format));
  16935. + port->format.es = &port->es;
  16936. +
  16937. + port->format.extradata_size =
  16938. + rmsg->u.port_info_get_reply.format.extradata_size;
  16939. + memcpy(port->format.extradata,
  16940. + rmsg->u.port_info_get_reply.extradata,
  16941. + port->format.extradata_size);
  16942. +
  16943. + pr_debug("received port info\n");
  16944. + dump_port_info(port);
  16945. +
  16946. +release_msg:
  16947. +
  16948. + pr_debug("%s:result:%d component:0x%x port:%d\n",
  16949. + __func__, ret, port->component->handle, port->handle);
  16950. +
  16951. + vchi_held_msg_release(&rmsg_handle);
  16952. +
  16953. + return ret;
  16954. +}
  16955. +
  16956. +/* create comonent on vc */
  16957. +static int create_component(struct vchiq_mmal_instance *instance,
  16958. + struct vchiq_mmal_component *component,
  16959. + const char *name)
  16960. +{
  16961. + int ret;
  16962. + struct mmal_msg m;
  16963. + struct mmal_msg *rmsg;
  16964. + VCHI_HELD_MSG_T rmsg_handle;
  16965. +
  16966. + /* build component create message */
  16967. + m.h.type = MMAL_MSG_TYPE_COMPONENT_CREATE;
  16968. + m.u.component_create.client_component = component;
  16969. + strncpy(m.u.component_create.name, name,
  16970. + sizeof(m.u.component_create.name));
  16971. +
  16972. + ret = send_synchronous_mmal_msg(instance, &m,
  16973. + sizeof(m.u.component_create),
  16974. + &rmsg, &rmsg_handle);
  16975. + if (ret)
  16976. + return ret;
  16977. +
  16978. + if (rmsg->h.type != m.h.type) {
  16979. + /* got an unexpected message type in reply */
  16980. + ret = -EINVAL;
  16981. + goto release_msg;
  16982. + }
  16983. +
  16984. + ret = -rmsg->u.component_create_reply.status;
  16985. + if (ret != MMAL_MSG_STATUS_SUCCESS)
  16986. + goto release_msg;
  16987. +
  16988. + /* a valid component response received */
  16989. + component->handle = rmsg->u.component_create_reply.component_handle;
  16990. + component->inputs = rmsg->u.component_create_reply.input_num;
  16991. + component->outputs = rmsg->u.component_create_reply.output_num;
  16992. + component->clocks = rmsg->u.component_create_reply.clock_num;
  16993. +
  16994. + pr_debug("Component handle:0x%x in:%d out:%d clock:%d\n",
  16995. + component->handle,
  16996. + component->inputs, component->outputs, component->clocks);
  16997. +
  16998. +release_msg:
  16999. + vchi_held_msg_release(&rmsg_handle);
  17000. +
  17001. + return ret;
  17002. +}
  17003. +
  17004. +/* destroys a component on vc */
  17005. +static int destroy_component(struct vchiq_mmal_instance *instance,
  17006. + struct vchiq_mmal_component *component)
  17007. +{
  17008. + int ret;
  17009. + struct mmal_msg m;
  17010. + struct mmal_msg *rmsg;
  17011. + VCHI_HELD_MSG_T rmsg_handle;
  17012. +
  17013. + m.h.type = MMAL_MSG_TYPE_COMPONENT_DESTROY;
  17014. + m.u.component_destroy.component_handle = component->handle;
  17015. +
  17016. + ret = send_synchronous_mmal_msg(instance, &m,
  17017. + sizeof(m.u.component_destroy),
  17018. + &rmsg, &rmsg_handle);
  17019. + if (ret)
  17020. + return ret;
  17021. +
  17022. + if (rmsg->h.type != m.h.type) {
  17023. + /* got an unexpected message type in reply */
  17024. + ret = -EINVAL;
  17025. + goto release_msg;
  17026. + }
  17027. +
  17028. + ret = -rmsg->u.component_destroy_reply.status;
  17029. +
  17030. +release_msg:
  17031. +
  17032. + vchi_held_msg_release(&rmsg_handle);
  17033. +
  17034. + return ret;
  17035. +}
  17036. +
  17037. +/* enable a component on vc */
  17038. +static int enable_component(struct vchiq_mmal_instance *instance,
  17039. + struct vchiq_mmal_component *component)
  17040. +{
  17041. + int ret;
  17042. + struct mmal_msg m;
  17043. + struct mmal_msg *rmsg;
  17044. + VCHI_HELD_MSG_T rmsg_handle;
  17045. +
  17046. + m.h.type = MMAL_MSG_TYPE_COMPONENT_ENABLE;
  17047. + m.u.component_enable.component_handle = component->handle;
  17048. +
  17049. + ret = send_synchronous_mmal_msg(instance, &m,
  17050. + sizeof(m.u.component_enable),
  17051. + &rmsg, &rmsg_handle);
  17052. + if (ret)
  17053. + return ret;
  17054. +
  17055. + if (rmsg->h.type != m.h.type) {
  17056. + /* got an unexpected message type in reply */
  17057. + ret = -EINVAL;
  17058. + goto release_msg;
  17059. + }
  17060. +
  17061. + ret = -rmsg->u.component_enable_reply.status;
  17062. +
  17063. +release_msg:
  17064. + vchi_held_msg_release(&rmsg_handle);
  17065. +
  17066. + return ret;
  17067. +}
  17068. +
  17069. +/* disable a component on vc */
  17070. +static int disable_component(struct vchiq_mmal_instance *instance,
  17071. + struct vchiq_mmal_component *component)
  17072. +{
  17073. + int ret;
  17074. + struct mmal_msg m;
  17075. + struct mmal_msg *rmsg;
  17076. + VCHI_HELD_MSG_T rmsg_handle;
  17077. +
  17078. + m.h.type = MMAL_MSG_TYPE_COMPONENT_DISABLE;
  17079. + m.u.component_disable.component_handle = component->handle;
  17080. +
  17081. + ret = send_synchronous_mmal_msg(instance, &m,
  17082. + sizeof(m.u.component_disable),
  17083. + &rmsg, &rmsg_handle);
  17084. + if (ret)
  17085. + return ret;
  17086. +
  17087. + if (rmsg->h.type != m.h.type) {
  17088. + /* got an unexpected message type in reply */
  17089. + ret = -EINVAL;
  17090. + goto release_msg;
  17091. + }
  17092. +
  17093. + ret = -rmsg->u.component_disable_reply.status;
  17094. +
  17095. +release_msg:
  17096. +
  17097. + vchi_held_msg_release(&rmsg_handle);
  17098. +
  17099. + return ret;
  17100. +}
  17101. +
  17102. +/* get version of mmal implementation */
  17103. +static int get_version(struct vchiq_mmal_instance *instance,
  17104. + u32 *major_out, u32 *minor_out)
  17105. +{
  17106. + int ret;
  17107. + struct mmal_msg m;
  17108. + struct mmal_msg *rmsg;
  17109. + VCHI_HELD_MSG_T rmsg_handle;
  17110. +
  17111. + m.h.type = MMAL_MSG_TYPE_GET_VERSION;
  17112. +
  17113. + ret = send_synchronous_mmal_msg(instance, &m,
  17114. + sizeof(m.u.version),
  17115. + &rmsg, &rmsg_handle);
  17116. + if (ret)
  17117. + return ret;
  17118. +
  17119. + if (rmsg->h.type != m.h.type) {
  17120. + /* got an unexpected message type in reply */
  17121. + ret = -EINVAL;
  17122. + goto release_msg;
  17123. + }
  17124. +
  17125. + *major_out = rmsg->u.version.major;
  17126. + *minor_out = rmsg->u.version.minor;
  17127. +
  17128. +release_msg:
  17129. + vchi_held_msg_release(&rmsg_handle);
  17130. +
  17131. + return ret;
  17132. +}
  17133. +
  17134. +/* do a port action with a port as a parameter */
  17135. +static int port_action_port(struct vchiq_mmal_instance *instance,
  17136. + struct vchiq_mmal_port *port,
  17137. + enum mmal_msg_port_action_type action_type)
  17138. +{
  17139. + int ret;
  17140. + struct mmal_msg m;
  17141. + struct mmal_msg *rmsg;
  17142. + VCHI_HELD_MSG_T rmsg_handle;
  17143. +
  17144. + m.h.type = MMAL_MSG_TYPE_PORT_ACTION;
  17145. + m.u.port_action_port.component_handle = port->component->handle;
  17146. + m.u.port_action_port.port_handle = port->handle;
  17147. + m.u.port_action_port.action = action_type;
  17148. +
  17149. + port_to_mmal_msg(port, &m.u.port_action_port.port);
  17150. +
  17151. + ret = send_synchronous_mmal_msg(instance, &m,
  17152. + sizeof(m.u.port_action_port),
  17153. + &rmsg, &rmsg_handle);
  17154. + if (ret)
  17155. + return ret;
  17156. +
  17157. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_ACTION) {
  17158. + /* got an unexpected message type in reply */
  17159. + ret = -EINVAL;
  17160. + goto release_msg;
  17161. + }
  17162. +
  17163. + ret = -rmsg->u.port_action_reply.status;
  17164. +
  17165. + pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d)\n",
  17166. + __func__,
  17167. + ret, port->component->handle, port->handle,
  17168. + port_action_type_names[action_type], action_type);
  17169. +
  17170. +release_msg:
  17171. + vchi_held_msg_release(&rmsg_handle);
  17172. +
  17173. + return ret;
  17174. +}
  17175. +
  17176. +/* do a port action with handles as parameters */
  17177. +static int port_action_handle(struct vchiq_mmal_instance *instance,
  17178. + struct vchiq_mmal_port *port,
  17179. + enum mmal_msg_port_action_type action_type,
  17180. + u32 connect_component_handle,
  17181. + u32 connect_port_handle)
  17182. +{
  17183. + int ret;
  17184. + struct mmal_msg m;
  17185. + struct mmal_msg *rmsg;
  17186. + VCHI_HELD_MSG_T rmsg_handle;
  17187. +
  17188. + m.h.type = MMAL_MSG_TYPE_PORT_ACTION;
  17189. +
  17190. + m.u.port_action_handle.component_handle = port->component->handle;
  17191. + m.u.port_action_handle.port_handle = port->handle;
  17192. + m.u.port_action_handle.action = action_type;
  17193. +
  17194. + m.u.port_action_handle.connect_component_handle =
  17195. + connect_component_handle;
  17196. + m.u.port_action_handle.connect_port_handle = connect_port_handle;
  17197. +
  17198. + ret = send_synchronous_mmal_msg(instance, &m,
  17199. + sizeof(m.u.port_action_handle),
  17200. + &rmsg, &rmsg_handle);
  17201. + if (ret)
  17202. + return ret;
  17203. +
  17204. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_ACTION) {
  17205. + /* got an unexpected message type in reply */
  17206. + ret = -EINVAL;
  17207. + goto release_msg;
  17208. + }
  17209. +
  17210. + ret = -rmsg->u.port_action_reply.status;
  17211. +
  17212. + pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d)" \
  17213. + " connect component:0x%x connect port:%d\n",
  17214. + __func__,
  17215. + ret, port->component->handle, port->handle,
  17216. + port_action_type_names[action_type],
  17217. + action_type, connect_component_handle, connect_port_handle);
  17218. +
  17219. +release_msg:
  17220. + vchi_held_msg_release(&rmsg_handle);
  17221. +
  17222. + return ret;
  17223. +}
  17224. +
  17225. +static int port_parameter_set(struct vchiq_mmal_instance *instance,
  17226. + struct vchiq_mmal_port *port,
  17227. + u32 parameter_id, void *value, u32 value_size)
  17228. +{
  17229. + int ret;
  17230. + struct mmal_msg m;
  17231. + struct mmal_msg *rmsg;
  17232. + VCHI_HELD_MSG_T rmsg_handle;
  17233. +
  17234. + m.h.type = MMAL_MSG_TYPE_PORT_PARAMETER_SET;
  17235. +
  17236. + m.u.port_parameter_set.component_handle = port->component->handle;
  17237. + m.u.port_parameter_set.port_handle = port->handle;
  17238. + m.u.port_parameter_set.id = parameter_id;
  17239. + m.u.port_parameter_set.size = (2 * sizeof(u32)) + value_size;
  17240. + memcpy(&m.u.port_parameter_set.value, value, value_size);
  17241. +
  17242. + ret = send_synchronous_mmal_msg(instance, &m,
  17243. + (4 * sizeof(u32)) + value_size,
  17244. + &rmsg, &rmsg_handle);
  17245. + if (ret)
  17246. + return ret;
  17247. +
  17248. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_PARAMETER_SET) {
  17249. + /* got an unexpected message type in reply */
  17250. + ret = -EINVAL;
  17251. + goto release_msg;
  17252. + }
  17253. +
  17254. + ret = -rmsg->u.port_parameter_set_reply.status;
  17255. +
  17256. + pr_debug("%s:result:%d component:0x%x port:%d parameter:%d\n",
  17257. + __func__,
  17258. + ret, port->component->handle, port->handle, parameter_id);
  17259. +
  17260. +release_msg:
  17261. + vchi_held_msg_release(&rmsg_handle);
  17262. +
  17263. + return ret;
  17264. +}
  17265. +
  17266. +static int port_parameter_get(struct vchiq_mmal_instance *instance,
  17267. + struct vchiq_mmal_port *port,
  17268. + u32 parameter_id, void *value, u32 *value_size)
  17269. +{
  17270. + int ret;
  17271. + struct mmal_msg m;
  17272. + struct mmal_msg *rmsg;
  17273. + VCHI_HELD_MSG_T rmsg_handle;
  17274. +
  17275. + m.h.type = MMAL_MSG_TYPE_PORT_PARAMETER_GET;
  17276. +
  17277. + m.u.port_parameter_get.component_handle = port->component->handle;
  17278. + m.u.port_parameter_get.port_handle = port->handle;
  17279. + m.u.port_parameter_get.id = parameter_id;
  17280. + m.u.port_parameter_get.size = (2 * sizeof(u32)) + *value_size;
  17281. +
  17282. + ret = send_synchronous_mmal_msg(instance, &m,
  17283. + sizeof(struct
  17284. + mmal_msg_port_parameter_get),
  17285. + &rmsg, &rmsg_handle);
  17286. + if (ret)
  17287. + return ret;
  17288. +
  17289. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_PARAMETER_GET) {
  17290. + /* got an unexpected message type in reply */
  17291. + pr_err("Incorrect reply type %d\n", rmsg->h.type);
  17292. + ret = -EINVAL;
  17293. + goto release_msg;
  17294. + }
  17295. +
  17296. + ret = -rmsg->u.port_parameter_get_reply.status;
  17297. + if (ret) {
  17298. + /* Copy only as much as we have space for
  17299. + * but report true size of parameter
  17300. + */
  17301. + memcpy(value, &rmsg->u.port_parameter_get_reply.value,
  17302. + *value_size);
  17303. + *value_size = rmsg->u.port_parameter_get_reply.size;
  17304. + } else
  17305. + memcpy(value, &rmsg->u.port_parameter_get_reply.value,
  17306. + rmsg->u.port_parameter_get_reply.size);
  17307. +
  17308. + pr_debug("%s:result:%d component:0x%x port:%d parameter:%d\n", __func__,
  17309. + ret, port->component->handle, port->handle, parameter_id);
  17310. +
  17311. +release_msg:
  17312. + vchi_held_msg_release(&rmsg_handle);
  17313. +
  17314. + return ret;
  17315. +}
  17316. +
  17317. +/* disables a port and drains buffers from it */
  17318. +static int port_disable(struct vchiq_mmal_instance *instance,
  17319. + struct vchiq_mmal_port *port)
  17320. +{
  17321. + int ret;
  17322. + struct list_head *q, *buf_head;
  17323. + unsigned long flags = 0;
  17324. +
  17325. + if (!port->enabled)
  17326. + return 0;
  17327. +
  17328. + port->enabled = false;
  17329. +
  17330. + ret = port_action_port(instance, port,
  17331. + MMAL_MSG_PORT_ACTION_TYPE_DISABLE);
  17332. + if (ret == 0) {
  17333. +
  17334. + /* drain all queued buffers on port */
  17335. + spin_lock_irqsave(&port->slock, flags);
  17336. +
  17337. + list_for_each_safe(buf_head, q, &port->buffers) {
  17338. + struct mmal_buffer *mmalbuf;
  17339. + mmalbuf = list_entry(buf_head, struct mmal_buffer,
  17340. + list);
  17341. + list_del(buf_head);
  17342. + if (port->buffer_cb)
  17343. + port->buffer_cb(instance,
  17344. + port, 0, mmalbuf, 0, 0,
  17345. + MMAL_TIME_UNKNOWN,
  17346. + MMAL_TIME_UNKNOWN);
  17347. + }
  17348. +
  17349. + spin_unlock_irqrestore(&port->slock, flags);
  17350. +
  17351. + ret = port_info_get(instance, port);
  17352. + }
  17353. +
  17354. + return ret;
  17355. +}
  17356. +
  17357. +/* enable a port */
  17358. +static int port_enable(struct vchiq_mmal_instance *instance,
  17359. + struct vchiq_mmal_port *port)
  17360. +{
  17361. + unsigned int hdr_count;
  17362. + struct list_head *buf_head;
  17363. + int ret;
  17364. +
  17365. + if (port->enabled)
  17366. + return 0;
  17367. +
  17368. + /* ensure there are enough buffers queued to cover the buffer headers */
  17369. + if (port->buffer_cb != NULL) {
  17370. + hdr_count = 0;
  17371. + list_for_each(buf_head, &port->buffers) {
  17372. + hdr_count++;
  17373. + }
  17374. + if (hdr_count < port->current_buffer.num)
  17375. + return -ENOSPC;
  17376. + }
  17377. +
  17378. + ret = port_action_port(instance, port,
  17379. + MMAL_MSG_PORT_ACTION_TYPE_ENABLE);
  17380. + if (ret)
  17381. + goto done;
  17382. +
  17383. + port->enabled = true;
  17384. +
  17385. + if (port->buffer_cb) {
  17386. + /* send buffer headers to videocore */
  17387. + hdr_count = 1;
  17388. + list_for_each(buf_head, &port->buffers) {
  17389. + struct mmal_buffer *mmalbuf;
  17390. + mmalbuf = list_entry(buf_head, struct mmal_buffer,
  17391. + list);
  17392. + ret = buffer_from_host(instance, port, mmalbuf);
  17393. + if (ret)
  17394. + goto done;
  17395. +
  17396. + hdr_count++;
  17397. + if (hdr_count > port->current_buffer.num)
  17398. + break;
  17399. + }
  17400. + }
  17401. +
  17402. + ret = port_info_get(instance, port);
  17403. +
  17404. +done:
  17405. + return ret;
  17406. +}
  17407. +
  17408. +/* ------------------------------------------------------------------
  17409. + * Exported API
  17410. + *------------------------------------------------------------------*/
  17411. +
  17412. +int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
  17413. + struct vchiq_mmal_port *port)
  17414. +{
  17415. + int ret;
  17416. +
  17417. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17418. + return -EINTR;
  17419. +
  17420. + ret = port_info_set(instance, port);
  17421. + if (ret)
  17422. + goto release_unlock;
  17423. +
  17424. + /* read what has actually been set */
  17425. + ret = port_info_get(instance, port);
  17426. +
  17427. +release_unlock:
  17428. + mutex_unlock(&instance->vchiq_mutex);
  17429. +
  17430. + return ret;
  17431. +
  17432. +}
  17433. +
  17434. +int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
  17435. + struct vchiq_mmal_port *port,
  17436. + u32 parameter, void *value, u32 value_size)
  17437. +{
  17438. + int ret;
  17439. +
  17440. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17441. + return -EINTR;
  17442. +
  17443. + ret = port_parameter_set(instance, port, parameter, value, value_size);
  17444. +
  17445. + mutex_unlock(&instance->vchiq_mutex);
  17446. +
  17447. + return ret;
  17448. +}
  17449. +
  17450. +int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
  17451. + struct vchiq_mmal_port *port,
  17452. + u32 parameter, void *value, u32 *value_size)
  17453. +{
  17454. + int ret;
  17455. +
  17456. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17457. + return -EINTR;
  17458. +
  17459. + ret = port_parameter_get(instance, port, parameter, value, value_size);
  17460. +
  17461. + mutex_unlock(&instance->vchiq_mutex);
  17462. +
  17463. + return ret;
  17464. +}
  17465. +
  17466. +/* enable a port
  17467. + *
  17468. + * enables a port and queues buffers for satisfying callbacks if we
  17469. + * provide a callback handler
  17470. + */
  17471. +int vchiq_mmal_port_enable(struct vchiq_mmal_instance *instance,
  17472. + struct vchiq_mmal_port *port,
  17473. + vchiq_mmal_buffer_cb buffer_cb)
  17474. +{
  17475. + int ret;
  17476. +
  17477. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17478. + return -EINTR;
  17479. +
  17480. + /* already enabled - noop */
  17481. + if (port->enabled) {
  17482. + ret = 0;
  17483. + goto unlock;
  17484. + }
  17485. +
  17486. + port->buffer_cb = buffer_cb;
  17487. +
  17488. + ret = port_enable(instance, port);
  17489. +
  17490. +unlock:
  17491. + mutex_unlock(&instance->vchiq_mutex);
  17492. +
  17493. + return ret;
  17494. +}
  17495. +
  17496. +int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
  17497. + struct vchiq_mmal_port *port)
  17498. +{
  17499. + int ret;
  17500. +
  17501. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17502. + return -EINTR;
  17503. +
  17504. + if (!port->enabled) {
  17505. + mutex_unlock(&instance->vchiq_mutex);
  17506. + return 0;
  17507. + }
  17508. +
  17509. + ret = port_disable(instance, port);
  17510. +
  17511. + mutex_unlock(&instance->vchiq_mutex);
  17512. +
  17513. + return ret;
  17514. +}
  17515. +
  17516. +/* ports will be connected in a tunneled manner so data buffers
  17517. + * are not handled by client.
  17518. + */
  17519. +int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
  17520. + struct vchiq_mmal_port *src,
  17521. + struct vchiq_mmal_port *dst)
  17522. +{
  17523. + int ret;
  17524. +
  17525. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17526. + return -EINTR;
  17527. +
  17528. + /* disconnect ports if connected */
  17529. + if (src->connected != NULL) {
  17530. + ret = port_disable(instance, src);
  17531. + if (ret) {
  17532. + pr_err("failed disabling src port(%d)\n", ret);
  17533. + goto release_unlock;
  17534. + }
  17535. +
  17536. + /* do not need to disable the destination port as they
  17537. + * are connected and it is done automatically
  17538. + */
  17539. +
  17540. + ret = port_action_handle(instance, src,
  17541. + MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT,
  17542. + src->connected->component->handle,
  17543. + src->connected->handle);
  17544. + if (ret < 0) {
  17545. + pr_err("failed disconnecting src port\n");
  17546. + goto release_unlock;
  17547. + }
  17548. + src->connected->enabled = false;
  17549. + src->connected = NULL;
  17550. + }
  17551. +
  17552. + if (dst == NULL) {
  17553. + /* do not make new connection */
  17554. + ret = 0;
  17555. + pr_debug("not making new connection\n");
  17556. + goto release_unlock;
  17557. + }
  17558. +
  17559. + /* copy src port format to dst */
  17560. + dst->format.encoding = src->format.encoding;
  17561. + dst->es.video.width = src->es.video.width;
  17562. + dst->es.video.height = src->es.video.height;
  17563. + dst->es.video.crop.x = src->es.video.crop.x;
  17564. + dst->es.video.crop.y = src->es.video.crop.y;
  17565. + dst->es.video.crop.width = src->es.video.crop.width;
  17566. + dst->es.video.crop.height = src->es.video.crop.height;
  17567. + dst->es.video.frame_rate.num = src->es.video.frame_rate.num;
  17568. + dst->es.video.frame_rate.den = src->es.video.frame_rate.den;
  17569. +
  17570. + /* set new format */
  17571. + ret = port_info_set(instance, dst);
  17572. + if (ret) {
  17573. + pr_debug("setting port info failed\n");
  17574. + goto release_unlock;
  17575. + }
  17576. +
  17577. + /* read what has actually been set */
  17578. + ret = port_info_get(instance, dst);
  17579. + if (ret) {
  17580. + pr_debug("read back port info failed\n");
  17581. + goto release_unlock;
  17582. + }
  17583. +
  17584. + /* connect two ports together */
  17585. + ret = port_action_handle(instance, src,
  17586. + MMAL_MSG_PORT_ACTION_TYPE_CONNECT,
  17587. + dst->component->handle, dst->handle);
  17588. + if (ret < 0) {
  17589. + pr_debug("connecting port %d:%d to %d:%d failed\n",
  17590. + src->component->handle, src->handle,
  17591. + dst->component->handle, dst->handle);
  17592. + goto release_unlock;
  17593. + }
  17594. + src->connected = dst;
  17595. +
  17596. +release_unlock:
  17597. +
  17598. + mutex_unlock(&instance->vchiq_mutex);
  17599. +
  17600. + return ret;
  17601. +}
  17602. +
  17603. +int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
  17604. + struct vchiq_mmal_port *port,
  17605. + struct mmal_buffer *buffer)
  17606. +{
  17607. + unsigned long flags = 0;
  17608. +
  17609. + spin_lock_irqsave(&port->slock, flags);
  17610. + list_add_tail(&buffer->list, &port->buffers);
  17611. + spin_unlock_irqrestore(&port->slock, flags);
  17612. +
  17613. + /* the port previously underflowed because it was missing a
  17614. + * mmal_buffer which has just been added, submit that buffer
  17615. + * to the mmal service.
  17616. + */
  17617. + if (port->buffer_underflow) {
  17618. + port_buffer_from_host(instance, port);
  17619. + port->buffer_underflow--;
  17620. + }
  17621. +
  17622. + return 0;
  17623. +}
  17624. +
  17625. +/* Initialise a mmal component and its ports
  17626. + *
  17627. + */
  17628. +int vchiq_mmal_component_init(struct vchiq_mmal_instance *instance,
  17629. + const char *name,
  17630. + struct vchiq_mmal_component **component_out)
  17631. +{
  17632. + int ret;
  17633. + int idx; /* port index */
  17634. + struct vchiq_mmal_component *component;
  17635. +
  17636. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17637. + return -EINTR;
  17638. +
  17639. + if (instance->component_idx == VCHIQ_MMAL_MAX_COMPONENTS) {
  17640. + ret = -EINVAL; /* todo is this correct error? */
  17641. + goto unlock;
  17642. + }
  17643. +
  17644. + component = &instance->component[instance->component_idx];
  17645. +
  17646. + ret = create_component(instance, component, name);
  17647. + if (ret < 0)
  17648. + goto unlock;
  17649. +
  17650. + /* ports info needs gathering */
  17651. + component->control.type = MMAL_PORT_TYPE_CONTROL;
  17652. + component->control.index = 0;
  17653. + component->control.component = component;
  17654. + spin_lock_init(&component->control.slock);
  17655. + INIT_LIST_HEAD(&component->control.buffers);
  17656. + ret = port_info_get(instance, &component->control);
  17657. + if (ret < 0)
  17658. + goto release_component;
  17659. +
  17660. + for (idx = 0; idx < component->inputs; idx++) {
  17661. + component->input[idx].type = MMAL_PORT_TYPE_INPUT;
  17662. + component->input[idx].index = idx;
  17663. + component->input[idx].component = component;
  17664. + spin_lock_init(&component->input[idx].slock);
  17665. + INIT_LIST_HEAD(&component->input[idx].buffers);
  17666. + ret = port_info_get(instance, &component->input[idx]);
  17667. + if (ret < 0)
  17668. + goto release_component;
  17669. + }
  17670. +
  17671. + for (idx = 0; idx < component->outputs; idx++) {
  17672. + component->output[idx].type = MMAL_PORT_TYPE_OUTPUT;
  17673. + component->output[idx].index = idx;
  17674. + component->output[idx].component = component;
  17675. + spin_lock_init(&component->output[idx].slock);
  17676. + INIT_LIST_HEAD(&component->output[idx].buffers);
  17677. + ret = port_info_get(instance, &component->output[idx]);
  17678. + if (ret < 0)
  17679. + goto release_component;
  17680. + }
  17681. +
  17682. + for (idx = 0; idx < component->clocks; idx++) {
  17683. + component->clock[idx].type = MMAL_PORT_TYPE_CLOCK;
  17684. + component->clock[idx].index = idx;
  17685. + component->clock[idx].component = component;
  17686. + spin_lock_init(&component->clock[idx].slock);
  17687. + INIT_LIST_HEAD(&component->clock[idx].buffers);
  17688. + ret = port_info_get(instance, &component->clock[idx]);
  17689. + if (ret < 0)
  17690. + goto release_component;
  17691. + }
  17692. +
  17693. + instance->component_idx++;
  17694. +
  17695. + *component_out = component;
  17696. +
  17697. + mutex_unlock(&instance->vchiq_mutex);
  17698. +
  17699. + return 0;
  17700. +
  17701. +release_component:
  17702. + destroy_component(instance, component);
  17703. +unlock:
  17704. + mutex_unlock(&instance->vchiq_mutex);
  17705. +
  17706. + return ret;
  17707. +}
  17708. +
  17709. +/*
  17710. + * cause a mmal component to be destroyed
  17711. + */
  17712. +int vchiq_mmal_component_finalise(struct vchiq_mmal_instance *instance,
  17713. + struct vchiq_mmal_component *component)
  17714. +{
  17715. + int ret;
  17716. +
  17717. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17718. + return -EINTR;
  17719. +
  17720. + if (component->enabled)
  17721. + ret = disable_component(instance, component);
  17722. +
  17723. + ret = destroy_component(instance, component);
  17724. +
  17725. + mutex_unlock(&instance->vchiq_mutex);
  17726. +
  17727. + return ret;
  17728. +}
  17729. +
  17730. +/*
  17731. + * cause a mmal component to be enabled
  17732. + */
  17733. +int vchiq_mmal_component_enable(struct vchiq_mmal_instance *instance,
  17734. + struct vchiq_mmal_component *component)
  17735. +{
  17736. + int ret;
  17737. +
  17738. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17739. + return -EINTR;
  17740. +
  17741. + if (component->enabled) {
  17742. + mutex_unlock(&instance->vchiq_mutex);
  17743. + return 0;
  17744. + }
  17745. +
  17746. + ret = enable_component(instance, component);
  17747. + if (ret == 0)
  17748. + component->enabled = true;
  17749. +
  17750. + mutex_unlock(&instance->vchiq_mutex);
  17751. +
  17752. + return ret;
  17753. +}
  17754. +
  17755. +/*
  17756. + * cause a mmal component to be enabled
  17757. + */
  17758. +int vchiq_mmal_component_disable(struct vchiq_mmal_instance *instance,
  17759. + struct vchiq_mmal_component *component)
  17760. +{
  17761. + int ret;
  17762. +
  17763. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17764. + return -EINTR;
  17765. +
  17766. + if (!component->enabled) {
  17767. + mutex_unlock(&instance->vchiq_mutex);
  17768. + return 0;
  17769. + }
  17770. +
  17771. + ret = disable_component(instance, component);
  17772. + if (ret == 0)
  17773. + component->enabled = false;
  17774. +
  17775. + mutex_unlock(&instance->vchiq_mutex);
  17776. +
  17777. + return ret;
  17778. +}
  17779. +
  17780. +int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
  17781. + u32 *major_out, u32 *minor_out)
  17782. +{
  17783. + int ret;
  17784. +
  17785. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17786. + return -EINTR;
  17787. +
  17788. + ret = get_version(instance, major_out, minor_out);
  17789. +
  17790. + mutex_unlock(&instance->vchiq_mutex);
  17791. +
  17792. + return ret;
  17793. +}
  17794. +
  17795. +int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance)
  17796. +{
  17797. + int status = 0;
  17798. +
  17799. + if (instance == NULL)
  17800. + return -EINVAL;
  17801. +
  17802. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17803. + return -EINTR;
  17804. +
  17805. + vchi_service_use(instance->handle);
  17806. +
  17807. + status = vchi_service_close(instance->handle);
  17808. + if (status != 0)
  17809. + pr_err("mmal-vchiq: VCHIQ close failed");
  17810. +
  17811. + mutex_unlock(&instance->vchiq_mutex);
  17812. +
  17813. + vfree(instance->bulk_scratch);
  17814. +
  17815. + kfree(instance);
  17816. +
  17817. + return status;
  17818. +}
  17819. +
  17820. +int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance)
  17821. +{
  17822. + int status;
  17823. + struct vchiq_mmal_instance *instance;
  17824. + static VCHI_CONNECTION_T *vchi_connection;
  17825. + static VCHI_INSTANCE_T vchi_instance;
  17826. + SERVICE_CREATION_T params = {
  17827. + VCHI_VERSION_EX(VC_MMAL_VER, VC_MMAL_MIN_VER),
  17828. + VC_MMAL_SERVER_NAME,
  17829. + vchi_connection,
  17830. + 0, /* rx fifo size (unused) */
  17831. + 0, /* tx fifo size (unused) */
  17832. + service_callback,
  17833. + NULL, /* service callback parameter */
  17834. + 1, /* unaligned bulk receives */
  17835. + 1, /* unaligned bulk transmits */
  17836. + 0 /* want crc check on bulk transfers */
  17837. + };
  17838. +
  17839. + /* compile time checks to ensure structure size as they are
  17840. + * directly (de)serialised from memory.
  17841. + */
  17842. +
  17843. + /* ensure the header structure has packed to the correct size */
  17844. + BUILD_BUG_ON(sizeof(struct mmal_msg_header) != 24);
  17845. +
  17846. + /* ensure message structure does not exceed maximum length */
  17847. + BUILD_BUG_ON(sizeof(struct mmal_msg) > MMAL_MSG_MAX_SIZE);
  17848. +
  17849. + /* mmal port struct is correct size */
  17850. + BUILD_BUG_ON(sizeof(struct mmal_port) != 64);
  17851. +
  17852. + /* create a vchi instance */
  17853. + status = vchi_initialise(&vchi_instance);
  17854. + if (status) {
  17855. + pr_err("Failed to initialise VCHI instance (status=%d)\n",
  17856. + status);
  17857. + return -EIO;
  17858. + }
  17859. +
  17860. + status = vchi_connect(NULL, 0, vchi_instance);
  17861. + if (status) {
  17862. + pr_err("Failed to connect VCHI instance (status=%d)\n", status);
  17863. + return -EIO;
  17864. + }
  17865. +
  17866. + instance = kmalloc(sizeof(*instance), GFP_KERNEL);
  17867. + memset(instance, 0, sizeof(*instance));
  17868. +
  17869. + mutex_init(&instance->vchiq_mutex);
  17870. + mutex_init(&instance->bulk_mutex);
  17871. +
  17872. + instance->bulk_scratch = vmalloc(PAGE_SIZE);
  17873. +
  17874. + params.callback_param = instance;
  17875. +
  17876. + status = vchi_service_open(vchi_instance, &params, &instance->handle);
  17877. + if (status) {
  17878. + pr_err("Failed to open VCHI service connection (status=%d)\n",
  17879. + status);
  17880. + goto err_close_services;
  17881. + }
  17882. +
  17883. + vchi_service_release(instance->handle);
  17884. +
  17885. + *out_instance = instance;
  17886. +
  17887. + return 0;
  17888. +
  17889. +err_close_services:
  17890. +
  17891. + vchi_service_close(instance->handle);
  17892. + vfree(instance->bulk_scratch);
  17893. + kfree(instance);
  17894. + return -ENODEV;
  17895. +}
  17896. diff -Nur linux-3.12.26.orig/drivers/media/platform/bcm2835/mmal-vchiq.h linux-3.12.26/drivers/media/platform/bcm2835/mmal-vchiq.h
  17897. --- linux-3.12.26.orig/drivers/media/platform/bcm2835/mmal-vchiq.h 1970-01-01 01:00:00.000000000 +0100
  17898. +++ linux-3.12.26/drivers/media/platform/bcm2835/mmal-vchiq.h 2014-08-06 16:50:14.401961585 +0200
  17899. @@ -0,0 +1,178 @@
  17900. +/*
  17901. + * Broadcom BM2835 V4L2 driver
  17902. + *
  17903. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  17904. + *
  17905. + * This file is subject to the terms and conditions of the GNU General Public
  17906. + * License. See the file COPYING in the main directory of this archive
  17907. + * for more details.
  17908. + *
  17909. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  17910. + * Dave Stevenson <dsteve@broadcom.com>
  17911. + * Simon Mellor <simellor@broadcom.com>
  17912. + * Luke Diamand <luked@broadcom.com>
  17913. + *
  17914. + * MMAL interface to VCHIQ message passing
  17915. + */
  17916. +
  17917. +#ifndef MMAL_VCHIQ_H
  17918. +#define MMAL_VCHIQ_H
  17919. +
  17920. +#include "mmal-msg-format.h"
  17921. +
  17922. +#define MAX_PORT_COUNT 4
  17923. +
  17924. +/* Maximum size of the format extradata. */
  17925. +#define MMAL_FORMAT_EXTRADATA_MAX_SIZE 128
  17926. +
  17927. +struct vchiq_mmal_instance;
  17928. +
  17929. +enum vchiq_mmal_es_type {
  17930. + MMAL_ES_TYPE_UNKNOWN, /**< Unknown elementary stream type */
  17931. + MMAL_ES_TYPE_CONTROL, /**< Elementary stream of control commands */
  17932. + MMAL_ES_TYPE_AUDIO, /**< Audio elementary stream */
  17933. + MMAL_ES_TYPE_VIDEO, /**< Video elementary stream */
  17934. + MMAL_ES_TYPE_SUBPICTURE /**< Sub-picture elementary stream */
  17935. +};
  17936. +
  17937. +/* rectangle, used lots so it gets its own struct */
  17938. +struct vchiq_mmal_rect {
  17939. + s32 x;
  17940. + s32 y;
  17941. + s32 width;
  17942. + s32 height;
  17943. +};
  17944. +
  17945. +struct vchiq_mmal_port_buffer {
  17946. + unsigned int num; /* number of buffers */
  17947. + u32 size; /* size of buffers */
  17948. + u32 alignment; /* alignment of buffers */
  17949. +};
  17950. +
  17951. +struct vchiq_mmal_port;
  17952. +
  17953. +typedef void (*vchiq_mmal_buffer_cb)(
  17954. + struct vchiq_mmal_instance *instance,
  17955. + struct vchiq_mmal_port *port,
  17956. + int status, struct mmal_buffer *buffer,
  17957. + unsigned long length, u32 mmal_flags, s64 dts, s64 pts);
  17958. +
  17959. +struct vchiq_mmal_port {
  17960. + bool enabled;
  17961. + u32 handle;
  17962. + u32 type; /* port type, cached to use on port info set */
  17963. + u32 index; /* port index, cached to use on port info set */
  17964. +
  17965. + /* component port belongs to, allows simple deref */
  17966. + struct vchiq_mmal_component *component;
  17967. +
  17968. + struct vchiq_mmal_port *connected; /* port conencted to */
  17969. +
  17970. + /* buffer info */
  17971. + struct vchiq_mmal_port_buffer minimum_buffer;
  17972. + struct vchiq_mmal_port_buffer recommended_buffer;
  17973. + struct vchiq_mmal_port_buffer current_buffer;
  17974. +
  17975. + /* stream format */
  17976. + struct mmal_es_format format;
  17977. + /* elementry stream format */
  17978. + union mmal_es_specific_format es;
  17979. +
  17980. + /* data buffers to fill */
  17981. + struct list_head buffers;
  17982. + /* lock to serialise adding and removing buffers from list */
  17983. + spinlock_t slock;
  17984. + /* count of how many buffer header refils have failed because
  17985. + * there was no buffer to satisfy them
  17986. + */
  17987. + int buffer_underflow;
  17988. + /* callback on buffer completion */
  17989. + vchiq_mmal_buffer_cb buffer_cb;
  17990. + /* callback context */
  17991. + void *cb_ctx;
  17992. +};
  17993. +
  17994. +struct vchiq_mmal_component {
  17995. + bool enabled;
  17996. + u32 handle; /* VideoCore handle for component */
  17997. + u32 inputs; /* Number of input ports */
  17998. + u32 outputs; /* Number of output ports */
  17999. + u32 clocks; /* Number of clock ports */
  18000. + struct vchiq_mmal_port control; /* control port */
  18001. + struct vchiq_mmal_port input[MAX_PORT_COUNT]; /* input ports */
  18002. + struct vchiq_mmal_port output[MAX_PORT_COUNT]; /* output ports */
  18003. + struct vchiq_mmal_port clock[MAX_PORT_COUNT]; /* clock ports */
  18004. +};
  18005. +
  18006. +
  18007. +int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance);
  18008. +int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance);
  18009. +
  18010. +/* Initialise a mmal component and its ports
  18011. +*
  18012. +*/
  18013. +int vchiq_mmal_component_init(
  18014. + struct vchiq_mmal_instance *instance,
  18015. + const char *name,
  18016. + struct vchiq_mmal_component **component_out);
  18017. +
  18018. +int vchiq_mmal_component_finalise(
  18019. + struct vchiq_mmal_instance *instance,
  18020. + struct vchiq_mmal_component *component);
  18021. +
  18022. +int vchiq_mmal_component_enable(
  18023. + struct vchiq_mmal_instance *instance,
  18024. + struct vchiq_mmal_component *component);
  18025. +
  18026. +int vchiq_mmal_component_disable(
  18027. + struct vchiq_mmal_instance *instance,
  18028. + struct vchiq_mmal_component *component);
  18029. +
  18030. +
  18031. +
  18032. +/* enable a mmal port
  18033. + *
  18034. + * enables a port and if a buffer callback provided enque buffer
  18035. + * headers as apropriate for the port.
  18036. + */
  18037. +int vchiq_mmal_port_enable(
  18038. + struct vchiq_mmal_instance *instance,
  18039. + struct vchiq_mmal_port *port,
  18040. + vchiq_mmal_buffer_cb buffer_cb);
  18041. +
  18042. +/* disable a port
  18043. + *
  18044. + * disable a port will dequeue any pending buffers
  18045. + */
  18046. +int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
  18047. + struct vchiq_mmal_port *port);
  18048. +
  18049. +
  18050. +int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
  18051. + struct vchiq_mmal_port *port,
  18052. + u32 parameter,
  18053. + void *value,
  18054. + u32 value_size);
  18055. +
  18056. +int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
  18057. + struct vchiq_mmal_port *port,
  18058. + u32 parameter,
  18059. + void *value,
  18060. + u32 *value_size);
  18061. +
  18062. +int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
  18063. + struct vchiq_mmal_port *port);
  18064. +
  18065. +int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
  18066. + struct vchiq_mmal_port *src,
  18067. + struct vchiq_mmal_port *dst);
  18068. +
  18069. +int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
  18070. + u32 *major_out,
  18071. + u32 *minor_out);
  18072. +
  18073. +int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
  18074. + struct vchiq_mmal_port *port,
  18075. + struct mmal_buffer *buf);
  18076. +
  18077. +#endif /* MMAL_VCHIQ_H */
  18078. diff -Nur linux-3.12.26.orig/drivers/media/platform/Kconfig linux-3.12.26/drivers/media/platform/Kconfig
  18079. --- linux-3.12.26.orig/drivers/media/platform/Kconfig 2014-07-30 18:02:44.000000000 +0200
  18080. +++ linux-3.12.26/drivers/media/platform/Kconfig 2014-08-06 16:50:14.401961585 +0200
  18081. @@ -124,6 +124,7 @@
  18082. source "drivers/media/platform/soc_camera/Kconfig"
  18083. source "drivers/media/platform/exynos4-is/Kconfig"
  18084. source "drivers/media/platform/s5p-tv/Kconfig"
  18085. +source "drivers/media/platform/bcm2835/Kconfig"
  18086. endif # V4L_PLATFORM_DRIVERS
  18087. diff -Nur linux-3.12.26.orig/drivers/media/platform/Makefile linux-3.12.26/drivers/media/platform/Makefile
  18088. --- linux-3.12.26.orig/drivers/media/platform/Makefile 2014-07-30 18:02:44.000000000 +0200
  18089. +++ linux-3.12.26/drivers/media/platform/Makefile 2014-08-06 16:50:14.405961616 +0200
  18090. @@ -52,4 +52,6 @@
  18091. obj-$(CONFIG_ARCH_OMAP) += omap/
  18092. +obj-$(CONFIG_VIDEO_BCM2835) += bcm2835/
  18093. +
  18094. ccflags-y += -I$(srctree)/drivers/media/i2c
  18095. diff -Nur linux-3.12.26.orig/drivers/media/usb/dvb-usb-v2/rtl28xxu.c linux-3.12.26/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
  18096. --- linux-3.12.26.orig/drivers/media/usb/dvb-usb-v2/rtl28xxu.c 2014-07-30 18:02:44.000000000 +0200
  18097. +++ linux-3.12.26/drivers/media/usb/dvb-usb-v2/rtl28xxu.c 2014-08-06 16:50:14.405961616 +0200
  18098. @@ -1390,6 +1390,10 @@
  18099. &rtl2832u_props, "Compro VideoMate U620F", NULL) },
  18100. { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd394,
  18101. &rtl2832u_props, "MaxMedia HU394-T", NULL) },
  18102. + { DVB_USB_DEVICE(USB_VID_GTEK, 0xb803 /*USB_PID_AUGUST_DVBT205*/,
  18103. + &rtl2832u_props, "August DVB-T 205", NULL) },
  18104. + { DVB_USB_DEVICE(USB_VID_GTEK, 0xa803 /*USB_PID_AUGUST_DVBT205*/,
  18105. + &rtl2832u_props, "August DVB-T 205", NULL) },
  18106. { DVB_USB_DEVICE(USB_VID_LEADTEK, 0x6a03,
  18107. &rtl2832u_props, "Leadtek WinFast DTV Dongle mini", NULL) },
  18108. { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_CPYTO_REDI_PC50A,
  18109. diff -Nur linux-3.12.26.orig/drivers/misc/Kconfig linux-3.12.26/drivers/misc/Kconfig
  18110. --- linux-3.12.26.orig/drivers/misc/Kconfig 2014-07-30 18:02:44.000000000 +0200
  18111. +++ linux-3.12.26/drivers/misc/Kconfig 2014-08-06 16:50:14.405961616 +0200
  18112. @@ -537,4 +537,5 @@
  18113. source "drivers/misc/altera-stapl/Kconfig"
  18114. source "drivers/misc/mei/Kconfig"
  18115. source "drivers/misc/vmw_vmci/Kconfig"
  18116. +source "drivers/misc/vc04_services/Kconfig"
  18117. endmenu
  18118. diff -Nur linux-3.12.26.orig/drivers/misc/Makefile linux-3.12.26/drivers/misc/Makefile
  18119. --- linux-3.12.26.orig/drivers/misc/Makefile 2014-07-30 18:02:44.000000000 +0200
  18120. +++ linux-3.12.26/drivers/misc/Makefile 2014-08-06 16:50:14.421961742 +0200
  18121. @@ -53,3 +53,4 @@
  18122. obj-$(CONFIG_VMWARE_VMCI) += vmw_vmci/
  18123. obj-$(CONFIG_LATTICE_ECP3_CONFIG) += lattice-ecp3-config.o
  18124. obj-$(CONFIG_SRAM) += sram.o
  18125. +obj-$(CONFIG_BCM2708_VCHIQ) += vc04_services/
  18126. diff -Nur linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchi/connections/connection.h linux-3.12.26/drivers/misc/vc04_services/interface/vchi/connections/connection.h
  18127. --- linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchi/connections/connection.h 1970-01-01 01:00:00.000000000 +0100
  18128. +++ linux-3.12.26/drivers/misc/vc04_services/interface/vchi/connections/connection.h 2014-08-06 16:50:14.425961773 +0200
  18129. @@ -0,0 +1,328 @@
  18130. +/**
  18131. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  18132. + *
  18133. + * Redistribution and use in source and binary forms, with or without
  18134. + * modification, are permitted provided that the following conditions
  18135. + * are met:
  18136. + * 1. Redistributions of source code must retain the above copyright
  18137. + * notice, this list of conditions, and the following disclaimer,
  18138. + * without modification.
  18139. + * 2. Redistributions in binary form must reproduce the above copyright
  18140. + * notice, this list of conditions and the following disclaimer in the
  18141. + * documentation and/or other materials provided with the distribution.
  18142. + * 3. The names of the above-listed copyright holders may not be used
  18143. + * to endorse or promote products derived from this software without
  18144. + * specific prior written permission.
  18145. + *
  18146. + * ALTERNATIVELY, this software may be distributed under the terms of the
  18147. + * GNU General Public License ("GPL") version 2, as published by the Free
  18148. + * Software Foundation.
  18149. + *
  18150. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  18151. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  18152. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  18153. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18154. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18155. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18156. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  18157. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  18158. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  18159. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  18160. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  18161. + */
  18162. +
  18163. +#ifndef CONNECTION_H_
  18164. +#define CONNECTION_H_
  18165. +
  18166. +#include <linux/kernel.h>
  18167. +#include <linux/types.h>
  18168. +#include <linux/semaphore.h>
  18169. +
  18170. +#include "interface/vchi/vchi_cfg_internal.h"
  18171. +#include "interface/vchi/vchi_common.h"
  18172. +#include "interface/vchi/message_drivers/message.h"
  18173. +
  18174. +/******************************************************************************
  18175. + Global defs
  18176. + *****************************************************************************/
  18177. +
  18178. +// Opaque handle for a connection / service pair
  18179. +typedef struct opaque_vchi_connection_connected_service_handle_t *VCHI_CONNECTION_SERVICE_HANDLE_T;
  18180. +
  18181. +// opaque handle to the connection state information
  18182. +typedef struct opaque_vchi_connection_info_t VCHI_CONNECTION_STATE_T;
  18183. +
  18184. +typedef struct vchi_connection_t VCHI_CONNECTION_T;
  18185. +
  18186. +
  18187. +/******************************************************************************
  18188. + API
  18189. + *****************************************************************************/
  18190. +
  18191. +// Routine to init a connection with a particular low level driver
  18192. +typedef VCHI_CONNECTION_STATE_T * (*VCHI_CONNECTION_INIT_T)( struct vchi_connection_t * connection,
  18193. + const VCHI_MESSAGE_DRIVER_T * driver );
  18194. +
  18195. +// Routine to control CRC enabling at a connection level
  18196. +typedef int32_t (*VCHI_CONNECTION_CRC_CONTROL_T)( VCHI_CONNECTION_STATE_T *state_handle,
  18197. + VCHI_CRC_CONTROL_T control );
  18198. +
  18199. +// Routine to create a service
  18200. +typedef int32_t (*VCHI_CONNECTION_SERVICE_CONNECT_T)( VCHI_CONNECTION_STATE_T *state_handle,
  18201. + int32_t service_id,
  18202. + uint32_t rx_fifo_size,
  18203. + uint32_t tx_fifo_size,
  18204. + int server,
  18205. + VCHI_CALLBACK_T callback,
  18206. + void *callback_param,
  18207. + int32_t want_crc,
  18208. + int32_t want_unaligned_bulk_rx,
  18209. + int32_t want_unaligned_bulk_tx,
  18210. + VCHI_CONNECTION_SERVICE_HANDLE_T *service_handle );
  18211. +
  18212. +// Routine to close a service
  18213. +typedef int32_t (*VCHI_CONNECTION_SERVICE_DISCONNECT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle );
  18214. +
  18215. +// Routine to queue a message
  18216. +typedef int32_t (*VCHI_CONNECTION_SERVICE_QUEUE_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  18217. + const void *data,
  18218. + uint32_t data_size,
  18219. + VCHI_FLAGS_T flags,
  18220. + void *msg_handle );
  18221. +
  18222. +// scatter-gather (vector) message queueing
  18223. +typedef int32_t (*VCHI_CONNECTION_SERVICE_QUEUE_MESSAGEV_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  18224. + VCHI_MSG_VECTOR_T *vector,
  18225. + uint32_t count,
  18226. + VCHI_FLAGS_T flags,
  18227. + void *msg_handle );
  18228. +
  18229. +// Routine to dequeue a message
  18230. +typedef int32_t (*VCHI_CONNECTION_SERVICE_DEQUEUE_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  18231. + void *data,
  18232. + uint32_t max_data_size_to_read,
  18233. + uint32_t *actual_msg_size,
  18234. + VCHI_FLAGS_T flags );
  18235. +
  18236. +// Routine to peek at a message
  18237. +typedef int32_t (*VCHI_CONNECTION_SERVICE_PEEK_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  18238. + void **data,
  18239. + uint32_t *msg_size,
  18240. + VCHI_FLAGS_T flags );
  18241. +
  18242. +// Routine to hold a message
  18243. +typedef int32_t (*VCHI_CONNECTION_SERVICE_HOLD_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  18244. + void **data,
  18245. + uint32_t *msg_size,
  18246. + VCHI_FLAGS_T flags,
  18247. + void **message_handle );
  18248. +
  18249. +// Routine to initialise a received message iterator
  18250. +typedef int32_t (*VCHI_CONNECTION_SERVICE_LOOKAHEAD_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  18251. + VCHI_MSG_ITER_T *iter,
  18252. + VCHI_FLAGS_T flags );
  18253. +
  18254. +// Routine to release a held message
  18255. +typedef int32_t (*VCHI_CONNECTION_HELD_MSG_RELEASE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  18256. + void *message_handle );
  18257. +
  18258. +// Routine to get info on a held message
  18259. +typedef int32_t (*VCHI_CONNECTION_HELD_MSG_INFO_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  18260. + void *message_handle,
  18261. + void **data,
  18262. + int32_t *msg_size,
  18263. + uint32_t *tx_timestamp,
  18264. + uint32_t *rx_timestamp );
  18265. +
  18266. +// Routine to check whether the iterator has a next message
  18267. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_HAS_NEXT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  18268. + const VCHI_MSG_ITER_T *iter );
  18269. +
  18270. +// Routine to advance the iterator
  18271. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_NEXT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  18272. + VCHI_MSG_ITER_T *iter,
  18273. + void **data,
  18274. + uint32_t *msg_size );
  18275. +
  18276. +// Routine to remove the last message returned by the iterator
  18277. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_REMOVE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  18278. + VCHI_MSG_ITER_T *iter );
  18279. +
  18280. +// Routine to hold the last message returned by the iterator
  18281. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_HOLD_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  18282. + VCHI_MSG_ITER_T *iter,
  18283. + void **msg_handle );
  18284. +
  18285. +// Routine to transmit bulk data
  18286. +typedef int32_t (*VCHI_CONNECTION_BULK_QUEUE_TRANSMIT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  18287. + const void *data_src,
  18288. + uint32_t data_size,
  18289. + VCHI_FLAGS_T flags,
  18290. + void *bulk_handle );
  18291. +
  18292. +// Routine to receive data
  18293. +typedef int32_t (*VCHI_CONNECTION_BULK_QUEUE_RECEIVE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  18294. + void *data_dst,
  18295. + uint32_t data_size,
  18296. + VCHI_FLAGS_T flags,
  18297. + void *bulk_handle );
  18298. +
  18299. +// Routine to report if a server is available
  18300. +typedef int32_t (*VCHI_CONNECTION_SERVER_PRESENT)( VCHI_CONNECTION_STATE_T *state, int32_t service_id, int32_t peer_flags );
  18301. +
  18302. +// Routine to report the number of RX slots available
  18303. +typedef int (*VCHI_CONNECTION_RX_SLOTS_AVAILABLE)( const VCHI_CONNECTION_STATE_T *state );
  18304. +
  18305. +// Routine to report the RX slot size
  18306. +typedef uint32_t (*VCHI_CONNECTION_RX_SLOT_SIZE)( const VCHI_CONNECTION_STATE_T *state );
  18307. +
  18308. +// Callback to indicate that the other side has added a buffer to the rx bulk DMA FIFO
  18309. +typedef void (*VCHI_CONNECTION_RX_BULK_BUFFER_ADDED)(VCHI_CONNECTION_STATE_T *state,
  18310. + int32_t service,
  18311. + uint32_t length,
  18312. + MESSAGE_TX_CHANNEL_T channel,
  18313. + uint32_t channel_params,
  18314. + uint32_t data_length,
  18315. + uint32_t data_offset);
  18316. +
  18317. +// Callback to inform a service that a Xon or Xoff message has been received
  18318. +typedef void (*VCHI_CONNECTION_FLOW_CONTROL)(VCHI_CONNECTION_STATE_T *state, int32_t service_id, int32_t xoff);
  18319. +
  18320. +// Callback to inform a service that a server available reply message has been received
  18321. +typedef void (*VCHI_CONNECTION_SERVER_AVAILABLE_REPLY)(VCHI_CONNECTION_STATE_T *state, int32_t service_id, uint32_t flags);
  18322. +
  18323. +// Callback to indicate that bulk auxiliary messages have arrived
  18324. +typedef void (*VCHI_CONNECTION_BULK_AUX_RECEIVED)(VCHI_CONNECTION_STATE_T *state);
  18325. +
  18326. +// Callback to indicate that bulk auxiliary messages have arrived
  18327. +typedef void (*VCHI_CONNECTION_BULK_AUX_TRANSMITTED)(VCHI_CONNECTION_STATE_T *state, void *handle);
  18328. +
  18329. +// Callback with all the connection info you require
  18330. +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);
  18331. +
  18332. +// Callback to inform of a disconnect
  18333. +typedef void (*VCHI_CONNECTION_DISCONNECT)(VCHI_CONNECTION_STATE_T *state, uint32_t flags);
  18334. +
  18335. +// Callback to inform of a power control request
  18336. +typedef void (*VCHI_CONNECTION_POWER_CONTROL)(VCHI_CONNECTION_STATE_T *state, MESSAGE_TX_CHANNEL_T channel, int32_t enable);
  18337. +
  18338. +// allocate memory suitably aligned for this connection
  18339. +typedef void * (*VCHI_BUFFER_ALLOCATE)(VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, uint32_t * length);
  18340. +
  18341. +// free memory allocated by buffer_allocate
  18342. +typedef void (*VCHI_BUFFER_FREE)(VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, void * address);
  18343. +
  18344. +
  18345. +/******************************************************************************
  18346. + System driver struct
  18347. + *****************************************************************************/
  18348. +
  18349. +struct opaque_vchi_connection_api_t
  18350. +{
  18351. + // Routine to init the connection
  18352. + VCHI_CONNECTION_INIT_T init;
  18353. +
  18354. + // Connection-level CRC control
  18355. + VCHI_CONNECTION_CRC_CONTROL_T crc_control;
  18356. +
  18357. + // Routine to connect to or create service
  18358. + VCHI_CONNECTION_SERVICE_CONNECT_T service_connect;
  18359. +
  18360. + // Routine to disconnect from a service
  18361. + VCHI_CONNECTION_SERVICE_DISCONNECT_T service_disconnect;
  18362. +
  18363. + // Routine to queue a message
  18364. + VCHI_CONNECTION_SERVICE_QUEUE_MESSAGE_T service_queue_msg;
  18365. +
  18366. + // scatter-gather (vector) message queue
  18367. + VCHI_CONNECTION_SERVICE_QUEUE_MESSAGEV_T service_queue_msgv;
  18368. +
  18369. + // Routine to dequeue a message
  18370. + VCHI_CONNECTION_SERVICE_DEQUEUE_MESSAGE_T service_dequeue_msg;
  18371. +
  18372. + // Routine to peek at a message
  18373. + VCHI_CONNECTION_SERVICE_PEEK_MESSAGE_T service_peek_msg;
  18374. +
  18375. + // Routine to hold a message
  18376. + VCHI_CONNECTION_SERVICE_HOLD_MESSAGE_T service_hold_msg;
  18377. +
  18378. + // Routine to initialise a received message iterator
  18379. + VCHI_CONNECTION_SERVICE_LOOKAHEAD_MESSAGE_T service_look_ahead_msg;
  18380. +
  18381. + // Routine to release a message
  18382. + VCHI_CONNECTION_HELD_MSG_RELEASE_T held_msg_release;
  18383. +
  18384. + // Routine to get information on a held message
  18385. + VCHI_CONNECTION_HELD_MSG_INFO_T held_msg_info;
  18386. +
  18387. + // Routine to check for next message on iterator
  18388. + VCHI_CONNECTION_MSG_ITER_HAS_NEXT_T msg_iter_has_next;
  18389. +
  18390. + // Routine to get next message on iterator
  18391. + VCHI_CONNECTION_MSG_ITER_NEXT_T msg_iter_next;
  18392. +
  18393. + // Routine to remove the last message returned by iterator
  18394. + VCHI_CONNECTION_MSG_ITER_REMOVE_T msg_iter_remove;
  18395. +
  18396. + // Routine to hold the last message returned by iterator
  18397. + VCHI_CONNECTION_MSG_ITER_HOLD_T msg_iter_hold;
  18398. +
  18399. + // Routine to transmit bulk data
  18400. + VCHI_CONNECTION_BULK_QUEUE_TRANSMIT_T bulk_queue_transmit;
  18401. +
  18402. + // Routine to receive data
  18403. + VCHI_CONNECTION_BULK_QUEUE_RECEIVE_T bulk_queue_receive;
  18404. +
  18405. + // Routine to report the available servers
  18406. + VCHI_CONNECTION_SERVER_PRESENT server_present;
  18407. +
  18408. + // Routine to report the number of RX slots available
  18409. + VCHI_CONNECTION_RX_SLOTS_AVAILABLE connection_rx_slots_available;
  18410. +
  18411. + // Routine to report the RX slot size
  18412. + VCHI_CONNECTION_RX_SLOT_SIZE connection_rx_slot_size;
  18413. +
  18414. + // Callback to indicate that the other side has added a buffer to the rx bulk DMA FIFO
  18415. + VCHI_CONNECTION_RX_BULK_BUFFER_ADDED rx_bulk_buffer_added;
  18416. +
  18417. + // Callback to inform a service that a Xon or Xoff message has been received
  18418. + VCHI_CONNECTION_FLOW_CONTROL flow_control;
  18419. +
  18420. + // Callback to inform a service that a server available reply message has been received
  18421. + VCHI_CONNECTION_SERVER_AVAILABLE_REPLY server_available_reply;
  18422. +
  18423. + // Callback to indicate that bulk auxiliary messages have arrived
  18424. + VCHI_CONNECTION_BULK_AUX_RECEIVED bulk_aux_received;
  18425. +
  18426. + // Callback to indicate that a bulk auxiliary message has been transmitted
  18427. + VCHI_CONNECTION_BULK_AUX_TRANSMITTED bulk_aux_transmitted;
  18428. +
  18429. + // Callback to provide information about the connection
  18430. + VCHI_CONNECTION_INFO connection_info;
  18431. +
  18432. + // Callback to notify that peer has requested disconnect
  18433. + VCHI_CONNECTION_DISCONNECT disconnect;
  18434. +
  18435. + // Callback to notify that peer has requested power change
  18436. + VCHI_CONNECTION_POWER_CONTROL power_control;
  18437. +
  18438. + // allocate memory suitably aligned for this connection
  18439. + VCHI_BUFFER_ALLOCATE buffer_allocate;
  18440. +
  18441. + // free memory allocated by buffer_allocate
  18442. + VCHI_BUFFER_FREE buffer_free;
  18443. +
  18444. +};
  18445. +
  18446. +struct vchi_connection_t {
  18447. + const VCHI_CONNECTION_API_T *api;
  18448. + VCHI_CONNECTION_STATE_T *state;
  18449. +#ifdef VCHI_COARSE_LOCKING
  18450. + struct semaphore sem;
  18451. +#endif
  18452. +};
  18453. +
  18454. +
  18455. +#endif /* CONNECTION_H_ */
  18456. +
  18457. +/****************************** End of file **********************************/
  18458. diff -Nur linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h linux-3.12.26/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h
  18459. --- linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h 1970-01-01 01:00:00.000000000 +0100
  18460. +++ linux-3.12.26/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h 2014-08-06 16:50:14.425961773 +0200
  18461. @@ -0,0 +1,204 @@
  18462. +/**
  18463. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  18464. + *
  18465. + * Redistribution and use in source and binary forms, with or without
  18466. + * modification, are permitted provided that the following conditions
  18467. + * are met:
  18468. + * 1. Redistributions of source code must retain the above copyright
  18469. + * notice, this list of conditions, and the following disclaimer,
  18470. + * without modification.
  18471. + * 2. Redistributions in binary form must reproduce the above copyright
  18472. + * notice, this list of conditions and the following disclaimer in the
  18473. + * documentation and/or other materials provided with the distribution.
  18474. + * 3. The names of the above-listed copyright holders may not be used
  18475. + * to endorse or promote products derived from this software without
  18476. + * specific prior written permission.
  18477. + *
  18478. + * ALTERNATIVELY, this software may be distributed under the terms of the
  18479. + * GNU General Public License ("GPL") version 2, as published by the Free
  18480. + * Software Foundation.
  18481. + *
  18482. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  18483. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  18484. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  18485. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18486. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18487. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18488. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  18489. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  18490. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  18491. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  18492. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  18493. + */
  18494. +
  18495. +#ifndef _VCHI_MESSAGE_H_
  18496. +#define _VCHI_MESSAGE_H_
  18497. +
  18498. +#include <linux/kernel.h>
  18499. +#include <linux/types.h>
  18500. +#include <linux/semaphore.h>
  18501. +
  18502. +#include "interface/vchi/vchi_cfg_internal.h"
  18503. +#include "interface/vchi/vchi_common.h"
  18504. +
  18505. +
  18506. +typedef enum message_event_type {
  18507. + MESSAGE_EVENT_NONE,
  18508. + MESSAGE_EVENT_NOP,
  18509. + MESSAGE_EVENT_MESSAGE,
  18510. + MESSAGE_EVENT_SLOT_COMPLETE,
  18511. + MESSAGE_EVENT_RX_BULK_PAUSED,
  18512. + MESSAGE_EVENT_RX_BULK_COMPLETE,
  18513. + MESSAGE_EVENT_TX_COMPLETE,
  18514. + MESSAGE_EVENT_MSG_DISCARDED
  18515. +} MESSAGE_EVENT_TYPE_T;
  18516. +
  18517. +typedef enum vchi_msg_flags
  18518. +{
  18519. + VCHI_MSG_FLAGS_NONE = 0x0,
  18520. + VCHI_MSG_FLAGS_TERMINATE_DMA = 0x1
  18521. +} VCHI_MSG_FLAGS_T;
  18522. +
  18523. +typedef enum message_tx_channel
  18524. +{
  18525. + MESSAGE_TX_CHANNEL_MESSAGE = 0,
  18526. + MESSAGE_TX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards
  18527. +} MESSAGE_TX_CHANNEL_T;
  18528. +
  18529. +// Macros used for cycling through bulk channels
  18530. +#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)
  18531. +#define MESSAGE_TX_CHANNEL_BULK_NEXT(c) (MESSAGE_TX_CHANNEL_BULK+((c)-MESSAGE_TX_CHANNEL_BULK+1)%VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION)
  18532. +
  18533. +typedef enum message_rx_channel
  18534. +{
  18535. + MESSAGE_RX_CHANNEL_MESSAGE = 0,
  18536. + MESSAGE_RX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards
  18537. +} MESSAGE_RX_CHANNEL_T;
  18538. +
  18539. +// Message receive slot information
  18540. +typedef struct rx_msg_slot_info {
  18541. +
  18542. + struct rx_msg_slot_info *next;
  18543. + //struct slot_info *prev;
  18544. +#if !defined VCHI_COARSE_LOCKING
  18545. + struct semaphore sem;
  18546. +#endif
  18547. +
  18548. + uint8_t *addr; // base address of slot
  18549. + uint32_t len; // length of slot in bytes
  18550. +
  18551. + uint32_t write_ptr; // hardware causes this to advance
  18552. + uint32_t read_ptr; // this module does the reading
  18553. + int active; // is this slot in the hardware dma fifo?
  18554. + uint32_t msgs_parsed; // count how many messages are in this slot
  18555. + uint32_t msgs_released; // how many messages have been released
  18556. + void *state; // connection state information
  18557. + uint8_t ref_count[VCHI_MAX_SERVICES_PER_CONNECTION]; // reference count for slots held by services
  18558. +} RX_MSG_SLOTINFO_T;
  18559. +
  18560. +// The message driver no longer needs to know about the fields of RX_BULK_SLOTINFO_T - sort this out.
  18561. +// In particular, it mustn't use addr and len - they're the client buffer, but the message
  18562. +// driver will be tasked with sending the aligned core section.
  18563. +typedef struct rx_bulk_slotinfo_t {
  18564. + struct rx_bulk_slotinfo_t *next;
  18565. +
  18566. + struct semaphore *blocking;
  18567. +
  18568. + // needed by DMA
  18569. + void *addr;
  18570. + uint32_t len;
  18571. +
  18572. + // needed for the callback
  18573. + void *service;
  18574. + void *handle;
  18575. + VCHI_FLAGS_T flags;
  18576. +} RX_BULK_SLOTINFO_T;
  18577. +
  18578. +
  18579. +/* ----------------------------------------------------------------------
  18580. + * each connection driver will have a pool of the following struct.
  18581. + *
  18582. + * the pool will be managed by vchi_qman_*
  18583. + * this means there will be multiple queues (single linked lists)
  18584. + * a given struct message_info will be on exactly one of these queues
  18585. + * at any one time
  18586. + * -------------------------------------------------------------------- */
  18587. +typedef struct rx_message_info {
  18588. +
  18589. + struct message_info *next;
  18590. + //struct message_info *prev;
  18591. +
  18592. + uint8_t *addr;
  18593. + uint32_t len;
  18594. + RX_MSG_SLOTINFO_T *slot; // points to whichever slot contains this message
  18595. + uint32_t tx_timestamp;
  18596. + uint32_t rx_timestamp;
  18597. +
  18598. +} RX_MESSAGE_INFO_T;
  18599. +
  18600. +typedef struct {
  18601. + MESSAGE_EVENT_TYPE_T type;
  18602. +
  18603. + struct {
  18604. + // for messages
  18605. + void *addr; // address of message
  18606. + uint16_t slot_delta; // whether this message indicated slot delta
  18607. + uint32_t len; // length of message
  18608. + RX_MSG_SLOTINFO_T *slot; // slot this message is in
  18609. + int32_t service; // service id this message is destined for
  18610. + uint32_t tx_timestamp; // timestamp from the header
  18611. + uint32_t rx_timestamp; // timestamp when we parsed it
  18612. + } message;
  18613. +
  18614. + // FIXME: cleanup slot reporting...
  18615. + RX_MSG_SLOTINFO_T *rx_msg;
  18616. + RX_BULK_SLOTINFO_T *rx_bulk;
  18617. + void *tx_handle;
  18618. + MESSAGE_TX_CHANNEL_T tx_channel;
  18619. +
  18620. +} MESSAGE_EVENT_T;
  18621. +
  18622. +
  18623. +// callbacks
  18624. +typedef void VCHI_MESSAGE_DRIVER_EVENT_CALLBACK_T( void *state );
  18625. +
  18626. +typedef struct {
  18627. + VCHI_MESSAGE_DRIVER_EVENT_CALLBACK_T *event_callback;
  18628. +} VCHI_MESSAGE_DRIVER_OPEN_T;
  18629. +
  18630. +
  18631. +// handle to this instance of message driver (as returned by ->open)
  18632. +typedef struct opaque_mhandle_t *VCHI_MDRIVER_HANDLE_T;
  18633. +
  18634. +struct opaque_vchi_message_driver_t {
  18635. + VCHI_MDRIVER_HANDLE_T *(*open)( VCHI_MESSAGE_DRIVER_OPEN_T *params, void *state );
  18636. + int32_t (*suspending)( VCHI_MDRIVER_HANDLE_T *handle );
  18637. + int32_t (*resumed)( VCHI_MDRIVER_HANDLE_T *handle );
  18638. + int32_t (*power_control)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T, int32_t enable );
  18639. + int32_t (*add_msg_rx_slot)( VCHI_MDRIVER_HANDLE_T *handle, RX_MSG_SLOTINFO_T *slot ); // rx message
  18640. + int32_t (*add_bulk_rx)( VCHI_MDRIVER_HANDLE_T *handle, void *data, uint32_t len, RX_BULK_SLOTINFO_T *slot ); // rx data (bulk)
  18641. + 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)
  18642. + void (*next_event)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_EVENT_T *event ); // get the next event from message_driver
  18643. + int32_t (*enable)( VCHI_MDRIVER_HANDLE_T *handle );
  18644. + int32_t (*form_message)( VCHI_MDRIVER_HANDLE_T *handle, int32_t service_id, VCHI_MSG_VECTOR_T *vector, uint32_t count, void
  18645. + *address, uint32_t length_avail, uint32_t max_total_length, int32_t pad_to_fill, int32_t allow_partial );
  18646. +
  18647. + int32_t (*update_message)( VCHI_MDRIVER_HANDLE_T *handle, void *dest, int16_t *slot_count );
  18648. + int32_t (*buffer_aligned)( VCHI_MDRIVER_HANDLE_T *handle, int tx, int uncached, const void *address, const uint32_t length );
  18649. + void * (*allocate_buffer)( VCHI_MDRIVER_HANDLE_T *handle, uint32_t *length );
  18650. + void (*free_buffer)( VCHI_MDRIVER_HANDLE_T *handle, void *address );
  18651. + int (*rx_slot_size)( VCHI_MDRIVER_HANDLE_T *handle, int msg_size );
  18652. + int (*tx_slot_size)( VCHI_MDRIVER_HANDLE_T *handle, int msg_size );
  18653. +
  18654. + int32_t (*tx_supports_terminate)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
  18655. + uint32_t (*tx_bulk_chunk_size)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
  18656. + int (*tx_alignment)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
  18657. + int (*rx_alignment)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_RX_CHANNEL_T channel );
  18658. + 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 );
  18659. + void (*debug)( VCHI_MDRIVER_HANDLE_T *handle );
  18660. +};
  18661. +
  18662. +
  18663. +#endif // _VCHI_MESSAGE_H_
  18664. +
  18665. +/****************************** End of file ***********************************/
  18666. diff -Nur linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h linux-3.12.26/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h
  18667. --- linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h 1970-01-01 01:00:00.000000000 +0100
  18668. +++ linux-3.12.26/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h 2014-08-06 16:50:14.425961773 +0200
  18669. @@ -0,0 +1,224 @@
  18670. +/**
  18671. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  18672. + *
  18673. + * Redistribution and use in source and binary forms, with or without
  18674. + * modification, are permitted provided that the following conditions
  18675. + * are met:
  18676. + * 1. Redistributions of source code must retain the above copyright
  18677. + * notice, this list of conditions, and the following disclaimer,
  18678. + * without modification.
  18679. + * 2. Redistributions in binary form must reproduce the above copyright
  18680. + * notice, this list of conditions and the following disclaimer in the
  18681. + * documentation and/or other materials provided with the distribution.
  18682. + * 3. The names of the above-listed copyright holders may not be used
  18683. + * to endorse or promote products derived from this software without
  18684. + * specific prior written permission.
  18685. + *
  18686. + * ALTERNATIVELY, this software may be distributed under the terms of the
  18687. + * GNU General Public License ("GPL") version 2, as published by the Free
  18688. + * Software Foundation.
  18689. + *
  18690. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  18691. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  18692. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  18693. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18694. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18695. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18696. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  18697. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  18698. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  18699. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  18700. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  18701. + */
  18702. +
  18703. +#ifndef VCHI_CFG_H_
  18704. +#define VCHI_CFG_H_
  18705. +
  18706. +/****************************************************************************************
  18707. + * Defines in this first section are part of the VCHI API and may be examined by VCHI
  18708. + * services.
  18709. + ***************************************************************************************/
  18710. +
  18711. +/* Required alignment of base addresses for bulk transfer, if unaligned transfers are not enabled */
  18712. +/* Really determined by the message driver, and should be available from a run-time call. */
  18713. +#ifndef VCHI_BULK_ALIGN
  18714. +# if __VCCOREVER__ >= 0x04000000
  18715. +# define VCHI_BULK_ALIGN 32 // Allows for the need to do cache cleans
  18716. +# else
  18717. +# define VCHI_BULK_ALIGN 16
  18718. +# endif
  18719. +#endif
  18720. +
  18721. +/* Required length multiple for bulk transfers, if unaligned transfers are not enabled */
  18722. +/* May be less than or greater than VCHI_BULK_ALIGN */
  18723. +/* Really determined by the message driver, and should be available from a run-time call. */
  18724. +#ifndef VCHI_BULK_GRANULARITY
  18725. +# if __VCCOREVER__ >= 0x04000000
  18726. +# define VCHI_BULK_GRANULARITY 32 // Allows for the need to do cache cleans
  18727. +# else
  18728. +# define VCHI_BULK_GRANULARITY 16
  18729. +# endif
  18730. +#endif
  18731. +
  18732. +/* The largest possible message to be queued with vchi_msg_queue. */
  18733. +#ifndef VCHI_MAX_MSG_SIZE
  18734. +# if defined VCHI_LOCAL_HOST_PORT
  18735. +# define VCHI_MAX_MSG_SIZE 16384 // makes file transfers fast, but should they be using bulk?
  18736. +# else
  18737. +# define VCHI_MAX_MSG_SIZE 4096 // NOTE: THIS MUST BE LARGER THAN OR EQUAL TO THE SIZE OF THE KHRONOS MERGE BUFFER!!
  18738. +# endif
  18739. +#endif
  18740. +
  18741. +/******************************************************************************************
  18742. + * Defines below are system configuration options, and should not be used by VCHI services.
  18743. + *****************************************************************************************/
  18744. +
  18745. +/* How many connections can we support? A localhost implementation uses 2 connections,
  18746. + * 1 for host-app, 1 for VMCS, and these are hooked together by a loopback MPHI VCFW
  18747. + * driver. */
  18748. +#ifndef VCHI_MAX_NUM_CONNECTIONS
  18749. +# define VCHI_MAX_NUM_CONNECTIONS 3
  18750. +#endif
  18751. +
  18752. +/* How many services can we open per connection? Extending this doesn't cost processing time, just a small
  18753. + * amount of static memory. */
  18754. +#ifndef VCHI_MAX_SERVICES_PER_CONNECTION
  18755. +# define VCHI_MAX_SERVICES_PER_CONNECTION 36
  18756. +#endif
  18757. +
  18758. +/* Adjust if using a message driver that supports more logical TX channels */
  18759. +#ifndef VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION
  18760. +# define VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION 9 // 1 MPHI + 8 CCP2 logical channels
  18761. +#endif
  18762. +
  18763. +/* Adjust if using a message driver that supports more logical RX channels */
  18764. +#ifndef VCHI_MAX_BULK_RX_CHANNELS_PER_CONNECTION
  18765. +# define VCHI_MAX_BULK_RX_CHANNELS_PER_CONNECTION 1 // 1 MPHI
  18766. +#endif
  18767. +
  18768. +/* How many receive slots do we use. This times VCHI_MAX_MSG_SIZE gives the effective
  18769. + * receive queue space, less message headers. */
  18770. +#ifndef VCHI_NUM_READ_SLOTS
  18771. +# if defined(VCHI_LOCAL_HOST_PORT)
  18772. +# define VCHI_NUM_READ_SLOTS 4
  18773. +# else
  18774. +# define VCHI_NUM_READ_SLOTS 48
  18775. +# endif
  18776. +#endif
  18777. +
  18778. +/* Do we utilise overrun facility for receive message slots? Can aid peer transmit
  18779. + * performance. Only define on VideoCore end, talking to host.
  18780. + */
  18781. +//#define VCHI_MSG_RX_OVERRUN
  18782. +
  18783. +/* How many transmit slots do we use. Generally don't need many, as the hardware driver
  18784. + * underneath VCHI will usually have its own buffering. */
  18785. +#ifndef VCHI_NUM_WRITE_SLOTS
  18786. +# define VCHI_NUM_WRITE_SLOTS 4
  18787. +#endif
  18788. +
  18789. +/* If a service has held or queued received messages in VCHI_XOFF_THRESHOLD or more slots,
  18790. + * then it's taking up too much buffer space, and the peer service will be told to stop
  18791. + * transmitting with an XOFF message. For this to be effective, the VCHI_NUM_READ_SLOTS
  18792. + * needs to be considerably bigger than VCHI_NUM_WRITE_SLOTS, or the transmit latency
  18793. + * is too high. */
  18794. +#ifndef VCHI_XOFF_THRESHOLD
  18795. +# define VCHI_XOFF_THRESHOLD (VCHI_NUM_READ_SLOTS / 2)
  18796. +#endif
  18797. +
  18798. +/* After we've sent an XOFF, the peer will be told to resume transmission once the local
  18799. + * service has dequeued/released enough messages that it's now occupying
  18800. + * VCHI_XON_THRESHOLD slots or fewer. */
  18801. +#ifndef VCHI_XON_THRESHOLD
  18802. +# define VCHI_XON_THRESHOLD (VCHI_NUM_READ_SLOTS / 4)
  18803. +#endif
  18804. +
  18805. +/* A size below which a bulk transfer omits the handshake completely and always goes
  18806. + * via the message channel, if bulk auxiliary is being sent on that service. (The user
  18807. + * can guarantee this by enabling unaligned transmits).
  18808. + * Not API. */
  18809. +#ifndef VCHI_MIN_BULK_SIZE
  18810. +# define VCHI_MIN_BULK_SIZE ( VCHI_MAX_MSG_SIZE / 2 < 4096 ? VCHI_MAX_MSG_SIZE / 2 : 4096 )
  18811. +#endif
  18812. +
  18813. +/* Maximum size of bulk transmission chunks, for each interface type. A trade-off between
  18814. + * speed and latency; the smaller the chunk size the better change of messages and other
  18815. + * bulk transmissions getting in when big bulk transfers are happening. Set to 0 to not
  18816. + * break transmissions into chunks.
  18817. + */
  18818. +#ifndef VCHI_MAX_BULK_CHUNK_SIZE_MPHI
  18819. +# define VCHI_MAX_BULK_CHUNK_SIZE_MPHI (16 * 1024)
  18820. +#endif
  18821. +
  18822. +/* NB Chunked CCP2 transmissions violate the letter of the CCP2 spec by using "JPEG8" mode
  18823. + * with multiple-line frames. Only use if the receiver can cope. */
  18824. +#ifndef VCHI_MAX_BULK_CHUNK_SIZE_CCP2
  18825. +# define VCHI_MAX_BULK_CHUNK_SIZE_CCP2 0
  18826. +#endif
  18827. +
  18828. +/* How many TX messages can we have pending in our transmit slots. Once exhausted,
  18829. + * vchi_msg_queue will be blocked. */
  18830. +#ifndef VCHI_TX_MSG_QUEUE_SIZE
  18831. +# define VCHI_TX_MSG_QUEUE_SIZE 256
  18832. +#endif
  18833. +
  18834. +/* How many RX messages can we have parsed in the receive slots. Once exhausted, parsing
  18835. + * will be suspended until older messages are dequeued/released. */
  18836. +#ifndef VCHI_RX_MSG_QUEUE_SIZE
  18837. +# define VCHI_RX_MSG_QUEUE_SIZE 256
  18838. +#endif
  18839. +
  18840. +/* Really should be able to cope if we run out of received message descriptors, by
  18841. + * suspending parsing as the comment above says, but we don't. This sweeps the issue
  18842. + * under the carpet. */
  18843. +#if VCHI_RX_MSG_QUEUE_SIZE < (VCHI_MAX_MSG_SIZE/16 + 1) * VCHI_NUM_READ_SLOTS
  18844. +# undef VCHI_RX_MSG_QUEUE_SIZE
  18845. +# define VCHI_RX_MSG_QUEUE_SIZE (VCHI_MAX_MSG_SIZE/16 + 1) * VCHI_NUM_READ_SLOTS
  18846. +#endif
  18847. +
  18848. +/* How many bulk transmits can we have pending. Once exhausted, vchi_bulk_queue_transmit
  18849. + * will be blocked. */
  18850. +#ifndef VCHI_TX_BULK_QUEUE_SIZE
  18851. +# define VCHI_TX_BULK_QUEUE_SIZE 64
  18852. +#endif
  18853. +
  18854. +/* How many bulk receives can we have pending. Once exhausted, vchi_bulk_queue_receive
  18855. + * will be blocked. */
  18856. +#ifndef VCHI_RX_BULK_QUEUE_SIZE
  18857. +# define VCHI_RX_BULK_QUEUE_SIZE 64
  18858. +#endif
  18859. +
  18860. +/* A limit on how many outstanding bulk requests we expect the peer to give us. If
  18861. + * the peer asks for more than this, VCHI will fail and assert. The number is determined
  18862. + * by the peer's hardware - it's the number of outstanding requests that can be queued
  18863. + * on all bulk channels. VC3's MPHI peripheral allows 16. */
  18864. +#ifndef VCHI_MAX_PEER_BULK_REQUESTS
  18865. +# define VCHI_MAX_PEER_BULK_REQUESTS 32
  18866. +#endif
  18867. +
  18868. +/* Define VCHI_CCP2TX_MANUAL_POWER if the host tells us when to turn the CCP2
  18869. + * transmitter on and off.
  18870. + */
  18871. +/*#define VCHI_CCP2TX_MANUAL_POWER*/
  18872. +
  18873. +#ifndef VCHI_CCP2TX_MANUAL_POWER
  18874. +
  18875. +/* Timeout (in milliseconds) for putting the CCP2TX interface into IDLE state. Set
  18876. + * negative for no IDLE.
  18877. + */
  18878. +# ifndef VCHI_CCP2TX_IDLE_TIMEOUT
  18879. +# define VCHI_CCP2TX_IDLE_TIMEOUT 5
  18880. +# endif
  18881. +
  18882. +/* Timeout (in milliseconds) for putting the CCP2TX interface into OFF state. Set
  18883. + * negative for no OFF.
  18884. + */
  18885. +# ifndef VCHI_CCP2TX_OFF_TIMEOUT
  18886. +# define VCHI_CCP2TX_OFF_TIMEOUT 1000
  18887. +# endif
  18888. +
  18889. +#endif /* VCHI_CCP2TX_MANUAL_POWER */
  18890. +
  18891. +#endif /* VCHI_CFG_H_ */
  18892. +
  18893. +/****************************** End of file **********************************/
  18894. diff -Nur linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h linux-3.12.26/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h
  18895. --- linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h 1970-01-01 01:00:00.000000000 +0100
  18896. +++ linux-3.12.26/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h 2014-08-06 16:50:14.441961899 +0200
  18897. @@ -0,0 +1,71 @@
  18898. +/**
  18899. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  18900. + *
  18901. + * Redistribution and use in source and binary forms, with or without
  18902. + * modification, are permitted provided that the following conditions
  18903. + * are met:
  18904. + * 1. Redistributions of source code must retain the above copyright
  18905. + * notice, this list of conditions, and the following disclaimer,
  18906. + * without modification.
  18907. + * 2. Redistributions in binary form must reproduce the above copyright
  18908. + * notice, this list of conditions and the following disclaimer in the
  18909. + * documentation and/or other materials provided with the distribution.
  18910. + * 3. The names of the above-listed copyright holders may not be used
  18911. + * to endorse or promote products derived from this software without
  18912. + * specific prior written permission.
  18913. + *
  18914. + * ALTERNATIVELY, this software may be distributed under the terms of the
  18915. + * GNU General Public License ("GPL") version 2, as published by the Free
  18916. + * Software Foundation.
  18917. + *
  18918. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  18919. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  18920. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  18921. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18922. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18923. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18924. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  18925. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  18926. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  18927. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  18928. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  18929. + */
  18930. +
  18931. +#ifndef VCHI_CFG_INTERNAL_H_
  18932. +#define VCHI_CFG_INTERNAL_H_
  18933. +
  18934. +/****************************************************************************************
  18935. + * Control optimisation attempts.
  18936. + ***************************************************************************************/
  18937. +
  18938. +// Don't use lots of short-term locks - use great long ones, reducing the overall locks-per-second
  18939. +#define VCHI_COARSE_LOCKING
  18940. +
  18941. +// Avoid lock then unlock on exit from blocking queue operations (msg tx, bulk rx/tx)
  18942. +// (only relevant if VCHI_COARSE_LOCKING)
  18943. +#define VCHI_ELIDE_BLOCK_EXIT_LOCK
  18944. +
  18945. +// Avoid lock on non-blocking peek
  18946. +// (only relevant if VCHI_COARSE_LOCKING)
  18947. +#define VCHI_AVOID_PEEK_LOCK
  18948. +
  18949. +// Use one slot-handler thread per connection, rather than 1 thread dealing with all connections in rotation.
  18950. +#define VCHI_MULTIPLE_HANDLER_THREADS
  18951. +
  18952. +// Put free descriptors onto the head of the free queue, rather than the tail, so that we don't thrash
  18953. +// our way through the pool of descriptors.
  18954. +#define VCHI_PUSH_FREE_DESCRIPTORS_ONTO_HEAD
  18955. +
  18956. +// Don't issue a MSG_AVAILABLE callback for every single message. Possibly only safe if VCHI_COARSE_LOCKING.
  18957. +#define VCHI_FEWER_MSG_AVAILABLE_CALLBACKS
  18958. +
  18959. +// Don't use message descriptors for TX messages that don't need them
  18960. +#define VCHI_MINIMISE_TX_MSG_DESCRIPTORS
  18961. +
  18962. +// Nano-locks for multiqueue
  18963. +//#define VCHI_MQUEUE_NANOLOCKS
  18964. +
  18965. +// Lock-free(er) dequeuing
  18966. +//#define VCHI_RX_NANOLOCKS
  18967. +
  18968. +#endif /*VCHI_CFG_INTERNAL_H_*/
  18969. diff -Nur linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchi/vchi_common.h linux-3.12.26/drivers/misc/vc04_services/interface/vchi/vchi_common.h
  18970. --- linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchi/vchi_common.h 1970-01-01 01:00:00.000000000 +0100
  18971. +++ linux-3.12.26/drivers/misc/vc04_services/interface/vchi/vchi_common.h 2014-08-06 16:50:14.445961931 +0200
  18972. @@ -0,0 +1,163 @@
  18973. +/**
  18974. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  18975. + *
  18976. + * Redistribution and use in source and binary forms, with or without
  18977. + * modification, are permitted provided that the following conditions
  18978. + * are met:
  18979. + * 1. Redistributions of source code must retain the above copyright
  18980. + * notice, this list of conditions, and the following disclaimer,
  18981. + * without modification.
  18982. + * 2. Redistributions in binary form must reproduce the above copyright
  18983. + * notice, this list of conditions and the following disclaimer in the
  18984. + * documentation and/or other materials provided with the distribution.
  18985. + * 3. The names of the above-listed copyright holders may not be used
  18986. + * to endorse or promote products derived from this software without
  18987. + * specific prior written permission.
  18988. + *
  18989. + * ALTERNATIVELY, this software may be distributed under the terms of the
  18990. + * GNU General Public License ("GPL") version 2, as published by the Free
  18991. + * Software Foundation.
  18992. + *
  18993. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  18994. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  18995. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  18996. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18997. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18998. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18999. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19000. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  19001. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  19002. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  19003. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19004. + */
  19005. +
  19006. +#ifndef VCHI_COMMON_H_
  19007. +#define VCHI_COMMON_H_
  19008. +
  19009. +
  19010. +//flags used when sending messages (must be bitmapped)
  19011. +typedef enum
  19012. +{
  19013. + VCHI_FLAGS_NONE = 0x0,
  19014. + 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)
  19015. + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE = 0x2, // run a callback when message sent
  19016. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED = 0x4, // return once the transfer is in a queue ready to go
  19017. + VCHI_FLAGS_ALLOW_PARTIAL = 0x8,
  19018. + VCHI_FLAGS_BLOCK_UNTIL_DATA_READ = 0x10,
  19019. + VCHI_FLAGS_CALLBACK_WHEN_DATA_READ = 0x20,
  19020. +
  19021. + VCHI_FLAGS_ALIGN_SLOT = 0x000080, // internal use only
  19022. + VCHI_FLAGS_BULK_AUX_QUEUED = 0x010000, // internal use only
  19023. + VCHI_FLAGS_BULK_AUX_COMPLETE = 0x020000, // internal use only
  19024. + VCHI_FLAGS_BULK_DATA_QUEUED = 0x040000, // internal use only
  19025. + VCHI_FLAGS_BULK_DATA_COMPLETE = 0x080000, // internal use only
  19026. + VCHI_FLAGS_INTERNAL = 0xFF0000
  19027. +} VCHI_FLAGS_T;
  19028. +
  19029. +// constants for vchi_crc_control()
  19030. +typedef enum {
  19031. + VCHI_CRC_NOTHING = -1,
  19032. + VCHI_CRC_PER_SERVICE = 0,
  19033. + VCHI_CRC_EVERYTHING = 1,
  19034. +} VCHI_CRC_CONTROL_T;
  19035. +
  19036. +//callback reasons when an event occurs on a service
  19037. +typedef enum
  19038. +{
  19039. + VCHI_CALLBACK_REASON_MIN,
  19040. +
  19041. + //This indicates that there is data available
  19042. + //handle is the msg id that was transmitted with the data
  19043. + // When a message is received and there was no FULL message available previously, send callback
  19044. + // Tasks get kicked by the callback, reset their event and try and read from the fifo until it fails
  19045. + VCHI_CALLBACK_MSG_AVAILABLE,
  19046. + VCHI_CALLBACK_MSG_SENT,
  19047. + VCHI_CALLBACK_MSG_SPACE_AVAILABLE, // XXX not yet implemented
  19048. +
  19049. + // This indicates that a transfer from the other side has completed
  19050. + VCHI_CALLBACK_BULK_RECEIVED,
  19051. + //This indicates that data queued up to be sent has now gone
  19052. + //handle is the msg id that was used when sending the data
  19053. + VCHI_CALLBACK_BULK_SENT,
  19054. + VCHI_CALLBACK_BULK_RX_SPACE_AVAILABLE, // XXX not yet implemented
  19055. + VCHI_CALLBACK_BULK_TX_SPACE_AVAILABLE, // XXX not yet implemented
  19056. +
  19057. + VCHI_CALLBACK_SERVICE_CLOSED,
  19058. +
  19059. + // this side has sent XOFF to peer due to lack of data consumption by service
  19060. + // (suggests the service may need to take some recovery action if it has
  19061. + // been deliberately holding off consuming data)
  19062. + VCHI_CALLBACK_SENT_XOFF,
  19063. + VCHI_CALLBACK_SENT_XON,
  19064. +
  19065. + // indicates that a bulk transfer has finished reading the source buffer
  19066. + VCHI_CALLBACK_BULK_DATA_READ,
  19067. +
  19068. + // power notification events (currently host side only)
  19069. + VCHI_CALLBACK_PEER_OFF,
  19070. + VCHI_CALLBACK_PEER_SUSPENDED,
  19071. + VCHI_CALLBACK_PEER_ON,
  19072. + VCHI_CALLBACK_PEER_RESUMED,
  19073. + VCHI_CALLBACK_FORCED_POWER_OFF,
  19074. +
  19075. +#ifdef USE_VCHIQ_ARM
  19076. + // some extra notifications provided by vchiq_arm
  19077. + VCHI_CALLBACK_SERVICE_OPENED,
  19078. + VCHI_CALLBACK_BULK_RECEIVE_ABORTED,
  19079. + VCHI_CALLBACK_BULK_TRANSMIT_ABORTED,
  19080. +#endif
  19081. +
  19082. + VCHI_CALLBACK_REASON_MAX
  19083. +} VCHI_CALLBACK_REASON_T;
  19084. +
  19085. +//Calback used by all services / bulk transfers
  19086. +typedef void (*VCHI_CALLBACK_T)( void *callback_param, //my service local param
  19087. + VCHI_CALLBACK_REASON_T reason,
  19088. + void *handle ); //for transmitting msg's only
  19089. +
  19090. +
  19091. +
  19092. +/*
  19093. + * Define vector struct for scatter-gather (vector) operations
  19094. + * Vectors can be nested - if a vector element has negative length, then
  19095. + * the data pointer is treated as pointing to another vector array, with
  19096. + * '-vec_len' elements. Thus to append a header onto an existing vector,
  19097. + * you can do this:
  19098. + *
  19099. + * void foo(const VCHI_MSG_VECTOR_T *v, int n)
  19100. + * {
  19101. + * VCHI_MSG_VECTOR_T nv[2];
  19102. + * nv[0].vec_base = my_header;
  19103. + * nv[0].vec_len = sizeof my_header;
  19104. + * nv[1].vec_base = v;
  19105. + * nv[1].vec_len = -n;
  19106. + * ...
  19107. + *
  19108. + */
  19109. +typedef struct vchi_msg_vector {
  19110. + const void *vec_base;
  19111. + int32_t vec_len;
  19112. +} VCHI_MSG_VECTOR_T;
  19113. +
  19114. +// Opaque type for a connection API
  19115. +typedef struct opaque_vchi_connection_api_t VCHI_CONNECTION_API_T;
  19116. +
  19117. +// Opaque type for a message driver
  19118. +typedef struct opaque_vchi_message_driver_t VCHI_MESSAGE_DRIVER_T;
  19119. +
  19120. +
  19121. +// Iterator structure for reading ahead through received message queue. Allocated by client,
  19122. +// initialised by vchi_msg_look_ahead. Fields are for internal VCHI use only.
  19123. +// Iterates over messages in queue at the instant of the call to vchi_msg_lookahead -
  19124. +// will not proceed to messages received since. Behaviour is undefined if an iterator
  19125. +// is used again after messages for that service are removed/dequeued by any
  19126. +// means other than vchi_msg_iter_... calls on the iterator itself.
  19127. +typedef struct {
  19128. + struct opaque_vchi_service_t *service;
  19129. + void *last;
  19130. + void *next;
  19131. + void *remove;
  19132. +} VCHI_MSG_ITER_T;
  19133. +
  19134. +
  19135. +#endif // VCHI_COMMON_H_
  19136. diff -Nur linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchi/vchi.h linux-3.12.26/drivers/misc/vc04_services/interface/vchi/vchi.h
  19137. --- linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchi/vchi.h 1970-01-01 01:00:00.000000000 +0100
  19138. +++ linux-3.12.26/drivers/misc/vc04_services/interface/vchi/vchi.h 2014-08-06 16:50:14.445961931 +0200
  19139. @@ -0,0 +1,373 @@
  19140. +/**
  19141. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  19142. + *
  19143. + * Redistribution and use in source and binary forms, with or without
  19144. + * modification, are permitted provided that the following conditions
  19145. + * are met:
  19146. + * 1. Redistributions of source code must retain the above copyright
  19147. + * notice, this list of conditions, and the following disclaimer,
  19148. + * without modification.
  19149. + * 2. Redistributions in binary form must reproduce the above copyright
  19150. + * notice, this list of conditions and the following disclaimer in the
  19151. + * documentation and/or other materials provided with the distribution.
  19152. + * 3. The names of the above-listed copyright holders may not be used
  19153. + * to endorse or promote products derived from this software without
  19154. + * specific prior written permission.
  19155. + *
  19156. + * ALTERNATIVELY, this software may be distributed under the terms of the
  19157. + * GNU General Public License ("GPL") version 2, as published by the Free
  19158. + * Software Foundation.
  19159. + *
  19160. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  19161. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  19162. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19163. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  19164. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19165. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19166. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19167. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  19168. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  19169. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  19170. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19171. + */
  19172. +
  19173. +#ifndef VCHI_H_
  19174. +#define VCHI_H_
  19175. +
  19176. +#include "interface/vchi/vchi_cfg.h"
  19177. +#include "interface/vchi/vchi_common.h"
  19178. +#include "interface/vchi/connections/connection.h"
  19179. +#include "vchi_mh.h"
  19180. +
  19181. +
  19182. +/******************************************************************************
  19183. + Global defs
  19184. + *****************************************************************************/
  19185. +
  19186. +#define VCHI_BULK_ROUND_UP(x) ((((unsigned long)(x))+VCHI_BULK_ALIGN-1) & ~(VCHI_BULK_ALIGN-1))
  19187. +#define VCHI_BULK_ROUND_DOWN(x) (((unsigned long)(x)) & ~(VCHI_BULK_ALIGN-1))
  19188. +#define VCHI_BULK_ALIGN_NBYTES(x) (VCHI_BULK_ALIGNED(x) ? 0 : (VCHI_BULK_ALIGN - ((unsigned long)(x) & (VCHI_BULK_ALIGN-1))))
  19189. +
  19190. +#ifdef USE_VCHIQ_ARM
  19191. +#define VCHI_BULK_ALIGNED(x) 1
  19192. +#else
  19193. +#define VCHI_BULK_ALIGNED(x) (((unsigned long)(x) & (VCHI_BULK_ALIGN-1)) == 0)
  19194. +#endif
  19195. +
  19196. +struct vchi_version {
  19197. + uint32_t version;
  19198. + uint32_t version_min;
  19199. +};
  19200. +#define VCHI_VERSION(v_) { v_, v_ }
  19201. +#define VCHI_VERSION_EX(v_, m_) { v_, m_ }
  19202. +
  19203. +typedef enum
  19204. +{
  19205. + VCHI_VEC_POINTER,
  19206. + VCHI_VEC_HANDLE,
  19207. + VCHI_VEC_LIST
  19208. +} VCHI_MSG_VECTOR_TYPE_T;
  19209. +
  19210. +typedef struct vchi_msg_vector_ex {
  19211. +
  19212. + VCHI_MSG_VECTOR_TYPE_T type;
  19213. + union
  19214. + {
  19215. + // a memory handle
  19216. + struct
  19217. + {
  19218. + VCHI_MEM_HANDLE_T handle;
  19219. + uint32_t offset;
  19220. + int32_t vec_len;
  19221. + } handle;
  19222. +
  19223. + // an ordinary data pointer
  19224. + struct
  19225. + {
  19226. + const void *vec_base;
  19227. + int32_t vec_len;
  19228. + } ptr;
  19229. +
  19230. + // a nested vector list
  19231. + struct
  19232. + {
  19233. + struct vchi_msg_vector_ex *vec;
  19234. + uint32_t vec_len;
  19235. + } list;
  19236. + } u;
  19237. +} VCHI_MSG_VECTOR_EX_T;
  19238. +
  19239. +
  19240. +// Construct an entry in a msg vector for a pointer (p) of length (l)
  19241. +#define VCHI_VEC_POINTER(p,l) VCHI_VEC_POINTER, { { (VCHI_MEM_HANDLE_T)(p), (l) } }
  19242. +
  19243. +// Construct an entry in a msg vector for a message handle (h), starting at offset (o) of length (l)
  19244. +#define VCHI_VEC_HANDLE(h,o,l) VCHI_VEC_HANDLE, { { (h), (o), (l) } }
  19245. +
  19246. +// Macros to manipulate 'FOURCC' values
  19247. +#define MAKE_FOURCC(x) ((int32_t)( (x[0] << 24) | (x[1] << 16) | (x[2] << 8) | x[3] ))
  19248. +#define FOURCC_TO_CHAR(x) (x >> 24) & 0xFF,(x >> 16) & 0xFF,(x >> 8) & 0xFF, x & 0xFF
  19249. +
  19250. +
  19251. +// Opaque service information
  19252. +struct opaque_vchi_service_t;
  19253. +
  19254. +// Descriptor for a held message. Allocated by client, initialised by vchi_msg_hold,
  19255. +// vchi_msg_iter_hold or vchi_msg_iter_hold_next. Fields are for internal VCHI use only.
  19256. +typedef struct
  19257. +{
  19258. + struct opaque_vchi_service_t *service;
  19259. + void *message;
  19260. +} VCHI_HELD_MSG_T;
  19261. +
  19262. +
  19263. +
  19264. +// structure used to provide the information needed to open a server or a client
  19265. +typedef struct {
  19266. + struct vchi_version version;
  19267. + int32_t service_id;
  19268. + VCHI_CONNECTION_T *connection;
  19269. + uint32_t rx_fifo_size;
  19270. + uint32_t tx_fifo_size;
  19271. + VCHI_CALLBACK_T callback;
  19272. + void *callback_param;
  19273. + /* client intends to receive bulk transfers of
  19274. + odd lengths or into unaligned buffers */
  19275. + int32_t want_unaligned_bulk_rx;
  19276. + /* client intends to transmit bulk transfers of
  19277. + odd lengths or out of unaligned buffers */
  19278. + int32_t want_unaligned_bulk_tx;
  19279. + /* client wants to check CRCs on (bulk) xfers.
  19280. + Only needs to be set at 1 end - will do both directions. */
  19281. + int32_t want_crc;
  19282. +} SERVICE_CREATION_T;
  19283. +
  19284. +// Opaque handle for a VCHI instance
  19285. +typedef struct opaque_vchi_instance_handle_t *VCHI_INSTANCE_T;
  19286. +
  19287. +// Opaque handle for a server or client
  19288. +typedef struct opaque_vchi_service_handle_t *VCHI_SERVICE_HANDLE_T;
  19289. +
  19290. +// Service registration & startup
  19291. +typedef void (*VCHI_SERVICE_INIT)(VCHI_INSTANCE_T initialise_instance, VCHI_CONNECTION_T **connections, uint32_t num_connections);
  19292. +
  19293. +typedef struct service_info_tag {
  19294. + const char * const vll_filename; /* VLL to load to start this service. This is an empty string if VLL is "static" */
  19295. + VCHI_SERVICE_INIT init; /* Service initialisation function */
  19296. + void *vll_handle; /* VLL handle; NULL when unloaded or a "static VLL" in build */
  19297. +} SERVICE_INFO_T;
  19298. +
  19299. +/******************************************************************************
  19300. + Global funcs - implementation is specific to which side you are on (local / remote)
  19301. + *****************************************************************************/
  19302. +
  19303. +#ifdef __cplusplus
  19304. +extern "C" {
  19305. +#endif
  19306. +
  19307. +extern /*@observer@*/ VCHI_CONNECTION_T * vchi_create_connection( const VCHI_CONNECTION_API_T * function_table,
  19308. + const VCHI_MESSAGE_DRIVER_T * low_level);
  19309. +
  19310. +
  19311. +// Routine used to initialise the vchi on both local + remote connections
  19312. +extern int32_t vchi_initialise( VCHI_INSTANCE_T *instance_handle );
  19313. +
  19314. +extern int32_t vchi_exit( void );
  19315. +
  19316. +extern int32_t vchi_connect( VCHI_CONNECTION_T **connections,
  19317. + const uint32_t num_connections,
  19318. + VCHI_INSTANCE_T instance_handle );
  19319. +
  19320. +//When this is called, ensure that all services have no data pending.
  19321. +//Bulk transfers can remain 'queued'
  19322. +extern int32_t vchi_disconnect( VCHI_INSTANCE_T instance_handle );
  19323. +
  19324. +// Global control over bulk CRC checking
  19325. +extern int32_t vchi_crc_control( VCHI_CONNECTION_T *connection,
  19326. + VCHI_CRC_CONTROL_T control );
  19327. +
  19328. +// helper functions
  19329. +extern void * vchi_allocate_buffer(VCHI_SERVICE_HANDLE_T handle, uint32_t *length);
  19330. +extern void vchi_free_buffer(VCHI_SERVICE_HANDLE_T handle, void *address);
  19331. +extern uint32_t vchi_current_time(VCHI_INSTANCE_T instance_handle);
  19332. +
  19333. +
  19334. +/******************************************************************************
  19335. + Global service API
  19336. + *****************************************************************************/
  19337. +// Routine to create a named service
  19338. +extern int32_t vchi_service_create( VCHI_INSTANCE_T instance_handle,
  19339. + SERVICE_CREATION_T *setup,
  19340. + VCHI_SERVICE_HANDLE_T *handle );
  19341. +
  19342. +// Routine to destory a service
  19343. +extern int32_t vchi_service_destroy( const VCHI_SERVICE_HANDLE_T handle );
  19344. +
  19345. +// Routine to open a named service
  19346. +extern int32_t vchi_service_open( VCHI_INSTANCE_T instance_handle,
  19347. + SERVICE_CREATION_T *setup,
  19348. + VCHI_SERVICE_HANDLE_T *handle);
  19349. +
  19350. +extern int32_t vchi_get_peer_version( const VCHI_SERVICE_HANDLE_T handle,
  19351. + short *peer_version );
  19352. +
  19353. +// Routine to close a named service
  19354. +extern int32_t vchi_service_close( const VCHI_SERVICE_HANDLE_T handle );
  19355. +
  19356. +// Routine to increment ref count on a named service
  19357. +extern int32_t vchi_service_use( const VCHI_SERVICE_HANDLE_T handle );
  19358. +
  19359. +// Routine to decrement ref count on a named service
  19360. +extern int32_t vchi_service_release( const VCHI_SERVICE_HANDLE_T handle );
  19361. +
  19362. +// Routine to send a message accross a service
  19363. +extern int32_t vchi_msg_queue( VCHI_SERVICE_HANDLE_T handle,
  19364. + const void *data,
  19365. + uint32_t data_size,
  19366. + VCHI_FLAGS_T flags,
  19367. + void *msg_handle );
  19368. +
  19369. +// scatter-gather (vector) and send message
  19370. +int32_t vchi_msg_queuev_ex( VCHI_SERVICE_HANDLE_T handle,
  19371. + VCHI_MSG_VECTOR_EX_T *vector,
  19372. + uint32_t count,
  19373. + VCHI_FLAGS_T flags,
  19374. + void *msg_handle );
  19375. +
  19376. +// legacy scatter-gather (vector) and send message, only handles pointers
  19377. +int32_t vchi_msg_queuev( VCHI_SERVICE_HANDLE_T handle,
  19378. + VCHI_MSG_VECTOR_T *vector,
  19379. + uint32_t count,
  19380. + VCHI_FLAGS_T flags,
  19381. + void *msg_handle );
  19382. +
  19383. +// Routine to receive a msg from a service
  19384. +// Dequeue is equivalent to hold, copy into client buffer, release
  19385. +extern int32_t vchi_msg_dequeue( VCHI_SERVICE_HANDLE_T handle,
  19386. + void *data,
  19387. + uint32_t max_data_size_to_read,
  19388. + uint32_t *actual_msg_size,
  19389. + VCHI_FLAGS_T flags );
  19390. +
  19391. +// Routine to look at a message in place.
  19392. +// The message is not dequeued, so a subsequent call to peek or dequeue
  19393. +// will return the same message.
  19394. +extern int32_t vchi_msg_peek( VCHI_SERVICE_HANDLE_T handle,
  19395. + void **data,
  19396. + uint32_t *msg_size,
  19397. + VCHI_FLAGS_T flags );
  19398. +
  19399. +// Routine to remove a message after it has been read in place with peek
  19400. +// The first message on the queue is dequeued.
  19401. +extern int32_t vchi_msg_remove( VCHI_SERVICE_HANDLE_T handle );
  19402. +
  19403. +// Routine to look at a message in place.
  19404. +// The message is dequeued, so the caller is left holding it; the descriptor is
  19405. +// filled in and must be released when the user has finished with the message.
  19406. +extern int32_t vchi_msg_hold( VCHI_SERVICE_HANDLE_T handle,
  19407. + void **data, // } may be NULL, as info can be
  19408. + uint32_t *msg_size, // } obtained from HELD_MSG_T
  19409. + VCHI_FLAGS_T flags,
  19410. + VCHI_HELD_MSG_T *message_descriptor );
  19411. +
  19412. +// Initialise an iterator to look through messages in place
  19413. +extern int32_t vchi_msg_look_ahead( VCHI_SERVICE_HANDLE_T handle,
  19414. + VCHI_MSG_ITER_T *iter,
  19415. + VCHI_FLAGS_T flags );
  19416. +
  19417. +/******************************************************************************
  19418. + Global service support API - operations on held messages and message iterators
  19419. + *****************************************************************************/
  19420. +
  19421. +// Routine to get the address of a held message
  19422. +extern void *vchi_held_msg_ptr( const VCHI_HELD_MSG_T *message );
  19423. +
  19424. +// Routine to get the size of a held message
  19425. +extern int32_t vchi_held_msg_size( const VCHI_HELD_MSG_T *message );
  19426. +
  19427. +// Routine to get the transmit timestamp as written into the header by the peer
  19428. +extern uint32_t vchi_held_msg_tx_timestamp( const VCHI_HELD_MSG_T *message );
  19429. +
  19430. +// Routine to get the reception timestamp, written as we parsed the header
  19431. +extern uint32_t vchi_held_msg_rx_timestamp( const VCHI_HELD_MSG_T *message );
  19432. +
  19433. +// Routine to release a held message after it has been processed
  19434. +extern int32_t vchi_held_msg_release( VCHI_HELD_MSG_T *message );
  19435. +
  19436. +// Indicates whether the iterator has a next message.
  19437. +extern int32_t vchi_msg_iter_has_next( const VCHI_MSG_ITER_T *iter );
  19438. +
  19439. +// Return the pointer and length for the next message and advance the iterator.
  19440. +extern int32_t vchi_msg_iter_next( VCHI_MSG_ITER_T *iter,
  19441. + void **data,
  19442. + uint32_t *msg_size );
  19443. +
  19444. +// Remove the last message returned by vchi_msg_iter_next.
  19445. +// Can only be called once after each call to vchi_msg_iter_next.
  19446. +extern int32_t vchi_msg_iter_remove( VCHI_MSG_ITER_T *iter );
  19447. +
  19448. +// Hold the last message returned by vchi_msg_iter_next.
  19449. +// Can only be called once after each call to vchi_msg_iter_next.
  19450. +extern int32_t vchi_msg_iter_hold( VCHI_MSG_ITER_T *iter,
  19451. + VCHI_HELD_MSG_T *message );
  19452. +
  19453. +// Return information for the next message, and hold it, advancing the iterator.
  19454. +extern int32_t vchi_msg_iter_hold_next( VCHI_MSG_ITER_T *iter,
  19455. + void **data, // } may be NULL
  19456. + uint32_t *msg_size, // }
  19457. + VCHI_HELD_MSG_T *message );
  19458. +
  19459. +
  19460. +/******************************************************************************
  19461. + Global bulk API
  19462. + *****************************************************************************/
  19463. +
  19464. +// Routine to prepare interface for a transfer from the other side
  19465. +extern int32_t vchi_bulk_queue_receive( VCHI_SERVICE_HANDLE_T handle,
  19466. + void *data_dst,
  19467. + uint32_t data_size,
  19468. + VCHI_FLAGS_T flags,
  19469. + void *transfer_handle );
  19470. +
  19471. +
  19472. +// Prepare interface for a transfer from the other side into relocatable memory.
  19473. +int32_t vchi_bulk_queue_receive_reloc( const VCHI_SERVICE_HANDLE_T handle,
  19474. + VCHI_MEM_HANDLE_T h_dst,
  19475. + uint32_t offset,
  19476. + uint32_t data_size,
  19477. + const VCHI_FLAGS_T flags,
  19478. + void * const bulk_handle );
  19479. +
  19480. +// Routine to queue up data ready for transfer to the other (once they have signalled they are ready)
  19481. +extern int32_t vchi_bulk_queue_transmit( VCHI_SERVICE_HANDLE_T handle,
  19482. + const void *data_src,
  19483. + uint32_t data_size,
  19484. + VCHI_FLAGS_T flags,
  19485. + void *transfer_handle );
  19486. +
  19487. +
  19488. +/******************************************************************************
  19489. + Configuration plumbing
  19490. + *****************************************************************************/
  19491. +
  19492. +// function prototypes for the different mid layers (the state info gives the different physical connections)
  19493. +extern const VCHI_CONNECTION_API_T *single_get_func_table( void );
  19494. +//extern const VCHI_CONNECTION_API_T *local_server_get_func_table( void );
  19495. +//extern const VCHI_CONNECTION_API_T *local_client_get_func_table( void );
  19496. +
  19497. +// declare all message drivers here
  19498. +const VCHI_MESSAGE_DRIVER_T *vchi_mphi_message_driver_func_table( void );
  19499. +
  19500. +#ifdef __cplusplus
  19501. +}
  19502. +#endif
  19503. +
  19504. +extern int32_t vchi_bulk_queue_transmit_reloc( VCHI_SERVICE_HANDLE_T handle,
  19505. + VCHI_MEM_HANDLE_T h_src,
  19506. + uint32_t offset,
  19507. + uint32_t data_size,
  19508. + VCHI_FLAGS_T flags,
  19509. + void *transfer_handle );
  19510. +#endif /* VCHI_H_ */
  19511. +
  19512. +/****************************** End of file **********************************/
  19513. diff -Nur linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchi/vchi_mh.h linux-3.12.26/drivers/misc/vc04_services/interface/vchi/vchi_mh.h
  19514. --- linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchi/vchi_mh.h 1970-01-01 01:00:00.000000000 +0100
  19515. +++ linux-3.12.26/drivers/misc/vc04_services/interface/vchi/vchi_mh.h 2014-08-06 16:50:14.449961962 +0200
  19516. @@ -0,0 +1,42 @@
  19517. +/**
  19518. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  19519. + *
  19520. + * Redistribution and use in source and binary forms, with or without
  19521. + * modification, are permitted provided that the following conditions
  19522. + * are met:
  19523. + * 1. Redistributions of source code must retain the above copyright
  19524. + * notice, this list of conditions, and the following disclaimer,
  19525. + * without modification.
  19526. + * 2. Redistributions in binary form must reproduce the above copyright
  19527. + * notice, this list of conditions and the following disclaimer in the
  19528. + * documentation and/or other materials provided with the distribution.
  19529. + * 3. The names of the above-listed copyright holders may not be used
  19530. + * to endorse or promote products derived from this software without
  19531. + * specific prior written permission.
  19532. + *
  19533. + * ALTERNATIVELY, this software may be distributed under the terms of the
  19534. + * GNU General Public License ("GPL") version 2, as published by the Free
  19535. + * Software Foundation.
  19536. + *
  19537. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  19538. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  19539. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19540. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  19541. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19542. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19543. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19544. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  19545. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  19546. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  19547. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19548. + */
  19549. +
  19550. +#ifndef VCHI_MH_H_
  19551. +#define VCHI_MH_H_
  19552. +
  19553. +#include <linux/types.h>
  19554. +
  19555. +typedef int32_t VCHI_MEM_HANDLE_T;
  19556. +#define VCHI_MEM_HANDLE_INVALID 0
  19557. +
  19558. +#endif
  19559. diff -Nur linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
  19560. --- linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c 1970-01-01 01:00:00.000000000 +0100
  19561. +++ linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c 2014-08-06 16:50:14.449961962 +0200
  19562. @@ -0,0 +1,561 @@
  19563. +/**
  19564. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  19565. + *
  19566. + * Redistribution and use in source and binary forms, with or without
  19567. + * modification, are permitted provided that the following conditions
  19568. + * are met:
  19569. + * 1. Redistributions of source code must retain the above copyright
  19570. + * notice, this list of conditions, and the following disclaimer,
  19571. + * without modification.
  19572. + * 2. Redistributions in binary form must reproduce the above copyright
  19573. + * notice, this list of conditions and the following disclaimer in the
  19574. + * documentation and/or other materials provided with the distribution.
  19575. + * 3. The names of the above-listed copyright holders may not be used
  19576. + * to endorse or promote products derived from this software without
  19577. + * specific prior written permission.
  19578. + *
  19579. + * ALTERNATIVELY, this software may be distributed under the terms of the
  19580. + * GNU General Public License ("GPL") version 2, as published by the Free
  19581. + * Software Foundation.
  19582. + *
  19583. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  19584. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  19585. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19586. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  19587. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19588. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19589. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19590. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  19591. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  19592. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  19593. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19594. + */
  19595. +
  19596. +#include <linux/kernel.h>
  19597. +#include <linux/types.h>
  19598. +#include <linux/errno.h>
  19599. +#include <linux/interrupt.h>
  19600. +#include <linux/irq.h>
  19601. +#include <linux/pagemap.h>
  19602. +#include <linux/dma-mapping.h>
  19603. +#include <linux/version.h>
  19604. +#include <linux/io.h>
  19605. +#include <linux/uaccess.h>
  19606. +#include <asm/pgtable.h>
  19607. +
  19608. +#include <mach/irqs.h>
  19609. +
  19610. +#include <mach/platform.h>
  19611. +#include <mach/vcio.h>
  19612. +
  19613. +#define TOTAL_SLOTS (VCHIQ_SLOT_ZERO_SLOTS + 2 * 32)
  19614. +
  19615. +#define VCHIQ_DOORBELL_IRQ IRQ_ARM_DOORBELL_0
  19616. +#define VCHIQ_ARM_ADDRESS(x) ((void *)__virt_to_bus((unsigned)x))
  19617. +
  19618. +#include "vchiq_arm.h"
  19619. +#include "vchiq_2835.h"
  19620. +#include "vchiq_connected.h"
  19621. +
  19622. +#define MAX_FRAGMENTS (VCHIQ_NUM_CURRENT_BULKS * 2)
  19623. +
  19624. +typedef struct vchiq_2835_state_struct {
  19625. + int inited;
  19626. + VCHIQ_ARM_STATE_T arm_state;
  19627. +} VCHIQ_2835_ARM_STATE_T;
  19628. +
  19629. +static char *g_slot_mem;
  19630. +static int g_slot_mem_size;
  19631. +dma_addr_t g_slot_phys;
  19632. +static FRAGMENTS_T *g_fragments_base;
  19633. +static FRAGMENTS_T *g_free_fragments;
  19634. +struct semaphore g_free_fragments_sema;
  19635. +
  19636. +extern int vchiq_arm_log_level;
  19637. +
  19638. +static DEFINE_SEMAPHORE(g_free_fragments_mutex);
  19639. +
  19640. +static irqreturn_t
  19641. +vchiq_doorbell_irq(int irq, void *dev_id);
  19642. +
  19643. +static int
  19644. +create_pagelist(char __user *buf, size_t count, unsigned short type,
  19645. + struct task_struct *task, PAGELIST_T ** ppagelist);
  19646. +
  19647. +static void
  19648. +free_pagelist(PAGELIST_T *pagelist, int actual);
  19649. +
  19650. +int __init
  19651. +vchiq_platform_init(VCHIQ_STATE_T *state)
  19652. +{
  19653. + VCHIQ_SLOT_ZERO_T *vchiq_slot_zero;
  19654. + int frag_mem_size;
  19655. + int err;
  19656. + int i;
  19657. +
  19658. + /* Allocate space for the channels in coherent memory */
  19659. + g_slot_mem_size = PAGE_ALIGN(TOTAL_SLOTS * VCHIQ_SLOT_SIZE);
  19660. + frag_mem_size = PAGE_ALIGN(sizeof(FRAGMENTS_T) * MAX_FRAGMENTS);
  19661. +
  19662. + g_slot_mem = dma_alloc_coherent(NULL, g_slot_mem_size + frag_mem_size,
  19663. + &g_slot_phys, GFP_ATOMIC);
  19664. +
  19665. + if (!g_slot_mem) {
  19666. + vchiq_log_error(vchiq_arm_log_level,
  19667. + "Unable to allocate channel memory");
  19668. + err = -ENOMEM;
  19669. + goto failed_alloc;
  19670. + }
  19671. +
  19672. + WARN_ON(((int)g_slot_mem & (PAGE_SIZE - 1)) != 0);
  19673. +
  19674. + vchiq_slot_zero = vchiq_init_slots(g_slot_mem, g_slot_mem_size);
  19675. + if (!vchiq_slot_zero) {
  19676. + err = -EINVAL;
  19677. + goto failed_init_slots;
  19678. + }
  19679. +
  19680. + vchiq_slot_zero->platform_data[VCHIQ_PLATFORM_FRAGMENTS_OFFSET_IDX] =
  19681. + (int)g_slot_phys + g_slot_mem_size;
  19682. + vchiq_slot_zero->platform_data[VCHIQ_PLATFORM_FRAGMENTS_COUNT_IDX] =
  19683. + MAX_FRAGMENTS;
  19684. +
  19685. + g_fragments_base = (FRAGMENTS_T *)(g_slot_mem + g_slot_mem_size);
  19686. + g_slot_mem_size += frag_mem_size;
  19687. +
  19688. + g_free_fragments = g_fragments_base;
  19689. + for (i = 0; i < (MAX_FRAGMENTS - 1); i++) {
  19690. + *(FRAGMENTS_T **)&g_fragments_base[i] =
  19691. + &g_fragments_base[i + 1];
  19692. + }
  19693. + *(FRAGMENTS_T **)&g_fragments_base[i] = NULL;
  19694. + sema_init(&g_free_fragments_sema, MAX_FRAGMENTS);
  19695. +
  19696. + if (vchiq_init_state(state, vchiq_slot_zero, 0/*slave*/) !=
  19697. + VCHIQ_SUCCESS) {
  19698. + err = -EINVAL;
  19699. + goto failed_vchiq_init;
  19700. + }
  19701. +
  19702. + err = request_irq(VCHIQ_DOORBELL_IRQ, vchiq_doorbell_irq,
  19703. + IRQF_IRQPOLL, "VCHIQ doorbell",
  19704. + state);
  19705. + if (err < 0) {
  19706. + vchiq_log_error(vchiq_arm_log_level, "%s: failed to register "
  19707. + "irq=%d err=%d", __func__,
  19708. + VCHIQ_DOORBELL_IRQ, err);
  19709. + goto failed_request_irq;
  19710. + }
  19711. +
  19712. + /* Send the base address of the slots to VideoCore */
  19713. +
  19714. + dsb(); /* Ensure all writes have completed */
  19715. +
  19716. + bcm_mailbox_write(MBOX_CHAN_VCHIQ, (unsigned int)g_slot_phys);
  19717. +
  19718. + vchiq_log_info(vchiq_arm_log_level,
  19719. + "vchiq_init - done (slots %x, phys %x)",
  19720. + (unsigned int)vchiq_slot_zero, g_slot_phys);
  19721. +
  19722. + vchiq_call_connected_callbacks();
  19723. +
  19724. + return 0;
  19725. +
  19726. +failed_request_irq:
  19727. +failed_vchiq_init:
  19728. +failed_init_slots:
  19729. + dma_free_coherent(NULL, g_slot_mem_size, g_slot_mem, g_slot_phys);
  19730. +
  19731. +failed_alloc:
  19732. + return err;
  19733. +}
  19734. +
  19735. +void __exit
  19736. +vchiq_platform_exit(VCHIQ_STATE_T *state)
  19737. +{
  19738. + free_irq(VCHIQ_DOORBELL_IRQ, state);
  19739. + dma_free_coherent(NULL, g_slot_mem_size,
  19740. + g_slot_mem, g_slot_phys);
  19741. +}
  19742. +
  19743. +
  19744. +VCHIQ_STATUS_T
  19745. +vchiq_platform_init_state(VCHIQ_STATE_T *state)
  19746. +{
  19747. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  19748. + state->platform_state = kzalloc(sizeof(VCHIQ_2835_ARM_STATE_T), GFP_KERNEL);
  19749. + ((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited = 1;
  19750. + status = vchiq_arm_init_state(state, &((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->arm_state);
  19751. + if(status != VCHIQ_SUCCESS)
  19752. + {
  19753. + ((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited = 0;
  19754. + }
  19755. + return status;
  19756. +}
  19757. +
  19758. +VCHIQ_ARM_STATE_T*
  19759. +vchiq_platform_get_arm_state(VCHIQ_STATE_T *state)
  19760. +{
  19761. + if(!((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited)
  19762. + {
  19763. + BUG();
  19764. + }
  19765. + return &((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->arm_state;
  19766. +}
  19767. +
  19768. +void
  19769. +remote_event_signal(REMOTE_EVENT_T *event)
  19770. +{
  19771. + wmb();
  19772. +
  19773. + event->fired = 1;
  19774. +
  19775. + dsb(); /* data barrier operation */
  19776. +
  19777. + if (event->armed) {
  19778. + /* trigger vc interrupt */
  19779. +
  19780. + writel(0, __io_address(ARM_0_BELL2));
  19781. + }
  19782. +}
  19783. +
  19784. +int
  19785. +vchiq_copy_from_user(void *dst, const void *src, int size)
  19786. +{
  19787. + if ((uint32_t)src < TASK_SIZE) {
  19788. + return copy_from_user(dst, src, size);
  19789. + } else {
  19790. + memcpy(dst, src, size);
  19791. + return 0;
  19792. + }
  19793. +}
  19794. +
  19795. +VCHIQ_STATUS_T
  19796. +vchiq_prepare_bulk_data(VCHIQ_BULK_T *bulk, VCHI_MEM_HANDLE_T memhandle,
  19797. + void *offset, int size, int dir)
  19798. +{
  19799. + PAGELIST_T *pagelist;
  19800. + int ret;
  19801. +
  19802. + WARN_ON(memhandle != VCHI_MEM_HANDLE_INVALID);
  19803. +
  19804. + ret = create_pagelist((char __user *)offset, size,
  19805. + (dir == VCHIQ_BULK_RECEIVE)
  19806. + ? PAGELIST_READ
  19807. + : PAGELIST_WRITE,
  19808. + current,
  19809. + &pagelist);
  19810. + if (ret != 0)
  19811. + return VCHIQ_ERROR;
  19812. +
  19813. + bulk->handle = memhandle;
  19814. + bulk->data = VCHIQ_ARM_ADDRESS(pagelist);
  19815. +
  19816. + /* Store the pagelist address in remote_data, which isn't used by the
  19817. + slave. */
  19818. + bulk->remote_data = pagelist;
  19819. +
  19820. + return VCHIQ_SUCCESS;
  19821. +}
  19822. +
  19823. +void
  19824. +vchiq_complete_bulk(VCHIQ_BULK_T *bulk)
  19825. +{
  19826. + if (bulk && bulk->remote_data && bulk->actual)
  19827. + free_pagelist((PAGELIST_T *)bulk->remote_data, bulk->actual);
  19828. +}
  19829. +
  19830. +void
  19831. +vchiq_transfer_bulk(VCHIQ_BULK_T *bulk)
  19832. +{
  19833. + /*
  19834. + * This should only be called on the master (VideoCore) side, but
  19835. + * provide an implementation to avoid the need for ifdefery.
  19836. + */
  19837. + BUG();
  19838. +}
  19839. +
  19840. +void
  19841. +vchiq_dump_platform_state(void *dump_context)
  19842. +{
  19843. + char buf[80];
  19844. + int len;
  19845. + len = snprintf(buf, sizeof(buf),
  19846. + " Platform: 2835 (VC master)");
  19847. + vchiq_dump(dump_context, buf, len + 1);
  19848. +}
  19849. +
  19850. +VCHIQ_STATUS_T
  19851. +vchiq_platform_suspend(VCHIQ_STATE_T *state)
  19852. +{
  19853. + return VCHIQ_ERROR;
  19854. +}
  19855. +
  19856. +VCHIQ_STATUS_T
  19857. +vchiq_platform_resume(VCHIQ_STATE_T *state)
  19858. +{
  19859. + return VCHIQ_SUCCESS;
  19860. +}
  19861. +
  19862. +void
  19863. +vchiq_platform_paused(VCHIQ_STATE_T *state)
  19864. +{
  19865. +}
  19866. +
  19867. +void
  19868. +vchiq_platform_resumed(VCHIQ_STATE_T *state)
  19869. +{
  19870. +}
  19871. +
  19872. +int
  19873. +vchiq_platform_videocore_wanted(VCHIQ_STATE_T* state)
  19874. +{
  19875. + return 1; // autosuspend not supported - videocore always wanted
  19876. +}
  19877. +
  19878. +int
  19879. +vchiq_platform_use_suspend_timer(void)
  19880. +{
  19881. + return 0;
  19882. +}
  19883. +void
  19884. +vchiq_dump_platform_use_state(VCHIQ_STATE_T *state)
  19885. +{
  19886. + vchiq_log_info((vchiq_arm_log_level>=VCHIQ_LOG_INFO),"Suspend timer not in use");
  19887. +}
  19888. +void
  19889. +vchiq_platform_handle_timeout(VCHIQ_STATE_T *state)
  19890. +{
  19891. + (void)state;
  19892. +}
  19893. +/*
  19894. + * Local functions
  19895. + */
  19896. +
  19897. +static irqreturn_t
  19898. +vchiq_doorbell_irq(int irq, void *dev_id)
  19899. +{
  19900. + VCHIQ_STATE_T *state = dev_id;
  19901. + irqreturn_t ret = IRQ_NONE;
  19902. + unsigned int status;
  19903. +
  19904. + /* Read (and clear) the doorbell */
  19905. + status = readl(__io_address(ARM_0_BELL0));
  19906. +
  19907. + if (status & 0x4) { /* Was the doorbell rung? */
  19908. + remote_event_pollall(state);
  19909. + ret = IRQ_HANDLED;
  19910. + }
  19911. +
  19912. + return ret;
  19913. +}
  19914. +
  19915. +/* There is a potential problem with partial cache lines (pages?)
  19916. +** at the ends of the block when reading. If the CPU accessed anything in
  19917. +** the same line (page?) then it may have pulled old data into the cache,
  19918. +** obscuring the new data underneath. We can solve this by transferring the
  19919. +** partial cache lines separately, and allowing the ARM to copy into the
  19920. +** cached area.
  19921. +
  19922. +** N.B. This implementation plays slightly fast and loose with the Linux
  19923. +** driver programming rules, e.g. its use of __virt_to_bus instead of
  19924. +** dma_map_single, but it isn't a multi-platform driver and it benefits
  19925. +** from increased speed as a result.
  19926. +*/
  19927. +
  19928. +static int
  19929. +create_pagelist(char __user *buf, size_t count, unsigned short type,
  19930. + struct task_struct *task, PAGELIST_T ** ppagelist)
  19931. +{
  19932. + PAGELIST_T *pagelist;
  19933. + struct page **pages;
  19934. + struct page *page;
  19935. + unsigned long *addrs;
  19936. + unsigned int num_pages, offset, i;
  19937. + char *addr, *base_addr, *next_addr;
  19938. + int run, addridx, actual_pages;
  19939. + unsigned long *need_release;
  19940. +
  19941. + offset = (unsigned int)buf & (PAGE_SIZE - 1);
  19942. + num_pages = (count + offset + PAGE_SIZE - 1) / PAGE_SIZE;
  19943. +
  19944. + *ppagelist = NULL;
  19945. +
  19946. + /* Allocate enough storage to hold the page pointers and the page
  19947. + ** list
  19948. + */
  19949. + pagelist = kmalloc(sizeof(PAGELIST_T) +
  19950. + (num_pages * sizeof(unsigned long)) +
  19951. + sizeof(unsigned long) +
  19952. + (num_pages * sizeof(pages[0])),
  19953. + GFP_KERNEL);
  19954. +
  19955. + vchiq_log_trace(vchiq_arm_log_level,
  19956. + "create_pagelist - %x", (unsigned int)pagelist);
  19957. + if (!pagelist)
  19958. + return -ENOMEM;
  19959. +
  19960. + addrs = pagelist->addrs;
  19961. + need_release = (unsigned long *)(addrs + num_pages);
  19962. + pages = (struct page **)(addrs + num_pages + 1);
  19963. +
  19964. + if (is_vmalloc_addr(buf)) {
  19965. + for (actual_pages = 0; actual_pages < num_pages; actual_pages++) {
  19966. + pages[actual_pages] = vmalloc_to_page(buf + (actual_pages * PAGE_SIZE));
  19967. + }
  19968. + *need_release = 0; /* do not try and release vmalloc pages */
  19969. + } else {
  19970. + down_read(&task->mm->mmap_sem);
  19971. + actual_pages = get_user_pages(task, task->mm,
  19972. + (unsigned long)buf & ~(PAGE_SIZE - 1),
  19973. + num_pages,
  19974. + (type == PAGELIST_READ) /*Write */ ,
  19975. + 0 /*Force */ ,
  19976. + pages,
  19977. + NULL /*vmas */);
  19978. + up_read(&task->mm->mmap_sem);
  19979. +
  19980. + if (actual_pages != num_pages) {
  19981. + vchiq_log_info(vchiq_arm_log_level,
  19982. + "create_pagelist - only %d/%d pages locked",
  19983. + actual_pages,
  19984. + num_pages);
  19985. +
  19986. + /* This is probably due to the process being killed */
  19987. + while (actual_pages > 0)
  19988. + {
  19989. + actual_pages--;
  19990. + page_cache_release(pages[actual_pages]);
  19991. + }
  19992. + kfree(pagelist);
  19993. + if (actual_pages == 0)
  19994. + actual_pages = -ENOMEM;
  19995. + return actual_pages;
  19996. + }
  19997. + *need_release = 1; /* release user pages */
  19998. + }
  19999. +
  20000. + pagelist->length = count;
  20001. + pagelist->type = type;
  20002. + pagelist->offset = offset;
  20003. +
  20004. + /* Group the pages into runs of contiguous pages */
  20005. +
  20006. + base_addr = VCHIQ_ARM_ADDRESS(page_address(pages[0]));
  20007. + next_addr = base_addr + PAGE_SIZE;
  20008. + addridx = 0;
  20009. + run = 0;
  20010. +
  20011. + for (i = 1; i < num_pages; i++) {
  20012. + addr = VCHIQ_ARM_ADDRESS(page_address(pages[i]));
  20013. + if ((addr == next_addr) && (run < (PAGE_SIZE - 1))) {
  20014. + next_addr += PAGE_SIZE;
  20015. + run++;
  20016. + } else {
  20017. + addrs[addridx] = (unsigned long)base_addr + run;
  20018. + addridx++;
  20019. + base_addr = addr;
  20020. + next_addr = addr + PAGE_SIZE;
  20021. + run = 0;
  20022. + }
  20023. + }
  20024. +
  20025. + addrs[addridx] = (unsigned long)base_addr + run;
  20026. + addridx++;
  20027. +
  20028. + /* Partial cache lines (fragments) require special measures */
  20029. + if ((type == PAGELIST_READ) &&
  20030. + ((pagelist->offset & (CACHE_LINE_SIZE - 1)) ||
  20031. + ((pagelist->offset + pagelist->length) &
  20032. + (CACHE_LINE_SIZE - 1)))) {
  20033. + FRAGMENTS_T *fragments;
  20034. +
  20035. + if (down_interruptible(&g_free_fragments_sema) != 0) {
  20036. + kfree(pagelist);
  20037. + return -EINTR;
  20038. + }
  20039. +
  20040. + WARN_ON(g_free_fragments == NULL);
  20041. +
  20042. + down(&g_free_fragments_mutex);
  20043. + fragments = (FRAGMENTS_T *) g_free_fragments;
  20044. + WARN_ON(fragments == NULL);
  20045. + g_free_fragments = *(FRAGMENTS_T **) g_free_fragments;
  20046. + up(&g_free_fragments_mutex);
  20047. + pagelist->type =
  20048. + PAGELIST_READ_WITH_FRAGMENTS + (fragments -
  20049. + g_fragments_base);
  20050. + }
  20051. +
  20052. + for (page = virt_to_page(pagelist);
  20053. + page <= virt_to_page(addrs + num_pages - 1); page++) {
  20054. + flush_dcache_page(page);
  20055. + }
  20056. +
  20057. + *ppagelist = pagelist;
  20058. +
  20059. + return 0;
  20060. +}
  20061. +
  20062. +static void
  20063. +free_pagelist(PAGELIST_T *pagelist, int actual)
  20064. +{
  20065. + unsigned long *need_release;
  20066. + struct page **pages;
  20067. + unsigned int num_pages, i;
  20068. +
  20069. + vchiq_log_trace(vchiq_arm_log_level,
  20070. + "free_pagelist - %x, %d", (unsigned int)pagelist, actual);
  20071. +
  20072. + num_pages =
  20073. + (pagelist->length + pagelist->offset + PAGE_SIZE - 1) /
  20074. + PAGE_SIZE;
  20075. +
  20076. + need_release = (unsigned long *)(pagelist->addrs + num_pages);
  20077. + pages = (struct page **)(pagelist->addrs + num_pages + 1);
  20078. +
  20079. + /* Deal with any partial cache lines (fragments) */
  20080. + if (pagelist->type >= PAGELIST_READ_WITH_FRAGMENTS) {
  20081. + FRAGMENTS_T *fragments = g_fragments_base +
  20082. + (pagelist->type - PAGELIST_READ_WITH_FRAGMENTS);
  20083. + int head_bytes, tail_bytes;
  20084. + head_bytes = (CACHE_LINE_SIZE - pagelist->offset) &
  20085. + (CACHE_LINE_SIZE - 1);
  20086. + tail_bytes = (pagelist->offset + actual) &
  20087. + (CACHE_LINE_SIZE - 1);
  20088. +
  20089. + if ((actual >= 0) && (head_bytes != 0)) {
  20090. + if (head_bytes > actual)
  20091. + head_bytes = actual;
  20092. +
  20093. + memcpy((char *)page_address(pages[0]) +
  20094. + pagelist->offset,
  20095. + fragments->headbuf,
  20096. + head_bytes);
  20097. + }
  20098. + if ((actual >= 0) && (head_bytes < actual) &&
  20099. + (tail_bytes != 0)) {
  20100. + memcpy((char *)page_address(pages[num_pages - 1]) +
  20101. + ((pagelist->offset + actual) &
  20102. + (PAGE_SIZE - 1) & ~(CACHE_LINE_SIZE - 1)),
  20103. + fragments->tailbuf, tail_bytes);
  20104. + }
  20105. +
  20106. + down(&g_free_fragments_mutex);
  20107. + *(FRAGMENTS_T **) fragments = g_free_fragments;
  20108. + g_free_fragments = fragments;
  20109. + up(&g_free_fragments_mutex);
  20110. + up(&g_free_fragments_sema);
  20111. + }
  20112. +
  20113. + if (*need_release) {
  20114. + for (i = 0; i < num_pages; i++) {
  20115. + if (pagelist->type != PAGELIST_WRITE)
  20116. + set_page_dirty(pages[i]);
  20117. +
  20118. + page_cache_release(pages[i]);
  20119. + }
  20120. + }
  20121. +
  20122. + kfree(pagelist);
  20123. +}
  20124. diff -Nur linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h
  20125. --- linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h 1970-01-01 01:00:00.000000000 +0100
  20126. +++ linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h 2014-08-06 16:50:14.449961962 +0200
  20127. @@ -0,0 +1,42 @@
  20128. +/**
  20129. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  20130. + *
  20131. + * Redistribution and use in source and binary forms, with or without
  20132. + * modification, are permitted provided that the following conditions
  20133. + * are met:
  20134. + * 1. Redistributions of source code must retain the above copyright
  20135. + * notice, this list of conditions, and the following disclaimer,
  20136. + * without modification.
  20137. + * 2. Redistributions in binary form must reproduce the above copyright
  20138. + * notice, this list of conditions and the following disclaimer in the
  20139. + * documentation and/or other materials provided with the distribution.
  20140. + * 3. The names of the above-listed copyright holders may not be used
  20141. + * to endorse or promote products derived from this software without
  20142. + * specific prior written permission.
  20143. + *
  20144. + * ALTERNATIVELY, this software may be distributed under the terms of the
  20145. + * GNU General Public License ("GPL") version 2, as published by the Free
  20146. + * Software Foundation.
  20147. + *
  20148. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  20149. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  20150. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20151. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  20152. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  20153. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20154. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20155. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  20156. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  20157. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  20158. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20159. + */
  20160. +
  20161. +#ifndef VCHIQ_2835_H
  20162. +#define VCHIQ_2835_H
  20163. +
  20164. +#include "vchiq_pagelist.h"
  20165. +
  20166. +#define VCHIQ_PLATFORM_FRAGMENTS_OFFSET_IDX 0
  20167. +#define VCHIQ_PLATFORM_FRAGMENTS_COUNT_IDX 1
  20168. +
  20169. +#endif /* VCHIQ_2835_H */
  20170. diff -Nur linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c
  20171. --- linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c 1970-01-01 01:00:00.000000000 +0100
  20172. +++ linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c 2014-08-06 16:50:14.449961962 +0200
  20173. @@ -0,0 +1,2813 @@
  20174. +/**
  20175. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  20176. + *
  20177. + * Redistribution and use in source and binary forms, with or without
  20178. + * modification, are permitted provided that the following conditions
  20179. + * are met:
  20180. + * 1. Redistributions of source code must retain the above copyright
  20181. + * notice, this list of conditions, and the following disclaimer,
  20182. + * without modification.
  20183. + * 2. Redistributions in binary form must reproduce the above copyright
  20184. + * notice, this list of conditions and the following disclaimer in the
  20185. + * documentation and/or other materials provided with the distribution.
  20186. + * 3. The names of the above-listed copyright holders may not be used
  20187. + * to endorse or promote products derived from this software without
  20188. + * specific prior written permission.
  20189. + *
  20190. + * ALTERNATIVELY, this software may be distributed under the terms of the
  20191. + * GNU General Public License ("GPL") version 2, as published by the Free
  20192. + * Software Foundation.
  20193. + *
  20194. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  20195. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  20196. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20197. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  20198. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  20199. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20200. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20201. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  20202. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  20203. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  20204. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20205. + */
  20206. +
  20207. +#include <linux/kernel.h>
  20208. +#include <linux/module.h>
  20209. +#include <linux/types.h>
  20210. +#include <linux/errno.h>
  20211. +#include <linux/cdev.h>
  20212. +#include <linux/fs.h>
  20213. +#include <linux/device.h>
  20214. +#include <linux/mm.h>
  20215. +#include <linux/highmem.h>
  20216. +#include <linux/pagemap.h>
  20217. +#include <linux/bug.h>
  20218. +#include <linux/semaphore.h>
  20219. +#include <linux/list.h>
  20220. +#include <linux/proc_fs.h>
  20221. +
  20222. +#include "vchiq_core.h"
  20223. +#include "vchiq_ioctl.h"
  20224. +#include "vchiq_arm.h"
  20225. +
  20226. +#define DEVICE_NAME "vchiq"
  20227. +
  20228. +/* Override the default prefix, which would be vchiq_arm (from the filename) */
  20229. +#undef MODULE_PARAM_PREFIX
  20230. +#define MODULE_PARAM_PREFIX DEVICE_NAME "."
  20231. +
  20232. +#define VCHIQ_MINOR 0
  20233. +
  20234. +/* Some per-instance constants */
  20235. +#define MAX_COMPLETIONS 16
  20236. +#define MAX_SERVICES 64
  20237. +#define MAX_ELEMENTS 8
  20238. +#define MSG_QUEUE_SIZE 64
  20239. +
  20240. +#define KEEPALIVE_VER 1
  20241. +#define KEEPALIVE_VER_MIN KEEPALIVE_VER
  20242. +
  20243. +/* Run time control of log level, based on KERN_XXX level. */
  20244. +int vchiq_arm_log_level = VCHIQ_LOG_DEFAULT;
  20245. +int vchiq_susp_log_level = VCHIQ_LOG_ERROR;
  20246. +
  20247. +#define SUSPEND_TIMER_TIMEOUT_MS 100
  20248. +#define SUSPEND_RETRY_TIMER_TIMEOUT_MS 1000
  20249. +
  20250. +#define VC_SUSPEND_NUM_OFFSET 3 /* number of values before idle which are -ve */
  20251. +static const char *const suspend_state_names[] = {
  20252. + "VC_SUSPEND_FORCE_CANCELED",
  20253. + "VC_SUSPEND_REJECTED",
  20254. + "VC_SUSPEND_FAILED",
  20255. + "VC_SUSPEND_IDLE",
  20256. + "VC_SUSPEND_REQUESTED",
  20257. + "VC_SUSPEND_IN_PROGRESS",
  20258. + "VC_SUSPEND_SUSPENDED"
  20259. +};
  20260. +#define VC_RESUME_NUM_OFFSET 1 /* number of values before idle which are -ve */
  20261. +static const char *const resume_state_names[] = {
  20262. + "VC_RESUME_FAILED",
  20263. + "VC_RESUME_IDLE",
  20264. + "VC_RESUME_REQUESTED",
  20265. + "VC_RESUME_IN_PROGRESS",
  20266. + "VC_RESUME_RESUMED"
  20267. +};
  20268. +/* The number of times we allow force suspend to timeout before actually
  20269. +** _forcing_ suspend. This is to cater for SW which fails to release vchiq
  20270. +** correctly - we don't want to prevent ARM suspend indefinitely in this case.
  20271. +*/
  20272. +#define FORCE_SUSPEND_FAIL_MAX 8
  20273. +
  20274. +/* The time in ms allowed for videocore to go idle when force suspend has been
  20275. + * requested */
  20276. +#define FORCE_SUSPEND_TIMEOUT_MS 200
  20277. +
  20278. +
  20279. +static void suspend_timer_callback(unsigned long context);
  20280. +static int vchiq_proc_add_instance(VCHIQ_INSTANCE_T instance);
  20281. +static void vchiq_proc_remove_instance(VCHIQ_INSTANCE_T instance);
  20282. +
  20283. +
  20284. +typedef struct user_service_struct {
  20285. + VCHIQ_SERVICE_T *service;
  20286. + void *userdata;
  20287. + VCHIQ_INSTANCE_T instance;
  20288. + int is_vchi;
  20289. + int dequeue_pending;
  20290. + int message_available_pos;
  20291. + int msg_insert;
  20292. + int msg_remove;
  20293. + struct semaphore insert_event;
  20294. + struct semaphore remove_event;
  20295. + VCHIQ_HEADER_T * msg_queue[MSG_QUEUE_SIZE];
  20296. +} USER_SERVICE_T;
  20297. +
  20298. +struct bulk_waiter_node {
  20299. + struct bulk_waiter bulk_waiter;
  20300. + int pid;
  20301. + struct list_head list;
  20302. +};
  20303. +
  20304. +struct vchiq_instance_struct {
  20305. + VCHIQ_STATE_T *state;
  20306. + VCHIQ_COMPLETION_DATA_T completions[MAX_COMPLETIONS];
  20307. + int completion_insert;
  20308. + int completion_remove;
  20309. + struct semaphore insert_event;
  20310. + struct semaphore remove_event;
  20311. + struct mutex completion_mutex;
  20312. +
  20313. + int connected;
  20314. + int closing;
  20315. + int pid;
  20316. + int mark;
  20317. +
  20318. + struct list_head bulk_waiter_list;
  20319. + struct mutex bulk_waiter_list_mutex;
  20320. +
  20321. + struct proc_dir_entry *proc_entry;
  20322. +};
  20323. +
  20324. +typedef struct dump_context_struct {
  20325. + char __user *buf;
  20326. + size_t actual;
  20327. + size_t space;
  20328. + loff_t offset;
  20329. +} DUMP_CONTEXT_T;
  20330. +
  20331. +static struct cdev vchiq_cdev;
  20332. +static dev_t vchiq_devid;
  20333. +static VCHIQ_STATE_T g_state;
  20334. +static struct class *vchiq_class;
  20335. +static struct device *vchiq_dev;
  20336. +static DEFINE_SPINLOCK(msg_queue_spinlock);
  20337. +
  20338. +static const char *const ioctl_names[] = {
  20339. + "CONNECT",
  20340. + "SHUTDOWN",
  20341. + "CREATE_SERVICE",
  20342. + "REMOVE_SERVICE",
  20343. + "QUEUE_MESSAGE",
  20344. + "QUEUE_BULK_TRANSMIT",
  20345. + "QUEUE_BULK_RECEIVE",
  20346. + "AWAIT_COMPLETION",
  20347. + "DEQUEUE_MESSAGE",
  20348. + "GET_CLIENT_ID",
  20349. + "GET_CONFIG",
  20350. + "CLOSE_SERVICE",
  20351. + "USE_SERVICE",
  20352. + "RELEASE_SERVICE",
  20353. + "SET_SERVICE_OPTION",
  20354. + "DUMP_PHYS_MEM"
  20355. +};
  20356. +
  20357. +vchiq_static_assert((sizeof(ioctl_names)/sizeof(ioctl_names[0])) ==
  20358. + (VCHIQ_IOC_MAX + 1));
  20359. +
  20360. +static void
  20361. +dump_phys_mem(void *virt_addr, uint32_t num_bytes);
  20362. +
  20363. +/****************************************************************************
  20364. +*
  20365. +* add_completion
  20366. +*
  20367. +***************************************************************************/
  20368. +
  20369. +static VCHIQ_STATUS_T
  20370. +add_completion(VCHIQ_INSTANCE_T instance, VCHIQ_REASON_T reason,
  20371. + VCHIQ_HEADER_T *header, USER_SERVICE_T *user_service,
  20372. + void *bulk_userdata)
  20373. +{
  20374. + VCHIQ_COMPLETION_DATA_T *completion;
  20375. + DEBUG_INITIALISE(g_state.local)
  20376. +
  20377. + while (instance->completion_insert ==
  20378. + (instance->completion_remove + MAX_COMPLETIONS)) {
  20379. + /* Out of space - wait for the client */
  20380. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20381. + vchiq_log_trace(vchiq_arm_log_level,
  20382. + "add_completion - completion queue full");
  20383. + DEBUG_COUNT(COMPLETION_QUEUE_FULL_COUNT);
  20384. + if (down_interruptible(&instance->remove_event) != 0) {
  20385. + vchiq_log_info(vchiq_arm_log_level,
  20386. + "service_callback interrupted");
  20387. + return VCHIQ_RETRY;
  20388. + } else if (instance->closing) {
  20389. + vchiq_log_info(vchiq_arm_log_level,
  20390. + "service_callback closing");
  20391. + return VCHIQ_ERROR;
  20392. + }
  20393. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20394. + }
  20395. +
  20396. + completion =
  20397. + &instance->completions[instance->completion_insert &
  20398. + (MAX_COMPLETIONS - 1)];
  20399. +
  20400. + completion->header = header;
  20401. + completion->reason = reason;
  20402. + /* N.B. service_userdata is updated while processing AWAIT_COMPLETION */
  20403. + completion->service_userdata = user_service->service;
  20404. + completion->bulk_userdata = bulk_userdata;
  20405. +
  20406. + if (reason == VCHIQ_SERVICE_CLOSED)
  20407. + /* Take an extra reference, to be held until
  20408. + this CLOSED notification is delivered. */
  20409. + lock_service(user_service->service);
  20410. +
  20411. + /* A write barrier is needed here to ensure that the entire completion
  20412. + record is written out before the insert point. */
  20413. + wmb();
  20414. +
  20415. + if (reason == VCHIQ_MESSAGE_AVAILABLE)
  20416. + user_service->message_available_pos =
  20417. + instance->completion_insert;
  20418. + instance->completion_insert++;
  20419. +
  20420. + up(&instance->insert_event);
  20421. +
  20422. + return VCHIQ_SUCCESS;
  20423. +}
  20424. +
  20425. +/****************************************************************************
  20426. +*
  20427. +* service_callback
  20428. +*
  20429. +***************************************************************************/
  20430. +
  20431. +static VCHIQ_STATUS_T
  20432. +service_callback(VCHIQ_REASON_T reason, VCHIQ_HEADER_T *header,
  20433. + VCHIQ_SERVICE_HANDLE_T handle, void *bulk_userdata)
  20434. +{
  20435. + /* How do we ensure the callback goes to the right client?
  20436. + ** The service_user data points to a USER_SERVICE_T record containing
  20437. + ** the original callback and the user state structure, which contains a
  20438. + ** circular buffer for completion records.
  20439. + */
  20440. + USER_SERVICE_T *user_service;
  20441. + VCHIQ_SERVICE_T *service;
  20442. + VCHIQ_INSTANCE_T instance;
  20443. + DEBUG_INITIALISE(g_state.local)
  20444. +
  20445. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20446. +
  20447. + service = handle_to_service(handle);
  20448. + BUG_ON(!service);
  20449. + user_service = (USER_SERVICE_T *)service->base.userdata;
  20450. + instance = user_service->instance;
  20451. +
  20452. + if (!instance || instance->closing)
  20453. + return VCHIQ_SUCCESS;
  20454. +
  20455. + vchiq_log_trace(vchiq_arm_log_level,
  20456. + "service_callback - service %lx(%d), reason %d, header %lx, "
  20457. + "instance %lx, bulk_userdata %lx",
  20458. + (unsigned long)user_service,
  20459. + service->localport,
  20460. + reason, (unsigned long)header,
  20461. + (unsigned long)instance, (unsigned long)bulk_userdata);
  20462. +
  20463. + if (header && user_service->is_vchi) {
  20464. + spin_lock(&msg_queue_spinlock);
  20465. + while (user_service->msg_insert ==
  20466. + (user_service->msg_remove + MSG_QUEUE_SIZE)) {
  20467. + spin_unlock(&msg_queue_spinlock);
  20468. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20469. + DEBUG_COUNT(MSG_QUEUE_FULL_COUNT);
  20470. + vchiq_log_trace(vchiq_arm_log_level,
  20471. + "service_callback - msg queue full");
  20472. + /* If there is no MESSAGE_AVAILABLE in the completion
  20473. + ** queue, add one
  20474. + */
  20475. + if ((user_service->message_available_pos -
  20476. + instance->completion_remove) < 0) {
  20477. + VCHIQ_STATUS_T status;
  20478. + vchiq_log_info(vchiq_arm_log_level,
  20479. + "Inserting extra MESSAGE_AVAILABLE");
  20480. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20481. + status = add_completion(instance, reason,
  20482. + NULL, user_service, bulk_userdata);
  20483. + if (status != VCHIQ_SUCCESS) {
  20484. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20485. + return status;
  20486. + }
  20487. + }
  20488. +
  20489. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20490. + if (down_interruptible(&user_service->remove_event)
  20491. + != 0) {
  20492. + vchiq_log_info(vchiq_arm_log_level,
  20493. + "service_callback interrupted");
  20494. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20495. + return VCHIQ_RETRY;
  20496. + } else if (instance->closing) {
  20497. + vchiq_log_info(vchiq_arm_log_level,
  20498. + "service_callback closing");
  20499. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20500. + return VCHIQ_ERROR;
  20501. + }
  20502. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20503. + spin_lock(&msg_queue_spinlock);
  20504. + }
  20505. +
  20506. + user_service->msg_queue[user_service->msg_insert &
  20507. + (MSG_QUEUE_SIZE - 1)] = header;
  20508. + user_service->msg_insert++;
  20509. + spin_unlock(&msg_queue_spinlock);
  20510. +
  20511. + up(&user_service->insert_event);
  20512. +
  20513. + /* If there is a thread waiting in DEQUEUE_MESSAGE, or if
  20514. + ** there is a MESSAGE_AVAILABLE in the completion queue then
  20515. + ** bypass the completion queue.
  20516. + */
  20517. + if (((user_service->message_available_pos -
  20518. + instance->completion_remove) >= 0) ||
  20519. + user_service->dequeue_pending) {
  20520. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20521. + user_service->dequeue_pending = 0;
  20522. + return VCHIQ_SUCCESS;
  20523. + }
  20524. +
  20525. + header = NULL;
  20526. + }
  20527. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20528. +
  20529. + return add_completion(instance, reason, header, user_service,
  20530. + bulk_userdata);
  20531. +}
  20532. +
  20533. +/****************************************************************************
  20534. +*
  20535. +* user_service_free
  20536. +*
  20537. +***************************************************************************/
  20538. +static void
  20539. +user_service_free(void *userdata)
  20540. +{
  20541. + kfree(userdata);
  20542. +}
  20543. +
  20544. +/****************************************************************************
  20545. +*
  20546. +* vchiq_ioctl
  20547. +*
  20548. +***************************************************************************/
  20549. +
  20550. +static long
  20551. +vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  20552. +{
  20553. + VCHIQ_INSTANCE_T instance = file->private_data;
  20554. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  20555. + VCHIQ_SERVICE_T *service = NULL;
  20556. + long ret = 0;
  20557. + int i, rc;
  20558. + DEBUG_INITIALISE(g_state.local)
  20559. +
  20560. + vchiq_log_trace(vchiq_arm_log_level,
  20561. + "vchiq_ioctl - instance %x, cmd %s, arg %lx",
  20562. + (unsigned int)instance,
  20563. + ((_IOC_TYPE(cmd) == VCHIQ_IOC_MAGIC) &&
  20564. + (_IOC_NR(cmd) <= VCHIQ_IOC_MAX)) ?
  20565. + ioctl_names[_IOC_NR(cmd)] : "<invalid>", arg);
  20566. +
  20567. + switch (cmd) {
  20568. + case VCHIQ_IOC_SHUTDOWN:
  20569. + if (!instance->connected)
  20570. + break;
  20571. +
  20572. + /* Remove all services */
  20573. + i = 0;
  20574. + while ((service = next_service_by_instance(instance->state,
  20575. + instance, &i)) != NULL) {
  20576. + status = vchiq_remove_service(service->handle);
  20577. + unlock_service(service);
  20578. + if (status != VCHIQ_SUCCESS)
  20579. + break;
  20580. + }
  20581. + service = NULL;
  20582. +
  20583. + if (status == VCHIQ_SUCCESS) {
  20584. + /* Wake the completion thread and ask it to exit */
  20585. + instance->closing = 1;
  20586. + up(&instance->insert_event);
  20587. + }
  20588. +
  20589. + break;
  20590. +
  20591. + case VCHIQ_IOC_CONNECT:
  20592. + if (instance->connected) {
  20593. + ret = -EINVAL;
  20594. + break;
  20595. + }
  20596. + rc = mutex_lock_interruptible(&instance->state->mutex);
  20597. + if (rc != 0) {
  20598. + vchiq_log_error(vchiq_arm_log_level,
  20599. + "vchiq: connect: could not lock mutex for "
  20600. + "state %d: %d",
  20601. + instance->state->id, rc);
  20602. + ret = -EINTR;
  20603. + break;
  20604. + }
  20605. + status = vchiq_connect_internal(instance->state, instance);
  20606. + mutex_unlock(&instance->state->mutex);
  20607. +
  20608. + if (status == VCHIQ_SUCCESS)
  20609. + instance->connected = 1;
  20610. + else
  20611. + vchiq_log_error(vchiq_arm_log_level,
  20612. + "vchiq: could not connect: %d", status);
  20613. + break;
  20614. +
  20615. + case VCHIQ_IOC_CREATE_SERVICE: {
  20616. + VCHIQ_CREATE_SERVICE_T args;
  20617. + USER_SERVICE_T *user_service = NULL;
  20618. + void *userdata;
  20619. + int srvstate;
  20620. +
  20621. + if (copy_from_user
  20622. + (&args, (const void __user *)arg,
  20623. + sizeof(args)) != 0) {
  20624. + ret = -EFAULT;
  20625. + break;
  20626. + }
  20627. +
  20628. + user_service = kmalloc(sizeof(USER_SERVICE_T), GFP_KERNEL);
  20629. + if (!user_service) {
  20630. + ret = -ENOMEM;
  20631. + break;
  20632. + }
  20633. +
  20634. + if (args.is_open) {
  20635. + if (!instance->connected) {
  20636. + ret = -ENOTCONN;
  20637. + kfree(user_service);
  20638. + break;
  20639. + }
  20640. + srvstate = VCHIQ_SRVSTATE_OPENING;
  20641. + } else {
  20642. + srvstate =
  20643. + instance->connected ?
  20644. + VCHIQ_SRVSTATE_LISTENING :
  20645. + VCHIQ_SRVSTATE_HIDDEN;
  20646. + }
  20647. +
  20648. + userdata = args.params.userdata;
  20649. + args.params.callback = service_callback;
  20650. + args.params.userdata = user_service;
  20651. + service = vchiq_add_service_internal(
  20652. + instance->state,
  20653. + &args.params, srvstate,
  20654. + instance, user_service_free);
  20655. +
  20656. + if (service != NULL) {
  20657. + user_service->service = service;
  20658. + user_service->userdata = userdata;
  20659. + user_service->instance = instance;
  20660. + user_service->is_vchi = args.is_vchi;
  20661. + user_service->dequeue_pending = 0;
  20662. + user_service->message_available_pos =
  20663. + instance->completion_remove - 1;
  20664. + user_service->msg_insert = 0;
  20665. + user_service->msg_remove = 0;
  20666. + sema_init(&user_service->insert_event, 0);
  20667. + sema_init(&user_service->remove_event, 0);
  20668. +
  20669. + if (args.is_open) {
  20670. + status = vchiq_open_service_internal
  20671. + (service, instance->pid);
  20672. + if (status != VCHIQ_SUCCESS) {
  20673. + vchiq_remove_service(service->handle);
  20674. + service = NULL;
  20675. + ret = (status == VCHIQ_RETRY) ?
  20676. + -EINTR : -EIO;
  20677. + break;
  20678. + }
  20679. + }
  20680. +
  20681. + if (copy_to_user((void __user *)
  20682. + &(((VCHIQ_CREATE_SERVICE_T __user *)
  20683. + arg)->handle),
  20684. + (const void *)&service->handle,
  20685. + sizeof(service->handle)) != 0) {
  20686. + ret = -EFAULT;
  20687. + vchiq_remove_service(service->handle);
  20688. + }
  20689. +
  20690. + service = NULL;
  20691. + } else {
  20692. + ret = -EEXIST;
  20693. + kfree(user_service);
  20694. + }
  20695. + } break;
  20696. +
  20697. + case VCHIQ_IOC_CLOSE_SERVICE: {
  20698. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  20699. +
  20700. + service = find_service_for_instance(instance, handle);
  20701. + if (service != NULL)
  20702. + status = vchiq_close_service(service->handle);
  20703. + else
  20704. + ret = -EINVAL;
  20705. + } break;
  20706. +
  20707. + case VCHIQ_IOC_REMOVE_SERVICE: {
  20708. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  20709. +
  20710. + service = find_service_for_instance(instance, handle);
  20711. + if (service != NULL)
  20712. + status = vchiq_remove_service(service->handle);
  20713. + else
  20714. + ret = -EINVAL;
  20715. + } break;
  20716. +
  20717. + case VCHIQ_IOC_USE_SERVICE:
  20718. + case VCHIQ_IOC_RELEASE_SERVICE: {
  20719. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  20720. +
  20721. + service = find_service_for_instance(instance, handle);
  20722. + if (service != NULL) {
  20723. + status = (cmd == VCHIQ_IOC_USE_SERVICE) ?
  20724. + vchiq_use_service_internal(service) :
  20725. + vchiq_release_service_internal(service);
  20726. + if (status != VCHIQ_SUCCESS) {
  20727. + vchiq_log_error(vchiq_susp_log_level,
  20728. + "%s: cmd %s returned error %d for "
  20729. + "service %c%c%c%c:%03d",
  20730. + __func__,
  20731. + (cmd == VCHIQ_IOC_USE_SERVICE) ?
  20732. + "VCHIQ_IOC_USE_SERVICE" :
  20733. + "VCHIQ_IOC_RELEASE_SERVICE",
  20734. + status,
  20735. + VCHIQ_FOURCC_AS_4CHARS(
  20736. + service->base.fourcc),
  20737. + service->client_id);
  20738. + ret = -EINVAL;
  20739. + }
  20740. + } else
  20741. + ret = -EINVAL;
  20742. + } break;
  20743. +
  20744. + case VCHIQ_IOC_QUEUE_MESSAGE: {
  20745. + VCHIQ_QUEUE_MESSAGE_T args;
  20746. + if (copy_from_user
  20747. + (&args, (const void __user *)arg,
  20748. + sizeof(args)) != 0) {
  20749. + ret = -EFAULT;
  20750. + break;
  20751. + }
  20752. +
  20753. + service = find_service_for_instance(instance, args.handle);
  20754. +
  20755. + if ((service != NULL) && (args.count <= MAX_ELEMENTS)) {
  20756. + /* Copy elements into kernel space */
  20757. + VCHIQ_ELEMENT_T elements[MAX_ELEMENTS];
  20758. + if (copy_from_user(elements, args.elements,
  20759. + args.count * sizeof(VCHIQ_ELEMENT_T)) == 0)
  20760. + status = vchiq_queue_message
  20761. + (args.handle,
  20762. + elements, args.count);
  20763. + else
  20764. + ret = -EFAULT;
  20765. + } else {
  20766. + ret = -EINVAL;
  20767. + }
  20768. + } break;
  20769. +
  20770. + case VCHIQ_IOC_QUEUE_BULK_TRANSMIT:
  20771. + case VCHIQ_IOC_QUEUE_BULK_RECEIVE: {
  20772. + VCHIQ_QUEUE_BULK_TRANSFER_T args;
  20773. + struct bulk_waiter_node *waiter = NULL;
  20774. + VCHIQ_BULK_DIR_T dir =
  20775. + (cmd == VCHIQ_IOC_QUEUE_BULK_TRANSMIT) ?
  20776. + VCHIQ_BULK_TRANSMIT : VCHIQ_BULK_RECEIVE;
  20777. +
  20778. + if (copy_from_user
  20779. + (&args, (const void __user *)arg,
  20780. + sizeof(args)) != 0) {
  20781. + ret = -EFAULT;
  20782. + break;
  20783. + }
  20784. +
  20785. + service = find_service_for_instance(instance, args.handle);
  20786. + if (!service) {
  20787. + ret = -EINVAL;
  20788. + break;
  20789. + }
  20790. +
  20791. + if (args.mode == VCHIQ_BULK_MODE_BLOCKING) {
  20792. + waiter = kzalloc(sizeof(struct bulk_waiter_node),
  20793. + GFP_KERNEL);
  20794. + if (!waiter) {
  20795. + ret = -ENOMEM;
  20796. + break;
  20797. + }
  20798. + args.userdata = &waiter->bulk_waiter;
  20799. + } else if (args.mode == VCHIQ_BULK_MODE_WAITING) {
  20800. + struct list_head *pos;
  20801. + mutex_lock(&instance->bulk_waiter_list_mutex);
  20802. + list_for_each(pos, &instance->bulk_waiter_list) {
  20803. + if (list_entry(pos, struct bulk_waiter_node,
  20804. + list)->pid == current->pid) {
  20805. + waiter = list_entry(pos,
  20806. + struct bulk_waiter_node,
  20807. + list);
  20808. + list_del(pos);
  20809. + break;
  20810. + }
  20811. +
  20812. + }
  20813. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  20814. + if (!waiter) {
  20815. + vchiq_log_error(vchiq_arm_log_level,
  20816. + "no bulk_waiter found for pid %d",
  20817. + current->pid);
  20818. + ret = -ESRCH;
  20819. + break;
  20820. + }
  20821. + vchiq_log_info(vchiq_arm_log_level,
  20822. + "found bulk_waiter %x for pid %d",
  20823. + (unsigned int)waiter, current->pid);
  20824. + args.userdata = &waiter->bulk_waiter;
  20825. + }
  20826. + status = vchiq_bulk_transfer
  20827. + (args.handle,
  20828. + VCHI_MEM_HANDLE_INVALID,
  20829. + args.data, args.size,
  20830. + args.userdata, args.mode,
  20831. + dir);
  20832. + if (!waiter)
  20833. + break;
  20834. + if ((status != VCHIQ_RETRY) || fatal_signal_pending(current) ||
  20835. + !waiter->bulk_waiter.bulk) {
  20836. + if (waiter->bulk_waiter.bulk) {
  20837. + /* Cancel the signal when the transfer
  20838. + ** completes. */
  20839. + spin_lock(&bulk_waiter_spinlock);
  20840. + waiter->bulk_waiter.bulk->userdata = NULL;
  20841. + spin_unlock(&bulk_waiter_spinlock);
  20842. + }
  20843. + kfree(waiter);
  20844. + } else {
  20845. + const VCHIQ_BULK_MODE_T mode_waiting =
  20846. + VCHIQ_BULK_MODE_WAITING;
  20847. + waiter->pid = current->pid;
  20848. + mutex_lock(&instance->bulk_waiter_list_mutex);
  20849. + list_add(&waiter->list, &instance->bulk_waiter_list);
  20850. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  20851. + vchiq_log_info(vchiq_arm_log_level,
  20852. + "saved bulk_waiter %x for pid %d",
  20853. + (unsigned int)waiter, current->pid);
  20854. +
  20855. + if (copy_to_user((void __user *)
  20856. + &(((VCHIQ_QUEUE_BULK_TRANSFER_T __user *)
  20857. + arg)->mode),
  20858. + (const void *)&mode_waiting,
  20859. + sizeof(mode_waiting)) != 0)
  20860. + ret = -EFAULT;
  20861. + }
  20862. + } break;
  20863. +
  20864. + case VCHIQ_IOC_AWAIT_COMPLETION: {
  20865. + VCHIQ_AWAIT_COMPLETION_T args;
  20866. +
  20867. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  20868. + if (!instance->connected) {
  20869. + ret = -ENOTCONN;
  20870. + break;
  20871. + }
  20872. +
  20873. + if (copy_from_user(&args, (const void __user *)arg,
  20874. + sizeof(args)) != 0) {
  20875. + ret = -EFAULT;
  20876. + break;
  20877. + }
  20878. +
  20879. + mutex_lock(&instance->completion_mutex);
  20880. +
  20881. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  20882. + while ((instance->completion_remove ==
  20883. + instance->completion_insert)
  20884. + && !instance->closing) {
  20885. + int rc;
  20886. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  20887. + mutex_unlock(&instance->completion_mutex);
  20888. + rc = down_interruptible(&instance->insert_event);
  20889. + mutex_lock(&instance->completion_mutex);
  20890. + if (rc != 0) {
  20891. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  20892. + vchiq_log_info(vchiq_arm_log_level,
  20893. + "AWAIT_COMPLETION interrupted");
  20894. + ret = -EINTR;
  20895. + break;
  20896. + }
  20897. + }
  20898. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  20899. +
  20900. + /* A read memory barrier is needed to stop prefetch of a stale
  20901. + ** completion record
  20902. + */
  20903. + rmb();
  20904. +
  20905. + if (ret == 0) {
  20906. + int msgbufcount = args.msgbufcount;
  20907. + for (ret = 0; ret < args.count; ret++) {
  20908. + VCHIQ_COMPLETION_DATA_T *completion;
  20909. + VCHIQ_SERVICE_T *service;
  20910. + USER_SERVICE_T *user_service;
  20911. + VCHIQ_HEADER_T *header;
  20912. + if (instance->completion_remove ==
  20913. + instance->completion_insert)
  20914. + break;
  20915. + completion = &instance->completions[
  20916. + instance->completion_remove &
  20917. + (MAX_COMPLETIONS - 1)];
  20918. +
  20919. + service = completion->service_userdata;
  20920. + user_service = service->base.userdata;
  20921. + completion->service_userdata =
  20922. + user_service->userdata;
  20923. +
  20924. + header = completion->header;
  20925. + if (header) {
  20926. + void __user *msgbuf;
  20927. + int msglen;
  20928. +
  20929. + msglen = header->size +
  20930. + sizeof(VCHIQ_HEADER_T);
  20931. + /* This must be a VCHIQ-style service */
  20932. + if (args.msgbufsize < msglen) {
  20933. + vchiq_log_error(
  20934. + vchiq_arm_log_level,
  20935. + "header %x: msgbufsize"
  20936. + " %x < msglen %x",
  20937. + (unsigned int)header,
  20938. + args.msgbufsize,
  20939. + msglen);
  20940. + WARN(1, "invalid message "
  20941. + "size\n");
  20942. + if (ret == 0)
  20943. + ret = -EMSGSIZE;
  20944. + break;
  20945. + }
  20946. + if (msgbufcount <= 0)
  20947. + /* Stall here for lack of a
  20948. + ** buffer for the message. */
  20949. + break;
  20950. + /* Get the pointer from user space */
  20951. + msgbufcount--;
  20952. + if (copy_from_user(&msgbuf,
  20953. + (const void __user *)
  20954. + &args.msgbufs[msgbufcount],
  20955. + sizeof(msgbuf)) != 0) {
  20956. + if (ret == 0)
  20957. + ret = -EFAULT;
  20958. + break;
  20959. + }
  20960. +
  20961. + /* Copy the message to user space */
  20962. + if (copy_to_user(msgbuf, header,
  20963. + msglen) != 0) {
  20964. + if (ret == 0)
  20965. + ret = -EFAULT;
  20966. + break;
  20967. + }
  20968. +
  20969. + /* Now it has been copied, the message
  20970. + ** can be released. */
  20971. + vchiq_release_message(service->handle,
  20972. + header);
  20973. +
  20974. + /* The completion must point to the
  20975. + ** msgbuf. */
  20976. + completion->header = msgbuf;
  20977. + }
  20978. +
  20979. + if (completion->reason ==
  20980. + VCHIQ_SERVICE_CLOSED)
  20981. + unlock_service(service);
  20982. +
  20983. + if (copy_to_user((void __user *)(
  20984. + (size_t)args.buf +
  20985. + ret * sizeof(VCHIQ_COMPLETION_DATA_T)),
  20986. + completion,
  20987. + sizeof(VCHIQ_COMPLETION_DATA_T)) != 0) {
  20988. + if (ret == 0)
  20989. + ret = -EFAULT;
  20990. + break;
  20991. + }
  20992. +
  20993. + instance->completion_remove++;
  20994. + }
  20995. +
  20996. + if (msgbufcount != args.msgbufcount) {
  20997. + if (copy_to_user((void __user *)
  20998. + &((VCHIQ_AWAIT_COMPLETION_T *)arg)->
  20999. + msgbufcount,
  21000. + &msgbufcount,
  21001. + sizeof(msgbufcount)) != 0) {
  21002. + ret = -EFAULT;
  21003. + }
  21004. + }
  21005. + }
  21006. +
  21007. + if (ret != 0)
  21008. + up(&instance->remove_event);
  21009. + mutex_unlock(&instance->completion_mutex);
  21010. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  21011. + } break;
  21012. +
  21013. + case VCHIQ_IOC_DEQUEUE_MESSAGE: {
  21014. + VCHIQ_DEQUEUE_MESSAGE_T args;
  21015. + USER_SERVICE_T *user_service;
  21016. + VCHIQ_HEADER_T *header;
  21017. +
  21018. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  21019. + if (copy_from_user
  21020. + (&args, (const void __user *)arg,
  21021. + sizeof(args)) != 0) {
  21022. + ret = -EFAULT;
  21023. + break;
  21024. + }
  21025. + service = find_service_for_instance(instance, args.handle);
  21026. + if (!service) {
  21027. + ret = -EINVAL;
  21028. + break;
  21029. + }
  21030. + user_service = (USER_SERVICE_T *)service->base.userdata;
  21031. + if (user_service->is_vchi == 0) {
  21032. + ret = -EINVAL;
  21033. + break;
  21034. + }
  21035. +
  21036. + spin_lock(&msg_queue_spinlock);
  21037. + if (user_service->msg_remove == user_service->msg_insert) {
  21038. + if (!args.blocking) {
  21039. + spin_unlock(&msg_queue_spinlock);
  21040. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  21041. + ret = -EWOULDBLOCK;
  21042. + break;
  21043. + }
  21044. + user_service->dequeue_pending = 1;
  21045. + do {
  21046. + spin_unlock(&msg_queue_spinlock);
  21047. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  21048. + if (down_interruptible(
  21049. + &user_service->insert_event) != 0) {
  21050. + vchiq_log_info(vchiq_arm_log_level,
  21051. + "DEQUEUE_MESSAGE interrupted");
  21052. + ret = -EINTR;
  21053. + break;
  21054. + }
  21055. + spin_lock(&msg_queue_spinlock);
  21056. + } while (user_service->msg_remove ==
  21057. + user_service->msg_insert);
  21058. +
  21059. + if (ret)
  21060. + break;
  21061. + }
  21062. +
  21063. + BUG_ON((int)(user_service->msg_insert -
  21064. + user_service->msg_remove) < 0);
  21065. +
  21066. + header = user_service->msg_queue[user_service->msg_remove &
  21067. + (MSG_QUEUE_SIZE - 1)];
  21068. + user_service->msg_remove++;
  21069. + spin_unlock(&msg_queue_spinlock);
  21070. +
  21071. + up(&user_service->remove_event);
  21072. + if (header == NULL)
  21073. + ret = -ENOTCONN;
  21074. + else if (header->size <= args.bufsize) {
  21075. + /* Copy to user space if msgbuf is not NULL */
  21076. + if ((args.buf == NULL) ||
  21077. + (copy_to_user((void __user *)args.buf,
  21078. + header->data,
  21079. + header->size) == 0)) {
  21080. + ret = header->size;
  21081. + vchiq_release_message(
  21082. + service->handle,
  21083. + header);
  21084. + } else
  21085. + ret = -EFAULT;
  21086. + } else {
  21087. + vchiq_log_error(vchiq_arm_log_level,
  21088. + "header %x: bufsize %x < size %x",
  21089. + (unsigned int)header, args.bufsize,
  21090. + header->size);
  21091. + WARN(1, "invalid size\n");
  21092. + ret = -EMSGSIZE;
  21093. + }
  21094. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  21095. + } break;
  21096. +
  21097. + case VCHIQ_IOC_GET_CLIENT_ID: {
  21098. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  21099. +
  21100. + ret = vchiq_get_client_id(handle);
  21101. + } break;
  21102. +
  21103. + case VCHIQ_IOC_GET_CONFIG: {
  21104. + VCHIQ_GET_CONFIG_T args;
  21105. + VCHIQ_CONFIG_T config;
  21106. +
  21107. + if (copy_from_user(&args, (const void __user *)arg,
  21108. + sizeof(args)) != 0) {
  21109. + ret = -EFAULT;
  21110. + break;
  21111. + }
  21112. + if (args.config_size > sizeof(config)) {
  21113. + ret = -EINVAL;
  21114. + break;
  21115. + }
  21116. + status = vchiq_get_config(instance, args.config_size, &config);
  21117. + if (status == VCHIQ_SUCCESS) {
  21118. + if (copy_to_user((void __user *)args.pconfig,
  21119. + &config, args.config_size) != 0) {
  21120. + ret = -EFAULT;
  21121. + break;
  21122. + }
  21123. + }
  21124. + } break;
  21125. +
  21126. + case VCHIQ_IOC_SET_SERVICE_OPTION: {
  21127. + VCHIQ_SET_SERVICE_OPTION_T args;
  21128. +
  21129. + if (copy_from_user(
  21130. + &args, (const void __user *)arg,
  21131. + sizeof(args)) != 0) {
  21132. + ret = -EFAULT;
  21133. + break;
  21134. + }
  21135. +
  21136. + service = find_service_for_instance(instance, args.handle);
  21137. + if (!service) {
  21138. + ret = -EINVAL;
  21139. + break;
  21140. + }
  21141. +
  21142. + status = vchiq_set_service_option(
  21143. + args.handle, args.option, args.value);
  21144. + } break;
  21145. +
  21146. + case VCHIQ_IOC_DUMP_PHYS_MEM: {
  21147. + VCHIQ_DUMP_MEM_T args;
  21148. +
  21149. + if (copy_from_user
  21150. + (&args, (const void __user *)arg,
  21151. + sizeof(args)) != 0) {
  21152. + ret = -EFAULT;
  21153. + break;
  21154. + }
  21155. + dump_phys_mem(args.virt_addr, args.num_bytes);
  21156. + } break;
  21157. +
  21158. + default:
  21159. + ret = -ENOTTY;
  21160. + break;
  21161. + }
  21162. +
  21163. + if (service)
  21164. + unlock_service(service);
  21165. +
  21166. + if (ret == 0) {
  21167. + if (status == VCHIQ_ERROR)
  21168. + ret = -EIO;
  21169. + else if (status == VCHIQ_RETRY)
  21170. + ret = -EINTR;
  21171. + }
  21172. +
  21173. + if ((status == VCHIQ_SUCCESS) && (ret < 0) && (ret != -EINTR) &&
  21174. + (ret != -EWOULDBLOCK))
  21175. + vchiq_log_info(vchiq_arm_log_level,
  21176. + " ioctl instance %lx, cmd %s -> status %d, %ld",
  21177. + (unsigned long)instance,
  21178. + (_IOC_NR(cmd) <= VCHIQ_IOC_MAX) ?
  21179. + ioctl_names[_IOC_NR(cmd)] :
  21180. + "<invalid>",
  21181. + status, ret);
  21182. + else
  21183. + vchiq_log_trace(vchiq_arm_log_level,
  21184. + " ioctl instance %lx, cmd %s -> status %d, %ld",
  21185. + (unsigned long)instance,
  21186. + (_IOC_NR(cmd) <= VCHIQ_IOC_MAX) ?
  21187. + ioctl_names[_IOC_NR(cmd)] :
  21188. + "<invalid>",
  21189. + status, ret);
  21190. +
  21191. + return ret;
  21192. +}
  21193. +
  21194. +/****************************************************************************
  21195. +*
  21196. +* vchiq_open
  21197. +*
  21198. +***************************************************************************/
  21199. +
  21200. +static int
  21201. +vchiq_open(struct inode *inode, struct file *file)
  21202. +{
  21203. + int dev = iminor(inode) & 0x0f;
  21204. + vchiq_log_info(vchiq_arm_log_level, "vchiq_open");
  21205. + switch (dev) {
  21206. + case VCHIQ_MINOR: {
  21207. + int ret;
  21208. + VCHIQ_STATE_T *state = vchiq_get_state();
  21209. + VCHIQ_INSTANCE_T instance;
  21210. +
  21211. + if (!state) {
  21212. + vchiq_log_error(vchiq_arm_log_level,
  21213. + "vchiq has no connection to VideoCore");
  21214. + return -ENOTCONN;
  21215. + }
  21216. +
  21217. + instance = kzalloc(sizeof(*instance), GFP_KERNEL);
  21218. + if (!instance)
  21219. + return -ENOMEM;
  21220. +
  21221. + instance->state = state;
  21222. + instance->pid = current->tgid;
  21223. +
  21224. + ret = vchiq_proc_add_instance(instance);
  21225. + if (ret != 0) {
  21226. + kfree(instance);
  21227. + return ret;
  21228. + }
  21229. +
  21230. + sema_init(&instance->insert_event, 0);
  21231. + sema_init(&instance->remove_event, 0);
  21232. + mutex_init(&instance->completion_mutex);
  21233. + mutex_init(&instance->bulk_waiter_list_mutex);
  21234. + INIT_LIST_HEAD(&instance->bulk_waiter_list);
  21235. +
  21236. + file->private_data = instance;
  21237. + } break;
  21238. +
  21239. + default:
  21240. + vchiq_log_error(vchiq_arm_log_level,
  21241. + "Unknown minor device: %d", dev);
  21242. + return -ENXIO;
  21243. + }
  21244. +
  21245. + return 0;
  21246. +}
  21247. +
  21248. +/****************************************************************************
  21249. +*
  21250. +* vchiq_release
  21251. +*
  21252. +***************************************************************************/
  21253. +
  21254. +static int
  21255. +vchiq_release(struct inode *inode, struct file *file)
  21256. +{
  21257. + int dev = iminor(inode) & 0x0f;
  21258. + int ret = 0;
  21259. + switch (dev) {
  21260. + case VCHIQ_MINOR: {
  21261. + VCHIQ_INSTANCE_T instance = file->private_data;
  21262. + VCHIQ_STATE_T *state = vchiq_get_state();
  21263. + VCHIQ_SERVICE_T *service;
  21264. + int i;
  21265. +
  21266. + vchiq_log_info(vchiq_arm_log_level,
  21267. + "vchiq_release: instance=%lx",
  21268. + (unsigned long)instance);
  21269. +
  21270. + if (!state) {
  21271. + ret = -EPERM;
  21272. + goto out;
  21273. + }
  21274. +
  21275. + /* Ensure videocore is awake to allow termination. */
  21276. + vchiq_use_internal(instance->state, NULL,
  21277. + USE_TYPE_VCHIQ);
  21278. +
  21279. + mutex_lock(&instance->completion_mutex);
  21280. +
  21281. + /* Wake the completion thread and ask it to exit */
  21282. + instance->closing = 1;
  21283. + up(&instance->insert_event);
  21284. +
  21285. + mutex_unlock(&instance->completion_mutex);
  21286. +
  21287. + /* Wake the slot handler if the completion queue is full. */
  21288. + up(&instance->remove_event);
  21289. +
  21290. + /* Mark all services for termination... */
  21291. + i = 0;
  21292. + while ((service = next_service_by_instance(state, instance,
  21293. + &i)) != NULL) {
  21294. + USER_SERVICE_T *user_service = service->base.userdata;
  21295. +
  21296. + /* Wake the slot handler if the msg queue is full. */
  21297. + up(&user_service->remove_event);
  21298. +
  21299. + vchiq_terminate_service_internal(service);
  21300. + unlock_service(service);
  21301. + }
  21302. +
  21303. + /* ...and wait for them to die */
  21304. + i = 0;
  21305. + while ((service = next_service_by_instance(state, instance, &i))
  21306. + != NULL) {
  21307. + USER_SERVICE_T *user_service = service->base.userdata;
  21308. +
  21309. + down(&service->remove_event);
  21310. +
  21311. + BUG_ON(service->srvstate != VCHIQ_SRVSTATE_FREE);
  21312. +
  21313. + spin_lock(&msg_queue_spinlock);
  21314. +
  21315. + while (user_service->msg_remove !=
  21316. + user_service->msg_insert) {
  21317. + VCHIQ_HEADER_T *header = user_service->
  21318. + msg_queue[user_service->msg_remove &
  21319. + (MSG_QUEUE_SIZE - 1)];
  21320. + user_service->msg_remove++;
  21321. + spin_unlock(&msg_queue_spinlock);
  21322. +
  21323. + if (header)
  21324. + vchiq_release_message(
  21325. + service->handle,
  21326. + header);
  21327. + spin_lock(&msg_queue_spinlock);
  21328. + }
  21329. +
  21330. + spin_unlock(&msg_queue_spinlock);
  21331. +
  21332. + unlock_service(service);
  21333. + }
  21334. +
  21335. + /* Release any closed services */
  21336. + while (instance->completion_remove !=
  21337. + instance->completion_insert) {
  21338. + VCHIQ_COMPLETION_DATA_T *completion;
  21339. + VCHIQ_SERVICE_T *service;
  21340. + completion = &instance->completions[
  21341. + instance->completion_remove &
  21342. + (MAX_COMPLETIONS - 1)];
  21343. + service = completion->service_userdata;
  21344. + if (completion->reason == VCHIQ_SERVICE_CLOSED)
  21345. + unlock_service(service);
  21346. + instance->completion_remove++;
  21347. + }
  21348. +
  21349. + /* Release the PEER service count. */
  21350. + vchiq_release_internal(instance->state, NULL);
  21351. +
  21352. + {
  21353. + struct list_head *pos, *next;
  21354. + list_for_each_safe(pos, next,
  21355. + &instance->bulk_waiter_list) {
  21356. + struct bulk_waiter_node *waiter;
  21357. + waiter = list_entry(pos,
  21358. + struct bulk_waiter_node,
  21359. + list);
  21360. + list_del(pos);
  21361. + vchiq_log_info(vchiq_arm_log_level,
  21362. + "bulk_waiter - cleaned up %x "
  21363. + "for pid %d",
  21364. + (unsigned int)waiter, waiter->pid);
  21365. + kfree(waiter);
  21366. + }
  21367. + }
  21368. +
  21369. + vchiq_proc_remove_instance(instance);
  21370. +
  21371. + kfree(instance);
  21372. + file->private_data = NULL;
  21373. + } break;
  21374. +
  21375. + default:
  21376. + vchiq_log_error(vchiq_arm_log_level,
  21377. + "Unknown minor device: %d", dev);
  21378. + ret = -ENXIO;
  21379. + }
  21380. +
  21381. +out:
  21382. + return ret;
  21383. +}
  21384. +
  21385. +/****************************************************************************
  21386. +*
  21387. +* vchiq_dump
  21388. +*
  21389. +***************************************************************************/
  21390. +
  21391. +void
  21392. +vchiq_dump(void *dump_context, const char *str, int len)
  21393. +{
  21394. + DUMP_CONTEXT_T *context = (DUMP_CONTEXT_T *)dump_context;
  21395. +
  21396. + if (context->actual < context->space) {
  21397. + int copy_bytes;
  21398. + if (context->offset > 0) {
  21399. + int skip_bytes = min(len, (int)context->offset);
  21400. + str += skip_bytes;
  21401. + len -= skip_bytes;
  21402. + context->offset -= skip_bytes;
  21403. + if (context->offset > 0)
  21404. + return;
  21405. + }
  21406. + copy_bytes = min(len, (int)(context->space - context->actual));
  21407. + if (copy_bytes == 0)
  21408. + return;
  21409. + if (copy_to_user(context->buf + context->actual, str,
  21410. + copy_bytes))
  21411. + context->actual = -EFAULT;
  21412. + context->actual += copy_bytes;
  21413. + len -= copy_bytes;
  21414. +
  21415. + /* If tne terminating NUL is included in the length, then it
  21416. + ** marks the end of a line and should be replaced with a
  21417. + ** carriage return. */
  21418. + if ((len == 0) && (str[copy_bytes - 1] == '\0')) {
  21419. + char cr = '\n';
  21420. + if (copy_to_user(context->buf + context->actual - 1,
  21421. + &cr, 1))
  21422. + context->actual = -EFAULT;
  21423. + }
  21424. + }
  21425. +}
  21426. +
  21427. +/****************************************************************************
  21428. +*
  21429. +* vchiq_dump_platform_instance_state
  21430. +*
  21431. +***************************************************************************/
  21432. +
  21433. +void
  21434. +vchiq_dump_platform_instances(void *dump_context)
  21435. +{
  21436. + VCHIQ_STATE_T *state = vchiq_get_state();
  21437. + char buf[80];
  21438. + int len;
  21439. + int i;
  21440. +
  21441. + /* There is no list of instances, so instead scan all services,
  21442. + marking those that have been dumped. */
  21443. +
  21444. + for (i = 0; i < state->unused_service; i++) {
  21445. + VCHIQ_SERVICE_T *service = state->services[i];
  21446. + VCHIQ_INSTANCE_T instance;
  21447. +
  21448. + if (service && (service->base.callback == service_callback)) {
  21449. + instance = service->instance;
  21450. + if (instance)
  21451. + instance->mark = 0;
  21452. + }
  21453. + }
  21454. +
  21455. + for (i = 0; i < state->unused_service; i++) {
  21456. + VCHIQ_SERVICE_T *service = state->services[i];
  21457. + VCHIQ_INSTANCE_T instance;
  21458. +
  21459. + if (service && (service->base.callback == service_callback)) {
  21460. + instance = service->instance;
  21461. + if (instance && !instance->mark) {
  21462. + len = snprintf(buf, sizeof(buf),
  21463. + "Instance %x: pid %d,%s completions "
  21464. + "%d/%d",
  21465. + (unsigned int)instance, instance->pid,
  21466. + instance->connected ? " connected, " :
  21467. + "",
  21468. + instance->completion_insert -
  21469. + instance->completion_remove,
  21470. + MAX_COMPLETIONS);
  21471. +
  21472. + vchiq_dump(dump_context, buf, len + 1);
  21473. +
  21474. + instance->mark = 1;
  21475. + }
  21476. + }
  21477. + }
  21478. +}
  21479. +
  21480. +/****************************************************************************
  21481. +*
  21482. +* vchiq_dump_platform_service_state
  21483. +*
  21484. +***************************************************************************/
  21485. +
  21486. +void
  21487. +vchiq_dump_platform_service_state(void *dump_context, VCHIQ_SERVICE_T *service)
  21488. +{
  21489. + USER_SERVICE_T *user_service = (USER_SERVICE_T *)service->base.userdata;
  21490. + char buf[80];
  21491. + int len;
  21492. +
  21493. + len = snprintf(buf, sizeof(buf), " instance %x",
  21494. + (unsigned int)service->instance);
  21495. +
  21496. + if ((service->base.callback == service_callback) &&
  21497. + user_service->is_vchi) {
  21498. + len += snprintf(buf + len, sizeof(buf) - len,
  21499. + ", %d/%d messages",
  21500. + user_service->msg_insert - user_service->msg_remove,
  21501. + MSG_QUEUE_SIZE);
  21502. +
  21503. + if (user_service->dequeue_pending)
  21504. + len += snprintf(buf + len, sizeof(buf) - len,
  21505. + " (dequeue pending)");
  21506. + }
  21507. +
  21508. + vchiq_dump(dump_context, buf, len + 1);
  21509. +}
  21510. +
  21511. +/****************************************************************************
  21512. +*
  21513. +* dump_user_mem
  21514. +*
  21515. +***************************************************************************/
  21516. +
  21517. +static void
  21518. +dump_phys_mem(void *virt_addr, uint32_t num_bytes)
  21519. +{
  21520. + int rc;
  21521. + uint8_t *end_virt_addr = virt_addr + num_bytes;
  21522. + int num_pages;
  21523. + int offset;
  21524. + int end_offset;
  21525. + int page_idx;
  21526. + int prev_idx;
  21527. + struct page *page;
  21528. + struct page **pages;
  21529. + uint8_t *kmapped_virt_ptr;
  21530. +
  21531. + /* Align virtAddr and endVirtAddr to 16 byte boundaries. */
  21532. +
  21533. + virt_addr = (void *)((unsigned long)virt_addr & ~0x0fuL);
  21534. + end_virt_addr = (void *)(((unsigned long)end_virt_addr + 15uL) &
  21535. + ~0x0fuL);
  21536. +
  21537. + offset = (int)(long)virt_addr & (PAGE_SIZE - 1);
  21538. + end_offset = (int)(long)end_virt_addr & (PAGE_SIZE - 1);
  21539. +
  21540. + num_pages = (offset + num_bytes + PAGE_SIZE - 1) / PAGE_SIZE;
  21541. +
  21542. + pages = kmalloc(sizeof(struct page *) * num_pages, GFP_KERNEL);
  21543. + if (pages == NULL) {
  21544. + vchiq_log_error(vchiq_arm_log_level,
  21545. + "Unable to allocation memory for %d pages\n",
  21546. + num_pages);
  21547. + return;
  21548. + }
  21549. +
  21550. + down_read(&current->mm->mmap_sem);
  21551. + rc = get_user_pages(current, /* task */
  21552. + current->mm, /* mm */
  21553. + (unsigned long)virt_addr, /* start */
  21554. + num_pages, /* len */
  21555. + 0, /* write */
  21556. + 0, /* force */
  21557. + pages, /* pages (array of page pointers) */
  21558. + NULL); /* vmas */
  21559. + up_read(&current->mm->mmap_sem);
  21560. +
  21561. + prev_idx = -1;
  21562. + page = NULL;
  21563. +
  21564. + while (offset < end_offset) {
  21565. +
  21566. + int page_offset = offset % PAGE_SIZE;
  21567. + page_idx = offset / PAGE_SIZE;
  21568. +
  21569. + if (page_idx != prev_idx) {
  21570. +
  21571. + if (page != NULL)
  21572. + kunmap(page);
  21573. + page = pages[page_idx];
  21574. + kmapped_virt_ptr = kmap(page);
  21575. +
  21576. + prev_idx = page_idx;
  21577. + }
  21578. +
  21579. + if (vchiq_arm_log_level >= VCHIQ_LOG_TRACE)
  21580. + vchiq_log_dump_mem("ph",
  21581. + (uint32_t)(unsigned long)&kmapped_virt_ptr[
  21582. + page_offset],
  21583. + &kmapped_virt_ptr[page_offset], 16);
  21584. +
  21585. + offset += 16;
  21586. + }
  21587. + if (page != NULL)
  21588. + kunmap(page);
  21589. +
  21590. + for (page_idx = 0; page_idx < num_pages; page_idx++)
  21591. + page_cache_release(pages[page_idx]);
  21592. +
  21593. + kfree(pages);
  21594. +}
  21595. +
  21596. +/****************************************************************************
  21597. +*
  21598. +* vchiq_read
  21599. +*
  21600. +***************************************************************************/
  21601. +
  21602. +static ssize_t
  21603. +vchiq_read(struct file *file, char __user *buf,
  21604. + size_t count, loff_t *ppos)
  21605. +{
  21606. + DUMP_CONTEXT_T context;
  21607. + context.buf = buf;
  21608. + context.actual = 0;
  21609. + context.space = count;
  21610. + context.offset = *ppos;
  21611. +
  21612. + vchiq_dump_state(&context, &g_state);
  21613. +
  21614. + *ppos += context.actual;
  21615. +
  21616. + return context.actual;
  21617. +}
  21618. +
  21619. +VCHIQ_STATE_T *
  21620. +vchiq_get_state(void)
  21621. +{
  21622. +
  21623. + if (g_state.remote == NULL)
  21624. + printk(KERN_ERR "%s: g_state.remote == NULL\n", __func__);
  21625. + else if (g_state.remote->initialised != 1)
  21626. + printk(KERN_NOTICE "%s: g_state.remote->initialised != 1 (%d)\n",
  21627. + __func__, g_state.remote->initialised);
  21628. +
  21629. + return ((g_state.remote != NULL) &&
  21630. + (g_state.remote->initialised == 1)) ? &g_state : NULL;
  21631. +}
  21632. +
  21633. +static const struct file_operations
  21634. +vchiq_fops = {
  21635. + .owner = THIS_MODULE,
  21636. + .unlocked_ioctl = vchiq_ioctl,
  21637. + .open = vchiq_open,
  21638. + .release = vchiq_release,
  21639. + .read = vchiq_read
  21640. +};
  21641. +
  21642. +/*
  21643. + * Autosuspend related functionality
  21644. + */
  21645. +
  21646. +int
  21647. +vchiq_videocore_wanted(VCHIQ_STATE_T *state)
  21648. +{
  21649. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21650. + if (!arm_state)
  21651. + /* autosuspend not supported - always return wanted */
  21652. + return 1;
  21653. + else if (arm_state->blocked_count)
  21654. + return 1;
  21655. + else if (!arm_state->videocore_use_count)
  21656. + /* usage count zero - check for override unless we're forcing */
  21657. + if (arm_state->resume_blocked)
  21658. + return 0;
  21659. + else
  21660. + return vchiq_platform_videocore_wanted(state);
  21661. + else
  21662. + /* non-zero usage count - videocore still required */
  21663. + return 1;
  21664. +}
  21665. +
  21666. +static VCHIQ_STATUS_T
  21667. +vchiq_keepalive_vchiq_callback(VCHIQ_REASON_T reason,
  21668. + VCHIQ_HEADER_T *header,
  21669. + VCHIQ_SERVICE_HANDLE_T service_user,
  21670. + void *bulk_user)
  21671. +{
  21672. + vchiq_log_error(vchiq_susp_log_level,
  21673. + "%s callback reason %d", __func__, reason);
  21674. + return 0;
  21675. +}
  21676. +
  21677. +static int
  21678. +vchiq_keepalive_thread_func(void *v)
  21679. +{
  21680. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  21681. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21682. +
  21683. + VCHIQ_STATUS_T status;
  21684. + VCHIQ_INSTANCE_T instance;
  21685. + VCHIQ_SERVICE_HANDLE_T ka_handle;
  21686. +
  21687. + VCHIQ_SERVICE_PARAMS_T params = {
  21688. + .fourcc = VCHIQ_MAKE_FOURCC('K', 'E', 'E', 'P'),
  21689. + .callback = vchiq_keepalive_vchiq_callback,
  21690. + .version = KEEPALIVE_VER,
  21691. + .version_min = KEEPALIVE_VER_MIN
  21692. + };
  21693. +
  21694. + status = vchiq_initialise(&instance);
  21695. + if (status != VCHIQ_SUCCESS) {
  21696. + vchiq_log_error(vchiq_susp_log_level,
  21697. + "%s vchiq_initialise failed %d", __func__, status);
  21698. + goto exit;
  21699. + }
  21700. +
  21701. + status = vchiq_connect(instance);
  21702. + if (status != VCHIQ_SUCCESS) {
  21703. + vchiq_log_error(vchiq_susp_log_level,
  21704. + "%s vchiq_connect failed %d", __func__, status);
  21705. + goto shutdown;
  21706. + }
  21707. +
  21708. + status = vchiq_add_service(instance, &params, &ka_handle);
  21709. + if (status != VCHIQ_SUCCESS) {
  21710. + vchiq_log_error(vchiq_susp_log_level,
  21711. + "%s vchiq_open_service failed %d", __func__, status);
  21712. + goto shutdown;
  21713. + }
  21714. +
  21715. + while (1) {
  21716. + long rc = 0, uc = 0;
  21717. + if (wait_for_completion_interruptible(&arm_state->ka_evt)
  21718. + != 0) {
  21719. + vchiq_log_error(vchiq_susp_log_level,
  21720. + "%s interrupted", __func__);
  21721. + flush_signals(current);
  21722. + continue;
  21723. + }
  21724. +
  21725. + /* read and clear counters. Do release_count then use_count to
  21726. + * prevent getting more releases than uses */
  21727. + rc = atomic_xchg(&arm_state->ka_release_count, 0);
  21728. + uc = atomic_xchg(&arm_state->ka_use_count, 0);
  21729. +
  21730. + /* Call use/release service the requisite number of times.
  21731. + * Process use before release so use counts don't go negative */
  21732. + while (uc--) {
  21733. + atomic_inc(&arm_state->ka_use_ack_count);
  21734. + status = vchiq_use_service(ka_handle);
  21735. + if (status != VCHIQ_SUCCESS) {
  21736. + vchiq_log_error(vchiq_susp_log_level,
  21737. + "%s vchiq_use_service error %d",
  21738. + __func__, status);
  21739. + }
  21740. + }
  21741. + while (rc--) {
  21742. + status = vchiq_release_service(ka_handle);
  21743. + if (status != VCHIQ_SUCCESS) {
  21744. + vchiq_log_error(vchiq_susp_log_level,
  21745. + "%s vchiq_release_service error %d",
  21746. + __func__, status);
  21747. + }
  21748. + }
  21749. + }
  21750. +
  21751. +shutdown:
  21752. + vchiq_shutdown(instance);
  21753. +exit:
  21754. + return 0;
  21755. +}
  21756. +
  21757. +
  21758. +
  21759. +VCHIQ_STATUS_T
  21760. +vchiq_arm_init_state(VCHIQ_STATE_T *state, VCHIQ_ARM_STATE_T *arm_state)
  21761. +{
  21762. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  21763. +
  21764. + if (arm_state) {
  21765. + rwlock_init(&arm_state->susp_res_lock);
  21766. +
  21767. + init_completion(&arm_state->ka_evt);
  21768. + atomic_set(&arm_state->ka_use_count, 0);
  21769. + atomic_set(&arm_state->ka_use_ack_count, 0);
  21770. + atomic_set(&arm_state->ka_release_count, 0);
  21771. +
  21772. + init_completion(&arm_state->vc_suspend_complete);
  21773. +
  21774. + init_completion(&arm_state->vc_resume_complete);
  21775. + /* Initialise to 'done' state. We only want to block on resume
  21776. + * completion while videocore is suspended. */
  21777. + set_resume_state(arm_state, VC_RESUME_RESUMED);
  21778. +
  21779. + init_completion(&arm_state->resume_blocker);
  21780. + /* Initialise to 'done' state. We only want to block on this
  21781. + * completion while resume is blocked */
  21782. + complete_all(&arm_state->resume_blocker);
  21783. +
  21784. + init_completion(&arm_state->blocked_blocker);
  21785. + /* Initialise to 'done' state. We only want to block on this
  21786. + * completion while things are waiting on the resume blocker */
  21787. + complete_all(&arm_state->blocked_blocker);
  21788. +
  21789. + arm_state->suspend_timer_timeout = SUSPEND_TIMER_TIMEOUT_MS;
  21790. + arm_state->suspend_timer_running = 0;
  21791. + init_timer(&arm_state->suspend_timer);
  21792. + arm_state->suspend_timer.data = (unsigned long)(state);
  21793. + arm_state->suspend_timer.function = suspend_timer_callback;
  21794. +
  21795. + arm_state->first_connect = 0;
  21796. +
  21797. + }
  21798. + return status;
  21799. +}
  21800. +
  21801. +/*
  21802. +** Functions to modify the state variables;
  21803. +** set_suspend_state
  21804. +** set_resume_state
  21805. +**
  21806. +** There are more state variables than we might like, so ensure they remain in
  21807. +** step. Suspend and resume state are maintained separately, since most of
  21808. +** these state machines can operate independently. However, there are a few
  21809. +** states where state transitions in one state machine cause a reset to the
  21810. +** other state machine. In addition, there are some completion events which
  21811. +** need to occur on state machine reset and end-state(s), so these are also
  21812. +** dealt with in these functions.
  21813. +**
  21814. +** In all states we set the state variable according to the input, but in some
  21815. +** cases we perform additional steps outlined below;
  21816. +**
  21817. +** VC_SUSPEND_IDLE - Initialise the suspend completion at the same time.
  21818. +** The suspend completion is completed after any suspend
  21819. +** attempt. When we reset the state machine we also reset
  21820. +** the completion. This reset occurs when videocore is
  21821. +** resumed, and also if we initiate suspend after a suspend
  21822. +** failure.
  21823. +**
  21824. +** VC_SUSPEND_IN_PROGRESS - This state is considered the point of no return for
  21825. +** suspend - ie from this point on we must try to suspend
  21826. +** before resuming can occur. We therefore also reset the
  21827. +** resume state machine to VC_RESUME_IDLE in this state.
  21828. +**
  21829. +** VC_SUSPEND_SUSPENDED - Suspend has completed successfully. Also call
  21830. +** complete_all on the suspend completion to notify
  21831. +** anything waiting for suspend to happen.
  21832. +**
  21833. +** VC_SUSPEND_REJECTED - Videocore rejected suspend. Videocore will also
  21834. +** initiate resume, so no need to alter resume state.
  21835. +** We call complete_all on the suspend completion to notify
  21836. +** of suspend rejection.
  21837. +**
  21838. +** VC_SUSPEND_FAILED - We failed to initiate videocore suspend. We notify the
  21839. +** suspend completion and reset the resume state machine.
  21840. +**
  21841. +** VC_RESUME_IDLE - Initialise the resume completion at the same time. The
  21842. +** resume completion is in it's 'done' state whenever
  21843. +** videcore is running. Therfore, the VC_RESUME_IDLE state
  21844. +** implies that videocore is suspended.
  21845. +** Hence, any thread which needs to wait until videocore is
  21846. +** running can wait on this completion - it will only block
  21847. +** if videocore is suspended.
  21848. +**
  21849. +** VC_RESUME_RESUMED - Resume has completed successfully. Videocore is running.
  21850. +** Call complete_all on the resume completion to unblock
  21851. +** any threads waiting for resume. Also reset the suspend
  21852. +** state machine to it's idle state.
  21853. +**
  21854. +** VC_RESUME_FAILED - Currently unused - no mechanism to fail resume exists.
  21855. +*/
  21856. +
  21857. +inline void
  21858. +set_suspend_state(VCHIQ_ARM_STATE_T *arm_state,
  21859. + enum vc_suspend_status new_state)
  21860. +{
  21861. + /* set the state in all cases */
  21862. + arm_state->vc_suspend_state = new_state;
  21863. +
  21864. + /* state specific additional actions */
  21865. + switch (new_state) {
  21866. + case VC_SUSPEND_FORCE_CANCELED:
  21867. + complete_all(&arm_state->vc_suspend_complete);
  21868. + break;
  21869. + case VC_SUSPEND_REJECTED:
  21870. + complete_all(&arm_state->vc_suspend_complete);
  21871. + break;
  21872. + case VC_SUSPEND_FAILED:
  21873. + complete_all(&arm_state->vc_suspend_complete);
  21874. + arm_state->vc_resume_state = VC_RESUME_RESUMED;
  21875. + complete_all(&arm_state->vc_resume_complete);
  21876. + break;
  21877. + case VC_SUSPEND_IDLE:
  21878. + INIT_COMPLETION(arm_state->vc_suspend_complete);
  21879. + break;
  21880. + case VC_SUSPEND_REQUESTED:
  21881. + break;
  21882. + case VC_SUSPEND_IN_PROGRESS:
  21883. + set_resume_state(arm_state, VC_RESUME_IDLE);
  21884. + break;
  21885. + case VC_SUSPEND_SUSPENDED:
  21886. + complete_all(&arm_state->vc_suspend_complete);
  21887. + break;
  21888. + default:
  21889. + BUG();
  21890. + break;
  21891. + }
  21892. +}
  21893. +
  21894. +inline void
  21895. +set_resume_state(VCHIQ_ARM_STATE_T *arm_state,
  21896. + enum vc_resume_status new_state)
  21897. +{
  21898. + /* set the state in all cases */
  21899. + arm_state->vc_resume_state = new_state;
  21900. +
  21901. + /* state specific additional actions */
  21902. + switch (new_state) {
  21903. + case VC_RESUME_FAILED:
  21904. + break;
  21905. + case VC_RESUME_IDLE:
  21906. + INIT_COMPLETION(arm_state->vc_resume_complete);
  21907. + break;
  21908. + case VC_RESUME_REQUESTED:
  21909. + break;
  21910. + case VC_RESUME_IN_PROGRESS:
  21911. + break;
  21912. + case VC_RESUME_RESUMED:
  21913. + complete_all(&arm_state->vc_resume_complete);
  21914. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  21915. + break;
  21916. + default:
  21917. + BUG();
  21918. + break;
  21919. + }
  21920. +}
  21921. +
  21922. +
  21923. +/* should be called with the write lock held */
  21924. +inline void
  21925. +start_suspend_timer(VCHIQ_ARM_STATE_T *arm_state)
  21926. +{
  21927. + del_timer(&arm_state->suspend_timer);
  21928. + arm_state->suspend_timer.expires = jiffies +
  21929. + msecs_to_jiffies(arm_state->
  21930. + suspend_timer_timeout);
  21931. + add_timer(&arm_state->suspend_timer);
  21932. + arm_state->suspend_timer_running = 1;
  21933. +}
  21934. +
  21935. +/* should be called with the write lock held */
  21936. +static inline void
  21937. +stop_suspend_timer(VCHIQ_ARM_STATE_T *arm_state)
  21938. +{
  21939. + if (arm_state->suspend_timer_running) {
  21940. + del_timer(&arm_state->suspend_timer);
  21941. + arm_state->suspend_timer_running = 0;
  21942. + }
  21943. +}
  21944. +
  21945. +static inline int
  21946. +need_resume(VCHIQ_STATE_T *state)
  21947. +{
  21948. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21949. + return (arm_state->vc_suspend_state > VC_SUSPEND_IDLE) &&
  21950. + (arm_state->vc_resume_state < VC_RESUME_REQUESTED) &&
  21951. + vchiq_videocore_wanted(state);
  21952. +}
  21953. +
  21954. +static int
  21955. +block_resume(VCHIQ_ARM_STATE_T *arm_state)
  21956. +{
  21957. + int status = VCHIQ_SUCCESS;
  21958. + const unsigned long timeout_val =
  21959. + msecs_to_jiffies(FORCE_SUSPEND_TIMEOUT_MS);
  21960. + int resume_count = 0;
  21961. +
  21962. + /* Allow any threads which were blocked by the last force suspend to
  21963. + * complete if they haven't already. Only give this one shot; if
  21964. + * blocked_count is incremented after blocked_blocker is completed
  21965. + * (which only happens when blocked_count hits 0) then those threads
  21966. + * will have to wait until next time around */
  21967. + if (arm_state->blocked_count) {
  21968. + INIT_COMPLETION(arm_state->blocked_blocker);
  21969. + write_unlock_bh(&arm_state->susp_res_lock);
  21970. + vchiq_log_info(vchiq_susp_log_level, "%s wait for previously "
  21971. + "blocked clients", __func__);
  21972. + if (wait_for_completion_interruptible_timeout(
  21973. + &arm_state->blocked_blocker, timeout_val)
  21974. + <= 0) {
  21975. + vchiq_log_error(vchiq_susp_log_level, "%s wait for "
  21976. + "previously blocked clients failed" , __func__);
  21977. + status = VCHIQ_ERROR;
  21978. + write_lock_bh(&arm_state->susp_res_lock);
  21979. + goto out;
  21980. + }
  21981. + vchiq_log_info(vchiq_susp_log_level, "%s previously blocked "
  21982. + "clients resumed", __func__);
  21983. + write_lock_bh(&arm_state->susp_res_lock);
  21984. + }
  21985. +
  21986. + /* We need to wait for resume to complete if it's in process */
  21987. + while (arm_state->vc_resume_state != VC_RESUME_RESUMED &&
  21988. + arm_state->vc_resume_state > VC_RESUME_IDLE) {
  21989. + if (resume_count > 1) {
  21990. + status = VCHIQ_ERROR;
  21991. + vchiq_log_error(vchiq_susp_log_level, "%s waited too "
  21992. + "many times for resume" , __func__);
  21993. + goto out;
  21994. + }
  21995. + write_unlock_bh(&arm_state->susp_res_lock);
  21996. + vchiq_log_info(vchiq_susp_log_level, "%s wait for resume",
  21997. + __func__);
  21998. + if (wait_for_completion_interruptible_timeout(
  21999. + &arm_state->vc_resume_complete, timeout_val)
  22000. + <= 0) {
  22001. + vchiq_log_error(vchiq_susp_log_level, "%s wait for "
  22002. + "resume failed (%s)", __func__,
  22003. + resume_state_names[arm_state->vc_resume_state +
  22004. + VC_RESUME_NUM_OFFSET]);
  22005. + status = VCHIQ_ERROR;
  22006. + write_lock_bh(&arm_state->susp_res_lock);
  22007. + goto out;
  22008. + }
  22009. + vchiq_log_info(vchiq_susp_log_level, "%s resumed", __func__);
  22010. + write_lock_bh(&arm_state->susp_res_lock);
  22011. + resume_count++;
  22012. + }
  22013. + INIT_COMPLETION(arm_state->resume_blocker);
  22014. + arm_state->resume_blocked = 1;
  22015. +
  22016. +out:
  22017. + return status;
  22018. +}
  22019. +
  22020. +static inline void
  22021. +unblock_resume(VCHIQ_ARM_STATE_T *arm_state)
  22022. +{
  22023. + complete_all(&arm_state->resume_blocker);
  22024. + arm_state->resume_blocked = 0;
  22025. +}
  22026. +
  22027. +/* Initiate suspend via slot handler. Should be called with the write lock
  22028. + * held */
  22029. +VCHIQ_STATUS_T
  22030. +vchiq_arm_vcsuspend(VCHIQ_STATE_T *state)
  22031. +{
  22032. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  22033. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22034. +
  22035. + if (!arm_state)
  22036. + goto out;
  22037. +
  22038. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22039. + status = VCHIQ_SUCCESS;
  22040. +
  22041. +
  22042. + switch (arm_state->vc_suspend_state) {
  22043. + case VC_SUSPEND_REQUESTED:
  22044. + vchiq_log_info(vchiq_susp_log_level, "%s: suspend already "
  22045. + "requested", __func__);
  22046. + break;
  22047. + case VC_SUSPEND_IN_PROGRESS:
  22048. + vchiq_log_info(vchiq_susp_log_level, "%s: suspend already in "
  22049. + "progress", __func__);
  22050. + break;
  22051. +
  22052. + default:
  22053. + /* We don't expect to be in other states, so log but continue
  22054. + * anyway */
  22055. + vchiq_log_error(vchiq_susp_log_level,
  22056. + "%s unexpected suspend state %s", __func__,
  22057. + suspend_state_names[arm_state->vc_suspend_state +
  22058. + VC_SUSPEND_NUM_OFFSET]);
  22059. + /* fall through */
  22060. + case VC_SUSPEND_REJECTED:
  22061. + case VC_SUSPEND_FAILED:
  22062. + /* Ensure any idle state actions have been run */
  22063. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  22064. + /* fall through */
  22065. + case VC_SUSPEND_IDLE:
  22066. + vchiq_log_info(vchiq_susp_log_level,
  22067. + "%s: suspending", __func__);
  22068. + set_suspend_state(arm_state, VC_SUSPEND_REQUESTED);
  22069. + /* kick the slot handler thread to initiate suspend */
  22070. + request_poll(state, NULL, 0);
  22071. + break;
  22072. + }
  22073. +
  22074. +out:
  22075. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, status);
  22076. + return status;
  22077. +}
  22078. +
  22079. +void
  22080. +vchiq_platform_check_suspend(VCHIQ_STATE_T *state)
  22081. +{
  22082. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22083. + int susp = 0;
  22084. +
  22085. + if (!arm_state)
  22086. + goto out;
  22087. +
  22088. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22089. +
  22090. + write_lock_bh(&arm_state->susp_res_lock);
  22091. + if (arm_state->vc_suspend_state == VC_SUSPEND_REQUESTED &&
  22092. + arm_state->vc_resume_state == VC_RESUME_RESUMED) {
  22093. + set_suspend_state(arm_state, VC_SUSPEND_IN_PROGRESS);
  22094. + susp = 1;
  22095. + }
  22096. + write_unlock_bh(&arm_state->susp_res_lock);
  22097. +
  22098. + if (susp)
  22099. + vchiq_platform_suspend(state);
  22100. +
  22101. +out:
  22102. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  22103. + return;
  22104. +}
  22105. +
  22106. +
  22107. +static void
  22108. +output_timeout_error(VCHIQ_STATE_T *state)
  22109. +{
  22110. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22111. + char service_err[50] = "";
  22112. + int vc_use_count = arm_state->videocore_use_count;
  22113. + int active_services = state->unused_service;
  22114. + int i;
  22115. +
  22116. + if (!arm_state->videocore_use_count) {
  22117. + snprintf(service_err, 50, " Videocore usecount is 0");
  22118. + goto output_msg;
  22119. + }
  22120. + for (i = 0; i < active_services; i++) {
  22121. + VCHIQ_SERVICE_T *service_ptr = state->services[i];
  22122. + if (service_ptr && service_ptr->service_use_count &&
  22123. + (service_ptr->srvstate != VCHIQ_SRVSTATE_FREE)) {
  22124. + snprintf(service_err, 50, " %c%c%c%c(%d) service has "
  22125. + "use count %d%s", VCHIQ_FOURCC_AS_4CHARS(
  22126. + service_ptr->base.fourcc),
  22127. + service_ptr->client_id,
  22128. + service_ptr->service_use_count,
  22129. + service_ptr->service_use_count ==
  22130. + vc_use_count ? "" : " (+ more)");
  22131. + break;
  22132. + }
  22133. + }
  22134. +
  22135. +output_msg:
  22136. + vchiq_log_error(vchiq_susp_log_level,
  22137. + "timed out waiting for vc suspend (%d).%s",
  22138. + arm_state->autosuspend_override, service_err);
  22139. +
  22140. +}
  22141. +
  22142. +/* Try to get videocore into suspended state, regardless of autosuspend state.
  22143. +** We don't actually force suspend, since videocore may get into a bad state
  22144. +** if we force suspend at a bad time. Instead, we wait for autosuspend to
  22145. +** determine a good point to suspend. If this doesn't happen within 100ms we
  22146. +** report failure.
  22147. +**
  22148. +** Returns VCHIQ_SUCCESS if videocore suspended successfully, VCHIQ_RETRY if
  22149. +** videocore failed to suspend in time or VCHIQ_ERROR if interrupted.
  22150. +*/
  22151. +VCHIQ_STATUS_T
  22152. +vchiq_arm_force_suspend(VCHIQ_STATE_T *state)
  22153. +{
  22154. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22155. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  22156. + long rc = 0;
  22157. + int repeat = -1;
  22158. +
  22159. + if (!arm_state)
  22160. + goto out;
  22161. +
  22162. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22163. +
  22164. + write_lock_bh(&arm_state->susp_res_lock);
  22165. +
  22166. + status = block_resume(arm_state);
  22167. + if (status != VCHIQ_SUCCESS)
  22168. + goto unlock;
  22169. + if (arm_state->vc_suspend_state == VC_SUSPEND_SUSPENDED) {
  22170. + /* Already suspended - just block resume and exit */
  22171. + vchiq_log_info(vchiq_susp_log_level, "%s already suspended",
  22172. + __func__);
  22173. + status = VCHIQ_SUCCESS;
  22174. + goto unlock;
  22175. + } else if (arm_state->vc_suspend_state <= VC_SUSPEND_IDLE) {
  22176. + /* initiate suspend immediately in the case that we're waiting
  22177. + * for the timeout */
  22178. + stop_suspend_timer(arm_state);
  22179. + if (!vchiq_videocore_wanted(state)) {
  22180. + vchiq_log_info(vchiq_susp_log_level, "%s videocore "
  22181. + "idle, initiating suspend", __func__);
  22182. + status = vchiq_arm_vcsuspend(state);
  22183. + } else if (arm_state->autosuspend_override <
  22184. + FORCE_SUSPEND_FAIL_MAX) {
  22185. + vchiq_log_info(vchiq_susp_log_level, "%s letting "
  22186. + "videocore go idle", __func__);
  22187. + status = VCHIQ_SUCCESS;
  22188. + } else {
  22189. + vchiq_log_warning(vchiq_susp_log_level, "%s failed too "
  22190. + "many times - attempting suspend", __func__);
  22191. + status = vchiq_arm_vcsuspend(state);
  22192. + }
  22193. + } else {
  22194. + vchiq_log_info(vchiq_susp_log_level, "%s videocore suspend "
  22195. + "in progress - wait for completion", __func__);
  22196. + status = VCHIQ_SUCCESS;
  22197. + }
  22198. +
  22199. + /* Wait for suspend to happen due to system idle (not forced..) */
  22200. + if (status != VCHIQ_SUCCESS)
  22201. + goto unblock_resume;
  22202. +
  22203. + do {
  22204. + write_unlock_bh(&arm_state->susp_res_lock);
  22205. +
  22206. + rc = wait_for_completion_interruptible_timeout(
  22207. + &arm_state->vc_suspend_complete,
  22208. + msecs_to_jiffies(FORCE_SUSPEND_TIMEOUT_MS));
  22209. +
  22210. + write_lock_bh(&arm_state->susp_res_lock);
  22211. + if (rc < 0) {
  22212. + vchiq_log_warning(vchiq_susp_log_level, "%s "
  22213. + "interrupted waiting for suspend", __func__);
  22214. + status = VCHIQ_ERROR;
  22215. + goto unblock_resume;
  22216. + } else if (rc == 0) {
  22217. + if (arm_state->vc_suspend_state > VC_SUSPEND_IDLE) {
  22218. + /* Repeat timeout once if in progress */
  22219. + if (repeat < 0) {
  22220. + repeat = 1;
  22221. + continue;
  22222. + }
  22223. + }
  22224. + arm_state->autosuspend_override++;
  22225. + output_timeout_error(state);
  22226. +
  22227. + status = VCHIQ_RETRY;
  22228. + goto unblock_resume;
  22229. + }
  22230. + } while (0 < (repeat--));
  22231. +
  22232. + /* Check and report state in case we need to abort ARM suspend */
  22233. + if (arm_state->vc_suspend_state != VC_SUSPEND_SUSPENDED) {
  22234. + status = VCHIQ_RETRY;
  22235. + vchiq_log_error(vchiq_susp_log_level,
  22236. + "%s videocore suspend failed (state %s)", __func__,
  22237. + suspend_state_names[arm_state->vc_suspend_state +
  22238. + VC_SUSPEND_NUM_OFFSET]);
  22239. + /* Reset the state only if it's still in an error state.
  22240. + * Something could have already initiated another suspend. */
  22241. + if (arm_state->vc_suspend_state < VC_SUSPEND_IDLE)
  22242. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  22243. +
  22244. + goto unblock_resume;
  22245. + }
  22246. +
  22247. + /* successfully suspended - unlock and exit */
  22248. + goto unlock;
  22249. +
  22250. +unblock_resume:
  22251. + /* all error states need to unblock resume before exit */
  22252. + unblock_resume(arm_state);
  22253. +
  22254. +unlock:
  22255. + write_unlock_bh(&arm_state->susp_res_lock);
  22256. +
  22257. +out:
  22258. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, status);
  22259. + return status;
  22260. +}
  22261. +
  22262. +void
  22263. +vchiq_check_suspend(VCHIQ_STATE_T *state)
  22264. +{
  22265. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22266. +
  22267. + if (!arm_state)
  22268. + goto out;
  22269. +
  22270. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22271. +
  22272. + write_lock_bh(&arm_state->susp_res_lock);
  22273. + if (arm_state->vc_suspend_state != VC_SUSPEND_SUSPENDED &&
  22274. + arm_state->first_connect &&
  22275. + !vchiq_videocore_wanted(state)) {
  22276. + vchiq_arm_vcsuspend(state);
  22277. + }
  22278. + write_unlock_bh(&arm_state->susp_res_lock);
  22279. +
  22280. +out:
  22281. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  22282. + return;
  22283. +}
  22284. +
  22285. +
  22286. +int
  22287. +vchiq_arm_allow_resume(VCHIQ_STATE_T *state)
  22288. +{
  22289. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22290. + int resume = 0;
  22291. + int ret = -1;
  22292. +
  22293. + if (!arm_state)
  22294. + goto out;
  22295. +
  22296. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22297. +
  22298. + write_lock_bh(&arm_state->susp_res_lock);
  22299. + unblock_resume(arm_state);
  22300. + resume = vchiq_check_resume(state);
  22301. + write_unlock_bh(&arm_state->susp_res_lock);
  22302. +
  22303. + if (resume) {
  22304. + if (wait_for_completion_interruptible(
  22305. + &arm_state->vc_resume_complete) < 0) {
  22306. + vchiq_log_error(vchiq_susp_log_level,
  22307. + "%s interrupted", __func__);
  22308. + /* failed, cannot accurately derive suspend
  22309. + * state, so exit early. */
  22310. + goto out;
  22311. + }
  22312. + }
  22313. +
  22314. + read_lock_bh(&arm_state->susp_res_lock);
  22315. + if (arm_state->vc_suspend_state == VC_SUSPEND_SUSPENDED) {
  22316. + vchiq_log_info(vchiq_susp_log_level,
  22317. + "%s: Videocore remains suspended", __func__);
  22318. + } else {
  22319. + vchiq_log_info(vchiq_susp_log_level,
  22320. + "%s: Videocore resumed", __func__);
  22321. + ret = 0;
  22322. + }
  22323. + read_unlock_bh(&arm_state->susp_res_lock);
  22324. +out:
  22325. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, ret);
  22326. + return ret;
  22327. +}
  22328. +
  22329. +/* This function should be called with the write lock held */
  22330. +int
  22331. +vchiq_check_resume(VCHIQ_STATE_T *state)
  22332. +{
  22333. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22334. + int resume = 0;
  22335. +
  22336. + if (!arm_state)
  22337. + goto out;
  22338. +
  22339. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22340. +
  22341. + if (need_resume(state)) {
  22342. + set_resume_state(arm_state, VC_RESUME_REQUESTED);
  22343. + request_poll(state, NULL, 0);
  22344. + resume = 1;
  22345. + }
  22346. +
  22347. +out:
  22348. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  22349. + return resume;
  22350. +}
  22351. +
  22352. +void
  22353. +vchiq_platform_check_resume(VCHIQ_STATE_T *state)
  22354. +{
  22355. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22356. + int res = 0;
  22357. +
  22358. + if (!arm_state)
  22359. + goto out;
  22360. +
  22361. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22362. +
  22363. + write_lock_bh(&arm_state->susp_res_lock);
  22364. + if (arm_state->wake_address == 0) {
  22365. + vchiq_log_info(vchiq_susp_log_level,
  22366. + "%s: already awake", __func__);
  22367. + goto unlock;
  22368. + }
  22369. + if (arm_state->vc_resume_state == VC_RESUME_IN_PROGRESS) {
  22370. + vchiq_log_info(vchiq_susp_log_level,
  22371. + "%s: already resuming", __func__);
  22372. + goto unlock;
  22373. + }
  22374. +
  22375. + if (arm_state->vc_resume_state == VC_RESUME_REQUESTED) {
  22376. + set_resume_state(arm_state, VC_RESUME_IN_PROGRESS);
  22377. + res = 1;
  22378. + } else
  22379. + vchiq_log_trace(vchiq_susp_log_level,
  22380. + "%s: not resuming (resume state %s)", __func__,
  22381. + resume_state_names[arm_state->vc_resume_state +
  22382. + VC_RESUME_NUM_OFFSET]);
  22383. +
  22384. +unlock:
  22385. + write_unlock_bh(&arm_state->susp_res_lock);
  22386. +
  22387. + if (res)
  22388. + vchiq_platform_resume(state);
  22389. +
  22390. +out:
  22391. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  22392. + return;
  22393. +
  22394. +}
  22395. +
  22396. +
  22397. +
  22398. +VCHIQ_STATUS_T
  22399. +vchiq_use_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  22400. + enum USE_TYPE_E use_type)
  22401. +{
  22402. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22403. + VCHIQ_STATUS_T ret = VCHIQ_SUCCESS;
  22404. + char entity[16];
  22405. + int *entity_uc;
  22406. + int local_uc, local_entity_uc;
  22407. +
  22408. + if (!arm_state)
  22409. + goto out;
  22410. +
  22411. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22412. +
  22413. + if (use_type == USE_TYPE_VCHIQ) {
  22414. + sprintf(entity, "VCHIQ: ");
  22415. + entity_uc = &arm_state->peer_use_count;
  22416. + } else if (service) {
  22417. + sprintf(entity, "%c%c%c%c:%03d",
  22418. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  22419. + service->client_id);
  22420. + entity_uc = &service->service_use_count;
  22421. + } else {
  22422. + vchiq_log_error(vchiq_susp_log_level, "%s null service "
  22423. + "ptr", __func__);
  22424. + ret = VCHIQ_ERROR;
  22425. + goto out;
  22426. + }
  22427. +
  22428. + write_lock_bh(&arm_state->susp_res_lock);
  22429. + while (arm_state->resume_blocked) {
  22430. + /* If we call 'use' while force suspend is waiting for suspend,
  22431. + * then we're about to block the thread which the force is
  22432. + * waiting to complete, so we're bound to just time out. In this
  22433. + * case, set the suspend state such that the wait will be
  22434. + * canceled, so we can complete as quickly as possible. */
  22435. + if (arm_state->resume_blocked && arm_state->vc_suspend_state ==
  22436. + VC_SUSPEND_IDLE) {
  22437. + set_suspend_state(arm_state, VC_SUSPEND_FORCE_CANCELED);
  22438. + break;
  22439. + }
  22440. + /* If suspend is already in progress then we need to block */
  22441. + if (!try_wait_for_completion(&arm_state->resume_blocker)) {
  22442. + /* Indicate that there are threads waiting on the resume
  22443. + * blocker. These need to be allowed to complete before
  22444. + * a _second_ call to force suspend can complete,
  22445. + * otherwise low priority threads might never actually
  22446. + * continue */
  22447. + arm_state->blocked_count++;
  22448. + write_unlock_bh(&arm_state->susp_res_lock);
  22449. + vchiq_log_info(vchiq_susp_log_level, "%s %s resume "
  22450. + "blocked - waiting...", __func__, entity);
  22451. + if (wait_for_completion_killable(
  22452. + &arm_state->resume_blocker) != 0) {
  22453. + vchiq_log_error(vchiq_susp_log_level, "%s %s "
  22454. + "wait for resume blocker interrupted",
  22455. + __func__, entity);
  22456. + ret = VCHIQ_ERROR;
  22457. + write_lock_bh(&arm_state->susp_res_lock);
  22458. + arm_state->blocked_count--;
  22459. + write_unlock_bh(&arm_state->susp_res_lock);
  22460. + goto out;
  22461. + }
  22462. + vchiq_log_info(vchiq_susp_log_level, "%s %s resume "
  22463. + "unblocked", __func__, entity);
  22464. + write_lock_bh(&arm_state->susp_res_lock);
  22465. + if (--arm_state->blocked_count == 0)
  22466. + complete_all(&arm_state->blocked_blocker);
  22467. + }
  22468. + }
  22469. +
  22470. + stop_suspend_timer(arm_state);
  22471. +
  22472. + local_uc = ++arm_state->videocore_use_count;
  22473. + local_entity_uc = ++(*entity_uc);
  22474. +
  22475. + /* If there's a pending request which hasn't yet been serviced then
  22476. + * just clear it. If we're past VC_SUSPEND_REQUESTED state then
  22477. + * vc_resume_complete will block until we either resume or fail to
  22478. + * suspend */
  22479. + if (arm_state->vc_suspend_state <= VC_SUSPEND_REQUESTED)
  22480. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  22481. +
  22482. + if ((use_type != USE_TYPE_SERVICE_NO_RESUME) && need_resume(state)) {
  22483. + set_resume_state(arm_state, VC_RESUME_REQUESTED);
  22484. + vchiq_log_info(vchiq_susp_log_level,
  22485. + "%s %s count %d, state count %d",
  22486. + __func__, entity, local_entity_uc, local_uc);
  22487. + request_poll(state, NULL, 0);
  22488. + } else
  22489. + vchiq_log_trace(vchiq_susp_log_level,
  22490. + "%s %s count %d, state count %d",
  22491. + __func__, entity, *entity_uc, local_uc);
  22492. +
  22493. +
  22494. + write_unlock_bh(&arm_state->susp_res_lock);
  22495. +
  22496. + /* Completion is in a done state when we're not suspended, so this won't
  22497. + * block for the non-suspended case. */
  22498. + if (!try_wait_for_completion(&arm_state->vc_resume_complete)) {
  22499. + vchiq_log_info(vchiq_susp_log_level, "%s %s wait for resume",
  22500. + __func__, entity);
  22501. + if (wait_for_completion_killable(
  22502. + &arm_state->vc_resume_complete) != 0) {
  22503. + vchiq_log_error(vchiq_susp_log_level, "%s %s wait for "
  22504. + "resume interrupted", __func__, entity);
  22505. + ret = VCHIQ_ERROR;
  22506. + goto out;
  22507. + }
  22508. + vchiq_log_info(vchiq_susp_log_level, "%s %s resumed", __func__,
  22509. + entity);
  22510. + }
  22511. +
  22512. + if (ret == VCHIQ_SUCCESS) {
  22513. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  22514. + long ack_cnt = atomic_xchg(&arm_state->ka_use_ack_count, 0);
  22515. + while (ack_cnt && (status == VCHIQ_SUCCESS)) {
  22516. + /* Send the use notify to videocore */
  22517. + status = vchiq_send_remote_use_active(state);
  22518. + if (status == VCHIQ_SUCCESS)
  22519. + ack_cnt--;
  22520. + else
  22521. + atomic_add(ack_cnt,
  22522. + &arm_state->ka_use_ack_count);
  22523. + }
  22524. + }
  22525. +
  22526. +out:
  22527. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, ret);
  22528. + return ret;
  22529. +}
  22530. +
  22531. +VCHIQ_STATUS_T
  22532. +vchiq_release_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service)
  22533. +{
  22534. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22535. + VCHIQ_STATUS_T ret = VCHIQ_SUCCESS;
  22536. + char entity[16];
  22537. + int *entity_uc;
  22538. + int local_uc, local_entity_uc;
  22539. +
  22540. + if (!arm_state)
  22541. + goto out;
  22542. +
  22543. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22544. +
  22545. + if (service) {
  22546. + sprintf(entity, "%c%c%c%c:%03d",
  22547. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  22548. + service->client_id);
  22549. + entity_uc = &service->service_use_count;
  22550. + } else {
  22551. + sprintf(entity, "PEER: ");
  22552. + entity_uc = &arm_state->peer_use_count;
  22553. + }
  22554. +
  22555. + write_lock_bh(&arm_state->susp_res_lock);
  22556. + if (!arm_state->videocore_use_count || !(*entity_uc)) {
  22557. + /* Don't use BUG_ON - don't allow user thread to crash kernel */
  22558. + WARN_ON(!arm_state->videocore_use_count);
  22559. + WARN_ON(!(*entity_uc));
  22560. + ret = VCHIQ_ERROR;
  22561. + goto unlock;
  22562. + }
  22563. + local_uc = --arm_state->videocore_use_count;
  22564. + local_entity_uc = --(*entity_uc);
  22565. +
  22566. + if (!vchiq_videocore_wanted(state)) {
  22567. + if (vchiq_platform_use_suspend_timer() &&
  22568. + !arm_state->resume_blocked) {
  22569. + /* Only use the timer if we're not trying to force
  22570. + * suspend (=> resume_blocked) */
  22571. + start_suspend_timer(arm_state);
  22572. + } else {
  22573. + vchiq_log_info(vchiq_susp_log_level,
  22574. + "%s %s count %d, state count %d - suspending",
  22575. + __func__, entity, *entity_uc,
  22576. + arm_state->videocore_use_count);
  22577. + vchiq_arm_vcsuspend(state);
  22578. + }
  22579. + } else
  22580. + vchiq_log_trace(vchiq_susp_log_level,
  22581. + "%s %s count %d, state count %d",
  22582. + __func__, entity, *entity_uc,
  22583. + arm_state->videocore_use_count);
  22584. +
  22585. +unlock:
  22586. + write_unlock_bh(&arm_state->susp_res_lock);
  22587. +
  22588. +out:
  22589. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, ret);
  22590. + return ret;
  22591. +}
  22592. +
  22593. +void
  22594. +vchiq_on_remote_use(VCHIQ_STATE_T *state)
  22595. +{
  22596. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22597. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22598. + atomic_inc(&arm_state->ka_use_count);
  22599. + complete(&arm_state->ka_evt);
  22600. +}
  22601. +
  22602. +void
  22603. +vchiq_on_remote_release(VCHIQ_STATE_T *state)
  22604. +{
  22605. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22606. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22607. + atomic_inc(&arm_state->ka_release_count);
  22608. + complete(&arm_state->ka_evt);
  22609. +}
  22610. +
  22611. +VCHIQ_STATUS_T
  22612. +vchiq_use_service_internal(VCHIQ_SERVICE_T *service)
  22613. +{
  22614. + return vchiq_use_internal(service->state, service, USE_TYPE_SERVICE);
  22615. +}
  22616. +
  22617. +VCHIQ_STATUS_T
  22618. +vchiq_release_service_internal(VCHIQ_SERVICE_T *service)
  22619. +{
  22620. + return vchiq_release_internal(service->state, service);
  22621. +}
  22622. +
  22623. +static void suspend_timer_callback(unsigned long context)
  22624. +{
  22625. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *)context;
  22626. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22627. + if (!arm_state)
  22628. + goto out;
  22629. + vchiq_log_info(vchiq_susp_log_level,
  22630. + "%s - suspend timer expired - check suspend", __func__);
  22631. + vchiq_check_suspend(state);
  22632. +out:
  22633. + return;
  22634. +}
  22635. +
  22636. +VCHIQ_STATUS_T
  22637. +vchiq_use_service_no_resume(VCHIQ_SERVICE_HANDLE_T handle)
  22638. +{
  22639. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  22640. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  22641. + if (service) {
  22642. + ret = vchiq_use_internal(service->state, service,
  22643. + USE_TYPE_SERVICE_NO_RESUME);
  22644. + unlock_service(service);
  22645. + }
  22646. + return ret;
  22647. +}
  22648. +
  22649. +VCHIQ_STATUS_T
  22650. +vchiq_use_service(VCHIQ_SERVICE_HANDLE_T handle)
  22651. +{
  22652. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  22653. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  22654. + if (service) {
  22655. + ret = vchiq_use_internal(service->state, service,
  22656. + USE_TYPE_SERVICE);
  22657. + unlock_service(service);
  22658. + }
  22659. + return ret;
  22660. +}
  22661. +
  22662. +VCHIQ_STATUS_T
  22663. +vchiq_release_service(VCHIQ_SERVICE_HANDLE_T handle)
  22664. +{
  22665. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  22666. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  22667. + if (service) {
  22668. + ret = vchiq_release_internal(service->state, service);
  22669. + unlock_service(service);
  22670. + }
  22671. + return ret;
  22672. +}
  22673. +
  22674. +void
  22675. +vchiq_dump_service_use_state(VCHIQ_STATE_T *state)
  22676. +{
  22677. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22678. + int i, j = 0;
  22679. + /* Only dump 64 services */
  22680. + static const int local_max_services = 64;
  22681. + /* If there's more than 64 services, only dump ones with
  22682. + * non-zero counts */
  22683. + int only_nonzero = 0;
  22684. + static const char *nz = "<-- preventing suspend";
  22685. +
  22686. + enum vc_suspend_status vc_suspend_state;
  22687. + enum vc_resume_status vc_resume_state;
  22688. + int peer_count;
  22689. + int vc_use_count;
  22690. + int active_services;
  22691. + struct service_data_struct {
  22692. + int fourcc;
  22693. + int clientid;
  22694. + int use_count;
  22695. + } service_data[local_max_services];
  22696. +
  22697. + if (!arm_state)
  22698. + return;
  22699. +
  22700. + read_lock_bh(&arm_state->susp_res_lock);
  22701. + vc_suspend_state = arm_state->vc_suspend_state;
  22702. + vc_resume_state = arm_state->vc_resume_state;
  22703. + peer_count = arm_state->peer_use_count;
  22704. + vc_use_count = arm_state->videocore_use_count;
  22705. + active_services = state->unused_service;
  22706. + if (active_services > local_max_services)
  22707. + only_nonzero = 1;
  22708. +
  22709. + for (i = 0; (i < active_services) && (j < local_max_services); i++) {
  22710. + VCHIQ_SERVICE_T *service_ptr = state->services[i];
  22711. + if (!service_ptr)
  22712. + continue;
  22713. +
  22714. + if (only_nonzero && !service_ptr->service_use_count)
  22715. + continue;
  22716. +
  22717. + if (service_ptr->srvstate != VCHIQ_SRVSTATE_FREE) {
  22718. + service_data[j].fourcc = service_ptr->base.fourcc;
  22719. + service_data[j].clientid = service_ptr->client_id;
  22720. + service_data[j++].use_count = service_ptr->
  22721. + service_use_count;
  22722. + }
  22723. + }
  22724. +
  22725. + read_unlock_bh(&arm_state->susp_res_lock);
  22726. +
  22727. + vchiq_log_warning(vchiq_susp_log_level,
  22728. + "-- Videcore suspend state: %s --",
  22729. + suspend_state_names[vc_suspend_state + VC_SUSPEND_NUM_OFFSET]);
  22730. + vchiq_log_warning(vchiq_susp_log_level,
  22731. + "-- Videcore resume state: %s --",
  22732. + resume_state_names[vc_resume_state + VC_RESUME_NUM_OFFSET]);
  22733. +
  22734. + if (only_nonzero)
  22735. + vchiq_log_warning(vchiq_susp_log_level, "Too many active "
  22736. + "services (%d). Only dumping up to first %d services "
  22737. + "with non-zero use-count", active_services,
  22738. + local_max_services);
  22739. +
  22740. + for (i = 0; i < j; i++) {
  22741. + vchiq_log_warning(vchiq_susp_log_level,
  22742. + "----- %c%c%c%c:%d service count %d %s",
  22743. + VCHIQ_FOURCC_AS_4CHARS(service_data[i].fourcc),
  22744. + service_data[i].clientid,
  22745. + service_data[i].use_count,
  22746. + service_data[i].use_count ? nz : "");
  22747. + }
  22748. + vchiq_log_warning(vchiq_susp_log_level,
  22749. + "----- VCHIQ use count count %d", peer_count);
  22750. + vchiq_log_warning(vchiq_susp_log_level,
  22751. + "--- Overall vchiq instance use count %d", vc_use_count);
  22752. +
  22753. + vchiq_dump_platform_use_state(state);
  22754. +}
  22755. +
  22756. +VCHIQ_STATUS_T
  22757. +vchiq_check_service(VCHIQ_SERVICE_T *service)
  22758. +{
  22759. + VCHIQ_ARM_STATE_T *arm_state;
  22760. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  22761. +
  22762. + if (!service || !service->state)
  22763. + goto out;
  22764. +
  22765. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22766. +
  22767. + arm_state = vchiq_platform_get_arm_state(service->state);
  22768. +
  22769. + read_lock_bh(&arm_state->susp_res_lock);
  22770. + if (service->service_use_count)
  22771. + ret = VCHIQ_SUCCESS;
  22772. + read_unlock_bh(&arm_state->susp_res_lock);
  22773. +
  22774. + if (ret == VCHIQ_ERROR) {
  22775. + vchiq_log_error(vchiq_susp_log_level,
  22776. + "%s ERROR - %c%c%c%c:%d service count %d, "
  22777. + "state count %d, videocore suspend state %s", __func__,
  22778. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  22779. + service->client_id, service->service_use_count,
  22780. + arm_state->videocore_use_count,
  22781. + suspend_state_names[arm_state->vc_suspend_state +
  22782. + VC_SUSPEND_NUM_OFFSET]);
  22783. + vchiq_dump_service_use_state(service->state);
  22784. + }
  22785. +out:
  22786. + return ret;
  22787. +}
  22788. +
  22789. +/* stub functions */
  22790. +void vchiq_on_remote_use_active(VCHIQ_STATE_T *state)
  22791. +{
  22792. + (void)state;
  22793. +}
  22794. +
  22795. +void vchiq_platform_conn_state_changed(VCHIQ_STATE_T *state,
  22796. + VCHIQ_CONNSTATE_T oldstate, VCHIQ_CONNSTATE_T newstate)
  22797. +{
  22798. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22799. + vchiq_log_info(vchiq_susp_log_level, "%d: %s->%s", state->id,
  22800. + get_conn_state_name(oldstate), get_conn_state_name(newstate));
  22801. + if (state->conn_state == VCHIQ_CONNSTATE_CONNECTED) {
  22802. + write_lock_bh(&arm_state->susp_res_lock);
  22803. + if (!arm_state->first_connect) {
  22804. + char threadname[10];
  22805. + arm_state->first_connect = 1;
  22806. + write_unlock_bh(&arm_state->susp_res_lock);
  22807. + snprintf(threadname, sizeof(threadname), "VCHIQka-%d",
  22808. + state->id);
  22809. + arm_state->ka_thread = kthread_create(
  22810. + &vchiq_keepalive_thread_func,
  22811. + (void *)state,
  22812. + threadname);
  22813. + if (arm_state->ka_thread == NULL) {
  22814. + vchiq_log_error(vchiq_susp_log_level,
  22815. + "vchiq: FATAL: couldn't create thread %s",
  22816. + threadname);
  22817. + } else {
  22818. + wake_up_process(arm_state->ka_thread);
  22819. + }
  22820. + } else
  22821. + write_unlock_bh(&arm_state->susp_res_lock);
  22822. + }
  22823. +}
  22824. +
  22825. +
  22826. +/****************************************************************************
  22827. +*
  22828. +* vchiq_init - called when the module is loaded.
  22829. +*
  22830. +***************************************************************************/
  22831. +
  22832. +static int __init
  22833. +vchiq_init(void)
  22834. +{
  22835. + int err;
  22836. + void *ptr_err;
  22837. +
  22838. + /* create proc entries */
  22839. + err = vchiq_proc_init();
  22840. + if (err != 0)
  22841. + goto failed_proc_init;
  22842. +
  22843. + err = alloc_chrdev_region(&vchiq_devid, VCHIQ_MINOR, 1, DEVICE_NAME);
  22844. + if (err != 0) {
  22845. + vchiq_log_error(vchiq_arm_log_level,
  22846. + "Unable to allocate device number");
  22847. + goto failed_alloc_chrdev;
  22848. + }
  22849. + cdev_init(&vchiq_cdev, &vchiq_fops);
  22850. + vchiq_cdev.owner = THIS_MODULE;
  22851. + err = cdev_add(&vchiq_cdev, vchiq_devid, 1);
  22852. + if (err != 0) {
  22853. + vchiq_log_error(vchiq_arm_log_level,
  22854. + "Unable to register device");
  22855. + goto failed_cdev_add;
  22856. + }
  22857. +
  22858. + /* create sysfs entries */
  22859. + vchiq_class = class_create(THIS_MODULE, DEVICE_NAME);
  22860. + ptr_err = vchiq_class;
  22861. + if (IS_ERR(ptr_err))
  22862. + goto failed_class_create;
  22863. +
  22864. + vchiq_dev = device_create(vchiq_class, NULL,
  22865. + vchiq_devid, NULL, "vchiq");
  22866. + ptr_err = vchiq_dev;
  22867. + if (IS_ERR(ptr_err))
  22868. + goto failed_device_create;
  22869. +
  22870. + err = vchiq_platform_init(&g_state);
  22871. + if (err != 0)
  22872. + goto failed_platform_init;
  22873. +
  22874. + vchiq_log_info(vchiq_arm_log_level,
  22875. + "vchiq: initialised - version %d (min %d), device %d.%d",
  22876. + VCHIQ_VERSION, VCHIQ_VERSION_MIN,
  22877. + MAJOR(vchiq_devid), MINOR(vchiq_devid));
  22878. +
  22879. + return 0;
  22880. +
  22881. +failed_platform_init:
  22882. + device_destroy(vchiq_class, vchiq_devid);
  22883. +failed_device_create:
  22884. + class_destroy(vchiq_class);
  22885. +failed_class_create:
  22886. + cdev_del(&vchiq_cdev);
  22887. + err = PTR_ERR(ptr_err);
  22888. +failed_cdev_add:
  22889. + unregister_chrdev_region(vchiq_devid, 1);
  22890. +failed_alloc_chrdev:
  22891. + vchiq_proc_deinit();
  22892. +failed_proc_init:
  22893. + vchiq_log_warning(vchiq_arm_log_level, "could not load vchiq");
  22894. + return err;
  22895. +}
  22896. +
  22897. +static int vchiq_instance_get_use_count(VCHIQ_INSTANCE_T instance)
  22898. +{
  22899. + VCHIQ_SERVICE_T *service;
  22900. + int use_count = 0, i;
  22901. + i = 0;
  22902. + while ((service = next_service_by_instance(instance->state,
  22903. + instance, &i)) != NULL) {
  22904. + use_count += service->service_use_count;
  22905. + unlock_service(service);
  22906. + }
  22907. + return use_count;
  22908. +}
  22909. +
  22910. +/* read the per-process use-count */
  22911. +static int proc_read_use_count(char *page, char **start,
  22912. + off_t off, int count,
  22913. + int *eof, void *data)
  22914. +{
  22915. + VCHIQ_INSTANCE_T instance = data;
  22916. + int len, use_count;
  22917. +
  22918. + use_count = vchiq_instance_get_use_count(instance);
  22919. + len = snprintf(page+off, count, "%d\n", use_count);
  22920. +
  22921. + return len;
  22922. +}
  22923. +
  22924. +/* add an instance (process) to the proc entries */
  22925. +static int vchiq_proc_add_instance(VCHIQ_INSTANCE_T instance)
  22926. +{
  22927. +#if 1
  22928. + return 0;
  22929. +#else
  22930. + char pidstr[32];
  22931. + struct proc_dir_entry *top, *use_count;
  22932. + struct proc_dir_entry *clients = vchiq_clients_top();
  22933. + int pid = instance->pid;
  22934. +
  22935. + snprintf(pidstr, sizeof(pidstr), "%d", pid);
  22936. + top = proc_mkdir(pidstr, clients);
  22937. + if (!top)
  22938. + goto fail_top;
  22939. +
  22940. + use_count = create_proc_read_entry("use_count",
  22941. + 0444, top,
  22942. + proc_read_use_count,
  22943. + instance);
  22944. + if (!use_count)
  22945. + goto fail_use_count;
  22946. +
  22947. + instance->proc_entry = top;
  22948. +
  22949. + return 0;
  22950. +
  22951. +fail_use_count:
  22952. + remove_proc_entry(top->name, clients);
  22953. +fail_top:
  22954. + return -ENOMEM;
  22955. +#endif
  22956. +}
  22957. +
  22958. +static void vchiq_proc_remove_instance(VCHIQ_INSTANCE_T instance)
  22959. +{
  22960. +#if 0
  22961. + struct proc_dir_entry *clients = vchiq_clients_top();
  22962. + remove_proc_entry("use_count", instance->proc_entry);
  22963. + remove_proc_entry(instance->proc_entry->name, clients);
  22964. +#endif
  22965. +}
  22966. +
  22967. +/****************************************************************************
  22968. +*
  22969. +* vchiq_exit - called when the module is unloaded.
  22970. +*
  22971. +***************************************************************************/
  22972. +
  22973. +static void __exit
  22974. +vchiq_exit(void)
  22975. +{
  22976. + vchiq_platform_exit(&g_state);
  22977. + device_destroy(vchiq_class, vchiq_devid);
  22978. + class_destroy(vchiq_class);
  22979. + cdev_del(&vchiq_cdev);
  22980. + unregister_chrdev_region(vchiq_devid, 1);
  22981. +}
  22982. +
  22983. +module_init(vchiq_init);
  22984. +module_exit(vchiq_exit);
  22985. +MODULE_LICENSE("GPL");
  22986. +MODULE_AUTHOR("Broadcom Corporation");
  22987. diff -Nur linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h
  22988. --- linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h 1970-01-01 01:00:00.000000000 +0100
  22989. +++ linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h 2014-08-06 16:50:14.449961962 +0200
  22990. @@ -0,0 +1,212 @@
  22991. +/**
  22992. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  22993. + *
  22994. + * Redistribution and use in source and binary forms, with or without
  22995. + * modification, are permitted provided that the following conditions
  22996. + * are met:
  22997. + * 1. Redistributions of source code must retain the above copyright
  22998. + * notice, this list of conditions, and the following disclaimer,
  22999. + * without modification.
  23000. + * 2. Redistributions in binary form must reproduce the above copyright
  23001. + * notice, this list of conditions and the following disclaimer in the
  23002. + * documentation and/or other materials provided with the distribution.
  23003. + * 3. The names of the above-listed copyright holders may not be used
  23004. + * to endorse or promote products derived from this software without
  23005. + * specific prior written permission.
  23006. + *
  23007. + * ALTERNATIVELY, this software may be distributed under the terms of the
  23008. + * GNU General Public License ("GPL") version 2, as published by the Free
  23009. + * Software Foundation.
  23010. + *
  23011. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  23012. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  23013. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23014. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23015. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23016. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23017. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  23018. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23019. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23020. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23021. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23022. + */
  23023. +
  23024. +#ifndef VCHIQ_ARM_H
  23025. +#define VCHIQ_ARM_H
  23026. +
  23027. +#include <linux/mutex.h>
  23028. +#include <linux/semaphore.h>
  23029. +#include <linux/atomic.h>
  23030. +#include "vchiq_core.h"
  23031. +
  23032. +
  23033. +enum vc_suspend_status {
  23034. + VC_SUSPEND_FORCE_CANCELED = -3, /* Force suspend canceled, too busy */
  23035. + VC_SUSPEND_REJECTED = -2, /* Videocore rejected suspend request */
  23036. + VC_SUSPEND_FAILED = -1, /* Videocore suspend failed */
  23037. + VC_SUSPEND_IDLE = 0, /* VC active, no suspend actions */
  23038. + VC_SUSPEND_REQUESTED, /* User has requested suspend */
  23039. + VC_SUSPEND_IN_PROGRESS, /* Slot handler has recvd suspend request */
  23040. + VC_SUSPEND_SUSPENDED /* Videocore suspend succeeded */
  23041. +};
  23042. +
  23043. +enum vc_resume_status {
  23044. + VC_RESUME_FAILED = -1, /* Videocore resume failed */
  23045. + VC_RESUME_IDLE = 0, /* VC suspended, no resume actions */
  23046. + VC_RESUME_REQUESTED, /* User has requested resume */
  23047. + VC_RESUME_IN_PROGRESS, /* Slot handler has received resume request */
  23048. + VC_RESUME_RESUMED /* Videocore resumed successfully (active) */
  23049. +};
  23050. +
  23051. +
  23052. +enum USE_TYPE_E {
  23053. + USE_TYPE_SERVICE,
  23054. + USE_TYPE_SERVICE_NO_RESUME,
  23055. + USE_TYPE_VCHIQ
  23056. +};
  23057. +
  23058. +
  23059. +
  23060. +typedef struct vchiq_arm_state_struct {
  23061. + /* Keepalive-related data */
  23062. + struct task_struct *ka_thread;
  23063. + struct completion ka_evt;
  23064. + atomic_t ka_use_count;
  23065. + atomic_t ka_use_ack_count;
  23066. + atomic_t ka_release_count;
  23067. +
  23068. + struct completion vc_suspend_complete;
  23069. + struct completion vc_resume_complete;
  23070. +
  23071. + rwlock_t susp_res_lock;
  23072. + enum vc_suspend_status vc_suspend_state;
  23073. + enum vc_resume_status vc_resume_state;
  23074. +
  23075. + unsigned int wake_address;
  23076. +
  23077. + struct timer_list suspend_timer;
  23078. + int suspend_timer_timeout;
  23079. + int suspend_timer_running;
  23080. +
  23081. + /* Global use count for videocore.
  23082. + ** This is equal to the sum of the use counts for all services. When
  23083. + ** this hits zero the videocore suspend procedure will be initiated.
  23084. + */
  23085. + int videocore_use_count;
  23086. +
  23087. + /* Use count to track requests from videocore peer.
  23088. + ** This use count is not associated with a service, so needs to be
  23089. + ** tracked separately with the state.
  23090. + */
  23091. + int peer_use_count;
  23092. +
  23093. + /* Flag to indicate whether resume is blocked. This happens when the
  23094. + ** ARM is suspending
  23095. + */
  23096. + struct completion resume_blocker;
  23097. + int resume_blocked;
  23098. + struct completion blocked_blocker;
  23099. + int blocked_count;
  23100. +
  23101. + int autosuspend_override;
  23102. +
  23103. + /* Flag to indicate that the first vchiq connect has made it through.
  23104. + ** This means that both sides should be fully ready, and we should
  23105. + ** be able to suspend after this point.
  23106. + */
  23107. + int first_connect;
  23108. +
  23109. + unsigned long long suspend_start_time;
  23110. + unsigned long long sleep_start_time;
  23111. + unsigned long long resume_start_time;
  23112. + unsigned long long last_wake_time;
  23113. +
  23114. +} VCHIQ_ARM_STATE_T;
  23115. +
  23116. +extern int vchiq_arm_log_level;
  23117. +extern int vchiq_susp_log_level;
  23118. +
  23119. +extern int __init
  23120. +vchiq_platform_init(VCHIQ_STATE_T *state);
  23121. +
  23122. +extern void __exit
  23123. +vchiq_platform_exit(VCHIQ_STATE_T *state);
  23124. +
  23125. +extern VCHIQ_STATE_T *
  23126. +vchiq_get_state(void);
  23127. +
  23128. +extern VCHIQ_STATUS_T
  23129. +vchiq_arm_vcsuspend(VCHIQ_STATE_T *state);
  23130. +
  23131. +extern VCHIQ_STATUS_T
  23132. +vchiq_arm_force_suspend(VCHIQ_STATE_T *state);
  23133. +
  23134. +extern int
  23135. +vchiq_arm_allow_resume(VCHIQ_STATE_T *state);
  23136. +
  23137. +extern VCHIQ_STATUS_T
  23138. +vchiq_arm_vcresume(VCHIQ_STATE_T *state);
  23139. +
  23140. +extern VCHIQ_STATUS_T
  23141. +vchiq_arm_init_state(VCHIQ_STATE_T *state, VCHIQ_ARM_STATE_T *arm_state);
  23142. +
  23143. +extern int
  23144. +vchiq_check_resume(VCHIQ_STATE_T *state);
  23145. +
  23146. +extern void
  23147. +vchiq_check_suspend(VCHIQ_STATE_T *state);
  23148. +
  23149. +extern VCHIQ_STATUS_T
  23150. +vchiq_use_service(VCHIQ_SERVICE_HANDLE_T handle);
  23151. +
  23152. +extern VCHIQ_STATUS_T
  23153. +vchiq_release_service(VCHIQ_SERVICE_HANDLE_T handle);
  23154. +
  23155. +extern VCHIQ_STATUS_T
  23156. +vchiq_check_service(VCHIQ_SERVICE_T *service);
  23157. +
  23158. +extern VCHIQ_STATUS_T
  23159. +vchiq_platform_suspend(VCHIQ_STATE_T *state);
  23160. +
  23161. +extern int
  23162. +vchiq_platform_videocore_wanted(VCHIQ_STATE_T *state);
  23163. +
  23164. +extern int
  23165. +vchiq_platform_use_suspend_timer(void);
  23166. +
  23167. +extern void
  23168. +vchiq_dump_platform_use_state(VCHIQ_STATE_T *state);
  23169. +
  23170. +extern void
  23171. +vchiq_dump_service_use_state(VCHIQ_STATE_T *state);
  23172. +
  23173. +extern VCHIQ_ARM_STATE_T*
  23174. +vchiq_platform_get_arm_state(VCHIQ_STATE_T *state);
  23175. +
  23176. +extern int
  23177. +vchiq_videocore_wanted(VCHIQ_STATE_T *state);
  23178. +
  23179. +extern VCHIQ_STATUS_T
  23180. +vchiq_use_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  23181. + enum USE_TYPE_E use_type);
  23182. +extern VCHIQ_STATUS_T
  23183. +vchiq_release_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service);
  23184. +
  23185. +void
  23186. +set_suspend_state(VCHIQ_ARM_STATE_T *arm_state,
  23187. + enum vc_suspend_status new_state);
  23188. +
  23189. +void
  23190. +set_resume_state(VCHIQ_ARM_STATE_T *arm_state,
  23191. + enum vc_resume_status new_state);
  23192. +
  23193. +void
  23194. +start_suspend_timer(VCHIQ_ARM_STATE_T *arm_state);
  23195. +
  23196. +extern int vchiq_proc_init(void);
  23197. +extern void vchiq_proc_deinit(void);
  23198. +extern struct proc_dir_entry *vchiq_proc_top(void);
  23199. +extern struct proc_dir_entry *vchiq_clients_top(void);
  23200. +
  23201. +
  23202. +#endif /* VCHIQ_ARM_H */
  23203. diff -Nur linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h
  23204. --- linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h 1970-01-01 01:00:00.000000000 +0100
  23205. +++ linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h 2014-08-06 16:50:14.469962119 +0200
  23206. @@ -0,0 +1,37 @@
  23207. +/**
  23208. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  23209. + *
  23210. + * Redistribution and use in source and binary forms, with or without
  23211. + * modification, are permitted provided that the following conditions
  23212. + * are met:
  23213. + * 1. Redistributions of source code must retain the above copyright
  23214. + * notice, this list of conditions, and the following disclaimer,
  23215. + * without modification.
  23216. + * 2. Redistributions in binary form must reproduce the above copyright
  23217. + * notice, this list of conditions and the following disclaimer in the
  23218. + * documentation and/or other materials provided with the distribution.
  23219. + * 3. The names of the above-listed copyright holders may not be used
  23220. + * to endorse or promote products derived from this software without
  23221. + * specific prior written permission.
  23222. + *
  23223. + * ALTERNATIVELY, this software may be distributed under the terms of the
  23224. + * GNU General Public License ("GPL") version 2, as published by the Free
  23225. + * Software Foundation.
  23226. + *
  23227. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  23228. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  23229. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23230. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23231. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23232. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23233. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  23234. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23235. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23236. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23237. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23238. + */
  23239. +
  23240. +const char *vchiq_get_build_hostname(void);
  23241. +const char *vchiq_get_build_version(void);
  23242. +const char *vchiq_get_build_time(void);
  23243. +const char *vchiq_get_build_date(void);
  23244. diff -Nur linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h
  23245. --- linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h 1970-01-01 01:00:00.000000000 +0100
  23246. +++ linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h 2014-08-06 16:50:14.469962119 +0200
  23247. @@ -0,0 +1,60 @@
  23248. +/**
  23249. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  23250. + *
  23251. + * Redistribution and use in source and binary forms, with or without
  23252. + * modification, are permitted provided that the following conditions
  23253. + * are met:
  23254. + * 1. Redistributions of source code must retain the above copyright
  23255. + * notice, this list of conditions, and the following disclaimer,
  23256. + * without modification.
  23257. + * 2. Redistributions in binary form must reproduce the above copyright
  23258. + * notice, this list of conditions and the following disclaimer in the
  23259. + * documentation and/or other materials provided with the distribution.
  23260. + * 3. The names of the above-listed copyright holders may not be used
  23261. + * to endorse or promote products derived from this software without
  23262. + * specific prior written permission.
  23263. + *
  23264. + * ALTERNATIVELY, this software may be distributed under the terms of the
  23265. + * GNU General Public License ("GPL") version 2, as published by the Free
  23266. + * Software Foundation.
  23267. + *
  23268. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  23269. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  23270. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23271. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23272. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23273. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23274. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  23275. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23276. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23277. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23278. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23279. + */
  23280. +
  23281. +#ifndef VCHIQ_CFG_H
  23282. +#define VCHIQ_CFG_H
  23283. +
  23284. +#define VCHIQ_MAGIC VCHIQ_MAKE_FOURCC('V', 'C', 'H', 'I')
  23285. +/* The version of VCHIQ - change with any non-trivial change */
  23286. +#define VCHIQ_VERSION 6
  23287. +/* The minimum compatible version - update to match VCHIQ_VERSION with any
  23288. +** incompatible change */
  23289. +#define VCHIQ_VERSION_MIN 3
  23290. +
  23291. +#define VCHIQ_MAX_STATES 1
  23292. +#define VCHIQ_MAX_SERVICES 4096
  23293. +#define VCHIQ_MAX_SLOTS 128
  23294. +#define VCHIQ_MAX_SLOTS_PER_SIDE 64
  23295. +
  23296. +#define VCHIQ_NUM_CURRENT_BULKS 32
  23297. +#define VCHIQ_NUM_SERVICE_BULKS 4
  23298. +
  23299. +#ifndef VCHIQ_ENABLE_DEBUG
  23300. +#define VCHIQ_ENABLE_DEBUG 1
  23301. +#endif
  23302. +
  23303. +#ifndef VCHIQ_ENABLE_STATS
  23304. +#define VCHIQ_ENABLE_STATS 1
  23305. +#endif
  23306. +
  23307. +#endif /* VCHIQ_CFG_H */
  23308. diff -Nur linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c
  23309. --- linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c 1970-01-01 01:00:00.000000000 +0100
  23310. +++ linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c 2014-08-06 16:50:14.469962119 +0200
  23311. @@ -0,0 +1,119 @@
  23312. +/**
  23313. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  23314. + *
  23315. + * Redistribution and use in source and binary forms, with or without
  23316. + * modification, are permitted provided that the following conditions
  23317. + * are met:
  23318. + * 1. Redistributions of source code must retain the above copyright
  23319. + * notice, this list of conditions, and the following disclaimer,
  23320. + * without modification.
  23321. + * 2. Redistributions in binary form must reproduce the above copyright
  23322. + * notice, this list of conditions and the following disclaimer in the
  23323. + * documentation and/or other materials provided with the distribution.
  23324. + * 3. The names of the above-listed copyright holders may not be used
  23325. + * to endorse or promote products derived from this software without
  23326. + * specific prior written permission.
  23327. + *
  23328. + * ALTERNATIVELY, this software may be distributed under the terms of the
  23329. + * GNU General Public License ("GPL") version 2, as published by the Free
  23330. + * Software Foundation.
  23331. + *
  23332. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  23333. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  23334. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23335. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23336. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23337. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23338. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  23339. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23340. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23341. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23342. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23343. + */
  23344. +
  23345. +#include "vchiq_connected.h"
  23346. +#include "vchiq_core.h"
  23347. +#include <linux/module.h>
  23348. +#include <linux/mutex.h>
  23349. +
  23350. +#define MAX_CALLBACKS 10
  23351. +
  23352. +static int g_connected;
  23353. +static int g_num_deferred_callbacks;
  23354. +static VCHIQ_CONNECTED_CALLBACK_T g_deferred_callback[MAX_CALLBACKS];
  23355. +static int g_once_init;
  23356. +static struct mutex g_connected_mutex;
  23357. +
  23358. +/****************************************************************************
  23359. +*
  23360. +* Function to initialize our lock.
  23361. +*
  23362. +***************************************************************************/
  23363. +
  23364. +static void connected_init(void)
  23365. +{
  23366. + if (!g_once_init) {
  23367. + mutex_init(&g_connected_mutex);
  23368. + g_once_init = 1;
  23369. + }
  23370. +}
  23371. +
  23372. +/****************************************************************************
  23373. +*
  23374. +* This function is used to defer initialization until the vchiq stack is
  23375. +* initialized. If the stack is already initialized, then the callback will
  23376. +* be made immediately, otherwise it will be deferred until
  23377. +* vchiq_call_connected_callbacks is called.
  23378. +*
  23379. +***************************************************************************/
  23380. +
  23381. +void vchiq_add_connected_callback(VCHIQ_CONNECTED_CALLBACK_T callback)
  23382. +{
  23383. + connected_init();
  23384. +
  23385. + if (mutex_lock_interruptible(&g_connected_mutex) != 0)
  23386. + return;
  23387. +
  23388. + if (g_connected)
  23389. + /* We're already connected. Call the callback immediately. */
  23390. +
  23391. + callback();
  23392. + else {
  23393. + if (g_num_deferred_callbacks >= MAX_CALLBACKS)
  23394. + vchiq_log_error(vchiq_core_log_level,
  23395. + "There already %d callback registered - "
  23396. + "please increase MAX_CALLBACKS",
  23397. + g_num_deferred_callbacks);
  23398. + else {
  23399. + g_deferred_callback[g_num_deferred_callbacks] =
  23400. + callback;
  23401. + g_num_deferred_callbacks++;
  23402. + }
  23403. + }
  23404. + mutex_unlock(&g_connected_mutex);
  23405. +}
  23406. +
  23407. +/****************************************************************************
  23408. +*
  23409. +* This function is called by the vchiq stack once it has been connected to
  23410. +* the videocore and clients can start to use the stack.
  23411. +*
  23412. +***************************************************************************/
  23413. +
  23414. +void vchiq_call_connected_callbacks(void)
  23415. +{
  23416. + int i;
  23417. +
  23418. + connected_init();
  23419. +
  23420. + if (mutex_lock_interruptible(&g_connected_mutex) != 0)
  23421. + return;
  23422. +
  23423. + for (i = 0; i < g_num_deferred_callbacks; i++)
  23424. + g_deferred_callback[i]();
  23425. +
  23426. + g_num_deferred_callbacks = 0;
  23427. + g_connected = 1;
  23428. + mutex_unlock(&g_connected_mutex);
  23429. +}
  23430. +EXPORT_SYMBOL(vchiq_add_connected_callback);
  23431. diff -Nur linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h
  23432. --- linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h 1970-01-01 01:00:00.000000000 +0100
  23433. +++ linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h 2014-08-06 16:50:14.489962276 +0200
  23434. @@ -0,0 +1,50 @@
  23435. +/**
  23436. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  23437. + *
  23438. + * Redistribution and use in source and binary forms, with or without
  23439. + * modification, are permitted provided that the following conditions
  23440. + * are met:
  23441. + * 1. Redistributions of source code must retain the above copyright
  23442. + * notice, this list of conditions, and the following disclaimer,
  23443. + * without modification.
  23444. + * 2. Redistributions in binary form must reproduce the above copyright
  23445. + * notice, this list of conditions and the following disclaimer in the
  23446. + * documentation and/or other materials provided with the distribution.
  23447. + * 3. The names of the above-listed copyright holders may not be used
  23448. + * to endorse or promote products derived from this software without
  23449. + * specific prior written permission.
  23450. + *
  23451. + * ALTERNATIVELY, this software may be distributed under the terms of the
  23452. + * GNU General Public License ("GPL") version 2, as published by the Free
  23453. + * Software Foundation.
  23454. + *
  23455. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  23456. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  23457. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23458. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23459. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23460. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23461. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  23462. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23463. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23464. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23465. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23466. + */
  23467. +
  23468. +#ifndef VCHIQ_CONNECTED_H
  23469. +#define VCHIQ_CONNECTED_H
  23470. +
  23471. +/* ---- Include Files ----------------------------------------------------- */
  23472. +
  23473. +/* ---- Constants and Types ---------------------------------------------- */
  23474. +
  23475. +typedef void (*VCHIQ_CONNECTED_CALLBACK_T)(void);
  23476. +
  23477. +/* ---- Variable Externs ------------------------------------------------- */
  23478. +
  23479. +/* ---- Function Prototypes ---------------------------------------------- */
  23480. +
  23481. +void vchiq_add_connected_callback(VCHIQ_CONNECTED_CALLBACK_T callback);
  23482. +void vchiq_call_connected_callbacks(void);
  23483. +
  23484. +#endif /* VCHIQ_CONNECTED_H */
  23485. diff -Nur linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c
  23486. --- linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c 1970-01-01 01:00:00.000000000 +0100
  23487. +++ linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c 2014-08-06 16:50:14.493962307 +0200
  23488. @@ -0,0 +1,3824 @@
  23489. +/**
  23490. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  23491. + *
  23492. + * Redistribution and use in source and binary forms, with or without
  23493. + * modification, are permitted provided that the following conditions
  23494. + * are met:
  23495. + * 1. Redistributions of source code must retain the above copyright
  23496. + * notice, this list of conditions, and the following disclaimer,
  23497. + * without modification.
  23498. + * 2. Redistributions in binary form must reproduce the above copyright
  23499. + * notice, this list of conditions and the following disclaimer in the
  23500. + * documentation and/or other materials provided with the distribution.
  23501. + * 3. The names of the above-listed copyright holders may not be used
  23502. + * to endorse or promote products derived from this software without
  23503. + * specific prior written permission.
  23504. + *
  23505. + * ALTERNATIVELY, this software may be distributed under the terms of the
  23506. + * GNU General Public License ("GPL") version 2, as published by the Free
  23507. + * Software Foundation.
  23508. + *
  23509. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  23510. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  23511. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23512. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23513. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23514. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23515. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  23516. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23517. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23518. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23519. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23520. + */
  23521. +
  23522. +#include "vchiq_core.h"
  23523. +
  23524. +#define VCHIQ_SLOT_HANDLER_STACK 8192
  23525. +
  23526. +#define HANDLE_STATE_SHIFT 12
  23527. +
  23528. +#define SLOT_INFO_FROM_INDEX(state, index) (state->slot_info + (index))
  23529. +#define SLOT_DATA_FROM_INDEX(state, index) (state->slot_data + (index))
  23530. +#define SLOT_INDEX_FROM_DATA(state, data) \
  23531. + (((unsigned int)((char *)data - (char *)state->slot_data)) / \
  23532. + VCHIQ_SLOT_SIZE)
  23533. +#define SLOT_INDEX_FROM_INFO(state, info) \
  23534. + ((unsigned int)(info - state->slot_info))
  23535. +#define SLOT_QUEUE_INDEX_FROM_POS(pos) \
  23536. + ((int)((unsigned int)(pos) / VCHIQ_SLOT_SIZE))
  23537. +
  23538. +
  23539. +#define BULK_INDEX(x) (x & (VCHIQ_NUM_SERVICE_BULKS - 1))
  23540. +
  23541. +
  23542. +struct vchiq_open_payload {
  23543. + int fourcc;
  23544. + int client_id;
  23545. + short version;
  23546. + short version_min;
  23547. +};
  23548. +
  23549. +struct vchiq_openack_payload {
  23550. + short version;
  23551. +};
  23552. +
  23553. +/* we require this for consistency between endpoints */
  23554. +vchiq_static_assert(sizeof(VCHIQ_HEADER_T) == 8);
  23555. +vchiq_static_assert(IS_POW2(sizeof(VCHIQ_HEADER_T)));
  23556. +vchiq_static_assert(IS_POW2(VCHIQ_NUM_CURRENT_BULKS));
  23557. +vchiq_static_assert(IS_POW2(VCHIQ_NUM_SERVICE_BULKS));
  23558. +vchiq_static_assert(IS_POW2(VCHIQ_MAX_SERVICES));
  23559. +vchiq_static_assert(VCHIQ_VERSION >= VCHIQ_VERSION_MIN);
  23560. +
  23561. +/* Run time control of log level, based on KERN_XXX level. */
  23562. +int vchiq_core_log_level = VCHIQ_LOG_DEFAULT;
  23563. +int vchiq_core_msg_log_level = VCHIQ_LOG_DEFAULT;
  23564. +int vchiq_sync_log_level = VCHIQ_LOG_DEFAULT;
  23565. +
  23566. +static atomic_t pause_bulks_count = ATOMIC_INIT(0);
  23567. +
  23568. +static DEFINE_SPINLOCK(service_spinlock);
  23569. +DEFINE_SPINLOCK(bulk_waiter_spinlock);
  23570. +DEFINE_SPINLOCK(quota_spinlock);
  23571. +
  23572. +VCHIQ_STATE_T *vchiq_states[VCHIQ_MAX_STATES];
  23573. +static unsigned int handle_seq;
  23574. +
  23575. +static const char *const srvstate_names[] = {
  23576. + "FREE",
  23577. + "HIDDEN",
  23578. + "LISTENING",
  23579. + "OPENING",
  23580. + "OPEN",
  23581. + "OPENSYNC",
  23582. + "CLOSESENT",
  23583. + "CLOSERECVD",
  23584. + "CLOSEWAIT",
  23585. + "CLOSED"
  23586. +};
  23587. +
  23588. +static const char *const reason_names[] = {
  23589. + "SERVICE_OPENED",
  23590. + "SERVICE_CLOSED",
  23591. + "MESSAGE_AVAILABLE",
  23592. + "BULK_TRANSMIT_DONE",
  23593. + "BULK_RECEIVE_DONE",
  23594. + "BULK_TRANSMIT_ABORTED",
  23595. + "BULK_RECEIVE_ABORTED"
  23596. +};
  23597. +
  23598. +static const char *const conn_state_names[] = {
  23599. + "DISCONNECTED",
  23600. + "CONNECTING",
  23601. + "CONNECTED",
  23602. + "PAUSING",
  23603. + "PAUSE_SENT",
  23604. + "PAUSED",
  23605. + "RESUMING",
  23606. + "PAUSE_TIMEOUT",
  23607. + "RESUME_TIMEOUT"
  23608. +};
  23609. +
  23610. +
  23611. +static void
  23612. +release_message_sync(VCHIQ_STATE_T *state, VCHIQ_HEADER_T *header);
  23613. +
  23614. +static const char *msg_type_str(unsigned int msg_type)
  23615. +{
  23616. + switch (msg_type) {
  23617. + case VCHIQ_MSG_PADDING: return "PADDING";
  23618. + case VCHIQ_MSG_CONNECT: return "CONNECT";
  23619. + case VCHIQ_MSG_OPEN: return "OPEN";
  23620. + case VCHIQ_MSG_OPENACK: return "OPENACK";
  23621. + case VCHIQ_MSG_CLOSE: return "CLOSE";
  23622. + case VCHIQ_MSG_DATA: return "DATA";
  23623. + case VCHIQ_MSG_BULK_RX: return "BULK_RX";
  23624. + case VCHIQ_MSG_BULK_TX: return "BULK_TX";
  23625. + case VCHIQ_MSG_BULK_RX_DONE: return "BULK_RX_DONE";
  23626. + case VCHIQ_MSG_BULK_TX_DONE: return "BULK_TX_DONE";
  23627. + case VCHIQ_MSG_PAUSE: return "PAUSE";
  23628. + case VCHIQ_MSG_RESUME: return "RESUME";
  23629. + case VCHIQ_MSG_REMOTE_USE: return "REMOTE_USE";
  23630. + case VCHIQ_MSG_REMOTE_RELEASE: return "REMOTE_RELEASE";
  23631. + case VCHIQ_MSG_REMOTE_USE_ACTIVE: return "REMOTE_USE_ACTIVE";
  23632. + }
  23633. + return "???";
  23634. +}
  23635. +
  23636. +static inline void
  23637. +vchiq_set_service_state(VCHIQ_SERVICE_T *service, int newstate)
  23638. +{
  23639. + vchiq_log_info(vchiq_core_log_level, "%d: srv:%d %s->%s",
  23640. + service->state->id, service->localport,
  23641. + srvstate_names[service->srvstate],
  23642. + srvstate_names[newstate]);
  23643. + service->srvstate = newstate;
  23644. +}
  23645. +
  23646. +VCHIQ_SERVICE_T *
  23647. +find_service_by_handle(VCHIQ_SERVICE_HANDLE_T handle)
  23648. +{
  23649. + VCHIQ_SERVICE_T *service;
  23650. +
  23651. + spin_lock(&service_spinlock);
  23652. + service = handle_to_service(handle);
  23653. + if (service && (service->srvstate != VCHIQ_SRVSTATE_FREE) &&
  23654. + (service->handle == handle)) {
  23655. + BUG_ON(service->ref_count == 0);
  23656. + service->ref_count++;
  23657. + } else
  23658. + service = NULL;
  23659. + spin_unlock(&service_spinlock);
  23660. +
  23661. + if (!service)
  23662. + vchiq_log_info(vchiq_core_log_level,
  23663. + "Invalid service handle 0x%x", handle);
  23664. +
  23665. + return service;
  23666. +}
  23667. +
  23668. +VCHIQ_SERVICE_T *
  23669. +find_service_by_port(VCHIQ_STATE_T *state, int localport)
  23670. +{
  23671. + VCHIQ_SERVICE_T *service = NULL;
  23672. + if ((unsigned int)localport <= VCHIQ_PORT_MAX) {
  23673. + spin_lock(&service_spinlock);
  23674. + service = state->services[localport];
  23675. + if (service && (service->srvstate != VCHIQ_SRVSTATE_FREE)) {
  23676. + BUG_ON(service->ref_count == 0);
  23677. + service->ref_count++;
  23678. + } else
  23679. + service = NULL;
  23680. + spin_unlock(&service_spinlock);
  23681. + }
  23682. +
  23683. + if (!service)
  23684. + vchiq_log_info(vchiq_core_log_level,
  23685. + "Invalid port %d", localport);
  23686. +
  23687. + return service;
  23688. +}
  23689. +
  23690. +VCHIQ_SERVICE_T *
  23691. +find_service_for_instance(VCHIQ_INSTANCE_T instance,
  23692. + VCHIQ_SERVICE_HANDLE_T handle) {
  23693. + VCHIQ_SERVICE_T *service;
  23694. +
  23695. + spin_lock(&service_spinlock);
  23696. + service = handle_to_service(handle);
  23697. + if (service && (service->srvstate != VCHIQ_SRVSTATE_FREE) &&
  23698. + (service->handle == handle) &&
  23699. + (service->instance == instance)) {
  23700. + BUG_ON(service->ref_count == 0);
  23701. + service->ref_count++;
  23702. + } else
  23703. + service = NULL;
  23704. + spin_unlock(&service_spinlock);
  23705. +
  23706. + if (!service)
  23707. + vchiq_log_info(vchiq_core_log_level,
  23708. + "Invalid service handle 0x%x", handle);
  23709. +
  23710. + return service;
  23711. +}
  23712. +
  23713. +VCHIQ_SERVICE_T *
  23714. +next_service_by_instance(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance,
  23715. + int *pidx)
  23716. +{
  23717. + VCHIQ_SERVICE_T *service = NULL;
  23718. + int idx = *pidx;
  23719. +
  23720. + spin_lock(&service_spinlock);
  23721. + while (idx < state->unused_service) {
  23722. + VCHIQ_SERVICE_T *srv = state->services[idx++];
  23723. + if (srv && (srv->srvstate != VCHIQ_SRVSTATE_FREE) &&
  23724. + (srv->instance == instance)) {
  23725. + service = srv;
  23726. + BUG_ON(service->ref_count == 0);
  23727. + service->ref_count++;
  23728. + break;
  23729. + }
  23730. + }
  23731. + spin_unlock(&service_spinlock);
  23732. +
  23733. + *pidx = idx;
  23734. +
  23735. + return service;
  23736. +}
  23737. +
  23738. +void
  23739. +lock_service(VCHIQ_SERVICE_T *service)
  23740. +{
  23741. + spin_lock(&service_spinlock);
  23742. + BUG_ON(!service || (service->ref_count == 0));
  23743. + if (service)
  23744. + service->ref_count++;
  23745. + spin_unlock(&service_spinlock);
  23746. +}
  23747. +
  23748. +void
  23749. +unlock_service(VCHIQ_SERVICE_T *service)
  23750. +{
  23751. + VCHIQ_STATE_T *state = service->state;
  23752. + spin_lock(&service_spinlock);
  23753. + BUG_ON(!service || (service->ref_count == 0));
  23754. + if (service && service->ref_count) {
  23755. + service->ref_count--;
  23756. + if (!service->ref_count) {
  23757. + BUG_ON(service->srvstate != VCHIQ_SRVSTATE_FREE);
  23758. + state->services[service->localport] = NULL;
  23759. + } else
  23760. + service = NULL;
  23761. + }
  23762. + spin_unlock(&service_spinlock);
  23763. +
  23764. + if (service && service->userdata_term)
  23765. + service->userdata_term(service->base.userdata);
  23766. +
  23767. + kfree(service);
  23768. +}
  23769. +
  23770. +int
  23771. +vchiq_get_client_id(VCHIQ_SERVICE_HANDLE_T handle)
  23772. +{
  23773. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  23774. + int id;
  23775. +
  23776. + id = service ? service->client_id : 0;
  23777. + if (service)
  23778. + unlock_service(service);
  23779. +
  23780. + return id;
  23781. +}
  23782. +
  23783. +void *
  23784. +vchiq_get_service_userdata(VCHIQ_SERVICE_HANDLE_T handle)
  23785. +{
  23786. + VCHIQ_SERVICE_T *service = handle_to_service(handle);
  23787. +
  23788. + return service ? service->base.userdata : NULL;
  23789. +}
  23790. +
  23791. +int
  23792. +vchiq_get_service_fourcc(VCHIQ_SERVICE_HANDLE_T handle)
  23793. +{
  23794. + VCHIQ_SERVICE_T *service = handle_to_service(handle);
  23795. +
  23796. + return service ? service->base.fourcc : 0;
  23797. +}
  23798. +
  23799. +static void
  23800. +mark_service_closing_internal(VCHIQ_SERVICE_T *service, int sh_thread)
  23801. +{
  23802. + VCHIQ_STATE_T *state = service->state;
  23803. + VCHIQ_SERVICE_QUOTA_T *service_quota;
  23804. +
  23805. + service->closing = 1;
  23806. +
  23807. + /* Synchronise with other threads. */
  23808. + mutex_lock(&state->recycle_mutex);
  23809. + mutex_unlock(&state->recycle_mutex);
  23810. + if (!sh_thread || (state->conn_state != VCHIQ_CONNSTATE_PAUSE_SENT)) {
  23811. + /* If we're pausing then the slot_mutex is held until resume
  23812. + * by the slot handler. Therefore don't try to acquire this
  23813. + * mutex if we're the slot handler and in the pause sent state.
  23814. + * We don't need to in this case anyway. */
  23815. + mutex_lock(&state->slot_mutex);
  23816. + mutex_unlock(&state->slot_mutex);
  23817. + }
  23818. +
  23819. + /* Unblock any sending thread. */
  23820. + service_quota = &state->service_quotas[service->localport];
  23821. + up(&service_quota->quota_event);
  23822. +}
  23823. +
  23824. +static void
  23825. +mark_service_closing(VCHIQ_SERVICE_T *service)
  23826. +{
  23827. + mark_service_closing_internal(service, 0);
  23828. +}
  23829. +
  23830. +static inline VCHIQ_STATUS_T
  23831. +make_service_callback(VCHIQ_SERVICE_T *service, VCHIQ_REASON_T reason,
  23832. + VCHIQ_HEADER_T *header, void *bulk_userdata)
  23833. +{
  23834. + VCHIQ_STATUS_T status;
  23835. + vchiq_log_trace(vchiq_core_log_level, "%d: callback:%d (%s, %x, %x)",
  23836. + service->state->id, service->localport, reason_names[reason],
  23837. + (unsigned int)header, (unsigned int)bulk_userdata);
  23838. + status = service->base.callback(reason, header, service->handle,
  23839. + bulk_userdata);
  23840. + if (status == VCHIQ_ERROR) {
  23841. + vchiq_log_warning(vchiq_core_log_level,
  23842. + "%d: ignoring ERROR from callback to service %x",
  23843. + service->state->id, service->handle);
  23844. + status = VCHIQ_SUCCESS;
  23845. + }
  23846. + return status;
  23847. +}
  23848. +
  23849. +inline void
  23850. +vchiq_set_conn_state(VCHIQ_STATE_T *state, VCHIQ_CONNSTATE_T newstate)
  23851. +{
  23852. + VCHIQ_CONNSTATE_T oldstate = state->conn_state;
  23853. + vchiq_log_info(vchiq_core_log_level, "%d: %s->%s", state->id,
  23854. + conn_state_names[oldstate],
  23855. + conn_state_names[newstate]);
  23856. + state->conn_state = newstate;
  23857. + vchiq_platform_conn_state_changed(state, oldstate, newstate);
  23858. +}
  23859. +
  23860. +static inline void
  23861. +remote_event_create(REMOTE_EVENT_T *event)
  23862. +{
  23863. + event->armed = 0;
  23864. + /* Don't clear the 'fired' flag because it may already have been set
  23865. + ** by the other side. */
  23866. + sema_init(event->event, 0);
  23867. +}
  23868. +
  23869. +static inline void
  23870. +remote_event_destroy(REMOTE_EVENT_T *event)
  23871. +{
  23872. + (void)event;
  23873. +}
  23874. +
  23875. +static inline int
  23876. +remote_event_wait(REMOTE_EVENT_T *event)
  23877. +{
  23878. + if (!event->fired) {
  23879. + event->armed = 1;
  23880. + dsb();
  23881. + if (!event->fired) {
  23882. + if (down_interruptible(event->event) != 0) {
  23883. + event->armed = 0;
  23884. + return 0;
  23885. + }
  23886. + }
  23887. + event->armed = 0;
  23888. + wmb();
  23889. + }
  23890. +
  23891. + event->fired = 0;
  23892. + return 1;
  23893. +}
  23894. +
  23895. +static inline void
  23896. +remote_event_signal_local(REMOTE_EVENT_T *event)
  23897. +{
  23898. + event->armed = 0;
  23899. + up(event->event);
  23900. +}
  23901. +
  23902. +static inline void
  23903. +remote_event_poll(REMOTE_EVENT_T *event)
  23904. +{
  23905. + if (event->fired && event->armed)
  23906. + remote_event_signal_local(event);
  23907. +}
  23908. +
  23909. +void
  23910. +remote_event_pollall(VCHIQ_STATE_T *state)
  23911. +{
  23912. + remote_event_poll(&state->local->sync_trigger);
  23913. + remote_event_poll(&state->local->sync_release);
  23914. + remote_event_poll(&state->local->trigger);
  23915. + remote_event_poll(&state->local->recycle);
  23916. +}
  23917. +
  23918. +/* Round up message sizes so that any space at the end of a slot is always big
  23919. +** enough for a header. This relies on header size being a power of two, which
  23920. +** has been verified earlier by a static assertion. */
  23921. +
  23922. +static inline unsigned int
  23923. +calc_stride(unsigned int size)
  23924. +{
  23925. + /* Allow room for the header */
  23926. + size += sizeof(VCHIQ_HEADER_T);
  23927. +
  23928. + /* Round up */
  23929. + return (size + sizeof(VCHIQ_HEADER_T) - 1) & ~(sizeof(VCHIQ_HEADER_T)
  23930. + - 1);
  23931. +}
  23932. +
  23933. +/* Called by the slot handler thread */
  23934. +static VCHIQ_SERVICE_T *
  23935. +get_listening_service(VCHIQ_STATE_T *state, int fourcc)
  23936. +{
  23937. + int i;
  23938. +
  23939. + WARN_ON(fourcc == VCHIQ_FOURCC_INVALID);
  23940. +
  23941. + for (i = 0; i < state->unused_service; i++) {
  23942. + VCHIQ_SERVICE_T *service = state->services[i];
  23943. + if (service &&
  23944. + (service->public_fourcc == fourcc) &&
  23945. + ((service->srvstate == VCHIQ_SRVSTATE_LISTENING) ||
  23946. + ((service->srvstate == VCHIQ_SRVSTATE_OPEN) &&
  23947. + (service->remoteport == VCHIQ_PORT_FREE)))) {
  23948. + lock_service(service);
  23949. + return service;
  23950. + }
  23951. + }
  23952. +
  23953. + return NULL;
  23954. +}
  23955. +
  23956. +/* Called by the slot handler thread */
  23957. +static VCHIQ_SERVICE_T *
  23958. +get_connected_service(VCHIQ_STATE_T *state, unsigned int port)
  23959. +{
  23960. + int i;
  23961. + for (i = 0; i < state->unused_service; i++) {
  23962. + VCHIQ_SERVICE_T *service = state->services[i];
  23963. + if (service && (service->srvstate == VCHIQ_SRVSTATE_OPEN)
  23964. + && (service->remoteport == port)) {
  23965. + lock_service(service);
  23966. + return service;
  23967. + }
  23968. + }
  23969. + return NULL;
  23970. +}
  23971. +
  23972. +inline void
  23973. +request_poll(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service, int poll_type)
  23974. +{
  23975. + uint32_t value;
  23976. +
  23977. + if (service) {
  23978. + do {
  23979. + value = atomic_read(&service->poll_flags);
  23980. + } while (atomic_cmpxchg(&service->poll_flags, value,
  23981. + value | (1 << poll_type)) != value);
  23982. +
  23983. + do {
  23984. + value = atomic_read(&state->poll_services[
  23985. + service->localport>>5]);
  23986. + } while (atomic_cmpxchg(
  23987. + &state->poll_services[service->localport>>5],
  23988. + value, value | (1 << (service->localport & 0x1f)))
  23989. + != value);
  23990. + }
  23991. +
  23992. + state->poll_needed = 1;
  23993. + wmb();
  23994. +
  23995. + /* ... and ensure the slot handler runs. */
  23996. + remote_event_signal_local(&state->local->trigger);
  23997. +}
  23998. +
  23999. +/* Called from queue_message, by the slot handler and application threads,
  24000. +** with slot_mutex held */
  24001. +static VCHIQ_HEADER_T *
  24002. +reserve_space(VCHIQ_STATE_T *state, int space, int is_blocking)
  24003. +{
  24004. + VCHIQ_SHARED_STATE_T *local = state->local;
  24005. + int tx_pos = state->local_tx_pos;
  24006. + int slot_space = VCHIQ_SLOT_SIZE - (tx_pos & VCHIQ_SLOT_MASK);
  24007. +
  24008. + if (space > slot_space) {
  24009. + VCHIQ_HEADER_T *header;
  24010. + /* Fill the remaining space with padding */
  24011. + WARN_ON(state->tx_data == NULL);
  24012. + header = (VCHIQ_HEADER_T *)
  24013. + (state->tx_data + (tx_pos & VCHIQ_SLOT_MASK));
  24014. + header->msgid = VCHIQ_MSGID_PADDING;
  24015. + header->size = slot_space - sizeof(VCHIQ_HEADER_T);
  24016. +
  24017. + tx_pos += slot_space;
  24018. + }
  24019. +
  24020. + /* If necessary, get the next slot. */
  24021. + if ((tx_pos & VCHIQ_SLOT_MASK) == 0) {
  24022. + int slot_index;
  24023. +
  24024. + /* If there is no free slot... */
  24025. +
  24026. + if (down_trylock(&state->slot_available_event) != 0) {
  24027. + /* ...wait for one. */
  24028. +
  24029. + VCHIQ_STATS_INC(state, slot_stalls);
  24030. +
  24031. + /* But first, flush through the last slot. */
  24032. + state->local_tx_pos = tx_pos;
  24033. + local->tx_pos = tx_pos;
  24034. + remote_event_signal(&state->remote->trigger);
  24035. +
  24036. + if (!is_blocking ||
  24037. + (down_interruptible(
  24038. + &state->slot_available_event) != 0))
  24039. + return NULL; /* No space available */
  24040. + }
  24041. +
  24042. + BUG_ON(tx_pos ==
  24043. + (state->slot_queue_available * VCHIQ_SLOT_SIZE));
  24044. +
  24045. + slot_index = local->slot_queue[
  24046. + SLOT_QUEUE_INDEX_FROM_POS(tx_pos) &
  24047. + VCHIQ_SLOT_QUEUE_MASK];
  24048. + state->tx_data =
  24049. + (char *)SLOT_DATA_FROM_INDEX(state, slot_index);
  24050. + }
  24051. +
  24052. + state->local_tx_pos = tx_pos + space;
  24053. +
  24054. + return (VCHIQ_HEADER_T *)(state->tx_data + (tx_pos & VCHIQ_SLOT_MASK));
  24055. +}
  24056. +
  24057. +/* Called by the recycle thread. */
  24058. +static void
  24059. +process_free_queue(VCHIQ_STATE_T *state)
  24060. +{
  24061. + VCHIQ_SHARED_STATE_T *local = state->local;
  24062. + BITSET_T service_found[BITSET_SIZE(VCHIQ_MAX_SERVICES)];
  24063. + int slot_queue_available;
  24064. +
  24065. + /* Use a read memory barrier to ensure that any state that may have
  24066. + ** been modified by another thread is not masked by stale prefetched
  24067. + ** values. */
  24068. + rmb();
  24069. +
  24070. + /* Find slots which have been freed by the other side, and return them
  24071. + ** to the available queue. */
  24072. + slot_queue_available = state->slot_queue_available;
  24073. +
  24074. + while (slot_queue_available != local->slot_queue_recycle) {
  24075. + unsigned int pos;
  24076. + int slot_index = local->slot_queue[slot_queue_available++ &
  24077. + VCHIQ_SLOT_QUEUE_MASK];
  24078. + char *data = (char *)SLOT_DATA_FROM_INDEX(state, slot_index);
  24079. + int data_found = 0;
  24080. +
  24081. + vchiq_log_trace(vchiq_core_log_level, "%d: pfq %d=%x %x %x",
  24082. + state->id, slot_index, (unsigned int)data,
  24083. + local->slot_queue_recycle, slot_queue_available);
  24084. +
  24085. + /* Initialise the bitmask for services which have used this
  24086. + ** slot */
  24087. + BITSET_ZERO(service_found);
  24088. +
  24089. + pos = 0;
  24090. +
  24091. + while (pos < VCHIQ_SLOT_SIZE) {
  24092. + VCHIQ_HEADER_T *header =
  24093. + (VCHIQ_HEADER_T *)(data + pos);
  24094. + int msgid = header->msgid;
  24095. + if (VCHIQ_MSG_TYPE(msgid) == VCHIQ_MSG_DATA) {
  24096. + int port = VCHIQ_MSG_SRCPORT(msgid);
  24097. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  24098. + &state->service_quotas[port];
  24099. + int count;
  24100. + spin_lock(&quota_spinlock);
  24101. + count = service_quota->message_use_count;
  24102. + if (count > 0)
  24103. + service_quota->message_use_count =
  24104. + count - 1;
  24105. + spin_unlock(&quota_spinlock);
  24106. +
  24107. + if (count == service_quota->message_quota)
  24108. + /* Signal the service that it
  24109. + ** has dropped below its quota
  24110. + */
  24111. + up(&service_quota->quota_event);
  24112. + else if (count == 0) {
  24113. + vchiq_log_error(vchiq_core_log_level,
  24114. + "service %d "
  24115. + "message_use_count=%d "
  24116. + "(header %x, msgid %x, "
  24117. + "header->msgid %x, "
  24118. + "header->size %x)",
  24119. + port,
  24120. + service_quota->
  24121. + message_use_count,
  24122. + (unsigned int)header, msgid,
  24123. + header->msgid,
  24124. + header->size);
  24125. + WARN(1, "invalid message use count\n");
  24126. + }
  24127. + if (!BITSET_IS_SET(service_found, port)) {
  24128. + /* Set the found bit for this service */
  24129. + BITSET_SET(service_found, port);
  24130. +
  24131. + spin_lock(&quota_spinlock);
  24132. + count = service_quota->slot_use_count;
  24133. + if (count > 0)
  24134. + service_quota->slot_use_count =
  24135. + count - 1;
  24136. + spin_unlock(&quota_spinlock);
  24137. +
  24138. + if (count > 0) {
  24139. + /* Signal the service in case
  24140. + ** it has dropped below its
  24141. + ** quota */
  24142. + up(&service_quota->quota_event);
  24143. + vchiq_log_trace(
  24144. + vchiq_core_log_level,
  24145. + "%d: pfq:%d %x@%x - "
  24146. + "slot_use->%d",
  24147. + state->id, port,
  24148. + header->size,
  24149. + (unsigned int)header,
  24150. + count - 1);
  24151. + } else {
  24152. + vchiq_log_error(
  24153. + vchiq_core_log_level,
  24154. + "service %d "
  24155. + "slot_use_count"
  24156. + "=%d (header %x"
  24157. + ", msgid %x, "
  24158. + "header->msgid"
  24159. + " %x, header->"
  24160. + "size %x)",
  24161. + port, count,
  24162. + (unsigned int)header,
  24163. + msgid,
  24164. + header->msgid,
  24165. + header->size);
  24166. + WARN(1, "bad slot use count\n");
  24167. + }
  24168. + }
  24169. +
  24170. + data_found = 1;
  24171. + }
  24172. +
  24173. + pos += calc_stride(header->size);
  24174. + if (pos > VCHIQ_SLOT_SIZE) {
  24175. + vchiq_log_error(vchiq_core_log_level,
  24176. + "pfq - pos %x: header %x, msgid %x, "
  24177. + "header->msgid %x, header->size %x",
  24178. + pos, (unsigned int)header, msgid,
  24179. + header->msgid, header->size);
  24180. + WARN(1, "invalid slot position\n");
  24181. + }
  24182. + }
  24183. +
  24184. + if (data_found) {
  24185. + int count;
  24186. + spin_lock(&quota_spinlock);
  24187. + count = state->data_use_count;
  24188. + if (count > 0)
  24189. + state->data_use_count =
  24190. + count - 1;
  24191. + spin_unlock(&quota_spinlock);
  24192. + if (count == state->data_quota)
  24193. + up(&state->data_quota_event);
  24194. + }
  24195. +
  24196. + state->slot_queue_available = slot_queue_available;
  24197. + up(&state->slot_available_event);
  24198. + }
  24199. +}
  24200. +
  24201. +/* Called by the slot handler and application threads */
  24202. +static VCHIQ_STATUS_T
  24203. +queue_message(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  24204. + int msgid, const VCHIQ_ELEMENT_T *elements,
  24205. + int count, int size, int is_blocking)
  24206. +{
  24207. + VCHIQ_SHARED_STATE_T *local;
  24208. + VCHIQ_SERVICE_QUOTA_T *service_quota = NULL;
  24209. + VCHIQ_HEADER_T *header;
  24210. + int type = VCHIQ_MSG_TYPE(msgid);
  24211. +
  24212. + unsigned int stride;
  24213. +
  24214. + local = state->local;
  24215. +
  24216. + stride = calc_stride(size);
  24217. +
  24218. + WARN_ON(!(stride <= VCHIQ_SLOT_SIZE));
  24219. +
  24220. + if ((type != VCHIQ_MSG_RESUME) &&
  24221. + (mutex_lock_interruptible(&state->slot_mutex) != 0))
  24222. + return VCHIQ_RETRY;
  24223. +
  24224. + if (type == VCHIQ_MSG_DATA) {
  24225. + int tx_end_index;
  24226. +
  24227. + BUG_ON(!service);
  24228. +
  24229. + if (service->closing) {
  24230. + /* The service has been closed */
  24231. + mutex_unlock(&state->slot_mutex);
  24232. + return VCHIQ_ERROR;
  24233. + }
  24234. +
  24235. + service_quota = &state->service_quotas[service->localport];
  24236. +
  24237. + spin_lock(&quota_spinlock);
  24238. +
  24239. + /* Ensure this service doesn't use more than its quota of
  24240. + ** messages or slots */
  24241. + tx_end_index = SLOT_QUEUE_INDEX_FROM_POS(
  24242. + state->local_tx_pos + stride - 1);
  24243. +
  24244. + /* Ensure data messages don't use more than their quota of
  24245. + ** slots */
  24246. + while ((tx_end_index != state->previous_data_index) &&
  24247. + (state->data_use_count == state->data_quota)) {
  24248. + VCHIQ_STATS_INC(state, data_stalls);
  24249. + spin_unlock(&quota_spinlock);
  24250. + mutex_unlock(&state->slot_mutex);
  24251. +
  24252. + if (down_interruptible(&state->data_quota_event)
  24253. + != 0)
  24254. + return VCHIQ_RETRY;
  24255. +
  24256. + mutex_lock(&state->slot_mutex);
  24257. + spin_lock(&quota_spinlock);
  24258. + tx_end_index = SLOT_QUEUE_INDEX_FROM_POS(
  24259. + state->local_tx_pos + stride - 1);
  24260. + if ((tx_end_index == state->previous_data_index) ||
  24261. + (state->data_use_count < state->data_quota)) {
  24262. + /* Pass the signal on to other waiters */
  24263. + up(&state->data_quota_event);
  24264. + break;
  24265. + }
  24266. + }
  24267. +
  24268. + while ((service_quota->message_use_count ==
  24269. + service_quota->message_quota) ||
  24270. + ((tx_end_index != service_quota->previous_tx_index) &&
  24271. + (service_quota->slot_use_count ==
  24272. + service_quota->slot_quota))) {
  24273. + spin_unlock(&quota_spinlock);
  24274. + vchiq_log_trace(vchiq_core_log_level,
  24275. + "%d: qm:%d %s,%x - quota stall "
  24276. + "(msg %d, slot %d)",
  24277. + state->id, service->localport,
  24278. + msg_type_str(type), size,
  24279. + service_quota->message_use_count,
  24280. + service_quota->slot_use_count);
  24281. + VCHIQ_SERVICE_STATS_INC(service, quota_stalls);
  24282. + mutex_unlock(&state->slot_mutex);
  24283. + if (down_interruptible(&service_quota->quota_event)
  24284. + != 0)
  24285. + return VCHIQ_RETRY;
  24286. + if (service->closing)
  24287. + return VCHIQ_ERROR;
  24288. + if (mutex_lock_interruptible(&state->slot_mutex) != 0)
  24289. + return VCHIQ_RETRY;
  24290. + if (service->srvstate != VCHIQ_SRVSTATE_OPEN) {
  24291. + /* The service has been closed */
  24292. + mutex_unlock(&state->slot_mutex);
  24293. + return VCHIQ_ERROR;
  24294. + }
  24295. + spin_lock(&quota_spinlock);
  24296. + tx_end_index = SLOT_QUEUE_INDEX_FROM_POS(
  24297. + state->local_tx_pos + stride - 1);
  24298. + }
  24299. +
  24300. + spin_unlock(&quota_spinlock);
  24301. + }
  24302. +
  24303. + header = reserve_space(state, stride, is_blocking);
  24304. +
  24305. + if (!header) {
  24306. + if (service)
  24307. + VCHIQ_SERVICE_STATS_INC(service, slot_stalls);
  24308. + mutex_unlock(&state->slot_mutex);
  24309. + return VCHIQ_RETRY;
  24310. + }
  24311. +
  24312. + if (type == VCHIQ_MSG_DATA) {
  24313. + int i, pos;
  24314. + int tx_end_index;
  24315. + int slot_use_count;
  24316. +
  24317. + vchiq_log_info(vchiq_core_log_level,
  24318. + "%d: qm %s@%x,%x (%d->%d)",
  24319. + state->id,
  24320. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  24321. + (unsigned int)header, size,
  24322. + VCHIQ_MSG_SRCPORT(msgid),
  24323. + VCHIQ_MSG_DSTPORT(msgid));
  24324. +
  24325. + BUG_ON(!service);
  24326. +
  24327. + for (i = 0, pos = 0; i < (unsigned int)count;
  24328. + pos += elements[i++].size)
  24329. + if (elements[i].size) {
  24330. + if (vchiq_copy_from_user
  24331. + (header->data + pos, elements[i].data,
  24332. + (size_t) elements[i].size) !=
  24333. + VCHIQ_SUCCESS) {
  24334. + mutex_unlock(&state->slot_mutex);
  24335. + VCHIQ_SERVICE_STATS_INC(service,
  24336. + error_count);
  24337. + return VCHIQ_ERROR;
  24338. + }
  24339. + if (i == 0) {
  24340. + if (vchiq_core_msg_log_level >=
  24341. + VCHIQ_LOG_INFO)
  24342. + vchiq_log_dump_mem("Sent", 0,
  24343. + header->data + pos,
  24344. + min(64u,
  24345. + elements[0].size));
  24346. + }
  24347. + }
  24348. +
  24349. + spin_lock(&quota_spinlock);
  24350. + service_quota->message_use_count++;
  24351. +
  24352. + tx_end_index =
  24353. + SLOT_QUEUE_INDEX_FROM_POS(state->local_tx_pos - 1);
  24354. +
  24355. + /* If this transmission can't fit in the last slot used by any
  24356. + ** service, the data_use_count must be increased. */
  24357. + if (tx_end_index != state->previous_data_index) {
  24358. + state->previous_data_index = tx_end_index;
  24359. + state->data_use_count++;
  24360. + }
  24361. +
  24362. + /* If this isn't the same slot last used by this service,
  24363. + ** the service's slot_use_count must be increased. */
  24364. + if (tx_end_index != service_quota->previous_tx_index) {
  24365. + service_quota->previous_tx_index = tx_end_index;
  24366. + slot_use_count = ++service_quota->slot_use_count;
  24367. + } else {
  24368. + slot_use_count = 0;
  24369. + }
  24370. +
  24371. + spin_unlock(&quota_spinlock);
  24372. +
  24373. + if (slot_use_count)
  24374. + vchiq_log_trace(vchiq_core_log_level,
  24375. + "%d: qm:%d %s,%x - slot_use->%d (hdr %p)",
  24376. + state->id, service->localport,
  24377. + msg_type_str(VCHIQ_MSG_TYPE(msgid)), size,
  24378. + slot_use_count, header);
  24379. +
  24380. + VCHIQ_SERVICE_STATS_INC(service, ctrl_tx_count);
  24381. + VCHIQ_SERVICE_STATS_ADD(service, ctrl_tx_bytes, size);
  24382. + } else {
  24383. + vchiq_log_info(vchiq_core_log_level,
  24384. + "%d: qm %s@%x,%x (%d->%d)", state->id,
  24385. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  24386. + (unsigned int)header, size,
  24387. + VCHIQ_MSG_SRCPORT(msgid),
  24388. + VCHIQ_MSG_DSTPORT(msgid));
  24389. + if (size != 0) {
  24390. + WARN_ON(!((count == 1) && (size == elements[0].size)));
  24391. + memcpy(header->data, elements[0].data,
  24392. + elements[0].size);
  24393. + }
  24394. + VCHIQ_STATS_INC(state, ctrl_tx_count);
  24395. + }
  24396. +
  24397. + header->msgid = msgid;
  24398. + header->size = size;
  24399. +
  24400. + {
  24401. + int svc_fourcc;
  24402. +
  24403. + svc_fourcc = service
  24404. + ? service->base.fourcc
  24405. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  24406. +
  24407. + vchiq_log_info(vchiq_core_msg_log_level,
  24408. + "Sent Msg %s(%u) to %c%c%c%c s:%u d:%d len:%d",
  24409. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  24410. + VCHIQ_MSG_TYPE(msgid),
  24411. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  24412. + VCHIQ_MSG_SRCPORT(msgid),
  24413. + VCHIQ_MSG_DSTPORT(msgid),
  24414. + size);
  24415. + }
  24416. +
  24417. + /* Make sure the new header is visible to the peer. */
  24418. + wmb();
  24419. +
  24420. + /* Make the new tx_pos visible to the peer. */
  24421. + local->tx_pos = state->local_tx_pos;
  24422. + wmb();
  24423. +
  24424. + if (service && (type == VCHIQ_MSG_CLOSE))
  24425. + vchiq_set_service_state(service, VCHIQ_SRVSTATE_CLOSESENT);
  24426. +
  24427. + if (VCHIQ_MSG_TYPE(msgid) != VCHIQ_MSG_PAUSE)
  24428. + mutex_unlock(&state->slot_mutex);
  24429. +
  24430. + remote_event_signal(&state->remote->trigger);
  24431. +
  24432. + return VCHIQ_SUCCESS;
  24433. +}
  24434. +
  24435. +/* Called by the slot handler and application threads */
  24436. +static VCHIQ_STATUS_T
  24437. +queue_message_sync(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  24438. + int msgid, const VCHIQ_ELEMENT_T *elements,
  24439. + int count, int size, int is_blocking)
  24440. +{
  24441. + VCHIQ_SHARED_STATE_T *local;
  24442. + VCHIQ_HEADER_T *header;
  24443. +
  24444. + local = state->local;
  24445. +
  24446. + if ((VCHIQ_MSG_TYPE(msgid) != VCHIQ_MSG_RESUME) &&
  24447. + (mutex_lock_interruptible(&state->sync_mutex) != 0))
  24448. + return VCHIQ_RETRY;
  24449. +
  24450. + remote_event_wait(&local->sync_release);
  24451. +
  24452. + rmb();
  24453. +
  24454. + header = (VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state,
  24455. + local->slot_sync);
  24456. +
  24457. + {
  24458. + int oldmsgid = header->msgid;
  24459. + if (oldmsgid != VCHIQ_MSGID_PADDING)
  24460. + vchiq_log_error(vchiq_core_log_level,
  24461. + "%d: qms - msgid %x, not PADDING",
  24462. + state->id, oldmsgid);
  24463. + }
  24464. +
  24465. + if (service) {
  24466. + int i, pos;
  24467. +
  24468. + vchiq_log_info(vchiq_sync_log_level,
  24469. + "%d: qms %s@%x,%x (%d->%d)", state->id,
  24470. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  24471. + (unsigned int)header, size,
  24472. + VCHIQ_MSG_SRCPORT(msgid),
  24473. + VCHIQ_MSG_DSTPORT(msgid));
  24474. +
  24475. + for (i = 0, pos = 0; i < (unsigned int)count;
  24476. + pos += elements[i++].size)
  24477. + if (elements[i].size) {
  24478. + if (vchiq_copy_from_user
  24479. + (header->data + pos, elements[i].data,
  24480. + (size_t) elements[i].size) !=
  24481. + VCHIQ_SUCCESS) {
  24482. + mutex_unlock(&state->sync_mutex);
  24483. + VCHIQ_SERVICE_STATS_INC(service,
  24484. + error_count);
  24485. + return VCHIQ_ERROR;
  24486. + }
  24487. + if (i == 0) {
  24488. + if (vchiq_sync_log_level >=
  24489. + VCHIQ_LOG_TRACE)
  24490. + vchiq_log_dump_mem("Sent Sync",
  24491. + 0, header->data + pos,
  24492. + min(64u,
  24493. + elements[0].size));
  24494. + }
  24495. + }
  24496. +
  24497. + VCHIQ_SERVICE_STATS_INC(service, ctrl_tx_count);
  24498. + VCHIQ_SERVICE_STATS_ADD(service, ctrl_tx_bytes, size);
  24499. + } else {
  24500. + vchiq_log_info(vchiq_sync_log_level,
  24501. + "%d: qms %s@%x,%x (%d->%d)", state->id,
  24502. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  24503. + (unsigned int)header, size,
  24504. + VCHIQ_MSG_SRCPORT(msgid),
  24505. + VCHIQ_MSG_DSTPORT(msgid));
  24506. + if (size != 0) {
  24507. + WARN_ON(!((count == 1) && (size == elements[0].size)));
  24508. + memcpy(header->data, elements[0].data,
  24509. + elements[0].size);
  24510. + }
  24511. + VCHIQ_STATS_INC(state, ctrl_tx_count);
  24512. + }
  24513. +
  24514. + header->size = size;
  24515. + header->msgid = msgid;
  24516. +
  24517. + if (vchiq_sync_log_level >= VCHIQ_LOG_TRACE) {
  24518. + int svc_fourcc;
  24519. +
  24520. + svc_fourcc = service
  24521. + ? service->base.fourcc
  24522. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  24523. +
  24524. + vchiq_log_trace(vchiq_sync_log_level,
  24525. + "Sent Sync Msg %s(%u) to %c%c%c%c s:%u d:%d len:%d",
  24526. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  24527. + VCHIQ_MSG_TYPE(msgid),
  24528. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  24529. + VCHIQ_MSG_SRCPORT(msgid),
  24530. + VCHIQ_MSG_DSTPORT(msgid),
  24531. + size);
  24532. + }
  24533. +
  24534. + /* Make sure the new header is visible to the peer. */
  24535. + wmb();
  24536. +
  24537. + remote_event_signal(&state->remote->sync_trigger);
  24538. +
  24539. + if (VCHIQ_MSG_TYPE(msgid) != VCHIQ_MSG_PAUSE)
  24540. + mutex_unlock(&state->sync_mutex);
  24541. +
  24542. + return VCHIQ_SUCCESS;
  24543. +}
  24544. +
  24545. +static inline void
  24546. +claim_slot(VCHIQ_SLOT_INFO_T *slot)
  24547. +{
  24548. + slot->use_count++;
  24549. +}
  24550. +
  24551. +static void
  24552. +release_slot(VCHIQ_STATE_T *state, VCHIQ_SLOT_INFO_T *slot_info,
  24553. + VCHIQ_HEADER_T *header, VCHIQ_SERVICE_T *service)
  24554. +{
  24555. + int release_count;
  24556. +
  24557. + mutex_lock(&state->recycle_mutex);
  24558. +
  24559. + if (header) {
  24560. + int msgid = header->msgid;
  24561. + if (((msgid & VCHIQ_MSGID_CLAIMED) == 0) ||
  24562. + (service && service->closing)) {
  24563. + mutex_unlock(&state->recycle_mutex);
  24564. + return;
  24565. + }
  24566. +
  24567. + /* Rewrite the message header to prevent a double
  24568. + ** release */
  24569. + header->msgid = msgid & ~VCHIQ_MSGID_CLAIMED;
  24570. + }
  24571. +
  24572. + release_count = slot_info->release_count;
  24573. + slot_info->release_count = ++release_count;
  24574. +
  24575. + if (release_count == slot_info->use_count) {
  24576. + int slot_queue_recycle;
  24577. + /* Add to the freed queue */
  24578. +
  24579. + /* A read barrier is necessary here to prevent speculative
  24580. + ** fetches of remote->slot_queue_recycle from overtaking the
  24581. + ** mutex. */
  24582. + rmb();
  24583. +
  24584. + slot_queue_recycle = state->remote->slot_queue_recycle;
  24585. + state->remote->slot_queue[slot_queue_recycle &
  24586. + VCHIQ_SLOT_QUEUE_MASK] =
  24587. + SLOT_INDEX_FROM_INFO(state, slot_info);
  24588. + state->remote->slot_queue_recycle = slot_queue_recycle + 1;
  24589. + vchiq_log_info(vchiq_core_log_level,
  24590. + "%d: release_slot %d - recycle->%x",
  24591. + state->id, SLOT_INDEX_FROM_INFO(state, slot_info),
  24592. + state->remote->slot_queue_recycle);
  24593. +
  24594. + /* A write barrier is necessary, but remote_event_signal
  24595. + ** contains one. */
  24596. + remote_event_signal(&state->remote->recycle);
  24597. + }
  24598. +
  24599. + mutex_unlock(&state->recycle_mutex);
  24600. +}
  24601. +
  24602. +/* Called by the slot handler - don't hold the bulk mutex */
  24603. +static VCHIQ_STATUS_T
  24604. +notify_bulks(VCHIQ_SERVICE_T *service, VCHIQ_BULK_QUEUE_T *queue,
  24605. + int retry_poll)
  24606. +{
  24607. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  24608. +
  24609. + vchiq_log_trace(vchiq_core_log_level,
  24610. + "%d: nb:%d %cx - p=%x rn=%x r=%x",
  24611. + service->state->id, service->localport,
  24612. + (queue == &service->bulk_tx) ? 't' : 'r',
  24613. + queue->process, queue->remote_notify, queue->remove);
  24614. +
  24615. + if (service->state->is_master) {
  24616. + while (queue->remote_notify != queue->process) {
  24617. + VCHIQ_BULK_T *bulk =
  24618. + &queue->bulks[BULK_INDEX(queue->remote_notify)];
  24619. + int msgtype = (bulk->dir == VCHIQ_BULK_TRANSMIT) ?
  24620. + VCHIQ_MSG_BULK_RX_DONE : VCHIQ_MSG_BULK_TX_DONE;
  24621. + int msgid = VCHIQ_MAKE_MSG(msgtype, service->localport,
  24622. + service->remoteport);
  24623. + VCHIQ_ELEMENT_T element = { &bulk->actual, 4 };
  24624. + /* Only reply to non-dummy bulk requests */
  24625. + if (bulk->remote_data) {
  24626. + status = queue_message(service->state, NULL,
  24627. + msgid, &element, 1, 4, 0);
  24628. + if (status != VCHIQ_SUCCESS)
  24629. + break;
  24630. + }
  24631. + queue->remote_notify++;
  24632. + }
  24633. + } else {
  24634. + queue->remote_notify = queue->process;
  24635. + }
  24636. +
  24637. + if (status == VCHIQ_SUCCESS) {
  24638. + while (queue->remove != queue->remote_notify) {
  24639. + VCHIQ_BULK_T *bulk =
  24640. + &queue->bulks[BULK_INDEX(queue->remove)];
  24641. +
  24642. + /* Only generate callbacks for non-dummy bulk
  24643. + ** requests, and non-terminated services */
  24644. + if (bulk->data && service->instance) {
  24645. + if (bulk->actual != VCHIQ_BULK_ACTUAL_ABORTED) {
  24646. + if (bulk->dir == VCHIQ_BULK_TRANSMIT) {
  24647. + VCHIQ_SERVICE_STATS_INC(service,
  24648. + bulk_tx_count);
  24649. + VCHIQ_SERVICE_STATS_ADD(service,
  24650. + bulk_tx_bytes,
  24651. + bulk->actual);
  24652. + } else {
  24653. + VCHIQ_SERVICE_STATS_INC(service,
  24654. + bulk_rx_count);
  24655. + VCHIQ_SERVICE_STATS_ADD(service,
  24656. + bulk_rx_bytes,
  24657. + bulk->actual);
  24658. + }
  24659. + } else {
  24660. + VCHIQ_SERVICE_STATS_INC(service,
  24661. + bulk_aborted_count);
  24662. + }
  24663. + if (bulk->mode == VCHIQ_BULK_MODE_BLOCKING) {
  24664. + struct bulk_waiter *waiter;
  24665. + spin_lock(&bulk_waiter_spinlock);
  24666. + waiter = bulk->userdata;
  24667. + if (waiter) {
  24668. + waiter->actual = bulk->actual;
  24669. + up(&waiter->event);
  24670. + }
  24671. + spin_unlock(&bulk_waiter_spinlock);
  24672. + } else if (bulk->mode ==
  24673. + VCHIQ_BULK_MODE_CALLBACK) {
  24674. + VCHIQ_REASON_T reason = (bulk->dir ==
  24675. + VCHIQ_BULK_TRANSMIT) ?
  24676. + ((bulk->actual ==
  24677. + VCHIQ_BULK_ACTUAL_ABORTED) ?
  24678. + VCHIQ_BULK_TRANSMIT_ABORTED :
  24679. + VCHIQ_BULK_TRANSMIT_DONE) :
  24680. + ((bulk->actual ==
  24681. + VCHIQ_BULK_ACTUAL_ABORTED) ?
  24682. + VCHIQ_BULK_RECEIVE_ABORTED :
  24683. + VCHIQ_BULK_RECEIVE_DONE);
  24684. + status = make_service_callback(service,
  24685. + reason, NULL, bulk->userdata);
  24686. + if (status == VCHIQ_RETRY)
  24687. + break;
  24688. + }
  24689. + }
  24690. +
  24691. + queue->remove++;
  24692. + up(&service->bulk_remove_event);
  24693. + }
  24694. + if (!retry_poll)
  24695. + status = VCHIQ_SUCCESS;
  24696. + }
  24697. +
  24698. + if (status == VCHIQ_RETRY)
  24699. + request_poll(service->state, service,
  24700. + (queue == &service->bulk_tx) ?
  24701. + VCHIQ_POLL_TXNOTIFY : VCHIQ_POLL_RXNOTIFY);
  24702. +
  24703. + return status;
  24704. +}
  24705. +
  24706. +/* Called by the slot handler thread */
  24707. +static void
  24708. +poll_services(VCHIQ_STATE_T *state)
  24709. +{
  24710. + int group, i;
  24711. +
  24712. + for (group = 0; group < BITSET_SIZE(state->unused_service); group++) {
  24713. + uint32_t flags;
  24714. + flags = atomic_xchg(&state->poll_services[group], 0);
  24715. + for (i = 0; flags; i++) {
  24716. + if (flags & (1 << i)) {
  24717. + VCHIQ_SERVICE_T *service =
  24718. + find_service_by_port(state,
  24719. + (group<<5) + i);
  24720. + uint32_t service_flags;
  24721. + flags &= ~(1 << i);
  24722. + if (!service)
  24723. + continue;
  24724. + service_flags =
  24725. + atomic_xchg(&service->poll_flags, 0);
  24726. + if (service_flags &
  24727. + (1 << VCHIQ_POLL_REMOVE)) {
  24728. + vchiq_log_info(vchiq_core_log_level,
  24729. + "%d: ps - remove %d<->%d",
  24730. + state->id, service->localport,
  24731. + service->remoteport);
  24732. +
  24733. + /* Make it look like a client, because
  24734. + it must be removed and not left in
  24735. + the LISTENING state. */
  24736. + service->public_fourcc =
  24737. + VCHIQ_FOURCC_INVALID;
  24738. +
  24739. + if (vchiq_close_service_internal(
  24740. + service, 0/*!close_recvd*/) !=
  24741. + VCHIQ_SUCCESS)
  24742. + request_poll(state, service,
  24743. + VCHIQ_POLL_REMOVE);
  24744. + } else if (service_flags &
  24745. + (1 << VCHIQ_POLL_TERMINATE)) {
  24746. + vchiq_log_info(vchiq_core_log_level,
  24747. + "%d: ps - terminate %d<->%d",
  24748. + state->id, service->localport,
  24749. + service->remoteport);
  24750. + if (vchiq_close_service_internal(
  24751. + service, 0/*!close_recvd*/) !=
  24752. + VCHIQ_SUCCESS)
  24753. + request_poll(state, service,
  24754. + VCHIQ_POLL_TERMINATE);
  24755. + }
  24756. + if (service_flags & (1 << VCHIQ_POLL_TXNOTIFY))
  24757. + notify_bulks(service,
  24758. + &service->bulk_tx,
  24759. + 1/*retry_poll*/);
  24760. + if (service_flags & (1 << VCHIQ_POLL_RXNOTIFY))
  24761. + notify_bulks(service,
  24762. + &service->bulk_rx,
  24763. + 1/*retry_poll*/);
  24764. + unlock_service(service);
  24765. + }
  24766. + }
  24767. + }
  24768. +}
  24769. +
  24770. +/* Called by the slot handler or application threads, holding the bulk mutex. */
  24771. +static int
  24772. +resolve_bulks(VCHIQ_SERVICE_T *service, VCHIQ_BULK_QUEUE_T *queue)
  24773. +{
  24774. + VCHIQ_STATE_T *state = service->state;
  24775. + int resolved = 0;
  24776. + int rc;
  24777. +
  24778. + while ((queue->process != queue->local_insert) &&
  24779. + (queue->process != queue->remote_insert)) {
  24780. + VCHIQ_BULK_T *bulk = &queue->bulks[BULK_INDEX(queue->process)];
  24781. +
  24782. + vchiq_log_trace(vchiq_core_log_level,
  24783. + "%d: rb:%d %cx - li=%x ri=%x p=%x",
  24784. + state->id, service->localport,
  24785. + (queue == &service->bulk_tx) ? 't' : 'r',
  24786. + queue->local_insert, queue->remote_insert,
  24787. + queue->process);
  24788. +
  24789. + WARN_ON(!((int)(queue->local_insert - queue->process) > 0));
  24790. + WARN_ON(!((int)(queue->remote_insert - queue->process) > 0));
  24791. +
  24792. + rc = mutex_lock_interruptible(&state->bulk_transfer_mutex);
  24793. + if (rc != 0)
  24794. + break;
  24795. +
  24796. + vchiq_transfer_bulk(bulk);
  24797. + mutex_unlock(&state->bulk_transfer_mutex);
  24798. +
  24799. + if (vchiq_core_msg_log_level >= VCHIQ_LOG_INFO) {
  24800. + const char *header = (queue == &service->bulk_tx) ?
  24801. + "Send Bulk to" : "Recv Bulk from";
  24802. + if (bulk->actual != VCHIQ_BULK_ACTUAL_ABORTED)
  24803. + vchiq_log_info(vchiq_core_msg_log_level,
  24804. + "%s %c%c%c%c d:%d len:%d %x<->%x",
  24805. + header,
  24806. + VCHIQ_FOURCC_AS_4CHARS(
  24807. + service->base.fourcc),
  24808. + service->remoteport,
  24809. + bulk->size,
  24810. + (unsigned int)bulk->data,
  24811. + (unsigned int)bulk->remote_data);
  24812. + else
  24813. + vchiq_log_info(vchiq_core_msg_log_level,
  24814. + "%s %c%c%c%c d:%d ABORTED - tx len:%d,"
  24815. + " rx len:%d %x<->%x",
  24816. + header,
  24817. + VCHIQ_FOURCC_AS_4CHARS(
  24818. + service->base.fourcc),
  24819. + service->remoteport,
  24820. + bulk->size,
  24821. + bulk->remote_size,
  24822. + (unsigned int)bulk->data,
  24823. + (unsigned int)bulk->remote_data);
  24824. + }
  24825. +
  24826. + vchiq_complete_bulk(bulk);
  24827. + queue->process++;
  24828. + resolved++;
  24829. + }
  24830. + return resolved;
  24831. +}
  24832. +
  24833. +/* Called with the bulk_mutex held */
  24834. +static void
  24835. +abort_outstanding_bulks(VCHIQ_SERVICE_T *service, VCHIQ_BULK_QUEUE_T *queue)
  24836. +{
  24837. + int is_tx = (queue == &service->bulk_tx);
  24838. + vchiq_log_trace(vchiq_core_log_level,
  24839. + "%d: aob:%d %cx - li=%x ri=%x p=%x",
  24840. + service->state->id, service->localport, is_tx ? 't' : 'r',
  24841. + queue->local_insert, queue->remote_insert, queue->process);
  24842. +
  24843. + WARN_ON(!((int)(queue->local_insert - queue->process) >= 0));
  24844. + WARN_ON(!((int)(queue->remote_insert - queue->process) >= 0));
  24845. +
  24846. + while ((queue->process != queue->local_insert) ||
  24847. + (queue->process != queue->remote_insert)) {
  24848. + VCHIQ_BULK_T *bulk = &queue->bulks[BULK_INDEX(queue->process)];
  24849. +
  24850. + if (queue->process == queue->remote_insert) {
  24851. + /* fabricate a matching dummy bulk */
  24852. + bulk->remote_data = NULL;
  24853. + bulk->remote_size = 0;
  24854. + queue->remote_insert++;
  24855. + }
  24856. +
  24857. + if (queue->process != queue->local_insert) {
  24858. + vchiq_complete_bulk(bulk);
  24859. +
  24860. + vchiq_log_info(vchiq_core_msg_log_level,
  24861. + "%s %c%c%c%c d:%d ABORTED - tx len:%d, "
  24862. + "rx len:%d",
  24863. + is_tx ? "Send Bulk to" : "Recv Bulk from",
  24864. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  24865. + service->remoteport,
  24866. + bulk->size,
  24867. + bulk->remote_size);
  24868. + } else {
  24869. + /* fabricate a matching dummy bulk */
  24870. + bulk->data = NULL;
  24871. + bulk->size = 0;
  24872. + bulk->actual = VCHIQ_BULK_ACTUAL_ABORTED;
  24873. + bulk->dir = is_tx ? VCHIQ_BULK_TRANSMIT :
  24874. + VCHIQ_BULK_RECEIVE;
  24875. + queue->local_insert++;
  24876. + }
  24877. +
  24878. + queue->process++;
  24879. + }
  24880. +}
  24881. +
  24882. +/* Called from the slot handler thread */
  24883. +static void
  24884. +pause_bulks(VCHIQ_STATE_T *state)
  24885. +{
  24886. + if (unlikely(atomic_inc_return(&pause_bulks_count) != 1)) {
  24887. + WARN_ON_ONCE(1);
  24888. + atomic_set(&pause_bulks_count, 1);
  24889. + return;
  24890. + }
  24891. +
  24892. + /* Block bulk transfers from all services */
  24893. + mutex_lock(&state->bulk_transfer_mutex);
  24894. +}
  24895. +
  24896. +/* Called from the slot handler thread */
  24897. +static void
  24898. +resume_bulks(VCHIQ_STATE_T *state)
  24899. +{
  24900. + int i;
  24901. + if (unlikely(atomic_dec_return(&pause_bulks_count) != 0)) {
  24902. + WARN_ON_ONCE(1);
  24903. + atomic_set(&pause_bulks_count, 0);
  24904. + return;
  24905. + }
  24906. +
  24907. + /* Allow bulk transfers from all services */
  24908. + mutex_unlock(&state->bulk_transfer_mutex);
  24909. +
  24910. + if (state->deferred_bulks == 0)
  24911. + return;
  24912. +
  24913. + /* Deal with any bulks which had to be deferred due to being in
  24914. + * paused state. Don't try to match up to number of deferred bulks
  24915. + * in case we've had something come and close the service in the
  24916. + * interim - just process all bulk queues for all services */
  24917. + vchiq_log_info(vchiq_core_log_level, "%s: processing %d deferred bulks",
  24918. + __func__, state->deferred_bulks);
  24919. +
  24920. + for (i = 0; i < state->unused_service; i++) {
  24921. + VCHIQ_SERVICE_T *service = state->services[i];
  24922. + int resolved_rx = 0;
  24923. + int resolved_tx = 0;
  24924. + if (!service || (service->srvstate != VCHIQ_SRVSTATE_OPEN))
  24925. + continue;
  24926. +
  24927. + mutex_lock(&service->bulk_mutex);
  24928. + resolved_rx = resolve_bulks(service, &service->bulk_rx);
  24929. + resolved_tx = resolve_bulks(service, &service->bulk_tx);
  24930. + mutex_unlock(&service->bulk_mutex);
  24931. + if (resolved_rx)
  24932. + notify_bulks(service, &service->bulk_rx, 1);
  24933. + if (resolved_tx)
  24934. + notify_bulks(service, &service->bulk_tx, 1);
  24935. + }
  24936. + state->deferred_bulks = 0;
  24937. +}
  24938. +
  24939. +static int
  24940. +parse_open(VCHIQ_STATE_T *state, VCHIQ_HEADER_T *header)
  24941. +{
  24942. + VCHIQ_SERVICE_T *service = NULL;
  24943. + int msgid, size;
  24944. + int type;
  24945. + unsigned int localport, remoteport;
  24946. +
  24947. + msgid = header->msgid;
  24948. + size = header->size;
  24949. + type = VCHIQ_MSG_TYPE(msgid);
  24950. + localport = VCHIQ_MSG_DSTPORT(msgid);
  24951. + remoteport = VCHIQ_MSG_SRCPORT(msgid);
  24952. + if (size >= sizeof(struct vchiq_open_payload)) {
  24953. + const struct vchiq_open_payload *payload =
  24954. + (struct vchiq_open_payload *)header->data;
  24955. + unsigned int fourcc;
  24956. +
  24957. + fourcc = payload->fourcc;
  24958. + vchiq_log_info(vchiq_core_log_level,
  24959. + "%d: prs OPEN@%x (%d->'%c%c%c%c')",
  24960. + state->id, (unsigned int)header,
  24961. + localport,
  24962. + VCHIQ_FOURCC_AS_4CHARS(fourcc));
  24963. +
  24964. + service = get_listening_service(state, fourcc);
  24965. +
  24966. + if (service) {
  24967. + /* A matching service exists */
  24968. + short version = payload->version;
  24969. + short version_min = payload->version_min;
  24970. + if ((service->version < version_min) ||
  24971. + (version < service->version_min)) {
  24972. + /* Version mismatch */
  24973. + vchiq_loud_error_header();
  24974. + vchiq_loud_error("%d: service %d (%c%c%c%c) "
  24975. + "version mismatch - local (%d, min %d)"
  24976. + " vs. remote (%d, min %d)",
  24977. + state->id, service->localport,
  24978. + VCHIQ_FOURCC_AS_4CHARS(fourcc),
  24979. + service->version, service->version_min,
  24980. + version, version_min);
  24981. + vchiq_loud_error_footer();
  24982. + unlock_service(service);
  24983. + service = NULL;
  24984. + goto fail_open;
  24985. + }
  24986. + service->peer_version = version;
  24987. +
  24988. + if (service->srvstate == VCHIQ_SRVSTATE_LISTENING) {
  24989. + struct vchiq_openack_payload ack_payload = {
  24990. + service->version
  24991. + };
  24992. + VCHIQ_ELEMENT_T body = {
  24993. + &ack_payload,
  24994. + sizeof(ack_payload)
  24995. + };
  24996. +
  24997. + /* Acknowledge the OPEN */
  24998. + if (service->sync) {
  24999. + if (queue_message_sync(state, NULL,
  25000. + VCHIQ_MAKE_MSG(
  25001. + VCHIQ_MSG_OPENACK,
  25002. + service->localport,
  25003. + remoteport),
  25004. + &body, 1, sizeof(ack_payload),
  25005. + 0) == VCHIQ_RETRY)
  25006. + goto bail_not_ready;
  25007. + } else {
  25008. + if (queue_message(state, NULL,
  25009. + VCHIQ_MAKE_MSG(
  25010. + VCHIQ_MSG_OPENACK,
  25011. + service->localport,
  25012. + remoteport),
  25013. + &body, 1, sizeof(ack_payload),
  25014. + 0) == VCHIQ_RETRY)
  25015. + goto bail_not_ready;
  25016. + }
  25017. +
  25018. + /* The service is now open */
  25019. + vchiq_set_service_state(service,
  25020. + service->sync ? VCHIQ_SRVSTATE_OPENSYNC
  25021. + : VCHIQ_SRVSTATE_OPEN);
  25022. + }
  25023. +
  25024. + service->remoteport = remoteport;
  25025. + service->client_id = ((int *)header->data)[1];
  25026. + if (make_service_callback(service, VCHIQ_SERVICE_OPENED,
  25027. + NULL, NULL) == VCHIQ_RETRY) {
  25028. + /* Bail out if not ready */
  25029. + service->remoteport = VCHIQ_PORT_FREE;
  25030. + goto bail_not_ready;
  25031. + }
  25032. +
  25033. + /* Success - the message has been dealt with */
  25034. + unlock_service(service);
  25035. + return 1;
  25036. + }
  25037. + }
  25038. +
  25039. +fail_open:
  25040. + /* No available service, or an invalid request - send a CLOSE */
  25041. + if (queue_message(state, NULL,
  25042. + VCHIQ_MAKE_MSG(VCHIQ_MSG_CLOSE, 0, VCHIQ_MSG_SRCPORT(msgid)),
  25043. + NULL, 0, 0, 0) == VCHIQ_RETRY)
  25044. + goto bail_not_ready;
  25045. +
  25046. + return 1;
  25047. +
  25048. +bail_not_ready:
  25049. + if (service)
  25050. + unlock_service(service);
  25051. +
  25052. + return 0;
  25053. +}
  25054. +
  25055. +/* Called by the slot handler thread */
  25056. +static void
  25057. +parse_rx_slots(VCHIQ_STATE_T *state)
  25058. +{
  25059. + VCHIQ_SHARED_STATE_T *remote = state->remote;
  25060. + VCHIQ_SERVICE_T *service = NULL;
  25061. + int tx_pos;
  25062. + DEBUG_INITIALISE(state->local)
  25063. +
  25064. + tx_pos = remote->tx_pos;
  25065. +
  25066. + while (state->rx_pos != tx_pos) {
  25067. + VCHIQ_HEADER_T *header;
  25068. + int msgid, size;
  25069. + int type;
  25070. + unsigned int localport, remoteport;
  25071. +
  25072. + DEBUG_TRACE(PARSE_LINE);
  25073. + if (!state->rx_data) {
  25074. + int rx_index;
  25075. + WARN_ON(!((state->rx_pos & VCHIQ_SLOT_MASK) == 0));
  25076. + rx_index = remote->slot_queue[
  25077. + SLOT_QUEUE_INDEX_FROM_POS(state->rx_pos) &
  25078. + VCHIQ_SLOT_QUEUE_MASK];
  25079. + state->rx_data = (char *)SLOT_DATA_FROM_INDEX(state,
  25080. + rx_index);
  25081. + state->rx_info = SLOT_INFO_FROM_INDEX(state, rx_index);
  25082. +
  25083. + /* Initialise use_count to one, and increment
  25084. + ** release_count at the end of the slot to avoid
  25085. + ** releasing the slot prematurely. */
  25086. + state->rx_info->use_count = 1;
  25087. + state->rx_info->release_count = 0;
  25088. + }
  25089. +
  25090. + header = (VCHIQ_HEADER_T *)(state->rx_data +
  25091. + (state->rx_pos & VCHIQ_SLOT_MASK));
  25092. + DEBUG_VALUE(PARSE_HEADER, (int)header);
  25093. + msgid = header->msgid;
  25094. + DEBUG_VALUE(PARSE_MSGID, msgid);
  25095. + size = header->size;
  25096. + type = VCHIQ_MSG_TYPE(msgid);
  25097. + localport = VCHIQ_MSG_DSTPORT(msgid);
  25098. + remoteport = VCHIQ_MSG_SRCPORT(msgid);
  25099. +
  25100. + if (type != VCHIQ_MSG_DATA)
  25101. + VCHIQ_STATS_INC(state, ctrl_rx_count);
  25102. +
  25103. + switch (type) {
  25104. + case VCHIQ_MSG_OPENACK:
  25105. + case VCHIQ_MSG_CLOSE:
  25106. + case VCHIQ_MSG_DATA:
  25107. + case VCHIQ_MSG_BULK_RX:
  25108. + case VCHIQ_MSG_BULK_TX:
  25109. + case VCHIQ_MSG_BULK_RX_DONE:
  25110. + case VCHIQ_MSG_BULK_TX_DONE:
  25111. + service = find_service_by_port(state, localport);
  25112. + if ((!service || service->remoteport != remoteport) &&
  25113. + (localport == 0) &&
  25114. + (type == VCHIQ_MSG_CLOSE)) {
  25115. + /* This could be a CLOSE from a client which
  25116. + hadn't yet received the OPENACK - look for
  25117. + the connected service */
  25118. + if (service)
  25119. + unlock_service(service);
  25120. + service = get_connected_service(state,
  25121. + remoteport);
  25122. + if (service)
  25123. + vchiq_log_warning(vchiq_core_log_level,
  25124. + "%d: prs %s@%x (%d->%d) - "
  25125. + "found connected service %d",
  25126. + state->id, msg_type_str(type),
  25127. + (unsigned int)header,
  25128. + remoteport, localport,
  25129. + service->localport);
  25130. + }
  25131. +
  25132. + if (!service) {
  25133. + vchiq_log_error(vchiq_core_log_level,
  25134. + "%d: prs %s@%x (%d->%d) - "
  25135. + "invalid/closed service %d",
  25136. + state->id, msg_type_str(type),
  25137. + (unsigned int)header,
  25138. + remoteport, localport, localport);
  25139. + goto skip_message;
  25140. + }
  25141. + break;
  25142. + default:
  25143. + break;
  25144. + }
  25145. +
  25146. + if (vchiq_core_msg_log_level >= VCHIQ_LOG_INFO) {
  25147. + int svc_fourcc;
  25148. +
  25149. + svc_fourcc = service
  25150. + ? service->base.fourcc
  25151. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  25152. + vchiq_log_info(vchiq_core_msg_log_level,
  25153. + "Rcvd Msg %s(%u) from %c%c%c%c s:%d d:%d "
  25154. + "len:%d",
  25155. + msg_type_str(type), type,
  25156. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  25157. + remoteport, localport, size);
  25158. + if (size > 0)
  25159. + vchiq_log_dump_mem("Rcvd", 0, header->data,
  25160. + min(64, size));
  25161. + }
  25162. +
  25163. + if (((unsigned int)header & VCHIQ_SLOT_MASK) + calc_stride(size)
  25164. + > VCHIQ_SLOT_SIZE) {
  25165. + vchiq_log_error(vchiq_core_log_level,
  25166. + "header %x (msgid %x) - size %x too big for "
  25167. + "slot",
  25168. + (unsigned int)header, (unsigned int)msgid,
  25169. + (unsigned int)size);
  25170. + WARN(1, "oversized for slot\n");
  25171. + }
  25172. +
  25173. + switch (type) {
  25174. + case VCHIQ_MSG_OPEN:
  25175. + WARN_ON(!(VCHIQ_MSG_DSTPORT(msgid) == 0));
  25176. + if (!parse_open(state, header))
  25177. + goto bail_not_ready;
  25178. + break;
  25179. + case VCHIQ_MSG_OPENACK:
  25180. + if (size >= sizeof(struct vchiq_openack_payload)) {
  25181. + const struct vchiq_openack_payload *payload =
  25182. + (struct vchiq_openack_payload *)
  25183. + header->data;
  25184. + service->peer_version = payload->version;
  25185. + }
  25186. + vchiq_log_info(vchiq_core_log_level,
  25187. + "%d: prs OPENACK@%x,%x (%d->%d) v:%d",
  25188. + state->id, (unsigned int)header, size,
  25189. + remoteport, localport, service->peer_version);
  25190. + if (service->srvstate ==
  25191. + VCHIQ_SRVSTATE_OPENING) {
  25192. + service->remoteport = remoteport;
  25193. + vchiq_set_service_state(service,
  25194. + VCHIQ_SRVSTATE_OPEN);
  25195. + up(&service->remove_event);
  25196. + } else
  25197. + vchiq_log_error(vchiq_core_log_level,
  25198. + "OPENACK received in state %s",
  25199. + srvstate_names[service->srvstate]);
  25200. + break;
  25201. + case VCHIQ_MSG_CLOSE:
  25202. + WARN_ON(size != 0); /* There should be no data */
  25203. +
  25204. + vchiq_log_info(vchiq_core_log_level,
  25205. + "%d: prs CLOSE@%x (%d->%d)",
  25206. + state->id, (unsigned int)header,
  25207. + remoteport, localport);
  25208. +
  25209. + mark_service_closing_internal(service, 1);
  25210. +
  25211. + if (vchiq_close_service_internal(service,
  25212. + 1/*close_recvd*/) == VCHIQ_RETRY)
  25213. + goto bail_not_ready;
  25214. +
  25215. + vchiq_log_info(vchiq_core_log_level,
  25216. + "Close Service %c%c%c%c s:%u d:%d",
  25217. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  25218. + service->localport,
  25219. + service->remoteport);
  25220. + break;
  25221. + case VCHIQ_MSG_DATA:
  25222. + vchiq_log_trace(vchiq_core_log_level,
  25223. + "%d: prs DATA@%x,%x (%d->%d)",
  25224. + state->id, (unsigned int)header, size,
  25225. + remoteport, localport);
  25226. +
  25227. + if ((service->remoteport == remoteport)
  25228. + && (service->srvstate ==
  25229. + VCHIQ_SRVSTATE_OPEN)) {
  25230. + header->msgid = msgid | VCHIQ_MSGID_CLAIMED;
  25231. + claim_slot(state->rx_info);
  25232. + DEBUG_TRACE(PARSE_LINE);
  25233. + if (make_service_callback(service,
  25234. + VCHIQ_MESSAGE_AVAILABLE, header,
  25235. + NULL) == VCHIQ_RETRY) {
  25236. + DEBUG_TRACE(PARSE_LINE);
  25237. + goto bail_not_ready;
  25238. + }
  25239. + VCHIQ_SERVICE_STATS_INC(service, ctrl_rx_count);
  25240. + VCHIQ_SERVICE_STATS_ADD(service, ctrl_rx_bytes,
  25241. + size);
  25242. + } else {
  25243. + VCHIQ_STATS_INC(state, error_count);
  25244. + }
  25245. + break;
  25246. + case VCHIQ_MSG_CONNECT:
  25247. + vchiq_log_info(vchiq_core_log_level,
  25248. + "%d: prs CONNECT@%x",
  25249. + state->id, (unsigned int)header);
  25250. + up(&state->connect);
  25251. + break;
  25252. + case VCHIQ_MSG_BULK_RX:
  25253. + case VCHIQ_MSG_BULK_TX: {
  25254. + VCHIQ_BULK_QUEUE_T *queue;
  25255. + WARN_ON(!state->is_master);
  25256. + queue = (type == VCHIQ_MSG_BULK_RX) ?
  25257. + &service->bulk_tx : &service->bulk_rx;
  25258. + if ((service->remoteport == remoteport)
  25259. + && (service->srvstate ==
  25260. + VCHIQ_SRVSTATE_OPEN)) {
  25261. + VCHIQ_BULK_T *bulk;
  25262. + int resolved = 0;
  25263. +
  25264. + DEBUG_TRACE(PARSE_LINE);
  25265. + if (mutex_lock_interruptible(
  25266. + &service->bulk_mutex) != 0) {
  25267. + DEBUG_TRACE(PARSE_LINE);
  25268. + goto bail_not_ready;
  25269. + }
  25270. +
  25271. + WARN_ON(!(queue->remote_insert < queue->remove +
  25272. + VCHIQ_NUM_SERVICE_BULKS));
  25273. + bulk = &queue->bulks[
  25274. + BULK_INDEX(queue->remote_insert)];
  25275. + bulk->remote_data =
  25276. + (void *)((int *)header->data)[0];
  25277. + bulk->remote_size = ((int *)header->data)[1];
  25278. + wmb();
  25279. +
  25280. + vchiq_log_info(vchiq_core_log_level,
  25281. + "%d: prs %s@%x (%d->%d) %x@%x",
  25282. + state->id, msg_type_str(type),
  25283. + (unsigned int)header,
  25284. + remoteport, localport,
  25285. + bulk->remote_size,
  25286. + (unsigned int)bulk->remote_data);
  25287. +
  25288. + queue->remote_insert++;
  25289. +
  25290. + if (atomic_read(&pause_bulks_count)) {
  25291. + state->deferred_bulks++;
  25292. + vchiq_log_info(vchiq_core_log_level,
  25293. + "%s: deferring bulk (%d)",
  25294. + __func__,
  25295. + state->deferred_bulks);
  25296. + if (state->conn_state !=
  25297. + VCHIQ_CONNSTATE_PAUSE_SENT)
  25298. + vchiq_log_error(
  25299. + vchiq_core_log_level,
  25300. + "%s: bulks paused in "
  25301. + "unexpected state %s",
  25302. + __func__,
  25303. + conn_state_names[
  25304. + state->conn_state]);
  25305. + } else if (state->conn_state ==
  25306. + VCHIQ_CONNSTATE_CONNECTED) {
  25307. + DEBUG_TRACE(PARSE_LINE);
  25308. + resolved = resolve_bulks(service,
  25309. + queue);
  25310. + }
  25311. +
  25312. + mutex_unlock(&service->bulk_mutex);
  25313. + if (resolved)
  25314. + notify_bulks(service, queue,
  25315. + 1/*retry_poll*/);
  25316. + }
  25317. + } break;
  25318. + case VCHIQ_MSG_BULK_RX_DONE:
  25319. + case VCHIQ_MSG_BULK_TX_DONE:
  25320. + WARN_ON(state->is_master);
  25321. + if ((service->remoteport == remoteport)
  25322. + && (service->srvstate !=
  25323. + VCHIQ_SRVSTATE_FREE)) {
  25324. + VCHIQ_BULK_QUEUE_T *queue;
  25325. + VCHIQ_BULK_T *bulk;
  25326. +
  25327. + queue = (type == VCHIQ_MSG_BULK_RX_DONE) ?
  25328. + &service->bulk_rx : &service->bulk_tx;
  25329. +
  25330. + DEBUG_TRACE(PARSE_LINE);
  25331. + if (mutex_lock_interruptible(
  25332. + &service->bulk_mutex) != 0) {
  25333. + DEBUG_TRACE(PARSE_LINE);
  25334. + goto bail_not_ready;
  25335. + }
  25336. + if ((int)(queue->remote_insert -
  25337. + queue->local_insert) >= 0) {
  25338. + vchiq_log_error(vchiq_core_log_level,
  25339. + "%d: prs %s@%x (%d->%d) "
  25340. + "unexpected (ri=%d,li=%d)",
  25341. + state->id, msg_type_str(type),
  25342. + (unsigned int)header,
  25343. + remoteport, localport,
  25344. + queue->remote_insert,
  25345. + queue->local_insert);
  25346. + mutex_unlock(&service->bulk_mutex);
  25347. + break;
  25348. + }
  25349. +
  25350. + BUG_ON(queue->process == queue->local_insert);
  25351. + BUG_ON(queue->process != queue->remote_insert);
  25352. +
  25353. + bulk = &queue->bulks[
  25354. + BULK_INDEX(queue->remote_insert)];
  25355. + bulk->actual = *(int *)header->data;
  25356. + queue->remote_insert++;
  25357. +
  25358. + vchiq_log_info(vchiq_core_log_level,
  25359. + "%d: prs %s@%x (%d->%d) %x@%x",
  25360. + state->id, msg_type_str(type),
  25361. + (unsigned int)header,
  25362. + remoteport, localport,
  25363. + bulk->actual, (unsigned int)bulk->data);
  25364. +
  25365. + vchiq_log_trace(vchiq_core_log_level,
  25366. + "%d: prs:%d %cx li=%x ri=%x p=%x",
  25367. + state->id, localport,
  25368. + (type == VCHIQ_MSG_BULK_RX_DONE) ?
  25369. + 'r' : 't',
  25370. + queue->local_insert,
  25371. + queue->remote_insert, queue->process);
  25372. +
  25373. + DEBUG_TRACE(PARSE_LINE);
  25374. + WARN_ON(queue->process == queue->local_insert);
  25375. + vchiq_complete_bulk(bulk);
  25376. + queue->process++;
  25377. + mutex_unlock(&service->bulk_mutex);
  25378. + DEBUG_TRACE(PARSE_LINE);
  25379. + notify_bulks(service, queue, 1/*retry_poll*/);
  25380. + DEBUG_TRACE(PARSE_LINE);
  25381. + }
  25382. + break;
  25383. + case VCHIQ_MSG_PADDING:
  25384. + vchiq_log_trace(vchiq_core_log_level,
  25385. + "%d: prs PADDING@%x,%x",
  25386. + state->id, (unsigned int)header, size);
  25387. + break;
  25388. + case VCHIQ_MSG_PAUSE:
  25389. + /* If initiated, signal the application thread */
  25390. + vchiq_log_trace(vchiq_core_log_level,
  25391. + "%d: prs PAUSE@%x,%x",
  25392. + state->id, (unsigned int)header, size);
  25393. + if (state->conn_state == VCHIQ_CONNSTATE_PAUSED) {
  25394. + vchiq_log_error(vchiq_core_log_level,
  25395. + "%d: PAUSE received in state PAUSED",
  25396. + state->id);
  25397. + break;
  25398. + }
  25399. + if (state->conn_state != VCHIQ_CONNSTATE_PAUSE_SENT) {
  25400. + /* Send a PAUSE in response */
  25401. + if (queue_message(state, NULL,
  25402. + VCHIQ_MAKE_MSG(VCHIQ_MSG_PAUSE, 0, 0),
  25403. + NULL, 0, 0, 0) == VCHIQ_RETRY)
  25404. + goto bail_not_ready;
  25405. + if (state->is_master)
  25406. + pause_bulks(state);
  25407. + }
  25408. + /* At this point slot_mutex is held */
  25409. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_PAUSED);
  25410. + vchiq_platform_paused(state);
  25411. + break;
  25412. + case VCHIQ_MSG_RESUME:
  25413. + vchiq_log_trace(vchiq_core_log_level,
  25414. + "%d: prs RESUME@%x,%x",
  25415. + state->id, (unsigned int)header, size);
  25416. + /* Release the slot mutex */
  25417. + mutex_unlock(&state->slot_mutex);
  25418. + if (state->is_master)
  25419. + resume_bulks(state);
  25420. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTED);
  25421. + vchiq_platform_resumed(state);
  25422. + break;
  25423. +
  25424. + case VCHIQ_MSG_REMOTE_USE:
  25425. + vchiq_on_remote_use(state);
  25426. + break;
  25427. + case VCHIQ_MSG_REMOTE_RELEASE:
  25428. + vchiq_on_remote_release(state);
  25429. + break;
  25430. + case VCHIQ_MSG_REMOTE_USE_ACTIVE:
  25431. + vchiq_on_remote_use_active(state);
  25432. + break;
  25433. +
  25434. + default:
  25435. + vchiq_log_error(vchiq_core_log_level,
  25436. + "%d: prs invalid msgid %x@%x,%x",
  25437. + state->id, msgid, (unsigned int)header, size);
  25438. + WARN(1, "invalid message\n");
  25439. + break;
  25440. + }
  25441. +
  25442. +skip_message:
  25443. + if (service) {
  25444. + unlock_service(service);
  25445. + service = NULL;
  25446. + }
  25447. +
  25448. + state->rx_pos += calc_stride(size);
  25449. +
  25450. + DEBUG_TRACE(PARSE_LINE);
  25451. + /* Perform some housekeeping when the end of the slot is
  25452. + ** reached. */
  25453. + if ((state->rx_pos & VCHIQ_SLOT_MASK) == 0) {
  25454. + /* Remove the extra reference count. */
  25455. + release_slot(state, state->rx_info, NULL, NULL);
  25456. + state->rx_data = NULL;
  25457. + }
  25458. + }
  25459. +
  25460. +bail_not_ready:
  25461. + if (service)
  25462. + unlock_service(service);
  25463. +}
  25464. +
  25465. +/* Called by the slot handler thread */
  25466. +static int
  25467. +slot_handler_func(void *v)
  25468. +{
  25469. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  25470. + VCHIQ_SHARED_STATE_T *local = state->local;
  25471. + DEBUG_INITIALISE(local)
  25472. +
  25473. + while (1) {
  25474. + DEBUG_COUNT(SLOT_HANDLER_COUNT);
  25475. + DEBUG_TRACE(SLOT_HANDLER_LINE);
  25476. + remote_event_wait(&local->trigger);
  25477. +
  25478. + rmb();
  25479. +
  25480. + DEBUG_TRACE(SLOT_HANDLER_LINE);
  25481. + if (state->poll_needed) {
  25482. + /* Check if we need to suspend - may change our
  25483. + * conn_state */
  25484. + vchiq_platform_check_suspend(state);
  25485. +
  25486. + state->poll_needed = 0;
  25487. +
  25488. + /* Handle service polling and other rare conditions here
  25489. + ** out of the mainline code */
  25490. + switch (state->conn_state) {
  25491. + case VCHIQ_CONNSTATE_CONNECTED:
  25492. + /* Poll the services as requested */
  25493. + poll_services(state);
  25494. + break;
  25495. +
  25496. + case VCHIQ_CONNSTATE_PAUSING:
  25497. + if (state->is_master)
  25498. + pause_bulks(state);
  25499. + if (queue_message(state, NULL,
  25500. + VCHIQ_MAKE_MSG(VCHIQ_MSG_PAUSE, 0, 0),
  25501. + NULL, 0, 0, 0) != VCHIQ_RETRY) {
  25502. + vchiq_set_conn_state(state,
  25503. + VCHIQ_CONNSTATE_PAUSE_SENT);
  25504. + } else {
  25505. + if (state->is_master)
  25506. + resume_bulks(state);
  25507. + /* Retry later */
  25508. + state->poll_needed = 1;
  25509. + }
  25510. + break;
  25511. +
  25512. + case VCHIQ_CONNSTATE_PAUSED:
  25513. + vchiq_platform_resume(state);
  25514. + break;
  25515. +
  25516. + case VCHIQ_CONNSTATE_RESUMING:
  25517. + if (queue_message(state, NULL,
  25518. + VCHIQ_MAKE_MSG(VCHIQ_MSG_RESUME, 0, 0),
  25519. + NULL, 0, 0, 0) != VCHIQ_RETRY) {
  25520. + if (state->is_master)
  25521. + resume_bulks(state);
  25522. + vchiq_set_conn_state(state,
  25523. + VCHIQ_CONNSTATE_CONNECTED);
  25524. + vchiq_platform_resumed(state);
  25525. + } else {
  25526. + /* This should really be impossible,
  25527. + ** since the PAUSE should have flushed
  25528. + ** through outstanding messages. */
  25529. + vchiq_log_error(vchiq_core_log_level,
  25530. + "Failed to send RESUME "
  25531. + "message");
  25532. + BUG();
  25533. + }
  25534. + break;
  25535. +
  25536. + case VCHIQ_CONNSTATE_PAUSE_TIMEOUT:
  25537. + case VCHIQ_CONNSTATE_RESUME_TIMEOUT:
  25538. + vchiq_platform_handle_timeout(state);
  25539. + break;
  25540. + default:
  25541. + break;
  25542. + }
  25543. +
  25544. +
  25545. + }
  25546. +
  25547. + DEBUG_TRACE(SLOT_HANDLER_LINE);
  25548. + parse_rx_slots(state);
  25549. + }
  25550. + return 0;
  25551. +}
  25552. +
  25553. +
  25554. +/* Called by the recycle thread */
  25555. +static int
  25556. +recycle_func(void *v)
  25557. +{
  25558. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  25559. + VCHIQ_SHARED_STATE_T *local = state->local;
  25560. +
  25561. + while (1) {
  25562. + remote_event_wait(&local->recycle);
  25563. +
  25564. + process_free_queue(state);
  25565. + }
  25566. + return 0;
  25567. +}
  25568. +
  25569. +
  25570. +/* Called by the sync thread */
  25571. +static int
  25572. +sync_func(void *v)
  25573. +{
  25574. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  25575. + VCHIQ_SHARED_STATE_T *local = state->local;
  25576. + VCHIQ_HEADER_T *header = (VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state,
  25577. + state->remote->slot_sync);
  25578. +
  25579. + while (1) {
  25580. + VCHIQ_SERVICE_T *service;
  25581. + int msgid, size;
  25582. + int type;
  25583. + unsigned int localport, remoteport;
  25584. +
  25585. + remote_event_wait(&local->sync_trigger);
  25586. +
  25587. + rmb();
  25588. +
  25589. + msgid = header->msgid;
  25590. + size = header->size;
  25591. + type = VCHIQ_MSG_TYPE(msgid);
  25592. + localport = VCHIQ_MSG_DSTPORT(msgid);
  25593. + remoteport = VCHIQ_MSG_SRCPORT(msgid);
  25594. +
  25595. + service = find_service_by_port(state, localport);
  25596. +
  25597. + if (!service) {
  25598. + vchiq_log_error(vchiq_sync_log_level,
  25599. + "%d: sf %s@%x (%d->%d) - "
  25600. + "invalid/closed service %d",
  25601. + state->id, msg_type_str(type),
  25602. + (unsigned int)header,
  25603. + remoteport, localport, localport);
  25604. + release_message_sync(state, header);
  25605. + continue;
  25606. + }
  25607. +
  25608. + if (vchiq_sync_log_level >= VCHIQ_LOG_TRACE) {
  25609. + int svc_fourcc;
  25610. +
  25611. + svc_fourcc = service
  25612. + ? service->base.fourcc
  25613. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  25614. + vchiq_log_trace(vchiq_sync_log_level,
  25615. + "Rcvd Msg %s from %c%c%c%c s:%d d:%d len:%d",
  25616. + msg_type_str(type),
  25617. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  25618. + remoteport, localport, size);
  25619. + if (size > 0)
  25620. + vchiq_log_dump_mem("Rcvd", 0, header->data,
  25621. + min(64, size));
  25622. + }
  25623. +
  25624. + switch (type) {
  25625. + case VCHIQ_MSG_OPENACK:
  25626. + if (size >= sizeof(struct vchiq_openack_payload)) {
  25627. + const struct vchiq_openack_payload *payload =
  25628. + (struct vchiq_openack_payload *)
  25629. + header->data;
  25630. + service->peer_version = payload->version;
  25631. + }
  25632. + vchiq_log_info(vchiq_sync_log_level,
  25633. + "%d: sf OPENACK@%x,%x (%d->%d) v:%d",
  25634. + state->id, (unsigned int)header, size,
  25635. + remoteport, localport, service->peer_version);
  25636. + if (service->srvstate == VCHIQ_SRVSTATE_OPENING) {
  25637. + service->remoteport = remoteport;
  25638. + vchiq_set_service_state(service,
  25639. + VCHIQ_SRVSTATE_OPENSYNC);
  25640. + up(&service->remove_event);
  25641. + }
  25642. + release_message_sync(state, header);
  25643. + break;
  25644. +
  25645. + case VCHIQ_MSG_DATA:
  25646. + vchiq_log_trace(vchiq_sync_log_level,
  25647. + "%d: sf DATA@%x,%x (%d->%d)",
  25648. + state->id, (unsigned int)header, size,
  25649. + remoteport, localport);
  25650. +
  25651. + if ((service->remoteport == remoteport) &&
  25652. + (service->srvstate ==
  25653. + VCHIQ_SRVSTATE_OPENSYNC)) {
  25654. + if (make_service_callback(service,
  25655. + VCHIQ_MESSAGE_AVAILABLE, header,
  25656. + NULL) == VCHIQ_RETRY)
  25657. + vchiq_log_error(vchiq_sync_log_level,
  25658. + "synchronous callback to "
  25659. + "service %d returns "
  25660. + "VCHIQ_RETRY",
  25661. + localport);
  25662. + }
  25663. + break;
  25664. +
  25665. + default:
  25666. + vchiq_log_error(vchiq_sync_log_level,
  25667. + "%d: sf unexpected msgid %x@%x,%x",
  25668. + state->id, msgid, (unsigned int)header, size);
  25669. + release_message_sync(state, header);
  25670. + break;
  25671. + }
  25672. +
  25673. + unlock_service(service);
  25674. + }
  25675. +
  25676. + return 0;
  25677. +}
  25678. +
  25679. +
  25680. +static void
  25681. +init_bulk_queue(VCHIQ_BULK_QUEUE_T *queue)
  25682. +{
  25683. + queue->local_insert = 0;
  25684. + queue->remote_insert = 0;
  25685. + queue->process = 0;
  25686. + queue->remote_notify = 0;
  25687. + queue->remove = 0;
  25688. +}
  25689. +
  25690. +
  25691. +inline const char *
  25692. +get_conn_state_name(VCHIQ_CONNSTATE_T conn_state)
  25693. +{
  25694. + return conn_state_names[conn_state];
  25695. +}
  25696. +
  25697. +
  25698. +VCHIQ_SLOT_ZERO_T *
  25699. +vchiq_init_slots(void *mem_base, int mem_size)
  25700. +{
  25701. + int mem_align = (VCHIQ_SLOT_SIZE - (int)mem_base) & VCHIQ_SLOT_MASK;
  25702. + VCHIQ_SLOT_ZERO_T *slot_zero =
  25703. + (VCHIQ_SLOT_ZERO_T *)((char *)mem_base + mem_align);
  25704. + int num_slots = (mem_size - mem_align)/VCHIQ_SLOT_SIZE;
  25705. + int first_data_slot = VCHIQ_SLOT_ZERO_SLOTS;
  25706. +
  25707. + /* Ensure there is enough memory to run an absolutely minimum system */
  25708. + num_slots -= first_data_slot;
  25709. +
  25710. + if (num_slots < 4) {
  25711. + vchiq_log_error(vchiq_core_log_level,
  25712. + "vchiq_init_slots - insufficient memory %x bytes",
  25713. + mem_size);
  25714. + return NULL;
  25715. + }
  25716. +
  25717. + memset(slot_zero, 0, sizeof(VCHIQ_SLOT_ZERO_T));
  25718. +
  25719. + slot_zero->magic = VCHIQ_MAGIC;
  25720. + slot_zero->version = VCHIQ_VERSION;
  25721. + slot_zero->version_min = VCHIQ_VERSION_MIN;
  25722. + slot_zero->slot_zero_size = sizeof(VCHIQ_SLOT_ZERO_T);
  25723. + slot_zero->slot_size = VCHIQ_SLOT_SIZE;
  25724. + slot_zero->max_slots = VCHIQ_MAX_SLOTS;
  25725. + slot_zero->max_slots_per_side = VCHIQ_MAX_SLOTS_PER_SIDE;
  25726. +
  25727. + slot_zero->master.slot_sync = first_data_slot;
  25728. + slot_zero->master.slot_first = first_data_slot + 1;
  25729. + slot_zero->master.slot_last = first_data_slot + (num_slots/2) - 1;
  25730. + slot_zero->slave.slot_sync = first_data_slot + (num_slots/2);
  25731. + slot_zero->slave.slot_first = first_data_slot + (num_slots/2) + 1;
  25732. + slot_zero->slave.slot_last = first_data_slot + num_slots - 1;
  25733. +
  25734. + return slot_zero;
  25735. +}
  25736. +
  25737. +VCHIQ_STATUS_T
  25738. +vchiq_init_state(VCHIQ_STATE_T *state, VCHIQ_SLOT_ZERO_T *slot_zero,
  25739. + int is_master)
  25740. +{
  25741. + VCHIQ_SHARED_STATE_T *local;
  25742. + VCHIQ_SHARED_STATE_T *remote;
  25743. + VCHIQ_STATUS_T status;
  25744. + char threadname[10];
  25745. + static int id;
  25746. + int i;
  25747. +
  25748. + vchiq_log_warning(vchiq_core_log_level,
  25749. + "%s: slot_zero = 0x%08lx, is_master = %d",
  25750. + __func__, (unsigned long)slot_zero, is_master);
  25751. +
  25752. + /* Check the input configuration */
  25753. +
  25754. + if (slot_zero->magic != VCHIQ_MAGIC) {
  25755. + vchiq_loud_error_header();
  25756. + vchiq_loud_error("Invalid VCHIQ magic value found.");
  25757. + vchiq_loud_error("slot_zero=%x: magic=%x (expected %x)",
  25758. + (unsigned int)slot_zero, slot_zero->magic, VCHIQ_MAGIC);
  25759. + vchiq_loud_error_footer();
  25760. + return VCHIQ_ERROR;
  25761. + }
  25762. +
  25763. + if (slot_zero->version < VCHIQ_VERSION_MIN) {
  25764. + vchiq_loud_error_header();
  25765. + vchiq_loud_error("Incompatible VCHIQ versions found.");
  25766. + vchiq_loud_error("slot_zero=%x: VideoCore version=%d "
  25767. + "(minimum %d)",
  25768. + (unsigned int)slot_zero, slot_zero->version,
  25769. + VCHIQ_VERSION_MIN);
  25770. + vchiq_loud_error("Restart with a newer VideoCore image.");
  25771. + vchiq_loud_error_footer();
  25772. + return VCHIQ_ERROR;
  25773. + }
  25774. +
  25775. + if (VCHIQ_VERSION < slot_zero->version_min) {
  25776. + vchiq_loud_error_header();
  25777. + vchiq_loud_error("Incompatible VCHIQ versions found.");
  25778. + vchiq_loud_error("slot_zero=%x: version=%d (VideoCore "
  25779. + "minimum %d)",
  25780. + (unsigned int)slot_zero, VCHIQ_VERSION,
  25781. + slot_zero->version_min);
  25782. + vchiq_loud_error("Restart with a newer kernel.");
  25783. + vchiq_loud_error_footer();
  25784. + return VCHIQ_ERROR;
  25785. + }
  25786. +
  25787. + if ((slot_zero->slot_zero_size != sizeof(VCHIQ_SLOT_ZERO_T)) ||
  25788. + (slot_zero->slot_size != VCHIQ_SLOT_SIZE) ||
  25789. + (slot_zero->max_slots != VCHIQ_MAX_SLOTS) ||
  25790. + (slot_zero->max_slots_per_side != VCHIQ_MAX_SLOTS_PER_SIDE)) {
  25791. + vchiq_loud_error_header();
  25792. + if (slot_zero->slot_zero_size != sizeof(VCHIQ_SLOT_ZERO_T))
  25793. + vchiq_loud_error("slot_zero=%x: slot_zero_size=%x "
  25794. + "(expected %x)",
  25795. + (unsigned int)slot_zero,
  25796. + slot_zero->slot_zero_size,
  25797. + sizeof(VCHIQ_SLOT_ZERO_T));
  25798. + if (slot_zero->slot_size != VCHIQ_SLOT_SIZE)
  25799. + vchiq_loud_error("slot_zero=%x: slot_size=%d "
  25800. + "(expected %d",
  25801. + (unsigned int)slot_zero, slot_zero->slot_size,
  25802. + VCHIQ_SLOT_SIZE);
  25803. + if (slot_zero->max_slots != VCHIQ_MAX_SLOTS)
  25804. + vchiq_loud_error("slot_zero=%x: max_slots=%d "
  25805. + "(expected %d)",
  25806. + (unsigned int)slot_zero, slot_zero->max_slots,
  25807. + VCHIQ_MAX_SLOTS);
  25808. + if (slot_zero->max_slots_per_side != VCHIQ_MAX_SLOTS_PER_SIDE)
  25809. + vchiq_loud_error("slot_zero=%x: max_slots_per_side=%d "
  25810. + "(expected %d)",
  25811. + (unsigned int)slot_zero,
  25812. + slot_zero->max_slots_per_side,
  25813. + VCHIQ_MAX_SLOTS_PER_SIDE);
  25814. + vchiq_loud_error_footer();
  25815. + return VCHIQ_ERROR;
  25816. + }
  25817. +
  25818. + if (is_master) {
  25819. + local = &slot_zero->master;
  25820. + remote = &slot_zero->slave;
  25821. + } else {
  25822. + local = &slot_zero->slave;
  25823. + remote = &slot_zero->master;
  25824. + }
  25825. +
  25826. + if (local->initialised) {
  25827. + vchiq_loud_error_header();
  25828. + if (remote->initialised)
  25829. + vchiq_loud_error("local state has already been "
  25830. + "initialised");
  25831. + else
  25832. + vchiq_loud_error("master/slave mismatch - two %ss",
  25833. + is_master ? "master" : "slave");
  25834. + vchiq_loud_error_footer();
  25835. + return VCHIQ_ERROR;
  25836. + }
  25837. +
  25838. + memset(state, 0, sizeof(VCHIQ_STATE_T));
  25839. +
  25840. + state->id = id++;
  25841. + state->is_master = is_master;
  25842. +
  25843. + /*
  25844. + initialize shared state pointers
  25845. + */
  25846. +
  25847. + state->local = local;
  25848. + state->remote = remote;
  25849. + state->slot_data = (VCHIQ_SLOT_T *)slot_zero;
  25850. +
  25851. + /*
  25852. + initialize events and mutexes
  25853. + */
  25854. +
  25855. + sema_init(&state->connect, 0);
  25856. + mutex_init(&state->mutex);
  25857. + sema_init(&state->trigger_event, 0);
  25858. + sema_init(&state->recycle_event, 0);
  25859. + sema_init(&state->sync_trigger_event, 0);
  25860. + sema_init(&state->sync_release_event, 0);
  25861. +
  25862. + mutex_init(&state->slot_mutex);
  25863. + mutex_init(&state->recycle_mutex);
  25864. + mutex_init(&state->sync_mutex);
  25865. + mutex_init(&state->bulk_transfer_mutex);
  25866. +
  25867. + sema_init(&state->slot_available_event, 0);
  25868. + sema_init(&state->slot_remove_event, 0);
  25869. + sema_init(&state->data_quota_event, 0);
  25870. +
  25871. + state->slot_queue_available = 0;
  25872. +
  25873. + for (i = 0; i < VCHIQ_MAX_SERVICES; i++) {
  25874. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  25875. + &state->service_quotas[i];
  25876. + sema_init(&service_quota->quota_event, 0);
  25877. + }
  25878. +
  25879. + for (i = local->slot_first; i <= local->slot_last; i++) {
  25880. + local->slot_queue[state->slot_queue_available++] = i;
  25881. + up(&state->slot_available_event);
  25882. + }
  25883. +
  25884. + state->default_slot_quota = state->slot_queue_available/2;
  25885. + state->default_message_quota =
  25886. + min((unsigned short)(state->default_slot_quota * 256),
  25887. + (unsigned short)~0);
  25888. +
  25889. + state->previous_data_index = -1;
  25890. + state->data_use_count = 0;
  25891. + state->data_quota = state->slot_queue_available - 1;
  25892. +
  25893. + local->trigger.event = &state->trigger_event;
  25894. + remote_event_create(&local->trigger);
  25895. + local->tx_pos = 0;
  25896. +
  25897. + local->recycle.event = &state->recycle_event;
  25898. + remote_event_create(&local->recycle);
  25899. + local->slot_queue_recycle = state->slot_queue_available;
  25900. +
  25901. + local->sync_trigger.event = &state->sync_trigger_event;
  25902. + remote_event_create(&local->sync_trigger);
  25903. +
  25904. + local->sync_release.event = &state->sync_release_event;
  25905. + remote_event_create(&local->sync_release);
  25906. +
  25907. + /* At start-of-day, the slot is empty and available */
  25908. + ((VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state, local->slot_sync))->msgid
  25909. + = VCHIQ_MSGID_PADDING;
  25910. + remote_event_signal_local(&local->sync_release);
  25911. +
  25912. + local->debug[DEBUG_ENTRIES] = DEBUG_MAX;
  25913. +
  25914. + status = vchiq_platform_init_state(state);
  25915. +
  25916. + /*
  25917. + bring up slot handler thread
  25918. + */
  25919. + snprintf(threadname, sizeof(threadname), "VCHIQ-%d", state->id);
  25920. + state->slot_handler_thread = kthread_create(&slot_handler_func,
  25921. + (void *)state,
  25922. + threadname);
  25923. +
  25924. + if (state->slot_handler_thread == NULL) {
  25925. + vchiq_loud_error_header();
  25926. + vchiq_loud_error("couldn't create thread %s", threadname);
  25927. + vchiq_loud_error_footer();
  25928. + return VCHIQ_ERROR;
  25929. + }
  25930. + set_user_nice(state->slot_handler_thread, -19);
  25931. + wake_up_process(state->slot_handler_thread);
  25932. +
  25933. + snprintf(threadname, sizeof(threadname), "VCHIQr-%d", state->id);
  25934. + state->recycle_thread = kthread_create(&recycle_func,
  25935. + (void *)state,
  25936. + threadname);
  25937. + if (state->recycle_thread == NULL) {
  25938. + vchiq_loud_error_header();
  25939. + vchiq_loud_error("couldn't create thread %s", threadname);
  25940. + vchiq_loud_error_footer();
  25941. + return VCHIQ_ERROR;
  25942. + }
  25943. + set_user_nice(state->recycle_thread, -19);
  25944. + wake_up_process(state->recycle_thread);
  25945. +
  25946. + snprintf(threadname, sizeof(threadname), "VCHIQs-%d", state->id);
  25947. + state->sync_thread = kthread_create(&sync_func,
  25948. + (void *)state,
  25949. + threadname);
  25950. + if (state->sync_thread == NULL) {
  25951. + vchiq_loud_error_header();
  25952. + vchiq_loud_error("couldn't create thread %s", threadname);
  25953. + vchiq_loud_error_footer();
  25954. + return VCHIQ_ERROR;
  25955. + }
  25956. + set_user_nice(state->sync_thread, -20);
  25957. + wake_up_process(state->sync_thread);
  25958. +
  25959. + BUG_ON(state->id >= VCHIQ_MAX_STATES);
  25960. + vchiq_states[state->id] = state;
  25961. +
  25962. + /* Indicate readiness to the other side */
  25963. + local->initialised = 1;
  25964. +
  25965. + return status;
  25966. +}
  25967. +
  25968. +/* Called from application thread when a client or server service is created. */
  25969. +VCHIQ_SERVICE_T *
  25970. +vchiq_add_service_internal(VCHIQ_STATE_T *state,
  25971. + const VCHIQ_SERVICE_PARAMS_T *params, int srvstate,
  25972. + VCHIQ_INSTANCE_T instance, VCHIQ_USERDATA_TERM_T userdata_term)
  25973. +{
  25974. + VCHIQ_SERVICE_T *service;
  25975. +
  25976. + service = kmalloc(sizeof(VCHIQ_SERVICE_T), GFP_KERNEL);
  25977. + if (service) {
  25978. + service->base.fourcc = params->fourcc;
  25979. + service->base.callback = params->callback;
  25980. + service->base.userdata = params->userdata;
  25981. + service->handle = VCHIQ_SERVICE_HANDLE_INVALID;
  25982. + service->ref_count = 1;
  25983. + service->srvstate = VCHIQ_SRVSTATE_FREE;
  25984. + service->userdata_term = userdata_term;
  25985. + service->localport = VCHIQ_PORT_FREE;
  25986. + service->remoteport = VCHIQ_PORT_FREE;
  25987. +
  25988. + service->public_fourcc = (srvstate == VCHIQ_SRVSTATE_OPENING) ?
  25989. + VCHIQ_FOURCC_INVALID : params->fourcc;
  25990. + service->client_id = 0;
  25991. + service->auto_close = 1;
  25992. + service->sync = 0;
  25993. + service->closing = 0;
  25994. + atomic_set(&service->poll_flags, 0);
  25995. + service->version = params->version;
  25996. + service->version_min = params->version_min;
  25997. + service->state = state;
  25998. + service->instance = instance;
  25999. + service->service_use_count = 0;
  26000. + init_bulk_queue(&service->bulk_tx);
  26001. + init_bulk_queue(&service->bulk_rx);
  26002. + sema_init(&service->remove_event, 0);
  26003. + sema_init(&service->bulk_remove_event, 0);
  26004. + mutex_init(&service->bulk_mutex);
  26005. + memset(&service->stats, 0, sizeof(service->stats));
  26006. + } else {
  26007. + vchiq_log_error(vchiq_core_log_level,
  26008. + "Out of memory");
  26009. + }
  26010. +
  26011. + if (service) {
  26012. + VCHIQ_SERVICE_T **pservice = NULL;
  26013. + int i;
  26014. +
  26015. + /* Although it is perfectly possible to use service_spinlock
  26016. + ** to protect the creation of services, it is overkill as it
  26017. + ** disables interrupts while the array is searched.
  26018. + ** The only danger is of another thread trying to create a
  26019. + ** service - service deletion is safe.
  26020. + ** Therefore it is preferable to use state->mutex which,
  26021. + ** although slower to claim, doesn't block interrupts while
  26022. + ** it is held.
  26023. + */
  26024. +
  26025. + mutex_lock(&state->mutex);
  26026. +
  26027. + /* Prepare to use a previously unused service */
  26028. + if (state->unused_service < VCHIQ_MAX_SERVICES)
  26029. + pservice = &state->services[state->unused_service];
  26030. +
  26031. + if (srvstate == VCHIQ_SRVSTATE_OPENING) {
  26032. + for (i = 0; i < state->unused_service; i++) {
  26033. + VCHIQ_SERVICE_T *srv = state->services[i];
  26034. + if (!srv) {
  26035. + pservice = &state->services[i];
  26036. + break;
  26037. + }
  26038. + }
  26039. + } else {
  26040. + for (i = (state->unused_service - 1); i >= 0; i--) {
  26041. + VCHIQ_SERVICE_T *srv = state->services[i];
  26042. + if (!srv)
  26043. + pservice = &state->services[i];
  26044. + else if ((srv->public_fourcc == params->fourcc)
  26045. + && ((srv->instance != instance) ||
  26046. + (srv->base.callback !=
  26047. + params->callback))) {
  26048. + /* There is another server using this
  26049. + ** fourcc which doesn't match. */
  26050. + pservice = NULL;
  26051. + break;
  26052. + }
  26053. + }
  26054. + }
  26055. +
  26056. + if (pservice) {
  26057. + service->localport = (pservice - state->services);
  26058. + if (!handle_seq)
  26059. + handle_seq = VCHIQ_MAX_STATES *
  26060. + VCHIQ_MAX_SERVICES;
  26061. + service->handle = handle_seq |
  26062. + (state->id * VCHIQ_MAX_SERVICES) |
  26063. + service->localport;
  26064. + handle_seq += VCHIQ_MAX_STATES * VCHIQ_MAX_SERVICES;
  26065. + *pservice = service;
  26066. + if (pservice == &state->services[state->unused_service])
  26067. + state->unused_service++;
  26068. + }
  26069. +
  26070. + mutex_unlock(&state->mutex);
  26071. +
  26072. + if (!pservice) {
  26073. + kfree(service);
  26074. + service = NULL;
  26075. + }
  26076. + }
  26077. +
  26078. + if (service) {
  26079. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  26080. + &state->service_quotas[service->localport];
  26081. + service_quota->slot_quota = state->default_slot_quota;
  26082. + service_quota->message_quota = state->default_message_quota;
  26083. + if (service_quota->slot_use_count == 0)
  26084. + service_quota->previous_tx_index =
  26085. + SLOT_QUEUE_INDEX_FROM_POS(state->local_tx_pos)
  26086. + - 1;
  26087. +
  26088. + /* Bring this service online */
  26089. + vchiq_set_service_state(service, srvstate);
  26090. +
  26091. + vchiq_log_info(vchiq_core_msg_log_level,
  26092. + "%s Service %c%c%c%c SrcPort:%d",
  26093. + (srvstate == VCHIQ_SRVSTATE_OPENING)
  26094. + ? "Open" : "Add",
  26095. + VCHIQ_FOURCC_AS_4CHARS(params->fourcc),
  26096. + service->localport);
  26097. + }
  26098. +
  26099. + /* Don't unlock the service - leave it with a ref_count of 1. */
  26100. +
  26101. + return service;
  26102. +}
  26103. +
  26104. +VCHIQ_STATUS_T
  26105. +vchiq_open_service_internal(VCHIQ_SERVICE_T *service, int client_id)
  26106. +{
  26107. + struct vchiq_open_payload payload = {
  26108. + service->base.fourcc,
  26109. + client_id,
  26110. + service->version,
  26111. + service->version_min
  26112. + };
  26113. + VCHIQ_ELEMENT_T body = { &payload, sizeof(payload) };
  26114. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  26115. +
  26116. + service->client_id = client_id;
  26117. + vchiq_use_service_internal(service);
  26118. + status = queue_message(service->state, NULL,
  26119. + VCHIQ_MAKE_MSG(VCHIQ_MSG_OPEN, service->localport, 0),
  26120. + &body, 1, sizeof(payload), 1);
  26121. + if (status == VCHIQ_SUCCESS) {
  26122. + if (down_interruptible(&service->remove_event) != 0) {
  26123. + status = VCHIQ_RETRY;
  26124. + vchiq_release_service_internal(service);
  26125. + } else if ((service->srvstate != VCHIQ_SRVSTATE_OPEN) &&
  26126. + (service->srvstate != VCHIQ_SRVSTATE_OPENSYNC)) {
  26127. + if (service->srvstate != VCHIQ_SRVSTATE_CLOSEWAIT)
  26128. + vchiq_log_error(vchiq_core_log_level,
  26129. + "%d: osi - srvstate = %s (ref %d)",
  26130. + service->state->id,
  26131. + srvstate_names[service->srvstate],
  26132. + service->ref_count);
  26133. + status = VCHIQ_ERROR;
  26134. + VCHIQ_SERVICE_STATS_INC(service, error_count);
  26135. + vchiq_release_service_internal(service);
  26136. + }
  26137. + }
  26138. + return status;
  26139. +}
  26140. +
  26141. +static void
  26142. +release_service_messages(VCHIQ_SERVICE_T *service)
  26143. +{
  26144. + VCHIQ_STATE_T *state = service->state;
  26145. + int slot_last = state->remote->slot_last;
  26146. + int i;
  26147. +
  26148. + /* Release any claimed messages */
  26149. + for (i = state->remote->slot_first; i <= slot_last; i++) {
  26150. + VCHIQ_SLOT_INFO_T *slot_info =
  26151. + SLOT_INFO_FROM_INDEX(state, i);
  26152. + if (slot_info->release_count != slot_info->use_count) {
  26153. + char *data =
  26154. + (char *)SLOT_DATA_FROM_INDEX(state, i);
  26155. + unsigned int pos, end;
  26156. +
  26157. + end = VCHIQ_SLOT_SIZE;
  26158. + if (data == state->rx_data)
  26159. + /* This buffer is still being read from - stop
  26160. + ** at the current read position */
  26161. + end = state->rx_pos & VCHIQ_SLOT_MASK;
  26162. +
  26163. + pos = 0;
  26164. +
  26165. + while (pos < end) {
  26166. + VCHIQ_HEADER_T *header =
  26167. + (VCHIQ_HEADER_T *)(data + pos);
  26168. + int msgid = header->msgid;
  26169. + int port = VCHIQ_MSG_DSTPORT(msgid);
  26170. + if ((port == service->localport) &&
  26171. + (msgid & VCHIQ_MSGID_CLAIMED)) {
  26172. + vchiq_log_info(vchiq_core_log_level,
  26173. + " fsi - hdr %x",
  26174. + (unsigned int)header);
  26175. + release_slot(state, slot_info, header,
  26176. + NULL);
  26177. + }
  26178. + pos += calc_stride(header->size);
  26179. + if (pos > VCHIQ_SLOT_SIZE) {
  26180. + vchiq_log_error(vchiq_core_log_level,
  26181. + "fsi - pos %x: header %x, "
  26182. + "msgid %x, header->msgid %x, "
  26183. + "header->size %x",
  26184. + pos, (unsigned int)header,
  26185. + msgid, header->msgid,
  26186. + header->size);
  26187. + WARN(1, "invalid slot position\n");
  26188. + }
  26189. + }
  26190. + }
  26191. + }
  26192. +}
  26193. +
  26194. +static int
  26195. +do_abort_bulks(VCHIQ_SERVICE_T *service)
  26196. +{
  26197. + VCHIQ_STATUS_T status;
  26198. +
  26199. + /* Abort any outstanding bulk transfers */
  26200. + if (mutex_lock_interruptible(&service->bulk_mutex) != 0)
  26201. + return 0;
  26202. + abort_outstanding_bulks(service, &service->bulk_tx);
  26203. + abort_outstanding_bulks(service, &service->bulk_rx);
  26204. + mutex_unlock(&service->bulk_mutex);
  26205. +
  26206. + status = notify_bulks(service, &service->bulk_tx, 0/*!retry_poll*/);
  26207. + if (status == VCHIQ_SUCCESS)
  26208. + status = notify_bulks(service, &service->bulk_rx,
  26209. + 0/*!retry_poll*/);
  26210. + return (status == VCHIQ_SUCCESS);
  26211. +}
  26212. +
  26213. +static VCHIQ_STATUS_T
  26214. +close_service_complete(VCHIQ_SERVICE_T *service, int failstate)
  26215. +{
  26216. + VCHIQ_STATUS_T status;
  26217. + int is_server = (service->public_fourcc != VCHIQ_FOURCC_INVALID);
  26218. + int newstate;
  26219. +
  26220. + switch (service->srvstate) {
  26221. + case VCHIQ_SRVSTATE_OPEN:
  26222. + case VCHIQ_SRVSTATE_CLOSESENT:
  26223. + case VCHIQ_SRVSTATE_CLOSERECVD:
  26224. + if (is_server) {
  26225. + if (service->auto_close) {
  26226. + service->client_id = 0;
  26227. + service->remoteport = VCHIQ_PORT_FREE;
  26228. + newstate = VCHIQ_SRVSTATE_LISTENING;
  26229. + } else
  26230. + newstate = VCHIQ_SRVSTATE_CLOSEWAIT;
  26231. + } else
  26232. + newstate = VCHIQ_SRVSTATE_CLOSED;
  26233. + vchiq_set_service_state(service, newstate);
  26234. + break;
  26235. + case VCHIQ_SRVSTATE_LISTENING:
  26236. + break;
  26237. + default:
  26238. + vchiq_log_error(vchiq_core_log_level,
  26239. + "close_service_complete(%x) called in state %s",
  26240. + service->handle, srvstate_names[service->srvstate]);
  26241. + WARN(1, "close_service_complete in unexpected state\n");
  26242. + return VCHIQ_ERROR;
  26243. + }
  26244. +
  26245. + status = make_service_callback(service,
  26246. + VCHIQ_SERVICE_CLOSED, NULL, NULL);
  26247. +
  26248. + if (status != VCHIQ_RETRY) {
  26249. + int uc = service->service_use_count;
  26250. + int i;
  26251. + /* Complete the close process */
  26252. + for (i = 0; i < uc; i++)
  26253. + /* cater for cases where close is forced and the
  26254. + ** client may not close all it's handles */
  26255. + vchiq_release_service_internal(service);
  26256. +
  26257. + service->client_id = 0;
  26258. + service->remoteport = VCHIQ_PORT_FREE;
  26259. +
  26260. + if (service->srvstate == VCHIQ_SRVSTATE_CLOSED)
  26261. + vchiq_free_service_internal(service);
  26262. + else if (service->srvstate != VCHIQ_SRVSTATE_CLOSEWAIT) {
  26263. + if (is_server)
  26264. + service->closing = 0;
  26265. +
  26266. + up(&service->remove_event);
  26267. + }
  26268. + } else
  26269. + vchiq_set_service_state(service, failstate);
  26270. +
  26271. + return status;
  26272. +}
  26273. +
  26274. +/* Called by the slot handler */
  26275. +VCHIQ_STATUS_T
  26276. +vchiq_close_service_internal(VCHIQ_SERVICE_T *service, int close_recvd)
  26277. +{
  26278. + VCHIQ_STATE_T *state = service->state;
  26279. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  26280. + int is_server = (service->public_fourcc != VCHIQ_FOURCC_INVALID);
  26281. +
  26282. + vchiq_log_info(vchiq_core_log_level, "%d: csi:%d,%d (%s)",
  26283. + service->state->id, service->localport, close_recvd,
  26284. + srvstate_names[service->srvstate]);
  26285. +
  26286. + switch (service->srvstate) {
  26287. + case VCHIQ_SRVSTATE_CLOSED:
  26288. + case VCHIQ_SRVSTATE_HIDDEN:
  26289. + case VCHIQ_SRVSTATE_LISTENING:
  26290. + case VCHIQ_SRVSTATE_CLOSEWAIT:
  26291. + if (close_recvd)
  26292. + vchiq_log_error(vchiq_core_log_level,
  26293. + "vchiq_close_service_internal(1) called "
  26294. + "in state %s",
  26295. + srvstate_names[service->srvstate]);
  26296. + else if (is_server) {
  26297. + if (service->srvstate == VCHIQ_SRVSTATE_LISTENING) {
  26298. + status = VCHIQ_ERROR;
  26299. + } else {
  26300. + service->client_id = 0;
  26301. + service->remoteport = VCHIQ_PORT_FREE;
  26302. + if (service->srvstate ==
  26303. + VCHIQ_SRVSTATE_CLOSEWAIT)
  26304. + vchiq_set_service_state(service,
  26305. + VCHIQ_SRVSTATE_LISTENING);
  26306. + }
  26307. + up(&service->remove_event);
  26308. + } else
  26309. + vchiq_free_service_internal(service);
  26310. + break;
  26311. + case VCHIQ_SRVSTATE_OPENING:
  26312. + if (close_recvd) {
  26313. + /* The open was rejected - tell the user */
  26314. + vchiq_set_service_state(service,
  26315. + VCHIQ_SRVSTATE_CLOSEWAIT);
  26316. + up(&service->remove_event);
  26317. + } else {
  26318. + /* Shutdown mid-open - let the other side know */
  26319. + status = queue_message(state, service,
  26320. + VCHIQ_MAKE_MSG
  26321. + (VCHIQ_MSG_CLOSE,
  26322. + service->localport,
  26323. + VCHIQ_MSG_DSTPORT(service->remoteport)),
  26324. + NULL, 0, 0, 0);
  26325. + }
  26326. + break;
  26327. +
  26328. + case VCHIQ_SRVSTATE_OPENSYNC:
  26329. + mutex_lock(&state->sync_mutex);
  26330. + /* Drop through */
  26331. +
  26332. + case VCHIQ_SRVSTATE_OPEN:
  26333. + if (state->is_master || close_recvd) {
  26334. + if (!do_abort_bulks(service))
  26335. + status = VCHIQ_RETRY;
  26336. + }
  26337. +
  26338. + release_service_messages(service);
  26339. +
  26340. + if (status == VCHIQ_SUCCESS)
  26341. + status = queue_message(state, service,
  26342. + VCHIQ_MAKE_MSG
  26343. + (VCHIQ_MSG_CLOSE,
  26344. + service->localport,
  26345. + VCHIQ_MSG_DSTPORT(service->remoteport)),
  26346. + NULL, 0, 0, 0);
  26347. +
  26348. + if (status == VCHIQ_SUCCESS) {
  26349. + if (!close_recvd)
  26350. + break;
  26351. + } else if (service->srvstate == VCHIQ_SRVSTATE_OPENSYNC) {
  26352. + mutex_unlock(&state->sync_mutex);
  26353. + break;
  26354. + } else
  26355. + break;
  26356. +
  26357. + status = close_service_complete(service,
  26358. + VCHIQ_SRVSTATE_CLOSERECVD);
  26359. + break;
  26360. +
  26361. + case VCHIQ_SRVSTATE_CLOSESENT:
  26362. + if (!close_recvd)
  26363. + /* This happens when a process is killed mid-close */
  26364. + break;
  26365. +
  26366. + if (!state->is_master) {
  26367. + if (!do_abort_bulks(service)) {
  26368. + status = VCHIQ_RETRY;
  26369. + break;
  26370. + }
  26371. + }
  26372. +
  26373. + if (status == VCHIQ_SUCCESS)
  26374. + status = close_service_complete(service,
  26375. + VCHIQ_SRVSTATE_CLOSERECVD);
  26376. + break;
  26377. +
  26378. + case VCHIQ_SRVSTATE_CLOSERECVD:
  26379. + if (!close_recvd && is_server)
  26380. + /* Force into LISTENING mode */
  26381. + vchiq_set_service_state(service,
  26382. + VCHIQ_SRVSTATE_LISTENING);
  26383. + status = close_service_complete(service,
  26384. + VCHIQ_SRVSTATE_CLOSERECVD);
  26385. + break;
  26386. +
  26387. + default:
  26388. + vchiq_log_error(vchiq_core_log_level,
  26389. + "vchiq_close_service_internal(%d) called in state %s",
  26390. + close_recvd, srvstate_names[service->srvstate]);
  26391. + break;
  26392. + }
  26393. +
  26394. + return status;
  26395. +}
  26396. +
  26397. +/* Called from the application process upon process death */
  26398. +void
  26399. +vchiq_terminate_service_internal(VCHIQ_SERVICE_T *service)
  26400. +{
  26401. + VCHIQ_STATE_T *state = service->state;
  26402. +
  26403. + vchiq_log_info(vchiq_core_log_level, "%d: tsi - (%d<->%d)",
  26404. + state->id, service->localport, service->remoteport);
  26405. +
  26406. + mark_service_closing(service);
  26407. +
  26408. + /* Mark the service for removal by the slot handler */
  26409. + request_poll(state, service, VCHIQ_POLL_REMOVE);
  26410. +}
  26411. +
  26412. +/* Called from the slot handler */
  26413. +void
  26414. +vchiq_free_service_internal(VCHIQ_SERVICE_T *service)
  26415. +{
  26416. + VCHIQ_STATE_T *state = service->state;
  26417. +
  26418. + vchiq_log_info(vchiq_core_log_level, "%d: fsi - (%d)",
  26419. + state->id, service->localport);
  26420. +
  26421. + switch (service->srvstate) {
  26422. + case VCHIQ_SRVSTATE_OPENING:
  26423. + case VCHIQ_SRVSTATE_CLOSED:
  26424. + case VCHIQ_SRVSTATE_HIDDEN:
  26425. + case VCHIQ_SRVSTATE_LISTENING:
  26426. + case VCHIQ_SRVSTATE_CLOSEWAIT:
  26427. + break;
  26428. + default:
  26429. + vchiq_log_error(vchiq_core_log_level,
  26430. + "%d: fsi - (%d) in state %s",
  26431. + state->id, service->localport,
  26432. + srvstate_names[service->srvstate]);
  26433. + return;
  26434. + }
  26435. +
  26436. + vchiq_set_service_state(service, VCHIQ_SRVSTATE_FREE);
  26437. +
  26438. + up(&service->remove_event);
  26439. +
  26440. + /* Release the initial lock */
  26441. + unlock_service(service);
  26442. +}
  26443. +
  26444. +VCHIQ_STATUS_T
  26445. +vchiq_connect_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance)
  26446. +{
  26447. + VCHIQ_SERVICE_T *service;
  26448. + int i;
  26449. +
  26450. + /* Find all services registered to this client and enable them. */
  26451. + i = 0;
  26452. + while ((service = next_service_by_instance(state, instance,
  26453. + &i)) != NULL) {
  26454. + if (service->srvstate == VCHIQ_SRVSTATE_HIDDEN)
  26455. + vchiq_set_service_state(service,
  26456. + VCHIQ_SRVSTATE_LISTENING);
  26457. + unlock_service(service);
  26458. + }
  26459. +
  26460. + if (state->conn_state == VCHIQ_CONNSTATE_DISCONNECTED) {
  26461. + if (queue_message(state, NULL,
  26462. + VCHIQ_MAKE_MSG(VCHIQ_MSG_CONNECT, 0, 0), NULL, 0,
  26463. + 0, 1) == VCHIQ_RETRY)
  26464. + return VCHIQ_RETRY;
  26465. +
  26466. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTING);
  26467. + }
  26468. +
  26469. + if (state->conn_state == VCHIQ_CONNSTATE_CONNECTING) {
  26470. + if (down_interruptible(&state->connect) != 0)
  26471. + return VCHIQ_RETRY;
  26472. +
  26473. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTED);
  26474. + up(&state->connect);
  26475. + }
  26476. +
  26477. + return VCHIQ_SUCCESS;
  26478. +}
  26479. +
  26480. +VCHIQ_STATUS_T
  26481. +vchiq_shutdown_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance)
  26482. +{
  26483. + VCHIQ_SERVICE_T *service;
  26484. + int i;
  26485. +
  26486. + /* Find all services registered to this client and enable them. */
  26487. + i = 0;
  26488. + while ((service = next_service_by_instance(state, instance,
  26489. + &i)) != NULL) {
  26490. + (void)vchiq_remove_service(service->handle);
  26491. + unlock_service(service);
  26492. + }
  26493. +
  26494. + return VCHIQ_SUCCESS;
  26495. +}
  26496. +
  26497. +VCHIQ_STATUS_T
  26498. +vchiq_pause_internal(VCHIQ_STATE_T *state)
  26499. +{
  26500. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  26501. +
  26502. + switch (state->conn_state) {
  26503. + case VCHIQ_CONNSTATE_CONNECTED:
  26504. + /* Request a pause */
  26505. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_PAUSING);
  26506. + request_poll(state, NULL, 0);
  26507. + break;
  26508. + default:
  26509. + vchiq_log_error(vchiq_core_log_level,
  26510. + "vchiq_pause_internal in state %s\n",
  26511. + conn_state_names[state->conn_state]);
  26512. + status = VCHIQ_ERROR;
  26513. + VCHIQ_STATS_INC(state, error_count);
  26514. + break;
  26515. + }
  26516. +
  26517. + return status;
  26518. +}
  26519. +
  26520. +VCHIQ_STATUS_T
  26521. +vchiq_resume_internal(VCHIQ_STATE_T *state)
  26522. +{
  26523. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  26524. +
  26525. + if (state->conn_state == VCHIQ_CONNSTATE_PAUSED) {
  26526. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_RESUMING);
  26527. + request_poll(state, NULL, 0);
  26528. + } else {
  26529. + status = VCHIQ_ERROR;
  26530. + VCHIQ_STATS_INC(state, error_count);
  26531. + }
  26532. +
  26533. + return status;
  26534. +}
  26535. +
  26536. +VCHIQ_STATUS_T
  26537. +vchiq_close_service(VCHIQ_SERVICE_HANDLE_T handle)
  26538. +{
  26539. + /* Unregister the service */
  26540. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  26541. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  26542. +
  26543. + if (!service)
  26544. + return VCHIQ_ERROR;
  26545. +
  26546. + vchiq_log_info(vchiq_core_log_level,
  26547. + "%d: close_service:%d",
  26548. + service->state->id, service->localport);
  26549. +
  26550. + if ((service->srvstate == VCHIQ_SRVSTATE_FREE) ||
  26551. + (service->srvstate == VCHIQ_SRVSTATE_LISTENING) ||
  26552. + (service->srvstate == VCHIQ_SRVSTATE_HIDDEN)) {
  26553. + unlock_service(service);
  26554. + return VCHIQ_ERROR;
  26555. + }
  26556. +
  26557. + mark_service_closing(service);
  26558. +
  26559. + if (current == service->state->slot_handler_thread) {
  26560. + status = vchiq_close_service_internal(service,
  26561. + 0/*!close_recvd*/);
  26562. + BUG_ON(status == VCHIQ_RETRY);
  26563. + } else {
  26564. + /* Mark the service for termination by the slot handler */
  26565. + request_poll(service->state, service, VCHIQ_POLL_TERMINATE);
  26566. + }
  26567. +
  26568. + while (1) {
  26569. + if (down_interruptible(&service->remove_event) != 0) {
  26570. + status = VCHIQ_RETRY;
  26571. + break;
  26572. + }
  26573. +
  26574. + if ((service->srvstate == VCHIQ_SRVSTATE_FREE) ||
  26575. + (service->srvstate == VCHIQ_SRVSTATE_LISTENING) ||
  26576. + (service->srvstate == VCHIQ_SRVSTATE_OPEN))
  26577. + break;
  26578. +
  26579. + vchiq_log_warning(vchiq_core_log_level,
  26580. + "%d: close_service:%d - waiting in state %s",
  26581. + service->state->id, service->localport,
  26582. + srvstate_names[service->srvstate]);
  26583. + }
  26584. +
  26585. + if ((status == VCHIQ_SUCCESS) &&
  26586. + (service->srvstate != VCHIQ_SRVSTATE_FREE) &&
  26587. + (service->srvstate != VCHIQ_SRVSTATE_LISTENING))
  26588. + status = VCHIQ_ERROR;
  26589. +
  26590. + unlock_service(service);
  26591. +
  26592. + return status;
  26593. +}
  26594. +
  26595. +VCHIQ_STATUS_T
  26596. +vchiq_remove_service(VCHIQ_SERVICE_HANDLE_T handle)
  26597. +{
  26598. + /* Unregister the service */
  26599. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  26600. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  26601. +
  26602. + if (!service)
  26603. + return VCHIQ_ERROR;
  26604. +
  26605. + vchiq_log_info(vchiq_core_log_level,
  26606. + "%d: remove_service:%d",
  26607. + service->state->id, service->localport);
  26608. +
  26609. + if (service->srvstate == VCHIQ_SRVSTATE_FREE) {
  26610. + unlock_service(service);
  26611. + return VCHIQ_ERROR;
  26612. + }
  26613. +
  26614. + mark_service_closing(service);
  26615. +
  26616. + if ((service->srvstate == VCHIQ_SRVSTATE_HIDDEN) ||
  26617. + (current == service->state->slot_handler_thread)) {
  26618. + /* Make it look like a client, because it must be removed and
  26619. + not left in the LISTENING state. */
  26620. + service->public_fourcc = VCHIQ_FOURCC_INVALID;
  26621. +
  26622. + status = vchiq_close_service_internal(service,
  26623. + 0/*!close_recvd*/);
  26624. + BUG_ON(status == VCHIQ_RETRY);
  26625. + } else {
  26626. + /* Mark the service for removal by the slot handler */
  26627. + request_poll(service->state, service, VCHIQ_POLL_REMOVE);
  26628. + }
  26629. + while (1) {
  26630. + if (down_interruptible(&service->remove_event) != 0) {
  26631. + status = VCHIQ_RETRY;
  26632. + break;
  26633. + }
  26634. +
  26635. + if ((service->srvstate == VCHIQ_SRVSTATE_FREE) ||
  26636. + (service->srvstate == VCHIQ_SRVSTATE_OPEN))
  26637. + break;
  26638. +
  26639. + vchiq_log_warning(vchiq_core_log_level,
  26640. + "%d: remove_service:%d - waiting in state %s",
  26641. + service->state->id, service->localport,
  26642. + srvstate_names[service->srvstate]);
  26643. + }
  26644. +
  26645. + if ((status == VCHIQ_SUCCESS) &&
  26646. + (service->srvstate != VCHIQ_SRVSTATE_FREE))
  26647. + status = VCHIQ_ERROR;
  26648. +
  26649. + unlock_service(service);
  26650. +
  26651. + return status;
  26652. +}
  26653. +
  26654. +
  26655. +/* This function may be called by kernel threads or user threads.
  26656. + * User threads may receive VCHIQ_RETRY to indicate that a signal has been
  26657. + * received and the call should be retried after being returned to user
  26658. + * context.
  26659. + * When called in blocking mode, the userdata field points to a bulk_waiter
  26660. + * structure.
  26661. + */
  26662. +VCHIQ_STATUS_T
  26663. +vchiq_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle,
  26664. + VCHI_MEM_HANDLE_T memhandle, void *offset, int size, void *userdata,
  26665. + VCHIQ_BULK_MODE_T mode, VCHIQ_BULK_DIR_T dir)
  26666. +{
  26667. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  26668. + VCHIQ_BULK_QUEUE_T *queue;
  26669. + VCHIQ_BULK_T *bulk;
  26670. + VCHIQ_STATE_T *state;
  26671. + struct bulk_waiter *bulk_waiter = NULL;
  26672. + const char dir_char = (dir == VCHIQ_BULK_TRANSMIT) ? 't' : 'r';
  26673. + const int dir_msgtype = (dir == VCHIQ_BULK_TRANSMIT) ?
  26674. + VCHIQ_MSG_BULK_TX : VCHIQ_MSG_BULK_RX;
  26675. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  26676. +
  26677. + if (!service ||
  26678. + (service->srvstate != VCHIQ_SRVSTATE_OPEN) ||
  26679. + ((memhandle == VCHI_MEM_HANDLE_INVALID) && (offset == NULL)) ||
  26680. + (vchiq_check_service(service) != VCHIQ_SUCCESS))
  26681. + goto error_exit;
  26682. +
  26683. + switch (mode) {
  26684. + case VCHIQ_BULK_MODE_NOCALLBACK:
  26685. + case VCHIQ_BULK_MODE_CALLBACK:
  26686. + break;
  26687. + case VCHIQ_BULK_MODE_BLOCKING:
  26688. + bulk_waiter = (struct bulk_waiter *)userdata;
  26689. + sema_init(&bulk_waiter->event, 0);
  26690. + bulk_waiter->actual = 0;
  26691. + bulk_waiter->bulk = NULL;
  26692. + break;
  26693. + case VCHIQ_BULK_MODE_WAITING:
  26694. + bulk_waiter = (struct bulk_waiter *)userdata;
  26695. + bulk = bulk_waiter->bulk;
  26696. + goto waiting;
  26697. + default:
  26698. + goto error_exit;
  26699. + }
  26700. +
  26701. + state = service->state;
  26702. +
  26703. + queue = (dir == VCHIQ_BULK_TRANSMIT) ?
  26704. + &service->bulk_tx : &service->bulk_rx;
  26705. +
  26706. + if (mutex_lock_interruptible(&service->bulk_mutex) != 0) {
  26707. + status = VCHIQ_RETRY;
  26708. + goto error_exit;
  26709. + }
  26710. +
  26711. + if (queue->local_insert == queue->remove + VCHIQ_NUM_SERVICE_BULKS) {
  26712. + VCHIQ_SERVICE_STATS_INC(service, bulk_stalls);
  26713. + do {
  26714. + mutex_unlock(&service->bulk_mutex);
  26715. + if (down_interruptible(&service->bulk_remove_event)
  26716. + != 0) {
  26717. + status = VCHIQ_RETRY;
  26718. + goto error_exit;
  26719. + }
  26720. + if (mutex_lock_interruptible(&service->bulk_mutex)
  26721. + != 0) {
  26722. + status = VCHIQ_RETRY;
  26723. + goto error_exit;
  26724. + }
  26725. + } while (queue->local_insert == queue->remove +
  26726. + VCHIQ_NUM_SERVICE_BULKS);
  26727. + }
  26728. +
  26729. + bulk = &queue->bulks[BULK_INDEX(queue->local_insert)];
  26730. +
  26731. + bulk->mode = mode;
  26732. + bulk->dir = dir;
  26733. + bulk->userdata = userdata;
  26734. + bulk->size = size;
  26735. + bulk->actual = VCHIQ_BULK_ACTUAL_ABORTED;
  26736. +
  26737. + if (vchiq_prepare_bulk_data(bulk, memhandle, offset, size, dir) !=
  26738. + VCHIQ_SUCCESS)
  26739. + goto unlock_error_exit;
  26740. +
  26741. + wmb();
  26742. +
  26743. + vchiq_log_info(vchiq_core_log_level,
  26744. + "%d: bt (%d->%d) %cx %x@%x %x",
  26745. + state->id,
  26746. + service->localport, service->remoteport, dir_char,
  26747. + size, (unsigned int)bulk->data, (unsigned int)userdata);
  26748. +
  26749. + if (state->is_master) {
  26750. + queue->local_insert++;
  26751. + if (resolve_bulks(service, queue))
  26752. + request_poll(state, service,
  26753. + (dir == VCHIQ_BULK_TRANSMIT) ?
  26754. + VCHIQ_POLL_TXNOTIFY : VCHIQ_POLL_RXNOTIFY);
  26755. + } else {
  26756. + int payload[2] = { (int)bulk->data, bulk->size };
  26757. + VCHIQ_ELEMENT_T element = { payload, sizeof(payload) };
  26758. +
  26759. + status = queue_message(state, NULL,
  26760. + VCHIQ_MAKE_MSG(dir_msgtype,
  26761. + service->localport, service->remoteport),
  26762. + &element, 1, sizeof(payload), 1);
  26763. + if (status != VCHIQ_SUCCESS) {
  26764. + vchiq_complete_bulk(bulk);
  26765. + goto unlock_error_exit;
  26766. + }
  26767. + queue->local_insert++;
  26768. + }
  26769. +
  26770. + mutex_unlock(&service->bulk_mutex);
  26771. +
  26772. + vchiq_log_trace(vchiq_core_log_level,
  26773. + "%d: bt:%d %cx li=%x ri=%x p=%x",
  26774. + state->id,
  26775. + service->localport, dir_char,
  26776. + queue->local_insert, queue->remote_insert, queue->process);
  26777. +
  26778. +waiting:
  26779. + unlock_service(service);
  26780. +
  26781. + status = VCHIQ_SUCCESS;
  26782. +
  26783. + if (bulk_waiter) {
  26784. + bulk_waiter->bulk = bulk;
  26785. + if (down_interruptible(&bulk_waiter->event) != 0)
  26786. + status = VCHIQ_RETRY;
  26787. + else if (bulk_waiter->actual == VCHIQ_BULK_ACTUAL_ABORTED)
  26788. + status = VCHIQ_ERROR;
  26789. + }
  26790. +
  26791. + return status;
  26792. +
  26793. +unlock_error_exit:
  26794. + mutex_unlock(&service->bulk_mutex);
  26795. +
  26796. +error_exit:
  26797. + if (service)
  26798. + unlock_service(service);
  26799. + return status;
  26800. +}
  26801. +
  26802. +VCHIQ_STATUS_T
  26803. +vchiq_queue_message(VCHIQ_SERVICE_HANDLE_T handle,
  26804. + const VCHIQ_ELEMENT_T *elements, unsigned int count)
  26805. +{
  26806. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  26807. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  26808. +
  26809. + unsigned int size = 0;
  26810. + unsigned int i;
  26811. +
  26812. + if (!service ||
  26813. + (vchiq_check_service(service) != VCHIQ_SUCCESS))
  26814. + goto error_exit;
  26815. +
  26816. + for (i = 0; i < (unsigned int)count; i++) {
  26817. + if (elements[i].size) {
  26818. + if (elements[i].data == NULL) {
  26819. + VCHIQ_SERVICE_STATS_INC(service, error_count);
  26820. + goto error_exit;
  26821. + }
  26822. + size += elements[i].size;
  26823. + }
  26824. + }
  26825. +
  26826. + if (size > VCHIQ_MAX_MSG_SIZE) {
  26827. + VCHIQ_SERVICE_STATS_INC(service, error_count);
  26828. + goto error_exit;
  26829. + }
  26830. +
  26831. + switch (service->srvstate) {
  26832. + case VCHIQ_SRVSTATE_OPEN:
  26833. + status = queue_message(service->state, service,
  26834. + VCHIQ_MAKE_MSG(VCHIQ_MSG_DATA,
  26835. + service->localport,
  26836. + service->remoteport),
  26837. + elements, count, size, 1);
  26838. + break;
  26839. + case VCHIQ_SRVSTATE_OPENSYNC:
  26840. + status = queue_message_sync(service->state, service,
  26841. + VCHIQ_MAKE_MSG(VCHIQ_MSG_DATA,
  26842. + service->localport,
  26843. + service->remoteport),
  26844. + elements, count, size, 1);
  26845. + break;
  26846. + default:
  26847. + status = VCHIQ_ERROR;
  26848. + break;
  26849. + }
  26850. +
  26851. +error_exit:
  26852. + if (service)
  26853. + unlock_service(service);
  26854. +
  26855. + return status;
  26856. +}
  26857. +
  26858. +void
  26859. +vchiq_release_message(VCHIQ_SERVICE_HANDLE_T handle, VCHIQ_HEADER_T *header)
  26860. +{
  26861. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  26862. + VCHIQ_SHARED_STATE_T *remote;
  26863. + VCHIQ_STATE_T *state;
  26864. + int slot_index;
  26865. +
  26866. + if (!service)
  26867. + return;
  26868. +
  26869. + state = service->state;
  26870. + remote = state->remote;
  26871. +
  26872. + slot_index = SLOT_INDEX_FROM_DATA(state, (void *)header);
  26873. +
  26874. + if ((slot_index >= remote->slot_first) &&
  26875. + (slot_index <= remote->slot_last)) {
  26876. + int msgid = header->msgid;
  26877. + if (msgid & VCHIQ_MSGID_CLAIMED) {
  26878. + VCHIQ_SLOT_INFO_T *slot_info =
  26879. + SLOT_INFO_FROM_INDEX(state, slot_index);
  26880. +
  26881. + release_slot(state, slot_info, header, service);
  26882. + }
  26883. + } else if (slot_index == remote->slot_sync)
  26884. + release_message_sync(state, header);
  26885. +
  26886. + unlock_service(service);
  26887. +}
  26888. +
  26889. +static void
  26890. +release_message_sync(VCHIQ_STATE_T *state, VCHIQ_HEADER_T *header)
  26891. +{
  26892. + header->msgid = VCHIQ_MSGID_PADDING;
  26893. + wmb();
  26894. + remote_event_signal(&state->remote->sync_release);
  26895. +}
  26896. +
  26897. +VCHIQ_STATUS_T
  26898. +vchiq_get_peer_version(VCHIQ_SERVICE_HANDLE_T handle, short *peer_version)
  26899. +{
  26900. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  26901. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  26902. +
  26903. + if (!service ||
  26904. + (vchiq_check_service(service) != VCHIQ_SUCCESS) ||
  26905. + !peer_version)
  26906. + goto exit;
  26907. + *peer_version = service->peer_version;
  26908. + status = VCHIQ_SUCCESS;
  26909. +
  26910. +exit:
  26911. + if (service)
  26912. + unlock_service(service);
  26913. + return status;
  26914. +}
  26915. +
  26916. +VCHIQ_STATUS_T
  26917. +vchiq_get_config(VCHIQ_INSTANCE_T instance,
  26918. + int config_size, VCHIQ_CONFIG_T *pconfig)
  26919. +{
  26920. + VCHIQ_CONFIG_T config;
  26921. +
  26922. + (void)instance;
  26923. +
  26924. + config.max_msg_size = VCHIQ_MAX_MSG_SIZE;
  26925. + config.bulk_threshold = VCHIQ_MAX_MSG_SIZE;
  26926. + config.max_outstanding_bulks = VCHIQ_NUM_SERVICE_BULKS;
  26927. + config.max_services = VCHIQ_MAX_SERVICES;
  26928. + config.version = VCHIQ_VERSION;
  26929. + config.version_min = VCHIQ_VERSION_MIN;
  26930. +
  26931. + if (config_size > sizeof(VCHIQ_CONFIG_T))
  26932. + return VCHIQ_ERROR;
  26933. +
  26934. + memcpy(pconfig, &config,
  26935. + min(config_size, (int)(sizeof(VCHIQ_CONFIG_T))));
  26936. +
  26937. + return VCHIQ_SUCCESS;
  26938. +}
  26939. +
  26940. +VCHIQ_STATUS_T
  26941. +vchiq_set_service_option(VCHIQ_SERVICE_HANDLE_T handle,
  26942. + VCHIQ_SERVICE_OPTION_T option, int value)
  26943. +{
  26944. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  26945. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  26946. +
  26947. + if (service) {
  26948. + switch (option) {
  26949. + case VCHIQ_SERVICE_OPTION_AUTOCLOSE:
  26950. + service->auto_close = value;
  26951. + status = VCHIQ_SUCCESS;
  26952. + break;
  26953. +
  26954. + case VCHIQ_SERVICE_OPTION_SLOT_QUOTA: {
  26955. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  26956. + &service->state->service_quotas[
  26957. + service->localport];
  26958. + if (value == 0)
  26959. + value = service->state->default_slot_quota;
  26960. + if ((value >= service_quota->slot_use_count) &&
  26961. + (value < (unsigned short)~0)) {
  26962. + service_quota->slot_quota = value;
  26963. + if ((value >= service_quota->slot_use_count) &&
  26964. + (service_quota->message_quota >=
  26965. + service_quota->message_use_count)) {
  26966. + /* Signal the service that it may have
  26967. + ** dropped below its quota */
  26968. + up(&service_quota->quota_event);
  26969. + }
  26970. + status = VCHIQ_SUCCESS;
  26971. + }
  26972. + } break;
  26973. +
  26974. + case VCHIQ_SERVICE_OPTION_MESSAGE_QUOTA: {
  26975. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  26976. + &service->state->service_quotas[
  26977. + service->localport];
  26978. + if (value == 0)
  26979. + value = service->state->default_message_quota;
  26980. + if ((value >= service_quota->message_use_count) &&
  26981. + (value < (unsigned short)~0)) {
  26982. + service_quota->message_quota = value;
  26983. + if ((value >=
  26984. + service_quota->message_use_count) &&
  26985. + (service_quota->slot_quota >=
  26986. + service_quota->slot_use_count))
  26987. + /* Signal the service that it may have
  26988. + ** dropped below its quota */
  26989. + up(&service_quota->quota_event);
  26990. + status = VCHIQ_SUCCESS;
  26991. + }
  26992. + } break;
  26993. +
  26994. + case VCHIQ_SERVICE_OPTION_SYNCHRONOUS:
  26995. + if ((service->srvstate == VCHIQ_SRVSTATE_HIDDEN) ||
  26996. + (service->srvstate ==
  26997. + VCHIQ_SRVSTATE_LISTENING)) {
  26998. + service->sync = value;
  26999. + status = VCHIQ_SUCCESS;
  27000. + }
  27001. + break;
  27002. +
  27003. + default:
  27004. + break;
  27005. + }
  27006. + unlock_service(service);
  27007. + }
  27008. +
  27009. + return status;
  27010. +}
  27011. +
  27012. +void
  27013. +vchiq_dump_shared_state(void *dump_context, VCHIQ_STATE_T *state,
  27014. + VCHIQ_SHARED_STATE_T *shared, const char *label)
  27015. +{
  27016. + static const char *const debug_names[] = {
  27017. + "<entries>",
  27018. + "SLOT_HANDLER_COUNT",
  27019. + "SLOT_HANDLER_LINE",
  27020. + "PARSE_LINE",
  27021. + "PARSE_HEADER",
  27022. + "PARSE_MSGID",
  27023. + "AWAIT_COMPLETION_LINE",
  27024. + "DEQUEUE_MESSAGE_LINE",
  27025. + "SERVICE_CALLBACK_LINE",
  27026. + "MSG_QUEUE_FULL_COUNT",
  27027. + "COMPLETION_QUEUE_FULL_COUNT"
  27028. + };
  27029. + int i;
  27030. +
  27031. + char buf[80];
  27032. + int len;
  27033. + len = snprintf(buf, sizeof(buf),
  27034. + " %s: slots %d-%d tx_pos=%x recycle=%x",
  27035. + label, shared->slot_first, shared->slot_last,
  27036. + shared->tx_pos, shared->slot_queue_recycle);
  27037. + vchiq_dump(dump_context, buf, len + 1);
  27038. +
  27039. + len = snprintf(buf, sizeof(buf),
  27040. + " Slots claimed:");
  27041. + vchiq_dump(dump_context, buf, len + 1);
  27042. +
  27043. + for (i = shared->slot_first; i <= shared->slot_last; i++) {
  27044. + VCHIQ_SLOT_INFO_T slot_info = *SLOT_INFO_FROM_INDEX(state, i);
  27045. + if (slot_info.use_count != slot_info.release_count) {
  27046. + len = snprintf(buf, sizeof(buf),
  27047. + " %d: %d/%d", i, slot_info.use_count,
  27048. + slot_info.release_count);
  27049. + vchiq_dump(dump_context, buf, len + 1);
  27050. + }
  27051. + }
  27052. +
  27053. + for (i = 1; i < shared->debug[DEBUG_ENTRIES]; i++) {
  27054. + len = snprintf(buf, sizeof(buf), " DEBUG: %s = %d(%x)",
  27055. + debug_names[i], shared->debug[i], shared->debug[i]);
  27056. + vchiq_dump(dump_context, buf, len + 1);
  27057. + }
  27058. +}
  27059. +
  27060. +void
  27061. +vchiq_dump_state(void *dump_context, VCHIQ_STATE_T *state)
  27062. +{
  27063. + char buf[80];
  27064. + int len;
  27065. + int i;
  27066. +
  27067. + len = snprintf(buf, sizeof(buf), "State %d: %s", state->id,
  27068. + conn_state_names[state->conn_state]);
  27069. + vchiq_dump(dump_context, buf, len + 1);
  27070. +
  27071. + len = snprintf(buf, sizeof(buf),
  27072. + " tx_pos=%x(@%x), rx_pos=%x(@%x)",
  27073. + state->local->tx_pos,
  27074. + (uint32_t)state->tx_data +
  27075. + (state->local_tx_pos & VCHIQ_SLOT_MASK),
  27076. + state->rx_pos,
  27077. + (uint32_t)state->rx_data +
  27078. + (state->rx_pos & VCHIQ_SLOT_MASK));
  27079. + vchiq_dump(dump_context, buf, len + 1);
  27080. +
  27081. + len = snprintf(buf, sizeof(buf),
  27082. + " Version: %d (min %d)",
  27083. + VCHIQ_VERSION, VCHIQ_VERSION_MIN);
  27084. + vchiq_dump(dump_context, buf, len + 1);
  27085. +
  27086. + if (VCHIQ_ENABLE_STATS) {
  27087. + len = snprintf(buf, sizeof(buf),
  27088. + " Stats: ctrl_tx_count=%d, ctrl_rx_count=%d, "
  27089. + "error_count=%d",
  27090. + state->stats.ctrl_tx_count, state->stats.ctrl_rx_count,
  27091. + state->stats.error_count);
  27092. + vchiq_dump(dump_context, buf, len + 1);
  27093. + }
  27094. +
  27095. + len = snprintf(buf, sizeof(buf),
  27096. + " Slots: %d available (%d data), %d recyclable, %d stalls "
  27097. + "(%d data)",
  27098. + ((state->slot_queue_available * VCHIQ_SLOT_SIZE) -
  27099. + state->local_tx_pos) / VCHIQ_SLOT_SIZE,
  27100. + state->data_quota - state->data_use_count,
  27101. + state->local->slot_queue_recycle - state->slot_queue_available,
  27102. + state->stats.slot_stalls, state->stats.data_stalls);
  27103. + vchiq_dump(dump_context, buf, len + 1);
  27104. +
  27105. + vchiq_dump_platform_state(dump_context);
  27106. +
  27107. + vchiq_dump_shared_state(dump_context, state, state->local, "Local");
  27108. + vchiq_dump_shared_state(dump_context, state, state->remote, "Remote");
  27109. +
  27110. + vchiq_dump_platform_instances(dump_context);
  27111. +
  27112. + for (i = 0; i < state->unused_service; i++) {
  27113. + VCHIQ_SERVICE_T *service = find_service_by_port(state, i);
  27114. +
  27115. + if (service) {
  27116. + vchiq_dump_service_state(dump_context, service);
  27117. + unlock_service(service);
  27118. + }
  27119. + }
  27120. +}
  27121. +
  27122. +void
  27123. +vchiq_dump_service_state(void *dump_context, VCHIQ_SERVICE_T *service)
  27124. +{
  27125. + char buf[80];
  27126. + int len;
  27127. +
  27128. + len = snprintf(buf, sizeof(buf), "Service %d: %s (ref %u)",
  27129. + service->localport, srvstate_names[service->srvstate],
  27130. + service->ref_count - 1); /*Don't include the lock just taken*/
  27131. +
  27132. + if (service->srvstate != VCHIQ_SRVSTATE_FREE) {
  27133. + char remoteport[30];
  27134. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  27135. + &service->state->service_quotas[service->localport];
  27136. + int fourcc = service->base.fourcc;
  27137. + int tx_pending, rx_pending;
  27138. + if (service->remoteport != VCHIQ_PORT_FREE) {
  27139. + int len2 = snprintf(remoteport, sizeof(remoteport),
  27140. + "%d", service->remoteport);
  27141. + if (service->public_fourcc != VCHIQ_FOURCC_INVALID)
  27142. + snprintf(remoteport + len2,
  27143. + sizeof(remoteport) - len2,
  27144. + " (client %x)", service->client_id);
  27145. + } else
  27146. + strcpy(remoteport, "n/a");
  27147. +
  27148. + len += snprintf(buf + len, sizeof(buf) - len,
  27149. + " '%c%c%c%c' remote %s (msg use %d/%d, slot use %d/%d)",
  27150. + VCHIQ_FOURCC_AS_4CHARS(fourcc),
  27151. + remoteport,
  27152. + service_quota->message_use_count,
  27153. + service_quota->message_quota,
  27154. + service_quota->slot_use_count,
  27155. + service_quota->slot_quota);
  27156. +
  27157. + vchiq_dump(dump_context, buf, len + 1);
  27158. +
  27159. + tx_pending = service->bulk_tx.local_insert -
  27160. + service->bulk_tx.remote_insert;
  27161. +
  27162. + rx_pending = service->bulk_rx.local_insert -
  27163. + service->bulk_rx.remote_insert;
  27164. +
  27165. + len = snprintf(buf, sizeof(buf),
  27166. + " Bulk: tx_pending=%d (size %d),"
  27167. + " rx_pending=%d (size %d)",
  27168. + tx_pending,
  27169. + tx_pending ? service->bulk_tx.bulks[
  27170. + BULK_INDEX(service->bulk_tx.remove)].size : 0,
  27171. + rx_pending,
  27172. + rx_pending ? service->bulk_rx.bulks[
  27173. + BULK_INDEX(service->bulk_rx.remove)].size : 0);
  27174. +
  27175. + if (VCHIQ_ENABLE_STATS) {
  27176. + vchiq_dump(dump_context, buf, len + 1);
  27177. +
  27178. + len = snprintf(buf, sizeof(buf),
  27179. + " Ctrl: tx_count=%d, tx_bytes=%llu, "
  27180. + "rx_count=%d, rx_bytes=%llu",
  27181. + service->stats.ctrl_tx_count,
  27182. + service->stats.ctrl_tx_bytes,
  27183. + service->stats.ctrl_rx_count,
  27184. + service->stats.ctrl_rx_bytes);
  27185. + vchiq_dump(dump_context, buf, len + 1);
  27186. +
  27187. + len = snprintf(buf, sizeof(buf),
  27188. + " Bulk: tx_count=%d, tx_bytes=%llu, "
  27189. + "rx_count=%d, rx_bytes=%llu",
  27190. + service->stats.bulk_tx_count,
  27191. + service->stats.bulk_tx_bytes,
  27192. + service->stats.bulk_rx_count,
  27193. + service->stats.bulk_rx_bytes);
  27194. + vchiq_dump(dump_context, buf, len + 1);
  27195. +
  27196. + len = snprintf(buf, sizeof(buf),
  27197. + " %d quota stalls, %d slot stalls, "
  27198. + "%d bulk stalls, %d aborted, %d errors",
  27199. + service->stats.quota_stalls,
  27200. + service->stats.slot_stalls,
  27201. + service->stats.bulk_stalls,
  27202. + service->stats.bulk_aborted_count,
  27203. + service->stats.error_count);
  27204. + }
  27205. + }
  27206. +
  27207. + vchiq_dump(dump_context, buf, len + 1);
  27208. +
  27209. + if (service->srvstate != VCHIQ_SRVSTATE_FREE)
  27210. + vchiq_dump_platform_service_state(dump_context, service);
  27211. +}
  27212. +
  27213. +
  27214. +void
  27215. +vchiq_loud_error_header(void)
  27216. +{
  27217. + vchiq_log_error(vchiq_core_log_level,
  27218. + "============================================================"
  27219. + "================");
  27220. + vchiq_log_error(vchiq_core_log_level,
  27221. + "============================================================"
  27222. + "================");
  27223. + vchiq_log_error(vchiq_core_log_level, "=====");
  27224. +}
  27225. +
  27226. +void
  27227. +vchiq_loud_error_footer(void)
  27228. +{
  27229. + vchiq_log_error(vchiq_core_log_level, "=====");
  27230. + vchiq_log_error(vchiq_core_log_level,
  27231. + "============================================================"
  27232. + "================");
  27233. + vchiq_log_error(vchiq_core_log_level,
  27234. + "============================================================"
  27235. + "================");
  27236. +}
  27237. +
  27238. +
  27239. +VCHIQ_STATUS_T vchiq_send_remote_use(VCHIQ_STATE_T *state)
  27240. +{
  27241. + VCHIQ_STATUS_T status = VCHIQ_RETRY;
  27242. + if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED)
  27243. + status = queue_message(state, NULL,
  27244. + VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_USE, 0, 0),
  27245. + NULL, 0, 0, 0);
  27246. + return status;
  27247. +}
  27248. +
  27249. +VCHIQ_STATUS_T vchiq_send_remote_release(VCHIQ_STATE_T *state)
  27250. +{
  27251. + VCHIQ_STATUS_T status = VCHIQ_RETRY;
  27252. + if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED)
  27253. + status = queue_message(state, NULL,
  27254. + VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_RELEASE, 0, 0),
  27255. + NULL, 0, 0, 0);
  27256. + return status;
  27257. +}
  27258. +
  27259. +VCHIQ_STATUS_T vchiq_send_remote_use_active(VCHIQ_STATE_T *state)
  27260. +{
  27261. + VCHIQ_STATUS_T status = VCHIQ_RETRY;
  27262. + if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED)
  27263. + status = queue_message(state, NULL,
  27264. + VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_USE_ACTIVE, 0, 0),
  27265. + NULL, 0, 0, 0);
  27266. + return status;
  27267. +}
  27268. +
  27269. +void vchiq_log_dump_mem(const char *label, uint32_t addr, const void *voidMem,
  27270. + size_t numBytes)
  27271. +{
  27272. + const uint8_t *mem = (const uint8_t *)voidMem;
  27273. + size_t offset;
  27274. + char lineBuf[100];
  27275. + char *s;
  27276. +
  27277. + while (numBytes > 0) {
  27278. + s = lineBuf;
  27279. +
  27280. + for (offset = 0; offset < 16; offset++) {
  27281. + if (offset < numBytes)
  27282. + s += snprintf(s, 4, "%02x ", mem[offset]);
  27283. + else
  27284. + s += snprintf(s, 4, " ");
  27285. + }
  27286. +
  27287. + for (offset = 0; offset < 16; offset++) {
  27288. + if (offset < numBytes) {
  27289. + uint8_t ch = mem[offset];
  27290. +
  27291. + if ((ch < ' ') || (ch > '~'))
  27292. + ch = '.';
  27293. + *s++ = (char)ch;
  27294. + }
  27295. + }
  27296. + *s++ = '\0';
  27297. +
  27298. + if ((label != NULL) && (*label != '\0'))
  27299. + vchiq_log_trace(VCHIQ_LOG_TRACE,
  27300. + "%s: %08x: %s", label, addr, lineBuf);
  27301. + else
  27302. + vchiq_log_trace(VCHIQ_LOG_TRACE,
  27303. + "%08x: %s", addr, lineBuf);
  27304. +
  27305. + addr += 16;
  27306. + mem += 16;
  27307. + if (numBytes > 16)
  27308. + numBytes -= 16;
  27309. + else
  27310. + numBytes = 0;
  27311. + }
  27312. +}
  27313. diff -Nur linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h
  27314. --- linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h 1970-01-01 01:00:00.000000000 +0100
  27315. +++ linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h 2014-08-06 16:50:14.493962307 +0200
  27316. @@ -0,0 +1,706 @@
  27317. +/**
  27318. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  27319. + *
  27320. + * Redistribution and use in source and binary forms, with or without
  27321. + * modification, are permitted provided that the following conditions
  27322. + * are met:
  27323. + * 1. Redistributions of source code must retain the above copyright
  27324. + * notice, this list of conditions, and the following disclaimer,
  27325. + * without modification.
  27326. + * 2. Redistributions in binary form must reproduce the above copyright
  27327. + * notice, this list of conditions and the following disclaimer in the
  27328. + * documentation and/or other materials provided with the distribution.
  27329. + * 3. The names of the above-listed copyright holders may not be used
  27330. + * to endorse or promote products derived from this software without
  27331. + * specific prior written permission.
  27332. + *
  27333. + * ALTERNATIVELY, this software may be distributed under the terms of the
  27334. + * GNU General Public License ("GPL") version 2, as published by the Free
  27335. + * Software Foundation.
  27336. + *
  27337. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  27338. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  27339. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  27340. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  27341. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  27342. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  27343. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27344. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  27345. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  27346. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27347. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27348. + */
  27349. +
  27350. +#ifndef VCHIQ_CORE_H
  27351. +#define VCHIQ_CORE_H
  27352. +
  27353. +#include <linux/mutex.h>
  27354. +#include <linux/semaphore.h>
  27355. +#include <linux/kthread.h>
  27356. +
  27357. +#include "vchiq_cfg.h"
  27358. +
  27359. +#include "vchiq.h"
  27360. +
  27361. +/* Run time control of log level, based on KERN_XXX level. */
  27362. +#define VCHIQ_LOG_DEFAULT 4
  27363. +#define VCHIQ_LOG_ERROR 3
  27364. +#define VCHIQ_LOG_WARNING 4
  27365. +#define VCHIQ_LOG_INFO 6
  27366. +#define VCHIQ_LOG_TRACE 7
  27367. +
  27368. +#define VCHIQ_LOG_PREFIX KERN_INFO "vchiq: "
  27369. +
  27370. +#ifndef vchiq_log_error
  27371. +#define vchiq_log_error(cat, fmt, ...) \
  27372. + do { if (cat >= VCHIQ_LOG_ERROR) \
  27373. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  27374. +#endif
  27375. +#ifndef vchiq_log_warning
  27376. +#define vchiq_log_warning(cat, fmt, ...) \
  27377. + do { if (cat >= VCHIQ_LOG_WARNING) \
  27378. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  27379. +#endif
  27380. +#ifndef vchiq_log_info
  27381. +#define vchiq_log_info(cat, fmt, ...) \
  27382. + do { if (cat >= VCHIQ_LOG_INFO) \
  27383. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  27384. +#endif
  27385. +#ifndef vchiq_log_trace
  27386. +#define vchiq_log_trace(cat, fmt, ...) \
  27387. + do { if (cat >= VCHIQ_LOG_TRACE) \
  27388. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  27389. +#endif
  27390. +
  27391. +#define vchiq_loud_error(...) \
  27392. + vchiq_log_error(vchiq_core_log_level, "===== " __VA_ARGS__)
  27393. +
  27394. +#ifndef vchiq_static_assert
  27395. +#define vchiq_static_assert(cond) __attribute__((unused)) \
  27396. + extern int vchiq_static_assert[(cond) ? 1 : -1]
  27397. +#endif
  27398. +
  27399. +#define IS_POW2(x) (x && ((x & (x - 1)) == 0))
  27400. +
  27401. +/* Ensure that the slot size and maximum number of slots are powers of 2 */
  27402. +vchiq_static_assert(IS_POW2(VCHIQ_SLOT_SIZE));
  27403. +vchiq_static_assert(IS_POW2(VCHIQ_MAX_SLOTS));
  27404. +vchiq_static_assert(IS_POW2(VCHIQ_MAX_SLOTS_PER_SIDE));
  27405. +
  27406. +#define VCHIQ_SLOT_MASK (VCHIQ_SLOT_SIZE - 1)
  27407. +#define VCHIQ_SLOT_QUEUE_MASK (VCHIQ_MAX_SLOTS_PER_SIDE - 1)
  27408. +#define VCHIQ_SLOT_ZERO_SLOTS ((sizeof(VCHIQ_SLOT_ZERO_T) + \
  27409. + VCHIQ_SLOT_SIZE - 1) / VCHIQ_SLOT_SIZE)
  27410. +
  27411. +#define VCHIQ_MSG_PADDING 0 /* - */
  27412. +#define VCHIQ_MSG_CONNECT 1 /* - */
  27413. +#define VCHIQ_MSG_OPEN 2 /* + (srcport, -), fourcc, client_id */
  27414. +#define VCHIQ_MSG_OPENACK 3 /* + (srcport, dstport) */
  27415. +#define VCHIQ_MSG_CLOSE 4 /* + (srcport, dstport) */
  27416. +#define VCHIQ_MSG_DATA 5 /* + (srcport, dstport) */
  27417. +#define VCHIQ_MSG_BULK_RX 6 /* + (srcport, dstport), data, size */
  27418. +#define VCHIQ_MSG_BULK_TX 7 /* + (srcport, dstport), data, size */
  27419. +#define VCHIQ_MSG_BULK_RX_DONE 8 /* + (srcport, dstport), actual */
  27420. +#define VCHIQ_MSG_BULK_TX_DONE 9 /* + (srcport, dstport), actual */
  27421. +#define VCHIQ_MSG_PAUSE 10 /* - */
  27422. +#define VCHIQ_MSG_RESUME 11 /* - */
  27423. +#define VCHIQ_MSG_REMOTE_USE 12 /* - */
  27424. +#define VCHIQ_MSG_REMOTE_RELEASE 13 /* - */
  27425. +#define VCHIQ_MSG_REMOTE_USE_ACTIVE 14 /* - */
  27426. +
  27427. +#define VCHIQ_PORT_MAX (VCHIQ_MAX_SERVICES - 1)
  27428. +#define VCHIQ_PORT_FREE 0x1000
  27429. +#define VCHIQ_PORT_IS_VALID(port) (port < VCHIQ_PORT_FREE)
  27430. +#define VCHIQ_MAKE_MSG(type, srcport, dstport) \
  27431. + ((type<<24) | (srcport<<12) | (dstport<<0))
  27432. +#define VCHIQ_MSG_TYPE(msgid) ((unsigned int)msgid >> 24)
  27433. +#define VCHIQ_MSG_SRCPORT(msgid) \
  27434. + (unsigned short)(((unsigned int)msgid >> 12) & 0xfff)
  27435. +#define VCHIQ_MSG_DSTPORT(msgid) \
  27436. + ((unsigned short)msgid & 0xfff)
  27437. +
  27438. +#define VCHIQ_FOURCC_AS_4CHARS(fourcc) \
  27439. + ((fourcc) >> 24) & 0xff, \
  27440. + ((fourcc) >> 16) & 0xff, \
  27441. + ((fourcc) >> 8) & 0xff, \
  27442. + (fourcc) & 0xff
  27443. +
  27444. +/* Ensure the fields are wide enough */
  27445. +vchiq_static_assert(VCHIQ_MSG_SRCPORT(VCHIQ_MAKE_MSG(0, 0, VCHIQ_PORT_MAX))
  27446. + == 0);
  27447. +vchiq_static_assert(VCHIQ_MSG_TYPE(VCHIQ_MAKE_MSG(0, VCHIQ_PORT_MAX, 0)) == 0);
  27448. +vchiq_static_assert((unsigned int)VCHIQ_PORT_MAX <
  27449. + (unsigned int)VCHIQ_PORT_FREE);
  27450. +
  27451. +#define VCHIQ_MSGID_PADDING VCHIQ_MAKE_MSG(VCHIQ_MSG_PADDING, 0, 0)
  27452. +#define VCHIQ_MSGID_CLAIMED 0x40000000
  27453. +
  27454. +#define VCHIQ_FOURCC_INVALID 0x00000000
  27455. +#define VCHIQ_FOURCC_IS_LEGAL(fourcc) (fourcc != VCHIQ_FOURCC_INVALID)
  27456. +
  27457. +#define VCHIQ_BULK_ACTUAL_ABORTED -1
  27458. +
  27459. +typedef uint32_t BITSET_T;
  27460. +
  27461. +vchiq_static_assert((sizeof(BITSET_T) * 8) == 32);
  27462. +
  27463. +#define BITSET_SIZE(b) ((b + 31) >> 5)
  27464. +#define BITSET_WORD(b) (b >> 5)
  27465. +#define BITSET_BIT(b) (1 << (b & 31))
  27466. +#define BITSET_ZERO(bs) memset(bs, 0, sizeof(bs))
  27467. +#define BITSET_IS_SET(bs, b) (bs[BITSET_WORD(b)] & BITSET_BIT(b))
  27468. +#define BITSET_SET(bs, b) (bs[BITSET_WORD(b)] |= BITSET_BIT(b))
  27469. +#define BITSET_CLR(bs, b) (bs[BITSET_WORD(b)] &= ~BITSET_BIT(b))
  27470. +
  27471. +#if VCHIQ_ENABLE_STATS
  27472. +#define VCHIQ_STATS_INC(state, stat) (state->stats. stat++)
  27473. +#define VCHIQ_SERVICE_STATS_INC(service, stat) (service->stats. stat++)
  27474. +#define VCHIQ_SERVICE_STATS_ADD(service, stat, addend) \
  27475. + (service->stats. stat += addend)
  27476. +#else
  27477. +#define VCHIQ_STATS_INC(state, stat) ((void)0)
  27478. +#define VCHIQ_SERVICE_STATS_INC(service, stat) ((void)0)
  27479. +#define VCHIQ_SERVICE_STATS_ADD(service, stat, addend) ((void)0)
  27480. +#endif
  27481. +
  27482. +enum {
  27483. + DEBUG_ENTRIES,
  27484. +#if VCHIQ_ENABLE_DEBUG
  27485. + DEBUG_SLOT_HANDLER_COUNT,
  27486. + DEBUG_SLOT_HANDLER_LINE,
  27487. + DEBUG_PARSE_LINE,
  27488. + DEBUG_PARSE_HEADER,
  27489. + DEBUG_PARSE_MSGID,
  27490. + DEBUG_AWAIT_COMPLETION_LINE,
  27491. + DEBUG_DEQUEUE_MESSAGE_LINE,
  27492. + DEBUG_SERVICE_CALLBACK_LINE,
  27493. + DEBUG_MSG_QUEUE_FULL_COUNT,
  27494. + DEBUG_COMPLETION_QUEUE_FULL_COUNT,
  27495. +#endif
  27496. + DEBUG_MAX
  27497. +};
  27498. +
  27499. +#if VCHIQ_ENABLE_DEBUG
  27500. +
  27501. +#define DEBUG_INITIALISE(local) int *debug_ptr = (local)->debug;
  27502. +#define DEBUG_TRACE(d) \
  27503. + do { debug_ptr[DEBUG_ ## d] = __LINE__; dsb(); } while (0)
  27504. +#define DEBUG_VALUE(d, v) \
  27505. + do { debug_ptr[DEBUG_ ## d] = (v); dsb(); } while (0)
  27506. +#define DEBUG_COUNT(d) \
  27507. + do { debug_ptr[DEBUG_ ## d]++; dsb(); } while (0)
  27508. +
  27509. +#else /* VCHIQ_ENABLE_DEBUG */
  27510. +
  27511. +#define DEBUG_INITIALISE(local)
  27512. +#define DEBUG_TRACE(d)
  27513. +#define DEBUG_VALUE(d, v)
  27514. +#define DEBUG_COUNT(d)
  27515. +
  27516. +#endif /* VCHIQ_ENABLE_DEBUG */
  27517. +
  27518. +typedef enum {
  27519. + VCHIQ_CONNSTATE_DISCONNECTED,
  27520. + VCHIQ_CONNSTATE_CONNECTING,
  27521. + VCHIQ_CONNSTATE_CONNECTED,
  27522. + VCHIQ_CONNSTATE_PAUSING,
  27523. + VCHIQ_CONNSTATE_PAUSE_SENT,
  27524. + VCHIQ_CONNSTATE_PAUSED,
  27525. + VCHIQ_CONNSTATE_RESUMING,
  27526. + VCHIQ_CONNSTATE_PAUSE_TIMEOUT,
  27527. + VCHIQ_CONNSTATE_RESUME_TIMEOUT
  27528. +} VCHIQ_CONNSTATE_T;
  27529. +
  27530. +enum {
  27531. + VCHIQ_SRVSTATE_FREE,
  27532. + VCHIQ_SRVSTATE_HIDDEN,
  27533. + VCHIQ_SRVSTATE_LISTENING,
  27534. + VCHIQ_SRVSTATE_OPENING,
  27535. + VCHIQ_SRVSTATE_OPEN,
  27536. + VCHIQ_SRVSTATE_OPENSYNC,
  27537. + VCHIQ_SRVSTATE_CLOSESENT,
  27538. + VCHIQ_SRVSTATE_CLOSERECVD,
  27539. + VCHIQ_SRVSTATE_CLOSEWAIT,
  27540. + VCHIQ_SRVSTATE_CLOSED
  27541. +};
  27542. +
  27543. +enum {
  27544. + VCHIQ_POLL_TERMINATE,
  27545. + VCHIQ_POLL_REMOVE,
  27546. + VCHIQ_POLL_TXNOTIFY,
  27547. + VCHIQ_POLL_RXNOTIFY,
  27548. + VCHIQ_POLL_COUNT
  27549. +};
  27550. +
  27551. +typedef enum {
  27552. + VCHIQ_BULK_TRANSMIT,
  27553. + VCHIQ_BULK_RECEIVE
  27554. +} VCHIQ_BULK_DIR_T;
  27555. +
  27556. +typedef void (*VCHIQ_USERDATA_TERM_T)(void *userdata);
  27557. +
  27558. +typedef struct vchiq_bulk_struct {
  27559. + short mode;
  27560. + short dir;
  27561. + void *userdata;
  27562. + VCHI_MEM_HANDLE_T handle;
  27563. + void *data;
  27564. + int size;
  27565. + void *remote_data;
  27566. + int remote_size;
  27567. + int actual;
  27568. +} VCHIQ_BULK_T;
  27569. +
  27570. +typedef struct vchiq_bulk_queue_struct {
  27571. + int local_insert; /* Where to insert the next local bulk */
  27572. + int remote_insert; /* Where to insert the next remote bulk (master) */
  27573. + int process; /* Bulk to transfer next */
  27574. + int remote_notify; /* Bulk to notify the remote client of next (mstr) */
  27575. + int remove; /* Bulk to notify the local client of, and remove,
  27576. + ** next */
  27577. + VCHIQ_BULK_T bulks[VCHIQ_NUM_SERVICE_BULKS];
  27578. +} VCHIQ_BULK_QUEUE_T;
  27579. +
  27580. +typedef struct remote_event_struct {
  27581. + int armed;
  27582. + int fired;
  27583. + struct semaphore *event;
  27584. +} REMOTE_EVENT_T;
  27585. +
  27586. +typedef struct opaque_platform_state_t *VCHIQ_PLATFORM_STATE_T;
  27587. +
  27588. +typedef struct vchiq_state_struct VCHIQ_STATE_T;
  27589. +
  27590. +typedef struct vchiq_slot_struct {
  27591. + char data[VCHIQ_SLOT_SIZE];
  27592. +} VCHIQ_SLOT_T;
  27593. +
  27594. +typedef struct vchiq_slot_info_struct {
  27595. + /* Use two counters rather than one to avoid the need for a mutex. */
  27596. + short use_count;
  27597. + short release_count;
  27598. +} VCHIQ_SLOT_INFO_T;
  27599. +
  27600. +typedef struct vchiq_service_struct {
  27601. + VCHIQ_SERVICE_BASE_T base;
  27602. + VCHIQ_SERVICE_HANDLE_T handle;
  27603. + unsigned int ref_count;
  27604. + int srvstate;
  27605. + VCHIQ_USERDATA_TERM_T userdata_term;
  27606. + unsigned int localport;
  27607. + unsigned int remoteport;
  27608. + int public_fourcc;
  27609. + int client_id;
  27610. + char auto_close;
  27611. + char sync;
  27612. + char closing;
  27613. + atomic_t poll_flags;
  27614. + short version;
  27615. + short version_min;
  27616. + short peer_version;
  27617. +
  27618. + VCHIQ_STATE_T *state;
  27619. + VCHIQ_INSTANCE_T instance;
  27620. +
  27621. + int service_use_count;
  27622. +
  27623. + VCHIQ_BULK_QUEUE_T bulk_tx;
  27624. + VCHIQ_BULK_QUEUE_T bulk_rx;
  27625. +
  27626. + struct semaphore remove_event;
  27627. + struct semaphore bulk_remove_event;
  27628. + struct mutex bulk_mutex;
  27629. +
  27630. + struct service_stats_struct {
  27631. + int quota_stalls;
  27632. + int slot_stalls;
  27633. + int bulk_stalls;
  27634. + int error_count;
  27635. + int ctrl_tx_count;
  27636. + int ctrl_rx_count;
  27637. + int bulk_tx_count;
  27638. + int bulk_rx_count;
  27639. + int bulk_aborted_count;
  27640. + uint64_t ctrl_tx_bytes;
  27641. + uint64_t ctrl_rx_bytes;
  27642. + uint64_t bulk_tx_bytes;
  27643. + uint64_t bulk_rx_bytes;
  27644. + } stats;
  27645. +} VCHIQ_SERVICE_T;
  27646. +
  27647. +/* The quota information is outside VCHIQ_SERVICE_T so that it can be
  27648. + statically allocated, since for accounting reasons a service's slot
  27649. + usage is carried over between users of the same port number.
  27650. + */
  27651. +typedef struct vchiq_service_quota_struct {
  27652. + unsigned short slot_quota;
  27653. + unsigned short slot_use_count;
  27654. + unsigned short message_quota;
  27655. + unsigned short message_use_count;
  27656. + struct semaphore quota_event;
  27657. + int previous_tx_index;
  27658. +} VCHIQ_SERVICE_QUOTA_T;
  27659. +
  27660. +typedef struct vchiq_shared_state_struct {
  27661. +
  27662. + /* A non-zero value here indicates that the content is valid. */
  27663. + int initialised;
  27664. +
  27665. + /* The first and last (inclusive) slots allocated to the owner. */
  27666. + int slot_first;
  27667. + int slot_last;
  27668. +
  27669. + /* The slot allocated to synchronous messages from the owner. */
  27670. + int slot_sync;
  27671. +
  27672. + /* Signalling this event indicates that owner's slot handler thread
  27673. + ** should run. */
  27674. + REMOTE_EVENT_T trigger;
  27675. +
  27676. + /* Indicates the byte position within the stream where the next message
  27677. + ** will be written. The least significant bits are an index into the
  27678. + ** slot. The next bits are the index of the slot in slot_queue. */
  27679. + int tx_pos;
  27680. +
  27681. + /* This event should be signalled when a slot is recycled. */
  27682. + REMOTE_EVENT_T recycle;
  27683. +
  27684. + /* The slot_queue index where the next recycled slot will be written. */
  27685. + int slot_queue_recycle;
  27686. +
  27687. + /* This event should be signalled when a synchronous message is sent. */
  27688. + REMOTE_EVENT_T sync_trigger;
  27689. +
  27690. + /* This event should be signalled when a synchronous message has been
  27691. + ** released. */
  27692. + REMOTE_EVENT_T sync_release;
  27693. +
  27694. + /* A circular buffer of slot indexes. */
  27695. + int slot_queue[VCHIQ_MAX_SLOTS_PER_SIDE];
  27696. +
  27697. + /* Debugging state */
  27698. + int debug[DEBUG_MAX];
  27699. +} VCHIQ_SHARED_STATE_T;
  27700. +
  27701. +typedef struct vchiq_slot_zero_struct {
  27702. + int magic;
  27703. + short version;
  27704. + short version_min;
  27705. + int slot_zero_size;
  27706. + int slot_size;
  27707. + int max_slots;
  27708. + int max_slots_per_side;
  27709. + int platform_data[2];
  27710. + VCHIQ_SHARED_STATE_T master;
  27711. + VCHIQ_SHARED_STATE_T slave;
  27712. + VCHIQ_SLOT_INFO_T slots[VCHIQ_MAX_SLOTS];
  27713. +} VCHIQ_SLOT_ZERO_T;
  27714. +
  27715. +struct vchiq_state_struct {
  27716. + int id;
  27717. + int initialised;
  27718. + VCHIQ_CONNSTATE_T conn_state;
  27719. + int is_master;
  27720. +
  27721. + VCHIQ_SHARED_STATE_T *local;
  27722. + VCHIQ_SHARED_STATE_T *remote;
  27723. + VCHIQ_SLOT_T *slot_data;
  27724. +
  27725. + unsigned short default_slot_quota;
  27726. + unsigned short default_message_quota;
  27727. +
  27728. + /* Event indicating connect message received */
  27729. + struct semaphore connect;
  27730. +
  27731. + /* Mutex protecting services */
  27732. + struct mutex mutex;
  27733. + VCHIQ_INSTANCE_T *instance;
  27734. +
  27735. + /* Processes incoming messages */
  27736. + struct task_struct *slot_handler_thread;
  27737. +
  27738. + /* Processes recycled slots */
  27739. + struct task_struct *recycle_thread;
  27740. +
  27741. + /* Processes synchronous messages */
  27742. + struct task_struct *sync_thread;
  27743. +
  27744. + /* Local implementation of the trigger remote event */
  27745. + struct semaphore trigger_event;
  27746. +
  27747. + /* Local implementation of the recycle remote event */
  27748. + struct semaphore recycle_event;
  27749. +
  27750. + /* Local implementation of the sync trigger remote event */
  27751. + struct semaphore sync_trigger_event;
  27752. +
  27753. + /* Local implementation of the sync release remote event */
  27754. + struct semaphore sync_release_event;
  27755. +
  27756. + char *tx_data;
  27757. + char *rx_data;
  27758. + VCHIQ_SLOT_INFO_T *rx_info;
  27759. +
  27760. + struct mutex slot_mutex;
  27761. +
  27762. + struct mutex recycle_mutex;
  27763. +
  27764. + struct mutex sync_mutex;
  27765. +
  27766. + struct mutex bulk_transfer_mutex;
  27767. +
  27768. + /* Indicates the byte position within the stream from where the next
  27769. + ** message will be read. The least significant bits are an index into
  27770. + ** the slot.The next bits are the index of the slot in
  27771. + ** remote->slot_queue. */
  27772. + int rx_pos;
  27773. +
  27774. + /* A cached copy of local->tx_pos. Only write to local->tx_pos, and read
  27775. + from remote->tx_pos. */
  27776. + int local_tx_pos;
  27777. +
  27778. + /* The slot_queue index of the slot to become available next. */
  27779. + int slot_queue_available;
  27780. +
  27781. + /* A flag to indicate if any poll has been requested */
  27782. + int poll_needed;
  27783. +
  27784. + /* Ths index of the previous slot used for data messages. */
  27785. + int previous_data_index;
  27786. +
  27787. + /* The number of slots occupied by data messages. */
  27788. + unsigned short data_use_count;
  27789. +
  27790. + /* The maximum number of slots to be occupied by data messages. */
  27791. + unsigned short data_quota;
  27792. +
  27793. + /* An array of bit sets indicating which services must be polled. */
  27794. + atomic_t poll_services[BITSET_SIZE(VCHIQ_MAX_SERVICES)];
  27795. +
  27796. + /* The number of the first unused service */
  27797. + int unused_service;
  27798. +
  27799. + /* Signalled when a free slot becomes available. */
  27800. + struct semaphore slot_available_event;
  27801. +
  27802. + struct semaphore slot_remove_event;
  27803. +
  27804. + /* Signalled when a free data slot becomes available. */
  27805. + struct semaphore data_quota_event;
  27806. +
  27807. + /* Incremented when there are bulk transfers which cannot be processed
  27808. + * whilst paused and must be processed on resume */
  27809. + int deferred_bulks;
  27810. +
  27811. + struct state_stats_struct {
  27812. + int slot_stalls;
  27813. + int data_stalls;
  27814. + int ctrl_tx_count;
  27815. + int ctrl_rx_count;
  27816. + int error_count;
  27817. + } stats;
  27818. +
  27819. + VCHIQ_SERVICE_T * services[VCHIQ_MAX_SERVICES];
  27820. + VCHIQ_SERVICE_QUOTA_T service_quotas[VCHIQ_MAX_SERVICES];
  27821. + VCHIQ_SLOT_INFO_T slot_info[VCHIQ_MAX_SLOTS];
  27822. +
  27823. + VCHIQ_PLATFORM_STATE_T platform_state;
  27824. +};
  27825. +
  27826. +struct bulk_waiter {
  27827. + VCHIQ_BULK_T *bulk;
  27828. + struct semaphore event;
  27829. + int actual;
  27830. +};
  27831. +
  27832. +extern spinlock_t bulk_waiter_spinlock;
  27833. +
  27834. +extern int vchiq_core_log_level;
  27835. +extern int vchiq_core_msg_log_level;
  27836. +extern int vchiq_sync_log_level;
  27837. +
  27838. +extern VCHIQ_STATE_T *vchiq_states[VCHIQ_MAX_STATES];
  27839. +
  27840. +extern const char *
  27841. +get_conn_state_name(VCHIQ_CONNSTATE_T conn_state);
  27842. +
  27843. +extern VCHIQ_SLOT_ZERO_T *
  27844. +vchiq_init_slots(void *mem_base, int mem_size);
  27845. +
  27846. +extern VCHIQ_STATUS_T
  27847. +vchiq_init_state(VCHIQ_STATE_T *state, VCHIQ_SLOT_ZERO_T *slot_zero,
  27848. + int is_master);
  27849. +
  27850. +extern VCHIQ_STATUS_T
  27851. +vchiq_connect_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance);
  27852. +
  27853. +extern VCHIQ_SERVICE_T *
  27854. +vchiq_add_service_internal(VCHIQ_STATE_T *state,
  27855. + const VCHIQ_SERVICE_PARAMS_T *params, int srvstate,
  27856. + VCHIQ_INSTANCE_T instance, VCHIQ_USERDATA_TERM_T userdata_term);
  27857. +
  27858. +extern VCHIQ_STATUS_T
  27859. +vchiq_open_service_internal(VCHIQ_SERVICE_T *service, int client_id);
  27860. +
  27861. +extern VCHIQ_STATUS_T
  27862. +vchiq_close_service_internal(VCHIQ_SERVICE_T *service, int close_recvd);
  27863. +
  27864. +extern void
  27865. +vchiq_terminate_service_internal(VCHIQ_SERVICE_T *service);
  27866. +
  27867. +extern void
  27868. +vchiq_free_service_internal(VCHIQ_SERVICE_T *service);
  27869. +
  27870. +extern VCHIQ_STATUS_T
  27871. +vchiq_shutdown_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance);
  27872. +
  27873. +extern VCHIQ_STATUS_T
  27874. +vchiq_pause_internal(VCHIQ_STATE_T *state);
  27875. +
  27876. +extern VCHIQ_STATUS_T
  27877. +vchiq_resume_internal(VCHIQ_STATE_T *state);
  27878. +
  27879. +extern void
  27880. +remote_event_pollall(VCHIQ_STATE_T *state);
  27881. +
  27882. +extern VCHIQ_STATUS_T
  27883. +vchiq_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle,
  27884. + VCHI_MEM_HANDLE_T memhandle, void *offset, int size, void *userdata,
  27885. + VCHIQ_BULK_MODE_T mode, VCHIQ_BULK_DIR_T dir);
  27886. +
  27887. +extern void
  27888. +vchiq_dump_state(void *dump_context, VCHIQ_STATE_T *state);
  27889. +
  27890. +extern void
  27891. +vchiq_dump_service_state(void *dump_context, VCHIQ_SERVICE_T *service);
  27892. +
  27893. +extern void
  27894. +vchiq_loud_error_header(void);
  27895. +
  27896. +extern void
  27897. +vchiq_loud_error_footer(void);
  27898. +
  27899. +extern void
  27900. +request_poll(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service, int poll_type);
  27901. +
  27902. +static inline VCHIQ_SERVICE_T *
  27903. +handle_to_service(VCHIQ_SERVICE_HANDLE_T handle)
  27904. +{
  27905. + VCHIQ_STATE_T *state = vchiq_states[(handle / VCHIQ_MAX_SERVICES) &
  27906. + (VCHIQ_MAX_STATES - 1)];
  27907. + if (!state)
  27908. + return NULL;
  27909. +
  27910. + return state->services[handle & (VCHIQ_MAX_SERVICES - 1)];
  27911. +}
  27912. +
  27913. +extern VCHIQ_SERVICE_T *
  27914. +find_service_by_handle(VCHIQ_SERVICE_HANDLE_T handle);
  27915. +
  27916. +extern VCHIQ_SERVICE_T *
  27917. +find_service_by_port(VCHIQ_STATE_T *state, int localport);
  27918. +
  27919. +extern VCHIQ_SERVICE_T *
  27920. +find_service_for_instance(VCHIQ_INSTANCE_T instance,
  27921. + VCHIQ_SERVICE_HANDLE_T handle);
  27922. +
  27923. +extern VCHIQ_SERVICE_T *
  27924. +next_service_by_instance(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance,
  27925. + int *pidx);
  27926. +
  27927. +extern void
  27928. +lock_service(VCHIQ_SERVICE_T *service);
  27929. +
  27930. +extern void
  27931. +unlock_service(VCHIQ_SERVICE_T *service);
  27932. +
  27933. +/* The following functions are called from vchiq_core, and external
  27934. +** implementations must be provided. */
  27935. +
  27936. +extern VCHIQ_STATUS_T
  27937. +vchiq_prepare_bulk_data(VCHIQ_BULK_T *bulk,
  27938. + VCHI_MEM_HANDLE_T memhandle, void *offset, int size, int dir);
  27939. +
  27940. +extern void
  27941. +vchiq_transfer_bulk(VCHIQ_BULK_T *bulk);
  27942. +
  27943. +extern void
  27944. +vchiq_complete_bulk(VCHIQ_BULK_T *bulk);
  27945. +
  27946. +extern VCHIQ_STATUS_T
  27947. +vchiq_copy_from_user(void *dst, const void *src, int size);
  27948. +
  27949. +extern void
  27950. +remote_event_signal(REMOTE_EVENT_T *event);
  27951. +
  27952. +void
  27953. +vchiq_platform_check_suspend(VCHIQ_STATE_T *state);
  27954. +
  27955. +extern void
  27956. +vchiq_platform_paused(VCHIQ_STATE_T *state);
  27957. +
  27958. +extern VCHIQ_STATUS_T
  27959. +vchiq_platform_resume(VCHIQ_STATE_T *state);
  27960. +
  27961. +extern void
  27962. +vchiq_platform_resumed(VCHIQ_STATE_T *state);
  27963. +
  27964. +extern void
  27965. +vchiq_dump(void *dump_context, const char *str, int len);
  27966. +
  27967. +extern void
  27968. +vchiq_dump_platform_state(void *dump_context);
  27969. +
  27970. +extern void
  27971. +vchiq_dump_platform_instances(void *dump_context);
  27972. +
  27973. +extern void
  27974. +vchiq_dump_platform_service_state(void *dump_context,
  27975. + VCHIQ_SERVICE_T *service);
  27976. +
  27977. +extern VCHIQ_STATUS_T
  27978. +vchiq_use_service_internal(VCHIQ_SERVICE_T *service);
  27979. +
  27980. +extern VCHIQ_STATUS_T
  27981. +vchiq_release_service_internal(VCHIQ_SERVICE_T *service);
  27982. +
  27983. +extern void
  27984. +vchiq_on_remote_use(VCHIQ_STATE_T *state);
  27985. +
  27986. +extern void
  27987. +vchiq_on_remote_release(VCHIQ_STATE_T *state);
  27988. +
  27989. +extern VCHIQ_STATUS_T
  27990. +vchiq_platform_init_state(VCHIQ_STATE_T *state);
  27991. +
  27992. +extern VCHIQ_STATUS_T
  27993. +vchiq_check_service(VCHIQ_SERVICE_T *service);
  27994. +
  27995. +extern void
  27996. +vchiq_on_remote_use_active(VCHIQ_STATE_T *state);
  27997. +
  27998. +extern VCHIQ_STATUS_T
  27999. +vchiq_send_remote_use(VCHIQ_STATE_T *state);
  28000. +
  28001. +extern VCHIQ_STATUS_T
  28002. +vchiq_send_remote_release(VCHIQ_STATE_T *state);
  28003. +
  28004. +extern VCHIQ_STATUS_T
  28005. +vchiq_send_remote_use_active(VCHIQ_STATE_T *state);
  28006. +
  28007. +extern void
  28008. +vchiq_platform_conn_state_changed(VCHIQ_STATE_T *state,
  28009. + VCHIQ_CONNSTATE_T oldstate, VCHIQ_CONNSTATE_T newstate);
  28010. +
  28011. +extern void
  28012. +vchiq_platform_handle_timeout(VCHIQ_STATE_T *state);
  28013. +
  28014. +extern void
  28015. +vchiq_set_conn_state(VCHIQ_STATE_T *state, VCHIQ_CONNSTATE_T newstate);
  28016. +
  28017. +
  28018. +extern void
  28019. +vchiq_log_dump_mem(const char *label, uint32_t addr, const void *voidMem,
  28020. + size_t numBytes);
  28021. +
  28022. +#endif
  28023. diff -Nur linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion
  28024. --- linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion 1970-01-01 01:00:00.000000000 +0100
  28025. +++ linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion 2014-08-06 16:50:14.493962307 +0200
  28026. @@ -0,0 +1,87 @@
  28027. +#!/usr/bin/perl -w
  28028. +
  28029. +use strict;
  28030. +
  28031. +#
  28032. +# Generate a version from available information
  28033. +#
  28034. +
  28035. +my $prefix = shift @ARGV;
  28036. +my $root = shift @ARGV;
  28037. +
  28038. +
  28039. +if ( not defined $root ) {
  28040. + die "usage: $0 prefix root-dir\n";
  28041. +}
  28042. +
  28043. +if ( ! -d $root ) {
  28044. + die "root directory $root not found\n";
  28045. +}
  28046. +
  28047. +my $version = "unknown";
  28048. +my $tainted = "";
  28049. +
  28050. +if ( -d "$root/.git" ) {
  28051. + # attempt to work out git version. only do so
  28052. + # on a linux build host, as cygwin builds are
  28053. + # already slow enough
  28054. +
  28055. + if ( -f "/usr/bin/git" || -f "/usr/local/bin/git" ) {
  28056. + if (not open(F, "git --git-dir $root/.git rev-parse --verify HEAD|")) {
  28057. + $version = "no git version";
  28058. + }
  28059. + else {
  28060. + $version = <F>;
  28061. + $version =~ s/[ \r\n]*$//; # chomp may not be enough (cygwin).
  28062. + $version =~ s/^[ \r\n]*//; # chomp may not be enough (cygwin).
  28063. + }
  28064. +
  28065. + if (open(G, "git --git-dir $root/.git status --porcelain|")) {
  28066. + $tainted = <G>;
  28067. + $tainted =~ s/[ \r\n]*$//; # chomp may not be enough (cygwin).
  28068. + $tainted =~ s/^[ \r\n]*//; # chomp may not be enough (cygwin).
  28069. + if (length $tainted) {
  28070. + $version = join ' ', $version, "(tainted)";
  28071. + }
  28072. + else {
  28073. + $version = join ' ', $version, "(clean)";
  28074. + }
  28075. + }
  28076. + }
  28077. +}
  28078. +
  28079. +my $hostname = `hostname`;
  28080. +$hostname =~ s/[ \r\n]*$//; # chomp may not be enough (cygwin).
  28081. +$hostname =~ s/^[ \r\n]*//; # chomp may not be enough (cygwin).
  28082. +
  28083. +
  28084. +print STDERR "Version $version\n";
  28085. +print <<EOF;
  28086. +#include "${prefix}_build_info.h"
  28087. +#include <linux/broadcom/vc_debug_sym.h>
  28088. +
  28089. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_hostname, "$hostname" );
  28090. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_version, "$version" );
  28091. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_time, __TIME__ );
  28092. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_date, __DATE__ );
  28093. +
  28094. +const char *vchiq_get_build_hostname( void )
  28095. +{
  28096. + return vchiq_build_hostname;
  28097. +}
  28098. +
  28099. +const char *vchiq_get_build_version( void )
  28100. +{
  28101. + return vchiq_build_version;
  28102. +}
  28103. +
  28104. +const char *vchiq_get_build_date( void )
  28105. +{
  28106. + return vchiq_build_date;
  28107. +}
  28108. +
  28109. +const char *vchiq_get_build_time( void )
  28110. +{
  28111. + return vchiq_build_time;
  28112. +}
  28113. +EOF
  28114. diff -Nur linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h
  28115. --- linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h 1970-01-01 01:00:00.000000000 +0100
  28116. +++ linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h 2014-08-06 16:50:14.493962307 +0200
  28117. @@ -0,0 +1,40 @@
  28118. +/**
  28119. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  28120. + *
  28121. + * Redistribution and use in source and binary forms, with or without
  28122. + * modification, are permitted provided that the following conditions
  28123. + * are met:
  28124. + * 1. Redistributions of source code must retain the above copyright
  28125. + * notice, this list of conditions, and the following disclaimer,
  28126. + * without modification.
  28127. + * 2. Redistributions in binary form must reproduce the above copyright
  28128. + * notice, this list of conditions and the following disclaimer in the
  28129. + * documentation and/or other materials provided with the distribution.
  28130. + * 3. The names of the above-listed copyright holders may not be used
  28131. + * to endorse or promote products derived from this software without
  28132. + * specific prior written permission.
  28133. + *
  28134. + * ALTERNATIVELY, this software may be distributed under the terms of the
  28135. + * GNU General Public License ("GPL") version 2, as published by the Free
  28136. + * Software Foundation.
  28137. + *
  28138. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  28139. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  28140. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  28141. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  28142. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28143. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  28144. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28145. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28146. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28147. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28148. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28149. + */
  28150. +
  28151. +#ifndef VCHIQ_VCHIQ_H
  28152. +#define VCHIQ_VCHIQ_H
  28153. +
  28154. +#include "vchiq_if.h"
  28155. +#include "vchiq_util.h"
  28156. +
  28157. +#endif
  28158. diff -Nur linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h
  28159. --- linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h 1970-01-01 01:00:00.000000000 +0100
  28160. +++ linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h 2014-08-06 16:50:14.493962307 +0200
  28161. @@ -0,0 +1,188 @@
  28162. +/**
  28163. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  28164. + *
  28165. + * Redistribution and use in source and binary forms, with or without
  28166. + * modification, are permitted provided that the following conditions
  28167. + * are met:
  28168. + * 1. Redistributions of source code must retain the above copyright
  28169. + * notice, this list of conditions, and the following disclaimer,
  28170. + * without modification.
  28171. + * 2. Redistributions in binary form must reproduce the above copyright
  28172. + * notice, this list of conditions and the following disclaimer in the
  28173. + * documentation and/or other materials provided with the distribution.
  28174. + * 3. The names of the above-listed copyright holders may not be used
  28175. + * to endorse or promote products derived from this software without
  28176. + * specific prior written permission.
  28177. + *
  28178. + * ALTERNATIVELY, this software may be distributed under the terms of the
  28179. + * GNU General Public License ("GPL") version 2, as published by the Free
  28180. + * Software Foundation.
  28181. + *
  28182. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  28183. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  28184. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  28185. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  28186. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28187. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  28188. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28189. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28190. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28191. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28192. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28193. + */
  28194. +
  28195. +#ifndef VCHIQ_IF_H
  28196. +#define VCHIQ_IF_H
  28197. +
  28198. +#include "interface/vchi/vchi_mh.h"
  28199. +
  28200. +#define VCHIQ_SERVICE_HANDLE_INVALID 0
  28201. +
  28202. +#define VCHIQ_SLOT_SIZE 4096
  28203. +#define VCHIQ_MAX_MSG_SIZE (VCHIQ_SLOT_SIZE - sizeof(VCHIQ_HEADER_T))
  28204. +#define VCHIQ_CHANNEL_SIZE VCHIQ_MAX_MSG_SIZE /* For backwards compatibility */
  28205. +
  28206. +#define VCHIQ_MAKE_FOURCC(x0, x1, x2, x3) \
  28207. + (((x0) << 24) | ((x1) << 16) | ((x2) << 8) | (x3))
  28208. +#define VCHIQ_GET_SERVICE_USERDATA(service) vchiq_get_service_userdata(service)
  28209. +#define VCHIQ_GET_SERVICE_FOURCC(service) vchiq_get_service_fourcc(service)
  28210. +
  28211. +typedef enum {
  28212. + VCHIQ_SERVICE_OPENED, /* service, -, - */
  28213. + VCHIQ_SERVICE_CLOSED, /* service, -, - */
  28214. + VCHIQ_MESSAGE_AVAILABLE, /* service, header, - */
  28215. + VCHIQ_BULK_TRANSMIT_DONE, /* service, -, bulk_userdata */
  28216. + VCHIQ_BULK_RECEIVE_DONE, /* service, -, bulk_userdata */
  28217. + VCHIQ_BULK_TRANSMIT_ABORTED, /* service, -, bulk_userdata */
  28218. + VCHIQ_BULK_RECEIVE_ABORTED /* service, -, bulk_userdata */
  28219. +} VCHIQ_REASON_T;
  28220. +
  28221. +typedef enum {
  28222. + VCHIQ_ERROR = -1,
  28223. + VCHIQ_SUCCESS = 0,
  28224. + VCHIQ_RETRY = 1
  28225. +} VCHIQ_STATUS_T;
  28226. +
  28227. +typedef enum {
  28228. + VCHIQ_BULK_MODE_CALLBACK,
  28229. + VCHIQ_BULK_MODE_BLOCKING,
  28230. + VCHIQ_BULK_MODE_NOCALLBACK,
  28231. + VCHIQ_BULK_MODE_WAITING /* Reserved for internal use */
  28232. +} VCHIQ_BULK_MODE_T;
  28233. +
  28234. +typedef enum {
  28235. + VCHIQ_SERVICE_OPTION_AUTOCLOSE,
  28236. + VCHIQ_SERVICE_OPTION_SLOT_QUOTA,
  28237. + VCHIQ_SERVICE_OPTION_MESSAGE_QUOTA,
  28238. + VCHIQ_SERVICE_OPTION_SYNCHRONOUS
  28239. +} VCHIQ_SERVICE_OPTION_T;
  28240. +
  28241. +typedef struct vchiq_header_struct {
  28242. + /* The message identifier - opaque to applications. */
  28243. + int msgid;
  28244. +
  28245. + /* Size of message data. */
  28246. + unsigned int size;
  28247. +
  28248. + char data[0]; /* message */
  28249. +} VCHIQ_HEADER_T;
  28250. +
  28251. +typedef struct {
  28252. + const void *data;
  28253. + unsigned int size;
  28254. +} VCHIQ_ELEMENT_T;
  28255. +
  28256. +typedef unsigned int VCHIQ_SERVICE_HANDLE_T;
  28257. +
  28258. +typedef VCHIQ_STATUS_T (*VCHIQ_CALLBACK_T)(VCHIQ_REASON_T, VCHIQ_HEADER_T *,
  28259. + VCHIQ_SERVICE_HANDLE_T, void *);
  28260. +
  28261. +typedef struct vchiq_service_base_struct {
  28262. + int fourcc;
  28263. + VCHIQ_CALLBACK_T callback;
  28264. + void *userdata;
  28265. +} VCHIQ_SERVICE_BASE_T;
  28266. +
  28267. +typedef struct vchiq_service_params_struct {
  28268. + int fourcc;
  28269. + VCHIQ_CALLBACK_T callback;
  28270. + void *userdata;
  28271. + short version; /* Increment for non-trivial changes */
  28272. + short version_min; /* Update for incompatible changes */
  28273. +} VCHIQ_SERVICE_PARAMS_T;
  28274. +
  28275. +typedef struct vchiq_config_struct {
  28276. + unsigned int max_msg_size;
  28277. + unsigned int bulk_threshold; /* The message size above which it
  28278. + is better to use a bulk transfer
  28279. + (<= max_msg_size) */
  28280. + unsigned int max_outstanding_bulks;
  28281. + unsigned int max_services;
  28282. + short version; /* The version of VCHIQ */
  28283. + short version_min; /* The minimum compatible version of VCHIQ */
  28284. +} VCHIQ_CONFIG_T;
  28285. +
  28286. +typedef struct vchiq_instance_struct *VCHIQ_INSTANCE_T;
  28287. +typedef void (*VCHIQ_REMOTE_USE_CALLBACK_T)(void *cb_arg);
  28288. +
  28289. +extern VCHIQ_STATUS_T vchiq_initialise(VCHIQ_INSTANCE_T *pinstance);
  28290. +extern VCHIQ_STATUS_T vchiq_shutdown(VCHIQ_INSTANCE_T instance);
  28291. +extern VCHIQ_STATUS_T vchiq_connect(VCHIQ_INSTANCE_T instance);
  28292. +extern VCHIQ_STATUS_T vchiq_add_service(VCHIQ_INSTANCE_T instance,
  28293. + const VCHIQ_SERVICE_PARAMS_T *params,
  28294. + VCHIQ_SERVICE_HANDLE_T *pservice);
  28295. +extern VCHIQ_STATUS_T vchiq_open_service(VCHIQ_INSTANCE_T instance,
  28296. + const VCHIQ_SERVICE_PARAMS_T *params,
  28297. + VCHIQ_SERVICE_HANDLE_T *pservice);
  28298. +extern VCHIQ_STATUS_T vchiq_close_service(VCHIQ_SERVICE_HANDLE_T service);
  28299. +extern VCHIQ_STATUS_T vchiq_remove_service(VCHIQ_SERVICE_HANDLE_T service);
  28300. +extern VCHIQ_STATUS_T vchiq_use_service(VCHIQ_SERVICE_HANDLE_T service);
  28301. +extern VCHIQ_STATUS_T vchiq_use_service_no_resume(
  28302. + VCHIQ_SERVICE_HANDLE_T service);
  28303. +extern VCHIQ_STATUS_T vchiq_release_service(VCHIQ_SERVICE_HANDLE_T service);
  28304. +
  28305. +extern VCHIQ_STATUS_T vchiq_queue_message(VCHIQ_SERVICE_HANDLE_T service,
  28306. + const VCHIQ_ELEMENT_T *elements, unsigned int count);
  28307. +extern void vchiq_release_message(VCHIQ_SERVICE_HANDLE_T service,
  28308. + VCHIQ_HEADER_T *header);
  28309. +extern VCHIQ_STATUS_T vchiq_queue_bulk_transmit(VCHIQ_SERVICE_HANDLE_T service,
  28310. + const void *data, unsigned int size, void *userdata);
  28311. +extern VCHIQ_STATUS_T vchiq_queue_bulk_receive(VCHIQ_SERVICE_HANDLE_T service,
  28312. + void *data, unsigned int size, void *userdata);
  28313. +extern VCHIQ_STATUS_T vchiq_queue_bulk_transmit_handle(
  28314. + VCHIQ_SERVICE_HANDLE_T service, VCHI_MEM_HANDLE_T handle,
  28315. + const void *offset, unsigned int size, void *userdata);
  28316. +extern VCHIQ_STATUS_T vchiq_queue_bulk_receive_handle(
  28317. + VCHIQ_SERVICE_HANDLE_T service, VCHI_MEM_HANDLE_T handle,
  28318. + void *offset, unsigned int size, void *userdata);
  28319. +extern VCHIQ_STATUS_T vchiq_bulk_transmit(VCHIQ_SERVICE_HANDLE_T service,
  28320. + const void *data, unsigned int size, void *userdata,
  28321. + VCHIQ_BULK_MODE_T mode);
  28322. +extern VCHIQ_STATUS_T vchiq_bulk_receive(VCHIQ_SERVICE_HANDLE_T service,
  28323. + void *data, unsigned int size, void *userdata,
  28324. + VCHIQ_BULK_MODE_T mode);
  28325. +extern VCHIQ_STATUS_T vchiq_bulk_transmit_handle(VCHIQ_SERVICE_HANDLE_T service,
  28326. + VCHI_MEM_HANDLE_T handle, const void *offset, unsigned int size,
  28327. + void *userdata, VCHIQ_BULK_MODE_T mode);
  28328. +extern VCHIQ_STATUS_T vchiq_bulk_receive_handle(VCHIQ_SERVICE_HANDLE_T service,
  28329. + VCHI_MEM_HANDLE_T handle, void *offset, unsigned int size,
  28330. + void *userdata, VCHIQ_BULK_MODE_T mode);
  28331. +extern int vchiq_get_client_id(VCHIQ_SERVICE_HANDLE_T service);
  28332. +extern void *vchiq_get_service_userdata(VCHIQ_SERVICE_HANDLE_T service);
  28333. +extern int vchiq_get_service_fourcc(VCHIQ_SERVICE_HANDLE_T service);
  28334. +extern VCHIQ_STATUS_T vchiq_get_config(VCHIQ_INSTANCE_T instance,
  28335. + int config_size, VCHIQ_CONFIG_T *pconfig);
  28336. +extern VCHIQ_STATUS_T vchiq_set_service_option(VCHIQ_SERVICE_HANDLE_T service,
  28337. + VCHIQ_SERVICE_OPTION_T option, int value);
  28338. +
  28339. +extern VCHIQ_STATUS_T vchiq_remote_use(VCHIQ_INSTANCE_T instance,
  28340. + VCHIQ_REMOTE_USE_CALLBACK_T callback, void *cb_arg);
  28341. +extern VCHIQ_STATUS_T vchiq_remote_release(VCHIQ_INSTANCE_T instance);
  28342. +
  28343. +extern VCHIQ_STATUS_T vchiq_dump_phys_mem(VCHIQ_SERVICE_HANDLE_T service,
  28344. + void *ptr, size_t num_bytes);
  28345. +
  28346. +extern VCHIQ_STATUS_T vchiq_get_peer_version(VCHIQ_SERVICE_HANDLE_T handle,
  28347. + short *peer_version);
  28348. +
  28349. +#endif /* VCHIQ_IF_H */
  28350. diff -Nur linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h
  28351. --- linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h 1970-01-01 01:00:00.000000000 +0100
  28352. +++ linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h 2014-08-06 16:50:14.493962307 +0200
  28353. @@ -0,0 +1,129 @@
  28354. +/**
  28355. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  28356. + *
  28357. + * Redistribution and use in source and binary forms, with or without
  28358. + * modification, are permitted provided that the following conditions
  28359. + * are met:
  28360. + * 1. Redistributions of source code must retain the above copyright
  28361. + * notice, this list of conditions, and the following disclaimer,
  28362. + * without modification.
  28363. + * 2. Redistributions in binary form must reproduce the above copyright
  28364. + * notice, this list of conditions and the following disclaimer in the
  28365. + * documentation and/or other materials provided with the distribution.
  28366. + * 3. The names of the above-listed copyright holders may not be used
  28367. + * to endorse or promote products derived from this software without
  28368. + * specific prior written permission.
  28369. + *
  28370. + * ALTERNATIVELY, this software may be distributed under the terms of the
  28371. + * GNU General Public License ("GPL") version 2, as published by the Free
  28372. + * Software Foundation.
  28373. + *
  28374. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  28375. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  28376. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  28377. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  28378. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28379. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  28380. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28381. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28382. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28383. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28384. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28385. + */
  28386. +
  28387. +#ifndef VCHIQ_IOCTLS_H
  28388. +#define VCHIQ_IOCTLS_H
  28389. +
  28390. +#include <linux/ioctl.h>
  28391. +#include "vchiq_if.h"
  28392. +
  28393. +#define VCHIQ_IOC_MAGIC 0xc4
  28394. +#define VCHIQ_INVALID_HANDLE (~0)
  28395. +
  28396. +typedef struct {
  28397. + VCHIQ_SERVICE_PARAMS_T params;
  28398. + int is_open;
  28399. + int is_vchi;
  28400. + unsigned int handle; /* OUT */
  28401. +} VCHIQ_CREATE_SERVICE_T;
  28402. +
  28403. +typedef struct {
  28404. + unsigned int handle;
  28405. + unsigned int count;
  28406. + const VCHIQ_ELEMENT_T *elements;
  28407. +} VCHIQ_QUEUE_MESSAGE_T;
  28408. +
  28409. +typedef struct {
  28410. + unsigned int handle;
  28411. + void *data;
  28412. + unsigned int size;
  28413. + void *userdata;
  28414. + VCHIQ_BULK_MODE_T mode;
  28415. +} VCHIQ_QUEUE_BULK_TRANSFER_T;
  28416. +
  28417. +typedef struct {
  28418. + VCHIQ_REASON_T reason;
  28419. + VCHIQ_HEADER_T *header;
  28420. + void *service_userdata;
  28421. + void *bulk_userdata;
  28422. +} VCHIQ_COMPLETION_DATA_T;
  28423. +
  28424. +typedef struct {
  28425. + unsigned int count;
  28426. + VCHIQ_COMPLETION_DATA_T *buf;
  28427. + unsigned int msgbufsize;
  28428. + unsigned int msgbufcount; /* IN/OUT */
  28429. + void **msgbufs;
  28430. +} VCHIQ_AWAIT_COMPLETION_T;
  28431. +
  28432. +typedef struct {
  28433. + unsigned int handle;
  28434. + int blocking;
  28435. + unsigned int bufsize;
  28436. + void *buf;
  28437. +} VCHIQ_DEQUEUE_MESSAGE_T;
  28438. +
  28439. +typedef struct {
  28440. + unsigned int config_size;
  28441. + VCHIQ_CONFIG_T *pconfig;
  28442. +} VCHIQ_GET_CONFIG_T;
  28443. +
  28444. +typedef struct {
  28445. + unsigned int handle;
  28446. + VCHIQ_SERVICE_OPTION_T option;
  28447. + int value;
  28448. +} VCHIQ_SET_SERVICE_OPTION_T;
  28449. +
  28450. +typedef struct {
  28451. + void *virt_addr;
  28452. + size_t num_bytes;
  28453. +} VCHIQ_DUMP_MEM_T;
  28454. +
  28455. +#define VCHIQ_IOC_CONNECT _IO(VCHIQ_IOC_MAGIC, 0)
  28456. +#define VCHIQ_IOC_SHUTDOWN _IO(VCHIQ_IOC_MAGIC, 1)
  28457. +#define VCHIQ_IOC_CREATE_SERVICE \
  28458. + _IOWR(VCHIQ_IOC_MAGIC, 2, VCHIQ_CREATE_SERVICE_T)
  28459. +#define VCHIQ_IOC_REMOVE_SERVICE _IO(VCHIQ_IOC_MAGIC, 3)
  28460. +#define VCHIQ_IOC_QUEUE_MESSAGE \
  28461. + _IOW(VCHIQ_IOC_MAGIC, 4, VCHIQ_QUEUE_MESSAGE_T)
  28462. +#define VCHIQ_IOC_QUEUE_BULK_TRANSMIT \
  28463. + _IOWR(VCHIQ_IOC_MAGIC, 5, VCHIQ_QUEUE_BULK_TRANSFER_T)
  28464. +#define VCHIQ_IOC_QUEUE_BULK_RECEIVE \
  28465. + _IOWR(VCHIQ_IOC_MAGIC, 6, VCHIQ_QUEUE_BULK_TRANSFER_T)
  28466. +#define VCHIQ_IOC_AWAIT_COMPLETION \
  28467. + _IOWR(VCHIQ_IOC_MAGIC, 7, VCHIQ_AWAIT_COMPLETION_T)
  28468. +#define VCHIQ_IOC_DEQUEUE_MESSAGE \
  28469. + _IOWR(VCHIQ_IOC_MAGIC, 8, VCHIQ_DEQUEUE_MESSAGE_T)
  28470. +#define VCHIQ_IOC_GET_CLIENT_ID _IO(VCHIQ_IOC_MAGIC, 9)
  28471. +#define VCHIQ_IOC_GET_CONFIG \
  28472. + _IOWR(VCHIQ_IOC_MAGIC, 10, VCHIQ_GET_CONFIG_T)
  28473. +#define VCHIQ_IOC_CLOSE_SERVICE _IO(VCHIQ_IOC_MAGIC, 11)
  28474. +#define VCHIQ_IOC_USE_SERVICE _IO(VCHIQ_IOC_MAGIC, 12)
  28475. +#define VCHIQ_IOC_RELEASE_SERVICE _IO(VCHIQ_IOC_MAGIC, 13)
  28476. +#define VCHIQ_IOC_SET_SERVICE_OPTION \
  28477. + _IOW(VCHIQ_IOC_MAGIC, 14, VCHIQ_SET_SERVICE_OPTION_T)
  28478. +#define VCHIQ_IOC_DUMP_PHYS_MEM \
  28479. + _IOW(VCHIQ_IOC_MAGIC, 15, VCHIQ_DUMP_MEM_T)
  28480. +#define VCHIQ_IOC_MAX 15
  28481. +
  28482. +#endif
  28483. diff -Nur linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c
  28484. --- linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c 1970-01-01 01:00:00.000000000 +0100
  28485. +++ linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c 2014-08-06 16:50:14.493962307 +0200
  28486. @@ -0,0 +1,456 @@
  28487. +/**
  28488. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  28489. + *
  28490. + * Redistribution and use in source and binary forms, with or without
  28491. + * modification, are permitted provided that the following conditions
  28492. + * are met:
  28493. + * 1. Redistributions of source code must retain the above copyright
  28494. + * notice, this list of conditions, and the following disclaimer,
  28495. + * without modification.
  28496. + * 2. Redistributions in binary form must reproduce the above copyright
  28497. + * notice, this list of conditions and the following disclaimer in the
  28498. + * documentation and/or other materials provided with the distribution.
  28499. + * 3. The names of the above-listed copyright holders may not be used
  28500. + * to endorse or promote products derived from this software without
  28501. + * specific prior written permission.
  28502. + *
  28503. + * ALTERNATIVELY, this software may be distributed under the terms of the
  28504. + * GNU General Public License ("GPL") version 2, as published by the Free
  28505. + * Software Foundation.
  28506. + *
  28507. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  28508. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  28509. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  28510. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  28511. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28512. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  28513. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28514. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28515. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28516. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28517. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28518. + */
  28519. +
  28520. +/* ---- Include Files ---------------------------------------------------- */
  28521. +
  28522. +#include <linux/kernel.h>
  28523. +#include <linux/module.h>
  28524. +#include <linux/mutex.h>
  28525. +
  28526. +#include "vchiq_core.h"
  28527. +#include "vchiq_arm.h"
  28528. +
  28529. +/* ---- Public Variables ------------------------------------------------- */
  28530. +
  28531. +/* ---- Private Constants and Types -------------------------------------- */
  28532. +
  28533. +struct bulk_waiter_node {
  28534. + struct bulk_waiter bulk_waiter;
  28535. + int pid;
  28536. + struct list_head list;
  28537. +};
  28538. +
  28539. +struct vchiq_instance_struct {
  28540. + VCHIQ_STATE_T *state;
  28541. +
  28542. + int connected;
  28543. +
  28544. + struct list_head bulk_waiter_list;
  28545. + struct mutex bulk_waiter_list_mutex;
  28546. +};
  28547. +
  28548. +static VCHIQ_STATUS_T
  28549. +vchiq_blocking_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  28550. + unsigned int size, VCHIQ_BULK_DIR_T dir);
  28551. +
  28552. +/****************************************************************************
  28553. +*
  28554. +* vchiq_initialise
  28555. +*
  28556. +***************************************************************************/
  28557. +#define VCHIQ_INIT_RETRIES 10
  28558. +VCHIQ_STATUS_T vchiq_initialise(VCHIQ_INSTANCE_T *instanceOut)
  28559. +{
  28560. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  28561. + VCHIQ_STATE_T *state;
  28562. + VCHIQ_INSTANCE_T instance = NULL;
  28563. + int i;
  28564. +
  28565. + vchiq_log_trace(vchiq_core_log_level, "%s called", __func__);
  28566. +
  28567. + /* VideoCore may not be ready due to boot up timing.
  28568. + It may never be ready if kernel and firmware are mismatched, so don't block forever. */
  28569. + for (i=0; i<VCHIQ_INIT_RETRIES; i++) {
  28570. + state = vchiq_get_state();
  28571. + if (state)
  28572. + break;
  28573. + udelay(500);
  28574. + }
  28575. + if (i==VCHIQ_INIT_RETRIES) {
  28576. + vchiq_log_error(vchiq_core_log_level,
  28577. + "%s: videocore not initialized\n", __func__);
  28578. + goto failed;
  28579. + } else if (i>0) {
  28580. + vchiq_log_warning(vchiq_core_log_level,
  28581. + "%s: videocore initialized after %d retries\n", __func__, i);
  28582. + }
  28583. +
  28584. + instance = kzalloc(sizeof(*instance), GFP_KERNEL);
  28585. + if (!instance) {
  28586. + vchiq_log_error(vchiq_core_log_level,
  28587. + "%s: error allocating vchiq instance\n", __func__);
  28588. + goto failed;
  28589. + }
  28590. +
  28591. + instance->connected = 0;
  28592. + instance->state = state;
  28593. + mutex_init(&instance->bulk_waiter_list_mutex);
  28594. + INIT_LIST_HEAD(&instance->bulk_waiter_list);
  28595. +
  28596. + *instanceOut = instance;
  28597. +
  28598. + status = VCHIQ_SUCCESS;
  28599. +
  28600. +failed:
  28601. + vchiq_log_trace(vchiq_core_log_level,
  28602. + "%s(%p): returning %d", __func__, instance, status);
  28603. +
  28604. + return status;
  28605. +}
  28606. +EXPORT_SYMBOL(vchiq_initialise);
  28607. +
  28608. +/****************************************************************************
  28609. +*
  28610. +* vchiq_shutdown
  28611. +*
  28612. +***************************************************************************/
  28613. +
  28614. +VCHIQ_STATUS_T vchiq_shutdown(VCHIQ_INSTANCE_T instance)
  28615. +{
  28616. + VCHIQ_STATUS_T status;
  28617. + VCHIQ_STATE_T *state = instance->state;
  28618. +
  28619. + vchiq_log_trace(vchiq_core_log_level,
  28620. + "%s(%p) called", __func__, instance);
  28621. +
  28622. + if (mutex_lock_interruptible(&state->mutex) != 0)
  28623. + return VCHIQ_RETRY;
  28624. +
  28625. + /* Remove all services */
  28626. + status = vchiq_shutdown_internal(state, instance);
  28627. +
  28628. + mutex_unlock(&state->mutex);
  28629. +
  28630. + vchiq_log_trace(vchiq_core_log_level,
  28631. + "%s(%p): returning %d", __func__, instance, status);
  28632. +
  28633. + if (status == VCHIQ_SUCCESS) {
  28634. + struct list_head *pos, *next;
  28635. + list_for_each_safe(pos, next,
  28636. + &instance->bulk_waiter_list) {
  28637. + struct bulk_waiter_node *waiter;
  28638. + waiter = list_entry(pos,
  28639. + struct bulk_waiter_node,
  28640. + list);
  28641. + list_del(pos);
  28642. + vchiq_log_info(vchiq_arm_log_level,
  28643. + "bulk_waiter - cleaned up %x "
  28644. + "for pid %d",
  28645. + (unsigned int)waiter, waiter->pid);
  28646. + kfree(waiter);
  28647. + }
  28648. + kfree(instance);
  28649. + }
  28650. +
  28651. + return status;
  28652. +}
  28653. +EXPORT_SYMBOL(vchiq_shutdown);
  28654. +
  28655. +/****************************************************************************
  28656. +*
  28657. +* vchiq_is_connected
  28658. +*
  28659. +***************************************************************************/
  28660. +
  28661. +int vchiq_is_connected(VCHIQ_INSTANCE_T instance)
  28662. +{
  28663. + return instance->connected;
  28664. +}
  28665. +
  28666. +/****************************************************************************
  28667. +*
  28668. +* vchiq_connect
  28669. +*
  28670. +***************************************************************************/
  28671. +
  28672. +VCHIQ_STATUS_T vchiq_connect(VCHIQ_INSTANCE_T instance)
  28673. +{
  28674. + VCHIQ_STATUS_T status;
  28675. + VCHIQ_STATE_T *state = instance->state;
  28676. +
  28677. + vchiq_log_trace(vchiq_core_log_level,
  28678. + "%s(%p) called", __func__, instance);
  28679. +
  28680. + if (mutex_lock_interruptible(&state->mutex) != 0) {
  28681. + vchiq_log_trace(vchiq_core_log_level,
  28682. + "%s: call to mutex_lock failed", __func__);
  28683. + status = VCHIQ_RETRY;
  28684. + goto failed;
  28685. + }
  28686. + status = vchiq_connect_internal(state, instance);
  28687. +
  28688. + if (status == VCHIQ_SUCCESS)
  28689. + instance->connected = 1;
  28690. +
  28691. + mutex_unlock(&state->mutex);
  28692. +
  28693. +failed:
  28694. + vchiq_log_trace(vchiq_core_log_level,
  28695. + "%s(%p): returning %d", __func__, instance, status);
  28696. +
  28697. + return status;
  28698. +}
  28699. +EXPORT_SYMBOL(vchiq_connect);
  28700. +
  28701. +/****************************************************************************
  28702. +*
  28703. +* vchiq_add_service
  28704. +*
  28705. +***************************************************************************/
  28706. +
  28707. +VCHIQ_STATUS_T vchiq_add_service(
  28708. + VCHIQ_INSTANCE_T instance,
  28709. + const VCHIQ_SERVICE_PARAMS_T *params,
  28710. + VCHIQ_SERVICE_HANDLE_T *phandle)
  28711. +{
  28712. + VCHIQ_STATUS_T status;
  28713. + VCHIQ_STATE_T *state = instance->state;
  28714. + VCHIQ_SERVICE_T *service = NULL;
  28715. + int srvstate;
  28716. +
  28717. + vchiq_log_trace(vchiq_core_log_level,
  28718. + "%s(%p) called", __func__, instance);
  28719. +
  28720. + *phandle = VCHIQ_SERVICE_HANDLE_INVALID;
  28721. +
  28722. + srvstate = vchiq_is_connected(instance)
  28723. + ? VCHIQ_SRVSTATE_LISTENING
  28724. + : VCHIQ_SRVSTATE_HIDDEN;
  28725. +
  28726. + service = vchiq_add_service_internal(
  28727. + state,
  28728. + params,
  28729. + srvstate,
  28730. + instance,
  28731. + NULL);
  28732. +
  28733. + if (service) {
  28734. + *phandle = service->handle;
  28735. + status = VCHIQ_SUCCESS;
  28736. + } else
  28737. + status = VCHIQ_ERROR;
  28738. +
  28739. + vchiq_log_trace(vchiq_core_log_level,
  28740. + "%s(%p): returning %d", __func__, instance, status);
  28741. +
  28742. + return status;
  28743. +}
  28744. +EXPORT_SYMBOL(vchiq_add_service);
  28745. +
  28746. +/****************************************************************************
  28747. +*
  28748. +* vchiq_open_service
  28749. +*
  28750. +***************************************************************************/
  28751. +
  28752. +VCHIQ_STATUS_T vchiq_open_service(
  28753. + VCHIQ_INSTANCE_T instance,
  28754. + const VCHIQ_SERVICE_PARAMS_T *params,
  28755. + VCHIQ_SERVICE_HANDLE_T *phandle)
  28756. +{
  28757. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  28758. + VCHIQ_STATE_T *state = instance->state;
  28759. + VCHIQ_SERVICE_T *service = NULL;
  28760. +
  28761. + vchiq_log_trace(vchiq_core_log_level,
  28762. + "%s(%p) called", __func__, instance);
  28763. +
  28764. + *phandle = VCHIQ_SERVICE_HANDLE_INVALID;
  28765. +
  28766. + if (!vchiq_is_connected(instance))
  28767. + goto failed;
  28768. +
  28769. + service = vchiq_add_service_internal(state,
  28770. + params,
  28771. + VCHIQ_SRVSTATE_OPENING,
  28772. + instance,
  28773. + NULL);
  28774. +
  28775. + if (service) {
  28776. + status = vchiq_open_service_internal(service, current->pid);
  28777. + if (status == VCHIQ_SUCCESS)
  28778. + *phandle = service->handle;
  28779. + else
  28780. + vchiq_remove_service(service->handle);
  28781. + }
  28782. +
  28783. +failed:
  28784. + vchiq_log_trace(vchiq_core_log_level,
  28785. + "%s(%p): returning %d", __func__, instance, status);
  28786. +
  28787. + return status;
  28788. +}
  28789. +EXPORT_SYMBOL(vchiq_open_service);
  28790. +
  28791. +VCHIQ_STATUS_T
  28792. +vchiq_queue_bulk_transmit(VCHIQ_SERVICE_HANDLE_T handle,
  28793. + const void *data, unsigned int size, void *userdata)
  28794. +{
  28795. + return vchiq_bulk_transfer(handle,
  28796. + VCHI_MEM_HANDLE_INVALID, (void *)data, size, userdata,
  28797. + VCHIQ_BULK_MODE_CALLBACK, VCHIQ_BULK_TRANSMIT);
  28798. +}
  28799. +EXPORT_SYMBOL(vchiq_queue_bulk_transmit);
  28800. +
  28801. +VCHIQ_STATUS_T
  28802. +vchiq_queue_bulk_receive(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  28803. + unsigned int size, void *userdata)
  28804. +{
  28805. + return vchiq_bulk_transfer(handle,
  28806. + VCHI_MEM_HANDLE_INVALID, data, size, userdata,
  28807. + VCHIQ_BULK_MODE_CALLBACK, VCHIQ_BULK_RECEIVE);
  28808. +}
  28809. +EXPORT_SYMBOL(vchiq_queue_bulk_receive);
  28810. +
  28811. +VCHIQ_STATUS_T
  28812. +vchiq_bulk_transmit(VCHIQ_SERVICE_HANDLE_T handle, const void *data,
  28813. + unsigned int size, void *userdata, VCHIQ_BULK_MODE_T mode)
  28814. +{
  28815. + VCHIQ_STATUS_T status;
  28816. +
  28817. + switch (mode) {
  28818. + case VCHIQ_BULK_MODE_NOCALLBACK:
  28819. + case VCHIQ_BULK_MODE_CALLBACK:
  28820. + status = vchiq_bulk_transfer(handle,
  28821. + VCHI_MEM_HANDLE_INVALID, (void *)data, size, userdata,
  28822. + mode, VCHIQ_BULK_TRANSMIT);
  28823. + break;
  28824. + case VCHIQ_BULK_MODE_BLOCKING:
  28825. + status = vchiq_blocking_bulk_transfer(handle,
  28826. + (void *)data, size, VCHIQ_BULK_TRANSMIT);
  28827. + break;
  28828. + default:
  28829. + return VCHIQ_ERROR;
  28830. + }
  28831. +
  28832. + return status;
  28833. +}
  28834. +EXPORT_SYMBOL(vchiq_bulk_transmit);
  28835. +
  28836. +VCHIQ_STATUS_T
  28837. +vchiq_bulk_receive(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  28838. + unsigned int size, void *userdata, VCHIQ_BULK_MODE_T mode)
  28839. +{
  28840. + VCHIQ_STATUS_T status;
  28841. +
  28842. + switch (mode) {
  28843. + case VCHIQ_BULK_MODE_NOCALLBACK:
  28844. + case VCHIQ_BULK_MODE_CALLBACK:
  28845. + status = vchiq_bulk_transfer(handle,
  28846. + VCHI_MEM_HANDLE_INVALID, data, size, userdata,
  28847. + mode, VCHIQ_BULK_RECEIVE);
  28848. + break;
  28849. + case VCHIQ_BULK_MODE_BLOCKING:
  28850. + status = vchiq_blocking_bulk_transfer(handle,
  28851. + (void *)data, size, VCHIQ_BULK_RECEIVE);
  28852. + break;
  28853. + default:
  28854. + return VCHIQ_ERROR;
  28855. + }
  28856. +
  28857. + return status;
  28858. +}
  28859. +EXPORT_SYMBOL(vchiq_bulk_receive);
  28860. +
  28861. +static VCHIQ_STATUS_T
  28862. +vchiq_blocking_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  28863. + unsigned int size, VCHIQ_BULK_DIR_T dir)
  28864. +{
  28865. + VCHIQ_INSTANCE_T instance;
  28866. + VCHIQ_SERVICE_T *service;
  28867. + VCHIQ_STATUS_T status;
  28868. + struct bulk_waiter_node *waiter = NULL;
  28869. + struct list_head *pos;
  28870. +
  28871. + service = find_service_by_handle(handle);
  28872. + if (!service)
  28873. + return VCHIQ_ERROR;
  28874. +
  28875. + instance = service->instance;
  28876. +
  28877. + unlock_service(service);
  28878. +
  28879. + mutex_lock(&instance->bulk_waiter_list_mutex);
  28880. + list_for_each(pos, &instance->bulk_waiter_list) {
  28881. + if (list_entry(pos, struct bulk_waiter_node,
  28882. + list)->pid == current->pid) {
  28883. + waiter = list_entry(pos,
  28884. + struct bulk_waiter_node,
  28885. + list);
  28886. + list_del(pos);
  28887. + break;
  28888. + }
  28889. + }
  28890. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  28891. +
  28892. + if (waiter) {
  28893. + VCHIQ_BULK_T *bulk = waiter->bulk_waiter.bulk;
  28894. + if (bulk) {
  28895. + /* This thread has an outstanding bulk transfer. */
  28896. + if ((bulk->data != data) ||
  28897. + (bulk->size != size)) {
  28898. + /* This is not a retry of the previous one.
  28899. + ** Cancel the signal when the transfer
  28900. + ** completes. */
  28901. + spin_lock(&bulk_waiter_spinlock);
  28902. + bulk->userdata = NULL;
  28903. + spin_unlock(&bulk_waiter_spinlock);
  28904. + }
  28905. + }
  28906. + }
  28907. +
  28908. + if (!waiter) {
  28909. + waiter = kzalloc(sizeof(struct bulk_waiter_node), GFP_KERNEL);
  28910. + if (!waiter) {
  28911. + vchiq_log_error(vchiq_core_log_level,
  28912. + "%s - out of memory", __func__);
  28913. + return VCHIQ_ERROR;
  28914. + }
  28915. + }
  28916. +
  28917. + status = vchiq_bulk_transfer(handle, VCHI_MEM_HANDLE_INVALID,
  28918. + data, size, &waiter->bulk_waiter, VCHIQ_BULK_MODE_BLOCKING,
  28919. + dir);
  28920. + if ((status != VCHIQ_RETRY) || fatal_signal_pending(current) ||
  28921. + !waiter->bulk_waiter.bulk) {
  28922. + VCHIQ_BULK_T *bulk = waiter->bulk_waiter.bulk;
  28923. + if (bulk) {
  28924. + /* Cancel the signal when the transfer
  28925. + ** completes. */
  28926. + spin_lock(&bulk_waiter_spinlock);
  28927. + bulk->userdata = NULL;
  28928. + spin_unlock(&bulk_waiter_spinlock);
  28929. + }
  28930. + kfree(waiter);
  28931. + } else {
  28932. + waiter->pid = current->pid;
  28933. + mutex_lock(&instance->bulk_waiter_list_mutex);
  28934. + list_add(&waiter->list, &instance->bulk_waiter_list);
  28935. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  28936. + vchiq_log_info(vchiq_arm_log_level,
  28937. + "saved bulk_waiter %x for pid %d",
  28938. + (unsigned int)waiter, current->pid);
  28939. + }
  28940. +
  28941. + return status;
  28942. +}
  28943. diff -Nur linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h
  28944. --- linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h 1970-01-01 01:00:00.000000000 +0100
  28945. +++ linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h 2014-08-06 16:50:14.493962307 +0200
  28946. @@ -0,0 +1,71 @@
  28947. +/**
  28948. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  28949. + *
  28950. + * Redistribution and use in source and binary forms, with or without
  28951. + * modification, are permitted provided that the following conditions
  28952. + * are met:
  28953. + * 1. Redistributions of source code must retain the above copyright
  28954. + * notice, this list of conditions, and the following disclaimer,
  28955. + * without modification.
  28956. + * 2. Redistributions in binary form must reproduce the above copyright
  28957. + * notice, this list of conditions and the following disclaimer in the
  28958. + * documentation and/or other materials provided with the distribution.
  28959. + * 3. The names of the above-listed copyright holders may not be used
  28960. + * to endorse or promote products derived from this software without
  28961. + * specific prior written permission.
  28962. + *
  28963. + * ALTERNATIVELY, this software may be distributed under the terms of the
  28964. + * GNU General Public License ("GPL") version 2, as published by the Free
  28965. + * Software Foundation.
  28966. + *
  28967. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  28968. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  28969. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  28970. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  28971. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28972. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  28973. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28974. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28975. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28976. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28977. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28978. + */
  28979. +
  28980. +#ifndef VCHIQ_MEMDRV_H
  28981. +#define VCHIQ_MEMDRV_H
  28982. +
  28983. +/* ---- Include Files ----------------------------------------------------- */
  28984. +
  28985. +#include <linux/kernel.h>
  28986. +#include "vchiq_if.h"
  28987. +
  28988. +/* ---- Constants and Types ---------------------------------------------- */
  28989. +
  28990. +typedef struct {
  28991. + void *armSharedMemVirt;
  28992. + dma_addr_t armSharedMemPhys;
  28993. + size_t armSharedMemSize;
  28994. +
  28995. + void *vcSharedMemVirt;
  28996. + dma_addr_t vcSharedMemPhys;
  28997. + size_t vcSharedMemSize;
  28998. +} VCHIQ_SHARED_MEM_INFO_T;
  28999. +
  29000. +/* ---- Variable Externs ------------------------------------------------- */
  29001. +
  29002. +/* ---- Function Prototypes ---------------------------------------------- */
  29003. +
  29004. +void vchiq_get_shared_mem_info(VCHIQ_SHARED_MEM_INFO_T *info);
  29005. +
  29006. +VCHIQ_STATUS_T vchiq_memdrv_initialise(void);
  29007. +
  29008. +VCHIQ_STATUS_T vchiq_userdrv_create_instance(
  29009. + const VCHIQ_PLATFORM_DATA_T * platform_data);
  29010. +
  29011. +VCHIQ_STATUS_T vchiq_userdrv_suspend(
  29012. + const VCHIQ_PLATFORM_DATA_T * platform_data);
  29013. +
  29014. +VCHIQ_STATUS_T vchiq_userdrv_resume(
  29015. + const VCHIQ_PLATFORM_DATA_T * platform_data);
  29016. +
  29017. +#endif
  29018. diff -Nur linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h
  29019. --- linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h 1970-01-01 01:00:00.000000000 +0100
  29020. +++ linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h 2014-08-06 16:50:14.497962339 +0200
  29021. @@ -0,0 +1,58 @@
  29022. +/**
  29023. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  29024. + *
  29025. + * Redistribution and use in source and binary forms, with or without
  29026. + * modification, are permitted provided that the following conditions
  29027. + * are met:
  29028. + * 1. Redistributions of source code must retain the above copyright
  29029. + * notice, this list of conditions, and the following disclaimer,
  29030. + * without modification.
  29031. + * 2. Redistributions in binary form must reproduce the above copyright
  29032. + * notice, this list of conditions and the following disclaimer in the
  29033. + * documentation and/or other materials provided with the distribution.
  29034. + * 3. The names of the above-listed copyright holders may not be used
  29035. + * to endorse or promote products derived from this software without
  29036. + * specific prior written permission.
  29037. + *
  29038. + * ALTERNATIVELY, this software may be distributed under the terms of the
  29039. + * GNU General Public License ("GPL") version 2, as published by the Free
  29040. + * Software Foundation.
  29041. + *
  29042. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  29043. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  29044. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  29045. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  29046. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  29047. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29048. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  29049. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29050. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29051. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29052. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29053. + */
  29054. +
  29055. +#ifndef VCHIQ_PAGELIST_H
  29056. +#define VCHIQ_PAGELIST_H
  29057. +
  29058. +#ifndef PAGE_SIZE
  29059. +#define PAGE_SIZE 4096
  29060. +#endif
  29061. +#define CACHE_LINE_SIZE 32
  29062. +#define PAGELIST_WRITE 0
  29063. +#define PAGELIST_READ 1
  29064. +#define PAGELIST_READ_WITH_FRAGMENTS 2
  29065. +
  29066. +typedef struct pagelist_struct {
  29067. + unsigned long length;
  29068. + unsigned short type;
  29069. + unsigned short offset;
  29070. + unsigned long addrs[1]; /* N.B. 12 LSBs hold the number of following
  29071. + pages at consecutive addresses. */
  29072. +} PAGELIST_T;
  29073. +
  29074. +typedef struct fragments_struct {
  29075. + char headbuf[CACHE_LINE_SIZE];
  29076. + char tailbuf[CACHE_LINE_SIZE];
  29077. +} FRAGMENTS_T;
  29078. +
  29079. +#endif /* VCHIQ_PAGELIST_H */
  29080. diff -Nur linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_proc.c linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_proc.c
  29081. --- linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_proc.c 1970-01-01 01:00:00.000000000 +0100
  29082. +++ linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_proc.c 2014-08-06 16:50:14.497962339 +0200
  29083. @@ -0,0 +1,253 @@
  29084. +/**
  29085. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  29086. + *
  29087. + * Redistribution and use in source and binary forms, with or without
  29088. + * modification, are permitted provided that the following conditions
  29089. + * are met:
  29090. + * 1. Redistributions of source code must retain the above copyright
  29091. + * notice, this list of conditions, and the following disclaimer,
  29092. + * without modification.
  29093. + * 2. Redistributions in binary form must reproduce the above copyright
  29094. + * notice, this list of conditions and the following disclaimer in the
  29095. + * documentation and/or other materials provided with the distribution.
  29096. + * 3. The names of the above-listed copyright holders may not be used
  29097. + * to endorse or promote products derived from this software without
  29098. + * specific prior written permission.
  29099. + *
  29100. + * ALTERNATIVELY, this software may be distributed under the terms of the
  29101. + * GNU General Public License ("GPL") version 2, as published by the Free
  29102. + * Software Foundation.
  29103. + *
  29104. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  29105. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  29106. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  29107. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  29108. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  29109. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29110. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  29111. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29112. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29113. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29114. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29115. + */
  29116. +
  29117. +
  29118. +#include <linux/proc_fs.h>
  29119. +#include "vchiq_core.h"
  29120. +#include "vchiq_arm.h"
  29121. +
  29122. +#if 1
  29123. +
  29124. +int vchiq_proc_init(void)
  29125. +{
  29126. + return 0;
  29127. +}
  29128. +
  29129. +void vchiq_proc_deinit(void)
  29130. +{
  29131. +}
  29132. +
  29133. +#else
  29134. +
  29135. +struct vchiq_proc_info {
  29136. + /* Global 'vc' proc entry used by all instances */
  29137. + struct proc_dir_entry *vc_cfg_dir;
  29138. +
  29139. + /* one entry per client process */
  29140. + struct proc_dir_entry *clients;
  29141. +
  29142. + /* log categories */
  29143. + struct proc_dir_entry *log_categories;
  29144. +};
  29145. +
  29146. +static struct vchiq_proc_info proc_info;
  29147. +
  29148. +struct proc_dir_entry *vchiq_proc_top(void)
  29149. +{
  29150. + BUG_ON(proc_info.vc_cfg_dir == NULL);
  29151. + return proc_info.vc_cfg_dir;
  29152. +}
  29153. +
  29154. +/****************************************************************************
  29155. +*
  29156. +* log category entries
  29157. +*
  29158. +***************************************************************************/
  29159. +#define PROC_WRITE_BUF_SIZE 256
  29160. +
  29161. +#define VCHIQ_LOG_ERROR_STR "error"
  29162. +#define VCHIQ_LOG_WARNING_STR "warning"
  29163. +#define VCHIQ_LOG_INFO_STR "info"
  29164. +#define VCHIQ_LOG_TRACE_STR "trace"
  29165. +
  29166. +static int log_cfg_read(char *buffer,
  29167. + char **start,
  29168. + off_t off,
  29169. + int count,
  29170. + int *eof,
  29171. + void *data)
  29172. +{
  29173. + int len = 0;
  29174. + char *log_value = NULL;
  29175. +
  29176. + switch (*((int *)data)) {
  29177. + case VCHIQ_LOG_ERROR:
  29178. + log_value = VCHIQ_LOG_ERROR_STR;
  29179. + break;
  29180. + case VCHIQ_LOG_WARNING:
  29181. + log_value = VCHIQ_LOG_WARNING_STR;
  29182. + break;
  29183. + case VCHIQ_LOG_INFO:
  29184. + log_value = VCHIQ_LOG_INFO_STR;
  29185. + break;
  29186. + case VCHIQ_LOG_TRACE:
  29187. + log_value = VCHIQ_LOG_TRACE_STR;
  29188. + break;
  29189. + default:
  29190. + break;
  29191. + }
  29192. +
  29193. + len += sprintf(buffer + len,
  29194. + "%s\n",
  29195. + log_value ? log_value : "(null)");
  29196. +
  29197. + return len;
  29198. +}
  29199. +
  29200. +
  29201. +static int log_cfg_write(struct file *file,
  29202. + const char __user *buffer,
  29203. + unsigned long count,
  29204. + void *data)
  29205. +{
  29206. + int *log_module = data;
  29207. + char kbuf[PROC_WRITE_BUF_SIZE + 1];
  29208. +
  29209. + (void)file;
  29210. +
  29211. + memset(kbuf, 0, PROC_WRITE_BUF_SIZE + 1);
  29212. + if (count >= PROC_WRITE_BUF_SIZE)
  29213. + count = PROC_WRITE_BUF_SIZE;
  29214. +
  29215. + if (copy_from_user(kbuf,
  29216. + buffer,
  29217. + count) != 0)
  29218. + return -EFAULT;
  29219. + kbuf[count - 1] = 0;
  29220. +
  29221. + if (strncmp("error", kbuf, strlen("error")) == 0)
  29222. + *log_module = VCHIQ_LOG_ERROR;
  29223. + else if (strncmp("warning", kbuf, strlen("warning")) == 0)
  29224. + *log_module = VCHIQ_LOG_WARNING;
  29225. + else if (strncmp("info", kbuf, strlen("info")) == 0)
  29226. + *log_module = VCHIQ_LOG_INFO;
  29227. + else if (strncmp("trace", kbuf, strlen("trace")) == 0)
  29228. + *log_module = VCHIQ_LOG_TRACE;
  29229. + else
  29230. + *log_module = VCHIQ_LOG_DEFAULT;
  29231. +
  29232. + return count;
  29233. +}
  29234. +
  29235. +/* Log category proc entries */
  29236. +struct vchiq_proc_log_entry {
  29237. + const char *name;
  29238. + int *plevel;
  29239. + struct proc_dir_entry *dir;
  29240. +};
  29241. +
  29242. +static struct vchiq_proc_log_entry vchiq_proc_log_entries[] = {
  29243. + { "core", &vchiq_core_log_level },
  29244. + { "msg", &vchiq_core_msg_log_level },
  29245. + { "sync", &vchiq_sync_log_level },
  29246. + { "susp", &vchiq_susp_log_level },
  29247. + { "arm", &vchiq_arm_log_level },
  29248. +};
  29249. +static int n_log_entries =
  29250. + sizeof(vchiq_proc_log_entries)/sizeof(vchiq_proc_log_entries[0]);
  29251. +
  29252. +/* create an entry under /proc/vc/log for each log category */
  29253. +static int vchiq_proc_create_log_entries(struct proc_dir_entry *top)
  29254. +{
  29255. + struct proc_dir_entry *dir;
  29256. + size_t i;
  29257. + int ret = 0;
  29258. + dir = proc_mkdir("log", proc_info.vc_cfg_dir);
  29259. + if (!dir)
  29260. + return -ENOMEM;
  29261. + proc_info.log_categories = dir;
  29262. +
  29263. + for (i = 0; i < n_log_entries; i++) {
  29264. + dir = create_proc_entry(vchiq_proc_log_entries[i].name,
  29265. + 0644,
  29266. + proc_info.log_categories);
  29267. + if (!dir) {
  29268. + ret = -ENOMEM;
  29269. + break;
  29270. + }
  29271. +
  29272. + dir->read_proc = &log_cfg_read;
  29273. + dir->write_proc = &log_cfg_write;
  29274. + dir->data = (void *)vchiq_proc_log_entries[i].plevel;
  29275. +
  29276. + vchiq_proc_log_entries[i].dir = dir;
  29277. + }
  29278. + return ret;
  29279. +}
  29280. +
  29281. +
  29282. +int vchiq_proc_init(void)
  29283. +{
  29284. + BUG_ON(proc_info.vc_cfg_dir != NULL);
  29285. +
  29286. + proc_info.vc_cfg_dir = proc_mkdir("vc", NULL);
  29287. + if (proc_info.vc_cfg_dir == NULL)
  29288. + goto fail;
  29289. +
  29290. + proc_info.clients = proc_mkdir("clients",
  29291. + proc_info.vc_cfg_dir);
  29292. + if (!proc_info.clients)
  29293. + goto fail;
  29294. +
  29295. + if (vchiq_proc_create_log_entries(proc_info.vc_cfg_dir) != 0)
  29296. + goto fail;
  29297. +
  29298. + return 0;
  29299. +
  29300. +fail:
  29301. + vchiq_proc_deinit();
  29302. + vchiq_log_error(vchiq_arm_log_level,
  29303. + "%s: failed to create proc directory",
  29304. + __func__);
  29305. +
  29306. + return -ENOMEM;
  29307. +}
  29308. +
  29309. +/* remove all the proc entries */
  29310. +void vchiq_proc_deinit(void)
  29311. +{
  29312. + /* log category entries */
  29313. + if (proc_info.log_categories) {
  29314. + size_t i;
  29315. + for (i = 0; i < n_log_entries; i++)
  29316. + if (vchiq_proc_log_entries[i].dir)
  29317. + remove_proc_entry(
  29318. + vchiq_proc_log_entries[i].name,
  29319. + proc_info.log_categories);
  29320. +
  29321. + remove_proc_entry(proc_info.log_categories->name,
  29322. + proc_info.vc_cfg_dir);
  29323. + }
  29324. + if (proc_info.clients)
  29325. + remove_proc_entry(proc_info.clients->name,
  29326. + proc_info.vc_cfg_dir);
  29327. + if (proc_info.vc_cfg_dir)
  29328. + remove_proc_entry(proc_info.vc_cfg_dir->name, NULL);
  29329. +}
  29330. +
  29331. +struct proc_dir_entry *vchiq_clients_top(void)
  29332. +{
  29333. + return proc_info.clients;
  29334. +}
  29335. +
  29336. +#endif
  29337. diff -Nur linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c
  29338. --- linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c 1970-01-01 01:00:00.000000000 +0100
  29339. +++ linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c 2014-08-06 16:50:14.497962339 +0200
  29340. @@ -0,0 +1,828 @@
  29341. +/**
  29342. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  29343. + *
  29344. + * Redistribution and use in source and binary forms, with or without
  29345. + * modification, are permitted provided that the following conditions
  29346. + * are met:
  29347. + * 1. Redistributions of source code must retain the above copyright
  29348. + * notice, this list of conditions, and the following disclaimer,
  29349. + * without modification.
  29350. + * 2. Redistributions in binary form must reproduce the above copyright
  29351. + * notice, this list of conditions and the following disclaimer in the
  29352. + * documentation and/or other materials provided with the distribution.
  29353. + * 3. The names of the above-listed copyright holders may not be used
  29354. + * to endorse or promote products derived from this software without
  29355. + * specific prior written permission.
  29356. + *
  29357. + * ALTERNATIVELY, this software may be distributed under the terms of the
  29358. + * GNU General Public License ("GPL") version 2, as published by the Free
  29359. + * Software Foundation.
  29360. + *
  29361. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  29362. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  29363. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  29364. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  29365. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  29366. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29367. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  29368. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29369. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29370. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29371. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29372. + */
  29373. +#include <linux/module.h>
  29374. +#include <linux/types.h>
  29375. +
  29376. +#include "interface/vchi/vchi.h"
  29377. +#include "vchiq.h"
  29378. +#include "vchiq_core.h"
  29379. +
  29380. +#include "vchiq_util.h"
  29381. +
  29382. +#include <stddef.h>
  29383. +
  29384. +#define vchiq_status_to_vchi(status) ((int32_t)status)
  29385. +
  29386. +typedef struct {
  29387. + VCHIQ_SERVICE_HANDLE_T handle;
  29388. +
  29389. + VCHIU_QUEUE_T queue;
  29390. +
  29391. + VCHI_CALLBACK_T callback;
  29392. + void *callback_param;
  29393. +} SHIM_SERVICE_T;
  29394. +
  29395. +/* ----------------------------------------------------------------------
  29396. + * return pointer to the mphi message driver function table
  29397. + * -------------------------------------------------------------------- */
  29398. +const VCHI_MESSAGE_DRIVER_T *
  29399. +vchi_mphi_message_driver_func_table(void)
  29400. +{
  29401. + return NULL;
  29402. +}
  29403. +
  29404. +/* ----------------------------------------------------------------------
  29405. + * return a pointer to the 'single' connection driver fops
  29406. + * -------------------------------------------------------------------- */
  29407. +const VCHI_CONNECTION_API_T *
  29408. +single_get_func_table(void)
  29409. +{
  29410. + return NULL;
  29411. +}
  29412. +
  29413. +VCHI_CONNECTION_T *vchi_create_connection(
  29414. + const VCHI_CONNECTION_API_T *function_table,
  29415. + const VCHI_MESSAGE_DRIVER_T *low_level)
  29416. +{
  29417. + (void)function_table;
  29418. + (void)low_level;
  29419. + return NULL;
  29420. +}
  29421. +
  29422. +/***********************************************************
  29423. + * Name: vchi_msg_peek
  29424. + *
  29425. + * Arguments: const VCHI_SERVICE_HANDLE_T handle,
  29426. + * void **data,
  29427. + * uint32_t *msg_size,
  29428. +
  29429. +
  29430. + * VCHI_FLAGS_T flags
  29431. + *
  29432. + * Description: Routine to return a pointer to the current message (to allow in
  29433. + * place processing). The message can be removed using
  29434. + * vchi_msg_remove when you're finished
  29435. + *
  29436. + * Returns: int32_t - success == 0
  29437. + *
  29438. + ***********************************************************/
  29439. +int32_t vchi_msg_peek(VCHI_SERVICE_HANDLE_T handle,
  29440. + void **data,
  29441. + uint32_t *msg_size,
  29442. + VCHI_FLAGS_T flags)
  29443. +{
  29444. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29445. + VCHIQ_HEADER_T *header;
  29446. +
  29447. + WARN_ON((flags != VCHI_FLAGS_NONE) &&
  29448. + (flags != VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE));
  29449. +
  29450. + if (flags == VCHI_FLAGS_NONE)
  29451. + if (vchiu_queue_is_empty(&service->queue))
  29452. + return -1;
  29453. +
  29454. + header = vchiu_queue_peek(&service->queue);
  29455. +
  29456. + *data = header->data;
  29457. + *msg_size = header->size;
  29458. +
  29459. + return 0;
  29460. +}
  29461. +EXPORT_SYMBOL(vchi_msg_peek);
  29462. +
  29463. +/***********************************************************
  29464. + * Name: vchi_msg_remove
  29465. + *
  29466. + * Arguments: const VCHI_SERVICE_HANDLE_T handle,
  29467. + *
  29468. + * Description: Routine to remove a message (after it has been read with
  29469. + * vchi_msg_peek)
  29470. + *
  29471. + * Returns: int32_t - success == 0
  29472. + *
  29473. + ***********************************************************/
  29474. +int32_t vchi_msg_remove(VCHI_SERVICE_HANDLE_T handle)
  29475. +{
  29476. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29477. + VCHIQ_HEADER_T *header;
  29478. +
  29479. + header = vchiu_queue_pop(&service->queue);
  29480. +
  29481. + vchiq_release_message(service->handle, header);
  29482. +
  29483. + return 0;
  29484. +}
  29485. +EXPORT_SYMBOL(vchi_msg_remove);
  29486. +
  29487. +/***********************************************************
  29488. + * Name: vchi_msg_queue
  29489. + *
  29490. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  29491. + * const void *data,
  29492. + * uint32_t data_size,
  29493. + * VCHI_FLAGS_T flags,
  29494. + * void *msg_handle,
  29495. + *
  29496. + * Description: Thin wrapper to queue a message onto a connection
  29497. + *
  29498. + * Returns: int32_t - success == 0
  29499. + *
  29500. + ***********************************************************/
  29501. +int32_t vchi_msg_queue(VCHI_SERVICE_HANDLE_T handle,
  29502. + const void *data,
  29503. + uint32_t data_size,
  29504. + VCHI_FLAGS_T flags,
  29505. + void *msg_handle)
  29506. +{
  29507. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29508. + VCHIQ_ELEMENT_T element = {data, data_size};
  29509. + VCHIQ_STATUS_T status;
  29510. +
  29511. + (void)msg_handle;
  29512. +
  29513. + WARN_ON(flags != VCHI_FLAGS_BLOCK_UNTIL_QUEUED);
  29514. +
  29515. + status = vchiq_queue_message(service->handle, &element, 1);
  29516. +
  29517. + /* vchiq_queue_message() may return VCHIQ_RETRY, so we need to
  29518. + ** implement a retry mechanism since this function is supposed
  29519. + ** to block until queued
  29520. + */
  29521. + while (status == VCHIQ_RETRY) {
  29522. + msleep(1);
  29523. + status = vchiq_queue_message(service->handle, &element, 1);
  29524. + }
  29525. +
  29526. + return vchiq_status_to_vchi(status);
  29527. +}
  29528. +EXPORT_SYMBOL(vchi_msg_queue);
  29529. +
  29530. +/***********************************************************
  29531. + * Name: vchi_bulk_queue_receive
  29532. + *
  29533. + * Arguments: VCHI_BULK_HANDLE_T handle,
  29534. + * void *data_dst,
  29535. + * const uint32_t data_size,
  29536. + * VCHI_FLAGS_T flags
  29537. + * void *bulk_handle
  29538. + *
  29539. + * Description: Routine to setup a rcv buffer
  29540. + *
  29541. + * Returns: int32_t - success == 0
  29542. + *
  29543. + ***********************************************************/
  29544. +int32_t vchi_bulk_queue_receive(VCHI_SERVICE_HANDLE_T handle,
  29545. + void *data_dst,
  29546. + uint32_t data_size,
  29547. + VCHI_FLAGS_T flags,
  29548. + void *bulk_handle)
  29549. +{
  29550. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29551. + VCHIQ_BULK_MODE_T mode;
  29552. + VCHIQ_STATUS_T status;
  29553. +
  29554. + switch ((int)flags) {
  29555. + case VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE
  29556. + | VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  29557. + WARN_ON(!service->callback);
  29558. + mode = VCHIQ_BULK_MODE_CALLBACK;
  29559. + break;
  29560. + case VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE:
  29561. + mode = VCHIQ_BULK_MODE_BLOCKING;
  29562. + break;
  29563. + case VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  29564. + case VCHI_FLAGS_NONE:
  29565. + mode = VCHIQ_BULK_MODE_NOCALLBACK;
  29566. + break;
  29567. + default:
  29568. + WARN(1, "unsupported message\n");
  29569. + return vchiq_status_to_vchi(VCHIQ_ERROR);
  29570. + }
  29571. +
  29572. + status = vchiq_bulk_receive(service->handle, data_dst, data_size,
  29573. + bulk_handle, mode);
  29574. +
  29575. + /* vchiq_bulk_receive() may return VCHIQ_RETRY, so we need to
  29576. + ** implement a retry mechanism since this function is supposed
  29577. + ** to block until queued
  29578. + */
  29579. + while (status == VCHIQ_RETRY) {
  29580. + msleep(1);
  29581. + status = vchiq_bulk_receive(service->handle, data_dst,
  29582. + data_size, bulk_handle, mode);
  29583. + }
  29584. +
  29585. + return vchiq_status_to_vchi(status);
  29586. +}
  29587. +EXPORT_SYMBOL(vchi_bulk_queue_receive);
  29588. +
  29589. +/***********************************************************
  29590. + * Name: vchi_bulk_queue_transmit
  29591. + *
  29592. + * Arguments: VCHI_BULK_HANDLE_T handle,
  29593. + * const void *data_src,
  29594. + * uint32_t data_size,
  29595. + * VCHI_FLAGS_T flags,
  29596. + * void *bulk_handle
  29597. + *
  29598. + * Description: Routine to transmit some data
  29599. + *
  29600. + * Returns: int32_t - success == 0
  29601. + *
  29602. + ***********************************************************/
  29603. +int32_t vchi_bulk_queue_transmit(VCHI_SERVICE_HANDLE_T handle,
  29604. + const void *data_src,
  29605. + uint32_t data_size,
  29606. + VCHI_FLAGS_T flags,
  29607. + void *bulk_handle)
  29608. +{
  29609. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29610. + VCHIQ_BULK_MODE_T mode;
  29611. + VCHIQ_STATUS_T status;
  29612. +
  29613. + switch ((int)flags) {
  29614. + case VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE
  29615. + | VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  29616. + WARN_ON(!service->callback);
  29617. + mode = VCHIQ_BULK_MODE_CALLBACK;
  29618. + break;
  29619. + case VCHI_FLAGS_BLOCK_UNTIL_DATA_READ:
  29620. + case VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE:
  29621. + mode = VCHIQ_BULK_MODE_BLOCKING;
  29622. + break;
  29623. + case VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  29624. + case VCHI_FLAGS_NONE:
  29625. + mode = VCHIQ_BULK_MODE_NOCALLBACK;
  29626. + break;
  29627. + default:
  29628. + WARN(1, "unsupported message\n");
  29629. + return vchiq_status_to_vchi(VCHIQ_ERROR);
  29630. + }
  29631. +
  29632. + status = vchiq_bulk_transmit(service->handle, data_src, data_size,
  29633. + bulk_handle, mode);
  29634. +
  29635. + /* vchiq_bulk_transmit() may return VCHIQ_RETRY, so we need to
  29636. + ** implement a retry mechanism since this function is supposed
  29637. + ** to block until queued
  29638. + */
  29639. + while (status == VCHIQ_RETRY) {
  29640. + msleep(1);
  29641. + status = vchiq_bulk_transmit(service->handle, data_src,
  29642. + data_size, bulk_handle, mode);
  29643. + }
  29644. +
  29645. + return vchiq_status_to_vchi(status);
  29646. +}
  29647. +EXPORT_SYMBOL(vchi_bulk_queue_transmit);
  29648. +
  29649. +/***********************************************************
  29650. + * Name: vchi_msg_dequeue
  29651. + *
  29652. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  29653. + * void *data,
  29654. + * uint32_t max_data_size_to_read,
  29655. + * uint32_t *actual_msg_size
  29656. + * VCHI_FLAGS_T flags
  29657. + *
  29658. + * Description: Routine to dequeue a message into the supplied buffer
  29659. + *
  29660. + * Returns: int32_t - success == 0
  29661. + *
  29662. + ***********************************************************/
  29663. +int32_t vchi_msg_dequeue(VCHI_SERVICE_HANDLE_T handle,
  29664. + void *data,
  29665. + uint32_t max_data_size_to_read,
  29666. + uint32_t *actual_msg_size,
  29667. + VCHI_FLAGS_T flags)
  29668. +{
  29669. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29670. + VCHIQ_HEADER_T *header;
  29671. +
  29672. + WARN_ON((flags != VCHI_FLAGS_NONE) &&
  29673. + (flags != VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE));
  29674. +
  29675. + if (flags == VCHI_FLAGS_NONE)
  29676. + if (vchiu_queue_is_empty(&service->queue))
  29677. + return -1;
  29678. +
  29679. + header = vchiu_queue_pop(&service->queue);
  29680. +
  29681. + memcpy(data, header->data, header->size < max_data_size_to_read ?
  29682. + header->size : max_data_size_to_read);
  29683. +
  29684. + *actual_msg_size = header->size;
  29685. +
  29686. + vchiq_release_message(service->handle, header);
  29687. +
  29688. + return 0;
  29689. +}
  29690. +EXPORT_SYMBOL(vchi_msg_dequeue);
  29691. +
  29692. +/***********************************************************
  29693. + * Name: vchi_msg_queuev
  29694. + *
  29695. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  29696. + * VCHI_MSG_VECTOR_T *vector,
  29697. + * uint32_t count,
  29698. + * VCHI_FLAGS_T flags,
  29699. + * void *msg_handle
  29700. + *
  29701. + * Description: Thin wrapper to queue a message onto a connection
  29702. + *
  29703. + * Returns: int32_t - success == 0
  29704. + *
  29705. + ***********************************************************/
  29706. +
  29707. +vchiq_static_assert(sizeof(VCHI_MSG_VECTOR_T) == sizeof(VCHIQ_ELEMENT_T));
  29708. +vchiq_static_assert(offsetof(VCHI_MSG_VECTOR_T, vec_base) ==
  29709. + offsetof(VCHIQ_ELEMENT_T, data));
  29710. +vchiq_static_assert(offsetof(VCHI_MSG_VECTOR_T, vec_len) ==
  29711. + offsetof(VCHIQ_ELEMENT_T, size));
  29712. +
  29713. +int32_t vchi_msg_queuev(VCHI_SERVICE_HANDLE_T handle,
  29714. + VCHI_MSG_VECTOR_T *vector,
  29715. + uint32_t count,
  29716. + VCHI_FLAGS_T flags,
  29717. + void *msg_handle)
  29718. +{
  29719. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29720. +
  29721. + (void)msg_handle;
  29722. +
  29723. + WARN_ON(flags != VCHI_FLAGS_BLOCK_UNTIL_QUEUED);
  29724. +
  29725. + return vchiq_status_to_vchi(vchiq_queue_message(service->handle,
  29726. + (const VCHIQ_ELEMENT_T *)vector, count));
  29727. +}
  29728. +EXPORT_SYMBOL(vchi_msg_queuev);
  29729. +
  29730. +/***********************************************************
  29731. + * Name: vchi_held_msg_release
  29732. + *
  29733. + * Arguments: VCHI_HELD_MSG_T *message
  29734. + *
  29735. + * Description: Routine to release a held message (after it has been read with
  29736. + * vchi_msg_hold)
  29737. + *
  29738. + * Returns: int32_t - success == 0
  29739. + *
  29740. + ***********************************************************/
  29741. +int32_t vchi_held_msg_release(VCHI_HELD_MSG_T *message)
  29742. +{
  29743. + vchiq_release_message((VCHIQ_SERVICE_HANDLE_T)message->service,
  29744. + (VCHIQ_HEADER_T *)message->message);
  29745. +
  29746. + return 0;
  29747. +}
  29748. +EXPORT_SYMBOL(vchi_held_msg_release);
  29749. +
  29750. +/***********************************************************
  29751. + * Name: vchi_msg_hold
  29752. + *
  29753. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  29754. + * void **data,
  29755. + * uint32_t *msg_size,
  29756. + * VCHI_FLAGS_T flags,
  29757. + * VCHI_HELD_MSG_T *message_handle
  29758. + *
  29759. + * Description: Routine to return a pointer to the current message (to allow
  29760. + * in place processing). The message is dequeued - don't forget
  29761. + * to release the message using vchi_held_msg_release when you're
  29762. + * finished.
  29763. + *
  29764. + * Returns: int32_t - success == 0
  29765. + *
  29766. + ***********************************************************/
  29767. +int32_t vchi_msg_hold(VCHI_SERVICE_HANDLE_T handle,
  29768. + void **data,
  29769. + uint32_t *msg_size,
  29770. + VCHI_FLAGS_T flags,
  29771. + VCHI_HELD_MSG_T *message_handle)
  29772. +{
  29773. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29774. + VCHIQ_HEADER_T *header;
  29775. +
  29776. + WARN_ON((flags != VCHI_FLAGS_NONE) &&
  29777. + (flags != VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE));
  29778. +
  29779. + if (flags == VCHI_FLAGS_NONE)
  29780. + if (vchiu_queue_is_empty(&service->queue))
  29781. + return -1;
  29782. +
  29783. + header = vchiu_queue_pop(&service->queue);
  29784. +
  29785. + *data = header->data;
  29786. + *msg_size = header->size;
  29787. +
  29788. + message_handle->service =
  29789. + (struct opaque_vchi_service_t *)service->handle;
  29790. + message_handle->message = header;
  29791. +
  29792. + return 0;
  29793. +}
  29794. +EXPORT_SYMBOL(vchi_msg_hold);
  29795. +
  29796. +/***********************************************************
  29797. + * Name: vchi_initialise
  29798. + *
  29799. + * Arguments: VCHI_INSTANCE_T *instance_handle
  29800. + * VCHI_CONNECTION_T **connections
  29801. + * const uint32_t num_connections
  29802. + *
  29803. + * Description: Initialises the hardware but does not transmit anything
  29804. + * When run as a Host App this will be called twice hence the need
  29805. + * to malloc the state information
  29806. + *
  29807. + * Returns: 0 if successful, failure otherwise
  29808. + *
  29809. + ***********************************************************/
  29810. +
  29811. +int32_t vchi_initialise(VCHI_INSTANCE_T *instance_handle)
  29812. +{
  29813. + VCHIQ_INSTANCE_T instance;
  29814. + VCHIQ_STATUS_T status;
  29815. +
  29816. + status = vchiq_initialise(&instance);
  29817. +
  29818. + *instance_handle = (VCHI_INSTANCE_T)instance;
  29819. +
  29820. + return vchiq_status_to_vchi(status);
  29821. +}
  29822. +EXPORT_SYMBOL(vchi_initialise);
  29823. +
  29824. +/***********************************************************
  29825. + * Name: vchi_connect
  29826. + *
  29827. + * Arguments: VCHI_CONNECTION_T **connections
  29828. + * const uint32_t num_connections
  29829. + * VCHI_INSTANCE_T instance_handle)
  29830. + *
  29831. + * Description: Starts the command service on each connection,
  29832. + * causing INIT messages to be pinged back and forth
  29833. + *
  29834. + * Returns: 0 if successful, failure otherwise
  29835. + *
  29836. + ***********************************************************/
  29837. +int32_t vchi_connect(VCHI_CONNECTION_T **connections,
  29838. + const uint32_t num_connections,
  29839. + VCHI_INSTANCE_T instance_handle)
  29840. +{
  29841. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  29842. +
  29843. + (void)connections;
  29844. + (void)num_connections;
  29845. +
  29846. + return vchiq_connect(instance);
  29847. +}
  29848. +EXPORT_SYMBOL(vchi_connect);
  29849. +
  29850. +
  29851. +/***********************************************************
  29852. + * Name: vchi_disconnect
  29853. + *
  29854. + * Arguments: VCHI_INSTANCE_T instance_handle
  29855. + *
  29856. + * Description: Stops the command service on each connection,
  29857. + * causing DE-INIT messages to be pinged back and forth
  29858. + *
  29859. + * Returns: 0 if successful, failure otherwise
  29860. + *
  29861. + ***********************************************************/
  29862. +int32_t vchi_disconnect(VCHI_INSTANCE_T instance_handle)
  29863. +{
  29864. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  29865. + return vchiq_status_to_vchi(vchiq_shutdown(instance));
  29866. +}
  29867. +EXPORT_SYMBOL(vchi_disconnect);
  29868. +
  29869. +
  29870. +/***********************************************************
  29871. + * Name: vchi_service_open
  29872. + * Name: vchi_service_create
  29873. + *
  29874. + * Arguments: VCHI_INSTANCE_T *instance_handle
  29875. + * SERVICE_CREATION_T *setup,
  29876. + * VCHI_SERVICE_HANDLE_T *handle
  29877. + *
  29878. + * Description: Routine to open a service
  29879. + *
  29880. + * Returns: int32_t - success == 0
  29881. + *
  29882. + ***********************************************************/
  29883. +
  29884. +static VCHIQ_STATUS_T shim_callback(VCHIQ_REASON_T reason,
  29885. + VCHIQ_HEADER_T *header, VCHIQ_SERVICE_HANDLE_T handle, void *bulk_user)
  29886. +{
  29887. + SHIM_SERVICE_T *service =
  29888. + (SHIM_SERVICE_T *)VCHIQ_GET_SERVICE_USERDATA(handle);
  29889. +
  29890. + if (!service->callback)
  29891. + goto release;
  29892. +
  29893. + switch (reason) {
  29894. + case VCHIQ_MESSAGE_AVAILABLE:
  29895. + vchiu_queue_push(&service->queue, header);
  29896. +
  29897. + service->callback(service->callback_param,
  29898. + VCHI_CALLBACK_MSG_AVAILABLE, NULL);
  29899. +
  29900. + goto done;
  29901. + break;
  29902. +
  29903. + case VCHIQ_BULK_TRANSMIT_DONE:
  29904. + service->callback(service->callback_param,
  29905. + VCHI_CALLBACK_BULK_SENT, bulk_user);
  29906. + break;
  29907. +
  29908. + case VCHIQ_BULK_RECEIVE_DONE:
  29909. + service->callback(service->callback_param,
  29910. + VCHI_CALLBACK_BULK_RECEIVED, bulk_user);
  29911. + break;
  29912. +
  29913. + case VCHIQ_SERVICE_CLOSED:
  29914. + service->callback(service->callback_param,
  29915. + VCHI_CALLBACK_SERVICE_CLOSED, NULL);
  29916. + break;
  29917. +
  29918. + case VCHIQ_SERVICE_OPENED:
  29919. + /* No equivalent VCHI reason */
  29920. + break;
  29921. +
  29922. + case VCHIQ_BULK_TRANSMIT_ABORTED:
  29923. + service->callback(service->callback_param,
  29924. + VCHI_CALLBACK_BULK_TRANSMIT_ABORTED,
  29925. + bulk_user);
  29926. + break;
  29927. +
  29928. + case VCHIQ_BULK_RECEIVE_ABORTED:
  29929. + service->callback(service->callback_param,
  29930. + VCHI_CALLBACK_BULK_RECEIVE_ABORTED,
  29931. + bulk_user);
  29932. + break;
  29933. +
  29934. + default:
  29935. + WARN(1, "not supported\n");
  29936. + break;
  29937. + }
  29938. +
  29939. +release:
  29940. + vchiq_release_message(service->handle, header);
  29941. +done:
  29942. + return VCHIQ_SUCCESS;
  29943. +}
  29944. +
  29945. +static SHIM_SERVICE_T *service_alloc(VCHIQ_INSTANCE_T instance,
  29946. + SERVICE_CREATION_T *setup)
  29947. +{
  29948. + SHIM_SERVICE_T *service = kzalloc(sizeof(SHIM_SERVICE_T), GFP_KERNEL);
  29949. +
  29950. + (void)instance;
  29951. +
  29952. + if (service) {
  29953. + if (vchiu_queue_init(&service->queue, 64)) {
  29954. + service->callback = setup->callback;
  29955. + service->callback_param = setup->callback_param;
  29956. + } else {
  29957. + kfree(service);
  29958. + service = NULL;
  29959. + }
  29960. + }
  29961. +
  29962. + return service;
  29963. +}
  29964. +
  29965. +static void service_free(SHIM_SERVICE_T *service)
  29966. +{
  29967. + if (service) {
  29968. + vchiu_queue_delete(&service->queue);
  29969. + kfree(service);
  29970. + }
  29971. +}
  29972. +
  29973. +int32_t vchi_service_open(VCHI_INSTANCE_T instance_handle,
  29974. + SERVICE_CREATION_T *setup,
  29975. + VCHI_SERVICE_HANDLE_T *handle)
  29976. +{
  29977. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  29978. + SHIM_SERVICE_T *service = service_alloc(instance, setup);
  29979. + if (service) {
  29980. + VCHIQ_SERVICE_PARAMS_T params;
  29981. + VCHIQ_STATUS_T status;
  29982. +
  29983. + memset(&params, 0, sizeof(params));
  29984. + params.fourcc = setup->service_id;
  29985. + params.callback = shim_callback;
  29986. + params.userdata = service;
  29987. + params.version = setup->version.version;
  29988. + params.version_min = setup->version.version_min;
  29989. +
  29990. + status = vchiq_open_service(instance, &params,
  29991. + &service->handle);
  29992. + if (status != VCHIQ_SUCCESS) {
  29993. + service_free(service);
  29994. + service = NULL;
  29995. + }
  29996. + }
  29997. +
  29998. + *handle = (VCHI_SERVICE_HANDLE_T)service;
  29999. +
  30000. + return (service != NULL) ? 0 : -1;
  30001. +}
  30002. +EXPORT_SYMBOL(vchi_service_open);
  30003. +
  30004. +int32_t vchi_service_create(VCHI_INSTANCE_T instance_handle,
  30005. + SERVICE_CREATION_T *setup,
  30006. + VCHI_SERVICE_HANDLE_T *handle)
  30007. +{
  30008. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  30009. + SHIM_SERVICE_T *service = service_alloc(instance, setup);
  30010. + if (service) {
  30011. + VCHIQ_SERVICE_PARAMS_T params;
  30012. + VCHIQ_STATUS_T status;
  30013. +
  30014. + memset(&params, 0, sizeof(params));
  30015. + params.fourcc = setup->service_id;
  30016. + params.callback = shim_callback;
  30017. + params.userdata = service;
  30018. + params.version = setup->version.version;
  30019. + params.version_min = setup->version.version_min;
  30020. + status = vchiq_add_service(instance, &params, &service->handle);
  30021. +
  30022. + if (status != VCHIQ_SUCCESS) {
  30023. + service_free(service);
  30024. + service = NULL;
  30025. + }
  30026. + }
  30027. +
  30028. + *handle = (VCHI_SERVICE_HANDLE_T)service;
  30029. +
  30030. + return (service != NULL) ? 0 : -1;
  30031. +}
  30032. +EXPORT_SYMBOL(vchi_service_create);
  30033. +
  30034. +int32_t vchi_service_close(const VCHI_SERVICE_HANDLE_T handle)
  30035. +{
  30036. + int32_t ret = -1;
  30037. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  30038. + if (service) {
  30039. + VCHIQ_STATUS_T status = vchiq_close_service(service->handle);
  30040. + if (status == VCHIQ_SUCCESS) {
  30041. + service_free(service);
  30042. + service = NULL;
  30043. + }
  30044. +
  30045. + ret = vchiq_status_to_vchi(status);
  30046. + }
  30047. + return ret;
  30048. +}
  30049. +EXPORT_SYMBOL(vchi_service_close);
  30050. +
  30051. +int32_t vchi_service_destroy(const VCHI_SERVICE_HANDLE_T handle)
  30052. +{
  30053. + int32_t ret = -1;
  30054. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  30055. + if (service) {
  30056. + VCHIQ_STATUS_T status = vchiq_remove_service(service->handle);
  30057. + if (status == VCHIQ_SUCCESS) {
  30058. + service_free(service);
  30059. + service = NULL;
  30060. + }
  30061. +
  30062. + ret = vchiq_status_to_vchi(status);
  30063. + }
  30064. + return ret;
  30065. +}
  30066. +EXPORT_SYMBOL(vchi_service_destroy);
  30067. +
  30068. +int32_t vchi_get_peer_version( const VCHI_SERVICE_HANDLE_T handle, short *peer_version )
  30069. +{
  30070. + int32_t ret = -1;
  30071. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  30072. + if(service)
  30073. + {
  30074. + VCHIQ_STATUS_T status = vchiq_get_peer_version(service->handle, peer_version);
  30075. + ret = vchiq_status_to_vchi( status );
  30076. + }
  30077. + return ret;
  30078. +}
  30079. +EXPORT_SYMBOL(vchi_get_peer_version);
  30080. +
  30081. +/* ----------------------------------------------------------------------
  30082. + * read a uint32_t from buffer.
  30083. + * network format is defined to be little endian
  30084. + * -------------------------------------------------------------------- */
  30085. +uint32_t
  30086. +vchi_readbuf_uint32(const void *_ptr)
  30087. +{
  30088. + const unsigned char *ptr = _ptr;
  30089. + return ptr[0] | (ptr[1] << 8) | (ptr[2] << 16) | (ptr[3] << 24);
  30090. +}
  30091. +
  30092. +/* ----------------------------------------------------------------------
  30093. + * write a uint32_t to buffer.
  30094. + * network format is defined to be little endian
  30095. + * -------------------------------------------------------------------- */
  30096. +void
  30097. +vchi_writebuf_uint32(void *_ptr, uint32_t value)
  30098. +{
  30099. + unsigned char *ptr = _ptr;
  30100. + ptr[0] = (unsigned char)((value >> 0) & 0xFF);
  30101. + ptr[1] = (unsigned char)((value >> 8) & 0xFF);
  30102. + ptr[2] = (unsigned char)((value >> 16) & 0xFF);
  30103. + ptr[3] = (unsigned char)((value >> 24) & 0xFF);
  30104. +}
  30105. +
  30106. +/* ----------------------------------------------------------------------
  30107. + * read a uint16_t from buffer.
  30108. + * network format is defined to be little endian
  30109. + * -------------------------------------------------------------------- */
  30110. +uint16_t
  30111. +vchi_readbuf_uint16(const void *_ptr)
  30112. +{
  30113. + const unsigned char *ptr = _ptr;
  30114. + return ptr[0] | (ptr[1] << 8);
  30115. +}
  30116. +
  30117. +/* ----------------------------------------------------------------------
  30118. + * write a uint16_t into the buffer.
  30119. + * network format is defined to be little endian
  30120. + * -------------------------------------------------------------------- */
  30121. +void
  30122. +vchi_writebuf_uint16(void *_ptr, uint16_t value)
  30123. +{
  30124. + unsigned char *ptr = _ptr;
  30125. + ptr[0] = (value >> 0) & 0xFF;
  30126. + ptr[1] = (value >> 8) & 0xFF;
  30127. +}
  30128. +
  30129. +/***********************************************************
  30130. + * Name: vchi_service_use
  30131. + *
  30132. + * Arguments: const VCHI_SERVICE_HANDLE_T handle
  30133. + *
  30134. + * Description: Routine to increment refcount on a service
  30135. + *
  30136. + * Returns: void
  30137. + *
  30138. + ***********************************************************/
  30139. +int32_t vchi_service_use(const VCHI_SERVICE_HANDLE_T handle)
  30140. +{
  30141. + int32_t ret = -1;
  30142. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  30143. + if (service)
  30144. + ret = vchiq_status_to_vchi(vchiq_use_service(service->handle));
  30145. + return ret;
  30146. +}
  30147. +EXPORT_SYMBOL(vchi_service_use);
  30148. +
  30149. +/***********************************************************
  30150. + * Name: vchi_service_release
  30151. + *
  30152. + * Arguments: const VCHI_SERVICE_HANDLE_T handle
  30153. + *
  30154. + * Description: Routine to decrement refcount on a service
  30155. + *
  30156. + * Returns: void
  30157. + *
  30158. + ***********************************************************/
  30159. +int32_t vchi_service_release(const VCHI_SERVICE_HANDLE_T handle)
  30160. +{
  30161. + int32_t ret = -1;
  30162. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  30163. + if (service)
  30164. + ret = vchiq_status_to_vchi(
  30165. + vchiq_release_service(service->handle));
  30166. + return ret;
  30167. +}
  30168. +EXPORT_SYMBOL(vchi_service_release);
  30169. diff -Nur linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c
  30170. --- linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c 1970-01-01 01:00:00.000000000 +0100
  30171. +++ linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c 2014-08-06 16:50:14.497962339 +0200
  30172. @@ -0,0 +1,151 @@
  30173. +/**
  30174. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  30175. + *
  30176. + * Redistribution and use in source and binary forms, with or without
  30177. + * modification, are permitted provided that the following conditions
  30178. + * are met:
  30179. + * 1. Redistributions of source code must retain the above copyright
  30180. + * notice, this list of conditions, and the following disclaimer,
  30181. + * without modification.
  30182. + * 2. Redistributions in binary form must reproduce the above copyright
  30183. + * notice, this list of conditions and the following disclaimer in the
  30184. + * documentation and/or other materials provided with the distribution.
  30185. + * 3. The names of the above-listed copyright holders may not be used
  30186. + * to endorse or promote products derived from this software without
  30187. + * specific prior written permission.
  30188. + *
  30189. + * ALTERNATIVELY, this software may be distributed under the terms of the
  30190. + * GNU General Public License ("GPL") version 2, as published by the Free
  30191. + * Software Foundation.
  30192. + *
  30193. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  30194. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  30195. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30196. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  30197. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  30198. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  30199. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  30200. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  30201. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30202. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  30203. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30204. + */
  30205. +
  30206. +#include "vchiq_util.h"
  30207. +
  30208. +static inline int is_pow2(int i)
  30209. +{
  30210. + return i && !(i & (i - 1));
  30211. +}
  30212. +
  30213. +int vchiu_queue_init(VCHIU_QUEUE_T *queue, int size)
  30214. +{
  30215. + WARN_ON(!is_pow2(size));
  30216. +
  30217. + queue->size = size;
  30218. + queue->read = 0;
  30219. + queue->write = 0;
  30220. +
  30221. + sema_init(&queue->pop, 0);
  30222. + sema_init(&queue->push, 0);
  30223. +
  30224. + queue->storage = kzalloc(size * sizeof(VCHIQ_HEADER_T *), GFP_KERNEL);
  30225. + if (queue->storage == NULL) {
  30226. + vchiu_queue_delete(queue);
  30227. + return 0;
  30228. + }
  30229. + return 1;
  30230. +}
  30231. +
  30232. +void vchiu_queue_delete(VCHIU_QUEUE_T *queue)
  30233. +{
  30234. + if (queue->storage != NULL)
  30235. + kfree(queue->storage);
  30236. +}
  30237. +
  30238. +int vchiu_queue_is_empty(VCHIU_QUEUE_T *queue)
  30239. +{
  30240. + return queue->read == queue->write;
  30241. +}
  30242. +
  30243. +int vchiu_queue_is_full(VCHIU_QUEUE_T *queue)
  30244. +{
  30245. + return queue->write == queue->read + queue->size;
  30246. +}
  30247. +
  30248. +void vchiu_queue_push(VCHIU_QUEUE_T *queue, VCHIQ_HEADER_T *header)
  30249. +{
  30250. + while (queue->write == queue->read + queue->size) {
  30251. + if (down_interruptible(&queue->pop) != 0) {
  30252. + flush_signals(current);
  30253. + }
  30254. + }
  30255. +
  30256. + /*
  30257. + * Write to queue->storage must be visible after read from
  30258. + * queue->read
  30259. + */
  30260. + smp_mb();
  30261. +
  30262. + queue->storage[queue->write & (queue->size - 1)] = header;
  30263. +
  30264. + /*
  30265. + * Write to queue->storage must be visible before write to
  30266. + * queue->write
  30267. + */
  30268. + smp_wmb();
  30269. +
  30270. + queue->write++;
  30271. +
  30272. + up(&queue->push);
  30273. +}
  30274. +
  30275. +VCHIQ_HEADER_T *vchiu_queue_peek(VCHIU_QUEUE_T *queue)
  30276. +{
  30277. + while (queue->write == queue->read) {
  30278. + if (down_interruptible(&queue->push) != 0) {
  30279. + flush_signals(current);
  30280. + }
  30281. + }
  30282. +
  30283. + up(&queue->push); // We haven't removed anything from the queue.
  30284. +
  30285. + /*
  30286. + * Read from queue->storage must be visible after read from
  30287. + * queue->write
  30288. + */
  30289. + smp_rmb();
  30290. +
  30291. + return queue->storage[queue->read & (queue->size - 1)];
  30292. +}
  30293. +
  30294. +VCHIQ_HEADER_T *vchiu_queue_pop(VCHIU_QUEUE_T *queue)
  30295. +{
  30296. + VCHIQ_HEADER_T *header;
  30297. +
  30298. + while (queue->write == queue->read) {
  30299. + if (down_interruptible(&queue->push) != 0) {
  30300. + flush_signals(current);
  30301. + }
  30302. + }
  30303. +
  30304. + /*
  30305. + * Read from queue->storage must be visible after read from
  30306. + * queue->write
  30307. + */
  30308. + smp_rmb();
  30309. +
  30310. + header = queue->storage[queue->read & (queue->size - 1)];
  30311. +
  30312. + /*
  30313. + * Read from queue->storage must be visible before write to
  30314. + * queue->read
  30315. + */
  30316. + smp_mb();
  30317. +
  30318. + queue->read++;
  30319. +
  30320. + up(&queue->pop);
  30321. +
  30322. + return header;
  30323. +}
  30324. diff -Nur linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h
  30325. --- linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h 1970-01-01 01:00:00.000000000 +0100
  30326. +++ linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h 2014-08-06 16:50:14.497962339 +0200
  30327. @@ -0,0 +1,81 @@
  30328. +/**
  30329. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  30330. + *
  30331. + * Redistribution and use in source and binary forms, with or without
  30332. + * modification, are permitted provided that the following conditions
  30333. + * are met:
  30334. + * 1. Redistributions of source code must retain the above copyright
  30335. + * notice, this list of conditions, and the following disclaimer,
  30336. + * without modification.
  30337. + * 2. Redistributions in binary form must reproduce the above copyright
  30338. + * notice, this list of conditions and the following disclaimer in the
  30339. + * documentation and/or other materials provided with the distribution.
  30340. + * 3. The names of the above-listed copyright holders may not be used
  30341. + * to endorse or promote products derived from this software without
  30342. + * specific prior written permission.
  30343. + *
  30344. + * ALTERNATIVELY, this software may be distributed under the terms of the
  30345. + * GNU General Public License ("GPL") version 2, as published by the Free
  30346. + * Software Foundation.
  30347. + *
  30348. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  30349. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  30350. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30351. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  30352. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  30353. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  30354. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  30355. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  30356. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30357. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  30358. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30359. + */
  30360. +
  30361. +#ifndef VCHIQ_UTIL_H
  30362. +#define VCHIQ_UTIL_H
  30363. +
  30364. +#include <linux/types.h>
  30365. +#include <linux/semaphore.h>
  30366. +#include <linux/mutex.h>
  30367. +#include <linux/bitops.h>
  30368. +#include <linux/kthread.h>
  30369. +#include <linux/wait.h>
  30370. +#include <linux/vmalloc.h>
  30371. +#include <linux/jiffies.h>
  30372. +#include <linux/delay.h>
  30373. +#include <linux/string.h>
  30374. +#include <linux/types.h>
  30375. +#include <linux/interrupt.h>
  30376. +#include <linux/random.h>
  30377. +#include <linux/sched.h>
  30378. +#include <linux/ctype.h>
  30379. +#include <linux/uaccess.h>
  30380. +#include <linux/time.h> /* for time_t */
  30381. +#include <linux/slab.h>
  30382. +#include <linux/vmalloc.h>
  30383. +
  30384. +#include "vchiq_if.h"
  30385. +
  30386. +typedef struct {
  30387. + int size;
  30388. + int read;
  30389. + int write;
  30390. +
  30391. + struct semaphore pop;
  30392. + struct semaphore push;
  30393. +
  30394. + VCHIQ_HEADER_T **storage;
  30395. +} VCHIU_QUEUE_T;
  30396. +
  30397. +extern int vchiu_queue_init(VCHIU_QUEUE_T *queue, int size);
  30398. +extern void vchiu_queue_delete(VCHIU_QUEUE_T *queue);
  30399. +
  30400. +extern int vchiu_queue_is_empty(VCHIU_QUEUE_T *queue);
  30401. +extern int vchiu_queue_is_full(VCHIU_QUEUE_T *queue);
  30402. +
  30403. +extern void vchiu_queue_push(VCHIU_QUEUE_T *queue, VCHIQ_HEADER_T *header);
  30404. +
  30405. +extern VCHIQ_HEADER_T *vchiu_queue_peek(VCHIU_QUEUE_T *queue);
  30406. +extern VCHIQ_HEADER_T *vchiu_queue_pop(VCHIU_QUEUE_T *queue);
  30407. +
  30408. +#endif
  30409. diff -Nur linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c
  30410. --- linux-3.12.26.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c 1970-01-01 01:00:00.000000000 +0100
  30411. +++ linux-3.12.26/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c 2014-08-06 16:50:14.497962339 +0200
  30412. @@ -0,0 +1,59 @@
  30413. +/**
  30414. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  30415. + *
  30416. + * Redistribution and use in source and binary forms, with or without
  30417. + * modification, are permitted provided that the following conditions
  30418. + * are met:
  30419. + * 1. Redistributions of source code must retain the above copyright
  30420. + * notice, this list of conditions, and the following disclaimer,
  30421. + * without modification.
  30422. + * 2. Redistributions in binary form must reproduce the above copyright
  30423. + * notice, this list of conditions and the following disclaimer in the
  30424. + * documentation and/or other materials provided with the distribution.
  30425. + * 3. The names of the above-listed copyright holders may not be used
  30426. + * to endorse or promote products derived from this software without
  30427. + * specific prior written permission.
  30428. + *
  30429. + * ALTERNATIVELY, this software may be distributed under the terms of the
  30430. + * GNU General Public License ("GPL") version 2, as published by the Free
  30431. + * Software Foundation.
  30432. + *
  30433. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  30434. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  30435. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30436. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  30437. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  30438. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  30439. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  30440. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  30441. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30442. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  30443. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30444. + */
  30445. +#include "vchiq_build_info.h"
  30446. +#include <linux/broadcom/vc_debug_sym.h>
  30447. +
  30448. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_hostname, "dc4-arm-01" );
  30449. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_version, "9245b4c35b99b3870e1f7dc598c5692b3c66a6f0 (tainted)" );
  30450. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_time, __TIME__ );
  30451. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_date, __DATE__ );
  30452. +
  30453. +const char *vchiq_get_build_hostname( void )
  30454. +{
  30455. + return vchiq_build_hostname;
  30456. +}
  30457. +
  30458. +const char *vchiq_get_build_version( void )
  30459. +{
  30460. + return vchiq_build_version;
  30461. +}
  30462. +
  30463. +const char *vchiq_get_build_date( void )
  30464. +{
  30465. + return vchiq_build_date;
  30466. +}
  30467. +
  30468. +const char *vchiq_get_build_time( void )
  30469. +{
  30470. + return vchiq_build_time;
  30471. +}
  30472. diff -Nur linux-3.12.26.orig/drivers/misc/vc04_services/Kconfig linux-3.12.26/drivers/misc/vc04_services/Kconfig
  30473. --- linux-3.12.26.orig/drivers/misc/vc04_services/Kconfig 1970-01-01 01:00:00.000000000 +0100
  30474. +++ linux-3.12.26/drivers/misc/vc04_services/Kconfig 2014-08-06 16:50:14.497962339 +0200
  30475. @@ -0,0 +1,9 @@
  30476. +config BCM2708_VCHIQ
  30477. + tristate "Videocore VCHIQ"
  30478. + depends on MACH_BCM2708
  30479. + default y
  30480. + help
  30481. + Kernel to VideoCore communication interface for the
  30482. + BCM2708 family of products.
  30483. + Defaults to Y when the Broadcom Videocore services
  30484. + are included in the build, N otherwise.
  30485. diff -Nur linux-3.12.26.orig/drivers/misc/vc04_services/Makefile linux-3.12.26/drivers/misc/vc04_services/Makefile
  30486. --- linux-3.12.26.orig/drivers/misc/vc04_services/Makefile 1970-01-01 01:00:00.000000000 +0100
  30487. +++ linux-3.12.26/drivers/misc/vc04_services/Makefile 2014-08-06 16:50:14.497962339 +0200
  30488. @@ -0,0 +1,17 @@
  30489. +ifeq ($(CONFIG_MACH_BCM2708),y)
  30490. +
  30491. +obj-$(CONFIG_BCM2708_VCHIQ) += vchiq.o
  30492. +
  30493. +vchiq-objs := \
  30494. + interface/vchiq_arm/vchiq_core.o \
  30495. + interface/vchiq_arm/vchiq_arm.o \
  30496. + interface/vchiq_arm/vchiq_kern_lib.o \
  30497. + interface/vchiq_arm/vchiq_2835_arm.o \
  30498. + interface/vchiq_arm/vchiq_proc.o \
  30499. + interface/vchiq_arm/vchiq_shim.o \
  30500. + interface/vchiq_arm/vchiq_util.o \
  30501. + interface/vchiq_arm/vchiq_connected.o \
  30502. +
  30503. +ccflags-y += -DVCOS_VERIFY_BKPTS=1 -Idrivers/misc/vc04_services -DUSE_VCHIQ_ARM -D__VCCOREVER__=0x04000000
  30504. +
  30505. +endif
  30506. diff -Nur linux-3.12.26.orig/drivers/mmc/card/block.c linux-3.12.26/drivers/mmc/card/block.c
  30507. --- linux-3.12.26.orig/drivers/mmc/card/block.c 2014-07-30 18:02:44.000000000 +0200
  30508. +++ linux-3.12.26/drivers/mmc/card/block.c 2014-08-06 16:50:14.533962622 +0200
  30509. @@ -1361,7 +1361,7 @@
  30510. brq->data.blocks = 1;
  30511. }
  30512. - if (brq->data.blocks > 1 || do_rel_wr) {
  30513. + if (brq->data.blocks > 1 || do_rel_wr || card->host->caps2 & MMC_CAP2_FORCE_MULTIBLOCK) {
  30514. /* SPI multiblock writes terminate using a special
  30515. * token, not a STOP_TRANSMISSION request.
  30516. */
  30517. diff -Nur linux-3.12.26.orig/drivers/mmc/core/sd.c linux-3.12.26/drivers/mmc/core/sd.c
  30518. --- linux-3.12.26.orig/drivers/mmc/core/sd.c 2014-07-30 18:02:44.000000000 +0200
  30519. +++ linux-3.12.26/drivers/mmc/core/sd.c 2014-08-06 16:50:14.553962779 +0200
  30520. @@ -14,6 +14,8 @@
  30521. #include <linux/sizes.h>
  30522. #include <linux/slab.h>
  30523. #include <linux/stat.h>
  30524. +#include <linux/jiffies.h>
  30525. +#include <linux/nmi.h>
  30526. #include <linux/mmc/host.h>
  30527. #include <linux/mmc/card.h>
  30528. @@ -66,6 +68,15 @@
  30529. __res & __mask; \
  30530. })
  30531. +// timeout for tries
  30532. +static const unsigned long retry_timeout_ms= 10*1000;
  30533. +
  30534. +// try at least 10 times, even if timeout is reached
  30535. +static const int retry_min_tries= 10;
  30536. +
  30537. +// delay between tries
  30538. +static const unsigned long retry_delay_ms= 10;
  30539. +
  30540. /*
  30541. * Given the decoded CSD structure, decode the raw CID to our CID structure.
  30542. */
  30543. @@ -218,12 +229,63 @@
  30544. }
  30545. /*
  30546. - * Fetch and process SD Status register.
  30547. + * Fetch and process SD Configuration Register.
  30548. + */
  30549. +static int mmc_read_scr(struct mmc_card *card)
  30550. +{
  30551. + unsigned long timeout_at;
  30552. + int err, tries;
  30553. +
  30554. + timeout_at= jiffies + msecs_to_jiffies( retry_timeout_ms );
  30555. + tries= 0;
  30556. +
  30557. + while( tries < retry_min_tries || time_before( jiffies, timeout_at ) )
  30558. + {
  30559. + unsigned long delay_at;
  30560. + tries++;
  30561. +
  30562. + err = mmc_app_send_scr(card, card->raw_scr);
  30563. + if( !err )
  30564. + break; // success!!!
  30565. +
  30566. + touch_nmi_watchdog(); // we are still alive!
  30567. +
  30568. + // delay
  30569. + delay_at= jiffies + msecs_to_jiffies( retry_delay_ms );
  30570. + while( time_before( jiffies, delay_at ) )
  30571. + {
  30572. + mdelay( 1 );
  30573. + touch_nmi_watchdog(); // we are still alive!
  30574. + }
  30575. + }
  30576. +
  30577. + if( err)
  30578. + {
  30579. + 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 );
  30580. + return err;
  30581. + }
  30582. +
  30583. + if( tries > 1 )
  30584. + {
  30585. + pr_info("%s: could read SD Configuration register (SCR) at the %dth attempt\n", mmc_hostname(card->host), tries );
  30586. + }
  30587. +
  30588. + err = mmc_decode_scr(card);
  30589. + if (err)
  30590. + return err;
  30591. +
  30592. + return err;
  30593. +}
  30594. +
  30595. +/*
  30596. + * Fetch and process SD Status Register.
  30597. */
  30598. static int mmc_read_ssr(struct mmc_card *card)
  30599. {
  30600. + unsigned long timeout_at;
  30601. unsigned int au, es, et, eo;
  30602. int err, i;
  30603. + int tries;
  30604. u32 *ssr;
  30605. if (!(card->csd.cmdclass & CCC_APP_SPEC)) {
  30606. @@ -236,14 +298,40 @@
  30607. if (!ssr)
  30608. return -ENOMEM;
  30609. - err = mmc_app_sd_status(card, ssr);
  30610. - if (err) {
  30611. - pr_warning("%s: problem reading SD Status "
  30612. - "register.\n", mmc_hostname(card->host));
  30613. - err = 0;
  30614. + timeout_at= jiffies + msecs_to_jiffies( retry_timeout_ms );
  30615. + tries= 0;
  30616. +
  30617. + while( tries < retry_min_tries || time_before( jiffies, timeout_at ) )
  30618. + {
  30619. + unsigned long delay_at;
  30620. + tries++;
  30621. +
  30622. + err= mmc_app_sd_status(card, ssr);
  30623. + if( !err )
  30624. + break; // sucess!!!
  30625. +
  30626. + touch_nmi_watchdog(); // we are still alive!
  30627. +
  30628. + // delay
  30629. + delay_at= jiffies + msecs_to_jiffies( retry_delay_ms );
  30630. + while( time_before( jiffies, delay_at ) )
  30631. + {
  30632. + mdelay( 1 );
  30633. + touch_nmi_watchdog(); // we are still alive!
  30634. + }
  30635. + }
  30636. +
  30637. + if( err)
  30638. + {
  30639. + 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 );
  30640. goto out;
  30641. }
  30642. + if( tries > 1 )
  30643. + {
  30644. + pr_info("%s: read SD Status register (SSR) after %d attempts\n", mmc_hostname(card->host), tries );
  30645. + }
  30646. +
  30647. for (i = 0; i < 16; i++)
  30648. ssr[i] = be32_to_cpu(ssr[i]);
  30649. @@ -823,14 +911,10 @@
  30650. if (!reinit) {
  30651. /*
  30652. - * Fetch SCR from card.
  30653. + * Fetch and decode SD Configuration register.
  30654. */
  30655. - err = mmc_app_send_scr(card, card->raw_scr);
  30656. - if (err)
  30657. - return err;
  30658. -
  30659. - err = mmc_decode_scr(card);
  30660. - if (err)
  30661. + err = mmc_read_scr(card);
  30662. + if( err )
  30663. return err;
  30664. /*
  30665. diff -Nur linux-3.12.26.orig/drivers/mmc/host/Kconfig linux-3.12.26/drivers/mmc/host/Kconfig
  30666. --- linux-3.12.26.orig/drivers/mmc/host/Kconfig 2014-07-30 18:02:44.000000000 +0200
  30667. +++ linux-3.12.26/drivers/mmc/host/Kconfig 2014-08-06 16:50:14.569962904 +0200
  30668. @@ -260,6 +260,27 @@
  30669. If you have a controller with this interface, say Y or M here.
  30670. +config MMC_SDHCI_BCM2708
  30671. + tristate "SDHCI support on BCM2708"
  30672. + depends on MMC_SDHCI && MACH_BCM2708
  30673. + select MMC_SDHCI_IO_ACCESSORS
  30674. + help
  30675. + This selects the Secure Digital Host Controller Interface (SDHCI)
  30676. + often referrered to as the eMMC block.
  30677. +
  30678. + If you have a controller with this interface, say Y or M here.
  30679. +
  30680. + If unsure, say N.
  30681. +
  30682. +config MMC_SDHCI_BCM2708_DMA
  30683. + bool "DMA support on BCM2708 Arasan controller"
  30684. + depends on MMC_SDHCI_BCM2708
  30685. + help
  30686. + Enable DMA support on the Arasan SDHCI controller in Broadcom 2708
  30687. + based chips.
  30688. +
  30689. + If unsure, say N.
  30690. +
  30691. config MMC_SDHCI_BCM2835
  30692. tristate "SDHCI platform support for the BCM2835 SD/MMC Controller"
  30693. depends on ARCH_BCM2835
  30694. diff -Nur linux-3.12.26.orig/drivers/mmc/host/Makefile linux-3.12.26/drivers/mmc/host/Makefile
  30695. --- linux-3.12.26.orig/drivers/mmc/host/Makefile 2014-07-30 18:02:44.000000000 +0200
  30696. +++ linux-3.12.26/drivers/mmc/host/Makefile 2014-08-06 16:50:14.569962904 +0200
  30697. @@ -15,6 +15,7 @@
  30698. obj-$(CONFIG_MMC_SDHCI_S3C) += sdhci-s3c.o
  30699. obj-$(CONFIG_MMC_SDHCI_SIRF) += sdhci-sirf.o
  30700. obj-$(CONFIG_MMC_SDHCI_SPEAR) += sdhci-spear.o
  30701. +obj-$(CONFIG_MMC_SDHCI_BCM2708) += sdhci-bcm2708.o
  30702. obj-$(CONFIG_MMC_WBSD) += wbsd.o
  30703. obj-$(CONFIG_MMC_AU1X) += au1xmmc.o
  30704. obj-$(CONFIG_MMC_OMAP) += omap.o
  30705. diff -Nur linux-3.12.26.orig/drivers/mmc/host/sdhci-bcm2708.c linux-3.12.26/drivers/mmc/host/sdhci-bcm2708.c
  30706. --- linux-3.12.26.orig/drivers/mmc/host/sdhci-bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  30707. +++ linux-3.12.26/drivers/mmc/host/sdhci-bcm2708.c 2014-08-06 16:50:14.569962904 +0200
  30708. @@ -0,0 +1,1410 @@
  30709. +/*
  30710. + * sdhci-bcm2708.c Support for SDHCI device on BCM2708
  30711. + * Copyright (c) 2010 Broadcom
  30712. + *
  30713. + * This program is free software; you can redistribute it and/or modify
  30714. + * it under the terms of the GNU General Public License version 2 as
  30715. + * published by the Free Software Foundation.
  30716. + *
  30717. + * This program is distributed in the hope that it will be useful,
  30718. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  30719. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  30720. + * GNU General Public License for more details.
  30721. + *
  30722. + * You should have received a copy of the GNU General Public License
  30723. + * along with this program; if not, write to the Free Software
  30724. + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  30725. + */
  30726. +
  30727. +/* Supports:
  30728. + * SDHCI platform device - Arasan SD controller in BCM2708
  30729. + *
  30730. + * Inspired by sdhci-pci.c, by Pierre Ossman
  30731. + */
  30732. +
  30733. +#include <linux/delay.h>
  30734. +#include <linux/highmem.h>
  30735. +#include <linux/platform_device.h>
  30736. +#include <linux/module.h>
  30737. +#include <linux/mmc/mmc.h>
  30738. +#include <linux/mmc/host.h>
  30739. +#include <linux/mmc/sd.h>
  30740. +
  30741. +#include <linux/io.h>
  30742. +#include <linux/dma-mapping.h>
  30743. +#include <mach/dma.h>
  30744. +
  30745. +#include "sdhci.h"
  30746. +
  30747. +/*****************************************************************************\
  30748. + * *
  30749. + * Configuration *
  30750. + * *
  30751. +\*****************************************************************************/
  30752. +
  30753. +#define DRIVER_NAME "bcm2708_sdhci"
  30754. +
  30755. +/* for the time being insist on DMA mode - PIO seems not to work */
  30756. +#ifndef CONFIG_MMC_SDHCI_BCM2708_DMA
  30757. +#warning Non-DMA (PIO) version of this driver currently unavailable
  30758. +#endif
  30759. +#undef CONFIG_MMC_SDHCI_BCM2708_DMA
  30760. +#define CONFIG_MMC_SDHCI_BCM2708_DMA y
  30761. +
  30762. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  30763. +/* #define CHECK_DMA_USE */
  30764. +#endif
  30765. +//#define LOG_REGISTERS
  30766. +
  30767. +#define USE_SCHED_TIME
  30768. +#define USE_SPACED_WRITES_2CLK 1 /* space consecutive register writes */
  30769. +#define USE_SOFTWARE_TIMEOUTS 1 /* not hardware timeouts */
  30770. +#define SOFTWARE_ERASE_TIMEOUT_SEC 30
  30771. +
  30772. +#define SDHCI_BCM_DMA_CHAN 4 /* this default is normally overriden */
  30773. +#define SDHCI_BCM_DMA_WAITS 0 /* delays slowing DMA transfers: 0-31 */
  30774. +/* We are worried that SD card DMA use may be blocking the AXI bus for others */
  30775. +
  30776. +/*! TODO: obtain these from the physical address */
  30777. +#define DMA_SDHCI_BASE 0x7e300000 /* EMMC register block on Videocore */
  30778. +#define DMA_SDHCI_BUFFER (DMA_SDHCI_BASE + SDHCI_BUFFER)
  30779. +
  30780. +#define BCM2708_SDHCI_SLEEP_TIMEOUT 1000 /* msecs */
  30781. +
  30782. +/* Mhz clock that the EMMC core is running at. Should match the platform clockman settings */
  30783. +#define BCM2708_EMMC_CLOCK_FREQ 50000000
  30784. +
  30785. +#define REG_EXRDFIFO_EN 0x80
  30786. +#define REG_EXRDFIFO_CFG 0x84
  30787. +
  30788. +int cycle_delay=2;
  30789. +
  30790. +/*****************************************************************************\
  30791. + * *
  30792. + * Debug *
  30793. + * *
  30794. +\*****************************************************************************/
  30795. +
  30796. +
  30797. +
  30798. +#define DBG(f, x...) \
  30799. + pr_debug(DRIVER_NAME " [%s()]: " f, __func__,## x)
  30800. +// printk(KERN_INFO DRIVER_NAME " [%s()]: " f, __func__,## x)//GRAYG
  30801. +
  30802. +
  30803. +/*****************************************************************************\
  30804. + * *
  30805. + * High Precision Time *
  30806. + * *
  30807. +\*****************************************************************************/
  30808. +
  30809. +#ifdef USE_SCHED_TIME
  30810. +
  30811. +#include <mach/frc.h>
  30812. +
  30813. +typedef unsigned long hptime_t;
  30814. +
  30815. +#define FMT_HPT "lu"
  30816. +
  30817. +static inline hptime_t hptime(void)
  30818. +{
  30819. + return frc_clock_ticks32();
  30820. +}
  30821. +
  30822. +#define HPTIME_CLK_NS 1000ul
  30823. +
  30824. +#else
  30825. +
  30826. +typedef unsigned long hptime_t;
  30827. +
  30828. +#define FMT_HPT "lu"
  30829. +
  30830. +static inline hptime_t hptime(void)
  30831. +{
  30832. + return jiffies;
  30833. +}
  30834. +
  30835. +#define HPTIME_CLK_NS (1000000000ul/HZ)
  30836. +
  30837. +#endif
  30838. +
  30839. +static inline unsigned long int since_ns(hptime_t t)
  30840. +{
  30841. + return (unsigned long)((hptime() - t) * HPTIME_CLK_NS);
  30842. +}
  30843. +
  30844. +static bool allow_highspeed = 1;
  30845. +static int emmc_clock_freq = BCM2708_EMMC_CLOCK_FREQ;
  30846. +static bool sync_after_dma = 1;
  30847. +static bool missing_status = 1;
  30848. +static bool spurious_crc_acmd51 = 0;
  30849. +bool enable_llm = 1;
  30850. +bool extra_messages = 0;
  30851. +
  30852. +#if 0
  30853. +static void hptime_test(void)
  30854. +{
  30855. + hptime_t now;
  30856. + hptime_t later;
  30857. +
  30858. + now = hptime();
  30859. + msleep(10);
  30860. + later = hptime();
  30861. +
  30862. + printk(KERN_INFO DRIVER_NAME": 10ms = %"FMT_HPT" clks "
  30863. + "(from %"FMT_HPT" to %"FMT_HPT") = %luns\n",
  30864. + later-now, now, later,
  30865. + (unsigned long)(HPTIME_CLK_NS * (later - now)));
  30866. +
  30867. + now = hptime();
  30868. + msleep(1000);
  30869. + later = hptime();
  30870. +
  30871. + printk(KERN_INFO DRIVER_NAME": 1s = %"FMT_HPT" clks "
  30872. + "(from %"FMT_HPT" to %"FMT_HPT") = %luns\n",
  30873. + later-now, now, later,
  30874. + (unsigned long)(HPTIME_CLK_NS * (later - now)));
  30875. +}
  30876. +#endif
  30877. +
  30878. +/*****************************************************************************\
  30879. + * *
  30880. + * SDHCI core callbacks *
  30881. + * *
  30882. +\*****************************************************************************/
  30883. +
  30884. +
  30885. +#ifdef CHECK_DMA_USE
  30886. +/*#define CHECK_DMA_REG_USE*/
  30887. +#endif
  30888. +
  30889. +#ifdef CHECK_DMA_REG_USE
  30890. +/* we don't expect anything to be using these registers during a
  30891. + DMA (except the IRQ status) - so check */
  30892. +static void check_dma_reg_use(struct sdhci_host *host, int reg);
  30893. +#else
  30894. +#define check_dma_reg_use(host, reg)
  30895. +#endif
  30896. +
  30897. +
  30898. +static inline u32 sdhci_bcm2708_raw_readl(struct sdhci_host *host, int reg)
  30899. +{
  30900. + return readl(host->ioaddr + reg);
  30901. +}
  30902. +
  30903. +u32 sdhci_bcm2708_readl(struct sdhci_host *host, int reg)
  30904. +{
  30905. + u32 l = sdhci_bcm2708_raw_readl(host, reg);
  30906. +
  30907. +#ifdef LOG_REGISTERS
  30908. + printk(KERN_ERR "%s: readl from 0x%02x, value 0x%08x\n",
  30909. + mmc_hostname(host->mmc), reg, l);
  30910. +#endif
  30911. + check_dma_reg_use(host, reg);
  30912. +
  30913. + return l;
  30914. +}
  30915. +
  30916. +u16 sdhci_bcm2708_readw(struct sdhci_host *host, int reg)
  30917. +{
  30918. + u32 l = sdhci_bcm2708_raw_readl(host, reg & ~3);
  30919. + u32 w = l >> (reg << 3 & 0x18) & 0xffff;
  30920. +
  30921. +#ifdef LOG_REGISTERS
  30922. + printk(KERN_ERR "%s: readw from 0x%02x, value 0x%04x\n",
  30923. + mmc_hostname(host->mmc), reg, w);
  30924. +#endif
  30925. + check_dma_reg_use(host, reg);
  30926. +
  30927. + return (u16)w;
  30928. +}
  30929. +
  30930. +u8 sdhci_bcm2708_readb(struct sdhci_host *host, int reg)
  30931. +{
  30932. + u32 l = sdhci_bcm2708_raw_readl(host, reg & ~3);
  30933. + u32 b = l >> (reg << 3 & 0x18) & 0xff;
  30934. +
  30935. +#ifdef LOG_REGISTERS
  30936. + printk(KERN_ERR "%s: readb from 0x%02x, value 0x%02x\n",
  30937. + mmc_hostname(host->mmc), reg, b);
  30938. +#endif
  30939. + check_dma_reg_use(host, reg);
  30940. +
  30941. + return (u8)b;
  30942. +}
  30943. +
  30944. +
  30945. +static void sdhci_bcm2708_raw_writel(struct sdhci_host *host, u32 val, int reg)
  30946. +{
  30947. + u32 ier;
  30948. +
  30949. +#if USE_SPACED_WRITES_2CLK
  30950. + static bool timeout_disabled = false;
  30951. + unsigned int ns_2clk = 0;
  30952. +
  30953. + /* The Arasan has a bugette whereby it may lose the content of
  30954. + * successive writes to registers that are within two SD-card clock
  30955. + * cycles of each other (a clock domain crossing problem).
  30956. + * It seems, however, that the data register does not have this problem.
  30957. + * (Which is just as well - otherwise we'd have to nobble the DMA engine
  30958. + * too)
  30959. + */
  30960. + if (reg != SDHCI_BUFFER && host->clock != 0) {
  30961. + /* host->clock is the clock freq in Hz */
  30962. + static hptime_t last_write_hpt;
  30963. + hptime_t now = hptime();
  30964. + ns_2clk = cycle_delay*1000000/(host->clock/1000);
  30965. +
  30966. + if (now == last_write_hpt || now == last_write_hpt+1) {
  30967. + /* we can't guarantee any significant time has
  30968. + * passed - we'll have to wait anyway ! */
  30969. + ndelay(ns_2clk);
  30970. + } else
  30971. + {
  30972. + /* we must have waited at least this many ns: */
  30973. + unsigned int ns_wait = HPTIME_CLK_NS *
  30974. + (now - last_write_hpt - 1);
  30975. + if (ns_wait < ns_2clk)
  30976. + ndelay(ns_2clk - ns_wait);
  30977. + }
  30978. + last_write_hpt = now;
  30979. + }
  30980. +#if USE_SOFTWARE_TIMEOUTS
  30981. + /* The Arasan is clocked for timeouts using the SD clock which is too
  30982. + * fast for ERASE commands and causes issues. So we disable timeouts
  30983. + * for ERASE */
  30984. + if (host->cmd != NULL && host->cmd->opcode == MMC_ERASE &&
  30985. + reg == (SDHCI_COMMAND & ~3)) {
  30986. + mod_timer(&host->timer,
  30987. + jiffies + SOFTWARE_ERASE_TIMEOUT_SEC * HZ);
  30988. + ier = readl(host->ioaddr + SDHCI_SIGNAL_ENABLE);
  30989. + ier &= ~SDHCI_INT_DATA_TIMEOUT;
  30990. + writel(ier, host->ioaddr + SDHCI_SIGNAL_ENABLE);
  30991. + timeout_disabled = true;
  30992. + ndelay(ns_2clk);
  30993. + } else if (timeout_disabled) {
  30994. + ier = readl(host->ioaddr + SDHCI_SIGNAL_ENABLE);
  30995. + ier |= SDHCI_INT_DATA_TIMEOUT;
  30996. + writel(ier, host->ioaddr + SDHCI_SIGNAL_ENABLE);
  30997. + timeout_disabled = false;
  30998. + ndelay(ns_2clk);
  30999. + }
  31000. +#endif
  31001. + writel(val, host->ioaddr + reg);
  31002. +#else
  31003. + void __iomem * regaddr = host->ioaddr + reg;
  31004. +
  31005. + writel(val, regaddr);
  31006. +
  31007. + if (reg != SDHCI_BUFFER && reg != SDHCI_INT_STATUS && host->clock != 0)
  31008. + {
  31009. + int timeout = 100000;
  31010. + while (val != readl(regaddr) && --timeout > 0)
  31011. + continue;
  31012. +
  31013. + if (timeout <= 0)
  31014. + printk(KERN_ERR "%s: writing 0x%X to reg 0x%X "
  31015. + "always gives 0x%X\n",
  31016. + mmc_hostname(host->mmc),
  31017. + val, reg, readl(regaddr));
  31018. + BUG_ON(timeout <= 0);
  31019. + }
  31020. +#endif
  31021. +}
  31022. +
  31023. +
  31024. +void sdhci_bcm2708_writel(struct sdhci_host *host, u32 val, int reg)
  31025. +{
  31026. +#ifdef LOG_REGISTERS
  31027. + printk(KERN_ERR "%s: writel to 0x%02x, value 0x%08x\n",
  31028. + mmc_hostname(host->mmc), reg, val);
  31029. +#endif
  31030. + check_dma_reg_use(host, reg);
  31031. +
  31032. + sdhci_bcm2708_raw_writel(host, val, reg);
  31033. +}
  31034. +
  31035. +void sdhci_bcm2708_writew(struct sdhci_host *host, u16 val, int reg)
  31036. +{
  31037. + static u32 shadow = 0;
  31038. +
  31039. + u32 p = reg == SDHCI_COMMAND ? shadow :
  31040. + sdhci_bcm2708_raw_readl(host, reg & ~3);
  31041. + u32 s = reg << 3 & 0x18;
  31042. + u32 l = val << s;
  31043. + u32 m = 0xffff << s;
  31044. +
  31045. +#ifdef LOG_REGISTERS
  31046. + printk(KERN_ERR "%s: writew to 0x%02x, value 0x%04x\n",
  31047. + mmc_hostname(host->mmc), reg, val);
  31048. +#endif
  31049. +
  31050. + if (reg == SDHCI_TRANSFER_MODE)
  31051. + shadow = (p & ~m) | l;
  31052. + else {
  31053. + check_dma_reg_use(host, reg);
  31054. + sdhci_bcm2708_raw_writel(host, (p & ~m) | l, reg & ~3);
  31055. + }
  31056. +}
  31057. +
  31058. +void sdhci_bcm2708_writeb(struct sdhci_host *host, u8 val, int reg)
  31059. +{
  31060. + u32 p = sdhci_bcm2708_raw_readl(host, reg & ~3);
  31061. + u32 s = reg << 3 & 0x18;
  31062. + u32 l = val << s;
  31063. + u32 m = 0xff << s;
  31064. +
  31065. +#ifdef LOG_REGISTERS
  31066. + printk(KERN_ERR "%s: writeb to 0x%02x, value 0x%02x\n",
  31067. + mmc_hostname(host->mmc), reg, val);
  31068. +#endif
  31069. +
  31070. + check_dma_reg_use(host, reg);
  31071. + sdhci_bcm2708_raw_writel(host, (p & ~m) | l, reg & ~3);
  31072. +}
  31073. +
  31074. +static unsigned int sdhci_bcm2708_get_max_clock(struct sdhci_host *host)
  31075. +{
  31076. + return emmc_clock_freq;
  31077. +}
  31078. +
  31079. +/*****************************************************************************\
  31080. + * *
  31081. + * DMA Operation *
  31082. + * *
  31083. +\*****************************************************************************/
  31084. +
  31085. +struct sdhci_bcm2708_priv {
  31086. + int dma_chan;
  31087. + int dma_irq;
  31088. + void __iomem *dma_chan_base;
  31089. + struct bcm2708_dma_cb *cb_base; /* DMA control blocks */
  31090. + dma_addr_t cb_handle;
  31091. + /* tracking scatter gather progress */
  31092. + unsigned sg_ix; /* scatter gather list index */
  31093. + unsigned sg_done; /* bytes in current sg_ix done */
  31094. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31095. + unsigned char dma_wanted; /* DMA transfer requested */
  31096. + unsigned char dma_waits; /* wait states in DMAs */
  31097. +#ifdef CHECK_DMA_USE
  31098. + unsigned char dmas_pending; /* no of unfinished DMAs */
  31099. + hptime_t when_started;
  31100. + hptime_t when_reset;
  31101. + hptime_t when_stopped;
  31102. +#endif
  31103. +#endif
  31104. + /* signalling the end of a transfer */
  31105. + void (*complete)(struct sdhci_host *);
  31106. +};
  31107. +
  31108. +#define SDHCI_HOST_PRIV(host) \
  31109. + (struct sdhci_bcm2708_priv *)((struct sdhci_host *)(host)+1)
  31110. +
  31111. +
  31112. +
  31113. +#ifdef CHECK_DMA_REG_USE
  31114. +static void check_dma_reg_use(struct sdhci_host *host, int reg)
  31115. +{
  31116. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31117. + if (host_priv->dma_wanted && reg != SDHCI_INT_STATUS) {
  31118. + printk(KERN_INFO"%s: accessing register 0x%x during DMA\n",
  31119. + mmc_hostname(host->mmc), reg);
  31120. + }
  31121. +}
  31122. +#endif
  31123. +
  31124. +
  31125. +
  31126. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31127. +
  31128. +static void sdhci_clear_set_irqgen(struct sdhci_host *host, u32 clear, u32 set)
  31129. +{
  31130. + u32 ier;
  31131. +
  31132. + ier = sdhci_bcm2708_raw_readl(host, SDHCI_SIGNAL_ENABLE);
  31133. + ier &= ~clear;
  31134. + ier |= set;
  31135. + /* change which requests generate IRQs - makes no difference to
  31136. + the content of SDHCI_INT_STATUS, or the need to acknowledge IRQs */
  31137. + sdhci_bcm2708_raw_writel(host, ier, SDHCI_SIGNAL_ENABLE);
  31138. +}
  31139. +
  31140. +static void sdhci_signal_irqs(struct sdhci_host *host, u32 irqs)
  31141. +{
  31142. + sdhci_clear_set_irqgen(host, 0, irqs);
  31143. +}
  31144. +
  31145. +static void sdhci_unsignal_irqs(struct sdhci_host *host, u32 irqs)
  31146. +{
  31147. + sdhci_clear_set_irqgen(host, irqs, 0);
  31148. +}
  31149. +
  31150. +
  31151. +
  31152. +static void schci_bcm2708_cb_read(struct sdhci_bcm2708_priv *host,
  31153. + int ix,
  31154. + dma_addr_t dma_addr, unsigned len,
  31155. + int /*bool*/ is_last)
  31156. +{
  31157. + struct bcm2708_dma_cb *cb = &host->cb_base[ix];
  31158. + unsigned char dmawaits = host->dma_waits;
  31159. +
  31160. + cb->info = BCM2708_DMA_PER_MAP(BCM2708_DMA_DREQ_EMMC) |
  31161. + BCM2708_DMA_WAITS(dmawaits) |
  31162. + BCM2708_DMA_S_DREQ |
  31163. + BCM2708_DMA_D_WIDTH |
  31164. + BCM2708_DMA_D_INC;
  31165. + cb->src = DMA_SDHCI_BUFFER; /* DATA register DMA address */
  31166. + cb->dst = dma_addr;
  31167. + cb->length = len;
  31168. + cb->stride = 0;
  31169. +
  31170. + if (is_last) {
  31171. + cb->info |= BCM2708_DMA_INT_EN |
  31172. + BCM2708_DMA_WAIT_RESP;
  31173. + cb->next = 0;
  31174. + } else
  31175. + cb->next = host->cb_handle +
  31176. + (ix+1)*sizeof(struct bcm2708_dma_cb);
  31177. +
  31178. + cb->pad[0] = 0;
  31179. + cb->pad[1] = 0;
  31180. +}
  31181. +
  31182. +static void schci_bcm2708_cb_write(struct sdhci_bcm2708_priv *host,
  31183. + int ix,
  31184. + dma_addr_t dma_addr, unsigned len,
  31185. + int /*bool*/ is_last)
  31186. +{
  31187. + struct bcm2708_dma_cb *cb = &host->cb_base[ix];
  31188. + unsigned char dmawaits = host->dma_waits;
  31189. +
  31190. + /* We can make arbitrarily large writes as long as we specify DREQ to
  31191. + pace the delivery of bytes to the Arasan hardware */
  31192. + cb->info = BCM2708_DMA_PER_MAP(BCM2708_DMA_DREQ_EMMC) |
  31193. + BCM2708_DMA_WAITS(dmawaits) |
  31194. + BCM2708_DMA_D_DREQ |
  31195. + BCM2708_DMA_S_WIDTH |
  31196. + BCM2708_DMA_S_INC;
  31197. + cb->src = dma_addr;
  31198. + cb->dst = DMA_SDHCI_BUFFER; /* DATA register DMA address */
  31199. + cb->length = len;
  31200. + cb->stride = 0;
  31201. +
  31202. + if (is_last) {
  31203. + cb->info |= BCM2708_DMA_INT_EN |
  31204. + BCM2708_DMA_WAIT_RESP;
  31205. + cb->next = 0;
  31206. + } else
  31207. + cb->next = host->cb_handle +
  31208. + (ix+1)*sizeof(struct bcm2708_dma_cb);
  31209. +
  31210. + cb->pad[0] = 0;
  31211. + cb->pad[1] = 0;
  31212. +}
  31213. +
  31214. +
  31215. +static void schci_bcm2708_dma_go(struct sdhci_host *host)
  31216. +{
  31217. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31218. + void __iomem *dma_chan_base = host_priv->dma_chan_base;
  31219. +
  31220. + BUG_ON(host_priv->dma_wanted);
  31221. +#ifdef CHECK_DMA_USE
  31222. + if (host_priv->dma_wanted)
  31223. + printk(KERN_ERR "%s: DMA already in progress - "
  31224. + "now %"FMT_HPT", last started %lu "
  31225. + "reset %lu stopped %lu\n",
  31226. + mmc_hostname(host->mmc),
  31227. + hptime(), since_ns(host_priv->when_started),
  31228. + since_ns(host_priv->when_reset),
  31229. + since_ns(host_priv->when_stopped));
  31230. + else if (host_priv->dmas_pending > 0)
  31231. + printk(KERN_INFO "%s: note - new DMA when %d reset DMAs "
  31232. + "already in progress - "
  31233. + "now %"FMT_HPT", started %lu reset %lu stopped %lu\n",
  31234. + mmc_hostname(host->mmc),
  31235. + host_priv->dmas_pending,
  31236. + hptime(), since_ns(host_priv->when_started),
  31237. + since_ns(host_priv->when_reset),
  31238. + since_ns(host_priv->when_stopped));
  31239. + host_priv->dmas_pending += 1;
  31240. + host_priv->when_started = hptime();
  31241. +#endif
  31242. + host_priv->dma_wanted = 1;
  31243. + DBG("PDMA go - base %p handle %08X\n", dma_chan_base,
  31244. + host_priv->cb_handle);
  31245. + bcm_dma_start(dma_chan_base, host_priv->cb_handle);
  31246. +}
  31247. +
  31248. +
  31249. +static void
  31250. +sdhci_platdma_read(struct sdhci_host *host, dma_addr_t dma_addr, size_t len)
  31251. +{
  31252. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31253. +
  31254. + DBG("PDMA to read %d bytes\n", len);
  31255. + host_priv->sg_done += len;
  31256. + schci_bcm2708_cb_read(host_priv, 0, dma_addr, len, 1/*TRUE*/);
  31257. + schci_bcm2708_dma_go(host);
  31258. +}
  31259. +
  31260. +
  31261. +static void
  31262. +sdhci_platdma_write(struct sdhci_host *host, dma_addr_t dma_addr, size_t len)
  31263. +{
  31264. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31265. +
  31266. + DBG("PDMA to write %d bytes\n", len);
  31267. + //BUG_ON(0 != (len & 0x1ff));
  31268. +
  31269. + host_priv->sg_done += len;
  31270. + schci_bcm2708_cb_write(host_priv, 0, dma_addr, len, 1/*TRUE*/);
  31271. + schci_bcm2708_dma_go(host);
  31272. +}
  31273. +
  31274. +/*! space is avaiable to receive into or data is available to write
  31275. + Platform DMA exported function
  31276. +*/
  31277. +void
  31278. +sdhci_bcm2708_platdma_avail(struct sdhci_host *host, unsigned int *ref_intmask,
  31279. + void(*completion_callback)(struct sdhci_host *host))
  31280. +{
  31281. + struct mmc_data *data = host->data;
  31282. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31283. + int sg_ix;
  31284. + size_t bytes;
  31285. + dma_addr_t addr;
  31286. +
  31287. + BUG_ON(NULL == data);
  31288. + BUG_ON(0 == data->blksz);
  31289. +
  31290. + host_priv->complete = completion_callback;
  31291. +
  31292. + sg_ix = host_priv->sg_ix;
  31293. + BUG_ON(sg_ix >= data->sg_len);
  31294. +
  31295. + /* we can DMA blocks larger than blksz - it may hang the DMA
  31296. + channel but we are its only user */
  31297. + bytes = sg_dma_len(&data->sg[sg_ix]) - host_priv->sg_done;
  31298. + addr = sg_dma_address(&data->sg[sg_ix]) + host_priv->sg_done;
  31299. +
  31300. + if (bytes > 0) {
  31301. + /* We're going to poll for read/write available state until
  31302. + we finish this DMA
  31303. + */
  31304. +
  31305. + if (data->flags & MMC_DATA_READ) {
  31306. + if (*ref_intmask & SDHCI_INT_DATA_AVAIL) {
  31307. + sdhci_unsignal_irqs(host, SDHCI_INT_DATA_AVAIL |
  31308. + SDHCI_INT_SPACE_AVAIL);
  31309. + sdhci_platdma_read(host, addr, bytes);
  31310. + }
  31311. + } else {
  31312. + if (*ref_intmask & SDHCI_INT_SPACE_AVAIL) {
  31313. + sdhci_unsignal_irqs(host, SDHCI_INT_DATA_AVAIL |
  31314. + SDHCI_INT_SPACE_AVAIL);
  31315. + sdhci_platdma_write(host, addr, bytes);
  31316. + }
  31317. + }
  31318. + }
  31319. + /* else:
  31320. + we have run out of bytes that need transferring (e.g. we may be in
  31321. + the middle of the last DMA transfer), or
  31322. + it is also possible that we've been called when another IRQ is
  31323. + signalled, even though we've turned off signalling of our own IRQ */
  31324. +
  31325. + *ref_intmask &= ~SDHCI_INT_DATA_END;
  31326. + /* don't let the main sdhci driver act on this .. we'll deal with it
  31327. + when we respond to the DMA - if one is currently in progress */
  31328. +}
  31329. +
  31330. +/* is it possible to DMA the given mmc_data structure?
  31331. + Platform DMA exported function
  31332. +*/
  31333. +int /*bool*/
  31334. +sdhci_bcm2708_platdma_dmaable(struct sdhci_host *host, struct mmc_data *data)
  31335. +{
  31336. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31337. + int ok = bcm_sg_suitable_for_dma(data->sg, data->sg_len);
  31338. +
  31339. + if (!ok)
  31340. + DBG("Reverting to PIO - bad cache alignment\n");
  31341. +
  31342. + else {
  31343. + host_priv->sg_ix = 0; /* first SG index */
  31344. + host_priv->sg_done = 0; /* no bytes done */
  31345. + }
  31346. +
  31347. + return ok;
  31348. +}
  31349. +
  31350. +#include <mach/arm_control.h> //GRAYG
  31351. +/*! the current SD transacton has been abandonned
  31352. + We need to tidy up if we were in the middle of a DMA
  31353. + Platform DMA exported function
  31354. +*/
  31355. +void
  31356. +sdhci_bcm2708_platdma_reset(struct sdhci_host *host, struct mmc_data *data)
  31357. +{
  31358. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31359. +// unsigned long flags;
  31360. +
  31361. + BUG_ON(NULL == host);
  31362. +
  31363. +// spin_lock_irqsave(&host->lock, flags);
  31364. +
  31365. + if (host_priv->dma_wanted) {
  31366. + if (NULL == data) {
  31367. + printk(KERN_ERR "%s: ongoing DMA reset - no data!\n",
  31368. + mmc_hostname(host->mmc));
  31369. + BUG_ON(NULL == data);
  31370. + } else {
  31371. + struct scatterlist *sg;
  31372. + int sg_len;
  31373. + int sg_todo;
  31374. + int rc;
  31375. + unsigned long cs;
  31376. +
  31377. + sg = data->sg;
  31378. + sg_len = data->sg_len;
  31379. + sg_todo = sg_dma_len(&sg[host_priv->sg_ix]);
  31380. +
  31381. + cs = readl(host_priv->dma_chan_base + BCM2708_DMA_CS);
  31382. +
  31383. + if (!(BCM2708_DMA_ACTIVE & cs))
  31384. + {
  31385. + if (extra_messages)
  31386. + printk(KERN_INFO "%s: missed completion of "
  31387. + "cmd %d DMA (%d/%d [%d]/[%d]) - "
  31388. + "ignoring it\n",
  31389. + mmc_hostname(host->mmc),
  31390. + host->last_cmdop,
  31391. + host_priv->sg_done, sg_todo,
  31392. + host_priv->sg_ix+1, sg_len);
  31393. + }
  31394. + else
  31395. + printk(KERN_INFO "%s: resetting ongoing cmd %d"
  31396. + "DMA before %d/%d [%d]/[%d] complete\n",
  31397. + mmc_hostname(host->mmc),
  31398. + host->last_cmdop,
  31399. + host_priv->sg_done, sg_todo,
  31400. + host_priv->sg_ix+1, sg_len);
  31401. +#ifdef CHECK_DMA_USE
  31402. + printk(KERN_INFO "%s: now %"FMT_HPT" started %lu "
  31403. + "last reset %lu last stopped %lu\n",
  31404. + mmc_hostname(host->mmc),
  31405. + hptime(), since_ns(host_priv->when_started),
  31406. + since_ns(host_priv->when_reset),
  31407. + since_ns(host_priv->when_stopped));
  31408. + { unsigned long info, debug;
  31409. + void __iomem *base;
  31410. + unsigned long pend0, pend1, pend2;
  31411. +
  31412. + base = host_priv->dma_chan_base;
  31413. + cs = readl(base + BCM2708_DMA_CS);
  31414. + info = readl(base + BCM2708_DMA_INFO);
  31415. + debug = readl(base + BCM2708_DMA_DEBUG);
  31416. + printk(KERN_INFO "%s: DMA%d CS=%08lX TI=%08lX "
  31417. + "DEBUG=%08lX\n",
  31418. + mmc_hostname(host->mmc),
  31419. + host_priv->dma_chan,
  31420. + cs, info, debug);
  31421. + pend0 = readl(__io_address(ARM_IRQ_PEND0));
  31422. + pend1 = readl(__io_address(ARM_IRQ_PEND1));
  31423. + pend2 = readl(__io_address(ARM_IRQ_PEND2));
  31424. +
  31425. + printk(KERN_INFO "%s: PEND0=%08lX "
  31426. + "PEND1=%08lX PEND2=%08lX\n",
  31427. + mmc_hostname(host->mmc),
  31428. + pend0, pend1, pend2);
  31429. +
  31430. + //gintsts = readl(__io_address(GINTSTS));
  31431. + //gintmsk = readl(__io_address(GINTMSK));
  31432. + //printk(KERN_INFO "%s: USB GINTSTS=%08lX"
  31433. + // "GINTMSK=%08lX\n",
  31434. + // mmc_hostname(host->mmc), gintsts, gintmsk);
  31435. + }
  31436. +#endif
  31437. + rc = bcm_dma_abort(host_priv->dma_chan_base);
  31438. + BUG_ON(rc != 0);
  31439. + }
  31440. + host_priv->dma_wanted = 0;
  31441. +#ifdef CHECK_DMA_USE
  31442. + host_priv->when_reset = hptime();
  31443. +#endif
  31444. + }
  31445. +
  31446. +// spin_unlock_irqrestore(&host->lock, flags);
  31447. +}
  31448. +
  31449. +
  31450. +static void sdhci_bcm2708_dma_complete_irq(struct sdhci_host *host,
  31451. + u32 dma_cs)
  31452. +{
  31453. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31454. + struct mmc_data *data;
  31455. + struct scatterlist *sg;
  31456. + int sg_len;
  31457. + int sg_ix;
  31458. + int sg_todo;
  31459. +// unsigned long flags;
  31460. +
  31461. + BUG_ON(NULL == host);
  31462. +
  31463. +// spin_lock_irqsave(&host->lock, flags);
  31464. + data = host->data;
  31465. +
  31466. +#ifdef CHECK_DMA_USE
  31467. + if (host_priv->dmas_pending <= 0)
  31468. + DBG("on completion no DMA in progress - "
  31469. + "now %"FMT_HPT" started %lu reset %lu stopped %lu\n",
  31470. + hptime(), since_ns(host_priv->when_started),
  31471. + since_ns(host_priv->when_reset),
  31472. + since_ns(host_priv->when_stopped));
  31473. + else if (host_priv->dmas_pending > 1)
  31474. + DBG("still %d DMA in progress after completion - "
  31475. + "now %"FMT_HPT" started %lu reset %lu stopped %lu\n",
  31476. + host_priv->dmas_pending - 1,
  31477. + hptime(), since_ns(host_priv->when_started),
  31478. + since_ns(host_priv->when_reset),
  31479. + since_ns(host_priv->when_stopped));
  31480. + BUG_ON(host_priv->dmas_pending <= 0);
  31481. + host_priv->dmas_pending -= 1;
  31482. + host_priv->when_stopped = hptime();
  31483. +#endif
  31484. + host_priv->dma_wanted = 0;
  31485. +
  31486. + if (NULL == data) {
  31487. + DBG("PDMA unused completion - status 0x%X\n", dma_cs);
  31488. +// spin_unlock_irqrestore(&host->lock, flags);
  31489. + return;
  31490. + }
  31491. + sg = data->sg;
  31492. + sg_len = data->sg_len;
  31493. + sg_todo = sg_dma_len(&sg[host_priv->sg_ix]);
  31494. +
  31495. + DBG("PDMA complete %d/%d [%d]/[%d]..\n",
  31496. + host_priv->sg_done, sg_todo,
  31497. + host_priv->sg_ix+1, sg_len);
  31498. +
  31499. + BUG_ON(host_priv->sg_done > sg_todo);
  31500. +
  31501. + if (host_priv->sg_done >= sg_todo) {
  31502. + host_priv->sg_ix++;
  31503. + host_priv->sg_done = 0;
  31504. + }
  31505. +
  31506. + sg_ix = host_priv->sg_ix;
  31507. + if (sg_ix < sg_len) {
  31508. + u32 irq_mask;
  31509. + /* Set off next DMA if we've got the capacity */
  31510. +
  31511. + if (data->flags & MMC_DATA_READ)
  31512. + irq_mask = SDHCI_INT_DATA_AVAIL;
  31513. + else
  31514. + irq_mask = SDHCI_INT_SPACE_AVAIL;
  31515. +
  31516. + /* We have to use the interrupt status register on the BCM2708
  31517. + rather than the SDHCI_PRESENT_STATE register because latency
  31518. + in the glue logic means that the information retrieved from
  31519. + the latter is not always up-to-date w.r.t the DMA engine -
  31520. + it may not indicate that a read or a write is ready yet */
  31521. + if (sdhci_bcm2708_raw_readl(host, SDHCI_INT_STATUS) &
  31522. + irq_mask) {
  31523. + size_t bytes = sg_dma_len(&sg[sg_ix]) -
  31524. + host_priv->sg_done;
  31525. + dma_addr_t addr = sg_dma_address(&data->sg[sg_ix]) +
  31526. + host_priv->sg_done;
  31527. +
  31528. + /* acknowledge interrupt */
  31529. + sdhci_bcm2708_raw_writel(host, irq_mask,
  31530. + SDHCI_INT_STATUS);
  31531. +
  31532. + BUG_ON(0 == bytes);
  31533. +
  31534. + if (data->flags & MMC_DATA_READ)
  31535. + sdhci_platdma_read(host, addr, bytes);
  31536. + else
  31537. + sdhci_platdma_write(host, addr, bytes);
  31538. + } else {
  31539. + DBG("PDMA - wait avail\n");
  31540. + /* may generate an IRQ if already present */
  31541. + sdhci_signal_irqs(host, SDHCI_INT_DATA_AVAIL |
  31542. + SDHCI_INT_SPACE_AVAIL);
  31543. + }
  31544. + } else {
  31545. + if (sync_after_dma) {
  31546. + /* On the Arasan controller the stop command (which will be
  31547. + scheduled after this completes) does not seem to work
  31548. + properly if we allow it to be issued when we are
  31549. + transferring data to/from the SD card.
  31550. + We get CRC and DEND errors unless we wait for
  31551. + the SD controller to finish reading/writing to the card. */
  31552. + u32 state_mask;
  31553. + int timeout=3*1000*1000;
  31554. +
  31555. + DBG("PDMA over - sync card\n");
  31556. + if (data->flags & MMC_DATA_READ)
  31557. + state_mask = SDHCI_DOING_READ;
  31558. + else
  31559. + state_mask = SDHCI_DOING_WRITE;
  31560. +
  31561. + while (0 != (sdhci_bcm2708_raw_readl(host, SDHCI_PRESENT_STATE)
  31562. + & state_mask) && --timeout > 0)
  31563. + {
  31564. + udelay(1);
  31565. + continue;
  31566. + }
  31567. + if (timeout <= 0)
  31568. + printk(KERN_ERR"%s: final %s to SD card still "
  31569. + "running\n",
  31570. + mmc_hostname(host->mmc),
  31571. + data->flags & MMC_DATA_READ? "read": "write");
  31572. + }
  31573. + if (host_priv->complete) {
  31574. + (*host_priv->complete)(host);
  31575. + DBG("PDMA %s complete\n",
  31576. + data->flags & MMC_DATA_READ?"read":"write");
  31577. + sdhci_signal_irqs(host, SDHCI_INT_DATA_AVAIL |
  31578. + SDHCI_INT_SPACE_AVAIL);
  31579. + }
  31580. + }
  31581. +// spin_unlock_irqrestore(&host->lock, flags);
  31582. +}
  31583. +
  31584. +static irqreturn_t sdhci_bcm2708_dma_irq(int irq, void *dev_id)
  31585. +{
  31586. + irqreturn_t result = IRQ_NONE;
  31587. + struct sdhci_host *host = dev_id;
  31588. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31589. + u32 dma_cs; /* control and status register */
  31590. +
  31591. + BUG_ON(NULL == dev_id);
  31592. + BUG_ON(NULL == host_priv->dma_chan_base);
  31593. +
  31594. + sdhci_spin_lock(host);
  31595. +
  31596. + dma_cs = readl(host_priv->dma_chan_base + BCM2708_DMA_CS);
  31597. +
  31598. + if (dma_cs & BCM2708_DMA_ERR) {
  31599. + unsigned long debug;
  31600. + debug = readl(host_priv->dma_chan_base +
  31601. + BCM2708_DMA_DEBUG);
  31602. + printk(KERN_ERR "%s: DMA error - CS %lX DEBUG %lX\n",
  31603. + mmc_hostname(host->mmc), (unsigned long)dma_cs,
  31604. + (unsigned long)debug);
  31605. + /* reset error */
  31606. + writel(debug, host_priv->dma_chan_base +
  31607. + BCM2708_DMA_DEBUG);
  31608. + }
  31609. + if (dma_cs & BCM2708_DMA_INT) {
  31610. + /* acknowledge interrupt */
  31611. + writel(BCM2708_DMA_INT,
  31612. + host_priv->dma_chan_base + BCM2708_DMA_CS);
  31613. +
  31614. + dsb(); /* ARM data synchronization (push) operation */
  31615. +
  31616. + if (!host_priv->dma_wanted) {
  31617. + /* ignore this interrupt - it was reset */
  31618. + if (extra_messages)
  31619. + printk(KERN_INFO "%s: DMA IRQ %X ignored - "
  31620. + "results were reset\n",
  31621. + mmc_hostname(host->mmc), dma_cs);
  31622. +#ifdef CHECK_DMA_USE
  31623. + printk(KERN_INFO "%s: now %"FMT_HPT
  31624. + " started %lu reset %lu stopped %lu\n",
  31625. + mmc_hostname(host->mmc), hptime(),
  31626. + since_ns(host_priv->when_started),
  31627. + since_ns(host_priv->when_reset),
  31628. + since_ns(host_priv->when_stopped));
  31629. + host_priv->dmas_pending--;
  31630. +#endif
  31631. + } else
  31632. + sdhci_bcm2708_dma_complete_irq(host, dma_cs);
  31633. +
  31634. + result = IRQ_HANDLED;
  31635. + }
  31636. + sdhci_spin_unlock(host);
  31637. +
  31638. + return result;
  31639. +}
  31640. +#endif /* CONFIG_MMC_SDHCI_BCM2708_DMA */
  31641. +
  31642. +
  31643. +/***************************************************************************** \
  31644. + * *
  31645. + * Device Attributes *
  31646. + * *
  31647. +\*****************************************************************************/
  31648. +
  31649. +
  31650. +/**
  31651. + * Show the DMA-using status
  31652. + */
  31653. +static ssize_t attr_dma_show(struct device *_dev,
  31654. + struct device_attribute *attr, char *buf)
  31655. +{
  31656. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  31657. +
  31658. + if (host) {
  31659. + int use_dma = (host->flags & SDHCI_USE_PLATDMA? 1:0);
  31660. + return sprintf(buf, "%d\n", use_dma);
  31661. + } else
  31662. + return -EINVAL;
  31663. +}
  31664. +
  31665. +/**
  31666. + * Set the DMA-using status
  31667. + */
  31668. +static ssize_t attr_dma_store(struct device *_dev,
  31669. + struct device_attribute *attr,
  31670. + const char *buf, size_t count)
  31671. +{
  31672. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  31673. +
  31674. + if (host) {
  31675. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31676. + int on = simple_strtol(buf, NULL, 0);
  31677. + if (on) {
  31678. + host->flags |= SDHCI_USE_PLATDMA;
  31679. + sdhci_bcm2708_writel(host, 1, REG_EXRDFIFO_EN);
  31680. + printk(KERN_INFO "%s: DMA enabled\n",
  31681. + mmc_hostname(host->mmc));
  31682. + } else {
  31683. + host->flags &= ~(SDHCI_USE_PLATDMA | SDHCI_REQ_USE_DMA);
  31684. + sdhci_bcm2708_writel(host, 0, REG_EXRDFIFO_EN);
  31685. + printk(KERN_INFO "%s: DMA disabled\n",
  31686. + mmc_hostname(host->mmc));
  31687. + }
  31688. +#endif
  31689. + return count;
  31690. + } else
  31691. + return -EINVAL;
  31692. +}
  31693. +
  31694. +static DEVICE_ATTR(use_dma, S_IRUGO | S_IWUGO, attr_dma_show, attr_dma_store);
  31695. +
  31696. +
  31697. +/**
  31698. + * Show the DMA wait states used
  31699. + */
  31700. +static ssize_t attr_dmawait_show(struct device *_dev,
  31701. + struct device_attribute *attr, char *buf)
  31702. +{
  31703. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  31704. +
  31705. + if (host) {
  31706. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31707. + int dmawait = host_priv->dma_waits;
  31708. + return sprintf(buf, "%d\n", dmawait);
  31709. + } else
  31710. + return -EINVAL;
  31711. +}
  31712. +
  31713. +/**
  31714. + * Set the DMA wait state used
  31715. + */
  31716. +static ssize_t attr_dmawait_store(struct device *_dev,
  31717. + struct device_attribute *attr,
  31718. + const char *buf, size_t count)
  31719. +{
  31720. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  31721. +
  31722. + if (host) {
  31723. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31724. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31725. + int dma_waits = simple_strtol(buf, NULL, 0);
  31726. + if (dma_waits >= 0 && dma_waits < 32)
  31727. + host_priv->dma_waits = dma_waits;
  31728. + else
  31729. + printk(KERN_ERR "%s: illegal dma_waits value - %d",
  31730. + mmc_hostname(host->mmc), dma_waits);
  31731. +#endif
  31732. + return count;
  31733. + } else
  31734. + return -EINVAL;
  31735. +}
  31736. +
  31737. +static DEVICE_ATTR(dma_wait, S_IRUGO | S_IWUGO,
  31738. + attr_dmawait_show, attr_dmawait_store);
  31739. +
  31740. +
  31741. +/**
  31742. + * Show the DMA-using status
  31743. + */
  31744. +static ssize_t attr_status_show(struct device *_dev,
  31745. + struct device_attribute *attr, char *buf)
  31746. +{
  31747. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  31748. +
  31749. + if (host) {
  31750. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31751. + return sprintf(buf,
  31752. + "present: yes\n"
  31753. + "power: %s\n"
  31754. + "clock: %u Hz\n"
  31755. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31756. + "dma: %s (%d waits)\n",
  31757. +#else
  31758. + "dma: unconfigured\n",
  31759. +#endif
  31760. + "always on",
  31761. + host->clock
  31762. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31763. + , (host->flags & SDHCI_USE_PLATDMA)? "on": "off"
  31764. + , host_priv->dma_waits
  31765. +#endif
  31766. + );
  31767. + } else
  31768. + return -EINVAL;
  31769. +}
  31770. +
  31771. +static DEVICE_ATTR(status, S_IRUGO, attr_status_show, NULL);
  31772. +
  31773. +/***************************************************************************** \
  31774. + * *
  31775. + * Power Management *
  31776. + * *
  31777. +\*****************************************************************************/
  31778. +
  31779. +
  31780. +#ifdef CONFIG_PM
  31781. +static int sdhci_bcm2708_suspend(struct platform_device *dev, pm_message_t state)
  31782. +{
  31783. + struct sdhci_host *host = (struct sdhci_host *)
  31784. + platform_get_drvdata(dev);
  31785. + int ret = 0;
  31786. +
  31787. + if (host->mmc) {
  31788. + //ret = mmc_suspend_host(host->mmc);
  31789. + }
  31790. +
  31791. + return ret;
  31792. +}
  31793. +
  31794. +static int sdhci_bcm2708_resume(struct platform_device *dev)
  31795. +{
  31796. + struct sdhci_host *host = (struct sdhci_host *)
  31797. + platform_get_drvdata(dev);
  31798. + int ret = 0;
  31799. +
  31800. + if (host->mmc) {
  31801. + //ret = mmc_resume_host(host->mmc);
  31802. + }
  31803. +
  31804. + return ret;
  31805. +}
  31806. +#endif
  31807. +
  31808. +
  31809. +/*****************************************************************************\
  31810. + * *
  31811. + * Device quirk functions. Implemented as local ops because the flags *
  31812. + * field is out of space with newer kernels. This implementation can be *
  31813. + * back ported to older kernels as well. *
  31814. +\****************************************************************************/
  31815. +static unsigned int sdhci_bcm2708_quirk_extra_ints(struct sdhci_host *host)
  31816. +{
  31817. + return 1;
  31818. +}
  31819. +
  31820. +static unsigned int sdhci_bcm2708_quirk_spurious_crc_acmd51(struct sdhci_host *host)
  31821. +{
  31822. + return 1;
  31823. +}
  31824. +
  31825. +static unsigned int sdhci_bcm2708_missing_status(struct sdhci_host *host)
  31826. +{
  31827. + return 1;
  31828. +}
  31829. +
  31830. +/***************************************************************************** \
  31831. + * *
  31832. + * Device ops *
  31833. + * *
  31834. +\*****************************************************************************/
  31835. +
  31836. +static struct sdhci_ops sdhci_bcm2708_ops = {
  31837. +#ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS
  31838. + .read_l = sdhci_bcm2708_readl,
  31839. + .read_w = sdhci_bcm2708_readw,
  31840. + .read_b = sdhci_bcm2708_readb,
  31841. + .write_l = sdhci_bcm2708_writel,
  31842. + .write_w = sdhci_bcm2708_writew,
  31843. + .write_b = sdhci_bcm2708_writeb,
  31844. +#else
  31845. +#error The BCM2708 SDHCI driver needs CONFIG_MMC_SDHCI_IO_ACCESSORS to be set
  31846. +#endif
  31847. + .get_max_clock = sdhci_bcm2708_get_max_clock,
  31848. +
  31849. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31850. + // Platform DMA operations
  31851. + .pdma_able = sdhci_bcm2708_platdma_dmaable,
  31852. + .pdma_avail = sdhci_bcm2708_platdma_avail,
  31853. + .pdma_reset = sdhci_bcm2708_platdma_reset,
  31854. +#endif
  31855. + .extra_ints = sdhci_bcm2708_quirk_extra_ints,
  31856. +};
  31857. +
  31858. +/*****************************************************************************\
  31859. + * *
  31860. + * Device probing/removal *
  31861. + * *
  31862. +\*****************************************************************************/
  31863. +
  31864. +static int sdhci_bcm2708_probe(struct platform_device *pdev)
  31865. +{
  31866. + struct sdhci_host *host;
  31867. + struct resource *iomem;
  31868. + struct sdhci_bcm2708_priv *host_priv;
  31869. + int ret;
  31870. +
  31871. + BUG_ON(pdev == NULL);
  31872. +
  31873. + iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  31874. + if (!iomem) {
  31875. + ret = -ENOMEM;
  31876. + goto err;
  31877. + }
  31878. +
  31879. + if (resource_size(iomem) != 0x100)
  31880. + dev_err(&pdev->dev, "Invalid iomem size. You may "
  31881. + "experience problems.\n");
  31882. +
  31883. + if (pdev->dev.parent)
  31884. + host = sdhci_alloc_host(pdev->dev.parent,
  31885. + sizeof(struct sdhci_bcm2708_priv));
  31886. + else
  31887. + host = sdhci_alloc_host(&pdev->dev,
  31888. + sizeof(struct sdhci_bcm2708_priv));
  31889. +
  31890. + if (IS_ERR(host)) {
  31891. + ret = PTR_ERR(host);
  31892. + goto err;
  31893. + }
  31894. + if (missing_status) {
  31895. + sdhci_bcm2708_ops.missing_status = sdhci_bcm2708_missing_status;
  31896. + }
  31897. +
  31898. + if( spurious_crc_acmd51 ) {
  31899. + sdhci_bcm2708_ops.spurious_crc_acmd51 = sdhci_bcm2708_quirk_spurious_crc_acmd51;
  31900. + }
  31901. +
  31902. +
  31903. + printk("sdhci: %s low-latency mode\n",enable_llm?"Enable":"Disable");
  31904. +
  31905. + host->hw_name = "BCM2708_Arasan";
  31906. + host->ops = &sdhci_bcm2708_ops;
  31907. + host->irq = platform_get_irq(pdev, 0);
  31908. + host->second_irq = 0;
  31909. +
  31910. + host->quirks = SDHCI_QUIRK_BROKEN_CARD_DETECTION |
  31911. + SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK |
  31912. + SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
  31913. + SDHCI_QUIRK_MISSING_CAPS |
  31914. + SDHCI_QUIRK_NO_HISPD_BIT |
  31915. + (sync_after_dma ? 0:SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12);
  31916. +
  31917. +
  31918. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31919. + host->flags = SDHCI_USE_PLATDMA;
  31920. +#endif
  31921. +
  31922. + if (!request_mem_region(iomem->start, resource_size(iomem),
  31923. + mmc_hostname(host->mmc))) {
  31924. + dev_err(&pdev->dev, "cannot request region\n");
  31925. + ret = -EBUSY;
  31926. + goto err_request;
  31927. + }
  31928. +
  31929. + host->ioaddr = ioremap(iomem->start, resource_size(iomem));
  31930. + if (!host->ioaddr) {
  31931. + dev_err(&pdev->dev, "failed to remap registers\n");
  31932. + ret = -ENOMEM;
  31933. + goto err_remap;
  31934. + }
  31935. +
  31936. + host_priv = SDHCI_HOST_PRIV(host);
  31937. +
  31938. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31939. + host_priv->dma_wanted = 0;
  31940. +#ifdef CHECK_DMA_USE
  31941. + host_priv->dmas_pending = 0;
  31942. + host_priv->when_started = 0;
  31943. + host_priv->when_reset = 0;
  31944. + host_priv->when_stopped = 0;
  31945. +#endif
  31946. + host_priv->sg_ix = 0;
  31947. + host_priv->sg_done = 0;
  31948. + host_priv->complete = NULL;
  31949. + host_priv->dma_waits = SDHCI_BCM_DMA_WAITS;
  31950. +
  31951. + host_priv->cb_base = dma_alloc_writecombine(&pdev->dev, SZ_4K,
  31952. + &host_priv->cb_handle,
  31953. + GFP_KERNEL);
  31954. + if (!host_priv->cb_base) {
  31955. + dev_err(&pdev->dev, "cannot allocate DMA CBs\n");
  31956. + ret = -ENOMEM;
  31957. + goto err_alloc_cb;
  31958. + }
  31959. +
  31960. + ret = bcm_dma_chan_alloc(BCM_DMA_FEATURE_FAST,
  31961. + &host_priv->dma_chan_base,
  31962. + &host_priv->dma_irq);
  31963. + if (ret < 0) {
  31964. + dev_err(&pdev->dev, "couldn't allocate a DMA channel\n");
  31965. + goto err_add_dma;
  31966. + }
  31967. + host_priv->dma_chan = ret;
  31968. +
  31969. + ret = request_irq(host_priv->dma_irq, sdhci_bcm2708_dma_irq,
  31970. + 0 /*IRQF_SHARED*/, DRIVER_NAME " (dma)", host);
  31971. + if (ret) {
  31972. + dev_err(&pdev->dev, "cannot set DMA IRQ\n");
  31973. + goto err_add_dma_irq;
  31974. + }
  31975. + host->second_irq = host_priv->dma_irq;
  31976. + DBG("DMA CBs %p handle %08X DMA%d %p DMA IRQ %d\n",
  31977. + host_priv->cb_base, (unsigned)host_priv->cb_handle,
  31978. + host_priv->dma_chan, host_priv->dma_chan_base,
  31979. + host_priv->dma_irq);
  31980. +
  31981. + // we support 3.3V
  31982. + host->caps |= SDHCI_CAN_VDD_330;
  31983. + if (allow_highspeed)
  31984. + host->mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED;
  31985. +
  31986. + /* single block writes cause data loss with some SD cards! */
  31987. + host->mmc->caps2 |= MMC_CAP2_FORCE_MULTIBLOCK;
  31988. +#endif
  31989. +
  31990. + ret = sdhci_add_host(host);
  31991. + if (ret)
  31992. + goto err_add_host;
  31993. +
  31994. + platform_set_drvdata(pdev, host);
  31995. + ret = device_create_file(&pdev->dev, &dev_attr_use_dma);
  31996. + ret = device_create_file(&pdev->dev, &dev_attr_dma_wait);
  31997. + ret = device_create_file(&pdev->dev, &dev_attr_status);
  31998. +
  31999. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  32000. + /* enable extension fifo for paced DMA transfers */
  32001. + sdhci_bcm2708_writel(host, 1, REG_EXRDFIFO_EN);
  32002. + sdhci_bcm2708_writel(host, 4, REG_EXRDFIFO_CFG);
  32003. +#endif
  32004. +
  32005. + printk(KERN_INFO "%s: BCM2708 SDHC host at 0x%08llx DMA %d IRQ %d\n",
  32006. + mmc_hostname(host->mmc), (unsigned long long)iomem->start,
  32007. + host_priv->dma_chan, host_priv->dma_irq);
  32008. +
  32009. + return 0;
  32010. +
  32011. +err_add_host:
  32012. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  32013. + free_irq(host_priv->dma_irq, host);
  32014. +err_add_dma_irq:
  32015. + bcm_dma_chan_free(host_priv->dma_chan);
  32016. +err_add_dma:
  32017. + dma_free_writecombine(&pdev->dev, SZ_4K, host_priv->cb_base,
  32018. + host_priv->cb_handle);
  32019. +err_alloc_cb:
  32020. +#endif
  32021. + iounmap(host->ioaddr);
  32022. +err_remap:
  32023. + release_mem_region(iomem->start, resource_size(iomem));
  32024. +err_request:
  32025. + sdhci_free_host(host);
  32026. +err:
  32027. + dev_err(&pdev->dev, "probe failed, err %d\n", ret);
  32028. + return ret;
  32029. +}
  32030. +
  32031. +static int sdhci_bcm2708_remove(struct platform_device *pdev)
  32032. +{
  32033. + struct sdhci_host *host = platform_get_drvdata(pdev);
  32034. + struct resource *iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  32035. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  32036. + int dead;
  32037. + u32 scratch;
  32038. +
  32039. + dead = 0;
  32040. + scratch = sdhci_bcm2708_readl(host, SDHCI_INT_STATUS);
  32041. + if (scratch == (u32)-1)
  32042. + dead = 1;
  32043. +
  32044. + device_remove_file(&pdev->dev, &dev_attr_status);
  32045. + device_remove_file(&pdev->dev, &dev_attr_dma_wait);
  32046. + device_remove_file(&pdev->dev, &dev_attr_use_dma);
  32047. +
  32048. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  32049. + free_irq(host_priv->dma_irq, host);
  32050. + dma_free_writecombine(&pdev->dev, SZ_4K, host_priv->cb_base,
  32051. + host_priv->cb_handle);
  32052. +#endif
  32053. + sdhci_remove_host(host, dead);
  32054. + iounmap(host->ioaddr);
  32055. + release_mem_region(iomem->start, resource_size(iomem));
  32056. + sdhci_free_host(host);
  32057. + platform_set_drvdata(pdev, NULL);
  32058. +
  32059. + return 0;
  32060. +}
  32061. +
  32062. +static struct platform_driver sdhci_bcm2708_driver = {
  32063. + .driver = {
  32064. + .name = DRIVER_NAME,
  32065. + .owner = THIS_MODULE,
  32066. + },
  32067. + .probe = sdhci_bcm2708_probe,
  32068. + .remove = sdhci_bcm2708_remove,
  32069. +
  32070. +#ifdef CONFIG_PM
  32071. + .suspend = sdhci_bcm2708_suspend,
  32072. + .resume = sdhci_bcm2708_resume,
  32073. +#endif
  32074. +
  32075. +};
  32076. +
  32077. +/*****************************************************************************\
  32078. + * *
  32079. + * Driver init/exit *
  32080. + * *
  32081. +\*****************************************************************************/
  32082. +
  32083. +static int __init sdhci_drv_init(void)
  32084. +{
  32085. + return platform_driver_register(&sdhci_bcm2708_driver);
  32086. +}
  32087. +
  32088. +static void __exit sdhci_drv_exit(void)
  32089. +{
  32090. + platform_driver_unregister(&sdhci_bcm2708_driver);
  32091. +}
  32092. +
  32093. +module_init(sdhci_drv_init);
  32094. +module_exit(sdhci_drv_exit);
  32095. +
  32096. +module_param(allow_highspeed, bool, 0444);
  32097. +module_param(emmc_clock_freq, int, 0444);
  32098. +module_param(sync_after_dma, bool, 0444);
  32099. +module_param(missing_status, bool, 0444);
  32100. +module_param(spurious_crc_acmd51, bool, 0444);
  32101. +module_param(enable_llm, bool, 0444);
  32102. +module_param(cycle_delay, int, 0444);
  32103. +module_param(extra_messages, bool, 0444);
  32104. +
  32105. +MODULE_DESCRIPTION("Secure Digital Host Controller Interface platform driver");
  32106. +MODULE_AUTHOR("Broadcom <info@broadcom.com>");
  32107. +MODULE_LICENSE("GPL v2");
  32108. +MODULE_ALIAS("platform:"DRIVER_NAME);
  32109. +
  32110. +MODULE_PARM_DESC(allow_highspeed, "Allow high speed transfers modes");
  32111. +MODULE_PARM_DESC(emmc_clock_freq, "Specify the speed of emmc clock");
  32112. +MODULE_PARM_DESC(sync_after_dma, "Block in driver until dma complete");
  32113. +MODULE_PARM_DESC(missing_status, "Use the missing status quirk");
  32114. +MODULE_PARM_DESC(spurious_crc_acmd51, "Use the spurious crc quirk for reading SCR (ACMD51)");
  32115. +MODULE_PARM_DESC(enable_llm, "Enable low-latency mode");
  32116. +MODULE_PARM_DESC(extra_messages, "Enable more sdcard warning messages");
  32117. +
  32118. +
  32119. diff -Nur linux-3.12.26.orig/drivers/mmc/host/sdhci.c linux-3.12.26/drivers/mmc/host/sdhci.c
  32120. --- linux-3.12.26.orig/drivers/mmc/host/sdhci.c 2014-07-30 18:02:44.000000000 +0200
  32121. +++ linux-3.12.26/drivers/mmc/host/sdhci.c 2014-08-06 16:50:14.569962904 +0200
  32122. @@ -28,6 +28,7 @@
  32123. #include <linux/mmc/mmc.h>
  32124. #include <linux/mmc/host.h>
  32125. #include <linux/mmc/card.h>
  32126. +#include <linux/mmc/sd.h>
  32127. #include <linux/mmc/slot-gpio.h>
  32128. #include "sdhci.h"
  32129. @@ -131,6 +132,99 @@
  32130. * Low level functions *
  32131. * *
  32132. \*****************************************************************************/
  32133. +extern bool enable_llm;
  32134. +static int sdhci_locked=0;
  32135. +void sdhci_spin_lock(struct sdhci_host *host)
  32136. +{
  32137. + spin_lock(&host->lock);
  32138. +#ifdef CONFIG_PREEMPT
  32139. + if(enable_llm)
  32140. + {
  32141. + disable_irq_nosync(host->irq);
  32142. + if(host->second_irq)
  32143. + disable_irq_nosync(host->second_irq);
  32144. + local_irq_enable();
  32145. + }
  32146. +#endif
  32147. +}
  32148. +
  32149. +void sdhci_spin_unlock(struct sdhci_host *host)
  32150. +{
  32151. +#ifdef CONFIG_PREEMPT
  32152. + if(enable_llm)
  32153. + {
  32154. + local_irq_disable();
  32155. + if(host->second_irq)
  32156. + enable_irq(host->second_irq);
  32157. + enable_irq(host->irq);
  32158. + }
  32159. +#endif
  32160. + spin_unlock(&host->lock);
  32161. +}
  32162. +
  32163. +void sdhci_spin_lock_irqsave(struct sdhci_host *host,unsigned long *flags)
  32164. +{
  32165. +#ifdef CONFIG_PREEMPT
  32166. + if(enable_llm)
  32167. + {
  32168. + while(sdhci_locked)
  32169. + {
  32170. + preempt_schedule();
  32171. + }
  32172. + spin_lock_irqsave(&host->lock,*flags);
  32173. + disable_irq(host->irq);
  32174. + if(host->second_irq)
  32175. + disable_irq(host->second_irq);
  32176. + local_irq_enable();
  32177. + }
  32178. + else
  32179. +#endif
  32180. + spin_lock_irqsave(&host->lock,*flags);
  32181. +}
  32182. +
  32183. +void sdhci_spin_unlock_irqrestore(struct sdhci_host *host,unsigned long flags)
  32184. +{
  32185. +#ifdef CONFIG_PREEMPT
  32186. + if(enable_llm)
  32187. + {
  32188. + local_irq_disable();
  32189. + if(host->second_irq)
  32190. + enable_irq(host->second_irq);
  32191. + enable_irq(host->irq);
  32192. + }
  32193. +#endif
  32194. + spin_unlock_irqrestore(&host->lock,flags);
  32195. +}
  32196. +
  32197. +static void sdhci_spin_enable_schedule(struct sdhci_host *host)
  32198. +{
  32199. +#ifdef CONFIG_PREEMPT
  32200. + if(enable_llm)
  32201. + {
  32202. + sdhci_locked = 1;
  32203. + preempt_enable();
  32204. + }
  32205. +#endif
  32206. +}
  32207. +
  32208. +static void sdhci_spin_disable_schedule(struct sdhci_host *host)
  32209. +{
  32210. +#ifdef CONFIG_PREEMPT
  32211. + if(enable_llm)
  32212. + {
  32213. + preempt_disable();
  32214. + sdhci_locked = 0;
  32215. + }
  32216. +#endif
  32217. +}
  32218. +
  32219. +
  32220. +#undef spin_lock_irqsave
  32221. +#define spin_lock_irqsave(host_lock, flags) sdhci_spin_lock_irqsave(container_of(host_lock, struct sdhci_host, lock), &flags)
  32222. +#define spin_unlock_irqrestore(host_lock, flags) sdhci_spin_unlock_irqrestore(container_of(host_lock, struct sdhci_host, lock), flags)
  32223. +
  32224. +#define spin_lock(host_lock) sdhci_spin_lock(container_of(host_lock, struct sdhci_host, lock))
  32225. +#define spin_unlock(host_lock) sdhci_spin_unlock(container_of(host_lock, struct sdhci_host, lock))
  32226. static void sdhci_clear_set_irqs(struct sdhci_host *host, u32 clear, u32 set)
  32227. {
  32228. @@ -300,7 +394,7 @@
  32229. struct sdhci_host *host = container_of(led, struct sdhci_host, led);
  32230. unsigned long flags;
  32231. - spin_lock_irqsave(&host->lock, flags);
  32232. + sdhci_spin_lock_irqsave(host, &flags);
  32233. if (host->runtime_suspended)
  32234. goto out;
  32235. @@ -310,7 +404,7 @@
  32236. else
  32237. sdhci_activate_led(host);
  32238. out:
  32239. - spin_unlock_irqrestore(&host->lock, flags);
  32240. + sdhci_spin_unlock_irqrestore(host, flags);
  32241. }
  32242. #endif
  32243. @@ -327,7 +421,7 @@
  32244. u32 uninitialized_var(scratch);
  32245. u8 *buf;
  32246. - DBG("PIO reading\n");
  32247. + DBG("PIO reading %db\n", host->data->blksz);
  32248. blksize = host->data->blksz;
  32249. chunk = 0;
  32250. @@ -372,7 +466,7 @@
  32251. u32 scratch;
  32252. u8 *buf;
  32253. - DBG("PIO writing\n");
  32254. + DBG("PIO writing %db\n", host->data->blksz);
  32255. blksize = host->data->blksz;
  32256. chunk = 0;
  32257. @@ -411,19 +505,28 @@
  32258. local_irq_restore(flags);
  32259. }
  32260. -static void sdhci_transfer_pio(struct sdhci_host *host)
  32261. +static void sdhci_transfer_pio(struct sdhci_host *host, u32 intstate)
  32262. {
  32263. u32 mask;
  32264. + u32 state = 0;
  32265. + u32 intmask;
  32266. + int available;
  32267. BUG_ON(!host->data);
  32268. if (host->blocks == 0)
  32269. return;
  32270. - if (host->data->flags & MMC_DATA_READ)
  32271. + if (host->data->flags & MMC_DATA_READ) {
  32272. mask = SDHCI_DATA_AVAILABLE;
  32273. - else
  32274. + intmask = SDHCI_INT_DATA_AVAIL;
  32275. + } else {
  32276. mask = SDHCI_SPACE_AVAILABLE;
  32277. + intmask = SDHCI_INT_SPACE_AVAIL;
  32278. + }
  32279. +
  32280. + /* initially we can see whether we can procede using intstate */
  32281. + available = (intstate & intmask);
  32282. /*
  32283. * Some controllers (JMicron JMB38x) mess up the buffer bits
  32284. @@ -434,7 +537,7 @@
  32285. (host->data->blocks == 1))
  32286. mask = ~0;
  32287. - while (sdhci_readl(host, SDHCI_PRESENT_STATE) & mask) {
  32288. + while (available) {
  32289. if (host->quirks & SDHCI_QUIRK_PIO_NEEDS_DELAY)
  32290. udelay(100);
  32291. @@ -446,9 +549,12 @@
  32292. host->blocks--;
  32293. if (host->blocks == 0)
  32294. break;
  32295. + state = sdhci_readl(host, SDHCI_PRESENT_STATE);
  32296. + available = state & mask;
  32297. + break;
  32298. }
  32299. - DBG("PIO transfer complete.\n");
  32300. + DBG("PIO transfer complete - %d blocks left.\n", host->blocks);
  32301. }
  32302. static char *sdhci_kmap_atomic(struct scatterlist *sg, unsigned long *flags)
  32303. @@ -721,7 +827,9 @@
  32304. u32 pio_irqs = SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL;
  32305. u32 dma_irqs = SDHCI_INT_DMA_END | SDHCI_INT_ADMA_ERROR;
  32306. - if (host->flags & SDHCI_REQ_USE_DMA)
  32307. + /* platform DMA will begin on receipt of PIO irqs */
  32308. + if ((host->flags & SDHCI_REQ_USE_DMA) &&
  32309. + !(host->flags & SDHCI_USE_PLATDMA))
  32310. sdhci_clear_set_irqs(host, pio_irqs, dma_irqs);
  32311. else
  32312. sdhci_clear_set_irqs(host, dma_irqs, pio_irqs);
  32313. @@ -753,44 +861,25 @@
  32314. host->data_early = 0;
  32315. host->data->bytes_xfered = 0;
  32316. - if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA))
  32317. + if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA | SDHCI_USE_PLATDMA))
  32318. host->flags |= SDHCI_REQ_USE_DMA;
  32319. /*
  32320. * FIXME: This doesn't account for merging when mapping the
  32321. * scatterlist.
  32322. */
  32323. - if (host->flags & SDHCI_REQ_USE_DMA) {
  32324. - int broken, i;
  32325. - struct scatterlist *sg;
  32326. -
  32327. - broken = 0;
  32328. - if (host->flags & SDHCI_USE_ADMA) {
  32329. - if (host->quirks & SDHCI_QUIRK_32BIT_ADMA_SIZE)
  32330. - broken = 1;
  32331. - } else {
  32332. - if (host->quirks & SDHCI_QUIRK_32BIT_DMA_SIZE)
  32333. - broken = 1;
  32334. - }
  32335. -
  32336. - if (unlikely(broken)) {
  32337. - for_each_sg(data->sg, sg, data->sg_len, i) {
  32338. - if (sg->length & 0x3) {
  32339. - DBG("Reverting to PIO because of "
  32340. - "transfer size (%d)\n",
  32341. - sg->length);
  32342. - host->flags &= ~SDHCI_REQ_USE_DMA;
  32343. - break;
  32344. - }
  32345. - }
  32346. - }
  32347. - }
  32348. /*
  32349. * The assumption here being that alignment is the same after
  32350. * translation to device address space.
  32351. */
  32352. - if (host->flags & SDHCI_REQ_USE_DMA) {
  32353. + if ((host->flags & (SDHCI_REQ_USE_DMA | SDHCI_USE_PLATDMA)) ==
  32354. + (SDHCI_REQ_USE_DMA | SDHCI_USE_PLATDMA)) {
  32355. +
  32356. + if (! sdhci_platdma_dmaable(host, data))
  32357. + host->flags &= ~SDHCI_REQ_USE_DMA;
  32358. +
  32359. + } else if (host->flags & SDHCI_REQ_USE_DMA) {
  32360. int broken, i;
  32361. struct scatterlist *sg;
  32362. @@ -849,7 +938,8 @@
  32363. */
  32364. WARN_ON(1);
  32365. host->flags &= ~SDHCI_REQ_USE_DMA;
  32366. - } else {
  32367. + } else
  32368. + if (!(host->flags & SDHCI_USE_PLATDMA)) {
  32369. WARN_ON(sg_cnt != 1);
  32370. sdhci_writel(host, sg_dma_address(data->sg),
  32371. SDHCI_DMA_ADDRESS);
  32372. @@ -865,11 +955,13 @@
  32373. if (host->version >= SDHCI_SPEC_200) {
  32374. ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
  32375. ctrl &= ~SDHCI_CTRL_DMA_MASK;
  32376. + if (! (host->flags & SDHCI_USE_PLATDMA)) {
  32377. if ((host->flags & SDHCI_REQ_USE_DMA) &&
  32378. (host->flags & SDHCI_USE_ADMA))
  32379. ctrl |= SDHCI_CTRL_ADMA32;
  32380. else
  32381. ctrl |= SDHCI_CTRL_SDMA;
  32382. + }
  32383. sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
  32384. }
  32385. @@ -921,7 +1013,8 @@
  32386. if (data->flags & MMC_DATA_READ)
  32387. mode |= SDHCI_TRNS_READ;
  32388. - if (host->flags & SDHCI_REQ_USE_DMA)
  32389. + if ((host->flags & SDHCI_REQ_USE_DMA) &&
  32390. + !(host->flags & SDHCI_USE_PLATDMA))
  32391. mode |= SDHCI_TRNS_DMA;
  32392. sdhci_writew(host, mode, SDHCI_TRANSFER_MODE);
  32393. @@ -937,13 +1030,16 @@
  32394. host->data = NULL;
  32395. if (host->flags & SDHCI_REQ_USE_DMA) {
  32396. - if (host->flags & SDHCI_USE_ADMA)
  32397. - sdhci_adma_table_post(host, data);
  32398. - else {
  32399. + /* we may have to abandon an ongoing platform DMA */
  32400. + if (host->flags & SDHCI_USE_PLATDMA)
  32401. + sdhci_platdma_reset(host, data);
  32402. +
  32403. + if (host->flags & (SDHCI_USE_PLATDMA | SDHCI_USE_SDMA)) {
  32404. dma_unmap_sg(mmc_dev(host->mmc), data->sg,
  32405. data->sg_len, (data->flags & MMC_DATA_READ) ?
  32406. DMA_FROM_DEVICE : DMA_TO_DEVICE);
  32407. - }
  32408. + } else if (host->flags & SDHCI_USE_ADMA)
  32409. + sdhci_adma_table_post(host, data);
  32410. }
  32411. /*
  32412. @@ -996,6 +1092,12 @@
  32413. if ((cmd->data != NULL) || (cmd->flags & MMC_RSP_BUSY))
  32414. mask |= SDHCI_DATA_INHIBIT;
  32415. + if(host->ops->missing_status && (cmd->opcode == MMC_SEND_STATUS)) {
  32416. + timeout = 5000; // Really obscenely large delay to send the status, due to bug in controller
  32417. + // which might cause the STATUS command to get stuck when a data operation is in flow
  32418. + mask |= SDHCI_DATA_INHIBIT;
  32419. + }
  32420. +
  32421. /* We shouldn't wait for data inihibit for stop commands, even
  32422. though they might use busy signaling */
  32423. if (host->mrq->data && (cmd == host->mrq->data->stop))
  32424. @@ -1011,12 +1113,20 @@
  32425. return;
  32426. }
  32427. timeout--;
  32428. + sdhci_spin_enable_schedule(host);
  32429. mdelay(1);
  32430. + sdhci_spin_disable_schedule(host);
  32431. }
  32432. + DBG("send cmd %d - wait 0x%X irq 0x%x\n", cmd->opcode, mask,
  32433. + sdhci_readl(host, SDHCI_INT_STATUS));
  32434. mod_timer(&host->timer, jiffies + 10 * HZ);
  32435. host->cmd = cmd;
  32436. + if (host->last_cmdop == MMC_APP_CMD)
  32437. + host->last_cmdop = -cmd->opcode;
  32438. + else
  32439. + host->last_cmdop = cmd->opcode;
  32440. sdhci_prepare_data(host, cmd);
  32441. @@ -1232,7 +1342,9 @@
  32442. return;
  32443. }
  32444. timeout--;
  32445. + sdhci_spin_enable_schedule(host);
  32446. mdelay(1);
  32447. + sdhci_spin_disable_schedule(host);
  32448. }
  32449. clk |= SDHCI_CLOCK_CARD_EN;
  32450. @@ -1333,7 +1445,7 @@
  32451. sdhci_runtime_pm_get(host);
  32452. - spin_lock_irqsave(&host->lock, flags);
  32453. + sdhci_spin_lock_irqsave(host, &flags);
  32454. WARN_ON(host->mrq != NULL);
  32455. @@ -1391,9 +1503,9 @@
  32456. mmc->card->type == MMC_TYPE_MMC ?
  32457. MMC_SEND_TUNING_BLOCK_HS200 :
  32458. MMC_SEND_TUNING_BLOCK;
  32459. - spin_unlock_irqrestore(&host->lock, flags);
  32460. + sdhci_spin_unlock_irqrestore(host, flags);
  32461. sdhci_execute_tuning(mmc, tuning_opcode);
  32462. - spin_lock_irqsave(&host->lock, flags);
  32463. + sdhci_spin_lock_irqsave(host, &flags);
  32464. /* Restore original mmc_request structure */
  32465. host->mrq = mrq;
  32466. @@ -1407,7 +1519,7 @@
  32467. }
  32468. mmiowb();
  32469. - spin_unlock_irqrestore(&host->lock, flags);
  32470. + sdhci_spin_unlock_irqrestore(host, flags);
  32471. }
  32472. static void sdhci_do_set_ios(struct sdhci_host *host, struct mmc_ios *ios)
  32473. @@ -1416,10 +1528,10 @@
  32474. int vdd_bit = -1;
  32475. u8 ctrl;
  32476. - spin_lock_irqsave(&host->lock, flags);
  32477. + sdhci_spin_lock_irqsave(host, &flags);
  32478. if (host->flags & SDHCI_DEVICE_DEAD) {
  32479. - spin_unlock_irqrestore(&host->lock, flags);
  32480. + sdhci_spin_unlock_irqrestore(host, flags);
  32481. if (host->vmmc && ios->power_mode == MMC_POWER_OFF)
  32482. mmc_regulator_set_ocr(host->mmc, host->vmmc, 0);
  32483. return;
  32484. @@ -1446,9 +1558,9 @@
  32485. vdd_bit = sdhci_set_power(host, ios->vdd);
  32486. if (host->vmmc && vdd_bit != -1) {
  32487. - spin_unlock_irqrestore(&host->lock, flags);
  32488. + sdhci_spin_unlock_irqrestore(host, flags);
  32489. mmc_regulator_set_ocr(host->mmc, host->vmmc, vdd_bit);
  32490. - spin_lock_irqsave(&host->lock, flags);
  32491. + sdhci_spin_lock_irqsave(host, &flags);
  32492. }
  32493. if (host->ops->platform_send_init_74_clocks)
  32494. @@ -1585,7 +1697,7 @@
  32495. sdhci_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA);
  32496. mmiowb();
  32497. - spin_unlock_irqrestore(&host->lock, flags);
  32498. + sdhci_spin_unlock_irqrestore(host, flags);
  32499. }
  32500. static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  32501. @@ -1633,7 +1745,7 @@
  32502. unsigned long flags;
  32503. int is_readonly;
  32504. - spin_lock_irqsave(&host->lock, flags);
  32505. + sdhci_spin_lock_irqsave(host, &flags);
  32506. if (host->flags & SDHCI_DEVICE_DEAD)
  32507. is_readonly = 0;
  32508. @@ -1643,7 +1755,7 @@
  32509. is_readonly = !(sdhci_readl(host, SDHCI_PRESENT_STATE)
  32510. & SDHCI_WRITE_PROTECT);
  32511. - spin_unlock_irqrestore(&host->lock, flags);
  32512. + sdhci_spin_unlock_irqrestore(host, flags);
  32513. /* This quirk needs to be replaced by a callback-function later */
  32514. return host->quirks & SDHCI_QUIRK_INVERTED_WRITE_PROTECT ?
  32515. @@ -1716,9 +1828,9 @@
  32516. struct sdhci_host *host = mmc_priv(mmc);
  32517. unsigned long flags;
  32518. - spin_lock_irqsave(&host->lock, flags);
  32519. + sdhci_spin_lock_irqsave(host, &flags);
  32520. sdhci_enable_sdio_irq_nolock(host, enable);
  32521. - spin_unlock_irqrestore(&host->lock, flags);
  32522. + sdhci_spin_unlock_irqrestore(host, flags);
  32523. }
  32524. static int sdhci_do_start_signal_voltage_switch(struct sdhci_host *host,
  32525. @@ -2066,7 +2178,7 @@
  32526. if (host->ops->card_event)
  32527. host->ops->card_event(host);
  32528. - spin_lock_irqsave(&host->lock, flags);
  32529. + sdhci_spin_lock_irqsave(host, &flags);
  32530. /* Check host->mrq first in case we are runtime suspended */
  32531. if (host->mrq && !sdhci_do_get_cd(host)) {
  32532. @@ -2082,7 +2194,7 @@
  32533. tasklet_schedule(&host->finish_tasklet);
  32534. }
  32535. - spin_unlock_irqrestore(&host->lock, flags);
  32536. + sdhci_spin_unlock_irqrestore(host, flags);
  32537. }
  32538. static const struct mmc_host_ops sdhci_ops = {
  32539. @@ -2121,14 +2233,14 @@
  32540. host = (struct sdhci_host*)param;
  32541. - spin_lock_irqsave(&host->lock, flags);
  32542. + sdhci_spin_lock_irqsave(host, &flags);
  32543. /*
  32544. * If this tasklet gets rescheduled while running, it will
  32545. * be run again afterwards but without any active request.
  32546. */
  32547. if (!host->mrq) {
  32548. - spin_unlock_irqrestore(&host->lock, flags);
  32549. + sdhci_spin_unlock_irqrestore(host, flags);
  32550. return;
  32551. }
  32552. @@ -2166,7 +2278,7 @@
  32553. #endif
  32554. mmiowb();
  32555. - spin_unlock_irqrestore(&host->lock, flags);
  32556. + sdhci_spin_unlock_irqrestore(host, flags);
  32557. mmc_request_done(host->mmc, mrq);
  32558. sdhci_runtime_pm_put(host);
  32559. @@ -2179,11 +2291,11 @@
  32560. host = (struct sdhci_host*)data;
  32561. - spin_lock_irqsave(&host->lock, flags);
  32562. + sdhci_spin_lock_irqsave(host, &flags);
  32563. if (host->mrq) {
  32564. pr_err("%s: Timeout waiting for hardware "
  32565. - "interrupt.\n", mmc_hostname(host->mmc));
  32566. + "interrupt - cmd%d.\n", mmc_hostname(host->mmc), host->last_cmdop);
  32567. sdhci_dumpregs(host);
  32568. if (host->data) {
  32569. @@ -2200,7 +2312,7 @@
  32570. }
  32571. mmiowb();
  32572. - spin_unlock_irqrestore(&host->lock, flags);
  32573. + sdhci_spin_unlock_irqrestore(host, flags);
  32574. }
  32575. static void sdhci_tuning_timer(unsigned long data)
  32576. @@ -2210,11 +2322,11 @@
  32577. host = (struct sdhci_host *)data;
  32578. - spin_lock_irqsave(&host->lock, flags);
  32579. + sdhci_spin_lock_irqsave(host, &flags);
  32580. host->flags |= SDHCI_NEEDS_RETUNING;
  32581. - spin_unlock_irqrestore(&host->lock, flags);
  32582. + sdhci_spin_unlock_irqrestore(host, flags);
  32583. }
  32584. /*****************************************************************************\
  32585. @@ -2228,10 +2340,13 @@
  32586. BUG_ON(intmask == 0);
  32587. if (!host->cmd) {
  32588. + if (!(host->ops->extra_ints)) {
  32589. pr_err("%s: Got command interrupt 0x%08x even "
  32590. "though no command operation was in progress.\n",
  32591. mmc_hostname(host->mmc), (unsigned)intmask);
  32592. sdhci_dumpregs(host);
  32593. + } else
  32594. + DBG("cmd irq 0x%08x cmd complete\n", (unsigned)intmask);
  32595. return;
  32596. }
  32597. @@ -2301,6 +2416,19 @@
  32598. static void sdhci_show_adma_error(struct sdhci_host *host) { }
  32599. #endif
  32600. +static void sdhci_data_end(struct sdhci_host *host)
  32601. +{
  32602. + if (host->cmd) {
  32603. + /*
  32604. + * Data managed to finish before the
  32605. + * command completed. Make sure we do
  32606. + * things in the proper order.
  32607. + */
  32608. + host->data_early = 1;
  32609. + } else
  32610. + sdhci_finish_data(host);
  32611. +}
  32612. +
  32613. static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
  32614. {
  32615. u32 command;
  32616. @@ -2330,23 +2458,39 @@
  32617. }
  32618. }
  32619. + if (!(host->ops->extra_ints)) {
  32620. pr_err("%s: Got data interrupt 0x%08x even "
  32621. "though no data operation was in progress.\n",
  32622. mmc_hostname(host->mmc), (unsigned)intmask);
  32623. sdhci_dumpregs(host);
  32624. + } else
  32625. + DBG("data irq 0x%08x but no data\n", (unsigned)intmask);
  32626. return;
  32627. }
  32628. if (intmask & SDHCI_INT_DATA_TIMEOUT)
  32629. host->data->error = -ETIMEDOUT;
  32630. - else if (intmask & SDHCI_INT_DATA_END_BIT)
  32631. + else if (intmask & SDHCI_INT_DATA_END_BIT) {
  32632. + DBG("end error in cmd %d\n", host->last_cmdop);
  32633. + if (host->ops->spurious_crc_acmd51 &&
  32634. + host->last_cmdop == -SD_APP_SEND_SCR) {
  32635. + DBG("ignoring spurious data_end_bit error\n");
  32636. + intmask = SDHCI_INT_DATA_AVAIL|SDHCI_INT_DATA_END;
  32637. + } else
  32638. host->data->error = -EILSEQ;
  32639. - else if ((intmask & SDHCI_INT_DATA_CRC) &&
  32640. + } else if ((intmask & SDHCI_INT_DATA_CRC) &&
  32641. SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND))
  32642. - != MMC_BUS_TEST_R)
  32643. + != MMC_BUS_TEST_R) {
  32644. + DBG("crc error in cmd %d\n", host->last_cmdop);
  32645. + if (host->ops->spurious_crc_acmd51 &&
  32646. + host->last_cmdop == -SD_APP_SEND_SCR) {
  32647. + DBG("ignoring spurious data_crc_bit error\n");
  32648. + intmask = SDHCI_INT_DATA_AVAIL|SDHCI_INT_DATA_END;
  32649. + } else {
  32650. host->data->error = -EILSEQ;
  32651. - else if (intmask & SDHCI_INT_ADMA_ERROR) {
  32652. + }
  32653. + } else if (intmask & SDHCI_INT_ADMA_ERROR) {
  32654. pr_err("%s: ADMA error\n", mmc_hostname(host->mmc));
  32655. sdhci_show_adma_error(host);
  32656. host->data->error = -EIO;
  32657. @@ -2354,11 +2498,18 @@
  32658. host->ops->adma_workaround(host, intmask);
  32659. }
  32660. - if (host->data->error)
  32661. + if (host->data->error) {
  32662. + DBG("finish request early on error %d\n", host->data->error);
  32663. sdhci_finish_data(host);
  32664. - else {
  32665. - if (intmask & (SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL))
  32666. - sdhci_transfer_pio(host);
  32667. + } else {
  32668. + if (intmask & (SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL)) {
  32669. + if (host->flags & SDHCI_REQ_USE_DMA) {
  32670. + /* possible only in PLATDMA mode */
  32671. + sdhci_platdma_avail(host, &intmask,
  32672. + &sdhci_data_end);
  32673. + } else
  32674. + sdhci_transfer_pio(host, intmask);
  32675. + }
  32676. /*
  32677. * We currently don't do anything fancy with DMA
  32678. @@ -2387,18 +2538,8 @@
  32679. sdhci_writel(host, dmanow, SDHCI_DMA_ADDRESS);
  32680. }
  32681. - if (intmask & SDHCI_INT_DATA_END) {
  32682. - if (host->cmd) {
  32683. - /*
  32684. - * Data managed to finish before the
  32685. - * command completed. Make sure we do
  32686. - * things in the proper order.
  32687. - */
  32688. - host->data_early = 1;
  32689. - } else {
  32690. - sdhci_finish_data(host);
  32691. - }
  32692. - }
  32693. + if (intmask & SDHCI_INT_DATA_END)
  32694. + sdhci_data_end(host);
  32695. }
  32696. }
  32697. @@ -2409,10 +2550,10 @@
  32698. u32 intmask, unexpected = 0;
  32699. int cardint = 0, max_loops = 16;
  32700. - spin_lock(&host->lock);
  32701. + sdhci_spin_lock(host);
  32702. if (host->runtime_suspended) {
  32703. - spin_unlock(&host->lock);
  32704. + sdhci_spin_unlock(host);
  32705. pr_warning("%s: got irq while runtime suspended\n",
  32706. mmc_hostname(host->mmc));
  32707. return IRQ_HANDLED;
  32708. @@ -2454,6 +2595,22 @@
  32709. tasklet_schedule(&host->card_tasklet);
  32710. }
  32711. + if (intmask & SDHCI_INT_ERROR_MASK & ~SDHCI_INT_ERROR)
  32712. + DBG("controller reports error 0x%x -"
  32713. + "%s%s%s%s%s%s%s%s%s%s",
  32714. + intmask,
  32715. + intmask & SDHCI_INT_TIMEOUT? " timeout": "",
  32716. + intmask & SDHCI_INT_CRC ? " crc": "",
  32717. + intmask & SDHCI_INT_END_BIT? " endbit": "",
  32718. + intmask & SDHCI_INT_INDEX? " index": "",
  32719. + intmask & SDHCI_INT_DATA_TIMEOUT? " data_timeout": "",
  32720. + intmask & SDHCI_INT_DATA_CRC? " data_crc": "",
  32721. + intmask & SDHCI_INT_DATA_END_BIT? " data_endbit": "",
  32722. + intmask & SDHCI_INT_BUS_POWER? " buspower": "",
  32723. + intmask & SDHCI_INT_ACMD12ERR? " acmd12": "",
  32724. + intmask & SDHCI_INT_ADMA_ERROR? " adma": ""
  32725. + );
  32726. +
  32727. if (intmask & SDHCI_INT_CMD_MASK) {
  32728. sdhci_writel(host, intmask & SDHCI_INT_CMD_MASK,
  32729. SDHCI_INT_STATUS);
  32730. @@ -2468,7 +2625,13 @@
  32731. intmask &= ~(SDHCI_INT_CMD_MASK | SDHCI_INT_DATA_MASK);
  32732. - intmask &= ~SDHCI_INT_ERROR;
  32733. + if (intmask & SDHCI_INT_ERROR_MASK) {
  32734. + /* collect any uncovered errors */
  32735. + sdhci_writel(host, intmask & SDHCI_INT_ERROR_MASK,
  32736. + SDHCI_INT_STATUS);
  32737. + }
  32738. +
  32739. + intmask &= ~SDHCI_INT_ERROR_MASK;
  32740. if (intmask & SDHCI_INT_BUS_POWER) {
  32741. pr_err("%s: Card is consuming too much power!\n",
  32742. @@ -2494,7 +2657,7 @@
  32743. if (intmask && --max_loops)
  32744. goto again;
  32745. out:
  32746. - spin_unlock(&host->lock);
  32747. + sdhci_spin_unlock(host);
  32748. if (unexpected) {
  32749. pr_err("%s: Unexpected interrupt 0x%08x.\n",
  32750. @@ -2588,13 +2751,14 @@
  32751. {
  32752. int ret;
  32753. - if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
  32754. + if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA |
  32755. + SDHCI_USE_PLATDMA)) {
  32756. if (host->ops->enable_dma)
  32757. host->ops->enable_dma(host);
  32758. }
  32759. if (!device_may_wakeup(mmc_dev(host->mmc))) {
  32760. - ret = request_irq(host->irq, sdhci_irq, IRQF_SHARED,
  32761. + ret = request_irq(host->irq, sdhci_irq, 0 /*IRQF_SHARED*/,
  32762. mmc_hostname(host->mmc), host);
  32763. if (ret)
  32764. return ret;
  32765. @@ -2671,15 +2835,15 @@
  32766. host->flags &= ~SDHCI_NEEDS_RETUNING;
  32767. }
  32768. - spin_lock_irqsave(&host->lock, flags);
  32769. + sdhci_spin_lock_irqsave(host, &flags);
  32770. sdhci_mask_irqs(host, SDHCI_INT_ALL_MASK);
  32771. - spin_unlock_irqrestore(&host->lock, flags);
  32772. + sdhci_spin_unlock_irqrestore(host, flags);
  32773. synchronize_irq(host->irq);
  32774. - spin_lock_irqsave(&host->lock, flags);
  32775. + sdhci_spin_lock_irqsave(host, &flags);
  32776. host->runtime_suspended = true;
  32777. - spin_unlock_irqrestore(&host->lock, flags);
  32778. + sdhci_spin_unlock_irqrestore(host, flags);
  32779. return ret;
  32780. }
  32781. @@ -2705,16 +2869,16 @@
  32782. sdhci_do_start_signal_voltage_switch(host, &host->mmc->ios);
  32783. if ((host_flags & SDHCI_PV_ENABLED) &&
  32784. !(host->quirks2 & SDHCI_QUIRK2_PRESET_VALUE_BROKEN)) {
  32785. - spin_lock_irqsave(&host->lock, flags);
  32786. + sdhci_spin_lock_irqsave(host, &flags);
  32787. sdhci_enable_preset_value(host, true);
  32788. - spin_unlock_irqrestore(&host->lock, flags);
  32789. + sdhci_spin_unlock_irqrestore(host, flags);
  32790. }
  32791. /* Set the re-tuning expiration flag */
  32792. if (host->flags & SDHCI_USING_RETUNING_TIMER)
  32793. host->flags |= SDHCI_NEEDS_RETUNING;
  32794. - spin_lock_irqsave(&host->lock, flags);
  32795. + sdhci_spin_lock_irqsave(host, &flags);
  32796. host->runtime_suspended = false;
  32797. @@ -2725,7 +2889,7 @@
  32798. /* Enable Card Detection */
  32799. sdhci_enable_card_detection(host);
  32800. - spin_unlock_irqrestore(&host->lock, flags);
  32801. + sdhci_spin_unlock_irqrestore(host, flags);
  32802. return ret;
  32803. }
  32804. @@ -2820,14 +2984,16 @@
  32805. host->flags &= ~SDHCI_USE_ADMA;
  32806. }
  32807. - if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
  32808. + if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA |
  32809. + SDHCI_USE_PLATDMA)) {
  32810. if (host->ops->enable_dma) {
  32811. if (host->ops->enable_dma(host)) {
  32812. pr_warning("%s: No suitable DMA "
  32813. "available. Falling back to PIO.\n",
  32814. mmc_hostname(mmc));
  32815. host->flags &=
  32816. - ~(SDHCI_USE_SDMA | SDHCI_USE_ADMA);
  32817. + ~(SDHCI_USE_SDMA | SDHCI_USE_ADMA |
  32818. + SDHCI_USE_PLATDMA);
  32819. }
  32820. }
  32821. }
  32822. @@ -3218,8 +3384,8 @@
  32823. sdhci_init(host, 0);
  32824. - ret = request_irq(host->irq, sdhci_irq, IRQF_SHARED,
  32825. - mmc_hostname(mmc), host);
  32826. + ret = request_irq(host->irq, sdhci_irq, 0 /*IRQF_SHARED*/,
  32827. + mmc_hostname(mmc), host);
  32828. if (ret) {
  32829. pr_err("%s: Failed to request IRQ %d: %d\n",
  32830. mmc_hostname(mmc), host->irq, ret);
  32831. @@ -3252,6 +3418,7 @@
  32832. pr_info("%s: SDHCI controller on %s [%s] using %s\n",
  32833. mmc_hostname(mmc), host->hw_name, dev_name(mmc_dev(mmc)),
  32834. + (host->flags & SDHCI_USE_PLATDMA) ? "platform's DMA" :
  32835. (host->flags & SDHCI_USE_ADMA) ? "ADMA" :
  32836. (host->flags & SDHCI_USE_SDMA) ? "DMA" : "PIO");
  32837. @@ -3279,7 +3446,7 @@
  32838. unsigned long flags;
  32839. if (dead) {
  32840. - spin_lock_irqsave(&host->lock, flags);
  32841. + sdhci_spin_lock_irqsave(host, &flags);
  32842. host->flags |= SDHCI_DEVICE_DEAD;
  32843. @@ -3291,7 +3458,7 @@
  32844. tasklet_schedule(&host->finish_tasklet);
  32845. }
  32846. - spin_unlock_irqrestore(&host->lock, flags);
  32847. + sdhci_spin_unlock_irqrestore(host, flags);
  32848. }
  32849. sdhci_disable_card_detection(host);
  32850. diff -Nur linux-3.12.26.orig/drivers/mmc/host/sdhci.h linux-3.12.26/drivers/mmc/host/sdhci.h
  32851. --- linux-3.12.26.orig/drivers/mmc/host/sdhci.h 2014-07-30 18:02:44.000000000 +0200
  32852. +++ linux-3.12.26/drivers/mmc/host/sdhci.h 2014-08-06 16:50:14.581962998 +0200
  32853. @@ -289,6 +289,18 @@
  32854. void (*platform_reset_enter)(struct sdhci_host *host, u8 mask);
  32855. void (*platform_reset_exit)(struct sdhci_host *host, u8 mask);
  32856. int (*set_uhs_signaling)(struct sdhci_host *host, unsigned int uhs);
  32857. +
  32858. + int (*pdma_able)(struct sdhci_host *host,
  32859. + struct mmc_data *data);
  32860. + void (*pdma_avail)(struct sdhci_host *host,
  32861. + unsigned int *ref_intmask,
  32862. + void(*complete)(struct sdhci_host *));
  32863. + void (*pdma_reset)(struct sdhci_host *host,
  32864. + struct mmc_data *data);
  32865. + unsigned int (*extra_ints)(struct sdhci_host *host);
  32866. + unsigned int (*spurious_crc_acmd51)(struct sdhci_host *host);
  32867. + unsigned int (*missing_status)(struct sdhci_host *host);
  32868. +
  32869. void (*hw_reset)(struct sdhci_host *host);
  32870. void (*platform_suspend)(struct sdhci_host *host);
  32871. void (*platform_resume)(struct sdhci_host *host);
  32872. @@ -400,9 +412,38 @@
  32873. extern void sdhci_enable_irq_wakeups(struct sdhci_host *host);
  32874. #endif
  32875. +static inline int /*bool*/
  32876. +sdhci_platdma_dmaable(struct sdhci_host *host, struct mmc_data *data)
  32877. +{
  32878. + if (host->ops->pdma_able)
  32879. + return host->ops->pdma_able(host, data);
  32880. + else
  32881. + return 1;
  32882. +}
  32883. +static inline void
  32884. +sdhci_platdma_avail(struct sdhci_host *host, unsigned int *ref_intmask,
  32885. + void(*completion_callback)(struct sdhci_host *))
  32886. +{
  32887. + if (host->ops->pdma_avail)
  32888. + host->ops->pdma_avail(host, ref_intmask, completion_callback);
  32889. +}
  32890. +
  32891. +static inline void
  32892. +sdhci_platdma_reset(struct sdhci_host *host, struct mmc_data *data)
  32893. +{
  32894. + if (host->ops->pdma_reset)
  32895. + host->ops->pdma_reset(host, data);
  32896. +}
  32897. +
  32898. #ifdef CONFIG_PM_RUNTIME
  32899. extern int sdhci_runtime_suspend_host(struct sdhci_host *host);
  32900. extern int sdhci_runtime_resume_host(struct sdhci_host *host);
  32901. #endif
  32902. +extern void sdhci_spin_lock_irqsave(struct sdhci_host *host,unsigned long *flags);
  32903. +extern void sdhci_spin_unlock_irqrestore(struct sdhci_host *host,unsigned long flags);
  32904. +extern void sdhci_spin_lock(struct sdhci_host *host);
  32905. +extern void sdhci_spin_unlock(struct sdhci_host *host);
  32906. +
  32907. +
  32908. #endif /* __SDHCI_HW_H */
  32909. diff -Nur linux-3.12.26.orig/drivers/net/bonding/bond_alb.c linux-3.12.26/drivers/net/bonding/bond_alb.c
  32910. --- linux-3.12.26.orig/drivers/net/bonding/bond_alb.c 2014-07-30 18:02:44.000000000 +0200
  32911. +++ linux-3.12.26/drivers/net/bonding/bond_alb.c 2014-08-06 16:50:14.597963124 +0200
  32912. @@ -694,7 +694,7 @@
  32913. client_info->ntt = 0;
  32914. }
  32915. - if (vlan_get_tag(skb, &client_info->vlan_id))
  32916. + if (!vlan_get_tag(skb, &client_info->vlan_id))
  32917. client_info->vlan_id = 0;
  32918. if (!client_info->assigned) {
  32919. diff -Nur linux-3.12.26.orig/drivers/net/ethernet/broadcom/bnx2.c linux-3.12.26/drivers/net/ethernet/broadcom/bnx2.c
  32920. --- linux-3.12.26.orig/drivers/net/ethernet/broadcom/bnx2.c 2014-07-30 18:02:44.000000000 +0200
  32921. +++ linux-3.12.26/drivers/net/ethernet/broadcom/bnx2.c 2014-08-06 16:50:14.621963313 +0200
  32922. @@ -2490,7 +2490,6 @@
  32923. bp->fw_wr_seq++;
  32924. msg_data |= bp->fw_wr_seq;
  32925. - bp->fw_last_msg = msg_data;
  32926. bnx2_shmem_wr(bp, BNX2_DRV_MB, msg_data);
  32927. @@ -3983,23 +3982,8 @@
  32928. wol_msg = BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL;
  32929. }
  32930. - if (!(bp->flags & BNX2_FLAG_NO_WOL)) {
  32931. - u32 val;
  32932. -
  32933. - wol_msg |= BNX2_DRV_MSG_DATA_WAIT3;
  32934. - if (bp->fw_last_msg || BNX2_CHIP(bp) != BNX2_CHIP_5709) {
  32935. - bnx2_fw_sync(bp, wol_msg, 1, 0);
  32936. - return;
  32937. - }
  32938. - /* Tell firmware not to power down the PHY yet, otherwise
  32939. - * the chip will take a long time to respond to MMIO reads.
  32940. - */
  32941. - val = bnx2_shmem_rd(bp, BNX2_PORT_FEATURE);
  32942. - bnx2_shmem_wr(bp, BNX2_PORT_FEATURE,
  32943. - val | BNX2_PORT_FEATURE_ASF_ENABLED);
  32944. - bnx2_fw_sync(bp, wol_msg, 1, 0);
  32945. - bnx2_shmem_wr(bp, BNX2_PORT_FEATURE, val);
  32946. - }
  32947. + if (!(bp->flags & BNX2_FLAG_NO_WOL))
  32948. + bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT3 | wol_msg, 1, 0);
  32949. }
  32950. @@ -4031,22 +4015,9 @@
  32951. if (bp->wol)
  32952. pci_set_power_state(bp->pdev, PCI_D3hot);
  32953. - break;
  32954. -
  32955. - }
  32956. - if (!bp->fw_last_msg && BNX2_CHIP(bp) == BNX2_CHIP_5709) {
  32957. - u32 val;
  32958. -
  32959. - /* Tell firmware not to power down the PHY yet,
  32960. - * otherwise the other port may not respond to
  32961. - * MMIO reads.
  32962. - */
  32963. - val = bnx2_shmem_rd(bp, BNX2_BC_STATE_CONDITION);
  32964. - val &= ~BNX2_CONDITION_PM_STATE_MASK;
  32965. - val |= BNX2_CONDITION_PM_STATE_UNPREP;
  32966. - bnx2_shmem_wr(bp, BNX2_BC_STATE_CONDITION, val);
  32967. + } else {
  32968. + pci_set_power_state(bp->pdev, PCI_D3hot);
  32969. }
  32970. - pci_set_power_state(bp->pdev, PCI_D3hot);
  32971. /* No more memory access after this point until
  32972. * device is brought back to D0.
  32973. diff -Nur linux-3.12.26.orig/drivers/net/ethernet/broadcom/bnx2.h linux-3.12.26/drivers/net/ethernet/broadcom/bnx2.h
  32974. --- linux-3.12.26.orig/drivers/net/ethernet/broadcom/bnx2.h 2014-07-30 18:02:44.000000000 +0200
  32975. +++ linux-3.12.26/drivers/net/ethernet/broadcom/bnx2.h 2014-08-06 16:50:14.633963407 +0200
  32976. @@ -6890,7 +6890,6 @@
  32977. u16 fw_wr_seq;
  32978. u16 fw_drv_pulse_wr_seq;
  32979. - u32 fw_last_msg;
  32980. int rx_max_ring;
  32981. int rx_ring_size;
  32982. @@ -7397,10 +7396,6 @@
  32983. #define BNX2_CONDITION_MFW_RUN_NCSI 0x00006000
  32984. #define BNX2_CONDITION_MFW_RUN_NONE 0x0000e000
  32985. #define BNX2_CONDITION_MFW_RUN_MASK 0x0000e000
  32986. -#define BNX2_CONDITION_PM_STATE_MASK 0x00030000
  32987. -#define BNX2_CONDITION_PM_STATE_FULL 0x00030000
  32988. -#define BNX2_CONDITION_PM_STATE_PREP 0x00020000
  32989. -#define BNX2_CONDITION_PM_STATE_UNPREP 0x00010000
  32990. #define BNX2_BC_STATE_DEBUG_CMD 0x1dc
  32991. #define BNX2_BC_STATE_BC_DBG_CMD_SIGNATURE 0x42440000
  32992. diff -Nur linux-3.12.26.orig/drivers/net/ethernet/broadcom/tg3.c linux-3.12.26/drivers/net/ethernet/broadcom/tg3.c
  32993. --- linux-3.12.26.orig/drivers/net/ethernet/broadcom/tg3.c 2014-07-30 18:02:44.000000000 +0200
  32994. +++ linux-3.12.26/drivers/net/ethernet/broadcom/tg3.c 2014-08-06 16:50:14.645963501 +0200
  32995. @@ -17482,6 +17482,8 @@
  32996. tg3_init_bufmgr_config(tp);
  32997. + features |= NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX;
  32998. +
  32999. /* 5700 B0 chips do not support checksumming correctly due
  33000. * to hardware bugs.
  33001. */
  33002. @@ -17513,8 +17515,7 @@
  33003. features |= NETIF_F_TSO_ECN;
  33004. }
  33005. - dev->features |= features | NETIF_F_HW_VLAN_CTAG_TX |
  33006. - NETIF_F_HW_VLAN_CTAG_RX;
  33007. + dev->features |= features;
  33008. dev->vlan_features |= features;
  33009. /*
  33010. diff -Nur linux-3.12.26.orig/drivers/net/ethernet/freescale/fec_main.c linux-3.12.26/drivers/net/ethernet/freescale/fec_main.c
  33011. --- linux-3.12.26.orig/drivers/net/ethernet/freescale/fec_main.c 2014-07-30 18:02:44.000000000 +0200
  33012. +++ linux-3.12.26/drivers/net/ethernet/freescale/fec_main.c 2014-08-06 16:50:14.645963501 +0200
  33013. @@ -525,6 +525,13 @@
  33014. /* Clear any outstanding interrupt. */
  33015. writel(0xffc00000, fep->hwp + FEC_IEVENT);
  33016. + /* Setup multicast filter. */
  33017. + set_multicast_list(ndev);
  33018. +#ifndef CONFIG_M5272
  33019. + writel(0, fep->hwp + FEC_HASH_TABLE_HIGH);
  33020. + writel(0, fep->hwp + FEC_HASH_TABLE_LOW);
  33021. +#endif
  33022. +
  33023. /* Set maximum receive buffer size. */
  33024. writel(PKT_MAXBLR_SIZE, fep->hwp + FEC_R_BUFF_SIZE);
  33025. @@ -645,13 +652,6 @@
  33026. writel(rcntl, fep->hwp + FEC_R_CNTRL);
  33027. - /* Setup multicast filter. */
  33028. - set_multicast_list(ndev);
  33029. -#ifndef CONFIG_M5272
  33030. - writel(0, fep->hwp + FEC_HASH_TABLE_HIGH);
  33031. - writel(0, fep->hwp + FEC_HASH_TABLE_LOW);
  33032. -#endif
  33033. -
  33034. if (id_entry->driver_data & FEC_QUIRK_ENET_MAC) {
  33035. /* enable ENET endian swap */
  33036. ecntl |= (1 << 8);
  33037. diff -Nur linux-3.12.26.orig/drivers/net/ethernet/micrel/ks8851.c linux-3.12.26/drivers/net/ethernet/micrel/ks8851.c
  33038. --- linux-3.12.26.orig/drivers/net/ethernet/micrel/ks8851.c 2014-07-30 18:02:44.000000000 +0200
  33039. +++ linux-3.12.26/drivers/net/ethernet/micrel/ks8851.c 2014-08-06 16:50:14.657963595 +0200
  33040. @@ -23,7 +23,6 @@
  33041. #include <linux/crc32.h>
  33042. #include <linux/mii.h>
  33043. #include <linux/eeprom_93cx6.h>
  33044. -#include <linux/regulator/consumer.h>
  33045. #include <linux/spi/spi.h>
  33046. @@ -84,7 +83,6 @@
  33047. * @rc_rxqcr: Cached copy of KS_RXQCR.
  33048. * @eeprom_size: Companion eeprom size in Bytes, 0 if no eeprom
  33049. * @eeprom: 93CX6 EEPROM state for accessing on-board EEPROM.
  33050. - * @vdd_reg: Optional regulator supplying the chip
  33051. *
  33052. * The @lock ensures that the chip is protected when certain operations are
  33053. * in progress. When the read or write packet transfer is in progress, most
  33054. @@ -132,7 +130,6 @@
  33055. struct spi_transfer spi_xfer2[2];
  33056. struct eeprom_93cx6 eeprom;
  33057. - struct regulator *vdd_reg;
  33058. };
  33059. static int msg_enable;
  33060. @@ -1417,21 +1414,6 @@
  33061. ks->spidev = spi;
  33062. ks->tx_space = 6144;
  33063. - ks->vdd_reg = regulator_get_optional(&spi->dev, "vdd");
  33064. - if (IS_ERR(ks->vdd_reg)) {
  33065. - ret = PTR_ERR(ks->vdd_reg);
  33066. - if (ret == -EPROBE_DEFER)
  33067. - goto err_reg;
  33068. - } else {
  33069. - ret = regulator_enable(ks->vdd_reg);
  33070. - if (ret) {
  33071. - dev_err(&spi->dev, "regulator enable fail: %d\n",
  33072. - ret);
  33073. - goto err_reg_en;
  33074. - }
  33075. - }
  33076. -
  33077. -
  33078. mutex_init(&ks->lock);
  33079. spin_lock_init(&ks->statelock);
  33080. @@ -1526,14 +1508,8 @@
  33081. err_netdev:
  33082. free_irq(ndev->irq, ks);
  33083. -err_irq:
  33084. err_id:
  33085. - if (!IS_ERR(ks->vdd_reg))
  33086. - regulator_disable(ks->vdd_reg);
  33087. -err_reg_en:
  33088. - if (!IS_ERR(ks->vdd_reg))
  33089. - regulator_put(ks->vdd_reg);
  33090. -err_reg:
  33091. +err_irq:
  33092. free_netdev(ndev);
  33093. return ret;
  33094. }
  33095. @@ -1547,10 +1523,6 @@
  33096. unregister_netdev(priv->netdev);
  33097. free_irq(spi->irq, priv);
  33098. - if (!IS_ERR(priv->vdd_reg)) {
  33099. - regulator_disable(priv->vdd_reg);
  33100. - regulator_put(priv->vdd_reg);
  33101. - }
  33102. free_netdev(priv->netdev);
  33103. return 0;
  33104. diff -Nur linux-3.12.26.orig/drivers/net/usb/smsc95xx.c linux-3.12.26/drivers/net/usb/smsc95xx.c
  33105. --- linux-3.12.26.orig/drivers/net/usb/smsc95xx.c 2014-07-30 18:02:44.000000000 +0200
  33106. +++ linux-3.12.26/drivers/net/usb/smsc95xx.c 2014-08-06 16:50:14.681963784 +0200
  33107. @@ -61,6 +61,7 @@
  33108. #define SUSPEND_SUSPEND3 (0x08)
  33109. #define SUSPEND_ALLMODES (SUSPEND_SUSPEND0 | SUSPEND_SUSPEND1 | \
  33110. SUSPEND_SUSPEND2 | SUSPEND_SUSPEND3)
  33111. +#define MAC_ADDR_LEN (6)
  33112. struct smsc95xx_priv {
  33113. u32 mac_cr;
  33114. @@ -76,6 +77,10 @@
  33115. module_param(turbo_mode, bool, 0644);
  33116. MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction");
  33117. +static char *macaddr = ":";
  33118. +module_param(macaddr, charp, 0);
  33119. +MODULE_PARM_DESC(macaddr, "MAC address");
  33120. +
  33121. static int __must_check __smsc95xx_read_reg(struct usbnet *dev, u32 index,
  33122. u32 *data, int in_pm)
  33123. {
  33124. @@ -765,8 +770,59 @@
  33125. return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
  33126. }
  33127. +/* Check the macaddr module parameter for a MAC address */
  33128. +static int smsc95xx_is_macaddr_param(struct usbnet *dev, u8 *dev_mac)
  33129. +{
  33130. + int i, j, got_num, num;
  33131. + u8 mtbl[MAC_ADDR_LEN];
  33132. +
  33133. + if (macaddr[0] == ':')
  33134. + return 0;
  33135. +
  33136. + i = 0;
  33137. + j = 0;
  33138. + num = 0;
  33139. + got_num = 0;
  33140. + while (j < MAC_ADDR_LEN) {
  33141. + if (macaddr[i] && macaddr[i] != ':') {
  33142. + got_num++;
  33143. + if ('0' <= macaddr[i] && macaddr[i] <= '9')
  33144. + num = num * 16 + macaddr[i] - '0';
  33145. + else if ('A' <= macaddr[i] && macaddr[i] <= 'F')
  33146. + num = num * 16 + 10 + macaddr[i] - 'A';
  33147. + else if ('a' <= macaddr[i] && macaddr[i] <= 'f')
  33148. + num = num * 16 + 10 + macaddr[i] - 'a';
  33149. + else
  33150. + break;
  33151. + i++;
  33152. + } else if (got_num == 2) {
  33153. + mtbl[j++] = (u8) num;
  33154. + num = 0;
  33155. + got_num = 0;
  33156. + i++;
  33157. + } else {
  33158. + break;
  33159. + }
  33160. + }
  33161. +
  33162. + if (j == MAC_ADDR_LEN) {
  33163. + netif_dbg(dev, ifup, dev->net, "Overriding MAC address with: "
  33164. + "%02x:%02x:%02x:%02x:%02x:%02x\n", mtbl[0], mtbl[1], mtbl[2],
  33165. + mtbl[3], mtbl[4], mtbl[5]);
  33166. + for (i = 0; i < MAC_ADDR_LEN; i++)
  33167. + dev_mac[i] = mtbl[i];
  33168. + return 1;
  33169. + } else {
  33170. + return 0;
  33171. + }
  33172. +}
  33173. +
  33174. static void smsc95xx_init_mac_address(struct usbnet *dev)
  33175. {
  33176. + /* Check module parameters */
  33177. + if (smsc95xx_is_macaddr_param(dev, dev->net->dev_addr))
  33178. + return;
  33179. +
  33180. /* try reading mac address from EEPROM */
  33181. if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
  33182. dev->net->dev_addr) == 0) {
  33183. diff -Nur linux-3.12.26.orig/drivers/net/usb/usbnet.c linux-3.12.26/drivers/net/usb/usbnet.c
  33184. --- linux-3.12.26.orig/drivers/net/usb/usbnet.c 2014-07-30 18:02:44.000000000 +0200
  33185. +++ linux-3.12.26/drivers/net/usb/usbnet.c 2014-08-06 16:50:14.685963816 +0200
  33186. @@ -753,12 +753,14 @@
  33187. // precondition: never called in_interrupt
  33188. static void usbnet_terminate_urbs(struct usbnet *dev)
  33189. {
  33190. + DECLARE_WAIT_QUEUE_HEAD_ONSTACK(unlink_wakeup);
  33191. DECLARE_WAITQUEUE(wait, current);
  33192. int temp;
  33193. /* ensure there are no more active urbs */
  33194. - add_wait_queue(&dev->wait, &wait);
  33195. + add_wait_queue(&unlink_wakeup, &wait);
  33196. set_current_state(TASK_UNINTERRUPTIBLE);
  33197. + dev->wait = &unlink_wakeup;
  33198. temp = unlink_urbs(dev, &dev->txq) +
  33199. unlink_urbs(dev, &dev->rxq);
  33200. @@ -772,14 +774,15 @@
  33201. "waited for %d urb completions\n", temp);
  33202. }
  33203. set_current_state(TASK_RUNNING);
  33204. - remove_wait_queue(&dev->wait, &wait);
  33205. + dev->wait = NULL;
  33206. + remove_wait_queue(&unlink_wakeup, &wait);
  33207. }
  33208. int usbnet_stop (struct net_device *net)
  33209. {
  33210. struct usbnet *dev = netdev_priv(net);
  33211. struct driver_info *info = dev->driver_info;
  33212. - int retval, pm;
  33213. + int retval;
  33214. clear_bit(EVENT_DEV_OPEN, &dev->flags);
  33215. netif_stop_queue (net);
  33216. @@ -789,8 +792,6 @@
  33217. net->stats.rx_packets, net->stats.tx_packets,
  33218. net->stats.rx_errors, net->stats.tx_errors);
  33219. - /* to not race resume */
  33220. - pm = usb_autopm_get_interface(dev->intf);
  33221. /* allow minidriver to stop correctly (wireless devices to turn off
  33222. * radio etc) */
  33223. if (info->stop) {
  33224. @@ -817,9 +818,6 @@
  33225. dev->flags = 0;
  33226. del_timer_sync (&dev->delay);
  33227. tasklet_kill (&dev->bh);
  33228. - if (!pm)
  33229. - usb_autopm_put_interface(dev->intf);
  33230. -
  33231. if (info->manage_power &&
  33232. !test_and_clear_bit(EVENT_NO_RUNTIME_PM, &dev->flags))
  33233. info->manage_power(dev, 0);
  33234. @@ -1440,12 +1438,11 @@
  33235. /* restart RX again after disabling due to high error rate */
  33236. clear_bit(EVENT_RX_KILL, &dev->flags);
  33237. - /* waiting for all pending urbs to complete?
  33238. - * only then can we forgo submitting anew
  33239. - */
  33240. - if (waitqueue_active(&dev->wait)) {
  33241. - if (dev->txq.qlen + dev->rxq.qlen + dev->done.qlen == 0)
  33242. - wake_up_all(&dev->wait);
  33243. + // waiting for all pending urbs to complete?
  33244. + if (dev->wait) {
  33245. + if ((dev->txq.qlen + dev->rxq.qlen + dev->done.qlen) == 0) {
  33246. + wake_up (dev->wait);
  33247. + }
  33248. // or are we maybe short a few urbs?
  33249. } else if (netif_running (dev->net) &&
  33250. @@ -1584,7 +1581,6 @@
  33251. dev->driver_name = name;
  33252. dev->msg_enable = netif_msg_init (msg_level, NETIF_MSG_DRV
  33253. | NETIF_MSG_PROBE | NETIF_MSG_LINK);
  33254. - init_waitqueue_head(&dev->wait);
  33255. skb_queue_head_init (&dev->rxq);
  33256. skb_queue_head_init (&dev->txq);
  33257. skb_queue_head_init (&dev->done);
  33258. @@ -1796,10 +1792,9 @@
  33259. spin_unlock_irq(&dev->txq.lock);
  33260. if (test_bit(EVENT_DEV_OPEN, &dev->flags)) {
  33261. - /* handle remote wakeup ASAP
  33262. - * we cannot race against stop
  33263. - */
  33264. - if (netif_device_present(dev->net) &&
  33265. + /* handle remote wakeup ASAP */
  33266. + if (!dev->wait &&
  33267. + netif_device_present(dev->net) &&
  33268. !timer_pending(&dev->delay) &&
  33269. !test_bit(EVENT_RX_HALT, &dev->flags))
  33270. rx_alloc_submit(dev, GFP_NOIO);
  33271. diff -Nur linux-3.12.26.orig/drivers/net/vxlan.c linux-3.12.26/drivers/net/vxlan.c
  33272. --- linux-3.12.26.orig/drivers/net/vxlan.c 2014-07-30 18:02:44.000000000 +0200
  33273. +++ linux-3.12.26/drivers/net/vxlan.c 2014-08-06 16:50:14.709964003 +0200
  33274. @@ -781,9 +781,6 @@
  33275. if (err)
  33276. return err;
  33277. - if (vxlan->default_dst.remote_ip.sa.sa_family != ip.sa.sa_family)
  33278. - return -EAFNOSUPPORT;
  33279. -
  33280. spin_lock_bh(&vxlan->hash_lock);
  33281. err = vxlan_fdb_create(vxlan, addr, &ip, ndm->ndm_state, flags,
  33282. port, vni, ifindex, ndm->ndm_flags);
  33283. @@ -1215,9 +1212,6 @@
  33284. neigh_release(n);
  33285. - if (reply == NULL)
  33286. - goto out;
  33287. -
  33288. skb_reset_mac_header(reply);
  33289. __skb_pull(reply, skb_network_offset(reply));
  33290. reply->ip_summed = CHECKSUM_UNNECESSARY;
  33291. @@ -1239,103 +1233,15 @@
  33292. }
  33293. #if IS_ENABLED(CONFIG_IPV6)
  33294. -
  33295. -static struct sk_buff *vxlan_na_create(struct sk_buff *request,
  33296. - struct neighbour *n, bool isrouter)
  33297. -{
  33298. - struct net_device *dev = request->dev;
  33299. - struct sk_buff *reply;
  33300. - struct nd_msg *ns, *na;
  33301. - struct ipv6hdr *pip6;
  33302. - u8 *daddr;
  33303. - int na_olen = 8; /* opt hdr + ETH_ALEN for target */
  33304. - int ns_olen;
  33305. - int i, len;
  33306. -
  33307. - if (dev == NULL)
  33308. - return NULL;
  33309. -
  33310. - len = LL_RESERVED_SPACE(dev) + sizeof(struct ipv6hdr) +
  33311. - sizeof(*na) + na_olen + dev->needed_tailroom;
  33312. - reply = alloc_skb(len, GFP_ATOMIC);
  33313. - if (reply == NULL)
  33314. - return NULL;
  33315. -
  33316. - reply->protocol = htons(ETH_P_IPV6);
  33317. - reply->dev = dev;
  33318. - skb_reserve(reply, LL_RESERVED_SPACE(request->dev));
  33319. - skb_push(reply, sizeof(struct ethhdr));
  33320. - skb_set_mac_header(reply, 0);
  33321. -
  33322. - ns = (struct nd_msg *)skb_transport_header(request);
  33323. -
  33324. - daddr = eth_hdr(request)->h_source;
  33325. - ns_olen = request->len - skb_transport_offset(request) - sizeof(*ns);
  33326. - for (i = 0; i < ns_olen-1; i += (ns->opt[i+1]<<3)) {
  33327. - if (ns->opt[i] == ND_OPT_SOURCE_LL_ADDR) {
  33328. - daddr = ns->opt + i + sizeof(struct nd_opt_hdr);
  33329. - break;
  33330. - }
  33331. - }
  33332. -
  33333. - /* Ethernet header */
  33334. - memcpy(eth_hdr(reply)->h_dest, daddr, ETH_ALEN);
  33335. - memcpy(eth_hdr(reply)->h_source, n->ha, ETH_ALEN);
  33336. - eth_hdr(reply)->h_proto = htons(ETH_P_IPV6);
  33337. - reply->protocol = htons(ETH_P_IPV6);
  33338. -
  33339. - skb_pull(reply, sizeof(struct ethhdr));
  33340. - skb_set_network_header(reply, 0);
  33341. - skb_put(reply, sizeof(struct ipv6hdr));
  33342. -
  33343. - /* IPv6 header */
  33344. -
  33345. - pip6 = ipv6_hdr(reply);
  33346. - memset(pip6, 0, sizeof(struct ipv6hdr));
  33347. - pip6->version = 6;
  33348. - pip6->priority = ipv6_hdr(request)->priority;
  33349. - pip6->nexthdr = IPPROTO_ICMPV6;
  33350. - pip6->hop_limit = 255;
  33351. - pip6->daddr = ipv6_hdr(request)->saddr;
  33352. - pip6->saddr = *(struct in6_addr *)n->primary_key;
  33353. -
  33354. - skb_pull(reply, sizeof(struct ipv6hdr));
  33355. - skb_set_transport_header(reply, 0);
  33356. -
  33357. - na = (struct nd_msg *)skb_put(reply, sizeof(*na) + na_olen);
  33358. -
  33359. - /* Neighbor Advertisement */
  33360. - memset(na, 0, sizeof(*na)+na_olen);
  33361. - na->icmph.icmp6_type = NDISC_NEIGHBOUR_ADVERTISEMENT;
  33362. - na->icmph.icmp6_router = isrouter;
  33363. - na->icmph.icmp6_override = 1;
  33364. - na->icmph.icmp6_solicited = 1;
  33365. - na->target = ns->target;
  33366. - memcpy(&na->opt[2], n->ha, ETH_ALEN);
  33367. - na->opt[0] = ND_OPT_TARGET_LL_ADDR;
  33368. - na->opt[1] = na_olen >> 3;
  33369. -
  33370. - na->icmph.icmp6_cksum = csum_ipv6_magic(&pip6->saddr,
  33371. - &pip6->daddr, sizeof(*na)+na_olen, IPPROTO_ICMPV6,
  33372. - csum_partial(na, sizeof(*na)+na_olen, 0));
  33373. -
  33374. - pip6->payload_len = htons(sizeof(*na)+na_olen);
  33375. -
  33376. - skb_push(reply, sizeof(struct ipv6hdr));
  33377. -
  33378. - reply->ip_summed = CHECKSUM_UNNECESSARY;
  33379. -
  33380. - return reply;
  33381. -}
  33382. -
  33383. static int neigh_reduce(struct net_device *dev, struct sk_buff *skb)
  33384. {
  33385. struct vxlan_dev *vxlan = netdev_priv(dev);
  33386. - struct nd_msg *msg;
  33387. + struct neighbour *n;
  33388. + union vxlan_addr ipa;
  33389. const struct ipv6hdr *iphdr;
  33390. const struct in6_addr *saddr, *daddr;
  33391. - struct neighbour *n;
  33392. - struct inet6_dev *in6_dev;
  33393. + struct nd_msg *msg;
  33394. + struct inet6_dev *in6_dev = NULL;
  33395. in6_dev = __in6_dev_get(dev);
  33396. if (!in6_dev)
  33397. @@ -1348,20 +1254,19 @@
  33398. saddr = &iphdr->saddr;
  33399. daddr = &iphdr->daddr;
  33400. + if (ipv6_addr_loopback(daddr) ||
  33401. + ipv6_addr_is_multicast(daddr))
  33402. + goto out;
  33403. +
  33404. msg = (struct nd_msg *)skb_transport_header(skb);
  33405. if (msg->icmph.icmp6_code != 0 ||
  33406. msg->icmph.icmp6_type != NDISC_NEIGHBOUR_SOLICITATION)
  33407. goto out;
  33408. - if (ipv6_addr_loopback(daddr) ||
  33409. - ipv6_addr_is_multicast(&msg->target))
  33410. - goto out;
  33411. -
  33412. - n = neigh_lookup(ipv6_stub->nd_tbl, &msg->target, dev);
  33413. + n = neigh_lookup(ipv6_stub->nd_tbl, daddr, dev);
  33414. if (n) {
  33415. struct vxlan_fdb *f;
  33416. - struct sk_buff *reply;
  33417. if (!(n->nud_state & NUD_CONNECTED)) {
  33418. neigh_release(n);
  33419. @@ -1375,23 +1280,13 @@
  33420. goto out;
  33421. }
  33422. - reply = vxlan_na_create(skb, n,
  33423. - !!(f ? f->flags & NTF_ROUTER : 0));
  33424. -
  33425. + ipv6_stub->ndisc_send_na(dev, n, saddr, &msg->target,
  33426. + !!in6_dev->cnf.forwarding,
  33427. + true, false, false);
  33428. neigh_release(n);
  33429. -
  33430. - if (reply == NULL)
  33431. - goto out;
  33432. -
  33433. - if (netif_rx_ni(reply) == NET_RX_DROP)
  33434. - dev->stats.rx_dropped++;
  33435. -
  33436. } else if (vxlan->flags & VXLAN_F_L3MISS) {
  33437. - union vxlan_addr ipa = {
  33438. - .sin6.sin6_addr = msg->target,
  33439. - .sa.sa_family = AF_INET6,
  33440. - };
  33441. -
  33442. + ipa.sin6.sin6_addr = *daddr;
  33443. + ipa.sa.sa_family = AF_INET6;
  33444. vxlan_ip_miss(dev, &ipa);
  33445. }
  33446. @@ -2488,10 +2383,9 @@
  33447. vni = nla_get_u32(data[IFLA_VXLAN_ID]);
  33448. dst->remote_vni = vni;
  33449. - /* Unless IPv6 is explicitly requested, assume IPv4 */
  33450. - dst->remote_ip.sa.sa_family = AF_INET;
  33451. if (data[IFLA_VXLAN_GROUP]) {
  33452. dst->remote_ip.sin.sin_addr.s_addr = nla_get_be32(data[IFLA_VXLAN_GROUP]);
  33453. + dst->remote_ip.sa.sa_family = AF_INET;
  33454. } else if (data[IFLA_VXLAN_GROUP6]) {
  33455. if (!IS_ENABLED(CONFIG_IPV6))
  33456. return -EPFNOSUPPORT;
  33457. diff -Nur linux-3.12.26.orig/drivers/net/xen-netback/common.h linux-3.12.26/drivers/net/xen-netback/common.h
  33458. --- linux-3.12.26.orig/drivers/net/xen-netback/common.h 2014-07-30 18:02:44.000000000 +0200
  33459. +++ linux-3.12.26/drivers/net/xen-netback/common.h 2014-08-06 16:50:14.709964003 +0200
  33460. @@ -102,11 +102,6 @@
  33461. domid_t domid;
  33462. unsigned int handle;
  33463. - /* Is this interface disabled? True when backend discovers
  33464. - * frontend is rogue.
  33465. - */
  33466. - bool disabled;
  33467. -
  33468. /* Use NAPI for guest TX */
  33469. struct napi_struct napi;
  33470. /* When feature-split-event-channels = 0, tx_irq = rx_irq. */
  33471. diff -Nur linux-3.12.26.orig/drivers/net/xen-netback/interface.c linux-3.12.26/drivers/net/xen-netback/interface.c
  33472. --- linux-3.12.26.orig/drivers/net/xen-netback/interface.c 2014-07-30 18:02:44.000000000 +0200
  33473. +++ linux-3.12.26/drivers/net/xen-netback/interface.c 2014-08-06 16:50:14.709964003 +0200
  33474. @@ -66,15 +66,6 @@
  33475. struct xenvif *vif = container_of(napi, struct xenvif, napi);
  33476. int work_done;
  33477. - /* This vif is rogue, we pretend we've there is nothing to do
  33478. - * for this vif to deschedule it from NAPI. But this interface
  33479. - * will be turned off in thread context later.
  33480. - */
  33481. - if (unlikely(vif->disabled)) {
  33482. - napi_complete(napi);
  33483. - return 0;
  33484. - }
  33485. -
  33486. work_done = xenvif_tx_action(vif, budget);
  33487. if (work_done < budget) {
  33488. @@ -318,8 +309,6 @@
  33489. vif->csum = 1;
  33490. vif->dev = dev;
  33491. - vif->disabled = false;
  33492. -
  33493. vif->credit_bytes = vif->remaining_credit = ~0UL;
  33494. vif->credit_usec = 0UL;
  33495. init_timer(&vif->credit_timeout);
  33496. diff -Nur linux-3.12.26.orig/drivers/net/xen-netback/netback.c linux-3.12.26/drivers/net/xen-netback/netback.c
  33497. --- linux-3.12.26.orig/drivers/net/xen-netback/netback.c 2014-07-30 18:02:44.000000000 +0200
  33498. +++ linux-3.12.26/drivers/net/xen-netback/netback.c 2014-08-06 16:50:14.709964003 +0200
  33499. @@ -206,8 +206,8 @@
  33500. * into multiple copies tend to give large frags their
  33501. * own buffers as before.
  33502. */
  33503. - BUG_ON(size > MAX_BUFFER_OFFSET);
  33504. - if ((offset + size > MAX_BUFFER_OFFSET) && offset && !head)
  33505. + if ((offset + size > MAX_BUFFER_OFFSET) &&
  33506. + (size <= MAX_BUFFER_OFFSET) && offset && !head)
  33507. return true;
  33508. return false;
  33509. @@ -731,8 +731,7 @@
  33510. static void xenvif_fatal_tx_err(struct xenvif *vif)
  33511. {
  33512. netdev_err(vif->dev, "fatal error; disabling device\n");
  33513. - vif->disabled = true;
  33514. - xenvif_kick_thread(vif);
  33515. + xenvif_carrier_off(vif);
  33516. }
  33517. static int xenvif_count_requests(struct xenvif *vif,
  33518. @@ -1243,7 +1242,7 @@
  33519. vif->tx.sring->req_prod, vif->tx.req_cons,
  33520. XEN_NETIF_TX_RING_SIZE);
  33521. xenvif_fatal_tx_err(vif);
  33522. - break;
  33523. + continue;
  33524. }
  33525. RING_FINAL_CHECK_FOR_REQUESTS(&vif->tx, work_to_do);
  33526. @@ -1643,18 +1642,7 @@
  33527. while (!kthread_should_stop()) {
  33528. wait_event_interruptible(vif->wq,
  33529. rx_work_todo(vif) ||
  33530. - vif->disabled ||
  33531. kthread_should_stop());
  33532. -
  33533. - /* This frontend is found to be rogue, disable it in
  33534. - * kthread context. Currently this is only set when
  33535. - * netback finds out frontend sends malformed packet,
  33536. - * but we cannot disable the interface in softirq
  33537. - * context so we defer it here.
  33538. - */
  33539. - if (unlikely(vif->disabled && netif_carrier_ok(vif->dev)))
  33540. - xenvif_carrier_off(vif);
  33541. -
  33542. if (kthread_should_stop())
  33543. break;
  33544. diff -Nur linux-3.12.26.orig/drivers/pci/host/pci-mvebu.c linux-3.12.26/drivers/pci/host/pci-mvebu.c
  33545. --- linux-3.12.26.orig/drivers/pci/host/pci-mvebu.c 2014-07-30 18:02:44.000000000 +0200
  33546. +++ linux-3.12.26/drivers/pci/host/pci-mvebu.c 2014-08-06 16:50:14.709964003 +0200
  33547. @@ -866,23 +866,11 @@
  33548. continue;
  33549. }
  33550. - port->clk = of_clk_get_by_name(child, NULL);
  33551. - if (IS_ERR(port->clk)) {
  33552. - dev_err(&pdev->dev, "PCIe%d.%d: cannot get clock\n",
  33553. - port->port, port->lane);
  33554. - continue;
  33555. - }
  33556. -
  33557. - ret = clk_prepare_enable(port->clk);
  33558. - if (ret)
  33559. - continue;
  33560. -
  33561. port->base = mvebu_pcie_map_registers(pdev, child, port);
  33562. if (IS_ERR(port->base)) {
  33563. dev_err(&pdev->dev, "PCIe%d.%d: cannot map registers\n",
  33564. port->port, port->lane);
  33565. port->base = NULL;
  33566. - clk_disable_unprepare(port->clk);
  33567. continue;
  33568. }
  33569. @@ -898,9 +886,22 @@
  33570. port->port, port->lane);
  33571. }
  33572. + port->clk = of_clk_get_by_name(child, NULL);
  33573. + if (IS_ERR(port->clk)) {
  33574. + dev_err(&pdev->dev, "PCIe%d.%d: cannot get clock\n",
  33575. + port->port, port->lane);
  33576. + iounmap(port->base);
  33577. + port->haslink = 0;
  33578. + continue;
  33579. + }
  33580. +
  33581. port->dn = child;
  33582. +
  33583. + clk_prepare_enable(port->clk);
  33584. spin_lock_init(&port->conf_lock);
  33585. +
  33586. mvebu_sw_pci_bridge_init(port);
  33587. +
  33588. i++;
  33589. }
  33590. diff -Nur linux-3.12.26.orig/drivers/spi/Kconfig linux-3.12.26/drivers/spi/Kconfig
  33591. --- linux-3.12.26.orig/drivers/spi/Kconfig 2014-07-30 18:02:44.000000000 +0200
  33592. +++ linux-3.12.26/drivers/spi/Kconfig 2014-08-06 16:50:14.713964035 +0200
  33593. @@ -85,6 +85,14 @@
  33594. is for the regular SPI controller. Slave mode operation is not also
  33595. not supported.
  33596. +config SPI_BCM2708
  33597. + tristate "BCM2708 SPI controller driver (SPI0)"
  33598. + depends on MACH_BCM2708
  33599. + help
  33600. + This selects a driver for the Broadcom BCM2708 SPI master (SPI0). This
  33601. + driver is not compatible with the "Universal SPI Master" or the SPI slave
  33602. + device.
  33603. +
  33604. config SPI_BFIN5XX
  33605. tristate "SPI controller driver for ADI Blackfin5xx"
  33606. depends on BLACKFIN && !BF60x
  33607. diff -Nur linux-3.12.26.orig/drivers/spi/Makefile linux-3.12.26/drivers/spi/Makefile
  33608. --- linux-3.12.26.orig/drivers/spi/Makefile 2014-07-30 18:02:44.000000000 +0200
  33609. +++ linux-3.12.26/drivers/spi/Makefile 2014-08-06 16:50:14.713964035 +0200
  33610. @@ -18,6 +18,7 @@
  33611. obj-$(CONFIG_SPI_BCM63XX) += spi-bcm63xx.o
  33612. obj-$(CONFIG_SPI_BFIN5XX) += spi-bfin5xx.o
  33613. obj-$(CONFIG_SPI_BFIN_V3) += spi-bfin-v3.o
  33614. +obj-$(CONFIG_SPI_BCM2708) += spi-bcm2708.o
  33615. obj-$(CONFIG_SPI_BFIN_SPORT) += spi-bfin-sport.o
  33616. obj-$(CONFIG_SPI_BITBANG) += spi-bitbang.o
  33617. obj-$(CONFIG_SPI_BUTTERFLY) += spi-butterfly.o
  33618. diff -Nur linux-3.12.26.orig/drivers/spi/spi-bcm2708.c linux-3.12.26/drivers/spi/spi-bcm2708.c
  33619. --- linux-3.12.26.orig/drivers/spi/spi-bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  33620. +++ linux-3.12.26/drivers/spi/spi-bcm2708.c 2014-08-06 16:50:14.713964035 +0200
  33621. @@ -0,0 +1,626 @@
  33622. +/*
  33623. + * Driver for Broadcom BCM2708 SPI Controllers
  33624. + *
  33625. + * Copyright (C) 2012 Chris Boot
  33626. + *
  33627. + * This driver is inspired by:
  33628. + * spi-ath79.c, Copyright (C) 2009-2011 Gabor Juhos <juhosg@openwrt.org>
  33629. + * spi-atmel.c, Copyright (C) 2006 Atmel Corporation
  33630. + *
  33631. + * This program is free software; you can redistribute it and/or modify
  33632. + * it under the terms of the GNU General Public License as published by
  33633. + * the Free Software Foundation; either version 2 of the License, or
  33634. + * (at your option) any later version.
  33635. + *
  33636. + * This program is distributed in the hope that it will be useful,
  33637. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  33638. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  33639. + * GNU General Public License for more details.
  33640. + *
  33641. + * You should have received a copy of the GNU General Public License
  33642. + * along with this program; if not, write to the Free Software
  33643. + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  33644. + */
  33645. +
  33646. +#include <linux/kernel.h>
  33647. +#include <linux/module.h>
  33648. +#include <linux/spinlock.h>
  33649. +#include <linux/clk.h>
  33650. +#include <linux/err.h>
  33651. +#include <linux/platform_device.h>
  33652. +#include <linux/io.h>
  33653. +#include <linux/spi/spi.h>
  33654. +#include <linux/interrupt.h>
  33655. +#include <linux/delay.h>
  33656. +#include <linux/log2.h>
  33657. +#include <linux/sched.h>
  33658. +#include <linux/wait.h>
  33659. +
  33660. +/* SPI register offsets */
  33661. +#define SPI_CS 0x00
  33662. +#define SPI_FIFO 0x04
  33663. +#define SPI_CLK 0x08
  33664. +#define SPI_DLEN 0x0c
  33665. +#define SPI_LTOH 0x10
  33666. +#define SPI_DC 0x14
  33667. +
  33668. +/* Bitfields in CS */
  33669. +#define SPI_CS_LEN_LONG 0x02000000
  33670. +#define SPI_CS_DMA_LEN 0x01000000
  33671. +#define SPI_CS_CSPOL2 0x00800000
  33672. +#define SPI_CS_CSPOL1 0x00400000
  33673. +#define SPI_CS_CSPOL0 0x00200000
  33674. +#define SPI_CS_RXF 0x00100000
  33675. +#define SPI_CS_RXR 0x00080000
  33676. +#define SPI_CS_TXD 0x00040000
  33677. +#define SPI_CS_RXD 0x00020000
  33678. +#define SPI_CS_DONE 0x00010000
  33679. +#define SPI_CS_LEN 0x00002000
  33680. +#define SPI_CS_REN 0x00001000
  33681. +#define SPI_CS_ADCS 0x00000800
  33682. +#define SPI_CS_INTR 0x00000400
  33683. +#define SPI_CS_INTD 0x00000200
  33684. +#define SPI_CS_DMAEN 0x00000100
  33685. +#define SPI_CS_TA 0x00000080
  33686. +#define SPI_CS_CSPOL 0x00000040
  33687. +#define SPI_CS_CLEAR_RX 0x00000020
  33688. +#define SPI_CS_CLEAR_TX 0x00000010
  33689. +#define SPI_CS_CPOL 0x00000008
  33690. +#define SPI_CS_CPHA 0x00000004
  33691. +#define SPI_CS_CS_10 0x00000002
  33692. +#define SPI_CS_CS_01 0x00000001
  33693. +
  33694. +#define SPI_TIMEOUT_MS 150
  33695. +
  33696. +#define DRV_NAME "bcm2708_spi"
  33697. +
  33698. +struct bcm2708_spi {
  33699. + spinlock_t lock;
  33700. + void __iomem *base;
  33701. + int irq;
  33702. + struct clk *clk;
  33703. + bool stopping;
  33704. +
  33705. + struct list_head queue;
  33706. + struct workqueue_struct *workq;
  33707. + struct work_struct work;
  33708. + struct completion done;
  33709. +
  33710. + const u8 *tx_buf;
  33711. + u8 *rx_buf;
  33712. + int len;
  33713. +};
  33714. +
  33715. +struct bcm2708_spi_state {
  33716. + u32 cs;
  33717. + u16 cdiv;
  33718. +};
  33719. +
  33720. +/*
  33721. + * This function sets the ALT mode on the SPI pins so that we can use them with
  33722. + * the SPI hardware.
  33723. + *
  33724. + * FIXME: This is a hack. Use pinmux / pinctrl.
  33725. + */
  33726. +static void bcm2708_init_pinmode(void)
  33727. +{
  33728. +#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
  33729. +#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
  33730. +
  33731. + int pin;
  33732. + u32 *gpio = ioremap(0x20200000, SZ_16K);
  33733. +
  33734. + /* SPI is on GPIO 7..11 */
  33735. + for (pin = 7; pin <= 11; pin++) {
  33736. + INP_GPIO(pin); /* set mode to GPIO input first */
  33737. + SET_GPIO_ALT(pin, 0); /* set mode to ALT 0 */
  33738. + }
  33739. +
  33740. + iounmap(gpio);
  33741. +
  33742. +#undef INP_GPIO
  33743. +#undef SET_GPIO_ALT
  33744. +}
  33745. +
  33746. +static inline u32 bcm2708_rd(struct bcm2708_spi *bs, unsigned reg)
  33747. +{
  33748. + return readl(bs->base + reg);
  33749. +}
  33750. +
  33751. +static inline void bcm2708_wr(struct bcm2708_spi *bs, unsigned reg, u32 val)
  33752. +{
  33753. + writel(val, bs->base + reg);
  33754. +}
  33755. +
  33756. +static inline void bcm2708_rd_fifo(struct bcm2708_spi *bs, int len)
  33757. +{
  33758. + u8 byte;
  33759. +
  33760. + while (len--) {
  33761. + byte = bcm2708_rd(bs, SPI_FIFO);
  33762. + if (bs->rx_buf)
  33763. + *bs->rx_buf++ = byte;
  33764. + }
  33765. +}
  33766. +
  33767. +static inline void bcm2708_wr_fifo(struct bcm2708_spi *bs, int len)
  33768. +{
  33769. + u8 byte;
  33770. + u16 val;
  33771. +
  33772. + if (len > bs->len)
  33773. + len = bs->len;
  33774. +
  33775. + if (unlikely(bcm2708_rd(bs, SPI_CS) & SPI_CS_LEN)) {
  33776. + /* LoSSI mode */
  33777. + if (unlikely(len % 2)) {
  33778. + printk(KERN_ERR"bcm2708_wr_fifo: length must be even, skipping.\n");
  33779. + bs->len = 0;
  33780. + return;
  33781. + }
  33782. + while (len) {
  33783. + if (bs->tx_buf) {
  33784. + val = *(const u16 *)bs->tx_buf;
  33785. + bs->tx_buf += 2;
  33786. + } else
  33787. + val = 0;
  33788. + bcm2708_wr(bs, SPI_FIFO, val);
  33789. + bs->len -= 2;
  33790. + len -= 2;
  33791. + }
  33792. + return;
  33793. + }
  33794. +
  33795. + while (len--) {
  33796. + byte = bs->tx_buf ? *bs->tx_buf++ : 0;
  33797. + bcm2708_wr(bs, SPI_FIFO, byte);
  33798. + bs->len--;
  33799. + }
  33800. +}
  33801. +
  33802. +static irqreturn_t bcm2708_spi_interrupt(int irq, void *dev_id)
  33803. +{
  33804. + struct spi_master *master = dev_id;
  33805. + struct bcm2708_spi *bs = spi_master_get_devdata(master);
  33806. + u32 cs;
  33807. +
  33808. + spin_lock(&bs->lock);
  33809. +
  33810. + cs = bcm2708_rd(bs, SPI_CS);
  33811. +
  33812. + if (cs & SPI_CS_DONE) {
  33813. + if (bs->len) { /* first interrupt in a transfer */
  33814. + /* fill the TX fifo with up to 16 bytes */
  33815. + bcm2708_wr_fifo(bs, 16);
  33816. + } else { /* transfer complete */
  33817. + /* disable interrupts */
  33818. + cs &= ~(SPI_CS_INTR | SPI_CS_INTD);
  33819. + bcm2708_wr(bs, SPI_CS, cs);
  33820. +
  33821. + /* drain RX FIFO */
  33822. + while (cs & SPI_CS_RXD) {
  33823. + bcm2708_rd_fifo(bs, 1);
  33824. + cs = bcm2708_rd(bs, SPI_CS);
  33825. + }
  33826. +
  33827. + /* wake up our bh */
  33828. + complete(&bs->done);
  33829. + }
  33830. + } else if (cs & SPI_CS_RXR) {
  33831. + /* read 12 bytes of data */
  33832. + bcm2708_rd_fifo(bs, 12);
  33833. +
  33834. + /* write up to 12 bytes */
  33835. + bcm2708_wr_fifo(bs, 12);
  33836. + }
  33837. +
  33838. + spin_unlock(&bs->lock);
  33839. +
  33840. + return IRQ_HANDLED;
  33841. +}
  33842. +
  33843. +static int bcm2708_setup_state(struct spi_master *master,
  33844. + struct device *dev, struct bcm2708_spi_state *state,
  33845. + u32 hz, u8 csel, u8 mode, u8 bpw)
  33846. +{
  33847. + struct bcm2708_spi *bs = spi_master_get_devdata(master);
  33848. + int cdiv;
  33849. + unsigned long bus_hz;
  33850. + u32 cs = 0;
  33851. +
  33852. + bus_hz = clk_get_rate(bs->clk);
  33853. +
  33854. + if (hz >= bus_hz) {
  33855. + cdiv = 2; /* bus_hz / 2 is as fast as we can go */
  33856. + } else if (hz) {
  33857. + cdiv = DIV_ROUND_UP(bus_hz, hz);
  33858. +
  33859. + /* CDIV must be a power of 2, so round up */
  33860. + cdiv = roundup_pow_of_two(cdiv);
  33861. +
  33862. + if (cdiv > 65536) {
  33863. + dev_dbg(dev,
  33864. + "setup: %d Hz too slow, cdiv %u; min %ld Hz\n",
  33865. + hz, cdiv, bus_hz / 65536);
  33866. + return -EINVAL;
  33867. + } else if (cdiv == 65536) {
  33868. + cdiv = 0;
  33869. + } else if (cdiv == 1) {
  33870. + cdiv = 2; /* 1 gets rounded down to 0; == 65536 */
  33871. + }
  33872. + } else {
  33873. + cdiv = 0;
  33874. + }
  33875. +
  33876. + switch (bpw) {
  33877. + case 8:
  33878. + break;
  33879. + case 9:
  33880. + /* Reading in LoSSI mode is a special case. See 'BCM2835 ARM Peripherals' datasheet */
  33881. + cs |= SPI_CS_LEN;
  33882. + break;
  33883. + default:
  33884. + dev_dbg(dev, "setup: invalid bits_per_word %u (must be 8 or 9)\n",
  33885. + bpw);
  33886. + return -EINVAL;
  33887. + }
  33888. +
  33889. + if (mode & SPI_CPOL)
  33890. + cs |= SPI_CS_CPOL;
  33891. + if (mode & SPI_CPHA)
  33892. + cs |= SPI_CS_CPHA;
  33893. +
  33894. + if (!(mode & SPI_NO_CS)) {
  33895. + if (mode & SPI_CS_HIGH) {
  33896. + cs |= SPI_CS_CSPOL;
  33897. + cs |= SPI_CS_CSPOL0 << csel;
  33898. + }
  33899. +
  33900. + cs |= csel;
  33901. + } else {
  33902. + cs |= SPI_CS_CS_10 | SPI_CS_CS_01;
  33903. + }
  33904. +
  33905. + if (state) {
  33906. + state->cs = cs;
  33907. + state->cdiv = cdiv;
  33908. + dev_dbg(dev, "setup: want %d Hz; "
  33909. + "bus_hz=%lu / cdiv=%u == %lu Hz; "
  33910. + "mode %u: cs 0x%08X\n",
  33911. + hz, bus_hz, cdiv, bus_hz/cdiv, mode, cs);
  33912. + }
  33913. +
  33914. + return 0;
  33915. +}
  33916. +
  33917. +static int bcm2708_process_transfer(struct bcm2708_spi *bs,
  33918. + struct spi_message *msg, struct spi_transfer *xfer)
  33919. +{
  33920. + struct spi_device *spi = msg->spi;
  33921. + struct bcm2708_spi_state state, *stp;
  33922. + int ret;
  33923. + u32 cs;
  33924. +
  33925. + if (bs->stopping)
  33926. + return -ESHUTDOWN;
  33927. +
  33928. + if (xfer->bits_per_word || xfer->speed_hz) {
  33929. + ret = bcm2708_setup_state(spi->master, &spi->dev, &state,
  33930. + xfer->speed_hz ? xfer->speed_hz : spi->max_speed_hz,
  33931. + spi->chip_select, spi->mode,
  33932. + xfer->bits_per_word ? xfer->bits_per_word :
  33933. + spi->bits_per_word);
  33934. + if (ret)
  33935. + return ret;
  33936. +
  33937. + stp = &state;
  33938. + } else {
  33939. + stp = spi->controller_state;
  33940. + }
  33941. +
  33942. + INIT_COMPLETION(bs->done);
  33943. + bs->tx_buf = xfer->tx_buf;
  33944. + bs->rx_buf = xfer->rx_buf;
  33945. + bs->len = xfer->len;
  33946. +
  33947. + cs = stp->cs | SPI_CS_INTR | SPI_CS_INTD | SPI_CS_TA;
  33948. +
  33949. + bcm2708_wr(bs, SPI_CLK, stp->cdiv);
  33950. + bcm2708_wr(bs, SPI_CS, cs);
  33951. +
  33952. + ret = wait_for_completion_timeout(&bs->done,
  33953. + msecs_to_jiffies(SPI_TIMEOUT_MS));
  33954. + if (ret == 0) {
  33955. + dev_err(&spi->dev, "transfer timed out\n");
  33956. + return -ETIMEDOUT;
  33957. + }
  33958. +
  33959. + if (xfer->delay_usecs)
  33960. + udelay(xfer->delay_usecs);
  33961. +
  33962. + if (list_is_last(&xfer->transfer_list, &msg->transfers) ||
  33963. + xfer->cs_change) {
  33964. + /* clear TA and interrupt flags */
  33965. + bcm2708_wr(bs, SPI_CS, stp->cs);
  33966. + }
  33967. +
  33968. + msg->actual_length += (xfer->len - bs->len);
  33969. +
  33970. + return 0;
  33971. +}
  33972. +
  33973. +static void bcm2708_work(struct work_struct *work)
  33974. +{
  33975. + struct bcm2708_spi *bs = container_of(work, struct bcm2708_spi, work);
  33976. + unsigned long flags;
  33977. + struct spi_message *msg;
  33978. + struct spi_transfer *xfer;
  33979. + int status = 0;
  33980. +
  33981. + spin_lock_irqsave(&bs->lock, flags);
  33982. + while (!list_empty(&bs->queue)) {
  33983. + msg = list_first_entry(&bs->queue, struct spi_message, queue);
  33984. + list_del_init(&msg->queue);
  33985. + spin_unlock_irqrestore(&bs->lock, flags);
  33986. +
  33987. + list_for_each_entry(xfer, &msg->transfers, transfer_list) {
  33988. + status = bcm2708_process_transfer(bs, msg, xfer);
  33989. + if (status)
  33990. + break;
  33991. + }
  33992. +
  33993. + msg->status = status;
  33994. + msg->complete(msg->context);
  33995. +
  33996. + spin_lock_irqsave(&bs->lock, flags);
  33997. + }
  33998. + spin_unlock_irqrestore(&bs->lock, flags);
  33999. +}
  34000. +
  34001. +static int bcm2708_spi_setup(struct spi_device *spi)
  34002. +{
  34003. + struct bcm2708_spi *bs = spi_master_get_devdata(spi->master);
  34004. + struct bcm2708_spi_state *state;
  34005. + int ret;
  34006. +
  34007. + if (bs->stopping)
  34008. + return -ESHUTDOWN;
  34009. +
  34010. + if (!(spi->mode & SPI_NO_CS) &&
  34011. + (spi->chip_select > spi->master->num_chipselect)) {
  34012. + dev_dbg(&spi->dev,
  34013. + "setup: invalid chipselect %u (%u defined)\n",
  34014. + spi->chip_select, spi->master->num_chipselect);
  34015. + return -EINVAL;
  34016. + }
  34017. +
  34018. + state = spi->controller_state;
  34019. + if (!state) {
  34020. + state = kzalloc(sizeof(*state), GFP_KERNEL);
  34021. + if (!state)
  34022. + return -ENOMEM;
  34023. +
  34024. + spi->controller_state = state;
  34025. + }
  34026. +
  34027. + ret = bcm2708_setup_state(spi->master, &spi->dev, state,
  34028. + spi->max_speed_hz, spi->chip_select, spi->mode,
  34029. + spi->bits_per_word);
  34030. + if (ret < 0) {
  34031. + kfree(state);
  34032. + spi->controller_state = NULL;
  34033. + return ret;
  34034. + }
  34035. +
  34036. + dev_dbg(&spi->dev,
  34037. + "setup: cd %d: %d Hz, bpw %u, mode 0x%x -> CS=%08x CDIV=%04x\n",
  34038. + spi->chip_select, spi->max_speed_hz, spi->bits_per_word,
  34039. + spi->mode, state->cs, state->cdiv);
  34040. +
  34041. + return 0;
  34042. +}
  34043. +
  34044. +static int bcm2708_spi_transfer(struct spi_device *spi, struct spi_message *msg)
  34045. +{
  34046. + struct bcm2708_spi *bs = spi_master_get_devdata(spi->master);
  34047. + struct spi_transfer *xfer;
  34048. + int ret;
  34049. + unsigned long flags;
  34050. +
  34051. + if (unlikely(list_empty(&msg->transfers)))
  34052. + return -EINVAL;
  34053. +
  34054. + if (bs->stopping)
  34055. + return -ESHUTDOWN;
  34056. +
  34057. + list_for_each_entry(xfer, &msg->transfers, transfer_list) {
  34058. + if (!(xfer->tx_buf || xfer->rx_buf) && xfer->len) {
  34059. + dev_dbg(&spi->dev, "missing rx or tx buf\n");
  34060. + return -EINVAL;
  34061. + }
  34062. +
  34063. + if (!xfer->bits_per_word || xfer->speed_hz)
  34064. + continue;
  34065. +
  34066. + ret = bcm2708_setup_state(spi->master, &spi->dev, NULL,
  34067. + xfer->speed_hz ? xfer->speed_hz : spi->max_speed_hz,
  34068. + spi->chip_select, spi->mode,
  34069. + xfer->bits_per_word ? xfer->bits_per_word :
  34070. + spi->bits_per_word);
  34071. + if (ret)
  34072. + return ret;
  34073. + }
  34074. +
  34075. + msg->status = -EINPROGRESS;
  34076. + msg->actual_length = 0;
  34077. +
  34078. + spin_lock_irqsave(&bs->lock, flags);
  34079. + list_add_tail(&msg->queue, &bs->queue);
  34080. + queue_work(bs->workq, &bs->work);
  34081. + spin_unlock_irqrestore(&bs->lock, flags);
  34082. +
  34083. + return 0;
  34084. +}
  34085. +
  34086. +static void bcm2708_spi_cleanup(struct spi_device *spi)
  34087. +{
  34088. + if (spi->controller_state) {
  34089. + kfree(spi->controller_state);
  34090. + spi->controller_state = NULL;
  34091. + }
  34092. +}
  34093. +
  34094. +static int bcm2708_spi_probe(struct platform_device *pdev)
  34095. +{
  34096. + struct resource *regs;
  34097. + int irq, err = -ENOMEM;
  34098. + struct clk *clk;
  34099. + struct spi_master *master;
  34100. + struct bcm2708_spi *bs;
  34101. +
  34102. + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  34103. + if (!regs) {
  34104. + dev_err(&pdev->dev, "could not get IO memory\n");
  34105. + return -ENXIO;
  34106. + }
  34107. +
  34108. + irq = platform_get_irq(pdev, 0);
  34109. + if (irq < 0) {
  34110. + dev_err(&pdev->dev, "could not get IRQ\n");
  34111. + return irq;
  34112. + }
  34113. +
  34114. + clk = clk_get(&pdev->dev, NULL);
  34115. + if (IS_ERR(clk)) {
  34116. + dev_err(&pdev->dev, "could not find clk: %ld\n", PTR_ERR(clk));
  34117. + return PTR_ERR(clk);
  34118. + }
  34119. +
  34120. + bcm2708_init_pinmode();
  34121. +
  34122. + master = spi_alloc_master(&pdev->dev, sizeof(*bs));
  34123. + if (!master) {
  34124. + dev_err(&pdev->dev, "spi_alloc_master() failed\n");
  34125. + goto out_clk_put;
  34126. + }
  34127. +
  34128. + /* the spi->mode bits understood by this driver: */
  34129. + master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_NO_CS;
  34130. +
  34131. + master->bus_num = pdev->id;
  34132. + master->num_chipselect = 3;
  34133. + master->setup = bcm2708_spi_setup;
  34134. + master->transfer = bcm2708_spi_transfer;
  34135. + master->cleanup = bcm2708_spi_cleanup;
  34136. + platform_set_drvdata(pdev, master);
  34137. +
  34138. + bs = spi_master_get_devdata(master);
  34139. +
  34140. + spin_lock_init(&bs->lock);
  34141. + INIT_LIST_HEAD(&bs->queue);
  34142. + init_completion(&bs->done);
  34143. + INIT_WORK(&bs->work, bcm2708_work);
  34144. +
  34145. + bs->base = ioremap(regs->start, resource_size(regs));
  34146. + if (!bs->base) {
  34147. + dev_err(&pdev->dev, "could not remap memory\n");
  34148. + goto out_master_put;
  34149. + }
  34150. +
  34151. + bs->workq = create_singlethread_workqueue(dev_name(&pdev->dev));
  34152. + if (!bs->workq) {
  34153. + dev_err(&pdev->dev, "could not create workqueue\n");
  34154. + goto out_iounmap;
  34155. + }
  34156. +
  34157. + bs->irq = irq;
  34158. + bs->clk = clk;
  34159. + bs->stopping = false;
  34160. +
  34161. + err = request_irq(irq, bcm2708_spi_interrupt, 0, dev_name(&pdev->dev),
  34162. + master);
  34163. + if (err) {
  34164. + dev_err(&pdev->dev, "could not request IRQ: %d\n", err);
  34165. + goto out_workqueue;
  34166. + }
  34167. +
  34168. + /* initialise the hardware */
  34169. + clk_enable(clk);
  34170. + bcm2708_wr(bs, SPI_CS, SPI_CS_REN | SPI_CS_CLEAR_RX | SPI_CS_CLEAR_TX);
  34171. +
  34172. + err = spi_register_master(master);
  34173. + if (err) {
  34174. + dev_err(&pdev->dev, "could not register SPI master: %d\n", err);
  34175. + goto out_free_irq;
  34176. + }
  34177. +
  34178. + dev_info(&pdev->dev, "SPI Controller at 0x%08lx (irq %d)\n",
  34179. + (unsigned long)regs->start, irq);
  34180. +
  34181. + return 0;
  34182. +
  34183. +out_free_irq:
  34184. + free_irq(bs->irq, master);
  34185. +out_workqueue:
  34186. + destroy_workqueue(bs->workq);
  34187. +out_iounmap:
  34188. + iounmap(bs->base);
  34189. +out_master_put:
  34190. + spi_master_put(master);
  34191. +out_clk_put:
  34192. + clk_put(clk);
  34193. + return err;
  34194. +}
  34195. +
  34196. +static int bcm2708_spi_remove(struct platform_device *pdev)
  34197. +{
  34198. + struct spi_master *master = platform_get_drvdata(pdev);
  34199. + struct bcm2708_spi *bs = spi_master_get_devdata(master);
  34200. +
  34201. + /* reset the hardware and block queue progress */
  34202. + spin_lock_irq(&bs->lock);
  34203. + bs->stopping = true;
  34204. + bcm2708_wr(bs, SPI_CS, SPI_CS_CLEAR_RX | SPI_CS_CLEAR_TX);
  34205. + spin_unlock_irq(&bs->lock);
  34206. +
  34207. + flush_work_sync(&bs->work);
  34208. +
  34209. + clk_disable(bs->clk);
  34210. + clk_put(bs->clk);
  34211. + free_irq(bs->irq, master);
  34212. + iounmap(bs->base);
  34213. +
  34214. + spi_unregister_master(master);
  34215. +
  34216. + return 0;
  34217. +}
  34218. +
  34219. +static struct platform_driver bcm2708_spi_driver = {
  34220. + .driver = {
  34221. + .name = DRV_NAME,
  34222. + .owner = THIS_MODULE,
  34223. + },
  34224. + .probe = bcm2708_spi_probe,
  34225. + .remove = bcm2708_spi_remove,
  34226. +};
  34227. +
  34228. +
  34229. +static int __init bcm2708_spi_init(void)
  34230. +{
  34231. + return platform_driver_probe(&bcm2708_spi_driver, bcm2708_spi_probe);
  34232. +}
  34233. +module_init(bcm2708_spi_init);
  34234. +
  34235. +static void __exit bcm2708_spi_exit(void)
  34236. +{
  34237. + platform_driver_unregister(&bcm2708_spi_driver);
  34238. +}
  34239. +module_exit(bcm2708_spi_exit);
  34240. +
  34241. +
  34242. +//module_platform_driver(bcm2708_spi_driver);
  34243. +
  34244. +MODULE_DESCRIPTION("SPI controller driver for Broadcom BCM2708");
  34245. +MODULE_AUTHOR("Chris Boot <bootc@bootc.net>");
  34246. +MODULE_LICENSE("GPL v2");
  34247. +MODULE_ALIAS("platform:" DRV_NAME);
  34248. diff -Nur linux-3.12.26.orig/drivers/staging/media/lirc/Kconfig linux-3.12.26/drivers/staging/media/lirc/Kconfig
  34249. --- linux-3.12.26.orig/drivers/staging/media/lirc/Kconfig 2014-07-30 18:02:44.000000000 +0200
  34250. +++ linux-3.12.26/drivers/staging/media/lirc/Kconfig 2014-08-06 16:50:14.713964035 +0200
  34251. @@ -38,6 +38,12 @@
  34252. help
  34253. Driver for Homebrew Parallel Port Receivers
  34254. +config LIRC_RPI
  34255. + tristate "Homebrew GPIO Port Receiver/Transmitter for the RaspberryPi"
  34256. + depends on LIRC
  34257. + help
  34258. + Driver for Homebrew GPIO Port Receiver/Transmitter for the RaspberryPi
  34259. +
  34260. config LIRC_SASEM
  34261. tristate "Sasem USB IR Remote"
  34262. depends on LIRC && USB
  34263. diff -Nur linux-3.12.26.orig/drivers/staging/media/lirc/lirc_rpi.c linux-3.12.26/drivers/staging/media/lirc/lirc_rpi.c
  34264. --- linux-3.12.26.orig/drivers/staging/media/lirc/lirc_rpi.c 1970-01-01 01:00:00.000000000 +0100
  34265. +++ linux-3.12.26/drivers/staging/media/lirc/lirc_rpi.c 2014-08-06 16:50:14.725964129 +0200
  34266. @@ -0,0 +1,693 @@
  34267. +/*
  34268. + * lirc_rpi.c
  34269. + *
  34270. + * lirc_rpi - Device driver that records pulse- and pause-lengths
  34271. + * (space-lengths) (just like the lirc_serial driver does)
  34272. + * between GPIO interrupt events on the Raspberry Pi.
  34273. + * Lots of code has been taken from the lirc_serial module,
  34274. + * so I would like say thanks to the authors.
  34275. + *
  34276. + * Copyright (C) 2012 Aron Robert Szabo <aron@reon.hu>,
  34277. + * Michael Bishop <cleverca22@gmail.com>
  34278. + * This program is free software; you can redistribute it and/or modify
  34279. + * it under the terms of the GNU General Public License as published by
  34280. + * the Free Software Foundation; either version 2 of the License, or
  34281. + * (at your option) any later version.
  34282. + *
  34283. + * This program is distributed in the hope that it will be useful,
  34284. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  34285. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  34286. + * GNU General Public License for more details.
  34287. + *
  34288. + * You should have received a copy of the GNU General Public License
  34289. + * along with this program; if not, write to the Free Software
  34290. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  34291. + */
  34292. +
  34293. +#include <linux/module.h>
  34294. +#include <linux/errno.h>
  34295. +#include <linux/interrupt.h>
  34296. +#include <linux/sched.h>
  34297. +#include <linux/kernel.h>
  34298. +#include <linux/time.h>
  34299. +#include <linux/string.h>
  34300. +#include <linux/delay.h>
  34301. +#include <linux/platform_device.h>
  34302. +#include <linux/irq.h>
  34303. +#include <linux/spinlock.h>
  34304. +#include <media/lirc.h>
  34305. +#include <media/lirc_dev.h>
  34306. +#include <linux/gpio.h>
  34307. +
  34308. +#define LIRC_DRIVER_NAME "lirc_rpi"
  34309. +#define RBUF_LEN 256
  34310. +#define LIRC_TRANSMITTER_LATENCY 256
  34311. +
  34312. +#ifndef MAX_UDELAY_MS
  34313. +#define MAX_UDELAY_US 5000
  34314. +#else
  34315. +#define MAX_UDELAY_US (MAX_UDELAY_MS*1000)
  34316. +#endif
  34317. +
  34318. +#define dprintk(fmt, args...) \
  34319. + do { \
  34320. + if (debug) \
  34321. + printk(KERN_DEBUG LIRC_DRIVER_NAME ": " \
  34322. + fmt, ## args); \
  34323. + } while (0)
  34324. +
  34325. +/* module parameters */
  34326. +
  34327. +/* set the default GPIO input pin */
  34328. +static int gpio_in_pin = 18;
  34329. +/* set the default GPIO output pin */
  34330. +static int gpio_out_pin = 17;
  34331. +/* enable debugging messages */
  34332. +static bool debug;
  34333. +/* -1 = auto, 0 = active high, 1 = active low */
  34334. +static int sense = -1;
  34335. +/* use softcarrier by default */
  34336. +static bool softcarrier = 1;
  34337. +/* 0 = do not invert output, 1 = invert output */
  34338. +static bool invert = 0;
  34339. +
  34340. +struct gpio_chip *gpiochip;
  34341. +struct irq_chip *irqchip;
  34342. +struct irq_data *irqdata;
  34343. +
  34344. +/* forward declarations */
  34345. +static long send_pulse(unsigned long length);
  34346. +static void send_space(long length);
  34347. +static void lirc_rpi_exit(void);
  34348. +
  34349. +int valid_gpio_pins[] = { 0, 1, 2, 3, 4, 7, 8, 9, 10, 11, 14, 15, 17, 18, 21,
  34350. + 22, 23, 24, 25 ,27, 28, 29, 30, 31 };
  34351. +
  34352. +static struct platform_device *lirc_rpi_dev;
  34353. +static struct timeval lasttv = { 0, 0 };
  34354. +static struct lirc_buffer rbuf;
  34355. +static spinlock_t lock;
  34356. +
  34357. +/* initialized/set in init_timing_params() */
  34358. +static unsigned int freq = 38000;
  34359. +static unsigned int duty_cycle = 50;
  34360. +static unsigned long period;
  34361. +static unsigned long pulse_width;
  34362. +static unsigned long space_width;
  34363. +
  34364. +static void safe_udelay(unsigned long usecs)
  34365. +{
  34366. + while (usecs > MAX_UDELAY_US) {
  34367. + udelay(MAX_UDELAY_US);
  34368. + usecs -= MAX_UDELAY_US;
  34369. + }
  34370. + udelay(usecs);
  34371. +}
  34372. +
  34373. +static int init_timing_params(unsigned int new_duty_cycle,
  34374. + unsigned int new_freq)
  34375. +{
  34376. + /*
  34377. + * period, pulse/space width are kept with 8 binary places -
  34378. + * IE multiplied by 256.
  34379. + */
  34380. + if (256 * 1000000L / new_freq * new_duty_cycle / 100 <=
  34381. + LIRC_TRANSMITTER_LATENCY)
  34382. + return -EINVAL;
  34383. + if (256 * 1000000L / new_freq * (100 - new_duty_cycle) / 100 <=
  34384. + LIRC_TRANSMITTER_LATENCY)
  34385. + return -EINVAL;
  34386. + duty_cycle = new_duty_cycle;
  34387. + freq = new_freq;
  34388. + period = 256 * 1000000L / freq;
  34389. + pulse_width = period * duty_cycle / 100;
  34390. + space_width = period - pulse_width;
  34391. + dprintk("in init_timing_params, freq=%d pulse=%ld, "
  34392. + "space=%ld\n", freq, pulse_width, space_width);
  34393. + return 0;
  34394. +}
  34395. +
  34396. +static long send_pulse_softcarrier(unsigned long length)
  34397. +{
  34398. + int flag;
  34399. + unsigned long actual, target, d;
  34400. +
  34401. + length <<= 8;
  34402. +
  34403. + actual = 0; target = 0; flag = 0;
  34404. + while (actual < length) {
  34405. + if (flag) {
  34406. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  34407. + target += space_width;
  34408. + } else {
  34409. + gpiochip->set(gpiochip, gpio_out_pin, !invert);
  34410. + target += pulse_width;
  34411. + }
  34412. + d = (target - actual -
  34413. + LIRC_TRANSMITTER_LATENCY + 128) >> 8;
  34414. + /*
  34415. + * Note - we've checked in ioctl that the pulse/space
  34416. + * widths are big enough so that d is > 0
  34417. + */
  34418. + udelay(d);
  34419. + actual += (d << 8) + LIRC_TRANSMITTER_LATENCY;
  34420. + flag = !flag;
  34421. + }
  34422. + return (actual-length) >> 8;
  34423. +}
  34424. +
  34425. +static long send_pulse(unsigned long length)
  34426. +{
  34427. + if (length <= 0)
  34428. + return 0;
  34429. +
  34430. + if (softcarrier) {
  34431. + return send_pulse_softcarrier(length);
  34432. + } else {
  34433. + gpiochip->set(gpiochip, gpio_out_pin, !invert);
  34434. + safe_udelay(length);
  34435. + return 0;
  34436. + }
  34437. +}
  34438. +
  34439. +static void send_space(long length)
  34440. +{
  34441. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  34442. + if (length <= 0)
  34443. + return;
  34444. + safe_udelay(length);
  34445. +}
  34446. +
  34447. +static void rbwrite(int l)
  34448. +{
  34449. + if (lirc_buffer_full(&rbuf)) {
  34450. + /* no new signals will be accepted */
  34451. + dprintk("Buffer overrun\n");
  34452. + return;
  34453. + }
  34454. + lirc_buffer_write(&rbuf, (void *)&l);
  34455. +}
  34456. +
  34457. +static void frbwrite(int l)
  34458. +{
  34459. + /* simple noise filter */
  34460. + static int pulse, space;
  34461. + static unsigned int ptr;
  34462. +
  34463. + if (ptr > 0 && (l & PULSE_BIT)) {
  34464. + pulse += l & PULSE_MASK;
  34465. + if (pulse > 250) {
  34466. + rbwrite(space);
  34467. + rbwrite(pulse | PULSE_BIT);
  34468. + ptr = 0;
  34469. + pulse = 0;
  34470. + }
  34471. + return;
  34472. + }
  34473. + if (!(l & PULSE_BIT)) {
  34474. + if (ptr == 0) {
  34475. + if (l > 20000) {
  34476. + space = l;
  34477. + ptr++;
  34478. + return;
  34479. + }
  34480. + } else {
  34481. + if (l > 20000) {
  34482. + space += pulse;
  34483. + if (space > PULSE_MASK)
  34484. + space = PULSE_MASK;
  34485. + space += l;
  34486. + if (space > PULSE_MASK)
  34487. + space = PULSE_MASK;
  34488. + pulse = 0;
  34489. + return;
  34490. + }
  34491. + rbwrite(space);
  34492. + rbwrite(pulse | PULSE_BIT);
  34493. + ptr = 0;
  34494. + pulse = 0;
  34495. + }
  34496. + }
  34497. + rbwrite(l);
  34498. +}
  34499. +
  34500. +static irqreturn_t irq_handler(int i, void *blah, struct pt_regs *regs)
  34501. +{
  34502. + struct timeval tv;
  34503. + long deltv;
  34504. + int data;
  34505. + int signal;
  34506. +
  34507. + /* use the GPIO signal level */
  34508. + signal = gpiochip->get(gpiochip, gpio_in_pin);
  34509. +
  34510. + /* unmask the irq */
  34511. + irqchip->irq_unmask(irqdata);
  34512. +
  34513. + if (sense != -1) {
  34514. + /* get current time */
  34515. + do_gettimeofday(&tv);
  34516. +
  34517. + /* calc time since last interrupt in microseconds */
  34518. + deltv = tv.tv_sec-lasttv.tv_sec;
  34519. + if (tv.tv_sec < lasttv.tv_sec ||
  34520. + (tv.tv_sec == lasttv.tv_sec &&
  34521. + tv.tv_usec < lasttv.tv_usec)) {
  34522. + printk(KERN_WARNING LIRC_DRIVER_NAME
  34523. + ": AIEEEE: your clock just jumped backwards\n");
  34524. + printk(KERN_WARNING LIRC_DRIVER_NAME
  34525. + ": %d %d %lx %lx %lx %lx\n", signal, sense,
  34526. + tv.tv_sec, lasttv.tv_sec,
  34527. + tv.tv_usec, lasttv.tv_usec);
  34528. + data = PULSE_MASK;
  34529. + } else if (deltv > 15) {
  34530. + data = PULSE_MASK; /* really long time */
  34531. + if (!(signal^sense)) {
  34532. + /* sanity check */
  34533. + printk(KERN_WARNING LIRC_DRIVER_NAME
  34534. + ": AIEEEE: %d %d %lx %lx %lx %lx\n",
  34535. + signal, sense, tv.tv_sec, lasttv.tv_sec,
  34536. + tv.tv_usec, lasttv.tv_usec);
  34537. + /*
  34538. + * detecting pulse while this
  34539. + * MUST be a space!
  34540. + */
  34541. + sense = sense ? 0 : 1;
  34542. + }
  34543. + } else {
  34544. + data = (int) (deltv*1000000 +
  34545. + (tv.tv_usec - lasttv.tv_usec));
  34546. + }
  34547. + frbwrite(signal^sense ? data : (data|PULSE_BIT));
  34548. + lasttv = tv;
  34549. + wake_up_interruptible(&rbuf.wait_poll);
  34550. + }
  34551. +
  34552. + return IRQ_HANDLED;
  34553. +}
  34554. +
  34555. +static int is_right_chip(struct gpio_chip *chip, void *data)
  34556. +{
  34557. + dprintk("is_right_chip %s %d\n", chip->label, strcmp(data, chip->label));
  34558. +
  34559. + if (strcmp(data, chip->label) == 0)
  34560. + return 1;
  34561. + return 0;
  34562. +}
  34563. +
  34564. +static int init_port(void)
  34565. +{
  34566. + int i, nlow, nhigh, ret, irq;
  34567. +
  34568. + gpiochip = gpiochip_find("bcm2708_gpio", is_right_chip);
  34569. +
  34570. + if (!gpiochip)
  34571. + return -ENODEV;
  34572. +
  34573. + if (gpio_request(gpio_out_pin, LIRC_DRIVER_NAME " ir/out")) {
  34574. + printk(KERN_ALERT LIRC_DRIVER_NAME
  34575. + ": cant claim gpio pin %d\n", gpio_out_pin);
  34576. + ret = -ENODEV;
  34577. + goto exit_init_port;
  34578. + }
  34579. +
  34580. + if (gpio_request(gpio_in_pin, LIRC_DRIVER_NAME " ir/in")) {
  34581. + printk(KERN_ALERT LIRC_DRIVER_NAME
  34582. + ": cant claim gpio pin %d\n", gpio_in_pin);
  34583. + ret = -ENODEV;
  34584. + goto exit_gpio_free_out_pin;
  34585. + }
  34586. +
  34587. + gpiochip->direction_input(gpiochip, gpio_in_pin);
  34588. + gpiochip->direction_output(gpiochip, gpio_out_pin, 1);
  34589. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  34590. +
  34591. + irq = gpiochip->to_irq(gpiochip, gpio_in_pin);
  34592. + dprintk("to_irq %d\n", irq);
  34593. + irqdata = irq_get_irq_data(irq);
  34594. +
  34595. + if (irqdata && irqdata->chip) {
  34596. + irqchip = irqdata->chip;
  34597. + } else {
  34598. + ret = -ENODEV;
  34599. + goto exit_gpio_free_in_pin;
  34600. + }
  34601. +
  34602. + /* if pin is high, then this must be an active low receiver. */
  34603. + if (sense == -1) {
  34604. + /* wait 1/2 sec for the power supply */
  34605. + msleep(500);
  34606. +
  34607. + /*
  34608. + * probe 9 times every 0.04s, collect "votes" for
  34609. + * active high/low
  34610. + */
  34611. + nlow = 0;
  34612. + nhigh = 0;
  34613. + for (i = 0; i < 9; i++) {
  34614. + if (gpiochip->get(gpiochip, gpio_in_pin))
  34615. + nlow++;
  34616. + else
  34617. + nhigh++;
  34618. + msleep(40);
  34619. + }
  34620. + sense = (nlow >= nhigh ? 1 : 0);
  34621. + printk(KERN_INFO LIRC_DRIVER_NAME
  34622. + ": auto-detected active %s receiver on GPIO pin %d\n",
  34623. + sense ? "low" : "high", gpio_in_pin);
  34624. + } else {
  34625. + printk(KERN_INFO LIRC_DRIVER_NAME
  34626. + ": manually using active %s receiver on GPIO pin %d\n",
  34627. + sense ? "low" : "high", gpio_in_pin);
  34628. + }
  34629. +
  34630. + return 0;
  34631. +
  34632. + exit_gpio_free_in_pin:
  34633. + gpio_free(gpio_in_pin);
  34634. +
  34635. + exit_gpio_free_out_pin:
  34636. + gpio_free(gpio_out_pin);
  34637. +
  34638. + exit_init_port:
  34639. + return ret;
  34640. +}
  34641. +
  34642. +// called when the character device is opened
  34643. +static int set_use_inc(void *data)
  34644. +{
  34645. + int result;
  34646. + unsigned long flags;
  34647. +
  34648. + /* initialize timestamp */
  34649. + do_gettimeofday(&lasttv);
  34650. +
  34651. + result = request_irq(gpiochip->to_irq(gpiochip, gpio_in_pin),
  34652. + (irq_handler_t) irq_handler, 0,
  34653. + LIRC_DRIVER_NAME, (void*) 0);
  34654. +
  34655. + switch (result) {
  34656. + case -EBUSY:
  34657. + printk(KERN_ERR LIRC_DRIVER_NAME
  34658. + ": IRQ %d is busy\n",
  34659. + gpiochip->to_irq(gpiochip, gpio_in_pin));
  34660. + return -EBUSY;
  34661. + case -EINVAL:
  34662. + printk(KERN_ERR LIRC_DRIVER_NAME
  34663. + ": Bad irq number or handler\n");
  34664. + return -EINVAL;
  34665. + default:
  34666. + dprintk("Interrupt %d obtained\n",
  34667. + gpiochip->to_irq(gpiochip, gpio_in_pin));
  34668. + break;
  34669. + };
  34670. +
  34671. + /* initialize pulse/space widths */
  34672. + init_timing_params(duty_cycle, freq);
  34673. +
  34674. + spin_lock_irqsave(&lock, flags);
  34675. +
  34676. + /* GPIO Pin Falling/Rising Edge Detect Enable */
  34677. + irqchip->irq_set_type(irqdata,
  34678. + IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING);
  34679. +
  34680. + /* unmask the irq */
  34681. + irqchip->irq_unmask(irqdata);
  34682. +
  34683. + spin_unlock_irqrestore(&lock, flags);
  34684. +
  34685. + return 0;
  34686. +}
  34687. +
  34688. +static void set_use_dec(void *data)
  34689. +{
  34690. + unsigned long flags;
  34691. +
  34692. + spin_lock_irqsave(&lock, flags);
  34693. +
  34694. + /* GPIO Pin Falling/Rising Edge Detect Disable */
  34695. + irqchip->irq_set_type(irqdata, 0);
  34696. + irqchip->irq_mask(irqdata);
  34697. +
  34698. + spin_unlock_irqrestore(&lock, flags);
  34699. +
  34700. + free_irq(gpiochip->to_irq(gpiochip, gpio_in_pin), (void *) 0);
  34701. +
  34702. + dprintk(KERN_INFO LIRC_DRIVER_NAME
  34703. + ": freed IRQ %d\n", gpiochip->to_irq(gpiochip, gpio_in_pin));
  34704. +}
  34705. +
  34706. +static ssize_t lirc_write(struct file *file, const char *buf,
  34707. + size_t n, loff_t *ppos)
  34708. +{
  34709. + int i, count;
  34710. + unsigned long flags;
  34711. + long delta = 0;
  34712. + int *wbuf;
  34713. +
  34714. + count = n / sizeof(int);
  34715. + if (n % sizeof(int) || count % 2 == 0)
  34716. + return -EINVAL;
  34717. + wbuf = memdup_user(buf, n);
  34718. + if (IS_ERR(wbuf))
  34719. + return PTR_ERR(wbuf);
  34720. + spin_lock_irqsave(&lock, flags);
  34721. +
  34722. + for (i = 0; i < count; i++) {
  34723. + if (i%2)
  34724. + send_space(wbuf[i] - delta);
  34725. + else
  34726. + delta = send_pulse(wbuf[i]);
  34727. + }
  34728. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  34729. +
  34730. + spin_unlock_irqrestore(&lock, flags);
  34731. + kfree(wbuf);
  34732. + return n;
  34733. +}
  34734. +
  34735. +static long lirc_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
  34736. +{
  34737. + int result;
  34738. + __u32 value;
  34739. +
  34740. + switch (cmd) {
  34741. + case LIRC_GET_SEND_MODE:
  34742. + return -ENOIOCTLCMD;
  34743. + break;
  34744. +
  34745. + case LIRC_SET_SEND_MODE:
  34746. + result = get_user(value, (__u32 *) arg);
  34747. + if (result)
  34748. + return result;
  34749. + /* only LIRC_MODE_PULSE supported */
  34750. + if (value != LIRC_MODE_PULSE)
  34751. + return -ENOSYS;
  34752. + break;
  34753. +
  34754. + case LIRC_GET_LENGTH:
  34755. + return -ENOSYS;
  34756. + break;
  34757. +
  34758. + case LIRC_SET_SEND_DUTY_CYCLE:
  34759. + dprintk("SET_SEND_DUTY_CYCLE\n");
  34760. + result = get_user(value, (__u32 *) arg);
  34761. + if (result)
  34762. + return result;
  34763. + if (value <= 0 || value > 100)
  34764. + return -EINVAL;
  34765. + return init_timing_params(value, freq);
  34766. + break;
  34767. +
  34768. + case LIRC_SET_SEND_CARRIER:
  34769. + dprintk("SET_SEND_CARRIER\n");
  34770. + result = get_user(value, (__u32 *) arg);
  34771. + if (result)
  34772. + return result;
  34773. + if (value > 500000 || value < 20000)
  34774. + return -EINVAL;
  34775. + return init_timing_params(duty_cycle, value);
  34776. + break;
  34777. +
  34778. + default:
  34779. + return lirc_dev_fop_ioctl(filep, cmd, arg);
  34780. + }
  34781. + return 0;
  34782. +}
  34783. +
  34784. +static const struct file_operations lirc_fops = {
  34785. + .owner = THIS_MODULE,
  34786. + .write = lirc_write,
  34787. + .unlocked_ioctl = lirc_ioctl,
  34788. + .read = lirc_dev_fop_read,
  34789. + .poll = lirc_dev_fop_poll,
  34790. + .open = lirc_dev_fop_open,
  34791. + .release = lirc_dev_fop_close,
  34792. + .llseek = no_llseek,
  34793. +};
  34794. +
  34795. +static struct lirc_driver driver = {
  34796. + .name = LIRC_DRIVER_NAME,
  34797. + .minor = -1,
  34798. + .code_length = 1,
  34799. + .sample_rate = 0,
  34800. + .data = NULL,
  34801. + .add_to_buf = NULL,
  34802. + .rbuf = &rbuf,
  34803. + .set_use_inc = set_use_inc,
  34804. + .set_use_dec = set_use_dec,
  34805. + .fops = &lirc_fops,
  34806. + .dev = NULL,
  34807. + .owner = THIS_MODULE,
  34808. +};
  34809. +
  34810. +static struct platform_driver lirc_rpi_driver = {
  34811. + .driver = {
  34812. + .name = LIRC_DRIVER_NAME,
  34813. + .owner = THIS_MODULE,
  34814. + },
  34815. +};
  34816. +
  34817. +static int __init lirc_rpi_init(void)
  34818. +{
  34819. + int result;
  34820. +
  34821. + /* Init read buffer. */
  34822. + result = lirc_buffer_init(&rbuf, sizeof(int), RBUF_LEN);
  34823. + if (result < 0)
  34824. + return -ENOMEM;
  34825. +
  34826. + result = platform_driver_register(&lirc_rpi_driver);
  34827. + if (result) {
  34828. + printk(KERN_ERR LIRC_DRIVER_NAME
  34829. + ": lirc register returned %d\n", result);
  34830. + goto exit_buffer_free;
  34831. + }
  34832. +
  34833. + lirc_rpi_dev = platform_device_alloc(LIRC_DRIVER_NAME, 0);
  34834. + if (!lirc_rpi_dev) {
  34835. + result = -ENOMEM;
  34836. + goto exit_driver_unregister;
  34837. + }
  34838. +
  34839. + result = platform_device_add(lirc_rpi_dev);
  34840. + if (result)
  34841. + goto exit_device_put;
  34842. +
  34843. + return 0;
  34844. +
  34845. + exit_device_put:
  34846. + platform_device_put(lirc_rpi_dev);
  34847. +
  34848. + exit_driver_unregister:
  34849. + platform_driver_unregister(&lirc_rpi_driver);
  34850. +
  34851. + exit_buffer_free:
  34852. + lirc_buffer_free(&rbuf);
  34853. +
  34854. + return result;
  34855. +}
  34856. +
  34857. +static void lirc_rpi_exit(void)
  34858. +{
  34859. + platform_device_unregister(lirc_rpi_dev);
  34860. + platform_driver_unregister(&lirc_rpi_driver);
  34861. + lirc_buffer_free(&rbuf);
  34862. +}
  34863. +
  34864. +static int __init lirc_rpi_init_module(void)
  34865. +{
  34866. + int result, i;
  34867. +
  34868. + result = lirc_rpi_init();
  34869. + if (result)
  34870. + return result;
  34871. +
  34872. + /* check if the module received valid gpio pin numbers */
  34873. + result = 0;
  34874. + if (gpio_in_pin != gpio_out_pin) {
  34875. + for(i = 0; (i < ARRAY_SIZE(valid_gpio_pins)) && (result != 2); i++) {
  34876. + if (gpio_in_pin == valid_gpio_pins[i] ||
  34877. + gpio_out_pin == valid_gpio_pins[i]) {
  34878. + result++;
  34879. + }
  34880. + }
  34881. + }
  34882. +
  34883. + if (result != 2) {
  34884. + result = -EINVAL;
  34885. + printk(KERN_ERR LIRC_DRIVER_NAME
  34886. + ": invalid GPIO pin(s) specified!\n");
  34887. + goto exit_rpi;
  34888. + }
  34889. +
  34890. + result = init_port();
  34891. + if (result < 0)
  34892. + goto exit_rpi;
  34893. +
  34894. + driver.features = LIRC_CAN_SET_SEND_DUTY_CYCLE |
  34895. + LIRC_CAN_SET_SEND_CARRIER |
  34896. + LIRC_CAN_SEND_PULSE |
  34897. + LIRC_CAN_REC_MODE2;
  34898. +
  34899. + driver.dev = &lirc_rpi_dev->dev;
  34900. + driver.minor = lirc_register_driver(&driver);
  34901. +
  34902. + if (driver.minor < 0) {
  34903. + printk(KERN_ERR LIRC_DRIVER_NAME
  34904. + ": device registration failed with %d\n", result);
  34905. + result = -EIO;
  34906. + goto exit_rpi;
  34907. + }
  34908. +
  34909. + printk(KERN_INFO LIRC_DRIVER_NAME ": driver registered!\n");
  34910. +
  34911. + return 0;
  34912. +
  34913. + exit_rpi:
  34914. + lirc_rpi_exit();
  34915. +
  34916. + return result;
  34917. +}
  34918. +
  34919. +static void __exit lirc_rpi_exit_module(void)
  34920. +{
  34921. + gpio_free(gpio_out_pin);
  34922. + gpio_free(gpio_in_pin);
  34923. +
  34924. + lirc_rpi_exit();
  34925. +
  34926. + lirc_unregister_driver(driver.minor);
  34927. + printk(KERN_INFO LIRC_DRIVER_NAME ": cleaned up module\n");
  34928. +}
  34929. +
  34930. +module_init(lirc_rpi_init_module);
  34931. +module_exit(lirc_rpi_exit_module);
  34932. +
  34933. +MODULE_DESCRIPTION("Infra-red receiver and blaster driver for Raspberry Pi GPIO.");
  34934. +MODULE_AUTHOR("Aron Robert Szabo <aron@reon.hu>");
  34935. +MODULE_AUTHOR("Michael Bishop <cleverca22@gmail.com>");
  34936. +MODULE_LICENSE("GPL");
  34937. +
  34938. +module_param(gpio_out_pin, int, S_IRUGO);
  34939. +MODULE_PARM_DESC(gpio_out_pin, "GPIO output/transmitter pin number of the BCM"
  34940. + " processor. Valid pin numbers are: 0, 1, 4, 8, 7, 9, 10, 11,"
  34941. + " 14, 15, 17, 18, 21, 22, 23, 24, 25, default 17");
  34942. +
  34943. +module_param(gpio_in_pin, int, S_IRUGO);
  34944. +MODULE_PARM_DESC(gpio_in_pin, "GPIO input pin number of the BCM processor."
  34945. + " Valid pin numbers are: 0, 1, 4, 8, 7, 9, 10, 11, 14, 15,"
  34946. + " 17, 18, 21, 22, 23, 24, 25, default 18");
  34947. +
  34948. +module_param(sense, int, S_IRUGO);
  34949. +MODULE_PARM_DESC(sense, "Override autodetection of IR receiver circuit"
  34950. + " (0 = active high, 1 = active low )");
  34951. +
  34952. +module_param(softcarrier, bool, S_IRUGO);
  34953. +MODULE_PARM_DESC(softcarrier, "Software carrier (0 = off, 1 = on, default on)");
  34954. +
  34955. +module_param(invert, bool, S_IRUGO);
  34956. +MODULE_PARM_DESC(invert, "Invert output (0 = off, 1 = on, default off");
  34957. +
  34958. +module_param(debug, bool, S_IRUGO | S_IWUSR);
  34959. +MODULE_PARM_DESC(debug, "Enable debugging messages");
  34960. diff -Nur linux-3.12.26.orig/drivers/staging/media/lirc/Makefile linux-3.12.26/drivers/staging/media/lirc/Makefile
  34961. --- linux-3.12.26.orig/drivers/staging/media/lirc/Makefile 2014-07-30 18:02:44.000000000 +0200
  34962. +++ linux-3.12.26/drivers/staging/media/lirc/Makefile 2014-08-06 16:50:14.729964161 +0200
  34963. @@ -7,6 +7,7 @@
  34964. obj-$(CONFIG_LIRC_IGORPLUGUSB) += lirc_igorplugusb.o
  34965. obj-$(CONFIG_LIRC_IMON) += lirc_imon.o
  34966. obj-$(CONFIG_LIRC_PARALLEL) += lirc_parallel.o
  34967. +obj-$(CONFIG_LIRC_RPI) += lirc_rpi.o
  34968. obj-$(CONFIG_LIRC_SASEM) += lirc_sasem.o
  34969. obj-$(CONFIG_LIRC_SERIAL) += lirc_serial.o
  34970. obj-$(CONFIG_LIRC_SIR) += lirc_sir.o
  34971. diff -Nur linux-3.12.26.orig/drivers/thermal/bcm2835-thermal.c linux-3.12.26/drivers/thermal/bcm2835-thermal.c
  34972. --- linux-3.12.26.orig/drivers/thermal/bcm2835-thermal.c 1970-01-01 01:00:00.000000000 +0100
  34973. +++ linux-3.12.26/drivers/thermal/bcm2835-thermal.c 2014-08-06 16:50:14.729964161 +0200
  34974. @@ -0,0 +1,184 @@
  34975. +/*****************************************************************************
  34976. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  34977. +*
  34978. +* Unless you and Broadcom execute a separate written software license
  34979. +* agreement governing use of this software, this software is licensed to you
  34980. +* under the terms of the GNU General Public License version 2, available at
  34981. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  34982. +*
  34983. +* Notwithstanding the above, under no circumstances may you combine this
  34984. +* software in any way with any other Broadcom software provided under a
  34985. +* license other than the GPL, without Broadcom's express prior written
  34986. +* consent.
  34987. +*****************************************************************************/
  34988. +
  34989. +#include <linux/kernel.h>
  34990. +#include <linux/module.h>
  34991. +#include <linux/init.h>
  34992. +#include <linux/platform_device.h>
  34993. +#include <linux/slab.h>
  34994. +#include <linux/sysfs.h>
  34995. +#include <mach/vcio.h>
  34996. +#include <linux/thermal.h>
  34997. +
  34998. +
  34999. +/* --- DEFINITIONS --- */
  35000. +#define MODULE_NAME "bcm2835_thermal"
  35001. +
  35002. +/*#define THERMAL_DEBUG_ENABLE*/
  35003. +
  35004. +#ifdef THERMAL_DEBUG_ENABLE
  35005. +#define print_debug(fmt,...) printk(KERN_INFO "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  35006. +#else
  35007. +#define print_debug(fmt,...)
  35008. +#endif
  35009. +#define print_err(fmt,...) printk(KERN_ERR "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__,__LINE__, ##__VA_ARGS__)
  35010. +
  35011. +#define VC_TAG_GET_TEMP 0x00030006
  35012. +#define VC_TAG_GET_MAX_TEMP 0x0003000A
  35013. +
  35014. +typedef enum {
  35015. + TEMP,
  35016. + MAX_TEMP,
  35017. +} temp_type;
  35018. +
  35019. +/* --- STRUCTS --- */
  35020. +/* tag part of the message */
  35021. +struct vc_msg_tag {
  35022. + uint32_t tag_id; /* the tag ID for the temperature */
  35023. + uint32_t buffer_size; /* size of the buffer (should be 8) */
  35024. + uint32_t request_code; /* identifies message as a request (should be 0) */
  35025. + uint32_t id; /* extra ID field (should be 0) */
  35026. + uint32_t val; /* returned value of the temperature */
  35027. +};
  35028. +
  35029. +/* message structure to be sent to videocore */
  35030. +struct vc_msg {
  35031. + uint32_t msg_size; /* simply, sizeof(struct vc_msg) */
  35032. + uint32_t request_code; /* holds various information like the success and number of bytes returned (refer to mailboxes wiki) */
  35033. + struct vc_msg_tag tag; /* the tag structure above to make */
  35034. + uint32_t end_tag; /* an end identifier, should be set to NULL */
  35035. +};
  35036. +
  35037. +struct bcm2835_thermal_data {
  35038. + struct thermal_zone_device *thermal_dev;
  35039. + struct vc_msg msg;
  35040. +};
  35041. +
  35042. +/* --- GLOBALS --- */
  35043. +static struct bcm2835_thermal_data bcm2835_data;
  35044. +
  35045. +/* Thermal Device Operations */
  35046. +static struct thermal_zone_device_ops ops;
  35047. +
  35048. +/* --- FUNCTIONS --- */
  35049. +
  35050. +static int bcm2835_get_temp_or_max(struct thermal_zone_device *thermal_dev, unsigned long *temp, unsigned tag_id)
  35051. +{
  35052. + int result = -1, retry = 3;
  35053. + print_debug("IN");
  35054. +
  35055. + *temp = 0;
  35056. + while (result != 0 && retry-- > 0) {
  35057. + /* wipe all previous message data */
  35058. + memset(&bcm2835_data.msg, 0, sizeof bcm2835_data.msg);
  35059. +
  35060. + /* prepare message */
  35061. + bcm2835_data.msg.msg_size = sizeof bcm2835_data.msg;
  35062. + bcm2835_data.msg.tag.buffer_size = 8;
  35063. + bcm2835_data.msg.tag.tag_id = tag_id;
  35064. +
  35065. + /* send the message */
  35066. + result = bcm_mailbox_property(&bcm2835_data.msg, sizeof bcm2835_data.msg);
  35067. + 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);
  35068. + if (!(bcm2835_data.msg.request_code & 0x80000000))
  35069. + result = -1;
  35070. + }
  35071. +
  35072. + /* check if it was all ok and return the rate in milli degrees C */
  35073. + if (result == 0)
  35074. + *temp = (uint)bcm2835_data.msg.tag.val;
  35075. + else
  35076. + print_err("Failed to get temperature! (%x:%d)\n", tag_id, result);
  35077. + print_debug("OUT");
  35078. + return result;
  35079. +}
  35080. +
  35081. +static int bcm2835_get_temp(struct thermal_zone_device *thermal_dev, unsigned long *temp)
  35082. +{
  35083. + return bcm2835_get_temp_or_max(thermal_dev, temp, VC_TAG_GET_TEMP);
  35084. +}
  35085. +
  35086. +static int bcm2835_get_max_temp(struct thermal_zone_device *thermal_dev, int trip_num, unsigned long *temp)
  35087. +{
  35088. + return bcm2835_get_temp_or_max(thermal_dev, temp, VC_TAG_GET_MAX_TEMP);
  35089. +}
  35090. +
  35091. +static int bcm2835_get_trip_type(struct thermal_zone_device * thermal_dev, int trip_num, enum thermal_trip_type *trip_type)
  35092. +{
  35093. + *trip_type = THERMAL_TRIP_HOT;
  35094. + return 0;
  35095. +}
  35096. +
  35097. +
  35098. +static int bcm2835_get_mode(struct thermal_zone_device *thermal_dev, enum thermal_device_mode *dev_mode)
  35099. +{
  35100. + *dev_mode = THERMAL_DEVICE_ENABLED;
  35101. + return 0;
  35102. +}
  35103. +
  35104. +
  35105. +static int bcm2835_thermal_probe(struct platform_device *pdev)
  35106. +{
  35107. + print_debug("IN");
  35108. + print_debug("THERMAL Driver has been probed!");
  35109. +
  35110. + /* check that the device isn't null!*/
  35111. + if(pdev == NULL)
  35112. + {
  35113. + print_debug("Platform device is empty!");
  35114. + return -ENODEV;
  35115. + }
  35116. +
  35117. + if(!(bcm2835_data.thermal_dev = thermal_zone_device_register("bcm2835_thermal", 1, 0, NULL, &ops, NULL, 0, 0)))
  35118. + {
  35119. + print_debug("Unable to register the thermal device!");
  35120. + return -EFAULT;
  35121. + }
  35122. + return 0;
  35123. +}
  35124. +
  35125. +
  35126. +static int bcm2835_thermal_remove(struct platform_device *pdev)
  35127. +{
  35128. + print_debug("IN");
  35129. +
  35130. + thermal_zone_device_unregister(bcm2835_data.thermal_dev);
  35131. +
  35132. + print_debug("OUT");
  35133. +
  35134. + return 0;
  35135. +}
  35136. +
  35137. +static struct thermal_zone_device_ops ops = {
  35138. + .get_temp = bcm2835_get_temp,
  35139. + .get_trip_temp = bcm2835_get_max_temp,
  35140. + .get_trip_type = bcm2835_get_trip_type,
  35141. + .get_mode = bcm2835_get_mode,
  35142. +};
  35143. +
  35144. +/* Thermal Driver */
  35145. +static struct platform_driver bcm2835_thermal_driver = {
  35146. + .probe = bcm2835_thermal_probe,
  35147. + .remove = bcm2835_thermal_remove,
  35148. + .driver = {
  35149. + .name = "bcm2835_thermal",
  35150. + .owner = THIS_MODULE,
  35151. + },
  35152. +};
  35153. +
  35154. +MODULE_LICENSE("GPL");
  35155. +MODULE_AUTHOR("Dorian Peake");
  35156. +MODULE_DESCRIPTION("Thermal driver for bcm2835 chip");
  35157. +
  35158. +module_platform_driver(bcm2835_thermal_driver);
  35159. diff -Nur linux-3.12.26.orig/drivers/thermal/Kconfig linux-3.12.26/drivers/thermal/Kconfig
  35160. --- linux-3.12.26.orig/drivers/thermal/Kconfig 2014-07-30 18:02:44.000000000 +0200
  35161. +++ linux-3.12.26/drivers/thermal/Kconfig 2014-08-06 16:50:14.729964161 +0200
  35162. @@ -181,6 +181,12 @@
  35163. enforce idle time which results in more package C-state residency. The
  35164. user interface is exposed via generic thermal framework.
  35165. +config THERMAL_BCM2835
  35166. + tristate "BCM2835 Thermal Driver"
  35167. + help
  35168. + This will enable temperature monitoring for the Broadcom BCM2835
  35169. + chip. If built as a module, it will be called 'bcm2835-thermal'.
  35170. +
  35171. config X86_PKG_TEMP_THERMAL
  35172. tristate "X86 package temperature thermal driver"
  35173. depends on X86_THERMAL_VECTOR
  35174. diff -Nur linux-3.12.26.orig/drivers/thermal/Makefile linux-3.12.26/drivers/thermal/Makefile
  35175. --- linux-3.12.26.orig/drivers/thermal/Makefile 2014-07-30 18:02:44.000000000 +0200
  35176. +++ linux-3.12.26/drivers/thermal/Makefile 2014-08-06 16:50:14.729964161 +0200
  35177. @@ -27,5 +27,6 @@
  35178. obj-$(CONFIG_IMX_THERMAL) += imx_thermal.o
  35179. obj-$(CONFIG_DB8500_CPUFREQ_COOLING) += db8500_cpufreq_cooling.o
  35180. obj-$(CONFIG_INTEL_POWERCLAMP) += intel_powerclamp.o
  35181. +obj-$(CONFIG_THERMAL_BCM2835) += bcm2835-thermal.o
  35182. obj-$(CONFIG_X86_PKG_TEMP_THERMAL) += x86_pkg_temp_thermal.o
  35183. obj-$(CONFIG_TI_SOC_THERMAL) += ti-soc-thermal/
  35184. diff -Nur linux-3.12.26.orig/drivers/tty/serial/amba-pl011.c linux-3.12.26/drivers/tty/serial/amba-pl011.c
  35185. --- linux-3.12.26.orig/drivers/tty/serial/amba-pl011.c 2014-07-30 18:02:44.000000000 +0200
  35186. +++ linux-3.12.26/drivers/tty/serial/amba-pl011.c 2014-08-06 16:50:14.729964161 +0200
  35187. @@ -84,7 +84,7 @@
  35188. static unsigned int get_fifosize_arm(struct amba_device *dev)
  35189. {
  35190. - return amba_rev(dev) < 3 ? 16 : 32;
  35191. + return 16; //TODO: fix: amba_rev(dev) < 3 ? 16 : 32;
  35192. }
  35193. static struct vendor_data vendor_arm = {
  35194. diff -Nur linux-3.12.26.orig/drivers/usb/core/generic.c linux-3.12.26/drivers/usb/core/generic.c
  35195. --- linux-3.12.26.orig/drivers/usb/core/generic.c 2014-07-30 18:02:44.000000000 +0200
  35196. +++ linux-3.12.26/drivers/usb/core/generic.c 2014-08-06 16:50:14.729964161 +0200
  35197. @@ -152,6 +152,7 @@
  35198. dev_warn(&udev->dev,
  35199. "no configuration chosen from %d choice%s\n",
  35200. num_configs, plural(num_configs));
  35201. + dev_warn(&udev->dev, "No support over %dmA\n", udev->bus_mA);
  35202. }
  35203. return i;
  35204. }
  35205. diff -Nur linux-3.12.26.orig/drivers/usb/core/message.c linux-3.12.26/drivers/usb/core/message.c
  35206. --- linux-3.12.26.orig/drivers/usb/core/message.c 2014-07-30 18:02:44.000000000 +0200
  35207. +++ linux-3.12.26/drivers/usb/core/message.c 2014-08-06 16:50:14.733964192 +0200
  35208. @@ -1885,6 +1885,85 @@
  35209. if (cp->string == NULL &&
  35210. !(dev->quirks & USB_QUIRK_CONFIG_INTF_STRINGS))
  35211. cp->string = usb_cache_string(dev, cp->desc.iConfiguration);
  35212. +/* Uncomment this define to enable the HS Electrical Test support */
  35213. +#define DWC_HS_ELECT_TST 1
  35214. +#ifdef DWC_HS_ELECT_TST
  35215. + /* Here we implement the HS Electrical Test support. The
  35216. + * tester uses a vendor ID of 0x1A0A to indicate we should
  35217. + * run a special test sequence. The product ID tells us
  35218. + * which sequence to run. We invoke the test sequence by
  35219. + * sending a non-standard SetFeature command to our root
  35220. + * hub port. Our dwc_otg_hcd_hub_control() routine will
  35221. + * recognize the command and perform the desired test
  35222. + * sequence.
  35223. + */
  35224. + if (dev->descriptor.idVendor == 0x1A0A) {
  35225. + /* HSOTG Electrical Test */
  35226. + dev_warn(&dev->dev, "VID from HSOTG Electrical Test Fixture\n");
  35227. +
  35228. + if (dev->bus && dev->bus->root_hub) {
  35229. + struct usb_device *hdev = dev->bus->root_hub;
  35230. + dev_warn(&dev->dev, "Got PID 0x%x\n", dev->descriptor.idProduct);
  35231. +
  35232. + switch (dev->descriptor.idProduct) {
  35233. + case 0x0101: /* TEST_SE0_NAK */
  35234. + dev_warn(&dev->dev, "TEST_SE0_NAK\n");
  35235. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  35236. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  35237. + USB_PORT_FEAT_TEST, 0x300, NULL, 0, HZ);
  35238. + break;
  35239. +
  35240. + case 0x0102: /* TEST_J */
  35241. + dev_warn(&dev->dev, "TEST_J\n");
  35242. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  35243. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  35244. + USB_PORT_FEAT_TEST, 0x100, NULL, 0, HZ);
  35245. + break;
  35246. +
  35247. + case 0x0103: /* TEST_K */
  35248. + dev_warn(&dev->dev, "TEST_K\n");
  35249. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  35250. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  35251. + USB_PORT_FEAT_TEST, 0x200, NULL, 0, HZ);
  35252. + break;
  35253. +
  35254. + case 0x0104: /* TEST_PACKET */
  35255. + dev_warn(&dev->dev, "TEST_PACKET\n");
  35256. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  35257. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  35258. + USB_PORT_FEAT_TEST, 0x400, NULL, 0, HZ);
  35259. + break;
  35260. +
  35261. + case 0x0105: /* TEST_FORCE_ENABLE */
  35262. + dev_warn(&dev->dev, "TEST_FORCE_ENABLE\n");
  35263. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  35264. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  35265. + USB_PORT_FEAT_TEST, 0x500, NULL, 0, HZ);
  35266. + break;
  35267. +
  35268. + case 0x0106: /* HS_HOST_PORT_SUSPEND_RESUME */
  35269. + dev_warn(&dev->dev, "HS_HOST_PORT_SUSPEND_RESUME\n");
  35270. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  35271. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  35272. + USB_PORT_FEAT_TEST, 0x600, NULL, 0, 40 * HZ);
  35273. + break;
  35274. +
  35275. + case 0x0107: /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup */
  35276. + dev_warn(&dev->dev, "SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup\n");
  35277. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  35278. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  35279. + USB_PORT_FEAT_TEST, 0x700, NULL, 0, 40 * HZ);
  35280. + break;
  35281. +
  35282. + case 0x0108: /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute */
  35283. + dev_warn(&dev->dev, "SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute\n");
  35284. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  35285. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  35286. + USB_PORT_FEAT_TEST, 0x800, NULL, 0, 40 * HZ);
  35287. + }
  35288. + }
  35289. + }
  35290. +#endif /* DWC_HS_ELECT_TST */
  35291. /* Now that the interfaces are installed, re-enable LPM. */
  35292. usb_unlocked_enable_lpm(dev);
  35293. diff -Nur linux-3.12.26.orig/drivers/usb/core/otg_whitelist.h linux-3.12.26/drivers/usb/core/otg_whitelist.h
  35294. --- linux-3.12.26.orig/drivers/usb/core/otg_whitelist.h 2014-07-30 18:02:44.000000000 +0200
  35295. +++ linux-3.12.26/drivers/usb/core/otg_whitelist.h 2014-08-06 16:50:14.733964192 +0200
  35296. @@ -19,33 +19,82 @@
  35297. static struct usb_device_id whitelist_table [] = {
  35298. /* hubs are optional in OTG, but very handy ... */
  35299. +#define CERT_WITHOUT_HUBS
  35300. +#if defined(CERT_WITHOUT_HUBS)
  35301. +{ USB_DEVICE( 0x0000, 0x0000 ), }, /* Root HUB Only*/
  35302. +#else
  35303. { USB_DEVICE_INFO(USB_CLASS_HUB, 0, 0), },
  35304. { USB_DEVICE_INFO(USB_CLASS_HUB, 0, 1), },
  35305. +{ USB_DEVICE_INFO(USB_CLASS_HUB, 0, 2), },
  35306. +#endif
  35307. #ifdef CONFIG_USB_PRINTER /* ignoring nonstatic linkage! */
  35308. /* FIXME actually, printers are NOT supposed to use device classes;
  35309. * they're supposed to use interface classes...
  35310. */
  35311. -{ USB_DEVICE_INFO(7, 1, 1) },
  35312. -{ USB_DEVICE_INFO(7, 1, 2) },
  35313. -{ USB_DEVICE_INFO(7, 1, 3) },
  35314. +//{ USB_DEVICE_INFO(7, 1, 1) },
  35315. +//{ USB_DEVICE_INFO(7, 1, 2) },
  35316. +//{ USB_DEVICE_INFO(7, 1, 3) },
  35317. #endif
  35318. #ifdef CONFIG_USB_NET_CDCETHER
  35319. /* Linux-USB CDC Ethernet gadget */
  35320. -{ USB_DEVICE(0x0525, 0xa4a1), },
  35321. +//{ USB_DEVICE(0x0525, 0xa4a1), },
  35322. /* Linux-USB CDC Ethernet + RNDIS gadget */
  35323. -{ USB_DEVICE(0x0525, 0xa4a2), },
  35324. +//{ USB_DEVICE(0x0525, 0xa4a2), },
  35325. #endif
  35326. #if defined(CONFIG_USB_TEST) || defined(CONFIG_USB_TEST_MODULE)
  35327. /* gadget zero, for testing */
  35328. -{ USB_DEVICE(0x0525, 0xa4a0), },
  35329. +//{ USB_DEVICE(0x0525, 0xa4a0), },
  35330. #endif
  35331. +/* OPT Tester */
  35332. +{ USB_DEVICE( 0x1a0a, 0x0101 ), }, /* TEST_SE0_NAK */
  35333. +{ USB_DEVICE( 0x1a0a, 0x0102 ), }, /* Test_J */
  35334. +{ USB_DEVICE( 0x1a0a, 0x0103 ), }, /* Test_K */
  35335. +{ USB_DEVICE( 0x1a0a, 0x0104 ), }, /* Test_PACKET */
  35336. +{ USB_DEVICE( 0x1a0a, 0x0105 ), }, /* Test_FORCE_ENABLE */
  35337. +{ USB_DEVICE( 0x1a0a, 0x0106 ), }, /* HS_PORT_SUSPEND_RESUME */
  35338. +{ USB_DEVICE( 0x1a0a, 0x0107 ), }, /* SINGLE_STEP_GET_DESCRIPTOR setup */
  35339. +{ USB_DEVICE( 0x1a0a, 0x0108 ), }, /* SINGLE_STEP_GET_DESCRIPTOR execute */
  35340. +
  35341. +/* Sony cameras */
  35342. +{ USB_DEVICE_VER(0x054c,0x0010,0x0410, 0x0500), },
  35343. +
  35344. +/* Memory Devices */
  35345. +//{ USB_DEVICE( 0x0781, 0x5150 ), }, /* SanDisk */
  35346. +//{ USB_DEVICE( 0x05DC, 0x0080 ), }, /* Lexar */
  35347. +//{ USB_DEVICE( 0x4146, 0x9281 ), }, /* IOMEGA */
  35348. +//{ USB_DEVICE( 0x067b, 0x2507 ), }, /* Hammer 20GB External HD */
  35349. +{ USB_DEVICE( 0x0EA0, 0x2168 ), }, /* Ours Technology Inc. (BUFFALO ClipDrive)*/
  35350. +//{ USB_DEVICE( 0x0457, 0x0150 ), }, /* Silicon Integrated Systems Corp. */
  35351. +
  35352. +/* HP Printers */
  35353. +//{ USB_DEVICE( 0x03F0, 0x1102 ), }, /* HP Photosmart 245 */
  35354. +//{ USB_DEVICE( 0x03F0, 0x1302 ), }, /* HP Photosmart 370 Series */
  35355. +
  35356. +/* Speakers */
  35357. +//{ USB_DEVICE( 0x0499, 0x3002 ), }, /* YAMAHA YST-MS35D USB Speakers */
  35358. +//{ USB_DEVICE( 0x0672, 0x1041 ), }, /* Labtec USB Headset */
  35359. +
  35360. { } /* Terminating entry */
  35361. };
  35362. +static inline void report_errors(struct usb_device *dev)
  35363. +{
  35364. + /* OTG MESSAGE: report errors here, customize to match your product */
  35365. + dev_info(&dev->dev, "device Vendor:%04x Product:%04x is not supported\n",
  35366. + le16_to_cpu(dev->descriptor.idVendor),
  35367. + le16_to_cpu(dev->descriptor.idProduct));
  35368. + if (USB_CLASS_HUB == dev->descriptor.bDeviceClass){
  35369. + dev_printk(KERN_CRIT, &dev->dev, "Unsupported Hub Topology\n");
  35370. + } else {
  35371. + dev_printk(KERN_CRIT, &dev->dev, "Attached Device is not Supported\n");
  35372. + }
  35373. +}
  35374. +
  35375. +
  35376. static int is_targeted(struct usb_device *dev)
  35377. {
  35378. struct usb_device_id *id = whitelist_table;
  35379. @@ -55,58 +104,83 @@
  35380. return 1;
  35381. /* HNP test device is _never_ targeted (see OTG spec 6.6.6) */
  35382. - if ((le16_to_cpu(dev->descriptor.idVendor) == 0x1a0a &&
  35383. - le16_to_cpu(dev->descriptor.idProduct) == 0xbadd))
  35384. - return 0;
  35385. + if (dev->descriptor.idVendor == 0x1a0a &&
  35386. + dev->descriptor.idProduct == 0xbadd) {
  35387. + return 0;
  35388. + } else if (!enable_whitelist) {
  35389. + return 1;
  35390. + } else {
  35391. - /* NOTE: can't use usb_match_id() since interface caches
  35392. - * aren't set up yet. this is cut/paste from that code.
  35393. - */
  35394. - for (id = whitelist_table; id->match_flags; id++) {
  35395. - if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) &&
  35396. - id->idVendor != le16_to_cpu(dev->descriptor.idVendor))
  35397. - continue;
  35398. -
  35399. - if ((id->match_flags & USB_DEVICE_ID_MATCH_PRODUCT) &&
  35400. - id->idProduct != le16_to_cpu(dev->descriptor.idProduct))
  35401. - continue;
  35402. -
  35403. - /* No need to test id->bcdDevice_lo != 0, since 0 is never
  35404. - greater than any unsigned number. */
  35405. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_LO) &&
  35406. - (id->bcdDevice_lo > le16_to_cpu(dev->descriptor.bcdDevice)))
  35407. - continue;
  35408. -
  35409. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI) &&
  35410. - (id->bcdDevice_hi < le16_to_cpu(dev->descriptor.bcdDevice)))
  35411. - continue;
  35412. -
  35413. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_CLASS) &&
  35414. - (id->bDeviceClass != dev->descriptor.bDeviceClass))
  35415. - continue;
  35416. -
  35417. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) &&
  35418. - (id->bDeviceSubClass != dev->descriptor.bDeviceSubClass))
  35419. - continue;
  35420. -
  35421. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) &&
  35422. - (id->bDeviceProtocol != dev->descriptor.bDeviceProtocol))
  35423. - continue;
  35424. +#ifdef DEBUG
  35425. + dev_dbg(&dev->dev, "device V:%04x P:%04x DC:%04x SC:%04x PR:%04x \n",
  35426. + dev->descriptor.idVendor,
  35427. + dev->descriptor.idProduct,
  35428. + dev->descriptor.bDeviceClass,
  35429. + dev->descriptor.bDeviceSubClass,
  35430. + dev->descriptor.bDeviceProtocol);
  35431. +#endif
  35432. return 1;
  35433. + /* NOTE: can't use usb_match_id() since interface caches
  35434. + * aren't set up yet. this is cut/paste from that code.
  35435. + */
  35436. + for (id = whitelist_table; id->match_flags; id++) {
  35437. +#ifdef DEBUG
  35438. + dev_dbg(&dev->dev,
  35439. + "ID: V:%04x P:%04x DC:%04x SC:%04x PR:%04x \n",
  35440. + id->idVendor,
  35441. + id->idProduct,
  35442. + id->bDeviceClass,
  35443. + id->bDeviceSubClass,
  35444. + id->bDeviceProtocol);
  35445. +#endif
  35446. +
  35447. + if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) &&
  35448. + id->idVendor != le16_to_cpu(dev->descriptor.idVendor))
  35449. + continue;
  35450. +
  35451. + if ((id->match_flags & USB_DEVICE_ID_MATCH_PRODUCT) &&
  35452. + id->idProduct != le16_to_cpu(dev->descriptor.idProduct))
  35453. + continue;
  35454. +
  35455. + /* No need to test id->bcdDevice_lo != 0, since 0 is never
  35456. + greater than any unsigned number. */
  35457. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_LO) &&
  35458. + (id->bcdDevice_lo > le16_to_cpu(dev->descriptor.bcdDevice)))
  35459. + continue;
  35460. +
  35461. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI) &&
  35462. + (id->bcdDevice_hi < le16_to_cpu(dev->descriptor.bcdDevice)))
  35463. + continue;
  35464. +
  35465. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_CLASS) &&
  35466. + (id->bDeviceClass != dev->descriptor.bDeviceClass))
  35467. + continue;
  35468. +
  35469. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) &&
  35470. + (id->bDeviceSubClass != dev->descriptor.bDeviceSubClass))
  35471. + continue;
  35472. +
  35473. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) &&
  35474. + (id->bDeviceProtocol != dev->descriptor.bDeviceProtocol))
  35475. + continue;
  35476. +
  35477. + return 1;
  35478. + }
  35479. }
  35480. /* add other match criteria here ... */
  35481. -
  35482. - /* OTG MESSAGE: report errors here, customize to match your product */
  35483. - dev_err(&dev->dev, "device v%04x p%04x is not supported\n",
  35484. - le16_to_cpu(dev->descriptor.idVendor),
  35485. - le16_to_cpu(dev->descriptor.idProduct));
  35486. #ifdef CONFIG_USB_OTG_WHITELIST
  35487. + report_errors(dev);
  35488. return 0;
  35489. #else
  35490. - return 1;
  35491. + if (enable_whitelist) {
  35492. + report_errors(dev);
  35493. + return 0;
  35494. + } else {
  35495. + return 1;
  35496. + }
  35497. #endif
  35498. }
  35499. diff -Nur linux-3.12.26.orig/drivers/usb/gadget/file_storage.c linux-3.12.26/drivers/usb/gadget/file_storage.c
  35500. --- linux-3.12.26.orig/drivers/usb/gadget/file_storage.c 1970-01-01 01:00:00.000000000 +0100
  35501. +++ linux-3.12.26/drivers/usb/gadget/file_storage.c 2014-08-06 16:50:14.733964192 +0200
  35502. @@ -0,0 +1,3676 @@
  35503. +/*
  35504. + * file_storage.c -- File-backed USB Storage Gadget, for USB development
  35505. + *
  35506. + * Copyright (C) 2003-2008 Alan Stern
  35507. + * All rights reserved.
  35508. + *
  35509. + * Redistribution and use in source and binary forms, with or without
  35510. + * modification, are permitted provided that the following conditions
  35511. + * are met:
  35512. + * 1. Redistributions of source code must retain the above copyright
  35513. + * notice, this list of conditions, and the following disclaimer,
  35514. + * without modification.
  35515. + * 2. Redistributions in binary form must reproduce the above copyright
  35516. + * notice, this list of conditions and the following disclaimer in the
  35517. + * documentation and/or other materials provided with the distribution.
  35518. + * 3. The names of the above-listed copyright holders may not be used
  35519. + * to endorse or promote products derived from this software without
  35520. + * specific prior written permission.
  35521. + *
  35522. + * ALTERNATIVELY, this software may be distributed under the terms of the
  35523. + * GNU General Public License ("GPL") as published by the Free Software
  35524. + * Foundation, either version 2 of that License or (at your option) any
  35525. + * later version.
  35526. + *
  35527. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  35528. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  35529. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  35530. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  35531. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  35532. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  35533. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  35534. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  35535. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  35536. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  35537. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35538. + */
  35539. +
  35540. +
  35541. +/*
  35542. + * The File-backed Storage Gadget acts as a USB Mass Storage device,
  35543. + * appearing to the host as a disk drive or as a CD-ROM drive. In addition
  35544. + * to providing an example of a genuinely useful gadget driver for a USB
  35545. + * device, it also illustrates a technique of double-buffering for increased
  35546. + * throughput. Last but not least, it gives an easy way to probe the
  35547. + * behavior of the Mass Storage drivers in a USB host.
  35548. + *
  35549. + * Backing storage is provided by a regular file or a block device, specified
  35550. + * by the "file" module parameter. Access can be limited to read-only by
  35551. + * setting the optional "ro" module parameter. (For CD-ROM emulation,
  35552. + * access is always read-only.) The gadget will indicate that it has
  35553. + * removable media if the optional "removable" module parameter is set.
  35554. + *
  35555. + * The gadget supports the Control-Bulk (CB), Control-Bulk-Interrupt (CBI),
  35556. + * and Bulk-Only (also known as Bulk-Bulk-Bulk or BBB) transports, selected
  35557. + * by the optional "transport" module parameter. It also supports the
  35558. + * following protocols: RBC (0x01), ATAPI or SFF-8020i (0x02), QIC-157 (0c03),
  35559. + * UFI (0x04), SFF-8070i (0x05), and transparent SCSI (0x06), selected by
  35560. + * the optional "protocol" module parameter. In addition, the default
  35561. + * Vendor ID, Product ID, release number and serial number can be overridden.
  35562. + *
  35563. + * There is support for multiple logical units (LUNs), each of which has
  35564. + * its own backing file. The number of LUNs can be set using the optional
  35565. + * "luns" module parameter (anywhere from 1 to 8), and the corresponding
  35566. + * files are specified using comma-separated lists for "file" and "ro".
  35567. + * The default number of LUNs is taken from the number of "file" elements;
  35568. + * it is 1 if "file" is not given. If "removable" is not set then a backing
  35569. + * file must be specified for each LUN. If it is set, then an unspecified
  35570. + * or empty backing filename means the LUN's medium is not loaded. Ideally
  35571. + * each LUN would be settable independently as a disk drive or a CD-ROM
  35572. + * drive, but currently all LUNs have to be the same type. The CD-ROM
  35573. + * emulation includes a single data track and no audio tracks; hence there
  35574. + * need be only one backing file per LUN.
  35575. + *
  35576. + * Requirements are modest; only a bulk-in and a bulk-out endpoint are
  35577. + * needed (an interrupt-out endpoint is also needed for CBI). The memory
  35578. + * requirement amounts to two 16K buffers, size configurable by a parameter.
  35579. + * Support is included for both full-speed and high-speed operation.
  35580. + *
  35581. + * Note that the driver is slightly non-portable in that it assumes a
  35582. + * single memory/DMA buffer will be useable for bulk-in, bulk-out, and
  35583. + * interrupt-in endpoints. With most device controllers this isn't an
  35584. + * issue, but there may be some with hardware restrictions that prevent
  35585. + * a buffer from being used by more than one endpoint.
  35586. + *
  35587. + * Module options:
  35588. + *
  35589. + * file=filename[,filename...]
  35590. + * Required if "removable" is not set, names of
  35591. + * the files or block devices used for
  35592. + * backing storage
  35593. + * serial=HHHH... Required serial number (string of hex chars)
  35594. + * ro=b[,b...] Default false, booleans for read-only access
  35595. + * removable Default false, boolean for removable media
  35596. + * luns=N Default N = number of filenames, number of
  35597. + * LUNs to support
  35598. + * nofua=b[,b...] Default false, booleans for ignore FUA flag
  35599. + * in SCSI WRITE(10,12) commands
  35600. + * stall Default determined according to the type of
  35601. + * USB device controller (usually true),
  35602. + * boolean to permit the driver to halt
  35603. + * bulk endpoints
  35604. + * cdrom Default false, boolean for whether to emulate
  35605. + * a CD-ROM drive
  35606. + * transport=XXX Default BBB, transport name (CB, CBI, or BBB)
  35607. + * protocol=YYY Default SCSI, protocol name (RBC, 8020 or
  35608. + * ATAPI, QIC, UFI, 8070, or SCSI;
  35609. + * also 1 - 6)
  35610. + * vendor=0xVVVV Default 0x0525 (NetChip), USB Vendor ID
  35611. + * product=0xPPPP Default 0xa4a5 (FSG), USB Product ID
  35612. + * release=0xRRRR Override the USB release number (bcdDevice)
  35613. + * buflen=N Default N=16384, buffer size used (will be
  35614. + * rounded down to a multiple of
  35615. + * PAGE_CACHE_SIZE)
  35616. + *
  35617. + * If CONFIG_USB_FILE_STORAGE_TEST is not set, only the "file", "serial", "ro",
  35618. + * "removable", "luns", "nofua", "stall", and "cdrom" options are available;
  35619. + * default values are used for everything else.
  35620. + *
  35621. + * The pathnames of the backing files and the ro settings are available in
  35622. + * the attribute files "file", "nofua", and "ro" in the lun<n> subdirectory of
  35623. + * the gadget's sysfs directory. If the "removable" option is set, writing to
  35624. + * these files will simulate ejecting/loading the medium (writing an empty
  35625. + * line means eject) and adjusting a write-enable tab. Changes to the ro
  35626. + * setting are not allowed when the medium is loaded or if CD-ROM emulation
  35627. + * is being used.
  35628. + *
  35629. + * This gadget driver is heavily based on "Gadget Zero" by David Brownell.
  35630. + * The driver's SCSI command interface was based on the "Information
  35631. + * technology - Small Computer System Interface - 2" document from
  35632. + * X3T9.2 Project 375D, Revision 10L, 7-SEP-93, available at
  35633. + * <http://www.t10.org/ftp/t10/drafts/s2/s2-r10l.pdf>. The single exception
  35634. + * is opcode 0x23 (READ FORMAT CAPACITIES), which was based on the
  35635. + * "Universal Serial Bus Mass Storage Class UFI Command Specification"
  35636. + * document, Revision 1.0, December 14, 1998, available at
  35637. + * <http://www.usb.org/developers/devclass_docs/usbmass-ufi10.pdf>.
  35638. + */
  35639. +
  35640. +
  35641. +/*
  35642. + * Driver Design
  35643. + *
  35644. + * The FSG driver is fairly straightforward. There is a main kernel
  35645. + * thread that handles most of the work. Interrupt routines field
  35646. + * callbacks from the controller driver: bulk- and interrupt-request
  35647. + * completion notifications, endpoint-0 events, and disconnect events.
  35648. + * Completion events are passed to the main thread by wakeup calls. Many
  35649. + * ep0 requests are handled at interrupt time, but SetInterface,
  35650. + * SetConfiguration, and device reset requests are forwarded to the
  35651. + * thread in the form of "exceptions" using SIGUSR1 signals (since they
  35652. + * should interrupt any ongoing file I/O operations).
  35653. + *
  35654. + * The thread's main routine implements the standard command/data/status
  35655. + * parts of a SCSI interaction. It and its subroutines are full of tests
  35656. + * for pending signals/exceptions -- all this polling is necessary since
  35657. + * the kernel has no setjmp/longjmp equivalents. (Maybe this is an
  35658. + * indication that the driver really wants to be running in userspace.)
  35659. + * An important point is that so long as the thread is alive it keeps an
  35660. + * open reference to the backing file. This will prevent unmounting
  35661. + * the backing file's underlying filesystem and could cause problems
  35662. + * during system shutdown, for example. To prevent such problems, the
  35663. + * thread catches INT, TERM, and KILL signals and converts them into
  35664. + * an EXIT exception.
  35665. + *
  35666. + * In normal operation the main thread is started during the gadget's
  35667. + * fsg_bind() callback and stopped during fsg_unbind(). But it can also
  35668. + * exit when it receives a signal, and there's no point leaving the
  35669. + * gadget running when the thread is dead. So just before the thread
  35670. + * exits, it deregisters the gadget driver. This makes things a little
  35671. + * tricky: The driver is deregistered at two places, and the exiting
  35672. + * thread can indirectly call fsg_unbind() which in turn can tell the
  35673. + * thread to exit. The first problem is resolved through the use of the
  35674. + * REGISTERED atomic bitflag; the driver will only be deregistered once.
  35675. + * The second problem is resolved by having fsg_unbind() check
  35676. + * fsg->state; it won't try to stop the thread if the state is already
  35677. + * FSG_STATE_TERMINATED.
  35678. + *
  35679. + * To provide maximum throughput, the driver uses a circular pipeline of
  35680. + * buffer heads (struct fsg_buffhd). In principle the pipeline can be
  35681. + * arbitrarily long; in practice the benefits don't justify having more
  35682. + * than 2 stages (i.e., double buffering). But it helps to think of the
  35683. + * pipeline as being a long one. Each buffer head contains a bulk-in and
  35684. + * a bulk-out request pointer (since the buffer can be used for both
  35685. + * output and input -- directions always are given from the host's
  35686. + * point of view) as well as a pointer to the buffer and various state
  35687. + * variables.
  35688. + *
  35689. + * Use of the pipeline follows a simple protocol. There is a variable
  35690. + * (fsg->next_buffhd_to_fill) that points to the next buffer head to use.
  35691. + * At any time that buffer head may still be in use from an earlier
  35692. + * request, so each buffer head has a state variable indicating whether
  35693. + * it is EMPTY, FULL, or BUSY. Typical use involves waiting for the
  35694. + * buffer head to be EMPTY, filling the buffer either by file I/O or by
  35695. + * USB I/O (during which the buffer head is BUSY), and marking the buffer
  35696. + * head FULL when the I/O is complete. Then the buffer will be emptied
  35697. + * (again possibly by USB I/O, during which it is marked BUSY) and
  35698. + * finally marked EMPTY again (possibly by a completion routine).
  35699. + *
  35700. + * A module parameter tells the driver to avoid stalling the bulk
  35701. + * endpoints wherever the transport specification allows. This is
  35702. + * necessary for some UDCs like the SuperH, which cannot reliably clear a
  35703. + * halt on a bulk endpoint. However, under certain circumstances the
  35704. + * Bulk-only specification requires a stall. In such cases the driver
  35705. + * will halt the endpoint and set a flag indicating that it should clear
  35706. + * the halt in software during the next device reset. Hopefully this
  35707. + * will permit everything to work correctly. Furthermore, although the
  35708. + * specification allows the bulk-out endpoint to halt when the host sends
  35709. + * too much data, implementing this would cause an unavoidable race.
  35710. + * The driver will always use the "no-stall" approach for OUT transfers.
  35711. + *
  35712. + * One subtle point concerns sending status-stage responses for ep0
  35713. + * requests. Some of these requests, such as device reset, can involve
  35714. + * interrupting an ongoing file I/O operation, which might take an
  35715. + * arbitrarily long time. During that delay the host might give up on
  35716. + * the original ep0 request and issue a new one. When that happens the
  35717. + * driver should not notify the host about completion of the original
  35718. + * request, as the host will no longer be waiting for it. So the driver
  35719. + * assigns to each ep0 request a unique tag, and it keeps track of the
  35720. + * tag value of the request associated with a long-running exception
  35721. + * (device-reset, interface-change, or configuration-change). When the
  35722. + * exception handler is finished, the status-stage response is submitted
  35723. + * only if the current ep0 request tag is equal to the exception request
  35724. + * tag. Thus only the most recently received ep0 request will get a
  35725. + * status-stage response.
  35726. + *
  35727. + * Warning: This driver source file is too long. It ought to be split up
  35728. + * into a header file plus about 3 separate .c files, to handle the details
  35729. + * of the Gadget, USB Mass Storage, and SCSI protocols.
  35730. + */
  35731. +
  35732. +
  35733. +/* #define VERBOSE_DEBUG */
  35734. +/* #define DUMP_MSGS */
  35735. +
  35736. +
  35737. +#include <linux/blkdev.h>
  35738. +#include <linux/completion.h>
  35739. +#include <linux/dcache.h>
  35740. +#include <linux/delay.h>
  35741. +#include <linux/device.h>
  35742. +#include <linux/fcntl.h>
  35743. +#include <linux/file.h>
  35744. +#include <linux/fs.h>
  35745. +#include <linux/kref.h>
  35746. +#include <linux/kthread.h>
  35747. +#include <linux/limits.h>
  35748. +#include <linux/module.h>
  35749. +#include <linux/rwsem.h>
  35750. +#include <linux/slab.h>
  35751. +#include <linux/spinlock.h>
  35752. +#include <linux/string.h>
  35753. +#include <linux/freezer.h>
  35754. +#include <linux/utsname.h>
  35755. +
  35756. +#include <linux/usb/ch9.h>
  35757. +#include <linux/usb/gadget.h>
  35758. +
  35759. +#include "gadget_chips.h"
  35760. +
  35761. +
  35762. +
  35763. +/*
  35764. + * Kbuild is not very cooperative with respect to linking separately
  35765. + * compiled library objects into one module. So for now we won't use
  35766. + * separate compilation ... ensuring init/exit sections work to shrink
  35767. + * the runtime footprint, and giving us at least some parts of what
  35768. + * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
  35769. + */
  35770. +#include "usbstring.c"
  35771. +#include "config.c"
  35772. +#include "epautoconf.c"
  35773. +
  35774. +/*-------------------------------------------------------------------------*/
  35775. +
  35776. +#define DRIVER_DESC "File-backed Storage Gadget"
  35777. +#define DRIVER_NAME "g_file_storage"
  35778. +#define DRIVER_VERSION "1 September 2010"
  35779. +
  35780. +static char fsg_string_manufacturer[64];
  35781. +static const char fsg_string_product[] = DRIVER_DESC;
  35782. +static const char fsg_string_config[] = "Self-powered";
  35783. +static const char fsg_string_interface[] = "Mass Storage";
  35784. +
  35785. +
  35786. +#include "storage_common.c"
  35787. +
  35788. +
  35789. +MODULE_DESCRIPTION(DRIVER_DESC);
  35790. +MODULE_AUTHOR("Alan Stern");
  35791. +MODULE_LICENSE("Dual BSD/GPL");
  35792. +
  35793. +/*
  35794. + * This driver assumes self-powered hardware and has no way for users to
  35795. + * trigger remote wakeup. It uses autoconfiguration to select endpoints
  35796. + * and endpoint addresses.
  35797. + */
  35798. +
  35799. +
  35800. +/*-------------------------------------------------------------------------*/
  35801. +
  35802. +
  35803. +/* Encapsulate the module parameter settings */
  35804. +
  35805. +static struct {
  35806. + char *file[FSG_MAX_LUNS];
  35807. + char *serial;
  35808. + bool ro[FSG_MAX_LUNS];
  35809. + bool nofua[FSG_MAX_LUNS];
  35810. + unsigned int num_filenames;
  35811. + unsigned int num_ros;
  35812. + unsigned int num_nofuas;
  35813. + unsigned int nluns;
  35814. +
  35815. + bool removable;
  35816. + bool can_stall;
  35817. + bool cdrom;
  35818. +
  35819. + char *transport_parm;
  35820. + char *protocol_parm;
  35821. + unsigned short vendor;
  35822. + unsigned short product;
  35823. + unsigned short release;
  35824. + unsigned int buflen;
  35825. +
  35826. + int transport_type;
  35827. + char *transport_name;
  35828. + int protocol_type;
  35829. + char *protocol_name;
  35830. +
  35831. +} mod_data = { // Default values
  35832. + .transport_parm = "BBB",
  35833. + .protocol_parm = "SCSI",
  35834. + .removable = 0,
  35835. + .can_stall = 1,
  35836. + .cdrom = 0,
  35837. + .vendor = FSG_VENDOR_ID,
  35838. + .product = FSG_PRODUCT_ID,
  35839. + .release = 0xffff, // Use controller chip type
  35840. + .buflen = 16384,
  35841. + };
  35842. +
  35843. +
  35844. +module_param_array_named(file, mod_data.file, charp, &mod_data.num_filenames,
  35845. + S_IRUGO);
  35846. +MODULE_PARM_DESC(file, "names of backing files or devices");
  35847. +
  35848. +module_param_named(serial, mod_data.serial, charp, S_IRUGO);
  35849. +MODULE_PARM_DESC(serial, "USB serial number");
  35850. +
  35851. +module_param_array_named(ro, mod_data.ro, bool, &mod_data.num_ros, S_IRUGO);
  35852. +MODULE_PARM_DESC(ro, "true to force read-only");
  35853. +
  35854. +module_param_array_named(nofua, mod_data.nofua, bool, &mod_data.num_nofuas,
  35855. + S_IRUGO);
  35856. +MODULE_PARM_DESC(nofua, "true to ignore SCSI WRITE(10,12) FUA bit");
  35857. +
  35858. +module_param_named(luns, mod_data.nluns, uint, S_IRUGO);
  35859. +MODULE_PARM_DESC(luns, "number of LUNs");
  35860. +
  35861. +module_param_named(removable, mod_data.removable, bool, S_IRUGO);
  35862. +MODULE_PARM_DESC(removable, "true to simulate removable media");
  35863. +
  35864. +module_param_named(stall, mod_data.can_stall, bool, S_IRUGO);
  35865. +MODULE_PARM_DESC(stall, "false to prevent bulk stalls");
  35866. +
  35867. +module_param_named(cdrom, mod_data.cdrom, bool, S_IRUGO);
  35868. +MODULE_PARM_DESC(cdrom, "true to emulate cdrom instead of disk");
  35869. +
  35870. +/* In the non-TEST version, only the module parameters listed above
  35871. + * are available. */
  35872. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  35873. +
  35874. +module_param_named(transport, mod_data.transport_parm, charp, S_IRUGO);
  35875. +MODULE_PARM_DESC(transport, "type of transport (BBB, CBI, or CB)");
  35876. +
  35877. +module_param_named(protocol, mod_data.protocol_parm, charp, S_IRUGO);
  35878. +MODULE_PARM_DESC(protocol, "type of protocol (RBC, 8020, QIC, UFI, "
  35879. + "8070, or SCSI)");
  35880. +
  35881. +module_param_named(vendor, mod_data.vendor, ushort, S_IRUGO);
  35882. +MODULE_PARM_DESC(vendor, "USB Vendor ID");
  35883. +
  35884. +module_param_named(product, mod_data.product, ushort, S_IRUGO);
  35885. +MODULE_PARM_DESC(product, "USB Product ID");
  35886. +
  35887. +module_param_named(release, mod_data.release, ushort, S_IRUGO);
  35888. +MODULE_PARM_DESC(release, "USB release number");
  35889. +
  35890. +module_param_named(buflen, mod_data.buflen, uint, S_IRUGO);
  35891. +MODULE_PARM_DESC(buflen, "I/O buffer size");
  35892. +
  35893. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  35894. +
  35895. +
  35896. +/*
  35897. + * These definitions will permit the compiler to avoid generating code for
  35898. + * parts of the driver that aren't used in the non-TEST version. Even gcc
  35899. + * can recognize when a test of a constant expression yields a dead code
  35900. + * path.
  35901. + */
  35902. +
  35903. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  35904. +
  35905. +#define transport_is_bbb() (mod_data.transport_type == USB_PR_BULK)
  35906. +#define transport_is_cbi() (mod_data.transport_type == USB_PR_CBI)
  35907. +#define protocol_is_scsi() (mod_data.protocol_type == USB_SC_SCSI)
  35908. +
  35909. +#else
  35910. +
  35911. +#define transport_is_bbb() 1
  35912. +#define transport_is_cbi() 0
  35913. +#define protocol_is_scsi() 1
  35914. +
  35915. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  35916. +
  35917. +
  35918. +/*-------------------------------------------------------------------------*/
  35919. +
  35920. +
  35921. +struct fsg_dev {
  35922. + /* lock protects: state, all the req_busy's, and cbbuf_cmnd */
  35923. + spinlock_t lock;
  35924. + struct usb_gadget *gadget;
  35925. +
  35926. + /* filesem protects: backing files in use */
  35927. + struct rw_semaphore filesem;
  35928. +
  35929. + /* reference counting: wait until all LUNs are released */
  35930. + struct kref ref;
  35931. +
  35932. + struct usb_ep *ep0; // Handy copy of gadget->ep0
  35933. + struct usb_request *ep0req; // For control responses
  35934. + unsigned int ep0_req_tag;
  35935. + const char *ep0req_name;
  35936. +
  35937. + struct usb_request *intreq; // For interrupt responses
  35938. + int intreq_busy;
  35939. + struct fsg_buffhd *intr_buffhd;
  35940. +
  35941. + unsigned int bulk_out_maxpacket;
  35942. + enum fsg_state state; // For exception handling
  35943. + unsigned int exception_req_tag;
  35944. +
  35945. + u8 config, new_config;
  35946. +
  35947. + unsigned int running : 1;
  35948. + unsigned int bulk_in_enabled : 1;
  35949. + unsigned int bulk_out_enabled : 1;
  35950. + unsigned int intr_in_enabled : 1;
  35951. + unsigned int phase_error : 1;
  35952. + unsigned int short_packet_received : 1;
  35953. + unsigned int bad_lun_okay : 1;
  35954. +
  35955. + unsigned long atomic_bitflags;
  35956. +#define REGISTERED 0
  35957. +#define IGNORE_BULK_OUT 1
  35958. +#define SUSPENDED 2
  35959. +
  35960. + struct usb_ep *bulk_in;
  35961. + struct usb_ep *bulk_out;
  35962. + struct usb_ep *intr_in;
  35963. +
  35964. + struct fsg_buffhd *next_buffhd_to_fill;
  35965. + struct fsg_buffhd *next_buffhd_to_drain;
  35966. +
  35967. + int thread_wakeup_needed;
  35968. + struct completion thread_notifier;
  35969. + struct task_struct *thread_task;
  35970. +
  35971. + int cmnd_size;
  35972. + u8 cmnd[MAX_COMMAND_SIZE];
  35973. + enum data_direction data_dir;
  35974. + u32 data_size;
  35975. + u32 data_size_from_cmnd;
  35976. + u32 tag;
  35977. + unsigned int lun;
  35978. + u32 residue;
  35979. + u32 usb_amount_left;
  35980. +
  35981. + /* The CB protocol offers no way for a host to know when a command
  35982. + * has completed. As a result the next command may arrive early,
  35983. + * and we will still have to handle it. For that reason we need
  35984. + * a buffer to store new commands when using CB (or CBI, which
  35985. + * does not oblige a host to wait for command completion either). */
  35986. + int cbbuf_cmnd_size;
  35987. + u8 cbbuf_cmnd[MAX_COMMAND_SIZE];
  35988. +
  35989. + unsigned int nluns;
  35990. + struct fsg_lun *luns;
  35991. + struct fsg_lun *curlun;
  35992. + /* Must be the last entry */
  35993. + struct fsg_buffhd buffhds[];
  35994. +};
  35995. +
  35996. +typedef void (*fsg_routine_t)(struct fsg_dev *);
  35997. +
  35998. +static int exception_in_progress(struct fsg_dev *fsg)
  35999. +{
  36000. + return (fsg->state > FSG_STATE_IDLE);
  36001. +}
  36002. +
  36003. +/* Make bulk-out requests be divisible by the maxpacket size */
  36004. +static void set_bulk_out_req_length(struct fsg_dev *fsg,
  36005. + struct fsg_buffhd *bh, unsigned int length)
  36006. +{
  36007. + unsigned int rem;
  36008. +
  36009. + bh->bulk_out_intended_length = length;
  36010. + rem = length % fsg->bulk_out_maxpacket;
  36011. + if (rem > 0)
  36012. + length += fsg->bulk_out_maxpacket - rem;
  36013. + bh->outreq->length = length;
  36014. +}
  36015. +
  36016. +static struct fsg_dev *the_fsg;
  36017. +static struct usb_gadget_driver fsg_driver;
  36018. +
  36019. +
  36020. +/*-------------------------------------------------------------------------*/
  36021. +
  36022. +static int fsg_set_halt(struct fsg_dev *fsg, struct usb_ep *ep)
  36023. +{
  36024. + const char *name;
  36025. +
  36026. + if (ep == fsg->bulk_in)
  36027. + name = "bulk-in";
  36028. + else if (ep == fsg->bulk_out)
  36029. + name = "bulk-out";
  36030. + else
  36031. + name = ep->name;
  36032. + DBG(fsg, "%s set halt\n", name);
  36033. + return usb_ep_set_halt(ep);
  36034. +}
  36035. +
  36036. +
  36037. +/*-------------------------------------------------------------------------*/
  36038. +
  36039. +/*
  36040. + * DESCRIPTORS ... most are static, but strings and (full) configuration
  36041. + * descriptors are built on demand. Also the (static) config and interface
  36042. + * descriptors are adjusted during fsg_bind().
  36043. + */
  36044. +
  36045. +/* There is only one configuration. */
  36046. +#define CONFIG_VALUE 1
  36047. +
  36048. +static struct usb_device_descriptor
  36049. +device_desc = {
  36050. + .bLength = sizeof device_desc,
  36051. + .bDescriptorType = USB_DT_DEVICE,
  36052. +
  36053. + .bcdUSB = cpu_to_le16(0x0200),
  36054. + .bDeviceClass = USB_CLASS_PER_INTERFACE,
  36055. +
  36056. + /* The next three values can be overridden by module parameters */
  36057. + .idVendor = cpu_to_le16(FSG_VENDOR_ID),
  36058. + .idProduct = cpu_to_le16(FSG_PRODUCT_ID),
  36059. + .bcdDevice = cpu_to_le16(0xffff),
  36060. +
  36061. + .iManufacturer = FSG_STRING_MANUFACTURER,
  36062. + .iProduct = FSG_STRING_PRODUCT,
  36063. + .iSerialNumber = FSG_STRING_SERIAL,
  36064. + .bNumConfigurations = 1,
  36065. +};
  36066. +
  36067. +static struct usb_config_descriptor
  36068. +config_desc = {
  36069. + .bLength = sizeof config_desc,
  36070. + .bDescriptorType = USB_DT_CONFIG,
  36071. +
  36072. + /* wTotalLength computed by usb_gadget_config_buf() */
  36073. + .bNumInterfaces = 1,
  36074. + .bConfigurationValue = CONFIG_VALUE,
  36075. + .iConfiguration = FSG_STRING_CONFIG,
  36076. + .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
  36077. + .bMaxPower = CONFIG_USB_GADGET_VBUS_DRAW / 2,
  36078. +};
  36079. +
  36080. +
  36081. +static struct usb_qualifier_descriptor
  36082. +dev_qualifier = {
  36083. + .bLength = sizeof dev_qualifier,
  36084. + .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
  36085. +
  36086. + .bcdUSB = cpu_to_le16(0x0200),
  36087. + .bDeviceClass = USB_CLASS_PER_INTERFACE,
  36088. +
  36089. + .bNumConfigurations = 1,
  36090. +};
  36091. +
  36092. +static int populate_bos(struct fsg_dev *fsg, u8 *buf)
  36093. +{
  36094. + memcpy(buf, &fsg_bos_desc, USB_DT_BOS_SIZE);
  36095. + buf += USB_DT_BOS_SIZE;
  36096. +
  36097. + memcpy(buf, &fsg_ext_cap_desc, USB_DT_USB_EXT_CAP_SIZE);
  36098. + buf += USB_DT_USB_EXT_CAP_SIZE;
  36099. +
  36100. + memcpy(buf, &fsg_ss_cap_desc, USB_DT_USB_SS_CAP_SIZE);
  36101. +
  36102. + return USB_DT_BOS_SIZE + USB_DT_USB_SS_CAP_SIZE
  36103. + + USB_DT_USB_EXT_CAP_SIZE;
  36104. +}
  36105. +
  36106. +/*
  36107. + * Config descriptors must agree with the code that sets configurations
  36108. + * and with code managing interfaces and their altsettings. They must
  36109. + * also handle different speeds and other-speed requests.
  36110. + */
  36111. +static int populate_config_buf(struct usb_gadget *gadget,
  36112. + u8 *buf, u8 type, unsigned index)
  36113. +{
  36114. + enum usb_device_speed speed = gadget->speed;
  36115. + int len;
  36116. + const struct usb_descriptor_header **function;
  36117. +
  36118. + if (index > 0)
  36119. + return -EINVAL;
  36120. +
  36121. + if (gadget_is_dualspeed(gadget) && type == USB_DT_OTHER_SPEED_CONFIG)
  36122. + speed = (USB_SPEED_FULL + USB_SPEED_HIGH) - speed;
  36123. + function = gadget_is_dualspeed(gadget) && speed == USB_SPEED_HIGH
  36124. + ? (const struct usb_descriptor_header **)fsg_hs_function
  36125. + : (const struct usb_descriptor_header **)fsg_fs_function;
  36126. +
  36127. + /* for now, don't advertise srp-only devices */
  36128. + if (!gadget_is_otg(gadget))
  36129. + function++;
  36130. +
  36131. + len = usb_gadget_config_buf(&config_desc, buf, EP0_BUFSIZE, function);
  36132. + ((struct usb_config_descriptor *) buf)->bDescriptorType = type;
  36133. + return len;
  36134. +}
  36135. +
  36136. +
  36137. +/*-------------------------------------------------------------------------*/
  36138. +
  36139. +/* These routines may be called in process context or in_irq */
  36140. +
  36141. +/* Caller must hold fsg->lock */
  36142. +static void wakeup_thread(struct fsg_dev *fsg)
  36143. +{
  36144. + /* Tell the main thread that something has happened */
  36145. + fsg->thread_wakeup_needed = 1;
  36146. + if (fsg->thread_task)
  36147. + wake_up_process(fsg->thread_task);
  36148. +}
  36149. +
  36150. +
  36151. +static void raise_exception(struct fsg_dev *fsg, enum fsg_state new_state)
  36152. +{
  36153. + unsigned long flags;
  36154. +
  36155. + /* Do nothing if a higher-priority exception is already in progress.
  36156. + * If a lower-or-equal priority exception is in progress, preempt it
  36157. + * and notify the main thread by sending it a signal. */
  36158. + spin_lock_irqsave(&fsg->lock, flags);
  36159. + if (fsg->state <= new_state) {
  36160. + fsg->exception_req_tag = fsg->ep0_req_tag;
  36161. + fsg->state = new_state;
  36162. + if (fsg->thread_task)
  36163. + send_sig_info(SIGUSR1, SEND_SIG_FORCED,
  36164. + fsg->thread_task);
  36165. + }
  36166. + spin_unlock_irqrestore(&fsg->lock, flags);
  36167. +}
  36168. +
  36169. +
  36170. +/*-------------------------------------------------------------------------*/
  36171. +
  36172. +/* The disconnect callback and ep0 routines. These always run in_irq,
  36173. + * except that ep0_queue() is called in the main thread to acknowledge
  36174. + * completion of various requests: set config, set interface, and
  36175. + * Bulk-only device reset. */
  36176. +
  36177. +static void fsg_disconnect(struct usb_gadget *gadget)
  36178. +{
  36179. + struct fsg_dev *fsg = get_gadget_data(gadget);
  36180. +
  36181. + DBG(fsg, "disconnect or port reset\n");
  36182. + raise_exception(fsg, FSG_STATE_DISCONNECT);
  36183. +}
  36184. +
  36185. +
  36186. +static int ep0_queue(struct fsg_dev *fsg)
  36187. +{
  36188. + int rc;
  36189. +
  36190. + rc = usb_ep_queue(fsg->ep0, fsg->ep0req, GFP_ATOMIC);
  36191. + if (rc != 0 && rc != -ESHUTDOWN) {
  36192. +
  36193. + /* We can't do much more than wait for a reset */
  36194. + WARNING(fsg, "error in submission: %s --> %d\n",
  36195. + fsg->ep0->name, rc);
  36196. + }
  36197. + return rc;
  36198. +}
  36199. +
  36200. +static void ep0_complete(struct usb_ep *ep, struct usb_request *req)
  36201. +{
  36202. + struct fsg_dev *fsg = ep->driver_data;
  36203. +
  36204. + if (req->actual > 0)
  36205. + dump_msg(fsg, fsg->ep0req_name, req->buf, req->actual);
  36206. + if (req->status || req->actual != req->length)
  36207. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  36208. + req->status, req->actual, req->length);
  36209. + if (req->status == -ECONNRESET) // Request was cancelled
  36210. + usb_ep_fifo_flush(ep);
  36211. +
  36212. + if (req->status == 0 && req->context)
  36213. + ((fsg_routine_t) (req->context))(fsg);
  36214. +}
  36215. +
  36216. +
  36217. +/*-------------------------------------------------------------------------*/
  36218. +
  36219. +/* Bulk and interrupt endpoint completion handlers.
  36220. + * These always run in_irq. */
  36221. +
  36222. +static void bulk_in_complete(struct usb_ep *ep, struct usb_request *req)
  36223. +{
  36224. + struct fsg_dev *fsg = ep->driver_data;
  36225. + struct fsg_buffhd *bh = req->context;
  36226. +
  36227. + if (req->status || req->actual != req->length)
  36228. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  36229. + req->status, req->actual, req->length);
  36230. + if (req->status == -ECONNRESET) // Request was cancelled
  36231. + usb_ep_fifo_flush(ep);
  36232. +
  36233. + /* Hold the lock while we update the request and buffer states */
  36234. + smp_wmb();
  36235. + spin_lock(&fsg->lock);
  36236. + bh->inreq_busy = 0;
  36237. + bh->state = BUF_STATE_EMPTY;
  36238. + wakeup_thread(fsg);
  36239. + spin_unlock(&fsg->lock);
  36240. +}
  36241. +
  36242. +static void bulk_out_complete(struct usb_ep *ep, struct usb_request *req)
  36243. +{
  36244. + struct fsg_dev *fsg = ep->driver_data;
  36245. + struct fsg_buffhd *bh = req->context;
  36246. +
  36247. + dump_msg(fsg, "bulk-out", req->buf, req->actual);
  36248. + if (req->status || req->actual != bh->bulk_out_intended_length)
  36249. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  36250. + req->status, req->actual,
  36251. + bh->bulk_out_intended_length);
  36252. + if (req->status == -ECONNRESET) // Request was cancelled
  36253. + usb_ep_fifo_flush(ep);
  36254. +
  36255. + /* Hold the lock while we update the request and buffer states */
  36256. + smp_wmb();
  36257. + spin_lock(&fsg->lock);
  36258. + bh->outreq_busy = 0;
  36259. + bh->state = BUF_STATE_FULL;
  36260. + wakeup_thread(fsg);
  36261. + spin_unlock(&fsg->lock);
  36262. +}
  36263. +
  36264. +
  36265. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  36266. +static void intr_in_complete(struct usb_ep *ep, struct usb_request *req)
  36267. +{
  36268. + struct fsg_dev *fsg = ep->driver_data;
  36269. + struct fsg_buffhd *bh = req->context;
  36270. +
  36271. + if (req->status || req->actual != req->length)
  36272. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  36273. + req->status, req->actual, req->length);
  36274. + if (req->status == -ECONNRESET) // Request was cancelled
  36275. + usb_ep_fifo_flush(ep);
  36276. +
  36277. + /* Hold the lock while we update the request and buffer states */
  36278. + smp_wmb();
  36279. + spin_lock(&fsg->lock);
  36280. + fsg->intreq_busy = 0;
  36281. + bh->state = BUF_STATE_EMPTY;
  36282. + wakeup_thread(fsg);
  36283. + spin_unlock(&fsg->lock);
  36284. +}
  36285. +
  36286. +#else
  36287. +static void intr_in_complete(struct usb_ep *ep, struct usb_request *req)
  36288. +{}
  36289. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  36290. +
  36291. +
  36292. +/*-------------------------------------------------------------------------*/
  36293. +
  36294. +/* Ep0 class-specific handlers. These always run in_irq. */
  36295. +
  36296. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  36297. +static void received_cbi_adsc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  36298. +{
  36299. + struct usb_request *req = fsg->ep0req;
  36300. + static u8 cbi_reset_cmnd[6] = {
  36301. + SEND_DIAGNOSTIC, 4, 0xff, 0xff, 0xff, 0xff};
  36302. +
  36303. + /* Error in command transfer? */
  36304. + if (req->status || req->length != req->actual ||
  36305. + req->actual < 6 || req->actual > MAX_COMMAND_SIZE) {
  36306. +
  36307. + /* Not all controllers allow a protocol stall after
  36308. + * receiving control-out data, but we'll try anyway. */
  36309. + fsg_set_halt(fsg, fsg->ep0);
  36310. + return; // Wait for reset
  36311. + }
  36312. +
  36313. + /* Is it the special reset command? */
  36314. + if (req->actual >= sizeof cbi_reset_cmnd &&
  36315. + memcmp(req->buf, cbi_reset_cmnd,
  36316. + sizeof cbi_reset_cmnd) == 0) {
  36317. +
  36318. + /* Raise an exception to stop the current operation
  36319. + * and reinitialize our state. */
  36320. + DBG(fsg, "cbi reset request\n");
  36321. + raise_exception(fsg, FSG_STATE_RESET);
  36322. + return;
  36323. + }
  36324. +
  36325. + VDBG(fsg, "CB[I] accept device-specific command\n");
  36326. + spin_lock(&fsg->lock);
  36327. +
  36328. + /* Save the command for later */
  36329. + if (fsg->cbbuf_cmnd_size)
  36330. + WARNING(fsg, "CB[I] overwriting previous command\n");
  36331. + fsg->cbbuf_cmnd_size = req->actual;
  36332. + memcpy(fsg->cbbuf_cmnd, req->buf, fsg->cbbuf_cmnd_size);
  36333. +
  36334. + wakeup_thread(fsg);
  36335. + spin_unlock(&fsg->lock);
  36336. +}
  36337. +
  36338. +#else
  36339. +static void received_cbi_adsc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  36340. +{}
  36341. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  36342. +
  36343. +
  36344. +static int class_setup_req(struct fsg_dev *fsg,
  36345. + const struct usb_ctrlrequest *ctrl)
  36346. +{
  36347. + struct usb_request *req = fsg->ep0req;
  36348. + int value = -EOPNOTSUPP;
  36349. + u16 w_index = le16_to_cpu(ctrl->wIndex);
  36350. + u16 w_value = le16_to_cpu(ctrl->wValue);
  36351. + u16 w_length = le16_to_cpu(ctrl->wLength);
  36352. +
  36353. + if (!fsg->config)
  36354. + return value;
  36355. +
  36356. + /* Handle Bulk-only class-specific requests */
  36357. + if (transport_is_bbb()) {
  36358. + switch (ctrl->bRequest) {
  36359. +
  36360. + case US_BULK_RESET_REQUEST:
  36361. + if (ctrl->bRequestType != (USB_DIR_OUT |
  36362. + USB_TYPE_CLASS | USB_RECIP_INTERFACE))
  36363. + break;
  36364. + if (w_index != 0 || w_value != 0 || w_length != 0) {
  36365. + value = -EDOM;
  36366. + break;
  36367. + }
  36368. +
  36369. + /* Raise an exception to stop the current operation
  36370. + * and reinitialize our state. */
  36371. + DBG(fsg, "bulk reset request\n");
  36372. + raise_exception(fsg, FSG_STATE_RESET);
  36373. + value = DELAYED_STATUS;
  36374. + break;
  36375. +
  36376. + case US_BULK_GET_MAX_LUN:
  36377. + if (ctrl->bRequestType != (USB_DIR_IN |
  36378. + USB_TYPE_CLASS | USB_RECIP_INTERFACE))
  36379. + break;
  36380. + if (w_index != 0 || w_value != 0 || w_length != 1) {
  36381. + value = -EDOM;
  36382. + break;
  36383. + }
  36384. + VDBG(fsg, "get max LUN\n");
  36385. + *(u8 *) req->buf = fsg->nluns - 1;
  36386. + value = 1;
  36387. + break;
  36388. + }
  36389. + }
  36390. +
  36391. + /* Handle CBI class-specific requests */
  36392. + else {
  36393. + switch (ctrl->bRequest) {
  36394. +
  36395. + case USB_CBI_ADSC_REQUEST:
  36396. + if (ctrl->bRequestType != (USB_DIR_OUT |
  36397. + USB_TYPE_CLASS | USB_RECIP_INTERFACE))
  36398. + break;
  36399. + if (w_index != 0 || w_value != 0) {
  36400. + value = -EDOM;
  36401. + break;
  36402. + }
  36403. + if (w_length > MAX_COMMAND_SIZE) {
  36404. + value = -EOVERFLOW;
  36405. + break;
  36406. + }
  36407. + value = w_length;
  36408. + fsg->ep0req->context = received_cbi_adsc;
  36409. + break;
  36410. + }
  36411. + }
  36412. +
  36413. + if (value == -EOPNOTSUPP)
  36414. + VDBG(fsg,
  36415. + "unknown class-specific control req "
  36416. + "%02x.%02x v%04x i%04x l%u\n",
  36417. + ctrl->bRequestType, ctrl->bRequest,
  36418. + le16_to_cpu(ctrl->wValue), w_index, w_length);
  36419. + return value;
  36420. +}
  36421. +
  36422. +
  36423. +/*-------------------------------------------------------------------------*/
  36424. +
  36425. +/* Ep0 standard request handlers. These always run in_irq. */
  36426. +
  36427. +static int standard_setup_req(struct fsg_dev *fsg,
  36428. + const struct usb_ctrlrequest *ctrl)
  36429. +{
  36430. + struct usb_request *req = fsg->ep0req;
  36431. + int value = -EOPNOTSUPP;
  36432. + u16 w_index = le16_to_cpu(ctrl->wIndex);
  36433. + u16 w_value = le16_to_cpu(ctrl->wValue);
  36434. +
  36435. + /* Usually this just stores reply data in the pre-allocated ep0 buffer,
  36436. + * but config change events will also reconfigure hardware. */
  36437. + switch (ctrl->bRequest) {
  36438. +
  36439. + case USB_REQ_GET_DESCRIPTOR:
  36440. + if (ctrl->bRequestType != (USB_DIR_IN | USB_TYPE_STANDARD |
  36441. + USB_RECIP_DEVICE))
  36442. + break;
  36443. + switch (w_value >> 8) {
  36444. +
  36445. + case USB_DT_DEVICE:
  36446. + VDBG(fsg, "get device descriptor\n");
  36447. + device_desc.bMaxPacketSize0 = fsg->ep0->maxpacket;
  36448. + value = sizeof device_desc;
  36449. + memcpy(req->buf, &device_desc, value);
  36450. + break;
  36451. + case USB_DT_DEVICE_QUALIFIER:
  36452. + VDBG(fsg, "get device qualifier\n");
  36453. + if (!gadget_is_dualspeed(fsg->gadget) ||
  36454. + fsg->gadget->speed == USB_SPEED_SUPER)
  36455. + break;
  36456. + /*
  36457. + * Assume ep0 uses the same maxpacket value for both
  36458. + * speeds
  36459. + */
  36460. + dev_qualifier.bMaxPacketSize0 = fsg->ep0->maxpacket;
  36461. + value = sizeof dev_qualifier;
  36462. + memcpy(req->buf, &dev_qualifier, value);
  36463. + break;
  36464. +
  36465. + case USB_DT_OTHER_SPEED_CONFIG:
  36466. + VDBG(fsg, "get other-speed config descriptor\n");
  36467. + if (!gadget_is_dualspeed(fsg->gadget) ||
  36468. + fsg->gadget->speed == USB_SPEED_SUPER)
  36469. + break;
  36470. + goto get_config;
  36471. + case USB_DT_CONFIG:
  36472. + VDBG(fsg, "get configuration descriptor\n");
  36473. +get_config:
  36474. + value = populate_config_buf(fsg->gadget,
  36475. + req->buf,
  36476. + w_value >> 8,
  36477. + w_value & 0xff);
  36478. + break;
  36479. +
  36480. + case USB_DT_STRING:
  36481. + VDBG(fsg, "get string descriptor\n");
  36482. +
  36483. + /* wIndex == language code */
  36484. + value = usb_gadget_get_string(&fsg_stringtab,
  36485. + w_value & 0xff, req->buf);
  36486. + break;
  36487. +
  36488. + case USB_DT_BOS:
  36489. + VDBG(fsg, "get bos descriptor\n");
  36490. +
  36491. + if (gadget_is_superspeed(fsg->gadget))
  36492. + value = populate_bos(fsg, req->buf);
  36493. + break;
  36494. + }
  36495. +
  36496. + break;
  36497. +
  36498. + /* One config, two speeds */
  36499. + case USB_REQ_SET_CONFIGURATION:
  36500. + if (ctrl->bRequestType != (USB_DIR_OUT | USB_TYPE_STANDARD |
  36501. + USB_RECIP_DEVICE))
  36502. + break;
  36503. + VDBG(fsg, "set configuration\n");
  36504. + if (w_value == CONFIG_VALUE || w_value == 0) {
  36505. + fsg->new_config = w_value;
  36506. +
  36507. + /* Raise an exception to wipe out previous transaction
  36508. + * state (queued bufs, etc) and set the new config. */
  36509. + raise_exception(fsg, FSG_STATE_CONFIG_CHANGE);
  36510. + value = DELAYED_STATUS;
  36511. + }
  36512. + break;
  36513. + case USB_REQ_GET_CONFIGURATION:
  36514. + if (ctrl->bRequestType != (USB_DIR_IN | USB_TYPE_STANDARD |
  36515. + USB_RECIP_DEVICE))
  36516. + break;
  36517. + VDBG(fsg, "get configuration\n");
  36518. + *(u8 *) req->buf = fsg->config;
  36519. + value = 1;
  36520. + break;
  36521. +
  36522. + case USB_REQ_SET_INTERFACE:
  36523. + if (ctrl->bRequestType != (USB_DIR_OUT| USB_TYPE_STANDARD |
  36524. + USB_RECIP_INTERFACE))
  36525. + break;
  36526. + if (fsg->config && w_index == 0) {
  36527. +
  36528. + /* Raise an exception to wipe out previous transaction
  36529. + * state (queued bufs, etc) and install the new
  36530. + * interface altsetting. */
  36531. + raise_exception(fsg, FSG_STATE_INTERFACE_CHANGE);
  36532. + value = DELAYED_STATUS;
  36533. + }
  36534. + break;
  36535. + case USB_REQ_GET_INTERFACE:
  36536. + if (ctrl->bRequestType != (USB_DIR_IN | USB_TYPE_STANDARD |
  36537. + USB_RECIP_INTERFACE))
  36538. + break;
  36539. + if (!fsg->config)
  36540. + break;
  36541. + if (w_index != 0) {
  36542. + value = -EDOM;
  36543. + break;
  36544. + }
  36545. + VDBG(fsg, "get interface\n");
  36546. + *(u8 *) req->buf = 0;
  36547. + value = 1;
  36548. + break;
  36549. +
  36550. + default:
  36551. + VDBG(fsg,
  36552. + "unknown control req %02x.%02x v%04x i%04x l%u\n",
  36553. + ctrl->bRequestType, ctrl->bRequest,
  36554. + w_value, w_index, le16_to_cpu(ctrl->wLength));
  36555. + }
  36556. +
  36557. + return value;
  36558. +}
  36559. +
  36560. +
  36561. +static int fsg_setup(struct usb_gadget *gadget,
  36562. + const struct usb_ctrlrequest *ctrl)
  36563. +{
  36564. + struct fsg_dev *fsg = get_gadget_data(gadget);
  36565. + int rc;
  36566. + int w_length = le16_to_cpu(ctrl->wLength);
  36567. +
  36568. + ++fsg->ep0_req_tag; // Record arrival of a new request
  36569. + fsg->ep0req->context = NULL;
  36570. + fsg->ep0req->length = 0;
  36571. + dump_msg(fsg, "ep0-setup", (u8 *) ctrl, sizeof(*ctrl));
  36572. +
  36573. + if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_CLASS)
  36574. + rc = class_setup_req(fsg, ctrl);
  36575. + else
  36576. + rc = standard_setup_req(fsg, ctrl);
  36577. +
  36578. + /* Respond with data/status or defer until later? */
  36579. + if (rc >= 0 && rc != DELAYED_STATUS) {
  36580. + rc = min(rc, w_length);
  36581. + fsg->ep0req->length = rc;
  36582. + fsg->ep0req->zero = rc < w_length;
  36583. + fsg->ep0req_name = (ctrl->bRequestType & USB_DIR_IN ?
  36584. + "ep0-in" : "ep0-out");
  36585. + rc = ep0_queue(fsg);
  36586. + }
  36587. +
  36588. + /* Device either stalls (rc < 0) or reports success */
  36589. + return rc;
  36590. +}
  36591. +
  36592. +
  36593. +/*-------------------------------------------------------------------------*/
  36594. +
  36595. +/* All the following routines run in process context */
  36596. +
  36597. +
  36598. +/* Use this for bulk or interrupt transfers, not ep0 */
  36599. +static void start_transfer(struct fsg_dev *fsg, struct usb_ep *ep,
  36600. + struct usb_request *req, int *pbusy,
  36601. + enum fsg_buffer_state *state)
  36602. +{
  36603. + int rc;
  36604. +
  36605. + if (ep == fsg->bulk_in)
  36606. + dump_msg(fsg, "bulk-in", req->buf, req->length);
  36607. + else if (ep == fsg->intr_in)
  36608. + dump_msg(fsg, "intr-in", req->buf, req->length);
  36609. +
  36610. + spin_lock_irq(&fsg->lock);
  36611. + *pbusy = 1;
  36612. + *state = BUF_STATE_BUSY;
  36613. + spin_unlock_irq(&fsg->lock);
  36614. + rc = usb_ep_queue(ep, req, GFP_KERNEL);
  36615. + if (rc != 0) {
  36616. + *pbusy = 0;
  36617. + *state = BUF_STATE_EMPTY;
  36618. +
  36619. + /* We can't do much more than wait for a reset */
  36620. +
  36621. + /* Note: currently the net2280 driver fails zero-length
  36622. + * submissions if DMA is enabled. */
  36623. + if (rc != -ESHUTDOWN && !(rc == -EOPNOTSUPP &&
  36624. + req->length == 0))
  36625. + WARNING(fsg, "error in submission: %s --> %d\n",
  36626. + ep->name, rc);
  36627. + }
  36628. +}
  36629. +
  36630. +
  36631. +static int sleep_thread(struct fsg_dev *fsg)
  36632. +{
  36633. + int rc = 0;
  36634. +
  36635. + /* Wait until a signal arrives or we are woken up */
  36636. + for (;;) {
  36637. + try_to_freeze();
  36638. + set_current_state(TASK_INTERRUPTIBLE);
  36639. + if (signal_pending(current)) {
  36640. + rc = -EINTR;
  36641. + break;
  36642. + }
  36643. + if (fsg->thread_wakeup_needed)
  36644. + break;
  36645. + schedule();
  36646. + }
  36647. + __set_current_state(TASK_RUNNING);
  36648. + fsg->thread_wakeup_needed = 0;
  36649. + return rc;
  36650. +}
  36651. +
  36652. +
  36653. +/*-------------------------------------------------------------------------*/
  36654. +
  36655. +static int do_read(struct fsg_dev *fsg)
  36656. +{
  36657. + struct fsg_lun *curlun = fsg->curlun;
  36658. + u32 lba;
  36659. + struct fsg_buffhd *bh;
  36660. + int rc;
  36661. + u32 amount_left;
  36662. + loff_t file_offset, file_offset_tmp;
  36663. + unsigned int amount;
  36664. + ssize_t nread;
  36665. +
  36666. + /* Get the starting Logical Block Address and check that it's
  36667. + * not too big */
  36668. + if (fsg->cmnd[0] == READ_6)
  36669. + lba = get_unaligned_be24(&fsg->cmnd[1]);
  36670. + else {
  36671. + lba = get_unaligned_be32(&fsg->cmnd[2]);
  36672. +
  36673. + /* We allow DPO (Disable Page Out = don't save data in the
  36674. + * cache) and FUA (Force Unit Access = don't read from the
  36675. + * cache), but we don't implement them. */
  36676. + if ((fsg->cmnd[1] & ~0x18) != 0) {
  36677. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36678. + return -EINVAL;
  36679. + }
  36680. + }
  36681. + if (lba >= curlun->num_sectors) {
  36682. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  36683. + return -EINVAL;
  36684. + }
  36685. + file_offset = ((loff_t) lba) << curlun->blkbits;
  36686. +
  36687. + /* Carry out the file reads */
  36688. + amount_left = fsg->data_size_from_cmnd;
  36689. + if (unlikely(amount_left == 0))
  36690. + return -EIO; // No default reply
  36691. +
  36692. + for (;;) {
  36693. +
  36694. + /* Figure out how much we need to read:
  36695. + * Try to read the remaining amount.
  36696. + * But don't read more than the buffer size.
  36697. + * And don't try to read past the end of the file.
  36698. + */
  36699. + amount = min((unsigned int) amount_left, mod_data.buflen);
  36700. + amount = min((loff_t) amount,
  36701. + curlun->file_length - file_offset);
  36702. +
  36703. + /* Wait for the next buffer to become available */
  36704. + bh = fsg->next_buffhd_to_fill;
  36705. + while (bh->state != BUF_STATE_EMPTY) {
  36706. + rc = sleep_thread(fsg);
  36707. + if (rc)
  36708. + return rc;
  36709. + }
  36710. +
  36711. + /* If we were asked to read past the end of file,
  36712. + * end with an empty buffer. */
  36713. + if (amount == 0) {
  36714. + curlun->sense_data =
  36715. + SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  36716. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  36717. + curlun->info_valid = 1;
  36718. + bh->inreq->length = 0;
  36719. + bh->state = BUF_STATE_FULL;
  36720. + break;
  36721. + }
  36722. +
  36723. + /* Perform the read */
  36724. + file_offset_tmp = file_offset;
  36725. + nread = vfs_read(curlun->filp,
  36726. + (char __user *) bh->buf,
  36727. + amount, &file_offset_tmp);
  36728. + VLDBG(curlun, "file read %u @ %llu -> %d\n", amount,
  36729. + (unsigned long long) file_offset,
  36730. + (int) nread);
  36731. + if (signal_pending(current))
  36732. + return -EINTR;
  36733. +
  36734. + if (nread < 0) {
  36735. + LDBG(curlun, "error in file read: %d\n",
  36736. + (int) nread);
  36737. + nread = 0;
  36738. + } else if (nread < amount) {
  36739. + LDBG(curlun, "partial file read: %d/%u\n",
  36740. + (int) nread, amount);
  36741. + nread = round_down(nread, curlun->blksize);
  36742. + }
  36743. + file_offset += nread;
  36744. + amount_left -= nread;
  36745. + fsg->residue -= nread;
  36746. +
  36747. + /* Except at the end of the transfer, nread will be
  36748. + * equal to the buffer size, which is divisible by the
  36749. + * bulk-in maxpacket size.
  36750. + */
  36751. + bh->inreq->length = nread;
  36752. + bh->state = BUF_STATE_FULL;
  36753. +
  36754. + /* If an error occurred, report it and its position */
  36755. + if (nread < amount) {
  36756. + curlun->sense_data = SS_UNRECOVERED_READ_ERROR;
  36757. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  36758. + curlun->info_valid = 1;
  36759. + break;
  36760. + }
  36761. +
  36762. + if (amount_left == 0)
  36763. + break; // No more left to read
  36764. +
  36765. + /* Send this buffer and go read some more */
  36766. + bh->inreq->zero = 0;
  36767. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  36768. + &bh->inreq_busy, &bh->state);
  36769. + fsg->next_buffhd_to_fill = bh->next;
  36770. + }
  36771. +
  36772. + return -EIO; // No default reply
  36773. +}
  36774. +
  36775. +
  36776. +/*-------------------------------------------------------------------------*/
  36777. +
  36778. +static int do_write(struct fsg_dev *fsg)
  36779. +{
  36780. + struct fsg_lun *curlun = fsg->curlun;
  36781. + u32 lba;
  36782. + struct fsg_buffhd *bh;
  36783. + int get_some_more;
  36784. + u32 amount_left_to_req, amount_left_to_write;
  36785. + loff_t usb_offset, file_offset, file_offset_tmp;
  36786. + unsigned int amount;
  36787. + ssize_t nwritten;
  36788. + int rc;
  36789. +
  36790. + if (curlun->ro) {
  36791. + curlun->sense_data = SS_WRITE_PROTECTED;
  36792. + return -EINVAL;
  36793. + }
  36794. + spin_lock(&curlun->filp->f_lock);
  36795. + curlun->filp->f_flags &= ~O_SYNC; // Default is not to wait
  36796. + spin_unlock(&curlun->filp->f_lock);
  36797. +
  36798. + /* Get the starting Logical Block Address and check that it's
  36799. + * not too big */
  36800. + if (fsg->cmnd[0] == WRITE_6)
  36801. + lba = get_unaligned_be24(&fsg->cmnd[1]);
  36802. + else {
  36803. + lba = get_unaligned_be32(&fsg->cmnd[2]);
  36804. +
  36805. + /* We allow DPO (Disable Page Out = don't save data in the
  36806. + * cache) and FUA (Force Unit Access = write directly to the
  36807. + * medium). We don't implement DPO; we implement FUA by
  36808. + * performing synchronous output. */
  36809. + if ((fsg->cmnd[1] & ~0x18) != 0) {
  36810. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36811. + return -EINVAL;
  36812. + }
  36813. + /* FUA */
  36814. + if (!curlun->nofua && (fsg->cmnd[1] & 0x08)) {
  36815. + spin_lock(&curlun->filp->f_lock);
  36816. + curlun->filp->f_flags |= O_DSYNC;
  36817. + spin_unlock(&curlun->filp->f_lock);
  36818. + }
  36819. + }
  36820. + if (lba >= curlun->num_sectors) {
  36821. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  36822. + return -EINVAL;
  36823. + }
  36824. +
  36825. + /* Carry out the file writes */
  36826. + get_some_more = 1;
  36827. + file_offset = usb_offset = ((loff_t) lba) << curlun->blkbits;
  36828. + amount_left_to_req = amount_left_to_write = fsg->data_size_from_cmnd;
  36829. +
  36830. + while (amount_left_to_write > 0) {
  36831. +
  36832. + /* Queue a request for more data from the host */
  36833. + bh = fsg->next_buffhd_to_fill;
  36834. + if (bh->state == BUF_STATE_EMPTY && get_some_more) {
  36835. +
  36836. + /* Figure out how much we want to get:
  36837. + * Try to get the remaining amount,
  36838. + * but not more than the buffer size.
  36839. + */
  36840. + amount = min(amount_left_to_req, mod_data.buflen);
  36841. +
  36842. + /* Beyond the end of the backing file? */
  36843. + if (usb_offset >= curlun->file_length) {
  36844. + get_some_more = 0;
  36845. + curlun->sense_data =
  36846. + SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  36847. + curlun->sense_data_info = usb_offset >> curlun->blkbits;
  36848. + curlun->info_valid = 1;
  36849. + continue;
  36850. + }
  36851. +
  36852. + /* Get the next buffer */
  36853. + usb_offset += amount;
  36854. + fsg->usb_amount_left -= amount;
  36855. + amount_left_to_req -= amount;
  36856. + if (amount_left_to_req == 0)
  36857. + get_some_more = 0;
  36858. +
  36859. + /* Except at the end of the transfer, amount will be
  36860. + * equal to the buffer size, which is divisible by
  36861. + * the bulk-out maxpacket size.
  36862. + */
  36863. + set_bulk_out_req_length(fsg, bh, amount);
  36864. + start_transfer(fsg, fsg->bulk_out, bh->outreq,
  36865. + &bh->outreq_busy, &bh->state);
  36866. + fsg->next_buffhd_to_fill = bh->next;
  36867. + continue;
  36868. + }
  36869. +
  36870. + /* Write the received data to the backing file */
  36871. + bh = fsg->next_buffhd_to_drain;
  36872. + if (bh->state == BUF_STATE_EMPTY && !get_some_more)
  36873. + break; // We stopped early
  36874. + if (bh->state == BUF_STATE_FULL) {
  36875. + smp_rmb();
  36876. + fsg->next_buffhd_to_drain = bh->next;
  36877. + bh->state = BUF_STATE_EMPTY;
  36878. +
  36879. + /* Did something go wrong with the transfer? */
  36880. + if (bh->outreq->status != 0) {
  36881. + curlun->sense_data = SS_COMMUNICATION_FAILURE;
  36882. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  36883. + curlun->info_valid = 1;
  36884. + break;
  36885. + }
  36886. +
  36887. + amount = bh->outreq->actual;
  36888. + if (curlun->file_length - file_offset < amount) {
  36889. + LERROR(curlun,
  36890. + "write %u @ %llu beyond end %llu\n",
  36891. + amount, (unsigned long long) file_offset,
  36892. + (unsigned long long) curlun->file_length);
  36893. + amount = curlun->file_length - file_offset;
  36894. + }
  36895. +
  36896. + /* Don't accept excess data. The spec doesn't say
  36897. + * what to do in this case. We'll ignore the error.
  36898. + */
  36899. + amount = min(amount, bh->bulk_out_intended_length);
  36900. +
  36901. + /* Don't write a partial block */
  36902. + amount = round_down(amount, curlun->blksize);
  36903. + if (amount == 0)
  36904. + goto empty_write;
  36905. +
  36906. + /* Perform the write */
  36907. + file_offset_tmp = file_offset;
  36908. + nwritten = vfs_write(curlun->filp,
  36909. + (char __user *) bh->buf,
  36910. + amount, &file_offset_tmp);
  36911. + VLDBG(curlun, "file write %u @ %llu -> %d\n", amount,
  36912. + (unsigned long long) file_offset,
  36913. + (int) nwritten);
  36914. + if (signal_pending(current))
  36915. + return -EINTR; // Interrupted!
  36916. +
  36917. + if (nwritten < 0) {
  36918. + LDBG(curlun, "error in file write: %d\n",
  36919. + (int) nwritten);
  36920. + nwritten = 0;
  36921. + } else if (nwritten < amount) {
  36922. + LDBG(curlun, "partial file write: %d/%u\n",
  36923. + (int) nwritten, amount);
  36924. + nwritten = round_down(nwritten, curlun->blksize);
  36925. + }
  36926. + file_offset += nwritten;
  36927. + amount_left_to_write -= nwritten;
  36928. + fsg->residue -= nwritten;
  36929. +
  36930. + /* If an error occurred, report it and its position */
  36931. + if (nwritten < amount) {
  36932. + curlun->sense_data = SS_WRITE_ERROR;
  36933. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  36934. + curlun->info_valid = 1;
  36935. + break;
  36936. + }
  36937. +
  36938. + empty_write:
  36939. + /* Did the host decide to stop early? */
  36940. + if (bh->outreq->actual < bh->bulk_out_intended_length) {
  36941. + fsg->short_packet_received = 1;
  36942. + break;
  36943. + }
  36944. + continue;
  36945. + }
  36946. +
  36947. + /* Wait for something to happen */
  36948. + rc = sleep_thread(fsg);
  36949. + if (rc)
  36950. + return rc;
  36951. + }
  36952. +
  36953. + return -EIO; // No default reply
  36954. +}
  36955. +
  36956. +
  36957. +/*-------------------------------------------------------------------------*/
  36958. +
  36959. +static int do_synchronize_cache(struct fsg_dev *fsg)
  36960. +{
  36961. + struct fsg_lun *curlun = fsg->curlun;
  36962. + int rc;
  36963. +
  36964. + /* We ignore the requested LBA and write out all file's
  36965. + * dirty data buffers. */
  36966. + rc = fsg_lun_fsync_sub(curlun);
  36967. + if (rc)
  36968. + curlun->sense_data = SS_WRITE_ERROR;
  36969. + return 0;
  36970. +}
  36971. +
  36972. +
  36973. +/*-------------------------------------------------------------------------*/
  36974. +
  36975. +static void invalidate_sub(struct fsg_lun *curlun)
  36976. +{
  36977. + struct file *filp = curlun->filp;
  36978. + struct inode *inode = filp->f_path.dentry->d_inode;
  36979. + unsigned long rc;
  36980. +
  36981. + rc = invalidate_mapping_pages(inode->i_mapping, 0, -1);
  36982. + VLDBG(curlun, "invalidate_mapping_pages -> %ld\n", rc);
  36983. +}
  36984. +
  36985. +static int do_verify(struct fsg_dev *fsg)
  36986. +{
  36987. + struct fsg_lun *curlun = fsg->curlun;
  36988. + u32 lba;
  36989. + u32 verification_length;
  36990. + struct fsg_buffhd *bh = fsg->next_buffhd_to_fill;
  36991. + loff_t file_offset, file_offset_tmp;
  36992. + u32 amount_left;
  36993. + unsigned int amount;
  36994. + ssize_t nread;
  36995. +
  36996. + /* Get the starting Logical Block Address and check that it's
  36997. + * not too big */
  36998. + lba = get_unaligned_be32(&fsg->cmnd[2]);
  36999. + if (lba >= curlun->num_sectors) {
  37000. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  37001. + return -EINVAL;
  37002. + }
  37003. +
  37004. + /* We allow DPO (Disable Page Out = don't save data in the
  37005. + * cache) but we don't implement it. */
  37006. + if ((fsg->cmnd[1] & ~0x10) != 0) {
  37007. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  37008. + return -EINVAL;
  37009. + }
  37010. +
  37011. + verification_length = get_unaligned_be16(&fsg->cmnd[7]);
  37012. + if (unlikely(verification_length == 0))
  37013. + return -EIO; // No default reply
  37014. +
  37015. + /* Prepare to carry out the file verify */
  37016. + amount_left = verification_length << curlun->blkbits;
  37017. + file_offset = ((loff_t) lba) << curlun->blkbits;
  37018. +
  37019. + /* Write out all the dirty buffers before invalidating them */
  37020. + fsg_lun_fsync_sub(curlun);
  37021. + if (signal_pending(current))
  37022. + return -EINTR;
  37023. +
  37024. + invalidate_sub(curlun);
  37025. + if (signal_pending(current))
  37026. + return -EINTR;
  37027. +
  37028. + /* Just try to read the requested blocks */
  37029. + while (amount_left > 0) {
  37030. +
  37031. + /* Figure out how much we need to read:
  37032. + * Try to read the remaining amount, but not more than
  37033. + * the buffer size.
  37034. + * And don't try to read past the end of the file.
  37035. + */
  37036. + amount = min((unsigned int) amount_left, mod_data.buflen);
  37037. + amount = min((loff_t) amount,
  37038. + curlun->file_length - file_offset);
  37039. + if (amount == 0) {
  37040. + curlun->sense_data =
  37041. + SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  37042. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  37043. + curlun->info_valid = 1;
  37044. + break;
  37045. + }
  37046. +
  37047. + /* Perform the read */
  37048. + file_offset_tmp = file_offset;
  37049. + nread = vfs_read(curlun->filp,
  37050. + (char __user *) bh->buf,
  37051. + amount, &file_offset_tmp);
  37052. + VLDBG(curlun, "file read %u @ %llu -> %d\n", amount,
  37053. + (unsigned long long) file_offset,
  37054. + (int) nread);
  37055. + if (signal_pending(current))
  37056. + return -EINTR;
  37057. +
  37058. + if (nread < 0) {
  37059. + LDBG(curlun, "error in file verify: %d\n",
  37060. + (int) nread);
  37061. + nread = 0;
  37062. + } else if (nread < amount) {
  37063. + LDBG(curlun, "partial file verify: %d/%u\n",
  37064. + (int) nread, amount);
  37065. + nread = round_down(nread, curlun->blksize);
  37066. + }
  37067. + if (nread == 0) {
  37068. + curlun->sense_data = SS_UNRECOVERED_READ_ERROR;
  37069. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  37070. + curlun->info_valid = 1;
  37071. + break;
  37072. + }
  37073. + file_offset += nread;
  37074. + amount_left -= nread;
  37075. + }
  37076. + return 0;
  37077. +}
  37078. +
  37079. +
  37080. +/*-------------------------------------------------------------------------*/
  37081. +
  37082. +static int do_inquiry(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  37083. +{
  37084. + u8 *buf = (u8 *) bh->buf;
  37085. +
  37086. + static char vendor_id[] = "Linux ";
  37087. + static char product_disk_id[] = "File-Stor Gadget";
  37088. + static char product_cdrom_id[] = "File-CD Gadget ";
  37089. +
  37090. + if (!fsg->curlun) { // Unsupported LUNs are okay
  37091. + fsg->bad_lun_okay = 1;
  37092. + memset(buf, 0, 36);
  37093. + buf[0] = 0x7f; // Unsupported, no device-type
  37094. + buf[4] = 31; // Additional length
  37095. + return 36;
  37096. + }
  37097. +
  37098. + memset(buf, 0, 8);
  37099. + buf[0] = (mod_data.cdrom ? TYPE_ROM : TYPE_DISK);
  37100. + if (mod_data.removable)
  37101. + buf[1] = 0x80;
  37102. + buf[2] = 2; // ANSI SCSI level 2
  37103. + buf[3] = 2; // SCSI-2 INQUIRY data format
  37104. + buf[4] = 31; // Additional length
  37105. + // No special options
  37106. + sprintf(buf + 8, "%-8s%-16s%04x", vendor_id,
  37107. + (mod_data.cdrom ? product_cdrom_id :
  37108. + product_disk_id),
  37109. + mod_data.release);
  37110. + return 36;
  37111. +}
  37112. +
  37113. +
  37114. +static int do_request_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  37115. +{
  37116. + struct fsg_lun *curlun = fsg->curlun;
  37117. + u8 *buf = (u8 *) bh->buf;
  37118. + u32 sd, sdinfo;
  37119. + int valid;
  37120. +
  37121. + /*
  37122. + * From the SCSI-2 spec., section 7.9 (Unit attention condition):
  37123. + *
  37124. + * If a REQUEST SENSE command is received from an initiator
  37125. + * with a pending unit attention condition (before the target
  37126. + * generates the contingent allegiance condition), then the
  37127. + * target shall either:
  37128. + * a) report any pending sense data and preserve the unit
  37129. + * attention condition on the logical unit, or,
  37130. + * b) report the unit attention condition, may discard any
  37131. + * pending sense data, and clear the unit attention
  37132. + * condition on the logical unit for that initiator.
  37133. + *
  37134. + * FSG normally uses option a); enable this code to use option b).
  37135. + */
  37136. +#if 0
  37137. + if (curlun && curlun->unit_attention_data != SS_NO_SENSE) {
  37138. + curlun->sense_data = curlun->unit_attention_data;
  37139. + curlun->unit_attention_data = SS_NO_SENSE;
  37140. + }
  37141. +#endif
  37142. +
  37143. + if (!curlun) { // Unsupported LUNs are okay
  37144. + fsg->bad_lun_okay = 1;
  37145. + sd = SS_LOGICAL_UNIT_NOT_SUPPORTED;
  37146. + sdinfo = 0;
  37147. + valid = 0;
  37148. + } else {
  37149. + sd = curlun->sense_data;
  37150. + sdinfo = curlun->sense_data_info;
  37151. + valid = curlun->info_valid << 7;
  37152. + curlun->sense_data = SS_NO_SENSE;
  37153. + curlun->sense_data_info = 0;
  37154. + curlun->info_valid = 0;
  37155. + }
  37156. +
  37157. + memset(buf, 0, 18);
  37158. + buf[0] = valid | 0x70; // Valid, current error
  37159. + buf[2] = SK(sd);
  37160. + put_unaligned_be32(sdinfo, &buf[3]); /* Sense information */
  37161. + buf[7] = 18 - 8; // Additional sense length
  37162. + buf[12] = ASC(sd);
  37163. + buf[13] = ASCQ(sd);
  37164. + return 18;
  37165. +}
  37166. +
  37167. +
  37168. +static int do_read_capacity(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  37169. +{
  37170. + struct fsg_lun *curlun = fsg->curlun;
  37171. + u32 lba = get_unaligned_be32(&fsg->cmnd[2]);
  37172. + int pmi = fsg->cmnd[8];
  37173. + u8 *buf = (u8 *) bh->buf;
  37174. +
  37175. + /* Check the PMI and LBA fields */
  37176. + if (pmi > 1 || (pmi == 0 && lba != 0)) {
  37177. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  37178. + return -EINVAL;
  37179. + }
  37180. +
  37181. + put_unaligned_be32(curlun->num_sectors - 1, &buf[0]);
  37182. + /* Max logical block */
  37183. + put_unaligned_be32(curlun->blksize, &buf[4]); /* Block length */
  37184. + return 8;
  37185. +}
  37186. +
  37187. +
  37188. +static int do_read_header(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  37189. +{
  37190. + struct fsg_lun *curlun = fsg->curlun;
  37191. + int msf = fsg->cmnd[1] & 0x02;
  37192. + u32 lba = get_unaligned_be32(&fsg->cmnd[2]);
  37193. + u8 *buf = (u8 *) bh->buf;
  37194. +
  37195. + if ((fsg->cmnd[1] & ~0x02) != 0) { /* Mask away MSF */
  37196. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  37197. + return -EINVAL;
  37198. + }
  37199. + if (lba >= curlun->num_sectors) {
  37200. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  37201. + return -EINVAL;
  37202. + }
  37203. +
  37204. + memset(buf, 0, 8);
  37205. + buf[0] = 0x01; /* 2048 bytes of user data, rest is EC */
  37206. + store_cdrom_address(&buf[4], msf, lba);
  37207. + return 8;
  37208. +}
  37209. +
  37210. +
  37211. +static int do_read_toc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  37212. +{
  37213. + struct fsg_lun *curlun = fsg->curlun;
  37214. + int msf = fsg->cmnd[1] & 0x02;
  37215. + int start_track = fsg->cmnd[6];
  37216. + u8 *buf = (u8 *) bh->buf;
  37217. +
  37218. + if ((fsg->cmnd[1] & ~0x02) != 0 || /* Mask away MSF */
  37219. + start_track > 1) {
  37220. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  37221. + return -EINVAL;
  37222. + }
  37223. +
  37224. + memset(buf, 0, 20);
  37225. + buf[1] = (20-2); /* TOC data length */
  37226. + buf[2] = 1; /* First track number */
  37227. + buf[3] = 1; /* Last track number */
  37228. + buf[5] = 0x16; /* Data track, copying allowed */
  37229. + buf[6] = 0x01; /* Only track is number 1 */
  37230. + store_cdrom_address(&buf[8], msf, 0);
  37231. +
  37232. + buf[13] = 0x16; /* Lead-out track is data */
  37233. + buf[14] = 0xAA; /* Lead-out track number */
  37234. + store_cdrom_address(&buf[16], msf, curlun->num_sectors);
  37235. + return 20;
  37236. +}
  37237. +
  37238. +
  37239. +static int do_mode_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  37240. +{
  37241. + struct fsg_lun *curlun = fsg->curlun;
  37242. + int mscmnd = fsg->cmnd[0];
  37243. + u8 *buf = (u8 *) bh->buf;
  37244. + u8 *buf0 = buf;
  37245. + int pc, page_code;
  37246. + int changeable_values, all_pages;
  37247. + int valid_page = 0;
  37248. + int len, limit;
  37249. +
  37250. + if ((fsg->cmnd[1] & ~0x08) != 0) { // Mask away DBD
  37251. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  37252. + return -EINVAL;
  37253. + }
  37254. + pc = fsg->cmnd[2] >> 6;
  37255. + page_code = fsg->cmnd[2] & 0x3f;
  37256. + if (pc == 3) {
  37257. + curlun->sense_data = SS_SAVING_PARAMETERS_NOT_SUPPORTED;
  37258. + return -EINVAL;
  37259. + }
  37260. + changeable_values = (pc == 1);
  37261. + all_pages = (page_code == 0x3f);
  37262. +
  37263. + /* Write the mode parameter header. Fixed values are: default
  37264. + * medium type, no cache control (DPOFUA), and no block descriptors.
  37265. + * The only variable value is the WriteProtect bit. We will fill in
  37266. + * the mode data length later. */
  37267. + memset(buf, 0, 8);
  37268. + if (mscmnd == MODE_SENSE) {
  37269. + buf[2] = (curlun->ro ? 0x80 : 0x00); // WP, DPOFUA
  37270. + buf += 4;
  37271. + limit = 255;
  37272. + } else { // MODE_SENSE_10
  37273. + buf[3] = (curlun->ro ? 0x80 : 0x00); // WP, DPOFUA
  37274. + buf += 8;
  37275. + limit = 65535; // Should really be mod_data.buflen
  37276. + }
  37277. +
  37278. + /* No block descriptors */
  37279. +
  37280. + /* The mode pages, in numerical order. The only page we support
  37281. + * is the Caching page. */
  37282. + if (page_code == 0x08 || all_pages) {
  37283. + valid_page = 1;
  37284. + buf[0] = 0x08; // Page code
  37285. + buf[1] = 10; // Page length
  37286. + memset(buf+2, 0, 10); // None of the fields are changeable
  37287. +
  37288. + if (!changeable_values) {
  37289. + buf[2] = 0x04; // Write cache enable,
  37290. + // Read cache not disabled
  37291. + // No cache retention priorities
  37292. + put_unaligned_be16(0xffff, &buf[4]);
  37293. + /* Don't disable prefetch */
  37294. + /* Minimum prefetch = 0 */
  37295. + put_unaligned_be16(0xffff, &buf[8]);
  37296. + /* Maximum prefetch */
  37297. + put_unaligned_be16(0xffff, &buf[10]);
  37298. + /* Maximum prefetch ceiling */
  37299. + }
  37300. + buf += 12;
  37301. + }
  37302. +
  37303. + /* Check that a valid page was requested and the mode data length
  37304. + * isn't too long. */
  37305. + len = buf - buf0;
  37306. + if (!valid_page || len > limit) {
  37307. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  37308. + return -EINVAL;
  37309. + }
  37310. +
  37311. + /* Store the mode data length */
  37312. + if (mscmnd == MODE_SENSE)
  37313. + buf0[0] = len - 1;
  37314. + else
  37315. + put_unaligned_be16(len - 2, buf0);
  37316. + return len;
  37317. +}
  37318. +
  37319. +
  37320. +static int do_start_stop(struct fsg_dev *fsg)
  37321. +{
  37322. + struct fsg_lun *curlun = fsg->curlun;
  37323. + int loej, start;
  37324. +
  37325. + if (!mod_data.removable) {
  37326. + curlun->sense_data = SS_INVALID_COMMAND;
  37327. + return -EINVAL;
  37328. + }
  37329. +
  37330. + // int immed = fsg->cmnd[1] & 0x01;
  37331. + loej = fsg->cmnd[4] & 0x02;
  37332. + start = fsg->cmnd[4] & 0x01;
  37333. +
  37334. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  37335. + if ((fsg->cmnd[1] & ~0x01) != 0 || // Mask away Immed
  37336. + (fsg->cmnd[4] & ~0x03) != 0) { // Mask LoEj, Start
  37337. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  37338. + return -EINVAL;
  37339. + }
  37340. +
  37341. + if (!start) {
  37342. +
  37343. + /* Are we allowed to unload the media? */
  37344. + if (curlun->prevent_medium_removal) {
  37345. + LDBG(curlun, "unload attempt prevented\n");
  37346. + curlun->sense_data = SS_MEDIUM_REMOVAL_PREVENTED;
  37347. + return -EINVAL;
  37348. + }
  37349. + if (loej) { // Simulate an unload/eject
  37350. + up_read(&fsg->filesem);
  37351. + down_write(&fsg->filesem);
  37352. + fsg_lun_close(curlun);
  37353. + up_write(&fsg->filesem);
  37354. + down_read(&fsg->filesem);
  37355. + }
  37356. + } else {
  37357. +
  37358. + /* Our emulation doesn't support mounting; the medium is
  37359. + * available for use as soon as it is loaded. */
  37360. + if (!fsg_lun_is_open(curlun)) {
  37361. + curlun->sense_data = SS_MEDIUM_NOT_PRESENT;
  37362. + return -EINVAL;
  37363. + }
  37364. + }
  37365. +#endif
  37366. + return 0;
  37367. +}
  37368. +
  37369. +
  37370. +static int do_prevent_allow(struct fsg_dev *fsg)
  37371. +{
  37372. + struct fsg_lun *curlun = fsg->curlun;
  37373. + int prevent;
  37374. +
  37375. + if (!mod_data.removable) {
  37376. + curlun->sense_data = SS_INVALID_COMMAND;
  37377. + return -EINVAL;
  37378. + }
  37379. +
  37380. + prevent = fsg->cmnd[4] & 0x01;
  37381. + if ((fsg->cmnd[4] & ~0x01) != 0) { // Mask away Prevent
  37382. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  37383. + return -EINVAL;
  37384. + }
  37385. +
  37386. + if (curlun->prevent_medium_removal && !prevent)
  37387. + fsg_lun_fsync_sub(curlun);
  37388. + curlun->prevent_medium_removal = prevent;
  37389. + return 0;
  37390. +}
  37391. +
  37392. +
  37393. +static int do_read_format_capacities(struct fsg_dev *fsg,
  37394. + struct fsg_buffhd *bh)
  37395. +{
  37396. + struct fsg_lun *curlun = fsg->curlun;
  37397. + u8 *buf = (u8 *) bh->buf;
  37398. +
  37399. + buf[0] = buf[1] = buf[2] = 0;
  37400. + buf[3] = 8; // Only the Current/Maximum Capacity Descriptor
  37401. + buf += 4;
  37402. +
  37403. + put_unaligned_be32(curlun->num_sectors, &buf[0]);
  37404. + /* Number of blocks */
  37405. + put_unaligned_be32(curlun->blksize, &buf[4]); /* Block length */
  37406. + buf[4] = 0x02; /* Current capacity */
  37407. + return 12;
  37408. +}
  37409. +
  37410. +
  37411. +static int do_mode_select(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  37412. +{
  37413. + struct fsg_lun *curlun = fsg->curlun;
  37414. +
  37415. + /* We don't support MODE SELECT */
  37416. + curlun->sense_data = SS_INVALID_COMMAND;
  37417. + return -EINVAL;
  37418. +}
  37419. +
  37420. +
  37421. +/*-------------------------------------------------------------------------*/
  37422. +
  37423. +static int halt_bulk_in_endpoint(struct fsg_dev *fsg)
  37424. +{
  37425. + int rc;
  37426. +
  37427. + rc = fsg_set_halt(fsg, fsg->bulk_in);
  37428. + if (rc == -EAGAIN)
  37429. + VDBG(fsg, "delayed bulk-in endpoint halt\n");
  37430. + while (rc != 0) {
  37431. + if (rc != -EAGAIN) {
  37432. + WARNING(fsg, "usb_ep_set_halt -> %d\n", rc);
  37433. + rc = 0;
  37434. + break;
  37435. + }
  37436. +
  37437. + /* Wait for a short time and then try again */
  37438. + if (msleep_interruptible(100) != 0)
  37439. + return -EINTR;
  37440. + rc = usb_ep_set_halt(fsg->bulk_in);
  37441. + }
  37442. + return rc;
  37443. +}
  37444. +
  37445. +static int wedge_bulk_in_endpoint(struct fsg_dev *fsg)
  37446. +{
  37447. + int rc;
  37448. +
  37449. + DBG(fsg, "bulk-in set wedge\n");
  37450. + rc = usb_ep_set_wedge(fsg->bulk_in);
  37451. + if (rc == -EAGAIN)
  37452. + VDBG(fsg, "delayed bulk-in endpoint wedge\n");
  37453. + while (rc != 0) {
  37454. + if (rc != -EAGAIN) {
  37455. + WARNING(fsg, "usb_ep_set_wedge -> %d\n", rc);
  37456. + rc = 0;
  37457. + break;
  37458. + }
  37459. +
  37460. + /* Wait for a short time and then try again */
  37461. + if (msleep_interruptible(100) != 0)
  37462. + return -EINTR;
  37463. + rc = usb_ep_set_wedge(fsg->bulk_in);
  37464. + }
  37465. + return rc;
  37466. +}
  37467. +
  37468. +static int throw_away_data(struct fsg_dev *fsg)
  37469. +{
  37470. + struct fsg_buffhd *bh;
  37471. + u32 amount;
  37472. + int rc;
  37473. +
  37474. + while ((bh = fsg->next_buffhd_to_drain)->state != BUF_STATE_EMPTY ||
  37475. + fsg->usb_amount_left > 0) {
  37476. +
  37477. + /* Throw away the data in a filled buffer */
  37478. + if (bh->state == BUF_STATE_FULL) {
  37479. + smp_rmb();
  37480. + bh->state = BUF_STATE_EMPTY;
  37481. + fsg->next_buffhd_to_drain = bh->next;
  37482. +
  37483. + /* A short packet or an error ends everything */
  37484. + if (bh->outreq->actual < bh->bulk_out_intended_length ||
  37485. + bh->outreq->status != 0) {
  37486. + raise_exception(fsg, FSG_STATE_ABORT_BULK_OUT);
  37487. + return -EINTR;
  37488. + }
  37489. + continue;
  37490. + }
  37491. +
  37492. + /* Try to submit another request if we need one */
  37493. + bh = fsg->next_buffhd_to_fill;
  37494. + if (bh->state == BUF_STATE_EMPTY && fsg->usb_amount_left > 0) {
  37495. + amount = min(fsg->usb_amount_left,
  37496. + (u32) mod_data.buflen);
  37497. +
  37498. + /* Except at the end of the transfer, amount will be
  37499. + * equal to the buffer size, which is divisible by
  37500. + * the bulk-out maxpacket size.
  37501. + */
  37502. + set_bulk_out_req_length(fsg, bh, amount);
  37503. + start_transfer(fsg, fsg->bulk_out, bh->outreq,
  37504. + &bh->outreq_busy, &bh->state);
  37505. + fsg->next_buffhd_to_fill = bh->next;
  37506. + fsg->usb_amount_left -= amount;
  37507. + continue;
  37508. + }
  37509. +
  37510. + /* Otherwise wait for something to happen */
  37511. + rc = sleep_thread(fsg);
  37512. + if (rc)
  37513. + return rc;
  37514. + }
  37515. + return 0;
  37516. +}
  37517. +
  37518. +
  37519. +static int finish_reply(struct fsg_dev *fsg)
  37520. +{
  37521. + struct fsg_buffhd *bh = fsg->next_buffhd_to_fill;
  37522. + int rc = 0;
  37523. +
  37524. + switch (fsg->data_dir) {
  37525. + case DATA_DIR_NONE:
  37526. + break; // Nothing to send
  37527. +
  37528. + /* If we don't know whether the host wants to read or write,
  37529. + * this must be CB or CBI with an unknown command. We mustn't
  37530. + * try to send or receive any data. So stall both bulk pipes
  37531. + * if we can and wait for a reset. */
  37532. + case DATA_DIR_UNKNOWN:
  37533. + if (mod_data.can_stall) {
  37534. + fsg_set_halt(fsg, fsg->bulk_out);
  37535. + rc = halt_bulk_in_endpoint(fsg);
  37536. + }
  37537. + break;
  37538. +
  37539. + /* All but the last buffer of data must have already been sent */
  37540. + case DATA_DIR_TO_HOST:
  37541. + if (fsg->data_size == 0)
  37542. + ; // Nothing to send
  37543. +
  37544. + /* If there's no residue, simply send the last buffer */
  37545. + else if (fsg->residue == 0) {
  37546. + bh->inreq->zero = 0;
  37547. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  37548. + &bh->inreq_busy, &bh->state);
  37549. + fsg->next_buffhd_to_fill = bh->next;
  37550. + }
  37551. +
  37552. + /* There is a residue. For CB and CBI, simply mark the end
  37553. + * of the data with a short packet. However, if we are
  37554. + * allowed to stall, there was no data at all (residue ==
  37555. + * data_size), and the command failed (invalid LUN or
  37556. + * sense data is set), then halt the bulk-in endpoint
  37557. + * instead. */
  37558. + else if (!transport_is_bbb()) {
  37559. + if (mod_data.can_stall &&
  37560. + fsg->residue == fsg->data_size &&
  37561. + (!fsg->curlun || fsg->curlun->sense_data != SS_NO_SENSE)) {
  37562. + bh->state = BUF_STATE_EMPTY;
  37563. + rc = halt_bulk_in_endpoint(fsg);
  37564. + } else {
  37565. + bh->inreq->zero = 1;
  37566. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  37567. + &bh->inreq_busy, &bh->state);
  37568. + fsg->next_buffhd_to_fill = bh->next;
  37569. + }
  37570. + }
  37571. +
  37572. + /*
  37573. + * For Bulk-only, mark the end of the data with a short
  37574. + * packet. If we are allowed to stall, halt the bulk-in
  37575. + * endpoint. (Note: This violates the Bulk-Only Transport
  37576. + * specification, which requires us to pad the data if we
  37577. + * don't halt the endpoint. Presumably nobody will mind.)
  37578. + */
  37579. + else {
  37580. + bh->inreq->zero = 1;
  37581. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  37582. + &bh->inreq_busy, &bh->state);
  37583. + fsg->next_buffhd_to_fill = bh->next;
  37584. + if (mod_data.can_stall)
  37585. + rc = halt_bulk_in_endpoint(fsg);
  37586. + }
  37587. + break;
  37588. +
  37589. + /* We have processed all we want from the data the host has sent.
  37590. + * There may still be outstanding bulk-out requests. */
  37591. + case DATA_DIR_FROM_HOST:
  37592. + if (fsg->residue == 0)
  37593. + ; // Nothing to receive
  37594. +
  37595. + /* Did the host stop sending unexpectedly early? */
  37596. + else if (fsg->short_packet_received) {
  37597. + raise_exception(fsg, FSG_STATE_ABORT_BULK_OUT);
  37598. + rc = -EINTR;
  37599. + }
  37600. +
  37601. + /* We haven't processed all the incoming data. Even though
  37602. + * we may be allowed to stall, doing so would cause a race.
  37603. + * The controller may already have ACK'ed all the remaining
  37604. + * bulk-out packets, in which case the host wouldn't see a
  37605. + * STALL. Not realizing the endpoint was halted, it wouldn't
  37606. + * clear the halt -- leading to problems later on. */
  37607. +#if 0
  37608. + else if (mod_data.can_stall) {
  37609. + fsg_set_halt(fsg, fsg->bulk_out);
  37610. + raise_exception(fsg, FSG_STATE_ABORT_BULK_OUT);
  37611. + rc = -EINTR;
  37612. + }
  37613. +#endif
  37614. +
  37615. + /* We can't stall. Read in the excess data and throw it
  37616. + * all away. */
  37617. + else
  37618. + rc = throw_away_data(fsg);
  37619. + break;
  37620. + }
  37621. + return rc;
  37622. +}
  37623. +
  37624. +
  37625. +static int send_status(struct fsg_dev *fsg)
  37626. +{
  37627. + struct fsg_lun *curlun = fsg->curlun;
  37628. + struct fsg_buffhd *bh;
  37629. + int rc;
  37630. + u8 status = US_BULK_STAT_OK;
  37631. + u32 sd, sdinfo = 0;
  37632. +
  37633. + /* Wait for the next buffer to become available */
  37634. + bh = fsg->next_buffhd_to_fill;
  37635. + while (bh->state != BUF_STATE_EMPTY) {
  37636. + rc = sleep_thread(fsg);
  37637. + if (rc)
  37638. + return rc;
  37639. + }
  37640. +
  37641. + if (curlun) {
  37642. + sd = curlun->sense_data;
  37643. + sdinfo = curlun->sense_data_info;
  37644. + } else if (fsg->bad_lun_okay)
  37645. + sd = SS_NO_SENSE;
  37646. + else
  37647. + sd = SS_LOGICAL_UNIT_NOT_SUPPORTED;
  37648. +
  37649. + if (fsg->phase_error) {
  37650. + DBG(fsg, "sending phase-error status\n");
  37651. + status = US_BULK_STAT_PHASE;
  37652. + sd = SS_INVALID_COMMAND;
  37653. + } else if (sd != SS_NO_SENSE) {
  37654. + DBG(fsg, "sending command-failure status\n");
  37655. + status = US_BULK_STAT_FAIL;
  37656. + VDBG(fsg, " sense data: SK x%02x, ASC x%02x, ASCQ x%02x;"
  37657. + " info x%x\n",
  37658. + SK(sd), ASC(sd), ASCQ(sd), sdinfo);
  37659. + }
  37660. +
  37661. + if (transport_is_bbb()) {
  37662. + struct bulk_cs_wrap *csw = bh->buf;
  37663. +
  37664. + /* Store and send the Bulk-only CSW */
  37665. + csw->Signature = cpu_to_le32(US_BULK_CS_SIGN);
  37666. + csw->Tag = fsg->tag;
  37667. + csw->Residue = cpu_to_le32(fsg->residue);
  37668. + csw->Status = status;
  37669. +
  37670. + bh->inreq->length = US_BULK_CS_WRAP_LEN;
  37671. + bh->inreq->zero = 0;
  37672. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  37673. + &bh->inreq_busy, &bh->state);
  37674. +
  37675. + } else if (mod_data.transport_type == USB_PR_CB) {
  37676. +
  37677. + /* Control-Bulk transport has no status phase! */
  37678. + return 0;
  37679. +
  37680. + } else { // USB_PR_CBI
  37681. + struct interrupt_data *buf = bh->buf;
  37682. +
  37683. + /* Store and send the Interrupt data. UFI sends the ASC
  37684. + * and ASCQ bytes. Everything else sends a Type (which
  37685. + * is always 0) and the status Value. */
  37686. + if (mod_data.protocol_type == USB_SC_UFI) {
  37687. + buf->bType = ASC(sd);
  37688. + buf->bValue = ASCQ(sd);
  37689. + } else {
  37690. + buf->bType = 0;
  37691. + buf->bValue = status;
  37692. + }
  37693. + fsg->intreq->length = CBI_INTERRUPT_DATA_LEN;
  37694. +
  37695. + fsg->intr_buffhd = bh; // Point to the right buffhd
  37696. + fsg->intreq->buf = bh->inreq->buf;
  37697. + fsg->intreq->context = bh;
  37698. + start_transfer(fsg, fsg->intr_in, fsg->intreq,
  37699. + &fsg->intreq_busy, &bh->state);
  37700. + }
  37701. +
  37702. + fsg->next_buffhd_to_fill = bh->next;
  37703. + return 0;
  37704. +}
  37705. +
  37706. +
  37707. +/*-------------------------------------------------------------------------*/
  37708. +
  37709. +/* Check whether the command is properly formed and whether its data size
  37710. + * and direction agree with the values we already have. */
  37711. +static int check_command(struct fsg_dev *fsg, int cmnd_size,
  37712. + enum data_direction data_dir, unsigned int mask,
  37713. + int needs_medium, const char *name)
  37714. +{
  37715. + int i;
  37716. + int lun = fsg->cmnd[1] >> 5;
  37717. + static const char dirletter[4] = {'u', 'o', 'i', 'n'};
  37718. + char hdlen[20];
  37719. + struct fsg_lun *curlun;
  37720. +
  37721. + /* Adjust the expected cmnd_size for protocol encapsulation padding.
  37722. + * Transparent SCSI doesn't pad. */
  37723. + if (protocol_is_scsi())
  37724. + ;
  37725. +
  37726. + /* There's some disagreement as to whether RBC pads commands or not.
  37727. + * We'll play it safe and accept either form. */
  37728. + else if (mod_data.protocol_type == USB_SC_RBC) {
  37729. + if (fsg->cmnd_size == 12)
  37730. + cmnd_size = 12;
  37731. +
  37732. + /* All the other protocols pad to 12 bytes */
  37733. + } else
  37734. + cmnd_size = 12;
  37735. +
  37736. + hdlen[0] = 0;
  37737. + if (fsg->data_dir != DATA_DIR_UNKNOWN)
  37738. + sprintf(hdlen, ", H%c=%u", dirletter[(int) fsg->data_dir],
  37739. + fsg->data_size);
  37740. + VDBG(fsg, "SCSI command: %s; Dc=%d, D%c=%u; Hc=%d%s\n",
  37741. + name, cmnd_size, dirletter[(int) data_dir],
  37742. + fsg->data_size_from_cmnd, fsg->cmnd_size, hdlen);
  37743. +
  37744. + /* We can't reply at all until we know the correct data direction
  37745. + * and size. */
  37746. + if (fsg->data_size_from_cmnd == 0)
  37747. + data_dir = DATA_DIR_NONE;
  37748. + if (fsg->data_dir == DATA_DIR_UNKNOWN) { // CB or CBI
  37749. + fsg->data_dir = data_dir;
  37750. + fsg->data_size = fsg->data_size_from_cmnd;
  37751. +
  37752. + } else { // Bulk-only
  37753. + if (fsg->data_size < fsg->data_size_from_cmnd) {
  37754. +
  37755. + /* Host data size < Device data size is a phase error.
  37756. + * Carry out the command, but only transfer as much
  37757. + * as we are allowed. */
  37758. + fsg->data_size_from_cmnd = fsg->data_size;
  37759. + fsg->phase_error = 1;
  37760. + }
  37761. + }
  37762. + fsg->residue = fsg->usb_amount_left = fsg->data_size;
  37763. +
  37764. + /* Conflicting data directions is a phase error */
  37765. + if (fsg->data_dir != data_dir && fsg->data_size_from_cmnd > 0) {
  37766. + fsg->phase_error = 1;
  37767. + return -EINVAL;
  37768. + }
  37769. +
  37770. + /* Verify the length of the command itself */
  37771. + if (cmnd_size != fsg->cmnd_size) {
  37772. +
  37773. + /* Special case workaround: There are plenty of buggy SCSI
  37774. + * implementations. Many have issues with cbw->Length
  37775. + * field passing a wrong command size. For those cases we
  37776. + * always try to work around the problem by using the length
  37777. + * sent by the host side provided it is at least as large
  37778. + * as the correct command length.
  37779. + * Examples of such cases would be MS-Windows, which issues
  37780. + * REQUEST SENSE with cbw->Length == 12 where it should
  37781. + * be 6, and xbox360 issuing INQUIRY, TEST UNIT READY and
  37782. + * REQUEST SENSE with cbw->Length == 10 where it should
  37783. + * be 6 as well.
  37784. + */
  37785. + if (cmnd_size <= fsg->cmnd_size) {
  37786. + DBG(fsg, "%s is buggy! Expected length %d "
  37787. + "but we got %d\n", name,
  37788. + cmnd_size, fsg->cmnd_size);
  37789. + cmnd_size = fsg->cmnd_size;
  37790. + } else {
  37791. + fsg->phase_error = 1;
  37792. + return -EINVAL;
  37793. + }
  37794. + }
  37795. +
  37796. + /* Check that the LUN values are consistent */
  37797. + if (transport_is_bbb()) {
  37798. + if (fsg->lun != lun)
  37799. + DBG(fsg, "using LUN %d from CBW, "
  37800. + "not LUN %d from CDB\n",
  37801. + fsg->lun, lun);
  37802. + }
  37803. +
  37804. + /* Check the LUN */
  37805. + curlun = fsg->curlun;
  37806. + if (curlun) {
  37807. + if (fsg->cmnd[0] != REQUEST_SENSE) {
  37808. + curlun->sense_data = SS_NO_SENSE;
  37809. + curlun->sense_data_info = 0;
  37810. + curlun->info_valid = 0;
  37811. + }
  37812. + } else {
  37813. + fsg->bad_lun_okay = 0;
  37814. +
  37815. + /* INQUIRY and REQUEST SENSE commands are explicitly allowed
  37816. + * to use unsupported LUNs; all others may not. */
  37817. + if (fsg->cmnd[0] != INQUIRY &&
  37818. + fsg->cmnd[0] != REQUEST_SENSE) {
  37819. + DBG(fsg, "unsupported LUN %d\n", fsg->lun);
  37820. + return -EINVAL;
  37821. + }
  37822. + }
  37823. +
  37824. + /* If a unit attention condition exists, only INQUIRY and
  37825. + * REQUEST SENSE commands are allowed; anything else must fail. */
  37826. + if (curlun && curlun->unit_attention_data != SS_NO_SENSE &&
  37827. + fsg->cmnd[0] != INQUIRY &&
  37828. + fsg->cmnd[0] != REQUEST_SENSE) {
  37829. + curlun->sense_data = curlun->unit_attention_data;
  37830. + curlun->unit_attention_data = SS_NO_SENSE;
  37831. + return -EINVAL;
  37832. + }
  37833. +
  37834. + /* Check that only command bytes listed in the mask are non-zero */
  37835. + fsg->cmnd[1] &= 0x1f; // Mask away the LUN
  37836. + for (i = 1; i < cmnd_size; ++i) {
  37837. + if (fsg->cmnd[i] && !(mask & (1 << i))) {
  37838. + if (curlun)
  37839. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  37840. + return -EINVAL;
  37841. + }
  37842. + }
  37843. +
  37844. + /* If the medium isn't mounted and the command needs to access
  37845. + * it, return an error. */
  37846. + if (curlun && !fsg_lun_is_open(curlun) && needs_medium) {
  37847. + curlun->sense_data = SS_MEDIUM_NOT_PRESENT;
  37848. + return -EINVAL;
  37849. + }
  37850. +
  37851. + return 0;
  37852. +}
  37853. +
  37854. +/* wrapper of check_command for data size in blocks handling */
  37855. +static int check_command_size_in_blocks(struct fsg_dev *fsg, int cmnd_size,
  37856. + enum data_direction data_dir, unsigned int mask,
  37857. + int needs_medium, const char *name)
  37858. +{
  37859. + if (fsg->curlun)
  37860. + fsg->data_size_from_cmnd <<= fsg->curlun->blkbits;
  37861. + return check_command(fsg, cmnd_size, data_dir,
  37862. + mask, needs_medium, name);
  37863. +}
  37864. +
  37865. +static int do_scsi_command(struct fsg_dev *fsg)
  37866. +{
  37867. + struct fsg_buffhd *bh;
  37868. + int rc;
  37869. + int reply = -EINVAL;
  37870. + int i;
  37871. + static char unknown[16];
  37872. +
  37873. + dump_cdb(fsg);
  37874. +
  37875. + /* Wait for the next buffer to become available for data or status */
  37876. + bh = fsg->next_buffhd_to_drain = fsg->next_buffhd_to_fill;
  37877. + while (bh->state != BUF_STATE_EMPTY) {
  37878. + rc = sleep_thread(fsg);
  37879. + if (rc)
  37880. + return rc;
  37881. + }
  37882. + fsg->phase_error = 0;
  37883. + fsg->short_packet_received = 0;
  37884. +
  37885. + down_read(&fsg->filesem); // We're using the backing file
  37886. + switch (fsg->cmnd[0]) {
  37887. +
  37888. + case INQUIRY:
  37889. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  37890. + if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
  37891. + (1<<4), 0,
  37892. + "INQUIRY")) == 0)
  37893. + reply = do_inquiry(fsg, bh);
  37894. + break;
  37895. +
  37896. + case MODE_SELECT:
  37897. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  37898. + if ((reply = check_command(fsg, 6, DATA_DIR_FROM_HOST,
  37899. + (1<<1) | (1<<4), 0,
  37900. + "MODE SELECT(6)")) == 0)
  37901. + reply = do_mode_select(fsg, bh);
  37902. + break;
  37903. +
  37904. + case MODE_SELECT_10:
  37905. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  37906. + if ((reply = check_command(fsg, 10, DATA_DIR_FROM_HOST,
  37907. + (1<<1) | (3<<7), 0,
  37908. + "MODE SELECT(10)")) == 0)
  37909. + reply = do_mode_select(fsg, bh);
  37910. + break;
  37911. +
  37912. + case MODE_SENSE:
  37913. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  37914. + if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
  37915. + (1<<1) | (1<<2) | (1<<4), 0,
  37916. + "MODE SENSE(6)")) == 0)
  37917. + reply = do_mode_sense(fsg, bh);
  37918. + break;
  37919. +
  37920. + case MODE_SENSE_10:
  37921. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  37922. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  37923. + (1<<1) | (1<<2) | (3<<7), 0,
  37924. + "MODE SENSE(10)")) == 0)
  37925. + reply = do_mode_sense(fsg, bh);
  37926. + break;
  37927. +
  37928. + case ALLOW_MEDIUM_REMOVAL:
  37929. + fsg->data_size_from_cmnd = 0;
  37930. + if ((reply = check_command(fsg, 6, DATA_DIR_NONE,
  37931. + (1<<4), 0,
  37932. + "PREVENT-ALLOW MEDIUM REMOVAL")) == 0)
  37933. + reply = do_prevent_allow(fsg);
  37934. + break;
  37935. +
  37936. + case READ_6:
  37937. + i = fsg->cmnd[4];
  37938. + fsg->data_size_from_cmnd = (i == 0) ? 256 : i;
  37939. + if ((reply = check_command_size_in_blocks(fsg, 6,
  37940. + DATA_DIR_TO_HOST,
  37941. + (7<<1) | (1<<4), 1,
  37942. + "READ(6)")) == 0)
  37943. + reply = do_read(fsg);
  37944. + break;
  37945. +
  37946. + case READ_10:
  37947. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  37948. + if ((reply = check_command_size_in_blocks(fsg, 10,
  37949. + DATA_DIR_TO_HOST,
  37950. + (1<<1) | (0xf<<2) | (3<<7), 1,
  37951. + "READ(10)")) == 0)
  37952. + reply = do_read(fsg);
  37953. + break;
  37954. +
  37955. + case READ_12:
  37956. + fsg->data_size_from_cmnd = get_unaligned_be32(&fsg->cmnd[6]);
  37957. + if ((reply = check_command_size_in_blocks(fsg, 12,
  37958. + DATA_DIR_TO_HOST,
  37959. + (1<<1) | (0xf<<2) | (0xf<<6), 1,
  37960. + "READ(12)")) == 0)
  37961. + reply = do_read(fsg);
  37962. + break;
  37963. +
  37964. + case READ_CAPACITY:
  37965. + fsg->data_size_from_cmnd = 8;
  37966. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  37967. + (0xf<<2) | (1<<8), 1,
  37968. + "READ CAPACITY")) == 0)
  37969. + reply = do_read_capacity(fsg, bh);
  37970. + break;
  37971. +
  37972. + case READ_HEADER:
  37973. + if (!mod_data.cdrom)
  37974. + goto unknown_cmnd;
  37975. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  37976. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  37977. + (3<<7) | (0x1f<<1), 1,
  37978. + "READ HEADER")) == 0)
  37979. + reply = do_read_header(fsg, bh);
  37980. + break;
  37981. +
  37982. + case READ_TOC:
  37983. + if (!mod_data.cdrom)
  37984. + goto unknown_cmnd;
  37985. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  37986. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  37987. + (7<<6) | (1<<1), 1,
  37988. + "READ TOC")) == 0)
  37989. + reply = do_read_toc(fsg, bh);
  37990. + break;
  37991. +
  37992. + case READ_FORMAT_CAPACITIES:
  37993. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  37994. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  37995. + (3<<7), 1,
  37996. + "READ FORMAT CAPACITIES")) == 0)
  37997. + reply = do_read_format_capacities(fsg, bh);
  37998. + break;
  37999. +
  38000. + case REQUEST_SENSE:
  38001. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  38002. + if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
  38003. + (1<<4), 0,
  38004. + "REQUEST SENSE")) == 0)
  38005. + reply = do_request_sense(fsg, bh);
  38006. + break;
  38007. +
  38008. + case START_STOP:
  38009. + fsg->data_size_from_cmnd = 0;
  38010. + if ((reply = check_command(fsg, 6, DATA_DIR_NONE,
  38011. + (1<<1) | (1<<4), 0,
  38012. + "START-STOP UNIT")) == 0)
  38013. + reply = do_start_stop(fsg);
  38014. + break;
  38015. +
  38016. + case SYNCHRONIZE_CACHE:
  38017. + fsg->data_size_from_cmnd = 0;
  38018. + if ((reply = check_command(fsg, 10, DATA_DIR_NONE,
  38019. + (0xf<<2) | (3<<7), 1,
  38020. + "SYNCHRONIZE CACHE")) == 0)
  38021. + reply = do_synchronize_cache(fsg);
  38022. + break;
  38023. +
  38024. + case TEST_UNIT_READY:
  38025. + fsg->data_size_from_cmnd = 0;
  38026. + reply = check_command(fsg, 6, DATA_DIR_NONE,
  38027. + 0, 1,
  38028. + "TEST UNIT READY");
  38029. + break;
  38030. +
  38031. + /* Although optional, this command is used by MS-Windows. We
  38032. + * support a minimal version: BytChk must be 0. */
  38033. + case VERIFY:
  38034. + fsg->data_size_from_cmnd = 0;
  38035. + if ((reply = check_command(fsg, 10, DATA_DIR_NONE,
  38036. + (1<<1) | (0xf<<2) | (3<<7), 1,
  38037. + "VERIFY")) == 0)
  38038. + reply = do_verify(fsg);
  38039. + break;
  38040. +
  38041. + case WRITE_6:
  38042. + i = fsg->cmnd[4];
  38043. + fsg->data_size_from_cmnd = (i == 0) ? 256 : i;
  38044. + if ((reply = check_command_size_in_blocks(fsg, 6,
  38045. + DATA_DIR_FROM_HOST,
  38046. + (7<<1) | (1<<4), 1,
  38047. + "WRITE(6)")) == 0)
  38048. + reply = do_write(fsg);
  38049. + break;
  38050. +
  38051. + case WRITE_10:
  38052. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  38053. + if ((reply = check_command_size_in_blocks(fsg, 10,
  38054. + DATA_DIR_FROM_HOST,
  38055. + (1<<1) | (0xf<<2) | (3<<7), 1,
  38056. + "WRITE(10)")) == 0)
  38057. + reply = do_write(fsg);
  38058. + break;
  38059. +
  38060. + case WRITE_12:
  38061. + fsg->data_size_from_cmnd = get_unaligned_be32(&fsg->cmnd[6]);
  38062. + if ((reply = check_command_size_in_blocks(fsg, 12,
  38063. + DATA_DIR_FROM_HOST,
  38064. + (1<<1) | (0xf<<2) | (0xf<<6), 1,
  38065. + "WRITE(12)")) == 0)
  38066. + reply = do_write(fsg);
  38067. + break;
  38068. +
  38069. + /* Some mandatory commands that we recognize but don't implement.
  38070. + * They don't mean much in this setting. It's left as an exercise
  38071. + * for anyone interested to implement RESERVE and RELEASE in terms
  38072. + * of Posix locks. */
  38073. + case FORMAT_UNIT:
  38074. + case RELEASE:
  38075. + case RESERVE:
  38076. + case SEND_DIAGNOSTIC:
  38077. + // Fall through
  38078. +
  38079. + default:
  38080. + unknown_cmnd:
  38081. + fsg->data_size_from_cmnd = 0;
  38082. + sprintf(unknown, "Unknown x%02x", fsg->cmnd[0]);
  38083. + if ((reply = check_command(fsg, fsg->cmnd_size,
  38084. + DATA_DIR_UNKNOWN, ~0, 0, unknown)) == 0) {
  38085. + fsg->curlun->sense_data = SS_INVALID_COMMAND;
  38086. + reply = -EINVAL;
  38087. + }
  38088. + break;
  38089. + }
  38090. + up_read(&fsg->filesem);
  38091. +
  38092. + if (reply == -EINTR || signal_pending(current))
  38093. + return -EINTR;
  38094. +
  38095. + /* Set up the single reply buffer for finish_reply() */
  38096. + if (reply == -EINVAL)
  38097. + reply = 0; // Error reply length
  38098. + if (reply >= 0 && fsg->data_dir == DATA_DIR_TO_HOST) {
  38099. + reply = min((u32) reply, fsg->data_size_from_cmnd);
  38100. + bh->inreq->length = reply;
  38101. + bh->state = BUF_STATE_FULL;
  38102. + fsg->residue -= reply;
  38103. + } // Otherwise it's already set
  38104. +
  38105. + return 0;
  38106. +}
  38107. +
  38108. +
  38109. +/*-------------------------------------------------------------------------*/
  38110. +
  38111. +static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  38112. +{
  38113. + struct usb_request *req = bh->outreq;
  38114. + struct bulk_cb_wrap *cbw = req->buf;
  38115. +
  38116. + /* Was this a real packet? Should it be ignored? */
  38117. + if (req->status || test_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags))
  38118. + return -EINVAL;
  38119. +
  38120. + /* Is the CBW valid? */
  38121. + if (req->actual != US_BULK_CB_WRAP_LEN ||
  38122. + cbw->Signature != cpu_to_le32(
  38123. + US_BULK_CB_SIGN)) {
  38124. + DBG(fsg, "invalid CBW: len %u sig 0x%x\n",
  38125. + req->actual,
  38126. + le32_to_cpu(cbw->Signature));
  38127. +
  38128. + /* The Bulk-only spec says we MUST stall the IN endpoint
  38129. + * (6.6.1), so it's unavoidable. It also says we must
  38130. + * retain this state until the next reset, but there's
  38131. + * no way to tell the controller driver it should ignore
  38132. + * Clear-Feature(HALT) requests.
  38133. + *
  38134. + * We aren't required to halt the OUT endpoint; instead
  38135. + * we can simply accept and discard any data received
  38136. + * until the next reset. */
  38137. + wedge_bulk_in_endpoint(fsg);
  38138. + set_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
  38139. + return -EINVAL;
  38140. + }
  38141. +
  38142. + /* Is the CBW meaningful? */
  38143. + if (cbw->Lun >= FSG_MAX_LUNS || cbw->Flags & ~US_BULK_FLAG_IN ||
  38144. + cbw->Length <= 0 || cbw->Length > MAX_COMMAND_SIZE) {
  38145. + DBG(fsg, "non-meaningful CBW: lun = %u, flags = 0x%x, "
  38146. + "cmdlen %u\n",
  38147. + cbw->Lun, cbw->Flags, cbw->Length);
  38148. +
  38149. + /* We can do anything we want here, so let's stall the
  38150. + * bulk pipes if we are allowed to. */
  38151. + if (mod_data.can_stall) {
  38152. + fsg_set_halt(fsg, fsg->bulk_out);
  38153. + halt_bulk_in_endpoint(fsg);
  38154. + }
  38155. + return -EINVAL;
  38156. + }
  38157. +
  38158. + /* Save the command for later */
  38159. + fsg->cmnd_size = cbw->Length;
  38160. + memcpy(fsg->cmnd, cbw->CDB, fsg->cmnd_size);
  38161. + if (cbw->Flags & US_BULK_FLAG_IN)
  38162. + fsg->data_dir = DATA_DIR_TO_HOST;
  38163. + else
  38164. + fsg->data_dir = DATA_DIR_FROM_HOST;
  38165. + fsg->data_size = le32_to_cpu(cbw->DataTransferLength);
  38166. + if (fsg->data_size == 0)
  38167. + fsg->data_dir = DATA_DIR_NONE;
  38168. + fsg->lun = cbw->Lun;
  38169. + fsg->tag = cbw->Tag;
  38170. + return 0;
  38171. +}
  38172. +
  38173. +
  38174. +static int get_next_command(struct fsg_dev *fsg)
  38175. +{
  38176. + struct fsg_buffhd *bh;
  38177. + int rc = 0;
  38178. +
  38179. + if (transport_is_bbb()) {
  38180. +
  38181. + /* Wait for the next buffer to become available */
  38182. + bh = fsg->next_buffhd_to_fill;
  38183. + while (bh->state != BUF_STATE_EMPTY) {
  38184. + rc = sleep_thread(fsg);
  38185. + if (rc)
  38186. + return rc;
  38187. + }
  38188. +
  38189. + /* Queue a request to read a Bulk-only CBW */
  38190. + set_bulk_out_req_length(fsg, bh, US_BULK_CB_WRAP_LEN);
  38191. + start_transfer(fsg, fsg->bulk_out, bh->outreq,
  38192. + &bh->outreq_busy, &bh->state);
  38193. +
  38194. + /* We will drain the buffer in software, which means we
  38195. + * can reuse it for the next filling. No need to advance
  38196. + * next_buffhd_to_fill. */
  38197. +
  38198. + /* Wait for the CBW to arrive */
  38199. + while (bh->state != BUF_STATE_FULL) {
  38200. + rc = sleep_thread(fsg);
  38201. + if (rc)
  38202. + return rc;
  38203. + }
  38204. + smp_rmb();
  38205. + rc = received_cbw(fsg, bh);
  38206. + bh->state = BUF_STATE_EMPTY;
  38207. +
  38208. + } else { // USB_PR_CB or USB_PR_CBI
  38209. +
  38210. + /* Wait for the next command to arrive */
  38211. + while (fsg->cbbuf_cmnd_size == 0) {
  38212. + rc = sleep_thread(fsg);
  38213. + if (rc)
  38214. + return rc;
  38215. + }
  38216. +
  38217. + /* Is the previous status interrupt request still busy?
  38218. + * The host is allowed to skip reading the status,
  38219. + * so we must cancel it. */
  38220. + if (fsg->intreq_busy)
  38221. + usb_ep_dequeue(fsg->intr_in, fsg->intreq);
  38222. +
  38223. + /* Copy the command and mark the buffer empty */
  38224. + fsg->data_dir = DATA_DIR_UNKNOWN;
  38225. + spin_lock_irq(&fsg->lock);
  38226. + fsg->cmnd_size = fsg->cbbuf_cmnd_size;
  38227. + memcpy(fsg->cmnd, fsg->cbbuf_cmnd, fsg->cmnd_size);
  38228. + fsg->cbbuf_cmnd_size = 0;
  38229. + spin_unlock_irq(&fsg->lock);
  38230. +
  38231. + /* Use LUN from the command */
  38232. + fsg->lun = fsg->cmnd[1] >> 5;
  38233. + }
  38234. +
  38235. + /* Update current lun */
  38236. + if (fsg->lun >= 0 && fsg->lun < fsg->nluns)
  38237. + fsg->curlun = &fsg->luns[fsg->lun];
  38238. + else
  38239. + fsg->curlun = NULL;
  38240. +
  38241. + return rc;
  38242. +}
  38243. +
  38244. +
  38245. +/*-------------------------------------------------------------------------*/
  38246. +
  38247. +static int enable_endpoint(struct fsg_dev *fsg, struct usb_ep *ep,
  38248. + const struct usb_endpoint_descriptor *d)
  38249. +{
  38250. + int rc;
  38251. +
  38252. + ep->driver_data = fsg;
  38253. + ep->desc = d;
  38254. + rc = usb_ep_enable(ep);
  38255. + if (rc)
  38256. + ERROR(fsg, "can't enable %s, result %d\n", ep->name, rc);
  38257. + return rc;
  38258. +}
  38259. +
  38260. +static int alloc_request(struct fsg_dev *fsg, struct usb_ep *ep,
  38261. + struct usb_request **preq)
  38262. +{
  38263. + *preq = usb_ep_alloc_request(ep, GFP_ATOMIC);
  38264. + if (*preq)
  38265. + return 0;
  38266. + ERROR(fsg, "can't allocate request for %s\n", ep->name);
  38267. + return -ENOMEM;
  38268. +}
  38269. +
  38270. +/*
  38271. + * Reset interface setting and re-init endpoint state (toggle etc).
  38272. + * Call with altsetting < 0 to disable the interface. The only other
  38273. + * available altsetting is 0, which enables the interface.
  38274. + */
  38275. +static int do_set_interface(struct fsg_dev *fsg, int altsetting)
  38276. +{
  38277. + int rc = 0;
  38278. + int i;
  38279. + const struct usb_endpoint_descriptor *d;
  38280. +
  38281. + if (fsg->running)
  38282. + DBG(fsg, "reset interface\n");
  38283. +
  38284. +reset:
  38285. + /* Deallocate the requests */
  38286. + for (i = 0; i < fsg_num_buffers; ++i) {
  38287. + struct fsg_buffhd *bh = &fsg->buffhds[i];
  38288. +
  38289. + if (bh->inreq) {
  38290. + usb_ep_free_request(fsg->bulk_in, bh->inreq);
  38291. + bh->inreq = NULL;
  38292. + }
  38293. + if (bh->outreq) {
  38294. + usb_ep_free_request(fsg->bulk_out, bh->outreq);
  38295. + bh->outreq = NULL;
  38296. + }
  38297. + }
  38298. + if (fsg->intreq) {
  38299. + usb_ep_free_request(fsg->intr_in, fsg->intreq);
  38300. + fsg->intreq = NULL;
  38301. + }
  38302. +
  38303. + /* Disable the endpoints */
  38304. + if (fsg->bulk_in_enabled) {
  38305. + usb_ep_disable(fsg->bulk_in);
  38306. + fsg->bulk_in_enabled = 0;
  38307. + }
  38308. + if (fsg->bulk_out_enabled) {
  38309. + usb_ep_disable(fsg->bulk_out);
  38310. + fsg->bulk_out_enabled = 0;
  38311. + }
  38312. + if (fsg->intr_in_enabled) {
  38313. + usb_ep_disable(fsg->intr_in);
  38314. + fsg->intr_in_enabled = 0;
  38315. + }
  38316. +
  38317. + fsg->running = 0;
  38318. + if (altsetting < 0 || rc != 0)
  38319. + return rc;
  38320. +
  38321. + DBG(fsg, "set interface %d\n", altsetting);
  38322. +
  38323. + /* Enable the endpoints */
  38324. + d = fsg_ep_desc(fsg->gadget,
  38325. + &fsg_fs_bulk_in_desc, &fsg_hs_bulk_in_desc,
  38326. + &fsg_ss_bulk_in_desc);
  38327. + if ((rc = enable_endpoint(fsg, fsg->bulk_in, d)) != 0)
  38328. + goto reset;
  38329. + fsg->bulk_in_enabled = 1;
  38330. +
  38331. + d = fsg_ep_desc(fsg->gadget,
  38332. + &fsg_fs_bulk_out_desc, &fsg_hs_bulk_out_desc,
  38333. + &fsg_ss_bulk_out_desc);
  38334. + if ((rc = enable_endpoint(fsg, fsg->bulk_out, d)) != 0)
  38335. + goto reset;
  38336. + fsg->bulk_out_enabled = 1;
  38337. + fsg->bulk_out_maxpacket = usb_endpoint_maxp(d);
  38338. + clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
  38339. +
  38340. + if (transport_is_cbi()) {
  38341. + d = fsg_ep_desc(fsg->gadget,
  38342. + &fsg_fs_intr_in_desc, &fsg_hs_intr_in_desc,
  38343. + &fsg_ss_intr_in_desc);
  38344. + if ((rc = enable_endpoint(fsg, fsg->intr_in, d)) != 0)
  38345. + goto reset;
  38346. + fsg->intr_in_enabled = 1;
  38347. + }
  38348. +
  38349. + /* Allocate the requests */
  38350. + for (i = 0; i < fsg_num_buffers; ++i) {
  38351. + struct fsg_buffhd *bh = &fsg->buffhds[i];
  38352. +
  38353. + if ((rc = alloc_request(fsg, fsg->bulk_in, &bh->inreq)) != 0)
  38354. + goto reset;
  38355. + if ((rc = alloc_request(fsg, fsg->bulk_out, &bh->outreq)) != 0)
  38356. + goto reset;
  38357. + bh->inreq->buf = bh->outreq->buf = bh->buf;
  38358. + bh->inreq->context = bh->outreq->context = bh;
  38359. + bh->inreq->complete = bulk_in_complete;
  38360. + bh->outreq->complete = bulk_out_complete;
  38361. + }
  38362. + if (transport_is_cbi()) {
  38363. + if ((rc = alloc_request(fsg, fsg->intr_in, &fsg->intreq)) != 0)
  38364. + goto reset;
  38365. + fsg->intreq->complete = intr_in_complete;
  38366. + }
  38367. +
  38368. + fsg->running = 1;
  38369. + for (i = 0; i < fsg->nluns; ++i)
  38370. + fsg->luns[i].unit_attention_data = SS_RESET_OCCURRED;
  38371. + return rc;
  38372. +}
  38373. +
  38374. +
  38375. +/*
  38376. + * Change our operational configuration. This code must agree with the code
  38377. + * that returns config descriptors, and with interface altsetting code.
  38378. + *
  38379. + * It's also responsible for power management interactions. Some
  38380. + * configurations might not work with our current power sources.
  38381. + * For now we just assume the gadget is always self-powered.
  38382. + */
  38383. +static int do_set_config(struct fsg_dev *fsg, u8 new_config)
  38384. +{
  38385. + int rc = 0;
  38386. +
  38387. + /* Disable the single interface */
  38388. + if (fsg->config != 0) {
  38389. + DBG(fsg, "reset config\n");
  38390. + fsg->config = 0;
  38391. + rc = do_set_interface(fsg, -1);
  38392. + }
  38393. +
  38394. + /* Enable the interface */
  38395. + if (new_config != 0) {
  38396. + fsg->config = new_config;
  38397. + if ((rc = do_set_interface(fsg, 0)) != 0)
  38398. + fsg->config = 0; // Reset on errors
  38399. + else
  38400. + INFO(fsg, "%s config #%d\n",
  38401. + usb_speed_string(fsg->gadget->speed),
  38402. + fsg->config);
  38403. + }
  38404. + return rc;
  38405. +}
  38406. +
  38407. +
  38408. +/*-------------------------------------------------------------------------*/
  38409. +
  38410. +static void handle_exception(struct fsg_dev *fsg)
  38411. +{
  38412. + siginfo_t info;
  38413. + int sig;
  38414. + int i;
  38415. + int num_active;
  38416. + struct fsg_buffhd *bh;
  38417. + enum fsg_state old_state;
  38418. + u8 new_config;
  38419. + struct fsg_lun *curlun;
  38420. + unsigned int exception_req_tag;
  38421. + int rc;
  38422. +
  38423. + /* Clear the existing signals. Anything but SIGUSR1 is converted
  38424. + * into a high-priority EXIT exception. */
  38425. + for (;;) {
  38426. + sig = dequeue_signal_lock(current, &current->blocked, &info);
  38427. + if (!sig)
  38428. + break;
  38429. + if (sig != SIGUSR1) {
  38430. + if (fsg->state < FSG_STATE_EXIT)
  38431. + DBG(fsg, "Main thread exiting on signal\n");
  38432. + raise_exception(fsg, FSG_STATE_EXIT);
  38433. + }
  38434. + }
  38435. +
  38436. + /* Cancel all the pending transfers */
  38437. + if (fsg->intreq_busy)
  38438. + usb_ep_dequeue(fsg->intr_in, fsg->intreq);
  38439. + for (i = 0; i < fsg_num_buffers; ++i) {
  38440. + bh = &fsg->buffhds[i];
  38441. + if (bh->inreq_busy)
  38442. + usb_ep_dequeue(fsg->bulk_in, bh->inreq);
  38443. + if (bh->outreq_busy)
  38444. + usb_ep_dequeue(fsg->bulk_out, bh->outreq);
  38445. + }
  38446. +
  38447. + /* Wait until everything is idle */
  38448. + for (;;) {
  38449. + num_active = fsg->intreq_busy;
  38450. + for (i = 0; i < fsg_num_buffers; ++i) {
  38451. + bh = &fsg->buffhds[i];
  38452. + num_active += bh->inreq_busy + bh->outreq_busy;
  38453. + }
  38454. + if (num_active == 0)
  38455. + break;
  38456. + if (sleep_thread(fsg))
  38457. + return;
  38458. + }
  38459. +
  38460. + /* Clear out the controller's fifos */
  38461. + if (fsg->bulk_in_enabled)
  38462. + usb_ep_fifo_flush(fsg->bulk_in);
  38463. + if (fsg->bulk_out_enabled)
  38464. + usb_ep_fifo_flush(fsg->bulk_out);
  38465. + if (fsg->intr_in_enabled)
  38466. + usb_ep_fifo_flush(fsg->intr_in);
  38467. +
  38468. + /* Reset the I/O buffer states and pointers, the SCSI
  38469. + * state, and the exception. Then invoke the handler. */
  38470. + spin_lock_irq(&fsg->lock);
  38471. +
  38472. + for (i = 0; i < fsg_num_buffers; ++i) {
  38473. + bh = &fsg->buffhds[i];
  38474. + bh->state = BUF_STATE_EMPTY;
  38475. + }
  38476. + fsg->next_buffhd_to_fill = fsg->next_buffhd_to_drain =
  38477. + &fsg->buffhds[0];
  38478. +
  38479. + exception_req_tag = fsg->exception_req_tag;
  38480. + new_config = fsg->new_config;
  38481. + old_state = fsg->state;
  38482. +
  38483. + if (old_state == FSG_STATE_ABORT_BULK_OUT)
  38484. + fsg->state = FSG_STATE_STATUS_PHASE;
  38485. + else {
  38486. + for (i = 0; i < fsg->nluns; ++i) {
  38487. + curlun = &fsg->luns[i];
  38488. + curlun->prevent_medium_removal = 0;
  38489. + curlun->sense_data = curlun->unit_attention_data =
  38490. + SS_NO_SENSE;
  38491. + curlun->sense_data_info = 0;
  38492. + curlun->info_valid = 0;
  38493. + }
  38494. + fsg->state = FSG_STATE_IDLE;
  38495. + }
  38496. + spin_unlock_irq(&fsg->lock);
  38497. +
  38498. + /* Carry out any extra actions required for the exception */
  38499. + switch (old_state) {
  38500. + default:
  38501. + break;
  38502. +
  38503. + case FSG_STATE_ABORT_BULK_OUT:
  38504. + send_status(fsg);
  38505. + spin_lock_irq(&fsg->lock);
  38506. + if (fsg->state == FSG_STATE_STATUS_PHASE)
  38507. + fsg->state = FSG_STATE_IDLE;
  38508. + spin_unlock_irq(&fsg->lock);
  38509. + break;
  38510. +
  38511. + case FSG_STATE_RESET:
  38512. + /* In case we were forced against our will to halt a
  38513. + * bulk endpoint, clear the halt now. (The SuperH UDC
  38514. + * requires this.) */
  38515. + if (test_and_clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags))
  38516. + usb_ep_clear_halt(fsg->bulk_in);
  38517. +
  38518. + if (transport_is_bbb()) {
  38519. + if (fsg->ep0_req_tag == exception_req_tag)
  38520. + ep0_queue(fsg); // Complete the status stage
  38521. +
  38522. + } else if (transport_is_cbi())
  38523. + send_status(fsg); // Status by interrupt pipe
  38524. +
  38525. + /* Technically this should go here, but it would only be
  38526. + * a waste of time. Ditto for the INTERFACE_CHANGE and
  38527. + * CONFIG_CHANGE cases. */
  38528. + // for (i = 0; i < fsg->nluns; ++i)
  38529. + // fsg->luns[i].unit_attention_data = SS_RESET_OCCURRED;
  38530. + break;
  38531. +
  38532. + case FSG_STATE_INTERFACE_CHANGE:
  38533. + rc = do_set_interface(fsg, 0);
  38534. + if (fsg->ep0_req_tag != exception_req_tag)
  38535. + break;
  38536. + if (rc != 0) // STALL on errors
  38537. + fsg_set_halt(fsg, fsg->ep0);
  38538. + else // Complete the status stage
  38539. + ep0_queue(fsg);
  38540. + break;
  38541. +
  38542. + case FSG_STATE_CONFIG_CHANGE:
  38543. + rc = do_set_config(fsg, new_config);
  38544. + if (fsg->ep0_req_tag != exception_req_tag)
  38545. + break;
  38546. + if (rc != 0) // STALL on errors
  38547. + fsg_set_halt(fsg, fsg->ep0);
  38548. + else // Complete the status stage
  38549. + ep0_queue(fsg);
  38550. + break;
  38551. +
  38552. + case FSG_STATE_DISCONNECT:
  38553. + for (i = 0; i < fsg->nluns; ++i)
  38554. + fsg_lun_fsync_sub(fsg->luns + i);
  38555. + do_set_config(fsg, 0); // Unconfigured state
  38556. + break;
  38557. +
  38558. + case FSG_STATE_EXIT:
  38559. + case FSG_STATE_TERMINATED:
  38560. + do_set_config(fsg, 0); // Free resources
  38561. + spin_lock_irq(&fsg->lock);
  38562. + fsg->state = FSG_STATE_TERMINATED; // Stop the thread
  38563. + spin_unlock_irq(&fsg->lock);
  38564. + break;
  38565. + }
  38566. +}
  38567. +
  38568. +
  38569. +/*-------------------------------------------------------------------------*/
  38570. +
  38571. +static int fsg_main_thread(void *fsg_)
  38572. +{
  38573. + struct fsg_dev *fsg = fsg_;
  38574. +
  38575. + /* Allow the thread to be killed by a signal, but set the signal mask
  38576. + * to block everything but INT, TERM, KILL, and USR1. */
  38577. + allow_signal(SIGINT);
  38578. + allow_signal(SIGTERM);
  38579. + allow_signal(SIGKILL);
  38580. + allow_signal(SIGUSR1);
  38581. +
  38582. + /* Allow the thread to be frozen */
  38583. + set_freezable();
  38584. +
  38585. + /* Arrange for userspace references to be interpreted as kernel
  38586. + * pointers. That way we can pass a kernel pointer to a routine
  38587. + * that expects a __user pointer and it will work okay. */
  38588. + set_fs(get_ds());
  38589. +
  38590. + /* The main loop */
  38591. + while (fsg->state != FSG_STATE_TERMINATED) {
  38592. + if (exception_in_progress(fsg) || signal_pending(current)) {
  38593. + handle_exception(fsg);
  38594. + continue;
  38595. + }
  38596. +
  38597. + if (!fsg->running) {
  38598. + sleep_thread(fsg);
  38599. + continue;
  38600. + }
  38601. +
  38602. + if (get_next_command(fsg))
  38603. + continue;
  38604. +
  38605. + spin_lock_irq(&fsg->lock);
  38606. + if (!exception_in_progress(fsg))
  38607. + fsg->state = FSG_STATE_DATA_PHASE;
  38608. + spin_unlock_irq(&fsg->lock);
  38609. +
  38610. + if (do_scsi_command(fsg) || finish_reply(fsg))
  38611. + continue;
  38612. +
  38613. + spin_lock_irq(&fsg->lock);
  38614. + if (!exception_in_progress(fsg))
  38615. + fsg->state = FSG_STATE_STATUS_PHASE;
  38616. + spin_unlock_irq(&fsg->lock);
  38617. +
  38618. + if (send_status(fsg))
  38619. + continue;
  38620. +
  38621. + spin_lock_irq(&fsg->lock);
  38622. + if (!exception_in_progress(fsg))
  38623. + fsg->state = FSG_STATE_IDLE;
  38624. + spin_unlock_irq(&fsg->lock);
  38625. + }
  38626. +
  38627. + spin_lock_irq(&fsg->lock);
  38628. + fsg->thread_task = NULL;
  38629. + spin_unlock_irq(&fsg->lock);
  38630. +
  38631. + /* If we are exiting because of a signal, unregister the
  38632. + * gadget driver. */
  38633. + if (test_and_clear_bit(REGISTERED, &fsg->atomic_bitflags))
  38634. + usb_gadget_unregister_driver(&fsg_driver);
  38635. +
  38636. + /* Let the unbind and cleanup routines know the thread has exited */
  38637. + complete_and_exit(&fsg->thread_notifier, 0);
  38638. +}
  38639. +
  38640. +
  38641. +/*-------------------------------------------------------------------------*/
  38642. +
  38643. +
  38644. +/* The write permissions and store_xxx pointers are set in fsg_bind() */
  38645. +static DEVICE_ATTR(ro, 0444, fsg_show_ro, NULL);
  38646. +static DEVICE_ATTR(nofua, 0644, fsg_show_nofua, NULL);
  38647. +static DEVICE_ATTR(file, 0444, fsg_show_file, NULL);
  38648. +
  38649. +
  38650. +/*-------------------------------------------------------------------------*/
  38651. +
  38652. +static void fsg_release(struct kref *ref)
  38653. +{
  38654. + struct fsg_dev *fsg = container_of(ref, struct fsg_dev, ref);
  38655. +
  38656. + kfree(fsg->luns);
  38657. + kfree(fsg);
  38658. +}
  38659. +
  38660. +static void lun_release(struct device *dev)
  38661. +{
  38662. + struct rw_semaphore *filesem = dev_get_drvdata(dev);
  38663. + struct fsg_dev *fsg =
  38664. + container_of(filesem, struct fsg_dev, filesem);
  38665. +
  38666. + kref_put(&fsg->ref, fsg_release);
  38667. +}
  38668. +
  38669. +static void /* __init_or_exit */ fsg_unbind(struct usb_gadget *gadget)
  38670. +{
  38671. + struct fsg_dev *fsg = get_gadget_data(gadget);
  38672. + int i;
  38673. + struct fsg_lun *curlun;
  38674. + struct usb_request *req = fsg->ep0req;
  38675. +
  38676. + DBG(fsg, "unbind\n");
  38677. + clear_bit(REGISTERED, &fsg->atomic_bitflags);
  38678. +
  38679. + /* If the thread isn't already dead, tell it to exit now */
  38680. + if (fsg->state != FSG_STATE_TERMINATED) {
  38681. + raise_exception(fsg, FSG_STATE_EXIT);
  38682. + wait_for_completion(&fsg->thread_notifier);
  38683. +
  38684. + /* The cleanup routine waits for this completion also */
  38685. + complete(&fsg->thread_notifier);
  38686. + }
  38687. +
  38688. + /* Unregister the sysfs attribute files and the LUNs */
  38689. + for (i = 0; i < fsg->nluns; ++i) {
  38690. + curlun = &fsg->luns[i];
  38691. + if (curlun->registered) {
  38692. + device_remove_file(&curlun->dev, &dev_attr_nofua);
  38693. + device_remove_file(&curlun->dev, &dev_attr_ro);
  38694. + device_remove_file(&curlun->dev, &dev_attr_file);
  38695. + fsg_lun_close(curlun);
  38696. + device_unregister(&curlun->dev);
  38697. + curlun->registered = 0;
  38698. + }
  38699. + }
  38700. +
  38701. + /* Free the data buffers */
  38702. + for (i = 0; i < fsg_num_buffers; ++i)
  38703. + kfree(fsg->buffhds[i].buf);
  38704. +
  38705. + /* Free the request and buffer for endpoint 0 */
  38706. + if (req) {
  38707. + kfree(req->buf);
  38708. + usb_ep_free_request(fsg->ep0, req);
  38709. + }
  38710. +
  38711. + set_gadget_data(gadget, NULL);
  38712. +}
  38713. +
  38714. +
  38715. +static int __init check_parameters(struct fsg_dev *fsg)
  38716. +{
  38717. + int prot;
  38718. + int gcnum;
  38719. +
  38720. + /* Store the default values */
  38721. + mod_data.transport_type = USB_PR_BULK;
  38722. + mod_data.transport_name = "Bulk-only";
  38723. + mod_data.protocol_type = USB_SC_SCSI;
  38724. + mod_data.protocol_name = "Transparent SCSI";
  38725. +
  38726. + /* Some peripheral controllers are known not to be able to
  38727. + * halt bulk endpoints correctly. If one of them is present,
  38728. + * disable stalls.
  38729. + */
  38730. + if (gadget_is_at91(fsg->gadget))
  38731. + mod_data.can_stall = 0;
  38732. +
  38733. + if (mod_data.release == 0xffff) { // Parameter wasn't set
  38734. + gcnum = usb_gadget_controller_number(fsg->gadget);
  38735. + if (gcnum >= 0)
  38736. + mod_data.release = 0x0300 + gcnum;
  38737. + else {
  38738. + WARNING(fsg, "controller '%s' not recognized\n",
  38739. + fsg->gadget->name);
  38740. + mod_data.release = 0x0399;
  38741. + }
  38742. + }
  38743. +
  38744. + prot = simple_strtol(mod_data.protocol_parm, NULL, 0);
  38745. +
  38746. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  38747. + if (strnicmp(mod_data.transport_parm, "BBB", 10) == 0) {
  38748. + ; // Use default setting
  38749. + } else if (strnicmp(mod_data.transport_parm, "CB", 10) == 0) {
  38750. + mod_data.transport_type = USB_PR_CB;
  38751. + mod_data.transport_name = "Control-Bulk";
  38752. + } else if (strnicmp(mod_data.transport_parm, "CBI", 10) == 0) {
  38753. + mod_data.transport_type = USB_PR_CBI;
  38754. + mod_data.transport_name = "Control-Bulk-Interrupt";
  38755. + } else {
  38756. + ERROR(fsg, "invalid transport: %s\n", mod_data.transport_parm);
  38757. + return -EINVAL;
  38758. + }
  38759. +
  38760. + if (strnicmp(mod_data.protocol_parm, "SCSI", 10) == 0 ||
  38761. + prot == USB_SC_SCSI) {
  38762. + ; // Use default setting
  38763. + } else if (strnicmp(mod_data.protocol_parm, "RBC", 10) == 0 ||
  38764. + prot == USB_SC_RBC) {
  38765. + mod_data.protocol_type = USB_SC_RBC;
  38766. + mod_data.protocol_name = "RBC";
  38767. + } else if (strnicmp(mod_data.protocol_parm, "8020", 4) == 0 ||
  38768. + strnicmp(mod_data.protocol_parm, "ATAPI", 10) == 0 ||
  38769. + prot == USB_SC_8020) {
  38770. + mod_data.protocol_type = USB_SC_8020;
  38771. + mod_data.protocol_name = "8020i (ATAPI)";
  38772. + } else if (strnicmp(mod_data.protocol_parm, "QIC", 3) == 0 ||
  38773. + prot == USB_SC_QIC) {
  38774. + mod_data.protocol_type = USB_SC_QIC;
  38775. + mod_data.protocol_name = "QIC-157";
  38776. + } else if (strnicmp(mod_data.protocol_parm, "UFI", 10) == 0 ||
  38777. + prot == USB_SC_UFI) {
  38778. + mod_data.protocol_type = USB_SC_UFI;
  38779. + mod_data.protocol_name = "UFI";
  38780. + } else if (strnicmp(mod_data.protocol_parm, "8070", 4) == 0 ||
  38781. + prot == USB_SC_8070) {
  38782. + mod_data.protocol_type = USB_SC_8070;
  38783. + mod_data.protocol_name = "8070i";
  38784. + } else {
  38785. + ERROR(fsg, "invalid protocol: %s\n", mod_data.protocol_parm);
  38786. + return -EINVAL;
  38787. + }
  38788. +
  38789. + mod_data.buflen &= PAGE_CACHE_MASK;
  38790. + if (mod_data.buflen <= 0) {
  38791. + ERROR(fsg, "invalid buflen\n");
  38792. + return -ETOOSMALL;
  38793. + }
  38794. +
  38795. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  38796. +
  38797. + /* Serial string handling.
  38798. + * On a real device, the serial string would be loaded
  38799. + * from permanent storage. */
  38800. + if (mod_data.serial) {
  38801. + const char *ch;
  38802. + unsigned len = 0;
  38803. +
  38804. + /* Sanity check :
  38805. + * The CB[I] specification limits the serial string to
  38806. + * 12 uppercase hexadecimal characters.
  38807. + * BBB need at least 12 uppercase hexadecimal characters,
  38808. + * with a maximum of 126. */
  38809. + for (ch = mod_data.serial; *ch; ++ch) {
  38810. + ++len;
  38811. + if ((*ch < '0' || *ch > '9') &&
  38812. + (*ch < 'A' || *ch > 'F')) { /* not uppercase hex */
  38813. + WARNING(fsg,
  38814. + "Invalid serial string character: %c\n",
  38815. + *ch);
  38816. + goto no_serial;
  38817. + }
  38818. + }
  38819. + if (len > 126 ||
  38820. + (mod_data.transport_type == USB_PR_BULK && len < 12) ||
  38821. + (mod_data.transport_type != USB_PR_BULK && len > 12)) {
  38822. + WARNING(fsg, "Invalid serial string length!\n");
  38823. + goto no_serial;
  38824. + }
  38825. + fsg_strings[FSG_STRING_SERIAL - 1].s = mod_data.serial;
  38826. + } else {
  38827. + WARNING(fsg, "No serial-number string provided!\n");
  38828. + no_serial:
  38829. + device_desc.iSerialNumber = 0;
  38830. + }
  38831. +
  38832. + return 0;
  38833. +}
  38834. +
  38835. +
  38836. +static int __init fsg_bind(struct usb_gadget *gadget)
  38837. +{
  38838. + struct fsg_dev *fsg = the_fsg;
  38839. + int rc;
  38840. + int i;
  38841. + struct fsg_lun *curlun;
  38842. + struct usb_ep *ep;
  38843. + struct usb_request *req;
  38844. + char *pathbuf, *p;
  38845. +
  38846. + fsg->gadget = gadget;
  38847. + set_gadget_data(gadget, fsg);
  38848. + fsg->ep0 = gadget->ep0;
  38849. + fsg->ep0->driver_data = fsg;
  38850. +
  38851. + if ((rc = check_parameters(fsg)) != 0)
  38852. + goto out;
  38853. +
  38854. + if (mod_data.removable) { // Enable the store_xxx attributes
  38855. + dev_attr_file.attr.mode = 0644;
  38856. + dev_attr_file.store = fsg_store_file;
  38857. + if (!mod_data.cdrom) {
  38858. + dev_attr_ro.attr.mode = 0644;
  38859. + dev_attr_ro.store = fsg_store_ro;
  38860. + }
  38861. + }
  38862. +
  38863. + /* Only for removable media? */
  38864. + dev_attr_nofua.attr.mode = 0644;
  38865. + dev_attr_nofua.store = fsg_store_nofua;
  38866. +
  38867. + /* Find out how many LUNs there should be */
  38868. + i = mod_data.nluns;
  38869. + if (i == 0)
  38870. + i = max(mod_data.num_filenames, 1u);
  38871. + if (i > FSG_MAX_LUNS) {
  38872. + ERROR(fsg, "invalid number of LUNs: %d\n", i);
  38873. + rc = -EINVAL;
  38874. + goto out;
  38875. + }
  38876. +
  38877. + /* Create the LUNs, open their backing files, and register the
  38878. + * LUN devices in sysfs. */
  38879. + fsg->luns = kzalloc(i * sizeof(struct fsg_lun), GFP_KERNEL);
  38880. + if (!fsg->luns) {
  38881. + rc = -ENOMEM;
  38882. + goto out;
  38883. + }
  38884. + fsg->nluns = i;
  38885. +
  38886. + for (i = 0; i < fsg->nluns; ++i) {
  38887. + curlun = &fsg->luns[i];
  38888. + curlun->cdrom = !!mod_data.cdrom;
  38889. + curlun->ro = mod_data.cdrom || mod_data.ro[i];
  38890. + curlun->initially_ro = curlun->ro;
  38891. + curlun->removable = mod_data.removable;
  38892. + curlun->nofua = mod_data.nofua[i];
  38893. + curlun->dev.release = lun_release;
  38894. + curlun->dev.parent = &gadget->dev;
  38895. + curlun->dev.driver = &fsg_driver.driver;
  38896. + dev_set_drvdata(&curlun->dev, &fsg->filesem);
  38897. + dev_set_name(&curlun->dev,"%s-lun%d",
  38898. + dev_name(&gadget->dev), i);
  38899. +
  38900. + kref_get(&fsg->ref);
  38901. + rc = device_register(&curlun->dev);
  38902. + if (rc) {
  38903. + INFO(fsg, "failed to register LUN%d: %d\n", i, rc);
  38904. + put_device(&curlun->dev);
  38905. + goto out;
  38906. + }
  38907. + curlun->registered = 1;
  38908. +
  38909. + rc = device_create_file(&curlun->dev, &dev_attr_ro);
  38910. + if (rc)
  38911. + goto out;
  38912. + rc = device_create_file(&curlun->dev, &dev_attr_nofua);
  38913. + if (rc)
  38914. + goto out;
  38915. + rc = device_create_file(&curlun->dev, &dev_attr_file);
  38916. + if (rc)
  38917. + goto out;
  38918. +
  38919. + if (mod_data.file[i] && *mod_data.file[i]) {
  38920. + rc = fsg_lun_open(curlun, mod_data.file[i]);
  38921. + if (rc)
  38922. + goto out;
  38923. + } else if (!mod_data.removable) {
  38924. + ERROR(fsg, "no file given for LUN%d\n", i);
  38925. + rc = -EINVAL;
  38926. + goto out;
  38927. + }
  38928. + }
  38929. +
  38930. + /* Find all the endpoints we will use */
  38931. + usb_ep_autoconfig_reset(gadget);
  38932. + ep = usb_ep_autoconfig(gadget, &fsg_fs_bulk_in_desc);
  38933. + if (!ep)
  38934. + goto autoconf_fail;
  38935. + ep->driver_data = fsg; // claim the endpoint
  38936. + fsg->bulk_in = ep;
  38937. +
  38938. + ep = usb_ep_autoconfig(gadget, &fsg_fs_bulk_out_desc);
  38939. + if (!ep)
  38940. + goto autoconf_fail;
  38941. + ep->driver_data = fsg; // claim the endpoint
  38942. + fsg->bulk_out = ep;
  38943. +
  38944. + if (transport_is_cbi()) {
  38945. + ep = usb_ep_autoconfig(gadget, &fsg_fs_intr_in_desc);
  38946. + if (!ep)
  38947. + goto autoconf_fail;
  38948. + ep->driver_data = fsg; // claim the endpoint
  38949. + fsg->intr_in = ep;
  38950. + }
  38951. +
  38952. + /* Fix up the descriptors */
  38953. + device_desc.idVendor = cpu_to_le16(mod_data.vendor);
  38954. + device_desc.idProduct = cpu_to_le16(mod_data.product);
  38955. + device_desc.bcdDevice = cpu_to_le16(mod_data.release);
  38956. +
  38957. + i = (transport_is_cbi() ? 3 : 2); // Number of endpoints
  38958. + fsg_intf_desc.bNumEndpoints = i;
  38959. + fsg_intf_desc.bInterfaceSubClass = mod_data.protocol_type;
  38960. + fsg_intf_desc.bInterfaceProtocol = mod_data.transport_type;
  38961. + fsg_fs_function[i + FSG_FS_FUNCTION_PRE_EP_ENTRIES] = NULL;
  38962. +
  38963. + if (gadget_is_dualspeed(gadget)) {
  38964. + fsg_hs_function[i + FSG_HS_FUNCTION_PRE_EP_ENTRIES] = NULL;
  38965. +
  38966. + /* Assume endpoint addresses are the same for both speeds */
  38967. + fsg_hs_bulk_in_desc.bEndpointAddress =
  38968. + fsg_fs_bulk_in_desc.bEndpointAddress;
  38969. + fsg_hs_bulk_out_desc.bEndpointAddress =
  38970. + fsg_fs_bulk_out_desc.bEndpointAddress;
  38971. + fsg_hs_intr_in_desc.bEndpointAddress =
  38972. + fsg_fs_intr_in_desc.bEndpointAddress;
  38973. + }
  38974. +
  38975. + if (gadget_is_superspeed(gadget)) {
  38976. + unsigned max_burst;
  38977. +
  38978. + fsg_ss_function[i + FSG_SS_FUNCTION_PRE_EP_ENTRIES] = NULL;
  38979. +
  38980. + /* Calculate bMaxBurst, we know packet size is 1024 */
  38981. + max_burst = min_t(unsigned, mod_data.buflen / 1024, 15);
  38982. +
  38983. + /* Assume endpoint addresses are the same for both speeds */
  38984. + fsg_ss_bulk_in_desc.bEndpointAddress =
  38985. + fsg_fs_bulk_in_desc.bEndpointAddress;
  38986. + fsg_ss_bulk_in_comp_desc.bMaxBurst = max_burst;
  38987. +
  38988. + fsg_ss_bulk_out_desc.bEndpointAddress =
  38989. + fsg_fs_bulk_out_desc.bEndpointAddress;
  38990. + fsg_ss_bulk_out_comp_desc.bMaxBurst = max_burst;
  38991. + }
  38992. +
  38993. + if (gadget_is_otg(gadget))
  38994. + fsg_otg_desc.bmAttributes |= USB_OTG_HNP;
  38995. +
  38996. + rc = -ENOMEM;
  38997. +
  38998. + /* Allocate the request and buffer for endpoint 0 */
  38999. + fsg->ep0req = req = usb_ep_alloc_request(fsg->ep0, GFP_KERNEL);
  39000. + if (!req)
  39001. + goto out;
  39002. + req->buf = kmalloc(EP0_BUFSIZE, GFP_KERNEL);
  39003. + if (!req->buf)
  39004. + goto out;
  39005. + req->complete = ep0_complete;
  39006. +
  39007. + /* Allocate the data buffers */
  39008. + for (i = 0; i < fsg_num_buffers; ++i) {
  39009. + struct fsg_buffhd *bh = &fsg->buffhds[i];
  39010. +
  39011. + /* Allocate for the bulk-in endpoint. We assume that
  39012. + * the buffer will also work with the bulk-out (and
  39013. + * interrupt-in) endpoint. */
  39014. + bh->buf = kmalloc(mod_data.buflen, GFP_KERNEL);
  39015. + if (!bh->buf)
  39016. + goto out;
  39017. + bh->next = bh + 1;
  39018. + }
  39019. + fsg->buffhds[fsg_num_buffers - 1].next = &fsg->buffhds[0];
  39020. +
  39021. + /* This should reflect the actual gadget power source */
  39022. + usb_gadget_set_selfpowered(gadget);
  39023. +
  39024. + snprintf(fsg_string_manufacturer, sizeof fsg_string_manufacturer,
  39025. + "%s %s with %s",
  39026. + init_utsname()->sysname, init_utsname()->release,
  39027. + gadget->name);
  39028. +
  39029. + fsg->thread_task = kthread_create(fsg_main_thread, fsg,
  39030. + "file-storage-gadget");
  39031. + if (IS_ERR(fsg->thread_task)) {
  39032. + rc = PTR_ERR(fsg->thread_task);
  39033. + goto out;
  39034. + }
  39035. +
  39036. + INFO(fsg, DRIVER_DESC ", version: " DRIVER_VERSION "\n");
  39037. + INFO(fsg, "NOTE: This driver is deprecated. "
  39038. + "Consider using g_mass_storage instead.\n");
  39039. + INFO(fsg, "Number of LUNs=%d\n", fsg->nluns);
  39040. +
  39041. + pathbuf = kmalloc(PATH_MAX, GFP_KERNEL);
  39042. + for (i = 0; i < fsg->nluns; ++i) {
  39043. + curlun = &fsg->luns[i];
  39044. + if (fsg_lun_is_open(curlun)) {
  39045. + p = NULL;
  39046. + if (pathbuf) {
  39047. + p = d_path(&curlun->filp->f_path,
  39048. + pathbuf, PATH_MAX);
  39049. + if (IS_ERR(p))
  39050. + p = NULL;
  39051. + }
  39052. + LINFO(curlun, "ro=%d, nofua=%d, file: %s\n",
  39053. + curlun->ro, curlun->nofua, (p ? p : "(error)"));
  39054. + }
  39055. + }
  39056. + kfree(pathbuf);
  39057. +
  39058. + DBG(fsg, "transport=%s (x%02x)\n",
  39059. + mod_data.transport_name, mod_data.transport_type);
  39060. + DBG(fsg, "protocol=%s (x%02x)\n",
  39061. + mod_data.protocol_name, mod_data.protocol_type);
  39062. + DBG(fsg, "VendorID=x%04x, ProductID=x%04x, Release=x%04x\n",
  39063. + mod_data.vendor, mod_data.product, mod_data.release);
  39064. + DBG(fsg, "removable=%d, stall=%d, cdrom=%d, buflen=%u\n",
  39065. + mod_data.removable, mod_data.can_stall,
  39066. + mod_data.cdrom, mod_data.buflen);
  39067. + DBG(fsg, "I/O thread pid: %d\n", task_pid_nr(fsg->thread_task));
  39068. +
  39069. + set_bit(REGISTERED, &fsg->atomic_bitflags);
  39070. +
  39071. + /* Tell the thread to start working */
  39072. + wake_up_process(fsg->thread_task);
  39073. + return 0;
  39074. +
  39075. +autoconf_fail:
  39076. + ERROR(fsg, "unable to autoconfigure all endpoints\n");
  39077. + rc = -ENOTSUPP;
  39078. +
  39079. +out:
  39080. + fsg->state = FSG_STATE_TERMINATED; // The thread is dead
  39081. + fsg_unbind(gadget);
  39082. + complete(&fsg->thread_notifier);
  39083. + return rc;
  39084. +}
  39085. +
  39086. +
  39087. +/*-------------------------------------------------------------------------*/
  39088. +
  39089. +static void fsg_suspend(struct usb_gadget *gadget)
  39090. +{
  39091. + struct fsg_dev *fsg = get_gadget_data(gadget);
  39092. +
  39093. + DBG(fsg, "suspend\n");
  39094. + set_bit(SUSPENDED, &fsg->atomic_bitflags);
  39095. +}
  39096. +
  39097. +static void fsg_resume(struct usb_gadget *gadget)
  39098. +{
  39099. + struct fsg_dev *fsg = get_gadget_data(gadget);
  39100. +
  39101. + DBG(fsg, "resume\n");
  39102. + clear_bit(SUSPENDED, &fsg->atomic_bitflags);
  39103. +}
  39104. +
  39105. +
  39106. +/*-------------------------------------------------------------------------*/
  39107. +
  39108. +static struct usb_gadget_driver fsg_driver = {
  39109. + .max_speed = USB_SPEED_SUPER,
  39110. + .function = (char *) fsg_string_product,
  39111. + .unbind = fsg_unbind,
  39112. + .disconnect = fsg_disconnect,
  39113. + .setup = fsg_setup,
  39114. + .suspend = fsg_suspend,
  39115. + .resume = fsg_resume,
  39116. +
  39117. + .driver = {
  39118. + .name = DRIVER_NAME,
  39119. + .owner = THIS_MODULE,
  39120. + // .release = ...
  39121. + // .suspend = ...
  39122. + // .resume = ...
  39123. + },
  39124. +};
  39125. +
  39126. +
  39127. +static int __init fsg_alloc(void)
  39128. +{
  39129. + struct fsg_dev *fsg;
  39130. +
  39131. + fsg = kzalloc(sizeof *fsg +
  39132. + fsg_num_buffers * sizeof *(fsg->buffhds), GFP_KERNEL);
  39133. +
  39134. + if (!fsg)
  39135. + return -ENOMEM;
  39136. + spin_lock_init(&fsg->lock);
  39137. + init_rwsem(&fsg->filesem);
  39138. + kref_init(&fsg->ref);
  39139. + init_completion(&fsg->thread_notifier);
  39140. +
  39141. + the_fsg = fsg;
  39142. + return 0;
  39143. +}
  39144. +
  39145. +
  39146. +static int __init fsg_init(void)
  39147. +{
  39148. + int rc;
  39149. + struct fsg_dev *fsg;
  39150. +
  39151. + rc = fsg_num_buffers_validate();
  39152. + if (rc != 0)
  39153. + return rc;
  39154. +
  39155. + if ((rc = fsg_alloc()) != 0)
  39156. + return rc;
  39157. + fsg = the_fsg;
  39158. + if ((rc = usb_gadget_probe_driver(&fsg_driver, fsg_bind)) != 0)
  39159. + kref_put(&fsg->ref, fsg_release);
  39160. + return rc;
  39161. +}
  39162. +module_init(fsg_init);
  39163. +
  39164. +
  39165. +static void __exit fsg_cleanup(void)
  39166. +{
  39167. + struct fsg_dev *fsg = the_fsg;
  39168. +
  39169. + /* Unregister the driver iff the thread hasn't already done so */
  39170. + if (test_and_clear_bit(REGISTERED, &fsg->atomic_bitflags))
  39171. + usb_gadget_unregister_driver(&fsg_driver);
  39172. +
  39173. + /* Wait for the thread to finish up */
  39174. + wait_for_completion(&fsg->thread_notifier);
  39175. +
  39176. + kref_put(&fsg->ref, fsg_release);
  39177. +}
  39178. +module_exit(fsg_cleanup);
  39179. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_common_port/changes.txt linux-3.12.26/drivers/usb/host/dwc_common_port/changes.txt
  39180. --- linux-3.12.26.orig/drivers/usb/host/dwc_common_port/changes.txt 1970-01-01 01:00:00.000000000 +0100
  39181. +++ linux-3.12.26/drivers/usb/host/dwc_common_port/changes.txt 2014-08-06 16:50:14.733964192 +0200
  39182. @@ -0,0 +1,174 @@
  39183. +
  39184. +dwc_read_reg32() and friends now take an additional parameter, a pointer to an
  39185. +IO context struct. The IO context struct should live in an os-dependent struct
  39186. +in your driver. As an example, the dwc_usb3 driver has an os-dependent struct
  39187. +named 'os_dep' embedded in the main device struct. So there these calls look
  39188. +like this:
  39189. +
  39190. + dwc_read_reg32(&usb3_dev->os_dep.ioctx, &pcd->dev_global_regs->dcfg);
  39191. +
  39192. + dwc_write_reg32(&usb3_dev->os_dep.ioctx,
  39193. + &pcd->dev_global_regs->dcfg, 0);
  39194. +
  39195. +Note that for the existing Linux driver ports, it is not necessary to actually
  39196. +define the 'ioctx' member in the os-dependent struct. Since Linux does not
  39197. +require an IO context, its macros for dwc_read_reg32() and friends do not
  39198. +use the context pointer, so it is optimized away by the compiler. But it is
  39199. +necessary to add the pointer parameter to all of the call sites, to be ready
  39200. +for any future ports (such as FreeBSD) which do require an IO context.
  39201. +
  39202. +
  39203. +Similarly, dwc_alloc(), dwc_alloc_atomic(), dwc_strdup(), and dwc_free() now
  39204. +take an additional parameter, a pointer to a memory context. Examples:
  39205. +
  39206. + addr = dwc_alloc(&usb3_dev->os_dep.memctx, size);
  39207. +
  39208. + dwc_free(&usb3_dev->os_dep.memctx, addr);
  39209. +
  39210. +Again, for the Linux ports, it is not necessary to actually define the memctx
  39211. +member, but it is necessary to add the pointer parameter to all of the call
  39212. +sites.
  39213. +
  39214. +
  39215. +Same for dwc_dma_alloc() and dwc_dma_free(). Examples:
  39216. +
  39217. + virt_addr = dwc_dma_alloc(&usb3_dev->os_dep.dmactx, size, &phys_addr);
  39218. +
  39219. + dwc_dma_free(&usb3_dev->os_dep.dmactx, size, virt_addr, phys_addr);
  39220. +
  39221. +
  39222. +Same for dwc_mutex_alloc() and dwc_mutex_free(). Examples:
  39223. +
  39224. + mutex = dwc_mutex_alloc(&usb3_dev->os_dep.mtxctx);
  39225. +
  39226. + dwc_mutex_free(&usb3_dev->os_dep.mtxctx, mutex);
  39227. +
  39228. +
  39229. +Same for dwc_spinlock_alloc() and dwc_spinlock_free(). Examples:
  39230. +
  39231. + lock = dwc_spinlock_alloc(&usb3_dev->osdep.splctx);
  39232. +
  39233. + dwc_spinlock_free(&usb3_dev->osdep.splctx, lock);
  39234. +
  39235. +
  39236. +Same for dwc_timer_alloc(). Example:
  39237. +
  39238. + timer = dwc_timer_alloc(&usb3_dev->os_dep.tmrctx, "dwc_usb3_tmr1",
  39239. + cb_func, cb_data);
  39240. +
  39241. +
  39242. +Same for dwc_waitq_alloc(). Example:
  39243. +
  39244. + waitq = dwc_waitq_alloc(&usb3_dev->os_dep.wtqctx);
  39245. +
  39246. +
  39247. +Same for dwc_thread_run(). Example:
  39248. +
  39249. + thread = dwc_thread_run(&usb3_dev->os_dep.thdctx, func,
  39250. + "dwc_usb3_thd1", data);
  39251. +
  39252. +
  39253. +Same for dwc_workq_alloc(). Example:
  39254. +
  39255. + workq = dwc_workq_alloc(&usb3_dev->osdep.wkqctx, "dwc_usb3_wkq1");
  39256. +
  39257. +
  39258. +Same for dwc_task_alloc(). Example:
  39259. +
  39260. + task = dwc_task_alloc(&usb3_dev->os_dep.tskctx, "dwc_usb3_tsk1",
  39261. + cb_func, cb_data);
  39262. +
  39263. +
  39264. +In addition to the context pointer additions, a few core functions have had
  39265. +other changes made to their parameters:
  39266. +
  39267. +The 'flags' parameter to dwc_spinlock_irqsave() and dwc_spinunlock_irqrestore()
  39268. +has been changed from a uint64_t to a dwc_irqflags_t.
  39269. +
  39270. +dwc_thread_should_stop() now takes a 'dwc_thread_t *' parameter, because the
  39271. +FreeBSD equivalent of that function requires it.
  39272. +
  39273. +And, in addition to the context pointer, dwc_task_alloc() also adds a
  39274. +'char *name' parameter, to be consistent with dwc_thread_run() and
  39275. +dwc_workq_alloc(), and because the FreeBSD equivalent of that function
  39276. +requires a unique name.
  39277. +
  39278. +
  39279. +Here is a complete list of the core functions that now take a pointer to a
  39280. +context as their first parameter:
  39281. +
  39282. + dwc_read_reg32
  39283. + dwc_read_reg64
  39284. + dwc_write_reg32
  39285. + dwc_write_reg64
  39286. + dwc_modify_reg32
  39287. + dwc_modify_reg64
  39288. + dwc_alloc
  39289. + dwc_alloc_atomic
  39290. + dwc_strdup
  39291. + dwc_free
  39292. + dwc_dma_alloc
  39293. + dwc_dma_free
  39294. + dwc_mutex_alloc
  39295. + dwc_mutex_free
  39296. + dwc_spinlock_alloc
  39297. + dwc_spinlock_free
  39298. + dwc_timer_alloc
  39299. + dwc_waitq_alloc
  39300. + dwc_thread_run
  39301. + dwc_workq_alloc
  39302. + dwc_task_alloc Also adds a 'char *name' as its 2nd parameter
  39303. +
  39304. +And here are the core functions that have other changes to their parameters:
  39305. +
  39306. + dwc_spinlock_irqsave 'flags' param is now a 'dwc_irqflags_t *'
  39307. + dwc_spinunlock_irqrestore 'flags' param is now a 'dwc_irqflags_t'
  39308. + dwc_thread_should_stop Adds a 'dwc_thread_t *' parameter
  39309. +
  39310. +
  39311. +
  39312. +The changes to the core functions also require some of the other library
  39313. +functions to change:
  39314. +
  39315. + dwc_cc_if_alloc() and dwc_cc_if_free() now take a 'void *memctx'
  39316. + (for memory allocation) as the 1st param and a 'void *mtxctx'
  39317. + (for mutex allocation) as the 2nd param.
  39318. +
  39319. + dwc_cc_clear(), dwc_cc_add(), dwc_cc_change(), dwc_cc_remove(),
  39320. + dwc_cc_data_for_save(), and dwc_cc_restore_from_data() now take a
  39321. + 'void *memctx' as the 1st param.
  39322. +
  39323. + dwc_dh_modpow(), dwc_dh_pk(), and dwc_dh_derive_keys() now take a
  39324. + 'void *memctx' as the 1st param.
  39325. +
  39326. + dwc_modpow() now takes a 'void *memctx' as the 1st param.
  39327. +
  39328. + dwc_alloc_notification_manager() now takes a 'void *memctx' as the
  39329. + 1st param and a 'void *wkqctx' (for work queue allocation) as the 2nd
  39330. + param, and also now returns an integer value that is non-zero if
  39331. + allocation of its data structures or work queue fails.
  39332. +
  39333. + dwc_register_notifier() now takes a 'void *memctx' as the 1st param.
  39334. +
  39335. + dwc_memory_debug_start() now takes a 'void *mem_ctx' as the first
  39336. + param, and also now returns an integer value that is non-zero if
  39337. + allocation of its data structures fails.
  39338. +
  39339. +
  39340. +
  39341. +Other miscellaneous changes:
  39342. +
  39343. +The DEBUG_MEMORY and DEBUG_REGS #define's have been renamed to
  39344. +DWC_DEBUG_MEMORY and DWC_DEBUG_REGS.
  39345. +
  39346. +The following #define's have been added to allow selectively compiling library
  39347. +features:
  39348. +
  39349. + DWC_CCLIB
  39350. + DWC_CRYPTOLIB
  39351. + DWC_NOTIFYLIB
  39352. + DWC_UTFLIB
  39353. +
  39354. +A DWC_LIBMODULE #define has also been added. If this is not defined, then the
  39355. +module code in dwc_common_linux.c is not compiled in. This allows linking the
  39356. +library code directly into a driver module, instead of as a standalone module.
  39357. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_common_port/doc/doxygen.cfg linux-3.12.26/drivers/usb/host/dwc_common_port/doc/doxygen.cfg
  39358. --- linux-3.12.26.orig/drivers/usb/host/dwc_common_port/doc/doxygen.cfg 1970-01-01 01:00:00.000000000 +0100
  39359. +++ linux-3.12.26/drivers/usb/host/dwc_common_port/doc/doxygen.cfg 2014-08-06 16:50:14.737964224 +0200
  39360. @@ -0,0 +1,270 @@
  39361. +# Doxyfile 1.4.5
  39362. +
  39363. +#---------------------------------------------------------------------------
  39364. +# Project related configuration options
  39365. +#---------------------------------------------------------------------------
  39366. +PROJECT_NAME = "Synopsys DWC Portability and Common Library for UWB"
  39367. +PROJECT_NUMBER =
  39368. +OUTPUT_DIRECTORY = doc
  39369. +CREATE_SUBDIRS = NO
  39370. +OUTPUT_LANGUAGE = English
  39371. +BRIEF_MEMBER_DESC = YES
  39372. +REPEAT_BRIEF = YES
  39373. +ABBREVIATE_BRIEF = "The $name class" \
  39374. + "The $name widget" \
  39375. + "The $name file" \
  39376. + is \
  39377. + provides \
  39378. + specifies \
  39379. + contains \
  39380. + represents \
  39381. + a \
  39382. + an \
  39383. + the
  39384. +ALWAYS_DETAILED_SEC = YES
  39385. +INLINE_INHERITED_MEMB = NO
  39386. +FULL_PATH_NAMES = NO
  39387. +STRIP_FROM_PATH = ..
  39388. +STRIP_FROM_INC_PATH =
  39389. +SHORT_NAMES = NO
  39390. +JAVADOC_AUTOBRIEF = YES
  39391. +MULTILINE_CPP_IS_BRIEF = NO
  39392. +DETAILS_AT_TOP = YES
  39393. +INHERIT_DOCS = YES
  39394. +SEPARATE_MEMBER_PAGES = NO
  39395. +TAB_SIZE = 8
  39396. +ALIASES =
  39397. +OPTIMIZE_OUTPUT_FOR_C = YES
  39398. +OPTIMIZE_OUTPUT_JAVA = NO
  39399. +BUILTIN_STL_SUPPORT = NO
  39400. +DISTRIBUTE_GROUP_DOC = NO
  39401. +SUBGROUPING = NO
  39402. +#---------------------------------------------------------------------------
  39403. +# Build related configuration options
  39404. +#---------------------------------------------------------------------------
  39405. +EXTRACT_ALL = NO
  39406. +EXTRACT_PRIVATE = NO
  39407. +EXTRACT_STATIC = YES
  39408. +EXTRACT_LOCAL_CLASSES = NO
  39409. +EXTRACT_LOCAL_METHODS = NO
  39410. +HIDE_UNDOC_MEMBERS = NO
  39411. +HIDE_UNDOC_CLASSES = NO
  39412. +HIDE_FRIEND_COMPOUNDS = NO
  39413. +HIDE_IN_BODY_DOCS = NO
  39414. +INTERNAL_DOCS = NO
  39415. +CASE_SENSE_NAMES = YES
  39416. +HIDE_SCOPE_NAMES = NO
  39417. +SHOW_INCLUDE_FILES = NO
  39418. +INLINE_INFO = YES
  39419. +SORT_MEMBER_DOCS = NO
  39420. +SORT_BRIEF_DOCS = NO
  39421. +SORT_BY_SCOPE_NAME = NO
  39422. +GENERATE_TODOLIST = YES
  39423. +GENERATE_TESTLIST = YES
  39424. +GENERATE_BUGLIST = YES
  39425. +GENERATE_DEPRECATEDLIST= YES
  39426. +ENABLED_SECTIONS =
  39427. +MAX_INITIALIZER_LINES = 30
  39428. +SHOW_USED_FILES = YES
  39429. +SHOW_DIRECTORIES = YES
  39430. +FILE_VERSION_FILTER =
  39431. +#---------------------------------------------------------------------------
  39432. +# configuration options related to warning and progress messages
  39433. +#---------------------------------------------------------------------------
  39434. +QUIET = YES
  39435. +WARNINGS = YES
  39436. +WARN_IF_UNDOCUMENTED = NO
  39437. +WARN_IF_DOC_ERROR = YES
  39438. +WARN_NO_PARAMDOC = YES
  39439. +WARN_FORMAT = "$file:$line: $text"
  39440. +WARN_LOGFILE =
  39441. +#---------------------------------------------------------------------------
  39442. +# configuration options related to the input files
  39443. +#---------------------------------------------------------------------------
  39444. +INPUT = .
  39445. +FILE_PATTERNS = *.c \
  39446. + *.cc \
  39447. + *.cxx \
  39448. + *.cpp \
  39449. + *.c++ \
  39450. + *.d \
  39451. + *.java \
  39452. + *.ii \
  39453. + *.ixx \
  39454. + *.ipp \
  39455. + *.i++ \
  39456. + *.inl \
  39457. + *.h \
  39458. + *.hh \
  39459. + *.hxx \
  39460. + *.hpp \
  39461. + *.h++ \
  39462. + *.idl \
  39463. + *.odl \
  39464. + *.cs \
  39465. + *.php \
  39466. + *.php3 \
  39467. + *.inc \
  39468. + *.m \
  39469. + *.mm \
  39470. + *.dox \
  39471. + *.py \
  39472. + *.C \
  39473. + *.CC \
  39474. + *.C++ \
  39475. + *.II \
  39476. + *.I++ \
  39477. + *.H \
  39478. + *.HH \
  39479. + *.H++ \
  39480. + *.CS \
  39481. + *.PHP \
  39482. + *.PHP3 \
  39483. + *.M \
  39484. + *.MM \
  39485. + *.PY
  39486. +RECURSIVE = NO
  39487. +EXCLUDE =
  39488. +EXCLUDE_SYMLINKS = NO
  39489. +EXCLUDE_PATTERNS =
  39490. +EXAMPLE_PATH =
  39491. +EXAMPLE_PATTERNS = *
  39492. +EXAMPLE_RECURSIVE = NO
  39493. +IMAGE_PATH =
  39494. +INPUT_FILTER =
  39495. +FILTER_PATTERNS =
  39496. +FILTER_SOURCE_FILES = NO
  39497. +#---------------------------------------------------------------------------
  39498. +# configuration options related to source browsing
  39499. +#---------------------------------------------------------------------------
  39500. +SOURCE_BROWSER = NO
  39501. +INLINE_SOURCES = NO
  39502. +STRIP_CODE_COMMENTS = YES
  39503. +REFERENCED_BY_RELATION = YES
  39504. +REFERENCES_RELATION = YES
  39505. +USE_HTAGS = NO
  39506. +VERBATIM_HEADERS = NO
  39507. +#---------------------------------------------------------------------------
  39508. +# configuration options related to the alphabetical class index
  39509. +#---------------------------------------------------------------------------
  39510. +ALPHABETICAL_INDEX = NO
  39511. +COLS_IN_ALPHA_INDEX = 5
  39512. +IGNORE_PREFIX =
  39513. +#---------------------------------------------------------------------------
  39514. +# configuration options related to the HTML output
  39515. +#---------------------------------------------------------------------------
  39516. +GENERATE_HTML = YES
  39517. +HTML_OUTPUT = html
  39518. +HTML_FILE_EXTENSION = .html
  39519. +HTML_HEADER =
  39520. +HTML_FOOTER =
  39521. +HTML_STYLESHEET =
  39522. +HTML_ALIGN_MEMBERS = YES
  39523. +GENERATE_HTMLHELP = NO
  39524. +CHM_FILE =
  39525. +HHC_LOCATION =
  39526. +GENERATE_CHI = NO
  39527. +BINARY_TOC = NO
  39528. +TOC_EXPAND = NO
  39529. +DISABLE_INDEX = NO
  39530. +ENUM_VALUES_PER_LINE = 4
  39531. +GENERATE_TREEVIEW = YES
  39532. +TREEVIEW_WIDTH = 250
  39533. +#---------------------------------------------------------------------------
  39534. +# configuration options related to the LaTeX output
  39535. +#---------------------------------------------------------------------------
  39536. +GENERATE_LATEX = NO
  39537. +LATEX_OUTPUT = latex
  39538. +LATEX_CMD_NAME = latex
  39539. +MAKEINDEX_CMD_NAME = makeindex
  39540. +COMPACT_LATEX = NO
  39541. +PAPER_TYPE = a4wide
  39542. +EXTRA_PACKAGES =
  39543. +LATEX_HEADER =
  39544. +PDF_HYPERLINKS = NO
  39545. +USE_PDFLATEX = NO
  39546. +LATEX_BATCHMODE = NO
  39547. +LATEX_HIDE_INDICES = NO
  39548. +#---------------------------------------------------------------------------
  39549. +# configuration options related to the RTF output
  39550. +#---------------------------------------------------------------------------
  39551. +GENERATE_RTF = NO
  39552. +RTF_OUTPUT = rtf
  39553. +COMPACT_RTF = NO
  39554. +RTF_HYPERLINKS = NO
  39555. +RTF_STYLESHEET_FILE =
  39556. +RTF_EXTENSIONS_FILE =
  39557. +#---------------------------------------------------------------------------
  39558. +# configuration options related to the man page output
  39559. +#---------------------------------------------------------------------------
  39560. +GENERATE_MAN = NO
  39561. +MAN_OUTPUT = man
  39562. +MAN_EXTENSION = .3
  39563. +MAN_LINKS = NO
  39564. +#---------------------------------------------------------------------------
  39565. +# configuration options related to the XML output
  39566. +#---------------------------------------------------------------------------
  39567. +GENERATE_XML = NO
  39568. +XML_OUTPUT = xml
  39569. +XML_SCHEMA =
  39570. +XML_DTD =
  39571. +XML_PROGRAMLISTING = YES
  39572. +#---------------------------------------------------------------------------
  39573. +# configuration options for the AutoGen Definitions output
  39574. +#---------------------------------------------------------------------------
  39575. +GENERATE_AUTOGEN_DEF = NO
  39576. +#---------------------------------------------------------------------------
  39577. +# configuration options related to the Perl module output
  39578. +#---------------------------------------------------------------------------
  39579. +GENERATE_PERLMOD = NO
  39580. +PERLMOD_LATEX = NO
  39581. +PERLMOD_PRETTY = YES
  39582. +PERLMOD_MAKEVAR_PREFIX =
  39583. +#---------------------------------------------------------------------------
  39584. +# Configuration options related to the preprocessor
  39585. +#---------------------------------------------------------------------------
  39586. +ENABLE_PREPROCESSING = YES
  39587. +MACRO_EXPANSION = NO
  39588. +EXPAND_ONLY_PREDEF = NO
  39589. +SEARCH_INCLUDES = YES
  39590. +INCLUDE_PATH =
  39591. +INCLUDE_FILE_PATTERNS =
  39592. +PREDEFINED = DEBUG DEBUG_MEMORY
  39593. +EXPAND_AS_DEFINED =
  39594. +SKIP_FUNCTION_MACROS = YES
  39595. +#---------------------------------------------------------------------------
  39596. +# Configuration::additions related to external references
  39597. +#---------------------------------------------------------------------------
  39598. +TAGFILES =
  39599. +GENERATE_TAGFILE =
  39600. +ALLEXTERNALS = NO
  39601. +EXTERNAL_GROUPS = YES
  39602. +PERL_PATH = /usr/bin/perl
  39603. +#---------------------------------------------------------------------------
  39604. +# Configuration options related to the dot tool
  39605. +#---------------------------------------------------------------------------
  39606. +CLASS_DIAGRAMS = YES
  39607. +HIDE_UNDOC_RELATIONS = YES
  39608. +HAVE_DOT = NO
  39609. +CLASS_GRAPH = YES
  39610. +COLLABORATION_GRAPH = YES
  39611. +GROUP_GRAPHS = YES
  39612. +UML_LOOK = NO
  39613. +TEMPLATE_RELATIONS = NO
  39614. +INCLUDE_GRAPH = NO
  39615. +INCLUDED_BY_GRAPH = YES
  39616. +CALL_GRAPH = NO
  39617. +GRAPHICAL_HIERARCHY = YES
  39618. +DIRECTORY_GRAPH = YES
  39619. +DOT_IMAGE_FORMAT = png
  39620. +DOT_PATH =
  39621. +DOTFILE_DIRS =
  39622. +MAX_DOT_GRAPH_DEPTH = 1000
  39623. +DOT_TRANSPARENT = NO
  39624. +DOT_MULTI_TARGETS = NO
  39625. +GENERATE_LEGEND = YES
  39626. +DOT_CLEANUP = YES
  39627. +#---------------------------------------------------------------------------
  39628. +# Configuration::additions related to the search engine
  39629. +#---------------------------------------------------------------------------
  39630. +SEARCHENGINE = NO
  39631. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_common_port/dwc_cc.c linux-3.12.26/drivers/usb/host/dwc_common_port/dwc_cc.c
  39632. --- linux-3.12.26.orig/drivers/usb/host/dwc_common_port/dwc_cc.c 1970-01-01 01:00:00.000000000 +0100
  39633. +++ linux-3.12.26/drivers/usb/host/dwc_common_port/dwc_cc.c 2014-08-06 16:50:14.737964224 +0200
  39634. @@ -0,0 +1,532 @@
  39635. +/* =========================================================================
  39636. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_cc.c $
  39637. + * $Revision: #4 $
  39638. + * $Date: 2010/11/04 $
  39639. + * $Change: 1621692 $
  39640. + *
  39641. + * Synopsys Portability Library Software and documentation
  39642. + * (hereinafter, "Software") is an Unsupported proprietary work of
  39643. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  39644. + * between Synopsys and you.
  39645. + *
  39646. + * The Software IS NOT an item of Licensed Software or Licensed Product
  39647. + * under any End User Software License Agreement or Agreement for
  39648. + * Licensed Product with Synopsys or any supplement thereto. You are
  39649. + * permitted to use and redistribute this Software in source and binary
  39650. + * forms, with or without modification, provided that redistributions
  39651. + * of source code must retain this notice. You may not view, use,
  39652. + * disclose, copy or distribute this file or any information contained
  39653. + * herein except pursuant to this license grant from Synopsys. If you
  39654. + * do not agree with this notice, including the disclaimer below, then
  39655. + * you are not authorized to use the Software.
  39656. + *
  39657. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  39658. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  39659. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  39660. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  39661. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  39662. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  39663. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  39664. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  39665. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  39666. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  39667. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  39668. + * DAMAGE.
  39669. + * ========================================================================= */
  39670. +#ifdef DWC_CCLIB
  39671. +
  39672. +#include "dwc_cc.h"
  39673. +
  39674. +typedef struct dwc_cc
  39675. +{
  39676. + uint32_t uid;
  39677. + uint8_t chid[16];
  39678. + uint8_t cdid[16];
  39679. + uint8_t ck[16];
  39680. + uint8_t *name;
  39681. + uint8_t length;
  39682. + DWC_CIRCLEQ_ENTRY(dwc_cc) list_entry;
  39683. +} dwc_cc_t;
  39684. +
  39685. +DWC_CIRCLEQ_HEAD(context_list, dwc_cc);
  39686. +
  39687. +/** The main structure for CC management. */
  39688. +struct dwc_cc_if
  39689. +{
  39690. + dwc_mutex_t *mutex;
  39691. + char *filename;
  39692. +
  39693. + unsigned is_host:1;
  39694. +
  39695. + dwc_notifier_t *notifier;
  39696. +
  39697. + struct context_list list;
  39698. +};
  39699. +
  39700. +#ifdef DEBUG
  39701. +static inline void dump_bytes(char *name, uint8_t *bytes, int len)
  39702. +{
  39703. + int i;
  39704. + DWC_PRINTF("%s: ", name);
  39705. + for (i=0; i<len; i++) {
  39706. + DWC_PRINTF("%02x ", bytes[i]);
  39707. + }
  39708. + DWC_PRINTF("\n");
  39709. +}
  39710. +#else
  39711. +#define dump_bytes(x...)
  39712. +#endif
  39713. +
  39714. +static dwc_cc_t *alloc_cc(void *mem_ctx, uint8_t *name, uint32_t length)
  39715. +{
  39716. + dwc_cc_t *cc = dwc_alloc(mem_ctx, sizeof(dwc_cc_t));
  39717. + if (!cc) {
  39718. + return NULL;
  39719. + }
  39720. + DWC_MEMSET(cc, 0, sizeof(dwc_cc_t));
  39721. +
  39722. + if (name) {
  39723. + cc->length = length;
  39724. + cc->name = dwc_alloc(mem_ctx, length);
  39725. + if (!cc->name) {
  39726. + dwc_free(mem_ctx, cc);
  39727. + return NULL;
  39728. + }
  39729. +
  39730. + DWC_MEMCPY(cc->name, name, length);
  39731. + }
  39732. +
  39733. + return cc;
  39734. +}
  39735. +
  39736. +static void free_cc(void *mem_ctx, dwc_cc_t *cc)
  39737. +{
  39738. + if (cc->name) {
  39739. + dwc_free(mem_ctx, cc->name);
  39740. + }
  39741. + dwc_free(mem_ctx, cc);
  39742. +}
  39743. +
  39744. +static uint32_t next_uid(dwc_cc_if_t *cc_if)
  39745. +{
  39746. + uint32_t uid = 0;
  39747. + dwc_cc_t *cc;
  39748. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  39749. + if (cc->uid > uid) {
  39750. + uid = cc->uid;
  39751. + }
  39752. + }
  39753. +
  39754. + if (uid == 0) {
  39755. + uid = 255;
  39756. + }
  39757. +
  39758. + return uid + 1;
  39759. +}
  39760. +
  39761. +static dwc_cc_t *cc_find(dwc_cc_if_t *cc_if, uint32_t uid)
  39762. +{
  39763. + dwc_cc_t *cc;
  39764. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  39765. + if (cc->uid == uid) {
  39766. + return cc;
  39767. + }
  39768. + }
  39769. + return NULL;
  39770. +}
  39771. +
  39772. +static unsigned int cc_data_size(dwc_cc_if_t *cc_if)
  39773. +{
  39774. + unsigned int size = 0;
  39775. + dwc_cc_t *cc;
  39776. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  39777. + size += (48 + 1);
  39778. + if (cc->name) {
  39779. + size += cc->length;
  39780. + }
  39781. + }
  39782. + return size;
  39783. +}
  39784. +
  39785. +static uint32_t cc_match_chid(dwc_cc_if_t *cc_if, uint8_t *chid)
  39786. +{
  39787. + uint32_t uid = 0;
  39788. + dwc_cc_t *cc;
  39789. +
  39790. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  39791. + if (DWC_MEMCMP(cc->chid, chid, 16) == 0) {
  39792. + uid = cc->uid;
  39793. + break;
  39794. + }
  39795. + }
  39796. + return uid;
  39797. +}
  39798. +static uint32_t cc_match_cdid(dwc_cc_if_t *cc_if, uint8_t *cdid)
  39799. +{
  39800. + uint32_t uid = 0;
  39801. + dwc_cc_t *cc;
  39802. +
  39803. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  39804. + if (DWC_MEMCMP(cc->cdid, cdid, 16) == 0) {
  39805. + uid = cc->uid;
  39806. + break;
  39807. + }
  39808. + }
  39809. + return uid;
  39810. +}
  39811. +
  39812. +/* Internal cc_add */
  39813. +static int32_t cc_add(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *chid,
  39814. + uint8_t *cdid, uint8_t *ck, uint8_t *name, uint8_t length)
  39815. +{
  39816. + dwc_cc_t *cc;
  39817. + uint32_t uid;
  39818. +
  39819. + if (cc_if->is_host) {
  39820. + uid = cc_match_cdid(cc_if, cdid);
  39821. + }
  39822. + else {
  39823. + uid = cc_match_chid(cc_if, chid);
  39824. + }
  39825. +
  39826. + if (uid) {
  39827. + DWC_DEBUGC("Replacing previous connection context id=%d name=%p name_len=%d", uid, name, length);
  39828. + cc = cc_find(cc_if, uid);
  39829. + }
  39830. + else {
  39831. + cc = alloc_cc(mem_ctx, name, length);
  39832. + cc->uid = next_uid(cc_if);
  39833. + DWC_CIRCLEQ_INSERT_TAIL(&cc_if->list, cc, list_entry);
  39834. + }
  39835. +
  39836. + DWC_MEMCPY(&(cc->chid[0]), chid, 16);
  39837. + DWC_MEMCPY(&(cc->cdid[0]), cdid, 16);
  39838. + DWC_MEMCPY(&(cc->ck[0]), ck, 16);
  39839. +
  39840. + DWC_DEBUGC("Added connection context id=%d name=%p name_len=%d", cc->uid, name, length);
  39841. + dump_bytes("CHID", cc->chid, 16);
  39842. + dump_bytes("CDID", cc->cdid, 16);
  39843. + dump_bytes("CK", cc->ck, 16);
  39844. + return cc->uid;
  39845. +}
  39846. +
  39847. +/* Internal cc_clear */
  39848. +static void cc_clear(void *mem_ctx, dwc_cc_if_t *cc_if)
  39849. +{
  39850. + while (!DWC_CIRCLEQ_EMPTY(&cc_if->list)) {
  39851. + dwc_cc_t *cc = DWC_CIRCLEQ_FIRST(&cc_if->list);
  39852. + DWC_CIRCLEQ_REMOVE_INIT(&cc_if->list, cc, list_entry);
  39853. + free_cc(mem_ctx, cc);
  39854. + }
  39855. +}
  39856. +
  39857. +dwc_cc_if_t *dwc_cc_if_alloc(void *mem_ctx, void *mtx_ctx,
  39858. + dwc_notifier_t *notifier, unsigned is_host)
  39859. +{
  39860. + dwc_cc_if_t *cc_if = NULL;
  39861. +
  39862. + /* Allocate a common_cc_if structure */
  39863. + cc_if = dwc_alloc(mem_ctx, sizeof(dwc_cc_if_t));
  39864. +
  39865. + if (!cc_if)
  39866. + return NULL;
  39867. +
  39868. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  39869. + DWC_MUTEX_ALLOC_LINUX_DEBUG(cc_if->mutex);
  39870. +#else
  39871. + cc_if->mutex = dwc_mutex_alloc(mtx_ctx);
  39872. +#endif
  39873. + if (!cc_if->mutex) {
  39874. + dwc_free(mem_ctx, cc_if);
  39875. + return NULL;
  39876. + }
  39877. +
  39878. + DWC_CIRCLEQ_INIT(&cc_if->list);
  39879. + cc_if->is_host = is_host;
  39880. + cc_if->notifier = notifier;
  39881. + return cc_if;
  39882. +}
  39883. +
  39884. +void dwc_cc_if_free(void *mem_ctx, void *mtx_ctx, dwc_cc_if_t *cc_if)
  39885. +{
  39886. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  39887. + DWC_MUTEX_FREE(cc_if->mutex);
  39888. +#else
  39889. + dwc_mutex_free(mtx_ctx, cc_if->mutex);
  39890. +#endif
  39891. + cc_clear(mem_ctx, cc_if);
  39892. + dwc_free(mem_ctx, cc_if);
  39893. +}
  39894. +
  39895. +static void cc_changed(dwc_cc_if_t *cc_if)
  39896. +{
  39897. + if (cc_if->notifier) {
  39898. + dwc_notify(cc_if->notifier, DWC_CC_LIST_CHANGED_NOTIFICATION, cc_if);
  39899. + }
  39900. +}
  39901. +
  39902. +void dwc_cc_clear(void *mem_ctx, dwc_cc_if_t *cc_if)
  39903. +{
  39904. + DWC_MUTEX_LOCK(cc_if->mutex);
  39905. + cc_clear(mem_ctx, cc_if);
  39906. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39907. + cc_changed(cc_if);
  39908. +}
  39909. +
  39910. +int32_t dwc_cc_add(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *chid,
  39911. + uint8_t *cdid, uint8_t *ck, uint8_t *name, uint8_t length)
  39912. +{
  39913. + uint32_t uid;
  39914. +
  39915. + DWC_MUTEX_LOCK(cc_if->mutex);
  39916. + uid = cc_add(mem_ctx, cc_if, chid, cdid, ck, name, length);
  39917. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39918. + cc_changed(cc_if);
  39919. +
  39920. + return uid;
  39921. +}
  39922. +
  39923. +void dwc_cc_change(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id, uint8_t *chid,
  39924. + uint8_t *cdid, uint8_t *ck, uint8_t *name, uint8_t length)
  39925. +{
  39926. + dwc_cc_t* cc;
  39927. +
  39928. + DWC_DEBUGC("Change connection context %d", id);
  39929. +
  39930. + DWC_MUTEX_LOCK(cc_if->mutex);
  39931. + cc = cc_find(cc_if, id);
  39932. + if (!cc) {
  39933. + DWC_ERROR("Uid %d not found in cc list\n", id);
  39934. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39935. + return;
  39936. + }
  39937. +
  39938. + if (chid) {
  39939. + DWC_MEMCPY(&(cc->chid[0]), chid, 16);
  39940. + }
  39941. + if (cdid) {
  39942. + DWC_MEMCPY(&(cc->cdid[0]), cdid, 16);
  39943. + }
  39944. + if (ck) {
  39945. + DWC_MEMCPY(&(cc->ck[0]), ck, 16);
  39946. + }
  39947. +
  39948. + if (name) {
  39949. + if (cc->name) {
  39950. + dwc_free(mem_ctx, cc->name);
  39951. + }
  39952. + cc->name = dwc_alloc(mem_ctx, length);
  39953. + if (!cc->name) {
  39954. + DWC_ERROR("Out of memory in dwc_cc_change()\n");
  39955. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39956. + return;
  39957. + }
  39958. + cc->length = length;
  39959. + DWC_MEMCPY(cc->name, name, length);
  39960. + }
  39961. +
  39962. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39963. +
  39964. + cc_changed(cc_if);
  39965. +
  39966. + DWC_DEBUGC("Changed connection context id=%d\n", id);
  39967. + dump_bytes("New CHID", cc->chid, 16);
  39968. + dump_bytes("New CDID", cc->cdid, 16);
  39969. + dump_bytes("New CK", cc->ck, 16);
  39970. +}
  39971. +
  39972. +void dwc_cc_remove(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id)
  39973. +{
  39974. + dwc_cc_t *cc;
  39975. +
  39976. + DWC_DEBUGC("Removing connection context %d", id);
  39977. +
  39978. + DWC_MUTEX_LOCK(cc_if->mutex);
  39979. + cc = cc_find(cc_if, id);
  39980. + if (!cc) {
  39981. + DWC_ERROR("Uid %d not found in cc list\n", id);
  39982. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39983. + return;
  39984. + }
  39985. +
  39986. + DWC_CIRCLEQ_REMOVE_INIT(&cc_if->list, cc, list_entry);
  39987. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39988. + free_cc(mem_ctx, cc);
  39989. +
  39990. + cc_changed(cc_if);
  39991. +}
  39992. +
  39993. +uint8_t *dwc_cc_data_for_save(void *mem_ctx, dwc_cc_if_t *cc_if, unsigned int *length)
  39994. +{
  39995. + uint8_t *buf, *x;
  39996. + uint8_t zero = 0;
  39997. + dwc_cc_t *cc;
  39998. +
  39999. + DWC_MUTEX_LOCK(cc_if->mutex);
  40000. + *length = cc_data_size(cc_if);
  40001. + if (!(*length)) {
  40002. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40003. + return NULL;
  40004. + }
  40005. +
  40006. + DWC_DEBUGC("Creating data for saving (length=%d)", *length);
  40007. +
  40008. + buf = dwc_alloc(mem_ctx, *length);
  40009. + if (!buf) {
  40010. + *length = 0;
  40011. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40012. + return NULL;
  40013. + }
  40014. +
  40015. + x = buf;
  40016. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  40017. + DWC_MEMCPY(x, cc->chid, 16);
  40018. + x += 16;
  40019. + DWC_MEMCPY(x, cc->cdid, 16);
  40020. + x += 16;
  40021. + DWC_MEMCPY(x, cc->ck, 16);
  40022. + x += 16;
  40023. + if (cc->name) {
  40024. + DWC_MEMCPY(x, &cc->length, 1);
  40025. + x += 1;
  40026. + DWC_MEMCPY(x, cc->name, cc->length);
  40027. + x += cc->length;
  40028. + }
  40029. + else {
  40030. + DWC_MEMCPY(x, &zero, 1);
  40031. + x += 1;
  40032. + }
  40033. + }
  40034. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40035. +
  40036. + return buf;
  40037. +}
  40038. +
  40039. +void dwc_cc_restore_from_data(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *data, uint32_t length)
  40040. +{
  40041. + uint8_t name_length;
  40042. + uint8_t *name;
  40043. + uint8_t *chid;
  40044. + uint8_t *cdid;
  40045. + uint8_t *ck;
  40046. + uint32_t i = 0;
  40047. +
  40048. + DWC_MUTEX_LOCK(cc_if->mutex);
  40049. + cc_clear(mem_ctx, cc_if);
  40050. +
  40051. + while (i < length) {
  40052. + chid = &data[i];
  40053. + i += 16;
  40054. + cdid = &data[i];
  40055. + i += 16;
  40056. + ck = &data[i];
  40057. + i += 16;
  40058. +
  40059. + name_length = data[i];
  40060. + i ++;
  40061. +
  40062. + if (name_length) {
  40063. + name = &data[i];
  40064. + i += name_length;
  40065. + }
  40066. + else {
  40067. + name = NULL;
  40068. + }
  40069. +
  40070. + /* check to see if we haven't overflown the buffer */
  40071. + if (i > length) {
  40072. + DWC_ERROR("Data format error while attempting to load CCs "
  40073. + "(nlen=%d, iter=%d, buflen=%d).\n", name_length, i, length);
  40074. + break;
  40075. + }
  40076. +
  40077. + cc_add(mem_ctx, cc_if, chid, cdid, ck, name, name_length);
  40078. + }
  40079. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40080. +
  40081. + cc_changed(cc_if);
  40082. +}
  40083. +
  40084. +uint32_t dwc_cc_match_chid(dwc_cc_if_t *cc_if, uint8_t *chid)
  40085. +{
  40086. + uint32_t uid = 0;
  40087. +
  40088. + DWC_MUTEX_LOCK(cc_if->mutex);
  40089. + uid = cc_match_chid(cc_if, chid);
  40090. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40091. + return uid;
  40092. +}
  40093. +uint32_t dwc_cc_match_cdid(dwc_cc_if_t *cc_if, uint8_t *cdid)
  40094. +{
  40095. + uint32_t uid = 0;
  40096. +
  40097. + DWC_MUTEX_LOCK(cc_if->mutex);
  40098. + uid = cc_match_cdid(cc_if, cdid);
  40099. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40100. + return uid;
  40101. +}
  40102. +
  40103. +uint8_t *dwc_cc_ck(dwc_cc_if_t *cc_if, int32_t id)
  40104. +{
  40105. + uint8_t *ck = NULL;
  40106. + dwc_cc_t *cc;
  40107. +
  40108. + DWC_MUTEX_LOCK(cc_if->mutex);
  40109. + cc = cc_find(cc_if, id);
  40110. + if (cc) {
  40111. + ck = cc->ck;
  40112. + }
  40113. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40114. +
  40115. + return ck;
  40116. +
  40117. +}
  40118. +
  40119. +uint8_t *dwc_cc_chid(dwc_cc_if_t *cc_if, int32_t id)
  40120. +{
  40121. + uint8_t *retval = NULL;
  40122. + dwc_cc_t *cc;
  40123. +
  40124. + DWC_MUTEX_LOCK(cc_if->mutex);
  40125. + cc = cc_find(cc_if, id);
  40126. + if (cc) {
  40127. + retval = cc->chid;
  40128. + }
  40129. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40130. +
  40131. + return retval;
  40132. +}
  40133. +
  40134. +uint8_t *dwc_cc_cdid(dwc_cc_if_t *cc_if, int32_t id)
  40135. +{
  40136. + uint8_t *retval = NULL;
  40137. + dwc_cc_t *cc;
  40138. +
  40139. + DWC_MUTEX_LOCK(cc_if->mutex);
  40140. + cc = cc_find(cc_if, id);
  40141. + if (cc) {
  40142. + retval = cc->cdid;
  40143. + }
  40144. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40145. +
  40146. + return retval;
  40147. +}
  40148. +
  40149. +uint8_t *dwc_cc_name(dwc_cc_if_t *cc_if, int32_t id, uint8_t *length)
  40150. +{
  40151. + uint8_t *retval = NULL;
  40152. + dwc_cc_t *cc;
  40153. +
  40154. + DWC_MUTEX_LOCK(cc_if->mutex);
  40155. + *length = 0;
  40156. + cc = cc_find(cc_if, id);
  40157. + if (cc) {
  40158. + *length = cc->length;
  40159. + retval = cc->name;
  40160. + }
  40161. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  40162. +
  40163. + return retval;
  40164. +}
  40165. +
  40166. +#endif /* DWC_CCLIB */
  40167. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_common_port/dwc_cc.h linux-3.12.26/drivers/usb/host/dwc_common_port/dwc_cc.h
  40168. --- linux-3.12.26.orig/drivers/usb/host/dwc_common_port/dwc_cc.h 1970-01-01 01:00:00.000000000 +0100
  40169. +++ linux-3.12.26/drivers/usb/host/dwc_common_port/dwc_cc.h 2014-08-06 16:50:14.737964224 +0200
  40170. @@ -0,0 +1,224 @@
  40171. +/* =========================================================================
  40172. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_cc.h $
  40173. + * $Revision: #4 $
  40174. + * $Date: 2010/09/28 $
  40175. + * $Change: 1596182 $
  40176. + *
  40177. + * Synopsys Portability Library Software and documentation
  40178. + * (hereinafter, "Software") is an Unsupported proprietary work of
  40179. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  40180. + * between Synopsys and you.
  40181. + *
  40182. + * The Software IS NOT an item of Licensed Software or Licensed Product
  40183. + * under any End User Software License Agreement or Agreement for
  40184. + * Licensed Product with Synopsys or any supplement thereto. You are
  40185. + * permitted to use and redistribute this Software in source and binary
  40186. + * forms, with or without modification, provided that redistributions
  40187. + * of source code must retain this notice. You may not view, use,
  40188. + * disclose, copy or distribute this file or any information contained
  40189. + * herein except pursuant to this license grant from Synopsys. If you
  40190. + * do not agree with this notice, including the disclaimer below, then
  40191. + * you are not authorized to use the Software.
  40192. + *
  40193. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  40194. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  40195. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  40196. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  40197. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  40198. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  40199. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  40200. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  40201. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  40202. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  40203. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  40204. + * DAMAGE.
  40205. + * ========================================================================= */
  40206. +#ifndef _DWC_CC_H_
  40207. +#define _DWC_CC_H_
  40208. +
  40209. +#ifdef __cplusplus
  40210. +extern "C" {
  40211. +#endif
  40212. +
  40213. +/** @file
  40214. + *
  40215. + * This file defines the Context Context library.
  40216. + *
  40217. + * The main data structure is dwc_cc_if_t which is returned by either the
  40218. + * dwc_cc_if_alloc function or returned by the module to the user via a provided
  40219. + * function. The data structure is opaque and should only be manipulated via the
  40220. + * functions provied in this API.
  40221. + *
  40222. + * It manages a list of connection contexts and operations can be performed to
  40223. + * add, remove, query, search, and change, those contexts. Additionally,
  40224. + * a dwc_notifier_t object can be requested from the manager so that
  40225. + * the user can be notified whenever the context list has changed.
  40226. + */
  40227. +
  40228. +#include "dwc_os.h"
  40229. +#include "dwc_list.h"
  40230. +#include "dwc_notifier.h"
  40231. +
  40232. +
  40233. +/* Notifications */
  40234. +#define DWC_CC_LIST_CHANGED_NOTIFICATION "DWC_CC_LIST_CHANGED_NOTIFICATION"
  40235. +
  40236. +struct dwc_cc_if;
  40237. +typedef struct dwc_cc_if dwc_cc_if_t;
  40238. +
  40239. +
  40240. +/** @name Connection Context Operations */
  40241. +/** @{ */
  40242. +
  40243. +/** This function allocates memory for a dwc_cc_if_t structure, initializes
  40244. + * fields to default values, and returns a pointer to the structure or NULL on
  40245. + * error. */
  40246. +extern dwc_cc_if_t *dwc_cc_if_alloc(void *mem_ctx, void *mtx_ctx,
  40247. + dwc_notifier_t *notifier, unsigned is_host);
  40248. +
  40249. +/** Frees the memory for the specified CC structure allocated from
  40250. + * dwc_cc_if_alloc(). */
  40251. +extern void dwc_cc_if_free(void *mem_ctx, void *mtx_ctx, dwc_cc_if_t *cc_if);
  40252. +
  40253. +/** Removes all contexts from the connection context list */
  40254. +extern void dwc_cc_clear(void *mem_ctx, dwc_cc_if_t *cc_if);
  40255. +
  40256. +/** Adds a connection context (CHID, CK, CDID, Name) to the connection context list.
  40257. + * If a CHID already exists, the CK and name are overwritten. Statistics are
  40258. + * not overwritten.
  40259. + *
  40260. + * @param cc_if The cc_if structure.
  40261. + * @param chid A pointer to the 16-byte CHID. This value will be copied.
  40262. + * @param ck A pointer to the 16-byte CK. This value will be copied.
  40263. + * @param cdid A pointer to the 16-byte CDID. This value will be copied.
  40264. + * @param name An optional host friendly name as defined in the association model
  40265. + * spec. Must be a UTF16-LE unicode string. Can be NULL to indicated no name.
  40266. + * @param length The length othe unicode string.
  40267. + * @return A unique identifier used to refer to this context that is valid for
  40268. + * as long as this context is still in the list. */
  40269. +extern int32_t dwc_cc_add(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *chid,
  40270. + uint8_t *cdid, uint8_t *ck, uint8_t *name,
  40271. + uint8_t length);
  40272. +
  40273. +/** Changes the CHID, CK, CDID, or Name values of a connection context in the
  40274. + * list, preserving any accumulated statistics. This would typically be called
  40275. + * if the host decideds to change the context with a SET_CONNECTION request.
  40276. + *
  40277. + * @param cc_if The cc_if structure.
  40278. + * @param id The identifier of the connection context.
  40279. + * @param chid A pointer to the 16-byte CHID. This value will be copied. NULL
  40280. + * indicates no change.
  40281. + * @param cdid A pointer to the 16-byte CDID. This value will be copied. NULL
  40282. + * indicates no change.
  40283. + * @param ck A pointer to the 16-byte CK. This value will be copied. NULL
  40284. + * indicates no change.
  40285. + * @param name Host friendly name UTF16-LE. NULL indicates no change.
  40286. + * @param length Length of name. */
  40287. +extern void dwc_cc_change(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id,
  40288. + uint8_t *chid, uint8_t *cdid, uint8_t *ck,
  40289. + uint8_t *name, uint8_t length);
  40290. +
  40291. +/** Remove the specified connection context.
  40292. + * @param cc_if The cc_if structure.
  40293. + * @param id The identifier of the connection context to remove. */
  40294. +extern void dwc_cc_remove(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id);
  40295. +
  40296. +/** Get a binary block of data for the connection context list and attributes.
  40297. + * This data can be used by the OS specific driver to save the connection
  40298. + * context list into non-volatile memory.
  40299. + *
  40300. + * @param cc_if The cc_if structure.
  40301. + * @param length Return the length of the data buffer.
  40302. + * @return A pointer to the data buffer. The memory for this buffer should be
  40303. + * freed with DWC_FREE() after use. */
  40304. +extern uint8_t *dwc_cc_data_for_save(void *mem_ctx, dwc_cc_if_t *cc_if,
  40305. + unsigned int *length);
  40306. +
  40307. +/** Restore the connection context list from the binary data that was previously
  40308. + * returned from a call to dwc_cc_data_for_save. This can be used by the OS specific
  40309. + * driver to load a connection context list from non-volatile memory.
  40310. + *
  40311. + * @param cc_if The cc_if structure.
  40312. + * @param data The data bytes as returned from dwc_cc_data_for_save.
  40313. + * @param length The length of the data. */
  40314. +extern void dwc_cc_restore_from_data(void *mem_ctx, dwc_cc_if_t *cc_if,
  40315. + uint8_t *data, unsigned int length);
  40316. +
  40317. +/** Find the connection context from the specified CHID.
  40318. + *
  40319. + * @param cc_if The cc_if structure.
  40320. + * @param chid A pointer to the CHID data.
  40321. + * @return A non-zero identifier of the connection context if the CHID matches.
  40322. + * Otherwise returns 0. */
  40323. +extern uint32_t dwc_cc_match_chid(dwc_cc_if_t *cc_if, uint8_t *chid);
  40324. +
  40325. +/** Find the connection context from the specified CDID.
  40326. + *
  40327. + * @param cc_if The cc_if structure.
  40328. + * @param cdid A pointer to the CDID data.
  40329. + * @return A non-zero identifier of the connection context if the CHID matches.
  40330. + * Otherwise returns 0. */
  40331. +extern uint32_t dwc_cc_match_cdid(dwc_cc_if_t *cc_if, uint8_t *cdid);
  40332. +
  40333. +/** Retrieve the CK from the specified connection context.
  40334. + *
  40335. + * @param cc_if The cc_if structure.
  40336. + * @param id The identifier of the connection context.
  40337. + * @return A pointer to the CK data. The memory does not need to be freed. */
  40338. +extern uint8_t *dwc_cc_ck(dwc_cc_if_t *cc_if, int32_t id);
  40339. +
  40340. +/** Retrieve the CHID from the specified connection context.
  40341. + *
  40342. + * @param cc_if The cc_if structure.
  40343. + * @param id The identifier of the connection context.
  40344. + * @return A pointer to the CHID data. The memory does not need to be freed. */
  40345. +extern uint8_t *dwc_cc_chid(dwc_cc_if_t *cc_if, int32_t id);
  40346. +
  40347. +/** Retrieve the CDID from the specified connection context.
  40348. + *
  40349. + * @param cc_if The cc_if structure.
  40350. + * @param id The identifier of the connection context.
  40351. + * @return A pointer to the CDID data. The memory does not need to be freed. */
  40352. +extern uint8_t *dwc_cc_cdid(dwc_cc_if_t *cc_if, int32_t id);
  40353. +
  40354. +extern uint8_t *dwc_cc_name(dwc_cc_if_t *cc_if, int32_t id, uint8_t *length);
  40355. +
  40356. +/** Checks a buffer for non-zero.
  40357. + * @param id A pointer to a 16 byte buffer.
  40358. + * @return true if the 16 byte value is non-zero. */
  40359. +static inline unsigned dwc_assoc_is_not_zero_id(uint8_t *id) {
  40360. + int i;
  40361. + for (i=0; i<16; i++) {
  40362. + if (id[i]) return 1;
  40363. + }
  40364. + return 0;
  40365. +}
  40366. +
  40367. +/** Checks a buffer for zero.
  40368. + * @param id A pointer to a 16 byte buffer.
  40369. + * @return true if the 16 byte value is zero. */
  40370. +static inline unsigned dwc_assoc_is_zero_id(uint8_t *id) {
  40371. + return !dwc_assoc_is_not_zero_id(id);
  40372. +}
  40373. +
  40374. +/** Prints an ASCII representation for the 16-byte chid, cdid, or ck, into
  40375. + * buffer. */
  40376. +static inline int dwc_print_id_string(char *buffer, uint8_t *id) {
  40377. + char *ptr = buffer;
  40378. + int i;
  40379. + for (i=0; i<16; i++) {
  40380. + ptr += DWC_SPRINTF(ptr, "%02x", id[i]);
  40381. + if (i < 15) {
  40382. + ptr += DWC_SPRINTF(ptr, " ");
  40383. + }
  40384. + }
  40385. + return ptr - buffer;
  40386. +}
  40387. +
  40388. +/** @} */
  40389. +
  40390. +#ifdef __cplusplus
  40391. +}
  40392. +#endif
  40393. +
  40394. +#endif /* _DWC_CC_H_ */
  40395. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c linux-3.12.26/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c
  40396. --- linux-3.12.26.orig/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c 1970-01-01 01:00:00.000000000 +0100
  40397. +++ linux-3.12.26/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c 2014-08-06 16:50:14.737964224 +0200
  40398. @@ -0,0 +1,1308 @@
  40399. +#include "dwc_os.h"
  40400. +#include "dwc_list.h"
  40401. +
  40402. +#ifdef DWC_CCLIB
  40403. +# include "dwc_cc.h"
  40404. +#endif
  40405. +
  40406. +#ifdef DWC_CRYPTOLIB
  40407. +# include "dwc_modpow.h"
  40408. +# include "dwc_dh.h"
  40409. +# include "dwc_crypto.h"
  40410. +#endif
  40411. +
  40412. +#ifdef DWC_NOTIFYLIB
  40413. +# include "dwc_notifier.h"
  40414. +#endif
  40415. +
  40416. +/* OS-Level Implementations */
  40417. +
  40418. +/* This is the FreeBSD 7.0 kernel implementation of the DWC platform library. */
  40419. +
  40420. +
  40421. +/* MISC */
  40422. +
  40423. +void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size)
  40424. +{
  40425. + return memset(dest, byte, size);
  40426. +}
  40427. +
  40428. +void *DWC_MEMCPY(void *dest, void const *src, uint32_t size)
  40429. +{
  40430. + return memcpy(dest, src, size);
  40431. +}
  40432. +
  40433. +void *DWC_MEMMOVE(void *dest, void *src, uint32_t size)
  40434. +{
  40435. + bcopy(src, dest, size);
  40436. + return dest;
  40437. +}
  40438. +
  40439. +int DWC_MEMCMP(void *m1, void *m2, uint32_t size)
  40440. +{
  40441. + return memcmp(m1, m2, size);
  40442. +}
  40443. +
  40444. +int DWC_STRNCMP(void *s1, void *s2, uint32_t size)
  40445. +{
  40446. + return strncmp(s1, s2, size);
  40447. +}
  40448. +
  40449. +int DWC_STRCMP(void *s1, void *s2)
  40450. +{
  40451. + return strcmp(s1, s2);
  40452. +}
  40453. +
  40454. +int DWC_STRLEN(char const *str)
  40455. +{
  40456. + return strlen(str);
  40457. +}
  40458. +
  40459. +char *DWC_STRCPY(char *to, char const *from)
  40460. +{
  40461. + return strcpy(to, from);
  40462. +}
  40463. +
  40464. +char *DWC_STRDUP(char const *str)
  40465. +{
  40466. + int len = DWC_STRLEN(str) + 1;
  40467. + char *new = DWC_ALLOC_ATOMIC(len);
  40468. +
  40469. + if (!new) {
  40470. + return NULL;
  40471. + }
  40472. +
  40473. + DWC_MEMCPY(new, str, len);
  40474. + return new;
  40475. +}
  40476. +
  40477. +int DWC_ATOI(char *str, int32_t *value)
  40478. +{
  40479. + char *end = NULL;
  40480. +
  40481. + *value = strtol(str, &end, 0);
  40482. + if (*end == '\0') {
  40483. + return 0;
  40484. + }
  40485. +
  40486. + return -1;
  40487. +}
  40488. +
  40489. +int DWC_ATOUI(char *str, uint32_t *value)
  40490. +{
  40491. + char *end = NULL;
  40492. +
  40493. + *value = strtoul(str, &end, 0);
  40494. + if (*end == '\0') {
  40495. + return 0;
  40496. + }
  40497. +
  40498. + return -1;
  40499. +}
  40500. +
  40501. +
  40502. +#ifdef DWC_UTFLIB
  40503. +/* From usbstring.c */
  40504. +
  40505. +int DWC_UTF8_TO_UTF16LE(uint8_t const *s, uint16_t *cp, unsigned len)
  40506. +{
  40507. + int count = 0;
  40508. + u8 c;
  40509. + u16 uchar;
  40510. +
  40511. + /* this insists on correct encodings, though not minimal ones.
  40512. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  40513. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  40514. + */
  40515. + while (len != 0 && (c = (u8) *s++) != 0) {
  40516. + if (unlikely(c & 0x80)) {
  40517. + // 2-byte sequence:
  40518. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  40519. + if ((c & 0xe0) == 0xc0) {
  40520. + uchar = (c & 0x1f) << 6;
  40521. +
  40522. + c = (u8) *s++;
  40523. + if ((c & 0xc0) != 0xc0)
  40524. + goto fail;
  40525. + c &= 0x3f;
  40526. + uchar |= c;
  40527. +
  40528. + // 3-byte sequence (most CJKV characters):
  40529. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  40530. + } else if ((c & 0xf0) == 0xe0) {
  40531. + uchar = (c & 0x0f) << 12;
  40532. +
  40533. + c = (u8) *s++;
  40534. + if ((c & 0xc0) != 0xc0)
  40535. + goto fail;
  40536. + c &= 0x3f;
  40537. + uchar |= c << 6;
  40538. +
  40539. + c = (u8) *s++;
  40540. + if ((c & 0xc0) != 0xc0)
  40541. + goto fail;
  40542. + c &= 0x3f;
  40543. + uchar |= c;
  40544. +
  40545. + /* no bogus surrogates */
  40546. + if (0xd800 <= uchar && uchar <= 0xdfff)
  40547. + goto fail;
  40548. +
  40549. + // 4-byte sequence (surrogate pairs, currently rare):
  40550. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  40551. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  40552. + // (uuuuu = wwww + 1)
  40553. + // FIXME accept the surrogate code points (only)
  40554. + } else
  40555. + goto fail;
  40556. + } else
  40557. + uchar = c;
  40558. + put_unaligned (cpu_to_le16 (uchar), cp++);
  40559. + count++;
  40560. + len--;
  40561. + }
  40562. + return count;
  40563. +fail:
  40564. + return -1;
  40565. +}
  40566. +
  40567. +#endif /* DWC_UTFLIB */
  40568. +
  40569. +
  40570. +/* dwc_debug.h */
  40571. +
  40572. +dwc_bool_t DWC_IN_IRQ(void)
  40573. +{
  40574. +// return in_irq();
  40575. + return 0;
  40576. +}
  40577. +
  40578. +dwc_bool_t DWC_IN_BH(void)
  40579. +{
  40580. +// return in_softirq();
  40581. + return 0;
  40582. +}
  40583. +
  40584. +void DWC_VPRINTF(char *format, va_list args)
  40585. +{
  40586. + vprintf(format, args);
  40587. +}
  40588. +
  40589. +int DWC_VSNPRINTF(char *str, int size, char *format, va_list args)
  40590. +{
  40591. + return vsnprintf(str, size, format, args);
  40592. +}
  40593. +
  40594. +void DWC_PRINTF(char *format, ...)
  40595. +{
  40596. + va_list args;
  40597. +
  40598. + va_start(args, format);
  40599. + DWC_VPRINTF(format, args);
  40600. + va_end(args);
  40601. +}
  40602. +
  40603. +int DWC_SPRINTF(char *buffer, char *format, ...)
  40604. +{
  40605. + int retval;
  40606. + va_list args;
  40607. +
  40608. + va_start(args, format);
  40609. + retval = vsprintf(buffer, format, args);
  40610. + va_end(args);
  40611. + return retval;
  40612. +}
  40613. +
  40614. +int DWC_SNPRINTF(char *buffer, int size, char *format, ...)
  40615. +{
  40616. + int retval;
  40617. + va_list args;
  40618. +
  40619. + va_start(args, format);
  40620. + retval = vsnprintf(buffer, size, format, args);
  40621. + va_end(args);
  40622. + return retval;
  40623. +}
  40624. +
  40625. +void __DWC_WARN(char *format, ...)
  40626. +{
  40627. + va_list args;
  40628. +
  40629. + va_start(args, format);
  40630. + DWC_VPRINTF(format, args);
  40631. + va_end(args);
  40632. +}
  40633. +
  40634. +void __DWC_ERROR(char *format, ...)
  40635. +{
  40636. + va_list args;
  40637. +
  40638. + va_start(args, format);
  40639. + DWC_VPRINTF(format, args);
  40640. + va_end(args);
  40641. +}
  40642. +
  40643. +void DWC_EXCEPTION(char *format, ...)
  40644. +{
  40645. + va_list args;
  40646. +
  40647. + va_start(args, format);
  40648. + DWC_VPRINTF(format, args);
  40649. + va_end(args);
  40650. +// BUG_ON(1); ???
  40651. +}
  40652. +
  40653. +#ifdef DEBUG
  40654. +void __DWC_DEBUG(char *format, ...)
  40655. +{
  40656. + va_list args;
  40657. +
  40658. + va_start(args, format);
  40659. + DWC_VPRINTF(format, args);
  40660. + va_end(args);
  40661. +}
  40662. +#endif
  40663. +
  40664. +
  40665. +/* dwc_mem.h */
  40666. +
  40667. +#if 0
  40668. +dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size,
  40669. + uint32_t align,
  40670. + uint32_t alloc)
  40671. +{
  40672. + struct dma_pool *pool = dma_pool_create("Pool", NULL,
  40673. + size, align, alloc);
  40674. + return (dwc_pool_t *)pool;
  40675. +}
  40676. +
  40677. +void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool)
  40678. +{
  40679. + dma_pool_destroy((struct dma_pool *)pool);
  40680. +}
  40681. +
  40682. +void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  40683. +{
  40684. +// return dma_pool_alloc((struct dma_pool *)pool, GFP_KERNEL, dma_addr);
  40685. + return dma_pool_alloc((struct dma_pool *)pool, M_WAITOK, dma_addr);
  40686. +}
  40687. +
  40688. +void *DWC_DMA_POOL_ZALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  40689. +{
  40690. + void *vaddr = DWC_DMA_POOL_ALLOC(pool, dma_addr);
  40691. + memset(..);
  40692. +}
  40693. +
  40694. +void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr)
  40695. +{
  40696. + dma_pool_free(pool, vaddr, daddr);
  40697. +}
  40698. +#endif
  40699. +
  40700. +static void dmamap_cb(void *arg, bus_dma_segment_t *segs, int nseg, int error)
  40701. +{
  40702. + if (error)
  40703. + return;
  40704. + *(bus_addr_t *)arg = segs[0].ds_addr;
  40705. +}
  40706. +
  40707. +void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  40708. +{
  40709. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  40710. + int error;
  40711. +
  40712. + error = bus_dma_tag_create(
  40713. +#if __FreeBSD_version >= 700000
  40714. + bus_get_dma_tag(dma->dev), /* parent */
  40715. +#else
  40716. + NULL, /* parent */
  40717. +#endif
  40718. + 4, 0, /* alignment, bounds */
  40719. + BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
  40720. + BUS_SPACE_MAXADDR, /* highaddr */
  40721. + NULL, NULL, /* filter, filterarg */
  40722. + size, /* maxsize */
  40723. + 1, /* nsegments */
  40724. + size, /* maxsegsize */
  40725. + 0, /* flags */
  40726. + NULL, /* lockfunc */
  40727. + NULL, /* lockarg */
  40728. + &dma->dma_tag);
  40729. + if (error) {
  40730. + device_printf(dma->dev, "%s: bus_dma_tag_create failed: %d\n",
  40731. + __func__, error);
  40732. + goto fail_0;
  40733. + }
  40734. +
  40735. + error = bus_dmamem_alloc(dma->dma_tag, &dma->dma_vaddr,
  40736. + BUS_DMA_NOWAIT | BUS_DMA_COHERENT, &dma->dma_map);
  40737. + if (error) {
  40738. + device_printf(dma->dev, "%s: bus_dmamem_alloc(%ju) failed: %d\n",
  40739. + __func__, (uintmax_t)size, error);
  40740. + goto fail_1;
  40741. + }
  40742. +
  40743. + dma->dma_paddr = 0;
  40744. + error = bus_dmamap_load(dma->dma_tag, dma->dma_map, dma->dma_vaddr, size,
  40745. + dmamap_cb, &dma->dma_paddr, BUS_DMA_NOWAIT);
  40746. + if (error || dma->dma_paddr == 0) {
  40747. + device_printf(dma->dev, "%s: bus_dmamap_load failed: %d\n",
  40748. + __func__, error);
  40749. + goto fail_2;
  40750. + }
  40751. +
  40752. + *dma_addr = dma->dma_paddr;
  40753. + return dma->dma_vaddr;
  40754. +
  40755. +fail_2:
  40756. + bus_dmamap_unload(dma->dma_tag, dma->dma_map);
  40757. +fail_1:
  40758. + bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
  40759. + bus_dma_tag_destroy(dma->dma_tag);
  40760. +fail_0:
  40761. + dma->dma_map = NULL;
  40762. + dma->dma_tag = NULL;
  40763. +
  40764. + return NULL;
  40765. +}
  40766. +
  40767. +void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr)
  40768. +{
  40769. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  40770. +
  40771. + if (dma->dma_tag == NULL)
  40772. + return;
  40773. + if (dma->dma_map != NULL) {
  40774. + bus_dmamap_sync(dma->dma_tag, dma->dma_map,
  40775. + BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
  40776. + bus_dmamap_unload(dma->dma_tag, dma->dma_map);
  40777. + bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
  40778. + dma->dma_map = NULL;
  40779. + }
  40780. +
  40781. + bus_dma_tag_destroy(dma->dma_tag);
  40782. + dma->dma_tag = NULL;
  40783. +}
  40784. +
  40785. +void *__DWC_ALLOC(void *mem_ctx, uint32_t size)
  40786. +{
  40787. + return malloc(size, M_DEVBUF, M_WAITOK | M_ZERO);
  40788. +}
  40789. +
  40790. +void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size)
  40791. +{
  40792. + return malloc(size, M_DEVBUF, M_NOWAIT | M_ZERO);
  40793. +}
  40794. +
  40795. +void __DWC_FREE(void *mem_ctx, void *addr)
  40796. +{
  40797. + free(addr, M_DEVBUF);
  40798. +}
  40799. +
  40800. +
  40801. +#ifdef DWC_CRYPTOLIB
  40802. +/* dwc_crypto.h */
  40803. +
  40804. +void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length)
  40805. +{
  40806. + get_random_bytes(buffer, length);
  40807. +}
  40808. +
  40809. +int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out)
  40810. +{
  40811. + struct crypto_blkcipher *tfm;
  40812. + struct blkcipher_desc desc;
  40813. + struct scatterlist sgd;
  40814. + struct scatterlist sgs;
  40815. +
  40816. + tfm = crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC);
  40817. + if (tfm == NULL) {
  40818. + printk("failed to load transform for aes CBC\n");
  40819. + return -1;
  40820. + }
  40821. +
  40822. + crypto_blkcipher_setkey(tfm, key, keylen);
  40823. + crypto_blkcipher_set_iv(tfm, iv, 16);
  40824. +
  40825. + sg_init_one(&sgd, out, messagelen);
  40826. + sg_init_one(&sgs, message, messagelen);
  40827. +
  40828. + desc.tfm = tfm;
  40829. + desc.flags = 0;
  40830. +
  40831. + if (crypto_blkcipher_encrypt(&desc, &sgd, &sgs, messagelen)) {
  40832. + crypto_free_blkcipher(tfm);
  40833. + DWC_ERROR("AES CBC encryption failed");
  40834. + return -1;
  40835. + }
  40836. +
  40837. + crypto_free_blkcipher(tfm);
  40838. + return 0;
  40839. +}
  40840. +
  40841. +int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out)
  40842. +{
  40843. + struct crypto_hash *tfm;
  40844. + struct hash_desc desc;
  40845. + struct scatterlist sg;
  40846. +
  40847. + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
  40848. + if (IS_ERR(tfm)) {
  40849. + DWC_ERROR("Failed to load transform for sha256: %ld", PTR_ERR(tfm));
  40850. + return 0;
  40851. + }
  40852. + desc.tfm = tfm;
  40853. + desc.flags = 0;
  40854. +
  40855. + sg_init_one(&sg, message, len);
  40856. + crypto_hash_digest(&desc, &sg, len, out);
  40857. + crypto_free_hash(tfm);
  40858. +
  40859. + return 1;
  40860. +}
  40861. +
  40862. +int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen,
  40863. + uint8_t *key, uint32_t keylen, uint8_t *out)
  40864. +{
  40865. + struct crypto_hash *tfm;
  40866. + struct hash_desc desc;
  40867. + struct scatterlist sg;
  40868. +
  40869. + tfm = crypto_alloc_hash("hmac(sha256)", 0, CRYPTO_ALG_ASYNC);
  40870. + if (IS_ERR(tfm)) {
  40871. + DWC_ERROR("Failed to load transform for hmac(sha256): %ld", PTR_ERR(tfm));
  40872. + return 0;
  40873. + }
  40874. + desc.tfm = tfm;
  40875. + desc.flags = 0;
  40876. +
  40877. + sg_init_one(&sg, message, messagelen);
  40878. + crypto_hash_setkey(tfm, key, keylen);
  40879. + crypto_hash_digest(&desc, &sg, messagelen, out);
  40880. + crypto_free_hash(tfm);
  40881. +
  40882. + return 1;
  40883. +}
  40884. +
  40885. +#endif /* DWC_CRYPTOLIB */
  40886. +
  40887. +
  40888. +/* Byte Ordering Conversions */
  40889. +
  40890. +uint32_t DWC_CPU_TO_LE32(uint32_t *p)
  40891. +{
  40892. +#ifdef __LITTLE_ENDIAN
  40893. + return *p;
  40894. +#else
  40895. + uint8_t *u_p = (uint8_t *)p;
  40896. +
  40897. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  40898. +#endif
  40899. +}
  40900. +
  40901. +uint32_t DWC_CPU_TO_BE32(uint32_t *p)
  40902. +{
  40903. +#ifdef __BIG_ENDIAN
  40904. + return *p;
  40905. +#else
  40906. + uint8_t *u_p = (uint8_t *)p;
  40907. +
  40908. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  40909. +#endif
  40910. +}
  40911. +
  40912. +uint32_t DWC_LE32_TO_CPU(uint32_t *p)
  40913. +{
  40914. +#ifdef __LITTLE_ENDIAN
  40915. + return *p;
  40916. +#else
  40917. + uint8_t *u_p = (uint8_t *)p;
  40918. +
  40919. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  40920. +#endif
  40921. +}
  40922. +
  40923. +uint32_t DWC_BE32_TO_CPU(uint32_t *p)
  40924. +{
  40925. +#ifdef __BIG_ENDIAN
  40926. + return *p;
  40927. +#else
  40928. + uint8_t *u_p = (uint8_t *)p;
  40929. +
  40930. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  40931. +#endif
  40932. +}
  40933. +
  40934. +uint16_t DWC_CPU_TO_LE16(uint16_t *p)
  40935. +{
  40936. +#ifdef __LITTLE_ENDIAN
  40937. + return *p;
  40938. +#else
  40939. + uint8_t *u_p = (uint8_t *)p;
  40940. + return (u_p[1] | (u_p[0] << 8));
  40941. +#endif
  40942. +}
  40943. +
  40944. +uint16_t DWC_CPU_TO_BE16(uint16_t *p)
  40945. +{
  40946. +#ifdef __BIG_ENDIAN
  40947. + return *p;
  40948. +#else
  40949. + uint8_t *u_p = (uint8_t *)p;
  40950. + return (u_p[1] | (u_p[0] << 8));
  40951. +#endif
  40952. +}
  40953. +
  40954. +uint16_t DWC_LE16_TO_CPU(uint16_t *p)
  40955. +{
  40956. +#ifdef __LITTLE_ENDIAN
  40957. + return *p;
  40958. +#else
  40959. + uint8_t *u_p = (uint8_t *)p;
  40960. + return (u_p[1] | (u_p[0] << 8));
  40961. +#endif
  40962. +}
  40963. +
  40964. +uint16_t DWC_BE16_TO_CPU(uint16_t *p)
  40965. +{
  40966. +#ifdef __BIG_ENDIAN
  40967. + return *p;
  40968. +#else
  40969. + uint8_t *u_p = (uint8_t *)p;
  40970. + return (u_p[1] | (u_p[0] << 8));
  40971. +#endif
  40972. +}
  40973. +
  40974. +
  40975. +/* Registers */
  40976. +
  40977. +uint32_t DWC_READ_REG32(void *io_ctx, uint32_t volatile *reg)
  40978. +{
  40979. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  40980. + bus_size_t ior = (bus_size_t)reg;
  40981. +
  40982. + return bus_space_read_4(io->iot, io->ioh, ior);
  40983. +}
  40984. +
  40985. +#if 0
  40986. +uint64_t DWC_READ_REG64(void *io_ctx, uint64_t volatile *reg)
  40987. +{
  40988. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  40989. + bus_size_t ior = (bus_size_t)reg;
  40990. +
  40991. + return bus_space_read_8(io->iot, io->ioh, ior);
  40992. +}
  40993. +#endif
  40994. +
  40995. +void DWC_WRITE_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t value)
  40996. +{
  40997. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  40998. + bus_size_t ior = (bus_size_t)reg;
  40999. +
  41000. + bus_space_write_4(io->iot, io->ioh, ior, value);
  41001. +}
  41002. +
  41003. +#if 0
  41004. +void DWC_WRITE_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t value)
  41005. +{
  41006. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  41007. + bus_size_t ior = (bus_size_t)reg;
  41008. +
  41009. + bus_space_write_8(io->iot, io->ioh, ior, value);
  41010. +}
  41011. +#endif
  41012. +
  41013. +void DWC_MODIFY_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t clear_mask,
  41014. + uint32_t set_mask)
  41015. +{
  41016. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  41017. + bus_size_t ior = (bus_size_t)reg;
  41018. +
  41019. + bus_space_write_4(io->iot, io->ioh, ior,
  41020. + (bus_space_read_4(io->iot, io->ioh, ior) &
  41021. + ~clear_mask) | set_mask);
  41022. +}
  41023. +
  41024. +#if 0
  41025. +void DWC_MODIFY_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t clear_mask,
  41026. + uint64_t set_mask)
  41027. +{
  41028. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  41029. + bus_size_t ior = (bus_size_t)reg;
  41030. +
  41031. + bus_space_write_8(io->iot, io->ioh, ior,
  41032. + (bus_space_read_8(io->iot, io->ioh, ior) &
  41033. + ~clear_mask) | set_mask);
  41034. +}
  41035. +#endif
  41036. +
  41037. +
  41038. +/* Locking */
  41039. +
  41040. +dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void)
  41041. +{
  41042. + struct mtx *sl = DWC_ALLOC(sizeof(*sl));
  41043. +
  41044. + if (!sl) {
  41045. + DWC_ERROR("Cannot allocate memory for spinlock");
  41046. + return NULL;
  41047. + }
  41048. +
  41049. + mtx_init(sl, "dw3spn", NULL, MTX_SPIN);
  41050. + return (dwc_spinlock_t *)sl;
  41051. +}
  41052. +
  41053. +void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock)
  41054. +{
  41055. + struct mtx *sl = (struct mtx *)lock;
  41056. +
  41057. + mtx_destroy(sl);
  41058. + DWC_FREE(sl);
  41059. +}
  41060. +
  41061. +void DWC_SPINLOCK(dwc_spinlock_t *lock)
  41062. +{
  41063. + mtx_lock_spin((struct mtx *)lock); // ???
  41064. +}
  41065. +
  41066. +void DWC_SPINUNLOCK(dwc_spinlock_t *lock)
  41067. +{
  41068. + mtx_unlock_spin((struct mtx *)lock); // ???
  41069. +}
  41070. +
  41071. +void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags)
  41072. +{
  41073. + mtx_lock_spin((struct mtx *)lock);
  41074. +}
  41075. +
  41076. +void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags)
  41077. +{
  41078. + mtx_unlock_spin((struct mtx *)lock);
  41079. +}
  41080. +
  41081. +dwc_mutex_t *DWC_MUTEX_ALLOC(void)
  41082. +{
  41083. + struct mtx *m;
  41084. + dwc_mutex_t *mutex = (dwc_mutex_t *)DWC_ALLOC(sizeof(struct mtx));
  41085. +
  41086. + if (!mutex) {
  41087. + DWC_ERROR("Cannot allocate memory for mutex");
  41088. + return NULL;
  41089. + }
  41090. +
  41091. + m = (struct mtx *)mutex;
  41092. + mtx_init(m, "dw3mtx", NULL, MTX_DEF);
  41093. + return mutex;
  41094. +}
  41095. +
  41096. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  41097. +#else
  41098. +void DWC_MUTEX_FREE(dwc_mutex_t *mutex)
  41099. +{
  41100. + mtx_destroy((struct mtx *)mutex);
  41101. + DWC_FREE(mutex);
  41102. +}
  41103. +#endif
  41104. +
  41105. +void DWC_MUTEX_LOCK(dwc_mutex_t *mutex)
  41106. +{
  41107. + struct mtx *m = (struct mtx *)mutex;
  41108. +
  41109. + mtx_lock(m);
  41110. +}
  41111. +
  41112. +int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex)
  41113. +{
  41114. + struct mtx *m = (struct mtx *)mutex;
  41115. +
  41116. + return mtx_trylock(m);
  41117. +}
  41118. +
  41119. +void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex)
  41120. +{
  41121. + struct mtx *m = (struct mtx *)mutex;
  41122. +
  41123. + mtx_unlock(m);
  41124. +}
  41125. +
  41126. +
  41127. +/* Timing */
  41128. +
  41129. +void DWC_UDELAY(uint32_t usecs)
  41130. +{
  41131. + DELAY(usecs);
  41132. +}
  41133. +
  41134. +void DWC_MDELAY(uint32_t msecs)
  41135. +{
  41136. + do {
  41137. + DELAY(1000);
  41138. + } while (--msecs);
  41139. +}
  41140. +
  41141. +void DWC_MSLEEP(uint32_t msecs)
  41142. +{
  41143. + struct timeval tv;
  41144. +
  41145. + tv.tv_sec = msecs / 1000;
  41146. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  41147. + pause("dw3slp", tvtohz(&tv));
  41148. +}
  41149. +
  41150. +uint32_t DWC_TIME(void)
  41151. +{
  41152. + struct timeval tv;
  41153. +
  41154. + microuptime(&tv); // or getmicrouptime? (less precise, but faster)
  41155. + return tv.tv_sec * 1000 + tv.tv_usec / 1000;
  41156. +}
  41157. +
  41158. +
  41159. +/* Timers */
  41160. +
  41161. +struct dwc_timer {
  41162. + struct callout t;
  41163. + char *name;
  41164. + dwc_spinlock_t *lock;
  41165. + dwc_timer_callback_t cb;
  41166. + void *data;
  41167. +};
  41168. +
  41169. +dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data)
  41170. +{
  41171. + dwc_timer_t *t = DWC_ALLOC(sizeof(*t));
  41172. +
  41173. + if (!t) {
  41174. + DWC_ERROR("Cannot allocate memory for timer");
  41175. + return NULL;
  41176. + }
  41177. +
  41178. + callout_init(&t->t, 1);
  41179. +
  41180. + t->name = DWC_STRDUP(name);
  41181. + if (!t->name) {
  41182. + DWC_ERROR("Cannot allocate memory for timer->name");
  41183. + goto no_name;
  41184. + }
  41185. +
  41186. + t->lock = DWC_SPINLOCK_ALLOC();
  41187. + if (!t->lock) {
  41188. + DWC_ERROR("Cannot allocate memory for lock");
  41189. + goto no_lock;
  41190. + }
  41191. +
  41192. + t->cb = cb;
  41193. + t->data = data;
  41194. +
  41195. + return t;
  41196. +
  41197. + no_lock:
  41198. + DWC_FREE(t->name);
  41199. + no_name:
  41200. + DWC_FREE(t);
  41201. +
  41202. + return NULL;
  41203. +}
  41204. +
  41205. +void DWC_TIMER_FREE(dwc_timer_t *timer)
  41206. +{
  41207. + callout_stop(&timer->t);
  41208. + DWC_SPINLOCK_FREE(timer->lock);
  41209. + DWC_FREE(timer->name);
  41210. + DWC_FREE(timer);
  41211. +}
  41212. +
  41213. +void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time)
  41214. +{
  41215. + struct timeval tv;
  41216. +
  41217. + tv.tv_sec = time / 1000;
  41218. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  41219. + callout_reset(&timer->t, tvtohz(&tv), timer->cb, timer->data);
  41220. +}
  41221. +
  41222. +void DWC_TIMER_CANCEL(dwc_timer_t *timer)
  41223. +{
  41224. + callout_stop(&timer->t);
  41225. +}
  41226. +
  41227. +
  41228. +/* Wait Queues */
  41229. +
  41230. +struct dwc_waitq {
  41231. + struct mtx lock;
  41232. + int abort;
  41233. +};
  41234. +
  41235. +dwc_waitq_t *DWC_WAITQ_ALLOC(void)
  41236. +{
  41237. + dwc_waitq_t *wq = DWC_ALLOC(sizeof(*wq));
  41238. +
  41239. + if (!wq) {
  41240. + DWC_ERROR("Cannot allocate memory for waitqueue");
  41241. + return NULL;
  41242. + }
  41243. +
  41244. + mtx_init(&wq->lock, "dw3wtq", NULL, MTX_DEF);
  41245. + wq->abort = 0;
  41246. +
  41247. + return wq;
  41248. +}
  41249. +
  41250. +void DWC_WAITQ_FREE(dwc_waitq_t *wq)
  41251. +{
  41252. + mtx_destroy(&wq->lock);
  41253. + DWC_FREE(wq);
  41254. +}
  41255. +
  41256. +int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data)
  41257. +{
  41258. +// intrmask_t ipl;
  41259. + int result = 0;
  41260. +
  41261. + mtx_lock(&wq->lock);
  41262. +// ipl = splbio();
  41263. +
  41264. + /* Skip the sleep if already aborted or triggered */
  41265. + if (!wq->abort && !cond(data)) {
  41266. +// splx(ipl);
  41267. + result = msleep(wq, &wq->lock, PCATCH, "dw3wat", 0); // infinite timeout
  41268. +// ipl = splbio();
  41269. + }
  41270. +
  41271. + if (result == ERESTART) { // signaled - restart
  41272. + result = -DWC_E_RESTART;
  41273. +
  41274. + } else if (result == EINTR) { // signaled - interrupt
  41275. + result = -DWC_E_ABORT;
  41276. +
  41277. + } else if (wq->abort) {
  41278. + result = -DWC_E_ABORT;
  41279. +
  41280. + } else {
  41281. + result = 0;
  41282. + }
  41283. +
  41284. + wq->abort = 0;
  41285. +// splx(ipl);
  41286. + mtx_unlock(&wq->lock);
  41287. + return result;
  41288. +}
  41289. +
  41290. +int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  41291. + void *data, int32_t msecs)
  41292. +{
  41293. + struct timeval tv, tv1, tv2;
  41294. +// intrmask_t ipl;
  41295. + int result = 0;
  41296. +
  41297. + tv.tv_sec = msecs / 1000;
  41298. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  41299. +
  41300. + mtx_lock(&wq->lock);
  41301. +// ipl = splbio();
  41302. +
  41303. + /* Skip the sleep if already aborted or triggered */
  41304. + if (!wq->abort && !cond(data)) {
  41305. +// splx(ipl);
  41306. + getmicrouptime(&tv1);
  41307. + result = msleep(wq, &wq->lock, PCATCH, "dw3wto", tvtohz(&tv));
  41308. + getmicrouptime(&tv2);
  41309. +// ipl = splbio();
  41310. + }
  41311. +
  41312. + if (result == 0) { // awoken
  41313. + if (wq->abort) {
  41314. + result = -DWC_E_ABORT;
  41315. + } else {
  41316. + tv2.tv_usec -= tv1.tv_usec;
  41317. + if (tv2.tv_usec < 0) {
  41318. + tv2.tv_usec += 1000000;
  41319. + tv2.tv_sec--;
  41320. + }
  41321. +
  41322. + tv2.tv_sec -= tv1.tv_sec;
  41323. + result = tv2.tv_sec * 1000 + tv2.tv_usec / 1000;
  41324. + result = msecs - result;
  41325. + if (result <= 0)
  41326. + result = 1;
  41327. + }
  41328. + } else if (result == ERESTART) { // signaled - restart
  41329. + result = -DWC_E_RESTART;
  41330. +
  41331. + } else if (result == EINTR) { // signaled - interrupt
  41332. + result = -DWC_E_ABORT;
  41333. +
  41334. + } else { // timed out
  41335. + result = -DWC_E_TIMEOUT;
  41336. + }
  41337. +
  41338. + wq->abort = 0;
  41339. +// splx(ipl);
  41340. + mtx_unlock(&wq->lock);
  41341. + return result;
  41342. +}
  41343. +
  41344. +void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq)
  41345. +{
  41346. + wakeup(wq);
  41347. +}
  41348. +
  41349. +void DWC_WAITQ_ABORT(dwc_waitq_t *wq)
  41350. +{
  41351. +// intrmask_t ipl;
  41352. +
  41353. + mtx_lock(&wq->lock);
  41354. +// ipl = splbio();
  41355. + wq->abort = 1;
  41356. + wakeup(wq);
  41357. +// splx(ipl);
  41358. + mtx_unlock(&wq->lock);
  41359. +}
  41360. +
  41361. +
  41362. +/* Threading */
  41363. +
  41364. +struct dwc_thread {
  41365. + struct proc *proc;
  41366. + int abort;
  41367. +};
  41368. +
  41369. +dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data)
  41370. +{
  41371. + int retval;
  41372. + dwc_thread_t *thread = DWC_ALLOC(sizeof(*thread));
  41373. +
  41374. + if (!thread) {
  41375. + return NULL;
  41376. + }
  41377. +
  41378. + thread->abort = 0;
  41379. + retval = kthread_create((void (*)(void *))func, data, &thread->proc,
  41380. + RFPROC | RFNOWAIT, 0, "%s", name);
  41381. + if (retval) {
  41382. + DWC_FREE(thread);
  41383. + return NULL;
  41384. + }
  41385. +
  41386. + return thread;
  41387. +}
  41388. +
  41389. +int DWC_THREAD_STOP(dwc_thread_t *thread)
  41390. +{
  41391. + int retval;
  41392. +
  41393. + thread->abort = 1;
  41394. + retval = tsleep(&thread->abort, 0, "dw3stp", 60 * hz);
  41395. +
  41396. + if (retval == 0) {
  41397. + /* DWC_THREAD_EXIT() will free the thread struct */
  41398. + return 0;
  41399. + }
  41400. +
  41401. + /* NOTE: We leak the thread struct if thread doesn't die */
  41402. +
  41403. + if (retval == EWOULDBLOCK) {
  41404. + return -DWC_E_TIMEOUT;
  41405. + }
  41406. +
  41407. + return -DWC_E_UNKNOWN;
  41408. +}
  41409. +
  41410. +dwc_bool_t DWC_THREAD_SHOULD_STOP(dwc_thread_t *thread)
  41411. +{
  41412. + return thread->abort;
  41413. +}
  41414. +
  41415. +void DWC_THREAD_EXIT(dwc_thread_t *thread)
  41416. +{
  41417. + wakeup(&thread->abort);
  41418. + DWC_FREE(thread);
  41419. + kthread_exit(0);
  41420. +}
  41421. +
  41422. +
  41423. +/* tasklets
  41424. + - Runs in interrupt context (cannot sleep)
  41425. + - Each tasklet runs on a single CPU [ How can we ensure this on FreeBSD? Does it matter? ]
  41426. + - Different tasklets can be running simultaneously on different CPUs [ shouldn't matter ]
  41427. + */
  41428. +struct dwc_tasklet {
  41429. + struct task t;
  41430. + dwc_tasklet_callback_t cb;
  41431. + void *data;
  41432. +};
  41433. +
  41434. +static void tasklet_callback(void *data, int pending) // what to do with pending ???
  41435. +{
  41436. + dwc_tasklet_t *task = (dwc_tasklet_t *)data;
  41437. +
  41438. + task->cb(task->data);
  41439. +}
  41440. +
  41441. +dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data)
  41442. +{
  41443. + dwc_tasklet_t *task = DWC_ALLOC(sizeof(*task));
  41444. +
  41445. + if (task) {
  41446. + task->cb = cb;
  41447. + task->data = data;
  41448. + TASK_INIT(&task->t, 0, tasklet_callback, task);
  41449. + } else {
  41450. + DWC_ERROR("Cannot allocate memory for tasklet");
  41451. + }
  41452. +
  41453. + return task;
  41454. +}
  41455. +
  41456. +void DWC_TASK_FREE(dwc_tasklet_t *task)
  41457. +{
  41458. + taskqueue_drain(taskqueue_fast, &task->t); // ???
  41459. + DWC_FREE(task);
  41460. +}
  41461. +
  41462. +void DWC_TASK_SCHEDULE(dwc_tasklet_t *task)
  41463. +{
  41464. + /* Uses predefined system queue */
  41465. + taskqueue_enqueue_fast(taskqueue_fast, &task->t);
  41466. +}
  41467. +
  41468. +
  41469. +/* workqueues
  41470. + - Runs in process context (can sleep)
  41471. + */
  41472. +typedef struct work_container {
  41473. + dwc_work_callback_t cb;
  41474. + void *data;
  41475. + dwc_workq_t *wq;
  41476. + char *name;
  41477. + int hz;
  41478. +
  41479. +#ifdef DEBUG
  41480. + DWC_CIRCLEQ_ENTRY(work_container) entry;
  41481. +#endif
  41482. + struct task task;
  41483. +} work_container_t;
  41484. +
  41485. +#ifdef DEBUG
  41486. +DWC_CIRCLEQ_HEAD(work_container_queue, work_container);
  41487. +#endif
  41488. +
  41489. +struct dwc_workq {
  41490. + struct taskqueue *taskq;
  41491. + dwc_spinlock_t *lock;
  41492. + dwc_waitq_t *waitq;
  41493. + int pending;
  41494. +
  41495. +#ifdef DEBUG
  41496. + struct work_container_queue entries;
  41497. +#endif
  41498. +};
  41499. +
  41500. +static void do_work(void *data, int pending) // what to do with pending ???
  41501. +{
  41502. + work_container_t *container = (work_container_t *)data;
  41503. + dwc_workq_t *wq = container->wq;
  41504. + dwc_irqflags_t flags;
  41505. +
  41506. + if (container->hz) {
  41507. + pause("dw3wrk", container->hz);
  41508. + }
  41509. +
  41510. + container->cb(container->data);
  41511. + DWC_DEBUG("Work done: %s, container=%p", container->name, container);
  41512. +
  41513. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  41514. +
  41515. +#ifdef DEBUG
  41516. + DWC_CIRCLEQ_REMOVE(&wq->entries, container, entry);
  41517. +#endif
  41518. + if (container->name)
  41519. + DWC_FREE(container->name);
  41520. + DWC_FREE(container);
  41521. + wq->pending--;
  41522. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  41523. + DWC_WAITQ_TRIGGER(wq->waitq);
  41524. +}
  41525. +
  41526. +static int work_done(void *data)
  41527. +{
  41528. + dwc_workq_t *workq = (dwc_workq_t *)data;
  41529. +
  41530. + return workq->pending == 0;
  41531. +}
  41532. +
  41533. +int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout)
  41534. +{
  41535. + return DWC_WAITQ_WAIT_TIMEOUT(workq->waitq, work_done, workq, timeout);
  41536. +}
  41537. +
  41538. +dwc_workq_t *DWC_WORKQ_ALLOC(char *name)
  41539. +{
  41540. + dwc_workq_t *wq = DWC_ALLOC(sizeof(*wq));
  41541. +
  41542. + if (!wq) {
  41543. + DWC_ERROR("Cannot allocate memory for workqueue");
  41544. + return NULL;
  41545. + }
  41546. +
  41547. + wq->taskq = taskqueue_create(name, M_NOWAIT, taskqueue_thread_enqueue, &wq->taskq);
  41548. + if (!wq->taskq) {
  41549. + DWC_ERROR("Cannot allocate memory for taskqueue");
  41550. + goto no_taskq;
  41551. + }
  41552. +
  41553. + wq->pending = 0;
  41554. +
  41555. + wq->lock = DWC_SPINLOCK_ALLOC();
  41556. + if (!wq->lock) {
  41557. + DWC_ERROR("Cannot allocate memory for spinlock");
  41558. + goto no_lock;
  41559. + }
  41560. +
  41561. + wq->waitq = DWC_WAITQ_ALLOC();
  41562. + if (!wq->waitq) {
  41563. + DWC_ERROR("Cannot allocate memory for waitqueue");
  41564. + goto no_waitq;
  41565. + }
  41566. +
  41567. + taskqueue_start_threads(&wq->taskq, 1, PWAIT, "%s taskq", "dw3tsk");
  41568. +
  41569. +#ifdef DEBUG
  41570. + DWC_CIRCLEQ_INIT(&wq->entries);
  41571. +#endif
  41572. + return wq;
  41573. +
  41574. + no_waitq:
  41575. + DWC_SPINLOCK_FREE(wq->lock);
  41576. + no_lock:
  41577. + taskqueue_free(wq->taskq);
  41578. + no_taskq:
  41579. + DWC_FREE(wq);
  41580. +
  41581. + return NULL;
  41582. +}
  41583. +
  41584. +void DWC_WORKQ_FREE(dwc_workq_t *wq)
  41585. +{
  41586. +#ifdef DEBUG
  41587. + dwc_irqflags_t flags;
  41588. +
  41589. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  41590. +
  41591. + if (wq->pending != 0) {
  41592. + struct work_container *container;
  41593. +
  41594. + DWC_ERROR("Destroying work queue with pending work");
  41595. +
  41596. + DWC_CIRCLEQ_FOREACH(container, &wq->entries, entry) {
  41597. + DWC_ERROR("Work %s still pending", container->name);
  41598. + }
  41599. + }
  41600. +
  41601. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  41602. +#endif
  41603. + DWC_WAITQ_FREE(wq->waitq);
  41604. + DWC_SPINLOCK_FREE(wq->lock);
  41605. + taskqueue_free(wq->taskq);
  41606. + DWC_FREE(wq);
  41607. +}
  41608. +
  41609. +void DWC_WORKQ_SCHEDULE(dwc_workq_t *wq, dwc_work_callback_t cb, void *data,
  41610. + char *format, ...)
  41611. +{
  41612. + dwc_irqflags_t flags;
  41613. + work_container_t *container;
  41614. + static char name[128];
  41615. + va_list args;
  41616. +
  41617. + va_start(args, format);
  41618. + DWC_VSNPRINTF(name, 128, format, args);
  41619. + va_end(args);
  41620. +
  41621. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  41622. + wq->pending++;
  41623. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  41624. + DWC_WAITQ_TRIGGER(wq->waitq);
  41625. +
  41626. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  41627. + if (!container) {
  41628. + DWC_ERROR("Cannot allocate memory for container");
  41629. + return;
  41630. + }
  41631. +
  41632. + container->name = DWC_STRDUP(name);
  41633. + if (!container->name) {
  41634. + DWC_ERROR("Cannot allocate memory for container->name");
  41635. + DWC_FREE(container);
  41636. + return;
  41637. + }
  41638. +
  41639. + container->cb = cb;
  41640. + container->data = data;
  41641. + container->wq = wq;
  41642. + container->hz = 0;
  41643. +
  41644. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  41645. +
  41646. + TASK_INIT(&container->task, 0, do_work, container);
  41647. +
  41648. +#ifdef DEBUG
  41649. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  41650. +#endif
  41651. + taskqueue_enqueue_fast(wq->taskq, &container->task);
  41652. +}
  41653. +
  41654. +void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *wq, dwc_work_callback_t cb,
  41655. + void *data, uint32_t time, char *format, ...)
  41656. +{
  41657. + dwc_irqflags_t flags;
  41658. + work_container_t *container;
  41659. + static char name[128];
  41660. + struct timeval tv;
  41661. + va_list args;
  41662. +
  41663. + va_start(args, format);
  41664. + DWC_VSNPRINTF(name, 128, format, args);
  41665. + va_end(args);
  41666. +
  41667. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  41668. + wq->pending++;
  41669. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  41670. + DWC_WAITQ_TRIGGER(wq->waitq);
  41671. +
  41672. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  41673. + if (!container) {
  41674. + DWC_ERROR("Cannot allocate memory for container");
  41675. + return;
  41676. + }
  41677. +
  41678. + container->name = DWC_STRDUP(name);
  41679. + if (!container->name) {
  41680. + DWC_ERROR("Cannot allocate memory for container->name");
  41681. + DWC_FREE(container);
  41682. + return;
  41683. + }
  41684. +
  41685. + container->cb = cb;
  41686. + container->data = data;
  41687. + container->wq = wq;
  41688. +
  41689. + tv.tv_sec = time / 1000;
  41690. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  41691. + container->hz = tvtohz(&tv);
  41692. +
  41693. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  41694. +
  41695. + TASK_INIT(&container->task, 0, do_work, container);
  41696. +
  41697. +#ifdef DEBUG
  41698. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  41699. +#endif
  41700. + taskqueue_enqueue_fast(wq->taskq, &container->task);
  41701. +}
  41702. +
  41703. +int DWC_WORKQ_PENDING(dwc_workq_t *wq)
  41704. +{
  41705. + return wq->pending;
  41706. +}
  41707. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_common_port/dwc_common_linux.c linux-3.12.26/drivers/usb/host/dwc_common_port/dwc_common_linux.c
  41708. --- linux-3.12.26.orig/drivers/usb/host/dwc_common_port/dwc_common_linux.c 1970-01-01 01:00:00.000000000 +0100
  41709. +++ linux-3.12.26/drivers/usb/host/dwc_common_port/dwc_common_linux.c 2014-08-06 16:50:14.737964224 +0200
  41710. @@ -0,0 +1,1432 @@
  41711. +#include <linux/kernel.h>
  41712. +#include <linux/init.h>
  41713. +#include <linux/module.h>
  41714. +#include <linux/kthread.h>
  41715. +
  41716. +#ifdef DWC_CCLIB
  41717. +# include "dwc_cc.h"
  41718. +#endif
  41719. +
  41720. +#ifdef DWC_CRYPTOLIB
  41721. +# include "dwc_modpow.h"
  41722. +# include "dwc_dh.h"
  41723. +# include "dwc_crypto.h"
  41724. +#endif
  41725. +
  41726. +#ifdef DWC_NOTIFYLIB
  41727. +# include "dwc_notifier.h"
  41728. +#endif
  41729. +
  41730. +/* OS-Level Implementations */
  41731. +
  41732. +/* This is the Linux kernel implementation of the DWC platform library. */
  41733. +#include <linux/moduleparam.h>
  41734. +#include <linux/ctype.h>
  41735. +#include <linux/crypto.h>
  41736. +#include <linux/delay.h>
  41737. +#include <linux/device.h>
  41738. +#include <linux/dma-mapping.h>
  41739. +#include <linux/cdev.h>
  41740. +#include <linux/errno.h>
  41741. +#include <linux/interrupt.h>
  41742. +#include <linux/jiffies.h>
  41743. +#include <linux/list.h>
  41744. +#include <linux/pci.h>
  41745. +#include <linux/random.h>
  41746. +#include <linux/scatterlist.h>
  41747. +#include <linux/slab.h>
  41748. +#include <linux/stat.h>
  41749. +#include <linux/string.h>
  41750. +#include <linux/timer.h>
  41751. +#include <linux/usb.h>
  41752. +
  41753. +#include <linux/version.h>
  41754. +
  41755. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
  41756. +# include <linux/usb/gadget.h>
  41757. +#else
  41758. +# include <linux/usb_gadget.h>
  41759. +#endif
  41760. +
  41761. +#include <asm/io.h>
  41762. +#include <asm/page.h>
  41763. +#include <asm/uaccess.h>
  41764. +#include <asm/unaligned.h>
  41765. +
  41766. +#include "dwc_os.h"
  41767. +#include "dwc_list.h"
  41768. +
  41769. +
  41770. +/* MISC */
  41771. +
  41772. +void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size)
  41773. +{
  41774. + return memset(dest, byte, size);
  41775. +}
  41776. +
  41777. +void *DWC_MEMCPY(void *dest, void const *src, uint32_t size)
  41778. +{
  41779. + return memcpy(dest, src, size);
  41780. +}
  41781. +
  41782. +void *DWC_MEMMOVE(void *dest, void *src, uint32_t size)
  41783. +{
  41784. + return memmove(dest, src, size);
  41785. +}
  41786. +
  41787. +int DWC_MEMCMP(void *m1, void *m2, uint32_t size)
  41788. +{
  41789. + return memcmp(m1, m2, size);
  41790. +}
  41791. +
  41792. +int DWC_STRNCMP(void *s1, void *s2, uint32_t size)
  41793. +{
  41794. + return strncmp(s1, s2, size);
  41795. +}
  41796. +
  41797. +int DWC_STRCMP(void *s1, void *s2)
  41798. +{
  41799. + return strcmp(s1, s2);
  41800. +}
  41801. +
  41802. +int DWC_STRLEN(char const *str)
  41803. +{
  41804. + return strlen(str);
  41805. +}
  41806. +
  41807. +char *DWC_STRCPY(char *to, char const *from)
  41808. +{
  41809. + return strcpy(to, from);
  41810. +}
  41811. +
  41812. +char *DWC_STRDUP(char const *str)
  41813. +{
  41814. + int len = DWC_STRLEN(str) + 1;
  41815. + char *new = DWC_ALLOC_ATOMIC(len);
  41816. +
  41817. + if (!new) {
  41818. + return NULL;
  41819. + }
  41820. +
  41821. + DWC_MEMCPY(new, str, len);
  41822. + return new;
  41823. +}
  41824. +
  41825. +int DWC_ATOI(const char *str, int32_t *value)
  41826. +{
  41827. + char *end = NULL;
  41828. +
  41829. + *value = simple_strtol(str, &end, 0);
  41830. + if (*end == '\0') {
  41831. + return 0;
  41832. + }
  41833. +
  41834. + return -1;
  41835. +}
  41836. +
  41837. +int DWC_ATOUI(const char *str, uint32_t *value)
  41838. +{
  41839. + char *end = NULL;
  41840. +
  41841. + *value = simple_strtoul(str, &end, 0);
  41842. + if (*end == '\0') {
  41843. + return 0;
  41844. + }
  41845. +
  41846. + return -1;
  41847. +}
  41848. +
  41849. +
  41850. +#ifdef DWC_UTFLIB
  41851. +/* From usbstring.c */
  41852. +
  41853. +int DWC_UTF8_TO_UTF16LE(uint8_t const *s, uint16_t *cp, unsigned len)
  41854. +{
  41855. + int count = 0;
  41856. + u8 c;
  41857. + u16 uchar;
  41858. +
  41859. + /* this insists on correct encodings, though not minimal ones.
  41860. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  41861. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  41862. + */
  41863. + while (len != 0 && (c = (u8) *s++) != 0) {
  41864. + if (unlikely(c & 0x80)) {
  41865. + // 2-byte sequence:
  41866. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  41867. + if ((c & 0xe0) == 0xc0) {
  41868. + uchar = (c & 0x1f) << 6;
  41869. +
  41870. + c = (u8) *s++;
  41871. + if ((c & 0xc0) != 0xc0)
  41872. + goto fail;
  41873. + c &= 0x3f;
  41874. + uchar |= c;
  41875. +
  41876. + // 3-byte sequence (most CJKV characters):
  41877. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  41878. + } else if ((c & 0xf0) == 0xe0) {
  41879. + uchar = (c & 0x0f) << 12;
  41880. +
  41881. + c = (u8) *s++;
  41882. + if ((c & 0xc0) != 0xc0)
  41883. + goto fail;
  41884. + c &= 0x3f;
  41885. + uchar |= c << 6;
  41886. +
  41887. + c = (u8) *s++;
  41888. + if ((c & 0xc0) != 0xc0)
  41889. + goto fail;
  41890. + c &= 0x3f;
  41891. + uchar |= c;
  41892. +
  41893. + /* no bogus surrogates */
  41894. + if (0xd800 <= uchar && uchar <= 0xdfff)
  41895. + goto fail;
  41896. +
  41897. + // 4-byte sequence (surrogate pairs, currently rare):
  41898. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  41899. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  41900. + // (uuuuu = wwww + 1)
  41901. + // FIXME accept the surrogate code points (only)
  41902. + } else
  41903. + goto fail;
  41904. + } else
  41905. + uchar = c;
  41906. + put_unaligned (cpu_to_le16 (uchar), cp++);
  41907. + count++;
  41908. + len--;
  41909. + }
  41910. + return count;
  41911. +fail:
  41912. + return -1;
  41913. +}
  41914. +#endif /* DWC_UTFLIB */
  41915. +
  41916. +
  41917. +/* dwc_debug.h */
  41918. +
  41919. +dwc_bool_t DWC_IN_IRQ(void)
  41920. +{
  41921. + return in_irq();
  41922. +}
  41923. +
  41924. +dwc_bool_t DWC_IN_BH(void)
  41925. +{
  41926. + return in_softirq();
  41927. +}
  41928. +
  41929. +void DWC_VPRINTF(char *format, va_list args)
  41930. +{
  41931. + vprintk(format, args);
  41932. +}
  41933. +
  41934. +int DWC_VSNPRINTF(char *str, int size, char *format, va_list args)
  41935. +{
  41936. + return vsnprintf(str, size, format, args);
  41937. +}
  41938. +
  41939. +void DWC_PRINTF(char *format, ...)
  41940. +{
  41941. + va_list args;
  41942. +
  41943. + va_start(args, format);
  41944. + DWC_VPRINTF(format, args);
  41945. + va_end(args);
  41946. +}
  41947. +
  41948. +int DWC_SPRINTF(char *buffer, char *format, ...)
  41949. +{
  41950. + int retval;
  41951. + va_list args;
  41952. +
  41953. + va_start(args, format);
  41954. + retval = vsprintf(buffer, format, args);
  41955. + va_end(args);
  41956. + return retval;
  41957. +}
  41958. +
  41959. +int DWC_SNPRINTF(char *buffer, int size, char *format, ...)
  41960. +{
  41961. + int retval;
  41962. + va_list args;
  41963. +
  41964. + va_start(args, format);
  41965. + retval = vsnprintf(buffer, size, format, args);
  41966. + va_end(args);
  41967. + return retval;
  41968. +}
  41969. +
  41970. +void __DWC_WARN(char *format, ...)
  41971. +{
  41972. + va_list args;
  41973. +
  41974. + va_start(args, format);
  41975. + DWC_PRINTF(KERN_WARNING);
  41976. + DWC_VPRINTF(format, args);
  41977. + va_end(args);
  41978. +}
  41979. +
  41980. +void __DWC_ERROR(char *format, ...)
  41981. +{
  41982. + va_list args;
  41983. +
  41984. + va_start(args, format);
  41985. + DWC_PRINTF(KERN_ERR);
  41986. + DWC_VPRINTF(format, args);
  41987. + va_end(args);
  41988. +}
  41989. +
  41990. +void DWC_EXCEPTION(char *format, ...)
  41991. +{
  41992. + va_list args;
  41993. +
  41994. + va_start(args, format);
  41995. + DWC_PRINTF(KERN_ERR);
  41996. + DWC_VPRINTF(format, args);
  41997. + va_end(args);
  41998. + BUG_ON(1);
  41999. +}
  42000. +
  42001. +#ifdef DEBUG
  42002. +void __DWC_DEBUG(char *format, ...)
  42003. +{
  42004. + va_list args;
  42005. +
  42006. + va_start(args, format);
  42007. + DWC_PRINTF(KERN_DEBUG);
  42008. + DWC_VPRINTF(format, args);
  42009. + va_end(args);
  42010. +}
  42011. +#endif
  42012. +
  42013. +
  42014. +/* dwc_mem.h */
  42015. +
  42016. +#if 0
  42017. +dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size,
  42018. + uint32_t align,
  42019. + uint32_t alloc)
  42020. +{
  42021. + struct dma_pool *pool = dma_pool_create("Pool", NULL,
  42022. + size, align, alloc);
  42023. + return (dwc_pool_t *)pool;
  42024. +}
  42025. +
  42026. +void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool)
  42027. +{
  42028. + dma_pool_destroy((struct dma_pool *)pool);
  42029. +}
  42030. +
  42031. +void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  42032. +{
  42033. + return dma_pool_alloc((struct dma_pool *)pool, GFP_KERNEL, dma_addr);
  42034. +}
  42035. +
  42036. +void *DWC_DMA_POOL_ZALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  42037. +{
  42038. + void *vaddr = DWC_DMA_POOL_ALLOC(pool, dma_addr);
  42039. + memset(..);
  42040. +}
  42041. +
  42042. +void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr)
  42043. +{
  42044. + dma_pool_free(pool, vaddr, daddr);
  42045. +}
  42046. +#endif
  42047. +
  42048. +void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  42049. +{
  42050. +#ifdef xxCOSIM /* Only works for 32-bit cosim */
  42051. + void *buf = dma_alloc_coherent(dma_ctx, (size_t)size, dma_addr, GFP_KERNEL);
  42052. +#else
  42053. + void *buf = dma_alloc_coherent(dma_ctx, (size_t)size, dma_addr, GFP_KERNEL | GFP_DMA32);
  42054. +#endif
  42055. + if (!buf) {
  42056. + return NULL;
  42057. + }
  42058. +
  42059. + memset(buf, 0, (size_t)size);
  42060. + return buf;
  42061. +}
  42062. +
  42063. +void *__DWC_DMA_ALLOC_ATOMIC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  42064. +{
  42065. + void *buf = dma_alloc_coherent(NULL, (size_t)size, dma_addr, GFP_ATOMIC);
  42066. + if (!buf) {
  42067. + return NULL;
  42068. + }
  42069. + memset(buf, 0, (size_t)size);
  42070. + return buf;
  42071. +}
  42072. +
  42073. +void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr)
  42074. +{
  42075. + dma_free_coherent(dma_ctx, size, virt_addr, dma_addr);
  42076. +}
  42077. +
  42078. +void *__DWC_ALLOC(void *mem_ctx, uint32_t size)
  42079. +{
  42080. + return kzalloc(size, GFP_KERNEL);
  42081. +}
  42082. +
  42083. +void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size)
  42084. +{
  42085. + return kzalloc(size, GFP_ATOMIC);
  42086. +}
  42087. +
  42088. +void __DWC_FREE(void *mem_ctx, void *addr)
  42089. +{
  42090. + kfree(addr);
  42091. +}
  42092. +
  42093. +
  42094. +#ifdef DWC_CRYPTOLIB
  42095. +/* dwc_crypto.h */
  42096. +
  42097. +void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length)
  42098. +{
  42099. + get_random_bytes(buffer, length);
  42100. +}
  42101. +
  42102. +int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out)
  42103. +{
  42104. + struct crypto_blkcipher *tfm;
  42105. + struct blkcipher_desc desc;
  42106. + struct scatterlist sgd;
  42107. + struct scatterlist sgs;
  42108. +
  42109. + tfm = crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC);
  42110. + if (tfm == NULL) {
  42111. + printk("failed to load transform for aes CBC\n");
  42112. + return -1;
  42113. + }
  42114. +
  42115. + crypto_blkcipher_setkey(tfm, key, keylen);
  42116. + crypto_blkcipher_set_iv(tfm, iv, 16);
  42117. +
  42118. + sg_init_one(&sgd, out, messagelen);
  42119. + sg_init_one(&sgs, message, messagelen);
  42120. +
  42121. + desc.tfm = tfm;
  42122. + desc.flags = 0;
  42123. +
  42124. + if (crypto_blkcipher_encrypt(&desc, &sgd, &sgs, messagelen)) {
  42125. + crypto_free_blkcipher(tfm);
  42126. + DWC_ERROR("AES CBC encryption failed");
  42127. + return -1;
  42128. + }
  42129. +
  42130. + crypto_free_blkcipher(tfm);
  42131. + return 0;
  42132. +}
  42133. +
  42134. +int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out)
  42135. +{
  42136. + struct crypto_hash *tfm;
  42137. + struct hash_desc desc;
  42138. + struct scatterlist sg;
  42139. +
  42140. + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
  42141. + if (IS_ERR(tfm)) {
  42142. + DWC_ERROR("Failed to load transform for sha256: %ld\n", PTR_ERR(tfm));
  42143. + return 0;
  42144. + }
  42145. + desc.tfm = tfm;
  42146. + desc.flags = 0;
  42147. +
  42148. + sg_init_one(&sg, message, len);
  42149. + crypto_hash_digest(&desc, &sg, len, out);
  42150. + crypto_free_hash(tfm);
  42151. +
  42152. + return 1;
  42153. +}
  42154. +
  42155. +int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen,
  42156. + uint8_t *key, uint32_t keylen, uint8_t *out)
  42157. +{
  42158. + struct crypto_hash *tfm;
  42159. + struct hash_desc desc;
  42160. + struct scatterlist sg;
  42161. +
  42162. + tfm = crypto_alloc_hash("hmac(sha256)", 0, CRYPTO_ALG_ASYNC);
  42163. + if (IS_ERR(tfm)) {
  42164. + DWC_ERROR("Failed to load transform for hmac(sha256): %ld\n", PTR_ERR(tfm));
  42165. + return 0;
  42166. + }
  42167. + desc.tfm = tfm;
  42168. + desc.flags = 0;
  42169. +
  42170. + sg_init_one(&sg, message, messagelen);
  42171. + crypto_hash_setkey(tfm, key, keylen);
  42172. + crypto_hash_digest(&desc, &sg, messagelen, out);
  42173. + crypto_free_hash(tfm);
  42174. +
  42175. + return 1;
  42176. +}
  42177. +#endif /* DWC_CRYPTOLIB */
  42178. +
  42179. +
  42180. +/* Byte Ordering Conversions */
  42181. +
  42182. +uint32_t DWC_CPU_TO_LE32(uint32_t *p)
  42183. +{
  42184. +#ifdef __LITTLE_ENDIAN
  42185. + return *p;
  42186. +#else
  42187. + uint8_t *u_p = (uint8_t *)p;
  42188. +
  42189. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  42190. +#endif
  42191. +}
  42192. +
  42193. +uint32_t DWC_CPU_TO_BE32(uint32_t *p)
  42194. +{
  42195. +#ifdef __BIG_ENDIAN
  42196. + return *p;
  42197. +#else
  42198. + uint8_t *u_p = (uint8_t *)p;
  42199. +
  42200. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  42201. +#endif
  42202. +}
  42203. +
  42204. +uint32_t DWC_LE32_TO_CPU(uint32_t *p)
  42205. +{
  42206. +#ifdef __LITTLE_ENDIAN
  42207. + return *p;
  42208. +#else
  42209. + uint8_t *u_p = (uint8_t *)p;
  42210. +
  42211. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  42212. +#endif
  42213. +}
  42214. +
  42215. +uint32_t DWC_BE32_TO_CPU(uint32_t *p)
  42216. +{
  42217. +#ifdef __BIG_ENDIAN
  42218. + return *p;
  42219. +#else
  42220. + uint8_t *u_p = (uint8_t *)p;
  42221. +
  42222. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  42223. +#endif
  42224. +}
  42225. +
  42226. +uint16_t DWC_CPU_TO_LE16(uint16_t *p)
  42227. +{
  42228. +#ifdef __LITTLE_ENDIAN
  42229. + return *p;
  42230. +#else
  42231. + uint8_t *u_p = (uint8_t *)p;
  42232. + return (u_p[1] | (u_p[0] << 8));
  42233. +#endif
  42234. +}
  42235. +
  42236. +uint16_t DWC_CPU_TO_BE16(uint16_t *p)
  42237. +{
  42238. +#ifdef __BIG_ENDIAN
  42239. + return *p;
  42240. +#else
  42241. + uint8_t *u_p = (uint8_t *)p;
  42242. + return (u_p[1] | (u_p[0] << 8));
  42243. +#endif
  42244. +}
  42245. +
  42246. +uint16_t DWC_LE16_TO_CPU(uint16_t *p)
  42247. +{
  42248. +#ifdef __LITTLE_ENDIAN
  42249. + return *p;
  42250. +#else
  42251. + uint8_t *u_p = (uint8_t *)p;
  42252. + return (u_p[1] | (u_p[0] << 8));
  42253. +#endif
  42254. +}
  42255. +
  42256. +uint16_t DWC_BE16_TO_CPU(uint16_t *p)
  42257. +{
  42258. +#ifdef __BIG_ENDIAN
  42259. + return *p;
  42260. +#else
  42261. + uint8_t *u_p = (uint8_t *)p;
  42262. + return (u_p[1] | (u_p[0] << 8));
  42263. +#endif
  42264. +}
  42265. +
  42266. +
  42267. +/* Registers */
  42268. +
  42269. +uint32_t DWC_READ_REG32(uint32_t volatile *reg)
  42270. +{
  42271. + return readl(reg);
  42272. +}
  42273. +
  42274. +#if 0
  42275. +uint64_t DWC_READ_REG64(uint64_t volatile *reg)
  42276. +{
  42277. +}
  42278. +#endif
  42279. +
  42280. +void DWC_WRITE_REG32(uint32_t volatile *reg, uint32_t value)
  42281. +{
  42282. + writel(value, reg);
  42283. +}
  42284. +
  42285. +#if 0
  42286. +void DWC_WRITE_REG64(uint64_t volatile *reg, uint64_t value)
  42287. +{
  42288. +}
  42289. +#endif
  42290. +
  42291. +void DWC_MODIFY_REG32(uint32_t volatile *reg, uint32_t clear_mask, uint32_t set_mask)
  42292. +{
  42293. + unsigned long flags;
  42294. +
  42295. + local_irq_save(flags);
  42296. + local_fiq_disable();
  42297. + writel((readl(reg) & ~clear_mask) | set_mask, reg);
  42298. + local_fiq_enable();
  42299. + local_irq_restore(flags);
  42300. +}
  42301. +
  42302. +#if 0
  42303. +void DWC_MODIFY_REG64(uint64_t volatile *reg, uint64_t clear_mask, uint64_t set_mask)
  42304. +{
  42305. +}
  42306. +#endif
  42307. +
  42308. +
  42309. +/* Locking */
  42310. +
  42311. +dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void)
  42312. +{
  42313. + spinlock_t *sl = (spinlock_t *)1;
  42314. +
  42315. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  42316. + sl = DWC_ALLOC(sizeof(*sl));
  42317. + if (!sl) {
  42318. + DWC_ERROR("Cannot allocate memory for spinlock\n");
  42319. + return NULL;
  42320. + }
  42321. +
  42322. + spin_lock_init(sl);
  42323. +#endif
  42324. + return (dwc_spinlock_t *)sl;
  42325. +}
  42326. +
  42327. +void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock)
  42328. +{
  42329. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  42330. + DWC_FREE(lock);
  42331. +#endif
  42332. +}
  42333. +
  42334. +void DWC_SPINLOCK(dwc_spinlock_t *lock)
  42335. +{
  42336. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  42337. + spin_lock((spinlock_t *)lock);
  42338. +#endif
  42339. +}
  42340. +
  42341. +void DWC_SPINUNLOCK(dwc_spinlock_t *lock)
  42342. +{
  42343. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  42344. + spin_unlock((spinlock_t *)lock);
  42345. +#endif
  42346. +}
  42347. +
  42348. +void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags)
  42349. +{
  42350. + dwc_irqflags_t f;
  42351. +
  42352. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  42353. + spin_lock_irqsave((spinlock_t *)lock, f);
  42354. +#else
  42355. + local_irq_save(f);
  42356. +#endif
  42357. + *flags = f;
  42358. +}
  42359. +
  42360. +void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags)
  42361. +{
  42362. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  42363. + spin_unlock_irqrestore((spinlock_t *)lock, flags);
  42364. +#else
  42365. + local_irq_restore(flags);
  42366. +#endif
  42367. +}
  42368. +
  42369. +dwc_mutex_t *DWC_MUTEX_ALLOC(void)
  42370. +{
  42371. + struct mutex *m;
  42372. + dwc_mutex_t *mutex = (dwc_mutex_t *)DWC_ALLOC(sizeof(struct mutex));
  42373. +
  42374. + if (!mutex) {
  42375. + DWC_ERROR("Cannot allocate memory for mutex\n");
  42376. + return NULL;
  42377. + }
  42378. +
  42379. + m = (struct mutex *)mutex;
  42380. + mutex_init(m);
  42381. + return mutex;
  42382. +}
  42383. +
  42384. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  42385. +#else
  42386. +void DWC_MUTEX_FREE(dwc_mutex_t *mutex)
  42387. +{
  42388. + mutex_destroy((struct mutex *)mutex);
  42389. + DWC_FREE(mutex);
  42390. +}
  42391. +#endif
  42392. +
  42393. +void DWC_MUTEX_LOCK(dwc_mutex_t *mutex)
  42394. +{
  42395. + struct mutex *m = (struct mutex *)mutex;
  42396. + mutex_lock(m);
  42397. +}
  42398. +
  42399. +int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex)
  42400. +{
  42401. + struct mutex *m = (struct mutex *)mutex;
  42402. + return mutex_trylock(m);
  42403. +}
  42404. +
  42405. +void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex)
  42406. +{
  42407. + struct mutex *m = (struct mutex *)mutex;
  42408. + mutex_unlock(m);
  42409. +}
  42410. +
  42411. +
  42412. +/* Timing */
  42413. +
  42414. +void DWC_UDELAY(uint32_t usecs)
  42415. +{
  42416. + udelay(usecs);
  42417. +}
  42418. +
  42419. +void DWC_MDELAY(uint32_t msecs)
  42420. +{
  42421. + mdelay(msecs);
  42422. +}
  42423. +
  42424. +void DWC_MSLEEP(uint32_t msecs)
  42425. +{
  42426. + msleep(msecs);
  42427. +}
  42428. +
  42429. +uint32_t DWC_TIME(void)
  42430. +{
  42431. + return jiffies_to_msecs(jiffies);
  42432. +}
  42433. +
  42434. +
  42435. +/* Timers */
  42436. +
  42437. +struct dwc_timer {
  42438. + struct timer_list *t;
  42439. + char *name;
  42440. + dwc_timer_callback_t cb;
  42441. + void *data;
  42442. + uint8_t scheduled;
  42443. + dwc_spinlock_t *lock;
  42444. +};
  42445. +
  42446. +static void timer_callback(unsigned long data)
  42447. +{
  42448. + dwc_timer_t *timer = (dwc_timer_t *)data;
  42449. + dwc_irqflags_t flags;
  42450. +
  42451. + DWC_SPINLOCK_IRQSAVE(timer->lock, &flags);
  42452. + timer->scheduled = 0;
  42453. + DWC_SPINUNLOCK_IRQRESTORE(timer->lock, flags);
  42454. + DWC_DEBUGC("Timer %s callback", timer->name);
  42455. + timer->cb(timer->data);
  42456. +}
  42457. +
  42458. +dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data)
  42459. +{
  42460. + dwc_timer_t *t = DWC_ALLOC(sizeof(*t));
  42461. +
  42462. + if (!t) {
  42463. + DWC_ERROR("Cannot allocate memory for timer");
  42464. + return NULL;
  42465. + }
  42466. +
  42467. + t->t = DWC_ALLOC(sizeof(*t->t));
  42468. + if (!t->t) {
  42469. + DWC_ERROR("Cannot allocate memory for timer->t");
  42470. + goto no_timer;
  42471. + }
  42472. +
  42473. + t->name = DWC_STRDUP(name);
  42474. + if (!t->name) {
  42475. + DWC_ERROR("Cannot allocate memory for timer->name");
  42476. + goto no_name;
  42477. + }
  42478. +
  42479. + t->lock = DWC_SPINLOCK_ALLOC();
  42480. + if (!t->lock) {
  42481. + DWC_ERROR("Cannot allocate memory for lock");
  42482. + goto no_lock;
  42483. + }
  42484. +
  42485. + t->scheduled = 0;
  42486. + t->t->base = &boot_tvec_bases;
  42487. + t->t->expires = jiffies;
  42488. + setup_timer(t->t, timer_callback, (unsigned long)t);
  42489. +
  42490. + t->cb = cb;
  42491. + t->data = data;
  42492. +
  42493. + return t;
  42494. +
  42495. + no_lock:
  42496. + DWC_FREE(t->name);
  42497. + no_name:
  42498. + DWC_FREE(t->t);
  42499. + no_timer:
  42500. + DWC_FREE(t);
  42501. + return NULL;
  42502. +}
  42503. +
  42504. +void DWC_TIMER_FREE(dwc_timer_t *timer)
  42505. +{
  42506. + dwc_irqflags_t flags;
  42507. +
  42508. + DWC_SPINLOCK_IRQSAVE(timer->lock, &flags);
  42509. +
  42510. + if (timer->scheduled) {
  42511. + del_timer(timer->t);
  42512. + timer->scheduled = 0;
  42513. + }
  42514. +
  42515. + DWC_SPINUNLOCK_IRQRESTORE(timer->lock, flags);
  42516. + DWC_SPINLOCK_FREE(timer->lock);
  42517. + DWC_FREE(timer->t);
  42518. + DWC_FREE(timer->name);
  42519. + DWC_FREE(timer);
  42520. +}
  42521. +
  42522. +void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time)
  42523. +{
  42524. + dwc_irqflags_t flags;
  42525. +
  42526. + DWC_SPINLOCK_IRQSAVE(timer->lock, &flags);
  42527. +
  42528. + if (!timer->scheduled) {
  42529. + timer->scheduled = 1;
  42530. + DWC_DEBUGC("Scheduling timer %s to expire in +%d msec", timer->name, time);
  42531. + timer->t->expires = jiffies + msecs_to_jiffies(time);
  42532. + add_timer(timer->t);
  42533. + } else {
  42534. + DWC_DEBUGC("Modifying timer %s to expire in +%d msec", timer->name, time);
  42535. + mod_timer(timer->t, jiffies + msecs_to_jiffies(time));
  42536. + }
  42537. +
  42538. + DWC_SPINUNLOCK_IRQRESTORE(timer->lock, flags);
  42539. +}
  42540. +
  42541. +void DWC_TIMER_CANCEL(dwc_timer_t *timer)
  42542. +{
  42543. + del_timer(timer->t);
  42544. +}
  42545. +
  42546. +
  42547. +/* Wait Queues */
  42548. +
  42549. +struct dwc_waitq {
  42550. + wait_queue_head_t queue;
  42551. + int abort;
  42552. +};
  42553. +
  42554. +dwc_waitq_t *DWC_WAITQ_ALLOC(void)
  42555. +{
  42556. + dwc_waitq_t *wq = DWC_ALLOC(sizeof(*wq));
  42557. +
  42558. + if (!wq) {
  42559. + DWC_ERROR("Cannot allocate memory for waitqueue\n");
  42560. + return NULL;
  42561. + }
  42562. +
  42563. + init_waitqueue_head(&wq->queue);
  42564. + wq->abort = 0;
  42565. + return wq;
  42566. +}
  42567. +
  42568. +void DWC_WAITQ_FREE(dwc_waitq_t *wq)
  42569. +{
  42570. + DWC_FREE(wq);
  42571. +}
  42572. +
  42573. +int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data)
  42574. +{
  42575. + int result = wait_event_interruptible(wq->queue,
  42576. + cond(data) || wq->abort);
  42577. + if (result == -ERESTARTSYS) {
  42578. + wq->abort = 0;
  42579. + return -DWC_E_RESTART;
  42580. + }
  42581. +
  42582. + if (wq->abort == 1) {
  42583. + wq->abort = 0;
  42584. + return -DWC_E_ABORT;
  42585. + }
  42586. +
  42587. + wq->abort = 0;
  42588. +
  42589. + if (result == 0) {
  42590. + return 0;
  42591. + }
  42592. +
  42593. + return -DWC_E_UNKNOWN;
  42594. +}
  42595. +
  42596. +int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  42597. + void *data, int32_t msecs)
  42598. +{
  42599. + int32_t tmsecs;
  42600. + int result = wait_event_interruptible_timeout(wq->queue,
  42601. + cond(data) || wq->abort,
  42602. + msecs_to_jiffies(msecs));
  42603. + if (result == -ERESTARTSYS) {
  42604. + wq->abort = 0;
  42605. + return -DWC_E_RESTART;
  42606. + }
  42607. +
  42608. + if (wq->abort == 1) {
  42609. + wq->abort = 0;
  42610. + return -DWC_E_ABORT;
  42611. + }
  42612. +
  42613. + wq->abort = 0;
  42614. +
  42615. + if (result > 0) {
  42616. + tmsecs = jiffies_to_msecs(result);
  42617. + if (!tmsecs) {
  42618. + return 1;
  42619. + }
  42620. +
  42621. + return tmsecs;
  42622. + }
  42623. +
  42624. + if (result == 0) {
  42625. + return -DWC_E_TIMEOUT;
  42626. + }
  42627. +
  42628. + return -DWC_E_UNKNOWN;
  42629. +}
  42630. +
  42631. +void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq)
  42632. +{
  42633. + wq->abort = 0;
  42634. + wake_up_interruptible(&wq->queue);
  42635. +}
  42636. +
  42637. +void DWC_WAITQ_ABORT(dwc_waitq_t *wq)
  42638. +{
  42639. + wq->abort = 1;
  42640. + wake_up_interruptible(&wq->queue);
  42641. +}
  42642. +
  42643. +
  42644. +/* Threading */
  42645. +
  42646. +dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data)
  42647. +{
  42648. + struct task_struct *thread = kthread_run(func, data, name);
  42649. +
  42650. + if (thread == ERR_PTR(-ENOMEM)) {
  42651. + return NULL;
  42652. + }
  42653. +
  42654. + return (dwc_thread_t *)thread;
  42655. +}
  42656. +
  42657. +int DWC_THREAD_STOP(dwc_thread_t *thread)
  42658. +{
  42659. + return kthread_stop((struct task_struct *)thread);
  42660. +}
  42661. +
  42662. +dwc_bool_t DWC_THREAD_SHOULD_STOP(void)
  42663. +{
  42664. + return kthread_should_stop();
  42665. +}
  42666. +
  42667. +
  42668. +/* tasklets
  42669. + - run in interrupt context (cannot sleep)
  42670. + - each tasklet runs on a single CPU
  42671. + - different tasklets can be running simultaneously on different CPUs
  42672. + */
  42673. +struct dwc_tasklet {
  42674. + struct tasklet_struct t;
  42675. + dwc_tasklet_callback_t cb;
  42676. + void *data;
  42677. +};
  42678. +
  42679. +static void tasklet_callback(unsigned long data)
  42680. +{
  42681. + dwc_tasklet_t *t = (dwc_tasklet_t *)data;
  42682. + t->cb(t->data);
  42683. +}
  42684. +
  42685. +dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data)
  42686. +{
  42687. + dwc_tasklet_t *t = DWC_ALLOC(sizeof(*t));
  42688. +
  42689. + if (t) {
  42690. + t->cb = cb;
  42691. + t->data = data;
  42692. + tasklet_init(&t->t, tasklet_callback, (unsigned long)t);
  42693. + } else {
  42694. + DWC_ERROR("Cannot allocate memory for tasklet\n");
  42695. + }
  42696. +
  42697. + return t;
  42698. +}
  42699. +
  42700. +void DWC_TASK_FREE(dwc_tasklet_t *task)
  42701. +{
  42702. + DWC_FREE(task);
  42703. +}
  42704. +
  42705. +void DWC_TASK_SCHEDULE(dwc_tasklet_t *task)
  42706. +{
  42707. + tasklet_schedule(&task->t);
  42708. +}
  42709. +
  42710. +void DWC_TASK_HI_SCHEDULE(dwc_tasklet_t *task)
  42711. +{
  42712. + tasklet_hi_schedule(&task->t);
  42713. +}
  42714. +
  42715. +
  42716. +/* workqueues
  42717. + - run in process context (can sleep)
  42718. + */
  42719. +typedef struct work_container {
  42720. + dwc_work_callback_t cb;
  42721. + void *data;
  42722. + dwc_workq_t *wq;
  42723. + char *name;
  42724. +
  42725. +#ifdef DEBUG
  42726. + DWC_CIRCLEQ_ENTRY(work_container) entry;
  42727. +#endif
  42728. + struct delayed_work work;
  42729. +} work_container_t;
  42730. +
  42731. +#ifdef DEBUG
  42732. +DWC_CIRCLEQ_HEAD(work_container_queue, work_container);
  42733. +#endif
  42734. +
  42735. +struct dwc_workq {
  42736. + struct workqueue_struct *wq;
  42737. + dwc_spinlock_t *lock;
  42738. + dwc_waitq_t *waitq;
  42739. + int pending;
  42740. +
  42741. +#ifdef DEBUG
  42742. + struct work_container_queue entries;
  42743. +#endif
  42744. +};
  42745. +
  42746. +static void do_work(struct work_struct *work)
  42747. +{
  42748. + dwc_irqflags_t flags;
  42749. + struct delayed_work *dw = container_of(work, struct delayed_work, work);
  42750. + work_container_t *container = container_of(dw, struct work_container, work);
  42751. + dwc_workq_t *wq = container->wq;
  42752. +
  42753. + container->cb(container->data);
  42754. +
  42755. +#ifdef DEBUG
  42756. + DWC_CIRCLEQ_REMOVE(&wq->entries, container, entry);
  42757. +#endif
  42758. + DWC_DEBUGC("Work done: %s, container=%p", container->name, container);
  42759. + if (container->name) {
  42760. + DWC_FREE(container->name);
  42761. + }
  42762. + DWC_FREE(container);
  42763. +
  42764. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  42765. + wq->pending--;
  42766. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  42767. + DWC_WAITQ_TRIGGER(wq->waitq);
  42768. +}
  42769. +
  42770. +static int work_done(void *data)
  42771. +{
  42772. + dwc_workq_t *workq = (dwc_workq_t *)data;
  42773. + return workq->pending == 0;
  42774. +}
  42775. +
  42776. +int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout)
  42777. +{
  42778. + return DWC_WAITQ_WAIT_TIMEOUT(workq->waitq, work_done, workq, timeout);
  42779. +}
  42780. +
  42781. +dwc_workq_t *DWC_WORKQ_ALLOC(char *name)
  42782. +{
  42783. + dwc_workq_t *wq = DWC_ALLOC(sizeof(*wq));
  42784. +
  42785. + if (!wq) {
  42786. + return NULL;
  42787. + }
  42788. +
  42789. + wq->wq = create_singlethread_workqueue(name);
  42790. + if (!wq->wq) {
  42791. + goto no_wq;
  42792. + }
  42793. +
  42794. + wq->pending = 0;
  42795. +
  42796. + wq->lock = DWC_SPINLOCK_ALLOC();
  42797. + if (!wq->lock) {
  42798. + goto no_lock;
  42799. + }
  42800. +
  42801. + wq->waitq = DWC_WAITQ_ALLOC();
  42802. + if (!wq->waitq) {
  42803. + goto no_waitq;
  42804. + }
  42805. +
  42806. +#ifdef DEBUG
  42807. + DWC_CIRCLEQ_INIT(&wq->entries);
  42808. +#endif
  42809. + return wq;
  42810. +
  42811. + no_waitq:
  42812. + DWC_SPINLOCK_FREE(wq->lock);
  42813. + no_lock:
  42814. + destroy_workqueue(wq->wq);
  42815. + no_wq:
  42816. + DWC_FREE(wq);
  42817. +
  42818. + return NULL;
  42819. +}
  42820. +
  42821. +void DWC_WORKQ_FREE(dwc_workq_t *wq)
  42822. +{
  42823. +#ifdef DEBUG
  42824. + if (wq->pending != 0) {
  42825. + struct work_container *wc;
  42826. + DWC_ERROR("Destroying work queue with pending work");
  42827. + DWC_CIRCLEQ_FOREACH(wc, &wq->entries, entry) {
  42828. + DWC_ERROR("Work %s still pending", wc->name);
  42829. + }
  42830. + }
  42831. +#endif
  42832. + destroy_workqueue(wq->wq);
  42833. + DWC_SPINLOCK_FREE(wq->lock);
  42834. + DWC_WAITQ_FREE(wq->waitq);
  42835. + DWC_FREE(wq);
  42836. +}
  42837. +
  42838. +void DWC_WORKQ_SCHEDULE(dwc_workq_t *wq, dwc_work_callback_t cb, void *data,
  42839. + char *format, ...)
  42840. +{
  42841. + dwc_irqflags_t flags;
  42842. + work_container_t *container;
  42843. + static char name[128];
  42844. + va_list args;
  42845. +
  42846. + va_start(args, format);
  42847. + DWC_VSNPRINTF(name, 128, format, args);
  42848. + va_end(args);
  42849. +
  42850. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  42851. + wq->pending++;
  42852. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  42853. + DWC_WAITQ_TRIGGER(wq->waitq);
  42854. +
  42855. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  42856. + if (!container) {
  42857. + DWC_ERROR("Cannot allocate memory for container\n");
  42858. + return;
  42859. + }
  42860. +
  42861. + container->name = DWC_STRDUP(name);
  42862. + if (!container->name) {
  42863. + DWC_ERROR("Cannot allocate memory for container->name\n");
  42864. + DWC_FREE(container);
  42865. + return;
  42866. + }
  42867. +
  42868. + container->cb = cb;
  42869. + container->data = data;
  42870. + container->wq = wq;
  42871. + DWC_DEBUGC("Queueing work: %s, container=%p", container->name, container);
  42872. + INIT_WORK(&container->work.work, do_work);
  42873. +
  42874. +#ifdef DEBUG
  42875. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  42876. +#endif
  42877. + queue_work(wq->wq, &container->work.work);
  42878. +}
  42879. +
  42880. +void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *wq, dwc_work_callback_t cb,
  42881. + void *data, uint32_t time, char *format, ...)
  42882. +{
  42883. + dwc_irqflags_t flags;
  42884. + work_container_t *container;
  42885. + static char name[128];
  42886. + va_list args;
  42887. +
  42888. + va_start(args, format);
  42889. + DWC_VSNPRINTF(name, 128, format, args);
  42890. + va_end(args);
  42891. +
  42892. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  42893. + wq->pending++;
  42894. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  42895. + DWC_WAITQ_TRIGGER(wq->waitq);
  42896. +
  42897. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  42898. + if (!container) {
  42899. + DWC_ERROR("Cannot allocate memory for container\n");
  42900. + return;
  42901. + }
  42902. +
  42903. + container->name = DWC_STRDUP(name);
  42904. + if (!container->name) {
  42905. + DWC_ERROR("Cannot allocate memory for container->name\n");
  42906. + DWC_FREE(container);
  42907. + return;
  42908. + }
  42909. +
  42910. + container->cb = cb;
  42911. + container->data = data;
  42912. + container->wq = wq;
  42913. + DWC_DEBUGC("Queueing work: %s, container=%p", container->name, container);
  42914. + INIT_DELAYED_WORK(&container->work, do_work);
  42915. +
  42916. +#ifdef DEBUG
  42917. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  42918. +#endif
  42919. + queue_delayed_work(wq->wq, &container->work, msecs_to_jiffies(time));
  42920. +}
  42921. +
  42922. +int DWC_WORKQ_PENDING(dwc_workq_t *wq)
  42923. +{
  42924. + return wq->pending;
  42925. +}
  42926. +
  42927. +
  42928. +#ifdef DWC_LIBMODULE
  42929. +
  42930. +#ifdef DWC_CCLIB
  42931. +/* CC */
  42932. +EXPORT_SYMBOL(dwc_cc_if_alloc);
  42933. +EXPORT_SYMBOL(dwc_cc_if_free);
  42934. +EXPORT_SYMBOL(dwc_cc_clear);
  42935. +EXPORT_SYMBOL(dwc_cc_add);
  42936. +EXPORT_SYMBOL(dwc_cc_remove);
  42937. +EXPORT_SYMBOL(dwc_cc_change);
  42938. +EXPORT_SYMBOL(dwc_cc_data_for_save);
  42939. +EXPORT_SYMBOL(dwc_cc_restore_from_data);
  42940. +EXPORT_SYMBOL(dwc_cc_match_chid);
  42941. +EXPORT_SYMBOL(dwc_cc_match_cdid);
  42942. +EXPORT_SYMBOL(dwc_cc_ck);
  42943. +EXPORT_SYMBOL(dwc_cc_chid);
  42944. +EXPORT_SYMBOL(dwc_cc_cdid);
  42945. +EXPORT_SYMBOL(dwc_cc_name);
  42946. +#endif /* DWC_CCLIB */
  42947. +
  42948. +#ifdef DWC_CRYPTOLIB
  42949. +# ifndef CONFIG_MACH_IPMATE
  42950. +/* Modpow */
  42951. +EXPORT_SYMBOL(dwc_modpow);
  42952. +
  42953. +/* DH */
  42954. +EXPORT_SYMBOL(dwc_dh_modpow);
  42955. +EXPORT_SYMBOL(dwc_dh_derive_keys);
  42956. +EXPORT_SYMBOL(dwc_dh_pk);
  42957. +# endif /* CONFIG_MACH_IPMATE */
  42958. +
  42959. +/* Crypto */
  42960. +EXPORT_SYMBOL(dwc_wusb_aes_encrypt);
  42961. +EXPORT_SYMBOL(dwc_wusb_cmf);
  42962. +EXPORT_SYMBOL(dwc_wusb_prf);
  42963. +EXPORT_SYMBOL(dwc_wusb_fill_ccm_nonce);
  42964. +EXPORT_SYMBOL(dwc_wusb_gen_nonce);
  42965. +EXPORT_SYMBOL(dwc_wusb_gen_key);
  42966. +EXPORT_SYMBOL(dwc_wusb_gen_mic);
  42967. +#endif /* DWC_CRYPTOLIB */
  42968. +
  42969. +/* Notification */
  42970. +#ifdef DWC_NOTIFYLIB
  42971. +EXPORT_SYMBOL(dwc_alloc_notification_manager);
  42972. +EXPORT_SYMBOL(dwc_free_notification_manager);
  42973. +EXPORT_SYMBOL(dwc_register_notifier);
  42974. +EXPORT_SYMBOL(dwc_unregister_notifier);
  42975. +EXPORT_SYMBOL(dwc_add_observer);
  42976. +EXPORT_SYMBOL(dwc_remove_observer);
  42977. +EXPORT_SYMBOL(dwc_notify);
  42978. +#endif
  42979. +
  42980. +/* Memory Debugging Routines */
  42981. +#ifdef DWC_DEBUG_MEMORY
  42982. +EXPORT_SYMBOL(dwc_alloc_debug);
  42983. +EXPORT_SYMBOL(dwc_alloc_atomic_debug);
  42984. +EXPORT_SYMBOL(dwc_free_debug);
  42985. +EXPORT_SYMBOL(dwc_dma_alloc_debug);
  42986. +EXPORT_SYMBOL(dwc_dma_free_debug);
  42987. +#endif
  42988. +
  42989. +EXPORT_SYMBOL(DWC_MEMSET);
  42990. +EXPORT_SYMBOL(DWC_MEMCPY);
  42991. +EXPORT_SYMBOL(DWC_MEMMOVE);
  42992. +EXPORT_SYMBOL(DWC_MEMCMP);
  42993. +EXPORT_SYMBOL(DWC_STRNCMP);
  42994. +EXPORT_SYMBOL(DWC_STRCMP);
  42995. +EXPORT_SYMBOL(DWC_STRLEN);
  42996. +EXPORT_SYMBOL(DWC_STRCPY);
  42997. +EXPORT_SYMBOL(DWC_STRDUP);
  42998. +EXPORT_SYMBOL(DWC_ATOI);
  42999. +EXPORT_SYMBOL(DWC_ATOUI);
  43000. +
  43001. +#ifdef DWC_UTFLIB
  43002. +EXPORT_SYMBOL(DWC_UTF8_TO_UTF16LE);
  43003. +#endif /* DWC_UTFLIB */
  43004. +
  43005. +EXPORT_SYMBOL(DWC_IN_IRQ);
  43006. +EXPORT_SYMBOL(DWC_IN_BH);
  43007. +EXPORT_SYMBOL(DWC_VPRINTF);
  43008. +EXPORT_SYMBOL(DWC_VSNPRINTF);
  43009. +EXPORT_SYMBOL(DWC_PRINTF);
  43010. +EXPORT_SYMBOL(DWC_SPRINTF);
  43011. +EXPORT_SYMBOL(DWC_SNPRINTF);
  43012. +EXPORT_SYMBOL(__DWC_WARN);
  43013. +EXPORT_SYMBOL(__DWC_ERROR);
  43014. +EXPORT_SYMBOL(DWC_EXCEPTION);
  43015. +
  43016. +#ifdef DEBUG
  43017. +EXPORT_SYMBOL(__DWC_DEBUG);
  43018. +#endif
  43019. +
  43020. +EXPORT_SYMBOL(__DWC_DMA_ALLOC);
  43021. +EXPORT_SYMBOL(__DWC_DMA_ALLOC_ATOMIC);
  43022. +EXPORT_SYMBOL(__DWC_DMA_FREE);
  43023. +EXPORT_SYMBOL(__DWC_ALLOC);
  43024. +EXPORT_SYMBOL(__DWC_ALLOC_ATOMIC);
  43025. +EXPORT_SYMBOL(__DWC_FREE);
  43026. +
  43027. +#ifdef DWC_CRYPTOLIB
  43028. +EXPORT_SYMBOL(DWC_RANDOM_BYTES);
  43029. +EXPORT_SYMBOL(DWC_AES_CBC);
  43030. +EXPORT_SYMBOL(DWC_SHA256);
  43031. +EXPORT_SYMBOL(DWC_HMAC_SHA256);
  43032. +#endif
  43033. +
  43034. +EXPORT_SYMBOL(DWC_CPU_TO_LE32);
  43035. +EXPORT_SYMBOL(DWC_CPU_TO_BE32);
  43036. +EXPORT_SYMBOL(DWC_LE32_TO_CPU);
  43037. +EXPORT_SYMBOL(DWC_BE32_TO_CPU);
  43038. +EXPORT_SYMBOL(DWC_CPU_TO_LE16);
  43039. +EXPORT_SYMBOL(DWC_CPU_TO_BE16);
  43040. +EXPORT_SYMBOL(DWC_LE16_TO_CPU);
  43041. +EXPORT_SYMBOL(DWC_BE16_TO_CPU);
  43042. +EXPORT_SYMBOL(DWC_READ_REG32);
  43043. +EXPORT_SYMBOL(DWC_WRITE_REG32);
  43044. +EXPORT_SYMBOL(DWC_MODIFY_REG32);
  43045. +
  43046. +#if 0
  43047. +EXPORT_SYMBOL(DWC_READ_REG64);
  43048. +EXPORT_SYMBOL(DWC_WRITE_REG64);
  43049. +EXPORT_SYMBOL(DWC_MODIFY_REG64);
  43050. +#endif
  43051. +
  43052. +EXPORT_SYMBOL(DWC_SPINLOCK_ALLOC);
  43053. +EXPORT_SYMBOL(DWC_SPINLOCK_FREE);
  43054. +EXPORT_SYMBOL(DWC_SPINLOCK);
  43055. +EXPORT_SYMBOL(DWC_SPINUNLOCK);
  43056. +EXPORT_SYMBOL(DWC_SPINLOCK_IRQSAVE);
  43057. +EXPORT_SYMBOL(DWC_SPINUNLOCK_IRQRESTORE);
  43058. +EXPORT_SYMBOL(DWC_MUTEX_ALLOC);
  43059. +
  43060. +#if (!defined(DWC_LINUX) || !defined(CONFIG_DEBUG_MUTEXES))
  43061. +EXPORT_SYMBOL(DWC_MUTEX_FREE);
  43062. +#endif
  43063. +
  43064. +EXPORT_SYMBOL(DWC_MUTEX_LOCK);
  43065. +EXPORT_SYMBOL(DWC_MUTEX_TRYLOCK);
  43066. +EXPORT_SYMBOL(DWC_MUTEX_UNLOCK);
  43067. +EXPORT_SYMBOL(DWC_UDELAY);
  43068. +EXPORT_SYMBOL(DWC_MDELAY);
  43069. +EXPORT_SYMBOL(DWC_MSLEEP);
  43070. +EXPORT_SYMBOL(DWC_TIME);
  43071. +EXPORT_SYMBOL(DWC_TIMER_ALLOC);
  43072. +EXPORT_SYMBOL(DWC_TIMER_FREE);
  43073. +EXPORT_SYMBOL(DWC_TIMER_SCHEDULE);
  43074. +EXPORT_SYMBOL(DWC_TIMER_CANCEL);
  43075. +EXPORT_SYMBOL(DWC_WAITQ_ALLOC);
  43076. +EXPORT_SYMBOL(DWC_WAITQ_FREE);
  43077. +EXPORT_SYMBOL(DWC_WAITQ_WAIT);
  43078. +EXPORT_SYMBOL(DWC_WAITQ_WAIT_TIMEOUT);
  43079. +EXPORT_SYMBOL(DWC_WAITQ_TRIGGER);
  43080. +EXPORT_SYMBOL(DWC_WAITQ_ABORT);
  43081. +EXPORT_SYMBOL(DWC_THREAD_RUN);
  43082. +EXPORT_SYMBOL(DWC_THREAD_STOP);
  43083. +EXPORT_SYMBOL(DWC_THREAD_SHOULD_STOP);
  43084. +EXPORT_SYMBOL(DWC_TASK_ALLOC);
  43085. +EXPORT_SYMBOL(DWC_TASK_FREE);
  43086. +EXPORT_SYMBOL(DWC_TASK_SCHEDULE);
  43087. +EXPORT_SYMBOL(DWC_WORKQ_WAIT_WORK_DONE);
  43088. +EXPORT_SYMBOL(DWC_WORKQ_ALLOC);
  43089. +EXPORT_SYMBOL(DWC_WORKQ_FREE);
  43090. +EXPORT_SYMBOL(DWC_WORKQ_SCHEDULE);
  43091. +EXPORT_SYMBOL(DWC_WORKQ_SCHEDULE_DELAYED);
  43092. +EXPORT_SYMBOL(DWC_WORKQ_PENDING);
  43093. +
  43094. +static int dwc_common_port_init_module(void)
  43095. +{
  43096. + int result = 0;
  43097. +
  43098. + printk(KERN_DEBUG "Module dwc_common_port init\n" );
  43099. +
  43100. +#ifdef DWC_DEBUG_MEMORY
  43101. + result = dwc_memory_debug_start(NULL);
  43102. + if (result) {
  43103. + printk(KERN_ERR
  43104. + "dwc_memory_debug_start() failed with error %d\n",
  43105. + result);
  43106. + return result;
  43107. + }
  43108. +#endif
  43109. +
  43110. +#ifdef DWC_NOTIFYLIB
  43111. + result = dwc_alloc_notification_manager(NULL, NULL);
  43112. + if (result) {
  43113. + printk(KERN_ERR
  43114. + "dwc_alloc_notification_manager() failed with error %d\n",
  43115. + result);
  43116. + return result;
  43117. + }
  43118. +#endif
  43119. + return result;
  43120. +}
  43121. +
  43122. +static void dwc_common_port_exit_module(void)
  43123. +{
  43124. + printk(KERN_DEBUG "Module dwc_common_port exit\n" );
  43125. +
  43126. +#ifdef DWC_NOTIFYLIB
  43127. + dwc_free_notification_manager();
  43128. +#endif
  43129. +
  43130. +#ifdef DWC_DEBUG_MEMORY
  43131. + dwc_memory_debug_stop();
  43132. +#endif
  43133. +}
  43134. +
  43135. +module_init(dwc_common_port_init_module);
  43136. +module_exit(dwc_common_port_exit_module);
  43137. +
  43138. +MODULE_DESCRIPTION("DWC Common Library - Portable version");
  43139. +MODULE_AUTHOR("Synopsys Inc.");
  43140. +MODULE_LICENSE ("GPL");
  43141. +
  43142. +#endif /* DWC_LIBMODULE */
  43143. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c linux-3.12.26/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c
  43144. --- linux-3.12.26.orig/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c 1970-01-01 01:00:00.000000000 +0100
  43145. +++ linux-3.12.26/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c 2014-08-06 16:50:14.737964224 +0200
  43146. @@ -0,0 +1,1275 @@
  43147. +#include "dwc_os.h"
  43148. +#include "dwc_list.h"
  43149. +
  43150. +#ifdef DWC_CCLIB
  43151. +# include "dwc_cc.h"
  43152. +#endif
  43153. +
  43154. +#ifdef DWC_CRYPTOLIB
  43155. +# include "dwc_modpow.h"
  43156. +# include "dwc_dh.h"
  43157. +# include "dwc_crypto.h"
  43158. +#endif
  43159. +
  43160. +#ifdef DWC_NOTIFYLIB
  43161. +# include "dwc_notifier.h"
  43162. +#endif
  43163. +
  43164. +/* OS-Level Implementations */
  43165. +
  43166. +/* This is the NetBSD 4.0.1 kernel implementation of the DWC platform library. */
  43167. +
  43168. +
  43169. +/* MISC */
  43170. +
  43171. +void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size)
  43172. +{
  43173. + return memset(dest, byte, size);
  43174. +}
  43175. +
  43176. +void *DWC_MEMCPY(void *dest, void const *src, uint32_t size)
  43177. +{
  43178. + return memcpy(dest, src, size);
  43179. +}
  43180. +
  43181. +void *DWC_MEMMOVE(void *dest, void *src, uint32_t size)
  43182. +{
  43183. + bcopy(src, dest, size);
  43184. + return dest;
  43185. +}
  43186. +
  43187. +int DWC_MEMCMP(void *m1, void *m2, uint32_t size)
  43188. +{
  43189. + return memcmp(m1, m2, size);
  43190. +}
  43191. +
  43192. +int DWC_STRNCMP(void *s1, void *s2, uint32_t size)
  43193. +{
  43194. + return strncmp(s1, s2, size);
  43195. +}
  43196. +
  43197. +int DWC_STRCMP(void *s1, void *s2)
  43198. +{
  43199. + return strcmp(s1, s2);
  43200. +}
  43201. +
  43202. +int DWC_STRLEN(char const *str)
  43203. +{
  43204. + return strlen(str);
  43205. +}
  43206. +
  43207. +char *DWC_STRCPY(char *to, char const *from)
  43208. +{
  43209. + return strcpy(to, from);
  43210. +}
  43211. +
  43212. +char *DWC_STRDUP(char const *str)
  43213. +{
  43214. + int len = DWC_STRLEN(str) + 1;
  43215. + char *new = DWC_ALLOC_ATOMIC(len);
  43216. +
  43217. + if (!new) {
  43218. + return NULL;
  43219. + }
  43220. +
  43221. + DWC_MEMCPY(new, str, len);
  43222. + return new;
  43223. +}
  43224. +
  43225. +int DWC_ATOI(char *str, int32_t *value)
  43226. +{
  43227. + char *end = NULL;
  43228. +
  43229. + /* NetBSD doesn't have 'strtol' in the kernel, but 'strtoul'
  43230. + * should be equivalent on 2's complement machines
  43231. + */
  43232. + *value = strtoul(str, &end, 0);
  43233. + if (*end == '\0') {
  43234. + return 0;
  43235. + }
  43236. +
  43237. + return -1;
  43238. +}
  43239. +
  43240. +int DWC_ATOUI(char *str, uint32_t *value)
  43241. +{
  43242. + char *end = NULL;
  43243. +
  43244. + *value = strtoul(str, &end, 0);
  43245. + if (*end == '\0') {
  43246. + return 0;
  43247. + }
  43248. +
  43249. + return -1;
  43250. +}
  43251. +
  43252. +
  43253. +#ifdef DWC_UTFLIB
  43254. +/* From usbstring.c */
  43255. +
  43256. +int DWC_UTF8_TO_UTF16LE(uint8_t const *s, uint16_t *cp, unsigned len)
  43257. +{
  43258. + int count = 0;
  43259. + u8 c;
  43260. + u16 uchar;
  43261. +
  43262. + /* this insists on correct encodings, though not minimal ones.
  43263. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  43264. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  43265. + */
  43266. + while (len != 0 && (c = (u8) *s++) != 0) {
  43267. + if (unlikely(c & 0x80)) {
  43268. + // 2-byte sequence:
  43269. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  43270. + if ((c & 0xe0) == 0xc0) {
  43271. + uchar = (c & 0x1f) << 6;
  43272. +
  43273. + c = (u8) *s++;
  43274. + if ((c & 0xc0) != 0xc0)
  43275. + goto fail;
  43276. + c &= 0x3f;
  43277. + uchar |= c;
  43278. +
  43279. + // 3-byte sequence (most CJKV characters):
  43280. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  43281. + } else if ((c & 0xf0) == 0xe0) {
  43282. + uchar = (c & 0x0f) << 12;
  43283. +
  43284. + c = (u8) *s++;
  43285. + if ((c & 0xc0) != 0xc0)
  43286. + goto fail;
  43287. + c &= 0x3f;
  43288. + uchar |= c << 6;
  43289. +
  43290. + c = (u8) *s++;
  43291. + if ((c & 0xc0) != 0xc0)
  43292. + goto fail;
  43293. + c &= 0x3f;
  43294. + uchar |= c;
  43295. +
  43296. + /* no bogus surrogates */
  43297. + if (0xd800 <= uchar && uchar <= 0xdfff)
  43298. + goto fail;
  43299. +
  43300. + // 4-byte sequence (surrogate pairs, currently rare):
  43301. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  43302. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  43303. + // (uuuuu = wwww + 1)
  43304. + // FIXME accept the surrogate code points (only)
  43305. + } else
  43306. + goto fail;
  43307. + } else
  43308. + uchar = c;
  43309. + put_unaligned (cpu_to_le16 (uchar), cp++);
  43310. + count++;
  43311. + len--;
  43312. + }
  43313. + return count;
  43314. +fail:
  43315. + return -1;
  43316. +}
  43317. +
  43318. +#endif /* DWC_UTFLIB */
  43319. +
  43320. +
  43321. +/* dwc_debug.h */
  43322. +
  43323. +dwc_bool_t DWC_IN_IRQ(void)
  43324. +{
  43325. +// return in_irq();
  43326. + return 0;
  43327. +}
  43328. +
  43329. +dwc_bool_t DWC_IN_BH(void)
  43330. +{
  43331. +// return in_softirq();
  43332. + return 0;
  43333. +}
  43334. +
  43335. +void DWC_VPRINTF(char *format, va_list args)
  43336. +{
  43337. + vprintf(format, args);
  43338. +}
  43339. +
  43340. +int DWC_VSNPRINTF(char *str, int size, char *format, va_list args)
  43341. +{
  43342. + return vsnprintf(str, size, format, args);
  43343. +}
  43344. +
  43345. +void DWC_PRINTF(char *format, ...)
  43346. +{
  43347. + va_list args;
  43348. +
  43349. + va_start(args, format);
  43350. + DWC_VPRINTF(format, args);
  43351. + va_end(args);
  43352. +}
  43353. +
  43354. +int DWC_SPRINTF(char *buffer, char *format, ...)
  43355. +{
  43356. + int retval;
  43357. + va_list args;
  43358. +
  43359. + va_start(args, format);
  43360. + retval = vsprintf(buffer, format, args);
  43361. + va_end(args);
  43362. + return retval;
  43363. +}
  43364. +
  43365. +int DWC_SNPRINTF(char *buffer, int size, char *format, ...)
  43366. +{
  43367. + int retval;
  43368. + va_list args;
  43369. +
  43370. + va_start(args, format);
  43371. + retval = vsnprintf(buffer, size, format, args);
  43372. + va_end(args);
  43373. + return retval;
  43374. +}
  43375. +
  43376. +void __DWC_WARN(char *format, ...)
  43377. +{
  43378. + va_list args;
  43379. +
  43380. + va_start(args, format);
  43381. + DWC_VPRINTF(format, args);
  43382. + va_end(args);
  43383. +}
  43384. +
  43385. +void __DWC_ERROR(char *format, ...)
  43386. +{
  43387. + va_list args;
  43388. +
  43389. + va_start(args, format);
  43390. + DWC_VPRINTF(format, args);
  43391. + va_end(args);
  43392. +}
  43393. +
  43394. +void DWC_EXCEPTION(char *format, ...)
  43395. +{
  43396. + va_list args;
  43397. +
  43398. + va_start(args, format);
  43399. + DWC_VPRINTF(format, args);
  43400. + va_end(args);
  43401. +// BUG_ON(1); ???
  43402. +}
  43403. +
  43404. +#ifdef DEBUG
  43405. +void __DWC_DEBUG(char *format, ...)
  43406. +{
  43407. + va_list args;
  43408. +
  43409. + va_start(args, format);
  43410. + DWC_VPRINTF(format, args);
  43411. + va_end(args);
  43412. +}
  43413. +#endif
  43414. +
  43415. +
  43416. +/* dwc_mem.h */
  43417. +
  43418. +#if 0
  43419. +dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size,
  43420. + uint32_t align,
  43421. + uint32_t alloc)
  43422. +{
  43423. + struct dma_pool *pool = dma_pool_create("Pool", NULL,
  43424. + size, align, alloc);
  43425. + return (dwc_pool_t *)pool;
  43426. +}
  43427. +
  43428. +void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool)
  43429. +{
  43430. + dma_pool_destroy((struct dma_pool *)pool);
  43431. +}
  43432. +
  43433. +void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  43434. +{
  43435. +// return dma_pool_alloc((struct dma_pool *)pool, GFP_KERNEL, dma_addr);
  43436. + return dma_pool_alloc((struct dma_pool *)pool, M_WAITOK, dma_addr);
  43437. +}
  43438. +
  43439. +void *DWC_DMA_POOL_ZALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  43440. +{
  43441. + void *vaddr = DWC_DMA_POOL_ALLOC(pool, dma_addr);
  43442. + memset(..);
  43443. +}
  43444. +
  43445. +void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr)
  43446. +{
  43447. + dma_pool_free(pool, vaddr, daddr);
  43448. +}
  43449. +#endif
  43450. +
  43451. +void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  43452. +{
  43453. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  43454. + int error;
  43455. +
  43456. + error = bus_dmamem_alloc(dma->dma_tag, size, 1, size, dma->segs,
  43457. + sizeof(dma->segs) / sizeof(dma->segs[0]),
  43458. + &dma->nsegs, BUS_DMA_NOWAIT);
  43459. + if (error) {
  43460. + printf("%s: bus_dmamem_alloc(%ju) failed: %d\n", __func__,
  43461. + (uintmax_t)size, error);
  43462. + goto fail_0;
  43463. + }
  43464. +
  43465. + error = bus_dmamem_map(dma->dma_tag, dma->segs, dma->nsegs, size,
  43466. + (caddr_t *)&dma->dma_vaddr,
  43467. + BUS_DMA_NOWAIT | BUS_DMA_COHERENT);
  43468. + if (error) {
  43469. + printf("%s: bus_dmamem_map failed: %d\n", __func__, error);
  43470. + goto fail_1;
  43471. + }
  43472. +
  43473. + error = bus_dmamap_create(dma->dma_tag, size, 1, size, 0,
  43474. + BUS_DMA_NOWAIT, &dma->dma_map);
  43475. + if (error) {
  43476. + printf("%s: bus_dmamap_create failed: %d\n", __func__, error);
  43477. + goto fail_2;
  43478. + }
  43479. +
  43480. + error = bus_dmamap_load(dma->dma_tag, dma->dma_map, dma->dma_vaddr,
  43481. + size, NULL, BUS_DMA_NOWAIT);
  43482. + if (error) {
  43483. + printf("%s: bus_dmamap_load failed: %d\n", __func__, error);
  43484. + goto fail_3;
  43485. + }
  43486. +
  43487. + dma->dma_paddr = (bus_addr_t)dma->segs[0].ds_addr;
  43488. + *dma_addr = dma->dma_paddr;
  43489. + return dma->dma_vaddr;
  43490. +
  43491. +fail_3:
  43492. + bus_dmamap_destroy(dma->dma_tag, dma->dma_map);
  43493. +fail_2:
  43494. + bus_dmamem_unmap(dma->dma_tag, dma->dma_vaddr, size);
  43495. +fail_1:
  43496. + bus_dmamem_free(dma->dma_tag, dma->segs, dma->nsegs);
  43497. +fail_0:
  43498. + dma->dma_map = NULL;
  43499. + dma->dma_vaddr = NULL;
  43500. + dma->nsegs = 0;
  43501. +
  43502. + return NULL;
  43503. +}
  43504. +
  43505. +void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr)
  43506. +{
  43507. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  43508. +
  43509. + if (dma->dma_map != NULL) {
  43510. + bus_dmamap_sync(dma->dma_tag, dma->dma_map, 0, size,
  43511. + BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
  43512. + bus_dmamap_unload(dma->dma_tag, dma->dma_map);
  43513. + bus_dmamap_destroy(dma->dma_tag, dma->dma_map);
  43514. + bus_dmamem_unmap(dma->dma_tag, dma->dma_vaddr, size);
  43515. + bus_dmamem_free(dma->dma_tag, dma->segs, dma->nsegs);
  43516. + dma->dma_paddr = 0;
  43517. + dma->dma_map = NULL;
  43518. + dma->dma_vaddr = NULL;
  43519. + dma->nsegs = 0;
  43520. + }
  43521. +}
  43522. +
  43523. +void *__DWC_ALLOC(void *mem_ctx, uint32_t size)
  43524. +{
  43525. + return malloc(size, M_DEVBUF, M_WAITOK | M_ZERO);
  43526. +}
  43527. +
  43528. +void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size)
  43529. +{
  43530. + return malloc(size, M_DEVBUF, M_NOWAIT | M_ZERO);
  43531. +}
  43532. +
  43533. +void __DWC_FREE(void *mem_ctx, void *addr)
  43534. +{
  43535. + free(addr, M_DEVBUF);
  43536. +}
  43537. +
  43538. +
  43539. +#ifdef DWC_CRYPTOLIB
  43540. +/* dwc_crypto.h */
  43541. +
  43542. +void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length)
  43543. +{
  43544. + get_random_bytes(buffer, length);
  43545. +}
  43546. +
  43547. +int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out)
  43548. +{
  43549. + struct crypto_blkcipher *tfm;
  43550. + struct blkcipher_desc desc;
  43551. + struct scatterlist sgd;
  43552. + struct scatterlist sgs;
  43553. +
  43554. + tfm = crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC);
  43555. + if (tfm == NULL) {
  43556. + printk("failed to load transform for aes CBC\n");
  43557. + return -1;
  43558. + }
  43559. +
  43560. + crypto_blkcipher_setkey(tfm, key, keylen);
  43561. + crypto_blkcipher_set_iv(tfm, iv, 16);
  43562. +
  43563. + sg_init_one(&sgd, out, messagelen);
  43564. + sg_init_one(&sgs, message, messagelen);
  43565. +
  43566. + desc.tfm = tfm;
  43567. + desc.flags = 0;
  43568. +
  43569. + if (crypto_blkcipher_encrypt(&desc, &sgd, &sgs, messagelen)) {
  43570. + crypto_free_blkcipher(tfm);
  43571. + DWC_ERROR("AES CBC encryption failed");
  43572. + return -1;
  43573. + }
  43574. +
  43575. + crypto_free_blkcipher(tfm);
  43576. + return 0;
  43577. +}
  43578. +
  43579. +int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out)
  43580. +{
  43581. + struct crypto_hash *tfm;
  43582. + struct hash_desc desc;
  43583. + struct scatterlist sg;
  43584. +
  43585. + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
  43586. + if (IS_ERR(tfm)) {
  43587. + DWC_ERROR("Failed to load transform for sha256: %ld", PTR_ERR(tfm));
  43588. + return 0;
  43589. + }
  43590. + desc.tfm = tfm;
  43591. + desc.flags = 0;
  43592. +
  43593. + sg_init_one(&sg, message, len);
  43594. + crypto_hash_digest(&desc, &sg, len, out);
  43595. + crypto_free_hash(tfm);
  43596. +
  43597. + return 1;
  43598. +}
  43599. +
  43600. +int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen,
  43601. + uint8_t *key, uint32_t keylen, uint8_t *out)
  43602. +{
  43603. + struct crypto_hash *tfm;
  43604. + struct hash_desc desc;
  43605. + struct scatterlist sg;
  43606. +
  43607. + tfm = crypto_alloc_hash("hmac(sha256)", 0, CRYPTO_ALG_ASYNC);
  43608. + if (IS_ERR(tfm)) {
  43609. + DWC_ERROR("Failed to load transform for hmac(sha256): %ld", PTR_ERR(tfm));
  43610. + return 0;
  43611. + }
  43612. + desc.tfm = tfm;
  43613. + desc.flags = 0;
  43614. +
  43615. + sg_init_one(&sg, message, messagelen);
  43616. + crypto_hash_setkey(tfm, key, keylen);
  43617. + crypto_hash_digest(&desc, &sg, messagelen, out);
  43618. + crypto_free_hash(tfm);
  43619. +
  43620. + return 1;
  43621. +}
  43622. +
  43623. +#endif /* DWC_CRYPTOLIB */
  43624. +
  43625. +
  43626. +/* Byte Ordering Conversions */
  43627. +
  43628. +uint32_t DWC_CPU_TO_LE32(uint32_t *p)
  43629. +{
  43630. +#ifdef __LITTLE_ENDIAN
  43631. + return *p;
  43632. +#else
  43633. + uint8_t *u_p = (uint8_t *)p;
  43634. +
  43635. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  43636. +#endif
  43637. +}
  43638. +
  43639. +uint32_t DWC_CPU_TO_BE32(uint32_t *p)
  43640. +{
  43641. +#ifdef __BIG_ENDIAN
  43642. + return *p;
  43643. +#else
  43644. + uint8_t *u_p = (uint8_t *)p;
  43645. +
  43646. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  43647. +#endif
  43648. +}
  43649. +
  43650. +uint32_t DWC_LE32_TO_CPU(uint32_t *p)
  43651. +{
  43652. +#ifdef __LITTLE_ENDIAN
  43653. + return *p;
  43654. +#else
  43655. + uint8_t *u_p = (uint8_t *)p;
  43656. +
  43657. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  43658. +#endif
  43659. +}
  43660. +
  43661. +uint32_t DWC_BE32_TO_CPU(uint32_t *p)
  43662. +{
  43663. +#ifdef __BIG_ENDIAN
  43664. + return *p;
  43665. +#else
  43666. + uint8_t *u_p = (uint8_t *)p;
  43667. +
  43668. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  43669. +#endif
  43670. +}
  43671. +
  43672. +uint16_t DWC_CPU_TO_LE16(uint16_t *p)
  43673. +{
  43674. +#ifdef __LITTLE_ENDIAN
  43675. + return *p;
  43676. +#else
  43677. + uint8_t *u_p = (uint8_t *)p;
  43678. + return (u_p[1] | (u_p[0] << 8));
  43679. +#endif
  43680. +}
  43681. +
  43682. +uint16_t DWC_CPU_TO_BE16(uint16_t *p)
  43683. +{
  43684. +#ifdef __BIG_ENDIAN
  43685. + return *p;
  43686. +#else
  43687. + uint8_t *u_p = (uint8_t *)p;
  43688. + return (u_p[1] | (u_p[0] << 8));
  43689. +#endif
  43690. +}
  43691. +
  43692. +uint16_t DWC_LE16_TO_CPU(uint16_t *p)
  43693. +{
  43694. +#ifdef __LITTLE_ENDIAN
  43695. + return *p;
  43696. +#else
  43697. + uint8_t *u_p = (uint8_t *)p;
  43698. + return (u_p[1] | (u_p[0] << 8));
  43699. +#endif
  43700. +}
  43701. +
  43702. +uint16_t DWC_BE16_TO_CPU(uint16_t *p)
  43703. +{
  43704. +#ifdef __BIG_ENDIAN
  43705. + return *p;
  43706. +#else
  43707. + uint8_t *u_p = (uint8_t *)p;
  43708. + return (u_p[1] | (u_p[0] << 8));
  43709. +#endif
  43710. +}
  43711. +
  43712. +
  43713. +/* Registers */
  43714. +
  43715. +uint32_t DWC_READ_REG32(void *io_ctx, uint32_t volatile *reg)
  43716. +{
  43717. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  43718. + bus_size_t ior = (bus_size_t)reg;
  43719. +
  43720. + return bus_space_read_4(io->iot, io->ioh, ior);
  43721. +}
  43722. +
  43723. +#if 0
  43724. +uint64_t DWC_READ_REG64(void *io_ctx, uint64_t volatile *reg)
  43725. +{
  43726. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  43727. + bus_size_t ior = (bus_size_t)reg;
  43728. +
  43729. + return bus_space_read_8(io->iot, io->ioh, ior);
  43730. +}
  43731. +#endif
  43732. +
  43733. +void DWC_WRITE_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t value)
  43734. +{
  43735. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  43736. + bus_size_t ior = (bus_size_t)reg;
  43737. +
  43738. + bus_space_write_4(io->iot, io->ioh, ior, value);
  43739. +}
  43740. +
  43741. +#if 0
  43742. +void DWC_WRITE_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t value)
  43743. +{
  43744. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  43745. + bus_size_t ior = (bus_size_t)reg;
  43746. +
  43747. + bus_space_write_8(io->iot, io->ioh, ior, value);
  43748. +}
  43749. +#endif
  43750. +
  43751. +void DWC_MODIFY_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t clear_mask,
  43752. + uint32_t set_mask)
  43753. +{
  43754. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  43755. + bus_size_t ior = (bus_size_t)reg;
  43756. +
  43757. + bus_space_write_4(io->iot, io->ioh, ior,
  43758. + (bus_space_read_4(io->iot, io->ioh, ior) &
  43759. + ~clear_mask) | set_mask);
  43760. +}
  43761. +
  43762. +#if 0
  43763. +void DWC_MODIFY_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t clear_mask,
  43764. + uint64_t set_mask)
  43765. +{
  43766. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  43767. + bus_size_t ior = (bus_size_t)reg;
  43768. +
  43769. + bus_space_write_8(io->iot, io->ioh, ior,
  43770. + (bus_space_read_8(io->iot, io->ioh, ior) &
  43771. + ~clear_mask) | set_mask);
  43772. +}
  43773. +#endif
  43774. +
  43775. +
  43776. +/* Locking */
  43777. +
  43778. +dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void)
  43779. +{
  43780. + struct simplelock *sl = DWC_ALLOC(sizeof(*sl));
  43781. +
  43782. + if (!sl) {
  43783. + DWC_ERROR("Cannot allocate memory for spinlock");
  43784. + return NULL;
  43785. + }
  43786. +
  43787. + simple_lock_init(sl);
  43788. + return (dwc_spinlock_t *)sl;
  43789. +}
  43790. +
  43791. +void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock)
  43792. +{
  43793. + struct simplelock *sl = (struct simplelock *)lock;
  43794. +
  43795. + DWC_FREE(sl);
  43796. +}
  43797. +
  43798. +void DWC_SPINLOCK(dwc_spinlock_t *lock)
  43799. +{
  43800. + simple_lock((struct simplelock *)lock);
  43801. +}
  43802. +
  43803. +void DWC_SPINUNLOCK(dwc_spinlock_t *lock)
  43804. +{
  43805. + simple_unlock((struct simplelock *)lock);
  43806. +}
  43807. +
  43808. +void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags)
  43809. +{
  43810. + simple_lock((struct simplelock *)lock);
  43811. + *flags = splbio();
  43812. +}
  43813. +
  43814. +void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags)
  43815. +{
  43816. + splx(flags);
  43817. + simple_unlock((struct simplelock *)lock);
  43818. +}
  43819. +
  43820. +dwc_mutex_t *DWC_MUTEX_ALLOC(void)
  43821. +{
  43822. + dwc_mutex_t *mutex = DWC_ALLOC(sizeof(struct lock));
  43823. +
  43824. + if (!mutex) {
  43825. + DWC_ERROR("Cannot allocate memory for mutex");
  43826. + return NULL;
  43827. + }
  43828. +
  43829. + lockinit((struct lock *)mutex, 0, "dw3mtx", 0, 0);
  43830. + return mutex;
  43831. +}
  43832. +
  43833. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  43834. +#else
  43835. +void DWC_MUTEX_FREE(dwc_mutex_t *mutex)
  43836. +{
  43837. + DWC_FREE(mutex);
  43838. +}
  43839. +#endif
  43840. +
  43841. +void DWC_MUTEX_LOCK(dwc_mutex_t *mutex)
  43842. +{
  43843. + lockmgr((struct lock *)mutex, LK_EXCLUSIVE, NULL);
  43844. +}
  43845. +
  43846. +int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex)
  43847. +{
  43848. + int status;
  43849. +
  43850. + status = lockmgr((struct lock *)mutex, LK_EXCLUSIVE | LK_NOWAIT, NULL);
  43851. + return status == 0;
  43852. +}
  43853. +
  43854. +void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex)
  43855. +{
  43856. + lockmgr((struct lock *)mutex, LK_RELEASE, NULL);
  43857. +}
  43858. +
  43859. +
  43860. +/* Timing */
  43861. +
  43862. +void DWC_UDELAY(uint32_t usecs)
  43863. +{
  43864. + DELAY(usecs);
  43865. +}
  43866. +
  43867. +void DWC_MDELAY(uint32_t msecs)
  43868. +{
  43869. + do {
  43870. + DELAY(1000);
  43871. + } while (--msecs);
  43872. +}
  43873. +
  43874. +void DWC_MSLEEP(uint32_t msecs)
  43875. +{
  43876. + struct timeval tv;
  43877. +
  43878. + tv.tv_sec = msecs / 1000;
  43879. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  43880. + tsleep(&tv, 0, "dw3slp", tvtohz(&tv));
  43881. +}
  43882. +
  43883. +uint32_t DWC_TIME(void)
  43884. +{
  43885. + struct timeval tv;
  43886. +
  43887. + microuptime(&tv); // or getmicrouptime? (less precise, but faster)
  43888. + return tv.tv_sec * 1000 + tv.tv_usec / 1000;
  43889. +}
  43890. +
  43891. +
  43892. +/* Timers */
  43893. +
  43894. +struct dwc_timer {
  43895. + struct callout t;
  43896. + char *name;
  43897. + dwc_spinlock_t *lock;
  43898. + dwc_timer_callback_t cb;
  43899. + void *data;
  43900. +};
  43901. +
  43902. +dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data)
  43903. +{
  43904. + dwc_timer_t *t = DWC_ALLOC(sizeof(*t));
  43905. +
  43906. + if (!t) {
  43907. + DWC_ERROR("Cannot allocate memory for timer");
  43908. + return NULL;
  43909. + }
  43910. +
  43911. + callout_init(&t->t);
  43912. +
  43913. + t->name = DWC_STRDUP(name);
  43914. + if (!t->name) {
  43915. + DWC_ERROR("Cannot allocate memory for timer->name");
  43916. + goto no_name;
  43917. + }
  43918. +
  43919. + t->lock = DWC_SPINLOCK_ALLOC();
  43920. + if (!t->lock) {
  43921. + DWC_ERROR("Cannot allocate memory for timer->lock");
  43922. + goto no_lock;
  43923. + }
  43924. +
  43925. + t->cb = cb;
  43926. + t->data = data;
  43927. +
  43928. + return t;
  43929. +
  43930. + no_lock:
  43931. + DWC_FREE(t->name);
  43932. + no_name:
  43933. + DWC_FREE(t);
  43934. +
  43935. + return NULL;
  43936. +}
  43937. +
  43938. +void DWC_TIMER_FREE(dwc_timer_t *timer)
  43939. +{
  43940. + callout_stop(&timer->t);
  43941. + DWC_SPINLOCK_FREE(timer->lock);
  43942. + DWC_FREE(timer->name);
  43943. + DWC_FREE(timer);
  43944. +}
  43945. +
  43946. +void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time)
  43947. +{
  43948. + struct timeval tv;
  43949. +
  43950. + tv.tv_sec = time / 1000;
  43951. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  43952. + callout_reset(&timer->t, tvtohz(&tv), timer->cb, timer->data);
  43953. +}
  43954. +
  43955. +void DWC_TIMER_CANCEL(dwc_timer_t *timer)
  43956. +{
  43957. + callout_stop(&timer->t);
  43958. +}
  43959. +
  43960. +
  43961. +/* Wait Queues */
  43962. +
  43963. +struct dwc_waitq {
  43964. + struct simplelock lock;
  43965. + int abort;
  43966. +};
  43967. +
  43968. +dwc_waitq_t *DWC_WAITQ_ALLOC(void)
  43969. +{
  43970. + dwc_waitq_t *wq = DWC_ALLOC(sizeof(*wq));
  43971. +
  43972. + if (!wq) {
  43973. + DWC_ERROR("Cannot allocate memory for waitqueue");
  43974. + return NULL;
  43975. + }
  43976. +
  43977. + simple_lock_init(&wq->lock);
  43978. + wq->abort = 0;
  43979. +
  43980. + return wq;
  43981. +}
  43982. +
  43983. +void DWC_WAITQ_FREE(dwc_waitq_t *wq)
  43984. +{
  43985. + DWC_FREE(wq);
  43986. +}
  43987. +
  43988. +int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data)
  43989. +{
  43990. + int ipl;
  43991. + int result = 0;
  43992. +
  43993. + simple_lock(&wq->lock);
  43994. + ipl = splbio();
  43995. +
  43996. + /* Skip the sleep if already aborted or triggered */
  43997. + if (!wq->abort && !cond(data)) {
  43998. + splx(ipl);
  43999. + result = ltsleep(wq, PCATCH, "dw3wat", 0, &wq->lock); // infinite timeout
  44000. + ipl = splbio();
  44001. + }
  44002. +
  44003. + if (result == 0) { // awoken
  44004. + if (wq->abort) {
  44005. + wq->abort = 0;
  44006. + result = -DWC_E_ABORT;
  44007. + } else {
  44008. + result = 0;
  44009. + }
  44010. +
  44011. + splx(ipl);
  44012. + simple_unlock(&wq->lock);
  44013. + } else {
  44014. + wq->abort = 0;
  44015. + splx(ipl);
  44016. + simple_unlock(&wq->lock);
  44017. +
  44018. + if (result == ERESTART) { // signaled - restart
  44019. + result = -DWC_E_RESTART;
  44020. + } else { // signaled - must be EINTR
  44021. + result = -DWC_E_ABORT;
  44022. + }
  44023. + }
  44024. +
  44025. + return result;
  44026. +}
  44027. +
  44028. +int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  44029. + void *data, int32_t msecs)
  44030. +{
  44031. + struct timeval tv, tv1, tv2;
  44032. + int ipl;
  44033. + int result = 0;
  44034. +
  44035. + tv.tv_sec = msecs / 1000;
  44036. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  44037. +
  44038. + simple_lock(&wq->lock);
  44039. + ipl = splbio();
  44040. +
  44041. + /* Skip the sleep if already aborted or triggered */
  44042. + if (!wq->abort && !cond(data)) {
  44043. + splx(ipl);
  44044. + getmicrouptime(&tv1);
  44045. + result = ltsleep(wq, PCATCH, "dw3wto", tvtohz(&tv), &wq->lock);
  44046. + getmicrouptime(&tv2);
  44047. + ipl = splbio();
  44048. + }
  44049. +
  44050. + if (result == 0) { // awoken
  44051. + if (wq->abort) {
  44052. + wq->abort = 0;
  44053. + splx(ipl);
  44054. + simple_unlock(&wq->lock);
  44055. + result = -DWC_E_ABORT;
  44056. + } else {
  44057. + splx(ipl);
  44058. + simple_unlock(&wq->lock);
  44059. +
  44060. + tv2.tv_usec -= tv1.tv_usec;
  44061. + if (tv2.tv_usec < 0) {
  44062. + tv2.tv_usec += 1000000;
  44063. + tv2.tv_sec--;
  44064. + }
  44065. +
  44066. + tv2.tv_sec -= tv1.tv_sec;
  44067. + result = tv2.tv_sec * 1000 + tv2.tv_usec / 1000;
  44068. + result = msecs - result;
  44069. + if (result <= 0)
  44070. + result = 1;
  44071. + }
  44072. + } else {
  44073. + wq->abort = 0;
  44074. + splx(ipl);
  44075. + simple_unlock(&wq->lock);
  44076. +
  44077. + if (result == ERESTART) { // signaled - restart
  44078. + result = -DWC_E_RESTART;
  44079. +
  44080. + } else if (result == EINTR) { // signaled - interrupt
  44081. + result = -DWC_E_ABORT;
  44082. +
  44083. + } else { // timed out
  44084. + result = -DWC_E_TIMEOUT;
  44085. + }
  44086. + }
  44087. +
  44088. + return result;
  44089. +}
  44090. +
  44091. +void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq)
  44092. +{
  44093. + wakeup(wq);
  44094. +}
  44095. +
  44096. +void DWC_WAITQ_ABORT(dwc_waitq_t *wq)
  44097. +{
  44098. + int ipl;
  44099. +
  44100. + simple_lock(&wq->lock);
  44101. + ipl = splbio();
  44102. + wq->abort = 1;
  44103. + wakeup(wq);
  44104. + splx(ipl);
  44105. + simple_unlock(&wq->lock);
  44106. +}
  44107. +
  44108. +
  44109. +/* Threading */
  44110. +
  44111. +struct dwc_thread {
  44112. + struct proc *proc;
  44113. + int abort;
  44114. +};
  44115. +
  44116. +dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data)
  44117. +{
  44118. + int retval;
  44119. + dwc_thread_t *thread = DWC_ALLOC(sizeof(*thread));
  44120. +
  44121. + if (!thread) {
  44122. + return NULL;
  44123. + }
  44124. +
  44125. + thread->abort = 0;
  44126. + retval = kthread_create1((void (*)(void *))func, data, &thread->proc,
  44127. + "%s", name);
  44128. + if (retval) {
  44129. + DWC_FREE(thread);
  44130. + return NULL;
  44131. + }
  44132. +
  44133. + return thread;
  44134. +}
  44135. +
  44136. +int DWC_THREAD_STOP(dwc_thread_t *thread)
  44137. +{
  44138. + int retval;
  44139. +
  44140. + thread->abort = 1;
  44141. + retval = tsleep(&thread->abort, 0, "dw3stp", 60 * hz);
  44142. +
  44143. + if (retval == 0) {
  44144. + /* DWC_THREAD_EXIT() will free the thread struct */
  44145. + return 0;
  44146. + }
  44147. +
  44148. + /* NOTE: We leak the thread struct if thread doesn't die */
  44149. +
  44150. + if (retval == EWOULDBLOCK) {
  44151. + return -DWC_E_TIMEOUT;
  44152. + }
  44153. +
  44154. + return -DWC_E_UNKNOWN;
  44155. +}
  44156. +
  44157. +dwc_bool_t DWC_THREAD_SHOULD_STOP(dwc_thread_t *thread)
  44158. +{
  44159. + return thread->abort;
  44160. +}
  44161. +
  44162. +void DWC_THREAD_EXIT(dwc_thread_t *thread)
  44163. +{
  44164. + wakeup(&thread->abort);
  44165. + DWC_FREE(thread);
  44166. + kthread_exit(0);
  44167. +}
  44168. +
  44169. +/* tasklets
  44170. + - Runs in interrupt context (cannot sleep)
  44171. + - Each tasklet runs on a single CPU
  44172. + - Different tasklets can be running simultaneously on different CPUs
  44173. + [ On NetBSD there is no corresponding mechanism, drivers don't have bottom-
  44174. + halves. So we just call the callback directly from DWC_TASK_SCHEDULE() ]
  44175. + */
  44176. +struct dwc_tasklet {
  44177. + dwc_tasklet_callback_t cb;
  44178. + void *data;
  44179. +};
  44180. +
  44181. +static void tasklet_callback(void *data)
  44182. +{
  44183. + dwc_tasklet_t *task = (dwc_tasklet_t *)data;
  44184. +
  44185. + task->cb(task->data);
  44186. +}
  44187. +
  44188. +dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data)
  44189. +{
  44190. + dwc_tasklet_t *task = DWC_ALLOC(sizeof(*task));
  44191. +
  44192. + if (task) {
  44193. + task->cb = cb;
  44194. + task->data = data;
  44195. + } else {
  44196. + DWC_ERROR("Cannot allocate memory for tasklet");
  44197. + }
  44198. +
  44199. + return task;
  44200. +}
  44201. +
  44202. +void DWC_TASK_FREE(dwc_tasklet_t *task)
  44203. +{
  44204. + DWC_FREE(task);
  44205. +}
  44206. +
  44207. +void DWC_TASK_SCHEDULE(dwc_tasklet_t *task)
  44208. +{
  44209. + tasklet_callback(task);
  44210. +}
  44211. +
  44212. +
  44213. +/* workqueues
  44214. + - Runs in process context (can sleep)
  44215. + */
  44216. +typedef struct work_container {
  44217. + dwc_work_callback_t cb;
  44218. + void *data;
  44219. + dwc_workq_t *wq;
  44220. + char *name;
  44221. + int hz;
  44222. + struct work task;
  44223. +} work_container_t;
  44224. +
  44225. +struct dwc_workq {
  44226. + struct workqueue *taskq;
  44227. + dwc_spinlock_t *lock;
  44228. + dwc_waitq_t *waitq;
  44229. + int pending;
  44230. + struct work_container *container;
  44231. +};
  44232. +
  44233. +static void do_work(struct work *task, void *data)
  44234. +{
  44235. + dwc_workq_t *wq = (dwc_workq_t *)data;
  44236. + work_container_t *container = wq->container;
  44237. + dwc_irqflags_t flags;
  44238. +
  44239. + if (container->hz) {
  44240. + tsleep(container, 0, "dw3wrk", container->hz);
  44241. + }
  44242. +
  44243. + container->cb(container->data);
  44244. + DWC_DEBUG("Work done: %s, container=%p", container->name, container);
  44245. +
  44246. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  44247. + if (container->name)
  44248. + DWC_FREE(container->name);
  44249. + DWC_FREE(container);
  44250. + wq->pending--;
  44251. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  44252. + DWC_WAITQ_TRIGGER(wq->waitq);
  44253. +}
  44254. +
  44255. +static int work_done(void *data)
  44256. +{
  44257. + dwc_workq_t *workq = (dwc_workq_t *)data;
  44258. +
  44259. + return workq->pending == 0;
  44260. +}
  44261. +
  44262. +int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout)
  44263. +{
  44264. + return DWC_WAITQ_WAIT_TIMEOUT(workq->waitq, work_done, workq, timeout);
  44265. +}
  44266. +
  44267. +dwc_workq_t *DWC_WORKQ_ALLOC(char *name)
  44268. +{
  44269. + int result;
  44270. + dwc_workq_t *wq = DWC_ALLOC(sizeof(*wq));
  44271. +
  44272. + if (!wq) {
  44273. + DWC_ERROR("Cannot allocate memory for workqueue");
  44274. + return NULL;
  44275. + }
  44276. +
  44277. + result = workqueue_create(&wq->taskq, name, do_work, wq, 0 /*PWAIT*/,
  44278. + IPL_BIO, 0);
  44279. + if (result) {
  44280. + DWC_ERROR("Cannot create workqueue");
  44281. + goto no_taskq;
  44282. + }
  44283. +
  44284. + wq->pending = 0;
  44285. +
  44286. + wq->lock = DWC_SPINLOCK_ALLOC();
  44287. + if (!wq->lock) {
  44288. + DWC_ERROR("Cannot allocate memory for spinlock");
  44289. + goto no_lock;
  44290. + }
  44291. +
  44292. + wq->waitq = DWC_WAITQ_ALLOC();
  44293. + if (!wq->waitq) {
  44294. + DWC_ERROR("Cannot allocate memory for waitqueue");
  44295. + goto no_waitq;
  44296. + }
  44297. +
  44298. + return wq;
  44299. +
  44300. + no_waitq:
  44301. + DWC_SPINLOCK_FREE(wq->lock);
  44302. + no_lock:
  44303. + workqueue_destroy(wq->taskq);
  44304. + no_taskq:
  44305. + DWC_FREE(wq);
  44306. +
  44307. + return NULL;
  44308. +}
  44309. +
  44310. +void DWC_WORKQ_FREE(dwc_workq_t *wq)
  44311. +{
  44312. +#ifdef DEBUG
  44313. + dwc_irqflags_t flags;
  44314. +
  44315. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  44316. +
  44317. + if (wq->pending != 0) {
  44318. + struct work_container *container = wq->container;
  44319. +
  44320. + DWC_ERROR("Destroying work queue with pending work");
  44321. +
  44322. + if (container && container->name) {
  44323. + DWC_ERROR("Work %s still pending", container->name);
  44324. + }
  44325. + }
  44326. +
  44327. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  44328. +#endif
  44329. + DWC_WAITQ_FREE(wq->waitq);
  44330. + DWC_SPINLOCK_FREE(wq->lock);
  44331. + workqueue_destroy(wq->taskq);
  44332. + DWC_FREE(wq);
  44333. +}
  44334. +
  44335. +void DWC_WORKQ_SCHEDULE(dwc_workq_t *wq, dwc_work_callback_t cb, void *data,
  44336. + char *format, ...)
  44337. +{
  44338. + dwc_irqflags_t flags;
  44339. + work_container_t *container;
  44340. + static char name[128];
  44341. + va_list args;
  44342. +
  44343. + va_start(args, format);
  44344. + DWC_VSNPRINTF(name, 128, format, args);
  44345. + va_end(args);
  44346. +
  44347. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  44348. + wq->pending++;
  44349. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  44350. + DWC_WAITQ_TRIGGER(wq->waitq);
  44351. +
  44352. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  44353. + if (!container) {
  44354. + DWC_ERROR("Cannot allocate memory for container");
  44355. + return;
  44356. + }
  44357. +
  44358. + container->name = DWC_STRDUP(name);
  44359. + if (!container->name) {
  44360. + DWC_ERROR("Cannot allocate memory for container->name");
  44361. + DWC_FREE(container);
  44362. + return;
  44363. + }
  44364. +
  44365. + container->cb = cb;
  44366. + container->data = data;
  44367. + container->wq = wq;
  44368. + container->hz = 0;
  44369. + wq->container = container;
  44370. +
  44371. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  44372. + workqueue_enqueue(wq->taskq, &container->task);
  44373. +}
  44374. +
  44375. +void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *wq, dwc_work_callback_t cb,
  44376. + void *data, uint32_t time, char *format, ...)
  44377. +{
  44378. + dwc_irqflags_t flags;
  44379. + work_container_t *container;
  44380. + static char name[128];
  44381. + struct timeval tv;
  44382. + va_list args;
  44383. +
  44384. + va_start(args, format);
  44385. + DWC_VSNPRINTF(name, 128, format, args);
  44386. + va_end(args);
  44387. +
  44388. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  44389. + wq->pending++;
  44390. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  44391. + DWC_WAITQ_TRIGGER(wq->waitq);
  44392. +
  44393. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  44394. + if (!container) {
  44395. + DWC_ERROR("Cannot allocate memory for container");
  44396. + return;
  44397. + }
  44398. +
  44399. + container->name = DWC_STRDUP(name);
  44400. + if (!container->name) {
  44401. + DWC_ERROR("Cannot allocate memory for container->name");
  44402. + DWC_FREE(container);
  44403. + return;
  44404. + }
  44405. +
  44406. + container->cb = cb;
  44407. + container->data = data;
  44408. + container->wq = wq;
  44409. + tv.tv_sec = time / 1000;
  44410. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  44411. + container->hz = tvtohz(&tv);
  44412. + wq->container = container;
  44413. +
  44414. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  44415. + workqueue_enqueue(wq->taskq, &container->task);
  44416. +}
  44417. +
  44418. +int DWC_WORKQ_PENDING(dwc_workq_t *wq)
  44419. +{
  44420. + return wq->pending;
  44421. +}
  44422. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_common_port/dwc_crypto.c linux-3.12.26/drivers/usb/host/dwc_common_port/dwc_crypto.c
  44423. --- linux-3.12.26.orig/drivers/usb/host/dwc_common_port/dwc_crypto.c 1970-01-01 01:00:00.000000000 +0100
  44424. +++ linux-3.12.26/drivers/usb/host/dwc_common_port/dwc_crypto.c 2014-08-06 16:50:14.765964443 +0200
  44425. @@ -0,0 +1,308 @@
  44426. +/* =========================================================================
  44427. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_crypto.c $
  44428. + * $Revision: #5 $
  44429. + * $Date: 2010/09/28 $
  44430. + * $Change: 1596182 $
  44431. + *
  44432. + * Synopsys Portability Library Software and documentation
  44433. + * (hereinafter, "Software") is an Unsupported proprietary work of
  44434. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  44435. + * between Synopsys and you.
  44436. + *
  44437. + * The Software IS NOT an item of Licensed Software or Licensed Product
  44438. + * under any End User Software License Agreement or Agreement for
  44439. + * Licensed Product with Synopsys or any supplement thereto. You are
  44440. + * permitted to use and redistribute this Software in source and binary
  44441. + * forms, with or without modification, provided that redistributions
  44442. + * of source code must retain this notice. You may not view, use,
  44443. + * disclose, copy or distribute this file or any information contained
  44444. + * herein except pursuant to this license grant from Synopsys. If you
  44445. + * do not agree with this notice, including the disclaimer below, then
  44446. + * you are not authorized to use the Software.
  44447. + *
  44448. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  44449. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  44450. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  44451. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  44452. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  44453. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  44454. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  44455. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  44456. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  44457. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  44458. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  44459. + * DAMAGE.
  44460. + * ========================================================================= */
  44461. +
  44462. +/** @file
  44463. + * This file contains the WUSB cryptographic routines.
  44464. + */
  44465. +
  44466. +#ifdef DWC_CRYPTOLIB
  44467. +
  44468. +#include "dwc_crypto.h"
  44469. +#include "usb.h"
  44470. +
  44471. +#ifdef DEBUG
  44472. +static inline void dump_bytes(char *name, uint8_t *bytes, int len)
  44473. +{
  44474. + int i;
  44475. + DWC_PRINTF("%s: ", name);
  44476. + for (i=0; i<len; i++) {
  44477. + DWC_PRINTF("%02x ", bytes[i]);
  44478. + }
  44479. + DWC_PRINTF("\n");
  44480. +}
  44481. +#else
  44482. +#define dump_bytes(x...)
  44483. +#endif
  44484. +
  44485. +/* Display a block */
  44486. +void show_block(const u8 *blk, const char *prefix, const char *suffix, int a)
  44487. +{
  44488. +#ifdef DWC_DEBUG_CRYPTO
  44489. + int i, blksize = 16;
  44490. +
  44491. + DWC_DEBUG("%s", prefix);
  44492. +
  44493. + if (suffix == NULL) {
  44494. + suffix = "\n";
  44495. + blksize = a;
  44496. + }
  44497. +
  44498. + for (i = 0; i < blksize; i++)
  44499. + DWC_PRINT("%02x%s", *blk++, ((i & 3) == 3) ? " " : " ");
  44500. + DWC_PRINT(suffix);
  44501. +#endif
  44502. +}
  44503. +
  44504. +/**
  44505. + * Encrypts an array of bytes using the AES encryption engine.
  44506. + * If <code>dst</code> == <code>src</code>, then the bytes will be encrypted
  44507. + * in-place.
  44508. + *
  44509. + * @return 0 on success, negative error code on error.
  44510. + */
  44511. +int dwc_wusb_aes_encrypt(u8 *src, u8 *key, u8 *dst)
  44512. +{
  44513. + u8 block_t[16];
  44514. + DWC_MEMSET(block_t, 0, 16);
  44515. +
  44516. + return DWC_AES_CBC(src, 16, key, 16, block_t, dst);
  44517. +}
  44518. +
  44519. +/**
  44520. + * The CCM-MAC-FUNCTION described in section 6.5 of the WUSB spec.
  44521. + * This function takes a data string and returns the encrypted CBC
  44522. + * Counter-mode MIC.
  44523. + *
  44524. + * @param key The 128-bit symmetric key.
  44525. + * @param nonce The CCM nonce.
  44526. + * @param label The unique 14-byte ASCII text label.
  44527. + * @param bytes The byte array to be encrypted.
  44528. + * @param len Length of the byte array.
  44529. + * @param result Byte array to receive the 8-byte encrypted MIC.
  44530. + */
  44531. +void dwc_wusb_cmf(u8 *key, u8 *nonce,
  44532. + char *label, u8 *bytes, int len, u8 *result)
  44533. +{
  44534. + u8 block_m[16];
  44535. + u8 block_x[16];
  44536. + u8 block_t[8];
  44537. + int idx, blkNum;
  44538. + u16 la = (u16)(len + 14);
  44539. +
  44540. + /* Set the AES-128 key */
  44541. + //dwc_aes_setkey(tfm, key, 16);
  44542. +
  44543. + /* Fill block B0 from flags = 0x59, N, and l(m) = 0 */
  44544. + block_m[0] = 0x59;
  44545. + for (idx = 0; idx < 13; idx++)
  44546. + block_m[idx + 1] = nonce[idx];
  44547. + block_m[14] = 0;
  44548. + block_m[15] = 0;
  44549. +
  44550. + /* Produce the CBC IV */
  44551. + dwc_wusb_aes_encrypt(block_m, key, block_x);
  44552. + show_block(block_m, "CBC IV in: ", "\n", 0);
  44553. + show_block(block_x, "CBC IV out:", "\n", 0);
  44554. +
  44555. + /* Fill block B1 from l(a) = Blen + 14, and A */
  44556. + block_x[0] ^= (u8)(la >> 8);
  44557. + block_x[1] ^= (u8)la;
  44558. + for (idx = 0; idx < 14; idx++)
  44559. + block_x[idx + 2] ^= label[idx];
  44560. + show_block(block_x, "After xor: ", "b1\n", 16);
  44561. +
  44562. + dwc_wusb_aes_encrypt(block_x, key, block_x);
  44563. + show_block(block_x, "After AES: ", "b1\n", 16);
  44564. +
  44565. + idx = 0;
  44566. + blkNum = 0;
  44567. +
  44568. + /* Fill remaining blocks with B */
  44569. + while (len-- > 0) {
  44570. + block_x[idx] ^= *bytes++;
  44571. + if (++idx >= 16) {
  44572. + idx = 0;
  44573. + show_block(block_x, "After xor: ", "\n", blkNum);
  44574. + dwc_wusb_aes_encrypt(block_x, key, block_x);
  44575. + show_block(block_x, "After AES: ", "\n", blkNum);
  44576. + blkNum++;
  44577. + }
  44578. + }
  44579. +
  44580. + /* Handle partial last block */
  44581. + if (idx > 0) {
  44582. + show_block(block_x, "After xor: ", "\n", blkNum);
  44583. + dwc_wusb_aes_encrypt(block_x, key, block_x);
  44584. + show_block(block_x, "After AES: ", "\n", blkNum);
  44585. + }
  44586. +
  44587. + /* Save the MIC tag */
  44588. + DWC_MEMCPY(block_t, block_x, 8);
  44589. + show_block(block_t, "MIC tag : ", NULL, 8);
  44590. +
  44591. + /* Fill block A0 from flags = 0x01, N, and counter = 0 */
  44592. + block_m[0] = 0x01;
  44593. + block_m[14] = 0;
  44594. + block_m[15] = 0;
  44595. +
  44596. + /* Encrypt the counter */
  44597. + dwc_wusb_aes_encrypt(block_m, key, block_x);
  44598. + show_block(block_x, "CTR[MIC] : ", NULL, 8);
  44599. +
  44600. + /* XOR with MIC tag */
  44601. + for (idx = 0; idx < 8; idx++) {
  44602. + block_t[idx] ^= block_x[idx];
  44603. + }
  44604. +
  44605. + /* Return result to caller */
  44606. + DWC_MEMCPY(result, block_t, 8);
  44607. + show_block(result, "CCM-MIC : ", NULL, 8);
  44608. +
  44609. +}
  44610. +
  44611. +/**
  44612. + * The PRF function described in section 6.5 of the WUSB spec. This function
  44613. + * concatenates MIC values returned from dwc_cmf() to create a value of
  44614. + * the requested length.
  44615. + *
  44616. + * @param prf_len Length of the PRF function in bits (64, 128, or 256).
  44617. + * @param key, nonce, label, bytes, len Same as for dwc_cmf().
  44618. + * @param result Byte array to receive the result.
  44619. + */
  44620. +void dwc_wusb_prf(int prf_len, u8 *key,
  44621. + u8 *nonce, char *label, u8 *bytes, int len, u8 *result)
  44622. +{
  44623. + int i;
  44624. +
  44625. + nonce[0] = 0;
  44626. + for (i = 0; i < prf_len >> 6; i++, nonce[0]++) {
  44627. + dwc_wusb_cmf(key, nonce, label, bytes, len, result);
  44628. + result += 8;
  44629. + }
  44630. +}
  44631. +
  44632. +/**
  44633. + * Fills in CCM Nonce per the WUSB spec.
  44634. + *
  44635. + * @param[in] haddr Host address.
  44636. + * @param[in] daddr Device address.
  44637. + * @param[in] tkid Session Key(PTK) identifier.
  44638. + * @param[out] nonce Pointer to where the CCM Nonce output is to be written.
  44639. + */
  44640. +void dwc_wusb_fill_ccm_nonce(uint16_t haddr, uint16_t daddr, uint8_t *tkid,
  44641. + uint8_t *nonce)
  44642. +{
  44643. +
  44644. + DWC_DEBUG("%s %x %x\n", __func__, daddr, haddr);
  44645. +
  44646. + DWC_MEMSET(&nonce[0], 0, 16);
  44647. +
  44648. + DWC_MEMCPY(&nonce[6], tkid, 3);
  44649. + nonce[9] = daddr & 0xFF;
  44650. + nonce[10] = (daddr >> 8) & 0xFF;
  44651. + nonce[11] = haddr & 0xFF;
  44652. + nonce[12] = (haddr >> 8) & 0xFF;
  44653. +
  44654. + dump_bytes("CCM nonce", nonce, 16);
  44655. +}
  44656. +
  44657. +/**
  44658. + * Generates a 16-byte cryptographic-grade random number for the Host/Device
  44659. + * Nonce.
  44660. + */
  44661. +void dwc_wusb_gen_nonce(uint16_t addr, uint8_t *nonce)
  44662. +{
  44663. + uint8_t inonce[16];
  44664. + uint32_t temp[4];
  44665. +
  44666. + /* Fill in the Nonce */
  44667. + DWC_MEMSET(&inonce[0], 0, sizeof(inonce));
  44668. + inonce[9] = addr & 0xFF;
  44669. + inonce[10] = (addr >> 8) & 0xFF;
  44670. + inonce[11] = inonce[9];
  44671. + inonce[12] = inonce[10];
  44672. +
  44673. + /* Collect "randomness samples" */
  44674. + DWC_RANDOM_BYTES((uint8_t *)temp, 16);
  44675. +
  44676. + dwc_wusb_prf_128((uint8_t *)temp, nonce,
  44677. + "Random Numbers", (uint8_t *)temp, sizeof(temp),
  44678. + nonce);
  44679. +}
  44680. +
  44681. +/**
  44682. + * Generates the Session Key (PTK) and Key Confirmation Key (KCK) per the
  44683. + * WUSB spec.
  44684. + *
  44685. + * @param[in] ccm_nonce Pointer to CCM Nonce.
  44686. + * @param[in] mk Master Key to derive the session from
  44687. + * @param[in] hnonce Pointer to Host Nonce.
  44688. + * @param[in] dnonce Pointer to Device Nonce.
  44689. + * @param[out] kck Pointer to where the KCK output is to be written.
  44690. + * @param[out] ptk Pointer to where the PTK output is to be written.
  44691. + */
  44692. +void dwc_wusb_gen_key(uint8_t *ccm_nonce, uint8_t *mk, uint8_t *hnonce,
  44693. + uint8_t *dnonce, uint8_t *kck, uint8_t *ptk)
  44694. +{
  44695. + uint8_t idata[32];
  44696. + uint8_t odata[32];
  44697. +
  44698. + dump_bytes("ck", mk, 16);
  44699. + dump_bytes("hnonce", hnonce, 16);
  44700. + dump_bytes("dnonce", dnonce, 16);
  44701. +
  44702. + /* The data is the HNonce and DNonce concatenated */
  44703. + DWC_MEMCPY(&idata[0], hnonce, 16);
  44704. + DWC_MEMCPY(&idata[16], dnonce, 16);
  44705. +
  44706. + dwc_wusb_prf_256(mk, ccm_nonce, "Pair-wise keys", idata, 32, odata);
  44707. +
  44708. + /* Low 16 bytes of the result is the KCK, high 16 is the PTK */
  44709. + DWC_MEMCPY(kck, &odata[0], 16);
  44710. + DWC_MEMCPY(ptk, &odata[16], 16);
  44711. +
  44712. + dump_bytes("kck", kck, 16);
  44713. + dump_bytes("ptk", ptk, 16);
  44714. +}
  44715. +
  44716. +/**
  44717. + * Generates the Message Integrity Code over the Handshake data per the
  44718. + * WUSB spec.
  44719. + *
  44720. + * @param ccm_nonce Pointer to CCM Nonce.
  44721. + * @param kck Pointer to Key Confirmation Key.
  44722. + * @param data Pointer to Handshake data to be checked.
  44723. + * @param mic Pointer to where the MIC output is to be written.
  44724. + */
  44725. +void dwc_wusb_gen_mic(uint8_t *ccm_nonce, uint8_t *kck,
  44726. + uint8_t *data, uint8_t *mic)
  44727. +{
  44728. +
  44729. + dwc_wusb_prf_64(kck, ccm_nonce, "out-of-bandMIC",
  44730. + data, WUSB_HANDSHAKE_LEN_FOR_MIC, mic);
  44731. +}
  44732. +
  44733. +#endif /* DWC_CRYPTOLIB */
  44734. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_common_port/dwc_crypto.h linux-3.12.26/drivers/usb/host/dwc_common_port/dwc_crypto.h
  44735. --- linux-3.12.26.orig/drivers/usb/host/dwc_common_port/dwc_crypto.h 1970-01-01 01:00:00.000000000 +0100
  44736. +++ linux-3.12.26/drivers/usb/host/dwc_common_port/dwc_crypto.h 2014-08-06 16:50:14.773964507 +0200
  44737. @@ -0,0 +1,111 @@
  44738. +/* =========================================================================
  44739. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_crypto.h $
  44740. + * $Revision: #3 $
  44741. + * $Date: 2010/09/28 $
  44742. + * $Change: 1596182 $
  44743. + *
  44744. + * Synopsys Portability Library Software and documentation
  44745. + * (hereinafter, "Software") is an Unsupported proprietary work of
  44746. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  44747. + * between Synopsys and you.
  44748. + *
  44749. + * The Software IS NOT an item of Licensed Software or Licensed Product
  44750. + * under any End User Software License Agreement or Agreement for
  44751. + * Licensed Product with Synopsys or any supplement thereto. You are
  44752. + * permitted to use and redistribute this Software in source and binary
  44753. + * forms, with or without modification, provided that redistributions
  44754. + * of source code must retain this notice. You may not view, use,
  44755. + * disclose, copy or distribute this file or any information contained
  44756. + * herein except pursuant to this license grant from Synopsys. If you
  44757. + * do not agree with this notice, including the disclaimer below, then
  44758. + * you are not authorized to use the Software.
  44759. + *
  44760. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  44761. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  44762. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  44763. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  44764. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  44765. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  44766. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  44767. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  44768. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  44769. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  44770. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  44771. + * DAMAGE.
  44772. + * ========================================================================= */
  44773. +
  44774. +#ifndef _DWC_CRYPTO_H_
  44775. +#define _DWC_CRYPTO_H_
  44776. +
  44777. +#ifdef __cplusplus
  44778. +extern "C" {
  44779. +#endif
  44780. +
  44781. +/** @file
  44782. + *
  44783. + * This file contains declarations for the WUSB Cryptographic routines as
  44784. + * defined in the WUSB spec. They are only to be used internally by the DWC UWB
  44785. + * modules.
  44786. + */
  44787. +
  44788. +#include "dwc_os.h"
  44789. +
  44790. +int dwc_wusb_aes_encrypt(u8 *src, u8 *key, u8 *dst);
  44791. +
  44792. +void dwc_wusb_cmf(u8 *key, u8 *nonce,
  44793. + char *label, u8 *bytes, int len, u8 *result);
  44794. +void dwc_wusb_prf(int prf_len, u8 *key,
  44795. + u8 *nonce, char *label, u8 *bytes, int len, u8 *result);
  44796. +
  44797. +/**
  44798. + * The PRF-64 function described in section 6.5 of the WUSB spec.
  44799. + *
  44800. + * @param key, nonce, label, bytes, len, result Same as for dwc_prf().
  44801. + */
  44802. +static inline void dwc_wusb_prf_64(u8 *key, u8 *nonce,
  44803. + char *label, u8 *bytes, int len, u8 *result)
  44804. +{
  44805. + dwc_wusb_prf(64, key, nonce, label, bytes, len, result);
  44806. +}
  44807. +
  44808. +/**
  44809. + * The PRF-128 function described in section 6.5 of the WUSB spec.
  44810. + *
  44811. + * @param key, nonce, label, bytes, len, result Same as for dwc_prf().
  44812. + */
  44813. +static inline void dwc_wusb_prf_128(u8 *key, u8 *nonce,
  44814. + char *label, u8 *bytes, int len, u8 *result)
  44815. +{
  44816. + dwc_wusb_prf(128, key, nonce, label, bytes, len, result);
  44817. +}
  44818. +
  44819. +/**
  44820. + * The PRF-256 function described in section 6.5 of the WUSB spec.
  44821. + *
  44822. + * @param key, nonce, label, bytes, len, result Same as for dwc_prf().
  44823. + */
  44824. +static inline void dwc_wusb_prf_256(u8 *key, u8 *nonce,
  44825. + char *label, u8 *bytes, int len, u8 *result)
  44826. +{
  44827. + dwc_wusb_prf(256, key, nonce, label, bytes, len, result);
  44828. +}
  44829. +
  44830. +
  44831. +void dwc_wusb_fill_ccm_nonce(uint16_t haddr, uint16_t daddr, uint8_t *tkid,
  44832. + uint8_t *nonce);
  44833. +void dwc_wusb_gen_nonce(uint16_t addr,
  44834. + uint8_t *nonce);
  44835. +
  44836. +void dwc_wusb_gen_key(uint8_t *ccm_nonce, uint8_t *mk,
  44837. + uint8_t *hnonce, uint8_t *dnonce,
  44838. + uint8_t *kck, uint8_t *ptk);
  44839. +
  44840. +
  44841. +void dwc_wusb_gen_mic(uint8_t *ccm_nonce, uint8_t
  44842. + *kck, uint8_t *data, uint8_t *mic);
  44843. +
  44844. +#ifdef __cplusplus
  44845. +}
  44846. +#endif
  44847. +
  44848. +#endif /* _DWC_CRYPTO_H_ */
  44849. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_common_port/dwc_dh.c linux-3.12.26/drivers/usb/host/dwc_common_port/dwc_dh.c
  44850. --- linux-3.12.26.orig/drivers/usb/host/dwc_common_port/dwc_dh.c 1970-01-01 01:00:00.000000000 +0100
  44851. +++ linux-3.12.26/drivers/usb/host/dwc_common_port/dwc_dh.c 2014-08-06 16:50:14.773964507 +0200
  44852. @@ -0,0 +1,291 @@
  44853. +/* =========================================================================
  44854. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_dh.c $
  44855. + * $Revision: #3 $
  44856. + * $Date: 2010/09/28 $
  44857. + * $Change: 1596182 $
  44858. + *
  44859. + * Synopsys Portability Library Software and documentation
  44860. + * (hereinafter, "Software") is an Unsupported proprietary work of
  44861. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  44862. + * between Synopsys and you.
  44863. + *
  44864. + * The Software IS NOT an item of Licensed Software or Licensed Product
  44865. + * under any End User Software License Agreement or Agreement for
  44866. + * Licensed Product with Synopsys or any supplement thereto. You are
  44867. + * permitted to use and redistribute this Software in source and binary
  44868. + * forms, with or without modification, provided that redistributions
  44869. + * of source code must retain this notice. You may not view, use,
  44870. + * disclose, copy or distribute this file or any information contained
  44871. + * herein except pursuant to this license grant from Synopsys. If you
  44872. + * do not agree with this notice, including the disclaimer below, then
  44873. + * you are not authorized to use the Software.
  44874. + *
  44875. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  44876. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  44877. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  44878. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  44879. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  44880. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  44881. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  44882. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  44883. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  44884. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  44885. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  44886. + * DAMAGE.
  44887. + * ========================================================================= */
  44888. +#ifdef DWC_CRYPTOLIB
  44889. +
  44890. +#ifndef CONFIG_MACH_IPMATE
  44891. +
  44892. +#include "dwc_dh.h"
  44893. +#include "dwc_modpow.h"
  44894. +
  44895. +#ifdef DEBUG
  44896. +/* This function prints out a buffer in the format described in the Association
  44897. + * Model specification. */
  44898. +static void dh_dump(char *str, void *_num, int len)
  44899. +{
  44900. + uint8_t *num = _num;
  44901. + int i;
  44902. + DWC_PRINTF("%s\n", str);
  44903. + for (i = 0; i < len; i ++) {
  44904. + DWC_PRINTF("%02x", num[i]);
  44905. + if (((i + 1) % 2) == 0) DWC_PRINTF(" ");
  44906. + if (((i + 1) % 26) == 0) DWC_PRINTF("\n");
  44907. + }
  44908. +
  44909. + DWC_PRINTF("\n");
  44910. +}
  44911. +#else
  44912. +#define dh_dump(_x...) do {; } while(0)
  44913. +#endif
  44914. +
  44915. +/* Constant g value */
  44916. +static __u32 dh_g[] = {
  44917. + 0x02000000,
  44918. +};
  44919. +
  44920. +/* Constant p value */
  44921. +static __u32 dh_p[] = {
  44922. + 0xFFFFFFFF, 0xFFFFFFFF, 0xA2DA0FC9, 0x34C26821, 0x8B62C6C4, 0xD11CDC80, 0x084E0229, 0x74CC678A,
  44923. + 0xA6BE0B02, 0x229B133B, 0x79084A51, 0xDD04348E, 0xB31995EF, 0x1B433ACD, 0x6D0A2B30, 0x37145FF2,
  44924. + 0x6D35E14F, 0x45C2516D, 0x76B585E4, 0xC67E5E62, 0xE9424CF4, 0x6BED37A6, 0xB65CFF0B, 0xEDB706F4,
  44925. + 0xFB6B38EE, 0xA59F895A, 0x11249FAE, 0xE61F4B7C, 0x51662849, 0x3D5BE4EC, 0xB87C00C2, 0x05BF63A1,
  44926. + 0x3648DA98, 0x9AD3551C, 0xA83F1669, 0x5FCF24FD, 0x235D6583, 0x96ADA3DC, 0x56F3621C, 0xBB528520,
  44927. + 0x0729D59E, 0x6D969670, 0x4E350C67, 0x0498BC4A, 0x086C74F1, 0x7C2118CA, 0x465E9032, 0x3BCE362E,
  44928. + 0x2C779EE3, 0x03860E18, 0xA283279B, 0x8FA207EC, 0xF05DC5B5, 0xC9524C6F, 0xF6CB2BDE, 0x18175895,
  44929. + 0x7C499539, 0xE56A95EA, 0x1826D215, 0x1005FA98, 0x5A8E7215, 0x2DC4AA8A, 0x0D1733AD, 0x337A5004,
  44930. + 0xAB2155A8, 0x64BA1CDF, 0x0485FBEC, 0x0AEFDB58, 0x5771EA8A, 0x7D0C065D, 0x850F97B3, 0xC7E4E1A6,
  44931. + 0x8CAEF5AB, 0xD73309DB, 0xE0948C1E, 0x9D61254A, 0x26D2E3CE, 0x6BEED21A, 0x06FA2FF1, 0x64088AD9,
  44932. + 0x730276D8, 0x646AC83E, 0x182B1F52, 0x0C207B17, 0x5717E1BB, 0x6C5D617A, 0xC0880977, 0xE246D9BA,
  44933. + 0xA04FE208, 0x31ABE574, 0xFC5BDB43, 0x8E10FDE0, 0x20D1824B, 0xCAD23AA9, 0xFFFFFFFF, 0xFFFFFFFF,
  44934. +};
  44935. +
  44936. +static void dh_swap_bytes(void *_in, void *_out, uint32_t len)
  44937. +{
  44938. + uint8_t *in = _in;
  44939. + uint8_t *out = _out;
  44940. + int i;
  44941. + for (i=0; i<len; i++) {
  44942. + out[i] = in[len-1-i];
  44943. + }
  44944. +}
  44945. +
  44946. +/* Computes the modular exponentiation (num^exp % mod). num, exp, and mod are
  44947. + * big endian numbers of size len, in bytes. Each len value must be a multiple
  44948. + * of 4. */
  44949. +int dwc_dh_modpow(void *mem_ctx, void *num, uint32_t num_len,
  44950. + void *exp, uint32_t exp_len,
  44951. + void *mod, uint32_t mod_len,
  44952. + void *out)
  44953. +{
  44954. + /* modpow() takes little endian numbers. AM uses big-endian. This
  44955. + * function swaps bytes of numbers before passing onto modpow. */
  44956. +
  44957. + int retval = 0;
  44958. + uint32_t *result;
  44959. +
  44960. + uint32_t *bignum_num = dwc_alloc(mem_ctx, num_len + 4);
  44961. + uint32_t *bignum_exp = dwc_alloc(mem_ctx, exp_len + 4);
  44962. + uint32_t *bignum_mod = dwc_alloc(mem_ctx, mod_len + 4);
  44963. +
  44964. + dh_swap_bytes(num, &bignum_num[1], num_len);
  44965. + bignum_num[0] = num_len / 4;
  44966. +
  44967. + dh_swap_bytes(exp, &bignum_exp[1], exp_len);
  44968. + bignum_exp[0] = exp_len / 4;
  44969. +
  44970. + dh_swap_bytes(mod, &bignum_mod[1], mod_len);
  44971. + bignum_mod[0] = mod_len / 4;
  44972. +
  44973. + result = dwc_modpow(mem_ctx, bignum_num, bignum_exp, bignum_mod);
  44974. + if (!result) {
  44975. + retval = -1;
  44976. + goto dh_modpow_nomem;
  44977. + }
  44978. +
  44979. + dh_swap_bytes(&result[1], out, result[0] * 4);
  44980. + dwc_free(mem_ctx, result);
  44981. +
  44982. + dh_modpow_nomem:
  44983. + dwc_free(mem_ctx, bignum_num);
  44984. + dwc_free(mem_ctx, bignum_exp);
  44985. + dwc_free(mem_ctx, bignum_mod);
  44986. + return retval;
  44987. +}
  44988. +
  44989. +
  44990. +int dwc_dh_pk(void *mem_ctx, uint8_t nd, uint8_t *exp, uint8_t *pk, uint8_t *hash)
  44991. +{
  44992. + int retval;
  44993. + uint8_t m3[385];
  44994. +
  44995. +#ifndef DH_TEST_VECTORS
  44996. + DWC_RANDOM_BYTES(exp, 32);
  44997. +#endif
  44998. +
  44999. + /* Compute the pkd */
  45000. + if ((retval = dwc_dh_modpow(mem_ctx, dh_g, 4,
  45001. + exp, 32,
  45002. + dh_p, 384, pk))) {
  45003. + return retval;
  45004. + }
  45005. +
  45006. + m3[384] = nd;
  45007. + DWC_MEMCPY(&m3[0], pk, 384);
  45008. + DWC_SHA256(m3, 385, hash);
  45009. +
  45010. + dh_dump("PK", pk, 384);
  45011. + dh_dump("SHA-256(M3)", hash, 32);
  45012. + return 0;
  45013. +}
  45014. +
  45015. +int dwc_dh_derive_keys(void *mem_ctx, uint8_t nd, uint8_t *pkh, uint8_t *pkd,
  45016. + uint8_t *exp, int is_host,
  45017. + char *dd, uint8_t *ck, uint8_t *kdk)
  45018. +{
  45019. + int retval;
  45020. + uint8_t mv[784];
  45021. + uint8_t sha_result[32];
  45022. + uint8_t dhkey[384];
  45023. + uint8_t shared_secret[384];
  45024. + char *message;
  45025. + uint32_t vd;
  45026. +
  45027. + uint8_t *pk;
  45028. +
  45029. + if (is_host) {
  45030. + pk = pkd;
  45031. + }
  45032. + else {
  45033. + pk = pkh;
  45034. + }
  45035. +
  45036. + if ((retval = dwc_dh_modpow(mem_ctx, pk, 384,
  45037. + exp, 32,
  45038. + dh_p, 384, shared_secret))) {
  45039. + return retval;
  45040. + }
  45041. + dh_dump("Shared Secret", shared_secret, 384);
  45042. +
  45043. + DWC_SHA256(shared_secret, 384, dhkey);
  45044. + dh_dump("DHKEY", dhkey, 384);
  45045. +
  45046. + DWC_MEMCPY(&mv[0], pkd, 384);
  45047. + DWC_MEMCPY(&mv[384], pkh, 384);
  45048. + DWC_MEMCPY(&mv[768], "displayed digest", 16);
  45049. + dh_dump("MV", mv, 784);
  45050. +
  45051. + DWC_SHA256(mv, 784, sha_result);
  45052. + dh_dump("SHA-256(MV)", sha_result, 32);
  45053. + dh_dump("First 32-bits of SHA-256(MV)", sha_result, 4);
  45054. +
  45055. + dh_swap_bytes(sha_result, &vd, 4);
  45056. +#ifdef DEBUG
  45057. + DWC_PRINTF("Vd (decimal) = %d\n", vd);
  45058. +#endif
  45059. +
  45060. + switch (nd) {
  45061. + case 2:
  45062. + vd = vd % 100;
  45063. + DWC_SPRINTF(dd, "%02d", vd);
  45064. + break;
  45065. + case 3:
  45066. + vd = vd % 1000;
  45067. + DWC_SPRINTF(dd, "%03d", vd);
  45068. + break;
  45069. + case 4:
  45070. + vd = vd % 10000;
  45071. + DWC_SPRINTF(dd, "%04d", vd);
  45072. + break;
  45073. + }
  45074. +#ifdef DEBUG
  45075. + DWC_PRINTF("Display Digits: %s\n", dd);
  45076. +#endif
  45077. +
  45078. + message = "connection key";
  45079. + DWC_HMAC_SHA256(message, DWC_STRLEN(message), dhkey, 32, sha_result);
  45080. + dh_dump("HMAC(SHA-256, DHKey, connection key)", sha_result, 32);
  45081. + DWC_MEMCPY(ck, sha_result, 16);
  45082. +
  45083. + message = "key derivation key";
  45084. + DWC_HMAC_SHA256(message, DWC_STRLEN(message), dhkey, 32, sha_result);
  45085. + dh_dump("HMAC(SHA-256, DHKey, key derivation key)", sha_result, 32);
  45086. + DWC_MEMCPY(kdk, sha_result, 32);
  45087. +
  45088. + return 0;
  45089. +}
  45090. +
  45091. +
  45092. +#ifdef DH_TEST_VECTORS
  45093. +
  45094. +static __u8 dh_a[] = {
  45095. + 0x44, 0x00, 0x51, 0xd6,
  45096. + 0xf0, 0xb5, 0x5e, 0xa9,
  45097. + 0x67, 0xab, 0x31, 0xc6,
  45098. + 0x8a, 0x8b, 0x5e, 0x37,
  45099. + 0xd9, 0x10, 0xda, 0xe0,
  45100. + 0xe2, 0xd4, 0x59, 0xa4,
  45101. + 0x86, 0x45, 0x9c, 0xaa,
  45102. + 0xdf, 0x36, 0x75, 0x16,
  45103. +};
  45104. +
  45105. +static __u8 dh_b[] = {
  45106. + 0x5d, 0xae, 0xc7, 0x86,
  45107. + 0x79, 0x80, 0xa3, 0x24,
  45108. + 0x8c, 0xe3, 0x57, 0x8f,
  45109. + 0xc7, 0x5f, 0x1b, 0x0f,
  45110. + 0x2d, 0xf8, 0x9d, 0x30,
  45111. + 0x6f, 0xa4, 0x52, 0xcd,
  45112. + 0xe0, 0x7a, 0x04, 0x8a,
  45113. + 0xde, 0xd9, 0x26, 0x56,
  45114. +};
  45115. +
  45116. +void dwc_run_dh_test_vectors(void *mem_ctx)
  45117. +{
  45118. + uint8_t pkd[384];
  45119. + uint8_t pkh[384];
  45120. + uint8_t hashd[32];
  45121. + uint8_t hashh[32];
  45122. + uint8_t ck[16];
  45123. + uint8_t kdk[32];
  45124. + char dd[5];
  45125. +
  45126. + DWC_PRINTF("\n\n\nDH_TEST_VECTORS\n\n");
  45127. +
  45128. + /* compute the PKd and SHA-256(PKd || Nd) */
  45129. + DWC_PRINTF("Computing PKd\n");
  45130. + dwc_dh_pk(mem_ctx, 2, dh_a, pkd, hashd);
  45131. +
  45132. + /* compute the PKd and SHA-256(PKh || Nd) */
  45133. + DWC_PRINTF("Computing PKh\n");
  45134. + dwc_dh_pk(mem_ctx, 2, dh_b, pkh, hashh);
  45135. +
  45136. + /* compute the dhkey */
  45137. + dwc_dh_derive_keys(mem_ctx, 2, pkh, pkd, dh_a, 0, dd, ck, kdk);
  45138. +}
  45139. +#endif /* DH_TEST_VECTORS */
  45140. +
  45141. +#endif /* !CONFIG_MACH_IPMATE */
  45142. +
  45143. +#endif /* DWC_CRYPTOLIB */
  45144. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_common_port/dwc_dh.h linux-3.12.26/drivers/usb/host/dwc_common_port/dwc_dh.h
  45145. --- linux-3.12.26.orig/drivers/usb/host/dwc_common_port/dwc_dh.h 1970-01-01 01:00:00.000000000 +0100
  45146. +++ linux-3.12.26/drivers/usb/host/dwc_common_port/dwc_dh.h 2014-08-06 16:50:14.777964537 +0200
  45147. @@ -0,0 +1,106 @@
  45148. +/* =========================================================================
  45149. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_dh.h $
  45150. + * $Revision: #4 $
  45151. + * $Date: 2010/09/28 $
  45152. + * $Change: 1596182 $
  45153. + *
  45154. + * Synopsys Portability Library Software and documentation
  45155. + * (hereinafter, "Software") is an Unsupported proprietary work of
  45156. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  45157. + * between Synopsys and you.
  45158. + *
  45159. + * The Software IS NOT an item of Licensed Software or Licensed Product
  45160. + * under any End User Software License Agreement or Agreement for
  45161. + * Licensed Product with Synopsys or any supplement thereto. You are
  45162. + * permitted to use and redistribute this Software in source and binary
  45163. + * forms, with or without modification, provided that redistributions
  45164. + * of source code must retain this notice. You may not view, use,
  45165. + * disclose, copy or distribute this file or any information contained
  45166. + * herein except pursuant to this license grant from Synopsys. If you
  45167. + * do not agree with this notice, including the disclaimer below, then
  45168. + * you are not authorized to use the Software.
  45169. + *
  45170. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  45171. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  45172. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  45173. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  45174. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  45175. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  45176. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  45177. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  45178. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  45179. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  45180. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  45181. + * DAMAGE.
  45182. + * ========================================================================= */
  45183. +#ifndef _DWC_DH_H_
  45184. +#define _DWC_DH_H_
  45185. +
  45186. +#ifdef __cplusplus
  45187. +extern "C" {
  45188. +#endif
  45189. +
  45190. +#include "dwc_os.h"
  45191. +
  45192. +/** @file
  45193. + *
  45194. + * This file defines the common functions on device and host for performing
  45195. + * numeric association as defined in the WUSB spec. They are only to be
  45196. + * used internally by the DWC UWB modules. */
  45197. +
  45198. +extern int dwc_dh_sha256(uint8_t *message, uint32_t len, uint8_t *out);
  45199. +extern int dwc_dh_hmac_sha256(uint8_t *message, uint32_t messagelen,
  45200. + uint8_t *key, uint32_t keylen,
  45201. + uint8_t *out);
  45202. +extern int dwc_dh_modpow(void *mem_ctx, void *num, uint32_t num_len,
  45203. + void *exp, uint32_t exp_len,
  45204. + void *mod, uint32_t mod_len,
  45205. + void *out);
  45206. +
  45207. +/** Computes PKD or PKH, and SHA-256(PKd || Nd)
  45208. + *
  45209. + * PK = g^exp mod p.
  45210. + *
  45211. + * Input:
  45212. + * Nd = Number of digits on the device.
  45213. + *
  45214. + * Output:
  45215. + * exp = A 32-byte buffer to be filled with a randomly generated number.
  45216. + * used as either A or B.
  45217. + * pk = A 384-byte buffer to be filled with the PKH or PKD.
  45218. + * hash = A 32-byte buffer to be filled with SHA-256(PK || ND).
  45219. + */
  45220. +extern int dwc_dh_pk(void *mem_ctx, uint8_t nd, uint8_t *exp, uint8_t *pkd, uint8_t *hash);
  45221. +
  45222. +/** Computes the DHKEY, and VD.
  45223. + *
  45224. + * If called from host, then it will comput DHKEY=PKD^exp % p.
  45225. + * If called from device, then it will comput DHKEY=PKH^exp % p.
  45226. + *
  45227. + * Input:
  45228. + * pkd = The PKD value.
  45229. + * pkh = The PKH value.
  45230. + * exp = The A value (if device) or B value (if host) generated in dwc_wudev_dh_pk.
  45231. + * is_host = Set to non zero if a WUSB host is calling this function.
  45232. + *
  45233. + * Output:
  45234. +
  45235. + * dd = A pointer to an buffer to be set to the displayed digits string to be shown
  45236. + * to the user. This buffer should be at 5 bytes long to hold 4 digits plus a
  45237. + * null termination character. This buffer can be used directly for display.
  45238. + * ck = A 16-byte buffer to be filled with the CK.
  45239. + * kdk = A 32-byte buffer to be filled with the KDK.
  45240. + */
  45241. +extern int dwc_dh_derive_keys(void *mem_ctx, uint8_t nd, uint8_t *pkh, uint8_t *pkd,
  45242. + uint8_t *exp, int is_host,
  45243. + char *dd, uint8_t *ck, uint8_t *kdk);
  45244. +
  45245. +#ifdef DH_TEST_VECTORS
  45246. +extern void dwc_run_dh_test_vectors(void);
  45247. +#endif
  45248. +
  45249. +#ifdef __cplusplus
  45250. +}
  45251. +#endif
  45252. +
  45253. +#endif /* _DWC_DH_H_ */
  45254. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_common_port/dwc_list.h linux-3.12.26/drivers/usb/host/dwc_common_port/dwc_list.h
  45255. --- linux-3.12.26.orig/drivers/usb/host/dwc_common_port/dwc_list.h 1970-01-01 01:00:00.000000000 +0100
  45256. +++ linux-3.12.26/drivers/usb/host/dwc_common_port/dwc_list.h 2014-08-06 16:50:14.777964537 +0200
  45257. @@ -0,0 +1,594 @@
  45258. +/* $OpenBSD: queue.h,v 1.26 2004/05/04 16:59:32 grange Exp $ */
  45259. +/* $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $ */
  45260. +
  45261. +/*
  45262. + * Copyright (c) 1991, 1993
  45263. + * The Regents of the University of California. All rights reserved.
  45264. + *
  45265. + * Redistribution and use in source and binary forms, with or without
  45266. + * modification, are permitted provided that the following conditions
  45267. + * are met:
  45268. + * 1. Redistributions of source code must retain the above copyright
  45269. + * notice, this list of conditions and the following disclaimer.
  45270. + * 2. Redistributions in binary form must reproduce the above copyright
  45271. + * notice, this list of conditions and the following disclaimer in the
  45272. + * documentation and/or other materials provided with the distribution.
  45273. + * 3. Neither the name of the University nor the names of its contributors
  45274. + * may be used to endorse or promote products derived from this software
  45275. + * without specific prior written permission.
  45276. + *
  45277. + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  45278. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  45279. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  45280. + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  45281. + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  45282. + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  45283. + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  45284. + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  45285. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  45286. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  45287. + * SUCH DAMAGE.
  45288. + *
  45289. + * @(#)queue.h 8.5 (Berkeley) 8/20/94
  45290. + */
  45291. +
  45292. +#ifndef _DWC_LIST_H_
  45293. +#define _DWC_LIST_H_
  45294. +
  45295. +#ifdef __cplusplus
  45296. +extern "C" {
  45297. +#endif
  45298. +
  45299. +/** @file
  45300. + *
  45301. + * This file defines linked list operations. It is derived from BSD with
  45302. + * only the MACRO names being prefixed with DWC_. This is because a few of
  45303. + * these names conflict with those on Linux. For documentation on use, see the
  45304. + * inline comments in the source code. The original license for this source
  45305. + * code applies and is preserved in the dwc_list.h source file.
  45306. + */
  45307. +
  45308. +/*
  45309. + * This file defines five types of data structures: singly-linked lists,
  45310. + * lists, simple queues, tail queues, and circular queues.
  45311. + *
  45312. + *
  45313. + * A singly-linked list is headed by a single forward pointer. The elements
  45314. + * are singly linked for minimum space and pointer manipulation overhead at
  45315. + * the expense of O(n) removal for arbitrary elements. New elements can be
  45316. + * added to the list after an existing element or at the head of the list.
  45317. + * Elements being removed from the head of the list should use the explicit
  45318. + * macro for this purpose for optimum efficiency. A singly-linked list may
  45319. + * only be traversed in the forward direction. Singly-linked lists are ideal
  45320. + * for applications with large datasets and few or no removals or for
  45321. + * implementing a LIFO queue.
  45322. + *
  45323. + * A list is headed by a single forward pointer (or an array of forward
  45324. + * pointers for a hash table header). The elements are doubly linked
  45325. + * so that an arbitrary element can be removed without a need to
  45326. + * traverse the list. New elements can be added to the list before
  45327. + * or after an existing element or at the head of the list. A list
  45328. + * may only be traversed in the forward direction.
  45329. + *
  45330. + * A simple queue is headed by a pair of pointers, one the head of the
  45331. + * list and the other to the tail of the list. The elements are singly
  45332. + * linked to save space, so elements can only be removed from the
  45333. + * head of the list. New elements can be added to the list before or after
  45334. + * an existing element, at the head of the list, or at the end of the
  45335. + * list. A simple queue may only be traversed in the forward direction.
  45336. + *
  45337. + * A tail queue is headed by a pair of pointers, one to the head of the
  45338. + * list and the other to the tail of the list. The elements are doubly
  45339. + * linked so that an arbitrary element can be removed without a need to
  45340. + * traverse the list. New elements can be added to the list before or
  45341. + * after an existing element, at the head of the list, or at the end of
  45342. + * the list. A tail queue may be traversed in either direction.
  45343. + *
  45344. + * A circle queue is headed by a pair of pointers, one to the head of the
  45345. + * list and the other to the tail of the list. The elements are doubly
  45346. + * linked so that an arbitrary element can be removed without a need to
  45347. + * traverse the list. New elements can be added to the list before or after
  45348. + * an existing element, at the head of the list, or at the end of the list.
  45349. + * A circle queue may be traversed in either direction, but has a more
  45350. + * complex end of list detection.
  45351. + *
  45352. + * For details on the use of these macros, see the queue(3) manual page.
  45353. + */
  45354. +
  45355. +/*
  45356. + * Double-linked List.
  45357. + */
  45358. +
  45359. +typedef struct dwc_list_link {
  45360. + struct dwc_list_link *next;
  45361. + struct dwc_list_link *prev;
  45362. +} dwc_list_link_t;
  45363. +
  45364. +#define DWC_LIST_INIT(link) do { \
  45365. + (link)->next = (link); \
  45366. + (link)->prev = (link); \
  45367. +} while (0)
  45368. +
  45369. +#define DWC_LIST_FIRST(link) ((link)->next)
  45370. +#define DWC_LIST_LAST(link) ((link)->prev)
  45371. +#define DWC_LIST_END(link) (link)
  45372. +#define DWC_LIST_NEXT(link) ((link)->next)
  45373. +#define DWC_LIST_PREV(link) ((link)->prev)
  45374. +#define DWC_LIST_EMPTY(link) \
  45375. + (DWC_LIST_FIRST(link) == DWC_LIST_END(link))
  45376. +#define DWC_LIST_ENTRY(link, type, field) \
  45377. + (type *)((uint8_t *)(link) - (size_t)(&((type *)0)->field))
  45378. +
  45379. +#if 0
  45380. +#define DWC_LIST_INSERT_HEAD(list, link) do { \
  45381. + (link)->next = (list)->next; \
  45382. + (link)->prev = (list); \
  45383. + (list)->next->prev = (link); \
  45384. + (list)->next = (link); \
  45385. +} while (0)
  45386. +
  45387. +#define DWC_LIST_INSERT_TAIL(list, link) do { \
  45388. + (link)->next = (list); \
  45389. + (link)->prev = (list)->prev; \
  45390. + (list)->prev->next = (link); \
  45391. + (list)->prev = (link); \
  45392. +} while (0)
  45393. +#else
  45394. +#define DWC_LIST_INSERT_HEAD(list, link) do { \
  45395. + dwc_list_link_t *__next__ = (list)->next; \
  45396. + __next__->prev = (link); \
  45397. + (link)->next = __next__; \
  45398. + (link)->prev = (list); \
  45399. + (list)->next = (link); \
  45400. +} while (0)
  45401. +
  45402. +#define DWC_LIST_INSERT_TAIL(list, link) do { \
  45403. + dwc_list_link_t *__prev__ = (list)->prev; \
  45404. + (list)->prev = (link); \
  45405. + (link)->next = (list); \
  45406. + (link)->prev = __prev__; \
  45407. + __prev__->next = (link); \
  45408. +} while (0)
  45409. +#endif
  45410. +
  45411. +#if 0
  45412. +static inline void __list_add(struct list_head *new,
  45413. + struct list_head *prev,
  45414. + struct list_head *next)
  45415. +{
  45416. + next->prev = new;
  45417. + new->next = next;
  45418. + new->prev = prev;
  45419. + prev->next = new;
  45420. +}
  45421. +
  45422. +static inline void list_add(struct list_head *new, struct list_head *head)
  45423. +{
  45424. + __list_add(new, head, head->next);
  45425. +}
  45426. +
  45427. +static inline void list_add_tail(struct list_head *new, struct list_head *head)
  45428. +{
  45429. + __list_add(new, head->prev, head);
  45430. +}
  45431. +
  45432. +static inline void __list_del(struct list_head * prev, struct list_head * next)
  45433. +{
  45434. + next->prev = prev;
  45435. + prev->next = next;
  45436. +}
  45437. +
  45438. +static inline void list_del(struct list_head *entry)
  45439. +{
  45440. + __list_del(entry->prev, entry->next);
  45441. + entry->next = LIST_POISON1;
  45442. + entry->prev = LIST_POISON2;
  45443. +}
  45444. +#endif
  45445. +
  45446. +#define DWC_LIST_REMOVE(link) do { \
  45447. + (link)->next->prev = (link)->prev; \
  45448. + (link)->prev->next = (link)->next; \
  45449. +} while (0)
  45450. +
  45451. +#define DWC_LIST_REMOVE_INIT(link) do { \
  45452. + DWC_LIST_REMOVE(link); \
  45453. + DWC_LIST_INIT(link); \
  45454. +} while (0)
  45455. +
  45456. +#define DWC_LIST_MOVE_HEAD(list, link) do { \
  45457. + DWC_LIST_REMOVE(link); \
  45458. + DWC_LIST_INSERT_HEAD(list, link); \
  45459. +} while (0)
  45460. +
  45461. +#define DWC_LIST_MOVE_TAIL(list, link) do { \
  45462. + DWC_LIST_REMOVE(link); \
  45463. + DWC_LIST_INSERT_TAIL(list, link); \
  45464. +} while (0)
  45465. +
  45466. +#define DWC_LIST_FOREACH(var, list) \
  45467. + for((var) = DWC_LIST_FIRST(list); \
  45468. + (var) != DWC_LIST_END(list); \
  45469. + (var) = DWC_LIST_NEXT(var))
  45470. +
  45471. +#define DWC_LIST_FOREACH_SAFE(var, var2, list) \
  45472. + for((var) = DWC_LIST_FIRST(list), (var2) = DWC_LIST_NEXT(var); \
  45473. + (var) != DWC_LIST_END(list); \
  45474. + (var) = (var2), (var2) = DWC_LIST_NEXT(var2))
  45475. +
  45476. +#define DWC_LIST_FOREACH_REVERSE(var, list) \
  45477. + for((var) = DWC_LIST_LAST(list); \
  45478. + (var) != DWC_LIST_END(list); \
  45479. + (var) = DWC_LIST_PREV(var))
  45480. +
  45481. +/*
  45482. + * Singly-linked List definitions.
  45483. + */
  45484. +#define DWC_SLIST_HEAD(name, type) \
  45485. +struct name { \
  45486. + struct type *slh_first; /* first element */ \
  45487. +}
  45488. +
  45489. +#define DWC_SLIST_HEAD_INITIALIZER(head) \
  45490. + { NULL }
  45491. +
  45492. +#define DWC_SLIST_ENTRY(type) \
  45493. +struct { \
  45494. + struct type *sle_next; /* next element */ \
  45495. +}
  45496. +
  45497. +/*
  45498. + * Singly-linked List access methods.
  45499. + */
  45500. +#define DWC_SLIST_FIRST(head) ((head)->slh_first)
  45501. +#define DWC_SLIST_END(head) NULL
  45502. +#define DWC_SLIST_EMPTY(head) (SLIST_FIRST(head) == SLIST_END(head))
  45503. +#define DWC_SLIST_NEXT(elm, field) ((elm)->field.sle_next)
  45504. +
  45505. +#define DWC_SLIST_FOREACH(var, head, field) \
  45506. + for((var) = SLIST_FIRST(head); \
  45507. + (var) != SLIST_END(head); \
  45508. + (var) = SLIST_NEXT(var, field))
  45509. +
  45510. +#define DWC_SLIST_FOREACH_PREVPTR(var, varp, head, field) \
  45511. + for((varp) = &SLIST_FIRST((head)); \
  45512. + ((var) = *(varp)) != SLIST_END(head); \
  45513. + (varp) = &SLIST_NEXT((var), field))
  45514. +
  45515. +/*
  45516. + * Singly-linked List functions.
  45517. + */
  45518. +#define DWC_SLIST_INIT(head) { \
  45519. + SLIST_FIRST(head) = SLIST_END(head); \
  45520. +}
  45521. +
  45522. +#define DWC_SLIST_INSERT_AFTER(slistelm, elm, field) do { \
  45523. + (elm)->field.sle_next = (slistelm)->field.sle_next; \
  45524. + (slistelm)->field.sle_next = (elm); \
  45525. +} while (0)
  45526. +
  45527. +#define DWC_SLIST_INSERT_HEAD(head, elm, field) do { \
  45528. + (elm)->field.sle_next = (head)->slh_first; \
  45529. + (head)->slh_first = (elm); \
  45530. +} while (0)
  45531. +
  45532. +#define DWC_SLIST_REMOVE_NEXT(head, elm, field) do { \
  45533. + (elm)->field.sle_next = (elm)->field.sle_next->field.sle_next; \
  45534. +} while (0)
  45535. +
  45536. +#define DWC_SLIST_REMOVE_HEAD(head, field) do { \
  45537. + (head)->slh_first = (head)->slh_first->field.sle_next; \
  45538. +} while (0)
  45539. +
  45540. +#define DWC_SLIST_REMOVE(head, elm, type, field) do { \
  45541. + if ((head)->slh_first == (elm)) { \
  45542. + SLIST_REMOVE_HEAD((head), field); \
  45543. + } \
  45544. + else { \
  45545. + struct type *curelm = (head)->slh_first; \
  45546. + while( curelm->field.sle_next != (elm) ) \
  45547. + curelm = curelm->field.sle_next; \
  45548. + curelm->field.sle_next = \
  45549. + curelm->field.sle_next->field.sle_next; \
  45550. + } \
  45551. +} while (0)
  45552. +
  45553. +/*
  45554. + * Simple queue definitions.
  45555. + */
  45556. +#define DWC_SIMPLEQ_HEAD(name, type) \
  45557. +struct name { \
  45558. + struct type *sqh_first; /* first element */ \
  45559. + struct type **sqh_last; /* addr of last next element */ \
  45560. +}
  45561. +
  45562. +#define DWC_SIMPLEQ_HEAD_INITIALIZER(head) \
  45563. + { NULL, &(head).sqh_first }
  45564. +
  45565. +#define DWC_SIMPLEQ_ENTRY(type) \
  45566. +struct { \
  45567. + struct type *sqe_next; /* next element */ \
  45568. +}
  45569. +
  45570. +/*
  45571. + * Simple queue access methods.
  45572. + */
  45573. +#define DWC_SIMPLEQ_FIRST(head) ((head)->sqh_first)
  45574. +#define DWC_SIMPLEQ_END(head) NULL
  45575. +#define DWC_SIMPLEQ_EMPTY(head) (SIMPLEQ_FIRST(head) == SIMPLEQ_END(head))
  45576. +#define DWC_SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next)
  45577. +
  45578. +#define DWC_SIMPLEQ_FOREACH(var, head, field) \
  45579. + for((var) = SIMPLEQ_FIRST(head); \
  45580. + (var) != SIMPLEQ_END(head); \
  45581. + (var) = SIMPLEQ_NEXT(var, field))
  45582. +
  45583. +/*
  45584. + * Simple queue functions.
  45585. + */
  45586. +#define DWC_SIMPLEQ_INIT(head) do { \
  45587. + (head)->sqh_first = NULL; \
  45588. + (head)->sqh_last = &(head)->sqh_first; \
  45589. +} while (0)
  45590. +
  45591. +#define DWC_SIMPLEQ_INSERT_HEAD(head, elm, field) do { \
  45592. + if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \
  45593. + (head)->sqh_last = &(elm)->field.sqe_next; \
  45594. + (head)->sqh_first = (elm); \
  45595. +} while (0)
  45596. +
  45597. +#define DWC_SIMPLEQ_INSERT_TAIL(head, elm, field) do { \
  45598. + (elm)->field.sqe_next = NULL; \
  45599. + *(head)->sqh_last = (elm); \
  45600. + (head)->sqh_last = &(elm)->field.sqe_next; \
  45601. +} while (0)
  45602. +
  45603. +#define DWC_SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
  45604. + if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\
  45605. + (head)->sqh_last = &(elm)->field.sqe_next; \
  45606. + (listelm)->field.sqe_next = (elm); \
  45607. +} while (0)
  45608. +
  45609. +#define DWC_SIMPLEQ_REMOVE_HEAD(head, field) do { \
  45610. + if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \
  45611. + (head)->sqh_last = &(head)->sqh_first; \
  45612. +} while (0)
  45613. +
  45614. +/*
  45615. + * Tail queue definitions.
  45616. + */
  45617. +#define DWC_TAILQ_HEAD(name, type) \
  45618. +struct name { \
  45619. + struct type *tqh_first; /* first element */ \
  45620. + struct type **tqh_last; /* addr of last next element */ \
  45621. +}
  45622. +
  45623. +#define DWC_TAILQ_HEAD_INITIALIZER(head) \
  45624. + { NULL, &(head).tqh_first }
  45625. +
  45626. +#define DWC_TAILQ_ENTRY(type) \
  45627. +struct { \
  45628. + struct type *tqe_next; /* next element */ \
  45629. + struct type **tqe_prev; /* address of previous next element */ \
  45630. +}
  45631. +
  45632. +/*
  45633. + * tail queue access methods
  45634. + */
  45635. +#define DWC_TAILQ_FIRST(head) ((head)->tqh_first)
  45636. +#define DWC_TAILQ_END(head) NULL
  45637. +#define DWC_TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
  45638. +#define DWC_TAILQ_LAST(head, headname) \
  45639. + (*(((struct headname *)((head)->tqh_last))->tqh_last))
  45640. +/* XXX */
  45641. +#define DWC_TAILQ_PREV(elm, headname, field) \
  45642. + (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
  45643. +#define DWC_TAILQ_EMPTY(head) \
  45644. + (DWC_TAILQ_FIRST(head) == DWC_TAILQ_END(head))
  45645. +
  45646. +#define DWC_TAILQ_FOREACH(var, head, field) \
  45647. + for ((var) = DWC_TAILQ_FIRST(head); \
  45648. + (var) != DWC_TAILQ_END(head); \
  45649. + (var) = DWC_TAILQ_NEXT(var, field))
  45650. +
  45651. +#define DWC_TAILQ_FOREACH_REVERSE(var, head, headname, field) \
  45652. + for ((var) = DWC_TAILQ_LAST(head, headname); \
  45653. + (var) != DWC_TAILQ_END(head); \
  45654. + (var) = DWC_TAILQ_PREV(var, headname, field))
  45655. +
  45656. +/*
  45657. + * Tail queue functions.
  45658. + */
  45659. +#define DWC_TAILQ_INIT(head) do { \
  45660. + (head)->tqh_first = NULL; \
  45661. + (head)->tqh_last = &(head)->tqh_first; \
  45662. +} while (0)
  45663. +
  45664. +#define DWC_TAILQ_INSERT_HEAD(head, elm, field) do { \
  45665. + if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
  45666. + (head)->tqh_first->field.tqe_prev = \
  45667. + &(elm)->field.tqe_next; \
  45668. + else \
  45669. + (head)->tqh_last = &(elm)->field.tqe_next; \
  45670. + (head)->tqh_first = (elm); \
  45671. + (elm)->field.tqe_prev = &(head)->tqh_first; \
  45672. +} while (0)
  45673. +
  45674. +#define DWC_TAILQ_INSERT_TAIL(head, elm, field) do { \
  45675. + (elm)->field.tqe_next = NULL; \
  45676. + (elm)->field.tqe_prev = (head)->tqh_last; \
  45677. + *(head)->tqh_last = (elm); \
  45678. + (head)->tqh_last = &(elm)->field.tqe_next; \
  45679. +} while (0)
  45680. +
  45681. +#define DWC_TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
  45682. + if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
  45683. + (elm)->field.tqe_next->field.tqe_prev = \
  45684. + &(elm)->field.tqe_next; \
  45685. + else \
  45686. + (head)->tqh_last = &(elm)->field.tqe_next; \
  45687. + (listelm)->field.tqe_next = (elm); \
  45688. + (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
  45689. +} while (0)
  45690. +
  45691. +#define DWC_TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
  45692. + (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
  45693. + (elm)->field.tqe_next = (listelm); \
  45694. + *(listelm)->field.tqe_prev = (elm); \
  45695. + (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
  45696. +} while (0)
  45697. +
  45698. +#define DWC_TAILQ_REMOVE(head, elm, field) do { \
  45699. + if (((elm)->field.tqe_next) != NULL) \
  45700. + (elm)->field.tqe_next->field.tqe_prev = \
  45701. + (elm)->field.tqe_prev; \
  45702. + else \
  45703. + (head)->tqh_last = (elm)->field.tqe_prev; \
  45704. + *(elm)->field.tqe_prev = (elm)->field.tqe_next; \
  45705. +} while (0)
  45706. +
  45707. +#define DWC_TAILQ_REPLACE(head, elm, elm2, field) do { \
  45708. + if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL) \
  45709. + (elm2)->field.tqe_next->field.tqe_prev = \
  45710. + &(elm2)->field.tqe_next; \
  45711. + else \
  45712. + (head)->tqh_last = &(elm2)->field.tqe_next; \
  45713. + (elm2)->field.tqe_prev = (elm)->field.tqe_prev; \
  45714. + *(elm2)->field.tqe_prev = (elm2); \
  45715. +} while (0)
  45716. +
  45717. +/*
  45718. + * Circular queue definitions.
  45719. + */
  45720. +#define DWC_CIRCLEQ_HEAD(name, type) \
  45721. +struct name { \
  45722. + struct type *cqh_first; /* first element */ \
  45723. + struct type *cqh_last; /* last element */ \
  45724. +}
  45725. +
  45726. +#define DWC_CIRCLEQ_HEAD_INITIALIZER(head) \
  45727. + { DWC_CIRCLEQ_END(&head), DWC_CIRCLEQ_END(&head) }
  45728. +
  45729. +#define DWC_CIRCLEQ_ENTRY(type) \
  45730. +struct { \
  45731. + struct type *cqe_next; /* next element */ \
  45732. + struct type *cqe_prev; /* previous element */ \
  45733. +}
  45734. +
  45735. +/*
  45736. + * Circular queue access methods
  45737. + */
  45738. +#define DWC_CIRCLEQ_FIRST(head) ((head)->cqh_first)
  45739. +#define DWC_CIRCLEQ_LAST(head) ((head)->cqh_last)
  45740. +#define DWC_CIRCLEQ_END(head) ((void *)(head))
  45741. +#define DWC_CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next)
  45742. +#define DWC_CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev)
  45743. +#define DWC_CIRCLEQ_EMPTY(head) \
  45744. + (DWC_CIRCLEQ_FIRST(head) == DWC_CIRCLEQ_END(head))
  45745. +
  45746. +#define DWC_CIRCLEQ_EMPTY_ENTRY(elm, field) (((elm)->field.cqe_next == NULL) && ((elm)->field.cqe_prev == NULL))
  45747. +
  45748. +#define DWC_CIRCLEQ_FOREACH(var, head, field) \
  45749. + for((var) = DWC_CIRCLEQ_FIRST(head); \
  45750. + (var) != DWC_CIRCLEQ_END(head); \
  45751. + (var) = DWC_CIRCLEQ_NEXT(var, field))
  45752. +
  45753. +#define DWC_CIRCLEQ_FOREACH_SAFE(var, var2, head, field) \
  45754. + for((var) = DWC_CIRCLEQ_FIRST(head), var2 = DWC_CIRCLEQ_NEXT(var, field); \
  45755. + (var) != DWC_CIRCLEQ_END(head); \
  45756. + (var) = var2, var2 = DWC_CIRCLEQ_NEXT(var, field))
  45757. +
  45758. +#define DWC_CIRCLEQ_FOREACH_REVERSE(var, head, field) \
  45759. + for((var) = DWC_CIRCLEQ_LAST(head); \
  45760. + (var) != DWC_CIRCLEQ_END(head); \
  45761. + (var) = DWC_CIRCLEQ_PREV(var, field))
  45762. +
  45763. +/*
  45764. + * Circular queue functions.
  45765. + */
  45766. +#define DWC_CIRCLEQ_INIT(head) do { \
  45767. + (head)->cqh_first = DWC_CIRCLEQ_END(head); \
  45768. + (head)->cqh_last = DWC_CIRCLEQ_END(head); \
  45769. +} while (0)
  45770. +
  45771. +#define DWC_CIRCLEQ_INIT_ENTRY(elm, field) do { \
  45772. + (elm)->field.cqe_next = NULL; \
  45773. + (elm)->field.cqe_prev = NULL; \
  45774. +} while (0)
  45775. +
  45776. +#define DWC_CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
  45777. + (elm)->field.cqe_next = (listelm)->field.cqe_next; \
  45778. + (elm)->field.cqe_prev = (listelm); \
  45779. + if ((listelm)->field.cqe_next == DWC_CIRCLEQ_END(head)) \
  45780. + (head)->cqh_last = (elm); \
  45781. + else \
  45782. + (listelm)->field.cqe_next->field.cqe_prev = (elm); \
  45783. + (listelm)->field.cqe_next = (elm); \
  45784. +} while (0)
  45785. +
  45786. +#define DWC_CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \
  45787. + (elm)->field.cqe_next = (listelm); \
  45788. + (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
  45789. + if ((listelm)->field.cqe_prev == DWC_CIRCLEQ_END(head)) \
  45790. + (head)->cqh_first = (elm); \
  45791. + else \
  45792. + (listelm)->field.cqe_prev->field.cqe_next = (elm); \
  45793. + (listelm)->field.cqe_prev = (elm); \
  45794. +} while (0)
  45795. +
  45796. +#define DWC_CIRCLEQ_INSERT_HEAD(head, elm, field) do { \
  45797. + (elm)->field.cqe_next = (head)->cqh_first; \
  45798. + (elm)->field.cqe_prev = DWC_CIRCLEQ_END(head); \
  45799. + if ((head)->cqh_last == DWC_CIRCLEQ_END(head)) \
  45800. + (head)->cqh_last = (elm); \
  45801. + else \
  45802. + (head)->cqh_first->field.cqe_prev = (elm); \
  45803. + (head)->cqh_first = (elm); \
  45804. +} while (0)
  45805. +
  45806. +#define DWC_CIRCLEQ_INSERT_TAIL(head, elm, field) do { \
  45807. + (elm)->field.cqe_next = DWC_CIRCLEQ_END(head); \
  45808. + (elm)->field.cqe_prev = (head)->cqh_last; \
  45809. + if ((head)->cqh_first == DWC_CIRCLEQ_END(head)) \
  45810. + (head)->cqh_first = (elm); \
  45811. + else \
  45812. + (head)->cqh_last->field.cqe_next = (elm); \
  45813. + (head)->cqh_last = (elm); \
  45814. +} while (0)
  45815. +
  45816. +#define DWC_CIRCLEQ_REMOVE(head, elm, field) do { \
  45817. + if ((elm)->field.cqe_next == DWC_CIRCLEQ_END(head)) \
  45818. + (head)->cqh_last = (elm)->field.cqe_prev; \
  45819. + else \
  45820. + (elm)->field.cqe_next->field.cqe_prev = \
  45821. + (elm)->field.cqe_prev; \
  45822. + if ((elm)->field.cqe_prev == DWC_CIRCLEQ_END(head)) \
  45823. + (head)->cqh_first = (elm)->field.cqe_next; \
  45824. + else \
  45825. + (elm)->field.cqe_prev->field.cqe_next = \
  45826. + (elm)->field.cqe_next; \
  45827. +} while (0)
  45828. +
  45829. +#define DWC_CIRCLEQ_REMOVE_INIT(head, elm, field) do { \
  45830. + DWC_CIRCLEQ_REMOVE(head, elm, field); \
  45831. + DWC_CIRCLEQ_INIT_ENTRY(elm, field); \
  45832. +} while (0)
  45833. +
  45834. +#define DWC_CIRCLEQ_REPLACE(head, elm, elm2, field) do { \
  45835. + if (((elm2)->field.cqe_next = (elm)->field.cqe_next) == \
  45836. + DWC_CIRCLEQ_END(head)) \
  45837. + (head).cqh_last = (elm2); \
  45838. + else \
  45839. + (elm2)->field.cqe_next->field.cqe_prev = (elm2); \
  45840. + if (((elm2)->field.cqe_prev = (elm)->field.cqe_prev) == \
  45841. + DWC_CIRCLEQ_END(head)) \
  45842. + (head).cqh_first = (elm2); \
  45843. + else \
  45844. + (elm2)->field.cqe_prev->field.cqe_next = (elm2); \
  45845. +} while (0)
  45846. +
  45847. +#ifdef __cplusplus
  45848. +}
  45849. +#endif
  45850. +
  45851. +#endif /* _DWC_LIST_H_ */
  45852. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_common_port/dwc_mem.c linux-3.12.26/drivers/usb/host/dwc_common_port/dwc_mem.c
  45853. --- linux-3.12.26.orig/drivers/usb/host/dwc_common_port/dwc_mem.c 1970-01-01 01:00:00.000000000 +0100
  45854. +++ linux-3.12.26/drivers/usb/host/dwc_common_port/dwc_mem.c 2014-08-06 16:50:14.777964537 +0200
  45855. @@ -0,0 +1,245 @@
  45856. +/* Memory Debugging */
  45857. +#ifdef DWC_DEBUG_MEMORY
  45858. +
  45859. +#include "dwc_os.h"
  45860. +#include "dwc_list.h"
  45861. +
  45862. +struct allocation {
  45863. + void *addr;
  45864. + void *ctx;
  45865. + char *func;
  45866. + int line;
  45867. + uint32_t size;
  45868. + int dma;
  45869. + DWC_CIRCLEQ_ENTRY(allocation) entry;
  45870. +};
  45871. +
  45872. +DWC_CIRCLEQ_HEAD(allocation_queue, allocation);
  45873. +
  45874. +struct allocation_manager {
  45875. + void *mem_ctx;
  45876. + struct allocation_queue allocations;
  45877. +
  45878. + /* statistics */
  45879. + int num;
  45880. + int num_freed;
  45881. + int num_active;
  45882. + uint32_t total;
  45883. + uint32_t cur;
  45884. + uint32_t max;
  45885. +};
  45886. +
  45887. +static struct allocation_manager *manager = NULL;
  45888. +
  45889. +static int add_allocation(void *ctx, uint32_t size, char const *func, int line, void *addr,
  45890. + int dma)
  45891. +{
  45892. + struct allocation *a;
  45893. +
  45894. + DWC_ASSERT(manager != NULL, "manager not allocated");
  45895. +
  45896. + a = __DWC_ALLOC_ATOMIC(manager->mem_ctx, sizeof(*a));
  45897. + if (!a) {
  45898. + return -DWC_E_NO_MEMORY;
  45899. + }
  45900. +
  45901. + a->func = __DWC_ALLOC_ATOMIC(manager->mem_ctx, DWC_STRLEN(func) + 1);
  45902. + if (!a->func) {
  45903. + __DWC_FREE(manager->mem_ctx, a);
  45904. + return -DWC_E_NO_MEMORY;
  45905. + }
  45906. +
  45907. + DWC_MEMCPY(a->func, func, DWC_STRLEN(func) + 1);
  45908. + a->addr = addr;
  45909. + a->ctx = ctx;
  45910. + a->line = line;
  45911. + a->size = size;
  45912. + a->dma = dma;
  45913. + DWC_CIRCLEQ_INSERT_TAIL(&manager->allocations, a, entry);
  45914. +
  45915. + /* Update stats */
  45916. + manager->num++;
  45917. + manager->num_active++;
  45918. + manager->total += size;
  45919. + manager->cur += size;
  45920. +
  45921. + if (manager->max < manager->cur) {
  45922. + manager->max = manager->cur;
  45923. + }
  45924. +
  45925. + return 0;
  45926. +}
  45927. +
  45928. +static struct allocation *find_allocation(void *ctx, void *addr)
  45929. +{
  45930. + struct allocation *a;
  45931. +
  45932. + DWC_CIRCLEQ_FOREACH(a, &manager->allocations, entry) {
  45933. + if (a->ctx == ctx && a->addr == addr) {
  45934. + return a;
  45935. + }
  45936. + }
  45937. +
  45938. + return NULL;
  45939. +}
  45940. +
  45941. +static void free_allocation(void *ctx, void *addr, char const *func, int line)
  45942. +{
  45943. + struct allocation *a = find_allocation(ctx, addr);
  45944. +
  45945. + if (!a) {
  45946. + DWC_ASSERT(0,
  45947. + "Free of address %p that was never allocated or already freed %s:%d",
  45948. + addr, func, line);
  45949. + return;
  45950. + }
  45951. +
  45952. + DWC_CIRCLEQ_REMOVE(&manager->allocations, a, entry);
  45953. +
  45954. + manager->num_active--;
  45955. + manager->num_freed++;
  45956. + manager->cur -= a->size;
  45957. + __DWC_FREE(manager->mem_ctx, a->func);
  45958. + __DWC_FREE(manager->mem_ctx, a);
  45959. +}
  45960. +
  45961. +int dwc_memory_debug_start(void *mem_ctx)
  45962. +{
  45963. + DWC_ASSERT(manager == NULL, "Memory debugging has already started\n");
  45964. +
  45965. + if (manager) {
  45966. + return -DWC_E_BUSY;
  45967. + }
  45968. +
  45969. + manager = __DWC_ALLOC(mem_ctx, sizeof(*manager));
  45970. + if (!manager) {
  45971. + return -DWC_E_NO_MEMORY;
  45972. + }
  45973. +
  45974. + DWC_CIRCLEQ_INIT(&manager->allocations);
  45975. + manager->mem_ctx = mem_ctx;
  45976. + manager->num = 0;
  45977. + manager->num_freed = 0;
  45978. + manager->num_active = 0;
  45979. + manager->total = 0;
  45980. + manager->cur = 0;
  45981. + manager->max = 0;
  45982. +
  45983. + return 0;
  45984. +}
  45985. +
  45986. +void dwc_memory_debug_stop(void)
  45987. +{
  45988. + struct allocation *a;
  45989. +
  45990. + dwc_memory_debug_report();
  45991. +
  45992. + DWC_CIRCLEQ_FOREACH(a, &manager->allocations, entry) {
  45993. + DWC_ERROR("Memory leaked from %s:%d\n", a->func, a->line);
  45994. + free_allocation(a->ctx, a->addr, NULL, -1);
  45995. + }
  45996. +
  45997. + __DWC_FREE(manager->mem_ctx, manager);
  45998. +}
  45999. +
  46000. +void dwc_memory_debug_report(void)
  46001. +{
  46002. + struct allocation *a;
  46003. +
  46004. + DWC_PRINTF("\n\n\n----------------- Memory Debugging Report -----------------\n\n");
  46005. + DWC_PRINTF("Num Allocations = %d\n", manager->num);
  46006. + DWC_PRINTF("Freed = %d\n", manager->num_freed);
  46007. + DWC_PRINTF("Active = %d\n", manager->num_active);
  46008. + DWC_PRINTF("Current Memory Used = %d\n", manager->cur);
  46009. + DWC_PRINTF("Total Memory Used = %d\n", manager->total);
  46010. + DWC_PRINTF("Maximum Memory Used at Once = %d\n", manager->max);
  46011. + DWC_PRINTF("Unfreed allocations:\n");
  46012. +
  46013. + DWC_CIRCLEQ_FOREACH(a, &manager->allocations, entry) {
  46014. + DWC_PRINTF(" addr=%p, size=%d from %s:%d, DMA=%d\n",
  46015. + a->addr, a->size, a->func, a->line, a->dma);
  46016. + }
  46017. +}
  46018. +
  46019. +/* The replacement functions */
  46020. +void *dwc_alloc_debug(void *mem_ctx, uint32_t size, char const *func, int line)
  46021. +{
  46022. + void *addr = __DWC_ALLOC(mem_ctx, size);
  46023. +
  46024. + if (!addr) {
  46025. + return NULL;
  46026. + }
  46027. +
  46028. + if (add_allocation(mem_ctx, size, func, line, addr, 0)) {
  46029. + __DWC_FREE(mem_ctx, addr);
  46030. + return NULL;
  46031. + }
  46032. +
  46033. + return addr;
  46034. +}
  46035. +
  46036. +void *dwc_alloc_atomic_debug(void *mem_ctx, uint32_t size, char const *func,
  46037. + int line)
  46038. +{
  46039. + void *addr = __DWC_ALLOC_ATOMIC(mem_ctx, size);
  46040. +
  46041. + if (!addr) {
  46042. + return NULL;
  46043. + }
  46044. +
  46045. + if (add_allocation(mem_ctx, size, func, line, addr, 0)) {
  46046. + __DWC_FREE(mem_ctx, addr);
  46047. + return NULL;
  46048. + }
  46049. +
  46050. + return addr;
  46051. +}
  46052. +
  46053. +void dwc_free_debug(void *mem_ctx, void *addr, char const *func, int line)
  46054. +{
  46055. + free_allocation(mem_ctx, addr, func, line);
  46056. + __DWC_FREE(mem_ctx, addr);
  46057. +}
  46058. +
  46059. +void *dwc_dma_alloc_debug(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr,
  46060. + char const *func, int line)
  46061. +{
  46062. + void *addr = __DWC_DMA_ALLOC(dma_ctx, size, dma_addr);
  46063. +
  46064. + if (!addr) {
  46065. + return NULL;
  46066. + }
  46067. +
  46068. + if (add_allocation(dma_ctx, size, func, line, addr, 1)) {
  46069. + __DWC_DMA_FREE(dma_ctx, size, addr, *dma_addr);
  46070. + return NULL;
  46071. + }
  46072. +
  46073. + return addr;
  46074. +}
  46075. +
  46076. +void *dwc_dma_alloc_atomic_debug(void *dma_ctx, uint32_t size,
  46077. + dwc_dma_t *dma_addr, char const *func, int line)
  46078. +{
  46079. + void *addr = __DWC_DMA_ALLOC_ATOMIC(dma_ctx, size, dma_addr);
  46080. +
  46081. + if (!addr) {
  46082. + return NULL;
  46083. + }
  46084. +
  46085. + if (add_allocation(dma_ctx, size, func, line, addr, 1)) {
  46086. + __DWC_DMA_FREE(dma_ctx, size, addr, *dma_addr);
  46087. + return NULL;
  46088. + }
  46089. +
  46090. + return addr;
  46091. +}
  46092. +
  46093. +void dwc_dma_free_debug(void *dma_ctx, uint32_t size, void *virt_addr,
  46094. + dwc_dma_t dma_addr, char const *func, int line)
  46095. +{
  46096. + free_allocation(dma_ctx, virt_addr, func, line);
  46097. + __DWC_DMA_FREE(dma_ctx, size, virt_addr, dma_addr);
  46098. +}
  46099. +
  46100. +#endif /* DWC_DEBUG_MEMORY */
  46101. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_common_port/dwc_modpow.c linux-3.12.26/drivers/usb/host/dwc_common_port/dwc_modpow.c
  46102. --- linux-3.12.26.orig/drivers/usb/host/dwc_common_port/dwc_modpow.c 1970-01-01 01:00:00.000000000 +0100
  46103. +++ linux-3.12.26/drivers/usb/host/dwc_common_port/dwc_modpow.c 2014-08-06 16:50:14.777964537 +0200
  46104. @@ -0,0 +1,636 @@
  46105. +/* Bignum routines adapted from PUTTY sources. PuTTY copyright notice follows.
  46106. + *
  46107. + * PuTTY is copyright 1997-2007 Simon Tatham.
  46108. + *
  46109. + * Portions copyright Robert de Bath, Joris van Rantwijk, Delian
  46110. + * Delchev, Andreas Schultz, Jeroen Massar, Wez Furlong, Nicolas Barry,
  46111. + * Justin Bradford, Ben Harris, Malcolm Smith, Ahmad Khalifa, Markus
  46112. + * Kuhn, and CORE SDI S.A.
  46113. + *
  46114. + * Permission is hereby granted, free of charge, to any person
  46115. + * obtaining a copy of this software and associated documentation files
  46116. + * (the "Software"), to deal in the Software without restriction,
  46117. + * including without limitation the rights to use, copy, modify, merge,
  46118. + * publish, distribute, sublicense, and/or sell copies of the Software,
  46119. + * and to permit persons to whom the Software is furnished to do so,
  46120. + * subject to the following conditions:
  46121. + *
  46122. + * The above copyright notice and this permission notice shall be
  46123. + * included in all copies or substantial portions of the Software.
  46124. +
  46125. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  46126. + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  46127. + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  46128. + * NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE
  46129. + * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  46130. + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  46131. + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  46132. + *
  46133. + */
  46134. +#ifdef DWC_CRYPTOLIB
  46135. +
  46136. +#ifndef CONFIG_MACH_IPMATE
  46137. +
  46138. +#include "dwc_modpow.h"
  46139. +
  46140. +#define BIGNUM_INT_MASK 0xFFFFFFFFUL
  46141. +#define BIGNUM_TOP_BIT 0x80000000UL
  46142. +#define BIGNUM_INT_BITS 32
  46143. +
  46144. +
  46145. +static void *snmalloc(void *mem_ctx, size_t n, size_t size)
  46146. +{
  46147. + void *p;
  46148. + size *= n;
  46149. + if (size == 0) size = 1;
  46150. + p = dwc_alloc(mem_ctx, size);
  46151. + return p;
  46152. +}
  46153. +
  46154. +#define snewn(ctx, n, type) ((type *)snmalloc((ctx), (n), sizeof(type)))
  46155. +#define sfree dwc_free
  46156. +
  46157. +/*
  46158. + * Usage notes:
  46159. + * * Do not call the DIVMOD_WORD macro with expressions such as array
  46160. + * subscripts, as some implementations object to this (see below).
  46161. + * * Note that none of the division methods below will cope if the
  46162. + * quotient won't fit into BIGNUM_INT_BITS. Callers should be careful
  46163. + * to avoid this case.
  46164. + * If this condition occurs, in the case of the x86 DIV instruction,
  46165. + * an overflow exception will occur, which (according to a correspondent)
  46166. + * will manifest on Windows as something like
  46167. + * 0xC0000095: Integer overflow
  46168. + * The C variant won't give the right answer, either.
  46169. + */
  46170. +
  46171. +#define MUL_WORD(w1, w2) ((BignumDblInt)w1 * w2)
  46172. +
  46173. +#if defined __GNUC__ && defined __i386__
  46174. +#define DIVMOD_WORD(q, r, hi, lo, w) \
  46175. + __asm__("div %2" : \
  46176. + "=d" (r), "=a" (q) : \
  46177. + "r" (w), "d" (hi), "a" (lo))
  46178. +#else
  46179. +#define DIVMOD_WORD(q, r, hi, lo, w) do { \
  46180. + BignumDblInt n = (((BignumDblInt)hi) << BIGNUM_INT_BITS) | lo; \
  46181. + q = n / w; \
  46182. + r = n % w; \
  46183. +} while (0)
  46184. +#endif
  46185. +
  46186. +// q = n / w;
  46187. +// r = n % w;
  46188. +
  46189. +#define BIGNUM_INT_BYTES (BIGNUM_INT_BITS / 8)
  46190. +
  46191. +#define BIGNUM_INTERNAL
  46192. +
  46193. +static Bignum newbn(void *mem_ctx, int length)
  46194. +{
  46195. + Bignum b = snewn(mem_ctx, length + 1, BignumInt);
  46196. + //if (!b)
  46197. + //abort(); /* FIXME */
  46198. + DWC_MEMSET(b, 0, (length + 1) * sizeof(*b));
  46199. + b[0] = length;
  46200. + return b;
  46201. +}
  46202. +
  46203. +void freebn(void *mem_ctx, Bignum b)
  46204. +{
  46205. + /*
  46206. + * Burn the evidence, just in case.
  46207. + */
  46208. + DWC_MEMSET(b, 0, sizeof(b[0]) * (b[0] + 1));
  46209. + sfree(mem_ctx, b);
  46210. +}
  46211. +
  46212. +/*
  46213. + * Compute c = a * b.
  46214. + * Input is in the first len words of a and b.
  46215. + * Result is returned in the first 2*len words of c.
  46216. + */
  46217. +static void internal_mul(BignumInt *a, BignumInt *b,
  46218. + BignumInt *c, int len)
  46219. +{
  46220. + int i, j;
  46221. + BignumDblInt t;
  46222. +
  46223. + for (j = 0; j < 2 * len; j++)
  46224. + c[j] = 0;
  46225. +
  46226. + for (i = len - 1; i >= 0; i--) {
  46227. + t = 0;
  46228. + for (j = len - 1; j >= 0; j--) {
  46229. + t += MUL_WORD(a[i], (BignumDblInt) b[j]);
  46230. + t += (BignumDblInt) c[i + j + 1];
  46231. + c[i + j + 1] = (BignumInt) t;
  46232. + t = t >> BIGNUM_INT_BITS;
  46233. + }
  46234. + c[i] = (BignumInt) t;
  46235. + }
  46236. +}
  46237. +
  46238. +static void internal_add_shifted(BignumInt *number,
  46239. + unsigned n, int shift)
  46240. +{
  46241. + int word = 1 + (shift / BIGNUM_INT_BITS);
  46242. + int bshift = shift % BIGNUM_INT_BITS;
  46243. + BignumDblInt addend;
  46244. +
  46245. + addend = (BignumDblInt)n << bshift;
  46246. +
  46247. + while (addend) {
  46248. + addend += number[word];
  46249. + number[word] = (BignumInt) addend & BIGNUM_INT_MASK;
  46250. + addend >>= BIGNUM_INT_BITS;
  46251. + word++;
  46252. + }
  46253. +}
  46254. +
  46255. +/*
  46256. + * Compute a = a % m.
  46257. + * Input in first alen words of a and first mlen words of m.
  46258. + * Output in first alen words of a
  46259. + * (of which first alen-mlen words will be zero).
  46260. + * The MSW of m MUST have its high bit set.
  46261. + * Quotient is accumulated in the `quotient' array, which is a Bignum
  46262. + * rather than the internal bigendian format. Quotient parts are shifted
  46263. + * left by `qshift' before adding into quot.
  46264. + */
  46265. +static void internal_mod(BignumInt *a, int alen,
  46266. + BignumInt *m, int mlen,
  46267. + BignumInt *quot, int qshift)
  46268. +{
  46269. + BignumInt m0, m1;
  46270. + unsigned int h;
  46271. + int i, k;
  46272. +
  46273. + m0 = m[0];
  46274. + if (mlen > 1)
  46275. + m1 = m[1];
  46276. + else
  46277. + m1 = 0;
  46278. +
  46279. + for (i = 0; i <= alen - mlen; i++) {
  46280. + BignumDblInt t;
  46281. + unsigned int q, r, c, ai1;
  46282. +
  46283. + if (i == 0) {
  46284. + h = 0;
  46285. + } else {
  46286. + h = a[i - 1];
  46287. + a[i - 1] = 0;
  46288. + }
  46289. +
  46290. + if (i == alen - 1)
  46291. + ai1 = 0;
  46292. + else
  46293. + ai1 = a[i + 1];
  46294. +
  46295. + /* Find q = h:a[i] / m0 */
  46296. + if (h >= m0) {
  46297. + /*
  46298. + * Special case.
  46299. + *
  46300. + * To illustrate it, suppose a BignumInt is 8 bits, and
  46301. + * we are dividing (say) A1:23:45:67 by A1:B2:C3. Then
  46302. + * our initial division will be 0xA123 / 0xA1, which
  46303. + * will give a quotient of 0x100 and a divide overflow.
  46304. + * However, the invariants in this division algorithm
  46305. + * are not violated, since the full number A1:23:... is
  46306. + * _less_ than the quotient prefix A1:B2:... and so the
  46307. + * following correction loop would have sorted it out.
  46308. + *
  46309. + * In this situation we set q to be the largest
  46310. + * quotient we _can_ stomach (0xFF, of course).
  46311. + */
  46312. + q = BIGNUM_INT_MASK;
  46313. + } else {
  46314. + /* Macro doesn't want an array subscript expression passed
  46315. + * into it (see definition), so use a temporary. */
  46316. + BignumInt tmplo = a[i];
  46317. + DIVMOD_WORD(q, r, h, tmplo, m0);
  46318. +
  46319. + /* Refine our estimate of q by looking at
  46320. + h:a[i]:a[i+1] / m0:m1 */
  46321. + t = MUL_WORD(m1, q);
  46322. + if (t > ((BignumDblInt) r << BIGNUM_INT_BITS) + ai1) {
  46323. + q--;
  46324. + t -= m1;
  46325. + r = (r + m0) & BIGNUM_INT_MASK; /* overflow? */
  46326. + if (r >= (BignumDblInt) m0 &&
  46327. + t > ((BignumDblInt) r << BIGNUM_INT_BITS) + ai1) q--;
  46328. + }
  46329. + }
  46330. +
  46331. + /* Subtract q * m from a[i...] */
  46332. + c = 0;
  46333. + for (k = mlen - 1; k >= 0; k--) {
  46334. + t = MUL_WORD(q, m[k]);
  46335. + t += c;
  46336. + c = (unsigned)(t >> BIGNUM_INT_BITS);
  46337. + if ((BignumInt) t > a[i + k])
  46338. + c++;
  46339. + a[i + k] -= (BignumInt) t;
  46340. + }
  46341. +
  46342. + /* Add back m in case of borrow */
  46343. + if (c != h) {
  46344. + t = 0;
  46345. + for (k = mlen - 1; k >= 0; k--) {
  46346. + t += m[k];
  46347. + t += a[i + k];
  46348. + a[i + k] = (BignumInt) t;
  46349. + t = t >> BIGNUM_INT_BITS;
  46350. + }
  46351. + q--;
  46352. + }
  46353. + if (quot)
  46354. + internal_add_shifted(quot, q, qshift + BIGNUM_INT_BITS * (alen - mlen - i));
  46355. + }
  46356. +}
  46357. +
  46358. +/*
  46359. + * Compute p % mod.
  46360. + * The most significant word of mod MUST be non-zero.
  46361. + * We assume that the result array is the same size as the mod array.
  46362. + * We optionally write out a quotient if `quotient' is non-NULL.
  46363. + * We can avoid writing out the result if `result' is NULL.
  46364. + */
  46365. +void bigdivmod(void *mem_ctx, Bignum p, Bignum mod, Bignum result, Bignum quotient)
  46366. +{
  46367. + BignumInt *n, *m;
  46368. + int mshift;
  46369. + int plen, mlen, i, j;
  46370. +
  46371. + /* Allocate m of size mlen, copy mod to m */
  46372. + /* We use big endian internally */
  46373. + mlen = mod[0];
  46374. + m = snewn(mem_ctx, mlen, BignumInt);
  46375. + //if (!m)
  46376. + //abort(); /* FIXME */
  46377. + for (j = 0; j < mlen; j++)
  46378. + m[j] = mod[mod[0] - j];
  46379. +
  46380. + /* Shift m left to make msb bit set */
  46381. + for (mshift = 0; mshift < BIGNUM_INT_BITS-1; mshift++)
  46382. + if ((m[0] << mshift) & BIGNUM_TOP_BIT)
  46383. + break;
  46384. + if (mshift) {
  46385. + for (i = 0; i < mlen - 1; i++)
  46386. + m[i] = (m[i] << mshift) | (m[i + 1] >> (BIGNUM_INT_BITS - mshift));
  46387. + m[mlen - 1] = m[mlen - 1] << mshift;
  46388. + }
  46389. +
  46390. + plen = p[0];
  46391. + /* Ensure plen > mlen */
  46392. + if (plen <= mlen)
  46393. + plen = mlen + 1;
  46394. +
  46395. + /* Allocate n of size plen, copy p to n */
  46396. + n = snewn(mem_ctx, plen, BignumInt);
  46397. + //if (!n)
  46398. + //abort(); /* FIXME */
  46399. + for (j = 0; j < plen; j++)
  46400. + n[j] = 0;
  46401. + for (j = 1; j <= (int)p[0]; j++)
  46402. + n[plen - j] = p[j];
  46403. +
  46404. + /* Main computation */
  46405. + internal_mod(n, plen, m, mlen, quotient, mshift);
  46406. +
  46407. + /* Fixup result in case the modulus was shifted */
  46408. + if (mshift) {
  46409. + for (i = plen - mlen - 1; i < plen - 1; i++)
  46410. + n[i] = (n[i] << mshift) | (n[i + 1] >> (BIGNUM_INT_BITS - mshift));
  46411. + n[plen - 1] = n[plen - 1] << mshift;
  46412. + internal_mod(n, plen, m, mlen, quotient, 0);
  46413. + for (i = plen - 1; i >= plen - mlen; i--)
  46414. + n[i] = (n[i] >> mshift) | (n[i - 1] << (BIGNUM_INT_BITS - mshift));
  46415. + }
  46416. +
  46417. + /* Copy result to buffer */
  46418. + if (result) {
  46419. + for (i = 1; i <= (int)result[0]; i++) {
  46420. + int j = plen - i;
  46421. + result[i] = j >= 0 ? n[j] : 0;
  46422. + }
  46423. + }
  46424. +
  46425. + /* Free temporary arrays */
  46426. + for (i = 0; i < mlen; i++)
  46427. + m[i] = 0;
  46428. + sfree(mem_ctx, m);
  46429. + for (i = 0; i < plen; i++)
  46430. + n[i] = 0;
  46431. + sfree(mem_ctx, n);
  46432. +}
  46433. +
  46434. +/*
  46435. + * Simple remainder.
  46436. + */
  46437. +Bignum bigmod(void *mem_ctx, Bignum a, Bignum b)
  46438. +{
  46439. + Bignum r = newbn(mem_ctx, b[0]);
  46440. + bigdivmod(mem_ctx, a, b, r, NULL);
  46441. + return r;
  46442. +}
  46443. +
  46444. +/*
  46445. + * Compute (base ^ exp) % mod.
  46446. + */
  46447. +Bignum dwc_modpow(void *mem_ctx, Bignum base_in, Bignum exp, Bignum mod)
  46448. +{
  46449. + BignumInt *a, *b, *n, *m;
  46450. + int mshift;
  46451. + int mlen, i, j;
  46452. + Bignum base, result;
  46453. +
  46454. + /*
  46455. + * The most significant word of mod needs to be non-zero. It
  46456. + * should already be, but let's make sure.
  46457. + */
  46458. + //assert(mod[mod[0]] != 0);
  46459. +
  46460. + /*
  46461. + * Make sure the base is smaller than the modulus, by reducing
  46462. + * it modulo the modulus if not.
  46463. + */
  46464. + base = bigmod(mem_ctx, base_in, mod);
  46465. +
  46466. + /* Allocate m of size mlen, copy mod to m */
  46467. + /* We use big endian internally */
  46468. + mlen = mod[0];
  46469. + m = snewn(mem_ctx, mlen, BignumInt);
  46470. + //if (!m)
  46471. + //abort(); /* FIXME */
  46472. + for (j = 0; j < mlen; j++)
  46473. + m[j] = mod[mod[0] - j];
  46474. +
  46475. + /* Shift m left to make msb bit set */
  46476. + for (mshift = 0; mshift < BIGNUM_INT_BITS - 1; mshift++)
  46477. + if ((m[0] << mshift) & BIGNUM_TOP_BIT)
  46478. + break;
  46479. + if (mshift) {
  46480. + for (i = 0; i < mlen - 1; i++)
  46481. + m[i] =
  46482. + (m[i] << mshift) | (m[i + 1] >>
  46483. + (BIGNUM_INT_BITS - mshift));
  46484. + m[mlen - 1] = m[mlen - 1] << mshift;
  46485. + }
  46486. +
  46487. + /* Allocate n of size mlen, copy base to n */
  46488. + n = snewn(mem_ctx, mlen, BignumInt);
  46489. + //if (!n)
  46490. + //abort(); /* FIXME */
  46491. + i = mlen - base[0];
  46492. + for (j = 0; j < i; j++)
  46493. + n[j] = 0;
  46494. + for (j = 0; j < base[0]; j++)
  46495. + n[i + j] = base[base[0] - j];
  46496. +
  46497. + /* Allocate a and b of size 2*mlen. Set a = 1 */
  46498. + a = snewn(mem_ctx, 2 * mlen, BignumInt);
  46499. + //if (!a)
  46500. + //abort(); /* FIXME */
  46501. + b = snewn(mem_ctx, 2 * mlen, BignumInt);
  46502. + //if (!b)
  46503. + //abort(); /* FIXME */
  46504. + for (i = 0; i < 2 * mlen; i++)
  46505. + a[i] = 0;
  46506. + a[2 * mlen - 1] = 1;
  46507. +
  46508. + /* Skip leading zero bits of exp. */
  46509. + i = 0;
  46510. + j = BIGNUM_INT_BITS - 1;
  46511. + while (i < exp[0] && (exp[exp[0] - i] & (1 << j)) == 0) {
  46512. + j--;
  46513. + if (j < 0) {
  46514. + i++;
  46515. + j = BIGNUM_INT_BITS - 1;
  46516. + }
  46517. + }
  46518. +
  46519. + /* Main computation */
  46520. + while (i < exp[0]) {
  46521. + while (j >= 0) {
  46522. + internal_mul(a + mlen, a + mlen, b, mlen);
  46523. + internal_mod(b, mlen * 2, m, mlen, NULL, 0);
  46524. + if ((exp[exp[0] - i] & (1 << j)) != 0) {
  46525. + internal_mul(b + mlen, n, a, mlen);
  46526. + internal_mod(a, mlen * 2, m, mlen, NULL, 0);
  46527. + } else {
  46528. + BignumInt *t;
  46529. + t = a;
  46530. + a = b;
  46531. + b = t;
  46532. + }
  46533. + j--;
  46534. + }
  46535. + i++;
  46536. + j = BIGNUM_INT_BITS - 1;
  46537. + }
  46538. +
  46539. + /* Fixup result in case the modulus was shifted */
  46540. + if (mshift) {
  46541. + for (i = mlen - 1; i < 2 * mlen - 1; i++)
  46542. + a[i] =
  46543. + (a[i] << mshift) | (a[i + 1] >>
  46544. + (BIGNUM_INT_BITS - mshift));
  46545. + a[2 * mlen - 1] = a[2 * mlen - 1] << mshift;
  46546. + internal_mod(a, mlen * 2, m, mlen, NULL, 0);
  46547. + for (i = 2 * mlen - 1; i >= mlen; i--)
  46548. + a[i] =
  46549. + (a[i] >> mshift) | (a[i - 1] <<
  46550. + (BIGNUM_INT_BITS - mshift));
  46551. + }
  46552. +
  46553. + /* Copy result to buffer */
  46554. + result = newbn(mem_ctx, mod[0]);
  46555. + for (i = 0; i < mlen; i++)
  46556. + result[result[0] - i] = a[i + mlen];
  46557. + while (result[0] > 1 && result[result[0]] == 0)
  46558. + result[0]--;
  46559. +
  46560. + /* Free temporary arrays */
  46561. + for (i = 0; i < 2 * mlen; i++)
  46562. + a[i] = 0;
  46563. + sfree(mem_ctx, a);
  46564. + for (i = 0; i < 2 * mlen; i++)
  46565. + b[i] = 0;
  46566. + sfree(mem_ctx, b);
  46567. + for (i = 0; i < mlen; i++)
  46568. + m[i] = 0;
  46569. + sfree(mem_ctx, m);
  46570. + for (i = 0; i < mlen; i++)
  46571. + n[i] = 0;
  46572. + sfree(mem_ctx, n);
  46573. +
  46574. + freebn(mem_ctx, base);
  46575. +
  46576. + return result;
  46577. +}
  46578. +
  46579. +
  46580. +#ifdef UNITTEST
  46581. +
  46582. +static __u32 dh_p[] = {
  46583. + 96,
  46584. + 0xFFFFFFFF,
  46585. + 0xFFFFFFFF,
  46586. + 0xA93AD2CA,
  46587. + 0x4B82D120,
  46588. + 0xE0FD108E,
  46589. + 0x43DB5BFC,
  46590. + 0x74E5AB31,
  46591. + 0x08E24FA0,
  46592. + 0xBAD946E2,
  46593. + 0x770988C0,
  46594. + 0x7A615D6C,
  46595. + 0xBBE11757,
  46596. + 0x177B200C,
  46597. + 0x521F2B18,
  46598. + 0x3EC86A64,
  46599. + 0xD8760273,
  46600. + 0xD98A0864,
  46601. + 0xF12FFA06,
  46602. + 0x1AD2EE6B,
  46603. + 0xCEE3D226,
  46604. + 0x4A25619D,
  46605. + 0x1E8C94E0,
  46606. + 0xDB0933D7,
  46607. + 0xABF5AE8C,
  46608. + 0xA6E1E4C7,
  46609. + 0xB3970F85,
  46610. + 0x5D060C7D,
  46611. + 0x8AEA7157,
  46612. + 0x58DBEF0A,
  46613. + 0xECFB8504,
  46614. + 0xDF1CBA64,
  46615. + 0xA85521AB,
  46616. + 0x04507A33,
  46617. + 0xAD33170D,
  46618. + 0x8AAAC42D,
  46619. + 0x15728E5A,
  46620. + 0x98FA0510,
  46621. + 0x15D22618,
  46622. + 0xEA956AE5,
  46623. + 0x3995497C,
  46624. + 0x95581718,
  46625. + 0xDE2BCBF6,
  46626. + 0x6F4C52C9,
  46627. + 0xB5C55DF0,
  46628. + 0xEC07A28F,
  46629. + 0x9B2783A2,
  46630. + 0x180E8603,
  46631. + 0xE39E772C,
  46632. + 0x2E36CE3B,
  46633. + 0x32905E46,
  46634. + 0xCA18217C,
  46635. + 0xF1746C08,
  46636. + 0x4ABC9804,
  46637. + 0x670C354E,
  46638. + 0x7096966D,
  46639. + 0x9ED52907,
  46640. + 0x208552BB,
  46641. + 0x1C62F356,
  46642. + 0xDCA3AD96,
  46643. + 0x83655D23,
  46644. + 0xFD24CF5F,
  46645. + 0x69163FA8,
  46646. + 0x1C55D39A,
  46647. + 0x98DA4836,
  46648. + 0xA163BF05,
  46649. + 0xC2007CB8,
  46650. + 0xECE45B3D,
  46651. + 0x49286651,
  46652. + 0x7C4B1FE6,
  46653. + 0xAE9F2411,
  46654. + 0x5A899FA5,
  46655. + 0xEE386BFB,
  46656. + 0xF406B7ED,
  46657. + 0x0BFF5CB6,
  46658. + 0xA637ED6B,
  46659. + 0xF44C42E9,
  46660. + 0x625E7EC6,
  46661. + 0xE485B576,
  46662. + 0x6D51C245,
  46663. + 0x4FE1356D,
  46664. + 0xF25F1437,
  46665. + 0x302B0A6D,
  46666. + 0xCD3A431B,
  46667. + 0xEF9519B3,
  46668. + 0x8E3404DD,
  46669. + 0x514A0879,
  46670. + 0x3B139B22,
  46671. + 0x020BBEA6,
  46672. + 0x8A67CC74,
  46673. + 0x29024E08,
  46674. + 0x80DC1CD1,
  46675. + 0xC4C6628B,
  46676. + 0x2168C234,
  46677. + 0xC90FDAA2,
  46678. + 0xFFFFFFFF,
  46679. + 0xFFFFFFFF,
  46680. +};
  46681. +
  46682. +static __u32 dh_a[] = {
  46683. + 8,
  46684. + 0xdf367516,
  46685. + 0x86459caa,
  46686. + 0xe2d459a4,
  46687. + 0xd910dae0,
  46688. + 0x8a8b5e37,
  46689. + 0x67ab31c6,
  46690. + 0xf0b55ea9,
  46691. + 0x440051d6,
  46692. +};
  46693. +
  46694. +static __u32 dh_b[] = {
  46695. + 8,
  46696. + 0xded92656,
  46697. + 0xe07a048a,
  46698. + 0x6fa452cd,
  46699. + 0x2df89d30,
  46700. + 0xc75f1b0f,
  46701. + 0x8ce3578f,
  46702. + 0x7980a324,
  46703. + 0x5daec786,
  46704. +};
  46705. +
  46706. +static __u32 dh_g[] = {
  46707. + 1,
  46708. + 2,
  46709. +};
  46710. +
  46711. +int main(void)
  46712. +{
  46713. + int i;
  46714. + __u32 *k;
  46715. + k = dwc_modpow(NULL, dh_g, dh_a, dh_p);
  46716. +
  46717. + printf("\n\n");
  46718. + for (i=0; i<k[0]; i++) {
  46719. + __u32 word32 = k[k[0] - i];
  46720. + __u16 l = word32 & 0xffff;
  46721. + __u16 m = (word32 & 0xffff0000) >> 16;
  46722. + printf("%04x %04x ", m, l);
  46723. + if (!((i + 1)%13)) printf("\n");
  46724. + }
  46725. + printf("\n\n");
  46726. +
  46727. + if ((k[0] == 0x60) && (k[1] == 0x28e490e5) && (k[0x60] == 0x5a0d3d4e)) {
  46728. + printf("PASS\n\n");
  46729. + }
  46730. + else {
  46731. + printf("FAIL\n\n");
  46732. + }
  46733. +
  46734. +}
  46735. +
  46736. +#endif /* UNITTEST */
  46737. +
  46738. +#endif /* CONFIG_MACH_IPMATE */
  46739. +
  46740. +#endif /*DWC_CRYPTOLIB */
  46741. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_common_port/dwc_modpow.h linux-3.12.26/drivers/usb/host/dwc_common_port/dwc_modpow.h
  46742. --- linux-3.12.26.orig/drivers/usb/host/dwc_common_port/dwc_modpow.h 1970-01-01 01:00:00.000000000 +0100
  46743. +++ linux-3.12.26/drivers/usb/host/dwc_common_port/dwc_modpow.h 2014-08-06 16:50:14.777964537 +0200
  46744. @@ -0,0 +1,34 @@
  46745. +/*
  46746. + * dwc_modpow.h
  46747. + * See dwc_modpow.c for license and changes
  46748. + */
  46749. +#ifndef _DWC_MODPOW_H
  46750. +#define _DWC_MODPOW_H
  46751. +
  46752. +#ifdef __cplusplus
  46753. +extern "C" {
  46754. +#endif
  46755. +
  46756. +#include "dwc_os.h"
  46757. +
  46758. +/** @file
  46759. + *
  46760. + * This file defines the module exponentiation function which is only used
  46761. + * internally by the DWC UWB modules for calculation of PKs during numeric
  46762. + * association. The routine is taken from the PUTTY, an open source terminal
  46763. + * emulator. The PUTTY License is preserved in the dwc_modpow.c file.
  46764. + *
  46765. + */
  46766. +
  46767. +typedef uint32_t BignumInt;
  46768. +typedef uint64_t BignumDblInt;
  46769. +typedef BignumInt *Bignum;
  46770. +
  46771. +/* Compute modular exponentiaion */
  46772. +extern Bignum dwc_modpow(void *mem_ctx, Bignum base_in, Bignum exp, Bignum mod);
  46773. +
  46774. +#ifdef __cplusplus
  46775. +}
  46776. +#endif
  46777. +
  46778. +#endif /* _LINUX_BIGNUM_H */
  46779. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_common_port/dwc_notifier.c linux-3.12.26/drivers/usb/host/dwc_common_port/dwc_notifier.c
  46780. --- linux-3.12.26.orig/drivers/usb/host/dwc_common_port/dwc_notifier.c 1970-01-01 01:00:00.000000000 +0100
  46781. +++ linux-3.12.26/drivers/usb/host/dwc_common_port/dwc_notifier.c 2014-08-06 16:50:14.777964537 +0200
  46782. @@ -0,0 +1,319 @@
  46783. +#ifdef DWC_NOTIFYLIB
  46784. +
  46785. +#include "dwc_notifier.h"
  46786. +#include "dwc_list.h"
  46787. +
  46788. +typedef struct dwc_observer {
  46789. + void *observer;
  46790. + dwc_notifier_callback_t callback;
  46791. + void *data;
  46792. + char *notification;
  46793. + DWC_CIRCLEQ_ENTRY(dwc_observer) list_entry;
  46794. +} observer_t;
  46795. +
  46796. +DWC_CIRCLEQ_HEAD(observer_queue, dwc_observer);
  46797. +
  46798. +typedef struct dwc_notifier {
  46799. + void *mem_ctx;
  46800. + void *object;
  46801. + struct observer_queue observers;
  46802. + DWC_CIRCLEQ_ENTRY(dwc_notifier) list_entry;
  46803. +} notifier_t;
  46804. +
  46805. +DWC_CIRCLEQ_HEAD(notifier_queue, dwc_notifier);
  46806. +
  46807. +typedef struct manager {
  46808. + void *mem_ctx;
  46809. + void *wkq_ctx;
  46810. + dwc_workq_t *wq;
  46811. +// dwc_mutex_t *mutex;
  46812. + struct notifier_queue notifiers;
  46813. +} manager_t;
  46814. +
  46815. +static manager_t *manager = NULL;
  46816. +
  46817. +static int create_manager(void *mem_ctx, void *wkq_ctx)
  46818. +{
  46819. + manager = dwc_alloc(mem_ctx, sizeof(manager_t));
  46820. + if (!manager) {
  46821. + return -DWC_E_NO_MEMORY;
  46822. + }
  46823. +
  46824. + DWC_CIRCLEQ_INIT(&manager->notifiers);
  46825. +
  46826. + manager->wq = dwc_workq_alloc(wkq_ctx, "DWC Notification WorkQ");
  46827. + if (!manager->wq) {
  46828. + return -DWC_E_NO_MEMORY;
  46829. + }
  46830. +
  46831. + return 0;
  46832. +}
  46833. +
  46834. +static void free_manager(void)
  46835. +{
  46836. + dwc_workq_free(manager->wq);
  46837. +
  46838. + /* All notifiers must have unregistered themselves before this module
  46839. + * can be removed. Hitting this assertion indicates a programmer
  46840. + * error. */
  46841. + DWC_ASSERT(DWC_CIRCLEQ_EMPTY(&manager->notifiers),
  46842. + "Notification manager being freed before all notifiers have been removed");
  46843. + dwc_free(manager->mem_ctx, manager);
  46844. +}
  46845. +
  46846. +#ifdef DEBUG
  46847. +static void dump_manager(void)
  46848. +{
  46849. + notifier_t *n;
  46850. + observer_t *o;
  46851. +
  46852. + DWC_ASSERT(manager, "Notification manager not found");
  46853. +
  46854. + DWC_DEBUG("List of all notifiers and observers:\n");
  46855. + DWC_CIRCLEQ_FOREACH(n, &manager->notifiers, list_entry) {
  46856. + DWC_DEBUG("Notifier %p has observers:\n", n->object);
  46857. + DWC_CIRCLEQ_FOREACH(o, &n->observers, list_entry) {
  46858. + DWC_DEBUG(" %p watching %s\n", o->observer, o->notification);
  46859. + }
  46860. + }
  46861. +}
  46862. +#else
  46863. +#define dump_manager(...)
  46864. +#endif
  46865. +
  46866. +static observer_t *alloc_observer(void *mem_ctx, void *observer, char *notification,
  46867. + dwc_notifier_callback_t callback, void *data)
  46868. +{
  46869. + observer_t *new_observer = dwc_alloc(mem_ctx, sizeof(observer_t));
  46870. +
  46871. + if (!new_observer) {
  46872. + return NULL;
  46873. + }
  46874. +
  46875. + DWC_CIRCLEQ_INIT_ENTRY(new_observer, list_entry);
  46876. + new_observer->observer = observer;
  46877. + new_observer->notification = notification;
  46878. + new_observer->callback = callback;
  46879. + new_observer->data = data;
  46880. + return new_observer;
  46881. +}
  46882. +
  46883. +static void free_observer(void *mem_ctx, observer_t *observer)
  46884. +{
  46885. + dwc_free(mem_ctx, observer);
  46886. +}
  46887. +
  46888. +static notifier_t *alloc_notifier(void *mem_ctx, void *object)
  46889. +{
  46890. + notifier_t *notifier;
  46891. +
  46892. + if (!object) {
  46893. + return NULL;
  46894. + }
  46895. +
  46896. + notifier = dwc_alloc(mem_ctx, sizeof(notifier_t));
  46897. + if (!notifier) {
  46898. + return NULL;
  46899. + }
  46900. +
  46901. + DWC_CIRCLEQ_INIT(&notifier->observers);
  46902. + DWC_CIRCLEQ_INIT_ENTRY(notifier, list_entry);
  46903. +
  46904. + notifier->mem_ctx = mem_ctx;
  46905. + notifier->object = object;
  46906. + return notifier;
  46907. +}
  46908. +
  46909. +static void free_notifier(notifier_t *notifier)
  46910. +{
  46911. + observer_t *observer;
  46912. +
  46913. + DWC_CIRCLEQ_FOREACH(observer, &notifier->observers, list_entry) {
  46914. + free_observer(notifier->mem_ctx, observer);
  46915. + }
  46916. +
  46917. + dwc_free(notifier->mem_ctx, notifier);
  46918. +}
  46919. +
  46920. +static notifier_t *find_notifier(void *object)
  46921. +{
  46922. + notifier_t *notifier;
  46923. +
  46924. + DWC_ASSERT(manager, "Notification manager not found");
  46925. +
  46926. + if (!object) {
  46927. + return NULL;
  46928. + }
  46929. +
  46930. + DWC_CIRCLEQ_FOREACH(notifier, &manager->notifiers, list_entry) {
  46931. + if (notifier->object == object) {
  46932. + return notifier;
  46933. + }
  46934. + }
  46935. +
  46936. + return NULL;
  46937. +}
  46938. +
  46939. +int dwc_alloc_notification_manager(void *mem_ctx, void *wkq_ctx)
  46940. +{
  46941. + return create_manager(mem_ctx, wkq_ctx);
  46942. +}
  46943. +
  46944. +void dwc_free_notification_manager(void)
  46945. +{
  46946. + free_manager();
  46947. +}
  46948. +
  46949. +dwc_notifier_t *dwc_register_notifier(void *mem_ctx, void *object)
  46950. +{
  46951. + notifier_t *notifier;
  46952. +
  46953. + DWC_ASSERT(manager, "Notification manager not found");
  46954. +
  46955. + notifier = find_notifier(object);
  46956. + if (notifier) {
  46957. + DWC_ERROR("Notifier %p is already registered\n", object);
  46958. + return NULL;
  46959. + }
  46960. +
  46961. + notifier = alloc_notifier(mem_ctx, object);
  46962. + if (!notifier) {
  46963. + return NULL;
  46964. + }
  46965. +
  46966. + DWC_CIRCLEQ_INSERT_TAIL(&manager->notifiers, notifier, list_entry);
  46967. +
  46968. + DWC_INFO("Notifier %p registered", object);
  46969. + dump_manager();
  46970. +
  46971. + return notifier;
  46972. +}
  46973. +
  46974. +void dwc_unregister_notifier(dwc_notifier_t *notifier)
  46975. +{
  46976. + DWC_ASSERT(manager, "Notification manager not found");
  46977. +
  46978. + if (!DWC_CIRCLEQ_EMPTY(&notifier->observers)) {
  46979. + observer_t *o;
  46980. +
  46981. + DWC_ERROR("Notifier %p has active observers when removing\n", notifier->object);
  46982. + DWC_CIRCLEQ_FOREACH(o, &notifier->observers, list_entry) {
  46983. + DWC_DEBUGC(" %p watching %s\n", o->observer, o->notification);
  46984. + }
  46985. +
  46986. + DWC_ASSERT(DWC_CIRCLEQ_EMPTY(&notifier->observers),
  46987. + "Notifier %p has active observers when removing", notifier);
  46988. + }
  46989. +
  46990. + DWC_CIRCLEQ_REMOVE_INIT(&manager->notifiers, notifier, list_entry);
  46991. + free_notifier(notifier);
  46992. +
  46993. + DWC_INFO("Notifier unregistered");
  46994. + dump_manager();
  46995. +}
  46996. +
  46997. +/* Add an observer to observe the notifier for a particular state, event, or notification. */
  46998. +int dwc_add_observer(void *observer, void *object, char *notification,
  46999. + dwc_notifier_callback_t callback, void *data)
  47000. +{
  47001. + notifier_t *notifier = find_notifier(object);
  47002. + observer_t *new_observer;
  47003. +
  47004. + if (!notifier) {
  47005. + DWC_ERROR("Notifier %p is not found when adding observer\n", object);
  47006. + return -DWC_E_INVALID;
  47007. + }
  47008. +
  47009. + new_observer = alloc_observer(notifier->mem_ctx, observer, notification, callback, data);
  47010. + if (!new_observer) {
  47011. + return -DWC_E_NO_MEMORY;
  47012. + }
  47013. +
  47014. + DWC_CIRCLEQ_INSERT_TAIL(&notifier->observers, new_observer, list_entry);
  47015. +
  47016. + DWC_INFO("Added observer %p to notifier %p observing notification %s, callback=%p, data=%p",
  47017. + observer, object, notification, callback, data);
  47018. +
  47019. + dump_manager();
  47020. + return 0;
  47021. +}
  47022. +
  47023. +int dwc_remove_observer(void *observer)
  47024. +{
  47025. + notifier_t *n;
  47026. +
  47027. + DWC_ASSERT(manager, "Notification manager not found");
  47028. +
  47029. + DWC_CIRCLEQ_FOREACH(n, &manager->notifiers, list_entry) {
  47030. + observer_t *o;
  47031. + observer_t *o2;
  47032. +
  47033. + DWC_CIRCLEQ_FOREACH_SAFE(o, o2, &n->observers, list_entry) {
  47034. + if (o->observer == observer) {
  47035. + DWC_CIRCLEQ_REMOVE_INIT(&n->observers, o, list_entry);
  47036. + DWC_INFO("Removing observer %p from notifier %p watching notification %s:",
  47037. + o->observer, n->object, o->notification);
  47038. + free_observer(n->mem_ctx, o);
  47039. + }
  47040. + }
  47041. + }
  47042. +
  47043. + dump_manager();
  47044. + return 0;
  47045. +}
  47046. +
  47047. +typedef struct callback_data {
  47048. + void *mem_ctx;
  47049. + dwc_notifier_callback_t cb;
  47050. + void *observer;
  47051. + void *data;
  47052. + void *object;
  47053. + char *notification;
  47054. + void *notification_data;
  47055. +} cb_data_t;
  47056. +
  47057. +static void cb_task(void *data)
  47058. +{
  47059. + cb_data_t *cb = (cb_data_t *)data;
  47060. +
  47061. + cb->cb(cb->object, cb->notification, cb->observer, cb->notification_data, cb->data);
  47062. + dwc_free(cb->mem_ctx, cb);
  47063. +}
  47064. +
  47065. +void dwc_notify(dwc_notifier_t *notifier, char *notification, void *notification_data)
  47066. +{
  47067. + observer_t *o;
  47068. +
  47069. + DWC_ASSERT(manager, "Notification manager not found");
  47070. +
  47071. + DWC_CIRCLEQ_FOREACH(o, &notifier->observers, list_entry) {
  47072. + int len = DWC_STRLEN(notification);
  47073. +
  47074. + if (DWC_STRLEN(o->notification) != len) {
  47075. + continue;
  47076. + }
  47077. +
  47078. + if (DWC_STRNCMP(o->notification, notification, len) == 0) {
  47079. + cb_data_t *cb_data = dwc_alloc(notifier->mem_ctx, sizeof(cb_data_t));
  47080. +
  47081. + if (!cb_data) {
  47082. + DWC_ERROR("Failed to allocate callback data\n");
  47083. + return;
  47084. + }
  47085. +
  47086. + cb_data->mem_ctx = notifier->mem_ctx;
  47087. + cb_data->cb = o->callback;
  47088. + cb_data->observer = o->observer;
  47089. + cb_data->data = o->data;
  47090. + cb_data->object = notifier->object;
  47091. + cb_data->notification = notification;
  47092. + cb_data->notification_data = notification_data;
  47093. + DWC_DEBUGC("Observer found %p for notification %s\n", o->observer, notification);
  47094. + DWC_WORKQ_SCHEDULE(manager->wq, cb_task, cb_data,
  47095. + "Notify callback from %p for Notification %s, to observer %p",
  47096. + cb_data->object, notification, cb_data->observer);
  47097. + }
  47098. + }
  47099. +}
  47100. +
  47101. +#endif /* DWC_NOTIFYLIB */
  47102. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_common_port/dwc_notifier.h linux-3.12.26/drivers/usb/host/dwc_common_port/dwc_notifier.h
  47103. --- linux-3.12.26.orig/drivers/usb/host/dwc_common_port/dwc_notifier.h 1970-01-01 01:00:00.000000000 +0100
  47104. +++ linux-3.12.26/drivers/usb/host/dwc_common_port/dwc_notifier.h 2014-08-06 16:50:14.777964537 +0200
  47105. @@ -0,0 +1,122 @@
  47106. +
  47107. +#ifndef __DWC_NOTIFIER_H__
  47108. +#define __DWC_NOTIFIER_H__
  47109. +
  47110. +#ifdef __cplusplus
  47111. +extern "C" {
  47112. +#endif
  47113. +
  47114. +#include "dwc_os.h"
  47115. +
  47116. +/** @file
  47117. + *
  47118. + * A simple implementation of the Observer pattern. Any "module" can
  47119. + * register as an observer or notifier. The notion of "module" is abstract and
  47120. + * can mean anything used to identify either an observer or notifier. Usually
  47121. + * it will be a pointer to a data structure which contains some state, ie an
  47122. + * object.
  47123. + *
  47124. + * Before any notifiers can be added, the global notification manager must be
  47125. + * brought up with dwc_alloc_notification_manager().
  47126. + * dwc_free_notification_manager() will bring it down and free all resources.
  47127. + * These would typically be called upon module load and unload. The
  47128. + * notification manager is a single global instance that handles all registered
  47129. + * observable modules and observers so this should be done only once.
  47130. + *
  47131. + * A module can be observable by using Notifications to publicize some general
  47132. + * information about it's state or operation. It does not care who listens, or
  47133. + * even if anyone listens, or what they do with the information. The observable
  47134. + * modules do not need to know any information about it's observers or their
  47135. + * interface, or their state or data.
  47136. + *
  47137. + * Any module can register to emit Notifications. It should publish a list of
  47138. + * notifications that it can emit and their behavior, such as when they will get
  47139. + * triggered, and what information will be provided to the observer. Then it
  47140. + * should register itself as an observable module. See dwc_register_notifier().
  47141. + *
  47142. + * Any module can observe any observable, registered module, provided it has a
  47143. + * handle to the other module and knows what notifications to observe. See
  47144. + * dwc_add_observer().
  47145. + *
  47146. + * A function of type dwc_notifier_callback_t is called whenever a notification
  47147. + * is triggered with one or more observers observing it. This function is
  47148. + * called in it's own process so it may sleep or block if needed. It is
  47149. + * guaranteed to be called sometime after the notification has occurred and will
  47150. + * be called once per each time the notification is triggered. It will NOT be
  47151. + * called in the same process context used to trigger the notification.
  47152. + *
  47153. + * @section Limitiations
  47154. + *
  47155. + * Keep in mind that Notifications that can be triggered in rapid sucession may
  47156. + * schedule too many processes too handle. Be aware of this limitation when
  47157. + * designing to use notifications, and only add notifications for appropriate
  47158. + * observable information.
  47159. + *
  47160. + * Also Notification callbacks are not synchronous. If you need to synchronize
  47161. + * the behavior between module/observer you must use other means. And perhaps
  47162. + * that will mean Notifications are not the proper solution.
  47163. + */
  47164. +
  47165. +struct dwc_notifier;
  47166. +typedef struct dwc_notifier dwc_notifier_t;
  47167. +
  47168. +/** The callback function must be of this type.
  47169. + *
  47170. + * @param object This is the object that is being observed.
  47171. + * @param notification This is the notification that was triggered.
  47172. + * @param observer This is the observer
  47173. + * @param notification_data This is notification-specific data that the notifier
  47174. + * has included in this notification. The value of this should be published in
  47175. + * the documentation of the observable module with the notifications.
  47176. + * @param user_data This is any custom data that the observer provided when
  47177. + * adding itself as an observer to the notification. */
  47178. +typedef void (*dwc_notifier_callback_t)(void *object, char *notification, void *observer,
  47179. + void *notification_data, void *user_data);
  47180. +
  47181. +/** Brings up the notification manager. */
  47182. +extern int dwc_alloc_notification_manager(void *mem_ctx, void *wkq_ctx);
  47183. +/** Brings down the notification manager. */
  47184. +extern void dwc_free_notification_manager(void);
  47185. +
  47186. +/** This function registers an observable module. A dwc_notifier_t object is
  47187. + * returned to the observable module. This is an opaque object that is used by
  47188. + * the observable module to trigger notifications. This object should only be
  47189. + * accessible to functions that are authorized to trigger notifications for this
  47190. + * module. Observers do not need this object. */
  47191. +extern dwc_notifier_t *dwc_register_notifier(void *mem_ctx, void *object);
  47192. +
  47193. +/** This function unregisters an observable module. All observers have to be
  47194. + * removed prior to unregistration. */
  47195. +extern void dwc_unregister_notifier(dwc_notifier_t *notifier);
  47196. +
  47197. +/** Add a module as an observer to the observable module. The observable module
  47198. + * needs to have previously registered with the notification manager.
  47199. + *
  47200. + * @param observer The observer module
  47201. + * @param object The module to observe
  47202. + * @param notification The notification to observe
  47203. + * @param callback The callback function to call
  47204. + * @param user_data Any additional user data to pass into the callback function */
  47205. +extern int dwc_add_observer(void *observer, void *object, char *notification,
  47206. + dwc_notifier_callback_t callback, void *user_data);
  47207. +
  47208. +/** Removes the specified observer from all notifications that it is currently
  47209. + * observing. */
  47210. +extern int dwc_remove_observer(void *observer);
  47211. +
  47212. +/** This function triggers a Notification. It should be called by the
  47213. + * observable module, or any module or library which the observable module
  47214. + * allows to trigger notification on it's behalf. Such as the dwc_cc_t.
  47215. + *
  47216. + * dwc_notify is a non-blocking function. Callbacks are scheduled called in
  47217. + * their own process context for each trigger. Callbacks can be blocking.
  47218. + * dwc_notify can be called from interrupt context if needed.
  47219. + *
  47220. + */
  47221. +void dwc_notify(dwc_notifier_t *notifier, char *notification, void *notification_data);
  47222. +
  47223. +#ifdef __cplusplus
  47224. +}
  47225. +#endif
  47226. +
  47227. +#endif /* __DWC_NOTIFIER_H__ */
  47228. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_common_port/dwc_os.h linux-3.12.26/drivers/usb/host/dwc_common_port/dwc_os.h
  47229. --- linux-3.12.26.orig/drivers/usb/host/dwc_common_port/dwc_os.h 1970-01-01 01:00:00.000000000 +0100
  47230. +++ linux-3.12.26/drivers/usb/host/dwc_common_port/dwc_os.h 2014-08-06 16:50:14.777964537 +0200
  47231. @@ -0,0 +1,1262 @@
  47232. +/* =========================================================================
  47233. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_os.h $
  47234. + * $Revision: #14 $
  47235. + * $Date: 2010/11/04 $
  47236. + * $Change: 1621695 $
  47237. + *
  47238. + * Synopsys Portability Library Software and documentation
  47239. + * (hereinafter, "Software") is an Unsupported proprietary work of
  47240. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  47241. + * between Synopsys and you.
  47242. + *
  47243. + * The Software IS NOT an item of Licensed Software or Licensed Product
  47244. + * under any End User Software License Agreement or Agreement for
  47245. + * Licensed Product with Synopsys or any supplement thereto. You are
  47246. + * permitted to use and redistribute this Software in source and binary
  47247. + * forms, with or without modification, provided that redistributions
  47248. + * of source code must retain this notice. You may not view, use,
  47249. + * disclose, copy or distribute this file or any information contained
  47250. + * herein except pursuant to this license grant from Synopsys. If you
  47251. + * do not agree with this notice, including the disclaimer below, then
  47252. + * you are not authorized to use the Software.
  47253. + *
  47254. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  47255. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  47256. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  47257. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  47258. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  47259. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  47260. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  47261. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  47262. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  47263. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  47264. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  47265. + * DAMAGE.
  47266. + * ========================================================================= */
  47267. +#ifndef _DWC_OS_H_
  47268. +#define _DWC_OS_H_
  47269. +
  47270. +#ifdef __cplusplus
  47271. +extern "C" {
  47272. +#endif
  47273. +
  47274. +/** @file
  47275. + *
  47276. + * DWC portability library, low level os-wrapper functions
  47277. + *
  47278. + */
  47279. +
  47280. +/* These basic types need to be defined by some OS header file or custom header
  47281. + * file for your specific target architecture.
  47282. + *
  47283. + * uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t, uint64_t, int64_t
  47284. + *
  47285. + * Any custom or alternate header file must be added and enabled here.
  47286. + */
  47287. +
  47288. +#ifdef DWC_LINUX
  47289. +# include <linux/types.h>
  47290. +# ifdef CONFIG_DEBUG_MUTEXES
  47291. +# include <linux/mutex.h>
  47292. +# endif
  47293. +# include <linux/errno.h>
  47294. +# include <stdarg.h>
  47295. +#endif
  47296. +
  47297. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  47298. +# include <os_dep.h>
  47299. +#endif
  47300. +
  47301. +
  47302. +/** @name Primitive Types and Values */
  47303. +
  47304. +/** We define a boolean type for consistency. Can be either YES or NO */
  47305. +typedef uint8_t dwc_bool_t;
  47306. +#define YES 1
  47307. +#define NO 0
  47308. +
  47309. +#ifdef DWC_LINUX
  47310. +
  47311. +/** @name Error Codes */
  47312. +#define DWC_E_INVALID EINVAL
  47313. +#define DWC_E_NO_MEMORY ENOMEM
  47314. +#define DWC_E_NO_DEVICE ENODEV
  47315. +#define DWC_E_NOT_SUPPORTED EOPNOTSUPP
  47316. +#define DWC_E_TIMEOUT ETIMEDOUT
  47317. +#define DWC_E_BUSY EBUSY
  47318. +#define DWC_E_AGAIN EAGAIN
  47319. +#define DWC_E_RESTART ERESTART
  47320. +#define DWC_E_ABORT ECONNABORTED
  47321. +#define DWC_E_SHUTDOWN ESHUTDOWN
  47322. +#define DWC_E_NO_DATA ENODATA
  47323. +#define DWC_E_DISCONNECT ECONNRESET
  47324. +#define DWC_E_UNKNOWN EINVAL
  47325. +#define DWC_E_NO_STREAM_RES ENOSR
  47326. +#define DWC_E_COMMUNICATION ECOMM
  47327. +#define DWC_E_OVERFLOW EOVERFLOW
  47328. +#define DWC_E_PROTOCOL EPROTO
  47329. +#define DWC_E_IN_PROGRESS EINPROGRESS
  47330. +#define DWC_E_PIPE EPIPE
  47331. +#define DWC_E_IO EIO
  47332. +#define DWC_E_NO_SPACE ENOSPC
  47333. +
  47334. +#else
  47335. +
  47336. +/** @name Error Codes */
  47337. +#define DWC_E_INVALID 1001
  47338. +#define DWC_E_NO_MEMORY 1002
  47339. +#define DWC_E_NO_DEVICE 1003
  47340. +#define DWC_E_NOT_SUPPORTED 1004
  47341. +#define DWC_E_TIMEOUT 1005
  47342. +#define DWC_E_BUSY 1006
  47343. +#define DWC_E_AGAIN 1007
  47344. +#define DWC_E_RESTART 1008
  47345. +#define DWC_E_ABORT 1009
  47346. +#define DWC_E_SHUTDOWN 1010
  47347. +#define DWC_E_NO_DATA 1011
  47348. +#define DWC_E_DISCONNECT 2000
  47349. +#define DWC_E_UNKNOWN 3000
  47350. +#define DWC_E_NO_STREAM_RES 4001
  47351. +#define DWC_E_COMMUNICATION 4002
  47352. +#define DWC_E_OVERFLOW 4003
  47353. +#define DWC_E_PROTOCOL 4004
  47354. +#define DWC_E_IN_PROGRESS 4005
  47355. +#define DWC_E_PIPE 4006
  47356. +#define DWC_E_IO 4007
  47357. +#define DWC_E_NO_SPACE 4008
  47358. +
  47359. +#endif
  47360. +
  47361. +
  47362. +/** @name Tracing/Logging Functions
  47363. + *
  47364. + * These function provide the capability to add tracing, debugging, and error
  47365. + * messages, as well exceptions as assertions. The WUDEV uses these
  47366. + * extensively. These could be logged to the main console, the serial port, an
  47367. + * internal buffer, etc. These functions could also be no-op if they are too
  47368. + * expensive on your system. By default undefining the DEBUG macro already
  47369. + * no-ops some of these functions. */
  47370. +
  47371. +/** Returns non-zero if in interrupt context. */
  47372. +extern dwc_bool_t DWC_IN_IRQ(void);
  47373. +#define dwc_in_irq DWC_IN_IRQ
  47374. +
  47375. +/** Returns "IRQ" if DWC_IN_IRQ is true. */
  47376. +static inline char *dwc_irq(void) {
  47377. + return DWC_IN_IRQ() ? "IRQ" : "";
  47378. +}
  47379. +
  47380. +/** Returns non-zero if in bottom-half context. */
  47381. +extern dwc_bool_t DWC_IN_BH(void);
  47382. +#define dwc_in_bh DWC_IN_BH
  47383. +
  47384. +/** Returns "BH" if DWC_IN_BH is true. */
  47385. +static inline char *dwc_bh(void) {
  47386. + return DWC_IN_BH() ? "BH" : "";
  47387. +}
  47388. +
  47389. +/**
  47390. + * A vprintf() clone. Just call vprintf if you've got it.
  47391. + */
  47392. +extern void DWC_VPRINTF(char *format, va_list args);
  47393. +#define dwc_vprintf DWC_VPRINTF
  47394. +
  47395. +/**
  47396. + * A vsnprintf() clone. Just call vprintf if you've got it.
  47397. + */
  47398. +extern int DWC_VSNPRINTF(char *str, int size, char *format, va_list args);
  47399. +#define dwc_vsnprintf DWC_VSNPRINTF
  47400. +
  47401. +/**
  47402. + * printf() clone. Just call printf if you've go it.
  47403. + */
  47404. +extern void DWC_PRINTF(char *format, ...)
  47405. +/* This provides compiler level static checking of the parameters if you're
  47406. + * using GCC. */
  47407. +#ifdef __GNUC__
  47408. + __attribute__ ((format(printf, 1, 2)));
  47409. +#else
  47410. + ;
  47411. +#endif
  47412. +#define dwc_printf DWC_PRINTF
  47413. +
  47414. +/**
  47415. + * sprintf() clone. Just call sprintf if you've got it.
  47416. + */
  47417. +extern int DWC_SPRINTF(char *string, char *format, ...)
  47418. +#ifdef __GNUC__
  47419. + __attribute__ ((format(printf, 2, 3)));
  47420. +#else
  47421. + ;
  47422. +#endif
  47423. +#define dwc_sprintf DWC_SPRINTF
  47424. +
  47425. +/**
  47426. + * snprintf() clone. Just call snprintf if you've got it.
  47427. + */
  47428. +extern int DWC_SNPRINTF(char *string, int size, char *format, ...)
  47429. +#ifdef __GNUC__
  47430. + __attribute__ ((format(printf, 3, 4)));
  47431. +#else
  47432. + ;
  47433. +#endif
  47434. +#define dwc_snprintf DWC_SNPRINTF
  47435. +
  47436. +/**
  47437. + * Prints a WARNING message. On systems that don't differentiate between
  47438. + * warnings and regular log messages, just print it. Indicates that something
  47439. + * may be wrong with the driver. Works like printf().
  47440. + *
  47441. + * Use the DWC_WARN macro to call this function.
  47442. + */
  47443. +extern void __DWC_WARN(char *format, ...)
  47444. +#ifdef __GNUC__
  47445. + __attribute__ ((format(printf, 1, 2)));
  47446. +#else
  47447. + ;
  47448. +#endif
  47449. +
  47450. +/**
  47451. + * Prints an error message. On systems that don't differentiate between errors
  47452. + * and regular log messages, just print it. Indicates that something went wrong
  47453. + * with the driver. Works like printf().
  47454. + *
  47455. + * Use the DWC_ERROR macro to call this function.
  47456. + */
  47457. +extern void __DWC_ERROR(char *format, ...)
  47458. +#ifdef __GNUC__
  47459. + __attribute__ ((format(printf, 1, 2)));
  47460. +#else
  47461. + ;
  47462. +#endif
  47463. +
  47464. +/**
  47465. + * Prints an exception error message and takes some user-defined action such as
  47466. + * print out a backtrace or trigger a breakpoint. Indicates that something went
  47467. + * abnormally wrong with the driver such as programmer error, or other
  47468. + * exceptional condition. It should not be ignored so even on systems without
  47469. + * printing capability, some action should be taken to notify the developer of
  47470. + * it. Works like printf().
  47471. + */
  47472. +extern void DWC_EXCEPTION(char *format, ...)
  47473. +#ifdef __GNUC__
  47474. + __attribute__ ((format(printf, 1, 2)));
  47475. +#else
  47476. + ;
  47477. +#endif
  47478. +#define dwc_exception DWC_EXCEPTION
  47479. +
  47480. +#ifndef DWC_OTG_DEBUG_LEV
  47481. +#define DWC_OTG_DEBUG_LEV 0
  47482. +#endif
  47483. +
  47484. +#ifdef DEBUG
  47485. +/**
  47486. + * Prints out a debug message. Used for logging/trace messages.
  47487. + *
  47488. + * Use the DWC_DEBUG macro to call this function
  47489. + */
  47490. +extern void __DWC_DEBUG(char *format, ...)
  47491. +#ifdef __GNUC__
  47492. + __attribute__ ((format(printf, 1, 2)));
  47493. +#else
  47494. + ;
  47495. +#endif
  47496. +#else
  47497. +#define __DWC_DEBUG printk
  47498. +#endif
  47499. +
  47500. +/**
  47501. + * Prints out a Debug message.
  47502. + */
  47503. +#define DWC_DEBUG(_format, _args...) __DWC_DEBUG("DEBUG:%s:%s: " _format "\n", \
  47504. + __func__, dwc_irq(), ## _args)
  47505. +#define dwc_debug DWC_DEBUG
  47506. +/**
  47507. + * Prints out a Debug message if enabled at compile time.
  47508. + */
  47509. +#if DWC_OTG_DEBUG_LEV > 0
  47510. +#define DWC_DEBUGC(_format, _args...) DWC_DEBUG(_format, ##_args )
  47511. +#else
  47512. +#define DWC_DEBUGC(_format, _args...)
  47513. +#endif
  47514. +#define dwc_debugc DWC_DEBUGC
  47515. +/**
  47516. + * Prints out an informative message.
  47517. + */
  47518. +#define DWC_INFO(_format, _args...) DWC_PRINTF("INFO:%s: " _format "\n", \
  47519. + dwc_irq(), ## _args)
  47520. +#define dwc_info DWC_INFO
  47521. +/**
  47522. + * Prints out an informative message if enabled at compile time.
  47523. + */
  47524. +#if DWC_OTG_DEBUG_LEV > 1
  47525. +#define DWC_INFOC(_format, _args...) DWC_INFO(_format, ##_args )
  47526. +#else
  47527. +#define DWC_INFOC(_format, _args...)
  47528. +#endif
  47529. +#define dwc_infoc DWC_INFOC
  47530. +/**
  47531. + * Prints out a warning message.
  47532. + */
  47533. +#define DWC_WARN(_format, _args...) __DWC_WARN("WARN:%s:%s:%d: " _format "\n", \
  47534. + dwc_irq(), __func__, __LINE__, ## _args)
  47535. +#define dwc_warn DWC_WARN
  47536. +/**
  47537. + * Prints out an error message.
  47538. + */
  47539. +#define DWC_ERROR(_format, _args...) __DWC_ERROR("ERROR:%s:%s:%d: " _format "\n", \
  47540. + dwc_irq(), __func__, __LINE__, ## _args)
  47541. +#define dwc_error DWC_ERROR
  47542. +
  47543. +#define DWC_PROTO_ERROR(_format, _args...) __DWC_WARN("ERROR:%s:%s:%d: " _format "\n", \
  47544. + dwc_irq(), __func__, __LINE__, ## _args)
  47545. +#define dwc_proto_error DWC_PROTO_ERROR
  47546. +
  47547. +#ifdef DEBUG
  47548. +/** Prints out a exception error message if the _expr expression fails. Disabled
  47549. + * if DEBUG is not enabled. */
  47550. +#define DWC_ASSERT(_expr, _format, _args...) do { \
  47551. + if (!(_expr)) { DWC_EXCEPTION("%s:%s:%d: " _format "\n", dwc_irq(), \
  47552. + __FILE__, __LINE__, ## _args); } \
  47553. + } while (0)
  47554. +#else
  47555. +#define DWC_ASSERT(_x...)
  47556. +#endif
  47557. +#define dwc_assert DWC_ASSERT
  47558. +
  47559. +
  47560. +/** @name Byte Ordering
  47561. + * The following functions are for conversions between processor's byte ordering
  47562. + * and specific ordering you want.
  47563. + */
  47564. +
  47565. +/** Converts 32 bit data in CPU byte ordering to little endian. */
  47566. +extern uint32_t DWC_CPU_TO_LE32(uint32_t *p);
  47567. +#define dwc_cpu_to_le32 DWC_CPU_TO_LE32
  47568. +
  47569. +/** Converts 32 bit data in CPU byte orderint to big endian. */
  47570. +extern uint32_t DWC_CPU_TO_BE32(uint32_t *p);
  47571. +#define dwc_cpu_to_be32 DWC_CPU_TO_BE32
  47572. +
  47573. +/** Converts 32 bit little endian data to CPU byte ordering. */
  47574. +extern uint32_t DWC_LE32_TO_CPU(uint32_t *p);
  47575. +#define dwc_le32_to_cpu DWC_LE32_TO_CPU
  47576. +
  47577. +/** Converts 32 bit big endian data to CPU byte ordering. */
  47578. +extern uint32_t DWC_BE32_TO_CPU(uint32_t *p);
  47579. +#define dwc_be32_to_cpu DWC_BE32_TO_CPU
  47580. +
  47581. +/** Converts 16 bit data in CPU byte ordering to little endian. */
  47582. +extern uint16_t DWC_CPU_TO_LE16(uint16_t *p);
  47583. +#define dwc_cpu_to_le16 DWC_CPU_TO_LE16
  47584. +
  47585. +/** Converts 16 bit data in CPU byte orderint to big endian. */
  47586. +extern uint16_t DWC_CPU_TO_BE16(uint16_t *p);
  47587. +#define dwc_cpu_to_be16 DWC_CPU_TO_BE16
  47588. +
  47589. +/** Converts 16 bit little endian data to CPU byte ordering. */
  47590. +extern uint16_t DWC_LE16_TO_CPU(uint16_t *p);
  47591. +#define dwc_le16_to_cpu DWC_LE16_TO_CPU
  47592. +
  47593. +/** Converts 16 bit bi endian data to CPU byte ordering. */
  47594. +extern uint16_t DWC_BE16_TO_CPU(uint16_t *p);
  47595. +#define dwc_be16_to_cpu DWC_BE16_TO_CPU
  47596. +
  47597. +
  47598. +/** @name Register Read/Write
  47599. + *
  47600. + * The following six functions should be implemented to read/write registers of
  47601. + * 32-bit and 64-bit sizes. All modules use this to read/write register values.
  47602. + * The reg value is a pointer to the register calculated from the void *base
  47603. + * variable passed into the driver when it is started. */
  47604. +
  47605. +#ifdef DWC_LINUX
  47606. +/* Linux doesn't need any extra parameters for register read/write, so we
  47607. + * just throw away the IO context parameter.
  47608. + */
  47609. +/** Reads the content of a 32-bit register. */
  47610. +extern uint32_t DWC_READ_REG32(uint32_t volatile *reg);
  47611. +#define dwc_read_reg32(_ctx_,_reg_) DWC_READ_REG32(_reg_)
  47612. +
  47613. +/** Reads the content of a 64-bit register. */
  47614. +extern uint64_t DWC_READ_REG64(uint64_t volatile *reg);
  47615. +#define dwc_read_reg64(_ctx_,_reg_) DWC_READ_REG64(_reg_)
  47616. +
  47617. +/** Writes to a 32-bit register. */
  47618. +extern void DWC_WRITE_REG32(uint32_t volatile *reg, uint32_t value);
  47619. +#define dwc_write_reg32(_ctx_,_reg_,_val_) DWC_WRITE_REG32(_reg_, _val_)
  47620. +
  47621. +/** Writes to a 64-bit register. */
  47622. +extern void DWC_WRITE_REG64(uint64_t volatile *reg, uint64_t value);
  47623. +#define dwc_write_reg64(_ctx_,_reg_,_val_) DWC_WRITE_REG64(_reg_, _val_)
  47624. +
  47625. +/**
  47626. + * Modify bit values in a register. Using the
  47627. + * algorithm: (reg_contents & ~clear_mask) | set_mask.
  47628. + */
  47629. +extern void DWC_MODIFY_REG32(uint32_t volatile *reg, uint32_t clear_mask, uint32_t set_mask);
  47630. +#define dwc_modify_reg32(_ctx_,_reg_,_cmsk_,_smsk_) DWC_MODIFY_REG32(_reg_,_cmsk_,_smsk_)
  47631. +extern void DWC_MODIFY_REG64(uint64_t volatile *reg, uint64_t clear_mask, uint64_t set_mask);
  47632. +#define dwc_modify_reg64(_ctx_,_reg_,_cmsk_,_smsk_) DWC_MODIFY_REG64(_reg_,_cmsk_,_smsk_)
  47633. +
  47634. +#endif /* DWC_LINUX */
  47635. +
  47636. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  47637. +typedef struct dwc_ioctx {
  47638. + struct device *dev;
  47639. + bus_space_tag_t iot;
  47640. + bus_space_handle_t ioh;
  47641. +} dwc_ioctx_t;
  47642. +
  47643. +/** BSD needs two extra parameters for register read/write, so we pass
  47644. + * them in using the IO context parameter.
  47645. + */
  47646. +/** Reads the content of a 32-bit register. */
  47647. +extern uint32_t DWC_READ_REG32(void *io_ctx, uint32_t volatile *reg);
  47648. +#define dwc_read_reg32 DWC_READ_REG32
  47649. +
  47650. +/** Reads the content of a 64-bit register. */
  47651. +extern uint64_t DWC_READ_REG64(void *io_ctx, uint64_t volatile *reg);
  47652. +#define dwc_read_reg64 DWC_READ_REG64
  47653. +
  47654. +/** Writes to a 32-bit register. */
  47655. +extern void DWC_WRITE_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t value);
  47656. +#define dwc_write_reg32 DWC_WRITE_REG32
  47657. +
  47658. +/** Writes to a 64-bit register. */
  47659. +extern void DWC_WRITE_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t value);
  47660. +#define dwc_write_reg64 DWC_WRITE_REG64
  47661. +
  47662. +/**
  47663. + * Modify bit values in a register. Using the
  47664. + * algorithm: (reg_contents & ~clear_mask) | set_mask.
  47665. + */
  47666. +extern void DWC_MODIFY_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t clear_mask, uint32_t set_mask);
  47667. +#define dwc_modify_reg32 DWC_MODIFY_REG32
  47668. +extern void DWC_MODIFY_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t clear_mask, uint64_t set_mask);
  47669. +#define dwc_modify_reg64 DWC_MODIFY_REG64
  47670. +
  47671. +#endif /* DWC_FREEBSD || DWC_NETBSD */
  47672. +
  47673. +/** @cond */
  47674. +
  47675. +/** @name Some convenience MACROS used internally. Define DWC_DEBUG_REGS to log the
  47676. + * register writes. */
  47677. +
  47678. +#ifdef DWC_LINUX
  47679. +
  47680. +# ifdef DWC_DEBUG_REGS
  47681. +
  47682. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  47683. +static inline uint32_t dwc_read_##_reg##_n(_container_type *container, int num) { \
  47684. + return DWC_READ_REG32(&container->regs->_reg[num]); \
  47685. +} \
  47686. +static inline void dwc_write_##_reg##_n(_container_type *container, int num, uint32_t data) { \
  47687. + DWC_DEBUG("WRITING %8s[%d]: %p: %08x", #_reg, num, \
  47688. + &(((uint32_t*)container->regs->_reg)[num]), data); \
  47689. + DWC_WRITE_REG32(&(((uint32_t*)container->regs->_reg)[num]), data); \
  47690. +}
  47691. +
  47692. +#define dwc_define_read_write_reg(_reg,_container_type) \
  47693. +static inline uint32_t dwc_read_##_reg(_container_type *container) { \
  47694. + return DWC_READ_REG32(&container->regs->_reg); \
  47695. +} \
  47696. +static inline void dwc_write_##_reg(_container_type *container, uint32_t data) { \
  47697. + DWC_DEBUG("WRITING %11s: %p: %08x", #_reg, &container->regs->_reg, data); \
  47698. + DWC_WRITE_REG32(&container->regs->_reg, data); \
  47699. +}
  47700. +
  47701. +# else /* DWC_DEBUG_REGS */
  47702. +
  47703. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  47704. +static inline uint32_t dwc_read_##_reg##_n(_container_type *container, int num) { \
  47705. + return DWC_READ_REG32(&container->regs->_reg[num]); \
  47706. +} \
  47707. +static inline void dwc_write_##_reg##_n(_container_type *container, int num, uint32_t data) { \
  47708. + DWC_WRITE_REG32(&(((uint32_t*)container->regs->_reg)[num]), data); \
  47709. +}
  47710. +
  47711. +#define dwc_define_read_write_reg(_reg,_container_type) \
  47712. +static inline uint32_t dwc_read_##_reg(_container_type *container) { \
  47713. + return DWC_READ_REG32(&container->regs->_reg); \
  47714. +} \
  47715. +static inline void dwc_write_##_reg(_container_type *container, uint32_t data) { \
  47716. + DWC_WRITE_REG32(&container->regs->_reg, data); \
  47717. +}
  47718. +
  47719. +# endif /* DWC_DEBUG_REGS */
  47720. +
  47721. +#endif /* DWC_LINUX */
  47722. +
  47723. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  47724. +
  47725. +# ifdef DWC_DEBUG_REGS
  47726. +
  47727. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  47728. +static inline uint32_t dwc_read_##_reg##_n(void *io_ctx, _container_type *container, int num) { \
  47729. + return DWC_READ_REG32(io_ctx, &container->regs->_reg[num]); \
  47730. +} \
  47731. +static inline void dwc_write_##_reg##_n(void *io_ctx, _container_type *container, int num, uint32_t data) { \
  47732. + DWC_DEBUG("WRITING %8s[%d]: %p: %08x", #_reg, num, \
  47733. + &(((uint32_t*)container->regs->_reg)[num]), data); \
  47734. + DWC_WRITE_REG32(io_ctx, &(((uint32_t*)container->regs->_reg)[num]), data); \
  47735. +}
  47736. +
  47737. +#define dwc_define_read_write_reg(_reg,_container_type) \
  47738. +static inline uint32_t dwc_read_##_reg(void *io_ctx, _container_type *container) { \
  47739. + return DWC_READ_REG32(io_ctx, &container->regs->_reg); \
  47740. +} \
  47741. +static inline void dwc_write_##_reg(void *io_ctx, _container_type *container, uint32_t data) { \
  47742. + DWC_DEBUG("WRITING %11s: %p: %08x", #_reg, &container->regs->_reg, data); \
  47743. + DWC_WRITE_REG32(io_ctx, &container->regs->_reg, data); \
  47744. +}
  47745. +
  47746. +# else /* DWC_DEBUG_REGS */
  47747. +
  47748. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  47749. +static inline uint32_t dwc_read_##_reg##_n(void *io_ctx, _container_type *container, int num) { \
  47750. + return DWC_READ_REG32(io_ctx, &container->regs->_reg[num]); \
  47751. +} \
  47752. +static inline void dwc_write_##_reg##_n(void *io_ctx, _container_type *container, int num, uint32_t data) { \
  47753. + DWC_WRITE_REG32(io_ctx, &(((uint32_t*)container->regs->_reg)[num]), data); \
  47754. +}
  47755. +
  47756. +#define dwc_define_read_write_reg(_reg,_container_type) \
  47757. +static inline uint32_t dwc_read_##_reg(void *io_ctx, _container_type *container) { \
  47758. + return DWC_READ_REG32(io_ctx, &container->regs->_reg); \
  47759. +} \
  47760. +static inline void dwc_write_##_reg(void *io_ctx, _container_type *container, uint32_t data) { \
  47761. + DWC_WRITE_REG32(io_ctx, &container->regs->_reg, data); \
  47762. +}
  47763. +
  47764. +# endif /* DWC_DEBUG_REGS */
  47765. +
  47766. +#endif /* DWC_FREEBSD || DWC_NETBSD */
  47767. +
  47768. +/** @endcond */
  47769. +
  47770. +
  47771. +#ifdef DWC_CRYPTOLIB
  47772. +/** @name Crypto Functions
  47773. + *
  47774. + * These are the low-level cryptographic functions used by the driver. */
  47775. +
  47776. +/** Perform AES CBC */
  47777. +extern int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out);
  47778. +#define dwc_aes_cbc DWC_AES_CBC
  47779. +
  47780. +/** Fill the provided buffer with random bytes. These should be cryptographic grade random numbers. */
  47781. +extern void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length);
  47782. +#define dwc_random_bytes DWC_RANDOM_BYTES
  47783. +
  47784. +/** Perform the SHA-256 hash function */
  47785. +extern int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out);
  47786. +#define dwc_sha256 DWC_SHA256
  47787. +
  47788. +/** Calculated the HMAC-SHA256 */
  47789. +extern int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t *out);
  47790. +#define dwc_hmac_sha256 DWC_HMAC_SHA256
  47791. +
  47792. +#endif /* DWC_CRYPTOLIB */
  47793. +
  47794. +
  47795. +/** @name Memory Allocation
  47796. + *
  47797. + * These function provide access to memory allocation. There are only 2 DMA
  47798. + * functions and 3 Regular memory functions that need to be implemented. None
  47799. + * of the memory debugging routines need to be implemented. The allocation
  47800. + * routines all ZERO the contents of the memory.
  47801. + *
  47802. + * Defining DWC_DEBUG_MEMORY turns on memory debugging and statistic gathering.
  47803. + * This checks for memory leaks, keeping track of alloc/free pairs. It also
  47804. + * keeps track of how much memory the driver is using at any given time. */
  47805. +
  47806. +#define DWC_PAGE_SIZE 4096
  47807. +#define DWC_PAGE_OFFSET(addr) (((uint32_t)addr) & 0xfff)
  47808. +#define DWC_PAGE_ALIGNED(addr) ((((uint32_t)addr) & 0xfff) == 0)
  47809. +
  47810. +#define DWC_INVALID_DMA_ADDR 0x0
  47811. +
  47812. +#ifdef DWC_LINUX
  47813. +/** Type for a DMA address */
  47814. +typedef dma_addr_t dwc_dma_t;
  47815. +#endif
  47816. +
  47817. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  47818. +typedef bus_addr_t dwc_dma_t;
  47819. +#endif
  47820. +
  47821. +#ifdef DWC_FREEBSD
  47822. +typedef struct dwc_dmactx {
  47823. + struct device *dev;
  47824. + bus_dma_tag_t dma_tag;
  47825. + bus_dmamap_t dma_map;
  47826. + bus_addr_t dma_paddr;
  47827. + void *dma_vaddr;
  47828. +} dwc_dmactx_t;
  47829. +#endif
  47830. +
  47831. +#ifdef DWC_NETBSD
  47832. +typedef struct dwc_dmactx {
  47833. + struct device *dev;
  47834. + bus_dma_tag_t dma_tag;
  47835. + bus_dmamap_t dma_map;
  47836. + bus_dma_segment_t segs[1];
  47837. + int nsegs;
  47838. + bus_addr_t dma_paddr;
  47839. + void *dma_vaddr;
  47840. +} dwc_dmactx_t;
  47841. +#endif
  47842. +
  47843. +/* @todo these functions will be added in the future */
  47844. +#if 0
  47845. +/**
  47846. + * Creates a DMA pool from which you can allocate DMA buffers. Buffers
  47847. + * allocated from this pool will be guaranteed to meet the size, alignment, and
  47848. + * boundary requirements specified.
  47849. + *
  47850. + * @param[in] size Specifies the size of the buffers that will be allocated from
  47851. + * this pool.
  47852. + * @param[in] align Specifies the byte alignment requirements of the buffers
  47853. + * allocated from this pool. Must be a power of 2.
  47854. + * @param[in] boundary Specifies the N-byte boundary that buffers allocated from
  47855. + * this pool must not cross.
  47856. + *
  47857. + * @returns A pointer to an internal opaque structure which is not to be
  47858. + * accessed outside of these library functions. Use this handle to specify
  47859. + * which pools to allocate/free DMA buffers from and also to destroy the pool,
  47860. + * when you are done with it.
  47861. + */
  47862. +extern dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size, uint32_t align, uint32_t boundary);
  47863. +
  47864. +/**
  47865. + * Destroy a DMA pool. All buffers allocated from that pool must be freed first.
  47866. + */
  47867. +extern void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool);
  47868. +
  47869. +/**
  47870. + * Allocate a buffer from the specified DMA pool and zeros its contents.
  47871. + */
  47872. +extern void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr);
  47873. +
  47874. +/**
  47875. + * Free a previously allocated buffer from the DMA pool.
  47876. + */
  47877. +extern void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr);
  47878. +#endif
  47879. +
  47880. +/** Allocates a DMA capable buffer and zeroes its contents. */
  47881. +extern void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr);
  47882. +
  47883. +/** Allocates a DMA capable buffer and zeroes its contents in atomic contest */
  47884. +extern void *__DWC_DMA_ALLOC_ATOMIC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr);
  47885. +
  47886. +/** Frees a previously allocated buffer. */
  47887. +extern void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr);
  47888. +
  47889. +/** Allocates a block of memory and zeroes its contents. */
  47890. +extern void *__DWC_ALLOC(void *mem_ctx, uint32_t size);
  47891. +
  47892. +/** Allocates a block of memory and zeroes its contents, in an atomic manner
  47893. + * which can be used inside interrupt context. The size should be sufficiently
  47894. + * small, a few KB at most, such that failures are not likely to occur. Can just call
  47895. + * __DWC_ALLOC if it is atomic. */
  47896. +extern void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size);
  47897. +
  47898. +/** Frees a previously allocated buffer. */
  47899. +extern void __DWC_FREE(void *mem_ctx, void *addr);
  47900. +
  47901. +#ifndef DWC_DEBUG_MEMORY
  47902. +
  47903. +#define DWC_ALLOC(_size_) __DWC_ALLOC(NULL, _size_)
  47904. +#define DWC_ALLOC_ATOMIC(_size_) __DWC_ALLOC_ATOMIC(NULL, _size_)
  47905. +#define DWC_FREE(_addr_) __DWC_FREE(NULL, _addr_)
  47906. +
  47907. +# ifdef DWC_LINUX
  47908. +#define DWC_DMA_ALLOC(_size_,_dma_) __DWC_DMA_ALLOC(NULL, _size_, _dma_)
  47909. +#define DWC_DMA_ALLOC_ATOMIC(_size_,_dma_) __DWC_DMA_ALLOC_ATOMIC(NULL, _size_,_dma_)
  47910. +#define DWC_DMA_FREE(_size_,_virt_,_dma_) __DWC_DMA_FREE(NULL, _size_, _virt_, _dma_)
  47911. +# endif
  47912. +
  47913. +# if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  47914. +#define DWC_DMA_ALLOC __DWC_DMA_ALLOC
  47915. +#define DWC_DMA_FREE __DWC_DMA_FREE
  47916. +# endif
  47917. +extern void *dwc_dma_alloc_atomic_debug(uint32_t size, dwc_dma_t *dma_addr, char const *func, int line);
  47918. +
  47919. +#else /* DWC_DEBUG_MEMORY */
  47920. +
  47921. +extern void *dwc_alloc_debug(void *mem_ctx, uint32_t size, char const *func, int line);
  47922. +extern void *dwc_alloc_atomic_debug(void *mem_ctx, uint32_t size, char const *func, int line);
  47923. +extern void dwc_free_debug(void *mem_ctx, void *addr, char const *func, int line);
  47924. +extern void *dwc_dma_alloc_debug(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr,
  47925. + char const *func, int line);
  47926. +extern void *dwc_dma_alloc_atomic_debug(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr,
  47927. + char const *func, int line);
  47928. +extern void dwc_dma_free_debug(void *dma_ctx, uint32_t size, void *virt_addr,
  47929. + dwc_dma_t dma_addr, char const *func, int line);
  47930. +
  47931. +extern int dwc_memory_debug_start(void *mem_ctx);
  47932. +extern void dwc_memory_debug_stop(void);
  47933. +extern void dwc_memory_debug_report(void);
  47934. +
  47935. +#define DWC_ALLOC(_size_) dwc_alloc_debug(NULL, _size_, __func__, __LINE__)
  47936. +#define DWC_ALLOC_ATOMIC(_size_) dwc_alloc_atomic_debug(NULL, _size_, \
  47937. + __func__, __LINE__)
  47938. +#define DWC_FREE(_addr_) dwc_free_debug(NULL, _addr_, __func__, __LINE__)
  47939. +
  47940. +# ifdef DWC_LINUX
  47941. +#define DWC_DMA_ALLOC(_size_,_dma_) dwc_dma_alloc_debug(NULL, _size_, \
  47942. + _dma_, __func__, __LINE__)
  47943. +#define DWC_DMA_ALLOC_ATOMIC(_size_,_dma_) dwc_dma_alloc_atomic_debug(NULL, _size_, \
  47944. + _dma_, __func__, __LINE__)
  47945. +#define DWC_DMA_FREE(_size_,_virt_,_dma_) dwc_dma_free_debug(NULL, _size_, \
  47946. + _virt_, _dma_, __func__, __LINE__)
  47947. +# endif
  47948. +
  47949. +# if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  47950. +#define DWC_DMA_ALLOC(_ctx_,_size_,_dma_) dwc_dma_alloc_debug(_ctx_, _size_, \
  47951. + _dma_, __func__, __LINE__)
  47952. +#define DWC_DMA_FREE(_ctx_,_size_,_virt_,_dma_) dwc_dma_free_debug(_ctx_, _size_, \
  47953. + _virt_, _dma_, __func__, __LINE__)
  47954. +# endif
  47955. +
  47956. +#endif /* DWC_DEBUG_MEMORY */
  47957. +
  47958. +#define dwc_alloc(_ctx_,_size_) DWC_ALLOC(_size_)
  47959. +#define dwc_alloc_atomic(_ctx_,_size_) DWC_ALLOC_ATOMIC(_size_)
  47960. +#define dwc_free(_ctx_,_addr_) DWC_FREE(_addr_)
  47961. +
  47962. +#ifdef DWC_LINUX
  47963. +/* Linux doesn't need any extra parameters for DMA buffer allocation, so we
  47964. + * just throw away the DMA context parameter.
  47965. + */
  47966. +#define dwc_dma_alloc(_ctx_,_size_,_dma_) DWC_DMA_ALLOC(_size_, _dma_)
  47967. +#define dwc_dma_alloc_atomic(_ctx_,_size_,_dma_) DWC_DMA_ALLOC_ATOMIC(_size_, _dma_)
  47968. +#define dwc_dma_free(_ctx_,_size_,_virt_,_dma_) DWC_DMA_FREE(_size_, _virt_, _dma_)
  47969. +#endif
  47970. +
  47971. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  47972. +/** BSD needs several extra parameters for DMA buffer allocation, so we pass
  47973. + * them in using the DMA context parameter.
  47974. + */
  47975. +#define dwc_dma_alloc DWC_DMA_ALLOC
  47976. +#define dwc_dma_free DWC_DMA_FREE
  47977. +#endif
  47978. +
  47979. +
  47980. +/** @name Memory and String Processing */
  47981. +
  47982. +/** memset() clone */
  47983. +extern void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size);
  47984. +#define dwc_memset DWC_MEMSET
  47985. +
  47986. +/** memcpy() clone */
  47987. +extern void *DWC_MEMCPY(void *dest, void const *src, uint32_t size);
  47988. +#define dwc_memcpy DWC_MEMCPY
  47989. +
  47990. +/** memmove() clone */
  47991. +extern void *DWC_MEMMOVE(void *dest, void *src, uint32_t size);
  47992. +#define dwc_memmove DWC_MEMMOVE
  47993. +
  47994. +/** memcmp() clone */
  47995. +extern int DWC_MEMCMP(void *m1, void *m2, uint32_t size);
  47996. +#define dwc_memcmp DWC_MEMCMP
  47997. +
  47998. +/** strcmp() clone */
  47999. +extern int DWC_STRCMP(void *s1, void *s2);
  48000. +#define dwc_strcmp DWC_STRCMP
  48001. +
  48002. +/** strncmp() clone */
  48003. +extern int DWC_STRNCMP(void *s1, void *s2, uint32_t size);
  48004. +#define dwc_strncmp DWC_STRNCMP
  48005. +
  48006. +/** strlen() clone, for NULL terminated ASCII strings */
  48007. +extern int DWC_STRLEN(char const *str);
  48008. +#define dwc_strlen DWC_STRLEN
  48009. +
  48010. +/** strcpy() clone, for NULL terminated ASCII strings */
  48011. +extern char *DWC_STRCPY(char *to, const char *from);
  48012. +#define dwc_strcpy DWC_STRCPY
  48013. +
  48014. +/** strdup() clone. If you wish to use memory allocation debugging, this
  48015. + * implementation of strdup should use the DWC_* memory routines instead of
  48016. + * calling a predefined strdup. Otherwise the memory allocated by this routine
  48017. + * will not be seen by the debugging routines. */
  48018. +extern char *DWC_STRDUP(char const *str);
  48019. +#define dwc_strdup(_ctx_,_str_) DWC_STRDUP(_str_)
  48020. +
  48021. +/** NOT an atoi() clone. Read the description carefully. Returns an integer
  48022. + * converted from the string str in base 10 unless the string begins with a "0x"
  48023. + * in which case it is base 16. String must be a NULL terminated sequence of
  48024. + * ASCII characters and may optionally begin with whitespace, a + or -, and a
  48025. + * "0x" prefix if base 16. The remaining characters must be valid digits for
  48026. + * the number and end with a NULL character. If any invalid characters are
  48027. + * encountered or it returns with a negative error code and the results of the
  48028. + * conversion are undefined. On sucess it returns 0. Overflow conditions are
  48029. + * undefined. An example implementation using atoi() can be referenced from the
  48030. + * Linux implementation. */
  48031. +extern int DWC_ATOI(const char *str, int32_t *value);
  48032. +#define dwc_atoi DWC_ATOI
  48033. +
  48034. +/** Same as above but for unsigned. */
  48035. +extern int DWC_ATOUI(const char *str, uint32_t *value);
  48036. +#define dwc_atoui DWC_ATOUI
  48037. +
  48038. +#ifdef DWC_UTFLIB
  48039. +/** This routine returns a UTF16LE unicode encoded string from a UTF8 string. */
  48040. +extern int DWC_UTF8_TO_UTF16LE(uint8_t const *utf8string, uint16_t *utf16string, unsigned len);
  48041. +#define dwc_utf8_to_utf16le DWC_UTF8_TO_UTF16LE
  48042. +#endif
  48043. +
  48044. +
  48045. +/** @name Wait queues
  48046. + *
  48047. + * Wait queues provide a means of synchronizing between threads or processes. A
  48048. + * process can block on a waitq if some condition is not true, waiting for it to
  48049. + * become true. When the waitq is triggered all waiting process will get
  48050. + * unblocked and the condition will be check again. Waitqs should be triggered
  48051. + * every time a condition can potentially change.*/
  48052. +struct dwc_waitq;
  48053. +
  48054. +/** Type for a waitq */
  48055. +typedef struct dwc_waitq dwc_waitq_t;
  48056. +
  48057. +/** The type of waitq condition callback function. This is called every time
  48058. + * condition is evaluated. */
  48059. +typedef int (*dwc_waitq_condition_t)(void *data);
  48060. +
  48061. +/** Allocate a waitq */
  48062. +extern dwc_waitq_t *DWC_WAITQ_ALLOC(void);
  48063. +#define dwc_waitq_alloc(_ctx_) DWC_WAITQ_ALLOC()
  48064. +
  48065. +/** Free a waitq */
  48066. +extern void DWC_WAITQ_FREE(dwc_waitq_t *wq);
  48067. +#define dwc_waitq_free DWC_WAITQ_FREE
  48068. +
  48069. +/** Check the condition and if it is false, block on the waitq. When unblocked, check the
  48070. + * condition again. The function returns when the condition becomes true. The return value
  48071. + * is 0 on condition true, DWC_WAITQ_ABORTED on abort or killed, or DWC_WAITQ_UNKNOWN on error. */
  48072. +extern int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data);
  48073. +#define dwc_waitq_wait DWC_WAITQ_WAIT
  48074. +
  48075. +/** Check the condition and if it is false, block on the waitq. When unblocked,
  48076. + * check the condition again. The function returns when the condition become
  48077. + * true or the timeout has passed. The return value is 0 on condition true or
  48078. + * DWC_TIMED_OUT on timeout, or DWC_WAITQ_ABORTED, or DWC_WAITQ_UNKNOWN on
  48079. + * error. */
  48080. +extern int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  48081. + void *data, int32_t msecs);
  48082. +#define dwc_waitq_wait_timeout DWC_WAITQ_WAIT_TIMEOUT
  48083. +
  48084. +/** Trigger a waitq, unblocking all processes. This should be called whenever a condition
  48085. + * has potentially changed. */
  48086. +extern void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq);
  48087. +#define dwc_waitq_trigger DWC_WAITQ_TRIGGER
  48088. +
  48089. +/** Unblock all processes waiting on the waitq with an ABORTED result. */
  48090. +extern void DWC_WAITQ_ABORT(dwc_waitq_t *wq);
  48091. +#define dwc_waitq_abort DWC_WAITQ_ABORT
  48092. +
  48093. +
  48094. +/** @name Threads
  48095. + *
  48096. + * A thread must be explicitly stopped. It must check DWC_THREAD_SHOULD_STOP
  48097. + * whenever it is woken up, and then return. The DWC_THREAD_STOP function
  48098. + * returns the value from the thread.
  48099. + */
  48100. +
  48101. +struct dwc_thread;
  48102. +
  48103. +/** Type for a thread */
  48104. +typedef struct dwc_thread dwc_thread_t;
  48105. +
  48106. +/** The thread function */
  48107. +typedef int (*dwc_thread_function_t)(void *data);
  48108. +
  48109. +/** Create a thread and start it running the thread_function. Returns a handle
  48110. + * to the thread */
  48111. +extern dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data);
  48112. +#define dwc_thread_run(_ctx_,_func_,_name_,_data_) DWC_THREAD_RUN(_func_, _name_, _data_)
  48113. +
  48114. +/** Stops a thread. Return the value returned by the thread. Or will return
  48115. + * DWC_ABORT if the thread never started. */
  48116. +extern int DWC_THREAD_STOP(dwc_thread_t *thread);
  48117. +#define dwc_thread_stop DWC_THREAD_STOP
  48118. +
  48119. +/** Signifies to the thread that it must stop. */
  48120. +#ifdef DWC_LINUX
  48121. +/* Linux doesn't need any parameters for kthread_should_stop() */
  48122. +extern dwc_bool_t DWC_THREAD_SHOULD_STOP(void);
  48123. +#define dwc_thread_should_stop(_thrd_) DWC_THREAD_SHOULD_STOP()
  48124. +
  48125. +/* No thread_exit function in Linux */
  48126. +#define dwc_thread_exit(_thrd_)
  48127. +#endif
  48128. +
  48129. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  48130. +/** BSD needs the thread pointer for kthread_suspend_check() */
  48131. +extern dwc_bool_t DWC_THREAD_SHOULD_STOP(dwc_thread_t *thread);
  48132. +#define dwc_thread_should_stop DWC_THREAD_SHOULD_STOP
  48133. +
  48134. +/** The thread must call this to exit. */
  48135. +extern void DWC_THREAD_EXIT(dwc_thread_t *thread);
  48136. +#define dwc_thread_exit DWC_THREAD_EXIT
  48137. +#endif
  48138. +
  48139. +
  48140. +/** @name Work queues
  48141. + *
  48142. + * Workqs are used to queue a callback function to be called at some later time,
  48143. + * in another thread. */
  48144. +struct dwc_workq;
  48145. +
  48146. +/** Type for a workq */
  48147. +typedef struct dwc_workq dwc_workq_t;
  48148. +
  48149. +/** The type of the callback function to be called. */
  48150. +typedef void (*dwc_work_callback_t)(void *data);
  48151. +
  48152. +/** Allocate a workq */
  48153. +extern dwc_workq_t *DWC_WORKQ_ALLOC(char *name);
  48154. +#define dwc_workq_alloc(_ctx_,_name_) DWC_WORKQ_ALLOC(_name_)
  48155. +
  48156. +/** Free a workq. All work must be completed before being freed. */
  48157. +extern void DWC_WORKQ_FREE(dwc_workq_t *workq);
  48158. +#define dwc_workq_free DWC_WORKQ_FREE
  48159. +
  48160. +/** Schedule a callback on the workq, passing in data. The function will be
  48161. + * scheduled at some later time. */
  48162. +extern void DWC_WORKQ_SCHEDULE(dwc_workq_t *workq, dwc_work_callback_t cb,
  48163. + void *data, char *format, ...)
  48164. +#ifdef __GNUC__
  48165. + __attribute__ ((format(printf, 4, 5)));
  48166. +#else
  48167. + ;
  48168. +#endif
  48169. +#define dwc_workq_schedule DWC_WORKQ_SCHEDULE
  48170. +
  48171. +/** Schedule a callback on the workq, that will be called until at least
  48172. + * given number miliseconds have passed. */
  48173. +extern void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *workq, dwc_work_callback_t cb,
  48174. + void *data, uint32_t time, char *format, ...)
  48175. +#ifdef __GNUC__
  48176. + __attribute__ ((format(printf, 5, 6)));
  48177. +#else
  48178. + ;
  48179. +#endif
  48180. +#define dwc_workq_schedule_delayed DWC_WORKQ_SCHEDULE_DELAYED
  48181. +
  48182. +/** The number of processes in the workq */
  48183. +extern int DWC_WORKQ_PENDING(dwc_workq_t *workq);
  48184. +#define dwc_workq_pending DWC_WORKQ_PENDING
  48185. +
  48186. +/** Blocks until all the work in the workq is complete or timed out. Returns <
  48187. + * 0 on timeout. */
  48188. +extern int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout);
  48189. +#define dwc_workq_wait_work_done DWC_WORKQ_WAIT_WORK_DONE
  48190. +
  48191. +
  48192. +/** @name Tasklets
  48193. + *
  48194. + */
  48195. +struct dwc_tasklet;
  48196. +
  48197. +/** Type for a tasklet */
  48198. +typedef struct dwc_tasklet dwc_tasklet_t;
  48199. +
  48200. +/** The type of the callback function to be called */
  48201. +typedef void (*dwc_tasklet_callback_t)(void *data);
  48202. +
  48203. +/** Allocates a tasklet */
  48204. +extern dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data);
  48205. +#define dwc_task_alloc(_ctx_,_name_,_cb_,_data_) DWC_TASK_ALLOC(_name_, _cb_, _data_)
  48206. +
  48207. +/** Frees a tasklet */
  48208. +extern void DWC_TASK_FREE(dwc_tasklet_t *task);
  48209. +#define dwc_task_free DWC_TASK_FREE
  48210. +
  48211. +/** Schedules a tasklet to run */
  48212. +extern void DWC_TASK_SCHEDULE(dwc_tasklet_t *task);
  48213. +#define dwc_task_schedule DWC_TASK_SCHEDULE
  48214. +
  48215. +extern void DWC_TASK_HI_SCHEDULE(dwc_tasklet_t *task);
  48216. +#define dwc_task_hi_schedule DWC_TASK_HI_SCHEDULE
  48217. +
  48218. +/** @name Timer
  48219. + *
  48220. + * Callbacks must be small and atomic.
  48221. + */
  48222. +struct dwc_timer;
  48223. +
  48224. +/** Type for a timer */
  48225. +typedef struct dwc_timer dwc_timer_t;
  48226. +
  48227. +/** The type of the callback function to be called */
  48228. +typedef void (*dwc_timer_callback_t)(void *data);
  48229. +
  48230. +/** Allocates a timer */
  48231. +extern dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data);
  48232. +#define dwc_timer_alloc(_ctx_,_name_,_cb_,_data_) DWC_TIMER_ALLOC(_name_,_cb_,_data_)
  48233. +
  48234. +/** Frees a timer */
  48235. +extern void DWC_TIMER_FREE(dwc_timer_t *timer);
  48236. +#define dwc_timer_free DWC_TIMER_FREE
  48237. +
  48238. +/** Schedules the timer to run at time ms from now. And will repeat at every
  48239. + * repeat_interval msec therafter
  48240. + *
  48241. + * Modifies a timer that is still awaiting execution to a new expiration time.
  48242. + * The mod_time is added to the old time. */
  48243. +extern void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time);
  48244. +#define dwc_timer_schedule DWC_TIMER_SCHEDULE
  48245. +
  48246. +/** Disables the timer from execution. */
  48247. +extern void DWC_TIMER_CANCEL(dwc_timer_t *timer);
  48248. +#define dwc_timer_cancel DWC_TIMER_CANCEL
  48249. +
  48250. +
  48251. +/** @name Spinlocks
  48252. + *
  48253. + * These locks are used when the work between the lock/unlock is atomic and
  48254. + * short. Interrupts are also disabled during the lock/unlock and thus they are
  48255. + * suitable to lock between interrupt/non-interrupt context. They also lock
  48256. + * between processes if you have multiple CPUs or Preemption. If you don't have
  48257. + * multiple CPUS or Preemption, then the you can simply implement the
  48258. + * DWC_SPINLOCK and DWC_SPINUNLOCK to disable and enable interrupts. Because
  48259. + * the work between the lock/unlock is atomic, the process context will never
  48260. + * change, and so you never have to lock between processes. */
  48261. +
  48262. +struct dwc_spinlock;
  48263. +
  48264. +/** Type for a spinlock */
  48265. +typedef struct dwc_spinlock dwc_spinlock_t;
  48266. +
  48267. +/** Type for the 'flags' argument to spinlock funtions */
  48268. +typedef unsigned long dwc_irqflags_t;
  48269. +
  48270. +/** Returns an initialized lock variable. This function should allocate and
  48271. + * initialize the OS-specific data structure used for locking. This data
  48272. + * structure is to be used for the DWC_LOCK and DWC_UNLOCK functions and should
  48273. + * be freed by the DWC_FREE_LOCK when it is no longer used. */
  48274. +extern dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void);
  48275. +#define dwc_spinlock_alloc(_ctx_) DWC_SPINLOCK_ALLOC()
  48276. +
  48277. +/** Frees an initialized lock variable. */
  48278. +extern void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock);
  48279. +#define dwc_spinlock_free(_ctx_,_lock_) DWC_SPINLOCK_FREE(_lock_)
  48280. +
  48281. +/** Disables interrupts and blocks until it acquires the lock.
  48282. + *
  48283. + * @param lock Pointer to the spinlock.
  48284. + * @param flags Unsigned long for irq flags storage.
  48285. + */
  48286. +extern void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags);
  48287. +#define dwc_spinlock_irqsave DWC_SPINLOCK_IRQSAVE
  48288. +
  48289. +/** Re-enables the interrupt and releases the lock.
  48290. + *
  48291. + * @param lock Pointer to the spinlock.
  48292. + * @param flags Unsigned long for irq flags storage. Must be the same as was
  48293. + * passed into DWC_LOCK.
  48294. + */
  48295. +extern void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags);
  48296. +#define dwc_spinunlock_irqrestore DWC_SPINUNLOCK_IRQRESTORE
  48297. +
  48298. +/** Blocks until it acquires the lock.
  48299. + *
  48300. + * @param lock Pointer to the spinlock.
  48301. + */
  48302. +extern void DWC_SPINLOCK(dwc_spinlock_t *lock);
  48303. +#define dwc_spinlock DWC_SPINLOCK
  48304. +
  48305. +/** Releases the lock.
  48306. + *
  48307. + * @param lock Pointer to the spinlock.
  48308. + */
  48309. +extern void DWC_SPINUNLOCK(dwc_spinlock_t *lock);
  48310. +#define dwc_spinunlock DWC_SPINUNLOCK
  48311. +
  48312. +
  48313. +/** @name Mutexes
  48314. + *
  48315. + * Unlike spinlocks Mutexes lock only between processes and the work between the
  48316. + * lock/unlock CAN block, therefore it CANNOT be called from interrupt context.
  48317. + */
  48318. +
  48319. +struct dwc_mutex;
  48320. +
  48321. +/** Type for a mutex */
  48322. +typedef struct dwc_mutex dwc_mutex_t;
  48323. +
  48324. +/* For Linux Mutex Debugging make it inline because the debugging routines use
  48325. + * the symbol to determine recursive locking. This makes it falsely think
  48326. + * recursive locking occurs. */
  48327. +#if defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES)
  48328. +#define DWC_MUTEX_ALLOC_LINUX_DEBUG(__mutexp) ({ \
  48329. + __mutexp = (dwc_mutex_t *)DWC_ALLOC(sizeof(struct mutex)); \
  48330. + mutex_init((struct mutex *)__mutexp); \
  48331. +})
  48332. +#endif
  48333. +
  48334. +/** Allocate a mutex */
  48335. +extern dwc_mutex_t *DWC_MUTEX_ALLOC(void);
  48336. +#define dwc_mutex_alloc(_ctx_) DWC_MUTEX_ALLOC()
  48337. +
  48338. +/* For memory leak debugging when using Linux Mutex Debugging */
  48339. +#if defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES)
  48340. +#define DWC_MUTEX_FREE(__mutexp) do { \
  48341. + mutex_destroy((struct mutex *)__mutexp); \
  48342. + DWC_FREE(__mutexp); \
  48343. +} while(0)
  48344. +#else
  48345. +/** Free a mutex */
  48346. +extern void DWC_MUTEX_FREE(dwc_mutex_t *mutex);
  48347. +#define dwc_mutex_free(_ctx_,_mutex_) DWC_MUTEX_FREE(_mutex_)
  48348. +#endif
  48349. +
  48350. +/** Lock a mutex */
  48351. +extern void DWC_MUTEX_LOCK(dwc_mutex_t *mutex);
  48352. +#define dwc_mutex_lock DWC_MUTEX_LOCK
  48353. +
  48354. +/** Non-blocking lock returns 1 on successful lock. */
  48355. +extern int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex);
  48356. +#define dwc_mutex_trylock DWC_MUTEX_TRYLOCK
  48357. +
  48358. +/** Unlock a mutex */
  48359. +extern void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex);
  48360. +#define dwc_mutex_unlock DWC_MUTEX_UNLOCK
  48361. +
  48362. +
  48363. +/** @name Time */
  48364. +
  48365. +/** Microsecond delay.
  48366. + *
  48367. + * @param usecs Microseconds to delay.
  48368. + */
  48369. +extern void DWC_UDELAY(uint32_t usecs);
  48370. +#define dwc_udelay DWC_UDELAY
  48371. +
  48372. +/** Millisecond delay.
  48373. + *
  48374. + * @param msecs Milliseconds to delay.
  48375. + */
  48376. +extern void DWC_MDELAY(uint32_t msecs);
  48377. +#define dwc_mdelay DWC_MDELAY
  48378. +
  48379. +/** Non-busy waiting.
  48380. + * Sleeps for specified number of milliseconds.
  48381. + *
  48382. + * @param msecs Milliseconds to sleep.
  48383. + */
  48384. +extern void DWC_MSLEEP(uint32_t msecs);
  48385. +#define dwc_msleep DWC_MSLEEP
  48386. +
  48387. +/**
  48388. + * Returns number of milliseconds since boot.
  48389. + */
  48390. +extern uint32_t DWC_TIME(void);
  48391. +#define dwc_time DWC_TIME
  48392. +
  48393. +
  48394. +
  48395. +
  48396. +/* @mainpage DWC Portability and Common Library
  48397. + *
  48398. + * This is the documentation for the DWC Portability and Common Library.
  48399. + *
  48400. + * @section intro Introduction
  48401. + *
  48402. + * The DWC Portability library consists of wrapper calls and data structures to
  48403. + * all low-level functions which are typically provided by the OS. The WUDEV
  48404. + * driver uses only these functions. In order to port the WUDEV driver, only
  48405. + * the functions in this library need to be re-implemented, with the same
  48406. + * behavior as documented here.
  48407. + *
  48408. + * The Common library consists of higher level functions, which rely only on
  48409. + * calling the functions from the DWC Portability library. These common
  48410. + * routines are shared across modules. Some of the common libraries need to be
  48411. + * used directly by the driver programmer when porting WUDEV. Such as the
  48412. + * parameter and notification libraries.
  48413. + *
  48414. + * @section low Portability Library OS Wrapper Functions
  48415. + *
  48416. + * Any function starting with DWC and in all CAPS is a low-level OS-wrapper that
  48417. + * needs to be implemented when porting, for example DWC_MUTEX_ALLOC(). All of
  48418. + * these functions are included in the dwc_os.h file.
  48419. + *
  48420. + * There are many functions here covering a wide array of OS services. Please
  48421. + * see dwc_os.h for details, and implementation notes for each function.
  48422. + *
  48423. + * @section common Common Library Functions
  48424. + *
  48425. + * Any function starting with dwc and in all lowercase is a common library
  48426. + * routine. These functions have a portable implementation and do not need to
  48427. + * be reimplemented when porting. The common routines can be used by any
  48428. + * driver, and some must be used by the end user to control the drivers. For
  48429. + * example, you must use the Parameter common library in order to set the
  48430. + * parameters in the WUDEV module.
  48431. + *
  48432. + * The common libraries consist of the following:
  48433. + *
  48434. + * - Connection Contexts - Used internally and can be used by end-user. See dwc_cc.h
  48435. + * - Parameters - Used internally and can be used by end-user. See dwc_params.h
  48436. + * - Notifications - Used internally and can be used by end-user. See dwc_notifier.h
  48437. + * - Lists - Used internally and can be used by end-user. See dwc_list.h
  48438. + * - Memory Debugging - Used internally and can be used by end-user. See dwc_os.h
  48439. + * - Modpow - Used internally only. See dwc_modpow.h
  48440. + * - DH - Used internally only. See dwc_dh.h
  48441. + * - Crypto - Used internally only. See dwc_crypto.h
  48442. + *
  48443. + *
  48444. + * @section prereq Prerequistes For dwc_os.h
  48445. + * @subsection types Data Types
  48446. + *
  48447. + * The dwc_os.h file assumes that several low-level data types are pre defined for the
  48448. + * compilation environment. These data types are:
  48449. + *
  48450. + * - uint8_t - unsigned 8-bit data type
  48451. + * - int8_t - signed 8-bit data type
  48452. + * - uint16_t - unsigned 16-bit data type
  48453. + * - int16_t - signed 16-bit data type
  48454. + * - uint32_t - unsigned 32-bit data type
  48455. + * - int32_t - signed 32-bit data type
  48456. + * - uint64_t - unsigned 64-bit data type
  48457. + * - int64_t - signed 64-bit data type
  48458. + *
  48459. + * Ensure that these are defined before using dwc_os.h. The easiest way to do
  48460. + * that is to modify the top of the file to include the appropriate header.
  48461. + * This is already done for the Linux environment. If the DWC_LINUX macro is
  48462. + * defined, the correct header will be added. A standard header <stdint.h> is
  48463. + * also used for environments where standard C headers are available.
  48464. + *
  48465. + * @subsection stdarg Variable Arguments
  48466. + *
  48467. + * Variable arguments are provided by a standard C header <stdarg.h>. it is
  48468. + * available in Both the Linux and ANSI C enviornment. An equivalent must be
  48469. + * provided in your enviornment in order to use dwc_os.h with the debug and
  48470. + * tracing message functionality.
  48471. + *
  48472. + * @subsection thread Threading
  48473. + *
  48474. + * WUDEV Core must be run on an operating system that provides for multiple
  48475. + * threads/processes. Threading can be implemented in many ways, even in
  48476. + * embedded systems without an operating system. At the bare minimum, the
  48477. + * system should be able to start any number of processes at any time to handle
  48478. + * special work. It need not be a pre-emptive system. Process context can
  48479. + * change upon a call to a blocking function. The hardware interrupt context
  48480. + * that calls the module's ISR() function must be differentiable from process
  48481. + * context, even if your processes are impemented via a hardware interrupt.
  48482. + * Further locking mechanism between process must exist (or be implemented), and
  48483. + * process context must have a way to disable interrupts for a period of time to
  48484. + * lock them out. If all of this exists, the functions in dwc_os.h related to
  48485. + * threading should be able to be implemented with the defined behavior.
  48486. + *
  48487. + */
  48488. +
  48489. +#ifdef __cplusplus
  48490. +}
  48491. +#endif
  48492. +
  48493. +#endif /* _DWC_OS_H_ */
  48494. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_common_port/Makefile linux-3.12.26/drivers/usb/host/dwc_common_port/Makefile
  48495. --- linux-3.12.26.orig/drivers/usb/host/dwc_common_port/Makefile 1970-01-01 01:00:00.000000000 +0100
  48496. +++ linux-3.12.26/drivers/usb/host/dwc_common_port/Makefile 2014-08-06 16:50:14.777964537 +0200
  48497. @@ -0,0 +1,58 @@
  48498. +#
  48499. +# Makefile for DWC_common library
  48500. +#
  48501. +
  48502. +ifneq ($(KERNELRELEASE),)
  48503. +
  48504. +ccflags-y += -DDWC_LINUX
  48505. +#ccflags-y += -DDEBUG
  48506. +#ccflags-y += -DDWC_DEBUG_REGS
  48507. +#ccflags-y += -DDWC_DEBUG_MEMORY
  48508. +
  48509. +ccflags-y += -DDWC_LIBMODULE
  48510. +ccflags-y += -DDWC_CCLIB
  48511. +#ccflags-y += -DDWC_CRYPTOLIB
  48512. +ccflags-y += -DDWC_NOTIFYLIB
  48513. +ccflags-y += -DDWC_UTFLIB
  48514. +
  48515. +obj-$(CONFIG_USB_DWCOTG) += dwc_common_port_lib.o
  48516. +dwc_common_port_lib-objs := dwc_cc.o dwc_modpow.o dwc_dh.o \
  48517. + dwc_crypto.o dwc_notifier.o \
  48518. + dwc_common_linux.o dwc_mem.o
  48519. +
  48520. +kernrelwd := $(subst ., ,$(KERNELRELEASE))
  48521. +kernrel3 := $(word 1,$(kernrelwd)).$(word 2,$(kernrelwd)).$(word 3,$(kernrelwd))
  48522. +
  48523. +ifneq ($(kernrel3),2.6.20)
  48524. +# grayg - I only know that we use ccflags-y in 2.6.31 actually
  48525. +ccflags-y += $(CPPFLAGS)
  48526. +endif
  48527. +
  48528. +else
  48529. +
  48530. +#ifeq ($(KDIR),)
  48531. +#$(error Must give "KDIR=/path/to/kernel/source" on command line or in environment)
  48532. +#endif
  48533. +
  48534. +ifeq ($(ARCH),)
  48535. +$(error Must give "ARCH=<arch>" on command line or in environment. Also, if \
  48536. + cross-compiling, must give "CROSS_COMPILE=/path/to/compiler/plus/tool-prefix-")
  48537. +endif
  48538. +
  48539. +ifeq ($(DOXYGEN),)
  48540. +DOXYGEN := doxygen
  48541. +endif
  48542. +
  48543. +default:
  48544. + $(MAKE) -C$(KDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  48545. +
  48546. +docs: $(wildcard *.[hc]) doc/doxygen.cfg
  48547. + $(DOXYGEN) doc/doxygen.cfg
  48548. +
  48549. +tags: $(wildcard *.[hc])
  48550. + $(CTAGS) -e $(wildcard *.[hc]) $(wildcard linux/*.[hc]) $(wildcard $(KDIR)/include/linux/usb*.h)
  48551. +
  48552. +endif
  48553. +
  48554. +clean:
  48555. + rm -rf *.o *.ko .*.cmd *.mod.c .*.o.d .*.o.tmp modules.order Module.markers Module.symvers .tmp_versions/
  48556. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_common_port/Makefile.fbsd linux-3.12.26/drivers/usb/host/dwc_common_port/Makefile.fbsd
  48557. --- linux-3.12.26.orig/drivers/usb/host/dwc_common_port/Makefile.fbsd 1970-01-01 01:00:00.000000000 +0100
  48558. +++ linux-3.12.26/drivers/usb/host/dwc_common_port/Makefile.fbsd 2014-08-06 16:50:14.777964537 +0200
  48559. @@ -0,0 +1,17 @@
  48560. +CFLAGS += -I/sys/i386/compile/GENERIC -I/sys/i386/include -I/usr/include
  48561. +CFLAGS += -DDWC_FREEBSD
  48562. +CFLAGS += -DDEBUG
  48563. +#CFLAGS += -DDWC_DEBUG_REGS
  48564. +#CFLAGS += -DDWC_DEBUG_MEMORY
  48565. +
  48566. +#CFLAGS += -DDWC_LIBMODULE
  48567. +#CFLAGS += -DDWC_CCLIB
  48568. +#CFLAGS += -DDWC_CRYPTOLIB
  48569. +#CFLAGS += -DDWC_NOTIFYLIB
  48570. +#CFLAGS += -DDWC_UTFLIB
  48571. +
  48572. +KMOD = dwc_common_port_lib
  48573. +SRCS = dwc_cc.c dwc_modpow.c dwc_dh.c dwc_crypto.c dwc_notifier.c \
  48574. + dwc_common_fbsd.c dwc_mem.c
  48575. +
  48576. +.include <bsd.kmod.mk>
  48577. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_common_port/Makefile.linux linux-3.12.26/drivers/usb/host/dwc_common_port/Makefile.linux
  48578. --- linux-3.12.26.orig/drivers/usb/host/dwc_common_port/Makefile.linux 1970-01-01 01:00:00.000000000 +0100
  48579. +++ linux-3.12.26/drivers/usb/host/dwc_common_port/Makefile.linux 2014-08-06 16:50:14.777964537 +0200
  48580. @@ -0,0 +1,49 @@
  48581. +#
  48582. +# Makefile for DWC_common library
  48583. +#
  48584. +ifneq ($(KERNELRELEASE),)
  48585. +
  48586. +ccflags-y += -DDWC_LINUX
  48587. +#ccflags-y += -DDEBUG
  48588. +#ccflags-y += -DDWC_DEBUG_REGS
  48589. +#ccflags-y += -DDWC_DEBUG_MEMORY
  48590. +
  48591. +ccflags-y += -DDWC_LIBMODULE
  48592. +ccflags-y += -DDWC_CCLIB
  48593. +ccflags-y += -DDWC_CRYPTOLIB
  48594. +ccflags-y += -DDWC_NOTIFYLIB
  48595. +ccflags-y += -DDWC_UTFLIB
  48596. +
  48597. +obj-m := dwc_common_port_lib.o
  48598. +dwc_common_port_lib-objs := dwc_cc.o dwc_modpow.o dwc_dh.o \
  48599. + dwc_crypto.o dwc_notifier.o \
  48600. + dwc_common_linux.o dwc_mem.o
  48601. +
  48602. +else
  48603. +
  48604. +ifeq ($(KDIR),)
  48605. +$(error Must give "KDIR=/path/to/kernel/source" on command line or in environment)
  48606. +endif
  48607. +
  48608. +ifeq ($(ARCH),)
  48609. +$(error Must give "ARCH=<arch>" on command line or in environment. Also, if \
  48610. + cross-compiling, must give "CROSS_COMPILE=/path/to/compiler/plus/tool-prefix-")
  48611. +endif
  48612. +
  48613. +ifeq ($(DOXYGEN),)
  48614. +DOXYGEN := doxygen
  48615. +endif
  48616. +
  48617. +default:
  48618. + $(MAKE) -C$(KDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  48619. +
  48620. +docs: $(wildcard *.[hc]) doc/doxygen.cfg
  48621. + $(DOXYGEN) doc/doxygen.cfg
  48622. +
  48623. +tags: $(wildcard *.[hc])
  48624. + $(CTAGS) -e $(wildcard *.[hc]) $(wildcard linux/*.[hc]) $(wildcard $(KDIR)/include/linux/usb*.h)
  48625. +
  48626. +endif
  48627. +
  48628. +clean:
  48629. + rm -rf *.o *.ko .*.cmd *.mod.c .*.o.d .*.o.tmp modules.order Module.markers Module.symvers .tmp_versions/
  48630. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_common_port/usb.h linux-3.12.26/drivers/usb/host/dwc_common_port/usb.h
  48631. --- linux-3.12.26.orig/drivers/usb/host/dwc_common_port/usb.h 1970-01-01 01:00:00.000000000 +0100
  48632. +++ linux-3.12.26/drivers/usb/host/dwc_common_port/usb.h 2014-08-06 16:50:14.777964537 +0200
  48633. @@ -0,0 +1,946 @@
  48634. +/*
  48635. + * Copyright (c) 1998 The NetBSD Foundation, Inc.
  48636. + * All rights reserved.
  48637. + *
  48638. + * This code is derived from software contributed to The NetBSD Foundation
  48639. + * by Lennart Augustsson (lennart@augustsson.net) at
  48640. + * Carlstedt Research & Technology.
  48641. + *
  48642. + * Redistribution and use in source and binary forms, with or without
  48643. + * modification, are permitted provided that the following conditions
  48644. + * are met:
  48645. + * 1. Redistributions of source code must retain the above copyright
  48646. + * notice, this list of conditions and the following disclaimer.
  48647. + * 2. Redistributions in binary form must reproduce the above copyright
  48648. + * notice, this list of conditions and the following disclaimer in the
  48649. + * documentation and/or other materials provided with the distribution.
  48650. + * 3. All advertising materials mentioning features or use of this software
  48651. + * must display the following acknowledgement:
  48652. + * This product includes software developed by the NetBSD
  48653. + * Foundation, Inc. and its contributors.
  48654. + * 4. Neither the name of The NetBSD Foundation nor the names of its
  48655. + * contributors may be used to endorse or promote products derived
  48656. + * from this software without specific prior written permission.
  48657. + *
  48658. + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  48659. + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  48660. + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  48661. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  48662. + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  48663. + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  48664. + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  48665. + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  48666. + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  48667. + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  48668. + * POSSIBILITY OF SUCH DAMAGE.
  48669. + */
  48670. +
  48671. +/* Modified by Synopsys, Inc, 12/12/2007 */
  48672. +
  48673. +
  48674. +#ifndef _USB_H_
  48675. +#define _USB_H_
  48676. +
  48677. +#ifdef __cplusplus
  48678. +extern "C" {
  48679. +#endif
  48680. +
  48681. +/*
  48682. + * The USB records contain some unaligned little-endian word
  48683. + * components. The U[SG]ETW macros take care of both the alignment
  48684. + * and endian problem and should always be used to access non-byte
  48685. + * values.
  48686. + */
  48687. +typedef u_int8_t uByte;
  48688. +typedef u_int8_t uWord[2];
  48689. +typedef u_int8_t uDWord[4];
  48690. +
  48691. +#define USETW2(w,h,l) ((w)[0] = (u_int8_t)(l), (w)[1] = (u_int8_t)(h))
  48692. +#define UCONSTW(x) { (x) & 0xff, ((x) >> 8) & 0xff }
  48693. +#define UCONSTDW(x) { (x) & 0xff, ((x) >> 8) & 0xff, \
  48694. + ((x) >> 16) & 0xff, ((x) >> 24) & 0xff }
  48695. +
  48696. +#if 1
  48697. +#define UGETW(w) ((w)[0] | ((w)[1] << 8))
  48698. +#define USETW(w,v) ((w)[0] = (u_int8_t)(v), (w)[1] = (u_int8_t)((v) >> 8))
  48699. +#define UGETDW(w) ((w)[0] | ((w)[1] << 8) | ((w)[2] << 16) | ((w)[3] << 24))
  48700. +#define USETDW(w,v) ((w)[0] = (u_int8_t)(v), \
  48701. + (w)[1] = (u_int8_t)((v) >> 8), \
  48702. + (w)[2] = (u_int8_t)((v) >> 16), \
  48703. + (w)[3] = (u_int8_t)((v) >> 24))
  48704. +#else
  48705. +/*
  48706. + * On little-endian machines that can handle unanliged accesses
  48707. + * (e.g. i386) these macros can be replaced by the following.
  48708. + */
  48709. +#define UGETW(w) (*(u_int16_t *)(w))
  48710. +#define USETW(w,v) (*(u_int16_t *)(w) = (v))
  48711. +#define UGETDW(w) (*(u_int32_t *)(w))
  48712. +#define USETDW(w,v) (*(u_int32_t *)(w) = (v))
  48713. +#endif
  48714. +
  48715. +/*
  48716. + * Macros for accessing UAS IU fields, which are big-endian
  48717. + */
  48718. +#define IUSETW2(w,h,l) ((w)[0] = (u_int8_t)(h), (w)[1] = (u_int8_t)(l))
  48719. +#define IUCONSTW(x) { ((x) >> 8) & 0xff, (x) & 0xff }
  48720. +#define IUCONSTDW(x) { ((x) >> 24) & 0xff, ((x) >> 16) & 0xff, \
  48721. + ((x) >> 8) & 0xff, (x) & 0xff }
  48722. +#define IUGETW(w) (((w)[0] << 8) | (w)[1])
  48723. +#define IUSETW(w,v) ((w)[0] = (u_int8_t)((v) >> 8), (w)[1] = (u_int8_t)(v))
  48724. +#define IUGETDW(w) (((w)[0] << 24) | ((w)[1] << 16) | ((w)[2] << 8) | (w)[3])
  48725. +#define IUSETDW(w,v) ((w)[0] = (u_int8_t)((v) >> 24), \
  48726. + (w)[1] = (u_int8_t)((v) >> 16), \
  48727. + (w)[2] = (u_int8_t)((v) >> 8), \
  48728. + (w)[3] = (u_int8_t)(v))
  48729. +
  48730. +#define UPACKED __attribute__((__packed__))
  48731. +
  48732. +typedef struct {
  48733. + uByte bmRequestType;
  48734. + uByte bRequest;
  48735. + uWord wValue;
  48736. + uWord wIndex;
  48737. + uWord wLength;
  48738. +} UPACKED usb_device_request_t;
  48739. +
  48740. +#define UT_GET_DIR(a) ((a) & 0x80)
  48741. +#define UT_WRITE 0x00
  48742. +#define UT_READ 0x80
  48743. +
  48744. +#define UT_GET_TYPE(a) ((a) & 0x60)
  48745. +#define UT_STANDARD 0x00
  48746. +#define UT_CLASS 0x20
  48747. +#define UT_VENDOR 0x40
  48748. +
  48749. +#define UT_GET_RECIPIENT(a) ((a) & 0x1f)
  48750. +#define UT_DEVICE 0x00
  48751. +#define UT_INTERFACE 0x01
  48752. +#define UT_ENDPOINT 0x02
  48753. +#define UT_OTHER 0x03
  48754. +
  48755. +#define UT_READ_DEVICE (UT_READ | UT_STANDARD | UT_DEVICE)
  48756. +#define UT_READ_INTERFACE (UT_READ | UT_STANDARD | UT_INTERFACE)
  48757. +#define UT_READ_ENDPOINT (UT_READ | UT_STANDARD | UT_ENDPOINT)
  48758. +#define UT_WRITE_DEVICE (UT_WRITE | UT_STANDARD | UT_DEVICE)
  48759. +#define UT_WRITE_INTERFACE (UT_WRITE | UT_STANDARD | UT_INTERFACE)
  48760. +#define UT_WRITE_ENDPOINT (UT_WRITE | UT_STANDARD | UT_ENDPOINT)
  48761. +#define UT_READ_CLASS_DEVICE (UT_READ | UT_CLASS | UT_DEVICE)
  48762. +#define UT_READ_CLASS_INTERFACE (UT_READ | UT_CLASS | UT_INTERFACE)
  48763. +#define UT_READ_CLASS_OTHER (UT_READ | UT_CLASS | UT_OTHER)
  48764. +#define UT_READ_CLASS_ENDPOINT (UT_READ | UT_CLASS | UT_ENDPOINT)
  48765. +#define UT_WRITE_CLASS_DEVICE (UT_WRITE | UT_CLASS | UT_DEVICE)
  48766. +#define UT_WRITE_CLASS_INTERFACE (UT_WRITE | UT_CLASS | UT_INTERFACE)
  48767. +#define UT_WRITE_CLASS_OTHER (UT_WRITE | UT_CLASS | UT_OTHER)
  48768. +#define UT_WRITE_CLASS_ENDPOINT (UT_WRITE | UT_CLASS | UT_ENDPOINT)
  48769. +#define UT_READ_VENDOR_DEVICE (UT_READ | UT_VENDOR | UT_DEVICE)
  48770. +#define UT_READ_VENDOR_INTERFACE (UT_READ | UT_VENDOR | UT_INTERFACE)
  48771. +#define UT_READ_VENDOR_OTHER (UT_READ | UT_VENDOR | UT_OTHER)
  48772. +#define UT_READ_VENDOR_ENDPOINT (UT_READ | UT_VENDOR | UT_ENDPOINT)
  48773. +#define UT_WRITE_VENDOR_DEVICE (UT_WRITE | UT_VENDOR | UT_DEVICE)
  48774. +#define UT_WRITE_VENDOR_INTERFACE (UT_WRITE | UT_VENDOR | UT_INTERFACE)
  48775. +#define UT_WRITE_VENDOR_OTHER (UT_WRITE | UT_VENDOR | UT_OTHER)
  48776. +#define UT_WRITE_VENDOR_ENDPOINT (UT_WRITE | UT_VENDOR | UT_ENDPOINT)
  48777. +
  48778. +/* Requests */
  48779. +#define UR_GET_STATUS 0x00
  48780. +#define USTAT_STANDARD_STATUS 0x00
  48781. +#define WUSTAT_WUSB_FEATURE 0x01
  48782. +#define WUSTAT_CHANNEL_INFO 0x02
  48783. +#define WUSTAT_RECEIVED_DATA 0x03
  48784. +#define WUSTAT_MAS_AVAILABILITY 0x04
  48785. +#define WUSTAT_CURRENT_TRANSMIT_POWER 0x05
  48786. +#define UR_CLEAR_FEATURE 0x01
  48787. +#define UR_SET_FEATURE 0x03
  48788. +#define UR_SET_AND_TEST_FEATURE 0x0c
  48789. +#define UR_SET_ADDRESS 0x05
  48790. +#define UR_GET_DESCRIPTOR 0x06
  48791. +#define UDESC_DEVICE 0x01
  48792. +#define UDESC_CONFIG 0x02
  48793. +#define UDESC_STRING 0x03
  48794. +#define UDESC_INTERFACE 0x04
  48795. +#define UDESC_ENDPOINT 0x05
  48796. +#define UDESC_SS_USB_COMPANION 0x30
  48797. +#define UDESC_DEVICE_QUALIFIER 0x06
  48798. +#define UDESC_OTHER_SPEED_CONFIGURATION 0x07
  48799. +#define UDESC_INTERFACE_POWER 0x08
  48800. +#define UDESC_OTG 0x09
  48801. +#define WUDESC_SECURITY 0x0c
  48802. +#define WUDESC_KEY 0x0d
  48803. +#define WUD_GET_KEY_INDEX(_wValue_) ((_wValue_) & 0xf)
  48804. +#define WUD_GET_KEY_TYPE(_wValue_) (((_wValue_) & 0x30) >> 4)
  48805. +#define WUD_KEY_TYPE_ASSOC 0x01
  48806. +#define WUD_KEY_TYPE_GTK 0x02
  48807. +#define WUD_GET_KEY_ORIGIN(_wValue_) (((_wValue_) & 0x40) >> 6)
  48808. +#define WUD_KEY_ORIGIN_HOST 0x00
  48809. +#define WUD_KEY_ORIGIN_DEVICE 0x01
  48810. +#define WUDESC_ENCRYPTION_TYPE 0x0e
  48811. +#define WUDESC_BOS 0x0f
  48812. +#define WUDESC_DEVICE_CAPABILITY 0x10
  48813. +#define WUDESC_WIRELESS_ENDPOINT_COMPANION 0x11
  48814. +#define UDESC_BOS 0x0f
  48815. +#define UDESC_DEVICE_CAPABILITY 0x10
  48816. +#define UDESC_CS_DEVICE 0x21 /* class specific */
  48817. +#define UDESC_CS_CONFIG 0x22
  48818. +#define UDESC_CS_STRING 0x23
  48819. +#define UDESC_CS_INTERFACE 0x24
  48820. +#define UDESC_CS_ENDPOINT 0x25
  48821. +#define UDESC_HUB 0x29
  48822. +#define UR_SET_DESCRIPTOR 0x07
  48823. +#define UR_GET_CONFIG 0x08
  48824. +#define UR_SET_CONFIG 0x09
  48825. +#define UR_GET_INTERFACE 0x0a
  48826. +#define UR_SET_INTERFACE 0x0b
  48827. +#define UR_SYNCH_FRAME 0x0c
  48828. +#define WUR_SET_ENCRYPTION 0x0d
  48829. +#define WUR_GET_ENCRYPTION 0x0e
  48830. +#define WUR_SET_HANDSHAKE 0x0f
  48831. +#define WUR_GET_HANDSHAKE 0x10
  48832. +#define WUR_SET_CONNECTION 0x11
  48833. +#define WUR_SET_SECURITY_DATA 0x12
  48834. +#define WUR_GET_SECURITY_DATA 0x13
  48835. +#define WUR_SET_WUSB_DATA 0x14
  48836. +#define WUDATA_DRPIE_INFO 0x01
  48837. +#define WUDATA_TRANSMIT_DATA 0x02
  48838. +#define WUDATA_TRANSMIT_PARAMS 0x03
  48839. +#define WUDATA_RECEIVE_PARAMS 0x04
  48840. +#define WUDATA_TRANSMIT_POWER 0x05
  48841. +#define WUR_LOOPBACK_DATA_WRITE 0x15
  48842. +#define WUR_LOOPBACK_DATA_READ 0x16
  48843. +#define WUR_SET_INTERFACE_DS 0x17
  48844. +
  48845. +/* Feature numbers */
  48846. +#define UF_ENDPOINT_HALT 0
  48847. +#define UF_DEVICE_REMOTE_WAKEUP 1
  48848. +#define UF_TEST_MODE 2
  48849. +#define UF_DEVICE_B_HNP_ENABLE 3
  48850. +#define UF_DEVICE_A_HNP_SUPPORT 4
  48851. +#define UF_DEVICE_A_ALT_HNP_SUPPORT 5
  48852. +#define WUF_WUSB 3
  48853. +#define WUF_TX_DRPIE 0x0
  48854. +#define WUF_DEV_XMIT_PACKET 0x1
  48855. +#define WUF_COUNT_PACKETS 0x2
  48856. +#define WUF_CAPTURE_PACKETS 0x3
  48857. +#define UF_FUNCTION_SUSPEND 0
  48858. +#define UF_U1_ENABLE 48
  48859. +#define UF_U2_ENABLE 49
  48860. +#define UF_LTM_ENABLE 50
  48861. +
  48862. +/* Class requests from the USB 2.0 hub spec, table 11-15 */
  48863. +#define UCR_CLEAR_HUB_FEATURE (0x2000 | UR_CLEAR_FEATURE)
  48864. +#define UCR_CLEAR_PORT_FEATURE (0x2300 | UR_CLEAR_FEATURE)
  48865. +#define UCR_GET_HUB_DESCRIPTOR (0xa000 | UR_GET_DESCRIPTOR)
  48866. +#define UCR_GET_HUB_STATUS (0xa000 | UR_GET_STATUS)
  48867. +#define UCR_GET_PORT_STATUS (0xa300 | UR_GET_STATUS)
  48868. +#define UCR_SET_HUB_FEATURE (0x2000 | UR_SET_FEATURE)
  48869. +#define UCR_SET_PORT_FEATURE (0x2300 | UR_SET_FEATURE)
  48870. +#define UCR_SET_AND_TEST_PORT_FEATURE (0xa300 | UR_SET_AND_TEST_FEATURE)
  48871. +
  48872. +#ifdef _MSC_VER
  48873. +#include <pshpack1.h>
  48874. +#endif
  48875. +
  48876. +typedef struct {
  48877. + uByte bLength;
  48878. + uByte bDescriptorType;
  48879. + uByte bDescriptorSubtype;
  48880. +} UPACKED usb_descriptor_t;
  48881. +
  48882. +typedef struct {
  48883. + uByte bLength;
  48884. + uByte bDescriptorType;
  48885. +} UPACKED usb_descriptor_header_t;
  48886. +
  48887. +typedef struct {
  48888. + uByte bLength;
  48889. + uByte bDescriptorType;
  48890. + uWord bcdUSB;
  48891. +#define UD_USB_2_0 0x0200
  48892. +#define UD_IS_USB2(d) (UGETW((d)->bcdUSB) >= UD_USB_2_0)
  48893. + uByte bDeviceClass;
  48894. + uByte bDeviceSubClass;
  48895. + uByte bDeviceProtocol;
  48896. + uByte bMaxPacketSize;
  48897. + /* The fields below are not part of the initial descriptor. */
  48898. + uWord idVendor;
  48899. + uWord idProduct;
  48900. + uWord bcdDevice;
  48901. + uByte iManufacturer;
  48902. + uByte iProduct;
  48903. + uByte iSerialNumber;
  48904. + uByte bNumConfigurations;
  48905. +} UPACKED usb_device_descriptor_t;
  48906. +#define USB_DEVICE_DESCRIPTOR_SIZE 18
  48907. +
  48908. +typedef struct {
  48909. + uByte bLength;
  48910. + uByte bDescriptorType;
  48911. + uWord wTotalLength;
  48912. + uByte bNumInterface;
  48913. + uByte bConfigurationValue;
  48914. + uByte iConfiguration;
  48915. +#define UC_ATT_ONE (1 << 7) /* must be set */
  48916. +#define UC_ATT_SELFPOWER (1 << 6) /* self powered */
  48917. +#define UC_ATT_WAKEUP (1 << 5) /* can wakeup */
  48918. +#define UC_ATT_BATTERY (1 << 4) /* battery powered */
  48919. + uByte bmAttributes;
  48920. +#define UC_BUS_POWERED 0x80
  48921. +#define UC_SELF_POWERED 0x40
  48922. +#define UC_REMOTE_WAKEUP 0x20
  48923. + uByte bMaxPower; /* max current in 2 mA units */
  48924. +#define UC_POWER_FACTOR 2
  48925. +} UPACKED usb_config_descriptor_t;
  48926. +#define USB_CONFIG_DESCRIPTOR_SIZE 9
  48927. +
  48928. +typedef struct {
  48929. + uByte bLength;
  48930. + uByte bDescriptorType;
  48931. + uByte bInterfaceNumber;
  48932. + uByte bAlternateSetting;
  48933. + uByte bNumEndpoints;
  48934. + uByte bInterfaceClass;
  48935. + uByte bInterfaceSubClass;
  48936. + uByte bInterfaceProtocol;
  48937. + uByte iInterface;
  48938. +} UPACKED usb_interface_descriptor_t;
  48939. +#define USB_INTERFACE_DESCRIPTOR_SIZE 9
  48940. +
  48941. +typedef struct {
  48942. + uByte bLength;
  48943. + uByte bDescriptorType;
  48944. + uByte bEndpointAddress;
  48945. +#define UE_GET_DIR(a) ((a) & 0x80)
  48946. +#define UE_SET_DIR(a,d) ((a) | (((d)&1) << 7))
  48947. +#define UE_DIR_IN 0x80
  48948. +#define UE_DIR_OUT 0x00
  48949. +#define UE_ADDR 0x0f
  48950. +#define UE_GET_ADDR(a) ((a) & UE_ADDR)
  48951. + uByte bmAttributes;
  48952. +#define UE_XFERTYPE 0x03
  48953. +#define UE_CONTROL 0x00
  48954. +#define UE_ISOCHRONOUS 0x01
  48955. +#define UE_BULK 0x02
  48956. +#define UE_INTERRUPT 0x03
  48957. +#define UE_GET_XFERTYPE(a) ((a) & UE_XFERTYPE)
  48958. +#define UE_ISO_TYPE 0x0c
  48959. +#define UE_ISO_ASYNC 0x04
  48960. +#define UE_ISO_ADAPT 0x08
  48961. +#define UE_ISO_SYNC 0x0c
  48962. +#define UE_GET_ISO_TYPE(a) ((a) & UE_ISO_TYPE)
  48963. + uWord wMaxPacketSize;
  48964. + uByte bInterval;
  48965. +} UPACKED usb_endpoint_descriptor_t;
  48966. +#define USB_ENDPOINT_DESCRIPTOR_SIZE 7
  48967. +
  48968. +typedef struct ss_endpoint_companion_descriptor {
  48969. + uByte bLength;
  48970. + uByte bDescriptorType;
  48971. + uByte bMaxBurst;
  48972. +#define USSE_GET_MAX_STREAMS(a) ((a) & 0x1f)
  48973. +#define USSE_SET_MAX_STREAMS(a, b) ((a) | ((b) & 0x1f))
  48974. +#define USSE_GET_MAX_PACKET_NUM(a) ((a) & 0x03)
  48975. +#define USSE_SET_MAX_PACKET_NUM(a, b) ((a) | ((b) & 0x03))
  48976. + uByte bmAttributes;
  48977. + uWord wBytesPerInterval;
  48978. +} UPACKED ss_endpoint_companion_descriptor_t;
  48979. +#define USB_SS_ENDPOINT_COMPANION_DESCRIPTOR_SIZE 6
  48980. +
  48981. +typedef struct {
  48982. + uByte bLength;
  48983. + uByte bDescriptorType;
  48984. + uWord bString[127];
  48985. +} UPACKED usb_string_descriptor_t;
  48986. +#define USB_MAX_STRING_LEN 128
  48987. +#define USB_LANGUAGE_TABLE 0 /* # of the string language id table */
  48988. +
  48989. +/* Hub specific request */
  48990. +#define UR_GET_BUS_STATE 0x02
  48991. +#define UR_CLEAR_TT_BUFFER 0x08
  48992. +#define UR_RESET_TT 0x09
  48993. +#define UR_GET_TT_STATE 0x0a
  48994. +#define UR_STOP_TT 0x0b
  48995. +
  48996. +/* Hub features */
  48997. +#define UHF_C_HUB_LOCAL_POWER 0
  48998. +#define UHF_C_HUB_OVER_CURRENT 1
  48999. +#define UHF_PORT_CONNECTION 0
  49000. +#define UHF_PORT_ENABLE 1
  49001. +#define UHF_PORT_SUSPEND 2
  49002. +#define UHF_PORT_OVER_CURRENT 3
  49003. +#define UHF_PORT_RESET 4
  49004. +#define UHF_PORT_L1 5
  49005. +#define UHF_PORT_POWER 8
  49006. +#define UHF_PORT_LOW_SPEED 9
  49007. +#define UHF_PORT_HIGH_SPEED 10
  49008. +#define UHF_C_PORT_CONNECTION 16
  49009. +#define UHF_C_PORT_ENABLE 17
  49010. +#define UHF_C_PORT_SUSPEND 18
  49011. +#define UHF_C_PORT_OVER_CURRENT 19
  49012. +#define UHF_C_PORT_RESET 20
  49013. +#define UHF_C_PORT_L1 23
  49014. +#define UHF_PORT_TEST 21
  49015. +#define UHF_PORT_INDICATOR 22
  49016. +
  49017. +typedef struct {
  49018. + uByte bDescLength;
  49019. + uByte bDescriptorType;
  49020. + uByte bNbrPorts;
  49021. + uWord wHubCharacteristics;
  49022. +#define UHD_PWR 0x0003
  49023. +#define UHD_PWR_GANGED 0x0000
  49024. +#define UHD_PWR_INDIVIDUAL 0x0001
  49025. +#define UHD_PWR_NO_SWITCH 0x0002
  49026. +#define UHD_COMPOUND 0x0004
  49027. +#define UHD_OC 0x0018
  49028. +#define UHD_OC_GLOBAL 0x0000
  49029. +#define UHD_OC_INDIVIDUAL 0x0008
  49030. +#define UHD_OC_NONE 0x0010
  49031. +#define UHD_TT_THINK 0x0060
  49032. +#define UHD_TT_THINK_8 0x0000
  49033. +#define UHD_TT_THINK_16 0x0020
  49034. +#define UHD_TT_THINK_24 0x0040
  49035. +#define UHD_TT_THINK_32 0x0060
  49036. +#define UHD_PORT_IND 0x0080
  49037. + uByte bPwrOn2PwrGood; /* delay in 2 ms units */
  49038. +#define UHD_PWRON_FACTOR 2
  49039. + uByte bHubContrCurrent;
  49040. + uByte DeviceRemovable[32]; /* max 255 ports */
  49041. +#define UHD_NOT_REMOV(desc, i) \
  49042. + (((desc)->DeviceRemovable[(i)/8] >> ((i) % 8)) & 1)
  49043. + /* deprecated */ uByte PortPowerCtrlMask[1];
  49044. +} UPACKED usb_hub_descriptor_t;
  49045. +#define USB_HUB_DESCRIPTOR_SIZE 9 /* includes deprecated PortPowerCtrlMask */
  49046. +
  49047. +typedef struct {
  49048. + uByte bLength;
  49049. + uByte bDescriptorType;
  49050. + uWord bcdUSB;
  49051. + uByte bDeviceClass;
  49052. + uByte bDeviceSubClass;
  49053. + uByte bDeviceProtocol;
  49054. + uByte bMaxPacketSize0;
  49055. + uByte bNumConfigurations;
  49056. + uByte bReserved;
  49057. +} UPACKED usb_device_qualifier_t;
  49058. +#define USB_DEVICE_QUALIFIER_SIZE 10
  49059. +
  49060. +typedef struct {
  49061. + uByte bLength;
  49062. + uByte bDescriptorType;
  49063. + uByte bmAttributes;
  49064. +#define UOTG_SRP 0x01
  49065. +#define UOTG_HNP 0x02
  49066. +} UPACKED usb_otg_descriptor_t;
  49067. +
  49068. +/* OTG feature selectors */
  49069. +#define UOTG_B_HNP_ENABLE 3
  49070. +#define UOTG_A_HNP_SUPPORT 4
  49071. +#define UOTG_A_ALT_HNP_SUPPORT 5
  49072. +
  49073. +typedef struct {
  49074. + uWord wStatus;
  49075. +/* Device status flags */
  49076. +#define UDS_SELF_POWERED 0x0001
  49077. +#define UDS_REMOTE_WAKEUP 0x0002
  49078. +/* Endpoint status flags */
  49079. +#define UES_HALT 0x0001
  49080. +} UPACKED usb_status_t;
  49081. +
  49082. +typedef struct {
  49083. + uWord wHubStatus;
  49084. +#define UHS_LOCAL_POWER 0x0001
  49085. +#define UHS_OVER_CURRENT 0x0002
  49086. + uWord wHubChange;
  49087. +} UPACKED usb_hub_status_t;
  49088. +
  49089. +typedef struct {
  49090. + uWord wPortStatus;
  49091. +#define UPS_CURRENT_CONNECT_STATUS 0x0001
  49092. +#define UPS_PORT_ENABLED 0x0002
  49093. +#define UPS_SUSPEND 0x0004
  49094. +#define UPS_OVERCURRENT_INDICATOR 0x0008
  49095. +#define UPS_RESET 0x0010
  49096. +#define UPS_PORT_POWER 0x0100
  49097. +#define UPS_LOW_SPEED 0x0200
  49098. +#define UPS_HIGH_SPEED 0x0400
  49099. +#define UPS_PORT_TEST 0x0800
  49100. +#define UPS_PORT_INDICATOR 0x1000
  49101. + uWord wPortChange;
  49102. +#define UPS_C_CONNECT_STATUS 0x0001
  49103. +#define UPS_C_PORT_ENABLED 0x0002
  49104. +#define UPS_C_SUSPEND 0x0004
  49105. +#define UPS_C_OVERCURRENT_INDICATOR 0x0008
  49106. +#define UPS_C_PORT_RESET 0x0010
  49107. +} UPACKED usb_port_status_t;
  49108. +
  49109. +#ifdef _MSC_VER
  49110. +#include <poppack.h>
  49111. +#endif
  49112. +
  49113. +/* Device class codes */
  49114. +#define UDCLASS_IN_INTERFACE 0x00
  49115. +#define UDCLASS_COMM 0x02
  49116. +#define UDCLASS_HUB 0x09
  49117. +#define UDSUBCLASS_HUB 0x00
  49118. +#define UDPROTO_FSHUB 0x00
  49119. +#define UDPROTO_HSHUBSTT 0x01
  49120. +#define UDPROTO_HSHUBMTT 0x02
  49121. +#define UDCLASS_DIAGNOSTIC 0xdc
  49122. +#define UDCLASS_WIRELESS 0xe0
  49123. +#define UDSUBCLASS_RF 0x01
  49124. +#define UDPROTO_BLUETOOTH 0x01
  49125. +#define UDCLASS_VENDOR 0xff
  49126. +
  49127. +/* Interface class codes */
  49128. +#define UICLASS_UNSPEC 0x00
  49129. +
  49130. +#define UICLASS_AUDIO 0x01
  49131. +#define UISUBCLASS_AUDIOCONTROL 1
  49132. +#define UISUBCLASS_AUDIOSTREAM 2
  49133. +#define UISUBCLASS_MIDISTREAM 3
  49134. +
  49135. +#define UICLASS_CDC 0x02 /* communication */
  49136. +#define UISUBCLASS_DIRECT_LINE_CONTROL_MODEL 1
  49137. +#define UISUBCLASS_ABSTRACT_CONTROL_MODEL 2
  49138. +#define UISUBCLASS_TELEPHONE_CONTROL_MODEL 3
  49139. +#define UISUBCLASS_MULTICHANNEL_CONTROL_MODEL 4
  49140. +#define UISUBCLASS_CAPI_CONTROLMODEL 5
  49141. +#define UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL 6
  49142. +#define UISUBCLASS_ATM_NETWORKING_CONTROL_MODEL 7
  49143. +#define UIPROTO_CDC_AT 1
  49144. +
  49145. +#define UICLASS_HID 0x03
  49146. +#define UISUBCLASS_BOOT 1
  49147. +#define UIPROTO_BOOT_KEYBOARD 1
  49148. +
  49149. +#define UICLASS_PHYSICAL 0x05
  49150. +
  49151. +#define UICLASS_IMAGE 0x06
  49152. +
  49153. +#define UICLASS_PRINTER 0x07
  49154. +#define UISUBCLASS_PRINTER 1
  49155. +#define UIPROTO_PRINTER_UNI 1
  49156. +#define UIPROTO_PRINTER_BI 2
  49157. +#define UIPROTO_PRINTER_1284 3
  49158. +
  49159. +#define UICLASS_MASS 0x08
  49160. +#define UISUBCLASS_RBC 1
  49161. +#define UISUBCLASS_SFF8020I 2
  49162. +#define UISUBCLASS_QIC157 3
  49163. +#define UISUBCLASS_UFI 4
  49164. +#define UISUBCLASS_SFF8070I 5
  49165. +#define UISUBCLASS_SCSI 6
  49166. +#define UIPROTO_MASS_CBI_I 0
  49167. +#define UIPROTO_MASS_CBI 1
  49168. +#define UIPROTO_MASS_BBB_OLD 2 /* Not in the spec anymore */
  49169. +#define UIPROTO_MASS_BBB 80 /* 'P' for the Iomega Zip drive */
  49170. +
  49171. +#define UICLASS_HUB 0x09
  49172. +#define UISUBCLASS_HUB 0
  49173. +#define UIPROTO_FSHUB 0
  49174. +#define UIPROTO_HSHUBSTT 0 /* Yes, same as previous */
  49175. +#define UIPROTO_HSHUBMTT 1
  49176. +
  49177. +#define UICLASS_CDC_DATA 0x0a
  49178. +#define UISUBCLASS_DATA 0
  49179. +#define UIPROTO_DATA_ISDNBRI 0x30 /* Physical iface */
  49180. +#define UIPROTO_DATA_HDLC 0x31 /* HDLC */
  49181. +#define UIPROTO_DATA_TRANSPARENT 0x32 /* Transparent */
  49182. +#define UIPROTO_DATA_Q921M 0x50 /* Management for Q921 */
  49183. +#define UIPROTO_DATA_Q921 0x51 /* Data for Q921 */
  49184. +#define UIPROTO_DATA_Q921TM 0x52 /* TEI multiplexer for Q921 */
  49185. +#define UIPROTO_DATA_V42BIS 0x90 /* Data compression */
  49186. +#define UIPROTO_DATA_Q931 0x91 /* Euro-ISDN */
  49187. +#define UIPROTO_DATA_V120 0x92 /* V.24 rate adaption */
  49188. +#define UIPROTO_DATA_CAPI 0x93 /* CAPI 2.0 commands */
  49189. +#define UIPROTO_DATA_HOST_BASED 0xfd /* Host based driver */
  49190. +#define UIPROTO_DATA_PUF 0xfe /* see Prot. Unit Func. Desc.*/
  49191. +#define UIPROTO_DATA_VENDOR 0xff /* Vendor specific */
  49192. +
  49193. +#define UICLASS_SMARTCARD 0x0b
  49194. +
  49195. +/*#define UICLASS_FIRM_UPD 0x0c*/
  49196. +
  49197. +#define UICLASS_SECURITY 0x0d
  49198. +
  49199. +#define UICLASS_DIAGNOSTIC 0xdc
  49200. +
  49201. +#define UICLASS_WIRELESS 0xe0
  49202. +#define UISUBCLASS_RF 0x01
  49203. +#define UIPROTO_BLUETOOTH 0x01
  49204. +
  49205. +#define UICLASS_APPL_SPEC 0xfe
  49206. +#define UISUBCLASS_FIRMWARE_DOWNLOAD 1
  49207. +#define UISUBCLASS_IRDA 2
  49208. +#define UIPROTO_IRDA 0
  49209. +
  49210. +#define UICLASS_VENDOR 0xff
  49211. +
  49212. +#define USB_HUB_MAX_DEPTH 5
  49213. +
  49214. +/*
  49215. + * Minimum time a device needs to be powered down to go through
  49216. + * a power cycle. XXX Are these time in the spec?
  49217. + */
  49218. +#define USB_POWER_DOWN_TIME 200 /* ms */
  49219. +#define USB_PORT_POWER_DOWN_TIME 100 /* ms */
  49220. +
  49221. +#if 0
  49222. +/* These are the values from the spec. */
  49223. +#define USB_PORT_RESET_DELAY 10 /* ms */
  49224. +#define USB_PORT_ROOT_RESET_DELAY 50 /* ms */
  49225. +#define USB_PORT_RESET_RECOVERY 10 /* ms */
  49226. +#define USB_PORT_POWERUP_DELAY 100 /* ms */
  49227. +#define USB_SET_ADDRESS_SETTLE 2 /* ms */
  49228. +#define USB_RESUME_DELAY (20*5) /* ms */
  49229. +#define USB_RESUME_WAIT 10 /* ms */
  49230. +#define USB_RESUME_RECOVERY 10 /* ms */
  49231. +#define USB_EXTRA_POWER_UP_TIME 0 /* ms */
  49232. +#else
  49233. +/* Allow for marginal (i.e. non-conforming) devices. */
  49234. +#define USB_PORT_RESET_DELAY 50 /* ms */
  49235. +#define USB_PORT_ROOT_RESET_DELAY 250 /* ms */
  49236. +#define USB_PORT_RESET_RECOVERY 250 /* ms */
  49237. +#define USB_PORT_POWERUP_DELAY 300 /* ms */
  49238. +#define USB_SET_ADDRESS_SETTLE 10 /* ms */
  49239. +#define USB_RESUME_DELAY (50*5) /* ms */
  49240. +#define USB_RESUME_WAIT 50 /* ms */
  49241. +#define USB_RESUME_RECOVERY 50 /* ms */
  49242. +#define USB_EXTRA_POWER_UP_TIME 20 /* ms */
  49243. +#endif
  49244. +
  49245. +#define USB_MIN_POWER 100 /* mA */
  49246. +#define USB_MAX_POWER 500 /* mA */
  49247. +
  49248. +#define USB_BUS_RESET_DELAY 100 /* ms XXX?*/
  49249. +
  49250. +#define USB_UNCONFIG_NO 0
  49251. +#define USB_UNCONFIG_INDEX (-1)
  49252. +
  49253. +/*** ioctl() related stuff ***/
  49254. +
  49255. +struct usb_ctl_request {
  49256. + int ucr_addr;
  49257. + usb_device_request_t ucr_request;
  49258. + void *ucr_data;
  49259. + int ucr_flags;
  49260. +#define USBD_SHORT_XFER_OK 0x04 /* allow short reads */
  49261. + int ucr_actlen; /* actual length transferred */
  49262. +};
  49263. +
  49264. +struct usb_alt_interface {
  49265. + int uai_config_index;
  49266. + int uai_interface_index;
  49267. + int uai_alt_no;
  49268. +};
  49269. +
  49270. +#define USB_CURRENT_CONFIG_INDEX (-1)
  49271. +#define USB_CURRENT_ALT_INDEX (-1)
  49272. +
  49273. +struct usb_config_desc {
  49274. + int ucd_config_index;
  49275. + usb_config_descriptor_t ucd_desc;
  49276. +};
  49277. +
  49278. +struct usb_interface_desc {
  49279. + int uid_config_index;
  49280. + int uid_interface_index;
  49281. + int uid_alt_index;
  49282. + usb_interface_descriptor_t uid_desc;
  49283. +};
  49284. +
  49285. +struct usb_endpoint_desc {
  49286. + int ued_config_index;
  49287. + int ued_interface_index;
  49288. + int ued_alt_index;
  49289. + int ued_endpoint_index;
  49290. + usb_endpoint_descriptor_t ued_desc;
  49291. +};
  49292. +
  49293. +struct usb_full_desc {
  49294. + int ufd_config_index;
  49295. + u_int ufd_size;
  49296. + u_char *ufd_data;
  49297. +};
  49298. +
  49299. +struct usb_string_desc {
  49300. + int usd_string_index;
  49301. + int usd_language_id;
  49302. + usb_string_descriptor_t usd_desc;
  49303. +};
  49304. +
  49305. +struct usb_ctl_report_desc {
  49306. + int ucrd_size;
  49307. + u_char ucrd_data[1024]; /* filled data size will vary */
  49308. +};
  49309. +
  49310. +typedef struct { u_int32_t cookie; } usb_event_cookie_t;
  49311. +
  49312. +#define USB_MAX_DEVNAMES 4
  49313. +#define USB_MAX_DEVNAMELEN 16
  49314. +struct usb_device_info {
  49315. + u_int8_t udi_bus;
  49316. + u_int8_t udi_addr; /* device address */
  49317. + usb_event_cookie_t udi_cookie;
  49318. + char udi_product[USB_MAX_STRING_LEN];
  49319. + char udi_vendor[USB_MAX_STRING_LEN];
  49320. + char udi_release[8];
  49321. + u_int16_t udi_productNo;
  49322. + u_int16_t udi_vendorNo;
  49323. + u_int16_t udi_releaseNo;
  49324. + u_int8_t udi_class;
  49325. + u_int8_t udi_subclass;
  49326. + u_int8_t udi_protocol;
  49327. + u_int8_t udi_config;
  49328. + u_int8_t udi_speed;
  49329. +#define USB_SPEED_UNKNOWN 0
  49330. +#define USB_SPEED_LOW 1
  49331. +#define USB_SPEED_FULL 2
  49332. +#define USB_SPEED_HIGH 3
  49333. +#define USB_SPEED_VARIABLE 4
  49334. +#define USB_SPEED_SUPER 5
  49335. + int udi_power; /* power consumption in mA, 0 if selfpowered */
  49336. + int udi_nports;
  49337. + char udi_devnames[USB_MAX_DEVNAMES][USB_MAX_DEVNAMELEN];
  49338. + u_int8_t udi_ports[16];/* hub only: addresses of devices on ports */
  49339. +#define USB_PORT_ENABLED 0xff
  49340. +#define USB_PORT_SUSPENDED 0xfe
  49341. +#define USB_PORT_POWERED 0xfd
  49342. +#define USB_PORT_DISABLED 0xfc
  49343. +};
  49344. +
  49345. +struct usb_ctl_report {
  49346. + int ucr_report;
  49347. + u_char ucr_data[1024]; /* filled data size will vary */
  49348. +};
  49349. +
  49350. +struct usb_device_stats {
  49351. + u_long uds_requests[4]; /* indexed by transfer type UE_* */
  49352. +};
  49353. +
  49354. +#define WUSB_MIN_IE 0x80
  49355. +#define WUSB_WCTA_IE 0x80
  49356. +#define WUSB_WCONNECTACK_IE 0x81
  49357. +#define WUSB_WHOSTINFO_IE 0x82
  49358. +#define WUHI_GET_CA(_bmAttributes_) ((_bmAttributes_) & 0x3)
  49359. +#define WUHI_CA_RECONN 0x00
  49360. +#define WUHI_CA_LIMITED 0x01
  49361. +#define WUHI_CA_ALL 0x03
  49362. +#define WUHI_GET_MLSI(_bmAttributes_) (((_bmAttributes_) & 0x38) >> 3)
  49363. +#define WUSB_WCHCHANGEANNOUNCE_IE 0x83
  49364. +#define WUSB_WDEV_DISCONNECT_IE 0x84
  49365. +#define WUSB_WHOST_DISCONNECT_IE 0x85
  49366. +#define WUSB_WRELEASE_CHANNEL_IE 0x86
  49367. +#define WUSB_WWORK_IE 0x87
  49368. +#define WUSB_WCHANNEL_STOP_IE 0x88
  49369. +#define WUSB_WDEV_KEEPALIVE_IE 0x89
  49370. +#define WUSB_WISOCH_DISCARD_IE 0x8A
  49371. +#define WUSB_WRESETDEVICE_IE 0x8B
  49372. +#define WUSB_WXMIT_PACKET_ADJUST_IE 0x8C
  49373. +#define WUSB_MAX_IE 0x8C
  49374. +
  49375. +/* Device Notification Types */
  49376. +
  49377. +#define WUSB_DN_MIN 0x01
  49378. +#define WUSB_DN_CONNECT 0x01
  49379. +# define WUSB_DA_OLDCONN 0x00
  49380. +# define WUSB_DA_NEWCONN 0x01
  49381. +# define WUSB_DA_SELF_BEACON 0x02
  49382. +# define WUSB_DA_DIR_BEACON 0x04
  49383. +# define WUSB_DA_NO_BEACON 0x06
  49384. +#define WUSB_DN_DISCONNECT 0x02
  49385. +#define WUSB_DN_EPRDY 0x03
  49386. +#define WUSB_DN_MASAVAILCHANGED 0x04
  49387. +#define WUSB_DN_REMOTEWAKEUP 0x05
  49388. +#define WUSB_DN_SLEEP 0x06
  49389. +#define WUSB_DN_ALIVE 0x07
  49390. +#define WUSB_DN_MAX 0x07
  49391. +
  49392. +#ifdef _MSC_VER
  49393. +#include <pshpack1.h>
  49394. +#endif
  49395. +
  49396. +/* WUSB Handshake Data. Used during the SET/GET HANDSHAKE requests */
  49397. +typedef struct wusb_hndshk_data {
  49398. + uByte bMessageNumber;
  49399. + uByte bStatus;
  49400. + uByte tTKID[3];
  49401. + uByte bReserved;
  49402. + uByte CDID[16];
  49403. + uByte Nonce[16];
  49404. + uByte MIC[8];
  49405. +} UPACKED wusb_hndshk_data_t;
  49406. +#define WUSB_HANDSHAKE_LEN_FOR_MIC 38
  49407. +
  49408. +/* WUSB Connection Context */
  49409. +typedef struct wusb_conn_context {
  49410. + uByte CHID [16];
  49411. + uByte CDID [16];
  49412. + uByte CK [16];
  49413. +} UPACKED wusb_conn_context_t;
  49414. +
  49415. +/* WUSB Security Descriptor */
  49416. +typedef struct wusb_security_desc {
  49417. + uByte bLength;
  49418. + uByte bDescriptorType;
  49419. + uWord wTotalLength;
  49420. + uByte bNumEncryptionTypes;
  49421. +} UPACKED wusb_security_desc_t;
  49422. +
  49423. +/* WUSB Encryption Type Descriptor */
  49424. +typedef struct wusb_encrypt_type_desc {
  49425. + uByte bLength;
  49426. + uByte bDescriptorType;
  49427. +
  49428. + uByte bEncryptionType;
  49429. +#define WUETD_UNSECURE 0
  49430. +#define WUETD_WIRED 1
  49431. +#define WUETD_CCM_1 2
  49432. +#define WUETD_RSA_1 3
  49433. +
  49434. + uByte bEncryptionValue;
  49435. + uByte bAuthKeyIndex;
  49436. +} UPACKED wusb_encrypt_type_desc_t;
  49437. +
  49438. +/* WUSB Key Descriptor */
  49439. +typedef struct wusb_key_desc {
  49440. + uByte bLength;
  49441. + uByte bDescriptorType;
  49442. + uByte tTKID[3];
  49443. + uByte bReserved;
  49444. + uByte KeyData[1]; /* variable length */
  49445. +} UPACKED wusb_key_desc_t;
  49446. +
  49447. +/* WUSB BOS Descriptor (Binary device Object Store) */
  49448. +typedef struct wusb_bos_desc {
  49449. + uByte bLength;
  49450. + uByte bDescriptorType;
  49451. + uWord wTotalLength;
  49452. + uByte bNumDeviceCaps;
  49453. +} UPACKED wusb_bos_desc_t;
  49454. +
  49455. +#define USB_DEVICE_CAPABILITY_20_EXTENSION 0x02
  49456. +typedef struct usb_dev_cap_20_ext_desc {
  49457. + uByte bLength;
  49458. + uByte bDescriptorType;
  49459. + uByte bDevCapabilityType;
  49460. +#define USB_20_EXT_LPM 0x02
  49461. + uDWord bmAttributes;
  49462. +} UPACKED usb_dev_cap_20_ext_desc_t;
  49463. +
  49464. +#define USB_DEVICE_CAPABILITY_SS_USB 0x03
  49465. +typedef struct usb_dev_cap_ss_usb {
  49466. + uByte bLength;
  49467. + uByte bDescriptorType;
  49468. + uByte bDevCapabilityType;
  49469. +#define USB_DC_SS_USB_LTM_CAPABLE 0x02
  49470. + uByte bmAttributes;
  49471. +#define USB_DC_SS_USB_SPEED_SUPPORT_LOW 0x01
  49472. +#define USB_DC_SS_USB_SPEED_SUPPORT_FULL 0x02
  49473. +#define USB_DC_SS_USB_SPEED_SUPPORT_HIGH 0x04
  49474. +#define USB_DC_SS_USB_SPEED_SUPPORT_SS 0x08
  49475. + uWord wSpeedsSupported;
  49476. + uByte bFunctionalitySupport;
  49477. + uByte bU1DevExitLat;
  49478. + uWord wU2DevExitLat;
  49479. +} UPACKED usb_dev_cap_ss_usb_t;
  49480. +
  49481. +#define USB_DEVICE_CAPABILITY_CONTAINER_ID 0x04
  49482. +typedef struct usb_dev_cap_container_id {
  49483. + uByte bLength;
  49484. + uByte bDescriptorType;
  49485. + uByte bDevCapabilityType;
  49486. + uByte bReserved;
  49487. + uByte containerID[16];
  49488. +} UPACKED usb_dev_cap_container_id_t;
  49489. +
  49490. +/* Device Capability Type Codes */
  49491. +#define WUSB_DEVICE_CAPABILITY_WIRELESS_USB 0x01
  49492. +
  49493. +/* Device Capability Descriptor */
  49494. +typedef struct wusb_dev_cap_desc {
  49495. + uByte bLength;
  49496. + uByte bDescriptorType;
  49497. + uByte bDevCapabilityType;
  49498. + uByte caps[1]; /* Variable length */
  49499. +} UPACKED wusb_dev_cap_desc_t;
  49500. +
  49501. +/* Device Capability Descriptor */
  49502. +typedef struct wusb_dev_cap_uwb_desc {
  49503. + uByte bLength;
  49504. + uByte bDescriptorType;
  49505. + uByte bDevCapabilityType;
  49506. + uByte bmAttributes;
  49507. + uWord wPHYRates; /* Bitmap */
  49508. + uByte bmTFITXPowerInfo;
  49509. + uByte bmFFITXPowerInfo;
  49510. + uWord bmBandGroup;
  49511. + uByte bReserved;
  49512. +} UPACKED wusb_dev_cap_uwb_desc_t;
  49513. +
  49514. +/* Wireless USB Endpoint Companion Descriptor */
  49515. +typedef struct wusb_endpoint_companion_desc {
  49516. + uByte bLength;
  49517. + uByte bDescriptorType;
  49518. + uByte bMaxBurst;
  49519. + uByte bMaxSequence;
  49520. + uWord wMaxStreamDelay;
  49521. + uWord wOverTheAirPacketSize;
  49522. + uByte bOverTheAirInterval;
  49523. + uByte bmCompAttributes;
  49524. +} UPACKED wusb_endpoint_companion_desc_t;
  49525. +
  49526. +/* Wireless USB Numeric Association M1 Data Structure */
  49527. +typedef struct wusb_m1_data {
  49528. + uByte version;
  49529. + uWord langId;
  49530. + uByte deviceFriendlyNameLength;
  49531. + uByte sha_256_m3[32];
  49532. + uByte deviceFriendlyName[256];
  49533. +} UPACKED wusb_m1_data_t;
  49534. +
  49535. +typedef struct wusb_m2_data {
  49536. + uByte version;
  49537. + uWord langId;
  49538. + uByte hostFriendlyNameLength;
  49539. + uByte pkh[384];
  49540. + uByte hostFriendlyName[256];
  49541. +} UPACKED wusb_m2_data_t;
  49542. +
  49543. +typedef struct wusb_m3_data {
  49544. + uByte pkd[384];
  49545. + uByte nd;
  49546. +} UPACKED wusb_m3_data_t;
  49547. +
  49548. +typedef struct wusb_m4_data {
  49549. + uDWord _attributeTypeIdAndLength_1;
  49550. + uWord associationTypeId;
  49551. +
  49552. + uDWord _attributeTypeIdAndLength_2;
  49553. + uWord associationSubTypeId;
  49554. +
  49555. + uDWord _attributeTypeIdAndLength_3;
  49556. + uDWord length;
  49557. +
  49558. + uDWord _attributeTypeIdAndLength_4;
  49559. + uDWord associationStatus;
  49560. +
  49561. + uDWord _attributeTypeIdAndLength_5;
  49562. + uByte chid[16];
  49563. +
  49564. + uDWord _attributeTypeIdAndLength_6;
  49565. + uByte cdid[16];
  49566. +
  49567. + uDWord _attributeTypeIdAndLength_7;
  49568. + uByte bandGroups[2];
  49569. +} UPACKED wusb_m4_data_t;
  49570. +
  49571. +#ifdef _MSC_VER
  49572. +#include <poppack.h>
  49573. +#endif
  49574. +
  49575. +#ifdef __cplusplus
  49576. +}
  49577. +#endif
  49578. +
  49579. +#endif /* _USB_H_ */
  49580. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_otg/doc/doxygen.cfg linux-3.12.26/drivers/usb/host/dwc_otg/doc/doxygen.cfg
  49581. --- linux-3.12.26.orig/drivers/usb/host/dwc_otg/doc/doxygen.cfg 1970-01-01 01:00:00.000000000 +0100
  49582. +++ linux-3.12.26/drivers/usb/host/dwc_otg/doc/doxygen.cfg 2014-08-06 16:50:14.781964569 +0200
  49583. @@ -0,0 +1,224 @@
  49584. +# Doxyfile 1.3.9.1
  49585. +
  49586. +#---------------------------------------------------------------------------
  49587. +# Project related configuration options
  49588. +#---------------------------------------------------------------------------
  49589. +PROJECT_NAME = "DesignWare USB 2.0 OTG Controller (DWC_otg) Device Driver"
  49590. +PROJECT_NUMBER = v3.00a
  49591. +OUTPUT_DIRECTORY = ./doc/
  49592. +CREATE_SUBDIRS = NO
  49593. +OUTPUT_LANGUAGE = English
  49594. +BRIEF_MEMBER_DESC = YES
  49595. +REPEAT_BRIEF = YES
  49596. +ABBREVIATE_BRIEF = "The $name class" \
  49597. + "The $name widget" \
  49598. + "The $name file" \
  49599. + is \
  49600. + provides \
  49601. + specifies \
  49602. + contains \
  49603. + represents \
  49604. + a \
  49605. + an \
  49606. + the
  49607. +ALWAYS_DETAILED_SEC = NO
  49608. +INLINE_INHERITED_MEMB = NO
  49609. +FULL_PATH_NAMES = NO
  49610. +STRIP_FROM_PATH =
  49611. +STRIP_FROM_INC_PATH =
  49612. +SHORT_NAMES = NO
  49613. +JAVADOC_AUTOBRIEF = YES
  49614. +MULTILINE_CPP_IS_BRIEF = NO
  49615. +INHERIT_DOCS = YES
  49616. +DISTRIBUTE_GROUP_DOC = NO
  49617. +TAB_SIZE = 8
  49618. +ALIASES =
  49619. +OPTIMIZE_OUTPUT_FOR_C = YES
  49620. +OPTIMIZE_OUTPUT_JAVA = NO
  49621. +SUBGROUPING = YES
  49622. +#---------------------------------------------------------------------------
  49623. +# Build related configuration options
  49624. +#---------------------------------------------------------------------------
  49625. +EXTRACT_ALL = NO
  49626. +EXTRACT_PRIVATE = YES
  49627. +EXTRACT_STATIC = YES
  49628. +EXTRACT_LOCAL_CLASSES = YES
  49629. +EXTRACT_LOCAL_METHODS = NO
  49630. +HIDE_UNDOC_MEMBERS = NO
  49631. +HIDE_UNDOC_CLASSES = NO
  49632. +HIDE_FRIEND_COMPOUNDS = NO
  49633. +HIDE_IN_BODY_DOCS = NO
  49634. +INTERNAL_DOCS = NO
  49635. +CASE_SENSE_NAMES = NO
  49636. +HIDE_SCOPE_NAMES = NO
  49637. +SHOW_INCLUDE_FILES = YES
  49638. +INLINE_INFO = YES
  49639. +SORT_MEMBER_DOCS = NO
  49640. +SORT_BRIEF_DOCS = NO
  49641. +SORT_BY_SCOPE_NAME = NO
  49642. +GENERATE_TODOLIST = YES
  49643. +GENERATE_TESTLIST = YES
  49644. +GENERATE_BUGLIST = YES
  49645. +GENERATE_DEPRECATEDLIST= YES
  49646. +ENABLED_SECTIONS =
  49647. +MAX_INITIALIZER_LINES = 30
  49648. +SHOW_USED_FILES = YES
  49649. +SHOW_DIRECTORIES = YES
  49650. +#---------------------------------------------------------------------------
  49651. +# configuration options related to warning and progress messages
  49652. +#---------------------------------------------------------------------------
  49653. +QUIET = YES
  49654. +WARNINGS = YES
  49655. +WARN_IF_UNDOCUMENTED = NO
  49656. +WARN_IF_DOC_ERROR = YES
  49657. +WARN_FORMAT = "$file:$line: $text"
  49658. +WARN_LOGFILE =
  49659. +#---------------------------------------------------------------------------
  49660. +# configuration options related to the input files
  49661. +#---------------------------------------------------------------------------
  49662. +INPUT = .
  49663. +FILE_PATTERNS = *.c \
  49664. + *.h \
  49665. + ./linux/*.c \
  49666. + ./linux/*.h
  49667. +RECURSIVE = NO
  49668. +EXCLUDE = ./test/ \
  49669. + ./dwc_otg/.AppleDouble/
  49670. +EXCLUDE_SYMLINKS = YES
  49671. +EXCLUDE_PATTERNS = *.mod.*
  49672. +EXAMPLE_PATH =
  49673. +EXAMPLE_PATTERNS = *
  49674. +EXAMPLE_RECURSIVE = NO
  49675. +IMAGE_PATH =
  49676. +INPUT_FILTER =
  49677. +FILTER_PATTERNS =
  49678. +FILTER_SOURCE_FILES = NO
  49679. +#---------------------------------------------------------------------------
  49680. +# configuration options related to source browsing
  49681. +#---------------------------------------------------------------------------
  49682. +SOURCE_BROWSER = YES
  49683. +INLINE_SOURCES = NO
  49684. +STRIP_CODE_COMMENTS = YES
  49685. +REFERENCED_BY_RELATION = NO
  49686. +REFERENCES_RELATION = NO
  49687. +VERBATIM_HEADERS = NO
  49688. +#---------------------------------------------------------------------------
  49689. +# configuration options related to the alphabetical class index
  49690. +#---------------------------------------------------------------------------
  49691. +ALPHABETICAL_INDEX = NO
  49692. +COLS_IN_ALPHA_INDEX = 5
  49693. +IGNORE_PREFIX =
  49694. +#---------------------------------------------------------------------------
  49695. +# configuration options related to the HTML output
  49696. +#---------------------------------------------------------------------------
  49697. +GENERATE_HTML = YES
  49698. +HTML_OUTPUT = html
  49699. +HTML_FILE_EXTENSION = .html
  49700. +HTML_HEADER =
  49701. +HTML_FOOTER =
  49702. +HTML_STYLESHEET =
  49703. +HTML_ALIGN_MEMBERS = YES
  49704. +GENERATE_HTMLHELP = NO
  49705. +CHM_FILE =
  49706. +HHC_LOCATION =
  49707. +GENERATE_CHI = NO
  49708. +BINARY_TOC = NO
  49709. +TOC_EXPAND = NO
  49710. +DISABLE_INDEX = NO
  49711. +ENUM_VALUES_PER_LINE = 4
  49712. +GENERATE_TREEVIEW = YES
  49713. +TREEVIEW_WIDTH = 250
  49714. +#---------------------------------------------------------------------------
  49715. +# configuration options related to the LaTeX output
  49716. +#---------------------------------------------------------------------------
  49717. +GENERATE_LATEX = NO
  49718. +LATEX_OUTPUT = latex
  49719. +LATEX_CMD_NAME = latex
  49720. +MAKEINDEX_CMD_NAME = makeindex
  49721. +COMPACT_LATEX = NO
  49722. +PAPER_TYPE = a4wide
  49723. +EXTRA_PACKAGES =
  49724. +LATEX_HEADER =
  49725. +PDF_HYPERLINKS = NO
  49726. +USE_PDFLATEX = NO
  49727. +LATEX_BATCHMODE = NO
  49728. +LATEX_HIDE_INDICES = NO
  49729. +#---------------------------------------------------------------------------
  49730. +# configuration options related to the RTF output
  49731. +#---------------------------------------------------------------------------
  49732. +GENERATE_RTF = NO
  49733. +RTF_OUTPUT = rtf
  49734. +COMPACT_RTF = NO
  49735. +RTF_HYPERLINKS = NO
  49736. +RTF_STYLESHEET_FILE =
  49737. +RTF_EXTENSIONS_FILE =
  49738. +#---------------------------------------------------------------------------
  49739. +# configuration options related to the man page output
  49740. +#---------------------------------------------------------------------------
  49741. +GENERATE_MAN = NO
  49742. +MAN_OUTPUT = man
  49743. +MAN_EXTENSION = .3
  49744. +MAN_LINKS = NO
  49745. +#---------------------------------------------------------------------------
  49746. +# configuration options related to the XML output
  49747. +#---------------------------------------------------------------------------
  49748. +GENERATE_XML = NO
  49749. +XML_OUTPUT = xml
  49750. +XML_SCHEMA =
  49751. +XML_DTD =
  49752. +XML_PROGRAMLISTING = YES
  49753. +#---------------------------------------------------------------------------
  49754. +# configuration options for the AutoGen Definitions output
  49755. +#---------------------------------------------------------------------------
  49756. +GENERATE_AUTOGEN_DEF = NO
  49757. +#---------------------------------------------------------------------------
  49758. +# configuration options related to the Perl module output
  49759. +#---------------------------------------------------------------------------
  49760. +GENERATE_PERLMOD = NO
  49761. +PERLMOD_LATEX = NO
  49762. +PERLMOD_PRETTY = YES
  49763. +PERLMOD_MAKEVAR_PREFIX =
  49764. +#---------------------------------------------------------------------------
  49765. +# Configuration options related to the preprocessor
  49766. +#---------------------------------------------------------------------------
  49767. +ENABLE_PREPROCESSING = YES
  49768. +MACRO_EXPANSION = YES
  49769. +EXPAND_ONLY_PREDEF = YES
  49770. +SEARCH_INCLUDES = YES
  49771. +INCLUDE_PATH =
  49772. +INCLUDE_FILE_PATTERNS =
  49773. +PREDEFINED = DEVICE_ATTR DWC_EN_ISOC
  49774. +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
  49775. +SKIP_FUNCTION_MACROS = NO
  49776. +#---------------------------------------------------------------------------
  49777. +# Configuration::additions related to external references
  49778. +#---------------------------------------------------------------------------
  49779. +TAGFILES =
  49780. +GENERATE_TAGFILE =
  49781. +ALLEXTERNALS = NO
  49782. +EXTERNAL_GROUPS = YES
  49783. +PERL_PATH = /usr/bin/perl
  49784. +#---------------------------------------------------------------------------
  49785. +# Configuration options related to the dot tool
  49786. +#---------------------------------------------------------------------------
  49787. +CLASS_DIAGRAMS = YES
  49788. +HIDE_UNDOC_RELATIONS = YES
  49789. +HAVE_DOT = NO
  49790. +CLASS_GRAPH = YES
  49791. +COLLABORATION_GRAPH = YES
  49792. +UML_LOOK = NO
  49793. +TEMPLATE_RELATIONS = NO
  49794. +INCLUDE_GRAPH = YES
  49795. +INCLUDED_BY_GRAPH = YES
  49796. +CALL_GRAPH = NO
  49797. +GRAPHICAL_HIERARCHY = YES
  49798. +DOT_IMAGE_FORMAT = png
  49799. +DOT_PATH =
  49800. +DOTFILE_DIRS =
  49801. +MAX_DOT_GRAPH_DEPTH = 1000
  49802. +GENERATE_LEGEND = YES
  49803. +DOT_CLEANUP = YES
  49804. +#---------------------------------------------------------------------------
  49805. +# Configuration::additions related to the search engine
  49806. +#---------------------------------------------------------------------------
  49807. +SEARCHENGINE = NO
  49808. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_otg/dummy_audio.c linux-3.12.26/drivers/usb/host/dwc_otg/dummy_audio.c
  49809. --- linux-3.12.26.orig/drivers/usb/host/dwc_otg/dummy_audio.c 1970-01-01 01:00:00.000000000 +0100
  49810. +++ linux-3.12.26/drivers/usb/host/dwc_otg/dummy_audio.c 2014-08-06 16:50:14.781964569 +0200
  49811. @@ -0,0 +1,1575 @@
  49812. +/*
  49813. + * zero.c -- Gadget Zero, for USB development
  49814. + *
  49815. + * Copyright (C) 2003-2004 David Brownell
  49816. + * All rights reserved.
  49817. + *
  49818. + * Redistribution and use in source and binary forms, with or without
  49819. + * modification, are permitted provided that the following conditions
  49820. + * are met:
  49821. + * 1. Redistributions of source code must retain the above copyright
  49822. + * notice, this list of conditions, and the following disclaimer,
  49823. + * without modification.
  49824. + * 2. Redistributions in binary form must reproduce the above copyright
  49825. + * notice, this list of conditions and the following disclaimer in the
  49826. + * documentation and/or other materials provided with the distribution.
  49827. + * 3. The names of the above-listed copyright holders may not be used
  49828. + * to endorse or promote products derived from this software without
  49829. + * specific prior written permission.
  49830. + *
  49831. + * ALTERNATIVELY, this software may be distributed under the terms of the
  49832. + * GNU General Public License ("GPL") as published by the Free Software
  49833. + * Foundation, either version 2 of that License or (at your option) any
  49834. + * later version.
  49835. + *
  49836. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  49837. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  49838. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  49839. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  49840. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  49841. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  49842. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  49843. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  49844. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  49845. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  49846. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  49847. + */
  49848. +
  49849. +
  49850. +/*
  49851. + * Gadget Zero only needs two bulk endpoints, and is an example of how you
  49852. + * can write a hardware-agnostic gadget driver running inside a USB device.
  49853. + *
  49854. + * Hardware details are visible (see CONFIG_USB_ZERO_* below) but don't
  49855. + * affect most of the driver.
  49856. + *
  49857. + * Use it with the Linux host/master side "usbtest" driver to get a basic
  49858. + * functional test of your device-side usb stack, or with "usb-skeleton".
  49859. + *
  49860. + * It supports two similar configurations. One sinks whatever the usb host
  49861. + * writes, and in return sources zeroes. The other loops whatever the host
  49862. + * writes back, so the host can read it. Module options include:
  49863. + *
  49864. + * buflen=N default N=4096, buffer size used
  49865. + * qlen=N default N=32, how many buffers in the loopback queue
  49866. + * loopdefault default false, list loopback config first
  49867. + *
  49868. + * Many drivers will only have one configuration, letting them be much
  49869. + * simpler if they also don't support high speed operation (like this
  49870. + * driver does).
  49871. + */
  49872. +
  49873. +#include <linux/config.h>
  49874. +#include <linux/module.h>
  49875. +#include <linux/kernel.h>
  49876. +#include <linux/delay.h>
  49877. +#include <linux/ioport.h>
  49878. +#include <linux/sched.h>
  49879. +#include <linux/slab.h>
  49880. +#include <linux/smp_lock.h>
  49881. +#include <linux/errno.h>
  49882. +#include <linux/init.h>
  49883. +#include <linux/timer.h>
  49884. +#include <linux/list.h>
  49885. +#include <linux/interrupt.h>
  49886. +#include <linux/uts.h>
  49887. +#include <linux/version.h>
  49888. +#include <linux/device.h>
  49889. +#include <linux/moduleparam.h>
  49890. +#include <linux/proc_fs.h>
  49891. +
  49892. +#include <asm/byteorder.h>
  49893. +#include <asm/io.h>
  49894. +#include <asm/irq.h>
  49895. +#include <asm/system.h>
  49896. +#include <asm/unaligned.h>
  49897. +
  49898. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
  49899. +# include <linux/usb/ch9.h>
  49900. +#else
  49901. +# include <linux/usb_ch9.h>
  49902. +#endif
  49903. +
  49904. +#include <linux/usb_gadget.h>
  49905. +
  49906. +
  49907. +/*-------------------------------------------------------------------------*/
  49908. +/*-------------------------------------------------------------------------*/
  49909. +
  49910. +
  49911. +static int utf8_to_utf16le(const char *s, u16 *cp, unsigned len)
  49912. +{
  49913. + int count = 0;
  49914. + u8 c;
  49915. + u16 uchar;
  49916. +
  49917. + /* this insists on correct encodings, though not minimal ones.
  49918. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  49919. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  49920. + */
  49921. + while (len != 0 && (c = (u8) *s++) != 0) {
  49922. + if (unlikely(c & 0x80)) {
  49923. + // 2-byte sequence:
  49924. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  49925. + if ((c & 0xe0) == 0xc0) {
  49926. + uchar = (c & 0x1f) << 6;
  49927. +
  49928. + c = (u8) *s++;
  49929. + if ((c & 0xc0) != 0xc0)
  49930. + goto fail;
  49931. + c &= 0x3f;
  49932. + uchar |= c;
  49933. +
  49934. + // 3-byte sequence (most CJKV characters):
  49935. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  49936. + } else if ((c & 0xf0) == 0xe0) {
  49937. + uchar = (c & 0x0f) << 12;
  49938. +
  49939. + c = (u8) *s++;
  49940. + if ((c & 0xc0) != 0xc0)
  49941. + goto fail;
  49942. + c &= 0x3f;
  49943. + uchar |= c << 6;
  49944. +
  49945. + c = (u8) *s++;
  49946. + if ((c & 0xc0) != 0xc0)
  49947. + goto fail;
  49948. + c &= 0x3f;
  49949. + uchar |= c;
  49950. +
  49951. + /* no bogus surrogates */
  49952. + if (0xd800 <= uchar && uchar <= 0xdfff)
  49953. + goto fail;
  49954. +
  49955. + // 4-byte sequence (surrogate pairs, currently rare):
  49956. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  49957. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  49958. + // (uuuuu = wwww + 1)
  49959. + // FIXME accept the surrogate code points (only)
  49960. +
  49961. + } else
  49962. + goto fail;
  49963. + } else
  49964. + uchar = c;
  49965. + put_unaligned (cpu_to_le16 (uchar), cp++);
  49966. + count++;
  49967. + len--;
  49968. + }
  49969. + return count;
  49970. +fail:
  49971. + return -1;
  49972. +}
  49973. +
  49974. +
  49975. +/**
  49976. + * usb_gadget_get_string - fill out a string descriptor
  49977. + * @table: of c strings encoded using UTF-8
  49978. + * @id: string id, from low byte of wValue in get string descriptor
  49979. + * @buf: at least 256 bytes
  49980. + *
  49981. + * Finds the UTF-8 string matching the ID, and converts it into a
  49982. + * string descriptor in utf16-le.
  49983. + * Returns length of descriptor (always even) or negative errno
  49984. + *
  49985. + * If your driver needs stings in multiple languages, you'll probably
  49986. + * "switch (wIndex) { ... }" in your ep0 string descriptor logic,
  49987. + * using this routine after choosing which set of UTF-8 strings to use.
  49988. + * Note that US-ASCII is a strict subset of UTF-8; any string bytes with
  49989. + * the eighth bit set will be multibyte UTF-8 characters, not ISO-8859/1
  49990. + * characters (which are also widely used in C strings).
  49991. + */
  49992. +int
  49993. +usb_gadget_get_string (struct usb_gadget_strings *table, int id, u8 *buf)
  49994. +{
  49995. + struct usb_string *s;
  49996. + int len;
  49997. +
  49998. + /* descriptor 0 has the language id */
  49999. + if (id == 0) {
  50000. + buf [0] = 4;
  50001. + buf [1] = USB_DT_STRING;
  50002. + buf [2] = (u8) table->language;
  50003. + buf [3] = (u8) (table->language >> 8);
  50004. + return 4;
  50005. + }
  50006. + for (s = table->strings; s && s->s; s++)
  50007. + if (s->id == id)
  50008. + break;
  50009. +
  50010. + /* unrecognized: stall. */
  50011. + if (!s || !s->s)
  50012. + return -EINVAL;
  50013. +
  50014. + /* string descriptors have length, tag, then UTF16-LE text */
  50015. + len = min ((size_t) 126, strlen (s->s));
  50016. + memset (buf + 2, 0, 2 * len); /* zero all the bytes */
  50017. + len = utf8_to_utf16le(s->s, (u16 *)&buf[2], len);
  50018. + if (len < 0)
  50019. + return -EINVAL;
  50020. + buf [0] = (len + 1) * 2;
  50021. + buf [1] = USB_DT_STRING;
  50022. + return buf [0];
  50023. +}
  50024. +
  50025. +
  50026. +/*-------------------------------------------------------------------------*/
  50027. +/*-------------------------------------------------------------------------*/
  50028. +
  50029. +
  50030. +/**
  50031. + * usb_descriptor_fillbuf - fill buffer with descriptors
  50032. + * @buf: Buffer to be filled
  50033. + * @buflen: Size of buf
  50034. + * @src: Array of descriptor pointers, terminated by null pointer.
  50035. + *
  50036. + * Copies descriptors into the buffer, returning the length or a
  50037. + * negative error code if they can't all be copied. Useful when
  50038. + * assembling descriptors for an associated set of interfaces used
  50039. + * as part of configuring a composite device; or in other cases where
  50040. + * sets of descriptors need to be marshaled.
  50041. + */
  50042. +int
  50043. +usb_descriptor_fillbuf(void *buf, unsigned buflen,
  50044. + const struct usb_descriptor_header **src)
  50045. +{
  50046. + u8 *dest = buf;
  50047. +
  50048. + if (!src)
  50049. + return -EINVAL;
  50050. +
  50051. + /* fill buffer from src[] until null descriptor ptr */
  50052. + for (; 0 != *src; src++) {
  50053. + unsigned len = (*src)->bLength;
  50054. +
  50055. + if (len > buflen)
  50056. + return -EINVAL;
  50057. + memcpy(dest, *src, len);
  50058. + buflen -= len;
  50059. + dest += len;
  50060. + }
  50061. + return dest - (u8 *)buf;
  50062. +}
  50063. +
  50064. +
  50065. +/**
  50066. + * usb_gadget_config_buf - builts a complete configuration descriptor
  50067. + * @config: Header for the descriptor, including characteristics such
  50068. + * as power requirements and number of interfaces.
  50069. + * @desc: Null-terminated vector of pointers to the descriptors (interface,
  50070. + * endpoint, etc) defining all functions in this device configuration.
  50071. + * @buf: Buffer for the resulting configuration descriptor.
  50072. + * @length: Length of buffer. If this is not big enough to hold the
  50073. + * entire configuration descriptor, an error code will be returned.
  50074. + *
  50075. + * This copies descriptors into the response buffer, building a descriptor
  50076. + * for that configuration. It returns the buffer length or a negative
  50077. + * status code. The config.wTotalLength field is set to match the length
  50078. + * of the result, but other descriptor fields (including power usage and
  50079. + * interface count) must be set by the caller.
  50080. + *
  50081. + * Gadget drivers could use this when constructing a config descriptor
  50082. + * in response to USB_REQ_GET_DESCRIPTOR. They will need to patch the
  50083. + * resulting bDescriptorType value if USB_DT_OTHER_SPEED_CONFIG is needed.
  50084. + */
  50085. +int usb_gadget_config_buf(
  50086. + const struct usb_config_descriptor *config,
  50087. + void *buf,
  50088. + unsigned length,
  50089. + const struct usb_descriptor_header **desc
  50090. +)
  50091. +{
  50092. + struct usb_config_descriptor *cp = buf;
  50093. + int len;
  50094. +
  50095. + /* config descriptor first */
  50096. + if (length < USB_DT_CONFIG_SIZE || !desc)
  50097. + return -EINVAL;
  50098. + *cp = *config;
  50099. +
  50100. + /* then interface/endpoint/class/vendor/... */
  50101. + len = usb_descriptor_fillbuf(USB_DT_CONFIG_SIZE + (u8*)buf,
  50102. + length - USB_DT_CONFIG_SIZE, desc);
  50103. + if (len < 0)
  50104. + return len;
  50105. + len += USB_DT_CONFIG_SIZE;
  50106. + if (len > 0xffff)
  50107. + return -EINVAL;
  50108. +
  50109. + /* patch up the config descriptor */
  50110. + cp->bLength = USB_DT_CONFIG_SIZE;
  50111. + cp->bDescriptorType = USB_DT_CONFIG;
  50112. + cp->wTotalLength = cpu_to_le16(len);
  50113. + cp->bmAttributes |= USB_CONFIG_ATT_ONE;
  50114. + return len;
  50115. +}
  50116. +
  50117. +/*-------------------------------------------------------------------------*/
  50118. +/*-------------------------------------------------------------------------*/
  50119. +
  50120. +
  50121. +#define RBUF_LEN (1024*1024)
  50122. +static int rbuf_start;
  50123. +static int rbuf_len;
  50124. +static __u8 rbuf[RBUF_LEN];
  50125. +
  50126. +/*-------------------------------------------------------------------------*/
  50127. +
  50128. +#define DRIVER_VERSION "St Patrick's Day 2004"
  50129. +
  50130. +static const char shortname [] = "zero";
  50131. +static const char longname [] = "YAMAHA YST-MS35D USB Speaker ";
  50132. +
  50133. +static const char source_sink [] = "source and sink data";
  50134. +static const char loopback [] = "loop input to output";
  50135. +
  50136. +/*-------------------------------------------------------------------------*/
  50137. +
  50138. +/*
  50139. + * driver assumes self-powered hardware, and
  50140. + * has no way for users to trigger remote wakeup.
  50141. + *
  50142. + * this version autoconfigures as much as possible,
  50143. + * which is reasonable for most "bulk-only" drivers.
  50144. + */
  50145. +static const char *EP_IN_NAME; /* source */
  50146. +static const char *EP_OUT_NAME; /* sink */
  50147. +
  50148. +/*-------------------------------------------------------------------------*/
  50149. +
  50150. +/* big enough to hold our biggest descriptor */
  50151. +#define USB_BUFSIZ 512
  50152. +
  50153. +struct zero_dev {
  50154. + spinlock_t lock;
  50155. + struct usb_gadget *gadget;
  50156. + struct usb_request *req; /* for control responses */
  50157. +
  50158. + /* when configured, we have one of two configs:
  50159. + * - source data (in to host) and sink it (out from host)
  50160. + * - or loop it back (out from host back in to host)
  50161. + */
  50162. + u8 config;
  50163. + struct usb_ep *in_ep, *out_ep;
  50164. +
  50165. + /* autoresume timer */
  50166. + struct timer_list resume;
  50167. +};
  50168. +
  50169. +#define xprintk(d,level,fmt,args...) \
  50170. + dev_printk(level , &(d)->gadget->dev , fmt , ## args)
  50171. +
  50172. +#ifdef DEBUG
  50173. +#define DBG(dev,fmt,args...) \
  50174. + xprintk(dev , KERN_DEBUG , fmt , ## args)
  50175. +#else
  50176. +#define DBG(dev,fmt,args...) \
  50177. + do { } while (0)
  50178. +#endif /* DEBUG */
  50179. +
  50180. +#ifdef VERBOSE
  50181. +#define VDBG DBG
  50182. +#else
  50183. +#define VDBG(dev,fmt,args...) \
  50184. + do { } while (0)
  50185. +#endif /* VERBOSE */
  50186. +
  50187. +#define ERROR(dev,fmt,args...) \
  50188. + xprintk(dev , KERN_ERR , fmt , ## args)
  50189. +#define WARN(dev,fmt,args...) \
  50190. + xprintk(dev , KERN_WARNING , fmt , ## args)
  50191. +#define INFO(dev,fmt,args...) \
  50192. + xprintk(dev , KERN_INFO , fmt , ## args)
  50193. +
  50194. +/*-------------------------------------------------------------------------*/
  50195. +
  50196. +static unsigned buflen = 4096;
  50197. +static unsigned qlen = 32;
  50198. +static unsigned pattern = 0;
  50199. +
  50200. +module_param (buflen, uint, S_IRUGO|S_IWUSR);
  50201. +module_param (qlen, uint, S_IRUGO|S_IWUSR);
  50202. +module_param (pattern, uint, S_IRUGO|S_IWUSR);
  50203. +
  50204. +/*
  50205. + * if it's nonzero, autoresume says how many seconds to wait
  50206. + * before trying to wake up the host after suspend.
  50207. + */
  50208. +static unsigned autoresume = 0;
  50209. +module_param (autoresume, uint, 0);
  50210. +
  50211. +/*
  50212. + * Normally the "loopback" configuration is second (index 1) so
  50213. + * it's not the default. Here's where to change that order, to
  50214. + * work better with hosts where config changes are problematic.
  50215. + * Or controllers (like superh) that only support one config.
  50216. + */
  50217. +static int loopdefault = 0;
  50218. +
  50219. +module_param (loopdefault, bool, S_IRUGO|S_IWUSR);
  50220. +
  50221. +/*-------------------------------------------------------------------------*/
  50222. +
  50223. +/* Thanks to NetChip Technologies for donating this product ID.
  50224. + *
  50225. + * DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!!
  50226. + * Instead: allocate your own, using normal USB-IF procedures.
  50227. + */
  50228. +#ifndef CONFIG_USB_ZERO_HNPTEST
  50229. +#define DRIVER_VENDOR_NUM 0x0525 /* NetChip */
  50230. +#define DRIVER_PRODUCT_NUM 0xa4a0 /* Linux-USB "Gadget Zero" */
  50231. +#else
  50232. +#define DRIVER_VENDOR_NUM 0x1a0a /* OTG test device IDs */
  50233. +#define DRIVER_PRODUCT_NUM 0xbadd
  50234. +#endif
  50235. +
  50236. +/*-------------------------------------------------------------------------*/
  50237. +
  50238. +/*
  50239. + * DESCRIPTORS ... most are static, but strings and (full)
  50240. + * configuration descriptors are built on demand.
  50241. + */
  50242. +
  50243. +/*
  50244. +#define STRING_MANUFACTURER 25
  50245. +#define STRING_PRODUCT 42
  50246. +#define STRING_SERIAL 101
  50247. +*/
  50248. +#define STRING_MANUFACTURER 1
  50249. +#define STRING_PRODUCT 2
  50250. +#define STRING_SERIAL 3
  50251. +
  50252. +#define STRING_SOURCE_SINK 250
  50253. +#define STRING_LOOPBACK 251
  50254. +
  50255. +/*
  50256. + * This device advertises two configurations; these numbers work
  50257. + * on a pxa250 as well as more flexible hardware.
  50258. + */
  50259. +#define CONFIG_SOURCE_SINK 3
  50260. +#define CONFIG_LOOPBACK 2
  50261. +
  50262. +/*
  50263. +static struct usb_device_descriptor
  50264. +device_desc = {
  50265. + .bLength = sizeof device_desc,
  50266. + .bDescriptorType = USB_DT_DEVICE,
  50267. +
  50268. + .bcdUSB = __constant_cpu_to_le16 (0x0200),
  50269. + .bDeviceClass = USB_CLASS_VENDOR_SPEC,
  50270. +
  50271. + .idVendor = __constant_cpu_to_le16 (DRIVER_VENDOR_NUM),
  50272. + .idProduct = __constant_cpu_to_le16 (DRIVER_PRODUCT_NUM),
  50273. + .iManufacturer = STRING_MANUFACTURER,
  50274. + .iProduct = STRING_PRODUCT,
  50275. + .iSerialNumber = STRING_SERIAL,
  50276. + .bNumConfigurations = 2,
  50277. +};
  50278. +*/
  50279. +static struct usb_device_descriptor
  50280. +device_desc = {
  50281. + .bLength = sizeof device_desc,
  50282. + .bDescriptorType = USB_DT_DEVICE,
  50283. + .bcdUSB = __constant_cpu_to_le16 (0x0100),
  50284. + .bDeviceClass = USB_CLASS_PER_INTERFACE,
  50285. + .bDeviceSubClass = 0,
  50286. + .bDeviceProtocol = 0,
  50287. + .bMaxPacketSize0 = 64,
  50288. + .bcdDevice = __constant_cpu_to_le16 (0x0100),
  50289. + .idVendor = __constant_cpu_to_le16 (0x0499),
  50290. + .idProduct = __constant_cpu_to_le16 (0x3002),
  50291. + .iManufacturer = STRING_MANUFACTURER,
  50292. + .iProduct = STRING_PRODUCT,
  50293. + .iSerialNumber = STRING_SERIAL,
  50294. + .bNumConfigurations = 1,
  50295. +};
  50296. +
  50297. +static struct usb_config_descriptor
  50298. +z_config = {
  50299. + .bLength = sizeof z_config,
  50300. + .bDescriptorType = USB_DT_CONFIG,
  50301. +
  50302. + /* compute wTotalLength on the fly */
  50303. + .bNumInterfaces = 2,
  50304. + .bConfigurationValue = 1,
  50305. + .iConfiguration = 0,
  50306. + .bmAttributes = 0x40,
  50307. + .bMaxPower = 0, /* self-powered */
  50308. +};
  50309. +
  50310. +
  50311. +static struct usb_otg_descriptor
  50312. +otg_descriptor = {
  50313. + .bLength = sizeof otg_descriptor,
  50314. + .bDescriptorType = USB_DT_OTG,
  50315. +
  50316. + .bmAttributes = USB_OTG_SRP,
  50317. +};
  50318. +
  50319. +/* one interface in each configuration */
  50320. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  50321. +
  50322. +/*
  50323. + * usb 2.0 devices need to expose both high speed and full speed
  50324. + * descriptors, unless they only run at full speed.
  50325. + *
  50326. + * that means alternate endpoint descriptors (bigger packets)
  50327. + * and a "device qualifier" ... plus more construction options
  50328. + * for the config descriptor.
  50329. + */
  50330. +
  50331. +static struct usb_qualifier_descriptor
  50332. +dev_qualifier = {
  50333. + .bLength = sizeof dev_qualifier,
  50334. + .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
  50335. +
  50336. + .bcdUSB = __constant_cpu_to_le16 (0x0200),
  50337. + .bDeviceClass = USB_CLASS_VENDOR_SPEC,
  50338. +
  50339. + .bNumConfigurations = 2,
  50340. +};
  50341. +
  50342. +
  50343. +struct usb_cs_as_general_descriptor {
  50344. + __u8 bLength;
  50345. + __u8 bDescriptorType;
  50346. +
  50347. + __u8 bDescriptorSubType;
  50348. + __u8 bTerminalLink;
  50349. + __u8 bDelay;
  50350. + __u16 wFormatTag;
  50351. +} __attribute__ ((packed));
  50352. +
  50353. +struct usb_cs_as_format_descriptor {
  50354. + __u8 bLength;
  50355. + __u8 bDescriptorType;
  50356. +
  50357. + __u8 bDescriptorSubType;
  50358. + __u8 bFormatType;
  50359. + __u8 bNrChannels;
  50360. + __u8 bSubframeSize;
  50361. + __u8 bBitResolution;
  50362. + __u8 bSamfreqType;
  50363. + __u8 tLowerSamFreq[3];
  50364. + __u8 tUpperSamFreq[3];
  50365. +} __attribute__ ((packed));
  50366. +
  50367. +static const struct usb_interface_descriptor
  50368. +z_audio_control_if_desc = {
  50369. + .bLength = sizeof z_audio_control_if_desc,
  50370. + .bDescriptorType = USB_DT_INTERFACE,
  50371. + .bInterfaceNumber = 0,
  50372. + .bAlternateSetting = 0,
  50373. + .bNumEndpoints = 0,
  50374. + .bInterfaceClass = USB_CLASS_AUDIO,
  50375. + .bInterfaceSubClass = 0x1,
  50376. + .bInterfaceProtocol = 0,
  50377. + .iInterface = 0,
  50378. +};
  50379. +
  50380. +static const struct usb_interface_descriptor
  50381. +z_audio_if_desc = {
  50382. + .bLength = sizeof z_audio_if_desc,
  50383. + .bDescriptorType = USB_DT_INTERFACE,
  50384. + .bInterfaceNumber = 1,
  50385. + .bAlternateSetting = 0,
  50386. + .bNumEndpoints = 0,
  50387. + .bInterfaceClass = USB_CLASS_AUDIO,
  50388. + .bInterfaceSubClass = 0x2,
  50389. + .bInterfaceProtocol = 0,
  50390. + .iInterface = 0,
  50391. +};
  50392. +
  50393. +static const struct usb_interface_descriptor
  50394. +z_audio_if_desc2 = {
  50395. + .bLength = sizeof z_audio_if_desc,
  50396. + .bDescriptorType = USB_DT_INTERFACE,
  50397. + .bInterfaceNumber = 1,
  50398. + .bAlternateSetting = 1,
  50399. + .bNumEndpoints = 1,
  50400. + .bInterfaceClass = USB_CLASS_AUDIO,
  50401. + .bInterfaceSubClass = 0x2,
  50402. + .bInterfaceProtocol = 0,
  50403. + .iInterface = 0,
  50404. +};
  50405. +
  50406. +static const struct usb_cs_as_general_descriptor
  50407. +z_audio_cs_as_if_desc = {
  50408. + .bLength = 7,
  50409. + .bDescriptorType = 0x24,
  50410. +
  50411. + .bDescriptorSubType = 0x01,
  50412. + .bTerminalLink = 0x01,
  50413. + .bDelay = 0x0,
  50414. + .wFormatTag = __constant_cpu_to_le16 (0x0001)
  50415. +};
  50416. +
  50417. +
  50418. +static const struct usb_cs_as_format_descriptor
  50419. +z_audio_cs_as_format_desc = {
  50420. + .bLength = 0xe,
  50421. + .bDescriptorType = 0x24,
  50422. +
  50423. + .bDescriptorSubType = 2,
  50424. + .bFormatType = 1,
  50425. + .bNrChannels = 1,
  50426. + .bSubframeSize = 1,
  50427. + .bBitResolution = 8,
  50428. + .bSamfreqType = 0,
  50429. + .tLowerSamFreq = {0x7e, 0x13, 0x00},
  50430. + .tUpperSamFreq = {0xe2, 0xd6, 0x00},
  50431. +};
  50432. +
  50433. +static const struct usb_endpoint_descriptor
  50434. +z_iso_ep = {
  50435. + .bLength = 0x09,
  50436. + .bDescriptorType = 0x05,
  50437. + .bEndpointAddress = 0x04,
  50438. + .bmAttributes = 0x09,
  50439. + .wMaxPacketSize = 0x0038,
  50440. + .bInterval = 0x01,
  50441. + .bRefresh = 0x00,
  50442. + .bSynchAddress = 0x00,
  50443. +};
  50444. +
  50445. +static char z_iso_ep2[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  50446. +
  50447. +// 9 bytes
  50448. +static char z_ac_interface_header_desc[] =
  50449. +{ 0x09, 0x24, 0x01, 0x00, 0x01, 0x2b, 0x00, 0x01, 0x01 };
  50450. +
  50451. +// 12 bytes
  50452. +static char z_0[] = {0x0c, 0x24, 0x02, 0x01, 0x01, 0x01, 0x00, 0x02,
  50453. + 0x03, 0x00, 0x00, 0x00};
  50454. +// 13 bytes
  50455. +static char z_1[] = {0x0d, 0x24, 0x06, 0x02, 0x01, 0x02, 0x15, 0x00,
  50456. + 0x02, 0x00, 0x02, 0x00, 0x00};
  50457. +// 9 bytes
  50458. +static char z_2[] = {0x09, 0x24, 0x03, 0x03, 0x01, 0x03, 0x00, 0x02,
  50459. + 0x00};
  50460. +
  50461. +static char za_0[] = {0x09, 0x04, 0x01, 0x02, 0x01, 0x01, 0x02, 0x00,
  50462. + 0x00};
  50463. +
  50464. +static char za_1[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  50465. +
  50466. +static char za_2[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x01, 0x08, 0x00,
  50467. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  50468. +
  50469. +static char za_3[] = {0x09, 0x05, 0x04, 0x09, 0x70, 0x00, 0x01, 0x00,
  50470. + 0x00};
  50471. +
  50472. +static char za_4[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  50473. +
  50474. +static char za_5[] = {0x09, 0x04, 0x01, 0x03, 0x01, 0x01, 0x02, 0x00,
  50475. + 0x00};
  50476. +
  50477. +static char za_6[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  50478. +
  50479. +static char za_7[] = {0x0e, 0x24, 0x02, 0x01, 0x01, 0x02, 0x10, 0x00,
  50480. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  50481. +
  50482. +static char za_8[] = {0x09, 0x05, 0x04, 0x09, 0x70, 0x00, 0x01, 0x00,
  50483. + 0x00};
  50484. +
  50485. +static char za_9[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  50486. +
  50487. +static char za_10[] = {0x09, 0x04, 0x01, 0x04, 0x01, 0x01, 0x02, 0x00,
  50488. + 0x00};
  50489. +
  50490. +static char za_11[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  50491. +
  50492. +static char za_12[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x02, 0x10, 0x00,
  50493. + 0x73, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  50494. +
  50495. +static char za_13[] = {0x09, 0x05, 0x04, 0x09, 0xe0, 0x00, 0x01, 0x00,
  50496. + 0x00};
  50497. +
  50498. +static char za_14[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  50499. +
  50500. +static char za_15[] = {0x09, 0x04, 0x01, 0x05, 0x01, 0x01, 0x02, 0x00,
  50501. + 0x00};
  50502. +
  50503. +static char za_16[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  50504. +
  50505. +static char za_17[] = {0x0e, 0x24, 0x02, 0x01, 0x01, 0x03, 0x14, 0x00,
  50506. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  50507. +
  50508. +static char za_18[] = {0x09, 0x05, 0x04, 0x09, 0xa8, 0x00, 0x01, 0x00,
  50509. + 0x00};
  50510. +
  50511. +static char za_19[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  50512. +
  50513. +static char za_20[] = {0x09, 0x04, 0x01, 0x06, 0x01, 0x01, 0x02, 0x00,
  50514. + 0x00};
  50515. +
  50516. +static char za_21[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  50517. +
  50518. +static char za_22[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x03, 0x14, 0x00,
  50519. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  50520. +
  50521. +static char za_23[] = {0x09, 0x05, 0x04, 0x09, 0x50, 0x01, 0x01, 0x00,
  50522. + 0x00};
  50523. +
  50524. +static char za_24[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  50525. +
  50526. +
  50527. +
  50528. +static const struct usb_descriptor_header *z_function [] = {
  50529. + (struct usb_descriptor_header *) &z_audio_control_if_desc,
  50530. + (struct usb_descriptor_header *) &z_ac_interface_header_desc,
  50531. + (struct usb_descriptor_header *) &z_0,
  50532. + (struct usb_descriptor_header *) &z_1,
  50533. + (struct usb_descriptor_header *) &z_2,
  50534. + (struct usb_descriptor_header *) &z_audio_if_desc,
  50535. + (struct usb_descriptor_header *) &z_audio_if_desc2,
  50536. + (struct usb_descriptor_header *) &z_audio_cs_as_if_desc,
  50537. + (struct usb_descriptor_header *) &z_audio_cs_as_format_desc,
  50538. + (struct usb_descriptor_header *) &z_iso_ep,
  50539. + (struct usb_descriptor_header *) &z_iso_ep2,
  50540. + (struct usb_descriptor_header *) &za_0,
  50541. + (struct usb_descriptor_header *) &za_1,
  50542. + (struct usb_descriptor_header *) &za_2,
  50543. + (struct usb_descriptor_header *) &za_3,
  50544. + (struct usb_descriptor_header *) &za_4,
  50545. + (struct usb_descriptor_header *) &za_5,
  50546. + (struct usb_descriptor_header *) &za_6,
  50547. + (struct usb_descriptor_header *) &za_7,
  50548. + (struct usb_descriptor_header *) &za_8,
  50549. + (struct usb_descriptor_header *) &za_9,
  50550. + (struct usb_descriptor_header *) &za_10,
  50551. + (struct usb_descriptor_header *) &za_11,
  50552. + (struct usb_descriptor_header *) &za_12,
  50553. + (struct usb_descriptor_header *) &za_13,
  50554. + (struct usb_descriptor_header *) &za_14,
  50555. + (struct usb_descriptor_header *) &za_15,
  50556. + (struct usb_descriptor_header *) &za_16,
  50557. + (struct usb_descriptor_header *) &za_17,
  50558. + (struct usb_descriptor_header *) &za_18,
  50559. + (struct usb_descriptor_header *) &za_19,
  50560. + (struct usb_descriptor_header *) &za_20,
  50561. + (struct usb_descriptor_header *) &za_21,
  50562. + (struct usb_descriptor_header *) &za_22,
  50563. + (struct usb_descriptor_header *) &za_23,
  50564. + (struct usb_descriptor_header *) &za_24,
  50565. + NULL,
  50566. +};
  50567. +
  50568. +/* maxpacket and other transfer characteristics vary by speed. */
  50569. +#define ep_desc(g,hs,fs) (((g)->speed==USB_SPEED_HIGH)?(hs):(fs))
  50570. +
  50571. +#else
  50572. +
  50573. +/* if there's no high speed support, maxpacket doesn't change. */
  50574. +#define ep_desc(g,hs,fs) fs
  50575. +
  50576. +#endif /* !CONFIG_USB_GADGET_DUALSPEED */
  50577. +
  50578. +static char manufacturer [40];
  50579. +//static char serial [40];
  50580. +static char serial [] = "Ser 00 em";
  50581. +
  50582. +/* static strings, in UTF-8 */
  50583. +static struct usb_string strings [] = {
  50584. + { STRING_MANUFACTURER, manufacturer, },
  50585. + { STRING_PRODUCT, longname, },
  50586. + { STRING_SERIAL, serial, },
  50587. + { STRING_LOOPBACK, loopback, },
  50588. + { STRING_SOURCE_SINK, source_sink, },
  50589. + { } /* end of list */
  50590. +};
  50591. +
  50592. +static struct usb_gadget_strings stringtab = {
  50593. + .language = 0x0409, /* en-us */
  50594. + .strings = strings,
  50595. +};
  50596. +
  50597. +/*
  50598. + * config descriptors are also handcrafted. these must agree with code
  50599. + * that sets configurations, and with code managing interfaces and their
  50600. + * altsettings. other complexity may come from:
  50601. + *
  50602. + * - high speed support, including "other speed config" rules
  50603. + * - multiple configurations
  50604. + * - interfaces with alternate settings
  50605. + * - embedded class or vendor-specific descriptors
  50606. + *
  50607. + * this handles high speed, and has a second config that could as easily
  50608. + * have been an alternate interface setting (on most hardware).
  50609. + *
  50610. + * NOTE: to demonstrate (and test) more USB capabilities, this driver
  50611. + * should include an altsetting to test interrupt transfers, including
  50612. + * high bandwidth modes at high speed. (Maybe work like Intel's test
  50613. + * device?)
  50614. + */
  50615. +static int
  50616. +config_buf (struct usb_gadget *gadget, u8 *buf, u8 type, unsigned index)
  50617. +{
  50618. + int len;
  50619. + const struct usb_descriptor_header **function;
  50620. +
  50621. + function = z_function;
  50622. + len = usb_gadget_config_buf (&z_config, buf, USB_BUFSIZ, function);
  50623. + if (len < 0)
  50624. + return len;
  50625. + ((struct usb_config_descriptor *) buf)->bDescriptorType = type;
  50626. + return len;
  50627. +}
  50628. +
  50629. +/*-------------------------------------------------------------------------*/
  50630. +
  50631. +static struct usb_request *
  50632. +alloc_ep_req (struct usb_ep *ep, unsigned length)
  50633. +{
  50634. + struct usb_request *req;
  50635. +
  50636. + req = usb_ep_alloc_request (ep, GFP_ATOMIC);
  50637. + if (req) {
  50638. + req->length = length;
  50639. + req->buf = usb_ep_alloc_buffer (ep, length,
  50640. + &req->dma, GFP_ATOMIC);
  50641. + if (!req->buf) {
  50642. + usb_ep_free_request (ep, req);
  50643. + req = NULL;
  50644. + }
  50645. + }
  50646. + return req;
  50647. +}
  50648. +
  50649. +static void free_ep_req (struct usb_ep *ep, struct usb_request *req)
  50650. +{
  50651. + if (req->buf)
  50652. + usb_ep_free_buffer (ep, req->buf, req->dma, req->length);
  50653. + usb_ep_free_request (ep, req);
  50654. +}
  50655. +
  50656. +/*-------------------------------------------------------------------------*/
  50657. +
  50658. +/* optionally require specific source/sink data patterns */
  50659. +
  50660. +static int
  50661. +check_read_data (
  50662. + struct zero_dev *dev,
  50663. + struct usb_ep *ep,
  50664. + struct usb_request *req
  50665. +)
  50666. +{
  50667. + unsigned i;
  50668. + u8 *buf = req->buf;
  50669. +
  50670. + for (i = 0; i < req->actual; i++, buf++) {
  50671. + switch (pattern) {
  50672. + /* all-zeroes has no synchronization issues */
  50673. + case 0:
  50674. + if (*buf == 0)
  50675. + continue;
  50676. + break;
  50677. + /* mod63 stays in sync with short-terminated transfers,
  50678. + * or otherwise when host and gadget agree on how large
  50679. + * each usb transfer request should be. resync is done
  50680. + * with set_interface or set_config.
  50681. + */
  50682. + case 1:
  50683. + if (*buf == (u8)(i % 63))
  50684. + continue;
  50685. + break;
  50686. + }
  50687. + ERROR (dev, "bad OUT byte, buf [%d] = %d\n", i, *buf);
  50688. + usb_ep_set_halt (ep);
  50689. + return -EINVAL;
  50690. + }
  50691. + return 0;
  50692. +}
  50693. +
  50694. +/*-------------------------------------------------------------------------*/
  50695. +
  50696. +static void zero_reset_config (struct zero_dev *dev)
  50697. +{
  50698. + if (dev->config == 0)
  50699. + return;
  50700. +
  50701. + DBG (dev, "reset config\n");
  50702. +
  50703. + /* just disable endpoints, forcing completion of pending i/o.
  50704. + * all our completion handlers free their requests in this case.
  50705. + */
  50706. + if (dev->in_ep) {
  50707. + usb_ep_disable (dev->in_ep);
  50708. + dev->in_ep = NULL;
  50709. + }
  50710. + if (dev->out_ep) {
  50711. + usb_ep_disable (dev->out_ep);
  50712. + dev->out_ep = NULL;
  50713. + }
  50714. + dev->config = 0;
  50715. + del_timer (&dev->resume);
  50716. +}
  50717. +
  50718. +#define _write(f, buf, sz) (f->f_op->write(f, buf, sz, &f->f_pos))
  50719. +
  50720. +static void
  50721. +zero_isoc_complete (struct usb_ep *ep, struct usb_request *req)
  50722. +{
  50723. + struct zero_dev *dev = ep->driver_data;
  50724. + int status = req->status;
  50725. + int i, j;
  50726. +
  50727. + switch (status) {
  50728. +
  50729. + case 0: /* normal completion? */
  50730. + //printk ("\nzero ---------------> isoc normal completion %d bytes\n", req->actual);
  50731. + for (i=0, j=rbuf_start; i<req->actual; i++) {
  50732. + //printk ("%02x ", ((__u8*)req->buf)[i]);
  50733. + rbuf[j] = ((__u8*)req->buf)[i];
  50734. + j++;
  50735. + if (j >= RBUF_LEN) j=0;
  50736. + }
  50737. + rbuf_start = j;
  50738. + //printk ("\n\n");
  50739. +
  50740. + if (rbuf_len < RBUF_LEN) {
  50741. + rbuf_len += req->actual;
  50742. + if (rbuf_len > RBUF_LEN) {
  50743. + rbuf_len = RBUF_LEN;
  50744. + }
  50745. + }
  50746. +
  50747. + break;
  50748. +
  50749. + /* this endpoint is normally active while we're configured */
  50750. + case -ECONNABORTED: /* hardware forced ep reset */
  50751. + case -ECONNRESET: /* request dequeued */
  50752. + case -ESHUTDOWN: /* disconnect from host */
  50753. + VDBG (dev, "%s gone (%d), %d/%d\n", ep->name, status,
  50754. + req->actual, req->length);
  50755. + if (ep == dev->out_ep)
  50756. + check_read_data (dev, ep, req);
  50757. + free_ep_req (ep, req);
  50758. + return;
  50759. +
  50760. + case -EOVERFLOW: /* buffer overrun on read means that
  50761. + * we didn't provide a big enough
  50762. + * buffer.
  50763. + */
  50764. + default:
  50765. +#if 1
  50766. + DBG (dev, "%s complete --> %d, %d/%d\n", ep->name,
  50767. + status, req->actual, req->length);
  50768. +#endif
  50769. + case -EREMOTEIO: /* short read */
  50770. + break;
  50771. + }
  50772. +
  50773. + status = usb_ep_queue (ep, req, GFP_ATOMIC);
  50774. + if (status) {
  50775. + ERROR (dev, "kill %s: resubmit %d bytes --> %d\n",
  50776. + ep->name, req->length, status);
  50777. + usb_ep_set_halt (ep);
  50778. + /* FIXME recover later ... somehow */
  50779. + }
  50780. +}
  50781. +
  50782. +static struct usb_request *
  50783. +zero_start_isoc_ep (struct usb_ep *ep, int gfp_flags)
  50784. +{
  50785. + struct usb_request *req;
  50786. + int status;
  50787. +
  50788. + req = alloc_ep_req (ep, 512);
  50789. + if (!req)
  50790. + return NULL;
  50791. +
  50792. + req->complete = zero_isoc_complete;
  50793. +
  50794. + status = usb_ep_queue (ep, req, gfp_flags);
  50795. + if (status) {
  50796. + struct zero_dev *dev = ep->driver_data;
  50797. +
  50798. + ERROR (dev, "start %s --> %d\n", ep->name, status);
  50799. + free_ep_req (ep, req);
  50800. + req = NULL;
  50801. + }
  50802. +
  50803. + return req;
  50804. +}
  50805. +
  50806. +/* change our operational config. this code must agree with the code
  50807. + * that returns config descriptors, and altsetting code.
  50808. + *
  50809. + * it's also responsible for power management interactions. some
  50810. + * configurations might not work with our current power sources.
  50811. + *
  50812. + * note that some device controller hardware will constrain what this
  50813. + * code can do, perhaps by disallowing more than one configuration or
  50814. + * by limiting configuration choices (like the pxa2xx).
  50815. + */
  50816. +static int
  50817. +zero_set_config (struct zero_dev *dev, unsigned number, int gfp_flags)
  50818. +{
  50819. + int result = 0;
  50820. + struct usb_gadget *gadget = dev->gadget;
  50821. + const struct usb_endpoint_descriptor *d;
  50822. + struct usb_ep *ep;
  50823. +
  50824. + if (number == dev->config)
  50825. + return 0;
  50826. +
  50827. + zero_reset_config (dev);
  50828. +
  50829. + gadget_for_each_ep (ep, gadget) {
  50830. +
  50831. + if (strcmp (ep->name, "ep4") == 0) {
  50832. +
  50833. + d = (struct usb_endpoint_descripter *)&za_23; // isoc ep desc for audio i/f alt setting 6
  50834. + result = usb_ep_enable (ep, d);
  50835. +
  50836. + if (result == 0) {
  50837. + ep->driver_data = dev;
  50838. + dev->in_ep = ep;
  50839. +
  50840. + if (zero_start_isoc_ep (ep, gfp_flags) != 0) {
  50841. +
  50842. + dev->in_ep = ep;
  50843. + continue;
  50844. + }
  50845. +
  50846. + usb_ep_disable (ep);
  50847. + result = -EIO;
  50848. + }
  50849. + }
  50850. +
  50851. + }
  50852. +
  50853. + dev->config = number;
  50854. + return result;
  50855. +}
  50856. +
  50857. +/*-------------------------------------------------------------------------*/
  50858. +
  50859. +static void zero_setup_complete (struct usb_ep *ep, struct usb_request *req)
  50860. +{
  50861. + if (req->status || req->actual != req->length)
  50862. + DBG ((struct zero_dev *) ep->driver_data,
  50863. + "setup complete --> %d, %d/%d\n",
  50864. + req->status, req->actual, req->length);
  50865. +}
  50866. +
  50867. +/*
  50868. + * The setup() callback implements all the ep0 functionality that's
  50869. + * not handled lower down, in hardware or the hardware driver (like
  50870. + * device and endpoint feature flags, and their status). It's all
  50871. + * housekeeping for the gadget function we're implementing. Most of
  50872. + * the work is in config-specific setup.
  50873. + */
  50874. +static int
  50875. +zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
  50876. +{
  50877. + struct zero_dev *dev = get_gadget_data (gadget);
  50878. + struct usb_request *req = dev->req;
  50879. + int value = -EOPNOTSUPP;
  50880. +
  50881. + /* usually this stores reply data in the pre-allocated ep0 buffer,
  50882. + * but config change events will reconfigure hardware.
  50883. + */
  50884. + req->zero = 0;
  50885. + switch (ctrl->bRequest) {
  50886. +
  50887. + case USB_REQ_GET_DESCRIPTOR:
  50888. +
  50889. + switch (ctrl->wValue >> 8) {
  50890. +
  50891. + case USB_DT_DEVICE:
  50892. + value = min (ctrl->wLength, (u16) sizeof device_desc);
  50893. + memcpy (req->buf, &device_desc, value);
  50894. + break;
  50895. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  50896. + case USB_DT_DEVICE_QUALIFIER:
  50897. + if (!gadget->is_dualspeed)
  50898. + break;
  50899. + value = min (ctrl->wLength, (u16) sizeof dev_qualifier);
  50900. + memcpy (req->buf, &dev_qualifier, value);
  50901. + break;
  50902. +
  50903. + case USB_DT_OTHER_SPEED_CONFIG:
  50904. + if (!gadget->is_dualspeed)
  50905. + break;
  50906. + // FALLTHROUGH
  50907. +#endif /* CONFIG_USB_GADGET_DUALSPEED */
  50908. + case USB_DT_CONFIG:
  50909. + value = config_buf (gadget, req->buf,
  50910. + ctrl->wValue >> 8,
  50911. + ctrl->wValue & 0xff);
  50912. + if (value >= 0)
  50913. + value = min (ctrl->wLength, (u16) value);
  50914. + break;
  50915. +
  50916. + case USB_DT_STRING:
  50917. + /* wIndex == language code.
  50918. + * this driver only handles one language, you can
  50919. + * add string tables for other languages, using
  50920. + * any UTF-8 characters
  50921. + */
  50922. + value = usb_gadget_get_string (&stringtab,
  50923. + ctrl->wValue & 0xff, req->buf);
  50924. + if (value >= 0) {
  50925. + value = min (ctrl->wLength, (u16) value);
  50926. + }
  50927. + break;
  50928. + }
  50929. + break;
  50930. +
  50931. + /* currently two configs, two speeds */
  50932. + case USB_REQ_SET_CONFIGURATION:
  50933. + if (ctrl->bRequestType != 0)
  50934. + goto unknown;
  50935. +
  50936. + spin_lock (&dev->lock);
  50937. + value = zero_set_config (dev, ctrl->wValue, GFP_ATOMIC);
  50938. + spin_unlock (&dev->lock);
  50939. + break;
  50940. + case USB_REQ_GET_CONFIGURATION:
  50941. + if (ctrl->bRequestType != USB_DIR_IN)
  50942. + goto unknown;
  50943. + *(u8 *)req->buf = dev->config;
  50944. + value = min (ctrl->wLength, (u16) 1);
  50945. + break;
  50946. +
  50947. + /* until we add altsetting support, or other interfaces,
  50948. + * only 0/0 are possible. pxa2xx only supports 0/0 (poorly)
  50949. + * and already killed pending endpoint I/O.
  50950. + */
  50951. + case USB_REQ_SET_INTERFACE:
  50952. +
  50953. + if (ctrl->bRequestType != USB_RECIP_INTERFACE)
  50954. + goto unknown;
  50955. + spin_lock (&dev->lock);
  50956. + if (dev->config) {
  50957. + u8 config = dev->config;
  50958. +
  50959. + /* resets interface configuration, forgets about
  50960. + * previous transaction state (queued bufs, etc)
  50961. + * and re-inits endpoint state (toggle etc)
  50962. + * no response queued, just zero status == success.
  50963. + * if we had more than one interface we couldn't
  50964. + * use this "reset the config" shortcut.
  50965. + */
  50966. + zero_reset_config (dev);
  50967. + zero_set_config (dev, config, GFP_ATOMIC);
  50968. + value = 0;
  50969. + }
  50970. + spin_unlock (&dev->lock);
  50971. + break;
  50972. + case USB_REQ_GET_INTERFACE:
  50973. + if ((ctrl->bRequestType == 0x21) && (ctrl->wIndex == 0x02)) {
  50974. + value = ctrl->wLength;
  50975. + break;
  50976. + }
  50977. + else {
  50978. + if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE))
  50979. + goto unknown;
  50980. + if (!dev->config)
  50981. + break;
  50982. + if (ctrl->wIndex != 0) {
  50983. + value = -EDOM;
  50984. + break;
  50985. + }
  50986. + *(u8 *)req->buf = 0;
  50987. + value = min (ctrl->wLength, (u16) 1);
  50988. + }
  50989. + break;
  50990. +
  50991. + /*
  50992. + * These are the same vendor-specific requests supported by
  50993. + * Intel's USB 2.0 compliance test devices. We exceed that
  50994. + * device spec by allowing multiple-packet requests.
  50995. + */
  50996. + case 0x5b: /* control WRITE test -- fill the buffer */
  50997. + if (ctrl->bRequestType != (USB_DIR_OUT|USB_TYPE_VENDOR))
  50998. + goto unknown;
  50999. + if (ctrl->wValue || ctrl->wIndex)
  51000. + break;
  51001. + /* just read that many bytes into the buffer */
  51002. + if (ctrl->wLength > USB_BUFSIZ)
  51003. + break;
  51004. + value = ctrl->wLength;
  51005. + break;
  51006. + case 0x5c: /* control READ test -- return the buffer */
  51007. + if (ctrl->bRequestType != (USB_DIR_IN|USB_TYPE_VENDOR))
  51008. + goto unknown;
  51009. + if (ctrl->wValue || ctrl->wIndex)
  51010. + break;
  51011. + /* expect those bytes are still in the buffer; send back */
  51012. + if (ctrl->wLength > USB_BUFSIZ
  51013. + || ctrl->wLength != req->length)
  51014. + break;
  51015. + value = ctrl->wLength;
  51016. + break;
  51017. +
  51018. + case 0x01: // SET_CUR
  51019. + case 0x02:
  51020. + case 0x03:
  51021. + case 0x04:
  51022. + case 0x05:
  51023. + value = ctrl->wLength;
  51024. + break;
  51025. + case 0x81:
  51026. + switch (ctrl->wValue) {
  51027. + case 0x0201:
  51028. + case 0x0202:
  51029. + ((u8*)req->buf)[0] = 0x00;
  51030. + ((u8*)req->buf)[1] = 0xe3;
  51031. + break;
  51032. + case 0x0300:
  51033. + case 0x0500:
  51034. + ((u8*)req->buf)[0] = 0x00;
  51035. + break;
  51036. + }
  51037. + //((u8*)req->buf)[0] = 0x81;
  51038. + //((u8*)req->buf)[1] = 0x81;
  51039. + value = ctrl->wLength;
  51040. + break;
  51041. + case 0x82:
  51042. + switch (ctrl->wValue) {
  51043. + case 0x0201:
  51044. + case 0x0202:
  51045. + ((u8*)req->buf)[0] = 0x00;
  51046. + ((u8*)req->buf)[1] = 0xc3;
  51047. + break;
  51048. + case 0x0300:
  51049. + case 0x0500:
  51050. + ((u8*)req->buf)[0] = 0x00;
  51051. + break;
  51052. + }
  51053. + //((u8*)req->buf)[0] = 0x82;
  51054. + //((u8*)req->buf)[1] = 0x82;
  51055. + value = ctrl->wLength;
  51056. + break;
  51057. + case 0x83:
  51058. + switch (ctrl->wValue) {
  51059. + case 0x0201:
  51060. + case 0x0202:
  51061. + ((u8*)req->buf)[0] = 0x00;
  51062. + ((u8*)req->buf)[1] = 0x00;
  51063. + break;
  51064. + case 0x0300:
  51065. + ((u8*)req->buf)[0] = 0x60;
  51066. + break;
  51067. + case 0x0500:
  51068. + ((u8*)req->buf)[0] = 0x18;
  51069. + break;
  51070. + }
  51071. + //((u8*)req->buf)[0] = 0x83;
  51072. + //((u8*)req->buf)[1] = 0x83;
  51073. + value = ctrl->wLength;
  51074. + break;
  51075. + case 0x84:
  51076. + switch (ctrl->wValue) {
  51077. + case 0x0201:
  51078. + case 0x0202:
  51079. + ((u8*)req->buf)[0] = 0x00;
  51080. + ((u8*)req->buf)[1] = 0x01;
  51081. + break;
  51082. + case 0x0300:
  51083. + case 0x0500:
  51084. + ((u8*)req->buf)[0] = 0x08;
  51085. + break;
  51086. + }
  51087. + //((u8*)req->buf)[0] = 0x84;
  51088. + //((u8*)req->buf)[1] = 0x84;
  51089. + value = ctrl->wLength;
  51090. + break;
  51091. + case 0x85:
  51092. + ((u8*)req->buf)[0] = 0x85;
  51093. + ((u8*)req->buf)[1] = 0x85;
  51094. + value = ctrl->wLength;
  51095. + break;
  51096. +
  51097. +
  51098. + default:
  51099. +unknown:
  51100. + printk("unknown control req%02x.%02x v%04x i%04x l%d\n",
  51101. + ctrl->bRequestType, ctrl->bRequest,
  51102. + ctrl->wValue, ctrl->wIndex, ctrl->wLength);
  51103. + }
  51104. +
  51105. + /* respond with data transfer before status phase? */
  51106. + if (value >= 0) {
  51107. + req->length = value;
  51108. + req->zero = value < ctrl->wLength
  51109. + && (value % gadget->ep0->maxpacket) == 0;
  51110. + value = usb_ep_queue (gadget->ep0, req, GFP_ATOMIC);
  51111. + if (value < 0) {
  51112. + DBG (dev, "ep_queue < 0 --> %d\n", value);
  51113. + req->status = 0;
  51114. + zero_setup_complete (gadget->ep0, req);
  51115. + }
  51116. + }
  51117. +
  51118. + /* device either stalls (value < 0) or reports success */
  51119. + return value;
  51120. +}
  51121. +
  51122. +static void
  51123. +zero_disconnect (struct usb_gadget *gadget)
  51124. +{
  51125. + struct zero_dev *dev = get_gadget_data (gadget);
  51126. + unsigned long flags;
  51127. +
  51128. + spin_lock_irqsave (&dev->lock, flags);
  51129. + zero_reset_config (dev);
  51130. +
  51131. + /* a more significant application might have some non-usb
  51132. + * activities to quiesce here, saving resources like power
  51133. + * or pushing the notification up a network stack.
  51134. + */
  51135. + spin_unlock_irqrestore (&dev->lock, flags);
  51136. +
  51137. + /* next we may get setup() calls to enumerate new connections;
  51138. + * or an unbind() during shutdown (including removing module).
  51139. + */
  51140. +}
  51141. +
  51142. +static void
  51143. +zero_autoresume (unsigned long _dev)
  51144. +{
  51145. + struct zero_dev *dev = (struct zero_dev *) _dev;
  51146. + int status;
  51147. +
  51148. + /* normally the host would be woken up for something
  51149. + * more significant than just a timer firing...
  51150. + */
  51151. + if (dev->gadget->speed != USB_SPEED_UNKNOWN) {
  51152. + status = usb_gadget_wakeup (dev->gadget);
  51153. + DBG (dev, "wakeup --> %d\n", status);
  51154. + }
  51155. +}
  51156. +
  51157. +/*-------------------------------------------------------------------------*/
  51158. +
  51159. +static void
  51160. +zero_unbind (struct usb_gadget *gadget)
  51161. +{
  51162. + struct zero_dev *dev = get_gadget_data (gadget);
  51163. +
  51164. + DBG (dev, "unbind\n");
  51165. +
  51166. + /* we've already been disconnected ... no i/o is active */
  51167. + if (dev->req)
  51168. + free_ep_req (gadget->ep0, dev->req);
  51169. + del_timer_sync (&dev->resume);
  51170. + kfree (dev);
  51171. + set_gadget_data (gadget, NULL);
  51172. +}
  51173. +
  51174. +static int
  51175. +zero_bind (struct usb_gadget *gadget)
  51176. +{
  51177. + struct zero_dev *dev;
  51178. + //struct usb_ep *ep;
  51179. +
  51180. + printk("binding\n");
  51181. + /*
  51182. + * DRIVER POLICY CHOICE: you may want to do this differently.
  51183. + * One thing to avoid is reusing a bcdDevice revision code
  51184. + * with different host-visible configurations or behavior
  51185. + * restrictions -- using ep1in/ep2out vs ep1out/ep3in, etc
  51186. + */
  51187. + //device_desc.bcdDevice = __constant_cpu_to_le16 (0x0201);
  51188. +
  51189. +
  51190. + /* ok, we made sense of the hardware ... */
  51191. + dev = kmalloc (sizeof *dev, SLAB_KERNEL);
  51192. + if (!dev)
  51193. + return -ENOMEM;
  51194. + memset (dev, 0, sizeof *dev);
  51195. + spin_lock_init (&dev->lock);
  51196. + dev->gadget = gadget;
  51197. + set_gadget_data (gadget, dev);
  51198. +
  51199. + /* preallocate control response and buffer */
  51200. + dev->req = usb_ep_alloc_request (gadget->ep0, GFP_KERNEL);
  51201. + if (!dev->req)
  51202. + goto enomem;
  51203. + dev->req->buf = usb_ep_alloc_buffer (gadget->ep0, USB_BUFSIZ,
  51204. + &dev->req->dma, GFP_KERNEL);
  51205. + if (!dev->req->buf)
  51206. + goto enomem;
  51207. +
  51208. + dev->req->complete = zero_setup_complete;
  51209. +
  51210. + device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
  51211. +
  51212. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  51213. + /* assume ep0 uses the same value for both speeds ... */
  51214. + dev_qualifier.bMaxPacketSize0 = device_desc.bMaxPacketSize0;
  51215. +
  51216. + /* and that all endpoints are dual-speed */
  51217. + //hs_source_desc.bEndpointAddress = fs_source_desc.bEndpointAddress;
  51218. + //hs_sink_desc.bEndpointAddress = fs_sink_desc.bEndpointAddress;
  51219. +#endif
  51220. +
  51221. + usb_gadget_set_selfpowered (gadget);
  51222. +
  51223. + init_timer (&dev->resume);
  51224. + dev->resume.function = zero_autoresume;
  51225. + dev->resume.data = (unsigned long) dev;
  51226. +
  51227. + gadget->ep0->driver_data = dev;
  51228. +
  51229. + INFO (dev, "%s, version: " DRIVER_VERSION "\n", longname);
  51230. + INFO (dev, "using %s, OUT %s IN %s\n", gadget->name,
  51231. + EP_OUT_NAME, EP_IN_NAME);
  51232. +
  51233. + snprintf (manufacturer, sizeof manufacturer,
  51234. + UTS_SYSNAME " " UTS_RELEASE " with %s",
  51235. + gadget->name);
  51236. +
  51237. + return 0;
  51238. +
  51239. +enomem:
  51240. + zero_unbind (gadget);
  51241. + return -ENOMEM;
  51242. +}
  51243. +
  51244. +/*-------------------------------------------------------------------------*/
  51245. +
  51246. +static void
  51247. +zero_suspend (struct usb_gadget *gadget)
  51248. +{
  51249. + struct zero_dev *dev = get_gadget_data (gadget);
  51250. +
  51251. + if (gadget->speed == USB_SPEED_UNKNOWN)
  51252. + return;
  51253. +
  51254. + if (autoresume) {
  51255. + mod_timer (&dev->resume, jiffies + (HZ * autoresume));
  51256. + DBG (dev, "suspend, wakeup in %d seconds\n", autoresume);
  51257. + } else
  51258. + DBG (dev, "suspend\n");
  51259. +}
  51260. +
  51261. +static void
  51262. +zero_resume (struct usb_gadget *gadget)
  51263. +{
  51264. + struct zero_dev *dev = get_gadget_data (gadget);
  51265. +
  51266. + DBG (dev, "resume\n");
  51267. + del_timer (&dev->resume);
  51268. +}
  51269. +
  51270. +
  51271. +/*-------------------------------------------------------------------------*/
  51272. +
  51273. +static struct usb_gadget_driver zero_driver = {
  51274. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  51275. + .speed = USB_SPEED_HIGH,
  51276. +#else
  51277. + .speed = USB_SPEED_FULL,
  51278. +#endif
  51279. + .function = (char *) longname,
  51280. + .bind = zero_bind,
  51281. + .unbind = zero_unbind,
  51282. +
  51283. + .setup = zero_setup,
  51284. + .disconnect = zero_disconnect,
  51285. +
  51286. + .suspend = zero_suspend,
  51287. + .resume = zero_resume,
  51288. +
  51289. + .driver = {
  51290. + .name = (char *) shortname,
  51291. + // .shutdown = ...
  51292. + // .suspend = ...
  51293. + // .resume = ...
  51294. + },
  51295. +};
  51296. +
  51297. +MODULE_AUTHOR ("David Brownell");
  51298. +MODULE_LICENSE ("Dual BSD/GPL");
  51299. +
  51300. +static struct proc_dir_entry *pdir, *pfile;
  51301. +
  51302. +static int isoc_read_data (char *page, char **start,
  51303. + off_t off, int count,
  51304. + int *eof, void *data)
  51305. +{
  51306. + int i;
  51307. + static int c = 0;
  51308. + static int done = 0;
  51309. + static int s = 0;
  51310. +
  51311. +/*
  51312. + printk ("\ncount: %d\n", count);
  51313. + printk ("rbuf_start: %d\n", rbuf_start);
  51314. + printk ("rbuf_len: %d\n", rbuf_len);
  51315. + printk ("off: %d\n", off);
  51316. + printk ("start: %p\n\n", *start);
  51317. +*/
  51318. + if (done) {
  51319. + c = 0;
  51320. + done = 0;
  51321. + *eof = 1;
  51322. + return 0;
  51323. + }
  51324. +
  51325. + if (c == 0) {
  51326. + if (rbuf_len == RBUF_LEN)
  51327. + s = rbuf_start;
  51328. + else s = 0;
  51329. + }
  51330. +
  51331. + for (i=0; i<count && c<rbuf_len; i++, c++) {
  51332. + page[i] = rbuf[(c+s) % RBUF_LEN];
  51333. + }
  51334. + *start = page;
  51335. +
  51336. + if (c >= rbuf_len) {
  51337. + *eof = 1;
  51338. + done = 1;
  51339. + }
  51340. +
  51341. +
  51342. + return i;
  51343. +}
  51344. +
  51345. +static int __init init (void)
  51346. +{
  51347. +
  51348. + int retval = 0;
  51349. +
  51350. + pdir = proc_mkdir("isoc_test", NULL);
  51351. + if(pdir == NULL) {
  51352. + retval = -ENOMEM;
  51353. + printk("Error creating dir\n");
  51354. + goto done;
  51355. + }
  51356. + pdir->owner = THIS_MODULE;
  51357. +
  51358. + pfile = create_proc_read_entry("isoc_data",
  51359. + 0444, pdir,
  51360. + isoc_read_data,
  51361. + NULL);
  51362. + if (pfile == NULL) {
  51363. + retval = -ENOMEM;
  51364. + printk("Error creating file\n");
  51365. + goto no_file;
  51366. + }
  51367. + pfile->owner = THIS_MODULE;
  51368. +
  51369. + return usb_gadget_register_driver (&zero_driver);
  51370. +
  51371. + no_file:
  51372. + remove_proc_entry("isoc_data", NULL);
  51373. + done:
  51374. + return retval;
  51375. +}
  51376. +module_init (init);
  51377. +
  51378. +static void __exit cleanup (void)
  51379. +{
  51380. +
  51381. + usb_gadget_unregister_driver (&zero_driver);
  51382. +
  51383. + remove_proc_entry("isoc_data", pdir);
  51384. + remove_proc_entry("isoc_test", NULL);
  51385. +}
  51386. +module_exit (cleanup);
  51387. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_cfi_common.h linux-3.12.26/drivers/usb/host/dwc_otg/dwc_cfi_common.h
  51388. --- linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_cfi_common.h 1970-01-01 01:00:00.000000000 +0100
  51389. +++ linux-3.12.26/drivers/usb/host/dwc_otg/dwc_cfi_common.h 2014-08-06 16:50:14.781964569 +0200
  51390. @@ -0,0 +1,142 @@
  51391. +/* ==========================================================================
  51392. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  51393. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  51394. + * otherwise expressly agreed to in writing between Synopsys and you.
  51395. + *
  51396. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  51397. + * any End User Software License Agreement or Agreement for Licensed Product
  51398. + * with Synopsys or any supplement thereto. You are permitted to use and
  51399. + * redistribute this Software in source and binary forms, with or without
  51400. + * modification, provided that redistributions of source code must retain this
  51401. + * notice. You may not view, use, disclose, copy or distribute this file or
  51402. + * any information contained herein except pursuant to this license grant from
  51403. + * Synopsys. If you do not agree with this notice, including the disclaimer
  51404. + * below, then you are not authorized to use the Software.
  51405. + *
  51406. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  51407. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  51408. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  51409. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  51410. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  51411. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  51412. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  51413. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  51414. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  51415. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  51416. + * DAMAGE.
  51417. + * ========================================================================== */
  51418. +
  51419. +#if !defined(__DWC_CFI_COMMON_H__)
  51420. +#define __DWC_CFI_COMMON_H__
  51421. +
  51422. +//#include <linux/types.h>
  51423. +
  51424. +/**
  51425. + * @file
  51426. + *
  51427. + * This file contains the CFI specific common constants, interfaces
  51428. + * (functions and macros) and structures for Linux. No PCD specific
  51429. + * data structure or definition is to be included in this file.
  51430. + *
  51431. + */
  51432. +
  51433. +/** This is a request for all Core Features */
  51434. +#define VEN_CORE_GET_FEATURES 0xB1
  51435. +
  51436. +/** This is a request to get the value of a specific Core Feature */
  51437. +#define VEN_CORE_GET_FEATURE 0xB2
  51438. +
  51439. +/** This command allows the host to set the value of a specific Core Feature */
  51440. +#define VEN_CORE_SET_FEATURE 0xB3
  51441. +
  51442. +/** This command allows the host to set the default values of
  51443. + * either all or any specific Core Feature
  51444. + */
  51445. +#define VEN_CORE_RESET_FEATURES 0xB4
  51446. +
  51447. +/** This command forces the PCD to write the deferred values of a Core Features */
  51448. +#define VEN_CORE_ACTIVATE_FEATURES 0xB5
  51449. +
  51450. +/** This request reads a DWORD value from a register at the specified offset */
  51451. +#define VEN_CORE_READ_REGISTER 0xB6
  51452. +
  51453. +/** This request writes a DWORD value into a register at the specified offset */
  51454. +#define VEN_CORE_WRITE_REGISTER 0xB7
  51455. +
  51456. +/** This structure is the header of the Core Features dataset returned to
  51457. + * the Host
  51458. + */
  51459. +struct cfi_all_features_header {
  51460. +/** The features header structure length is */
  51461. +#define CFI_ALL_FEATURES_HDR_LEN 8
  51462. + /**
  51463. + * The total length of the features dataset returned to the Host
  51464. + */
  51465. + uint16_t wTotalLen;
  51466. +
  51467. + /**
  51468. + * CFI version number inBinary-Coded Decimal (i.e., 1.00 is 100H).
  51469. + * This field identifies the version of the CFI Specification with which
  51470. + * the device is compliant.
  51471. + */
  51472. + uint16_t wVersion;
  51473. +
  51474. + /** The ID of the Core */
  51475. + uint16_t wCoreID;
  51476. +#define CFI_CORE_ID_UDC 1
  51477. +#define CFI_CORE_ID_OTG 2
  51478. +#define CFI_CORE_ID_WUDEV 3
  51479. +
  51480. + /** Number of features returned by VEN_CORE_GET_FEATURES request */
  51481. + uint16_t wNumFeatures;
  51482. +} UPACKED;
  51483. +
  51484. +typedef struct cfi_all_features_header cfi_all_features_header_t;
  51485. +
  51486. +/** This structure is a header of the Core Feature descriptor dataset returned to
  51487. + * the Host after the VEN_CORE_GET_FEATURES request
  51488. + */
  51489. +struct cfi_feature_desc_header {
  51490. +#define CFI_FEATURE_DESC_HDR_LEN 8
  51491. +
  51492. + /** The feature ID */
  51493. + uint16_t wFeatureID;
  51494. +
  51495. + /** Length of this feature descriptor in bytes - including the
  51496. + * length of the feature name string
  51497. + */
  51498. + uint16_t wLength;
  51499. +
  51500. + /** The data length of this feature in bytes */
  51501. + uint16_t wDataLength;
  51502. +
  51503. + /**
  51504. + * Attributes of this features
  51505. + * D0: Access rights
  51506. + * 0 - Read/Write
  51507. + * 1 - Read only
  51508. + */
  51509. + uint8_t bmAttributes;
  51510. +#define CFI_FEATURE_ATTR_RO 1
  51511. +#define CFI_FEATURE_ATTR_RW 0
  51512. +
  51513. + /** Length of the feature name in bytes */
  51514. + uint8_t bNameLen;
  51515. +
  51516. + /** The feature name buffer */
  51517. + //uint8_t *name;
  51518. +} UPACKED;
  51519. +
  51520. +typedef struct cfi_feature_desc_header cfi_feature_desc_header_t;
  51521. +
  51522. +/**
  51523. + * This structure describes a NULL terminated string referenced by its id field.
  51524. + * It is very similar to usb_string structure but has the id field type set to 16-bit.
  51525. + */
  51526. +struct cfi_string {
  51527. + uint16_t id;
  51528. + const uint8_t *s;
  51529. +};
  51530. +typedef struct cfi_string cfi_string_t;
  51531. +
  51532. +#endif
  51533. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_adp.c linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_adp.c
  51534. --- linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_adp.c 1970-01-01 01:00:00.000000000 +0100
  51535. +++ linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_adp.c 2014-08-06 16:50:14.781964569 +0200
  51536. @@ -0,0 +1,854 @@
  51537. +/* ==========================================================================
  51538. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_adp.c $
  51539. + * $Revision: #12 $
  51540. + * $Date: 2011/10/26 $
  51541. + * $Change: 1873028 $
  51542. + *
  51543. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  51544. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  51545. + * otherwise expressly agreed to in writing between Synopsys and you.
  51546. + *
  51547. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  51548. + * any End User Software License Agreement or Agreement for Licensed Product
  51549. + * with Synopsys or any supplement thereto. You are permitted to use and
  51550. + * redistribute this Software in source and binary forms, with or without
  51551. + * modification, provided that redistributions of source code must retain this
  51552. + * notice. You may not view, use, disclose, copy or distribute this file or
  51553. + * any information contained herein except pursuant to this license grant from
  51554. + * Synopsys. If you do not agree with this notice, including the disclaimer
  51555. + * below, then you are not authorized to use the Software.
  51556. + *
  51557. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  51558. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  51559. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  51560. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  51561. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  51562. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  51563. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  51564. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  51565. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  51566. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  51567. + * DAMAGE.
  51568. + * ========================================================================== */
  51569. +
  51570. +#include "dwc_os.h"
  51571. +#include "dwc_otg_regs.h"
  51572. +#include "dwc_otg_cil.h"
  51573. +#include "dwc_otg_adp.h"
  51574. +
  51575. +/** @file
  51576. + *
  51577. + * This file contains the most of the Attach Detect Protocol implementation for
  51578. + * the driver to support OTG Rev2.0.
  51579. + *
  51580. + */
  51581. +
  51582. +void dwc_otg_adp_write_reg(dwc_otg_core_if_t * core_if, uint32_t value)
  51583. +{
  51584. + adpctl_data_t adpctl;
  51585. +
  51586. + adpctl.d32 = value;
  51587. + adpctl.b.ar = 0x2;
  51588. +
  51589. + DWC_WRITE_REG32(&core_if->core_global_regs->adpctl, adpctl.d32);
  51590. +
  51591. + while (adpctl.b.ar) {
  51592. + adpctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->adpctl);
  51593. + }
  51594. +
  51595. +}
  51596. +
  51597. +/**
  51598. + * Function is called to read ADP registers
  51599. + */
  51600. +uint32_t dwc_otg_adp_read_reg(dwc_otg_core_if_t * core_if)
  51601. +{
  51602. + adpctl_data_t adpctl;
  51603. +
  51604. + adpctl.d32 = 0;
  51605. + adpctl.b.ar = 0x1;
  51606. +
  51607. + DWC_WRITE_REG32(&core_if->core_global_regs->adpctl, adpctl.d32);
  51608. +
  51609. + while (adpctl.b.ar) {
  51610. + adpctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->adpctl);
  51611. + }
  51612. +
  51613. + return adpctl.d32;
  51614. +}
  51615. +
  51616. +/**
  51617. + * Function is called to read ADPCTL register and filter Write-clear bits
  51618. + */
  51619. +uint32_t dwc_otg_adp_read_reg_filter(dwc_otg_core_if_t * core_if)
  51620. +{
  51621. + adpctl_data_t adpctl;
  51622. +
  51623. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  51624. + adpctl.b.adp_tmout_int = 0;
  51625. + adpctl.b.adp_prb_int = 0;
  51626. + adpctl.b.adp_tmout_int = 0;
  51627. +
  51628. + return adpctl.d32;
  51629. +}
  51630. +
  51631. +/**
  51632. + * Function is called to write ADP registers
  51633. + */
  51634. +void dwc_otg_adp_modify_reg(dwc_otg_core_if_t * core_if, uint32_t clr,
  51635. + uint32_t set)
  51636. +{
  51637. + dwc_otg_adp_write_reg(core_if,
  51638. + (dwc_otg_adp_read_reg(core_if) & (~clr)) | set);
  51639. +}
  51640. +
  51641. +static void adp_sense_timeout(void *ptr)
  51642. +{
  51643. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  51644. + core_if->adp.sense_timer_started = 0;
  51645. + DWC_PRINTF("ADP SENSE TIMEOUT\n");
  51646. + if (core_if->adp_enable) {
  51647. + dwc_otg_adp_sense_stop(core_if);
  51648. + dwc_otg_adp_probe_start(core_if);
  51649. + }
  51650. +}
  51651. +
  51652. +/**
  51653. + * This function is called when the ADP vbus timer expires. Timeout is 1.1s.
  51654. + */
  51655. +static void adp_vbuson_timeout(void *ptr)
  51656. +{
  51657. + gpwrdn_data_t gpwrdn;
  51658. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  51659. + hprt0_data_t hprt0 = {.d32 = 0 };
  51660. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  51661. + DWC_PRINTF("%s: 1.1 seconds expire after turning on VBUS\n",__FUNCTION__);
  51662. + if (core_if) {
  51663. + core_if->adp.vbuson_timer_started = 0;
  51664. + /* Turn off vbus */
  51665. + hprt0.b.prtpwr = 1;
  51666. + DWC_MODIFY_REG32(core_if->host_if->hprt0, hprt0.d32, 0);
  51667. + gpwrdn.d32 = 0;
  51668. +
  51669. + /* Power off the core */
  51670. + if (core_if->power_down == 2) {
  51671. + /* Enable Wakeup Logic */
  51672. +// gpwrdn.b.wkupactiv = 1;
  51673. + gpwrdn.b.pmuactv = 0;
  51674. + gpwrdn.b.pwrdnrstn = 1;
  51675. + gpwrdn.b.pwrdnclmp = 1;
  51676. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  51677. + gpwrdn.d32);
  51678. +
  51679. + /* Suspend the Phy Clock */
  51680. + pcgcctl.b.stoppclk = 1;
  51681. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  51682. +
  51683. + /* Switch on VDD */
  51684. +// gpwrdn.b.wkupactiv = 1;
  51685. + gpwrdn.b.pmuactv = 1;
  51686. + gpwrdn.b.pwrdnrstn = 1;
  51687. + gpwrdn.b.pwrdnclmp = 1;
  51688. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  51689. + gpwrdn.d32);
  51690. + } else {
  51691. + /* Enable Power Down Logic */
  51692. + gpwrdn.b.pmuintsel = 1;
  51693. + gpwrdn.b.pmuactv = 1;
  51694. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  51695. + }
  51696. +
  51697. + /* Power off the core */
  51698. + if (core_if->power_down == 2) {
  51699. + gpwrdn.d32 = 0;
  51700. + gpwrdn.b.pwrdnswtch = 1;
  51701. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn,
  51702. + gpwrdn.d32, 0);
  51703. + }
  51704. +
  51705. + /* Unmask SRP detected interrupt from Power Down Logic */
  51706. + gpwrdn.d32 = 0;
  51707. + gpwrdn.b.srp_det_msk = 1;
  51708. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  51709. +
  51710. + dwc_otg_adp_probe_start(core_if);
  51711. + dwc_otg_dump_global_registers(core_if);
  51712. + dwc_otg_dump_host_registers(core_if);
  51713. + }
  51714. +
  51715. +}
  51716. +
  51717. +/**
  51718. + * Start the ADP Initial Probe timer to detect if Port Connected interrupt is
  51719. + * not asserted within 1.1 seconds.
  51720. + *
  51721. + * @param core_if the pointer to core_if strucure.
  51722. + */
  51723. +void dwc_otg_adp_vbuson_timer_start(dwc_otg_core_if_t * core_if)
  51724. +{
  51725. + core_if->adp.vbuson_timer_started = 1;
  51726. + if (core_if->adp.vbuson_timer)
  51727. + {
  51728. + DWC_PRINTF("SCHEDULING VBUSON TIMER\n");
  51729. + /* 1.1 secs + 60ms necessary for cil_hcd_start*/
  51730. + DWC_TIMER_SCHEDULE(core_if->adp.vbuson_timer, 1160);
  51731. + } else {
  51732. + DWC_WARN("VBUSON_TIMER = %p\n",core_if->adp.vbuson_timer);
  51733. + }
  51734. +}
  51735. +
  51736. +#if 0
  51737. +/**
  51738. + * Masks all DWC OTG core interrupts
  51739. + *
  51740. + */
  51741. +static void mask_all_interrupts(dwc_otg_core_if_t * core_if)
  51742. +{
  51743. + int i;
  51744. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  51745. +
  51746. + /* Mask Host Interrupts */
  51747. +
  51748. + /* Clear and disable HCINTs */
  51749. + for (i = 0; i < core_if->core_params->host_channels; i++) {
  51750. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[i]->hcintmsk, 0);
  51751. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[i]->hcint, 0xFFFFFFFF);
  51752. +
  51753. + }
  51754. +
  51755. + /* Clear and disable HAINT */
  51756. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->haintmsk, 0x0000);
  51757. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->haint, 0xFFFFFFFF);
  51758. +
  51759. + /* Mask Device Interrupts */
  51760. + if (!core_if->multiproc_int_enable) {
  51761. + /* Clear and disable IN Endpoint interrupts */
  51762. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->diepmsk, 0);
  51763. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  51764. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->
  51765. + diepint, 0xFFFFFFFF);
  51766. + }
  51767. +
  51768. + /* Clear and disable OUT Endpoint interrupts */
  51769. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->doepmsk, 0);
  51770. + for (i = 0; i <= core_if->dev_if->num_out_eps; i++) {
  51771. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->
  51772. + doepint, 0xFFFFFFFF);
  51773. + }
  51774. +
  51775. + /* Clear and disable DAINT */
  51776. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->daint,
  51777. + 0xFFFFFFFF);
  51778. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->daintmsk, 0);
  51779. + } else {
  51780. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  51781. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  51782. + diepeachintmsk[i], 0);
  51783. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->
  51784. + diepint, 0xFFFFFFFF);
  51785. + }
  51786. +
  51787. + for (i = 0; i < core_if->dev_if->num_out_eps; ++i) {
  51788. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  51789. + doepeachintmsk[i], 0);
  51790. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->
  51791. + doepint, 0xFFFFFFFF);
  51792. + }
  51793. +
  51794. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->deachintmsk,
  51795. + 0);
  51796. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->deachint,
  51797. + 0xFFFFFFFF);
  51798. +
  51799. + }
  51800. +
  51801. + /* Disable interrupts */
  51802. + ahbcfg.b.glblintrmsk = 1;
  51803. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, ahbcfg.d32, 0);
  51804. +
  51805. + /* Disable all interrupts. */
  51806. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, 0);
  51807. +
  51808. + /* Clear any pending interrupts */
  51809. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  51810. +
  51811. + /* Clear any pending OTG Interrupts */
  51812. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgint, 0xFFFFFFFF);
  51813. +}
  51814. +
  51815. +/**
  51816. + * Unmask Port Connection Detected interrupt
  51817. + *
  51818. + */
  51819. +static void unmask_conn_det_intr(dwc_otg_core_if_t * core_if)
  51820. +{
  51821. + gintmsk_data_t gintmsk = {.d32 = 0,.b.portintr = 1 };
  51822. +
  51823. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32);
  51824. +}
  51825. +#endif
  51826. +
  51827. +/**
  51828. + * Starts the ADP Probing
  51829. + *
  51830. + * @param core_if the pointer to core_if structure.
  51831. + */
  51832. +uint32_t dwc_otg_adp_probe_start(dwc_otg_core_if_t * core_if)
  51833. +{
  51834. +
  51835. + adpctl_data_t adpctl = {.d32 = 0};
  51836. + gpwrdn_data_t gpwrdn;
  51837. +#if 0
  51838. + adpctl_data_t adpctl_int = {.d32 = 0, .b.adp_prb_int = 1,
  51839. + .b.adp_sns_int = 1, b.adp_tmout_int};
  51840. +#endif
  51841. + dwc_otg_disable_global_interrupts(core_if);
  51842. + DWC_PRINTF("ADP Probe Start\n");
  51843. + core_if->adp.probe_enabled = 1;
  51844. +
  51845. + adpctl.b.adpres = 1;
  51846. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51847. +
  51848. + while (adpctl.b.adpres) {
  51849. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  51850. + }
  51851. +
  51852. + adpctl.d32 = 0;
  51853. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  51854. +
  51855. + /* In Host mode unmask SRP detected interrupt */
  51856. + gpwrdn.d32 = 0;
  51857. + gpwrdn.b.sts_chngint_msk = 1;
  51858. + if (!gpwrdn.b.idsts) {
  51859. + gpwrdn.b.srp_det_msk = 1;
  51860. + }
  51861. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  51862. +
  51863. + adpctl.b.adp_tmout_int_msk = 1;
  51864. + adpctl.b.adp_prb_int_msk = 1;
  51865. + adpctl.b.prb_dschg = 1;
  51866. + adpctl.b.prb_delta = 1;
  51867. + adpctl.b.prb_per = 1;
  51868. + adpctl.b.adpen = 1;
  51869. + adpctl.b.enaprb = 1;
  51870. +
  51871. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51872. + DWC_PRINTF("ADP Probe Finish\n");
  51873. + return 0;
  51874. +}
  51875. +
  51876. +/**
  51877. + * Starts the ADP Sense timer to detect if ADP Sense interrupt is not asserted
  51878. + * within 3 seconds.
  51879. + *
  51880. + * @param core_if the pointer to core_if strucure.
  51881. + */
  51882. +void dwc_otg_adp_sense_timer_start(dwc_otg_core_if_t * core_if)
  51883. +{
  51884. + core_if->adp.sense_timer_started = 1;
  51885. + DWC_TIMER_SCHEDULE(core_if->adp.sense_timer, 3000 /* 3 secs */ );
  51886. +}
  51887. +
  51888. +/**
  51889. + * Starts the ADP Sense
  51890. + *
  51891. + * @param core_if the pointer to core_if strucure.
  51892. + */
  51893. +uint32_t dwc_otg_adp_sense_start(dwc_otg_core_if_t * core_if)
  51894. +{
  51895. + adpctl_data_t adpctl;
  51896. +
  51897. + DWC_PRINTF("ADP Sense Start\n");
  51898. +
  51899. + /* Unmask ADP sense interrupt and mask all other from the core */
  51900. + adpctl.d32 = dwc_otg_adp_read_reg_filter(core_if);
  51901. + adpctl.b.adp_sns_int_msk = 1;
  51902. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51903. + dwc_otg_disable_global_interrupts(core_if); // vahrama
  51904. +
  51905. + /* Set ADP reset bit*/
  51906. + adpctl.d32 = dwc_otg_adp_read_reg_filter(core_if);
  51907. + adpctl.b.adpres = 1;
  51908. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51909. +
  51910. + while (adpctl.b.adpres) {
  51911. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  51912. + }
  51913. +
  51914. + adpctl.b.adpres = 0;
  51915. + adpctl.b.adpen = 1;
  51916. + adpctl.b.enasns = 1;
  51917. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51918. +
  51919. + dwc_otg_adp_sense_timer_start(core_if);
  51920. +
  51921. + return 0;
  51922. +}
  51923. +
  51924. +/**
  51925. + * Stops the ADP Probing
  51926. + *
  51927. + * @param core_if the pointer to core_if strucure.
  51928. + */
  51929. +uint32_t dwc_otg_adp_probe_stop(dwc_otg_core_if_t * core_if)
  51930. +{
  51931. +
  51932. + adpctl_data_t adpctl;
  51933. + DWC_PRINTF("Stop ADP probe\n");
  51934. + core_if->adp.probe_enabled = 0;
  51935. + core_if->adp.probe_counter = 0;
  51936. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  51937. +
  51938. + adpctl.b.adpen = 0;
  51939. + adpctl.b.adp_prb_int = 1;
  51940. + adpctl.b.adp_tmout_int = 1;
  51941. + adpctl.b.adp_sns_int = 1;
  51942. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51943. +
  51944. + return 0;
  51945. +}
  51946. +
  51947. +/**
  51948. + * Stops the ADP Sensing
  51949. + *
  51950. + * @param core_if the pointer to core_if strucure.
  51951. + */
  51952. +uint32_t dwc_otg_adp_sense_stop(dwc_otg_core_if_t * core_if)
  51953. +{
  51954. + adpctl_data_t adpctl;
  51955. +
  51956. + core_if->adp.sense_enabled = 0;
  51957. +
  51958. + adpctl.d32 = dwc_otg_adp_read_reg_filter(core_if);
  51959. + adpctl.b.enasns = 0;
  51960. + adpctl.b.adp_sns_int = 1;
  51961. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51962. +
  51963. + return 0;
  51964. +}
  51965. +
  51966. +/**
  51967. + * Called to turn on the VBUS after initial ADP probe in host mode.
  51968. + * If port power was already enabled in cil_hcd_start function then
  51969. + * only schedule a timer.
  51970. + *
  51971. + * @param core_if the pointer to core_if structure.
  51972. + */
  51973. +void dwc_otg_adp_turnon_vbus(dwc_otg_core_if_t * core_if)
  51974. +{
  51975. + hprt0_data_t hprt0 = {.d32 = 0 };
  51976. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  51977. + DWC_PRINTF("Turn on VBUS for 1.1s, port power is %d\n", hprt0.b.prtpwr);
  51978. +
  51979. + if (hprt0.b.prtpwr == 0) {
  51980. + hprt0.b.prtpwr = 1;
  51981. + //DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  51982. + }
  51983. +
  51984. + dwc_otg_adp_vbuson_timer_start(core_if);
  51985. +}
  51986. +
  51987. +/**
  51988. + * Called right after driver is loaded
  51989. + * to perform initial actions for ADP
  51990. + *
  51991. + * @param core_if the pointer to core_if structure.
  51992. + * @param is_host - flag for current mode of operation either from GINTSTS or GPWRDN
  51993. + */
  51994. +void dwc_otg_adp_start(dwc_otg_core_if_t * core_if, uint8_t is_host)
  51995. +{
  51996. + gpwrdn_data_t gpwrdn;
  51997. +
  51998. + DWC_PRINTF("ADP Initial Start\n");
  51999. + core_if->adp.adp_started = 1;
  52000. +
  52001. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  52002. + dwc_otg_disable_global_interrupts(core_if);
  52003. + if (is_host) {
  52004. + DWC_PRINTF("HOST MODE\n");
  52005. + /* Enable Power Down Logic Interrupt*/
  52006. + gpwrdn.d32 = 0;
  52007. + gpwrdn.b.pmuintsel = 1;
  52008. + gpwrdn.b.pmuactv = 1;
  52009. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  52010. + /* Initialize first ADP probe to obtain Ramp Time value */
  52011. + core_if->adp.initial_probe = 1;
  52012. + dwc_otg_adp_probe_start(core_if);
  52013. + } else {
  52014. + gotgctl_data_t gotgctl;
  52015. + gotgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  52016. + DWC_PRINTF("DEVICE MODE\n");
  52017. + if (gotgctl.b.bsesvld == 0) {
  52018. + /* Enable Power Down Logic Interrupt*/
  52019. + gpwrdn.d32 = 0;
  52020. + DWC_PRINTF("VBUS is not valid - start ADP probe\n");
  52021. + gpwrdn.b.pmuintsel = 1;
  52022. + gpwrdn.b.pmuactv = 1;
  52023. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  52024. + core_if->adp.initial_probe = 1;
  52025. + dwc_otg_adp_probe_start(core_if);
  52026. + } else {
  52027. + DWC_PRINTF("VBUS is valid - initialize core as a Device\n");
  52028. + core_if->op_state = B_PERIPHERAL;
  52029. + dwc_otg_core_init(core_if);
  52030. + dwc_otg_enable_global_interrupts(core_if);
  52031. + cil_pcd_start(core_if);
  52032. + dwc_otg_dump_global_registers(core_if);
  52033. + dwc_otg_dump_dev_registers(core_if);
  52034. + }
  52035. + }
  52036. +}
  52037. +
  52038. +void dwc_otg_adp_init(dwc_otg_core_if_t * core_if)
  52039. +{
  52040. + core_if->adp.adp_started = 0;
  52041. + core_if->adp.initial_probe = 0;
  52042. + core_if->adp.probe_timer_values[0] = -1;
  52043. + core_if->adp.probe_timer_values[1] = -1;
  52044. + core_if->adp.probe_enabled = 0;
  52045. + core_if->adp.sense_enabled = 0;
  52046. + core_if->adp.sense_timer_started = 0;
  52047. + core_if->adp.vbuson_timer_started = 0;
  52048. + core_if->adp.probe_counter = 0;
  52049. + core_if->adp.gpwrdn = 0;
  52050. + core_if->adp.attached = DWC_OTG_ADP_UNKOWN;
  52051. + /* Initialize timers */
  52052. + core_if->adp.sense_timer =
  52053. + DWC_TIMER_ALLOC("ADP SENSE TIMER", adp_sense_timeout, core_if);
  52054. + core_if->adp.vbuson_timer =
  52055. + DWC_TIMER_ALLOC("ADP VBUS ON TIMER", adp_vbuson_timeout, core_if);
  52056. + if (!core_if->adp.sense_timer || !core_if->adp.vbuson_timer)
  52057. + {
  52058. + DWC_ERROR("Could not allocate memory for ADP timers\n");
  52059. + }
  52060. +}
  52061. +
  52062. +void dwc_otg_adp_remove(dwc_otg_core_if_t * core_if)
  52063. +{
  52064. + gpwrdn_data_t gpwrdn = { .d32 = 0 };
  52065. + gpwrdn.b.pmuintsel = 1;
  52066. + gpwrdn.b.pmuactv = 1;
  52067. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  52068. +
  52069. + if (core_if->adp.probe_enabled)
  52070. + dwc_otg_adp_probe_stop(core_if);
  52071. + if (core_if->adp.sense_enabled)
  52072. + dwc_otg_adp_sense_stop(core_if);
  52073. + if (core_if->adp.sense_timer_started)
  52074. + DWC_TIMER_CANCEL(core_if->adp.sense_timer);
  52075. + if (core_if->adp.vbuson_timer_started)
  52076. + DWC_TIMER_CANCEL(core_if->adp.vbuson_timer);
  52077. + DWC_TIMER_FREE(core_if->adp.sense_timer);
  52078. + DWC_TIMER_FREE(core_if->adp.vbuson_timer);
  52079. +}
  52080. +
  52081. +/////////////////////////////////////////////////////////////////////
  52082. +////////////// ADP Interrupt Handlers ///////////////////////////////
  52083. +/////////////////////////////////////////////////////////////////////
  52084. +/**
  52085. + * This function sets Ramp Timer values
  52086. + */
  52087. +static uint32_t set_timer_value(dwc_otg_core_if_t * core_if, uint32_t val)
  52088. +{
  52089. + if (core_if->adp.probe_timer_values[0] == -1) {
  52090. + core_if->adp.probe_timer_values[0] = val;
  52091. + core_if->adp.probe_timer_values[1] = -1;
  52092. + return 1;
  52093. + } else {
  52094. + core_if->adp.probe_timer_values[1] =
  52095. + core_if->adp.probe_timer_values[0];
  52096. + core_if->adp.probe_timer_values[0] = val;
  52097. + return 0;
  52098. + }
  52099. +}
  52100. +
  52101. +/**
  52102. + * This function compares Ramp Timer values
  52103. + */
  52104. +static uint32_t compare_timer_values(dwc_otg_core_if_t * core_if)
  52105. +{
  52106. + uint32_t diff;
  52107. + if (core_if->adp.probe_timer_values[0]>=core_if->adp.probe_timer_values[1])
  52108. + diff = core_if->adp.probe_timer_values[0]-core_if->adp.probe_timer_values[1];
  52109. + else
  52110. + diff = core_if->adp.probe_timer_values[1]-core_if->adp.probe_timer_values[0];
  52111. + if(diff < 2) {
  52112. + return 0;
  52113. + } else {
  52114. + return 1;
  52115. + }
  52116. +}
  52117. +
  52118. +/**
  52119. + * This function handles ADP Probe Interrupts
  52120. + */
  52121. +static int32_t dwc_otg_adp_handle_prb_intr(dwc_otg_core_if_t * core_if,
  52122. + uint32_t val)
  52123. +{
  52124. + adpctl_data_t adpctl = {.d32 = 0 };
  52125. + gpwrdn_data_t gpwrdn, temp;
  52126. + adpctl.d32 = val;
  52127. +
  52128. + temp.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  52129. + core_if->adp.probe_counter++;
  52130. + core_if->adp.gpwrdn = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  52131. + if (adpctl.b.rtim == 0 && !temp.b.idsts){
  52132. + DWC_PRINTF("RTIM value is 0\n");
  52133. + goto exit;
  52134. + }
  52135. + if (set_timer_value(core_if, adpctl.b.rtim) &&
  52136. + core_if->adp.initial_probe) {
  52137. + core_if->adp.initial_probe = 0;
  52138. + dwc_otg_adp_probe_stop(core_if);
  52139. + gpwrdn.d32 = 0;
  52140. + gpwrdn.b.pmuactv = 1;
  52141. + gpwrdn.b.pmuintsel = 1;
  52142. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  52143. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  52144. +
  52145. + /* check which value is for device mode and which for Host mode */
  52146. + if (!temp.b.idsts) { /* considered host mode value is 0 */
  52147. + /*
  52148. + * Turn on VBUS after initial ADP probe.
  52149. + */
  52150. + core_if->op_state = A_HOST;
  52151. + dwc_otg_enable_global_interrupts(core_if);
  52152. + DWC_SPINUNLOCK(core_if->lock);
  52153. + cil_hcd_start(core_if);
  52154. + dwc_otg_adp_turnon_vbus(core_if);
  52155. + DWC_SPINLOCK(core_if->lock);
  52156. + } else {
  52157. + /*
  52158. + * Initiate SRP after initial ADP probe.
  52159. + */
  52160. + dwc_otg_enable_global_interrupts(core_if);
  52161. + dwc_otg_initiate_srp(core_if);
  52162. + }
  52163. + } else if (core_if->adp.probe_counter > 2){
  52164. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  52165. + if (compare_timer_values(core_if)) {
  52166. + DWC_PRINTF("Difference in timer values !!! \n");
  52167. +// core_if->adp.attached = DWC_OTG_ADP_ATTACHED;
  52168. + dwc_otg_adp_probe_stop(core_if);
  52169. +
  52170. + /* Power on the core */
  52171. + if (core_if->power_down == 2) {
  52172. + gpwrdn.b.pwrdnswtch = 1;
  52173. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  52174. + gpwrdn, 0, gpwrdn.d32);
  52175. + }
  52176. +
  52177. + /* check which value is for device mode and which for Host mode */
  52178. + if (!temp.b.idsts) { /* considered host mode value is 0 */
  52179. + /* Disable Interrupt from Power Down Logic */
  52180. + gpwrdn.d32 = 0;
  52181. + gpwrdn.b.pmuintsel = 1;
  52182. + gpwrdn.b.pmuactv = 1;
  52183. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  52184. + gpwrdn, gpwrdn.d32, 0);
  52185. +
  52186. + /*
  52187. + * Initialize the Core for Host mode.
  52188. + */
  52189. + core_if->op_state = A_HOST;
  52190. + dwc_otg_core_init(core_if);
  52191. + dwc_otg_enable_global_interrupts(core_if);
  52192. + cil_hcd_start(core_if);
  52193. + } else {
  52194. + gotgctl_data_t gotgctl;
  52195. + /* Mask SRP detected interrupt from Power Down Logic */
  52196. + gpwrdn.d32 = 0;
  52197. + gpwrdn.b.srp_det_msk = 1;
  52198. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  52199. + gpwrdn, gpwrdn.d32, 0);
  52200. +
  52201. + /* Disable Power Down Logic */
  52202. + gpwrdn.d32 = 0;
  52203. + gpwrdn.b.pmuintsel = 1;
  52204. + gpwrdn.b.pmuactv = 1;
  52205. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  52206. + gpwrdn, gpwrdn.d32, 0);
  52207. +
  52208. + /*
  52209. + * Initialize the Core for Device mode.
  52210. + */
  52211. + core_if->op_state = B_PERIPHERAL;
  52212. + dwc_otg_core_init(core_if);
  52213. + dwc_otg_enable_global_interrupts(core_if);
  52214. + cil_pcd_start(core_if);
  52215. +
  52216. + gotgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  52217. + if (!gotgctl.b.bsesvld) {
  52218. + dwc_otg_initiate_srp(core_if);
  52219. + }
  52220. + }
  52221. + }
  52222. + if (core_if->power_down == 2) {
  52223. + if (gpwrdn.b.bsessvld) {
  52224. + /* Mask SRP detected interrupt from Power Down Logic */
  52225. + gpwrdn.d32 = 0;
  52226. + gpwrdn.b.srp_det_msk = 1;
  52227. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  52228. +
  52229. + /* Disable Power Down Logic */
  52230. + gpwrdn.d32 = 0;
  52231. + gpwrdn.b.pmuactv = 1;
  52232. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  52233. +
  52234. + /*
  52235. + * Initialize the Core for Device mode.
  52236. + */
  52237. + core_if->op_state = B_PERIPHERAL;
  52238. + dwc_otg_core_init(core_if);
  52239. + dwc_otg_enable_global_interrupts(core_if);
  52240. + cil_pcd_start(core_if);
  52241. + }
  52242. + }
  52243. + }
  52244. +exit:
  52245. + /* Clear interrupt */
  52246. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  52247. + adpctl.b.adp_prb_int = 1;
  52248. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  52249. +
  52250. + return 0;
  52251. +}
  52252. +
  52253. +/**
  52254. + * This function hadles ADP Sense Interrupt
  52255. + */
  52256. +static int32_t dwc_otg_adp_handle_sns_intr(dwc_otg_core_if_t * core_if)
  52257. +{
  52258. + adpctl_data_t adpctl;
  52259. + /* Stop ADP Sense timer */
  52260. + DWC_TIMER_CANCEL(core_if->adp.sense_timer);
  52261. +
  52262. + /* Restart ADP Sense timer */
  52263. + dwc_otg_adp_sense_timer_start(core_if);
  52264. +
  52265. + /* Clear interrupt */
  52266. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  52267. + adpctl.b.adp_sns_int = 1;
  52268. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  52269. +
  52270. + return 0;
  52271. +}
  52272. +
  52273. +/**
  52274. + * This function handles ADP Probe Interrupts
  52275. + */
  52276. +static int32_t dwc_otg_adp_handle_prb_tmout_intr(dwc_otg_core_if_t * core_if,
  52277. + uint32_t val)
  52278. +{
  52279. + adpctl_data_t adpctl = {.d32 = 0 };
  52280. + adpctl.d32 = val;
  52281. + set_timer_value(core_if, adpctl.b.rtim);
  52282. +
  52283. + /* Clear interrupt */
  52284. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  52285. + adpctl.b.adp_tmout_int = 1;
  52286. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  52287. +
  52288. + return 0;
  52289. +}
  52290. +
  52291. +/**
  52292. + * ADP Interrupt handler.
  52293. + *
  52294. + */
  52295. +int32_t dwc_otg_adp_handle_intr(dwc_otg_core_if_t * core_if)
  52296. +{
  52297. + int retval = 0;
  52298. + adpctl_data_t adpctl = {.d32 = 0};
  52299. +
  52300. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  52301. + DWC_PRINTF("ADPCTL = %08x\n",adpctl.d32);
  52302. +
  52303. + if (adpctl.b.adp_sns_int & adpctl.b.adp_sns_int_msk) {
  52304. + DWC_PRINTF("ADP Sense interrupt\n");
  52305. + retval |= dwc_otg_adp_handle_sns_intr(core_if);
  52306. + }
  52307. + if (adpctl.b.adp_tmout_int & adpctl.b.adp_tmout_int_msk) {
  52308. + DWC_PRINTF("ADP timeout interrupt\n");
  52309. + retval |= dwc_otg_adp_handle_prb_tmout_intr(core_if, adpctl.d32);
  52310. + }
  52311. + if (adpctl.b.adp_prb_int & adpctl.b.adp_prb_int_msk) {
  52312. + DWC_PRINTF("ADP Probe interrupt\n");
  52313. + adpctl.b.adp_prb_int = 1;
  52314. + retval |= dwc_otg_adp_handle_prb_intr(core_if, adpctl.d32);
  52315. + }
  52316. +
  52317. +// dwc_otg_adp_modify_reg(core_if, adpctl.d32, 0);
  52318. + //dwc_otg_adp_write_reg(core_if, adpctl.d32);
  52319. + DWC_PRINTF("RETURN FROM ADP ISR\n");
  52320. +
  52321. + return retval;
  52322. +}
  52323. +
  52324. +/**
  52325. + *
  52326. + * @param core_if Programming view of DWC_otg controller.
  52327. + */
  52328. +int32_t dwc_otg_adp_handle_srp_intr(dwc_otg_core_if_t * core_if)
  52329. +{
  52330. +
  52331. +#ifndef DWC_HOST_ONLY
  52332. + hprt0_data_t hprt0;
  52333. + gpwrdn_data_t gpwrdn;
  52334. + DWC_DEBUGPL(DBG_ANY, "++ Power Down Logic Session Request Interrupt++\n");
  52335. +
  52336. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  52337. + /* check which value is for device mode and which for Host mode */
  52338. + if (!gpwrdn.b.idsts) { /* considered host mode value is 0 */
  52339. + DWC_PRINTF("SRP: Host mode\n");
  52340. +
  52341. + if (core_if->adp_enable) {
  52342. + dwc_otg_adp_probe_stop(core_if);
  52343. +
  52344. + /* Power on the core */
  52345. + if (core_if->power_down == 2) {
  52346. + gpwrdn.b.pwrdnswtch = 1;
  52347. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  52348. + gpwrdn, 0, gpwrdn.d32);
  52349. + }
  52350. +
  52351. + core_if->op_state = A_HOST;
  52352. + dwc_otg_core_init(core_if);
  52353. + dwc_otg_enable_global_interrupts(core_if);
  52354. + cil_hcd_start(core_if);
  52355. + }
  52356. +
  52357. + /* Turn on the port power bit. */
  52358. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  52359. + hprt0.b.prtpwr = 1;
  52360. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  52361. +
  52362. + /* Start the Connection timer. So a message can be displayed
  52363. + * if connect does not occur within 10 seconds. */
  52364. + cil_hcd_session_start(core_if);
  52365. + } else {
  52366. + DWC_PRINTF("SRP: Device mode %s\n", __FUNCTION__);
  52367. + if (core_if->adp_enable) {
  52368. + dwc_otg_adp_probe_stop(core_if);
  52369. +
  52370. + /* Power on the core */
  52371. + if (core_if->power_down == 2) {
  52372. + gpwrdn.b.pwrdnswtch = 1;
  52373. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  52374. + gpwrdn, 0, gpwrdn.d32);
  52375. + }
  52376. +
  52377. + gpwrdn.d32 = 0;
  52378. + gpwrdn.b.pmuactv = 0;
  52379. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  52380. + gpwrdn.d32);
  52381. +
  52382. + core_if->op_state = B_PERIPHERAL;
  52383. + dwc_otg_core_init(core_if);
  52384. + dwc_otg_enable_global_interrupts(core_if);
  52385. + cil_pcd_start(core_if);
  52386. + }
  52387. + }
  52388. +#endif
  52389. + return 1;
  52390. +}
  52391. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_adp.h linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_adp.h
  52392. --- linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_adp.h 1970-01-01 01:00:00.000000000 +0100
  52393. +++ linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_adp.h 2014-08-06 16:50:14.781964569 +0200
  52394. @@ -0,0 +1,80 @@
  52395. +/* ==========================================================================
  52396. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_adp.h $
  52397. + * $Revision: #7 $
  52398. + * $Date: 2011/10/24 $
  52399. + * $Change: 1871159 $
  52400. + *
  52401. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  52402. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  52403. + * otherwise expressly agreed to in writing between Synopsys and you.
  52404. + *
  52405. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  52406. + * any End User Software License Agreement or Agreement for Licensed Product
  52407. + * with Synopsys or any supplement thereto. You are permitted to use and
  52408. + * redistribute this Software in source and binary forms, with or without
  52409. + * modification, provided that redistributions of source code must retain this
  52410. + * notice. You may not view, use, disclose, copy or distribute this file or
  52411. + * any information contained herein except pursuant to this license grant from
  52412. + * Synopsys. If you do not agree with this notice, including the disclaimer
  52413. + * below, then you are not authorized to use the Software.
  52414. + *
  52415. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  52416. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  52417. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  52418. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  52419. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  52420. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  52421. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  52422. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  52423. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  52424. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  52425. + * DAMAGE.
  52426. + * ========================================================================== */
  52427. +
  52428. +#ifndef __DWC_OTG_ADP_H__
  52429. +#define __DWC_OTG_ADP_H__
  52430. +
  52431. +/**
  52432. + * @file
  52433. + *
  52434. + * This file contains the Attach Detect Protocol interfaces and defines
  52435. + * (functions) and structures for Linux.
  52436. + *
  52437. + */
  52438. +
  52439. +#define DWC_OTG_ADP_UNATTACHED 0
  52440. +#define DWC_OTG_ADP_ATTACHED 1
  52441. +#define DWC_OTG_ADP_UNKOWN 2
  52442. +
  52443. +typedef struct dwc_otg_adp {
  52444. + uint32_t adp_started;
  52445. + uint32_t initial_probe;
  52446. + int32_t probe_timer_values[2];
  52447. + uint32_t probe_enabled;
  52448. + uint32_t sense_enabled;
  52449. + dwc_timer_t *sense_timer;
  52450. + uint32_t sense_timer_started;
  52451. + dwc_timer_t *vbuson_timer;
  52452. + uint32_t vbuson_timer_started;
  52453. + uint32_t attached;
  52454. + uint32_t probe_counter;
  52455. + uint32_t gpwrdn;
  52456. +} dwc_otg_adp_t;
  52457. +
  52458. +/**
  52459. + * Attach Detect Protocol functions
  52460. + */
  52461. +
  52462. +extern void dwc_otg_adp_write_reg(dwc_otg_core_if_t * core_if, uint32_t value);
  52463. +extern uint32_t dwc_otg_adp_read_reg(dwc_otg_core_if_t * core_if);
  52464. +extern uint32_t dwc_otg_adp_probe_start(dwc_otg_core_if_t * core_if);
  52465. +extern uint32_t dwc_otg_adp_sense_start(dwc_otg_core_if_t * core_if);
  52466. +extern uint32_t dwc_otg_adp_probe_stop(dwc_otg_core_if_t * core_if);
  52467. +extern uint32_t dwc_otg_adp_sense_stop(dwc_otg_core_if_t * core_if);
  52468. +extern void dwc_otg_adp_start(dwc_otg_core_if_t * core_if, uint8_t is_host);
  52469. +extern void dwc_otg_adp_init(dwc_otg_core_if_t * core_if);
  52470. +extern void dwc_otg_adp_remove(dwc_otg_core_if_t * core_if);
  52471. +extern int32_t dwc_otg_adp_handle_intr(dwc_otg_core_if_t * core_if);
  52472. +extern int32_t dwc_otg_adp_handle_srp_intr(dwc_otg_core_if_t * core_if);
  52473. +
  52474. +#endif //__DWC_OTG_ADP_H__
  52475. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_attr.c linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_attr.c
  52476. --- linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_attr.c 1970-01-01 01:00:00.000000000 +0100
  52477. +++ linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_attr.c 2014-08-06 16:50:14.785964600 +0200
  52478. @@ -0,0 +1,1210 @@
  52479. +/* ==========================================================================
  52480. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_attr.c $
  52481. + * $Revision: #44 $
  52482. + * $Date: 2010/11/29 $
  52483. + * $Change: 1636033 $
  52484. + *
  52485. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  52486. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  52487. + * otherwise expressly agreed to in writing between Synopsys and you.
  52488. + *
  52489. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  52490. + * any End User Software License Agreement or Agreement for Licensed Product
  52491. + * with Synopsys or any supplement thereto. You are permitted to use and
  52492. + * redistribute this Software in source and binary forms, with or without
  52493. + * modification, provided that redistributions of source code must retain this
  52494. + * notice. You may not view, use, disclose, copy or distribute this file or
  52495. + * any information contained herein except pursuant to this license grant from
  52496. + * Synopsys. If you do not agree with this notice, including the disclaimer
  52497. + * below, then you are not authorized to use the Software.
  52498. + *
  52499. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  52500. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  52501. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  52502. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  52503. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  52504. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  52505. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  52506. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  52507. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  52508. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  52509. + * DAMAGE.
  52510. + * ========================================================================== */
  52511. +
  52512. +/** @file
  52513. + *
  52514. + * The diagnostic interface will provide access to the controller for
  52515. + * bringing up the hardware and testing. The Linux driver attributes
  52516. + * feature will be used to provide the Linux Diagnostic
  52517. + * Interface. These attributes are accessed through sysfs.
  52518. + */
  52519. +
  52520. +/** @page "Linux Module Attributes"
  52521. + *
  52522. + * The Linux module attributes feature is used to provide the Linux
  52523. + * Diagnostic Interface. These attributes are accessed through sysfs.
  52524. + * The diagnostic interface will provide access to the controller for
  52525. + * bringing up the hardware and testing.
  52526. +
  52527. + The following table shows the attributes.
  52528. + <table>
  52529. + <tr>
  52530. + <td><b> Name</b></td>
  52531. + <td><b> Description</b></td>
  52532. + <td><b> Access</b></td>
  52533. + </tr>
  52534. +
  52535. + <tr>
  52536. + <td> mode </td>
  52537. + <td> Returns the current mode: 0 for device mode, 1 for host mode</td>
  52538. + <td> Read</td>
  52539. + </tr>
  52540. +
  52541. + <tr>
  52542. + <td> hnpcapable </td>
  52543. + <td> Gets or sets the "HNP-capable" bit in the Core USB Configuraton Register.
  52544. + Read returns the current value.</td>
  52545. + <td> Read/Write</td>
  52546. + </tr>
  52547. +
  52548. + <tr>
  52549. + <td> srpcapable </td>
  52550. + <td> Gets or sets the "SRP-capable" bit in the Core USB Configuraton Register.
  52551. + Read returns the current value.</td>
  52552. + <td> Read/Write</td>
  52553. + </tr>
  52554. +
  52555. + <tr>
  52556. + <td> hsic_connect </td>
  52557. + <td> Gets or sets the "HSIC-Connect" bit in the GLPMCFG Register.
  52558. + Read returns the current value.</td>
  52559. + <td> Read/Write</td>
  52560. + </tr>
  52561. +
  52562. + <tr>
  52563. + <td> inv_sel_hsic </td>
  52564. + <td> Gets or sets the "Invert Select HSIC" bit in the GLPMFG Register.
  52565. + Read returns the current value.</td>
  52566. + <td> Read/Write</td>
  52567. + </tr>
  52568. +
  52569. + <tr>
  52570. + <td> hnp </td>
  52571. + <td> Initiates the Host Negotiation Protocol. Read returns the status.</td>
  52572. + <td> Read/Write</td>
  52573. + </tr>
  52574. +
  52575. + <tr>
  52576. + <td> srp </td>
  52577. + <td> Initiates the Session Request Protocol. Read returns the status.</td>
  52578. + <td> Read/Write</td>
  52579. + </tr>
  52580. +
  52581. + <tr>
  52582. + <td> buspower </td>
  52583. + <td> Gets or sets the Power State of the bus (0 - Off or 1 - On)</td>
  52584. + <td> Read/Write</td>
  52585. + </tr>
  52586. +
  52587. + <tr>
  52588. + <td> bussuspend </td>
  52589. + <td> Suspends the USB bus.</td>
  52590. + <td> Read/Write</td>
  52591. + </tr>
  52592. +
  52593. + <tr>
  52594. + <td> busconnected </td>
  52595. + <td> Gets the connection status of the bus</td>
  52596. + <td> Read</td>
  52597. + </tr>
  52598. +
  52599. + <tr>
  52600. + <td> gotgctl </td>
  52601. + <td> Gets or sets the Core Control Status Register.</td>
  52602. + <td> Read/Write</td>
  52603. + </tr>
  52604. +
  52605. + <tr>
  52606. + <td> gusbcfg </td>
  52607. + <td> Gets or sets the Core USB Configuration Register</td>
  52608. + <td> Read/Write</td>
  52609. + </tr>
  52610. +
  52611. + <tr>
  52612. + <td> grxfsiz </td>
  52613. + <td> Gets or sets the Receive FIFO Size Register</td>
  52614. + <td> Read/Write</td>
  52615. + </tr>
  52616. +
  52617. + <tr>
  52618. + <td> gnptxfsiz </td>
  52619. + <td> Gets or sets the non-periodic Transmit Size Register</td>
  52620. + <td> Read/Write</td>
  52621. + </tr>
  52622. +
  52623. + <tr>
  52624. + <td> gpvndctl </td>
  52625. + <td> Gets or sets the PHY Vendor Control Register</td>
  52626. + <td> Read/Write</td>
  52627. + </tr>
  52628. +
  52629. + <tr>
  52630. + <td> ggpio </td>
  52631. + <td> Gets the value in the lower 16-bits of the General Purpose IO Register
  52632. + or sets the upper 16 bits.</td>
  52633. + <td> Read/Write</td>
  52634. + </tr>
  52635. +
  52636. + <tr>
  52637. + <td> guid </td>
  52638. + <td> Gets or sets the value of the User ID Register</td>
  52639. + <td> Read/Write</td>
  52640. + </tr>
  52641. +
  52642. + <tr>
  52643. + <td> gsnpsid </td>
  52644. + <td> Gets the value of the Synopsys ID Regester</td>
  52645. + <td> Read</td>
  52646. + </tr>
  52647. +
  52648. + <tr>
  52649. + <td> devspeed </td>
  52650. + <td> Gets or sets the device speed setting in the DCFG register</td>
  52651. + <td> Read/Write</td>
  52652. + </tr>
  52653. +
  52654. + <tr>
  52655. + <td> enumspeed </td>
  52656. + <td> Gets the device enumeration Speed.</td>
  52657. + <td> Read</td>
  52658. + </tr>
  52659. +
  52660. + <tr>
  52661. + <td> hptxfsiz </td>
  52662. + <td> Gets the value of the Host Periodic Transmit FIFO</td>
  52663. + <td> Read</td>
  52664. + </tr>
  52665. +
  52666. + <tr>
  52667. + <td> hprt0 </td>
  52668. + <td> Gets or sets the value in the Host Port Control and Status Register</td>
  52669. + <td> Read/Write</td>
  52670. + </tr>
  52671. +
  52672. + <tr>
  52673. + <td> regoffset </td>
  52674. + <td> Sets the register offset for the next Register Access</td>
  52675. + <td> Read/Write</td>
  52676. + </tr>
  52677. +
  52678. + <tr>
  52679. + <td> regvalue </td>
  52680. + <td> Gets or sets the value of the register at the offset in the regoffset attribute.</td>
  52681. + <td> Read/Write</td>
  52682. + </tr>
  52683. +
  52684. + <tr>
  52685. + <td> remote_wakeup </td>
  52686. + <td> On read, shows the status of Remote Wakeup. On write, initiates a remote
  52687. + wakeup of the host. When bit 0 is 1 and Remote Wakeup is enabled, the Remote
  52688. + Wakeup signalling bit in the Device Control Register is set for 1
  52689. + milli-second.</td>
  52690. + <td> Read/Write</td>
  52691. + </tr>
  52692. +
  52693. + <tr>
  52694. + <td> rem_wakeup_pwrdn </td>
  52695. + <td> On read, shows the status core - hibernated or not. On write, initiates
  52696. + a remote wakeup of the device from Hibernation. </td>
  52697. + <td> Read/Write</td>
  52698. + </tr>
  52699. +
  52700. + <tr>
  52701. + <td> mode_ch_tim_en </td>
  52702. + <td> This bit is used to enable or disable the host core to wait for 200 PHY
  52703. + clock cycles at the end of Resume to change the opmode signal to the PHY to 00
  52704. + after Suspend or LPM. </td>
  52705. + <td> Read/Write</td>
  52706. + </tr>
  52707. +
  52708. + <tr>
  52709. + <td> fr_interval </td>
  52710. + <td> On read, shows the value of HFIR Frame Interval. On write, dynamically
  52711. + reload HFIR register during runtime. The application can write a value to this
  52712. + register only after the Port Enable bit of the Host Port Control and Status
  52713. + register (HPRT.PrtEnaPort) has been set </td>
  52714. + <td> Read/Write</td>
  52715. + </tr>
  52716. +
  52717. + <tr>
  52718. + <td> disconnect_us </td>
  52719. + <td> On read, shows the status of disconnect_device_us. On write, sets disconnect_us
  52720. + which causes soft disconnect for 100us. Applicable only for device mode of operation.</td>
  52721. + <td> Read/Write</td>
  52722. + </tr>
  52723. +
  52724. + <tr>
  52725. + <td> regdump </td>
  52726. + <td> Dumps the contents of core registers.</td>
  52727. + <td> Read</td>
  52728. + </tr>
  52729. +
  52730. + <tr>
  52731. + <td> spramdump </td>
  52732. + <td> Dumps the contents of core registers.</td>
  52733. + <td> Read</td>
  52734. + </tr>
  52735. +
  52736. + <tr>
  52737. + <td> hcddump </td>
  52738. + <td> Dumps the current HCD state.</td>
  52739. + <td> Read</td>
  52740. + </tr>
  52741. +
  52742. + <tr>
  52743. + <td> hcd_frrem </td>
  52744. + <td> Shows the average value of the Frame Remaining
  52745. + field in the Host Frame Number/Frame Remaining register when an SOF interrupt
  52746. + occurs. This can be used to determine the average interrupt latency. Also
  52747. + shows the average Frame Remaining value for start_transfer and the "a" and
  52748. + "b" sample points. The "a" and "b" sample points may be used during debugging
  52749. + bto determine how long it takes to execute a section of the HCD code.</td>
  52750. + <td> Read</td>
  52751. + </tr>
  52752. +
  52753. + <tr>
  52754. + <td> rd_reg_test </td>
  52755. + <td> Displays the time required to read the GNPTXFSIZ register many times
  52756. + (the output shows the number of times the register is read).
  52757. + <td> Read</td>
  52758. + </tr>
  52759. +
  52760. + <tr>
  52761. + <td> wr_reg_test </td>
  52762. + <td> Displays the time required to write the GNPTXFSIZ register many times
  52763. + (the output shows the number of times the register is written).
  52764. + <td> Read</td>
  52765. + </tr>
  52766. +
  52767. + <tr>
  52768. + <td> lpm_response </td>
  52769. + <td> Gets or sets lpm_response mode. Applicable only in device mode.
  52770. + <td> Write</td>
  52771. + </tr>
  52772. +
  52773. + <tr>
  52774. + <td> sleep_status </td>
  52775. + <td> Shows sleep status of device.
  52776. + <td> Read</td>
  52777. + </tr>
  52778. +
  52779. + </table>
  52780. +
  52781. + Example usage:
  52782. + To get the current mode:
  52783. + cat /sys/devices/lm0/mode
  52784. +
  52785. + To power down the USB:
  52786. + echo 0 > /sys/devices/lm0/buspower
  52787. + */
  52788. +
  52789. +#include "dwc_otg_os_dep.h"
  52790. +#include "dwc_os.h"
  52791. +#include "dwc_otg_driver.h"
  52792. +#include "dwc_otg_attr.h"
  52793. +#include "dwc_otg_core_if.h"
  52794. +#include "dwc_otg_pcd_if.h"
  52795. +#include "dwc_otg_hcd_if.h"
  52796. +
  52797. +/*
  52798. + * MACROs for defining sysfs attribute
  52799. + */
  52800. +#ifdef LM_INTERFACE
  52801. +
  52802. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  52803. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  52804. +{ \
  52805. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  52806. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  52807. + uint32_t val; \
  52808. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  52809. + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
  52810. +}
  52811. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  52812. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  52813. + const char *buf, size_t count) \
  52814. +{ \
  52815. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  52816. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  52817. + uint32_t set = simple_strtoul(buf, NULL, 16); \
  52818. + dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
  52819. + return count; \
  52820. +}
  52821. +
  52822. +#elif defined(PCI_INTERFACE)
  52823. +
  52824. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  52825. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  52826. +{ \
  52827. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  52828. + uint32_t val; \
  52829. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  52830. + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
  52831. +}
  52832. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  52833. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  52834. + const char *buf, size_t count) \
  52835. +{ \
  52836. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  52837. + uint32_t set = simple_strtoul(buf, NULL, 16); \
  52838. + dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
  52839. + return count; \
  52840. +}
  52841. +
  52842. +#elif defined(PLATFORM_INTERFACE)
  52843. +
  52844. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  52845. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  52846. +{ \
  52847. + struct platform_device *platform_dev = \
  52848. + container_of(_dev, struct platform_device, dev); \
  52849. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  52850. + uint32_t val; \
  52851. + DWC_PRINTF("%s(%p) -> platform_dev %p, otg_dev %p\n", \
  52852. + __func__, _dev, platform_dev, otg_dev); \
  52853. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  52854. + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
  52855. +}
  52856. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  52857. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  52858. + const char *buf, size_t count) \
  52859. +{ \
  52860. + struct platform_device *platform_dev = container_of(_dev, struct platform_device, dev); \
  52861. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  52862. + uint32_t set = simple_strtoul(buf, NULL, 16); \
  52863. + dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
  52864. + return count; \
  52865. +}
  52866. +#endif
  52867. +
  52868. +/*
  52869. + * MACROs for defining sysfs attribute for 32-bit registers
  52870. + */
  52871. +#ifdef LM_INTERFACE
  52872. +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  52873. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  52874. +{ \
  52875. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  52876. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  52877. + uint32_t val; \
  52878. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  52879. + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
  52880. +}
  52881. +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  52882. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  52883. + const char *buf, size_t count) \
  52884. +{ \
  52885. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  52886. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  52887. + uint32_t val = simple_strtoul(buf, NULL, 16); \
  52888. + dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
  52889. + return count; \
  52890. +}
  52891. +#elif defined(PCI_INTERFACE)
  52892. +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  52893. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  52894. +{ \
  52895. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  52896. + uint32_t val; \
  52897. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  52898. + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
  52899. +}
  52900. +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  52901. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  52902. + const char *buf, size_t count) \
  52903. +{ \
  52904. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  52905. + uint32_t val = simple_strtoul(buf, NULL, 16); \
  52906. + dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
  52907. + return count; \
  52908. +}
  52909. +
  52910. +#elif defined(PLATFORM_INTERFACE)
  52911. +#include "dwc_otg_dbg.h"
  52912. +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  52913. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  52914. +{ \
  52915. + struct platform_device *platform_dev = container_of(_dev, struct platform_device, dev); \
  52916. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  52917. + uint32_t val; \
  52918. + DWC_PRINTF("%s(%p) -> platform_dev %p, otg_dev %p\n", \
  52919. + __func__, _dev, platform_dev, otg_dev); \
  52920. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  52921. + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
  52922. +}
  52923. +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  52924. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  52925. + const char *buf, size_t count) \
  52926. +{ \
  52927. + struct platform_device *platform_dev = container_of(_dev, struct platform_device, dev); \
  52928. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  52929. + uint32_t val = simple_strtoul(buf, NULL, 16); \
  52930. + dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
  52931. + return count; \
  52932. +}
  52933. +
  52934. +#endif
  52935. +
  52936. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_RW(_otg_attr_name_,_string_) \
  52937. +DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  52938. +DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  52939. +DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);
  52940. +
  52941. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_RO(_otg_attr_name_,_string_) \
  52942. +DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  52943. +DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);
  52944. +
  52945. +#define DWC_OTG_DEVICE_ATTR_REG32_RW(_otg_attr_name_,_addr_,_string_) \
  52946. +DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  52947. +DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  52948. +DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);
  52949. +
  52950. +#define DWC_OTG_DEVICE_ATTR_REG32_RO(_otg_attr_name_,_addr_,_string_) \
  52951. +DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  52952. +DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);
  52953. +
  52954. +/** @name Functions for Show/Store of Attributes */
  52955. +/**@{*/
  52956. +
  52957. +/**
  52958. + * Helper function returning the otg_device structure of the given device
  52959. + */
  52960. +static dwc_otg_device_t *dwc_otg_drvdev(struct device *_dev)
  52961. +{
  52962. + dwc_otg_device_t *otg_dev;
  52963. + DWC_OTG_GETDRVDEV(otg_dev, _dev);
  52964. + return otg_dev;
  52965. +}
  52966. +
  52967. +/**
  52968. + * Show the register offset of the Register Access.
  52969. + */
  52970. +static ssize_t regoffset_show(struct device *_dev,
  52971. + struct device_attribute *attr, char *buf)
  52972. +{
  52973. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52974. + return snprintf(buf, sizeof("0xFFFFFFFF\n") + 1, "0x%08x\n",
  52975. + otg_dev->os_dep.reg_offset);
  52976. +}
  52977. +
  52978. +/**
  52979. + * Set the register offset for the next Register Access Read/Write
  52980. + */
  52981. +static ssize_t regoffset_store(struct device *_dev,
  52982. + struct device_attribute *attr,
  52983. + const char *buf, size_t count)
  52984. +{
  52985. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52986. + uint32_t offset = simple_strtoul(buf, NULL, 16);
  52987. +#if defined(LM_INTERFACE) || defined(PLATFORM_INTERFACE)
  52988. + if (offset < SZ_256K) {
  52989. +#elif defined(PCI_INTERFACE)
  52990. + if (offset < 0x00040000) {
  52991. +#endif
  52992. + otg_dev->os_dep.reg_offset = offset;
  52993. + } else {
  52994. + dev_err(_dev, "invalid offset\n");
  52995. + }
  52996. +
  52997. + return count;
  52998. +}
  52999. +
  53000. +DEVICE_ATTR(regoffset, S_IRUGO | S_IWUSR, regoffset_show, regoffset_store);
  53001. +
  53002. +/**
  53003. + * Show the value of the register at the offset in the reg_offset
  53004. + * attribute.
  53005. + */
  53006. +static ssize_t regvalue_show(struct device *_dev,
  53007. + struct device_attribute *attr, char *buf)
  53008. +{
  53009. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53010. + uint32_t val;
  53011. + volatile uint32_t *addr;
  53012. +
  53013. + if (otg_dev->os_dep.reg_offset != 0xFFFFFFFF && 0 != otg_dev->os_dep.base) {
  53014. + /* Calculate the address */
  53015. + addr = (uint32_t *) (otg_dev->os_dep.reg_offset +
  53016. + (uint8_t *) otg_dev->os_dep.base);
  53017. + val = DWC_READ_REG32(addr);
  53018. + return snprintf(buf,
  53019. + sizeof("Reg@0xFFFFFFFF = 0xFFFFFFFF\n") + 1,
  53020. + "Reg@0x%06x = 0x%08x\n", otg_dev->os_dep.reg_offset,
  53021. + val);
  53022. + } else {
  53023. + dev_err(_dev, "Invalid offset (0x%0x)\n", otg_dev->os_dep.reg_offset);
  53024. + return sprintf(buf, "invalid offset\n");
  53025. + }
  53026. +}
  53027. +
  53028. +/**
  53029. + * Store the value in the register at the offset in the reg_offset
  53030. + * attribute.
  53031. + *
  53032. + */
  53033. +static ssize_t regvalue_store(struct device *_dev,
  53034. + struct device_attribute *attr,
  53035. + const char *buf, size_t count)
  53036. +{
  53037. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53038. + volatile uint32_t *addr;
  53039. + uint32_t val = simple_strtoul(buf, NULL, 16);
  53040. + //dev_dbg(_dev, "Offset=0x%08x Val=0x%08x\n", otg_dev->reg_offset, val);
  53041. + if (otg_dev->os_dep.reg_offset != 0xFFFFFFFF && 0 != otg_dev->os_dep.base) {
  53042. + /* Calculate the address */
  53043. + addr = (uint32_t *) (otg_dev->os_dep.reg_offset +
  53044. + (uint8_t *) otg_dev->os_dep.base);
  53045. + DWC_WRITE_REG32(addr, val);
  53046. + } else {
  53047. + dev_err(_dev, "Invalid Register Offset (0x%08x)\n",
  53048. + otg_dev->os_dep.reg_offset);
  53049. + }
  53050. + return count;
  53051. +}
  53052. +
  53053. +DEVICE_ATTR(regvalue, S_IRUGO | S_IWUSR, regvalue_show, regvalue_store);
  53054. +
  53055. +/*
  53056. + * Attributes
  53057. + */
  53058. +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(mode, "Mode");
  53059. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(hnpcapable, "HNPCapable");
  53060. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(srpcapable, "SRPCapable");
  53061. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(hsic_connect, "HSIC Connect");
  53062. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(inv_sel_hsic, "Invert Select HSIC");
  53063. +
  53064. +//DWC_OTG_DEVICE_ATTR_BITFIELD_RW(buspower,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");
  53065. +//DWC_OTG_DEVICE_ATTR_BITFIELD_RW(bussuspend,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");
  53066. +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(busconnected, "Bus Connected");
  53067. +
  53068. +DWC_OTG_DEVICE_ATTR_REG32_RW(gotgctl, 0, "GOTGCTL");
  53069. +DWC_OTG_DEVICE_ATTR_REG32_RW(gusbcfg,
  53070. + &(otg_dev->core_if->core_global_regs->gusbcfg),
  53071. + "GUSBCFG");
  53072. +DWC_OTG_DEVICE_ATTR_REG32_RW(grxfsiz,
  53073. + &(otg_dev->core_if->core_global_regs->grxfsiz),
  53074. + "GRXFSIZ");
  53075. +DWC_OTG_DEVICE_ATTR_REG32_RW(gnptxfsiz,
  53076. + &(otg_dev->core_if->core_global_regs->gnptxfsiz),
  53077. + "GNPTXFSIZ");
  53078. +DWC_OTG_DEVICE_ATTR_REG32_RW(gpvndctl,
  53079. + &(otg_dev->core_if->core_global_regs->gpvndctl),
  53080. + "GPVNDCTL");
  53081. +DWC_OTG_DEVICE_ATTR_REG32_RW(ggpio,
  53082. + &(otg_dev->core_if->core_global_regs->ggpio),
  53083. + "GGPIO");
  53084. +DWC_OTG_DEVICE_ATTR_REG32_RW(guid, &(otg_dev->core_if->core_global_regs->guid),
  53085. + "GUID");
  53086. +DWC_OTG_DEVICE_ATTR_REG32_RO(gsnpsid,
  53087. + &(otg_dev->core_if->core_global_regs->gsnpsid),
  53088. + "GSNPSID");
  53089. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(devspeed, "Device Speed");
  53090. +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(enumspeed, "Device Enumeration Speed");
  53091. +
  53092. +DWC_OTG_DEVICE_ATTR_REG32_RO(hptxfsiz,
  53093. + &(otg_dev->core_if->core_global_regs->hptxfsiz),
  53094. + "HPTXFSIZ");
  53095. +DWC_OTG_DEVICE_ATTR_REG32_RW(hprt0, otg_dev->core_if->host_if->hprt0, "HPRT0");
  53096. +
  53097. +/**
  53098. + * @todo Add code to initiate the HNP.
  53099. + */
  53100. +/**
  53101. + * Show the HNP status bit
  53102. + */
  53103. +static ssize_t hnp_show(struct device *_dev,
  53104. + struct device_attribute *attr, char *buf)
  53105. +{
  53106. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53107. + return sprintf(buf, "HstNegScs = 0x%x\n",
  53108. + dwc_otg_get_hnpstatus(otg_dev->core_if));
  53109. +}
  53110. +
  53111. +/**
  53112. + * Set the HNP Request bit
  53113. + */
  53114. +static ssize_t hnp_store(struct device *_dev,
  53115. + struct device_attribute *attr,
  53116. + const char *buf, size_t count)
  53117. +{
  53118. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53119. + uint32_t in = simple_strtoul(buf, NULL, 16);
  53120. + dwc_otg_set_hnpreq(otg_dev->core_if, in);
  53121. + return count;
  53122. +}
  53123. +
  53124. +DEVICE_ATTR(hnp, 0644, hnp_show, hnp_store);
  53125. +
  53126. +/**
  53127. + * @todo Add code to initiate the SRP.
  53128. + */
  53129. +/**
  53130. + * Show the SRP status bit
  53131. + */
  53132. +static ssize_t srp_show(struct device *_dev,
  53133. + struct device_attribute *attr, char *buf)
  53134. +{
  53135. +#ifndef DWC_HOST_ONLY
  53136. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53137. + return sprintf(buf, "SesReqScs = 0x%x\n",
  53138. + dwc_otg_get_srpstatus(otg_dev->core_if));
  53139. +#else
  53140. + return sprintf(buf, "Host Only Mode!\n");
  53141. +#endif
  53142. +}
  53143. +
  53144. +/**
  53145. + * Set the SRP Request bit
  53146. + */
  53147. +static ssize_t srp_store(struct device *_dev,
  53148. + struct device_attribute *attr,
  53149. + const char *buf, size_t count)
  53150. +{
  53151. +#ifndef DWC_HOST_ONLY
  53152. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53153. + dwc_otg_pcd_initiate_srp(otg_dev->pcd);
  53154. +#endif
  53155. + return count;
  53156. +}
  53157. +
  53158. +DEVICE_ATTR(srp, 0644, srp_show, srp_store);
  53159. +
  53160. +/**
  53161. + * @todo Need to do more for power on/off?
  53162. + */
  53163. +/**
  53164. + * Show the Bus Power status
  53165. + */
  53166. +static ssize_t buspower_show(struct device *_dev,
  53167. + struct device_attribute *attr, char *buf)
  53168. +{
  53169. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53170. + return sprintf(buf, "Bus Power = 0x%x\n",
  53171. + dwc_otg_get_prtpower(otg_dev->core_if));
  53172. +}
  53173. +
  53174. +/**
  53175. + * Set the Bus Power status
  53176. + */
  53177. +static ssize_t buspower_store(struct device *_dev,
  53178. + struct device_attribute *attr,
  53179. + const char *buf, size_t count)
  53180. +{
  53181. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53182. + uint32_t on = simple_strtoul(buf, NULL, 16);
  53183. + dwc_otg_set_prtpower(otg_dev->core_if, on);
  53184. + return count;
  53185. +}
  53186. +
  53187. +DEVICE_ATTR(buspower, 0644, buspower_show, buspower_store);
  53188. +
  53189. +/**
  53190. + * @todo Need to do more for suspend?
  53191. + */
  53192. +/**
  53193. + * Show the Bus Suspend status
  53194. + */
  53195. +static ssize_t bussuspend_show(struct device *_dev,
  53196. + struct device_attribute *attr, char *buf)
  53197. +{
  53198. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53199. + return sprintf(buf, "Bus Suspend = 0x%x\n",
  53200. + dwc_otg_get_prtsuspend(otg_dev->core_if));
  53201. +}
  53202. +
  53203. +/**
  53204. + * Set the Bus Suspend status
  53205. + */
  53206. +static ssize_t bussuspend_store(struct device *_dev,
  53207. + struct device_attribute *attr,
  53208. + const char *buf, size_t count)
  53209. +{
  53210. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53211. + uint32_t in = simple_strtoul(buf, NULL, 16);
  53212. + dwc_otg_set_prtsuspend(otg_dev->core_if, in);
  53213. + return count;
  53214. +}
  53215. +
  53216. +DEVICE_ATTR(bussuspend, 0644, bussuspend_show, bussuspend_store);
  53217. +
  53218. +/**
  53219. + * Show the Mode Change Ready Timer status
  53220. + */
  53221. +static ssize_t mode_ch_tim_en_show(struct device *_dev,
  53222. + struct device_attribute *attr, char *buf)
  53223. +{
  53224. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53225. + return sprintf(buf, "Mode Change Ready Timer Enable = 0x%x\n",
  53226. + dwc_otg_get_mode_ch_tim(otg_dev->core_if));
  53227. +}
  53228. +
  53229. +/**
  53230. + * Set the Mode Change Ready Timer status
  53231. + */
  53232. +static ssize_t mode_ch_tim_en_store(struct device *_dev,
  53233. + struct device_attribute *attr,
  53234. + const char *buf, size_t count)
  53235. +{
  53236. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53237. + uint32_t in = simple_strtoul(buf, NULL, 16);
  53238. + dwc_otg_set_mode_ch_tim(otg_dev->core_if, in);
  53239. + return count;
  53240. +}
  53241. +
  53242. +DEVICE_ATTR(mode_ch_tim_en, 0644, mode_ch_tim_en_show, mode_ch_tim_en_store);
  53243. +
  53244. +/**
  53245. + * Show the value of HFIR Frame Interval bitfield
  53246. + */
  53247. +static ssize_t fr_interval_show(struct device *_dev,
  53248. + struct device_attribute *attr, char *buf)
  53249. +{
  53250. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53251. + return sprintf(buf, "Frame Interval = 0x%x\n",
  53252. + dwc_otg_get_fr_interval(otg_dev->core_if));
  53253. +}
  53254. +
  53255. +/**
  53256. + * Set the HFIR Frame Interval value
  53257. + */
  53258. +static ssize_t fr_interval_store(struct device *_dev,
  53259. + struct device_attribute *attr,
  53260. + const char *buf, size_t count)
  53261. +{
  53262. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53263. + uint32_t in = simple_strtoul(buf, NULL, 10);
  53264. + dwc_otg_set_fr_interval(otg_dev->core_if, in);
  53265. + return count;
  53266. +}
  53267. +
  53268. +DEVICE_ATTR(fr_interval, 0644, fr_interval_show, fr_interval_store);
  53269. +
  53270. +/**
  53271. + * Show the status of Remote Wakeup.
  53272. + */
  53273. +static ssize_t remote_wakeup_show(struct device *_dev,
  53274. + struct device_attribute *attr, char *buf)
  53275. +{
  53276. +#ifndef DWC_HOST_ONLY
  53277. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53278. +
  53279. + return sprintf(buf,
  53280. + "Remote Wakeup Sig = %d Enabled = %d LPM Remote Wakeup = %d\n",
  53281. + dwc_otg_get_remotewakesig(otg_dev->core_if),
  53282. + dwc_otg_pcd_get_rmwkup_enable(otg_dev->pcd),
  53283. + dwc_otg_get_lpm_remotewakeenabled(otg_dev->core_if));
  53284. +#else
  53285. + return sprintf(buf, "Host Only Mode!\n");
  53286. +#endif /* DWC_HOST_ONLY */
  53287. +}
  53288. +
  53289. +/**
  53290. + * Initiate a remote wakeup of the host. The Device control register
  53291. + * Remote Wakeup Signal bit is written if the PCD Remote wakeup enable
  53292. + * flag is set.
  53293. + *
  53294. + */
  53295. +static ssize_t remote_wakeup_store(struct device *_dev,
  53296. + struct device_attribute *attr,
  53297. + const char *buf, size_t count)
  53298. +{
  53299. +#ifndef DWC_HOST_ONLY
  53300. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53301. + uint32_t val = simple_strtoul(buf, NULL, 16);
  53302. +
  53303. + if (val & 1) {
  53304. + dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 1);
  53305. + } else {
  53306. + dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 0);
  53307. + }
  53308. +#endif /* DWC_HOST_ONLY */
  53309. + return count;
  53310. +}
  53311. +
  53312. +DEVICE_ATTR(remote_wakeup, S_IRUGO | S_IWUSR, remote_wakeup_show,
  53313. + remote_wakeup_store);
  53314. +
  53315. +/**
  53316. + * Show the whether core is hibernated or not.
  53317. + */
  53318. +static ssize_t rem_wakeup_pwrdn_show(struct device *_dev,
  53319. + struct device_attribute *attr, char *buf)
  53320. +{
  53321. +#ifndef DWC_HOST_ONLY
  53322. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53323. +
  53324. + if (dwc_otg_get_core_state(otg_dev->core_if)) {
  53325. + DWC_PRINTF("Core is in hibernation\n");
  53326. + } else {
  53327. + DWC_PRINTF("Core is not in hibernation\n");
  53328. + }
  53329. +#endif /* DWC_HOST_ONLY */
  53330. + return 0;
  53331. +}
  53332. +
  53333. +extern int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
  53334. + int rem_wakeup, int reset);
  53335. +
  53336. +/**
  53337. + * Initiate a remote wakeup of the device to exit from hibernation.
  53338. + */
  53339. +static ssize_t rem_wakeup_pwrdn_store(struct device *_dev,
  53340. + struct device_attribute *attr,
  53341. + const char *buf, size_t count)
  53342. +{
  53343. +#ifndef DWC_HOST_ONLY
  53344. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53345. + dwc_otg_device_hibernation_restore(otg_dev->core_if, 1, 0);
  53346. +#endif
  53347. + return count;
  53348. +}
  53349. +
  53350. +DEVICE_ATTR(rem_wakeup_pwrdn, S_IRUGO | S_IWUSR, rem_wakeup_pwrdn_show,
  53351. + rem_wakeup_pwrdn_store);
  53352. +
  53353. +static ssize_t disconnect_us(struct device *_dev,
  53354. + struct device_attribute *attr,
  53355. + const char *buf, size_t count)
  53356. +{
  53357. +
  53358. +#ifndef DWC_HOST_ONLY
  53359. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53360. + uint32_t val = simple_strtoul(buf, NULL, 16);
  53361. + DWC_PRINTF("The Passed value is %04x\n", val);
  53362. +
  53363. + dwc_otg_pcd_disconnect_us(otg_dev->pcd, 50);
  53364. +
  53365. +#endif /* DWC_HOST_ONLY */
  53366. + return count;
  53367. +}
  53368. +
  53369. +DEVICE_ATTR(disconnect_us, S_IWUSR, 0, disconnect_us);
  53370. +
  53371. +/**
  53372. + * Dump global registers and either host or device registers (depending on the
  53373. + * current mode of the core).
  53374. + */
  53375. +static ssize_t regdump_show(struct device *_dev,
  53376. + struct device_attribute *attr, char *buf)
  53377. +{
  53378. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53379. +
  53380. + dwc_otg_dump_global_registers(otg_dev->core_if);
  53381. + if (dwc_otg_is_host_mode(otg_dev->core_if)) {
  53382. + dwc_otg_dump_host_registers(otg_dev->core_if);
  53383. + } else {
  53384. + dwc_otg_dump_dev_registers(otg_dev->core_if);
  53385. +
  53386. + }
  53387. + return sprintf(buf, "Register Dump\n");
  53388. +}
  53389. +
  53390. +DEVICE_ATTR(regdump, S_IRUGO, regdump_show, 0);
  53391. +
  53392. +/**
  53393. + * Dump global registers and either host or device registers (depending on the
  53394. + * current mode of the core).
  53395. + */
  53396. +static ssize_t spramdump_show(struct device *_dev,
  53397. + struct device_attribute *attr, char *buf)
  53398. +{
  53399. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53400. +
  53401. + //dwc_otg_dump_spram(otg_dev->core_if);
  53402. +
  53403. + return sprintf(buf, "SPRAM Dump\n");
  53404. +}
  53405. +
  53406. +DEVICE_ATTR(spramdump, S_IRUGO, spramdump_show, 0);
  53407. +
  53408. +/**
  53409. + * Dump the current hcd state.
  53410. + */
  53411. +static ssize_t hcddump_show(struct device *_dev,
  53412. + struct device_attribute *attr, char *buf)
  53413. +{
  53414. +#ifndef DWC_DEVICE_ONLY
  53415. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53416. + dwc_otg_hcd_dump_state(otg_dev->hcd);
  53417. +#endif /* DWC_DEVICE_ONLY */
  53418. + return sprintf(buf, "HCD Dump\n");
  53419. +}
  53420. +
  53421. +DEVICE_ATTR(hcddump, S_IRUGO, hcddump_show, 0);
  53422. +
  53423. +/**
  53424. + * Dump the average frame remaining at SOF. This can be used to
  53425. + * determine average interrupt latency. Frame remaining is also shown for
  53426. + * start transfer and two additional sample points.
  53427. + */
  53428. +static ssize_t hcd_frrem_show(struct device *_dev,
  53429. + struct device_attribute *attr, char *buf)
  53430. +{
  53431. +#ifndef DWC_DEVICE_ONLY
  53432. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53433. +
  53434. + dwc_otg_hcd_dump_frrem(otg_dev->hcd);
  53435. +#endif /* DWC_DEVICE_ONLY */
  53436. + return sprintf(buf, "HCD Dump Frame Remaining\n");
  53437. +}
  53438. +
  53439. +DEVICE_ATTR(hcd_frrem, S_IRUGO, hcd_frrem_show, 0);
  53440. +
  53441. +/**
  53442. + * Displays the time required to read the GNPTXFSIZ register many times (the
  53443. + * output shows the number of times the register is read).
  53444. + */
  53445. +#define RW_REG_COUNT 10000000
  53446. +#define MSEC_PER_JIFFIE 1000/HZ
  53447. +static ssize_t rd_reg_test_show(struct device *_dev,
  53448. + struct device_attribute *attr, char *buf)
  53449. +{
  53450. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53451. + int i;
  53452. + int time;
  53453. + int start_jiffies;
  53454. +
  53455. + printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
  53456. + HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
  53457. + start_jiffies = jiffies;
  53458. + for (i = 0; i < RW_REG_COUNT; i++) {
  53459. + dwc_otg_get_gnptxfsiz(otg_dev->core_if);
  53460. + }
  53461. + time = jiffies - start_jiffies;
  53462. + return sprintf(buf,
  53463. + "Time to read GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
  53464. + RW_REG_COUNT, time * MSEC_PER_JIFFIE, time);
  53465. +}
  53466. +
  53467. +DEVICE_ATTR(rd_reg_test, S_IRUGO, rd_reg_test_show, 0);
  53468. +
  53469. +/**
  53470. + * Displays the time required to write the GNPTXFSIZ register many times (the
  53471. + * output shows the number of times the register is written).
  53472. + */
  53473. +static ssize_t wr_reg_test_show(struct device *_dev,
  53474. + struct device_attribute *attr, char *buf)
  53475. +{
  53476. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53477. + uint32_t reg_val;
  53478. + int i;
  53479. + int time;
  53480. + int start_jiffies;
  53481. +
  53482. + printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
  53483. + HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
  53484. + reg_val = dwc_otg_get_gnptxfsiz(otg_dev->core_if);
  53485. + start_jiffies = jiffies;
  53486. + for (i = 0; i < RW_REG_COUNT; i++) {
  53487. + dwc_otg_set_gnptxfsiz(otg_dev->core_if, reg_val);
  53488. + }
  53489. + time = jiffies - start_jiffies;
  53490. + return sprintf(buf,
  53491. + "Time to write GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
  53492. + RW_REG_COUNT, time * MSEC_PER_JIFFIE, time);
  53493. +}
  53494. +
  53495. +DEVICE_ATTR(wr_reg_test, S_IRUGO, wr_reg_test_show, 0);
  53496. +
  53497. +#ifdef CONFIG_USB_DWC_OTG_LPM
  53498. +
  53499. +/**
  53500. +* Show the lpm_response attribute.
  53501. +*/
  53502. +static ssize_t lpmresp_show(struct device *_dev,
  53503. + struct device_attribute *attr, char *buf)
  53504. +{
  53505. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53506. +
  53507. + if (!dwc_otg_get_param_lpm_enable(otg_dev->core_if))
  53508. + return sprintf(buf, "** LPM is DISABLED **\n");
  53509. +
  53510. + if (!dwc_otg_is_device_mode(otg_dev->core_if)) {
  53511. + return sprintf(buf, "** Current mode is not device mode\n");
  53512. + }
  53513. + return sprintf(buf, "lpm_response = %d\n",
  53514. + dwc_otg_get_lpmresponse(otg_dev->core_if));
  53515. +}
  53516. +
  53517. +/**
  53518. +* Store the lpm_response attribute.
  53519. +*/
  53520. +static ssize_t lpmresp_store(struct device *_dev,
  53521. + struct device_attribute *attr,
  53522. + const char *buf, size_t count)
  53523. +{
  53524. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53525. + uint32_t val = simple_strtoul(buf, NULL, 16);
  53526. +
  53527. + if (!dwc_otg_get_param_lpm_enable(otg_dev->core_if)) {
  53528. + return 0;
  53529. + }
  53530. +
  53531. + if (!dwc_otg_is_device_mode(otg_dev->core_if)) {
  53532. + return 0;
  53533. + }
  53534. +
  53535. + dwc_otg_set_lpmresponse(otg_dev->core_if, val);
  53536. + return count;
  53537. +}
  53538. +
  53539. +DEVICE_ATTR(lpm_response, S_IRUGO | S_IWUSR, lpmresp_show, lpmresp_store);
  53540. +
  53541. +/**
  53542. +* Show the sleep_status attribute.
  53543. +*/
  53544. +static ssize_t sleepstatus_show(struct device *_dev,
  53545. + struct device_attribute *attr, char *buf)
  53546. +{
  53547. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53548. + return sprintf(buf, "Sleep Status = %d\n",
  53549. + dwc_otg_get_lpm_portsleepstatus(otg_dev->core_if));
  53550. +}
  53551. +
  53552. +/**
  53553. + * Store the sleep_status attribure.
  53554. + */
  53555. +static ssize_t sleepstatus_store(struct device *_dev,
  53556. + struct device_attribute *attr,
  53557. + const char *buf, size_t count)
  53558. +{
  53559. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53560. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  53561. +
  53562. + if (dwc_otg_get_lpm_portsleepstatus(otg_dev->core_if)) {
  53563. + if (dwc_otg_is_host_mode(core_if)) {
  53564. +
  53565. + DWC_PRINTF("Host initiated resume\n");
  53566. + dwc_otg_set_prtresume(otg_dev->core_if, 1);
  53567. + }
  53568. + }
  53569. +
  53570. + return count;
  53571. +}
  53572. +
  53573. +DEVICE_ATTR(sleep_status, S_IRUGO | S_IWUSR, sleepstatus_show,
  53574. + sleepstatus_store);
  53575. +
  53576. +#endif /* CONFIG_USB_DWC_OTG_LPM_ENABLE */
  53577. +
  53578. +/**@}*/
  53579. +
  53580. +/**
  53581. + * Create the device files
  53582. + */
  53583. +void dwc_otg_attr_create(
  53584. +#ifdef LM_INTERFACE
  53585. + struct lm_device *dev
  53586. +#elif defined(PCI_INTERFACE)
  53587. + struct pci_dev *dev
  53588. +#elif defined(PLATFORM_INTERFACE)
  53589. + struct platform_device *dev
  53590. +#endif
  53591. + )
  53592. +{
  53593. + int error;
  53594. +
  53595. + error = device_create_file(&dev->dev, &dev_attr_regoffset);
  53596. + error = device_create_file(&dev->dev, &dev_attr_regvalue);
  53597. + error = device_create_file(&dev->dev, &dev_attr_mode);
  53598. + error = device_create_file(&dev->dev, &dev_attr_hnpcapable);
  53599. + error = device_create_file(&dev->dev, &dev_attr_srpcapable);
  53600. + error = device_create_file(&dev->dev, &dev_attr_hsic_connect);
  53601. + error = device_create_file(&dev->dev, &dev_attr_inv_sel_hsic);
  53602. + error = device_create_file(&dev->dev, &dev_attr_hnp);
  53603. + error = device_create_file(&dev->dev, &dev_attr_srp);
  53604. + error = device_create_file(&dev->dev, &dev_attr_buspower);
  53605. + error = device_create_file(&dev->dev, &dev_attr_bussuspend);
  53606. + error = device_create_file(&dev->dev, &dev_attr_mode_ch_tim_en);
  53607. + error = device_create_file(&dev->dev, &dev_attr_fr_interval);
  53608. + error = device_create_file(&dev->dev, &dev_attr_busconnected);
  53609. + error = device_create_file(&dev->dev, &dev_attr_gotgctl);
  53610. + error = device_create_file(&dev->dev, &dev_attr_gusbcfg);
  53611. + error = device_create_file(&dev->dev, &dev_attr_grxfsiz);
  53612. + error = device_create_file(&dev->dev, &dev_attr_gnptxfsiz);
  53613. + error = device_create_file(&dev->dev, &dev_attr_gpvndctl);
  53614. + error = device_create_file(&dev->dev, &dev_attr_ggpio);
  53615. + error = device_create_file(&dev->dev, &dev_attr_guid);
  53616. + error = device_create_file(&dev->dev, &dev_attr_gsnpsid);
  53617. + error = device_create_file(&dev->dev, &dev_attr_devspeed);
  53618. + error = device_create_file(&dev->dev, &dev_attr_enumspeed);
  53619. + error = device_create_file(&dev->dev, &dev_attr_hptxfsiz);
  53620. + error = device_create_file(&dev->dev, &dev_attr_hprt0);
  53621. + error = device_create_file(&dev->dev, &dev_attr_remote_wakeup);
  53622. + error = device_create_file(&dev->dev, &dev_attr_rem_wakeup_pwrdn);
  53623. + error = device_create_file(&dev->dev, &dev_attr_disconnect_us);
  53624. + error = device_create_file(&dev->dev, &dev_attr_regdump);
  53625. + error = device_create_file(&dev->dev, &dev_attr_spramdump);
  53626. + error = device_create_file(&dev->dev, &dev_attr_hcddump);
  53627. + error = device_create_file(&dev->dev, &dev_attr_hcd_frrem);
  53628. + error = device_create_file(&dev->dev, &dev_attr_rd_reg_test);
  53629. + error = device_create_file(&dev->dev, &dev_attr_wr_reg_test);
  53630. +#ifdef CONFIG_USB_DWC_OTG_LPM
  53631. + error = device_create_file(&dev->dev, &dev_attr_lpm_response);
  53632. + error = device_create_file(&dev->dev, &dev_attr_sleep_status);
  53633. +#endif
  53634. +}
  53635. +
  53636. +/**
  53637. + * Remove the device files
  53638. + */
  53639. +void dwc_otg_attr_remove(
  53640. +#ifdef LM_INTERFACE
  53641. + struct lm_device *dev
  53642. +#elif defined(PCI_INTERFACE)
  53643. + struct pci_dev *dev
  53644. +#elif defined(PLATFORM_INTERFACE)
  53645. + struct platform_device *dev
  53646. +#endif
  53647. + )
  53648. +{
  53649. + device_remove_file(&dev->dev, &dev_attr_regoffset);
  53650. + device_remove_file(&dev->dev, &dev_attr_regvalue);
  53651. + device_remove_file(&dev->dev, &dev_attr_mode);
  53652. + device_remove_file(&dev->dev, &dev_attr_hnpcapable);
  53653. + device_remove_file(&dev->dev, &dev_attr_srpcapable);
  53654. + device_remove_file(&dev->dev, &dev_attr_hsic_connect);
  53655. + device_remove_file(&dev->dev, &dev_attr_inv_sel_hsic);
  53656. + device_remove_file(&dev->dev, &dev_attr_hnp);
  53657. + device_remove_file(&dev->dev, &dev_attr_srp);
  53658. + device_remove_file(&dev->dev, &dev_attr_buspower);
  53659. + device_remove_file(&dev->dev, &dev_attr_bussuspend);
  53660. + device_remove_file(&dev->dev, &dev_attr_mode_ch_tim_en);
  53661. + device_remove_file(&dev->dev, &dev_attr_fr_interval);
  53662. + device_remove_file(&dev->dev, &dev_attr_busconnected);
  53663. + device_remove_file(&dev->dev, &dev_attr_gotgctl);
  53664. + device_remove_file(&dev->dev, &dev_attr_gusbcfg);
  53665. + device_remove_file(&dev->dev, &dev_attr_grxfsiz);
  53666. + device_remove_file(&dev->dev, &dev_attr_gnptxfsiz);
  53667. + device_remove_file(&dev->dev, &dev_attr_gpvndctl);
  53668. + device_remove_file(&dev->dev, &dev_attr_ggpio);
  53669. + device_remove_file(&dev->dev, &dev_attr_guid);
  53670. + device_remove_file(&dev->dev, &dev_attr_gsnpsid);
  53671. + device_remove_file(&dev->dev, &dev_attr_devspeed);
  53672. + device_remove_file(&dev->dev, &dev_attr_enumspeed);
  53673. + device_remove_file(&dev->dev, &dev_attr_hptxfsiz);
  53674. + device_remove_file(&dev->dev, &dev_attr_hprt0);
  53675. + device_remove_file(&dev->dev, &dev_attr_remote_wakeup);
  53676. + device_remove_file(&dev->dev, &dev_attr_rem_wakeup_pwrdn);
  53677. + device_remove_file(&dev->dev, &dev_attr_disconnect_us);
  53678. + device_remove_file(&dev->dev, &dev_attr_regdump);
  53679. + device_remove_file(&dev->dev, &dev_attr_spramdump);
  53680. + device_remove_file(&dev->dev, &dev_attr_hcddump);
  53681. + device_remove_file(&dev->dev, &dev_attr_hcd_frrem);
  53682. + device_remove_file(&dev->dev, &dev_attr_rd_reg_test);
  53683. + device_remove_file(&dev->dev, &dev_attr_wr_reg_test);
  53684. +#ifdef CONFIG_USB_DWC_OTG_LPM
  53685. + device_remove_file(&dev->dev, &dev_attr_lpm_response);
  53686. + device_remove_file(&dev->dev, &dev_attr_sleep_status);
  53687. +#endif
  53688. +}
  53689. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_attr.h linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_attr.h
  53690. --- linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_attr.h 1970-01-01 01:00:00.000000000 +0100
  53691. +++ linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_attr.h 2014-08-06 16:50:14.785964600 +0200
  53692. @@ -0,0 +1,89 @@
  53693. +/* ==========================================================================
  53694. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_attr.h $
  53695. + * $Revision: #13 $
  53696. + * $Date: 2010/06/21 $
  53697. + * $Change: 1532021 $
  53698. + *
  53699. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  53700. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  53701. + * otherwise expressly agreed to in writing between Synopsys and you.
  53702. + *
  53703. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  53704. + * any End User Software License Agreement or Agreement for Licensed Product
  53705. + * with Synopsys or any supplement thereto. You are permitted to use and
  53706. + * redistribute this Software in source and binary forms, with or without
  53707. + * modification, provided that redistributions of source code must retain this
  53708. + * notice. You may not view, use, disclose, copy or distribute this file or
  53709. + * any information contained herein except pursuant to this license grant from
  53710. + * Synopsys. If you do not agree with this notice, including the disclaimer
  53711. + * below, then you are not authorized to use the Software.
  53712. + *
  53713. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  53714. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  53715. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  53716. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  53717. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  53718. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  53719. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  53720. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  53721. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  53722. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  53723. + * DAMAGE.
  53724. + * ========================================================================== */
  53725. +
  53726. +#if !defined(__DWC_OTG_ATTR_H__)
  53727. +#define __DWC_OTG_ATTR_H__
  53728. +
  53729. +/** @file
  53730. + * This file contains the interface to the Linux device attributes.
  53731. + */
  53732. +extern struct device_attribute dev_attr_regoffset;
  53733. +extern struct device_attribute dev_attr_regvalue;
  53734. +
  53735. +extern struct device_attribute dev_attr_mode;
  53736. +extern struct device_attribute dev_attr_hnpcapable;
  53737. +extern struct device_attribute dev_attr_srpcapable;
  53738. +extern struct device_attribute dev_attr_hnp;
  53739. +extern struct device_attribute dev_attr_srp;
  53740. +extern struct device_attribute dev_attr_buspower;
  53741. +extern struct device_attribute dev_attr_bussuspend;
  53742. +extern struct device_attribute dev_attr_mode_ch_tim_en;
  53743. +extern struct device_attribute dev_attr_fr_interval;
  53744. +extern struct device_attribute dev_attr_busconnected;
  53745. +extern struct device_attribute dev_attr_gotgctl;
  53746. +extern struct device_attribute dev_attr_gusbcfg;
  53747. +extern struct device_attribute dev_attr_grxfsiz;
  53748. +extern struct device_attribute dev_attr_gnptxfsiz;
  53749. +extern struct device_attribute dev_attr_gpvndctl;
  53750. +extern struct device_attribute dev_attr_ggpio;
  53751. +extern struct device_attribute dev_attr_guid;
  53752. +extern struct device_attribute dev_attr_gsnpsid;
  53753. +extern struct device_attribute dev_attr_devspeed;
  53754. +extern struct device_attribute dev_attr_enumspeed;
  53755. +extern struct device_attribute dev_attr_hptxfsiz;
  53756. +extern struct device_attribute dev_attr_hprt0;
  53757. +#ifdef CONFIG_USB_DWC_OTG_LPM
  53758. +extern struct device_attribute dev_attr_lpm_response;
  53759. +extern struct device_attribute devi_attr_sleep_status;
  53760. +#endif
  53761. +
  53762. +void dwc_otg_attr_create(
  53763. +#ifdef LM_INTERFACE
  53764. + struct lm_device *dev
  53765. +#elif defined(PCI_INTERFACE)
  53766. + struct pci_dev *dev
  53767. +#elif defined(PLATFORM_INTERFACE)
  53768. + struct platform_device *dev
  53769. +#endif
  53770. + );
  53771. +
  53772. +void dwc_otg_attr_remove(
  53773. +#ifdef LM_INTERFACE
  53774. + struct lm_device *dev
  53775. +#elif defined(PCI_INTERFACE)
  53776. + struct pci_dev *dev
  53777. +#elif defined(PLATFORM_INTERFACE)
  53778. + struct platform_device *dev
  53779. +#endif
  53780. + );
  53781. +#endif
  53782. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_cfi.c linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_cfi.c
  53783. --- linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_cfi.c 1970-01-01 01:00:00.000000000 +0100
  53784. +++ linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_cfi.c 2014-08-06 16:50:14.793964664 +0200
  53785. @@ -0,0 +1,1876 @@
  53786. +/* ==========================================================================
  53787. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  53788. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  53789. + * otherwise expressly agreed to in writing between Synopsys and you.
  53790. + *
  53791. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  53792. + * any End User Software License Agreement or Agreement for Licensed Product
  53793. + * with Synopsys or any supplement thereto. You are permitted to use and
  53794. + * redistribute this Software in source and binary forms, with or without
  53795. + * modification, provided that redistributions of source code must retain this
  53796. + * notice. You may not view, use, disclose, copy or distribute this file or
  53797. + * any information contained herein except pursuant to this license grant from
  53798. + * Synopsys. If you do not agree with this notice, including the disclaimer
  53799. + * below, then you are not authorized to use the Software.
  53800. + *
  53801. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  53802. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  53803. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  53804. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  53805. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  53806. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  53807. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  53808. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  53809. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  53810. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  53811. + * DAMAGE.
  53812. + * ========================================================================== */
  53813. +
  53814. +/** @file
  53815. + *
  53816. + * This file contains the most of the CFI(Core Feature Interface)
  53817. + * implementation for the OTG.
  53818. + */
  53819. +
  53820. +#ifdef DWC_UTE_CFI
  53821. +
  53822. +#include "dwc_otg_pcd.h"
  53823. +#include "dwc_otg_cfi.h"
  53824. +
  53825. +/** This definition should actually migrate to the Portability Library */
  53826. +#define DWC_CONSTANT_CPU_TO_LE16(x) (x)
  53827. +
  53828. +extern dwc_otg_pcd_ep_t *get_ep_by_addr(dwc_otg_pcd_t * pcd, u16 wIndex);
  53829. +
  53830. +static int cfi_core_features_buf(uint8_t * buf, uint16_t buflen);
  53831. +static int cfi_get_feature_value(uint8_t * buf, uint16_t buflen,
  53832. + struct dwc_otg_pcd *pcd,
  53833. + struct cfi_usb_ctrlrequest *ctrl_req);
  53834. +static int cfi_set_feature_value(struct dwc_otg_pcd *pcd);
  53835. +static int cfi_ep_get_sg_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  53836. + struct cfi_usb_ctrlrequest *req);
  53837. +static int cfi_ep_get_concat_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  53838. + struct cfi_usb_ctrlrequest *req);
  53839. +static int cfi_ep_get_align_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  53840. + struct cfi_usb_ctrlrequest *req);
  53841. +static int cfi_preproc_reset(struct dwc_otg_pcd *pcd,
  53842. + struct cfi_usb_ctrlrequest *req);
  53843. +static void cfi_free_ep_bs_dyn_data(cfi_ep_t * cfiep);
  53844. +
  53845. +static uint16_t get_dfifo_size(dwc_otg_core_if_t * core_if);
  53846. +static int32_t get_rxfifo_size(dwc_otg_core_if_t * core_if, uint16_t wValue);
  53847. +static int32_t get_txfifo_size(struct dwc_otg_pcd *pcd, uint16_t wValue);
  53848. +
  53849. +static uint8_t resize_fifos(dwc_otg_core_if_t * core_if);
  53850. +
  53851. +/** This is the header of the all features descriptor */
  53852. +static cfi_all_features_header_t all_props_desc_header = {
  53853. + .wVersion = DWC_CONSTANT_CPU_TO_LE16(0x100),
  53854. + .wCoreID = DWC_CONSTANT_CPU_TO_LE16(CFI_CORE_ID_OTG),
  53855. + .wNumFeatures = DWC_CONSTANT_CPU_TO_LE16(9),
  53856. +};
  53857. +
  53858. +/** This is an array of statically allocated feature descriptors */
  53859. +static cfi_feature_desc_header_t prop_descs[] = {
  53860. +
  53861. + /* FT_ID_DMA_MODE */
  53862. + {
  53863. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_MODE),
  53864. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  53865. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(1),
  53866. + },
  53867. +
  53868. + /* FT_ID_DMA_BUFFER_SETUP */
  53869. + {
  53870. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_BUFFER_SETUP),
  53871. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  53872. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  53873. + },
  53874. +
  53875. + /* FT_ID_DMA_BUFF_ALIGN */
  53876. + {
  53877. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_BUFF_ALIGN),
  53878. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  53879. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  53880. + },
  53881. +
  53882. + /* FT_ID_DMA_CONCAT_SETUP */
  53883. + {
  53884. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_CONCAT_SETUP),
  53885. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  53886. + //.wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  53887. + },
  53888. +
  53889. + /* FT_ID_DMA_CIRCULAR */
  53890. + {
  53891. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_CIRCULAR),
  53892. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  53893. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  53894. + },
  53895. +
  53896. + /* FT_ID_THRESHOLD_SETUP */
  53897. + {
  53898. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_THRESHOLD_SETUP),
  53899. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  53900. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  53901. + },
  53902. +
  53903. + /* FT_ID_DFIFO_DEPTH */
  53904. + {
  53905. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DFIFO_DEPTH),
  53906. + .bmAttributes = CFI_FEATURE_ATTR_RO,
  53907. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  53908. + },
  53909. +
  53910. + /* FT_ID_TX_FIFO_DEPTH */
  53911. + {
  53912. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_TX_FIFO_DEPTH),
  53913. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  53914. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  53915. + },
  53916. +
  53917. + /* FT_ID_RX_FIFO_DEPTH */
  53918. + {
  53919. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_RX_FIFO_DEPTH),
  53920. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  53921. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  53922. + }
  53923. +};
  53924. +
  53925. +/** The table of feature names */
  53926. +cfi_string_t prop_name_table[] = {
  53927. + {FT_ID_DMA_MODE, "dma_mode"},
  53928. + {FT_ID_DMA_BUFFER_SETUP, "buffer_setup"},
  53929. + {FT_ID_DMA_BUFF_ALIGN, "buffer_align"},
  53930. + {FT_ID_DMA_CONCAT_SETUP, "concat_setup"},
  53931. + {FT_ID_DMA_CIRCULAR, "buffer_circular"},
  53932. + {FT_ID_THRESHOLD_SETUP, "threshold_setup"},
  53933. + {FT_ID_DFIFO_DEPTH, "dfifo_depth"},
  53934. + {FT_ID_TX_FIFO_DEPTH, "txfifo_depth"},
  53935. + {FT_ID_RX_FIFO_DEPTH, "rxfifo_depth"},
  53936. + {}
  53937. +};
  53938. +
  53939. +/************************************************************************/
  53940. +
  53941. +/**
  53942. + * Returns the name of the feature by its ID
  53943. + * or NULL if no featute ID matches.
  53944. + *
  53945. + */
  53946. +const uint8_t *get_prop_name(uint16_t prop_id, int *len)
  53947. +{
  53948. + cfi_string_t *pstr;
  53949. + *len = 0;
  53950. +
  53951. + for (pstr = prop_name_table; pstr && pstr->s; pstr++) {
  53952. + if (pstr->id == prop_id) {
  53953. + *len = DWC_STRLEN(pstr->s);
  53954. + return pstr->s;
  53955. + }
  53956. + }
  53957. + return NULL;
  53958. +}
  53959. +
  53960. +/**
  53961. + * This function handles all CFI specific control requests.
  53962. + *
  53963. + * Return a negative value to stall the DCE.
  53964. + */
  53965. +int cfi_setup(struct dwc_otg_pcd *pcd, struct cfi_usb_ctrlrequest *ctrl)
  53966. +{
  53967. + int retval = 0;
  53968. + dwc_otg_pcd_ep_t *ep = NULL;
  53969. + cfiobject_t *cfi = pcd->cfi;
  53970. + struct dwc_otg_core_if *coreif = GET_CORE_IF(pcd);
  53971. + uint16_t wLen = DWC_LE16_TO_CPU(&ctrl->wLength);
  53972. + uint16_t wValue = DWC_LE16_TO_CPU(&ctrl->wValue);
  53973. + uint16_t wIndex = DWC_LE16_TO_CPU(&ctrl->wIndex);
  53974. + uint32_t regaddr = 0;
  53975. + uint32_t regval = 0;
  53976. +
  53977. + /* Save this Control Request in the CFI object.
  53978. + * The data field will be assigned in the data stage completion CB function.
  53979. + */
  53980. + cfi->ctrl_req = *ctrl;
  53981. + cfi->ctrl_req.data = NULL;
  53982. +
  53983. + cfi->need_gadget_att = 0;
  53984. + cfi->need_status_in_complete = 0;
  53985. +
  53986. + switch (ctrl->bRequest) {
  53987. + case VEN_CORE_GET_FEATURES:
  53988. + retval = cfi_core_features_buf(cfi->buf_in.buf, CFI_IN_BUF_LEN);
  53989. + if (retval >= 0) {
  53990. + //dump_msg(cfi->buf_in.buf, retval);
  53991. + ep = &pcd->ep0;
  53992. +
  53993. + retval = min((uint16_t) retval, wLen);
  53994. + /* Transfer this buffer to the host through the EP0-IN EP */
  53995. + ep->dwc_ep.dma_addr = cfi->buf_in.addr;
  53996. + ep->dwc_ep.start_xfer_buff = cfi->buf_in.buf;
  53997. + ep->dwc_ep.xfer_buff = cfi->buf_in.buf;
  53998. + ep->dwc_ep.xfer_len = retval;
  53999. + ep->dwc_ep.xfer_count = 0;
  54000. + ep->dwc_ep.sent_zlp = 0;
  54001. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  54002. +
  54003. + pcd->ep0_pending = 1;
  54004. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  54005. + }
  54006. + retval = 0;
  54007. + break;
  54008. +
  54009. + case VEN_CORE_GET_FEATURE:
  54010. + CFI_INFO("VEN_CORE_GET_FEATURE\n");
  54011. + retval = cfi_get_feature_value(cfi->buf_in.buf, CFI_IN_BUF_LEN,
  54012. + pcd, ctrl);
  54013. + if (retval >= 0) {
  54014. + ep = &pcd->ep0;
  54015. +
  54016. + retval = min((uint16_t) retval, wLen);
  54017. + /* Transfer this buffer to the host through the EP0-IN EP */
  54018. + ep->dwc_ep.dma_addr = cfi->buf_in.addr;
  54019. + ep->dwc_ep.start_xfer_buff = cfi->buf_in.buf;
  54020. + ep->dwc_ep.xfer_buff = cfi->buf_in.buf;
  54021. + ep->dwc_ep.xfer_len = retval;
  54022. + ep->dwc_ep.xfer_count = 0;
  54023. + ep->dwc_ep.sent_zlp = 0;
  54024. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  54025. +
  54026. + pcd->ep0_pending = 1;
  54027. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  54028. + }
  54029. + CFI_INFO("VEN_CORE_GET_FEATURE=%d\n", retval);
  54030. + dump_msg(cfi->buf_in.buf, retval);
  54031. + break;
  54032. +
  54033. + case VEN_CORE_SET_FEATURE:
  54034. + CFI_INFO("VEN_CORE_SET_FEATURE\n");
  54035. + /* Set up an XFER to get the data stage of the control request,
  54036. + * which is the new value of the feature to be modified.
  54037. + */
  54038. + ep = &pcd->ep0;
  54039. + ep->dwc_ep.is_in = 0;
  54040. + ep->dwc_ep.dma_addr = cfi->buf_out.addr;
  54041. + ep->dwc_ep.start_xfer_buff = cfi->buf_out.buf;
  54042. + ep->dwc_ep.xfer_buff = cfi->buf_out.buf;
  54043. + ep->dwc_ep.xfer_len = wLen;
  54044. + ep->dwc_ep.xfer_count = 0;
  54045. + ep->dwc_ep.sent_zlp = 0;
  54046. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  54047. +
  54048. + pcd->ep0_pending = 1;
  54049. + /* Read the control write's data stage */
  54050. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  54051. + retval = 0;
  54052. + break;
  54053. +
  54054. + case VEN_CORE_RESET_FEATURES:
  54055. + CFI_INFO("VEN_CORE_RESET_FEATURES\n");
  54056. + cfi->need_gadget_att = 1;
  54057. + cfi->need_status_in_complete = 1;
  54058. + retval = cfi_preproc_reset(pcd, ctrl);
  54059. + CFI_INFO("VEN_CORE_RESET_FEATURES = (%d)\n", retval);
  54060. + break;
  54061. +
  54062. + case VEN_CORE_ACTIVATE_FEATURES:
  54063. + CFI_INFO("VEN_CORE_ACTIVATE_FEATURES\n");
  54064. + break;
  54065. +
  54066. + case VEN_CORE_READ_REGISTER:
  54067. + CFI_INFO("VEN_CORE_READ_REGISTER\n");
  54068. + /* wValue optionally contains the HI WORD of the register offset and
  54069. + * wIndex contains the LOW WORD of the register offset
  54070. + */
  54071. + if (wValue == 0) {
  54072. + /* @TODO - MAS - fix the access to the base field */
  54073. + regaddr = 0;
  54074. + //regaddr = (uint32_t) pcd->otg_dev->os_dep.base;
  54075. + //GET_CORE_IF(pcd)->co
  54076. + regaddr |= wIndex;
  54077. + } else {
  54078. + regaddr = (wValue << 16) | wIndex;
  54079. + }
  54080. +
  54081. + /* Read a 32-bit value of the memory at the regaddr */
  54082. + regval = DWC_READ_REG32((uint32_t *) regaddr);
  54083. +
  54084. + ep = &pcd->ep0;
  54085. + dwc_memcpy(cfi->buf_in.buf, &regval, sizeof(uint32_t));
  54086. + ep->dwc_ep.is_in = 1;
  54087. + ep->dwc_ep.dma_addr = cfi->buf_in.addr;
  54088. + ep->dwc_ep.start_xfer_buff = cfi->buf_in.buf;
  54089. + ep->dwc_ep.xfer_buff = cfi->buf_in.buf;
  54090. + ep->dwc_ep.xfer_len = wLen;
  54091. + ep->dwc_ep.xfer_count = 0;
  54092. + ep->dwc_ep.sent_zlp = 0;
  54093. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  54094. +
  54095. + pcd->ep0_pending = 1;
  54096. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  54097. + cfi->need_gadget_att = 0;
  54098. + retval = 0;
  54099. + break;
  54100. +
  54101. + case VEN_CORE_WRITE_REGISTER:
  54102. + CFI_INFO("VEN_CORE_WRITE_REGISTER\n");
  54103. + /* Set up an XFER to get the data stage of the control request,
  54104. + * which is the new value of the register to be modified.
  54105. + */
  54106. + ep = &pcd->ep0;
  54107. + ep->dwc_ep.is_in = 0;
  54108. + ep->dwc_ep.dma_addr = cfi->buf_out.addr;
  54109. + ep->dwc_ep.start_xfer_buff = cfi->buf_out.buf;
  54110. + ep->dwc_ep.xfer_buff = cfi->buf_out.buf;
  54111. + ep->dwc_ep.xfer_len = wLen;
  54112. + ep->dwc_ep.xfer_count = 0;
  54113. + ep->dwc_ep.sent_zlp = 0;
  54114. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  54115. +
  54116. + pcd->ep0_pending = 1;
  54117. + /* Read the control write's data stage */
  54118. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  54119. + retval = 0;
  54120. + break;
  54121. +
  54122. + default:
  54123. + retval = -DWC_E_NOT_SUPPORTED;
  54124. + break;
  54125. + }
  54126. +
  54127. + return retval;
  54128. +}
  54129. +
  54130. +/**
  54131. + * This function prepares the core features descriptors and copies its
  54132. + * raw representation into the buffer <buf>.
  54133. + *
  54134. + * The buffer structure is as follows:
  54135. + * all_features_header (8 bytes)
  54136. + * features_#1 (8 bytes + feature name string length)
  54137. + * features_#2 (8 bytes + feature name string length)
  54138. + * .....
  54139. + * features_#n - where n=the total count of feature descriptors
  54140. + */
  54141. +static int cfi_core_features_buf(uint8_t * buf, uint16_t buflen)
  54142. +{
  54143. + cfi_feature_desc_header_t *prop_hdr = prop_descs;
  54144. + cfi_feature_desc_header_t *prop;
  54145. + cfi_all_features_header_t *all_props_hdr = &all_props_desc_header;
  54146. + cfi_all_features_header_t *tmp;
  54147. + uint8_t *tmpbuf = buf;
  54148. + const uint8_t *pname = NULL;
  54149. + int i, j, namelen = 0, totlen;
  54150. +
  54151. + /* Prepare and copy the core features into the buffer */
  54152. + CFI_INFO("%s:\n", __func__);
  54153. +
  54154. + tmp = (cfi_all_features_header_t *) tmpbuf;
  54155. + *tmp = *all_props_hdr;
  54156. + tmpbuf += CFI_ALL_FEATURES_HDR_LEN;
  54157. +
  54158. + j = sizeof(prop_descs) / sizeof(cfi_all_features_header_t);
  54159. + for (i = 0; i < j; i++, prop_hdr++) {
  54160. + pname = get_prop_name(prop_hdr->wFeatureID, &namelen);
  54161. + prop = (cfi_feature_desc_header_t *) tmpbuf;
  54162. + *prop = *prop_hdr;
  54163. +
  54164. + prop->bNameLen = namelen;
  54165. + prop->wLength =
  54166. + DWC_CONSTANT_CPU_TO_LE16(CFI_FEATURE_DESC_HDR_LEN +
  54167. + namelen);
  54168. +
  54169. + tmpbuf += CFI_FEATURE_DESC_HDR_LEN;
  54170. + dwc_memcpy(tmpbuf, pname, namelen);
  54171. + tmpbuf += namelen;
  54172. + }
  54173. +
  54174. + totlen = tmpbuf - buf;
  54175. +
  54176. + if (totlen > 0) {
  54177. + tmp = (cfi_all_features_header_t *) buf;
  54178. + tmp->wTotalLen = DWC_CONSTANT_CPU_TO_LE16(totlen);
  54179. + }
  54180. +
  54181. + return totlen;
  54182. +}
  54183. +
  54184. +/**
  54185. + * This function releases all the dynamic memory in the CFI object.
  54186. + */
  54187. +static void cfi_release(cfiobject_t * cfiobj)
  54188. +{
  54189. + cfi_ep_t *cfiep;
  54190. + dwc_list_link_t *tmp;
  54191. +
  54192. + CFI_INFO("%s\n", __func__);
  54193. +
  54194. + if (cfiobj->buf_in.buf) {
  54195. + DWC_DMA_FREE(CFI_IN_BUF_LEN, cfiobj->buf_in.buf,
  54196. + cfiobj->buf_in.addr);
  54197. + cfiobj->buf_in.buf = NULL;
  54198. + }
  54199. +
  54200. + if (cfiobj->buf_out.buf) {
  54201. + DWC_DMA_FREE(CFI_OUT_BUF_LEN, cfiobj->buf_out.buf,
  54202. + cfiobj->buf_out.addr);
  54203. + cfiobj->buf_out.buf = NULL;
  54204. + }
  54205. +
  54206. + /* Free the Buffer Setup values for each EP */
  54207. + //list_for_each_entry(cfiep, &cfiobj->active_eps, lh) {
  54208. + DWC_LIST_FOREACH(tmp, &cfiobj->active_eps) {
  54209. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  54210. + cfi_free_ep_bs_dyn_data(cfiep);
  54211. + }
  54212. +}
  54213. +
  54214. +/**
  54215. + * This function frees the dynamically allocated EP buffer setup data.
  54216. + */
  54217. +static void cfi_free_ep_bs_dyn_data(cfi_ep_t * cfiep)
  54218. +{
  54219. + if (cfiep->bm_sg) {
  54220. + DWC_FREE(cfiep->bm_sg);
  54221. + cfiep->bm_sg = NULL;
  54222. + }
  54223. +
  54224. + if (cfiep->bm_align) {
  54225. + DWC_FREE(cfiep->bm_align);
  54226. + cfiep->bm_align = NULL;
  54227. + }
  54228. +
  54229. + if (cfiep->bm_concat) {
  54230. + if (NULL != cfiep->bm_concat->wTxBytes) {
  54231. + DWC_FREE(cfiep->bm_concat->wTxBytes);
  54232. + cfiep->bm_concat->wTxBytes = NULL;
  54233. + }
  54234. + DWC_FREE(cfiep->bm_concat);
  54235. + cfiep->bm_concat = NULL;
  54236. + }
  54237. +}
  54238. +
  54239. +/**
  54240. + * This function initializes the default values of the features
  54241. + * for a specific endpoint and should be called only once when
  54242. + * the EP is enabled first time.
  54243. + */
  54244. +static int cfi_ep_init_defaults(struct dwc_otg_pcd *pcd, cfi_ep_t * cfiep)
  54245. +{
  54246. + int retval = 0;
  54247. +
  54248. + cfiep->bm_sg = DWC_ALLOC(sizeof(ddma_sg_buffer_setup_t));
  54249. + if (NULL == cfiep->bm_sg) {
  54250. + CFI_INFO("Failed to allocate memory for SG feature value\n");
  54251. + return -DWC_E_NO_MEMORY;
  54252. + }
  54253. + dwc_memset(cfiep->bm_sg, 0, sizeof(ddma_sg_buffer_setup_t));
  54254. +
  54255. + /* For the Concatenation feature's default value we do not allocate
  54256. + * memory for the wTxBytes field - it will be done in the set_feature_value
  54257. + * request handler.
  54258. + */
  54259. + cfiep->bm_concat = DWC_ALLOC(sizeof(ddma_concat_buffer_setup_t));
  54260. + if (NULL == cfiep->bm_concat) {
  54261. + CFI_INFO
  54262. + ("Failed to allocate memory for CONCATENATION feature value\n");
  54263. + DWC_FREE(cfiep->bm_sg);
  54264. + return -DWC_E_NO_MEMORY;
  54265. + }
  54266. + dwc_memset(cfiep->bm_concat, 0, sizeof(ddma_concat_buffer_setup_t));
  54267. +
  54268. + cfiep->bm_align = DWC_ALLOC(sizeof(ddma_align_buffer_setup_t));
  54269. + if (NULL == cfiep->bm_align) {
  54270. + CFI_INFO
  54271. + ("Failed to allocate memory for Alignment feature value\n");
  54272. + DWC_FREE(cfiep->bm_sg);
  54273. + DWC_FREE(cfiep->bm_concat);
  54274. + return -DWC_E_NO_MEMORY;
  54275. + }
  54276. + dwc_memset(cfiep->bm_align, 0, sizeof(ddma_align_buffer_setup_t));
  54277. +
  54278. + return retval;
  54279. +}
  54280. +
  54281. +/**
  54282. + * The callback function that notifies the CFI on the activation of
  54283. + * an endpoint in the PCD. The following steps are done in this function:
  54284. + *
  54285. + * Create a dynamically allocated cfi_ep_t object (a CFI wrapper to the PCD's
  54286. + * active endpoint)
  54287. + * Create MAX_DMA_DESCS_PER_EP count DMA Descriptors for the EP
  54288. + * Set the Buffer Mode to standard
  54289. + * Initialize the default values for all EP modes (SG, Circular, Concat, Align)
  54290. + * Add the cfi_ep_t object to the list of active endpoints in the CFI object
  54291. + */
  54292. +static int cfi_ep_enable(struct cfiobject *cfi, struct dwc_otg_pcd *pcd,
  54293. + struct dwc_otg_pcd_ep *ep)
  54294. +{
  54295. + cfi_ep_t *cfiep;
  54296. + int retval = -DWC_E_NOT_SUPPORTED;
  54297. +
  54298. + CFI_INFO("%s: epname=%s; epnum=0x%02x\n", __func__,
  54299. + "EP_" /*ep->ep.name */ , ep->desc->bEndpointAddress);
  54300. + /* MAS - Check whether this endpoint already is in the list */
  54301. + cfiep = get_cfi_ep_by_pcd_ep(cfi, ep);
  54302. +
  54303. + if (NULL == cfiep) {
  54304. + /* Allocate a cfi_ep_t object */
  54305. + cfiep = DWC_ALLOC(sizeof(cfi_ep_t));
  54306. + if (NULL == cfiep) {
  54307. + CFI_INFO
  54308. + ("Unable to allocate memory for <cfiep> in function %s\n",
  54309. + __func__);
  54310. + return -DWC_E_NO_MEMORY;
  54311. + }
  54312. + dwc_memset(cfiep, 0, sizeof(cfi_ep_t));
  54313. +
  54314. + /* Save the dwc_otg_pcd_ep pointer in the cfiep object */
  54315. + cfiep->ep = ep;
  54316. +
  54317. + /* Allocate the DMA Descriptors chain of MAX_DMA_DESCS_PER_EP count */
  54318. + ep->dwc_ep.descs =
  54319. + DWC_DMA_ALLOC(MAX_DMA_DESCS_PER_EP *
  54320. + sizeof(dwc_otg_dma_desc_t),
  54321. + &ep->dwc_ep.descs_dma_addr);
  54322. +
  54323. + if (NULL == ep->dwc_ep.descs) {
  54324. + DWC_FREE(cfiep);
  54325. + return -DWC_E_NO_MEMORY;
  54326. + }
  54327. +
  54328. + DWC_LIST_INIT(&cfiep->lh);
  54329. +
  54330. + /* Set the buffer mode to BM_STANDARD. It will be modified
  54331. + * when building descriptors for a specific buffer mode */
  54332. + ep->dwc_ep.buff_mode = BM_STANDARD;
  54333. +
  54334. + /* Create and initialize the default values for this EP's Buffer modes */
  54335. + if ((retval = cfi_ep_init_defaults(pcd, cfiep)) < 0)
  54336. + return retval;
  54337. +
  54338. + /* Add the cfi_ep_t object to the CFI object's list of active endpoints */
  54339. + DWC_LIST_INSERT_TAIL(&cfi->active_eps, &cfiep->lh);
  54340. + retval = 0;
  54341. + } else { /* The sought EP already is in the list */
  54342. + CFI_INFO("%s: The sought EP already is in the list\n",
  54343. + __func__);
  54344. + }
  54345. +
  54346. + return retval;
  54347. +}
  54348. +
  54349. +/**
  54350. + * This function is called when the data stage of a 3-stage Control Write request
  54351. + * is complete.
  54352. + *
  54353. + */
  54354. +static int cfi_ctrl_write_complete(struct cfiobject *cfi,
  54355. + struct dwc_otg_pcd *pcd)
  54356. +{
  54357. + uint32_t addr, reg_value;
  54358. + uint16_t wIndex, wValue;
  54359. + uint8_t bRequest;
  54360. + uint8_t *buf = cfi->buf_out.buf;
  54361. + //struct usb_ctrlrequest *ctrl_req = &cfi->ctrl_req_saved;
  54362. + struct cfi_usb_ctrlrequest *ctrl_req = &cfi->ctrl_req;
  54363. + int retval = -DWC_E_NOT_SUPPORTED;
  54364. +
  54365. + CFI_INFO("%s\n", __func__);
  54366. +
  54367. + bRequest = ctrl_req->bRequest;
  54368. + wIndex = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wIndex);
  54369. + wValue = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wValue);
  54370. +
  54371. + /*
  54372. + * Save the pointer to the data stage in the ctrl_req's <data> field.
  54373. + * The request should be already saved in the command stage by now.
  54374. + */
  54375. + ctrl_req->data = cfi->buf_out.buf;
  54376. + cfi->need_status_in_complete = 0;
  54377. + cfi->need_gadget_att = 0;
  54378. +
  54379. + switch (bRequest) {
  54380. + case VEN_CORE_WRITE_REGISTER:
  54381. + /* The buffer contains raw data of the new value for the register */
  54382. + reg_value = *((uint32_t *) buf);
  54383. + if (wValue == 0) {
  54384. + addr = 0;
  54385. + //addr = (uint32_t) pcd->otg_dev->os_dep.base;
  54386. + addr += wIndex;
  54387. + } else {
  54388. + addr = (wValue << 16) | wIndex;
  54389. + }
  54390. +
  54391. + //writel(reg_value, addr);
  54392. +
  54393. + retval = 0;
  54394. + cfi->need_status_in_complete = 1;
  54395. + break;
  54396. +
  54397. + case VEN_CORE_SET_FEATURE:
  54398. + /* The buffer contains raw data of the new value of the feature */
  54399. + retval = cfi_set_feature_value(pcd);
  54400. + if (retval < 0)
  54401. + return retval;
  54402. +
  54403. + cfi->need_status_in_complete = 1;
  54404. + break;
  54405. +
  54406. + default:
  54407. + break;
  54408. + }
  54409. +
  54410. + return retval;
  54411. +}
  54412. +
  54413. +/**
  54414. + * This function builds the DMA descriptors for the SG buffer mode.
  54415. + */
  54416. +static void cfi_build_sg_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  54417. + dwc_otg_pcd_request_t * req)
  54418. +{
  54419. + struct dwc_otg_pcd_ep *ep = cfiep->ep;
  54420. + ddma_sg_buffer_setup_t *sgval = cfiep->bm_sg;
  54421. + struct dwc_otg_dma_desc *desc = cfiep->ep->dwc_ep.descs;
  54422. + struct dwc_otg_dma_desc *desc_last = cfiep->ep->dwc_ep.descs;
  54423. + dma_addr_t buff_addr = req->dma;
  54424. + int i;
  54425. + uint32_t txsize, off;
  54426. +
  54427. + txsize = sgval->wSize;
  54428. + off = sgval->bOffset;
  54429. +
  54430. +// CFI_INFO("%s: %s TXSIZE=0x%08x; OFFSET=0x%08x\n",
  54431. +// __func__, cfiep->ep->ep.name, txsize, off);
  54432. +
  54433. + for (i = 0; i < sgval->bCount; i++) {
  54434. + desc->status.b.bs = BS_HOST_BUSY;
  54435. + desc->buf = buff_addr;
  54436. + desc->status.b.l = 0;
  54437. + desc->status.b.ioc = 0;
  54438. + desc->status.b.sp = 0;
  54439. + desc->status.b.bytes = txsize;
  54440. + desc->status.b.bs = BS_HOST_READY;
  54441. +
  54442. + /* Set the next address of the buffer */
  54443. + buff_addr += txsize + off;
  54444. + desc_last = desc;
  54445. + desc++;
  54446. + }
  54447. +
  54448. + /* Set the last, ioc and sp bits on the Last DMA Descriptor */
  54449. + desc_last->status.b.l = 1;
  54450. + desc_last->status.b.ioc = 1;
  54451. + desc_last->status.b.sp = ep->dwc_ep.sent_zlp;
  54452. + /* Save the last DMA descriptor pointer */
  54453. + cfiep->dma_desc_last = desc_last;
  54454. + cfiep->desc_count = sgval->bCount;
  54455. +}
  54456. +
  54457. +/**
  54458. + * This function builds the DMA descriptors for the Concatenation buffer mode.
  54459. + */
  54460. +static void cfi_build_concat_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  54461. + dwc_otg_pcd_request_t * req)
  54462. +{
  54463. + struct dwc_otg_pcd_ep *ep = cfiep->ep;
  54464. + ddma_concat_buffer_setup_t *concatval = cfiep->bm_concat;
  54465. + struct dwc_otg_dma_desc *desc = cfiep->ep->dwc_ep.descs;
  54466. + struct dwc_otg_dma_desc *desc_last = cfiep->ep->dwc_ep.descs;
  54467. + dma_addr_t buff_addr = req->dma;
  54468. + int i;
  54469. + uint16_t *txsize;
  54470. +
  54471. + txsize = concatval->wTxBytes;
  54472. +
  54473. + for (i = 0; i < concatval->hdr.bDescCount; i++) {
  54474. + desc->buf = buff_addr;
  54475. + desc->status.b.bs = BS_HOST_BUSY;
  54476. + desc->status.b.l = 0;
  54477. + desc->status.b.ioc = 0;
  54478. + desc->status.b.sp = 0;
  54479. + desc->status.b.bytes = *txsize;
  54480. + desc->status.b.bs = BS_HOST_READY;
  54481. +
  54482. + txsize++;
  54483. + /* Set the next address of the buffer */
  54484. + buff_addr += UGETW(ep->desc->wMaxPacketSize);
  54485. + desc_last = desc;
  54486. + desc++;
  54487. + }
  54488. +
  54489. + /* Set the last, ioc and sp bits on the Last DMA Descriptor */
  54490. + desc_last->status.b.l = 1;
  54491. + desc_last->status.b.ioc = 1;
  54492. + desc_last->status.b.sp = ep->dwc_ep.sent_zlp;
  54493. + cfiep->dma_desc_last = desc_last;
  54494. + cfiep->desc_count = concatval->hdr.bDescCount;
  54495. +}
  54496. +
  54497. +/**
  54498. + * This function builds the DMA descriptors for the Circular buffer mode
  54499. + */
  54500. +static void cfi_build_circ_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  54501. + dwc_otg_pcd_request_t * req)
  54502. +{
  54503. + /* @todo: MAS - add implementation when this feature needs to be tested */
  54504. +}
  54505. +
  54506. +/**
  54507. + * This function builds the DMA descriptors for the Alignment buffer mode
  54508. + */
  54509. +static void cfi_build_align_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  54510. + dwc_otg_pcd_request_t * req)
  54511. +{
  54512. + struct dwc_otg_pcd_ep *ep = cfiep->ep;
  54513. + ddma_align_buffer_setup_t *alignval = cfiep->bm_align;
  54514. + struct dwc_otg_dma_desc *desc = cfiep->ep->dwc_ep.descs;
  54515. + dma_addr_t buff_addr = req->dma;
  54516. +
  54517. + desc->status.b.bs = BS_HOST_BUSY;
  54518. + desc->status.b.l = 1;
  54519. + desc->status.b.ioc = 1;
  54520. + desc->status.b.sp = ep->dwc_ep.sent_zlp;
  54521. + desc->status.b.bytes = req->length;
  54522. + /* Adjust the buffer alignment */
  54523. + desc->buf = (buff_addr + alignval->bAlign);
  54524. + desc->status.b.bs = BS_HOST_READY;
  54525. + cfiep->dma_desc_last = desc;
  54526. + cfiep->desc_count = 1;
  54527. +}
  54528. +
  54529. +/**
  54530. + * This function builds the DMA descriptors chain for different modes of the
  54531. + * buffer setup of an endpoint.
  54532. + */
  54533. +static void cfi_build_descriptors(struct cfiobject *cfi,
  54534. + struct dwc_otg_pcd *pcd,
  54535. + struct dwc_otg_pcd_ep *ep,
  54536. + dwc_otg_pcd_request_t * req)
  54537. +{
  54538. + cfi_ep_t *cfiep;
  54539. +
  54540. + /* Get the cfiep by the dwc_otg_pcd_ep */
  54541. + cfiep = get_cfi_ep_by_pcd_ep(cfi, ep);
  54542. + if (NULL == cfiep) {
  54543. + CFI_INFO("%s: Unable to find a matching active endpoint\n",
  54544. + __func__);
  54545. + return;
  54546. + }
  54547. +
  54548. + cfiep->xfer_len = req->length;
  54549. +
  54550. + /* Iterate through all the DMA descriptors */
  54551. + switch (cfiep->ep->dwc_ep.buff_mode) {
  54552. + case BM_SG:
  54553. + cfi_build_sg_descs(cfi, cfiep, req);
  54554. + break;
  54555. +
  54556. + case BM_CONCAT:
  54557. + cfi_build_concat_descs(cfi, cfiep, req);
  54558. + break;
  54559. +
  54560. + case BM_CIRCULAR:
  54561. + cfi_build_circ_descs(cfi, cfiep, req);
  54562. + break;
  54563. +
  54564. + case BM_ALIGN:
  54565. + cfi_build_align_descs(cfi, cfiep, req);
  54566. + break;
  54567. +
  54568. + default:
  54569. + break;
  54570. + }
  54571. +}
  54572. +
  54573. +/**
  54574. + * Allocate DMA buffer for different Buffer modes.
  54575. + */
  54576. +static void *cfi_ep_alloc_buf(struct cfiobject *cfi, struct dwc_otg_pcd *pcd,
  54577. + struct dwc_otg_pcd_ep *ep, dma_addr_t * dma,
  54578. + unsigned size, gfp_t flags)
  54579. +{
  54580. + return DWC_DMA_ALLOC(size, dma);
  54581. +}
  54582. +
  54583. +/**
  54584. + * This function initializes the CFI object.
  54585. + */
  54586. +int init_cfi(cfiobject_t * cfiobj)
  54587. +{
  54588. + CFI_INFO("%s\n", __func__);
  54589. +
  54590. + /* Allocate a buffer for IN XFERs */
  54591. + cfiobj->buf_in.buf =
  54592. + DWC_DMA_ALLOC(CFI_IN_BUF_LEN, &cfiobj->buf_in.addr);
  54593. + if (NULL == cfiobj->buf_in.buf) {
  54594. + CFI_INFO("Unable to allocate buffer for INs\n");
  54595. + return -DWC_E_NO_MEMORY;
  54596. + }
  54597. +
  54598. + /* Allocate a buffer for OUT XFERs */
  54599. + cfiobj->buf_out.buf =
  54600. + DWC_DMA_ALLOC(CFI_OUT_BUF_LEN, &cfiobj->buf_out.addr);
  54601. + if (NULL == cfiobj->buf_out.buf) {
  54602. + CFI_INFO("Unable to allocate buffer for OUT\n");
  54603. + return -DWC_E_NO_MEMORY;
  54604. + }
  54605. +
  54606. + /* Initialize the callback function pointers */
  54607. + cfiobj->ops.release = cfi_release;
  54608. + cfiobj->ops.ep_enable = cfi_ep_enable;
  54609. + cfiobj->ops.ctrl_write_complete = cfi_ctrl_write_complete;
  54610. + cfiobj->ops.build_descriptors = cfi_build_descriptors;
  54611. + cfiobj->ops.ep_alloc_buf = cfi_ep_alloc_buf;
  54612. +
  54613. + /* Initialize the list of active endpoints in the CFI object */
  54614. + DWC_LIST_INIT(&cfiobj->active_eps);
  54615. +
  54616. + return 0;
  54617. +}
  54618. +
  54619. +/**
  54620. + * This function reads the required feature's current value into the buffer
  54621. + *
  54622. + * @retval: Returns negative as error, or the data length of the feature
  54623. + */
  54624. +static int cfi_get_feature_value(uint8_t * buf, uint16_t buflen,
  54625. + struct dwc_otg_pcd *pcd,
  54626. + struct cfi_usb_ctrlrequest *ctrl_req)
  54627. +{
  54628. + int retval = -DWC_E_NOT_SUPPORTED;
  54629. + struct dwc_otg_core_if *coreif = GET_CORE_IF(pcd);
  54630. + uint16_t dfifo, rxfifo, txfifo;
  54631. +
  54632. + switch (ctrl_req->wIndex) {
  54633. + /* Whether the DDMA is enabled or not */
  54634. + case FT_ID_DMA_MODE:
  54635. + *buf = (coreif->dma_enable && coreif->dma_desc_enable) ? 1 : 0;
  54636. + retval = 1;
  54637. + break;
  54638. +
  54639. + case FT_ID_DMA_BUFFER_SETUP:
  54640. + retval = cfi_ep_get_sg_val(buf, pcd, ctrl_req);
  54641. + break;
  54642. +
  54643. + case FT_ID_DMA_BUFF_ALIGN:
  54644. + retval = cfi_ep_get_align_val(buf, pcd, ctrl_req);
  54645. + break;
  54646. +
  54647. + case FT_ID_DMA_CONCAT_SETUP:
  54648. + retval = cfi_ep_get_concat_val(buf, pcd, ctrl_req);
  54649. + break;
  54650. +
  54651. + case FT_ID_DMA_CIRCULAR:
  54652. + CFI_INFO("GetFeature value (FT_ID_DMA_CIRCULAR)\n");
  54653. + break;
  54654. +
  54655. + case FT_ID_THRESHOLD_SETUP:
  54656. + CFI_INFO("GetFeature value (FT_ID_THRESHOLD_SETUP)\n");
  54657. + break;
  54658. +
  54659. + case FT_ID_DFIFO_DEPTH:
  54660. + dfifo = get_dfifo_size(coreif);
  54661. + *((uint16_t *) buf) = dfifo;
  54662. + retval = sizeof(uint16_t);
  54663. + break;
  54664. +
  54665. + case FT_ID_TX_FIFO_DEPTH:
  54666. + retval = get_txfifo_size(pcd, ctrl_req->wValue);
  54667. + if (retval >= 0) {
  54668. + txfifo = retval;
  54669. + *((uint16_t *) buf) = txfifo;
  54670. + retval = sizeof(uint16_t);
  54671. + }
  54672. + break;
  54673. +
  54674. + case FT_ID_RX_FIFO_DEPTH:
  54675. + retval = get_rxfifo_size(coreif, ctrl_req->wValue);
  54676. + if (retval >= 0) {
  54677. + rxfifo = retval;
  54678. + *((uint16_t *) buf) = rxfifo;
  54679. + retval = sizeof(uint16_t);
  54680. + }
  54681. + break;
  54682. + }
  54683. +
  54684. + return retval;
  54685. +}
  54686. +
  54687. +/**
  54688. + * This function resets the SG for the specified EP to its default value
  54689. + */
  54690. +static int cfi_reset_sg_val(cfi_ep_t * cfiep)
  54691. +{
  54692. + dwc_memset(cfiep->bm_sg, 0, sizeof(ddma_sg_buffer_setup_t));
  54693. + return 0;
  54694. +}
  54695. +
  54696. +/**
  54697. + * This function resets the Alignment for the specified EP to its default value
  54698. + */
  54699. +static int cfi_reset_align_val(cfi_ep_t * cfiep)
  54700. +{
  54701. + dwc_memset(cfiep->bm_sg, 0, sizeof(ddma_sg_buffer_setup_t));
  54702. + return 0;
  54703. +}
  54704. +
  54705. +/**
  54706. + * This function resets the Concatenation for the specified EP to its default value
  54707. + * This function will also set the value of the wTxBytes field to NULL after
  54708. + * freeing the memory previously allocated for this field.
  54709. + */
  54710. +static int cfi_reset_concat_val(cfi_ep_t * cfiep)
  54711. +{
  54712. + /* First we need to free the wTxBytes field */
  54713. + if (cfiep->bm_concat->wTxBytes) {
  54714. + DWC_FREE(cfiep->bm_concat->wTxBytes);
  54715. + cfiep->bm_concat->wTxBytes = NULL;
  54716. + }
  54717. +
  54718. + dwc_memset(cfiep->bm_concat, 0, sizeof(ddma_concat_buffer_setup_t));
  54719. + return 0;
  54720. +}
  54721. +
  54722. +/**
  54723. + * This function resets all the buffer setups of the specified endpoint
  54724. + */
  54725. +static int cfi_ep_reset_all_setup_vals(cfi_ep_t * cfiep)
  54726. +{
  54727. + cfi_reset_sg_val(cfiep);
  54728. + cfi_reset_align_val(cfiep);
  54729. + cfi_reset_concat_val(cfiep);
  54730. + return 0;
  54731. +}
  54732. +
  54733. +static int cfi_handle_reset_fifo_val(struct dwc_otg_pcd *pcd, uint8_t ep_addr,
  54734. + uint8_t rx_rst, uint8_t tx_rst)
  54735. +{
  54736. + int retval = -DWC_E_INVALID;
  54737. + uint16_t tx_siz[15];
  54738. + uint16_t rx_siz = 0;
  54739. + dwc_otg_pcd_ep_t *ep = NULL;
  54740. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  54741. + dwc_otg_core_params_t *params = GET_CORE_IF(pcd)->core_params;
  54742. +
  54743. + if (rx_rst) {
  54744. + rx_siz = params->dev_rx_fifo_size;
  54745. + params->dev_rx_fifo_size = GET_CORE_IF(pcd)->init_rxfsiz;
  54746. + }
  54747. +
  54748. + if (tx_rst) {
  54749. + if (ep_addr == 0) {
  54750. + int i;
  54751. +
  54752. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  54753. + tx_siz[i] =
  54754. + core_if->core_params->dev_tx_fifo_size[i];
  54755. + core_if->core_params->dev_tx_fifo_size[i] =
  54756. + core_if->init_txfsiz[i];
  54757. + }
  54758. + } else {
  54759. +
  54760. + ep = get_ep_by_addr(pcd, ep_addr);
  54761. +
  54762. + if (NULL == ep) {
  54763. + CFI_INFO
  54764. + ("%s: Unable to get the endpoint addr=0x%02x\n",
  54765. + __func__, ep_addr);
  54766. + return -DWC_E_INVALID;
  54767. + }
  54768. +
  54769. + tx_siz[0] =
  54770. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num -
  54771. + 1];
  54772. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1] =
  54773. + GET_CORE_IF(pcd)->init_txfsiz[ep->
  54774. + dwc_ep.tx_fifo_num -
  54775. + 1];
  54776. + }
  54777. + }
  54778. +
  54779. + if (resize_fifos(GET_CORE_IF(pcd))) {
  54780. + retval = 0;
  54781. + } else {
  54782. + CFI_INFO
  54783. + ("%s: Error resetting the feature Reset All(FIFO size)\n",
  54784. + __func__);
  54785. + if (rx_rst) {
  54786. + params->dev_rx_fifo_size = rx_siz;
  54787. + }
  54788. +
  54789. + if (tx_rst) {
  54790. + if (ep_addr == 0) {
  54791. + int i;
  54792. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps;
  54793. + i++) {
  54794. + core_if->
  54795. + core_params->dev_tx_fifo_size[i] =
  54796. + tx_siz[i];
  54797. + }
  54798. + } else {
  54799. + params->dev_tx_fifo_size[ep->
  54800. + dwc_ep.tx_fifo_num -
  54801. + 1] = tx_siz[0];
  54802. + }
  54803. + }
  54804. + retval = -DWC_E_INVALID;
  54805. + }
  54806. + return retval;
  54807. +}
  54808. +
  54809. +static int cfi_handle_reset_all(struct dwc_otg_pcd *pcd, uint8_t addr)
  54810. +{
  54811. + int retval = 0;
  54812. + cfi_ep_t *cfiep;
  54813. + cfiobject_t *cfi = pcd->cfi;
  54814. + dwc_list_link_t *tmp;
  54815. +
  54816. + retval = cfi_handle_reset_fifo_val(pcd, addr, 1, 1);
  54817. + if (retval < 0) {
  54818. + return retval;
  54819. + }
  54820. +
  54821. + /* If the EP address is known then reset the features for only that EP */
  54822. + if (addr) {
  54823. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  54824. + if (NULL == cfiep) {
  54825. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  54826. + __func__, addr);
  54827. + return -DWC_E_INVALID;
  54828. + }
  54829. + retval = cfi_ep_reset_all_setup_vals(cfiep);
  54830. + cfiep->ep->dwc_ep.buff_mode = BM_STANDARD;
  54831. + }
  54832. + /* Otherwise (wValue == 0), reset all features of all EP's */
  54833. + else {
  54834. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  54835. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  54836. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  54837. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  54838. + retval = cfi_ep_reset_all_setup_vals(cfiep);
  54839. + cfiep->ep->dwc_ep.buff_mode = BM_STANDARD;
  54840. + if (retval < 0) {
  54841. + CFI_INFO
  54842. + ("%s: Error resetting the feature Reset All\n",
  54843. + __func__);
  54844. + return retval;
  54845. + }
  54846. + }
  54847. + }
  54848. + return retval;
  54849. +}
  54850. +
  54851. +static int cfi_handle_reset_dma_buff_setup(struct dwc_otg_pcd *pcd,
  54852. + uint8_t addr)
  54853. +{
  54854. + int retval = 0;
  54855. + cfi_ep_t *cfiep;
  54856. + cfiobject_t *cfi = pcd->cfi;
  54857. + dwc_list_link_t *tmp;
  54858. +
  54859. + /* If the EP address is known then reset the features for only that EP */
  54860. + if (addr) {
  54861. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  54862. + if (NULL == cfiep) {
  54863. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  54864. + __func__, addr);
  54865. + return -DWC_E_INVALID;
  54866. + }
  54867. + retval = cfi_reset_sg_val(cfiep);
  54868. + }
  54869. + /* Otherwise (wValue == 0), reset all features of all EP's */
  54870. + else {
  54871. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  54872. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  54873. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  54874. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  54875. + retval = cfi_reset_sg_val(cfiep);
  54876. + if (retval < 0) {
  54877. + CFI_INFO
  54878. + ("%s: Error resetting the feature Buffer Setup\n",
  54879. + __func__);
  54880. + return retval;
  54881. + }
  54882. + }
  54883. + }
  54884. + return retval;
  54885. +}
  54886. +
  54887. +static int cfi_handle_reset_concat_val(struct dwc_otg_pcd *pcd, uint8_t addr)
  54888. +{
  54889. + int retval = 0;
  54890. + cfi_ep_t *cfiep;
  54891. + cfiobject_t *cfi = pcd->cfi;
  54892. + dwc_list_link_t *tmp;
  54893. +
  54894. + /* If the EP address is known then reset the features for only that EP */
  54895. + if (addr) {
  54896. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  54897. + if (NULL == cfiep) {
  54898. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  54899. + __func__, addr);
  54900. + return -DWC_E_INVALID;
  54901. + }
  54902. + retval = cfi_reset_concat_val(cfiep);
  54903. + }
  54904. + /* Otherwise (wValue == 0), reset all features of all EP's */
  54905. + else {
  54906. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  54907. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  54908. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  54909. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  54910. + retval = cfi_reset_concat_val(cfiep);
  54911. + if (retval < 0) {
  54912. + CFI_INFO
  54913. + ("%s: Error resetting the feature Concatenation Value\n",
  54914. + __func__);
  54915. + return retval;
  54916. + }
  54917. + }
  54918. + }
  54919. + return retval;
  54920. +}
  54921. +
  54922. +static int cfi_handle_reset_align_val(struct dwc_otg_pcd *pcd, uint8_t addr)
  54923. +{
  54924. + int retval = 0;
  54925. + cfi_ep_t *cfiep;
  54926. + cfiobject_t *cfi = pcd->cfi;
  54927. + dwc_list_link_t *tmp;
  54928. +
  54929. + /* If the EP address is known then reset the features for only that EP */
  54930. + if (addr) {
  54931. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  54932. + if (NULL == cfiep) {
  54933. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  54934. + __func__, addr);
  54935. + return -DWC_E_INVALID;
  54936. + }
  54937. + retval = cfi_reset_align_val(cfiep);
  54938. + }
  54939. + /* Otherwise (wValue == 0), reset all features of all EP's */
  54940. + else {
  54941. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  54942. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  54943. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  54944. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  54945. + retval = cfi_reset_align_val(cfiep);
  54946. + if (retval < 0) {
  54947. + CFI_INFO
  54948. + ("%s: Error resetting the feature Aliignment Value\n",
  54949. + __func__);
  54950. + return retval;
  54951. + }
  54952. + }
  54953. + }
  54954. + return retval;
  54955. +
  54956. +}
  54957. +
  54958. +static int cfi_preproc_reset(struct dwc_otg_pcd *pcd,
  54959. + struct cfi_usb_ctrlrequest *req)
  54960. +{
  54961. + int retval = 0;
  54962. +
  54963. + switch (req->wIndex) {
  54964. + case 0:
  54965. + /* Reset all features */
  54966. + retval = cfi_handle_reset_all(pcd, req->wValue & 0xff);
  54967. + break;
  54968. +
  54969. + case FT_ID_DMA_BUFFER_SETUP:
  54970. + /* Reset the SG buffer setup */
  54971. + retval =
  54972. + cfi_handle_reset_dma_buff_setup(pcd, req->wValue & 0xff);
  54973. + break;
  54974. +
  54975. + case FT_ID_DMA_CONCAT_SETUP:
  54976. + /* Reset the Concatenation buffer setup */
  54977. + retval = cfi_handle_reset_concat_val(pcd, req->wValue & 0xff);
  54978. + break;
  54979. +
  54980. + case FT_ID_DMA_BUFF_ALIGN:
  54981. + /* Reset the Alignment buffer setup */
  54982. + retval = cfi_handle_reset_align_val(pcd, req->wValue & 0xff);
  54983. + break;
  54984. +
  54985. + case FT_ID_TX_FIFO_DEPTH:
  54986. + retval =
  54987. + cfi_handle_reset_fifo_val(pcd, req->wValue & 0xff, 0, 1);
  54988. + pcd->cfi->need_gadget_att = 0;
  54989. + break;
  54990. +
  54991. + case FT_ID_RX_FIFO_DEPTH:
  54992. + retval = cfi_handle_reset_fifo_val(pcd, 0, 1, 0);
  54993. + pcd->cfi->need_gadget_att = 0;
  54994. + break;
  54995. + default:
  54996. + break;
  54997. + }
  54998. + return retval;
  54999. +}
  55000. +
  55001. +/**
  55002. + * This function sets a new value for the SG buffer setup.
  55003. + */
  55004. +static int cfi_ep_set_sg_val(uint8_t * buf, struct dwc_otg_pcd *pcd)
  55005. +{
  55006. + uint8_t inaddr, outaddr;
  55007. + cfi_ep_t *epin, *epout;
  55008. + ddma_sg_buffer_setup_t *psgval;
  55009. + uint32_t desccount, size;
  55010. +
  55011. + CFI_INFO("%s\n", __func__);
  55012. +
  55013. + psgval = (ddma_sg_buffer_setup_t *) buf;
  55014. + desccount = (uint32_t) psgval->bCount;
  55015. + size = (uint32_t) psgval->wSize;
  55016. +
  55017. + /* Check the DMA descriptor count */
  55018. + if ((desccount > MAX_DMA_DESCS_PER_EP) || (desccount == 0)) {
  55019. + CFI_INFO
  55020. + ("%s: The count of DMA Descriptors should be between 1 and %d\n",
  55021. + __func__, MAX_DMA_DESCS_PER_EP);
  55022. + return -DWC_E_INVALID;
  55023. + }
  55024. +
  55025. + /* Check the DMA descriptor count */
  55026. +
  55027. + if (size == 0) {
  55028. +
  55029. + CFI_INFO("%s: The transfer size should be at least 1 byte\n",
  55030. + __func__);
  55031. +
  55032. + return -DWC_E_INVALID;
  55033. +
  55034. + }
  55035. +
  55036. + inaddr = psgval->bInEndpointAddress;
  55037. + outaddr = psgval->bOutEndpointAddress;
  55038. +
  55039. + epin = get_cfi_ep_by_addr(pcd->cfi, inaddr);
  55040. + epout = get_cfi_ep_by_addr(pcd->cfi, outaddr);
  55041. +
  55042. + if (NULL == epin || NULL == epout) {
  55043. + CFI_INFO
  55044. + ("%s: Unable to get the endpoints inaddr=0x%02x outaddr=0x%02x\n",
  55045. + __func__, inaddr, outaddr);
  55046. + return -DWC_E_INVALID;
  55047. + }
  55048. +
  55049. + epin->ep->dwc_ep.buff_mode = BM_SG;
  55050. + dwc_memcpy(epin->bm_sg, psgval, sizeof(ddma_sg_buffer_setup_t));
  55051. +
  55052. + epout->ep->dwc_ep.buff_mode = BM_SG;
  55053. + dwc_memcpy(epout->bm_sg, psgval, sizeof(ddma_sg_buffer_setup_t));
  55054. +
  55055. + return 0;
  55056. +}
  55057. +
  55058. +/**
  55059. + * This function sets a new value for the buffer Alignment setup.
  55060. + */
  55061. +static int cfi_ep_set_alignment_val(uint8_t * buf, struct dwc_otg_pcd *pcd)
  55062. +{
  55063. + cfi_ep_t *ep;
  55064. + uint8_t addr;
  55065. + ddma_align_buffer_setup_t *palignval;
  55066. +
  55067. + palignval = (ddma_align_buffer_setup_t *) buf;
  55068. + addr = palignval->bEndpointAddress;
  55069. +
  55070. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  55071. +
  55072. + if (NULL == ep) {
  55073. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  55074. + __func__, addr);
  55075. + return -DWC_E_INVALID;
  55076. + }
  55077. +
  55078. + ep->ep->dwc_ep.buff_mode = BM_ALIGN;
  55079. + dwc_memcpy(ep->bm_align, palignval, sizeof(ddma_align_buffer_setup_t));
  55080. +
  55081. + return 0;
  55082. +}
  55083. +
  55084. +/**
  55085. + * This function sets a new value for the Concatenation buffer setup.
  55086. + */
  55087. +static int cfi_ep_set_concat_val(uint8_t * buf, struct dwc_otg_pcd *pcd)
  55088. +{
  55089. + uint8_t addr;
  55090. + cfi_ep_t *ep;
  55091. + struct _ddma_concat_buffer_setup_hdr *pConcatValHdr;
  55092. + uint16_t *pVals;
  55093. + uint32_t desccount;
  55094. + int i;
  55095. + uint16_t mps;
  55096. +
  55097. + pConcatValHdr = (struct _ddma_concat_buffer_setup_hdr *)buf;
  55098. + desccount = (uint32_t) pConcatValHdr->bDescCount;
  55099. + pVals = (uint16_t *) (buf + BS_CONCAT_VAL_HDR_LEN);
  55100. +
  55101. + /* Check the DMA descriptor count */
  55102. + if (desccount > MAX_DMA_DESCS_PER_EP) {
  55103. + CFI_INFO("%s: Maximum DMA Descriptor count should be %d\n",
  55104. + __func__, MAX_DMA_DESCS_PER_EP);
  55105. + return -DWC_E_INVALID;
  55106. + }
  55107. +
  55108. + addr = pConcatValHdr->bEndpointAddress;
  55109. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  55110. + if (NULL == ep) {
  55111. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  55112. + __func__, addr);
  55113. + return -DWC_E_INVALID;
  55114. + }
  55115. +
  55116. + mps = UGETW(ep->ep->desc->wMaxPacketSize);
  55117. +
  55118. +#if 0
  55119. + for (i = 0; i < desccount; i++) {
  55120. + CFI_INFO("%s: wTxSize[%d]=0x%04x\n", __func__, i, pVals[i]);
  55121. + }
  55122. + CFI_INFO("%s: epname=%s; mps=%d\n", __func__, ep->ep->ep.name, mps);
  55123. +#endif
  55124. +
  55125. + /* Check the wTxSizes to be less than or equal to the mps */
  55126. + for (i = 0; i < desccount; i++) {
  55127. + if (pVals[i] > mps) {
  55128. + CFI_INFO
  55129. + ("%s: ERROR - the wTxSize[%d] should be <= MPS (wTxSize=%d)\n",
  55130. + __func__, i, pVals[i]);
  55131. + return -DWC_E_INVALID;
  55132. + }
  55133. + }
  55134. +
  55135. + ep->ep->dwc_ep.buff_mode = BM_CONCAT;
  55136. + dwc_memcpy(ep->bm_concat, pConcatValHdr, BS_CONCAT_VAL_HDR_LEN);
  55137. +
  55138. + /* Free the previously allocated storage for the wTxBytes */
  55139. + if (ep->bm_concat->wTxBytes) {
  55140. + DWC_FREE(ep->bm_concat->wTxBytes);
  55141. + }
  55142. +
  55143. + /* Allocate a new storage for the wTxBytes field */
  55144. + ep->bm_concat->wTxBytes =
  55145. + DWC_ALLOC(sizeof(uint16_t) * pConcatValHdr->bDescCount);
  55146. + if (NULL == ep->bm_concat->wTxBytes) {
  55147. + CFI_INFO("%s: Unable to allocate memory\n", __func__);
  55148. + return -DWC_E_NO_MEMORY;
  55149. + }
  55150. +
  55151. + /* Copy the new values into the wTxBytes filed */
  55152. + dwc_memcpy(ep->bm_concat->wTxBytes, buf + BS_CONCAT_VAL_HDR_LEN,
  55153. + sizeof(uint16_t) * pConcatValHdr->bDescCount);
  55154. +
  55155. + return 0;
  55156. +}
  55157. +
  55158. +/**
  55159. + * This function calculates the total of all FIFO sizes
  55160. + *
  55161. + * @param core_if Programming view of DWC_otg controller
  55162. + *
  55163. + * @return The total of data FIFO sizes.
  55164. + *
  55165. + */
  55166. +static uint16_t get_dfifo_size(dwc_otg_core_if_t * core_if)
  55167. +{
  55168. + dwc_otg_core_params_t *params = core_if->core_params;
  55169. + uint16_t dfifo_total = 0;
  55170. + int i;
  55171. +
  55172. + /* The shared RxFIFO size */
  55173. + dfifo_total =
  55174. + params->dev_rx_fifo_size + params->dev_nperio_tx_fifo_size;
  55175. +
  55176. + /* Add up each TxFIFO size to the total */
  55177. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  55178. + dfifo_total += params->dev_tx_fifo_size[i];
  55179. + }
  55180. +
  55181. + return dfifo_total;
  55182. +}
  55183. +
  55184. +/**
  55185. + * This function returns Rx FIFO size
  55186. + *
  55187. + * @param core_if Programming view of DWC_otg controller
  55188. + *
  55189. + * @return The total of data FIFO sizes.
  55190. + *
  55191. + */
  55192. +static int32_t get_rxfifo_size(dwc_otg_core_if_t * core_if, uint16_t wValue)
  55193. +{
  55194. + switch (wValue >> 8) {
  55195. + case 0:
  55196. + return (core_if->pwron_rxfsiz <
  55197. + 32768) ? core_if->pwron_rxfsiz : 32768;
  55198. + break;
  55199. + case 1:
  55200. + return core_if->core_params->dev_rx_fifo_size;
  55201. + break;
  55202. + default:
  55203. + return -DWC_E_INVALID;
  55204. + break;
  55205. + }
  55206. +}
  55207. +
  55208. +/**
  55209. + * This function returns Tx FIFO size for IN EP
  55210. + *
  55211. + * @param core_if Programming view of DWC_otg controller
  55212. + *
  55213. + * @return The total of data FIFO sizes.
  55214. + *
  55215. + */
  55216. +static int32_t get_txfifo_size(struct dwc_otg_pcd *pcd, uint16_t wValue)
  55217. +{
  55218. + dwc_otg_pcd_ep_t *ep;
  55219. +
  55220. + ep = get_ep_by_addr(pcd, wValue & 0xff);
  55221. +
  55222. + if (NULL == ep) {
  55223. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  55224. + __func__, wValue & 0xff);
  55225. + return -DWC_E_INVALID;
  55226. + }
  55227. +
  55228. + if (!ep->dwc_ep.is_in) {
  55229. + CFI_INFO
  55230. + ("%s: No Tx FIFO assingned to the Out endpoint addr=0x%02x\n",
  55231. + __func__, wValue & 0xff);
  55232. + return -DWC_E_INVALID;
  55233. + }
  55234. +
  55235. + switch (wValue >> 8) {
  55236. + case 0:
  55237. + return (GET_CORE_IF(pcd)->pwron_txfsiz
  55238. + [ep->dwc_ep.tx_fifo_num - 1] <
  55239. + 768) ? GET_CORE_IF(pcd)->pwron_txfsiz[ep->
  55240. + dwc_ep.tx_fifo_num
  55241. + - 1] : 32768;
  55242. + break;
  55243. + case 1:
  55244. + return GET_CORE_IF(pcd)->core_params->
  55245. + dev_tx_fifo_size[ep->dwc_ep.num - 1];
  55246. + break;
  55247. + default:
  55248. + return -DWC_E_INVALID;
  55249. + break;
  55250. + }
  55251. +}
  55252. +
  55253. +/**
  55254. + * This function checks if the submitted combination of
  55255. + * device mode FIFO sizes is possible or not.
  55256. + *
  55257. + * @param core_if Programming view of DWC_otg controller
  55258. + *
  55259. + * @return 1 if possible, 0 otherwise.
  55260. + *
  55261. + */
  55262. +static uint8_t check_fifo_sizes(dwc_otg_core_if_t * core_if)
  55263. +{
  55264. + uint16_t dfifo_actual = 0;
  55265. + dwc_otg_core_params_t *params = core_if->core_params;
  55266. + uint16_t start_addr = 0;
  55267. + int i;
  55268. +
  55269. + dfifo_actual =
  55270. + params->dev_rx_fifo_size + params->dev_nperio_tx_fifo_size;
  55271. +
  55272. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  55273. + dfifo_actual += params->dev_tx_fifo_size[i];
  55274. + }
  55275. +
  55276. + if (dfifo_actual > core_if->total_fifo_size) {
  55277. + return 0;
  55278. + }
  55279. +
  55280. + if (params->dev_rx_fifo_size > 32768 || params->dev_rx_fifo_size < 16)
  55281. + return 0;
  55282. +
  55283. + if (params->dev_nperio_tx_fifo_size > 32768
  55284. + || params->dev_nperio_tx_fifo_size < 16)
  55285. + return 0;
  55286. +
  55287. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  55288. +
  55289. + if (params->dev_tx_fifo_size[i] > 768
  55290. + || params->dev_tx_fifo_size[i] < 4)
  55291. + return 0;
  55292. + }
  55293. +
  55294. + if (params->dev_rx_fifo_size > core_if->pwron_rxfsiz)
  55295. + return 0;
  55296. + start_addr = params->dev_rx_fifo_size;
  55297. +
  55298. + if (params->dev_nperio_tx_fifo_size > core_if->pwron_gnptxfsiz)
  55299. + return 0;
  55300. + start_addr += params->dev_nperio_tx_fifo_size;
  55301. +
  55302. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  55303. +
  55304. + if (params->dev_tx_fifo_size[i] > core_if->pwron_txfsiz[i])
  55305. + return 0;
  55306. + start_addr += params->dev_tx_fifo_size[i];
  55307. + }
  55308. +
  55309. + return 1;
  55310. +}
  55311. +
  55312. +/**
  55313. + * This function resizes Device mode FIFOs
  55314. + *
  55315. + * @param core_if Programming view of DWC_otg controller
  55316. + *
  55317. + * @return 1 if successful, 0 otherwise
  55318. + *
  55319. + */
  55320. +static uint8_t resize_fifos(dwc_otg_core_if_t * core_if)
  55321. +{
  55322. + int i = 0;
  55323. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  55324. + dwc_otg_core_params_t *params = core_if->core_params;
  55325. + uint32_t rx_fifo_size;
  55326. + fifosize_data_t nptxfifosize;
  55327. + fifosize_data_t txfifosize[15];
  55328. +
  55329. + uint32_t rx_fsz_bak;
  55330. + uint32_t nptxfsz_bak;
  55331. + uint32_t txfsz_bak[15];
  55332. +
  55333. + uint16_t start_address;
  55334. + uint8_t retval = 1;
  55335. +
  55336. + if (!check_fifo_sizes(core_if)) {
  55337. + return 0;
  55338. + }
  55339. +
  55340. + /* Configure data FIFO sizes */
  55341. + if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
  55342. + rx_fsz_bak = DWC_READ_REG32(&global_regs->grxfsiz);
  55343. + rx_fifo_size = params->dev_rx_fifo_size;
  55344. + DWC_WRITE_REG32(&global_regs->grxfsiz, rx_fifo_size);
  55345. +
  55346. + /*
  55347. + * Tx FIFOs These FIFOs are numbered from 1 to 15.
  55348. + * Indexes of the FIFO size module parameters in the
  55349. + * dev_tx_fifo_size array and the FIFO size registers in
  55350. + * the dtxfsiz array run from 0 to 14.
  55351. + */
  55352. +
  55353. + /* Non-periodic Tx FIFO */
  55354. + nptxfsz_bak = DWC_READ_REG32(&global_regs->gnptxfsiz);
  55355. + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
  55356. + start_address = params->dev_rx_fifo_size;
  55357. + nptxfifosize.b.startaddr = start_address;
  55358. +
  55359. + DWC_WRITE_REG32(&global_regs->gnptxfsiz, nptxfifosize.d32);
  55360. +
  55361. + start_address += nptxfifosize.b.depth;
  55362. +
  55363. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  55364. + txfsz_bak[i] = DWC_READ_REG32(&global_regs->dtxfsiz[i]);
  55365. +
  55366. + txfifosize[i].b.depth = params->dev_tx_fifo_size[i];
  55367. + txfifosize[i].b.startaddr = start_address;
  55368. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  55369. + txfifosize[i].d32);
  55370. +
  55371. + start_address += txfifosize[i].b.depth;
  55372. + }
  55373. +
  55374. + /** Check if register values are set correctly */
  55375. + if (rx_fifo_size != DWC_READ_REG32(&global_regs->grxfsiz)) {
  55376. + retval = 0;
  55377. + }
  55378. +
  55379. + if (nptxfifosize.d32 != DWC_READ_REG32(&global_regs->gnptxfsiz)) {
  55380. + retval = 0;
  55381. + }
  55382. +
  55383. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  55384. + if (txfifosize[i].d32 !=
  55385. + DWC_READ_REG32(&global_regs->dtxfsiz[i])) {
  55386. + retval = 0;
  55387. + }
  55388. + }
  55389. +
  55390. + /** If register values are not set correctly, reset old values */
  55391. + if (retval == 0) {
  55392. + DWC_WRITE_REG32(&global_regs->grxfsiz, rx_fsz_bak);
  55393. +
  55394. + /* Non-periodic Tx FIFO */
  55395. + DWC_WRITE_REG32(&global_regs->gnptxfsiz, nptxfsz_bak);
  55396. +
  55397. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  55398. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  55399. + txfsz_bak[i]);
  55400. + }
  55401. + }
  55402. + } else {
  55403. + return 0;
  55404. + }
  55405. +
  55406. + /* Flush the FIFOs */
  55407. + dwc_otg_flush_tx_fifo(core_if, 0x10); /* all Tx FIFOs */
  55408. + dwc_otg_flush_rx_fifo(core_if);
  55409. +
  55410. + return retval;
  55411. +}
  55412. +
  55413. +/**
  55414. + * This function sets a new value for the buffer Alignment setup.
  55415. + */
  55416. +static int cfi_ep_set_tx_fifo_val(uint8_t * buf, dwc_otg_pcd_t * pcd)
  55417. +{
  55418. + int retval;
  55419. + uint32_t fsiz;
  55420. + uint16_t size;
  55421. + uint16_t ep_addr;
  55422. + dwc_otg_pcd_ep_t *ep;
  55423. + dwc_otg_core_params_t *params = GET_CORE_IF(pcd)->core_params;
  55424. + tx_fifo_size_setup_t *ptxfifoval;
  55425. +
  55426. + ptxfifoval = (tx_fifo_size_setup_t *) buf;
  55427. + ep_addr = ptxfifoval->bEndpointAddress;
  55428. + size = ptxfifoval->wDepth;
  55429. +
  55430. + ep = get_ep_by_addr(pcd, ep_addr);
  55431. +
  55432. + CFI_INFO
  55433. + ("%s: Set Tx FIFO size: endpoint addr=0x%02x, depth=%d, FIFO Num=%d\n",
  55434. + __func__, ep_addr, size, ep->dwc_ep.tx_fifo_num);
  55435. +
  55436. + if (NULL == ep) {
  55437. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  55438. + __func__, ep_addr);
  55439. + return -DWC_E_INVALID;
  55440. + }
  55441. +
  55442. + fsiz = params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1];
  55443. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1] = size;
  55444. +
  55445. + if (resize_fifos(GET_CORE_IF(pcd))) {
  55446. + retval = 0;
  55447. + } else {
  55448. + CFI_INFO
  55449. + ("%s: Error setting the feature Tx FIFO Size for EP%d\n",
  55450. + __func__, ep_addr);
  55451. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1] = fsiz;
  55452. + retval = -DWC_E_INVALID;
  55453. + }
  55454. +
  55455. + return retval;
  55456. +}
  55457. +
  55458. +/**
  55459. + * This function sets a new value for the buffer Alignment setup.
  55460. + */
  55461. +static int cfi_set_rx_fifo_val(uint8_t * buf, dwc_otg_pcd_t * pcd)
  55462. +{
  55463. + int retval;
  55464. + uint32_t fsiz;
  55465. + uint16_t size;
  55466. + dwc_otg_core_params_t *params = GET_CORE_IF(pcd)->core_params;
  55467. + rx_fifo_size_setup_t *prxfifoval;
  55468. +
  55469. + prxfifoval = (rx_fifo_size_setup_t *) buf;
  55470. + size = prxfifoval->wDepth;
  55471. +
  55472. + fsiz = params->dev_rx_fifo_size;
  55473. + params->dev_rx_fifo_size = size;
  55474. +
  55475. + if (resize_fifos(GET_CORE_IF(pcd))) {
  55476. + retval = 0;
  55477. + } else {
  55478. + CFI_INFO("%s: Error setting the feature Rx FIFO Size\n",
  55479. + __func__);
  55480. + params->dev_rx_fifo_size = fsiz;
  55481. + retval = -DWC_E_INVALID;
  55482. + }
  55483. +
  55484. + return retval;
  55485. +}
  55486. +
  55487. +/**
  55488. + * This function reads the SG of an EP's buffer setup into the buffer buf
  55489. + */
  55490. +static int cfi_ep_get_sg_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  55491. + struct cfi_usb_ctrlrequest *req)
  55492. +{
  55493. + int retval = -DWC_E_INVALID;
  55494. + uint8_t addr;
  55495. + cfi_ep_t *ep;
  55496. +
  55497. + /* The Low Byte of the wValue contains a non-zero address of the endpoint */
  55498. + addr = req->wValue & 0xFF;
  55499. + if (addr == 0) /* The address should be non-zero */
  55500. + return retval;
  55501. +
  55502. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  55503. + if (NULL == ep) {
  55504. + CFI_INFO("%s: Unable to get the endpoint address(0x%02x)\n",
  55505. + __func__, addr);
  55506. + return retval;
  55507. + }
  55508. +
  55509. + dwc_memcpy(buf, ep->bm_sg, BS_SG_VAL_DESC_LEN);
  55510. + retval = BS_SG_VAL_DESC_LEN;
  55511. + return retval;
  55512. +}
  55513. +
  55514. +/**
  55515. + * This function reads the Concatenation value of an EP's buffer mode into
  55516. + * the buffer buf
  55517. + */
  55518. +static int cfi_ep_get_concat_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  55519. + struct cfi_usb_ctrlrequest *req)
  55520. +{
  55521. + int retval = -DWC_E_INVALID;
  55522. + uint8_t addr;
  55523. + cfi_ep_t *ep;
  55524. + uint8_t desc_count;
  55525. +
  55526. + /* The Low Byte of the wValue contains a non-zero address of the endpoint */
  55527. + addr = req->wValue & 0xFF;
  55528. + if (addr == 0) /* The address should be non-zero */
  55529. + return retval;
  55530. +
  55531. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  55532. + if (NULL == ep) {
  55533. + CFI_INFO("%s: Unable to get the endpoint address(0x%02x)\n",
  55534. + __func__, addr);
  55535. + return retval;
  55536. + }
  55537. +
  55538. + /* Copy the header to the buffer */
  55539. + dwc_memcpy(buf, ep->bm_concat, BS_CONCAT_VAL_HDR_LEN);
  55540. + /* Advance the buffer pointer by the header size */
  55541. + buf += BS_CONCAT_VAL_HDR_LEN;
  55542. +
  55543. + desc_count = ep->bm_concat->hdr.bDescCount;
  55544. + /* Copy alll the wTxBytes to the buffer */
  55545. + dwc_memcpy(buf, ep->bm_concat->wTxBytes, sizeof(uid16_t) * desc_count);
  55546. +
  55547. + retval = BS_CONCAT_VAL_HDR_LEN + sizeof(uid16_t) * desc_count;
  55548. + return retval;
  55549. +}
  55550. +
  55551. +/**
  55552. + * This function reads the buffer Alignment value of an EP's buffer mode into
  55553. + * the buffer buf
  55554. + *
  55555. + * @return The total number of bytes copied to the buffer or negative error code.
  55556. + */
  55557. +static int cfi_ep_get_align_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  55558. + struct cfi_usb_ctrlrequest *req)
  55559. +{
  55560. + int retval = -DWC_E_INVALID;
  55561. + uint8_t addr;
  55562. + cfi_ep_t *ep;
  55563. +
  55564. + /* The Low Byte of the wValue contains a non-zero address of the endpoint */
  55565. + addr = req->wValue & 0xFF;
  55566. + if (addr == 0) /* The address should be non-zero */
  55567. + return retval;
  55568. +
  55569. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  55570. + if (NULL == ep) {
  55571. + CFI_INFO("%s: Unable to get the endpoint address(0x%02x)\n",
  55572. + __func__, addr);
  55573. + return retval;
  55574. + }
  55575. +
  55576. + dwc_memcpy(buf, ep->bm_align, BS_ALIGN_VAL_HDR_LEN);
  55577. + retval = BS_ALIGN_VAL_HDR_LEN;
  55578. +
  55579. + return retval;
  55580. +}
  55581. +
  55582. +/**
  55583. + * This function sets a new value for the specified feature
  55584. + *
  55585. + * @param pcd A pointer to the PCD object
  55586. + *
  55587. + * @return 0 if successful, negative error code otherwise to stall the DCE.
  55588. + */
  55589. +static int cfi_set_feature_value(struct dwc_otg_pcd *pcd)
  55590. +{
  55591. + int retval = -DWC_E_NOT_SUPPORTED;
  55592. + uint16_t wIndex, wValue;
  55593. + uint8_t bRequest;
  55594. + struct dwc_otg_core_if *coreif;
  55595. + cfiobject_t *cfi = pcd->cfi;
  55596. + struct cfi_usb_ctrlrequest *ctrl_req;
  55597. + uint8_t *buf;
  55598. + ctrl_req = &cfi->ctrl_req;
  55599. +
  55600. + buf = pcd->cfi->ctrl_req.data;
  55601. +
  55602. + coreif = GET_CORE_IF(pcd);
  55603. + bRequest = ctrl_req->bRequest;
  55604. + wIndex = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wIndex);
  55605. + wValue = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wValue);
  55606. +
  55607. + /* See which feature is to be modified */
  55608. + switch (wIndex) {
  55609. + case FT_ID_DMA_BUFFER_SETUP:
  55610. + /* Modify the feature */
  55611. + if ((retval = cfi_ep_set_sg_val(buf, pcd)) < 0)
  55612. + return retval;
  55613. +
  55614. + /* And send this request to the gadget */
  55615. + cfi->need_gadget_att = 1;
  55616. + break;
  55617. +
  55618. + case FT_ID_DMA_BUFF_ALIGN:
  55619. + if ((retval = cfi_ep_set_alignment_val(buf, pcd)) < 0)
  55620. + return retval;
  55621. + cfi->need_gadget_att = 1;
  55622. + break;
  55623. +
  55624. + case FT_ID_DMA_CONCAT_SETUP:
  55625. + /* Modify the feature */
  55626. + if ((retval = cfi_ep_set_concat_val(buf, pcd)) < 0)
  55627. + return retval;
  55628. + cfi->need_gadget_att = 1;
  55629. + break;
  55630. +
  55631. + case FT_ID_DMA_CIRCULAR:
  55632. + CFI_INFO("FT_ID_DMA_CIRCULAR\n");
  55633. + break;
  55634. +
  55635. + case FT_ID_THRESHOLD_SETUP:
  55636. + CFI_INFO("FT_ID_THRESHOLD_SETUP\n");
  55637. + break;
  55638. +
  55639. + case FT_ID_DFIFO_DEPTH:
  55640. + CFI_INFO("FT_ID_DFIFO_DEPTH\n");
  55641. + break;
  55642. +
  55643. + case FT_ID_TX_FIFO_DEPTH:
  55644. + CFI_INFO("FT_ID_TX_FIFO_DEPTH\n");
  55645. + if ((retval = cfi_ep_set_tx_fifo_val(buf, pcd)) < 0)
  55646. + return retval;
  55647. + cfi->need_gadget_att = 0;
  55648. + break;
  55649. +
  55650. + case FT_ID_RX_FIFO_DEPTH:
  55651. + CFI_INFO("FT_ID_RX_FIFO_DEPTH\n");
  55652. + if ((retval = cfi_set_rx_fifo_val(buf, pcd)) < 0)
  55653. + return retval;
  55654. + cfi->need_gadget_att = 0;
  55655. + break;
  55656. + }
  55657. +
  55658. + return retval;
  55659. +}
  55660. +
  55661. +#endif //DWC_UTE_CFI
  55662. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_cfi.h linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_cfi.h
  55663. --- linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_cfi.h 1970-01-01 01:00:00.000000000 +0100
  55664. +++ linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_cfi.h 2014-08-06 16:50:14.793964664 +0200
  55665. @@ -0,0 +1,320 @@
  55666. +/* ==========================================================================
  55667. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  55668. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  55669. + * otherwise expressly agreed to in writing between Synopsys and you.
  55670. + *
  55671. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  55672. + * any End User Software License Agreement or Agreement for Licensed Product
  55673. + * with Synopsys or any supplement thereto. You are permitted to use and
  55674. + * redistribute this Software in source and binary forms, with or without
  55675. + * modification, provided that redistributions of source code must retain this
  55676. + * notice. You may not view, use, disclose, copy or distribute this file or
  55677. + * any information contained herein except pursuant to this license grant from
  55678. + * Synopsys. If you do not agree with this notice, including the disclaimer
  55679. + * below, then you are not authorized to use the Software.
  55680. + *
  55681. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  55682. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  55683. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  55684. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  55685. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  55686. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  55687. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  55688. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  55689. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  55690. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  55691. + * DAMAGE.
  55692. + * ========================================================================== */
  55693. +
  55694. +#if !defined(__DWC_OTG_CFI_H__)
  55695. +#define __DWC_OTG_CFI_H__
  55696. +
  55697. +#include "dwc_otg_pcd.h"
  55698. +#include "dwc_cfi_common.h"
  55699. +
  55700. +/**
  55701. + * @file
  55702. + * This file contains the CFI related OTG PCD specific common constants,
  55703. + * interfaces(functions and macros) and data structures.The CFI Protocol is an
  55704. + * optional interface for internal testing purposes that a DUT may implement to
  55705. + * support testing of configurable features.
  55706. + *
  55707. + */
  55708. +
  55709. +struct dwc_otg_pcd;
  55710. +struct dwc_otg_pcd_ep;
  55711. +
  55712. +/** OTG CFI Features (properties) ID constants */
  55713. +/** This is a request for all Core Features */
  55714. +#define FT_ID_DMA_MODE 0x0001
  55715. +#define FT_ID_DMA_BUFFER_SETUP 0x0002
  55716. +#define FT_ID_DMA_BUFF_ALIGN 0x0003
  55717. +#define FT_ID_DMA_CONCAT_SETUP 0x0004
  55718. +#define FT_ID_DMA_CIRCULAR 0x0005
  55719. +#define FT_ID_THRESHOLD_SETUP 0x0006
  55720. +#define FT_ID_DFIFO_DEPTH 0x0007
  55721. +#define FT_ID_TX_FIFO_DEPTH 0x0008
  55722. +#define FT_ID_RX_FIFO_DEPTH 0x0009
  55723. +
  55724. +/**********************************************************/
  55725. +#define CFI_INFO_DEF
  55726. +
  55727. +#ifdef CFI_INFO_DEF
  55728. +#define CFI_INFO(fmt...) DWC_PRINTF("CFI: " fmt);
  55729. +#else
  55730. +#define CFI_INFO(fmt...)
  55731. +#endif
  55732. +
  55733. +#define min(x,y) ({ \
  55734. + x < y ? x : y; })
  55735. +
  55736. +#define max(x,y) ({ \
  55737. + x > y ? x : y; })
  55738. +
  55739. +/**
  55740. + * Descriptor DMA SG Buffer setup structure (SG buffer). This structure is
  55741. + * also used for setting up a buffer for Circular DDMA.
  55742. + */
  55743. +struct _ddma_sg_buffer_setup {
  55744. +#define BS_SG_VAL_DESC_LEN 6
  55745. + /* The OUT EP address */
  55746. + uint8_t bOutEndpointAddress;
  55747. + /* The IN EP address */
  55748. + uint8_t bInEndpointAddress;
  55749. + /* Number of bytes to put between transfer segments (must be DWORD boundaries) */
  55750. + uint8_t bOffset;
  55751. + /* The number of transfer segments (a DMA descriptors per each segment) */
  55752. + uint8_t bCount;
  55753. + /* Size (in byte) of each transfer segment */
  55754. + uint16_t wSize;
  55755. +} __attribute__ ((packed));
  55756. +typedef struct _ddma_sg_buffer_setup ddma_sg_buffer_setup_t;
  55757. +
  55758. +/** Descriptor DMA Concatenation Buffer setup structure */
  55759. +struct _ddma_concat_buffer_setup_hdr {
  55760. +#define BS_CONCAT_VAL_HDR_LEN 4
  55761. + /* The endpoint for which the buffer is to be set up */
  55762. + uint8_t bEndpointAddress;
  55763. + /* The count of descriptors to be used */
  55764. + uint8_t bDescCount;
  55765. + /* The total size of the transfer */
  55766. + uint16_t wSize;
  55767. +} __attribute__ ((packed));
  55768. +typedef struct _ddma_concat_buffer_setup_hdr ddma_concat_buffer_setup_hdr_t;
  55769. +
  55770. +/** Descriptor DMA Concatenation Buffer setup structure */
  55771. +struct _ddma_concat_buffer_setup {
  55772. + /* The SG header */
  55773. + ddma_concat_buffer_setup_hdr_t hdr;
  55774. +
  55775. + /* The XFER sizes pointer (allocated dynamically) */
  55776. + uint16_t *wTxBytes;
  55777. +} __attribute__ ((packed));
  55778. +typedef struct _ddma_concat_buffer_setup ddma_concat_buffer_setup_t;
  55779. +
  55780. +/** Descriptor DMA Alignment Buffer setup structure */
  55781. +struct _ddma_align_buffer_setup {
  55782. +#define BS_ALIGN_VAL_HDR_LEN 2
  55783. + uint8_t bEndpointAddress;
  55784. + uint8_t bAlign;
  55785. +} __attribute__ ((packed));
  55786. +typedef struct _ddma_align_buffer_setup ddma_align_buffer_setup_t;
  55787. +
  55788. +/** Transmit FIFO Size setup structure */
  55789. +struct _tx_fifo_size_setup {
  55790. + uint8_t bEndpointAddress;
  55791. + uint16_t wDepth;
  55792. +} __attribute__ ((packed));
  55793. +typedef struct _tx_fifo_size_setup tx_fifo_size_setup_t;
  55794. +
  55795. +/** Transmit FIFO Size setup structure */
  55796. +struct _rx_fifo_size_setup {
  55797. + uint16_t wDepth;
  55798. +} __attribute__ ((packed));
  55799. +typedef struct _rx_fifo_size_setup rx_fifo_size_setup_t;
  55800. +
  55801. +/**
  55802. + * struct cfi_usb_ctrlrequest - the CFI implementation of the struct usb_ctrlrequest
  55803. + * This structure encapsulates the standard usb_ctrlrequest and adds a pointer
  55804. + * to the data returned in the data stage of a 3-stage Control Write requests.
  55805. + */
  55806. +struct cfi_usb_ctrlrequest {
  55807. + uint8_t bRequestType;
  55808. + uint8_t bRequest;
  55809. + uint16_t wValue;
  55810. + uint16_t wIndex;
  55811. + uint16_t wLength;
  55812. + uint8_t *data;
  55813. +} UPACKED;
  55814. +
  55815. +/*---------------------------------------------------------------------------*/
  55816. +
  55817. +/**
  55818. + * The CFI wrapper of the enabled and activated dwc_otg_pcd_ep structures.
  55819. + * This structure is used to store the buffer setup data for any
  55820. + * enabled endpoint in the PCD.
  55821. + */
  55822. +struct cfi_ep {
  55823. + /* Entry for the list container */
  55824. + dwc_list_link_t lh;
  55825. + /* Pointer to the active PCD endpoint structure */
  55826. + struct dwc_otg_pcd_ep *ep;
  55827. + /* The last descriptor in the chain of DMA descriptors of the endpoint */
  55828. + struct dwc_otg_dma_desc *dma_desc_last;
  55829. + /* The SG feature value */
  55830. + ddma_sg_buffer_setup_t *bm_sg;
  55831. + /* The Circular feature value */
  55832. + ddma_sg_buffer_setup_t *bm_circ;
  55833. + /* The Concatenation feature value */
  55834. + ddma_concat_buffer_setup_t *bm_concat;
  55835. + /* The Alignment feature value */
  55836. + ddma_align_buffer_setup_t *bm_align;
  55837. + /* XFER length */
  55838. + uint32_t xfer_len;
  55839. + /*
  55840. + * Count of DMA descriptors currently used.
  55841. + * The total should not exceed the MAX_DMA_DESCS_PER_EP value
  55842. + * defined in the dwc_otg_cil.h
  55843. + */
  55844. + uint32_t desc_count;
  55845. +};
  55846. +typedef struct cfi_ep cfi_ep_t;
  55847. +
  55848. +typedef struct cfi_dma_buff {
  55849. +#define CFI_IN_BUF_LEN 1024
  55850. +#define CFI_OUT_BUF_LEN 1024
  55851. + dma_addr_t addr;
  55852. + uint8_t *buf;
  55853. +} cfi_dma_buff_t;
  55854. +
  55855. +struct cfiobject;
  55856. +
  55857. +/**
  55858. + * This is the interface for the CFI operations.
  55859. + *
  55860. + * @param ep_enable Called when any endpoint is enabled and activated.
  55861. + * @param release Called when the CFI object is released and it needs to correctly
  55862. + * deallocate the dynamic memory
  55863. + * @param ctrl_write_complete Called when the data stage of the request is complete
  55864. + */
  55865. +typedef struct cfi_ops {
  55866. + int (*ep_enable) (struct cfiobject * cfi, struct dwc_otg_pcd * pcd,
  55867. + struct dwc_otg_pcd_ep * ep);
  55868. + void *(*ep_alloc_buf) (struct cfiobject * cfi, struct dwc_otg_pcd * pcd,
  55869. + struct dwc_otg_pcd_ep * ep, dma_addr_t * dma,
  55870. + unsigned size, gfp_t flags);
  55871. + void (*release) (struct cfiobject * cfi);
  55872. + int (*ctrl_write_complete) (struct cfiobject * cfi,
  55873. + struct dwc_otg_pcd * pcd);
  55874. + void (*build_descriptors) (struct cfiobject * cfi,
  55875. + struct dwc_otg_pcd * pcd,
  55876. + struct dwc_otg_pcd_ep * ep,
  55877. + dwc_otg_pcd_request_t * req);
  55878. +} cfi_ops_t;
  55879. +
  55880. +struct cfiobject {
  55881. + cfi_ops_t ops;
  55882. + struct dwc_otg_pcd *pcd;
  55883. + struct usb_gadget *gadget;
  55884. +
  55885. + /* Buffers used to send/receive CFI-related request data */
  55886. + cfi_dma_buff_t buf_in;
  55887. + cfi_dma_buff_t buf_out;
  55888. +
  55889. + /* CFI specific Control request wrapper */
  55890. + struct cfi_usb_ctrlrequest ctrl_req;
  55891. +
  55892. + /* The list of active EP's in the PCD of type cfi_ep_t */
  55893. + dwc_list_link_t active_eps;
  55894. +
  55895. + /* This flag shall control the propagation of a specific request
  55896. + * to the gadget's processing routines.
  55897. + * 0 - no gadget handling
  55898. + * 1 - the gadget needs to know about this request (w/o completing a status
  55899. + * phase - just return a 0 to the _setup callback)
  55900. + */
  55901. + uint8_t need_gadget_att;
  55902. +
  55903. + /* Flag indicating whether the status IN phase needs to be
  55904. + * completed by the PCD
  55905. + */
  55906. + uint8_t need_status_in_complete;
  55907. +};
  55908. +typedef struct cfiobject cfiobject_t;
  55909. +
  55910. +#define DUMP_MSG
  55911. +
  55912. +#if defined(DUMP_MSG)
  55913. +static inline void dump_msg(const u8 * buf, unsigned int length)
  55914. +{
  55915. + unsigned int start, num, i;
  55916. + char line[52], *p;
  55917. +
  55918. + if (length >= 512)
  55919. + return;
  55920. +
  55921. + start = 0;
  55922. + while (length > 0) {
  55923. + num = min(length, 16u);
  55924. + p = line;
  55925. + for (i = 0; i < num; ++i) {
  55926. + if (i == 8)
  55927. + *p++ = ' ';
  55928. + DWC_SPRINTF(p, " %02x", buf[i]);
  55929. + p += 3;
  55930. + }
  55931. + *p = 0;
  55932. + DWC_DEBUG("%6x: %s\n", start, line);
  55933. + buf += num;
  55934. + start += num;
  55935. + length -= num;
  55936. + }
  55937. +}
  55938. +#else
  55939. +static inline void dump_msg(const u8 * buf, unsigned int length)
  55940. +{
  55941. +}
  55942. +#endif
  55943. +
  55944. +/**
  55945. + * This function returns a pointer to cfi_ep_t object with the addr address.
  55946. + */
  55947. +static inline struct cfi_ep *get_cfi_ep_by_addr(struct cfiobject *cfi,
  55948. + uint8_t addr)
  55949. +{
  55950. + struct cfi_ep *pcfiep;
  55951. + dwc_list_link_t *tmp;
  55952. +
  55953. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  55954. + pcfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  55955. +
  55956. + if (pcfiep->ep->desc->bEndpointAddress == addr) {
  55957. + return pcfiep;
  55958. + }
  55959. + }
  55960. +
  55961. + return NULL;
  55962. +}
  55963. +
  55964. +/**
  55965. + * This function returns a pointer to cfi_ep_t object that matches
  55966. + * the dwc_otg_pcd_ep object.
  55967. + */
  55968. +static inline struct cfi_ep *get_cfi_ep_by_pcd_ep(struct cfiobject *cfi,
  55969. + struct dwc_otg_pcd_ep *ep)
  55970. +{
  55971. + struct cfi_ep *pcfiep = NULL;
  55972. + dwc_list_link_t *tmp;
  55973. +
  55974. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  55975. + pcfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  55976. + if (pcfiep->ep == ep) {
  55977. + return pcfiep;
  55978. + }
  55979. + }
  55980. + return NULL;
  55981. +}
  55982. +
  55983. +int cfi_setup(struct dwc_otg_pcd *pcd, struct cfi_usb_ctrlrequest *ctrl);
  55984. +
  55985. +#endif /* (__DWC_OTG_CFI_H__) */
  55986. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_cil.c linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_cil.c
  55987. --- linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_cil.c 1970-01-01 01:00:00.000000000 +0100
  55988. +++ linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_cil.c 2014-08-06 16:50:14.797964694 +0200
  55989. @@ -0,0 +1,7151 @@
  55990. +/* ==========================================================================
  55991. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil.c $
  55992. + * $Revision: #191 $
  55993. + * $Date: 2012/08/10 $
  55994. + * $Change: 2047372 $
  55995. + *
  55996. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  55997. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  55998. + * otherwise expressly agreed to in writing between Synopsys and you.
  55999. + *
  56000. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  56001. + * any End User Software License Agreement or Agreement for Licensed Product
  56002. + * with Synopsys or any supplement thereto. You are permitted to use and
  56003. + * redistribute this Software in source and binary forms, with or without
  56004. + * modification, provided that redistributions of source code must retain this
  56005. + * notice. You may not view, use, disclose, copy or distribute this file or
  56006. + * any information contained herein except pursuant to this license grant from
  56007. + * Synopsys. If you do not agree with this notice, including the disclaimer
  56008. + * below, then you are not authorized to use the Software.
  56009. + *
  56010. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  56011. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  56012. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  56013. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  56014. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  56015. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  56016. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  56017. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  56018. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  56019. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  56020. + * DAMAGE.
  56021. + * ========================================================================== */
  56022. +
  56023. +/** @file
  56024. + *
  56025. + * The Core Interface Layer provides basic services for accessing and
  56026. + * managing the DWC_otg hardware. These services are used by both the
  56027. + * Host Controller Driver and the Peripheral Controller Driver.
  56028. + *
  56029. + * The CIL manages the memory map for the core so that the HCD and PCD
  56030. + * don't have to do this separately. It also handles basic tasks like
  56031. + * reading/writing the registers and data FIFOs in the controller.
  56032. + * Some of the data access functions provide encapsulation of several
  56033. + * operations required to perform a task, such as writing multiple
  56034. + * registers to start a transfer. Finally, the CIL performs basic
  56035. + * services that are not specific to either the host or device modes
  56036. + * of operation. These services include management of the OTG Host
  56037. + * Negotiation Protocol (HNP) and Session Request Protocol (SRP). A
  56038. + * Diagnostic API is also provided to allow testing of the controller
  56039. + * hardware.
  56040. + *
  56041. + * The Core Interface Layer has the following requirements:
  56042. + * - Provides basic controller operations.
  56043. + * - Minimal use of OS services.
  56044. + * - The OS services used will be abstracted by using inline functions
  56045. + * or macros.
  56046. + *
  56047. + */
  56048. +
  56049. +#include "dwc_os.h"
  56050. +#include "dwc_otg_regs.h"
  56051. +#include "dwc_otg_cil.h"
  56052. +
  56053. +static int dwc_otg_setup_params(dwc_otg_core_if_t * core_if);
  56054. +
  56055. +/**
  56056. + * This function is called to initialize the DWC_otg CSR data
  56057. + * structures. The register addresses in the device and host
  56058. + * structures are initialized from the base address supplied by the
  56059. + * caller. The calling function must make the OS calls to get the
  56060. + * base address of the DWC_otg controller registers. The core_params
  56061. + * argument holds the parameters that specify how the core should be
  56062. + * configured.
  56063. + *
  56064. + * @param reg_base_addr Base address of DWC_otg core registers
  56065. + *
  56066. + */
  56067. +dwc_otg_core_if_t *dwc_otg_cil_init(const uint32_t * reg_base_addr)
  56068. +{
  56069. + dwc_otg_core_if_t *core_if = 0;
  56070. + dwc_otg_dev_if_t *dev_if = 0;
  56071. + dwc_otg_host_if_t *host_if = 0;
  56072. + uint8_t *reg_base = (uint8_t *) reg_base_addr;
  56073. + int i = 0;
  56074. +
  56075. + DWC_DEBUGPL(DBG_CILV, "%s(%p)\n", __func__, reg_base_addr);
  56076. +
  56077. + core_if = DWC_ALLOC(sizeof(dwc_otg_core_if_t));
  56078. +
  56079. + if (core_if == NULL) {
  56080. + DWC_DEBUGPL(DBG_CIL,
  56081. + "Allocation of dwc_otg_core_if_t failed\n");
  56082. + return 0;
  56083. + }
  56084. + core_if->core_global_regs = (dwc_otg_core_global_regs_t *) reg_base;
  56085. +
  56086. + /*
  56087. + * Allocate the Device Mode structures.
  56088. + */
  56089. + dev_if = DWC_ALLOC(sizeof(dwc_otg_dev_if_t));
  56090. +
  56091. + if (dev_if == NULL) {
  56092. + DWC_DEBUGPL(DBG_CIL, "Allocation of dwc_otg_dev_if_t failed\n");
  56093. + DWC_FREE(core_if);
  56094. + return 0;
  56095. + }
  56096. +
  56097. + dev_if->dev_global_regs =
  56098. + (dwc_otg_device_global_regs_t *) (reg_base +
  56099. + DWC_DEV_GLOBAL_REG_OFFSET);
  56100. +
  56101. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  56102. + dev_if->in_ep_regs[i] = (dwc_otg_dev_in_ep_regs_t *)
  56103. + (reg_base + DWC_DEV_IN_EP_REG_OFFSET +
  56104. + (i * DWC_EP_REG_OFFSET));
  56105. +
  56106. + dev_if->out_ep_regs[i] = (dwc_otg_dev_out_ep_regs_t *)
  56107. + (reg_base + DWC_DEV_OUT_EP_REG_OFFSET +
  56108. + (i * DWC_EP_REG_OFFSET));
  56109. + DWC_DEBUGPL(DBG_CILV, "in_ep_regs[%d]->diepctl=%p\n",
  56110. + i, &dev_if->in_ep_regs[i]->diepctl);
  56111. + DWC_DEBUGPL(DBG_CILV, "out_ep_regs[%d]->doepctl=%p\n",
  56112. + i, &dev_if->out_ep_regs[i]->doepctl);
  56113. + }
  56114. +
  56115. + dev_if->speed = 0; // unknown
  56116. +
  56117. + core_if->dev_if = dev_if;
  56118. +
  56119. + /*
  56120. + * Allocate the Host Mode structures.
  56121. + */
  56122. + host_if = DWC_ALLOC(sizeof(dwc_otg_host_if_t));
  56123. +
  56124. + if (host_if == NULL) {
  56125. + DWC_DEBUGPL(DBG_CIL,
  56126. + "Allocation of dwc_otg_host_if_t failed\n");
  56127. + DWC_FREE(dev_if);
  56128. + DWC_FREE(core_if);
  56129. + return 0;
  56130. + }
  56131. +
  56132. + host_if->host_global_regs = (dwc_otg_host_global_regs_t *)
  56133. + (reg_base + DWC_OTG_HOST_GLOBAL_REG_OFFSET);
  56134. +
  56135. + host_if->hprt0 =
  56136. + (uint32_t *) (reg_base + DWC_OTG_HOST_PORT_REGS_OFFSET);
  56137. +
  56138. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  56139. + host_if->hc_regs[i] = (dwc_otg_hc_regs_t *)
  56140. + (reg_base + DWC_OTG_HOST_CHAN_REGS_OFFSET +
  56141. + (i * DWC_OTG_CHAN_REGS_OFFSET));
  56142. + DWC_DEBUGPL(DBG_CILV, "hc_reg[%d]->hcchar=%p\n",
  56143. + i, &host_if->hc_regs[i]->hcchar);
  56144. + }
  56145. +
  56146. + host_if->num_host_channels = MAX_EPS_CHANNELS;
  56147. + core_if->host_if = host_if;
  56148. +
  56149. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  56150. + core_if->data_fifo[i] =
  56151. + (uint32_t *) (reg_base + DWC_OTG_DATA_FIFO_OFFSET +
  56152. + (i * DWC_OTG_DATA_FIFO_SIZE));
  56153. + DWC_DEBUGPL(DBG_CILV, "data_fifo[%d]=0x%08lx\n",
  56154. + i, (unsigned long)core_if->data_fifo[i]);
  56155. + }
  56156. +
  56157. + core_if->pcgcctl = (uint32_t *) (reg_base + DWC_OTG_PCGCCTL_OFFSET);
  56158. +
  56159. + /* Initiate lx_state to L3 disconnected state */
  56160. + core_if->lx_state = DWC_OTG_L3;
  56161. + /*
  56162. + * Store the contents of the hardware configuration registers here for
  56163. + * easy access later.
  56164. + */
  56165. + core_if->hwcfg1.d32 =
  56166. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg1);
  56167. + core_if->hwcfg2.d32 =
  56168. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg2);
  56169. + core_if->hwcfg3.d32 =
  56170. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg3);
  56171. + core_if->hwcfg4.d32 =
  56172. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg4);
  56173. +
  56174. + /* Force host mode to get HPTXFSIZ exact power on value */
  56175. + {
  56176. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  56177. + gusbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  56178. + gusbcfg.b.force_host_mode = 1;
  56179. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gusbcfg.d32);
  56180. + dwc_mdelay(100);
  56181. + core_if->hptxfsiz.d32 =
  56182. + DWC_READ_REG32(&core_if->core_global_regs->hptxfsiz);
  56183. + gusbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  56184. + gusbcfg.b.force_host_mode = 0;
  56185. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gusbcfg.d32);
  56186. + dwc_mdelay(100);
  56187. + }
  56188. +
  56189. + DWC_DEBUGPL(DBG_CILV, "hwcfg1=%08x\n", core_if->hwcfg1.d32);
  56190. + DWC_DEBUGPL(DBG_CILV, "hwcfg2=%08x\n", core_if->hwcfg2.d32);
  56191. + DWC_DEBUGPL(DBG_CILV, "hwcfg3=%08x\n", core_if->hwcfg3.d32);
  56192. + DWC_DEBUGPL(DBG_CILV, "hwcfg4=%08x\n", core_if->hwcfg4.d32);
  56193. +
  56194. + core_if->hcfg.d32 =
  56195. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  56196. + core_if->dcfg.d32 =
  56197. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  56198. +
  56199. + DWC_DEBUGPL(DBG_CILV, "hcfg=%08x\n", core_if->hcfg.d32);
  56200. + DWC_DEBUGPL(DBG_CILV, "dcfg=%08x\n", core_if->dcfg.d32);
  56201. +
  56202. + DWC_DEBUGPL(DBG_CILV, "op_mode=%0x\n", core_if->hwcfg2.b.op_mode);
  56203. + DWC_DEBUGPL(DBG_CILV, "arch=%0x\n", core_if->hwcfg2.b.architecture);
  56204. + DWC_DEBUGPL(DBG_CILV, "num_dev_ep=%d\n", core_if->hwcfg2.b.num_dev_ep);
  56205. + DWC_DEBUGPL(DBG_CILV, "num_host_chan=%d\n",
  56206. + core_if->hwcfg2.b.num_host_chan);
  56207. + DWC_DEBUGPL(DBG_CILV, "nonperio_tx_q_depth=0x%0x\n",
  56208. + core_if->hwcfg2.b.nonperio_tx_q_depth);
  56209. + DWC_DEBUGPL(DBG_CILV, "host_perio_tx_q_depth=0x%0x\n",
  56210. + core_if->hwcfg2.b.host_perio_tx_q_depth);
  56211. + DWC_DEBUGPL(DBG_CILV, "dev_token_q_depth=0x%0x\n",
  56212. + core_if->hwcfg2.b.dev_token_q_depth);
  56213. +
  56214. + DWC_DEBUGPL(DBG_CILV, "Total FIFO SZ=%d\n",
  56215. + core_if->hwcfg3.b.dfifo_depth);
  56216. + DWC_DEBUGPL(DBG_CILV, "xfer_size_cntr_width=%0x\n",
  56217. + core_if->hwcfg3.b.xfer_size_cntr_width);
  56218. +
  56219. + /*
  56220. + * Set the SRP sucess bit for FS-I2c
  56221. + */
  56222. + core_if->srp_success = 0;
  56223. + core_if->srp_timer_started = 0;
  56224. +
  56225. + /*
  56226. + * Create new workqueue and init works
  56227. + */
  56228. + core_if->wq_otg = DWC_WORKQ_ALLOC("dwc_otg");
  56229. + if (core_if->wq_otg == 0) {
  56230. + DWC_WARN("DWC_WORKQ_ALLOC failed\n");
  56231. + DWC_FREE(host_if);
  56232. + DWC_FREE(dev_if);
  56233. + DWC_FREE(core_if);
  56234. + return 0;
  56235. + }
  56236. +
  56237. + core_if->snpsid = DWC_READ_REG32(&core_if->core_global_regs->gsnpsid);
  56238. +
  56239. + DWC_PRINTF("Core Release: %x.%x%x%x\n",
  56240. + (core_if->snpsid >> 12 & 0xF),
  56241. + (core_if->snpsid >> 8 & 0xF),
  56242. + (core_if->snpsid >> 4 & 0xF), (core_if->snpsid & 0xF));
  56243. +
  56244. + core_if->wkp_timer = DWC_TIMER_ALLOC("Wake Up Timer",
  56245. + w_wakeup_detected, core_if);
  56246. + if (core_if->wkp_timer == 0) {
  56247. + DWC_WARN("DWC_TIMER_ALLOC failed\n");
  56248. + DWC_FREE(host_if);
  56249. + DWC_FREE(dev_if);
  56250. + DWC_WORKQ_FREE(core_if->wq_otg);
  56251. + DWC_FREE(core_if);
  56252. + return 0;
  56253. + }
  56254. +
  56255. + if (dwc_otg_setup_params(core_if)) {
  56256. + DWC_WARN("Error while setting core params\n");
  56257. + }
  56258. +
  56259. + core_if->hibernation_suspend = 0;
  56260. +
  56261. + /** ADP initialization */
  56262. + dwc_otg_adp_init(core_if);
  56263. +
  56264. + return core_if;
  56265. +}
  56266. +
  56267. +/**
  56268. + * This function frees the structures allocated by dwc_otg_cil_init().
  56269. + *
  56270. + * @param core_if The core interface pointer returned from
  56271. + * dwc_otg_cil_init().
  56272. + *
  56273. + */
  56274. +void dwc_otg_cil_remove(dwc_otg_core_if_t * core_if)
  56275. +{
  56276. + dctl_data_t dctl = {.d32 = 0 };
  56277. + DWC_DEBUGPL(DBG_CILV, "%s(%p)\n", __func__, core_if);
  56278. +
  56279. + /* Disable all interrupts */
  56280. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, 1, 0);
  56281. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, 0);
  56282. +
  56283. + dctl.b.sftdiscon = 1;
  56284. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  56285. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0,
  56286. + dctl.d32);
  56287. + }
  56288. +
  56289. + if (core_if->wq_otg) {
  56290. + DWC_WORKQ_WAIT_WORK_DONE(core_if->wq_otg, 500);
  56291. + DWC_WORKQ_FREE(core_if->wq_otg);
  56292. + }
  56293. + if (core_if->dev_if) {
  56294. + DWC_FREE(core_if->dev_if);
  56295. + }
  56296. + if (core_if->host_if) {
  56297. + DWC_FREE(core_if->host_if);
  56298. + }
  56299. +
  56300. + /** Remove ADP Stuff */
  56301. + dwc_otg_adp_remove(core_if);
  56302. + if (core_if->core_params) {
  56303. + DWC_FREE(core_if->core_params);
  56304. + }
  56305. + if (core_if->wkp_timer) {
  56306. + DWC_TIMER_FREE(core_if->wkp_timer);
  56307. + }
  56308. + if (core_if->srp_timer) {
  56309. + DWC_TIMER_FREE(core_if->srp_timer);
  56310. + }
  56311. + DWC_FREE(core_if);
  56312. +}
  56313. +
  56314. +/**
  56315. + * This function enables the controller's Global Interrupt in the AHB Config
  56316. + * register.
  56317. + *
  56318. + * @param core_if Programming view of DWC_otg controller.
  56319. + */
  56320. +void dwc_otg_enable_global_interrupts(dwc_otg_core_if_t * core_if)
  56321. +{
  56322. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  56323. + ahbcfg.b.glblintrmsk = 1; /* Enable interrupts */
  56324. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, 0, ahbcfg.d32);
  56325. +}
  56326. +
  56327. +/**
  56328. + * This function disables the controller's Global Interrupt in the AHB Config
  56329. + * register.
  56330. + *
  56331. + * @param core_if Programming view of DWC_otg controller.
  56332. + */
  56333. +void dwc_otg_disable_global_interrupts(dwc_otg_core_if_t * core_if)
  56334. +{
  56335. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  56336. + ahbcfg.b.glblintrmsk = 1; /* Disable interrupts */
  56337. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, ahbcfg.d32, 0);
  56338. +}
  56339. +
  56340. +/**
  56341. + * This function initializes the commmon interrupts, used in both
  56342. + * device and host modes.
  56343. + *
  56344. + * @param core_if Programming view of the DWC_otg controller
  56345. + *
  56346. + */
  56347. +static void dwc_otg_enable_common_interrupts(dwc_otg_core_if_t * core_if)
  56348. +{
  56349. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  56350. + gintmsk_data_t intr_mask = {.d32 = 0 };
  56351. +
  56352. + /* Clear any pending OTG Interrupts */
  56353. + DWC_WRITE_REG32(&global_regs->gotgint, 0xFFFFFFFF);
  56354. +
  56355. + /* Clear any pending interrupts */
  56356. + DWC_WRITE_REG32(&global_regs->gintsts, 0xFFFFFFFF);
  56357. +
  56358. + /*
  56359. + * Enable the interrupts in the GINTMSK.
  56360. + */
  56361. + intr_mask.b.modemismatch = 1;
  56362. + intr_mask.b.otgintr = 1;
  56363. +
  56364. + if (!core_if->dma_enable) {
  56365. + intr_mask.b.rxstsqlvl = 1;
  56366. + }
  56367. +
  56368. + intr_mask.b.conidstschng = 1;
  56369. + intr_mask.b.wkupintr = 1;
  56370. + intr_mask.b.disconnect = 0;
  56371. + intr_mask.b.usbsuspend = 1;
  56372. + intr_mask.b.sessreqintr = 1;
  56373. +#ifdef CONFIG_USB_DWC_OTG_LPM
  56374. + if (core_if->core_params->lpm_enable) {
  56375. + intr_mask.b.lpmtranrcvd = 1;
  56376. + }
  56377. +#endif
  56378. + DWC_WRITE_REG32(&global_regs->gintmsk, intr_mask.d32);
  56379. +}
  56380. +
  56381. +/*
  56382. + * The restore operation is modified to support Synopsys Emulated Powerdown and
  56383. + * Hibernation. This function is for exiting from Device mode hibernation by
  56384. + * Host Initiated Resume/Reset and Device Initiated Remote-Wakeup.
  56385. + * @param core_if Programming view of DWC_otg controller.
  56386. + * @param rem_wakeup - indicates whether resume is initiated by Device or Host.
  56387. + * @param reset - indicates whether resume is initiated by Reset.
  56388. + */
  56389. +int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
  56390. + int rem_wakeup, int reset)
  56391. +{
  56392. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  56393. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  56394. + dctl_data_t dctl = {.d32 = 0 };
  56395. +
  56396. + int timeout = 2000;
  56397. +
  56398. + if (!core_if->hibernation_suspend) {
  56399. + DWC_PRINTF("Already exited from Hibernation\n");
  56400. + return 1;
  56401. + }
  56402. +
  56403. + DWC_DEBUGPL(DBG_PCD, "%s called\n", __FUNCTION__);
  56404. + /* Switch-on voltage to the core */
  56405. + gpwrdn.b.pwrdnswtch = 1;
  56406. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56407. + dwc_udelay(10);
  56408. +
  56409. + /* Reset core */
  56410. + gpwrdn.d32 = 0;
  56411. + gpwrdn.b.pwrdnrstn = 1;
  56412. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56413. + dwc_udelay(10);
  56414. +
  56415. + /* Assert Restore signal */
  56416. + gpwrdn.d32 = 0;
  56417. + gpwrdn.b.restore = 1;
  56418. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  56419. + dwc_udelay(10);
  56420. +
  56421. + /* Disable power clamps */
  56422. + gpwrdn.d32 = 0;
  56423. + gpwrdn.b.pwrdnclmp = 1;
  56424. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56425. +
  56426. + if (rem_wakeup) {
  56427. + dwc_udelay(70);
  56428. + }
  56429. +
  56430. + /* Deassert Reset core */
  56431. + gpwrdn.d32 = 0;
  56432. + gpwrdn.b.pwrdnrstn = 1;
  56433. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  56434. + dwc_udelay(10);
  56435. +
  56436. + /* Disable PMU interrupt */
  56437. + gpwrdn.d32 = 0;
  56438. + gpwrdn.b.pmuintsel = 1;
  56439. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56440. +
  56441. + /* Mask interrupts from gpwrdn */
  56442. + gpwrdn.d32 = 0;
  56443. + gpwrdn.b.connect_det_msk = 1;
  56444. + gpwrdn.b.srp_det_msk = 1;
  56445. + gpwrdn.b.disconn_det_msk = 1;
  56446. + gpwrdn.b.rst_det_msk = 1;
  56447. + gpwrdn.b.lnstchng_msk = 1;
  56448. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56449. +
  56450. + /* Indicates that we are going out from hibernation */
  56451. + core_if->hibernation_suspend = 0;
  56452. +
  56453. + /*
  56454. + * Set Restore Essential Regs bit in PCGCCTL register, restore_mode = 1
  56455. + * indicates restore from remote_wakeup
  56456. + */
  56457. + restore_essential_regs(core_if, rem_wakeup, 0);
  56458. +
  56459. + /*
  56460. + * Wait a little for seeing new value of variable hibernation_suspend if
  56461. + * Restore done interrupt received before polling
  56462. + */
  56463. + dwc_udelay(10);
  56464. +
  56465. + if (core_if->hibernation_suspend == 0) {
  56466. + /*
  56467. + * Wait For Restore_done Interrupt. This mechanism of polling the
  56468. + * interrupt is introduced to avoid any possible race conditions
  56469. + */
  56470. + do {
  56471. + gintsts_data_t gintsts;
  56472. + gintsts.d32 =
  56473. + DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  56474. + if (gintsts.b.restoredone) {
  56475. + gintsts.d32 = 0;
  56476. + gintsts.b.restoredone = 1;
  56477. + DWC_WRITE_REG32(&core_if->core_global_regs->
  56478. + gintsts, gintsts.d32);
  56479. + DWC_PRINTF("Restore Done Interrupt seen\n");
  56480. + break;
  56481. + }
  56482. + dwc_udelay(10);
  56483. + } while (--timeout);
  56484. + if (!timeout) {
  56485. + DWC_PRINTF("Restore Done interrupt wasn't generated here\n");
  56486. + }
  56487. + }
  56488. + /* Clear all pending interupts */
  56489. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  56490. +
  56491. + /* De-assert Restore */
  56492. + gpwrdn.d32 = 0;
  56493. + gpwrdn.b.restore = 1;
  56494. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56495. + dwc_udelay(10);
  56496. +
  56497. + if (!rem_wakeup) {
  56498. + pcgcctl.d32 = 0;
  56499. + pcgcctl.b.rstpdwnmodule = 1;
  56500. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  56501. + }
  56502. +
  56503. + /* Restore GUSBCFG and DCFG */
  56504. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg,
  56505. + core_if->gr_backup->gusbcfg_local);
  56506. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg,
  56507. + core_if->dr_backup->dcfg);
  56508. +
  56509. + /* De-assert Wakeup Logic */
  56510. + gpwrdn.d32 = 0;
  56511. + gpwrdn.b.pmuactv = 1;
  56512. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56513. + dwc_udelay(10);
  56514. +
  56515. + if (!rem_wakeup) {
  56516. + /* Set Device programming done bit */
  56517. + dctl.b.pwronprgdone = 1;
  56518. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  56519. + } else {
  56520. + /* Start Remote Wakeup Signaling */
  56521. + dctl.d32 = core_if->dr_backup->dctl;
  56522. + dctl.b.rmtwkupsig = 1;
  56523. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  56524. + }
  56525. +
  56526. + dwc_mdelay(2);
  56527. + /* Clear all pending interupts */
  56528. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  56529. +
  56530. + /* Restore global registers */
  56531. + dwc_otg_restore_global_regs(core_if);
  56532. + /* Restore device global registers */
  56533. + dwc_otg_restore_dev_regs(core_if, rem_wakeup);
  56534. +
  56535. + if (rem_wakeup) {
  56536. + dwc_mdelay(7);
  56537. + dctl.d32 = 0;
  56538. + dctl.b.rmtwkupsig = 1;
  56539. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, 0);
  56540. + }
  56541. +
  56542. + core_if->hibernation_suspend = 0;
  56543. + /* The core will be in ON STATE */
  56544. + core_if->lx_state = DWC_OTG_L0;
  56545. + DWC_PRINTF("Hibernation recovery completes here\n");
  56546. +
  56547. + return 1;
  56548. +}
  56549. +
  56550. +/*
  56551. + * The restore operation is modified to support Synopsys Emulated Powerdown and
  56552. + * Hibernation. This function is for exiting from Host mode hibernation by
  56553. + * Host Initiated Resume/Reset and Device Initiated Remote-Wakeup.
  56554. + * @param core_if Programming view of DWC_otg controller.
  56555. + * @param rem_wakeup - indicates whether resume is initiated by Device or Host.
  56556. + * @param reset - indicates whether resume is initiated by Reset.
  56557. + */
  56558. +int dwc_otg_host_hibernation_restore(dwc_otg_core_if_t * core_if,
  56559. + int rem_wakeup, int reset)
  56560. +{
  56561. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  56562. + hprt0_data_t hprt0 = {.d32 = 0 };
  56563. +
  56564. + int timeout = 2000;
  56565. +
  56566. + DWC_DEBUGPL(DBG_HCD, "%s called\n", __FUNCTION__);
  56567. + /* Switch-on voltage to the core */
  56568. + gpwrdn.b.pwrdnswtch = 1;
  56569. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56570. + dwc_udelay(10);
  56571. +
  56572. + /* Reset core */
  56573. + gpwrdn.d32 = 0;
  56574. + gpwrdn.b.pwrdnrstn = 1;
  56575. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56576. + dwc_udelay(10);
  56577. +
  56578. + /* Assert Restore signal */
  56579. + gpwrdn.d32 = 0;
  56580. + gpwrdn.b.restore = 1;
  56581. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  56582. + dwc_udelay(10);
  56583. +
  56584. + /* Disable power clamps */
  56585. + gpwrdn.d32 = 0;
  56586. + gpwrdn.b.pwrdnclmp = 1;
  56587. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56588. +
  56589. + if (!rem_wakeup) {
  56590. + dwc_udelay(50);
  56591. + }
  56592. +
  56593. + /* Deassert Reset core */
  56594. + gpwrdn.d32 = 0;
  56595. + gpwrdn.b.pwrdnrstn = 1;
  56596. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  56597. + dwc_udelay(10);
  56598. +
  56599. + /* Disable PMU interrupt */
  56600. + gpwrdn.d32 = 0;
  56601. + gpwrdn.b.pmuintsel = 1;
  56602. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56603. +
  56604. + gpwrdn.d32 = 0;
  56605. + gpwrdn.b.connect_det_msk = 1;
  56606. + gpwrdn.b.srp_det_msk = 1;
  56607. + gpwrdn.b.disconn_det_msk = 1;
  56608. + gpwrdn.b.rst_det_msk = 1;
  56609. + gpwrdn.b.lnstchng_msk = 1;
  56610. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56611. +
  56612. + /* Indicates that we are going out from hibernation */
  56613. + core_if->hibernation_suspend = 0;
  56614. +
  56615. + /* Set Restore Essential Regs bit in PCGCCTL register */
  56616. + restore_essential_regs(core_if, rem_wakeup, 1);
  56617. +
  56618. + /* Wait a little for seeing new value of variable hibernation_suspend if
  56619. + * Restore done interrupt received before polling */
  56620. + dwc_udelay(10);
  56621. +
  56622. + if (core_if->hibernation_suspend == 0) {
  56623. + /* Wait For Restore_done Interrupt. This mechanism of polling the
  56624. + * interrupt is introduced to avoid any possible race conditions
  56625. + */
  56626. + do {
  56627. + gintsts_data_t gintsts;
  56628. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  56629. + if (gintsts.b.restoredone) {
  56630. + gintsts.d32 = 0;
  56631. + gintsts.b.restoredone = 1;
  56632. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  56633. + DWC_DEBUGPL(DBG_HCD,"Restore Done Interrupt seen\n");
  56634. + break;
  56635. + }
  56636. + dwc_udelay(10);
  56637. + } while (--timeout);
  56638. + if (!timeout) {
  56639. + DWC_WARN("Restore Done interrupt wasn't generated\n");
  56640. + }
  56641. + }
  56642. +
  56643. + /* Set the flag's value to 0 again after receiving restore done interrupt */
  56644. + core_if->hibernation_suspend = 0;
  56645. +
  56646. + /* This step is not described in functional spec but if not wait for this
  56647. + * delay, mismatch interrupts occurred because just after restore core is
  56648. + * in Device mode(gintsts.curmode == 0) */
  56649. + dwc_mdelay(100);
  56650. +
  56651. + /* Clear all pending interrupts */
  56652. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  56653. +
  56654. + /* De-assert Restore */
  56655. + gpwrdn.d32 = 0;
  56656. + gpwrdn.b.restore = 1;
  56657. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56658. + dwc_udelay(10);
  56659. +
  56660. + /* Restore GUSBCFG and HCFG */
  56661. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg,
  56662. + core_if->gr_backup->gusbcfg_local);
  56663. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg,
  56664. + core_if->hr_backup->hcfg_local);
  56665. +
  56666. + /* De-assert Wakeup Logic */
  56667. + gpwrdn.d32 = 0;
  56668. + gpwrdn.b.pmuactv = 1;
  56669. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56670. + dwc_udelay(10);
  56671. +
  56672. + /* Start the Resume operation by programming HPRT0 */
  56673. + hprt0.d32 = core_if->hr_backup->hprt0_local;
  56674. + hprt0.b.prtpwr = 1;
  56675. + hprt0.b.prtena = 0;
  56676. + hprt0.b.prtsusp = 0;
  56677. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  56678. +
  56679. + DWC_PRINTF("Resume Starts Now\n");
  56680. + if (!reset) { // Indicates it is Resume Operation
  56681. + hprt0.d32 = core_if->hr_backup->hprt0_local;
  56682. + hprt0.b.prtres = 1;
  56683. + hprt0.b.prtpwr = 1;
  56684. + hprt0.b.prtena = 0;
  56685. + hprt0.b.prtsusp = 0;
  56686. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  56687. +
  56688. + if (!rem_wakeup)
  56689. + hprt0.b.prtres = 0;
  56690. + /* Wait for Resume time and then program HPRT again */
  56691. + dwc_mdelay(100);
  56692. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  56693. +
  56694. + } else { // Indicates it is Reset Operation
  56695. + hprt0.d32 = core_if->hr_backup->hprt0_local;
  56696. + hprt0.b.prtrst = 1;
  56697. + hprt0.b.prtpwr = 1;
  56698. + hprt0.b.prtena = 0;
  56699. + hprt0.b.prtsusp = 0;
  56700. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  56701. + /* Wait for Reset time and then program HPRT again */
  56702. + dwc_mdelay(60);
  56703. + hprt0.b.prtrst = 0;
  56704. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  56705. + }
  56706. + /* Clear all interrupt status */
  56707. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  56708. + hprt0.b.prtconndet = 1;
  56709. + hprt0.b.prtenchng = 1;
  56710. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  56711. +
  56712. + /* Clear all pending interupts */
  56713. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  56714. +
  56715. + /* Restore global registers */
  56716. + dwc_otg_restore_global_regs(core_if);
  56717. + /* Restore host global registers */
  56718. + dwc_otg_restore_host_regs(core_if, reset);
  56719. +
  56720. + /* The core will be in ON STATE */
  56721. + core_if->lx_state = DWC_OTG_L0;
  56722. + DWC_PRINTF("Hibernation recovery is complete here\n");
  56723. + return 0;
  56724. +}
  56725. +
  56726. +/** Saves some register values into system memory. */
  56727. +int dwc_otg_save_global_regs(dwc_otg_core_if_t * core_if)
  56728. +{
  56729. + struct dwc_otg_global_regs_backup *gr;
  56730. + int i;
  56731. +
  56732. + gr = core_if->gr_backup;
  56733. + if (!gr) {
  56734. + gr = DWC_ALLOC(sizeof(*gr));
  56735. + if (!gr) {
  56736. + return -DWC_E_NO_MEMORY;
  56737. + }
  56738. + core_if->gr_backup = gr;
  56739. + }
  56740. +
  56741. + gr->gotgctl_local = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  56742. + gr->gintmsk_local = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  56743. + gr->gahbcfg_local = DWC_READ_REG32(&core_if->core_global_regs->gahbcfg);
  56744. + gr->gusbcfg_local = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  56745. + gr->grxfsiz_local = DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  56746. + gr->gnptxfsiz_local = DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz);
  56747. + gr->hptxfsiz_local = DWC_READ_REG32(&core_if->core_global_regs->hptxfsiz);
  56748. +#ifdef CONFIG_USB_DWC_OTG_LPM
  56749. + gr->glpmcfg_local = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  56750. +#endif
  56751. + gr->gi2cctl_local = DWC_READ_REG32(&core_if->core_global_regs->gi2cctl);
  56752. + gr->pcgcctl_local = DWC_READ_REG32(core_if->pcgcctl);
  56753. + gr->gdfifocfg_local =
  56754. + DWC_READ_REG32(&core_if->core_global_regs->gdfifocfg);
  56755. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  56756. + gr->dtxfsiz_local[i] =
  56757. + DWC_READ_REG32(&(core_if->core_global_regs->dtxfsiz[i]));
  56758. + }
  56759. +
  56760. + DWC_DEBUGPL(DBG_ANY, "===========Backing Global registers==========\n");
  56761. + DWC_DEBUGPL(DBG_ANY, "Backed up gotgctl = %08x\n", gr->gotgctl_local);
  56762. + DWC_DEBUGPL(DBG_ANY, "Backed up gintmsk = %08x\n", gr->gintmsk_local);
  56763. + DWC_DEBUGPL(DBG_ANY, "Backed up gahbcfg = %08x\n", gr->gahbcfg_local);
  56764. + DWC_DEBUGPL(DBG_ANY, "Backed up gusbcfg = %08x\n", gr->gusbcfg_local);
  56765. + DWC_DEBUGPL(DBG_ANY, "Backed up grxfsiz = %08x\n", gr->grxfsiz_local);
  56766. + DWC_DEBUGPL(DBG_ANY, "Backed up gnptxfsiz = %08x\n",
  56767. + gr->gnptxfsiz_local);
  56768. + DWC_DEBUGPL(DBG_ANY, "Backed up hptxfsiz = %08x\n",
  56769. + gr->hptxfsiz_local);
  56770. +#ifdef CONFIG_USB_DWC_OTG_LPM
  56771. + DWC_DEBUGPL(DBG_ANY, "Backed up glpmcfg = %08x\n", gr->glpmcfg_local);
  56772. +#endif
  56773. + DWC_DEBUGPL(DBG_ANY, "Backed up gi2cctl = %08x\n", gr->gi2cctl_local);
  56774. + DWC_DEBUGPL(DBG_ANY, "Backed up pcgcctl = %08x\n", gr->pcgcctl_local);
  56775. + DWC_DEBUGPL(DBG_ANY,"Backed up gdfifocfg = %08x\n",gr->gdfifocfg_local);
  56776. +
  56777. + return 0;
  56778. +}
  56779. +
  56780. +/** Saves GINTMSK register before setting the msk bits. */
  56781. +int dwc_otg_save_gintmsk_reg(dwc_otg_core_if_t * core_if)
  56782. +{
  56783. + struct dwc_otg_global_regs_backup *gr;
  56784. +
  56785. + gr = core_if->gr_backup;
  56786. + if (!gr) {
  56787. + gr = DWC_ALLOC(sizeof(*gr));
  56788. + if (!gr) {
  56789. + return -DWC_E_NO_MEMORY;
  56790. + }
  56791. + core_if->gr_backup = gr;
  56792. + }
  56793. +
  56794. + gr->gintmsk_local = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  56795. +
  56796. + DWC_DEBUGPL(DBG_ANY,"=============Backing GINTMSK registers============\n");
  56797. + DWC_DEBUGPL(DBG_ANY, "Backed up gintmsk = %08x\n", gr->gintmsk_local);
  56798. +
  56799. + return 0;
  56800. +}
  56801. +
  56802. +int dwc_otg_save_dev_regs(dwc_otg_core_if_t * core_if)
  56803. +{
  56804. + struct dwc_otg_dev_regs_backup *dr;
  56805. + int i;
  56806. +
  56807. + dr = core_if->dr_backup;
  56808. + if (!dr) {
  56809. + dr = DWC_ALLOC(sizeof(*dr));
  56810. + if (!dr) {
  56811. + return -DWC_E_NO_MEMORY;
  56812. + }
  56813. + core_if->dr_backup = dr;
  56814. + }
  56815. +
  56816. + dr->dcfg = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  56817. + dr->dctl = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  56818. + dr->daintmsk =
  56819. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
  56820. + dr->diepmsk =
  56821. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->diepmsk);
  56822. + dr->doepmsk =
  56823. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->doepmsk);
  56824. +
  56825. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  56826. + dr->diepctl[i] =
  56827. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->diepctl);
  56828. + dr->dieptsiz[i] =
  56829. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->dieptsiz);
  56830. + dr->diepdma[i] =
  56831. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->diepdma);
  56832. + }
  56833. +
  56834. + DWC_DEBUGPL(DBG_ANY,
  56835. + "=============Backing Host registers==============\n");
  56836. + DWC_DEBUGPL(DBG_ANY, "Backed up dcfg = %08x\n", dr->dcfg);
  56837. + DWC_DEBUGPL(DBG_ANY, "Backed up dctl = %08x\n", dr->dctl);
  56838. + DWC_DEBUGPL(DBG_ANY, "Backed up daintmsk = %08x\n",
  56839. + dr->daintmsk);
  56840. + DWC_DEBUGPL(DBG_ANY, "Backed up diepmsk = %08x\n", dr->diepmsk);
  56841. + DWC_DEBUGPL(DBG_ANY, "Backed up doepmsk = %08x\n", dr->doepmsk);
  56842. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  56843. + DWC_DEBUGPL(DBG_ANY, "Backed up diepctl[%d] = %08x\n", i,
  56844. + dr->diepctl[i]);
  56845. + DWC_DEBUGPL(DBG_ANY, "Backed up dieptsiz[%d] = %08x\n",
  56846. + i, dr->dieptsiz[i]);
  56847. + DWC_DEBUGPL(DBG_ANY, "Backed up diepdma[%d] = %08x\n", i,
  56848. + dr->diepdma[i]);
  56849. + }
  56850. +
  56851. + return 0;
  56852. +}
  56853. +
  56854. +int dwc_otg_save_host_regs(dwc_otg_core_if_t * core_if)
  56855. +{
  56856. + struct dwc_otg_host_regs_backup *hr;
  56857. + int i;
  56858. +
  56859. + hr = core_if->hr_backup;
  56860. + if (!hr) {
  56861. + hr = DWC_ALLOC(sizeof(*hr));
  56862. + if (!hr) {
  56863. + return -DWC_E_NO_MEMORY;
  56864. + }
  56865. + core_if->hr_backup = hr;
  56866. + }
  56867. +
  56868. + hr->hcfg_local =
  56869. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  56870. + hr->haintmsk_local =
  56871. + DWC_READ_REG32(&core_if->host_if->host_global_regs->haintmsk);
  56872. + for (i = 0; i < dwc_otg_get_param_host_channels(core_if); ++i) {
  56873. + hr->hcintmsk_local[i] =
  56874. + DWC_READ_REG32(&core_if->host_if->hc_regs[i]->hcintmsk);
  56875. + }
  56876. + hr->hprt0_local = DWC_READ_REG32(core_if->host_if->hprt0);
  56877. + hr->hfir_local =
  56878. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hfir);
  56879. +
  56880. + DWC_DEBUGPL(DBG_ANY,
  56881. + "=============Backing Host registers===============\n");
  56882. + DWC_DEBUGPL(DBG_ANY, "Backed up hcfg = %08x\n",
  56883. + hr->hcfg_local);
  56884. + DWC_DEBUGPL(DBG_ANY, "Backed up haintmsk = %08x\n", hr->haintmsk_local);
  56885. + for (i = 0; i < dwc_otg_get_param_host_channels(core_if); ++i) {
  56886. + DWC_DEBUGPL(DBG_ANY, "Backed up hcintmsk[%02d]=%08x\n", i,
  56887. + hr->hcintmsk_local[i]);
  56888. + }
  56889. + DWC_DEBUGPL(DBG_ANY, "Backed up hprt0 = %08x\n",
  56890. + hr->hprt0_local);
  56891. + DWC_DEBUGPL(DBG_ANY, "Backed up hfir = %08x\n",
  56892. + hr->hfir_local);
  56893. +
  56894. + return 0;
  56895. +}
  56896. +
  56897. +int dwc_otg_restore_global_regs(dwc_otg_core_if_t *core_if)
  56898. +{
  56899. + struct dwc_otg_global_regs_backup *gr;
  56900. + int i;
  56901. +
  56902. + gr = core_if->gr_backup;
  56903. + if (!gr) {
  56904. + return -DWC_E_INVALID;
  56905. + }
  56906. +
  56907. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgctl, gr->gotgctl_local);
  56908. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gr->gintmsk_local);
  56909. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gr->gusbcfg_local);
  56910. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg, gr->gahbcfg_local);
  56911. + DWC_WRITE_REG32(&core_if->core_global_regs->grxfsiz, gr->grxfsiz_local);
  56912. + DWC_WRITE_REG32(&core_if->core_global_regs->gnptxfsiz,
  56913. + gr->gnptxfsiz_local);
  56914. + DWC_WRITE_REG32(&core_if->core_global_regs->hptxfsiz,
  56915. + gr->hptxfsiz_local);
  56916. + DWC_WRITE_REG32(&core_if->core_global_regs->gdfifocfg,
  56917. + gr->gdfifocfg_local);
  56918. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  56919. + DWC_WRITE_REG32(&core_if->core_global_regs->dtxfsiz[i],
  56920. + gr->dtxfsiz_local[i]);
  56921. + }
  56922. +
  56923. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  56924. + DWC_WRITE_REG32(core_if->host_if->hprt0, 0x0000100A);
  56925. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg,
  56926. + (gr->gahbcfg_local));
  56927. + return 0;
  56928. +}
  56929. +
  56930. +int dwc_otg_restore_dev_regs(dwc_otg_core_if_t * core_if, int rem_wakeup)
  56931. +{
  56932. + struct dwc_otg_dev_regs_backup *dr;
  56933. + int i;
  56934. +
  56935. + dr = core_if->dr_backup;
  56936. +
  56937. + if (!dr) {
  56938. + return -DWC_E_INVALID;
  56939. + }
  56940. +
  56941. + if (!rem_wakeup) {
  56942. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl,
  56943. + dr->dctl);
  56944. + }
  56945. +
  56946. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->daintmsk, dr->daintmsk);
  56947. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->diepmsk, dr->diepmsk);
  56948. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->doepmsk, dr->doepmsk);
  56949. +
  56950. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  56951. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->dieptsiz, dr->dieptsiz[i]);
  56952. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->diepdma, dr->diepdma[i]);
  56953. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->diepctl, dr->diepctl[i]);
  56954. + }
  56955. +
  56956. + return 0;
  56957. +}
  56958. +
  56959. +int dwc_otg_restore_host_regs(dwc_otg_core_if_t * core_if, int reset)
  56960. +{
  56961. + struct dwc_otg_host_regs_backup *hr;
  56962. + int i;
  56963. + hr = core_if->hr_backup;
  56964. +
  56965. + if (!hr) {
  56966. + return -DWC_E_INVALID;
  56967. + }
  56968. +
  56969. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg, hr->hcfg_local);
  56970. + //if (!reset)
  56971. + //{
  56972. + // DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hfir, hr->hfir_local);
  56973. + //}
  56974. +
  56975. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->haintmsk,
  56976. + hr->haintmsk_local);
  56977. + for (i = 0; i < dwc_otg_get_param_host_channels(core_if); ++i) {
  56978. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[i]->hcintmsk,
  56979. + hr->hcintmsk_local[i]);
  56980. + }
  56981. +
  56982. + return 0;
  56983. +}
  56984. +
  56985. +int restore_lpm_i2c_regs(dwc_otg_core_if_t * core_if)
  56986. +{
  56987. + struct dwc_otg_global_regs_backup *gr;
  56988. +
  56989. + gr = core_if->gr_backup;
  56990. +
  56991. + /* Restore values for LPM and I2C */
  56992. +#ifdef CONFIG_USB_DWC_OTG_LPM
  56993. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, gr->glpmcfg_local);
  56994. +#endif
  56995. + DWC_WRITE_REG32(&core_if->core_global_regs->gi2cctl, gr->gi2cctl_local);
  56996. +
  56997. + return 0;
  56998. +}
  56999. +
  57000. +int restore_essential_regs(dwc_otg_core_if_t * core_if, int rmode, int is_host)
  57001. +{
  57002. + struct dwc_otg_global_regs_backup *gr;
  57003. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  57004. + gahbcfg_data_t gahbcfg = {.d32 = 0 };
  57005. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  57006. + gintmsk_data_t gintmsk = {.d32 = 0 };
  57007. +
  57008. + /* Restore LPM and I2C registers */
  57009. + restore_lpm_i2c_regs(core_if);
  57010. +
  57011. + /* Set PCGCCTL to 0 */
  57012. + DWC_WRITE_REG32(core_if->pcgcctl, 0x00000000);
  57013. +
  57014. + gr = core_if->gr_backup;
  57015. + /* Load restore values for [31:14] bits */
  57016. + DWC_WRITE_REG32(core_if->pcgcctl,
  57017. + ((gr->pcgcctl_local & 0xffffc000) | 0x00020000));
  57018. +
  57019. + /* Umnask global Interrupt in GAHBCFG and restore it */
  57020. + gahbcfg.d32 = gr->gahbcfg_local;
  57021. + gahbcfg.b.glblintrmsk = 1;
  57022. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg, gahbcfg.d32);
  57023. +
  57024. + /* Clear all pending interupts */
  57025. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  57026. +
  57027. + /* Unmask restore done interrupt */
  57028. + gintmsk.b.restoredone = 1;
  57029. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32);
  57030. +
  57031. + /* Restore GUSBCFG and HCFG/DCFG */
  57032. + gusbcfg.d32 = core_if->gr_backup->gusbcfg_local;
  57033. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gusbcfg.d32);
  57034. +
  57035. + if (is_host) {
  57036. + hcfg_data_t hcfg = {.d32 = 0 };
  57037. + hcfg.d32 = core_if->hr_backup->hcfg_local;
  57038. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg,
  57039. + hcfg.d32);
  57040. +
  57041. + /* Load restore values for [31:14] bits */
  57042. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  57043. + pcgcctl.d32 = gr->pcgcctl_local | 0x00020000;
  57044. +
  57045. + if (rmode)
  57046. + pcgcctl.b.restoremode = 1;
  57047. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  57048. + dwc_udelay(10);
  57049. +
  57050. + /* Load restore values for [31:14] bits and set EssRegRestored bit */
  57051. + pcgcctl.d32 = gr->pcgcctl_local | 0xffffc000;
  57052. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  57053. + pcgcctl.b.ess_reg_restored = 1;
  57054. + if (rmode)
  57055. + pcgcctl.b.restoremode = 1;
  57056. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  57057. + } else {
  57058. + dcfg_data_t dcfg = {.d32 = 0 };
  57059. + dcfg.d32 = core_if->dr_backup->dcfg;
  57060. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
  57061. +
  57062. + /* Load restore values for [31:14] bits */
  57063. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  57064. + pcgcctl.d32 = gr->pcgcctl_local | 0x00020000;
  57065. + if (!rmode) {
  57066. + pcgcctl.d32 |= 0x208;
  57067. + }
  57068. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  57069. + dwc_udelay(10);
  57070. +
  57071. + /* Load restore values for [31:14] bits */
  57072. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  57073. + pcgcctl.d32 = gr->pcgcctl_local | 0x00020000;
  57074. + pcgcctl.b.ess_reg_restored = 1;
  57075. + if (!rmode)
  57076. + pcgcctl.d32 |= 0x208;
  57077. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  57078. + }
  57079. +
  57080. + return 0;
  57081. +}
  57082. +
  57083. +/**
  57084. + * Initializes the FSLSPClkSel field of the HCFG register depending on the PHY
  57085. + * type.
  57086. + */
  57087. +static void init_fslspclksel(dwc_otg_core_if_t * core_if)
  57088. +{
  57089. + uint32_t val;
  57090. + hcfg_data_t hcfg;
  57091. +
  57092. + if (((core_if->hwcfg2.b.hs_phy_type == 2) &&
  57093. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  57094. + (core_if->core_params->ulpi_fs_ls)) ||
  57095. + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
  57096. + /* Full speed PHY */
  57097. + val = DWC_HCFG_48_MHZ;
  57098. + } else {
  57099. + /* High speed PHY running at full speed or high speed */
  57100. + val = DWC_HCFG_30_60_MHZ;
  57101. + }
  57102. +
  57103. + DWC_DEBUGPL(DBG_CIL, "Initializing HCFG.FSLSPClkSel to 0x%1x\n", val);
  57104. + hcfg.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  57105. + hcfg.b.fslspclksel = val;
  57106. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  57107. +}
  57108. +
  57109. +/**
  57110. + * Initializes the DevSpd field of the DCFG register depending on the PHY type
  57111. + * and the enumeration speed of the device.
  57112. + */
  57113. +static void init_devspd(dwc_otg_core_if_t * core_if)
  57114. +{
  57115. + uint32_t val;
  57116. + dcfg_data_t dcfg;
  57117. +
  57118. + if (((core_if->hwcfg2.b.hs_phy_type == 2) &&
  57119. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  57120. + (core_if->core_params->ulpi_fs_ls)) ||
  57121. + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
  57122. + /* Full speed PHY */
  57123. + val = 0x3;
  57124. + } else if (core_if->core_params->speed == DWC_SPEED_PARAM_FULL) {
  57125. + /* High speed PHY running at full speed */
  57126. + val = 0x1;
  57127. + } else {
  57128. + /* High speed PHY running at high speed */
  57129. + val = 0x0;
  57130. + }
  57131. +
  57132. + DWC_DEBUGPL(DBG_CIL, "Initializing DCFG.DevSpd to 0x%1x\n", val);
  57133. +
  57134. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  57135. + dcfg.b.devspd = val;
  57136. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
  57137. +}
  57138. +
  57139. +/**
  57140. + * This function calculates the number of IN EPS
  57141. + * using GHWCFG1 and GHWCFG2 registers values
  57142. + *
  57143. + * @param core_if Programming view of the DWC_otg controller
  57144. + */
  57145. +static uint32_t calc_num_in_eps(dwc_otg_core_if_t * core_if)
  57146. +{
  57147. + uint32_t num_in_eps = 0;
  57148. + uint32_t num_eps = core_if->hwcfg2.b.num_dev_ep;
  57149. + uint32_t hwcfg1 = core_if->hwcfg1.d32 >> 3;
  57150. + uint32_t num_tx_fifos = core_if->hwcfg4.b.num_in_eps;
  57151. + int i;
  57152. +
  57153. + for (i = 0; i < num_eps; ++i) {
  57154. + if (!(hwcfg1 & 0x1))
  57155. + num_in_eps++;
  57156. +
  57157. + hwcfg1 >>= 2;
  57158. + }
  57159. +
  57160. + if (core_if->hwcfg4.b.ded_fifo_en) {
  57161. + num_in_eps =
  57162. + (num_in_eps > num_tx_fifos) ? num_tx_fifos : num_in_eps;
  57163. + }
  57164. +
  57165. + return num_in_eps;
  57166. +}
  57167. +
  57168. +/**
  57169. + * This function calculates the number of OUT EPS
  57170. + * using GHWCFG1 and GHWCFG2 registers values
  57171. + *
  57172. + * @param core_if Programming view of the DWC_otg controller
  57173. + */
  57174. +static uint32_t calc_num_out_eps(dwc_otg_core_if_t * core_if)
  57175. +{
  57176. + uint32_t num_out_eps = 0;
  57177. + uint32_t num_eps = core_if->hwcfg2.b.num_dev_ep;
  57178. + uint32_t hwcfg1 = core_if->hwcfg1.d32 >> 2;
  57179. + int i;
  57180. +
  57181. + for (i = 0; i < num_eps; ++i) {
  57182. + if (!(hwcfg1 & 0x1))
  57183. + num_out_eps++;
  57184. +
  57185. + hwcfg1 >>= 2;
  57186. + }
  57187. + return num_out_eps;
  57188. +}
  57189. +
  57190. +/**
  57191. + * This function initializes the DWC_otg controller registers and
  57192. + * prepares the core for device mode or host mode operation.
  57193. + *
  57194. + * @param core_if Programming view of the DWC_otg controller
  57195. + *
  57196. + */
  57197. +void dwc_otg_core_init(dwc_otg_core_if_t * core_if)
  57198. +{
  57199. + int i = 0;
  57200. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  57201. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  57202. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  57203. + gusbcfg_data_t usbcfg = {.d32 = 0 };
  57204. + gi2cctl_data_t i2cctl = {.d32 = 0 };
  57205. +
  57206. + DWC_DEBUGPL(DBG_CILV, "dwc_otg_core_init(%p) regs at %p\n",
  57207. + core_if, global_regs);
  57208. +
  57209. + /* Common Initialization */
  57210. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  57211. +
  57212. + /* Program the ULPI External VBUS bit if needed */
  57213. + usbcfg.b.ulpi_ext_vbus_drv =
  57214. + (core_if->core_params->phy_ulpi_ext_vbus ==
  57215. + DWC_PHY_ULPI_EXTERNAL_VBUS) ? 1 : 0;
  57216. +
  57217. + /* Set external TS Dline pulsing */
  57218. + usbcfg.b.term_sel_dl_pulse =
  57219. + (core_if->core_params->ts_dline == 1) ? 1 : 0;
  57220. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  57221. +
  57222. + /* Reset the Controller */
  57223. + dwc_otg_core_reset(core_if);
  57224. +
  57225. + core_if->adp_enable = core_if->core_params->adp_supp_enable;
  57226. + core_if->power_down = core_if->core_params->power_down;
  57227. + core_if->otg_sts = 0;
  57228. +
  57229. + /* Initialize parameters from Hardware configuration registers. */
  57230. + dev_if->num_in_eps = calc_num_in_eps(core_if);
  57231. + dev_if->num_out_eps = calc_num_out_eps(core_if);
  57232. +
  57233. + DWC_DEBUGPL(DBG_CIL, "num_dev_perio_in_ep=%d\n",
  57234. + core_if->hwcfg4.b.num_dev_perio_in_ep);
  57235. +
  57236. + for (i = 0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; i++) {
  57237. + dev_if->perio_tx_fifo_size[i] =
  57238. + DWC_READ_REG32(&global_regs->dtxfsiz[i]) >> 16;
  57239. + DWC_DEBUGPL(DBG_CIL, "Periodic Tx FIFO SZ #%d=0x%0x\n",
  57240. + i, dev_if->perio_tx_fifo_size[i]);
  57241. + }
  57242. +
  57243. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  57244. + dev_if->tx_fifo_size[i] =
  57245. + DWC_READ_REG32(&global_regs->dtxfsiz[i]) >> 16;
  57246. + DWC_DEBUGPL(DBG_CIL, "Tx FIFO SZ #%d=0x%0x\n",
  57247. + i, dev_if->tx_fifo_size[i]);
  57248. + }
  57249. +
  57250. + core_if->total_fifo_size = core_if->hwcfg3.b.dfifo_depth;
  57251. + core_if->rx_fifo_size = DWC_READ_REG32(&global_regs->grxfsiz);
  57252. + core_if->nperio_tx_fifo_size =
  57253. + DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16;
  57254. +
  57255. + DWC_DEBUGPL(DBG_CIL, "Total FIFO SZ=%d\n", core_if->total_fifo_size);
  57256. + DWC_DEBUGPL(DBG_CIL, "Rx FIFO SZ=%d\n", core_if->rx_fifo_size);
  57257. + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO SZ=%d\n",
  57258. + core_if->nperio_tx_fifo_size);
  57259. +
  57260. + /* This programming sequence needs to happen in FS mode before any other
  57261. + * programming occurs */
  57262. + if ((core_if->core_params->speed == DWC_SPEED_PARAM_FULL) &&
  57263. + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
  57264. + /* If FS mode with FS PHY */
  57265. +
  57266. + /* core_init() is now called on every switch so only call the
  57267. + * following for the first time through. */
  57268. + if (!core_if->phy_init_done) {
  57269. + core_if->phy_init_done = 1;
  57270. + DWC_DEBUGPL(DBG_CIL, "FS_PHY detected\n");
  57271. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  57272. + usbcfg.b.physel = 1;
  57273. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  57274. +
  57275. + /* Reset after a PHY select */
  57276. + dwc_otg_core_reset(core_if);
  57277. + }
  57278. +
  57279. + /* Program DCFG.DevSpd or HCFG.FSLSPclkSel to 48Mhz in FS. Also
  57280. + * do this on HNP Dev/Host mode switches (done in dev_init and
  57281. + * host_init). */
  57282. + if (dwc_otg_is_host_mode(core_if)) {
  57283. + init_fslspclksel(core_if);
  57284. + } else {
  57285. + init_devspd(core_if);
  57286. + }
  57287. +
  57288. + if (core_if->core_params->i2c_enable) {
  57289. + DWC_DEBUGPL(DBG_CIL, "FS_PHY Enabling I2c\n");
  57290. + /* Program GUSBCFG.OtgUtmifsSel to I2C */
  57291. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  57292. + usbcfg.b.otgutmifssel = 1;
  57293. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  57294. +
  57295. + /* Program GI2CCTL.I2CEn */
  57296. + i2cctl.d32 = DWC_READ_REG32(&global_regs->gi2cctl);
  57297. + i2cctl.b.i2cdevaddr = 1;
  57298. + i2cctl.b.i2cen = 0;
  57299. + DWC_WRITE_REG32(&global_regs->gi2cctl, i2cctl.d32);
  57300. + i2cctl.b.i2cen = 1;
  57301. + DWC_WRITE_REG32(&global_regs->gi2cctl, i2cctl.d32);
  57302. + }
  57303. +
  57304. + } /* endif speed == DWC_SPEED_PARAM_FULL */
  57305. + else {
  57306. + /* High speed PHY. */
  57307. + if (!core_if->phy_init_done) {
  57308. + core_if->phy_init_done = 1;
  57309. + /* HS PHY parameters. These parameters are preserved
  57310. + * during soft reset so only program the first time. Do
  57311. + * a soft reset immediately after setting phyif. */
  57312. +
  57313. + if (core_if->core_params->phy_type == 2) {
  57314. + /* ULPI interface */
  57315. + usbcfg.b.ulpi_utmi_sel = 1;
  57316. + usbcfg.b.phyif = 0;
  57317. + usbcfg.b.ddrsel =
  57318. + core_if->core_params->phy_ulpi_ddr;
  57319. + } else if (core_if->core_params->phy_type == 1) {
  57320. + /* UTMI+ interface */
  57321. + usbcfg.b.ulpi_utmi_sel = 0;
  57322. + if (core_if->core_params->phy_utmi_width == 16) {
  57323. + usbcfg.b.phyif = 1;
  57324. +
  57325. + } else {
  57326. + usbcfg.b.phyif = 0;
  57327. + }
  57328. + } else {
  57329. + DWC_ERROR("FS PHY TYPE\n");
  57330. + }
  57331. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  57332. + /* Reset after setting the PHY parameters */
  57333. + dwc_otg_core_reset(core_if);
  57334. + }
  57335. + }
  57336. +
  57337. + if ((core_if->hwcfg2.b.hs_phy_type == 2) &&
  57338. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  57339. + (core_if->core_params->ulpi_fs_ls)) {
  57340. + DWC_DEBUGPL(DBG_CIL, "Setting ULPI FSLS\n");
  57341. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  57342. + usbcfg.b.ulpi_fsls = 1;
  57343. + usbcfg.b.ulpi_clk_sus_m = 1;
  57344. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  57345. + } else {
  57346. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  57347. + usbcfg.b.ulpi_fsls = 0;
  57348. + usbcfg.b.ulpi_clk_sus_m = 0;
  57349. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  57350. + }
  57351. +
  57352. + /* Program the GAHBCFG Register. */
  57353. + switch (core_if->hwcfg2.b.architecture) {
  57354. +
  57355. + case DWC_SLAVE_ONLY_ARCH:
  57356. + DWC_DEBUGPL(DBG_CIL, "Slave Only Mode\n");
  57357. + ahbcfg.b.nptxfemplvl_txfemplvl =
  57358. + DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY;
  57359. + ahbcfg.b.ptxfemplvl = DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY;
  57360. + core_if->dma_enable = 0;
  57361. + core_if->dma_desc_enable = 0;
  57362. + break;
  57363. +
  57364. + case DWC_EXT_DMA_ARCH:
  57365. + DWC_DEBUGPL(DBG_CIL, "External DMA Mode\n");
  57366. + {
  57367. + uint8_t brst_sz = core_if->core_params->dma_burst_size;
  57368. + ahbcfg.b.hburstlen = 0;
  57369. + while (brst_sz > 1) {
  57370. + ahbcfg.b.hburstlen++;
  57371. + brst_sz >>= 1;
  57372. + }
  57373. + }
  57374. + core_if->dma_enable = (core_if->core_params->dma_enable != 0);
  57375. + core_if->dma_desc_enable =
  57376. + (core_if->core_params->dma_desc_enable != 0);
  57377. + break;
  57378. +
  57379. + case DWC_INT_DMA_ARCH:
  57380. + DWC_DEBUGPL(DBG_CIL, "Internal DMA Mode\n");
  57381. + /* Old value was DWC_GAHBCFG_INT_DMA_BURST_INCR - done for
  57382. + Host mode ISOC in issue fix - vahrama */
  57383. + /* Broadcom had altered to (1<<3)|(0<<0) - WRESP=1, max 4 beats */
  57384. + ahbcfg.b.hburstlen = (1<<3)|(0<<0);//DWC_GAHBCFG_INT_DMA_BURST_INCR4;
  57385. + core_if->dma_enable = (core_if->core_params->dma_enable != 0);
  57386. + core_if->dma_desc_enable =
  57387. + (core_if->core_params->dma_desc_enable != 0);
  57388. + break;
  57389. +
  57390. + }
  57391. + if (core_if->dma_enable) {
  57392. + if (core_if->dma_desc_enable) {
  57393. + DWC_PRINTF("Using Descriptor DMA mode\n");
  57394. + } else {
  57395. + DWC_PRINTF("Using Buffer DMA mode\n");
  57396. +
  57397. + }
  57398. + } else {
  57399. + DWC_PRINTF("Using Slave mode\n");
  57400. + core_if->dma_desc_enable = 0;
  57401. + }
  57402. +
  57403. + if (core_if->core_params->ahb_single) {
  57404. + ahbcfg.b.ahbsingle = 1;
  57405. + }
  57406. +
  57407. + ahbcfg.b.dmaenable = core_if->dma_enable;
  57408. + DWC_WRITE_REG32(&global_regs->gahbcfg, ahbcfg.d32);
  57409. +
  57410. + core_if->en_multiple_tx_fifo = core_if->hwcfg4.b.ded_fifo_en;
  57411. +
  57412. + core_if->pti_enh_enable = core_if->core_params->pti_enable != 0;
  57413. + core_if->multiproc_int_enable = core_if->core_params->mpi_enable;
  57414. + DWC_PRINTF("Periodic Transfer Interrupt Enhancement - %s\n",
  57415. + ((core_if->pti_enh_enable) ? "enabled" : "disabled"));
  57416. + DWC_PRINTF("Multiprocessor Interrupt Enhancement - %s\n",
  57417. + ((core_if->multiproc_int_enable) ? "enabled" : "disabled"));
  57418. +
  57419. + /*
  57420. + * Program the GUSBCFG register.
  57421. + */
  57422. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  57423. +
  57424. + switch (core_if->hwcfg2.b.op_mode) {
  57425. + case DWC_MODE_HNP_SRP_CAPABLE:
  57426. + usbcfg.b.hnpcap = (core_if->core_params->otg_cap ==
  57427. + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE);
  57428. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  57429. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  57430. + break;
  57431. +
  57432. + case DWC_MODE_SRP_ONLY_CAPABLE:
  57433. + usbcfg.b.hnpcap = 0;
  57434. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  57435. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  57436. + break;
  57437. +
  57438. + case DWC_MODE_NO_HNP_SRP_CAPABLE:
  57439. + usbcfg.b.hnpcap = 0;
  57440. + usbcfg.b.srpcap = 0;
  57441. + break;
  57442. +
  57443. + case DWC_MODE_SRP_CAPABLE_DEVICE:
  57444. + usbcfg.b.hnpcap = 0;
  57445. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  57446. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  57447. + break;
  57448. +
  57449. + case DWC_MODE_NO_SRP_CAPABLE_DEVICE:
  57450. + usbcfg.b.hnpcap = 0;
  57451. + usbcfg.b.srpcap = 0;
  57452. + break;
  57453. +
  57454. + case DWC_MODE_SRP_CAPABLE_HOST:
  57455. + usbcfg.b.hnpcap = 0;
  57456. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  57457. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  57458. + break;
  57459. +
  57460. + case DWC_MODE_NO_SRP_CAPABLE_HOST:
  57461. + usbcfg.b.hnpcap = 0;
  57462. + usbcfg.b.srpcap = 0;
  57463. + break;
  57464. + }
  57465. +
  57466. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  57467. +
  57468. +#ifdef CONFIG_USB_DWC_OTG_LPM
  57469. + if (core_if->core_params->lpm_enable) {
  57470. + glpmcfg_data_t lpmcfg = {.d32 = 0 };
  57471. +
  57472. + /* To enable LPM support set lpm_cap_en bit */
  57473. + lpmcfg.b.lpm_cap_en = 1;
  57474. +
  57475. + /* Make AppL1Res ACK */
  57476. + lpmcfg.b.appl_resp = 1;
  57477. +
  57478. + /* Retry 3 times */
  57479. + lpmcfg.b.retry_count = 3;
  57480. +
  57481. + DWC_MODIFY_REG32(&core_if->core_global_regs->glpmcfg,
  57482. + 0, lpmcfg.d32);
  57483. +
  57484. + }
  57485. +#endif
  57486. + if (core_if->core_params->ic_usb_cap) {
  57487. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  57488. + gusbcfg.b.ic_usb_cap = 1;
  57489. + DWC_MODIFY_REG32(&core_if->core_global_regs->gusbcfg,
  57490. + 0, gusbcfg.d32);
  57491. + }
  57492. + {
  57493. + gotgctl_data_t gotgctl = {.d32 = 0 };
  57494. + gotgctl.b.otgver = core_if->core_params->otg_ver;
  57495. + DWC_MODIFY_REG32(&core_if->core_global_regs->gotgctl, 0,
  57496. + gotgctl.d32);
  57497. + /* Set OTG version supported */
  57498. + core_if->otg_ver = core_if->core_params->otg_ver;
  57499. + DWC_PRINTF("OTG VER PARAM: %d, OTG VER FLAG: %d\n",
  57500. + core_if->core_params->otg_ver, core_if->otg_ver);
  57501. + }
  57502. +
  57503. +
  57504. + /* Enable common interrupts */
  57505. + dwc_otg_enable_common_interrupts(core_if);
  57506. +
  57507. + /* Do device or host intialization based on mode during PCD
  57508. + * and HCD initialization */
  57509. + if (dwc_otg_is_host_mode(core_if)) {
  57510. + DWC_DEBUGPL(DBG_ANY, "Host Mode\n");
  57511. + core_if->op_state = A_HOST;
  57512. + } else {
  57513. + DWC_DEBUGPL(DBG_ANY, "Device Mode\n");
  57514. + core_if->op_state = B_PERIPHERAL;
  57515. +#ifdef DWC_DEVICE_ONLY
  57516. + dwc_otg_core_dev_init(core_if);
  57517. +#endif
  57518. + }
  57519. +}
  57520. +
  57521. +/**
  57522. + * This function enables the Device mode interrupts.
  57523. + *
  57524. + * @param core_if Programming view of DWC_otg controller
  57525. + */
  57526. +void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t * core_if)
  57527. +{
  57528. + gintmsk_data_t intr_mask = {.d32 = 0 };
  57529. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  57530. +
  57531. + DWC_DEBUGPL(DBG_CIL, "%s()\n", __func__);
  57532. +
  57533. + /* Disable all interrupts. */
  57534. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  57535. +
  57536. + /* Clear any pending interrupts */
  57537. + DWC_WRITE_REG32(&global_regs->gintsts, 0xFFFFFFFF);
  57538. +
  57539. + /* Enable the common interrupts */
  57540. + dwc_otg_enable_common_interrupts(core_if);
  57541. +
  57542. + /* Enable interrupts */
  57543. + intr_mask.b.usbreset = 1;
  57544. + intr_mask.b.enumdone = 1;
  57545. + /* Disable Disconnect interrupt in Device mode */
  57546. + intr_mask.b.disconnect = 0;
  57547. +
  57548. + if (!core_if->multiproc_int_enable) {
  57549. + intr_mask.b.inepintr = 1;
  57550. + intr_mask.b.outepintr = 1;
  57551. + }
  57552. +
  57553. + intr_mask.b.erlysuspend = 1;
  57554. +
  57555. + if (core_if->en_multiple_tx_fifo == 0) {
  57556. + intr_mask.b.epmismatch = 1;
  57557. + }
  57558. +
  57559. + //intr_mask.b.incomplisoout = 1;
  57560. + intr_mask.b.incomplisoin = 1;
  57561. +
  57562. +/* Enable the ignore frame number for ISOC xfers - MAS */
  57563. +/* Disable to support high bandwith ISOC transfers - manukz */
  57564. +#if 0
  57565. +#ifdef DWC_UTE_PER_IO
  57566. + if (core_if->dma_enable) {
  57567. + if (core_if->dma_desc_enable) {
  57568. + dctl_data_t dctl1 = {.d32 = 0 };
  57569. + dctl1.b.ifrmnum = 1;
  57570. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  57571. + dctl, 0, dctl1.d32);
  57572. + DWC_DEBUG("----Enabled Ignore frame number (0x%08x)",
  57573. + DWC_READ_REG32(&core_if->dev_if->
  57574. + dev_global_regs->dctl));
  57575. + }
  57576. + }
  57577. +#endif
  57578. +#endif
  57579. +#ifdef DWC_EN_ISOC
  57580. + if (core_if->dma_enable) {
  57581. + if (core_if->dma_desc_enable == 0) {
  57582. + if (core_if->pti_enh_enable) {
  57583. + dctl_data_t dctl = {.d32 = 0 };
  57584. + dctl.b.ifrmnum = 1;
  57585. + DWC_MODIFY_REG32(&core_if->
  57586. + dev_if->dev_global_regs->dctl,
  57587. + 0, dctl.d32);
  57588. + } else {
  57589. + intr_mask.b.incomplisoin = 1;
  57590. + intr_mask.b.incomplisoout = 1;
  57591. + }
  57592. + }
  57593. + } else {
  57594. + intr_mask.b.incomplisoin = 1;
  57595. + intr_mask.b.incomplisoout = 1;
  57596. + }
  57597. +#endif /* DWC_EN_ISOC */
  57598. +
  57599. + /** @todo NGS: Should this be a module parameter? */
  57600. +#ifdef USE_PERIODIC_EP
  57601. + intr_mask.b.isooutdrop = 1;
  57602. + intr_mask.b.eopframe = 1;
  57603. + intr_mask.b.incomplisoin = 1;
  57604. + intr_mask.b.incomplisoout = 1;
  57605. +#endif
  57606. +
  57607. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
  57608. +
  57609. + DWC_DEBUGPL(DBG_CIL, "%s() gintmsk=%0x\n", __func__,
  57610. + DWC_READ_REG32(&global_regs->gintmsk));
  57611. +}
  57612. +
  57613. +/**
  57614. + * This function initializes the DWC_otg controller registers for
  57615. + * device mode.
  57616. + *
  57617. + * @param core_if Programming view of DWC_otg controller
  57618. + *
  57619. + */
  57620. +void dwc_otg_core_dev_init(dwc_otg_core_if_t * core_if)
  57621. +{
  57622. + int i;
  57623. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  57624. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  57625. + dwc_otg_core_params_t *params = core_if->core_params;
  57626. + dcfg_data_t dcfg = {.d32 = 0 };
  57627. + depctl_data_t diepctl = {.d32 = 0 };
  57628. + grstctl_t resetctl = {.d32 = 0 };
  57629. + uint32_t rx_fifo_size;
  57630. + fifosize_data_t nptxfifosize;
  57631. + fifosize_data_t txfifosize;
  57632. + dthrctl_data_t dthrctl;
  57633. + fifosize_data_t ptxfifosize;
  57634. + uint16_t rxfsiz, nptxfsiz;
  57635. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  57636. + hwcfg3_data_t hwcfg3 = {.d32 = 0 };
  57637. +
  57638. + /* Restart the Phy Clock */
  57639. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  57640. +
  57641. + /* Device configuration register */
  57642. + init_devspd(core_if);
  57643. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  57644. + dcfg.b.descdma = (core_if->dma_desc_enable) ? 1 : 0;
  57645. + dcfg.b.perfrint = DWC_DCFG_FRAME_INTERVAL_80;
  57646. + /* Enable Device OUT NAK in case of DDMA mode*/
  57647. + if (core_if->core_params->dev_out_nak) {
  57648. + dcfg.b.endevoutnak = 1;
  57649. + }
  57650. +
  57651. + if (core_if->core_params->cont_on_bna) {
  57652. + dctl_data_t dctl = {.d32 = 0 };
  57653. + dctl.b.encontonbna = 1;
  57654. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, 0, dctl.d32);
  57655. + }
  57656. +
  57657. +
  57658. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  57659. +
  57660. + /* Configure data FIFO sizes */
  57661. + if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
  57662. + DWC_DEBUGPL(DBG_CIL, "Total FIFO Size=%d\n",
  57663. + core_if->total_fifo_size);
  57664. + DWC_DEBUGPL(DBG_CIL, "Rx FIFO Size=%d\n",
  57665. + params->dev_rx_fifo_size);
  57666. + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO Size=%d\n",
  57667. + params->dev_nperio_tx_fifo_size);
  57668. +
  57669. + /* Rx FIFO */
  57670. + DWC_DEBUGPL(DBG_CIL, "initial grxfsiz=%08x\n",
  57671. + DWC_READ_REG32(&global_regs->grxfsiz));
  57672. +
  57673. +#ifdef DWC_UTE_CFI
  57674. + core_if->pwron_rxfsiz = DWC_READ_REG32(&global_regs->grxfsiz);
  57675. + core_if->init_rxfsiz = params->dev_rx_fifo_size;
  57676. +#endif
  57677. + rx_fifo_size = params->dev_rx_fifo_size;
  57678. + DWC_WRITE_REG32(&global_regs->grxfsiz, rx_fifo_size);
  57679. +
  57680. + DWC_DEBUGPL(DBG_CIL, "new grxfsiz=%08x\n",
  57681. + DWC_READ_REG32(&global_regs->grxfsiz));
  57682. +
  57683. + /** Set Periodic Tx FIFO Mask all bits 0 */
  57684. + core_if->p_tx_msk = 0;
  57685. +
  57686. + /** Set Tx FIFO Mask all bits 0 */
  57687. + core_if->tx_msk = 0;
  57688. +
  57689. + if (core_if->en_multiple_tx_fifo == 0) {
  57690. + /* Non-periodic Tx FIFO */
  57691. + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
  57692. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  57693. +
  57694. + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
  57695. + nptxfifosize.b.startaddr = params->dev_rx_fifo_size;
  57696. +
  57697. + DWC_WRITE_REG32(&global_regs->gnptxfsiz,
  57698. + nptxfifosize.d32);
  57699. +
  57700. + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
  57701. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  57702. +
  57703. + /**@todo NGS: Fix Periodic FIFO Sizing! */
  57704. + /*
  57705. + * Periodic Tx FIFOs These FIFOs are numbered from 1 to 15.
  57706. + * Indexes of the FIFO size module parameters in the
  57707. + * dev_perio_tx_fifo_size array and the FIFO size registers in
  57708. + * the dptxfsiz array run from 0 to 14.
  57709. + */
  57710. + /** @todo Finish debug of this */
  57711. + ptxfifosize.b.startaddr =
  57712. + nptxfifosize.b.startaddr + nptxfifosize.b.depth;
  57713. + for (i = 0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; i++) {
  57714. + ptxfifosize.b.depth =
  57715. + params->dev_perio_tx_fifo_size[i];
  57716. + DWC_DEBUGPL(DBG_CIL,
  57717. + "initial dtxfsiz[%d]=%08x\n", i,
  57718. + DWC_READ_REG32(&global_regs->dtxfsiz
  57719. + [i]));
  57720. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  57721. + ptxfifosize.d32);
  57722. + DWC_DEBUGPL(DBG_CIL, "new dtxfsiz[%d]=%08x\n",
  57723. + i,
  57724. + DWC_READ_REG32(&global_regs->dtxfsiz
  57725. + [i]));
  57726. + ptxfifosize.b.startaddr += ptxfifosize.b.depth;
  57727. + }
  57728. + } else {
  57729. + /*
  57730. + * Tx FIFOs These FIFOs are numbered from 1 to 15.
  57731. + * Indexes of the FIFO size module parameters in the
  57732. + * dev_tx_fifo_size array and the FIFO size registers in
  57733. + * the dtxfsiz array run from 0 to 14.
  57734. + */
  57735. +
  57736. + /* Non-periodic Tx FIFO */
  57737. + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
  57738. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  57739. +
  57740. +#ifdef DWC_UTE_CFI
  57741. + core_if->pwron_gnptxfsiz =
  57742. + (DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16);
  57743. + core_if->init_gnptxfsiz =
  57744. + params->dev_nperio_tx_fifo_size;
  57745. +#endif
  57746. + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
  57747. + nptxfifosize.b.startaddr = params->dev_rx_fifo_size;
  57748. +
  57749. + DWC_WRITE_REG32(&global_regs->gnptxfsiz,
  57750. + nptxfifosize.d32);
  57751. +
  57752. + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
  57753. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  57754. +
  57755. + txfifosize.b.startaddr =
  57756. + nptxfifosize.b.startaddr + nptxfifosize.b.depth;
  57757. +
  57758. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  57759. +
  57760. + txfifosize.b.depth =
  57761. + params->dev_tx_fifo_size[i];
  57762. +
  57763. + DWC_DEBUGPL(DBG_CIL,
  57764. + "initial dtxfsiz[%d]=%08x\n",
  57765. + i,
  57766. + DWC_READ_REG32(&global_regs->dtxfsiz
  57767. + [i]));
  57768. +
  57769. +#ifdef DWC_UTE_CFI
  57770. + core_if->pwron_txfsiz[i] =
  57771. + (DWC_READ_REG32
  57772. + (&global_regs->dtxfsiz[i]) >> 16);
  57773. + core_if->init_txfsiz[i] =
  57774. + params->dev_tx_fifo_size[i];
  57775. +#endif
  57776. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  57777. + txfifosize.d32);
  57778. +
  57779. + DWC_DEBUGPL(DBG_CIL,
  57780. + "new dtxfsiz[%d]=%08x\n",
  57781. + i,
  57782. + DWC_READ_REG32(&global_regs->dtxfsiz
  57783. + [i]));
  57784. +
  57785. + txfifosize.b.startaddr += txfifosize.b.depth;
  57786. + }
  57787. + if (core_if->snpsid <= OTG_CORE_REV_2_94a) {
  57788. + /* Calculating DFIFOCFG for Device mode to include RxFIFO and NPTXFIFO */
  57789. + gdfifocfg.d32 = DWC_READ_REG32(&global_regs->gdfifocfg);
  57790. + hwcfg3.d32 = DWC_READ_REG32(&global_regs->ghwcfg3);
  57791. + gdfifocfg.b.gdfifocfg = (DWC_READ_REG32(&global_regs->ghwcfg3) >> 16);
  57792. + DWC_WRITE_REG32(&global_regs->gdfifocfg, gdfifocfg.d32);
  57793. + rxfsiz = (DWC_READ_REG32(&global_regs->grxfsiz) & 0x0000ffff);
  57794. + nptxfsiz = (DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16);
  57795. + gdfifocfg.b.epinfobase = rxfsiz + nptxfsiz;
  57796. + DWC_WRITE_REG32(&global_regs->gdfifocfg, gdfifocfg.d32);
  57797. + }
  57798. + }
  57799. +
  57800. + /* Flush the FIFOs */
  57801. + dwc_otg_flush_tx_fifo(core_if, 0x10); /* all Tx FIFOs */
  57802. + dwc_otg_flush_rx_fifo(core_if);
  57803. +
  57804. + /* Flush the Learning Queue. */
  57805. + resetctl.b.intknqflsh = 1;
  57806. + DWC_WRITE_REG32(&core_if->core_global_regs->grstctl, resetctl.d32);
  57807. +
  57808. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable) {
  57809. + core_if->start_predict = 0;
  57810. + for (i = 0; i<= core_if->dev_if->num_in_eps; ++i) {
  57811. + core_if->nextep_seq[i] = 0xff; // 0xff - EP not active
  57812. + }
  57813. + core_if->nextep_seq[0] = 0;
  57814. + core_if->first_in_nextep_seq = 0;
  57815. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl);
  57816. + diepctl.b.nextep = 0;
  57817. + DWC_WRITE_REG32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
  57818. +
  57819. + /* Update IN Endpoint Mismatch Count by active IN NP EP count + 1 */
  57820. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  57821. + dcfg.b.epmscnt = 2;
  57822. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  57823. +
  57824. + DWC_DEBUGPL(DBG_CILV,"%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  57825. + __func__, core_if->first_in_nextep_seq);
  57826. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  57827. + DWC_DEBUGPL(DBG_CILV, "%2d ", core_if->nextep_seq[i]);
  57828. + }
  57829. + DWC_DEBUGPL(DBG_CILV,"\n");
  57830. + }
  57831. +
  57832. + /* Clear all pending Device Interrupts */
  57833. + /** @todo - if the condition needed to be checked
  57834. + * or in any case all pending interrutps should be cleared?
  57835. + */
  57836. + if (core_if->multiproc_int_enable) {
  57837. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  57838. + DWC_WRITE_REG32(&dev_if->
  57839. + dev_global_regs->diepeachintmsk[i], 0);
  57840. + }
  57841. + }
  57842. +
  57843. + for (i = 0; i < core_if->dev_if->num_out_eps; ++i) {
  57844. + DWC_WRITE_REG32(&dev_if->
  57845. + dev_global_regs->doepeachintmsk[i], 0);
  57846. + }
  57847. +
  57848. + DWC_WRITE_REG32(&dev_if->dev_global_regs->deachint, 0xFFFFFFFF);
  57849. + DWC_WRITE_REG32(&dev_if->dev_global_regs->deachintmsk, 0);
  57850. + } else {
  57851. + DWC_WRITE_REG32(&dev_if->dev_global_regs->diepmsk, 0);
  57852. + DWC_WRITE_REG32(&dev_if->dev_global_regs->doepmsk, 0);
  57853. + DWC_WRITE_REG32(&dev_if->dev_global_regs->daint, 0xFFFFFFFF);
  57854. + DWC_WRITE_REG32(&dev_if->dev_global_regs->daintmsk, 0);
  57855. + }
  57856. +
  57857. + for (i = 0; i <= dev_if->num_in_eps; i++) {
  57858. + depctl_data_t depctl;
  57859. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  57860. + if (depctl.b.epena) {
  57861. + depctl.d32 = 0;
  57862. + depctl.b.epdis = 1;
  57863. + depctl.b.snak = 1;
  57864. + } else {
  57865. + depctl.d32 = 0;
  57866. + }
  57867. +
  57868. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32);
  57869. +
  57870. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->dieptsiz, 0);
  57871. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepdma, 0);
  57872. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepint, 0xFF);
  57873. + }
  57874. +
  57875. + for (i = 0; i <= dev_if->num_out_eps; i++) {
  57876. + depctl_data_t depctl;
  57877. + depctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[i]->doepctl);
  57878. + if (depctl.b.epena) {
  57879. + dctl_data_t dctl = {.d32 = 0 };
  57880. + gintmsk_data_t gintsts = {.d32 = 0 };
  57881. + doepint_data_t doepint = {.d32 = 0 };
  57882. + dctl.b.sgoutnak = 1;
  57883. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  57884. + do {
  57885. + dwc_udelay(10);
  57886. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  57887. + } while (!gintsts.b.goutnakeff);
  57888. + gintsts.d32 = 0;
  57889. + gintsts.b.goutnakeff = 1;
  57890. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  57891. +
  57892. + depctl.d32 = 0;
  57893. + depctl.b.epdis = 1;
  57894. + depctl.b.snak = 1;
  57895. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->doepctl, depctl.d32);
  57896. + do {
  57897. + dwc_udelay(10);
  57898. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  57899. + out_ep_regs[i]->doepint);
  57900. + } while (!doepint.b.epdisabled);
  57901. +
  57902. + doepint.b.epdisabled = 1;
  57903. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->doepint, doepint.d32);
  57904. +
  57905. + dctl.d32 = 0;
  57906. + dctl.b.cgoutnak = 1;
  57907. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  57908. + } else {
  57909. + depctl.d32 = 0;
  57910. + }
  57911. +
  57912. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepctl, depctl.d32);
  57913. +
  57914. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doeptsiz, 0);
  57915. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepdma, 0);
  57916. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepint, 0xFF);
  57917. + }
  57918. +
  57919. + if (core_if->en_multiple_tx_fifo && core_if->dma_enable) {
  57920. + dev_if->non_iso_tx_thr_en = params->thr_ctl & 0x1;
  57921. + dev_if->iso_tx_thr_en = (params->thr_ctl >> 1) & 0x1;
  57922. + dev_if->rx_thr_en = (params->thr_ctl >> 2) & 0x1;
  57923. +
  57924. + dev_if->rx_thr_length = params->rx_thr_length;
  57925. + dev_if->tx_thr_length = params->tx_thr_length;
  57926. +
  57927. + dev_if->setup_desc_index = 0;
  57928. +
  57929. + dthrctl.d32 = 0;
  57930. + dthrctl.b.non_iso_thr_en = dev_if->non_iso_tx_thr_en;
  57931. + dthrctl.b.iso_thr_en = dev_if->iso_tx_thr_en;
  57932. + dthrctl.b.tx_thr_len = dev_if->tx_thr_length;
  57933. + dthrctl.b.rx_thr_en = dev_if->rx_thr_en;
  57934. + dthrctl.b.rx_thr_len = dev_if->rx_thr_length;
  57935. + dthrctl.b.ahb_thr_ratio = params->ahb_thr_ratio;
  57936. +
  57937. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dtknqr3_dthrctl,
  57938. + dthrctl.d32);
  57939. +
  57940. + DWC_DEBUGPL(DBG_CIL,
  57941. + "Non ISO Tx Thr - %d\nISO Tx Thr - %d\nRx Thr - %d\nTx Thr Len - %d\nRx Thr Len - %d\n",
  57942. + dthrctl.b.non_iso_thr_en, dthrctl.b.iso_thr_en,
  57943. + dthrctl.b.rx_thr_en, dthrctl.b.tx_thr_len,
  57944. + dthrctl.b.rx_thr_len);
  57945. +
  57946. + }
  57947. +
  57948. + dwc_otg_enable_device_interrupts(core_if);
  57949. +
  57950. + {
  57951. + diepmsk_data_t msk = {.d32 = 0 };
  57952. + msk.b.txfifoundrn = 1;
  57953. + if (core_if->multiproc_int_enable) {
  57954. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->
  57955. + diepeachintmsk[0], msk.d32, msk.d32);
  57956. + } else {
  57957. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->diepmsk,
  57958. + msk.d32, msk.d32);
  57959. + }
  57960. + }
  57961. +
  57962. + if (core_if->multiproc_int_enable) {
  57963. + /* Set NAK on Babble */
  57964. + dctl_data_t dctl = {.d32 = 0 };
  57965. + dctl.b.nakonbble = 1;
  57966. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, 0, dctl.d32);
  57967. + }
  57968. +
  57969. + if (core_if->snpsid >= OTG_CORE_REV_2_94a) {
  57970. + dctl_data_t dctl = {.d32 = 0 };
  57971. + dctl.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dctl);
  57972. + dctl.b.sftdiscon = 0;
  57973. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dctl, dctl.d32);
  57974. + }
  57975. +}
  57976. +
  57977. +/**
  57978. + * This function enables the Host mode interrupts.
  57979. + *
  57980. + * @param core_if Programming view of DWC_otg controller
  57981. + */
  57982. +void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t * core_if)
  57983. +{
  57984. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  57985. + gintmsk_data_t intr_mask = {.d32 = 0 };
  57986. +
  57987. + DWC_DEBUGPL(DBG_CIL, "%s(%p)\n", __func__, core_if);
  57988. +
  57989. + /* Disable all interrupts. */
  57990. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  57991. +
  57992. + /* Clear any pending interrupts. */
  57993. + DWC_WRITE_REG32(&global_regs->gintsts, 0xFFFFFFFF);
  57994. +
  57995. + /* Enable the common interrupts */
  57996. + dwc_otg_enable_common_interrupts(core_if);
  57997. +
  57998. + /*
  57999. + * Enable host mode interrupts without disturbing common
  58000. + * interrupts.
  58001. + */
  58002. +
  58003. + intr_mask.b.disconnect = 1;
  58004. + intr_mask.b.portintr = 1;
  58005. + intr_mask.b.hcintr = 1;
  58006. +
  58007. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
  58008. +}
  58009. +
  58010. +/**
  58011. + * This function disables the Host Mode interrupts.
  58012. + *
  58013. + * @param core_if Programming view of DWC_otg controller
  58014. + */
  58015. +void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t * core_if)
  58016. +{
  58017. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  58018. + gintmsk_data_t intr_mask = {.d32 = 0 };
  58019. +
  58020. + DWC_DEBUGPL(DBG_CILV, "%s()\n", __func__);
  58021. +
  58022. + /*
  58023. + * Disable host mode interrupts without disturbing common
  58024. + * interrupts.
  58025. + */
  58026. + intr_mask.b.sofintr = 1;
  58027. + intr_mask.b.portintr = 1;
  58028. + intr_mask.b.hcintr = 1;
  58029. + intr_mask.b.ptxfempty = 1;
  58030. + intr_mask.b.nptxfempty = 1;
  58031. +
  58032. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32, 0);
  58033. +}
  58034. +
  58035. +/**
  58036. + * This function initializes the DWC_otg controller registers for
  58037. + * host mode.
  58038. + *
  58039. + * This function flushes the Tx and Rx FIFOs and it flushes any entries in the
  58040. + * request queues. Host channels are reset to ensure that they are ready for
  58041. + * performing transfers.
  58042. + *
  58043. + * @param core_if Programming view of DWC_otg controller
  58044. + *
  58045. + */
  58046. +void dwc_otg_core_host_init(dwc_otg_core_if_t * core_if)
  58047. +{
  58048. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  58049. + dwc_otg_host_if_t *host_if = core_if->host_if;
  58050. + dwc_otg_core_params_t *params = core_if->core_params;
  58051. + hprt0_data_t hprt0 = {.d32 = 0 };
  58052. + fifosize_data_t nptxfifosize;
  58053. + fifosize_data_t ptxfifosize;
  58054. + uint16_t rxfsiz, nptxfsiz, hptxfsiz;
  58055. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  58056. + int i;
  58057. + hcchar_data_t hcchar;
  58058. + hcfg_data_t hcfg;
  58059. + hfir_data_t hfir;
  58060. + dwc_otg_hc_regs_t *hc_regs;
  58061. + int num_channels;
  58062. + gotgctl_data_t gotgctl = {.d32 = 0 };
  58063. +
  58064. + DWC_DEBUGPL(DBG_CILV, "%s(%p)\n", __func__, core_if);
  58065. +
  58066. + /* Restart the Phy Clock */
  58067. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  58068. +
  58069. + /* Initialize Host Configuration Register */
  58070. + init_fslspclksel(core_if);
  58071. + if (core_if->core_params->speed == DWC_SPEED_PARAM_FULL) {
  58072. + hcfg.d32 = DWC_READ_REG32(&host_if->host_global_regs->hcfg);
  58073. + hcfg.b.fslssupp = 1;
  58074. + DWC_WRITE_REG32(&host_if->host_global_regs->hcfg, hcfg.d32);
  58075. +
  58076. + }
  58077. +
  58078. + /* This bit allows dynamic reloading of the HFIR register
  58079. + * during runtime. This bit needs to be programmed during
  58080. + * initial configuration and its value must not be changed
  58081. + * during runtime.*/
  58082. + if (core_if->core_params->reload_ctl == 1) {
  58083. + hfir.d32 = DWC_READ_REG32(&host_if->host_global_regs->hfir);
  58084. + hfir.b.hfirrldctrl = 1;
  58085. + DWC_WRITE_REG32(&host_if->host_global_regs->hfir, hfir.d32);
  58086. + }
  58087. +
  58088. + if (core_if->core_params->dma_desc_enable) {
  58089. + uint8_t op_mode = core_if->hwcfg2.b.op_mode;
  58090. + if (!
  58091. + (core_if->hwcfg4.b.desc_dma
  58092. + && (core_if->snpsid >= OTG_CORE_REV_2_90a)
  58093. + && ((op_mode == DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  58094. + || (op_mode == DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG)
  58095. + || (op_mode ==
  58096. + DWC_HWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE_OTG)
  58097. + || (op_mode == DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)
  58098. + || (op_mode ==
  58099. + DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST)))) {
  58100. +
  58101. + DWC_ERROR("Host can't operate in Descriptor DMA mode.\n"
  58102. + "Either core version is below 2.90a or "
  58103. + "GHWCFG2, GHWCFG4 registers' values do not allow Descriptor DMA in host mode.\n"
  58104. + "To run the driver in Buffer DMA host mode set dma_desc_enable "
  58105. + "module parameter to 0.\n");
  58106. + return;
  58107. + }
  58108. + hcfg.d32 = DWC_READ_REG32(&host_if->host_global_regs->hcfg);
  58109. + hcfg.b.descdma = 1;
  58110. + DWC_WRITE_REG32(&host_if->host_global_regs->hcfg, hcfg.d32);
  58111. + }
  58112. +
  58113. + /* Configure data FIFO sizes */
  58114. + if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
  58115. + DWC_DEBUGPL(DBG_CIL, "Total FIFO Size=%d\n",
  58116. + core_if->total_fifo_size);
  58117. + DWC_DEBUGPL(DBG_CIL, "Rx FIFO Size=%d\n",
  58118. + params->host_rx_fifo_size);
  58119. + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO Size=%d\n",
  58120. + params->host_nperio_tx_fifo_size);
  58121. + DWC_DEBUGPL(DBG_CIL, "P Tx FIFO Size=%d\n",
  58122. + params->host_perio_tx_fifo_size);
  58123. +
  58124. + /* Rx FIFO */
  58125. + DWC_DEBUGPL(DBG_CIL, "initial grxfsiz=%08x\n",
  58126. + DWC_READ_REG32(&global_regs->grxfsiz));
  58127. + DWC_WRITE_REG32(&global_regs->grxfsiz,
  58128. + params->host_rx_fifo_size);
  58129. + DWC_DEBUGPL(DBG_CIL, "new grxfsiz=%08x\n",
  58130. + DWC_READ_REG32(&global_regs->grxfsiz));
  58131. +
  58132. + /* Non-periodic Tx FIFO */
  58133. + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
  58134. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  58135. + nptxfifosize.b.depth = params->host_nperio_tx_fifo_size;
  58136. + nptxfifosize.b.startaddr = params->host_rx_fifo_size;
  58137. + DWC_WRITE_REG32(&global_regs->gnptxfsiz, nptxfifosize.d32);
  58138. + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
  58139. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  58140. +
  58141. + /* Periodic Tx FIFO */
  58142. + DWC_DEBUGPL(DBG_CIL, "initial hptxfsiz=%08x\n",
  58143. + DWC_READ_REG32(&global_regs->hptxfsiz));
  58144. + ptxfifosize.b.depth = params->host_perio_tx_fifo_size;
  58145. + ptxfifosize.b.startaddr =
  58146. + nptxfifosize.b.startaddr + nptxfifosize.b.depth;
  58147. + DWC_WRITE_REG32(&global_regs->hptxfsiz, ptxfifosize.d32);
  58148. + DWC_DEBUGPL(DBG_CIL, "new hptxfsiz=%08x\n",
  58149. + DWC_READ_REG32(&global_regs->hptxfsiz));
  58150. +
  58151. + if (core_if->en_multiple_tx_fifo
  58152. + && core_if->snpsid <= OTG_CORE_REV_2_94a) {
  58153. + /* Global DFIFOCFG calculation for Host mode - include RxFIFO, NPTXFIFO and HPTXFIFO */
  58154. + gdfifocfg.d32 = DWC_READ_REG32(&global_regs->gdfifocfg);
  58155. + rxfsiz = (DWC_READ_REG32(&global_regs->grxfsiz) & 0x0000ffff);
  58156. + nptxfsiz = (DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16);
  58157. + hptxfsiz = (DWC_READ_REG32(&global_regs->hptxfsiz) >> 16);
  58158. + gdfifocfg.b.epinfobase = rxfsiz + nptxfsiz + hptxfsiz;
  58159. + DWC_WRITE_REG32(&global_regs->gdfifocfg, gdfifocfg.d32);
  58160. + }
  58161. + }
  58162. +
  58163. + /* TODO - check this */
  58164. + /* Clear Host Set HNP Enable in the OTG Control Register */
  58165. + gotgctl.b.hstsethnpen = 1;
  58166. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  58167. + /* Make sure the FIFOs are flushed. */
  58168. + dwc_otg_flush_tx_fifo(core_if, 0x10 /* all TX FIFOs */ );
  58169. + dwc_otg_flush_rx_fifo(core_if);
  58170. +
  58171. + /* Clear Host Set HNP Enable in the OTG Control Register */
  58172. + gotgctl.b.hstsethnpen = 1;
  58173. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  58174. +
  58175. + if (!core_if->core_params->dma_desc_enable) {
  58176. + /* Flush out any leftover queued requests. */
  58177. + num_channels = core_if->core_params->host_channels;
  58178. +
  58179. + for (i = 0; i < num_channels; i++) {
  58180. + hc_regs = core_if->host_if->hc_regs[i];
  58181. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58182. + hcchar.b.chen = 0;
  58183. + hcchar.b.chdis = 1;
  58184. + hcchar.b.epdir = 0;
  58185. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  58186. + }
  58187. +
  58188. + /* Halt all channels to put them into a known state. */
  58189. + for (i = 0; i < num_channels; i++) {
  58190. + int count = 0;
  58191. + hc_regs = core_if->host_if->hc_regs[i];
  58192. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58193. + hcchar.b.chen = 1;
  58194. + hcchar.b.chdis = 1;
  58195. + hcchar.b.epdir = 0;
  58196. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  58197. + DWC_DEBUGPL(DBG_HCDV, "%s: Halt channel %d regs %p\n", __func__, i, hc_regs);
  58198. + do {
  58199. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58200. + if (++count > 1000) {
  58201. + DWC_ERROR
  58202. + ("%s: Unable to clear halt on channel %d (timeout HCCHAR 0x%X @%p)\n",
  58203. + __func__, i, hcchar.d32, &hc_regs->hcchar);
  58204. + break;
  58205. + }
  58206. + dwc_udelay(1);
  58207. + } while (hcchar.b.chen);
  58208. + }
  58209. + }
  58210. +
  58211. + /* Turn on the vbus power. */
  58212. + DWC_PRINTF("Init: Port Power? op_state=%d\n", core_if->op_state);
  58213. + if (core_if->op_state == A_HOST) {
  58214. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  58215. + DWC_PRINTF("Init: Power Port (%d)\n", hprt0.b.prtpwr);
  58216. + if (hprt0.b.prtpwr == 0) {
  58217. + hprt0.b.prtpwr = 1;
  58218. + DWC_WRITE_REG32(host_if->hprt0, hprt0.d32);
  58219. + }
  58220. + }
  58221. +
  58222. + dwc_otg_enable_host_interrupts(core_if);
  58223. +}
  58224. +
  58225. +/**
  58226. + * Prepares a host channel for transferring packets to/from a specific
  58227. + * endpoint. The HCCHARn register is set up with the characteristics specified
  58228. + * in _hc. Host channel interrupts that may need to be serviced while this
  58229. + * transfer is in progress are enabled.
  58230. + *
  58231. + * @param core_if Programming view of DWC_otg controller
  58232. + * @param hc Information needed to initialize the host channel
  58233. + */
  58234. +void dwc_otg_hc_init(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  58235. +{
  58236. + uint32_t intr_enable;
  58237. + hcintmsk_data_t hc_intr_mask;
  58238. + gintmsk_data_t gintmsk = {.d32 = 0 };
  58239. + hcchar_data_t hcchar;
  58240. + hcsplt_data_t hcsplt;
  58241. +
  58242. + uint8_t hc_num = hc->hc_num;
  58243. + dwc_otg_host_if_t *host_if = core_if->host_if;
  58244. + dwc_otg_hc_regs_t *hc_regs = host_if->hc_regs[hc_num];
  58245. +
  58246. + /* Clear old interrupt conditions for this host channel. */
  58247. + hc_intr_mask.d32 = 0xFFFFFFFF;
  58248. + hc_intr_mask.b.reserved14_31 = 0;
  58249. + DWC_WRITE_REG32(&hc_regs->hcint, hc_intr_mask.d32);
  58250. +
  58251. + /* Enable channel interrupts required for this transfer. */
  58252. + hc_intr_mask.d32 = 0;
  58253. + hc_intr_mask.b.chhltd = 1;
  58254. + if (core_if->dma_enable) {
  58255. + /* For Descriptor DMA mode core halts the channel on AHB error. Interrupt is not required */
  58256. + if (!core_if->dma_desc_enable)
  58257. + hc_intr_mask.b.ahberr = 1;
  58258. + else {
  58259. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  58260. + hc_intr_mask.b.xfercompl = 1;
  58261. + }
  58262. +
  58263. + if (hc->error_state && !hc->do_split &&
  58264. + hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
  58265. + hc_intr_mask.b.ack = 1;
  58266. + if (hc->ep_is_in) {
  58267. + hc_intr_mask.b.datatglerr = 1;
  58268. + if (hc->ep_type != DWC_OTG_EP_TYPE_INTR) {
  58269. + hc_intr_mask.b.nak = 1;
  58270. + }
  58271. + }
  58272. + }
  58273. + } else {
  58274. + switch (hc->ep_type) {
  58275. + case DWC_OTG_EP_TYPE_CONTROL:
  58276. + case DWC_OTG_EP_TYPE_BULK:
  58277. + hc_intr_mask.b.xfercompl = 1;
  58278. + hc_intr_mask.b.stall = 1;
  58279. + hc_intr_mask.b.xacterr = 1;
  58280. + hc_intr_mask.b.datatglerr = 1;
  58281. + if (hc->ep_is_in) {
  58282. + hc_intr_mask.b.bblerr = 1;
  58283. + } else {
  58284. + hc_intr_mask.b.nak = 1;
  58285. + hc_intr_mask.b.nyet = 1;
  58286. + if (hc->do_ping) {
  58287. + hc_intr_mask.b.ack = 1;
  58288. + }
  58289. + }
  58290. +
  58291. + if (hc->do_split) {
  58292. + hc_intr_mask.b.nak = 1;
  58293. + if (hc->complete_split) {
  58294. + hc_intr_mask.b.nyet = 1;
  58295. + } else {
  58296. + hc_intr_mask.b.ack = 1;
  58297. + }
  58298. + }
  58299. +
  58300. + if (hc->error_state) {
  58301. + hc_intr_mask.b.ack = 1;
  58302. + }
  58303. + break;
  58304. + case DWC_OTG_EP_TYPE_INTR:
  58305. + hc_intr_mask.b.xfercompl = 1;
  58306. + hc_intr_mask.b.nak = 1;
  58307. + hc_intr_mask.b.stall = 1;
  58308. + hc_intr_mask.b.xacterr = 1;
  58309. + hc_intr_mask.b.datatglerr = 1;
  58310. + hc_intr_mask.b.frmovrun = 1;
  58311. +
  58312. + if (hc->ep_is_in) {
  58313. + hc_intr_mask.b.bblerr = 1;
  58314. + }
  58315. + if (hc->error_state) {
  58316. + hc_intr_mask.b.ack = 1;
  58317. + }
  58318. + if (hc->do_split) {
  58319. + if (hc->complete_split) {
  58320. + hc_intr_mask.b.nyet = 1;
  58321. + } else {
  58322. + hc_intr_mask.b.ack = 1;
  58323. + }
  58324. + }
  58325. + break;
  58326. + case DWC_OTG_EP_TYPE_ISOC:
  58327. + hc_intr_mask.b.xfercompl = 1;
  58328. + hc_intr_mask.b.frmovrun = 1;
  58329. + hc_intr_mask.b.ack = 1;
  58330. +
  58331. + if (hc->ep_is_in) {
  58332. + hc_intr_mask.b.xacterr = 1;
  58333. + hc_intr_mask.b.bblerr = 1;
  58334. + }
  58335. + break;
  58336. + }
  58337. + }
  58338. + DWC_WRITE_REG32(&hc_regs->hcintmsk, hc_intr_mask.d32);
  58339. +
  58340. + /* Enable the top level host channel interrupt. */
  58341. + intr_enable = (1 << hc_num);
  58342. + DWC_MODIFY_REG32(&host_if->host_global_regs->haintmsk, 0, intr_enable);
  58343. +
  58344. + /* Make sure host channel interrupts are enabled. */
  58345. + gintmsk.b.hcintr = 1;
  58346. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, gintmsk.d32);
  58347. +
  58348. + /*
  58349. + * Program the HCCHARn register with the endpoint characteristics for
  58350. + * the current transfer.
  58351. + */
  58352. + hcchar.d32 = 0;
  58353. + hcchar.b.devaddr = hc->dev_addr;
  58354. + hcchar.b.epnum = hc->ep_num;
  58355. + hcchar.b.epdir = hc->ep_is_in;
  58356. + hcchar.b.lspddev = (hc->speed == DWC_OTG_EP_SPEED_LOW);
  58357. + hcchar.b.eptype = hc->ep_type;
  58358. + hcchar.b.mps = hc->max_packet;
  58359. +
  58360. + DWC_WRITE_REG32(&host_if->hc_regs[hc_num]->hcchar, hcchar.d32);
  58361. +
  58362. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d, Dev Addr %d, EP #%d\n",
  58363. + __func__, hc->hc_num, hcchar.b.devaddr, hcchar.b.epnum);
  58364. + DWC_DEBUGPL(DBG_HCDV, " Is In %d, Is Low Speed %d, EP Type %d, "
  58365. + "Max Pkt %d, Multi Cnt %d\n",
  58366. + hcchar.b.epdir, hcchar.b.lspddev, hcchar.b.eptype,
  58367. + hcchar.b.mps, hcchar.b.multicnt);
  58368. +
  58369. + /*
  58370. + * Program the HCSPLIT register for SPLITs
  58371. + */
  58372. + hcsplt.d32 = 0;
  58373. + if (hc->do_split) {
  58374. + DWC_DEBUGPL(DBG_HCDV, "Programming HC %d with split --> %s\n",
  58375. + hc->hc_num,
  58376. + hc->complete_split ? "CSPLIT" : "SSPLIT");
  58377. + hcsplt.b.compsplt = hc->complete_split;
  58378. + hcsplt.b.xactpos = hc->xact_pos;
  58379. + hcsplt.b.hubaddr = hc->hub_addr;
  58380. + hcsplt.b.prtaddr = hc->port_addr;
  58381. + DWC_DEBUGPL(DBG_HCDV, "\t comp split %d\n", hc->complete_split);
  58382. + DWC_DEBUGPL(DBG_HCDV, "\t xact pos %d\n", hc->xact_pos);
  58383. + DWC_DEBUGPL(DBG_HCDV, "\t hub addr %d\n", hc->hub_addr);
  58384. + DWC_DEBUGPL(DBG_HCDV, "\t port addr %d\n", hc->port_addr);
  58385. + DWC_DEBUGPL(DBG_HCDV, "\t is_in %d\n", hc->ep_is_in);
  58386. + DWC_DEBUGPL(DBG_HCDV, "\t Max Pkt: %d\n", hcchar.b.mps);
  58387. + DWC_DEBUGPL(DBG_HCDV, "\t xferlen: %d\n", hc->xfer_len);
  58388. + }
  58389. + DWC_WRITE_REG32(&host_if->hc_regs[hc_num]->hcsplt, hcsplt.d32);
  58390. +
  58391. +}
  58392. +
  58393. +/**
  58394. + * Attempts to halt a host channel. This function should only be called in
  58395. + * Slave mode or to abort a transfer in either Slave mode or DMA mode. Under
  58396. + * normal circumstances in DMA mode, the controller halts the channel when the
  58397. + * transfer is complete or a condition occurs that requires application
  58398. + * intervention.
  58399. + *
  58400. + * In slave mode, checks for a free request queue entry, then sets the Channel
  58401. + * Enable and Channel Disable bits of the Host Channel Characteristics
  58402. + * register of the specified channel to intiate the halt. If there is no free
  58403. + * request queue entry, sets only the Channel Disable bit of the HCCHARn
  58404. + * register to flush requests for this channel. In the latter case, sets a
  58405. + * flag to indicate that the host channel needs to be halted when a request
  58406. + * queue slot is open.
  58407. + *
  58408. + * In DMA mode, always sets the Channel Enable and Channel Disable bits of the
  58409. + * HCCHARn register. The controller ensures there is space in the request
  58410. + * queue before submitting the halt request.
  58411. + *
  58412. + * Some time may elapse before the core flushes any posted requests for this
  58413. + * host channel and halts. The Channel Halted interrupt handler completes the
  58414. + * deactivation of the host channel.
  58415. + *
  58416. + * @param core_if Controller register interface.
  58417. + * @param hc Host channel to halt.
  58418. + * @param halt_status Reason for halting the channel.
  58419. + */
  58420. +void dwc_otg_hc_halt(dwc_otg_core_if_t * core_if,
  58421. + dwc_hc_t * hc, dwc_otg_halt_status_e halt_status)
  58422. +{
  58423. + gnptxsts_data_t nptxsts;
  58424. + hptxsts_data_t hptxsts;
  58425. + hcchar_data_t hcchar;
  58426. + dwc_otg_hc_regs_t *hc_regs;
  58427. + dwc_otg_core_global_regs_t *global_regs;
  58428. + dwc_otg_host_global_regs_t *host_global_regs;
  58429. +
  58430. + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  58431. + global_regs = core_if->core_global_regs;
  58432. + host_global_regs = core_if->host_if->host_global_regs;
  58433. +
  58434. + DWC_ASSERT(!(halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS),
  58435. + "halt_status = %d\n", halt_status);
  58436. +
  58437. + if (halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE ||
  58438. + halt_status == DWC_OTG_HC_XFER_AHB_ERR) {
  58439. + /*
  58440. + * Disable all channel interrupts except Ch Halted. The QTD
  58441. + * and QH state associated with this transfer has been cleared
  58442. + * (in the case of URB_DEQUEUE), so the channel needs to be
  58443. + * shut down carefully to prevent crashes.
  58444. + */
  58445. + hcintmsk_data_t hcintmsk;
  58446. + hcintmsk.d32 = 0;
  58447. + hcintmsk.b.chhltd = 1;
  58448. + DWC_WRITE_REG32(&hc_regs->hcintmsk, hcintmsk.d32);
  58449. +
  58450. + /*
  58451. + * Make sure no other interrupts besides halt are currently
  58452. + * pending. Handling another interrupt could cause a crash due
  58453. + * to the QTD and QH state.
  58454. + */
  58455. + DWC_WRITE_REG32(&hc_regs->hcint, ~hcintmsk.d32);
  58456. +
  58457. + /*
  58458. + * Make sure the halt status is set to URB_DEQUEUE or AHB_ERR
  58459. + * even if the channel was already halted for some other
  58460. + * reason.
  58461. + */
  58462. + hc->halt_status = halt_status;
  58463. +
  58464. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58465. + if (hcchar.b.chen == 0) {
  58466. + /*
  58467. + * The channel is either already halted or it hasn't
  58468. + * started yet. In DMA mode, the transfer may halt if
  58469. + * it finishes normally or a condition occurs that
  58470. + * requires driver intervention. Don't want to halt
  58471. + * the channel again. In either Slave or DMA mode,
  58472. + * it's possible that the transfer has been assigned
  58473. + * to a channel, but not started yet when an URB is
  58474. + * dequeued. Don't want to halt a channel that hasn't
  58475. + * started yet.
  58476. + */
  58477. + return;
  58478. + }
  58479. + }
  58480. + if (hc->halt_pending) {
  58481. + /*
  58482. + * A halt has already been issued for this channel. This might
  58483. + * happen when a transfer is aborted by a higher level in
  58484. + * the stack.
  58485. + */
  58486. +#ifdef DEBUG
  58487. + DWC_PRINTF
  58488. + ("*** %s: Channel %d, _hc->halt_pending already set ***\n",
  58489. + __func__, hc->hc_num);
  58490. +
  58491. +#endif
  58492. + return;
  58493. + }
  58494. +
  58495. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58496. +
  58497. + /* No need to set the bit in DDMA for disabling the channel */
  58498. + //TODO check it everywhere channel is disabled
  58499. + if (!core_if->core_params->dma_desc_enable)
  58500. + hcchar.b.chen = 1;
  58501. + hcchar.b.chdis = 1;
  58502. +
  58503. + if (!core_if->dma_enable) {
  58504. + /* Check for space in the request queue to issue the halt. */
  58505. + if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
  58506. + hc->ep_type == DWC_OTG_EP_TYPE_BULK) {
  58507. + nptxsts.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  58508. + if (nptxsts.b.nptxqspcavail == 0) {
  58509. + hcchar.b.chen = 0;
  58510. + }
  58511. + } else {
  58512. + hptxsts.d32 =
  58513. + DWC_READ_REG32(&host_global_regs->hptxsts);
  58514. + if ((hptxsts.b.ptxqspcavail == 0)
  58515. + || (core_if->queuing_high_bandwidth)) {
  58516. + hcchar.b.chen = 0;
  58517. + }
  58518. + }
  58519. + }
  58520. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  58521. +
  58522. + hc->halt_status = halt_status;
  58523. +
  58524. + if (hcchar.b.chen) {
  58525. + hc->halt_pending = 1;
  58526. + hc->halt_on_queue = 0;
  58527. + } else {
  58528. + hc->halt_on_queue = 1;
  58529. + }
  58530. +
  58531. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  58532. + DWC_DEBUGPL(DBG_HCDV, " hcchar: 0x%08x\n", hcchar.d32);
  58533. + DWC_DEBUGPL(DBG_HCDV, " halt_pending: %d\n", hc->halt_pending);
  58534. + DWC_DEBUGPL(DBG_HCDV, " halt_on_queue: %d\n", hc->halt_on_queue);
  58535. + DWC_DEBUGPL(DBG_HCDV, " halt_status: %d\n", hc->halt_status);
  58536. +
  58537. + return;
  58538. +}
  58539. +
  58540. +/**
  58541. + * Clears the transfer state for a host channel. This function is normally
  58542. + * called after a transfer is done and the host channel is being released.
  58543. + *
  58544. + * @param core_if Programming view of DWC_otg controller.
  58545. + * @param hc Identifies the host channel to clean up.
  58546. + */
  58547. +void dwc_otg_hc_cleanup(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  58548. +{
  58549. + dwc_otg_hc_regs_t *hc_regs;
  58550. +
  58551. + hc->xfer_started = 0;
  58552. +
  58553. + /*
  58554. + * Clear channel interrupt enables and any unhandled channel interrupt
  58555. + * conditions.
  58556. + */
  58557. + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  58558. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0);
  58559. + DWC_WRITE_REG32(&hc_regs->hcint, 0xFFFFFFFF);
  58560. +#ifdef DEBUG
  58561. + DWC_TIMER_CANCEL(core_if->hc_xfer_timer[hc->hc_num]);
  58562. +#endif
  58563. +}
  58564. +
  58565. +/**
  58566. + * Sets the channel property that indicates in which frame a periodic transfer
  58567. + * should occur. This is always set to the _next_ frame. This function has no
  58568. + * effect on non-periodic transfers.
  58569. + *
  58570. + * @param core_if Programming view of DWC_otg controller.
  58571. + * @param hc Identifies the host channel to set up and its properties.
  58572. + * @param hcchar Current value of the HCCHAR register for the specified host
  58573. + * channel.
  58574. + */
  58575. +static inline void hc_set_even_odd_frame(dwc_otg_core_if_t * core_if,
  58576. + dwc_hc_t * hc, hcchar_data_t * hcchar)
  58577. +{
  58578. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  58579. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  58580. + hfnum_data_t hfnum;
  58581. + hfnum.d32 =
  58582. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hfnum);
  58583. +
  58584. + /* 1 if _next_ frame is odd, 0 if it's even */
  58585. + hcchar->b.oddfrm = (hfnum.b.frnum & 0x1) ? 0 : 1;
  58586. +#ifdef DEBUG
  58587. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR && hc->do_split
  58588. + && !hc->complete_split) {
  58589. + switch (hfnum.b.frnum & 0x7) {
  58590. + case 7:
  58591. + core_if->hfnum_7_samples++;
  58592. + core_if->hfnum_7_frrem_accum += hfnum.b.frrem;
  58593. + break;
  58594. + case 0:
  58595. + core_if->hfnum_0_samples++;
  58596. + core_if->hfnum_0_frrem_accum += hfnum.b.frrem;
  58597. + break;
  58598. + default:
  58599. + core_if->hfnum_other_samples++;
  58600. + core_if->hfnum_other_frrem_accum +=
  58601. + hfnum.b.frrem;
  58602. + break;
  58603. + }
  58604. + }
  58605. +#endif
  58606. + }
  58607. +}
  58608. +
  58609. +#ifdef DEBUG
  58610. +void hc_xfer_timeout(void *ptr)
  58611. +{
  58612. + hc_xfer_info_t *xfer_info = NULL;
  58613. + int hc_num = 0;
  58614. +
  58615. + if (ptr)
  58616. + xfer_info = (hc_xfer_info_t *) ptr;
  58617. +
  58618. + if (!xfer_info->hc) {
  58619. + DWC_ERROR("xfer_info->hc = %p\n", xfer_info->hc);
  58620. + return;
  58621. + }
  58622. +
  58623. + hc_num = xfer_info->hc->hc_num;
  58624. + DWC_WARN("%s: timeout on channel %d\n", __func__, hc_num);
  58625. + DWC_WARN(" start_hcchar_val 0x%08x\n",
  58626. + xfer_info->core_if->start_hcchar_val[hc_num]);
  58627. +}
  58628. +#endif
  58629. +
  58630. +void ep_xfer_timeout(void *ptr)
  58631. +{
  58632. + ep_xfer_info_t *xfer_info = NULL;
  58633. + int ep_num = 0;
  58634. + dctl_data_t dctl = {.d32 = 0 };
  58635. + gintsts_data_t gintsts = {.d32 = 0 };
  58636. + gintmsk_data_t gintmsk = {.d32 = 0 };
  58637. +
  58638. + if (ptr)
  58639. + xfer_info = (ep_xfer_info_t *) ptr;
  58640. +
  58641. + if (!xfer_info->ep) {
  58642. + DWC_ERROR("xfer_info->ep = %p\n", xfer_info->ep);
  58643. + return;
  58644. + }
  58645. +
  58646. + ep_num = xfer_info->ep->num;
  58647. + DWC_WARN("%s: timeout on endpoit %d\n", __func__, ep_num);
  58648. + /* Put the sate to 2 as it was time outed */
  58649. + xfer_info->state = 2;
  58650. +
  58651. + dctl.d32 =
  58652. + DWC_READ_REG32(&xfer_info->core_if->dev_if->dev_global_regs->dctl);
  58653. + gintsts.d32 =
  58654. + DWC_READ_REG32(&xfer_info->core_if->core_global_regs->gintsts);
  58655. + gintmsk.d32 =
  58656. + DWC_READ_REG32(&xfer_info->core_if->core_global_regs->gintmsk);
  58657. +
  58658. + if (!gintmsk.b.goutnakeff) {
  58659. + /* Unmask it */
  58660. + gintmsk.b.goutnakeff = 1;
  58661. + DWC_WRITE_REG32(&xfer_info->core_if->core_global_regs->gintmsk,
  58662. + gintmsk.d32);
  58663. +
  58664. + }
  58665. +
  58666. + if (!gintsts.b.goutnakeff) {
  58667. + dctl.b.sgoutnak = 1;
  58668. + }
  58669. + DWC_WRITE_REG32(&xfer_info->core_if->dev_if->dev_global_regs->dctl,
  58670. + dctl.d32);
  58671. +
  58672. +}
  58673. +
  58674. +void set_pid_isoc(dwc_hc_t * hc)
  58675. +{
  58676. + /* Set up the initial PID for the transfer. */
  58677. + if (hc->speed == DWC_OTG_EP_SPEED_HIGH) {
  58678. + if (hc->ep_is_in) {
  58679. + if (hc->multi_count == 1) {
  58680. + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
  58681. + } else if (hc->multi_count == 2) {
  58682. + hc->data_pid_start = DWC_OTG_HC_PID_DATA1;
  58683. + } else {
  58684. + hc->data_pid_start = DWC_OTG_HC_PID_DATA2;
  58685. + }
  58686. + } else {
  58687. + if (hc->multi_count == 1) {
  58688. + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
  58689. + } else {
  58690. + hc->data_pid_start = DWC_OTG_HC_PID_MDATA;
  58691. + }
  58692. + }
  58693. + } else {
  58694. + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
  58695. + }
  58696. +}
  58697. +
  58698. +/**
  58699. + * This function does the setup for a data transfer for a host channel and
  58700. + * starts the transfer. May be called in either Slave mode or DMA mode. In
  58701. + * Slave mode, the caller must ensure that there is sufficient space in the
  58702. + * request queue and Tx Data FIFO.
  58703. + *
  58704. + * For an OUT transfer in Slave mode, it loads a data packet into the
  58705. + * appropriate FIFO. If necessary, additional data packets will be loaded in
  58706. + * the Host ISR.
  58707. + *
  58708. + * For an IN transfer in Slave mode, a data packet is requested. The data
  58709. + * packets are unloaded from the Rx FIFO in the Host ISR. If necessary,
  58710. + * additional data packets are requested in the Host ISR.
  58711. + *
  58712. + * For a PING transfer in Slave mode, the Do Ping bit is set in the HCTSIZ
  58713. + * register along with a packet count of 1 and the channel is enabled. This
  58714. + * causes a single PING transaction to occur. Other fields in HCTSIZ are
  58715. + * simply set to 0 since no data transfer occurs in this case.
  58716. + *
  58717. + * For a PING transfer in DMA mode, the HCTSIZ register is initialized with
  58718. + * all the information required to perform the subsequent data transfer. In
  58719. + * addition, the Do Ping bit is set in the HCTSIZ register. In this case, the
  58720. + * controller performs the entire PING protocol, then starts the data
  58721. + * transfer.
  58722. + *
  58723. + * @param core_if Programming view of DWC_otg controller.
  58724. + * @param hc Information needed to initialize the host channel. The xfer_len
  58725. + * value may be reduced to accommodate the max widths of the XferSize and
  58726. + * PktCnt fields in the HCTSIZn register. The multi_count value may be changed
  58727. + * to reflect the final xfer_len value.
  58728. + */
  58729. +void dwc_otg_hc_start_transfer(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  58730. +{
  58731. + hcchar_data_t hcchar;
  58732. + hctsiz_data_t hctsiz;
  58733. + uint16_t num_packets;
  58734. + uint32_t max_hc_xfer_size = core_if->core_params->max_transfer_size;
  58735. + uint16_t max_hc_pkt_count = core_if->core_params->max_packet_count;
  58736. + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  58737. +
  58738. + hctsiz.d32 = 0;
  58739. +
  58740. + if (hc->do_ping) {
  58741. + if (!core_if->dma_enable) {
  58742. + dwc_otg_hc_do_ping(core_if, hc);
  58743. + hc->xfer_started = 1;
  58744. + return;
  58745. + } else {
  58746. + hctsiz.b.dopng = 1;
  58747. + }
  58748. + }
  58749. +
  58750. + if (hc->do_split) {
  58751. + num_packets = 1;
  58752. +
  58753. + if (hc->complete_split && !hc->ep_is_in) {
  58754. + /* For CSPLIT OUT Transfer, set the size to 0 so the
  58755. + * core doesn't expect any data written to the FIFO */
  58756. + hc->xfer_len = 0;
  58757. + } else if (hc->ep_is_in || (hc->xfer_len > hc->max_packet)) {
  58758. + hc->xfer_len = hc->max_packet;
  58759. + } else if (!hc->ep_is_in && (hc->xfer_len > 188)) {
  58760. + hc->xfer_len = 188;
  58761. + }
  58762. +
  58763. + hctsiz.b.xfersize = hc->xfer_len;
  58764. + } else {
  58765. + /*
  58766. + * Ensure that the transfer length and packet count will fit
  58767. + * in the widths allocated for them in the HCTSIZn register.
  58768. + */
  58769. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  58770. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  58771. + /*
  58772. + * Make sure the transfer size is no larger than one
  58773. + * (micro)frame's worth of data. (A check was done
  58774. + * when the periodic transfer was accepted to ensure
  58775. + * that a (micro)frame's worth of data can be
  58776. + * programmed into a channel.)
  58777. + */
  58778. + uint32_t max_periodic_len =
  58779. + hc->multi_count * hc->max_packet;
  58780. + if (hc->xfer_len > max_periodic_len) {
  58781. + hc->xfer_len = max_periodic_len;
  58782. + } else {
  58783. + }
  58784. + } else if (hc->xfer_len > max_hc_xfer_size) {
  58785. + /* Make sure that xfer_len is a multiple of max packet size. */
  58786. + hc->xfer_len = max_hc_xfer_size - hc->max_packet + 1;
  58787. + }
  58788. +
  58789. + if (hc->xfer_len > 0) {
  58790. + num_packets =
  58791. + (hc->xfer_len + hc->max_packet -
  58792. + 1) / hc->max_packet;
  58793. + if (num_packets > max_hc_pkt_count) {
  58794. + num_packets = max_hc_pkt_count;
  58795. + hc->xfer_len = num_packets * hc->max_packet;
  58796. + }
  58797. + } else {
  58798. + /* Need 1 packet for transfer length of 0. */
  58799. + num_packets = 1;
  58800. + }
  58801. +
  58802. + if (hc->ep_is_in) {
  58803. + /* Always program an integral # of max packets for IN transfers. */
  58804. + hc->xfer_len = num_packets * hc->max_packet;
  58805. + }
  58806. +
  58807. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  58808. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  58809. + /*
  58810. + * Make sure that the multi_count field matches the
  58811. + * actual transfer length.
  58812. + */
  58813. + hc->multi_count = num_packets;
  58814. + }
  58815. +
  58816. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  58817. + set_pid_isoc(hc);
  58818. +
  58819. + hctsiz.b.xfersize = hc->xfer_len;
  58820. + }
  58821. +
  58822. + hc->start_pkt_count = num_packets;
  58823. + hctsiz.b.pktcnt = num_packets;
  58824. + hctsiz.b.pid = hc->data_pid_start;
  58825. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  58826. +
  58827. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  58828. + DWC_DEBUGPL(DBG_HCDV, " Xfer Size: %d\n", hctsiz.b.xfersize);
  58829. + DWC_DEBUGPL(DBG_HCDV, " Num Pkts: %d\n", hctsiz.b.pktcnt);
  58830. + DWC_DEBUGPL(DBG_HCDV, " Start PID: %d\n", hctsiz.b.pid);
  58831. +
  58832. + if (core_if->dma_enable) {
  58833. + dwc_dma_t dma_addr;
  58834. + if (hc->align_buff) {
  58835. + dma_addr = hc->align_buff;
  58836. + } else {
  58837. + dma_addr = ((unsigned long)hc->xfer_buff & 0xffffffff);
  58838. + }
  58839. + DWC_WRITE_REG32(&hc_regs->hcdma, dma_addr);
  58840. + }
  58841. +
  58842. + /* Start the split */
  58843. + if (hc->do_split) {
  58844. + hcsplt_data_t hcsplt;
  58845. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  58846. + hcsplt.b.spltena = 1;
  58847. + DWC_WRITE_REG32(&hc_regs->hcsplt, hcsplt.d32);
  58848. + }
  58849. +
  58850. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58851. + hcchar.b.multicnt = hc->multi_count;
  58852. + hc_set_even_odd_frame(core_if, hc, &hcchar);
  58853. +#ifdef DEBUG
  58854. + core_if->start_hcchar_val[hc->hc_num] = hcchar.d32;
  58855. + if (hcchar.b.chdis) {
  58856. + DWC_WARN("%s: chdis set, channel %d, hcchar 0x%08x\n",
  58857. + __func__, hc->hc_num, hcchar.d32);
  58858. + }
  58859. +#endif
  58860. +
  58861. + /* Set host channel enable after all other setup is complete. */
  58862. + hcchar.b.chen = 1;
  58863. + hcchar.b.chdis = 0;
  58864. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  58865. +
  58866. + hc->xfer_started = 1;
  58867. + hc->requests++;
  58868. +
  58869. + if (!core_if->dma_enable && !hc->ep_is_in && hc->xfer_len > 0) {
  58870. + /* Load OUT packet into the appropriate Tx FIFO. */
  58871. + dwc_otg_hc_write_packet(core_if, hc);
  58872. + }
  58873. +#ifdef DEBUG
  58874. + if (hc->ep_type != DWC_OTG_EP_TYPE_INTR) {
  58875. + DWC_DEBUGPL(DBG_HCDV, "transfer %d from core_if %p\n",
  58876. + hc->hc_num, core_if);//GRAYG
  58877. + core_if->hc_xfer_info[hc->hc_num].core_if = core_if;
  58878. + core_if->hc_xfer_info[hc->hc_num].hc = hc;
  58879. +
  58880. + /* Start a timer for this transfer. */
  58881. + DWC_TIMER_SCHEDULE(core_if->hc_xfer_timer[hc->hc_num], 10000);
  58882. + }
  58883. +#endif
  58884. +}
  58885. +
  58886. +/**
  58887. + * This function does the setup for a data transfer for a host channel
  58888. + * and starts the transfer in Descriptor DMA mode.
  58889. + *
  58890. + * Initializes HCTSIZ register. For a PING transfer the Do Ping bit is set.
  58891. + * Sets PID and NTD values. For periodic transfers
  58892. + * initializes SCHED_INFO field with micro-frame bitmap.
  58893. + *
  58894. + * Initializes HCDMA register with descriptor list address and CTD value
  58895. + * then starts the transfer via enabling the channel.
  58896. + *
  58897. + * @param core_if Programming view of DWC_otg controller.
  58898. + * @param hc Information needed to initialize the host channel.
  58899. + */
  58900. +void dwc_otg_hc_start_transfer_ddma(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  58901. +{
  58902. + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  58903. + hcchar_data_t hcchar;
  58904. + hctsiz_data_t hctsiz;
  58905. + hcdma_data_t hcdma;
  58906. +
  58907. + hctsiz.d32 = 0;
  58908. +
  58909. + if (hc->do_ping)
  58910. + hctsiz.b_ddma.dopng = 1;
  58911. +
  58912. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  58913. + set_pid_isoc(hc);
  58914. +
  58915. + /* Packet Count and Xfer Size are not used in Descriptor DMA mode */
  58916. + hctsiz.b_ddma.pid = hc->data_pid_start;
  58917. + hctsiz.b_ddma.ntd = hc->ntd - 1; /* 0 - 1 descriptor, 1 - 2 descriptors, etc. */
  58918. + hctsiz.b_ddma.schinfo = hc->schinfo; /* Non-zero only for high-speed interrupt endpoints */
  58919. +
  58920. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  58921. + DWC_DEBUGPL(DBG_HCDV, " Start PID: %d\n", hctsiz.b.pid);
  58922. + DWC_DEBUGPL(DBG_HCDV, " NTD: %d\n", hctsiz.b_ddma.ntd);
  58923. +
  58924. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  58925. +
  58926. + hcdma.d32 = 0;
  58927. + hcdma.b.dma_addr = ((uint32_t) hc->desc_list_addr) >> 11;
  58928. +
  58929. + /* Always start from first descriptor. */
  58930. + hcdma.b.ctd = 0;
  58931. + DWC_WRITE_REG32(&hc_regs->hcdma, hcdma.d32);
  58932. +
  58933. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58934. + hcchar.b.multicnt = hc->multi_count;
  58935. +
  58936. +#ifdef DEBUG
  58937. + core_if->start_hcchar_val[hc->hc_num] = hcchar.d32;
  58938. + if (hcchar.b.chdis) {
  58939. + DWC_WARN("%s: chdis set, channel %d, hcchar 0x%08x\n",
  58940. + __func__, hc->hc_num, hcchar.d32);
  58941. + }
  58942. +#endif
  58943. +
  58944. + /* Set host channel enable after all other setup is complete. */
  58945. + hcchar.b.chen = 1;
  58946. + hcchar.b.chdis = 0;
  58947. +
  58948. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  58949. +
  58950. + hc->xfer_started = 1;
  58951. + hc->requests++;
  58952. +
  58953. +#ifdef DEBUG
  58954. + if ((hc->ep_type != DWC_OTG_EP_TYPE_INTR)
  58955. + && (hc->ep_type != DWC_OTG_EP_TYPE_ISOC)) {
  58956. + DWC_DEBUGPL(DBG_HCDV, "DMA transfer %d from core_if %p\n",
  58957. + hc->hc_num, core_if);//GRAYG
  58958. + core_if->hc_xfer_info[hc->hc_num].core_if = core_if;
  58959. + core_if->hc_xfer_info[hc->hc_num].hc = hc;
  58960. + /* Start a timer for this transfer. */
  58961. + DWC_TIMER_SCHEDULE(core_if->hc_xfer_timer[hc->hc_num], 10000);
  58962. + }
  58963. +#endif
  58964. +
  58965. +}
  58966. +
  58967. +/**
  58968. + * This function continues a data transfer that was started by previous call
  58969. + * to <code>dwc_otg_hc_start_transfer</code>. The caller must ensure there is
  58970. + * sufficient space in the request queue and Tx Data FIFO. This function
  58971. + * should only be called in Slave mode. In DMA mode, the controller acts
  58972. + * autonomously to complete transfers programmed to a host channel.
  58973. + *
  58974. + * For an OUT transfer, a new data packet is loaded into the appropriate FIFO
  58975. + * if there is any data remaining to be queued. For an IN transfer, another
  58976. + * data packet is always requested. For the SETUP phase of a control transfer,
  58977. + * this function does nothing.
  58978. + *
  58979. + * @return 1 if a new request is queued, 0 if no more requests are required
  58980. + * for this transfer.
  58981. + */
  58982. +int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  58983. +{
  58984. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  58985. +
  58986. + if (hc->do_split) {
  58987. + /* SPLITs always queue just once per channel */
  58988. + return 0;
  58989. + } else if (hc->data_pid_start == DWC_OTG_HC_PID_SETUP) {
  58990. + /* SETUPs are queued only once since they can't be NAKed. */
  58991. + return 0;
  58992. + } else if (hc->ep_is_in) {
  58993. + /*
  58994. + * Always queue another request for other IN transfers. If
  58995. + * back-to-back INs are issued and NAKs are received for both,
  58996. + * the driver may still be processing the first NAK when the
  58997. + * second NAK is received. When the interrupt handler clears
  58998. + * the NAK interrupt for the first NAK, the second NAK will
  58999. + * not be seen. So we can't depend on the NAK interrupt
  59000. + * handler to requeue a NAKed request. Instead, IN requests
  59001. + * are issued each time this function is called. When the
  59002. + * transfer completes, the extra requests for the channel will
  59003. + * be flushed.
  59004. + */
  59005. + hcchar_data_t hcchar;
  59006. + dwc_otg_hc_regs_t *hc_regs =
  59007. + core_if->host_if->hc_regs[hc->hc_num];
  59008. +
  59009. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  59010. + hc_set_even_odd_frame(core_if, hc, &hcchar);
  59011. + hcchar.b.chen = 1;
  59012. + hcchar.b.chdis = 0;
  59013. + DWC_DEBUGPL(DBG_HCDV, " IN xfer: hcchar = 0x%08x\n",
  59014. + hcchar.d32);
  59015. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  59016. + hc->requests++;
  59017. + return 1;
  59018. + } else {
  59019. + /* OUT transfers. */
  59020. + if (hc->xfer_count < hc->xfer_len) {
  59021. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  59022. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  59023. + hcchar_data_t hcchar;
  59024. + dwc_otg_hc_regs_t *hc_regs;
  59025. + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  59026. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  59027. + hc_set_even_odd_frame(core_if, hc, &hcchar);
  59028. + }
  59029. +
  59030. + /* Load OUT packet into the appropriate Tx FIFO. */
  59031. + dwc_otg_hc_write_packet(core_if, hc);
  59032. + hc->requests++;
  59033. + return 1;
  59034. + } else {
  59035. + return 0;
  59036. + }
  59037. + }
  59038. +}
  59039. +
  59040. +/**
  59041. + * Starts a PING transfer. This function should only be called in Slave mode.
  59042. + * The Do Ping bit is set in the HCTSIZ register, then the channel is enabled.
  59043. + */
  59044. +void dwc_otg_hc_do_ping(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  59045. +{
  59046. + hcchar_data_t hcchar;
  59047. + hctsiz_data_t hctsiz;
  59048. + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  59049. +
  59050. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  59051. +
  59052. + hctsiz.d32 = 0;
  59053. + hctsiz.b.dopng = 1;
  59054. + hctsiz.b.pktcnt = 1;
  59055. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  59056. +
  59057. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  59058. + hcchar.b.chen = 1;
  59059. + hcchar.b.chdis = 0;
  59060. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  59061. +}
  59062. +
  59063. +/*
  59064. + * This function writes a packet into the Tx FIFO associated with the Host
  59065. + * Channel. For a channel associated with a non-periodic EP, the non-periodic
  59066. + * Tx FIFO is written. For a channel associated with a periodic EP, the
  59067. + * periodic Tx FIFO is written. This function should only be called in Slave
  59068. + * mode.
  59069. + *
  59070. + * Upon return the xfer_buff and xfer_count fields in _hc are incremented by
  59071. + * then number of bytes written to the Tx FIFO.
  59072. + */
  59073. +void dwc_otg_hc_write_packet(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  59074. +{
  59075. + uint32_t i;
  59076. + uint32_t remaining_count;
  59077. + uint32_t byte_count;
  59078. + uint32_t dword_count;
  59079. +
  59080. + uint32_t *data_buff = (uint32_t *) (hc->xfer_buff);
  59081. + uint32_t *data_fifo = core_if->data_fifo[hc->hc_num];
  59082. +
  59083. + remaining_count = hc->xfer_len - hc->xfer_count;
  59084. + if (remaining_count > hc->max_packet) {
  59085. + byte_count = hc->max_packet;
  59086. + } else {
  59087. + byte_count = remaining_count;
  59088. + }
  59089. +
  59090. + dword_count = (byte_count + 3) / 4;
  59091. +
  59092. + if ((((unsigned long)data_buff) & 0x3) == 0) {
  59093. + /* xfer_buff is DWORD aligned. */
  59094. + for (i = 0; i < dword_count; i++, data_buff++) {
  59095. + DWC_WRITE_REG32(data_fifo, *data_buff);
  59096. + }
  59097. + } else {
  59098. + /* xfer_buff is not DWORD aligned. */
  59099. + for (i = 0; i < dword_count; i++, data_buff++) {
  59100. + uint32_t data;
  59101. + data =
  59102. + (data_buff[0] | data_buff[1] << 8 | data_buff[2] <<
  59103. + 16 | data_buff[3] << 24);
  59104. + DWC_WRITE_REG32(data_fifo, data);
  59105. + }
  59106. + }
  59107. +
  59108. + hc->xfer_count += byte_count;
  59109. + hc->xfer_buff += byte_count;
  59110. +}
  59111. +
  59112. +/**
  59113. + * Gets the current USB frame number. This is the frame number from the last
  59114. + * SOF packet.
  59115. + */
  59116. +uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t * core_if)
  59117. +{
  59118. + dsts_data_t dsts;
  59119. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  59120. +
  59121. + /* read current frame/microframe number from DSTS register */
  59122. + return dsts.b.soffn;
  59123. +}
  59124. +
  59125. +/**
  59126. + * Calculates and gets the frame Interval value of HFIR register according PHY
  59127. + * type and speed.The application can modify a value of HFIR register only after
  59128. + * the Port Enable bit of the Host Port Control and Status register
  59129. + * (HPRT.PrtEnaPort) has been set.
  59130. +*/
  59131. +
  59132. +uint32_t calc_frame_interval(dwc_otg_core_if_t * core_if)
  59133. +{
  59134. + gusbcfg_data_t usbcfg;
  59135. + hwcfg2_data_t hwcfg2;
  59136. + hprt0_data_t hprt0;
  59137. + int clock = 60; // default value
  59138. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  59139. + hwcfg2.d32 = DWC_READ_REG32(&core_if->core_global_regs->ghwcfg2);
  59140. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  59141. + if (!usbcfg.b.physel && usbcfg.b.ulpi_utmi_sel && !usbcfg.b.phyif)
  59142. + clock = 60;
  59143. + if (usbcfg.b.physel && hwcfg2.b.fs_phy_type == 3)
  59144. + clock = 48;
  59145. + if (!usbcfg.b.phylpwrclksel && !usbcfg.b.physel &&
  59146. + !usbcfg.b.ulpi_utmi_sel && usbcfg.b.phyif)
  59147. + clock = 30;
  59148. + if (!usbcfg.b.phylpwrclksel && !usbcfg.b.physel &&
  59149. + !usbcfg.b.ulpi_utmi_sel && !usbcfg.b.phyif)
  59150. + clock = 60;
  59151. + if (usbcfg.b.phylpwrclksel && !usbcfg.b.physel &&
  59152. + !usbcfg.b.ulpi_utmi_sel && usbcfg.b.phyif)
  59153. + clock = 48;
  59154. + if (usbcfg.b.physel && !usbcfg.b.phyif && hwcfg2.b.fs_phy_type == 2)
  59155. + clock = 48;
  59156. + if (usbcfg.b.physel && hwcfg2.b.fs_phy_type == 1)
  59157. + clock = 48;
  59158. + if (hprt0.b.prtspd == 0)
  59159. + /* High speed case */
  59160. + return 125 * clock;
  59161. + else
  59162. + /* FS/LS case */
  59163. + return 1000 * clock;
  59164. +}
  59165. +
  59166. +/**
  59167. + * This function reads a setup packet from the Rx FIFO into the destination
  59168. + * buffer. This function is called from the Rx Status Queue Level (RxStsQLvl)
  59169. + * Interrupt routine when a SETUP packet has been received in Slave mode.
  59170. + *
  59171. + * @param core_if Programming view of DWC_otg controller.
  59172. + * @param dest Destination buffer for packet data.
  59173. + */
  59174. +void dwc_otg_read_setup_packet(dwc_otg_core_if_t * core_if, uint32_t * dest)
  59175. +{
  59176. + device_grxsts_data_t status;
  59177. + /* Get the 8 bytes of a setup transaction data */
  59178. +
  59179. + /* Pop 2 DWORDS off the receive data FIFO into memory */
  59180. + dest[0] = DWC_READ_REG32(core_if->data_fifo[0]);
  59181. + dest[1] = DWC_READ_REG32(core_if->data_fifo[0]);
  59182. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  59183. + status.d32 =
  59184. + DWC_READ_REG32(&core_if->core_global_regs->grxstsp);
  59185. + DWC_DEBUGPL(DBG_ANY,
  59186. + "EP:%d BCnt:%d " "pktsts:%x Frame:%d(0x%0x)\n",
  59187. + status.b.epnum, status.b.bcnt, status.b.pktsts,
  59188. + status.b.fn, status.b.fn);
  59189. + }
  59190. +}
  59191. +
  59192. +/**
  59193. + * This function enables EP0 OUT to receive SETUP packets and configures EP0
  59194. + * IN for transmitting packets. It is normally called when the
  59195. + * "Enumeration Done" interrupt occurs.
  59196. + *
  59197. + * @param core_if Programming view of DWC_otg controller.
  59198. + * @param ep The EP0 data.
  59199. + */
  59200. +void dwc_otg_ep0_activate(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  59201. +{
  59202. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  59203. + dsts_data_t dsts;
  59204. + depctl_data_t diepctl;
  59205. + depctl_data_t doepctl;
  59206. + dctl_data_t dctl = {.d32 = 0 };
  59207. +
  59208. + ep->stp_rollover = 0;
  59209. + /* Read the Device Status and Endpoint 0 Control registers */
  59210. + dsts.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dsts);
  59211. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl);
  59212. + doepctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl);
  59213. +
  59214. + /* Set the MPS of the IN EP based on the enumeration speed */
  59215. + switch (dsts.b.enumspd) {
  59216. + case DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ:
  59217. + case DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ:
  59218. + case DWC_DSTS_ENUMSPD_FS_PHY_48MHZ:
  59219. + diepctl.b.mps = DWC_DEP0CTL_MPS_64;
  59220. + break;
  59221. + case DWC_DSTS_ENUMSPD_LS_PHY_6MHZ:
  59222. + diepctl.b.mps = DWC_DEP0CTL_MPS_8;
  59223. + break;
  59224. + }
  59225. +
  59226. + DWC_WRITE_REG32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
  59227. +
  59228. + /* Enable OUT EP for receive */
  59229. + if (core_if->snpsid <= OTG_CORE_REV_2_94a) {
  59230. + doepctl.b.epena = 1;
  59231. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepctl, doepctl.d32);
  59232. + }
  59233. +#ifdef VERBOSE
  59234. + DWC_DEBUGPL(DBG_PCDV, "doepctl0=%0x\n",
  59235. + DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl));
  59236. + DWC_DEBUGPL(DBG_PCDV, "diepctl0=%0x\n",
  59237. + DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl));
  59238. +#endif
  59239. + dctl.b.cgnpinnak = 1;
  59240. +
  59241. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  59242. + DWC_DEBUGPL(DBG_PCDV, "dctl=%0x\n",
  59243. + DWC_READ_REG32(&dev_if->dev_global_regs->dctl));
  59244. +
  59245. +}
  59246. +
  59247. +/**
  59248. + * This function activates an EP. The Device EP control register for
  59249. + * the EP is configured as defined in the ep structure. Note: This
  59250. + * function is not used for EP0.
  59251. + *
  59252. + * @param core_if Programming view of DWC_otg controller.
  59253. + * @param ep The EP to activate.
  59254. + */
  59255. +void dwc_otg_ep_activate(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  59256. +{
  59257. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  59258. + depctl_data_t depctl;
  59259. + volatile uint32_t *addr;
  59260. + daint_data_t daintmsk = {.d32 = 0 };
  59261. + dcfg_data_t dcfg;
  59262. + uint8_t i;
  59263. +
  59264. + DWC_DEBUGPL(DBG_PCDV, "%s() EP%d-%s\n", __func__, ep->num,
  59265. + (ep->is_in ? "IN" : "OUT"));
  59266. +
  59267. +#ifdef DWC_UTE_PER_IO
  59268. + ep->xiso_frame_num = 0xFFFFFFFF;
  59269. + ep->xiso_active_xfers = 0;
  59270. + ep->xiso_queued_xfers = 0;
  59271. +#endif
  59272. + /* Read DEPCTLn register */
  59273. + if (ep->is_in == 1) {
  59274. + addr = &dev_if->in_ep_regs[ep->num]->diepctl;
  59275. + daintmsk.ep.in = 1 << ep->num;
  59276. + } else {
  59277. + addr = &dev_if->out_ep_regs[ep->num]->doepctl;
  59278. + daintmsk.ep.out = 1 << ep->num;
  59279. + }
  59280. +
  59281. + /* If the EP is already active don't change the EP Control
  59282. + * register. */
  59283. + depctl.d32 = DWC_READ_REG32(addr);
  59284. + if (!depctl.b.usbactep) {
  59285. + depctl.b.mps = ep->maxpacket;
  59286. + depctl.b.eptype = ep->type;
  59287. + depctl.b.txfnum = ep->tx_fifo_num;
  59288. +
  59289. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  59290. + depctl.b.setd0pid = 1; // ???
  59291. + } else {
  59292. + depctl.b.setd0pid = 1;
  59293. + }
  59294. + depctl.b.usbactep = 1;
  59295. +
  59296. + /* Update nextep_seq array and EPMSCNT in DCFG*/
  59297. + if (!(depctl.b.eptype & 1) && (ep->is_in == 1)) { // NP IN EP
  59298. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  59299. + if (core_if->nextep_seq[i] == core_if->first_in_nextep_seq)
  59300. + break;
  59301. + }
  59302. + core_if->nextep_seq[i] = ep->num;
  59303. + core_if->nextep_seq[ep->num] = core_if->first_in_nextep_seq;
  59304. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  59305. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  59306. + dcfg.b.epmscnt++;
  59307. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  59308. +
  59309. + DWC_DEBUGPL(DBG_PCDV,
  59310. + "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  59311. + __func__, core_if->first_in_nextep_seq);
  59312. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  59313. + DWC_DEBUGPL(DBG_PCDV, "%2d\n",
  59314. + core_if->nextep_seq[i]);
  59315. + }
  59316. +
  59317. + }
  59318. +
  59319. +
  59320. + DWC_WRITE_REG32(addr, depctl.d32);
  59321. + DWC_DEBUGPL(DBG_PCDV, "DEPCTL=%08x\n", DWC_READ_REG32(addr));
  59322. + }
  59323. +
  59324. + /* Enable the Interrupt for this EP */
  59325. + if (core_if->multiproc_int_enable) {
  59326. + if (ep->is_in == 1) {
  59327. + diepmsk_data_t diepmsk = {.d32 = 0 };
  59328. + diepmsk.b.xfercompl = 1;
  59329. + diepmsk.b.timeout = 1;
  59330. + diepmsk.b.epdisabled = 1;
  59331. + diepmsk.b.ahberr = 1;
  59332. + diepmsk.b.intknepmis = 1;
  59333. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable)
  59334. + diepmsk.b.intknepmis = 0;
  59335. + diepmsk.b.txfifoundrn = 1; //?????
  59336. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  59337. + diepmsk.b.nak = 1;
  59338. + }
  59339. +
  59340. +
  59341. +
  59342. +/*
  59343. + if (core_if->dma_desc_enable) {
  59344. + diepmsk.b.bna = 1;
  59345. + }
  59346. +*/
  59347. +/*
  59348. + if (core_if->dma_enable) {
  59349. + doepmsk.b.nak = 1;
  59350. + }
  59351. +*/
  59352. + DWC_WRITE_REG32(&dev_if->dev_global_regs->
  59353. + diepeachintmsk[ep->num], diepmsk.d32);
  59354. +
  59355. + } else {
  59356. + doepmsk_data_t doepmsk = {.d32 = 0 };
  59357. + doepmsk.b.xfercompl = 1;
  59358. + doepmsk.b.ahberr = 1;
  59359. + doepmsk.b.epdisabled = 1;
  59360. + if (ep->type == DWC_OTG_EP_TYPE_ISOC)
  59361. + doepmsk.b.outtknepdis = 1;
  59362. +
  59363. +/*
  59364. +
  59365. + if (core_if->dma_desc_enable) {
  59366. + doepmsk.b.bna = 1;
  59367. + }
  59368. +*/
  59369. +/*
  59370. + doepmsk.b.babble = 1;
  59371. + doepmsk.b.nyet = 1;
  59372. + doepmsk.b.nak = 1;
  59373. +*/
  59374. + DWC_WRITE_REG32(&dev_if->dev_global_regs->
  59375. + doepeachintmsk[ep->num], doepmsk.d32);
  59376. + }
  59377. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->deachintmsk,
  59378. + 0, daintmsk.d32);
  59379. + } else {
  59380. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  59381. + if (ep->is_in) {
  59382. + diepmsk_data_t diepmsk = {.d32 = 0 };
  59383. + diepmsk.b.nak = 1;
  59384. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->diepmsk, 0, diepmsk.d32);
  59385. + } else {
  59386. + doepmsk_data_t doepmsk = {.d32 = 0 };
  59387. + doepmsk.b.outtknepdis = 1;
  59388. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->doepmsk, 0, doepmsk.d32);
  59389. + }
  59390. + }
  59391. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->daintmsk,
  59392. + 0, daintmsk.d32);
  59393. + }
  59394. +
  59395. + DWC_DEBUGPL(DBG_PCDV, "DAINTMSK=%0x\n",
  59396. + DWC_READ_REG32(&dev_if->dev_global_regs->daintmsk));
  59397. +
  59398. + ep->stall_clear_flag = 0;
  59399. +
  59400. + return;
  59401. +}
  59402. +
  59403. +/**
  59404. + * This function deactivates an EP. This is done by clearing the USB Active
  59405. + * EP bit in the Device EP control register. Note: This function is not used
  59406. + * for EP0. EP0 cannot be deactivated.
  59407. + *
  59408. + * @param core_if Programming view of DWC_otg controller.
  59409. + * @param ep The EP to deactivate.
  59410. + */
  59411. +void dwc_otg_ep_deactivate(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  59412. +{
  59413. + depctl_data_t depctl = {.d32 = 0 };
  59414. + volatile uint32_t *addr;
  59415. + daint_data_t daintmsk = {.d32 = 0 };
  59416. + dcfg_data_t dcfg;
  59417. + uint8_t i = 0;
  59418. +
  59419. +#ifdef DWC_UTE_PER_IO
  59420. + ep->xiso_frame_num = 0xFFFFFFFF;
  59421. + ep->xiso_active_xfers = 0;
  59422. + ep->xiso_queued_xfers = 0;
  59423. +#endif
  59424. +
  59425. + /* Read DEPCTLn register */
  59426. + if (ep->is_in == 1) {
  59427. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  59428. + daintmsk.ep.in = 1 << ep->num;
  59429. + } else {
  59430. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  59431. + daintmsk.ep.out = 1 << ep->num;
  59432. + }
  59433. +
  59434. + depctl.d32 = DWC_READ_REG32(addr);
  59435. +
  59436. + depctl.b.usbactep = 0;
  59437. +
  59438. + /* Update nextep_seq array and EPMSCNT in DCFG*/
  59439. + if (!(depctl.b.eptype & 1) && ep->is_in == 1) { // NP EP IN
  59440. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  59441. + if (core_if->nextep_seq[i] == ep->num)
  59442. + break;
  59443. + }
  59444. + core_if->nextep_seq[i] = core_if->nextep_seq[ep->num];
  59445. + if (core_if->first_in_nextep_seq == ep->num)
  59446. + core_if->first_in_nextep_seq = i;
  59447. + core_if->nextep_seq[ep->num] = 0xff;
  59448. + depctl.b.nextep = 0;
  59449. + dcfg.d32 =
  59450. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  59451. + dcfg.b.epmscnt--;
  59452. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg,
  59453. + dcfg.d32);
  59454. +
  59455. + DWC_DEBUGPL(DBG_PCDV,
  59456. + "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  59457. + __func__, core_if->first_in_nextep_seq);
  59458. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  59459. + DWC_DEBUGPL(DBG_PCDV, "%2d\n", core_if->nextep_seq[i]);
  59460. + }
  59461. + }
  59462. +
  59463. + if (ep->is_in == 1)
  59464. + depctl.b.txfnum = 0;
  59465. +
  59466. + if (core_if->dma_desc_enable)
  59467. + depctl.b.epdis = 1;
  59468. +
  59469. + DWC_WRITE_REG32(addr, depctl.d32);
  59470. + depctl.d32 = DWC_READ_REG32(addr);
  59471. + if (core_if->dma_enable && ep->type == DWC_OTG_EP_TYPE_ISOC
  59472. + && depctl.b.epena) {
  59473. + depctl_data_t depctl = {.d32 = 0};
  59474. + if (ep->is_in) {
  59475. + diepint_data_t diepint = {.d32 = 0};
  59476. +
  59477. + depctl.b.snak = 1;
  59478. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  59479. + diepctl, depctl.d32);
  59480. + do {
  59481. + dwc_udelay(10);
  59482. + diepint.d32 =
  59483. + DWC_READ_REG32(&core_if->
  59484. + dev_if->in_ep_regs[ep->num]->
  59485. + diepint);
  59486. + } while (!diepint.b.inepnakeff);
  59487. + diepint.b.inepnakeff = 1;
  59488. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  59489. + diepint, diepint.d32);
  59490. + depctl.d32 = 0;
  59491. + depctl.b.epdis = 1;
  59492. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  59493. + diepctl, depctl.d32);
  59494. + do {
  59495. + dwc_udelay(10);
  59496. + diepint.d32 =
  59497. + DWC_READ_REG32(&core_if->
  59498. + dev_if->in_ep_regs[ep->num]->
  59499. + diepint);
  59500. + } while (!diepint.b.epdisabled);
  59501. + diepint.b.epdisabled = 1;
  59502. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  59503. + diepint, diepint.d32);
  59504. + } else {
  59505. + dctl_data_t dctl = {.d32 = 0};
  59506. + gintmsk_data_t gintsts = {.d32 = 0};
  59507. + doepint_data_t doepint = {.d32 = 0};
  59508. + dctl.b.sgoutnak = 1;
  59509. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  59510. + dctl, 0, dctl.d32);
  59511. + do {
  59512. + dwc_udelay(10);
  59513. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  59514. + } while (!gintsts.b.goutnakeff);
  59515. + gintsts.d32 = 0;
  59516. + gintsts.b.goutnakeff = 1;
  59517. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  59518. +
  59519. + depctl.d32 = 0;
  59520. + depctl.b.epdis = 1;
  59521. + depctl.b.snak = 1;
  59522. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[ep->num]->doepctl, depctl.d32);
  59523. + do
  59524. + {
  59525. + dwc_udelay(10);
  59526. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  59527. + out_ep_regs[ep->num]->doepint);
  59528. + } while (!doepint.b.epdisabled);
  59529. +
  59530. + doepint.b.epdisabled = 1;
  59531. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[ep->num]->doepint, doepint.d32);
  59532. +
  59533. + dctl.d32 = 0;
  59534. + dctl.b.cgoutnak = 1;
  59535. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  59536. + }
  59537. + }
  59538. +
  59539. + /* Disable the Interrupt for this EP */
  59540. + if (core_if->multiproc_int_enable) {
  59541. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->deachintmsk,
  59542. + daintmsk.d32, 0);
  59543. +
  59544. + if (ep->is_in == 1) {
  59545. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  59546. + diepeachintmsk[ep->num], 0);
  59547. + } else {
  59548. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  59549. + doepeachintmsk[ep->num], 0);
  59550. + }
  59551. + } else {
  59552. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->daintmsk,
  59553. + daintmsk.d32, 0);
  59554. + }
  59555. +
  59556. +}
  59557. +
  59558. +/**
  59559. + * This function initializes dma descriptor chain.
  59560. + *
  59561. + * @param core_if Programming view of DWC_otg controller.
  59562. + * @param ep The EP to start the transfer on.
  59563. + */
  59564. +static void init_dma_desc_chain(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  59565. +{
  59566. + dwc_otg_dev_dma_desc_t *dma_desc;
  59567. + uint32_t offset;
  59568. + uint32_t xfer_est;
  59569. + int i;
  59570. + unsigned maxxfer_local, total_len;
  59571. +
  59572. + if (!ep->is_in && ep->type == DWC_OTG_EP_TYPE_INTR &&
  59573. + (ep->maxpacket%4)) {
  59574. + maxxfer_local = ep->maxpacket;
  59575. + total_len = ep->xfer_len;
  59576. + } else {
  59577. + maxxfer_local = ep->maxxfer;
  59578. + total_len = ep->total_len;
  59579. + }
  59580. +
  59581. + ep->desc_cnt = (total_len / maxxfer_local) +
  59582. + ((total_len % maxxfer_local) ? 1 : 0);
  59583. +
  59584. + if (!ep->desc_cnt)
  59585. + ep->desc_cnt = 1;
  59586. +
  59587. + if (ep->desc_cnt > MAX_DMA_DESC_CNT)
  59588. + ep->desc_cnt = MAX_DMA_DESC_CNT;
  59589. +
  59590. + dma_desc = ep->desc_addr;
  59591. + if (maxxfer_local == ep->maxpacket) {
  59592. + if ((total_len % maxxfer_local) &&
  59593. + (total_len/maxxfer_local < MAX_DMA_DESC_CNT)) {
  59594. + xfer_est = (ep->desc_cnt - 1) * maxxfer_local +
  59595. + (total_len % maxxfer_local);
  59596. + } else
  59597. + xfer_est = ep->desc_cnt * maxxfer_local;
  59598. + } else
  59599. + xfer_est = total_len;
  59600. + offset = 0;
  59601. + for (i = 0; i < ep->desc_cnt; ++i) {
  59602. + /** DMA Descriptor Setup */
  59603. + if (xfer_est > maxxfer_local) {
  59604. + dma_desc->status.b.bs = BS_HOST_BUSY;
  59605. + dma_desc->status.b.l = 0;
  59606. + dma_desc->status.b.ioc = 0;
  59607. + dma_desc->status.b.sp = 0;
  59608. + dma_desc->status.b.bytes = maxxfer_local;
  59609. + dma_desc->buf = ep->dma_addr + offset;
  59610. + dma_desc->status.b.sts = 0;
  59611. + dma_desc->status.b.bs = BS_HOST_READY;
  59612. +
  59613. + xfer_est -= maxxfer_local;
  59614. + offset += maxxfer_local;
  59615. + } else {
  59616. + dma_desc->status.b.bs = BS_HOST_BUSY;
  59617. + dma_desc->status.b.l = 1;
  59618. + dma_desc->status.b.ioc = 1;
  59619. + if (ep->is_in) {
  59620. + dma_desc->status.b.sp =
  59621. + (xfer_est %
  59622. + ep->maxpacket) ? 1 : ((ep->
  59623. + sent_zlp) ? 1 : 0);
  59624. + dma_desc->status.b.bytes = xfer_est;
  59625. + } else {
  59626. + if (maxxfer_local == ep->maxpacket)
  59627. + dma_desc->status.b.bytes = xfer_est;
  59628. + else
  59629. + dma_desc->status.b.bytes =
  59630. + xfer_est + ((4 - (xfer_est & 0x3)) & 0x3);
  59631. + }
  59632. +
  59633. + dma_desc->buf = ep->dma_addr + offset;
  59634. + dma_desc->status.b.sts = 0;
  59635. + dma_desc->status.b.bs = BS_HOST_READY;
  59636. + }
  59637. + dma_desc++;
  59638. + }
  59639. +}
  59640. +/**
  59641. + * This function is called when to write ISOC data into appropriate dedicated
  59642. + * periodic FIFO.
  59643. + */
  59644. +static int32_t write_isoc_tx_fifo(dwc_otg_core_if_t * core_if, dwc_ep_t * dwc_ep)
  59645. +{
  59646. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  59647. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  59648. + dtxfsts_data_t txstatus = {.d32 = 0 };
  59649. + uint32_t len = 0;
  59650. + int epnum = dwc_ep->num;
  59651. + int dwords;
  59652. +
  59653. + DWC_DEBUGPL(DBG_PCD, "Dedicated TxFifo Empty: %d \n", epnum);
  59654. +
  59655. + ep_regs = core_if->dev_if->in_ep_regs[epnum];
  59656. +
  59657. + len = dwc_ep->xfer_len - dwc_ep->xfer_count;
  59658. +
  59659. + if (len > dwc_ep->maxpacket) {
  59660. + len = dwc_ep->maxpacket;
  59661. + }
  59662. +
  59663. + dwords = (len + 3) / 4;
  59664. +
  59665. + /* While there is space in the queue and space in the FIFO and
  59666. + * More data to tranfer, Write packets to the Tx FIFO */
  59667. + txstatus.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  59668. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum, txstatus.d32);
  59669. +
  59670. + while (txstatus.b.txfspcavail > dwords &&
  59671. + dwc_ep->xfer_count < dwc_ep->xfer_len && dwc_ep->xfer_len != 0) {
  59672. + /* Write the FIFO */
  59673. + dwc_otg_ep_write_packet(core_if, dwc_ep, 0);
  59674. +
  59675. + len = dwc_ep->xfer_len - dwc_ep->xfer_count;
  59676. + if (len > dwc_ep->maxpacket) {
  59677. + len = dwc_ep->maxpacket;
  59678. + }
  59679. +
  59680. + dwords = (len + 3) / 4;
  59681. + txstatus.d32 =
  59682. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  59683. + DWC_DEBUGPL(DBG_PCDV, "dtxfsts[%d]=0x%08x\n", epnum,
  59684. + txstatus.d32);
  59685. + }
  59686. +
  59687. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum,
  59688. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts));
  59689. +
  59690. + return 1;
  59691. +}
  59692. +/**
  59693. + * This function does the setup for a data transfer for an EP and
  59694. + * starts the transfer. For an IN transfer, the packets will be
  59695. + * loaded into the appropriate Tx FIFO in the ISR. For OUT transfers,
  59696. + * the packets are unloaded from the Rx FIFO in the ISR. the ISR.
  59697. + *
  59698. + * @param core_if Programming view of DWC_otg controller.
  59699. + * @param ep The EP to start the transfer on.
  59700. + */
  59701. +
  59702. +void dwc_otg_ep_start_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  59703. +{
  59704. + depctl_data_t depctl;
  59705. + deptsiz_data_t deptsiz;
  59706. + gintmsk_data_t intr_mask = {.d32 = 0 };
  59707. +
  59708. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s()\n", __func__);
  59709. + DWC_DEBUGPL(DBG_PCD, "ep%d-%s xfer_len=%d xfer_cnt=%d "
  59710. + "xfer_buff=%p start_xfer_buff=%p, total_len = %d\n",
  59711. + ep->num, (ep->is_in ? "IN" : "OUT"), ep->xfer_len,
  59712. + ep->xfer_count, ep->xfer_buff, ep->start_xfer_buff,
  59713. + ep->total_len);
  59714. + /* IN endpoint */
  59715. + if (ep->is_in == 1) {
  59716. + dwc_otg_dev_in_ep_regs_t *in_regs =
  59717. + core_if->dev_if->in_ep_regs[ep->num];
  59718. +
  59719. + gnptxsts_data_t gtxstatus;
  59720. +
  59721. + gtxstatus.d32 =
  59722. + DWC_READ_REG32(&core_if->core_global_regs->gnptxsts);
  59723. +
  59724. + if (core_if->en_multiple_tx_fifo == 0
  59725. + && gtxstatus.b.nptxqspcavail == 0 && !core_if->dma_enable) {
  59726. +#ifdef DEBUG
  59727. + DWC_PRINTF("TX Queue Full (0x%0x)\n", gtxstatus.d32);
  59728. +#endif
  59729. + return;
  59730. + }
  59731. +
  59732. + depctl.d32 = DWC_READ_REG32(&(in_regs->diepctl));
  59733. + deptsiz.d32 = DWC_READ_REG32(&(in_regs->dieptsiz));
  59734. +
  59735. + if (ep->maxpacket > ep->maxxfer / MAX_PKT_CNT)
  59736. + ep->xfer_len += (ep->maxxfer < (ep->total_len - ep->xfer_len)) ?
  59737. + ep->maxxfer : (ep->total_len - ep->xfer_len);
  59738. + else
  59739. + ep->xfer_len += (MAX_PKT_CNT * ep->maxpacket < (ep->total_len - ep->xfer_len)) ?
  59740. + MAX_PKT_CNT * ep->maxpacket : (ep->total_len - ep->xfer_len);
  59741. +
  59742. +
  59743. + /* Zero Length Packet? */
  59744. + if ((ep->xfer_len - ep->xfer_count) == 0) {
  59745. + deptsiz.b.xfersize = 0;
  59746. + deptsiz.b.pktcnt = 1;
  59747. + } else {
  59748. + /* Program the transfer size and packet count
  59749. + * as follows: xfersize = N * maxpacket +
  59750. + * short_packet pktcnt = N + (short_packet
  59751. + * exist ? 1 : 0)
  59752. + */
  59753. + deptsiz.b.xfersize = ep->xfer_len - ep->xfer_count;
  59754. + deptsiz.b.pktcnt =
  59755. + (ep->xfer_len - ep->xfer_count - 1 +
  59756. + ep->maxpacket) / ep->maxpacket;
  59757. + if (deptsiz.b.pktcnt > MAX_PKT_CNT) {
  59758. + deptsiz.b.pktcnt = MAX_PKT_CNT;
  59759. + deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
  59760. + }
  59761. + if (ep->type == DWC_OTG_EP_TYPE_ISOC)
  59762. + deptsiz.b.mc = deptsiz.b.pktcnt;
  59763. + }
  59764. +
  59765. + /* Write the DMA register */
  59766. + if (core_if->dma_enable) {
  59767. + if (core_if->dma_desc_enable == 0) {
  59768. + if (ep->type != DWC_OTG_EP_TYPE_ISOC)
  59769. + deptsiz.b.mc = 1;
  59770. + DWC_WRITE_REG32(&in_regs->dieptsiz,
  59771. + deptsiz.d32);
  59772. + DWC_WRITE_REG32(&(in_regs->diepdma),
  59773. + (uint32_t) ep->dma_addr);
  59774. + } else {
  59775. +#ifdef DWC_UTE_CFI
  59776. + /* The descriptor chain should be already initialized by now */
  59777. + if (ep->buff_mode != BM_STANDARD) {
  59778. + DWC_WRITE_REG32(&in_regs->diepdma,
  59779. + ep->descs_dma_addr);
  59780. + } else {
  59781. +#endif
  59782. + init_dma_desc_chain(core_if, ep);
  59783. + /** DIEPDMAn Register write */
  59784. + DWC_WRITE_REG32(&in_regs->diepdma,
  59785. + ep->dma_desc_addr);
  59786. +#ifdef DWC_UTE_CFI
  59787. + }
  59788. +#endif
  59789. + }
  59790. + } else {
  59791. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  59792. + if (ep->type != DWC_OTG_EP_TYPE_ISOC) {
  59793. + /**
  59794. + * Enable the Non-Periodic Tx FIFO empty interrupt,
  59795. + * or the Tx FIFO epmty interrupt in dedicated Tx FIFO mode,
  59796. + * the data will be written into the fifo by the ISR.
  59797. + */
  59798. + if (core_if->en_multiple_tx_fifo == 0) {
  59799. + intr_mask.b.nptxfempty = 1;
  59800. + DWC_MODIFY_REG32
  59801. + (&core_if->core_global_regs->gintmsk,
  59802. + intr_mask.d32, intr_mask.d32);
  59803. + } else {
  59804. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  59805. + if (ep->xfer_len > 0) {
  59806. + uint32_t fifoemptymsk = 0;
  59807. + fifoemptymsk = 1 << ep->num;
  59808. + DWC_MODIFY_REG32
  59809. + (&core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  59810. + 0, fifoemptymsk);
  59811. +
  59812. + }
  59813. + }
  59814. + } else {
  59815. + write_isoc_tx_fifo(core_if, ep);
  59816. + }
  59817. + }
  59818. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  59819. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  59820. +
  59821. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  59822. + dsts_data_t dsts = {.d32 = 0};
  59823. + if (ep->bInterval == 1) {
  59824. + dsts.d32 =
  59825. + DWC_READ_REG32(&core_if->dev_if->
  59826. + dev_global_regs->dsts);
  59827. + ep->frame_num = dsts.b.soffn + ep->bInterval;
  59828. + if (ep->frame_num > 0x3FFF) {
  59829. + ep->frm_overrun = 1;
  59830. + ep->frame_num &= 0x3FFF;
  59831. + } else
  59832. + ep->frm_overrun = 0;
  59833. + if (ep->frame_num & 0x1) {
  59834. + depctl.b.setd1pid = 1;
  59835. + } else {
  59836. + depctl.b.setd0pid = 1;
  59837. + }
  59838. + }
  59839. + }
  59840. + /* EP enable, IN data in FIFO */
  59841. + depctl.b.cnak = 1;
  59842. + depctl.b.epena = 1;
  59843. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  59844. +
  59845. + } else {
  59846. + /* OUT endpoint */
  59847. + dwc_otg_dev_out_ep_regs_t *out_regs =
  59848. + core_if->dev_if->out_ep_regs[ep->num];
  59849. +
  59850. + depctl.d32 = DWC_READ_REG32(&(out_regs->doepctl));
  59851. + deptsiz.d32 = DWC_READ_REG32(&(out_regs->doeptsiz));
  59852. +
  59853. + if (!core_if->dma_desc_enable) {
  59854. + if (ep->maxpacket > ep->maxxfer / MAX_PKT_CNT)
  59855. + ep->xfer_len += (ep->maxxfer < (ep->total_len - ep->xfer_len)) ?
  59856. + ep->maxxfer : (ep->total_len - ep->xfer_len);
  59857. + else
  59858. + ep->xfer_len += (MAX_PKT_CNT * ep->maxpacket < (ep->total_len
  59859. + - ep->xfer_len)) ? MAX_PKT_CNT * ep->maxpacket : (ep->total_len - ep->xfer_len);
  59860. + }
  59861. +
  59862. + /* Program the transfer size and packet count as follows:
  59863. + *
  59864. + * pktcnt = N
  59865. + * xfersize = N * maxpacket
  59866. + */
  59867. + if ((ep->xfer_len - ep->xfer_count) == 0) {
  59868. + /* Zero Length Packet */
  59869. + deptsiz.b.xfersize = ep->maxpacket;
  59870. + deptsiz.b.pktcnt = 1;
  59871. + } else {
  59872. + deptsiz.b.pktcnt =
  59873. + (ep->xfer_len - ep->xfer_count +
  59874. + (ep->maxpacket - 1)) / ep->maxpacket;
  59875. + if (deptsiz.b.pktcnt > MAX_PKT_CNT) {
  59876. + deptsiz.b.pktcnt = MAX_PKT_CNT;
  59877. + }
  59878. + if (!core_if->dma_desc_enable) {
  59879. + ep->xfer_len =
  59880. + deptsiz.b.pktcnt * ep->maxpacket + ep->xfer_count;
  59881. + }
  59882. + deptsiz.b.xfersize = ep->xfer_len - ep->xfer_count;
  59883. + }
  59884. +
  59885. + DWC_DEBUGPL(DBG_PCDV, "ep%d xfersize=%d pktcnt=%d\n",
  59886. + ep->num, deptsiz.b.xfersize, deptsiz.b.pktcnt);
  59887. +
  59888. + if (core_if->dma_enable) {
  59889. + if (!core_if->dma_desc_enable) {
  59890. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  59891. + deptsiz.d32);
  59892. +
  59893. + DWC_WRITE_REG32(&(out_regs->doepdma),
  59894. + (uint32_t) ep->dma_addr);
  59895. + } else {
  59896. +#ifdef DWC_UTE_CFI
  59897. + /* The descriptor chain should be already initialized by now */
  59898. + if (ep->buff_mode != BM_STANDARD) {
  59899. + DWC_WRITE_REG32(&out_regs->doepdma,
  59900. + ep->descs_dma_addr);
  59901. + } else {
  59902. +#endif
  59903. + /** This is used for interrupt out transfers*/
  59904. + if (!ep->xfer_len)
  59905. + ep->xfer_len = ep->total_len;
  59906. + init_dma_desc_chain(core_if, ep);
  59907. +
  59908. + if (core_if->core_params->dev_out_nak) {
  59909. + if (ep->type == DWC_OTG_EP_TYPE_BULK) {
  59910. + deptsiz.b.pktcnt = (ep->total_len +
  59911. + (ep->maxpacket - 1)) / ep->maxpacket;
  59912. + deptsiz.b.xfersize = ep->total_len;
  59913. + /* Remember initial value of doeptsiz */
  59914. + core_if->start_doeptsiz_val[ep->num] = deptsiz.d32;
  59915. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  59916. + deptsiz.d32);
  59917. + }
  59918. + }
  59919. + /** DOEPDMAn Register write */
  59920. + DWC_WRITE_REG32(&out_regs->doepdma,
  59921. + ep->dma_desc_addr);
  59922. +#ifdef DWC_UTE_CFI
  59923. + }
  59924. +#endif
  59925. + }
  59926. + } else {
  59927. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  59928. + }
  59929. +
  59930. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  59931. + dsts_data_t dsts = {.d32 = 0};
  59932. + if (ep->bInterval == 1) {
  59933. + dsts.d32 =
  59934. + DWC_READ_REG32(&core_if->dev_if->
  59935. + dev_global_regs->dsts);
  59936. + ep->frame_num = dsts.b.soffn + ep->bInterval;
  59937. + if (ep->frame_num > 0x3FFF) {
  59938. + ep->frm_overrun = 1;
  59939. + ep->frame_num &= 0x3FFF;
  59940. + } else
  59941. + ep->frm_overrun = 0;
  59942. +
  59943. + if (ep->frame_num & 0x1) {
  59944. + depctl.b.setd1pid = 1;
  59945. + } else {
  59946. + depctl.b.setd0pid = 1;
  59947. + }
  59948. + }
  59949. + }
  59950. +
  59951. + /* EP enable */
  59952. + depctl.b.cnak = 1;
  59953. + depctl.b.epena = 1;
  59954. +
  59955. + DWC_WRITE_REG32(&out_regs->doepctl, depctl.d32);
  59956. +
  59957. + DWC_DEBUGPL(DBG_PCD, "DOEPCTL=%08x DOEPTSIZ=%08x\n",
  59958. + DWC_READ_REG32(&out_regs->doepctl),
  59959. + DWC_READ_REG32(&out_regs->doeptsiz));
  59960. + DWC_DEBUGPL(DBG_PCD, "DAINTMSK=%08x GINTMSK=%08x\n",
  59961. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->
  59962. + daintmsk),
  59963. + DWC_READ_REG32(&core_if->core_global_regs->
  59964. + gintmsk));
  59965. +
  59966. + /* Timer is scheduling only for out bulk transfers for
  59967. + * "Device DDMA OUT NAK Enhancement" feature to inform user
  59968. + * about received data payload in case of timeout
  59969. + */
  59970. + if (core_if->core_params->dev_out_nak) {
  59971. + if (ep->type == DWC_OTG_EP_TYPE_BULK) {
  59972. + core_if->ep_xfer_info[ep->num].core_if = core_if;
  59973. + core_if->ep_xfer_info[ep->num].ep = ep;
  59974. + core_if->ep_xfer_info[ep->num].state = 1;
  59975. +
  59976. + /* Start a timer for this transfer. */
  59977. + DWC_TIMER_SCHEDULE(core_if->ep_xfer_timer[ep->num], 10000);
  59978. + }
  59979. + }
  59980. + }
  59981. +}
  59982. +
  59983. +/**
  59984. + * This function setup a zero length transfer in Buffer DMA and
  59985. + * Slave modes for usb requests with zero field set
  59986. + *
  59987. + * @param core_if Programming view of DWC_otg controller.
  59988. + * @param ep The EP to start the transfer on.
  59989. + *
  59990. + */
  59991. +void dwc_otg_ep_start_zl_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  59992. +{
  59993. +
  59994. + depctl_data_t depctl;
  59995. + deptsiz_data_t deptsiz;
  59996. + gintmsk_data_t intr_mask = {.d32 = 0 };
  59997. +
  59998. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s()\n", __func__);
  59999. + DWC_PRINTF("zero length transfer is called\n");
  60000. +
  60001. + /* IN endpoint */
  60002. + if (ep->is_in == 1) {
  60003. + dwc_otg_dev_in_ep_regs_t *in_regs =
  60004. + core_if->dev_if->in_ep_regs[ep->num];
  60005. +
  60006. + depctl.d32 = DWC_READ_REG32(&(in_regs->diepctl));
  60007. + deptsiz.d32 = DWC_READ_REG32(&(in_regs->dieptsiz));
  60008. +
  60009. + deptsiz.b.xfersize = 0;
  60010. + deptsiz.b.pktcnt = 1;
  60011. +
  60012. + /* Write the DMA register */
  60013. + if (core_if->dma_enable) {
  60014. + if (core_if->dma_desc_enable == 0) {
  60015. + deptsiz.b.mc = 1;
  60016. + DWC_WRITE_REG32(&in_regs->dieptsiz,
  60017. + deptsiz.d32);
  60018. + DWC_WRITE_REG32(&(in_regs->diepdma),
  60019. + (uint32_t) ep->dma_addr);
  60020. + }
  60021. + } else {
  60022. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  60023. + /**
  60024. + * Enable the Non-Periodic Tx FIFO empty interrupt,
  60025. + * or the Tx FIFO epmty interrupt in dedicated Tx FIFO mode,
  60026. + * the data will be written into the fifo by the ISR.
  60027. + */
  60028. + if (core_if->en_multiple_tx_fifo == 0) {
  60029. + intr_mask.b.nptxfempty = 1;
  60030. + DWC_MODIFY_REG32(&core_if->
  60031. + core_global_regs->gintmsk,
  60032. + intr_mask.d32, intr_mask.d32);
  60033. + } else {
  60034. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  60035. + if (ep->xfer_len > 0) {
  60036. + uint32_t fifoemptymsk = 0;
  60037. + fifoemptymsk = 1 << ep->num;
  60038. + DWC_MODIFY_REG32(&core_if->
  60039. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  60040. + 0, fifoemptymsk);
  60041. + }
  60042. + }
  60043. + }
  60044. +
  60045. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  60046. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  60047. + /* EP enable, IN data in FIFO */
  60048. + depctl.b.cnak = 1;
  60049. + depctl.b.epena = 1;
  60050. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  60051. +
  60052. + } else {
  60053. + /* OUT endpoint */
  60054. + dwc_otg_dev_out_ep_regs_t *out_regs =
  60055. + core_if->dev_if->out_ep_regs[ep->num];
  60056. +
  60057. + depctl.d32 = DWC_READ_REG32(&(out_regs->doepctl));
  60058. + deptsiz.d32 = DWC_READ_REG32(&(out_regs->doeptsiz));
  60059. +
  60060. + /* Zero Length Packet */
  60061. + deptsiz.b.xfersize = ep->maxpacket;
  60062. + deptsiz.b.pktcnt = 1;
  60063. +
  60064. + if (core_if->dma_enable) {
  60065. + if (!core_if->dma_desc_enable) {
  60066. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  60067. + deptsiz.d32);
  60068. +
  60069. + DWC_WRITE_REG32(&(out_regs->doepdma),
  60070. + (uint32_t) ep->dma_addr);
  60071. + }
  60072. + } else {
  60073. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  60074. + }
  60075. +
  60076. + /* EP enable */
  60077. + depctl.b.cnak = 1;
  60078. + depctl.b.epena = 1;
  60079. +
  60080. + DWC_WRITE_REG32(&out_regs->doepctl, depctl.d32);
  60081. +
  60082. + }
  60083. +}
  60084. +
  60085. +/**
  60086. + * This function does the setup for a data transfer for EP0 and starts
  60087. + * the transfer. For an IN transfer, the packets will be loaded into
  60088. + * the appropriate Tx FIFO in the ISR. For OUT transfers, the packets are
  60089. + * unloaded from the Rx FIFO in the ISR.
  60090. + *
  60091. + * @param core_if Programming view of DWC_otg controller.
  60092. + * @param ep The EP0 data.
  60093. + */
  60094. +void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  60095. +{
  60096. + depctl_data_t depctl;
  60097. + deptsiz0_data_t deptsiz;
  60098. + gintmsk_data_t intr_mask = {.d32 = 0 };
  60099. + dwc_otg_dev_dma_desc_t *dma_desc;
  60100. +
  60101. + DWC_DEBUGPL(DBG_PCD, "ep%d-%s xfer_len=%d xfer_cnt=%d "
  60102. + "xfer_buff=%p start_xfer_buff=%p \n",
  60103. + ep->num, (ep->is_in ? "IN" : "OUT"), ep->xfer_len,
  60104. + ep->xfer_count, ep->xfer_buff, ep->start_xfer_buff);
  60105. +
  60106. + ep->total_len = ep->xfer_len;
  60107. +
  60108. + /* IN endpoint */
  60109. + if (ep->is_in == 1) {
  60110. + dwc_otg_dev_in_ep_regs_t *in_regs =
  60111. + core_if->dev_if->in_ep_regs[0];
  60112. +
  60113. + gnptxsts_data_t gtxstatus;
  60114. +
  60115. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  60116. + depctl.d32 = DWC_READ_REG32(&in_regs->diepctl);
  60117. + if (depctl.b.epena)
  60118. + return;
  60119. + }
  60120. +
  60121. + gtxstatus.d32 =
  60122. + DWC_READ_REG32(&core_if->core_global_regs->gnptxsts);
  60123. +
  60124. + /* If dedicated FIFO every time flush fifo before enable ep*/
  60125. + if (core_if->en_multiple_tx_fifo && core_if->snpsid >= OTG_CORE_REV_3_00a)
  60126. + dwc_otg_flush_tx_fifo(core_if, ep->tx_fifo_num);
  60127. +
  60128. + if (core_if->en_multiple_tx_fifo == 0
  60129. + && gtxstatus.b.nptxqspcavail == 0
  60130. + && !core_if->dma_enable) {
  60131. +#ifdef DEBUG
  60132. + deptsiz.d32 = DWC_READ_REG32(&in_regs->dieptsiz);
  60133. + DWC_DEBUGPL(DBG_PCD, "DIEPCTL0=%0x\n",
  60134. + DWC_READ_REG32(&in_regs->diepctl));
  60135. + DWC_DEBUGPL(DBG_PCD, "DIEPTSIZ0=%0x (sz=%d, pcnt=%d)\n",
  60136. + deptsiz.d32,
  60137. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  60138. + DWC_PRINTF("TX Queue or FIFO Full (0x%0x)\n",
  60139. + gtxstatus.d32);
  60140. +#endif
  60141. + return;
  60142. + }
  60143. +
  60144. + depctl.d32 = DWC_READ_REG32(&in_regs->diepctl);
  60145. + deptsiz.d32 = DWC_READ_REG32(&in_regs->dieptsiz);
  60146. +
  60147. + /* Zero Length Packet? */
  60148. + if (ep->xfer_len == 0) {
  60149. + deptsiz.b.xfersize = 0;
  60150. + deptsiz.b.pktcnt = 1;
  60151. + } else {
  60152. + /* Program the transfer size and packet count
  60153. + * as follows: xfersize = N * maxpacket +
  60154. + * short_packet pktcnt = N + (short_packet
  60155. + * exist ? 1 : 0)
  60156. + */
  60157. + if (ep->xfer_len > ep->maxpacket) {
  60158. + ep->xfer_len = ep->maxpacket;
  60159. + deptsiz.b.xfersize = ep->maxpacket;
  60160. + } else {
  60161. + deptsiz.b.xfersize = ep->xfer_len;
  60162. + }
  60163. + deptsiz.b.pktcnt = 1;
  60164. +
  60165. + }
  60166. + DWC_DEBUGPL(DBG_PCDV,
  60167. + "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
  60168. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt,
  60169. + deptsiz.d32);
  60170. +
  60171. + /* Write the DMA register */
  60172. + if (core_if->dma_enable) {
  60173. + if (core_if->dma_desc_enable == 0) {
  60174. + DWC_WRITE_REG32(&in_regs->dieptsiz,
  60175. + deptsiz.d32);
  60176. +
  60177. + DWC_WRITE_REG32(&(in_regs->diepdma),
  60178. + (uint32_t) ep->dma_addr);
  60179. + } else {
  60180. + dma_desc = core_if->dev_if->in_desc_addr;
  60181. +
  60182. + /** DMA Descriptor Setup */
  60183. + dma_desc->status.b.bs = BS_HOST_BUSY;
  60184. + dma_desc->status.b.l = 1;
  60185. + dma_desc->status.b.ioc = 1;
  60186. + dma_desc->status.b.sp =
  60187. + (ep->xfer_len == ep->maxpacket) ? 0 : 1;
  60188. + dma_desc->status.b.bytes = ep->xfer_len;
  60189. + dma_desc->buf = ep->dma_addr;
  60190. + dma_desc->status.b.sts = 0;
  60191. + dma_desc->status.b.bs = BS_HOST_READY;
  60192. +
  60193. + /** DIEPDMA0 Register write */
  60194. + DWC_WRITE_REG32(&in_regs->diepdma,
  60195. + core_if->
  60196. + dev_if->dma_in_desc_addr);
  60197. + }
  60198. + } else {
  60199. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  60200. + }
  60201. +
  60202. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  60203. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  60204. + /* EP enable, IN data in FIFO */
  60205. + depctl.b.cnak = 1;
  60206. + depctl.b.epena = 1;
  60207. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  60208. +
  60209. + /**
  60210. + * Enable the Non-Periodic Tx FIFO empty interrupt, the
  60211. + * data will be written into the fifo by the ISR.
  60212. + */
  60213. + if (!core_if->dma_enable) {
  60214. + if (core_if->en_multiple_tx_fifo == 0) {
  60215. + intr_mask.b.nptxfempty = 1;
  60216. + DWC_MODIFY_REG32(&core_if->
  60217. + core_global_regs->gintmsk,
  60218. + intr_mask.d32, intr_mask.d32);
  60219. + } else {
  60220. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  60221. + if (ep->xfer_len > 0) {
  60222. + uint32_t fifoemptymsk = 0;
  60223. + fifoemptymsk |= 1 << ep->num;
  60224. + DWC_MODIFY_REG32(&core_if->
  60225. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  60226. + 0, fifoemptymsk);
  60227. + }
  60228. + }
  60229. + }
  60230. + } else {
  60231. + /* OUT endpoint */
  60232. + dwc_otg_dev_out_ep_regs_t *out_regs =
  60233. + core_if->dev_if->out_ep_regs[0];
  60234. +
  60235. + depctl.d32 = DWC_READ_REG32(&out_regs->doepctl);
  60236. + deptsiz.d32 = DWC_READ_REG32(&out_regs->doeptsiz);
  60237. +
  60238. + /* Program the transfer size and packet count as follows:
  60239. + * xfersize = N * (maxpacket + 4 - (maxpacket % 4))
  60240. + * pktcnt = N */
  60241. + /* Zero Length Packet */
  60242. + deptsiz.b.xfersize = ep->maxpacket;
  60243. + deptsiz.b.pktcnt = 1;
  60244. + if (core_if->snpsid >= OTG_CORE_REV_3_00a)
  60245. + deptsiz.b.supcnt = 3;
  60246. +
  60247. + DWC_DEBUGPL(DBG_PCDV, "len=%d xfersize=%d pktcnt=%d\n",
  60248. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt);
  60249. +
  60250. + if (core_if->dma_enable) {
  60251. + if (!core_if->dma_desc_enable) {
  60252. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  60253. + deptsiz.d32);
  60254. +
  60255. + DWC_WRITE_REG32(&(out_regs->doepdma),
  60256. + (uint32_t) ep->dma_addr);
  60257. + } else {
  60258. + dma_desc = core_if->dev_if->out_desc_addr;
  60259. +
  60260. + /** DMA Descriptor Setup */
  60261. + dma_desc->status.b.bs = BS_HOST_BUSY;
  60262. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  60263. + dma_desc->status.b.mtrf = 0;
  60264. + dma_desc->status.b.sr = 0;
  60265. + }
  60266. + dma_desc->status.b.l = 1;
  60267. + dma_desc->status.b.ioc = 1;
  60268. + dma_desc->status.b.bytes = ep->maxpacket;
  60269. + dma_desc->buf = ep->dma_addr;
  60270. + dma_desc->status.b.sts = 0;
  60271. + dma_desc->status.b.bs = BS_HOST_READY;
  60272. +
  60273. + /** DOEPDMA0 Register write */
  60274. + DWC_WRITE_REG32(&out_regs->doepdma,
  60275. + core_if->dev_if->
  60276. + dma_out_desc_addr);
  60277. + }
  60278. + } else {
  60279. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  60280. + }
  60281. +
  60282. + /* EP enable */
  60283. + depctl.b.cnak = 1;
  60284. + depctl.b.epena = 1;
  60285. + DWC_WRITE_REG32(&(out_regs->doepctl), depctl.d32);
  60286. + }
  60287. +}
  60288. +
  60289. +/**
  60290. + * This function continues control IN transfers started by
  60291. + * dwc_otg_ep0_start_transfer, when the transfer does not fit in a
  60292. + * single packet. NOTE: The DIEPCTL0/DOEPCTL0 registers only have one
  60293. + * bit for the packet count.
  60294. + *
  60295. + * @param core_if Programming view of DWC_otg controller.
  60296. + * @param ep The EP0 data.
  60297. + */
  60298. +void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  60299. +{
  60300. + depctl_data_t depctl;
  60301. + deptsiz0_data_t deptsiz;
  60302. + gintmsk_data_t intr_mask = {.d32 = 0 };
  60303. + dwc_otg_dev_dma_desc_t *dma_desc;
  60304. +
  60305. + if (ep->is_in == 1) {
  60306. + dwc_otg_dev_in_ep_regs_t *in_regs =
  60307. + core_if->dev_if->in_ep_regs[0];
  60308. + gnptxsts_data_t tx_status = {.d32 = 0 };
  60309. +
  60310. + tx_status.d32 =
  60311. + DWC_READ_REG32(&core_if->core_global_regs->gnptxsts);
  60312. + /** @todo Should there be check for room in the Tx
  60313. + * Status Queue. If not remove the code above this comment. */
  60314. +
  60315. + depctl.d32 = DWC_READ_REG32(&in_regs->diepctl);
  60316. + deptsiz.d32 = DWC_READ_REG32(&in_regs->dieptsiz);
  60317. +
  60318. + /* Program the transfer size and packet count
  60319. + * as follows: xfersize = N * maxpacket +
  60320. + * short_packet pktcnt = N + (short_packet
  60321. + * exist ? 1 : 0)
  60322. + */
  60323. +
  60324. + if (core_if->dma_desc_enable == 0) {
  60325. + deptsiz.b.xfersize =
  60326. + (ep->total_len - ep->xfer_count) >
  60327. + ep->maxpacket ? ep->maxpacket : (ep->total_len -
  60328. + ep->xfer_count);
  60329. + deptsiz.b.pktcnt = 1;
  60330. + if (core_if->dma_enable == 0) {
  60331. + ep->xfer_len += deptsiz.b.xfersize;
  60332. + } else {
  60333. + ep->xfer_len = deptsiz.b.xfersize;
  60334. + }
  60335. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  60336. + } else {
  60337. + ep->xfer_len =
  60338. + (ep->total_len - ep->xfer_count) >
  60339. + ep->maxpacket ? ep->maxpacket : (ep->total_len -
  60340. + ep->xfer_count);
  60341. +
  60342. + dma_desc = core_if->dev_if->in_desc_addr;
  60343. +
  60344. + /** DMA Descriptor Setup */
  60345. + dma_desc->status.b.bs = BS_HOST_BUSY;
  60346. + dma_desc->status.b.l = 1;
  60347. + dma_desc->status.b.ioc = 1;
  60348. + dma_desc->status.b.sp =
  60349. + (ep->xfer_len == ep->maxpacket) ? 0 : 1;
  60350. + dma_desc->status.b.bytes = ep->xfer_len;
  60351. + dma_desc->buf = ep->dma_addr;
  60352. + dma_desc->status.b.sts = 0;
  60353. + dma_desc->status.b.bs = BS_HOST_READY;
  60354. +
  60355. + /** DIEPDMA0 Register write */
  60356. + DWC_WRITE_REG32(&in_regs->diepdma,
  60357. + core_if->dev_if->dma_in_desc_addr);
  60358. + }
  60359. +
  60360. + DWC_DEBUGPL(DBG_PCDV,
  60361. + "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
  60362. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt,
  60363. + deptsiz.d32);
  60364. +
  60365. + /* Write the DMA register */
  60366. + if (core_if->hwcfg2.b.architecture == DWC_INT_DMA_ARCH) {
  60367. + if (core_if->dma_desc_enable == 0)
  60368. + DWC_WRITE_REG32(&(in_regs->diepdma),
  60369. + (uint32_t) ep->dma_addr);
  60370. + }
  60371. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  60372. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  60373. + /* EP enable, IN data in FIFO */
  60374. + depctl.b.cnak = 1;
  60375. + depctl.b.epena = 1;
  60376. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  60377. +
  60378. + /**
  60379. + * Enable the Non-Periodic Tx FIFO empty interrupt, the
  60380. + * data will be written into the fifo by the ISR.
  60381. + */
  60382. + if (!core_if->dma_enable) {
  60383. + if (core_if->en_multiple_tx_fifo == 0) {
  60384. + /* First clear it from GINTSTS */
  60385. + intr_mask.b.nptxfempty = 1;
  60386. + DWC_MODIFY_REG32(&core_if->
  60387. + core_global_regs->gintmsk,
  60388. + intr_mask.d32, intr_mask.d32);
  60389. +
  60390. + } else {
  60391. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  60392. + if (ep->xfer_len > 0) {
  60393. + uint32_t fifoemptymsk = 0;
  60394. + fifoemptymsk |= 1 << ep->num;
  60395. + DWC_MODIFY_REG32(&core_if->
  60396. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  60397. + 0, fifoemptymsk);
  60398. + }
  60399. + }
  60400. + }
  60401. + } else {
  60402. + dwc_otg_dev_out_ep_regs_t *out_regs =
  60403. + core_if->dev_if->out_ep_regs[0];
  60404. +
  60405. + depctl.d32 = DWC_READ_REG32(&out_regs->doepctl);
  60406. + deptsiz.d32 = DWC_READ_REG32(&out_regs->doeptsiz);
  60407. +
  60408. + /* Program the transfer size and packet count
  60409. + * as follows: xfersize = N * maxpacket +
  60410. + * short_packet pktcnt = N + (short_packet
  60411. + * exist ? 1 : 0)
  60412. + */
  60413. + deptsiz.b.xfersize = ep->maxpacket;
  60414. + deptsiz.b.pktcnt = 1;
  60415. +
  60416. + if (core_if->dma_desc_enable == 0) {
  60417. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  60418. + } else {
  60419. + dma_desc = core_if->dev_if->out_desc_addr;
  60420. +
  60421. + /** DMA Descriptor Setup */
  60422. + dma_desc->status.b.bs = BS_HOST_BUSY;
  60423. + dma_desc->status.b.l = 1;
  60424. + dma_desc->status.b.ioc = 1;
  60425. + dma_desc->status.b.bytes = ep->maxpacket;
  60426. + dma_desc->buf = ep->dma_addr;
  60427. + dma_desc->status.b.sts = 0;
  60428. + dma_desc->status.b.bs = BS_HOST_READY;
  60429. +
  60430. + /** DOEPDMA0 Register write */
  60431. + DWC_WRITE_REG32(&out_regs->doepdma,
  60432. + core_if->dev_if->dma_out_desc_addr);
  60433. + }
  60434. +
  60435. + DWC_DEBUGPL(DBG_PCDV,
  60436. + "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
  60437. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt,
  60438. + deptsiz.d32);
  60439. +
  60440. + /* Write the DMA register */
  60441. + if (core_if->hwcfg2.b.architecture == DWC_INT_DMA_ARCH) {
  60442. + if (core_if->dma_desc_enable == 0)
  60443. + DWC_WRITE_REG32(&(out_regs->doepdma),
  60444. + (uint32_t) ep->dma_addr);
  60445. +
  60446. + }
  60447. +
  60448. + /* EP enable, IN data in FIFO */
  60449. + depctl.b.cnak = 1;
  60450. + depctl.b.epena = 1;
  60451. + DWC_WRITE_REG32(&out_regs->doepctl, depctl.d32);
  60452. +
  60453. + }
  60454. +}
  60455. +
  60456. +#ifdef DEBUG
  60457. +void dump_msg(const u8 * buf, unsigned int length)
  60458. +{
  60459. + unsigned int start, num, i;
  60460. + char line[52], *p;
  60461. +
  60462. + if (length >= 512)
  60463. + return;
  60464. + start = 0;
  60465. + while (length > 0) {
  60466. + num = length < 16u ? length : 16u;
  60467. + p = line;
  60468. + for (i = 0; i < num; ++i) {
  60469. + if (i == 8)
  60470. + *p++ = ' ';
  60471. + DWC_SPRINTF(p, " %02x", buf[i]);
  60472. + p += 3;
  60473. + }
  60474. + *p = 0;
  60475. + DWC_PRINTF("%6x: %s\n", start, line);
  60476. + buf += num;
  60477. + start += num;
  60478. + length -= num;
  60479. + }
  60480. +}
  60481. +#else
  60482. +static inline void dump_msg(const u8 * buf, unsigned int length)
  60483. +{
  60484. +}
  60485. +#endif
  60486. +
  60487. +/**
  60488. + * This function writes a packet into the Tx FIFO associated with the
  60489. + * EP. For non-periodic EPs the non-periodic Tx FIFO is written. For
  60490. + * periodic EPs the periodic Tx FIFO associated with the EP is written
  60491. + * with all packets for the next micro-frame.
  60492. + *
  60493. + * @param core_if Programming view of DWC_otg controller.
  60494. + * @param ep The EP to write packet for.
  60495. + * @param dma Indicates if DMA is being used.
  60496. + */
  60497. +void dwc_otg_ep_write_packet(dwc_otg_core_if_t * core_if, dwc_ep_t * ep,
  60498. + int dma)
  60499. +{
  60500. + /**
  60501. + * The buffer is padded to DWORD on a per packet basis in
  60502. + * slave/dma mode if the MPS is not DWORD aligned. The last
  60503. + * packet, if short, is also padded to a multiple of DWORD.
  60504. + *
  60505. + * ep->xfer_buff always starts DWORD aligned in memory and is a
  60506. + * multiple of DWORD in length
  60507. + *
  60508. + * ep->xfer_len can be any number of bytes
  60509. + *
  60510. + * ep->xfer_count is a multiple of ep->maxpacket until the last
  60511. + * packet
  60512. + *
  60513. + * FIFO access is DWORD */
  60514. +
  60515. + uint32_t i;
  60516. + uint32_t byte_count;
  60517. + uint32_t dword_count;
  60518. + uint32_t *fifo;
  60519. + uint32_t *data_buff = (uint32_t *) ep->xfer_buff;
  60520. +
  60521. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s(%p,%p)\n", __func__, core_if,
  60522. + ep);
  60523. + if (ep->xfer_count >= ep->xfer_len) {
  60524. + DWC_WARN("%s() No data for EP%d!!!\n", __func__, ep->num);
  60525. + return;
  60526. + }
  60527. +
  60528. + /* Find the byte length of the packet either short packet or MPS */
  60529. + if ((ep->xfer_len - ep->xfer_count) < ep->maxpacket) {
  60530. + byte_count = ep->xfer_len - ep->xfer_count;
  60531. + } else {
  60532. + byte_count = ep->maxpacket;
  60533. + }
  60534. +
  60535. + /* Find the DWORD length, padded by extra bytes as neccessary if MPS
  60536. + * is not a multiple of DWORD */
  60537. + dword_count = (byte_count + 3) / 4;
  60538. +
  60539. +#ifdef VERBOSE
  60540. + dump_msg(ep->xfer_buff, byte_count);
  60541. +#endif
  60542. +
  60543. + /**@todo NGS Where are the Periodic Tx FIFO addresses
  60544. + * intialized? What should this be? */
  60545. +
  60546. + fifo = core_if->data_fifo[ep->num];
  60547. +
  60548. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "fifo=%p buff=%p *p=%08x bc=%d\n",
  60549. + fifo, data_buff, *data_buff, byte_count);
  60550. +
  60551. + if (!dma) {
  60552. + for (i = 0; i < dword_count; i++, data_buff++) {
  60553. + DWC_WRITE_REG32(fifo, *data_buff);
  60554. + }
  60555. + }
  60556. +
  60557. + ep->xfer_count += byte_count;
  60558. + ep->xfer_buff += byte_count;
  60559. + ep->dma_addr += byte_count;
  60560. +}
  60561. +
  60562. +/**
  60563. + * Set the EP STALL.
  60564. + *
  60565. + * @param core_if Programming view of DWC_otg controller.
  60566. + * @param ep The EP to set the stall on.
  60567. + */
  60568. +void dwc_otg_ep_set_stall(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  60569. +{
  60570. + depctl_data_t depctl;
  60571. + volatile uint32_t *depctl_addr;
  60572. +
  60573. + DWC_DEBUGPL(DBG_PCD, "%s ep%d-%s\n", __func__, ep->num,
  60574. + (ep->is_in ? "IN" : "OUT"));
  60575. +
  60576. + if (ep->is_in == 1) {
  60577. + depctl_addr = &(core_if->dev_if->in_ep_regs[ep->num]->diepctl);
  60578. + depctl.d32 = DWC_READ_REG32(depctl_addr);
  60579. +
  60580. + /* set the disable and stall bits */
  60581. + if (depctl.b.epena) {
  60582. + depctl.b.epdis = 1;
  60583. + }
  60584. + depctl.b.stall = 1;
  60585. + DWC_WRITE_REG32(depctl_addr, depctl.d32);
  60586. + } else {
  60587. + depctl_addr = &(core_if->dev_if->out_ep_regs[ep->num]->doepctl);
  60588. + depctl.d32 = DWC_READ_REG32(depctl_addr);
  60589. +
  60590. + /* set the stall bit */
  60591. + depctl.b.stall = 1;
  60592. + DWC_WRITE_REG32(depctl_addr, depctl.d32);
  60593. + }
  60594. +
  60595. + DWC_DEBUGPL(DBG_PCD, "DEPCTL=%0x\n", DWC_READ_REG32(depctl_addr));
  60596. +
  60597. + return;
  60598. +}
  60599. +
  60600. +/**
  60601. + * Clear the EP STALL.
  60602. + *
  60603. + * @param core_if Programming view of DWC_otg controller.
  60604. + * @param ep The EP to clear stall from.
  60605. + */
  60606. +void dwc_otg_ep_clear_stall(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  60607. +{
  60608. + depctl_data_t depctl;
  60609. + volatile uint32_t *depctl_addr;
  60610. +
  60611. + DWC_DEBUGPL(DBG_PCD, "%s ep%d-%s\n", __func__, ep->num,
  60612. + (ep->is_in ? "IN" : "OUT"));
  60613. +
  60614. + if (ep->is_in == 1) {
  60615. + depctl_addr = &(core_if->dev_if->in_ep_regs[ep->num]->diepctl);
  60616. + } else {
  60617. + depctl_addr = &(core_if->dev_if->out_ep_regs[ep->num]->doepctl);
  60618. + }
  60619. +
  60620. + depctl.d32 = DWC_READ_REG32(depctl_addr);
  60621. +
  60622. + /* clear the stall bits */
  60623. + depctl.b.stall = 0;
  60624. +
  60625. + /*
  60626. + * USB Spec 9.4.5: For endpoints using data toggle, regardless
  60627. + * of whether an endpoint has the Halt feature set, a
  60628. + * ClearFeature(ENDPOINT_HALT) request always results in the
  60629. + * data toggle being reinitialized to DATA0.
  60630. + */
  60631. + if (ep->type == DWC_OTG_EP_TYPE_INTR ||
  60632. + ep->type == DWC_OTG_EP_TYPE_BULK) {
  60633. + depctl.b.setd0pid = 1; /* DATA0 */
  60634. + }
  60635. +
  60636. + DWC_WRITE_REG32(depctl_addr, depctl.d32);
  60637. + DWC_DEBUGPL(DBG_PCD, "DEPCTL=%0x\n", DWC_READ_REG32(depctl_addr));
  60638. + return;
  60639. +}
  60640. +
  60641. +/**
  60642. + * This function reads a packet from the Rx FIFO into the destination
  60643. + * buffer. To read SETUP data use dwc_otg_read_setup_packet.
  60644. + *
  60645. + * @param core_if Programming view of DWC_otg controller.
  60646. + * @param dest Destination buffer for the packet.
  60647. + * @param bytes Number of bytes to copy to the destination.
  60648. + */
  60649. +void dwc_otg_read_packet(dwc_otg_core_if_t * core_if,
  60650. + uint8_t * dest, uint16_t bytes)
  60651. +{
  60652. + int i;
  60653. + int word_count = (bytes + 3) / 4;
  60654. +
  60655. + volatile uint32_t *fifo = core_if->data_fifo[0];
  60656. + uint32_t *data_buff = (uint32_t *) dest;
  60657. +
  60658. + /**
  60659. + * @todo Account for the case where _dest is not dword aligned. This
  60660. + * requires reading data from the FIFO into a uint32_t temp buffer,
  60661. + * then moving it into the data buffer.
  60662. + */
  60663. +
  60664. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s(%p,%p,%d)\n", __func__,
  60665. + core_if, dest, bytes);
  60666. +
  60667. + for (i = 0; i < word_count; i++, data_buff++) {
  60668. + *data_buff = DWC_READ_REG32(fifo);
  60669. + }
  60670. +
  60671. + return;
  60672. +}
  60673. +
  60674. +/**
  60675. + * This functions reads the device registers and prints them
  60676. + *
  60677. + * @param core_if Programming view of DWC_otg controller.
  60678. + */
  60679. +void dwc_otg_dump_dev_registers(dwc_otg_core_if_t * core_if)
  60680. +{
  60681. + int i;
  60682. + volatile uint32_t *addr;
  60683. +
  60684. + DWC_PRINTF("Device Global Registers\n");
  60685. + addr = &core_if->dev_if->dev_global_regs->dcfg;
  60686. + DWC_PRINTF("DCFG @0x%08lX : 0x%08X\n",
  60687. + (unsigned long)addr, DWC_READ_REG32(addr));
  60688. + addr = &core_if->dev_if->dev_global_regs->dctl;
  60689. + DWC_PRINTF("DCTL @0x%08lX : 0x%08X\n",
  60690. + (unsigned long)addr, DWC_READ_REG32(addr));
  60691. + addr = &core_if->dev_if->dev_global_regs->dsts;
  60692. + DWC_PRINTF("DSTS @0x%08lX : 0x%08X\n",
  60693. + (unsigned long)addr, DWC_READ_REG32(addr));
  60694. + addr = &core_if->dev_if->dev_global_regs->diepmsk;
  60695. + DWC_PRINTF("DIEPMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60696. + DWC_READ_REG32(addr));
  60697. + addr = &core_if->dev_if->dev_global_regs->doepmsk;
  60698. + DWC_PRINTF("DOEPMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60699. + DWC_READ_REG32(addr));
  60700. + addr = &core_if->dev_if->dev_global_regs->daint;
  60701. + DWC_PRINTF("DAINT @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60702. + DWC_READ_REG32(addr));
  60703. + addr = &core_if->dev_if->dev_global_regs->daintmsk;
  60704. + DWC_PRINTF("DAINTMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60705. + DWC_READ_REG32(addr));
  60706. + addr = &core_if->dev_if->dev_global_regs->dtknqr1;
  60707. + DWC_PRINTF("DTKNQR1 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60708. + DWC_READ_REG32(addr));
  60709. + if (core_if->hwcfg2.b.dev_token_q_depth > 6) {
  60710. + addr = &core_if->dev_if->dev_global_regs->dtknqr2;
  60711. + DWC_PRINTF("DTKNQR2 @0x%08lX : 0x%08X\n",
  60712. + (unsigned long)addr, DWC_READ_REG32(addr));
  60713. + }
  60714. +
  60715. + addr = &core_if->dev_if->dev_global_regs->dvbusdis;
  60716. + DWC_PRINTF("DVBUSID @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60717. + DWC_READ_REG32(addr));
  60718. +
  60719. + addr = &core_if->dev_if->dev_global_regs->dvbuspulse;
  60720. + DWC_PRINTF("DVBUSPULSE @0x%08lX : 0x%08X\n",
  60721. + (unsigned long)addr, DWC_READ_REG32(addr));
  60722. +
  60723. + addr = &core_if->dev_if->dev_global_regs->dtknqr3_dthrctl;
  60724. + DWC_PRINTF("DTKNQR3_DTHRCTL @0x%08lX : 0x%08X\n",
  60725. + (unsigned long)addr, DWC_READ_REG32(addr));
  60726. +
  60727. + if (core_if->hwcfg2.b.dev_token_q_depth > 22) {
  60728. + addr = &core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk;
  60729. + DWC_PRINTF("DTKNQR4 @0x%08lX : 0x%08X\n",
  60730. + (unsigned long)addr, DWC_READ_REG32(addr));
  60731. + }
  60732. +
  60733. + addr = &core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk;
  60734. + DWC_PRINTF("FIFOEMPMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60735. + DWC_READ_REG32(addr));
  60736. +
  60737. + if (core_if->hwcfg2.b.multi_proc_int) {
  60738. +
  60739. + addr = &core_if->dev_if->dev_global_regs->deachint;
  60740. + DWC_PRINTF("DEACHINT @0x%08lX : 0x%08X\n",
  60741. + (unsigned long)addr, DWC_READ_REG32(addr));
  60742. + addr = &core_if->dev_if->dev_global_regs->deachintmsk;
  60743. + DWC_PRINTF("DEACHINTMSK @0x%08lX : 0x%08X\n",
  60744. + (unsigned long)addr, DWC_READ_REG32(addr));
  60745. +
  60746. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  60747. + addr =
  60748. + &core_if->dev_if->
  60749. + dev_global_regs->diepeachintmsk[i];
  60750. + DWC_PRINTF("DIEPEACHINTMSK[%d] @0x%08lX : 0x%08X\n",
  60751. + i, (unsigned long)addr,
  60752. + DWC_READ_REG32(addr));
  60753. + }
  60754. +
  60755. + for (i = 0; i <= core_if->dev_if->num_out_eps; i++) {
  60756. + addr =
  60757. + &core_if->dev_if->
  60758. + dev_global_regs->doepeachintmsk[i];
  60759. + DWC_PRINTF("DOEPEACHINTMSK[%d] @0x%08lX : 0x%08X\n",
  60760. + i, (unsigned long)addr,
  60761. + DWC_READ_REG32(addr));
  60762. + }
  60763. + }
  60764. +
  60765. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  60766. + DWC_PRINTF("Device IN EP %d Registers\n", i);
  60767. + addr = &core_if->dev_if->in_ep_regs[i]->diepctl;
  60768. + DWC_PRINTF("DIEPCTL @0x%08lX : 0x%08X\n",
  60769. + (unsigned long)addr, DWC_READ_REG32(addr));
  60770. + addr = &core_if->dev_if->in_ep_regs[i]->diepint;
  60771. + DWC_PRINTF("DIEPINT @0x%08lX : 0x%08X\n",
  60772. + (unsigned long)addr, DWC_READ_REG32(addr));
  60773. + addr = &core_if->dev_if->in_ep_regs[i]->dieptsiz;
  60774. + DWC_PRINTF("DIETSIZ @0x%08lX : 0x%08X\n",
  60775. + (unsigned long)addr, DWC_READ_REG32(addr));
  60776. + addr = &core_if->dev_if->in_ep_regs[i]->diepdma;
  60777. + DWC_PRINTF("DIEPDMA @0x%08lX : 0x%08X\n",
  60778. + (unsigned long)addr, DWC_READ_REG32(addr));
  60779. + addr = &core_if->dev_if->in_ep_regs[i]->dtxfsts;
  60780. + DWC_PRINTF("DTXFSTS @0x%08lX : 0x%08X\n",
  60781. + (unsigned long)addr, DWC_READ_REG32(addr));
  60782. + addr = &core_if->dev_if->in_ep_regs[i]->diepdmab;
  60783. + DWC_PRINTF("DIEPDMAB @0x%08lX : 0x%08X\n",
  60784. + (unsigned long)addr, 0 /*DWC_READ_REG32(addr) */ );
  60785. + }
  60786. +
  60787. + for (i = 0; i <= core_if->dev_if->num_out_eps; i++) {
  60788. + DWC_PRINTF("Device OUT EP %d Registers\n", i);
  60789. + addr = &core_if->dev_if->out_ep_regs[i]->doepctl;
  60790. + DWC_PRINTF("DOEPCTL @0x%08lX : 0x%08X\n",
  60791. + (unsigned long)addr, DWC_READ_REG32(addr));
  60792. + addr = &core_if->dev_if->out_ep_regs[i]->doepint;
  60793. + DWC_PRINTF("DOEPINT @0x%08lX : 0x%08X\n",
  60794. + (unsigned long)addr, DWC_READ_REG32(addr));
  60795. + addr = &core_if->dev_if->out_ep_regs[i]->doeptsiz;
  60796. + DWC_PRINTF("DOETSIZ @0x%08lX : 0x%08X\n",
  60797. + (unsigned long)addr, DWC_READ_REG32(addr));
  60798. + addr = &core_if->dev_if->out_ep_regs[i]->doepdma;
  60799. + DWC_PRINTF("DOEPDMA @0x%08lX : 0x%08X\n",
  60800. + (unsigned long)addr, DWC_READ_REG32(addr));
  60801. + if (core_if->dma_enable) { /* Don't access this register in SLAVE mode */
  60802. + addr = &core_if->dev_if->out_ep_regs[i]->doepdmab;
  60803. + DWC_PRINTF("DOEPDMAB @0x%08lX : 0x%08X\n",
  60804. + (unsigned long)addr, DWC_READ_REG32(addr));
  60805. + }
  60806. +
  60807. + }
  60808. +}
  60809. +
  60810. +/**
  60811. + * This functions reads the SPRAM and prints its content
  60812. + *
  60813. + * @param core_if Programming view of DWC_otg controller.
  60814. + */
  60815. +void dwc_otg_dump_spram(dwc_otg_core_if_t * core_if)
  60816. +{
  60817. + volatile uint8_t *addr, *start_addr, *end_addr;
  60818. +
  60819. + DWC_PRINTF("SPRAM Data:\n");
  60820. + start_addr = (void *)core_if->core_global_regs;
  60821. + DWC_PRINTF("Base Address: 0x%8lX\n", (unsigned long)start_addr);
  60822. + start_addr += 0x00028000;
  60823. + end_addr = (void *)core_if->core_global_regs;
  60824. + end_addr += 0x000280e0;
  60825. +
  60826. + for (addr = start_addr; addr < end_addr; addr += 16) {
  60827. + DWC_PRINTF
  60828. + ("0x%8lX:\t%2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X\n",
  60829. + (unsigned long)addr, addr[0], addr[1], addr[2], addr[3],
  60830. + addr[4], addr[5], addr[6], addr[7], addr[8], addr[9],
  60831. + addr[10], addr[11], addr[12], addr[13], addr[14], addr[15]
  60832. + );
  60833. + }
  60834. +
  60835. + return;
  60836. +}
  60837. +
  60838. +/**
  60839. + * This function reads the host registers and prints them
  60840. + *
  60841. + * @param core_if Programming view of DWC_otg controller.
  60842. + */
  60843. +void dwc_otg_dump_host_registers(dwc_otg_core_if_t * core_if)
  60844. +{
  60845. + int i;
  60846. + volatile uint32_t *addr;
  60847. +
  60848. + DWC_PRINTF("Host Global Registers\n");
  60849. + addr = &core_if->host_if->host_global_regs->hcfg;
  60850. + DWC_PRINTF("HCFG @0x%08lX : 0x%08X\n",
  60851. + (unsigned long)addr, DWC_READ_REG32(addr));
  60852. + addr = &core_if->host_if->host_global_regs->hfir;
  60853. + DWC_PRINTF("HFIR @0x%08lX : 0x%08X\n",
  60854. + (unsigned long)addr, DWC_READ_REG32(addr));
  60855. + addr = &core_if->host_if->host_global_regs->hfnum;
  60856. + DWC_PRINTF("HFNUM @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60857. + DWC_READ_REG32(addr));
  60858. + addr = &core_if->host_if->host_global_regs->hptxsts;
  60859. + DWC_PRINTF("HPTXSTS @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60860. + DWC_READ_REG32(addr));
  60861. + addr = &core_if->host_if->host_global_regs->haint;
  60862. + DWC_PRINTF("HAINT @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60863. + DWC_READ_REG32(addr));
  60864. + addr = &core_if->host_if->host_global_regs->haintmsk;
  60865. + DWC_PRINTF("HAINTMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60866. + DWC_READ_REG32(addr));
  60867. + if (core_if->dma_desc_enable) {
  60868. + addr = &core_if->host_if->host_global_regs->hflbaddr;
  60869. + DWC_PRINTF("HFLBADDR @0x%08lX : 0x%08X\n",
  60870. + (unsigned long)addr, DWC_READ_REG32(addr));
  60871. + }
  60872. +
  60873. + addr = core_if->host_if->hprt0;
  60874. + DWC_PRINTF("HPRT0 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60875. + DWC_READ_REG32(addr));
  60876. +
  60877. + for (i = 0; i < core_if->core_params->host_channels; i++) {
  60878. + DWC_PRINTF("Host Channel %d Specific Registers\n", i);
  60879. + addr = &core_if->host_if->hc_regs[i]->hcchar;
  60880. + DWC_PRINTF("HCCHAR @0x%08lX : 0x%08X\n",
  60881. + (unsigned long)addr, DWC_READ_REG32(addr));
  60882. + addr = &core_if->host_if->hc_regs[i]->hcsplt;
  60883. + DWC_PRINTF("HCSPLT @0x%08lX : 0x%08X\n",
  60884. + (unsigned long)addr, DWC_READ_REG32(addr));
  60885. + addr = &core_if->host_if->hc_regs[i]->hcint;
  60886. + DWC_PRINTF("HCINT @0x%08lX : 0x%08X\n",
  60887. + (unsigned long)addr, DWC_READ_REG32(addr));
  60888. + addr = &core_if->host_if->hc_regs[i]->hcintmsk;
  60889. + DWC_PRINTF("HCINTMSK @0x%08lX : 0x%08X\n",
  60890. + (unsigned long)addr, DWC_READ_REG32(addr));
  60891. + addr = &core_if->host_if->hc_regs[i]->hctsiz;
  60892. + DWC_PRINTF("HCTSIZ @0x%08lX : 0x%08X\n",
  60893. + (unsigned long)addr, DWC_READ_REG32(addr));
  60894. + addr = &core_if->host_if->hc_regs[i]->hcdma;
  60895. + DWC_PRINTF("HCDMA @0x%08lX : 0x%08X\n",
  60896. + (unsigned long)addr, DWC_READ_REG32(addr));
  60897. + if (core_if->dma_desc_enable) {
  60898. + addr = &core_if->host_if->hc_regs[i]->hcdmab;
  60899. + DWC_PRINTF("HCDMAB @0x%08lX : 0x%08X\n",
  60900. + (unsigned long)addr, DWC_READ_REG32(addr));
  60901. + }
  60902. +
  60903. + }
  60904. + return;
  60905. +}
  60906. +
  60907. +/**
  60908. + * This function reads the core global registers and prints them
  60909. + *
  60910. + * @param core_if Programming view of DWC_otg controller.
  60911. + */
  60912. +void dwc_otg_dump_global_registers(dwc_otg_core_if_t * core_if)
  60913. +{
  60914. + int i, ep_num;
  60915. + volatile uint32_t *addr;
  60916. + char *txfsiz;
  60917. +
  60918. + DWC_PRINTF("Core Global Registers\n");
  60919. + addr = &core_if->core_global_regs->gotgctl;
  60920. + DWC_PRINTF("GOTGCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60921. + DWC_READ_REG32(addr));
  60922. + addr = &core_if->core_global_regs->gotgint;
  60923. + DWC_PRINTF("GOTGINT @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60924. + DWC_READ_REG32(addr));
  60925. + addr = &core_if->core_global_regs->gahbcfg;
  60926. + DWC_PRINTF("GAHBCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60927. + DWC_READ_REG32(addr));
  60928. + addr = &core_if->core_global_regs->gusbcfg;
  60929. + DWC_PRINTF("GUSBCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60930. + DWC_READ_REG32(addr));
  60931. + addr = &core_if->core_global_regs->grstctl;
  60932. + DWC_PRINTF("GRSTCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60933. + DWC_READ_REG32(addr));
  60934. + addr = &core_if->core_global_regs->gintsts;
  60935. + DWC_PRINTF("GINTSTS @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60936. + DWC_READ_REG32(addr));
  60937. + addr = &core_if->core_global_regs->gintmsk;
  60938. + DWC_PRINTF("GINTMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60939. + DWC_READ_REG32(addr));
  60940. + addr = &core_if->core_global_regs->grxstsr;
  60941. + DWC_PRINTF("GRXSTSR @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60942. + DWC_READ_REG32(addr));
  60943. + addr = &core_if->core_global_regs->grxfsiz;
  60944. + DWC_PRINTF("GRXFSIZ @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60945. + DWC_READ_REG32(addr));
  60946. + addr = &core_if->core_global_regs->gnptxfsiz;
  60947. + DWC_PRINTF("GNPTXFSIZ @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60948. + DWC_READ_REG32(addr));
  60949. + addr = &core_if->core_global_regs->gnptxsts;
  60950. + DWC_PRINTF("GNPTXSTS @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60951. + DWC_READ_REG32(addr));
  60952. + addr = &core_if->core_global_regs->gi2cctl;
  60953. + DWC_PRINTF("GI2CCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60954. + DWC_READ_REG32(addr));
  60955. + addr = &core_if->core_global_regs->gpvndctl;
  60956. + DWC_PRINTF("GPVNDCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60957. + DWC_READ_REG32(addr));
  60958. + addr = &core_if->core_global_regs->ggpio;
  60959. + DWC_PRINTF("GGPIO @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60960. + DWC_READ_REG32(addr));
  60961. + addr = &core_if->core_global_regs->guid;
  60962. + DWC_PRINTF("GUID @0x%08lX : 0x%08X\n",
  60963. + (unsigned long)addr, DWC_READ_REG32(addr));
  60964. + addr = &core_if->core_global_regs->gsnpsid;
  60965. + DWC_PRINTF("GSNPSID @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60966. + DWC_READ_REG32(addr));
  60967. + addr = &core_if->core_global_regs->ghwcfg1;
  60968. + DWC_PRINTF("GHWCFG1 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60969. + DWC_READ_REG32(addr));
  60970. + addr = &core_if->core_global_regs->ghwcfg2;
  60971. + DWC_PRINTF("GHWCFG2 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60972. + DWC_READ_REG32(addr));
  60973. + addr = &core_if->core_global_regs->ghwcfg3;
  60974. + DWC_PRINTF("GHWCFG3 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60975. + DWC_READ_REG32(addr));
  60976. + addr = &core_if->core_global_regs->ghwcfg4;
  60977. + DWC_PRINTF("GHWCFG4 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60978. + DWC_READ_REG32(addr));
  60979. + addr = &core_if->core_global_regs->glpmcfg;
  60980. + DWC_PRINTF("GLPMCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60981. + DWC_READ_REG32(addr));
  60982. + addr = &core_if->core_global_regs->gpwrdn;
  60983. + DWC_PRINTF("GPWRDN @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60984. + DWC_READ_REG32(addr));
  60985. + addr = &core_if->core_global_regs->gdfifocfg;
  60986. + DWC_PRINTF("GDFIFOCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60987. + DWC_READ_REG32(addr));
  60988. + addr = &core_if->core_global_regs->adpctl;
  60989. + DWC_PRINTF("ADPCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60990. + dwc_otg_adp_read_reg(core_if));
  60991. + addr = &core_if->core_global_regs->hptxfsiz;
  60992. + DWC_PRINTF("HPTXFSIZ @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60993. + DWC_READ_REG32(addr));
  60994. +
  60995. + if (core_if->en_multiple_tx_fifo == 0) {
  60996. + ep_num = core_if->hwcfg4.b.num_dev_perio_in_ep;
  60997. + txfsiz = "DPTXFSIZ";
  60998. + } else {
  60999. + ep_num = core_if->hwcfg4.b.num_in_eps;
  61000. + txfsiz = "DIENPTXF";
  61001. + }
  61002. + for (i = 0; i < ep_num; i++) {
  61003. + addr = &core_if->core_global_regs->dtxfsiz[i];
  61004. + DWC_PRINTF("%s[%d] @0x%08lX : 0x%08X\n", txfsiz, i + 1,
  61005. + (unsigned long)addr, DWC_READ_REG32(addr));
  61006. + }
  61007. + addr = core_if->pcgcctl;
  61008. + DWC_PRINTF("PCGCCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  61009. + DWC_READ_REG32(addr));
  61010. +}
  61011. +
  61012. +/**
  61013. + * Flush a Tx FIFO.
  61014. + *
  61015. + * @param core_if Programming view of DWC_otg controller.
  61016. + * @param num Tx FIFO to flush.
  61017. + */
  61018. +void dwc_otg_flush_tx_fifo(dwc_otg_core_if_t * core_if, const int num)
  61019. +{
  61020. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  61021. + volatile grstctl_t greset = {.d32 = 0 };
  61022. + int count = 0;
  61023. +
  61024. + DWC_DEBUGPL((DBG_CIL | DBG_PCDV), "Flush Tx FIFO %d\n", num);
  61025. +
  61026. + greset.b.txfflsh = 1;
  61027. + greset.b.txfnum = num;
  61028. + DWC_WRITE_REG32(&global_regs->grstctl, greset.d32);
  61029. +
  61030. + do {
  61031. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  61032. + if (++count > 10000) {
  61033. + DWC_WARN("%s() HANG! GRSTCTL=%0x GNPTXSTS=0x%08x\n",
  61034. + __func__, greset.d32,
  61035. + DWC_READ_REG32(&global_regs->gnptxsts));
  61036. + break;
  61037. + }
  61038. + dwc_udelay(1);
  61039. + } while (greset.b.txfflsh == 1);
  61040. +
  61041. + /* Wait for 3 PHY Clocks */
  61042. + dwc_udelay(1);
  61043. +}
  61044. +
  61045. +/**
  61046. + * Flush Rx FIFO.
  61047. + *
  61048. + * @param core_if Programming view of DWC_otg controller.
  61049. + */
  61050. +void dwc_otg_flush_rx_fifo(dwc_otg_core_if_t * core_if)
  61051. +{
  61052. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  61053. + volatile grstctl_t greset = {.d32 = 0 };
  61054. + int count = 0;
  61055. +
  61056. + DWC_DEBUGPL((DBG_CIL | DBG_PCDV), "%s\n", __func__);
  61057. + /*
  61058. + *
  61059. + */
  61060. + greset.b.rxfflsh = 1;
  61061. + DWC_WRITE_REG32(&global_regs->grstctl, greset.d32);
  61062. +
  61063. + do {
  61064. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  61065. + if (++count > 10000) {
  61066. + DWC_WARN("%s() HANG! GRSTCTL=%0x\n", __func__,
  61067. + greset.d32);
  61068. + break;
  61069. + }
  61070. + dwc_udelay(1);
  61071. + } while (greset.b.rxfflsh == 1);
  61072. +
  61073. + /* Wait for 3 PHY Clocks */
  61074. + dwc_udelay(1);
  61075. +}
  61076. +
  61077. +/**
  61078. + * Do core a soft reset of the core. Be careful with this because it
  61079. + * resets all the internal state machines of the core.
  61080. + */
  61081. +void dwc_otg_core_reset(dwc_otg_core_if_t * core_if)
  61082. +{
  61083. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  61084. + volatile grstctl_t greset = {.d32 = 0 };
  61085. + int count = 0;
  61086. +
  61087. + DWC_DEBUGPL(DBG_CILV, "%s\n", __func__);
  61088. + /* Wait for AHB master IDLE state. */
  61089. + do {
  61090. + dwc_udelay(10);
  61091. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  61092. + if (++count > 100000) {
  61093. + DWC_WARN("%s() HANG! AHB Idle GRSTCTL=%0x\n", __func__,
  61094. + greset.d32);
  61095. + return;
  61096. + }
  61097. + }
  61098. + while (greset.b.ahbidle == 0);
  61099. +
  61100. + /* Core Soft Reset */
  61101. + count = 0;
  61102. + greset.b.csftrst = 1;
  61103. + DWC_WRITE_REG32(&global_regs->grstctl, greset.d32);
  61104. + do {
  61105. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  61106. + if (++count > 10000) {
  61107. + DWC_WARN("%s() HANG! Soft Reset GRSTCTL=%0x\n",
  61108. + __func__, greset.d32);
  61109. + break;
  61110. + }
  61111. + dwc_udelay(1);
  61112. + }
  61113. + while (greset.b.csftrst == 1);
  61114. +
  61115. + /* Wait for 3 PHY Clocks */
  61116. + dwc_mdelay(100);
  61117. +}
  61118. +
  61119. +uint8_t dwc_otg_is_device_mode(dwc_otg_core_if_t * _core_if)
  61120. +{
  61121. + return (dwc_otg_mode(_core_if) != DWC_HOST_MODE);
  61122. +}
  61123. +
  61124. +uint8_t dwc_otg_is_host_mode(dwc_otg_core_if_t * _core_if)
  61125. +{
  61126. + return (dwc_otg_mode(_core_if) == DWC_HOST_MODE);
  61127. +}
  61128. +
  61129. +/**
  61130. + * Register HCD callbacks. The callbacks are used to start and stop
  61131. + * the HCD for interrupt processing.
  61132. + *
  61133. + * @param core_if Programming view of DWC_otg controller.
  61134. + * @param cb the HCD callback structure.
  61135. + * @param p pointer to be passed to callback function (usb_hcd*).
  61136. + */
  61137. +void dwc_otg_cil_register_hcd_callbacks(dwc_otg_core_if_t * core_if,
  61138. + dwc_otg_cil_callbacks_t * cb, void *p)
  61139. +{
  61140. + core_if->hcd_cb = cb;
  61141. + cb->p = p;
  61142. +}
  61143. +
  61144. +/**
  61145. + * Register PCD callbacks. The callbacks are used to start and stop
  61146. + * the PCD for interrupt processing.
  61147. + *
  61148. + * @param core_if Programming view of DWC_otg controller.
  61149. + * @param cb the PCD callback structure.
  61150. + * @param p pointer to be passed to callback function (pcd*).
  61151. + */
  61152. +void dwc_otg_cil_register_pcd_callbacks(dwc_otg_core_if_t * core_if,
  61153. + dwc_otg_cil_callbacks_t * cb, void *p)
  61154. +{
  61155. + core_if->pcd_cb = cb;
  61156. + cb->p = p;
  61157. +}
  61158. +
  61159. +#ifdef DWC_EN_ISOC
  61160. +
  61161. +/**
  61162. + * This function writes isoc data per 1 (micro)frame into tx fifo
  61163. + *
  61164. + * @param core_if Programming view of DWC_otg controller.
  61165. + * @param ep The EP to start the transfer on.
  61166. + *
  61167. + */
  61168. +void write_isoc_frame_data(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  61169. +{
  61170. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  61171. + dtxfsts_data_t txstatus = {.d32 = 0 };
  61172. + uint32_t len = 0;
  61173. + uint32_t dwords;
  61174. +
  61175. + ep->xfer_len = ep->data_per_frame;
  61176. + ep->xfer_count = 0;
  61177. +
  61178. + ep_regs = core_if->dev_if->in_ep_regs[ep->num];
  61179. +
  61180. + len = ep->xfer_len - ep->xfer_count;
  61181. +
  61182. + if (len > ep->maxpacket) {
  61183. + len = ep->maxpacket;
  61184. + }
  61185. +
  61186. + dwords = (len + 3) / 4;
  61187. +
  61188. + /* While there is space in the queue and space in the FIFO and
  61189. + * More data to tranfer, Write packets to the Tx FIFO */
  61190. + txstatus.d32 =
  61191. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[ep->num]->dtxfsts);
  61192. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", ep->num, txstatus.d32);
  61193. +
  61194. + while (txstatus.b.txfspcavail > dwords &&
  61195. + ep->xfer_count < ep->xfer_len && ep->xfer_len != 0) {
  61196. + /* Write the FIFO */
  61197. + dwc_otg_ep_write_packet(core_if, ep, 0);
  61198. +
  61199. + len = ep->xfer_len - ep->xfer_count;
  61200. + if (len > ep->maxpacket) {
  61201. + len = ep->maxpacket;
  61202. + }
  61203. +
  61204. + dwords = (len + 3) / 4;
  61205. + txstatus.d32 =
  61206. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  61207. + dtxfsts);
  61208. + DWC_DEBUGPL(DBG_PCDV, "dtxfsts[%d]=0x%08x\n", ep->num,
  61209. + txstatus.d32);
  61210. + }
  61211. +}
  61212. +
  61213. +/**
  61214. + * This function initializes a descriptor chain for Isochronous transfer
  61215. + *
  61216. + * @param core_if Programming view of DWC_otg controller.
  61217. + * @param ep The EP to start the transfer on.
  61218. + *
  61219. + */
  61220. +void dwc_otg_iso_ep_start_frm_transfer(dwc_otg_core_if_t * core_if,
  61221. + dwc_ep_t * ep)
  61222. +{
  61223. + deptsiz_data_t deptsiz = {.d32 = 0 };
  61224. + depctl_data_t depctl = {.d32 = 0 };
  61225. + dsts_data_t dsts = {.d32 = 0 };
  61226. + volatile uint32_t *addr;
  61227. +
  61228. + if (ep->is_in) {
  61229. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  61230. + } else {
  61231. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  61232. + }
  61233. +
  61234. + ep->xfer_len = ep->data_per_frame;
  61235. + ep->xfer_count = 0;
  61236. + ep->xfer_buff = ep->cur_pkt_addr;
  61237. + ep->dma_addr = ep->cur_pkt_dma_addr;
  61238. +
  61239. + if (ep->is_in) {
  61240. + /* Program the transfer size and packet count
  61241. + * as follows: xfersize = N * maxpacket +
  61242. + * short_packet pktcnt = N + (short_packet
  61243. + * exist ? 1 : 0)
  61244. + */
  61245. + deptsiz.b.xfersize = ep->xfer_len;
  61246. + deptsiz.b.pktcnt =
  61247. + (ep->xfer_len - 1 + ep->maxpacket) / ep->maxpacket;
  61248. + deptsiz.b.mc = deptsiz.b.pktcnt;
  61249. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->dieptsiz,
  61250. + deptsiz.d32);
  61251. +
  61252. + /* Write the DMA register */
  61253. + if (core_if->dma_enable) {
  61254. + DWC_WRITE_REG32(&
  61255. + (core_if->dev_if->in_ep_regs[ep->num]->
  61256. + diepdma), (uint32_t) ep->dma_addr);
  61257. + }
  61258. + } else {
  61259. + deptsiz.b.pktcnt =
  61260. + (ep->xfer_len + (ep->maxpacket - 1)) / ep->maxpacket;
  61261. + deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
  61262. +
  61263. + DWC_WRITE_REG32(&core_if->dev_if->
  61264. + out_ep_regs[ep->num]->doeptsiz, deptsiz.d32);
  61265. +
  61266. + if (core_if->dma_enable) {
  61267. + DWC_WRITE_REG32(&
  61268. + (core_if->dev_if->
  61269. + out_ep_regs[ep->num]->doepdma),
  61270. + (uint32_t) ep->dma_addr);
  61271. + }
  61272. + }
  61273. +
  61274. + /** Enable endpoint, clear nak */
  61275. +
  61276. + depctl.d32 = 0;
  61277. + if (ep->bInterval == 1) {
  61278. + dsts.d32 =
  61279. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  61280. + ep->next_frame = dsts.b.soffn + ep->bInterval;
  61281. +
  61282. + if (ep->next_frame & 0x1) {
  61283. + depctl.b.setd1pid = 1;
  61284. + } else {
  61285. + depctl.b.setd0pid = 1;
  61286. + }
  61287. + } else {
  61288. + ep->next_frame += ep->bInterval;
  61289. +
  61290. + if (ep->next_frame & 0x1) {
  61291. + depctl.b.setd1pid = 1;
  61292. + } else {
  61293. + depctl.b.setd0pid = 1;
  61294. + }
  61295. + }
  61296. + depctl.b.epena = 1;
  61297. + depctl.b.cnak = 1;
  61298. +
  61299. + DWC_MODIFY_REG32(addr, 0, depctl.d32);
  61300. + depctl.d32 = DWC_READ_REG32(addr);
  61301. +
  61302. + if (ep->is_in && core_if->dma_enable == 0) {
  61303. + write_isoc_frame_data(core_if, ep);
  61304. + }
  61305. +
  61306. +}
  61307. +#endif /* DWC_EN_ISOC */
  61308. +
  61309. +static void dwc_otg_set_uninitialized(int32_t * p, int size)
  61310. +{
  61311. + int i;
  61312. + for (i = 0; i < size; i++) {
  61313. + p[i] = -1;
  61314. + }
  61315. +}
  61316. +
  61317. +static int dwc_otg_param_initialized(int32_t val)
  61318. +{
  61319. + return val != -1;
  61320. +}
  61321. +
  61322. +static int dwc_otg_setup_params(dwc_otg_core_if_t * core_if)
  61323. +{
  61324. + int i;
  61325. + core_if->core_params = DWC_ALLOC(sizeof(*core_if->core_params));
  61326. + if (!core_if->core_params) {
  61327. + return -DWC_E_NO_MEMORY;
  61328. + }
  61329. + dwc_otg_set_uninitialized((int32_t *) core_if->core_params,
  61330. + sizeof(*core_if->core_params) /
  61331. + sizeof(int32_t));
  61332. + DWC_PRINTF("Setting default values for core params\n");
  61333. + dwc_otg_set_param_otg_cap(core_if, dwc_param_otg_cap_default);
  61334. + dwc_otg_set_param_dma_enable(core_if, dwc_param_dma_enable_default);
  61335. + dwc_otg_set_param_dma_desc_enable(core_if,
  61336. + dwc_param_dma_desc_enable_default);
  61337. + dwc_otg_set_param_opt(core_if, dwc_param_opt_default);
  61338. + dwc_otg_set_param_dma_burst_size(core_if,
  61339. + dwc_param_dma_burst_size_default);
  61340. + dwc_otg_set_param_host_support_fs_ls_low_power(core_if,
  61341. + dwc_param_host_support_fs_ls_low_power_default);
  61342. + dwc_otg_set_param_enable_dynamic_fifo(core_if,
  61343. + dwc_param_enable_dynamic_fifo_default);
  61344. + dwc_otg_set_param_data_fifo_size(core_if,
  61345. + dwc_param_data_fifo_size_default);
  61346. + dwc_otg_set_param_dev_rx_fifo_size(core_if,
  61347. + dwc_param_dev_rx_fifo_size_default);
  61348. + dwc_otg_set_param_dev_nperio_tx_fifo_size(core_if,
  61349. + dwc_param_dev_nperio_tx_fifo_size_default);
  61350. + dwc_otg_set_param_host_rx_fifo_size(core_if,
  61351. + dwc_param_host_rx_fifo_size_default);
  61352. + dwc_otg_set_param_host_nperio_tx_fifo_size(core_if,
  61353. + dwc_param_host_nperio_tx_fifo_size_default);
  61354. + dwc_otg_set_param_host_perio_tx_fifo_size(core_if,
  61355. + dwc_param_host_perio_tx_fifo_size_default);
  61356. + dwc_otg_set_param_max_transfer_size(core_if,
  61357. + dwc_param_max_transfer_size_default);
  61358. + dwc_otg_set_param_max_packet_count(core_if,
  61359. + dwc_param_max_packet_count_default);
  61360. + dwc_otg_set_param_host_channels(core_if,
  61361. + dwc_param_host_channels_default);
  61362. + dwc_otg_set_param_dev_endpoints(core_if,
  61363. + dwc_param_dev_endpoints_default);
  61364. + dwc_otg_set_param_phy_type(core_if, dwc_param_phy_type_default);
  61365. + dwc_otg_set_param_speed(core_if, dwc_param_speed_default);
  61366. + dwc_otg_set_param_host_ls_low_power_phy_clk(core_if,
  61367. + dwc_param_host_ls_low_power_phy_clk_default);
  61368. + dwc_otg_set_param_phy_ulpi_ddr(core_if, dwc_param_phy_ulpi_ddr_default);
  61369. + dwc_otg_set_param_phy_ulpi_ext_vbus(core_if,
  61370. + dwc_param_phy_ulpi_ext_vbus_default);
  61371. + dwc_otg_set_param_phy_utmi_width(core_if,
  61372. + dwc_param_phy_utmi_width_default);
  61373. + dwc_otg_set_param_ts_dline(core_if, dwc_param_ts_dline_default);
  61374. + dwc_otg_set_param_i2c_enable(core_if, dwc_param_i2c_enable_default);
  61375. + dwc_otg_set_param_ulpi_fs_ls(core_if, dwc_param_ulpi_fs_ls_default);
  61376. + dwc_otg_set_param_en_multiple_tx_fifo(core_if,
  61377. + dwc_param_en_multiple_tx_fifo_default);
  61378. + for (i = 0; i < 15; i++) {
  61379. + dwc_otg_set_param_dev_perio_tx_fifo_size(core_if,
  61380. + dwc_param_dev_perio_tx_fifo_size_default,
  61381. + i);
  61382. + }
  61383. +
  61384. + for (i = 0; i < 15; i++) {
  61385. + dwc_otg_set_param_dev_tx_fifo_size(core_if,
  61386. + dwc_param_dev_tx_fifo_size_default,
  61387. + i);
  61388. + }
  61389. + dwc_otg_set_param_thr_ctl(core_if, dwc_param_thr_ctl_default);
  61390. + dwc_otg_set_param_mpi_enable(core_if, dwc_param_mpi_enable_default);
  61391. + dwc_otg_set_param_pti_enable(core_if, dwc_param_pti_enable_default);
  61392. + dwc_otg_set_param_lpm_enable(core_if, dwc_param_lpm_enable_default);
  61393. + dwc_otg_set_param_ic_usb_cap(core_if, dwc_param_ic_usb_cap_default);
  61394. + dwc_otg_set_param_tx_thr_length(core_if,
  61395. + dwc_param_tx_thr_length_default);
  61396. + dwc_otg_set_param_rx_thr_length(core_if,
  61397. + dwc_param_rx_thr_length_default);
  61398. + dwc_otg_set_param_ahb_thr_ratio(core_if,
  61399. + dwc_param_ahb_thr_ratio_default);
  61400. + dwc_otg_set_param_power_down(core_if, dwc_param_power_down_default);
  61401. + dwc_otg_set_param_reload_ctl(core_if, dwc_param_reload_ctl_default);
  61402. + dwc_otg_set_param_dev_out_nak(core_if, dwc_param_dev_out_nak_default);
  61403. + dwc_otg_set_param_cont_on_bna(core_if, dwc_param_cont_on_bna_default);
  61404. + dwc_otg_set_param_ahb_single(core_if, dwc_param_ahb_single_default);
  61405. + dwc_otg_set_param_otg_ver(core_if, dwc_param_otg_ver_default);
  61406. + dwc_otg_set_param_adp_enable(core_if, dwc_param_adp_enable_default);
  61407. + DWC_PRINTF("Finished setting default values for core params\n");
  61408. +
  61409. + return 0;
  61410. +}
  61411. +
  61412. +uint8_t dwc_otg_is_dma_enable(dwc_otg_core_if_t * core_if)
  61413. +{
  61414. + return core_if->dma_enable;
  61415. +}
  61416. +
  61417. +/* Checks if the parameter is outside of its valid range of values */
  61418. +#define DWC_OTG_PARAM_TEST(_param_, _low_, _high_) \
  61419. + (((_param_) < (_low_)) || \
  61420. + ((_param_) > (_high_)))
  61421. +
  61422. +/* Parameter access functions */
  61423. +int dwc_otg_set_param_otg_cap(dwc_otg_core_if_t * core_if, int32_t val)
  61424. +{
  61425. + int valid;
  61426. + int retval = 0;
  61427. + if (DWC_OTG_PARAM_TEST(val, 0, 2)) {
  61428. + DWC_WARN("Wrong value for otg_cap parameter\n");
  61429. + DWC_WARN("otg_cap parameter must be 0,1 or 2\n");
  61430. + retval = -DWC_E_INVALID;
  61431. + goto out;
  61432. + }
  61433. +
  61434. + valid = 1;
  61435. + switch (val) {
  61436. + case DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE:
  61437. + if (core_if->hwcfg2.b.op_mode !=
  61438. + DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  61439. + valid = 0;
  61440. + break;
  61441. + case DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE:
  61442. + if ((core_if->hwcfg2.b.op_mode !=
  61443. + DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  61444. + && (core_if->hwcfg2.b.op_mode !=
  61445. + DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG)
  61446. + && (core_if->hwcfg2.b.op_mode !=
  61447. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE)
  61448. + && (core_if->hwcfg2.b.op_mode !=
  61449. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)) {
  61450. + valid = 0;
  61451. + }
  61452. + break;
  61453. + case DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE:
  61454. + /* always valid */
  61455. + break;
  61456. + }
  61457. + if (!valid) {
  61458. + if (dwc_otg_param_initialized(core_if->core_params->otg_cap)) {
  61459. + DWC_ERROR
  61460. + ("%d invalid for otg_cap paremter. Check HW configuration.\n",
  61461. + val);
  61462. + }
  61463. + val =
  61464. + (((core_if->hwcfg2.b.op_mode ==
  61465. + DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  61466. + || (core_if->hwcfg2.b.op_mode ==
  61467. + DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG)
  61468. + || (core_if->hwcfg2.b.op_mode ==
  61469. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE)
  61470. + || (core_if->hwcfg2.b.op_mode ==
  61471. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)) ?
  61472. + DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE :
  61473. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  61474. + retval = -DWC_E_INVALID;
  61475. + }
  61476. +
  61477. + core_if->core_params->otg_cap = val;
  61478. +out:
  61479. + return retval;
  61480. +}
  61481. +
  61482. +int32_t dwc_otg_get_param_otg_cap(dwc_otg_core_if_t * core_if)
  61483. +{
  61484. + return core_if->core_params->otg_cap;
  61485. +}
  61486. +
  61487. +int dwc_otg_set_param_opt(dwc_otg_core_if_t * core_if, int32_t val)
  61488. +{
  61489. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61490. + DWC_WARN("Wrong value for opt parameter\n");
  61491. + return -DWC_E_INVALID;
  61492. + }
  61493. + core_if->core_params->opt = val;
  61494. + return 0;
  61495. +}
  61496. +
  61497. +int32_t dwc_otg_get_param_opt(dwc_otg_core_if_t * core_if)
  61498. +{
  61499. + return core_if->core_params->opt;
  61500. +}
  61501. +
  61502. +int dwc_otg_set_param_dma_enable(dwc_otg_core_if_t * core_if, int32_t val)
  61503. +{
  61504. + int retval = 0;
  61505. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61506. + DWC_WARN("Wrong value for dma enable\n");
  61507. + return -DWC_E_INVALID;
  61508. + }
  61509. +
  61510. + if ((val == 1) && (core_if->hwcfg2.b.architecture == 0)) {
  61511. + if (dwc_otg_param_initialized(core_if->core_params->dma_enable)) {
  61512. + DWC_ERROR
  61513. + ("%d invalid for dma_enable paremter. Check HW configuration.\n",
  61514. + val);
  61515. + }
  61516. + val = 0;
  61517. + retval = -DWC_E_INVALID;
  61518. + }
  61519. +
  61520. + core_if->core_params->dma_enable = val;
  61521. + if (val == 0) {
  61522. + dwc_otg_set_param_dma_desc_enable(core_if, 0);
  61523. + }
  61524. + return retval;
  61525. +}
  61526. +
  61527. +int32_t dwc_otg_get_param_dma_enable(dwc_otg_core_if_t * core_if)
  61528. +{
  61529. + return core_if->core_params->dma_enable;
  61530. +}
  61531. +
  61532. +int dwc_otg_set_param_dma_desc_enable(dwc_otg_core_if_t * core_if, int32_t val)
  61533. +{
  61534. + int retval = 0;
  61535. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61536. + DWC_WARN("Wrong value for dma_enable\n");
  61537. + DWC_WARN("dma_desc_enable must be 0 or 1\n");
  61538. + return -DWC_E_INVALID;
  61539. + }
  61540. +
  61541. + if ((val == 1)
  61542. + && ((dwc_otg_get_param_dma_enable(core_if) == 0)
  61543. + || (core_if->hwcfg4.b.desc_dma == 0))) {
  61544. + if (dwc_otg_param_initialized
  61545. + (core_if->core_params->dma_desc_enable)) {
  61546. + DWC_ERROR
  61547. + ("%d invalid for dma_desc_enable paremter. Check HW configuration.\n",
  61548. + val);
  61549. + }
  61550. + val = 0;
  61551. + retval = -DWC_E_INVALID;
  61552. + }
  61553. + core_if->core_params->dma_desc_enable = val;
  61554. + return retval;
  61555. +}
  61556. +
  61557. +int32_t dwc_otg_get_param_dma_desc_enable(dwc_otg_core_if_t * core_if)
  61558. +{
  61559. + return core_if->core_params->dma_desc_enable;
  61560. +}
  61561. +
  61562. +int dwc_otg_set_param_host_support_fs_ls_low_power(dwc_otg_core_if_t * core_if,
  61563. + int32_t val)
  61564. +{
  61565. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61566. + DWC_WARN("Wrong value for host_support_fs_low_power\n");
  61567. + DWC_WARN("host_support_fs_low_power must be 0 or 1\n");
  61568. + return -DWC_E_INVALID;
  61569. + }
  61570. + core_if->core_params->host_support_fs_ls_low_power = val;
  61571. + return 0;
  61572. +}
  61573. +
  61574. +int32_t dwc_otg_get_param_host_support_fs_ls_low_power(dwc_otg_core_if_t *
  61575. + core_if)
  61576. +{
  61577. + return core_if->core_params->host_support_fs_ls_low_power;
  61578. +}
  61579. +
  61580. +int dwc_otg_set_param_enable_dynamic_fifo(dwc_otg_core_if_t * core_if,
  61581. + int32_t val)
  61582. +{
  61583. + int retval = 0;
  61584. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61585. + DWC_WARN("Wrong value for enable_dynamic_fifo\n");
  61586. + DWC_WARN("enable_dynamic_fifo must be 0 or 1\n");
  61587. + return -DWC_E_INVALID;
  61588. + }
  61589. +
  61590. + if ((val == 1) && (core_if->hwcfg2.b.dynamic_fifo == 0)) {
  61591. + if (dwc_otg_param_initialized
  61592. + (core_if->core_params->enable_dynamic_fifo)) {
  61593. + DWC_ERROR
  61594. + ("%d invalid for enable_dynamic_fifo paremter. Check HW configuration.\n",
  61595. + val);
  61596. + }
  61597. + val = 0;
  61598. + retval = -DWC_E_INVALID;
  61599. + }
  61600. + core_if->core_params->enable_dynamic_fifo = val;
  61601. + return retval;
  61602. +}
  61603. +
  61604. +int32_t dwc_otg_get_param_enable_dynamic_fifo(dwc_otg_core_if_t * core_if)
  61605. +{
  61606. + return core_if->core_params->enable_dynamic_fifo;
  61607. +}
  61608. +
  61609. +int dwc_otg_set_param_data_fifo_size(dwc_otg_core_if_t * core_if, int32_t val)
  61610. +{
  61611. + int retval = 0;
  61612. + if (DWC_OTG_PARAM_TEST(val, 32, 32768)) {
  61613. + DWC_WARN("Wrong value for data_fifo_size\n");
  61614. + DWC_WARN("data_fifo_size must be 32-32768\n");
  61615. + return -DWC_E_INVALID;
  61616. + }
  61617. +
  61618. + if (val > core_if->hwcfg3.b.dfifo_depth) {
  61619. + if (dwc_otg_param_initialized
  61620. + (core_if->core_params->data_fifo_size)) {
  61621. + DWC_ERROR
  61622. + ("%d invalid for data_fifo_size parameter. Check HW configuration.\n",
  61623. + val);
  61624. + }
  61625. + val = core_if->hwcfg3.b.dfifo_depth;
  61626. + retval = -DWC_E_INVALID;
  61627. + }
  61628. +
  61629. + core_if->core_params->data_fifo_size = val;
  61630. + return retval;
  61631. +}
  61632. +
  61633. +int32_t dwc_otg_get_param_data_fifo_size(dwc_otg_core_if_t * core_if)
  61634. +{
  61635. + return core_if->core_params->data_fifo_size;
  61636. +}
  61637. +
  61638. +int dwc_otg_set_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if, int32_t val)
  61639. +{
  61640. + int retval = 0;
  61641. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  61642. + DWC_WARN("Wrong value for dev_rx_fifo_size\n");
  61643. + DWC_WARN("dev_rx_fifo_size must be 16-32768\n");
  61644. + return -DWC_E_INVALID;
  61645. + }
  61646. +
  61647. + if (val > DWC_READ_REG32(&core_if->core_global_regs->grxfsiz)) {
  61648. + if (dwc_otg_param_initialized(core_if->core_params->dev_rx_fifo_size)) {
  61649. + DWC_WARN("%d invalid for dev_rx_fifo_size parameter\n", val);
  61650. + }
  61651. + val = DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  61652. + retval = -DWC_E_INVALID;
  61653. + }
  61654. +
  61655. + core_if->core_params->dev_rx_fifo_size = val;
  61656. + return retval;
  61657. +}
  61658. +
  61659. +int32_t dwc_otg_get_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if)
  61660. +{
  61661. + return core_if->core_params->dev_rx_fifo_size;
  61662. +}
  61663. +
  61664. +int dwc_otg_set_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  61665. + int32_t val)
  61666. +{
  61667. + int retval = 0;
  61668. +
  61669. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  61670. + DWC_WARN("Wrong value for dev_nperio_tx_fifo\n");
  61671. + DWC_WARN("dev_nperio_tx_fifo must be 16-32768\n");
  61672. + return -DWC_E_INVALID;
  61673. + }
  61674. +
  61675. + if (val > (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >> 16)) {
  61676. + if (dwc_otg_param_initialized
  61677. + (core_if->core_params->dev_nperio_tx_fifo_size)) {
  61678. + DWC_ERROR
  61679. + ("%d invalid for dev_nperio_tx_fifo_size. Check HW configuration.\n",
  61680. + val);
  61681. + }
  61682. + val =
  61683. + (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >>
  61684. + 16);
  61685. + retval = -DWC_E_INVALID;
  61686. + }
  61687. +
  61688. + core_if->core_params->dev_nperio_tx_fifo_size = val;
  61689. + return retval;
  61690. +}
  61691. +
  61692. +int32_t dwc_otg_get_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if)
  61693. +{
  61694. + return core_if->core_params->dev_nperio_tx_fifo_size;
  61695. +}
  61696. +
  61697. +int dwc_otg_set_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if,
  61698. + int32_t val)
  61699. +{
  61700. + int retval = 0;
  61701. +
  61702. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  61703. + DWC_WARN("Wrong value for host_rx_fifo_size\n");
  61704. + DWC_WARN("host_rx_fifo_size must be 16-32768\n");
  61705. + return -DWC_E_INVALID;
  61706. + }
  61707. +
  61708. + if (val > DWC_READ_REG32(&core_if->core_global_regs->grxfsiz)) {
  61709. + if (dwc_otg_param_initialized
  61710. + (core_if->core_params->host_rx_fifo_size)) {
  61711. + DWC_ERROR
  61712. + ("%d invalid for host_rx_fifo_size. Check HW configuration.\n",
  61713. + val);
  61714. + }
  61715. + val = DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  61716. + retval = -DWC_E_INVALID;
  61717. + }
  61718. +
  61719. + core_if->core_params->host_rx_fifo_size = val;
  61720. + return retval;
  61721. +
  61722. +}
  61723. +
  61724. +int32_t dwc_otg_get_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if)
  61725. +{
  61726. + return core_if->core_params->host_rx_fifo_size;
  61727. +}
  61728. +
  61729. +int dwc_otg_set_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  61730. + int32_t val)
  61731. +{
  61732. + int retval = 0;
  61733. +
  61734. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  61735. + DWC_WARN("Wrong value for host_nperio_tx_fifo_size\n");
  61736. + DWC_WARN("host_nperio_tx_fifo_size must be 16-32768\n");
  61737. + return -DWC_E_INVALID;
  61738. + }
  61739. +
  61740. + if (val > (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >> 16)) {
  61741. + if (dwc_otg_param_initialized
  61742. + (core_if->core_params->host_nperio_tx_fifo_size)) {
  61743. + DWC_ERROR
  61744. + ("%d invalid for host_nperio_tx_fifo_size. Check HW configuration.\n",
  61745. + val);
  61746. + }
  61747. + val =
  61748. + (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >>
  61749. + 16);
  61750. + retval = -DWC_E_INVALID;
  61751. + }
  61752. +
  61753. + core_if->core_params->host_nperio_tx_fifo_size = val;
  61754. + return retval;
  61755. +}
  61756. +
  61757. +int32_t dwc_otg_get_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if)
  61758. +{
  61759. + return core_if->core_params->host_nperio_tx_fifo_size;
  61760. +}
  61761. +
  61762. +int dwc_otg_set_param_host_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  61763. + int32_t val)
  61764. +{
  61765. + int retval = 0;
  61766. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  61767. + DWC_WARN("Wrong value for host_perio_tx_fifo_size\n");
  61768. + DWC_WARN("host_perio_tx_fifo_size must be 16-32768\n");
  61769. + return -DWC_E_INVALID;
  61770. + }
  61771. +
  61772. + if (val > ((core_if->hptxfsiz.d32) >> 16)) {
  61773. + if (dwc_otg_param_initialized
  61774. + (core_if->core_params->host_perio_tx_fifo_size)) {
  61775. + DWC_ERROR
  61776. + ("%d invalid for host_perio_tx_fifo_size. Check HW configuration.\n",
  61777. + val);
  61778. + }
  61779. + val = (core_if->hptxfsiz.d32) >> 16;
  61780. + retval = -DWC_E_INVALID;
  61781. + }
  61782. +
  61783. + core_if->core_params->host_perio_tx_fifo_size = val;
  61784. + return retval;
  61785. +}
  61786. +
  61787. +int32_t dwc_otg_get_param_host_perio_tx_fifo_size(dwc_otg_core_if_t * core_if)
  61788. +{
  61789. + return core_if->core_params->host_perio_tx_fifo_size;
  61790. +}
  61791. +
  61792. +int dwc_otg_set_param_max_transfer_size(dwc_otg_core_if_t * core_if,
  61793. + int32_t val)
  61794. +{
  61795. + int retval = 0;
  61796. +
  61797. + if (DWC_OTG_PARAM_TEST(val, 2047, 524288)) {
  61798. + DWC_WARN("Wrong value for max_transfer_size\n");
  61799. + DWC_WARN("max_transfer_size must be 2047-524288\n");
  61800. + return -DWC_E_INVALID;
  61801. + }
  61802. +
  61803. + if (val >= (1 << (core_if->hwcfg3.b.xfer_size_cntr_width + 11))) {
  61804. + if (dwc_otg_param_initialized
  61805. + (core_if->core_params->max_transfer_size)) {
  61806. + DWC_ERROR
  61807. + ("%d invalid for max_transfer_size. Check HW configuration.\n",
  61808. + val);
  61809. + }
  61810. + val =
  61811. + ((1 << (core_if->hwcfg3.b.packet_size_cntr_width + 11)) -
  61812. + 1);
  61813. + retval = -DWC_E_INVALID;
  61814. + }
  61815. +
  61816. + core_if->core_params->max_transfer_size = val;
  61817. + return retval;
  61818. +}
  61819. +
  61820. +int32_t dwc_otg_get_param_max_transfer_size(dwc_otg_core_if_t * core_if)
  61821. +{
  61822. + return core_if->core_params->max_transfer_size;
  61823. +}
  61824. +
  61825. +int dwc_otg_set_param_max_packet_count(dwc_otg_core_if_t * core_if, int32_t val)
  61826. +{
  61827. + int retval = 0;
  61828. +
  61829. + if (DWC_OTG_PARAM_TEST(val, 15, 511)) {
  61830. + DWC_WARN("Wrong value for max_packet_count\n");
  61831. + DWC_WARN("max_packet_count must be 15-511\n");
  61832. + return -DWC_E_INVALID;
  61833. + }
  61834. +
  61835. + if (val > (1 << (core_if->hwcfg3.b.packet_size_cntr_width + 4))) {
  61836. + if (dwc_otg_param_initialized
  61837. + (core_if->core_params->max_packet_count)) {
  61838. + DWC_ERROR
  61839. + ("%d invalid for max_packet_count. Check HW configuration.\n",
  61840. + val);
  61841. + }
  61842. + val =
  61843. + ((1 << (core_if->hwcfg3.b.packet_size_cntr_width + 4)) - 1);
  61844. + retval = -DWC_E_INVALID;
  61845. + }
  61846. +
  61847. + core_if->core_params->max_packet_count = val;
  61848. + return retval;
  61849. +}
  61850. +
  61851. +int32_t dwc_otg_get_param_max_packet_count(dwc_otg_core_if_t * core_if)
  61852. +{
  61853. + return core_if->core_params->max_packet_count;
  61854. +}
  61855. +
  61856. +int dwc_otg_set_param_host_channels(dwc_otg_core_if_t * core_if, int32_t val)
  61857. +{
  61858. + int retval = 0;
  61859. +
  61860. + if (DWC_OTG_PARAM_TEST(val, 1, 16)) {
  61861. + DWC_WARN("Wrong value for host_channels\n");
  61862. + DWC_WARN("host_channels must be 1-16\n");
  61863. + return -DWC_E_INVALID;
  61864. + }
  61865. +
  61866. + if (val > (core_if->hwcfg2.b.num_host_chan + 1)) {
  61867. + if (dwc_otg_param_initialized
  61868. + (core_if->core_params->host_channels)) {
  61869. + DWC_ERROR
  61870. + ("%d invalid for host_channels. Check HW configurations.\n",
  61871. + val);
  61872. + }
  61873. + val = (core_if->hwcfg2.b.num_host_chan + 1);
  61874. + retval = -DWC_E_INVALID;
  61875. + }
  61876. +
  61877. + core_if->core_params->host_channels = val;
  61878. + return retval;
  61879. +}
  61880. +
  61881. +int32_t dwc_otg_get_param_host_channels(dwc_otg_core_if_t * core_if)
  61882. +{
  61883. + return core_if->core_params->host_channels;
  61884. +}
  61885. +
  61886. +int dwc_otg_set_param_dev_endpoints(dwc_otg_core_if_t * core_if, int32_t val)
  61887. +{
  61888. + int retval = 0;
  61889. +
  61890. + if (DWC_OTG_PARAM_TEST(val, 1, 15)) {
  61891. + DWC_WARN("Wrong value for dev_endpoints\n");
  61892. + DWC_WARN("dev_endpoints must be 1-15\n");
  61893. + return -DWC_E_INVALID;
  61894. + }
  61895. +
  61896. + if (val > (core_if->hwcfg2.b.num_dev_ep)) {
  61897. + if (dwc_otg_param_initialized
  61898. + (core_if->core_params->dev_endpoints)) {
  61899. + DWC_ERROR
  61900. + ("%d invalid for dev_endpoints. Check HW configurations.\n",
  61901. + val);
  61902. + }
  61903. + val = core_if->hwcfg2.b.num_dev_ep;
  61904. + retval = -DWC_E_INVALID;
  61905. + }
  61906. +
  61907. + core_if->core_params->dev_endpoints = val;
  61908. + return retval;
  61909. +}
  61910. +
  61911. +int32_t dwc_otg_get_param_dev_endpoints(dwc_otg_core_if_t * core_if)
  61912. +{
  61913. + return core_if->core_params->dev_endpoints;
  61914. +}
  61915. +
  61916. +int dwc_otg_set_param_phy_type(dwc_otg_core_if_t * core_if, int32_t val)
  61917. +{
  61918. + int retval = 0;
  61919. + int valid = 0;
  61920. +
  61921. + if (DWC_OTG_PARAM_TEST(val, 0, 2)) {
  61922. + DWC_WARN("Wrong value for phy_type\n");
  61923. + DWC_WARN("phy_type must be 0,1 or 2\n");
  61924. + return -DWC_E_INVALID;
  61925. + }
  61926. +#ifndef NO_FS_PHY_HW_CHECKS
  61927. + if ((val == DWC_PHY_TYPE_PARAM_UTMI) &&
  61928. + ((core_if->hwcfg2.b.hs_phy_type == 1) ||
  61929. + (core_if->hwcfg2.b.hs_phy_type == 3))) {
  61930. + valid = 1;
  61931. + } else if ((val == DWC_PHY_TYPE_PARAM_ULPI) &&
  61932. + ((core_if->hwcfg2.b.hs_phy_type == 2) ||
  61933. + (core_if->hwcfg2.b.hs_phy_type == 3))) {
  61934. + valid = 1;
  61935. + } else if ((val == DWC_PHY_TYPE_PARAM_FS) &&
  61936. + (core_if->hwcfg2.b.fs_phy_type == 1)) {
  61937. + valid = 1;
  61938. + }
  61939. + if (!valid) {
  61940. + if (dwc_otg_param_initialized(core_if->core_params->phy_type)) {
  61941. + DWC_ERROR
  61942. + ("%d invalid for phy_type. Check HW configurations.\n",
  61943. + val);
  61944. + }
  61945. + if (core_if->hwcfg2.b.hs_phy_type) {
  61946. + if ((core_if->hwcfg2.b.hs_phy_type == 3) ||
  61947. + (core_if->hwcfg2.b.hs_phy_type == 1)) {
  61948. + val = DWC_PHY_TYPE_PARAM_UTMI;
  61949. + } else {
  61950. + val = DWC_PHY_TYPE_PARAM_ULPI;
  61951. + }
  61952. + }
  61953. + retval = -DWC_E_INVALID;
  61954. + }
  61955. +#endif
  61956. + core_if->core_params->phy_type = val;
  61957. + return retval;
  61958. +}
  61959. +
  61960. +int32_t dwc_otg_get_param_phy_type(dwc_otg_core_if_t * core_if)
  61961. +{
  61962. + return core_if->core_params->phy_type;
  61963. +}
  61964. +
  61965. +int dwc_otg_set_param_speed(dwc_otg_core_if_t * core_if, int32_t val)
  61966. +{
  61967. + int retval = 0;
  61968. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61969. + DWC_WARN("Wrong value for speed parameter\n");
  61970. + DWC_WARN("max_speed parameter must be 0 or 1\n");
  61971. + return -DWC_E_INVALID;
  61972. + }
  61973. + if ((val == 0)
  61974. + && dwc_otg_get_param_phy_type(core_if) == DWC_PHY_TYPE_PARAM_FS) {
  61975. + if (dwc_otg_param_initialized(core_if->core_params->speed)) {
  61976. + DWC_ERROR
  61977. + ("%d invalid for speed paremter. Check HW configuration.\n",
  61978. + val);
  61979. + }
  61980. + val =
  61981. + (dwc_otg_get_param_phy_type(core_if) ==
  61982. + DWC_PHY_TYPE_PARAM_FS ? 1 : 0);
  61983. + retval = -DWC_E_INVALID;
  61984. + }
  61985. + core_if->core_params->speed = val;
  61986. + return retval;
  61987. +}
  61988. +
  61989. +int32_t dwc_otg_get_param_speed(dwc_otg_core_if_t * core_if)
  61990. +{
  61991. + return core_if->core_params->speed;
  61992. +}
  61993. +
  61994. +int dwc_otg_set_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t * core_if,
  61995. + int32_t val)
  61996. +{
  61997. + int retval = 0;
  61998. +
  61999. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62000. + DWC_WARN
  62001. + ("Wrong value for host_ls_low_power_phy_clk parameter\n");
  62002. + DWC_WARN("host_ls_low_power_phy_clk must be 0 or 1\n");
  62003. + return -DWC_E_INVALID;
  62004. + }
  62005. +
  62006. + if ((val == DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ)
  62007. + && (dwc_otg_get_param_phy_type(core_if) == DWC_PHY_TYPE_PARAM_FS)) {
  62008. + if (dwc_otg_param_initialized
  62009. + (core_if->core_params->host_ls_low_power_phy_clk)) {
  62010. + DWC_ERROR
  62011. + ("%d invalid for host_ls_low_power_phy_clk. Check HW configuration.\n",
  62012. + val);
  62013. + }
  62014. + val =
  62015. + (dwc_otg_get_param_phy_type(core_if) ==
  62016. + DWC_PHY_TYPE_PARAM_FS) ?
  62017. + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ :
  62018. + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ;
  62019. + retval = -DWC_E_INVALID;
  62020. + }
  62021. +
  62022. + core_if->core_params->host_ls_low_power_phy_clk = val;
  62023. + return retval;
  62024. +}
  62025. +
  62026. +int32_t dwc_otg_get_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t * core_if)
  62027. +{
  62028. + return core_if->core_params->host_ls_low_power_phy_clk;
  62029. +}
  62030. +
  62031. +int dwc_otg_set_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if, int32_t val)
  62032. +{
  62033. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62034. + DWC_WARN("Wrong value for phy_ulpi_ddr\n");
  62035. + DWC_WARN("phy_upli_ddr must be 0 or 1\n");
  62036. + return -DWC_E_INVALID;
  62037. + }
  62038. +
  62039. + core_if->core_params->phy_ulpi_ddr = val;
  62040. + return 0;
  62041. +}
  62042. +
  62043. +int32_t dwc_otg_get_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if)
  62044. +{
  62045. + return core_if->core_params->phy_ulpi_ddr;
  62046. +}
  62047. +
  62048. +int dwc_otg_set_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if,
  62049. + int32_t val)
  62050. +{
  62051. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62052. + DWC_WARN("Wrong valaue for phy_ulpi_ext_vbus\n");
  62053. + DWC_WARN("phy_ulpi_ext_vbus must be 0 or 1\n");
  62054. + return -DWC_E_INVALID;
  62055. + }
  62056. +
  62057. + core_if->core_params->phy_ulpi_ext_vbus = val;
  62058. + return 0;
  62059. +}
  62060. +
  62061. +int32_t dwc_otg_get_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if)
  62062. +{
  62063. + return core_if->core_params->phy_ulpi_ext_vbus;
  62064. +}
  62065. +
  62066. +int dwc_otg_set_param_phy_utmi_width(dwc_otg_core_if_t * core_if, int32_t val)
  62067. +{
  62068. + if (DWC_OTG_PARAM_TEST(val, 8, 8) && DWC_OTG_PARAM_TEST(val, 16, 16)) {
  62069. + DWC_WARN("Wrong valaue for phy_utmi_width\n");
  62070. + DWC_WARN("phy_utmi_width must be 8 or 16\n");
  62071. + return -DWC_E_INVALID;
  62072. + }
  62073. +
  62074. + core_if->core_params->phy_utmi_width = val;
  62075. + return 0;
  62076. +}
  62077. +
  62078. +int32_t dwc_otg_get_param_phy_utmi_width(dwc_otg_core_if_t * core_if)
  62079. +{
  62080. + return core_if->core_params->phy_utmi_width;
  62081. +}
  62082. +
  62083. +int dwc_otg_set_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if, int32_t val)
  62084. +{
  62085. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62086. + DWC_WARN("Wrong valaue for ulpi_fs_ls\n");
  62087. + DWC_WARN("ulpi_fs_ls must be 0 or 1\n");
  62088. + return -DWC_E_INVALID;
  62089. + }
  62090. +
  62091. + core_if->core_params->ulpi_fs_ls = val;
  62092. + return 0;
  62093. +}
  62094. +
  62095. +int32_t dwc_otg_get_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if)
  62096. +{
  62097. + return core_if->core_params->ulpi_fs_ls;
  62098. +}
  62099. +
  62100. +int dwc_otg_set_param_ts_dline(dwc_otg_core_if_t * core_if, int32_t val)
  62101. +{
  62102. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62103. + DWC_WARN("Wrong valaue for ts_dline\n");
  62104. + DWC_WARN("ts_dline must be 0 or 1\n");
  62105. + return -DWC_E_INVALID;
  62106. + }
  62107. +
  62108. + core_if->core_params->ts_dline = val;
  62109. + return 0;
  62110. +}
  62111. +
  62112. +int32_t dwc_otg_get_param_ts_dline(dwc_otg_core_if_t * core_if)
  62113. +{
  62114. + return core_if->core_params->ts_dline;
  62115. +}
  62116. +
  62117. +int dwc_otg_set_param_i2c_enable(dwc_otg_core_if_t * core_if, int32_t val)
  62118. +{
  62119. + int retval = 0;
  62120. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62121. + DWC_WARN("Wrong valaue for i2c_enable\n");
  62122. + DWC_WARN("i2c_enable must be 0 or 1\n");
  62123. + return -DWC_E_INVALID;
  62124. + }
  62125. +#ifndef NO_FS_PHY_HW_CHECK
  62126. + if (val == 1 && core_if->hwcfg3.b.i2c == 0) {
  62127. + if (dwc_otg_param_initialized(core_if->core_params->i2c_enable)) {
  62128. + DWC_ERROR
  62129. + ("%d invalid for i2c_enable. Check HW configuration.\n",
  62130. + val);
  62131. + }
  62132. + val = 0;
  62133. + retval = -DWC_E_INVALID;
  62134. + }
  62135. +#endif
  62136. +
  62137. + core_if->core_params->i2c_enable = val;
  62138. + return retval;
  62139. +}
  62140. +
  62141. +int32_t dwc_otg_get_param_i2c_enable(dwc_otg_core_if_t * core_if)
  62142. +{
  62143. + return core_if->core_params->i2c_enable;
  62144. +}
  62145. +
  62146. +int dwc_otg_set_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  62147. + int32_t val, int fifo_num)
  62148. +{
  62149. + int retval = 0;
  62150. +
  62151. + if (DWC_OTG_PARAM_TEST(val, 4, 768)) {
  62152. + DWC_WARN("Wrong value for dev_perio_tx_fifo_size\n");
  62153. + DWC_WARN("dev_perio_tx_fifo_size must be 4-768\n");
  62154. + return -DWC_E_INVALID;
  62155. + }
  62156. +
  62157. + if (val >
  62158. + (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]))) {
  62159. + if (dwc_otg_param_initialized
  62160. + (core_if->core_params->dev_perio_tx_fifo_size[fifo_num])) {
  62161. + DWC_ERROR
  62162. + ("`%d' invalid for parameter `dev_perio_fifo_size_%d'. Check HW configuration.\n",
  62163. + val, fifo_num);
  62164. + }
  62165. + val = (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]));
  62166. + retval = -DWC_E_INVALID;
  62167. + }
  62168. +
  62169. + core_if->core_params->dev_perio_tx_fifo_size[fifo_num] = val;
  62170. + return retval;
  62171. +}
  62172. +
  62173. +int32_t dwc_otg_get_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  62174. + int fifo_num)
  62175. +{
  62176. + return core_if->core_params->dev_perio_tx_fifo_size[fifo_num];
  62177. +}
  62178. +
  62179. +int dwc_otg_set_param_en_multiple_tx_fifo(dwc_otg_core_if_t * core_if,
  62180. + int32_t val)
  62181. +{
  62182. + int retval = 0;
  62183. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62184. + DWC_WARN("Wrong valaue for en_multiple_tx_fifo,\n");
  62185. + DWC_WARN("en_multiple_tx_fifo must be 0 or 1\n");
  62186. + return -DWC_E_INVALID;
  62187. + }
  62188. +
  62189. + if (val == 1 && core_if->hwcfg4.b.ded_fifo_en == 0) {
  62190. + if (dwc_otg_param_initialized
  62191. + (core_if->core_params->en_multiple_tx_fifo)) {
  62192. + DWC_ERROR
  62193. + ("%d invalid for parameter en_multiple_tx_fifo. Check HW configuration.\n",
  62194. + val);
  62195. + }
  62196. + val = 0;
  62197. + retval = -DWC_E_INVALID;
  62198. + }
  62199. +
  62200. + core_if->core_params->en_multiple_tx_fifo = val;
  62201. + return retval;
  62202. +}
  62203. +
  62204. +int32_t dwc_otg_get_param_en_multiple_tx_fifo(dwc_otg_core_if_t * core_if)
  62205. +{
  62206. + return core_if->core_params->en_multiple_tx_fifo;
  62207. +}
  62208. +
  62209. +int dwc_otg_set_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if, int32_t val,
  62210. + int fifo_num)
  62211. +{
  62212. + int retval = 0;
  62213. +
  62214. + if (DWC_OTG_PARAM_TEST(val, 4, 768)) {
  62215. + DWC_WARN("Wrong value for dev_tx_fifo_size\n");
  62216. + DWC_WARN("dev_tx_fifo_size must be 4-768\n");
  62217. + return -DWC_E_INVALID;
  62218. + }
  62219. +
  62220. + if (val >
  62221. + (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]))) {
  62222. + if (dwc_otg_param_initialized
  62223. + (core_if->core_params->dev_tx_fifo_size[fifo_num])) {
  62224. + DWC_ERROR
  62225. + ("`%d' invalid for parameter `dev_tx_fifo_size_%d'. Check HW configuration.\n",
  62226. + val, fifo_num);
  62227. + }
  62228. + val = (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]));
  62229. + retval = -DWC_E_INVALID;
  62230. + }
  62231. +
  62232. + core_if->core_params->dev_tx_fifo_size[fifo_num] = val;
  62233. + return retval;
  62234. +}
  62235. +
  62236. +int32_t dwc_otg_get_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if,
  62237. + int fifo_num)
  62238. +{
  62239. + return core_if->core_params->dev_tx_fifo_size[fifo_num];
  62240. +}
  62241. +
  62242. +int dwc_otg_set_param_thr_ctl(dwc_otg_core_if_t * core_if, int32_t val)
  62243. +{
  62244. + int retval = 0;
  62245. +
  62246. + if (DWC_OTG_PARAM_TEST(val, 0, 7)) {
  62247. + DWC_WARN("Wrong value for thr_ctl\n");
  62248. + DWC_WARN("thr_ctl must be 0-7\n");
  62249. + return -DWC_E_INVALID;
  62250. + }
  62251. +
  62252. + if ((val != 0) &&
  62253. + (!dwc_otg_get_param_dma_enable(core_if) ||
  62254. + !core_if->hwcfg4.b.ded_fifo_en)) {
  62255. + if (dwc_otg_param_initialized(core_if->core_params->thr_ctl)) {
  62256. + DWC_ERROR
  62257. + ("%d invalid for parameter thr_ctl. Check HW configuration.\n",
  62258. + val);
  62259. + }
  62260. + val = 0;
  62261. + retval = -DWC_E_INVALID;
  62262. + }
  62263. +
  62264. + core_if->core_params->thr_ctl = val;
  62265. + return retval;
  62266. +}
  62267. +
  62268. +int32_t dwc_otg_get_param_thr_ctl(dwc_otg_core_if_t * core_if)
  62269. +{
  62270. + return core_if->core_params->thr_ctl;
  62271. +}
  62272. +
  62273. +int dwc_otg_set_param_lpm_enable(dwc_otg_core_if_t * core_if, int32_t val)
  62274. +{
  62275. + int retval = 0;
  62276. +
  62277. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62278. + DWC_WARN("Wrong value for lpm_enable\n");
  62279. + DWC_WARN("lpm_enable must be 0 or 1\n");
  62280. + return -DWC_E_INVALID;
  62281. + }
  62282. +
  62283. + if (val && !core_if->hwcfg3.b.otg_lpm_en) {
  62284. + if (dwc_otg_param_initialized(core_if->core_params->lpm_enable)) {
  62285. + DWC_ERROR
  62286. + ("%d invalid for parameter lpm_enable. Check HW configuration.\n",
  62287. + val);
  62288. + }
  62289. + val = 0;
  62290. + retval = -DWC_E_INVALID;
  62291. + }
  62292. +
  62293. + core_if->core_params->lpm_enable = val;
  62294. + return retval;
  62295. +}
  62296. +
  62297. +int32_t dwc_otg_get_param_lpm_enable(dwc_otg_core_if_t * core_if)
  62298. +{
  62299. + return core_if->core_params->lpm_enable;
  62300. +}
  62301. +
  62302. +int dwc_otg_set_param_tx_thr_length(dwc_otg_core_if_t * core_if, int32_t val)
  62303. +{
  62304. + if (DWC_OTG_PARAM_TEST(val, 8, 128)) {
  62305. + DWC_WARN("Wrong valaue for tx_thr_length\n");
  62306. + DWC_WARN("tx_thr_length must be 8 - 128\n");
  62307. + return -DWC_E_INVALID;
  62308. + }
  62309. +
  62310. + core_if->core_params->tx_thr_length = val;
  62311. + return 0;
  62312. +}
  62313. +
  62314. +int32_t dwc_otg_get_param_tx_thr_length(dwc_otg_core_if_t * core_if)
  62315. +{
  62316. + return core_if->core_params->tx_thr_length;
  62317. +}
  62318. +
  62319. +int dwc_otg_set_param_rx_thr_length(dwc_otg_core_if_t * core_if, int32_t val)
  62320. +{
  62321. + if (DWC_OTG_PARAM_TEST(val, 8, 128)) {
  62322. + DWC_WARN("Wrong valaue for rx_thr_length\n");
  62323. + DWC_WARN("rx_thr_length must be 8 - 128\n");
  62324. + return -DWC_E_INVALID;
  62325. + }
  62326. +
  62327. + core_if->core_params->rx_thr_length = val;
  62328. + return 0;
  62329. +}
  62330. +
  62331. +int32_t dwc_otg_get_param_rx_thr_length(dwc_otg_core_if_t * core_if)
  62332. +{
  62333. + return core_if->core_params->rx_thr_length;
  62334. +}
  62335. +
  62336. +int dwc_otg_set_param_dma_burst_size(dwc_otg_core_if_t * core_if, int32_t val)
  62337. +{
  62338. + if (DWC_OTG_PARAM_TEST(val, 1, 1) &&
  62339. + DWC_OTG_PARAM_TEST(val, 4, 4) &&
  62340. + DWC_OTG_PARAM_TEST(val, 8, 8) &&
  62341. + DWC_OTG_PARAM_TEST(val, 16, 16) &&
  62342. + DWC_OTG_PARAM_TEST(val, 32, 32) &&
  62343. + DWC_OTG_PARAM_TEST(val, 64, 64) &&
  62344. + DWC_OTG_PARAM_TEST(val, 128, 128) &&
  62345. + DWC_OTG_PARAM_TEST(val, 256, 256)) {
  62346. + DWC_WARN("`%d' invalid for parameter `dma_burst_size'\n", val);
  62347. + return -DWC_E_INVALID;
  62348. + }
  62349. + core_if->core_params->dma_burst_size = val;
  62350. + return 0;
  62351. +}
  62352. +
  62353. +int32_t dwc_otg_get_param_dma_burst_size(dwc_otg_core_if_t * core_if)
  62354. +{
  62355. + return core_if->core_params->dma_burst_size;
  62356. +}
  62357. +
  62358. +int dwc_otg_set_param_pti_enable(dwc_otg_core_if_t * core_if, int32_t val)
  62359. +{
  62360. + int retval = 0;
  62361. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62362. + DWC_WARN("`%d' invalid for parameter `pti_enable'\n", val);
  62363. + return -DWC_E_INVALID;
  62364. + }
  62365. + if (val && (core_if->snpsid < OTG_CORE_REV_2_72a)) {
  62366. + if (dwc_otg_param_initialized(core_if->core_params->pti_enable)) {
  62367. + DWC_ERROR
  62368. + ("%d invalid for parameter pti_enable. Check HW configuration.\n",
  62369. + val);
  62370. + }
  62371. + retval = -DWC_E_INVALID;
  62372. + val = 0;
  62373. + }
  62374. + core_if->core_params->pti_enable = val;
  62375. + return retval;
  62376. +}
  62377. +
  62378. +int32_t dwc_otg_get_param_pti_enable(dwc_otg_core_if_t * core_if)
  62379. +{
  62380. + return core_if->core_params->pti_enable;
  62381. +}
  62382. +
  62383. +int dwc_otg_set_param_mpi_enable(dwc_otg_core_if_t * core_if, int32_t val)
  62384. +{
  62385. + int retval = 0;
  62386. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62387. + DWC_WARN("`%d' invalid for parameter `mpi_enable'\n", val);
  62388. + return -DWC_E_INVALID;
  62389. + }
  62390. + if (val && (core_if->hwcfg2.b.multi_proc_int == 0)) {
  62391. + if (dwc_otg_param_initialized(core_if->core_params->mpi_enable)) {
  62392. + DWC_ERROR
  62393. + ("%d invalid for parameter mpi_enable. Check HW configuration.\n",
  62394. + val);
  62395. + }
  62396. + retval = -DWC_E_INVALID;
  62397. + val = 0;
  62398. + }
  62399. + core_if->core_params->mpi_enable = val;
  62400. + return retval;
  62401. +}
  62402. +
  62403. +int32_t dwc_otg_get_param_mpi_enable(dwc_otg_core_if_t * core_if)
  62404. +{
  62405. + return core_if->core_params->mpi_enable;
  62406. +}
  62407. +
  62408. +int dwc_otg_set_param_adp_enable(dwc_otg_core_if_t * core_if, int32_t val)
  62409. +{
  62410. + int retval = 0;
  62411. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62412. + DWC_WARN("`%d' invalid for parameter `adp_enable'\n", val);
  62413. + return -DWC_E_INVALID;
  62414. + }
  62415. + if (val && (core_if->hwcfg3.b.adp_supp == 0)) {
  62416. + if (dwc_otg_param_initialized
  62417. + (core_if->core_params->adp_supp_enable)) {
  62418. + DWC_ERROR
  62419. + ("%d invalid for parameter adp_enable. Check HW configuration.\n",
  62420. + val);
  62421. + }
  62422. + retval = -DWC_E_INVALID;
  62423. + val = 0;
  62424. + }
  62425. + core_if->core_params->adp_supp_enable = val;
  62426. + /*Set OTG version 2.0 in case of enabling ADP*/
  62427. + if (val)
  62428. + dwc_otg_set_param_otg_ver(core_if, 1);
  62429. +
  62430. + return retval;
  62431. +}
  62432. +
  62433. +int32_t dwc_otg_get_param_adp_enable(dwc_otg_core_if_t * core_if)
  62434. +{
  62435. + return core_if->core_params->adp_supp_enable;
  62436. +}
  62437. +
  62438. +int dwc_otg_set_param_ic_usb_cap(dwc_otg_core_if_t * core_if, int32_t val)
  62439. +{
  62440. + int retval = 0;
  62441. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62442. + DWC_WARN("`%d' invalid for parameter `ic_usb_cap'\n", val);
  62443. + DWC_WARN("ic_usb_cap must be 0 or 1\n");
  62444. + return -DWC_E_INVALID;
  62445. + }
  62446. +
  62447. + if (val && (core_if->hwcfg2.b.otg_enable_ic_usb == 0)) {
  62448. + if (dwc_otg_param_initialized(core_if->core_params->ic_usb_cap)) {
  62449. + DWC_ERROR
  62450. + ("%d invalid for parameter ic_usb_cap. Check HW configuration.\n",
  62451. + val);
  62452. + }
  62453. + retval = -DWC_E_INVALID;
  62454. + val = 0;
  62455. + }
  62456. + core_if->core_params->ic_usb_cap = val;
  62457. + return retval;
  62458. +}
  62459. +
  62460. +int32_t dwc_otg_get_param_ic_usb_cap(dwc_otg_core_if_t * core_if)
  62461. +{
  62462. + return core_if->core_params->ic_usb_cap;
  62463. +}
  62464. +
  62465. +int dwc_otg_set_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if, int32_t val)
  62466. +{
  62467. + int retval = 0;
  62468. + int valid = 1;
  62469. +
  62470. + if (DWC_OTG_PARAM_TEST(val, 0, 3)) {
  62471. + DWC_WARN("`%d' invalid for parameter `ahb_thr_ratio'\n", val);
  62472. + DWC_WARN("ahb_thr_ratio must be 0 - 3\n");
  62473. + return -DWC_E_INVALID;
  62474. + }
  62475. +
  62476. + if (val
  62477. + && (core_if->snpsid < OTG_CORE_REV_2_81a
  62478. + || !dwc_otg_get_param_thr_ctl(core_if))) {
  62479. + valid = 0;
  62480. + } else if (val
  62481. + && ((dwc_otg_get_param_tx_thr_length(core_if) / (1 << val)) <
  62482. + 4)) {
  62483. + valid = 0;
  62484. + }
  62485. + if (valid == 0) {
  62486. + if (dwc_otg_param_initialized
  62487. + (core_if->core_params->ahb_thr_ratio)) {
  62488. + DWC_ERROR
  62489. + ("%d invalid for parameter ahb_thr_ratio. Check HW configuration.\n",
  62490. + val);
  62491. + }
  62492. + retval = -DWC_E_INVALID;
  62493. + val = 0;
  62494. + }
  62495. +
  62496. + core_if->core_params->ahb_thr_ratio = val;
  62497. + return retval;
  62498. +}
  62499. +
  62500. +int32_t dwc_otg_get_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if)
  62501. +{
  62502. + return core_if->core_params->ahb_thr_ratio;
  62503. +}
  62504. +
  62505. +int dwc_otg_set_param_power_down(dwc_otg_core_if_t * core_if, int32_t val)
  62506. +{
  62507. + int retval = 0;
  62508. + int valid = 1;
  62509. + hwcfg4_data_t hwcfg4 = {.d32 = 0 };
  62510. + hwcfg4.d32 = DWC_READ_REG32(&core_if->core_global_regs->ghwcfg4);
  62511. +
  62512. + if (DWC_OTG_PARAM_TEST(val, 0, 3)) {
  62513. + DWC_WARN("`%d' invalid for parameter `power_down'\n", val);
  62514. + DWC_WARN("power_down must be 0 - 2\n");
  62515. + return -DWC_E_INVALID;
  62516. + }
  62517. +
  62518. + if ((val == 2) && (core_if->snpsid < OTG_CORE_REV_2_91a)) {
  62519. + valid = 0;
  62520. + }
  62521. + if ((val == 3)
  62522. + && ((core_if->snpsid < OTG_CORE_REV_3_00a)
  62523. + || (hwcfg4.b.xhiber == 0))) {
  62524. + valid = 0;
  62525. + }
  62526. + if (valid == 0) {
  62527. + if (dwc_otg_param_initialized(core_if->core_params->power_down)) {
  62528. + DWC_ERROR
  62529. + ("%d invalid for parameter power_down. Check HW configuration.\n",
  62530. + val);
  62531. + }
  62532. + retval = -DWC_E_INVALID;
  62533. + val = 0;
  62534. + }
  62535. + core_if->core_params->power_down = val;
  62536. + return retval;
  62537. +}
  62538. +
  62539. +int32_t dwc_otg_get_param_power_down(dwc_otg_core_if_t * core_if)
  62540. +{
  62541. + return core_if->core_params->power_down;
  62542. +}
  62543. +
  62544. +int dwc_otg_set_param_reload_ctl(dwc_otg_core_if_t * core_if, int32_t val)
  62545. +{
  62546. + int retval = 0;
  62547. + int valid = 1;
  62548. +
  62549. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62550. + DWC_WARN("`%d' invalid for parameter `reload_ctl'\n", val);
  62551. + DWC_WARN("reload_ctl must be 0 or 1\n");
  62552. + return -DWC_E_INVALID;
  62553. + }
  62554. +
  62555. + if ((val == 1) && (core_if->snpsid < OTG_CORE_REV_2_92a)) {
  62556. + valid = 0;
  62557. + }
  62558. + if (valid == 0) {
  62559. + if (dwc_otg_param_initialized(core_if->core_params->reload_ctl)) {
  62560. + DWC_ERROR("%d invalid for parameter reload_ctl."
  62561. + "Check HW configuration.\n", val);
  62562. + }
  62563. + retval = -DWC_E_INVALID;
  62564. + val = 0;
  62565. + }
  62566. + core_if->core_params->reload_ctl = val;
  62567. + return retval;
  62568. +}
  62569. +
  62570. +int32_t dwc_otg_get_param_reload_ctl(dwc_otg_core_if_t * core_if)
  62571. +{
  62572. + return core_if->core_params->reload_ctl;
  62573. +}
  62574. +
  62575. +int dwc_otg_set_param_dev_out_nak(dwc_otg_core_if_t * core_if, int32_t val)
  62576. +{
  62577. + int retval = 0;
  62578. + int valid = 1;
  62579. +
  62580. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62581. + DWC_WARN("`%d' invalid for parameter `dev_out_nak'\n", val);
  62582. + DWC_WARN("dev_out_nak must be 0 or 1\n");
  62583. + return -DWC_E_INVALID;
  62584. + }
  62585. +
  62586. + if ((val == 1) && ((core_if->snpsid < OTG_CORE_REV_2_93a) ||
  62587. + !(core_if->core_params->dma_desc_enable))) {
  62588. + valid = 0;
  62589. + }
  62590. + if (valid == 0) {
  62591. + if (dwc_otg_param_initialized(core_if->core_params->dev_out_nak)) {
  62592. + DWC_ERROR("%d invalid for parameter dev_out_nak."
  62593. + "Check HW configuration.\n", val);
  62594. + }
  62595. + retval = -DWC_E_INVALID;
  62596. + val = 0;
  62597. + }
  62598. + core_if->core_params->dev_out_nak = val;
  62599. + return retval;
  62600. +}
  62601. +
  62602. +int32_t dwc_otg_get_param_dev_out_nak(dwc_otg_core_if_t * core_if)
  62603. +{
  62604. + return core_if->core_params->dev_out_nak;
  62605. +}
  62606. +
  62607. +int dwc_otg_set_param_cont_on_bna(dwc_otg_core_if_t * core_if, int32_t val)
  62608. +{
  62609. + int retval = 0;
  62610. + int valid = 1;
  62611. +
  62612. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62613. + DWC_WARN("`%d' invalid for parameter `cont_on_bna'\n", val);
  62614. + DWC_WARN("cont_on_bna must be 0 or 1\n");
  62615. + return -DWC_E_INVALID;
  62616. + }
  62617. +
  62618. + if ((val == 1) && ((core_if->snpsid < OTG_CORE_REV_2_94a) ||
  62619. + !(core_if->core_params->dma_desc_enable))) {
  62620. + valid = 0;
  62621. + }
  62622. + if (valid == 0) {
  62623. + if (dwc_otg_param_initialized(core_if->core_params->cont_on_bna)) {
  62624. + DWC_ERROR("%d invalid for parameter cont_on_bna."
  62625. + "Check HW configuration.\n", val);
  62626. + }
  62627. + retval = -DWC_E_INVALID;
  62628. + val = 0;
  62629. + }
  62630. + core_if->core_params->cont_on_bna = val;
  62631. + return retval;
  62632. +}
  62633. +
  62634. +int32_t dwc_otg_get_param_cont_on_bna(dwc_otg_core_if_t * core_if)
  62635. +{
  62636. + return core_if->core_params->cont_on_bna;
  62637. +}
  62638. +
  62639. +int dwc_otg_set_param_ahb_single(dwc_otg_core_if_t * core_if, int32_t val)
  62640. +{
  62641. + int retval = 0;
  62642. + int valid = 1;
  62643. +
  62644. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62645. + DWC_WARN("`%d' invalid for parameter `ahb_single'\n", val);
  62646. + DWC_WARN("ahb_single must be 0 or 1\n");
  62647. + return -DWC_E_INVALID;
  62648. + }
  62649. +
  62650. + if ((val == 1) && (core_if->snpsid < OTG_CORE_REV_2_94a)) {
  62651. + valid = 0;
  62652. + }
  62653. + if (valid == 0) {
  62654. + if (dwc_otg_param_initialized(core_if->core_params->ahb_single)) {
  62655. + DWC_ERROR("%d invalid for parameter ahb_single."
  62656. + "Check HW configuration.\n", val);
  62657. + }
  62658. + retval = -DWC_E_INVALID;
  62659. + val = 0;
  62660. + }
  62661. + core_if->core_params->ahb_single = val;
  62662. + return retval;
  62663. +}
  62664. +
  62665. +int32_t dwc_otg_get_param_ahb_single(dwc_otg_core_if_t * core_if)
  62666. +{
  62667. + return core_if->core_params->ahb_single;
  62668. +}
  62669. +
  62670. +int dwc_otg_set_param_otg_ver(dwc_otg_core_if_t * core_if, int32_t val)
  62671. +{
  62672. + int retval = 0;
  62673. +
  62674. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62675. + DWC_WARN("`%d' invalid for parameter `otg_ver'\n", val);
  62676. + DWC_WARN
  62677. + ("otg_ver must be 0(for OTG 1.3 support) or 1(for OTG 2.0 support)\n");
  62678. + return -DWC_E_INVALID;
  62679. + }
  62680. +
  62681. + core_if->core_params->otg_ver = val;
  62682. + return retval;
  62683. +}
  62684. +
  62685. +int32_t dwc_otg_get_param_otg_ver(dwc_otg_core_if_t * core_if)
  62686. +{
  62687. + return core_if->core_params->otg_ver;
  62688. +}
  62689. +
  62690. +uint32_t dwc_otg_get_hnpstatus(dwc_otg_core_if_t * core_if)
  62691. +{
  62692. + gotgctl_data_t otgctl;
  62693. + otgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  62694. + return otgctl.b.hstnegscs;
  62695. +}
  62696. +
  62697. +uint32_t dwc_otg_get_srpstatus(dwc_otg_core_if_t * core_if)
  62698. +{
  62699. + gotgctl_data_t otgctl;
  62700. + otgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  62701. + return otgctl.b.sesreqscs;
  62702. +}
  62703. +
  62704. +void dwc_otg_set_hnpreq(dwc_otg_core_if_t * core_if, uint32_t val)
  62705. +{
  62706. + if(core_if->otg_ver == 0) {
  62707. + gotgctl_data_t otgctl;
  62708. + otgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  62709. + otgctl.b.hnpreq = val;
  62710. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgctl, otgctl.d32);
  62711. + } else {
  62712. + core_if->otg_sts = val;
  62713. + }
  62714. +}
  62715. +
  62716. +uint32_t dwc_otg_get_gsnpsid(dwc_otg_core_if_t * core_if)
  62717. +{
  62718. + return core_if->snpsid;
  62719. +}
  62720. +
  62721. +uint32_t dwc_otg_get_mode(dwc_otg_core_if_t * core_if)
  62722. +{
  62723. + gintsts_data_t gintsts;
  62724. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  62725. + return gintsts.b.curmode;
  62726. +}
  62727. +
  62728. +uint32_t dwc_otg_get_hnpcapable(dwc_otg_core_if_t * core_if)
  62729. +{
  62730. + gusbcfg_data_t usbcfg;
  62731. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  62732. + return usbcfg.b.hnpcap;
  62733. +}
  62734. +
  62735. +void dwc_otg_set_hnpcapable(dwc_otg_core_if_t * core_if, uint32_t val)
  62736. +{
  62737. + gusbcfg_data_t usbcfg;
  62738. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  62739. + usbcfg.b.hnpcap = val;
  62740. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, usbcfg.d32);
  62741. +}
  62742. +
  62743. +uint32_t dwc_otg_get_srpcapable(dwc_otg_core_if_t * core_if)
  62744. +{
  62745. + gusbcfg_data_t usbcfg;
  62746. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  62747. + return usbcfg.b.srpcap;
  62748. +}
  62749. +
  62750. +void dwc_otg_set_srpcapable(dwc_otg_core_if_t * core_if, uint32_t val)
  62751. +{
  62752. + gusbcfg_data_t usbcfg;
  62753. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  62754. + usbcfg.b.srpcap = val;
  62755. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, usbcfg.d32);
  62756. +}
  62757. +
  62758. +uint32_t dwc_otg_get_devspeed(dwc_otg_core_if_t * core_if)
  62759. +{
  62760. + dcfg_data_t dcfg;
  62761. + /* originally: dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg); */
  62762. +
  62763. + dcfg.d32 = -1; //GRAYG
  62764. + DWC_DEBUGPL(DBG_CILV, "%s - core_if(%p)\n", __func__, core_if);
  62765. + if (NULL == core_if)
  62766. + DWC_ERROR("reg request with NULL core_if\n");
  62767. + DWC_DEBUGPL(DBG_CILV, "%s - core_if(%p)->dev_if(%p)\n", __func__,
  62768. + core_if, core_if->dev_if);
  62769. + if (NULL == core_if->dev_if)
  62770. + DWC_ERROR("reg request with NULL dev_if\n");
  62771. + DWC_DEBUGPL(DBG_CILV, "%s - core_if(%p)->dev_if(%p)->"
  62772. + "dev_global_regs(%p)\n", __func__,
  62773. + core_if, core_if->dev_if,
  62774. + core_if->dev_if->dev_global_regs);
  62775. + if (NULL == core_if->dev_if->dev_global_regs)
  62776. + DWC_ERROR("reg request with NULL dev_global_regs\n");
  62777. + else {
  62778. + DWC_DEBUGPL(DBG_CILV, "%s - &core_if(%p)->dev_if(%p)->"
  62779. + "dev_global_regs(%p)->dcfg = %p\n", __func__,
  62780. + core_if, core_if->dev_if,
  62781. + core_if->dev_if->dev_global_regs,
  62782. + &core_if->dev_if->dev_global_regs->dcfg);
  62783. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  62784. + }
  62785. + return dcfg.b.devspd;
  62786. +}
  62787. +
  62788. +void dwc_otg_set_devspeed(dwc_otg_core_if_t * core_if, uint32_t val)
  62789. +{
  62790. + dcfg_data_t dcfg;
  62791. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  62792. + dcfg.b.devspd = val;
  62793. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
  62794. +}
  62795. +
  62796. +uint32_t dwc_otg_get_busconnected(dwc_otg_core_if_t * core_if)
  62797. +{
  62798. + hprt0_data_t hprt0;
  62799. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  62800. + return hprt0.b.prtconnsts;
  62801. +}
  62802. +
  62803. +uint32_t dwc_otg_get_enumspeed(dwc_otg_core_if_t * core_if)
  62804. +{
  62805. + dsts_data_t dsts;
  62806. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  62807. + return dsts.b.enumspd;
  62808. +}
  62809. +
  62810. +uint32_t dwc_otg_get_prtpower(dwc_otg_core_if_t * core_if)
  62811. +{
  62812. + hprt0_data_t hprt0;
  62813. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  62814. + return hprt0.b.prtpwr;
  62815. +
  62816. +}
  62817. +
  62818. +uint32_t dwc_otg_get_core_state(dwc_otg_core_if_t * core_if)
  62819. +{
  62820. + return core_if->hibernation_suspend;
  62821. +}
  62822. +
  62823. +void dwc_otg_set_prtpower(dwc_otg_core_if_t * core_if, uint32_t val)
  62824. +{
  62825. + hprt0_data_t hprt0;
  62826. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  62827. + hprt0.b.prtpwr = val;
  62828. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  62829. +}
  62830. +
  62831. +uint32_t dwc_otg_get_prtsuspend(dwc_otg_core_if_t * core_if)
  62832. +{
  62833. + hprt0_data_t hprt0;
  62834. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  62835. + return hprt0.b.prtsusp;
  62836. +
  62837. +}
  62838. +
  62839. +void dwc_otg_set_prtsuspend(dwc_otg_core_if_t * core_if, uint32_t val)
  62840. +{
  62841. + hprt0_data_t hprt0;
  62842. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  62843. + hprt0.b.prtsusp = val;
  62844. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  62845. +}
  62846. +
  62847. +uint32_t dwc_otg_get_fr_interval(dwc_otg_core_if_t * core_if)
  62848. +{
  62849. + hfir_data_t hfir;
  62850. + hfir.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hfir);
  62851. + return hfir.b.frint;
  62852. +
  62853. +}
  62854. +
  62855. +void dwc_otg_set_fr_interval(dwc_otg_core_if_t * core_if, uint32_t val)
  62856. +{
  62857. + hfir_data_t hfir;
  62858. + uint32_t fram_int;
  62859. + fram_int = calc_frame_interval(core_if);
  62860. + hfir.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hfir);
  62861. + if (!core_if->core_params->reload_ctl) {
  62862. + DWC_WARN("\nCannot reload HFIR register.HFIR.HFIRRldCtrl bit is"
  62863. + "not set to 1.\nShould load driver with reload_ctl=1"
  62864. + " module parameter\n");
  62865. + return;
  62866. + }
  62867. + switch (fram_int) {
  62868. + case 3750:
  62869. + if ((val < 3350) || (val > 4150)) {
  62870. + DWC_WARN("HFIR interval for HS core and 30 MHz"
  62871. + "clock freq should be from 3350 to 4150\n");
  62872. + return;
  62873. + }
  62874. + break;
  62875. + case 30000:
  62876. + if ((val < 26820) || (val > 33180)) {
  62877. + DWC_WARN("HFIR interval for FS/LS core and 30 MHz"
  62878. + "clock freq should be from 26820 to 33180\n");
  62879. + return;
  62880. + }
  62881. + break;
  62882. + case 6000:
  62883. + if ((val < 5360) || (val > 6640)) {
  62884. + DWC_WARN("HFIR interval for HS core and 48 MHz"
  62885. + "clock freq should be from 5360 to 6640\n");
  62886. + return;
  62887. + }
  62888. + break;
  62889. + case 48000:
  62890. + if ((val < 42912) || (val > 53088)) {
  62891. + DWC_WARN("HFIR interval for FS/LS core and 48 MHz"
  62892. + "clock freq should be from 42912 to 53088\n");
  62893. + return;
  62894. + }
  62895. + break;
  62896. + case 7500:
  62897. + if ((val < 6700) || (val > 8300)) {
  62898. + DWC_WARN("HFIR interval for HS core and 60 MHz"
  62899. + "clock freq should be from 6700 to 8300\n");
  62900. + return;
  62901. + }
  62902. + break;
  62903. + case 60000:
  62904. + if ((val < 53640) || (val > 65536)) {
  62905. + DWC_WARN("HFIR interval for FS/LS core and 60 MHz"
  62906. + "clock freq should be from 53640 to 65536\n");
  62907. + return;
  62908. + }
  62909. + break;
  62910. + default:
  62911. + DWC_WARN("Unknown frame interval\n");
  62912. + return;
  62913. + break;
  62914. +
  62915. + }
  62916. + hfir.b.frint = val;
  62917. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hfir, hfir.d32);
  62918. +}
  62919. +
  62920. +uint32_t dwc_otg_get_mode_ch_tim(dwc_otg_core_if_t * core_if)
  62921. +{
  62922. + hcfg_data_t hcfg;
  62923. + hcfg.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  62924. + return hcfg.b.modechtimen;
  62925. +
  62926. +}
  62927. +
  62928. +void dwc_otg_set_mode_ch_tim(dwc_otg_core_if_t * core_if, uint32_t val)
  62929. +{
  62930. + hcfg_data_t hcfg;
  62931. + hcfg.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  62932. + hcfg.b.modechtimen = val;
  62933. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  62934. +}
  62935. +
  62936. +void dwc_otg_set_prtresume(dwc_otg_core_if_t * core_if, uint32_t val)
  62937. +{
  62938. + hprt0_data_t hprt0;
  62939. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  62940. + hprt0.b.prtres = val;
  62941. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  62942. +}
  62943. +
  62944. +uint32_t dwc_otg_get_remotewakesig(dwc_otg_core_if_t * core_if)
  62945. +{
  62946. + dctl_data_t dctl;
  62947. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  62948. + return dctl.b.rmtwkupsig;
  62949. +}
  62950. +
  62951. +uint32_t dwc_otg_get_lpm_portsleepstatus(dwc_otg_core_if_t * core_if)
  62952. +{
  62953. + glpmcfg_data_t lpmcfg;
  62954. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  62955. +
  62956. + DWC_ASSERT(!
  62957. + ((core_if->lx_state == DWC_OTG_L1) ^ lpmcfg.b.prt_sleep_sts),
  62958. + "lx_state = %d, lmpcfg.prt_sleep_sts = %d\n",
  62959. + core_if->lx_state, lpmcfg.b.prt_sleep_sts);
  62960. +
  62961. + return lpmcfg.b.prt_sleep_sts;
  62962. +}
  62963. +
  62964. +uint32_t dwc_otg_get_lpm_remotewakeenabled(dwc_otg_core_if_t * core_if)
  62965. +{
  62966. + glpmcfg_data_t lpmcfg;
  62967. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  62968. + return lpmcfg.b.rem_wkup_en;
  62969. +}
  62970. +
  62971. +uint32_t dwc_otg_get_lpmresponse(dwc_otg_core_if_t * core_if)
  62972. +{
  62973. + glpmcfg_data_t lpmcfg;
  62974. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  62975. + return lpmcfg.b.appl_resp;
  62976. +}
  62977. +
  62978. +void dwc_otg_set_lpmresponse(dwc_otg_core_if_t * core_if, uint32_t val)
  62979. +{
  62980. + glpmcfg_data_t lpmcfg;
  62981. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  62982. + lpmcfg.b.appl_resp = val;
  62983. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  62984. +}
  62985. +
  62986. +uint32_t dwc_otg_get_hsic_connect(dwc_otg_core_if_t * core_if)
  62987. +{
  62988. + glpmcfg_data_t lpmcfg;
  62989. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  62990. + return lpmcfg.b.hsic_connect;
  62991. +}
  62992. +
  62993. +void dwc_otg_set_hsic_connect(dwc_otg_core_if_t * core_if, uint32_t val)
  62994. +{
  62995. + glpmcfg_data_t lpmcfg;
  62996. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  62997. + lpmcfg.b.hsic_connect = val;
  62998. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  62999. +}
  63000. +
  63001. +uint32_t dwc_otg_get_inv_sel_hsic(dwc_otg_core_if_t * core_if)
  63002. +{
  63003. + glpmcfg_data_t lpmcfg;
  63004. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  63005. + return lpmcfg.b.inv_sel_hsic;
  63006. +
  63007. +}
  63008. +
  63009. +void dwc_otg_set_inv_sel_hsic(dwc_otg_core_if_t * core_if, uint32_t val)
  63010. +{
  63011. + glpmcfg_data_t lpmcfg;
  63012. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  63013. + lpmcfg.b.inv_sel_hsic = val;
  63014. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  63015. +}
  63016. +
  63017. +uint32_t dwc_otg_get_gotgctl(dwc_otg_core_if_t * core_if)
  63018. +{
  63019. + return DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  63020. +}
  63021. +
  63022. +void dwc_otg_set_gotgctl(dwc_otg_core_if_t * core_if, uint32_t val)
  63023. +{
  63024. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgctl, val);
  63025. +}
  63026. +
  63027. +uint32_t dwc_otg_get_gusbcfg(dwc_otg_core_if_t * core_if)
  63028. +{
  63029. + return DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  63030. +}
  63031. +
  63032. +void dwc_otg_set_gusbcfg(dwc_otg_core_if_t * core_if, uint32_t val)
  63033. +{
  63034. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, val);
  63035. +}
  63036. +
  63037. +uint32_t dwc_otg_get_grxfsiz(dwc_otg_core_if_t * core_if)
  63038. +{
  63039. + return DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  63040. +}
  63041. +
  63042. +void dwc_otg_set_grxfsiz(dwc_otg_core_if_t * core_if, uint32_t val)
  63043. +{
  63044. + DWC_WRITE_REG32(&core_if->core_global_regs->grxfsiz, val);
  63045. +}
  63046. +
  63047. +uint32_t dwc_otg_get_gnptxfsiz(dwc_otg_core_if_t * core_if)
  63048. +{
  63049. + return DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz);
  63050. +}
  63051. +
  63052. +void dwc_otg_set_gnptxfsiz(dwc_otg_core_if_t * core_if, uint32_t val)
  63053. +{
  63054. + DWC_WRITE_REG32(&core_if->core_global_regs->gnptxfsiz, val);
  63055. +}
  63056. +
  63057. +uint32_t dwc_otg_get_gpvndctl(dwc_otg_core_if_t * core_if)
  63058. +{
  63059. + return DWC_READ_REG32(&core_if->core_global_regs->gpvndctl);
  63060. +}
  63061. +
  63062. +void dwc_otg_set_gpvndctl(dwc_otg_core_if_t * core_if, uint32_t val)
  63063. +{
  63064. + DWC_WRITE_REG32(&core_if->core_global_regs->gpvndctl, val);
  63065. +}
  63066. +
  63067. +uint32_t dwc_otg_get_ggpio(dwc_otg_core_if_t * core_if)
  63068. +{
  63069. + return DWC_READ_REG32(&core_if->core_global_regs->ggpio);
  63070. +}
  63071. +
  63072. +void dwc_otg_set_ggpio(dwc_otg_core_if_t * core_if, uint32_t val)
  63073. +{
  63074. + DWC_WRITE_REG32(&core_if->core_global_regs->ggpio, val);
  63075. +}
  63076. +
  63077. +uint32_t dwc_otg_get_hprt0(dwc_otg_core_if_t * core_if)
  63078. +{
  63079. + return DWC_READ_REG32(core_if->host_if->hprt0);
  63080. +
  63081. +}
  63082. +
  63083. +void dwc_otg_set_hprt0(dwc_otg_core_if_t * core_if, uint32_t val)
  63084. +{
  63085. + DWC_WRITE_REG32(core_if->host_if->hprt0, val);
  63086. +}
  63087. +
  63088. +uint32_t dwc_otg_get_guid(dwc_otg_core_if_t * core_if)
  63089. +{
  63090. + return DWC_READ_REG32(&core_if->core_global_regs->guid);
  63091. +}
  63092. +
  63093. +void dwc_otg_set_guid(dwc_otg_core_if_t * core_if, uint32_t val)
  63094. +{
  63095. + DWC_WRITE_REG32(&core_if->core_global_regs->guid, val);
  63096. +}
  63097. +
  63098. +uint32_t dwc_otg_get_hptxfsiz(dwc_otg_core_if_t * core_if)
  63099. +{
  63100. + return DWC_READ_REG32(&core_if->core_global_regs->hptxfsiz);
  63101. +}
  63102. +
  63103. +uint16_t dwc_otg_get_otg_version(dwc_otg_core_if_t * core_if)
  63104. +{
  63105. + return ((core_if->otg_ver == 1) ? (uint16_t)0x0200 : (uint16_t)0x0103);
  63106. +}
  63107. +
  63108. +/**
  63109. + * Start the SRP timer to detect when the SRP does not complete within
  63110. + * 6 seconds.
  63111. + *
  63112. + * @param core_if the pointer to core_if strucure.
  63113. + */
  63114. +void dwc_otg_pcd_start_srp_timer(dwc_otg_core_if_t * core_if)
  63115. +{
  63116. + core_if->srp_timer_started = 1;
  63117. + DWC_TIMER_SCHEDULE(core_if->srp_timer, 6000 /* 6 secs */ );
  63118. +}
  63119. +
  63120. +void dwc_otg_initiate_srp(dwc_otg_core_if_t * core_if)
  63121. +{
  63122. + uint32_t *addr = (uint32_t *) & (core_if->core_global_regs->gotgctl);
  63123. + gotgctl_data_t mem;
  63124. + gotgctl_data_t val;
  63125. +
  63126. + val.d32 = DWC_READ_REG32(addr);
  63127. + if (val.b.sesreq) {
  63128. + DWC_ERROR("Session Request Already active!\n");
  63129. + return;
  63130. + }
  63131. +
  63132. + DWC_INFO("Session Request Initated\n"); //NOTICE
  63133. + mem.d32 = DWC_READ_REG32(addr);
  63134. + mem.b.sesreq = 1;
  63135. + DWC_WRITE_REG32(addr, mem.d32);
  63136. +
  63137. + /* Start the SRP timer */
  63138. + dwc_otg_pcd_start_srp_timer(core_if);
  63139. + return;
  63140. +}
  63141. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_cil.h linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_cil.h
  63142. --- linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_cil.h 1970-01-01 01:00:00.000000000 +0100
  63143. +++ linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_cil.h 2014-08-06 16:50:14.801964726 +0200
  63144. @@ -0,0 +1,1464 @@
  63145. +/* ==========================================================================
  63146. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil.h $
  63147. + * $Revision: #123 $
  63148. + * $Date: 2012/08/10 $
  63149. + * $Change: 2047372 $
  63150. + *
  63151. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  63152. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  63153. + * otherwise expressly agreed to in writing between Synopsys and you.
  63154. + *
  63155. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  63156. + * any End User Software License Agreement or Agreement for Licensed Product
  63157. + * with Synopsys or any supplement thereto. You are permitted to use and
  63158. + * redistribute this Software in source and binary forms, with or without
  63159. + * modification, provided that redistributions of source code must retain this
  63160. + * notice. You may not view, use, disclose, copy or distribute this file or
  63161. + * any information contained herein except pursuant to this license grant from
  63162. + * Synopsys. If you do not agree with this notice, including the disclaimer
  63163. + * below, then you are not authorized to use the Software.
  63164. + *
  63165. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  63166. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  63167. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  63168. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  63169. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  63170. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  63171. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  63172. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  63173. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  63174. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  63175. + * DAMAGE.
  63176. + * ========================================================================== */
  63177. +
  63178. +#if !defined(__DWC_CIL_H__)
  63179. +#define __DWC_CIL_H__
  63180. +
  63181. +#include "dwc_list.h"
  63182. +#include "dwc_otg_dbg.h"
  63183. +#include "dwc_otg_regs.h"
  63184. +
  63185. +#include "dwc_otg_core_if.h"
  63186. +#include "dwc_otg_adp.h"
  63187. +
  63188. +/**
  63189. + * @file
  63190. + * This file contains the interface to the Core Interface Layer.
  63191. + */
  63192. +
  63193. +#ifdef DWC_UTE_CFI
  63194. +
  63195. +#define MAX_DMA_DESCS_PER_EP 256
  63196. +
  63197. +/**
  63198. + * Enumeration for the data buffer mode
  63199. + */
  63200. +typedef enum _data_buffer_mode {
  63201. + BM_STANDARD = 0, /* data buffer is in normal mode */
  63202. + BM_SG = 1, /* data buffer uses the scatter/gather mode */
  63203. + BM_CONCAT = 2, /* data buffer uses the concatenation mode */
  63204. + BM_CIRCULAR = 3, /* data buffer uses the circular DMA mode */
  63205. + BM_ALIGN = 4 /* data buffer is in buffer alignment mode */
  63206. +} data_buffer_mode_e;
  63207. +#endif //DWC_UTE_CFI
  63208. +
  63209. +/** Macros defined for DWC OTG HW Release version */
  63210. +
  63211. +#define OTG_CORE_REV_2_60a 0x4F54260A
  63212. +#define OTG_CORE_REV_2_71a 0x4F54271A
  63213. +#define OTG_CORE_REV_2_72a 0x4F54272A
  63214. +#define OTG_CORE_REV_2_80a 0x4F54280A
  63215. +#define OTG_CORE_REV_2_81a 0x4F54281A
  63216. +#define OTG_CORE_REV_2_90a 0x4F54290A
  63217. +#define OTG_CORE_REV_2_91a 0x4F54291A
  63218. +#define OTG_CORE_REV_2_92a 0x4F54292A
  63219. +#define OTG_CORE_REV_2_93a 0x4F54293A
  63220. +#define OTG_CORE_REV_2_94a 0x4F54294A
  63221. +#define OTG_CORE_REV_3_00a 0x4F54300A
  63222. +
  63223. +/**
  63224. + * Information for each ISOC packet.
  63225. + */
  63226. +typedef struct iso_pkt_info {
  63227. + uint32_t offset;
  63228. + uint32_t length;
  63229. + int32_t status;
  63230. +} iso_pkt_info_t;
  63231. +
  63232. +/**
  63233. + * The <code>dwc_ep</code> structure represents the state of a single
  63234. + * endpoint when acting in device mode. It contains the data items
  63235. + * needed for an endpoint to be activated and transfer packets.
  63236. + */
  63237. +typedef struct dwc_ep {
  63238. + /** EP number used for register address lookup */
  63239. + uint8_t num;
  63240. + /** EP direction 0 = OUT */
  63241. + unsigned is_in:1;
  63242. + /** EP active. */
  63243. + unsigned active:1;
  63244. +
  63245. + /**
  63246. + * Periodic Tx FIFO # for IN EPs For INTR EP set to 0 to use non-periodic
  63247. + * Tx FIFO. If dedicated Tx FIFOs are enabled Tx FIFO # FOR IN EPs*/
  63248. + unsigned tx_fifo_num:4;
  63249. + /** EP type: 0 - Control, 1 - ISOC, 2 - BULK, 3 - INTR */
  63250. + unsigned type:2;
  63251. +#define DWC_OTG_EP_TYPE_CONTROL 0
  63252. +#define DWC_OTG_EP_TYPE_ISOC 1
  63253. +#define DWC_OTG_EP_TYPE_BULK 2
  63254. +#define DWC_OTG_EP_TYPE_INTR 3
  63255. +
  63256. + /** DATA start PID for INTR and BULK EP */
  63257. + unsigned data_pid_start:1;
  63258. + /** Frame (even/odd) for ISOC EP */
  63259. + unsigned even_odd_frame:1;
  63260. + /** Max Packet bytes */
  63261. + unsigned maxpacket:11;
  63262. +
  63263. + /** Max Transfer size */
  63264. + uint32_t maxxfer;
  63265. +
  63266. + /** @name Transfer state */
  63267. + /** @{ */
  63268. +
  63269. + /**
  63270. + * Pointer to the beginning of the transfer buffer -- do not modify
  63271. + * during transfer.
  63272. + */
  63273. +
  63274. + dwc_dma_t dma_addr;
  63275. +
  63276. + dwc_dma_t dma_desc_addr;
  63277. + dwc_otg_dev_dma_desc_t *desc_addr;
  63278. +
  63279. + uint8_t *start_xfer_buff;
  63280. + /** pointer to the transfer buffer */
  63281. + uint8_t *xfer_buff;
  63282. + /** Number of bytes to transfer */
  63283. + unsigned xfer_len:19;
  63284. + /** Number of bytes transferred. */
  63285. + unsigned xfer_count:19;
  63286. + /** Sent ZLP */
  63287. + unsigned sent_zlp:1;
  63288. + /** Total len for control transfer */
  63289. + unsigned total_len:19;
  63290. +
  63291. + /** stall clear flag */
  63292. + unsigned stall_clear_flag:1;
  63293. +
  63294. + /** SETUP pkt cnt rollover flag for EP0 out*/
  63295. + unsigned stp_rollover;
  63296. +
  63297. +#ifdef DWC_UTE_CFI
  63298. + /* The buffer mode */
  63299. + data_buffer_mode_e buff_mode;
  63300. +
  63301. + /* The chain of DMA descriptors.
  63302. + * MAX_DMA_DESCS_PER_EP will be allocated for each active EP.
  63303. + */
  63304. + dwc_otg_dma_desc_t *descs;
  63305. +
  63306. + /* The DMA address of the descriptors chain start */
  63307. + dma_addr_t descs_dma_addr;
  63308. + /** This variable stores the length of the last enqueued request */
  63309. + uint32_t cfi_req_len;
  63310. +#endif //DWC_UTE_CFI
  63311. +
  63312. +/** Max DMA Descriptor count for any EP */
  63313. +#define MAX_DMA_DESC_CNT 256
  63314. + /** Allocated DMA Desc count */
  63315. + uint32_t desc_cnt;
  63316. +
  63317. + /** bInterval */
  63318. + uint32_t bInterval;
  63319. + /** Next frame num to setup next ISOC transfer */
  63320. + uint32_t frame_num;
  63321. + /** Indicates SOF number overrun in DSTS */
  63322. + uint8_t frm_overrun;
  63323. +
  63324. +#ifdef DWC_UTE_PER_IO
  63325. + /** Next frame num for which will be setup DMA Desc */
  63326. + uint32_t xiso_frame_num;
  63327. + /** bInterval */
  63328. + uint32_t xiso_bInterval;
  63329. + /** Count of currently active transfers - shall be either 0 or 1 */
  63330. + int xiso_active_xfers;
  63331. + int xiso_queued_xfers;
  63332. +#endif
  63333. +#ifdef DWC_EN_ISOC
  63334. + /**
  63335. + * Variables specific for ISOC EPs
  63336. + *
  63337. + */
  63338. + /** DMA addresses of ISOC buffers */
  63339. + dwc_dma_t dma_addr0;
  63340. + dwc_dma_t dma_addr1;
  63341. +
  63342. + dwc_dma_t iso_dma_desc_addr;
  63343. + dwc_otg_dev_dma_desc_t *iso_desc_addr;
  63344. +
  63345. + /** pointer to the transfer buffers */
  63346. + uint8_t *xfer_buff0;
  63347. + uint8_t *xfer_buff1;
  63348. +
  63349. + /** number of ISOC Buffer is processing */
  63350. + uint32_t proc_buf_num;
  63351. + /** Interval of ISOC Buffer processing */
  63352. + uint32_t buf_proc_intrvl;
  63353. + /** Data size for regular frame */
  63354. + uint32_t data_per_frame;
  63355. +
  63356. + /* todo - pattern data support is to be implemented in the future */
  63357. + /** Data size for pattern frame */
  63358. + uint32_t data_pattern_frame;
  63359. + /** Frame number of pattern data */
  63360. + uint32_t sync_frame;
  63361. +
  63362. + /** bInterval */
  63363. + uint32_t bInterval;
  63364. + /** ISO Packet number per frame */
  63365. + uint32_t pkt_per_frm;
  63366. + /** Next frame num for which will be setup DMA Desc */
  63367. + uint32_t next_frame;
  63368. + /** Number of packets per buffer processing */
  63369. + uint32_t pkt_cnt;
  63370. + /** Info for all isoc packets */
  63371. + iso_pkt_info_t *pkt_info;
  63372. + /** current pkt number */
  63373. + uint32_t cur_pkt;
  63374. + /** current pkt number */
  63375. + uint8_t *cur_pkt_addr;
  63376. + /** current pkt number */
  63377. + uint32_t cur_pkt_dma_addr;
  63378. +#endif /* DWC_EN_ISOC */
  63379. +
  63380. +/** @} */
  63381. +} dwc_ep_t;
  63382. +
  63383. +/*
  63384. + * Reasons for halting a host channel.
  63385. + */
  63386. +typedef enum dwc_otg_halt_status {
  63387. + DWC_OTG_HC_XFER_NO_HALT_STATUS,
  63388. + DWC_OTG_HC_XFER_COMPLETE,
  63389. + DWC_OTG_HC_XFER_URB_COMPLETE,
  63390. + DWC_OTG_HC_XFER_ACK,
  63391. + DWC_OTG_HC_XFER_NAK,
  63392. + DWC_OTG_HC_XFER_NYET,
  63393. + DWC_OTG_HC_XFER_STALL,
  63394. + DWC_OTG_HC_XFER_XACT_ERR,
  63395. + DWC_OTG_HC_XFER_FRAME_OVERRUN,
  63396. + DWC_OTG_HC_XFER_BABBLE_ERR,
  63397. + DWC_OTG_HC_XFER_DATA_TOGGLE_ERR,
  63398. + DWC_OTG_HC_XFER_AHB_ERR,
  63399. + DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE,
  63400. + DWC_OTG_HC_XFER_URB_DEQUEUE
  63401. +} dwc_otg_halt_status_e;
  63402. +
  63403. +/**
  63404. + * Host channel descriptor. This structure represents the state of a single
  63405. + * host channel when acting in host mode. It contains the data items needed to
  63406. + * transfer packets to an endpoint via a host channel.
  63407. + */
  63408. +typedef struct dwc_hc {
  63409. + /** Host channel number used for register address lookup */
  63410. + uint8_t hc_num;
  63411. +
  63412. + /** Device to access */
  63413. + unsigned dev_addr:7;
  63414. +
  63415. + /** EP to access */
  63416. + unsigned ep_num:4;
  63417. +
  63418. + /** EP direction. 0: OUT, 1: IN */
  63419. + unsigned ep_is_in:1;
  63420. +
  63421. + /**
  63422. + * EP speed.
  63423. + * One of the following values:
  63424. + * - DWC_OTG_EP_SPEED_LOW
  63425. + * - DWC_OTG_EP_SPEED_FULL
  63426. + * - DWC_OTG_EP_SPEED_HIGH
  63427. + */
  63428. + unsigned speed:2;
  63429. +#define DWC_OTG_EP_SPEED_LOW 0
  63430. +#define DWC_OTG_EP_SPEED_FULL 1
  63431. +#define DWC_OTG_EP_SPEED_HIGH 2
  63432. +
  63433. + /**
  63434. + * Endpoint type.
  63435. + * One of the following values:
  63436. + * - DWC_OTG_EP_TYPE_CONTROL: 0
  63437. + * - DWC_OTG_EP_TYPE_ISOC: 1
  63438. + * - DWC_OTG_EP_TYPE_BULK: 2
  63439. + * - DWC_OTG_EP_TYPE_INTR: 3
  63440. + */
  63441. + unsigned ep_type:2;
  63442. +
  63443. + /** Max packet size in bytes */
  63444. + unsigned max_packet:11;
  63445. +
  63446. + /**
  63447. + * PID for initial transaction.
  63448. + * 0: DATA0,<br>
  63449. + * 1: DATA2,<br>
  63450. + * 2: DATA1,<br>
  63451. + * 3: MDATA (non-Control EP),
  63452. + * SETUP (Control EP)
  63453. + */
  63454. + unsigned data_pid_start:2;
  63455. +#define DWC_OTG_HC_PID_DATA0 0
  63456. +#define DWC_OTG_HC_PID_DATA2 1
  63457. +#define DWC_OTG_HC_PID_DATA1 2
  63458. +#define DWC_OTG_HC_PID_MDATA 3
  63459. +#define DWC_OTG_HC_PID_SETUP 3
  63460. +
  63461. + /** Number of periodic transactions per (micro)frame */
  63462. + unsigned multi_count:2;
  63463. +
  63464. + /** @name Transfer State */
  63465. + /** @{ */
  63466. +
  63467. + /** Pointer to the current transfer buffer position. */
  63468. + uint8_t *xfer_buff;
  63469. + /**
  63470. + * In Buffer DMA mode this buffer will be used
  63471. + * if xfer_buff is not DWORD aligned.
  63472. + */
  63473. + dwc_dma_t align_buff;
  63474. + /** Total number of bytes to transfer. */
  63475. + uint32_t xfer_len;
  63476. + /** Number of bytes transferred so far. */
  63477. + uint32_t xfer_count;
  63478. + /** Packet count at start of transfer.*/
  63479. + uint16_t start_pkt_count;
  63480. +
  63481. + /**
  63482. + * Flag to indicate whether the transfer has been started. Set to 1 if
  63483. + * it has been started, 0 otherwise.
  63484. + */
  63485. + uint8_t xfer_started;
  63486. +
  63487. + /**
  63488. + * Set to 1 to indicate that a PING request should be issued on this
  63489. + * channel. If 0, process normally.
  63490. + */
  63491. + uint8_t do_ping;
  63492. +
  63493. + /**
  63494. + * Set to 1 to indicate that the error count for this transaction is
  63495. + * non-zero. Set to 0 if the error count is 0.
  63496. + */
  63497. + uint8_t error_state;
  63498. +
  63499. + /**
  63500. + * Set to 1 to indicate that this channel should be halted the next
  63501. + * time a request is queued for the channel. This is necessary in
  63502. + * slave mode if no request queue space is available when an attempt
  63503. + * is made to halt the channel.
  63504. + */
  63505. + uint8_t halt_on_queue;
  63506. +
  63507. + /**
  63508. + * Set to 1 if the host channel has been halted, but the core is not
  63509. + * finished flushing queued requests. Otherwise 0.
  63510. + */
  63511. + uint8_t halt_pending;
  63512. +
  63513. + /**
  63514. + * Reason for halting the host channel.
  63515. + */
  63516. + dwc_otg_halt_status_e halt_status;
  63517. +
  63518. + /*
  63519. + * Split settings for the host channel
  63520. + */
  63521. + uint8_t do_split; /**< Enable split for the channel */
  63522. + uint8_t complete_split; /**< Enable complete split */
  63523. + uint8_t hub_addr; /**< Address of high speed hub */
  63524. +
  63525. + uint8_t port_addr; /**< Port of the low/full speed device */
  63526. + /** Split transaction position
  63527. + * One of the following values:
  63528. + * - DWC_HCSPLIT_XACTPOS_MID
  63529. + * - DWC_HCSPLIT_XACTPOS_BEGIN
  63530. + * - DWC_HCSPLIT_XACTPOS_END
  63531. + * - DWC_HCSPLIT_XACTPOS_ALL */
  63532. + uint8_t xact_pos;
  63533. +
  63534. + /** Set when the host channel does a short read. */
  63535. + uint8_t short_read;
  63536. +
  63537. + /**
  63538. + * Number of requests issued for this channel since it was assigned to
  63539. + * the current transfer (not counting PINGs).
  63540. + */
  63541. + uint8_t requests;
  63542. +
  63543. + /**
  63544. + * Queue Head for the transfer being processed by this channel.
  63545. + */
  63546. + struct dwc_otg_qh *qh;
  63547. +
  63548. + /** @} */
  63549. +
  63550. + /** Entry in list of host channels. */
  63551. + DWC_CIRCLEQ_ENTRY(dwc_hc) hc_list_entry;
  63552. +
  63553. + /** @name Descriptor DMA support */
  63554. + /** @{ */
  63555. +
  63556. + /** Number of Transfer Descriptors */
  63557. + uint16_t ntd;
  63558. +
  63559. + /** Descriptor List DMA address */
  63560. + dwc_dma_t desc_list_addr;
  63561. +
  63562. + /** Scheduling micro-frame bitmap. */
  63563. + uint8_t schinfo;
  63564. +
  63565. + /** @} */
  63566. +} dwc_hc_t;
  63567. +
  63568. +/**
  63569. + * The following parameters may be specified when starting the module. These
  63570. + * parameters define how the DWC_otg controller should be configured.
  63571. + */
  63572. +typedef struct dwc_otg_core_params {
  63573. + int32_t opt;
  63574. +
  63575. + /**
  63576. + * Specifies the OTG capabilities. The driver will automatically
  63577. + * detect the value for this parameter if none is specified.
  63578. + * 0 - HNP and SRP capable (default)
  63579. + * 1 - SRP Only capable
  63580. + * 2 - No HNP/SRP capable
  63581. + */
  63582. + int32_t otg_cap;
  63583. +
  63584. + /**
  63585. + * Specifies whether to use slave or DMA mode for accessing the data
  63586. + * FIFOs. The driver will automatically detect the value for this
  63587. + * parameter if none is specified.
  63588. + * 0 - Slave
  63589. + * 1 - DMA (default, if available)
  63590. + */
  63591. + int32_t dma_enable;
  63592. +
  63593. + /**
  63594. + * When DMA mode is enabled specifies whether to use address DMA or DMA
  63595. + * Descriptor mode for accessing the data FIFOs in device mode. The driver
  63596. + * will automatically detect the value for this if none is specified.
  63597. + * 0 - address DMA
  63598. + * 1 - DMA Descriptor(default, if available)
  63599. + */
  63600. + int32_t dma_desc_enable;
  63601. + /** The DMA Burst size (applicable only for External DMA
  63602. + * Mode). 1, 4, 8 16, 32, 64, 128, 256 (default 32)
  63603. + */
  63604. + int32_t dma_burst_size; /* Translate this to GAHBCFG values */
  63605. +
  63606. + /**
  63607. + * Specifies the maximum speed of operation in host and device mode.
  63608. + * The actual speed depends on the speed of the attached device and
  63609. + * the value of phy_type. The actual speed depends on the speed of the
  63610. + * attached device.
  63611. + * 0 - High Speed (default)
  63612. + * 1 - Full Speed
  63613. + */
  63614. + int32_t speed;
  63615. + /** Specifies whether low power mode is supported when attached
  63616. + * to a Full Speed or Low Speed device in host mode.
  63617. + * 0 - Don't support low power mode (default)
  63618. + * 1 - Support low power mode
  63619. + */
  63620. + int32_t host_support_fs_ls_low_power;
  63621. +
  63622. + /** Specifies the PHY clock rate in low power mode when connected to a
  63623. + * Low Speed device in host mode. This parameter is applicable only if
  63624. + * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
  63625. + * then defaults to 6 MHZ otherwise 48 MHZ.
  63626. + *
  63627. + * 0 - 48 MHz
  63628. + * 1 - 6 MHz
  63629. + */
  63630. + int32_t host_ls_low_power_phy_clk;
  63631. +
  63632. + /**
  63633. + * 0 - Use cC FIFO size parameters
  63634. + * 1 - Allow dynamic FIFO sizing (default)
  63635. + */
  63636. + int32_t enable_dynamic_fifo;
  63637. +
  63638. + /** Total number of 4-byte words in the data FIFO memory. This
  63639. + * memory includes the Rx FIFO, non-periodic Tx FIFO, and periodic
  63640. + * Tx FIFOs.
  63641. + * 32 to 32768 (default 8192)
  63642. + * Note: The total FIFO memory depth in the FPGA configuration is 8192.
  63643. + */
  63644. + int32_t data_fifo_size;
  63645. +
  63646. + /** Number of 4-byte words in the Rx FIFO in device mode when dynamic
  63647. + * FIFO sizing is enabled.
  63648. + * 16 to 32768 (default 1064)
  63649. + */
  63650. + int32_t dev_rx_fifo_size;
  63651. +
  63652. + /** Number of 4-byte words in the non-periodic Tx FIFO in device mode
  63653. + * when dynamic FIFO sizing is enabled.
  63654. + * 16 to 32768 (default 1024)
  63655. + */
  63656. + int32_t dev_nperio_tx_fifo_size;
  63657. +
  63658. + /** Number of 4-byte words in each of the periodic Tx FIFOs in device
  63659. + * mode when dynamic FIFO sizing is enabled.
  63660. + * 4 to 768 (default 256)
  63661. + */
  63662. + uint32_t dev_perio_tx_fifo_size[MAX_PERIO_FIFOS];
  63663. +
  63664. + /** Number of 4-byte words in the Rx FIFO in host mode when dynamic
  63665. + * FIFO sizing is enabled.
  63666. + * 16 to 32768 (default 1024)
  63667. + */
  63668. + int32_t host_rx_fifo_size;
  63669. +
  63670. + /** Number of 4-byte words in the non-periodic Tx FIFO in host mode
  63671. + * when Dynamic FIFO sizing is enabled in the core.
  63672. + * 16 to 32768 (default 1024)
  63673. + */
  63674. + int32_t host_nperio_tx_fifo_size;
  63675. +
  63676. + /** Number of 4-byte words in the host periodic Tx FIFO when dynamic
  63677. + * FIFO sizing is enabled.
  63678. + * 16 to 32768 (default 1024)
  63679. + */
  63680. + int32_t host_perio_tx_fifo_size;
  63681. +
  63682. + /** The maximum transfer size supported in bytes.
  63683. + * 2047 to 65,535 (default 65,535)
  63684. + */
  63685. + int32_t max_transfer_size;
  63686. +
  63687. + /** The maximum number of packets in a transfer.
  63688. + * 15 to 511 (default 511)
  63689. + */
  63690. + int32_t max_packet_count;
  63691. +
  63692. + /** The number of host channel registers to use.
  63693. + * 1 to 16 (default 12)
  63694. + * Note: The FPGA configuration supports a maximum of 12 host channels.
  63695. + */
  63696. + int32_t host_channels;
  63697. +
  63698. + /** The number of endpoints in addition to EP0 available for device
  63699. + * mode operations.
  63700. + * 1 to 15 (default 6 IN and OUT)
  63701. + * Note: The FPGA configuration supports a maximum of 6 IN and OUT
  63702. + * endpoints in addition to EP0.
  63703. + */
  63704. + int32_t dev_endpoints;
  63705. +
  63706. + /**
  63707. + * Specifies the type of PHY interface to use. By default, the driver
  63708. + * will automatically detect the phy_type.
  63709. + *
  63710. + * 0 - Full Speed PHY
  63711. + * 1 - UTMI+ (default)
  63712. + * 2 - ULPI
  63713. + */
  63714. + int32_t phy_type;
  63715. +
  63716. + /**
  63717. + * Specifies the UTMI+ Data Width. This parameter is
  63718. + * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
  63719. + * PHY_TYPE, this parameter indicates the data width between
  63720. + * the MAC and the ULPI Wrapper.) Also, this parameter is
  63721. + * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
  63722. + * to "8 and 16 bits", meaning that the core has been
  63723. + * configured to work at either data path width.
  63724. + *
  63725. + * 8 or 16 bits (default 16)
  63726. + */
  63727. + int32_t phy_utmi_width;
  63728. +
  63729. + /**
  63730. + * Specifies whether the ULPI operates at double or single
  63731. + * data rate. This parameter is only applicable if PHY_TYPE is
  63732. + * ULPI.
  63733. + *
  63734. + * 0 - single data rate ULPI interface with 8 bit wide data
  63735. + * bus (default)
  63736. + * 1 - double data rate ULPI interface with 4 bit wide data
  63737. + * bus
  63738. + */
  63739. + int32_t phy_ulpi_ddr;
  63740. +
  63741. + /**
  63742. + * Specifies whether to use the internal or external supply to
  63743. + * drive the vbus with a ULPI phy.
  63744. + */
  63745. + int32_t phy_ulpi_ext_vbus;
  63746. +
  63747. + /**
  63748. + * Specifies whether to use the I2Cinterface for full speed PHY. This
  63749. + * parameter is only applicable if PHY_TYPE is FS.
  63750. + * 0 - No (default)
  63751. + * 1 - Yes
  63752. + */
  63753. + int32_t i2c_enable;
  63754. +
  63755. + int32_t ulpi_fs_ls;
  63756. +
  63757. + int32_t ts_dline;
  63758. +
  63759. + /**
  63760. + * Specifies whether dedicated transmit FIFOs are
  63761. + * enabled for non periodic IN endpoints in device mode
  63762. + * 0 - No
  63763. + * 1 - Yes
  63764. + */
  63765. + int32_t en_multiple_tx_fifo;
  63766. +
  63767. + /** Number of 4-byte words in each of the Tx FIFOs in device
  63768. + * mode when dynamic FIFO sizing is enabled.
  63769. + * 4 to 768 (default 256)
  63770. + */
  63771. + uint32_t dev_tx_fifo_size[MAX_TX_FIFOS];
  63772. +
  63773. + /** Thresholding enable flag-
  63774. + * bit 0 - enable non-ISO Tx thresholding
  63775. + * bit 1 - enable ISO Tx thresholding
  63776. + * bit 2 - enable Rx thresholding
  63777. + */
  63778. + uint32_t thr_ctl;
  63779. +
  63780. + /** Thresholding length for Tx
  63781. + * FIFOs in 32 bit DWORDs
  63782. + */
  63783. + uint32_t tx_thr_length;
  63784. +
  63785. + /** Thresholding length for Rx
  63786. + * FIFOs in 32 bit DWORDs
  63787. + */
  63788. + uint32_t rx_thr_length;
  63789. +
  63790. + /**
  63791. + * Specifies whether LPM (Link Power Management) support is enabled
  63792. + */
  63793. + int32_t lpm_enable;
  63794. +
  63795. + /** Per Transfer Interrupt
  63796. + * mode enable flag
  63797. + * 1 - Enabled
  63798. + * 0 - Disabled
  63799. + */
  63800. + int32_t pti_enable;
  63801. +
  63802. + /** Multi Processor Interrupt
  63803. + * mode enable flag
  63804. + * 1 - Enabled
  63805. + * 0 - Disabled
  63806. + */
  63807. + int32_t mpi_enable;
  63808. +
  63809. + /** IS_USB Capability
  63810. + * 1 - Enabled
  63811. + * 0 - Disabled
  63812. + */
  63813. + int32_t ic_usb_cap;
  63814. +
  63815. + /** AHB Threshold Ratio
  63816. + * 2'b00 AHB Threshold = MAC Threshold
  63817. + * 2'b01 AHB Threshold = 1/2 MAC Threshold
  63818. + * 2'b10 AHB Threshold = 1/4 MAC Threshold
  63819. + * 2'b11 AHB Threshold = 1/8 MAC Threshold
  63820. + */
  63821. + int32_t ahb_thr_ratio;
  63822. +
  63823. + /** ADP Support
  63824. + * 1 - Enabled
  63825. + * 0 - Disabled
  63826. + */
  63827. + int32_t adp_supp_enable;
  63828. +
  63829. + /** HFIR Reload Control
  63830. + * 0 - The HFIR cannot be reloaded dynamically.
  63831. + * 1 - Allow dynamic reloading of the HFIR register during runtime.
  63832. + */
  63833. + int32_t reload_ctl;
  63834. +
  63835. + /** DCFG: Enable device Out NAK
  63836. + * 0 - The core does not set NAK after Bulk Out transfer complete.
  63837. + * 1 - The core sets NAK after Bulk OUT transfer complete.
  63838. + */
  63839. + int32_t dev_out_nak;
  63840. +
  63841. + /** DCFG: Enable Continue on BNA
  63842. + * After receiving BNA interrupt the core disables the endpoint,when the
  63843. + * endpoint is re-enabled by the application the core starts processing
  63844. + * 0 - from the DOEPDMA descriptor
  63845. + * 1 - from the descriptor which received the BNA.
  63846. + */
  63847. + int32_t cont_on_bna;
  63848. +
  63849. + /** GAHBCFG: AHB Single Support
  63850. + * This bit when programmed supports SINGLE transfers for remainder
  63851. + * data in a transfer for DMA mode of operation.
  63852. + * 0 - in this case the remainder data will be sent using INCR burst size.
  63853. + * 1 - in this case the remainder data will be sent using SINGLE burst size.
  63854. + */
  63855. + int32_t ahb_single;
  63856. +
  63857. + /** Core Power down mode
  63858. + * 0 - No Power Down is enabled
  63859. + * 1 - Reserved
  63860. + * 2 - Complete Power Down (Hibernation)
  63861. + */
  63862. + int32_t power_down;
  63863. +
  63864. + /** OTG revision supported
  63865. + * 0 - OTG 1.3 revision
  63866. + * 1 - OTG 2.0 revision
  63867. + */
  63868. + int32_t otg_ver;
  63869. +
  63870. +} dwc_otg_core_params_t;
  63871. +
  63872. +#ifdef DEBUG
  63873. +struct dwc_otg_core_if;
  63874. +typedef struct hc_xfer_info {
  63875. + struct dwc_otg_core_if *core_if;
  63876. + dwc_hc_t *hc;
  63877. +} hc_xfer_info_t;
  63878. +#endif
  63879. +
  63880. +typedef struct ep_xfer_info {
  63881. + struct dwc_otg_core_if *core_if;
  63882. + dwc_ep_t *ep;
  63883. + uint8_t state;
  63884. +} ep_xfer_info_t;
  63885. +/*
  63886. + * Device States
  63887. + */
  63888. +typedef enum dwc_otg_lx_state {
  63889. + /** On state */
  63890. + DWC_OTG_L0,
  63891. + /** LPM sleep state*/
  63892. + DWC_OTG_L1,
  63893. + /** USB suspend state*/
  63894. + DWC_OTG_L2,
  63895. + /** Off state*/
  63896. + DWC_OTG_L3
  63897. +} dwc_otg_lx_state_e;
  63898. +
  63899. +struct dwc_otg_global_regs_backup {
  63900. + uint32_t gotgctl_local;
  63901. + uint32_t gintmsk_local;
  63902. + uint32_t gahbcfg_local;
  63903. + uint32_t gusbcfg_local;
  63904. + uint32_t grxfsiz_local;
  63905. + uint32_t gnptxfsiz_local;
  63906. +#ifdef CONFIG_USB_DWC_OTG_LPM
  63907. + uint32_t glpmcfg_local;
  63908. +#endif
  63909. + uint32_t gi2cctl_local;
  63910. + uint32_t hptxfsiz_local;
  63911. + uint32_t pcgcctl_local;
  63912. + uint32_t gdfifocfg_local;
  63913. + uint32_t dtxfsiz_local[MAX_EPS_CHANNELS];
  63914. + uint32_t gpwrdn_local;
  63915. + uint32_t xhib_pcgcctl;
  63916. + uint32_t xhib_gpwrdn;
  63917. +};
  63918. +
  63919. +struct dwc_otg_host_regs_backup {
  63920. + uint32_t hcfg_local;
  63921. + uint32_t haintmsk_local;
  63922. + uint32_t hcintmsk_local[MAX_EPS_CHANNELS];
  63923. + uint32_t hprt0_local;
  63924. + uint32_t hfir_local;
  63925. +};
  63926. +
  63927. +struct dwc_otg_dev_regs_backup {
  63928. + uint32_t dcfg;
  63929. + uint32_t dctl;
  63930. + uint32_t daintmsk;
  63931. + uint32_t diepmsk;
  63932. + uint32_t doepmsk;
  63933. + uint32_t diepctl[MAX_EPS_CHANNELS];
  63934. + uint32_t dieptsiz[MAX_EPS_CHANNELS];
  63935. + uint32_t diepdma[MAX_EPS_CHANNELS];
  63936. +};
  63937. +/**
  63938. + * The <code>dwc_otg_core_if</code> structure contains information needed to manage
  63939. + * the DWC_otg controller acting in either host or device mode. It
  63940. + * represents the programming view of the controller as a whole.
  63941. + */
  63942. +struct dwc_otg_core_if {
  63943. + /** Parameters that define how the core should be configured.*/
  63944. + dwc_otg_core_params_t *core_params;
  63945. +
  63946. + /** Core Global registers starting at offset 000h. */
  63947. + dwc_otg_core_global_regs_t *core_global_regs;
  63948. +
  63949. + /** Device-specific information */
  63950. + dwc_otg_dev_if_t *dev_if;
  63951. + /** Host-specific information */
  63952. + dwc_otg_host_if_t *host_if;
  63953. +
  63954. + /** Value from SNPSID register */
  63955. + uint32_t snpsid;
  63956. +
  63957. + /*
  63958. + * Set to 1 if the core PHY interface bits in USBCFG have been
  63959. + * initialized.
  63960. + */
  63961. + uint8_t phy_init_done;
  63962. +
  63963. + /*
  63964. + * SRP Success flag, set by srp success interrupt in FS I2C mode
  63965. + */
  63966. + uint8_t srp_success;
  63967. + uint8_t srp_timer_started;
  63968. + /** Timer for SRP. If it expires before SRP is successful
  63969. + * clear the SRP. */
  63970. + dwc_timer_t *srp_timer;
  63971. +
  63972. +#ifdef DWC_DEV_SRPCAP
  63973. + /* This timer is needed to power on the hibernated host core if SRP is not
  63974. + * initiated on connected SRP capable device for limited period of time
  63975. + */
  63976. + uint8_t pwron_timer_started;
  63977. + dwc_timer_t *pwron_timer;
  63978. +#endif
  63979. + /* Common configuration information */
  63980. + /** Power and Clock Gating Control Register */
  63981. + volatile uint32_t *pcgcctl;
  63982. +#define DWC_OTG_PCGCCTL_OFFSET 0xE00
  63983. +
  63984. + /** Push/pop addresses for endpoints or host channels.*/
  63985. + uint32_t *data_fifo[MAX_EPS_CHANNELS];
  63986. +#define DWC_OTG_DATA_FIFO_OFFSET 0x1000
  63987. +#define DWC_OTG_DATA_FIFO_SIZE 0x1000
  63988. +
  63989. + /** Total RAM for FIFOs (Bytes) */
  63990. + uint16_t total_fifo_size;
  63991. + /** Size of Rx FIFO (Bytes) */
  63992. + uint16_t rx_fifo_size;
  63993. + /** Size of Non-periodic Tx FIFO (Bytes) */
  63994. + uint16_t nperio_tx_fifo_size;
  63995. +
  63996. + /** 1 if DMA is enabled, 0 otherwise. */
  63997. + uint8_t dma_enable;
  63998. +
  63999. + /** 1 if DMA descriptor is enabled, 0 otherwise. */
  64000. + uint8_t dma_desc_enable;
  64001. +
  64002. + /** 1 if PTI Enhancement mode is enabled, 0 otherwise. */
  64003. + uint8_t pti_enh_enable;
  64004. +
  64005. + /** 1 if MPI Enhancement mode is enabled, 0 otherwise. */
  64006. + uint8_t multiproc_int_enable;
  64007. +
  64008. + /** 1 if dedicated Tx FIFOs are enabled, 0 otherwise. */
  64009. + uint8_t en_multiple_tx_fifo;
  64010. +
  64011. + /** Set to 1 if multiple packets of a high-bandwidth transfer is in
  64012. + * process of being queued */
  64013. + uint8_t queuing_high_bandwidth;
  64014. +
  64015. + /** Hardware Configuration -- stored here for convenience.*/
  64016. + hwcfg1_data_t hwcfg1;
  64017. + hwcfg2_data_t hwcfg2;
  64018. + hwcfg3_data_t hwcfg3;
  64019. + hwcfg4_data_t hwcfg4;
  64020. + fifosize_data_t hptxfsiz;
  64021. +
  64022. + /** Host and Device Configuration -- stored here for convenience.*/
  64023. + hcfg_data_t hcfg;
  64024. + dcfg_data_t dcfg;
  64025. +
  64026. + /** The operational State, during transations
  64027. + * (a_host>>a_peripherial and b_device=>b_host) this may not
  64028. + * match the core but allows the software to determine
  64029. + * transitions.
  64030. + */
  64031. + uint8_t op_state;
  64032. +
  64033. + /**
  64034. + * Set to 1 if the HCD needs to be restarted on a session request
  64035. + * interrupt. This is required if no connector ID status change has
  64036. + * occurred since the HCD was last disconnected.
  64037. + */
  64038. + uint8_t restart_hcd_on_session_req;
  64039. +
  64040. + /** HCD callbacks */
  64041. + /** A-Device is a_host */
  64042. +#define A_HOST (1)
  64043. + /** A-Device is a_suspend */
  64044. +#define A_SUSPEND (2)
  64045. + /** A-Device is a_peripherial */
  64046. +#define A_PERIPHERAL (3)
  64047. + /** B-Device is operating as a Peripheral. */
  64048. +#define B_PERIPHERAL (4)
  64049. + /** B-Device is operating as a Host. */
  64050. +#define B_HOST (5)
  64051. +
  64052. + /** HCD callbacks */
  64053. + struct dwc_otg_cil_callbacks *hcd_cb;
  64054. + /** PCD callbacks */
  64055. + struct dwc_otg_cil_callbacks *pcd_cb;
  64056. +
  64057. + /** Device mode Periodic Tx FIFO Mask */
  64058. + uint32_t p_tx_msk;
  64059. + /** Device mode Periodic Tx FIFO Mask */
  64060. + uint32_t tx_msk;
  64061. +
  64062. + /** Workqueue object used for handling several interrupts */
  64063. + dwc_workq_t *wq_otg;
  64064. +
  64065. + /** Timer object used for handling "Wakeup Detected" Interrupt */
  64066. + dwc_timer_t *wkp_timer;
  64067. + /** This arrays used for debug purposes for DEV OUT NAK enhancement */
  64068. + uint32_t start_doeptsiz_val[MAX_EPS_CHANNELS];
  64069. + ep_xfer_info_t ep_xfer_info[MAX_EPS_CHANNELS];
  64070. + dwc_timer_t *ep_xfer_timer[MAX_EPS_CHANNELS];
  64071. +#ifdef DEBUG
  64072. + uint32_t start_hcchar_val[MAX_EPS_CHANNELS];
  64073. +
  64074. + hc_xfer_info_t hc_xfer_info[MAX_EPS_CHANNELS];
  64075. + dwc_timer_t *hc_xfer_timer[MAX_EPS_CHANNELS];
  64076. +
  64077. + uint32_t hfnum_7_samples;
  64078. + uint64_t hfnum_7_frrem_accum;
  64079. + uint32_t hfnum_0_samples;
  64080. + uint64_t hfnum_0_frrem_accum;
  64081. + uint32_t hfnum_other_samples;
  64082. + uint64_t hfnum_other_frrem_accum;
  64083. +#endif
  64084. +
  64085. +#ifdef DWC_UTE_CFI
  64086. + uint16_t pwron_rxfsiz;
  64087. + uint16_t pwron_gnptxfsiz;
  64088. + uint16_t pwron_txfsiz[15];
  64089. +
  64090. + uint16_t init_rxfsiz;
  64091. + uint16_t init_gnptxfsiz;
  64092. + uint16_t init_txfsiz[15];
  64093. +#endif
  64094. +
  64095. + /** Lx state of device */
  64096. + dwc_otg_lx_state_e lx_state;
  64097. +
  64098. + /** Saved Core Global registers */
  64099. + struct dwc_otg_global_regs_backup *gr_backup;
  64100. + /** Saved Host registers */
  64101. + struct dwc_otg_host_regs_backup *hr_backup;
  64102. + /** Saved Device registers */
  64103. + struct dwc_otg_dev_regs_backup *dr_backup;
  64104. +
  64105. + /** Power Down Enable */
  64106. + uint32_t power_down;
  64107. +
  64108. + /** ADP support Enable */
  64109. + uint32_t adp_enable;
  64110. +
  64111. + /** ADP structure object */
  64112. + dwc_otg_adp_t adp;
  64113. +
  64114. + /** hibernation/suspend flag */
  64115. + int hibernation_suspend;
  64116. +
  64117. + /** Device mode extended hibernation flag */
  64118. + int xhib;
  64119. +
  64120. + /** OTG revision supported */
  64121. + uint32_t otg_ver;
  64122. +
  64123. + /** OTG status flag used for HNP polling */
  64124. + uint8_t otg_sts;
  64125. +
  64126. + /** Pointer to either hcd->lock or pcd->lock */
  64127. + dwc_spinlock_t *lock;
  64128. +
  64129. + /** Start predict NextEP based on Learning Queue if equal 1,
  64130. + * also used as counter of disabled NP IN EP's */
  64131. + uint8_t start_predict;
  64132. +
  64133. + /** NextEp sequence, including EP0: nextep_seq[] = EP if non-periodic and
  64134. + * active, 0xff otherwise */
  64135. + uint8_t nextep_seq[MAX_EPS_CHANNELS];
  64136. +
  64137. + /** Index of fisrt EP in nextep_seq array which should be re-enabled **/
  64138. + uint8_t first_in_nextep_seq;
  64139. +
  64140. + /** Frame number while entering to ISR - needed for ISOCs **/
  64141. + uint32_t frame_num;
  64142. +
  64143. +};
  64144. +
  64145. +#ifdef DEBUG
  64146. +/*
  64147. + * This function is called when transfer is timed out.
  64148. + */
  64149. +extern void hc_xfer_timeout(void *ptr);
  64150. +#endif
  64151. +
  64152. +/*
  64153. + * This function is called when transfer is timed out on endpoint.
  64154. + */
  64155. +extern void ep_xfer_timeout(void *ptr);
  64156. +
  64157. +/*
  64158. + * The following functions are functions for works
  64159. + * using during handling some interrupts
  64160. + */
  64161. +extern void w_conn_id_status_change(void *p);
  64162. +
  64163. +extern void w_wakeup_detected(void *p);
  64164. +
  64165. +/** Saves global register values into system memory. */
  64166. +extern int dwc_otg_save_global_regs(dwc_otg_core_if_t * core_if);
  64167. +/** Saves device register values into system memory. */
  64168. +extern int dwc_otg_save_dev_regs(dwc_otg_core_if_t * core_if);
  64169. +/** Saves host register values into system memory. */
  64170. +extern int dwc_otg_save_host_regs(dwc_otg_core_if_t * core_if);
  64171. +/** Restore global register values. */
  64172. +extern int dwc_otg_restore_global_regs(dwc_otg_core_if_t * core_if);
  64173. +/** Restore host register values. */
  64174. +extern int dwc_otg_restore_host_regs(dwc_otg_core_if_t * core_if, int reset);
  64175. +/** Restore device register values. */
  64176. +extern int dwc_otg_restore_dev_regs(dwc_otg_core_if_t * core_if,
  64177. + int rem_wakeup);
  64178. +extern int restore_lpm_i2c_regs(dwc_otg_core_if_t * core_if);
  64179. +extern int restore_essential_regs(dwc_otg_core_if_t * core_if, int rmode,
  64180. + int is_host);
  64181. +
  64182. +extern int dwc_otg_host_hibernation_restore(dwc_otg_core_if_t * core_if,
  64183. + int restore_mode, int reset);
  64184. +extern int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
  64185. + int rem_wakeup, int reset);
  64186. +
  64187. +/*
  64188. + * The following functions support initialization of the CIL driver component
  64189. + * and the DWC_otg controller.
  64190. + */
  64191. +extern void dwc_otg_core_host_init(dwc_otg_core_if_t * _core_if);
  64192. +extern void dwc_otg_core_dev_init(dwc_otg_core_if_t * _core_if);
  64193. +
  64194. +/** @name Device CIL Functions
  64195. + * The following functions support managing the DWC_otg controller in device
  64196. + * mode.
  64197. + */
  64198. +/**@{*/
  64199. +extern void dwc_otg_wakeup(dwc_otg_core_if_t * _core_if);
  64200. +extern void dwc_otg_read_setup_packet(dwc_otg_core_if_t * _core_if,
  64201. + uint32_t * _dest);
  64202. +extern uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t * _core_if);
  64203. +extern void dwc_otg_ep0_activate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  64204. +extern void dwc_otg_ep_activate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  64205. +extern void dwc_otg_ep_deactivate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  64206. +extern void dwc_otg_ep_start_transfer(dwc_otg_core_if_t * _core_if,
  64207. + dwc_ep_t * _ep);
  64208. +extern void dwc_otg_ep_start_zl_transfer(dwc_otg_core_if_t * _core_if,
  64209. + dwc_ep_t * _ep);
  64210. +extern void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t * _core_if,
  64211. + dwc_ep_t * _ep);
  64212. +extern void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t * _core_if,
  64213. + dwc_ep_t * _ep);
  64214. +extern void dwc_otg_ep_write_packet(dwc_otg_core_if_t * _core_if,
  64215. + dwc_ep_t * _ep, int _dma);
  64216. +extern void dwc_otg_ep_set_stall(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  64217. +extern void dwc_otg_ep_clear_stall(dwc_otg_core_if_t * _core_if,
  64218. + dwc_ep_t * _ep);
  64219. +extern void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t * _core_if);
  64220. +
  64221. +#ifdef DWC_EN_ISOC
  64222. +extern void dwc_otg_iso_ep_start_frm_transfer(dwc_otg_core_if_t * core_if,
  64223. + dwc_ep_t * ep);
  64224. +extern void dwc_otg_iso_ep_start_buf_transfer(dwc_otg_core_if_t * core_if,
  64225. + dwc_ep_t * ep);
  64226. +#endif /* DWC_EN_ISOC */
  64227. +/**@}*/
  64228. +
  64229. +/** @name Host CIL Functions
  64230. + * The following functions support managing the DWC_otg controller in host
  64231. + * mode.
  64232. + */
  64233. +/**@{*/
  64234. +extern void dwc_otg_hc_init(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
  64235. +extern void dwc_otg_hc_halt(dwc_otg_core_if_t * _core_if,
  64236. + dwc_hc_t * _hc, dwc_otg_halt_status_e _halt_status);
  64237. +extern void dwc_otg_hc_cleanup(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
  64238. +extern void dwc_otg_hc_start_transfer(dwc_otg_core_if_t * _core_if,
  64239. + dwc_hc_t * _hc);
  64240. +extern int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t * _core_if,
  64241. + dwc_hc_t * _hc);
  64242. +extern void dwc_otg_hc_do_ping(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
  64243. +extern void dwc_otg_hc_write_packet(dwc_otg_core_if_t * _core_if,
  64244. + dwc_hc_t * _hc);
  64245. +extern void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t * _core_if);
  64246. +extern void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t * _core_if);
  64247. +
  64248. +extern void dwc_otg_hc_start_transfer_ddma(dwc_otg_core_if_t * core_if,
  64249. + dwc_hc_t * hc);
  64250. +
  64251. +extern uint32_t calc_frame_interval(dwc_otg_core_if_t * core_if);
  64252. +
  64253. +/* Macro used to clear one channel interrupt */
  64254. +#define clear_hc_int(_hc_regs_, _intr_) \
  64255. +do { \
  64256. + hcint_data_t hcint_clear = {.d32 = 0}; \
  64257. + hcint_clear.b._intr_ = 1; \
  64258. + DWC_WRITE_REG32(&(_hc_regs_)->hcint, hcint_clear.d32); \
  64259. +} while (0)
  64260. +
  64261. +/*
  64262. + * Macro used to disable one channel interrupt. Channel interrupts are
  64263. + * disabled when the channel is halted or released by the interrupt handler.
  64264. + * There is no need to handle further interrupts of that type until the
  64265. + * channel is re-assigned. In fact, subsequent handling may cause crashes
  64266. + * because the channel structures are cleaned up when the channel is released.
  64267. + */
  64268. +#define disable_hc_int(_hc_regs_, _intr_) \
  64269. +do { \
  64270. + hcintmsk_data_t hcintmsk = {.d32 = 0}; \
  64271. + hcintmsk.b._intr_ = 1; \
  64272. + DWC_MODIFY_REG32(&(_hc_regs_)->hcintmsk, hcintmsk.d32, 0); \
  64273. +} while (0)
  64274. +
  64275. +/**
  64276. + * This function Reads HPRT0 in preparation to modify. It keeps the
  64277. + * WC bits 0 so that if they are read as 1, they won't clear when you
  64278. + * write it back
  64279. + */
  64280. +static inline uint32_t dwc_otg_read_hprt0(dwc_otg_core_if_t * _core_if)
  64281. +{
  64282. + hprt0_data_t hprt0;
  64283. + hprt0.d32 = DWC_READ_REG32(_core_if->host_if->hprt0);
  64284. + hprt0.b.prtena = 0;
  64285. + hprt0.b.prtconndet = 0;
  64286. + hprt0.b.prtenchng = 0;
  64287. + hprt0.b.prtovrcurrchng = 0;
  64288. + return hprt0.d32;
  64289. +}
  64290. +
  64291. +/**@}*/
  64292. +
  64293. +/** @name Common CIL Functions
  64294. + * The following functions support managing the DWC_otg controller in either
  64295. + * device or host mode.
  64296. + */
  64297. +/**@{*/
  64298. +
  64299. +extern void dwc_otg_read_packet(dwc_otg_core_if_t * core_if,
  64300. + uint8_t * dest, uint16_t bytes);
  64301. +
  64302. +extern void dwc_otg_flush_tx_fifo(dwc_otg_core_if_t * _core_if, const int _num);
  64303. +extern void dwc_otg_flush_rx_fifo(dwc_otg_core_if_t * _core_if);
  64304. +extern void dwc_otg_core_reset(dwc_otg_core_if_t * _core_if);
  64305. +
  64306. +/**
  64307. + * This function returns the Core Interrupt register.
  64308. + */
  64309. +static inline uint32_t dwc_otg_read_core_intr(dwc_otg_core_if_t * core_if)
  64310. +{
  64311. + return (DWC_READ_REG32(&core_if->core_global_regs->gintsts) &
  64312. + DWC_READ_REG32(&core_if->core_global_regs->gintmsk));
  64313. +}
  64314. +
  64315. +/**
  64316. + * This function returns the OTG Interrupt register.
  64317. + */
  64318. +static inline uint32_t dwc_otg_read_otg_intr(dwc_otg_core_if_t * core_if)
  64319. +{
  64320. + return (DWC_READ_REG32(&core_if->core_global_regs->gotgint));
  64321. +}
  64322. +
  64323. +/**
  64324. + * This function reads the Device All Endpoints Interrupt register and
  64325. + * returns the IN endpoint interrupt bits.
  64326. + */
  64327. +static inline uint32_t dwc_otg_read_dev_all_in_ep_intr(dwc_otg_core_if_t *
  64328. + core_if)
  64329. +{
  64330. +
  64331. + uint32_t v;
  64332. +
  64333. + if (core_if->multiproc_int_enable) {
  64334. + v = DWC_READ_REG32(&core_if->dev_if->
  64335. + dev_global_regs->deachint) &
  64336. + DWC_READ_REG32(&core_if->
  64337. + dev_if->dev_global_regs->deachintmsk);
  64338. + } else {
  64339. + v = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daint) &
  64340. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
  64341. + }
  64342. + return (v & 0xffff);
  64343. +}
  64344. +
  64345. +/**
  64346. + * This function reads the Device All Endpoints Interrupt register and
  64347. + * returns the OUT endpoint interrupt bits.
  64348. + */
  64349. +static inline uint32_t dwc_otg_read_dev_all_out_ep_intr(dwc_otg_core_if_t *
  64350. + core_if)
  64351. +{
  64352. + uint32_t v;
  64353. +
  64354. + if (core_if->multiproc_int_enable) {
  64355. + v = DWC_READ_REG32(&core_if->dev_if->
  64356. + dev_global_regs->deachint) &
  64357. + DWC_READ_REG32(&core_if->
  64358. + dev_if->dev_global_regs->deachintmsk);
  64359. + } else {
  64360. + v = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daint) &
  64361. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
  64362. + }
  64363. +
  64364. + return ((v & 0xffff0000) >> 16);
  64365. +}
  64366. +
  64367. +/**
  64368. + * This function returns the Device IN EP Interrupt register
  64369. + */
  64370. +static inline uint32_t dwc_otg_read_dev_in_ep_intr(dwc_otg_core_if_t * core_if,
  64371. + dwc_ep_t * ep)
  64372. +{
  64373. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  64374. + uint32_t v, msk, emp;
  64375. +
  64376. + if (core_if->multiproc_int_enable) {
  64377. + msk =
  64378. + DWC_READ_REG32(&dev_if->
  64379. + dev_global_regs->diepeachintmsk[ep->num]);
  64380. + emp =
  64381. + DWC_READ_REG32(&dev_if->
  64382. + dev_global_regs->dtknqr4_fifoemptymsk);
  64383. + msk |= ((emp >> ep->num) & 0x1) << 7;
  64384. + v = DWC_READ_REG32(&dev_if->in_ep_regs[ep->num]->diepint) & msk;
  64385. + } else {
  64386. + msk = DWC_READ_REG32(&dev_if->dev_global_regs->diepmsk);
  64387. + emp =
  64388. + DWC_READ_REG32(&dev_if->
  64389. + dev_global_regs->dtknqr4_fifoemptymsk);
  64390. + msk |= ((emp >> ep->num) & 0x1) << 7;
  64391. + v = DWC_READ_REG32(&dev_if->in_ep_regs[ep->num]->diepint) & msk;
  64392. + }
  64393. +
  64394. + return v;
  64395. +}
  64396. +
  64397. +/**
  64398. + * This function returns the Device OUT EP Interrupt register
  64399. + */
  64400. +static inline uint32_t dwc_otg_read_dev_out_ep_intr(dwc_otg_core_if_t *
  64401. + _core_if, dwc_ep_t * _ep)
  64402. +{
  64403. + dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
  64404. + uint32_t v;
  64405. + doepmsk_data_t msk = {.d32 = 0 };
  64406. +
  64407. + if (_core_if->multiproc_int_enable) {
  64408. + msk.d32 =
  64409. + DWC_READ_REG32(&dev_if->
  64410. + dev_global_regs->doepeachintmsk[_ep->num]);
  64411. + if (_core_if->pti_enh_enable) {
  64412. + msk.b.pktdrpsts = 1;
  64413. + }
  64414. + v = DWC_READ_REG32(&dev_if->
  64415. + out_ep_regs[_ep->num]->doepint) & msk.d32;
  64416. + } else {
  64417. + msk.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->doepmsk);
  64418. + if (_core_if->pti_enh_enable) {
  64419. + msk.b.pktdrpsts = 1;
  64420. + }
  64421. + v = DWC_READ_REG32(&dev_if->
  64422. + out_ep_regs[_ep->num]->doepint) & msk.d32;
  64423. + }
  64424. + return v;
  64425. +}
  64426. +
  64427. +/**
  64428. + * This function returns the Host All Channel Interrupt register
  64429. + */
  64430. +static inline uint32_t dwc_otg_read_host_all_channels_intr(dwc_otg_core_if_t *
  64431. + _core_if)
  64432. +{
  64433. + return (DWC_READ_REG32(&_core_if->host_if->host_global_regs->haint));
  64434. +}
  64435. +
  64436. +static inline uint32_t dwc_otg_read_host_channel_intr(dwc_otg_core_if_t *
  64437. + _core_if, dwc_hc_t * _hc)
  64438. +{
  64439. + return (DWC_READ_REG32
  64440. + (&_core_if->host_if->hc_regs[_hc->hc_num]->hcint));
  64441. +}
  64442. +
  64443. +/**
  64444. + * This function returns the mode of the operation, host or device.
  64445. + *
  64446. + * @return 0 - Device Mode, 1 - Host Mode
  64447. + */
  64448. +static inline uint32_t dwc_otg_mode(dwc_otg_core_if_t * _core_if)
  64449. +{
  64450. + return (DWC_READ_REG32(&_core_if->core_global_regs->gintsts) & 0x1);
  64451. +}
  64452. +
  64453. +/**@}*/
  64454. +
  64455. +/**
  64456. + * DWC_otg CIL callback structure. This structure allows the HCD and
  64457. + * PCD to register functions used for starting and stopping the PCD
  64458. + * and HCD for role change on for a DRD.
  64459. + */
  64460. +typedef struct dwc_otg_cil_callbacks {
  64461. + /** Start function for role change */
  64462. + int (*start) (void *_p);
  64463. + /** Stop Function for role change */
  64464. + int (*stop) (void *_p);
  64465. + /** Disconnect Function for role change */
  64466. + int (*disconnect) (void *_p);
  64467. + /** Resume/Remote wakeup Function */
  64468. + int (*resume_wakeup) (void *_p);
  64469. + /** Suspend function */
  64470. + int (*suspend) (void *_p);
  64471. + /** Session Start (SRP) */
  64472. + int (*session_start) (void *_p);
  64473. +#ifdef CONFIG_USB_DWC_OTG_LPM
  64474. + /** Sleep (switch to L0 state) */
  64475. + int (*sleep) (void *_p);
  64476. +#endif
  64477. + /** Pointer passed to start() and stop() */
  64478. + void *p;
  64479. +} dwc_otg_cil_callbacks_t;
  64480. +
  64481. +extern void dwc_otg_cil_register_pcd_callbacks(dwc_otg_core_if_t * _core_if,
  64482. + dwc_otg_cil_callbacks_t * _cb,
  64483. + void *_p);
  64484. +extern void dwc_otg_cil_register_hcd_callbacks(dwc_otg_core_if_t * _core_if,
  64485. + dwc_otg_cil_callbacks_t * _cb,
  64486. + void *_p);
  64487. +
  64488. +void dwc_otg_initiate_srp(dwc_otg_core_if_t * core_if);
  64489. +
  64490. +//////////////////////////////////////////////////////////////////////
  64491. +/** Start the HCD. Helper function for using the HCD callbacks.
  64492. + *
  64493. + * @param core_if Programming view of DWC_otg controller.
  64494. + */
  64495. +static inline void cil_hcd_start(dwc_otg_core_if_t * core_if)
  64496. +{
  64497. + if (core_if->hcd_cb && core_if->hcd_cb->start) {
  64498. + core_if->hcd_cb->start(core_if->hcd_cb->p);
  64499. + }
  64500. +}
  64501. +
  64502. +/** Stop the HCD. Helper function for using the HCD callbacks.
  64503. + *
  64504. + * @param core_if Programming view of DWC_otg controller.
  64505. + */
  64506. +static inline void cil_hcd_stop(dwc_otg_core_if_t * core_if)
  64507. +{
  64508. + if (core_if->hcd_cb && core_if->hcd_cb->stop) {
  64509. + core_if->hcd_cb->stop(core_if->hcd_cb->p);
  64510. + }
  64511. +}
  64512. +
  64513. +/** Disconnect the HCD. Helper function for using the HCD callbacks.
  64514. + *
  64515. + * @param core_if Programming view of DWC_otg controller.
  64516. + */
  64517. +static inline void cil_hcd_disconnect(dwc_otg_core_if_t * core_if)
  64518. +{
  64519. + if (core_if->hcd_cb && core_if->hcd_cb->disconnect) {
  64520. + core_if->hcd_cb->disconnect(core_if->hcd_cb->p);
  64521. + }
  64522. +}
  64523. +
  64524. +/** Inform the HCD the a New Session has begun. Helper function for
  64525. + * using the HCD callbacks.
  64526. + *
  64527. + * @param core_if Programming view of DWC_otg controller.
  64528. + */
  64529. +static inline void cil_hcd_session_start(dwc_otg_core_if_t * core_if)
  64530. +{
  64531. + if (core_if->hcd_cb && core_if->hcd_cb->session_start) {
  64532. + core_if->hcd_cb->session_start(core_if->hcd_cb->p);
  64533. + }
  64534. +}
  64535. +
  64536. +#ifdef CONFIG_USB_DWC_OTG_LPM
  64537. +/**
  64538. + * Inform the HCD about LPM sleep.
  64539. + * Helper function for using the HCD callbacks.
  64540. + *
  64541. + * @param core_if Programming view of DWC_otg controller.
  64542. + */
  64543. +static inline void cil_hcd_sleep(dwc_otg_core_if_t * core_if)
  64544. +{
  64545. + if (core_if->hcd_cb && core_if->hcd_cb->sleep) {
  64546. + core_if->hcd_cb->sleep(core_if->hcd_cb->p);
  64547. + }
  64548. +}
  64549. +#endif
  64550. +
  64551. +/** Resume the HCD. Helper function for using the HCD callbacks.
  64552. + *
  64553. + * @param core_if Programming view of DWC_otg controller.
  64554. + */
  64555. +static inline void cil_hcd_resume(dwc_otg_core_if_t * core_if)
  64556. +{
  64557. + if (core_if->hcd_cb && core_if->hcd_cb->resume_wakeup) {
  64558. + core_if->hcd_cb->resume_wakeup(core_if->hcd_cb->p);
  64559. + }
  64560. +}
  64561. +
  64562. +/** Start the PCD. Helper function for using the PCD callbacks.
  64563. + *
  64564. + * @param core_if Programming view of DWC_otg controller.
  64565. + */
  64566. +static inline void cil_pcd_start(dwc_otg_core_if_t * core_if)
  64567. +{
  64568. + if (core_if->pcd_cb && core_if->pcd_cb->start) {
  64569. + core_if->pcd_cb->start(core_if->pcd_cb->p);
  64570. + }
  64571. +}
  64572. +
  64573. +/** Stop the PCD. Helper function for using the PCD callbacks.
  64574. + *
  64575. + * @param core_if Programming view of DWC_otg controller.
  64576. + */
  64577. +static inline void cil_pcd_stop(dwc_otg_core_if_t * core_if)
  64578. +{
  64579. + if (core_if->pcd_cb && core_if->pcd_cb->stop) {
  64580. + core_if->pcd_cb->stop(core_if->pcd_cb->p);
  64581. + }
  64582. +}
  64583. +
  64584. +/** Suspend the PCD. Helper function for using the PCD callbacks.
  64585. + *
  64586. + * @param core_if Programming view of DWC_otg controller.
  64587. + */
  64588. +static inline void cil_pcd_suspend(dwc_otg_core_if_t * core_if)
  64589. +{
  64590. + if (core_if->pcd_cb && core_if->pcd_cb->suspend) {
  64591. + core_if->pcd_cb->suspend(core_if->pcd_cb->p);
  64592. + }
  64593. +}
  64594. +
  64595. +/** Resume the PCD. Helper function for using the PCD callbacks.
  64596. + *
  64597. + * @param core_if Programming view of DWC_otg controller.
  64598. + */
  64599. +static inline void cil_pcd_resume(dwc_otg_core_if_t * core_if)
  64600. +{
  64601. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  64602. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  64603. + }
  64604. +}
  64605. +
  64606. +//////////////////////////////////////////////////////////////////////
  64607. +
  64608. +#endif
  64609. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c
  64610. --- linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c 1970-01-01 01:00:00.000000000 +0100
  64611. +++ linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c 2014-08-06 16:50:14.801964726 +0200
  64612. @@ -0,0 +1,1595 @@
  64613. +/* ==========================================================================
  64614. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil_intr.c $
  64615. + * $Revision: #32 $
  64616. + * $Date: 2012/08/10 $
  64617. + * $Change: 2047372 $
  64618. + *
  64619. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  64620. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  64621. + * otherwise expressly agreed to in writing between Synopsys and you.
  64622. + *
  64623. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  64624. + * any End User Software License Agreement or Agreement for Licensed Product
  64625. + * with Synopsys or any supplement thereto. You are permitted to use and
  64626. + * redistribute this Software in source and binary forms, with or without
  64627. + * modification, provided that redistributions of source code must retain this
  64628. + * notice. You may not view, use, disclose, copy or distribute this file or
  64629. + * any information contained herein except pursuant to this license grant from
  64630. + * Synopsys. If you do not agree with this notice, including the disclaimer
  64631. + * below, then you are not authorized to use the Software.
  64632. + *
  64633. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  64634. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  64635. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  64636. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  64637. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  64638. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  64639. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  64640. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  64641. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  64642. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  64643. + * DAMAGE.
  64644. + * ========================================================================== */
  64645. +
  64646. +/** @file
  64647. + *
  64648. + * The Core Interface Layer provides basic services for accessing and
  64649. + * managing the DWC_otg hardware. These services are used by both the
  64650. + * Host Controller Driver and the Peripheral Controller Driver.
  64651. + *
  64652. + * This file contains the Common Interrupt handlers.
  64653. + */
  64654. +#include "dwc_os.h"
  64655. +#include "dwc_otg_regs.h"
  64656. +#include "dwc_otg_cil.h"
  64657. +#include "dwc_otg_driver.h"
  64658. +#include "dwc_otg_pcd.h"
  64659. +#include "dwc_otg_hcd.h"
  64660. +
  64661. +#ifdef DEBUG
  64662. +inline const char *op_state_str(dwc_otg_core_if_t * core_if)
  64663. +{
  64664. + return (core_if->op_state == A_HOST ? "a_host" :
  64665. + (core_if->op_state == A_SUSPEND ? "a_suspend" :
  64666. + (core_if->op_state == A_PERIPHERAL ? "a_peripheral" :
  64667. + (core_if->op_state == B_PERIPHERAL ? "b_peripheral" :
  64668. + (core_if->op_state == B_HOST ? "b_host" : "unknown")))));
  64669. +}
  64670. +#endif
  64671. +
  64672. +/** This function will log a debug message
  64673. + *
  64674. + * @param core_if Programming view of DWC_otg controller.
  64675. + */
  64676. +int32_t dwc_otg_handle_mode_mismatch_intr(dwc_otg_core_if_t * core_if)
  64677. +{
  64678. + gintsts_data_t gintsts;
  64679. + DWC_WARN("Mode Mismatch Interrupt: currently in %s mode\n",
  64680. + dwc_otg_mode(core_if) ? "Host" : "Device");
  64681. +
  64682. + /* Clear interrupt */
  64683. + gintsts.d32 = 0;
  64684. + gintsts.b.modemismatch = 1;
  64685. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  64686. + return 1;
  64687. +}
  64688. +
  64689. +/**
  64690. + * This function handles the OTG Interrupts. It reads the OTG
  64691. + * Interrupt Register (GOTGINT) to determine what interrupt has
  64692. + * occurred.
  64693. + *
  64694. + * @param core_if Programming view of DWC_otg controller.
  64695. + */
  64696. +int32_t dwc_otg_handle_otg_intr(dwc_otg_core_if_t * core_if)
  64697. +{
  64698. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  64699. + gotgint_data_t gotgint;
  64700. + gotgctl_data_t gotgctl;
  64701. + gintmsk_data_t gintmsk;
  64702. + gpwrdn_data_t gpwrdn;
  64703. +
  64704. + gotgint.d32 = DWC_READ_REG32(&global_regs->gotgint);
  64705. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  64706. + DWC_DEBUGPL(DBG_CIL, "++OTG Interrupt gotgint=%0x [%s]\n", gotgint.d32,
  64707. + op_state_str(core_if));
  64708. +
  64709. + if (gotgint.b.sesenddet) {
  64710. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  64711. + "Session End Detected++ (%s)\n",
  64712. + op_state_str(core_if));
  64713. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  64714. +
  64715. + if (core_if->op_state == B_HOST) {
  64716. + cil_pcd_start(core_if);
  64717. + core_if->op_state = B_PERIPHERAL;
  64718. + } else {
  64719. + /* If not B_HOST and Device HNP still set. HNP
  64720. + * Did not succeed!*/
  64721. + if (gotgctl.b.devhnpen) {
  64722. + DWC_DEBUGPL(DBG_ANY, "Session End Detected\n");
  64723. + __DWC_ERROR("Device Not Connected/Responding!\n");
  64724. + }
  64725. +
  64726. + /* If Session End Detected the B-Cable has
  64727. + * been disconnected. */
  64728. + /* Reset PCD and Gadget driver to a
  64729. + * clean state. */
  64730. + core_if->lx_state = DWC_OTG_L0;
  64731. + DWC_SPINUNLOCK(core_if->lock);
  64732. + cil_pcd_stop(core_if);
  64733. + DWC_SPINLOCK(core_if->lock);
  64734. +
  64735. + if (core_if->adp_enable) {
  64736. + if (core_if->power_down == 2) {
  64737. + gpwrdn.d32 = 0;
  64738. + gpwrdn.b.pwrdnswtch = 1;
  64739. + DWC_MODIFY_REG32(&core_if->
  64740. + core_global_regs->
  64741. + gpwrdn, gpwrdn.d32, 0);
  64742. + }
  64743. +
  64744. + gpwrdn.d32 = 0;
  64745. + gpwrdn.b.pmuintsel = 1;
  64746. + gpwrdn.b.pmuactv = 1;
  64747. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  64748. + gpwrdn, 0, gpwrdn.d32);
  64749. +
  64750. + dwc_otg_adp_sense_start(core_if);
  64751. + }
  64752. + }
  64753. +
  64754. + gotgctl.d32 = 0;
  64755. + gotgctl.b.devhnpen = 1;
  64756. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  64757. + }
  64758. + if (gotgint.b.sesreqsucstschng) {
  64759. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  64760. + "Session Reqeust Success Status Change++\n");
  64761. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  64762. + if (gotgctl.b.sesreqscs) {
  64763. +
  64764. + if ((core_if->core_params->phy_type ==
  64765. + DWC_PHY_TYPE_PARAM_FS) && (core_if->core_params->i2c_enable)) {
  64766. + core_if->srp_success = 1;
  64767. + } else {
  64768. + DWC_SPINUNLOCK(core_if->lock);
  64769. + cil_pcd_resume(core_if);
  64770. + DWC_SPINLOCK(core_if->lock);
  64771. + /* Clear Session Request */
  64772. + gotgctl.d32 = 0;
  64773. + gotgctl.b.sesreq = 1;
  64774. + DWC_MODIFY_REG32(&global_regs->gotgctl,
  64775. + gotgctl.d32, 0);
  64776. + }
  64777. + }
  64778. + }
  64779. + if (gotgint.b.hstnegsucstschng) {
  64780. + /* Print statements during the HNP interrupt handling
  64781. + * can cause it to fail.*/
  64782. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  64783. + /* WA for 3.00a- HW is not setting cur_mode, even sometimes
  64784. + * this does not help*/
  64785. + if (core_if->snpsid >= OTG_CORE_REV_3_00a)
  64786. + dwc_udelay(100);
  64787. + if (gotgctl.b.hstnegscs) {
  64788. + if (dwc_otg_is_host_mode(core_if)) {
  64789. + core_if->op_state = B_HOST;
  64790. + /*
  64791. + * Need to disable SOF interrupt immediately.
  64792. + * When switching from device to host, the PCD
  64793. + * interrupt handler won't handle the
  64794. + * interrupt if host mode is already set. The
  64795. + * HCD interrupt handler won't get called if
  64796. + * the HCD state is HALT. This means that the
  64797. + * interrupt does not get handled and Linux
  64798. + * complains loudly.
  64799. + */
  64800. + gintmsk.d32 = 0;
  64801. + gintmsk.b.sofintr = 1;
  64802. + DWC_MODIFY_REG32(&global_regs->gintmsk,
  64803. + gintmsk.d32, 0);
  64804. + /* Call callback function with spin lock released */
  64805. + DWC_SPINUNLOCK(core_if->lock);
  64806. + cil_pcd_stop(core_if);
  64807. + /*
  64808. + * Initialize the Core for Host mode.
  64809. + */
  64810. + cil_hcd_start(core_if);
  64811. + DWC_SPINLOCK(core_if->lock);
  64812. + core_if->op_state = B_HOST;
  64813. + }
  64814. + } else {
  64815. + gotgctl.d32 = 0;
  64816. + gotgctl.b.hnpreq = 1;
  64817. + gotgctl.b.devhnpen = 1;
  64818. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  64819. + DWC_DEBUGPL(DBG_ANY, "HNP Failed\n");
  64820. + __DWC_ERROR("Device Not Connected/Responding\n");
  64821. + }
  64822. + }
  64823. + if (gotgint.b.hstnegdet) {
  64824. + /* The disconnect interrupt is set at the same time as
  64825. + * Host Negotiation Detected. During the mode
  64826. + * switch all interrupts are cleared so the disconnect
  64827. + * interrupt handler will not get executed.
  64828. + */
  64829. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  64830. + "Host Negotiation Detected++ (%s)\n",
  64831. + (dwc_otg_is_host_mode(core_if) ? "Host" :
  64832. + "Device"));
  64833. + if (dwc_otg_is_device_mode(core_if)) {
  64834. + DWC_DEBUGPL(DBG_ANY, "a_suspend->a_peripheral (%d)\n",
  64835. + core_if->op_state);
  64836. + DWC_SPINUNLOCK(core_if->lock);
  64837. + cil_hcd_disconnect(core_if);
  64838. + cil_pcd_start(core_if);
  64839. + DWC_SPINLOCK(core_if->lock);
  64840. + core_if->op_state = A_PERIPHERAL;
  64841. + } else {
  64842. + /*
  64843. + * Need to disable SOF interrupt immediately. When
  64844. + * switching from device to host, the PCD interrupt
  64845. + * handler won't handle the interrupt if host mode is
  64846. + * already set. The HCD interrupt handler won't get
  64847. + * called if the HCD state is HALT. This means that
  64848. + * the interrupt does not get handled and Linux
  64849. + * complains loudly.
  64850. + */
  64851. + gintmsk.d32 = 0;
  64852. + gintmsk.b.sofintr = 1;
  64853. + DWC_MODIFY_REG32(&global_regs->gintmsk, gintmsk.d32, 0);
  64854. + DWC_SPINUNLOCK(core_if->lock);
  64855. + cil_pcd_stop(core_if);
  64856. + cil_hcd_start(core_if);
  64857. + DWC_SPINLOCK(core_if->lock);
  64858. + core_if->op_state = A_HOST;
  64859. + }
  64860. + }
  64861. + if (gotgint.b.adevtoutchng) {
  64862. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  64863. + "A-Device Timeout Change++\n");
  64864. + }
  64865. + if (gotgint.b.debdone) {
  64866. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: " "Debounce Done++\n");
  64867. + }
  64868. +
  64869. + /* Clear GOTGINT */
  64870. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgint, gotgint.d32);
  64871. +
  64872. + return 1;
  64873. +}
  64874. +
  64875. +void w_conn_id_status_change(void *p)
  64876. +{
  64877. + dwc_otg_core_if_t *core_if = p;
  64878. + uint32_t count = 0;
  64879. + gotgctl_data_t gotgctl = {.d32 = 0 };
  64880. +
  64881. + gotgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  64882. + DWC_DEBUGPL(DBG_CIL, "gotgctl=%0x\n", gotgctl.d32);
  64883. + DWC_DEBUGPL(DBG_CIL, "gotgctl.b.conidsts=%d\n", gotgctl.b.conidsts);
  64884. +
  64885. + /* B-Device connector (Device Mode) */
  64886. + if (gotgctl.b.conidsts) {
  64887. + /* Wait for switch to device mode. */
  64888. + while (!dwc_otg_is_device_mode(core_if)) {
  64889. + DWC_PRINTF("Waiting for Peripheral Mode, Mode=%s\n",
  64890. + (dwc_otg_is_host_mode(core_if) ? "Host" :
  64891. + "Peripheral"));
  64892. + dwc_mdelay(100);
  64893. + if (++count > 10000)
  64894. + break;
  64895. + }
  64896. + DWC_ASSERT(++count < 10000,
  64897. + "Connection id status change timed out");
  64898. + core_if->op_state = B_PERIPHERAL;
  64899. + dwc_otg_core_init(core_if);
  64900. + dwc_otg_enable_global_interrupts(core_if);
  64901. + cil_pcd_start(core_if);
  64902. + } else {
  64903. + /* A-Device connector (Host Mode) */
  64904. + while (!dwc_otg_is_host_mode(core_if)) {
  64905. + DWC_PRINTF("Waiting for Host Mode, Mode=%s\n",
  64906. + (dwc_otg_is_host_mode(core_if) ? "Host" :
  64907. + "Peripheral"));
  64908. + dwc_mdelay(100);
  64909. + if (++count > 10000)
  64910. + break;
  64911. + }
  64912. + DWC_ASSERT(++count < 10000,
  64913. + "Connection id status change timed out");
  64914. + core_if->op_state = A_HOST;
  64915. + /*
  64916. + * Initialize the Core for Host mode.
  64917. + */
  64918. + dwc_otg_core_init(core_if);
  64919. + dwc_otg_enable_global_interrupts(core_if);
  64920. + cil_hcd_start(core_if);
  64921. + }
  64922. +}
  64923. +
  64924. +/**
  64925. + * This function handles the Connector ID Status Change Interrupt. It
  64926. + * reads the OTG Interrupt Register (GOTCTL) to determine whether this
  64927. + * is a Device to Host Mode transition or a Host Mode to Device
  64928. + * Transition.
  64929. + *
  64930. + * This only occurs when the cable is connected/removed from the PHY
  64931. + * connector.
  64932. + *
  64933. + * @param core_if Programming view of DWC_otg controller.
  64934. + */
  64935. +int32_t dwc_otg_handle_conn_id_status_change_intr(dwc_otg_core_if_t * core_if)
  64936. +{
  64937. +
  64938. + /*
  64939. + * Need to disable SOF interrupt immediately. If switching from device
  64940. + * to host, the PCD interrupt handler won't handle the interrupt if
  64941. + * host mode is already set. The HCD interrupt handler won't get
  64942. + * called if the HCD state is HALT. This means that the interrupt does
  64943. + * not get handled and Linux complains loudly.
  64944. + */
  64945. + gintmsk_data_t gintmsk = {.d32 = 0 };
  64946. + gintsts_data_t gintsts = {.d32 = 0 };
  64947. +
  64948. + gintmsk.b.sofintr = 1;
  64949. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32, 0);
  64950. +
  64951. + DWC_DEBUGPL(DBG_CIL,
  64952. + " ++Connector ID Status Change Interrupt++ (%s)\n",
  64953. + (dwc_otg_is_host_mode(core_if) ? "Host" : "Device"));
  64954. +
  64955. + DWC_SPINUNLOCK(core_if->lock);
  64956. +
  64957. + /*
  64958. + * Need to schedule a work, as there are possible DELAY function calls
  64959. + * Release lock before scheduling workq as it holds spinlock during scheduling
  64960. + */
  64961. +
  64962. + DWC_WORKQ_SCHEDULE(core_if->wq_otg, w_conn_id_status_change,
  64963. + core_if, "connection id status change");
  64964. + DWC_SPINLOCK(core_if->lock);
  64965. +
  64966. + /* Set flag and clear interrupt */
  64967. + gintsts.b.conidstschng = 1;
  64968. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  64969. +
  64970. + return 1;
  64971. +}
  64972. +
  64973. +/**
  64974. + * This interrupt indicates that a device is initiating the Session
  64975. + * Request Protocol to request the host to turn on bus power so a new
  64976. + * session can begin. The handler responds by turning on bus power. If
  64977. + * the DWC_otg controller is in low power mode, the handler brings the
  64978. + * controller out of low power mode before turning on bus power.
  64979. + *
  64980. + * @param core_if Programming view of DWC_otg controller.
  64981. + */
  64982. +int32_t dwc_otg_handle_session_req_intr(dwc_otg_core_if_t * core_if)
  64983. +{
  64984. + gintsts_data_t gintsts;
  64985. +
  64986. +#ifndef DWC_HOST_ONLY
  64987. + DWC_DEBUGPL(DBG_ANY, "++Session Request Interrupt++\n");
  64988. +
  64989. + if (dwc_otg_is_device_mode(core_if)) {
  64990. + DWC_PRINTF("SRP: Device mode\n");
  64991. + } else {
  64992. + hprt0_data_t hprt0;
  64993. + DWC_PRINTF("SRP: Host mode\n");
  64994. +
  64995. + /* Turn on the port power bit. */
  64996. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  64997. + hprt0.b.prtpwr = 1;
  64998. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  64999. +
  65000. + /* Start the Connection timer. So a message can be displayed
  65001. + * if connect does not occur within 10 seconds. */
  65002. + cil_hcd_session_start(core_if);
  65003. + }
  65004. +#endif
  65005. +
  65006. + /* Clear interrupt */
  65007. + gintsts.d32 = 0;
  65008. + gintsts.b.sessreqintr = 1;
  65009. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  65010. +
  65011. + return 1;
  65012. +}
  65013. +
  65014. +void w_wakeup_detected(void *p)
  65015. +{
  65016. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) p;
  65017. + /*
  65018. + * Clear the Resume after 70ms. (Need 20 ms minimum. Use 70 ms
  65019. + * so that OPT tests pass with all PHYs).
  65020. + */
  65021. + hprt0_data_t hprt0 = {.d32 = 0 };
  65022. +#if 0
  65023. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  65024. + /* Restart the Phy Clock */
  65025. + pcgcctl.b.stoppclk = 1;
  65026. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  65027. + dwc_udelay(10);
  65028. +#endif //0
  65029. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  65030. + DWC_DEBUGPL(DBG_ANY, "Resume: HPRT0=%0x\n", hprt0.d32);
  65031. +// dwc_mdelay(70);
  65032. + hprt0.b.prtres = 0; /* Resume */
  65033. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  65034. + DWC_DEBUGPL(DBG_ANY, "Clear Resume: HPRT0=%0x\n",
  65035. + DWC_READ_REG32(core_if->host_if->hprt0));
  65036. +
  65037. + cil_hcd_resume(core_if);
  65038. +
  65039. + /** Change to L0 state*/
  65040. + core_if->lx_state = DWC_OTG_L0;
  65041. +}
  65042. +
  65043. +/**
  65044. + * This interrupt indicates that the DWC_otg controller has detected a
  65045. + * resume or remote wakeup sequence. If the DWC_otg controller is in
  65046. + * low power mode, the handler must brings the controller out of low
  65047. + * power mode. The controller automatically begins resume
  65048. + * signaling. The handler schedules a time to stop resume signaling.
  65049. + */
  65050. +int32_t dwc_otg_handle_wakeup_detected_intr(dwc_otg_core_if_t * core_if)
  65051. +{
  65052. + gintsts_data_t gintsts;
  65053. +
  65054. + DWC_DEBUGPL(DBG_ANY,
  65055. + "++Resume and Remote Wakeup Detected Interrupt++\n");
  65056. +
  65057. + DWC_PRINTF("%s lxstate = %d\n", __func__, core_if->lx_state);
  65058. +
  65059. + if (dwc_otg_is_device_mode(core_if)) {
  65060. + dctl_data_t dctl = {.d32 = 0 };
  65061. + DWC_DEBUGPL(DBG_PCD, "DSTS=0x%0x\n",
  65062. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->
  65063. + dsts));
  65064. + if (core_if->lx_state == DWC_OTG_L2) {
  65065. +#ifdef PARTIAL_POWER_DOWN
  65066. + if (core_if->hwcfg4.b.power_optimiz) {
  65067. + pcgcctl_data_t power = {.d32 = 0 };
  65068. +
  65069. + power.d32 = DWC_READ_REG32(core_if->pcgcctl);
  65070. + DWC_DEBUGPL(DBG_CIL, "PCGCCTL=%0x\n",
  65071. + power.d32);
  65072. +
  65073. + power.b.stoppclk = 0;
  65074. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  65075. +
  65076. + power.b.pwrclmp = 0;
  65077. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  65078. +
  65079. + power.b.rstpdwnmodule = 0;
  65080. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  65081. + }
  65082. +#endif
  65083. + /* Clear the Remote Wakeup Signaling */
  65084. + dctl.b.rmtwkupsig = 1;
  65085. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  65086. + dctl, dctl.d32, 0);
  65087. +
  65088. + DWC_SPINUNLOCK(core_if->lock);
  65089. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  65090. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  65091. + }
  65092. + DWC_SPINLOCK(core_if->lock);
  65093. + } else {
  65094. + glpmcfg_data_t lpmcfg;
  65095. + lpmcfg.d32 =
  65096. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  65097. + lpmcfg.b.hird_thres &= (~(1 << 4));
  65098. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg,
  65099. + lpmcfg.d32);
  65100. + }
  65101. + /** Change to L0 state*/
  65102. + core_if->lx_state = DWC_OTG_L0;
  65103. + } else {
  65104. + if (core_if->lx_state != DWC_OTG_L1) {
  65105. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  65106. +
  65107. + /* Restart the Phy Clock */
  65108. + pcgcctl.b.stoppclk = 1;
  65109. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  65110. + DWC_TIMER_SCHEDULE(core_if->wkp_timer, 71);
  65111. + } else {
  65112. + /** Change to L0 state*/
  65113. + core_if->lx_state = DWC_OTG_L0;
  65114. + }
  65115. + }
  65116. +
  65117. + /* Clear interrupt */
  65118. + gintsts.d32 = 0;
  65119. + gintsts.b.wkupintr = 1;
  65120. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  65121. +
  65122. + return 1;
  65123. +}
  65124. +
  65125. +/**
  65126. + * This interrupt indicates that the Wakeup Logic has detected a
  65127. + * Device disconnect.
  65128. + */
  65129. +static int32_t dwc_otg_handle_pwrdn_disconnect_intr(dwc_otg_core_if_t *core_if)
  65130. +{
  65131. + gpwrdn_data_t gpwrdn = { .d32 = 0 };
  65132. + gpwrdn_data_t gpwrdn_temp = { .d32 = 0 };
  65133. + gpwrdn_temp.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  65134. +
  65135. + DWC_PRINTF("%s called\n", __FUNCTION__);
  65136. +
  65137. + if (!core_if->hibernation_suspend) {
  65138. + DWC_PRINTF("Already exited from Hibernation\n");
  65139. + return 1;
  65140. + }
  65141. +
  65142. + /* Switch on the voltage to the core */
  65143. + gpwrdn.b.pwrdnswtch = 1;
  65144. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65145. + dwc_udelay(10);
  65146. +
  65147. + /* Reset the core */
  65148. + gpwrdn.d32 = 0;
  65149. + gpwrdn.b.pwrdnrstn = 1;
  65150. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65151. + dwc_udelay(10);
  65152. +
  65153. + /* Disable power clamps*/
  65154. + gpwrdn.d32 = 0;
  65155. + gpwrdn.b.pwrdnclmp = 1;
  65156. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65157. +
  65158. + /* Remove reset the core signal */
  65159. + gpwrdn.d32 = 0;
  65160. + gpwrdn.b.pwrdnrstn = 1;
  65161. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  65162. + dwc_udelay(10);
  65163. +
  65164. + /* Disable PMU interrupt */
  65165. + gpwrdn.d32 = 0;
  65166. + gpwrdn.b.pmuintsel = 1;
  65167. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65168. +
  65169. + core_if->hibernation_suspend = 0;
  65170. +
  65171. + /* Disable PMU */
  65172. + gpwrdn.d32 = 0;
  65173. + gpwrdn.b.pmuactv = 1;
  65174. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65175. + dwc_udelay(10);
  65176. +
  65177. + if (gpwrdn_temp.b.idsts) {
  65178. + core_if->op_state = B_PERIPHERAL;
  65179. + dwc_otg_core_init(core_if);
  65180. + dwc_otg_enable_global_interrupts(core_if);
  65181. + cil_pcd_start(core_if);
  65182. + } else {
  65183. + core_if->op_state = A_HOST;
  65184. + dwc_otg_core_init(core_if);
  65185. + dwc_otg_enable_global_interrupts(core_if);
  65186. + cil_hcd_start(core_if);
  65187. + }
  65188. +
  65189. + return 1;
  65190. +}
  65191. +
  65192. +/**
  65193. + * This interrupt indicates that the Wakeup Logic has detected a
  65194. + * remote wakeup sequence.
  65195. + */
  65196. +static int32_t dwc_otg_handle_pwrdn_wakeup_detected_intr(dwc_otg_core_if_t * core_if)
  65197. +{
  65198. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  65199. + DWC_DEBUGPL(DBG_ANY,
  65200. + "++Powerdown Remote Wakeup Detected Interrupt++\n");
  65201. +
  65202. + if (!core_if->hibernation_suspend) {
  65203. + DWC_PRINTF("Already exited from Hibernation\n");
  65204. + return 1;
  65205. + }
  65206. +
  65207. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  65208. + if (gpwrdn.b.idsts) { // Device Mode
  65209. + if ((core_if->power_down == 2)
  65210. + && (core_if->hibernation_suspend == 1)) {
  65211. + dwc_otg_device_hibernation_restore(core_if, 0, 0);
  65212. + }
  65213. + } else {
  65214. + if ((core_if->power_down == 2)
  65215. + && (core_if->hibernation_suspend == 1)) {
  65216. + dwc_otg_host_hibernation_restore(core_if, 1, 0);
  65217. + }
  65218. + }
  65219. + return 1;
  65220. +}
  65221. +
  65222. +static int32_t dwc_otg_handle_pwrdn_idsts_change(dwc_otg_device_t *otg_dev)
  65223. +{
  65224. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  65225. + gpwrdn_data_t gpwrdn_temp = {.d32 = 0 };
  65226. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  65227. +
  65228. + DWC_DEBUGPL(DBG_ANY, "%s called\n", __FUNCTION__);
  65229. + gpwrdn_temp.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  65230. + if (core_if->power_down == 2) {
  65231. + if (!core_if->hibernation_suspend) {
  65232. + DWC_PRINTF("Already exited from Hibernation\n");
  65233. + return 1;
  65234. + }
  65235. + DWC_DEBUGPL(DBG_ANY, "Exit from hibernation on ID sts change\n");
  65236. + /* Switch on the voltage to the core */
  65237. + gpwrdn.b.pwrdnswtch = 1;
  65238. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65239. + dwc_udelay(10);
  65240. +
  65241. + /* Reset the core */
  65242. + gpwrdn.d32 = 0;
  65243. + gpwrdn.b.pwrdnrstn = 1;
  65244. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65245. + dwc_udelay(10);
  65246. +
  65247. + /* Disable power clamps */
  65248. + gpwrdn.d32 = 0;
  65249. + gpwrdn.b.pwrdnclmp = 1;
  65250. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65251. +
  65252. + /* Remove reset the core signal */
  65253. + gpwrdn.d32 = 0;
  65254. + gpwrdn.b.pwrdnrstn = 1;
  65255. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  65256. + dwc_udelay(10);
  65257. +
  65258. + /* Disable PMU interrupt */
  65259. + gpwrdn.d32 = 0;
  65260. + gpwrdn.b.pmuintsel = 1;
  65261. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65262. +
  65263. + /*Indicates that we are exiting from hibernation */
  65264. + core_if->hibernation_suspend = 0;
  65265. +
  65266. + /* Disable PMU */
  65267. + gpwrdn.d32 = 0;
  65268. + gpwrdn.b.pmuactv = 1;
  65269. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65270. + dwc_udelay(10);
  65271. +
  65272. + gpwrdn.d32 = core_if->gr_backup->gpwrdn_local;
  65273. + if (gpwrdn.b.dis_vbus == 1) {
  65274. + gpwrdn.d32 = 0;
  65275. + gpwrdn.b.dis_vbus = 1;
  65276. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65277. + }
  65278. +
  65279. + if (gpwrdn_temp.b.idsts) {
  65280. + core_if->op_state = B_PERIPHERAL;
  65281. + dwc_otg_core_init(core_if);
  65282. + dwc_otg_enable_global_interrupts(core_if);
  65283. + cil_pcd_start(core_if);
  65284. + } else {
  65285. + core_if->op_state = A_HOST;
  65286. + dwc_otg_core_init(core_if);
  65287. + dwc_otg_enable_global_interrupts(core_if);
  65288. + cil_hcd_start(core_if);
  65289. + }
  65290. + }
  65291. +
  65292. + if (core_if->adp_enable) {
  65293. + uint8_t is_host = 0;
  65294. + DWC_SPINUNLOCK(core_if->lock);
  65295. + /* Change the core_if's lock to hcd/pcd lock depend on mode? */
  65296. +#ifndef DWC_HOST_ONLY
  65297. + if (gpwrdn_temp.b.idsts)
  65298. + core_if->lock = otg_dev->pcd->lock;
  65299. +#endif
  65300. +#ifndef DWC_DEVICE_ONLY
  65301. + if (!gpwrdn_temp.b.idsts) {
  65302. + core_if->lock = otg_dev->hcd->lock;
  65303. + is_host = 1;
  65304. + }
  65305. +#endif
  65306. + DWC_PRINTF("RESTART ADP\n");
  65307. + if (core_if->adp.probe_enabled)
  65308. + dwc_otg_adp_probe_stop(core_if);
  65309. + if (core_if->adp.sense_enabled)
  65310. + dwc_otg_adp_sense_stop(core_if);
  65311. + if (core_if->adp.sense_timer_started)
  65312. + DWC_TIMER_CANCEL(core_if->adp.sense_timer);
  65313. + if (core_if->adp.vbuson_timer_started)
  65314. + DWC_TIMER_CANCEL(core_if->adp.vbuson_timer);
  65315. + core_if->adp.probe_timer_values[0] = -1;
  65316. + core_if->adp.probe_timer_values[1] = -1;
  65317. + core_if->adp.sense_timer_started = 0;
  65318. + core_if->adp.vbuson_timer_started = 0;
  65319. + core_if->adp.probe_counter = 0;
  65320. + core_if->adp.gpwrdn = 0;
  65321. +
  65322. + /* Disable PMU and restart ADP */
  65323. + gpwrdn_temp.d32 = 0;
  65324. + gpwrdn_temp.b.pmuactv = 1;
  65325. + gpwrdn_temp.b.pmuintsel = 1;
  65326. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65327. + DWC_PRINTF("Check point 1\n");
  65328. + dwc_mdelay(110);
  65329. + dwc_otg_adp_start(core_if, is_host);
  65330. + DWC_SPINLOCK(core_if->lock);
  65331. + }
  65332. +
  65333. +
  65334. + return 1;
  65335. +}
  65336. +
  65337. +static int32_t dwc_otg_handle_pwrdn_session_change(dwc_otg_core_if_t * core_if)
  65338. +{
  65339. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  65340. + int32_t otg_cap_param = core_if->core_params->otg_cap;
  65341. + DWC_DEBUGPL(DBG_ANY, "%s called\n", __FUNCTION__);
  65342. +
  65343. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  65344. + if (core_if->power_down == 2) {
  65345. + if (!core_if->hibernation_suspend) {
  65346. + DWC_PRINTF("Already exited from Hibernation\n");
  65347. + return 1;
  65348. + }
  65349. +
  65350. + if ((otg_cap_param != DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE ||
  65351. + otg_cap_param != DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE) &&
  65352. + gpwrdn.b.bsessvld == 0) {
  65353. + /* Save gpwrdn register for further usage if stschng interrupt */
  65354. + core_if->gr_backup->gpwrdn_local =
  65355. + DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  65356. + /*Exit from ISR and wait for stschng interrupt with bsessvld = 1 */
  65357. + return 1;
  65358. + }
  65359. +
  65360. + /* Switch on the voltage to the core */
  65361. + gpwrdn.d32 = 0;
  65362. + gpwrdn.b.pwrdnswtch = 1;
  65363. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65364. + dwc_udelay(10);
  65365. +
  65366. + /* Reset the core */
  65367. + gpwrdn.d32 = 0;
  65368. + gpwrdn.b.pwrdnrstn = 1;
  65369. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65370. + dwc_udelay(10);
  65371. +
  65372. + /* Disable power clamps */
  65373. + gpwrdn.d32 = 0;
  65374. + gpwrdn.b.pwrdnclmp = 1;
  65375. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65376. +
  65377. + /* Remove reset the core signal */
  65378. + gpwrdn.d32 = 0;
  65379. + gpwrdn.b.pwrdnrstn = 1;
  65380. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  65381. + dwc_udelay(10);
  65382. +
  65383. + /* Disable PMU interrupt */
  65384. + gpwrdn.d32 = 0;
  65385. + gpwrdn.b.pmuintsel = 1;
  65386. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65387. + dwc_udelay(10);
  65388. +
  65389. + /*Indicates that we are exiting from hibernation */
  65390. + core_if->hibernation_suspend = 0;
  65391. +
  65392. + /* Disable PMU */
  65393. + gpwrdn.d32 = 0;
  65394. + gpwrdn.b.pmuactv = 1;
  65395. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65396. + dwc_udelay(10);
  65397. +
  65398. + core_if->op_state = B_PERIPHERAL;
  65399. + dwc_otg_core_init(core_if);
  65400. + dwc_otg_enable_global_interrupts(core_if);
  65401. + cil_pcd_start(core_if);
  65402. +
  65403. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE ||
  65404. + otg_cap_param == DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE) {
  65405. + /*
  65406. + * Initiate SRP after initial ADP probe.
  65407. + */
  65408. + dwc_otg_initiate_srp(core_if);
  65409. + }
  65410. + }
  65411. +
  65412. + return 1;
  65413. +}
  65414. +/**
  65415. + * This interrupt indicates that the Wakeup Logic has detected a
  65416. + * status change either on IDDIG or BSessVld.
  65417. + */
  65418. +static uint32_t dwc_otg_handle_pwrdn_stschng_intr(dwc_otg_device_t *otg_dev)
  65419. +{
  65420. + int retval;
  65421. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  65422. + gpwrdn_data_t gpwrdn_temp = {.d32 = 0 };
  65423. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  65424. +
  65425. + DWC_PRINTF("%s called\n", __FUNCTION__);
  65426. +
  65427. + if (core_if->power_down == 2) {
  65428. + if (core_if->hibernation_suspend <= 0) {
  65429. + DWC_PRINTF("Already exited from Hibernation\n");
  65430. + return 1;
  65431. + } else
  65432. + gpwrdn_temp.d32 = core_if->gr_backup->gpwrdn_local;
  65433. +
  65434. + } else {
  65435. + gpwrdn_temp.d32 = core_if->adp.gpwrdn;
  65436. + }
  65437. +
  65438. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  65439. +
  65440. + if (gpwrdn.b.idsts ^ gpwrdn_temp.b.idsts) {
  65441. + retval = dwc_otg_handle_pwrdn_idsts_change(otg_dev);
  65442. + } else if (gpwrdn.b.bsessvld ^ gpwrdn_temp.b.bsessvld) {
  65443. + retval = dwc_otg_handle_pwrdn_session_change(core_if);
  65444. + }
  65445. +
  65446. + return retval;
  65447. +}
  65448. +
  65449. +/**
  65450. + * This interrupt indicates that the Wakeup Logic has detected a
  65451. + * SRP.
  65452. + */
  65453. +static int32_t dwc_otg_handle_pwrdn_srp_intr(dwc_otg_core_if_t * core_if)
  65454. +{
  65455. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  65456. +
  65457. + DWC_PRINTF("%s called\n", __FUNCTION__);
  65458. +
  65459. + if (!core_if->hibernation_suspend) {
  65460. + DWC_PRINTF("Already exited from Hibernation\n");
  65461. + return 1;
  65462. + }
  65463. +#ifdef DWC_DEV_SRPCAP
  65464. + if (core_if->pwron_timer_started) {
  65465. + core_if->pwron_timer_started = 0;
  65466. + DWC_TIMER_CANCEL(core_if->pwron_timer);
  65467. + }
  65468. +#endif
  65469. +
  65470. + /* Switch on the voltage to the core */
  65471. + gpwrdn.b.pwrdnswtch = 1;
  65472. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65473. + dwc_udelay(10);
  65474. +
  65475. + /* Reset the core */
  65476. + gpwrdn.d32 = 0;
  65477. + gpwrdn.b.pwrdnrstn = 1;
  65478. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65479. + dwc_udelay(10);
  65480. +
  65481. + /* Disable power clamps */
  65482. + gpwrdn.d32 = 0;
  65483. + gpwrdn.b.pwrdnclmp = 1;
  65484. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65485. +
  65486. + /* Remove reset the core signal */
  65487. + gpwrdn.d32 = 0;
  65488. + gpwrdn.b.pwrdnrstn = 1;
  65489. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  65490. + dwc_udelay(10);
  65491. +
  65492. + /* Disable PMU interrupt */
  65493. + gpwrdn.d32 = 0;
  65494. + gpwrdn.b.pmuintsel = 1;
  65495. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65496. +
  65497. + /* Indicates that we are exiting from hibernation */
  65498. + core_if->hibernation_suspend = 0;
  65499. +
  65500. + /* Disable PMU */
  65501. + gpwrdn.d32 = 0;
  65502. + gpwrdn.b.pmuactv = 1;
  65503. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65504. + dwc_udelay(10);
  65505. +
  65506. + /* Programm Disable VBUS to 0 */
  65507. + gpwrdn.d32 = 0;
  65508. + gpwrdn.b.dis_vbus = 1;
  65509. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65510. +
  65511. + /*Initialize the core as Host */
  65512. + core_if->op_state = A_HOST;
  65513. + dwc_otg_core_init(core_if);
  65514. + dwc_otg_enable_global_interrupts(core_if);
  65515. + cil_hcd_start(core_if);
  65516. +
  65517. + return 1;
  65518. +}
  65519. +
  65520. +/** This interrupt indicates that restore command after Hibernation
  65521. + * was completed by the core. */
  65522. +int32_t dwc_otg_handle_restore_done_intr(dwc_otg_core_if_t * core_if)
  65523. +{
  65524. + pcgcctl_data_t pcgcctl;
  65525. + DWC_DEBUGPL(DBG_ANY, "++Restore Done Interrupt++\n");
  65526. +
  65527. + //TODO De-assert restore signal. 8.a
  65528. + pcgcctl.d32 = DWC_READ_REG32(core_if->pcgcctl);
  65529. + if (pcgcctl.b.restoremode == 1) {
  65530. + gintmsk_data_t gintmsk = {.d32 = 0 };
  65531. + /*
  65532. + * If restore mode is Remote Wakeup,
  65533. + * unmask Remote Wakeup interrupt.
  65534. + */
  65535. + gintmsk.b.wkupintr = 1;
  65536. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  65537. + 0, gintmsk.d32);
  65538. + }
  65539. +
  65540. + return 1;
  65541. +}
  65542. +
  65543. +/**
  65544. + * This interrupt indicates that a device has been disconnected from
  65545. + * the root port.
  65546. + */
  65547. +int32_t dwc_otg_handle_disconnect_intr(dwc_otg_core_if_t * core_if)
  65548. +{
  65549. + gintsts_data_t gintsts;
  65550. +
  65551. + DWC_DEBUGPL(DBG_ANY, "++Disconnect Detected Interrupt++ (%s) %s\n",
  65552. + (dwc_otg_is_host_mode(core_if) ? "Host" : "Device"),
  65553. + op_state_str(core_if));
  65554. +
  65555. +/** @todo Consolidate this if statement. */
  65556. +#ifndef DWC_HOST_ONLY
  65557. + if (core_if->op_state == B_HOST) {
  65558. + /* If in device mode Disconnect and stop the HCD, then
  65559. + * start the PCD. */
  65560. + DWC_SPINUNLOCK(core_if->lock);
  65561. + cil_hcd_disconnect(core_if);
  65562. + cil_pcd_start(core_if);
  65563. + DWC_SPINLOCK(core_if->lock);
  65564. + core_if->op_state = B_PERIPHERAL;
  65565. + } else if (dwc_otg_is_device_mode(core_if)) {
  65566. + gotgctl_data_t gotgctl = {.d32 = 0 };
  65567. + gotgctl.d32 =
  65568. + DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  65569. + if (gotgctl.b.hstsethnpen == 1) {
  65570. + /* Do nothing, if HNP in process the OTG
  65571. + * interrupt "Host Negotiation Detected"
  65572. + * interrupt will do the mode switch.
  65573. + */
  65574. + } else if (gotgctl.b.devhnpen == 0) {
  65575. + /* If in device mode Disconnect and stop the HCD, then
  65576. + * start the PCD. */
  65577. + DWC_SPINUNLOCK(core_if->lock);
  65578. + cil_hcd_disconnect(core_if);
  65579. + cil_pcd_start(core_if);
  65580. + DWC_SPINLOCK(core_if->lock);
  65581. + core_if->op_state = B_PERIPHERAL;
  65582. + } else {
  65583. + DWC_DEBUGPL(DBG_ANY, "!a_peripheral && !devhnpen\n");
  65584. + }
  65585. + } else {
  65586. + if (core_if->op_state == A_HOST) {
  65587. + /* A-Cable still connected but device disconnected. */
  65588. + cil_hcd_disconnect(core_if);
  65589. + if (core_if->adp_enable) {
  65590. + gpwrdn_data_t gpwrdn = { .d32 = 0 };
  65591. + cil_hcd_stop(core_if);
  65592. + /* Enable Power Down Logic */
  65593. + gpwrdn.b.pmuintsel = 1;
  65594. + gpwrdn.b.pmuactv = 1;
  65595. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  65596. + gpwrdn, 0, gpwrdn.d32);
  65597. + dwc_otg_adp_probe_start(core_if);
  65598. +
  65599. + /* Power off the core */
  65600. + if (core_if->power_down == 2) {
  65601. + gpwrdn.d32 = 0;
  65602. + gpwrdn.b.pwrdnswtch = 1;
  65603. + DWC_MODIFY_REG32
  65604. + (&core_if->core_global_regs->gpwrdn,
  65605. + gpwrdn.d32, 0);
  65606. + }
  65607. + }
  65608. + }
  65609. + }
  65610. +#endif
  65611. + /* Change to L3(OFF) state */
  65612. + core_if->lx_state = DWC_OTG_L3;
  65613. +
  65614. + gintsts.d32 = 0;
  65615. + gintsts.b.disconnect = 1;
  65616. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  65617. + return 1;
  65618. +}
  65619. +
  65620. +/**
  65621. + * This interrupt indicates that SUSPEND state has been detected on
  65622. + * the USB.
  65623. + *
  65624. + * For HNP the USB Suspend interrupt signals the change from
  65625. + * "a_peripheral" to "a_host".
  65626. + *
  65627. + * When power management is enabled the core will be put in low power
  65628. + * mode.
  65629. + */
  65630. +int32_t dwc_otg_handle_usb_suspend_intr(dwc_otg_core_if_t * core_if)
  65631. +{
  65632. + dsts_data_t dsts;
  65633. + gintsts_data_t gintsts;
  65634. + dcfg_data_t dcfg;
  65635. +
  65636. + DWC_DEBUGPL(DBG_ANY, "USB SUSPEND\n");
  65637. +
  65638. + if (dwc_otg_is_device_mode(core_if)) {
  65639. + /* Check the Device status register to determine if the Suspend
  65640. + * state is active. */
  65641. + dsts.d32 =
  65642. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  65643. + DWC_DEBUGPL(DBG_PCD, "DSTS=0x%0x\n", dsts.d32);
  65644. + DWC_DEBUGPL(DBG_PCD, "DSTS.Suspend Status=%d "
  65645. + "HWCFG4.power Optimize=%d\n",
  65646. + dsts.b.suspsts, core_if->hwcfg4.b.power_optimiz);
  65647. +
  65648. +#ifdef PARTIAL_POWER_DOWN
  65649. +/** @todo Add a module parameter for power management. */
  65650. +
  65651. + if (dsts.b.suspsts && core_if->hwcfg4.b.power_optimiz) {
  65652. + pcgcctl_data_t power = {.d32 = 0 };
  65653. + DWC_DEBUGPL(DBG_CIL, "suspend\n");
  65654. +
  65655. + power.b.pwrclmp = 1;
  65656. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  65657. +
  65658. + power.b.rstpdwnmodule = 1;
  65659. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, power.d32);
  65660. +
  65661. + power.b.stoppclk = 1;
  65662. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, power.d32);
  65663. +
  65664. + } else {
  65665. + DWC_DEBUGPL(DBG_ANY, "disconnect?\n");
  65666. + }
  65667. +#endif
  65668. + /* PCD callback for suspend. Release the lock inside of callback function */
  65669. + cil_pcd_suspend(core_if);
  65670. + if (core_if->power_down == 2)
  65671. + {
  65672. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  65673. + DWC_DEBUGPL(DBG_ANY,"lx_state = %08x\n",core_if->lx_state);
  65674. + DWC_DEBUGPL(DBG_ANY," device address = %08d\n",dcfg.b.devaddr);
  65675. +
  65676. + if (core_if->lx_state != DWC_OTG_L3 && dcfg.b.devaddr) {
  65677. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  65678. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  65679. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  65680. +
  65681. + /* Change to L2(suspend) state */
  65682. + core_if->lx_state = DWC_OTG_L2;
  65683. +
  65684. + /* Clear interrupt in gintsts */
  65685. + gintsts.d32 = 0;
  65686. + gintsts.b.usbsuspend = 1;
  65687. + DWC_WRITE_REG32(&core_if->core_global_regs->
  65688. + gintsts, gintsts.d32);
  65689. + DWC_PRINTF("Start of hibernation completed\n");
  65690. + dwc_otg_save_global_regs(core_if);
  65691. + dwc_otg_save_dev_regs(core_if);
  65692. +
  65693. + gusbcfg.d32 =
  65694. + DWC_READ_REG32(&core_if->core_global_regs->
  65695. + gusbcfg);
  65696. + if (gusbcfg.b.ulpi_utmi_sel == 1) {
  65697. + /* ULPI interface */
  65698. + /* Suspend the Phy Clock */
  65699. + pcgcctl.d32 = 0;
  65700. + pcgcctl.b.stoppclk = 1;
  65701. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  65702. + pcgcctl.d32);
  65703. + dwc_udelay(10);
  65704. + gpwrdn.b.pmuactv = 1;
  65705. + DWC_MODIFY_REG32(&core_if->
  65706. + core_global_regs->
  65707. + gpwrdn, 0, gpwrdn.d32);
  65708. + } else {
  65709. + /* UTMI+ Interface */
  65710. + gpwrdn.b.pmuactv = 1;
  65711. + DWC_MODIFY_REG32(&core_if->
  65712. + core_global_regs->
  65713. + gpwrdn, 0, gpwrdn.d32);
  65714. + dwc_udelay(10);
  65715. + pcgcctl.b.stoppclk = 1;
  65716. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  65717. + pcgcctl.d32);
  65718. + dwc_udelay(10);
  65719. + }
  65720. +
  65721. + /* Set flag to indicate that we are in hibernation */
  65722. + core_if->hibernation_suspend = 1;
  65723. + /* Enable interrupts from wake up logic */
  65724. + gpwrdn.d32 = 0;
  65725. + gpwrdn.b.pmuintsel = 1;
  65726. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  65727. + gpwrdn, 0, gpwrdn.d32);
  65728. + dwc_udelay(10);
  65729. +
  65730. + /* Unmask device mode interrupts in GPWRDN */
  65731. + gpwrdn.d32 = 0;
  65732. + gpwrdn.b.rst_det_msk = 1;
  65733. + gpwrdn.b.lnstchng_msk = 1;
  65734. + gpwrdn.b.sts_chngint_msk = 1;
  65735. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  65736. + gpwrdn, 0, gpwrdn.d32);
  65737. + dwc_udelay(10);
  65738. +
  65739. + /* Enable Power Down Clamp */
  65740. + gpwrdn.d32 = 0;
  65741. + gpwrdn.b.pwrdnclmp = 1;
  65742. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  65743. + gpwrdn, 0, gpwrdn.d32);
  65744. + dwc_udelay(10);
  65745. +
  65746. + /* Switch off VDD */
  65747. + gpwrdn.d32 = 0;
  65748. + gpwrdn.b.pwrdnswtch = 1;
  65749. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  65750. + gpwrdn, 0, gpwrdn.d32);
  65751. +
  65752. + /* Save gpwrdn register for further usage if stschng interrupt */
  65753. + core_if->gr_backup->gpwrdn_local =
  65754. + DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  65755. + DWC_PRINTF("Hibernation completed\n");
  65756. +
  65757. + return 1;
  65758. + }
  65759. + } else if (core_if->power_down == 3) {
  65760. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  65761. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  65762. + DWC_DEBUGPL(DBG_ANY, "lx_state = %08x\n",core_if->lx_state);
  65763. + DWC_DEBUGPL(DBG_ANY, " device address = %08d\n",dcfg.b.devaddr);
  65764. +
  65765. + if (core_if->lx_state != DWC_OTG_L3 && dcfg.b.devaddr) {
  65766. + DWC_DEBUGPL(DBG_ANY, "Start entering to extended hibernation\n");
  65767. + core_if->xhib = 1;
  65768. +
  65769. + /* Clear interrupt in gintsts */
  65770. + gintsts.d32 = 0;
  65771. + gintsts.b.usbsuspend = 1;
  65772. + DWC_WRITE_REG32(&core_if->core_global_regs->
  65773. + gintsts, gintsts.d32);
  65774. +
  65775. + dwc_otg_save_global_regs(core_if);
  65776. + dwc_otg_save_dev_regs(core_if);
  65777. +
  65778. + /* Wait for 10 PHY clocks */
  65779. + dwc_udelay(10);
  65780. +
  65781. + /* Program GPIO register while entering to xHib */
  65782. + DWC_WRITE_REG32(&core_if->core_global_regs->ggpio, 0x1);
  65783. +
  65784. + pcgcctl.b.enbl_extnd_hiber = 1;
  65785. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  65786. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  65787. +
  65788. + pcgcctl.d32 = 0;
  65789. + pcgcctl.b.extnd_hiber_pwrclmp = 1;
  65790. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  65791. +
  65792. + pcgcctl.d32 = 0;
  65793. + pcgcctl.b.extnd_hiber_switch = 1;
  65794. + core_if->gr_backup->xhib_gpwrdn = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  65795. + core_if->gr_backup->xhib_pcgcctl = DWC_READ_REG32(core_if->pcgcctl) | pcgcctl.d32;
  65796. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  65797. +
  65798. + DWC_DEBUGPL(DBG_ANY, "Finished entering to extended hibernation\n");
  65799. +
  65800. + return 1;
  65801. + }
  65802. + }
  65803. + } else {
  65804. + if (core_if->op_state == A_PERIPHERAL) {
  65805. + DWC_DEBUGPL(DBG_ANY, "a_peripheral->a_host\n");
  65806. + /* Clear the a_peripheral flag, back to a_host. */
  65807. + DWC_SPINUNLOCK(core_if->lock);
  65808. + cil_pcd_stop(core_if);
  65809. + cil_hcd_start(core_if);
  65810. + DWC_SPINLOCK(core_if->lock);
  65811. + core_if->op_state = A_HOST;
  65812. + }
  65813. + }
  65814. +
  65815. + /* Change to L2(suspend) state */
  65816. + core_if->lx_state = DWC_OTG_L2;
  65817. +
  65818. + /* Clear interrupt */
  65819. + gintsts.d32 = 0;
  65820. + gintsts.b.usbsuspend = 1;
  65821. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  65822. +
  65823. + return 1;
  65824. +}
  65825. +
  65826. +static int32_t dwc_otg_handle_xhib_exit_intr(dwc_otg_core_if_t * core_if)
  65827. +{
  65828. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  65829. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  65830. + gahbcfg_data_t gahbcfg = {.d32 = 0 };
  65831. +
  65832. + dwc_udelay(10);
  65833. +
  65834. + /* Program GPIO register while entering to xHib */
  65835. + DWC_WRITE_REG32(&core_if->core_global_regs->ggpio, 0x0);
  65836. +
  65837. + pcgcctl.d32 = core_if->gr_backup->xhib_pcgcctl;
  65838. + pcgcctl.b.extnd_hiber_pwrclmp = 0;
  65839. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  65840. + dwc_udelay(10);
  65841. +
  65842. + gpwrdn.d32 = core_if->gr_backup->xhib_gpwrdn;
  65843. + gpwrdn.b.restore = 1;
  65844. + DWC_WRITE_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32);
  65845. + dwc_udelay(10);
  65846. +
  65847. + restore_lpm_i2c_regs(core_if);
  65848. +
  65849. + pcgcctl.d32 = core_if->gr_backup->pcgcctl_local & (0x3FFFF << 14);
  65850. + pcgcctl.b.max_xcvrselect = 1;
  65851. + pcgcctl.b.ess_reg_restored = 0;
  65852. + pcgcctl.b.extnd_hiber_switch = 0;
  65853. + pcgcctl.b.extnd_hiber_pwrclmp = 0;
  65854. + pcgcctl.b.enbl_extnd_hiber = 1;
  65855. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  65856. +
  65857. + gahbcfg.d32 = core_if->gr_backup->gahbcfg_local;
  65858. + gahbcfg.b.glblintrmsk = 1;
  65859. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg, gahbcfg.d32);
  65860. +
  65861. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  65862. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, 0x1 << 16);
  65863. +
  65864. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg,
  65865. + core_if->gr_backup->gusbcfg_local);
  65866. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg,
  65867. + core_if->dr_backup->dcfg);
  65868. +
  65869. + pcgcctl.d32 = 0;
  65870. + pcgcctl.d32 = core_if->gr_backup->pcgcctl_local & (0x3FFFF << 14);
  65871. + pcgcctl.b.max_xcvrselect = 1;
  65872. + pcgcctl.d32 |= 0x608;
  65873. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  65874. + dwc_udelay(10);
  65875. +
  65876. + pcgcctl.d32 = 0;
  65877. + pcgcctl.d32 = core_if->gr_backup->pcgcctl_local & (0x3FFFF << 14);
  65878. + pcgcctl.b.max_xcvrselect = 1;
  65879. + pcgcctl.b.ess_reg_restored = 1;
  65880. + pcgcctl.b.enbl_extnd_hiber = 1;
  65881. + pcgcctl.b.rstpdwnmodule = 1;
  65882. + pcgcctl.b.restoremode = 1;
  65883. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  65884. +
  65885. + DWC_DEBUGPL(DBG_ANY, "%s called\n", __FUNCTION__);
  65886. +
  65887. + return 1;
  65888. +}
  65889. +
  65890. +#ifdef CONFIG_USB_DWC_OTG_LPM
  65891. +/**
  65892. + * This function hadles LPM transaction received interrupt.
  65893. + */
  65894. +static int32_t dwc_otg_handle_lpm_intr(dwc_otg_core_if_t * core_if)
  65895. +{
  65896. + glpmcfg_data_t lpmcfg;
  65897. + gintsts_data_t gintsts;
  65898. +
  65899. + if (!core_if->core_params->lpm_enable) {
  65900. + DWC_PRINTF("Unexpected LPM interrupt\n");
  65901. + }
  65902. +
  65903. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  65904. + DWC_PRINTF("LPM config register = 0x%08x\n", lpmcfg.d32);
  65905. +
  65906. + if (dwc_otg_is_host_mode(core_if)) {
  65907. + cil_hcd_sleep(core_if);
  65908. + } else {
  65909. + lpmcfg.b.hird_thres |= (1 << 4);
  65910. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg,
  65911. + lpmcfg.d32);
  65912. + }
  65913. +
  65914. + /* Examine prt_sleep_sts after TL1TokenTetry period max (10 us) */
  65915. + dwc_udelay(10);
  65916. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  65917. + if (lpmcfg.b.prt_sleep_sts) {
  65918. + /* Save the current state */
  65919. + core_if->lx_state = DWC_OTG_L1;
  65920. + }
  65921. +
  65922. + /* Clear interrupt */
  65923. + gintsts.d32 = 0;
  65924. + gintsts.b.lpmtranrcvd = 1;
  65925. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  65926. + return 1;
  65927. +}
  65928. +#endif /* CONFIG_USB_DWC_OTG_LPM */
  65929. +
  65930. +/**
  65931. + * This function returns the Core Interrupt register.
  65932. + */
  65933. +static inline uint32_t dwc_otg_read_common_intr(dwc_otg_core_if_t * core_if, gintmsk_data_t *reenable_gintmsk, dwc_otg_hcd_t *hcd)
  65934. +{
  65935. + gahbcfg_data_t gahbcfg = {.d32 = 0 };
  65936. + gintsts_data_t gintsts;
  65937. + gintmsk_data_t gintmsk;
  65938. + gintmsk_data_t gintmsk_common = {.d32 = 0 };
  65939. + gintmsk_common.b.wkupintr = 1;
  65940. + gintmsk_common.b.sessreqintr = 1;
  65941. + gintmsk_common.b.conidstschng = 1;
  65942. + gintmsk_common.b.otgintr = 1;
  65943. + gintmsk_common.b.modemismatch = 1;
  65944. + gintmsk_common.b.disconnect = 1;
  65945. + gintmsk_common.b.usbsuspend = 1;
  65946. +#ifdef CONFIG_USB_DWC_OTG_LPM
  65947. + gintmsk_common.b.lpmtranrcvd = 1;
  65948. +#endif
  65949. + gintmsk_common.b.restoredone = 1;
  65950. + if(dwc_otg_is_device_mode(core_if))
  65951. + {
  65952. + /** @todo: The port interrupt occurs while in device
  65953. + * mode. Added code to CIL to clear the interrupt for now!
  65954. + */
  65955. + gintmsk_common.b.portintr = 1;
  65956. + }
  65957. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  65958. + gintmsk.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  65959. + if(fiq_enable) {
  65960. + local_fiq_disable();
  65961. + /* Pull in the interrupts that the FIQ has masked */
  65962. + gintmsk.d32 |= ~(hcd->fiq_state->gintmsk_saved.d32);
  65963. + /* for the upstairs function to reenable - have to read it here in case FIQ triggers again */
  65964. + reenable_gintmsk->d32 |= gintmsk.d32;
  65965. + reenable_gintmsk->d32 |= ~(hcd->fiq_state->gintmsk_saved.d32);
  65966. + reenable_gintmsk->d32 &= gintmsk_common.d32;
  65967. + local_fiq_enable();
  65968. + }
  65969. +
  65970. + gahbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gahbcfg);
  65971. +
  65972. +#ifdef DEBUG
  65973. + /* if any common interrupts set */
  65974. + if (gintsts.d32 & gintmsk_common.d32) {
  65975. + DWC_DEBUGPL(DBG_ANY, "common_intr: gintsts=%08x gintmsk=%08x\n",
  65976. + gintsts.d32, gintmsk.d32);
  65977. + }
  65978. +#endif
  65979. + if (!fiq_enable){
  65980. + if (gahbcfg.b.glblintrmsk)
  65981. + return ((gintsts.d32 & gintmsk.d32) & gintmsk_common.d32);
  65982. + else
  65983. + return 0;
  65984. + } else {
  65985. + /* Our IRQ kicker is no longer the USB hardware, it's the MPHI interface.
  65986. + * Can't trust the global interrupt mask bit in this case.
  65987. + */
  65988. + return ((gintsts.d32 & gintmsk.d32) & gintmsk_common.d32);
  65989. + }
  65990. +
  65991. +}
  65992. +
  65993. +/* MACRO for clearing interupt bits in GPWRDN register */
  65994. +#define CLEAR_GPWRDN_INTR(__core_if,__intr) \
  65995. +do { \
  65996. + gpwrdn_data_t gpwrdn = {.d32=0}; \
  65997. + gpwrdn.b.__intr = 1; \
  65998. + DWC_MODIFY_REG32(&__core_if->core_global_regs->gpwrdn, \
  65999. + 0, gpwrdn.d32); \
  66000. +} while (0)
  66001. +
  66002. +/**
  66003. + * Common interrupt handler.
  66004. + *
  66005. + * The common interrupts are those that occur in both Host and Device mode.
  66006. + * This handler handles the following interrupts:
  66007. + * - Mode Mismatch Interrupt
  66008. + * - Disconnect Interrupt
  66009. + * - OTG Interrupt
  66010. + * - Connector ID Status Change Interrupt
  66011. + * - Session Request Interrupt.
  66012. + * - Resume / Remote Wakeup Detected Interrupt.
  66013. + * - LPM Transaction Received Interrupt
  66014. + * - ADP Transaction Received Interrupt
  66015. + *
  66016. + */
  66017. +int32_t dwc_otg_handle_common_intr(void *dev)
  66018. +{
  66019. + int retval = 0;
  66020. + gintsts_data_t gintsts;
  66021. + gintmsk_data_t gintmsk_reenable = { .d32 = 0 };
  66022. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  66023. + dwc_otg_device_t *otg_dev = dev;
  66024. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  66025. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  66026. + if (dwc_otg_is_device_mode(core_if))
  66027. + core_if->frame_num = dwc_otg_get_frame_number(core_if);
  66028. +
  66029. + if (core_if->lock)
  66030. + DWC_SPINLOCK(core_if->lock);
  66031. +
  66032. + if (core_if->power_down == 3 && core_if->xhib == 1) {
  66033. + DWC_DEBUGPL(DBG_ANY, "Exiting from xHIB state\n");
  66034. + retval |= dwc_otg_handle_xhib_exit_intr(core_if);
  66035. + core_if->xhib = 2;
  66036. + if (core_if->lock)
  66037. + DWC_SPINUNLOCK(core_if->lock);
  66038. +
  66039. + return retval;
  66040. + }
  66041. +
  66042. + if (core_if->hibernation_suspend <= 0) {
  66043. + /* read_common will have to poke the FIQ's saved mask. We must then clear this mask at the end
  66044. + * of this handler - god only knows why it's done like this
  66045. + */
  66046. + gintsts.d32 = dwc_otg_read_common_intr(core_if, &gintmsk_reenable, otg_dev->hcd);
  66047. +
  66048. + if (gintsts.b.modemismatch) {
  66049. + retval |= dwc_otg_handle_mode_mismatch_intr(core_if);
  66050. + }
  66051. + if (gintsts.b.otgintr) {
  66052. + retval |= dwc_otg_handle_otg_intr(core_if);
  66053. + }
  66054. + if (gintsts.b.conidstschng) {
  66055. + retval |=
  66056. + dwc_otg_handle_conn_id_status_change_intr(core_if);
  66057. + }
  66058. + if (gintsts.b.disconnect) {
  66059. + retval |= dwc_otg_handle_disconnect_intr(core_if);
  66060. + }
  66061. + if (gintsts.b.sessreqintr) {
  66062. + retval |= dwc_otg_handle_session_req_intr(core_if);
  66063. + }
  66064. + if (gintsts.b.wkupintr) {
  66065. + retval |= dwc_otg_handle_wakeup_detected_intr(core_if);
  66066. + }
  66067. + if (gintsts.b.usbsuspend) {
  66068. + retval |= dwc_otg_handle_usb_suspend_intr(core_if);
  66069. + }
  66070. +#ifdef CONFIG_USB_DWC_OTG_LPM
  66071. + if (gintsts.b.lpmtranrcvd) {
  66072. + retval |= dwc_otg_handle_lpm_intr(core_if);
  66073. + }
  66074. +#endif
  66075. + if (gintsts.b.restoredone) {
  66076. + gintsts.d32 = 0;
  66077. + if (core_if->power_down == 2)
  66078. + core_if->hibernation_suspend = -1;
  66079. + else if (core_if->power_down == 3 && core_if->xhib == 2) {
  66080. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  66081. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  66082. + dctl_data_t dctl = {.d32 = 0 };
  66083. +
  66084. + DWC_WRITE_REG32(&core_if->core_global_regs->
  66085. + gintsts, 0xFFFFFFFF);
  66086. +
  66087. + DWC_DEBUGPL(DBG_ANY,
  66088. + "RESTORE DONE generated\n");
  66089. +
  66090. + gpwrdn.b.restore = 1;
  66091. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  66092. + dwc_udelay(10);
  66093. +
  66094. + pcgcctl.b.rstpdwnmodule = 1;
  66095. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  66096. +
  66097. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, core_if->gr_backup->gusbcfg_local);
  66098. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, core_if->dr_backup->dcfg);
  66099. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, core_if->dr_backup->dctl);
  66100. + dwc_udelay(50);
  66101. +
  66102. + dctl.b.pwronprgdone = 1;
  66103. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  66104. + dwc_udelay(10);
  66105. +
  66106. + dwc_otg_restore_global_regs(core_if);
  66107. + dwc_otg_restore_dev_regs(core_if, 0);
  66108. +
  66109. + dctl.d32 = 0;
  66110. + dctl.b.pwronprgdone = 1;
  66111. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, 0);
  66112. + dwc_udelay(10);
  66113. +
  66114. + pcgcctl.d32 = 0;
  66115. + pcgcctl.b.enbl_extnd_hiber = 1;
  66116. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  66117. +
  66118. + /* The core will be in ON STATE */
  66119. + core_if->lx_state = DWC_OTG_L0;
  66120. + core_if->xhib = 0;
  66121. +
  66122. + DWC_SPINUNLOCK(core_if->lock);
  66123. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  66124. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  66125. + }
  66126. + DWC_SPINLOCK(core_if->lock);
  66127. +
  66128. + }
  66129. +
  66130. + gintsts.b.restoredone = 1;
  66131. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts,gintsts.d32);
  66132. + DWC_PRINTF(" --Restore done interrupt received-- \n");
  66133. + retval |= 1;
  66134. + }
  66135. + if (gintsts.b.portintr && dwc_otg_is_device_mode(core_if)) {
  66136. + /* The port interrupt occurs while in device mode with HPRT0
  66137. + * Port Enable/Disable.
  66138. + */
  66139. + gintsts.d32 = 0;
  66140. + gintsts.b.portintr = 1;
  66141. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts,gintsts.d32);
  66142. + retval |= 1;
  66143. + gintmsk_reenable.b.portintr = 1;
  66144. +
  66145. + }
  66146. + /* Did we actually handle anything? if so, unmask the interrupt */
  66147. +// fiq_print(FIQDBG_INT, otg_dev->hcd->fiq_state, "CILOUT %1d", retval);
  66148. +// fiq_print(FIQDBG_INT, otg_dev->hcd->fiq_state, "%08x", gintsts.d32);
  66149. +// fiq_print(FIQDBG_INT, otg_dev->hcd->fiq_state, "%08x", gintmsk_reenable.d32);
  66150. + if (retval) {
  66151. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk_reenable.d32);
  66152. + }
  66153. +
  66154. + } else {
  66155. + DWC_DEBUGPL(DBG_ANY, "gpwrdn=%08x\n", gpwrdn.d32);
  66156. +
  66157. + if (gpwrdn.b.disconn_det && gpwrdn.b.disconn_det_msk) {
  66158. + CLEAR_GPWRDN_INTR(core_if, disconn_det);
  66159. + if (gpwrdn.b.linestate == 0) {
  66160. + dwc_otg_handle_pwrdn_disconnect_intr(core_if);
  66161. + } else {
  66162. + DWC_PRINTF("Disconnect detected while linestate is not 0\n");
  66163. + }
  66164. +
  66165. + retval |= 1;
  66166. + }
  66167. + if (gpwrdn.b.lnstschng && gpwrdn.b.lnstchng_msk) {
  66168. + CLEAR_GPWRDN_INTR(core_if, lnstschng);
  66169. + /* remote wakeup from hibernation */
  66170. + if (gpwrdn.b.linestate == 2 || gpwrdn.b.linestate == 1) {
  66171. + dwc_otg_handle_pwrdn_wakeup_detected_intr(core_if);
  66172. + } else {
  66173. + DWC_PRINTF("gpwrdn.linestate = %d\n", gpwrdn.b.linestate);
  66174. + }
  66175. + retval |= 1;
  66176. + }
  66177. + if (gpwrdn.b.rst_det && gpwrdn.b.rst_det_msk) {
  66178. + CLEAR_GPWRDN_INTR(core_if, rst_det);
  66179. + if (gpwrdn.b.linestate == 0) {
  66180. + DWC_PRINTF("Reset detected\n");
  66181. + retval |= dwc_otg_device_hibernation_restore(core_if, 0, 1);
  66182. + }
  66183. + }
  66184. + if (gpwrdn.b.srp_det && gpwrdn.b.srp_det_msk) {
  66185. + CLEAR_GPWRDN_INTR(core_if, srp_det);
  66186. + dwc_otg_handle_pwrdn_srp_intr(core_if);
  66187. + retval |= 1;
  66188. + }
  66189. + }
  66190. + /* Handle ADP interrupt here */
  66191. + if (gpwrdn.b.adp_int) {
  66192. + DWC_PRINTF("ADP interrupt\n");
  66193. + CLEAR_GPWRDN_INTR(core_if, adp_int);
  66194. + dwc_otg_adp_handle_intr(core_if);
  66195. + retval |= 1;
  66196. + }
  66197. + if (gpwrdn.b.sts_chngint && gpwrdn.b.sts_chngint_msk) {
  66198. + DWC_PRINTF("STS CHNG interrupt asserted\n");
  66199. + CLEAR_GPWRDN_INTR(core_if, sts_chngint);
  66200. + dwc_otg_handle_pwrdn_stschng_intr(otg_dev);
  66201. +
  66202. + retval |= 1;
  66203. + }
  66204. + if (core_if->lock)
  66205. + DWC_SPINUNLOCK(core_if->lock);
  66206. + return retval;
  66207. +}
  66208. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_core_if.h linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_core_if.h
  66209. --- linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_core_if.h 1970-01-01 01:00:00.000000000 +0100
  66210. +++ linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_core_if.h 2014-08-06 16:50:14.801964726 +0200
  66211. @@ -0,0 +1,705 @@
  66212. +/* ==========================================================================
  66213. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_core_if.h $
  66214. + * $Revision: #13 $
  66215. + * $Date: 2012/08/10 $
  66216. + * $Change: 2047372 $
  66217. + *
  66218. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  66219. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  66220. + * otherwise expressly agreed to in writing between Synopsys and you.
  66221. + *
  66222. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  66223. + * any End User Software License Agreement or Agreement for Licensed Product
  66224. + * with Synopsys or any supplement thereto. You are permitted to use and
  66225. + * redistribute this Software in source and binary forms, with or without
  66226. + * modification, provided that redistributions of source code must retain this
  66227. + * notice. You may not view, use, disclose, copy or distribute this file or
  66228. + * any information contained herein except pursuant to this license grant from
  66229. + * Synopsys. If you do not agree with this notice, including the disclaimer
  66230. + * below, then you are not authorized to use the Software.
  66231. + *
  66232. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  66233. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  66234. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  66235. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  66236. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  66237. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  66238. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  66239. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  66240. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  66241. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  66242. + * DAMAGE.
  66243. + * ========================================================================== */
  66244. +#if !defined(__DWC_CORE_IF_H__)
  66245. +#define __DWC_CORE_IF_H__
  66246. +
  66247. +#include "dwc_os.h"
  66248. +
  66249. +/** @file
  66250. + * This file defines DWC_OTG Core API
  66251. + */
  66252. +
  66253. +struct dwc_otg_core_if;
  66254. +typedef struct dwc_otg_core_if dwc_otg_core_if_t;
  66255. +
  66256. +/** Maximum number of Periodic FIFOs */
  66257. +#define MAX_PERIO_FIFOS 15
  66258. +/** Maximum number of Periodic FIFOs */
  66259. +#define MAX_TX_FIFOS 15
  66260. +
  66261. +/** Maximum number of Endpoints/HostChannels */
  66262. +#define MAX_EPS_CHANNELS 16
  66263. +
  66264. +extern dwc_otg_core_if_t *dwc_otg_cil_init(const uint32_t * _reg_base_addr);
  66265. +extern void dwc_otg_core_init(dwc_otg_core_if_t * _core_if);
  66266. +extern void dwc_otg_cil_remove(dwc_otg_core_if_t * _core_if);
  66267. +
  66268. +extern void dwc_otg_enable_global_interrupts(dwc_otg_core_if_t * _core_if);
  66269. +extern void dwc_otg_disable_global_interrupts(dwc_otg_core_if_t * _core_if);
  66270. +
  66271. +extern uint8_t dwc_otg_is_device_mode(dwc_otg_core_if_t * _core_if);
  66272. +extern uint8_t dwc_otg_is_host_mode(dwc_otg_core_if_t * _core_if);
  66273. +
  66274. +extern uint8_t dwc_otg_is_dma_enable(dwc_otg_core_if_t * core_if);
  66275. +
  66276. +/** This function should be called on every hardware interrupt. */
  66277. +extern int32_t dwc_otg_handle_common_intr(void *otg_dev);
  66278. +
  66279. +/** @name OTG Core Parameters */
  66280. +/** @{ */
  66281. +
  66282. +/**
  66283. + * Specifies the OTG capabilities. The driver will automatically
  66284. + * detect the value for this parameter if none is specified.
  66285. + * 0 - HNP and SRP capable (default)
  66286. + * 1 - SRP Only capable
  66287. + * 2 - No HNP/SRP capable
  66288. + */
  66289. +extern int dwc_otg_set_param_otg_cap(dwc_otg_core_if_t * core_if, int32_t val);
  66290. +extern int32_t dwc_otg_get_param_otg_cap(dwc_otg_core_if_t * core_if);
  66291. +#define DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE 0
  66292. +#define DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE 1
  66293. +#define DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE 2
  66294. +#define dwc_param_otg_cap_default DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE
  66295. +
  66296. +extern int dwc_otg_set_param_opt(dwc_otg_core_if_t * core_if, int32_t val);
  66297. +extern int32_t dwc_otg_get_param_opt(dwc_otg_core_if_t * core_if);
  66298. +#define dwc_param_opt_default 1
  66299. +
  66300. +/**
  66301. + * Specifies whether to use slave or DMA mode for accessing the data
  66302. + * FIFOs. The driver will automatically detect the value for this
  66303. + * parameter if none is specified.
  66304. + * 0 - Slave
  66305. + * 1 - DMA (default, if available)
  66306. + */
  66307. +extern int dwc_otg_set_param_dma_enable(dwc_otg_core_if_t * core_if,
  66308. + int32_t val);
  66309. +extern int32_t dwc_otg_get_param_dma_enable(dwc_otg_core_if_t * core_if);
  66310. +#define dwc_param_dma_enable_default 1
  66311. +
  66312. +/**
  66313. + * When DMA mode is enabled specifies whether to use
  66314. + * address DMA or DMA Descritor mode for accessing the data
  66315. + * FIFOs in device mode. The driver will automatically detect
  66316. + * the value for this parameter if none is specified.
  66317. + * 0 - address DMA
  66318. + * 1 - DMA Descriptor(default, if available)
  66319. + */
  66320. +extern int dwc_otg_set_param_dma_desc_enable(dwc_otg_core_if_t * core_if,
  66321. + int32_t val);
  66322. +extern int32_t dwc_otg_get_param_dma_desc_enable(dwc_otg_core_if_t * core_if);
  66323. +//#define dwc_param_dma_desc_enable_default 1
  66324. +#define dwc_param_dma_desc_enable_default 0 // Broadcom BCM2708
  66325. +
  66326. +/** The DMA Burst size (applicable only for External DMA
  66327. + * Mode). 1, 4, 8 16, 32, 64, 128, 256 (default 32)
  66328. + */
  66329. +extern int dwc_otg_set_param_dma_burst_size(dwc_otg_core_if_t * core_if,
  66330. + int32_t val);
  66331. +extern int32_t dwc_otg_get_param_dma_burst_size(dwc_otg_core_if_t * core_if);
  66332. +#define dwc_param_dma_burst_size_default 32
  66333. +
  66334. +/**
  66335. + * Specifies the maximum speed of operation in host and device mode.
  66336. + * The actual speed depends on the speed of the attached device and
  66337. + * the value of phy_type. The actual speed depends on the speed of the
  66338. + * attached device.
  66339. + * 0 - High Speed (default)
  66340. + * 1 - Full Speed
  66341. + */
  66342. +extern int dwc_otg_set_param_speed(dwc_otg_core_if_t * core_if, int32_t val);
  66343. +extern int32_t dwc_otg_get_param_speed(dwc_otg_core_if_t * core_if);
  66344. +#define dwc_param_speed_default 0
  66345. +#define DWC_SPEED_PARAM_HIGH 0
  66346. +#define DWC_SPEED_PARAM_FULL 1
  66347. +
  66348. +/** Specifies whether low power mode is supported when attached
  66349. + * to a Full Speed or Low Speed device in host mode.
  66350. + * 0 - Don't support low power mode (default)
  66351. + * 1 - Support low power mode
  66352. + */
  66353. +extern int dwc_otg_set_param_host_support_fs_ls_low_power(dwc_otg_core_if_t *
  66354. + core_if, int32_t val);
  66355. +extern int32_t dwc_otg_get_param_host_support_fs_ls_low_power(dwc_otg_core_if_t
  66356. + * core_if);
  66357. +#define dwc_param_host_support_fs_ls_low_power_default 0
  66358. +
  66359. +/** Specifies the PHY clock rate in low power mode when connected to a
  66360. + * Low Speed device in host mode. This parameter is applicable only if
  66361. + * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
  66362. + * then defaults to 6 MHZ otherwise 48 MHZ.
  66363. + *
  66364. + * 0 - 48 MHz
  66365. + * 1 - 6 MHz
  66366. + */
  66367. +extern int dwc_otg_set_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t *
  66368. + core_if, int32_t val);
  66369. +extern int32_t dwc_otg_get_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t *
  66370. + core_if);
  66371. +#define dwc_param_host_ls_low_power_phy_clk_default 0
  66372. +#define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ 0
  66373. +#define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ 1
  66374. +
  66375. +/**
  66376. + * 0 - Use cC FIFO size parameters
  66377. + * 1 - Allow dynamic FIFO sizing (default)
  66378. + */
  66379. +extern int dwc_otg_set_param_enable_dynamic_fifo(dwc_otg_core_if_t * core_if,
  66380. + int32_t val);
  66381. +extern int32_t dwc_otg_get_param_enable_dynamic_fifo(dwc_otg_core_if_t *
  66382. + core_if);
  66383. +#define dwc_param_enable_dynamic_fifo_default 1
  66384. +
  66385. +/** Total number of 4-byte words in the data FIFO memory. This
  66386. + * memory includes the Rx FIFO, non-periodic Tx FIFO, and periodic
  66387. + * Tx FIFOs.
  66388. + * 32 to 32768 (default 8192)
  66389. + * Note: The total FIFO memory depth in the FPGA configuration is 8192.
  66390. + */
  66391. +extern int dwc_otg_set_param_data_fifo_size(dwc_otg_core_if_t * core_if,
  66392. + int32_t val);
  66393. +extern int32_t dwc_otg_get_param_data_fifo_size(dwc_otg_core_if_t * core_if);
  66394. +//#define dwc_param_data_fifo_size_default 8192
  66395. +#define dwc_param_data_fifo_size_default 0xFF0 // Broadcom BCM2708
  66396. +
  66397. +/** Number of 4-byte words in the Rx FIFO in device mode when dynamic
  66398. + * FIFO sizing is enabled.
  66399. + * 16 to 32768 (default 1064)
  66400. + */
  66401. +extern int dwc_otg_set_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if,
  66402. + int32_t val);
  66403. +extern int32_t dwc_otg_get_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if);
  66404. +#define dwc_param_dev_rx_fifo_size_default 1064
  66405. +
  66406. +/** Number of 4-byte words in the non-periodic Tx FIFO in device mode
  66407. + * when dynamic FIFO sizing is enabled.
  66408. + * 16 to 32768 (default 1024)
  66409. + */
  66410. +extern int dwc_otg_set_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t *
  66411. + core_if, int32_t val);
  66412. +extern int32_t dwc_otg_get_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t *
  66413. + core_if);
  66414. +#define dwc_param_dev_nperio_tx_fifo_size_default 1024
  66415. +
  66416. +/** Number of 4-byte words in each of the periodic Tx FIFOs in device
  66417. + * mode when dynamic FIFO sizing is enabled.
  66418. + * 4 to 768 (default 256)
  66419. + */
  66420. +extern int dwc_otg_set_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  66421. + int32_t val, int fifo_num);
  66422. +extern int32_t dwc_otg_get_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t *
  66423. + core_if, int fifo_num);
  66424. +#define dwc_param_dev_perio_tx_fifo_size_default 256
  66425. +
  66426. +/** Number of 4-byte words in the Rx FIFO in host mode when dynamic
  66427. + * FIFO sizing is enabled.
  66428. + * 16 to 32768 (default 1024)
  66429. + */
  66430. +extern int dwc_otg_set_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if,
  66431. + int32_t val);
  66432. +extern int32_t dwc_otg_get_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if);
  66433. +//#define dwc_param_host_rx_fifo_size_default 1024
  66434. +#define dwc_param_host_rx_fifo_size_default 774 // Broadcom BCM2708
  66435. +
  66436. +/** Number of 4-byte words in the non-periodic Tx FIFO in host mode
  66437. + * when Dynamic FIFO sizing is enabled in the core.
  66438. + * 16 to 32768 (default 1024)
  66439. + */
  66440. +extern int dwc_otg_set_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t *
  66441. + core_if, int32_t val);
  66442. +extern int32_t dwc_otg_get_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t *
  66443. + core_if);
  66444. +//#define dwc_param_host_nperio_tx_fifo_size_default 1024
  66445. +#define dwc_param_host_nperio_tx_fifo_size_default 0x100 // Broadcom BCM2708
  66446. +
  66447. +/** Number of 4-byte words in the host periodic Tx FIFO when dynamic
  66448. + * FIFO sizing is enabled.
  66449. + * 16 to 32768 (default 1024)
  66450. + */
  66451. +extern int dwc_otg_set_param_host_perio_tx_fifo_size(dwc_otg_core_if_t *
  66452. + core_if, int32_t val);
  66453. +extern int32_t dwc_otg_get_param_host_perio_tx_fifo_size(dwc_otg_core_if_t *
  66454. + core_if);
  66455. +//#define dwc_param_host_perio_tx_fifo_size_default 1024
  66456. +#define dwc_param_host_perio_tx_fifo_size_default 0x200 // Broadcom BCM2708
  66457. +
  66458. +/** The maximum transfer size supported in bytes.
  66459. + * 2047 to 65,535 (default 65,535)
  66460. + */
  66461. +extern int dwc_otg_set_param_max_transfer_size(dwc_otg_core_if_t * core_if,
  66462. + int32_t val);
  66463. +extern int32_t dwc_otg_get_param_max_transfer_size(dwc_otg_core_if_t * core_if);
  66464. +#define dwc_param_max_transfer_size_default 65535
  66465. +
  66466. +/** The maximum number of packets in a transfer.
  66467. + * 15 to 511 (default 511)
  66468. + */
  66469. +extern int dwc_otg_set_param_max_packet_count(dwc_otg_core_if_t * core_if,
  66470. + int32_t val);
  66471. +extern int32_t dwc_otg_get_param_max_packet_count(dwc_otg_core_if_t * core_if);
  66472. +#define dwc_param_max_packet_count_default 511
  66473. +
  66474. +/** The number of host channel registers to use.
  66475. + * 1 to 16 (default 12)
  66476. + * Note: The FPGA configuration supports a maximum of 12 host channels.
  66477. + */
  66478. +extern int dwc_otg_set_param_host_channels(dwc_otg_core_if_t * core_if,
  66479. + int32_t val);
  66480. +extern int32_t dwc_otg_get_param_host_channels(dwc_otg_core_if_t * core_if);
  66481. +//#define dwc_param_host_channels_default 12
  66482. +#define dwc_param_host_channels_default 8 // Broadcom BCM2708
  66483. +
  66484. +/** The number of endpoints in addition to EP0 available for device
  66485. + * mode operations.
  66486. + * 1 to 15 (default 6 IN and OUT)
  66487. + * Note: The FPGA configuration supports a maximum of 6 IN and OUT
  66488. + * endpoints in addition to EP0.
  66489. + */
  66490. +extern int dwc_otg_set_param_dev_endpoints(dwc_otg_core_if_t * core_if,
  66491. + int32_t val);
  66492. +extern int32_t dwc_otg_get_param_dev_endpoints(dwc_otg_core_if_t * core_if);
  66493. +#define dwc_param_dev_endpoints_default 6
  66494. +
  66495. +/**
  66496. + * Specifies the type of PHY interface to use. By default, the driver
  66497. + * will automatically detect the phy_type.
  66498. + *
  66499. + * 0 - Full Speed PHY
  66500. + * 1 - UTMI+ (default)
  66501. + * 2 - ULPI
  66502. + */
  66503. +extern int dwc_otg_set_param_phy_type(dwc_otg_core_if_t * core_if, int32_t val);
  66504. +extern int32_t dwc_otg_get_param_phy_type(dwc_otg_core_if_t * core_if);
  66505. +#define DWC_PHY_TYPE_PARAM_FS 0
  66506. +#define DWC_PHY_TYPE_PARAM_UTMI 1
  66507. +#define DWC_PHY_TYPE_PARAM_ULPI 2
  66508. +#define dwc_param_phy_type_default DWC_PHY_TYPE_PARAM_UTMI
  66509. +
  66510. +/**
  66511. + * Specifies the UTMI+ Data Width. This parameter is
  66512. + * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
  66513. + * PHY_TYPE, this parameter indicates the data width between
  66514. + * the MAC and the ULPI Wrapper.) Also, this parameter is
  66515. + * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
  66516. + * to "8 and 16 bits", meaning that the core has been
  66517. + * configured to work at either data path width.
  66518. + *
  66519. + * 8 or 16 bits (default 16)
  66520. + */
  66521. +extern int dwc_otg_set_param_phy_utmi_width(dwc_otg_core_if_t * core_if,
  66522. + int32_t val);
  66523. +extern int32_t dwc_otg_get_param_phy_utmi_width(dwc_otg_core_if_t * core_if);
  66524. +//#define dwc_param_phy_utmi_width_default 16
  66525. +#define dwc_param_phy_utmi_width_default 8 // Broadcom BCM2708
  66526. +
  66527. +/**
  66528. + * Specifies whether the ULPI operates at double or single
  66529. + * data rate. This parameter is only applicable if PHY_TYPE is
  66530. + * ULPI.
  66531. + *
  66532. + * 0 - single data rate ULPI interface with 8 bit wide data
  66533. + * bus (default)
  66534. + * 1 - double data rate ULPI interface with 4 bit wide data
  66535. + * bus
  66536. + */
  66537. +extern int dwc_otg_set_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if,
  66538. + int32_t val);
  66539. +extern int32_t dwc_otg_get_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if);
  66540. +#define dwc_param_phy_ulpi_ddr_default 0
  66541. +
  66542. +/**
  66543. + * Specifies whether to use the internal or external supply to
  66544. + * drive the vbus with a ULPI phy.
  66545. + */
  66546. +extern int dwc_otg_set_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if,
  66547. + int32_t val);
  66548. +extern int32_t dwc_otg_get_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if);
  66549. +#define DWC_PHY_ULPI_INTERNAL_VBUS 0
  66550. +#define DWC_PHY_ULPI_EXTERNAL_VBUS 1
  66551. +#define dwc_param_phy_ulpi_ext_vbus_default DWC_PHY_ULPI_INTERNAL_VBUS
  66552. +
  66553. +/**
  66554. + * Specifies whether to use the I2Cinterface for full speed PHY. This
  66555. + * parameter is only applicable if PHY_TYPE is FS.
  66556. + * 0 - No (default)
  66557. + * 1 - Yes
  66558. + */
  66559. +extern int dwc_otg_set_param_i2c_enable(dwc_otg_core_if_t * core_if,
  66560. + int32_t val);
  66561. +extern int32_t dwc_otg_get_param_i2c_enable(dwc_otg_core_if_t * core_if);
  66562. +#define dwc_param_i2c_enable_default 0
  66563. +
  66564. +extern int dwc_otg_set_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if,
  66565. + int32_t val);
  66566. +extern int32_t dwc_otg_get_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if);
  66567. +#define dwc_param_ulpi_fs_ls_default 0
  66568. +
  66569. +extern int dwc_otg_set_param_ts_dline(dwc_otg_core_if_t * core_if, int32_t val);
  66570. +extern int32_t dwc_otg_get_param_ts_dline(dwc_otg_core_if_t * core_if);
  66571. +#define dwc_param_ts_dline_default 0
  66572. +
  66573. +/**
  66574. + * Specifies whether dedicated transmit FIFOs are
  66575. + * enabled for non periodic IN endpoints in device mode
  66576. + * 0 - No
  66577. + * 1 - Yes
  66578. + */
  66579. +extern int dwc_otg_set_param_en_multiple_tx_fifo(dwc_otg_core_if_t * core_if,
  66580. + int32_t val);
  66581. +extern int32_t dwc_otg_get_param_en_multiple_tx_fifo(dwc_otg_core_if_t *
  66582. + core_if);
  66583. +#define dwc_param_en_multiple_tx_fifo_default 1
  66584. +
  66585. +/** Number of 4-byte words in each of the Tx FIFOs in device
  66586. + * mode when dynamic FIFO sizing is enabled.
  66587. + * 4 to 768 (default 256)
  66588. + */
  66589. +extern int dwc_otg_set_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if,
  66590. + int fifo_num, int32_t val);
  66591. +extern int32_t dwc_otg_get_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if,
  66592. + int fifo_num);
  66593. +#define dwc_param_dev_tx_fifo_size_default 768
  66594. +
  66595. +/** Thresholding enable flag-
  66596. + * bit 0 - enable non-ISO Tx thresholding
  66597. + * bit 1 - enable ISO Tx thresholding
  66598. + * bit 2 - enable Rx thresholding
  66599. + */
  66600. +extern int dwc_otg_set_param_thr_ctl(dwc_otg_core_if_t * core_if, int32_t val);
  66601. +extern int32_t dwc_otg_get_thr_ctl(dwc_otg_core_if_t * core_if, int fifo_num);
  66602. +#define dwc_param_thr_ctl_default 0
  66603. +
  66604. +/** Thresholding length for Tx
  66605. + * FIFOs in 32 bit DWORDs
  66606. + */
  66607. +extern int dwc_otg_set_param_tx_thr_length(dwc_otg_core_if_t * core_if,
  66608. + int32_t val);
  66609. +extern int32_t dwc_otg_get_tx_thr_length(dwc_otg_core_if_t * core_if);
  66610. +#define dwc_param_tx_thr_length_default 64
  66611. +
  66612. +/** Thresholding length for Rx
  66613. + * FIFOs in 32 bit DWORDs
  66614. + */
  66615. +extern int dwc_otg_set_param_rx_thr_length(dwc_otg_core_if_t * core_if,
  66616. + int32_t val);
  66617. +extern int32_t dwc_otg_get_rx_thr_length(dwc_otg_core_if_t * core_if);
  66618. +#define dwc_param_rx_thr_length_default 64
  66619. +
  66620. +/**
  66621. + * Specifies whether LPM (Link Power Management) support is enabled
  66622. + */
  66623. +extern int dwc_otg_set_param_lpm_enable(dwc_otg_core_if_t * core_if,
  66624. + int32_t val);
  66625. +extern int32_t dwc_otg_get_param_lpm_enable(dwc_otg_core_if_t * core_if);
  66626. +#define dwc_param_lpm_enable_default 1
  66627. +
  66628. +/**
  66629. + * Specifies whether PTI enhancement is enabled
  66630. + */
  66631. +extern int dwc_otg_set_param_pti_enable(dwc_otg_core_if_t * core_if,
  66632. + int32_t val);
  66633. +extern int32_t dwc_otg_get_param_pti_enable(dwc_otg_core_if_t * core_if);
  66634. +#define dwc_param_pti_enable_default 0
  66635. +
  66636. +/**
  66637. + * Specifies whether MPI enhancement is enabled
  66638. + */
  66639. +extern int dwc_otg_set_param_mpi_enable(dwc_otg_core_if_t * core_if,
  66640. + int32_t val);
  66641. +extern int32_t dwc_otg_get_param_mpi_enable(dwc_otg_core_if_t * core_if);
  66642. +#define dwc_param_mpi_enable_default 0
  66643. +
  66644. +/**
  66645. + * Specifies whether ADP capability is enabled
  66646. + */
  66647. +extern int dwc_otg_set_param_adp_enable(dwc_otg_core_if_t * core_if,
  66648. + int32_t val);
  66649. +extern int32_t dwc_otg_get_param_adp_enable(dwc_otg_core_if_t * core_if);
  66650. +#define dwc_param_adp_enable_default 0
  66651. +
  66652. +/**
  66653. + * Specifies whether IC_USB capability is enabled
  66654. + */
  66655. +
  66656. +extern int dwc_otg_set_param_ic_usb_cap(dwc_otg_core_if_t * core_if,
  66657. + int32_t val);
  66658. +extern int32_t dwc_otg_get_param_ic_usb_cap(dwc_otg_core_if_t * core_if);
  66659. +#define dwc_param_ic_usb_cap_default 0
  66660. +
  66661. +extern int dwc_otg_set_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if,
  66662. + int32_t val);
  66663. +extern int32_t dwc_otg_get_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if);
  66664. +#define dwc_param_ahb_thr_ratio_default 0
  66665. +
  66666. +extern int dwc_otg_set_param_power_down(dwc_otg_core_if_t * core_if,
  66667. + int32_t val);
  66668. +extern int32_t dwc_otg_get_param_power_down(dwc_otg_core_if_t * core_if);
  66669. +#define dwc_param_power_down_default 0
  66670. +
  66671. +extern int dwc_otg_set_param_reload_ctl(dwc_otg_core_if_t * core_if,
  66672. + int32_t val);
  66673. +extern int32_t dwc_otg_get_param_reload_ctl(dwc_otg_core_if_t * core_if);
  66674. +#define dwc_param_reload_ctl_default 0
  66675. +
  66676. +extern int dwc_otg_set_param_dev_out_nak(dwc_otg_core_if_t * core_if,
  66677. + int32_t val);
  66678. +extern int32_t dwc_otg_get_param_dev_out_nak(dwc_otg_core_if_t * core_if);
  66679. +#define dwc_param_dev_out_nak_default 0
  66680. +
  66681. +extern int dwc_otg_set_param_cont_on_bna(dwc_otg_core_if_t * core_if,
  66682. + int32_t val);
  66683. +extern int32_t dwc_otg_get_param_cont_on_bna(dwc_otg_core_if_t * core_if);
  66684. +#define dwc_param_cont_on_bna_default 0
  66685. +
  66686. +extern int dwc_otg_set_param_ahb_single(dwc_otg_core_if_t * core_if,
  66687. + int32_t val);
  66688. +extern int32_t dwc_otg_get_param_ahb_single(dwc_otg_core_if_t * core_if);
  66689. +#define dwc_param_ahb_single_default 0
  66690. +
  66691. +extern int dwc_otg_set_param_otg_ver(dwc_otg_core_if_t * core_if, int32_t val);
  66692. +extern int32_t dwc_otg_get_param_otg_ver(dwc_otg_core_if_t * core_if);
  66693. +#define dwc_param_otg_ver_default 0
  66694. +
  66695. +/** @} */
  66696. +
  66697. +/** @name Access to registers and bit-fields */
  66698. +
  66699. +/**
  66700. + * Dump core registers and SPRAM
  66701. + */
  66702. +extern void dwc_otg_dump_dev_registers(dwc_otg_core_if_t * _core_if);
  66703. +extern void dwc_otg_dump_spram(dwc_otg_core_if_t * _core_if);
  66704. +extern void dwc_otg_dump_host_registers(dwc_otg_core_if_t * _core_if);
  66705. +extern void dwc_otg_dump_global_registers(dwc_otg_core_if_t * _core_if);
  66706. +
  66707. +/**
  66708. + * Get host negotiation status.
  66709. + */
  66710. +extern uint32_t dwc_otg_get_hnpstatus(dwc_otg_core_if_t * core_if);
  66711. +
  66712. +/**
  66713. + * Get srp status
  66714. + */
  66715. +extern uint32_t dwc_otg_get_srpstatus(dwc_otg_core_if_t * core_if);
  66716. +
  66717. +/**
  66718. + * Set hnpreq bit in the GOTGCTL register.
  66719. + */
  66720. +extern void dwc_otg_set_hnpreq(dwc_otg_core_if_t * core_if, uint32_t val);
  66721. +
  66722. +/**
  66723. + * Get Content of SNPSID register.
  66724. + */
  66725. +extern uint32_t dwc_otg_get_gsnpsid(dwc_otg_core_if_t * core_if);
  66726. +
  66727. +/**
  66728. + * Get current mode.
  66729. + * Returns 0 if in device mode, and 1 if in host mode.
  66730. + */
  66731. +extern uint32_t dwc_otg_get_mode(dwc_otg_core_if_t * core_if);
  66732. +
  66733. +/**
  66734. + * Get value of hnpcapable field in the GUSBCFG register
  66735. + */
  66736. +extern uint32_t dwc_otg_get_hnpcapable(dwc_otg_core_if_t * core_if);
  66737. +/**
  66738. + * Set value of hnpcapable field in the GUSBCFG register
  66739. + */
  66740. +extern void dwc_otg_set_hnpcapable(dwc_otg_core_if_t * core_if, uint32_t val);
  66741. +
  66742. +/**
  66743. + * Get value of srpcapable field in the GUSBCFG register
  66744. + */
  66745. +extern uint32_t dwc_otg_get_srpcapable(dwc_otg_core_if_t * core_if);
  66746. +/**
  66747. + * Set value of srpcapable field in the GUSBCFG register
  66748. + */
  66749. +extern void dwc_otg_set_srpcapable(dwc_otg_core_if_t * core_if, uint32_t val);
  66750. +
  66751. +/**
  66752. + * Get value of devspeed field in the DCFG register
  66753. + */
  66754. +extern uint32_t dwc_otg_get_devspeed(dwc_otg_core_if_t * core_if);
  66755. +/**
  66756. + * Set value of devspeed field in the DCFG register
  66757. + */
  66758. +extern void dwc_otg_set_devspeed(dwc_otg_core_if_t * core_if, uint32_t val);
  66759. +
  66760. +/**
  66761. + * Get the value of busconnected field from the HPRT0 register
  66762. + */
  66763. +extern uint32_t dwc_otg_get_busconnected(dwc_otg_core_if_t * core_if);
  66764. +
  66765. +/**
  66766. + * Gets the device enumeration Speed.
  66767. + */
  66768. +extern uint32_t dwc_otg_get_enumspeed(dwc_otg_core_if_t * core_if);
  66769. +
  66770. +/**
  66771. + * Get value of prtpwr field from the HPRT0 register
  66772. + */
  66773. +extern uint32_t dwc_otg_get_prtpower(dwc_otg_core_if_t * core_if);
  66774. +
  66775. +/**
  66776. + * Get value of flag indicating core state - hibernated or not
  66777. + */
  66778. +extern uint32_t dwc_otg_get_core_state(dwc_otg_core_if_t * core_if);
  66779. +
  66780. +/**
  66781. + * Set value of prtpwr field from the HPRT0 register
  66782. + */
  66783. +extern void dwc_otg_set_prtpower(dwc_otg_core_if_t * core_if, uint32_t val);
  66784. +
  66785. +/**
  66786. + * Get value of prtsusp field from the HPRT0 regsiter
  66787. + */
  66788. +extern uint32_t dwc_otg_get_prtsuspend(dwc_otg_core_if_t * core_if);
  66789. +/**
  66790. + * Set value of prtpwr field from the HPRT0 register
  66791. + */
  66792. +extern void dwc_otg_set_prtsuspend(dwc_otg_core_if_t * core_if, uint32_t val);
  66793. +
  66794. +/**
  66795. + * Get value of ModeChTimEn field from the HCFG regsiter
  66796. + */
  66797. +extern uint32_t dwc_otg_get_mode_ch_tim(dwc_otg_core_if_t * core_if);
  66798. +/**
  66799. + * Set value of ModeChTimEn field from the HCFG regsiter
  66800. + */
  66801. +extern void dwc_otg_set_mode_ch_tim(dwc_otg_core_if_t * core_if, uint32_t val);
  66802. +
  66803. +/**
  66804. + * Get value of Fram Interval field from the HFIR regsiter
  66805. + */
  66806. +extern uint32_t dwc_otg_get_fr_interval(dwc_otg_core_if_t * core_if);
  66807. +/**
  66808. + * Set value of Frame Interval field from the HFIR regsiter
  66809. + */
  66810. +extern void dwc_otg_set_fr_interval(dwc_otg_core_if_t * core_if, uint32_t val);
  66811. +
  66812. +/**
  66813. + * Set value of prtres field from the HPRT0 register
  66814. + *FIXME Remove?
  66815. + */
  66816. +extern void dwc_otg_set_prtresume(dwc_otg_core_if_t * core_if, uint32_t val);
  66817. +
  66818. +/**
  66819. + * Get value of rmtwkupsig bit in DCTL register
  66820. + */
  66821. +extern uint32_t dwc_otg_get_remotewakesig(dwc_otg_core_if_t * core_if);
  66822. +
  66823. +/**
  66824. + * Get value of prt_sleep_sts field from the GLPMCFG register
  66825. + */
  66826. +extern uint32_t dwc_otg_get_lpm_portsleepstatus(dwc_otg_core_if_t * core_if);
  66827. +
  66828. +/**
  66829. + * Get value of rem_wkup_en field from the GLPMCFG register
  66830. + */
  66831. +extern uint32_t dwc_otg_get_lpm_remotewakeenabled(dwc_otg_core_if_t * core_if);
  66832. +
  66833. +/**
  66834. + * Get value of appl_resp field from the GLPMCFG register
  66835. + */
  66836. +extern uint32_t dwc_otg_get_lpmresponse(dwc_otg_core_if_t * core_if);
  66837. +/**
  66838. + * Set value of appl_resp field from the GLPMCFG register
  66839. + */
  66840. +extern void dwc_otg_set_lpmresponse(dwc_otg_core_if_t * core_if, uint32_t val);
  66841. +
  66842. +/**
  66843. + * Get value of hsic_connect field from the GLPMCFG register
  66844. + */
  66845. +extern uint32_t dwc_otg_get_hsic_connect(dwc_otg_core_if_t * core_if);
  66846. +/**
  66847. + * Set value of hsic_connect field from the GLPMCFG register
  66848. + */
  66849. +extern void dwc_otg_set_hsic_connect(dwc_otg_core_if_t * core_if, uint32_t val);
  66850. +
  66851. +/**
  66852. + * Get value of inv_sel_hsic field from the GLPMCFG register.
  66853. + */
  66854. +extern uint32_t dwc_otg_get_inv_sel_hsic(dwc_otg_core_if_t * core_if);
  66855. +/**
  66856. + * Set value of inv_sel_hsic field from the GLPMFG register.
  66857. + */
  66858. +extern void dwc_otg_set_inv_sel_hsic(dwc_otg_core_if_t * core_if, uint32_t val);
  66859. +
  66860. +/*
  66861. + * Some functions for accessing registers
  66862. + */
  66863. +
  66864. +/**
  66865. + * GOTGCTL register
  66866. + */
  66867. +extern uint32_t dwc_otg_get_gotgctl(dwc_otg_core_if_t * core_if);
  66868. +extern void dwc_otg_set_gotgctl(dwc_otg_core_if_t * core_if, uint32_t val);
  66869. +
  66870. +/**
  66871. + * GUSBCFG register
  66872. + */
  66873. +extern uint32_t dwc_otg_get_gusbcfg(dwc_otg_core_if_t * core_if);
  66874. +extern void dwc_otg_set_gusbcfg(dwc_otg_core_if_t * core_if, uint32_t val);
  66875. +
  66876. +/**
  66877. + * GRXFSIZ register
  66878. + */
  66879. +extern uint32_t dwc_otg_get_grxfsiz(dwc_otg_core_if_t * core_if);
  66880. +extern void dwc_otg_set_grxfsiz(dwc_otg_core_if_t * core_if, uint32_t val);
  66881. +
  66882. +/**
  66883. + * GNPTXFSIZ register
  66884. + */
  66885. +extern uint32_t dwc_otg_get_gnptxfsiz(dwc_otg_core_if_t * core_if);
  66886. +extern void dwc_otg_set_gnptxfsiz(dwc_otg_core_if_t * core_if, uint32_t val);
  66887. +
  66888. +extern uint32_t dwc_otg_get_gpvndctl(dwc_otg_core_if_t * core_if);
  66889. +extern void dwc_otg_set_gpvndctl(dwc_otg_core_if_t * core_if, uint32_t val);
  66890. +
  66891. +/**
  66892. + * GGPIO register
  66893. + */
  66894. +extern uint32_t dwc_otg_get_ggpio(dwc_otg_core_if_t * core_if);
  66895. +extern void dwc_otg_set_ggpio(dwc_otg_core_if_t * core_if, uint32_t val);
  66896. +
  66897. +/**
  66898. + * GUID register
  66899. + */
  66900. +extern uint32_t dwc_otg_get_guid(dwc_otg_core_if_t * core_if);
  66901. +extern void dwc_otg_set_guid(dwc_otg_core_if_t * core_if, uint32_t val);
  66902. +
  66903. +/**
  66904. + * HPRT0 register
  66905. + */
  66906. +extern uint32_t dwc_otg_get_hprt0(dwc_otg_core_if_t * core_if);
  66907. +extern void dwc_otg_set_hprt0(dwc_otg_core_if_t * core_if, uint32_t val);
  66908. +
  66909. +/**
  66910. + * GHPTXFSIZE
  66911. + */
  66912. +extern uint32_t dwc_otg_get_hptxfsiz(dwc_otg_core_if_t * core_if);
  66913. +
  66914. +/** @} */
  66915. +
  66916. +#endif /* __DWC_CORE_IF_H__ */
  66917. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_dbg.h linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_dbg.h
  66918. --- linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_dbg.h 1970-01-01 01:00:00.000000000 +0100
  66919. +++ linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_dbg.h 2014-08-06 16:50:14.801964726 +0200
  66920. @@ -0,0 +1,117 @@
  66921. +/* ==========================================================================
  66922. + *
  66923. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  66924. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  66925. + * otherwise expressly agreed to in writing between Synopsys and you.
  66926. + *
  66927. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  66928. + * any End User Software License Agreement or Agreement for Licensed Product
  66929. + * with Synopsys or any supplement thereto. You are permitted to use and
  66930. + * redistribute this Software in source and binary forms, with or without
  66931. + * modification, provided that redistributions of source code must retain this
  66932. + * notice. You may not view, use, disclose, copy or distribute this file or
  66933. + * any information contained herein except pursuant to this license grant from
  66934. + * Synopsys. If you do not agree with this notice, including the disclaimer
  66935. + * below, then you are not authorized to use the Software.
  66936. + *
  66937. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  66938. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  66939. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  66940. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  66941. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  66942. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  66943. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  66944. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  66945. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  66946. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  66947. + * DAMAGE.
  66948. + * ========================================================================== */
  66949. +
  66950. +#ifndef __DWC_OTG_DBG_H__
  66951. +#define __DWC_OTG_DBG_H__
  66952. +
  66953. +/** @file
  66954. + * This file defines debug levels.
  66955. + * Debugging support vanishes in non-debug builds.
  66956. + */
  66957. +
  66958. +/**
  66959. + * The Debug Level bit-mask variable.
  66960. + */
  66961. +extern uint32_t g_dbg_lvl;
  66962. +/**
  66963. + * Set the Debug Level variable.
  66964. + */
  66965. +static inline uint32_t SET_DEBUG_LEVEL(const uint32_t new)
  66966. +{
  66967. + uint32_t old = g_dbg_lvl;
  66968. + g_dbg_lvl = new;
  66969. + return old;
  66970. +}
  66971. +
  66972. +#define DBG_USER (0x1)
  66973. +/** When debug level has the DBG_CIL bit set, display CIL Debug messages. */
  66974. +#define DBG_CIL (0x2)
  66975. +/** When debug level has the DBG_CILV bit set, display CIL Verbose debug
  66976. + * messages */
  66977. +#define DBG_CILV (0x20)
  66978. +/** When debug level has the DBG_PCD bit set, display PCD (Device) debug
  66979. + * messages */
  66980. +#define DBG_PCD (0x4)
  66981. +/** When debug level has the DBG_PCDV set, display PCD (Device) Verbose debug
  66982. + * messages */
  66983. +#define DBG_PCDV (0x40)
  66984. +/** When debug level has the DBG_HCD bit set, display Host debug messages */
  66985. +#define DBG_HCD (0x8)
  66986. +/** When debug level has the DBG_HCDV bit set, display Verbose Host debug
  66987. + * messages */
  66988. +#define DBG_HCDV (0x80)
  66989. +/** When debug level has the DBG_HCD_URB bit set, display enqueued URBs in host
  66990. + * mode. */
  66991. +#define DBG_HCD_URB (0x800)
  66992. +/** When debug level has the DBG_HCDI bit set, display host interrupt
  66993. + * messages. */
  66994. +#define DBG_HCDI (0x1000)
  66995. +
  66996. +/** When debug level has any bit set, display debug messages */
  66997. +#define DBG_ANY (0xFF)
  66998. +
  66999. +/** All debug messages off */
  67000. +#define DBG_OFF 0
  67001. +
  67002. +/** Prefix string for DWC_DEBUG print macros. */
  67003. +#define USB_DWC "DWC_otg: "
  67004. +
  67005. +/**
  67006. + * Print a debug message when the Global debug level variable contains
  67007. + * the bit defined in <code>lvl</code>.
  67008. + *
  67009. + * @param[in] lvl - Debug level, use one of the DBG_ constants above.
  67010. + * @param[in] x - like printf
  67011. + *
  67012. + * Example:<p>
  67013. + * <code>
  67014. + * DWC_DEBUGPL( DBG_ANY, "%s(%p)\n", __func__, _reg_base_addr);
  67015. + * </code>
  67016. + * <br>
  67017. + * results in:<br>
  67018. + * <code>
  67019. + * usb-DWC_otg: dwc_otg_cil_init(ca867000)
  67020. + * </code>
  67021. + */
  67022. +#ifdef DEBUG
  67023. +
  67024. +# define DWC_DEBUGPL(lvl, x...) do{ if ((lvl)&g_dbg_lvl)__DWC_DEBUG(USB_DWC x ); }while(0)
  67025. +# define DWC_DEBUGP(x...) DWC_DEBUGPL(DBG_ANY, x )
  67026. +
  67027. +# define CHK_DEBUG_LEVEL(level) ((level) & g_dbg_lvl)
  67028. +
  67029. +#else
  67030. +
  67031. +# define DWC_DEBUGPL(lvl, x...) do{}while(0)
  67032. +# define DWC_DEBUGP(x...)
  67033. +
  67034. +# define CHK_DEBUG_LEVEL(level) (0)
  67035. +
  67036. +#endif /*DEBUG*/
  67037. +#endif
  67038. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_driver.c linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_driver.c
  67039. --- linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_driver.c 1970-01-01 01:00:00.000000000 +0100
  67040. +++ linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_driver.c 2014-08-06 16:50:14.805964758 +0200
  67041. @@ -0,0 +1,1749 @@
  67042. +/* ==========================================================================
  67043. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_driver.c $
  67044. + * $Revision: #92 $
  67045. + * $Date: 2012/08/10 $
  67046. + * $Change: 2047372 $
  67047. + *
  67048. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  67049. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  67050. + * otherwise expressly agreed to in writing between Synopsys and you.
  67051. + *
  67052. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  67053. + * any End User Software License Agreement or Agreement for Licensed Product
  67054. + * with Synopsys or any supplement thereto. You are permitted to use and
  67055. + * redistribute this Software in source and binary forms, with or without
  67056. + * modification, provided that redistributions of source code must retain this
  67057. + * notice. You may not view, use, disclose, copy or distribute this file or
  67058. + * any information contained herein except pursuant to this license grant from
  67059. + * Synopsys. If you do not agree with this notice, including the disclaimer
  67060. + * below, then you are not authorized to use the Software.
  67061. + *
  67062. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  67063. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  67064. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  67065. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  67066. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  67067. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  67068. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  67069. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  67070. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  67071. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  67072. + * DAMAGE.
  67073. + * ========================================================================== */
  67074. +
  67075. +/** @file
  67076. + * The dwc_otg_driver module provides the initialization and cleanup entry
  67077. + * points for the DWC_otg driver. This module will be dynamically installed
  67078. + * after Linux is booted using the insmod command. When the module is
  67079. + * installed, the dwc_otg_driver_init function is called. When the module is
  67080. + * removed (using rmmod), the dwc_otg_driver_cleanup function is called.
  67081. + *
  67082. + * This module also defines a data structure for the dwc_otg_driver, which is
  67083. + * used in conjunction with the standard ARM lm_device structure. These
  67084. + * structures allow the OTG driver to comply with the standard Linux driver
  67085. + * model in which devices and drivers are registered with a bus driver. This
  67086. + * has the benefit that Linux can expose attributes of the driver and device
  67087. + * in its special sysfs file system. Users can then read or write files in
  67088. + * this file system to perform diagnostics on the driver components or the
  67089. + * device.
  67090. + */
  67091. +
  67092. +#include "dwc_otg_os_dep.h"
  67093. +#include "dwc_os.h"
  67094. +#include "dwc_otg_dbg.h"
  67095. +#include "dwc_otg_driver.h"
  67096. +#include "dwc_otg_attr.h"
  67097. +#include "dwc_otg_core_if.h"
  67098. +#include "dwc_otg_pcd_if.h"
  67099. +#include "dwc_otg_hcd_if.h"
  67100. +#include "dwc_otg_fiq_fsm.h"
  67101. +
  67102. +#define DWC_DRIVER_VERSION "3.00a 10-AUG-2012"
  67103. +#define DWC_DRIVER_DESC "HS OTG USB Controller driver"
  67104. +
  67105. +bool microframe_schedule=true;
  67106. +
  67107. +static const char dwc_driver_name[] = "dwc_otg";
  67108. +
  67109. +
  67110. +extern int pcd_init(
  67111. +#ifdef LM_INTERFACE
  67112. + struct lm_device *_dev
  67113. +#elif defined(PCI_INTERFACE)
  67114. + struct pci_dev *_dev
  67115. +#elif defined(PLATFORM_INTERFACE)
  67116. + struct platform_device *dev
  67117. +#endif
  67118. + );
  67119. +extern int hcd_init(
  67120. +#ifdef LM_INTERFACE
  67121. + struct lm_device *_dev
  67122. +#elif defined(PCI_INTERFACE)
  67123. + struct pci_dev *_dev
  67124. +#elif defined(PLATFORM_INTERFACE)
  67125. + struct platform_device *dev
  67126. +#endif
  67127. + );
  67128. +
  67129. +extern int pcd_remove(
  67130. +#ifdef LM_INTERFACE
  67131. + struct lm_device *_dev
  67132. +#elif defined(PCI_INTERFACE)
  67133. + struct pci_dev *_dev
  67134. +#elif defined(PLATFORM_INTERFACE)
  67135. + struct platform_device *_dev
  67136. +#endif
  67137. + );
  67138. +
  67139. +extern void hcd_remove(
  67140. +#ifdef LM_INTERFACE
  67141. + struct lm_device *_dev
  67142. +#elif defined(PCI_INTERFACE)
  67143. + struct pci_dev *_dev
  67144. +#elif defined(PLATFORM_INTERFACE)
  67145. + struct platform_device *_dev
  67146. +#endif
  67147. + );
  67148. +
  67149. +extern void dwc_otg_adp_start(dwc_otg_core_if_t * core_if, uint8_t is_host);
  67150. +
  67151. +/*-------------------------------------------------------------------------*/
  67152. +/* Encapsulate the module parameter settings */
  67153. +
  67154. +struct dwc_otg_driver_module_params {
  67155. + int32_t opt;
  67156. + int32_t otg_cap;
  67157. + int32_t dma_enable;
  67158. + int32_t dma_desc_enable;
  67159. + int32_t dma_burst_size;
  67160. + int32_t speed;
  67161. + int32_t host_support_fs_ls_low_power;
  67162. + int32_t host_ls_low_power_phy_clk;
  67163. + int32_t enable_dynamic_fifo;
  67164. + int32_t data_fifo_size;
  67165. + int32_t dev_rx_fifo_size;
  67166. + int32_t dev_nperio_tx_fifo_size;
  67167. + uint32_t dev_perio_tx_fifo_size[MAX_PERIO_FIFOS];
  67168. + int32_t host_rx_fifo_size;
  67169. + int32_t host_nperio_tx_fifo_size;
  67170. + int32_t host_perio_tx_fifo_size;
  67171. + int32_t max_transfer_size;
  67172. + int32_t max_packet_count;
  67173. + int32_t host_channels;
  67174. + int32_t dev_endpoints;
  67175. + int32_t phy_type;
  67176. + int32_t phy_utmi_width;
  67177. + int32_t phy_ulpi_ddr;
  67178. + int32_t phy_ulpi_ext_vbus;
  67179. + int32_t i2c_enable;
  67180. + int32_t ulpi_fs_ls;
  67181. + int32_t ts_dline;
  67182. + int32_t en_multiple_tx_fifo;
  67183. + uint32_t dev_tx_fifo_size[MAX_TX_FIFOS];
  67184. + uint32_t thr_ctl;
  67185. + uint32_t tx_thr_length;
  67186. + uint32_t rx_thr_length;
  67187. + int32_t pti_enable;
  67188. + int32_t mpi_enable;
  67189. + int32_t lpm_enable;
  67190. + int32_t ic_usb_cap;
  67191. + int32_t ahb_thr_ratio;
  67192. + int32_t power_down;
  67193. + int32_t reload_ctl;
  67194. + int32_t dev_out_nak;
  67195. + int32_t cont_on_bna;
  67196. + int32_t ahb_single;
  67197. + int32_t otg_ver;
  67198. + int32_t adp_enable;
  67199. +};
  67200. +
  67201. +static struct dwc_otg_driver_module_params dwc_otg_module_params = {
  67202. + .opt = -1,
  67203. + .otg_cap = -1,
  67204. + .dma_enable = -1,
  67205. + .dma_desc_enable = -1,
  67206. + .dma_burst_size = -1,
  67207. + .speed = -1,
  67208. + .host_support_fs_ls_low_power = -1,
  67209. + .host_ls_low_power_phy_clk = -1,
  67210. + .enable_dynamic_fifo = -1,
  67211. + .data_fifo_size = -1,
  67212. + .dev_rx_fifo_size = -1,
  67213. + .dev_nperio_tx_fifo_size = -1,
  67214. + .dev_perio_tx_fifo_size = {
  67215. + /* dev_perio_tx_fifo_size_1 */
  67216. + -1,
  67217. + -1,
  67218. + -1,
  67219. + -1,
  67220. + -1,
  67221. + -1,
  67222. + -1,
  67223. + -1,
  67224. + -1,
  67225. + -1,
  67226. + -1,
  67227. + -1,
  67228. + -1,
  67229. + -1,
  67230. + -1
  67231. + /* 15 */
  67232. + },
  67233. + .host_rx_fifo_size = -1,
  67234. + .host_nperio_tx_fifo_size = -1,
  67235. + .host_perio_tx_fifo_size = -1,
  67236. + .max_transfer_size = -1,
  67237. + .max_packet_count = -1,
  67238. + .host_channels = -1,
  67239. + .dev_endpoints = -1,
  67240. + .phy_type = -1,
  67241. + .phy_utmi_width = -1,
  67242. + .phy_ulpi_ddr = -1,
  67243. + .phy_ulpi_ext_vbus = -1,
  67244. + .i2c_enable = -1,
  67245. + .ulpi_fs_ls = -1,
  67246. + .ts_dline = -1,
  67247. + .en_multiple_tx_fifo = -1,
  67248. + .dev_tx_fifo_size = {
  67249. + /* dev_tx_fifo_size */
  67250. + -1,
  67251. + -1,
  67252. + -1,
  67253. + -1,
  67254. + -1,
  67255. + -1,
  67256. + -1,
  67257. + -1,
  67258. + -1,
  67259. + -1,
  67260. + -1,
  67261. + -1,
  67262. + -1,
  67263. + -1,
  67264. + -1
  67265. + /* 15 */
  67266. + },
  67267. + .thr_ctl = -1,
  67268. + .tx_thr_length = -1,
  67269. + .rx_thr_length = -1,
  67270. + .pti_enable = -1,
  67271. + .mpi_enable = -1,
  67272. + .lpm_enable = 0,
  67273. + .ic_usb_cap = -1,
  67274. + .ahb_thr_ratio = -1,
  67275. + .power_down = -1,
  67276. + .reload_ctl = -1,
  67277. + .dev_out_nak = -1,
  67278. + .cont_on_bna = -1,
  67279. + .ahb_single = -1,
  67280. + .otg_ver = -1,
  67281. + .adp_enable = -1,
  67282. +};
  67283. +
  67284. +//Global variable to switch the fiq fix on or off
  67285. +bool fiq_enable = 1;
  67286. +// Global variable to enable the split transaction fix
  67287. +bool fiq_fsm_enable = false;
  67288. +//Bulk split-transaction NAK holdoff in microframes
  67289. +uint16_t nak_holdoff = 8;
  67290. +
  67291. +unsigned short fiq_fsm_mask = 0x01;
  67292. +
  67293. +/**
  67294. + * This function shows the Driver Version.
  67295. + */
  67296. +static ssize_t version_show(struct device_driver *dev, char *buf)
  67297. +{
  67298. + return snprintf(buf, sizeof(DWC_DRIVER_VERSION) + 2, "%s\n",
  67299. + DWC_DRIVER_VERSION);
  67300. +}
  67301. +
  67302. +static DRIVER_ATTR(version, S_IRUGO, version_show, NULL);
  67303. +
  67304. +/**
  67305. + * Global Debug Level Mask.
  67306. + */
  67307. +uint32_t g_dbg_lvl = 0; /* OFF */
  67308. +
  67309. +/**
  67310. + * This function shows the driver Debug Level.
  67311. + */
  67312. +static ssize_t dbg_level_show(struct device_driver *drv, char *buf)
  67313. +{
  67314. + return sprintf(buf, "0x%0x\n", g_dbg_lvl);
  67315. +}
  67316. +
  67317. +/**
  67318. + * This function stores the driver Debug Level.
  67319. + */
  67320. +static ssize_t dbg_level_store(struct device_driver *drv, const char *buf,
  67321. + size_t count)
  67322. +{
  67323. + g_dbg_lvl = simple_strtoul(buf, NULL, 16);
  67324. + return count;
  67325. +}
  67326. +
  67327. +static DRIVER_ATTR(debuglevel, S_IRUGO | S_IWUSR, dbg_level_show,
  67328. + dbg_level_store);
  67329. +
  67330. +/**
  67331. + * This function is called during module intialization
  67332. + * to pass module parameters to the DWC_OTG CORE.
  67333. + */
  67334. +static int set_parameters(dwc_otg_core_if_t * core_if)
  67335. +{
  67336. + int retval = 0;
  67337. + int i;
  67338. +
  67339. + if (dwc_otg_module_params.otg_cap != -1) {
  67340. + retval +=
  67341. + dwc_otg_set_param_otg_cap(core_if,
  67342. + dwc_otg_module_params.otg_cap);
  67343. + }
  67344. + if (dwc_otg_module_params.dma_enable != -1) {
  67345. + retval +=
  67346. + dwc_otg_set_param_dma_enable(core_if,
  67347. + dwc_otg_module_params.
  67348. + dma_enable);
  67349. + }
  67350. + if (dwc_otg_module_params.dma_desc_enable != -1) {
  67351. + retval +=
  67352. + dwc_otg_set_param_dma_desc_enable(core_if,
  67353. + dwc_otg_module_params.
  67354. + dma_desc_enable);
  67355. + }
  67356. + if (dwc_otg_module_params.opt != -1) {
  67357. + retval +=
  67358. + dwc_otg_set_param_opt(core_if, dwc_otg_module_params.opt);
  67359. + }
  67360. + if (dwc_otg_module_params.dma_burst_size != -1) {
  67361. + retval +=
  67362. + dwc_otg_set_param_dma_burst_size(core_if,
  67363. + dwc_otg_module_params.
  67364. + dma_burst_size);
  67365. + }
  67366. + if (dwc_otg_module_params.host_support_fs_ls_low_power != -1) {
  67367. + retval +=
  67368. + dwc_otg_set_param_host_support_fs_ls_low_power(core_if,
  67369. + dwc_otg_module_params.
  67370. + host_support_fs_ls_low_power);
  67371. + }
  67372. + if (dwc_otg_module_params.enable_dynamic_fifo != -1) {
  67373. + retval +=
  67374. + dwc_otg_set_param_enable_dynamic_fifo(core_if,
  67375. + dwc_otg_module_params.
  67376. + enable_dynamic_fifo);
  67377. + }
  67378. + if (dwc_otg_module_params.data_fifo_size != -1) {
  67379. + retval +=
  67380. + dwc_otg_set_param_data_fifo_size(core_if,
  67381. + dwc_otg_module_params.
  67382. + data_fifo_size);
  67383. + }
  67384. + if (dwc_otg_module_params.dev_rx_fifo_size != -1) {
  67385. + retval +=
  67386. + dwc_otg_set_param_dev_rx_fifo_size(core_if,
  67387. + dwc_otg_module_params.
  67388. + dev_rx_fifo_size);
  67389. + }
  67390. + if (dwc_otg_module_params.dev_nperio_tx_fifo_size != -1) {
  67391. + retval +=
  67392. + dwc_otg_set_param_dev_nperio_tx_fifo_size(core_if,
  67393. + dwc_otg_module_params.
  67394. + dev_nperio_tx_fifo_size);
  67395. + }
  67396. + if (dwc_otg_module_params.host_rx_fifo_size != -1) {
  67397. + retval +=
  67398. + dwc_otg_set_param_host_rx_fifo_size(core_if,
  67399. + dwc_otg_module_params.host_rx_fifo_size);
  67400. + }
  67401. + if (dwc_otg_module_params.host_nperio_tx_fifo_size != -1) {
  67402. + retval +=
  67403. + dwc_otg_set_param_host_nperio_tx_fifo_size(core_if,
  67404. + dwc_otg_module_params.
  67405. + host_nperio_tx_fifo_size);
  67406. + }
  67407. + if (dwc_otg_module_params.host_perio_tx_fifo_size != -1) {
  67408. + retval +=
  67409. + dwc_otg_set_param_host_perio_tx_fifo_size(core_if,
  67410. + dwc_otg_module_params.
  67411. + host_perio_tx_fifo_size);
  67412. + }
  67413. + if (dwc_otg_module_params.max_transfer_size != -1) {
  67414. + retval +=
  67415. + dwc_otg_set_param_max_transfer_size(core_if,
  67416. + dwc_otg_module_params.
  67417. + max_transfer_size);
  67418. + }
  67419. + if (dwc_otg_module_params.max_packet_count != -1) {
  67420. + retval +=
  67421. + dwc_otg_set_param_max_packet_count(core_if,
  67422. + dwc_otg_module_params.
  67423. + max_packet_count);
  67424. + }
  67425. + if (dwc_otg_module_params.host_channels != -1) {
  67426. + retval +=
  67427. + dwc_otg_set_param_host_channels(core_if,
  67428. + dwc_otg_module_params.
  67429. + host_channels);
  67430. + }
  67431. + if (dwc_otg_module_params.dev_endpoints != -1) {
  67432. + retval +=
  67433. + dwc_otg_set_param_dev_endpoints(core_if,
  67434. + dwc_otg_module_params.
  67435. + dev_endpoints);
  67436. + }
  67437. + if (dwc_otg_module_params.phy_type != -1) {
  67438. + retval +=
  67439. + dwc_otg_set_param_phy_type(core_if,
  67440. + dwc_otg_module_params.phy_type);
  67441. + }
  67442. + if (dwc_otg_module_params.speed != -1) {
  67443. + retval +=
  67444. + dwc_otg_set_param_speed(core_if,
  67445. + dwc_otg_module_params.speed);
  67446. + }
  67447. + if (dwc_otg_module_params.host_ls_low_power_phy_clk != -1) {
  67448. + retval +=
  67449. + dwc_otg_set_param_host_ls_low_power_phy_clk(core_if,
  67450. + dwc_otg_module_params.
  67451. + host_ls_low_power_phy_clk);
  67452. + }
  67453. + if (dwc_otg_module_params.phy_ulpi_ddr != -1) {
  67454. + retval +=
  67455. + dwc_otg_set_param_phy_ulpi_ddr(core_if,
  67456. + dwc_otg_module_params.
  67457. + phy_ulpi_ddr);
  67458. + }
  67459. + if (dwc_otg_module_params.phy_ulpi_ext_vbus != -1) {
  67460. + retval +=
  67461. + dwc_otg_set_param_phy_ulpi_ext_vbus(core_if,
  67462. + dwc_otg_module_params.
  67463. + phy_ulpi_ext_vbus);
  67464. + }
  67465. + if (dwc_otg_module_params.phy_utmi_width != -1) {
  67466. + retval +=
  67467. + dwc_otg_set_param_phy_utmi_width(core_if,
  67468. + dwc_otg_module_params.
  67469. + phy_utmi_width);
  67470. + }
  67471. + if (dwc_otg_module_params.ulpi_fs_ls != -1) {
  67472. + retval +=
  67473. + dwc_otg_set_param_ulpi_fs_ls(core_if,
  67474. + dwc_otg_module_params.ulpi_fs_ls);
  67475. + }
  67476. + if (dwc_otg_module_params.ts_dline != -1) {
  67477. + retval +=
  67478. + dwc_otg_set_param_ts_dline(core_if,
  67479. + dwc_otg_module_params.ts_dline);
  67480. + }
  67481. + if (dwc_otg_module_params.i2c_enable != -1) {
  67482. + retval +=
  67483. + dwc_otg_set_param_i2c_enable(core_if,
  67484. + dwc_otg_module_params.
  67485. + i2c_enable);
  67486. + }
  67487. + if (dwc_otg_module_params.en_multiple_tx_fifo != -1) {
  67488. + retval +=
  67489. + dwc_otg_set_param_en_multiple_tx_fifo(core_if,
  67490. + dwc_otg_module_params.
  67491. + en_multiple_tx_fifo);
  67492. + }
  67493. + for (i = 0; i < 15; i++) {
  67494. + if (dwc_otg_module_params.dev_perio_tx_fifo_size[i] != -1) {
  67495. + retval +=
  67496. + dwc_otg_set_param_dev_perio_tx_fifo_size(core_if,
  67497. + dwc_otg_module_params.
  67498. + dev_perio_tx_fifo_size
  67499. + [i], i);
  67500. + }
  67501. + }
  67502. +
  67503. + for (i = 0; i < 15; i++) {
  67504. + if (dwc_otg_module_params.dev_tx_fifo_size[i] != -1) {
  67505. + retval += dwc_otg_set_param_dev_tx_fifo_size(core_if,
  67506. + dwc_otg_module_params.
  67507. + dev_tx_fifo_size
  67508. + [i], i);
  67509. + }
  67510. + }
  67511. + if (dwc_otg_module_params.thr_ctl != -1) {
  67512. + retval +=
  67513. + dwc_otg_set_param_thr_ctl(core_if,
  67514. + dwc_otg_module_params.thr_ctl);
  67515. + }
  67516. + if (dwc_otg_module_params.mpi_enable != -1) {
  67517. + retval +=
  67518. + dwc_otg_set_param_mpi_enable(core_if,
  67519. + dwc_otg_module_params.
  67520. + mpi_enable);
  67521. + }
  67522. + if (dwc_otg_module_params.pti_enable != -1) {
  67523. + retval +=
  67524. + dwc_otg_set_param_pti_enable(core_if,
  67525. + dwc_otg_module_params.
  67526. + pti_enable);
  67527. + }
  67528. + if (dwc_otg_module_params.lpm_enable != -1) {
  67529. + retval +=
  67530. + dwc_otg_set_param_lpm_enable(core_if,
  67531. + dwc_otg_module_params.
  67532. + lpm_enable);
  67533. + }
  67534. + if (dwc_otg_module_params.ic_usb_cap != -1) {
  67535. + retval +=
  67536. + dwc_otg_set_param_ic_usb_cap(core_if,
  67537. + dwc_otg_module_params.
  67538. + ic_usb_cap);
  67539. + }
  67540. + if (dwc_otg_module_params.tx_thr_length != -1) {
  67541. + retval +=
  67542. + dwc_otg_set_param_tx_thr_length(core_if,
  67543. + dwc_otg_module_params.tx_thr_length);
  67544. + }
  67545. + if (dwc_otg_module_params.rx_thr_length != -1) {
  67546. + retval +=
  67547. + dwc_otg_set_param_rx_thr_length(core_if,
  67548. + dwc_otg_module_params.
  67549. + rx_thr_length);
  67550. + }
  67551. + if (dwc_otg_module_params.ahb_thr_ratio != -1) {
  67552. + retval +=
  67553. + dwc_otg_set_param_ahb_thr_ratio(core_if,
  67554. + dwc_otg_module_params.ahb_thr_ratio);
  67555. + }
  67556. + if (dwc_otg_module_params.power_down != -1) {
  67557. + retval +=
  67558. + dwc_otg_set_param_power_down(core_if,
  67559. + dwc_otg_module_params.power_down);
  67560. + }
  67561. + if (dwc_otg_module_params.reload_ctl != -1) {
  67562. + retval +=
  67563. + dwc_otg_set_param_reload_ctl(core_if,
  67564. + dwc_otg_module_params.reload_ctl);
  67565. + }
  67566. +
  67567. + if (dwc_otg_module_params.dev_out_nak != -1) {
  67568. + retval +=
  67569. + dwc_otg_set_param_dev_out_nak(core_if,
  67570. + dwc_otg_module_params.dev_out_nak);
  67571. + }
  67572. +
  67573. + if (dwc_otg_module_params.cont_on_bna != -1) {
  67574. + retval +=
  67575. + dwc_otg_set_param_cont_on_bna(core_if,
  67576. + dwc_otg_module_params.cont_on_bna);
  67577. + }
  67578. +
  67579. + if (dwc_otg_module_params.ahb_single != -1) {
  67580. + retval +=
  67581. + dwc_otg_set_param_ahb_single(core_if,
  67582. + dwc_otg_module_params.ahb_single);
  67583. + }
  67584. +
  67585. + if (dwc_otg_module_params.otg_ver != -1) {
  67586. + retval +=
  67587. + dwc_otg_set_param_otg_ver(core_if,
  67588. + dwc_otg_module_params.otg_ver);
  67589. + }
  67590. + if (dwc_otg_module_params.adp_enable != -1) {
  67591. + retval +=
  67592. + dwc_otg_set_param_adp_enable(core_if,
  67593. + dwc_otg_module_params.
  67594. + adp_enable);
  67595. + }
  67596. + return retval;
  67597. +}
  67598. +
  67599. +/**
  67600. + * This function is the top level interrupt handler for the Common
  67601. + * (Device and host modes) interrupts.
  67602. + */
  67603. +static irqreturn_t dwc_otg_common_irq(int irq, void *dev)
  67604. +{
  67605. + int32_t retval = IRQ_NONE;
  67606. +
  67607. + retval = dwc_otg_handle_common_intr(dev);
  67608. + if (retval != 0) {
  67609. + S3C2410X_CLEAR_EINTPEND();
  67610. + }
  67611. + return IRQ_RETVAL(retval);
  67612. +}
  67613. +
  67614. +/**
  67615. + * This function is called when a lm_device is unregistered with the
  67616. + * dwc_otg_driver. This happens, for example, when the rmmod command is
  67617. + * executed. The device may or may not be electrically present. If it is
  67618. + * present, the driver stops device processing. Any resources used on behalf
  67619. + * of this device are freed.
  67620. + *
  67621. + * @param _dev
  67622. + */
  67623. +#ifdef LM_INTERFACE
  67624. +#define REM_RETVAL(n)
  67625. +static void dwc_otg_driver_remove( struct lm_device *_dev )
  67626. +{ dwc_otg_device_t *otg_dev = lm_get_drvdata(_dev);
  67627. +#elif defined(PCI_INTERFACE)
  67628. +#define REM_RETVAL(n)
  67629. +static void dwc_otg_driver_remove( struct pci_dev *_dev )
  67630. +{ dwc_otg_device_t *otg_dev = pci_get_drvdata(_dev);
  67631. +#elif defined(PLATFORM_INTERFACE)
  67632. +#define REM_RETVAL(n) n
  67633. +static int dwc_otg_driver_remove( struct platform_device *_dev )
  67634. +{ dwc_otg_device_t *otg_dev = platform_get_drvdata(_dev);
  67635. +#endif
  67636. +
  67637. + DWC_DEBUGPL(DBG_ANY, "%s(%p) otg_dev %p\n", __func__, _dev, otg_dev);
  67638. +
  67639. + if (!otg_dev) {
  67640. + /* Memory allocation for the dwc_otg_device failed. */
  67641. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev NULL!\n", __func__);
  67642. + return REM_RETVAL(-ENOMEM);
  67643. + }
  67644. +#ifndef DWC_DEVICE_ONLY
  67645. + if (otg_dev->hcd) {
  67646. + hcd_remove(_dev);
  67647. + } else {
  67648. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->hcd NULL!\n", __func__);
  67649. + return REM_RETVAL(-EINVAL);
  67650. + }
  67651. +#endif
  67652. +
  67653. +#ifndef DWC_HOST_ONLY
  67654. + if (otg_dev->pcd) {
  67655. + pcd_remove(_dev);
  67656. + } else {
  67657. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->pcd NULL!\n", __func__);
  67658. + return REM_RETVAL(-EINVAL);
  67659. + }
  67660. +#endif
  67661. + /*
  67662. + * Free the IRQ
  67663. + */
  67664. + if (otg_dev->common_irq_installed) {
  67665. +#ifdef PLATFORM_INTERFACE
  67666. + free_irq(platform_get_irq(_dev, 0), otg_dev);
  67667. +#else
  67668. + free_irq(_dev->irq, otg_dev);
  67669. +#endif
  67670. + } else {
  67671. + DWC_DEBUGPL(DBG_ANY, "%s: There is no installed irq!\n", __func__);
  67672. + return REM_RETVAL(-ENXIO);
  67673. + }
  67674. +
  67675. + if (otg_dev->core_if) {
  67676. + dwc_otg_cil_remove(otg_dev->core_if);
  67677. + } else {
  67678. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->core_if NULL!\n", __func__);
  67679. + return REM_RETVAL(-ENXIO);
  67680. + }
  67681. +
  67682. + /*
  67683. + * Remove the device attributes
  67684. + */
  67685. + dwc_otg_attr_remove(_dev);
  67686. +
  67687. + /*
  67688. + * Return the memory.
  67689. + */
  67690. + if (otg_dev->os_dep.base) {
  67691. + iounmap(otg_dev->os_dep.base);
  67692. + }
  67693. + DWC_FREE(otg_dev);
  67694. +
  67695. + /*
  67696. + * Clear the drvdata pointer.
  67697. + */
  67698. +#ifdef LM_INTERFACE
  67699. + lm_set_drvdata(_dev, 0);
  67700. +#elif defined(PCI_INTERFACE)
  67701. + release_mem_region(otg_dev->os_dep.rsrc_start,
  67702. + otg_dev->os_dep.rsrc_len);
  67703. + pci_set_drvdata(_dev, 0);
  67704. +#elif defined(PLATFORM_INTERFACE)
  67705. + platform_set_drvdata(_dev, 0);
  67706. +#endif
  67707. + return REM_RETVAL(0);
  67708. +}
  67709. +
  67710. +/**
  67711. + * This function is called when an lm_device is bound to a
  67712. + * dwc_otg_driver. It creates the driver components required to
  67713. + * control the device (CIL, HCD, and PCD) and it initializes the
  67714. + * device. The driver components are stored in a dwc_otg_device
  67715. + * structure. A reference to the dwc_otg_device is saved in the
  67716. + * lm_device. This allows the driver to access the dwc_otg_device
  67717. + * structure on subsequent calls to driver methods for this device.
  67718. + *
  67719. + * @param _dev Bus device
  67720. + */
  67721. +static int dwc_otg_driver_probe(
  67722. +#ifdef LM_INTERFACE
  67723. + struct lm_device *_dev
  67724. +#elif defined(PCI_INTERFACE)
  67725. + struct pci_dev *_dev,
  67726. + const struct pci_device_id *id
  67727. +#elif defined(PLATFORM_INTERFACE)
  67728. + struct platform_device *_dev
  67729. +#endif
  67730. + )
  67731. +{
  67732. + int retval = 0;
  67733. + dwc_otg_device_t *dwc_otg_device;
  67734. + int devirq;
  67735. +
  67736. + dev_dbg(&_dev->dev, "dwc_otg_driver_probe(%p)\n", _dev);
  67737. +#ifdef LM_INTERFACE
  67738. + dev_dbg(&_dev->dev, "start=0x%08x\n", (unsigned)_dev->resource.start);
  67739. +#elif defined(PCI_INTERFACE)
  67740. + if (!id) {
  67741. + DWC_ERROR("Invalid pci_device_id %p", id);
  67742. + return -EINVAL;
  67743. + }
  67744. +
  67745. + if (!_dev || (pci_enable_device(_dev) < 0)) {
  67746. + DWC_ERROR("Invalid pci_device %p", _dev);
  67747. + return -ENODEV;
  67748. + }
  67749. + dev_dbg(&_dev->dev, "start=0x%08x\n", (unsigned)pci_resource_start(_dev,0));
  67750. + /* other stuff needed as well? */
  67751. +
  67752. +#elif defined(PLATFORM_INTERFACE)
  67753. + dev_dbg(&_dev->dev, "start=0x%08x (len 0x%x)\n",
  67754. + (unsigned)_dev->resource->start,
  67755. + (unsigned)(_dev->resource->end - _dev->resource->start));
  67756. +#endif
  67757. +
  67758. + dwc_otg_device = DWC_ALLOC(sizeof(dwc_otg_device_t));
  67759. +
  67760. + if (!dwc_otg_device) {
  67761. + dev_err(&_dev->dev, "kmalloc of dwc_otg_device failed\n");
  67762. + return -ENOMEM;
  67763. + }
  67764. +
  67765. + memset(dwc_otg_device, 0, sizeof(*dwc_otg_device));
  67766. + dwc_otg_device->os_dep.reg_offset = 0xFFFFFFFF;
  67767. +
  67768. + /*
  67769. + * Map the DWC_otg Core memory into virtual address space.
  67770. + */
  67771. +#ifdef LM_INTERFACE
  67772. + dwc_otg_device->os_dep.base = ioremap(_dev->resource.start, SZ_256K);
  67773. +
  67774. + if (!dwc_otg_device->os_dep.base) {
  67775. + dev_err(&_dev->dev, "ioremap() failed\n");
  67776. + DWC_FREE(dwc_otg_device);
  67777. + return -ENOMEM;
  67778. + }
  67779. + dev_dbg(&_dev->dev, "base=0x%08x\n",
  67780. + (unsigned)dwc_otg_device->os_dep.base);
  67781. +#elif defined(PCI_INTERFACE)
  67782. + _dev->current_state = PCI_D0;
  67783. + _dev->dev.power.power_state = PMSG_ON;
  67784. +
  67785. + if (!_dev->irq) {
  67786. + DWC_ERROR("Found HC with no IRQ. Check BIOS/PCI %s setup!",
  67787. + pci_name(_dev));
  67788. + iounmap(dwc_otg_device->os_dep.base);
  67789. + DWC_FREE(dwc_otg_device);
  67790. + return -ENODEV;
  67791. + }
  67792. +
  67793. + dwc_otg_device->os_dep.rsrc_start = pci_resource_start(_dev, 0);
  67794. + dwc_otg_device->os_dep.rsrc_len = pci_resource_len(_dev, 0);
  67795. + DWC_DEBUGPL(DBG_ANY, "PCI resource: start=%08x, len=%08x\n",
  67796. + (unsigned)dwc_otg_device->os_dep.rsrc_start,
  67797. + (unsigned)dwc_otg_device->os_dep.rsrc_len);
  67798. + if (!request_mem_region
  67799. + (dwc_otg_device->os_dep.rsrc_start, dwc_otg_device->os_dep.rsrc_len,
  67800. + "dwc_otg")) {
  67801. + dev_dbg(&_dev->dev, "error requesting memory\n");
  67802. + iounmap(dwc_otg_device->os_dep.base);
  67803. + DWC_FREE(dwc_otg_device);
  67804. + return -EFAULT;
  67805. + }
  67806. +
  67807. + dwc_otg_device->os_dep.base =
  67808. + ioremap_nocache(dwc_otg_device->os_dep.rsrc_start,
  67809. + dwc_otg_device->os_dep.rsrc_len);
  67810. + if (dwc_otg_device->os_dep.base == NULL) {
  67811. + dev_dbg(&_dev->dev, "error mapping memory\n");
  67812. + release_mem_region(dwc_otg_device->os_dep.rsrc_start,
  67813. + dwc_otg_device->os_dep.rsrc_len);
  67814. + iounmap(dwc_otg_device->os_dep.base);
  67815. + DWC_FREE(dwc_otg_device);
  67816. + return -EFAULT;
  67817. + }
  67818. + dev_dbg(&_dev->dev, "base=0x%p (before adjust) \n",
  67819. + dwc_otg_device->os_dep.base);
  67820. + dwc_otg_device->os_dep.base = (char *)dwc_otg_device->os_dep.base;
  67821. + dev_dbg(&_dev->dev, "base=0x%p (after adjust) \n",
  67822. + dwc_otg_device->os_dep.base);
  67823. + dev_dbg(&_dev->dev, "%s: mapped PA 0x%x to VA 0x%p\n", __func__,
  67824. + (unsigned)dwc_otg_device->os_dep.rsrc_start,
  67825. + dwc_otg_device->os_dep.base);
  67826. +
  67827. + pci_set_master(_dev);
  67828. + pci_set_drvdata(_dev, dwc_otg_device);
  67829. +#elif defined(PLATFORM_INTERFACE)
  67830. + DWC_DEBUGPL(DBG_ANY,"Platform resource: start=%08x, len=%08x\n",
  67831. + _dev->resource->start,
  67832. + _dev->resource->end - _dev->resource->start + 1);
  67833. +#if 1
  67834. + if (!request_mem_region(_dev->resource[0].start,
  67835. + _dev->resource[0].end - _dev->resource[0].start + 1,
  67836. + "dwc_otg")) {
  67837. + dev_dbg(&_dev->dev, "error reserving mapped memory\n");
  67838. + retval = -EFAULT;
  67839. + goto fail;
  67840. + }
  67841. +
  67842. + dwc_otg_device->os_dep.base = ioremap_nocache(_dev->resource[0].start,
  67843. + _dev->resource[0].end -
  67844. + _dev->resource[0].start+1);
  67845. + if (fiq_enable)
  67846. + {
  67847. + if (!request_mem_region(_dev->resource[1].start,
  67848. + _dev->resource[1].end - _dev->resource[1].start + 1,
  67849. + "dwc_otg")) {
  67850. + dev_dbg(&_dev->dev, "error reserving mapped memory\n");
  67851. + retval = -EFAULT;
  67852. + goto fail;
  67853. + }
  67854. +
  67855. + dwc_otg_device->os_dep.mphi_base = ioremap_nocache(_dev->resource[1].start,
  67856. + _dev->resource[1].end -
  67857. + _dev->resource[1].start + 1);
  67858. + }
  67859. +
  67860. +#else
  67861. + {
  67862. + struct map_desc desc = {
  67863. + .virtual = IO_ADDRESS((unsigned)_dev->resource->start),
  67864. + .pfn = __phys_to_pfn((unsigned)_dev->resource->start),
  67865. + .length = SZ_128K,
  67866. + .type = MT_DEVICE
  67867. + };
  67868. + iotable_init(&desc, 1);
  67869. + dwc_otg_device->os_dep.base = (void *)desc.virtual;
  67870. + }
  67871. +#endif
  67872. + if (!dwc_otg_device->os_dep.base) {
  67873. + dev_err(&_dev->dev, "ioremap() failed\n");
  67874. + retval = -ENOMEM;
  67875. + goto fail;
  67876. + }
  67877. + dev_dbg(&_dev->dev, "base=0x%08x\n",
  67878. + (unsigned)dwc_otg_device->os_dep.base);
  67879. +#endif
  67880. +
  67881. + /*
  67882. + * Initialize driver data to point to the global DWC_otg
  67883. + * Device structure.
  67884. + */
  67885. +#ifdef LM_INTERFACE
  67886. + lm_set_drvdata(_dev, dwc_otg_device);
  67887. +#elif defined(PLATFORM_INTERFACE)
  67888. + platform_set_drvdata(_dev, dwc_otg_device);
  67889. +#endif
  67890. + dev_dbg(&_dev->dev, "dwc_otg_device=0x%p\n", dwc_otg_device);
  67891. +
  67892. + dwc_otg_device->core_if = dwc_otg_cil_init(dwc_otg_device->os_dep.base);
  67893. + DWC_DEBUGPL(DBG_HCDV, "probe of device %p given core_if %p\n",
  67894. + dwc_otg_device, dwc_otg_device->core_if);//GRAYG
  67895. +
  67896. + if (!dwc_otg_device->core_if) {
  67897. + dev_err(&_dev->dev, "CIL initialization failed!\n");
  67898. + retval = -ENOMEM;
  67899. + goto fail;
  67900. + }
  67901. +
  67902. + dev_dbg(&_dev->dev, "Calling get_gsnpsid\n");
  67903. + /*
  67904. + * Attempt to ensure this device is really a DWC_otg Controller.
  67905. + * Read and verify the SNPSID register contents. The value should be
  67906. + * 0x45F42XXX or 0x45F42XXX, which corresponds to either "OT2" or "OTG3",
  67907. + * as in "OTG version 2.XX" or "OTG version 3.XX".
  67908. + */
  67909. +
  67910. + if (((dwc_otg_get_gsnpsid(dwc_otg_device->core_if) & 0xFFFFF000) != 0x4F542000) &&
  67911. + ((dwc_otg_get_gsnpsid(dwc_otg_device->core_if) & 0xFFFFF000) != 0x4F543000)) {
  67912. + dev_err(&_dev->dev, "Bad value for SNPSID: 0x%08x\n",
  67913. + dwc_otg_get_gsnpsid(dwc_otg_device->core_if));
  67914. + retval = -EINVAL;
  67915. + goto fail;
  67916. + }
  67917. +
  67918. + /*
  67919. + * Validate parameter values.
  67920. + */
  67921. + dev_dbg(&_dev->dev, "Calling set_parameters\n");
  67922. + if (set_parameters(dwc_otg_device->core_if)) {
  67923. + retval = -EINVAL;
  67924. + goto fail;
  67925. + }
  67926. +
  67927. + /*
  67928. + * Create Device Attributes in sysfs
  67929. + */
  67930. + dev_dbg(&_dev->dev, "Calling attr_create\n");
  67931. + dwc_otg_attr_create(_dev);
  67932. +
  67933. + /*
  67934. + * Disable the global interrupt until all the interrupt
  67935. + * handlers are installed.
  67936. + */
  67937. + dev_dbg(&_dev->dev, "Calling disable_global_interrupts\n");
  67938. + dwc_otg_disable_global_interrupts(dwc_otg_device->core_if);
  67939. +
  67940. + /*
  67941. + * Install the interrupt handler for the common interrupts before
  67942. + * enabling common interrupts in core_init below.
  67943. + */
  67944. +
  67945. +#if defined(PLATFORM_INTERFACE)
  67946. + devirq = platform_get_irq(_dev, 0);
  67947. +#else
  67948. + devirq = _dev->irq;
  67949. +#endif
  67950. + DWC_DEBUGPL(DBG_CIL, "registering (common) handler for irq%d\n",
  67951. + devirq);
  67952. + dev_dbg(&_dev->dev, "Calling request_irq(%d)\n", devirq);
  67953. + retval = request_irq(devirq, dwc_otg_common_irq,
  67954. + IRQF_SHARED,
  67955. + "dwc_otg", dwc_otg_device);
  67956. + if (retval) {
  67957. + DWC_ERROR("request of irq%d failed\n", devirq);
  67958. + retval = -EBUSY;
  67959. + goto fail;
  67960. + } else {
  67961. + dwc_otg_device->common_irq_installed = 1;
  67962. + }
  67963. +
  67964. +#ifndef IRQF_TRIGGER_LOW
  67965. +#if defined(LM_INTERFACE) || defined(PLATFORM_INTERFACE)
  67966. + dev_dbg(&_dev->dev, "Calling set_irq_type\n");
  67967. + set_irq_type(devirq,
  67968. +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30))
  67969. + IRQT_LOW
  67970. +#else
  67971. + IRQ_TYPE_LEVEL_LOW
  67972. +#endif
  67973. + );
  67974. +#endif
  67975. +#endif /*IRQF_TRIGGER_LOW*/
  67976. +
  67977. + /*
  67978. + * Initialize the DWC_otg core.
  67979. + */
  67980. + dev_dbg(&_dev->dev, "Calling dwc_otg_core_init\n");
  67981. + dwc_otg_core_init(dwc_otg_device->core_if);
  67982. +
  67983. +#ifndef DWC_HOST_ONLY
  67984. + /*
  67985. + * Initialize the PCD
  67986. + */
  67987. + dev_dbg(&_dev->dev, "Calling pcd_init\n");
  67988. + retval = pcd_init(_dev);
  67989. + if (retval != 0) {
  67990. + DWC_ERROR("pcd_init failed\n");
  67991. + dwc_otg_device->pcd = NULL;
  67992. + goto fail;
  67993. + }
  67994. +#endif
  67995. +#ifndef DWC_DEVICE_ONLY
  67996. + /*
  67997. + * Initialize the HCD
  67998. + */
  67999. + dev_dbg(&_dev->dev, "Calling hcd_init\n");
  68000. + retval = hcd_init(_dev);
  68001. + if (retval != 0) {
  68002. + DWC_ERROR("hcd_init failed\n");
  68003. + dwc_otg_device->hcd = NULL;
  68004. + goto fail;
  68005. + }
  68006. +#endif
  68007. + /* Recover from drvdata having been overwritten by hcd_init() */
  68008. +#ifdef LM_INTERFACE
  68009. + lm_set_drvdata(_dev, dwc_otg_device);
  68010. +#elif defined(PLATFORM_INTERFACE)
  68011. + platform_set_drvdata(_dev, dwc_otg_device);
  68012. +#elif defined(PCI_INTERFACE)
  68013. + pci_set_drvdata(_dev, dwc_otg_device);
  68014. + dwc_otg_device->os_dep.pcidev = _dev;
  68015. +#endif
  68016. +
  68017. + /*
  68018. + * Enable the global interrupt after all the interrupt
  68019. + * handlers are installed if there is no ADP support else
  68020. + * perform initial actions required for Internal ADP logic.
  68021. + */
  68022. + if (!dwc_otg_get_param_adp_enable(dwc_otg_device->core_if)) {
  68023. + dev_dbg(&_dev->dev, "Calling enable_global_interrupts\n");
  68024. + dwc_otg_enable_global_interrupts(dwc_otg_device->core_if);
  68025. + dev_dbg(&_dev->dev, "Done\n");
  68026. + } else
  68027. + dwc_otg_adp_start(dwc_otg_device->core_if,
  68028. + dwc_otg_is_host_mode(dwc_otg_device->core_if));
  68029. +
  68030. + return 0;
  68031. +
  68032. +fail:
  68033. + dwc_otg_driver_remove(_dev);
  68034. + return retval;
  68035. +}
  68036. +
  68037. +/**
  68038. + * This structure defines the methods to be called by a bus driver
  68039. + * during the lifecycle of a device on that bus. Both drivers and
  68040. + * devices are registered with a bus driver. The bus driver matches
  68041. + * devices to drivers based on information in the device and driver
  68042. + * structures.
  68043. + *
  68044. + * The probe function is called when the bus driver matches a device
  68045. + * to this driver. The remove function is called when a device is
  68046. + * unregistered with the bus driver.
  68047. + */
  68048. +#ifdef LM_INTERFACE
  68049. +static struct lm_driver dwc_otg_driver = {
  68050. + .drv = {.name = (char *)dwc_driver_name,},
  68051. + .probe = dwc_otg_driver_probe,
  68052. + .remove = dwc_otg_driver_remove,
  68053. + // 'suspend' and 'resume' absent
  68054. +};
  68055. +#elif defined(PCI_INTERFACE)
  68056. +static const struct pci_device_id pci_ids[] = { {
  68057. + PCI_DEVICE(0x16c3, 0xabcd),
  68058. + .driver_data =
  68059. + (unsigned long)0xdeadbeef,
  68060. + }, { /* end: all zeroes */ }
  68061. +};
  68062. +
  68063. +MODULE_DEVICE_TABLE(pci, pci_ids);
  68064. +
  68065. +/* pci driver glue; this is a "new style" PCI driver module */
  68066. +static struct pci_driver dwc_otg_driver = {
  68067. + .name = "dwc_otg",
  68068. + .id_table = pci_ids,
  68069. +
  68070. + .probe = dwc_otg_driver_probe,
  68071. + .remove = dwc_otg_driver_remove,
  68072. +
  68073. + .driver = {
  68074. + .name = (char *)dwc_driver_name,
  68075. + },
  68076. +};
  68077. +#elif defined(PLATFORM_INTERFACE)
  68078. +static struct platform_device_id platform_ids[] = {
  68079. + {
  68080. + .name = "bcm2708_usb",
  68081. + .driver_data = (kernel_ulong_t) 0xdeadbeef,
  68082. + },
  68083. + { /* end: all zeroes */ }
  68084. +};
  68085. +MODULE_DEVICE_TABLE(platform, platform_ids);
  68086. +
  68087. +static struct platform_driver dwc_otg_driver = {
  68088. + .driver = {
  68089. + .name = (char *)dwc_driver_name,
  68090. + },
  68091. + .id_table = platform_ids,
  68092. +
  68093. + .probe = dwc_otg_driver_probe,
  68094. + .remove = dwc_otg_driver_remove,
  68095. + // no 'shutdown', 'suspend', 'resume', 'suspend_late' or 'resume_early'
  68096. +};
  68097. +#endif
  68098. +
  68099. +/**
  68100. + * This function is called when the dwc_otg_driver is installed with the
  68101. + * insmod command. It registers the dwc_otg_driver structure with the
  68102. + * appropriate bus driver. This will cause the dwc_otg_driver_probe function
  68103. + * to be called. In addition, the bus driver will automatically expose
  68104. + * attributes defined for the device and driver in the special sysfs file
  68105. + * system.
  68106. + *
  68107. + * @return
  68108. + */
  68109. +static int __init dwc_otg_driver_init(void)
  68110. +{
  68111. + int retval = 0;
  68112. + int error;
  68113. + struct device_driver *drv;
  68114. +
  68115. + if(fiq_fsm_enable && !fiq_enable) {
  68116. + printk(KERN_WARNING "dwc_otg: fiq_fsm_enable was set without fiq_enable! Correcting.\n");
  68117. + fiq_enable = 1;
  68118. + }
  68119. +
  68120. + printk(KERN_INFO "%s: version %s (%s bus)\n", dwc_driver_name,
  68121. + DWC_DRIVER_VERSION,
  68122. +#ifdef LM_INTERFACE
  68123. + "logicmodule");
  68124. + retval = lm_driver_register(&dwc_otg_driver);
  68125. + drv = &dwc_otg_driver.drv;
  68126. +#elif defined(PCI_INTERFACE)
  68127. + "pci");
  68128. + retval = pci_register_driver(&dwc_otg_driver);
  68129. + drv = &dwc_otg_driver.driver;
  68130. +#elif defined(PLATFORM_INTERFACE)
  68131. + "platform");
  68132. + retval = platform_driver_register(&dwc_otg_driver);
  68133. + drv = &dwc_otg_driver.driver;
  68134. +#endif
  68135. + if (retval < 0) {
  68136. + printk(KERN_ERR "%s retval=%d\n", __func__, retval);
  68137. + return retval;
  68138. + }
  68139. + printk(KERN_DEBUG "dwc_otg: FIQ %s\n", fiq_enable ? "enabled":"disabled");
  68140. + printk(KERN_DEBUG "dwc_otg: NAK holdoff %s\n", nak_holdoff ? "enabled":"disabled");
  68141. + printk(KERN_DEBUG "dwc_otg: FIQ split-transaction FSM %s\n", fiq_fsm_enable ? "enabled":"disabled");
  68142. +
  68143. + error = driver_create_file(drv, &driver_attr_version);
  68144. +#ifdef DEBUG
  68145. + error = driver_create_file(drv, &driver_attr_debuglevel);
  68146. +#endif
  68147. + return retval;
  68148. +}
  68149. +
  68150. +module_init(dwc_otg_driver_init);
  68151. +
  68152. +/**
  68153. + * This function is called when the driver is removed from the kernel
  68154. + * with the rmmod command. The driver unregisters itself with its bus
  68155. + * driver.
  68156. + *
  68157. + */
  68158. +static void __exit dwc_otg_driver_cleanup(void)
  68159. +{
  68160. + printk(KERN_DEBUG "dwc_otg_driver_cleanup()\n");
  68161. +
  68162. +#ifdef LM_INTERFACE
  68163. + driver_remove_file(&dwc_otg_driver.drv, &driver_attr_debuglevel);
  68164. + driver_remove_file(&dwc_otg_driver.drv, &driver_attr_version);
  68165. + lm_driver_unregister(&dwc_otg_driver);
  68166. +#elif defined(PCI_INTERFACE)
  68167. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_debuglevel);
  68168. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_version);
  68169. + pci_unregister_driver(&dwc_otg_driver);
  68170. +#elif defined(PLATFORM_INTERFACE)
  68171. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_debuglevel);
  68172. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_version);
  68173. + platform_driver_unregister(&dwc_otg_driver);
  68174. +#endif
  68175. +
  68176. + printk(KERN_INFO "%s module removed\n", dwc_driver_name);
  68177. +}
  68178. +
  68179. +module_exit(dwc_otg_driver_cleanup);
  68180. +
  68181. +MODULE_DESCRIPTION(DWC_DRIVER_DESC);
  68182. +MODULE_AUTHOR("Synopsys Inc.");
  68183. +MODULE_LICENSE("GPL");
  68184. +
  68185. +module_param_named(otg_cap, dwc_otg_module_params.otg_cap, int, 0444);
  68186. +MODULE_PARM_DESC(otg_cap, "OTG Capabilities 0=HNP&SRP 1=SRP Only 2=None");
  68187. +module_param_named(opt, dwc_otg_module_params.opt, int, 0444);
  68188. +MODULE_PARM_DESC(opt, "OPT Mode");
  68189. +module_param_named(dma_enable, dwc_otg_module_params.dma_enable, int, 0444);
  68190. +MODULE_PARM_DESC(dma_enable, "DMA Mode 0=Slave 1=DMA enabled");
  68191. +
  68192. +module_param_named(dma_desc_enable, dwc_otg_module_params.dma_desc_enable, int,
  68193. + 0444);
  68194. +MODULE_PARM_DESC(dma_desc_enable,
  68195. + "DMA Desc Mode 0=Address DMA 1=DMA Descriptor enabled");
  68196. +
  68197. +module_param_named(dma_burst_size, dwc_otg_module_params.dma_burst_size, int,
  68198. + 0444);
  68199. +MODULE_PARM_DESC(dma_burst_size,
  68200. + "DMA Burst Size 1, 4, 8, 16, 32, 64, 128, 256");
  68201. +module_param_named(speed, dwc_otg_module_params.speed, int, 0444);
  68202. +MODULE_PARM_DESC(speed, "Speed 0=High Speed 1=Full Speed");
  68203. +module_param_named(host_support_fs_ls_low_power,
  68204. + dwc_otg_module_params.host_support_fs_ls_low_power, int,
  68205. + 0444);
  68206. +MODULE_PARM_DESC(host_support_fs_ls_low_power,
  68207. + "Support Low Power w/FS or LS 0=Support 1=Don't Support");
  68208. +module_param_named(host_ls_low_power_phy_clk,
  68209. + dwc_otg_module_params.host_ls_low_power_phy_clk, int, 0444);
  68210. +MODULE_PARM_DESC(host_ls_low_power_phy_clk,
  68211. + "Low Speed Low Power Clock 0=48Mhz 1=6Mhz");
  68212. +module_param_named(enable_dynamic_fifo,
  68213. + dwc_otg_module_params.enable_dynamic_fifo, int, 0444);
  68214. +MODULE_PARM_DESC(enable_dynamic_fifo, "0=cC Setting 1=Allow Dynamic Sizing");
  68215. +module_param_named(data_fifo_size, dwc_otg_module_params.data_fifo_size, int,
  68216. + 0444);
  68217. +MODULE_PARM_DESC(data_fifo_size,
  68218. + "Total number of words in the data FIFO memory 32-32768");
  68219. +module_param_named(dev_rx_fifo_size, dwc_otg_module_params.dev_rx_fifo_size,
  68220. + int, 0444);
  68221. +MODULE_PARM_DESC(dev_rx_fifo_size, "Number of words in the Rx FIFO 16-32768");
  68222. +module_param_named(dev_nperio_tx_fifo_size,
  68223. + dwc_otg_module_params.dev_nperio_tx_fifo_size, int, 0444);
  68224. +MODULE_PARM_DESC(dev_nperio_tx_fifo_size,
  68225. + "Number of words in the non-periodic Tx FIFO 16-32768");
  68226. +module_param_named(dev_perio_tx_fifo_size_1,
  68227. + dwc_otg_module_params.dev_perio_tx_fifo_size[0], int, 0444);
  68228. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_1,
  68229. + "Number of words in the periodic Tx FIFO 4-768");
  68230. +module_param_named(dev_perio_tx_fifo_size_2,
  68231. + dwc_otg_module_params.dev_perio_tx_fifo_size[1], int, 0444);
  68232. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_2,
  68233. + "Number of words in the periodic Tx FIFO 4-768");
  68234. +module_param_named(dev_perio_tx_fifo_size_3,
  68235. + dwc_otg_module_params.dev_perio_tx_fifo_size[2], int, 0444);
  68236. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_3,
  68237. + "Number of words in the periodic Tx FIFO 4-768");
  68238. +module_param_named(dev_perio_tx_fifo_size_4,
  68239. + dwc_otg_module_params.dev_perio_tx_fifo_size[3], int, 0444);
  68240. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_4,
  68241. + "Number of words in the periodic Tx FIFO 4-768");
  68242. +module_param_named(dev_perio_tx_fifo_size_5,
  68243. + dwc_otg_module_params.dev_perio_tx_fifo_size[4], int, 0444);
  68244. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_5,
  68245. + "Number of words in the periodic Tx FIFO 4-768");
  68246. +module_param_named(dev_perio_tx_fifo_size_6,
  68247. + dwc_otg_module_params.dev_perio_tx_fifo_size[5], int, 0444);
  68248. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_6,
  68249. + "Number of words in the periodic Tx FIFO 4-768");
  68250. +module_param_named(dev_perio_tx_fifo_size_7,
  68251. + dwc_otg_module_params.dev_perio_tx_fifo_size[6], int, 0444);
  68252. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_7,
  68253. + "Number of words in the periodic Tx FIFO 4-768");
  68254. +module_param_named(dev_perio_tx_fifo_size_8,
  68255. + dwc_otg_module_params.dev_perio_tx_fifo_size[7], int, 0444);
  68256. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_8,
  68257. + "Number of words in the periodic Tx FIFO 4-768");
  68258. +module_param_named(dev_perio_tx_fifo_size_9,
  68259. + dwc_otg_module_params.dev_perio_tx_fifo_size[8], int, 0444);
  68260. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_9,
  68261. + "Number of words in the periodic Tx FIFO 4-768");
  68262. +module_param_named(dev_perio_tx_fifo_size_10,
  68263. + dwc_otg_module_params.dev_perio_tx_fifo_size[9], int, 0444);
  68264. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_10,
  68265. + "Number of words in the periodic Tx FIFO 4-768");
  68266. +module_param_named(dev_perio_tx_fifo_size_11,
  68267. + dwc_otg_module_params.dev_perio_tx_fifo_size[10], int, 0444);
  68268. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_11,
  68269. + "Number of words in the periodic Tx FIFO 4-768");
  68270. +module_param_named(dev_perio_tx_fifo_size_12,
  68271. + dwc_otg_module_params.dev_perio_tx_fifo_size[11], int, 0444);
  68272. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_12,
  68273. + "Number of words in the periodic Tx FIFO 4-768");
  68274. +module_param_named(dev_perio_tx_fifo_size_13,
  68275. + dwc_otg_module_params.dev_perio_tx_fifo_size[12], int, 0444);
  68276. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_13,
  68277. + "Number of words in the periodic Tx FIFO 4-768");
  68278. +module_param_named(dev_perio_tx_fifo_size_14,
  68279. + dwc_otg_module_params.dev_perio_tx_fifo_size[13], int, 0444);
  68280. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_14,
  68281. + "Number of words in the periodic Tx FIFO 4-768");
  68282. +module_param_named(dev_perio_tx_fifo_size_15,
  68283. + dwc_otg_module_params.dev_perio_tx_fifo_size[14], int, 0444);
  68284. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_15,
  68285. + "Number of words in the periodic Tx FIFO 4-768");
  68286. +module_param_named(host_rx_fifo_size, dwc_otg_module_params.host_rx_fifo_size,
  68287. + int, 0444);
  68288. +MODULE_PARM_DESC(host_rx_fifo_size, "Number of words in the Rx FIFO 16-32768");
  68289. +module_param_named(host_nperio_tx_fifo_size,
  68290. + dwc_otg_module_params.host_nperio_tx_fifo_size, int, 0444);
  68291. +MODULE_PARM_DESC(host_nperio_tx_fifo_size,
  68292. + "Number of words in the non-periodic Tx FIFO 16-32768");
  68293. +module_param_named(host_perio_tx_fifo_size,
  68294. + dwc_otg_module_params.host_perio_tx_fifo_size, int, 0444);
  68295. +MODULE_PARM_DESC(host_perio_tx_fifo_size,
  68296. + "Number of words in the host periodic Tx FIFO 16-32768");
  68297. +module_param_named(max_transfer_size, dwc_otg_module_params.max_transfer_size,
  68298. + int, 0444);
  68299. +/** @todo Set the max to 512K, modify checks */
  68300. +MODULE_PARM_DESC(max_transfer_size,
  68301. + "The maximum transfer size supported in bytes 2047-65535");
  68302. +module_param_named(max_packet_count, dwc_otg_module_params.max_packet_count,
  68303. + int, 0444);
  68304. +MODULE_PARM_DESC(max_packet_count,
  68305. + "The maximum number of packets in a transfer 15-511");
  68306. +module_param_named(host_channels, dwc_otg_module_params.host_channels, int,
  68307. + 0444);
  68308. +MODULE_PARM_DESC(host_channels,
  68309. + "The number of host channel registers to use 1-16");
  68310. +module_param_named(dev_endpoints, dwc_otg_module_params.dev_endpoints, int,
  68311. + 0444);
  68312. +MODULE_PARM_DESC(dev_endpoints,
  68313. + "The number of endpoints in addition to EP0 available for device mode 1-15");
  68314. +module_param_named(phy_type, dwc_otg_module_params.phy_type, int, 0444);
  68315. +MODULE_PARM_DESC(phy_type, "0=Reserved 1=UTMI+ 2=ULPI");
  68316. +module_param_named(phy_utmi_width, dwc_otg_module_params.phy_utmi_width, int,
  68317. + 0444);
  68318. +MODULE_PARM_DESC(phy_utmi_width, "Specifies the UTMI+ Data Width 8 or 16 bits");
  68319. +module_param_named(phy_ulpi_ddr, dwc_otg_module_params.phy_ulpi_ddr, int, 0444);
  68320. +MODULE_PARM_DESC(phy_ulpi_ddr,
  68321. + "ULPI at double or single data rate 0=Single 1=Double");
  68322. +module_param_named(phy_ulpi_ext_vbus, dwc_otg_module_params.phy_ulpi_ext_vbus,
  68323. + int, 0444);
  68324. +MODULE_PARM_DESC(phy_ulpi_ext_vbus,
  68325. + "ULPI PHY using internal or external vbus 0=Internal");
  68326. +module_param_named(i2c_enable, dwc_otg_module_params.i2c_enable, int, 0444);
  68327. +MODULE_PARM_DESC(i2c_enable, "FS PHY Interface");
  68328. +module_param_named(ulpi_fs_ls, dwc_otg_module_params.ulpi_fs_ls, int, 0444);
  68329. +MODULE_PARM_DESC(ulpi_fs_ls, "ULPI PHY FS/LS mode only");
  68330. +module_param_named(ts_dline, dwc_otg_module_params.ts_dline, int, 0444);
  68331. +MODULE_PARM_DESC(ts_dline, "Term select Dline pulsing for all PHYs");
  68332. +module_param_named(debug, g_dbg_lvl, int, 0444);
  68333. +MODULE_PARM_DESC(debug, "");
  68334. +
  68335. +module_param_named(en_multiple_tx_fifo,
  68336. + dwc_otg_module_params.en_multiple_tx_fifo, int, 0444);
  68337. +MODULE_PARM_DESC(en_multiple_tx_fifo,
  68338. + "Dedicated Non Periodic Tx FIFOs 0=disabled 1=enabled");
  68339. +module_param_named(dev_tx_fifo_size_1,
  68340. + dwc_otg_module_params.dev_tx_fifo_size[0], int, 0444);
  68341. +MODULE_PARM_DESC(dev_tx_fifo_size_1, "Number of words in the Tx FIFO 4-768");
  68342. +module_param_named(dev_tx_fifo_size_2,
  68343. + dwc_otg_module_params.dev_tx_fifo_size[1], int, 0444);
  68344. +MODULE_PARM_DESC(dev_tx_fifo_size_2, "Number of words in the Tx FIFO 4-768");
  68345. +module_param_named(dev_tx_fifo_size_3,
  68346. + dwc_otg_module_params.dev_tx_fifo_size[2], int, 0444);
  68347. +MODULE_PARM_DESC(dev_tx_fifo_size_3, "Number of words in the Tx FIFO 4-768");
  68348. +module_param_named(dev_tx_fifo_size_4,
  68349. + dwc_otg_module_params.dev_tx_fifo_size[3], int, 0444);
  68350. +MODULE_PARM_DESC(dev_tx_fifo_size_4, "Number of words in the Tx FIFO 4-768");
  68351. +module_param_named(dev_tx_fifo_size_5,
  68352. + dwc_otg_module_params.dev_tx_fifo_size[4], int, 0444);
  68353. +MODULE_PARM_DESC(dev_tx_fifo_size_5, "Number of words in the Tx FIFO 4-768");
  68354. +module_param_named(dev_tx_fifo_size_6,
  68355. + dwc_otg_module_params.dev_tx_fifo_size[5], int, 0444);
  68356. +MODULE_PARM_DESC(dev_tx_fifo_size_6, "Number of words in the Tx FIFO 4-768");
  68357. +module_param_named(dev_tx_fifo_size_7,
  68358. + dwc_otg_module_params.dev_tx_fifo_size[6], int, 0444);
  68359. +MODULE_PARM_DESC(dev_tx_fifo_size_7, "Number of words in the Tx FIFO 4-768");
  68360. +module_param_named(dev_tx_fifo_size_8,
  68361. + dwc_otg_module_params.dev_tx_fifo_size[7], int, 0444);
  68362. +MODULE_PARM_DESC(dev_tx_fifo_size_8, "Number of words in the Tx FIFO 4-768");
  68363. +module_param_named(dev_tx_fifo_size_9,
  68364. + dwc_otg_module_params.dev_tx_fifo_size[8], int, 0444);
  68365. +MODULE_PARM_DESC(dev_tx_fifo_size_9, "Number of words in the Tx FIFO 4-768");
  68366. +module_param_named(dev_tx_fifo_size_10,
  68367. + dwc_otg_module_params.dev_tx_fifo_size[9], int, 0444);
  68368. +MODULE_PARM_DESC(dev_tx_fifo_size_10, "Number of words in the Tx FIFO 4-768");
  68369. +module_param_named(dev_tx_fifo_size_11,
  68370. + dwc_otg_module_params.dev_tx_fifo_size[10], int, 0444);
  68371. +MODULE_PARM_DESC(dev_tx_fifo_size_11, "Number of words in the Tx FIFO 4-768");
  68372. +module_param_named(dev_tx_fifo_size_12,
  68373. + dwc_otg_module_params.dev_tx_fifo_size[11], int, 0444);
  68374. +MODULE_PARM_DESC(dev_tx_fifo_size_12, "Number of words in the Tx FIFO 4-768");
  68375. +module_param_named(dev_tx_fifo_size_13,
  68376. + dwc_otg_module_params.dev_tx_fifo_size[12], int, 0444);
  68377. +MODULE_PARM_DESC(dev_tx_fifo_size_13, "Number of words in the Tx FIFO 4-768");
  68378. +module_param_named(dev_tx_fifo_size_14,
  68379. + dwc_otg_module_params.dev_tx_fifo_size[13], int, 0444);
  68380. +MODULE_PARM_DESC(dev_tx_fifo_size_14, "Number of words in the Tx FIFO 4-768");
  68381. +module_param_named(dev_tx_fifo_size_15,
  68382. + dwc_otg_module_params.dev_tx_fifo_size[14], int, 0444);
  68383. +MODULE_PARM_DESC(dev_tx_fifo_size_15, "Number of words in the Tx FIFO 4-768");
  68384. +
  68385. +module_param_named(thr_ctl, dwc_otg_module_params.thr_ctl, int, 0444);
  68386. +MODULE_PARM_DESC(thr_ctl,
  68387. + "Thresholding enable flag bit 0 - non ISO Tx thr., 1 - ISO Tx thr., 2 - Rx thr.- bit 0=disabled 1=enabled");
  68388. +module_param_named(tx_thr_length, dwc_otg_module_params.tx_thr_length, int,
  68389. + 0444);
  68390. +MODULE_PARM_DESC(tx_thr_length, "Tx Threshold length in 32 bit DWORDs");
  68391. +module_param_named(rx_thr_length, dwc_otg_module_params.rx_thr_length, int,
  68392. + 0444);
  68393. +MODULE_PARM_DESC(rx_thr_length, "Rx Threshold length in 32 bit DWORDs");
  68394. +
  68395. +module_param_named(pti_enable, dwc_otg_module_params.pti_enable, int, 0444);
  68396. +module_param_named(mpi_enable, dwc_otg_module_params.mpi_enable, int, 0444);
  68397. +module_param_named(lpm_enable, dwc_otg_module_params.lpm_enable, int, 0444);
  68398. +MODULE_PARM_DESC(lpm_enable, "LPM Enable 0=LPM Disabled 1=LPM Enabled");
  68399. +module_param_named(ic_usb_cap, dwc_otg_module_params.ic_usb_cap, int, 0444);
  68400. +MODULE_PARM_DESC(ic_usb_cap,
  68401. + "IC_USB Capability 0=IC_USB Disabled 1=IC_USB Enabled");
  68402. +module_param_named(ahb_thr_ratio, dwc_otg_module_params.ahb_thr_ratio, int,
  68403. + 0444);
  68404. +MODULE_PARM_DESC(ahb_thr_ratio, "AHB Threshold Ratio");
  68405. +module_param_named(power_down, dwc_otg_module_params.power_down, int, 0444);
  68406. +MODULE_PARM_DESC(power_down, "Power Down Mode");
  68407. +module_param_named(reload_ctl, dwc_otg_module_params.reload_ctl, int, 0444);
  68408. +MODULE_PARM_DESC(reload_ctl, "HFIR Reload Control");
  68409. +module_param_named(dev_out_nak, dwc_otg_module_params.dev_out_nak, int, 0444);
  68410. +MODULE_PARM_DESC(dev_out_nak, "Enable Device OUT NAK");
  68411. +module_param_named(cont_on_bna, dwc_otg_module_params.cont_on_bna, int, 0444);
  68412. +MODULE_PARM_DESC(cont_on_bna, "Enable Enable Continue on BNA");
  68413. +module_param_named(ahb_single, dwc_otg_module_params.ahb_single, int, 0444);
  68414. +MODULE_PARM_DESC(ahb_single, "Enable AHB Single Support");
  68415. +module_param_named(adp_enable, dwc_otg_module_params.adp_enable, int, 0444);
  68416. +MODULE_PARM_DESC(adp_enable, "ADP Enable 0=ADP Disabled 1=ADP Enabled");
  68417. +module_param_named(otg_ver, dwc_otg_module_params.otg_ver, int, 0444);
  68418. +MODULE_PARM_DESC(otg_ver, "OTG revision supported 0=OTG 1.3 1=OTG 2.0");
  68419. +module_param(microframe_schedule, bool, 0444);
  68420. +MODULE_PARM_DESC(microframe_schedule, "Enable the microframe scheduler");
  68421. +
  68422. +module_param(fiq_enable, bool, 0444);
  68423. +MODULE_PARM_DESC(fiq_enable, "Enable the FIQ");
  68424. +module_param(nak_holdoff, ushort, 0644);
  68425. +MODULE_PARM_DESC(nak_holdoff, "Throttle duration for bulk split-transaction endpoints on a NAK. Default 8");
  68426. +module_param(fiq_fsm_enable, bool, 0444);
  68427. +MODULE_PARM_DESC(fiq_fsm_enable, "Enable the FIQ to perform split transactions as defined by fiq_fsm_mask");
  68428. +module_param(fiq_fsm_mask, ushort, 0444);
  68429. +MODULE_PARM_DESC(fiq_fsm_mask, "Bitmask of transactions to perform in the FIQ.\n"
  68430. + "Bit 0 : Non-periodic split transactions\n"
  68431. + "Bit 1 : Periodic split transactions\n"
  68432. + "Bit 2 : High-speed multi-transfer isochronous\n"
  68433. + "All other bits should be set 0.");
  68434. +
  68435. +
  68436. +/** @page "Module Parameters"
  68437. + *
  68438. + * The following parameters may be specified when starting the module.
  68439. + * These parameters define how the DWC_otg controller should be
  68440. + * configured. Parameter values are passed to the CIL initialization
  68441. + * function dwc_otg_cil_init
  68442. + *
  68443. + * Example: <code>modprobe dwc_otg speed=1 otg_cap=1</code>
  68444. + *
  68445. +
  68446. + <table>
  68447. + <tr><td>Parameter Name</td><td>Meaning</td></tr>
  68448. +
  68449. + <tr>
  68450. + <td>otg_cap</td>
  68451. + <td>Specifies the OTG capabilities. The driver will automatically detect the
  68452. + value for this parameter if none is specified.
  68453. + - 0: HNP and SRP capable (default, if available)
  68454. + - 1: SRP Only capable
  68455. + - 2: No HNP/SRP capable
  68456. + </td></tr>
  68457. +
  68458. + <tr>
  68459. + <td>dma_enable</td>
  68460. + <td>Specifies whether to use slave or DMA mode for accessing the data FIFOs.
  68461. + The driver will automatically detect the value for this parameter if none is
  68462. + specified.
  68463. + - 0: Slave
  68464. + - 1: DMA (default, if available)
  68465. + </td></tr>
  68466. +
  68467. + <tr>
  68468. + <td>dma_burst_size</td>
  68469. + <td>The DMA Burst size (applicable only for External DMA Mode).
  68470. + - Values: 1, 4, 8 16, 32, 64, 128, 256 (default 32)
  68471. + </td></tr>
  68472. +
  68473. + <tr>
  68474. + <td>speed</td>
  68475. + <td>Specifies the maximum speed of operation in host and device mode. The
  68476. + actual speed depends on the speed of the attached device and the value of
  68477. + phy_type.
  68478. + - 0: High Speed (default)
  68479. + - 1: Full Speed
  68480. + </td></tr>
  68481. +
  68482. + <tr>
  68483. + <td>host_support_fs_ls_low_power</td>
  68484. + <td>Specifies whether low power mode is supported when attached to a Full
  68485. + Speed or Low Speed device in host mode.
  68486. + - 0: Don't support low power mode (default)
  68487. + - 1: Support low power mode
  68488. + </td></tr>
  68489. +
  68490. + <tr>
  68491. + <td>host_ls_low_power_phy_clk</td>
  68492. + <td>Specifies the PHY clock rate in low power mode when connected to a Low
  68493. + Speed device in host mode. This parameter is applicable only if
  68494. + HOST_SUPPORT_FS_LS_LOW_POWER is enabled.
  68495. + - 0: 48 MHz (default)
  68496. + - 1: 6 MHz
  68497. + </td></tr>
  68498. +
  68499. + <tr>
  68500. + <td>enable_dynamic_fifo</td>
  68501. + <td> Specifies whether FIFOs may be resized by the driver software.
  68502. + - 0: Use cC FIFO size parameters
  68503. + - 1: Allow dynamic FIFO sizing (default)
  68504. + </td></tr>
  68505. +
  68506. + <tr>
  68507. + <td>data_fifo_size</td>
  68508. + <td>Total number of 4-byte words in the data FIFO memory. This memory
  68509. + includes the Rx FIFO, non-periodic Tx FIFO, and periodic Tx FIFOs.
  68510. + - Values: 32 to 32768 (default 8192)
  68511. +
  68512. + Note: The total FIFO memory depth in the FPGA configuration is 8192.
  68513. + </td></tr>
  68514. +
  68515. + <tr>
  68516. + <td>dev_rx_fifo_size</td>
  68517. + <td>Number of 4-byte words in the Rx FIFO in device mode when dynamic
  68518. + FIFO sizing is enabled.
  68519. + - Values: 16 to 32768 (default 1064)
  68520. + </td></tr>
  68521. +
  68522. + <tr>
  68523. + <td>dev_nperio_tx_fifo_size</td>
  68524. + <td>Number of 4-byte words in the non-periodic Tx FIFO in device mode when
  68525. + dynamic FIFO sizing is enabled.
  68526. + - Values: 16 to 32768 (default 1024)
  68527. + </td></tr>
  68528. +
  68529. + <tr>
  68530. + <td>dev_perio_tx_fifo_size_n (n = 1 to 15)</td>
  68531. + <td>Number of 4-byte words in each of the periodic Tx FIFOs in device mode
  68532. + when dynamic FIFO sizing is enabled.
  68533. + - Values: 4 to 768 (default 256)
  68534. + </td></tr>
  68535. +
  68536. + <tr>
  68537. + <td>host_rx_fifo_size</td>
  68538. + <td>Number of 4-byte words in the Rx FIFO in host mode when dynamic FIFO
  68539. + sizing is enabled.
  68540. + - Values: 16 to 32768 (default 1024)
  68541. + </td></tr>
  68542. +
  68543. + <tr>
  68544. + <td>host_nperio_tx_fifo_size</td>
  68545. + <td>Number of 4-byte words in the non-periodic Tx FIFO in host mode when
  68546. + dynamic FIFO sizing is enabled in the core.
  68547. + - Values: 16 to 32768 (default 1024)
  68548. + </td></tr>
  68549. +
  68550. + <tr>
  68551. + <td>host_perio_tx_fifo_size</td>
  68552. + <td>Number of 4-byte words in the host periodic Tx FIFO when dynamic FIFO
  68553. + sizing is enabled.
  68554. + - Values: 16 to 32768 (default 1024)
  68555. + </td></tr>
  68556. +
  68557. + <tr>
  68558. + <td>max_transfer_size</td>
  68559. + <td>The maximum transfer size supported in bytes.
  68560. + - Values: 2047 to 65,535 (default 65,535)
  68561. + </td></tr>
  68562. +
  68563. + <tr>
  68564. + <td>max_packet_count</td>
  68565. + <td>The maximum number of packets in a transfer.
  68566. + - Values: 15 to 511 (default 511)
  68567. + </td></tr>
  68568. +
  68569. + <tr>
  68570. + <td>host_channels</td>
  68571. + <td>The number of host channel registers to use.
  68572. + - Values: 1 to 16 (default 12)
  68573. +
  68574. + Note: The FPGA configuration supports a maximum of 12 host channels.
  68575. + </td></tr>
  68576. +
  68577. + <tr>
  68578. + <td>dev_endpoints</td>
  68579. + <td>The number of endpoints in addition to EP0 available for device mode
  68580. + operations.
  68581. + - Values: 1 to 15 (default 6 IN and OUT)
  68582. +
  68583. + Note: The FPGA configuration supports a maximum of 6 IN and OUT endpoints in
  68584. + addition to EP0.
  68585. + </td></tr>
  68586. +
  68587. + <tr>
  68588. + <td>phy_type</td>
  68589. + <td>Specifies the type of PHY interface to use. By default, the driver will
  68590. + automatically detect the phy_type.
  68591. + - 0: Full Speed
  68592. + - 1: UTMI+ (default, if available)
  68593. + - 2: ULPI
  68594. + </td></tr>
  68595. +
  68596. + <tr>
  68597. + <td>phy_utmi_width</td>
  68598. + <td>Specifies the UTMI+ Data Width. This parameter is applicable for a
  68599. + phy_type of UTMI+. Also, this parameter is applicable only if the
  68600. + OTG_HSPHY_WIDTH cC parameter was set to "8 and 16 bits", meaning that the
  68601. + core has been configured to work at either data path width.
  68602. + - Values: 8 or 16 bits (default 16)
  68603. + </td></tr>
  68604. +
  68605. + <tr>
  68606. + <td>phy_ulpi_ddr</td>
  68607. + <td>Specifies whether the ULPI operates at double or single data rate. This
  68608. + parameter is only applicable if phy_type is ULPI.
  68609. + - 0: single data rate ULPI interface with 8 bit wide data bus (default)
  68610. + - 1: double data rate ULPI interface with 4 bit wide data bus
  68611. + </td></tr>
  68612. +
  68613. + <tr>
  68614. + <td>i2c_enable</td>
  68615. + <td>Specifies whether to use the I2C interface for full speed PHY. This
  68616. + parameter is only applicable if PHY_TYPE is FS.
  68617. + - 0: Disabled (default)
  68618. + - 1: Enabled
  68619. + </td></tr>
  68620. +
  68621. + <tr>
  68622. + <td>ulpi_fs_ls</td>
  68623. + <td>Specifies whether to use ULPI FS/LS mode only.
  68624. + - 0: Disabled (default)
  68625. + - 1: Enabled
  68626. + </td></tr>
  68627. +
  68628. + <tr>
  68629. + <td>ts_dline</td>
  68630. + <td>Specifies whether term select D-Line pulsing for all PHYs is enabled.
  68631. + - 0: Disabled (default)
  68632. + - 1: Enabled
  68633. + </td></tr>
  68634. +
  68635. + <tr>
  68636. + <td>en_multiple_tx_fifo</td>
  68637. + <td>Specifies whether dedicatedto tx fifos are enabled for non periodic IN EPs.
  68638. + The driver will automatically detect the value for this parameter if none is
  68639. + specified.
  68640. + - 0: Disabled
  68641. + - 1: Enabled (default, if available)
  68642. + </td></tr>
  68643. +
  68644. + <tr>
  68645. + <td>dev_tx_fifo_size_n (n = 1 to 15)</td>
  68646. + <td>Number of 4-byte words in each of the Tx FIFOs in device mode
  68647. + when dynamic FIFO sizing is enabled.
  68648. + - Values: 4 to 768 (default 256)
  68649. + </td></tr>
  68650. +
  68651. + <tr>
  68652. + <td>tx_thr_length</td>
  68653. + <td>Transmit Threshold length in 32 bit double words
  68654. + - Values: 8 to 128 (default 64)
  68655. + </td></tr>
  68656. +
  68657. + <tr>
  68658. + <td>rx_thr_length</td>
  68659. + <td>Receive Threshold length in 32 bit double words
  68660. + - Values: 8 to 128 (default 64)
  68661. + </td></tr>
  68662. +
  68663. +<tr>
  68664. + <td>thr_ctl</td>
  68665. + <td>Specifies whether to enable Thresholding for Device mode. Bits 0, 1, 2 of
  68666. + this parmater specifies if thresholding is enabled for non-Iso Tx, Iso Tx and
  68667. + Rx transfers accordingly.
  68668. + The driver will automatically detect the value for this parameter if none is
  68669. + specified.
  68670. + - Values: 0 to 7 (default 0)
  68671. + Bit values indicate:
  68672. + - 0: Thresholding disabled
  68673. + - 1: Thresholding enabled
  68674. + </td></tr>
  68675. +
  68676. +<tr>
  68677. + <td>dma_desc_enable</td>
  68678. + <td>Specifies whether to enable Descriptor DMA mode.
  68679. + The driver will automatically detect the value for this parameter if none is
  68680. + specified.
  68681. + - 0: Descriptor DMA disabled
  68682. + - 1: Descriptor DMA (default, if available)
  68683. + </td></tr>
  68684. +
  68685. +<tr>
  68686. + <td>mpi_enable</td>
  68687. + <td>Specifies whether to enable MPI enhancement mode.
  68688. + The driver will automatically detect the value for this parameter if none is
  68689. + specified.
  68690. + - 0: MPI disabled (default)
  68691. + - 1: MPI enable
  68692. + </td></tr>
  68693. +
  68694. +<tr>
  68695. + <td>pti_enable</td>
  68696. + <td>Specifies whether to enable PTI enhancement support.
  68697. + The driver will automatically detect the value for this parameter if none is
  68698. + specified.
  68699. + - 0: PTI disabled (default)
  68700. + - 1: PTI enable
  68701. + </td></tr>
  68702. +
  68703. +<tr>
  68704. + <td>lpm_enable</td>
  68705. + <td>Specifies whether to enable LPM support.
  68706. + The driver will automatically detect the value for this parameter if none is
  68707. + specified.
  68708. + - 0: LPM disabled
  68709. + - 1: LPM enable (default, if available)
  68710. + </td></tr>
  68711. +
  68712. +<tr>
  68713. + <td>ic_usb_cap</td>
  68714. + <td>Specifies whether to enable IC_USB capability.
  68715. + The driver will automatically detect the value for this parameter if none is
  68716. + specified.
  68717. + - 0: IC_USB disabled (default, if available)
  68718. + - 1: IC_USB enable
  68719. + </td></tr>
  68720. +
  68721. +<tr>
  68722. + <td>ahb_thr_ratio</td>
  68723. + <td>Specifies AHB Threshold ratio.
  68724. + - Values: 0 to 3 (default 0)
  68725. + </td></tr>
  68726. +
  68727. +<tr>
  68728. + <td>power_down</td>
  68729. + <td>Specifies Power Down(Hibernation) Mode.
  68730. + The driver will automatically detect the value for this parameter if none is
  68731. + specified.
  68732. + - 0: Power Down disabled (default)
  68733. + - 2: Power Down enabled
  68734. + </td></tr>
  68735. +
  68736. + <tr>
  68737. + <td>reload_ctl</td>
  68738. + <td>Specifies whether dynamic reloading of the HFIR register is allowed during
  68739. + run time. The driver will automatically detect the value for this parameter if
  68740. + none is specified. In case the HFIR value is reloaded when HFIR.RldCtrl == 1'b0
  68741. + the core might misbehave.
  68742. + - 0: Reload Control disabled (default)
  68743. + - 1: Reload Control enabled
  68744. + </td></tr>
  68745. +
  68746. + <tr>
  68747. + <td>dev_out_nak</td>
  68748. + <td>Specifies whether Device OUT NAK enhancement enabled or no.
  68749. + The driver will automatically detect the value for this parameter if
  68750. + none is specified. This parameter is valid only when OTG_EN_DESC_DMA == 1b1.
  68751. + - 0: The core does not set NAK after Bulk OUT transfer complete (default)
  68752. + - 1: The core sets NAK after Bulk OUT transfer complete
  68753. + </td></tr>
  68754. +
  68755. + <tr>
  68756. + <td>cont_on_bna</td>
  68757. + <td>Specifies whether Enable Continue on BNA enabled or no.
  68758. + After receiving BNA interrupt the core disables the endpoint,when the
  68759. + endpoint is re-enabled by the application the
  68760. + - 0: Core starts processing from the DOEPDMA descriptor (default)
  68761. + - 1: Core starts processing from the descriptor which received the BNA.
  68762. + This parameter is valid only when OTG_EN_DESC_DMA == 1b1.
  68763. + </td></tr>
  68764. +
  68765. + <tr>
  68766. + <td>ahb_single</td>
  68767. + <td>This bit when programmed supports SINGLE transfers for remainder data
  68768. + in a transfer for DMA mode of operation.
  68769. + - 0: The remainder data will be sent using INCR burst size (default)
  68770. + - 1: The remainder data will be sent using SINGLE burst size.
  68771. + </td></tr>
  68772. +
  68773. +<tr>
  68774. + <td>adp_enable</td>
  68775. + <td>Specifies whether ADP feature is enabled.
  68776. + The driver will automatically detect the value for this parameter if none is
  68777. + specified.
  68778. + - 0: ADP feature disabled (default)
  68779. + - 1: ADP feature enabled
  68780. + </td></tr>
  68781. +
  68782. + <tr>
  68783. + <td>otg_ver</td>
  68784. + <td>Specifies whether OTG is performing as USB OTG Revision 2.0 or Revision 1.3
  68785. + USB OTG device.
  68786. + - 0: OTG 2.0 support disabled (default)
  68787. + - 1: OTG 2.0 support enabled
  68788. + </td></tr>
  68789. +
  68790. +*/
  68791. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_driver.h linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_driver.h
  68792. --- linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_driver.h 1970-01-01 01:00:00.000000000 +0100
  68793. +++ linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_driver.h 2014-08-06 16:50:14.805964758 +0200
  68794. @@ -0,0 +1,86 @@
  68795. +/* ==========================================================================
  68796. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_driver.h $
  68797. + * $Revision: #19 $
  68798. + * $Date: 2010/11/15 $
  68799. + * $Change: 1627671 $
  68800. + *
  68801. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  68802. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  68803. + * otherwise expressly agreed to in writing between Synopsys and you.
  68804. + *
  68805. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  68806. + * any End User Software License Agreement or Agreement for Licensed Product
  68807. + * with Synopsys or any supplement thereto. You are permitted to use and
  68808. + * redistribute this Software in source and binary forms, with or without
  68809. + * modification, provided that redistributions of source code must retain this
  68810. + * notice. You may not view, use, disclose, copy or distribute this file or
  68811. + * any information contained herein except pursuant to this license grant from
  68812. + * Synopsys. If you do not agree with this notice, including the disclaimer
  68813. + * below, then you are not authorized to use the Software.
  68814. + *
  68815. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  68816. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  68817. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  68818. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  68819. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  68820. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  68821. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  68822. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  68823. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  68824. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  68825. + * DAMAGE.
  68826. + * ========================================================================== */
  68827. +
  68828. +#ifndef __DWC_OTG_DRIVER_H__
  68829. +#define __DWC_OTG_DRIVER_H__
  68830. +
  68831. +/** @file
  68832. + * This file contains the interface to the Linux driver.
  68833. + */
  68834. +#include "dwc_otg_os_dep.h"
  68835. +#include "dwc_otg_core_if.h"
  68836. +
  68837. +/* Type declarations */
  68838. +struct dwc_otg_pcd;
  68839. +struct dwc_otg_hcd;
  68840. +
  68841. +/**
  68842. + * This structure is a wrapper that encapsulates the driver components used to
  68843. + * manage a single DWC_otg controller.
  68844. + */
  68845. +typedef struct dwc_otg_device {
  68846. + /** Structure containing OS-dependent stuff. KEEP THIS STRUCT AT THE
  68847. + * VERY BEGINNING OF THE DEVICE STRUCT. OSes such as FreeBSD and NetBSD
  68848. + * require this. */
  68849. + struct os_dependent os_dep;
  68850. +
  68851. + /** Pointer to the core interface structure. */
  68852. + dwc_otg_core_if_t *core_if;
  68853. +
  68854. + /** Pointer to the PCD structure. */
  68855. + struct dwc_otg_pcd *pcd;
  68856. +
  68857. + /** Pointer to the HCD structure. */
  68858. + struct dwc_otg_hcd *hcd;
  68859. +
  68860. + /** Flag to indicate whether the common IRQ handler is installed. */
  68861. + uint8_t common_irq_installed;
  68862. +
  68863. +} dwc_otg_device_t;
  68864. +
  68865. +/*We must clear S3C24XX_EINTPEND external interrupt register
  68866. + * because after clearing in this register trigerred IRQ from
  68867. + * H/W core in kernel interrupt can be occured again before OTG
  68868. + * handlers clear all IRQ sources of Core registers because of
  68869. + * timing latencies and Low Level IRQ Type.
  68870. + */
  68871. +#ifdef CONFIG_MACH_IPMATE
  68872. +#define S3C2410X_CLEAR_EINTPEND() \
  68873. +do { \
  68874. + __raw_writel(1UL << 11,S3C24XX_EINTPEND); \
  68875. +} while (0)
  68876. +#else
  68877. +#define S3C2410X_CLEAR_EINTPEND() do { } while (0)
  68878. +#endif
  68879. +
  68880. +#endif
  68881. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c
  68882. --- linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c 1970-01-01 01:00:00.000000000 +0100
  68883. +++ linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c 2014-08-06 16:50:14.805964758 +0200
  68884. @@ -0,0 +1,1289 @@
  68885. +/*
  68886. + * dwc_otg_fiq_fsm.c - The finite state machine FIQ
  68887. + *
  68888. + * Copyright (c) 2013 Raspberry Pi Foundation
  68889. + *
  68890. + * Author: Jonathan Bell <jonathan@raspberrypi.org>
  68891. + * All rights reserved.
  68892. + *
  68893. + * Redistribution and use in source and binary forms, with or without
  68894. + * modification, are permitted provided that the following conditions are met:
  68895. + * * Redistributions of source code must retain the above copyright
  68896. + * notice, this list of conditions and the following disclaimer.
  68897. + * * Redistributions in binary form must reproduce the above copyright
  68898. + * notice, this list of conditions and the following disclaimer in the
  68899. + * documentation and/or other materials provided with the distribution.
  68900. + * * Neither the name of Raspberry Pi nor the
  68901. + * names of its contributors may be used to endorse or promote products
  68902. + * derived from this software without specific prior written permission.
  68903. + *
  68904. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  68905. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  68906. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  68907. + * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  68908. + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  68909. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  68910. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  68911. + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  68912. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  68913. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  68914. + *
  68915. + * This FIQ implements functionality that performs split transactions on
  68916. + * the dwc_otg hardware without any outside intervention. A split transaction
  68917. + * is "queued" by nominating a specific host channel to perform the entirety
  68918. + * of a split transaction. This FIQ will then perform the microframe-precise
  68919. + * scheduling required in each phase of the transaction until completion.
  68920. + *
  68921. + * The FIQ functionality is glued into the Synopsys driver via the entry point
  68922. + * in the FSM enqueue function, and at the exit point in handling a HC interrupt
  68923. + * for a FSM-enabled channel.
  68924. + *
  68925. + * NB: Large parts of this implementation have architecture-specific code.
  68926. + * For porting this functionality to other ARM machines, the minimum is required:
  68927. + * - An interrupt controller allowing the top-level dwc USB interrupt to be routed
  68928. + * to the FIQ
  68929. + * - A method of forcing a software generated interrupt from FIQ mode that then
  68930. + * triggers an IRQ entry (with the dwc USB handler called by this IRQ number)
  68931. + * - Guaranteed interrupt routing such that both the FIQ and SGI occur on the same
  68932. + * processor core - there is no locking between the FIQ and IRQ (aside from
  68933. + * local_fiq_disable)
  68934. + *
  68935. + */
  68936. +
  68937. +#include "dwc_otg_fiq_fsm.h"
  68938. +
  68939. +
  68940. +char buffer[1000*16];
  68941. +int wptr;
  68942. +void notrace _fiq_print(enum fiq_debug_level dbg_lvl, volatile struct fiq_state *state, char *fmt, ...)
  68943. +{
  68944. + enum fiq_debug_level dbg_lvl_req = FIQDBG_ERR;
  68945. + va_list args;
  68946. + char text[17];
  68947. + hfnum_data_t hfnum = { .d32 = FIQ_READ(state->dwc_regs_base + 0x408) };
  68948. +
  68949. + if((dbg_lvl & dbg_lvl_req) || dbg_lvl == FIQDBG_ERR)
  68950. + {
  68951. + snprintf(text, 9, " %4d:%1u ", hfnum.b.frnum/8, hfnum.b.frnum & 7);
  68952. + va_start(args, fmt);
  68953. + vsnprintf(text+8, 9, fmt, args);
  68954. + va_end(args);
  68955. +
  68956. + memcpy(buffer + wptr, text, 16);
  68957. + wptr = (wptr + 16) % sizeof(buffer);
  68958. + }
  68959. +}
  68960. +
  68961. +/**
  68962. + * fiq_fsm_restart_channel() - Poke channel enable bit for a split transaction
  68963. + * @channel: channel to re-enable
  68964. + */
  68965. +static void fiq_fsm_restart_channel(struct fiq_state *st, int n, int force)
  68966. +{
  68967. + hcchar_data_t hcchar = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR) };
  68968. +
  68969. + hcchar.b.chen = 0;
  68970. + if (st->channel[n].hcchar_copy.b.eptype & 0x1) {
  68971. + hfnum_data_t hfnum = { .d32 = FIQ_READ(st->dwc_regs_base + HFNUM) };
  68972. + /* Hardware bug workaround: update the ssplit index */
  68973. + if (st->channel[n].hcsplt_copy.b.spltena)
  68974. + st->channel[n].expected_uframe = (hfnum.b.frnum + 1) & 0x3FFF;
  68975. +
  68976. + hcchar.b.oddfrm = (hfnum.b.frnum & 0x1) ? 0 : 1;
  68977. + }
  68978. +
  68979. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR, hcchar.d32);
  68980. + hcchar.d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  68981. + hcchar.b.chen = 1;
  68982. +
  68983. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR, hcchar.d32);
  68984. + fiq_print(FIQDBG_INT, st, "HCGO %01d %01d", n, force);
  68985. +}
  68986. +
  68987. +/**
  68988. + * fiq_fsm_setup_csplit() - Prepare a host channel for a CSplit transaction stage
  68989. + * @st: Pointer to the channel's state
  68990. + * @n : channel number
  68991. + *
  68992. + * Change host channel registers to perform a complete-split transaction. Being mindful of the
  68993. + * endpoint direction, set control regs up correctly.
  68994. + */
  68995. +static void notrace fiq_fsm_setup_csplit(struct fiq_state *st, int n)
  68996. +{
  68997. + hcsplt_data_t hcsplt = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCSPLT) };
  68998. + hctsiz_data_t hctsiz = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ) };
  68999. +
  69000. + hcsplt.b.compsplt = 1;
  69001. + if (st->channel[n].hcchar_copy.b.epdir == 1) {
  69002. + // If IN, the CSPLIT result contains the data or a hub handshake. hctsiz = maxpacket.
  69003. + hctsiz.b.xfersize = st->channel[n].hctsiz_copy.b.xfersize;
  69004. + } else {
  69005. + // If OUT, the CSPLIT result contains handshake only.
  69006. + hctsiz.b.xfersize = 0;
  69007. + }
  69008. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCSPLT, hcsplt.d32);
  69009. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ, hctsiz.d32);
  69010. + mb();
  69011. +}
  69012. +
  69013. +static inline int notrace fiq_get_xfer_len(struct fiq_state *st, int n)
  69014. +{
  69015. + /* The xfersize register is a bit wonky. For IN transfers, it decrements by the packet size. */
  69016. + hctsiz_data_t hctsiz = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ) };
  69017. +
  69018. + if (st->channel[n].hcchar_copy.b.epdir == 0) {
  69019. + return st->channel[n].hctsiz_copy.b.xfersize;
  69020. + } else {
  69021. + return st->channel[n].hctsiz_copy.b.xfersize - hctsiz.b.xfersize;
  69022. + }
  69023. +
  69024. +}
  69025. +
  69026. +
  69027. +/**
  69028. + * fiq_increment_dma_buf() - update DMA address for bounce buffers after a CSPLIT
  69029. + *
  69030. + * Of use only for IN periodic transfers.
  69031. + */
  69032. +static int notrace fiq_increment_dma_buf(struct fiq_state *st, int num_channels, int n)
  69033. +{
  69034. + hcdma_data_t hcdma;
  69035. + int i = st->channel[n].dma_info.index;
  69036. + int len;
  69037. + struct fiq_dma_blob *blob = (struct fiq_dma_blob *) st->dma_base;
  69038. +
  69039. + len = fiq_get_xfer_len(st, n);
  69040. + fiq_print(FIQDBG_INT, st, "LEN: %03d", len);
  69041. + st->channel[n].dma_info.slot_len[i] = len;
  69042. + i++;
  69043. + if (i > 6)
  69044. + BUG();
  69045. +
  69046. + hcdma.d32 = (dma_addr_t) &blob->channel[n].index[i].buf[0];
  69047. + FIQ_WRITE(st->dwc_regs_base + HC_DMA + (HC_OFFSET * n), hcdma.d32);
  69048. + st->channel[n].dma_info.index = i;
  69049. + return 0;
  69050. +}
  69051. +
  69052. +/**
  69053. + * fiq_reload_hctsiz() - for IN transactions, reset HCTSIZ
  69054. + */
  69055. +static void notrace fiq_fsm_reload_hctsiz(struct fiq_state *st, int n)
  69056. +{
  69057. + hctsiz_data_t hctsiz = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ) };
  69058. + hctsiz.b.xfersize = st->channel[n].hctsiz_copy.b.xfersize;
  69059. + hctsiz.b.pktcnt = 1;
  69060. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ, hctsiz.d32);
  69061. +}
  69062. +
  69063. +/**
  69064. + * fiq_iso_out_advance() - update DMA address and split position bits
  69065. + * for isochronous OUT transactions.
  69066. + *
  69067. + * Returns 1 if this is the last packet queued, 0 otherwise. Split-ALL and
  69068. + * Split-BEGIN states are not handled - this is done when the transaction was queued.
  69069. + *
  69070. + * This function must only be called from the FIQ_ISO_OUT_ACTIVE state.
  69071. + */
  69072. +static int notrace fiq_iso_out_advance(struct fiq_state *st, int num_channels, int n)
  69073. +{
  69074. + hcsplt_data_t hcsplt;
  69075. + hctsiz_data_t hctsiz;
  69076. + hcdma_data_t hcdma;
  69077. + struct fiq_dma_blob *blob = (struct fiq_dma_blob *) st->dma_base;
  69078. + int last = 0;
  69079. + int i = st->channel[n].dma_info.index;
  69080. +
  69081. + fiq_print(FIQDBG_INT, st, "ADV %01d %01d ", n, i);
  69082. + i++;
  69083. + if (i == 4)
  69084. + last = 1;
  69085. + if (st->channel[n].dma_info.slot_len[i+1] == 255)
  69086. + last = 1;
  69087. +
  69088. + /* New DMA address - address of bounce buffer referred to in index */
  69089. + hcdma.d32 = (uint32_t) &blob->channel[n].index[i].buf[0];
  69090. + //hcdma.d32 = FIQ_READ(st->dwc_regs_base + HC_DMA + (HC_OFFSET * n));
  69091. + //hcdma.d32 += st->channel[n].dma_info.slot_len[i];
  69092. + fiq_print(FIQDBG_INT, st, "LAST: %01d ", last);
  69093. + fiq_print(FIQDBG_INT, st, "LEN: %03d", st->channel[n].dma_info.slot_len[i]);
  69094. + hcsplt.d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCSPLT);
  69095. + hctsiz.d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ);
  69096. + hcsplt.b.xactpos = (last) ? ISOC_XACTPOS_END : ISOC_XACTPOS_MID;
  69097. + /* Set up new packet length */
  69098. + hctsiz.b.pktcnt = 1;
  69099. + hctsiz.b.xfersize = st->channel[n].dma_info.slot_len[i];
  69100. + fiq_print(FIQDBG_INT, st, "%08x", hctsiz.d32);
  69101. +
  69102. + st->channel[n].dma_info.index++;
  69103. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCSPLT, hcsplt.d32);
  69104. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ, hctsiz.d32);
  69105. + FIQ_WRITE(st->dwc_regs_base + HC_DMA + (HC_OFFSET * n), hcdma.d32);
  69106. + return last;
  69107. +}
  69108. +
  69109. +/**
  69110. + * fiq_fsm_tt_next_isoc() - queue next pending isochronous out start-split on a TT
  69111. + *
  69112. + * Despite the limitations of the DWC core, we can force a microframe pipeline of
  69113. + * isochronous OUT start-split transactions while waiting for a corresponding other-type
  69114. + * of endpoint to finish its CSPLITs. TTs have big periodic buffers therefore it
  69115. + * is very unlikely that filling the start-split FIFO will cause data loss.
  69116. + * This allows much better interleaving of transactions in an order-independent way-
  69117. + * there is no requirement to prioritise isochronous, just a state-space search has
  69118. + * to be performed on each periodic start-split complete interrupt.
  69119. + */
  69120. +static int notrace fiq_fsm_tt_next_isoc(struct fiq_state *st, int num_channels, int n)
  69121. +{
  69122. + int hub_addr = st->channel[n].hub_addr;
  69123. + int port_addr = st->channel[n].port_addr;
  69124. + int i, poked = 0;
  69125. + for (i = 0; i < num_channels; i++) {
  69126. + if (i == n || st->channel[i].fsm == FIQ_PASSTHROUGH)
  69127. + continue;
  69128. + if (st->channel[i].hub_addr == hub_addr &&
  69129. + st->channel[i].port_addr == port_addr) {
  69130. + switch (st->channel[i].fsm) {
  69131. + case FIQ_PER_ISO_OUT_PENDING:
  69132. + if (st->channel[i].nrpackets == 1) {
  69133. + st->channel[i].fsm = FIQ_PER_ISO_OUT_LAST;
  69134. + } else {
  69135. + st->channel[i].fsm = FIQ_PER_ISO_OUT_ACTIVE;
  69136. + }
  69137. + fiq_fsm_restart_channel(st, i, 0);
  69138. + poked = 1;
  69139. + break;
  69140. +
  69141. + default:
  69142. + break;
  69143. + }
  69144. + }
  69145. + if (poked)
  69146. + break;
  69147. + }
  69148. + return poked;
  69149. +}
  69150. +
  69151. +/**
  69152. + * fiq_fsm_tt_in_use() - search for host channels using this TT
  69153. + * @n: Channel to use as reference
  69154. + *
  69155. + */
  69156. +int notrace noinline fiq_fsm_tt_in_use(struct fiq_state *st, int num_channels, int n)
  69157. +{
  69158. + int hub_addr = st->channel[n].hub_addr;
  69159. + int port_addr = st->channel[n].port_addr;
  69160. + int i, in_use = 0;
  69161. + for (i = 0; i < num_channels; i++) {
  69162. + if (i == n || st->channel[i].fsm == FIQ_PASSTHROUGH)
  69163. + continue;
  69164. + switch (st->channel[i].fsm) {
  69165. + /* TT is reserved for channels that are in the middle of a periodic
  69166. + * split transaction.
  69167. + */
  69168. + case FIQ_PER_SSPLIT_STARTED:
  69169. + case FIQ_PER_CSPLIT_WAIT:
  69170. + case FIQ_PER_CSPLIT_NYET1:
  69171. + //case FIQ_PER_CSPLIT_POLL:
  69172. + case FIQ_PER_ISO_OUT_ACTIVE:
  69173. + if (st->channel[i].hub_addr == hub_addr &&
  69174. + st->channel[i].port_addr == port_addr) {
  69175. + in_use = 1;
  69176. + }
  69177. + break;
  69178. + default:
  69179. + break;
  69180. + }
  69181. + if (in_use)
  69182. + break;
  69183. + }
  69184. + return in_use;
  69185. +}
  69186. +
  69187. +/**
  69188. + * fiq_fsm_more_csplits() - determine whether additional CSPLITs need
  69189. + * to be issued for this IN transaction.
  69190. + *
  69191. + * We cannot tell the inbound PID of a data packet due to hardware limitations.
  69192. + * we need to make an educated guess as to whether we need to queue another CSPLIT
  69193. + * or not. A no-brainer is when we have received enough data to fill the endpoint
  69194. + * size, but for endpoints that give variable-length data then we have to resort
  69195. + * to heuristics.
  69196. + *
  69197. + * We also return whether this is the last CSPLIT to be queued, again based on
  69198. + * heuristics. This is to allow a 1-uframe overlap of periodic split transactions.
  69199. + * Note: requires at least 1 CSPLIT to have been performed prior to being called.
  69200. + */
  69201. +
  69202. +/*
  69203. + * We need some way of guaranteeing if a returned periodic packet of size X
  69204. + * has a DATA0 PID.
  69205. + * The heuristic value of 144 bytes assumes that the received data has maximal
  69206. + * bit-stuffing and the clock frequency of the transmitting device is at the lowest
  69207. + * permissible limit. If the transfer length results in a final packet size
  69208. + * 144 < p <= 188, then an erroneous CSPLIT will be issued.
  69209. + * Also used to ensure that an endpoint will nominally only return a single
  69210. + * complete-split worth of data.
  69211. + */
  69212. +#define DATA0_PID_HEURISTIC 144
  69213. +
  69214. +static int notrace noinline fiq_fsm_more_csplits(struct fiq_state *state, int n, int *probably_last)
  69215. +{
  69216. +
  69217. + int i;
  69218. + int total_len = 0;
  69219. + int more_needed = 1;
  69220. + struct fiq_channel_state *st = &state->channel[n];
  69221. +
  69222. + for (i = 0; i < st->dma_info.index; i++) {
  69223. + total_len += st->dma_info.slot_len[i];
  69224. + }
  69225. +
  69226. + *probably_last = 0;
  69227. +
  69228. + if (st->hcchar_copy.b.eptype == 0x3) {
  69229. + /*
  69230. + * An interrupt endpoint will take max 2 CSPLITs. if we are receiving data
  69231. + * then this is definitely the last CSPLIT.
  69232. + */
  69233. + *probably_last = 1;
  69234. + } else {
  69235. + /* Isoc IN. This is a bit risky if we are the first transaction:
  69236. + * we may have been held off slightly. */
  69237. + if (i > 1 && st->dma_info.slot_len[st->dma_info.index-1] <= DATA0_PID_HEURISTIC) {
  69238. + more_needed = 0;
  69239. + }
  69240. + /* If in the next uframe we will receive enough data to fill the endpoint,
  69241. + * then only issue 1 more csplit.
  69242. + */
  69243. + if (st->hctsiz_copy.b.xfersize - total_len <= DATA0_PID_HEURISTIC)
  69244. + *probably_last = 1;
  69245. + }
  69246. +
  69247. + if (total_len >= st->hctsiz_copy.b.xfersize ||
  69248. + i == 6 || total_len == 0)
  69249. + /* Note: due to bit stuffing it is possible to have > 6 CSPLITs for
  69250. + * a single endpoint. Accepting more would completely break our scheduling mechanism though
  69251. + * - in these extreme cases we will pass through a truncated packet.
  69252. + */
  69253. + more_needed = 0;
  69254. +
  69255. + return more_needed;
  69256. +}
  69257. +
  69258. +/**
  69259. + * fiq_fsm_too_late() - Test transaction for lateness
  69260. + *
  69261. + * If a SSPLIT for a large IN transaction is issued too late in a frame,
  69262. + * the hub will disable the port to the device and respond with ERR handshakes.
  69263. + * The hub status endpoint will not reflect this change.
  69264. + * Returns 1 if we will issue a SSPLIT that will result in a device babble.
  69265. + */
  69266. +int notrace fiq_fsm_too_late(struct fiq_state *st, int n)
  69267. +{
  69268. + int uframe;
  69269. + hfnum_data_t hfnum = { .d32 = FIQ_READ(st->dwc_regs_base + HFNUM) };
  69270. + uframe = hfnum.b.frnum & 0x7;
  69271. + if ((uframe < 6) && (st->channel[n].nrpackets + 1 + uframe > 7)) {
  69272. + return 1;
  69273. + } else {
  69274. + return 0;
  69275. + }
  69276. +}
  69277. +
  69278. +
  69279. +/**
  69280. + * fiq_fsm_start_next_periodic() - A half-arsed attempt at a microframe pipeline
  69281. + *
  69282. + * Search pending transactions in the start-split pending state and queue them.
  69283. + * Don't queue packets in uframe .5 (comes out in .6) (USB2.0 11.18.4).
  69284. + * Note: we specifically don't do isochronous OUT transactions first because better
  69285. + * use of the TT's start-split fifo can be achieved by pipelining an IN before an OUT.
  69286. + */
  69287. +static void notrace noinline fiq_fsm_start_next_periodic(struct fiq_state *st, int num_channels)
  69288. +{
  69289. + int n;
  69290. + hfnum_data_t hfnum = { .d32 = FIQ_READ(st->dwc_regs_base + HFNUM) };
  69291. + if ((hfnum.b.frnum & 0x7) == 5)
  69292. + return;
  69293. + for (n = 0; n < num_channels; n++) {
  69294. + if (st->channel[n].fsm == FIQ_PER_SSPLIT_QUEUED) {
  69295. + /* Check to see if any other transactions are using this TT */
  69296. + if(!fiq_fsm_tt_in_use(st, num_channels, n)) {
  69297. + if (!fiq_fsm_too_late(st, n)) {
  69298. + st->channel[n].fsm = FIQ_PER_SSPLIT_STARTED;
  69299. + fiq_print(FIQDBG_INT, st, "NEXTPER ");
  69300. + fiq_fsm_restart_channel(st, n, 0);
  69301. + } else {
  69302. + st->channel[n].fsm = FIQ_PER_SPLIT_TIMEOUT;
  69303. + }
  69304. + break;
  69305. + }
  69306. + }
  69307. + }
  69308. + for (n = 0; n < num_channels; n++) {
  69309. + if (st->channel[n].fsm == FIQ_PER_ISO_OUT_PENDING) {
  69310. + if (!fiq_fsm_tt_in_use(st, num_channels, n)) {
  69311. + fiq_print(FIQDBG_INT, st, "NEXTISO ");
  69312. + st->channel[n].fsm = FIQ_PER_ISO_OUT_ACTIVE;
  69313. + fiq_fsm_restart_channel(st, n, 0);
  69314. + break;
  69315. + }
  69316. + }
  69317. + }
  69318. +}
  69319. +
  69320. +/**
  69321. + * fiq_fsm_update_hs_isoc() - update isochronous frame and transfer data
  69322. + * @state: Pointer to fiq_state
  69323. + * @n: Channel transaction is active on
  69324. + * @hcint: Copy of host channel interrupt register
  69325. + *
  69326. + * Returns 0 if there are no more transactions for this HC to do, 1
  69327. + * otherwise.
  69328. + */
  69329. +static int notrace noinline fiq_fsm_update_hs_isoc(struct fiq_state *state, int n, hcint_data_t hcint)
  69330. +{
  69331. + struct fiq_channel_state *st = &state->channel[n];
  69332. + int xfer_len = 0, nrpackets = 0;
  69333. + hcdma_data_t hcdma;
  69334. + fiq_print(FIQDBG_INT, state, "HSISO %02d", n);
  69335. +
  69336. + xfer_len = fiq_get_xfer_len(state, n);
  69337. + st->hs_isoc_info.iso_desc[st->hs_isoc_info.index].actual_length = xfer_len;
  69338. +
  69339. + st->hs_isoc_info.iso_desc[st->hs_isoc_info.index].status = hcint.d32;
  69340. +
  69341. + st->hs_isoc_info.index++;
  69342. + if (st->hs_isoc_info.index == st->hs_isoc_info.nrframes) {
  69343. + return 0;
  69344. + }
  69345. +
  69346. + /* grab the next DMA address offset from the array */
  69347. + hcdma.d32 = st->hcdma_copy.d32 + st->hs_isoc_info.iso_desc[st->hs_isoc_info.index].offset;
  69348. + FIQ_WRITE(state->dwc_regs_base + HC_DMA + (HC_OFFSET * n), hcdma.d32);
  69349. +
  69350. + /* We need to set multi_count. This is a bit tricky - has to be set per-transaction as
  69351. + * the core needs to be told to send the correct number. Caution: for IN transfers,
  69352. + * this is always set to the maximum size of the endpoint. */
  69353. + xfer_len = st->hs_isoc_info.iso_desc[st->hs_isoc_info.index].length;
  69354. + /* Integer divide in a FIQ: fun. FIXME: make this not suck */
  69355. + nrpackets = (xfer_len + st->hcchar_copy.b.mps - 1) / st->hcchar_copy.b.mps;
  69356. + if (nrpackets == 0)
  69357. + nrpackets = 1;
  69358. + st->hcchar_copy.b.multicnt = nrpackets;
  69359. + st->hctsiz_copy.b.pktcnt = nrpackets;
  69360. +
  69361. + /* Initial PID also needs to be set */
  69362. + if (st->hcchar_copy.b.epdir == 0) {
  69363. + st->hctsiz_copy.b.xfersize = xfer_len;
  69364. + switch (st->hcchar_copy.b.multicnt) {
  69365. + case 1:
  69366. + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
  69367. + break;
  69368. + case 2:
  69369. + case 3:
  69370. + st->hctsiz_copy.b.pid = DWC_PID_MDATA;
  69371. + break;
  69372. + }
  69373. +
  69374. + } else {
  69375. + switch (st->hcchar_copy.b.multicnt) {
  69376. + st->hctsiz_copy.b.xfersize = nrpackets * st->hcchar_copy.b.mps;
  69377. + case 1:
  69378. + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
  69379. + break;
  69380. + case 2:
  69381. + st->hctsiz_copy.b.pid = DWC_PID_DATA1;
  69382. + break;
  69383. + case 3:
  69384. + st->hctsiz_copy.b.pid = DWC_PID_DATA2;
  69385. + break;
  69386. + }
  69387. + }
  69388. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ, st->hctsiz_copy.d32);
  69389. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR, st->hcchar_copy.d32);
  69390. + /* Channel is enabled on hcint handler exit */
  69391. + fiq_print(FIQDBG_INT, state, "HSISOOUT");
  69392. + return 1;
  69393. +}
  69394. +
  69395. +
  69396. +/**
  69397. + * fiq_fsm_do_sof() - FSM start-of-frame interrupt handler
  69398. + * @state: Pointer to the state struct passed from banked FIQ mode registers.
  69399. + * @num_channels: set according to the DWC hardware configuration
  69400. + *
  69401. + * The SOF handler in FSM mode has two functions
  69402. + * 1. Hold off SOF from causing schedule advancement in IRQ context if there's
  69403. + * nothing to do
  69404. + * 2. Advance certain FSM states that require either a microframe delay, or a microframe
  69405. + * of holdoff.
  69406. + *
  69407. + * The second part is architecture-specific to mach-bcm2835 -
  69408. + * a sane interrupt controller would have a mask register for ARM interrupt sources
  69409. + * to be promoted to the nFIQ line, but it doesn't. Instead a single interrupt
  69410. + * number (USB) can be enabled. This means that certain parts of the USB specification
  69411. + * that require "wait a little while, then issue another packet" cannot be fulfilled with
  69412. + * the timing granularity required to achieve optimal throughout. The workaround is to use
  69413. + * the SOF "timer" (125uS) to perform this task.
  69414. + */
  69415. +static int notrace noinline fiq_fsm_do_sof(struct fiq_state *state, int num_channels)
  69416. +{
  69417. + hfnum_data_t hfnum = { .d32 = FIQ_READ(state->dwc_regs_base + HFNUM) };
  69418. + int n;
  69419. + int kick_irq = 0;
  69420. +
  69421. + if ((hfnum.b.frnum & 0x7) == 1) {
  69422. + /* We cannot issue csplits for transactions in the last frame past (n+1).1
  69423. + * Check to see if there are any transactions that are stale.
  69424. + * Boot them out.
  69425. + */
  69426. + for (n = 0; n < num_channels; n++) {
  69427. + switch (state->channel[n].fsm) {
  69428. + case FIQ_PER_CSPLIT_WAIT:
  69429. + case FIQ_PER_CSPLIT_NYET1:
  69430. + case FIQ_PER_CSPLIT_POLL:
  69431. + case FIQ_PER_CSPLIT_LAST:
  69432. + /* Check if we are no longer in the same full-speed frame. */
  69433. + if (((state->channel[n].expected_uframe & 0x3FFF) & ~0x7) <
  69434. + (hfnum.b.frnum & ~0x7))
  69435. + state->channel[n].fsm = FIQ_PER_SPLIT_TIMEOUT;
  69436. + break;
  69437. + default:
  69438. + break;
  69439. + }
  69440. + }
  69441. + }
  69442. +
  69443. + for (n = 0; n < num_channels; n++) {
  69444. + switch (state->channel[n].fsm) {
  69445. +
  69446. + case FIQ_NP_SSPLIT_RETRY:
  69447. + case FIQ_NP_IN_CSPLIT_RETRY:
  69448. + case FIQ_NP_OUT_CSPLIT_RETRY:
  69449. + fiq_fsm_restart_channel(state, n, 0);
  69450. + break;
  69451. +
  69452. + case FIQ_HS_ISOC_SLEEPING:
  69453. + state->channel[n].fsm = FIQ_HS_ISOC_TURBO;
  69454. + fiq_fsm_restart_channel(state, n, 0);
  69455. + break;
  69456. +
  69457. + case FIQ_PER_SSPLIT_QUEUED:
  69458. + if ((hfnum.b.frnum & 0x7) == 5)
  69459. + break;
  69460. + if(!fiq_fsm_tt_in_use(state, num_channels, n)) {
  69461. + if (!fiq_fsm_too_late(state, n)) {
  69462. + fiq_print(FIQDBG_INT, st, "SOF GO %01d", n);
  69463. + fiq_fsm_restart_channel(state, n, 0);
  69464. + state->channel[n].fsm = FIQ_PER_SSPLIT_STARTED;
  69465. + } else {
  69466. + state->channel[n].fsm = FIQ_PER_SPLIT_TIMEOUT;
  69467. + state->haintmsk_saved.b2.chint &= ~(1 << n);
  69468. + kick_irq |= 1;
  69469. + }
  69470. + }
  69471. + break;
  69472. +
  69473. + case FIQ_PER_ISO_OUT_PENDING:
  69474. + /* Ordinarily, this should be poked after the SSPLIT
  69475. + * complete interrupt for a competing transfer on the same
  69476. + * TT. Doesn't happen for aborted transactions though.
  69477. + */
  69478. + if ((hfnum.b.frnum & 0x7) >= 5)
  69479. + break;
  69480. + if (!fiq_fsm_tt_in_use(state, num_channels, n)) {
  69481. + /* Hardware bug. SOF can sometimes occur after the channel halt interrupt
  69482. + * that caused this.
  69483. + */
  69484. + fiq_fsm_restart_channel(state, n, 0);
  69485. + fiq_print(FIQDBG_INT, state, "SOF ISOC");
  69486. + if (state->channel[n].nrpackets == 1) {
  69487. + state->channel[n].fsm = FIQ_PER_ISO_OUT_LAST;
  69488. + } else {
  69489. + state->channel[n].fsm = FIQ_PER_ISO_OUT_ACTIVE;
  69490. + }
  69491. + }
  69492. + break;
  69493. +
  69494. + case FIQ_PER_CSPLIT_WAIT:
  69495. + /* we are guaranteed to be in this state if and only if the SSPLIT interrupt
  69496. + * occurred when the bus transaction occurred. The SOF interrupt reversal bug
  69497. + * will utterly bugger this up though.
  69498. + */
  69499. + if (hfnum.b.frnum != state->channel[n].expected_uframe) {
  69500. + fiq_print(FIQDBG_INT, state, "SOFCS %d ", n);
  69501. + state->channel[n].fsm = FIQ_PER_CSPLIT_POLL;
  69502. + fiq_fsm_restart_channel(state, n, 0);
  69503. + fiq_fsm_start_next_periodic(state, num_channels);
  69504. +
  69505. + }
  69506. + break;
  69507. +
  69508. + case FIQ_PER_SPLIT_TIMEOUT:
  69509. + /* Ugly: we have to force a HCD interrupt.
  69510. + * Poke the mask for the channel in question.
  69511. + * We will take a fake SOF because of this, but
  69512. + * that's OK.
  69513. + */
  69514. + state->haintmsk_saved.b2.chint &= ~(1 << n);
  69515. + kick_irq |= 1;
  69516. + break;
  69517. +
  69518. + default:
  69519. + break;
  69520. + }
  69521. + }
  69522. +
  69523. + if (state->kick_np_queues ||
  69524. + dwc_frame_num_le(state->next_sched_frame, hfnum.b.frnum))
  69525. + kick_irq |= 1;
  69526. +
  69527. + return !kick_irq;
  69528. +}
  69529. +
  69530. +
  69531. +/**
  69532. + * fiq_fsm_do_hcintr() - FSM host channel interrupt handler
  69533. + * @state: Pointer to the FIQ state struct
  69534. + * @num_channels: Number of channels as per hardware config
  69535. + * @n: channel for which HAINT(i) was raised
  69536. + *
  69537. + * An important property is that only the CHHLT interrupt is unmasked. Unfortunately, AHBerr is as well.
  69538. + */
  69539. +static int notrace noinline fiq_fsm_do_hcintr(struct fiq_state *state, int num_channels, int n)
  69540. +{
  69541. + hcint_data_t hcint;
  69542. + hcintmsk_data_t hcintmsk;
  69543. + hcint_data_t hcint_probe;
  69544. + hcchar_data_t hcchar;
  69545. + int handled = 0;
  69546. + int restart = 0;
  69547. + int last_csplit = 0;
  69548. + int start_next_periodic = 0;
  69549. + struct fiq_channel_state *st = &state->channel[n];
  69550. + hfnum_data_t hfnum;
  69551. +
  69552. + hcint.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINT);
  69553. + hcintmsk.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINTMSK);
  69554. + hcint_probe.d32 = hcint.d32 & hcintmsk.d32;
  69555. +
  69556. + if (st->fsm != FIQ_PASSTHROUGH) {
  69557. + fiq_print(FIQDBG_INT, state, "HC%01d ST%02d", n, st->fsm);
  69558. + fiq_print(FIQDBG_INT, state, "%08x", hcint.d32);
  69559. + }
  69560. +
  69561. + switch (st->fsm) {
  69562. +
  69563. + case FIQ_PASSTHROUGH:
  69564. + case FIQ_DEQUEUE_ISSUED:
  69565. + /* doesn't belong to us, kick it upstairs */
  69566. + break;
  69567. +
  69568. + case FIQ_PASSTHROUGH_ERRORSTATE:
  69569. + /* We are here to emulate the error recovery mechanism of the dwc HCD.
  69570. + * Several interrupts are unmasked if a previous transaction failed - it's
  69571. + * death for the FIQ to attempt to handle them as the channel isn't halted.
  69572. + * Emulate what the HCD does in this situation: mask and continue.
  69573. + * The FSM has no other state setup so this has to be handled out-of-band.
  69574. + */
  69575. + fiq_print(FIQDBG_ERR, state, "ERRST %02d", n);
  69576. + if (hcint_probe.b.nak || hcint_probe.b.ack || hcint_probe.b.datatglerr) {
  69577. + fiq_print(FIQDBG_ERR, state, "RESET %02d", n);
  69578. + st->nr_errors = 0;
  69579. + hcintmsk.b.nak = 0;
  69580. + hcintmsk.b.ack = 0;
  69581. + hcintmsk.b.datatglerr = 0;
  69582. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINTMSK, hcintmsk.d32);
  69583. + return 1;
  69584. + }
  69585. + if (hcint_probe.b.chhltd) {
  69586. + fiq_print(FIQDBG_ERR, state, "CHHLT %02d", n);
  69587. + fiq_print(FIQDBG_ERR, state, "%08x", hcint.d32);
  69588. + return 0;
  69589. + }
  69590. + break;
  69591. +
  69592. + /* Non-periodic state groups */
  69593. + case FIQ_NP_SSPLIT_STARTED:
  69594. + case FIQ_NP_SSPLIT_RETRY:
  69595. + /* Got a HCINT for a NP SSPLIT. Expected ACK / NAK / fail */
  69596. + if (hcint.b.ack) {
  69597. + /* SSPLIT complete. For OUT, the data has been sent. For IN, the LS transaction
  69598. + * will start shortly. SOF needs to kick the transaction to prevent a NYET flood.
  69599. + */
  69600. + if(st->hcchar_copy.b.epdir == 1)
  69601. + st->fsm = FIQ_NP_IN_CSPLIT_RETRY;
  69602. + else
  69603. + st->fsm = FIQ_NP_OUT_CSPLIT_RETRY;
  69604. + st->nr_errors = 0;
  69605. + handled = 1;
  69606. + fiq_fsm_setup_csplit(state, n);
  69607. + } else if (hcint.b.nak) {
  69608. + // No buffer space in TT. Retry on a uframe boundary.
  69609. + st->fsm = FIQ_NP_SSPLIT_RETRY;
  69610. + handled = 1;
  69611. + } else if (hcint.b.xacterr) {
  69612. + // The only other one we care about is xacterr. This implies HS bus error - retry.
  69613. + st->nr_errors++;
  69614. + st->fsm = FIQ_NP_SSPLIT_RETRY;
  69615. + if (st->nr_errors >= 3) {
  69616. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  69617. + } else {
  69618. + handled = 1;
  69619. + restart = 1;
  69620. + }
  69621. + } else {
  69622. + st->fsm = FIQ_NP_SPLIT_LS_ABORTED;
  69623. + handled = 0;
  69624. + restart = 0;
  69625. + }
  69626. + break;
  69627. +
  69628. + case FIQ_NP_IN_CSPLIT_RETRY:
  69629. + /* Received a CSPLIT done interrupt.
  69630. + * Expected Data/NAK/STALL/NYET for IN.
  69631. + */
  69632. + if (hcint.b.xfercomp) {
  69633. + /* For IN, data is present. */
  69634. + st->fsm = FIQ_NP_SPLIT_DONE;
  69635. + } else if (hcint.b.nak) {
  69636. + /* no endpoint data. Punt it upstairs */
  69637. + st->fsm = FIQ_NP_SPLIT_DONE;
  69638. + } else if (hcint.b.nyet) {
  69639. + /* CSPLIT NYET - retry on a uframe boundary. */
  69640. + handled = 1;
  69641. + st->nr_errors = 0;
  69642. + } else if (hcint.b.datatglerr) {
  69643. + /* data toggle errors do not set the xfercomp bit. */
  69644. + st->fsm = FIQ_NP_SPLIT_LS_ABORTED;
  69645. + } else if (hcint.b.xacterr) {
  69646. + /* HS error. Retry immediate */
  69647. + st->fsm = FIQ_NP_IN_CSPLIT_RETRY;
  69648. + st->nr_errors++;
  69649. + if (st->nr_errors >= 3) {
  69650. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  69651. + } else {
  69652. + handled = 1;
  69653. + restart = 1;
  69654. + }
  69655. + } else if (hcint.b.stall) {
  69656. + /* A STALL implies either a LS bus error or a genuine STALL. */
  69657. + st->fsm = FIQ_NP_SPLIT_LS_ABORTED;
  69658. + } else {
  69659. + /* Hardware bug. It's possible in some cases to
  69660. + * get a channel halt with nothing else set when
  69661. + * the response was a NYET. Treat as local 3-strikes retry.
  69662. + */
  69663. + hcint_data_t hcint_test = hcint;
  69664. + hcint_test.b.chhltd = 0;
  69665. + if (!hcint_test.d32) {
  69666. + st->nr_errors++;
  69667. + if (st->nr_errors >= 3) {
  69668. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  69669. + } else {
  69670. + handled = 1;
  69671. + }
  69672. + } else {
  69673. + /* Bail out if something unexpected happened */
  69674. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  69675. + }
  69676. + }
  69677. + break;
  69678. +
  69679. + case FIQ_NP_OUT_CSPLIT_RETRY:
  69680. + /* Received a CSPLIT done interrupt.
  69681. + * Expected ACK/NAK/STALL/NYET/XFERCOMP for OUT.*/
  69682. + if (hcint.b.xfercomp) {
  69683. + st->fsm = FIQ_NP_SPLIT_DONE;
  69684. + } else if (hcint.b.nak) {
  69685. + // The HCD will implement the holdoff on frame boundaries.
  69686. + st->fsm = FIQ_NP_SPLIT_DONE;
  69687. + } else if (hcint.b.nyet) {
  69688. + // Hub still processing.
  69689. + st->fsm = FIQ_NP_OUT_CSPLIT_RETRY;
  69690. + handled = 1;
  69691. + st->nr_errors = 0;
  69692. + //restart = 1;
  69693. + } else if (hcint.b.xacterr) {
  69694. + /* HS error. retry immediate */
  69695. + st->fsm = FIQ_NP_OUT_CSPLIT_RETRY;
  69696. + st->nr_errors++;
  69697. + if (st->nr_errors >= 3) {
  69698. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  69699. + } else {
  69700. + handled = 1;
  69701. + restart = 1;
  69702. + }
  69703. + } else if (hcint.b.stall) {
  69704. + /* LS bus error or genuine stall */
  69705. + st->fsm = FIQ_NP_SPLIT_LS_ABORTED;
  69706. + } else {
  69707. + /*
  69708. + * Hardware bug. It's possible in some cases to get a
  69709. + * channel halt with nothing else set when the response was a NYET.
  69710. + * Treat as local 3-strikes retry.
  69711. + */
  69712. + hcint_data_t hcint_test = hcint;
  69713. + hcint_test.b.chhltd = 0;
  69714. + if (!hcint_test.d32) {
  69715. + st->nr_errors++;
  69716. + if (st->nr_errors >= 3) {
  69717. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  69718. + } else {
  69719. + handled = 1;
  69720. + }
  69721. + } else {
  69722. + // Something unexpected happened. AHBerror or babble perhaps. Let the IRQ deal with it.
  69723. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  69724. + }
  69725. + }
  69726. + break;
  69727. +
  69728. + /* Periodic split states (except isoc out) */
  69729. + case FIQ_PER_SSPLIT_STARTED:
  69730. + /* Expect an ACK or failure for SSPLIT */
  69731. + if (hcint.b.ack) {
  69732. + /*
  69733. + * SSPLIT transfer complete interrupt - the generation of this interrupt is fraught with bugs.
  69734. + * For a packet queued in microframe n-3 to appear in n-2, if the channel is enabled near the EOF1
  69735. + * point for microframe n-3, the packet will not appear on the bus until microframe n.
  69736. + * Additionally, the generation of the actual interrupt is dodgy. For a packet appearing on the bus
  69737. + * in microframe n, sometimes the interrupt is generated immediately. Sometimes, it appears in n+1
  69738. + * coincident with SOF for n+1.
  69739. + * SOF is also buggy. It can sometimes be raised AFTER the first bus transaction has taken place.
  69740. + * These appear to be caused by timing/clock crossing bugs within the core itself.
  69741. + * State machine workaround.
  69742. + */
  69743. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  69744. + hcchar.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  69745. + fiq_fsm_setup_csplit(state, n);
  69746. + /* Poke the oddfrm bit. If we are equivalent, we received the interrupt at the correct
  69747. + * time. If not, then we're in the next SOF.
  69748. + */
  69749. + if ((hfnum.b.frnum & 0x1) == hcchar.b.oddfrm) {
  69750. + fiq_print(FIQDBG_INT, state, "CSWAIT %01d", n);
  69751. + st->expected_uframe = hfnum.b.frnum;
  69752. + st->fsm = FIQ_PER_CSPLIT_WAIT;
  69753. + } else {
  69754. + fiq_print(FIQDBG_INT, state, "CSPOL %01d", n);
  69755. + /* For isochronous IN endpoints,
  69756. + * we need to hold off if we are expecting a lot of data */
  69757. + if (st->hcchar_copy.b.mps < DATA0_PID_HEURISTIC) {
  69758. + start_next_periodic = 1;
  69759. + }
  69760. + /* Danger will robinson: we are in a broken state. If our first interrupt after
  69761. + * this is a NYET, it will be delayed by 1 uframe and result in an unrecoverable
  69762. + * lag. Unmask the NYET interrupt.
  69763. + */
  69764. + st->expected_uframe = (hfnum.b.frnum + 1) & 0x3FFF;
  69765. + st->fsm = FIQ_PER_CSPLIT_BROKEN_NYET1;
  69766. + restart = 1;
  69767. + }
  69768. + handled = 1;
  69769. + } else if (hcint.b.xacterr) {
  69770. + /* 3-strikes retry is enabled, we have hit our max nr_errors */
  69771. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  69772. + start_next_periodic = 1;
  69773. + } else {
  69774. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  69775. + start_next_periodic = 1;
  69776. + }
  69777. + /* We can now queue the next isochronous OUT transaction, if one is pending. */
  69778. + if(fiq_fsm_tt_next_isoc(state, num_channels, n)) {
  69779. + fiq_print(FIQDBG_INT, state, "NEXTISO ");
  69780. + }
  69781. + break;
  69782. +
  69783. + case FIQ_PER_CSPLIT_NYET1:
  69784. + /* First CSPLIT attempt was a NYET. If we get a subsequent NYET,
  69785. + * we are too late and the TT has dropped its CSPLIT fifo.
  69786. + */
  69787. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  69788. + hcchar.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  69789. + start_next_periodic = 1;
  69790. + if (hcint.b.nak) {
  69791. + st->fsm = FIQ_PER_SPLIT_DONE;
  69792. + } else if (hcint.b.xfercomp) {
  69793. + fiq_increment_dma_buf(state, num_channels, n);
  69794. + st->fsm = FIQ_PER_CSPLIT_POLL;
  69795. + st->nr_errors = 0;
  69796. + if (fiq_fsm_more_csplits(state, n, &last_csplit)) {
  69797. + handled = 1;
  69798. + restart = 1;
  69799. + if (!last_csplit)
  69800. + start_next_periodic = 0;
  69801. + } else {
  69802. + st->fsm = FIQ_PER_SPLIT_DONE;
  69803. + }
  69804. + } else if (hcint.b.nyet) {
  69805. + /* Doh. Data lost. */
  69806. + st->fsm = FIQ_PER_SPLIT_NYET_ABORTED;
  69807. + } else if (hcint.b.xacterr || hcint.b.stall) {
  69808. + st->fsm = FIQ_PER_SPLIT_LS_ABORTED;
  69809. + } else {
  69810. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  69811. + }
  69812. + break;
  69813. +
  69814. + case FIQ_PER_CSPLIT_BROKEN_NYET1:
  69815. + /*
  69816. + * we got here because our host channel is in the delayed-interrupt
  69817. + * state and we cannot take a NYET interrupt any later than when it
  69818. + * occurred. Disable then re-enable the channel if this happens to force
  69819. + * CSPLITs to occur at the right time.
  69820. + */
  69821. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  69822. + hcchar.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  69823. + fiq_print(FIQDBG_INT, state, "BROK: %01d ", n);
  69824. + if (hcint.b.nak) {
  69825. + st->fsm = FIQ_PER_SPLIT_DONE;
  69826. + start_next_periodic = 1;
  69827. + } else if (hcint.b.xfercomp) {
  69828. + fiq_increment_dma_buf(state, num_channels, n);
  69829. + if (fiq_fsm_more_csplits(state, n, &last_csplit)) {
  69830. + st->fsm = FIQ_PER_CSPLIT_POLL;
  69831. + handled = 1;
  69832. + restart = 1;
  69833. + start_next_periodic = 1;
  69834. + /* Reload HCTSIZ for the next transfer */
  69835. + fiq_fsm_reload_hctsiz(state, n);
  69836. + if (!last_csplit)
  69837. + start_next_periodic = 0;
  69838. + } else {
  69839. + st->fsm = FIQ_PER_SPLIT_DONE;
  69840. + }
  69841. + } else if (hcint.b.nyet) {
  69842. + st->fsm = FIQ_PER_SPLIT_NYET_ABORTED;
  69843. + start_next_periodic = 1;
  69844. + } else if (hcint.b.xacterr) {
  69845. + /* Local 3-strikes retry is handled by the core. This is a ERR response.*/
  69846. + st->fsm = FIQ_PER_SPLIT_LS_ABORTED;
  69847. + } else {
  69848. + fiq_print(FIQDBG_INT, state, "TOGGLES");
  69849. + BUG();
  69850. + }
  69851. + break;
  69852. +
  69853. + case FIQ_PER_CSPLIT_POLL:
  69854. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  69855. + hcchar.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  69856. + start_next_periodic = 1;
  69857. + if (hcint.b.nak) {
  69858. + st->fsm = FIQ_PER_SPLIT_DONE;
  69859. + } else if (hcint.b.xfercomp) {
  69860. + fiq_increment_dma_buf(state, num_channels, n);
  69861. + if (fiq_fsm_more_csplits(state, n, &last_csplit)) {
  69862. + handled = 1;
  69863. + restart = 1;
  69864. + /* Reload HCTSIZ for the next transfer */
  69865. + fiq_fsm_reload_hctsiz(state, n);
  69866. + if (!last_csplit)
  69867. + start_next_periodic = 0;
  69868. + } else {
  69869. + st->fsm = FIQ_PER_SPLIT_DONE;
  69870. + }
  69871. + } else if (hcint.b.nyet) {
  69872. + /* Are we a NYET after the first data packet? */
  69873. + if (st->nrpackets == 0) {
  69874. + st->fsm = FIQ_PER_CSPLIT_NYET1;
  69875. + handled = 1;
  69876. + restart = 1;
  69877. + } else {
  69878. + /* We got a NYET when polling CSPLITs. Can happen
  69879. + * if our heuristic fails, or if someone disables us
  69880. + * for any significant length of time.
  69881. + */
  69882. + if (st->nr_errors >= 3) {
  69883. + st->fsm = FIQ_PER_SPLIT_NYET_ABORTED;
  69884. + } else {
  69885. + st->fsm = FIQ_PER_SPLIT_DONE;
  69886. + }
  69887. + }
  69888. + } else if (hcint.b.xacterr || hcint.b.stall) {
  69889. + /* For xacterr, Local 3-strikes retry is handled by the core. This is a ERR response.*/
  69890. + st->fsm = FIQ_PER_SPLIT_LS_ABORTED;
  69891. + } else if (hcint.b.datatglerr) {
  69892. + fiq_print(FIQDBG_INT, state, "TOGGLES");
  69893. + BUG();
  69894. + } else {
  69895. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  69896. + }
  69897. + break;
  69898. +
  69899. + case FIQ_HS_ISOC_TURBO:
  69900. + if (fiq_fsm_update_hs_isoc(state, n, hcint)) {
  69901. + /* more transactions to come */
  69902. + handled = 1;
  69903. + restart = 1;
  69904. + fiq_print(FIQDBG_INT, state, "HSISO M ");
  69905. + } else {
  69906. + st->fsm = FIQ_HS_ISOC_DONE;
  69907. + fiq_print(FIQDBG_INT, state, "HSISO F ");
  69908. + }
  69909. + break;
  69910. +
  69911. + case FIQ_HS_ISOC_ABORTED:
  69912. + /* This abort is called by the driver rewriting the state mid-transaction
  69913. + * which allows the dequeue mechanism to work more effectively.
  69914. + */
  69915. + break;
  69916. +
  69917. + case FIQ_PER_ISO_OUT_ACTIVE:
  69918. + if (hcint.b.ack) {
  69919. + if(fiq_iso_out_advance(state, num_channels, n)) {
  69920. + /* last OUT transfer */
  69921. + st->fsm = FIQ_PER_ISO_OUT_LAST;
  69922. + /*
  69923. + * Assuming the periodic FIFO in the dwc core
  69924. + * actually does its job properly, we can queue
  69925. + * the next ssplit now and in theory, the wire
  69926. + * transactions will be in-order.
  69927. + */
  69928. + // No it doesn't. It appears to process requests in host channel order.
  69929. + //start_next_periodic = 1;
  69930. + }
  69931. + handled = 1;
  69932. + restart = 1;
  69933. + } else {
  69934. + /*
  69935. + * Isochronous transactions carry on regardless. Log the error
  69936. + * and continue.
  69937. + */
  69938. + //explode += 1;
  69939. + st->nr_errors++;
  69940. + if(fiq_iso_out_advance(state, num_channels, n)) {
  69941. + st->fsm = FIQ_PER_ISO_OUT_LAST;
  69942. + //start_next_periodic = 1;
  69943. + }
  69944. + handled = 1;
  69945. + restart = 1;
  69946. + }
  69947. + break;
  69948. +
  69949. + case FIQ_PER_ISO_OUT_LAST:
  69950. + if (hcint.b.ack) {
  69951. + /* All done here */
  69952. + st->fsm = FIQ_PER_ISO_OUT_DONE;
  69953. + } else {
  69954. + st->fsm = FIQ_PER_ISO_OUT_DONE;
  69955. + st->nr_errors++;
  69956. + }
  69957. + start_next_periodic = 1;
  69958. + break;
  69959. +
  69960. + case FIQ_PER_SPLIT_TIMEOUT:
  69961. + /* SOF kicked us because we overran. */
  69962. + start_next_periodic = 1;
  69963. + break;
  69964. +
  69965. + default:
  69966. + break;
  69967. + }
  69968. +
  69969. + if (handled) {
  69970. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINT, hcint.d32);
  69971. + } else {
  69972. + /* Copy the regs into the state so the IRQ knows what to do */
  69973. + st->hcint_copy.d32 = hcint.d32;
  69974. + }
  69975. +
  69976. + if (restart) {
  69977. + /* Restart always implies handled. */
  69978. + if (restart == 2) {
  69979. + /* For complete-split INs, the show must go on.
  69980. + * Force a channel restart */
  69981. + fiq_fsm_restart_channel(state, n, 1);
  69982. + } else {
  69983. + fiq_fsm_restart_channel(state, n, 0);
  69984. + }
  69985. + }
  69986. + if (start_next_periodic) {
  69987. + fiq_fsm_start_next_periodic(state, num_channels);
  69988. + }
  69989. + if (st->fsm != FIQ_PASSTHROUGH)
  69990. + fiq_print(FIQDBG_INT, state, "FSMOUT%02d", st->fsm);
  69991. +
  69992. + return handled;
  69993. +}
  69994. +
  69995. +
  69996. +/**
  69997. + * dwc_otg_fiq_fsm() - Flying State Machine (monster) FIQ
  69998. + * @state: pointer to state struct passed from the banked FIQ mode registers.
  69999. + * @num_channels: set according to the DWC hardware configuration
  70000. + * @dma: pointer to DMA bounce buffers for split transaction slots
  70001. + *
  70002. + * The FSM FIQ performs the low-level tasks that normally would be performed by the microcode
  70003. + * inside an EHCI or similar host controller regarding split transactions. The DWC core
  70004. + * interrupts each and every time a split transaction packet is received or sent successfully.
  70005. + * This results in either an interrupt storm when everything is working "properly", or
  70006. + * the interrupt latency of the system in general breaks time-sensitive periodic split
  70007. + * transactions. Pushing the low-level, but relatively easy state machine work into the FIQ
  70008. + * solves these problems.
  70009. + *
  70010. + * Return: void
  70011. + */
  70012. +void notrace dwc_otg_fiq_fsm(struct fiq_state *state, int num_channels)
  70013. +{
  70014. + gintsts_data_t gintsts, gintsts_handled;
  70015. + gintmsk_data_t gintmsk;
  70016. + //hfnum_data_t hfnum;
  70017. + haint_data_t haint, haint_handled;
  70018. + haintmsk_data_t haintmsk;
  70019. + int kick_irq = 0;
  70020. +
  70021. + gintsts_handled.d32 = 0;
  70022. + haint_handled.d32 = 0;
  70023. +
  70024. + gintsts.d32 = FIQ_READ(state->dwc_regs_base + GINTSTS);
  70025. + gintmsk.d32 = FIQ_READ(state->dwc_regs_base + GINTMSK);
  70026. + gintsts.d32 &= gintmsk.d32;
  70027. +
  70028. + if (gintsts.b.sofintr) {
  70029. + /* For FSM mode, SOF is required to keep the state machine advance for
  70030. + * certain stages of the periodic pipeline. It's death to mask this
  70031. + * interrupt in that case.
  70032. + */
  70033. +
  70034. + if (!fiq_fsm_do_sof(state, num_channels)) {
  70035. + /* Kick IRQ once. Queue advancement means that all pending transactions
  70036. + * will get serviced when the IRQ finally executes.
  70037. + */
  70038. + if (state->gintmsk_saved.b.sofintr == 1)
  70039. + kick_irq |= 1;
  70040. + state->gintmsk_saved.b.sofintr = 0;
  70041. + }
  70042. + gintsts_handled.b.sofintr = 1;
  70043. + }
  70044. +
  70045. + if (gintsts.b.hcintr) {
  70046. + int i;
  70047. + haint.d32 = FIQ_READ(state->dwc_regs_base + HAINT);
  70048. + haintmsk.d32 = FIQ_READ(state->dwc_regs_base + HAINTMSK);
  70049. + haint.d32 &= haintmsk.d32;
  70050. + haint_handled.d32 = 0;
  70051. + for (i=0; i<num_channels; i++) {
  70052. + if (haint.b2.chint & (1 << i)) {
  70053. + if(!fiq_fsm_do_hcintr(state, num_channels, i)) {
  70054. + /* HCINT was not handled in FIQ
  70055. + * HAINT is level-sensitive, leading to level-sensitive ginststs.b.hcint bit.
  70056. + * Mask HAINT(i) but keep top-level hcint unmasked.
  70057. + */
  70058. + state->haintmsk_saved.b2.chint &= ~(1 << i);
  70059. + } else {
  70060. + /* do_hcintr cleaned up after itself, but clear haint */
  70061. + haint_handled.b2.chint |= (1 << i);
  70062. + }
  70063. + }
  70064. + }
  70065. +
  70066. + if (haint_handled.b2.chint) {
  70067. + FIQ_WRITE(state->dwc_regs_base + HAINT, haint_handled.d32);
  70068. + }
  70069. +
  70070. + if (haintmsk.d32 != (haintmsk.d32 & state->haintmsk_saved.d32)) {
  70071. + /*
  70072. + * This is necessary to avoid multiple retriggers of the MPHI in the case
  70073. + * where interrupts are held off and HCINTs start to pile up.
  70074. + * Only wake up the IRQ if a new interrupt came in, was not handled and was
  70075. + * masked.
  70076. + */
  70077. + haintmsk.d32 &= state->haintmsk_saved.d32;
  70078. + FIQ_WRITE(state->dwc_regs_base + HAINTMSK, haintmsk.d32);
  70079. + kick_irq |= 1;
  70080. + }
  70081. + /* Top-Level interrupt - always handled because it's level-sensitive */
  70082. + gintsts_handled.b.hcintr = 1;
  70083. + }
  70084. +
  70085. +
  70086. + /* Clear the bits in the saved register that were not handled but were triggered. */
  70087. + state->gintmsk_saved.d32 &= ~(gintsts.d32 & ~gintsts_handled.d32);
  70088. +
  70089. + /* FIQ didn't handle something - mask has changed - write new mask */
  70090. + if (gintmsk.d32 != (gintmsk.d32 & state->gintmsk_saved.d32)) {
  70091. + gintmsk.d32 &= state->gintmsk_saved.d32;
  70092. + gintmsk.b.sofintr = 1;
  70093. + FIQ_WRITE(state->dwc_regs_base + GINTMSK, gintmsk.d32);
  70094. +// fiq_print(FIQDBG_INT, state, "KICKGINT");
  70095. +// fiq_print(FIQDBG_INT, state, "%08x", gintmsk.d32);
  70096. +// fiq_print(FIQDBG_INT, state, "%08x", state->gintmsk_saved.d32);
  70097. + kick_irq |= 1;
  70098. + }
  70099. +
  70100. + if (gintsts_handled.d32) {
  70101. + /* Only applies to edge-sensitive bits in GINTSTS */
  70102. + FIQ_WRITE(state->dwc_regs_base + GINTSTS, gintsts_handled.d32);
  70103. + }
  70104. +
  70105. + /* We got an interrupt, didn't handle it. */
  70106. + if (kick_irq) {
  70107. + state->mphi_int_count++;
  70108. + FIQ_WRITE(state->mphi_regs.outdda, (int) state->dummy_send);
  70109. + FIQ_WRITE(state->mphi_regs.outddb, (1<<29));
  70110. +
  70111. + }
  70112. + state->fiq_done++;
  70113. + mb();
  70114. +}
  70115. +
  70116. +
  70117. +/**
  70118. + * dwc_otg_fiq_nop() - FIQ "lite"
  70119. + * @state: pointer to state struct passed from the banked FIQ mode registers.
  70120. + *
  70121. + * The "nop" handler does not intervene on any interrupts other than SOF.
  70122. + * It is limited in scope to deciding at each SOF if the IRQ SOF handler (which deals
  70123. + * with non-periodic/periodic queues) needs to be kicked.
  70124. + *
  70125. + * This is done to hold off the SOF interrupt, which occurs at a rate of 8000 per second.
  70126. + *
  70127. + * Return: void
  70128. + */
  70129. +void notrace dwc_otg_fiq_nop(struct fiq_state *state)
  70130. +{
  70131. + gintsts_data_t gintsts, gintsts_handled;
  70132. + gintmsk_data_t gintmsk;
  70133. + hfnum_data_t hfnum;
  70134. +
  70135. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  70136. + gintsts.d32 = FIQ_READ(state->dwc_regs_base + GINTSTS);
  70137. + gintmsk.d32 = FIQ_READ(state->dwc_regs_base + GINTMSK);
  70138. + gintsts.d32 &= gintmsk.d32;
  70139. + gintsts_handled.d32 = 0;
  70140. +
  70141. + if (gintsts.b.sofintr) {
  70142. + if (!state->kick_np_queues &&
  70143. + dwc_frame_num_gt(state->next_sched_frame, hfnum.b.frnum)) {
  70144. + /* SOF handled, no work to do, just ACK interrupt */
  70145. + gintsts_handled.b.sofintr = 1;
  70146. + } else {
  70147. + /* Kick IRQ */
  70148. + state->gintmsk_saved.b.sofintr = 0;
  70149. + }
  70150. + }
  70151. +
  70152. + /* Reset handled interrupts */
  70153. + if(gintsts_handled.d32) {
  70154. + FIQ_WRITE(state->dwc_regs_base + GINTSTS, gintsts_handled.d32);
  70155. + }
  70156. +
  70157. + /* Clear the bits in the saved register that were not handled but were triggered. */
  70158. + state->gintmsk_saved.d32 &= ~(gintsts.d32 & ~gintsts_handled.d32);
  70159. +
  70160. + /* We got an interrupt, didn't handle it and want to mask it */
  70161. + if (~(state->gintmsk_saved.d32)) {
  70162. + state->mphi_int_count++;
  70163. + gintmsk.d32 &= state->gintmsk_saved.d32;
  70164. + FIQ_WRITE(state->dwc_regs_base + GINTMSK, gintmsk.d32);
  70165. + /* Force a clear before another dummy send */
  70166. + FIQ_WRITE(state->mphi_regs.intstat, (1<<29));
  70167. + FIQ_WRITE(state->mphi_regs.outdda, (int) state->dummy_send);
  70168. + FIQ_WRITE(state->mphi_regs.outddb, (1<<29));
  70169. +
  70170. + }
  70171. + state->fiq_done++;
  70172. + mb();
  70173. +}
  70174. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h
  70175. --- linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h 1970-01-01 01:00:00.000000000 +0100
  70176. +++ linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h 2014-08-06 16:50:14.805964758 +0200
  70177. @@ -0,0 +1,353 @@
  70178. +/*
  70179. + * dwc_otg_fiq_fsm.h - Finite state machine FIQ header definitions
  70180. + *
  70181. + * Copyright (c) 2013 Raspberry Pi Foundation
  70182. + *
  70183. + * Author: Jonathan Bell <jonathan@raspberrypi.org>
  70184. + * All rights reserved.
  70185. + *
  70186. + * Redistribution and use in source and binary forms, with or without
  70187. + * modification, are permitted provided that the following conditions are met:
  70188. + * * Redistributions of source code must retain the above copyright
  70189. + * notice, this list of conditions and the following disclaimer.
  70190. + * * Redistributions in binary form must reproduce the above copyright
  70191. + * notice, this list of conditions and the following disclaimer in the
  70192. + * documentation and/or other materials provided with the distribution.
  70193. + * * Neither the name of Raspberry Pi nor the
  70194. + * names of its contributors may be used to endorse or promote products
  70195. + * derived from this software without specific prior written permission.
  70196. + *
  70197. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  70198. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  70199. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  70200. + * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  70201. + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  70202. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  70203. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  70204. + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  70205. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  70206. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  70207. + *
  70208. + * This FIQ implements functionality that performs split transactions on
  70209. + * the dwc_otg hardware without any outside intervention. A split transaction
  70210. + * is "queued" by nominating a specific host channel to perform the entirety
  70211. + * of a split transaction. This FIQ will then perform the microframe-precise
  70212. + * scheduling required in each phase of the transaction until completion.
  70213. + *
  70214. + * The FIQ functionality has been surgically implanted into the Synopsys
  70215. + * vendor-provided driver.
  70216. + *
  70217. + */
  70218. +
  70219. +#ifndef DWC_OTG_FIQ_FSM_H_
  70220. +#define DWC_OTG_FIQ_FSM_H_
  70221. +
  70222. +#include "dwc_otg_regs.h"
  70223. +#include "dwc_otg_cil.h"
  70224. +#include "dwc_otg_hcd.h"
  70225. +#include <linux/kernel.h>
  70226. +#include <linux/irqflags.h>
  70227. +#include <linux/string.h>
  70228. +#include <asm/barrier.h>
  70229. +
  70230. +#if 0
  70231. +#define FLAME_ON(x) \
  70232. +do { \
  70233. + int gpioreg; \
  70234. + \
  70235. + gpioreg = readl(__io_address(0x20200000+0x8)); \
  70236. + gpioreg &= ~(7 << (x-20)*3); \
  70237. + gpioreg |= 0x1 << (x-20)*3; \
  70238. + writel(gpioreg, __io_address(0x20200000+0x8)); \
  70239. + \
  70240. + writel(1<<x, __io_address(0x20200000+(0x1C))); \
  70241. +} while (0)
  70242. +
  70243. +#define FLAME_OFF(x) \
  70244. +do { \
  70245. + writel(1<<x, __io_address(0x20200000+(0x28))); \
  70246. +} while (0)
  70247. +#else
  70248. +#define FLAME_ON(x) do { } while (0)
  70249. +#define FLAME_OFF(X) do { } while (0)
  70250. +#endif
  70251. +
  70252. +/* This is a quick-and-dirty arch-specific register read/write. We know that
  70253. + * writes to a peripheral on BCM2835 will always arrive in-order, also that
  70254. + * reads and writes are executed in-order therefore the need for memory barriers
  70255. + * is obviated if we're only talking to USB.
  70256. + */
  70257. +#define FIQ_WRITE(_addr_,_data_) (*(volatile unsigned int *) (_addr_) = (_data_))
  70258. +#define FIQ_READ(_addr_) (*(volatile unsigned int *) (_addr_))
  70259. +
  70260. +/* FIQ-ified register definitions. Offsets are from dwc_regs_base. */
  70261. +#define GINTSTS 0x014
  70262. +#define GINTMSK 0x018
  70263. +/* Debug register. Poll the top of the received packets FIFO. */
  70264. +#define GRXSTSR 0x01C
  70265. +#define HFNUM 0x408
  70266. +#define HAINT 0x414
  70267. +#define HAINTMSK 0x418
  70268. +#define HPRT0 0x440
  70269. +
  70270. +/* HC_regs start from an offset of 0x500 */
  70271. +#define HC_START 0x500
  70272. +#define HC_OFFSET 0x020
  70273. +
  70274. +#define HC_DMA 0x514
  70275. +
  70276. +#define HCCHAR 0x00
  70277. +#define HCSPLT 0x04
  70278. +#define HCINT 0x08
  70279. +#define HCINTMSK 0x0C
  70280. +#define HCTSIZ 0x10
  70281. +
  70282. +#define ISOC_XACTPOS_ALL 0b11
  70283. +#define ISOC_XACTPOS_BEGIN 0b10
  70284. +#define ISOC_XACTPOS_MID 0b00
  70285. +#define ISOC_XACTPOS_END 0b01
  70286. +
  70287. +#define DWC_PID_DATA2 0b01
  70288. +#define DWC_PID_MDATA 0b11
  70289. +#define DWC_PID_DATA1 0b10
  70290. +#define DWC_PID_DATA0 0b00
  70291. +
  70292. +typedef struct {
  70293. + volatile void* base;
  70294. + volatile void* ctrl;
  70295. + volatile void* outdda;
  70296. + volatile void* outddb;
  70297. + volatile void* intstat;
  70298. +} mphi_regs_t;
  70299. +
  70300. +
  70301. +enum fiq_debug_level {
  70302. + FIQDBG_SCHED = (1 << 0),
  70303. + FIQDBG_INT = (1 << 1),
  70304. + FIQDBG_ERR = (1 << 2),
  70305. + FIQDBG_PORTHUB = (1 << 3),
  70306. +};
  70307. +
  70308. +struct fiq_state;
  70309. +
  70310. +extern void _fiq_print (enum fiq_debug_level dbg_lvl, volatile struct fiq_state *state, char *fmt, ...);
  70311. +#if 0
  70312. +#define fiq_print _fiq_print
  70313. +#else
  70314. +#define fiq_print(x, y, ...)
  70315. +#endif
  70316. +
  70317. +extern bool fiq_enable, fiq_fsm_enable;
  70318. +extern ushort nak_holdoff;
  70319. +
  70320. +/**
  70321. + * enum fiq_fsm_state - The FIQ FSM states.
  70322. + *
  70323. + * This is the "core" of the FIQ FSM. Broadly, the FSM states follow the
  70324. + * USB2.0 specification for host responses to various transaction states.
  70325. + * There are modifications to this host state machine because of a variety of
  70326. + * quirks and limitations in the dwc_otg hardware.
  70327. + *
  70328. + * The fsm state is also used to communicate back to the driver on completion of
  70329. + * a split transaction. The end states are used in conjunction with the interrupts
  70330. + * raised by the final transaction.
  70331. + */
  70332. +enum fiq_fsm_state {
  70333. + /* FIQ isn't enabled for this host channel */
  70334. + FIQ_PASSTHROUGH = 0,
  70335. + /* For the first interrupt received for this channel,
  70336. + * the FIQ has to ack any interrupts indicating success. */
  70337. + FIQ_PASSTHROUGH_ERRORSTATE = 31,
  70338. + /* Nonperiodic state groups */
  70339. + FIQ_NP_SSPLIT_STARTED = 1,
  70340. + FIQ_NP_SSPLIT_RETRY = 2,
  70341. + FIQ_NP_OUT_CSPLIT_RETRY = 3,
  70342. + FIQ_NP_IN_CSPLIT_RETRY = 4,
  70343. + FIQ_NP_SPLIT_DONE = 5,
  70344. + FIQ_NP_SPLIT_LS_ABORTED = 6,
  70345. + /* This differentiates a HS transaction error from a LS one
  70346. + * (handling the hub state is different) */
  70347. + FIQ_NP_SPLIT_HS_ABORTED = 7,
  70348. +
  70349. + /* Periodic state groups */
  70350. + /* Periodic transactions are either started directly by the IRQ handler
  70351. + * or deferred if the TT is already in use.
  70352. + */
  70353. + FIQ_PER_SSPLIT_QUEUED = 8,
  70354. + FIQ_PER_SSPLIT_STARTED = 9,
  70355. + FIQ_PER_SSPLIT_LAST = 10,
  70356. +
  70357. +
  70358. + FIQ_PER_ISO_OUT_PENDING = 11,
  70359. + FIQ_PER_ISO_OUT_ACTIVE = 12,
  70360. + FIQ_PER_ISO_OUT_LAST = 13,
  70361. + FIQ_PER_ISO_OUT_DONE = 27,
  70362. +
  70363. + FIQ_PER_CSPLIT_WAIT = 14,
  70364. + FIQ_PER_CSPLIT_NYET1 = 15,
  70365. + FIQ_PER_CSPLIT_BROKEN_NYET1 = 28,
  70366. + FIQ_PER_CSPLIT_NYET_FAFF = 29,
  70367. + /* For multiple CSPLITs (large isoc IN, or delayed interrupt) */
  70368. + FIQ_PER_CSPLIT_POLL = 16,
  70369. + /* The last CSPLIT for a transaction has been issued, differentiates
  70370. + * for the state machine to queue the next packet.
  70371. + */
  70372. + FIQ_PER_CSPLIT_LAST = 17,
  70373. +
  70374. + FIQ_PER_SPLIT_DONE = 18,
  70375. + FIQ_PER_SPLIT_LS_ABORTED = 19,
  70376. + FIQ_PER_SPLIT_HS_ABORTED = 20,
  70377. + FIQ_PER_SPLIT_NYET_ABORTED = 21,
  70378. + /* Frame rollover has occurred without the transaction finishing. */
  70379. + FIQ_PER_SPLIT_TIMEOUT = 22,
  70380. +
  70381. + /* FIQ-accelerated HS Isochronous state groups */
  70382. + FIQ_HS_ISOC_TURBO = 23,
  70383. + /* For interval > 1, SOF wakes up the isochronous FSM */
  70384. + FIQ_HS_ISOC_SLEEPING = 24,
  70385. + FIQ_HS_ISOC_DONE = 25,
  70386. + FIQ_HS_ISOC_ABORTED = 26,
  70387. + FIQ_DEQUEUE_ISSUED = 30,
  70388. + FIQ_TEST = 32,
  70389. +};
  70390. +
  70391. +struct fiq_stack {
  70392. + int magic1;
  70393. + uint8_t stack[2048];
  70394. + int magic2;
  70395. +};
  70396. +
  70397. +
  70398. +/**
  70399. + * struct fiq_dma_info - DMA bounce buffer utilisation information (per-channel)
  70400. + * @index: Number of slots reported used for IN transactions / number of slots
  70401. + * transmitted for an OUT transaction
  70402. + * @slot_len[6]: Number of actual transfer bytes in each slot (255 if unused)
  70403. + *
  70404. + * Split transaction transfers can have variable length depending on other bus
  70405. + * traffic. The OTG core DMA engine requires 4-byte aligned addresses therefore
  70406. + * each transaction needs a guaranteed aligned address. A maximum of 6 split transfers
  70407. + * can happen per-frame.
  70408. + */
  70409. +struct fiq_dma_info {
  70410. + u8 index;
  70411. + u8 slot_len[6];
  70412. +};
  70413. +
  70414. +struct __attribute__((packed)) fiq_split_dma_slot {
  70415. + u8 buf[188];
  70416. +};
  70417. +
  70418. +struct fiq_dma_channel {
  70419. + struct __attribute__((packed)) fiq_split_dma_slot index[6];
  70420. +};
  70421. +
  70422. +struct fiq_dma_blob {
  70423. + struct __attribute__((packed)) fiq_dma_channel channel[0];
  70424. +};
  70425. +
  70426. +/**
  70427. + * struct fiq_hs_isoc_info - USB2.0 isochronous data
  70428. + * @iso_frame: Pointer to the array of OTG URB iso_frame_descs.
  70429. + * @nrframes: Total length of iso_frame_desc array
  70430. + * @index: Current index (FIQ-maintained)
  70431. + *
  70432. + */
  70433. +struct fiq_hs_isoc_info {
  70434. + struct dwc_otg_hcd_iso_packet_desc *iso_desc;
  70435. + unsigned int nrframes;
  70436. + unsigned int index;
  70437. +};
  70438. +
  70439. +/**
  70440. + * struct fiq_channel_state - FIQ state machine storage
  70441. + * @fsm: Current state of the channel as understood by the FIQ
  70442. + * @nr_errors: Number of transaction errors on this split-transaction
  70443. + * @hub_addr: SSPLIT/CSPLIT destination hub
  70444. + * @port_addr: SSPLIT/CSPLIT destination port - always 1 if single TT hub
  70445. + * @nrpackets: For isoc OUT, the number of split-OUT packets to transmit. For
  70446. + * split-IN, number of CSPLIT data packets that were received.
  70447. + * @hcchar_copy:
  70448. + * @hcsplt_copy:
  70449. + * @hcintmsk_copy:
  70450. + * @hctsiz_copy: Copies of the host channel registers.
  70451. + * For use as scratch, or for returning state.
  70452. + *
  70453. + * The fiq_channel_state is state storage between interrupts for a host channel. The
  70454. + * FSM state is stored here. Members of this structure must only be set up by the
  70455. + * driver prior to enabling the FIQ for this host channel, and not touched until the FIQ
  70456. + * has updated the state to either a COMPLETE state group or ABORT state group.
  70457. + */
  70458. +
  70459. +struct fiq_channel_state {
  70460. + enum fiq_fsm_state fsm;
  70461. + unsigned int nr_errors;
  70462. + unsigned int hub_addr;
  70463. + unsigned int port_addr;
  70464. + /* Hardware bug workaround: sometimes channel halt interrupts are
  70465. + * delayed until the next SOF. Keep track of when we expected to get interrupted. */
  70466. + unsigned int expected_uframe;
  70467. + /* in/out for communicating number of dma buffers used, or number of ISOC to do */
  70468. + unsigned int nrpackets;
  70469. + struct fiq_dma_info dma_info;
  70470. + struct fiq_hs_isoc_info hs_isoc_info;
  70471. + /* Copies of HC registers - in/out communication from/to IRQ handler
  70472. + * and for ease of channel setup. A bit of mungeing is performed - for
  70473. + * example the hctsiz.b.maxp is _always_ the max packet size of the endpoint.
  70474. + */
  70475. + hcchar_data_t hcchar_copy;
  70476. + hcsplt_data_t hcsplt_copy;
  70477. + hcint_data_t hcint_copy;
  70478. + hcintmsk_data_t hcintmsk_copy;
  70479. + hctsiz_data_t hctsiz_copy;
  70480. + hcdma_data_t hcdma_copy;
  70481. +};
  70482. +
  70483. +/**
  70484. + * struct fiq_state - top-level FIQ state machine storage
  70485. + * @mphi_regs: virtual address of the MPHI peripheral register file
  70486. + * @dwc_regs_base: virtual address of the base of the DWC core register file
  70487. + * @dma_base: physical address for the base of the DMA bounce buffers
  70488. + * @dummy_send: Scratch area for sending a fake message to the MPHI peripheral
  70489. + * @gintmsk_saved: Top-level mask of interrupts that the FIQ has not handled.
  70490. + * Used for determining which interrupts fired to set off the IRQ handler.
  70491. + * @haintmsk_saved: Mask of interrupts from host channels that the FIQ did not handle internally.
  70492. + * @np_count: Non-periodic transactions in the active queue
  70493. + * @np_sent: Count of non-periodic transactions that have completed
  70494. + * @next_sched_frame: For periodic transactions handled by the driver's SOF-driven queuing mechanism,
  70495. + * this is the next frame on which a SOF interrupt is required. Used to hold off
  70496. + * passing SOF through to the driver until necessary.
  70497. + * @channel[n]: Per-channel FIQ state. Allocated during init depending on the number of host
  70498. + * channels configured into the core logic.
  70499. + *
  70500. + * This is passed as the first argument to the dwc_otg_fiq_fsm top-level FIQ handler from the asm stub.
  70501. + * It contains top-level state information.
  70502. + */
  70503. +struct fiq_state {
  70504. + mphi_regs_t mphi_regs;
  70505. + void *dwc_regs_base;
  70506. + dma_addr_t dma_base;
  70507. + struct fiq_dma_blob *fiq_dmab;
  70508. + void *dummy_send;
  70509. + gintmsk_data_t gintmsk_saved;
  70510. + haintmsk_data_t haintmsk_saved;
  70511. + int mphi_int_count;
  70512. + unsigned int fiq_done;
  70513. + unsigned int kick_np_queues;
  70514. + unsigned int next_sched_frame;
  70515. +#ifdef FIQ_DEBUG
  70516. + char * buffer;
  70517. + unsigned int bufsiz;
  70518. +#endif
  70519. + struct fiq_channel_state channel[0];
  70520. +};
  70521. +
  70522. +extern int fiq_fsm_too_late(struct fiq_state *st, int n);
  70523. +
  70524. +extern int fiq_fsm_tt_in_use(struct fiq_state *st, int num_channels, int n);
  70525. +
  70526. +extern void dwc_otg_fiq_fsm(struct fiq_state *state, int num_channels);
  70527. +
  70528. +extern void dwc_otg_fiq_nop(struct fiq_state *state);
  70529. +
  70530. +#endif /* DWC_OTG_FIQ_FSM_H_ */
  70531. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_fiq_stub.S linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_fiq_stub.S
  70532. --- linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_fiq_stub.S 1970-01-01 01:00:00.000000000 +0100
  70533. +++ linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_fiq_stub.S 2014-08-06 16:50:14.805964758 +0200
  70534. @@ -0,0 +1,81 @@
  70535. +/*
  70536. + * dwc_otg_fiq_fsm.S - assembly stub for the FSM FIQ
  70537. + *
  70538. + * Copyright (c) 2013 Raspberry Pi Foundation
  70539. + *
  70540. + * Author: Jonathan Bell <jonathan@raspberrypi.org>
  70541. + * All rights reserved.
  70542. + *
  70543. + * Redistribution and use in source and binary forms, with or without
  70544. + * modification, are permitted provided that the following conditions are met:
  70545. + * * Redistributions of source code must retain the above copyright
  70546. + * notice, this list of conditions and the following disclaimer.
  70547. + * * Redistributions in binary form must reproduce the above copyright
  70548. + * notice, this list of conditions and the following disclaimer in the
  70549. + * documentation and/or other materials provided with the distribution.
  70550. + * * Neither the name of Raspberry Pi nor the
  70551. + * names of its contributors may be used to endorse or promote products
  70552. + * derived from this software without specific prior written permission.
  70553. + *
  70554. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  70555. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  70556. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  70557. + * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  70558. + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  70559. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  70560. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  70561. + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  70562. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  70563. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  70564. + */
  70565. +
  70566. +
  70567. +#include <asm/assembler.h>
  70568. +#include <linux/linkage.h>
  70569. +
  70570. +
  70571. +.text
  70572. +
  70573. +.global _dwc_otg_fiq_stub_end;
  70574. +
  70575. +/**
  70576. + * _dwc_otg_fiq_stub() - entry copied to the FIQ vector page to allow
  70577. + * a C-style function call with arguments from the FIQ banked registers.
  70578. + * r0 = &hcd->fiq_state
  70579. + * r1 = &hcd->num_channels
  70580. + * r2 = &hcd->dma_buffers
  70581. + * Tramples: r0, r1, r2, r4, fp, ip
  70582. + */
  70583. +
  70584. +ENTRY(_dwc_otg_fiq_stub)
  70585. + /* Stash unbanked regs - SP will have been set up for us */
  70586. + mov ip, sp;
  70587. + stmdb sp!, {r0-r12, lr};
  70588. +#ifdef FIQ_DEBUG
  70589. + // Cycle profiling - read cycle counter at start
  70590. + mrc p15, 0, r5, c15, c12, 1;
  70591. +#endif
  70592. + /* r11 = fp, don't trample it */
  70593. + mov r4, fp;
  70594. + /* set EABI frame size */
  70595. + sub fp, ip, #512;
  70596. +
  70597. + /* for fiq NOP mode - just need state */
  70598. + mov r0, r8;
  70599. + /* r9 = num_channels */
  70600. + mov r1, r9;
  70601. + /* r10 = struct *dma_bufs */
  70602. +// mov r2, r10;
  70603. +
  70604. + /* r4 = &fiq_c_function */
  70605. + blx r4;
  70606. +#ifdef FIQ_DEBUG
  70607. + mrc p15, 0, r4, c15, c12, 1;
  70608. + subs r5, r5, r4;
  70609. + // r5 is now the cycle count time for executing the FIQ. Store it somewhere?
  70610. +#endif
  70611. + ldmia sp!, {r0-r12, lr};
  70612. + subs pc, lr, #4;
  70613. +_dwc_otg_fiq_stub_end:
  70614. +END(_dwc_otg_fiq_stub)
  70615. +
  70616. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd.c linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_hcd.c
  70617. --- linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd.c 1970-01-01 01:00:00.000000000 +0100
  70618. +++ linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_hcd.c 2014-08-06 16:50:14.813964820 +0200
  70619. @@ -0,0 +1,4188 @@
  70620. +
  70621. +/* ==========================================================================
  70622. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd.c $
  70623. + * $Revision: #104 $
  70624. + * $Date: 2011/10/24 $
  70625. + * $Change: 1871159 $
  70626. + *
  70627. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  70628. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  70629. + * otherwise expressly agreed to in writing between Synopsys and you.
  70630. + *
  70631. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  70632. + * any End User Software License Agreement or Agreement for Licensed Product
  70633. + * with Synopsys or any supplement thereto. You are permitted to use and
  70634. + * redistribute this Software in source and binary forms, with or without
  70635. + * modification, provided that redistributions of source code must retain this
  70636. + * notice. You may not view, use, disclose, copy or distribute this file or
  70637. + * any information contained herein except pursuant to this license grant from
  70638. + * Synopsys. If you do not agree with this notice, including the disclaimer
  70639. + * below, then you are not authorized to use the Software.
  70640. + *
  70641. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  70642. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  70643. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  70644. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  70645. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  70646. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  70647. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  70648. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  70649. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  70650. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  70651. + * DAMAGE.
  70652. + * ========================================================================== */
  70653. +#ifndef DWC_DEVICE_ONLY
  70654. +
  70655. +/** @file
  70656. + * This file implements HCD Core. All code in this file is portable and doesn't
  70657. + * use any OS specific functions.
  70658. + * Interface provided by HCD Core is defined in <code><hcd_if.h></code>
  70659. + * header file.
  70660. + */
  70661. +
  70662. +#include <linux/usb.h>
  70663. +#include <linux/usb/hcd.h>
  70664. +
  70665. +#include "dwc_otg_hcd.h"
  70666. +#include "dwc_otg_regs.h"
  70667. +#include "dwc_otg_fiq_fsm.h"
  70668. +
  70669. +extern bool microframe_schedule;
  70670. +extern uint16_t fiq_fsm_mask, nak_holdoff;
  70671. +
  70672. +//#define DEBUG_HOST_CHANNELS
  70673. +#ifdef DEBUG_HOST_CHANNELS
  70674. +static int last_sel_trans_num_per_scheduled = 0;
  70675. +static int last_sel_trans_num_nonper_scheduled = 0;
  70676. +static int last_sel_trans_num_avail_hc_at_start = 0;
  70677. +static int last_sel_trans_num_avail_hc_at_end = 0;
  70678. +#endif /* DEBUG_HOST_CHANNELS */
  70679. +
  70680. +
  70681. +dwc_otg_hcd_t *dwc_otg_hcd_alloc_hcd(void)
  70682. +{
  70683. + return DWC_ALLOC(sizeof(dwc_otg_hcd_t));
  70684. +}
  70685. +
  70686. +/**
  70687. + * Connection timeout function. An OTG host is required to display a
  70688. + * message if the device does not connect within 10 seconds.
  70689. + */
  70690. +void dwc_otg_hcd_connect_timeout(void *ptr)
  70691. +{
  70692. + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, ptr);
  70693. + DWC_PRINTF("Connect Timeout\n");
  70694. + __DWC_ERROR("Device Not Connected/Responding\n");
  70695. +}
  70696. +
  70697. +#if defined(DEBUG)
  70698. +static void dump_channel_info(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  70699. +{
  70700. + if (qh->channel != NULL) {
  70701. + dwc_hc_t *hc = qh->channel;
  70702. + dwc_list_link_t *item;
  70703. + dwc_otg_qh_t *qh_item;
  70704. + int num_channels = hcd->core_if->core_params->host_channels;
  70705. + int i;
  70706. +
  70707. + dwc_otg_hc_regs_t *hc_regs;
  70708. + hcchar_data_t hcchar;
  70709. + hcsplt_data_t hcsplt;
  70710. + hctsiz_data_t hctsiz;
  70711. + uint32_t hcdma;
  70712. +
  70713. + hc_regs = hcd->core_if->host_if->hc_regs[hc->hc_num];
  70714. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70715. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  70716. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  70717. + hcdma = DWC_READ_REG32(&hc_regs->hcdma);
  70718. +
  70719. + DWC_PRINTF(" Assigned to channel %p:\n", hc);
  70720. + DWC_PRINTF(" hcchar 0x%08x, hcsplt 0x%08x\n", hcchar.d32,
  70721. + hcsplt.d32);
  70722. + DWC_PRINTF(" hctsiz 0x%08x, hcdma 0x%08x\n", hctsiz.d32,
  70723. + hcdma);
  70724. + DWC_PRINTF(" dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
  70725. + hc->dev_addr, hc->ep_num, hc->ep_is_in);
  70726. + DWC_PRINTF(" ep_type: %d\n", hc->ep_type);
  70727. + DWC_PRINTF(" max_packet: %d\n", hc->max_packet);
  70728. + DWC_PRINTF(" data_pid_start: %d\n", hc->data_pid_start);
  70729. + DWC_PRINTF(" xfer_started: %d\n", hc->xfer_started);
  70730. + DWC_PRINTF(" halt_status: %d\n", hc->halt_status);
  70731. + DWC_PRINTF(" xfer_buff: %p\n", hc->xfer_buff);
  70732. + DWC_PRINTF(" xfer_len: %d\n", hc->xfer_len);
  70733. + DWC_PRINTF(" qh: %p\n", hc->qh);
  70734. + DWC_PRINTF(" NP inactive sched:\n");
  70735. + DWC_LIST_FOREACH(item, &hcd->non_periodic_sched_inactive) {
  70736. + qh_item =
  70737. + DWC_LIST_ENTRY(item, dwc_otg_qh_t, qh_list_entry);
  70738. + DWC_PRINTF(" %p\n", qh_item);
  70739. + }
  70740. + DWC_PRINTF(" NP active sched:\n");
  70741. + DWC_LIST_FOREACH(item, &hcd->non_periodic_sched_active) {
  70742. + qh_item =
  70743. + DWC_LIST_ENTRY(item, dwc_otg_qh_t, qh_list_entry);
  70744. + DWC_PRINTF(" %p\n", qh_item);
  70745. + }
  70746. + DWC_PRINTF(" Channels: \n");
  70747. + for (i = 0; i < num_channels; i++) {
  70748. + dwc_hc_t *hc = hcd->hc_ptr_array[i];
  70749. + DWC_PRINTF(" %2d: %p\n", i, hc);
  70750. + }
  70751. + }
  70752. +}
  70753. +#else
  70754. +#define dump_channel_info(hcd, qh)
  70755. +#endif /* DEBUG */
  70756. +
  70757. +/**
  70758. + * Work queue function for starting the HCD when A-Cable is connected.
  70759. + * The hcd_start() must be called in a process context.
  70760. + */
  70761. +static void hcd_start_func(void *_vp)
  70762. +{
  70763. + dwc_otg_hcd_t *hcd = (dwc_otg_hcd_t *) _vp;
  70764. +
  70765. + DWC_DEBUGPL(DBG_HCDV, "%s() %p\n", __func__, hcd);
  70766. + if (hcd) {
  70767. + hcd->fops->start(hcd);
  70768. + }
  70769. +}
  70770. +
  70771. +static void del_xfer_timers(dwc_otg_hcd_t * hcd)
  70772. +{
  70773. +#ifdef DEBUG
  70774. + int i;
  70775. + int num_channels = hcd->core_if->core_params->host_channels;
  70776. + for (i = 0; i < num_channels; i++) {
  70777. + DWC_TIMER_CANCEL(hcd->core_if->hc_xfer_timer[i]);
  70778. + }
  70779. +#endif
  70780. +}
  70781. +
  70782. +static void del_timers(dwc_otg_hcd_t * hcd)
  70783. +{
  70784. + del_xfer_timers(hcd);
  70785. + DWC_TIMER_CANCEL(hcd->conn_timer);
  70786. +}
  70787. +
  70788. +/**
  70789. + * Processes all the URBs in a single list of QHs. Completes them with
  70790. + * -ESHUTDOWN and frees the QTD.
  70791. + */
  70792. +static void kill_urbs_in_qh_list(dwc_otg_hcd_t * hcd, dwc_list_link_t * qh_list)
  70793. +{
  70794. + dwc_list_link_t *qh_item, *qh_tmp;
  70795. + dwc_otg_qh_t *qh;
  70796. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  70797. +
  70798. + DWC_LIST_FOREACH_SAFE(qh_item, qh_tmp, qh_list) {
  70799. + qh = DWC_LIST_ENTRY(qh_item, dwc_otg_qh_t, qh_list_entry);
  70800. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp,
  70801. + &qh->qtd_list, qtd_list_entry) {
  70802. + qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  70803. + if (qtd->urb != NULL) {
  70804. + hcd->fops->complete(hcd, qtd->urb->priv,
  70805. + qtd->urb, -DWC_E_SHUTDOWN);
  70806. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  70807. + }
  70808. +
  70809. + }
  70810. + if(qh->channel) {
  70811. + /* Using hcchar.chen == 1 is not a reliable test.
  70812. + * It is possible that the channel has already halted
  70813. + * but not yet been through the IRQ handler.
  70814. + */
  70815. + dwc_otg_hc_halt(hcd->core_if, qh->channel,
  70816. + DWC_OTG_HC_XFER_URB_DEQUEUE);
  70817. + if(microframe_schedule)
  70818. + hcd->available_host_channels++;
  70819. + qh->channel = NULL;
  70820. + }
  70821. + dwc_otg_hcd_qh_remove(hcd, qh);
  70822. + }
  70823. +}
  70824. +
  70825. +/**
  70826. + * Responds with an error status of ESHUTDOWN to all URBs in the non-periodic
  70827. + * and periodic schedules. The QTD associated with each URB is removed from
  70828. + * the schedule and freed. This function may be called when a disconnect is
  70829. + * detected or when the HCD is being stopped.
  70830. + */
  70831. +static void kill_all_urbs(dwc_otg_hcd_t * hcd)
  70832. +{
  70833. + kill_urbs_in_qh_list(hcd, &hcd->non_periodic_sched_inactive);
  70834. + kill_urbs_in_qh_list(hcd, &hcd->non_periodic_sched_active);
  70835. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_inactive);
  70836. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_ready);
  70837. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_assigned);
  70838. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_queued);
  70839. +}
  70840. +
  70841. +/**
  70842. + * Start the connection timer. An OTG host is required to display a
  70843. + * message if the device does not connect within 10 seconds. The
  70844. + * timer is deleted if a port connect interrupt occurs before the
  70845. + * timer expires.
  70846. + */
  70847. +static void dwc_otg_hcd_start_connect_timer(dwc_otg_hcd_t * hcd)
  70848. +{
  70849. + DWC_TIMER_SCHEDULE(hcd->conn_timer, 10000 /* 10 secs */ );
  70850. +}
  70851. +
  70852. +/**
  70853. + * HCD Callback function for disconnect of the HCD.
  70854. + *
  70855. + * @param p void pointer to the <code>struct usb_hcd</code>
  70856. + */
  70857. +static int32_t dwc_otg_hcd_session_start_cb(void *p)
  70858. +{
  70859. + dwc_otg_hcd_t *dwc_otg_hcd;
  70860. + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, p);
  70861. + dwc_otg_hcd = p;
  70862. + dwc_otg_hcd_start_connect_timer(dwc_otg_hcd);
  70863. + return 1;
  70864. +}
  70865. +
  70866. +/**
  70867. + * HCD Callback function for starting the HCD when A-Cable is
  70868. + * connected.
  70869. + *
  70870. + * @param p void pointer to the <code>struct usb_hcd</code>
  70871. + */
  70872. +static int32_t dwc_otg_hcd_start_cb(void *p)
  70873. +{
  70874. + dwc_otg_hcd_t *dwc_otg_hcd = p;
  70875. + dwc_otg_core_if_t *core_if;
  70876. + hprt0_data_t hprt0;
  70877. +
  70878. + core_if = dwc_otg_hcd->core_if;
  70879. +
  70880. + if (core_if->op_state == B_HOST) {
  70881. + /*
  70882. + * Reset the port. During a HNP mode switch the reset
  70883. + * needs to occur within 1ms and have a duration of at
  70884. + * least 50ms.
  70885. + */
  70886. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  70887. + hprt0.b.prtrst = 1;
  70888. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  70889. + }
  70890. + DWC_WORKQ_SCHEDULE_DELAYED(core_if->wq_otg,
  70891. + hcd_start_func, dwc_otg_hcd, 50,
  70892. + "start hcd");
  70893. +
  70894. + return 1;
  70895. +}
  70896. +
  70897. +/**
  70898. + * HCD Callback function for disconnect of the HCD.
  70899. + *
  70900. + * @param p void pointer to the <code>struct usb_hcd</code>
  70901. + */
  70902. +static int32_t dwc_otg_hcd_disconnect_cb(void *p)
  70903. +{
  70904. + gintsts_data_t intr;
  70905. + dwc_otg_hcd_t *dwc_otg_hcd = p;
  70906. +
  70907. + /*
  70908. + * Set status flags for the hub driver.
  70909. + */
  70910. + dwc_otg_hcd->flags.b.port_connect_status_change = 1;
  70911. + dwc_otg_hcd->flags.b.port_connect_status = 0;
  70912. + if(fiq_enable)
  70913. + local_fiq_disable();
  70914. + /*
  70915. + * Shutdown any transfers in process by clearing the Tx FIFO Empty
  70916. + * interrupt mask and status bits and disabling subsequent host
  70917. + * channel interrupts.
  70918. + */
  70919. + intr.d32 = 0;
  70920. + intr.b.nptxfempty = 1;
  70921. + intr.b.ptxfempty = 1;
  70922. + intr.b.hcintr = 1;
  70923. + DWC_MODIFY_REG32(&dwc_otg_hcd->core_if->core_global_regs->gintmsk,
  70924. + intr.d32, 0);
  70925. + DWC_MODIFY_REG32(&dwc_otg_hcd->core_if->core_global_regs->gintsts,
  70926. + intr.d32, 0);
  70927. +
  70928. + del_timers(dwc_otg_hcd);
  70929. +
  70930. + /*
  70931. + * Turn off the vbus power only if the core has transitioned to device
  70932. + * mode. If still in host mode, need to keep power on to detect a
  70933. + * reconnection.
  70934. + */
  70935. + if (dwc_otg_is_device_mode(dwc_otg_hcd->core_if)) {
  70936. + if (dwc_otg_hcd->core_if->op_state != A_SUSPEND) {
  70937. + hprt0_data_t hprt0 = {.d32 = 0 };
  70938. + DWC_PRINTF("Disconnect: PortPower off\n");
  70939. + hprt0.b.prtpwr = 0;
  70940. + DWC_WRITE_REG32(dwc_otg_hcd->core_if->host_if->hprt0,
  70941. + hprt0.d32);
  70942. + }
  70943. +
  70944. + dwc_otg_disable_host_interrupts(dwc_otg_hcd->core_if);
  70945. + }
  70946. +
  70947. + /* Respond with an error status to all URBs in the schedule. */
  70948. + kill_all_urbs(dwc_otg_hcd);
  70949. +
  70950. + if (dwc_otg_is_host_mode(dwc_otg_hcd->core_if)) {
  70951. + /* Clean up any host channels that were in use. */
  70952. + int num_channels;
  70953. + int i;
  70954. + dwc_hc_t *channel;
  70955. + dwc_otg_hc_regs_t *hc_regs;
  70956. + hcchar_data_t hcchar;
  70957. +
  70958. + num_channels = dwc_otg_hcd->core_if->core_params->host_channels;
  70959. +
  70960. + if (!dwc_otg_hcd->core_if->dma_enable) {
  70961. + /* Flush out any channel requests in slave mode. */
  70962. + for (i = 0; i < num_channels; i++) {
  70963. + channel = dwc_otg_hcd->hc_ptr_array[i];
  70964. + if (DWC_CIRCLEQ_EMPTY_ENTRY
  70965. + (channel, hc_list_entry)) {
  70966. + hc_regs =
  70967. + dwc_otg_hcd->core_if->
  70968. + host_if->hc_regs[i];
  70969. + hcchar.d32 =
  70970. + DWC_READ_REG32(&hc_regs->hcchar);
  70971. + if (hcchar.b.chen) {
  70972. + hcchar.b.chen = 0;
  70973. + hcchar.b.chdis = 1;
  70974. + hcchar.b.epdir = 0;
  70975. + DWC_WRITE_REG32
  70976. + (&hc_regs->hcchar,
  70977. + hcchar.d32);
  70978. + }
  70979. + }
  70980. + }
  70981. + }
  70982. +
  70983. + for (i = 0; i < num_channels; i++) {
  70984. + channel = dwc_otg_hcd->hc_ptr_array[i];
  70985. + if (DWC_CIRCLEQ_EMPTY_ENTRY(channel, hc_list_entry)) {
  70986. + hc_regs =
  70987. + dwc_otg_hcd->core_if->host_if->hc_regs[i];
  70988. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70989. + if (hcchar.b.chen) {
  70990. + /* Halt the channel. */
  70991. + hcchar.b.chdis = 1;
  70992. + DWC_WRITE_REG32(&hc_regs->hcchar,
  70993. + hcchar.d32);
  70994. + }
  70995. +
  70996. + dwc_otg_hc_cleanup(dwc_otg_hcd->core_if,
  70997. + channel);
  70998. + DWC_CIRCLEQ_INSERT_TAIL
  70999. + (&dwc_otg_hcd->free_hc_list, channel,
  71000. + hc_list_entry);
  71001. + /*
  71002. + * Added for Descriptor DMA to prevent channel double cleanup
  71003. + * in release_channel_ddma(). Which called from ep_disable
  71004. + * when device disconnect.
  71005. + */
  71006. + channel->qh = NULL;
  71007. + }
  71008. + }
  71009. + if(fiq_fsm_enable) {
  71010. + for(i=0; i < 128; i++) {
  71011. + dwc_otg_hcd->hub_port[i] = 0;
  71012. + }
  71013. + }
  71014. +
  71015. + }
  71016. +
  71017. + if(fiq_enable)
  71018. + local_fiq_enable();
  71019. +
  71020. + if (dwc_otg_hcd->fops->disconnect) {
  71021. + dwc_otg_hcd->fops->disconnect(dwc_otg_hcd);
  71022. + }
  71023. +
  71024. + return 1;
  71025. +}
  71026. +
  71027. +/**
  71028. + * HCD Callback function for stopping the HCD.
  71029. + *
  71030. + * @param p void pointer to the <code>struct usb_hcd</code>
  71031. + */
  71032. +static int32_t dwc_otg_hcd_stop_cb(void *p)
  71033. +{
  71034. + dwc_otg_hcd_t *dwc_otg_hcd = p;
  71035. +
  71036. + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, p);
  71037. + dwc_otg_hcd_stop(dwc_otg_hcd);
  71038. + return 1;
  71039. +}
  71040. +
  71041. +#ifdef CONFIG_USB_DWC_OTG_LPM
  71042. +/**
  71043. + * HCD Callback function for sleep of HCD.
  71044. + *
  71045. + * @param p void pointer to the <code>struct usb_hcd</code>
  71046. + */
  71047. +static int dwc_otg_hcd_sleep_cb(void *p)
  71048. +{
  71049. + dwc_otg_hcd_t *hcd = p;
  71050. +
  71051. + dwc_otg_hcd_free_hc_from_lpm(hcd);
  71052. +
  71053. + return 0;
  71054. +}
  71055. +#endif
  71056. +
  71057. +
  71058. +/**
  71059. + * HCD Callback function for Remote Wakeup.
  71060. + *
  71061. + * @param p void pointer to the <code>struct usb_hcd</code>
  71062. + */
  71063. +static int dwc_otg_hcd_rem_wakeup_cb(void *p)
  71064. +{
  71065. + dwc_otg_hcd_t *hcd = p;
  71066. +
  71067. + if (hcd->core_if->lx_state == DWC_OTG_L2) {
  71068. + hcd->flags.b.port_suspend_change = 1;
  71069. + }
  71070. +#ifdef CONFIG_USB_DWC_OTG_LPM
  71071. + else {
  71072. + hcd->flags.b.port_l1_change = 1;
  71073. + }
  71074. +#endif
  71075. + return 0;
  71076. +}
  71077. +
  71078. +/**
  71079. + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
  71080. + * stopped.
  71081. + */
  71082. +void dwc_otg_hcd_stop(dwc_otg_hcd_t * hcd)
  71083. +{
  71084. + hprt0_data_t hprt0 = {.d32 = 0 };
  71085. +
  71086. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD STOP\n");
  71087. +
  71088. + /*
  71089. + * The root hub should be disconnected before this function is called.
  71090. + * The disconnect will clear the QTD lists (via ..._hcd_urb_dequeue)
  71091. + * and the QH lists (via ..._hcd_endpoint_disable).
  71092. + */
  71093. +
  71094. + /* Turn off all host-specific interrupts. */
  71095. + dwc_otg_disable_host_interrupts(hcd->core_if);
  71096. +
  71097. + /* Turn off the vbus power */
  71098. + DWC_PRINTF("PortPower off\n");
  71099. + hprt0.b.prtpwr = 0;
  71100. + DWC_WRITE_REG32(hcd->core_if->host_if->hprt0, hprt0.d32);
  71101. + dwc_mdelay(1);
  71102. +}
  71103. +
  71104. +int dwc_otg_hcd_urb_enqueue(dwc_otg_hcd_t * hcd,
  71105. + dwc_otg_hcd_urb_t * dwc_otg_urb, void **ep_handle,
  71106. + int atomic_alloc)
  71107. +{
  71108. + int retval = 0;
  71109. + uint8_t needs_scheduling = 0;
  71110. + dwc_otg_transaction_type_e tr_type;
  71111. + dwc_otg_qtd_t *qtd;
  71112. + gintmsk_data_t intr_mask = {.d32 = 0 };
  71113. + hprt0_data_t hprt0 = { .d32 = 0 };
  71114. +
  71115. +#ifdef DEBUG /* integrity checks (Broadcom) */
  71116. + if (NULL == hcd->core_if) {
  71117. + DWC_ERROR("**** DWC OTG HCD URB Enqueue - HCD has NULL core_if\n");
  71118. + /* No longer connected. */
  71119. + return -DWC_E_INVALID;
  71120. + }
  71121. +#endif
  71122. + if (!hcd->flags.b.port_connect_status) {
  71123. + /* No longer connected. */
  71124. + DWC_ERROR("Not connected\n");
  71125. + return -DWC_E_NO_DEVICE;
  71126. + }
  71127. +
  71128. + /* Some core configurations cannot support LS traffic on a FS root port */
  71129. + if ((hcd->fops->speed(hcd, dwc_otg_urb->priv) == USB_SPEED_LOW) &&
  71130. + (hcd->core_if->hwcfg2.b.fs_phy_type == 1) &&
  71131. + (hcd->core_if->hwcfg2.b.hs_phy_type == 1)) {
  71132. + hprt0.d32 = DWC_READ_REG32(hcd->core_if->host_if->hprt0);
  71133. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_FULL_SPEED) {
  71134. + return -DWC_E_NO_DEVICE;
  71135. + }
  71136. + }
  71137. +
  71138. + qtd = dwc_otg_hcd_qtd_create(dwc_otg_urb, atomic_alloc);
  71139. + if (qtd == NULL) {
  71140. + DWC_ERROR("DWC OTG HCD URB Enqueue failed creating QTD\n");
  71141. + return -DWC_E_NO_MEMORY;
  71142. + }
  71143. +#ifdef DEBUG /* integrity checks (Broadcom) */
  71144. + if (qtd->urb == NULL) {
  71145. + DWC_ERROR("**** DWC OTG HCD URB Enqueue created QTD with no URBs\n");
  71146. + return -DWC_E_NO_MEMORY;
  71147. + }
  71148. + if (qtd->urb->priv == NULL) {
  71149. + DWC_ERROR("**** DWC OTG HCD URB Enqueue created QTD URB with no URB handle\n");
  71150. + return -DWC_E_NO_MEMORY;
  71151. + }
  71152. +#endif
  71153. + intr_mask.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->gintmsk);
  71154. + if(!intr_mask.b.sofintr || fiq_enable) needs_scheduling = 1;
  71155. + if((((dwc_otg_qh_t *)ep_handle)->ep_type == UE_BULK) && !(qtd->urb->flags & URB_GIVEBACK_ASAP))
  71156. + /* Do not schedule SG transactions until qtd has URB_GIVEBACK_ASAP set */
  71157. + needs_scheduling = 0;
  71158. +
  71159. + retval = dwc_otg_hcd_qtd_add(qtd, hcd, (dwc_otg_qh_t **) ep_handle, atomic_alloc);
  71160. + // creates a new queue in ep_handle if it doesn't exist already
  71161. + if (retval < 0) {
  71162. + DWC_ERROR("DWC OTG HCD URB Enqueue failed adding QTD. "
  71163. + "Error status %d\n", retval);
  71164. + dwc_otg_hcd_qtd_free(qtd);
  71165. + return retval;
  71166. + }
  71167. +
  71168. + if(needs_scheduling) {
  71169. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  71170. + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
  71171. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  71172. + }
  71173. + }
  71174. + return retval;
  71175. +}
  71176. +
  71177. +int dwc_otg_hcd_urb_dequeue(dwc_otg_hcd_t * hcd,
  71178. + dwc_otg_hcd_urb_t * dwc_otg_urb)
  71179. +{
  71180. + dwc_otg_qh_t *qh;
  71181. + dwc_otg_qtd_t *urb_qtd;
  71182. + BUG_ON(!hcd);
  71183. + BUG_ON(!dwc_otg_urb);
  71184. +
  71185. +#ifdef DEBUG /* integrity checks (Broadcom) */
  71186. +
  71187. + if (hcd == NULL) {
  71188. + DWC_ERROR("**** DWC OTG HCD URB Dequeue has NULL HCD\n");
  71189. + return -DWC_E_INVALID;
  71190. + }
  71191. + if (dwc_otg_urb == NULL) {
  71192. + DWC_ERROR("**** DWC OTG HCD URB Dequeue has NULL URB\n");
  71193. + return -DWC_E_INVALID;
  71194. + }
  71195. + if (dwc_otg_urb->qtd == NULL) {
  71196. + DWC_ERROR("**** DWC OTG HCD URB Dequeue with NULL QTD\n");
  71197. + return -DWC_E_INVALID;
  71198. + }
  71199. + urb_qtd = dwc_otg_urb->qtd;
  71200. + BUG_ON(!urb_qtd);
  71201. + if (urb_qtd->qh == NULL) {
  71202. + DWC_ERROR("**** DWC OTG HCD URB Dequeue with QTD with NULL Q handler\n");
  71203. + return -DWC_E_INVALID;
  71204. + }
  71205. +#else
  71206. + urb_qtd = dwc_otg_urb->qtd;
  71207. + BUG_ON(!urb_qtd);
  71208. +#endif
  71209. + qh = urb_qtd->qh;
  71210. + BUG_ON(!qh);
  71211. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  71212. + if (urb_qtd->in_process) {
  71213. + dump_channel_info(hcd, qh);
  71214. + }
  71215. + }
  71216. +#ifdef DEBUG /* integrity checks (Broadcom) */
  71217. + if (hcd->core_if == NULL) {
  71218. + DWC_ERROR("**** DWC OTG HCD URB Dequeue HCD has NULL core_if\n");
  71219. + return -DWC_E_INVALID;
  71220. + }
  71221. +#endif
  71222. + if (urb_qtd->in_process && qh->channel) {
  71223. + /* The QTD is in process (it has been assigned to a channel). */
  71224. + if (hcd->flags.b.port_connect_status) {
  71225. + int n = qh->channel->hc_num;
  71226. + /*
  71227. + * If still connected (i.e. in host mode), halt the
  71228. + * channel so it can be used for other transfers. If
  71229. + * no longer connected, the host registers can't be
  71230. + * written to halt the channel since the core is in
  71231. + * device mode.
  71232. + */
  71233. + /* In FIQ FSM mode, we need to shut down carefully.
  71234. + * The FIQ may attempt to restart a disabled channel */
  71235. + if (fiq_fsm_enable && (hcd->fiq_state->channel[n].fsm != FIQ_PASSTHROUGH)) {
  71236. + hcd->fiq_state->channel[n].fsm = FIQ_DEQUEUE_ISSUED;
  71237. + }
  71238. + dwc_otg_hc_halt(hcd->core_if, qh->channel,
  71239. + DWC_OTG_HC_XFER_URB_DEQUEUE);
  71240. +
  71241. + }
  71242. + }
  71243. +
  71244. + /*
  71245. + * Free the QTD and clean up the associated QH. Leave the QH in the
  71246. + * schedule if it has any remaining QTDs.
  71247. + */
  71248. +
  71249. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue - "
  71250. + "delete %sQueue handler\n",
  71251. + hcd->core_if->dma_desc_enable?"DMA ":"");
  71252. + if (!hcd->core_if->dma_desc_enable) {
  71253. + uint8_t b = urb_qtd->in_process;
  71254. + dwc_otg_hcd_qtd_remove_and_free(hcd, urb_qtd, qh);
  71255. + if (b) {
  71256. + dwc_otg_hcd_qh_deactivate(hcd, qh, 0);
  71257. + qh->channel = NULL;
  71258. + } else if (DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  71259. + dwc_otg_hcd_qh_remove(hcd, qh);
  71260. + }
  71261. + } else {
  71262. + dwc_otg_hcd_qtd_remove_and_free(hcd, urb_qtd, qh);
  71263. + }
  71264. + return 0;
  71265. +}
  71266. +
  71267. +int dwc_otg_hcd_endpoint_disable(dwc_otg_hcd_t * hcd, void *ep_handle,
  71268. + int retry)
  71269. +{
  71270. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  71271. + int retval = 0;
  71272. + dwc_irqflags_t flags;
  71273. +
  71274. + if (retry < 0) {
  71275. + retval = -DWC_E_INVALID;
  71276. + goto done;
  71277. + }
  71278. +
  71279. + if (!qh) {
  71280. + retval = -DWC_E_INVALID;
  71281. + goto done;
  71282. + }
  71283. +
  71284. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  71285. +
  71286. + while (!DWC_CIRCLEQ_EMPTY(&qh->qtd_list) && retry) {
  71287. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  71288. + retry--;
  71289. + dwc_msleep(5);
  71290. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  71291. + }
  71292. +
  71293. + dwc_otg_hcd_qh_remove(hcd, qh);
  71294. +
  71295. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  71296. + /*
  71297. + * Split dwc_otg_hcd_qh_remove_and_free() into qh_remove
  71298. + * and qh_free to prevent stack dump on DWC_DMA_FREE() with
  71299. + * irq_disabled (spinlock_irqsave) in dwc_otg_hcd_desc_list_free()
  71300. + * and dwc_otg_hcd_frame_list_alloc().
  71301. + */
  71302. + dwc_otg_hcd_qh_free(hcd, qh);
  71303. +
  71304. +done:
  71305. + return retval;
  71306. +}
  71307. +
  71308. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  71309. +int dwc_otg_hcd_endpoint_reset(dwc_otg_hcd_t * hcd, void *ep_handle)
  71310. +{
  71311. + int retval = 0;
  71312. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  71313. + if (!qh)
  71314. + return -DWC_E_INVALID;
  71315. +
  71316. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  71317. + return retval;
  71318. +}
  71319. +#endif
  71320. +
  71321. +/**
  71322. + * HCD Callback structure for handling mode switching.
  71323. + */
  71324. +static dwc_otg_cil_callbacks_t hcd_cil_callbacks = {
  71325. + .start = dwc_otg_hcd_start_cb,
  71326. + .stop = dwc_otg_hcd_stop_cb,
  71327. + .disconnect = dwc_otg_hcd_disconnect_cb,
  71328. + .session_start = dwc_otg_hcd_session_start_cb,
  71329. + .resume_wakeup = dwc_otg_hcd_rem_wakeup_cb,
  71330. +#ifdef CONFIG_USB_DWC_OTG_LPM
  71331. + .sleep = dwc_otg_hcd_sleep_cb,
  71332. +#endif
  71333. + .p = 0,
  71334. +};
  71335. +
  71336. +/**
  71337. + * Reset tasklet function
  71338. + */
  71339. +static void reset_tasklet_func(void *data)
  71340. +{
  71341. + dwc_otg_hcd_t *dwc_otg_hcd = (dwc_otg_hcd_t *) data;
  71342. + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
  71343. + hprt0_data_t hprt0;
  71344. +
  71345. + DWC_DEBUGPL(DBG_HCDV, "USB RESET tasklet called\n");
  71346. +
  71347. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  71348. + hprt0.b.prtrst = 1;
  71349. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  71350. + dwc_mdelay(60);
  71351. +
  71352. + hprt0.b.prtrst = 0;
  71353. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  71354. + dwc_otg_hcd->flags.b.port_reset_change = 1;
  71355. +}
  71356. +
  71357. +static void completion_tasklet_func(void *ptr)
  71358. +{
  71359. + dwc_otg_hcd_t *hcd = (dwc_otg_hcd_t *) ptr;
  71360. + struct urb *urb;
  71361. + urb_tq_entry_t *item;
  71362. + dwc_irqflags_t flags;
  71363. +
  71364. + /* This could just be spin_lock_irq */
  71365. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  71366. + while (!DWC_TAILQ_EMPTY(&hcd->completed_urb_list)) {
  71367. + item = DWC_TAILQ_FIRST(&hcd->completed_urb_list);
  71368. + urb = item->urb;
  71369. + DWC_TAILQ_REMOVE(&hcd->completed_urb_list, item,
  71370. + urb_tq_entries);
  71371. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  71372. + DWC_FREE(item);
  71373. +
  71374. + usb_hcd_giveback_urb(hcd->priv, urb, urb->status);
  71375. +
  71376. +
  71377. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  71378. + }
  71379. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  71380. + return;
  71381. +}
  71382. +
  71383. +static void qh_list_free(dwc_otg_hcd_t * hcd, dwc_list_link_t * qh_list)
  71384. +{
  71385. + dwc_list_link_t *item;
  71386. + dwc_otg_qh_t *qh;
  71387. + dwc_irqflags_t flags;
  71388. +
  71389. + if (!qh_list->next) {
  71390. + /* The list hasn't been initialized yet. */
  71391. + return;
  71392. + }
  71393. + /*
  71394. + * Hold spinlock here. Not needed in that case if bellow
  71395. + * function is being called from ISR
  71396. + */
  71397. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  71398. + /* Ensure there are no QTDs or URBs left. */
  71399. + kill_urbs_in_qh_list(hcd, qh_list);
  71400. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  71401. +
  71402. + DWC_LIST_FOREACH(item, qh_list) {
  71403. + qh = DWC_LIST_ENTRY(item, dwc_otg_qh_t, qh_list_entry);
  71404. + dwc_otg_hcd_qh_remove_and_free(hcd, qh);
  71405. + }
  71406. +}
  71407. +
  71408. +/**
  71409. + * Exit from Hibernation if Host did not detect SRP from connected SRP capable
  71410. + * Device during SRP time by host power up.
  71411. + */
  71412. +void dwc_otg_hcd_power_up(void *ptr)
  71413. +{
  71414. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  71415. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  71416. +
  71417. + DWC_PRINTF("%s called\n", __FUNCTION__);
  71418. +
  71419. + if (!core_if->hibernation_suspend) {
  71420. + DWC_PRINTF("Already exited from Hibernation\n");
  71421. + return;
  71422. + }
  71423. +
  71424. + /* Switch on the voltage to the core */
  71425. + gpwrdn.b.pwrdnswtch = 1;
  71426. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  71427. + dwc_udelay(10);
  71428. +
  71429. + /* Reset the core */
  71430. + gpwrdn.d32 = 0;
  71431. + gpwrdn.b.pwrdnrstn = 1;
  71432. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  71433. + dwc_udelay(10);
  71434. +
  71435. + /* Disable power clamps */
  71436. + gpwrdn.d32 = 0;
  71437. + gpwrdn.b.pwrdnclmp = 1;
  71438. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  71439. +
  71440. + /* Remove reset the core signal */
  71441. + gpwrdn.d32 = 0;
  71442. + gpwrdn.b.pwrdnrstn = 1;
  71443. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  71444. + dwc_udelay(10);
  71445. +
  71446. + /* Disable PMU interrupt */
  71447. + gpwrdn.d32 = 0;
  71448. + gpwrdn.b.pmuintsel = 1;
  71449. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  71450. +
  71451. + core_if->hibernation_suspend = 0;
  71452. +
  71453. + /* Disable PMU */
  71454. + gpwrdn.d32 = 0;
  71455. + gpwrdn.b.pmuactv = 1;
  71456. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  71457. + dwc_udelay(10);
  71458. +
  71459. + /* Enable VBUS */
  71460. + gpwrdn.d32 = 0;
  71461. + gpwrdn.b.dis_vbus = 1;
  71462. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  71463. +
  71464. + core_if->op_state = A_HOST;
  71465. + dwc_otg_core_init(core_if);
  71466. + dwc_otg_enable_global_interrupts(core_if);
  71467. + cil_hcd_start(core_if);
  71468. +}
  71469. +
  71470. +void dwc_otg_cleanup_fiq_channel(dwc_otg_hcd_t *hcd, uint32_t num)
  71471. +{
  71472. + struct fiq_channel_state *st = &hcd->fiq_state->channel[num];
  71473. + struct fiq_dma_blob *blob = hcd->fiq_dmab;
  71474. + int i;
  71475. +
  71476. + st->fsm = FIQ_PASSTHROUGH;
  71477. + st->hcchar_copy.d32 = 0;
  71478. + st->hcsplt_copy.d32 = 0;
  71479. + st->hcint_copy.d32 = 0;
  71480. + st->hcintmsk_copy.d32 = 0;
  71481. + st->hctsiz_copy.d32 = 0;
  71482. + st->hcdma_copy.d32 = 0;
  71483. + st->nr_errors = 0;
  71484. + st->hub_addr = 0;
  71485. + st->port_addr = 0;
  71486. + st->expected_uframe = 0;
  71487. + st->nrpackets = 0;
  71488. + st->dma_info.index = 0;
  71489. + for (i = 0; i < 6; i++)
  71490. + st->dma_info.slot_len[i] = 255;
  71491. + st->hs_isoc_info.index = 0;
  71492. + st->hs_isoc_info.iso_desc = NULL;
  71493. + st->hs_isoc_info.nrframes = 0;
  71494. +
  71495. + DWC_MEMSET(&blob->channel[num].index[0], 0x6b, 1128);
  71496. +}
  71497. +
  71498. +/**
  71499. + * Frees secondary storage associated with the dwc_otg_hcd structure contained
  71500. + * in the struct usb_hcd field.
  71501. + */
  71502. +static void dwc_otg_hcd_free(dwc_otg_hcd_t * dwc_otg_hcd)
  71503. +{
  71504. + int i;
  71505. +
  71506. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD FREE\n");
  71507. +
  71508. + del_timers(dwc_otg_hcd);
  71509. +
  71510. + /* Free memory for QH/QTD lists */
  71511. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_inactive);
  71512. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_active);
  71513. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_inactive);
  71514. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_ready);
  71515. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_assigned);
  71516. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_queued);
  71517. +
  71518. + /* Free memory for the host channels. */
  71519. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  71520. + dwc_hc_t *hc = dwc_otg_hcd->hc_ptr_array[i];
  71521. +
  71522. +#ifdef DEBUG
  71523. + if (dwc_otg_hcd->core_if->hc_xfer_timer[i]) {
  71524. + DWC_TIMER_FREE(dwc_otg_hcd->core_if->hc_xfer_timer[i]);
  71525. + }
  71526. +#endif
  71527. + if (hc != NULL) {
  71528. + DWC_DEBUGPL(DBG_HCDV, "HCD Free channel #%i, hc=%p\n",
  71529. + i, hc);
  71530. + DWC_FREE(hc);
  71531. + }
  71532. + }
  71533. +
  71534. + if (dwc_otg_hcd->core_if->dma_enable) {
  71535. + if (dwc_otg_hcd->status_buf_dma) {
  71536. + DWC_DMA_FREE(DWC_OTG_HCD_STATUS_BUF_SIZE,
  71537. + dwc_otg_hcd->status_buf,
  71538. + dwc_otg_hcd->status_buf_dma);
  71539. + }
  71540. + } else if (dwc_otg_hcd->status_buf != NULL) {
  71541. + DWC_FREE(dwc_otg_hcd->status_buf);
  71542. + }
  71543. + DWC_SPINLOCK_FREE(dwc_otg_hcd->channel_lock);
  71544. + DWC_SPINLOCK_FREE(dwc_otg_hcd->lock);
  71545. + /* Set core_if's lock pointer to NULL */
  71546. + dwc_otg_hcd->core_if->lock = NULL;
  71547. +
  71548. + DWC_TIMER_FREE(dwc_otg_hcd->conn_timer);
  71549. + DWC_TASK_FREE(dwc_otg_hcd->reset_tasklet);
  71550. + DWC_TASK_FREE(dwc_otg_hcd->completion_tasklet);
  71551. + DWC_FREE(dwc_otg_hcd->fiq_state);
  71552. +
  71553. +#ifdef DWC_DEV_SRPCAP
  71554. + if (dwc_otg_hcd->core_if->power_down == 2 &&
  71555. + dwc_otg_hcd->core_if->pwron_timer) {
  71556. + DWC_TIMER_FREE(dwc_otg_hcd->core_if->pwron_timer);
  71557. + }
  71558. +#endif
  71559. + DWC_FREE(dwc_otg_hcd);
  71560. +}
  71561. +
  71562. +int init_hcd_usecs(dwc_otg_hcd_t *_hcd);
  71563. +
  71564. +int dwc_otg_hcd_init(dwc_otg_hcd_t * hcd, dwc_otg_core_if_t * core_if)
  71565. +{
  71566. + int retval = 0;
  71567. + int num_channels;
  71568. + int i;
  71569. + dwc_hc_t *channel;
  71570. +
  71571. + hcd->lock = DWC_SPINLOCK_ALLOC();
  71572. + hcd->channel_lock = DWC_SPINLOCK_ALLOC();
  71573. + DWC_DEBUGPL(DBG_HCDV, "init of HCD %p given core_if %p\n",
  71574. + hcd, core_if);
  71575. + if (!hcd->lock) {
  71576. + DWC_ERROR("Could not allocate lock for pcd");
  71577. + DWC_FREE(hcd);
  71578. + retval = -DWC_E_NO_MEMORY;
  71579. + goto out;
  71580. + }
  71581. + hcd->core_if = core_if;
  71582. +
  71583. + /* Register the HCD CIL Callbacks */
  71584. + dwc_otg_cil_register_hcd_callbacks(hcd->core_if,
  71585. + &hcd_cil_callbacks, hcd);
  71586. +
  71587. + /* Initialize the non-periodic schedule. */
  71588. + DWC_LIST_INIT(&hcd->non_periodic_sched_inactive);
  71589. + DWC_LIST_INIT(&hcd->non_periodic_sched_active);
  71590. +
  71591. + /* Initialize the periodic schedule. */
  71592. + DWC_LIST_INIT(&hcd->periodic_sched_inactive);
  71593. + DWC_LIST_INIT(&hcd->periodic_sched_ready);
  71594. + DWC_LIST_INIT(&hcd->periodic_sched_assigned);
  71595. + DWC_LIST_INIT(&hcd->periodic_sched_queued);
  71596. + DWC_TAILQ_INIT(&hcd->completed_urb_list);
  71597. + /*
  71598. + * Create a host channel descriptor for each host channel implemented
  71599. + * in the controller. Initialize the channel descriptor array.
  71600. + */
  71601. + DWC_CIRCLEQ_INIT(&hcd->free_hc_list);
  71602. + num_channels = hcd->core_if->core_params->host_channels;
  71603. + DWC_MEMSET(hcd->hc_ptr_array, 0, sizeof(hcd->hc_ptr_array));
  71604. + for (i = 0; i < num_channels; i++) {
  71605. + channel = DWC_ALLOC(sizeof(dwc_hc_t));
  71606. + if (channel == NULL) {
  71607. + retval = -DWC_E_NO_MEMORY;
  71608. + DWC_ERROR("%s: host channel allocation failed\n",
  71609. + __func__);
  71610. + dwc_otg_hcd_free(hcd);
  71611. + goto out;
  71612. + }
  71613. + channel->hc_num = i;
  71614. + hcd->hc_ptr_array[i] = channel;
  71615. +#ifdef DEBUG
  71616. + hcd->core_if->hc_xfer_timer[i] =
  71617. + DWC_TIMER_ALLOC("hc timer", hc_xfer_timeout,
  71618. + &hcd->core_if->hc_xfer_info[i]);
  71619. +#endif
  71620. + DWC_DEBUGPL(DBG_HCDV, "HCD Added channel #%d, hc=%p\n", i,
  71621. + channel);
  71622. + }
  71623. +
  71624. + if (fiq_enable) {
  71625. + hcd->fiq_state = DWC_ALLOC(sizeof(struct fiq_state) + (sizeof(struct fiq_channel_state) * num_channels));
  71626. + if (!hcd->fiq_state) {
  71627. + retval = -DWC_E_NO_MEMORY;
  71628. + DWC_ERROR("%s: cannot allocate fiq_state structure\n", __func__);
  71629. + dwc_otg_hcd_free(hcd);
  71630. + goto out;
  71631. + }
  71632. + DWC_MEMSET(hcd->fiq_state, 0, (sizeof(struct fiq_state) + (sizeof(struct fiq_channel_state) * num_channels)));
  71633. +
  71634. + for (i = 0; i < num_channels; i++) {
  71635. + hcd->fiq_state->channel[i].fsm = FIQ_PASSTHROUGH;
  71636. + }
  71637. + hcd->fiq_state->dummy_send = DWC_ALLOC_ATOMIC(16);
  71638. +
  71639. + hcd->fiq_stack = DWC_ALLOC(sizeof(struct fiq_stack));
  71640. + if (!hcd->fiq_stack) {
  71641. + retval = -DWC_E_NO_MEMORY;
  71642. + DWC_ERROR("%s: cannot allocate fiq_stack structure\n", __func__);
  71643. + dwc_otg_hcd_free(hcd);
  71644. + goto out;
  71645. + }
  71646. + hcd->fiq_stack->magic1 = 0xDEADBEEF;
  71647. + hcd->fiq_stack->magic2 = 0xD00DFEED;
  71648. + hcd->fiq_state->gintmsk_saved.d32 = ~0;
  71649. + hcd->fiq_state->haintmsk_saved.b2.chint = ~0;
  71650. +
  71651. + /* This bit is terrible and uses no API, but necessary. The FIQ has no concept of DMA pools
  71652. + * (and if it did, would be a lot slower). This allocates a chunk of memory (~9kiB for 8 host channels)
  71653. + * for use as transaction bounce buffers in a 2-D array. Our access into this chunk is done by some
  71654. + * moderately readable array casts.
  71655. + */
  71656. + hcd->fiq_dmab = DWC_DMA_ALLOC((sizeof(struct fiq_dma_channel) * num_channels), &hcd->fiq_state->dma_base);
  71657. + DWC_WARN("FIQ DMA bounce buffers: virt = 0x%08x dma = 0x%08x len=%d",
  71658. + (unsigned int)hcd->fiq_dmab, (unsigned int)hcd->fiq_state->dma_base,
  71659. + sizeof(struct fiq_dma_channel) * num_channels);
  71660. +
  71661. + DWC_MEMSET(hcd->fiq_dmab, 0x6b, 9024);
  71662. +
  71663. + /* pointer for debug in fiq_print */
  71664. + hcd->fiq_state->fiq_dmab = hcd->fiq_dmab;
  71665. + if (fiq_fsm_enable) {
  71666. + int i;
  71667. + for (i=0; i < hcd->core_if->core_params->host_channels; i++) {
  71668. + dwc_otg_cleanup_fiq_channel(hcd, i);
  71669. + }
  71670. + DWC_PRINTF("FIQ FSM acceleration enabled for :\n%s%s%s",
  71671. + (fiq_fsm_mask & 0x1) ? "Non-periodic Split Transactions\n" : "",
  71672. + (fiq_fsm_mask & 0x2) ? "Periodic Split Transactions\n" : "",
  71673. + (fiq_fsm_mask & 0x4) ? "High-Speed Isochronous Endpoints\n" : "");
  71674. + }
  71675. + }
  71676. +
  71677. + /* Initialize the Connection timeout timer. */
  71678. + hcd->conn_timer = DWC_TIMER_ALLOC("Connection timer",
  71679. + dwc_otg_hcd_connect_timeout, 0);
  71680. +
  71681. + printk(KERN_DEBUG "dwc_otg: Microframe scheduler %s\n", microframe_schedule ? "enabled":"disabled");
  71682. + if (microframe_schedule)
  71683. + init_hcd_usecs(hcd);
  71684. +
  71685. + /* Initialize reset tasklet. */
  71686. + hcd->reset_tasklet = DWC_TASK_ALLOC("reset_tasklet", reset_tasklet_func, hcd);
  71687. +
  71688. + hcd->completion_tasklet = DWC_TASK_ALLOC("completion_tasklet",
  71689. + completion_tasklet_func, hcd);
  71690. +#ifdef DWC_DEV_SRPCAP
  71691. + if (hcd->core_if->power_down == 2) {
  71692. + /* Initialize Power on timer for Host power up in case hibernation */
  71693. + hcd->core_if->pwron_timer = DWC_TIMER_ALLOC("PWRON TIMER",
  71694. + dwc_otg_hcd_power_up, core_if);
  71695. + }
  71696. +#endif
  71697. +
  71698. + /*
  71699. + * Allocate space for storing data on status transactions. Normally no
  71700. + * data is sent, but this space acts as a bit bucket. This must be
  71701. + * done after usb_add_hcd since that function allocates the DMA buffer
  71702. + * pool.
  71703. + */
  71704. + if (hcd->core_if->dma_enable) {
  71705. + hcd->status_buf =
  71706. + DWC_DMA_ALLOC(DWC_OTG_HCD_STATUS_BUF_SIZE,
  71707. + &hcd->status_buf_dma);
  71708. + } else {
  71709. + hcd->status_buf = DWC_ALLOC(DWC_OTG_HCD_STATUS_BUF_SIZE);
  71710. + }
  71711. + if (!hcd->status_buf) {
  71712. + retval = -DWC_E_NO_MEMORY;
  71713. + DWC_ERROR("%s: status_buf allocation failed\n", __func__);
  71714. + dwc_otg_hcd_free(hcd);
  71715. + goto out;
  71716. + }
  71717. +
  71718. + hcd->otg_port = 1;
  71719. + hcd->frame_list = NULL;
  71720. + hcd->frame_list_dma = 0;
  71721. + hcd->periodic_qh_count = 0;
  71722. +
  71723. + DWC_MEMSET(hcd->hub_port, 0, sizeof(hcd->hub_port));
  71724. +#ifdef FIQ_DEBUG
  71725. + DWC_MEMSET(hcd->hub_port_alloc, -1, sizeof(hcd->hub_port_alloc));
  71726. +#endif
  71727. +
  71728. +out:
  71729. + return retval;
  71730. +}
  71731. +
  71732. +void dwc_otg_hcd_remove(dwc_otg_hcd_t * hcd)
  71733. +{
  71734. + /* Turn off all host-specific interrupts. */
  71735. + dwc_otg_disable_host_interrupts(hcd->core_if);
  71736. +
  71737. + dwc_otg_hcd_free(hcd);
  71738. +}
  71739. +
  71740. +/**
  71741. + * Initializes dynamic portions of the DWC_otg HCD state.
  71742. + */
  71743. +static void dwc_otg_hcd_reinit(dwc_otg_hcd_t * hcd)
  71744. +{
  71745. + int num_channels;
  71746. + int i;
  71747. + dwc_hc_t *channel;
  71748. + dwc_hc_t *channel_tmp;
  71749. +
  71750. + hcd->flags.d32 = 0;
  71751. +
  71752. + hcd->non_periodic_qh_ptr = &hcd->non_periodic_sched_active;
  71753. + if (!microframe_schedule) {
  71754. + hcd->non_periodic_channels = 0;
  71755. + hcd->periodic_channels = 0;
  71756. + } else {
  71757. + hcd->available_host_channels = hcd->core_if->core_params->host_channels;
  71758. + }
  71759. + /*
  71760. + * Put all channels in the free channel list and clean up channel
  71761. + * states.
  71762. + */
  71763. + DWC_CIRCLEQ_FOREACH_SAFE(channel, channel_tmp,
  71764. + &hcd->free_hc_list, hc_list_entry) {
  71765. + DWC_CIRCLEQ_REMOVE(&hcd->free_hc_list, channel, hc_list_entry);
  71766. + }
  71767. +
  71768. + num_channels = hcd->core_if->core_params->host_channels;
  71769. + for (i = 0; i < num_channels; i++) {
  71770. + channel = hcd->hc_ptr_array[i];
  71771. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, channel,
  71772. + hc_list_entry);
  71773. + dwc_otg_hc_cleanup(hcd->core_if, channel);
  71774. + }
  71775. +
  71776. + /* Initialize the DWC core for host mode operation. */
  71777. + dwc_otg_core_host_init(hcd->core_if);
  71778. +
  71779. + /* Set core_if's lock pointer to the hcd->lock */
  71780. + hcd->core_if->lock = hcd->lock;
  71781. +}
  71782. +
  71783. +/**
  71784. + * Assigns transactions from a QTD to a free host channel and initializes the
  71785. + * host channel to perform the transactions. The host channel is removed from
  71786. + * the free list.
  71787. + *
  71788. + * @param hcd The HCD state structure.
  71789. + * @param qh Transactions from the first QTD for this QH are selected and
  71790. + * assigned to a free host channel.
  71791. + */
  71792. +static void assign_and_init_hc(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  71793. +{
  71794. + dwc_hc_t *hc;
  71795. + dwc_otg_qtd_t *qtd;
  71796. + dwc_otg_hcd_urb_t *urb;
  71797. + void* ptr = NULL;
  71798. +
  71799. + qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  71800. +
  71801. + urb = qtd->urb;
  71802. +
  71803. + DWC_DEBUGPL(DBG_HCDV, "%s(%p,%p) - urb %x, actual_length %d\n", __func__, hcd, qh, (unsigned int)urb, urb->actual_length);
  71804. +
  71805. + if (((urb->actual_length < 0) || (urb->actual_length > urb->length)) && !dwc_otg_hcd_is_pipe_in(&urb->pipe_info))
  71806. + urb->actual_length = urb->length;
  71807. +
  71808. +
  71809. + hc = DWC_CIRCLEQ_FIRST(&hcd->free_hc_list);
  71810. +
  71811. + /* Remove the host channel from the free list. */
  71812. + DWC_CIRCLEQ_REMOVE_INIT(&hcd->free_hc_list, hc, hc_list_entry);
  71813. +
  71814. + qh->channel = hc;
  71815. +
  71816. + qtd->in_process = 1;
  71817. +
  71818. + /*
  71819. + * Use usb_pipedevice to determine device address. This address is
  71820. + * 0 before the SET_ADDRESS command and the correct address afterward.
  71821. + */
  71822. + hc->dev_addr = dwc_otg_hcd_get_dev_addr(&urb->pipe_info);
  71823. + hc->ep_num = dwc_otg_hcd_get_ep_num(&urb->pipe_info);
  71824. + hc->speed = qh->dev_speed;
  71825. + hc->max_packet = dwc_max_packet(qh->maxp);
  71826. +
  71827. + hc->xfer_started = 0;
  71828. + hc->halt_status = DWC_OTG_HC_XFER_NO_HALT_STATUS;
  71829. + hc->error_state = (qtd->error_count > 0);
  71830. + hc->halt_on_queue = 0;
  71831. + hc->halt_pending = 0;
  71832. + hc->requests = 0;
  71833. +
  71834. + /*
  71835. + * The following values may be modified in the transfer type section
  71836. + * below. The xfer_len value may be reduced when the transfer is
  71837. + * started to accommodate the max widths of the XferSize and PktCnt
  71838. + * fields in the HCTSIZn register.
  71839. + */
  71840. +
  71841. + hc->ep_is_in = (dwc_otg_hcd_is_pipe_in(&urb->pipe_info) != 0);
  71842. + if (hc->ep_is_in) {
  71843. + hc->do_ping = 0;
  71844. + } else {
  71845. + hc->do_ping = qh->ping_state;
  71846. + }
  71847. +
  71848. + hc->data_pid_start = qh->data_toggle;
  71849. + hc->multi_count = 1;
  71850. +
  71851. + if (hcd->core_if->dma_enable) {
  71852. + hc->xfer_buff = (uint8_t *) urb->dma + urb->actual_length;
  71853. +
  71854. + /* For non-dword aligned case */
  71855. + if (((unsigned long)hc->xfer_buff & 0x3)
  71856. + && !hcd->core_if->dma_desc_enable) {
  71857. + ptr = (uint8_t *) urb->buf + urb->actual_length;
  71858. + }
  71859. + } else {
  71860. + hc->xfer_buff = (uint8_t *) urb->buf + urb->actual_length;
  71861. + }
  71862. + hc->xfer_len = urb->length - urb->actual_length;
  71863. + hc->xfer_count = 0;
  71864. +
  71865. + /*
  71866. + * Set the split attributes
  71867. + */
  71868. + hc->do_split = 0;
  71869. + if (qh->do_split) {
  71870. + uint32_t hub_addr, port_addr;
  71871. + hc->do_split = 1;
  71872. + hc->xact_pos = qtd->isoc_split_pos;
  71873. + /* We don't need to do complete splits anymore */
  71874. +// if(fiq_fsm_enable)
  71875. + if (0)
  71876. + hc->complete_split = qtd->complete_split = 0;
  71877. + else
  71878. + hc->complete_split = qtd->complete_split;
  71879. +
  71880. + hcd->fops->hub_info(hcd, urb->priv, &hub_addr, &port_addr);
  71881. + hc->hub_addr = (uint8_t) hub_addr;
  71882. + hc->port_addr = (uint8_t) port_addr;
  71883. + }
  71884. +
  71885. + switch (dwc_otg_hcd_get_pipe_type(&urb->pipe_info)) {
  71886. + case UE_CONTROL:
  71887. + hc->ep_type = DWC_OTG_EP_TYPE_CONTROL;
  71888. + switch (qtd->control_phase) {
  71889. + case DWC_OTG_CONTROL_SETUP:
  71890. + DWC_DEBUGPL(DBG_HCDV, " Control setup transaction\n");
  71891. + hc->do_ping = 0;
  71892. + hc->ep_is_in = 0;
  71893. + hc->data_pid_start = DWC_OTG_HC_PID_SETUP;
  71894. + if (hcd->core_if->dma_enable) {
  71895. + hc->xfer_buff = (uint8_t *) urb->setup_dma;
  71896. + } else {
  71897. + hc->xfer_buff = (uint8_t *) urb->setup_packet;
  71898. + }
  71899. + hc->xfer_len = 8;
  71900. + ptr = NULL;
  71901. + break;
  71902. + case DWC_OTG_CONTROL_DATA:
  71903. + DWC_DEBUGPL(DBG_HCDV, " Control data transaction\n");
  71904. + hc->data_pid_start = qtd->data_toggle;
  71905. + break;
  71906. + case DWC_OTG_CONTROL_STATUS:
  71907. + /*
  71908. + * Direction is opposite of data direction or IN if no
  71909. + * data.
  71910. + */
  71911. + DWC_DEBUGPL(DBG_HCDV, " Control status transaction\n");
  71912. + if (urb->length == 0) {
  71913. + hc->ep_is_in = 1;
  71914. + } else {
  71915. + hc->ep_is_in =
  71916. + dwc_otg_hcd_is_pipe_out(&urb->pipe_info);
  71917. + }
  71918. + if (hc->ep_is_in) {
  71919. + hc->do_ping = 0;
  71920. + }
  71921. +
  71922. + hc->data_pid_start = DWC_OTG_HC_PID_DATA1;
  71923. +
  71924. + hc->xfer_len = 0;
  71925. + if (hcd->core_if->dma_enable) {
  71926. + hc->xfer_buff = (uint8_t *) hcd->status_buf_dma;
  71927. + } else {
  71928. + hc->xfer_buff = (uint8_t *) hcd->status_buf;
  71929. + }
  71930. + ptr = NULL;
  71931. + break;
  71932. + }
  71933. + break;
  71934. + case UE_BULK:
  71935. + hc->ep_type = DWC_OTG_EP_TYPE_BULK;
  71936. + break;
  71937. + case UE_INTERRUPT:
  71938. + hc->ep_type = DWC_OTG_EP_TYPE_INTR;
  71939. + break;
  71940. + case UE_ISOCHRONOUS:
  71941. + {
  71942. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  71943. +
  71944. + hc->ep_type = DWC_OTG_EP_TYPE_ISOC;
  71945. +
  71946. + if (hcd->core_if->dma_desc_enable)
  71947. + break;
  71948. +
  71949. + frame_desc = &urb->iso_descs[qtd->isoc_frame_index];
  71950. +
  71951. + frame_desc->status = 0;
  71952. +
  71953. + if (hcd->core_if->dma_enable) {
  71954. + hc->xfer_buff = (uint8_t *) urb->dma;
  71955. + } else {
  71956. + hc->xfer_buff = (uint8_t *) urb->buf;
  71957. + }
  71958. + hc->xfer_buff +=
  71959. + frame_desc->offset + qtd->isoc_split_offset;
  71960. + hc->xfer_len =
  71961. + frame_desc->length - qtd->isoc_split_offset;
  71962. +
  71963. + /* For non-dword aligned buffers */
  71964. + if (((unsigned long)hc->xfer_buff & 0x3)
  71965. + && hcd->core_if->dma_enable) {
  71966. + ptr =
  71967. + (uint8_t *) urb->buf + frame_desc->offset +
  71968. + qtd->isoc_split_offset;
  71969. + } else
  71970. + ptr = NULL;
  71971. +
  71972. + if (hc->xact_pos == DWC_HCSPLIT_XACTPOS_ALL) {
  71973. + if (hc->xfer_len <= 188) {
  71974. + hc->xact_pos = DWC_HCSPLIT_XACTPOS_ALL;
  71975. + } else {
  71976. + hc->xact_pos =
  71977. + DWC_HCSPLIT_XACTPOS_BEGIN;
  71978. + }
  71979. + }
  71980. + }
  71981. + break;
  71982. + }
  71983. + /* non DWORD-aligned buffer case */
  71984. + if (ptr) {
  71985. + uint32_t buf_size;
  71986. + if (hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
  71987. + buf_size = hcd->core_if->core_params->max_transfer_size;
  71988. + } else {
  71989. + buf_size = 4096;
  71990. + }
  71991. + if (!qh->dw_align_buf) {
  71992. + qh->dw_align_buf = DWC_DMA_ALLOC_ATOMIC(buf_size,
  71993. + &qh->dw_align_buf_dma);
  71994. + if (!qh->dw_align_buf) {
  71995. + DWC_ERROR
  71996. + ("%s: Failed to allocate memory to handle "
  71997. + "non-dword aligned buffer case\n",
  71998. + __func__);
  71999. + return;
  72000. + }
  72001. + }
  72002. + if (!hc->ep_is_in) {
  72003. + dwc_memcpy(qh->dw_align_buf, ptr, hc->xfer_len);
  72004. + }
  72005. + hc->align_buff = qh->dw_align_buf_dma;
  72006. + } else {
  72007. + hc->align_buff = 0;
  72008. + }
  72009. +
  72010. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  72011. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  72012. + /*
  72013. + * This value may be modified when the transfer is started to
  72014. + * reflect the actual transfer length.
  72015. + */
  72016. + hc->multi_count = dwc_hb_mult(qh->maxp);
  72017. + }
  72018. +
  72019. + if (hcd->core_if->dma_desc_enable)
  72020. + hc->desc_list_addr = qh->desc_list_dma;
  72021. +
  72022. + dwc_otg_hc_init(hcd->core_if, hc);
  72023. + hc->qh = qh;
  72024. +}
  72025. +
  72026. +
  72027. +/**
  72028. + * fiq_fsm_transaction_suitable() - Test a QH for compatibility with the FIQ
  72029. + * @qh: pointer to the endpoint's queue head
  72030. + *
  72031. + * Transaction start/end control flow is grafted onto the existing dwc_otg
  72032. + * mechanisms, to avoid spaghettifying the functions more than they already are.
  72033. + * This function's eligibility check is altered by debug parameter.
  72034. + *
  72035. + * Returns: 0 for unsuitable, 1 implies the FIQ can be enabled for this transaction.
  72036. + */
  72037. +
  72038. +int fiq_fsm_transaction_suitable(dwc_otg_qh_t *qh)
  72039. +{
  72040. + if (qh->do_split) {
  72041. + switch (qh->ep_type) {
  72042. + case UE_CONTROL:
  72043. + case UE_BULK:
  72044. + if (fiq_fsm_mask & (1 << 0))
  72045. + return 1;
  72046. + break;
  72047. + case UE_INTERRUPT:
  72048. + case UE_ISOCHRONOUS:
  72049. + if (fiq_fsm_mask & (1 << 1))
  72050. + return 1;
  72051. + break;
  72052. + default:
  72053. + break;
  72054. + }
  72055. + } else if (qh->ep_type == UE_ISOCHRONOUS) {
  72056. + if (fiq_fsm_mask & (1 << 2)) {
  72057. + /* HS ISOCH support. We test for compatibility:
  72058. + * - DWORD aligned buffers
  72059. + * - Must be at least 2 transfers (otherwise pointless to use the FIQ)
  72060. + * If yes, then the fsm enqueue function will handle the state machine setup.
  72061. + */
  72062. + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  72063. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  72064. + struct dwc_otg_hcd_iso_packet_desc (*iso_descs)[0] = &urb->iso_descs;
  72065. + int nr_iso_frames = urb->packet_count;
  72066. + int i;
  72067. + uint32_t ptr;
  72068. +
  72069. + if (nr_iso_frames < 2)
  72070. + return 0;
  72071. + for (i = 0; i < nr_iso_frames; i++) {
  72072. + ptr = urb->dma + iso_descs[i]->offset;
  72073. + if (ptr & 0x3) {
  72074. + printk_ratelimited("%s: Non-Dword aligned isochronous frame offset."
  72075. + " Cannot queue FIQ-accelerated transfer to device %d endpoint %d\n",
  72076. + __FUNCTION__, qh->channel->dev_addr, qh->channel->ep_num);
  72077. + return 0;
  72078. + }
  72079. + }
  72080. + return 1;
  72081. + }
  72082. + }
  72083. + return 0;
  72084. +}
  72085. +
  72086. +/**
  72087. + * fiq_fsm_setup_periodic_dma() - Set up DMA bounce buffers
  72088. + * @hcd: Pointer to the dwc_otg_hcd struct
  72089. + * @qh: Pointer to the endpoint's queue head
  72090. + *
  72091. + * Periodic split transactions are transmitted modulo 188 bytes.
  72092. + * This necessitates slicing data up into buckets for isochronous out
  72093. + * and fixing up the DMA address for all IN transfers.
  72094. + *
  72095. + * Returns 1 if the DMA bounce buffers have been used, 0 if the default
  72096. + * HC buffer has been used.
  72097. + */
  72098. +int fiq_fsm_setup_periodic_dma(dwc_otg_hcd_t *hcd, struct fiq_channel_state *st, dwc_otg_qh_t *qh)
  72099. + {
  72100. + int frame_length, i = 0;
  72101. + uint8_t *ptr = NULL;
  72102. + dwc_hc_t *hc = qh->channel;
  72103. + struct fiq_dma_blob *blob;
  72104. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  72105. +
  72106. + for (i = 0; i < 6; i++) {
  72107. + st->dma_info.slot_len[i] = 255;
  72108. + }
  72109. + st->dma_info.index = 0;
  72110. + i = 0;
  72111. + if (hc->ep_is_in) {
  72112. + /*
  72113. + * Set dma_regs to bounce buffer. FIQ will update the
  72114. + * state depending on transaction progress.
  72115. + */
  72116. + blob = (struct fiq_dma_blob *) hcd->fiq_state->dma_base;
  72117. + st->hcdma_copy.d32 = (uint32_t) &blob->channel[hc->hc_num].index[0].buf[0];
  72118. + /* Calculate the max number of CSPLITS such that the FIQ can time out
  72119. + * a transaction if it fails.
  72120. + */
  72121. + frame_length = st->hcchar_copy.b.mps;
  72122. + do {
  72123. + i++;
  72124. + frame_length -= 188;
  72125. + } while (frame_length >= 0);
  72126. + st->nrpackets = i;
  72127. + return 1;
  72128. + } else {
  72129. + if (qh->ep_type == UE_ISOCHRONOUS) {
  72130. +
  72131. + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  72132. +
  72133. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  72134. + frame_length = frame_desc->length;
  72135. +
  72136. + /* Virtual address for bounce buffers */
  72137. + blob = hcd->fiq_dmab;
  72138. +
  72139. + ptr = qtd->urb->buf + frame_desc->offset;
  72140. + if (frame_length == 0) {
  72141. + /*
  72142. + * for isochronous transactions, we must still transmit a packet
  72143. + * even if the length is zero.
  72144. + */
  72145. + st->dma_info.slot_len[0] = 0;
  72146. + st->nrpackets = 1;
  72147. + } else {
  72148. + do {
  72149. + if (frame_length <= 188) {
  72150. + dwc_memcpy(&blob->channel[hc->hc_num].index[i].buf[0], ptr, frame_length);
  72151. + st->dma_info.slot_len[i] = frame_length;
  72152. + ptr += frame_length;
  72153. + } else {
  72154. + dwc_memcpy(&blob->channel[hc->hc_num].index[i].buf[0], ptr, 188);
  72155. + st->dma_info.slot_len[i] = 188;
  72156. + ptr += 188;
  72157. + }
  72158. + i++;
  72159. + frame_length -= 188;
  72160. + } while (frame_length > 0);
  72161. + st->nrpackets = i;
  72162. + }
  72163. + ptr = qtd->urb->buf + frame_desc->offset;
  72164. + /* Point the HC at the DMA address of the bounce buffers */
  72165. + blob = (struct fiq_dma_blob *) hcd->fiq_state->dma_base;
  72166. + st->hcdma_copy.d32 = (uint32_t) &blob->channel[hc->hc_num].index[0].buf[0];
  72167. +
  72168. + /* fixup xfersize to the actual packet size */
  72169. + st->hctsiz_copy.b.pid = 0;
  72170. + st->hctsiz_copy.b.xfersize = st->dma_info.slot_len[0];
  72171. + return 1;
  72172. + } else {
  72173. + /* For interrupt, single OUT packet required, goes in the SSPLIT from hc_buff. */
  72174. + return 0;
  72175. + }
  72176. + }
  72177. +}
  72178. +
  72179. +/*
  72180. + * Pushing a periodic request into the queue near the EOF1 point
  72181. + * in a microframe causes erroneous behaviour (frmovrun) interrupt.
  72182. + * Usually, the request goes out on the bus causing a transfer but
  72183. + * the core does not transfer the data to memory.
  72184. + * This guard interval (in number of 60MHz clocks) is required which
  72185. + * must cater for CPU latency between reading the value and enabling
  72186. + * the channel.
  72187. + */
  72188. +#define PERIODIC_FRREM_BACKOFF 1000
  72189. +
  72190. +int fiq_fsm_queue_isoc_transaction(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh)
  72191. +{
  72192. + dwc_hc_t *hc = qh->channel;
  72193. + dwc_otg_hc_regs_t *hc_regs = hcd->core_if->host_if->hc_regs[hc->hc_num];
  72194. + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  72195. + int frame;
  72196. + struct fiq_channel_state *st = &hcd->fiq_state->channel[hc->hc_num];
  72197. + int xfer_len, nrpackets;
  72198. + hcdma_data_t hcdma;
  72199. + hfnum_data_t hfnum;
  72200. +
  72201. + if (st->fsm != FIQ_PASSTHROUGH)
  72202. + return 0;
  72203. +
  72204. + st->nr_errors = 0;
  72205. +
  72206. + st->hcchar_copy.d32 = 0;
  72207. + st->hcchar_copy.b.mps = hc->max_packet;
  72208. + st->hcchar_copy.b.epdir = hc->ep_is_in;
  72209. + st->hcchar_copy.b.devaddr = hc->dev_addr;
  72210. + st->hcchar_copy.b.epnum = hc->ep_num;
  72211. + st->hcchar_copy.b.eptype = hc->ep_type;
  72212. +
  72213. + st->hcintmsk_copy.b.chhltd = 1;
  72214. +
  72215. + frame = dwc_otg_hcd_get_frame_number(hcd);
  72216. + st->hcchar_copy.b.oddfrm = (frame & 0x1) ? 0 : 1;
  72217. +
  72218. + st->hcchar_copy.b.lspddev = 0;
  72219. + /* Enable the channel later as a final register write. */
  72220. +
  72221. + st->hcsplt_copy.d32 = 0;
  72222. +
  72223. + st->hs_isoc_info.iso_desc = (struct dwc_otg_hcd_iso_packet_desc *) &qtd->urb->iso_descs;
  72224. + st->hs_isoc_info.nrframes = qtd->urb->packet_count;
  72225. + /* grab the next DMA address offset from the array */
  72226. + st->hcdma_copy.d32 = qtd->urb->dma;
  72227. + hcdma.d32 = st->hcdma_copy.d32 + st->hs_isoc_info.iso_desc[0].offset;
  72228. +
  72229. + /* We need to set multi_count. This is a bit tricky - has to be set per-transaction as
  72230. + * the core needs to be told to send the correct number. Caution: for IN transfers,
  72231. + * this is always set to the maximum size of the endpoint. */
  72232. + xfer_len = st->hs_isoc_info.iso_desc[0].length;
  72233. + nrpackets = (xfer_len + st->hcchar_copy.b.mps - 1) / st->hcchar_copy.b.mps;
  72234. + if (nrpackets == 0)
  72235. + nrpackets = 1;
  72236. + st->hcchar_copy.b.multicnt = nrpackets;
  72237. + st->hctsiz_copy.b.pktcnt = nrpackets;
  72238. +
  72239. + /* Initial PID also needs to be set */
  72240. + if (st->hcchar_copy.b.epdir == 0) {
  72241. + st->hctsiz_copy.b.xfersize = xfer_len;
  72242. + switch (st->hcchar_copy.b.multicnt) {
  72243. + case 1:
  72244. + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
  72245. + break;
  72246. + case 2:
  72247. + case 3:
  72248. + st->hctsiz_copy.b.pid = DWC_PID_MDATA;
  72249. + break;
  72250. + }
  72251. +
  72252. + } else {
  72253. + st->hctsiz_copy.b.xfersize = nrpackets * st->hcchar_copy.b.mps;
  72254. + switch (st->hcchar_copy.b.multicnt) {
  72255. + case 1:
  72256. + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
  72257. + break;
  72258. + case 2:
  72259. + st->hctsiz_copy.b.pid = DWC_PID_DATA1;
  72260. + break;
  72261. + case 3:
  72262. + st->hctsiz_copy.b.pid = DWC_PID_DATA2;
  72263. + break;
  72264. + }
  72265. + }
  72266. +
  72267. + fiq_print(FIQDBG_INT, hcd->fiq_state, "FSMQ %01d ", hc->hc_num);
  72268. + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hcchar_copy.d32);
  72269. + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hctsiz_copy.d32);
  72270. + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hcdma_copy.d32);
  72271. + hfnum.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hfnum);
  72272. + local_fiq_disable();
  72273. + DWC_WRITE_REG32(&hc_regs->hctsiz, st->hctsiz_copy.d32);
  72274. + DWC_WRITE_REG32(&hc_regs->hcsplt, st->hcsplt_copy.d32);
  72275. + DWC_WRITE_REG32(&hc_regs->hcdma, st->hcdma_copy.d32);
  72276. + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
  72277. + DWC_WRITE_REG32(&hc_regs->hcintmsk, st->hcintmsk_copy.d32);
  72278. + if (hfnum.b.frrem < PERIODIC_FRREM_BACKOFF) {
  72279. + /* Prevent queueing near EOF1. Bad things happen if a periodic
  72280. + * split transaction is queued very close to EOF.
  72281. + */
  72282. + st->fsm = FIQ_HS_ISOC_SLEEPING;
  72283. + } else {
  72284. + st->fsm = FIQ_HS_ISOC_TURBO;
  72285. + st->hcchar_copy.b.chen = 1;
  72286. + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
  72287. + }
  72288. + mb();
  72289. + st->hcchar_copy.b.chen = 0;
  72290. + local_fiq_enable();
  72291. + return 0;
  72292. +}
  72293. +
  72294. +
  72295. +/**
  72296. + * fiq_fsm_queue_split_transaction() - Set up a host channel and FIQ state
  72297. + * @hcd: Pointer to the dwc_otg_hcd struct
  72298. + * @qh: Pointer to the endpoint's queue head
  72299. + *
  72300. + * This overrides the dwc_otg driver's normal method of queueing a transaction.
  72301. + * Called from dwc_otg_hcd_queue_transactions(), this performs specific setup
  72302. + * for the nominated host channel.
  72303. + *
  72304. + * For periodic transfers, it also peeks at the FIQ state to see if an immediate
  72305. + * start is possible. If not, then the FIQ is left to start the transfer.
  72306. + */
  72307. +int fiq_fsm_queue_split_transaction(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh)
  72308. +{
  72309. + int start_immediate = 1, i;
  72310. + hfnum_data_t hfnum;
  72311. + dwc_hc_t *hc = qh->channel;
  72312. + dwc_otg_hc_regs_t *hc_regs = hcd->core_if->host_if->hc_regs[hc->hc_num];
  72313. + /* Program HC registers, setup FIQ_state, examine FIQ if periodic, start transfer (not if uframe 5) */
  72314. + int hub_addr, port_addr, frame, uframe;
  72315. + struct fiq_channel_state *st = &hcd->fiq_state->channel[hc->hc_num];
  72316. +
  72317. + if (st->fsm != FIQ_PASSTHROUGH)
  72318. + return 0;
  72319. + st->nr_errors = 0;
  72320. +
  72321. + st->hcchar_copy.d32 = 0;
  72322. + st->hcchar_copy.b.mps = hc->max_packet;
  72323. + st->hcchar_copy.b.epdir = hc->ep_is_in;
  72324. + st->hcchar_copy.b.devaddr = hc->dev_addr;
  72325. + st->hcchar_copy.b.epnum = hc->ep_num;
  72326. + st->hcchar_copy.b.eptype = hc->ep_type;
  72327. + if (hc->ep_type & 0x1) {
  72328. + if (hc->ep_is_in)
  72329. + st->hcchar_copy.b.multicnt = 3;
  72330. + else
  72331. + /* Docs say set this to 1, but driver sets to 0! */
  72332. + st->hcchar_copy.b.multicnt = 0;
  72333. + } else {
  72334. + st->hcchar_copy.b.multicnt = 1;
  72335. + st->hcchar_copy.b.oddfrm = 0;
  72336. + }
  72337. + st->hcchar_copy.b.lspddev = (hc->speed == DWC_OTG_EP_SPEED_LOW) ? 1 : 0;
  72338. + /* Enable the channel later as a final register write. */
  72339. +
  72340. + st->hcsplt_copy.d32 = 0;
  72341. + if(qh->do_split) {
  72342. + hcd->fops->hub_info(hcd, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->priv, &hub_addr, &port_addr);
  72343. + st->hcsplt_copy.b.compsplt = 0;
  72344. + st->hcsplt_copy.b.spltena = 1;
  72345. + // XACTPOS is for isoc-out only but needs initialising anyway.
  72346. + st->hcsplt_copy.b.xactpos = ISOC_XACTPOS_ALL;
  72347. + if((qh->ep_type == DWC_OTG_EP_TYPE_ISOC) && (!qh->ep_is_in)) {
  72348. + /* For packetsize 0 < L < 188, ISOC_XACTPOS_ALL.
  72349. + * for longer than this, ISOC_XACTPOS_BEGIN and the FIQ
  72350. + * will update as necessary.
  72351. + */
  72352. + if (hc->xfer_len > 188) {
  72353. + st->hcsplt_copy.b.xactpos = ISOC_XACTPOS_BEGIN;
  72354. + }
  72355. + }
  72356. + st->hcsplt_copy.b.hubaddr = (uint8_t) hub_addr;
  72357. + st->hcsplt_copy.b.prtaddr = (uint8_t) port_addr;
  72358. + st->hub_addr = hub_addr;
  72359. + st->port_addr = port_addr;
  72360. + }
  72361. +
  72362. + st->hctsiz_copy.d32 = 0;
  72363. + st->hctsiz_copy.b.dopng = 0;
  72364. + st->hctsiz_copy.b.pid = hc->data_pid_start;
  72365. +
  72366. + if (hc->ep_is_in || (hc->xfer_len > hc->max_packet)) {
  72367. + hc->xfer_len = hc->max_packet;
  72368. + } else if (!hc->ep_is_in && (hc->xfer_len > 188)) {
  72369. + hc->xfer_len = 188;
  72370. + }
  72371. + st->hctsiz_copy.b.xfersize = hc->xfer_len;
  72372. +
  72373. + st->hctsiz_copy.b.pktcnt = 1;
  72374. +
  72375. + if (hc->ep_type & 0x1) {
  72376. + /*
  72377. + * For potentially multi-packet transfers, must use the DMA bounce buffers. For IN transfers,
  72378. + * the DMA address is the address of the first 188byte slot buffer in the bounce buffer array.
  72379. + * For multi-packet OUT transfers, we need to copy the data into the bounce buffer array so the FIQ can punt
  72380. + * the right address out as necessary. hc->xfer_buff and hc->xfer_len have already been set
  72381. + * in assign_and_init_hc(), but this is for the eventual transaction completion only. The FIQ
  72382. + * must not touch internal driver state.
  72383. + */
  72384. + if(!fiq_fsm_setup_periodic_dma(hcd, st, qh)) {
  72385. + if (hc->align_buff) {
  72386. + st->hcdma_copy.d32 = hc->align_buff;
  72387. + } else {
  72388. + st->hcdma_copy.d32 = ((unsigned long) hc->xfer_buff & 0xFFFFFFFF);
  72389. + }
  72390. + }
  72391. + } else {
  72392. + if (hc->align_buff) {
  72393. + st->hcdma_copy.d32 = hc->align_buff;
  72394. + } else {
  72395. + st->hcdma_copy.d32 = ((unsigned long) hc->xfer_buff & 0xFFFFFFFF);
  72396. + }
  72397. + }
  72398. + /* The FIQ depends upon no other interrupts being enabled except channel halt.
  72399. + * Fixup channel interrupt mask. */
  72400. + st->hcintmsk_copy.d32 = 0;
  72401. + st->hcintmsk_copy.b.chhltd = 1;
  72402. + st->hcintmsk_copy.b.ahberr = 1;
  72403. +
  72404. + DWC_WRITE_REG32(&hc_regs->hcdma, st->hcdma_copy.d32);
  72405. + DWC_WRITE_REG32(&hc_regs->hctsiz, st->hctsiz_copy.d32);
  72406. + DWC_WRITE_REG32(&hc_regs->hcsplt, st->hcsplt_copy.d32);
  72407. + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
  72408. + DWC_WRITE_REG32(&hc_regs->hcintmsk, st->hcintmsk_copy.d32);
  72409. +
  72410. + local_fiq_disable();
  72411. + mb();
  72412. +
  72413. + if (hc->ep_type & 0x1) {
  72414. + hfnum.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hfnum);
  72415. + frame = (hfnum.b.frnum & ~0x7) >> 3;
  72416. + uframe = hfnum.b.frnum & 0x7;
  72417. + if (hfnum.b.frrem < PERIODIC_FRREM_BACKOFF) {
  72418. + /* Prevent queueing near EOF1. Bad things happen if a periodic
  72419. + * split transaction is queued very close to EOF.
  72420. + */
  72421. + start_immediate = 0;
  72422. + } else if (uframe == 5) {
  72423. + start_immediate = 0;
  72424. + } else if (hc->ep_type == UE_ISOCHRONOUS && !hc->ep_is_in) {
  72425. + start_immediate = 0;
  72426. + } else if (hc->ep_is_in && fiq_fsm_too_late(hcd->fiq_state, hc->hc_num)) {
  72427. + start_immediate = 0;
  72428. + } else {
  72429. + /* Search through all host channels to determine if a transaction
  72430. + * is currently in progress */
  72431. + for (i = 0; i < hcd->core_if->core_params->host_channels; i++) {
  72432. + if (i == hc->hc_num || hcd->fiq_state->channel[i].fsm == FIQ_PASSTHROUGH)
  72433. + continue;
  72434. + switch (hcd->fiq_state->channel[i].fsm) {
  72435. + /* TT is reserved for channels that are in the middle of a periodic
  72436. + * split transaction.
  72437. + */
  72438. + case FIQ_PER_SSPLIT_STARTED:
  72439. + case FIQ_PER_CSPLIT_WAIT:
  72440. + case FIQ_PER_CSPLIT_NYET1:
  72441. + case FIQ_PER_CSPLIT_POLL:
  72442. + case FIQ_PER_ISO_OUT_ACTIVE:
  72443. + case FIQ_PER_ISO_OUT_LAST:
  72444. + if (hcd->fiq_state->channel[i].hub_addr == hub_addr &&
  72445. + hcd->fiq_state->channel[i].port_addr == port_addr) {
  72446. + start_immediate = 0;
  72447. + }
  72448. + break;
  72449. + default:
  72450. + break;
  72451. + }
  72452. + if (!start_immediate)
  72453. + break;
  72454. + }
  72455. + }
  72456. + }
  72457. + fiq_print(FIQDBG_INT, hcd->fiq_state, "FSMQ %01d %01d", hc->hc_num, start_immediate);
  72458. + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08d", hfnum.b.frrem);
  72459. + //fiq_print(FIQDBG_INT, hcd->fiq_state, "H:%02dP:%02d", hub_addr, port_addr);
  72460. + //fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hctsiz_copy.d32);
  72461. + //fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hcdma_copy.d32);
  72462. + switch (hc->ep_type) {
  72463. + case UE_CONTROL:
  72464. + case UE_BULK:
  72465. + st->fsm = FIQ_NP_SSPLIT_STARTED;
  72466. + break;
  72467. + case UE_ISOCHRONOUS:
  72468. + if (hc->ep_is_in) {
  72469. + if (start_immediate) {
  72470. + st->fsm = FIQ_PER_SSPLIT_STARTED;
  72471. + } else {
  72472. + st->fsm = FIQ_PER_SSPLIT_QUEUED;
  72473. + }
  72474. + } else {
  72475. + if (start_immediate) {
  72476. + /* Single-isoc OUT packets don't require FIQ involvement */
  72477. + if (st->nrpackets == 1) {
  72478. + st->fsm = FIQ_PER_ISO_OUT_LAST;
  72479. + } else {
  72480. + st->fsm = FIQ_PER_ISO_OUT_ACTIVE;
  72481. + }
  72482. + } else {
  72483. + st->fsm = FIQ_PER_ISO_OUT_PENDING;
  72484. + }
  72485. + }
  72486. + break;
  72487. + case UE_INTERRUPT:
  72488. + if (start_immediate) {
  72489. + st->fsm = FIQ_PER_SSPLIT_STARTED;
  72490. + } else {
  72491. + st->fsm = FIQ_PER_SSPLIT_QUEUED;
  72492. + }
  72493. + default:
  72494. + break;
  72495. + }
  72496. + if (start_immediate) {
  72497. + /* Set the oddfrm bit as close as possible to actual queueing */
  72498. + frame = dwc_otg_hcd_get_frame_number(hcd);
  72499. + st->expected_uframe = (frame + 1) & 0x3FFF;
  72500. + st->hcchar_copy.b.oddfrm = (frame & 0x1) ? 0 : 1;
  72501. + st->hcchar_copy.b.chen = 1;
  72502. + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
  72503. + }
  72504. + mb();
  72505. + local_fiq_enable();
  72506. + return 0;
  72507. +}
  72508. +
  72509. +
  72510. +/**
  72511. + * This function selects transactions from the HCD transfer schedule and
  72512. + * assigns them to available host channels. It is called from HCD interrupt
  72513. + * handler functions.
  72514. + *
  72515. + * @param hcd The HCD state structure.
  72516. + *
  72517. + * @return The types of new transactions that were assigned to host channels.
  72518. + */
  72519. +dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t * hcd)
  72520. +{
  72521. + dwc_list_link_t *qh_ptr;
  72522. + dwc_otg_qh_t *qh;
  72523. + int num_channels;
  72524. + dwc_irqflags_t flags;
  72525. + dwc_spinlock_t *channel_lock = hcd->channel_lock;
  72526. + dwc_otg_transaction_type_e ret_val = DWC_OTG_TRANSACTION_NONE;
  72527. +
  72528. +#ifdef DEBUG_HOST_CHANNELS
  72529. + last_sel_trans_num_per_scheduled = 0;
  72530. + last_sel_trans_num_nonper_scheduled = 0;
  72531. + last_sel_trans_num_avail_hc_at_start = hcd->available_host_channels;
  72532. +#endif /* DEBUG_HOST_CHANNELS */
  72533. +
  72534. + /* Process entries in the periodic ready list. */
  72535. + qh_ptr = DWC_LIST_FIRST(&hcd->periodic_sched_ready);
  72536. +
  72537. + while (qh_ptr != &hcd->periodic_sched_ready &&
  72538. + !DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
  72539. +
  72540. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  72541. +
  72542. + if (microframe_schedule) {
  72543. + // Make sure we leave one channel for non periodic transactions.
  72544. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  72545. + if (hcd->available_host_channels <= 1) {
  72546. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  72547. + break;
  72548. + }
  72549. + hcd->available_host_channels--;
  72550. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  72551. +#ifdef DEBUG_HOST_CHANNELS
  72552. + last_sel_trans_num_per_scheduled++;
  72553. +#endif /* DEBUG_HOST_CHANNELS */
  72554. + }
  72555. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  72556. + assign_and_init_hc(hcd, qh);
  72557. +
  72558. + /*
  72559. + * Move the QH from the periodic ready schedule to the
  72560. + * periodic assigned schedule.
  72561. + */
  72562. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  72563. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  72564. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_assigned,
  72565. + &qh->qh_list_entry);
  72566. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  72567. + }
  72568. +
  72569. + /*
  72570. + * Process entries in the inactive portion of the non-periodic
  72571. + * schedule. Some free host channels may not be used if they are
  72572. + * reserved for periodic transfers.
  72573. + */
  72574. + qh_ptr = hcd->non_periodic_sched_inactive.next;
  72575. + num_channels = hcd->core_if->core_params->host_channels;
  72576. + while (qh_ptr != &hcd->non_periodic_sched_inactive &&
  72577. + (microframe_schedule || hcd->non_periodic_channels <
  72578. + num_channels - hcd->periodic_channels) &&
  72579. + !DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
  72580. +
  72581. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  72582. + /*
  72583. + * Check to see if this is a NAK'd retransmit, in which case ignore for retransmission
  72584. + * we hold off on bulk retransmissions to reduce NAK interrupt overhead for full-speed
  72585. + * cheeky devices that just hold off using NAKs
  72586. + */
  72587. + if (nak_holdoff && qh->do_split) {
  72588. + if (qh->nak_frame != 0xffff) {
  72589. + uint16_t next_frame = dwc_frame_num_inc(qh->nak_frame, (qh->ep_type == UE_BULK) ? nak_holdoff : 8);
  72590. + uint16_t frame = dwc_otg_hcd_get_frame_number(hcd);
  72591. + if (dwc_frame_num_le(frame, next_frame)) {
  72592. + if(dwc_frame_num_le(next_frame, hcd->fiq_state->next_sched_frame)) {
  72593. + hcd->fiq_state->next_sched_frame = next_frame;
  72594. + }
  72595. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  72596. + continue;
  72597. + } else {
  72598. + qh->nak_frame = 0xFFFF;
  72599. + }
  72600. + }
  72601. + }
  72602. +
  72603. + if (microframe_schedule) {
  72604. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  72605. + if (hcd->available_host_channels < 1) {
  72606. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  72607. + break;
  72608. + }
  72609. + hcd->available_host_channels--;
  72610. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  72611. +#ifdef DEBUG_HOST_CHANNELS
  72612. + last_sel_trans_num_nonper_scheduled++;
  72613. +#endif /* DEBUG_HOST_CHANNELS */
  72614. + }
  72615. +
  72616. + assign_and_init_hc(hcd, qh);
  72617. +
  72618. + /*
  72619. + * Move the QH from the non-periodic inactive schedule to the
  72620. + * non-periodic active schedule.
  72621. + */
  72622. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  72623. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  72624. + DWC_LIST_MOVE_HEAD(&hcd->non_periodic_sched_active,
  72625. + &qh->qh_list_entry);
  72626. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  72627. +
  72628. +
  72629. + if (!microframe_schedule)
  72630. + hcd->non_periodic_channels++;
  72631. + }
  72632. + /* we moved a non-periodic QH to the active schedule. If the inactive queue is empty,
  72633. + * stop the FIQ from kicking us. We could potentially still have elements here if we
  72634. + * ran out of host channels.
  72635. + */
  72636. + if (DWC_LIST_EMPTY(&hcd->non_periodic_sched_inactive)) {
  72637. + hcd->fiq_state->kick_np_queues = 0;
  72638. + } else {
  72639. + /* For each entry remaining in the NP inactive queue,
  72640. + * if this a NAK'd retransmit then don't set the kick flag.
  72641. + */
  72642. + if(nak_holdoff) {
  72643. + DWC_LIST_FOREACH(qh_ptr, &hcd->non_periodic_sched_inactive) {
  72644. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  72645. + if (qh->nak_frame == 0xFFFF) {
  72646. + hcd->fiq_state->kick_np_queues = 1;
  72647. + }
  72648. + }
  72649. + }
  72650. + }
  72651. + if(!DWC_LIST_EMPTY(&hcd->periodic_sched_assigned))
  72652. + ret_val |= DWC_OTG_TRANSACTION_PERIODIC;
  72653. +
  72654. + if(!DWC_LIST_EMPTY(&hcd->non_periodic_sched_active))
  72655. + ret_val |= DWC_OTG_TRANSACTION_NON_PERIODIC;
  72656. +
  72657. +
  72658. +#ifdef DEBUG_HOST_CHANNELS
  72659. + last_sel_trans_num_avail_hc_at_end = hcd->available_host_channels;
  72660. +#endif /* DEBUG_HOST_CHANNELS */
  72661. + return ret_val;
  72662. +}
  72663. +
  72664. +/**
  72665. + * Attempts to queue a single transaction request for a host channel
  72666. + * associated with either a periodic or non-periodic transfer. This function
  72667. + * assumes that there is space available in the appropriate request queue. For
  72668. + * an OUT transfer or SETUP transaction in Slave mode, it checks whether space
  72669. + * is available in the appropriate Tx FIFO.
  72670. + *
  72671. + * @param hcd The HCD state structure.
  72672. + * @param hc Host channel descriptor associated with either a periodic or
  72673. + * non-periodic transfer.
  72674. + * @param fifo_dwords_avail Number of DWORDs available in the periodic Tx
  72675. + * FIFO for periodic transfers or the non-periodic Tx FIFO for non-periodic
  72676. + * transfers.
  72677. + *
  72678. + * @return 1 if a request is queued and more requests may be needed to
  72679. + * complete the transfer, 0 if no more requests are required for this
  72680. + * transfer, -1 if there is insufficient space in the Tx FIFO.
  72681. + */
  72682. +static int queue_transaction(dwc_otg_hcd_t * hcd,
  72683. + dwc_hc_t * hc, uint16_t fifo_dwords_avail)
  72684. +{
  72685. + int retval;
  72686. +
  72687. + if (hcd->core_if->dma_enable) {
  72688. + if (hcd->core_if->dma_desc_enable) {
  72689. + if (!hc->xfer_started
  72690. + || (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)) {
  72691. + dwc_otg_hcd_start_xfer_ddma(hcd, hc->qh);
  72692. + hc->qh->ping_state = 0;
  72693. + }
  72694. + } else if (!hc->xfer_started) {
  72695. + if (fiq_fsm_enable && hc->error_state) {
  72696. + hcd->fiq_state->channel[hc->hc_num].nr_errors =
  72697. + DWC_CIRCLEQ_FIRST(&hc->qh->qtd_list)->error_count;
  72698. + hcd->fiq_state->channel[hc->hc_num].fsm =
  72699. + FIQ_PASSTHROUGH_ERRORSTATE;
  72700. + }
  72701. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  72702. + hc->qh->ping_state = 0;
  72703. + }
  72704. + retval = 0;
  72705. + } else if (hc->halt_pending) {
  72706. + /* Don't queue a request if the channel has been halted. */
  72707. + retval = 0;
  72708. + } else if (hc->halt_on_queue) {
  72709. + dwc_otg_hc_halt(hcd->core_if, hc, hc->halt_status);
  72710. + retval = 0;
  72711. + } else if (hc->do_ping) {
  72712. + if (!hc->xfer_started) {
  72713. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  72714. + }
  72715. + retval = 0;
  72716. + } else if (!hc->ep_is_in || hc->data_pid_start == DWC_OTG_HC_PID_SETUP) {
  72717. + if ((fifo_dwords_avail * 4) >= hc->max_packet) {
  72718. + if (!hc->xfer_started) {
  72719. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  72720. + retval = 1;
  72721. + } else {
  72722. + retval =
  72723. + dwc_otg_hc_continue_transfer(hcd->core_if,
  72724. + hc);
  72725. + }
  72726. + } else {
  72727. + retval = -1;
  72728. + }
  72729. + } else {
  72730. + if (!hc->xfer_started) {
  72731. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  72732. + retval = 1;
  72733. + } else {
  72734. + retval = dwc_otg_hc_continue_transfer(hcd->core_if, hc);
  72735. + }
  72736. + }
  72737. +
  72738. + return retval;
  72739. +}
  72740. +
  72741. +/**
  72742. + * Processes periodic channels for the next frame and queues transactions for
  72743. + * these channels to the DWC_otg controller. After queueing transactions, the
  72744. + * Periodic Tx FIFO Empty interrupt is enabled if there are more transactions
  72745. + * to queue as Periodic Tx FIFO or request queue space becomes available.
  72746. + * Otherwise, the Periodic Tx FIFO Empty interrupt is disabled.
  72747. + */
  72748. +static void process_periodic_channels(dwc_otg_hcd_t * hcd)
  72749. +{
  72750. + hptxsts_data_t tx_status;
  72751. + dwc_list_link_t *qh_ptr;
  72752. + dwc_otg_qh_t *qh;
  72753. + int status = 0;
  72754. + int no_queue_space = 0;
  72755. + int no_fifo_space = 0;
  72756. +
  72757. + dwc_otg_host_global_regs_t *host_regs;
  72758. + host_regs = hcd->core_if->host_if->host_global_regs;
  72759. +
  72760. + DWC_DEBUGPL(DBG_HCDV, "Queue periodic transactions\n");
  72761. +#ifdef DEBUG
  72762. + tx_status.d32 = DWC_READ_REG32(&host_regs->hptxsts);
  72763. + DWC_DEBUGPL(DBG_HCDV,
  72764. + " P Tx Req Queue Space Avail (before queue): %d\n",
  72765. + tx_status.b.ptxqspcavail);
  72766. + DWC_DEBUGPL(DBG_HCDV, " P Tx FIFO Space Avail (before queue): %d\n",
  72767. + tx_status.b.ptxfspcavail);
  72768. +#endif
  72769. +
  72770. + qh_ptr = hcd->periodic_sched_assigned.next;
  72771. + while (qh_ptr != &hcd->periodic_sched_assigned) {
  72772. + tx_status.d32 = DWC_READ_REG32(&host_regs->hptxsts);
  72773. + if (tx_status.b.ptxqspcavail == 0) {
  72774. + no_queue_space = 1;
  72775. + break;
  72776. + }
  72777. +
  72778. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  72779. +
  72780. + // Do not send a split start transaction any later than frame .6
  72781. + // Note, we have to schedule a periodic in .5 to make it go in .6
  72782. + if(fiq_fsm_enable && qh->do_split && ((dwc_otg_hcd_get_frame_number(hcd) + 1) & 7) > 6)
  72783. + {
  72784. + qh_ptr = qh_ptr->next;
  72785. + hcd->fiq_state->next_sched_frame = dwc_otg_hcd_get_frame_number(hcd) | 7;
  72786. + continue;
  72787. + }
  72788. +
  72789. + if (fiq_fsm_enable && fiq_fsm_transaction_suitable(qh)) {
  72790. + if (qh->do_split)
  72791. + fiq_fsm_queue_split_transaction(hcd, qh);
  72792. + else
  72793. + fiq_fsm_queue_isoc_transaction(hcd, qh);
  72794. + } else {
  72795. +
  72796. + /*
  72797. + * Set a flag if we're queueing high-bandwidth in slave mode.
  72798. + * The flag prevents any halts to get into the request queue in
  72799. + * the middle of multiple high-bandwidth packets getting queued.
  72800. + */
  72801. + if (!hcd->core_if->dma_enable && qh->channel->multi_count > 1) {
  72802. + hcd->core_if->queuing_high_bandwidth = 1;
  72803. + }
  72804. + status = queue_transaction(hcd, qh->channel,
  72805. + tx_status.b.ptxfspcavail);
  72806. + if (status < 0) {
  72807. + no_fifo_space = 1;
  72808. + break;
  72809. + }
  72810. + }
  72811. +
  72812. + /*
  72813. + * In Slave mode, stay on the current transfer until there is
  72814. + * nothing more to do or the high-bandwidth request count is
  72815. + * reached. In DMA mode, only need to queue one request. The
  72816. + * controller automatically handles multiple packets for
  72817. + * high-bandwidth transfers.
  72818. + */
  72819. + if (hcd->core_if->dma_enable || status == 0 ||
  72820. + qh->channel->requests == qh->channel->multi_count) {
  72821. + qh_ptr = qh_ptr->next;
  72822. + /*
  72823. + * Move the QH from the periodic assigned schedule to
  72824. + * the periodic queued schedule.
  72825. + */
  72826. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_queued,
  72827. + &qh->qh_list_entry);
  72828. +
  72829. + /* done queuing high bandwidth */
  72830. + hcd->core_if->queuing_high_bandwidth = 0;
  72831. + }
  72832. + }
  72833. +
  72834. + if (!hcd->core_if->dma_enable) {
  72835. + dwc_otg_core_global_regs_t *global_regs;
  72836. + gintmsk_data_t intr_mask = {.d32 = 0 };
  72837. +
  72838. + global_regs = hcd->core_if->core_global_regs;
  72839. + intr_mask.b.ptxfempty = 1;
  72840. +#ifdef DEBUG
  72841. + tx_status.d32 = DWC_READ_REG32(&host_regs->hptxsts);
  72842. + DWC_DEBUGPL(DBG_HCDV,
  72843. + " P Tx Req Queue Space Avail (after queue): %d\n",
  72844. + tx_status.b.ptxqspcavail);
  72845. + DWC_DEBUGPL(DBG_HCDV,
  72846. + " P Tx FIFO Space Avail (after queue): %d\n",
  72847. + tx_status.b.ptxfspcavail);
  72848. +#endif
  72849. + if (!DWC_LIST_EMPTY(&hcd->periodic_sched_assigned) ||
  72850. + no_queue_space || no_fifo_space) {
  72851. + /*
  72852. + * May need to queue more transactions as the request
  72853. + * queue or Tx FIFO empties. Enable the periodic Tx
  72854. + * FIFO empty interrupt. (Always use the half-empty
  72855. + * level to ensure that new requests are loaded as
  72856. + * soon as possible.)
  72857. + */
  72858. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0,
  72859. + intr_mask.d32);
  72860. + } else {
  72861. + /*
  72862. + * Disable the Tx FIFO empty interrupt since there are
  72863. + * no more transactions that need to be queued right
  72864. + * now. This function is called from interrupt
  72865. + * handlers to queue more transactions as transfer
  72866. + * states change.
  72867. + */
  72868. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32,
  72869. + 0);
  72870. + }
  72871. + }
  72872. +}
  72873. +
  72874. +/**
  72875. + * Processes active non-periodic channels and queues transactions for these
  72876. + * channels to the DWC_otg controller. After queueing transactions, the NP Tx
  72877. + * FIFO Empty interrupt is enabled if there are more transactions to queue as
  72878. + * NP Tx FIFO or request queue space becomes available. Otherwise, the NP Tx
  72879. + * FIFO Empty interrupt is disabled.
  72880. + */
  72881. +static void process_non_periodic_channels(dwc_otg_hcd_t * hcd)
  72882. +{
  72883. + gnptxsts_data_t tx_status;
  72884. + dwc_list_link_t *orig_qh_ptr;
  72885. + dwc_otg_qh_t *qh;
  72886. + int status;
  72887. + int no_queue_space = 0;
  72888. + int no_fifo_space = 0;
  72889. + int more_to_do = 0;
  72890. +
  72891. + dwc_otg_core_global_regs_t *global_regs =
  72892. + hcd->core_if->core_global_regs;
  72893. +
  72894. + DWC_DEBUGPL(DBG_HCDV, "Queue non-periodic transactions\n");
  72895. +#ifdef DEBUG
  72896. + tx_status.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  72897. + DWC_DEBUGPL(DBG_HCDV,
  72898. + " NP Tx Req Queue Space Avail (before queue): %d\n",
  72899. + tx_status.b.nptxqspcavail);
  72900. + DWC_DEBUGPL(DBG_HCDV, " NP Tx FIFO Space Avail (before queue): %d\n",
  72901. + tx_status.b.nptxfspcavail);
  72902. +#endif
  72903. + /*
  72904. + * Keep track of the starting point. Skip over the start-of-list
  72905. + * entry.
  72906. + */
  72907. + if (hcd->non_periodic_qh_ptr == &hcd->non_periodic_sched_active) {
  72908. + hcd->non_periodic_qh_ptr = hcd->non_periodic_qh_ptr->next;
  72909. + }
  72910. + orig_qh_ptr = hcd->non_periodic_qh_ptr;
  72911. +
  72912. + /*
  72913. + * Process once through the active list or until no more space is
  72914. + * available in the request queue or the Tx FIFO.
  72915. + */
  72916. + do {
  72917. + tx_status.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  72918. + if (!hcd->core_if->dma_enable && tx_status.b.nptxqspcavail == 0) {
  72919. + no_queue_space = 1;
  72920. + break;
  72921. + }
  72922. +
  72923. + qh = DWC_LIST_ENTRY(hcd->non_periodic_qh_ptr, dwc_otg_qh_t,
  72924. + qh_list_entry);
  72925. +
  72926. + if(fiq_fsm_enable && fiq_fsm_transaction_suitable(qh)) {
  72927. + fiq_fsm_queue_split_transaction(hcd, qh);
  72928. + } else {
  72929. + status = queue_transaction(hcd, qh->channel,
  72930. + tx_status.b.nptxfspcavail);
  72931. +
  72932. + if (status > 0) {
  72933. + more_to_do = 1;
  72934. + } else if (status < 0) {
  72935. + no_fifo_space = 1;
  72936. + break;
  72937. + }
  72938. + }
  72939. + /* Advance to next QH, skipping start-of-list entry. */
  72940. + hcd->non_periodic_qh_ptr = hcd->non_periodic_qh_ptr->next;
  72941. + if (hcd->non_periodic_qh_ptr == &hcd->non_periodic_sched_active) {
  72942. + hcd->non_periodic_qh_ptr =
  72943. + hcd->non_periodic_qh_ptr->next;
  72944. + }
  72945. +
  72946. + } while (hcd->non_periodic_qh_ptr != orig_qh_ptr);
  72947. +
  72948. + if (!hcd->core_if->dma_enable) {
  72949. + gintmsk_data_t intr_mask = {.d32 = 0 };
  72950. + intr_mask.b.nptxfempty = 1;
  72951. +
  72952. +#ifdef DEBUG
  72953. + tx_status.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  72954. + DWC_DEBUGPL(DBG_HCDV,
  72955. + " NP Tx Req Queue Space Avail (after queue): %d\n",
  72956. + tx_status.b.nptxqspcavail);
  72957. + DWC_DEBUGPL(DBG_HCDV,
  72958. + " NP Tx FIFO Space Avail (after queue): %d\n",
  72959. + tx_status.b.nptxfspcavail);
  72960. +#endif
  72961. + if (more_to_do || no_queue_space || no_fifo_space) {
  72962. + /*
  72963. + * May need to queue more transactions as the request
  72964. + * queue or Tx FIFO empties. Enable the non-periodic
  72965. + * Tx FIFO empty interrupt. (Always use the half-empty
  72966. + * level to ensure that new requests are loaded as
  72967. + * soon as possible.)
  72968. + */
  72969. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0,
  72970. + intr_mask.d32);
  72971. + } else {
  72972. + /*
  72973. + * Disable the Tx FIFO empty interrupt since there are
  72974. + * no more transactions that need to be queued right
  72975. + * now. This function is called from interrupt
  72976. + * handlers to queue more transactions as transfer
  72977. + * states change.
  72978. + */
  72979. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32,
  72980. + 0);
  72981. + }
  72982. + }
  72983. +}
  72984. +
  72985. +/**
  72986. + * This function processes the currently active host channels and queues
  72987. + * transactions for these channels to the DWC_otg controller. It is called
  72988. + * from HCD interrupt handler functions.
  72989. + *
  72990. + * @param hcd The HCD state structure.
  72991. + * @param tr_type The type(s) of transactions to queue (non-periodic,
  72992. + * periodic, or both).
  72993. + */
  72994. +void dwc_otg_hcd_queue_transactions(dwc_otg_hcd_t * hcd,
  72995. + dwc_otg_transaction_type_e tr_type)
  72996. +{
  72997. +#ifdef DEBUG_SOF
  72998. + DWC_DEBUGPL(DBG_HCD, "Queue Transactions\n");
  72999. +#endif
  73000. + /* Process host channels associated with periodic transfers. */
  73001. + if ((tr_type == DWC_OTG_TRANSACTION_PERIODIC ||
  73002. + tr_type == DWC_OTG_TRANSACTION_ALL) &&
  73003. + !DWC_LIST_EMPTY(&hcd->periodic_sched_assigned)) {
  73004. +
  73005. + process_periodic_channels(hcd);
  73006. + }
  73007. +
  73008. + /* Process host channels associated with non-periodic transfers. */
  73009. + if (tr_type == DWC_OTG_TRANSACTION_NON_PERIODIC ||
  73010. + tr_type == DWC_OTG_TRANSACTION_ALL) {
  73011. + if (!DWC_LIST_EMPTY(&hcd->non_periodic_sched_active)) {
  73012. + process_non_periodic_channels(hcd);
  73013. + } else {
  73014. + /*
  73015. + * Ensure NP Tx FIFO empty interrupt is disabled when
  73016. + * there are no non-periodic transfers to process.
  73017. + */
  73018. + gintmsk_data_t gintmsk = {.d32 = 0 };
  73019. + gintmsk.b.nptxfempty = 1;
  73020. + DWC_MODIFY_REG32(&hcd->core_if->
  73021. + core_global_regs->gintmsk, gintmsk.d32,
  73022. + 0);
  73023. + }
  73024. + }
  73025. +}
  73026. +
  73027. +#ifdef DWC_HS_ELECT_TST
  73028. +/*
  73029. + * Quick and dirty hack to implement the HS Electrical Test
  73030. + * SINGLE_STEP_GET_DEVICE_DESCRIPTOR feature.
  73031. + *
  73032. + * This code was copied from our userspace app "hset". It sends a
  73033. + * Get Device Descriptor control sequence in two parts, first the
  73034. + * Setup packet by itself, followed some time later by the In and
  73035. + * Ack packets. Rather than trying to figure out how to add this
  73036. + * functionality to the normal driver code, we just hijack the
  73037. + * hardware, using these two function to drive the hardware
  73038. + * directly.
  73039. + */
  73040. +
  73041. +static dwc_otg_core_global_regs_t *global_regs;
  73042. +static dwc_otg_host_global_regs_t *hc_global_regs;
  73043. +static dwc_otg_hc_regs_t *hc_regs;
  73044. +static uint32_t *data_fifo;
  73045. +
  73046. +static void do_setup(void)
  73047. +{
  73048. + gintsts_data_t gintsts;
  73049. + hctsiz_data_t hctsiz;
  73050. + hcchar_data_t hcchar;
  73051. + haint_data_t haint;
  73052. + hcint_data_t hcint;
  73053. +
  73054. + /* Enable HAINTs */
  73055. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0001);
  73056. +
  73057. + /* Enable HCINTs */
  73058. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x04a3);
  73059. +
  73060. + /* Read GINTSTS */
  73061. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73062. +
  73063. + /* Read HAINT */
  73064. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  73065. +
  73066. + /* Read HCINT */
  73067. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  73068. +
  73069. + /* Read HCCHAR */
  73070. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73071. +
  73072. + /* Clear HCINT */
  73073. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  73074. +
  73075. + /* Clear HAINT */
  73076. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  73077. +
  73078. + /* Clear GINTSTS */
  73079. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  73080. +
  73081. + /* Read GINTSTS */
  73082. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73083. +
  73084. + /*
  73085. + * Send Setup packet (Get Device Descriptor)
  73086. + */
  73087. +
  73088. + /* Make sure channel is disabled */
  73089. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73090. + if (hcchar.b.chen) {
  73091. + hcchar.b.chdis = 1;
  73092. +// hcchar.b.chen = 1;
  73093. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  73094. + //sleep(1);
  73095. + dwc_mdelay(1000);
  73096. +
  73097. + /* Read GINTSTS */
  73098. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73099. +
  73100. + /* Read HAINT */
  73101. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  73102. +
  73103. + /* Read HCINT */
  73104. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  73105. +
  73106. + /* Read HCCHAR */
  73107. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73108. +
  73109. + /* Clear HCINT */
  73110. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  73111. +
  73112. + /* Clear HAINT */
  73113. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  73114. +
  73115. + /* Clear GINTSTS */
  73116. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  73117. +
  73118. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73119. + }
  73120. +
  73121. + /* Set HCTSIZ */
  73122. + hctsiz.d32 = 0;
  73123. + hctsiz.b.xfersize = 8;
  73124. + hctsiz.b.pktcnt = 1;
  73125. + hctsiz.b.pid = DWC_OTG_HC_PID_SETUP;
  73126. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  73127. +
  73128. + /* Set HCCHAR */
  73129. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73130. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  73131. + hcchar.b.epdir = 0;
  73132. + hcchar.b.epnum = 0;
  73133. + hcchar.b.mps = 8;
  73134. + hcchar.b.chen = 1;
  73135. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  73136. +
  73137. + /* Fill FIFO with Setup data for Get Device Descriptor */
  73138. + data_fifo = (uint32_t *) ((char *)global_regs + 0x1000);
  73139. + DWC_WRITE_REG32(data_fifo++, 0x01000680);
  73140. + DWC_WRITE_REG32(data_fifo++, 0x00080000);
  73141. +
  73142. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73143. +
  73144. + /* Wait for host channel interrupt */
  73145. + do {
  73146. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73147. + } while (gintsts.b.hcintr == 0);
  73148. +
  73149. + /* Disable HCINTs */
  73150. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x0000);
  73151. +
  73152. + /* Disable HAINTs */
  73153. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0000);
  73154. +
  73155. + /* Read HAINT */
  73156. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  73157. +
  73158. + /* Read HCINT */
  73159. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  73160. +
  73161. + /* Read HCCHAR */
  73162. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73163. +
  73164. + /* Clear HCINT */
  73165. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  73166. +
  73167. + /* Clear HAINT */
  73168. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  73169. +
  73170. + /* Clear GINTSTS */
  73171. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  73172. +
  73173. + /* Read GINTSTS */
  73174. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73175. +}
  73176. +
  73177. +static void do_in_ack(void)
  73178. +{
  73179. + gintsts_data_t gintsts;
  73180. + hctsiz_data_t hctsiz;
  73181. + hcchar_data_t hcchar;
  73182. + haint_data_t haint;
  73183. + hcint_data_t hcint;
  73184. + host_grxsts_data_t grxsts;
  73185. +
  73186. + /* Enable HAINTs */
  73187. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0001);
  73188. +
  73189. + /* Enable HCINTs */
  73190. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x04a3);
  73191. +
  73192. + /* Read GINTSTS */
  73193. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73194. +
  73195. + /* Read HAINT */
  73196. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  73197. +
  73198. + /* Read HCINT */
  73199. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  73200. +
  73201. + /* Read HCCHAR */
  73202. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73203. +
  73204. + /* Clear HCINT */
  73205. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  73206. +
  73207. + /* Clear HAINT */
  73208. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  73209. +
  73210. + /* Clear GINTSTS */
  73211. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  73212. +
  73213. + /* Read GINTSTS */
  73214. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73215. +
  73216. + /*
  73217. + * Receive Control In packet
  73218. + */
  73219. +
  73220. + /* Make sure channel is disabled */
  73221. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73222. + if (hcchar.b.chen) {
  73223. + hcchar.b.chdis = 1;
  73224. + hcchar.b.chen = 1;
  73225. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  73226. + //sleep(1);
  73227. + dwc_mdelay(1000);
  73228. +
  73229. + /* Read GINTSTS */
  73230. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73231. +
  73232. + /* Read HAINT */
  73233. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  73234. +
  73235. + /* Read HCINT */
  73236. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  73237. +
  73238. + /* Read HCCHAR */
  73239. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73240. +
  73241. + /* Clear HCINT */
  73242. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  73243. +
  73244. + /* Clear HAINT */
  73245. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  73246. +
  73247. + /* Clear GINTSTS */
  73248. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  73249. +
  73250. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73251. + }
  73252. +
  73253. + /* Set HCTSIZ */
  73254. + hctsiz.d32 = 0;
  73255. + hctsiz.b.xfersize = 8;
  73256. + hctsiz.b.pktcnt = 1;
  73257. + hctsiz.b.pid = DWC_OTG_HC_PID_DATA1;
  73258. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  73259. +
  73260. + /* Set HCCHAR */
  73261. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73262. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  73263. + hcchar.b.epdir = 1;
  73264. + hcchar.b.epnum = 0;
  73265. + hcchar.b.mps = 8;
  73266. + hcchar.b.chen = 1;
  73267. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  73268. +
  73269. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73270. +
  73271. + /* Wait for receive status queue interrupt */
  73272. + do {
  73273. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73274. + } while (gintsts.b.rxstsqlvl == 0);
  73275. +
  73276. + /* Read RXSTS */
  73277. + grxsts.d32 = DWC_READ_REG32(&global_regs->grxstsp);
  73278. +
  73279. + /* Clear RXSTSQLVL in GINTSTS */
  73280. + gintsts.d32 = 0;
  73281. + gintsts.b.rxstsqlvl = 1;
  73282. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  73283. +
  73284. + switch (grxsts.b.pktsts) {
  73285. + case DWC_GRXSTS_PKTSTS_IN:
  73286. + /* Read the data into the host buffer */
  73287. + if (grxsts.b.bcnt > 0) {
  73288. + int i;
  73289. + int word_count = (grxsts.b.bcnt + 3) / 4;
  73290. +
  73291. + data_fifo = (uint32_t *) ((char *)global_regs + 0x1000);
  73292. +
  73293. + for (i = 0; i < word_count; i++) {
  73294. + (void)DWC_READ_REG32(data_fifo++);
  73295. + }
  73296. + }
  73297. + break;
  73298. +
  73299. + default:
  73300. + break;
  73301. + }
  73302. +
  73303. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73304. +
  73305. + /* Wait for receive status queue interrupt */
  73306. + do {
  73307. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73308. + } while (gintsts.b.rxstsqlvl == 0);
  73309. +
  73310. + /* Read RXSTS */
  73311. + grxsts.d32 = DWC_READ_REG32(&global_regs->grxstsp);
  73312. +
  73313. + /* Clear RXSTSQLVL in GINTSTS */
  73314. + gintsts.d32 = 0;
  73315. + gintsts.b.rxstsqlvl = 1;
  73316. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  73317. +
  73318. + switch (grxsts.b.pktsts) {
  73319. + case DWC_GRXSTS_PKTSTS_IN_XFER_COMP:
  73320. + break;
  73321. +
  73322. + default:
  73323. + break;
  73324. + }
  73325. +
  73326. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73327. +
  73328. + /* Wait for host channel interrupt */
  73329. + do {
  73330. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73331. + } while (gintsts.b.hcintr == 0);
  73332. +
  73333. + /* Read HAINT */
  73334. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  73335. +
  73336. + /* Read HCINT */
  73337. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  73338. +
  73339. + /* Read HCCHAR */
  73340. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73341. +
  73342. + /* Clear HCINT */
  73343. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  73344. +
  73345. + /* Clear HAINT */
  73346. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  73347. +
  73348. + /* Clear GINTSTS */
  73349. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  73350. +
  73351. + /* Read GINTSTS */
  73352. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73353. +
  73354. +// usleep(100000);
  73355. +// mdelay(100);
  73356. + dwc_mdelay(1);
  73357. +
  73358. + /*
  73359. + * Send handshake packet
  73360. + */
  73361. +
  73362. + /* Read HAINT */
  73363. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  73364. +
  73365. + /* Read HCINT */
  73366. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  73367. +
  73368. + /* Read HCCHAR */
  73369. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73370. +
  73371. + /* Clear HCINT */
  73372. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  73373. +
  73374. + /* Clear HAINT */
  73375. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  73376. +
  73377. + /* Clear GINTSTS */
  73378. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  73379. +
  73380. + /* Read GINTSTS */
  73381. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73382. +
  73383. + /* Make sure channel is disabled */
  73384. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73385. + if (hcchar.b.chen) {
  73386. + hcchar.b.chdis = 1;
  73387. + hcchar.b.chen = 1;
  73388. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  73389. + //sleep(1);
  73390. + dwc_mdelay(1000);
  73391. +
  73392. + /* Read GINTSTS */
  73393. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73394. +
  73395. + /* Read HAINT */
  73396. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  73397. +
  73398. + /* Read HCINT */
  73399. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  73400. +
  73401. + /* Read HCCHAR */
  73402. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73403. +
  73404. + /* Clear HCINT */
  73405. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  73406. +
  73407. + /* Clear HAINT */
  73408. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  73409. +
  73410. + /* Clear GINTSTS */
  73411. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  73412. +
  73413. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73414. + }
  73415. +
  73416. + /* Set HCTSIZ */
  73417. + hctsiz.d32 = 0;
  73418. + hctsiz.b.xfersize = 0;
  73419. + hctsiz.b.pktcnt = 1;
  73420. + hctsiz.b.pid = DWC_OTG_HC_PID_DATA1;
  73421. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  73422. +
  73423. + /* Set HCCHAR */
  73424. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73425. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  73426. + hcchar.b.epdir = 0;
  73427. + hcchar.b.epnum = 0;
  73428. + hcchar.b.mps = 8;
  73429. + hcchar.b.chen = 1;
  73430. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  73431. +
  73432. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73433. +
  73434. + /* Wait for host channel interrupt */
  73435. + do {
  73436. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73437. + } while (gintsts.b.hcintr == 0);
  73438. +
  73439. + /* Disable HCINTs */
  73440. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x0000);
  73441. +
  73442. + /* Disable HAINTs */
  73443. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0000);
  73444. +
  73445. + /* Read HAINT */
  73446. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  73447. +
  73448. + /* Read HCINT */
  73449. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  73450. +
  73451. + /* Read HCCHAR */
  73452. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73453. +
  73454. + /* Clear HCINT */
  73455. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  73456. +
  73457. + /* Clear HAINT */
  73458. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  73459. +
  73460. + /* Clear GINTSTS */
  73461. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  73462. +
  73463. + /* Read GINTSTS */
  73464. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  73465. +}
  73466. +#endif
  73467. +
  73468. +/** Handles hub class-specific requests. */
  73469. +int dwc_otg_hcd_hub_control(dwc_otg_hcd_t * dwc_otg_hcd,
  73470. + uint16_t typeReq,
  73471. + uint16_t wValue,
  73472. + uint16_t wIndex, uint8_t * buf, uint16_t wLength)
  73473. +{
  73474. + int retval = 0;
  73475. +
  73476. + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
  73477. + usb_hub_descriptor_t *hub_desc;
  73478. + hprt0_data_t hprt0 = {.d32 = 0 };
  73479. +
  73480. + uint32_t port_status;
  73481. +
  73482. + switch (typeReq) {
  73483. + case UCR_CLEAR_HUB_FEATURE:
  73484. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  73485. + "ClearHubFeature 0x%x\n", wValue);
  73486. + switch (wValue) {
  73487. + case UHF_C_HUB_LOCAL_POWER:
  73488. + case UHF_C_HUB_OVER_CURRENT:
  73489. + /* Nothing required here */
  73490. + break;
  73491. + default:
  73492. + retval = -DWC_E_INVALID;
  73493. + DWC_ERROR("DWC OTG HCD - "
  73494. + "ClearHubFeature request %xh unknown\n",
  73495. + wValue);
  73496. + }
  73497. + break;
  73498. + case UCR_CLEAR_PORT_FEATURE:
  73499. +#ifdef CONFIG_USB_DWC_OTG_LPM
  73500. + if (wValue != UHF_PORT_L1)
  73501. +#endif
  73502. + if (!wIndex || wIndex > 1)
  73503. + goto error;
  73504. +
  73505. + switch (wValue) {
  73506. + case UHF_PORT_ENABLE:
  73507. + DWC_DEBUGPL(DBG_ANY, "DWC OTG HCD HUB CONTROL - "
  73508. + "ClearPortFeature USB_PORT_FEAT_ENABLE\n");
  73509. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  73510. + hprt0.b.prtena = 1;
  73511. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  73512. + break;
  73513. + case UHF_PORT_SUSPEND:
  73514. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  73515. + "ClearPortFeature USB_PORT_FEAT_SUSPEND\n");
  73516. +
  73517. + if (core_if->power_down == 2) {
  73518. + dwc_otg_host_hibernation_restore(core_if, 0, 0);
  73519. + } else {
  73520. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  73521. + dwc_mdelay(5);
  73522. +
  73523. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  73524. + hprt0.b.prtres = 1;
  73525. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  73526. + hprt0.b.prtsusp = 0;
  73527. + /* Clear Resume bit */
  73528. + dwc_mdelay(100);
  73529. + hprt0.b.prtres = 0;
  73530. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  73531. + }
  73532. + break;
  73533. +#ifdef CONFIG_USB_DWC_OTG_LPM
  73534. + case UHF_PORT_L1:
  73535. + {
  73536. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  73537. + glpmcfg_data_t lpmcfg = {.d32 = 0 };
  73538. +
  73539. + lpmcfg.d32 =
  73540. + DWC_READ_REG32(&core_if->
  73541. + core_global_regs->glpmcfg);
  73542. + lpmcfg.b.en_utmi_sleep = 0;
  73543. + lpmcfg.b.hird_thres &= (~(1 << 4));
  73544. + lpmcfg.b.prt_sleep_sts = 1;
  73545. + DWC_WRITE_REG32(&core_if->
  73546. + core_global_regs->glpmcfg,
  73547. + lpmcfg.d32);
  73548. +
  73549. + /* Clear Enbl_L1Gating bit. */
  73550. + pcgcctl.b.enbl_sleep_gating = 1;
  73551. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32,
  73552. + 0);
  73553. +
  73554. + dwc_mdelay(5);
  73555. +
  73556. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  73557. + hprt0.b.prtres = 1;
  73558. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  73559. + hprt0.d32);
  73560. + /* This bit will be cleared in wakeup interrupt handle */
  73561. + break;
  73562. + }
  73563. +#endif
  73564. + case UHF_PORT_POWER:
  73565. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  73566. + "ClearPortFeature USB_PORT_FEAT_POWER\n");
  73567. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  73568. + hprt0.b.prtpwr = 0;
  73569. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  73570. + break;
  73571. + case UHF_PORT_INDICATOR:
  73572. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  73573. + "ClearPortFeature USB_PORT_FEAT_INDICATOR\n");
  73574. + /* Port inidicator not supported */
  73575. + break;
  73576. + case UHF_C_PORT_CONNECTION:
  73577. + /* Clears drivers internal connect status change
  73578. + * flag */
  73579. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  73580. + "ClearPortFeature USB_PORT_FEAT_C_CONNECTION\n");
  73581. + dwc_otg_hcd->flags.b.port_connect_status_change = 0;
  73582. + break;
  73583. + case UHF_C_PORT_RESET:
  73584. + /* Clears the driver's internal Port Reset Change
  73585. + * flag */
  73586. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  73587. + "ClearPortFeature USB_PORT_FEAT_C_RESET\n");
  73588. + dwc_otg_hcd->flags.b.port_reset_change = 0;
  73589. + break;
  73590. + case UHF_C_PORT_ENABLE:
  73591. + /* Clears the driver's internal Port
  73592. + * Enable/Disable Change flag */
  73593. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  73594. + "ClearPortFeature USB_PORT_FEAT_C_ENABLE\n");
  73595. + dwc_otg_hcd->flags.b.port_enable_change = 0;
  73596. + break;
  73597. + case UHF_C_PORT_SUSPEND:
  73598. + /* Clears the driver's internal Port Suspend
  73599. + * Change flag, which is set when resume signaling on
  73600. + * the host port is complete */
  73601. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  73602. + "ClearPortFeature USB_PORT_FEAT_C_SUSPEND\n");
  73603. + dwc_otg_hcd->flags.b.port_suspend_change = 0;
  73604. + break;
  73605. +#ifdef CONFIG_USB_DWC_OTG_LPM
  73606. + case UHF_C_PORT_L1:
  73607. + dwc_otg_hcd->flags.b.port_l1_change = 0;
  73608. + break;
  73609. +#endif
  73610. + case UHF_C_PORT_OVER_CURRENT:
  73611. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  73612. + "ClearPortFeature USB_PORT_FEAT_C_OVER_CURRENT\n");
  73613. + dwc_otg_hcd->flags.b.port_over_current_change = 0;
  73614. + break;
  73615. + default:
  73616. + retval = -DWC_E_INVALID;
  73617. + DWC_ERROR("DWC OTG HCD - "
  73618. + "ClearPortFeature request %xh "
  73619. + "unknown or unsupported\n", wValue);
  73620. + }
  73621. + break;
  73622. + case UCR_GET_HUB_DESCRIPTOR:
  73623. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  73624. + "GetHubDescriptor\n");
  73625. + hub_desc = (usb_hub_descriptor_t *) buf;
  73626. + hub_desc->bDescLength = 9;
  73627. + hub_desc->bDescriptorType = 0x29;
  73628. + hub_desc->bNbrPorts = 1;
  73629. + USETW(hub_desc->wHubCharacteristics, 0x08);
  73630. + hub_desc->bPwrOn2PwrGood = 1;
  73631. + hub_desc->bHubContrCurrent = 0;
  73632. + hub_desc->DeviceRemovable[0] = 0;
  73633. + hub_desc->DeviceRemovable[1] = 0xff;
  73634. + break;
  73635. + case UCR_GET_HUB_STATUS:
  73636. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  73637. + "GetHubStatus\n");
  73638. + DWC_MEMSET(buf, 0, 4);
  73639. + break;
  73640. + case UCR_GET_PORT_STATUS:
  73641. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  73642. + "GetPortStatus wIndex = 0x%04x FLAGS=0x%08x\n",
  73643. + wIndex, dwc_otg_hcd->flags.d32);
  73644. + if (!wIndex || wIndex > 1)
  73645. + goto error;
  73646. +
  73647. + port_status = 0;
  73648. +
  73649. + if (dwc_otg_hcd->flags.b.port_connect_status_change)
  73650. + port_status |= (1 << UHF_C_PORT_CONNECTION);
  73651. +
  73652. + if (dwc_otg_hcd->flags.b.port_enable_change)
  73653. + port_status |= (1 << UHF_C_PORT_ENABLE);
  73654. +
  73655. + if (dwc_otg_hcd->flags.b.port_suspend_change)
  73656. + port_status |= (1 << UHF_C_PORT_SUSPEND);
  73657. +
  73658. + if (dwc_otg_hcd->flags.b.port_l1_change)
  73659. + port_status |= (1 << UHF_C_PORT_L1);
  73660. +
  73661. + if (dwc_otg_hcd->flags.b.port_reset_change) {
  73662. + port_status |= (1 << UHF_C_PORT_RESET);
  73663. + }
  73664. +
  73665. + if (dwc_otg_hcd->flags.b.port_over_current_change) {
  73666. + DWC_WARN("Overcurrent change detected\n");
  73667. + port_status |= (1 << UHF_C_PORT_OVER_CURRENT);
  73668. + }
  73669. +
  73670. + if (!dwc_otg_hcd->flags.b.port_connect_status) {
  73671. + /*
  73672. + * The port is disconnected, which means the core is
  73673. + * either in device mode or it soon will be. Just
  73674. + * return 0's for the remainder of the port status
  73675. + * since the port register can't be read if the core
  73676. + * is in device mode.
  73677. + */
  73678. + *((__le32 *) buf) = dwc_cpu_to_le32(&port_status);
  73679. + break;
  73680. + }
  73681. +
  73682. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  73683. + DWC_DEBUGPL(DBG_HCDV, " HPRT0: 0x%08x\n", hprt0.d32);
  73684. +
  73685. + if (hprt0.b.prtconnsts)
  73686. + port_status |= (1 << UHF_PORT_CONNECTION);
  73687. +
  73688. + if (hprt0.b.prtena)
  73689. + port_status |= (1 << UHF_PORT_ENABLE);
  73690. +
  73691. + if (hprt0.b.prtsusp)
  73692. + port_status |= (1 << UHF_PORT_SUSPEND);
  73693. +
  73694. + if (hprt0.b.prtovrcurract)
  73695. + port_status |= (1 << UHF_PORT_OVER_CURRENT);
  73696. +
  73697. + if (hprt0.b.prtrst)
  73698. + port_status |= (1 << UHF_PORT_RESET);
  73699. +
  73700. + if (hprt0.b.prtpwr)
  73701. + port_status |= (1 << UHF_PORT_POWER);
  73702. +
  73703. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED)
  73704. + port_status |= (1 << UHF_PORT_HIGH_SPEED);
  73705. + else if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED)
  73706. + port_status |= (1 << UHF_PORT_LOW_SPEED);
  73707. +
  73708. + if (hprt0.b.prttstctl)
  73709. + port_status |= (1 << UHF_PORT_TEST);
  73710. + if (dwc_otg_get_lpm_portsleepstatus(dwc_otg_hcd->core_if)) {
  73711. + port_status |= (1 << UHF_PORT_L1);
  73712. + }
  73713. + /*
  73714. + For Synopsys HW emulation of Power down wkup_control asserts the
  73715. + hreset_n and prst_n on suspned. This causes the HPRT0 to be zero.
  73716. + We intentionally tell the software that port is in L2Suspend state.
  73717. + Only for STE.
  73718. + */
  73719. + if ((core_if->power_down == 2)
  73720. + && (core_if->hibernation_suspend == 1)) {
  73721. + port_status |= (1 << UHF_PORT_SUSPEND);
  73722. + }
  73723. + /* USB_PORT_FEAT_INDICATOR unsupported always 0 */
  73724. +
  73725. + *((__le32 *) buf) = dwc_cpu_to_le32(&port_status);
  73726. +
  73727. + break;
  73728. + case UCR_SET_HUB_FEATURE:
  73729. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  73730. + "SetHubFeature\n");
  73731. + /* No HUB features supported */
  73732. + break;
  73733. + case UCR_SET_PORT_FEATURE:
  73734. + if (wValue != UHF_PORT_TEST && (!wIndex || wIndex > 1))
  73735. + goto error;
  73736. +
  73737. + if (!dwc_otg_hcd->flags.b.port_connect_status) {
  73738. + /*
  73739. + * The port is disconnected, which means the core is
  73740. + * either in device mode or it soon will be. Just
  73741. + * return without doing anything since the port
  73742. + * register can't be written if the core is in device
  73743. + * mode.
  73744. + */
  73745. + break;
  73746. + }
  73747. +
  73748. + switch (wValue) {
  73749. + case UHF_PORT_SUSPEND:
  73750. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  73751. + "SetPortFeature - USB_PORT_FEAT_SUSPEND\n");
  73752. + if (dwc_otg_hcd_otg_port(dwc_otg_hcd) != wIndex) {
  73753. + goto error;
  73754. + }
  73755. + if (core_if->power_down == 2) {
  73756. + int timeout = 300;
  73757. + dwc_irqflags_t flags;
  73758. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  73759. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  73760. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  73761. +#ifdef DWC_DEV_SRPCAP
  73762. + int32_t otg_cap_param = core_if->core_params->otg_cap;
  73763. +#endif
  73764. + DWC_PRINTF("Preparing for complete power-off\n");
  73765. +
  73766. + /* Save registers before hibernation */
  73767. + dwc_otg_save_global_regs(core_if);
  73768. + dwc_otg_save_host_regs(core_if);
  73769. +
  73770. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  73771. + hprt0.b.prtsusp = 1;
  73772. + hprt0.b.prtena = 0;
  73773. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  73774. + /* Spin hprt0.b.prtsusp to became 1 */
  73775. + do {
  73776. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  73777. + if (hprt0.b.prtsusp) {
  73778. + break;
  73779. + }
  73780. + dwc_mdelay(1);
  73781. + } while (--timeout);
  73782. + if (!timeout) {
  73783. + DWC_WARN("Suspend wasn't genereted\n");
  73784. + }
  73785. + dwc_udelay(10);
  73786. +
  73787. + /*
  73788. + * We need to disable interrupts to prevent servicing of any IRQ
  73789. + * during going to hibernation
  73790. + */
  73791. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  73792. + core_if->lx_state = DWC_OTG_L2;
  73793. +#ifdef DWC_DEV_SRPCAP
  73794. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  73795. + hprt0.b.prtpwr = 0;
  73796. + hprt0.b.prtena = 0;
  73797. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  73798. + hprt0.d32);
  73799. +#endif
  73800. + gusbcfg.d32 =
  73801. + DWC_READ_REG32(&core_if->core_global_regs->
  73802. + gusbcfg);
  73803. + if (gusbcfg.b.ulpi_utmi_sel == 1) {
  73804. + /* ULPI interface */
  73805. + /* Suspend the Phy Clock */
  73806. + pcgcctl.d32 = 0;
  73807. + pcgcctl.b.stoppclk = 1;
  73808. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  73809. + pcgcctl.d32);
  73810. + dwc_udelay(10);
  73811. + gpwrdn.b.pmuactv = 1;
  73812. + DWC_MODIFY_REG32(&core_if->
  73813. + core_global_regs->
  73814. + gpwrdn, 0, gpwrdn.d32);
  73815. + } else {
  73816. + /* UTMI+ Interface */
  73817. + gpwrdn.b.pmuactv = 1;
  73818. + DWC_MODIFY_REG32(&core_if->
  73819. + core_global_regs->
  73820. + gpwrdn, 0, gpwrdn.d32);
  73821. + dwc_udelay(10);
  73822. + pcgcctl.b.stoppclk = 1;
  73823. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  73824. + dwc_udelay(10);
  73825. + }
  73826. +#ifdef DWC_DEV_SRPCAP
  73827. + gpwrdn.d32 = 0;
  73828. + gpwrdn.b.dis_vbus = 1;
  73829. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  73830. + gpwrdn, 0, gpwrdn.d32);
  73831. +#endif
  73832. + gpwrdn.d32 = 0;
  73833. + gpwrdn.b.pmuintsel = 1;
  73834. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  73835. + gpwrdn, 0, gpwrdn.d32);
  73836. + dwc_udelay(10);
  73837. +
  73838. + gpwrdn.d32 = 0;
  73839. +#ifdef DWC_DEV_SRPCAP
  73840. + gpwrdn.b.srp_det_msk = 1;
  73841. +#endif
  73842. + gpwrdn.b.disconn_det_msk = 1;
  73843. + gpwrdn.b.lnstchng_msk = 1;
  73844. + gpwrdn.b.sts_chngint_msk = 1;
  73845. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  73846. + gpwrdn, 0, gpwrdn.d32);
  73847. + dwc_udelay(10);
  73848. +
  73849. + /* Enable Power Down Clamp and all interrupts in GPWRDN */
  73850. + gpwrdn.d32 = 0;
  73851. + gpwrdn.b.pwrdnclmp = 1;
  73852. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  73853. + gpwrdn, 0, gpwrdn.d32);
  73854. + dwc_udelay(10);
  73855. +
  73856. + /* Switch off VDD */
  73857. + gpwrdn.d32 = 0;
  73858. + gpwrdn.b.pwrdnswtch = 1;
  73859. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  73860. + gpwrdn, 0, gpwrdn.d32);
  73861. +
  73862. +#ifdef DWC_DEV_SRPCAP
  73863. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE)
  73864. + {
  73865. + core_if->pwron_timer_started = 1;
  73866. + DWC_TIMER_SCHEDULE(core_if->pwron_timer, 6000 /* 6 secs */ );
  73867. + }
  73868. +#endif
  73869. + /* Save gpwrdn register for further usage if stschng interrupt */
  73870. + core_if->gr_backup->gpwrdn_local =
  73871. + DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  73872. +
  73873. + /* Set flag to indicate that we are in hibernation */
  73874. + core_if->hibernation_suspend = 1;
  73875. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock,flags);
  73876. +
  73877. + DWC_PRINTF("Host hibernation completed\n");
  73878. + // Exit from case statement
  73879. + break;
  73880. +
  73881. + }
  73882. + if (dwc_otg_hcd_otg_port(dwc_otg_hcd) == wIndex &&
  73883. + dwc_otg_hcd->fops->get_b_hnp_enable(dwc_otg_hcd)) {
  73884. + gotgctl_data_t gotgctl = {.d32 = 0 };
  73885. + gotgctl.b.hstsethnpen = 1;
  73886. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  73887. + gotgctl, 0, gotgctl.d32);
  73888. + core_if->op_state = A_SUSPEND;
  73889. + }
  73890. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  73891. + hprt0.b.prtsusp = 1;
  73892. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  73893. + {
  73894. + dwc_irqflags_t flags;
  73895. + /* Update lx_state */
  73896. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  73897. + core_if->lx_state = DWC_OTG_L2;
  73898. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  73899. + }
  73900. + /* Suspend the Phy Clock */
  73901. + {
  73902. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  73903. + pcgcctl.b.stoppclk = 1;
  73904. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  73905. + pcgcctl.d32);
  73906. + dwc_udelay(10);
  73907. + }
  73908. +
  73909. + /* For HNP the bus must be suspended for at least 200ms. */
  73910. + if (dwc_otg_hcd->fops->get_b_hnp_enable(dwc_otg_hcd)) {
  73911. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  73912. + pcgcctl.b.stoppclk = 1;
  73913. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  73914. + dwc_mdelay(200);
  73915. + }
  73916. +
  73917. + /** @todo - check how sw can wait for 1 sec to check asesvld??? */
  73918. +#if 0 //vahrama !!!!!!!!!!!!!!!!!!
  73919. + if (core_if->adp_enable) {
  73920. + gotgctl_data_t gotgctl = {.d32 = 0 };
  73921. + gpwrdn_data_t gpwrdn;
  73922. +
  73923. + while (gotgctl.b.asesvld == 1) {
  73924. + gotgctl.d32 =
  73925. + DWC_READ_REG32(&core_if->
  73926. + core_global_regs->
  73927. + gotgctl);
  73928. + dwc_mdelay(100);
  73929. + }
  73930. +
  73931. + /* Enable Power Down Logic */
  73932. + gpwrdn.d32 = 0;
  73933. + gpwrdn.b.pmuactv = 1;
  73934. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  73935. + gpwrdn, 0, gpwrdn.d32);
  73936. +
  73937. + /* Unmask SRP detected interrupt from Power Down Logic */
  73938. + gpwrdn.d32 = 0;
  73939. + gpwrdn.b.srp_det_msk = 1;
  73940. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  73941. + gpwrdn, 0, gpwrdn.d32);
  73942. +
  73943. + dwc_otg_adp_probe_start(core_if);
  73944. + }
  73945. +#endif
  73946. + break;
  73947. + case UHF_PORT_POWER:
  73948. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  73949. + "SetPortFeature - USB_PORT_FEAT_POWER\n");
  73950. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  73951. + hprt0.b.prtpwr = 1;
  73952. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  73953. + break;
  73954. + case UHF_PORT_RESET:
  73955. + if ((core_if->power_down == 2)
  73956. + && (core_if->hibernation_suspend == 1)) {
  73957. + /* If we are going to exit from Hibernated
  73958. + * state via USB RESET.
  73959. + */
  73960. + dwc_otg_host_hibernation_restore(core_if, 0, 1);
  73961. + } else {
  73962. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  73963. +
  73964. + DWC_DEBUGPL(DBG_HCD,
  73965. + "DWC OTG HCD HUB CONTROL - "
  73966. + "SetPortFeature - USB_PORT_FEAT_RESET\n");
  73967. + {
  73968. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  73969. + pcgcctl.b.enbl_sleep_gating = 1;
  73970. + pcgcctl.b.stoppclk = 1;
  73971. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  73972. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  73973. + }
  73974. +#ifdef CONFIG_USB_DWC_OTG_LPM
  73975. + {
  73976. + glpmcfg_data_t lpmcfg;
  73977. + lpmcfg.d32 =
  73978. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  73979. + if (lpmcfg.b.prt_sleep_sts) {
  73980. + lpmcfg.b.en_utmi_sleep = 0;
  73981. + lpmcfg.b.hird_thres &= (~(1 << 4));
  73982. + DWC_WRITE_REG32
  73983. + (&core_if->core_global_regs->glpmcfg,
  73984. + lpmcfg.d32);
  73985. + dwc_mdelay(1);
  73986. + }
  73987. + }
  73988. +#endif
  73989. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  73990. + /* Clear suspend bit if resetting from suspended state. */
  73991. + hprt0.b.prtsusp = 0;
  73992. + /* When B-Host the Port reset bit is set in
  73993. + * the Start HCD Callback function, so that
  73994. + * the reset is started within 1ms of the HNP
  73995. + * success interrupt. */
  73996. + if (!dwc_otg_hcd_is_b_host(dwc_otg_hcd)) {
  73997. + hprt0.b.prtpwr = 1;
  73998. + hprt0.b.prtrst = 1;
  73999. + DWC_PRINTF("Indeed it is in host mode hprt0 = %08x\n",hprt0.d32);
  74000. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  74001. + hprt0.d32);
  74002. + }
  74003. + /* Clear reset bit in 10ms (FS/LS) or 50ms (HS) */
  74004. + dwc_mdelay(60);
  74005. + hprt0.b.prtrst = 0;
  74006. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  74007. + core_if->lx_state = DWC_OTG_L0; /* Now back to the on state */
  74008. + }
  74009. + break;
  74010. +#ifdef DWC_HS_ELECT_TST
  74011. + case UHF_PORT_TEST:
  74012. + {
  74013. + uint32_t t;
  74014. + gintmsk_data_t gintmsk;
  74015. +
  74016. + t = (wIndex >> 8); /* MSB wIndex USB */
  74017. + DWC_DEBUGPL(DBG_HCD,
  74018. + "DWC OTG HCD HUB CONTROL - "
  74019. + "SetPortFeature - USB_PORT_FEAT_TEST %d\n",
  74020. + t);
  74021. + DWC_WARN("USB_PORT_FEAT_TEST %d\n", t);
  74022. + if (t < 6) {
  74023. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  74024. + hprt0.b.prttstctl = t;
  74025. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  74026. + hprt0.d32);
  74027. + } else {
  74028. + /* Setup global vars with reg addresses (quick and
  74029. + * dirty hack, should be cleaned up)
  74030. + */
  74031. + global_regs = core_if->core_global_regs;
  74032. + hc_global_regs =
  74033. + core_if->host_if->host_global_regs;
  74034. + hc_regs =
  74035. + (dwc_otg_hc_regs_t *) ((char *)
  74036. + global_regs +
  74037. + 0x500);
  74038. + data_fifo =
  74039. + (uint32_t *) ((char *)global_regs +
  74040. + 0x1000);
  74041. +
  74042. + if (t == 6) { /* HS_HOST_PORT_SUSPEND_RESUME */
  74043. + /* Save current interrupt mask */
  74044. + gintmsk.d32 =
  74045. + DWC_READ_REG32
  74046. + (&global_regs->gintmsk);
  74047. +
  74048. + /* Disable all interrupts while we muck with
  74049. + * the hardware directly
  74050. + */
  74051. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  74052. +
  74053. + /* 15 second delay per the test spec */
  74054. + dwc_mdelay(15000);
  74055. +
  74056. + /* Drive suspend on the root port */
  74057. + hprt0.d32 =
  74058. + dwc_otg_read_hprt0(core_if);
  74059. + hprt0.b.prtsusp = 1;
  74060. + hprt0.b.prtres = 0;
  74061. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  74062. +
  74063. + /* 15 second delay per the test spec */
  74064. + dwc_mdelay(15000);
  74065. +
  74066. + /* Drive resume on the root port */
  74067. + hprt0.d32 =
  74068. + dwc_otg_read_hprt0(core_if);
  74069. + hprt0.b.prtsusp = 0;
  74070. + hprt0.b.prtres = 1;
  74071. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  74072. + dwc_mdelay(100);
  74073. +
  74074. + /* Clear the resume bit */
  74075. + hprt0.b.prtres = 0;
  74076. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  74077. +
  74078. + /* Restore interrupts */
  74079. + DWC_WRITE_REG32(&global_regs->gintmsk, gintmsk.d32);
  74080. + } else if (t == 7) { /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup */
  74081. + /* Save current interrupt mask */
  74082. + gintmsk.d32 =
  74083. + DWC_READ_REG32
  74084. + (&global_regs->gintmsk);
  74085. +
  74086. + /* Disable all interrupts while we muck with
  74087. + * the hardware directly
  74088. + */
  74089. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  74090. +
  74091. + /* 15 second delay per the test spec */
  74092. + dwc_mdelay(15000);
  74093. +
  74094. + /* Send the Setup packet */
  74095. + do_setup();
  74096. +
  74097. + /* 15 second delay so nothing else happens for awhile */
  74098. + dwc_mdelay(15000);
  74099. +
  74100. + /* Restore interrupts */
  74101. + DWC_WRITE_REG32(&global_regs->gintmsk, gintmsk.d32);
  74102. + } else if (t == 8) { /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute */
  74103. + /* Save current interrupt mask */
  74104. + gintmsk.d32 =
  74105. + DWC_READ_REG32
  74106. + (&global_regs->gintmsk);
  74107. +
  74108. + /* Disable all interrupts while we muck with
  74109. + * the hardware directly
  74110. + */
  74111. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  74112. +
  74113. + /* Send the Setup packet */
  74114. + do_setup();
  74115. +
  74116. + /* 15 second delay so nothing else happens for awhile */
  74117. + dwc_mdelay(15000);
  74118. +
  74119. + /* Send the In and Ack packets */
  74120. + do_in_ack();
  74121. +
  74122. + /* 15 second delay so nothing else happens for awhile */
  74123. + dwc_mdelay(15000);
  74124. +
  74125. + /* Restore interrupts */
  74126. + DWC_WRITE_REG32(&global_regs->gintmsk, gintmsk.d32);
  74127. + }
  74128. + }
  74129. + break;
  74130. + }
  74131. +#endif /* DWC_HS_ELECT_TST */
  74132. +
  74133. + case UHF_PORT_INDICATOR:
  74134. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  74135. + "SetPortFeature - USB_PORT_FEAT_INDICATOR\n");
  74136. + /* Not supported */
  74137. + break;
  74138. + default:
  74139. + retval = -DWC_E_INVALID;
  74140. + DWC_ERROR("DWC OTG HCD - "
  74141. + "SetPortFeature request %xh "
  74142. + "unknown or unsupported\n", wValue);
  74143. + break;
  74144. + }
  74145. + break;
  74146. +#ifdef CONFIG_USB_DWC_OTG_LPM
  74147. + case UCR_SET_AND_TEST_PORT_FEATURE:
  74148. + if (wValue != UHF_PORT_L1) {
  74149. + goto error;
  74150. + }
  74151. + {
  74152. + int portnum, hird, devaddr, remwake;
  74153. + glpmcfg_data_t lpmcfg;
  74154. + uint32_t time_usecs;
  74155. + gintsts_data_t gintsts;
  74156. + gintmsk_data_t gintmsk;
  74157. +
  74158. + if (!dwc_otg_get_param_lpm_enable(core_if)) {
  74159. + goto error;
  74160. + }
  74161. + if (wValue != UHF_PORT_L1 || wLength != 1) {
  74162. + goto error;
  74163. + }
  74164. + /* Check if the port currently is in SLEEP state */
  74165. + lpmcfg.d32 =
  74166. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  74167. + if (lpmcfg.b.prt_sleep_sts) {
  74168. + DWC_INFO("Port is already in sleep mode\n");
  74169. + buf[0] = 0; /* Return success */
  74170. + break;
  74171. + }
  74172. +
  74173. + portnum = wIndex & 0xf;
  74174. + hird = (wIndex >> 4) & 0xf;
  74175. + devaddr = (wIndex >> 8) & 0x7f;
  74176. + remwake = (wIndex >> 15);
  74177. +
  74178. + if (portnum != 1) {
  74179. + retval = -DWC_E_INVALID;
  74180. + DWC_WARN
  74181. + ("Wrong port number(%d) in SetandTestPortFeature request\n",
  74182. + portnum);
  74183. + break;
  74184. + }
  74185. +
  74186. + DWC_PRINTF
  74187. + ("SetandTestPortFeature request: portnum = %d, hird = %d, devaddr = %d, rewake = %d\n",
  74188. + portnum, hird, devaddr, remwake);
  74189. + /* Disable LPM interrupt */
  74190. + gintmsk.d32 = 0;
  74191. + gintmsk.b.lpmtranrcvd = 1;
  74192. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  74193. + gintmsk.d32, 0);
  74194. +
  74195. + if (dwc_otg_hcd_send_lpm
  74196. + (dwc_otg_hcd, devaddr, hird, remwake)) {
  74197. + retval = -DWC_E_INVALID;
  74198. + break;
  74199. + }
  74200. +
  74201. + time_usecs = 10 * (lpmcfg.b.retry_count + 1);
  74202. + /* We will consider timeout if time_usecs microseconds pass,
  74203. + * and we don't receive LPM transaction status.
  74204. + * After receiving non-error responce(ACK/NYET/STALL) from device,
  74205. + * core will set lpmtranrcvd bit.
  74206. + */
  74207. + do {
  74208. + gintsts.d32 =
  74209. + DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  74210. + if (gintsts.b.lpmtranrcvd) {
  74211. + break;
  74212. + }
  74213. + dwc_udelay(1);
  74214. + } while (--time_usecs);
  74215. + /* lpm_int bit will be cleared in LPM interrupt handler */
  74216. +
  74217. + /* Now fill status
  74218. + * 0x00 - Success
  74219. + * 0x10 - NYET
  74220. + * 0x11 - Timeout
  74221. + */
  74222. + if (!gintsts.b.lpmtranrcvd) {
  74223. + buf[0] = 0x3; /* Completion code is Timeout */
  74224. + dwc_otg_hcd_free_hc_from_lpm(dwc_otg_hcd);
  74225. + } else {
  74226. + lpmcfg.d32 =
  74227. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  74228. + if (lpmcfg.b.lpm_resp == 0x3) {
  74229. + /* ACK responce from the device */
  74230. + buf[0] = 0x00; /* Success */
  74231. + } else if (lpmcfg.b.lpm_resp == 0x2) {
  74232. + /* NYET responce from the device */
  74233. + buf[0] = 0x2;
  74234. + } else {
  74235. + /* Otherwise responce with Timeout */
  74236. + buf[0] = 0x3;
  74237. + }
  74238. + }
  74239. + DWC_PRINTF("Device responce to LPM trans is %x\n",
  74240. + lpmcfg.b.lpm_resp);
  74241. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0,
  74242. + gintmsk.d32);
  74243. +
  74244. + break;
  74245. + }
  74246. +#endif /* CONFIG_USB_DWC_OTG_LPM */
  74247. + default:
  74248. +error:
  74249. + retval = -DWC_E_INVALID;
  74250. + DWC_WARN("DWC OTG HCD - "
  74251. + "Unknown hub control request type or invalid typeReq: %xh wIndex: %xh wValue: %xh\n",
  74252. + typeReq, wIndex, wValue);
  74253. + break;
  74254. + }
  74255. +
  74256. + return retval;
  74257. +}
  74258. +
  74259. +#ifdef CONFIG_USB_DWC_OTG_LPM
  74260. +/** Returns index of host channel to perform LPM transaction. */
  74261. +int dwc_otg_hcd_get_hc_for_lpm_tran(dwc_otg_hcd_t * hcd, uint8_t devaddr)
  74262. +{
  74263. + dwc_otg_core_if_t *core_if = hcd->core_if;
  74264. + dwc_hc_t *hc;
  74265. + hcchar_data_t hcchar;
  74266. + gintmsk_data_t gintmsk = {.d32 = 0 };
  74267. +
  74268. + if (DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
  74269. + DWC_PRINTF("No free channel to select for LPM transaction\n");
  74270. + return -1;
  74271. + }
  74272. +
  74273. + hc = DWC_CIRCLEQ_FIRST(&hcd->free_hc_list);
  74274. +
  74275. + /* Mask host channel interrupts. */
  74276. + gintmsk.b.hcintr = 1;
  74277. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32, 0);
  74278. +
  74279. + /* Fill fields that core needs for LPM transaction */
  74280. + hcchar.b.devaddr = devaddr;
  74281. + hcchar.b.epnum = 0;
  74282. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  74283. + hcchar.b.mps = 64;
  74284. + hcchar.b.lspddev = (hc->speed == DWC_OTG_EP_SPEED_LOW);
  74285. + hcchar.b.epdir = 0; /* OUT */
  74286. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[hc->hc_num]->hcchar,
  74287. + hcchar.d32);
  74288. +
  74289. + /* Remove the host channel from the free list. */
  74290. + DWC_CIRCLEQ_REMOVE_INIT(&hcd->free_hc_list, hc, hc_list_entry);
  74291. +
  74292. + DWC_PRINTF("hcnum = %d devaddr = %d\n", hc->hc_num, devaddr);
  74293. +
  74294. + return hc->hc_num;
  74295. +}
  74296. +
  74297. +/** Release hc after performing LPM transaction */
  74298. +void dwc_otg_hcd_free_hc_from_lpm(dwc_otg_hcd_t * hcd)
  74299. +{
  74300. + dwc_hc_t *hc;
  74301. + glpmcfg_data_t lpmcfg;
  74302. + uint8_t hc_num;
  74303. +
  74304. + lpmcfg.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->glpmcfg);
  74305. + hc_num = lpmcfg.b.lpm_chan_index;
  74306. +
  74307. + hc = hcd->hc_ptr_array[hc_num];
  74308. +
  74309. + DWC_PRINTF("Freeing channel %d after LPM\n", hc_num);
  74310. + /* Return host channel to free list */
  74311. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, hc, hc_list_entry);
  74312. +}
  74313. +
  74314. +int dwc_otg_hcd_send_lpm(dwc_otg_hcd_t * hcd, uint8_t devaddr, uint8_t hird,
  74315. + uint8_t bRemoteWake)
  74316. +{
  74317. + glpmcfg_data_t lpmcfg;
  74318. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  74319. + int channel;
  74320. +
  74321. + channel = dwc_otg_hcd_get_hc_for_lpm_tran(hcd, devaddr);
  74322. + if (channel < 0) {
  74323. + return channel;
  74324. + }
  74325. +
  74326. + pcgcctl.b.enbl_sleep_gating = 1;
  74327. + DWC_MODIFY_REG32(hcd->core_if->pcgcctl, 0, pcgcctl.d32);
  74328. +
  74329. + /* Read LPM config register */
  74330. + lpmcfg.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->glpmcfg);
  74331. +
  74332. + /* Program LPM transaction fields */
  74333. + lpmcfg.b.rem_wkup_en = bRemoteWake;
  74334. + lpmcfg.b.hird = hird;
  74335. + lpmcfg.b.hird_thres = 0x1c;
  74336. + lpmcfg.b.lpm_chan_index = channel;
  74337. + lpmcfg.b.en_utmi_sleep = 1;
  74338. + /* Program LPM config register */
  74339. + DWC_WRITE_REG32(&hcd->core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  74340. +
  74341. + /* Send LPM transaction */
  74342. + lpmcfg.b.send_lpm = 1;
  74343. + DWC_WRITE_REG32(&hcd->core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  74344. +
  74345. + return 0;
  74346. +}
  74347. +
  74348. +#endif /* CONFIG_USB_DWC_OTG_LPM */
  74349. +
  74350. +int dwc_otg_hcd_is_status_changed(dwc_otg_hcd_t * hcd, int port)
  74351. +{
  74352. + int retval;
  74353. +
  74354. + if (port != 1) {
  74355. + return -DWC_E_INVALID;
  74356. + }
  74357. +
  74358. + retval = (hcd->flags.b.port_connect_status_change ||
  74359. + hcd->flags.b.port_reset_change ||
  74360. + hcd->flags.b.port_enable_change ||
  74361. + hcd->flags.b.port_suspend_change ||
  74362. + hcd->flags.b.port_over_current_change);
  74363. +#ifdef DEBUG
  74364. + if (retval) {
  74365. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB STATUS DATA:"
  74366. + " Root port status changed\n");
  74367. + DWC_DEBUGPL(DBG_HCDV, " port_connect_status_change: %d\n",
  74368. + hcd->flags.b.port_connect_status_change);
  74369. + DWC_DEBUGPL(DBG_HCDV, " port_reset_change: %d\n",
  74370. + hcd->flags.b.port_reset_change);
  74371. + DWC_DEBUGPL(DBG_HCDV, " port_enable_change: %d\n",
  74372. + hcd->flags.b.port_enable_change);
  74373. + DWC_DEBUGPL(DBG_HCDV, " port_suspend_change: %d\n",
  74374. + hcd->flags.b.port_suspend_change);
  74375. + DWC_DEBUGPL(DBG_HCDV, " port_over_current_change: %d\n",
  74376. + hcd->flags.b.port_over_current_change);
  74377. + }
  74378. +#endif
  74379. + return retval;
  74380. +}
  74381. +
  74382. +int dwc_otg_hcd_get_frame_number(dwc_otg_hcd_t * dwc_otg_hcd)
  74383. +{
  74384. + hfnum_data_t hfnum;
  74385. + hfnum.d32 =
  74386. + DWC_READ_REG32(&dwc_otg_hcd->core_if->host_if->host_global_regs->
  74387. + hfnum);
  74388. +
  74389. +#ifdef DEBUG_SOF
  74390. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD GET FRAME NUMBER %d\n",
  74391. + hfnum.b.frnum);
  74392. +#endif
  74393. + return hfnum.b.frnum;
  74394. +}
  74395. +
  74396. +int dwc_otg_hcd_start(dwc_otg_hcd_t * hcd,
  74397. + struct dwc_otg_hcd_function_ops *fops)
  74398. +{
  74399. + int retval = 0;
  74400. +
  74401. + hcd->fops = fops;
  74402. + if (!dwc_otg_is_device_mode(hcd->core_if) &&
  74403. + (!hcd->core_if->adp_enable || hcd->core_if->adp.adp_started)) {
  74404. + dwc_otg_hcd_reinit(hcd);
  74405. + } else {
  74406. + retval = -DWC_E_NO_DEVICE;
  74407. + }
  74408. +
  74409. + return retval;
  74410. +}
  74411. +
  74412. +void *dwc_otg_hcd_get_priv_data(dwc_otg_hcd_t * hcd)
  74413. +{
  74414. + return hcd->priv;
  74415. +}
  74416. +
  74417. +void dwc_otg_hcd_set_priv_data(dwc_otg_hcd_t * hcd, void *priv_data)
  74418. +{
  74419. + hcd->priv = priv_data;
  74420. +}
  74421. +
  74422. +uint32_t dwc_otg_hcd_otg_port(dwc_otg_hcd_t * hcd)
  74423. +{
  74424. + return hcd->otg_port;
  74425. +}
  74426. +
  74427. +uint32_t dwc_otg_hcd_is_b_host(dwc_otg_hcd_t * hcd)
  74428. +{
  74429. + uint32_t is_b_host;
  74430. + if (hcd->core_if->op_state == B_HOST) {
  74431. + is_b_host = 1;
  74432. + } else {
  74433. + is_b_host = 0;
  74434. + }
  74435. +
  74436. + return is_b_host;
  74437. +}
  74438. +
  74439. +dwc_otg_hcd_urb_t *dwc_otg_hcd_urb_alloc(dwc_otg_hcd_t * hcd,
  74440. + int iso_desc_count, int atomic_alloc)
  74441. +{
  74442. + dwc_otg_hcd_urb_t *dwc_otg_urb;
  74443. + uint32_t size;
  74444. +
  74445. + size =
  74446. + sizeof(*dwc_otg_urb) +
  74447. + iso_desc_count * sizeof(struct dwc_otg_hcd_iso_packet_desc);
  74448. + if (atomic_alloc)
  74449. + dwc_otg_urb = DWC_ALLOC_ATOMIC(size);
  74450. + else
  74451. + dwc_otg_urb = DWC_ALLOC(size);
  74452. +
  74453. + if (dwc_otg_urb)
  74454. + dwc_otg_urb->packet_count = iso_desc_count;
  74455. + else {
  74456. + DWC_ERROR("**** DWC OTG HCD URB alloc - "
  74457. + "%salloc of %db failed\n",
  74458. + atomic_alloc?"atomic ":"", size);
  74459. + }
  74460. + return dwc_otg_urb;
  74461. +}
  74462. +
  74463. +void dwc_otg_hcd_urb_set_pipeinfo(dwc_otg_hcd_urb_t * dwc_otg_urb,
  74464. + uint8_t dev_addr, uint8_t ep_num,
  74465. + uint8_t ep_type, uint8_t ep_dir, uint16_t mps)
  74466. +{
  74467. + dwc_otg_hcd_fill_pipe(&dwc_otg_urb->pipe_info, dev_addr, ep_num,
  74468. + ep_type, ep_dir, mps);
  74469. +#if 0
  74470. + DWC_PRINTF
  74471. + ("addr = %d, ep_num = %d, ep_dir = 0x%x, ep_type = 0x%x, mps = %d\n",
  74472. + dev_addr, ep_num, ep_dir, ep_type, mps);
  74473. +#endif
  74474. +}
  74475. +
  74476. +void dwc_otg_hcd_urb_set_params(dwc_otg_hcd_urb_t * dwc_otg_urb,
  74477. + void *urb_handle, void *buf, dwc_dma_t dma,
  74478. + uint32_t buflen, void *setup_packet,
  74479. + dwc_dma_t setup_dma, uint32_t flags,
  74480. + uint16_t interval)
  74481. +{
  74482. + dwc_otg_urb->priv = urb_handle;
  74483. + dwc_otg_urb->buf = buf;
  74484. + dwc_otg_urb->dma = dma;
  74485. + dwc_otg_urb->length = buflen;
  74486. + dwc_otg_urb->setup_packet = setup_packet;
  74487. + dwc_otg_urb->setup_dma = setup_dma;
  74488. + dwc_otg_urb->flags = flags;
  74489. + dwc_otg_urb->interval = interval;
  74490. + dwc_otg_urb->status = -DWC_E_IN_PROGRESS;
  74491. +}
  74492. +
  74493. +uint32_t dwc_otg_hcd_urb_get_status(dwc_otg_hcd_urb_t * dwc_otg_urb)
  74494. +{
  74495. + return dwc_otg_urb->status;
  74496. +}
  74497. +
  74498. +uint32_t dwc_otg_hcd_urb_get_actual_length(dwc_otg_hcd_urb_t * dwc_otg_urb)
  74499. +{
  74500. + return dwc_otg_urb->actual_length;
  74501. +}
  74502. +
  74503. +uint32_t dwc_otg_hcd_urb_get_error_count(dwc_otg_hcd_urb_t * dwc_otg_urb)
  74504. +{
  74505. + return dwc_otg_urb->error_count;
  74506. +}
  74507. +
  74508. +void dwc_otg_hcd_urb_set_iso_desc_params(dwc_otg_hcd_urb_t * dwc_otg_urb,
  74509. + int desc_num, uint32_t offset,
  74510. + uint32_t length)
  74511. +{
  74512. + dwc_otg_urb->iso_descs[desc_num].offset = offset;
  74513. + dwc_otg_urb->iso_descs[desc_num].length = length;
  74514. +}
  74515. +
  74516. +uint32_t dwc_otg_hcd_urb_get_iso_desc_status(dwc_otg_hcd_urb_t * dwc_otg_urb,
  74517. + int desc_num)
  74518. +{
  74519. + return dwc_otg_urb->iso_descs[desc_num].status;
  74520. +}
  74521. +
  74522. +uint32_t dwc_otg_hcd_urb_get_iso_desc_actual_length(dwc_otg_hcd_urb_t *
  74523. + dwc_otg_urb, int desc_num)
  74524. +{
  74525. + return dwc_otg_urb->iso_descs[desc_num].actual_length;
  74526. +}
  74527. +
  74528. +int dwc_otg_hcd_is_bandwidth_allocated(dwc_otg_hcd_t * hcd, void *ep_handle)
  74529. +{
  74530. + int allocated = 0;
  74531. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  74532. +
  74533. + if (qh) {
  74534. + if (!DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  74535. + allocated = 1;
  74536. + }
  74537. + }
  74538. + return allocated;
  74539. +}
  74540. +
  74541. +int dwc_otg_hcd_is_bandwidth_freed(dwc_otg_hcd_t * hcd, void *ep_handle)
  74542. +{
  74543. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  74544. + int freed = 0;
  74545. + DWC_ASSERT(qh, "qh is not allocated\n");
  74546. +
  74547. + if (DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  74548. + freed = 1;
  74549. + }
  74550. +
  74551. + return freed;
  74552. +}
  74553. +
  74554. +uint8_t dwc_otg_hcd_get_ep_bandwidth(dwc_otg_hcd_t * hcd, void *ep_handle)
  74555. +{
  74556. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  74557. + DWC_ASSERT(qh, "qh is not allocated\n");
  74558. + return qh->usecs;
  74559. +}
  74560. +
  74561. +void dwc_otg_hcd_dump_state(dwc_otg_hcd_t * hcd)
  74562. +{
  74563. +#ifdef DEBUG
  74564. + int num_channels;
  74565. + int i;
  74566. + gnptxsts_data_t np_tx_status;
  74567. + hptxsts_data_t p_tx_status;
  74568. +
  74569. + num_channels = hcd->core_if->core_params->host_channels;
  74570. + DWC_PRINTF("\n");
  74571. + DWC_PRINTF
  74572. + ("************************************************************\n");
  74573. + DWC_PRINTF("HCD State:\n");
  74574. + DWC_PRINTF(" Num channels: %d\n", num_channels);
  74575. + for (i = 0; i < num_channels; i++) {
  74576. + dwc_hc_t *hc = hcd->hc_ptr_array[i];
  74577. + DWC_PRINTF(" Channel %d:\n", i);
  74578. + DWC_PRINTF(" dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
  74579. + hc->dev_addr, hc->ep_num, hc->ep_is_in);
  74580. + DWC_PRINTF(" speed: %d\n", hc->speed);
  74581. + DWC_PRINTF(" ep_type: %d\n", hc->ep_type);
  74582. + DWC_PRINTF(" max_packet: %d\n", hc->max_packet);
  74583. + DWC_PRINTF(" data_pid_start: %d\n", hc->data_pid_start);
  74584. + DWC_PRINTF(" multi_count: %d\n", hc->multi_count);
  74585. + DWC_PRINTF(" xfer_started: %d\n", hc->xfer_started);
  74586. + DWC_PRINTF(" xfer_buff: %p\n", hc->xfer_buff);
  74587. + DWC_PRINTF(" xfer_len: %d\n", hc->xfer_len);
  74588. + DWC_PRINTF(" xfer_count: %d\n", hc->xfer_count);
  74589. + DWC_PRINTF(" halt_on_queue: %d\n", hc->halt_on_queue);
  74590. + DWC_PRINTF(" halt_pending: %d\n", hc->halt_pending);
  74591. + DWC_PRINTF(" halt_status: %d\n", hc->halt_status);
  74592. + DWC_PRINTF(" do_split: %d\n", hc->do_split);
  74593. + DWC_PRINTF(" complete_split: %d\n", hc->complete_split);
  74594. + DWC_PRINTF(" hub_addr: %d\n", hc->hub_addr);
  74595. + DWC_PRINTF(" port_addr: %d\n", hc->port_addr);
  74596. + DWC_PRINTF(" xact_pos: %d\n", hc->xact_pos);
  74597. + DWC_PRINTF(" requests: %d\n", hc->requests);
  74598. + DWC_PRINTF(" qh: %p\n", hc->qh);
  74599. + if (hc->xfer_started) {
  74600. + hfnum_data_t hfnum;
  74601. + hcchar_data_t hcchar;
  74602. + hctsiz_data_t hctsiz;
  74603. + hcint_data_t hcint;
  74604. + hcintmsk_data_t hcintmsk;
  74605. + hfnum.d32 =
  74606. + DWC_READ_REG32(&hcd->core_if->
  74607. + host_if->host_global_regs->hfnum);
  74608. + hcchar.d32 =
  74609. + DWC_READ_REG32(&hcd->core_if->host_if->
  74610. + hc_regs[i]->hcchar);
  74611. + hctsiz.d32 =
  74612. + DWC_READ_REG32(&hcd->core_if->host_if->
  74613. + hc_regs[i]->hctsiz);
  74614. + hcint.d32 =
  74615. + DWC_READ_REG32(&hcd->core_if->host_if->
  74616. + hc_regs[i]->hcint);
  74617. + hcintmsk.d32 =
  74618. + DWC_READ_REG32(&hcd->core_if->host_if->
  74619. + hc_regs[i]->hcintmsk);
  74620. + DWC_PRINTF(" hfnum: 0x%08x\n", hfnum.d32);
  74621. + DWC_PRINTF(" hcchar: 0x%08x\n", hcchar.d32);
  74622. + DWC_PRINTF(" hctsiz: 0x%08x\n", hctsiz.d32);
  74623. + DWC_PRINTF(" hcint: 0x%08x\n", hcint.d32);
  74624. + DWC_PRINTF(" hcintmsk: 0x%08x\n", hcintmsk.d32);
  74625. + }
  74626. + if (hc->xfer_started && hc->qh) {
  74627. + dwc_otg_qtd_t *qtd;
  74628. + dwc_otg_hcd_urb_t *urb;
  74629. +
  74630. + DWC_CIRCLEQ_FOREACH(qtd, &hc->qh->qtd_list, qtd_list_entry) {
  74631. + if (!qtd->in_process)
  74632. + break;
  74633. +
  74634. + urb = qtd->urb;
  74635. + DWC_PRINTF(" URB Info:\n");
  74636. + DWC_PRINTF(" qtd: %p, urb: %p\n", qtd, urb);
  74637. + if (urb) {
  74638. + DWC_PRINTF(" Dev: %d, EP: %d %s\n",
  74639. + dwc_otg_hcd_get_dev_addr(&urb->
  74640. + pipe_info),
  74641. + dwc_otg_hcd_get_ep_num(&urb->
  74642. + pipe_info),
  74643. + dwc_otg_hcd_is_pipe_in(&urb->
  74644. + pipe_info) ?
  74645. + "IN" : "OUT");
  74646. + DWC_PRINTF(" Max packet size: %d\n",
  74647. + dwc_otg_hcd_get_mps(&urb->
  74648. + pipe_info));
  74649. + DWC_PRINTF(" transfer_buffer: %p\n",
  74650. + urb->buf);
  74651. + DWC_PRINTF(" transfer_dma: %p\n",
  74652. + (void *)urb->dma);
  74653. + DWC_PRINTF(" transfer_buffer_length: %d\n",
  74654. + urb->length);
  74655. + DWC_PRINTF(" actual_length: %d\n",
  74656. + urb->actual_length);
  74657. + }
  74658. + }
  74659. + }
  74660. + }
  74661. + DWC_PRINTF(" non_periodic_channels: %d\n", hcd->non_periodic_channels);
  74662. + DWC_PRINTF(" periodic_channels: %d\n", hcd->periodic_channels);
  74663. + DWC_PRINTF(" periodic_usecs: %d\n", hcd->periodic_usecs);
  74664. + np_tx_status.d32 =
  74665. + DWC_READ_REG32(&hcd->core_if->core_global_regs->gnptxsts);
  74666. + DWC_PRINTF(" NP Tx Req Queue Space Avail: %d\n",
  74667. + np_tx_status.b.nptxqspcavail);
  74668. + DWC_PRINTF(" NP Tx FIFO Space Avail: %d\n",
  74669. + np_tx_status.b.nptxfspcavail);
  74670. + p_tx_status.d32 =
  74671. + DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hptxsts);
  74672. + DWC_PRINTF(" P Tx Req Queue Space Avail: %d\n",
  74673. + p_tx_status.b.ptxqspcavail);
  74674. + DWC_PRINTF(" P Tx FIFO Space Avail: %d\n", p_tx_status.b.ptxfspcavail);
  74675. + dwc_otg_hcd_dump_frrem(hcd);
  74676. + dwc_otg_dump_global_registers(hcd->core_if);
  74677. + dwc_otg_dump_host_registers(hcd->core_if);
  74678. + DWC_PRINTF
  74679. + ("************************************************************\n");
  74680. + DWC_PRINTF("\n");
  74681. +#endif
  74682. +}
  74683. +
  74684. +#ifdef DEBUG
  74685. +void dwc_print_setup_data(uint8_t * setup)
  74686. +{
  74687. + int i;
  74688. + if (CHK_DEBUG_LEVEL(DBG_HCD)) {
  74689. + DWC_PRINTF("Setup Data = MSB ");
  74690. + for (i = 7; i >= 0; i--)
  74691. + DWC_PRINTF("%02x ", setup[i]);
  74692. + DWC_PRINTF("\n");
  74693. + DWC_PRINTF(" bmRequestType Tranfer = %s\n",
  74694. + (setup[0] & 0x80) ? "Device-to-Host" :
  74695. + "Host-to-Device");
  74696. + DWC_PRINTF(" bmRequestType Type = ");
  74697. + switch ((setup[0] & 0x60) >> 5) {
  74698. + case 0:
  74699. + DWC_PRINTF("Standard\n");
  74700. + break;
  74701. + case 1:
  74702. + DWC_PRINTF("Class\n");
  74703. + break;
  74704. + case 2:
  74705. + DWC_PRINTF("Vendor\n");
  74706. + break;
  74707. + case 3:
  74708. + DWC_PRINTF("Reserved\n");
  74709. + break;
  74710. + }
  74711. + DWC_PRINTF(" bmRequestType Recipient = ");
  74712. + switch (setup[0] & 0x1f) {
  74713. + case 0:
  74714. + DWC_PRINTF("Device\n");
  74715. + break;
  74716. + case 1:
  74717. + DWC_PRINTF("Interface\n");
  74718. + break;
  74719. + case 2:
  74720. + DWC_PRINTF("Endpoint\n");
  74721. + break;
  74722. + case 3:
  74723. + DWC_PRINTF("Other\n");
  74724. + break;
  74725. + default:
  74726. + DWC_PRINTF("Reserved\n");
  74727. + break;
  74728. + }
  74729. + DWC_PRINTF(" bRequest = 0x%0x\n", setup[1]);
  74730. + DWC_PRINTF(" wValue = 0x%0x\n", *((uint16_t *) & setup[2]));
  74731. + DWC_PRINTF(" wIndex = 0x%0x\n", *((uint16_t *) & setup[4]));
  74732. + DWC_PRINTF(" wLength = 0x%0x\n\n", *((uint16_t *) & setup[6]));
  74733. + }
  74734. +}
  74735. +#endif
  74736. +
  74737. +void dwc_otg_hcd_dump_frrem(dwc_otg_hcd_t * hcd)
  74738. +{
  74739. +#if 0
  74740. + DWC_PRINTF("Frame remaining at SOF:\n");
  74741. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  74742. + hcd->frrem_samples, hcd->frrem_accum,
  74743. + (hcd->frrem_samples > 0) ?
  74744. + hcd->frrem_accum / hcd->frrem_samples : 0);
  74745. +
  74746. + DWC_PRINTF("\n");
  74747. + DWC_PRINTF("Frame remaining at start_transfer (uframe 7):\n");
  74748. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  74749. + hcd->core_if->hfnum_7_samples,
  74750. + hcd->core_if->hfnum_7_frrem_accum,
  74751. + (hcd->core_if->hfnum_7_samples >
  74752. + 0) ? hcd->core_if->hfnum_7_frrem_accum /
  74753. + hcd->core_if->hfnum_7_samples : 0);
  74754. + DWC_PRINTF("Frame remaining at start_transfer (uframe 0):\n");
  74755. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  74756. + hcd->core_if->hfnum_0_samples,
  74757. + hcd->core_if->hfnum_0_frrem_accum,
  74758. + (hcd->core_if->hfnum_0_samples >
  74759. + 0) ? hcd->core_if->hfnum_0_frrem_accum /
  74760. + hcd->core_if->hfnum_0_samples : 0);
  74761. + DWC_PRINTF("Frame remaining at start_transfer (uframe 1-6):\n");
  74762. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  74763. + hcd->core_if->hfnum_other_samples,
  74764. + hcd->core_if->hfnum_other_frrem_accum,
  74765. + (hcd->core_if->hfnum_other_samples >
  74766. + 0) ? hcd->core_if->hfnum_other_frrem_accum /
  74767. + hcd->core_if->hfnum_other_samples : 0);
  74768. +
  74769. + DWC_PRINTF("\n");
  74770. + DWC_PRINTF("Frame remaining at sample point A (uframe 7):\n");
  74771. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  74772. + hcd->hfnum_7_samples_a, hcd->hfnum_7_frrem_accum_a,
  74773. + (hcd->hfnum_7_samples_a > 0) ?
  74774. + hcd->hfnum_7_frrem_accum_a / hcd->hfnum_7_samples_a : 0);
  74775. + DWC_PRINTF("Frame remaining at sample point A (uframe 0):\n");
  74776. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  74777. + hcd->hfnum_0_samples_a, hcd->hfnum_0_frrem_accum_a,
  74778. + (hcd->hfnum_0_samples_a > 0) ?
  74779. + hcd->hfnum_0_frrem_accum_a / hcd->hfnum_0_samples_a : 0);
  74780. + DWC_PRINTF("Frame remaining at sample point A (uframe 1-6):\n");
  74781. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  74782. + hcd->hfnum_other_samples_a, hcd->hfnum_other_frrem_accum_a,
  74783. + (hcd->hfnum_other_samples_a > 0) ?
  74784. + hcd->hfnum_other_frrem_accum_a /
  74785. + hcd->hfnum_other_samples_a : 0);
  74786. +
  74787. + DWC_PRINTF("\n");
  74788. + DWC_PRINTF("Frame remaining at sample point B (uframe 7):\n");
  74789. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  74790. + hcd->hfnum_7_samples_b, hcd->hfnum_7_frrem_accum_b,
  74791. + (hcd->hfnum_7_samples_b > 0) ?
  74792. + hcd->hfnum_7_frrem_accum_b / hcd->hfnum_7_samples_b : 0);
  74793. + DWC_PRINTF("Frame remaining at sample point B (uframe 0):\n");
  74794. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  74795. + hcd->hfnum_0_samples_b, hcd->hfnum_0_frrem_accum_b,
  74796. + (hcd->hfnum_0_samples_b > 0) ?
  74797. + hcd->hfnum_0_frrem_accum_b / hcd->hfnum_0_samples_b : 0);
  74798. + DWC_PRINTF("Frame remaining at sample point B (uframe 1-6):\n");
  74799. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  74800. + hcd->hfnum_other_samples_b, hcd->hfnum_other_frrem_accum_b,
  74801. + (hcd->hfnum_other_samples_b > 0) ?
  74802. + hcd->hfnum_other_frrem_accum_b /
  74803. + hcd->hfnum_other_samples_b : 0);
  74804. +#endif
  74805. +}
  74806. +
  74807. +#endif /* DWC_DEVICE_ONLY */
  74808. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c
  74809. --- linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c 1970-01-01 01:00:00.000000000 +0100
  74810. +++ linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c 2014-08-06 16:50:14.813964820 +0200
  74811. @@ -0,0 +1,1132 @@
  74812. +/*==========================================================================
  74813. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_ddma.c $
  74814. + * $Revision: #10 $
  74815. + * $Date: 2011/10/20 $
  74816. + * $Change: 1869464 $
  74817. + *
  74818. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  74819. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  74820. + * otherwise expressly agreed to in writing between Synopsys and you.
  74821. + *
  74822. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  74823. + * any End User Software License Agreement or Agreement for Licensed Product
  74824. + * with Synopsys or any supplement thereto. You are permitted to use and
  74825. + * redistribute this Software in source and binary forms, with or without
  74826. + * modification, provided that redistributions of source code must retain this
  74827. + * notice. You may not view, use, disclose, copy or distribute this file or
  74828. + * any information contained herein except pursuant to this license grant from
  74829. + * Synopsys. If you do not agree with this notice, including the disclaimer
  74830. + * below, then you are not authorized to use the Software.
  74831. + *
  74832. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  74833. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  74834. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  74835. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  74836. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  74837. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  74838. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  74839. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  74840. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  74841. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  74842. + * DAMAGE.
  74843. + * ========================================================================== */
  74844. +#ifndef DWC_DEVICE_ONLY
  74845. +
  74846. +/** @file
  74847. + * This file contains Descriptor DMA support implementation for host mode.
  74848. + */
  74849. +
  74850. +#include "dwc_otg_hcd.h"
  74851. +#include "dwc_otg_regs.h"
  74852. +
  74853. +extern bool microframe_schedule;
  74854. +
  74855. +static inline uint8_t frame_list_idx(uint16_t frame)
  74856. +{
  74857. + return (frame & (MAX_FRLIST_EN_NUM - 1));
  74858. +}
  74859. +
  74860. +static inline uint16_t desclist_idx_inc(uint16_t idx, uint16_t inc, uint8_t speed)
  74861. +{
  74862. + return (idx + inc) &
  74863. + (((speed ==
  74864. + DWC_OTG_EP_SPEED_HIGH) ? MAX_DMA_DESC_NUM_HS_ISOC :
  74865. + MAX_DMA_DESC_NUM_GENERIC) - 1);
  74866. +}
  74867. +
  74868. +static inline uint16_t desclist_idx_dec(uint16_t idx, uint16_t inc, uint8_t speed)
  74869. +{
  74870. + return (idx - inc) &
  74871. + (((speed ==
  74872. + DWC_OTG_EP_SPEED_HIGH) ? MAX_DMA_DESC_NUM_HS_ISOC :
  74873. + MAX_DMA_DESC_NUM_GENERIC) - 1);
  74874. +}
  74875. +
  74876. +static inline uint16_t max_desc_num(dwc_otg_qh_t * qh)
  74877. +{
  74878. + return (((qh->ep_type == UE_ISOCHRONOUS)
  74879. + && (qh->dev_speed == DWC_OTG_EP_SPEED_HIGH))
  74880. + ? MAX_DMA_DESC_NUM_HS_ISOC : MAX_DMA_DESC_NUM_GENERIC);
  74881. +}
  74882. +static inline uint16_t frame_incr_val(dwc_otg_qh_t * qh)
  74883. +{
  74884. + return ((qh->dev_speed == DWC_OTG_EP_SPEED_HIGH)
  74885. + ? ((qh->interval + 8 - 1) / 8)
  74886. + : qh->interval);
  74887. +}
  74888. +
  74889. +static int desc_list_alloc(dwc_otg_qh_t * qh)
  74890. +{
  74891. + int retval = 0;
  74892. +
  74893. + qh->desc_list = (dwc_otg_host_dma_desc_t *)
  74894. + DWC_DMA_ALLOC(sizeof(dwc_otg_host_dma_desc_t) * max_desc_num(qh),
  74895. + &qh->desc_list_dma);
  74896. +
  74897. + if (!qh->desc_list) {
  74898. + retval = -DWC_E_NO_MEMORY;
  74899. + DWC_ERROR("%s: DMA descriptor list allocation failed\n", __func__);
  74900. +
  74901. + }
  74902. +
  74903. + dwc_memset(qh->desc_list, 0x00,
  74904. + sizeof(dwc_otg_host_dma_desc_t) * max_desc_num(qh));
  74905. +
  74906. + qh->n_bytes =
  74907. + (uint32_t *) DWC_ALLOC(sizeof(uint32_t) * max_desc_num(qh));
  74908. +
  74909. + if (!qh->n_bytes) {
  74910. + retval = -DWC_E_NO_MEMORY;
  74911. + DWC_ERROR
  74912. + ("%s: Failed to allocate array for descriptors' size actual values\n",
  74913. + __func__);
  74914. +
  74915. + }
  74916. + return retval;
  74917. +
  74918. +}
  74919. +
  74920. +static void desc_list_free(dwc_otg_qh_t * qh)
  74921. +{
  74922. + if (qh->desc_list) {
  74923. + DWC_DMA_FREE(max_desc_num(qh), qh->desc_list,
  74924. + qh->desc_list_dma);
  74925. + qh->desc_list = NULL;
  74926. + }
  74927. +
  74928. + if (qh->n_bytes) {
  74929. + DWC_FREE(qh->n_bytes);
  74930. + qh->n_bytes = NULL;
  74931. + }
  74932. +}
  74933. +
  74934. +static int frame_list_alloc(dwc_otg_hcd_t * hcd)
  74935. +{
  74936. + int retval = 0;
  74937. + if (hcd->frame_list)
  74938. + return 0;
  74939. +
  74940. + hcd->frame_list = DWC_DMA_ALLOC(4 * MAX_FRLIST_EN_NUM,
  74941. + &hcd->frame_list_dma);
  74942. + if (!hcd->frame_list) {
  74943. + retval = -DWC_E_NO_MEMORY;
  74944. + DWC_ERROR("%s: Frame List allocation failed\n", __func__);
  74945. + }
  74946. +
  74947. + dwc_memset(hcd->frame_list, 0x00, 4 * MAX_FRLIST_EN_NUM);
  74948. +
  74949. + return retval;
  74950. +}
  74951. +
  74952. +static void frame_list_free(dwc_otg_hcd_t * hcd)
  74953. +{
  74954. + if (!hcd->frame_list)
  74955. + return;
  74956. +
  74957. + DWC_DMA_FREE(4 * MAX_FRLIST_EN_NUM, hcd->frame_list, hcd->frame_list_dma);
  74958. + hcd->frame_list = NULL;
  74959. +}
  74960. +
  74961. +static void per_sched_enable(dwc_otg_hcd_t * hcd, uint16_t fr_list_en)
  74962. +{
  74963. +
  74964. + hcfg_data_t hcfg;
  74965. +
  74966. + hcfg.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hcfg);
  74967. +
  74968. + if (hcfg.b.perschedena) {
  74969. + /* already enabled */
  74970. + return;
  74971. + }
  74972. +
  74973. + DWC_WRITE_REG32(&hcd->core_if->host_if->host_global_regs->hflbaddr,
  74974. + hcd->frame_list_dma);
  74975. +
  74976. + switch (fr_list_en) {
  74977. + case 64:
  74978. + hcfg.b.frlisten = 3;
  74979. + break;
  74980. + case 32:
  74981. + hcfg.b.frlisten = 2;
  74982. + break;
  74983. + case 16:
  74984. + hcfg.b.frlisten = 1;
  74985. + break;
  74986. + case 8:
  74987. + hcfg.b.frlisten = 0;
  74988. + break;
  74989. + default:
  74990. + break;
  74991. + }
  74992. +
  74993. + hcfg.b.perschedena = 1;
  74994. +
  74995. + DWC_DEBUGPL(DBG_HCD, "Enabling Periodic schedule\n");
  74996. + DWC_WRITE_REG32(&hcd->core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  74997. +
  74998. +}
  74999. +
  75000. +static void per_sched_disable(dwc_otg_hcd_t * hcd)
  75001. +{
  75002. + hcfg_data_t hcfg;
  75003. +
  75004. + hcfg.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hcfg);
  75005. +
  75006. + if (!hcfg.b.perschedena) {
  75007. + /* already disabled */
  75008. + return;
  75009. + }
  75010. + hcfg.b.perschedena = 0;
  75011. +
  75012. + DWC_DEBUGPL(DBG_HCD, "Disabling Periodic schedule\n");
  75013. + DWC_WRITE_REG32(&hcd->core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  75014. +}
  75015. +
  75016. +/*
  75017. + * Activates/Deactivates FrameList entries for the channel
  75018. + * based on endpoint servicing period.
  75019. + */
  75020. +void update_frame_list(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh, uint8_t enable)
  75021. +{
  75022. + uint16_t i, j, inc;
  75023. + dwc_hc_t *hc = NULL;
  75024. +
  75025. + if (!qh->channel) {
  75026. + DWC_ERROR("qh->channel = %p", qh->channel);
  75027. + return;
  75028. + }
  75029. +
  75030. + if (!hcd) {
  75031. + DWC_ERROR("------hcd = %p", hcd);
  75032. + return;
  75033. + }
  75034. +
  75035. + if (!hcd->frame_list) {
  75036. + DWC_ERROR("-------hcd->frame_list = %p", hcd->frame_list);
  75037. + return;
  75038. + }
  75039. +
  75040. + hc = qh->channel;
  75041. + inc = frame_incr_val(qh);
  75042. + if (qh->ep_type == UE_ISOCHRONOUS)
  75043. + i = frame_list_idx(qh->sched_frame);
  75044. + else
  75045. + i = 0;
  75046. +
  75047. + j = i;
  75048. + do {
  75049. + if (enable)
  75050. + hcd->frame_list[j] |= (1 << hc->hc_num);
  75051. + else
  75052. + hcd->frame_list[j] &= ~(1 << hc->hc_num);
  75053. + j = (j + inc) & (MAX_FRLIST_EN_NUM - 1);
  75054. + }
  75055. + while (j != i);
  75056. + if (!enable)
  75057. + return;
  75058. + hc->schinfo = 0;
  75059. + if (qh->channel->speed == DWC_OTG_EP_SPEED_HIGH) {
  75060. + j = 1;
  75061. + /* TODO - check this */
  75062. + inc = (8 + qh->interval - 1) / qh->interval;
  75063. + for (i = 0; i < inc; i++) {
  75064. + hc->schinfo |= j;
  75065. + j = j << qh->interval;
  75066. + }
  75067. + } else {
  75068. + hc->schinfo = 0xff;
  75069. + }
  75070. +}
  75071. +
  75072. +#if 1
  75073. +void dump_frame_list(dwc_otg_hcd_t * hcd)
  75074. +{
  75075. + int i = 0;
  75076. + DWC_PRINTF("--FRAME LIST (hex) --\n");
  75077. + for (i = 0; i < MAX_FRLIST_EN_NUM; i++) {
  75078. + DWC_PRINTF("%x\t", hcd->frame_list[i]);
  75079. + if (!(i % 8) && i)
  75080. + DWC_PRINTF("\n");
  75081. + }
  75082. + DWC_PRINTF("\n----\n");
  75083. +
  75084. +}
  75085. +#endif
  75086. +
  75087. +static void release_channel_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  75088. +{
  75089. + dwc_irqflags_t flags;
  75090. + dwc_spinlock_t *channel_lock = hcd->channel_lock;
  75091. +
  75092. + dwc_hc_t *hc = qh->channel;
  75093. + if (dwc_qh_is_non_per(qh)) {
  75094. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  75095. + if (!microframe_schedule)
  75096. + hcd->non_periodic_channels--;
  75097. + else
  75098. + hcd->available_host_channels++;
  75099. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  75100. + } else
  75101. + update_frame_list(hcd, qh, 0);
  75102. +
  75103. + /*
  75104. + * The condition is added to prevent double cleanup try in case of device
  75105. + * disconnect. See channel cleanup in dwc_otg_hcd_disconnect_cb().
  75106. + */
  75107. + if (hc->qh) {
  75108. + dwc_otg_hc_cleanup(hcd->core_if, hc);
  75109. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, hc, hc_list_entry);
  75110. + hc->qh = NULL;
  75111. + }
  75112. +
  75113. + qh->channel = NULL;
  75114. + qh->ntd = 0;
  75115. +
  75116. + if (qh->desc_list) {
  75117. + dwc_memset(qh->desc_list, 0x00,
  75118. + sizeof(dwc_otg_host_dma_desc_t) * max_desc_num(qh));
  75119. + }
  75120. +}
  75121. +
  75122. +/**
  75123. + * Initializes a QH structure's Descriptor DMA related members.
  75124. + * Allocates memory for descriptor list.
  75125. + * On first periodic QH, allocates memory for FrameList
  75126. + * and enables periodic scheduling.
  75127. + *
  75128. + * @param hcd The HCD state structure for the DWC OTG controller.
  75129. + * @param qh The QH to init.
  75130. + *
  75131. + * @return 0 if successful, negative error code otherwise.
  75132. + */
  75133. +int dwc_otg_hcd_qh_init_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  75134. +{
  75135. + int retval = 0;
  75136. +
  75137. + if (qh->do_split) {
  75138. + DWC_ERROR("SPLIT Transfers are not supported in Descriptor DMA.\n");
  75139. + return -1;
  75140. + }
  75141. +
  75142. + retval = desc_list_alloc(qh);
  75143. +
  75144. + if ((retval == 0)
  75145. + && (qh->ep_type == UE_ISOCHRONOUS || qh->ep_type == UE_INTERRUPT)) {
  75146. + if (!hcd->frame_list) {
  75147. + retval = frame_list_alloc(hcd);
  75148. + /* Enable periodic schedule on first periodic QH */
  75149. + if (retval == 0)
  75150. + per_sched_enable(hcd, MAX_FRLIST_EN_NUM);
  75151. + }
  75152. + }
  75153. +
  75154. + qh->ntd = 0;
  75155. +
  75156. + return retval;
  75157. +}
  75158. +
  75159. +/**
  75160. + * Frees descriptor list memory associated with the QH.
  75161. + * If QH is periodic and the last, frees FrameList memory
  75162. + * and disables periodic scheduling.
  75163. + *
  75164. + * @param hcd The HCD state structure for the DWC OTG controller.
  75165. + * @param qh The QH to init.
  75166. + */
  75167. +void dwc_otg_hcd_qh_free_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  75168. +{
  75169. + desc_list_free(qh);
  75170. +
  75171. + /*
  75172. + * Channel still assigned due to some reasons.
  75173. + * Seen on Isoc URB dequeue. Channel halted but no subsequent
  75174. + * ChHalted interrupt to release the channel. Afterwards
  75175. + * when it comes here from endpoint disable routine
  75176. + * channel remains assigned.
  75177. + */
  75178. + if (qh->channel)
  75179. + release_channel_ddma(hcd, qh);
  75180. +
  75181. + if ((qh->ep_type == UE_ISOCHRONOUS || qh->ep_type == UE_INTERRUPT)
  75182. + && (microframe_schedule || !hcd->periodic_channels) && hcd->frame_list) {
  75183. +
  75184. + per_sched_disable(hcd);
  75185. + frame_list_free(hcd);
  75186. + }
  75187. +}
  75188. +
  75189. +static uint8_t frame_to_desc_idx(dwc_otg_qh_t * qh, uint16_t frame_idx)
  75190. +{
  75191. + if (qh->dev_speed == DWC_OTG_EP_SPEED_HIGH) {
  75192. + /*
  75193. + * Descriptor set(8 descriptors) index
  75194. + * which is 8-aligned.
  75195. + */
  75196. + return (frame_idx & ((MAX_DMA_DESC_NUM_HS_ISOC / 8) - 1)) * 8;
  75197. + } else {
  75198. + return (frame_idx & (MAX_DMA_DESC_NUM_GENERIC - 1));
  75199. + }
  75200. +}
  75201. +
  75202. +/*
  75203. + * Determine starting frame for Isochronous transfer.
  75204. + * Few frames skipped to prevent race condition with HC.
  75205. + */
  75206. +static uint8_t calc_starting_frame(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  75207. + uint8_t * skip_frames)
  75208. +{
  75209. + uint16_t frame = 0;
  75210. + hcd->frame_number = dwc_otg_hcd_get_frame_number(hcd);
  75211. +
  75212. + /* sched_frame is always frame number(not uFrame) both in FS and HS !! */
  75213. +
  75214. + /*
  75215. + * skip_frames is used to limit activated descriptors number
  75216. + * to avoid the situation when HC services the last activated
  75217. + * descriptor firstly.
  75218. + * Example for FS:
  75219. + * Current frame is 1, scheduled frame is 3. Since HC always fetches the descriptor
  75220. + * corresponding to curr_frame+1, the descriptor corresponding to frame 2
  75221. + * will be fetched. If the number of descriptors is max=64 (or greather) the
  75222. + * list will be fully programmed with Active descriptors and it is possible
  75223. + * case(rare) that the latest descriptor(considering rollback) corresponding
  75224. + * to frame 2 will be serviced first. HS case is more probable because, in fact,
  75225. + * up to 11 uframes(16 in the code) may be skipped.
  75226. + */
  75227. + if (qh->dev_speed == DWC_OTG_EP_SPEED_HIGH) {
  75228. + /*
  75229. + * Consider uframe counter also, to start xfer asap.
  75230. + * If half of the frame elapsed skip 2 frames otherwise
  75231. + * just 1 frame.
  75232. + * Starting descriptor index must be 8-aligned, so
  75233. + * if the current frame is near to complete the next one
  75234. + * is skipped as well.
  75235. + */
  75236. +
  75237. + if (dwc_micro_frame_num(hcd->frame_number) >= 5) {
  75238. + *skip_frames = 2 * 8;
  75239. + frame = dwc_frame_num_inc(hcd->frame_number, *skip_frames);
  75240. + } else {
  75241. + *skip_frames = 1 * 8;
  75242. + frame = dwc_frame_num_inc(hcd->frame_number, *skip_frames);
  75243. + }
  75244. +
  75245. + frame = dwc_full_frame_num(frame);
  75246. + } else {
  75247. + /*
  75248. + * Two frames are skipped for FS - the current and the next.
  75249. + * But for descriptor programming, 1 frame(descriptor) is enough,
  75250. + * see example above.
  75251. + */
  75252. + *skip_frames = 1;
  75253. + frame = dwc_frame_num_inc(hcd->frame_number, 2);
  75254. + }
  75255. +
  75256. + return frame;
  75257. +}
  75258. +
  75259. +/*
  75260. + * Calculate initial descriptor index for isochronous transfer
  75261. + * based on scheduled frame.
  75262. + */
  75263. +static uint8_t recalc_initial_desc_idx(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  75264. +{
  75265. + uint16_t frame = 0, fr_idx, fr_idx_tmp;
  75266. + uint8_t skip_frames = 0;
  75267. + /*
  75268. + * With current ISOC processing algorithm the channel is being
  75269. + * released when no more QTDs in the list(qh->ntd == 0).
  75270. + * Thus this function is called only when qh->ntd == 0 and qh->channel == 0.
  75271. + *
  75272. + * So qh->channel != NULL branch is not used and just not removed from the
  75273. + * source file. It is required for another possible approach which is,
  75274. + * do not disable and release the channel when ISOC session completed,
  75275. + * just move QH to inactive schedule until new QTD arrives.
  75276. + * On new QTD, the QH moved back to 'ready' schedule,
  75277. + * starting frame and therefore starting desc_index are recalculated.
  75278. + * In this case channel is released only on ep_disable.
  75279. + */
  75280. +
  75281. + /* Calculate starting descriptor index. For INTERRUPT endpoint it is always 0. */
  75282. + if (qh->channel) {
  75283. + frame = calc_starting_frame(hcd, qh, &skip_frames);
  75284. + /*
  75285. + * Calculate initial descriptor index based on FrameList current bitmap
  75286. + * and servicing period.
  75287. + */
  75288. + fr_idx_tmp = frame_list_idx(frame);
  75289. + fr_idx =
  75290. + (MAX_FRLIST_EN_NUM + frame_list_idx(qh->sched_frame) -
  75291. + fr_idx_tmp)
  75292. + % frame_incr_val(qh);
  75293. + fr_idx = (fr_idx + fr_idx_tmp) % MAX_FRLIST_EN_NUM;
  75294. + } else {
  75295. + qh->sched_frame = calc_starting_frame(hcd, qh, &skip_frames);
  75296. + fr_idx = frame_list_idx(qh->sched_frame);
  75297. + }
  75298. +
  75299. + qh->td_first = qh->td_last = frame_to_desc_idx(qh, fr_idx);
  75300. +
  75301. + return skip_frames;
  75302. +}
  75303. +
  75304. +#define ISOC_URB_GIVEBACK_ASAP
  75305. +
  75306. +#define MAX_ISOC_XFER_SIZE_FS 1023
  75307. +#define MAX_ISOC_XFER_SIZE_HS 3072
  75308. +#define DESCNUM_THRESHOLD 4
  75309. +
  75310. +static void init_isoc_dma_desc(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  75311. + uint8_t skip_frames)
  75312. +{
  75313. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  75314. + dwc_otg_qtd_t *qtd;
  75315. + dwc_otg_host_dma_desc_t *dma_desc;
  75316. + uint16_t idx, inc, n_desc, ntd_max, max_xfer_size;
  75317. +
  75318. + idx = qh->td_last;
  75319. + inc = qh->interval;
  75320. + n_desc = 0;
  75321. +
  75322. + ntd_max = (max_desc_num(qh) + qh->interval - 1) / qh->interval;
  75323. + if (skip_frames && !qh->channel)
  75324. + ntd_max = ntd_max - skip_frames / qh->interval;
  75325. +
  75326. + max_xfer_size =
  75327. + (qh->dev_speed ==
  75328. + DWC_OTG_EP_SPEED_HIGH) ? MAX_ISOC_XFER_SIZE_HS :
  75329. + MAX_ISOC_XFER_SIZE_FS;
  75330. +
  75331. + DWC_CIRCLEQ_FOREACH(qtd, &qh->qtd_list, qtd_list_entry) {
  75332. + while ((qh->ntd < ntd_max)
  75333. + && (qtd->isoc_frame_index_last <
  75334. + qtd->urb->packet_count)) {
  75335. +
  75336. + dma_desc = &qh->desc_list[idx];
  75337. + dwc_memset(dma_desc, 0x00, sizeof(dwc_otg_host_dma_desc_t));
  75338. +
  75339. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index_last];
  75340. +
  75341. + if (frame_desc->length > max_xfer_size)
  75342. + qh->n_bytes[idx] = max_xfer_size;
  75343. + else
  75344. + qh->n_bytes[idx] = frame_desc->length;
  75345. + dma_desc->status.b_isoc.n_bytes = qh->n_bytes[idx];
  75346. + dma_desc->status.b_isoc.a = 1;
  75347. + dma_desc->status.b_isoc.sts = 0;
  75348. +
  75349. + dma_desc->buf = qtd->urb->dma + frame_desc->offset;
  75350. +
  75351. + qh->ntd++;
  75352. +
  75353. + qtd->isoc_frame_index_last++;
  75354. +
  75355. +#ifdef ISOC_URB_GIVEBACK_ASAP
  75356. + /*
  75357. + * Set IOC for each descriptor corresponding to the
  75358. + * last frame of the URB.
  75359. + */
  75360. + if (qtd->isoc_frame_index_last ==
  75361. + qtd->urb->packet_count)
  75362. + dma_desc->status.b_isoc.ioc = 1;
  75363. +
  75364. +#endif
  75365. + idx = desclist_idx_inc(idx, inc, qh->dev_speed);
  75366. + n_desc++;
  75367. +
  75368. + }
  75369. + qtd->in_process = 1;
  75370. + }
  75371. +
  75372. + qh->td_last = idx;
  75373. +
  75374. +#ifdef ISOC_URB_GIVEBACK_ASAP
  75375. + /* Set IOC for the last descriptor if descriptor list is full */
  75376. + if (qh->ntd == ntd_max) {
  75377. + idx = desclist_idx_dec(qh->td_last, inc, qh->dev_speed);
  75378. + qh->desc_list[idx].status.b_isoc.ioc = 1;
  75379. + }
  75380. +#else
  75381. + /*
  75382. + * Set IOC bit only for one descriptor.
  75383. + * Always try to be ahead of HW processing,
  75384. + * i.e. on IOC generation driver activates next descriptors but
  75385. + * core continues to process descriptors followed the one with IOC set.
  75386. + */
  75387. +
  75388. + if (n_desc > DESCNUM_THRESHOLD) {
  75389. + /*
  75390. + * Move IOC "up". Required even if there is only one QTD
  75391. + * in the list, cause QTDs migth continue to be queued,
  75392. + * but during the activation it was only one queued.
  75393. + * Actually more than one QTD might be in the list if this function called
  75394. + * from XferCompletion - QTDs was queued during HW processing of the previous
  75395. + * descriptor chunk.
  75396. + */
  75397. + idx = dwc_desclist_idx_dec(idx, inc * ((qh->ntd + 1) / 2), qh->dev_speed);
  75398. + } else {
  75399. + /*
  75400. + * Set the IOC for the latest descriptor
  75401. + * if either number of descriptor is not greather than threshold
  75402. + * or no more new descriptors activated.
  75403. + */
  75404. + idx = dwc_desclist_idx_dec(qh->td_last, inc, qh->dev_speed);
  75405. + }
  75406. +
  75407. + qh->desc_list[idx].status.b_isoc.ioc = 1;
  75408. +#endif
  75409. +}
  75410. +
  75411. +static void init_non_isoc_dma_desc(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  75412. +{
  75413. +
  75414. + dwc_hc_t *hc;
  75415. + dwc_otg_host_dma_desc_t *dma_desc;
  75416. + dwc_otg_qtd_t *qtd;
  75417. + int num_packets, len, n_desc = 0;
  75418. +
  75419. + hc = qh->channel;
  75420. +
  75421. + /*
  75422. + * Start with hc->xfer_buff initialized in
  75423. + * assign_and_init_hc(), then if SG transfer consists of multiple URBs,
  75424. + * this pointer re-assigned to the buffer of the currently processed QTD.
  75425. + * For non-SG request there is always one QTD active.
  75426. + */
  75427. +
  75428. + DWC_CIRCLEQ_FOREACH(qtd, &qh->qtd_list, qtd_list_entry) {
  75429. +
  75430. + if (n_desc) {
  75431. + /* SG request - more than 1 QTDs */
  75432. + hc->xfer_buff = (uint8_t *)qtd->urb->dma + qtd->urb->actual_length;
  75433. + hc->xfer_len = qtd->urb->length - qtd->urb->actual_length;
  75434. + }
  75435. +
  75436. + qtd->n_desc = 0;
  75437. +
  75438. + do {
  75439. + dma_desc = &qh->desc_list[n_desc];
  75440. + len = hc->xfer_len;
  75441. +
  75442. + if (len > MAX_DMA_DESC_SIZE)
  75443. + len = MAX_DMA_DESC_SIZE - hc->max_packet + 1;
  75444. +
  75445. + if (hc->ep_is_in) {
  75446. + if (len > 0) {
  75447. + num_packets = (len + hc->max_packet - 1) / hc->max_packet;
  75448. + } else {
  75449. + /* Need 1 packet for transfer length of 0. */
  75450. + num_packets = 1;
  75451. + }
  75452. + /* Always program an integral # of max packets for IN transfers. */
  75453. + len = num_packets * hc->max_packet;
  75454. + }
  75455. +
  75456. + dma_desc->status.b.n_bytes = len;
  75457. +
  75458. + qh->n_bytes[n_desc] = len;
  75459. +
  75460. + if ((qh->ep_type == UE_CONTROL)
  75461. + && (qtd->control_phase == DWC_OTG_CONTROL_SETUP))
  75462. + dma_desc->status.b.sup = 1; /* Setup Packet */
  75463. +
  75464. + dma_desc->status.b.a = 1; /* Active descriptor */
  75465. + dma_desc->status.b.sts = 0;
  75466. +
  75467. + dma_desc->buf =
  75468. + ((unsigned long)hc->xfer_buff & 0xffffffff);
  75469. +
  75470. + /*
  75471. + * Last descriptor(or single) of IN transfer
  75472. + * with actual size less than MaxPacket.
  75473. + */
  75474. + if (len > hc->xfer_len) {
  75475. + hc->xfer_len = 0;
  75476. + } else {
  75477. + hc->xfer_buff += len;
  75478. + hc->xfer_len -= len;
  75479. + }
  75480. +
  75481. + qtd->n_desc++;
  75482. + n_desc++;
  75483. + }
  75484. + while ((hc->xfer_len > 0) && (n_desc != MAX_DMA_DESC_NUM_GENERIC));
  75485. +
  75486. +
  75487. + qtd->in_process = 1;
  75488. +
  75489. + if (qh->ep_type == UE_CONTROL)
  75490. + break;
  75491. +
  75492. + if (n_desc == MAX_DMA_DESC_NUM_GENERIC)
  75493. + break;
  75494. + }
  75495. +
  75496. + if (n_desc) {
  75497. + /* Request Transfer Complete interrupt for the last descriptor */
  75498. + qh->desc_list[n_desc - 1].status.b.ioc = 1;
  75499. + /* End of List indicator */
  75500. + qh->desc_list[n_desc - 1].status.b.eol = 1;
  75501. +
  75502. + hc->ntd = n_desc;
  75503. + }
  75504. +}
  75505. +
  75506. +/**
  75507. + * For Control and Bulk endpoints initializes descriptor list
  75508. + * and starts the transfer.
  75509. + *
  75510. + * For Interrupt and Isochronous endpoints initializes descriptor list
  75511. + * then updates FrameList, marking appropriate entries as active.
  75512. + * In case of Isochronous, the starting descriptor index is calculated based
  75513. + * on the scheduled frame, but only on the first transfer descriptor within a session.
  75514. + * Then starts the transfer via enabling the channel.
  75515. + * For Isochronous endpoint the channel is not halted on XferComplete
  75516. + * interrupt so remains assigned to the endpoint(QH) until session is done.
  75517. + *
  75518. + * @param hcd The HCD state structure for the DWC OTG controller.
  75519. + * @param qh The QH to init.
  75520. + *
  75521. + * @return 0 if successful, negative error code otherwise.
  75522. + */
  75523. +void dwc_otg_hcd_start_xfer_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  75524. +{
  75525. + /* Channel is already assigned */
  75526. + dwc_hc_t *hc = qh->channel;
  75527. + uint8_t skip_frames = 0;
  75528. +
  75529. + switch (hc->ep_type) {
  75530. + case DWC_OTG_EP_TYPE_CONTROL:
  75531. + case DWC_OTG_EP_TYPE_BULK:
  75532. + init_non_isoc_dma_desc(hcd, qh);
  75533. +
  75534. + dwc_otg_hc_start_transfer_ddma(hcd->core_if, hc);
  75535. + break;
  75536. + case DWC_OTG_EP_TYPE_INTR:
  75537. + init_non_isoc_dma_desc(hcd, qh);
  75538. +
  75539. + update_frame_list(hcd, qh, 1);
  75540. +
  75541. + dwc_otg_hc_start_transfer_ddma(hcd->core_if, hc);
  75542. + break;
  75543. + case DWC_OTG_EP_TYPE_ISOC:
  75544. +
  75545. + if (!qh->ntd)
  75546. + skip_frames = recalc_initial_desc_idx(hcd, qh);
  75547. +
  75548. + init_isoc_dma_desc(hcd, qh, skip_frames);
  75549. +
  75550. + if (!hc->xfer_started) {
  75551. +
  75552. + update_frame_list(hcd, qh, 1);
  75553. +
  75554. + /*
  75555. + * Always set to max, instead of actual size.
  75556. + * Otherwise ntd will be changed with
  75557. + * channel being enabled. Not recommended.
  75558. + *
  75559. + */
  75560. + hc->ntd = max_desc_num(qh);
  75561. + /* Enable channel only once for ISOC */
  75562. + dwc_otg_hc_start_transfer_ddma(hcd->core_if, hc);
  75563. + }
  75564. +
  75565. + break;
  75566. + default:
  75567. +
  75568. + break;
  75569. + }
  75570. +}
  75571. +
  75572. +static void complete_isoc_xfer_ddma(dwc_otg_hcd_t * hcd,
  75573. + dwc_hc_t * hc,
  75574. + dwc_otg_hc_regs_t * hc_regs,
  75575. + dwc_otg_halt_status_e halt_status)
  75576. +{
  75577. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  75578. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  75579. + dwc_otg_qh_t *qh;
  75580. + dwc_otg_host_dma_desc_t *dma_desc;
  75581. + uint16_t idx, remain;
  75582. + uint8_t urb_compl;
  75583. +
  75584. + qh = hc->qh;
  75585. + idx = qh->td_first;
  75586. +
  75587. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  75588. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry)
  75589. + qtd->in_process = 0;
  75590. + return;
  75591. + } else if ((halt_status == DWC_OTG_HC_XFER_AHB_ERR) ||
  75592. + (halt_status == DWC_OTG_HC_XFER_BABBLE_ERR)) {
  75593. + /*
  75594. + * Channel is halted in these error cases.
  75595. + * Considered as serious issues.
  75596. + * Complete all URBs marking all frames as failed,
  75597. + * irrespective whether some of the descriptors(frames) succeeded or no.
  75598. + * Pass error code to completion routine as well, to
  75599. + * update urb->status, some of class drivers might use it to stop
  75600. + * queing transfer requests.
  75601. + */
  75602. + int err = (halt_status == DWC_OTG_HC_XFER_AHB_ERR)
  75603. + ? (-DWC_E_IO)
  75604. + : (-DWC_E_OVERFLOW);
  75605. +
  75606. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry) {
  75607. + for (idx = 0; idx < qtd->urb->packet_count; idx++) {
  75608. + frame_desc = &qtd->urb->iso_descs[idx];
  75609. + frame_desc->status = err;
  75610. + }
  75611. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, err);
  75612. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  75613. + }
  75614. + return;
  75615. + }
  75616. +
  75617. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry) {
  75618. +
  75619. + if (!qtd->in_process)
  75620. + break;
  75621. +
  75622. + urb_compl = 0;
  75623. +
  75624. + do {
  75625. +
  75626. + dma_desc = &qh->desc_list[idx];
  75627. +
  75628. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  75629. + remain = hc->ep_is_in ? dma_desc->status.b_isoc.n_bytes : 0;
  75630. +
  75631. + if (dma_desc->status.b_isoc.sts == DMA_DESC_STS_PKTERR) {
  75632. + /*
  75633. + * XactError or, unable to complete all the transactions
  75634. + * in the scheduled micro-frame/frame,
  75635. + * both indicated by DMA_DESC_STS_PKTERR.
  75636. + */
  75637. + qtd->urb->error_count++;
  75638. + frame_desc->actual_length = qh->n_bytes[idx] - remain;
  75639. + frame_desc->status = -DWC_E_PROTOCOL;
  75640. + } else {
  75641. + /* Success */
  75642. +
  75643. + frame_desc->actual_length = qh->n_bytes[idx] - remain;
  75644. + frame_desc->status = 0;
  75645. + }
  75646. +
  75647. + if (++qtd->isoc_frame_index == qtd->urb->packet_count) {
  75648. + /*
  75649. + * urb->status is not used for isoc transfers here.
  75650. + * The individual frame_desc status are used instead.
  75651. + */
  75652. +
  75653. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  75654. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  75655. +
  75656. + /*
  75657. + * This check is necessary because urb_dequeue can be called
  75658. + * from urb complete callback(sound driver example).
  75659. + * All pending URBs are dequeued there, so no need for
  75660. + * further processing.
  75661. + */
  75662. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  75663. + return;
  75664. + }
  75665. +
  75666. + urb_compl = 1;
  75667. +
  75668. + }
  75669. +
  75670. + qh->ntd--;
  75671. +
  75672. + /* Stop if IOC requested descriptor reached */
  75673. + if (dma_desc->status.b_isoc.ioc) {
  75674. + idx = desclist_idx_inc(idx, qh->interval, hc->speed);
  75675. + goto stop_scan;
  75676. + }
  75677. +
  75678. + idx = desclist_idx_inc(idx, qh->interval, hc->speed);
  75679. +
  75680. + if (urb_compl)
  75681. + break;
  75682. + }
  75683. + while (idx != qh->td_first);
  75684. + }
  75685. +stop_scan:
  75686. + qh->td_first = idx;
  75687. +}
  75688. +
  75689. +uint8_t update_non_isoc_urb_state_ddma(dwc_otg_hcd_t * hcd,
  75690. + dwc_hc_t * hc,
  75691. + dwc_otg_qtd_t * qtd,
  75692. + dwc_otg_host_dma_desc_t * dma_desc,
  75693. + dwc_otg_halt_status_e halt_status,
  75694. + uint32_t n_bytes, uint8_t * xfer_done)
  75695. +{
  75696. +
  75697. + uint16_t remain = hc->ep_is_in ? dma_desc->status.b.n_bytes : 0;
  75698. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  75699. +
  75700. + if (halt_status == DWC_OTG_HC_XFER_AHB_ERR) {
  75701. + urb->status = -DWC_E_IO;
  75702. + return 1;
  75703. + }
  75704. + if (dma_desc->status.b.sts == DMA_DESC_STS_PKTERR) {
  75705. + switch (halt_status) {
  75706. + case DWC_OTG_HC_XFER_STALL:
  75707. + urb->status = -DWC_E_PIPE;
  75708. + break;
  75709. + case DWC_OTG_HC_XFER_BABBLE_ERR:
  75710. + urb->status = -DWC_E_OVERFLOW;
  75711. + break;
  75712. + case DWC_OTG_HC_XFER_XACT_ERR:
  75713. + urb->status = -DWC_E_PROTOCOL;
  75714. + break;
  75715. + default:
  75716. + DWC_ERROR("%s: Unhandled descriptor error status (%d)\n", __func__,
  75717. + halt_status);
  75718. + break;
  75719. + }
  75720. + return 1;
  75721. + }
  75722. +
  75723. + if (dma_desc->status.b.a == 1) {
  75724. + DWC_DEBUGPL(DBG_HCDV,
  75725. + "Active descriptor encountered on channel %d\n",
  75726. + hc->hc_num);
  75727. + return 0;
  75728. + }
  75729. +
  75730. + if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL) {
  75731. + if (qtd->control_phase == DWC_OTG_CONTROL_DATA) {
  75732. + urb->actual_length += n_bytes - remain;
  75733. + if (remain || urb->actual_length == urb->length) {
  75734. + /*
  75735. + * For Control Data stage do not set urb->status=0 to prevent
  75736. + * URB callback. Set it when Status phase done. See below.
  75737. + */
  75738. + *xfer_done = 1;
  75739. + }
  75740. +
  75741. + } else if (qtd->control_phase == DWC_OTG_CONTROL_STATUS) {
  75742. + urb->status = 0;
  75743. + *xfer_done = 1;
  75744. + }
  75745. + /* No handling for SETUP stage */
  75746. + } else {
  75747. + /* BULK and INTR */
  75748. + urb->actual_length += n_bytes - remain;
  75749. + if (remain || urb->actual_length == urb->length) {
  75750. + urb->status = 0;
  75751. + *xfer_done = 1;
  75752. + }
  75753. + }
  75754. +
  75755. + return 0;
  75756. +}
  75757. +
  75758. +static void complete_non_isoc_xfer_ddma(dwc_otg_hcd_t * hcd,
  75759. + dwc_hc_t * hc,
  75760. + dwc_otg_hc_regs_t * hc_regs,
  75761. + dwc_otg_halt_status_e halt_status)
  75762. +{
  75763. + dwc_otg_hcd_urb_t *urb = NULL;
  75764. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  75765. + dwc_otg_qh_t *qh;
  75766. + dwc_otg_host_dma_desc_t *dma_desc;
  75767. + uint32_t n_bytes, n_desc, i;
  75768. + uint8_t failed = 0, xfer_done;
  75769. +
  75770. + n_desc = 0;
  75771. +
  75772. + qh = hc->qh;
  75773. +
  75774. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  75775. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry) {
  75776. + qtd->in_process = 0;
  75777. + }
  75778. + return;
  75779. + }
  75780. +
  75781. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &qh->qtd_list, qtd_list_entry) {
  75782. +
  75783. + urb = qtd->urb;
  75784. +
  75785. + n_bytes = 0;
  75786. + xfer_done = 0;
  75787. +
  75788. + for (i = 0; i < qtd->n_desc; i++) {
  75789. + dma_desc = &qh->desc_list[n_desc];
  75790. +
  75791. + n_bytes = qh->n_bytes[n_desc];
  75792. +
  75793. + failed =
  75794. + update_non_isoc_urb_state_ddma(hcd, hc, qtd,
  75795. + dma_desc,
  75796. + halt_status, n_bytes,
  75797. + &xfer_done);
  75798. +
  75799. + if (failed
  75800. + || (xfer_done
  75801. + && (urb->status != -DWC_E_IN_PROGRESS))) {
  75802. +
  75803. + hcd->fops->complete(hcd, urb->priv, urb,
  75804. + urb->status);
  75805. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  75806. +
  75807. + if (failed)
  75808. + goto stop_scan;
  75809. + } else if (qh->ep_type == UE_CONTROL) {
  75810. + if (qtd->control_phase == DWC_OTG_CONTROL_SETUP) {
  75811. + if (urb->length > 0) {
  75812. + qtd->control_phase = DWC_OTG_CONTROL_DATA;
  75813. + } else {
  75814. + qtd->control_phase = DWC_OTG_CONTROL_STATUS;
  75815. + }
  75816. + DWC_DEBUGPL(DBG_HCDV, " Control setup transaction done\n");
  75817. + } else if (qtd->control_phase == DWC_OTG_CONTROL_DATA) {
  75818. + if (xfer_done) {
  75819. + qtd->control_phase = DWC_OTG_CONTROL_STATUS;
  75820. + DWC_DEBUGPL(DBG_HCDV, " Control data transfer done\n");
  75821. + } else if (i + 1 == qtd->n_desc) {
  75822. + /*
  75823. + * Last descriptor for Control data stage which is
  75824. + * not completed yet.
  75825. + */
  75826. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  75827. + }
  75828. + }
  75829. + }
  75830. +
  75831. + n_desc++;
  75832. + }
  75833. +
  75834. + }
  75835. +
  75836. +stop_scan:
  75837. +
  75838. + if (qh->ep_type != UE_CONTROL) {
  75839. + /*
  75840. + * Resetting the data toggle for bulk
  75841. + * and interrupt endpoints in case of stall. See handle_hc_stall_intr()
  75842. + */
  75843. + if (halt_status == DWC_OTG_HC_XFER_STALL)
  75844. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  75845. + else
  75846. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  75847. + }
  75848. +
  75849. + if (halt_status == DWC_OTG_HC_XFER_COMPLETE) {
  75850. + hcint_data_t hcint;
  75851. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  75852. + if (hcint.b.nyet) {
  75853. + /*
  75854. + * Got a NYET on the last transaction of the transfer. It
  75855. + * means that the endpoint should be in the PING state at the
  75856. + * beginning of the next transfer.
  75857. + */
  75858. + qh->ping_state = 1;
  75859. + clear_hc_int(hc_regs, nyet);
  75860. + }
  75861. +
  75862. + }
  75863. +
  75864. +}
  75865. +
  75866. +/**
  75867. + * This function is called from interrupt handlers.
  75868. + * Scans the descriptor list, updates URB's status and
  75869. + * calls completion routine for the URB if it's done.
  75870. + * Releases the channel to be used by other transfers.
  75871. + * In case of Isochronous endpoint the channel is not halted until
  75872. + * the end of the session, i.e. QTD list is empty.
  75873. + * If periodic channel released the FrameList is updated accordingly.
  75874. + *
  75875. + * Calls transaction selection routines to activate pending transfers.
  75876. + *
  75877. + * @param hcd The HCD state structure for the DWC OTG controller.
  75878. + * @param hc Host channel, the transfer is completed on.
  75879. + * @param hc_regs Host channel registers.
  75880. + * @param halt_status Reason the channel is being halted,
  75881. + * or just XferComplete for isochronous transfer
  75882. + */
  75883. +void dwc_otg_hcd_complete_xfer_ddma(dwc_otg_hcd_t * hcd,
  75884. + dwc_hc_t * hc,
  75885. + dwc_otg_hc_regs_t * hc_regs,
  75886. + dwc_otg_halt_status_e halt_status)
  75887. +{
  75888. + uint8_t continue_isoc_xfer = 0;
  75889. + dwc_otg_transaction_type_e tr_type;
  75890. + dwc_otg_qh_t *qh = hc->qh;
  75891. +
  75892. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  75893. +
  75894. + complete_isoc_xfer_ddma(hcd, hc, hc_regs, halt_status);
  75895. +
  75896. + /* Release the channel if halted or session completed */
  75897. + if (halt_status != DWC_OTG_HC_XFER_COMPLETE ||
  75898. + DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  75899. +
  75900. + /* Halt the channel if session completed */
  75901. + if (halt_status == DWC_OTG_HC_XFER_COMPLETE) {
  75902. + dwc_otg_hc_halt(hcd->core_if, hc, halt_status);
  75903. + }
  75904. +
  75905. + release_channel_ddma(hcd, qh);
  75906. + dwc_otg_hcd_qh_remove(hcd, qh);
  75907. + } else {
  75908. + /* Keep in assigned schedule to continue transfer */
  75909. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_assigned,
  75910. + &qh->qh_list_entry);
  75911. + continue_isoc_xfer = 1;
  75912. +
  75913. + }
  75914. + /** @todo Consider the case when period exceeds FrameList size.
  75915. + * Frame Rollover interrupt should be used.
  75916. + */
  75917. + } else {
  75918. + /* Scan descriptor list to complete the URB(s), then release the channel */
  75919. + complete_non_isoc_xfer_ddma(hcd, hc, hc_regs, halt_status);
  75920. +
  75921. + release_channel_ddma(hcd, qh);
  75922. + dwc_otg_hcd_qh_remove(hcd, qh);
  75923. +
  75924. + if (!DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  75925. + /* Add back to inactive non-periodic schedule on normal completion */
  75926. + dwc_otg_hcd_qh_add(hcd, qh);
  75927. + }
  75928. +
  75929. + }
  75930. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  75931. + if (tr_type != DWC_OTG_TRANSACTION_NONE || continue_isoc_xfer) {
  75932. + if (continue_isoc_xfer) {
  75933. + if (tr_type == DWC_OTG_TRANSACTION_NONE) {
  75934. + tr_type = DWC_OTG_TRANSACTION_PERIODIC;
  75935. + } else if (tr_type == DWC_OTG_TRANSACTION_NON_PERIODIC) {
  75936. + tr_type = DWC_OTG_TRANSACTION_ALL;
  75937. + }
  75938. + }
  75939. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  75940. + }
  75941. +}
  75942. +
  75943. +#endif /* DWC_DEVICE_ONLY */
  75944. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd.h linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_hcd.h
  75945. --- linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd.h 1970-01-01 01:00:00.000000000 +0100
  75946. +++ linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_hcd.h 2014-08-06 16:50:14.817964852 +0200
  75947. @@ -0,0 +1,862 @@
  75948. +/* ==========================================================================
  75949. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd.h $
  75950. + * $Revision: #58 $
  75951. + * $Date: 2011/09/15 $
  75952. + * $Change: 1846647 $
  75953. + *
  75954. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  75955. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  75956. + * otherwise expressly agreed to in writing between Synopsys and you.
  75957. + *
  75958. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  75959. + * any End User Software License Agreement or Agreement for Licensed Product
  75960. + * with Synopsys or any supplement thereto. You are permitted to use and
  75961. + * redistribute this Software in source and binary forms, with or without
  75962. + * modification, provided that redistributions of source code must retain this
  75963. + * notice. You may not view, use, disclose, copy or distribute this file or
  75964. + * any information contained herein except pursuant to this license grant from
  75965. + * Synopsys. If you do not agree with this notice, including the disclaimer
  75966. + * below, then you are not authorized to use the Software.
  75967. + *
  75968. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  75969. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  75970. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  75971. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  75972. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  75973. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  75974. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  75975. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  75976. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  75977. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  75978. + * DAMAGE.
  75979. + * ========================================================================== */
  75980. +#ifndef DWC_DEVICE_ONLY
  75981. +#ifndef __DWC_HCD_H__
  75982. +#define __DWC_HCD_H__
  75983. +
  75984. +#include "dwc_otg_os_dep.h"
  75985. +#include "usb.h"
  75986. +#include "dwc_otg_hcd_if.h"
  75987. +#include "dwc_otg_core_if.h"
  75988. +#include "dwc_list.h"
  75989. +#include "dwc_otg_cil.h"
  75990. +#include "dwc_otg_fiq_fsm.h"
  75991. +
  75992. +
  75993. +/**
  75994. + * @file
  75995. + *
  75996. + * This file contains the structures, constants, and interfaces for
  75997. + * the Host Contoller Driver (HCD).
  75998. + *
  75999. + * The Host Controller Driver (HCD) is responsible for translating requests
  76000. + * from the USB Driver into the appropriate actions on the DWC_otg controller.
  76001. + * It isolates the USBD from the specifics of the controller by providing an
  76002. + * API to the USBD.
  76003. + */
  76004. +
  76005. +struct dwc_otg_hcd_pipe_info {
  76006. + uint8_t dev_addr;
  76007. + uint8_t ep_num;
  76008. + uint8_t pipe_type;
  76009. + uint8_t pipe_dir;
  76010. + uint16_t mps;
  76011. +};
  76012. +
  76013. +struct dwc_otg_hcd_iso_packet_desc {
  76014. + uint32_t offset;
  76015. + uint32_t length;
  76016. + uint32_t actual_length;
  76017. + uint32_t status;
  76018. +};
  76019. +
  76020. +struct dwc_otg_qtd;
  76021. +
  76022. +struct dwc_otg_hcd_urb {
  76023. + void *priv;
  76024. + struct dwc_otg_qtd *qtd;
  76025. + void *buf;
  76026. + dwc_dma_t dma;
  76027. + void *setup_packet;
  76028. + dwc_dma_t setup_dma;
  76029. + uint32_t length;
  76030. + uint32_t actual_length;
  76031. + uint32_t status;
  76032. + uint32_t error_count;
  76033. + uint32_t packet_count;
  76034. + uint32_t flags;
  76035. + uint16_t interval;
  76036. + struct dwc_otg_hcd_pipe_info pipe_info;
  76037. + struct dwc_otg_hcd_iso_packet_desc iso_descs[0];
  76038. +};
  76039. +
  76040. +static inline uint8_t dwc_otg_hcd_get_ep_num(struct dwc_otg_hcd_pipe_info *pipe)
  76041. +{
  76042. + return pipe->ep_num;
  76043. +}
  76044. +
  76045. +static inline uint8_t dwc_otg_hcd_get_pipe_type(struct dwc_otg_hcd_pipe_info
  76046. + *pipe)
  76047. +{
  76048. + return pipe->pipe_type;
  76049. +}
  76050. +
  76051. +static inline uint16_t dwc_otg_hcd_get_mps(struct dwc_otg_hcd_pipe_info *pipe)
  76052. +{
  76053. + return pipe->mps;
  76054. +}
  76055. +
  76056. +static inline uint8_t dwc_otg_hcd_get_dev_addr(struct dwc_otg_hcd_pipe_info
  76057. + *pipe)
  76058. +{
  76059. + return pipe->dev_addr;
  76060. +}
  76061. +
  76062. +static inline uint8_t dwc_otg_hcd_is_pipe_isoc(struct dwc_otg_hcd_pipe_info
  76063. + *pipe)
  76064. +{
  76065. + return (pipe->pipe_type == UE_ISOCHRONOUS);
  76066. +}
  76067. +
  76068. +static inline uint8_t dwc_otg_hcd_is_pipe_int(struct dwc_otg_hcd_pipe_info
  76069. + *pipe)
  76070. +{
  76071. + return (pipe->pipe_type == UE_INTERRUPT);
  76072. +}
  76073. +
  76074. +static inline uint8_t dwc_otg_hcd_is_pipe_bulk(struct dwc_otg_hcd_pipe_info
  76075. + *pipe)
  76076. +{
  76077. + return (pipe->pipe_type == UE_BULK);
  76078. +}
  76079. +
  76080. +static inline uint8_t dwc_otg_hcd_is_pipe_control(struct dwc_otg_hcd_pipe_info
  76081. + *pipe)
  76082. +{
  76083. + return (pipe->pipe_type == UE_CONTROL);
  76084. +}
  76085. +
  76086. +static inline uint8_t dwc_otg_hcd_is_pipe_in(struct dwc_otg_hcd_pipe_info *pipe)
  76087. +{
  76088. + return (pipe->pipe_dir == UE_DIR_IN);
  76089. +}
  76090. +
  76091. +static inline uint8_t dwc_otg_hcd_is_pipe_out(struct dwc_otg_hcd_pipe_info
  76092. + *pipe)
  76093. +{
  76094. + return (!dwc_otg_hcd_is_pipe_in(pipe));
  76095. +}
  76096. +
  76097. +static inline void dwc_otg_hcd_fill_pipe(struct dwc_otg_hcd_pipe_info *pipe,
  76098. + uint8_t devaddr, uint8_t ep_num,
  76099. + uint8_t pipe_type, uint8_t pipe_dir,
  76100. + uint16_t mps)
  76101. +{
  76102. + pipe->dev_addr = devaddr;
  76103. + pipe->ep_num = ep_num;
  76104. + pipe->pipe_type = pipe_type;
  76105. + pipe->pipe_dir = pipe_dir;
  76106. + pipe->mps = mps;
  76107. +}
  76108. +
  76109. +/**
  76110. + * Phases for control transfers.
  76111. + */
  76112. +typedef enum dwc_otg_control_phase {
  76113. + DWC_OTG_CONTROL_SETUP,
  76114. + DWC_OTG_CONTROL_DATA,
  76115. + DWC_OTG_CONTROL_STATUS
  76116. +} dwc_otg_control_phase_e;
  76117. +
  76118. +/** Transaction types. */
  76119. +typedef enum dwc_otg_transaction_type {
  76120. + DWC_OTG_TRANSACTION_NONE = 0,
  76121. + DWC_OTG_TRANSACTION_PERIODIC = 1,
  76122. + DWC_OTG_TRANSACTION_NON_PERIODIC = 2,
  76123. + DWC_OTG_TRANSACTION_ALL = DWC_OTG_TRANSACTION_PERIODIC + DWC_OTG_TRANSACTION_NON_PERIODIC
  76124. +} dwc_otg_transaction_type_e;
  76125. +
  76126. +struct dwc_otg_qh;
  76127. +
  76128. +/**
  76129. + * A Queue Transfer Descriptor (QTD) holds the state of a bulk, control,
  76130. + * interrupt, or isochronous transfer. A single QTD is created for each URB
  76131. + * (of one of these types) submitted to the HCD. The transfer associated with
  76132. + * a QTD may require one or multiple transactions.
  76133. + *
  76134. + * A QTD is linked to a Queue Head, which is entered in either the
  76135. + * non-periodic or periodic schedule for execution. When a QTD is chosen for
  76136. + * execution, some or all of its transactions may be executed. After
  76137. + * execution, the state of the QTD is updated. The QTD may be retired if all
  76138. + * its transactions are complete or if an error occurred. Otherwise, it
  76139. + * remains in the schedule so more transactions can be executed later.
  76140. + */
  76141. +typedef struct dwc_otg_qtd {
  76142. + /**
  76143. + * Determines the PID of the next data packet for the data phase of
  76144. + * control transfers. Ignored for other transfer types.<br>
  76145. + * One of the following values:
  76146. + * - DWC_OTG_HC_PID_DATA0
  76147. + * - DWC_OTG_HC_PID_DATA1
  76148. + */
  76149. + uint8_t data_toggle;
  76150. +
  76151. + /** Current phase for control transfers (Setup, Data, or Status). */
  76152. + dwc_otg_control_phase_e control_phase;
  76153. +
  76154. + /** Keep track of the current split type
  76155. + * for FS/LS endpoints on a HS Hub */
  76156. + uint8_t complete_split;
  76157. +
  76158. + /** How many bytes transferred during SSPLIT OUT */
  76159. + uint32_t ssplit_out_xfer_count;
  76160. +
  76161. + /**
  76162. + * Holds the number of bus errors that have occurred for a transaction
  76163. + * within this transfer.
  76164. + */
  76165. + uint8_t error_count;
  76166. +
  76167. + /**
  76168. + * Index of the next frame descriptor for an isochronous transfer. A
  76169. + * frame descriptor describes the buffer position and length of the
  76170. + * data to be transferred in the next scheduled (micro)frame of an
  76171. + * isochronous transfer. It also holds status for that transaction.
  76172. + * The frame index starts at 0.
  76173. + */
  76174. + uint16_t isoc_frame_index;
  76175. +
  76176. + /** Position of the ISOC split on full/low speed */
  76177. + uint8_t isoc_split_pos;
  76178. +
  76179. + /** Position of the ISOC split in the buffer for the current frame */
  76180. + uint16_t isoc_split_offset;
  76181. +
  76182. + /** URB for this transfer */
  76183. + struct dwc_otg_hcd_urb *urb;
  76184. +
  76185. + struct dwc_otg_qh *qh;
  76186. +
  76187. + /** This list of QTDs */
  76188. + DWC_CIRCLEQ_ENTRY(dwc_otg_qtd) qtd_list_entry;
  76189. +
  76190. + /** Indicates if this QTD is currently processed by HW. */
  76191. + uint8_t in_process;
  76192. +
  76193. + /** Number of DMA descriptors for this QTD */
  76194. + uint8_t n_desc;
  76195. +
  76196. + /**
  76197. + * Last activated frame(packet) index.
  76198. + * Used in Descriptor DMA mode only.
  76199. + */
  76200. + uint16_t isoc_frame_index_last;
  76201. +
  76202. +} dwc_otg_qtd_t;
  76203. +
  76204. +DWC_CIRCLEQ_HEAD(dwc_otg_qtd_list, dwc_otg_qtd);
  76205. +
  76206. +/**
  76207. + * A Queue Head (QH) holds the static characteristics of an endpoint and
  76208. + * maintains a list of transfers (QTDs) for that endpoint. A QH structure may
  76209. + * be entered in either the non-periodic or periodic schedule.
  76210. + */
  76211. +typedef struct dwc_otg_qh {
  76212. + /**
  76213. + * Endpoint type.
  76214. + * One of the following values:
  76215. + * - UE_CONTROL
  76216. + * - UE_BULK
  76217. + * - UE_INTERRUPT
  76218. + * - UE_ISOCHRONOUS
  76219. + */
  76220. + uint8_t ep_type;
  76221. + uint8_t ep_is_in;
  76222. +
  76223. + /** wMaxPacketSize Field of Endpoint Descriptor. */
  76224. + uint16_t maxp;
  76225. +
  76226. + /**
  76227. + * Device speed.
  76228. + * One of the following values:
  76229. + * - DWC_OTG_EP_SPEED_LOW
  76230. + * - DWC_OTG_EP_SPEED_FULL
  76231. + * - DWC_OTG_EP_SPEED_HIGH
  76232. + */
  76233. + uint8_t dev_speed;
  76234. +
  76235. + /**
  76236. + * Determines the PID of the next data packet for non-control
  76237. + * transfers. Ignored for control transfers.<br>
  76238. + * One of the following values:
  76239. + * - DWC_OTG_HC_PID_DATA0
  76240. + * - DWC_OTG_HC_PID_DATA1
  76241. + */
  76242. + uint8_t data_toggle;
  76243. +
  76244. + /** Ping state if 1. */
  76245. + uint8_t ping_state;
  76246. +
  76247. + /**
  76248. + * List of QTDs for this QH.
  76249. + */
  76250. + struct dwc_otg_qtd_list qtd_list;
  76251. +
  76252. + /** Host channel currently processing transfers for this QH. */
  76253. + struct dwc_hc *channel;
  76254. +
  76255. + /** Full/low speed endpoint on high-speed hub requires split. */
  76256. + uint8_t do_split;
  76257. +
  76258. + /** @name Periodic schedule information */
  76259. + /** @{ */
  76260. +
  76261. + /** Bandwidth in microseconds per (micro)frame. */
  76262. + uint16_t usecs;
  76263. +
  76264. + /** Interval between transfers in (micro)frames. */
  76265. + uint16_t interval;
  76266. +
  76267. + /**
  76268. + * (micro)frame to initialize a periodic transfer. The transfer
  76269. + * executes in the following (micro)frame.
  76270. + */
  76271. + uint16_t sched_frame;
  76272. +
  76273. + /*
  76274. + ** Frame a NAK was received on this queue head, used to minimise NAK retransmission
  76275. + */
  76276. + uint16_t nak_frame;
  76277. +
  76278. + /** (micro)frame at which last start split was initialized. */
  76279. + uint16_t start_split_frame;
  76280. +
  76281. + /** @} */
  76282. +
  76283. + /**
  76284. + * Used instead of original buffer if
  76285. + * it(physical address) is not dword-aligned.
  76286. + */
  76287. + uint8_t *dw_align_buf;
  76288. + dwc_dma_t dw_align_buf_dma;
  76289. +
  76290. + /** Entry for QH in either the periodic or non-periodic schedule. */
  76291. + dwc_list_link_t qh_list_entry;
  76292. +
  76293. + /** @name Descriptor DMA support */
  76294. + /** @{ */
  76295. +
  76296. + /** Descriptor List. */
  76297. + dwc_otg_host_dma_desc_t *desc_list;
  76298. +
  76299. + /** Descriptor List physical address. */
  76300. + dwc_dma_t desc_list_dma;
  76301. +
  76302. + /**
  76303. + * Xfer Bytes array.
  76304. + * Each element corresponds to a descriptor and indicates
  76305. + * original XferSize size value for the descriptor.
  76306. + */
  76307. + uint32_t *n_bytes;
  76308. +
  76309. + /** Actual number of transfer descriptors in a list. */
  76310. + uint16_t ntd;
  76311. +
  76312. + /** First activated isochronous transfer descriptor index. */
  76313. + uint8_t td_first;
  76314. + /** Last activated isochronous transfer descriptor index. */
  76315. + uint8_t td_last;
  76316. +
  76317. + /** @} */
  76318. +
  76319. +
  76320. + uint16_t speed;
  76321. + uint16_t frame_usecs[8];
  76322. +
  76323. + uint32_t skip_count;
  76324. +} dwc_otg_qh_t;
  76325. +
  76326. +DWC_CIRCLEQ_HEAD(hc_list, dwc_hc);
  76327. +
  76328. +typedef struct urb_tq_entry {
  76329. + struct urb *urb;
  76330. + DWC_TAILQ_ENTRY(urb_tq_entry) urb_tq_entries;
  76331. +} urb_tq_entry_t;
  76332. +
  76333. +DWC_TAILQ_HEAD(urb_list, urb_tq_entry);
  76334. +
  76335. +/**
  76336. + * This structure holds the state of the HCD, including the non-periodic and
  76337. + * periodic schedules.
  76338. + */
  76339. +struct dwc_otg_hcd {
  76340. + /** The DWC otg device pointer */
  76341. + struct dwc_otg_device *otg_dev;
  76342. + /** DWC OTG Core Interface Layer */
  76343. + dwc_otg_core_if_t *core_if;
  76344. +
  76345. + /** Function HCD driver callbacks */
  76346. + struct dwc_otg_hcd_function_ops *fops;
  76347. +
  76348. + /** Internal DWC HCD Flags */
  76349. + volatile union dwc_otg_hcd_internal_flags {
  76350. + uint32_t d32;
  76351. + struct {
  76352. + unsigned port_connect_status_change:1;
  76353. + unsigned port_connect_status:1;
  76354. + unsigned port_reset_change:1;
  76355. + unsigned port_enable_change:1;
  76356. + unsigned port_suspend_change:1;
  76357. + unsigned port_over_current_change:1;
  76358. + unsigned port_l1_change:1;
  76359. + unsigned reserved:26;
  76360. + } b;
  76361. + } flags;
  76362. +
  76363. + /**
  76364. + * Inactive items in the non-periodic schedule. This is a list of
  76365. + * Queue Heads. Transfers associated with these Queue Heads are not
  76366. + * currently assigned to a host channel.
  76367. + */
  76368. + dwc_list_link_t non_periodic_sched_inactive;
  76369. +
  76370. + /**
  76371. + * Active items in the non-periodic schedule. This is a list of
  76372. + * Queue Heads. Transfers associated with these Queue Heads are
  76373. + * currently assigned to a host channel.
  76374. + */
  76375. + dwc_list_link_t non_periodic_sched_active;
  76376. +
  76377. + /**
  76378. + * Pointer to the next Queue Head to process in the active
  76379. + * non-periodic schedule.
  76380. + */
  76381. + dwc_list_link_t *non_periodic_qh_ptr;
  76382. +
  76383. + /**
  76384. + * Inactive items in the periodic schedule. This is a list of QHs for
  76385. + * periodic transfers that are _not_ scheduled for the next frame.
  76386. + * Each QH in the list has an interval counter that determines when it
  76387. + * needs to be scheduled for execution. This scheduling mechanism
  76388. + * allows only a simple calculation for periodic bandwidth used (i.e.
  76389. + * must assume that all periodic transfers may need to execute in the
  76390. + * same frame). However, it greatly simplifies scheduling and should
  76391. + * be sufficient for the vast majority of OTG hosts, which need to
  76392. + * connect to a small number of peripherals at one time.
  76393. + *
  76394. + * Items move from this list to periodic_sched_ready when the QH
  76395. + * interval counter is 0 at SOF.
  76396. + */
  76397. + dwc_list_link_t periodic_sched_inactive;
  76398. +
  76399. + /**
  76400. + * List of periodic QHs that are ready for execution in the next
  76401. + * frame, but have not yet been assigned to host channels.
  76402. + *
  76403. + * Items move from this list to periodic_sched_assigned as host
  76404. + * channels become available during the current frame.
  76405. + */
  76406. + dwc_list_link_t periodic_sched_ready;
  76407. +
  76408. + /**
  76409. + * List of periodic QHs to be executed in the next frame that are
  76410. + * assigned to host channels.
  76411. + *
  76412. + * Items move from this list to periodic_sched_queued as the
  76413. + * transactions for the QH are queued to the DWC_otg controller.
  76414. + */
  76415. + dwc_list_link_t periodic_sched_assigned;
  76416. +
  76417. + /**
  76418. + * List of periodic QHs that have been queued for execution.
  76419. + *
  76420. + * Items move from this list to either periodic_sched_inactive or
  76421. + * periodic_sched_ready when the channel associated with the transfer
  76422. + * is released. If the interval for the QH is 1, the item moves to
  76423. + * periodic_sched_ready because it must be rescheduled for the next
  76424. + * frame. Otherwise, the item moves to periodic_sched_inactive.
  76425. + */
  76426. + dwc_list_link_t periodic_sched_queued;
  76427. +
  76428. + /**
  76429. + * Total bandwidth claimed so far for periodic transfers. This value
  76430. + * is in microseconds per (micro)frame. The assumption is that all
  76431. + * periodic transfers may occur in the same (micro)frame.
  76432. + */
  76433. + uint16_t periodic_usecs;
  76434. +
  76435. + /**
  76436. + * Total bandwidth claimed so far for all periodic transfers
  76437. + * in a frame.
  76438. + * This will include a mixture of HS and FS transfers.
  76439. + * Units are microseconds per (micro)frame.
  76440. + * We have a budget per frame and have to schedule
  76441. + * transactions accordingly.
  76442. + * Watch out for the fact that things are actually scheduled for the
  76443. + * "next frame".
  76444. + */
  76445. + uint16_t frame_usecs[8];
  76446. +
  76447. +
  76448. + /**
  76449. + * Frame number read from the core at SOF. The value ranges from 0 to
  76450. + * DWC_HFNUM_MAX_FRNUM.
  76451. + */
  76452. + uint16_t frame_number;
  76453. +
  76454. + /**
  76455. + * Count of periodic QHs, if using several eps. For SOF enable/disable.
  76456. + */
  76457. + uint16_t periodic_qh_count;
  76458. +
  76459. + /**
  76460. + * Free host channels in the controller. This is a list of
  76461. + * dwc_hc_t items.
  76462. + */
  76463. + struct hc_list free_hc_list;
  76464. + /**
  76465. + * Number of host channels assigned to periodic transfers. Currently
  76466. + * assuming that there is a dedicated host channel for each periodic
  76467. + * transaction and at least one host channel available for
  76468. + * non-periodic transactions.
  76469. + */
  76470. + int periodic_channels; /* microframe_schedule==0 */
  76471. +
  76472. + /**
  76473. + * Number of host channels assigned to non-periodic transfers.
  76474. + */
  76475. + int non_periodic_channels; /* microframe_schedule==0 */
  76476. +
  76477. + /**
  76478. + * Number of host channels assigned to non-periodic transfers.
  76479. + */
  76480. + int available_host_channels;
  76481. +
  76482. + /**
  76483. + * Array of pointers to the host channel descriptors. Allows accessing
  76484. + * a host channel descriptor given the host channel number. This is
  76485. + * useful in interrupt handlers.
  76486. + */
  76487. + struct dwc_hc *hc_ptr_array[MAX_EPS_CHANNELS];
  76488. +
  76489. + /**
  76490. + * Buffer to use for any data received during the status phase of a
  76491. + * control transfer. Normally no data is transferred during the status
  76492. + * phase. This buffer is used as a bit bucket.
  76493. + */
  76494. + uint8_t *status_buf;
  76495. +
  76496. + /**
  76497. + * DMA address for status_buf.
  76498. + */
  76499. + dma_addr_t status_buf_dma;
  76500. +#define DWC_OTG_HCD_STATUS_BUF_SIZE 64
  76501. +
  76502. + /**
  76503. + * Connection timer. An OTG host must display a message if the device
  76504. + * does not connect. Started when the VBus power is turned on via
  76505. + * sysfs attribute "buspower".
  76506. + */
  76507. + dwc_timer_t *conn_timer;
  76508. +
  76509. + /* Tasket to do a reset */
  76510. + dwc_tasklet_t *reset_tasklet;
  76511. +
  76512. + dwc_tasklet_t *completion_tasklet;
  76513. + struct urb_list completed_urb_list;
  76514. +
  76515. + /* */
  76516. + dwc_spinlock_t *lock;
  76517. + dwc_spinlock_t *channel_lock;
  76518. + /**
  76519. + * Private data that could be used by OS wrapper.
  76520. + */
  76521. + void *priv;
  76522. +
  76523. + uint8_t otg_port;
  76524. +
  76525. + /** Frame List */
  76526. + uint32_t *frame_list;
  76527. +
  76528. + /** Hub - Port assignment */
  76529. + int hub_port[128];
  76530. +#ifdef FIQ_DEBUG
  76531. + int hub_port_alloc[2048];
  76532. +#endif
  76533. +
  76534. + /** Frame List DMA address */
  76535. + dma_addr_t frame_list_dma;
  76536. +
  76537. + struct fiq_stack *fiq_stack;
  76538. + struct fiq_state *fiq_state;
  76539. +
  76540. + /** Virtual address for split transaction DMA bounce buffers */
  76541. + struct fiq_dma_blob *fiq_dmab;
  76542. +
  76543. +#ifdef DEBUG
  76544. + uint32_t frrem_samples;
  76545. + uint64_t frrem_accum;
  76546. +
  76547. + uint32_t hfnum_7_samples_a;
  76548. + uint64_t hfnum_7_frrem_accum_a;
  76549. + uint32_t hfnum_0_samples_a;
  76550. + uint64_t hfnum_0_frrem_accum_a;
  76551. + uint32_t hfnum_other_samples_a;
  76552. + uint64_t hfnum_other_frrem_accum_a;
  76553. +
  76554. + uint32_t hfnum_7_samples_b;
  76555. + uint64_t hfnum_7_frrem_accum_b;
  76556. + uint32_t hfnum_0_samples_b;
  76557. + uint64_t hfnum_0_frrem_accum_b;
  76558. + uint32_t hfnum_other_samples_b;
  76559. + uint64_t hfnum_other_frrem_accum_b;
  76560. +#endif
  76561. +};
  76562. +
  76563. +/** @name Transaction Execution Functions */
  76564. +/** @{ */
  76565. +extern dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t
  76566. + * hcd);
  76567. +extern void dwc_otg_hcd_queue_transactions(dwc_otg_hcd_t * hcd,
  76568. + dwc_otg_transaction_type_e tr_type);
  76569. +
  76570. +int dwc_otg_hcd_allocate_port(dwc_otg_hcd_t * hcd, dwc_otg_qh_t *qh);
  76571. +void dwc_otg_hcd_release_port(dwc_otg_hcd_t * dwc_otg_hcd, dwc_otg_qh_t *qh);
  76572. +
  76573. +extern int fiq_fsm_queue_transaction(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh);
  76574. +extern int fiq_fsm_transaction_suitable(dwc_otg_qh_t *qh);
  76575. +extern void dwc_otg_cleanup_fiq_channel(dwc_otg_hcd_t *hcd, uint32_t num);
  76576. +
  76577. +/** @} */
  76578. +
  76579. +/** @name Interrupt Handler Functions */
  76580. +/** @{ */
  76581. +extern int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  76582. +extern int32_t dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  76583. +extern int32_t dwc_otg_hcd_handle_rx_status_q_level_intr(dwc_otg_hcd_t *
  76584. + dwc_otg_hcd);
  76585. +extern int32_t dwc_otg_hcd_handle_np_tx_fifo_empty_intr(dwc_otg_hcd_t *
  76586. + dwc_otg_hcd);
  76587. +extern int32_t dwc_otg_hcd_handle_perio_tx_fifo_empty_intr(dwc_otg_hcd_t *
  76588. + dwc_otg_hcd);
  76589. +extern int32_t dwc_otg_hcd_handle_incomplete_periodic_intr(dwc_otg_hcd_t *
  76590. + dwc_otg_hcd);
  76591. +extern int32_t dwc_otg_hcd_handle_port_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  76592. +extern int32_t dwc_otg_hcd_handle_conn_id_status_change_intr(dwc_otg_hcd_t *
  76593. + dwc_otg_hcd);
  76594. +extern int32_t dwc_otg_hcd_handle_disconnect_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  76595. +extern int32_t dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  76596. +extern int32_t dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd_t * dwc_otg_hcd,
  76597. + uint32_t num);
  76598. +extern int32_t dwc_otg_hcd_handle_session_req_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  76599. +extern int32_t dwc_otg_hcd_handle_wakeup_detected_intr(dwc_otg_hcd_t *
  76600. + dwc_otg_hcd);
  76601. +/** @} */
  76602. +
  76603. +/** @name Schedule Queue Functions */
  76604. +/** @{ */
  76605. +
  76606. +/* Implemented in dwc_otg_hcd_queue.c */
  76607. +extern dwc_otg_qh_t *dwc_otg_hcd_qh_create(dwc_otg_hcd_t * hcd,
  76608. + dwc_otg_hcd_urb_t * urb, int atomic_alloc);
  76609. +extern void dwc_otg_hcd_qh_free(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  76610. +extern int dwc_otg_hcd_qh_add(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  76611. +extern void dwc_otg_hcd_qh_remove(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  76612. +extern void dwc_otg_hcd_qh_deactivate(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  76613. + int sched_csplit);
  76614. +
  76615. +/** Remove and free a QH */
  76616. +static inline void dwc_otg_hcd_qh_remove_and_free(dwc_otg_hcd_t * hcd,
  76617. + dwc_otg_qh_t * qh)
  76618. +{
  76619. + dwc_irqflags_t flags;
  76620. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  76621. + dwc_otg_hcd_qh_remove(hcd, qh);
  76622. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  76623. + dwc_otg_hcd_qh_free(hcd, qh);
  76624. +}
  76625. +
  76626. +/** Allocates memory for a QH structure.
  76627. + * @return Returns the memory allocate or NULL on error. */
  76628. +static inline dwc_otg_qh_t *dwc_otg_hcd_qh_alloc(int atomic_alloc)
  76629. +{
  76630. + if (atomic_alloc)
  76631. + return (dwc_otg_qh_t *) DWC_ALLOC_ATOMIC(sizeof(dwc_otg_qh_t));
  76632. + else
  76633. + return (dwc_otg_qh_t *) DWC_ALLOC(sizeof(dwc_otg_qh_t));
  76634. +}
  76635. +
  76636. +extern dwc_otg_qtd_t *dwc_otg_hcd_qtd_create(dwc_otg_hcd_urb_t * urb,
  76637. + int atomic_alloc);
  76638. +extern void dwc_otg_hcd_qtd_init(dwc_otg_qtd_t * qtd, dwc_otg_hcd_urb_t * urb);
  76639. +extern int dwc_otg_hcd_qtd_add(dwc_otg_qtd_t * qtd, dwc_otg_hcd_t * dwc_otg_hcd,
  76640. + dwc_otg_qh_t ** qh, int atomic_alloc);
  76641. +
  76642. +/** Allocates memory for a QTD structure.
  76643. + * @return Returns the memory allocate or NULL on error. */
  76644. +static inline dwc_otg_qtd_t *dwc_otg_hcd_qtd_alloc(int atomic_alloc)
  76645. +{
  76646. + if (atomic_alloc)
  76647. + return (dwc_otg_qtd_t *) DWC_ALLOC_ATOMIC(sizeof(dwc_otg_qtd_t));
  76648. + else
  76649. + return (dwc_otg_qtd_t *) DWC_ALLOC(sizeof(dwc_otg_qtd_t));
  76650. +}
  76651. +
  76652. +/** Frees the memory for a QTD structure. QTD should already be removed from
  76653. + * list.
  76654. + * @param qtd QTD to free.*/
  76655. +static inline void dwc_otg_hcd_qtd_free(dwc_otg_qtd_t * qtd)
  76656. +{
  76657. + DWC_FREE(qtd);
  76658. +}
  76659. +
  76660. +/** Removes a QTD from list.
  76661. + * @param hcd HCD instance.
  76662. + * @param qtd QTD to remove from list.
  76663. + * @param qh QTD belongs to.
  76664. + */
  76665. +static inline void dwc_otg_hcd_qtd_remove(dwc_otg_hcd_t * hcd,
  76666. + dwc_otg_qtd_t * qtd,
  76667. + dwc_otg_qh_t * qh)
  76668. +{
  76669. + DWC_CIRCLEQ_REMOVE(&qh->qtd_list, qtd, qtd_list_entry);
  76670. +}
  76671. +
  76672. +/** Remove and free a QTD
  76673. + * Need to disable IRQ and hold hcd lock while calling this function out of
  76674. + * interrupt servicing chain */
  76675. +static inline void dwc_otg_hcd_qtd_remove_and_free(dwc_otg_hcd_t * hcd,
  76676. + dwc_otg_qtd_t * qtd,
  76677. + dwc_otg_qh_t * qh)
  76678. +{
  76679. + dwc_otg_hcd_qtd_remove(hcd, qtd, qh);
  76680. + dwc_otg_hcd_qtd_free(qtd);
  76681. +}
  76682. +
  76683. +/** @} */
  76684. +
  76685. +/** @name Descriptor DMA Supporting Functions */
  76686. +/** @{ */
  76687. +
  76688. +extern void dwc_otg_hcd_start_xfer_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  76689. +extern void dwc_otg_hcd_complete_xfer_ddma(dwc_otg_hcd_t * hcd,
  76690. + dwc_hc_t * hc,
  76691. + dwc_otg_hc_regs_t * hc_regs,
  76692. + dwc_otg_halt_status_e halt_status);
  76693. +
  76694. +extern int dwc_otg_hcd_qh_init_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  76695. +extern void dwc_otg_hcd_qh_free_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  76696. +
  76697. +/** @} */
  76698. +
  76699. +/** @name Internal Functions */
  76700. +/** @{ */
  76701. +dwc_otg_qh_t *dwc_urb_to_qh(dwc_otg_hcd_urb_t * urb);
  76702. +/** @} */
  76703. +
  76704. +#ifdef CONFIG_USB_DWC_OTG_LPM
  76705. +extern int dwc_otg_hcd_get_hc_for_lpm_tran(dwc_otg_hcd_t * hcd,
  76706. + uint8_t devaddr);
  76707. +extern void dwc_otg_hcd_free_hc_from_lpm(dwc_otg_hcd_t * hcd);
  76708. +#endif
  76709. +
  76710. +/** Gets the QH that contains the list_head */
  76711. +#define dwc_list_to_qh(_list_head_ptr_) container_of(_list_head_ptr_, dwc_otg_qh_t, qh_list_entry)
  76712. +
  76713. +/** Gets the QTD that contains the list_head */
  76714. +#define dwc_list_to_qtd(_list_head_ptr_) container_of(_list_head_ptr_, dwc_otg_qtd_t, qtd_list_entry)
  76715. +
  76716. +/** Check if QH is non-periodic */
  76717. +#define dwc_qh_is_non_per(_qh_ptr_) ((_qh_ptr_->ep_type == UE_BULK) || \
  76718. + (_qh_ptr_->ep_type == UE_CONTROL))
  76719. +
  76720. +/** High bandwidth multiplier as encoded in highspeed endpoint descriptors */
  76721. +#define dwc_hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
  76722. +
  76723. +/** Packet size for any kind of endpoint descriptor */
  76724. +#define dwc_max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff)
  76725. +
  76726. +/**
  76727. + * Returns true if _frame1 is less than or equal to _frame2. The comparison is
  76728. + * done modulo DWC_HFNUM_MAX_FRNUM. This accounts for the rollover of the
  76729. + * frame number when the max frame number is reached.
  76730. + */
  76731. +static inline int dwc_frame_num_le(uint16_t frame1, uint16_t frame2)
  76732. +{
  76733. + return ((frame2 - frame1) & DWC_HFNUM_MAX_FRNUM) <=
  76734. + (DWC_HFNUM_MAX_FRNUM >> 1);
  76735. +}
  76736. +
  76737. +/**
  76738. + * Returns true if _frame1 is greater than _frame2. The comparison is done
  76739. + * modulo DWC_HFNUM_MAX_FRNUM. This accounts for the rollover of the frame
  76740. + * number when the max frame number is reached.
  76741. + */
  76742. +static inline int dwc_frame_num_gt(uint16_t frame1, uint16_t frame2)
  76743. +{
  76744. + return (frame1 != frame2) &&
  76745. + (((frame1 - frame2) & DWC_HFNUM_MAX_FRNUM) <
  76746. + (DWC_HFNUM_MAX_FRNUM >> 1));
  76747. +}
  76748. +
  76749. +/**
  76750. + * Increments _frame by the amount specified by _inc. The addition is done
  76751. + * modulo DWC_HFNUM_MAX_FRNUM. Returns the incremented value.
  76752. + */
  76753. +static inline uint16_t dwc_frame_num_inc(uint16_t frame, uint16_t inc)
  76754. +{
  76755. + return (frame + inc) & DWC_HFNUM_MAX_FRNUM;
  76756. +}
  76757. +
  76758. +static inline uint16_t dwc_full_frame_num(uint16_t frame)
  76759. +{
  76760. + return (frame & DWC_HFNUM_MAX_FRNUM) >> 3;
  76761. +}
  76762. +
  76763. +static inline uint16_t dwc_micro_frame_num(uint16_t frame)
  76764. +{
  76765. + return frame & 0x7;
  76766. +}
  76767. +
  76768. +void dwc_otg_hcd_save_data_toggle(dwc_hc_t * hc,
  76769. + dwc_otg_hc_regs_t * hc_regs,
  76770. + dwc_otg_qtd_t * qtd);
  76771. +
  76772. +#ifdef DEBUG
  76773. +/**
  76774. + * Macro to sample the remaining PHY clocks left in the current frame. This
  76775. + * may be used during debugging to determine the average time it takes to
  76776. + * execute sections of code. There are two possible sample points, "a" and
  76777. + * "b", so the _letter argument must be one of these values.
  76778. + *
  76779. + * To dump the average sample times, read the "hcd_frrem" sysfs attribute. For
  76780. + * example, "cat /sys/devices/lm0/hcd_frrem".
  76781. + */
  76782. +#define dwc_sample_frrem(_hcd, _qh, _letter) \
  76783. +{ \
  76784. + hfnum_data_t hfnum; \
  76785. + dwc_otg_qtd_t *qtd; \
  76786. + qtd = list_entry(_qh->qtd_list.next, dwc_otg_qtd_t, qtd_list_entry); \
  76787. + if (usb_pipeint(qtd->urb->pipe) && _qh->start_split_frame != 0 && !qtd->complete_split) { \
  76788. + hfnum.d32 = DWC_READ_REG32(&_hcd->core_if->host_if->host_global_regs->hfnum); \
  76789. + switch (hfnum.b.frnum & 0x7) { \
  76790. + case 7: \
  76791. + _hcd->hfnum_7_samples_##_letter++; \
  76792. + _hcd->hfnum_7_frrem_accum_##_letter += hfnum.b.frrem; \
  76793. + break; \
  76794. + case 0: \
  76795. + _hcd->hfnum_0_samples_##_letter++; \
  76796. + _hcd->hfnum_0_frrem_accum_##_letter += hfnum.b.frrem; \
  76797. + break; \
  76798. + default: \
  76799. + _hcd->hfnum_other_samples_##_letter++; \
  76800. + _hcd->hfnum_other_frrem_accum_##_letter += hfnum.b.frrem; \
  76801. + break; \
  76802. + } \
  76803. + } \
  76804. +}
  76805. +#else
  76806. +#define dwc_sample_frrem(_hcd, _qh, _letter)
  76807. +#endif
  76808. +#endif
  76809. +#endif /* DWC_DEVICE_ONLY */
  76810. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h
  76811. --- linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h 1970-01-01 01:00:00.000000000 +0100
  76812. +++ linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h 2014-08-06 16:50:14.817964852 +0200
  76813. @@ -0,0 +1,417 @@
  76814. +/* ==========================================================================
  76815. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_if.h $
  76816. + * $Revision: #12 $
  76817. + * $Date: 2011/10/26 $
  76818. + * $Change: 1873028 $
  76819. + *
  76820. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  76821. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  76822. + * otherwise expressly agreed to in writing between Synopsys and you.
  76823. + *
  76824. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  76825. + * any End User Software License Agreement or Agreement for Licensed Product
  76826. + * with Synopsys or any supplement thereto. You are permitted to use and
  76827. + * redistribute this Software in source and binary forms, with or without
  76828. + * modification, provided that redistributions of source code must retain this
  76829. + * notice. You may not view, use, disclose, copy or distribute this file or
  76830. + * any information contained herein except pursuant to this license grant from
  76831. + * Synopsys. If you do not agree with this notice, including the disclaimer
  76832. + * below, then you are not authorized to use the Software.
  76833. + *
  76834. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  76835. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  76836. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  76837. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  76838. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  76839. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  76840. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  76841. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  76842. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  76843. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  76844. + * DAMAGE.
  76845. + * ========================================================================== */
  76846. +#ifndef DWC_DEVICE_ONLY
  76847. +#ifndef __DWC_HCD_IF_H__
  76848. +#define __DWC_HCD_IF_H__
  76849. +
  76850. +#include "dwc_otg_core_if.h"
  76851. +
  76852. +/** @file
  76853. + * This file defines DWC_OTG HCD Core API.
  76854. + */
  76855. +
  76856. +struct dwc_otg_hcd;
  76857. +typedef struct dwc_otg_hcd dwc_otg_hcd_t;
  76858. +
  76859. +struct dwc_otg_hcd_urb;
  76860. +typedef struct dwc_otg_hcd_urb dwc_otg_hcd_urb_t;
  76861. +
  76862. +/** @name HCD Function Driver Callbacks */
  76863. +/** @{ */
  76864. +
  76865. +/** This function is called whenever core switches to host mode. */
  76866. +typedef int (*dwc_otg_hcd_start_cb_t) (dwc_otg_hcd_t * hcd);
  76867. +
  76868. +/** This function is called when device has been disconnected */
  76869. +typedef int (*dwc_otg_hcd_disconnect_cb_t) (dwc_otg_hcd_t * hcd);
  76870. +
  76871. +/** Wrapper provides this function to HCD to core, so it can get hub information to which device is connected */
  76872. +typedef int (*dwc_otg_hcd_hub_info_from_urb_cb_t) (dwc_otg_hcd_t * hcd,
  76873. + void *urb_handle,
  76874. + uint32_t * hub_addr,
  76875. + uint32_t * port_addr);
  76876. +/** Via this function HCD core gets device speed */
  76877. +typedef int (*dwc_otg_hcd_speed_from_urb_cb_t) (dwc_otg_hcd_t * hcd,
  76878. + void *urb_handle);
  76879. +
  76880. +/** This function is called when urb is completed */
  76881. +typedef int (*dwc_otg_hcd_complete_urb_cb_t) (dwc_otg_hcd_t * hcd,
  76882. + void *urb_handle,
  76883. + dwc_otg_hcd_urb_t * dwc_otg_urb,
  76884. + int32_t status);
  76885. +
  76886. +/** Via this function HCD core gets b_hnp_enable parameter */
  76887. +typedef int (*dwc_otg_hcd_get_b_hnp_enable) (dwc_otg_hcd_t * hcd);
  76888. +
  76889. +struct dwc_otg_hcd_function_ops {
  76890. + dwc_otg_hcd_start_cb_t start;
  76891. + dwc_otg_hcd_disconnect_cb_t disconnect;
  76892. + dwc_otg_hcd_hub_info_from_urb_cb_t hub_info;
  76893. + dwc_otg_hcd_speed_from_urb_cb_t speed;
  76894. + dwc_otg_hcd_complete_urb_cb_t complete;
  76895. + dwc_otg_hcd_get_b_hnp_enable get_b_hnp_enable;
  76896. +};
  76897. +/** @} */
  76898. +
  76899. +/** @name HCD Core API */
  76900. +/** @{ */
  76901. +/** This function allocates dwc_otg_hcd structure and returns pointer on it. */
  76902. +extern dwc_otg_hcd_t *dwc_otg_hcd_alloc_hcd(void);
  76903. +
  76904. +/** This function should be called to initiate HCD Core.
  76905. + *
  76906. + * @param hcd The HCD
  76907. + * @param core_if The DWC_OTG Core
  76908. + *
  76909. + * Returns -DWC_E_NO_MEMORY if no enough memory.
  76910. + * Returns 0 on success
  76911. + */
  76912. +extern int dwc_otg_hcd_init(dwc_otg_hcd_t * hcd, dwc_otg_core_if_t * core_if);
  76913. +
  76914. +/** Frees HCD
  76915. + *
  76916. + * @param hcd The HCD
  76917. + */
  76918. +extern void dwc_otg_hcd_remove(dwc_otg_hcd_t * hcd);
  76919. +
  76920. +/** This function should be called on every hardware interrupt.
  76921. + *
  76922. + * @param dwc_otg_hcd The HCD
  76923. + *
  76924. + * Returns non zero if interrupt is handled
  76925. + * Return 0 if interrupt is not handled
  76926. + */
  76927. +extern int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  76928. +
  76929. +/** This function is used to handle the fast interrupt
  76930. + *
  76931. + */
  76932. +extern void __attribute__ ((naked)) dwc_otg_hcd_handle_fiq(void);
  76933. +
  76934. +/**
  76935. + * Returns private data set by
  76936. + * dwc_otg_hcd_set_priv_data function.
  76937. + *
  76938. + * @param hcd The HCD
  76939. + */
  76940. +extern void *dwc_otg_hcd_get_priv_data(dwc_otg_hcd_t * hcd);
  76941. +
  76942. +/**
  76943. + * Set private data.
  76944. + *
  76945. + * @param hcd The HCD
  76946. + * @param priv_data pointer to be stored in private data
  76947. + */
  76948. +extern void dwc_otg_hcd_set_priv_data(dwc_otg_hcd_t * hcd, void *priv_data);
  76949. +
  76950. +/**
  76951. + * This function initializes the HCD Core.
  76952. + *
  76953. + * @param hcd The HCD
  76954. + * @param fops The Function Driver Operations data structure containing pointers to all callbacks.
  76955. + *
  76956. + * Returns -DWC_E_NO_DEVICE if Core is currently is in device mode.
  76957. + * Returns 0 on success
  76958. + */
  76959. +extern int dwc_otg_hcd_start(dwc_otg_hcd_t * hcd,
  76960. + struct dwc_otg_hcd_function_ops *fops);
  76961. +
  76962. +/**
  76963. + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
  76964. + * stopped.
  76965. + *
  76966. + * @param hcd The HCD
  76967. + */
  76968. +extern void dwc_otg_hcd_stop(dwc_otg_hcd_t * hcd);
  76969. +
  76970. +/**
  76971. + * Handles hub class-specific requests.
  76972. + *
  76973. + * @param dwc_otg_hcd The HCD
  76974. + * @param typeReq Request Type
  76975. + * @param wValue wValue from control request
  76976. + * @param wIndex wIndex from control request
  76977. + * @param buf data buffer
  76978. + * @param wLength data buffer length
  76979. + *
  76980. + * Returns -DWC_E_INVALID if invalid argument is passed
  76981. + * Returns 0 on success
  76982. + */
  76983. +extern int dwc_otg_hcd_hub_control(dwc_otg_hcd_t * dwc_otg_hcd,
  76984. + uint16_t typeReq, uint16_t wValue,
  76985. + uint16_t wIndex, uint8_t * buf,
  76986. + uint16_t wLength);
  76987. +
  76988. +/**
  76989. + * Returns otg port number.
  76990. + *
  76991. + * @param hcd The HCD
  76992. + */
  76993. +extern uint32_t dwc_otg_hcd_otg_port(dwc_otg_hcd_t * hcd);
  76994. +
  76995. +/**
  76996. + * Returns OTG version - either 1.3 or 2.0.
  76997. + *
  76998. + * @param core_if The core_if structure pointer
  76999. + */
  77000. +extern uint16_t dwc_otg_get_otg_version(dwc_otg_core_if_t * core_if);
  77001. +
  77002. +/**
  77003. + * Returns 1 if currently core is acting as B host, and 0 otherwise.
  77004. + *
  77005. + * @param hcd The HCD
  77006. + */
  77007. +extern uint32_t dwc_otg_hcd_is_b_host(dwc_otg_hcd_t * hcd);
  77008. +
  77009. +/**
  77010. + * Returns current frame number.
  77011. + *
  77012. + * @param hcd The HCD
  77013. + */
  77014. +extern int dwc_otg_hcd_get_frame_number(dwc_otg_hcd_t * hcd);
  77015. +
  77016. +/**
  77017. + * Dumps hcd state.
  77018. + *
  77019. + * @param hcd The HCD
  77020. + */
  77021. +extern void dwc_otg_hcd_dump_state(dwc_otg_hcd_t * hcd);
  77022. +
  77023. +/**
  77024. + * Dump the average frame remaining at SOF. This can be used to
  77025. + * determine average interrupt latency. Frame remaining is also shown for
  77026. + * start transfer and two additional sample points.
  77027. + * Currently this function is not implemented.
  77028. + *
  77029. + * @param hcd The HCD
  77030. + */
  77031. +extern void dwc_otg_hcd_dump_frrem(dwc_otg_hcd_t * hcd);
  77032. +
  77033. +/**
  77034. + * Sends LPM transaction to the local device.
  77035. + *
  77036. + * @param hcd The HCD
  77037. + * @param devaddr Device Address
  77038. + * @param hird Host initiated resume duration
  77039. + * @param bRemoteWake Value of bRemoteWake field in LPM transaction
  77040. + *
  77041. + * Returns negative value if sending LPM transaction was not succeeded.
  77042. + * Returns 0 on success.
  77043. + */
  77044. +extern int dwc_otg_hcd_send_lpm(dwc_otg_hcd_t * hcd, uint8_t devaddr,
  77045. + uint8_t hird, uint8_t bRemoteWake);
  77046. +
  77047. +/* URB interface */
  77048. +
  77049. +/**
  77050. + * Allocates memory for dwc_otg_hcd_urb structure.
  77051. + * Allocated memory should be freed by call of DWC_FREE.
  77052. + *
  77053. + * @param hcd The HCD
  77054. + * @param iso_desc_count Count of ISOC descriptors
  77055. + * @param atomic_alloc Specefies whether to perform atomic allocation.
  77056. + */
  77057. +extern dwc_otg_hcd_urb_t *dwc_otg_hcd_urb_alloc(dwc_otg_hcd_t * hcd,
  77058. + int iso_desc_count,
  77059. + int atomic_alloc);
  77060. +
  77061. +/**
  77062. + * Set pipe information in URB.
  77063. + *
  77064. + * @param hcd_urb DWC_OTG URB
  77065. + * @param devaddr Device Address
  77066. + * @param ep_num Endpoint Number
  77067. + * @param ep_type Endpoint Type
  77068. + * @param ep_dir Endpoint Direction
  77069. + * @param mps Max Packet Size
  77070. + */
  77071. +extern void dwc_otg_hcd_urb_set_pipeinfo(dwc_otg_hcd_urb_t * hcd_urb,
  77072. + uint8_t devaddr, uint8_t ep_num,
  77073. + uint8_t ep_type, uint8_t ep_dir,
  77074. + uint16_t mps);
  77075. +
  77076. +/* Transfer flags */
  77077. +#define URB_GIVEBACK_ASAP 0x1
  77078. +#define URB_SEND_ZERO_PACKET 0x2
  77079. +
  77080. +/**
  77081. + * Sets dwc_otg_hcd_urb parameters.
  77082. + *
  77083. + * @param urb DWC_OTG URB allocated by dwc_otg_hcd_urb_alloc function.
  77084. + * @param urb_handle Unique handle for request, this will be passed back
  77085. + * to function driver in completion callback.
  77086. + * @param buf The buffer for the data
  77087. + * @param dma The DMA buffer for the data
  77088. + * @param buflen Transfer length
  77089. + * @param sp Buffer for setup data
  77090. + * @param sp_dma DMA address of setup data buffer
  77091. + * @param flags Transfer flags
  77092. + * @param interval Polling interval for interrupt or isochronous transfers.
  77093. + */
  77094. +extern void dwc_otg_hcd_urb_set_params(dwc_otg_hcd_urb_t * urb,
  77095. + void *urb_handle, void *buf,
  77096. + dwc_dma_t dma, uint32_t buflen, void *sp,
  77097. + dwc_dma_t sp_dma, uint32_t flags,
  77098. + uint16_t interval);
  77099. +
  77100. +/** Gets status from dwc_otg_hcd_urb
  77101. + *
  77102. + * @param dwc_otg_urb DWC_OTG URB
  77103. + */
  77104. +extern uint32_t dwc_otg_hcd_urb_get_status(dwc_otg_hcd_urb_t * dwc_otg_urb);
  77105. +
  77106. +/** Gets actual length from dwc_otg_hcd_urb
  77107. + *
  77108. + * @param dwc_otg_urb DWC_OTG URB
  77109. + */
  77110. +extern uint32_t dwc_otg_hcd_urb_get_actual_length(dwc_otg_hcd_urb_t *
  77111. + dwc_otg_urb);
  77112. +
  77113. +/** Gets error count from dwc_otg_hcd_urb. Only for ISOC URBs
  77114. + *
  77115. + * @param dwc_otg_urb DWC_OTG URB
  77116. + */
  77117. +extern uint32_t dwc_otg_hcd_urb_get_error_count(dwc_otg_hcd_urb_t *
  77118. + dwc_otg_urb);
  77119. +
  77120. +/** Set ISOC descriptor offset and length
  77121. + *
  77122. + * @param dwc_otg_urb DWC_OTG URB
  77123. + * @param desc_num ISOC descriptor number
  77124. + * @param offset Offset from beginig of buffer.
  77125. + * @param length Transaction length
  77126. + */
  77127. +extern void dwc_otg_hcd_urb_set_iso_desc_params(dwc_otg_hcd_urb_t * dwc_otg_urb,
  77128. + int desc_num, uint32_t offset,
  77129. + uint32_t length);
  77130. +
  77131. +/** Get status of ISOC descriptor, specified by desc_num
  77132. + *
  77133. + * @param dwc_otg_urb DWC_OTG URB
  77134. + * @param desc_num ISOC descriptor number
  77135. + */
  77136. +extern uint32_t dwc_otg_hcd_urb_get_iso_desc_status(dwc_otg_hcd_urb_t *
  77137. + dwc_otg_urb, int desc_num);
  77138. +
  77139. +/** Get actual length of ISOC descriptor, specified by desc_num
  77140. + *
  77141. + * @param dwc_otg_urb DWC_OTG URB
  77142. + * @param desc_num ISOC descriptor number
  77143. + */
  77144. +extern uint32_t dwc_otg_hcd_urb_get_iso_desc_actual_length(dwc_otg_hcd_urb_t *
  77145. + dwc_otg_urb,
  77146. + int desc_num);
  77147. +
  77148. +/** Queue URB. After transfer is completes, the complete callback will be called with the URB status
  77149. + *
  77150. + * @param dwc_otg_hcd The HCD
  77151. + * @param dwc_otg_urb DWC_OTG URB
  77152. + * @param ep_handle Out parameter for returning endpoint handle
  77153. + * @param atomic_alloc Flag to do atomic allocation if needed
  77154. + *
  77155. + * Returns -DWC_E_NO_DEVICE if no device is connected.
  77156. + * Returns -DWC_E_NO_MEMORY if there is no enough memory.
  77157. + * Returns 0 on success.
  77158. + */
  77159. +extern int dwc_otg_hcd_urb_enqueue(dwc_otg_hcd_t * dwc_otg_hcd,
  77160. + dwc_otg_hcd_urb_t * dwc_otg_urb,
  77161. + void **ep_handle, int atomic_alloc);
  77162. +
  77163. +/** De-queue the specified URB
  77164. + *
  77165. + * @param dwc_otg_hcd The HCD
  77166. + * @param dwc_otg_urb DWC_OTG URB
  77167. + */
  77168. +extern int dwc_otg_hcd_urb_dequeue(dwc_otg_hcd_t * dwc_otg_hcd,
  77169. + dwc_otg_hcd_urb_t * dwc_otg_urb);
  77170. +
  77171. +/** Frees resources in the DWC_otg controller related to a given endpoint.
  77172. + * Any URBs for the endpoint must already be dequeued.
  77173. + *
  77174. + * @param hcd The HCD
  77175. + * @param ep_handle Endpoint handle, returned by dwc_otg_hcd_urb_enqueue function
  77176. + * @param retry Number of retries if there are queued transfers.
  77177. + *
  77178. + * Returns -DWC_E_INVALID if invalid arguments are passed.
  77179. + * Returns 0 on success
  77180. + */
  77181. +extern int dwc_otg_hcd_endpoint_disable(dwc_otg_hcd_t * hcd, void *ep_handle,
  77182. + int retry);
  77183. +
  77184. +/* Resets the data toggle in qh structure. This function can be called from
  77185. + * usb_clear_halt routine.
  77186. + *
  77187. + * @param hcd The HCD
  77188. + * @param ep_handle Endpoint handle, returned by dwc_otg_hcd_urb_enqueue function
  77189. + *
  77190. + * Returns -DWC_E_INVALID if invalid arguments are passed.
  77191. + * Returns 0 on success
  77192. + */
  77193. +extern int dwc_otg_hcd_endpoint_reset(dwc_otg_hcd_t * hcd, void *ep_handle);
  77194. +
  77195. +/** Returns 1 if status of specified port is changed and 0 otherwise.
  77196. + *
  77197. + * @param hcd The HCD
  77198. + * @param port Port number
  77199. + */
  77200. +extern int dwc_otg_hcd_is_status_changed(dwc_otg_hcd_t * hcd, int port);
  77201. +
  77202. +/** Call this function to check if bandwidth was allocated for specified endpoint.
  77203. + * Only for ISOC and INTERRUPT endpoints.
  77204. + *
  77205. + * @param hcd The HCD
  77206. + * @param ep_handle Endpoint handle
  77207. + */
  77208. +extern int dwc_otg_hcd_is_bandwidth_allocated(dwc_otg_hcd_t * hcd,
  77209. + void *ep_handle);
  77210. +
  77211. +/** Call this function to check if bandwidth was freed for specified endpoint.
  77212. + *
  77213. + * @param hcd The HCD
  77214. + * @param ep_handle Endpoint handle
  77215. + */
  77216. +extern int dwc_otg_hcd_is_bandwidth_freed(dwc_otg_hcd_t * hcd, void *ep_handle);
  77217. +
  77218. +/** Returns bandwidth allocated for specified endpoint in microseconds.
  77219. + * Only for ISOC and INTERRUPT endpoints.
  77220. + *
  77221. + * @param hcd The HCD
  77222. + * @param ep_handle Endpoint handle
  77223. + */
  77224. +extern uint8_t dwc_otg_hcd_get_ep_bandwidth(dwc_otg_hcd_t * hcd,
  77225. + void *ep_handle);
  77226. +
  77227. +/** @} */
  77228. +
  77229. +#endif /* __DWC_HCD_IF_H__ */
  77230. +#endif /* DWC_DEVICE_ONLY */
  77231. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c
  77232. --- linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c 1970-01-01 01:00:00.000000000 +0100
  77233. +++ linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c 2014-08-06 16:50:14.817964852 +0200
  77234. @@ -0,0 +1,2681 @@
  77235. +/* ==========================================================================
  77236. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_intr.c $
  77237. + * $Revision: #89 $
  77238. + * $Date: 2011/10/20 $
  77239. + * $Change: 1869487 $
  77240. + *
  77241. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  77242. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  77243. + * otherwise expressly agreed to in writing between Synopsys and you.
  77244. + *
  77245. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  77246. + * any End User Software License Agreement or Agreement for Licensed Product
  77247. + * with Synopsys or any supplement thereto. You are permitted to use and
  77248. + * redistribute this Software in source and binary forms, with or without
  77249. + * modification, provided that redistributions of source code must retain this
  77250. + * notice. You may not view, use, disclose, copy or distribute this file or
  77251. + * any information contained herein except pursuant to this license grant from
  77252. + * Synopsys. If you do not agree with this notice, including the disclaimer
  77253. + * below, then you are not authorized to use the Software.
  77254. + *
  77255. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  77256. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  77257. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  77258. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  77259. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  77260. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  77261. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  77262. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  77263. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  77264. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  77265. + * DAMAGE.
  77266. + * ========================================================================== */
  77267. +#ifndef DWC_DEVICE_ONLY
  77268. +
  77269. +#include "dwc_otg_hcd.h"
  77270. +#include "dwc_otg_regs.h"
  77271. +
  77272. +#include <linux/jiffies.h>
  77273. +#include <mach/hardware.h>
  77274. +#include <asm/fiq.h>
  77275. +
  77276. +
  77277. +extern bool microframe_schedule;
  77278. +
  77279. +/** @file
  77280. + * This file contains the implementation of the HCD Interrupt handlers.
  77281. + */
  77282. +
  77283. +int fiq_done, int_done;
  77284. +
  77285. +#ifdef FIQ_DEBUG
  77286. +char buffer[1000*16];
  77287. +int wptr;
  77288. +void notrace _fiq_print(FIQDBG_T dbg_lvl, char *fmt, ...)
  77289. +{
  77290. + FIQDBG_T dbg_lvl_req = FIQDBG_PORTHUB;
  77291. + va_list args;
  77292. + char text[17];
  77293. + hfnum_data_t hfnum = { .d32 = FIQ_READ(dwc_regs_base + 0x408) };
  77294. +
  77295. + if(dbg_lvl & dbg_lvl_req || dbg_lvl == FIQDBG_ERR)
  77296. + {
  77297. + local_fiq_disable();
  77298. + snprintf(text, 9, "%4d%d:%d ", hfnum.b.frnum/8, hfnum.b.frnum%8, 8 - hfnum.b.frrem/937);
  77299. + va_start(args, fmt);
  77300. + vsnprintf(text+8, 9, fmt, args);
  77301. + va_end(args);
  77302. +
  77303. + memcpy(buffer + wptr, text, 16);
  77304. + wptr = (wptr + 16) % sizeof(buffer);
  77305. + local_fiq_enable();
  77306. + }
  77307. +}
  77308. +#endif
  77309. +
  77310. +/** This function handles interrupts for the HCD. */
  77311. +int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  77312. +{
  77313. + int retval = 0;
  77314. + static int last_time;
  77315. + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
  77316. + gintsts_data_t gintsts;
  77317. + gintmsk_data_t gintmsk;
  77318. + hfnum_data_t hfnum;
  77319. + haintmsk_data_t haintmsk;
  77320. +
  77321. +#ifdef DEBUG
  77322. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  77323. +
  77324. +#endif
  77325. +
  77326. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  77327. + gintmsk.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  77328. +
  77329. + /* Exit from ISR if core is hibernated */
  77330. + if (core_if->hibernation_suspend == 1) {
  77331. + goto exit_handler_routine;
  77332. + }
  77333. + DWC_SPINLOCK(dwc_otg_hcd->lock);
  77334. + /* Check if HOST Mode */
  77335. + if (dwc_otg_is_host_mode(core_if)) {
  77336. + local_fiq_disable();
  77337. + /* Pull in from the FIQ's disabled mask */
  77338. + gintmsk.d32 = gintmsk.d32 | ~(dwc_otg_hcd->fiq_state->gintmsk_saved.d32);
  77339. + dwc_otg_hcd->fiq_state->gintmsk_saved.d32 = ~0;
  77340. +
  77341. +
  77342. + if (fiq_fsm_enable && ( 0x0000FFFF & ~(dwc_otg_hcd->fiq_state->haintmsk_saved.b2.chint))) {
  77343. + gintsts.b.hcintr = 1;
  77344. + }
  77345. +
  77346. + /* Danger will robinson: fake a SOF if necessary */
  77347. + if (fiq_fsm_enable && (dwc_otg_hcd->fiq_state->gintmsk_saved.b.sofintr == 1)) {
  77348. + gintsts.b.sofintr = 1;
  77349. + }
  77350. + gintsts.d32 &= gintmsk.d32;
  77351. +
  77352. + local_fiq_enable();
  77353. + if (!gintsts.d32) {
  77354. + goto exit_handler_routine;
  77355. + }
  77356. +
  77357. +#ifdef DEBUG
  77358. + // We should be OK doing this because the common interrupts should already have been serviced
  77359. + /* Don't print debug message in the interrupt handler on SOF */
  77360. +#ifndef DEBUG_SOF
  77361. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  77362. +#endif
  77363. + DWC_DEBUGPL(DBG_HCDI, "\n");
  77364. +#endif
  77365. +
  77366. +#ifdef DEBUG
  77367. +#ifndef DEBUG_SOF
  77368. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  77369. +#endif
  77370. + DWC_DEBUGPL(DBG_HCDI,
  77371. + "DWC OTG HCD Interrupt Detected gintsts&gintmsk=0x%08x core_if=%p\n",
  77372. + gintsts.d32, core_if);
  77373. +#endif
  77374. + hfnum.d32 = DWC_READ_REG32(&dwc_otg_hcd->core_if->host_if->host_global_regs->hfnum);
  77375. + if (gintsts.b.sofintr) {
  77376. + retval |= dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd);
  77377. + }
  77378. +
  77379. + if (gintsts.b.rxstsqlvl) {
  77380. + retval |=
  77381. + dwc_otg_hcd_handle_rx_status_q_level_intr
  77382. + (dwc_otg_hcd);
  77383. + }
  77384. + if (gintsts.b.nptxfempty) {
  77385. + retval |=
  77386. + dwc_otg_hcd_handle_np_tx_fifo_empty_intr
  77387. + (dwc_otg_hcd);
  77388. + }
  77389. + if (gintsts.b.i2cintr) {
  77390. + /** @todo Implement i2cintr handler. */
  77391. + }
  77392. + if (gintsts.b.portintr) {
  77393. +
  77394. + gintmsk_data_t gintmsk = { .b.portintr = 1};
  77395. + retval |= dwc_otg_hcd_handle_port_intr(dwc_otg_hcd);
  77396. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, gintmsk.d32);
  77397. + }
  77398. + if (gintsts.b.hcintr) {
  77399. + retval |= dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd);
  77400. + }
  77401. + if (gintsts.b.ptxfempty) {
  77402. + retval |=
  77403. + dwc_otg_hcd_handle_perio_tx_fifo_empty_intr
  77404. + (dwc_otg_hcd);
  77405. + }
  77406. +#ifdef DEBUG
  77407. +#ifndef DEBUG_SOF
  77408. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  77409. +#endif
  77410. + {
  77411. + DWC_DEBUGPL(DBG_HCDI,
  77412. + "DWC OTG HCD Finished Servicing Interrupts\n");
  77413. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD gintsts=0x%08x\n",
  77414. + DWC_READ_REG32(&global_regs->gintsts));
  77415. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD gintmsk=0x%08x\n",
  77416. + DWC_READ_REG32(&global_regs->gintmsk));
  77417. + }
  77418. +#endif
  77419. +
  77420. +#ifdef DEBUG
  77421. +#ifndef DEBUG_SOF
  77422. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  77423. +#endif
  77424. + DWC_DEBUGPL(DBG_HCDI, "\n");
  77425. +#endif
  77426. +
  77427. + }
  77428. +
  77429. +exit_handler_routine:
  77430. + if (fiq_enable) {
  77431. + gintmsk_data_t gintmsk_new;
  77432. + haintmsk_data_t haintmsk_new;
  77433. + local_fiq_disable();
  77434. + gintmsk_new.d32 = *(volatile uint32_t *)&dwc_otg_hcd->fiq_state->gintmsk_saved.d32;
  77435. + if(fiq_fsm_enable)
  77436. + haintmsk_new.d32 = *(volatile uint32_t *)&dwc_otg_hcd->fiq_state->haintmsk_saved.d32;
  77437. + else
  77438. + haintmsk_new.d32 = 0x0000FFFF;
  77439. +
  77440. + /* The FIQ could have sneaked another interrupt in. If so, don't clear MPHI */
  77441. + if ((gintmsk_new.d32 == ~0) && (haintmsk_new.d32 == 0x0000FFFF)) {
  77442. + DWC_WRITE_REG32(dwc_otg_hcd->fiq_state->mphi_regs.intstat, (1<<16));
  77443. + if (dwc_otg_hcd->fiq_state->mphi_int_count >= 50) {
  77444. + fiq_print(FIQDBG_INT, dwc_otg_hcd->fiq_state, "MPHI CLR");
  77445. + DWC_WRITE_REG32(dwc_otg_hcd->fiq_state->mphi_regs.ctrl, ((1<<31) + (1<<16)));
  77446. + while (!(DWC_READ_REG32(dwc_otg_hcd->fiq_state->mphi_regs.ctrl) & (1 << 17)))
  77447. + ;
  77448. + DWC_WRITE_REG32(dwc_otg_hcd->fiq_state->mphi_regs.ctrl, (1<<31));
  77449. + dwc_otg_hcd->fiq_state->mphi_int_count = 0;
  77450. + }
  77451. + int_done++;
  77452. + }
  77453. + haintmsk.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->haintmsk);
  77454. + /* Re-enable interrupts that the FIQ masked (first time round) */
  77455. + FIQ_WRITE(dwc_otg_hcd->fiq_state->dwc_regs_base + GINTMSK, gintmsk.d32);
  77456. + local_fiq_enable();
  77457. +
  77458. + if ((jiffies / HZ) > last_time) {
  77459. + //dwc_otg_qh_t *qh;
  77460. + //dwc_list_link_t *cur;
  77461. + /* Once a second output the fiq and irq numbers, useful for debug */
  77462. + last_time = jiffies / HZ;
  77463. + // DWC_WARN("np_kick=%d AHC=%d sched_frame=%d cur_frame=%d int_done=%d fiq_done=%d",
  77464. + // dwc_otg_hcd->fiq_state->kick_np_queues, dwc_otg_hcd->available_host_channels,
  77465. + // dwc_otg_hcd->fiq_state->next_sched_frame, hfnum.b.frnum, int_done, dwc_otg_hcd->fiq_state->fiq_done);
  77466. + //printk(KERN_WARNING "Periodic queues:\n");
  77467. + }
  77468. + }
  77469. +
  77470. + DWC_SPINUNLOCK(dwc_otg_hcd->lock);
  77471. + return retval;
  77472. +}
  77473. +
  77474. +#ifdef DWC_TRACK_MISSED_SOFS
  77475. +
  77476. +#warning Compiling code to track missed SOFs
  77477. +#define FRAME_NUM_ARRAY_SIZE 1000
  77478. +/**
  77479. + * This function is for debug only.
  77480. + */
  77481. +static inline void track_missed_sofs(uint16_t curr_frame_number)
  77482. +{
  77483. + static uint16_t frame_num_array[FRAME_NUM_ARRAY_SIZE];
  77484. + static uint16_t last_frame_num_array[FRAME_NUM_ARRAY_SIZE];
  77485. + static int frame_num_idx = 0;
  77486. + static uint16_t last_frame_num = DWC_HFNUM_MAX_FRNUM;
  77487. + static int dumped_frame_num_array = 0;
  77488. +
  77489. + if (frame_num_idx < FRAME_NUM_ARRAY_SIZE) {
  77490. + if (((last_frame_num + 1) & DWC_HFNUM_MAX_FRNUM) !=
  77491. + curr_frame_number) {
  77492. + frame_num_array[frame_num_idx] = curr_frame_number;
  77493. + last_frame_num_array[frame_num_idx++] = last_frame_num;
  77494. + }
  77495. + } else if (!dumped_frame_num_array) {
  77496. + int i;
  77497. + DWC_PRINTF("Frame Last Frame\n");
  77498. + DWC_PRINTF("----- ----------\n");
  77499. + for (i = 0; i < FRAME_NUM_ARRAY_SIZE; i++) {
  77500. + DWC_PRINTF("0x%04x 0x%04x\n",
  77501. + frame_num_array[i], last_frame_num_array[i]);
  77502. + }
  77503. + dumped_frame_num_array = 1;
  77504. + }
  77505. + last_frame_num = curr_frame_number;
  77506. +}
  77507. +#endif
  77508. +
  77509. +/**
  77510. + * Handles the start-of-frame interrupt in host mode. Non-periodic
  77511. + * transactions may be queued to the DWC_otg controller for the current
  77512. + * (micro)frame. Periodic transactions may be queued to the controller for the
  77513. + * next (micro)frame.
  77514. + */
  77515. +int32_t dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd_t * hcd)
  77516. +{
  77517. + hfnum_data_t hfnum;
  77518. + gintsts_data_t gintsts = { .d32 = 0 };
  77519. + dwc_list_link_t *qh_entry;
  77520. + dwc_otg_qh_t *qh;
  77521. + dwc_otg_transaction_type_e tr_type;
  77522. + int did_something = 0;
  77523. + int32_t next_sched_frame = -1;
  77524. +
  77525. + hfnum.d32 =
  77526. + DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hfnum);
  77527. +
  77528. +#ifdef DEBUG_SOF
  77529. + DWC_DEBUGPL(DBG_HCD, "--Start of Frame Interrupt--\n");
  77530. +#endif
  77531. + hcd->frame_number = hfnum.b.frnum;
  77532. +
  77533. +#ifdef DEBUG
  77534. + hcd->frrem_accum += hfnum.b.frrem;
  77535. + hcd->frrem_samples++;
  77536. +#endif
  77537. +
  77538. +#ifdef DWC_TRACK_MISSED_SOFS
  77539. + track_missed_sofs(hcd->frame_number);
  77540. +#endif
  77541. + /* Determine whether any periodic QHs should be executed. */
  77542. + qh_entry = DWC_LIST_FIRST(&hcd->periodic_sched_inactive);
  77543. + while (qh_entry != &hcd->periodic_sched_inactive) {
  77544. + qh = DWC_LIST_ENTRY(qh_entry, dwc_otg_qh_t, qh_list_entry);
  77545. + qh_entry = qh_entry->next;
  77546. + if (dwc_frame_num_le(qh->sched_frame, hcd->frame_number)) {
  77547. +
  77548. + /*
  77549. + * Move QH to the ready list to be executed next
  77550. + * (micro)frame.
  77551. + */
  77552. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_ready,
  77553. + &qh->qh_list_entry);
  77554. +
  77555. + did_something = 1;
  77556. + }
  77557. + else
  77558. + {
  77559. + if(next_sched_frame < 0 || dwc_frame_num_le(qh->sched_frame, next_sched_frame))
  77560. + {
  77561. + next_sched_frame = qh->sched_frame;
  77562. + }
  77563. + }
  77564. + }
  77565. +
  77566. + hcd->fiq_state->next_sched_frame = next_sched_frame;
  77567. +
  77568. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  77569. + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
  77570. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  77571. + did_something = 1;
  77572. + }
  77573. +
  77574. + /* Clear interrupt - but do not trample on the FIQ sof */
  77575. + if (!fiq_fsm_enable) {
  77576. + gintsts.b.sofintr = 1;
  77577. + DWC_WRITE_REG32(&hcd->core_if->core_global_regs->gintsts, gintsts.d32);
  77578. + }
  77579. + return 1;
  77580. +}
  77581. +
  77582. +/** Handles the Rx Status Queue Level Interrupt, which indicates that there is at
  77583. + * least one packet in the Rx FIFO. The packets are moved from the FIFO to
  77584. + * memory if the DWC_otg controller is operating in Slave mode. */
  77585. +int32_t dwc_otg_hcd_handle_rx_status_q_level_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  77586. +{
  77587. + host_grxsts_data_t grxsts;
  77588. + dwc_hc_t *hc = NULL;
  77589. +
  77590. + DWC_DEBUGPL(DBG_HCD, "--RxStsQ Level Interrupt--\n");
  77591. +
  77592. + grxsts.d32 =
  77593. + DWC_READ_REG32(&dwc_otg_hcd->core_if->core_global_regs->grxstsp);
  77594. +
  77595. + hc = dwc_otg_hcd->hc_ptr_array[grxsts.b.chnum];
  77596. + if (!hc) {
  77597. + DWC_ERROR("Unable to get corresponding channel\n");
  77598. + return 0;
  77599. + }
  77600. +
  77601. + /* Packet Status */
  77602. + DWC_DEBUGPL(DBG_HCDV, " Ch num = %d\n", grxsts.b.chnum);
  77603. + DWC_DEBUGPL(DBG_HCDV, " Count = %d\n", grxsts.b.bcnt);
  77604. + DWC_DEBUGPL(DBG_HCDV, " DPID = %d, hc.dpid = %d\n", grxsts.b.dpid,
  77605. + hc->data_pid_start);
  77606. + DWC_DEBUGPL(DBG_HCDV, " PStatus = %d\n", grxsts.b.pktsts);
  77607. +
  77608. + switch (grxsts.b.pktsts) {
  77609. + case DWC_GRXSTS_PKTSTS_IN:
  77610. + /* Read the data into the host buffer. */
  77611. + if (grxsts.b.bcnt > 0) {
  77612. + dwc_otg_read_packet(dwc_otg_hcd->core_if,
  77613. + hc->xfer_buff, grxsts.b.bcnt);
  77614. +
  77615. + /* Update the HC fields for the next packet received. */
  77616. + hc->xfer_count += grxsts.b.bcnt;
  77617. + hc->xfer_buff += grxsts.b.bcnt;
  77618. + }
  77619. +
  77620. + case DWC_GRXSTS_PKTSTS_IN_XFER_COMP:
  77621. + case DWC_GRXSTS_PKTSTS_DATA_TOGGLE_ERR:
  77622. + case DWC_GRXSTS_PKTSTS_CH_HALTED:
  77623. + /* Handled in interrupt, just ignore data */
  77624. + break;
  77625. + default:
  77626. + DWC_ERROR("RX_STS_Q Interrupt: Unknown status %d\n",
  77627. + grxsts.b.pktsts);
  77628. + break;
  77629. + }
  77630. +
  77631. + return 1;
  77632. +}
  77633. +
  77634. +/** This interrupt occurs when the non-periodic Tx FIFO is half-empty. More
  77635. + * data packets may be written to the FIFO for OUT transfers. More requests
  77636. + * may be written to the non-periodic request queue for IN transfers. This
  77637. + * interrupt is enabled only in Slave mode. */
  77638. +int32_t dwc_otg_hcd_handle_np_tx_fifo_empty_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  77639. +{
  77640. + DWC_DEBUGPL(DBG_HCD, "--Non-Periodic TxFIFO Empty Interrupt--\n");
  77641. + dwc_otg_hcd_queue_transactions(dwc_otg_hcd,
  77642. + DWC_OTG_TRANSACTION_NON_PERIODIC);
  77643. + return 1;
  77644. +}
  77645. +
  77646. +/** This interrupt occurs when the periodic Tx FIFO is half-empty. More data
  77647. + * packets may be written to the FIFO for OUT transfers. More requests may be
  77648. + * written to the periodic request queue for IN transfers. This interrupt is
  77649. + * enabled only in Slave mode. */
  77650. +int32_t dwc_otg_hcd_handle_perio_tx_fifo_empty_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  77651. +{
  77652. + DWC_DEBUGPL(DBG_HCD, "--Periodic TxFIFO Empty Interrupt--\n");
  77653. + dwc_otg_hcd_queue_transactions(dwc_otg_hcd,
  77654. + DWC_OTG_TRANSACTION_PERIODIC);
  77655. + return 1;
  77656. +}
  77657. +
  77658. +/** There are multiple conditions that can cause a port interrupt. This function
  77659. + * determines which interrupt conditions have occurred and handles them
  77660. + * appropriately. */
  77661. +int32_t dwc_otg_hcd_handle_port_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  77662. +{
  77663. + int retval = 0;
  77664. + hprt0_data_t hprt0;
  77665. + hprt0_data_t hprt0_modify;
  77666. +
  77667. + hprt0.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  77668. + hprt0_modify.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  77669. +
  77670. + /* Clear appropriate bits in HPRT0 to clear the interrupt bit in
  77671. + * GINTSTS */
  77672. +
  77673. + hprt0_modify.b.prtena = 0;
  77674. + hprt0_modify.b.prtconndet = 0;
  77675. + hprt0_modify.b.prtenchng = 0;
  77676. + hprt0_modify.b.prtovrcurrchng = 0;
  77677. +
  77678. + /* Port Connect Detected
  77679. + * Set flag and clear if detected */
  77680. + if (dwc_otg_hcd->core_if->hibernation_suspend == 1) {
  77681. + // Dont modify port status if we are in hibernation state
  77682. + hprt0_modify.b.prtconndet = 1;
  77683. + hprt0_modify.b.prtenchng = 1;
  77684. + DWC_WRITE_REG32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0_modify.d32);
  77685. + hprt0.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  77686. + return retval;
  77687. + }
  77688. +
  77689. + if (hprt0.b.prtconndet) {
  77690. + /** @todo - check if steps performed in 'else' block should be perfromed regardles adp */
  77691. + if (dwc_otg_hcd->core_if->adp_enable &&
  77692. + dwc_otg_hcd->core_if->adp.vbuson_timer_started == 1) {
  77693. + DWC_PRINTF("PORT CONNECT DETECTED ----------------\n");
  77694. + DWC_TIMER_CANCEL(dwc_otg_hcd->core_if->adp.vbuson_timer);
  77695. + dwc_otg_hcd->core_if->adp.vbuson_timer_started = 0;
  77696. + /* TODO - check if this is required, as
  77697. + * host initialization was already performed
  77698. + * after initial ADP probing
  77699. + */
  77700. + /*dwc_otg_hcd->core_if->adp.vbuson_timer_started = 0;
  77701. + dwc_otg_core_init(dwc_otg_hcd->core_if);
  77702. + dwc_otg_enable_global_interrupts(dwc_otg_hcd->core_if);
  77703. + cil_hcd_start(dwc_otg_hcd->core_if);*/
  77704. + } else {
  77705. +
  77706. + DWC_DEBUGPL(DBG_HCD, "--Port Interrupt HPRT0=0x%08x "
  77707. + "Port Connect Detected--\n", hprt0.d32);
  77708. + dwc_otg_hcd->flags.b.port_connect_status_change = 1;
  77709. + dwc_otg_hcd->flags.b.port_connect_status = 1;
  77710. + hprt0_modify.b.prtconndet = 1;
  77711. +
  77712. + /* B-Device has connected, Delete the connection timer. */
  77713. + DWC_TIMER_CANCEL(dwc_otg_hcd->conn_timer);
  77714. + }
  77715. + /* The Hub driver asserts a reset when it sees port connect
  77716. + * status change flag */
  77717. + retval |= 1;
  77718. + }
  77719. +
  77720. + /* Port Enable Changed
  77721. + * Clear if detected - Set internal flag if disabled */
  77722. + if (hprt0.b.prtenchng) {
  77723. + DWC_DEBUGPL(DBG_HCD, " --Port Interrupt HPRT0=0x%08x "
  77724. + "Port Enable Changed--\n", hprt0.d32);
  77725. + hprt0_modify.b.prtenchng = 1;
  77726. + if (hprt0.b.prtena == 1) {
  77727. + hfir_data_t hfir;
  77728. + int do_reset = 0;
  77729. + dwc_otg_core_params_t *params =
  77730. + dwc_otg_hcd->core_if->core_params;
  77731. + dwc_otg_core_global_regs_t *global_regs =
  77732. + dwc_otg_hcd->core_if->core_global_regs;
  77733. + dwc_otg_host_if_t *host_if =
  77734. + dwc_otg_hcd->core_if->host_if;
  77735. +
  77736. + /* Every time when port enables calculate
  77737. + * HFIR.FrInterval
  77738. + */
  77739. + hfir.d32 = DWC_READ_REG32(&host_if->host_global_regs->hfir);
  77740. + hfir.b.frint = calc_frame_interval(dwc_otg_hcd->core_if);
  77741. + DWC_WRITE_REG32(&host_if->host_global_regs->hfir, hfir.d32);
  77742. +
  77743. + /* Check if we need to adjust the PHY clock speed for
  77744. + * low power and adjust it */
  77745. + if (params->host_support_fs_ls_low_power) {
  77746. + gusbcfg_data_t usbcfg;
  77747. +
  77748. + usbcfg.d32 =
  77749. + DWC_READ_REG32(&global_regs->gusbcfg);
  77750. +
  77751. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED
  77752. + || hprt0.b.prtspd ==
  77753. + DWC_HPRT0_PRTSPD_FULL_SPEED) {
  77754. + /*
  77755. + * Low power
  77756. + */
  77757. + hcfg_data_t hcfg;
  77758. + if (usbcfg.b.phylpwrclksel == 0) {
  77759. + /* Set PHY low power clock select for FS/LS devices */
  77760. + usbcfg.b.phylpwrclksel = 1;
  77761. + DWC_WRITE_REG32
  77762. + (&global_regs->gusbcfg,
  77763. + usbcfg.d32);
  77764. + do_reset = 1;
  77765. + }
  77766. +
  77767. + hcfg.d32 =
  77768. + DWC_READ_REG32
  77769. + (&host_if->host_global_regs->hcfg);
  77770. +
  77771. + if (hprt0.b.prtspd ==
  77772. + DWC_HPRT0_PRTSPD_LOW_SPEED
  77773. + && params->host_ls_low_power_phy_clk
  77774. + ==
  77775. + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ)
  77776. + {
  77777. + /* 6 MHZ */
  77778. + DWC_DEBUGPL(DBG_CIL,
  77779. + "FS_PHY programming HCFG to 6 MHz (Low Power)\n");
  77780. + if (hcfg.b.fslspclksel !=
  77781. + DWC_HCFG_6_MHZ) {
  77782. + hcfg.b.fslspclksel =
  77783. + DWC_HCFG_6_MHZ;
  77784. + DWC_WRITE_REG32
  77785. + (&host_if->host_global_regs->hcfg,
  77786. + hcfg.d32);
  77787. + do_reset = 1;
  77788. + }
  77789. + } else {
  77790. + /* 48 MHZ */
  77791. + DWC_DEBUGPL(DBG_CIL,
  77792. + "FS_PHY programming HCFG to 48 MHz ()\n");
  77793. + if (hcfg.b.fslspclksel !=
  77794. + DWC_HCFG_48_MHZ) {
  77795. + hcfg.b.fslspclksel =
  77796. + DWC_HCFG_48_MHZ;
  77797. + DWC_WRITE_REG32
  77798. + (&host_if->host_global_regs->hcfg,
  77799. + hcfg.d32);
  77800. + do_reset = 1;
  77801. + }
  77802. + }
  77803. + } else {
  77804. + /*
  77805. + * Not low power
  77806. + */
  77807. + if (usbcfg.b.phylpwrclksel == 1) {
  77808. + usbcfg.b.phylpwrclksel = 0;
  77809. + DWC_WRITE_REG32
  77810. + (&global_regs->gusbcfg,
  77811. + usbcfg.d32);
  77812. + do_reset = 1;
  77813. + }
  77814. + }
  77815. +
  77816. + if (do_reset) {
  77817. + DWC_TASK_SCHEDULE(dwc_otg_hcd->reset_tasklet);
  77818. + }
  77819. + }
  77820. +
  77821. + if (!do_reset) {
  77822. + /* Port has been enabled set the reset change flag */
  77823. + dwc_otg_hcd->flags.b.port_reset_change = 1;
  77824. + }
  77825. + } else {
  77826. + dwc_otg_hcd->flags.b.port_enable_change = 1;
  77827. + }
  77828. + retval |= 1;
  77829. + }
  77830. +
  77831. + /** Overcurrent Change Interrupt */
  77832. + if (hprt0.b.prtovrcurrchng) {
  77833. + DWC_DEBUGPL(DBG_HCD, " --Port Interrupt HPRT0=0x%08x "
  77834. + "Port Overcurrent Changed--\n", hprt0.d32);
  77835. + dwc_otg_hcd->flags.b.port_over_current_change = 1;
  77836. + hprt0_modify.b.prtovrcurrchng = 1;
  77837. + retval |= 1;
  77838. + }
  77839. +
  77840. + /* Clear Port Interrupts */
  77841. + DWC_WRITE_REG32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0_modify.d32);
  77842. +
  77843. + return retval;
  77844. +}
  77845. +
  77846. +/** This interrupt indicates that one or more host channels has a pending
  77847. + * interrupt. There are multiple conditions that can cause each host channel
  77848. + * interrupt. This function determines which conditions have occurred for each
  77849. + * host channel interrupt and handles them appropriately. */
  77850. +int32_t dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  77851. +{
  77852. + int i;
  77853. + int retval = 0;
  77854. + haint_data_t haint = { .d32 = 0 } ;
  77855. +
  77856. + /* Clear appropriate bits in HCINTn to clear the interrupt bit in
  77857. + * GINTSTS */
  77858. +
  77859. + if (!fiq_fsm_enable)
  77860. + haint.d32 = dwc_otg_read_host_all_channels_intr(dwc_otg_hcd->core_if);
  77861. +
  77862. + // Overwrite with saved interrupts from fiq handler
  77863. + if(fiq_fsm_enable)
  77864. + {
  77865. + /* check the mask? */
  77866. + local_fiq_disable();
  77867. + haint.b2.chint |= ~(dwc_otg_hcd->fiq_state->haintmsk_saved.b2.chint);
  77868. + dwc_otg_hcd->fiq_state->haintmsk_saved.b2.chint = ~0;
  77869. + local_fiq_enable();
  77870. + }
  77871. +
  77872. + for (i = 0; i < dwc_otg_hcd->core_if->core_params->host_channels; i++) {
  77873. + if (haint.b2.chint & (1 << i)) {
  77874. + retval |= dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd, i);
  77875. + }
  77876. + }
  77877. +
  77878. + return retval;
  77879. +}
  77880. +
  77881. +/**
  77882. + * Gets the actual length of a transfer after the transfer halts. _halt_status
  77883. + * holds the reason for the halt.
  77884. + *
  77885. + * For IN transfers where halt_status is DWC_OTG_HC_XFER_COMPLETE,
  77886. + * *short_read is set to 1 upon return if less than the requested
  77887. + * number of bytes were transferred. Otherwise, *short_read is set to 0 upon
  77888. + * return. short_read may also be NULL on entry, in which case it remains
  77889. + * unchanged.
  77890. + */
  77891. +static uint32_t get_actual_xfer_length(dwc_hc_t * hc,
  77892. + dwc_otg_hc_regs_t * hc_regs,
  77893. + dwc_otg_qtd_t * qtd,
  77894. + dwc_otg_halt_status_e halt_status,
  77895. + int *short_read)
  77896. +{
  77897. + hctsiz_data_t hctsiz;
  77898. + uint32_t length;
  77899. +
  77900. + if (short_read != NULL) {
  77901. + *short_read = 0;
  77902. + }
  77903. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  77904. +
  77905. + if (halt_status == DWC_OTG_HC_XFER_COMPLETE) {
  77906. + if (hc->ep_is_in) {
  77907. + length = hc->xfer_len - hctsiz.b.xfersize;
  77908. + if (short_read != NULL) {
  77909. + *short_read = (hctsiz.b.xfersize != 0);
  77910. + }
  77911. + } else if (hc->qh->do_split) {
  77912. + //length = split_out_xfersize[hc->hc_num];
  77913. + length = qtd->ssplit_out_xfer_count;
  77914. + } else {
  77915. + length = hc->xfer_len;
  77916. + }
  77917. + } else {
  77918. + /*
  77919. + * Must use the hctsiz.pktcnt field to determine how much data
  77920. + * has been transferred. This field reflects the number of
  77921. + * packets that have been transferred via the USB. This is
  77922. + * always an integral number of packets if the transfer was
  77923. + * halted before its normal completion. (Can't use the
  77924. + * hctsiz.xfersize field because that reflects the number of
  77925. + * bytes transferred via the AHB, not the USB).
  77926. + */
  77927. + length =
  77928. + (hc->start_pkt_count - hctsiz.b.pktcnt) * hc->max_packet;
  77929. + }
  77930. +
  77931. + return length;
  77932. +}
  77933. +
  77934. +/**
  77935. + * Updates the state of the URB after a Transfer Complete interrupt on the
  77936. + * host channel. Updates the actual_length field of the URB based on the
  77937. + * number of bytes transferred via the host channel. Sets the URB status
  77938. + * if the data transfer is finished.
  77939. + *
  77940. + * @return 1 if the data transfer specified by the URB is completely finished,
  77941. + * 0 otherwise.
  77942. + */
  77943. +static int update_urb_state_xfer_comp(dwc_hc_t * hc,
  77944. + dwc_otg_hc_regs_t * hc_regs,
  77945. + dwc_otg_hcd_urb_t * urb,
  77946. + dwc_otg_qtd_t * qtd)
  77947. +{
  77948. + int xfer_done = 0;
  77949. + int short_read = 0;
  77950. +
  77951. + int xfer_length;
  77952. +
  77953. + xfer_length = get_actual_xfer_length(hc, hc_regs, qtd,
  77954. + DWC_OTG_HC_XFER_COMPLETE,
  77955. + &short_read);
  77956. +
  77957. + /* non DWORD-aligned buffer case handling. */
  77958. + if (hc->align_buff && xfer_length && hc->ep_is_in) {
  77959. + dwc_memcpy(urb->buf + urb->actual_length, hc->qh->dw_align_buf,
  77960. + xfer_length);
  77961. + }
  77962. +
  77963. + urb->actual_length += xfer_length;
  77964. +
  77965. + if (xfer_length && (hc->ep_type == DWC_OTG_EP_TYPE_BULK) &&
  77966. + (urb->flags & URB_SEND_ZERO_PACKET)
  77967. + && (urb->actual_length == urb->length)
  77968. + && !(urb->length % hc->max_packet)) {
  77969. + xfer_done = 0;
  77970. + } else if (short_read || urb->actual_length >= urb->length) {
  77971. + xfer_done = 1;
  77972. + urb->status = 0;
  77973. + }
  77974. +
  77975. +#ifdef DEBUG
  77976. + {
  77977. + hctsiz_data_t hctsiz;
  77978. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  77979. + DWC_DEBUGPL(DBG_HCDV, "DWC_otg: %s: %s, channel %d\n",
  77980. + __func__, (hc->ep_is_in ? "IN" : "OUT"),
  77981. + hc->hc_num);
  77982. + DWC_DEBUGPL(DBG_HCDV, " hc->xfer_len %d\n", hc->xfer_len);
  77983. + DWC_DEBUGPL(DBG_HCDV, " hctsiz.xfersize %d\n",
  77984. + hctsiz.b.xfersize);
  77985. + DWC_DEBUGPL(DBG_HCDV, " urb->transfer_buffer_length %d\n",
  77986. + urb->length);
  77987. + DWC_DEBUGPL(DBG_HCDV, " urb->actual_length %d\n",
  77988. + urb->actual_length);
  77989. + DWC_DEBUGPL(DBG_HCDV, " short_read %d, xfer_done %d\n",
  77990. + short_read, xfer_done);
  77991. + }
  77992. +#endif
  77993. +
  77994. + return xfer_done;
  77995. +}
  77996. +
  77997. +/*
  77998. + * Save the starting data toggle for the next transfer. The data toggle is
  77999. + * saved in the QH for non-control transfers and it's saved in the QTD for
  78000. + * control transfers.
  78001. + */
  78002. +void dwc_otg_hcd_save_data_toggle(dwc_hc_t * hc,
  78003. + dwc_otg_hc_regs_t * hc_regs, dwc_otg_qtd_t * qtd)
  78004. +{
  78005. + hctsiz_data_t hctsiz;
  78006. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  78007. +
  78008. + if (hc->ep_type != DWC_OTG_EP_TYPE_CONTROL) {
  78009. + dwc_otg_qh_t *qh = hc->qh;
  78010. + if (hctsiz.b.pid == DWC_HCTSIZ_DATA0) {
  78011. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  78012. + } else {
  78013. + qh->data_toggle = DWC_OTG_HC_PID_DATA1;
  78014. + }
  78015. + } else {
  78016. + if (hctsiz.b.pid == DWC_HCTSIZ_DATA0) {
  78017. + qtd->data_toggle = DWC_OTG_HC_PID_DATA0;
  78018. + } else {
  78019. + qtd->data_toggle = DWC_OTG_HC_PID_DATA1;
  78020. + }
  78021. + }
  78022. +}
  78023. +
  78024. +/**
  78025. + * Updates the state of an Isochronous URB when the transfer is stopped for
  78026. + * any reason. The fields of the current entry in the frame descriptor array
  78027. + * are set based on the transfer state and the input _halt_status. Completes
  78028. + * the Isochronous URB if all the URB frames have been completed.
  78029. + *
  78030. + * @return DWC_OTG_HC_XFER_COMPLETE if there are more frames remaining to be
  78031. + * transferred in the URB. Otherwise return DWC_OTG_HC_XFER_URB_COMPLETE.
  78032. + */
  78033. +static dwc_otg_halt_status_e
  78034. +update_isoc_urb_state(dwc_otg_hcd_t * hcd,
  78035. + dwc_hc_t * hc,
  78036. + dwc_otg_hc_regs_t * hc_regs,
  78037. + dwc_otg_qtd_t * qtd, dwc_otg_halt_status_e halt_status)
  78038. +{
  78039. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  78040. + dwc_otg_halt_status_e ret_val = halt_status;
  78041. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  78042. +
  78043. + frame_desc = &urb->iso_descs[qtd->isoc_frame_index];
  78044. + switch (halt_status) {
  78045. + case DWC_OTG_HC_XFER_COMPLETE:
  78046. + frame_desc->status = 0;
  78047. + frame_desc->actual_length =
  78048. + get_actual_xfer_length(hc, hc_regs, qtd, halt_status, NULL);
  78049. +
  78050. + /* non DWORD-aligned buffer case handling. */
  78051. + if (hc->align_buff && frame_desc->actual_length && hc->ep_is_in) {
  78052. + dwc_memcpy(urb->buf + frame_desc->offset + qtd->isoc_split_offset,
  78053. + hc->qh->dw_align_buf, frame_desc->actual_length);
  78054. + }
  78055. +
  78056. + break;
  78057. + case DWC_OTG_HC_XFER_FRAME_OVERRUN:
  78058. + urb->error_count++;
  78059. + if (hc->ep_is_in) {
  78060. + frame_desc->status = -DWC_E_NO_STREAM_RES;
  78061. + } else {
  78062. + frame_desc->status = -DWC_E_COMMUNICATION;
  78063. + }
  78064. + frame_desc->actual_length = 0;
  78065. + break;
  78066. + case DWC_OTG_HC_XFER_BABBLE_ERR:
  78067. + urb->error_count++;
  78068. + frame_desc->status = -DWC_E_OVERFLOW;
  78069. + /* Don't need to update actual_length in this case. */
  78070. + break;
  78071. + case DWC_OTG_HC_XFER_XACT_ERR:
  78072. + urb->error_count++;
  78073. + frame_desc->status = -DWC_E_PROTOCOL;
  78074. + frame_desc->actual_length =
  78075. + get_actual_xfer_length(hc, hc_regs, qtd, halt_status, NULL);
  78076. +
  78077. + /* non DWORD-aligned buffer case handling. */
  78078. + if (hc->align_buff && frame_desc->actual_length && hc->ep_is_in) {
  78079. + dwc_memcpy(urb->buf + frame_desc->offset + qtd->isoc_split_offset,
  78080. + hc->qh->dw_align_buf, frame_desc->actual_length);
  78081. + }
  78082. + /* Skip whole frame */
  78083. + if (hc->qh->do_split && (hc->ep_type == DWC_OTG_EP_TYPE_ISOC) &&
  78084. + hc->ep_is_in && hcd->core_if->dma_enable) {
  78085. + qtd->complete_split = 0;
  78086. + qtd->isoc_split_offset = 0;
  78087. + }
  78088. +
  78089. + break;
  78090. + default:
  78091. + DWC_ASSERT(1, "Unhandled _halt_status (%d)\n", halt_status);
  78092. + break;
  78093. + }
  78094. + if (++qtd->isoc_frame_index == urb->packet_count) {
  78095. + /*
  78096. + * urb->status is not used for isoc transfers.
  78097. + * The individual frame_desc statuses are used instead.
  78098. + */
  78099. + hcd->fops->complete(hcd, urb->priv, urb, 0);
  78100. + ret_val = DWC_OTG_HC_XFER_URB_COMPLETE;
  78101. + } else {
  78102. + ret_val = DWC_OTG_HC_XFER_COMPLETE;
  78103. + }
  78104. + return ret_val;
  78105. +}
  78106. +
  78107. +/**
  78108. + * Frees the first QTD in the QH's list if free_qtd is 1. For non-periodic
  78109. + * QHs, removes the QH from the active non-periodic schedule. If any QTDs are
  78110. + * still linked to the QH, the QH is added to the end of the inactive
  78111. + * non-periodic schedule. For periodic QHs, removes the QH from the periodic
  78112. + * schedule if no more QTDs are linked to the QH.
  78113. + */
  78114. +static void deactivate_qh(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh, int free_qtd)
  78115. +{
  78116. + int continue_split = 0;
  78117. + dwc_otg_qtd_t *qtd;
  78118. +
  78119. + DWC_DEBUGPL(DBG_HCDV, " %s(%p,%p,%d)\n", __func__, hcd, qh, free_qtd);
  78120. +
  78121. + qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  78122. +
  78123. + if (qtd->complete_split) {
  78124. + continue_split = 1;
  78125. + } else if (qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_MID ||
  78126. + qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_END) {
  78127. + continue_split = 1;
  78128. + }
  78129. +
  78130. + if (free_qtd) {
  78131. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  78132. + continue_split = 0;
  78133. + }
  78134. +
  78135. + qh->channel = NULL;
  78136. + dwc_otg_hcd_qh_deactivate(hcd, qh, continue_split);
  78137. +}
  78138. +
  78139. +/**
  78140. + * Releases a host channel for use by other transfers. Attempts to select and
  78141. + * queue more transactions since at least one host channel is available.
  78142. + *
  78143. + * @param hcd The HCD state structure.
  78144. + * @param hc The host channel to release.
  78145. + * @param qtd The QTD associated with the host channel. This QTD may be freed
  78146. + * if the transfer is complete or an error has occurred.
  78147. + * @param halt_status Reason the channel is being released. This status
  78148. + * determines the actions taken by this function.
  78149. + */
  78150. +static void release_channel(dwc_otg_hcd_t * hcd,
  78151. + dwc_hc_t * hc,
  78152. + dwc_otg_qtd_t * qtd,
  78153. + dwc_otg_halt_status_e halt_status)
  78154. +{
  78155. + dwc_otg_transaction_type_e tr_type;
  78156. + int free_qtd;
  78157. + dwc_irqflags_t flags;
  78158. + dwc_spinlock_t *channel_lock = hcd->channel_lock;
  78159. +
  78160. + int hog_port = 0;
  78161. +
  78162. + DWC_DEBUGPL(DBG_HCDV, " %s: channel %d, halt_status %d, xfer_len %d\n",
  78163. + __func__, hc->hc_num, halt_status, hc->xfer_len);
  78164. +
  78165. + if(fiq_fsm_enable && hc->do_split) {
  78166. + if(!hc->ep_is_in && hc->ep_type == UE_ISOCHRONOUS) {
  78167. + if(hc->xact_pos == DWC_HCSPLIT_XACTPOS_MID ||
  78168. + hc->xact_pos == DWC_HCSPLIT_XACTPOS_BEGIN) {
  78169. + hog_port = 0;
  78170. + }
  78171. + }
  78172. + }
  78173. +
  78174. + switch (halt_status) {
  78175. + case DWC_OTG_HC_XFER_URB_COMPLETE:
  78176. + free_qtd = 1;
  78177. + break;
  78178. + case DWC_OTG_HC_XFER_AHB_ERR:
  78179. + case DWC_OTG_HC_XFER_STALL:
  78180. + case DWC_OTG_HC_XFER_BABBLE_ERR:
  78181. + free_qtd = 1;
  78182. + break;
  78183. + case DWC_OTG_HC_XFER_XACT_ERR:
  78184. + if (qtd->error_count >= 3) {
  78185. + DWC_DEBUGPL(DBG_HCDV,
  78186. + " Complete URB with transaction error\n");
  78187. + free_qtd = 1;
  78188. + qtd->urb->status = -DWC_E_PROTOCOL;
  78189. + hcd->fops->complete(hcd, qtd->urb->priv,
  78190. + qtd->urb, -DWC_E_PROTOCOL);
  78191. + } else {
  78192. + free_qtd = 0;
  78193. + }
  78194. + break;
  78195. + case DWC_OTG_HC_XFER_URB_DEQUEUE:
  78196. + /*
  78197. + * The QTD has already been removed and the QH has been
  78198. + * deactivated. Don't want to do anything except release the
  78199. + * host channel and try to queue more transfers.
  78200. + */
  78201. + goto cleanup;
  78202. + case DWC_OTG_HC_XFER_NO_HALT_STATUS:
  78203. + free_qtd = 0;
  78204. + break;
  78205. + case DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE:
  78206. + DWC_DEBUGPL(DBG_HCDV,
  78207. + " Complete URB with I/O error\n");
  78208. + free_qtd = 1;
  78209. + qtd->urb->status = -DWC_E_IO;
  78210. + hcd->fops->complete(hcd, qtd->urb->priv,
  78211. + qtd->urb, -DWC_E_IO);
  78212. + break;
  78213. + default:
  78214. + free_qtd = 0;
  78215. + break;
  78216. + }
  78217. +
  78218. + deactivate_qh(hcd, hc->qh, free_qtd);
  78219. +
  78220. +cleanup:
  78221. + /*
  78222. + * Release the host channel for use by other transfers. The cleanup
  78223. + * function clears the channel interrupt enables and conditions, so
  78224. + * there's no need to clear the Channel Halted interrupt separately.
  78225. + */
  78226. + if (fiq_fsm_enable && hcd->fiq_state->channel[hc->hc_num].fsm != FIQ_PASSTHROUGH)
  78227. + dwc_otg_cleanup_fiq_channel(hcd, hc->hc_num);
  78228. + dwc_otg_hc_cleanup(hcd->core_if, hc);
  78229. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, hc, hc_list_entry);
  78230. +
  78231. + if (!microframe_schedule) {
  78232. + switch (hc->ep_type) {
  78233. + case DWC_OTG_EP_TYPE_CONTROL:
  78234. + case DWC_OTG_EP_TYPE_BULK:
  78235. + hcd->non_periodic_channels--;
  78236. + break;
  78237. +
  78238. + default:
  78239. + /*
  78240. + * Don't release reservations for periodic channels here.
  78241. + * That's done when a periodic transfer is descheduled (i.e.
  78242. + * when the QH is removed from the periodic schedule).
  78243. + */
  78244. + break;
  78245. + }
  78246. + } else {
  78247. +
  78248. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  78249. + hcd->available_host_channels++;
  78250. + fiq_print(FIQDBG_INT, hcd->fiq_state, "AHC = %d ", hcd->available_host_channels);
  78251. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  78252. + }
  78253. +
  78254. + /* Try to queue more transfers now that there's a free channel. */
  78255. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  78256. + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
  78257. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  78258. + }
  78259. +}
  78260. +
  78261. +/**
  78262. + * Halts a host channel. If the channel cannot be halted immediately because
  78263. + * the request queue is full, this function ensures that the FIFO empty
  78264. + * interrupt for the appropriate queue is enabled so that the halt request can
  78265. + * be queued when there is space in the request queue.
  78266. + *
  78267. + * This function may also be called in DMA mode. In that case, the channel is
  78268. + * simply released since the core always halts the channel automatically in
  78269. + * DMA mode.
  78270. + */
  78271. +static void halt_channel(dwc_otg_hcd_t * hcd,
  78272. + dwc_hc_t * hc,
  78273. + dwc_otg_qtd_t * qtd, dwc_otg_halt_status_e halt_status)
  78274. +{
  78275. + if (hcd->core_if->dma_enable) {
  78276. + release_channel(hcd, hc, qtd, halt_status);
  78277. + return;
  78278. + }
  78279. +
  78280. + /* Slave mode processing... */
  78281. + dwc_otg_hc_halt(hcd->core_if, hc, halt_status);
  78282. +
  78283. + if (hc->halt_on_queue) {
  78284. + gintmsk_data_t gintmsk = {.d32 = 0 };
  78285. + dwc_otg_core_global_regs_t *global_regs;
  78286. + global_regs = hcd->core_if->core_global_regs;
  78287. +
  78288. + if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
  78289. + hc->ep_type == DWC_OTG_EP_TYPE_BULK) {
  78290. + /*
  78291. + * Make sure the Non-periodic Tx FIFO empty interrupt
  78292. + * is enabled so that the non-periodic schedule will
  78293. + * be processed.
  78294. + */
  78295. + gintmsk.b.nptxfempty = 1;
  78296. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmsk.d32);
  78297. + } else {
  78298. + /*
  78299. + * Move the QH from the periodic queued schedule to
  78300. + * the periodic assigned schedule. This allows the
  78301. + * halt to be queued when the periodic schedule is
  78302. + * processed.
  78303. + */
  78304. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_assigned,
  78305. + &hc->qh->qh_list_entry);
  78306. +
  78307. + /*
  78308. + * Make sure the Periodic Tx FIFO Empty interrupt is
  78309. + * enabled so that the periodic schedule will be
  78310. + * processed.
  78311. + */
  78312. + gintmsk.b.ptxfempty = 1;
  78313. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmsk.d32);
  78314. + }
  78315. + }
  78316. +}
  78317. +
  78318. +/**
  78319. + * Performs common cleanup for non-periodic transfers after a Transfer
  78320. + * Complete interrupt. This function should be called after any endpoint type
  78321. + * specific handling is finished to release the host channel.
  78322. + */
  78323. +static void complete_non_periodic_xfer(dwc_otg_hcd_t * hcd,
  78324. + dwc_hc_t * hc,
  78325. + dwc_otg_hc_regs_t * hc_regs,
  78326. + dwc_otg_qtd_t * qtd,
  78327. + dwc_otg_halt_status_e halt_status)
  78328. +{
  78329. + hcint_data_t hcint;
  78330. +
  78331. + qtd->error_count = 0;
  78332. +
  78333. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  78334. + if (hcint.b.nyet) {
  78335. + /*
  78336. + * Got a NYET on the last transaction of the transfer. This
  78337. + * means that the endpoint should be in the PING state at the
  78338. + * beginning of the next transfer.
  78339. + */
  78340. + hc->qh->ping_state = 1;
  78341. + clear_hc_int(hc_regs, nyet);
  78342. + }
  78343. +
  78344. + /*
  78345. + * Always halt and release the host channel to make it available for
  78346. + * more transfers. There may still be more phases for a control
  78347. + * transfer or more data packets for a bulk transfer at this point,
  78348. + * but the host channel is still halted. A channel will be reassigned
  78349. + * to the transfer when the non-periodic schedule is processed after
  78350. + * the channel is released. This allows transactions to be queued
  78351. + * properly via dwc_otg_hcd_queue_transactions, which also enables the
  78352. + * Tx FIFO Empty interrupt if necessary.
  78353. + */
  78354. + if (hc->ep_is_in) {
  78355. + /*
  78356. + * IN transfers in Slave mode require an explicit disable to
  78357. + * halt the channel. (In DMA mode, this call simply releases
  78358. + * the channel.)
  78359. + */
  78360. + halt_channel(hcd, hc, qtd, halt_status);
  78361. + } else {
  78362. + /*
  78363. + * The channel is automatically disabled by the core for OUT
  78364. + * transfers in Slave mode.
  78365. + */
  78366. + release_channel(hcd, hc, qtd, halt_status);
  78367. + }
  78368. +}
  78369. +
  78370. +/**
  78371. + * Performs common cleanup for periodic transfers after a Transfer Complete
  78372. + * interrupt. This function should be called after any endpoint type specific
  78373. + * handling is finished to release the host channel.
  78374. + */
  78375. +static void complete_periodic_xfer(dwc_otg_hcd_t * hcd,
  78376. + dwc_hc_t * hc,
  78377. + dwc_otg_hc_regs_t * hc_regs,
  78378. + dwc_otg_qtd_t * qtd,
  78379. + dwc_otg_halt_status_e halt_status)
  78380. +{
  78381. + hctsiz_data_t hctsiz;
  78382. + qtd->error_count = 0;
  78383. +
  78384. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  78385. + if (!hc->ep_is_in || hctsiz.b.pktcnt == 0) {
  78386. + /* Core halts channel in these cases. */
  78387. + release_channel(hcd, hc, qtd, halt_status);
  78388. + } else {
  78389. + /* Flush any outstanding requests from the Tx queue. */
  78390. + halt_channel(hcd, hc, qtd, halt_status);
  78391. + }
  78392. +}
  78393. +
  78394. +static int32_t handle_xfercomp_isoc_split_in(dwc_otg_hcd_t * hcd,
  78395. + dwc_hc_t * hc,
  78396. + dwc_otg_hc_regs_t * hc_regs,
  78397. + dwc_otg_qtd_t * qtd)
  78398. +{
  78399. + uint32_t len;
  78400. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  78401. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  78402. +
  78403. + len = get_actual_xfer_length(hc, hc_regs, qtd,
  78404. + DWC_OTG_HC_XFER_COMPLETE, NULL);
  78405. +
  78406. + if (!len) {
  78407. + qtd->complete_split = 0;
  78408. + qtd->isoc_split_offset = 0;
  78409. + return 0;
  78410. + }
  78411. + frame_desc->actual_length += len;
  78412. +
  78413. + if (hc->align_buff && len)
  78414. + dwc_memcpy(qtd->urb->buf + frame_desc->offset +
  78415. + qtd->isoc_split_offset, hc->qh->dw_align_buf, len);
  78416. + qtd->isoc_split_offset += len;
  78417. +
  78418. + if (frame_desc->length == frame_desc->actual_length) {
  78419. + frame_desc->status = 0;
  78420. + qtd->isoc_frame_index++;
  78421. + qtd->complete_split = 0;
  78422. + qtd->isoc_split_offset = 0;
  78423. + }
  78424. +
  78425. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  78426. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  78427. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  78428. + } else {
  78429. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  78430. + }
  78431. +
  78432. + return 1; /* Indicates that channel released */
  78433. +}
  78434. +
  78435. +/**
  78436. + * Handles a host channel Transfer Complete interrupt. This handler may be
  78437. + * called in either DMA mode or Slave mode.
  78438. + */
  78439. +static int32_t handle_hc_xfercomp_intr(dwc_otg_hcd_t * hcd,
  78440. + dwc_hc_t * hc,
  78441. + dwc_otg_hc_regs_t * hc_regs,
  78442. + dwc_otg_qtd_t * qtd)
  78443. +{
  78444. + int urb_xfer_done;
  78445. + dwc_otg_halt_status_e halt_status = DWC_OTG_HC_XFER_COMPLETE;
  78446. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  78447. + int pipe_type = dwc_otg_hcd_get_pipe_type(&urb->pipe_info);
  78448. +
  78449. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  78450. + "Transfer Complete--\n", hc->hc_num);
  78451. +
  78452. + if (hcd->core_if->dma_desc_enable) {
  78453. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs, halt_status);
  78454. + if (pipe_type == UE_ISOCHRONOUS) {
  78455. + /* Do not disable the interrupt, just clear it */
  78456. + clear_hc_int(hc_regs, xfercomp);
  78457. + return 1;
  78458. + }
  78459. + goto handle_xfercomp_done;
  78460. + }
  78461. +
  78462. + /*
  78463. + * Handle xfer complete on CSPLIT.
  78464. + */
  78465. +
  78466. + if (hc->qh->do_split) {
  78467. + if ((hc->ep_type == DWC_OTG_EP_TYPE_ISOC) && hc->ep_is_in
  78468. + && hcd->core_if->dma_enable) {
  78469. + if (qtd->complete_split
  78470. + && handle_xfercomp_isoc_split_in(hcd, hc, hc_regs,
  78471. + qtd))
  78472. + goto handle_xfercomp_done;
  78473. + } else {
  78474. + qtd->complete_split = 0;
  78475. + }
  78476. + }
  78477. +
  78478. + /* Update the QTD and URB states. */
  78479. + switch (pipe_type) {
  78480. + case UE_CONTROL:
  78481. + switch (qtd->control_phase) {
  78482. + case DWC_OTG_CONTROL_SETUP:
  78483. + if (urb->length > 0) {
  78484. + qtd->control_phase = DWC_OTG_CONTROL_DATA;
  78485. + } else {
  78486. + qtd->control_phase = DWC_OTG_CONTROL_STATUS;
  78487. + }
  78488. + DWC_DEBUGPL(DBG_HCDV,
  78489. + " Control setup transaction done\n");
  78490. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  78491. + break;
  78492. + case DWC_OTG_CONTROL_DATA:{
  78493. + urb_xfer_done =
  78494. + update_urb_state_xfer_comp(hc, hc_regs, urb,
  78495. + qtd);
  78496. + if (urb_xfer_done) {
  78497. + qtd->control_phase =
  78498. + DWC_OTG_CONTROL_STATUS;
  78499. + DWC_DEBUGPL(DBG_HCDV,
  78500. + " Control data transfer done\n");
  78501. + } else {
  78502. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  78503. + }
  78504. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  78505. + break;
  78506. + }
  78507. + case DWC_OTG_CONTROL_STATUS:
  78508. + DWC_DEBUGPL(DBG_HCDV, " Control transfer complete\n");
  78509. + if (urb->status == -DWC_E_IN_PROGRESS) {
  78510. + urb->status = 0;
  78511. + }
  78512. + hcd->fops->complete(hcd, urb->priv, urb, urb->status);
  78513. + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
  78514. + break;
  78515. + }
  78516. +
  78517. + complete_non_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  78518. + break;
  78519. + case UE_BULK:
  78520. + DWC_DEBUGPL(DBG_HCDV, " Bulk transfer complete\n");
  78521. + urb_xfer_done =
  78522. + update_urb_state_xfer_comp(hc, hc_regs, urb, qtd);
  78523. + if (urb_xfer_done) {
  78524. + hcd->fops->complete(hcd, urb->priv, urb, urb->status);
  78525. + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
  78526. + } else {
  78527. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  78528. + }
  78529. +
  78530. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  78531. + complete_non_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  78532. + break;
  78533. + case UE_INTERRUPT:
  78534. + DWC_DEBUGPL(DBG_HCDV, " Interrupt transfer complete\n");
  78535. + urb_xfer_done =
  78536. + update_urb_state_xfer_comp(hc, hc_regs, urb, qtd);
  78537. +
  78538. + /*
  78539. + * Interrupt URB is done on the first transfer complete
  78540. + * interrupt.
  78541. + */
  78542. + if (urb_xfer_done) {
  78543. + hcd->fops->complete(hcd, urb->priv, urb, urb->status);
  78544. + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
  78545. + } else {
  78546. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  78547. + }
  78548. +
  78549. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  78550. + complete_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  78551. + break;
  78552. + case UE_ISOCHRONOUS:
  78553. + DWC_DEBUGPL(DBG_HCDV, " Isochronous transfer complete\n");
  78554. + if (qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_ALL) {
  78555. + halt_status =
  78556. + update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  78557. + DWC_OTG_HC_XFER_COMPLETE);
  78558. + }
  78559. + complete_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  78560. + break;
  78561. + }
  78562. +
  78563. +handle_xfercomp_done:
  78564. + disable_hc_int(hc_regs, xfercompl);
  78565. +
  78566. + return 1;
  78567. +}
  78568. +
  78569. +/**
  78570. + * Handles a host channel STALL interrupt. This handler may be called in
  78571. + * either DMA mode or Slave mode.
  78572. + */
  78573. +static int32_t handle_hc_stall_intr(dwc_otg_hcd_t * hcd,
  78574. + dwc_hc_t * hc,
  78575. + dwc_otg_hc_regs_t * hc_regs,
  78576. + dwc_otg_qtd_t * qtd)
  78577. +{
  78578. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  78579. + int pipe_type = dwc_otg_hcd_get_pipe_type(&urb->pipe_info);
  78580. +
  78581. + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
  78582. + "STALL Received--\n", hc->hc_num);
  78583. +
  78584. + if (hcd->core_if->dma_desc_enable) {
  78585. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs, DWC_OTG_HC_XFER_STALL);
  78586. + goto handle_stall_done;
  78587. + }
  78588. +
  78589. + if (pipe_type == UE_CONTROL) {
  78590. + hcd->fops->complete(hcd, urb->priv, urb, -DWC_E_PIPE);
  78591. + }
  78592. +
  78593. + if (pipe_type == UE_BULK || pipe_type == UE_INTERRUPT) {
  78594. + hcd->fops->complete(hcd, urb->priv, urb, -DWC_E_PIPE);
  78595. + /*
  78596. + * USB protocol requires resetting the data toggle for bulk
  78597. + * and interrupt endpoints when a CLEAR_FEATURE(ENDPOINT_HALT)
  78598. + * setup command is issued to the endpoint. Anticipate the
  78599. + * CLEAR_FEATURE command since a STALL has occurred and reset
  78600. + * the data toggle now.
  78601. + */
  78602. + hc->qh->data_toggle = 0;
  78603. + }
  78604. +
  78605. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_STALL);
  78606. +
  78607. +handle_stall_done:
  78608. + disable_hc_int(hc_regs, stall);
  78609. +
  78610. + return 1;
  78611. +}
  78612. +
  78613. +/*
  78614. + * Updates the state of the URB when a transfer has been stopped due to an
  78615. + * abnormal condition before the transfer completes. Modifies the
  78616. + * actual_length field of the URB to reflect the number of bytes that have
  78617. + * actually been transferred via the host channel.
  78618. + */
  78619. +static void update_urb_state_xfer_intr(dwc_hc_t * hc,
  78620. + dwc_otg_hc_regs_t * hc_regs,
  78621. + dwc_otg_hcd_urb_t * urb,
  78622. + dwc_otg_qtd_t * qtd,
  78623. + dwc_otg_halt_status_e halt_status)
  78624. +{
  78625. + uint32_t bytes_transferred = get_actual_xfer_length(hc, hc_regs, qtd,
  78626. + halt_status, NULL);
  78627. + /* non DWORD-aligned buffer case handling. */
  78628. + if (hc->align_buff && bytes_transferred && hc->ep_is_in) {
  78629. + dwc_memcpy(urb->buf + urb->actual_length, hc->qh->dw_align_buf,
  78630. + bytes_transferred);
  78631. + }
  78632. +
  78633. + urb->actual_length += bytes_transferred;
  78634. +
  78635. +#ifdef DEBUG
  78636. + {
  78637. + hctsiz_data_t hctsiz;
  78638. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  78639. + DWC_DEBUGPL(DBG_HCDV, "DWC_otg: %s: %s, channel %d\n",
  78640. + __func__, (hc->ep_is_in ? "IN" : "OUT"),
  78641. + hc->hc_num);
  78642. + DWC_DEBUGPL(DBG_HCDV, " hc->start_pkt_count %d\n",
  78643. + hc->start_pkt_count);
  78644. + DWC_DEBUGPL(DBG_HCDV, " hctsiz.pktcnt %d\n", hctsiz.b.pktcnt);
  78645. + DWC_DEBUGPL(DBG_HCDV, " hc->max_packet %d\n", hc->max_packet);
  78646. + DWC_DEBUGPL(DBG_HCDV, " bytes_transferred %d\n",
  78647. + bytes_transferred);
  78648. + DWC_DEBUGPL(DBG_HCDV, " urb->actual_length %d\n",
  78649. + urb->actual_length);
  78650. + DWC_DEBUGPL(DBG_HCDV, " urb->transfer_buffer_length %d\n",
  78651. + urb->length);
  78652. + }
  78653. +#endif
  78654. +}
  78655. +
  78656. +/**
  78657. + * Handles a host channel NAK interrupt. This handler may be called in either
  78658. + * DMA mode or Slave mode.
  78659. + */
  78660. +static int32_t handle_hc_nak_intr(dwc_otg_hcd_t * hcd,
  78661. + dwc_hc_t * hc,
  78662. + dwc_otg_hc_regs_t * hc_regs,
  78663. + dwc_otg_qtd_t * qtd)
  78664. +{
  78665. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  78666. + "NAK Received--\n", hc->hc_num);
  78667. +
  78668. + /*
  78669. + * When we get bulk NAKs then remember this so we holdoff on this qh until
  78670. + * the beginning of the next frame
  78671. + */
  78672. + switch(dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  78673. + case UE_BULK:
  78674. + case UE_CONTROL:
  78675. + if (nak_holdoff && qtd->qh->do_split)
  78676. + hc->qh->nak_frame = dwc_otg_hcd_get_frame_number(hcd);
  78677. + }
  78678. +
  78679. + /*
  78680. + * Handle NAK for IN/OUT SSPLIT/CSPLIT transfers, bulk, control, and
  78681. + * interrupt. Re-start the SSPLIT transfer.
  78682. + */
  78683. + if (hc->do_split) {
  78684. + if (hc->complete_split) {
  78685. + qtd->error_count = 0;
  78686. + }
  78687. + qtd->complete_split = 0;
  78688. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
  78689. + goto handle_nak_done;
  78690. + }
  78691. +
  78692. + switch (dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  78693. + case UE_CONTROL:
  78694. + case UE_BULK:
  78695. + if (hcd->core_if->dma_enable && hc->ep_is_in) {
  78696. + /*
  78697. + * NAK interrupts are enabled on bulk/control IN
  78698. + * transfers in DMA mode for the sole purpose of
  78699. + * resetting the error count after a transaction error
  78700. + * occurs. The core will continue transferring data.
  78701. + * Disable other interrupts unmasked for the same
  78702. + * reason.
  78703. + */
  78704. + disable_hc_int(hc_regs, datatglerr);
  78705. + disable_hc_int(hc_regs, ack);
  78706. + qtd->error_count = 0;
  78707. + goto handle_nak_done;
  78708. + }
  78709. +
  78710. + /*
  78711. + * NAK interrupts normally occur during OUT transfers in DMA
  78712. + * or Slave mode. For IN transfers, more requests will be
  78713. + * queued as request queue space is available.
  78714. + */
  78715. + qtd->error_count = 0;
  78716. +
  78717. + if (!hc->qh->ping_state) {
  78718. + update_urb_state_xfer_intr(hc, hc_regs,
  78719. + qtd->urb, qtd,
  78720. + DWC_OTG_HC_XFER_NAK);
  78721. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  78722. +
  78723. + if (hc->speed == DWC_OTG_EP_SPEED_HIGH)
  78724. + hc->qh->ping_state = 1;
  78725. + }
  78726. +
  78727. + /*
  78728. + * Halt the channel so the transfer can be re-started from
  78729. + * the appropriate point or the PING protocol will
  78730. + * start/continue.
  78731. + */
  78732. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
  78733. + break;
  78734. + case UE_INTERRUPT:
  78735. + qtd->error_count = 0;
  78736. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
  78737. + break;
  78738. + case UE_ISOCHRONOUS:
  78739. + /* Should never get called for isochronous transfers. */
  78740. + DWC_ASSERT(1, "NACK interrupt for ISOC transfer\n");
  78741. + break;
  78742. + }
  78743. +
  78744. +handle_nak_done:
  78745. + disable_hc_int(hc_regs, nak);
  78746. +
  78747. + return 1;
  78748. +}
  78749. +
  78750. +/**
  78751. + * Handles a host channel ACK interrupt. This interrupt is enabled when
  78752. + * performing the PING protocol in Slave mode, when errors occur during
  78753. + * either Slave mode or DMA mode, and during Start Split transactions.
  78754. + */
  78755. +static int32_t handle_hc_ack_intr(dwc_otg_hcd_t * hcd,
  78756. + dwc_hc_t * hc,
  78757. + dwc_otg_hc_regs_t * hc_regs,
  78758. + dwc_otg_qtd_t * qtd)
  78759. +{
  78760. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  78761. + "ACK Received--\n", hc->hc_num);
  78762. +
  78763. + if (hc->do_split) {
  78764. + /*
  78765. + * Handle ACK on SSPLIT.
  78766. + * ACK should not occur in CSPLIT.
  78767. + */
  78768. + if (!hc->ep_is_in && hc->data_pid_start != DWC_OTG_HC_PID_SETUP) {
  78769. + qtd->ssplit_out_xfer_count = hc->xfer_len;
  78770. + }
  78771. + if (!(hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in)) {
  78772. + /* Don't need complete for isochronous out transfers. */
  78773. + qtd->complete_split = 1;
  78774. + }
  78775. +
  78776. + /* ISOC OUT */
  78777. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in) {
  78778. + switch (hc->xact_pos) {
  78779. + case DWC_HCSPLIT_XACTPOS_ALL:
  78780. + break;
  78781. + case DWC_HCSPLIT_XACTPOS_END:
  78782. + qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_ALL;
  78783. + qtd->isoc_split_offset = 0;
  78784. + break;
  78785. + case DWC_HCSPLIT_XACTPOS_BEGIN:
  78786. + case DWC_HCSPLIT_XACTPOS_MID:
  78787. + /*
  78788. + * For BEGIN or MID, calculate the length for
  78789. + * the next microframe to determine the correct
  78790. + * SSPLIT token, either MID or END.
  78791. + */
  78792. + {
  78793. + struct dwc_otg_hcd_iso_packet_desc
  78794. + *frame_desc;
  78795. +
  78796. + frame_desc =
  78797. + &qtd->urb->
  78798. + iso_descs[qtd->isoc_frame_index];
  78799. + qtd->isoc_split_offset += 188;
  78800. +
  78801. + if ((frame_desc->length -
  78802. + qtd->isoc_split_offset) <= 188) {
  78803. + qtd->isoc_split_pos =
  78804. + DWC_HCSPLIT_XACTPOS_END;
  78805. + } else {
  78806. + qtd->isoc_split_pos =
  78807. + DWC_HCSPLIT_XACTPOS_MID;
  78808. + }
  78809. +
  78810. + }
  78811. + break;
  78812. + }
  78813. + } else {
  78814. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_ACK);
  78815. + }
  78816. + } else {
  78817. + /*
  78818. + * An unmasked ACK on a non-split DMA transaction is
  78819. + * for the sole purpose of resetting error counts. Disable other
  78820. + * interrupts unmasked for the same reason.
  78821. + */
  78822. + if(hcd->core_if->dma_enable) {
  78823. + disable_hc_int(hc_regs, datatglerr);
  78824. + disable_hc_int(hc_regs, nak);
  78825. + }
  78826. + qtd->error_count = 0;
  78827. +
  78828. + if (hc->qh->ping_state) {
  78829. + hc->qh->ping_state = 0;
  78830. + /*
  78831. + * Halt the channel so the transfer can be re-started
  78832. + * from the appropriate point. This only happens in
  78833. + * Slave mode. In DMA mode, the ping_state is cleared
  78834. + * when the transfer is started because the core
  78835. + * automatically executes the PING, then the transfer.
  78836. + */
  78837. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_ACK);
  78838. + }
  78839. + }
  78840. +
  78841. + /*
  78842. + * If the ACK occurred when _not_ in the PING state, let the channel
  78843. + * continue transferring data after clearing the error count.
  78844. + */
  78845. +
  78846. + disable_hc_int(hc_regs, ack);
  78847. +
  78848. + return 1;
  78849. +}
  78850. +
  78851. +/**
  78852. + * Handles a host channel NYET interrupt. This interrupt should only occur on
  78853. + * Bulk and Control OUT endpoints and for complete split transactions. If a
  78854. + * NYET occurs at the same time as a Transfer Complete interrupt, it is
  78855. + * handled in the xfercomp interrupt handler, not here. This handler may be
  78856. + * called in either DMA mode or Slave mode.
  78857. + */
  78858. +static int32_t handle_hc_nyet_intr(dwc_otg_hcd_t * hcd,
  78859. + dwc_hc_t * hc,
  78860. + dwc_otg_hc_regs_t * hc_regs,
  78861. + dwc_otg_qtd_t * qtd)
  78862. +{
  78863. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  78864. + "NYET Received--\n", hc->hc_num);
  78865. +
  78866. + /*
  78867. + * NYET on CSPLIT
  78868. + * re-do the CSPLIT immediately on non-periodic
  78869. + */
  78870. + if (hc->do_split && hc->complete_split) {
  78871. + if (hc->ep_is_in && (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  78872. + && hcd->core_if->dma_enable) {
  78873. + qtd->complete_split = 0;
  78874. + qtd->isoc_split_offset = 0;
  78875. + if (++qtd->isoc_frame_index == qtd->urb->packet_count) {
  78876. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  78877. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  78878. + }
  78879. + else
  78880. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  78881. + goto handle_nyet_done;
  78882. + }
  78883. +
  78884. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  78885. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  78886. + int frnum = dwc_otg_hcd_get_frame_number(hcd);
  78887. +
  78888. + // With the FIQ running we only ever see the failed NYET
  78889. + if (dwc_full_frame_num(frnum) !=
  78890. + dwc_full_frame_num(hc->qh->sched_frame) ||
  78891. + fiq_fsm_enable) {
  78892. + /*
  78893. + * No longer in the same full speed frame.
  78894. + * Treat this as a transaction error.
  78895. + */
  78896. +#if 0
  78897. + /** @todo Fix system performance so this can
  78898. + * be treated as an error. Right now complete
  78899. + * splits cannot be scheduled precisely enough
  78900. + * due to other system activity, so this error
  78901. + * occurs regularly in Slave mode.
  78902. + */
  78903. + qtd->error_count++;
  78904. +#endif
  78905. + qtd->complete_split = 0;
  78906. + halt_channel(hcd, hc, qtd,
  78907. + DWC_OTG_HC_XFER_XACT_ERR);
  78908. + /** @todo add support for isoc release */
  78909. + goto handle_nyet_done;
  78910. + }
  78911. + }
  78912. +
  78913. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NYET);
  78914. + goto handle_nyet_done;
  78915. + }
  78916. +
  78917. + hc->qh->ping_state = 1;
  78918. + qtd->error_count = 0;
  78919. +
  78920. + update_urb_state_xfer_intr(hc, hc_regs, qtd->urb, qtd,
  78921. + DWC_OTG_HC_XFER_NYET);
  78922. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  78923. +
  78924. + /*
  78925. + * Halt the channel and re-start the transfer so the PING
  78926. + * protocol will start.
  78927. + */
  78928. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NYET);
  78929. +
  78930. +handle_nyet_done:
  78931. + disable_hc_int(hc_regs, nyet);
  78932. + return 1;
  78933. +}
  78934. +
  78935. +/**
  78936. + * Handles a host channel babble interrupt. This handler may be called in
  78937. + * either DMA mode or Slave mode.
  78938. + */
  78939. +static int32_t handle_hc_babble_intr(dwc_otg_hcd_t * hcd,
  78940. + dwc_hc_t * hc,
  78941. + dwc_otg_hc_regs_t * hc_regs,
  78942. + dwc_otg_qtd_t * qtd)
  78943. +{
  78944. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  78945. + "Babble Error--\n", hc->hc_num);
  78946. +
  78947. + if (hcd->core_if->dma_desc_enable) {
  78948. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  78949. + DWC_OTG_HC_XFER_BABBLE_ERR);
  78950. + goto handle_babble_done;
  78951. + }
  78952. +
  78953. + if (hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
  78954. + hcd->fops->complete(hcd, qtd->urb->priv,
  78955. + qtd->urb, -DWC_E_OVERFLOW);
  78956. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_BABBLE_ERR);
  78957. + } else {
  78958. + dwc_otg_halt_status_e halt_status;
  78959. + halt_status = update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  78960. + DWC_OTG_HC_XFER_BABBLE_ERR);
  78961. + halt_channel(hcd, hc, qtd, halt_status);
  78962. + }
  78963. +
  78964. +handle_babble_done:
  78965. + disable_hc_int(hc_regs, bblerr);
  78966. + return 1;
  78967. +}
  78968. +
  78969. +/**
  78970. + * Handles a host channel AHB error interrupt. This handler is only called in
  78971. + * DMA mode.
  78972. + */
  78973. +static int32_t handle_hc_ahberr_intr(dwc_otg_hcd_t * hcd,
  78974. + dwc_hc_t * hc,
  78975. + dwc_otg_hc_regs_t * hc_regs,
  78976. + dwc_otg_qtd_t * qtd)
  78977. +{
  78978. + hcchar_data_t hcchar;
  78979. + hcsplt_data_t hcsplt;
  78980. + hctsiz_data_t hctsiz;
  78981. + uint32_t hcdma;
  78982. + char *pipetype, *speed;
  78983. +
  78984. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  78985. +
  78986. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  78987. + "AHB Error--\n", hc->hc_num);
  78988. +
  78989. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  78990. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  78991. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  78992. + hcdma = DWC_READ_REG32(&hc_regs->hcdma);
  78993. +
  78994. + DWC_ERROR("AHB ERROR, Channel %d\n", hc->hc_num);
  78995. + DWC_ERROR(" hcchar 0x%08x, hcsplt 0x%08x\n", hcchar.d32, hcsplt.d32);
  78996. + DWC_ERROR(" hctsiz 0x%08x, hcdma 0x%08x\n", hctsiz.d32, hcdma);
  78997. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Enqueue\n");
  78998. + DWC_ERROR(" Device address: %d\n",
  78999. + dwc_otg_hcd_get_dev_addr(&urb->pipe_info));
  79000. + DWC_ERROR(" Endpoint: %d, %s\n",
  79001. + dwc_otg_hcd_get_ep_num(&urb->pipe_info),
  79002. + (dwc_otg_hcd_is_pipe_in(&urb->pipe_info) ? "IN" : "OUT"));
  79003. +
  79004. + switch (dwc_otg_hcd_get_pipe_type(&urb->pipe_info)) {
  79005. + case UE_CONTROL:
  79006. + pipetype = "CONTROL";
  79007. + break;
  79008. + case UE_BULK:
  79009. + pipetype = "BULK";
  79010. + break;
  79011. + case UE_INTERRUPT:
  79012. + pipetype = "INTERRUPT";
  79013. + break;
  79014. + case UE_ISOCHRONOUS:
  79015. + pipetype = "ISOCHRONOUS";
  79016. + break;
  79017. + default:
  79018. + pipetype = "UNKNOWN";
  79019. + break;
  79020. + }
  79021. +
  79022. + DWC_ERROR(" Endpoint type: %s\n", pipetype);
  79023. +
  79024. + switch (hc->speed) {
  79025. + case DWC_OTG_EP_SPEED_HIGH:
  79026. + speed = "HIGH";
  79027. + break;
  79028. + case DWC_OTG_EP_SPEED_FULL:
  79029. + speed = "FULL";
  79030. + break;
  79031. + case DWC_OTG_EP_SPEED_LOW:
  79032. + speed = "LOW";
  79033. + break;
  79034. + default:
  79035. + speed = "UNKNOWN";
  79036. + break;
  79037. + };
  79038. +
  79039. + DWC_ERROR(" Speed: %s\n", speed);
  79040. +
  79041. + DWC_ERROR(" Max packet size: %d\n",
  79042. + dwc_otg_hcd_get_mps(&urb->pipe_info));
  79043. + DWC_ERROR(" Data buffer length: %d\n", urb->length);
  79044. + DWC_ERROR(" Transfer buffer: %p, Transfer DMA: %p\n",
  79045. + urb->buf, (void *)urb->dma);
  79046. + DWC_ERROR(" Setup buffer: %p, Setup DMA: %p\n",
  79047. + urb->setup_packet, (void *)urb->setup_dma);
  79048. + DWC_ERROR(" Interval: %d\n", urb->interval);
  79049. +
  79050. + /* Core haltes the channel for Descriptor DMA mode */
  79051. + if (hcd->core_if->dma_desc_enable) {
  79052. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  79053. + DWC_OTG_HC_XFER_AHB_ERR);
  79054. + goto handle_ahberr_done;
  79055. + }
  79056. +
  79057. + hcd->fops->complete(hcd, urb->priv, urb, -DWC_E_IO);
  79058. +
  79059. + /*
  79060. + * Force a channel halt. Don't call halt_channel because that won't
  79061. + * write to the HCCHARn register in DMA mode to force the halt.
  79062. + */
  79063. + dwc_otg_hc_halt(hcd->core_if, hc, DWC_OTG_HC_XFER_AHB_ERR);
  79064. +handle_ahberr_done:
  79065. + disable_hc_int(hc_regs, ahberr);
  79066. + return 1;
  79067. +}
  79068. +
  79069. +/**
  79070. + * Handles a host channel transaction error interrupt. This handler may be
  79071. + * called in either DMA mode or Slave mode.
  79072. + */
  79073. +static int32_t handle_hc_xacterr_intr(dwc_otg_hcd_t * hcd,
  79074. + dwc_hc_t * hc,
  79075. + dwc_otg_hc_regs_t * hc_regs,
  79076. + dwc_otg_qtd_t * qtd)
  79077. +{
  79078. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  79079. + "Transaction Error--\n", hc->hc_num);
  79080. +
  79081. + if (hcd->core_if->dma_desc_enable) {
  79082. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  79083. + DWC_OTG_HC_XFER_XACT_ERR);
  79084. + goto handle_xacterr_done;
  79085. + }
  79086. +
  79087. + switch (dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  79088. + case UE_CONTROL:
  79089. + case UE_BULK:
  79090. + qtd->error_count++;
  79091. + if (!hc->qh->ping_state) {
  79092. +
  79093. + update_urb_state_xfer_intr(hc, hc_regs,
  79094. + qtd->urb, qtd,
  79095. + DWC_OTG_HC_XFER_XACT_ERR);
  79096. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  79097. + if (!hc->ep_is_in && hc->speed == DWC_OTG_EP_SPEED_HIGH) {
  79098. + hc->qh->ping_state = 1;
  79099. + }
  79100. + }
  79101. +
  79102. + /*
  79103. + * Halt the channel so the transfer can be re-started from
  79104. + * the appropriate point or the PING protocol will start.
  79105. + */
  79106. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  79107. + break;
  79108. + case UE_INTERRUPT:
  79109. + qtd->error_count++;
  79110. + if (hc->do_split && hc->complete_split) {
  79111. + qtd->complete_split = 0;
  79112. + }
  79113. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  79114. + break;
  79115. + case UE_ISOCHRONOUS:
  79116. + {
  79117. + dwc_otg_halt_status_e halt_status;
  79118. + halt_status =
  79119. + update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  79120. + DWC_OTG_HC_XFER_XACT_ERR);
  79121. +
  79122. + halt_channel(hcd, hc, qtd, halt_status);
  79123. + }
  79124. + break;
  79125. + }
  79126. +handle_xacterr_done:
  79127. + disable_hc_int(hc_regs, xacterr);
  79128. +
  79129. + return 1;
  79130. +}
  79131. +
  79132. +/**
  79133. + * Handles a host channel frame overrun interrupt. This handler may be called
  79134. + * in either DMA mode or Slave mode.
  79135. + */
  79136. +static int32_t handle_hc_frmovrun_intr(dwc_otg_hcd_t * hcd,
  79137. + dwc_hc_t * hc,
  79138. + dwc_otg_hc_regs_t * hc_regs,
  79139. + dwc_otg_qtd_t * qtd)
  79140. +{
  79141. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  79142. + "Frame Overrun--\n", hc->hc_num);
  79143. +
  79144. + switch (dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  79145. + case UE_CONTROL:
  79146. + case UE_BULK:
  79147. + break;
  79148. + case UE_INTERRUPT:
  79149. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_FRAME_OVERRUN);
  79150. + break;
  79151. + case UE_ISOCHRONOUS:
  79152. + {
  79153. + dwc_otg_halt_status_e halt_status;
  79154. + halt_status =
  79155. + update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  79156. + DWC_OTG_HC_XFER_FRAME_OVERRUN);
  79157. +
  79158. + halt_channel(hcd, hc, qtd, halt_status);
  79159. + }
  79160. + break;
  79161. + }
  79162. +
  79163. + disable_hc_int(hc_regs, frmovrun);
  79164. +
  79165. + return 1;
  79166. +}
  79167. +
  79168. +/**
  79169. + * Handles a host channel data toggle error interrupt. This handler may be
  79170. + * called in either DMA mode or Slave mode.
  79171. + */
  79172. +static int32_t handle_hc_datatglerr_intr(dwc_otg_hcd_t * hcd,
  79173. + dwc_hc_t * hc,
  79174. + dwc_otg_hc_regs_t * hc_regs,
  79175. + dwc_otg_qtd_t * qtd)
  79176. +{
  79177. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  79178. + "Data Toggle Error on %s transfer--\n",
  79179. + hc->hc_num, (hc->ep_is_in ? "IN" : "OUT"));
  79180. +
  79181. + /* Data toggles on split transactions cause the hc to halt.
  79182. + * restart transfer */
  79183. + if(hc->qh->do_split)
  79184. + {
  79185. + qtd->error_count++;
  79186. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  79187. + update_urb_state_xfer_intr(hc, hc_regs,
  79188. + qtd->urb, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  79189. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  79190. + } else if (hc->ep_is_in) {
  79191. + /* An unmasked data toggle error on a non-split DMA transaction is
  79192. + * for the sole purpose of resetting error counts. Disable other
  79193. + * interrupts unmasked for the same reason.
  79194. + */
  79195. + if(hcd->core_if->dma_enable) {
  79196. + disable_hc_int(hc_regs, ack);
  79197. + disable_hc_int(hc_regs, nak);
  79198. + }
  79199. + qtd->error_count = 0;
  79200. + }
  79201. +
  79202. + disable_hc_int(hc_regs, datatglerr);
  79203. +
  79204. + return 1;
  79205. +}
  79206. +
  79207. +#ifdef DEBUG
  79208. +/**
  79209. + * This function is for debug only. It checks that a valid halt status is set
  79210. + * and that HCCHARn.chdis is clear. If there's a problem, corrective action is
  79211. + * taken and a warning is issued.
  79212. + * @return 1 if halt status is ok, 0 otherwise.
  79213. + */
  79214. +static inline int halt_status_ok(dwc_otg_hcd_t * hcd,
  79215. + dwc_hc_t * hc,
  79216. + dwc_otg_hc_regs_t * hc_regs,
  79217. + dwc_otg_qtd_t * qtd)
  79218. +{
  79219. + hcchar_data_t hcchar;
  79220. + hctsiz_data_t hctsiz;
  79221. + hcint_data_t hcint;
  79222. + hcintmsk_data_t hcintmsk;
  79223. + hcsplt_data_t hcsplt;
  79224. +
  79225. + if (hc->halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS) {
  79226. + /*
  79227. + * This code is here only as a check. This condition should
  79228. + * never happen. Ignore the halt if it does occur.
  79229. + */
  79230. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  79231. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  79232. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  79233. + hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
  79234. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  79235. + DWC_WARN
  79236. + ("%s: hc->halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS, "
  79237. + "channel %d, hcchar 0x%08x, hctsiz 0x%08x, "
  79238. + "hcint 0x%08x, hcintmsk 0x%08x, "
  79239. + "hcsplt 0x%08x, qtd->complete_split %d\n", __func__,
  79240. + hc->hc_num, hcchar.d32, hctsiz.d32, hcint.d32,
  79241. + hcintmsk.d32, hcsplt.d32, qtd->complete_split);
  79242. +
  79243. + DWC_WARN("%s: no halt status, channel %d, ignoring interrupt\n",
  79244. + __func__, hc->hc_num);
  79245. + DWC_WARN("\n");
  79246. + clear_hc_int(hc_regs, chhltd);
  79247. + return 0;
  79248. + }
  79249. +
  79250. + /*
  79251. + * This code is here only as a check. hcchar.chdis should
  79252. + * never be set when the halt interrupt occurs. Halt the
  79253. + * channel again if it does occur.
  79254. + */
  79255. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  79256. + if (hcchar.b.chdis) {
  79257. + DWC_WARN("%s: hcchar.chdis set unexpectedly, "
  79258. + "hcchar 0x%08x, trying to halt again\n",
  79259. + __func__, hcchar.d32);
  79260. + clear_hc_int(hc_regs, chhltd);
  79261. + hc->halt_pending = 0;
  79262. + halt_channel(hcd, hc, qtd, hc->halt_status);
  79263. + return 0;
  79264. + }
  79265. +
  79266. + return 1;
  79267. +}
  79268. +#endif
  79269. +
  79270. +/**
  79271. + * Handles a host Channel Halted interrupt in DMA mode. This handler
  79272. + * determines the reason the channel halted and proceeds accordingly.
  79273. + */
  79274. +static void handle_hc_chhltd_intr_dma(dwc_otg_hcd_t * hcd,
  79275. + dwc_hc_t * hc,
  79276. + dwc_otg_hc_regs_t * hc_regs,
  79277. + dwc_otg_qtd_t * qtd)
  79278. +{
  79279. + int out_nak_enh = 0;
  79280. + hcint_data_t hcint;
  79281. + hcintmsk_data_t hcintmsk;
  79282. + /* For core with OUT NAK enhancement, the flow for high-
  79283. + * speed CONTROL/BULK OUT is handled a little differently.
  79284. + */
  79285. + if (hcd->core_if->snpsid >= OTG_CORE_REV_2_71a) {
  79286. + if (hc->speed == DWC_OTG_EP_SPEED_HIGH && !hc->ep_is_in &&
  79287. + (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
  79288. + hc->ep_type == DWC_OTG_EP_TYPE_BULK)) {
  79289. + out_nak_enh = 1;
  79290. + }
  79291. + }
  79292. +
  79293. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE ||
  79294. + (hc->halt_status == DWC_OTG_HC_XFER_AHB_ERR
  79295. + && !hcd->core_if->dma_desc_enable)) {
  79296. + /*
  79297. + * Just release the channel. A dequeue can happen on a
  79298. + * transfer timeout. In the case of an AHB Error, the channel
  79299. + * was forced to halt because there's no way to gracefully
  79300. + * recover.
  79301. + */
  79302. + if (hcd->core_if->dma_desc_enable)
  79303. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  79304. + hc->halt_status);
  79305. + else
  79306. + release_channel(hcd, hc, qtd, hc->halt_status);
  79307. + return;
  79308. + }
  79309. +
  79310. + /* Read the HCINTn register to determine the cause for the halt. */
  79311. +
  79312. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  79313. + hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
  79314. +
  79315. + if (hcint.b.xfercomp) {
  79316. + /** @todo This is here because of a possible hardware bug. Spec
  79317. + * says that on SPLIT-ISOC OUT transfers in DMA mode that a HALT
  79318. + * interrupt w/ACK bit set should occur, but I only see the
  79319. + * XFERCOMP bit, even with it masked out. This is a workaround
  79320. + * for that behavior. Should fix this when hardware is fixed.
  79321. + */
  79322. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in) {
  79323. + handle_hc_ack_intr(hcd, hc, hc_regs, qtd);
  79324. + }
  79325. + handle_hc_xfercomp_intr(hcd, hc, hc_regs, qtd);
  79326. + } else if (hcint.b.stall) {
  79327. + handle_hc_stall_intr(hcd, hc, hc_regs, qtd);
  79328. + } else if (hcint.b.xacterr && !hcd->core_if->dma_desc_enable) {
  79329. + if (out_nak_enh) {
  79330. + if (hcint.b.nyet || hcint.b.nak || hcint.b.ack) {
  79331. + DWC_DEBUGPL(DBG_HCD, "XactErr with NYET/NAK/ACK\n");
  79332. + qtd->error_count = 0;
  79333. + } else {
  79334. + DWC_DEBUGPL(DBG_HCD, "XactErr without NYET/NAK/ACK\n");
  79335. + }
  79336. + }
  79337. +
  79338. + /*
  79339. + * Must handle xacterr before nak or ack. Could get a xacterr
  79340. + * at the same time as either of these on a BULK/CONTROL OUT
  79341. + * that started with a PING. The xacterr takes precedence.
  79342. + */
  79343. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  79344. + } else if (hcint.b.xcs_xact && hcd->core_if->dma_desc_enable) {
  79345. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  79346. + } else if (hcint.b.ahberr && hcd->core_if->dma_desc_enable) {
  79347. + handle_hc_ahberr_intr(hcd, hc, hc_regs, qtd);
  79348. + } else if (hcint.b.bblerr) {
  79349. + handle_hc_babble_intr(hcd, hc, hc_regs, qtd);
  79350. + } else if (hcint.b.frmovrun) {
  79351. + handle_hc_frmovrun_intr(hcd, hc, hc_regs, qtd);
  79352. + } else if (hcint.b.datatglerr) {
  79353. + handle_hc_datatglerr_intr(hcd, hc, hc_regs, qtd);
  79354. + } else if (!out_nak_enh) {
  79355. + if (hcint.b.nyet) {
  79356. + /*
  79357. + * Must handle nyet before nak or ack. Could get a nyet at the
  79358. + * same time as either of those on a BULK/CONTROL OUT that
  79359. + * started with a PING. The nyet takes precedence.
  79360. + */
  79361. + handle_hc_nyet_intr(hcd, hc, hc_regs, qtd);
  79362. + } else if (hcint.b.nak && !hcintmsk.b.nak) {
  79363. + /*
  79364. + * If nak is not masked, it's because a non-split IN transfer
  79365. + * is in an error state. In that case, the nak is handled by
  79366. + * the nak interrupt handler, not here. Handle nak here for
  79367. + * BULK/CONTROL OUT transfers, which halt on a NAK to allow
  79368. + * rewinding the buffer pointer.
  79369. + */
  79370. + handle_hc_nak_intr(hcd, hc, hc_regs, qtd);
  79371. + } else if (hcint.b.ack && !hcintmsk.b.ack) {
  79372. + /*
  79373. + * If ack is not masked, it's because a non-split IN transfer
  79374. + * is in an error state. In that case, the ack is handled by
  79375. + * the ack interrupt handler, not here. Handle ack here for
  79376. + * split transfers. Start splits halt on ACK.
  79377. + */
  79378. + handle_hc_ack_intr(hcd, hc, hc_regs, qtd);
  79379. + } else {
  79380. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  79381. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  79382. + /*
  79383. + * A periodic transfer halted with no other channel
  79384. + * interrupts set. Assume it was halted by the core
  79385. + * because it could not be completed in its scheduled
  79386. + * (micro)frame.
  79387. + */
  79388. +#ifdef DEBUG
  79389. + DWC_PRINTF
  79390. + ("%s: Halt channel %d (assume incomplete periodic transfer)\n",
  79391. + __func__, hc->hc_num);
  79392. +#endif
  79393. + halt_channel(hcd, hc, qtd,
  79394. + DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE);
  79395. + } else {
  79396. + DWC_ERROR
  79397. + ("%s: Channel %d, DMA Mode -- ChHltd set, but reason "
  79398. + "for halting is unknown, hcint 0x%08x, intsts 0x%08x\n",
  79399. + __func__, hc->hc_num, hcint.d32,
  79400. + DWC_READ_REG32(&hcd->
  79401. + core_if->core_global_regs->
  79402. + gintsts));
  79403. + /* Failthrough: use 3-strikes rule */
  79404. + qtd->error_count++;
  79405. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  79406. + update_urb_state_xfer_intr(hc, hc_regs,
  79407. + qtd->urb, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  79408. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  79409. + }
  79410. +
  79411. + }
  79412. + } else {
  79413. + DWC_PRINTF("NYET/NAK/ACK/other in non-error case, 0x%08x\n",
  79414. + hcint.d32);
  79415. + /* Failthrough: use 3-strikes rule */
  79416. + qtd->error_count++;
  79417. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  79418. + update_urb_state_xfer_intr(hc, hc_regs,
  79419. + qtd->urb, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  79420. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  79421. + }
  79422. +}
  79423. +
  79424. +/**
  79425. + * Handles a host channel Channel Halted interrupt.
  79426. + *
  79427. + * In slave mode, this handler is called only when the driver specifically
  79428. + * requests a halt. This occurs during handling other host channel interrupts
  79429. + * (e.g. nak, xacterr, stall, nyet, etc.).
  79430. + *
  79431. + * In DMA mode, this is the interrupt that occurs when the core has finished
  79432. + * processing a transfer on a channel. Other host channel interrupts (except
  79433. + * ahberr) are disabled in DMA mode.
  79434. + */
  79435. +static int32_t handle_hc_chhltd_intr(dwc_otg_hcd_t * hcd,
  79436. + dwc_hc_t * hc,
  79437. + dwc_otg_hc_regs_t * hc_regs,
  79438. + dwc_otg_qtd_t * qtd)
  79439. +{
  79440. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  79441. + "Channel Halted--\n", hc->hc_num);
  79442. +
  79443. + if (hcd->core_if->dma_enable) {
  79444. + handle_hc_chhltd_intr_dma(hcd, hc, hc_regs, qtd);
  79445. + } else {
  79446. +#ifdef DEBUG
  79447. + if (!halt_status_ok(hcd, hc, hc_regs, qtd)) {
  79448. + return 1;
  79449. + }
  79450. +#endif
  79451. + release_channel(hcd, hc, qtd, hc->halt_status);
  79452. + }
  79453. +
  79454. + return 1;
  79455. +}
  79456. +
  79457. +
  79458. +/**
  79459. + * dwc_otg_fiq_unmangle_isoc() - Update the iso_frame_desc structure on
  79460. + * FIQ transfer completion
  79461. + * @hcd: Pointer to dwc_otg_hcd struct
  79462. + * @num: Host channel number
  79463. + *
  79464. + * 1. Un-mangle the status as recorded in each iso_frame_desc status
  79465. + * 2. Copy it from the dwc_otg_urb into the real URB
  79466. + */
  79467. +void dwc_otg_fiq_unmangle_isoc(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh, dwc_otg_qtd_t *qtd, uint32_t num)
  79468. +{
  79469. + struct dwc_otg_hcd_urb *dwc_urb = qtd->urb;
  79470. + int nr_frames = dwc_urb->packet_count;
  79471. + int i;
  79472. + hcint_data_t frame_hcint;
  79473. +
  79474. + for (i = 0; i < nr_frames; i++) {
  79475. + frame_hcint.d32 = dwc_urb->iso_descs[i].status;
  79476. + if (frame_hcint.b.xfercomp) {
  79477. + dwc_urb->iso_descs[i].status = 0;
  79478. + dwc_urb->actual_length += dwc_urb->iso_descs[i].actual_length;
  79479. + } else if (frame_hcint.b.frmovrun) {
  79480. + if (qh->ep_is_in)
  79481. + dwc_urb->iso_descs[i].status = -DWC_E_NO_STREAM_RES;
  79482. + else
  79483. + dwc_urb->iso_descs[i].status = -DWC_E_COMMUNICATION;
  79484. + dwc_urb->error_count++;
  79485. + dwc_urb->iso_descs[i].actual_length = 0;
  79486. + } else if (frame_hcint.b.xacterr) {
  79487. + dwc_urb->iso_descs[i].status = -DWC_E_PROTOCOL;
  79488. + dwc_urb->error_count++;
  79489. + dwc_urb->iso_descs[i].actual_length = 0;
  79490. + } else if (frame_hcint.b.bblerr) {
  79491. + dwc_urb->iso_descs[i].status = -DWC_E_OVERFLOW;
  79492. + dwc_urb->error_count++;
  79493. + dwc_urb->iso_descs[i].actual_length = 0;
  79494. + } else {
  79495. + /* Something went wrong */
  79496. + dwc_urb->iso_descs[i].status = -1;
  79497. + dwc_urb->iso_descs[i].actual_length = 0;
  79498. + dwc_urb->error_count++;
  79499. + }
  79500. + }
  79501. + //printk_ratelimited(KERN_INFO "%s: HS isochronous of %d/%d frames with %d errors complete\n",
  79502. + // __FUNCTION__, i, dwc_urb->packet_count, dwc_urb->error_count);
  79503. + hcd->fops->complete(hcd, dwc_urb->priv, dwc_urb, 0);
  79504. + release_channel(hcd, qh->channel, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  79505. +}
  79506. +
  79507. +/**
  79508. + * dwc_otg_fiq_unsetup_per_dma() - Remove data from bounce buffers for split transactions
  79509. + * @hcd: Pointer to dwc_otg_hcd struct
  79510. + * @num: Host channel number
  79511. + *
  79512. + * Copies data from the FIQ bounce buffers into the URB's transfer buffer. Does not modify URB state.
  79513. + * Returns total length of data or -1 if the buffers were not used.
  79514. + *
  79515. + */
  79516. +int dwc_otg_fiq_unsetup_per_dma(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh, dwc_otg_qtd_t *qtd, uint32_t num)
  79517. +{
  79518. + dwc_hc_t *hc = qh->channel;
  79519. + struct fiq_dma_blob *blob = hcd->fiq_dmab;
  79520. + struct fiq_channel_state *st = &hcd->fiq_state->channel[num];
  79521. + uint8_t *ptr = NULL;
  79522. + int index = 0, len = 0;
  79523. + int i = 0;
  79524. + if (hc->ep_is_in) {
  79525. + /* Copy data out of the DMA bounce buffers to the URB's buffer.
  79526. + * The align_buf is ignored as this is ignored on FSM enqueue. */
  79527. + ptr = qtd->urb->buf;
  79528. + if (qh->ep_type == UE_ISOCHRONOUS) {
  79529. + /* Isoc IN transactions - grab the offset of the iso_frame_desc into the URB transfer buffer */
  79530. + index = qtd->isoc_frame_index;
  79531. + ptr += qtd->urb->iso_descs[index].offset;
  79532. + } else {
  79533. + /* Need to increment by actual_length for interrupt IN */
  79534. + ptr += qtd->urb->actual_length;
  79535. + }
  79536. +
  79537. + for (i = 0; i < st->dma_info.index; i++) {
  79538. + len += st->dma_info.slot_len[i];
  79539. + dwc_memcpy(ptr, &blob->channel[num].index[i].buf[0], st->dma_info.slot_len[i]);
  79540. + ptr += st->dma_info.slot_len[i];
  79541. + }
  79542. + return len;
  79543. + } else {
  79544. + /* OUT endpoints - nothing to do. */
  79545. + return -1;
  79546. + }
  79547. +
  79548. +}
  79549. +/**
  79550. + * dwc_otg_hcd_handle_hc_fsm() - handle an unmasked channel interrupt
  79551. + * from a channel handled in the FIQ
  79552. + * @hcd: Pointer to dwc_otg_hcd struct
  79553. + * @num: Host channel number
  79554. + *
  79555. + * If a host channel interrupt was received by the IRQ and this was a channel
  79556. + * used by the FIQ, the execution flow for transfer completion is substantially
  79557. + * different from the normal (messy) path. This function and its friends handles
  79558. + * channel cleanup and transaction completion from a FIQ transaction.
  79559. + */
  79560. +int32_t dwc_otg_hcd_handle_hc_fsm(dwc_otg_hcd_t *hcd, uint32_t num)
  79561. +{
  79562. + struct fiq_channel_state *st = &hcd->fiq_state->channel[num];
  79563. + dwc_hc_t *hc = hcd->hc_ptr_array[num];
  79564. + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&hc->qh->qtd_list);
  79565. + dwc_otg_qh_t *qh = hc->qh;
  79566. + dwc_otg_hc_regs_t *hc_regs = hcd->core_if->host_if->hc_regs[num];
  79567. + hcint_data_t hcint = hcd->fiq_state->channel[num].hcint_copy;
  79568. + int hostchannels = 0;
  79569. + int ret = 0;
  79570. + fiq_print(FIQDBG_INT, hcd->fiq_state, "OUT %01d %01d ", num , st->fsm);
  79571. +
  79572. + hostchannels = hcd->available_host_channels;
  79573. + switch (st->fsm) {
  79574. + case FIQ_TEST:
  79575. + break;
  79576. +
  79577. + case FIQ_DEQUEUE_ISSUED:
  79578. + /* hc_halt was called. QTD no longer exists. */
  79579. + /* TODO: for a nonperiodic split transaction, need to issue a
  79580. + * CLEAR_TT_BUFFER hub command if we were in the start-split phase.
  79581. + */
  79582. + release_channel(hcd, hc, NULL, hc->halt_status);
  79583. + ret = 1;
  79584. + break;
  79585. +
  79586. + case FIQ_NP_SPLIT_DONE:
  79587. + /* Nonperiodic transaction complete. */
  79588. + if (!hc->ep_is_in) {
  79589. + qtd->ssplit_out_xfer_count = hc->xfer_len;
  79590. + }
  79591. + if (hcint.b.xfercomp) {
  79592. + handle_hc_xfercomp_intr(hcd, hc, hc_regs, qtd);
  79593. + } else if (hcint.b.nak) {
  79594. + handle_hc_nak_intr(hcd, hc, hc_regs, qtd);
  79595. + }
  79596. + ret = 1;
  79597. + break;
  79598. +
  79599. + case FIQ_NP_SPLIT_HS_ABORTED:
  79600. + /* A HS abort is a 3-strikes on the HS bus at any point in the transaction.
  79601. + * Normally a CLEAR_TT_BUFFER hub command would be required: we can't do that
  79602. + * because there's no guarantee which order a non-periodic split happened in.
  79603. + * We could end up clearing a perfectly good transaction out of the buffer.
  79604. + */
  79605. + if (hcint.b.xacterr) {
  79606. + qtd->error_count += st->nr_errors;
  79607. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  79608. + } else if (hcint.b.ahberr) {
  79609. + handle_hc_ahberr_intr(hcd, hc, hc_regs, qtd);
  79610. + } else {
  79611. + local_fiq_disable();
  79612. + BUG();
  79613. + }
  79614. + break;
  79615. +
  79616. + case FIQ_NP_SPLIT_LS_ABORTED:
  79617. + /* A few cases can cause this - either an unknown state on a SSPLIT or
  79618. + * STALL/data toggle error response on a CSPLIT */
  79619. + if (hcint.b.stall) {
  79620. + handle_hc_stall_intr(hcd, hc, hc_regs, qtd);
  79621. + } else if (hcint.b.datatglerr) {
  79622. + handle_hc_datatglerr_intr(hcd, hc, hc_regs, qtd);
  79623. + } else if (hcint.b.ahberr) {
  79624. + handle_hc_ahberr_intr(hcd, hc, hc_regs, qtd);
  79625. + } else {
  79626. + local_fiq_disable();
  79627. + BUG();
  79628. + }
  79629. + break;
  79630. +
  79631. + case FIQ_PER_SPLIT_DONE:
  79632. + /* Isoc IN or Interrupt IN/OUT */
  79633. +
  79634. + /* Flow control here is different from the normal execution by the driver.
  79635. + * We need to completely ignore most of the driver's method of handling
  79636. + * split transactions and do it ourselves.
  79637. + */
  79638. + if (hc->ep_type == UE_INTERRUPT) {
  79639. + if (hcint.b.nak) {
  79640. + handle_hc_nak_intr(hcd, hc, hc_regs, qtd);
  79641. + } else if (hc->ep_is_in) {
  79642. + int len;
  79643. + len = dwc_otg_fiq_unsetup_per_dma(hcd, hc->qh, qtd, num);
  79644. + //printk(KERN_NOTICE "FIQ Transaction: hc=%d len=%d urb_len = %d\n", num, len, qtd->urb->length);
  79645. + qtd->urb->actual_length += len;
  79646. + if (qtd->urb->actual_length >= qtd->urb->length) {
  79647. + qtd->urb->status = 0;
  79648. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, qtd->urb->status);
  79649. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  79650. + } else {
  79651. + /* Interrupt transfer not complete yet - is it a short read? */
  79652. + if (len < hc->max_packet) {
  79653. + /* Interrupt transaction complete */
  79654. + qtd->urb->status = 0;
  79655. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, qtd->urb->status);
  79656. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  79657. + } else {
  79658. + /* Further transactions required */
  79659. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  79660. + }
  79661. + }
  79662. + } else {
  79663. + /* Interrupt OUT complete. */
  79664. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  79665. + qtd->urb->actual_length += hc->xfer_len;
  79666. + if (qtd->urb->actual_length >= qtd->urb->length) {
  79667. + qtd->urb->status = 0;
  79668. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, qtd->urb->status);
  79669. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  79670. + } else {
  79671. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  79672. + }
  79673. + }
  79674. + } else {
  79675. + /* ISOC IN complete. */
  79676. + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  79677. + int len = 0;
  79678. + /* Record errors, update qtd. */
  79679. + if (st->nr_errors) {
  79680. + frame_desc->actual_length = 0;
  79681. + frame_desc->status = -DWC_E_PROTOCOL;
  79682. + } else {
  79683. + frame_desc->status = 0;
  79684. + /* Unswizzle dma */
  79685. + len = dwc_otg_fiq_unsetup_per_dma(hcd, qh, qtd, num);
  79686. + frame_desc->actual_length = len;
  79687. + }
  79688. + qtd->isoc_frame_index++;
  79689. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  79690. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  79691. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  79692. + } else {
  79693. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  79694. + }
  79695. + }
  79696. + break;
  79697. +
  79698. + case FIQ_PER_ISO_OUT_DONE: {
  79699. + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  79700. + /* Record errors, update qtd. */
  79701. + if (st->nr_errors) {
  79702. + frame_desc->actual_length = 0;
  79703. + frame_desc->status = -DWC_E_PROTOCOL;
  79704. + } else {
  79705. + frame_desc->status = 0;
  79706. + frame_desc->actual_length = frame_desc->length;
  79707. + }
  79708. + qtd->isoc_frame_index++;
  79709. + qtd->isoc_split_offset = 0;
  79710. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  79711. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  79712. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  79713. + } else {
  79714. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  79715. + }
  79716. + }
  79717. + break;
  79718. +
  79719. + case FIQ_PER_SPLIT_NYET_ABORTED:
  79720. + /* Doh. lost the data. */
  79721. + printk_ratelimited(KERN_INFO "Transfer to device %d endpoint 0x%x frame %d failed "
  79722. + "- FIQ reported NYET. Data may have been lost.\n",
  79723. + hc->dev_addr, hc->ep_num, dwc_otg_hcd_get_frame_number(hcd) >> 3);
  79724. + if (hc->ep_type == UE_ISOCHRONOUS) {
  79725. + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  79726. + /* Record errors, update qtd. */
  79727. + frame_desc->actual_length = 0;
  79728. + frame_desc->status = -DWC_E_PROTOCOL;
  79729. + qtd->isoc_frame_index++;
  79730. + qtd->isoc_split_offset = 0;
  79731. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  79732. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  79733. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  79734. + } else {
  79735. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  79736. + }
  79737. + } else {
  79738. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  79739. + }
  79740. + break;
  79741. +
  79742. + case FIQ_HS_ISOC_DONE:
  79743. + /* The FIQ has performed a whole pile of isochronous transactions.
  79744. + * The status is recorded as the interrupt state should the transaction
  79745. + * fail.
  79746. + */
  79747. + dwc_otg_fiq_unmangle_isoc(hcd, qh, qtd, num);
  79748. + break;
  79749. +
  79750. + case FIQ_PER_SPLIT_LS_ABORTED:
  79751. + if (hcint.b.xacterr) {
  79752. + /* Hub has responded with an ERR packet. Device
  79753. + * has been unplugged or the port has been disabled.
  79754. + * TODO: need to issue a reset to the hub port. */
  79755. + qtd->error_count += 3;
  79756. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  79757. + } else if (hcint.b.stall) {
  79758. + handle_hc_stall_intr(hcd, hc, hc_regs, qtd);
  79759. + } else {
  79760. + printk_ratelimited(KERN_INFO "Transfer to device %d endpoint 0x%x failed "
  79761. + "- FIQ reported FSM=%d. Data may have been lost.\n",
  79762. + st->fsm, hc->dev_addr, hc->ep_num);
  79763. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  79764. + }
  79765. + break;
  79766. +
  79767. + case FIQ_PER_SPLIT_HS_ABORTED:
  79768. + /* Either the SSPLIT phase suffered transaction errors or something
  79769. + * unexpected happened.
  79770. + */
  79771. + qtd->error_count += 3;
  79772. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  79773. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  79774. + break;
  79775. +
  79776. + case FIQ_PER_SPLIT_TIMEOUT:
  79777. + /* Couldn't complete in the nominated frame */
  79778. + printk(KERN_INFO "Transfer to device %d endpoint 0x%x frame %d failed "
  79779. + "- FIQ timed out. Data may have been lost.\n",
  79780. + hc->dev_addr, hc->ep_num, dwc_otg_hcd_get_frame_number(hcd) >> 3);
  79781. + if (hc->ep_type == UE_ISOCHRONOUS) {
  79782. + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  79783. + /* Record errors, update qtd. */
  79784. + frame_desc->actual_length = 0;
  79785. + if (hc->ep_is_in) {
  79786. + frame_desc->status = -DWC_E_NO_STREAM_RES;
  79787. + } else {
  79788. + frame_desc->status = -DWC_E_COMMUNICATION;
  79789. + }
  79790. + qtd->isoc_frame_index++;
  79791. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  79792. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  79793. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  79794. + } else {
  79795. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  79796. + }
  79797. + } else {
  79798. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  79799. + }
  79800. + break;
  79801. +
  79802. + default:
  79803. + local_fiq_disable();
  79804. + DWC_WARN("unexpected state received on hc=%d fsm=%d", hc->hc_num, st->fsm);
  79805. + BUG();
  79806. + }
  79807. + //if (hostchannels != hcd->available_host_channels) {
  79808. + /* should have incremented by now! */
  79809. + // BUG();
  79810. +// }
  79811. + return ret;
  79812. +}
  79813. +
  79814. +/** Handles interrupt for a specific Host Channel */
  79815. +int32_t dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd_t * dwc_otg_hcd, uint32_t num)
  79816. +{
  79817. + int retval = 0;
  79818. + hcint_data_t hcint;
  79819. + hcintmsk_data_t hcintmsk;
  79820. + dwc_hc_t *hc;
  79821. + dwc_otg_hc_regs_t *hc_regs;
  79822. + dwc_otg_qtd_t *qtd;
  79823. +
  79824. + DWC_DEBUGPL(DBG_HCDV, "--Host Channel Interrupt--, Channel %d\n", num);
  79825. +
  79826. + hc = dwc_otg_hcd->hc_ptr_array[num];
  79827. + hc_regs = dwc_otg_hcd->core_if->host_if->hc_regs[num];
  79828. + if(hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  79829. + /* We are responding to a channel disable. Driver
  79830. + * state is cleared - our qtd has gone away.
  79831. + */
  79832. + release_channel(dwc_otg_hcd, hc, NULL, hc->halt_status);
  79833. + return 1;
  79834. + }
  79835. + qtd = DWC_CIRCLEQ_FIRST(&hc->qh->qtd_list);
  79836. +
  79837. + /*
  79838. + * FSM mode: Check to see if this is a HC interrupt from a channel handled by the FIQ.
  79839. + * Execution path is fundamentally different for the channels after a FIQ has completed
  79840. + * a split transaction.
  79841. + */
  79842. + if (fiq_fsm_enable) {
  79843. + switch (dwc_otg_hcd->fiq_state->channel[num].fsm) {
  79844. + case FIQ_PASSTHROUGH:
  79845. + break;
  79846. + case FIQ_PASSTHROUGH_ERRORSTATE:
  79847. + /* Hook into the error count */
  79848. + fiq_print(FIQDBG_ERR, dwc_otg_hcd->fiq_state, "HCDERR%02d", num);
  79849. + if (dwc_otg_hcd->fiq_state->channel[num].nr_errors) {
  79850. + qtd->error_count = 0;
  79851. + fiq_print(FIQDBG_ERR, dwc_otg_hcd->fiq_state, "RESET ");
  79852. + }
  79853. + break;
  79854. + default:
  79855. + dwc_otg_hcd_handle_hc_fsm(dwc_otg_hcd, num);
  79856. + return 1;
  79857. + }
  79858. + }
  79859. +
  79860. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  79861. + hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
  79862. + hcint.d32 = hcint.d32 & hcintmsk.d32;
  79863. + if (!dwc_otg_hcd->core_if->dma_enable) {
  79864. + if (hcint.b.chhltd && hcint.d32 != 0x2) {
  79865. + hcint.b.chhltd = 0;
  79866. + }
  79867. + }
  79868. +
  79869. + if (hcint.b.xfercomp) {
  79870. + retval |=
  79871. + handle_hc_xfercomp_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  79872. + /*
  79873. + * If NYET occurred at same time as Xfer Complete, the NYET is
  79874. + * handled by the Xfer Complete interrupt handler. Don't want
  79875. + * to call the NYET interrupt handler in this case.
  79876. + */
  79877. + hcint.b.nyet = 0;
  79878. + }
  79879. + if (hcint.b.chhltd) {
  79880. + retval |= handle_hc_chhltd_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  79881. + }
  79882. + if (hcint.b.ahberr) {
  79883. + retval |= handle_hc_ahberr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  79884. + }
  79885. + if (hcint.b.stall) {
  79886. + retval |= handle_hc_stall_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  79887. + }
  79888. + if (hcint.b.nak) {
  79889. + retval |= handle_hc_nak_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  79890. + }
  79891. + if (hcint.b.ack) {
  79892. + if(!hcint.b.chhltd)
  79893. + retval |= handle_hc_ack_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  79894. + }
  79895. + if (hcint.b.nyet) {
  79896. + retval |= handle_hc_nyet_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  79897. + }
  79898. + if (hcint.b.xacterr) {
  79899. + retval |= handle_hc_xacterr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  79900. + }
  79901. + if (hcint.b.bblerr) {
  79902. + retval |= handle_hc_babble_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  79903. + }
  79904. + if (hcint.b.frmovrun) {
  79905. + retval |=
  79906. + handle_hc_frmovrun_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  79907. + }
  79908. + if (hcint.b.datatglerr) {
  79909. + retval |=
  79910. + handle_hc_datatglerr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  79911. + }
  79912. +
  79913. + return retval;
  79914. +}
  79915. +#endif /* DWC_DEVICE_ONLY */
  79916. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c
  79917. --- linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c 1970-01-01 01:00:00.000000000 +0100
  79918. +++ linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c 2014-08-06 16:50:14.845965072 +0200
  79919. @@ -0,0 +1,985 @@
  79920. +
  79921. +/* ==========================================================================
  79922. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_linux.c $
  79923. + * $Revision: #20 $
  79924. + * $Date: 2011/10/26 $
  79925. + * $Change: 1872981 $
  79926. + *
  79927. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  79928. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  79929. + * otherwise expressly agreed to in writing between Synopsys and you.
  79930. + *
  79931. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  79932. + * any End User Software License Agreement or Agreement for Licensed Product
  79933. + * with Synopsys or any supplement thereto. You are permitted to use and
  79934. + * redistribute this Software in source and binary forms, with or without
  79935. + * modification, provided that redistributions of source code must retain this
  79936. + * notice. You may not view, use, disclose, copy or distribute this file or
  79937. + * any information contained herein except pursuant to this license grant from
  79938. + * Synopsys. If you do not agree with this notice, including the disclaimer
  79939. + * below, then you are not authorized to use the Software.
  79940. + *
  79941. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  79942. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  79943. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  79944. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  79945. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  79946. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  79947. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  79948. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  79949. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  79950. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  79951. + * DAMAGE.
  79952. + * ========================================================================== */
  79953. +#ifndef DWC_DEVICE_ONLY
  79954. +
  79955. +/**
  79956. + * @file
  79957. + *
  79958. + * This file contains the implementation of the HCD. In Linux, the HCD
  79959. + * implements the hc_driver API.
  79960. + */
  79961. +#include <linux/kernel.h>
  79962. +#include <linux/module.h>
  79963. +#include <linux/moduleparam.h>
  79964. +#include <linux/init.h>
  79965. +#include <linux/device.h>
  79966. +#include <linux/errno.h>
  79967. +#include <linux/list.h>
  79968. +#include <linux/interrupt.h>
  79969. +#include <linux/string.h>
  79970. +#include <linux/dma-mapping.h>
  79971. +#include <linux/version.h>
  79972. +#include <asm/io.h>
  79973. +#include <asm/fiq.h>
  79974. +#include <linux/usb.h>
  79975. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35)
  79976. +#include <../drivers/usb/core/hcd.h>
  79977. +#else
  79978. +#include <linux/usb/hcd.h>
  79979. +#endif
  79980. +#include <asm/bug.h>
  79981. +
  79982. +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30))
  79983. +#define USB_URB_EP_LINKING 1
  79984. +#else
  79985. +#define USB_URB_EP_LINKING 0
  79986. +#endif
  79987. +
  79988. +#include "dwc_otg_hcd_if.h"
  79989. +#include "dwc_otg_dbg.h"
  79990. +#include "dwc_otg_driver.h"
  79991. +#include "dwc_otg_hcd.h"
  79992. +
  79993. +extern unsigned char _dwc_otg_fiq_stub, _dwc_otg_fiq_stub_end;
  79994. +
  79995. +/**
  79996. + * Gets the endpoint number from a _bEndpointAddress argument. The endpoint is
  79997. + * qualified with its direction (possible 32 endpoints per device).
  79998. + */
  79999. +#define dwc_ep_addr_to_endpoint(_bEndpointAddress_) ((_bEndpointAddress_ & USB_ENDPOINT_NUMBER_MASK) | \
  80000. + ((_bEndpointAddress_ & USB_DIR_IN) != 0) << 4)
  80001. +
  80002. +static const char dwc_otg_hcd_name[] = "dwc_otg_hcd";
  80003. +
  80004. +extern bool fiq_enable;
  80005. +
  80006. +/** @name Linux HC Driver API Functions */
  80007. +/** @{ */
  80008. +/* manage i/o requests, device state */
  80009. +static int dwc_otg_urb_enqueue(struct usb_hcd *hcd,
  80010. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  80011. + struct usb_host_endpoint *ep,
  80012. +#endif
  80013. + struct urb *urb, gfp_t mem_flags);
  80014. +
  80015. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
  80016. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  80017. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd, struct urb *urb);
  80018. +#endif
  80019. +#else /* kernels at or post 2.6.30 */
  80020. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd,
  80021. + struct urb *urb, int status);
  80022. +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30) */
  80023. +
  80024. +static void endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *ep);
  80025. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  80026. +static void endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep);
  80027. +#endif
  80028. +static irqreturn_t dwc_otg_hcd_irq(struct usb_hcd *hcd);
  80029. +extern int hcd_start(struct usb_hcd *hcd);
  80030. +extern void hcd_stop(struct usb_hcd *hcd);
  80031. +static int get_frame_number(struct usb_hcd *hcd);
  80032. +extern int hub_status_data(struct usb_hcd *hcd, char *buf);
  80033. +extern int hub_control(struct usb_hcd *hcd,
  80034. + u16 typeReq,
  80035. + u16 wValue, u16 wIndex, char *buf, u16 wLength);
  80036. +
  80037. +struct wrapper_priv_data {
  80038. + dwc_otg_hcd_t *dwc_otg_hcd;
  80039. +};
  80040. +
  80041. +/** @} */
  80042. +
  80043. +static struct hc_driver dwc_otg_hc_driver = {
  80044. +
  80045. + .description = dwc_otg_hcd_name,
  80046. + .product_desc = "DWC OTG Controller",
  80047. + .hcd_priv_size = sizeof(struct wrapper_priv_data),
  80048. +
  80049. + .irq = dwc_otg_hcd_irq,
  80050. +
  80051. + .flags = HCD_MEMORY | HCD_USB2,
  80052. +
  80053. + //.reset =
  80054. + .start = hcd_start,
  80055. + //.suspend =
  80056. + //.resume =
  80057. + .stop = hcd_stop,
  80058. +
  80059. + .urb_enqueue = dwc_otg_urb_enqueue,
  80060. + .urb_dequeue = dwc_otg_urb_dequeue,
  80061. + .endpoint_disable = endpoint_disable,
  80062. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  80063. + .endpoint_reset = endpoint_reset,
  80064. +#endif
  80065. + .get_frame_number = get_frame_number,
  80066. +
  80067. + .hub_status_data = hub_status_data,
  80068. + .hub_control = hub_control,
  80069. + //.bus_suspend =
  80070. + //.bus_resume =
  80071. +};
  80072. +
  80073. +/** Gets the dwc_otg_hcd from a struct usb_hcd */
  80074. +static inline dwc_otg_hcd_t *hcd_to_dwc_otg_hcd(struct usb_hcd *hcd)
  80075. +{
  80076. + struct wrapper_priv_data *p;
  80077. + p = (struct wrapper_priv_data *)(hcd->hcd_priv);
  80078. + return p->dwc_otg_hcd;
  80079. +}
  80080. +
  80081. +/** Gets the struct usb_hcd that contains a dwc_otg_hcd_t. */
  80082. +static inline struct usb_hcd *dwc_otg_hcd_to_hcd(dwc_otg_hcd_t * dwc_otg_hcd)
  80083. +{
  80084. + return dwc_otg_hcd_get_priv_data(dwc_otg_hcd);
  80085. +}
  80086. +
  80087. +/** Gets the usb_host_endpoint associated with an URB. */
  80088. +inline struct usb_host_endpoint *dwc_urb_to_endpoint(struct urb *urb)
  80089. +{
  80090. + struct usb_device *dev = urb->dev;
  80091. + int ep_num = usb_pipeendpoint(urb->pipe);
  80092. +
  80093. + if (usb_pipein(urb->pipe))
  80094. + return dev->ep_in[ep_num];
  80095. + else
  80096. + return dev->ep_out[ep_num];
  80097. +}
  80098. +
  80099. +static int _disconnect(dwc_otg_hcd_t * hcd)
  80100. +{
  80101. + struct usb_hcd *usb_hcd = dwc_otg_hcd_to_hcd(hcd);
  80102. +
  80103. + usb_hcd->self.is_b_host = 0;
  80104. + return 0;
  80105. +}
  80106. +
  80107. +static int _start(dwc_otg_hcd_t * hcd)
  80108. +{
  80109. + struct usb_hcd *usb_hcd = dwc_otg_hcd_to_hcd(hcd);
  80110. +
  80111. + usb_hcd->self.is_b_host = dwc_otg_hcd_is_b_host(hcd);
  80112. + hcd_start(usb_hcd);
  80113. +
  80114. + return 0;
  80115. +}
  80116. +
  80117. +static int _hub_info(dwc_otg_hcd_t * hcd, void *urb_handle, uint32_t * hub_addr,
  80118. + uint32_t * port_addr)
  80119. +{
  80120. + struct urb *urb = (struct urb *)urb_handle;
  80121. + struct usb_bus *bus;
  80122. +#if 1 //GRAYG - temporary
  80123. + if (NULL == urb_handle)
  80124. + DWC_ERROR("**** %s - NULL URB handle\n", __func__);//GRAYG
  80125. + if (NULL == urb->dev)
  80126. + DWC_ERROR("**** %s - URB has no device\n", __func__);//GRAYG
  80127. + if (NULL == port_addr)
  80128. + DWC_ERROR("**** %s - NULL port_address\n", __func__);//GRAYG
  80129. +#endif
  80130. + if (urb->dev->tt) {
  80131. + if (NULL == urb->dev->tt->hub) {
  80132. + DWC_ERROR("**** %s - (URB's transactor has no TT - giving no hub)\n",
  80133. + __func__); //GRAYG
  80134. + //*hub_addr = (u8)usb_pipedevice(urb->pipe); //GRAYG
  80135. + *hub_addr = 0; //GRAYG
  80136. + // we probably shouldn't have a transaction translator if
  80137. + // there's no associated hub?
  80138. + } else {
  80139. + bus = hcd_to_bus(dwc_otg_hcd_to_hcd(hcd));
  80140. + if (urb->dev->tt->hub == bus->root_hub)
  80141. + *hub_addr = 0;
  80142. + else
  80143. + *hub_addr = urb->dev->tt->hub->devnum;
  80144. + }
  80145. + *port_addr = urb->dev->tt->multi ? urb->dev->ttport : 1;
  80146. + } else {
  80147. + *hub_addr = 0;
  80148. + *port_addr = urb->dev->ttport;
  80149. + }
  80150. + return 0;
  80151. +}
  80152. +
  80153. +static int _speed(dwc_otg_hcd_t * hcd, void *urb_handle)
  80154. +{
  80155. + struct urb *urb = (struct urb *)urb_handle;
  80156. + return urb->dev->speed;
  80157. +}
  80158. +
  80159. +static int _get_b_hnp_enable(dwc_otg_hcd_t * hcd)
  80160. +{
  80161. + struct usb_hcd *usb_hcd = dwc_otg_hcd_to_hcd(hcd);
  80162. + return usb_hcd->self.b_hnp_enable;
  80163. +}
  80164. +
  80165. +static void allocate_bus_bandwidth(struct usb_hcd *hcd, uint32_t bw,
  80166. + struct urb *urb)
  80167. +{
  80168. + hcd_to_bus(hcd)->bandwidth_allocated += bw / urb->interval;
  80169. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  80170. + hcd_to_bus(hcd)->bandwidth_isoc_reqs++;
  80171. + } else {
  80172. + hcd_to_bus(hcd)->bandwidth_int_reqs++;
  80173. + }
  80174. +}
  80175. +
  80176. +static void free_bus_bandwidth(struct usb_hcd *hcd, uint32_t bw,
  80177. + struct urb *urb)
  80178. +{
  80179. + hcd_to_bus(hcd)->bandwidth_allocated -= bw / urb->interval;
  80180. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  80181. + hcd_to_bus(hcd)->bandwidth_isoc_reqs--;
  80182. + } else {
  80183. + hcd_to_bus(hcd)->bandwidth_int_reqs--;
  80184. + }
  80185. +}
  80186. +
  80187. +/**
  80188. + * Sets the final status of an URB and returns it to the device driver. Any
  80189. + * required cleanup of the URB is performed. The HCD lock should be held on
  80190. + * entry.
  80191. + */
  80192. +static int _complete(dwc_otg_hcd_t * hcd, void *urb_handle,
  80193. + dwc_otg_hcd_urb_t * dwc_otg_urb, int32_t status)
  80194. +{
  80195. + struct urb *urb = (struct urb *)urb_handle;
  80196. + urb_tq_entry_t *new_entry;
  80197. + int rc = 0;
  80198. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  80199. + DWC_PRINTF("%s: urb %p, device %d, ep %d %s, status=%d\n",
  80200. + __func__, urb, usb_pipedevice(urb->pipe),
  80201. + usb_pipeendpoint(urb->pipe),
  80202. + usb_pipein(urb->pipe) ? "IN" : "OUT", status);
  80203. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  80204. + int i;
  80205. + for (i = 0; i < urb->number_of_packets; i++) {
  80206. + DWC_PRINTF(" ISO Desc %d status: %d\n",
  80207. + i, urb->iso_frame_desc[i].status);
  80208. + }
  80209. + }
  80210. + }
  80211. + new_entry = DWC_ALLOC_ATOMIC(sizeof(urb_tq_entry_t));
  80212. + urb->actual_length = dwc_otg_hcd_urb_get_actual_length(dwc_otg_urb);
  80213. + /* Convert status value. */
  80214. + switch (status) {
  80215. + case -DWC_E_PROTOCOL:
  80216. + status = -EPROTO;
  80217. + break;
  80218. + case -DWC_E_IN_PROGRESS:
  80219. + status = -EINPROGRESS;
  80220. + break;
  80221. + case -DWC_E_PIPE:
  80222. + status = -EPIPE;
  80223. + break;
  80224. + case -DWC_E_IO:
  80225. + status = -EIO;
  80226. + break;
  80227. + case -DWC_E_TIMEOUT:
  80228. + status = -ETIMEDOUT;
  80229. + break;
  80230. + case -DWC_E_OVERFLOW:
  80231. + status = -EOVERFLOW;
  80232. + break;
  80233. + case -DWC_E_SHUTDOWN:
  80234. + status = -ESHUTDOWN;
  80235. + break;
  80236. + default:
  80237. + if (status) {
  80238. + DWC_PRINTF("Uknown urb status %d\n", status);
  80239. +
  80240. + }
  80241. + }
  80242. +
  80243. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  80244. + int i;
  80245. +
  80246. + urb->error_count = dwc_otg_hcd_urb_get_error_count(dwc_otg_urb);
  80247. + for (i = 0; i < urb->number_of_packets; ++i) {
  80248. + urb->iso_frame_desc[i].actual_length =
  80249. + dwc_otg_hcd_urb_get_iso_desc_actual_length
  80250. + (dwc_otg_urb, i);
  80251. + urb->iso_frame_desc[i].status =
  80252. + dwc_otg_hcd_urb_get_iso_desc_status(dwc_otg_urb, i);
  80253. + }
  80254. + }
  80255. +
  80256. + urb->status = status;
  80257. + urb->hcpriv = NULL;
  80258. + if (!status) {
  80259. + if ((urb->transfer_flags & URB_SHORT_NOT_OK) &&
  80260. + (urb->actual_length < urb->transfer_buffer_length)) {
  80261. + urb->status = -EREMOTEIO;
  80262. + }
  80263. + }
  80264. +
  80265. + if ((usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) ||
  80266. + (usb_pipetype(urb->pipe) == PIPE_INTERRUPT)) {
  80267. + struct usb_host_endpoint *ep = dwc_urb_to_endpoint(urb);
  80268. + if (ep) {
  80269. + free_bus_bandwidth(dwc_otg_hcd_to_hcd(hcd),
  80270. + dwc_otg_hcd_get_ep_bandwidth(hcd,
  80271. + ep->hcpriv),
  80272. + urb);
  80273. + }
  80274. + }
  80275. + DWC_FREE(dwc_otg_urb);
  80276. + if (!new_entry) {
  80277. + DWC_ERROR("dwc_otg_hcd: complete: cannot allocate URB TQ entry\n");
  80278. + urb->status = -EPROTO;
  80279. + /* don't schedule the tasklet -
  80280. + * directly return the packet here with error. */
  80281. +#if USB_URB_EP_LINKING
  80282. + usb_hcd_unlink_urb_from_ep(dwc_otg_hcd_to_hcd(hcd), urb);
  80283. +#endif
  80284. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  80285. + usb_hcd_giveback_urb(dwc_otg_hcd_to_hcd(hcd), urb);
  80286. +#else
  80287. + usb_hcd_giveback_urb(dwc_otg_hcd_to_hcd(hcd), urb, urb->status);
  80288. +#endif
  80289. + } else {
  80290. + new_entry->urb = urb;
  80291. +#if USB_URB_EP_LINKING
  80292. + rc = usb_hcd_check_unlink_urb(dwc_otg_hcd_to_hcd(hcd), urb, urb->status);
  80293. + if(0 == rc) {
  80294. + usb_hcd_unlink_urb_from_ep(dwc_otg_hcd_to_hcd(hcd), urb);
  80295. + }
  80296. +#endif
  80297. + if(0 == rc) {
  80298. + DWC_TAILQ_INSERT_TAIL(&hcd->completed_urb_list, new_entry,
  80299. + urb_tq_entries);
  80300. + DWC_TASK_HI_SCHEDULE(hcd->completion_tasklet);
  80301. + }
  80302. + }
  80303. + return 0;
  80304. +}
  80305. +
  80306. +static struct dwc_otg_hcd_function_ops hcd_fops = {
  80307. + .start = _start,
  80308. + .disconnect = _disconnect,
  80309. + .hub_info = _hub_info,
  80310. + .speed = _speed,
  80311. + .complete = _complete,
  80312. + .get_b_hnp_enable = _get_b_hnp_enable,
  80313. +};
  80314. +
  80315. +static struct fiq_handler fh = {
  80316. + .name = "usb_fiq",
  80317. +};
  80318. +
  80319. +
  80320. +
  80321. +/**
  80322. + * Initializes the HCD. This function allocates memory for and initializes the
  80323. + * static parts of the usb_hcd and dwc_otg_hcd structures. It also registers the
  80324. + * USB bus with the core and calls the hc_driver->start() function. It returns
  80325. + * a negative error on failure.
  80326. + */
  80327. +int hcd_init(dwc_bus_dev_t *_dev)
  80328. +{
  80329. + struct usb_hcd *hcd = NULL;
  80330. + dwc_otg_hcd_t *dwc_otg_hcd = NULL;
  80331. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  80332. + int retval = 0;
  80333. + u64 dmamask;
  80334. + struct pt_regs regs;
  80335. +
  80336. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD INIT otg_dev=%p\n", otg_dev);
  80337. +
  80338. + /* Set device flags indicating whether the HCD supports DMA. */
  80339. + if (dwc_otg_is_dma_enable(otg_dev->core_if))
  80340. + dmamask = DMA_BIT_MASK(32);
  80341. + else
  80342. + dmamask = 0;
  80343. +
  80344. +#if defined(LM_INTERFACE) || defined(PLATFORM_INTERFACE)
  80345. + dma_set_mask(&_dev->dev, dmamask);
  80346. + dma_set_coherent_mask(&_dev->dev, dmamask);
  80347. +#elif defined(PCI_INTERFACE)
  80348. + pci_set_dma_mask(_dev, dmamask);
  80349. + pci_set_consistent_dma_mask(_dev, dmamask);
  80350. +#endif
  80351. +
  80352. + /*
  80353. + * Allocate memory for the base HCD plus the DWC OTG HCD.
  80354. + * Initialize the base HCD.
  80355. + */
  80356. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
  80357. + hcd = usb_create_hcd(&dwc_otg_hc_driver, &_dev->dev, _dev->dev.bus_id);
  80358. +#else
  80359. + hcd = usb_create_hcd(&dwc_otg_hc_driver, &_dev->dev, dev_name(&_dev->dev));
  80360. + hcd->has_tt = 1;
  80361. +// hcd->uses_new_polling = 1;
  80362. +// hcd->poll_rh = 0;
  80363. +#endif
  80364. + if (!hcd) {
  80365. + retval = -ENOMEM;
  80366. + goto error1;
  80367. + }
  80368. +
  80369. + hcd->regs = otg_dev->os_dep.base;
  80370. +
  80371. +
  80372. + /* Initialize the DWC OTG HCD. */
  80373. + dwc_otg_hcd = dwc_otg_hcd_alloc_hcd();
  80374. + if (!dwc_otg_hcd) {
  80375. + goto error2;
  80376. + }
  80377. + ((struct wrapper_priv_data *)(hcd->hcd_priv))->dwc_otg_hcd =
  80378. + dwc_otg_hcd;
  80379. + otg_dev->hcd = dwc_otg_hcd;
  80380. +
  80381. + if (dwc_otg_hcd_init(dwc_otg_hcd, otg_dev->core_if)) {
  80382. + goto error2;
  80383. + }
  80384. +
  80385. + if (fiq_enable)
  80386. + {
  80387. + if (claim_fiq(&fh)) {
  80388. + DWC_ERROR("Can't claim FIQ");
  80389. + goto error2;
  80390. + }
  80391. +
  80392. + DWC_WARN("FIQ at 0x%08x", (fiq_fsm_enable ? (int)&dwc_otg_fiq_fsm : (int)&dwc_otg_fiq_nop));
  80393. + DWC_WARN("FIQ ASM at 0x%08x length %d", (int)&_dwc_otg_fiq_stub, (int)(&_dwc_otg_fiq_stub_end - &_dwc_otg_fiq_stub));
  80394. +
  80395. + set_fiq_handler((void *) &_dwc_otg_fiq_stub, &_dwc_otg_fiq_stub_end - &_dwc_otg_fiq_stub);
  80396. + memset(&regs,0,sizeof(regs));
  80397. +
  80398. + regs.ARM_r8 = (long) dwc_otg_hcd->fiq_state;
  80399. + if (fiq_fsm_enable) {
  80400. + regs.ARM_r9 = dwc_otg_hcd->core_if->core_params->host_channels;
  80401. + //regs.ARM_r10 = dwc_otg_hcd->dma;
  80402. + regs.ARM_fp = (long) dwc_otg_fiq_fsm;
  80403. + } else {
  80404. + regs.ARM_fp = (long) dwc_otg_fiq_nop;
  80405. + }
  80406. +
  80407. + regs.ARM_sp = (long) dwc_otg_hcd->fiq_stack + (sizeof(struct fiq_stack) - 4);
  80408. +
  80409. +// __show_regs(&regs);
  80410. + set_fiq_regs(&regs);
  80411. +
  80412. + //Set the mphi periph to the required registers
  80413. + dwc_otg_hcd->fiq_state->mphi_regs.base = otg_dev->os_dep.mphi_base;
  80414. + dwc_otg_hcd->fiq_state->mphi_regs.ctrl = otg_dev->os_dep.mphi_base + 0x4c;
  80415. + dwc_otg_hcd->fiq_state->mphi_regs.outdda = otg_dev->os_dep.mphi_base + 0x28;
  80416. + dwc_otg_hcd->fiq_state->mphi_regs.outddb = otg_dev->os_dep.mphi_base + 0x2c;
  80417. + dwc_otg_hcd->fiq_state->mphi_regs.intstat = otg_dev->os_dep.mphi_base + 0x50;
  80418. + dwc_otg_hcd->fiq_state->dwc_regs_base = otg_dev->os_dep.base;
  80419. + DWC_WARN("MPHI regs_base at 0x%08x", (int)dwc_otg_hcd->fiq_state->mphi_regs.base);
  80420. + //Enable mphi peripheral
  80421. + writel((1<<31),dwc_otg_hcd->fiq_state->mphi_regs.ctrl);
  80422. +#ifdef DEBUG
  80423. + if (readl(dwc_otg_hcd->fiq_state->mphi_regs.ctrl) & 0x80000000)
  80424. + DWC_WARN("MPHI periph has been enabled");
  80425. + else
  80426. + DWC_WARN("MPHI periph has NOT been enabled");
  80427. +#endif
  80428. + // Enable FIQ interrupt from USB peripheral
  80429. + enable_fiq(INTERRUPT_VC_USB);
  80430. + local_fiq_enable();
  80431. + }
  80432. +
  80433. +
  80434. + otg_dev->hcd->otg_dev = otg_dev;
  80435. + hcd->self.otg_port = dwc_otg_hcd_otg_port(dwc_otg_hcd);
  80436. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33) //don't support for LM(with 2.6.20.1 kernel)
  80437. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) //version field absent later
  80438. + hcd->self.otg_version = dwc_otg_get_otg_version(otg_dev->core_if);
  80439. +#endif
  80440. + /* Don't support SG list at this point */
  80441. + hcd->self.sg_tablesize = 0;
  80442. +#endif
  80443. + /*
  80444. + * Finish generic HCD initialization and start the HCD. This function
  80445. + * allocates the DMA buffer pool, registers the USB bus, requests the
  80446. + * IRQ line, and calls hcd_start method.
  80447. + */
  80448. +#ifdef PLATFORM_INTERFACE
  80449. + retval = usb_add_hcd(hcd, platform_get_irq(_dev, 0), IRQF_SHARED | IRQF_DISABLED);
  80450. +#else
  80451. + retval = usb_add_hcd(hcd, _dev->irq, IRQF_SHARED | IRQF_DISABLED);
  80452. +#endif
  80453. + if (retval < 0) {
  80454. + goto error2;
  80455. + }
  80456. +
  80457. + dwc_otg_hcd_set_priv_data(dwc_otg_hcd, hcd);
  80458. + return 0;
  80459. +
  80460. +error2:
  80461. + usb_put_hcd(hcd);
  80462. +error1:
  80463. + return retval;
  80464. +}
  80465. +
  80466. +/**
  80467. + * Removes the HCD.
  80468. + * Frees memory and resources associated with the HCD and deregisters the bus.
  80469. + */
  80470. +void hcd_remove(dwc_bus_dev_t *_dev)
  80471. +{
  80472. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  80473. + dwc_otg_hcd_t *dwc_otg_hcd;
  80474. + struct usb_hcd *hcd;
  80475. +
  80476. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD REMOVE otg_dev=%p\n", otg_dev);
  80477. +
  80478. + if (!otg_dev) {
  80479. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev NULL!\n", __func__);
  80480. + return;
  80481. + }
  80482. +
  80483. + dwc_otg_hcd = otg_dev->hcd;
  80484. +
  80485. + if (!dwc_otg_hcd) {
  80486. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->hcd NULL!\n", __func__);
  80487. + return;
  80488. + }
  80489. +
  80490. + hcd = dwc_otg_hcd_to_hcd(dwc_otg_hcd);
  80491. +
  80492. + if (!hcd) {
  80493. + DWC_DEBUGPL(DBG_ANY,
  80494. + "%s: dwc_otg_hcd_to_hcd(dwc_otg_hcd) NULL!\n",
  80495. + __func__);
  80496. + return;
  80497. + }
  80498. + usb_remove_hcd(hcd);
  80499. + dwc_otg_hcd_set_priv_data(dwc_otg_hcd, NULL);
  80500. + dwc_otg_hcd_remove(dwc_otg_hcd);
  80501. + usb_put_hcd(hcd);
  80502. +}
  80503. +
  80504. +/* =========================================================================
  80505. + * Linux HC Driver Functions
  80506. + * ========================================================================= */
  80507. +
  80508. +/** Initializes the DWC_otg controller and its root hub and prepares it for host
  80509. + * mode operation. Activates the root port. Returns 0 on success and a negative
  80510. + * error code on failure. */
  80511. +int hcd_start(struct usb_hcd *hcd)
  80512. +{
  80513. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  80514. + struct usb_bus *bus;
  80515. +
  80516. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD START\n");
  80517. + bus = hcd_to_bus(hcd);
  80518. +
  80519. + hcd->state = HC_STATE_RUNNING;
  80520. + if (dwc_otg_hcd_start(dwc_otg_hcd, &hcd_fops)) {
  80521. + return 0;
  80522. + }
  80523. +
  80524. + /* Initialize and connect root hub if one is not already attached */
  80525. + if (bus->root_hub) {
  80526. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Has Root Hub\n");
  80527. + /* Inform the HUB driver to resume. */
  80528. + usb_hcd_resume_root_hub(hcd);
  80529. + }
  80530. +
  80531. + return 0;
  80532. +}
  80533. +
  80534. +/**
  80535. + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
  80536. + * stopped.
  80537. + */
  80538. +void hcd_stop(struct usb_hcd *hcd)
  80539. +{
  80540. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  80541. +
  80542. + dwc_otg_hcd_stop(dwc_otg_hcd);
  80543. +}
  80544. +
  80545. +/** Returns the current frame number. */
  80546. +static int get_frame_number(struct usb_hcd *hcd)
  80547. +{
  80548. + hprt0_data_t hprt0;
  80549. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  80550. + hprt0.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  80551. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED)
  80552. + return dwc_otg_hcd_get_frame_number(dwc_otg_hcd) >> 3;
  80553. + else
  80554. + return dwc_otg_hcd_get_frame_number(dwc_otg_hcd);
  80555. +}
  80556. +
  80557. +#ifdef DEBUG
  80558. +static void dump_urb_info(struct urb *urb, char *fn_name)
  80559. +{
  80560. + DWC_PRINTF("%s, urb %p\n", fn_name, urb);
  80561. + DWC_PRINTF(" Device address: %d\n", usb_pipedevice(urb->pipe));
  80562. + DWC_PRINTF(" Endpoint: %d, %s\n", usb_pipeendpoint(urb->pipe),
  80563. + (usb_pipein(urb->pipe) ? "IN" : "OUT"));
  80564. + DWC_PRINTF(" Endpoint type: %s\n", ( {
  80565. + char *pipetype;
  80566. + switch (usb_pipetype(urb->pipe)) {
  80567. +case PIPE_CONTROL:
  80568. +pipetype = "CONTROL"; break; case PIPE_BULK:
  80569. +pipetype = "BULK"; break; case PIPE_INTERRUPT:
  80570. +pipetype = "INTERRUPT"; break; case PIPE_ISOCHRONOUS:
  80571. +pipetype = "ISOCHRONOUS"; break; default:
  80572. + pipetype = "UNKNOWN"; break;};
  80573. + pipetype;}
  80574. + )) ;
  80575. + DWC_PRINTF(" Speed: %s\n", ( {
  80576. + char *speed; switch (urb->dev->speed) {
  80577. +case USB_SPEED_HIGH:
  80578. +speed = "HIGH"; break; case USB_SPEED_FULL:
  80579. +speed = "FULL"; break; case USB_SPEED_LOW:
  80580. +speed = "LOW"; break; default:
  80581. + speed = "UNKNOWN"; break;};
  80582. + speed;}
  80583. + )) ;
  80584. + DWC_PRINTF(" Max packet size: %d\n",
  80585. + usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)));
  80586. + DWC_PRINTF(" Data buffer length: %d\n", urb->transfer_buffer_length);
  80587. + DWC_PRINTF(" Transfer buffer: %p, Transfer DMA: %p\n",
  80588. + urb->transfer_buffer, (void *)urb->transfer_dma);
  80589. + DWC_PRINTF(" Setup buffer: %p, Setup DMA: %p\n",
  80590. + urb->setup_packet, (void *)urb->setup_dma);
  80591. + DWC_PRINTF(" Interval: %d\n", urb->interval);
  80592. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  80593. + int i;
  80594. + for (i = 0; i < urb->number_of_packets; i++) {
  80595. + DWC_PRINTF(" ISO Desc %d:\n", i);
  80596. + DWC_PRINTF(" offset: %d, length %d\n",
  80597. + urb->iso_frame_desc[i].offset,
  80598. + urb->iso_frame_desc[i].length);
  80599. + }
  80600. + }
  80601. +}
  80602. +#endif
  80603. +
  80604. +/** Starts processing a USB transfer request specified by a USB Request Block
  80605. + * (URB). mem_flags indicates the type of memory allocation to use while
  80606. + * processing this URB. */
  80607. +static int dwc_otg_urb_enqueue(struct usb_hcd *hcd,
  80608. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  80609. + struct usb_host_endpoint *ep,
  80610. +#endif
  80611. + struct urb *urb, gfp_t mem_flags)
  80612. +{
  80613. + int retval = 0;
  80614. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)
  80615. + struct usb_host_endpoint *ep = urb->ep;
  80616. +#endif
  80617. + dwc_irqflags_t irqflags;
  80618. + void **ref_ep_hcpriv = &ep->hcpriv;
  80619. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  80620. + dwc_otg_hcd_urb_t *dwc_otg_urb;
  80621. + int i;
  80622. + int alloc_bandwidth = 0;
  80623. + uint8_t ep_type = 0;
  80624. + uint32_t flags = 0;
  80625. + void *buf;
  80626. +
  80627. +#ifdef DEBUG
  80628. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  80629. + dump_urb_info(urb, "dwc_otg_urb_enqueue");
  80630. + }
  80631. +#endif
  80632. +
  80633. + if (!urb->transfer_buffer && urb->transfer_buffer_length)
  80634. + return -EINVAL;
  80635. +
  80636. + if ((usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS)
  80637. + || (usb_pipetype(urb->pipe) == PIPE_INTERRUPT)) {
  80638. + if (!dwc_otg_hcd_is_bandwidth_allocated
  80639. + (dwc_otg_hcd, ref_ep_hcpriv)) {
  80640. + alloc_bandwidth = 1;
  80641. + }
  80642. + }
  80643. +
  80644. + switch (usb_pipetype(urb->pipe)) {
  80645. + case PIPE_CONTROL:
  80646. + ep_type = USB_ENDPOINT_XFER_CONTROL;
  80647. + break;
  80648. + case PIPE_ISOCHRONOUS:
  80649. + ep_type = USB_ENDPOINT_XFER_ISOC;
  80650. + break;
  80651. + case PIPE_BULK:
  80652. + ep_type = USB_ENDPOINT_XFER_BULK;
  80653. + break;
  80654. + case PIPE_INTERRUPT:
  80655. + ep_type = USB_ENDPOINT_XFER_INT;
  80656. + break;
  80657. + default:
  80658. + DWC_WARN("Wrong EP type - %d\n", usb_pipetype(urb->pipe));
  80659. + }
  80660. +
  80661. + /* # of packets is often 0 - do we really need to call this then? */
  80662. + dwc_otg_urb = dwc_otg_hcd_urb_alloc(dwc_otg_hcd,
  80663. + urb->number_of_packets,
  80664. + mem_flags == GFP_ATOMIC ? 1 : 0);
  80665. +
  80666. + if(dwc_otg_urb == NULL)
  80667. + return -ENOMEM;
  80668. +
  80669. + if (!dwc_otg_urb && urb->number_of_packets)
  80670. + return -ENOMEM;
  80671. +
  80672. + dwc_otg_hcd_urb_set_pipeinfo(dwc_otg_urb, usb_pipedevice(urb->pipe),
  80673. + usb_pipeendpoint(urb->pipe), ep_type,
  80674. + usb_pipein(urb->pipe),
  80675. + usb_maxpacket(urb->dev, urb->pipe,
  80676. + !(usb_pipein(urb->pipe))));
  80677. +
  80678. + buf = urb->transfer_buffer;
  80679. + if (hcd->self.uses_dma) {
  80680. + /*
  80681. + * Calculate virtual address from physical address,
  80682. + * because some class driver may not fill transfer_buffer.
  80683. + * In Buffer DMA mode virual address is used,
  80684. + * when handling non DWORD aligned buffers.
  80685. + */
  80686. + //buf = phys_to_virt(urb->transfer_dma);
  80687. + // DMA addresses are bus addresses not physical addresses!
  80688. + buf = dma_to_virt(&urb->dev->dev, urb->transfer_dma);
  80689. + }
  80690. +
  80691. + if (!(urb->transfer_flags & URB_NO_INTERRUPT))
  80692. + flags |= URB_GIVEBACK_ASAP;
  80693. + if (urb->transfer_flags & URB_ZERO_PACKET)
  80694. + flags |= URB_SEND_ZERO_PACKET;
  80695. +
  80696. + dwc_otg_hcd_urb_set_params(dwc_otg_urb, urb, buf,
  80697. + urb->transfer_dma,
  80698. + urb->transfer_buffer_length,
  80699. + urb->setup_packet,
  80700. + urb->setup_dma, flags, urb->interval);
  80701. +
  80702. + for (i = 0; i < urb->number_of_packets; ++i) {
  80703. + dwc_otg_hcd_urb_set_iso_desc_params(dwc_otg_urb, i,
  80704. + urb->
  80705. + iso_frame_desc[i].offset,
  80706. + urb->
  80707. + iso_frame_desc[i].length);
  80708. + }
  80709. +
  80710. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &irqflags);
  80711. + urb->hcpriv = dwc_otg_urb;
  80712. +#if USB_URB_EP_LINKING
  80713. + retval = usb_hcd_link_urb_to_ep(hcd, urb);
  80714. + if (0 == retval)
  80715. +#endif
  80716. + {
  80717. + retval = dwc_otg_hcd_urb_enqueue(dwc_otg_hcd, dwc_otg_urb,
  80718. + /*(dwc_otg_qh_t **)*/
  80719. + ref_ep_hcpriv, 1);
  80720. + if (0 == retval) {
  80721. + if (alloc_bandwidth) {
  80722. + allocate_bus_bandwidth(hcd,
  80723. + dwc_otg_hcd_get_ep_bandwidth(
  80724. + dwc_otg_hcd, *ref_ep_hcpriv),
  80725. + urb);
  80726. + }
  80727. + } else {
  80728. + DWC_DEBUGPL(DBG_HCD, "DWC OTG dwc_otg_hcd_urb_enqueue failed rc %d\n", retval);
  80729. +#if USB_URB_EP_LINKING
  80730. + usb_hcd_unlink_urb_from_ep(hcd, urb);
  80731. +#endif
  80732. + DWC_FREE(dwc_otg_urb);
  80733. + urb->hcpriv = NULL;
  80734. + if (retval == -DWC_E_NO_DEVICE)
  80735. + retval = -ENODEV;
  80736. + }
  80737. + }
  80738. +#if USB_URB_EP_LINKING
  80739. + else
  80740. + {
  80741. + DWC_FREE(dwc_otg_urb);
  80742. + urb->hcpriv = NULL;
  80743. + }
  80744. +#endif
  80745. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, irqflags);
  80746. + return retval;
  80747. +}
  80748. +
  80749. +/** Aborts/cancels a USB transfer request. Always returns 0 to indicate
  80750. + * success. */
  80751. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  80752. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
  80753. +#else
  80754. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
  80755. +#endif
  80756. +{
  80757. + dwc_irqflags_t flags;
  80758. + dwc_otg_hcd_t *dwc_otg_hcd;
  80759. + int rc;
  80760. +
  80761. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue\n");
  80762. +
  80763. + dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  80764. +
  80765. +#ifdef DEBUG
  80766. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  80767. + dump_urb_info(urb, "dwc_otg_urb_dequeue");
  80768. + }
  80769. +#endif
  80770. +
  80771. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  80772. + rc = usb_hcd_check_unlink_urb(hcd, urb, status);
  80773. + if (0 == rc) {
  80774. + if(urb->hcpriv != NULL) {
  80775. + dwc_otg_hcd_urb_dequeue(dwc_otg_hcd,
  80776. + (dwc_otg_hcd_urb_t *)urb->hcpriv);
  80777. +
  80778. + DWC_FREE(urb->hcpriv);
  80779. + urb->hcpriv = NULL;
  80780. + }
  80781. + }
  80782. +
  80783. + if (0 == rc) {
  80784. + /* Higher layer software sets URB status. */
  80785. +#if USB_URB_EP_LINKING
  80786. + usb_hcd_unlink_urb_from_ep(hcd, urb);
  80787. +#endif
  80788. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  80789. +
  80790. +
  80791. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  80792. + usb_hcd_giveback_urb(hcd, urb);
  80793. +#else
  80794. + usb_hcd_giveback_urb(hcd, urb, status);
  80795. +#endif
  80796. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  80797. + DWC_PRINTF("Called usb_hcd_giveback_urb() \n");
  80798. + DWC_PRINTF(" 1urb->status = %d\n", urb->status);
  80799. + }
  80800. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue OK\n");
  80801. + } else {
  80802. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  80803. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue failed - rc %d\n",
  80804. + rc);
  80805. + }
  80806. +
  80807. + return rc;
  80808. +}
  80809. +
  80810. +/* Frees resources in the DWC_otg controller related to a given endpoint. Also
  80811. + * clears state in the HCD related to the endpoint. Any URBs for the endpoint
  80812. + * must already be dequeued. */
  80813. +static void endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
  80814. +{
  80815. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  80816. +
  80817. + DWC_DEBUGPL(DBG_HCD,
  80818. + "DWC OTG HCD EP DISABLE: _bEndpointAddress=0x%02x, "
  80819. + "endpoint=%d\n", ep->desc.bEndpointAddress,
  80820. + dwc_ep_addr_to_endpoint(ep->desc.bEndpointAddress));
  80821. + dwc_otg_hcd_endpoint_disable(dwc_otg_hcd, ep->hcpriv, 250);
  80822. + ep->hcpriv = NULL;
  80823. +}
  80824. +
  80825. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  80826. +/* Resets endpoint specific parameter values, in current version used to reset
  80827. + * the data toggle(as a WA). This function can be called from usb_clear_halt routine */
  80828. +static void endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
  80829. +{
  80830. + dwc_irqflags_t flags;
  80831. + struct usb_device *udev = NULL;
  80832. + int epnum = usb_endpoint_num(&ep->desc);
  80833. + int is_out = usb_endpoint_dir_out(&ep->desc);
  80834. + int is_control = usb_endpoint_xfer_control(&ep->desc);
  80835. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  80836. + struct device *dev = DWC_OTG_OS_GETDEV(dwc_otg_hcd->otg_dev->os_dep);
  80837. +
  80838. + if (dev)
  80839. + udev = to_usb_device(dev);
  80840. + else
  80841. + return;
  80842. +
  80843. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD EP RESET: Endpoint Num=0x%02d\n", epnum);
  80844. +
  80845. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  80846. + usb_settoggle(udev, epnum, is_out, 0);
  80847. + if (is_control)
  80848. + usb_settoggle(udev, epnum, !is_out, 0);
  80849. +
  80850. + if (ep->hcpriv) {
  80851. + dwc_otg_hcd_endpoint_reset(dwc_otg_hcd, ep->hcpriv);
  80852. + }
  80853. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  80854. +}
  80855. +#endif
  80856. +
  80857. +/** Handles host mode interrupts for the DWC_otg controller. Returns IRQ_NONE if
  80858. + * there was no interrupt to handle. Returns IRQ_HANDLED if there was a valid
  80859. + * interrupt.
  80860. + *
  80861. + * This function is called by the USB core when an interrupt occurs */
  80862. +static irqreturn_t dwc_otg_hcd_irq(struct usb_hcd *hcd)
  80863. +{
  80864. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  80865. + int32_t retval = dwc_otg_hcd_handle_intr(dwc_otg_hcd);
  80866. + if (retval != 0) {
  80867. + S3C2410X_CLEAR_EINTPEND();
  80868. + }
  80869. + return IRQ_RETVAL(retval);
  80870. +}
  80871. +
  80872. +/** Creates Status Change bitmap for the root hub and root port. The bitmap is
  80873. + * returned in buf. Bit 0 is the status change indicator for the root hub. Bit 1
  80874. + * is the status change indicator for the single root port. Returns 1 if either
  80875. + * change indicator is 1, otherwise returns 0. */
  80876. +int hub_status_data(struct usb_hcd *hcd, char *buf)
  80877. +{
  80878. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  80879. +
  80880. + buf[0] = 0;
  80881. + buf[0] |= (dwc_otg_hcd_is_status_changed(dwc_otg_hcd, 1)) << 1;
  80882. +
  80883. + return (buf[0] != 0);
  80884. +}
  80885. +
  80886. +/** Handles hub class-specific requests. */
  80887. +int hub_control(struct usb_hcd *hcd,
  80888. + u16 typeReq, u16 wValue, u16 wIndex, char *buf, u16 wLength)
  80889. +{
  80890. + int retval;
  80891. +
  80892. + retval = dwc_otg_hcd_hub_control(hcd_to_dwc_otg_hcd(hcd),
  80893. + typeReq, wValue, wIndex, buf, wLength);
  80894. +
  80895. + switch (retval) {
  80896. + case -DWC_E_INVALID:
  80897. + retval = -EINVAL;
  80898. + break;
  80899. + }
  80900. +
  80901. + return retval;
  80902. +}
  80903. +
  80904. +#endif /* DWC_DEVICE_ONLY */
  80905. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c
  80906. --- linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c 1970-01-01 01:00:00.000000000 +0100
  80907. +++ linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c 2014-08-06 16:50:14.845965072 +0200
  80908. @@ -0,0 +1,942 @@
  80909. +/* ==========================================================================
  80910. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_queue.c $
  80911. + * $Revision: #44 $
  80912. + * $Date: 2011/10/26 $
  80913. + * $Change: 1873028 $
  80914. + *
  80915. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  80916. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  80917. + * otherwise expressly agreed to in writing between Synopsys and you.
  80918. + *
  80919. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  80920. + * any End User Software License Agreement or Agreement for Licensed Product
  80921. + * with Synopsys or any supplement thereto. You are permitted to use and
  80922. + * redistribute this Software in source and binary forms, with or without
  80923. + * modification, provided that redistributions of source code must retain this
  80924. + * notice. You may not view, use, disclose, copy or distribute this file or
  80925. + * any information contained herein except pursuant to this license grant from
  80926. + * Synopsys. If you do not agree with this notice, including the disclaimer
  80927. + * below, then you are not authorized to use the Software.
  80928. + *
  80929. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  80930. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  80931. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  80932. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  80933. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  80934. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  80935. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  80936. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  80937. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  80938. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  80939. + * DAMAGE.
  80940. + * ========================================================================== */
  80941. +#ifndef DWC_DEVICE_ONLY
  80942. +
  80943. +/**
  80944. + * @file
  80945. + *
  80946. + * This file contains the functions to manage Queue Heads and Queue
  80947. + * Transfer Descriptors.
  80948. + */
  80949. +
  80950. +#include "dwc_otg_hcd.h"
  80951. +#include "dwc_otg_regs.h"
  80952. +
  80953. +extern bool microframe_schedule;
  80954. +
  80955. +/**
  80956. + * Free each QTD in the QH's QTD-list then free the QH. QH should already be
  80957. + * removed from a list. QTD list should already be empty if called from URB
  80958. + * Dequeue.
  80959. + *
  80960. + * @param hcd HCD instance.
  80961. + * @param qh The QH to free.
  80962. + */
  80963. +void dwc_otg_hcd_qh_free(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  80964. +{
  80965. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  80966. +
  80967. + /* Free each QTD in the QTD list */
  80968. + DWC_SPINLOCK(hcd->lock);
  80969. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &qh->qtd_list, qtd_list_entry) {
  80970. + DWC_CIRCLEQ_REMOVE(&qh->qtd_list, qtd, qtd_list_entry);
  80971. + dwc_otg_hcd_qtd_free(qtd);
  80972. + }
  80973. +
  80974. + if (hcd->core_if->dma_desc_enable) {
  80975. + dwc_otg_hcd_qh_free_ddma(hcd, qh);
  80976. + } else if (qh->dw_align_buf) {
  80977. + uint32_t buf_size;
  80978. + if (qh->ep_type == UE_ISOCHRONOUS) {
  80979. + buf_size = 4096;
  80980. + } else {
  80981. + buf_size = hcd->core_if->core_params->max_transfer_size;
  80982. + }
  80983. + DWC_DMA_FREE(buf_size, qh->dw_align_buf, qh->dw_align_buf_dma);
  80984. + }
  80985. +
  80986. + DWC_FREE(qh);
  80987. + DWC_SPINUNLOCK(hcd->lock);
  80988. + return;
  80989. +}
  80990. +
  80991. +#define BitStuffTime(bytecount) ((8 * 7* bytecount) / 6)
  80992. +#define HS_HOST_DELAY 5 /* nanoseconds */
  80993. +#define FS_LS_HOST_DELAY 1000 /* nanoseconds */
  80994. +#define HUB_LS_SETUP 333 /* nanoseconds */
  80995. +#define NS_TO_US(ns) ((ns + 500) / 1000)
  80996. + /* convert & round nanoseconds to microseconds */
  80997. +
  80998. +static uint32_t calc_bus_time(int speed, int is_in, int is_isoc, int bytecount)
  80999. +{
  81000. + unsigned long retval;
  81001. +
  81002. + switch (speed) {
  81003. + case USB_SPEED_HIGH:
  81004. + if (is_isoc) {
  81005. + retval =
  81006. + ((38 * 8 * 2083) +
  81007. + (2083 * (3 + BitStuffTime(bytecount)))) / 1000 +
  81008. + HS_HOST_DELAY;
  81009. + } else {
  81010. + retval =
  81011. + ((55 * 8 * 2083) +
  81012. + (2083 * (3 + BitStuffTime(bytecount)))) / 1000 +
  81013. + HS_HOST_DELAY;
  81014. + }
  81015. + break;
  81016. + case USB_SPEED_FULL:
  81017. + if (is_isoc) {
  81018. + retval =
  81019. + (8354 * (31 + 10 * BitStuffTime(bytecount))) / 1000;
  81020. + if (is_in) {
  81021. + retval = 7268 + FS_LS_HOST_DELAY + retval;
  81022. + } else {
  81023. + retval = 6265 + FS_LS_HOST_DELAY + retval;
  81024. + }
  81025. + } else {
  81026. + retval =
  81027. + (8354 * (31 + 10 * BitStuffTime(bytecount))) / 1000;
  81028. + retval = 9107 + FS_LS_HOST_DELAY + retval;
  81029. + }
  81030. + break;
  81031. + case USB_SPEED_LOW:
  81032. + if (is_in) {
  81033. + retval =
  81034. + (67667 * (31 + 10 * BitStuffTime(bytecount))) /
  81035. + 1000;
  81036. + retval =
  81037. + 64060 + (2 * HUB_LS_SETUP) + FS_LS_HOST_DELAY +
  81038. + retval;
  81039. + } else {
  81040. + retval =
  81041. + (66700 * (31 + 10 * BitStuffTime(bytecount))) /
  81042. + 1000;
  81043. + retval =
  81044. + 64107 + (2 * HUB_LS_SETUP) + FS_LS_HOST_DELAY +
  81045. + retval;
  81046. + }
  81047. + break;
  81048. + default:
  81049. + DWC_WARN("Unknown device speed\n");
  81050. + retval = -1;
  81051. + }
  81052. +
  81053. + return NS_TO_US(retval);
  81054. +}
  81055. +
  81056. +/**
  81057. + * Initializes a QH structure.
  81058. + *
  81059. + * @param hcd The HCD state structure for the DWC OTG controller.
  81060. + * @param qh The QH to init.
  81061. + * @param urb Holds the information about the device/endpoint that we need
  81062. + * to initialize the QH.
  81063. + */
  81064. +#define SCHEDULE_SLOP 10
  81065. +void qh_init(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh, dwc_otg_hcd_urb_t * urb)
  81066. +{
  81067. + char *speed, *type;
  81068. + int dev_speed;
  81069. + uint32_t hub_addr, hub_port;
  81070. +
  81071. + dwc_memset(qh, 0, sizeof(dwc_otg_qh_t));
  81072. +
  81073. + /* Initialize QH */
  81074. + qh->ep_type = dwc_otg_hcd_get_pipe_type(&urb->pipe_info);
  81075. + qh->ep_is_in = dwc_otg_hcd_is_pipe_in(&urb->pipe_info) ? 1 : 0;
  81076. +
  81077. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  81078. + qh->maxp = dwc_otg_hcd_get_mps(&urb->pipe_info);
  81079. + DWC_CIRCLEQ_INIT(&qh->qtd_list);
  81080. + DWC_LIST_INIT(&qh->qh_list_entry);
  81081. + qh->channel = NULL;
  81082. +
  81083. + /* FS/LS Enpoint on HS Hub
  81084. + * NOT virtual root hub */
  81085. + dev_speed = hcd->fops->speed(hcd, urb->priv);
  81086. +
  81087. + hcd->fops->hub_info(hcd, urb->priv, &hub_addr, &hub_port);
  81088. + qh->do_split = 0;
  81089. + if (microframe_schedule)
  81090. + qh->speed = dev_speed;
  81091. +
  81092. + qh->nak_frame = 0xffff;
  81093. +
  81094. + if (((dev_speed == USB_SPEED_LOW) ||
  81095. + (dev_speed == USB_SPEED_FULL)) &&
  81096. + (hub_addr != 0 && hub_addr != 1)) {
  81097. + DWC_DEBUGPL(DBG_HCD,
  81098. + "QH init: EP %d: TT found at hub addr %d, for port %d\n",
  81099. + dwc_otg_hcd_get_ep_num(&urb->pipe_info), hub_addr,
  81100. + hub_port);
  81101. + qh->do_split = 1;
  81102. + qh->skip_count = 0;
  81103. + }
  81104. +
  81105. + if (qh->ep_type == UE_INTERRUPT || qh->ep_type == UE_ISOCHRONOUS) {
  81106. + /* Compute scheduling parameters once and save them. */
  81107. + hprt0_data_t hprt;
  81108. +
  81109. + /** @todo Account for split transfers in the bus time. */
  81110. + int bytecount =
  81111. + dwc_hb_mult(qh->maxp) * dwc_max_packet(qh->maxp);
  81112. +
  81113. + qh->usecs =
  81114. + calc_bus_time((qh->do_split ? USB_SPEED_HIGH : dev_speed),
  81115. + qh->ep_is_in, (qh->ep_type == UE_ISOCHRONOUS),
  81116. + bytecount);
  81117. + /* Start in a slightly future (micro)frame. */
  81118. + qh->sched_frame = dwc_frame_num_inc(hcd->frame_number,
  81119. + SCHEDULE_SLOP);
  81120. + qh->interval = urb->interval;
  81121. +
  81122. +#if 0
  81123. + /* Increase interrupt polling rate for debugging. */
  81124. + if (qh->ep_type == UE_INTERRUPT) {
  81125. + qh->interval = 8;
  81126. + }
  81127. +#endif
  81128. + hprt.d32 = DWC_READ_REG32(hcd->core_if->host_if->hprt0);
  81129. + if ((hprt.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED) &&
  81130. + ((dev_speed == USB_SPEED_LOW) ||
  81131. + (dev_speed == USB_SPEED_FULL))) {
  81132. + qh->interval *= 8;
  81133. + qh->sched_frame |= 0x7;
  81134. + qh->start_split_frame = qh->sched_frame;
  81135. + }
  81136. +
  81137. + }
  81138. +
  81139. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD QH Initialized\n");
  81140. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - qh = %p\n", qh);
  81141. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Device Address = %d\n",
  81142. + dwc_otg_hcd_get_dev_addr(&urb->pipe_info));
  81143. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Endpoint %d, %s\n",
  81144. + dwc_otg_hcd_get_ep_num(&urb->pipe_info),
  81145. + dwc_otg_hcd_is_pipe_in(&urb->pipe_info) ? "IN" : "OUT");
  81146. + switch (dev_speed) {
  81147. + case USB_SPEED_LOW:
  81148. + qh->dev_speed = DWC_OTG_EP_SPEED_LOW;
  81149. + speed = "low";
  81150. + break;
  81151. + case USB_SPEED_FULL:
  81152. + qh->dev_speed = DWC_OTG_EP_SPEED_FULL;
  81153. + speed = "full";
  81154. + break;
  81155. + case USB_SPEED_HIGH:
  81156. + qh->dev_speed = DWC_OTG_EP_SPEED_HIGH;
  81157. + speed = "high";
  81158. + break;
  81159. + default:
  81160. + speed = "?";
  81161. + break;
  81162. + }
  81163. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Speed = %s\n", speed);
  81164. +
  81165. + switch (qh->ep_type) {
  81166. + case UE_ISOCHRONOUS:
  81167. + type = "isochronous";
  81168. + break;
  81169. + case UE_INTERRUPT:
  81170. + type = "interrupt";
  81171. + break;
  81172. + case UE_CONTROL:
  81173. + type = "control";
  81174. + break;
  81175. + case UE_BULK:
  81176. + type = "bulk";
  81177. + break;
  81178. + default:
  81179. + type = "?";
  81180. + break;
  81181. + }
  81182. +
  81183. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Type = %s\n", type);
  81184. +
  81185. +#ifdef DEBUG
  81186. + if (qh->ep_type == UE_INTERRUPT) {
  81187. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - usecs = %d\n",
  81188. + qh->usecs);
  81189. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - interval = %d\n",
  81190. + qh->interval);
  81191. + }
  81192. +#endif
  81193. +
  81194. +}
  81195. +
  81196. +/**
  81197. + * This function allocates and initializes a QH.
  81198. + *
  81199. + * @param hcd The HCD state structure for the DWC OTG controller.
  81200. + * @param urb Holds the information about the device/endpoint that we need
  81201. + * to initialize the QH.
  81202. + * @param atomic_alloc Flag to do atomic allocation if needed
  81203. + *
  81204. + * @return Returns pointer to the newly allocated QH, or NULL on error. */
  81205. +dwc_otg_qh_t *dwc_otg_hcd_qh_create(dwc_otg_hcd_t * hcd,
  81206. + dwc_otg_hcd_urb_t * urb, int atomic_alloc)
  81207. +{
  81208. + dwc_otg_qh_t *qh;
  81209. +
  81210. + /* Allocate memory */
  81211. + /** @todo add memflags argument */
  81212. + qh = dwc_otg_hcd_qh_alloc(atomic_alloc);
  81213. + if (qh == NULL) {
  81214. + DWC_ERROR("qh allocation failed");
  81215. + return NULL;
  81216. + }
  81217. +
  81218. + qh_init(hcd, qh, urb);
  81219. +
  81220. + if (hcd->core_if->dma_desc_enable
  81221. + && (dwc_otg_hcd_qh_init_ddma(hcd, qh) < 0)) {
  81222. + dwc_otg_hcd_qh_free(hcd, qh);
  81223. + return NULL;
  81224. + }
  81225. +
  81226. + return qh;
  81227. +}
  81228. +
  81229. +/* microframe_schedule=0 start */
  81230. +
  81231. +/**
  81232. + * Checks that a channel is available for a periodic transfer.
  81233. + *
  81234. + * @return 0 if successful, negative error code otherise.
  81235. + */
  81236. +static int periodic_channel_available(dwc_otg_hcd_t * hcd)
  81237. +{
  81238. + /*
  81239. + * Currently assuming that there is a dedicated host channnel for each
  81240. + * periodic transaction plus at least one host channel for
  81241. + * non-periodic transactions.
  81242. + */
  81243. + int status;
  81244. + int num_channels;
  81245. +
  81246. + num_channels = hcd->core_if->core_params->host_channels;
  81247. + if ((hcd->periodic_channels + hcd->non_periodic_channels < num_channels)
  81248. + && (hcd->periodic_channels < num_channels - 1)) {
  81249. + status = 0;
  81250. + } else {
  81251. + DWC_INFO("%s: Total channels: %d, Periodic: %d, Non-periodic: %d\n",
  81252. + __func__, num_channels, hcd->periodic_channels, hcd->non_periodic_channels); //NOTICE
  81253. + status = -DWC_E_NO_SPACE;
  81254. + }
  81255. +
  81256. + return status;
  81257. +}
  81258. +
  81259. +/**
  81260. + * Checks that there is sufficient bandwidth for the specified QH in the
  81261. + * periodic schedule. For simplicity, this calculation assumes that all the
  81262. + * transfers in the periodic schedule may occur in the same (micro)frame.
  81263. + *
  81264. + * @param hcd The HCD state structure for the DWC OTG controller.
  81265. + * @param qh QH containing periodic bandwidth required.
  81266. + *
  81267. + * @return 0 if successful, negative error code otherwise.
  81268. + */
  81269. +static int check_periodic_bandwidth(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  81270. +{
  81271. + int status;
  81272. + int16_t max_claimed_usecs;
  81273. +
  81274. + status = 0;
  81275. +
  81276. + if ((qh->dev_speed == DWC_OTG_EP_SPEED_HIGH) || qh->do_split) {
  81277. + /*
  81278. + * High speed mode.
  81279. + * Max periodic usecs is 80% x 125 usec = 100 usec.
  81280. + */
  81281. +
  81282. + max_claimed_usecs = 100 - qh->usecs;
  81283. + } else {
  81284. + /*
  81285. + * Full speed mode.
  81286. + * Max periodic usecs is 90% x 1000 usec = 900 usec.
  81287. + */
  81288. + max_claimed_usecs = 900 - qh->usecs;
  81289. + }
  81290. +
  81291. + if (hcd->periodic_usecs > max_claimed_usecs) {
  81292. + DWC_INFO("%s: already claimed usecs %d, required usecs %d\n", __func__, hcd->periodic_usecs, qh->usecs); //NOTICE
  81293. + status = -DWC_E_NO_SPACE;
  81294. + }
  81295. +
  81296. + return status;
  81297. +}
  81298. +
  81299. +/* microframe_schedule=0 end */
  81300. +
  81301. +/**
  81302. + * Microframe scheduler
  81303. + * track the total use in hcd->frame_usecs
  81304. + * keep each qh use in qh->frame_usecs
  81305. + * when surrendering the qh then donate the time back
  81306. + */
  81307. +const unsigned short max_uframe_usecs[]={ 100, 100, 100, 100, 100, 100, 30, 0 };
  81308. +
  81309. +/*
  81310. + * called from dwc_otg_hcd.c:dwc_otg_hcd_init
  81311. + */
  81312. +int init_hcd_usecs(dwc_otg_hcd_t *_hcd)
  81313. +{
  81314. + int i;
  81315. + for (i=0; i<8; i++) {
  81316. + _hcd->frame_usecs[i] = max_uframe_usecs[i];
  81317. + }
  81318. + return 0;
  81319. +}
  81320. +
  81321. +static int find_single_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
  81322. +{
  81323. + int i;
  81324. + unsigned short utime;
  81325. + int t_left;
  81326. + int ret;
  81327. + int done;
  81328. +
  81329. + ret = -1;
  81330. + utime = _qh->usecs;
  81331. + t_left = utime;
  81332. + i = 0;
  81333. + done = 0;
  81334. + while (done == 0) {
  81335. + /* At the start _hcd->frame_usecs[i] = max_uframe_usecs[i]; */
  81336. + if (utime <= _hcd->frame_usecs[i]) {
  81337. + _hcd->frame_usecs[i] -= utime;
  81338. + _qh->frame_usecs[i] += utime;
  81339. + t_left -= utime;
  81340. + ret = i;
  81341. + done = 1;
  81342. + return ret;
  81343. + } else {
  81344. + i++;
  81345. + if (i == 8) {
  81346. + done = 1;
  81347. + ret = -1;
  81348. + }
  81349. + }
  81350. + }
  81351. + return ret;
  81352. + }
  81353. +
  81354. +/*
  81355. + * use this for FS apps that can span multiple uframes
  81356. + */
  81357. +static int find_multi_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
  81358. +{
  81359. + int i;
  81360. + int j;
  81361. + unsigned short utime;
  81362. + int t_left;
  81363. + int ret;
  81364. + int done;
  81365. + unsigned short xtime;
  81366. +
  81367. + ret = -1;
  81368. + utime = _qh->usecs;
  81369. + t_left = utime;
  81370. + i = 0;
  81371. + done = 0;
  81372. +loop:
  81373. + while (done == 0) {
  81374. + if(_hcd->frame_usecs[i] <= 0) {
  81375. + i++;
  81376. + if (i == 8) {
  81377. + done = 1;
  81378. + ret = -1;
  81379. + }
  81380. + goto loop;
  81381. + }
  81382. +
  81383. + /*
  81384. + * we need n consecutive slots
  81385. + * so use j as a start slot j plus j+1 must be enough time (for now)
  81386. + */
  81387. + xtime= _hcd->frame_usecs[i];
  81388. + for (j = i+1 ; j < 8 ; j++ ) {
  81389. + /*
  81390. + * if we add this frame remaining time to xtime we may
  81391. + * be OK, if not we need to test j for a complete frame
  81392. + */
  81393. + if ((xtime+_hcd->frame_usecs[j]) < utime) {
  81394. + if (_hcd->frame_usecs[j] < max_uframe_usecs[j]) {
  81395. + j = 8;
  81396. + ret = -1;
  81397. + continue;
  81398. + }
  81399. + }
  81400. + if (xtime >= utime) {
  81401. + ret = i;
  81402. + j = 8; /* stop loop with a good value ret */
  81403. + continue;
  81404. + }
  81405. + /* add the frame time to x time */
  81406. + xtime += _hcd->frame_usecs[j];
  81407. + /* we must have a fully available next frame or break */
  81408. + if ((xtime < utime)
  81409. + && (_hcd->frame_usecs[j] == max_uframe_usecs[j])) {
  81410. + ret = -1;
  81411. + j = 8; /* stop loop with a bad value ret */
  81412. + continue;
  81413. + }
  81414. + }
  81415. + if (ret >= 0) {
  81416. + t_left = utime;
  81417. + for (j = i; (t_left>0) && (j < 8); j++ ) {
  81418. + t_left -= _hcd->frame_usecs[j];
  81419. + if ( t_left <= 0 ) {
  81420. + _qh->frame_usecs[j] += _hcd->frame_usecs[j] + t_left;
  81421. + _hcd->frame_usecs[j]= -t_left;
  81422. + ret = i;
  81423. + done = 1;
  81424. + } else {
  81425. + _qh->frame_usecs[j] += _hcd->frame_usecs[j];
  81426. + _hcd->frame_usecs[j] = 0;
  81427. + }
  81428. + }
  81429. + } else {
  81430. + i++;
  81431. + if (i == 8) {
  81432. + done = 1;
  81433. + ret = -1;
  81434. + }
  81435. + }
  81436. + }
  81437. + return ret;
  81438. +}
  81439. +
  81440. +static int find_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
  81441. +{
  81442. + int ret;
  81443. + ret = -1;
  81444. +
  81445. + if (_qh->speed == USB_SPEED_HIGH) {
  81446. + /* if this is a hs transaction we need a full frame */
  81447. + ret = find_single_uframe(_hcd, _qh);
  81448. + } else {
  81449. + /* if this is a fs transaction we may need a sequence of frames */
  81450. + ret = find_multi_uframe(_hcd, _qh);
  81451. + }
  81452. + return ret;
  81453. +}
  81454. +
  81455. +/**
  81456. + * Checks that the max transfer size allowed in a host channel is large enough
  81457. + * to handle the maximum data transfer in a single (micro)frame for a periodic
  81458. + * transfer.
  81459. + *
  81460. + * @param hcd The HCD state structure for the DWC OTG controller.
  81461. + * @param qh QH for a periodic endpoint.
  81462. + *
  81463. + * @return 0 if successful, negative error code otherwise.
  81464. + */
  81465. +static int check_max_xfer_size(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  81466. +{
  81467. + int status;
  81468. + uint32_t max_xfer_size;
  81469. + uint32_t max_channel_xfer_size;
  81470. +
  81471. + status = 0;
  81472. +
  81473. + max_xfer_size = dwc_max_packet(qh->maxp) * dwc_hb_mult(qh->maxp);
  81474. + max_channel_xfer_size = hcd->core_if->core_params->max_transfer_size;
  81475. +
  81476. + if (max_xfer_size > max_channel_xfer_size) {
  81477. + DWC_INFO("%s: Periodic xfer length %d > " "max xfer length for channel %d\n",
  81478. + __func__, max_xfer_size, max_channel_xfer_size); //NOTICE
  81479. + status = -DWC_E_NO_SPACE;
  81480. + }
  81481. +
  81482. + return status;
  81483. +}
  81484. +
  81485. +
  81486. +
  81487. +/**
  81488. + * Schedules an interrupt or isochronous transfer in the periodic schedule.
  81489. + *
  81490. + * @param hcd The HCD state structure for the DWC OTG controller.
  81491. + * @param qh QH for the periodic transfer. The QH should already contain the
  81492. + * scheduling information.
  81493. + *
  81494. + * @return 0 if successful, negative error code otherwise.
  81495. + */
  81496. +static int schedule_periodic(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  81497. +{
  81498. + int status = 0;
  81499. +
  81500. + if (microframe_schedule) {
  81501. + int frame;
  81502. + status = find_uframe(hcd, qh);
  81503. + frame = -1;
  81504. + if (status == 0) {
  81505. + frame = 7;
  81506. + } else {
  81507. + if (status > 0 )
  81508. + frame = status-1;
  81509. + }
  81510. +
  81511. + /* Set the new frame up */
  81512. + if (frame > -1) {
  81513. + qh->sched_frame &= ~0x7;
  81514. + qh->sched_frame |= (frame & 7);
  81515. + }
  81516. +
  81517. + if (status != -1)
  81518. + status = 0;
  81519. + } else {
  81520. + status = periodic_channel_available(hcd);
  81521. + if (status) {
  81522. + DWC_INFO("%s: No host channel available for periodic " "transfer.\n", __func__); //NOTICE
  81523. + return status;
  81524. + }
  81525. +
  81526. + status = check_periodic_bandwidth(hcd, qh);
  81527. + }
  81528. + if (status) {
  81529. + DWC_INFO("%s: Insufficient periodic bandwidth for "
  81530. + "periodic transfer.\n", __func__);
  81531. + return status;
  81532. + }
  81533. + status = check_max_xfer_size(hcd, qh);
  81534. + if (status) {
  81535. + DWC_INFO("%s: Channel max transfer size too small "
  81536. + "for periodic transfer.\n", __func__);
  81537. + return status;
  81538. + }
  81539. +
  81540. + if (hcd->core_if->dma_desc_enable) {
  81541. + /* Don't rely on SOF and start in ready schedule */
  81542. + DWC_LIST_INSERT_TAIL(&hcd->periodic_sched_ready, &qh->qh_list_entry);
  81543. + }
  81544. + else {
  81545. + if(DWC_LIST_EMPTY(&hcd->periodic_sched_inactive) || dwc_frame_num_le(qh->sched_frame, hcd->fiq_state->next_sched_frame))
  81546. + {
  81547. + hcd->fiq_state->next_sched_frame = qh->sched_frame;
  81548. +
  81549. + }
  81550. + /* Always start in the inactive schedule. */
  81551. + DWC_LIST_INSERT_TAIL(&hcd->periodic_sched_inactive, &qh->qh_list_entry);
  81552. + }
  81553. +
  81554. + if (!microframe_schedule) {
  81555. + /* Reserve the periodic channel. */
  81556. + hcd->periodic_channels++;
  81557. + }
  81558. +
  81559. + /* Update claimed usecs per (micro)frame. */
  81560. + hcd->periodic_usecs += qh->usecs;
  81561. +
  81562. + return status;
  81563. +}
  81564. +
  81565. +
  81566. +/**
  81567. + * This function adds a QH to either the non periodic or periodic schedule if
  81568. + * it is not already in the schedule. If the QH is already in the schedule, no
  81569. + * action is taken.
  81570. + *
  81571. + * @return 0 if successful, negative error code otherwise.
  81572. + */
  81573. +int dwc_otg_hcd_qh_add(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  81574. +{
  81575. + int status = 0;
  81576. + gintmsk_data_t intr_mask = {.d32 = 0 };
  81577. +
  81578. + if (!DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  81579. + /* QH already in a schedule. */
  81580. + return status;
  81581. + }
  81582. +
  81583. + /* Add the new QH to the appropriate schedule */
  81584. + if (dwc_qh_is_non_per(qh)) {
  81585. + /* Always start in the inactive schedule. */
  81586. + DWC_LIST_INSERT_TAIL(&hcd->non_periodic_sched_inactive,
  81587. + &qh->qh_list_entry);
  81588. + //hcd->fiq_state->kick_np_queues = 1;
  81589. + } else {
  81590. + status = schedule_periodic(hcd, qh);
  81591. + if ( !hcd->periodic_qh_count ) {
  81592. + intr_mask.b.sofintr = 1;
  81593. + DWC_MODIFY_REG32(&hcd->core_if->core_global_regs->gintmsk,
  81594. + intr_mask.d32, intr_mask.d32);
  81595. + }
  81596. + hcd->periodic_qh_count++;
  81597. + }
  81598. +
  81599. + return status;
  81600. +}
  81601. +
  81602. +/**
  81603. + * Removes an interrupt or isochronous transfer from the periodic schedule.
  81604. + *
  81605. + * @param hcd The HCD state structure for the DWC OTG controller.
  81606. + * @param qh QH for the periodic transfer.
  81607. + */
  81608. +static void deschedule_periodic(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  81609. +{
  81610. + int i;
  81611. + DWC_LIST_REMOVE_INIT(&qh->qh_list_entry);
  81612. +
  81613. + /* Update claimed usecs per (micro)frame. */
  81614. + hcd->periodic_usecs -= qh->usecs;
  81615. +
  81616. + if (!microframe_schedule) {
  81617. + /* Release the periodic channel reservation. */
  81618. + hcd->periodic_channels--;
  81619. + } else {
  81620. + for (i = 0; i < 8; i++) {
  81621. + hcd->frame_usecs[i] += qh->frame_usecs[i];
  81622. + qh->frame_usecs[i] = 0;
  81623. + }
  81624. + }
  81625. +}
  81626. +
  81627. +/**
  81628. + * Removes a QH from either the non-periodic or periodic schedule. Memory is
  81629. + * not freed.
  81630. + *
  81631. + * @param hcd The HCD state structure.
  81632. + * @param qh QH to remove from schedule. */
  81633. +void dwc_otg_hcd_qh_remove(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  81634. +{
  81635. + gintmsk_data_t intr_mask = {.d32 = 0 };
  81636. +
  81637. + if (DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  81638. + /* QH is not in a schedule. */
  81639. + return;
  81640. + }
  81641. +
  81642. + if (dwc_qh_is_non_per(qh)) {
  81643. + if (hcd->non_periodic_qh_ptr == &qh->qh_list_entry) {
  81644. + hcd->non_periodic_qh_ptr =
  81645. + hcd->non_periodic_qh_ptr->next;
  81646. + }
  81647. + DWC_LIST_REMOVE_INIT(&qh->qh_list_entry);
  81648. + //if (!DWC_LIST_EMPTY(&hcd->non_periodic_sched_inactive))
  81649. + // hcd->fiq_state->kick_np_queues = 1;
  81650. + } else {
  81651. + deschedule_periodic(hcd, qh);
  81652. + hcd->periodic_qh_count--;
  81653. + if( !hcd->periodic_qh_count && !fiq_fsm_enable ) {
  81654. + intr_mask.b.sofintr = 1;
  81655. + DWC_MODIFY_REG32(&hcd->core_if->core_global_regs->gintmsk,
  81656. + intr_mask.d32, 0);
  81657. + }
  81658. + }
  81659. +}
  81660. +
  81661. +/**
  81662. + * Deactivates a QH. For non-periodic QHs, removes the QH from the active
  81663. + * non-periodic schedule. The QH is added to the inactive non-periodic
  81664. + * schedule if any QTDs are still attached to the QH.
  81665. + *
  81666. + * For periodic QHs, the QH is removed from the periodic queued schedule. If
  81667. + * there are any QTDs still attached to the QH, the QH is added to either the
  81668. + * periodic inactive schedule or the periodic ready schedule and its next
  81669. + * scheduled frame is calculated. The QH is placed in the ready schedule if
  81670. + * the scheduled frame has been reached already. Otherwise it's placed in the
  81671. + * inactive schedule. If there are no QTDs attached to the QH, the QH is
  81672. + * completely removed from the periodic schedule.
  81673. + */
  81674. +void dwc_otg_hcd_qh_deactivate(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  81675. + int sched_next_periodic_split)
  81676. +{
  81677. + if (dwc_qh_is_non_per(qh)) {
  81678. + dwc_otg_hcd_qh_remove(hcd, qh);
  81679. + if (!DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  81680. + /* Add back to inactive non-periodic schedule. */
  81681. + dwc_otg_hcd_qh_add(hcd, qh);
  81682. + //hcd->fiq_state->kick_np_queues = 1;
  81683. + }
  81684. + } else {
  81685. + uint16_t frame_number = dwc_otg_hcd_get_frame_number(hcd);
  81686. +
  81687. + if (qh->do_split) {
  81688. + /* Schedule the next continuing periodic split transfer */
  81689. + if (sched_next_periodic_split) {
  81690. +
  81691. + qh->sched_frame = frame_number;
  81692. +
  81693. + if (dwc_frame_num_le(frame_number,
  81694. + dwc_frame_num_inc
  81695. + (qh->start_split_frame,
  81696. + 1))) {
  81697. + /*
  81698. + * Allow one frame to elapse after start
  81699. + * split microframe before scheduling
  81700. + * complete split, but DONT if we are
  81701. + * doing the next start split in the
  81702. + * same frame for an ISOC out.
  81703. + */
  81704. + if ((qh->ep_type != UE_ISOCHRONOUS) ||
  81705. + (qh->ep_is_in != 0)) {
  81706. + qh->sched_frame =
  81707. + dwc_frame_num_inc(qh->sched_frame, 1);
  81708. + }
  81709. + }
  81710. + } else {
  81711. + qh->sched_frame =
  81712. + dwc_frame_num_inc(qh->start_split_frame,
  81713. + qh->interval);
  81714. + if (dwc_frame_num_le
  81715. + (qh->sched_frame, frame_number)) {
  81716. + qh->sched_frame = frame_number;
  81717. + }
  81718. + qh->sched_frame |= 0x7;
  81719. + qh->start_split_frame = qh->sched_frame;
  81720. + }
  81721. + } else {
  81722. + qh->sched_frame =
  81723. + dwc_frame_num_inc(qh->sched_frame, qh->interval);
  81724. + if (dwc_frame_num_le(qh->sched_frame, frame_number)) {
  81725. + qh->sched_frame = frame_number;
  81726. + }
  81727. + }
  81728. +
  81729. + if (DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  81730. + dwc_otg_hcd_qh_remove(hcd, qh);
  81731. + } else {
  81732. + /*
  81733. + * Remove from periodic_sched_queued and move to
  81734. + * appropriate queue.
  81735. + */
  81736. + if ((microframe_schedule && dwc_frame_num_le(qh->sched_frame, frame_number)) ||
  81737. + (!microframe_schedule && qh->sched_frame == frame_number)) {
  81738. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_ready,
  81739. + &qh->qh_list_entry);
  81740. + } else {
  81741. + if(!dwc_frame_num_le(hcd->fiq_state->next_sched_frame, qh->sched_frame))
  81742. + {
  81743. + hcd->fiq_state->next_sched_frame = qh->sched_frame;
  81744. + }
  81745. +
  81746. + DWC_LIST_MOVE_HEAD
  81747. + (&hcd->periodic_sched_inactive,
  81748. + &qh->qh_list_entry);
  81749. + }
  81750. + }
  81751. + }
  81752. +}
  81753. +
  81754. +/**
  81755. + * This function allocates and initializes a QTD.
  81756. + *
  81757. + * @param urb The URB to create a QTD from. Each URB-QTD pair will end up
  81758. + * pointing to each other so each pair should have a unique correlation.
  81759. + * @param atomic_alloc Flag to do atomic alloc if needed
  81760. + *
  81761. + * @return Returns pointer to the newly allocated QTD, or NULL on error. */
  81762. +dwc_otg_qtd_t *dwc_otg_hcd_qtd_create(dwc_otg_hcd_urb_t * urb, int atomic_alloc)
  81763. +{
  81764. + dwc_otg_qtd_t *qtd;
  81765. +
  81766. + qtd = dwc_otg_hcd_qtd_alloc(atomic_alloc);
  81767. + if (qtd == NULL) {
  81768. + return NULL;
  81769. + }
  81770. +
  81771. + dwc_otg_hcd_qtd_init(qtd, urb);
  81772. + return qtd;
  81773. +}
  81774. +
  81775. +/**
  81776. + * Initializes a QTD structure.
  81777. + *
  81778. + * @param qtd The QTD to initialize.
  81779. + * @param urb The URB to use for initialization. */
  81780. +void dwc_otg_hcd_qtd_init(dwc_otg_qtd_t * qtd, dwc_otg_hcd_urb_t * urb)
  81781. +{
  81782. + dwc_memset(qtd, 0, sizeof(dwc_otg_qtd_t));
  81783. + qtd->urb = urb;
  81784. + if (dwc_otg_hcd_get_pipe_type(&urb->pipe_info) == UE_CONTROL) {
  81785. + /*
  81786. + * The only time the QTD data toggle is used is on the data
  81787. + * phase of control transfers. This phase always starts with
  81788. + * DATA1.
  81789. + */
  81790. + qtd->data_toggle = DWC_OTG_HC_PID_DATA1;
  81791. + qtd->control_phase = DWC_OTG_CONTROL_SETUP;
  81792. + }
  81793. +
  81794. + /* start split */
  81795. + qtd->complete_split = 0;
  81796. + qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_ALL;
  81797. + qtd->isoc_split_offset = 0;
  81798. + qtd->in_process = 0;
  81799. +
  81800. + /* Store the qtd ptr in the urb to reference what QTD. */
  81801. + urb->qtd = qtd;
  81802. + return;
  81803. +}
  81804. +
  81805. +/**
  81806. + * This function adds a QTD to the QTD-list of a QH. It will find the correct
  81807. + * QH to place the QTD into. If it does not find a QH, then it will create a
  81808. + * new QH. If the QH to which the QTD is added is not currently scheduled, it
  81809. + * is placed into the proper schedule based on its EP type.
  81810. + * HCD lock must be held and interrupts must be disabled on entry
  81811. + *
  81812. + * @param[in] qtd The QTD to add
  81813. + * @param[in] hcd The DWC HCD structure
  81814. + * @param[out] qh out parameter to return queue head
  81815. + * @param atomic_alloc Flag to do atomic alloc if needed
  81816. + *
  81817. + * @return 0 if successful, negative error code otherwise.
  81818. + */
  81819. +int dwc_otg_hcd_qtd_add(dwc_otg_qtd_t * qtd,
  81820. + dwc_otg_hcd_t * hcd, dwc_otg_qh_t ** qh, int atomic_alloc)
  81821. +{
  81822. + int retval = 0;
  81823. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  81824. +
  81825. + /*
  81826. + * Get the QH which holds the QTD-list to insert to. Create QH if it
  81827. + * doesn't exist.
  81828. + */
  81829. + if (*qh == NULL) {
  81830. + *qh = dwc_otg_hcd_qh_create(hcd, urb, atomic_alloc);
  81831. + if (*qh == NULL) {
  81832. + retval = -DWC_E_NO_MEMORY;
  81833. + goto done;
  81834. + } else {
  81835. + if (fiq_enable)
  81836. + hcd->fiq_state->kick_np_queues = 1;
  81837. + }
  81838. + }
  81839. + retval = dwc_otg_hcd_qh_add(hcd, *qh);
  81840. + if (retval == 0) {
  81841. + DWC_CIRCLEQ_INSERT_TAIL(&((*qh)->qtd_list), qtd,
  81842. + qtd_list_entry);
  81843. + qtd->qh = *qh;
  81844. + }
  81845. +done:
  81846. +
  81847. + return retval;
  81848. +}
  81849. +
  81850. +#endif /* DWC_DEVICE_ONLY */
  81851. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h
  81852. --- linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h 1970-01-01 01:00:00.000000000 +0100
  81853. +++ linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h 2014-08-06 16:50:14.845965072 +0200
  81854. @@ -0,0 +1,188 @@
  81855. +#ifndef _DWC_OS_DEP_H_
  81856. +#define _DWC_OS_DEP_H_
  81857. +
  81858. +/**
  81859. + * @file
  81860. + *
  81861. + * This file contains OS dependent structures.
  81862. + *
  81863. + */
  81864. +
  81865. +#include <linux/kernel.h>
  81866. +#include <linux/module.h>
  81867. +#include <linux/moduleparam.h>
  81868. +#include <linux/init.h>
  81869. +#include <linux/device.h>
  81870. +#include <linux/errno.h>
  81871. +#include <linux/types.h>
  81872. +#include <linux/slab.h>
  81873. +#include <linux/list.h>
  81874. +#include <linux/interrupt.h>
  81875. +#include <linux/ctype.h>
  81876. +#include <linux/string.h>
  81877. +#include <linux/dma-mapping.h>
  81878. +#include <linux/jiffies.h>
  81879. +#include <linux/delay.h>
  81880. +#include <linux/timer.h>
  81881. +#include <linux/workqueue.h>
  81882. +#include <linux/stat.h>
  81883. +#include <linux/pci.h>
  81884. +
  81885. +#include <linux/version.h>
  81886. +
  81887. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
  81888. +# include <linux/irq.h>
  81889. +#endif
  81890. +
  81891. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
  81892. +# include <linux/usb/ch9.h>
  81893. +#else
  81894. +# include <linux/usb_ch9.h>
  81895. +#endif
  81896. +
  81897. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
  81898. +# include <linux/usb/gadget.h>
  81899. +#else
  81900. +# include <linux/usb_gadget.h>
  81901. +#endif
  81902. +
  81903. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
  81904. +# include <asm/irq.h>
  81905. +#endif
  81906. +
  81907. +#ifdef PCI_INTERFACE
  81908. +# include <asm/io.h>
  81909. +#endif
  81910. +
  81911. +#ifdef LM_INTERFACE
  81912. +# include <asm/unaligned.h>
  81913. +# include <asm/sizes.h>
  81914. +# include <asm/param.h>
  81915. +# include <asm/io.h>
  81916. +# if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30))
  81917. +# include <asm/arch/hardware.h>
  81918. +# include <asm/arch/lm.h>
  81919. +# include <asm/arch/irqs.h>
  81920. +# include <asm/arch/regs-irq.h>
  81921. +# else
  81922. +/* in 2.6.31, at least, we seem to have lost the generic LM infrastructure -
  81923. + here we assume that the machine architecture provides definitions
  81924. + in its own header
  81925. +*/
  81926. +# include <mach/lm.h>
  81927. +# include <mach/hardware.h>
  81928. +# endif
  81929. +#endif
  81930. +
  81931. +#ifdef PLATFORM_INTERFACE
  81932. +#include <linux/platform_device.h>
  81933. +#include <asm/mach/map.h>
  81934. +#endif
  81935. +
  81936. +/** The OS page size */
  81937. +#define DWC_OS_PAGE_SIZE PAGE_SIZE
  81938. +
  81939. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
  81940. +typedef int gfp_t;
  81941. +#endif
  81942. +
  81943. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
  81944. +# define IRQF_SHARED SA_SHIRQ
  81945. +#endif
  81946. +
  81947. +typedef struct os_dependent {
  81948. + /** Base address returned from ioremap() */
  81949. + void *base;
  81950. +
  81951. + /** Register offset for Diagnostic API */
  81952. + uint32_t reg_offset;
  81953. +
  81954. + /** Base address for MPHI peripheral */
  81955. + void *mphi_base;
  81956. +
  81957. +#ifdef LM_INTERFACE
  81958. + struct lm_device *lmdev;
  81959. +#elif defined(PCI_INTERFACE)
  81960. + struct pci_dev *pcidev;
  81961. +
  81962. + /** Start address of a PCI region */
  81963. + resource_size_t rsrc_start;
  81964. +
  81965. + /** Length address of a PCI region */
  81966. + resource_size_t rsrc_len;
  81967. +#elif defined(PLATFORM_INTERFACE)
  81968. + struct platform_device *platformdev;
  81969. +#endif
  81970. +
  81971. +} os_dependent_t;
  81972. +
  81973. +#ifdef __cplusplus
  81974. +}
  81975. +#endif
  81976. +
  81977. +
  81978. +
  81979. +/* Type for the our device on the chosen bus */
  81980. +#if defined(LM_INTERFACE)
  81981. +typedef struct lm_device dwc_bus_dev_t;
  81982. +#elif defined(PCI_INTERFACE)
  81983. +typedef struct pci_dev dwc_bus_dev_t;
  81984. +#elif defined(PLATFORM_INTERFACE)
  81985. +typedef struct platform_device dwc_bus_dev_t;
  81986. +#endif
  81987. +
  81988. +/* Helper macro to retrieve drvdata from the device on the chosen bus */
  81989. +#if defined(LM_INTERFACE)
  81990. +#define DWC_OTG_BUSDRVDATA(_dev) lm_get_drvdata(_dev)
  81991. +#elif defined(PCI_INTERFACE)
  81992. +#define DWC_OTG_BUSDRVDATA(_dev) pci_get_drvdata(_dev)
  81993. +#elif defined(PLATFORM_INTERFACE)
  81994. +#define DWC_OTG_BUSDRVDATA(_dev) platform_get_drvdata(_dev)
  81995. +#endif
  81996. +
  81997. +/**
  81998. + * Helper macro returning the otg_device structure of a given struct device
  81999. + *
  82000. + * c.f. static dwc_otg_device_t *dwc_otg_drvdev(struct device *_dev)
  82001. + */
  82002. +#ifdef LM_INTERFACE
  82003. +#define DWC_OTG_GETDRVDEV(_var, _dev) do { \
  82004. + struct lm_device *lm_dev = \
  82005. + container_of(_dev, struct lm_device, dev); \
  82006. + _var = lm_get_drvdata(lm_dev); \
  82007. + } while (0)
  82008. +
  82009. +#elif defined(PCI_INTERFACE)
  82010. +#define DWC_OTG_GETDRVDEV(_var, _dev) do { \
  82011. + _var = dev_get_drvdata(_dev); \
  82012. + } while (0)
  82013. +
  82014. +#elif defined(PLATFORM_INTERFACE)
  82015. +#define DWC_OTG_GETDRVDEV(_var, _dev) do { \
  82016. + struct platform_device *platform_dev = \
  82017. + container_of(_dev, struct platform_device, dev); \
  82018. + _var = platform_get_drvdata(platform_dev); \
  82019. + } while (0)
  82020. +#endif
  82021. +
  82022. +
  82023. +/**
  82024. + * Helper macro returning the struct dev of the given struct os_dependent
  82025. + *
  82026. + * c.f. static struct device *dwc_otg_getdev(struct os_dependent *osdep)
  82027. + */
  82028. +#ifdef LM_INTERFACE
  82029. +#define DWC_OTG_OS_GETDEV(_osdep) \
  82030. + ((_osdep).lmdev == NULL? NULL: &(_osdep).lmdev->dev)
  82031. +#elif defined(PCI_INTERFACE)
  82032. +#define DWC_OTG_OS_GETDEV(_osdep) \
  82033. + ((_osdep).pci_dev == NULL? NULL: &(_osdep).pci_dev->dev)
  82034. +#elif defined(PLATFORM_INTERFACE)
  82035. +#define DWC_OTG_OS_GETDEV(_osdep) \
  82036. + ((_osdep).platformdev == NULL? NULL: &(_osdep).platformdev->dev)
  82037. +#endif
  82038. +
  82039. +
  82040. +
  82041. +
  82042. +#endif /* _DWC_OS_DEP_H_ */
  82043. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_pcd.c linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_pcd.c
  82044. --- linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_pcd.c 1970-01-01 01:00:00.000000000 +0100
  82045. +++ linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_pcd.c 2014-08-06 16:50:14.849965104 +0200
  82046. @@ -0,0 +1,2708 @@
  82047. +/* ==========================================================================
  82048. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd.c $
  82049. + * $Revision: #101 $
  82050. + * $Date: 2012/08/10 $
  82051. + * $Change: 2047372 $
  82052. + *
  82053. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  82054. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  82055. + * otherwise expressly agreed to in writing between Synopsys and you.
  82056. + *
  82057. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  82058. + * any End User Software License Agreement or Agreement for Licensed Product
  82059. + * with Synopsys or any supplement thereto. You are permitted to use and
  82060. + * redistribute this Software in source and binary forms, with or without
  82061. + * modification, provided that redistributions of source code must retain this
  82062. + * notice. You may not view, use, disclose, copy or distribute this file or
  82063. + * any information contained herein except pursuant to this license grant from
  82064. + * Synopsys. If you do not agree with this notice, including the disclaimer
  82065. + * below, then you are not authorized to use the Software.
  82066. + *
  82067. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  82068. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  82069. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  82070. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  82071. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  82072. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  82073. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  82074. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  82075. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  82076. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  82077. + * DAMAGE.
  82078. + * ========================================================================== */
  82079. +#ifndef DWC_HOST_ONLY
  82080. +
  82081. +/** @file
  82082. + * This file implements PCD Core. All code in this file is portable and doesn't
  82083. + * use any OS specific functions.
  82084. + * PCD Core provides Interface, defined in <code><dwc_otg_pcd_if.h></code>
  82085. + * header file, which can be used to implement OS specific PCD interface.
  82086. + *
  82087. + * An important function of the PCD is managing interrupts generated
  82088. + * by the DWC_otg controller. The implementation of the DWC_otg device
  82089. + * mode interrupt service routines is in dwc_otg_pcd_intr.c.
  82090. + *
  82091. + * @todo Add Device Mode test modes (Test J mode, Test K mode, etc).
  82092. + * @todo Does it work when the request size is greater than DEPTSIZ
  82093. + * transfer size
  82094. + *
  82095. + */
  82096. +
  82097. +#include "dwc_otg_pcd.h"
  82098. +
  82099. +#ifdef DWC_UTE_CFI
  82100. +#include "dwc_otg_cfi.h"
  82101. +
  82102. +extern int init_cfi(cfiobject_t * cfiobj);
  82103. +#endif
  82104. +
  82105. +/**
  82106. + * Choose endpoint from ep arrays using usb_ep structure.
  82107. + */
  82108. +static dwc_otg_pcd_ep_t *get_ep_from_handle(dwc_otg_pcd_t * pcd, void *handle)
  82109. +{
  82110. + int i;
  82111. + if (pcd->ep0.priv == handle) {
  82112. + return &pcd->ep0;
  82113. + }
  82114. + for (i = 0; i < MAX_EPS_CHANNELS - 1; i++) {
  82115. + if (pcd->in_ep[i].priv == handle)
  82116. + return &pcd->in_ep[i];
  82117. + if (pcd->out_ep[i].priv == handle)
  82118. + return &pcd->out_ep[i];
  82119. + }
  82120. +
  82121. + return NULL;
  82122. +}
  82123. +
  82124. +/**
  82125. + * This function completes a request. It call's the request call back.
  82126. + */
  82127. +void dwc_otg_request_done(dwc_otg_pcd_ep_t * ep, dwc_otg_pcd_request_t * req,
  82128. + int32_t status)
  82129. +{
  82130. + unsigned stopped = ep->stopped;
  82131. +
  82132. + DWC_DEBUGPL(DBG_PCDV, "%s(ep %p req %p)\n", __func__, ep, req);
  82133. + DWC_CIRCLEQ_REMOVE_INIT(&ep->queue, req, queue_entry);
  82134. +
  82135. + /* don't modify queue heads during completion callback */
  82136. + ep->stopped = 1;
  82137. + /* spin_unlock/spin_lock now done in fops->complete() */
  82138. + ep->pcd->fops->complete(ep->pcd, ep->priv, req->priv, status,
  82139. + req->actual);
  82140. +
  82141. + if (ep->pcd->request_pending > 0) {
  82142. + --ep->pcd->request_pending;
  82143. + }
  82144. +
  82145. + ep->stopped = stopped;
  82146. + DWC_FREE(req);
  82147. +}
  82148. +
  82149. +/**
  82150. + * This function terminates all the requsts in the EP request queue.
  82151. + */
  82152. +void dwc_otg_request_nuke(dwc_otg_pcd_ep_t * ep)
  82153. +{
  82154. + dwc_otg_pcd_request_t *req;
  82155. +
  82156. + ep->stopped = 1;
  82157. +
  82158. + /* called with irqs blocked?? */
  82159. + while (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  82160. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  82161. + dwc_otg_request_done(ep, req, -DWC_E_SHUTDOWN);
  82162. + }
  82163. +}
  82164. +
  82165. +void dwc_otg_pcd_start(dwc_otg_pcd_t * pcd,
  82166. + const struct dwc_otg_pcd_function_ops *fops)
  82167. +{
  82168. + pcd->fops = fops;
  82169. +}
  82170. +
  82171. +/**
  82172. + * PCD Callback function for initializing the PCD when switching to
  82173. + * device mode.
  82174. + *
  82175. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  82176. + */
  82177. +static int32_t dwc_otg_pcd_start_cb(void *p)
  82178. +{
  82179. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  82180. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  82181. +
  82182. + /*
  82183. + * Initialized the Core for Device mode.
  82184. + */
  82185. + if (dwc_otg_is_device_mode(core_if)) {
  82186. + dwc_otg_core_dev_init(core_if);
  82187. + /* Set core_if's lock pointer to the pcd->lock */
  82188. + core_if->lock = pcd->lock;
  82189. + }
  82190. + return 1;
  82191. +}
  82192. +
  82193. +/** CFI-specific buffer allocation function for EP */
  82194. +#ifdef DWC_UTE_CFI
  82195. +uint8_t *cfiw_ep_alloc_buffer(dwc_otg_pcd_t * pcd, void *pep, dwc_dma_t * addr,
  82196. + size_t buflen, int flags)
  82197. +{
  82198. + dwc_otg_pcd_ep_t *ep;
  82199. + ep = get_ep_from_handle(pcd, pep);
  82200. + if (!ep) {
  82201. + DWC_WARN("bad ep\n");
  82202. + return -DWC_E_INVALID;
  82203. + }
  82204. +
  82205. + return pcd->cfi->ops.ep_alloc_buf(pcd->cfi, pcd, ep, addr, buflen,
  82206. + flags);
  82207. +}
  82208. +#else
  82209. +uint8_t *cfiw_ep_alloc_buffer(dwc_otg_pcd_t * pcd, void *pep, dwc_dma_t * addr,
  82210. + size_t buflen, int flags);
  82211. +#endif
  82212. +
  82213. +/**
  82214. + * PCD Callback function for notifying the PCD when resuming from
  82215. + * suspend.
  82216. + *
  82217. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  82218. + */
  82219. +static int32_t dwc_otg_pcd_resume_cb(void *p)
  82220. +{
  82221. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  82222. +
  82223. + if (pcd->fops->resume) {
  82224. + pcd->fops->resume(pcd);
  82225. + }
  82226. +
  82227. + /* Stop the SRP timeout timer. */
  82228. + if ((GET_CORE_IF(pcd)->core_params->phy_type != DWC_PHY_TYPE_PARAM_FS)
  82229. + || (!GET_CORE_IF(pcd)->core_params->i2c_enable)) {
  82230. + if (GET_CORE_IF(pcd)->srp_timer_started) {
  82231. + GET_CORE_IF(pcd)->srp_timer_started = 0;
  82232. + DWC_TIMER_CANCEL(GET_CORE_IF(pcd)->srp_timer);
  82233. + }
  82234. + }
  82235. + return 1;
  82236. +}
  82237. +
  82238. +/**
  82239. + * PCD Callback function for notifying the PCD device is suspended.
  82240. + *
  82241. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  82242. + */
  82243. +static int32_t dwc_otg_pcd_suspend_cb(void *p)
  82244. +{
  82245. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  82246. +
  82247. + if (pcd->fops->suspend) {
  82248. + DWC_SPINUNLOCK(pcd->lock);
  82249. + pcd->fops->suspend(pcd);
  82250. + DWC_SPINLOCK(pcd->lock);
  82251. + }
  82252. +
  82253. + return 1;
  82254. +}
  82255. +
  82256. +/**
  82257. + * PCD Callback function for stopping the PCD when switching to Host
  82258. + * mode.
  82259. + *
  82260. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  82261. + */
  82262. +static int32_t dwc_otg_pcd_stop_cb(void *p)
  82263. +{
  82264. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  82265. + extern void dwc_otg_pcd_stop(dwc_otg_pcd_t * _pcd);
  82266. +
  82267. + dwc_otg_pcd_stop(pcd);
  82268. + return 1;
  82269. +}
  82270. +
  82271. +/**
  82272. + * PCD Callback structure for handling mode switching.
  82273. + */
  82274. +static dwc_otg_cil_callbacks_t pcd_callbacks = {
  82275. + .start = dwc_otg_pcd_start_cb,
  82276. + .stop = dwc_otg_pcd_stop_cb,
  82277. + .suspend = dwc_otg_pcd_suspend_cb,
  82278. + .resume_wakeup = dwc_otg_pcd_resume_cb,
  82279. + .p = 0, /* Set at registration */
  82280. +};
  82281. +
  82282. +/**
  82283. + * This function allocates a DMA Descriptor chain for the Endpoint
  82284. + * buffer to be used for a transfer to/from the specified endpoint.
  82285. + */
  82286. +dwc_otg_dev_dma_desc_t *dwc_otg_ep_alloc_desc_chain(dwc_dma_t * dma_desc_addr,
  82287. + uint32_t count)
  82288. +{
  82289. + return DWC_DMA_ALLOC_ATOMIC(count * sizeof(dwc_otg_dev_dma_desc_t),
  82290. + dma_desc_addr);
  82291. +}
  82292. +
  82293. +/**
  82294. + * This function frees a DMA Descriptor chain that was allocated by ep_alloc_desc.
  82295. + */
  82296. +void dwc_otg_ep_free_desc_chain(dwc_otg_dev_dma_desc_t * desc_addr,
  82297. + uint32_t dma_desc_addr, uint32_t count)
  82298. +{
  82299. + DWC_DMA_FREE(count * sizeof(dwc_otg_dev_dma_desc_t), desc_addr,
  82300. + dma_desc_addr);
  82301. +}
  82302. +
  82303. +#ifdef DWC_EN_ISOC
  82304. +
  82305. +/**
  82306. + * This function initializes a descriptor chain for Isochronous transfer
  82307. + *
  82308. + * @param core_if Programming view of DWC_otg controller.
  82309. + * @param dwc_ep The EP to start the transfer on.
  82310. + *
  82311. + */
  82312. +void dwc_otg_iso_ep_start_ddma_transfer(dwc_otg_core_if_t * core_if,
  82313. + dwc_ep_t * dwc_ep)
  82314. +{
  82315. +
  82316. + dsts_data_t dsts = {.d32 = 0 };
  82317. + depctl_data_t depctl = {.d32 = 0 };
  82318. + volatile uint32_t *addr;
  82319. + int i, j;
  82320. + uint32_t len;
  82321. +
  82322. + if (dwc_ep->is_in)
  82323. + dwc_ep->desc_cnt = dwc_ep->buf_proc_intrvl / dwc_ep->bInterval;
  82324. + else
  82325. + dwc_ep->desc_cnt =
  82326. + dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm /
  82327. + dwc_ep->bInterval;
  82328. +
  82329. + /** Allocate descriptors for double buffering */
  82330. + dwc_ep->iso_desc_addr =
  82331. + dwc_otg_ep_alloc_desc_chain(&dwc_ep->iso_dma_desc_addr,
  82332. + dwc_ep->desc_cnt * 2);
  82333. + if (dwc_ep->desc_addr) {
  82334. + DWC_WARN("%s, can't allocate DMA descriptor chain\n", __func__);
  82335. + return;
  82336. + }
  82337. +
  82338. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  82339. +
  82340. + /** ISO OUT EP */
  82341. + if (dwc_ep->is_in == 0) {
  82342. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  82343. + dwc_otg_dev_dma_desc_t *dma_desc = dwc_ep->iso_desc_addr;
  82344. + dma_addr_t dma_ad;
  82345. + uint32_t data_per_desc;
  82346. + dwc_otg_dev_out_ep_regs_t *out_regs =
  82347. + core_if->dev_if->out_ep_regs[dwc_ep->num];
  82348. + int offset;
  82349. +
  82350. + addr = &core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl;
  82351. + dma_ad = (dma_addr_t) DWC_READ_REG32(&(out_regs->doepdma));
  82352. +
  82353. + /** Buffer 0 descriptors setup */
  82354. + dma_ad = dwc_ep->dma_addr0;
  82355. +
  82356. + sts.b_iso_out.bs = BS_HOST_READY;
  82357. + sts.b_iso_out.rxsts = 0;
  82358. + sts.b_iso_out.l = 0;
  82359. + sts.b_iso_out.sp = 0;
  82360. + sts.b_iso_out.ioc = 0;
  82361. + sts.b_iso_out.pid = 0;
  82362. + sts.b_iso_out.framenum = 0;
  82363. +
  82364. + offset = 0;
  82365. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  82366. + i += dwc_ep->pkt_per_frm) {
  82367. +
  82368. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  82369. + uint32_t len = (j + 1) * dwc_ep->maxpacket;
  82370. + if (len > dwc_ep->data_per_frame)
  82371. + data_per_desc =
  82372. + dwc_ep->data_per_frame -
  82373. + j * dwc_ep->maxpacket;
  82374. + else
  82375. + data_per_desc = dwc_ep->maxpacket;
  82376. + len = data_per_desc % 4;
  82377. + if (len)
  82378. + data_per_desc += 4 - len;
  82379. +
  82380. + sts.b_iso_out.rxbytes = data_per_desc;
  82381. + dma_desc->buf = dma_ad;
  82382. + dma_desc->status.d32 = sts.d32;
  82383. +
  82384. + offset += data_per_desc;
  82385. + dma_desc++;
  82386. + dma_ad += data_per_desc;
  82387. + }
  82388. + }
  82389. +
  82390. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  82391. + uint32_t len = (j + 1) * dwc_ep->maxpacket;
  82392. + if (len > dwc_ep->data_per_frame)
  82393. + data_per_desc =
  82394. + dwc_ep->data_per_frame -
  82395. + j * dwc_ep->maxpacket;
  82396. + else
  82397. + data_per_desc = dwc_ep->maxpacket;
  82398. + len = data_per_desc % 4;
  82399. + if (len)
  82400. + data_per_desc += 4 - len;
  82401. + sts.b_iso_out.rxbytes = data_per_desc;
  82402. + dma_desc->buf = dma_ad;
  82403. + dma_desc->status.d32 = sts.d32;
  82404. +
  82405. + offset += data_per_desc;
  82406. + dma_desc++;
  82407. + dma_ad += data_per_desc;
  82408. + }
  82409. +
  82410. + sts.b_iso_out.ioc = 1;
  82411. + len = (j + 1) * dwc_ep->maxpacket;
  82412. + if (len > dwc_ep->data_per_frame)
  82413. + data_per_desc =
  82414. + dwc_ep->data_per_frame - j * dwc_ep->maxpacket;
  82415. + else
  82416. + data_per_desc = dwc_ep->maxpacket;
  82417. + len = data_per_desc % 4;
  82418. + if (len)
  82419. + data_per_desc += 4 - len;
  82420. + sts.b_iso_out.rxbytes = data_per_desc;
  82421. +
  82422. + dma_desc->buf = dma_ad;
  82423. + dma_desc->status.d32 = sts.d32;
  82424. + dma_desc++;
  82425. +
  82426. + /** Buffer 1 descriptors setup */
  82427. + sts.b_iso_out.ioc = 0;
  82428. + dma_ad = dwc_ep->dma_addr1;
  82429. +
  82430. + offset = 0;
  82431. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  82432. + i += dwc_ep->pkt_per_frm) {
  82433. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  82434. + uint32_t len = (j + 1) * dwc_ep->maxpacket;
  82435. + if (len > dwc_ep->data_per_frame)
  82436. + data_per_desc =
  82437. + dwc_ep->data_per_frame -
  82438. + j * dwc_ep->maxpacket;
  82439. + else
  82440. + data_per_desc = dwc_ep->maxpacket;
  82441. + len = data_per_desc % 4;
  82442. + if (len)
  82443. + data_per_desc += 4 - len;
  82444. +
  82445. + data_per_desc =
  82446. + sts.b_iso_out.rxbytes = data_per_desc;
  82447. + dma_desc->buf = dma_ad;
  82448. + dma_desc->status.d32 = sts.d32;
  82449. +
  82450. + offset += data_per_desc;
  82451. + dma_desc++;
  82452. + dma_ad += data_per_desc;
  82453. + }
  82454. + }
  82455. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  82456. + data_per_desc =
  82457. + ((j + 1) * dwc_ep->maxpacket >
  82458. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  82459. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  82460. + data_per_desc +=
  82461. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  82462. + sts.b_iso_out.rxbytes = data_per_desc;
  82463. + dma_desc->buf = dma_ad;
  82464. + dma_desc->status.d32 = sts.d32;
  82465. +
  82466. + offset += data_per_desc;
  82467. + dma_desc++;
  82468. + dma_ad += data_per_desc;
  82469. + }
  82470. +
  82471. + sts.b_iso_out.ioc = 1;
  82472. + sts.b_iso_out.l = 1;
  82473. + data_per_desc =
  82474. + ((j + 1) * dwc_ep->maxpacket >
  82475. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  82476. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  82477. + data_per_desc +=
  82478. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  82479. + sts.b_iso_out.rxbytes = data_per_desc;
  82480. +
  82481. + dma_desc->buf = dma_ad;
  82482. + dma_desc->status.d32 = sts.d32;
  82483. +
  82484. + dwc_ep->next_frame = 0;
  82485. +
  82486. + /** Write dma_ad into DOEPDMA register */
  82487. + DWC_WRITE_REG32(&(out_regs->doepdma),
  82488. + (uint32_t) dwc_ep->iso_dma_desc_addr);
  82489. +
  82490. + }
  82491. + /** ISO IN EP */
  82492. + else {
  82493. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  82494. + dwc_otg_dev_dma_desc_t *dma_desc = dwc_ep->iso_desc_addr;
  82495. + dma_addr_t dma_ad;
  82496. + dwc_otg_dev_in_ep_regs_t *in_regs =
  82497. + core_if->dev_if->in_ep_regs[dwc_ep->num];
  82498. + unsigned int frmnumber;
  82499. + fifosize_data_t txfifosize, rxfifosize;
  82500. +
  82501. + txfifosize.d32 =
  82502. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[dwc_ep->num]->
  82503. + dtxfsts);
  82504. + rxfifosize.d32 =
  82505. + DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  82506. +
  82507. + addr = &core_if->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  82508. +
  82509. + dma_ad = dwc_ep->dma_addr0;
  82510. +
  82511. + dsts.d32 =
  82512. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  82513. +
  82514. + sts.b_iso_in.bs = BS_HOST_READY;
  82515. + sts.b_iso_in.txsts = 0;
  82516. + sts.b_iso_in.sp =
  82517. + (dwc_ep->data_per_frame % dwc_ep->maxpacket) ? 1 : 0;
  82518. + sts.b_iso_in.ioc = 0;
  82519. + sts.b_iso_in.pid = dwc_ep->pkt_per_frm;
  82520. +
  82521. + frmnumber = dwc_ep->next_frame;
  82522. +
  82523. + sts.b_iso_in.framenum = frmnumber;
  82524. + sts.b_iso_in.txbytes = dwc_ep->data_per_frame;
  82525. + sts.b_iso_in.l = 0;
  82526. +
  82527. + /** Buffer 0 descriptors setup */
  82528. + for (i = 0; i < dwc_ep->desc_cnt - 1; i++) {
  82529. + dma_desc->buf = dma_ad;
  82530. + dma_desc->status.d32 = sts.d32;
  82531. + dma_desc++;
  82532. +
  82533. + dma_ad += dwc_ep->data_per_frame;
  82534. + sts.b_iso_in.framenum += dwc_ep->bInterval;
  82535. + }
  82536. +
  82537. + sts.b_iso_in.ioc = 1;
  82538. + dma_desc->buf = dma_ad;
  82539. + dma_desc->status.d32 = sts.d32;
  82540. + ++dma_desc;
  82541. +
  82542. + /** Buffer 1 descriptors setup */
  82543. + sts.b_iso_in.ioc = 0;
  82544. + dma_ad = dwc_ep->dma_addr1;
  82545. +
  82546. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  82547. + i += dwc_ep->pkt_per_frm) {
  82548. + dma_desc->buf = dma_ad;
  82549. + dma_desc->status.d32 = sts.d32;
  82550. + dma_desc++;
  82551. +
  82552. + dma_ad += dwc_ep->data_per_frame;
  82553. + sts.b_iso_in.framenum += dwc_ep->bInterval;
  82554. +
  82555. + sts.b_iso_in.ioc = 0;
  82556. + }
  82557. + sts.b_iso_in.ioc = 1;
  82558. + sts.b_iso_in.l = 1;
  82559. +
  82560. + dma_desc->buf = dma_ad;
  82561. + dma_desc->status.d32 = sts.d32;
  82562. +
  82563. + dwc_ep->next_frame = sts.b_iso_in.framenum + dwc_ep->bInterval;
  82564. +
  82565. + /** Write dma_ad into diepdma register */
  82566. + DWC_WRITE_REG32(&(in_regs->diepdma),
  82567. + (uint32_t) dwc_ep->iso_dma_desc_addr);
  82568. + }
  82569. + /** Enable endpoint, clear nak */
  82570. + depctl.d32 = 0;
  82571. + depctl.b.epena = 1;
  82572. + depctl.b.usbactep = 1;
  82573. + depctl.b.cnak = 1;
  82574. +
  82575. + DWC_MODIFY_REG32(addr, depctl.d32, depctl.d32);
  82576. + depctl.d32 = DWC_READ_REG32(addr);
  82577. +}
  82578. +
  82579. +/**
  82580. + * This function initializes a descriptor chain for Isochronous transfer
  82581. + *
  82582. + * @param core_if Programming view of DWC_otg controller.
  82583. + * @param ep The EP to start the transfer on.
  82584. + *
  82585. + */
  82586. +void dwc_otg_iso_ep_start_buf_transfer(dwc_otg_core_if_t * core_if,
  82587. + dwc_ep_t * ep)
  82588. +{
  82589. + depctl_data_t depctl = {.d32 = 0 };
  82590. + volatile uint32_t *addr;
  82591. +
  82592. + if (ep->is_in) {
  82593. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  82594. + } else {
  82595. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  82596. + }
  82597. +
  82598. + if (core_if->dma_enable == 0 || core_if->dma_desc_enable != 0) {
  82599. + return;
  82600. + } else {
  82601. + deptsiz_data_t deptsiz = {.d32 = 0 };
  82602. +
  82603. + ep->xfer_len =
  82604. + ep->data_per_frame * ep->buf_proc_intrvl / ep->bInterval;
  82605. + ep->pkt_cnt =
  82606. + (ep->xfer_len - 1 + ep->maxpacket) / ep->maxpacket;
  82607. + ep->xfer_count = 0;
  82608. + ep->xfer_buff =
  82609. + (ep->proc_buf_num) ? ep->xfer_buff1 : ep->xfer_buff0;
  82610. + ep->dma_addr =
  82611. + (ep->proc_buf_num) ? ep->dma_addr1 : ep->dma_addr0;
  82612. +
  82613. + if (ep->is_in) {
  82614. + /* Program the transfer size and packet count
  82615. + * as follows: xfersize = N * maxpacket +
  82616. + * short_packet pktcnt = N + (short_packet
  82617. + * exist ? 1 : 0)
  82618. + */
  82619. + deptsiz.b.mc = ep->pkt_per_frm;
  82620. + deptsiz.b.xfersize = ep->xfer_len;
  82621. + deptsiz.b.pktcnt =
  82622. + (ep->xfer_len - 1 + ep->maxpacket) / ep->maxpacket;
  82623. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  82624. + dieptsiz, deptsiz.d32);
  82625. +
  82626. + /* Write the DMA register */
  82627. + DWC_WRITE_REG32(&
  82628. + (core_if->dev_if->in_ep_regs[ep->num]->
  82629. + diepdma), (uint32_t) ep->dma_addr);
  82630. +
  82631. + } else {
  82632. + deptsiz.b.pktcnt =
  82633. + (ep->xfer_len + (ep->maxpacket - 1)) /
  82634. + ep->maxpacket;
  82635. + deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
  82636. +
  82637. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[ep->num]->
  82638. + doeptsiz, deptsiz.d32);
  82639. +
  82640. + /* Write the DMA register */
  82641. + DWC_WRITE_REG32(&
  82642. + (core_if->dev_if->out_ep_regs[ep->num]->
  82643. + doepdma), (uint32_t) ep->dma_addr);
  82644. +
  82645. + }
  82646. + /** Enable endpoint, clear nak */
  82647. + depctl.d32 = 0;
  82648. + depctl.b.epena = 1;
  82649. + depctl.b.cnak = 1;
  82650. +
  82651. + DWC_MODIFY_REG32(addr, depctl.d32, depctl.d32);
  82652. + }
  82653. +}
  82654. +
  82655. +/**
  82656. + * This function does the setup for a data transfer for an EP and
  82657. + * starts the transfer. For an IN transfer, the packets will be
  82658. + * loaded into the appropriate Tx FIFO in the ISR. For OUT transfers,
  82659. + * the packets are unloaded from the Rx FIFO in the ISR.
  82660. + *
  82661. + * @param core_if Programming view of DWC_otg controller.
  82662. + * @param ep The EP to start the transfer on.
  82663. + */
  82664. +
  82665. +static void dwc_otg_iso_ep_start_transfer(dwc_otg_core_if_t * core_if,
  82666. + dwc_ep_t * ep)
  82667. +{
  82668. + if (core_if->dma_enable) {
  82669. + if (core_if->dma_desc_enable) {
  82670. + if (ep->is_in) {
  82671. + ep->desc_cnt = ep->pkt_cnt / ep->pkt_per_frm;
  82672. + } else {
  82673. + ep->desc_cnt = ep->pkt_cnt;
  82674. + }
  82675. + dwc_otg_iso_ep_start_ddma_transfer(core_if, ep);
  82676. + } else {
  82677. + if (core_if->pti_enh_enable) {
  82678. + dwc_otg_iso_ep_start_buf_transfer(core_if, ep);
  82679. + } else {
  82680. + ep->cur_pkt_addr =
  82681. + (ep->proc_buf_num) ? ep->xfer_buff1 : ep->
  82682. + xfer_buff0;
  82683. + ep->cur_pkt_dma_addr =
  82684. + (ep->proc_buf_num) ? ep->dma_addr1 : ep->
  82685. + dma_addr0;
  82686. + dwc_otg_iso_ep_start_frm_transfer(core_if, ep);
  82687. + }
  82688. + }
  82689. + } else {
  82690. + ep->cur_pkt_addr =
  82691. + (ep->proc_buf_num) ? ep->xfer_buff1 : ep->xfer_buff0;
  82692. + ep->cur_pkt_dma_addr =
  82693. + (ep->proc_buf_num) ? ep->dma_addr1 : ep->dma_addr0;
  82694. + dwc_otg_iso_ep_start_frm_transfer(core_if, ep);
  82695. + }
  82696. +}
  82697. +
  82698. +/**
  82699. + * This function stops transfer for an EP and
  82700. + * resets the ep's variables.
  82701. + *
  82702. + * @param core_if Programming view of DWC_otg controller.
  82703. + * @param ep The EP to start the transfer on.
  82704. + */
  82705. +
  82706. +void dwc_otg_iso_ep_stop_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  82707. +{
  82708. + depctl_data_t depctl = {.d32 = 0 };
  82709. + volatile uint32_t *addr;
  82710. +
  82711. + if (ep->is_in == 1) {
  82712. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  82713. + } else {
  82714. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  82715. + }
  82716. +
  82717. + /* disable the ep */
  82718. + depctl.d32 = DWC_READ_REG32(addr);
  82719. +
  82720. + depctl.b.epdis = 1;
  82721. + depctl.b.snak = 1;
  82722. +
  82723. + DWC_WRITE_REG32(addr, depctl.d32);
  82724. +
  82725. + if (core_if->dma_desc_enable &&
  82726. + ep->iso_desc_addr && ep->iso_dma_desc_addr) {
  82727. + dwc_otg_ep_free_desc_chain(ep->iso_desc_addr,
  82728. + ep->iso_dma_desc_addr,
  82729. + ep->desc_cnt * 2);
  82730. + }
  82731. +
  82732. + /* reset varibales */
  82733. + ep->dma_addr0 = 0;
  82734. + ep->dma_addr1 = 0;
  82735. + ep->xfer_buff0 = 0;
  82736. + ep->xfer_buff1 = 0;
  82737. + ep->data_per_frame = 0;
  82738. + ep->data_pattern_frame = 0;
  82739. + ep->sync_frame = 0;
  82740. + ep->buf_proc_intrvl = 0;
  82741. + ep->bInterval = 0;
  82742. + ep->proc_buf_num = 0;
  82743. + ep->pkt_per_frm = 0;
  82744. + ep->pkt_per_frm = 0;
  82745. + ep->desc_cnt = 0;
  82746. + ep->iso_desc_addr = 0;
  82747. + ep->iso_dma_desc_addr = 0;
  82748. +}
  82749. +
  82750. +int dwc_otg_pcd_iso_ep_start(dwc_otg_pcd_t * pcd, void *ep_handle,
  82751. + uint8_t * buf0, uint8_t * buf1, dwc_dma_t dma0,
  82752. + dwc_dma_t dma1, int sync_frame, int dp_frame,
  82753. + int data_per_frame, int start_frame,
  82754. + int buf_proc_intrvl, void *req_handle,
  82755. + int atomic_alloc)
  82756. +{
  82757. + dwc_otg_pcd_ep_t *ep;
  82758. + dwc_irqflags_t flags = 0;
  82759. + dwc_ep_t *dwc_ep;
  82760. + int32_t frm_data;
  82761. + dsts_data_t dsts;
  82762. + dwc_otg_core_if_t *core_if;
  82763. +
  82764. + ep = get_ep_from_handle(pcd, ep_handle);
  82765. +
  82766. + if (!ep || !ep->desc || ep->dwc_ep.num == 0) {
  82767. + DWC_WARN("bad ep\n");
  82768. + return -DWC_E_INVALID;
  82769. + }
  82770. +
  82771. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  82772. + core_if = GET_CORE_IF(pcd);
  82773. + dwc_ep = &ep->dwc_ep;
  82774. +
  82775. + if (ep->iso_req_handle) {
  82776. + DWC_WARN("ISO request in progress\n");
  82777. + }
  82778. +
  82779. + dwc_ep->dma_addr0 = dma0;
  82780. + dwc_ep->dma_addr1 = dma1;
  82781. +
  82782. + dwc_ep->xfer_buff0 = buf0;
  82783. + dwc_ep->xfer_buff1 = buf1;
  82784. +
  82785. + dwc_ep->data_per_frame = data_per_frame;
  82786. +
  82787. + /** @todo - pattern data support is to be implemented in the future */
  82788. + dwc_ep->data_pattern_frame = dp_frame;
  82789. + dwc_ep->sync_frame = sync_frame;
  82790. +
  82791. + dwc_ep->buf_proc_intrvl = buf_proc_intrvl;
  82792. +
  82793. + dwc_ep->bInterval = 1 << (ep->desc->bInterval - 1);
  82794. +
  82795. + dwc_ep->proc_buf_num = 0;
  82796. +
  82797. + dwc_ep->pkt_per_frm = 0;
  82798. + frm_data = ep->dwc_ep.data_per_frame;
  82799. + while (frm_data > 0) {
  82800. + dwc_ep->pkt_per_frm++;
  82801. + frm_data -= ep->dwc_ep.maxpacket;
  82802. + }
  82803. +
  82804. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  82805. +
  82806. + if (start_frame == -1) {
  82807. + dwc_ep->next_frame = dsts.b.soffn + 1;
  82808. + if (dwc_ep->bInterval != 1) {
  82809. + dwc_ep->next_frame =
  82810. + dwc_ep->next_frame + (dwc_ep->bInterval - 1 -
  82811. + dwc_ep->next_frame %
  82812. + dwc_ep->bInterval);
  82813. + }
  82814. + } else {
  82815. + dwc_ep->next_frame = start_frame;
  82816. + }
  82817. +
  82818. + if (!core_if->pti_enh_enable) {
  82819. + dwc_ep->pkt_cnt =
  82820. + dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm /
  82821. + dwc_ep->bInterval;
  82822. + } else {
  82823. + dwc_ep->pkt_cnt =
  82824. + (dwc_ep->data_per_frame *
  82825. + (dwc_ep->buf_proc_intrvl / dwc_ep->bInterval)
  82826. + - 1 + dwc_ep->maxpacket) / dwc_ep->maxpacket;
  82827. + }
  82828. +
  82829. + if (core_if->dma_desc_enable) {
  82830. + dwc_ep->desc_cnt =
  82831. + dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm /
  82832. + dwc_ep->bInterval;
  82833. + }
  82834. +
  82835. + if (atomic_alloc) {
  82836. + dwc_ep->pkt_info =
  82837. + DWC_ALLOC_ATOMIC(sizeof(iso_pkt_info_t) * dwc_ep->pkt_cnt);
  82838. + } else {
  82839. + dwc_ep->pkt_info =
  82840. + DWC_ALLOC(sizeof(iso_pkt_info_t) * dwc_ep->pkt_cnt);
  82841. + }
  82842. + if (!dwc_ep->pkt_info) {
  82843. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  82844. + return -DWC_E_NO_MEMORY;
  82845. + }
  82846. + if (core_if->pti_enh_enable) {
  82847. + dwc_memset(dwc_ep->pkt_info, 0,
  82848. + sizeof(iso_pkt_info_t) * dwc_ep->pkt_cnt);
  82849. + }
  82850. +
  82851. + dwc_ep->cur_pkt = 0;
  82852. + ep->iso_req_handle = req_handle;
  82853. +
  82854. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  82855. + dwc_otg_iso_ep_start_transfer(core_if, dwc_ep);
  82856. + return 0;
  82857. +}
  82858. +
  82859. +int dwc_otg_pcd_iso_ep_stop(dwc_otg_pcd_t * pcd, void *ep_handle,
  82860. + void *req_handle)
  82861. +{
  82862. + dwc_irqflags_t flags = 0;
  82863. + dwc_otg_pcd_ep_t *ep;
  82864. + dwc_ep_t *dwc_ep;
  82865. +
  82866. + ep = get_ep_from_handle(pcd, ep_handle);
  82867. + if (!ep || !ep->desc || ep->dwc_ep.num == 0) {
  82868. + DWC_WARN("bad ep\n");
  82869. + return -DWC_E_INVALID;
  82870. + }
  82871. + dwc_ep = &ep->dwc_ep;
  82872. +
  82873. + dwc_otg_iso_ep_stop_transfer(GET_CORE_IF(pcd), dwc_ep);
  82874. +
  82875. + DWC_FREE(dwc_ep->pkt_info);
  82876. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  82877. + if (ep->iso_req_handle != req_handle) {
  82878. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  82879. + return -DWC_E_INVALID;
  82880. + }
  82881. +
  82882. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  82883. +
  82884. + ep->iso_req_handle = 0;
  82885. + return 0;
  82886. +}
  82887. +
  82888. +/**
  82889. + * This function is used for perodical data exchnage between PCD and gadget drivers.
  82890. + * for Isochronous EPs
  82891. + *
  82892. + * - Every time a sync period completes this function is called to
  82893. + * perform data exchange between PCD and gadget
  82894. + */
  82895. +void dwc_otg_iso_buffer_done(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep,
  82896. + void *req_handle)
  82897. +{
  82898. + int i;
  82899. + dwc_ep_t *dwc_ep;
  82900. +
  82901. + dwc_ep = &ep->dwc_ep;
  82902. +
  82903. + DWC_SPINUNLOCK(ep->pcd->lock);
  82904. + pcd->fops->isoc_complete(pcd, ep->priv, ep->iso_req_handle,
  82905. + dwc_ep->proc_buf_num ^ 0x1);
  82906. + DWC_SPINLOCK(ep->pcd->lock);
  82907. +
  82908. + for (i = 0; i < dwc_ep->pkt_cnt; ++i) {
  82909. + dwc_ep->pkt_info[i].status = 0;
  82910. + dwc_ep->pkt_info[i].offset = 0;
  82911. + dwc_ep->pkt_info[i].length = 0;
  82912. + }
  82913. +}
  82914. +
  82915. +int dwc_otg_pcd_get_iso_packet_count(dwc_otg_pcd_t * pcd, void *ep_handle,
  82916. + void *iso_req_handle)
  82917. +{
  82918. + dwc_otg_pcd_ep_t *ep;
  82919. + dwc_ep_t *dwc_ep;
  82920. +
  82921. + ep = get_ep_from_handle(pcd, ep_handle);
  82922. + if (!ep->desc || ep->dwc_ep.num == 0) {
  82923. + DWC_WARN("bad ep\n");
  82924. + return -DWC_E_INVALID;
  82925. + }
  82926. + dwc_ep = &ep->dwc_ep;
  82927. +
  82928. + return dwc_ep->pkt_cnt;
  82929. +}
  82930. +
  82931. +void dwc_otg_pcd_get_iso_packet_params(dwc_otg_pcd_t * pcd, void *ep_handle,
  82932. + void *iso_req_handle, int packet,
  82933. + int *status, int *actual, int *offset)
  82934. +{
  82935. + dwc_otg_pcd_ep_t *ep;
  82936. + dwc_ep_t *dwc_ep;
  82937. +
  82938. + ep = get_ep_from_handle(pcd, ep_handle);
  82939. + if (!ep)
  82940. + DWC_WARN("bad ep\n");
  82941. +
  82942. + dwc_ep = &ep->dwc_ep;
  82943. +
  82944. + *status = dwc_ep->pkt_info[packet].status;
  82945. + *actual = dwc_ep->pkt_info[packet].length;
  82946. + *offset = dwc_ep->pkt_info[packet].offset;
  82947. +}
  82948. +
  82949. +#endif /* DWC_EN_ISOC */
  82950. +
  82951. +static void dwc_otg_pcd_init_ep(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * pcd_ep,
  82952. + uint32_t is_in, uint32_t ep_num)
  82953. +{
  82954. + /* Init EP structure */
  82955. + pcd_ep->desc = 0;
  82956. + pcd_ep->pcd = pcd;
  82957. + pcd_ep->stopped = 1;
  82958. + pcd_ep->queue_sof = 0;
  82959. +
  82960. + /* Init DWC ep structure */
  82961. + pcd_ep->dwc_ep.is_in = is_in;
  82962. + pcd_ep->dwc_ep.num = ep_num;
  82963. + pcd_ep->dwc_ep.active = 0;
  82964. + pcd_ep->dwc_ep.tx_fifo_num = 0;
  82965. + /* Control until ep is actvated */
  82966. + pcd_ep->dwc_ep.type = DWC_OTG_EP_TYPE_CONTROL;
  82967. + pcd_ep->dwc_ep.maxpacket = MAX_PACKET_SIZE;
  82968. + pcd_ep->dwc_ep.dma_addr = 0;
  82969. + pcd_ep->dwc_ep.start_xfer_buff = 0;
  82970. + pcd_ep->dwc_ep.xfer_buff = 0;
  82971. + pcd_ep->dwc_ep.xfer_len = 0;
  82972. + pcd_ep->dwc_ep.xfer_count = 0;
  82973. + pcd_ep->dwc_ep.sent_zlp = 0;
  82974. + pcd_ep->dwc_ep.total_len = 0;
  82975. + pcd_ep->dwc_ep.desc_addr = 0;
  82976. + pcd_ep->dwc_ep.dma_desc_addr = 0;
  82977. + DWC_CIRCLEQ_INIT(&pcd_ep->queue);
  82978. +}
  82979. +
  82980. +/**
  82981. + * Initialize ep's
  82982. + */
  82983. +static void dwc_otg_pcd_reinit(dwc_otg_pcd_t * pcd)
  82984. +{
  82985. + int i;
  82986. + uint32_t hwcfg1;
  82987. + dwc_otg_pcd_ep_t *ep;
  82988. + int in_ep_cntr, out_ep_cntr;
  82989. + uint32_t num_in_eps = (GET_CORE_IF(pcd))->dev_if->num_in_eps;
  82990. + uint32_t num_out_eps = (GET_CORE_IF(pcd))->dev_if->num_out_eps;
  82991. +
  82992. + /**
  82993. + * Initialize the EP0 structure.
  82994. + */
  82995. + ep = &pcd->ep0;
  82996. + dwc_otg_pcd_init_ep(pcd, ep, 0, 0);
  82997. +
  82998. + in_ep_cntr = 0;
  82999. + hwcfg1 = (GET_CORE_IF(pcd))->hwcfg1.d32 >> 3;
  83000. + for (i = 1; in_ep_cntr < num_in_eps; i++) {
  83001. + if ((hwcfg1 & 0x1) == 0) {
  83002. + dwc_otg_pcd_ep_t *ep = &pcd->in_ep[in_ep_cntr];
  83003. + in_ep_cntr++;
  83004. + /**
  83005. + * @todo NGS: Add direction to EP, based on contents
  83006. + * of HWCFG1. Need a copy of HWCFG1 in pcd structure?
  83007. + * sprintf(";r
  83008. + */
  83009. + dwc_otg_pcd_init_ep(pcd, ep, 1 /* IN */ , i);
  83010. +
  83011. + DWC_CIRCLEQ_INIT(&ep->queue);
  83012. + }
  83013. + hwcfg1 >>= 2;
  83014. + }
  83015. +
  83016. + out_ep_cntr = 0;
  83017. + hwcfg1 = (GET_CORE_IF(pcd))->hwcfg1.d32 >> 2;
  83018. + for (i = 1; out_ep_cntr < num_out_eps; i++) {
  83019. + if ((hwcfg1 & 0x1) == 0) {
  83020. + dwc_otg_pcd_ep_t *ep = &pcd->out_ep[out_ep_cntr];
  83021. + out_ep_cntr++;
  83022. + /**
  83023. + * @todo NGS: Add direction to EP, based on contents
  83024. + * of HWCFG1. Need a copy of HWCFG1 in pcd structure?
  83025. + * sprintf(";r
  83026. + */
  83027. + dwc_otg_pcd_init_ep(pcd, ep, 0 /* OUT */ , i);
  83028. + DWC_CIRCLEQ_INIT(&ep->queue);
  83029. + }
  83030. + hwcfg1 >>= 2;
  83031. + }
  83032. +
  83033. + pcd->ep0state = EP0_DISCONNECT;
  83034. + pcd->ep0.dwc_ep.maxpacket = MAX_EP0_SIZE;
  83035. + pcd->ep0.dwc_ep.type = DWC_OTG_EP_TYPE_CONTROL;
  83036. +}
  83037. +
  83038. +/**
  83039. + * This function is called when the SRP timer expires. The SRP should
  83040. + * complete within 6 seconds.
  83041. + */
  83042. +static void srp_timeout(void *ptr)
  83043. +{
  83044. + gotgctl_data_t gotgctl;
  83045. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  83046. + volatile uint32_t *addr = &core_if->core_global_regs->gotgctl;
  83047. +
  83048. + gotgctl.d32 = DWC_READ_REG32(addr);
  83049. +
  83050. + core_if->srp_timer_started = 0;
  83051. +
  83052. + if (core_if->adp_enable) {
  83053. + if (gotgctl.b.bsesvld == 0) {
  83054. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  83055. + DWC_PRINTF("SRP Timeout BSESSVLD = 0\n");
  83056. + /* Power off the core */
  83057. + if (core_if->power_down == 2) {
  83058. + gpwrdn.b.pwrdnswtch = 1;
  83059. + DWC_MODIFY_REG32(&core_if->
  83060. + core_global_regs->gpwrdn,
  83061. + gpwrdn.d32, 0);
  83062. + }
  83063. +
  83064. + gpwrdn.d32 = 0;
  83065. + gpwrdn.b.pmuintsel = 1;
  83066. + gpwrdn.b.pmuactv = 1;
  83067. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  83068. + gpwrdn.d32);
  83069. + dwc_otg_adp_probe_start(core_if);
  83070. + } else {
  83071. + DWC_PRINTF("SRP Timeout BSESSVLD = 1\n");
  83072. + core_if->op_state = B_PERIPHERAL;
  83073. + dwc_otg_core_init(core_if);
  83074. + dwc_otg_enable_global_interrupts(core_if);
  83075. + cil_pcd_start(core_if);
  83076. + }
  83077. + }
  83078. +
  83079. + if ((core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS) &&
  83080. + (core_if->core_params->i2c_enable)) {
  83081. + DWC_PRINTF("SRP Timeout\n");
  83082. +
  83083. + if ((core_if->srp_success) && (gotgctl.b.bsesvld)) {
  83084. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  83085. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  83086. + }
  83087. +
  83088. + /* Clear Session Request */
  83089. + gotgctl.d32 = 0;
  83090. + gotgctl.b.sesreq = 1;
  83091. + DWC_MODIFY_REG32(&core_if->core_global_regs->gotgctl,
  83092. + gotgctl.d32, 0);
  83093. +
  83094. + core_if->srp_success = 0;
  83095. + } else {
  83096. + __DWC_ERROR("Device not connected/responding\n");
  83097. + gotgctl.b.sesreq = 0;
  83098. + DWC_WRITE_REG32(addr, gotgctl.d32);
  83099. + }
  83100. + } else if (gotgctl.b.sesreq) {
  83101. + DWC_PRINTF("SRP Timeout\n");
  83102. +
  83103. + __DWC_ERROR("Device not connected/responding\n");
  83104. + gotgctl.b.sesreq = 0;
  83105. + DWC_WRITE_REG32(addr, gotgctl.d32);
  83106. + } else {
  83107. + DWC_PRINTF(" SRP GOTGCTL=%0x\n", gotgctl.d32);
  83108. + }
  83109. +}
  83110. +
  83111. +/**
  83112. + * Tasklet
  83113. + *
  83114. + */
  83115. +extern void start_next_request(dwc_otg_pcd_ep_t * ep);
  83116. +
  83117. +static void start_xfer_tasklet_func(void *data)
  83118. +{
  83119. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) data;
  83120. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  83121. +
  83122. + int i;
  83123. + depctl_data_t diepctl;
  83124. +
  83125. + DWC_DEBUGPL(DBG_PCDV, "Start xfer tasklet\n");
  83126. +
  83127. + diepctl.d32 = DWC_READ_REG32(&core_if->dev_if->in_ep_regs[0]->diepctl);
  83128. +
  83129. + if (pcd->ep0.queue_sof) {
  83130. + pcd->ep0.queue_sof = 0;
  83131. + start_next_request(&pcd->ep0);
  83132. + // break;
  83133. + }
  83134. +
  83135. + for (i = 0; i < core_if->dev_if->num_in_eps; i++) {
  83136. + depctl_data_t diepctl;
  83137. + diepctl.d32 =
  83138. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->diepctl);
  83139. +
  83140. + if (pcd->in_ep[i].queue_sof) {
  83141. + pcd->in_ep[i].queue_sof = 0;
  83142. + start_next_request(&pcd->in_ep[i]);
  83143. + // break;
  83144. + }
  83145. + }
  83146. +
  83147. + return;
  83148. +}
  83149. +
  83150. +/**
  83151. + * This function initialized the PCD portion of the driver.
  83152. + *
  83153. + */
  83154. +dwc_otg_pcd_t *dwc_otg_pcd_init(dwc_otg_core_if_t * core_if)
  83155. +{
  83156. + dwc_otg_pcd_t *pcd = NULL;
  83157. + dwc_otg_dev_if_t *dev_if;
  83158. + int i;
  83159. +
  83160. + /*
  83161. + * Allocate PCD structure
  83162. + */
  83163. + pcd = DWC_ALLOC(sizeof(dwc_otg_pcd_t));
  83164. +
  83165. + if (pcd == NULL) {
  83166. + return NULL;
  83167. + }
  83168. +
  83169. + pcd->lock = DWC_SPINLOCK_ALLOC();
  83170. + DWC_DEBUGPL(DBG_HCDV, "Init of PCD %p given core_if %p\n",
  83171. + pcd, core_if);//GRAYG
  83172. + if (!pcd->lock) {
  83173. + DWC_ERROR("Could not allocate lock for pcd");
  83174. + DWC_FREE(pcd);
  83175. + return NULL;
  83176. + }
  83177. + /* Set core_if's lock pointer to hcd->lock */
  83178. + core_if->lock = pcd->lock;
  83179. + pcd->core_if = core_if;
  83180. +
  83181. + dev_if = core_if->dev_if;
  83182. + dev_if->isoc_ep = NULL;
  83183. +
  83184. + if (core_if->hwcfg4.b.ded_fifo_en) {
  83185. + DWC_PRINTF("Dedicated Tx FIFOs mode\n");
  83186. + } else {
  83187. + DWC_PRINTF("Shared Tx FIFO mode\n");
  83188. + }
  83189. +
  83190. + /*
  83191. + * Initialized the Core for Device mode here if there is nod ADP support.
  83192. + * Otherwise it will be done later in dwc_otg_adp_start routine.
  83193. + */
  83194. + if (dwc_otg_is_device_mode(core_if) /*&& !core_if->adp_enable*/) {
  83195. + dwc_otg_core_dev_init(core_if);
  83196. + }
  83197. +
  83198. + /*
  83199. + * Register the PCD Callbacks.
  83200. + */
  83201. + dwc_otg_cil_register_pcd_callbacks(core_if, &pcd_callbacks, pcd);
  83202. +
  83203. + /*
  83204. + * Initialize the DMA buffer for SETUP packets
  83205. + */
  83206. + if (GET_CORE_IF(pcd)->dma_enable) {
  83207. + pcd->setup_pkt =
  83208. + DWC_DMA_ALLOC(sizeof(*pcd->setup_pkt) * 5,
  83209. + &pcd->setup_pkt_dma_handle);
  83210. + if (pcd->setup_pkt == NULL) {
  83211. + DWC_FREE(pcd);
  83212. + return NULL;
  83213. + }
  83214. +
  83215. + pcd->status_buf =
  83216. + DWC_DMA_ALLOC(sizeof(uint16_t),
  83217. + &pcd->status_buf_dma_handle);
  83218. + if (pcd->status_buf == NULL) {
  83219. + DWC_DMA_FREE(sizeof(*pcd->setup_pkt) * 5,
  83220. + pcd->setup_pkt, pcd->setup_pkt_dma_handle);
  83221. + DWC_FREE(pcd);
  83222. + return NULL;
  83223. + }
  83224. +
  83225. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  83226. + dev_if->setup_desc_addr[0] =
  83227. + dwc_otg_ep_alloc_desc_chain
  83228. + (&dev_if->dma_setup_desc_addr[0], 1);
  83229. + dev_if->setup_desc_addr[1] =
  83230. + dwc_otg_ep_alloc_desc_chain
  83231. + (&dev_if->dma_setup_desc_addr[1], 1);
  83232. + dev_if->in_desc_addr =
  83233. + dwc_otg_ep_alloc_desc_chain
  83234. + (&dev_if->dma_in_desc_addr, 1);
  83235. + dev_if->out_desc_addr =
  83236. + dwc_otg_ep_alloc_desc_chain
  83237. + (&dev_if->dma_out_desc_addr, 1);
  83238. + pcd->data_terminated = 0;
  83239. +
  83240. + if (dev_if->setup_desc_addr[0] == 0
  83241. + || dev_if->setup_desc_addr[1] == 0
  83242. + || dev_if->in_desc_addr == 0
  83243. + || dev_if->out_desc_addr == 0) {
  83244. +
  83245. + if (dev_if->out_desc_addr)
  83246. + dwc_otg_ep_free_desc_chain
  83247. + (dev_if->out_desc_addr,
  83248. + dev_if->dma_out_desc_addr, 1);
  83249. + if (dev_if->in_desc_addr)
  83250. + dwc_otg_ep_free_desc_chain
  83251. + (dev_if->in_desc_addr,
  83252. + dev_if->dma_in_desc_addr, 1);
  83253. + if (dev_if->setup_desc_addr[1])
  83254. + dwc_otg_ep_free_desc_chain
  83255. + (dev_if->setup_desc_addr[1],
  83256. + dev_if->dma_setup_desc_addr[1], 1);
  83257. + if (dev_if->setup_desc_addr[0])
  83258. + dwc_otg_ep_free_desc_chain
  83259. + (dev_if->setup_desc_addr[0],
  83260. + dev_if->dma_setup_desc_addr[0], 1);
  83261. +
  83262. + DWC_DMA_FREE(sizeof(*pcd->setup_pkt) * 5,
  83263. + pcd->setup_pkt,
  83264. + pcd->setup_pkt_dma_handle);
  83265. + DWC_DMA_FREE(sizeof(*pcd->status_buf),
  83266. + pcd->status_buf,
  83267. + pcd->status_buf_dma_handle);
  83268. +
  83269. + DWC_FREE(pcd);
  83270. +
  83271. + return NULL;
  83272. + }
  83273. + }
  83274. + } else {
  83275. + pcd->setup_pkt = DWC_ALLOC(sizeof(*pcd->setup_pkt) * 5);
  83276. + if (pcd->setup_pkt == NULL) {
  83277. + DWC_FREE(pcd);
  83278. + return NULL;
  83279. + }
  83280. +
  83281. + pcd->status_buf = DWC_ALLOC(sizeof(uint16_t));
  83282. + if (pcd->status_buf == NULL) {
  83283. + DWC_FREE(pcd->setup_pkt);
  83284. + DWC_FREE(pcd);
  83285. + return NULL;
  83286. + }
  83287. + }
  83288. +
  83289. + dwc_otg_pcd_reinit(pcd);
  83290. +
  83291. + /* Allocate the cfi object for the PCD */
  83292. +#ifdef DWC_UTE_CFI
  83293. + pcd->cfi = DWC_ALLOC(sizeof(cfiobject_t));
  83294. + if (NULL == pcd->cfi)
  83295. + goto fail;
  83296. + if (init_cfi(pcd->cfi)) {
  83297. + CFI_INFO("%s: Failed to init the CFI object\n", __func__);
  83298. + goto fail;
  83299. + }
  83300. +#endif
  83301. +
  83302. + /* Initialize tasklets */
  83303. + pcd->start_xfer_tasklet = DWC_TASK_ALLOC("xfer_tasklet",
  83304. + start_xfer_tasklet_func, pcd);
  83305. + pcd->test_mode_tasklet = DWC_TASK_ALLOC("test_mode_tasklet",
  83306. + do_test_mode, pcd);
  83307. +
  83308. + /* Initialize SRP timer */
  83309. + core_if->srp_timer = DWC_TIMER_ALLOC("SRP TIMER", srp_timeout, core_if);
  83310. +
  83311. + if (core_if->core_params->dev_out_nak) {
  83312. + /**
  83313. + * Initialize xfer timeout timer. Implemented for
  83314. + * 2.93a feature "Device DDMA OUT NAK Enhancement"
  83315. + */
  83316. + for(i = 0; i < MAX_EPS_CHANNELS; i++) {
  83317. + pcd->core_if->ep_xfer_timer[i] =
  83318. + DWC_TIMER_ALLOC("ep timer", ep_xfer_timeout,
  83319. + &pcd->core_if->ep_xfer_info[i]);
  83320. + }
  83321. + }
  83322. +
  83323. + return pcd;
  83324. +#ifdef DWC_UTE_CFI
  83325. +fail:
  83326. +#endif
  83327. + if (pcd->setup_pkt)
  83328. + DWC_FREE(pcd->setup_pkt);
  83329. + if (pcd->status_buf)
  83330. + DWC_FREE(pcd->status_buf);
  83331. +#ifdef DWC_UTE_CFI
  83332. + if (pcd->cfi)
  83333. + DWC_FREE(pcd->cfi);
  83334. +#endif
  83335. + if (pcd)
  83336. + DWC_FREE(pcd);
  83337. + return NULL;
  83338. +
  83339. +}
  83340. +
  83341. +/**
  83342. + * Remove PCD specific data
  83343. + */
  83344. +void dwc_otg_pcd_remove(dwc_otg_pcd_t * pcd)
  83345. +{
  83346. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  83347. + int i;
  83348. + if (pcd->core_if->core_params->dev_out_nak) {
  83349. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  83350. + DWC_TIMER_CANCEL(pcd->core_if->ep_xfer_timer[i]);
  83351. + pcd->core_if->ep_xfer_info[i].state = 0;
  83352. + }
  83353. + }
  83354. +
  83355. + if (GET_CORE_IF(pcd)->dma_enable) {
  83356. + DWC_DMA_FREE(sizeof(*pcd->setup_pkt) * 5, pcd->setup_pkt,
  83357. + pcd->setup_pkt_dma_handle);
  83358. + DWC_DMA_FREE(sizeof(uint16_t), pcd->status_buf,
  83359. + pcd->status_buf_dma_handle);
  83360. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  83361. + dwc_otg_ep_free_desc_chain(dev_if->setup_desc_addr[0],
  83362. + dev_if->dma_setup_desc_addr
  83363. + [0], 1);
  83364. + dwc_otg_ep_free_desc_chain(dev_if->setup_desc_addr[1],
  83365. + dev_if->dma_setup_desc_addr
  83366. + [1], 1);
  83367. + dwc_otg_ep_free_desc_chain(dev_if->in_desc_addr,
  83368. + dev_if->dma_in_desc_addr, 1);
  83369. + dwc_otg_ep_free_desc_chain(dev_if->out_desc_addr,
  83370. + dev_if->dma_out_desc_addr,
  83371. + 1);
  83372. + }
  83373. + } else {
  83374. + DWC_FREE(pcd->setup_pkt);
  83375. + DWC_FREE(pcd->status_buf);
  83376. + }
  83377. + DWC_SPINLOCK_FREE(pcd->lock);
  83378. + /* Set core_if's lock pointer to NULL */
  83379. + pcd->core_if->lock = NULL;
  83380. +
  83381. + DWC_TASK_FREE(pcd->start_xfer_tasklet);
  83382. + DWC_TASK_FREE(pcd->test_mode_tasklet);
  83383. + if (pcd->core_if->core_params->dev_out_nak) {
  83384. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  83385. + if (pcd->core_if->ep_xfer_timer[i]) {
  83386. + DWC_TIMER_FREE(pcd->core_if->ep_xfer_timer[i]);
  83387. + }
  83388. + }
  83389. + }
  83390. +
  83391. +/* Release the CFI object's dynamic memory */
  83392. +#ifdef DWC_UTE_CFI
  83393. + if (pcd->cfi->ops.release) {
  83394. + pcd->cfi->ops.release(pcd->cfi);
  83395. + }
  83396. +#endif
  83397. +
  83398. + DWC_FREE(pcd);
  83399. +}
  83400. +
  83401. +/**
  83402. + * Returns whether registered pcd is dual speed or not
  83403. + */
  83404. +uint32_t dwc_otg_pcd_is_dualspeed(dwc_otg_pcd_t * pcd)
  83405. +{
  83406. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  83407. +
  83408. + if ((core_if->core_params->speed == DWC_SPEED_PARAM_FULL) ||
  83409. + ((core_if->hwcfg2.b.hs_phy_type == 2) &&
  83410. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  83411. + (core_if->core_params->ulpi_fs_ls))) {
  83412. + return 0;
  83413. + }
  83414. +
  83415. + return 1;
  83416. +}
  83417. +
  83418. +/**
  83419. + * Returns whether registered pcd is OTG capable or not
  83420. + */
  83421. +uint32_t dwc_otg_pcd_is_otg(dwc_otg_pcd_t * pcd)
  83422. +{
  83423. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  83424. + gusbcfg_data_t usbcfg = {.d32 = 0 };
  83425. +
  83426. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  83427. + if (!usbcfg.b.srpcap || !usbcfg.b.hnpcap) {
  83428. + return 0;
  83429. + }
  83430. +
  83431. + return 1;
  83432. +}
  83433. +
  83434. +/**
  83435. + * This function assigns periodic Tx FIFO to an periodic EP
  83436. + * in shared Tx FIFO mode
  83437. + */
  83438. +static uint32_t assign_tx_fifo(dwc_otg_core_if_t * core_if)
  83439. +{
  83440. + uint32_t TxMsk = 1;
  83441. + int i;
  83442. +
  83443. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; ++i) {
  83444. + if ((TxMsk & core_if->tx_msk) == 0) {
  83445. + core_if->tx_msk |= TxMsk;
  83446. + return i + 1;
  83447. + }
  83448. + TxMsk <<= 1;
  83449. + }
  83450. + return 0;
  83451. +}
  83452. +
  83453. +/**
  83454. + * This function assigns periodic Tx FIFO to an periodic EP
  83455. + * in shared Tx FIFO mode
  83456. + */
  83457. +static uint32_t assign_perio_tx_fifo(dwc_otg_core_if_t * core_if)
  83458. +{
  83459. + uint32_t PerTxMsk = 1;
  83460. + int i;
  83461. + for (i = 0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; ++i) {
  83462. + if ((PerTxMsk & core_if->p_tx_msk) == 0) {
  83463. + core_if->p_tx_msk |= PerTxMsk;
  83464. + return i + 1;
  83465. + }
  83466. + PerTxMsk <<= 1;
  83467. + }
  83468. + return 0;
  83469. +}
  83470. +
  83471. +/**
  83472. + * This function releases periodic Tx FIFO
  83473. + * in shared Tx FIFO mode
  83474. + */
  83475. +static void release_perio_tx_fifo(dwc_otg_core_if_t * core_if,
  83476. + uint32_t fifo_num)
  83477. +{
  83478. + core_if->p_tx_msk =
  83479. + (core_if->p_tx_msk & (1 << (fifo_num - 1))) ^ core_if->p_tx_msk;
  83480. +}
  83481. +
  83482. +/**
  83483. + * This function releases periodic Tx FIFO
  83484. + * in shared Tx FIFO mode
  83485. + */
  83486. +static void release_tx_fifo(dwc_otg_core_if_t * core_if, uint32_t fifo_num)
  83487. +{
  83488. + core_if->tx_msk =
  83489. + (core_if->tx_msk & (1 << (fifo_num - 1))) ^ core_if->tx_msk;
  83490. +}
  83491. +
  83492. +/**
  83493. + * This function is being called from gadget
  83494. + * to enable PCD endpoint.
  83495. + */
  83496. +int dwc_otg_pcd_ep_enable(dwc_otg_pcd_t * pcd,
  83497. + const uint8_t * ep_desc, void *usb_ep)
  83498. +{
  83499. + int num, dir;
  83500. + dwc_otg_pcd_ep_t *ep = NULL;
  83501. + const usb_endpoint_descriptor_t *desc;
  83502. + dwc_irqflags_t flags;
  83503. + fifosize_data_t dptxfsiz = {.d32 = 0 };
  83504. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  83505. + gdfifocfg_data_t gdfifocfgbase = {.d32 = 0 };
  83506. + int retval = 0;
  83507. + int i, epcount;
  83508. +
  83509. + desc = (const usb_endpoint_descriptor_t *)ep_desc;
  83510. +
  83511. + if (!desc) {
  83512. + pcd->ep0.priv = usb_ep;
  83513. + ep = &pcd->ep0;
  83514. + retval = -DWC_E_INVALID;
  83515. + goto out;
  83516. + }
  83517. +
  83518. + num = UE_GET_ADDR(desc->bEndpointAddress);
  83519. + dir = UE_GET_DIR(desc->bEndpointAddress);
  83520. +
  83521. + if (!desc->wMaxPacketSize) {
  83522. + DWC_WARN("bad maxpacketsize\n");
  83523. + retval = -DWC_E_INVALID;
  83524. + goto out;
  83525. + }
  83526. +
  83527. + if (dir == UE_DIR_IN) {
  83528. + epcount = pcd->core_if->dev_if->num_in_eps;
  83529. + for (i = 0; i < epcount; i++) {
  83530. + if (num == pcd->in_ep[i].dwc_ep.num) {
  83531. + ep = &pcd->in_ep[i];
  83532. + break;
  83533. + }
  83534. + }
  83535. + } else {
  83536. + epcount = pcd->core_if->dev_if->num_out_eps;
  83537. + for (i = 0; i < epcount; i++) {
  83538. + if (num == pcd->out_ep[i].dwc_ep.num) {
  83539. + ep = &pcd->out_ep[i];
  83540. + break;
  83541. + }
  83542. + }
  83543. + }
  83544. +
  83545. + if (!ep) {
  83546. + DWC_WARN("bad address\n");
  83547. + retval = -DWC_E_INVALID;
  83548. + goto out;
  83549. + }
  83550. +
  83551. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  83552. +
  83553. + ep->desc = desc;
  83554. + ep->priv = usb_ep;
  83555. +
  83556. + /*
  83557. + * Activate the EP
  83558. + */
  83559. + ep->stopped = 0;
  83560. +
  83561. + ep->dwc_ep.is_in = (dir == UE_DIR_IN);
  83562. + ep->dwc_ep.maxpacket = UGETW(desc->wMaxPacketSize);
  83563. +
  83564. + ep->dwc_ep.type = desc->bmAttributes & UE_XFERTYPE;
  83565. +
  83566. + if (ep->dwc_ep.is_in) {
  83567. + if (!GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  83568. + ep->dwc_ep.tx_fifo_num = 0;
  83569. +
  83570. + if (ep->dwc_ep.type == UE_ISOCHRONOUS) {
  83571. + /*
  83572. + * if ISOC EP then assign a Periodic Tx FIFO.
  83573. + */
  83574. + ep->dwc_ep.tx_fifo_num =
  83575. + assign_perio_tx_fifo(GET_CORE_IF(pcd));
  83576. + }
  83577. + } else {
  83578. + /*
  83579. + * if Dedicated FIFOs mode is on then assign a Tx FIFO.
  83580. + */
  83581. + ep->dwc_ep.tx_fifo_num =
  83582. + assign_tx_fifo(GET_CORE_IF(pcd));
  83583. + }
  83584. +
  83585. + /* Calculating EP info controller base address */
  83586. + if (ep->dwc_ep.tx_fifo_num
  83587. + && GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  83588. + gdfifocfg.d32 =
  83589. + DWC_READ_REG32(&GET_CORE_IF(pcd)->
  83590. + core_global_regs->gdfifocfg);
  83591. + gdfifocfgbase.d32 = gdfifocfg.d32 >> 16;
  83592. + dptxfsiz.d32 =
  83593. + (DWC_READ_REG32
  83594. + (&GET_CORE_IF(pcd)->core_global_regs->
  83595. + dtxfsiz[ep->dwc_ep.tx_fifo_num - 1]) >> 16);
  83596. + gdfifocfg.b.epinfobase =
  83597. + gdfifocfgbase.d32 + dptxfsiz.d32;
  83598. + if (GET_CORE_IF(pcd)->snpsid <= OTG_CORE_REV_2_94a) {
  83599. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->
  83600. + core_global_regs->gdfifocfg,
  83601. + gdfifocfg.d32);
  83602. + }
  83603. + }
  83604. + }
  83605. + /* Set initial data PID. */
  83606. + if (ep->dwc_ep.type == UE_BULK) {
  83607. + ep->dwc_ep.data_pid_start = 0;
  83608. + }
  83609. +
  83610. + /* Alloc DMA Descriptors */
  83611. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  83612. +#ifndef DWC_UTE_PER_IO
  83613. + if (ep->dwc_ep.type != UE_ISOCHRONOUS) {
  83614. +#endif
  83615. + ep->dwc_ep.desc_addr =
  83616. + dwc_otg_ep_alloc_desc_chain(&ep->
  83617. + dwc_ep.dma_desc_addr,
  83618. + MAX_DMA_DESC_CNT);
  83619. + if (!ep->dwc_ep.desc_addr) {
  83620. + DWC_WARN("%s, can't allocate DMA descriptor\n",
  83621. + __func__);
  83622. + retval = -DWC_E_SHUTDOWN;
  83623. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  83624. + goto out;
  83625. + }
  83626. +#ifndef DWC_UTE_PER_IO
  83627. + }
  83628. +#endif
  83629. + }
  83630. +
  83631. + DWC_DEBUGPL(DBG_PCD, "Activate %s: type=%d, mps=%d desc=%p\n",
  83632. + (ep->dwc_ep.is_in ? "IN" : "OUT"),
  83633. + ep->dwc_ep.type, ep->dwc_ep.maxpacket, ep->desc);
  83634. +#ifdef DWC_UTE_PER_IO
  83635. + ep->dwc_ep.xiso_bInterval = 1 << (ep->desc->bInterval - 1);
  83636. +#endif
  83637. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  83638. + ep->dwc_ep.bInterval = 1 << (ep->desc->bInterval - 1);
  83639. + ep->dwc_ep.frame_num = 0xFFFFFFFF;
  83640. + }
  83641. +
  83642. + dwc_otg_ep_activate(GET_CORE_IF(pcd), &ep->dwc_ep);
  83643. +
  83644. +#ifdef DWC_UTE_CFI
  83645. + if (pcd->cfi->ops.ep_enable) {
  83646. + pcd->cfi->ops.ep_enable(pcd->cfi, pcd, ep);
  83647. + }
  83648. +#endif
  83649. +
  83650. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  83651. +
  83652. +out:
  83653. + return retval;
  83654. +}
  83655. +
  83656. +/**
  83657. + * This function is being called from gadget
  83658. + * to disable PCD endpoint.
  83659. + */
  83660. +int dwc_otg_pcd_ep_disable(dwc_otg_pcd_t * pcd, void *ep_handle)
  83661. +{
  83662. + dwc_otg_pcd_ep_t *ep;
  83663. + dwc_irqflags_t flags;
  83664. + dwc_otg_dev_dma_desc_t *desc_addr;
  83665. + dwc_dma_t dma_desc_addr;
  83666. + gdfifocfg_data_t gdfifocfgbase = {.d32 = 0 };
  83667. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  83668. + fifosize_data_t dptxfsiz = {.d32 = 0 };
  83669. +
  83670. + ep = get_ep_from_handle(pcd, ep_handle);
  83671. +
  83672. + if (!ep || !ep->desc) {
  83673. + DWC_DEBUGPL(DBG_PCD, "bad ep address\n");
  83674. + return -DWC_E_INVALID;
  83675. + }
  83676. +
  83677. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  83678. +
  83679. + dwc_otg_request_nuke(ep);
  83680. +
  83681. + dwc_otg_ep_deactivate(GET_CORE_IF(pcd), &ep->dwc_ep);
  83682. + if (pcd->core_if->core_params->dev_out_nak) {
  83683. + DWC_TIMER_CANCEL(pcd->core_if->ep_xfer_timer[ep->dwc_ep.num]);
  83684. + pcd->core_if->ep_xfer_info[ep->dwc_ep.num].state = 0;
  83685. + }
  83686. + ep->desc = NULL;
  83687. + ep->stopped = 1;
  83688. +
  83689. + gdfifocfg.d32 =
  83690. + DWC_READ_REG32(&GET_CORE_IF(pcd)->core_global_regs->gdfifocfg);
  83691. + gdfifocfgbase.d32 = gdfifocfg.d32 >> 16;
  83692. +
  83693. + if (ep->dwc_ep.is_in) {
  83694. + if (GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  83695. + /* Flush the Tx FIFO */
  83696. + dwc_otg_flush_tx_fifo(GET_CORE_IF(pcd),
  83697. + ep->dwc_ep.tx_fifo_num);
  83698. + }
  83699. + release_perio_tx_fifo(GET_CORE_IF(pcd), ep->dwc_ep.tx_fifo_num);
  83700. + release_tx_fifo(GET_CORE_IF(pcd), ep->dwc_ep.tx_fifo_num);
  83701. + if (GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  83702. + /* Decreasing EPinfo Base Addr */
  83703. + dptxfsiz.d32 =
  83704. + (DWC_READ_REG32
  83705. + (&GET_CORE_IF(pcd)->
  83706. + core_global_regs->dtxfsiz[ep->dwc_ep.tx_fifo_num-1]) >> 16);
  83707. + gdfifocfg.b.epinfobase = gdfifocfgbase.d32 - dptxfsiz.d32;
  83708. + if (GET_CORE_IF(pcd)->snpsid <= OTG_CORE_REV_2_94a) {
  83709. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gdfifocfg,
  83710. + gdfifocfg.d32);
  83711. + }
  83712. + }
  83713. + }
  83714. +
  83715. + /* Free DMA Descriptors */
  83716. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  83717. + if (ep->dwc_ep.type != UE_ISOCHRONOUS) {
  83718. + desc_addr = ep->dwc_ep.desc_addr;
  83719. + dma_desc_addr = ep->dwc_ep.dma_desc_addr;
  83720. +
  83721. + /* Cannot call dma_free_coherent() with IRQs disabled */
  83722. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  83723. + dwc_otg_ep_free_desc_chain(desc_addr, dma_desc_addr,
  83724. + MAX_DMA_DESC_CNT);
  83725. +
  83726. + goto out_unlocked;
  83727. + }
  83728. + }
  83729. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  83730. +
  83731. +out_unlocked:
  83732. + DWC_DEBUGPL(DBG_PCD, "%d %s disabled\n", ep->dwc_ep.num,
  83733. + ep->dwc_ep.is_in ? "IN" : "OUT");
  83734. + return 0;
  83735. +
  83736. +}
  83737. +
  83738. +/******************************************************************************/
  83739. +#ifdef DWC_UTE_PER_IO
  83740. +
  83741. +/**
  83742. + * Free the request and its extended parts
  83743. + *
  83744. + */
  83745. +void dwc_pcd_xiso_ereq_free(dwc_otg_pcd_ep_t * ep, dwc_otg_pcd_request_t * req)
  83746. +{
  83747. + DWC_FREE(req->ext_req.per_io_frame_descs);
  83748. + DWC_FREE(req);
  83749. +}
  83750. +
  83751. +/**
  83752. + * Start the next request in the endpoint's queue.
  83753. + *
  83754. + */
  83755. +int dwc_otg_pcd_xiso_start_next_request(dwc_otg_pcd_t * pcd,
  83756. + dwc_otg_pcd_ep_t * ep)
  83757. +{
  83758. + int i;
  83759. + dwc_otg_pcd_request_t *req = NULL;
  83760. + dwc_ep_t *dwcep = NULL;
  83761. + struct dwc_iso_xreq_port *ereq = NULL;
  83762. + struct dwc_iso_pkt_desc_port *ddesc_iso;
  83763. + uint16_t nat;
  83764. + depctl_data_t diepctl;
  83765. +
  83766. + dwcep = &ep->dwc_ep;
  83767. +
  83768. + if (dwcep->xiso_active_xfers > 0) {
  83769. +#if 0 //Disable this to decrease s/w overhead that is crucial for Isoc transfers
  83770. + DWC_WARN("There are currently active transfers for EP%d \
  83771. + (active=%d; queued=%d)", dwcep->num, dwcep->xiso_active_xfers,
  83772. + dwcep->xiso_queued_xfers);
  83773. +#endif
  83774. + return 0;
  83775. + }
  83776. +
  83777. + nat = UGETW(ep->desc->wMaxPacketSize);
  83778. + nat = (nat >> 11) & 0x03;
  83779. +
  83780. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  83781. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  83782. + ereq = &req->ext_req;
  83783. + ep->stopped = 0;
  83784. +
  83785. + /* Get the frame number */
  83786. + dwcep->xiso_frame_num =
  83787. + dwc_otg_get_frame_number(GET_CORE_IF(pcd));
  83788. + DWC_DEBUG("FRM_NUM=%d", dwcep->xiso_frame_num);
  83789. +
  83790. + ddesc_iso = ereq->per_io_frame_descs;
  83791. +
  83792. + if (dwcep->is_in) {
  83793. + /* Setup DMA Descriptor chain for IN Isoc request */
  83794. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  83795. + //if ((i % (nat + 1)) == 0)
  83796. + if ( i > 0 )
  83797. + dwcep->xiso_frame_num =
  83798. + (dwcep->xiso_bInterval +
  83799. + dwcep->xiso_frame_num) & 0x3FFF;
  83800. + dwcep->desc_addr[i].buf =
  83801. + req->dma + ddesc_iso[i].offset;
  83802. + dwcep->desc_addr[i].status.b_iso_in.txbytes =
  83803. + ddesc_iso[i].length;
  83804. + dwcep->desc_addr[i].status.b_iso_in.framenum =
  83805. + dwcep->xiso_frame_num;
  83806. + dwcep->desc_addr[i].status.b_iso_in.bs =
  83807. + BS_HOST_READY;
  83808. + dwcep->desc_addr[i].status.b_iso_in.txsts = 0;
  83809. + dwcep->desc_addr[i].status.b_iso_in.sp =
  83810. + (ddesc_iso[i].length %
  83811. + dwcep->maxpacket) ? 1 : 0;
  83812. + dwcep->desc_addr[i].status.b_iso_in.ioc = 0;
  83813. + dwcep->desc_addr[i].status.b_iso_in.pid = nat + 1;
  83814. + dwcep->desc_addr[i].status.b_iso_in.l = 0;
  83815. +
  83816. + /* Process the last descriptor */
  83817. + if (i == ereq->pio_pkt_count - 1) {
  83818. + dwcep->desc_addr[i].status.b_iso_in.ioc = 1;
  83819. + dwcep->desc_addr[i].status.b_iso_in.l = 1;
  83820. + }
  83821. + }
  83822. +
  83823. + /* Setup and start the transfer for this endpoint */
  83824. + dwcep->xiso_active_xfers++;
  83825. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->dev_if->
  83826. + in_ep_regs[dwcep->num]->diepdma,
  83827. + dwcep->dma_desc_addr);
  83828. + diepctl.d32 = 0;
  83829. + diepctl.b.epena = 1;
  83830. + diepctl.b.cnak = 1;
  83831. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->dev_if->
  83832. + in_ep_regs[dwcep->num]->diepctl, 0,
  83833. + diepctl.d32);
  83834. + } else {
  83835. + /* Setup DMA Descriptor chain for OUT Isoc request */
  83836. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  83837. + //if ((i % (nat + 1)) == 0)
  83838. + dwcep->xiso_frame_num = (dwcep->xiso_bInterval +
  83839. + dwcep->xiso_frame_num) & 0x3FFF;
  83840. + dwcep->desc_addr[i].buf =
  83841. + req->dma + ddesc_iso[i].offset;
  83842. + dwcep->desc_addr[i].status.b_iso_out.rxbytes =
  83843. + ddesc_iso[i].length;
  83844. + dwcep->desc_addr[i].status.b_iso_out.framenum =
  83845. + dwcep->xiso_frame_num;
  83846. + dwcep->desc_addr[i].status.b_iso_out.bs =
  83847. + BS_HOST_READY;
  83848. + dwcep->desc_addr[i].status.b_iso_out.rxsts = 0;
  83849. + dwcep->desc_addr[i].status.b_iso_out.sp =
  83850. + (ddesc_iso[i].length %
  83851. + dwcep->maxpacket) ? 1 : 0;
  83852. + dwcep->desc_addr[i].status.b_iso_out.ioc = 0;
  83853. + dwcep->desc_addr[i].status.b_iso_out.pid = nat + 1;
  83854. + dwcep->desc_addr[i].status.b_iso_out.l = 0;
  83855. +
  83856. + /* Process the last descriptor */
  83857. + if (i == ereq->pio_pkt_count - 1) {
  83858. + dwcep->desc_addr[i].status.b_iso_out.ioc = 1;
  83859. + dwcep->desc_addr[i].status.b_iso_out.l = 1;
  83860. + }
  83861. + }
  83862. +
  83863. + /* Setup and start the transfer for this endpoint */
  83864. + dwcep->xiso_active_xfers++;
  83865. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->
  83866. + dev_if->out_ep_regs[dwcep->num]->
  83867. + doepdma, dwcep->dma_desc_addr);
  83868. + diepctl.d32 = 0;
  83869. + diepctl.b.epena = 1;
  83870. + diepctl.b.cnak = 1;
  83871. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->
  83872. + dev_if->out_ep_regs[dwcep->num]->
  83873. + doepctl, 0, diepctl.d32);
  83874. + }
  83875. +
  83876. + } else {
  83877. + ep->stopped = 1;
  83878. + }
  83879. +
  83880. + return 0;
  83881. +}
  83882. +
  83883. +/**
  83884. + * - Remove the request from the queue
  83885. + */
  83886. +void complete_xiso_ep(dwc_otg_pcd_ep_t * ep)
  83887. +{
  83888. + dwc_otg_pcd_request_t *req = NULL;
  83889. + struct dwc_iso_xreq_port *ereq = NULL;
  83890. + struct dwc_iso_pkt_desc_port *ddesc_iso = NULL;
  83891. + dwc_ep_t *dwcep = NULL;
  83892. + int i;
  83893. +
  83894. + //DWC_DEBUG();
  83895. + dwcep = &ep->dwc_ep;
  83896. +
  83897. + /* Get the first pending request from the queue */
  83898. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  83899. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  83900. + if (!req) {
  83901. + DWC_PRINTF("complete_ep 0x%p, req = NULL!\n", ep);
  83902. + return;
  83903. + }
  83904. + dwcep->xiso_active_xfers--;
  83905. + dwcep->xiso_queued_xfers--;
  83906. + /* Remove this request from the queue */
  83907. + DWC_CIRCLEQ_REMOVE_INIT(&ep->queue, req, queue_entry);
  83908. + } else {
  83909. + DWC_PRINTF("complete_ep 0x%p, ep->queue empty!\n", ep);
  83910. + return;
  83911. + }
  83912. +
  83913. + ep->stopped = 1;
  83914. + ereq = &req->ext_req;
  83915. + ddesc_iso = ereq->per_io_frame_descs;
  83916. +
  83917. + if (dwcep->xiso_active_xfers < 0) {
  83918. + DWC_WARN("EP#%d (xiso_active_xfers=%d)", dwcep->num,
  83919. + dwcep->xiso_active_xfers);
  83920. + }
  83921. +
  83922. + /* Fill the Isoc descs of portable extended req from dma descriptors */
  83923. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  83924. + if (dwcep->is_in) { /* IN endpoints */
  83925. + ddesc_iso[i].actual_length = ddesc_iso[i].length -
  83926. + dwcep->desc_addr[i].status.b_iso_in.txbytes;
  83927. + ddesc_iso[i].status =
  83928. + dwcep->desc_addr[i].status.b_iso_in.txsts;
  83929. + } else { /* OUT endpoints */
  83930. + ddesc_iso[i].actual_length = ddesc_iso[i].length -
  83931. + dwcep->desc_addr[i].status.b_iso_out.rxbytes;
  83932. + ddesc_iso[i].status =
  83933. + dwcep->desc_addr[i].status.b_iso_out.rxsts;
  83934. + }
  83935. + }
  83936. +
  83937. + DWC_SPINUNLOCK(ep->pcd->lock);
  83938. +
  83939. + /* Call the completion function in the non-portable logic */
  83940. + ep->pcd->fops->xisoc_complete(ep->pcd, ep->priv, req->priv, 0,
  83941. + &req->ext_req);
  83942. +
  83943. + DWC_SPINLOCK(ep->pcd->lock);
  83944. +
  83945. + /* Free the request - specific freeing needed for extended request object */
  83946. + dwc_pcd_xiso_ereq_free(ep, req);
  83947. +
  83948. + /* Start the next request */
  83949. + dwc_otg_pcd_xiso_start_next_request(ep->pcd, ep);
  83950. +
  83951. + return;
  83952. +}
  83953. +
  83954. +/**
  83955. + * Create and initialize the Isoc pkt descriptors of the extended request.
  83956. + *
  83957. + */
  83958. +static int dwc_otg_pcd_xiso_create_pkt_descs(dwc_otg_pcd_request_t * req,
  83959. + void *ereq_nonport,
  83960. + int atomic_alloc)
  83961. +{
  83962. + struct dwc_iso_xreq_port *ereq = NULL;
  83963. + struct dwc_iso_xreq_port *req_mapped = NULL;
  83964. + struct dwc_iso_pkt_desc_port *ipds = NULL; /* To be created in this function */
  83965. + uint32_t pkt_count;
  83966. + int i;
  83967. +
  83968. + ereq = &req->ext_req;
  83969. + req_mapped = (struct dwc_iso_xreq_port *)ereq_nonport;
  83970. + pkt_count = req_mapped->pio_pkt_count;
  83971. +
  83972. + /* Create the isoc descs */
  83973. + if (atomic_alloc) {
  83974. + ipds = DWC_ALLOC_ATOMIC(sizeof(*ipds) * pkt_count);
  83975. + } else {
  83976. + ipds = DWC_ALLOC(sizeof(*ipds) * pkt_count);
  83977. + }
  83978. +
  83979. + if (!ipds) {
  83980. + DWC_ERROR("Failed to allocate isoc descriptors");
  83981. + return -DWC_E_NO_MEMORY;
  83982. + }
  83983. +
  83984. + /* Initialize the extended request fields */
  83985. + ereq->per_io_frame_descs = ipds;
  83986. + ereq->error_count = 0;
  83987. + ereq->pio_alloc_pkt_count = pkt_count;
  83988. + ereq->pio_pkt_count = pkt_count;
  83989. + ereq->tr_sub_flags = req_mapped->tr_sub_flags;
  83990. +
  83991. + /* Init the Isoc descriptors */
  83992. + for (i = 0; i < pkt_count; i++) {
  83993. + ipds[i].length = req_mapped->per_io_frame_descs[i].length;
  83994. + ipds[i].offset = req_mapped->per_io_frame_descs[i].offset;
  83995. + ipds[i].status = req_mapped->per_io_frame_descs[i].status; /* 0 */
  83996. + ipds[i].actual_length =
  83997. + req_mapped->per_io_frame_descs[i].actual_length;
  83998. + }
  83999. +
  84000. + return 0;
  84001. +}
  84002. +
  84003. +static void prn_ext_request(struct dwc_iso_xreq_port *ereq)
  84004. +{
  84005. + struct dwc_iso_pkt_desc_port *xfd = NULL;
  84006. + int i;
  84007. +
  84008. + DWC_DEBUG("per_io_frame_descs=%p", ereq->per_io_frame_descs);
  84009. + DWC_DEBUG("tr_sub_flags=%d", ereq->tr_sub_flags);
  84010. + DWC_DEBUG("error_count=%d", ereq->error_count);
  84011. + DWC_DEBUG("pio_alloc_pkt_count=%d", ereq->pio_alloc_pkt_count);
  84012. + DWC_DEBUG("pio_pkt_count=%d", ereq->pio_pkt_count);
  84013. + DWC_DEBUG("res=%d", ereq->res);
  84014. +
  84015. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  84016. + xfd = &ereq->per_io_frame_descs[0];
  84017. + DWC_DEBUG("FD #%d", i);
  84018. +
  84019. + DWC_DEBUG("xfd->actual_length=%d", xfd->actual_length);
  84020. + DWC_DEBUG("xfd->length=%d", xfd->length);
  84021. + DWC_DEBUG("xfd->offset=%d", xfd->offset);
  84022. + DWC_DEBUG("xfd->status=%d", xfd->status);
  84023. + }
  84024. +}
  84025. +
  84026. +/**
  84027. + *
  84028. + */
  84029. +int dwc_otg_pcd_xiso_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  84030. + uint8_t * buf, dwc_dma_t dma_buf, uint32_t buflen,
  84031. + int zero, void *req_handle, int atomic_alloc,
  84032. + void *ereq_nonport)
  84033. +{
  84034. + dwc_otg_pcd_request_t *req = NULL;
  84035. + dwc_otg_pcd_ep_t *ep;
  84036. + dwc_irqflags_t flags;
  84037. + int res;
  84038. +
  84039. + ep = get_ep_from_handle(pcd, ep_handle);
  84040. + if (!ep) {
  84041. + DWC_WARN("bad ep\n");
  84042. + return -DWC_E_INVALID;
  84043. + }
  84044. +
  84045. + /* We support this extension only for DDMA mode */
  84046. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC)
  84047. + if (!GET_CORE_IF(pcd)->dma_desc_enable)
  84048. + return -DWC_E_INVALID;
  84049. +
  84050. + /* Create a dwc_otg_pcd_request_t object */
  84051. + if (atomic_alloc) {
  84052. + req = DWC_ALLOC_ATOMIC(sizeof(*req));
  84053. + } else {
  84054. + req = DWC_ALLOC(sizeof(*req));
  84055. + }
  84056. +
  84057. + if (!req) {
  84058. + return -DWC_E_NO_MEMORY;
  84059. + }
  84060. +
  84061. + /* Create the Isoc descs for this request which shall be the exact match
  84062. + * of the structure sent to us from the non-portable logic */
  84063. + res =
  84064. + dwc_otg_pcd_xiso_create_pkt_descs(req, ereq_nonport, atomic_alloc);
  84065. + if (res) {
  84066. + DWC_WARN("Failed to init the Isoc descriptors");
  84067. + DWC_FREE(req);
  84068. + return res;
  84069. + }
  84070. +
  84071. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  84072. +
  84073. + DWC_CIRCLEQ_INIT_ENTRY(req, queue_entry);
  84074. + req->buf = buf;
  84075. + req->dma = dma_buf;
  84076. + req->length = buflen;
  84077. + req->sent_zlp = zero;
  84078. + req->priv = req_handle;
  84079. +
  84080. + //DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  84081. + ep->dwc_ep.dma_addr = dma_buf;
  84082. + ep->dwc_ep.start_xfer_buff = buf;
  84083. + ep->dwc_ep.xfer_buff = buf;
  84084. + ep->dwc_ep.xfer_len = 0;
  84085. + ep->dwc_ep.xfer_count = 0;
  84086. + ep->dwc_ep.sent_zlp = 0;
  84087. + ep->dwc_ep.total_len = buflen;
  84088. +
  84089. + /* Add this request to the tail */
  84090. + DWC_CIRCLEQ_INSERT_TAIL(&ep->queue, req, queue_entry);
  84091. + ep->dwc_ep.xiso_queued_xfers++;
  84092. +
  84093. +//DWC_DEBUG("CP_0");
  84094. +//DWC_DEBUG("req->ext_req.tr_sub_flags=%d", req->ext_req.tr_sub_flags);
  84095. +//prn_ext_request((struct dwc_iso_xreq_port *) ereq_nonport);
  84096. +//prn_ext_request(&req->ext_req);
  84097. +
  84098. + //DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  84099. +
  84100. + /* If the req->status == ASAP then check if there is any active transfer
  84101. + * for this endpoint. If no active transfers, then get the first entry
  84102. + * from the queue and start that transfer
  84103. + */
  84104. + if (req->ext_req.tr_sub_flags == DWC_EREQ_TF_ASAP) {
  84105. + res = dwc_otg_pcd_xiso_start_next_request(pcd, ep);
  84106. + if (res) {
  84107. + DWC_WARN("Failed to start the next Isoc transfer");
  84108. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  84109. + DWC_FREE(req);
  84110. + return res;
  84111. + }
  84112. + }
  84113. +
  84114. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  84115. + return 0;
  84116. +}
  84117. +
  84118. +#endif
  84119. +/* END ifdef DWC_UTE_PER_IO ***************************************************/
  84120. +int dwc_otg_pcd_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  84121. + uint8_t * buf, dwc_dma_t dma_buf, uint32_t buflen,
  84122. + int zero, void *req_handle, int atomic_alloc)
  84123. +{
  84124. + dwc_irqflags_t flags;
  84125. + dwc_otg_pcd_request_t *req;
  84126. + dwc_otg_pcd_ep_t *ep;
  84127. + uint32_t max_transfer;
  84128. +
  84129. + ep = get_ep_from_handle(pcd, ep_handle);
  84130. + if (!ep || (!ep->desc && ep->dwc_ep.num != 0)) {
  84131. + DWC_WARN("bad ep\n");
  84132. + return -DWC_E_INVALID;
  84133. + }
  84134. +
  84135. + if (atomic_alloc) {
  84136. + req = DWC_ALLOC_ATOMIC(sizeof(*req));
  84137. + } else {
  84138. + req = DWC_ALLOC(sizeof(*req));
  84139. + }
  84140. +
  84141. + if (!req) {
  84142. + return -DWC_E_NO_MEMORY;
  84143. + }
  84144. + DWC_CIRCLEQ_INIT_ENTRY(req, queue_entry);
  84145. + if (!GET_CORE_IF(pcd)->core_params->opt) {
  84146. + if (ep->dwc_ep.num != 0) {
  84147. + DWC_ERROR("queue req %p, len %d buf %p\n",
  84148. + req_handle, buflen, buf);
  84149. + }
  84150. + }
  84151. +
  84152. + req->buf = buf;
  84153. + req->dma = dma_buf;
  84154. + req->length = buflen;
  84155. + req->sent_zlp = zero;
  84156. + req->priv = req_handle;
  84157. + req->dw_align_buf = NULL;
  84158. + if ((dma_buf & 0x3) && GET_CORE_IF(pcd)->dma_enable
  84159. + && !GET_CORE_IF(pcd)->dma_desc_enable)
  84160. + req->dw_align_buf = DWC_DMA_ALLOC(buflen,
  84161. + &req->dw_align_buf_dma);
  84162. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  84163. +
  84164. + /*
  84165. + * After adding request to the queue for IN ISOC wait for In Token Received
  84166. + * when TX FIFO is empty interrupt and for OUT ISOC wait for OUT Token
  84167. + * Received when EP is disabled interrupt to obtain starting microframe
  84168. + * (odd/even) start transfer
  84169. + */
  84170. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  84171. + if (req != 0) {
  84172. + depctl_data_t depctl = {.d32 =
  84173. + DWC_READ_REG32(&pcd->core_if->dev_if->
  84174. + in_ep_regs[ep->dwc_ep.num]->
  84175. + diepctl) };
  84176. + ++pcd->request_pending;
  84177. +
  84178. + DWC_CIRCLEQ_INSERT_TAIL(&ep->queue, req, queue_entry);
  84179. + if (ep->dwc_ep.is_in) {
  84180. + depctl.b.cnak = 1;
  84181. + DWC_WRITE_REG32(&pcd->core_if->dev_if->
  84182. + in_ep_regs[ep->dwc_ep.num]->
  84183. + diepctl, depctl.d32);
  84184. + }
  84185. +
  84186. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  84187. + }
  84188. + return 0;
  84189. + }
  84190. +
  84191. + /*
  84192. + * For EP0 IN without premature status, zlp is required?
  84193. + */
  84194. + if (ep->dwc_ep.num == 0 && ep->dwc_ep.is_in) {
  84195. + DWC_DEBUGPL(DBG_PCDV, "%d-OUT ZLP\n", ep->dwc_ep.num);
  84196. + //_req->zero = 1;
  84197. + }
  84198. +
  84199. + /* Start the transfer */
  84200. + if (DWC_CIRCLEQ_EMPTY(&ep->queue) && !ep->stopped) {
  84201. + /* EP0 Transfer? */
  84202. + if (ep->dwc_ep.num == 0) {
  84203. + switch (pcd->ep0state) {
  84204. + case EP0_IN_DATA_PHASE:
  84205. + DWC_DEBUGPL(DBG_PCD,
  84206. + "%s ep0: EP0_IN_DATA_PHASE\n",
  84207. + __func__);
  84208. + break;
  84209. +
  84210. + case EP0_OUT_DATA_PHASE:
  84211. + DWC_DEBUGPL(DBG_PCD,
  84212. + "%s ep0: EP0_OUT_DATA_PHASE\n",
  84213. + __func__);
  84214. + if (pcd->request_config) {
  84215. + /* Complete STATUS PHASE */
  84216. + ep->dwc_ep.is_in = 1;
  84217. + pcd->ep0state = EP0_IN_STATUS_PHASE;
  84218. + }
  84219. + break;
  84220. +
  84221. + case EP0_IN_STATUS_PHASE:
  84222. + DWC_DEBUGPL(DBG_PCD,
  84223. + "%s ep0: EP0_IN_STATUS_PHASE\n",
  84224. + __func__);
  84225. + break;
  84226. +
  84227. + default:
  84228. + DWC_DEBUGPL(DBG_ANY, "ep0: odd state %d\n",
  84229. + pcd->ep0state);
  84230. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  84231. + return -DWC_E_SHUTDOWN;
  84232. + }
  84233. +
  84234. + ep->dwc_ep.dma_addr = dma_buf;
  84235. + ep->dwc_ep.start_xfer_buff = buf;
  84236. + ep->dwc_ep.xfer_buff = buf;
  84237. + ep->dwc_ep.xfer_len = buflen;
  84238. + ep->dwc_ep.xfer_count = 0;
  84239. + ep->dwc_ep.sent_zlp = 0;
  84240. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  84241. +
  84242. + if (zero) {
  84243. + if ((ep->dwc_ep.xfer_len %
  84244. + ep->dwc_ep.maxpacket == 0)
  84245. + && (ep->dwc_ep.xfer_len != 0)) {
  84246. + ep->dwc_ep.sent_zlp = 1;
  84247. + }
  84248. +
  84249. + }
  84250. +
  84251. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd),
  84252. + &ep->dwc_ep);
  84253. + } // non-ep0 endpoints
  84254. + else {
  84255. +#ifdef DWC_UTE_CFI
  84256. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  84257. + /* store the request length */
  84258. + ep->dwc_ep.cfi_req_len = buflen;
  84259. + pcd->cfi->ops.build_descriptors(pcd->cfi, pcd,
  84260. + ep, req);
  84261. + } else {
  84262. +#endif
  84263. + max_transfer =
  84264. + GET_CORE_IF(ep->pcd)->core_params->
  84265. + max_transfer_size;
  84266. +
  84267. + /* Setup and start the Transfer */
  84268. + if (req->dw_align_buf){
  84269. + if (ep->dwc_ep.is_in)
  84270. + dwc_memcpy(req->dw_align_buf,
  84271. + buf, buflen);
  84272. + ep->dwc_ep.dma_addr =
  84273. + req->dw_align_buf_dma;
  84274. + ep->dwc_ep.start_xfer_buff =
  84275. + req->dw_align_buf;
  84276. + ep->dwc_ep.xfer_buff =
  84277. + req->dw_align_buf;
  84278. + } else {
  84279. + ep->dwc_ep.dma_addr = dma_buf;
  84280. + ep->dwc_ep.start_xfer_buff = buf;
  84281. + ep->dwc_ep.xfer_buff = buf;
  84282. + }
  84283. + ep->dwc_ep.xfer_len = 0;
  84284. + ep->dwc_ep.xfer_count = 0;
  84285. + ep->dwc_ep.sent_zlp = 0;
  84286. + ep->dwc_ep.total_len = buflen;
  84287. +
  84288. + ep->dwc_ep.maxxfer = max_transfer;
  84289. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  84290. + uint32_t out_max_xfer =
  84291. + DDMA_MAX_TRANSFER_SIZE -
  84292. + (DDMA_MAX_TRANSFER_SIZE % 4);
  84293. + if (ep->dwc_ep.is_in) {
  84294. + if (ep->dwc_ep.maxxfer >
  84295. + DDMA_MAX_TRANSFER_SIZE) {
  84296. + ep->dwc_ep.maxxfer =
  84297. + DDMA_MAX_TRANSFER_SIZE;
  84298. + }
  84299. + } else {
  84300. + if (ep->dwc_ep.maxxfer >
  84301. + out_max_xfer) {
  84302. + ep->dwc_ep.maxxfer =
  84303. + out_max_xfer;
  84304. + }
  84305. + }
  84306. + }
  84307. + if (ep->dwc_ep.maxxfer < ep->dwc_ep.total_len) {
  84308. + ep->dwc_ep.maxxfer -=
  84309. + (ep->dwc_ep.maxxfer %
  84310. + ep->dwc_ep.maxpacket);
  84311. + }
  84312. +
  84313. + if (zero) {
  84314. + if ((ep->dwc_ep.total_len %
  84315. + ep->dwc_ep.maxpacket == 0)
  84316. + && (ep->dwc_ep.total_len != 0)) {
  84317. + ep->dwc_ep.sent_zlp = 1;
  84318. + }
  84319. + }
  84320. +#ifdef DWC_UTE_CFI
  84321. + }
  84322. +#endif
  84323. + dwc_otg_ep_start_transfer(GET_CORE_IF(pcd),
  84324. + &ep->dwc_ep);
  84325. + }
  84326. + }
  84327. +
  84328. + if (req != 0) {
  84329. + ++pcd->request_pending;
  84330. + DWC_CIRCLEQ_INSERT_TAIL(&ep->queue, req, queue_entry);
  84331. + if (ep->dwc_ep.is_in && ep->stopped
  84332. + && !(GET_CORE_IF(pcd)->dma_enable)) {
  84333. + /** @todo NGS Create a function for this. */
  84334. + diepmsk_data_t diepmsk = {.d32 = 0 };
  84335. + diepmsk.b.intktxfemp = 1;
  84336. + if (GET_CORE_IF(pcd)->multiproc_int_enable) {
  84337. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->
  84338. + dev_if->dev_global_regs->diepeachintmsk
  84339. + [ep->dwc_ep.num], 0,
  84340. + diepmsk.d32);
  84341. + } else {
  84342. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->
  84343. + dev_if->dev_global_regs->
  84344. + diepmsk, 0, diepmsk.d32);
  84345. + }
  84346. +
  84347. + }
  84348. + }
  84349. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  84350. +
  84351. + return 0;
  84352. +}
  84353. +
  84354. +int dwc_otg_pcd_ep_dequeue(dwc_otg_pcd_t * pcd, void *ep_handle,
  84355. + void *req_handle)
  84356. +{
  84357. + dwc_irqflags_t flags;
  84358. + dwc_otg_pcd_request_t *req;
  84359. + dwc_otg_pcd_ep_t *ep;
  84360. +
  84361. + ep = get_ep_from_handle(pcd, ep_handle);
  84362. + if (!ep || (!ep->desc && ep->dwc_ep.num != 0)) {
  84363. + DWC_WARN("bad argument\n");
  84364. + return -DWC_E_INVALID;
  84365. + }
  84366. +
  84367. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  84368. +
  84369. + /* make sure it's actually queued on this endpoint */
  84370. + DWC_CIRCLEQ_FOREACH(req, &ep->queue, queue_entry) {
  84371. + if (req->priv == (void *)req_handle) {
  84372. + break;
  84373. + }
  84374. + }
  84375. +
  84376. + if (req->priv != (void *)req_handle) {
  84377. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  84378. + return -DWC_E_INVALID;
  84379. + }
  84380. +
  84381. + if (!DWC_CIRCLEQ_EMPTY_ENTRY(req, queue_entry)) {
  84382. + dwc_otg_request_done(ep, req, -DWC_E_RESTART);
  84383. + } else {
  84384. + req = NULL;
  84385. + }
  84386. +
  84387. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  84388. +
  84389. + return req ? 0 : -DWC_E_SHUTDOWN;
  84390. +
  84391. +}
  84392. +
  84393. +/**
  84394. + * dwc_otg_pcd_ep_wedge - sets the halt feature and ignores clear requests
  84395. + *
  84396. + * Use this to stall an endpoint and ignore CLEAR_FEATURE(HALT_ENDPOINT)
  84397. + * requests. If the gadget driver clears the halt status, it will
  84398. + * automatically unwedge the endpoint.
  84399. + *
  84400. + * Returns zero on success, else negative DWC error code.
  84401. + */
  84402. +int dwc_otg_pcd_ep_wedge(dwc_otg_pcd_t * pcd, void *ep_handle)
  84403. +{
  84404. + dwc_otg_pcd_ep_t *ep;
  84405. + dwc_irqflags_t flags;
  84406. + int retval = 0;
  84407. +
  84408. + ep = get_ep_from_handle(pcd, ep_handle);
  84409. +
  84410. + if ((!ep->desc && ep != &pcd->ep0) ||
  84411. + (ep->desc && (ep->desc->bmAttributes == UE_ISOCHRONOUS))) {
  84412. + DWC_WARN("%s, bad ep\n", __func__);
  84413. + return -DWC_E_INVALID;
  84414. + }
  84415. +
  84416. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  84417. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  84418. + DWC_WARN("%d %s XFer In process\n", ep->dwc_ep.num,
  84419. + ep->dwc_ep.is_in ? "IN" : "OUT");
  84420. + retval = -DWC_E_AGAIN;
  84421. + } else {
  84422. + /* This code needs to be reviewed */
  84423. + if (ep->dwc_ep.is_in == 1 && GET_CORE_IF(pcd)->dma_desc_enable) {
  84424. + dtxfsts_data_t txstatus;
  84425. + fifosize_data_t txfifosize;
  84426. +
  84427. + txfifosize.d32 =
  84428. + DWC_READ_REG32(&GET_CORE_IF(pcd)->
  84429. + core_global_regs->dtxfsiz[ep->dwc_ep.
  84430. + tx_fifo_num]);
  84431. + txstatus.d32 =
  84432. + DWC_READ_REG32(&GET_CORE_IF(pcd)->
  84433. + dev_if->in_ep_regs[ep->dwc_ep.num]->
  84434. + dtxfsts);
  84435. +
  84436. + if (txstatus.b.txfspcavail < txfifosize.b.depth) {
  84437. + DWC_WARN("%s() Data In Tx Fifo\n", __func__);
  84438. + retval = -DWC_E_AGAIN;
  84439. + } else {
  84440. + if (ep->dwc_ep.num == 0) {
  84441. + pcd->ep0state = EP0_STALL;
  84442. + }
  84443. +
  84444. + ep->stopped = 1;
  84445. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd),
  84446. + &ep->dwc_ep);
  84447. + }
  84448. + } else {
  84449. + if (ep->dwc_ep.num == 0) {
  84450. + pcd->ep0state = EP0_STALL;
  84451. + }
  84452. +
  84453. + ep->stopped = 1;
  84454. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  84455. + }
  84456. + }
  84457. +
  84458. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  84459. +
  84460. + return retval;
  84461. +}
  84462. +
  84463. +int dwc_otg_pcd_ep_halt(dwc_otg_pcd_t * pcd, void *ep_handle, int value)
  84464. +{
  84465. + dwc_otg_pcd_ep_t *ep;
  84466. + dwc_irqflags_t flags;
  84467. + int retval = 0;
  84468. +
  84469. + ep = get_ep_from_handle(pcd, ep_handle);
  84470. +
  84471. + if (!ep || (!ep->desc && ep != &pcd->ep0) ||
  84472. + (ep->desc && (ep->desc->bmAttributes == UE_ISOCHRONOUS))) {
  84473. + DWC_WARN("%s, bad ep\n", __func__);
  84474. + return -DWC_E_INVALID;
  84475. + }
  84476. +
  84477. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  84478. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  84479. + DWC_WARN("%d %s XFer In process\n", ep->dwc_ep.num,
  84480. + ep->dwc_ep.is_in ? "IN" : "OUT");
  84481. + retval = -DWC_E_AGAIN;
  84482. + } else if (value == 0) {
  84483. + dwc_otg_ep_clear_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  84484. + } else if (value == 1) {
  84485. + if (ep->dwc_ep.is_in == 1 && GET_CORE_IF(pcd)->dma_desc_enable) {
  84486. + dtxfsts_data_t txstatus;
  84487. + fifosize_data_t txfifosize;
  84488. +
  84489. + txfifosize.d32 =
  84490. + DWC_READ_REG32(&GET_CORE_IF(pcd)->core_global_regs->
  84491. + dtxfsiz[ep->dwc_ep.tx_fifo_num]);
  84492. + txstatus.d32 =
  84493. + DWC_READ_REG32(&GET_CORE_IF(pcd)->dev_if->
  84494. + in_ep_regs[ep->dwc_ep.num]->dtxfsts);
  84495. +
  84496. + if (txstatus.b.txfspcavail < txfifosize.b.depth) {
  84497. + DWC_WARN("%s() Data In Tx Fifo\n", __func__);
  84498. + retval = -DWC_E_AGAIN;
  84499. + } else {
  84500. + if (ep->dwc_ep.num == 0) {
  84501. + pcd->ep0state = EP0_STALL;
  84502. + }
  84503. +
  84504. + ep->stopped = 1;
  84505. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd),
  84506. + &ep->dwc_ep);
  84507. + }
  84508. + } else {
  84509. + if (ep->dwc_ep.num == 0) {
  84510. + pcd->ep0state = EP0_STALL;
  84511. + }
  84512. +
  84513. + ep->stopped = 1;
  84514. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  84515. + }
  84516. + } else if (value == 2) {
  84517. + ep->dwc_ep.stall_clear_flag = 0;
  84518. + } else if (value == 3) {
  84519. + ep->dwc_ep.stall_clear_flag = 1;
  84520. + }
  84521. +
  84522. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  84523. +
  84524. + return retval;
  84525. +}
  84526. +
  84527. +/**
  84528. + * This function initiates remote wakeup of the host from suspend state.
  84529. + */
  84530. +void dwc_otg_pcd_rem_wkup_from_suspend(dwc_otg_pcd_t * pcd, int set)
  84531. +{
  84532. + dctl_data_t dctl = { 0 };
  84533. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  84534. + dsts_data_t dsts;
  84535. +
  84536. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  84537. + if (!dsts.b.suspsts) {
  84538. + DWC_WARN("Remote wakeup while is not in suspend state\n");
  84539. + }
  84540. + /* Check if DEVICE_REMOTE_WAKEUP feature enabled */
  84541. + if (pcd->remote_wakeup_enable) {
  84542. + if (set) {
  84543. +
  84544. + if (core_if->adp_enable) {
  84545. + gpwrdn_data_t gpwrdn;
  84546. +
  84547. + dwc_otg_adp_probe_stop(core_if);
  84548. +
  84549. + /* Mask SRP detected interrupt from Power Down Logic */
  84550. + gpwrdn.d32 = 0;
  84551. + gpwrdn.b.srp_det_msk = 1;
  84552. + DWC_MODIFY_REG32(&core_if->
  84553. + core_global_regs->gpwrdn,
  84554. + gpwrdn.d32, 0);
  84555. +
  84556. + /* Disable Power Down Logic */
  84557. + gpwrdn.d32 = 0;
  84558. + gpwrdn.b.pmuactv = 1;
  84559. + DWC_MODIFY_REG32(&core_if->
  84560. + core_global_regs->gpwrdn,
  84561. + gpwrdn.d32, 0);
  84562. +
  84563. + /*
  84564. + * Initialize the Core for Device mode.
  84565. + */
  84566. + core_if->op_state = B_PERIPHERAL;
  84567. + dwc_otg_core_init(core_if);
  84568. + dwc_otg_enable_global_interrupts(core_if);
  84569. + cil_pcd_start(core_if);
  84570. +
  84571. + dwc_otg_initiate_srp(core_if);
  84572. + }
  84573. +
  84574. + dctl.b.rmtwkupsig = 1;
  84575. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  84576. + dctl, 0, dctl.d32);
  84577. + DWC_DEBUGPL(DBG_PCD, "Set Remote Wakeup\n");
  84578. +
  84579. + dwc_mdelay(2);
  84580. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  84581. + dctl, dctl.d32, 0);
  84582. + DWC_DEBUGPL(DBG_PCD, "Clear Remote Wakeup\n");
  84583. + }
  84584. + } else {
  84585. + DWC_DEBUGPL(DBG_PCD, "Remote Wakeup is disabled\n");
  84586. + }
  84587. +}
  84588. +
  84589. +#ifdef CONFIG_USB_DWC_OTG_LPM
  84590. +/**
  84591. + * This function initiates remote wakeup of the host from L1 sleep state.
  84592. + */
  84593. +void dwc_otg_pcd_rem_wkup_from_sleep(dwc_otg_pcd_t * pcd, int set)
  84594. +{
  84595. + glpmcfg_data_t lpmcfg;
  84596. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  84597. +
  84598. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  84599. +
  84600. + /* Check if we are in L1 state */
  84601. + if (!lpmcfg.b.prt_sleep_sts) {
  84602. + DWC_DEBUGPL(DBG_PCD, "Device is not in sleep state\n");
  84603. + return;
  84604. + }
  84605. +
  84606. + /* Check if host allows remote wakeup */
  84607. + if (!lpmcfg.b.rem_wkup_en) {
  84608. + DWC_DEBUGPL(DBG_PCD, "Host does not allow remote wakeup\n");
  84609. + return;
  84610. + }
  84611. +
  84612. + /* Check if Resume OK */
  84613. + if (!lpmcfg.b.sleep_state_resumeok) {
  84614. + DWC_DEBUGPL(DBG_PCD, "Sleep state resume is not OK\n");
  84615. + return;
  84616. + }
  84617. +
  84618. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  84619. + lpmcfg.b.en_utmi_sleep = 0;
  84620. + lpmcfg.b.hird_thres &= (~(1 << 4));
  84621. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  84622. +
  84623. + if (set) {
  84624. + dctl_data_t dctl = {.d32 = 0 };
  84625. + dctl.b.rmtwkupsig = 1;
  84626. + /* Set RmtWkUpSig bit to start remote wakup signaling.
  84627. + * Hardware will automatically clear this bit.
  84628. + */
  84629. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl,
  84630. + 0, dctl.d32);
  84631. + DWC_DEBUGPL(DBG_PCD, "Set Remote Wakeup\n");
  84632. + }
  84633. +
  84634. +}
  84635. +#endif
  84636. +
  84637. +/**
  84638. + * Performs remote wakeup.
  84639. + */
  84640. +void dwc_otg_pcd_remote_wakeup(dwc_otg_pcd_t * pcd, int set)
  84641. +{
  84642. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  84643. + dwc_irqflags_t flags;
  84644. + if (dwc_otg_is_device_mode(core_if)) {
  84645. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  84646. +#ifdef CONFIG_USB_DWC_OTG_LPM
  84647. + if (core_if->lx_state == DWC_OTG_L1) {
  84648. + dwc_otg_pcd_rem_wkup_from_sleep(pcd, set);
  84649. + } else {
  84650. +#endif
  84651. + dwc_otg_pcd_rem_wkup_from_suspend(pcd, set);
  84652. +#ifdef CONFIG_USB_DWC_OTG_LPM
  84653. + }
  84654. +#endif
  84655. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  84656. + }
  84657. + return;
  84658. +}
  84659. +
  84660. +void dwc_otg_pcd_disconnect_us(dwc_otg_pcd_t * pcd, int no_of_usecs)
  84661. +{
  84662. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  84663. + dctl_data_t dctl = { 0 };
  84664. +
  84665. + if (dwc_otg_is_device_mode(core_if)) {
  84666. + dctl.b.sftdiscon = 1;
  84667. + DWC_PRINTF("Soft disconnect for %d useconds\n",no_of_usecs);
  84668. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  84669. + dwc_udelay(no_of_usecs);
  84670. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32,0);
  84671. +
  84672. + } else{
  84673. + DWC_PRINTF("NOT SUPPORTED IN HOST MODE\n");
  84674. + }
  84675. + return;
  84676. +
  84677. +}
  84678. +
  84679. +int dwc_otg_pcd_wakeup(dwc_otg_pcd_t * pcd)
  84680. +{
  84681. + dsts_data_t dsts;
  84682. + gotgctl_data_t gotgctl;
  84683. +
  84684. + /*
  84685. + * This function starts the Protocol if no session is in progress. If
  84686. + * a session is already in progress, but the device is suspended,
  84687. + * remote wakeup signaling is started.
  84688. + */
  84689. +
  84690. + /* Check if valid session */
  84691. + gotgctl.d32 =
  84692. + DWC_READ_REG32(&(GET_CORE_IF(pcd)->core_global_regs->gotgctl));
  84693. + if (gotgctl.b.bsesvld) {
  84694. + /* Check if suspend state */
  84695. + dsts.d32 =
  84696. + DWC_READ_REG32(&
  84697. + (GET_CORE_IF(pcd)->dev_if->
  84698. + dev_global_regs->dsts));
  84699. + if (dsts.b.suspsts) {
  84700. + dwc_otg_pcd_remote_wakeup(pcd, 1);
  84701. + }
  84702. + } else {
  84703. + dwc_otg_pcd_initiate_srp(pcd);
  84704. + }
  84705. +
  84706. + return 0;
  84707. +
  84708. +}
  84709. +
  84710. +/**
  84711. + * Start the SRP timer to detect when the SRP does not complete within
  84712. + * 6 seconds.
  84713. + *
  84714. + * @param pcd the pcd structure.
  84715. + */
  84716. +void dwc_otg_pcd_initiate_srp(dwc_otg_pcd_t * pcd)
  84717. +{
  84718. + dwc_irqflags_t flags;
  84719. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  84720. + dwc_otg_initiate_srp(GET_CORE_IF(pcd));
  84721. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  84722. +}
  84723. +
  84724. +int dwc_otg_pcd_get_frame_number(dwc_otg_pcd_t * pcd)
  84725. +{
  84726. + return dwc_otg_get_frame_number(GET_CORE_IF(pcd));
  84727. +}
  84728. +
  84729. +int dwc_otg_pcd_is_lpm_enabled(dwc_otg_pcd_t * pcd)
  84730. +{
  84731. + return GET_CORE_IF(pcd)->core_params->lpm_enable;
  84732. +}
  84733. +
  84734. +uint32_t get_b_hnp_enable(dwc_otg_pcd_t * pcd)
  84735. +{
  84736. + return pcd->b_hnp_enable;
  84737. +}
  84738. +
  84739. +uint32_t get_a_hnp_support(dwc_otg_pcd_t * pcd)
  84740. +{
  84741. + return pcd->a_hnp_support;
  84742. +}
  84743. +
  84744. +uint32_t get_a_alt_hnp_support(dwc_otg_pcd_t * pcd)
  84745. +{
  84746. + return pcd->a_alt_hnp_support;
  84747. +}
  84748. +
  84749. +int dwc_otg_pcd_get_rmwkup_enable(dwc_otg_pcd_t * pcd)
  84750. +{
  84751. + return pcd->remote_wakeup_enable;
  84752. +}
  84753. +
  84754. +#endif /* DWC_HOST_ONLY */
  84755. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_pcd.h linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_pcd.h
  84756. --- linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_pcd.h 1970-01-01 01:00:00.000000000 +0100
  84757. +++ linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_pcd.h 2014-08-06 16:50:14.849965104 +0200
  84758. @@ -0,0 +1,266 @@
  84759. +/* ==========================================================================
  84760. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd.h $
  84761. + * $Revision: #48 $
  84762. + * $Date: 2012/08/10 $
  84763. + * $Change: 2047372 $
  84764. + *
  84765. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  84766. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  84767. + * otherwise expressly agreed to in writing between Synopsys and you.
  84768. + *
  84769. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  84770. + * any End User Software License Agreement or Agreement for Licensed Product
  84771. + * with Synopsys or any supplement thereto. You are permitted to use and
  84772. + * redistribute this Software in source and binary forms, with or without
  84773. + * modification, provided that redistributions of source code must retain this
  84774. + * notice. You may not view, use, disclose, copy or distribute this file or
  84775. + * any information contained herein except pursuant to this license grant from
  84776. + * Synopsys. If you do not agree with this notice, including the disclaimer
  84777. + * below, then you are not authorized to use the Software.
  84778. + *
  84779. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  84780. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  84781. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  84782. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  84783. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  84784. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  84785. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  84786. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  84787. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  84788. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  84789. + * DAMAGE.
  84790. + * ========================================================================== */
  84791. +#ifndef DWC_HOST_ONLY
  84792. +#if !defined(__DWC_PCD_H__)
  84793. +#define __DWC_PCD_H__
  84794. +
  84795. +#include "dwc_otg_os_dep.h"
  84796. +#include "usb.h"
  84797. +#include "dwc_otg_cil.h"
  84798. +#include "dwc_otg_pcd_if.h"
  84799. +struct cfiobject;
  84800. +
  84801. +/**
  84802. + * @file
  84803. + *
  84804. + * This file contains the structures, constants, and interfaces for
  84805. + * the Perpherial Contoller Driver (PCD).
  84806. + *
  84807. + * The Peripheral Controller Driver (PCD) for Linux will implement the
  84808. + * Gadget API, so that the existing Gadget drivers can be used. For
  84809. + * the Mass Storage Function driver the File-backed USB Storage Gadget
  84810. + * (FBS) driver will be used. The FBS driver supports the
  84811. + * Control-Bulk (CB), Control-Bulk-Interrupt (CBI), and Bulk-Only
  84812. + * transports.
  84813. + *
  84814. + */
  84815. +
  84816. +/** Invalid DMA Address */
  84817. +#define DWC_DMA_ADDR_INVALID (~(dwc_dma_t)0)
  84818. +
  84819. +/** Max Transfer size for any EP */
  84820. +#define DDMA_MAX_TRANSFER_SIZE 65535
  84821. +
  84822. +/**
  84823. + * Get the pointer to the core_if from the pcd pointer.
  84824. + */
  84825. +#define GET_CORE_IF( _pcd ) (_pcd->core_if)
  84826. +
  84827. +/**
  84828. + * States of EP0.
  84829. + */
  84830. +typedef enum ep0_state {
  84831. + EP0_DISCONNECT, /* no host */
  84832. + EP0_IDLE,
  84833. + EP0_IN_DATA_PHASE,
  84834. + EP0_OUT_DATA_PHASE,
  84835. + EP0_IN_STATUS_PHASE,
  84836. + EP0_OUT_STATUS_PHASE,
  84837. + EP0_STALL,
  84838. +} ep0state_e;
  84839. +
  84840. +/** Fordward declaration.*/
  84841. +struct dwc_otg_pcd;
  84842. +
  84843. +/** DWC_otg iso request structure.
  84844. + *
  84845. + */
  84846. +typedef struct usb_iso_request dwc_otg_pcd_iso_request_t;
  84847. +
  84848. +#ifdef DWC_UTE_PER_IO
  84849. +
  84850. +/**
  84851. + * This shall be the exact analogy of the same type structure defined in the
  84852. + * usb_gadget.h. Each descriptor contains
  84853. + */
  84854. +struct dwc_iso_pkt_desc_port {
  84855. + uint32_t offset;
  84856. + uint32_t length; /* expected length */
  84857. + uint32_t actual_length;
  84858. + uint32_t status;
  84859. +};
  84860. +
  84861. +struct dwc_iso_xreq_port {
  84862. + /** transfer/submission flag */
  84863. + uint32_t tr_sub_flags;
  84864. + /** Start the request ASAP */
  84865. +#define DWC_EREQ_TF_ASAP 0x00000002
  84866. + /** Just enqueue the request w/o initiating a transfer */
  84867. +#define DWC_EREQ_TF_ENQUEUE 0x00000004
  84868. +
  84869. + /**
  84870. + * count of ISO packets attached to this request - shall
  84871. + * not exceed the pio_alloc_pkt_count
  84872. + */
  84873. + uint32_t pio_pkt_count;
  84874. + /** count of ISO packets allocated for this request */
  84875. + uint32_t pio_alloc_pkt_count;
  84876. + /** number of ISO packet errors */
  84877. + uint32_t error_count;
  84878. + /** reserved for future extension */
  84879. + uint32_t res;
  84880. + /** Will be allocated and freed in the UTE gadget and based on the CFC value */
  84881. + struct dwc_iso_pkt_desc_port *per_io_frame_descs;
  84882. +};
  84883. +#endif
  84884. +/** DWC_otg request structure.
  84885. + * This structure is a list of requests.
  84886. + */
  84887. +typedef struct dwc_otg_pcd_request {
  84888. + void *priv;
  84889. + void *buf;
  84890. + dwc_dma_t dma;
  84891. + uint32_t length;
  84892. + uint32_t actual;
  84893. + unsigned sent_zlp:1;
  84894. + /**
  84895. + * Used instead of original buffer if
  84896. + * it(physical address) is not dword-aligned.
  84897. + **/
  84898. + uint8_t *dw_align_buf;
  84899. + dwc_dma_t dw_align_buf_dma;
  84900. +
  84901. + DWC_CIRCLEQ_ENTRY(dwc_otg_pcd_request) queue_entry;
  84902. +#ifdef DWC_UTE_PER_IO
  84903. + struct dwc_iso_xreq_port ext_req;
  84904. + //void *priv_ereq_nport; /* */
  84905. +#endif
  84906. +} dwc_otg_pcd_request_t;
  84907. +
  84908. +DWC_CIRCLEQ_HEAD(req_list, dwc_otg_pcd_request);
  84909. +
  84910. +/** PCD EP structure.
  84911. + * This structure describes an EP, there is an array of EPs in the PCD
  84912. + * structure.
  84913. + */
  84914. +typedef struct dwc_otg_pcd_ep {
  84915. + /** USB EP Descriptor */
  84916. + const usb_endpoint_descriptor_t *desc;
  84917. +
  84918. + /** queue of dwc_otg_pcd_requests. */
  84919. + struct req_list queue;
  84920. + unsigned stopped:1;
  84921. + unsigned disabling:1;
  84922. + unsigned dma:1;
  84923. + unsigned queue_sof:1;
  84924. +
  84925. +#ifdef DWC_EN_ISOC
  84926. + /** ISOC req handle passed */
  84927. + void *iso_req_handle;
  84928. +#endif //_EN_ISOC_
  84929. +
  84930. + /** DWC_otg ep data. */
  84931. + dwc_ep_t dwc_ep;
  84932. +
  84933. + /** Pointer to PCD */
  84934. + struct dwc_otg_pcd *pcd;
  84935. +
  84936. + void *priv;
  84937. +} dwc_otg_pcd_ep_t;
  84938. +
  84939. +/** DWC_otg PCD Structure.
  84940. + * This structure encapsulates the data for the dwc_otg PCD.
  84941. + */
  84942. +struct dwc_otg_pcd {
  84943. + const struct dwc_otg_pcd_function_ops *fops;
  84944. + /** The DWC otg device pointer */
  84945. + struct dwc_otg_device *otg_dev;
  84946. + /** Core Interface */
  84947. + dwc_otg_core_if_t *core_if;
  84948. + /** State of EP0 */
  84949. + ep0state_e ep0state;
  84950. + /** EP0 Request is pending */
  84951. + unsigned ep0_pending:1;
  84952. + /** Indicates when SET CONFIGURATION Request is in process */
  84953. + unsigned request_config:1;
  84954. + /** The state of the Remote Wakeup Enable. */
  84955. + unsigned remote_wakeup_enable:1;
  84956. + /** The state of the B-Device HNP Enable. */
  84957. + unsigned b_hnp_enable:1;
  84958. + /** The state of A-Device HNP Support. */
  84959. + unsigned a_hnp_support:1;
  84960. + /** The state of the A-Device Alt HNP support. */
  84961. + unsigned a_alt_hnp_support:1;
  84962. + /** Count of pending Requests */
  84963. + unsigned request_pending;
  84964. +
  84965. + /** SETUP packet for EP0
  84966. + * This structure is allocated as a DMA buffer on PCD initialization
  84967. + * with enough space for up to 3 setup packets.
  84968. + */
  84969. + union {
  84970. + usb_device_request_t req;
  84971. + uint32_t d32[2];
  84972. + } *setup_pkt;
  84973. +
  84974. + dwc_dma_t setup_pkt_dma_handle;
  84975. +
  84976. + /* Additional buffer and flag for CTRL_WR premature case */
  84977. + uint8_t *backup_buf;
  84978. + unsigned data_terminated;
  84979. +
  84980. + /** 2-byte dma buffer used to return status from GET_STATUS */
  84981. + uint16_t *status_buf;
  84982. + dwc_dma_t status_buf_dma_handle;
  84983. +
  84984. + /** EP0 */
  84985. + dwc_otg_pcd_ep_t ep0;
  84986. +
  84987. + /** Array of IN EPs. */
  84988. + dwc_otg_pcd_ep_t in_ep[MAX_EPS_CHANNELS - 1];
  84989. + /** Array of OUT EPs. */
  84990. + dwc_otg_pcd_ep_t out_ep[MAX_EPS_CHANNELS - 1];
  84991. + /** number of valid EPs in the above array. */
  84992. +// unsigned num_eps : 4;
  84993. + dwc_spinlock_t *lock;
  84994. +
  84995. + /** Tasklet to defer starting of TEST mode transmissions until
  84996. + * Status Phase has been completed.
  84997. + */
  84998. + dwc_tasklet_t *test_mode_tasklet;
  84999. +
  85000. + /** Tasklet to delay starting of xfer in DMA mode */
  85001. + dwc_tasklet_t *start_xfer_tasklet;
  85002. +
  85003. + /** The test mode to enter when the tasklet is executed. */
  85004. + unsigned test_mode;
  85005. + /** The cfi_api structure that implements most of the CFI API
  85006. + * and OTG specific core configuration functionality
  85007. + */
  85008. +#ifdef DWC_UTE_CFI
  85009. + struct cfiobject *cfi;
  85010. +#endif
  85011. +
  85012. +};
  85013. +
  85014. +//FIXME this functions should be static, and this prototypes should be removed
  85015. +extern void dwc_otg_request_nuke(dwc_otg_pcd_ep_t * ep);
  85016. +extern void dwc_otg_request_done(dwc_otg_pcd_ep_t * ep,
  85017. + dwc_otg_pcd_request_t * req, int32_t status);
  85018. +
  85019. +void dwc_otg_iso_buffer_done(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep,
  85020. + void *req_handle);
  85021. +
  85022. +extern void do_test_mode(void *data);
  85023. +#endif
  85024. +#endif /* DWC_HOST_ONLY */
  85025. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h
  85026. --- linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h 1970-01-01 01:00:00.000000000 +0100
  85027. +++ linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h 2014-08-06 16:50:14.849965104 +0200
  85028. @@ -0,0 +1,360 @@
  85029. +/* ==========================================================================
  85030. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd_if.h $
  85031. + * $Revision: #11 $
  85032. + * $Date: 2011/10/26 $
  85033. + * $Change: 1873028 $
  85034. + *
  85035. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  85036. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  85037. + * otherwise expressly agreed to in writing between Synopsys and you.
  85038. + *
  85039. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  85040. + * any End User Software License Agreement or Agreement for Licensed Product
  85041. + * with Synopsys or any supplement thereto. You are permitted to use and
  85042. + * redistribute this Software in source and binary forms, with or without
  85043. + * modification, provided that redistributions of source code must retain this
  85044. + * notice. You may not view, use, disclose, copy or distribute this file or
  85045. + * any information contained herein except pursuant to this license grant from
  85046. + * Synopsys. If you do not agree with this notice, including the disclaimer
  85047. + * below, then you are not authorized to use the Software.
  85048. + *
  85049. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  85050. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  85051. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  85052. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  85053. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  85054. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  85055. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  85056. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  85057. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  85058. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  85059. + * DAMAGE.
  85060. + * ========================================================================== */
  85061. +#ifndef DWC_HOST_ONLY
  85062. +
  85063. +#if !defined(__DWC_PCD_IF_H__)
  85064. +#define __DWC_PCD_IF_H__
  85065. +
  85066. +//#include "dwc_os.h"
  85067. +#include "dwc_otg_core_if.h"
  85068. +
  85069. +/** @file
  85070. + * This file defines DWC_OTG PCD Core API.
  85071. + */
  85072. +
  85073. +struct dwc_otg_pcd;
  85074. +typedef struct dwc_otg_pcd dwc_otg_pcd_t;
  85075. +
  85076. +/** Maxpacket size for EP0 */
  85077. +#define MAX_EP0_SIZE 64
  85078. +/** Maxpacket size for any EP */
  85079. +#define MAX_PACKET_SIZE 1024
  85080. +
  85081. +/** @name Function Driver Callbacks */
  85082. +/** @{ */
  85083. +
  85084. +/** This function will be called whenever a previously queued request has
  85085. + * completed. The status value will be set to -DWC_E_SHUTDOWN to indicated a
  85086. + * failed or aborted transfer, or -DWC_E_RESTART to indicate the device was reset,
  85087. + * or -DWC_E_TIMEOUT to indicate it timed out, or -DWC_E_INVALID to indicate invalid
  85088. + * parameters. */
  85089. +typedef int (*dwc_completion_cb_t) (dwc_otg_pcd_t * pcd, void *ep_handle,
  85090. + void *req_handle, int32_t status,
  85091. + uint32_t actual);
  85092. +/**
  85093. + * This function will be called whenever a previousle queued ISOC request has
  85094. + * completed. Count of ISOC packets could be read using dwc_otg_pcd_get_iso_packet_count
  85095. + * function.
  85096. + * The status of each ISOC packet could be read using dwc_otg_pcd_get_iso_packet_*
  85097. + * functions.
  85098. + */
  85099. +typedef int (*dwc_isoc_completion_cb_t) (dwc_otg_pcd_t * pcd, void *ep_handle,
  85100. + void *req_handle, int proc_buf_num);
  85101. +/** This function should handle any SETUP request that cannot be handled by the
  85102. + * PCD Core. This includes most GET_DESCRIPTORs, SET_CONFIGS, Any
  85103. + * class-specific requests, etc. The function must non-blocking.
  85104. + *
  85105. + * Returns 0 on success.
  85106. + * Returns -DWC_E_NOT_SUPPORTED if the request is not supported.
  85107. + * Returns -DWC_E_INVALID if the setup request had invalid parameters or bytes.
  85108. + * Returns -DWC_E_SHUTDOWN on any other error. */
  85109. +typedef int (*dwc_setup_cb_t) (dwc_otg_pcd_t * pcd, uint8_t * bytes);
  85110. +/** This is called whenever the device has been disconnected. The function
  85111. + * driver should take appropriate action to clean up all pending requests in the
  85112. + * PCD Core, remove all endpoints (except ep0), and initialize back to reset
  85113. + * state. */
  85114. +typedef int (*dwc_disconnect_cb_t) (dwc_otg_pcd_t * pcd);
  85115. +/** This function is called when device has been connected. */
  85116. +typedef int (*dwc_connect_cb_t) (dwc_otg_pcd_t * pcd, int speed);
  85117. +/** This function is called when device has been suspended */
  85118. +typedef int (*dwc_suspend_cb_t) (dwc_otg_pcd_t * pcd);
  85119. +/** This function is called when device has received LPM tokens, i.e.
  85120. + * device has been sent to sleep state. */
  85121. +typedef int (*dwc_sleep_cb_t) (dwc_otg_pcd_t * pcd);
  85122. +/** This function is called when device has been resumed
  85123. + * from suspend(L2) or L1 sleep state. */
  85124. +typedef int (*dwc_resume_cb_t) (dwc_otg_pcd_t * pcd);
  85125. +/** This function is called whenever hnp params has been changed.
  85126. + * User can call get_b_hnp_enable, get_a_hnp_support, get_a_alt_hnp_support functions
  85127. + * to get hnp parameters. */
  85128. +typedef int (*dwc_hnp_params_changed_cb_t) (dwc_otg_pcd_t * pcd);
  85129. +/** This function is called whenever USB RESET is detected. */
  85130. +typedef int (*dwc_reset_cb_t) (dwc_otg_pcd_t * pcd);
  85131. +
  85132. +typedef int (*cfi_setup_cb_t) (dwc_otg_pcd_t * pcd, void *ctrl_req_bytes);
  85133. +
  85134. +/**
  85135. + *
  85136. + * @param ep_handle Void pointer to the usb_ep structure
  85137. + * @param ereq_port Pointer to the extended request structure created in the
  85138. + * portable part.
  85139. + */
  85140. +typedef int (*xiso_completion_cb_t) (dwc_otg_pcd_t * pcd, void *ep_handle,
  85141. + void *req_handle, int32_t status,
  85142. + void *ereq_port);
  85143. +/** Function Driver Ops Data Structure */
  85144. +struct dwc_otg_pcd_function_ops {
  85145. + dwc_connect_cb_t connect;
  85146. + dwc_disconnect_cb_t disconnect;
  85147. + dwc_setup_cb_t setup;
  85148. + dwc_completion_cb_t complete;
  85149. + dwc_isoc_completion_cb_t isoc_complete;
  85150. + dwc_suspend_cb_t suspend;
  85151. + dwc_sleep_cb_t sleep;
  85152. + dwc_resume_cb_t resume;
  85153. + dwc_reset_cb_t reset;
  85154. + dwc_hnp_params_changed_cb_t hnp_changed;
  85155. + cfi_setup_cb_t cfi_setup;
  85156. +#ifdef DWC_UTE_PER_IO
  85157. + xiso_completion_cb_t xisoc_complete;
  85158. +#endif
  85159. +};
  85160. +/** @} */
  85161. +
  85162. +/** @name Function Driver Functions */
  85163. +/** @{ */
  85164. +
  85165. +/** Call this function to get pointer on dwc_otg_pcd_t,
  85166. + * this pointer will be used for all PCD API functions.
  85167. + *
  85168. + * @param core_if The DWC_OTG Core
  85169. + */
  85170. +extern dwc_otg_pcd_t *dwc_otg_pcd_init(dwc_otg_core_if_t * core_if);
  85171. +
  85172. +/** Frees PCD allocated by dwc_otg_pcd_init
  85173. + *
  85174. + * @param pcd The PCD
  85175. + */
  85176. +extern void dwc_otg_pcd_remove(dwc_otg_pcd_t * pcd);
  85177. +
  85178. +/** Call this to bind the function driver to the PCD Core.
  85179. + *
  85180. + * @param pcd Pointer on dwc_otg_pcd_t returned by dwc_otg_pcd_init function.
  85181. + * @param fops The Function Driver Ops data structure containing pointers to all callbacks.
  85182. + */
  85183. +extern void dwc_otg_pcd_start(dwc_otg_pcd_t * pcd,
  85184. + const struct dwc_otg_pcd_function_ops *fops);
  85185. +
  85186. +/** Enables an endpoint for use. This function enables an endpoint in
  85187. + * the PCD. The endpoint is described by the ep_desc which has the
  85188. + * same format as a USB ep descriptor. The ep_handle parameter is used to refer
  85189. + * to the endpoint from other API functions and in callbacks. Normally this
  85190. + * should be called after a SET_CONFIGURATION/SET_INTERFACE to configure the
  85191. + * core for that interface.
  85192. + *
  85193. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  85194. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  85195. + * Returns 0 on success.
  85196. + *
  85197. + * @param pcd The PCD
  85198. + * @param ep_desc Endpoint descriptor
  85199. + * @param usb_ep Handle on endpoint, that will be used to identify endpoint.
  85200. + */
  85201. +extern int dwc_otg_pcd_ep_enable(dwc_otg_pcd_t * pcd,
  85202. + const uint8_t * ep_desc, void *usb_ep);
  85203. +
  85204. +/** Disable the endpoint referenced by ep_handle.
  85205. + *
  85206. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  85207. + * Returns -DWC_E_SHUTDOWN if any other error occurred.
  85208. + * Returns 0 on success. */
  85209. +extern int dwc_otg_pcd_ep_disable(dwc_otg_pcd_t * pcd, void *ep_handle);
  85210. +
  85211. +/** Queue a data transfer request on the endpoint referenced by ep_handle.
  85212. + * After the transfer is completes, the complete callback will be called with
  85213. + * the request status.
  85214. + *
  85215. + * @param pcd The PCD
  85216. + * @param ep_handle The handle of the endpoint
  85217. + * @param buf The buffer for the data
  85218. + * @param dma_buf The DMA buffer for the data
  85219. + * @param buflen The length of the data transfer
  85220. + * @param zero Specifies whether to send zero length last packet.
  85221. + * @param req_handle Set this handle to any value to use to reference this
  85222. + * request in the ep_dequeue function or from the complete callback
  85223. + * @param atomic_alloc If driver need to perform atomic allocations
  85224. + * for internal data structures.
  85225. + *
  85226. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  85227. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  85228. + * Returns 0 on success. */
  85229. +extern int dwc_otg_pcd_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  85230. + uint8_t * buf, dwc_dma_t dma_buf,
  85231. + uint32_t buflen, int zero, void *req_handle,
  85232. + int atomic_alloc);
  85233. +#ifdef DWC_UTE_PER_IO
  85234. +/**
  85235. + *
  85236. + * @param ereq_nonport Pointer to the extended request part of the
  85237. + * usb_request structure defined in usb_gadget.h file.
  85238. + */
  85239. +extern int dwc_otg_pcd_xiso_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  85240. + uint8_t * buf, dwc_dma_t dma_buf,
  85241. + uint32_t buflen, int zero,
  85242. + void *req_handle, int atomic_alloc,
  85243. + void *ereq_nonport);
  85244. +
  85245. +#endif
  85246. +
  85247. +/** De-queue the specified data transfer that has not yet completed.
  85248. + *
  85249. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  85250. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  85251. + * Returns 0 on success. */
  85252. +extern int dwc_otg_pcd_ep_dequeue(dwc_otg_pcd_t * pcd, void *ep_handle,
  85253. + void *req_handle);
  85254. +
  85255. +/** Halt (STALL) an endpoint or clear it.
  85256. + *
  85257. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  85258. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  85259. + * Returns -DWC_E_AGAIN if the STALL cannot be sent and must be tried again later
  85260. + * Returns 0 on success. */
  85261. +extern int dwc_otg_pcd_ep_halt(dwc_otg_pcd_t * pcd, void *ep_handle, int value);
  85262. +
  85263. +/** This function */
  85264. +extern int dwc_otg_pcd_ep_wedge(dwc_otg_pcd_t * pcd, void *ep_handle);
  85265. +
  85266. +/** This function should be called on every hardware interrupt */
  85267. +extern int32_t dwc_otg_pcd_handle_intr(dwc_otg_pcd_t * pcd);
  85268. +
  85269. +/** This function returns current frame number */
  85270. +extern int dwc_otg_pcd_get_frame_number(dwc_otg_pcd_t * pcd);
  85271. +
  85272. +/**
  85273. + * Start isochronous transfers on the endpoint referenced by ep_handle.
  85274. + * For isochronous transfers duble buffering is used.
  85275. + * After processing each of buffers comlete callback will be called with
  85276. + * status for each transaction.
  85277. + *
  85278. + * @param pcd The PCD
  85279. + * @param ep_handle The handle of the endpoint
  85280. + * @param buf0 The virtual address of first data buffer
  85281. + * @param buf1 The virtual address of second data buffer
  85282. + * @param dma0 The DMA address of first data buffer
  85283. + * @param dma1 The DMA address of second data buffer
  85284. + * @param sync_frame Data pattern frame number
  85285. + * @param dp_frame Data size for pattern frame
  85286. + * @param data_per_frame Data size for regular frame
  85287. + * @param start_frame Frame number to start transfers, if -1 then start transfers ASAP.
  85288. + * @param buf_proc_intrvl Interval of ISOC Buffer processing
  85289. + * @param req_handle Handle of ISOC request
  85290. + * @param atomic_alloc Specefies whether to perform atomic allocation for
  85291. + * internal data structures.
  85292. + *
  85293. + * Returns -DWC_E_NO_MEMORY if there is no enough memory.
  85294. + * Returns -DWC_E_INVALID if incorrect arguments are passed to the function.
  85295. + * Returns -DW_E_SHUTDOWN for any other error.
  85296. + * Returns 0 on success
  85297. + */
  85298. +extern int dwc_otg_pcd_iso_ep_start(dwc_otg_pcd_t * pcd, void *ep_handle,
  85299. + uint8_t * buf0, uint8_t * buf1,
  85300. + dwc_dma_t dma0, dwc_dma_t dma1,
  85301. + int sync_frame, int dp_frame,
  85302. + int data_per_frame, int start_frame,
  85303. + int buf_proc_intrvl, void *req_handle,
  85304. + int atomic_alloc);
  85305. +
  85306. +/** Stop ISOC transfers on endpoint referenced by ep_handle.
  85307. + *
  85308. + * @param pcd The PCD
  85309. + * @param ep_handle The handle of the endpoint
  85310. + * @param req_handle Handle of ISOC request
  85311. + *
  85312. + * Returns -DWC_E_INVALID if incorrect arguments are passed to the function
  85313. + * Returns 0 on success
  85314. + */
  85315. +int dwc_otg_pcd_iso_ep_stop(dwc_otg_pcd_t * pcd, void *ep_handle,
  85316. + void *req_handle);
  85317. +
  85318. +/** Get ISOC packet status.
  85319. + *
  85320. + * @param pcd The PCD
  85321. + * @param ep_handle The handle of the endpoint
  85322. + * @param iso_req_handle Isochronoush request handle
  85323. + * @param packet Number of packet
  85324. + * @param status Out parameter for returning status
  85325. + * @param actual Out parameter for returning actual length
  85326. + * @param offset Out parameter for returning offset
  85327. + *
  85328. + */
  85329. +extern void dwc_otg_pcd_get_iso_packet_params(dwc_otg_pcd_t * pcd,
  85330. + void *ep_handle,
  85331. + void *iso_req_handle, int packet,
  85332. + int *status, int *actual,
  85333. + int *offset);
  85334. +
  85335. +/** Get ISOC packet count.
  85336. + *
  85337. + * @param pcd The PCD
  85338. + * @param ep_handle The handle of the endpoint
  85339. + * @param iso_req_handle
  85340. + */
  85341. +extern int dwc_otg_pcd_get_iso_packet_count(dwc_otg_pcd_t * pcd,
  85342. + void *ep_handle,
  85343. + void *iso_req_handle);
  85344. +
  85345. +/** This function starts the SRP Protocol if no session is in progress. If
  85346. + * a session is already in progress, but the device is suspended,
  85347. + * remote wakeup signaling is started.
  85348. + */
  85349. +extern int dwc_otg_pcd_wakeup(dwc_otg_pcd_t * pcd);
  85350. +
  85351. +/** This function returns 1 if LPM support is enabled, and 0 otherwise. */
  85352. +extern int dwc_otg_pcd_is_lpm_enabled(dwc_otg_pcd_t * pcd);
  85353. +
  85354. +/** This function returns 1 if remote wakeup is allowed and 0, otherwise. */
  85355. +extern int dwc_otg_pcd_get_rmwkup_enable(dwc_otg_pcd_t * pcd);
  85356. +
  85357. +/** Initiate SRP */
  85358. +extern void dwc_otg_pcd_initiate_srp(dwc_otg_pcd_t * pcd);
  85359. +
  85360. +/** Starts remote wakeup signaling. */
  85361. +extern void dwc_otg_pcd_remote_wakeup(dwc_otg_pcd_t * pcd, int set);
  85362. +
  85363. +/** Starts micorsecond soft disconnect. */
  85364. +extern void dwc_otg_pcd_disconnect_us(dwc_otg_pcd_t * pcd, int no_of_usecs);
  85365. +/** This function returns whether device is dualspeed.*/
  85366. +extern uint32_t dwc_otg_pcd_is_dualspeed(dwc_otg_pcd_t * pcd);
  85367. +
  85368. +/** This function returns whether device is otg. */
  85369. +extern uint32_t dwc_otg_pcd_is_otg(dwc_otg_pcd_t * pcd);
  85370. +
  85371. +/** These functions allow to get hnp parameters */
  85372. +extern uint32_t get_b_hnp_enable(dwc_otg_pcd_t * pcd);
  85373. +extern uint32_t get_a_hnp_support(dwc_otg_pcd_t * pcd);
  85374. +extern uint32_t get_a_alt_hnp_support(dwc_otg_pcd_t * pcd);
  85375. +
  85376. +/** CFI specific Interface functions */
  85377. +/** Allocate a cfi buffer */
  85378. +extern uint8_t *cfiw_ep_alloc_buffer(dwc_otg_pcd_t * pcd, void *pep,
  85379. + dwc_dma_t * addr, size_t buflen,
  85380. + int flags);
  85381. +
  85382. +/******************************************************************************/
  85383. +
  85384. +/** @} */
  85385. +
  85386. +#endif /* __DWC_PCD_IF_H__ */
  85387. +
  85388. +#endif /* DWC_HOST_ONLY */
  85389. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c
  85390. --- linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c 1970-01-01 01:00:00.000000000 +0100
  85391. +++ linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c 2014-08-06 16:50:14.853965134 +0200
  85392. @@ -0,0 +1,5147 @@
  85393. +/* ==========================================================================
  85394. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd_intr.c $
  85395. + * $Revision: #116 $
  85396. + * $Date: 2012/08/10 $
  85397. + * $Change: 2047372 $
  85398. + *
  85399. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  85400. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  85401. + * otherwise expressly agreed to in writing between Synopsys and you.
  85402. + *
  85403. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  85404. + * any End User Software License Agreement or Agreement for Licensed Product
  85405. + * with Synopsys or any supplement thereto. You are permitted to use and
  85406. + * redistribute this Software in source and binary forms, with or without
  85407. + * modification, provided that redistributions of source code must retain this
  85408. + * notice. You may not view, use, disclose, copy or distribute this file or
  85409. + * any information contained herein except pursuant to this license grant from
  85410. + * Synopsys. If you do not agree with this notice, including the disclaimer
  85411. + * below, then you are not authorized to use the Software.
  85412. + *
  85413. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  85414. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  85415. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  85416. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  85417. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  85418. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  85419. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  85420. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  85421. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  85422. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  85423. + * DAMAGE.
  85424. + * ========================================================================== */
  85425. +#ifndef DWC_HOST_ONLY
  85426. +
  85427. +#include "dwc_otg_pcd.h"
  85428. +
  85429. +#ifdef DWC_UTE_CFI
  85430. +#include "dwc_otg_cfi.h"
  85431. +#endif
  85432. +
  85433. +#ifdef DWC_UTE_PER_IO
  85434. +extern void complete_xiso_ep(dwc_otg_pcd_ep_t * ep);
  85435. +#endif
  85436. +//#define PRINT_CFI_DMA_DESCS
  85437. +
  85438. +#define DEBUG_EP0
  85439. +
  85440. +/**
  85441. + * This function updates OTG.
  85442. + */
  85443. +static void dwc_otg_pcd_update_otg(dwc_otg_pcd_t * pcd, const unsigned reset)
  85444. +{
  85445. +
  85446. + if (reset) {
  85447. + pcd->b_hnp_enable = 0;
  85448. + pcd->a_hnp_support = 0;
  85449. + pcd->a_alt_hnp_support = 0;
  85450. + }
  85451. +
  85452. + if (pcd->fops->hnp_changed) {
  85453. + pcd->fops->hnp_changed(pcd);
  85454. + }
  85455. +}
  85456. +
  85457. +/** @file
  85458. + * This file contains the implementation of the PCD Interrupt handlers.
  85459. + *
  85460. + * The PCD handles the device interrupts. Many conditions can cause a
  85461. + * device interrupt. When an interrupt occurs, the device interrupt
  85462. + * service routine determines the cause of the interrupt and
  85463. + * dispatches handling to the appropriate function. These interrupt
  85464. + * handling functions are described below.
  85465. + * All interrupt registers are processed from LSB to MSB.
  85466. + */
  85467. +
  85468. +/**
  85469. + * This function prints the ep0 state for debug purposes.
  85470. + */
  85471. +static inline void print_ep0_state(dwc_otg_pcd_t * pcd)
  85472. +{
  85473. +#ifdef DEBUG
  85474. + char str[40];
  85475. +
  85476. + switch (pcd->ep0state) {
  85477. + case EP0_DISCONNECT:
  85478. + dwc_strcpy(str, "EP0_DISCONNECT");
  85479. + break;
  85480. + case EP0_IDLE:
  85481. + dwc_strcpy(str, "EP0_IDLE");
  85482. + break;
  85483. + case EP0_IN_DATA_PHASE:
  85484. + dwc_strcpy(str, "EP0_IN_DATA_PHASE");
  85485. + break;
  85486. + case EP0_OUT_DATA_PHASE:
  85487. + dwc_strcpy(str, "EP0_OUT_DATA_PHASE");
  85488. + break;
  85489. + case EP0_IN_STATUS_PHASE:
  85490. + dwc_strcpy(str, "EP0_IN_STATUS_PHASE");
  85491. + break;
  85492. + case EP0_OUT_STATUS_PHASE:
  85493. + dwc_strcpy(str, "EP0_OUT_STATUS_PHASE");
  85494. + break;
  85495. + case EP0_STALL:
  85496. + dwc_strcpy(str, "EP0_STALL");
  85497. + break;
  85498. + default:
  85499. + dwc_strcpy(str, "EP0_INVALID");
  85500. + }
  85501. +
  85502. + DWC_DEBUGPL(DBG_ANY, "%s(%d)\n", str, pcd->ep0state);
  85503. +#endif
  85504. +}
  85505. +
  85506. +/**
  85507. + * This function calculate the size of the payload in the memory
  85508. + * for out endpoints and prints size for debug purposes(used in
  85509. + * 2.93a DevOutNak feature).
  85510. + */
  85511. +static inline void print_memory_payload(dwc_otg_pcd_t * pcd, dwc_ep_t * ep)
  85512. +{
  85513. +#ifdef DEBUG
  85514. + deptsiz_data_t deptsiz_init = {.d32 = 0 };
  85515. + deptsiz_data_t deptsiz_updt = {.d32 = 0 };
  85516. + int pack_num;
  85517. + unsigned payload;
  85518. +
  85519. + deptsiz_init.d32 = pcd->core_if->start_doeptsiz_val[ep->num];
  85520. + deptsiz_updt.d32 =
  85521. + DWC_READ_REG32(&pcd->core_if->dev_if->
  85522. + out_ep_regs[ep->num]->doeptsiz);
  85523. + /* Payload will be */
  85524. + payload = deptsiz_init.b.xfersize - deptsiz_updt.b.xfersize;
  85525. + /* Packet count is decremented every time a packet
  85526. + * is written to the RxFIFO not in to the external memory
  85527. + * So, if payload == 0, then it means no packet was sent to ext memory*/
  85528. + pack_num = (!payload) ? 0 : (deptsiz_init.b.pktcnt - deptsiz_updt.b.pktcnt);
  85529. + DWC_DEBUGPL(DBG_PCDV,
  85530. + "Payload for EP%d-%s\n",
  85531. + ep->num, (ep->is_in ? "IN" : "OUT"));
  85532. + DWC_DEBUGPL(DBG_PCDV,
  85533. + "Number of transfered bytes = 0x%08x\n", payload);
  85534. + DWC_DEBUGPL(DBG_PCDV,
  85535. + "Number of transfered packets = %d\n", pack_num);
  85536. +#endif
  85537. +}
  85538. +
  85539. +
  85540. +#ifdef DWC_UTE_CFI
  85541. +static inline void print_desc(struct dwc_otg_dma_desc *ddesc,
  85542. + const uint8_t * epname, int descnum)
  85543. +{
  85544. + CFI_INFO
  85545. + ("%s DMA_DESC(%d) buf=0x%08x bytes=0x%04x; sp=0x%x; l=0x%x; sts=0x%02x; bs=0x%02x\n",
  85546. + epname, descnum, ddesc->buf, ddesc->status.b.bytes,
  85547. + ddesc->status.b.sp, ddesc->status.b.l, ddesc->status.b.sts,
  85548. + ddesc->status.b.bs);
  85549. +}
  85550. +#endif
  85551. +
  85552. +/**
  85553. + * This function returns pointer to in ep struct with number ep_num
  85554. + */
  85555. +static inline dwc_otg_pcd_ep_t *get_in_ep(dwc_otg_pcd_t * pcd, uint32_t ep_num)
  85556. +{
  85557. + int i;
  85558. + int num_in_eps = GET_CORE_IF(pcd)->dev_if->num_in_eps;
  85559. + if (ep_num == 0) {
  85560. + return &pcd->ep0;
  85561. + } else {
  85562. + for (i = 0; i < num_in_eps; ++i) {
  85563. + if (pcd->in_ep[i].dwc_ep.num == ep_num)
  85564. + return &pcd->in_ep[i];
  85565. + }
  85566. + return 0;
  85567. + }
  85568. +}
  85569. +
  85570. +/**
  85571. + * This function returns pointer to out ep struct with number ep_num
  85572. + */
  85573. +static inline dwc_otg_pcd_ep_t *get_out_ep(dwc_otg_pcd_t * pcd, uint32_t ep_num)
  85574. +{
  85575. + int i;
  85576. + int num_out_eps = GET_CORE_IF(pcd)->dev_if->num_out_eps;
  85577. + if (ep_num == 0) {
  85578. + return &pcd->ep0;
  85579. + } else {
  85580. + for (i = 0; i < num_out_eps; ++i) {
  85581. + if (pcd->out_ep[i].dwc_ep.num == ep_num)
  85582. + return &pcd->out_ep[i];
  85583. + }
  85584. + return 0;
  85585. + }
  85586. +}
  85587. +
  85588. +/**
  85589. + * This functions gets a pointer to an EP from the wIndex address
  85590. + * value of the control request.
  85591. + */
  85592. +dwc_otg_pcd_ep_t *get_ep_by_addr(dwc_otg_pcd_t * pcd, u16 wIndex)
  85593. +{
  85594. + dwc_otg_pcd_ep_t *ep;
  85595. + uint32_t ep_num = UE_GET_ADDR(wIndex);
  85596. +
  85597. + if (ep_num == 0) {
  85598. + ep = &pcd->ep0;
  85599. + } else if (UE_GET_DIR(wIndex) == UE_DIR_IN) { /* in ep */
  85600. + ep = &pcd->in_ep[ep_num - 1];
  85601. + } else {
  85602. + ep = &pcd->out_ep[ep_num - 1];
  85603. + }
  85604. +
  85605. + return ep;
  85606. +}
  85607. +
  85608. +/**
  85609. + * This function checks the EP request queue, if the queue is not
  85610. + * empty the next request is started.
  85611. + */
  85612. +void start_next_request(dwc_otg_pcd_ep_t * ep)
  85613. +{
  85614. + dwc_otg_pcd_request_t *req = 0;
  85615. + uint32_t max_transfer =
  85616. + GET_CORE_IF(ep->pcd)->core_params->max_transfer_size;
  85617. +
  85618. +#ifdef DWC_UTE_CFI
  85619. + struct dwc_otg_pcd *pcd;
  85620. + pcd = ep->pcd;
  85621. +#endif
  85622. +
  85623. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  85624. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  85625. +
  85626. +#ifdef DWC_UTE_CFI
  85627. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  85628. + ep->dwc_ep.cfi_req_len = req->length;
  85629. + pcd->cfi->ops.build_descriptors(pcd->cfi, pcd, ep, req);
  85630. + } else {
  85631. +#endif
  85632. + /* Setup and start the Transfer */
  85633. + if (req->dw_align_buf) {
  85634. + ep->dwc_ep.dma_addr = req->dw_align_buf_dma;
  85635. + ep->dwc_ep.start_xfer_buff = req->dw_align_buf;
  85636. + ep->dwc_ep.xfer_buff = req->dw_align_buf;
  85637. + } else {
  85638. + ep->dwc_ep.dma_addr = req->dma;
  85639. + ep->dwc_ep.start_xfer_buff = req->buf;
  85640. + ep->dwc_ep.xfer_buff = req->buf;
  85641. + }
  85642. + ep->dwc_ep.sent_zlp = 0;
  85643. + ep->dwc_ep.total_len = req->length;
  85644. + ep->dwc_ep.xfer_len = 0;
  85645. + ep->dwc_ep.xfer_count = 0;
  85646. +
  85647. + ep->dwc_ep.maxxfer = max_transfer;
  85648. + if (GET_CORE_IF(ep->pcd)->dma_desc_enable) {
  85649. + uint32_t out_max_xfer = DDMA_MAX_TRANSFER_SIZE
  85650. + - (DDMA_MAX_TRANSFER_SIZE % 4);
  85651. + if (ep->dwc_ep.is_in) {
  85652. + if (ep->dwc_ep.maxxfer >
  85653. + DDMA_MAX_TRANSFER_SIZE) {
  85654. + ep->dwc_ep.maxxfer =
  85655. + DDMA_MAX_TRANSFER_SIZE;
  85656. + }
  85657. + } else {
  85658. + if (ep->dwc_ep.maxxfer > out_max_xfer) {
  85659. + ep->dwc_ep.maxxfer =
  85660. + out_max_xfer;
  85661. + }
  85662. + }
  85663. + }
  85664. + if (ep->dwc_ep.maxxfer < ep->dwc_ep.total_len) {
  85665. + ep->dwc_ep.maxxfer -=
  85666. + (ep->dwc_ep.maxxfer % ep->dwc_ep.maxpacket);
  85667. + }
  85668. + if (req->sent_zlp) {
  85669. + if ((ep->dwc_ep.total_len %
  85670. + ep->dwc_ep.maxpacket == 0)
  85671. + && (ep->dwc_ep.total_len != 0)) {
  85672. + ep->dwc_ep.sent_zlp = 1;
  85673. + }
  85674. +
  85675. + }
  85676. +#ifdef DWC_UTE_CFI
  85677. + }
  85678. +#endif
  85679. + dwc_otg_ep_start_transfer(GET_CORE_IF(ep->pcd), &ep->dwc_ep);
  85680. + } else if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  85681. + DWC_PRINTF("There are no more ISOC requests \n");
  85682. + ep->dwc_ep.frame_num = 0xFFFFFFFF;
  85683. + }
  85684. +}
  85685. +
  85686. +/**
  85687. + * This function handles the SOF Interrupts. At this time the SOF
  85688. + * Interrupt is disabled.
  85689. + */
  85690. +int32_t dwc_otg_pcd_handle_sof_intr(dwc_otg_pcd_t * pcd)
  85691. +{
  85692. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  85693. +
  85694. + gintsts_data_t gintsts;
  85695. +
  85696. + DWC_DEBUGPL(DBG_PCD, "SOF\n");
  85697. +
  85698. + /* Clear interrupt */
  85699. + gintsts.d32 = 0;
  85700. + gintsts.b.sofintr = 1;
  85701. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  85702. +
  85703. + return 1;
  85704. +}
  85705. +
  85706. +/**
  85707. + * This function handles the Rx Status Queue Level Interrupt, which
  85708. + * indicates that there is a least one packet in the Rx FIFO. The
  85709. + * packets are moved from the FIFO to memory, where they will be
  85710. + * processed when the Endpoint Interrupt Register indicates Transfer
  85711. + * Complete or SETUP Phase Done.
  85712. + *
  85713. + * Repeat the following until the Rx Status Queue is empty:
  85714. + * -# Read the Receive Status Pop Register (GRXSTSP) to get Packet
  85715. + * info
  85716. + * -# If Receive FIFO is empty then skip to step Clear the interrupt
  85717. + * and exit
  85718. + * -# If SETUP Packet call dwc_otg_read_setup_packet to copy the
  85719. + * SETUP data to the buffer
  85720. + * -# If OUT Data Packet call dwc_otg_read_packet to copy the data
  85721. + * to the destination buffer
  85722. + */
  85723. +int32_t dwc_otg_pcd_handle_rx_status_q_level_intr(dwc_otg_pcd_t * pcd)
  85724. +{
  85725. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  85726. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  85727. + gintmsk_data_t gintmask = {.d32 = 0 };
  85728. + device_grxsts_data_t status;
  85729. + dwc_otg_pcd_ep_t *ep;
  85730. + gintsts_data_t gintsts;
  85731. +#ifdef DEBUG
  85732. + static char *dpid_str[] = { "D0", "D2", "D1", "MDATA" };
  85733. +#endif
  85734. +
  85735. + //DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, _pcd);
  85736. + /* Disable the Rx Status Queue Level interrupt */
  85737. + gintmask.b.rxstsqlvl = 1;
  85738. + DWC_MODIFY_REG32(&global_regs->gintmsk, gintmask.d32, 0);
  85739. +
  85740. + /* Get the Status from the top of the FIFO */
  85741. + status.d32 = DWC_READ_REG32(&global_regs->grxstsp);
  85742. +
  85743. + DWC_DEBUGPL(DBG_PCD, "EP:%d BCnt:%d DPID:%s "
  85744. + "pktsts:%x Frame:%d(0x%0x)\n",
  85745. + status.b.epnum, status.b.bcnt,
  85746. + dpid_str[status.b.dpid],
  85747. + status.b.pktsts, status.b.fn, status.b.fn);
  85748. + /* Get pointer to EP structure */
  85749. + ep = get_out_ep(pcd, status.b.epnum);
  85750. +
  85751. + switch (status.b.pktsts) {
  85752. + case DWC_DSTS_GOUT_NAK:
  85753. + DWC_DEBUGPL(DBG_PCDV, "Global OUT NAK\n");
  85754. + break;
  85755. + case DWC_STS_DATA_UPDT:
  85756. + DWC_DEBUGPL(DBG_PCDV, "OUT Data Packet\n");
  85757. + if (status.b.bcnt && ep->dwc_ep.xfer_buff) {
  85758. + /** @todo NGS Check for buffer overflow? */
  85759. + dwc_otg_read_packet(core_if,
  85760. + ep->dwc_ep.xfer_buff,
  85761. + status.b.bcnt);
  85762. + ep->dwc_ep.xfer_count += status.b.bcnt;
  85763. + ep->dwc_ep.xfer_buff += status.b.bcnt;
  85764. + }
  85765. + break;
  85766. + case DWC_STS_XFER_COMP:
  85767. + DWC_DEBUGPL(DBG_PCDV, "OUT Complete\n");
  85768. + break;
  85769. + case DWC_DSTS_SETUP_COMP:
  85770. +#ifdef DEBUG_EP0
  85771. + DWC_DEBUGPL(DBG_PCDV, "Setup Complete\n");
  85772. +#endif
  85773. + break;
  85774. + case DWC_DSTS_SETUP_UPDT:
  85775. + dwc_otg_read_setup_packet(core_if, pcd->setup_pkt->d32);
  85776. +#ifdef DEBUG_EP0
  85777. + DWC_DEBUGPL(DBG_PCD,
  85778. + "SETUP PKT: %02x.%02x v%04x i%04x l%04x\n",
  85779. + pcd->setup_pkt->req.bmRequestType,
  85780. + pcd->setup_pkt->req.bRequest,
  85781. + UGETW(pcd->setup_pkt->req.wValue),
  85782. + UGETW(pcd->setup_pkt->req.wIndex),
  85783. + UGETW(pcd->setup_pkt->req.wLength));
  85784. +#endif
  85785. + ep->dwc_ep.xfer_count += status.b.bcnt;
  85786. + break;
  85787. + default:
  85788. + DWC_DEBUGPL(DBG_PCDV, "Invalid Packet Status (0x%0x)\n",
  85789. + status.b.pktsts);
  85790. + break;
  85791. + }
  85792. +
  85793. + /* Enable the Rx Status Queue Level interrupt */
  85794. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmask.d32);
  85795. + /* Clear interrupt */
  85796. + gintsts.d32 = 0;
  85797. + gintsts.b.rxstsqlvl = 1;
  85798. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  85799. +
  85800. + //DWC_DEBUGPL(DBG_PCDV, "EXIT: %s\n", __func__);
  85801. + return 1;
  85802. +}
  85803. +
  85804. +/**
  85805. + * This function examines the Device IN Token Learning Queue to
  85806. + * determine the EP number of the last IN token received. This
  85807. + * implementation is for the Mass Storage device where there are only
  85808. + * 2 IN EPs (Control-IN and BULK-IN).
  85809. + *
  85810. + * The EP numbers for the first six IN Tokens are in DTKNQR1 and there
  85811. + * are 8 EP Numbers in each of the other possible DTKNQ Registers.
  85812. + *
  85813. + * @param core_if Programming view of DWC_otg controller.
  85814. + *
  85815. + */
  85816. +static inline int get_ep_of_last_in_token(dwc_otg_core_if_t * core_if)
  85817. +{
  85818. + dwc_otg_device_global_regs_t *dev_global_regs =
  85819. + core_if->dev_if->dev_global_regs;
  85820. + const uint32_t TOKEN_Q_DEPTH = core_if->hwcfg2.b.dev_token_q_depth;
  85821. + /* Number of Token Queue Registers */
  85822. + const int DTKNQ_REG_CNT = (TOKEN_Q_DEPTH + 7) / 8;
  85823. + dtknq1_data_t dtknqr1;
  85824. + uint32_t in_tkn_epnums[4];
  85825. + int ndx = 0;
  85826. + int i = 0;
  85827. + volatile uint32_t *addr = &dev_global_regs->dtknqr1;
  85828. + int epnum = 0;
  85829. +
  85830. + //DWC_DEBUGPL(DBG_PCD,"dev_token_q_depth=%d\n",TOKEN_Q_DEPTH);
  85831. +
  85832. + /* Read the DTKNQ Registers */
  85833. + for (i = 0; i < DTKNQ_REG_CNT; i++) {
  85834. + in_tkn_epnums[i] = DWC_READ_REG32(addr);
  85835. + DWC_DEBUGPL(DBG_PCDV, "DTKNQR%d=0x%08x\n", i + 1,
  85836. + in_tkn_epnums[i]);
  85837. + if (addr == &dev_global_regs->dvbusdis) {
  85838. + addr = &dev_global_regs->dtknqr3_dthrctl;
  85839. + } else {
  85840. + ++addr;
  85841. + }
  85842. +
  85843. + }
  85844. +
  85845. + /* Copy the DTKNQR1 data to the bit field. */
  85846. + dtknqr1.d32 = in_tkn_epnums[0];
  85847. + /* Get the EP numbers */
  85848. + in_tkn_epnums[0] = dtknqr1.b.epnums0_5;
  85849. + ndx = dtknqr1.b.intknwptr - 1;
  85850. +
  85851. + //DWC_DEBUGPL(DBG_PCDV,"ndx=%d\n",ndx);
  85852. + if (ndx == -1) {
  85853. + /** @todo Find a simpler way to calculate the max
  85854. + * queue position.*/
  85855. + int cnt = TOKEN_Q_DEPTH;
  85856. + if (TOKEN_Q_DEPTH <= 6) {
  85857. + cnt = TOKEN_Q_DEPTH - 1;
  85858. + } else if (TOKEN_Q_DEPTH <= 14) {
  85859. + cnt = TOKEN_Q_DEPTH - 7;
  85860. + } else if (TOKEN_Q_DEPTH <= 22) {
  85861. + cnt = TOKEN_Q_DEPTH - 15;
  85862. + } else {
  85863. + cnt = TOKEN_Q_DEPTH - 23;
  85864. + }
  85865. + epnum = (in_tkn_epnums[DTKNQ_REG_CNT - 1] >> (cnt * 4)) & 0xF;
  85866. + } else {
  85867. + if (ndx <= 5) {
  85868. + epnum = (in_tkn_epnums[0] >> (ndx * 4)) & 0xF;
  85869. + } else if (ndx <= 13) {
  85870. + ndx -= 6;
  85871. + epnum = (in_tkn_epnums[1] >> (ndx * 4)) & 0xF;
  85872. + } else if (ndx <= 21) {
  85873. + ndx -= 14;
  85874. + epnum = (in_tkn_epnums[2] >> (ndx * 4)) & 0xF;
  85875. + } else if (ndx <= 29) {
  85876. + ndx -= 22;
  85877. + epnum = (in_tkn_epnums[3] >> (ndx * 4)) & 0xF;
  85878. + }
  85879. + }
  85880. + //DWC_DEBUGPL(DBG_PCD,"epnum=%d\n",epnum);
  85881. + return epnum;
  85882. +}
  85883. +
  85884. +/**
  85885. + * This interrupt occurs when the non-periodic Tx FIFO is half-empty.
  85886. + * The active request is checked for the next packet to be loaded into
  85887. + * the non-periodic Tx FIFO.
  85888. + */
  85889. +int32_t dwc_otg_pcd_handle_np_tx_fifo_empty_intr(dwc_otg_pcd_t * pcd)
  85890. +{
  85891. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  85892. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  85893. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  85894. + gnptxsts_data_t txstatus = {.d32 = 0 };
  85895. + gintsts_data_t gintsts;
  85896. +
  85897. + int epnum = 0;
  85898. + dwc_otg_pcd_ep_t *ep = 0;
  85899. + uint32_t len = 0;
  85900. + int dwords;
  85901. +
  85902. + /* Get the epnum from the IN Token Learning Queue. */
  85903. + epnum = get_ep_of_last_in_token(core_if);
  85904. + ep = get_in_ep(pcd, epnum);
  85905. +
  85906. + DWC_DEBUGPL(DBG_PCD, "NP TxFifo Empty: %d \n", epnum);
  85907. +
  85908. + ep_regs = core_if->dev_if->in_ep_regs[epnum];
  85909. +
  85910. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  85911. + if (len > ep->dwc_ep.maxpacket) {
  85912. + len = ep->dwc_ep.maxpacket;
  85913. + }
  85914. + dwords = (len + 3) / 4;
  85915. +
  85916. + /* While there is space in the queue and space in the FIFO and
  85917. + * More data to tranfer, Write packets to the Tx FIFO */
  85918. + txstatus.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  85919. + DWC_DEBUGPL(DBG_PCDV, "b4 GNPTXSTS=0x%08x\n", txstatus.d32);
  85920. +
  85921. + while (txstatus.b.nptxqspcavail > 0 &&
  85922. + txstatus.b.nptxfspcavail > dwords &&
  85923. + ep->dwc_ep.xfer_count < ep->dwc_ep.xfer_len) {
  85924. + /* Write the FIFO */
  85925. + dwc_otg_ep_write_packet(core_if, &ep->dwc_ep, 0);
  85926. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  85927. +
  85928. + if (len > ep->dwc_ep.maxpacket) {
  85929. + len = ep->dwc_ep.maxpacket;
  85930. + }
  85931. +
  85932. + dwords = (len + 3) / 4;
  85933. + txstatus.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  85934. + DWC_DEBUGPL(DBG_PCDV, "GNPTXSTS=0x%08x\n", txstatus.d32);
  85935. + }
  85936. +
  85937. + DWC_DEBUGPL(DBG_PCDV, "GNPTXSTS=0x%08x\n",
  85938. + DWC_READ_REG32(&global_regs->gnptxsts));
  85939. +
  85940. + /* Clear interrupt */
  85941. + gintsts.d32 = 0;
  85942. + gintsts.b.nptxfempty = 1;
  85943. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  85944. +
  85945. + return 1;
  85946. +}
  85947. +
  85948. +/**
  85949. + * This function is called when dedicated Tx FIFO Empty interrupt occurs.
  85950. + * The active request is checked for the next packet to be loaded into
  85951. + * apropriate Tx FIFO.
  85952. + */
  85953. +static int32_t write_empty_tx_fifo(dwc_otg_pcd_t * pcd, uint32_t epnum)
  85954. +{
  85955. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  85956. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  85957. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  85958. + dtxfsts_data_t txstatus = {.d32 = 0 };
  85959. + dwc_otg_pcd_ep_t *ep = 0;
  85960. + uint32_t len = 0;
  85961. + int dwords;
  85962. +
  85963. + ep = get_in_ep(pcd, epnum);
  85964. +
  85965. + DWC_DEBUGPL(DBG_PCD, "Dedicated TxFifo Empty: %d \n", epnum);
  85966. +
  85967. + ep_regs = core_if->dev_if->in_ep_regs[epnum];
  85968. +
  85969. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  85970. +
  85971. + if (len > ep->dwc_ep.maxpacket) {
  85972. + len = ep->dwc_ep.maxpacket;
  85973. + }
  85974. +
  85975. + dwords = (len + 3) / 4;
  85976. +
  85977. + /* While there is space in the queue and space in the FIFO and
  85978. + * More data to tranfer, Write packets to the Tx FIFO */
  85979. + txstatus.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  85980. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum, txstatus.d32);
  85981. +
  85982. + while (txstatus.b.txfspcavail > dwords &&
  85983. + ep->dwc_ep.xfer_count < ep->dwc_ep.xfer_len &&
  85984. + ep->dwc_ep.xfer_len != 0) {
  85985. + /* Write the FIFO */
  85986. + dwc_otg_ep_write_packet(core_if, &ep->dwc_ep, 0);
  85987. +
  85988. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  85989. + if (len > ep->dwc_ep.maxpacket) {
  85990. + len = ep->dwc_ep.maxpacket;
  85991. + }
  85992. +
  85993. + dwords = (len + 3) / 4;
  85994. + txstatus.d32 =
  85995. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  85996. + DWC_DEBUGPL(DBG_PCDV, "dtxfsts[%d]=0x%08x\n", epnum,
  85997. + txstatus.d32);
  85998. + }
  85999. +
  86000. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum,
  86001. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts));
  86002. +
  86003. + return 1;
  86004. +}
  86005. +
  86006. +/**
  86007. + * This function is called when the Device is disconnected. It stops
  86008. + * any active requests and informs the Gadget driver of the
  86009. + * disconnect.
  86010. + */
  86011. +void dwc_otg_pcd_stop(dwc_otg_pcd_t * pcd)
  86012. +{
  86013. + int i, num_in_eps, num_out_eps;
  86014. + dwc_otg_pcd_ep_t *ep;
  86015. +
  86016. + gintmsk_data_t intr_mask = {.d32 = 0 };
  86017. +
  86018. + DWC_SPINLOCK(pcd->lock);
  86019. +
  86020. + num_in_eps = GET_CORE_IF(pcd)->dev_if->num_in_eps;
  86021. + num_out_eps = GET_CORE_IF(pcd)->dev_if->num_out_eps;
  86022. +
  86023. + DWC_DEBUGPL(DBG_PCDV, "%s() \n", __func__);
  86024. + /* don't disconnect drivers more than once */
  86025. + if (pcd->ep0state == EP0_DISCONNECT) {
  86026. + DWC_DEBUGPL(DBG_ANY, "%s() Already Disconnected\n", __func__);
  86027. + DWC_SPINUNLOCK(pcd->lock);
  86028. + return;
  86029. + }
  86030. + pcd->ep0state = EP0_DISCONNECT;
  86031. +
  86032. + /* Reset the OTG state. */
  86033. + dwc_otg_pcd_update_otg(pcd, 1);
  86034. +
  86035. + /* Disable the NP Tx Fifo Empty Interrupt. */
  86036. + intr_mask.b.nptxfempty = 1;
  86037. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  86038. + intr_mask.d32, 0);
  86039. +
  86040. + /* Flush the FIFOs */
  86041. + /**@todo NGS Flush Periodic FIFOs */
  86042. + dwc_otg_flush_tx_fifo(GET_CORE_IF(pcd), 0x10);
  86043. + dwc_otg_flush_rx_fifo(GET_CORE_IF(pcd));
  86044. +
  86045. + /* prevent new request submissions, kill any outstanding requests */
  86046. + ep = &pcd->ep0;
  86047. + dwc_otg_request_nuke(ep);
  86048. + /* prevent new request submissions, kill any outstanding requests */
  86049. + for (i = 0; i < num_in_eps; i++) {
  86050. + dwc_otg_pcd_ep_t *ep = &pcd->in_ep[i];
  86051. + dwc_otg_request_nuke(ep);
  86052. + }
  86053. + /* prevent new request submissions, kill any outstanding requests */
  86054. + for (i = 0; i < num_out_eps; i++) {
  86055. + dwc_otg_pcd_ep_t *ep = &pcd->out_ep[i];
  86056. + dwc_otg_request_nuke(ep);
  86057. + }
  86058. +
  86059. + /* report disconnect; the driver is already quiesced */
  86060. + if (pcd->fops->disconnect) {
  86061. + DWC_SPINUNLOCK(pcd->lock);
  86062. + pcd->fops->disconnect(pcd);
  86063. + DWC_SPINLOCK(pcd->lock);
  86064. + }
  86065. + DWC_SPINUNLOCK(pcd->lock);
  86066. +}
  86067. +
  86068. +/**
  86069. + * This interrupt indicates that ...
  86070. + */
  86071. +int32_t dwc_otg_pcd_handle_i2c_intr(dwc_otg_pcd_t * pcd)
  86072. +{
  86073. + gintmsk_data_t intr_mask = {.d32 = 0 };
  86074. + gintsts_data_t gintsts;
  86075. +
  86076. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "i2cintr");
  86077. + intr_mask.b.i2cintr = 1;
  86078. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  86079. + intr_mask.d32, 0);
  86080. +
  86081. + /* Clear interrupt */
  86082. + gintsts.d32 = 0;
  86083. + gintsts.b.i2cintr = 1;
  86084. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  86085. + gintsts.d32);
  86086. + return 1;
  86087. +}
  86088. +
  86089. +/**
  86090. + * This interrupt indicates that ...
  86091. + */
  86092. +int32_t dwc_otg_pcd_handle_early_suspend_intr(dwc_otg_pcd_t * pcd)
  86093. +{
  86094. + gintsts_data_t gintsts;
  86095. +#if defined(VERBOSE)
  86096. + DWC_PRINTF("Early Suspend Detected\n");
  86097. +#endif
  86098. +
  86099. + /* Clear interrupt */
  86100. + gintsts.d32 = 0;
  86101. + gintsts.b.erlysuspend = 1;
  86102. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  86103. + gintsts.d32);
  86104. + return 1;
  86105. +}
  86106. +
  86107. +/**
  86108. + * This function configures EPO to receive SETUP packets.
  86109. + *
  86110. + * @todo NGS: Update the comments from the HW FS.
  86111. + *
  86112. + * -# Program the following fields in the endpoint specific registers
  86113. + * for Control OUT EP 0, in order to receive a setup packet
  86114. + * - DOEPTSIZ0.Packet Count = 3 (To receive up to 3 back to back
  86115. + * setup packets)
  86116. + * - DOEPTSIZE0.Transfer Size = 24 Bytes (To receive up to 3 back
  86117. + * to back setup packets)
  86118. + * - In DMA mode, DOEPDMA0 Register with a memory address to
  86119. + * store any setup packets received
  86120. + *
  86121. + * @param core_if Programming view of DWC_otg controller.
  86122. + * @param pcd Programming view of the PCD.
  86123. + */
  86124. +static inline void ep0_out_start(dwc_otg_core_if_t * core_if,
  86125. + dwc_otg_pcd_t * pcd)
  86126. +{
  86127. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  86128. + deptsiz0_data_t doeptsize0 = {.d32 = 0 };
  86129. + dwc_otg_dev_dma_desc_t *dma_desc;
  86130. + depctl_data_t doepctl = {.d32 = 0 };
  86131. +
  86132. +#ifdef VERBOSE
  86133. + DWC_DEBUGPL(DBG_PCDV, "%s() doepctl0=%0x\n", __func__,
  86134. + DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl));
  86135. +#endif
  86136. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  86137. + doepctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl);
  86138. + if (doepctl.b.epena) {
  86139. + return;
  86140. + }
  86141. + }
  86142. +
  86143. + doeptsize0.b.supcnt = 3;
  86144. + doeptsize0.b.pktcnt = 1;
  86145. + doeptsize0.b.xfersize = 8 * 3;
  86146. +
  86147. + if (core_if->dma_enable) {
  86148. + if (!core_if->dma_desc_enable) {
  86149. + /** put here as for Hermes mode deptisz register should not be written */
  86150. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doeptsiz,
  86151. + doeptsize0.d32);
  86152. +
  86153. + /** @todo dma needs to handle multiple setup packets (up to 3) */
  86154. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepdma,
  86155. + pcd->setup_pkt_dma_handle);
  86156. + } else {
  86157. + dev_if->setup_desc_index =
  86158. + (dev_if->setup_desc_index + 1) & 1;
  86159. + dma_desc =
  86160. + dev_if->setup_desc_addr[dev_if->setup_desc_index];
  86161. +
  86162. + /** DMA Descriptor Setup */
  86163. + dma_desc->status.b.bs = BS_HOST_BUSY;
  86164. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  86165. + dma_desc->status.b.sr = 0;
  86166. + dma_desc->status.b.mtrf = 0;
  86167. + }
  86168. + dma_desc->status.b.l = 1;
  86169. + dma_desc->status.b.ioc = 1;
  86170. + dma_desc->status.b.bytes = pcd->ep0.dwc_ep.maxpacket;
  86171. + dma_desc->buf = pcd->setup_pkt_dma_handle;
  86172. + dma_desc->status.b.sts = 0;
  86173. + dma_desc->status.b.bs = BS_HOST_READY;
  86174. +
  86175. + /** DOEPDMA0 Register write */
  86176. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepdma,
  86177. + dev_if->dma_setup_desc_addr
  86178. + [dev_if->setup_desc_index]);
  86179. + }
  86180. +
  86181. + } else {
  86182. + /** put here as for Hermes mode deptisz register should not be written */
  86183. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doeptsiz,
  86184. + doeptsize0.d32);
  86185. + }
  86186. +
  86187. + /** DOEPCTL0 Register write cnak will be set after setup interrupt */
  86188. + doepctl.d32 = 0;
  86189. + doepctl.b.epena = 1;
  86190. + if (core_if->snpsid <= OTG_CORE_REV_2_94a) {
  86191. + doepctl.b.cnak = 1;
  86192. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepctl, doepctl.d32);
  86193. + } else {
  86194. + DWC_MODIFY_REG32(&dev_if->out_ep_regs[0]->doepctl, 0, doepctl.d32);
  86195. + }
  86196. +
  86197. +#ifdef VERBOSE
  86198. + DWC_DEBUGPL(DBG_PCDV, "doepctl0=%0x\n",
  86199. + DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl));
  86200. + DWC_DEBUGPL(DBG_PCDV, "diepctl0=%0x\n",
  86201. + DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl));
  86202. +#endif
  86203. +}
  86204. +
  86205. +/**
  86206. + * This interrupt occurs when a USB Reset is detected. When the USB
  86207. + * Reset Interrupt occurs the device state is set to DEFAULT and the
  86208. + * EP0 state is set to IDLE.
  86209. + * -# Set the NAK bit for all OUT endpoints (DOEPCTLn.SNAK = 1)
  86210. + * -# Unmask the following interrupt bits
  86211. + * - DAINTMSK.INEP0 = 1 (Control 0 IN endpoint)
  86212. + * - DAINTMSK.OUTEP0 = 1 (Control 0 OUT endpoint)
  86213. + * - DOEPMSK.SETUP = 1
  86214. + * - DOEPMSK.XferCompl = 1
  86215. + * - DIEPMSK.XferCompl = 1
  86216. + * - DIEPMSK.TimeOut = 1
  86217. + * -# Program the following fields in the endpoint specific registers
  86218. + * for Control OUT EP 0, in order to receive a setup packet
  86219. + * - DOEPTSIZ0.Packet Count = 3 (To receive up to 3 back to back
  86220. + * setup packets)
  86221. + * - DOEPTSIZE0.Transfer Size = 24 Bytes (To receive up to 3 back
  86222. + * to back setup packets)
  86223. + * - In DMA mode, DOEPDMA0 Register with a memory address to
  86224. + * store any setup packets received
  86225. + * At this point, all the required initialization, except for enabling
  86226. + * the control 0 OUT endpoint is done, for receiving SETUP packets.
  86227. + */
  86228. +int32_t dwc_otg_pcd_handle_usb_reset_intr(dwc_otg_pcd_t * pcd)
  86229. +{
  86230. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  86231. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  86232. + depctl_data_t doepctl = {.d32 = 0 };
  86233. + depctl_data_t diepctl = {.d32 = 0 };
  86234. + daint_data_t daintmsk = {.d32 = 0 };
  86235. + doepmsk_data_t doepmsk = {.d32 = 0 };
  86236. + diepmsk_data_t diepmsk = {.d32 = 0 };
  86237. + dcfg_data_t dcfg = {.d32 = 0 };
  86238. + grstctl_t resetctl = {.d32 = 0 };
  86239. + dctl_data_t dctl = {.d32 = 0 };
  86240. + int i = 0;
  86241. + gintsts_data_t gintsts;
  86242. + pcgcctl_data_t power = {.d32 = 0 };
  86243. +
  86244. + power.d32 = DWC_READ_REG32(core_if->pcgcctl);
  86245. + if (power.b.stoppclk) {
  86246. + power.d32 = 0;
  86247. + power.b.stoppclk = 1;
  86248. + DWC_MODIFY_REG32(core_if->pcgcctl, power.d32, 0);
  86249. +
  86250. + power.b.pwrclmp = 1;
  86251. + DWC_MODIFY_REG32(core_if->pcgcctl, power.d32, 0);
  86252. +
  86253. + power.b.rstpdwnmodule = 1;
  86254. + DWC_MODIFY_REG32(core_if->pcgcctl, power.d32, 0);
  86255. + }
  86256. +
  86257. + core_if->lx_state = DWC_OTG_L0;
  86258. +
  86259. + DWC_PRINTF("USB RESET\n");
  86260. +#ifdef DWC_EN_ISOC
  86261. + for (i = 1; i < 16; ++i) {
  86262. + dwc_otg_pcd_ep_t *ep;
  86263. + dwc_ep_t *dwc_ep;
  86264. + ep = get_in_ep(pcd, i);
  86265. + if (ep != 0) {
  86266. + dwc_ep = &ep->dwc_ep;
  86267. + dwc_ep->next_frame = 0xffffffff;
  86268. + }
  86269. + }
  86270. +#endif /* DWC_EN_ISOC */
  86271. +
  86272. + /* reset the HNP settings */
  86273. + dwc_otg_pcd_update_otg(pcd, 1);
  86274. +
  86275. + /* Clear the Remote Wakeup Signalling */
  86276. + dctl.b.rmtwkupsig = 1;
  86277. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, 0);
  86278. +
  86279. + /* Set NAK for all OUT EPs */
  86280. + doepctl.b.snak = 1;
  86281. + for (i = 0; i <= dev_if->num_out_eps; i++) {
  86282. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepctl, doepctl.d32);
  86283. + }
  86284. +
  86285. + /* Flush the NP Tx FIFO */
  86286. + dwc_otg_flush_tx_fifo(core_if, 0x10);
  86287. + /* Flush the Learning Queue */
  86288. + resetctl.b.intknqflsh = 1;
  86289. + DWC_WRITE_REG32(&core_if->core_global_regs->grstctl, resetctl.d32);
  86290. +
  86291. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable) {
  86292. + core_if->start_predict = 0;
  86293. + for (i = 0; i<= core_if->dev_if->num_in_eps; ++i) {
  86294. + core_if->nextep_seq[i] = 0xff; // 0xff - EP not active
  86295. + }
  86296. + core_if->nextep_seq[0] = 0;
  86297. + core_if->first_in_nextep_seq = 0;
  86298. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl);
  86299. + diepctl.b.nextep = 0;
  86300. + DWC_WRITE_REG32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
  86301. +
  86302. + /* Update IN Endpoint Mismatch Count by active IN NP EP count + 1 */
  86303. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  86304. + dcfg.b.epmscnt = 2;
  86305. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  86306. +
  86307. + DWC_DEBUGPL(DBG_PCDV,
  86308. + "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  86309. + __func__, core_if->first_in_nextep_seq);
  86310. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  86311. + DWC_DEBUGPL(DBG_PCDV, "%2d\n", core_if->nextep_seq[i]);
  86312. + }
  86313. + }
  86314. +
  86315. + if (core_if->multiproc_int_enable) {
  86316. + daintmsk.b.inep0 = 1;
  86317. + daintmsk.b.outep0 = 1;
  86318. + DWC_WRITE_REG32(&dev_if->dev_global_regs->deachintmsk,
  86319. + daintmsk.d32);
  86320. +
  86321. + doepmsk.b.setup = 1;
  86322. + doepmsk.b.xfercompl = 1;
  86323. + doepmsk.b.ahberr = 1;
  86324. + doepmsk.b.epdisabled = 1;
  86325. +
  86326. + if ((core_if->dma_desc_enable) ||
  86327. + (core_if->dma_enable
  86328. + && core_if->snpsid >= OTG_CORE_REV_3_00a)) {
  86329. + doepmsk.b.stsphsercvd = 1;
  86330. + }
  86331. + if (core_if->dma_desc_enable)
  86332. + doepmsk.b.bna = 1;
  86333. +/*
  86334. + doepmsk.b.babble = 1;
  86335. + doepmsk.b.nyet = 1;
  86336. +
  86337. + if (core_if->dma_enable) {
  86338. + doepmsk.b.nak = 1;
  86339. + }
  86340. +*/
  86341. + DWC_WRITE_REG32(&dev_if->dev_global_regs->doepeachintmsk[0],
  86342. + doepmsk.d32);
  86343. +
  86344. + diepmsk.b.xfercompl = 1;
  86345. + diepmsk.b.timeout = 1;
  86346. + diepmsk.b.epdisabled = 1;
  86347. + diepmsk.b.ahberr = 1;
  86348. + diepmsk.b.intknepmis = 1;
  86349. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable)
  86350. + diepmsk.b.intknepmis = 0;
  86351. +
  86352. +/* if (core_if->dma_desc_enable) {
  86353. + diepmsk.b.bna = 1;
  86354. + }
  86355. +*/
  86356. +/*
  86357. + if (core_if->dma_enable) {
  86358. + diepmsk.b.nak = 1;
  86359. + }
  86360. +*/
  86361. + DWC_WRITE_REG32(&dev_if->dev_global_regs->diepeachintmsk[0],
  86362. + diepmsk.d32);
  86363. + } else {
  86364. + daintmsk.b.inep0 = 1;
  86365. + daintmsk.b.outep0 = 1;
  86366. + DWC_WRITE_REG32(&dev_if->dev_global_regs->daintmsk,
  86367. + daintmsk.d32);
  86368. +
  86369. + doepmsk.b.setup = 1;
  86370. + doepmsk.b.xfercompl = 1;
  86371. + doepmsk.b.ahberr = 1;
  86372. + doepmsk.b.epdisabled = 1;
  86373. +
  86374. + if ((core_if->dma_desc_enable) ||
  86375. + (core_if->dma_enable
  86376. + && core_if->snpsid >= OTG_CORE_REV_3_00a)) {
  86377. + doepmsk.b.stsphsercvd = 1;
  86378. + }
  86379. + if (core_if->dma_desc_enable)
  86380. + doepmsk.b.bna = 1;
  86381. + DWC_WRITE_REG32(&dev_if->dev_global_regs->doepmsk, doepmsk.d32);
  86382. +
  86383. + diepmsk.b.xfercompl = 1;
  86384. + diepmsk.b.timeout = 1;
  86385. + diepmsk.b.epdisabled = 1;
  86386. + diepmsk.b.ahberr = 1;
  86387. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable)
  86388. + diepmsk.b.intknepmis = 0;
  86389. +/*
  86390. + if (core_if->dma_desc_enable) {
  86391. + diepmsk.b.bna = 1;
  86392. + }
  86393. +*/
  86394. +
  86395. + DWC_WRITE_REG32(&dev_if->dev_global_regs->diepmsk, diepmsk.d32);
  86396. + }
  86397. +
  86398. + /* Reset Device Address */
  86399. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  86400. + dcfg.b.devaddr = 0;
  86401. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  86402. +
  86403. + /* setup EP0 to receive SETUP packets */
  86404. + if (core_if->snpsid <= OTG_CORE_REV_2_94a)
  86405. + ep0_out_start(core_if, pcd);
  86406. +
  86407. + /* Clear interrupt */
  86408. + gintsts.d32 = 0;
  86409. + gintsts.b.usbreset = 1;
  86410. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  86411. +
  86412. + return 1;
  86413. +}
  86414. +
  86415. +/**
  86416. + * Get the device speed from the device status register and convert it
  86417. + * to USB speed constant.
  86418. + *
  86419. + * @param core_if Programming view of DWC_otg controller.
  86420. + */
  86421. +static int get_device_speed(dwc_otg_core_if_t * core_if)
  86422. +{
  86423. + dsts_data_t dsts;
  86424. + int speed = 0;
  86425. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  86426. +
  86427. + switch (dsts.b.enumspd) {
  86428. + case DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ:
  86429. + speed = USB_SPEED_HIGH;
  86430. + break;
  86431. + case DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ:
  86432. + case DWC_DSTS_ENUMSPD_FS_PHY_48MHZ:
  86433. + speed = USB_SPEED_FULL;
  86434. + break;
  86435. +
  86436. + case DWC_DSTS_ENUMSPD_LS_PHY_6MHZ:
  86437. + speed = USB_SPEED_LOW;
  86438. + break;
  86439. + }
  86440. +
  86441. + return speed;
  86442. +}
  86443. +
  86444. +/**
  86445. + * Read the device status register and set the device speed in the
  86446. + * data structure.
  86447. + * Set up EP0 to receive SETUP packets by calling dwc_ep0_activate.
  86448. + */
  86449. +int32_t dwc_otg_pcd_handle_enum_done_intr(dwc_otg_pcd_t * pcd)
  86450. +{
  86451. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  86452. + gintsts_data_t gintsts;
  86453. + gusbcfg_data_t gusbcfg;
  86454. + dwc_otg_core_global_regs_t *global_regs =
  86455. + GET_CORE_IF(pcd)->core_global_regs;
  86456. + uint8_t utmi16b, utmi8b;
  86457. + int speed;
  86458. + DWC_DEBUGPL(DBG_PCD, "SPEED ENUM\n");
  86459. +
  86460. + if (GET_CORE_IF(pcd)->snpsid >= OTG_CORE_REV_2_60a) {
  86461. + utmi16b = 6; //vahrama old value was 6;
  86462. + utmi8b = 9;
  86463. + } else {
  86464. + utmi16b = 4;
  86465. + utmi8b = 8;
  86466. + }
  86467. + dwc_otg_ep0_activate(GET_CORE_IF(pcd), &ep0->dwc_ep);
  86468. + if (GET_CORE_IF(pcd)->snpsid >= OTG_CORE_REV_3_00a) {
  86469. + ep0_out_start(GET_CORE_IF(pcd), pcd);
  86470. + }
  86471. +
  86472. +#ifdef DEBUG_EP0
  86473. + print_ep0_state(pcd);
  86474. +#endif
  86475. +
  86476. + if (pcd->ep0state == EP0_DISCONNECT) {
  86477. + pcd->ep0state = EP0_IDLE;
  86478. + } else if (pcd->ep0state == EP0_STALL) {
  86479. + pcd->ep0state = EP0_IDLE;
  86480. + }
  86481. +
  86482. + pcd->ep0state = EP0_IDLE;
  86483. +
  86484. + ep0->stopped = 0;
  86485. +
  86486. + speed = get_device_speed(GET_CORE_IF(pcd));
  86487. + pcd->fops->connect(pcd, speed);
  86488. +
  86489. + /* Set USB turnaround time based on device speed and PHY interface. */
  86490. + gusbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  86491. + if (speed == USB_SPEED_HIGH) {
  86492. + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type ==
  86493. + DWC_HWCFG2_HS_PHY_TYPE_ULPI) {
  86494. + /* ULPI interface */
  86495. + gusbcfg.b.usbtrdtim = 9;
  86496. + }
  86497. + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type ==
  86498. + DWC_HWCFG2_HS_PHY_TYPE_UTMI) {
  86499. + /* UTMI+ interface */
  86500. + if (GET_CORE_IF(pcd)->hwcfg4.b.utmi_phy_data_width == 0) {
  86501. + gusbcfg.b.usbtrdtim = utmi8b;
  86502. + } else if (GET_CORE_IF(pcd)->hwcfg4.
  86503. + b.utmi_phy_data_width == 1) {
  86504. + gusbcfg.b.usbtrdtim = utmi16b;
  86505. + } else if (GET_CORE_IF(pcd)->
  86506. + core_params->phy_utmi_width == 8) {
  86507. + gusbcfg.b.usbtrdtim = utmi8b;
  86508. + } else {
  86509. + gusbcfg.b.usbtrdtim = utmi16b;
  86510. + }
  86511. + }
  86512. + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type ==
  86513. + DWC_HWCFG2_HS_PHY_TYPE_UTMI_ULPI) {
  86514. + /* UTMI+ OR ULPI interface */
  86515. + if (gusbcfg.b.ulpi_utmi_sel == 1) {
  86516. + /* ULPI interface */
  86517. + gusbcfg.b.usbtrdtim = 9;
  86518. + } else {
  86519. + /* UTMI+ interface */
  86520. + if (GET_CORE_IF(pcd)->
  86521. + core_params->phy_utmi_width == 16) {
  86522. + gusbcfg.b.usbtrdtim = utmi16b;
  86523. + } else {
  86524. + gusbcfg.b.usbtrdtim = utmi8b;
  86525. + }
  86526. + }
  86527. + }
  86528. + } else {
  86529. + /* Full or low speed */
  86530. + gusbcfg.b.usbtrdtim = 9;
  86531. + }
  86532. + DWC_WRITE_REG32(&global_regs->gusbcfg, gusbcfg.d32);
  86533. +
  86534. + /* Clear interrupt */
  86535. + gintsts.d32 = 0;
  86536. + gintsts.b.enumdone = 1;
  86537. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  86538. + gintsts.d32);
  86539. + return 1;
  86540. +}
  86541. +
  86542. +/**
  86543. + * This interrupt indicates that the ISO OUT Packet was dropped due to
  86544. + * Rx FIFO full or Rx Status Queue Full. If this interrupt occurs
  86545. + * read all the data from the Rx FIFO.
  86546. + */
  86547. +int32_t dwc_otg_pcd_handle_isoc_out_packet_dropped_intr(dwc_otg_pcd_t * pcd)
  86548. +{
  86549. + gintmsk_data_t intr_mask = {.d32 = 0 };
  86550. + gintsts_data_t gintsts;
  86551. +
  86552. + DWC_WARN("INTERRUPT Handler not implemented for %s\n",
  86553. + "ISOC Out Dropped");
  86554. +
  86555. + intr_mask.b.isooutdrop = 1;
  86556. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  86557. + intr_mask.d32, 0);
  86558. +
  86559. + /* Clear interrupt */
  86560. + gintsts.d32 = 0;
  86561. + gintsts.b.isooutdrop = 1;
  86562. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  86563. + gintsts.d32);
  86564. +
  86565. + return 1;
  86566. +}
  86567. +
  86568. +/**
  86569. + * This interrupt indicates the end of the portion of the micro-frame
  86570. + * for periodic transactions. If there is a periodic transaction for
  86571. + * the next frame, load the packets into the EP periodic Tx FIFO.
  86572. + */
  86573. +int32_t dwc_otg_pcd_handle_end_periodic_frame_intr(dwc_otg_pcd_t * pcd)
  86574. +{
  86575. + gintmsk_data_t intr_mask = {.d32 = 0 };
  86576. + gintsts_data_t gintsts;
  86577. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "EOP");
  86578. +
  86579. + intr_mask.b.eopframe = 1;
  86580. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  86581. + intr_mask.d32, 0);
  86582. +
  86583. + /* Clear interrupt */
  86584. + gintsts.d32 = 0;
  86585. + gintsts.b.eopframe = 1;
  86586. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  86587. + gintsts.d32);
  86588. +
  86589. + return 1;
  86590. +}
  86591. +
  86592. +/**
  86593. + * This interrupt indicates that EP of the packet on the top of the
  86594. + * non-periodic Tx FIFO does not match EP of the IN Token received.
  86595. + *
  86596. + * The "Device IN Token Queue" Registers are read to determine the
  86597. + * order the IN Tokens have been received. The non-periodic Tx FIFO
  86598. + * is flushed, so it can be reloaded in the order seen in the IN Token
  86599. + * Queue.
  86600. + */
  86601. +int32_t dwc_otg_pcd_handle_ep_mismatch_intr(dwc_otg_pcd_t * pcd)
  86602. +{
  86603. + gintsts_data_t gintsts;
  86604. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  86605. + dctl_data_t dctl;
  86606. + gintmsk_data_t intr_mask = {.d32 = 0 };
  86607. +
  86608. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable) {
  86609. + core_if->start_predict = 1;
  86610. +
  86611. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, core_if);
  86612. +
  86613. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  86614. + if (!gintsts.b.ginnakeff) {
  86615. + /* Disable EP Mismatch interrupt */
  86616. + intr_mask.d32 = 0;
  86617. + intr_mask.b.epmismatch = 1;
  86618. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, intr_mask.d32, 0);
  86619. + /* Enable the Global IN NAK Effective Interrupt */
  86620. + intr_mask.d32 = 0;
  86621. + intr_mask.b.ginnakeff = 1;
  86622. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, intr_mask.d32);
  86623. + /* Set the global non-periodic IN NAK handshake */
  86624. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  86625. + dctl.b.sgnpinnak = 1;
  86626. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  86627. + } else {
  86628. + DWC_PRINTF("gintsts.b.ginnakeff = 1! dctl.b.sgnpinnak not set\n");
  86629. + }
  86630. + /* Disabling of all EP's will be done in dwc_otg_pcd_handle_in_nak_effective()
  86631. + * handler after Global IN NAK Effective interrupt will be asserted */
  86632. + }
  86633. + /* Clear interrupt */
  86634. + gintsts.d32 = 0;
  86635. + gintsts.b.epmismatch = 1;
  86636. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  86637. +
  86638. + return 1;
  86639. +}
  86640. +
  86641. +/**
  86642. + * This interrupt is valid only in DMA mode. This interrupt indicates that the
  86643. + * core has stopped fetching data for IN endpoints due to the unavailability of
  86644. + * TxFIFO space or Request Queue space. This interrupt is used by the
  86645. + * application for an endpoint mismatch algorithm.
  86646. + *
  86647. + * @param pcd The PCD
  86648. + */
  86649. +int32_t dwc_otg_pcd_handle_ep_fetsusp_intr(dwc_otg_pcd_t * pcd)
  86650. +{
  86651. + gintsts_data_t gintsts;
  86652. + gintmsk_data_t gintmsk_data;
  86653. + dctl_data_t dctl;
  86654. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  86655. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, core_if);
  86656. +
  86657. + /* Clear the global non-periodic IN NAK handshake */
  86658. + dctl.d32 = 0;
  86659. + dctl.b.cgnpinnak = 1;
  86660. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  86661. +
  86662. + /* Mask GINTSTS.FETSUSP interrupt */
  86663. + gintmsk_data.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  86664. + gintmsk_data.b.fetsusp = 0;
  86665. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk_data.d32);
  86666. +
  86667. + /* Clear interrupt */
  86668. + gintsts.d32 = 0;
  86669. + gintsts.b.fetsusp = 1;
  86670. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  86671. +
  86672. + return 1;
  86673. +}
  86674. +/**
  86675. + * This funcion stalls EP0.
  86676. + */
  86677. +static inline void ep0_do_stall(dwc_otg_pcd_t * pcd, const int err_val)
  86678. +{
  86679. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  86680. + usb_device_request_t *ctrl = &pcd->setup_pkt->req;
  86681. + DWC_WARN("req %02x.%02x protocol STALL; err %d\n",
  86682. + ctrl->bmRequestType, ctrl->bRequest, err_val);
  86683. +
  86684. + ep0->dwc_ep.is_in = 1;
  86685. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd), &ep0->dwc_ep);
  86686. + pcd->ep0.stopped = 1;
  86687. + pcd->ep0state = EP0_IDLE;
  86688. + ep0_out_start(GET_CORE_IF(pcd), pcd);
  86689. +}
  86690. +
  86691. +/**
  86692. + * This functions delegates the setup command to the gadget driver.
  86693. + */
  86694. +static inline void do_gadget_setup(dwc_otg_pcd_t * pcd,
  86695. + usb_device_request_t * ctrl)
  86696. +{
  86697. + int ret = 0;
  86698. + DWC_SPINUNLOCK(pcd->lock);
  86699. + ret = pcd->fops->setup(pcd, (uint8_t *) ctrl);
  86700. + DWC_SPINLOCK(pcd->lock);
  86701. + if (ret < 0) {
  86702. + ep0_do_stall(pcd, ret);
  86703. + }
  86704. +
  86705. + /** @todo This is a g_file_storage gadget driver specific
  86706. + * workaround: a DELAYED_STATUS result from the fsg_setup
  86707. + * routine will result in the gadget queueing a EP0 IN status
  86708. + * phase for a two-stage control transfer. Exactly the same as
  86709. + * a SET_CONFIGURATION/SET_INTERFACE except that this is a class
  86710. + * specific request. Need a generic way to know when the gadget
  86711. + * driver will queue the status phase. Can we assume when we
  86712. + * call the gadget driver setup() function that it will always
  86713. + * queue and require the following flag? Need to look into
  86714. + * this.
  86715. + */
  86716. +
  86717. + if (ret == 256 + 999) {
  86718. + pcd->request_config = 1;
  86719. + }
  86720. +}
  86721. +
  86722. +#ifdef DWC_UTE_CFI
  86723. +/**
  86724. + * This functions delegates the CFI setup commands to the gadget driver.
  86725. + * This function will return a negative value to indicate a failure.
  86726. + */
  86727. +static inline int cfi_gadget_setup(dwc_otg_pcd_t * pcd,
  86728. + struct cfi_usb_ctrlrequest *ctrl_req)
  86729. +{
  86730. + int ret = 0;
  86731. +
  86732. + if (pcd->fops && pcd->fops->cfi_setup) {
  86733. + DWC_SPINUNLOCK(pcd->lock);
  86734. + ret = pcd->fops->cfi_setup(pcd, ctrl_req);
  86735. + DWC_SPINLOCK(pcd->lock);
  86736. + if (ret < 0) {
  86737. + ep0_do_stall(pcd, ret);
  86738. + return ret;
  86739. + }
  86740. + }
  86741. +
  86742. + return ret;
  86743. +}
  86744. +#endif
  86745. +
  86746. +/**
  86747. + * This function starts the Zero-Length Packet for the IN status phase
  86748. + * of a 2 stage control transfer.
  86749. + */
  86750. +static inline void do_setup_in_status_phase(dwc_otg_pcd_t * pcd)
  86751. +{
  86752. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  86753. + if (pcd->ep0state == EP0_STALL) {
  86754. + return;
  86755. + }
  86756. +
  86757. + pcd->ep0state = EP0_IN_STATUS_PHASE;
  86758. +
  86759. + /* Prepare for more SETUP Packets */
  86760. + DWC_DEBUGPL(DBG_PCD, "EP0 IN ZLP\n");
  86761. + if ((GET_CORE_IF(pcd)->snpsid >= OTG_CORE_REV_3_00a)
  86762. + && (pcd->core_if->dma_desc_enable)
  86763. + && (ep0->dwc_ep.xfer_count < ep0->dwc_ep.total_len)) {
  86764. + DWC_DEBUGPL(DBG_PCDV,
  86765. + "Data terminated wait next packet in out_desc_addr\n");
  86766. + pcd->backup_buf = phys_to_virt(ep0->dwc_ep.dma_addr);
  86767. + pcd->data_terminated = 1;
  86768. + }
  86769. + ep0->dwc_ep.xfer_len = 0;
  86770. + ep0->dwc_ep.xfer_count = 0;
  86771. + ep0->dwc_ep.is_in = 1;
  86772. + ep0->dwc_ep.dma_addr = pcd->setup_pkt_dma_handle;
  86773. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
  86774. +
  86775. + /* Prepare for more SETUP Packets */
  86776. + //ep0_out_start(GET_CORE_IF(pcd), pcd);
  86777. +}
  86778. +
  86779. +/**
  86780. + * This function starts the Zero-Length Packet for the OUT status phase
  86781. + * of a 2 stage control transfer.
  86782. + */
  86783. +static inline void do_setup_out_status_phase(dwc_otg_pcd_t * pcd)
  86784. +{
  86785. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  86786. + if (pcd->ep0state == EP0_STALL) {
  86787. + DWC_DEBUGPL(DBG_PCD, "EP0 STALLED\n");
  86788. + return;
  86789. + }
  86790. + pcd->ep0state = EP0_OUT_STATUS_PHASE;
  86791. +
  86792. + DWC_DEBUGPL(DBG_PCD, "EP0 OUT ZLP\n");
  86793. + ep0->dwc_ep.xfer_len = 0;
  86794. + ep0->dwc_ep.xfer_count = 0;
  86795. + ep0->dwc_ep.is_in = 0;
  86796. + ep0->dwc_ep.dma_addr = pcd->setup_pkt_dma_handle;
  86797. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
  86798. +
  86799. + /* Prepare for more SETUP Packets */
  86800. + if (GET_CORE_IF(pcd)->dma_enable == 0) {
  86801. + ep0_out_start(GET_CORE_IF(pcd), pcd);
  86802. + }
  86803. +}
  86804. +
  86805. +/**
  86806. + * Clear the EP halt (STALL) and if pending requests start the
  86807. + * transfer.
  86808. + */
  86809. +static inline void pcd_clear_halt(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep)
  86810. +{
  86811. + if (ep->dwc_ep.stall_clear_flag == 0)
  86812. + dwc_otg_ep_clear_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  86813. +
  86814. + /* Reactive the EP */
  86815. + dwc_otg_ep_activate(GET_CORE_IF(pcd), &ep->dwc_ep);
  86816. + if (ep->stopped) {
  86817. + ep->stopped = 0;
  86818. + /* If there is a request in the EP queue start it */
  86819. +
  86820. + /** @todo FIXME: this causes an EP mismatch in DMA mode.
  86821. + * epmismatch not yet implemented. */
  86822. +
  86823. + /*
  86824. + * Above fixme is solved by implmenting a tasklet to call the
  86825. + * start_next_request(), outside of interrupt context at some
  86826. + * time after the current time, after a clear-halt setup packet.
  86827. + * Still need to implement ep mismatch in the future if a gadget
  86828. + * ever uses more than one endpoint at once
  86829. + */
  86830. + ep->queue_sof = 1;
  86831. + DWC_TASK_SCHEDULE(pcd->start_xfer_tasklet);
  86832. + }
  86833. + /* Start Control Status Phase */
  86834. + do_setup_in_status_phase(pcd);
  86835. +}
  86836. +
  86837. +/**
  86838. + * This function is called when the SET_FEATURE TEST_MODE Setup packet
  86839. + * is sent from the host. The Device Control register is written with
  86840. + * the Test Mode bits set to the specified Test Mode. This is done as
  86841. + * a tasklet so that the "Status" phase of the control transfer
  86842. + * completes before transmitting the TEST packets.
  86843. + *
  86844. + * @todo This has not been tested since the tasklet struct was put
  86845. + * into the PCD struct!
  86846. + *
  86847. + */
  86848. +void do_test_mode(void *data)
  86849. +{
  86850. + dctl_data_t dctl;
  86851. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) data;
  86852. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  86853. + int test_mode = pcd->test_mode;
  86854. +
  86855. +// DWC_WARN("%s() has not been tested since being rewritten!\n", __func__);
  86856. +
  86857. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  86858. + switch (test_mode) {
  86859. + case 1: // TEST_J
  86860. + dctl.b.tstctl = 1;
  86861. + break;
  86862. +
  86863. + case 2: // TEST_K
  86864. + dctl.b.tstctl = 2;
  86865. + break;
  86866. +
  86867. + case 3: // TEST_SE0_NAK
  86868. + dctl.b.tstctl = 3;
  86869. + break;
  86870. +
  86871. + case 4: // TEST_PACKET
  86872. + dctl.b.tstctl = 4;
  86873. + break;
  86874. +
  86875. + case 5: // TEST_FORCE_ENABLE
  86876. + dctl.b.tstctl = 5;
  86877. + break;
  86878. + }
  86879. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  86880. +}
  86881. +
  86882. +/**
  86883. + * This function process the GET_STATUS Setup Commands.
  86884. + */
  86885. +static inline void do_get_status(dwc_otg_pcd_t * pcd)
  86886. +{
  86887. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  86888. + dwc_otg_pcd_ep_t *ep;
  86889. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  86890. + uint16_t *status = pcd->status_buf;
  86891. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  86892. +
  86893. +#ifdef DEBUG_EP0
  86894. + DWC_DEBUGPL(DBG_PCD,
  86895. + "GET_STATUS %02x.%02x v%04x i%04x l%04x\n",
  86896. + ctrl.bmRequestType, ctrl.bRequest,
  86897. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  86898. + UGETW(ctrl.wLength));
  86899. +#endif
  86900. +
  86901. + switch (UT_GET_RECIPIENT(ctrl.bmRequestType)) {
  86902. + case UT_DEVICE:
  86903. + if(UGETW(ctrl.wIndex) == 0xF000) { /* OTG Status selector */
  86904. + DWC_PRINTF("wIndex - %d\n", UGETW(ctrl.wIndex));
  86905. + DWC_PRINTF("OTG VERSION - %d\n", core_if->otg_ver);
  86906. + DWC_PRINTF("OTG CAP - %d, %d\n",
  86907. + core_if->core_params->otg_cap,
  86908. + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE);
  86909. + if (core_if->otg_ver == 1
  86910. + && core_if->core_params->otg_cap ==
  86911. + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  86912. + uint8_t *otgsts = (uint8_t*)pcd->status_buf;
  86913. + *otgsts = (core_if->otg_sts & 0x1);
  86914. + pcd->ep0_pending = 1;
  86915. + ep0->dwc_ep.start_xfer_buff =
  86916. + (uint8_t *) otgsts;
  86917. + ep0->dwc_ep.xfer_buff = (uint8_t *) otgsts;
  86918. + ep0->dwc_ep.dma_addr =
  86919. + pcd->status_buf_dma_handle;
  86920. + ep0->dwc_ep.xfer_len = 1;
  86921. + ep0->dwc_ep.xfer_count = 0;
  86922. + ep0->dwc_ep.total_len = ep0->dwc_ep.xfer_len;
  86923. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd),
  86924. + &ep0->dwc_ep);
  86925. + return;
  86926. + } else {
  86927. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  86928. + return;
  86929. + }
  86930. + break;
  86931. + } else {
  86932. + *status = 0x1; /* Self powered */
  86933. + *status |= pcd->remote_wakeup_enable << 1;
  86934. + break;
  86935. + }
  86936. + case UT_INTERFACE:
  86937. + *status = 0;
  86938. + break;
  86939. +
  86940. + case UT_ENDPOINT:
  86941. + ep = get_ep_by_addr(pcd, UGETW(ctrl.wIndex));
  86942. + if (ep == 0 || UGETW(ctrl.wLength) > 2) {
  86943. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  86944. + return;
  86945. + }
  86946. + /** @todo check for EP stall */
  86947. + *status = ep->stopped;
  86948. + break;
  86949. + }
  86950. + pcd->ep0_pending = 1;
  86951. + ep0->dwc_ep.start_xfer_buff = (uint8_t *) status;
  86952. + ep0->dwc_ep.xfer_buff = (uint8_t *) status;
  86953. + ep0->dwc_ep.dma_addr = pcd->status_buf_dma_handle;
  86954. + ep0->dwc_ep.xfer_len = 2;
  86955. + ep0->dwc_ep.xfer_count = 0;
  86956. + ep0->dwc_ep.total_len = ep0->dwc_ep.xfer_len;
  86957. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
  86958. +}
  86959. +
  86960. +/**
  86961. + * This function process the SET_FEATURE Setup Commands.
  86962. + */
  86963. +static inline void do_set_feature(dwc_otg_pcd_t * pcd)
  86964. +{
  86965. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  86966. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  86967. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  86968. + dwc_otg_pcd_ep_t *ep = 0;
  86969. + int32_t otg_cap_param = core_if->core_params->otg_cap;
  86970. + gotgctl_data_t gotgctl = {.d32 = 0 };
  86971. +
  86972. + DWC_DEBUGPL(DBG_PCD, "SET_FEATURE:%02x.%02x v%04x i%04x l%04x\n",
  86973. + ctrl.bmRequestType, ctrl.bRequest,
  86974. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  86975. + UGETW(ctrl.wLength));
  86976. + DWC_DEBUGPL(DBG_PCD, "otg_cap=%d\n", otg_cap_param);
  86977. +
  86978. + switch (UT_GET_RECIPIENT(ctrl.bmRequestType)) {
  86979. + case UT_DEVICE:
  86980. + switch (UGETW(ctrl.wValue)) {
  86981. + case UF_DEVICE_REMOTE_WAKEUP:
  86982. + pcd->remote_wakeup_enable = 1;
  86983. + break;
  86984. +
  86985. + case UF_TEST_MODE:
  86986. + /* Setup the Test Mode tasklet to do the Test
  86987. + * Packet generation after the SETUP Status
  86988. + * phase has completed. */
  86989. +
  86990. + /** @todo This has not been tested since the
  86991. + * tasklet struct was put into the PCD
  86992. + * struct! */
  86993. + pcd->test_mode = UGETW(ctrl.wIndex) >> 8;
  86994. + DWC_TASK_SCHEDULE(pcd->test_mode_tasklet);
  86995. + break;
  86996. +
  86997. + case UF_DEVICE_B_HNP_ENABLE:
  86998. + DWC_DEBUGPL(DBG_PCDV,
  86999. + "SET_FEATURE: USB_DEVICE_B_HNP_ENABLE\n");
  87000. +
  87001. + /* dev may initiate HNP */
  87002. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  87003. + pcd->b_hnp_enable = 1;
  87004. + dwc_otg_pcd_update_otg(pcd, 0);
  87005. + DWC_DEBUGPL(DBG_PCD, "Request B HNP\n");
  87006. + /**@todo Is the gotgctl.devhnpen cleared
  87007. + * by a USB Reset? */
  87008. + gotgctl.b.devhnpen = 1;
  87009. + gotgctl.b.hnpreq = 1;
  87010. + DWC_WRITE_REG32(&global_regs->gotgctl,
  87011. + gotgctl.d32);
  87012. + } else {
  87013. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  87014. + return;
  87015. + }
  87016. + break;
  87017. +
  87018. + case UF_DEVICE_A_HNP_SUPPORT:
  87019. + /* RH port supports HNP */
  87020. + DWC_DEBUGPL(DBG_PCDV,
  87021. + "SET_FEATURE: USB_DEVICE_A_HNP_SUPPORT\n");
  87022. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  87023. + pcd->a_hnp_support = 1;
  87024. + dwc_otg_pcd_update_otg(pcd, 0);
  87025. + } else {
  87026. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  87027. + return;
  87028. + }
  87029. + break;
  87030. +
  87031. + case UF_DEVICE_A_ALT_HNP_SUPPORT:
  87032. + /* other RH port does */
  87033. + DWC_DEBUGPL(DBG_PCDV,
  87034. + "SET_FEATURE: USB_DEVICE_A_ALT_HNP_SUPPORT\n");
  87035. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  87036. + pcd->a_alt_hnp_support = 1;
  87037. + dwc_otg_pcd_update_otg(pcd, 0);
  87038. + } else {
  87039. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  87040. + return;
  87041. + }
  87042. + break;
  87043. +
  87044. + default:
  87045. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  87046. + return;
  87047. +
  87048. + }
  87049. + do_setup_in_status_phase(pcd);
  87050. + break;
  87051. +
  87052. + case UT_INTERFACE:
  87053. + do_gadget_setup(pcd, &ctrl);
  87054. + break;
  87055. +
  87056. + case UT_ENDPOINT:
  87057. + if (UGETW(ctrl.wValue) == UF_ENDPOINT_HALT) {
  87058. + ep = get_ep_by_addr(pcd, UGETW(ctrl.wIndex));
  87059. + if (ep == 0) {
  87060. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  87061. + return;
  87062. + }
  87063. + ep->stopped = 1;
  87064. + dwc_otg_ep_set_stall(core_if, &ep->dwc_ep);
  87065. + }
  87066. + do_setup_in_status_phase(pcd);
  87067. + break;
  87068. + }
  87069. +}
  87070. +
  87071. +/**
  87072. + * This function process the CLEAR_FEATURE Setup Commands.
  87073. + */
  87074. +static inline void do_clear_feature(dwc_otg_pcd_t * pcd)
  87075. +{
  87076. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  87077. + dwc_otg_pcd_ep_t *ep = 0;
  87078. +
  87079. + DWC_DEBUGPL(DBG_PCD,
  87080. + "CLEAR_FEATURE:%02x.%02x v%04x i%04x l%04x\n",
  87081. + ctrl.bmRequestType, ctrl.bRequest,
  87082. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  87083. + UGETW(ctrl.wLength));
  87084. +
  87085. + switch (UT_GET_RECIPIENT(ctrl.bmRequestType)) {
  87086. + case UT_DEVICE:
  87087. + switch (UGETW(ctrl.wValue)) {
  87088. + case UF_DEVICE_REMOTE_WAKEUP:
  87089. + pcd->remote_wakeup_enable = 0;
  87090. + break;
  87091. +
  87092. + case UF_TEST_MODE:
  87093. + /** @todo Add CLEAR_FEATURE for TEST modes. */
  87094. + break;
  87095. +
  87096. + default:
  87097. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  87098. + return;
  87099. + }
  87100. + do_setup_in_status_phase(pcd);
  87101. + break;
  87102. +
  87103. + case UT_ENDPOINT:
  87104. + ep = get_ep_by_addr(pcd, UGETW(ctrl.wIndex));
  87105. + if (ep == 0) {
  87106. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  87107. + return;
  87108. + }
  87109. +
  87110. + pcd_clear_halt(pcd, ep);
  87111. +
  87112. + break;
  87113. + }
  87114. +}
  87115. +
  87116. +/**
  87117. + * This function process the SET_ADDRESS Setup Commands.
  87118. + */
  87119. +static inline void do_set_address(dwc_otg_pcd_t * pcd)
  87120. +{
  87121. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  87122. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  87123. +
  87124. + if (ctrl.bmRequestType == UT_DEVICE) {
  87125. + dcfg_data_t dcfg = {.d32 = 0 };
  87126. +
  87127. +#ifdef DEBUG_EP0
  87128. +// DWC_DEBUGPL(DBG_PCDV, "SET_ADDRESS:%d\n", ctrl.wValue);
  87129. +#endif
  87130. + dcfg.b.devaddr = UGETW(ctrl.wValue);
  87131. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dcfg, 0, dcfg.d32);
  87132. + do_setup_in_status_phase(pcd);
  87133. + }
  87134. +}
  87135. +
  87136. +/**
  87137. + * This function processes SETUP commands. In Linux, the USB Command
  87138. + * processing is done in two places - the first being the PCD and the
  87139. + * second in the Gadget Driver (for example, the File-Backed Storage
  87140. + * Gadget Driver).
  87141. + *
  87142. + * <table>
  87143. + * <tr><td>Command </td><td>Driver </td><td>Description</td></tr>
  87144. + *
  87145. + * <tr><td>GET_STATUS </td><td>PCD </td><td>Command is processed as
  87146. + * defined in chapter 9 of the USB 2.0 Specification chapter 9
  87147. + * </td></tr>
  87148. + *
  87149. + * <tr><td>CLEAR_FEATURE </td><td>PCD </td><td>The Device and Endpoint
  87150. + * requests are the ENDPOINT_HALT feature is procesed, all others the
  87151. + * interface requests are ignored.</td></tr>
  87152. + *
  87153. + * <tr><td>SET_FEATURE </td><td>PCD </td><td>The Device and Endpoint
  87154. + * requests are processed by the PCD. Interface requests are passed
  87155. + * to the Gadget Driver.</td></tr>
  87156. + *
  87157. + * <tr><td>SET_ADDRESS </td><td>PCD </td><td>Program the DCFG reg,
  87158. + * with device address received </td></tr>
  87159. + *
  87160. + * <tr><td>GET_DESCRIPTOR </td><td>Gadget Driver </td><td>Return the
  87161. + * requested descriptor</td></tr>
  87162. + *
  87163. + * <tr><td>SET_DESCRIPTOR </td><td>Gadget Driver </td><td>Optional -
  87164. + * not implemented by any of the existing Gadget Drivers.</td></tr>
  87165. + *
  87166. + * <tr><td>SET_CONFIGURATION </td><td>Gadget Driver </td><td>Disable
  87167. + * all EPs and enable EPs for new configuration.</td></tr>
  87168. + *
  87169. + * <tr><td>GET_CONFIGURATION </td><td>Gadget Driver </td><td>Return
  87170. + * the current configuration</td></tr>
  87171. + *
  87172. + * <tr><td>SET_INTERFACE </td><td>Gadget Driver </td><td>Disable all
  87173. + * EPs and enable EPs for new configuration.</td></tr>
  87174. + *
  87175. + * <tr><td>GET_INTERFACE </td><td>Gadget Driver </td><td>Return the
  87176. + * current interface.</td></tr>
  87177. + *
  87178. + * <tr><td>SYNC_FRAME </td><td>PCD </td><td>Display debug
  87179. + * message.</td></tr>
  87180. + * </table>
  87181. + *
  87182. + * When the SETUP Phase Done interrupt occurs, the PCD SETUP commands are
  87183. + * processed by pcd_setup. Calling the Function Driver's setup function from
  87184. + * pcd_setup processes the gadget SETUP commands.
  87185. + */
  87186. +static inline void pcd_setup(dwc_otg_pcd_t * pcd)
  87187. +{
  87188. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  87189. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  87190. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  87191. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  87192. +
  87193. + deptsiz0_data_t doeptsize0 = {.d32 = 0 };
  87194. +
  87195. +#ifdef DWC_UTE_CFI
  87196. + int retval = 0;
  87197. + struct cfi_usb_ctrlrequest cfi_req;
  87198. +#endif
  87199. +
  87200. + doeptsize0.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[0]->doeptsiz);
  87201. +
  87202. + /** In BDMA more then 1 setup packet is not supported till 3.00a */
  87203. + if (core_if->dma_enable && core_if->dma_desc_enable == 0
  87204. + && (doeptsize0.b.supcnt < 2)
  87205. + && (core_if->snpsid < OTG_CORE_REV_2_94a)) {
  87206. + DWC_ERROR
  87207. + ("\n\n----------- CANNOT handle > 1 setup packet in DMA mode\n\n");
  87208. + }
  87209. + if ((core_if->snpsid >= OTG_CORE_REV_3_00a)
  87210. + && (core_if->dma_enable == 1) && (core_if->dma_desc_enable == 0)) {
  87211. + ctrl =
  87212. + (pcd->setup_pkt +
  87213. + (3 - doeptsize0.b.supcnt - 1 +
  87214. + ep0->dwc_ep.stp_rollover))->req;
  87215. + }
  87216. +#ifdef DEBUG_EP0
  87217. + DWC_DEBUGPL(DBG_PCD, "SETUP %02x.%02x v%04x i%04x l%04x\n",
  87218. + ctrl.bmRequestType, ctrl.bRequest,
  87219. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  87220. + UGETW(ctrl.wLength));
  87221. +#endif
  87222. +
  87223. + /* Clean up the request queue */
  87224. + dwc_otg_request_nuke(ep0);
  87225. + ep0->stopped = 0;
  87226. +
  87227. + if (ctrl.bmRequestType & UE_DIR_IN) {
  87228. + ep0->dwc_ep.is_in = 1;
  87229. + pcd->ep0state = EP0_IN_DATA_PHASE;
  87230. + } else {
  87231. + ep0->dwc_ep.is_in = 0;
  87232. + pcd->ep0state = EP0_OUT_DATA_PHASE;
  87233. + }
  87234. +
  87235. + if (UGETW(ctrl.wLength) == 0) {
  87236. + ep0->dwc_ep.is_in = 1;
  87237. + pcd->ep0state = EP0_IN_STATUS_PHASE;
  87238. + }
  87239. +
  87240. + if (UT_GET_TYPE(ctrl.bmRequestType) != UT_STANDARD) {
  87241. +
  87242. +#ifdef DWC_UTE_CFI
  87243. + DWC_MEMCPY(&cfi_req, &ctrl, sizeof(usb_device_request_t));
  87244. +
  87245. + //printk(KERN_ALERT "CFI: req_type=0x%02x; req=0x%02x\n",
  87246. + ctrl.bRequestType, ctrl.bRequest);
  87247. + if (UT_GET_TYPE(cfi_req.bRequestType) == UT_VENDOR) {
  87248. + if (cfi_req.bRequest > 0xB0 && cfi_req.bRequest < 0xBF) {
  87249. + retval = cfi_setup(pcd, &cfi_req);
  87250. + if (retval < 0) {
  87251. + ep0_do_stall(pcd, retval);
  87252. + pcd->ep0_pending = 0;
  87253. + return;
  87254. + }
  87255. +
  87256. + /* if need gadget setup then call it and check the retval */
  87257. + if (pcd->cfi->need_gadget_att) {
  87258. + retval =
  87259. + cfi_gadget_setup(pcd,
  87260. + &pcd->
  87261. + cfi->ctrl_req);
  87262. + if (retval < 0) {
  87263. + pcd->ep0_pending = 0;
  87264. + return;
  87265. + }
  87266. + }
  87267. +
  87268. + if (pcd->cfi->need_status_in_complete) {
  87269. + do_setup_in_status_phase(pcd);
  87270. + }
  87271. + return;
  87272. + }
  87273. + }
  87274. +#endif
  87275. +
  87276. + /* handle non-standard (class/vendor) requests in the gadget driver */
  87277. + do_gadget_setup(pcd, &ctrl);
  87278. + return;
  87279. + }
  87280. +
  87281. + /** @todo NGS: Handle bad setup packet? */
  87282. +
  87283. +///////////////////////////////////////////
  87284. +//// --- Standard Request handling --- ////
  87285. +
  87286. + switch (ctrl.bRequest) {
  87287. + case UR_GET_STATUS:
  87288. + do_get_status(pcd);
  87289. + break;
  87290. +
  87291. + case UR_CLEAR_FEATURE:
  87292. + do_clear_feature(pcd);
  87293. + break;
  87294. +
  87295. + case UR_SET_FEATURE:
  87296. + do_set_feature(pcd);
  87297. + break;
  87298. +
  87299. + case UR_SET_ADDRESS:
  87300. + do_set_address(pcd);
  87301. + break;
  87302. +
  87303. + case UR_SET_INTERFACE:
  87304. + case UR_SET_CONFIG:
  87305. +// _pcd->request_config = 1; /* Configuration changed */
  87306. + do_gadget_setup(pcd, &ctrl);
  87307. + break;
  87308. +
  87309. + case UR_SYNCH_FRAME:
  87310. + do_gadget_setup(pcd, &ctrl);
  87311. + break;
  87312. +
  87313. + default:
  87314. + /* Call the Gadget Driver's setup functions */
  87315. + do_gadget_setup(pcd, &ctrl);
  87316. + break;
  87317. + }
  87318. +}
  87319. +
  87320. +/**
  87321. + * This function completes the ep0 control transfer.
  87322. + */
  87323. +static int32_t ep0_complete_request(dwc_otg_pcd_ep_t * ep)
  87324. +{
  87325. + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
  87326. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  87327. + dwc_otg_dev_in_ep_regs_t *in_ep_regs =
  87328. + dev_if->in_ep_regs[ep->dwc_ep.num];
  87329. +#ifdef DEBUG_EP0
  87330. + dwc_otg_dev_out_ep_regs_t *out_ep_regs =
  87331. + dev_if->out_ep_regs[ep->dwc_ep.num];
  87332. +#endif
  87333. + deptsiz0_data_t deptsiz;
  87334. + dev_dma_desc_sts_t desc_sts;
  87335. + dwc_otg_pcd_request_t *req;
  87336. + int is_last = 0;
  87337. + dwc_otg_pcd_t *pcd = ep->pcd;
  87338. +
  87339. +#ifdef DWC_UTE_CFI
  87340. + struct cfi_usb_ctrlrequest *ctrlreq;
  87341. + int retval = -DWC_E_NOT_SUPPORTED;
  87342. +#endif
  87343. +
  87344. + desc_sts.b.bytes = 0;
  87345. +
  87346. + if (pcd->ep0_pending && DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  87347. + if (ep->dwc_ep.is_in) {
  87348. +#ifdef DEBUG_EP0
  87349. + DWC_DEBUGPL(DBG_PCDV, "Do setup OUT status phase\n");
  87350. +#endif
  87351. + do_setup_out_status_phase(pcd);
  87352. + } else {
  87353. +#ifdef DEBUG_EP0
  87354. + DWC_DEBUGPL(DBG_PCDV, "Do setup IN status phase\n");
  87355. +#endif
  87356. +
  87357. +#ifdef DWC_UTE_CFI
  87358. + ctrlreq = &pcd->cfi->ctrl_req;
  87359. +
  87360. + if (UT_GET_TYPE(ctrlreq->bRequestType) == UT_VENDOR) {
  87361. + if (ctrlreq->bRequest > 0xB0
  87362. + && ctrlreq->bRequest < 0xBF) {
  87363. +
  87364. + /* Return if the PCD failed to handle the request */
  87365. + if ((retval =
  87366. + pcd->cfi->ops.
  87367. + ctrl_write_complete(pcd->cfi,
  87368. + pcd)) < 0) {
  87369. + CFI_INFO
  87370. + ("ERROR setting a new value in the PCD(%d)\n",
  87371. + retval);
  87372. + ep0_do_stall(pcd, retval);
  87373. + pcd->ep0_pending = 0;
  87374. + return 0;
  87375. + }
  87376. +
  87377. + /* If the gadget needs to be notified on the request */
  87378. + if (pcd->cfi->need_gadget_att == 1) {
  87379. + //retval = do_gadget_setup(pcd, &pcd->cfi->ctrl_req);
  87380. + retval =
  87381. + cfi_gadget_setup(pcd,
  87382. + &pcd->cfi->
  87383. + ctrl_req);
  87384. +
  87385. + /* Return from the function if the gadget failed to process
  87386. + * the request properly - this should never happen !!!
  87387. + */
  87388. + if (retval < 0) {
  87389. + CFI_INFO
  87390. + ("ERROR setting a new value in the gadget(%d)\n",
  87391. + retval);
  87392. + pcd->ep0_pending = 0;
  87393. + return 0;
  87394. + }
  87395. + }
  87396. +
  87397. + CFI_INFO("%s: RETVAL=%d\n", __func__,
  87398. + retval);
  87399. + /* If we hit here then the PCD and the gadget has properly
  87400. + * handled the request - so send the ZLP IN to the host.
  87401. + */
  87402. + /* @todo: MAS - decide whether we need to start the setup
  87403. + * stage based on the need_setup value of the cfi object
  87404. + */
  87405. + do_setup_in_status_phase(pcd);
  87406. + pcd->ep0_pending = 0;
  87407. + return 1;
  87408. + }
  87409. + }
  87410. +#endif
  87411. +
  87412. + do_setup_in_status_phase(pcd);
  87413. + }
  87414. + pcd->ep0_pending = 0;
  87415. + return 1;
  87416. + }
  87417. +
  87418. + if (DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  87419. + return 0;
  87420. + }
  87421. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  87422. +
  87423. + if (pcd->ep0state == EP0_OUT_STATUS_PHASE
  87424. + || pcd->ep0state == EP0_IN_STATUS_PHASE) {
  87425. + is_last = 1;
  87426. + } else if (ep->dwc_ep.is_in) {
  87427. + deptsiz.d32 = DWC_READ_REG32(&in_ep_regs->dieptsiz);
  87428. + if (core_if->dma_desc_enable != 0)
  87429. + desc_sts = dev_if->in_desc_addr->status;
  87430. +#ifdef DEBUG_EP0
  87431. + DWC_DEBUGPL(DBG_PCDV, "%d len=%d xfersize=%d pktcnt=%d\n",
  87432. + ep->dwc_ep.num, ep->dwc_ep.xfer_len,
  87433. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  87434. +#endif
  87435. +
  87436. + if (((core_if->dma_desc_enable == 0)
  87437. + && (deptsiz.b.xfersize == 0))
  87438. + || ((core_if->dma_desc_enable != 0)
  87439. + && (desc_sts.b.bytes == 0))) {
  87440. + req->actual = ep->dwc_ep.xfer_count;
  87441. + /* Is a Zero Len Packet needed? */
  87442. + if (req->sent_zlp) {
  87443. +#ifdef DEBUG_EP0
  87444. + DWC_DEBUGPL(DBG_PCD, "Setup Rx ZLP\n");
  87445. +#endif
  87446. + req->sent_zlp = 0;
  87447. + }
  87448. + do_setup_out_status_phase(pcd);
  87449. + }
  87450. + } else {
  87451. + /* ep0-OUT */
  87452. +#ifdef DEBUG_EP0
  87453. + deptsiz.d32 = DWC_READ_REG32(&out_ep_regs->doeptsiz);
  87454. + DWC_DEBUGPL(DBG_PCDV, "%d len=%d xsize=%d pktcnt=%d\n",
  87455. + ep->dwc_ep.num, ep->dwc_ep.xfer_len,
  87456. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  87457. +#endif
  87458. + req->actual = ep->dwc_ep.xfer_count;
  87459. +
  87460. + /* Is a Zero Len Packet needed? */
  87461. + if (req->sent_zlp) {
  87462. +#ifdef DEBUG_EP0
  87463. + DWC_DEBUGPL(DBG_PCDV, "Setup Tx ZLP\n");
  87464. +#endif
  87465. + req->sent_zlp = 0;
  87466. + }
  87467. + /* For older cores do setup in status phase in Slave/BDMA modes,
  87468. + * starting from 3.00 do that only in slave, and for DMA modes
  87469. + * just re-enable ep 0 OUT here*/
  87470. + if (core_if->dma_enable == 0
  87471. + || (core_if->dma_desc_enable == 0
  87472. + && core_if->snpsid <= OTG_CORE_REV_2_94a)) {
  87473. + do_setup_in_status_phase(pcd);
  87474. + } else if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  87475. + DWC_DEBUGPL(DBG_PCDV,
  87476. + "Enable out ep before in status phase\n");
  87477. + ep0_out_start(core_if, pcd);
  87478. + }
  87479. + }
  87480. +
  87481. + /* Complete the request */
  87482. + if (is_last) {
  87483. + dwc_otg_request_done(ep, req, 0);
  87484. + ep->dwc_ep.start_xfer_buff = 0;
  87485. + ep->dwc_ep.xfer_buff = 0;
  87486. + ep->dwc_ep.xfer_len = 0;
  87487. + return 1;
  87488. + }
  87489. + return 0;
  87490. +}
  87491. +
  87492. +#ifdef DWC_UTE_CFI
  87493. +/**
  87494. + * This function calculates traverses all the CFI DMA descriptors and
  87495. + * and accumulates the bytes that are left to be transfered.
  87496. + *
  87497. + * @return The total bytes left to transfered, or a negative value as failure
  87498. + */
  87499. +static inline int cfi_calc_desc_residue(dwc_otg_pcd_ep_t * ep)
  87500. +{
  87501. + int32_t ret = 0;
  87502. + int i;
  87503. + struct dwc_otg_dma_desc *ddesc = NULL;
  87504. + struct cfi_ep *cfiep;
  87505. +
  87506. + /* See if the pcd_ep has its respective cfi_ep mapped */
  87507. + cfiep = get_cfi_ep_by_pcd_ep(ep->pcd->cfi, ep);
  87508. + if (!cfiep) {
  87509. + CFI_INFO("%s: Failed to find ep\n", __func__);
  87510. + return -1;
  87511. + }
  87512. +
  87513. + ddesc = ep->dwc_ep.descs;
  87514. +
  87515. + for (i = 0; (i < cfiep->desc_count) && (i < MAX_DMA_DESCS_PER_EP); i++) {
  87516. +
  87517. +#if defined(PRINT_CFI_DMA_DESCS)
  87518. + print_desc(ddesc, ep->ep.name, i);
  87519. +#endif
  87520. + ret += ddesc->status.b.bytes;
  87521. + ddesc++;
  87522. + }
  87523. +
  87524. + if (ret)
  87525. + CFI_INFO("!!!!!!!!!! WARNING (%s) - residue=%d\n", __func__,
  87526. + ret);
  87527. +
  87528. + return ret;
  87529. +}
  87530. +#endif
  87531. +
  87532. +/**
  87533. + * This function completes the request for the EP. If there are
  87534. + * additional requests for the EP in the queue they will be started.
  87535. + */
  87536. +static void complete_ep(dwc_otg_pcd_ep_t * ep)
  87537. +{
  87538. + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
  87539. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  87540. + dwc_otg_dev_in_ep_regs_t *in_ep_regs =
  87541. + dev_if->in_ep_regs[ep->dwc_ep.num];
  87542. + deptsiz_data_t deptsiz;
  87543. + dev_dma_desc_sts_t desc_sts;
  87544. + dwc_otg_pcd_request_t *req = 0;
  87545. + dwc_otg_dev_dma_desc_t *dma_desc;
  87546. + uint32_t byte_count = 0;
  87547. + int is_last = 0;
  87548. + int i;
  87549. +
  87550. + DWC_DEBUGPL(DBG_PCDV, "%s() %d-%s\n", __func__, ep->dwc_ep.num,
  87551. + (ep->dwc_ep.is_in ? "IN" : "OUT"));
  87552. +
  87553. + /* Get any pending requests */
  87554. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  87555. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  87556. + if (!req) {
  87557. + DWC_PRINTF("complete_ep 0x%p, req = NULL!\n", ep);
  87558. + return;
  87559. + }
  87560. + } else {
  87561. + DWC_PRINTF("complete_ep 0x%p, ep->queue empty!\n", ep);
  87562. + return;
  87563. + }
  87564. +
  87565. + DWC_DEBUGPL(DBG_PCD, "Requests %d\n", ep->pcd->request_pending);
  87566. +
  87567. + if (ep->dwc_ep.is_in) {
  87568. + deptsiz.d32 = DWC_READ_REG32(&in_ep_regs->dieptsiz);
  87569. +
  87570. + if (core_if->dma_enable) {
  87571. + if (core_if->dma_desc_enable == 0) {
  87572. + if (deptsiz.b.xfersize == 0
  87573. + && deptsiz.b.pktcnt == 0) {
  87574. + byte_count =
  87575. + ep->dwc_ep.xfer_len -
  87576. + ep->dwc_ep.xfer_count;
  87577. +
  87578. + ep->dwc_ep.xfer_buff += byte_count;
  87579. + ep->dwc_ep.dma_addr += byte_count;
  87580. + ep->dwc_ep.xfer_count += byte_count;
  87581. +
  87582. + DWC_DEBUGPL(DBG_PCDV,
  87583. + "%d-%s len=%d xfersize=%d pktcnt=%d\n",
  87584. + ep->dwc_ep.num,
  87585. + (ep->dwc_ep.
  87586. + is_in ? "IN" : "OUT"),
  87587. + ep->dwc_ep.xfer_len,
  87588. + deptsiz.b.xfersize,
  87589. + deptsiz.b.pktcnt);
  87590. +
  87591. + if (ep->dwc_ep.xfer_len <
  87592. + ep->dwc_ep.total_len) {
  87593. + dwc_otg_ep_start_transfer
  87594. + (core_if, &ep->dwc_ep);
  87595. + } else if (ep->dwc_ep.sent_zlp) {
  87596. + /*
  87597. + * This fragment of code should initiate 0
  87598. + * length transfer in case if it is queued
  87599. + * a transfer with size divisible to EPs max
  87600. + * packet size and with usb_request zero field
  87601. + * is set, which means that after data is transfered,
  87602. + * it is also should be transfered
  87603. + * a 0 length packet at the end. For Slave and
  87604. + * Buffer DMA modes in this case SW has
  87605. + * to initiate 2 transfers one with transfer size,
  87606. + * and the second with 0 size. For Descriptor
  87607. + * DMA mode SW is able to initiate a transfer,
  87608. + * which will handle all the packets including
  87609. + * the last 0 length.
  87610. + */
  87611. + ep->dwc_ep.sent_zlp = 0;
  87612. + dwc_otg_ep_start_zl_transfer
  87613. + (core_if, &ep->dwc_ep);
  87614. + } else {
  87615. + is_last = 1;
  87616. + }
  87617. + } else {
  87618. + if (ep->dwc_ep.type ==
  87619. + DWC_OTG_EP_TYPE_ISOC) {
  87620. + req->actual = 0;
  87621. + dwc_otg_request_done(ep, req, 0);
  87622. +
  87623. + ep->dwc_ep.start_xfer_buff = 0;
  87624. + ep->dwc_ep.xfer_buff = 0;
  87625. + ep->dwc_ep.xfer_len = 0;
  87626. +
  87627. + /* If there is a request in the queue start it. */
  87628. + start_next_request(ep);
  87629. + } else
  87630. + DWC_WARN
  87631. + ("Incomplete transfer (%d - %s [siz=%d pkt=%d])\n",
  87632. + ep->dwc_ep.num,
  87633. + (ep->dwc_ep.is_in ? "IN" : "OUT"),
  87634. + deptsiz.b.xfersize,
  87635. + deptsiz.b.pktcnt);
  87636. + }
  87637. + } else {
  87638. + dma_desc = ep->dwc_ep.desc_addr;
  87639. + byte_count = 0;
  87640. + ep->dwc_ep.sent_zlp = 0;
  87641. +
  87642. +#ifdef DWC_UTE_CFI
  87643. + CFI_INFO("%s: BUFFER_MODE=%d\n", __func__,
  87644. + ep->dwc_ep.buff_mode);
  87645. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  87646. + int residue;
  87647. +
  87648. + residue = cfi_calc_desc_residue(ep);
  87649. + if (residue < 0)
  87650. + return;
  87651. +
  87652. + byte_count = residue;
  87653. + } else {
  87654. +#endif
  87655. + for (i = 0; i < ep->dwc_ep.desc_cnt;
  87656. + ++i) {
  87657. + desc_sts = dma_desc->status;
  87658. + byte_count += desc_sts.b.bytes;
  87659. + dma_desc++;
  87660. + }
  87661. +#ifdef DWC_UTE_CFI
  87662. + }
  87663. +#endif
  87664. + if (byte_count == 0) {
  87665. + ep->dwc_ep.xfer_count =
  87666. + ep->dwc_ep.total_len;
  87667. + is_last = 1;
  87668. + } else {
  87669. + DWC_WARN("Incomplete transfer\n");
  87670. + }
  87671. + }
  87672. + } else {
  87673. + if (deptsiz.b.xfersize == 0 && deptsiz.b.pktcnt == 0) {
  87674. + DWC_DEBUGPL(DBG_PCDV,
  87675. + "%d-%s len=%d xfersize=%d pktcnt=%d\n",
  87676. + ep->dwc_ep.num,
  87677. + ep->dwc_ep.is_in ? "IN" : "OUT",
  87678. + ep->dwc_ep.xfer_len,
  87679. + deptsiz.b.xfersize,
  87680. + deptsiz.b.pktcnt);
  87681. +
  87682. + /* Check if the whole transfer was completed,
  87683. + * if no, setup transfer for next portion of data
  87684. + */
  87685. + if (ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
  87686. + dwc_otg_ep_start_transfer(core_if,
  87687. + &ep->dwc_ep);
  87688. + } else if (ep->dwc_ep.sent_zlp) {
  87689. + /*
  87690. + * This fragment of code should initiate 0
  87691. + * length trasfer in case if it is queued
  87692. + * a trasfer with size divisible to EPs max
  87693. + * packet size and with usb_request zero field
  87694. + * is set, which means that after data is transfered,
  87695. + * it is also should be transfered
  87696. + * a 0 length packet at the end. For Slave and
  87697. + * Buffer DMA modes in this case SW has
  87698. + * to initiate 2 transfers one with transfer size,
  87699. + * and the second with 0 size. For Desriptor
  87700. + * DMA mode SW is able to initiate a transfer,
  87701. + * which will handle all the packets including
  87702. + * the last 0 legth.
  87703. + */
  87704. + ep->dwc_ep.sent_zlp = 0;
  87705. + dwc_otg_ep_start_zl_transfer(core_if,
  87706. + &ep->dwc_ep);
  87707. + } else {
  87708. + is_last = 1;
  87709. + }
  87710. + } else {
  87711. + DWC_WARN
  87712. + ("Incomplete transfer (%d-%s [siz=%d pkt=%d])\n",
  87713. + ep->dwc_ep.num,
  87714. + (ep->dwc_ep.is_in ? "IN" : "OUT"),
  87715. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  87716. + }
  87717. + }
  87718. + } else {
  87719. + dwc_otg_dev_out_ep_regs_t *out_ep_regs =
  87720. + dev_if->out_ep_regs[ep->dwc_ep.num];
  87721. + desc_sts.d32 = 0;
  87722. + if (core_if->dma_enable) {
  87723. + if (core_if->dma_desc_enable) {
  87724. + dma_desc = ep->dwc_ep.desc_addr;
  87725. + byte_count = 0;
  87726. + ep->dwc_ep.sent_zlp = 0;
  87727. +
  87728. +#ifdef DWC_UTE_CFI
  87729. + CFI_INFO("%s: BUFFER_MODE=%d\n", __func__,
  87730. + ep->dwc_ep.buff_mode);
  87731. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  87732. + int residue;
  87733. + residue = cfi_calc_desc_residue(ep);
  87734. + if (residue < 0)
  87735. + return;
  87736. + byte_count = residue;
  87737. + } else {
  87738. +#endif
  87739. +
  87740. + for (i = 0; i < ep->dwc_ep.desc_cnt;
  87741. + ++i) {
  87742. + desc_sts = dma_desc->status;
  87743. + byte_count += desc_sts.b.bytes;
  87744. + dma_desc++;
  87745. + }
  87746. +
  87747. +#ifdef DWC_UTE_CFI
  87748. + }
  87749. +#endif
  87750. + /* Checking for interrupt Out transfers with not
  87751. + * dword aligned mps sizes
  87752. + */
  87753. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_INTR &&
  87754. + (ep->dwc_ep.maxpacket%4)) {
  87755. + ep->dwc_ep.xfer_count =
  87756. + ep->dwc_ep.total_len - byte_count;
  87757. + if ((ep->dwc_ep.xfer_len %
  87758. + ep->dwc_ep.maxpacket)
  87759. + && (ep->dwc_ep.xfer_len /
  87760. + ep->dwc_ep.maxpacket <
  87761. + MAX_DMA_DESC_CNT))
  87762. + ep->dwc_ep.xfer_len -=
  87763. + (ep->dwc_ep.desc_cnt -
  87764. + 1) * ep->dwc_ep.maxpacket +
  87765. + ep->dwc_ep.xfer_len %
  87766. + ep->dwc_ep.maxpacket;
  87767. + else
  87768. + ep->dwc_ep.xfer_len -=
  87769. + ep->dwc_ep.desc_cnt *
  87770. + ep->dwc_ep.maxpacket;
  87771. + if (ep->dwc_ep.xfer_len > 0) {
  87772. + dwc_otg_ep_start_transfer
  87773. + (core_if, &ep->dwc_ep);
  87774. + } else {
  87775. + is_last = 1;
  87776. + }
  87777. + } else {
  87778. + ep->dwc_ep.xfer_count =
  87779. + ep->dwc_ep.total_len - byte_count +
  87780. + ((4 -
  87781. + (ep->dwc_ep.
  87782. + total_len & 0x3)) & 0x3);
  87783. + is_last = 1;
  87784. + }
  87785. + } else {
  87786. + deptsiz.d32 = 0;
  87787. + deptsiz.d32 =
  87788. + DWC_READ_REG32(&out_ep_regs->doeptsiz);
  87789. +
  87790. + byte_count = (ep->dwc_ep.xfer_len -
  87791. + ep->dwc_ep.xfer_count -
  87792. + deptsiz.b.xfersize);
  87793. + ep->dwc_ep.xfer_buff += byte_count;
  87794. + ep->dwc_ep.dma_addr += byte_count;
  87795. + ep->dwc_ep.xfer_count += byte_count;
  87796. +
  87797. + /* Check if the whole transfer was completed,
  87798. + * if no, setup transfer for next portion of data
  87799. + */
  87800. + if (ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
  87801. + dwc_otg_ep_start_transfer(core_if,
  87802. + &ep->dwc_ep);
  87803. + } else if (ep->dwc_ep.sent_zlp) {
  87804. + /*
  87805. + * This fragment of code should initiate 0
  87806. + * length trasfer in case if it is queued
  87807. + * a trasfer with size divisible to EPs max
  87808. + * packet size and with usb_request zero field
  87809. + * is set, which means that after data is transfered,
  87810. + * it is also should be transfered
  87811. + * a 0 length packet at the end. For Slave and
  87812. + * Buffer DMA modes in this case SW has
  87813. + * to initiate 2 transfers one with transfer size,
  87814. + * and the second with 0 size. For Desriptor
  87815. + * DMA mode SW is able to initiate a transfer,
  87816. + * which will handle all the packets including
  87817. + * the last 0 legth.
  87818. + */
  87819. + ep->dwc_ep.sent_zlp = 0;
  87820. + dwc_otg_ep_start_zl_transfer(core_if,
  87821. + &ep->dwc_ep);
  87822. + } else {
  87823. + is_last = 1;
  87824. + }
  87825. + }
  87826. + } else {
  87827. + /* Check if the whole transfer was completed,
  87828. + * if no, setup transfer for next portion of data
  87829. + */
  87830. + if (ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
  87831. + dwc_otg_ep_start_transfer(core_if, &ep->dwc_ep);
  87832. + } else if (ep->dwc_ep.sent_zlp) {
  87833. + /*
  87834. + * This fragment of code should initiate 0
  87835. + * length transfer in case if it is queued
  87836. + * a transfer with size divisible to EPs max
  87837. + * packet size and with usb_request zero field
  87838. + * is set, which means that after data is transfered,
  87839. + * it is also should be transfered
  87840. + * a 0 length packet at the end. For Slave and
  87841. + * Buffer DMA modes in this case SW has
  87842. + * to initiate 2 transfers one with transfer size,
  87843. + * and the second with 0 size. For Descriptor
  87844. + * DMA mode SW is able to initiate a transfer,
  87845. + * which will handle all the packets including
  87846. + * the last 0 length.
  87847. + */
  87848. + ep->dwc_ep.sent_zlp = 0;
  87849. + dwc_otg_ep_start_zl_transfer(core_if,
  87850. + &ep->dwc_ep);
  87851. + } else {
  87852. + is_last = 1;
  87853. + }
  87854. + }
  87855. +
  87856. + DWC_DEBUGPL(DBG_PCDV,
  87857. + "addr %p, %d-%s len=%d cnt=%d xsize=%d pktcnt=%d\n",
  87858. + &out_ep_regs->doeptsiz, ep->dwc_ep.num,
  87859. + ep->dwc_ep.is_in ? "IN" : "OUT",
  87860. + ep->dwc_ep.xfer_len, ep->dwc_ep.xfer_count,
  87861. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  87862. + }
  87863. +
  87864. + /* Complete the request */
  87865. + if (is_last) {
  87866. +#ifdef DWC_UTE_CFI
  87867. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  87868. + req->actual = ep->dwc_ep.cfi_req_len - byte_count;
  87869. + } else {
  87870. +#endif
  87871. + req->actual = ep->dwc_ep.xfer_count;
  87872. +#ifdef DWC_UTE_CFI
  87873. + }
  87874. +#endif
  87875. + if (req->dw_align_buf) {
  87876. + if (!ep->dwc_ep.is_in) {
  87877. + dwc_memcpy(req->buf, req->dw_align_buf, req->length);
  87878. + }
  87879. + DWC_DMA_FREE(req->length, req->dw_align_buf,
  87880. + req->dw_align_buf_dma);
  87881. + }
  87882. +
  87883. + dwc_otg_request_done(ep, req, 0);
  87884. +
  87885. + ep->dwc_ep.start_xfer_buff = 0;
  87886. + ep->dwc_ep.xfer_buff = 0;
  87887. + ep->dwc_ep.xfer_len = 0;
  87888. +
  87889. + /* If there is a request in the queue start it. */
  87890. + start_next_request(ep);
  87891. + }
  87892. +}
  87893. +
  87894. +#ifdef DWC_EN_ISOC
  87895. +
  87896. +/**
  87897. + * This function BNA interrupt for Isochronous EPs
  87898. + *
  87899. + */
  87900. +static void dwc_otg_pcd_handle_iso_bna(dwc_otg_pcd_ep_t * ep)
  87901. +{
  87902. + dwc_ep_t *dwc_ep = &ep->dwc_ep;
  87903. + volatile uint32_t *addr;
  87904. + depctl_data_t depctl = {.d32 = 0 };
  87905. + dwc_otg_pcd_t *pcd = ep->pcd;
  87906. + dwc_otg_dev_dma_desc_t *dma_desc;
  87907. + int i;
  87908. +
  87909. + dma_desc =
  87910. + dwc_ep->iso_desc_addr + dwc_ep->desc_cnt * (dwc_ep->proc_buf_num);
  87911. +
  87912. + if (dwc_ep->is_in) {
  87913. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  87914. + for (i = 0; i < dwc_ep->desc_cnt; ++i, ++dma_desc) {
  87915. + sts.d32 = dma_desc->status.d32;
  87916. + sts.b_iso_in.bs = BS_HOST_READY;
  87917. + dma_desc->status.d32 = sts.d32;
  87918. + }
  87919. + } else {
  87920. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  87921. + for (i = 0; i < dwc_ep->desc_cnt; ++i, ++dma_desc) {
  87922. + sts.d32 = dma_desc->status.d32;
  87923. + sts.b_iso_out.bs = BS_HOST_READY;
  87924. + dma_desc->status.d32 = sts.d32;
  87925. + }
  87926. + }
  87927. +
  87928. + if (dwc_ep->is_in == 0) {
  87929. + addr =
  87930. + &GET_CORE_IF(pcd)->dev_if->out_ep_regs[dwc_ep->
  87931. + num]->doepctl;
  87932. + } else {
  87933. + addr =
  87934. + &GET_CORE_IF(pcd)->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  87935. + }
  87936. + depctl.b.epena = 1;
  87937. + DWC_MODIFY_REG32(addr, depctl.d32, depctl.d32);
  87938. +}
  87939. +
  87940. +/**
  87941. + * This function sets latest iso packet information(non-PTI mode)
  87942. + *
  87943. + * @param core_if Programming view of DWC_otg controller.
  87944. + * @param ep The EP to start the transfer on.
  87945. + *
  87946. + */
  87947. +void set_current_pkt_info(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  87948. +{
  87949. + deptsiz_data_t deptsiz = {.d32 = 0 };
  87950. + dma_addr_t dma_addr;
  87951. + uint32_t offset;
  87952. +
  87953. + if (ep->proc_buf_num)
  87954. + dma_addr = ep->dma_addr1;
  87955. + else
  87956. + dma_addr = ep->dma_addr0;
  87957. +
  87958. + if (ep->is_in) {
  87959. + deptsiz.d32 =
  87960. + DWC_READ_REG32(&core_if->dev_if->
  87961. + in_ep_regs[ep->num]->dieptsiz);
  87962. + offset = ep->data_per_frame;
  87963. + } else {
  87964. + deptsiz.d32 =
  87965. + DWC_READ_REG32(&core_if->dev_if->
  87966. + out_ep_regs[ep->num]->doeptsiz);
  87967. + offset =
  87968. + ep->data_per_frame +
  87969. + (0x4 & (0x4 - (ep->data_per_frame & 0x3)));
  87970. + }
  87971. +
  87972. + if (!deptsiz.b.xfersize) {
  87973. + ep->pkt_info[ep->cur_pkt].length = ep->data_per_frame;
  87974. + ep->pkt_info[ep->cur_pkt].offset =
  87975. + ep->cur_pkt_dma_addr - dma_addr;
  87976. + ep->pkt_info[ep->cur_pkt].status = 0;
  87977. + } else {
  87978. + ep->pkt_info[ep->cur_pkt].length = ep->data_per_frame;
  87979. + ep->pkt_info[ep->cur_pkt].offset =
  87980. + ep->cur_pkt_dma_addr - dma_addr;
  87981. + ep->pkt_info[ep->cur_pkt].status = -DWC_E_NO_DATA;
  87982. + }
  87983. + ep->cur_pkt_addr += offset;
  87984. + ep->cur_pkt_dma_addr += offset;
  87985. + ep->cur_pkt++;
  87986. +}
  87987. +
  87988. +/**
  87989. + * This function sets latest iso packet information(DDMA mode)
  87990. + *
  87991. + * @param core_if Programming view of DWC_otg controller.
  87992. + * @param dwc_ep The EP to start the transfer on.
  87993. + *
  87994. + */
  87995. +static void set_ddma_iso_pkts_info(dwc_otg_core_if_t * core_if,
  87996. + dwc_ep_t * dwc_ep)
  87997. +{
  87998. + dwc_otg_dev_dma_desc_t *dma_desc;
  87999. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  88000. + iso_pkt_info_t *iso_packet;
  88001. + uint32_t data_per_desc;
  88002. + uint32_t offset;
  88003. + int i, j;
  88004. +
  88005. + iso_packet = dwc_ep->pkt_info;
  88006. +
  88007. + /** Reinit closed DMA Descriptors*/
  88008. + /** ISO OUT EP */
  88009. + if (dwc_ep->is_in == 0) {
  88010. + dma_desc =
  88011. + dwc_ep->iso_desc_addr +
  88012. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  88013. + offset = 0;
  88014. +
  88015. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  88016. + i += dwc_ep->pkt_per_frm) {
  88017. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  88018. + data_per_desc =
  88019. + ((j + 1) * dwc_ep->maxpacket >
  88020. + dwc_ep->
  88021. + data_per_frame) ? dwc_ep->data_per_frame -
  88022. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  88023. + data_per_desc +=
  88024. + (data_per_desc % 4) ? (4 -
  88025. + data_per_desc %
  88026. + 4) : 0;
  88027. +
  88028. + sts.d32 = dma_desc->status.d32;
  88029. +
  88030. + /* Write status in iso_packet_decsriptor */
  88031. + iso_packet->status =
  88032. + sts.b_iso_out.rxsts +
  88033. + (sts.b_iso_out.bs ^ BS_DMA_DONE);
  88034. + if (iso_packet->status) {
  88035. + iso_packet->status = -DWC_E_NO_DATA;
  88036. + }
  88037. +
  88038. + /* Received data length */
  88039. + if (!sts.b_iso_out.rxbytes) {
  88040. + iso_packet->length =
  88041. + data_per_desc -
  88042. + sts.b_iso_out.rxbytes;
  88043. + } else {
  88044. + iso_packet->length =
  88045. + data_per_desc -
  88046. + sts.b_iso_out.rxbytes + (4 -
  88047. + dwc_ep->data_per_frame
  88048. + % 4);
  88049. + }
  88050. +
  88051. + iso_packet->offset = offset;
  88052. +
  88053. + offset += data_per_desc;
  88054. + dma_desc++;
  88055. + iso_packet++;
  88056. + }
  88057. + }
  88058. +
  88059. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  88060. + data_per_desc =
  88061. + ((j + 1) * dwc_ep->maxpacket >
  88062. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  88063. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  88064. + data_per_desc +=
  88065. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  88066. +
  88067. + sts.d32 = dma_desc->status.d32;
  88068. +
  88069. + /* Write status in iso_packet_decsriptor */
  88070. + iso_packet->status =
  88071. + sts.b_iso_out.rxsts +
  88072. + (sts.b_iso_out.bs ^ BS_DMA_DONE);
  88073. + if (iso_packet->status) {
  88074. + iso_packet->status = -DWC_E_NO_DATA;
  88075. + }
  88076. +
  88077. + /* Received data length */
  88078. + iso_packet->length =
  88079. + dwc_ep->data_per_frame - sts.b_iso_out.rxbytes;
  88080. +
  88081. + iso_packet->offset = offset;
  88082. +
  88083. + offset += data_per_desc;
  88084. + iso_packet++;
  88085. + dma_desc++;
  88086. + }
  88087. +
  88088. + sts.d32 = dma_desc->status.d32;
  88089. +
  88090. + /* Write status in iso_packet_decsriptor */
  88091. + iso_packet->status =
  88092. + sts.b_iso_out.rxsts + (sts.b_iso_out.bs ^ BS_DMA_DONE);
  88093. + if (iso_packet->status) {
  88094. + iso_packet->status = -DWC_E_NO_DATA;
  88095. + }
  88096. + /* Received data length */
  88097. + if (!sts.b_iso_out.rxbytes) {
  88098. + iso_packet->length =
  88099. + dwc_ep->data_per_frame - sts.b_iso_out.rxbytes;
  88100. + } else {
  88101. + iso_packet->length =
  88102. + dwc_ep->data_per_frame - sts.b_iso_out.rxbytes +
  88103. + (4 - dwc_ep->data_per_frame % 4);
  88104. + }
  88105. +
  88106. + iso_packet->offset = offset;
  88107. + } else {
  88108. +/** ISO IN EP */
  88109. +
  88110. + dma_desc =
  88111. + dwc_ep->iso_desc_addr +
  88112. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  88113. +
  88114. + for (i = 0; i < dwc_ep->desc_cnt - 1; i++) {
  88115. + sts.d32 = dma_desc->status.d32;
  88116. +
  88117. + /* Write status in iso packet descriptor */
  88118. + iso_packet->status =
  88119. + sts.b_iso_in.txsts +
  88120. + (sts.b_iso_in.bs ^ BS_DMA_DONE);
  88121. + if (iso_packet->status != 0) {
  88122. + iso_packet->status = -DWC_E_NO_DATA;
  88123. +
  88124. + }
  88125. + /* Bytes has been transfered */
  88126. + iso_packet->length =
  88127. + dwc_ep->data_per_frame - sts.b_iso_in.txbytes;
  88128. +
  88129. + dma_desc++;
  88130. + iso_packet++;
  88131. + }
  88132. +
  88133. + sts.d32 = dma_desc->status.d32;
  88134. + while (sts.b_iso_in.bs == BS_DMA_BUSY) {
  88135. + sts.d32 = dma_desc->status.d32;
  88136. + }
  88137. +
  88138. + /* Write status in iso packet descriptor ??? do be done with ERROR codes */
  88139. + iso_packet->status =
  88140. + sts.b_iso_in.txsts + (sts.b_iso_in.bs ^ BS_DMA_DONE);
  88141. + if (iso_packet->status != 0) {
  88142. + iso_packet->status = -DWC_E_NO_DATA;
  88143. + }
  88144. +
  88145. + /* Bytes has been transfered */
  88146. + iso_packet->length =
  88147. + dwc_ep->data_per_frame - sts.b_iso_in.txbytes;
  88148. + }
  88149. +}
  88150. +
  88151. +/**
  88152. + * This function reinitialize DMA Descriptors for Isochronous transfer
  88153. + *
  88154. + * @param core_if Programming view of DWC_otg controller.
  88155. + * @param dwc_ep The EP to start the transfer on.
  88156. + *
  88157. + */
  88158. +static void reinit_ddma_iso_xfer(dwc_otg_core_if_t * core_if, dwc_ep_t * dwc_ep)
  88159. +{
  88160. + int i, j;
  88161. + dwc_otg_dev_dma_desc_t *dma_desc;
  88162. + dma_addr_t dma_ad;
  88163. + volatile uint32_t *addr;
  88164. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  88165. + uint32_t data_per_desc;
  88166. +
  88167. + if (dwc_ep->is_in == 0) {
  88168. + addr = &core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl;
  88169. + } else {
  88170. + addr = &core_if->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  88171. + }
  88172. +
  88173. + if (dwc_ep->proc_buf_num == 0) {
  88174. + /** Buffer 0 descriptors setup */
  88175. + dma_ad = dwc_ep->dma_addr0;
  88176. + } else {
  88177. + /** Buffer 1 descriptors setup */
  88178. + dma_ad = dwc_ep->dma_addr1;
  88179. + }
  88180. +
  88181. + /** Reinit closed DMA Descriptors*/
  88182. + /** ISO OUT EP */
  88183. + if (dwc_ep->is_in == 0) {
  88184. + dma_desc =
  88185. + dwc_ep->iso_desc_addr +
  88186. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  88187. +
  88188. + sts.b_iso_out.bs = BS_HOST_READY;
  88189. + sts.b_iso_out.rxsts = 0;
  88190. + sts.b_iso_out.l = 0;
  88191. + sts.b_iso_out.sp = 0;
  88192. + sts.b_iso_out.ioc = 0;
  88193. + sts.b_iso_out.pid = 0;
  88194. + sts.b_iso_out.framenum = 0;
  88195. +
  88196. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  88197. + i += dwc_ep->pkt_per_frm) {
  88198. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  88199. + data_per_desc =
  88200. + ((j + 1) * dwc_ep->maxpacket >
  88201. + dwc_ep->
  88202. + data_per_frame) ? dwc_ep->data_per_frame -
  88203. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  88204. + data_per_desc +=
  88205. + (data_per_desc % 4) ? (4 -
  88206. + data_per_desc %
  88207. + 4) : 0;
  88208. + sts.b_iso_out.rxbytes = data_per_desc;
  88209. + dma_desc->buf = dma_ad;
  88210. + dma_desc->status.d32 = sts.d32;
  88211. +
  88212. + dma_ad += data_per_desc;
  88213. + dma_desc++;
  88214. + }
  88215. + }
  88216. +
  88217. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  88218. +
  88219. + data_per_desc =
  88220. + ((j + 1) * dwc_ep->maxpacket >
  88221. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  88222. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  88223. + data_per_desc +=
  88224. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  88225. + sts.b_iso_out.rxbytes = data_per_desc;
  88226. +
  88227. + dma_desc->buf = dma_ad;
  88228. + dma_desc->status.d32 = sts.d32;
  88229. +
  88230. + dma_desc++;
  88231. + dma_ad += data_per_desc;
  88232. + }
  88233. +
  88234. + sts.b_iso_out.ioc = 1;
  88235. + sts.b_iso_out.l = dwc_ep->proc_buf_num;
  88236. +
  88237. + data_per_desc =
  88238. + ((j + 1) * dwc_ep->maxpacket >
  88239. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  88240. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  88241. + data_per_desc +=
  88242. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  88243. + sts.b_iso_out.rxbytes = data_per_desc;
  88244. +
  88245. + dma_desc->buf = dma_ad;
  88246. + dma_desc->status.d32 = sts.d32;
  88247. + } else {
  88248. +/** ISO IN EP */
  88249. +
  88250. + dma_desc =
  88251. + dwc_ep->iso_desc_addr +
  88252. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  88253. +
  88254. + sts.b_iso_in.bs = BS_HOST_READY;
  88255. + sts.b_iso_in.txsts = 0;
  88256. + sts.b_iso_in.sp = 0;
  88257. + sts.b_iso_in.ioc = 0;
  88258. + sts.b_iso_in.pid = dwc_ep->pkt_per_frm;
  88259. + sts.b_iso_in.framenum = dwc_ep->next_frame;
  88260. + sts.b_iso_in.txbytes = dwc_ep->data_per_frame;
  88261. + sts.b_iso_in.l = 0;
  88262. +
  88263. + for (i = 0; i < dwc_ep->desc_cnt - 1; i++) {
  88264. + dma_desc->buf = dma_ad;
  88265. + dma_desc->status.d32 = sts.d32;
  88266. +
  88267. + sts.b_iso_in.framenum += dwc_ep->bInterval;
  88268. + dma_ad += dwc_ep->data_per_frame;
  88269. + dma_desc++;
  88270. + }
  88271. +
  88272. + sts.b_iso_in.ioc = 1;
  88273. + sts.b_iso_in.l = dwc_ep->proc_buf_num;
  88274. +
  88275. + dma_desc->buf = dma_ad;
  88276. + dma_desc->status.d32 = sts.d32;
  88277. +
  88278. + dwc_ep->next_frame =
  88279. + sts.b_iso_in.framenum + dwc_ep->bInterval * 1;
  88280. + }
  88281. + dwc_ep->proc_buf_num = (dwc_ep->proc_buf_num ^ 1) & 0x1;
  88282. +}
  88283. +
  88284. +/**
  88285. + * This function is to handle Iso EP transfer complete interrupt
  88286. + * in case Iso out packet was dropped
  88287. + *
  88288. + * @param core_if Programming view of DWC_otg controller.
  88289. + * @param dwc_ep The EP for wihich transfer complete was asserted
  88290. + *
  88291. + */
  88292. +static uint32_t handle_iso_out_pkt_dropped(dwc_otg_core_if_t * core_if,
  88293. + dwc_ep_t * dwc_ep)
  88294. +{
  88295. + uint32_t dma_addr;
  88296. + uint32_t drp_pkt;
  88297. + uint32_t drp_pkt_cnt;
  88298. + deptsiz_data_t deptsiz = {.d32 = 0 };
  88299. + depctl_data_t depctl = {.d32 = 0 };
  88300. + int i;
  88301. +
  88302. + deptsiz.d32 =
  88303. + DWC_READ_REG32(&core_if->dev_if->
  88304. + out_ep_regs[dwc_ep->num]->doeptsiz);
  88305. +
  88306. + drp_pkt = dwc_ep->pkt_cnt - deptsiz.b.pktcnt;
  88307. + drp_pkt_cnt = dwc_ep->pkt_per_frm - (drp_pkt % dwc_ep->pkt_per_frm);
  88308. +
  88309. + /* Setting dropped packets status */
  88310. + for (i = 0; i < drp_pkt_cnt; ++i) {
  88311. + dwc_ep->pkt_info[drp_pkt].status = -DWC_E_NO_DATA;
  88312. + drp_pkt++;
  88313. + deptsiz.b.pktcnt--;
  88314. + }
  88315. +
  88316. + if (deptsiz.b.pktcnt > 0) {
  88317. + deptsiz.b.xfersize =
  88318. + dwc_ep->xfer_len - (dwc_ep->pkt_cnt -
  88319. + deptsiz.b.pktcnt) * dwc_ep->maxpacket;
  88320. + } else {
  88321. + deptsiz.b.xfersize = 0;
  88322. + deptsiz.b.pktcnt = 0;
  88323. + }
  88324. +
  88325. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doeptsiz,
  88326. + deptsiz.d32);
  88327. +
  88328. + if (deptsiz.b.pktcnt > 0) {
  88329. + if (dwc_ep->proc_buf_num) {
  88330. + dma_addr =
  88331. + dwc_ep->dma_addr1 + dwc_ep->xfer_len -
  88332. + deptsiz.b.xfersize;
  88333. + } else {
  88334. + dma_addr =
  88335. + dwc_ep->dma_addr0 + dwc_ep->xfer_len -
  88336. + deptsiz.b.xfersize;;
  88337. + }
  88338. +
  88339. + DWC_WRITE_REG32(&core_if->dev_if->
  88340. + out_ep_regs[dwc_ep->num]->doepdma, dma_addr);
  88341. +
  88342. + /** Re-enable endpoint, clear nak */
  88343. + depctl.d32 = 0;
  88344. + depctl.b.epena = 1;
  88345. + depctl.b.cnak = 1;
  88346. +
  88347. + DWC_MODIFY_REG32(&core_if->dev_if->
  88348. + out_ep_regs[dwc_ep->num]->doepctl, depctl.d32,
  88349. + depctl.d32);
  88350. + return 0;
  88351. + } else {
  88352. + return 1;
  88353. + }
  88354. +}
  88355. +
  88356. +/**
  88357. + * This function sets iso packets information(PTI mode)
  88358. + *
  88359. + * @param core_if Programming view of DWC_otg controller.
  88360. + * @param ep The EP to start the transfer on.
  88361. + *
  88362. + */
  88363. +static uint32_t set_iso_pkts_info(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  88364. +{
  88365. + int i, j;
  88366. + dma_addr_t dma_ad;
  88367. + iso_pkt_info_t *packet_info = ep->pkt_info;
  88368. + uint32_t offset;
  88369. + uint32_t frame_data;
  88370. + deptsiz_data_t deptsiz;
  88371. +
  88372. + if (ep->proc_buf_num == 0) {
  88373. + /** Buffer 0 descriptors setup */
  88374. + dma_ad = ep->dma_addr0;
  88375. + } else {
  88376. + /** Buffer 1 descriptors setup */
  88377. + dma_ad = ep->dma_addr1;
  88378. + }
  88379. +
  88380. + if (ep->is_in) {
  88381. + deptsiz.d32 =
  88382. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  88383. + dieptsiz);
  88384. + } else {
  88385. + deptsiz.d32 =
  88386. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[ep->num]->
  88387. + doeptsiz);
  88388. + }
  88389. +
  88390. + if (!deptsiz.b.xfersize) {
  88391. + offset = 0;
  88392. + for (i = 0; i < ep->pkt_cnt; i += ep->pkt_per_frm) {
  88393. + frame_data = ep->data_per_frame;
  88394. + for (j = 0; j < ep->pkt_per_frm; ++j) {
  88395. +
  88396. + /* Packet status - is not set as initially
  88397. + * it is set to 0 and if packet was sent
  88398. + successfully, status field will remain 0*/
  88399. +
  88400. + /* Bytes has been transfered */
  88401. + packet_info->length =
  88402. + (ep->maxpacket <
  88403. + frame_data) ? ep->maxpacket : frame_data;
  88404. +
  88405. + /* Received packet offset */
  88406. + packet_info->offset = offset;
  88407. + offset += packet_info->length;
  88408. + frame_data -= packet_info->length;
  88409. +
  88410. + packet_info++;
  88411. + }
  88412. + }
  88413. + return 1;
  88414. + } else {
  88415. + /* This is a workaround for in case of Transfer Complete with
  88416. + * PktDrpSts interrupts merging - in this case Transfer complete
  88417. + * interrupt for Isoc Out Endpoint is asserted without PktDrpSts
  88418. + * set and with DOEPTSIZ register non zero. Investigations showed,
  88419. + * that this happens when Out packet is dropped, but because of
  88420. + * interrupts merging during first interrupt handling PktDrpSts
  88421. + * bit is cleared and for next merged interrupts it is not reset.
  88422. + * In this case SW hadles the interrupt as if PktDrpSts bit is set.
  88423. + */
  88424. + if (ep->is_in) {
  88425. + return 1;
  88426. + } else {
  88427. + return handle_iso_out_pkt_dropped(core_if, ep);
  88428. + }
  88429. + }
  88430. +}
  88431. +
  88432. +/**
  88433. + * This function is to handle Iso EP transfer complete interrupt
  88434. + *
  88435. + * @param pcd The PCD
  88436. + * @param ep The EP for which transfer complete was asserted
  88437. + *
  88438. + */
  88439. +static void complete_iso_ep(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep)
  88440. +{
  88441. + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
  88442. + dwc_ep_t *dwc_ep = &ep->dwc_ep;
  88443. + uint8_t is_last = 0;
  88444. +
  88445. + if (ep->dwc_ep.next_frame == 0xffffffff) {
  88446. + DWC_WARN("Next frame is not set!\n");
  88447. + return;
  88448. + }
  88449. +
  88450. + if (core_if->dma_enable) {
  88451. + if (core_if->dma_desc_enable) {
  88452. + set_ddma_iso_pkts_info(core_if, dwc_ep);
  88453. + reinit_ddma_iso_xfer(core_if, dwc_ep);
  88454. + is_last = 1;
  88455. + } else {
  88456. + if (core_if->pti_enh_enable) {
  88457. + if (set_iso_pkts_info(core_if, dwc_ep)) {
  88458. + dwc_ep->proc_buf_num =
  88459. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  88460. + dwc_otg_iso_ep_start_buf_transfer
  88461. + (core_if, dwc_ep);
  88462. + is_last = 1;
  88463. + }
  88464. + } else {
  88465. + set_current_pkt_info(core_if, dwc_ep);
  88466. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  88467. + is_last = 1;
  88468. + dwc_ep->cur_pkt = 0;
  88469. + dwc_ep->proc_buf_num =
  88470. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  88471. + if (dwc_ep->proc_buf_num) {
  88472. + dwc_ep->cur_pkt_addr =
  88473. + dwc_ep->xfer_buff1;
  88474. + dwc_ep->cur_pkt_dma_addr =
  88475. + dwc_ep->dma_addr1;
  88476. + } else {
  88477. + dwc_ep->cur_pkt_addr =
  88478. + dwc_ep->xfer_buff0;
  88479. + dwc_ep->cur_pkt_dma_addr =
  88480. + dwc_ep->dma_addr0;
  88481. + }
  88482. +
  88483. + }
  88484. + dwc_otg_iso_ep_start_frm_transfer(core_if,
  88485. + dwc_ep);
  88486. + }
  88487. + }
  88488. + } else {
  88489. + set_current_pkt_info(core_if, dwc_ep);
  88490. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  88491. + is_last = 1;
  88492. + dwc_ep->cur_pkt = 0;
  88493. + dwc_ep->proc_buf_num = (dwc_ep->proc_buf_num ^ 1) & 0x1;
  88494. + if (dwc_ep->proc_buf_num) {
  88495. + dwc_ep->cur_pkt_addr = dwc_ep->xfer_buff1;
  88496. + dwc_ep->cur_pkt_dma_addr = dwc_ep->dma_addr1;
  88497. + } else {
  88498. + dwc_ep->cur_pkt_addr = dwc_ep->xfer_buff0;
  88499. + dwc_ep->cur_pkt_dma_addr = dwc_ep->dma_addr0;
  88500. + }
  88501. +
  88502. + }
  88503. + dwc_otg_iso_ep_start_frm_transfer(core_if, dwc_ep);
  88504. + }
  88505. + if (is_last)
  88506. + dwc_otg_iso_buffer_done(pcd, ep, ep->iso_req_handle);
  88507. +}
  88508. +#endif /* DWC_EN_ISOC */
  88509. +
  88510. +/**
  88511. + * This function handle BNA interrupt for Non Isochronous EPs
  88512. + *
  88513. + */
  88514. +static void dwc_otg_pcd_handle_noniso_bna(dwc_otg_pcd_ep_t * ep)
  88515. +{
  88516. + dwc_ep_t *dwc_ep = &ep->dwc_ep;
  88517. + volatile uint32_t *addr;
  88518. + depctl_data_t depctl = {.d32 = 0 };
  88519. + dwc_otg_pcd_t *pcd = ep->pcd;
  88520. + dwc_otg_dev_dma_desc_t *dma_desc;
  88521. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  88522. + dwc_otg_core_if_t *core_if = ep->pcd->core_if;
  88523. + int i, start;
  88524. +
  88525. + if (!dwc_ep->desc_cnt)
  88526. + DWC_WARN("Ep%d %s Descriptor count = %d \n", dwc_ep->num,
  88527. + (dwc_ep->is_in ? "IN" : "OUT"), dwc_ep->desc_cnt);
  88528. +
  88529. + if (core_if->core_params->cont_on_bna && !dwc_ep->is_in
  88530. + && dwc_ep->type != DWC_OTG_EP_TYPE_CONTROL) {
  88531. + uint32_t doepdma;
  88532. + dwc_otg_dev_out_ep_regs_t *out_regs =
  88533. + core_if->dev_if->out_ep_regs[dwc_ep->num];
  88534. + doepdma = DWC_READ_REG32(&(out_regs->doepdma));
  88535. + start = (doepdma - dwc_ep->dma_desc_addr)/sizeof(dwc_otg_dev_dma_desc_t);
  88536. + dma_desc = &(dwc_ep->desc_addr[start]);
  88537. + } else {
  88538. + start = 0;
  88539. + dma_desc = dwc_ep->desc_addr;
  88540. + }
  88541. +
  88542. +
  88543. + for (i = start; i < dwc_ep->desc_cnt; ++i, ++dma_desc) {
  88544. + sts.d32 = dma_desc->status.d32;
  88545. + sts.b.bs = BS_HOST_READY;
  88546. + dma_desc->status.d32 = sts.d32;
  88547. + }
  88548. +
  88549. + if (dwc_ep->is_in == 0) {
  88550. + addr =
  88551. + &GET_CORE_IF(pcd)->dev_if->out_ep_regs[dwc_ep->num]->
  88552. + doepctl;
  88553. + } else {
  88554. + addr =
  88555. + &GET_CORE_IF(pcd)->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  88556. + }
  88557. + depctl.b.epena = 1;
  88558. + depctl.b.cnak = 1;
  88559. + DWC_MODIFY_REG32(addr, 0, depctl.d32);
  88560. +}
  88561. +
  88562. +/**
  88563. + * This function handles EP0 Control transfers.
  88564. + *
  88565. + * The state of the control transfers are tracked in
  88566. + * <code>ep0state</code>.
  88567. + */
  88568. +static void handle_ep0(dwc_otg_pcd_t * pcd)
  88569. +{
  88570. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  88571. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  88572. + dev_dma_desc_sts_t desc_sts;
  88573. + deptsiz0_data_t deptsiz;
  88574. + uint32_t byte_count;
  88575. +
  88576. +#ifdef DEBUG_EP0
  88577. + DWC_DEBUGPL(DBG_PCDV, "%s()\n", __func__);
  88578. + print_ep0_state(pcd);
  88579. +#endif
  88580. +
  88581. +// DWC_PRINTF("HANDLE EP0\n");
  88582. +
  88583. + switch (pcd->ep0state) {
  88584. + case EP0_DISCONNECT:
  88585. + break;
  88586. +
  88587. + case EP0_IDLE:
  88588. + pcd->request_config = 0;
  88589. +
  88590. + pcd_setup(pcd);
  88591. + break;
  88592. +
  88593. + case EP0_IN_DATA_PHASE:
  88594. +#ifdef DEBUG_EP0
  88595. + DWC_DEBUGPL(DBG_PCD, "DATA_IN EP%d-%s: type=%d, mps=%d\n",
  88596. + ep0->dwc_ep.num, (ep0->dwc_ep.is_in ? "IN" : "OUT"),
  88597. + ep0->dwc_ep.type, ep0->dwc_ep.maxpacket);
  88598. +#endif
  88599. +
  88600. + if (core_if->dma_enable != 0) {
  88601. + /*
  88602. + * For EP0 we can only program 1 packet at a time so we
  88603. + * need to do the make calculations after each complete.
  88604. + * Call write_packet to make the calculations, as in
  88605. + * slave mode, and use those values to determine if we
  88606. + * can complete.
  88607. + */
  88608. + if (core_if->dma_desc_enable == 0) {
  88609. + deptsiz.d32 =
  88610. + DWC_READ_REG32(&core_if->
  88611. + dev_if->in_ep_regs[0]->
  88612. + dieptsiz);
  88613. + byte_count =
  88614. + ep0->dwc_ep.xfer_len - deptsiz.b.xfersize;
  88615. + } else {
  88616. + desc_sts =
  88617. + core_if->dev_if->in_desc_addr->status;
  88618. + byte_count =
  88619. + ep0->dwc_ep.xfer_len - desc_sts.b.bytes;
  88620. + }
  88621. + ep0->dwc_ep.xfer_count += byte_count;
  88622. + ep0->dwc_ep.xfer_buff += byte_count;
  88623. + ep0->dwc_ep.dma_addr += byte_count;
  88624. + }
  88625. + if (ep0->dwc_ep.xfer_count < ep0->dwc_ep.total_len) {
  88626. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  88627. + &ep0->dwc_ep);
  88628. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER\n");
  88629. + } else if (ep0->dwc_ep.sent_zlp) {
  88630. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  88631. + &ep0->dwc_ep);
  88632. + ep0->dwc_ep.sent_zlp = 0;
  88633. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER sent zlp\n");
  88634. + } else {
  88635. + ep0_complete_request(ep0);
  88636. + DWC_DEBUGPL(DBG_PCD, "COMPLETE TRANSFER\n");
  88637. + }
  88638. + break;
  88639. + case EP0_OUT_DATA_PHASE:
  88640. +#ifdef DEBUG_EP0
  88641. + DWC_DEBUGPL(DBG_PCD, "DATA_OUT EP%d-%s: type=%d, mps=%d\n",
  88642. + ep0->dwc_ep.num, (ep0->dwc_ep.is_in ? "IN" : "OUT"),
  88643. + ep0->dwc_ep.type, ep0->dwc_ep.maxpacket);
  88644. +#endif
  88645. + if (core_if->dma_enable != 0) {
  88646. + if (core_if->dma_desc_enable == 0) {
  88647. + deptsiz.d32 =
  88648. + DWC_READ_REG32(&core_if->
  88649. + dev_if->out_ep_regs[0]->
  88650. + doeptsiz);
  88651. + byte_count =
  88652. + ep0->dwc_ep.maxpacket - deptsiz.b.xfersize;
  88653. + } else {
  88654. + desc_sts =
  88655. + core_if->dev_if->out_desc_addr->status;
  88656. + byte_count =
  88657. + ep0->dwc_ep.maxpacket - desc_sts.b.bytes;
  88658. + }
  88659. + ep0->dwc_ep.xfer_count += byte_count;
  88660. + ep0->dwc_ep.xfer_buff += byte_count;
  88661. + ep0->dwc_ep.dma_addr += byte_count;
  88662. + }
  88663. + if (ep0->dwc_ep.xfer_count < ep0->dwc_ep.total_len) {
  88664. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  88665. + &ep0->dwc_ep);
  88666. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER\n");
  88667. + } else if (ep0->dwc_ep.sent_zlp) {
  88668. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  88669. + &ep0->dwc_ep);
  88670. + ep0->dwc_ep.sent_zlp = 0;
  88671. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER sent zlp\n");
  88672. + } else {
  88673. + ep0_complete_request(ep0);
  88674. + DWC_DEBUGPL(DBG_PCD, "COMPLETE TRANSFER\n");
  88675. + }
  88676. + break;
  88677. +
  88678. + case EP0_IN_STATUS_PHASE:
  88679. + case EP0_OUT_STATUS_PHASE:
  88680. + DWC_DEBUGPL(DBG_PCD, "CASE: EP0_STATUS\n");
  88681. + ep0_complete_request(ep0);
  88682. + pcd->ep0state = EP0_IDLE;
  88683. + ep0->stopped = 1;
  88684. + ep0->dwc_ep.is_in = 0; /* OUT for next SETUP */
  88685. +
  88686. + /* Prepare for more SETUP Packets */
  88687. + if (core_if->dma_enable) {
  88688. + ep0_out_start(core_if, pcd);
  88689. + }
  88690. + break;
  88691. +
  88692. + case EP0_STALL:
  88693. + DWC_ERROR("EP0 STALLed, should not get here pcd_setup()\n");
  88694. + break;
  88695. + }
  88696. +#ifdef DEBUG_EP0
  88697. + print_ep0_state(pcd);
  88698. +#endif
  88699. +}
  88700. +
  88701. +/**
  88702. + * Restart transfer
  88703. + */
  88704. +static void restart_transfer(dwc_otg_pcd_t * pcd, const uint32_t epnum)
  88705. +{
  88706. + dwc_otg_core_if_t *core_if;
  88707. + dwc_otg_dev_if_t *dev_if;
  88708. + deptsiz_data_t dieptsiz = {.d32 = 0 };
  88709. + dwc_otg_pcd_ep_t *ep;
  88710. +
  88711. + ep = get_in_ep(pcd, epnum);
  88712. +
  88713. +#ifdef DWC_EN_ISOC
  88714. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  88715. + return;
  88716. + }
  88717. +#endif /* DWC_EN_ISOC */
  88718. +
  88719. + core_if = GET_CORE_IF(pcd);
  88720. + dev_if = core_if->dev_if;
  88721. +
  88722. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dieptsiz);
  88723. +
  88724. + DWC_DEBUGPL(DBG_PCD, "xfer_buff=%p xfer_count=%0x xfer_len=%0x"
  88725. + " stopped=%d\n", ep->dwc_ep.xfer_buff,
  88726. + ep->dwc_ep.xfer_count, ep->dwc_ep.xfer_len, ep->stopped);
  88727. + /*
  88728. + * If xfersize is 0 and pktcnt in not 0, resend the last packet.
  88729. + */
  88730. + if (dieptsiz.b.pktcnt && dieptsiz.b.xfersize == 0 &&
  88731. + ep->dwc_ep.start_xfer_buff != 0) {
  88732. + if (ep->dwc_ep.total_len <= ep->dwc_ep.maxpacket) {
  88733. + ep->dwc_ep.xfer_count = 0;
  88734. + ep->dwc_ep.xfer_buff = ep->dwc_ep.start_xfer_buff;
  88735. + ep->dwc_ep.xfer_len = ep->dwc_ep.xfer_count;
  88736. + } else {
  88737. + ep->dwc_ep.xfer_count -= ep->dwc_ep.maxpacket;
  88738. + /* convert packet size to dwords. */
  88739. + ep->dwc_ep.xfer_buff -= ep->dwc_ep.maxpacket;
  88740. + ep->dwc_ep.xfer_len = ep->dwc_ep.xfer_count;
  88741. + }
  88742. + ep->stopped = 0;
  88743. + DWC_DEBUGPL(DBG_PCD, "xfer_buff=%p xfer_count=%0x "
  88744. + "xfer_len=%0x stopped=%d\n",
  88745. + ep->dwc_ep.xfer_buff,
  88746. + ep->dwc_ep.xfer_count, ep->dwc_ep.xfer_len,
  88747. + ep->stopped);
  88748. + if (epnum == 0) {
  88749. + dwc_otg_ep0_start_transfer(core_if, &ep->dwc_ep);
  88750. + } else {
  88751. + dwc_otg_ep_start_transfer(core_if, &ep->dwc_ep);
  88752. + }
  88753. + }
  88754. +}
  88755. +
  88756. +/*
  88757. + * This function create new nextep sequnce based on Learn Queue.
  88758. + *
  88759. + * @param core_if Programming view of DWC_otg controller
  88760. + */
  88761. +void predict_nextep_seq( dwc_otg_core_if_t * core_if)
  88762. +{
  88763. + dwc_otg_device_global_regs_t *dev_global_regs =
  88764. + core_if->dev_if->dev_global_regs;
  88765. + const uint32_t TOKEN_Q_DEPTH = core_if->hwcfg2.b.dev_token_q_depth;
  88766. + /* Number of Token Queue Registers */
  88767. + const int DTKNQ_REG_CNT = (TOKEN_Q_DEPTH + 7) / 8;
  88768. + dtknq1_data_t dtknqr1;
  88769. + uint32_t in_tkn_epnums[4];
  88770. + uint8_t seqnum[MAX_EPS_CHANNELS];
  88771. + uint8_t intkn_seq[TOKEN_Q_DEPTH];
  88772. + grstctl_t resetctl = {.d32 = 0 };
  88773. + uint8_t temp;
  88774. + int ndx = 0;
  88775. + int start = 0;
  88776. + int end = 0;
  88777. + int sort_done = 0;
  88778. + int i = 0;
  88779. + volatile uint32_t *addr = &dev_global_regs->dtknqr1;
  88780. +
  88781. +
  88782. + DWC_DEBUGPL(DBG_PCD,"dev_token_q_depth=%d\n",TOKEN_Q_DEPTH);
  88783. +
  88784. + /* Read the DTKNQ Registers */
  88785. + for (i = 0; i < DTKNQ_REG_CNT; i++) {
  88786. + in_tkn_epnums[i] = DWC_READ_REG32(addr);
  88787. + DWC_DEBUGPL(DBG_PCDV, "DTKNQR%d=0x%08x\n", i + 1,
  88788. + in_tkn_epnums[i]);
  88789. + if (addr == &dev_global_regs->dvbusdis) {
  88790. + addr = &dev_global_regs->dtknqr3_dthrctl;
  88791. + } else {
  88792. + ++addr;
  88793. + }
  88794. +
  88795. + }
  88796. +
  88797. + /* Copy the DTKNQR1 data to the bit field. */
  88798. + dtknqr1.d32 = in_tkn_epnums[0];
  88799. + if (dtknqr1.b.wrap_bit) {
  88800. + ndx = dtknqr1.b.intknwptr;
  88801. + end = ndx -1;
  88802. + if (end < 0)
  88803. + end = TOKEN_Q_DEPTH -1;
  88804. + } else {
  88805. + ndx = 0;
  88806. + end = dtknqr1.b.intknwptr -1;
  88807. + if (end < 0)
  88808. + end = 0;
  88809. + }
  88810. + start = ndx;
  88811. +
  88812. + /* Fill seqnum[] by initial values: EP number + 31 */
  88813. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  88814. + seqnum[i] = i +31;
  88815. + }
  88816. +
  88817. + /* Fill intkn_seq[] from in_tkn_epnums[0] */
  88818. + for (i=0; i < 6; i++)
  88819. + intkn_seq[i] = (in_tkn_epnums[0] >> ((7-i) * 4)) & 0xf;
  88820. +
  88821. + if (TOKEN_Q_DEPTH > 6) {
  88822. + /* Fill intkn_seq[] from in_tkn_epnums[1] */
  88823. + for (i=6; i < 14; i++)
  88824. + intkn_seq[i] =
  88825. + (in_tkn_epnums[1] >> ((7 - (i - 6)) * 4)) & 0xf;
  88826. + }
  88827. +
  88828. + if (TOKEN_Q_DEPTH > 14) {
  88829. + /* Fill intkn_seq[] from in_tkn_epnums[1] */
  88830. + for (i=14; i < 22; i++)
  88831. + intkn_seq[i] =
  88832. + (in_tkn_epnums[2] >> ((7 - (i - 14)) * 4)) & 0xf;
  88833. + }
  88834. +
  88835. + if (TOKEN_Q_DEPTH > 22) {
  88836. + /* Fill intkn_seq[] from in_tkn_epnums[1] */
  88837. + for (i=22; i < 30; i++)
  88838. + intkn_seq[i] =
  88839. + (in_tkn_epnums[3] >> ((7 - (i - 22)) * 4)) & 0xf;
  88840. + }
  88841. +
  88842. + DWC_DEBUGPL(DBG_PCDV, "%s start=%d end=%d intkn_seq[]:\n", __func__,
  88843. + start, end);
  88844. + for (i=0; i<TOKEN_Q_DEPTH; i++)
  88845. + DWC_DEBUGPL(DBG_PCDV,"%d\n", intkn_seq[i]);
  88846. +
  88847. + /* Update seqnum based on intkn_seq[] */
  88848. + i = 0;
  88849. + do {
  88850. + seqnum[intkn_seq[ndx]] = i;
  88851. + ndx++;
  88852. + i++;
  88853. + if (ndx == TOKEN_Q_DEPTH)
  88854. + ndx = 0;
  88855. + } while ( i < TOKEN_Q_DEPTH );
  88856. +
  88857. + /* Mark non active EP's in seqnum[] by 0xff */
  88858. + for (i=0; i<=core_if->dev_if->num_in_eps; i++) {
  88859. + if (core_if->nextep_seq[i] == 0xff )
  88860. + seqnum[i] = 0xff;
  88861. + }
  88862. +
  88863. + /* Sort seqnum[] */
  88864. + sort_done = 0;
  88865. + while (!sort_done) {
  88866. + sort_done = 1;
  88867. + for (i=0; i<core_if->dev_if->num_in_eps; i++) {
  88868. + if (seqnum[i] > seqnum[i+1]) {
  88869. + temp = seqnum[i];
  88870. + seqnum[i] = seqnum[i+1];
  88871. + seqnum[i+1] = temp;
  88872. + sort_done = 0;
  88873. + }
  88874. + }
  88875. + }
  88876. +
  88877. + ndx = start + seqnum[0];
  88878. + if (ndx >= TOKEN_Q_DEPTH)
  88879. + ndx = ndx % TOKEN_Q_DEPTH;
  88880. + core_if->first_in_nextep_seq = intkn_seq[ndx];
  88881. +
  88882. + /* Update seqnum[] by EP numbers */
  88883. + for (i=0; i<=core_if->dev_if->num_in_eps; i++) {
  88884. + ndx = start + i;
  88885. + if (seqnum[i] < 31) {
  88886. + ndx = start + seqnum[i];
  88887. + if (ndx >= TOKEN_Q_DEPTH)
  88888. + ndx = ndx % TOKEN_Q_DEPTH;
  88889. + seqnum[i] = intkn_seq[ndx];
  88890. + } else {
  88891. + if (seqnum[i] < 0xff) {
  88892. + seqnum[i] = seqnum[i] - 31;
  88893. + } else {
  88894. + break;
  88895. + }
  88896. + }
  88897. + }
  88898. +
  88899. + /* Update nextep_seq[] based on seqnum[] */
  88900. + for (i=0; i<core_if->dev_if->num_in_eps; i++) {
  88901. + if (seqnum[i] != 0xff) {
  88902. + if (seqnum[i+1] != 0xff) {
  88903. + core_if->nextep_seq[seqnum[i]] = seqnum[i+1];
  88904. + } else {
  88905. + core_if->nextep_seq[seqnum[i]] = core_if->first_in_nextep_seq;
  88906. + break;
  88907. + }
  88908. + } else {
  88909. + break;
  88910. + }
  88911. + }
  88912. +
  88913. + DWC_DEBUGPL(DBG_PCDV, "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  88914. + __func__, core_if->first_in_nextep_seq);
  88915. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  88916. + DWC_DEBUGPL(DBG_PCDV,"%2d\n", core_if->nextep_seq[i]);
  88917. + }
  88918. +
  88919. + /* Flush the Learning Queue */
  88920. + resetctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->grstctl);
  88921. + resetctl.b.intknqflsh = 1;
  88922. + DWC_WRITE_REG32(&core_if->core_global_regs->grstctl, resetctl.d32);
  88923. +
  88924. +
  88925. +}
  88926. +
  88927. +/**
  88928. + * handle the IN EP disable interrupt.
  88929. + */
  88930. +static inline void handle_in_ep_disable_intr(dwc_otg_pcd_t * pcd,
  88931. + const uint32_t epnum)
  88932. +{
  88933. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  88934. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  88935. + deptsiz_data_t dieptsiz = {.d32 = 0 };
  88936. + dctl_data_t dctl = {.d32 = 0 };
  88937. + dwc_otg_pcd_ep_t *ep;
  88938. + dwc_ep_t *dwc_ep;
  88939. + gintmsk_data_t gintmsk_data;
  88940. + depctl_data_t depctl;
  88941. + uint32_t diepdma;
  88942. + uint32_t remain_to_transfer = 0;
  88943. + uint8_t i;
  88944. + uint32_t xfer_size;
  88945. +
  88946. + ep = get_in_ep(pcd, epnum);
  88947. + dwc_ep = &ep->dwc_ep;
  88948. +
  88949. + if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  88950. + dwc_otg_flush_tx_fifo(core_if, dwc_ep->tx_fifo_num);
  88951. + complete_ep(ep);
  88952. + return;
  88953. + }
  88954. +
  88955. + DWC_DEBUGPL(DBG_PCD, "diepctl%d=%0x\n", epnum,
  88956. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl));
  88957. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dieptsiz);
  88958. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl);
  88959. +
  88960. + DWC_DEBUGPL(DBG_ANY, "pktcnt=%d size=%d\n",
  88961. + dieptsiz.b.pktcnt, dieptsiz.b.xfersize);
  88962. +
  88963. + if ((core_if->start_predict == 0) || (depctl.b.eptype & 1)) {
  88964. + if (ep->stopped) {
  88965. + if (core_if->en_multiple_tx_fifo)
  88966. + /* Flush the Tx FIFO */
  88967. + dwc_otg_flush_tx_fifo(core_if, dwc_ep->tx_fifo_num);
  88968. + /* Clear the Global IN NP NAK */
  88969. + dctl.d32 = 0;
  88970. + dctl.b.cgnpinnak = 1;
  88971. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  88972. + /* Restart the transaction */
  88973. + if (dieptsiz.b.pktcnt != 0 || dieptsiz.b.xfersize != 0) {
  88974. + restart_transfer(pcd, epnum);
  88975. + }
  88976. + } else {
  88977. + /* Restart the transaction */
  88978. + if (dieptsiz.b.pktcnt != 0 || dieptsiz.b.xfersize != 0) {
  88979. + restart_transfer(pcd, epnum);
  88980. + }
  88981. + DWC_DEBUGPL(DBG_ANY, "STOPPED!!!\n");
  88982. + }
  88983. + return;
  88984. + }
  88985. +
  88986. + if (core_if->start_predict > 2) { // NP IN EP
  88987. + core_if->start_predict--;
  88988. + return;
  88989. + }
  88990. +
  88991. + core_if->start_predict--;
  88992. +
  88993. + if (core_if->start_predict == 1) { // All NP IN Ep's disabled now
  88994. +
  88995. + predict_nextep_seq(core_if);
  88996. +
  88997. + /* Update all active IN EP's NextEP field based of nextep_seq[] */
  88998. + for ( i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  88999. + depctl.d32 =
  89000. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  89001. + if (core_if->nextep_seq[i] != 0xff) { // Active NP IN EP
  89002. + depctl.b.nextep = core_if->nextep_seq[i];
  89003. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32);
  89004. + }
  89005. + }
  89006. + /* Flush Shared NP TxFIFO */
  89007. + dwc_otg_flush_tx_fifo(core_if, 0);
  89008. + /* Rewind buffers */
  89009. + if (!core_if->dma_desc_enable) {
  89010. + i = core_if->first_in_nextep_seq;
  89011. + do {
  89012. + ep = get_in_ep(pcd, i);
  89013. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->dieptsiz);
  89014. + xfer_size = ep->dwc_ep.total_len - ep->dwc_ep.xfer_count;
  89015. + if (xfer_size > ep->dwc_ep.maxxfer)
  89016. + xfer_size = ep->dwc_ep.maxxfer;
  89017. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  89018. + if (dieptsiz.b.pktcnt != 0) {
  89019. + if (xfer_size == 0) {
  89020. + remain_to_transfer = 0;
  89021. + } else {
  89022. + if ((xfer_size % ep->dwc_ep.maxpacket) == 0) {
  89023. + remain_to_transfer =
  89024. + dieptsiz.b.pktcnt * ep->dwc_ep.maxpacket;
  89025. + } else {
  89026. + remain_to_transfer = ((dieptsiz.b.pktcnt -1) * ep->dwc_ep.maxpacket)
  89027. + + (xfer_size % ep->dwc_ep.maxpacket);
  89028. + }
  89029. + }
  89030. + diepdma = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepdma);
  89031. + dieptsiz.b.xfersize = remain_to_transfer;
  89032. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->dieptsiz, dieptsiz.d32);
  89033. + diepdma = ep->dwc_ep.dma_addr + (xfer_size - remain_to_transfer);
  89034. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepdma, diepdma);
  89035. + }
  89036. + i = core_if->nextep_seq[i];
  89037. + } while (i != core_if->first_in_nextep_seq);
  89038. + } else { // dma_desc_enable
  89039. + DWC_PRINTF("%s Learning Queue not supported in DDMA\n", __func__);
  89040. + }
  89041. +
  89042. + /* Restart transfers in predicted sequences */
  89043. + i = core_if->first_in_nextep_seq;
  89044. + do {
  89045. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->dieptsiz);
  89046. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  89047. + if (dieptsiz.b.pktcnt != 0) {
  89048. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  89049. + depctl.b.epena = 1;
  89050. + depctl.b.cnak = 1;
  89051. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32);
  89052. + }
  89053. + i = core_if->nextep_seq[i];
  89054. + } while (i != core_if->first_in_nextep_seq);
  89055. +
  89056. + /* Clear the global non-periodic IN NAK handshake */
  89057. + dctl.d32 = 0;
  89058. + dctl.b.cgnpinnak = 1;
  89059. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  89060. +
  89061. + /* Unmask EP Mismatch interrupt */
  89062. + gintmsk_data.d32 = 0;
  89063. + gintmsk_data.b.epmismatch = 1;
  89064. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, gintmsk_data.d32);
  89065. +
  89066. + core_if->start_predict = 0;
  89067. +
  89068. + }
  89069. +}
  89070. +
  89071. +/**
  89072. + * Handler for the IN EP timeout handshake interrupt.
  89073. + */
  89074. +static inline void handle_in_ep_timeout_intr(dwc_otg_pcd_t * pcd,
  89075. + const uint32_t epnum)
  89076. +{
  89077. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  89078. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  89079. +
  89080. +#ifdef DEBUG
  89081. + deptsiz_data_t dieptsiz = {.d32 = 0 };
  89082. + uint32_t num = 0;
  89083. +#endif
  89084. + dctl_data_t dctl = {.d32 = 0 };
  89085. + dwc_otg_pcd_ep_t *ep;
  89086. +
  89087. + gintmsk_data_t intr_mask = {.d32 = 0 };
  89088. +
  89089. + ep = get_in_ep(pcd, epnum);
  89090. +
  89091. + /* Disable the NP Tx Fifo Empty Interrrupt */
  89092. + if (!core_if->dma_enable) {
  89093. + intr_mask.b.nptxfempty = 1;
  89094. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  89095. + intr_mask.d32, 0);
  89096. + }
  89097. + /** @todo NGS Check EP type.
  89098. + * Implement for Periodic EPs */
  89099. + /*
  89100. + * Non-periodic EP
  89101. + */
  89102. + /* Enable the Global IN NAK Effective Interrupt */
  89103. + intr_mask.b.ginnakeff = 1;
  89104. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, intr_mask.d32);
  89105. +
  89106. + /* Set Global IN NAK */
  89107. + dctl.b.sgnpinnak = 1;
  89108. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  89109. +
  89110. + ep->stopped = 1;
  89111. +
  89112. +#ifdef DEBUG
  89113. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[num]->dieptsiz);
  89114. + DWC_DEBUGPL(DBG_ANY, "pktcnt=%d size=%d\n",
  89115. + dieptsiz.b.pktcnt, dieptsiz.b.xfersize);
  89116. +#endif
  89117. +
  89118. +#ifdef DISABLE_PERIODIC_EP
  89119. + /*
  89120. + * Set the NAK bit for this EP to
  89121. + * start the disable process.
  89122. + */
  89123. + diepctl.d32 = 0;
  89124. + diepctl.b.snak = 1;
  89125. + DWC_MODIFY_REG32(&dev_if->in_ep_regs[num]->diepctl, diepctl.d32,
  89126. + diepctl.d32);
  89127. + ep->disabling = 1;
  89128. + ep->stopped = 1;
  89129. +#endif
  89130. +}
  89131. +
  89132. +/**
  89133. + * Handler for the IN EP NAK interrupt.
  89134. + */
  89135. +static inline int32_t handle_in_ep_nak_intr(dwc_otg_pcd_t * pcd,
  89136. + const uint32_t epnum)
  89137. +{
  89138. + /** @todo implement ISR */
  89139. + dwc_otg_core_if_t *core_if;
  89140. + diepmsk_data_t intr_mask = {.d32 = 0 };
  89141. +
  89142. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "IN EP NAK");
  89143. + core_if = GET_CORE_IF(pcd);
  89144. + intr_mask.b.nak = 1;
  89145. +
  89146. + if (core_if->multiproc_int_enable) {
  89147. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  89148. + diepeachintmsk[epnum], intr_mask.d32, 0);
  89149. + } else {
  89150. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->diepmsk,
  89151. + intr_mask.d32, 0);
  89152. + }
  89153. +
  89154. + return 1;
  89155. +}
  89156. +
  89157. +/**
  89158. + * Handler for the OUT EP Babble interrupt.
  89159. + */
  89160. +static inline int32_t handle_out_ep_babble_intr(dwc_otg_pcd_t * pcd,
  89161. + const uint32_t epnum)
  89162. +{
  89163. + /** @todo implement ISR */
  89164. + dwc_otg_core_if_t *core_if;
  89165. + doepmsk_data_t intr_mask = {.d32 = 0 };
  89166. +
  89167. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n",
  89168. + "OUT EP Babble");
  89169. + core_if = GET_CORE_IF(pcd);
  89170. + intr_mask.b.babble = 1;
  89171. +
  89172. + if (core_if->multiproc_int_enable) {
  89173. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  89174. + doepeachintmsk[epnum], intr_mask.d32, 0);
  89175. + } else {
  89176. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  89177. + intr_mask.d32, 0);
  89178. + }
  89179. +
  89180. + return 1;
  89181. +}
  89182. +
  89183. +/**
  89184. + * Handler for the OUT EP NAK interrupt.
  89185. + */
  89186. +static inline int32_t handle_out_ep_nak_intr(dwc_otg_pcd_t * pcd,
  89187. + const uint32_t epnum)
  89188. +{
  89189. + /** @todo implement ISR */
  89190. + dwc_otg_core_if_t *core_if;
  89191. + doepmsk_data_t intr_mask = {.d32 = 0 };
  89192. +
  89193. + DWC_DEBUGPL(DBG_ANY, "INTERRUPT Handler not implemented for %s\n", "OUT EP NAK");
  89194. + core_if = GET_CORE_IF(pcd);
  89195. + intr_mask.b.nak = 1;
  89196. +
  89197. + if (core_if->multiproc_int_enable) {
  89198. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  89199. + doepeachintmsk[epnum], intr_mask.d32, 0);
  89200. + } else {
  89201. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  89202. + intr_mask.d32, 0);
  89203. + }
  89204. +
  89205. + return 1;
  89206. +}
  89207. +
  89208. +/**
  89209. + * Handler for the OUT EP NYET interrupt.
  89210. + */
  89211. +static inline int32_t handle_out_ep_nyet_intr(dwc_otg_pcd_t * pcd,
  89212. + const uint32_t epnum)
  89213. +{
  89214. + /** @todo implement ISR */
  89215. + dwc_otg_core_if_t *core_if;
  89216. + doepmsk_data_t intr_mask = {.d32 = 0 };
  89217. +
  89218. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "OUT EP NYET");
  89219. + core_if = GET_CORE_IF(pcd);
  89220. + intr_mask.b.nyet = 1;
  89221. +
  89222. + if (core_if->multiproc_int_enable) {
  89223. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  89224. + doepeachintmsk[epnum], intr_mask.d32, 0);
  89225. + } else {
  89226. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  89227. + intr_mask.d32, 0);
  89228. + }
  89229. +
  89230. + return 1;
  89231. +}
  89232. +
  89233. +/**
  89234. + * This interrupt indicates that an IN EP has a pending Interrupt.
  89235. + * The sequence for handling the IN EP interrupt is shown below:
  89236. + * -# Read the Device All Endpoint Interrupt register
  89237. + * -# Repeat the following for each IN EP interrupt bit set (from
  89238. + * LSB to MSB).
  89239. + * -# Read the Device Endpoint Interrupt (DIEPINTn) register
  89240. + * -# If "Transfer Complete" call the request complete function
  89241. + * -# If "Endpoint Disabled" complete the EP disable procedure.
  89242. + * -# If "AHB Error Interrupt" log error
  89243. + * -# If "Time-out Handshake" log error
  89244. + * -# If "IN Token Received when TxFIFO Empty" write packet to Tx
  89245. + * FIFO.
  89246. + * -# If "IN Token EP Mismatch" (disable, this is handled by EP
  89247. + * Mismatch Interrupt)
  89248. + */
  89249. +static int32_t dwc_otg_pcd_handle_in_ep_intr(dwc_otg_pcd_t * pcd)
  89250. +{
  89251. +#define CLEAR_IN_EP_INTR(__core_if,__epnum,__intr) \
  89252. +do { \
  89253. + diepint_data_t diepint = {.d32=0}; \
  89254. + diepint.b.__intr = 1; \
  89255. + DWC_WRITE_REG32(&__core_if->dev_if->in_ep_regs[__epnum]->diepint, \
  89256. + diepint.d32); \
  89257. +} while (0)
  89258. +
  89259. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  89260. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  89261. + diepint_data_t diepint = {.d32 = 0 };
  89262. + depctl_data_t depctl = {.d32 = 0 };
  89263. + uint32_t ep_intr;
  89264. + uint32_t epnum = 0;
  89265. + dwc_otg_pcd_ep_t *ep;
  89266. + dwc_ep_t *dwc_ep;
  89267. + gintmsk_data_t intr_mask = {.d32 = 0 };
  89268. +
  89269. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, pcd);
  89270. +
  89271. + /* Read in the device interrupt bits */
  89272. + ep_intr = dwc_otg_read_dev_all_in_ep_intr(core_if);
  89273. +
  89274. + /* Service the Device IN interrupts for each endpoint */
  89275. + while (ep_intr) {
  89276. + if (ep_intr & 0x1) {
  89277. + uint32_t empty_msk;
  89278. + /* Get EP pointer */
  89279. + ep = get_in_ep(pcd, epnum);
  89280. + dwc_ep = &ep->dwc_ep;
  89281. +
  89282. + depctl.d32 =
  89283. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl);
  89284. + empty_msk =
  89285. + DWC_READ_REG32(&dev_if->
  89286. + dev_global_regs->dtknqr4_fifoemptymsk);
  89287. +
  89288. + DWC_DEBUGPL(DBG_PCDV,
  89289. + "IN EP INTERRUPT - %d\nepmty_msk - %8x diepctl - %8x\n",
  89290. + epnum, empty_msk, depctl.d32);
  89291. +
  89292. + DWC_DEBUGPL(DBG_PCD,
  89293. + "EP%d-%s: type=%d, mps=%d\n",
  89294. + dwc_ep->num, (dwc_ep->is_in ? "IN" : "OUT"),
  89295. + dwc_ep->type, dwc_ep->maxpacket);
  89296. +
  89297. + diepint.d32 =
  89298. + dwc_otg_read_dev_in_ep_intr(core_if, dwc_ep);
  89299. +
  89300. + DWC_DEBUGPL(DBG_PCDV,
  89301. + "EP %d Interrupt Register - 0x%x\n", epnum,
  89302. + diepint.d32);
  89303. + /* Transfer complete */
  89304. + if (diepint.b.xfercompl) {
  89305. + /* Disable the NP Tx FIFO Empty
  89306. + * Interrupt */
  89307. + if (core_if->en_multiple_tx_fifo == 0) {
  89308. + intr_mask.b.nptxfempty = 1;
  89309. + DWC_MODIFY_REG32
  89310. + (&core_if->core_global_regs->gintmsk,
  89311. + intr_mask.d32, 0);
  89312. + } else {
  89313. + /* Disable the Tx FIFO Empty Interrupt for this EP */
  89314. + uint32_t fifoemptymsk =
  89315. + 0x1 << dwc_ep->num;
  89316. + DWC_MODIFY_REG32(&core_if->
  89317. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  89318. + fifoemptymsk, 0);
  89319. + }
  89320. + /* Clear the bit in DIEPINTn for this interrupt */
  89321. + CLEAR_IN_EP_INTR(core_if, epnum, xfercompl);
  89322. +
  89323. + /* Complete the transfer */
  89324. + if (epnum == 0) {
  89325. + handle_ep0(pcd);
  89326. + }
  89327. +#ifdef DWC_EN_ISOC
  89328. + else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  89329. + if (!ep->stopped)
  89330. + complete_iso_ep(pcd, ep);
  89331. + }
  89332. +#endif /* DWC_EN_ISOC */
  89333. +#ifdef DWC_UTE_PER_IO
  89334. + else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  89335. + if (!ep->stopped)
  89336. + complete_xiso_ep(ep);
  89337. + }
  89338. +#endif /* DWC_UTE_PER_IO */
  89339. + else {
  89340. + if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC &&
  89341. + dwc_ep->bInterval > 1) {
  89342. + dwc_ep->frame_num += dwc_ep->bInterval;
  89343. + if (dwc_ep->frame_num > 0x3FFF)
  89344. + {
  89345. + dwc_ep->frm_overrun = 1;
  89346. + dwc_ep->frame_num &= 0x3FFF;
  89347. + } else
  89348. + dwc_ep->frm_overrun = 0;
  89349. + }
  89350. + complete_ep(ep);
  89351. + if(diepint.b.nak)
  89352. + CLEAR_IN_EP_INTR(core_if, epnum, nak);
  89353. + }
  89354. + }
  89355. + /* Endpoint disable */
  89356. + if (diepint.b.epdisabled) {
  89357. + DWC_DEBUGPL(DBG_ANY, "EP%d IN disabled\n",
  89358. + epnum);
  89359. + handle_in_ep_disable_intr(pcd, epnum);
  89360. +
  89361. + /* Clear the bit in DIEPINTn for this interrupt */
  89362. + CLEAR_IN_EP_INTR(core_if, epnum, epdisabled);
  89363. + }
  89364. + /* AHB Error */
  89365. + if (diepint.b.ahberr) {
  89366. + DWC_ERROR("EP%d IN AHB Error\n", epnum);
  89367. + /* Clear the bit in DIEPINTn for this interrupt */
  89368. + CLEAR_IN_EP_INTR(core_if, epnum, ahberr);
  89369. + }
  89370. + /* TimeOUT Handshake (non-ISOC IN EPs) */
  89371. + if (diepint.b.timeout) {
  89372. + DWC_ERROR("EP%d IN Time-out\n", epnum);
  89373. + handle_in_ep_timeout_intr(pcd, epnum);
  89374. +
  89375. + CLEAR_IN_EP_INTR(core_if, epnum, timeout);
  89376. + }
  89377. + /** IN Token received with TxF Empty */
  89378. + if (diepint.b.intktxfemp) {
  89379. + DWC_DEBUGPL(DBG_ANY,
  89380. + "EP%d IN TKN TxFifo Empty\n",
  89381. + epnum);
  89382. + if (!ep->stopped && epnum != 0) {
  89383. +
  89384. + diepmsk_data_t diepmsk = {.d32 = 0 };
  89385. + diepmsk.b.intktxfemp = 1;
  89386. +
  89387. + if (core_if->multiproc_int_enable) {
  89388. + DWC_MODIFY_REG32
  89389. + (&dev_if->dev_global_regs->diepeachintmsk
  89390. + [epnum], diepmsk.d32, 0);
  89391. + } else {
  89392. + DWC_MODIFY_REG32
  89393. + (&dev_if->dev_global_regs->diepmsk,
  89394. + diepmsk.d32, 0);
  89395. + }
  89396. + } else if (core_if->dma_desc_enable
  89397. + && epnum == 0
  89398. + && pcd->ep0state ==
  89399. + EP0_OUT_STATUS_PHASE) {
  89400. + // EP0 IN set STALL
  89401. + depctl.d32 =
  89402. + DWC_READ_REG32(&dev_if->in_ep_regs
  89403. + [epnum]->diepctl);
  89404. +
  89405. + /* set the disable and stall bits */
  89406. + if (depctl.b.epena) {
  89407. + depctl.b.epdis = 1;
  89408. + }
  89409. + depctl.b.stall = 1;
  89410. + DWC_WRITE_REG32(&dev_if->in_ep_regs
  89411. + [epnum]->diepctl,
  89412. + depctl.d32);
  89413. + }
  89414. + CLEAR_IN_EP_INTR(core_if, epnum, intktxfemp);
  89415. + }
  89416. + /** IN Token Received with EP mismatch */
  89417. + if (diepint.b.intknepmis) {
  89418. + DWC_DEBUGPL(DBG_ANY,
  89419. + "EP%d IN TKN EP Mismatch\n", epnum);
  89420. + CLEAR_IN_EP_INTR(core_if, epnum, intknepmis);
  89421. + }
  89422. + /** IN Endpoint NAK Effective */
  89423. + if (diepint.b.inepnakeff) {
  89424. + DWC_DEBUGPL(DBG_ANY,
  89425. + "EP%d IN EP NAK Effective\n",
  89426. + epnum);
  89427. + /* Periodic EP */
  89428. + if (ep->disabling) {
  89429. + depctl.d32 = 0;
  89430. + depctl.b.snak = 1;
  89431. + depctl.b.epdis = 1;
  89432. + DWC_MODIFY_REG32(&dev_if->in_ep_regs
  89433. + [epnum]->diepctl,
  89434. + depctl.d32,
  89435. + depctl.d32);
  89436. + }
  89437. + CLEAR_IN_EP_INTR(core_if, epnum, inepnakeff);
  89438. +
  89439. + }
  89440. +
  89441. + /** IN EP Tx FIFO Empty Intr */
  89442. + if (diepint.b.emptyintr) {
  89443. + DWC_DEBUGPL(DBG_ANY,
  89444. + "EP%d Tx FIFO Empty Intr \n",
  89445. + epnum);
  89446. + write_empty_tx_fifo(pcd, epnum);
  89447. +
  89448. + CLEAR_IN_EP_INTR(core_if, epnum, emptyintr);
  89449. +
  89450. + }
  89451. +
  89452. + /** IN EP BNA Intr */
  89453. + if (diepint.b.bna) {
  89454. + CLEAR_IN_EP_INTR(core_if, epnum, bna);
  89455. + if (core_if->dma_desc_enable) {
  89456. +#ifdef DWC_EN_ISOC
  89457. + if (dwc_ep->type ==
  89458. + DWC_OTG_EP_TYPE_ISOC) {
  89459. + /*
  89460. + * This checking is performed to prevent first "false" BNA
  89461. + * handling occuring right after reconnect
  89462. + */
  89463. + if (dwc_ep->next_frame !=
  89464. + 0xffffffff)
  89465. + dwc_otg_pcd_handle_iso_bna(ep);
  89466. + } else
  89467. +#endif /* DWC_EN_ISOC */
  89468. + {
  89469. + dwc_otg_pcd_handle_noniso_bna(ep);
  89470. + }
  89471. + }
  89472. + }
  89473. + /* NAK Interrutp */
  89474. + if (diepint.b.nak) {
  89475. + DWC_DEBUGPL(DBG_ANY, "EP%d IN NAK Interrupt\n",
  89476. + epnum);
  89477. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  89478. + depctl_data_t depctl;
  89479. + if (ep->dwc_ep.frame_num == 0xFFFFFFFF) {
  89480. + ep->dwc_ep.frame_num = core_if->frame_num;
  89481. + if (ep->dwc_ep.bInterval > 1) {
  89482. + depctl.d32 = 0;
  89483. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl);
  89484. + if (ep->dwc_ep.frame_num & 0x1) {
  89485. + depctl.b.setd1pid = 1;
  89486. + depctl.b.setd0pid = 0;
  89487. + } else {
  89488. + depctl.b.setd0pid = 1;
  89489. + depctl.b.setd1pid = 0;
  89490. + }
  89491. + DWC_WRITE_REG32(&dev_if->in_ep_regs[epnum]->diepctl, depctl.d32);
  89492. + }
  89493. + start_next_request(ep);
  89494. + }
  89495. + ep->dwc_ep.frame_num += ep->dwc_ep.bInterval;
  89496. + if (dwc_ep->frame_num > 0x3FFF) {
  89497. + dwc_ep->frm_overrun = 1;
  89498. + dwc_ep->frame_num &= 0x3FFF;
  89499. + } else
  89500. + dwc_ep->frm_overrun = 0;
  89501. + }
  89502. +
  89503. + CLEAR_IN_EP_INTR(core_if, epnum, nak);
  89504. + }
  89505. + }
  89506. + epnum++;
  89507. + ep_intr >>= 1;
  89508. + }
  89509. +
  89510. + return 1;
  89511. +#undef CLEAR_IN_EP_INTR
  89512. +}
  89513. +
  89514. +/**
  89515. + * This interrupt indicates that an OUT EP has a pending Interrupt.
  89516. + * The sequence for handling the OUT EP interrupt is shown below:
  89517. + * -# Read the Device All Endpoint Interrupt register
  89518. + * -# Repeat the following for each OUT EP interrupt bit set (from
  89519. + * LSB to MSB).
  89520. + * -# Read the Device Endpoint Interrupt (DOEPINTn) register
  89521. + * -# If "Transfer Complete" call the request complete function
  89522. + * -# If "Endpoint Disabled" complete the EP disable procedure.
  89523. + * -# If "AHB Error Interrupt" log error
  89524. + * -# If "Setup Phase Done" process Setup Packet (See Standard USB
  89525. + * Command Processing)
  89526. + */
  89527. +static int32_t dwc_otg_pcd_handle_out_ep_intr(dwc_otg_pcd_t * pcd)
  89528. +{
  89529. +#define CLEAR_OUT_EP_INTR(__core_if,__epnum,__intr) \
  89530. +do { \
  89531. + doepint_data_t doepint = {.d32=0}; \
  89532. + doepint.b.__intr = 1; \
  89533. + DWC_WRITE_REG32(&__core_if->dev_if->out_ep_regs[__epnum]->doepint, \
  89534. + doepint.d32); \
  89535. +} while (0)
  89536. +
  89537. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  89538. + uint32_t ep_intr;
  89539. + doepint_data_t doepint = {.d32 = 0 };
  89540. + uint32_t epnum = 0;
  89541. + dwc_otg_pcd_ep_t *ep;
  89542. + dwc_ep_t *dwc_ep;
  89543. + dctl_data_t dctl = {.d32 = 0 };
  89544. + gintmsk_data_t gintmsk = {.d32 = 0 };
  89545. +
  89546. +
  89547. + DWC_DEBUGPL(DBG_PCDV, "%s()\n", __func__);
  89548. +
  89549. + /* Read in the device interrupt bits */
  89550. + ep_intr = dwc_otg_read_dev_all_out_ep_intr(core_if);
  89551. +
  89552. + while (ep_intr) {
  89553. + if (ep_intr & 0x1) {
  89554. + /* Get EP pointer */
  89555. + ep = get_out_ep(pcd, epnum);
  89556. + dwc_ep = &ep->dwc_ep;
  89557. +
  89558. +#ifdef VERBOSE
  89559. + DWC_DEBUGPL(DBG_PCDV,
  89560. + "EP%d-%s: type=%d, mps=%d\n",
  89561. + dwc_ep->num, (dwc_ep->is_in ? "IN" : "OUT"),
  89562. + dwc_ep->type, dwc_ep->maxpacket);
  89563. +#endif
  89564. + doepint.d32 =
  89565. + dwc_otg_read_dev_out_ep_intr(core_if, dwc_ep);
  89566. + /* Moved this interrupt upper due to core deffect of asserting
  89567. + * OUT EP 0 xfercompl along with stsphsrcvd in BDMA */
  89568. + if (doepint.b.stsphsercvd) {
  89569. + deptsiz0_data_t deptsiz;
  89570. + CLEAR_OUT_EP_INTR(core_if, epnum, stsphsercvd);
  89571. + deptsiz.d32 =
  89572. + DWC_READ_REG32(&core_if->dev_if->
  89573. + out_ep_regs[0]->doeptsiz);
  89574. + if (core_if->snpsid >= OTG_CORE_REV_3_00a
  89575. + && core_if->dma_enable
  89576. + && core_if->dma_desc_enable == 0
  89577. + && doepint.b.xfercompl
  89578. + && deptsiz.b.xfersize == 24) {
  89579. + CLEAR_OUT_EP_INTR(core_if, epnum,
  89580. + xfercompl);
  89581. + doepint.b.xfercompl = 0;
  89582. + ep0_out_start(core_if, pcd);
  89583. + }
  89584. + if ((core_if->dma_desc_enable) ||
  89585. + (core_if->dma_enable
  89586. + && core_if->snpsid >=
  89587. + OTG_CORE_REV_3_00a)) {
  89588. + do_setup_in_status_phase(pcd);
  89589. + }
  89590. + }
  89591. + /* Transfer complete */
  89592. + if (doepint.b.xfercompl) {
  89593. +
  89594. + if (epnum == 0) {
  89595. + /* Clear the bit in DOEPINTn for this interrupt */
  89596. + CLEAR_OUT_EP_INTR(core_if, epnum, xfercompl);
  89597. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  89598. + DWC_DEBUGPL(DBG_PCDV, "DOEPINT=%x doepint=%x\n",
  89599. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[0]->doepint),
  89600. + doepint.d32);
  89601. + DWC_DEBUGPL(DBG_PCDV, "DOEPCTL=%x \n",
  89602. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[0]->doepctl));
  89603. +
  89604. + if (core_if->snpsid >= OTG_CORE_REV_3_00a
  89605. + && core_if->dma_enable == 0) {
  89606. + doepint_data_t doepint;
  89607. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  89608. + out_ep_regs[0]->doepint);
  89609. + if (pcd->ep0state == EP0_IDLE && doepint.b.sr) {
  89610. + CLEAR_OUT_EP_INTR(core_if, epnum, sr);
  89611. + goto exit_xfercompl;
  89612. + }
  89613. + }
  89614. + /* In case of DDMA look at SR bit to go to the Data Stage */
  89615. + if (core_if->dma_desc_enable) {
  89616. + dev_dma_desc_sts_t status = {.d32 = 0};
  89617. + if (pcd->ep0state == EP0_IDLE) {
  89618. + status.d32 = core_if->dev_if->setup_desc_addr[core_if->
  89619. + dev_if->setup_desc_index]->status.d32;
  89620. + if(pcd->data_terminated) {
  89621. + pcd->data_terminated = 0;
  89622. + status.d32 = core_if->dev_if->out_desc_addr->status.d32;
  89623. + dwc_memcpy(&pcd->setup_pkt->req, pcd->backup_buf, 8);
  89624. + }
  89625. + if (status.b.sr) {
  89626. + if (doepint.b.setup) {
  89627. + DWC_DEBUGPL(DBG_PCDV, "DMA DESC EP0_IDLE SR=1 setup=1\n");
  89628. + /* Already started data stage, clear setup */
  89629. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  89630. + doepint.b.setup = 0;
  89631. + handle_ep0(pcd);
  89632. + /* Prepare for more setup packets */
  89633. + if (pcd->ep0state == EP0_IN_STATUS_PHASE ||
  89634. + pcd->ep0state == EP0_IN_DATA_PHASE) {
  89635. + ep0_out_start(core_if, pcd);
  89636. + }
  89637. +
  89638. + goto exit_xfercompl;
  89639. + } else {
  89640. + /* Prepare for more setup packets */
  89641. + DWC_DEBUGPL(DBG_PCDV,
  89642. + "EP0_IDLE SR=1 setup=0 new setup comes\n");
  89643. + ep0_out_start(core_if, pcd);
  89644. + }
  89645. + }
  89646. + } else {
  89647. + dwc_otg_pcd_request_t *req;
  89648. + dev_dma_desc_sts_t status = {.d32 = 0};
  89649. + diepint_data_t diepint0;
  89650. + diepint0.d32 = DWC_READ_REG32(&core_if->dev_if->
  89651. + in_ep_regs[0]->diepint);
  89652. +
  89653. + if (pcd->ep0state == EP0_STALL || pcd->ep0state == EP0_DISCONNECT) {
  89654. + DWC_ERROR("EP0 is stalled/disconnected\n");
  89655. + }
  89656. +
  89657. + /* Clear IN xfercompl if set */
  89658. + if (diepint0.b.xfercompl && (pcd->ep0state == EP0_IN_STATUS_PHASE
  89659. + || pcd->ep0state == EP0_IN_DATA_PHASE)) {
  89660. + DWC_WRITE_REG32(&core_if->dev_if->
  89661. + in_ep_regs[0]->diepint, diepint0.d32);
  89662. + }
  89663. +
  89664. + status.d32 = core_if->dev_if->setup_desc_addr[core_if->
  89665. + dev_if->setup_desc_index]->status.d32;
  89666. +
  89667. + if (ep->dwc_ep.xfer_count != ep->dwc_ep.total_len
  89668. + && (pcd->ep0state == EP0_OUT_DATA_PHASE))
  89669. + status.d32 = core_if->dev_if->out_desc_addr->status.d32;
  89670. + if (pcd->ep0state == EP0_OUT_STATUS_PHASE)
  89671. + status.d32 = core_if->dev_if->
  89672. + out_desc_addr->status.d32;
  89673. +
  89674. + if (status.b.sr) {
  89675. + if (DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  89676. + DWC_DEBUGPL(DBG_PCDV, "Request queue empty!!\n");
  89677. + } else {
  89678. + DWC_DEBUGPL(DBG_PCDV, "complete req!!\n");
  89679. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  89680. + if (ep->dwc_ep.xfer_count != ep->dwc_ep.total_len &&
  89681. + pcd->ep0state == EP0_OUT_DATA_PHASE) {
  89682. + /* Read arrived setup packet from req->buf */
  89683. + dwc_memcpy(&pcd->setup_pkt->req,
  89684. + req->buf + ep->dwc_ep.xfer_count, 8);
  89685. + }
  89686. + req->actual = ep->dwc_ep.xfer_count;
  89687. + dwc_otg_request_done(ep, req, -ECONNRESET);
  89688. + ep->dwc_ep.start_xfer_buff = 0;
  89689. + ep->dwc_ep.xfer_buff = 0;
  89690. + ep->dwc_ep.xfer_len = 0;
  89691. + }
  89692. + pcd->ep0state = EP0_IDLE;
  89693. + if (doepint.b.setup) {
  89694. + DWC_DEBUGPL(DBG_PCDV, "EP0_IDLE SR=1 setup=1\n");
  89695. + /* Data stage started, clear setup */
  89696. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  89697. + doepint.b.setup = 0;
  89698. + handle_ep0(pcd);
  89699. + /* Prepare for setup packets if ep0in was enabled*/
  89700. + if (pcd->ep0state == EP0_IN_STATUS_PHASE) {
  89701. + ep0_out_start(core_if, pcd);
  89702. + }
  89703. +
  89704. + goto exit_xfercompl;
  89705. + } else {
  89706. + /* Prepare for more setup packets */
  89707. + DWC_DEBUGPL(DBG_PCDV,
  89708. + "EP0_IDLE SR=1 setup=0 new setup comes 2\n");
  89709. + ep0_out_start(core_if, pcd);
  89710. + }
  89711. + }
  89712. + }
  89713. + }
  89714. + if (core_if->snpsid >= OTG_CORE_REV_2_94a && core_if->dma_enable
  89715. + && core_if->dma_desc_enable == 0) {
  89716. + doepint_data_t doepint_temp = {.d32 = 0};
  89717. + deptsiz0_data_t doeptsize0 = {.d32 = 0 };
  89718. + doepint_temp.d32 = DWC_READ_REG32(&core_if->dev_if->
  89719. + out_ep_regs[ep->dwc_ep.num]->doepint);
  89720. + doeptsize0.d32 = DWC_READ_REG32(&core_if->dev_if->
  89721. + out_ep_regs[ep->dwc_ep.num]->doeptsiz);
  89722. + if (pcd->ep0state == EP0_IDLE) {
  89723. + if (doepint_temp.b.sr) {
  89724. + CLEAR_OUT_EP_INTR(core_if, epnum, sr);
  89725. + }
  89726. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  89727. + out_ep_regs[0]->doepint);
  89728. + if (doeptsize0.b.supcnt == 3) {
  89729. + DWC_DEBUGPL(DBG_ANY, "Rolling over!!!!!!!\n");
  89730. + ep->dwc_ep.stp_rollover = 1;
  89731. + }
  89732. + if (doepint.b.setup) {
  89733. +retry:
  89734. + /* Already started data stage, clear setup */
  89735. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  89736. + doepint.b.setup = 0;
  89737. + handle_ep0(pcd);
  89738. + ep->dwc_ep.stp_rollover = 0;
  89739. + /* Prepare for more setup packets */
  89740. + if (pcd->ep0state == EP0_IN_STATUS_PHASE ||
  89741. + pcd->ep0state == EP0_IN_DATA_PHASE) {
  89742. + ep0_out_start(core_if, pcd);
  89743. + }
  89744. + goto exit_xfercompl;
  89745. + } else {
  89746. + /* Prepare for more setup packets */
  89747. + DWC_DEBUGPL(DBG_ANY,
  89748. + "EP0_IDLE SR=1 setup=0 new setup comes\n");
  89749. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  89750. + out_ep_regs[0]->doepint);
  89751. + if(doepint.b.setup)
  89752. + goto retry;
  89753. + ep0_out_start(core_if, pcd);
  89754. + }
  89755. + } else {
  89756. + dwc_otg_pcd_request_t *req;
  89757. + diepint_data_t diepint0 = {.d32 = 0};
  89758. + doepint_data_t doepint_temp = {.d32 = 0};
  89759. + depctl_data_t diepctl0;
  89760. + diepint0.d32 = DWC_READ_REG32(&core_if->dev_if->
  89761. + in_ep_regs[0]->diepint);
  89762. + diepctl0.d32 = DWC_READ_REG32(&core_if->dev_if->
  89763. + in_ep_regs[0]->diepctl);
  89764. +
  89765. + if (pcd->ep0state == EP0_IN_DATA_PHASE
  89766. + || pcd->ep0state == EP0_IN_STATUS_PHASE) {
  89767. + if (diepint0.b.xfercompl) {
  89768. + DWC_WRITE_REG32(&core_if->dev_if->
  89769. + in_ep_regs[0]->diepint, diepint0.d32);
  89770. + }
  89771. + if (diepctl0.b.epena) {
  89772. + diepint_data_t diepint = {.d32 = 0};
  89773. + diepctl0.b.snak = 1;
  89774. + DWC_WRITE_REG32(&core_if->dev_if->
  89775. + in_ep_regs[0]->diepctl, diepctl0.d32);
  89776. + do {
  89777. + dwc_udelay(10);
  89778. + diepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  89779. + in_ep_regs[0]->diepint);
  89780. + } while (!diepint.b.inepnakeff);
  89781. + diepint.b.inepnakeff = 1;
  89782. + DWC_WRITE_REG32(&core_if->dev_if->
  89783. + in_ep_regs[0]->diepint, diepint.d32);
  89784. + diepctl0.d32 = 0;
  89785. + diepctl0.b.epdis = 1;
  89786. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[0]->diepctl,
  89787. + diepctl0.d32);
  89788. + do {
  89789. + dwc_udelay(10);
  89790. + diepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  89791. + in_ep_regs[0]->diepint);
  89792. + } while (!diepint.b.epdisabled);
  89793. + diepint.b.epdisabled = 1;
  89794. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[0]->diepint,
  89795. + diepint.d32);
  89796. + }
  89797. + }
  89798. + doepint_temp.d32 = DWC_READ_REG32(&core_if->dev_if->
  89799. + out_ep_regs[ep->dwc_ep.num]->doepint);
  89800. + if (doepint_temp.b.sr) {
  89801. + CLEAR_OUT_EP_INTR(core_if, epnum, sr);
  89802. + if (DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  89803. + DWC_DEBUGPL(DBG_PCDV, "Request queue empty!!\n");
  89804. + } else {
  89805. + DWC_DEBUGPL(DBG_PCDV, "complete req!!\n");
  89806. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  89807. + if (ep->dwc_ep.xfer_count != ep->dwc_ep.total_len &&
  89808. + pcd->ep0state == EP0_OUT_DATA_PHASE) {
  89809. + /* Read arrived setup packet from req->buf */
  89810. + dwc_memcpy(&pcd->setup_pkt->req,
  89811. + req->buf + ep->dwc_ep.xfer_count, 8);
  89812. + }
  89813. + req->actual = ep->dwc_ep.xfer_count;
  89814. + dwc_otg_request_done(ep, req, -ECONNRESET);
  89815. + ep->dwc_ep.start_xfer_buff = 0;
  89816. + ep->dwc_ep.xfer_buff = 0;
  89817. + ep->dwc_ep.xfer_len = 0;
  89818. + }
  89819. + pcd->ep0state = EP0_IDLE;
  89820. + if (doepint.b.setup) {
  89821. + DWC_DEBUGPL(DBG_PCDV, "EP0_IDLE SR=1 setup=1\n");
  89822. + /* Data stage started, clear setup */
  89823. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  89824. + doepint.b.setup = 0;
  89825. + handle_ep0(pcd);
  89826. + /* Prepare for setup packets if ep0in was enabled*/
  89827. + if (pcd->ep0state == EP0_IN_STATUS_PHASE) {
  89828. + ep0_out_start(core_if, pcd);
  89829. + }
  89830. + goto exit_xfercompl;
  89831. + } else {
  89832. + /* Prepare for more setup packets */
  89833. + DWC_DEBUGPL(DBG_PCDV,
  89834. + "EP0_IDLE SR=1 setup=0 new setup comes 2\n");
  89835. + ep0_out_start(core_if, pcd);
  89836. + }
  89837. + }
  89838. + }
  89839. + }
  89840. + if (core_if->dma_enable == 0 || pcd->ep0state != EP0_IDLE)
  89841. + handle_ep0(pcd);
  89842. +exit_xfercompl:
  89843. + DWC_DEBUGPL(DBG_PCDV, "DOEPINT=%x doepint=%x\n",
  89844. + dwc_otg_read_dev_out_ep_intr(core_if, dwc_ep), doepint.d32);
  89845. + } else {
  89846. + if (core_if->dma_desc_enable == 0
  89847. + || pcd->ep0state != EP0_IDLE)
  89848. + handle_ep0(pcd);
  89849. + }
  89850. +#ifdef DWC_EN_ISOC
  89851. + } else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  89852. + if (doepint.b.pktdrpsts == 0) {
  89853. + /* Clear the bit in DOEPINTn for this interrupt */
  89854. + CLEAR_OUT_EP_INTR(core_if,
  89855. + epnum,
  89856. + xfercompl);
  89857. + complete_iso_ep(pcd, ep);
  89858. + } else {
  89859. +
  89860. + doepint_data_t doepint = {.d32 = 0 };
  89861. + doepint.b.xfercompl = 1;
  89862. + doepint.b.pktdrpsts = 1;
  89863. + DWC_WRITE_REG32
  89864. + (&core_if->dev_if->out_ep_regs
  89865. + [epnum]->doepint,
  89866. + doepint.d32);
  89867. + if (handle_iso_out_pkt_dropped
  89868. + (core_if, dwc_ep)) {
  89869. + complete_iso_ep(pcd,
  89870. + ep);
  89871. + }
  89872. + }
  89873. +#endif /* DWC_EN_ISOC */
  89874. +#ifdef DWC_UTE_PER_IO
  89875. + } else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  89876. + CLEAR_OUT_EP_INTR(core_if, epnum, xfercompl);
  89877. + if (!ep->stopped)
  89878. + complete_xiso_ep(ep);
  89879. +#endif /* DWC_UTE_PER_IO */
  89880. + } else {
  89881. + /* Clear the bit in DOEPINTn for this interrupt */
  89882. + CLEAR_OUT_EP_INTR(core_if, epnum,
  89883. + xfercompl);
  89884. +
  89885. + if (core_if->core_params->dev_out_nak) {
  89886. + DWC_TIMER_CANCEL(pcd->core_if->ep_xfer_timer[epnum]);
  89887. + pcd->core_if->ep_xfer_info[epnum].state = 0;
  89888. +#ifdef DEBUG
  89889. + print_memory_payload(pcd, dwc_ep);
  89890. +#endif
  89891. + }
  89892. + complete_ep(ep);
  89893. + }
  89894. +
  89895. + }
  89896. +
  89897. + /* Endpoint disable */
  89898. + if (doepint.b.epdisabled) {
  89899. +
  89900. + /* Clear the bit in DOEPINTn for this interrupt */
  89901. + CLEAR_OUT_EP_INTR(core_if, epnum, epdisabled);
  89902. + if (core_if->core_params->dev_out_nak) {
  89903. +#ifdef DEBUG
  89904. + print_memory_payload(pcd, dwc_ep);
  89905. +#endif
  89906. + /* In case of timeout condition */
  89907. + if (core_if->ep_xfer_info[epnum].state == 2) {
  89908. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->
  89909. + dev_global_regs->dctl);
  89910. + dctl.b.cgoutnak = 1;
  89911. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl,
  89912. + dctl.d32);
  89913. + /* Unmask goutnakeff interrupt which was masked
  89914. + * during handle nak out interrupt */
  89915. + gintmsk.b.goutnakeff = 1;
  89916. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  89917. + 0, gintmsk.d32);
  89918. +
  89919. + complete_ep(ep);
  89920. + }
  89921. + }
  89922. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC)
  89923. + {
  89924. + dctl_data_t dctl;
  89925. + gintmsk_data_t intr_mask = {.d32 = 0};
  89926. + dwc_otg_pcd_request_t *req = 0;
  89927. +
  89928. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->
  89929. + dev_global_regs->dctl);
  89930. + dctl.b.cgoutnak = 1;
  89931. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl,
  89932. + dctl.d32);
  89933. +
  89934. + intr_mask.d32 = 0;
  89935. + intr_mask.b.incomplisoout = 1;
  89936. +
  89937. + /* Get any pending requests */
  89938. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  89939. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  89940. + if (!req) {
  89941. + DWC_PRINTF("complete_ep 0x%p, req = NULL!\n", ep);
  89942. + } else {
  89943. + dwc_otg_request_done(ep, req, 0);
  89944. + start_next_request(ep);
  89945. + }
  89946. + } else {
  89947. + DWC_PRINTF("complete_ep 0x%p, ep->queue empty!\n", ep);
  89948. + }
  89949. + }
  89950. + }
  89951. + /* AHB Error */
  89952. + if (doepint.b.ahberr) {
  89953. + DWC_ERROR("EP%d OUT AHB Error\n", epnum);
  89954. + DWC_ERROR("EP%d DEPDMA=0x%08x \n",
  89955. + epnum, core_if->dev_if->out_ep_regs[epnum]->doepdma);
  89956. + CLEAR_OUT_EP_INTR(core_if, epnum, ahberr);
  89957. + }
  89958. + /* Setup Phase Done (contorl EPs) */
  89959. + if (doepint.b.setup) {
  89960. +#ifdef DEBUG_EP0
  89961. + DWC_DEBUGPL(DBG_PCD, "EP%d SETUP Done\n", epnum);
  89962. +#endif
  89963. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  89964. +
  89965. + handle_ep0(pcd);
  89966. + }
  89967. +
  89968. + /** OUT EP BNA Intr */
  89969. + if (doepint.b.bna) {
  89970. + CLEAR_OUT_EP_INTR(core_if, epnum, bna);
  89971. + if (core_if->dma_desc_enable) {
  89972. +#ifdef DWC_EN_ISOC
  89973. + if (dwc_ep->type ==
  89974. + DWC_OTG_EP_TYPE_ISOC) {
  89975. + /*
  89976. + * This checking is performed to prevent first "false" BNA
  89977. + * handling occuring right after reconnect
  89978. + */
  89979. + if (dwc_ep->next_frame !=
  89980. + 0xffffffff)
  89981. + dwc_otg_pcd_handle_iso_bna(ep);
  89982. + } else
  89983. +#endif /* DWC_EN_ISOC */
  89984. + {
  89985. + dwc_otg_pcd_handle_noniso_bna(ep);
  89986. + }
  89987. + }
  89988. + }
  89989. + /* Babble Interrupt */
  89990. + if (doepint.b.babble) {
  89991. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT Babble\n",
  89992. + epnum);
  89993. + handle_out_ep_babble_intr(pcd, epnum);
  89994. +
  89995. + CLEAR_OUT_EP_INTR(core_if, epnum, babble);
  89996. + }
  89997. + if (doepint.b.outtknepdis) {
  89998. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT Token received when EP is \
  89999. + disabled\n",epnum);
  90000. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  90001. + doepmsk_data_t doepmsk = {.d32 = 0};
  90002. + ep->dwc_ep.frame_num = core_if->frame_num;
  90003. + if (ep->dwc_ep.bInterval > 1) {
  90004. + depctl_data_t depctl;
  90005. + depctl.d32 = DWC_READ_REG32(&core_if->dev_if->
  90006. + out_ep_regs[epnum]->doepctl);
  90007. + if (ep->dwc_ep.frame_num & 0x1) {
  90008. + depctl.b.setd1pid = 1;
  90009. + depctl.b.setd0pid = 0;
  90010. + } else {
  90011. + depctl.b.setd0pid = 1;
  90012. + depctl.b.setd1pid = 0;
  90013. + }
  90014. + DWC_WRITE_REG32(&core_if->dev_if->
  90015. + out_ep_regs[epnum]->doepctl, depctl.d32);
  90016. + }
  90017. + start_next_request(ep);
  90018. + doepmsk.b.outtknepdis = 1;
  90019. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  90020. + doepmsk.d32, 0);
  90021. + }
  90022. + CLEAR_OUT_EP_INTR(core_if, epnum, outtknepdis);
  90023. + }
  90024. +
  90025. + /* NAK Interrutp */
  90026. + if (doepint.b.nak) {
  90027. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT NAK\n", epnum);
  90028. + handle_out_ep_nak_intr(pcd, epnum);
  90029. +
  90030. + CLEAR_OUT_EP_INTR(core_if, epnum, nak);
  90031. + }
  90032. + /* NYET Interrutp */
  90033. + if (doepint.b.nyet) {
  90034. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT NYET\n", epnum);
  90035. + handle_out_ep_nyet_intr(pcd, epnum);
  90036. +
  90037. + CLEAR_OUT_EP_INTR(core_if, epnum, nyet);
  90038. + }
  90039. + }
  90040. +
  90041. + epnum++;
  90042. + ep_intr >>= 1;
  90043. + }
  90044. +
  90045. + return 1;
  90046. +
  90047. +#undef CLEAR_OUT_EP_INTR
  90048. +}
  90049. +static int drop_transfer(uint32_t trgt_fr, uint32_t curr_fr, uint8_t frm_overrun)
  90050. +{
  90051. + int retval = 0;
  90052. + if(!frm_overrun && curr_fr >= trgt_fr)
  90053. + retval = 1;
  90054. + else if (frm_overrun
  90055. + && (curr_fr >= trgt_fr && ((curr_fr - trgt_fr) < 0x3FFF / 2)))
  90056. + retval = 1;
  90057. + return retval;
  90058. +}
  90059. +/**
  90060. + * Incomplete ISO IN Transfer Interrupt.
  90061. + * This interrupt indicates one of the following conditions occurred
  90062. + * while transmitting an ISOC transaction.
  90063. + * - Corrupted IN Token for ISOC EP.
  90064. + * - Packet not complete in FIFO.
  90065. + * The follow actions will be taken:
  90066. + * -# Determine the EP
  90067. + * -# Set incomplete flag in dwc_ep structure
  90068. + * -# Disable EP; when "Endpoint Disabled" interrupt is received
  90069. + * Flush FIFO
  90070. + */
  90071. +int32_t dwc_otg_pcd_handle_incomplete_isoc_in_intr(dwc_otg_pcd_t * pcd)
  90072. +{
  90073. + gintsts_data_t gintsts;
  90074. +
  90075. +#ifdef DWC_EN_ISOC
  90076. + dwc_otg_dev_if_t *dev_if;
  90077. + deptsiz_data_t deptsiz = {.d32 = 0 };
  90078. + depctl_data_t depctl = {.d32 = 0 };
  90079. + dsts_data_t dsts = {.d32 = 0 };
  90080. + dwc_ep_t *dwc_ep;
  90081. + int i;
  90082. +
  90083. + dev_if = GET_CORE_IF(pcd)->dev_if;
  90084. +
  90085. + for (i = 1; i <= dev_if->num_in_eps; ++i) {
  90086. + dwc_ep = &pcd->in_ep[i].dwc_ep;
  90087. + if (dwc_ep->active && dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  90088. + deptsiz.d32 =
  90089. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->dieptsiz);
  90090. + depctl.d32 =
  90091. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  90092. +
  90093. + if (depctl.b.epdis && deptsiz.d32) {
  90094. + set_current_pkt_info(GET_CORE_IF(pcd), dwc_ep);
  90095. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  90096. + dwc_ep->cur_pkt = 0;
  90097. + dwc_ep->proc_buf_num =
  90098. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  90099. +
  90100. + if (dwc_ep->proc_buf_num) {
  90101. + dwc_ep->cur_pkt_addr =
  90102. + dwc_ep->xfer_buff1;
  90103. + dwc_ep->cur_pkt_dma_addr =
  90104. + dwc_ep->dma_addr1;
  90105. + } else {
  90106. + dwc_ep->cur_pkt_addr =
  90107. + dwc_ep->xfer_buff0;
  90108. + dwc_ep->cur_pkt_dma_addr =
  90109. + dwc_ep->dma_addr0;
  90110. + }
  90111. +
  90112. + }
  90113. +
  90114. + dsts.d32 =
  90115. + DWC_READ_REG32(&GET_CORE_IF(pcd)->dev_if->
  90116. + dev_global_regs->dsts);
  90117. + dwc_ep->next_frame = dsts.b.soffn;
  90118. +
  90119. + dwc_otg_iso_ep_start_frm_transfer(GET_CORE_IF
  90120. + (pcd),
  90121. + dwc_ep);
  90122. + }
  90123. + }
  90124. + }
  90125. +
  90126. +#else
  90127. + depctl_data_t depctl = {.d32 = 0 };
  90128. + dwc_ep_t *dwc_ep;
  90129. + dwc_otg_dev_if_t *dev_if;
  90130. + int i;
  90131. + dev_if = GET_CORE_IF(pcd)->dev_if;
  90132. +
  90133. + DWC_DEBUGPL(DBG_PCD,"Incomplete ISO IN \n");
  90134. +
  90135. + for (i = 1; i <= dev_if->num_in_eps; ++i) {
  90136. + dwc_ep = &pcd->in_ep[i-1].dwc_ep;
  90137. + depctl.d32 =
  90138. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  90139. + if (depctl.b.epena && dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  90140. + if (drop_transfer(dwc_ep->frame_num, GET_CORE_IF(pcd)->frame_num,
  90141. + dwc_ep->frm_overrun))
  90142. + {
  90143. + depctl.d32 =
  90144. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  90145. + depctl.b.snak = 1;
  90146. + depctl.b.epdis = 1;
  90147. + DWC_MODIFY_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32, depctl.d32);
  90148. + }
  90149. + }
  90150. + }
  90151. +
  90152. + /*intr_mask.b.incomplisoin = 1;
  90153. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  90154. + intr_mask.d32, 0); */
  90155. +#endif //DWC_EN_ISOC
  90156. +
  90157. + /* Clear interrupt */
  90158. + gintsts.d32 = 0;
  90159. + gintsts.b.incomplisoin = 1;
  90160. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  90161. + gintsts.d32);
  90162. +
  90163. + return 1;
  90164. +}
  90165. +
  90166. +/**
  90167. + * Incomplete ISO OUT Transfer Interrupt.
  90168. + *
  90169. + * This interrupt indicates that the core has dropped an ISO OUT
  90170. + * packet. The following conditions can be the cause:
  90171. + * - FIFO Full, the entire packet would not fit in the FIFO.
  90172. + * - CRC Error
  90173. + * - Corrupted Token
  90174. + * The follow actions will be taken:
  90175. + * -# Determine the EP
  90176. + * -# Set incomplete flag in dwc_ep structure
  90177. + * -# Read any data from the FIFO
  90178. + * -# Disable EP. When "Endpoint Disabled" interrupt is received
  90179. + * re-enable EP.
  90180. + */
  90181. +int32_t dwc_otg_pcd_handle_incomplete_isoc_out_intr(dwc_otg_pcd_t * pcd)
  90182. +{
  90183. +
  90184. + gintsts_data_t gintsts;
  90185. +
  90186. +#ifdef DWC_EN_ISOC
  90187. + dwc_otg_dev_if_t *dev_if;
  90188. + deptsiz_data_t deptsiz = {.d32 = 0 };
  90189. + depctl_data_t depctl = {.d32 = 0 };
  90190. + dsts_data_t dsts = {.d32 = 0 };
  90191. + dwc_ep_t *dwc_ep;
  90192. + int i;
  90193. +
  90194. + dev_if = GET_CORE_IF(pcd)->dev_if;
  90195. +
  90196. + for (i = 1; i <= dev_if->num_out_eps; ++i) {
  90197. + dwc_ep = &pcd->in_ep[i].dwc_ep;
  90198. + if (pcd->out_ep[i].dwc_ep.active &&
  90199. + pcd->out_ep[i].dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  90200. + deptsiz.d32 =
  90201. + DWC_READ_REG32(&dev_if->out_ep_regs[i]->doeptsiz);
  90202. + depctl.d32 =
  90203. + DWC_READ_REG32(&dev_if->out_ep_regs[i]->doepctl);
  90204. +
  90205. + if (depctl.b.epdis && deptsiz.d32) {
  90206. + set_current_pkt_info(GET_CORE_IF(pcd),
  90207. + &pcd->out_ep[i].dwc_ep);
  90208. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  90209. + dwc_ep->cur_pkt = 0;
  90210. + dwc_ep->proc_buf_num =
  90211. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  90212. +
  90213. + if (dwc_ep->proc_buf_num) {
  90214. + dwc_ep->cur_pkt_addr =
  90215. + dwc_ep->xfer_buff1;
  90216. + dwc_ep->cur_pkt_dma_addr =
  90217. + dwc_ep->dma_addr1;
  90218. + } else {
  90219. + dwc_ep->cur_pkt_addr =
  90220. + dwc_ep->xfer_buff0;
  90221. + dwc_ep->cur_pkt_dma_addr =
  90222. + dwc_ep->dma_addr0;
  90223. + }
  90224. +
  90225. + }
  90226. +
  90227. + dsts.d32 =
  90228. + DWC_READ_REG32(&GET_CORE_IF(pcd)->dev_if->
  90229. + dev_global_regs->dsts);
  90230. + dwc_ep->next_frame = dsts.b.soffn;
  90231. +
  90232. + dwc_otg_iso_ep_start_frm_transfer(GET_CORE_IF
  90233. + (pcd),
  90234. + dwc_ep);
  90235. + }
  90236. + }
  90237. + }
  90238. +#else
  90239. + /** @todo implement ISR */
  90240. + gintmsk_data_t intr_mask = {.d32 = 0 };
  90241. + dwc_otg_core_if_t *core_if;
  90242. + deptsiz_data_t deptsiz = {.d32 = 0 };
  90243. + depctl_data_t depctl = {.d32 = 0 };
  90244. + dctl_data_t dctl = {.d32 = 0 };
  90245. + dwc_ep_t *dwc_ep = NULL;
  90246. + int i;
  90247. + core_if = GET_CORE_IF(pcd);
  90248. +
  90249. + for (i = 0; i < core_if->dev_if->num_out_eps; ++i) {
  90250. + dwc_ep = &pcd->out_ep[i].dwc_ep;
  90251. + depctl.d32 =
  90252. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl);
  90253. + if (depctl.b.epena && depctl.b.dpid == (core_if->frame_num & 0x1)) {
  90254. + core_if->dev_if->isoc_ep = dwc_ep;
  90255. + deptsiz.d32 =
  90256. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doeptsiz);
  90257. + break;
  90258. + }
  90259. + }
  90260. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  90261. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  90262. + intr_mask.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  90263. +
  90264. + if (!intr_mask.b.goutnakeff) {
  90265. + /* Unmask it */
  90266. + intr_mask.b.goutnakeff = 1;
  90267. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, intr_mask.d32);
  90268. + }
  90269. + if (!gintsts.b.goutnakeff) {
  90270. + dctl.b.sgoutnak = 1;
  90271. + }
  90272. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  90273. +
  90274. + depctl.d32 = DWC_READ_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl);
  90275. + if (depctl.b.epena) {
  90276. + depctl.b.epdis = 1;
  90277. + depctl.b.snak = 1;
  90278. + }
  90279. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl, depctl.d32);
  90280. +
  90281. + intr_mask.d32 = 0;
  90282. + intr_mask.b.incomplisoout = 1;
  90283. +
  90284. +#endif /* DWC_EN_ISOC */
  90285. +
  90286. + /* Clear interrupt */
  90287. + gintsts.d32 = 0;
  90288. + gintsts.b.incomplisoout = 1;
  90289. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  90290. + gintsts.d32);
  90291. +
  90292. + return 1;
  90293. +}
  90294. +
  90295. +/**
  90296. + * This function handles the Global IN NAK Effective interrupt.
  90297. + *
  90298. + */
  90299. +int32_t dwc_otg_pcd_handle_in_nak_effective(dwc_otg_pcd_t * pcd)
  90300. +{
  90301. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  90302. + depctl_data_t diepctl = {.d32 = 0 };
  90303. + gintmsk_data_t intr_mask = {.d32 = 0 };
  90304. + gintsts_data_t gintsts;
  90305. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  90306. + int i;
  90307. +
  90308. + DWC_DEBUGPL(DBG_PCD, "Global IN NAK Effective\n");
  90309. +
  90310. + /* Disable all active IN EPs */
  90311. + for (i = 0; i <= dev_if->num_in_eps; i++) {
  90312. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  90313. + if (!(diepctl.b.eptype & 1) && diepctl.b.epena) {
  90314. + if (core_if->start_predict > 0)
  90315. + core_if->start_predict++;
  90316. + diepctl.b.epdis = 1;
  90317. + diepctl.b.snak = 1;
  90318. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, diepctl.d32);
  90319. + }
  90320. + }
  90321. +
  90322. +
  90323. + /* Disable the Global IN NAK Effective Interrupt */
  90324. + intr_mask.b.ginnakeff = 1;
  90325. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  90326. + intr_mask.d32, 0);
  90327. +
  90328. + /* Clear interrupt */
  90329. + gintsts.d32 = 0;
  90330. + gintsts.b.ginnakeff = 1;
  90331. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  90332. + gintsts.d32);
  90333. +
  90334. + return 1;
  90335. +}
  90336. +
  90337. +/**
  90338. + * OUT NAK Effective.
  90339. + *
  90340. + */
  90341. +int32_t dwc_otg_pcd_handle_out_nak_effective(dwc_otg_pcd_t * pcd)
  90342. +{
  90343. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  90344. + gintmsk_data_t intr_mask = {.d32 = 0 };
  90345. + gintsts_data_t gintsts;
  90346. + depctl_data_t doepctl;
  90347. + int i;
  90348. +
  90349. + /* Disable the Global OUT NAK Effective Interrupt */
  90350. + intr_mask.b.goutnakeff = 1;
  90351. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  90352. + intr_mask.d32, 0);
  90353. +
  90354. + /* If DEV OUT NAK enabled*/
  90355. + if (pcd->core_if->core_params->dev_out_nak) {
  90356. + /* Run over all out endpoints to determine the ep number on
  90357. + * which the timeout has happened
  90358. + */
  90359. + for (i = 0; i <= dev_if->num_out_eps; i++) {
  90360. + if ( pcd->core_if->ep_xfer_info[i].state == 2 )
  90361. + break;
  90362. + }
  90363. + if (i > dev_if->num_out_eps) {
  90364. + dctl_data_t dctl;
  90365. + dctl.d32 =
  90366. + DWC_READ_REG32(&dev_if->dev_global_regs->dctl);
  90367. + dctl.b.cgoutnak = 1;
  90368. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dctl,
  90369. + dctl.d32);
  90370. + goto out;
  90371. + }
  90372. +
  90373. + /* Disable the endpoint */
  90374. + doepctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[i]->doepctl);
  90375. + if (doepctl.b.epena) {
  90376. + doepctl.b.epdis = 1;
  90377. + doepctl.b.snak = 1;
  90378. + }
  90379. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepctl, doepctl.d32);
  90380. + return 1;
  90381. + }
  90382. + /* We come here from Incomplete ISO OUT handler */
  90383. + if (dev_if->isoc_ep) {
  90384. + dwc_ep_t *dwc_ep = (dwc_ep_t *)dev_if->isoc_ep;
  90385. + uint32_t epnum = dwc_ep->num;
  90386. + doepint_data_t doepint;
  90387. + doepint.d32 =
  90388. + DWC_READ_REG32(&dev_if->out_ep_regs[dwc_ep->num]->doepint);
  90389. + dev_if->isoc_ep = NULL;
  90390. + doepctl.d32 =
  90391. + DWC_READ_REG32(&dev_if->out_ep_regs[epnum]->doepctl);
  90392. + DWC_PRINTF("Before disable DOEPCTL = %08x\n", doepctl.d32);
  90393. + if (doepctl.b.epena) {
  90394. + doepctl.b.epdis = 1;
  90395. + doepctl.b.snak = 1;
  90396. + }
  90397. + DWC_WRITE_REG32(&dev_if->out_ep_regs[epnum]->doepctl,
  90398. + doepctl.d32);
  90399. + return 1;
  90400. + } else
  90401. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n",
  90402. + "Global OUT NAK Effective\n");
  90403. +
  90404. +out:
  90405. + /* Clear interrupt */
  90406. + gintsts.d32 = 0;
  90407. + gintsts.b.goutnakeff = 1;
  90408. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  90409. + gintsts.d32);
  90410. +
  90411. + return 1;
  90412. +}
  90413. +
  90414. +/**
  90415. + * PCD interrupt handler.
  90416. + *
  90417. + * The PCD handles the device interrupts. Many conditions can cause a
  90418. + * device interrupt. When an interrupt occurs, the device interrupt
  90419. + * service routine determines the cause of the interrupt and
  90420. + * dispatches handling to the appropriate function. These interrupt
  90421. + * handling functions are described below.
  90422. + *
  90423. + * All interrupt registers are processed from LSB to MSB.
  90424. + *
  90425. + */
  90426. +int32_t dwc_otg_pcd_handle_intr(dwc_otg_pcd_t * pcd)
  90427. +{
  90428. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  90429. +#ifdef VERBOSE
  90430. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  90431. +#endif
  90432. + gintsts_data_t gintr_status;
  90433. + int32_t retval = 0;
  90434. +
  90435. + /* Exit from ISR if core is hibernated */
  90436. + if (core_if->hibernation_suspend == 1) {
  90437. + return retval;
  90438. + }
  90439. +#ifdef VERBOSE
  90440. + DWC_DEBUGPL(DBG_ANY, "%s() gintsts=%08x gintmsk=%08x\n",
  90441. + __func__,
  90442. + DWC_READ_REG32(&global_regs->gintsts),
  90443. + DWC_READ_REG32(&global_regs->gintmsk));
  90444. +#endif
  90445. +
  90446. + if (dwc_otg_is_device_mode(core_if)) {
  90447. + DWC_SPINLOCK(pcd->lock);
  90448. +#ifdef VERBOSE
  90449. + DWC_DEBUGPL(DBG_PCDV, "%s() gintsts=%08x gintmsk=%08x\n",
  90450. + __func__,
  90451. + DWC_READ_REG32(&global_regs->gintsts),
  90452. + DWC_READ_REG32(&global_regs->gintmsk));
  90453. +#endif
  90454. +
  90455. + gintr_status.d32 = dwc_otg_read_core_intr(core_if);
  90456. +
  90457. + DWC_DEBUGPL(DBG_PCDV, "%s: gintsts&gintmsk=%08x\n",
  90458. + __func__, gintr_status.d32);
  90459. +
  90460. + if (gintr_status.b.sofintr) {
  90461. + retval |= dwc_otg_pcd_handle_sof_intr(pcd);
  90462. + }
  90463. + if (gintr_status.b.rxstsqlvl) {
  90464. + retval |=
  90465. + dwc_otg_pcd_handle_rx_status_q_level_intr(pcd);
  90466. + }
  90467. + if (gintr_status.b.nptxfempty) {
  90468. + retval |= dwc_otg_pcd_handle_np_tx_fifo_empty_intr(pcd);
  90469. + }
  90470. + if (gintr_status.b.goutnakeff) {
  90471. + retval |= dwc_otg_pcd_handle_out_nak_effective(pcd);
  90472. + }
  90473. + if (gintr_status.b.i2cintr) {
  90474. + retval |= dwc_otg_pcd_handle_i2c_intr(pcd);
  90475. + }
  90476. + if (gintr_status.b.erlysuspend) {
  90477. + retval |= dwc_otg_pcd_handle_early_suspend_intr(pcd);
  90478. + }
  90479. + if (gintr_status.b.usbreset) {
  90480. + retval |= dwc_otg_pcd_handle_usb_reset_intr(pcd);
  90481. + }
  90482. + if (gintr_status.b.enumdone) {
  90483. + retval |= dwc_otg_pcd_handle_enum_done_intr(pcd);
  90484. + }
  90485. + if (gintr_status.b.isooutdrop) {
  90486. + retval |=
  90487. + dwc_otg_pcd_handle_isoc_out_packet_dropped_intr
  90488. + (pcd);
  90489. + }
  90490. + if (gintr_status.b.eopframe) {
  90491. + retval |=
  90492. + dwc_otg_pcd_handle_end_periodic_frame_intr(pcd);
  90493. + }
  90494. + if (gintr_status.b.inepint) {
  90495. + if (!core_if->multiproc_int_enable) {
  90496. + retval |= dwc_otg_pcd_handle_in_ep_intr(pcd);
  90497. + }
  90498. + }
  90499. + if (gintr_status.b.outepintr) {
  90500. + if (!core_if->multiproc_int_enable) {
  90501. + retval |= dwc_otg_pcd_handle_out_ep_intr(pcd);
  90502. + }
  90503. + }
  90504. + if (gintr_status.b.epmismatch) {
  90505. + retval |= dwc_otg_pcd_handle_ep_mismatch_intr(pcd);
  90506. + }
  90507. + if (gintr_status.b.fetsusp) {
  90508. + retval |= dwc_otg_pcd_handle_ep_fetsusp_intr(pcd);
  90509. + }
  90510. + if (gintr_status.b.ginnakeff) {
  90511. + retval |= dwc_otg_pcd_handle_in_nak_effective(pcd);
  90512. + }
  90513. + if (gintr_status.b.incomplisoin) {
  90514. + retval |=
  90515. + dwc_otg_pcd_handle_incomplete_isoc_in_intr(pcd);
  90516. + }
  90517. + if (gintr_status.b.incomplisoout) {
  90518. + retval |=
  90519. + dwc_otg_pcd_handle_incomplete_isoc_out_intr(pcd);
  90520. + }
  90521. +
  90522. + /* In MPI mode Device Endpoints interrupts are asserted
  90523. + * without setting outepintr and inepint bits set, so these
  90524. + * Interrupt handlers are called without checking these bit-fields
  90525. + */
  90526. + if (core_if->multiproc_int_enable) {
  90527. + retval |= dwc_otg_pcd_handle_in_ep_intr(pcd);
  90528. + retval |= dwc_otg_pcd_handle_out_ep_intr(pcd);
  90529. + }
  90530. +#ifdef VERBOSE
  90531. + DWC_DEBUGPL(DBG_PCDV, "%s() gintsts=%0x\n", __func__,
  90532. + DWC_READ_REG32(&global_regs->gintsts));
  90533. +#endif
  90534. + DWC_SPINUNLOCK(pcd->lock);
  90535. + }
  90536. + return retval;
  90537. +}
  90538. +
  90539. +#endif /* DWC_HOST_ONLY */
  90540. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c
  90541. --- linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c 1970-01-01 01:00:00.000000000 +0100
  90542. +++ linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c 2014-08-06 16:50:14.853965134 +0200
  90543. @@ -0,0 +1,1358 @@
  90544. + /* ==========================================================================
  90545. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd_linux.c $
  90546. + * $Revision: #21 $
  90547. + * $Date: 2012/08/10 $
  90548. + * $Change: 2047372 $
  90549. + *
  90550. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  90551. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  90552. + * otherwise expressly agreed to in writing between Synopsys and you.
  90553. + *
  90554. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  90555. + * any End User Software License Agreement or Agreement for Licensed Product
  90556. + * with Synopsys or any supplement thereto. You are permitted to use and
  90557. + * redistribute this Software in source and binary forms, with or without
  90558. + * modification, provided that redistributions of source code must retain this
  90559. + * notice. You may not view, use, disclose, copy or distribute this file or
  90560. + * any information contained herein except pursuant to this license grant from
  90561. + * Synopsys. If you do not agree with this notice, including the disclaimer
  90562. + * below, then you are not authorized to use the Software.
  90563. + *
  90564. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  90565. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  90566. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  90567. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  90568. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  90569. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  90570. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  90571. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  90572. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  90573. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  90574. + * DAMAGE.
  90575. + * ========================================================================== */
  90576. +#ifndef DWC_HOST_ONLY
  90577. +
  90578. +/** @file
  90579. + * This file implements the Peripheral Controller Driver.
  90580. + *
  90581. + * The Peripheral Controller Driver (PCD) is responsible for
  90582. + * translating requests from the Function Driver into the appropriate
  90583. + * actions on the DWC_otg controller. It isolates the Function Driver
  90584. + * from the specifics of the controller by providing an API to the
  90585. + * Function Driver.
  90586. + *
  90587. + * The Peripheral Controller Driver for Linux will implement the
  90588. + * Gadget API, so that the existing Gadget drivers can be used.
  90589. + * (Gadget Driver is the Linux terminology for a Function Driver.)
  90590. + *
  90591. + * The Linux Gadget API is defined in the header file
  90592. + * <code><linux/usb_gadget.h></code>. The USB EP operations API is
  90593. + * defined in the structure <code>usb_ep_ops</code> and the USB
  90594. + * Controller API is defined in the structure
  90595. + * <code>usb_gadget_ops</code>.
  90596. + *
  90597. + */
  90598. +
  90599. +#include "dwc_otg_os_dep.h"
  90600. +#include "dwc_otg_pcd_if.h"
  90601. +#include "dwc_otg_pcd.h"
  90602. +#include "dwc_otg_driver.h"
  90603. +#include "dwc_otg_dbg.h"
  90604. +
  90605. +static struct gadget_wrapper {
  90606. + dwc_otg_pcd_t *pcd;
  90607. +
  90608. + struct usb_gadget gadget;
  90609. + struct usb_gadget_driver *driver;
  90610. +
  90611. + struct usb_ep ep0;
  90612. + struct usb_ep in_ep[16];
  90613. + struct usb_ep out_ep[16];
  90614. +
  90615. +} *gadget_wrapper;
  90616. +
  90617. +/* Display the contents of the buffer */
  90618. +extern void dump_msg(const u8 * buf, unsigned int length);
  90619. +/**
  90620. + * Get the dwc_otg_pcd_ep_t* from usb_ep* pointer - NULL in case
  90621. + * if the endpoint is not found
  90622. + */
  90623. +static struct dwc_otg_pcd_ep *ep_from_handle(dwc_otg_pcd_t * pcd, void *handle)
  90624. +{
  90625. + int i;
  90626. + if (pcd->ep0.priv == handle) {
  90627. + return &pcd->ep0;
  90628. + }
  90629. +
  90630. + for (i = 0; i < MAX_EPS_CHANNELS - 1; i++) {
  90631. + if (pcd->in_ep[i].priv == handle)
  90632. + return &pcd->in_ep[i];
  90633. + if (pcd->out_ep[i].priv == handle)
  90634. + return &pcd->out_ep[i];
  90635. + }
  90636. +
  90637. + return NULL;
  90638. +}
  90639. +
  90640. +/* USB Endpoint Operations */
  90641. +/*
  90642. + * The following sections briefly describe the behavior of the Gadget
  90643. + * API endpoint operations implemented in the DWC_otg driver
  90644. + * software. Detailed descriptions of the generic behavior of each of
  90645. + * these functions can be found in the Linux header file
  90646. + * include/linux/usb_gadget.h.
  90647. + *
  90648. + * The Gadget API provides wrapper functions for each of the function
  90649. + * pointers defined in usb_ep_ops. The Gadget Driver calls the wrapper
  90650. + * function, which then calls the underlying PCD function. The
  90651. + * following sections are named according to the wrapper
  90652. + * functions. Within each section, the corresponding DWC_otg PCD
  90653. + * function name is specified.
  90654. + *
  90655. + */
  90656. +
  90657. +/**
  90658. + * This function is called by the Gadget Driver for each EP to be
  90659. + * configured for the current configuration (SET_CONFIGURATION).
  90660. + *
  90661. + * This function initializes the dwc_otg_ep_t data structure, and then
  90662. + * calls dwc_otg_ep_activate.
  90663. + */
  90664. +static int ep_enable(struct usb_ep *usb_ep,
  90665. + const struct usb_endpoint_descriptor *ep_desc)
  90666. +{
  90667. + int retval;
  90668. +
  90669. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p)\n", __func__, usb_ep, ep_desc);
  90670. +
  90671. + if (!usb_ep || !ep_desc || ep_desc->bDescriptorType != USB_DT_ENDPOINT) {
  90672. + DWC_WARN("%s, bad ep or descriptor\n", __func__);
  90673. + return -EINVAL;
  90674. + }
  90675. + if (usb_ep == &gadget_wrapper->ep0) {
  90676. + DWC_WARN("%s, bad ep(0)\n", __func__);
  90677. + return -EINVAL;
  90678. + }
  90679. +
  90680. + /* Check FIFO size? */
  90681. + if (!ep_desc->wMaxPacketSize) {
  90682. + DWC_WARN("%s, bad %s maxpacket\n", __func__, usb_ep->name);
  90683. + return -ERANGE;
  90684. + }
  90685. +
  90686. + if (!gadget_wrapper->driver ||
  90687. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  90688. + DWC_WARN("%s, bogus device state\n", __func__);
  90689. + return -ESHUTDOWN;
  90690. + }
  90691. +
  90692. + /* Delete after check - MAS */
  90693. +#if 0
  90694. + nat = (uint32_t) ep_desc->wMaxPacketSize;
  90695. + printk(KERN_ALERT "%s: nat (before) =%d\n", __func__, nat);
  90696. + nat = (nat >> 11) & 0x03;
  90697. + printk(KERN_ALERT "%s: nat (after) =%d\n", __func__, nat);
  90698. +#endif
  90699. + retval = dwc_otg_pcd_ep_enable(gadget_wrapper->pcd,
  90700. + (const uint8_t *)ep_desc,
  90701. + (void *)usb_ep);
  90702. + if (retval) {
  90703. + DWC_WARN("dwc_otg_pcd_ep_enable failed\n");
  90704. + return -EINVAL;
  90705. + }
  90706. +
  90707. + usb_ep->maxpacket = le16_to_cpu(ep_desc->wMaxPacketSize);
  90708. +
  90709. + return 0;
  90710. +}
  90711. +
  90712. +/**
  90713. + * This function is called when an EP is disabled due to disconnect or
  90714. + * change in configuration. Any pending requests will terminate with a
  90715. + * status of -ESHUTDOWN.
  90716. + *
  90717. + * This function modifies the dwc_otg_ep_t data structure for this EP,
  90718. + * and then calls dwc_otg_ep_deactivate.
  90719. + */
  90720. +static int ep_disable(struct usb_ep *usb_ep)
  90721. +{
  90722. + int retval;
  90723. +
  90724. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, usb_ep);
  90725. + if (!usb_ep) {
  90726. + DWC_DEBUGPL(DBG_PCD, "%s, %s not enabled\n", __func__,
  90727. + usb_ep ? usb_ep->name : NULL);
  90728. + return -EINVAL;
  90729. + }
  90730. +
  90731. + retval = dwc_otg_pcd_ep_disable(gadget_wrapper->pcd, usb_ep);
  90732. + if (retval) {
  90733. + retval = -EINVAL;
  90734. + }
  90735. +
  90736. + return retval;
  90737. +}
  90738. +
  90739. +/**
  90740. + * This function allocates a request object to use with the specified
  90741. + * endpoint.
  90742. + *
  90743. + * @param ep The endpoint to be used with with the request
  90744. + * @param gfp_flags the GFP_* flags to use.
  90745. + */
  90746. +static struct usb_request *dwc_otg_pcd_alloc_request(struct usb_ep *ep,
  90747. + gfp_t gfp_flags)
  90748. +{
  90749. + struct usb_request *usb_req;
  90750. +
  90751. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%d)\n", __func__, ep, gfp_flags);
  90752. + if (0 == ep) {
  90753. + DWC_WARN("%s() %s\n", __func__, "Invalid EP!\n");
  90754. + return 0;
  90755. + }
  90756. + usb_req = kmalloc(sizeof(*usb_req), gfp_flags);
  90757. + if (0 == usb_req) {
  90758. + DWC_WARN("%s() %s\n", __func__, "request allocation failed!\n");
  90759. + return 0;
  90760. + }
  90761. + memset(usb_req, 0, sizeof(*usb_req));
  90762. + usb_req->dma = DWC_DMA_ADDR_INVALID;
  90763. +
  90764. + return usb_req;
  90765. +}
  90766. +
  90767. +/**
  90768. + * This function frees a request object.
  90769. + *
  90770. + * @param ep The endpoint associated with the request
  90771. + * @param req The request being freed
  90772. + */
  90773. +static void dwc_otg_pcd_free_request(struct usb_ep *ep, struct usb_request *req)
  90774. +{
  90775. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p)\n", __func__, ep, req);
  90776. +
  90777. + if (0 == ep || 0 == req) {
  90778. + DWC_WARN("%s() %s\n", __func__,
  90779. + "Invalid ep or req argument!\n");
  90780. + return;
  90781. + }
  90782. +
  90783. + kfree(req);
  90784. +}
  90785. +
  90786. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  90787. +/**
  90788. + * This function allocates an I/O buffer to be used for a transfer
  90789. + * to/from the specified endpoint.
  90790. + *
  90791. + * @param usb_ep The endpoint to be used with with the request
  90792. + * @param bytes The desired number of bytes for the buffer
  90793. + * @param dma Pointer to the buffer's DMA address; must be valid
  90794. + * @param gfp_flags the GFP_* flags to use.
  90795. + * @return address of a new buffer or null is buffer could not be allocated.
  90796. + */
  90797. +static void *dwc_otg_pcd_alloc_buffer(struct usb_ep *usb_ep, unsigned bytes,
  90798. + dma_addr_t * dma, gfp_t gfp_flags)
  90799. +{
  90800. + void *buf;
  90801. + dwc_otg_pcd_t *pcd = 0;
  90802. +
  90803. + pcd = gadget_wrapper->pcd;
  90804. +
  90805. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%d,%p,%0x)\n", __func__, usb_ep, bytes,
  90806. + dma, gfp_flags);
  90807. +
  90808. + /* Check dword alignment */
  90809. + if ((bytes & 0x3UL) != 0) {
  90810. + DWC_WARN("%s() Buffer size is not a multiple of"
  90811. + "DWORD size (%d)", __func__, bytes);
  90812. + }
  90813. +
  90814. + buf = dma_alloc_coherent(NULL, bytes, dma, gfp_flags);
  90815. +
  90816. + /* Check dword alignment */
  90817. + if (((int)buf & 0x3UL) != 0) {
  90818. + DWC_WARN("%s() Buffer is not DWORD aligned (%p)",
  90819. + __func__, buf);
  90820. + }
  90821. +
  90822. + return buf;
  90823. +}
  90824. +
  90825. +/**
  90826. + * This function frees an I/O buffer that was allocated by alloc_buffer.
  90827. + *
  90828. + * @param usb_ep the endpoint associated with the buffer
  90829. + * @param buf address of the buffer
  90830. + * @param dma The buffer's DMA address
  90831. + * @param bytes The number of bytes of the buffer
  90832. + */
  90833. +static void dwc_otg_pcd_free_buffer(struct usb_ep *usb_ep, void *buf,
  90834. + dma_addr_t dma, unsigned bytes)
  90835. +{
  90836. + dwc_otg_pcd_t *pcd = 0;
  90837. +
  90838. + pcd = gadget_wrapper->pcd;
  90839. +
  90840. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%0x,%d)\n", __func__, buf, dma, bytes);
  90841. +
  90842. + dma_free_coherent(NULL, bytes, buf, dma);
  90843. +}
  90844. +#endif
  90845. +
  90846. +/**
  90847. + * This function is used to submit an I/O Request to an EP.
  90848. + *
  90849. + * - When the request completes the request's completion callback
  90850. + * is called to return the request to the driver.
  90851. + * - An EP, except control EPs, may have multiple requests
  90852. + * pending.
  90853. + * - Once submitted the request cannot be examined or modified.
  90854. + * - Each request is turned into one or more packets.
  90855. + * - A BULK EP can queue any amount of data; the transfer is
  90856. + * packetized.
  90857. + * - Zero length Packets are specified with the request 'zero'
  90858. + * flag.
  90859. + */
  90860. +static int ep_queue(struct usb_ep *usb_ep, struct usb_request *usb_req,
  90861. + gfp_t gfp_flags)
  90862. +{
  90863. + dwc_otg_pcd_t *pcd;
  90864. + struct dwc_otg_pcd_ep *ep = NULL;
  90865. + int retval = 0, is_isoc_ep = 0;
  90866. + dma_addr_t dma_addr = DWC_DMA_ADDR_INVALID;
  90867. +
  90868. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p,%d)\n",
  90869. + __func__, usb_ep, usb_req, gfp_flags);
  90870. +
  90871. + if (!usb_req || !usb_req->complete || !usb_req->buf) {
  90872. + DWC_WARN("bad params\n");
  90873. + return -EINVAL;
  90874. + }
  90875. +
  90876. + if (!usb_ep) {
  90877. + DWC_WARN("bad ep\n");
  90878. + return -EINVAL;
  90879. + }
  90880. +
  90881. + pcd = gadget_wrapper->pcd;
  90882. + if (!gadget_wrapper->driver ||
  90883. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  90884. + DWC_DEBUGPL(DBG_PCDV, "gadget.speed=%d\n",
  90885. + gadget_wrapper->gadget.speed);
  90886. + DWC_WARN("bogus device state\n");
  90887. + return -ESHUTDOWN;
  90888. + }
  90889. +
  90890. + DWC_DEBUGPL(DBG_PCD, "%s queue req %p, len %d buf %p\n",
  90891. + usb_ep->name, usb_req, usb_req->length, usb_req->buf);
  90892. +
  90893. + usb_req->status = -EINPROGRESS;
  90894. + usb_req->actual = 0;
  90895. +
  90896. + ep = ep_from_handle(pcd, usb_ep);
  90897. + if (ep == NULL)
  90898. + is_isoc_ep = 0;
  90899. + else
  90900. + is_isoc_ep = (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) ? 1 : 0;
  90901. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  90902. + dma_addr = usb_req->dma;
  90903. +#else
  90904. + if (GET_CORE_IF(pcd)->dma_enable) {
  90905. + dwc_otg_device_t *otg_dev = gadget_wrapper->pcd->otg_dev;
  90906. + struct device *dev = NULL;
  90907. +
  90908. + if (otg_dev != NULL)
  90909. + dev = DWC_OTG_OS_GETDEV(otg_dev->os_dep);
  90910. +
  90911. + if (usb_req->length != 0 &&
  90912. + usb_req->dma == DWC_DMA_ADDR_INVALID) {
  90913. + dma_addr = dma_map_single(dev, usb_req->buf,
  90914. + usb_req->length,
  90915. + ep->dwc_ep.is_in ?
  90916. + DMA_TO_DEVICE:
  90917. + DMA_FROM_DEVICE);
  90918. + }
  90919. + }
  90920. +#endif
  90921. +
  90922. +#ifdef DWC_UTE_PER_IO
  90923. + if (is_isoc_ep == 1) {
  90924. + retval = dwc_otg_pcd_xiso_ep_queue(pcd, usb_ep, usb_req->buf, dma_addr,
  90925. + usb_req->length, usb_req->zero, usb_req,
  90926. + gfp_flags == GFP_ATOMIC ? 1 : 0, &usb_req->ext_req);
  90927. + if (retval)
  90928. + return -EINVAL;
  90929. +
  90930. + return 0;
  90931. + }
  90932. +#endif
  90933. + retval = dwc_otg_pcd_ep_queue(pcd, usb_ep, usb_req->buf, dma_addr,
  90934. + usb_req->length, usb_req->zero, usb_req,
  90935. + gfp_flags == GFP_ATOMIC ? 1 : 0);
  90936. + if (retval) {
  90937. + return -EINVAL;
  90938. + }
  90939. +
  90940. + return 0;
  90941. +}
  90942. +
  90943. +/**
  90944. + * This function cancels an I/O request from an EP.
  90945. + */
  90946. +static int ep_dequeue(struct usb_ep *usb_ep, struct usb_request *usb_req)
  90947. +{
  90948. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p)\n", __func__, usb_ep, usb_req);
  90949. +
  90950. + if (!usb_ep || !usb_req) {
  90951. + DWC_WARN("bad argument\n");
  90952. + return -EINVAL;
  90953. + }
  90954. + if (!gadget_wrapper->driver ||
  90955. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  90956. + DWC_WARN("bogus device state\n");
  90957. + return -ESHUTDOWN;
  90958. + }
  90959. + if (dwc_otg_pcd_ep_dequeue(gadget_wrapper->pcd, usb_ep, usb_req)) {
  90960. + return -EINVAL;
  90961. + }
  90962. +
  90963. + return 0;
  90964. +}
  90965. +
  90966. +/**
  90967. + * usb_ep_set_halt stalls an endpoint.
  90968. + *
  90969. + * usb_ep_clear_halt clears an endpoint halt and resets its data
  90970. + * toggle.
  90971. + *
  90972. + * Both of these functions are implemented with the same underlying
  90973. + * function. The behavior depends on the value argument.
  90974. + *
  90975. + * @param[in] usb_ep the Endpoint to halt or clear halt.
  90976. + * @param[in] value
  90977. + * - 0 means clear_halt.
  90978. + * - 1 means set_halt,
  90979. + * - 2 means clear stall lock flag.
  90980. + * - 3 means set stall lock flag.
  90981. + */
  90982. +static int ep_halt(struct usb_ep *usb_ep, int value)
  90983. +{
  90984. + int retval = 0;
  90985. +
  90986. + DWC_DEBUGPL(DBG_PCD, "HALT %s %d\n", usb_ep->name, value);
  90987. +
  90988. + if (!usb_ep) {
  90989. + DWC_WARN("bad ep\n");
  90990. + return -EINVAL;
  90991. + }
  90992. +
  90993. + retval = dwc_otg_pcd_ep_halt(gadget_wrapper->pcd, usb_ep, value);
  90994. + if (retval == -DWC_E_AGAIN) {
  90995. + return -EAGAIN;
  90996. + } else if (retval) {
  90997. + retval = -EINVAL;
  90998. + }
  90999. +
  91000. + return retval;
  91001. +}
  91002. +
  91003. +//#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30))
  91004. +#if 0
  91005. +/**
  91006. + * ep_wedge: sets the halt feature and ignores clear requests
  91007. + *
  91008. + * @usb_ep: the endpoint being wedged
  91009. + *
  91010. + * Use this to stall an endpoint and ignore CLEAR_FEATURE(HALT_ENDPOINT)
  91011. + * requests. If the gadget driver clears the halt status, it will
  91012. + * automatically unwedge the endpoint.
  91013. + *
  91014. + * Returns zero on success, else negative errno. *
  91015. + * Check usb_ep_set_wedge() at "usb_gadget.h" for details
  91016. + */
  91017. +static int ep_wedge(struct usb_ep *usb_ep)
  91018. +{
  91019. + int retval = 0;
  91020. +
  91021. + DWC_DEBUGPL(DBG_PCD, "WEDGE %s\n", usb_ep->name);
  91022. +
  91023. + if (!usb_ep) {
  91024. + DWC_WARN("bad ep\n");
  91025. + return -EINVAL;
  91026. + }
  91027. +
  91028. + retval = dwc_otg_pcd_ep_wedge(gadget_wrapper->pcd, usb_ep);
  91029. + if (retval == -DWC_E_AGAIN) {
  91030. + retval = -EAGAIN;
  91031. + } else if (retval) {
  91032. + retval = -EINVAL;
  91033. + }
  91034. +
  91035. + return retval;
  91036. +}
  91037. +#endif
  91038. +
  91039. +#ifdef DWC_EN_ISOC
  91040. +/**
  91041. + * This function is used to submit an ISOC Transfer Request to an EP.
  91042. + *
  91043. + * - Every time a sync period completes the request's completion callback
  91044. + * is called to provide data to the gadget driver.
  91045. + * - Once submitted the request cannot be modified.
  91046. + * - Each request is turned into periodic data packets untill ISO
  91047. + * Transfer is stopped..
  91048. + */
  91049. +static int iso_ep_start(struct usb_ep *usb_ep, struct usb_iso_request *req,
  91050. + gfp_t gfp_flags)
  91051. +{
  91052. + int retval = 0;
  91053. +
  91054. + if (!req || !req->process_buffer || !req->buf0 || !req->buf1) {
  91055. + DWC_WARN("bad params\n");
  91056. + return -EINVAL;
  91057. + }
  91058. +
  91059. + if (!usb_ep) {
  91060. + DWC_PRINTF("bad params\n");
  91061. + return -EINVAL;
  91062. + }
  91063. +
  91064. + req->status = -EINPROGRESS;
  91065. +
  91066. + retval =
  91067. + dwc_otg_pcd_iso_ep_start(gadget_wrapper->pcd, usb_ep, req->buf0,
  91068. + req->buf1, req->dma0, req->dma1,
  91069. + req->sync_frame, req->data_pattern_frame,
  91070. + req->data_per_frame,
  91071. + req->
  91072. + flags & USB_REQ_ISO_ASAP ? -1 :
  91073. + req->start_frame, req->buf_proc_intrvl,
  91074. + req, gfp_flags == GFP_ATOMIC ? 1 : 0);
  91075. +
  91076. + if (retval) {
  91077. + return -EINVAL;
  91078. + }
  91079. +
  91080. + return retval;
  91081. +}
  91082. +
  91083. +/**
  91084. + * This function stops ISO EP Periodic Data Transfer.
  91085. + */
  91086. +static int iso_ep_stop(struct usb_ep *usb_ep, struct usb_iso_request *req)
  91087. +{
  91088. + int retval = 0;
  91089. + if (!usb_ep) {
  91090. + DWC_WARN("bad ep\n");
  91091. + }
  91092. +
  91093. + if (!gadget_wrapper->driver ||
  91094. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  91095. + DWC_DEBUGPL(DBG_PCDV, "gadget.speed=%d\n",
  91096. + gadget_wrapper->gadget.speed);
  91097. + DWC_WARN("bogus device state\n");
  91098. + }
  91099. +
  91100. + dwc_otg_pcd_iso_ep_stop(gadget_wrapper->pcd, usb_ep, req);
  91101. + if (retval) {
  91102. + retval = -EINVAL;
  91103. + }
  91104. +
  91105. + return retval;
  91106. +}
  91107. +
  91108. +static struct usb_iso_request *alloc_iso_request(struct usb_ep *ep,
  91109. + int packets, gfp_t gfp_flags)
  91110. +{
  91111. + struct usb_iso_request *pReq = NULL;
  91112. + uint32_t req_size;
  91113. +
  91114. + req_size = sizeof(struct usb_iso_request);
  91115. + req_size +=
  91116. + (2 * packets * (sizeof(struct usb_gadget_iso_packet_descriptor)));
  91117. +
  91118. + pReq = kmalloc(req_size, gfp_flags);
  91119. + if (!pReq) {
  91120. + DWC_WARN("Can't allocate Iso Request\n");
  91121. + return 0;
  91122. + }
  91123. + pReq->iso_packet_desc0 = (void *)(pReq + 1);
  91124. +
  91125. + pReq->iso_packet_desc1 = pReq->iso_packet_desc0 + packets;
  91126. +
  91127. + return pReq;
  91128. +}
  91129. +
  91130. +static void free_iso_request(struct usb_ep *ep, struct usb_iso_request *req)
  91131. +{
  91132. + kfree(req);
  91133. +}
  91134. +
  91135. +static struct usb_isoc_ep_ops dwc_otg_pcd_ep_ops = {
  91136. + .ep_ops = {
  91137. + .enable = ep_enable,
  91138. + .disable = ep_disable,
  91139. +
  91140. + .alloc_request = dwc_otg_pcd_alloc_request,
  91141. + .free_request = dwc_otg_pcd_free_request,
  91142. +
  91143. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  91144. + .alloc_buffer = dwc_otg_pcd_alloc_buffer,
  91145. + .free_buffer = dwc_otg_pcd_free_buffer,
  91146. +#endif
  91147. +
  91148. + .queue = ep_queue,
  91149. + .dequeue = ep_dequeue,
  91150. +
  91151. + .set_halt = ep_halt,
  91152. + .fifo_status = 0,
  91153. + .fifo_flush = 0,
  91154. + },
  91155. + .iso_ep_start = iso_ep_start,
  91156. + .iso_ep_stop = iso_ep_stop,
  91157. + .alloc_iso_request = alloc_iso_request,
  91158. + .free_iso_request = free_iso_request,
  91159. +};
  91160. +
  91161. +#else
  91162. +
  91163. + int (*enable) (struct usb_ep *ep,
  91164. + const struct usb_endpoint_descriptor *desc);
  91165. + int (*disable) (struct usb_ep *ep);
  91166. +
  91167. + struct usb_request *(*alloc_request) (struct usb_ep *ep,
  91168. + gfp_t gfp_flags);
  91169. + void (*free_request) (struct usb_ep *ep, struct usb_request *req);
  91170. +
  91171. + int (*queue) (struct usb_ep *ep, struct usb_request *req,
  91172. + gfp_t gfp_flags);
  91173. + int (*dequeue) (struct usb_ep *ep, struct usb_request *req);
  91174. +
  91175. + int (*set_halt) (struct usb_ep *ep, int value);
  91176. + int (*set_wedge) (struct usb_ep *ep);
  91177. +
  91178. + int (*fifo_status) (struct usb_ep *ep);
  91179. + void (*fifo_flush) (struct usb_ep *ep);
  91180. +static struct usb_ep_ops dwc_otg_pcd_ep_ops = {
  91181. + .enable = ep_enable,
  91182. + .disable = ep_disable,
  91183. +
  91184. + .alloc_request = dwc_otg_pcd_alloc_request,
  91185. + .free_request = dwc_otg_pcd_free_request,
  91186. +
  91187. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  91188. + .alloc_buffer = dwc_otg_pcd_alloc_buffer,
  91189. + .free_buffer = dwc_otg_pcd_free_buffer,
  91190. +#else
  91191. + /* .set_wedge = ep_wedge, */
  91192. + .set_wedge = NULL, /* uses set_halt instead */
  91193. +#endif
  91194. +
  91195. + .queue = ep_queue,
  91196. + .dequeue = ep_dequeue,
  91197. +
  91198. + .set_halt = ep_halt,
  91199. + .fifo_status = 0,
  91200. + .fifo_flush = 0,
  91201. +
  91202. +};
  91203. +
  91204. +#endif /* _EN_ISOC_ */
  91205. +/* Gadget Operations */
  91206. +/**
  91207. + * The following gadget operations will be implemented in the DWC_otg
  91208. + * PCD. Functions in the API that are not described below are not
  91209. + * implemented.
  91210. + *
  91211. + * The Gadget API provides wrapper functions for each of the function
  91212. + * pointers defined in usb_gadget_ops. The Gadget Driver calls the
  91213. + * wrapper function, which then calls the underlying PCD function. The
  91214. + * following sections are named according to the wrapper functions
  91215. + * (except for ioctl, which doesn't have a wrapper function). Within
  91216. + * each section, the corresponding DWC_otg PCD function name is
  91217. + * specified.
  91218. + *
  91219. + */
  91220. +
  91221. +/**
  91222. + *Gets the USB Frame number of the last SOF.
  91223. + */
  91224. +static int get_frame_number(struct usb_gadget *gadget)
  91225. +{
  91226. + struct gadget_wrapper *d;
  91227. +
  91228. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, gadget);
  91229. +
  91230. + if (gadget == 0) {
  91231. + return -ENODEV;
  91232. + }
  91233. +
  91234. + d = container_of(gadget, struct gadget_wrapper, gadget);
  91235. + return dwc_otg_pcd_get_frame_number(d->pcd);
  91236. +}
  91237. +
  91238. +#ifdef CONFIG_USB_DWC_OTG_LPM
  91239. +static int test_lpm_enabled(struct usb_gadget *gadget)
  91240. +{
  91241. + struct gadget_wrapper *d;
  91242. +
  91243. + d = container_of(gadget, struct gadget_wrapper, gadget);
  91244. +
  91245. + return dwc_otg_pcd_is_lpm_enabled(d->pcd);
  91246. +}
  91247. +#endif
  91248. +
  91249. +/**
  91250. + * Initiates Session Request Protocol (SRP) to wakeup the host if no
  91251. + * session is in progress. If a session is already in progress, but
  91252. + * the device is suspended, remote wakeup signaling is started.
  91253. + *
  91254. + */
  91255. +static int wakeup(struct usb_gadget *gadget)
  91256. +{
  91257. + struct gadget_wrapper *d;
  91258. +
  91259. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, gadget);
  91260. +
  91261. + if (gadget == 0) {
  91262. + return -ENODEV;
  91263. + } else {
  91264. + d = container_of(gadget, struct gadget_wrapper, gadget);
  91265. + }
  91266. + dwc_otg_pcd_wakeup(d->pcd);
  91267. + return 0;
  91268. +}
  91269. +
  91270. +static const struct usb_gadget_ops dwc_otg_pcd_ops = {
  91271. + .get_frame = get_frame_number,
  91272. + .wakeup = wakeup,
  91273. +#ifdef CONFIG_USB_DWC_OTG_LPM
  91274. + .lpm_support = test_lpm_enabled,
  91275. +#endif
  91276. + // current versions must always be self-powered
  91277. +};
  91278. +
  91279. +static int _setup(dwc_otg_pcd_t * pcd, uint8_t * bytes)
  91280. +{
  91281. + int retval = -DWC_E_NOT_SUPPORTED;
  91282. + if (gadget_wrapper->driver && gadget_wrapper->driver->setup) {
  91283. + retval = gadget_wrapper->driver->setup(&gadget_wrapper->gadget,
  91284. + (struct usb_ctrlrequest
  91285. + *)bytes);
  91286. + }
  91287. +
  91288. + if (retval == -ENOTSUPP) {
  91289. + retval = -DWC_E_NOT_SUPPORTED;
  91290. + } else if (retval < 0) {
  91291. + retval = -DWC_E_INVALID;
  91292. + }
  91293. +
  91294. + return retval;
  91295. +}
  91296. +
  91297. +#ifdef DWC_EN_ISOC
  91298. +static int _isoc_complete(dwc_otg_pcd_t * pcd, void *ep_handle,
  91299. + void *req_handle, int proc_buf_num)
  91300. +{
  91301. + int i, packet_count;
  91302. + struct usb_gadget_iso_packet_descriptor *iso_packet = 0;
  91303. + struct usb_iso_request *iso_req = req_handle;
  91304. +
  91305. + if (proc_buf_num) {
  91306. + iso_packet = iso_req->iso_packet_desc1;
  91307. + } else {
  91308. + iso_packet = iso_req->iso_packet_desc0;
  91309. + }
  91310. + packet_count =
  91311. + dwc_otg_pcd_get_iso_packet_count(pcd, ep_handle, req_handle);
  91312. + for (i = 0; i < packet_count; ++i) {
  91313. + int status;
  91314. + int actual;
  91315. + int offset;
  91316. + dwc_otg_pcd_get_iso_packet_params(pcd, ep_handle, req_handle,
  91317. + i, &status, &actual, &offset);
  91318. + switch (status) {
  91319. + case -DWC_E_NO_DATA:
  91320. + status = -ENODATA;
  91321. + break;
  91322. + default:
  91323. + if (status) {
  91324. + DWC_PRINTF("unknown status in isoc packet\n");
  91325. + }
  91326. +
  91327. + }
  91328. + iso_packet[i].status = status;
  91329. + iso_packet[i].offset = offset;
  91330. + iso_packet[i].actual_length = actual;
  91331. + }
  91332. +
  91333. + iso_req->status = 0;
  91334. + iso_req->process_buffer(ep_handle, iso_req);
  91335. +
  91336. + return 0;
  91337. +}
  91338. +#endif /* DWC_EN_ISOC */
  91339. +
  91340. +#ifdef DWC_UTE_PER_IO
  91341. +/**
  91342. + * Copy the contents of the extended request to the Linux usb_request's
  91343. + * extended part and call the gadget's completion.
  91344. + *
  91345. + * @param pcd Pointer to the pcd structure
  91346. + * @param ep_handle Void pointer to the usb_ep structure
  91347. + * @param req_handle Void pointer to the usb_request structure
  91348. + * @param status Request status returned from the portable logic
  91349. + * @param ereq_port Void pointer to the extended request structure
  91350. + * created in the the portable part that contains the
  91351. + * results of the processed iso packets.
  91352. + */
  91353. +static int _xisoc_complete(dwc_otg_pcd_t * pcd, void *ep_handle,
  91354. + void *req_handle, int32_t status, void *ereq_port)
  91355. +{
  91356. + struct dwc_ute_iso_req_ext *ereqorg = NULL;
  91357. + struct dwc_iso_xreq_port *ereqport = NULL;
  91358. + struct dwc_ute_iso_packet_descriptor *desc_org = NULL;
  91359. + int i;
  91360. + struct usb_request *req;
  91361. + //struct dwc_ute_iso_packet_descriptor *
  91362. + //int status = 0;
  91363. +
  91364. + req = (struct usb_request *)req_handle;
  91365. + ereqorg = &req->ext_req;
  91366. + ereqport = (struct dwc_iso_xreq_port *)ereq_port;
  91367. + desc_org = ereqorg->per_io_frame_descs;
  91368. +
  91369. + if (req && req->complete) {
  91370. + /* Copy the request data from the portable logic to our request */
  91371. + for (i = 0; i < ereqport->pio_pkt_count; i++) {
  91372. + desc_org[i].actual_length =
  91373. + ereqport->per_io_frame_descs[i].actual_length;
  91374. + desc_org[i].status =
  91375. + ereqport->per_io_frame_descs[i].status;
  91376. + }
  91377. +
  91378. + switch (status) {
  91379. + case -DWC_E_SHUTDOWN:
  91380. + req->status = -ESHUTDOWN;
  91381. + break;
  91382. + case -DWC_E_RESTART:
  91383. + req->status = -ECONNRESET;
  91384. + break;
  91385. + case -DWC_E_INVALID:
  91386. + req->status = -EINVAL;
  91387. + break;
  91388. + case -DWC_E_TIMEOUT:
  91389. + req->status = -ETIMEDOUT;
  91390. + break;
  91391. + default:
  91392. + req->status = status;
  91393. + }
  91394. +
  91395. + /* And call the gadget's completion */
  91396. + req->complete(ep_handle, req);
  91397. + }
  91398. +
  91399. + return 0;
  91400. +}
  91401. +#endif /* DWC_UTE_PER_IO */
  91402. +
  91403. +static int _complete(dwc_otg_pcd_t * pcd, void *ep_handle,
  91404. + void *req_handle, int32_t status, uint32_t actual)
  91405. +{
  91406. + struct usb_request *req = (struct usb_request *)req_handle;
  91407. +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27)
  91408. + struct dwc_otg_pcd_ep *ep = NULL;
  91409. +#endif
  91410. +
  91411. + if (req && req->complete) {
  91412. + switch (status) {
  91413. + case -DWC_E_SHUTDOWN:
  91414. + req->status = -ESHUTDOWN;
  91415. + break;
  91416. + case -DWC_E_RESTART:
  91417. + req->status = -ECONNRESET;
  91418. + break;
  91419. + case -DWC_E_INVALID:
  91420. + req->status = -EINVAL;
  91421. + break;
  91422. + case -DWC_E_TIMEOUT:
  91423. + req->status = -ETIMEDOUT;
  91424. + break;
  91425. + default:
  91426. + req->status = status;
  91427. +
  91428. + }
  91429. +
  91430. + req->actual = actual;
  91431. + DWC_SPINUNLOCK(pcd->lock);
  91432. + req->complete(ep_handle, req);
  91433. + DWC_SPINLOCK(pcd->lock);
  91434. + }
  91435. +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27)
  91436. + ep = ep_from_handle(pcd, ep_handle);
  91437. + if (GET_CORE_IF(pcd)->dma_enable) {
  91438. + if (req->length != 0) {
  91439. + dwc_otg_device_t *otg_dev = gadget_wrapper->pcd->otg_dev;
  91440. + struct device *dev = NULL;
  91441. +
  91442. + if (otg_dev != NULL)
  91443. + dev = DWC_OTG_OS_GETDEV(otg_dev->os_dep);
  91444. +
  91445. + dma_unmap_single(dev, req->dma, req->length,
  91446. + ep->dwc_ep.is_in ?
  91447. + DMA_TO_DEVICE: DMA_FROM_DEVICE);
  91448. + }
  91449. + }
  91450. +#endif
  91451. +
  91452. + return 0;
  91453. +}
  91454. +
  91455. +static int _connect(dwc_otg_pcd_t * pcd, int speed)
  91456. +{
  91457. + gadget_wrapper->gadget.speed = speed;
  91458. + return 0;
  91459. +}
  91460. +
  91461. +static int _disconnect(dwc_otg_pcd_t * pcd)
  91462. +{
  91463. + if (gadget_wrapper->driver && gadget_wrapper->driver->disconnect) {
  91464. + gadget_wrapper->driver->disconnect(&gadget_wrapper->gadget);
  91465. + }
  91466. + return 0;
  91467. +}
  91468. +
  91469. +static int _resume(dwc_otg_pcd_t * pcd)
  91470. +{
  91471. + if (gadget_wrapper->driver && gadget_wrapper->driver->resume) {
  91472. + gadget_wrapper->driver->resume(&gadget_wrapper->gadget);
  91473. + }
  91474. +
  91475. + return 0;
  91476. +}
  91477. +
  91478. +static int _suspend(dwc_otg_pcd_t * pcd)
  91479. +{
  91480. + if (gadget_wrapper->driver && gadget_wrapper->driver->suspend) {
  91481. + gadget_wrapper->driver->suspend(&gadget_wrapper->gadget);
  91482. + }
  91483. + return 0;
  91484. +}
  91485. +
  91486. +/**
  91487. + * This function updates the otg values in the gadget structure.
  91488. + */
  91489. +static int _hnp_changed(dwc_otg_pcd_t * pcd)
  91490. +{
  91491. +
  91492. + if (!gadget_wrapper->gadget.is_otg)
  91493. + return 0;
  91494. +
  91495. + gadget_wrapper->gadget.b_hnp_enable = get_b_hnp_enable(pcd);
  91496. + gadget_wrapper->gadget.a_hnp_support = get_a_hnp_support(pcd);
  91497. + gadget_wrapper->gadget.a_alt_hnp_support = get_a_alt_hnp_support(pcd);
  91498. + return 0;
  91499. +}
  91500. +
  91501. +static int _reset(dwc_otg_pcd_t * pcd)
  91502. +{
  91503. + return 0;
  91504. +}
  91505. +
  91506. +#ifdef DWC_UTE_CFI
  91507. +static int _cfi_setup(dwc_otg_pcd_t * pcd, void *cfi_req)
  91508. +{
  91509. + int retval = -DWC_E_INVALID;
  91510. + if (gadget_wrapper->driver->cfi_feature_setup) {
  91511. + retval =
  91512. + gadget_wrapper->driver->
  91513. + cfi_feature_setup(&gadget_wrapper->gadget,
  91514. + (struct cfi_usb_ctrlrequest *)cfi_req);
  91515. + }
  91516. +
  91517. + return retval;
  91518. +}
  91519. +#endif
  91520. +
  91521. +static const struct dwc_otg_pcd_function_ops fops = {
  91522. + .complete = _complete,
  91523. +#ifdef DWC_EN_ISOC
  91524. + .isoc_complete = _isoc_complete,
  91525. +#endif
  91526. + .setup = _setup,
  91527. + .disconnect = _disconnect,
  91528. + .connect = _connect,
  91529. + .resume = _resume,
  91530. + .suspend = _suspend,
  91531. + .hnp_changed = _hnp_changed,
  91532. + .reset = _reset,
  91533. +#ifdef DWC_UTE_CFI
  91534. + .cfi_setup = _cfi_setup,
  91535. +#endif
  91536. +#ifdef DWC_UTE_PER_IO
  91537. + .xisoc_complete = _xisoc_complete,
  91538. +#endif
  91539. +};
  91540. +
  91541. +/**
  91542. + * This function is the top level PCD interrupt handler.
  91543. + */
  91544. +static irqreturn_t dwc_otg_pcd_irq(int irq, void *dev)
  91545. +{
  91546. + dwc_otg_pcd_t *pcd = dev;
  91547. + int32_t retval = IRQ_NONE;
  91548. +
  91549. + retval = dwc_otg_pcd_handle_intr(pcd);
  91550. + if (retval != 0) {
  91551. + S3C2410X_CLEAR_EINTPEND();
  91552. + }
  91553. + return IRQ_RETVAL(retval);
  91554. +}
  91555. +
  91556. +/**
  91557. + * This function initialized the usb_ep structures to there default
  91558. + * state.
  91559. + *
  91560. + * @param d Pointer on gadget_wrapper.
  91561. + */
  91562. +void gadget_add_eps(struct gadget_wrapper *d)
  91563. +{
  91564. + static const char *names[] = {
  91565. +
  91566. + "ep0",
  91567. + "ep1in",
  91568. + "ep2in",
  91569. + "ep3in",
  91570. + "ep4in",
  91571. + "ep5in",
  91572. + "ep6in",
  91573. + "ep7in",
  91574. + "ep8in",
  91575. + "ep9in",
  91576. + "ep10in",
  91577. + "ep11in",
  91578. + "ep12in",
  91579. + "ep13in",
  91580. + "ep14in",
  91581. + "ep15in",
  91582. + "ep1out",
  91583. + "ep2out",
  91584. + "ep3out",
  91585. + "ep4out",
  91586. + "ep5out",
  91587. + "ep6out",
  91588. + "ep7out",
  91589. + "ep8out",
  91590. + "ep9out",
  91591. + "ep10out",
  91592. + "ep11out",
  91593. + "ep12out",
  91594. + "ep13out",
  91595. + "ep14out",
  91596. + "ep15out"
  91597. + };
  91598. +
  91599. + int i;
  91600. + struct usb_ep *ep;
  91601. + int8_t dev_endpoints;
  91602. +
  91603. + DWC_DEBUGPL(DBG_PCDV, "%s\n", __func__);
  91604. +
  91605. + INIT_LIST_HEAD(&d->gadget.ep_list);
  91606. + d->gadget.ep0 = &d->ep0;
  91607. + d->gadget.speed = USB_SPEED_UNKNOWN;
  91608. +
  91609. + INIT_LIST_HEAD(&d->gadget.ep0->ep_list);
  91610. +
  91611. + /**
  91612. + * Initialize the EP0 structure.
  91613. + */
  91614. + ep = &d->ep0;
  91615. +
  91616. + /* Init the usb_ep structure. */
  91617. + ep->name = names[0];
  91618. + ep->ops = (struct usb_ep_ops *)&dwc_otg_pcd_ep_ops;
  91619. +
  91620. + /**
  91621. + * @todo NGS: What should the max packet size be set to
  91622. + * here? Before EP type is set?
  91623. + */
  91624. + ep->maxpacket = MAX_PACKET_SIZE;
  91625. + dwc_otg_pcd_ep_enable(d->pcd, NULL, ep);
  91626. +
  91627. + list_add_tail(&ep->ep_list, &d->gadget.ep_list);
  91628. +
  91629. + /**
  91630. + * Initialize the EP structures.
  91631. + */
  91632. + dev_endpoints = d->pcd->core_if->dev_if->num_in_eps;
  91633. +
  91634. + for (i = 0; i < dev_endpoints; i++) {
  91635. + ep = &d->in_ep[i];
  91636. +
  91637. + /* Init the usb_ep structure. */
  91638. + ep->name = names[d->pcd->in_ep[i].dwc_ep.num];
  91639. + ep->ops = (struct usb_ep_ops *)&dwc_otg_pcd_ep_ops;
  91640. +
  91641. + /**
  91642. + * @todo NGS: What should the max packet size be set to
  91643. + * here? Before EP type is set?
  91644. + */
  91645. + ep->maxpacket = MAX_PACKET_SIZE;
  91646. + list_add_tail(&ep->ep_list, &d->gadget.ep_list);
  91647. + }
  91648. +
  91649. + dev_endpoints = d->pcd->core_if->dev_if->num_out_eps;
  91650. +
  91651. + for (i = 0; i < dev_endpoints; i++) {
  91652. + ep = &d->out_ep[i];
  91653. +
  91654. + /* Init the usb_ep structure. */
  91655. + ep->name = names[15 + d->pcd->out_ep[i].dwc_ep.num];
  91656. + ep->ops = (struct usb_ep_ops *)&dwc_otg_pcd_ep_ops;
  91657. +
  91658. + /**
  91659. + * @todo NGS: What should the max packet size be set to
  91660. + * here? Before EP type is set?
  91661. + */
  91662. + ep->maxpacket = MAX_PACKET_SIZE;
  91663. +
  91664. + list_add_tail(&ep->ep_list, &d->gadget.ep_list);
  91665. + }
  91666. +
  91667. + /* remove ep0 from the list. There is a ep0 pointer. */
  91668. + list_del_init(&d->ep0.ep_list);
  91669. +
  91670. + d->ep0.maxpacket = MAX_EP0_SIZE;
  91671. +}
  91672. +
  91673. +/**
  91674. + * This function releases the Gadget device.
  91675. + * required by device_unregister().
  91676. + *
  91677. + * @todo Should this do something? Should it free the PCD?
  91678. + */
  91679. +static void dwc_otg_pcd_gadget_release(struct device *dev)
  91680. +{
  91681. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, dev);
  91682. +}
  91683. +
  91684. +static struct gadget_wrapper *alloc_wrapper(dwc_bus_dev_t *_dev)
  91685. +{
  91686. + static char pcd_name[] = "dwc_otg_pcd";
  91687. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  91688. + struct gadget_wrapper *d;
  91689. + int retval;
  91690. +
  91691. + d = DWC_ALLOC(sizeof(*d));
  91692. + if (d == NULL) {
  91693. + return NULL;
  91694. + }
  91695. +
  91696. + memset(d, 0, sizeof(*d));
  91697. +
  91698. + d->gadget.name = pcd_name;
  91699. + d->pcd = otg_dev->pcd;
  91700. +
  91701. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
  91702. + strcpy(d->gadget.dev.bus_id, "gadget");
  91703. +#else
  91704. + dev_set_name(&d->gadget.dev, "%s", "gadget");
  91705. +#endif
  91706. +
  91707. + d->gadget.dev.parent = &_dev->dev;
  91708. + d->gadget.dev.release = dwc_otg_pcd_gadget_release;
  91709. + d->gadget.ops = &dwc_otg_pcd_ops;
  91710. + d->gadget.max_speed = dwc_otg_pcd_is_dualspeed(otg_dev->pcd) ? USB_SPEED_HIGH:USB_SPEED_FULL;
  91711. + d->gadget.is_otg = dwc_otg_pcd_is_otg(otg_dev->pcd);
  91712. +
  91713. + d->driver = 0;
  91714. + /* Register the gadget device */
  91715. + retval = device_register(&d->gadget.dev);
  91716. + if (retval != 0) {
  91717. + DWC_ERROR("device_register failed\n");
  91718. + DWC_FREE(d);
  91719. + return NULL;
  91720. + }
  91721. +
  91722. + return d;
  91723. +}
  91724. +
  91725. +static void free_wrapper(struct gadget_wrapper *d)
  91726. +{
  91727. + if (d->driver) {
  91728. + /* should have been done already by driver model core */
  91729. + DWC_WARN("driver '%s' is still registered\n",
  91730. + d->driver->driver.name);
  91731. + usb_gadget_unregister_driver(d->driver);
  91732. + }
  91733. +
  91734. + device_unregister(&d->gadget.dev);
  91735. + DWC_FREE(d);
  91736. +}
  91737. +
  91738. +/**
  91739. + * This function initialized the PCD portion of the driver.
  91740. + *
  91741. + */
  91742. +int pcd_init(dwc_bus_dev_t *_dev)
  91743. +{
  91744. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  91745. + int retval = 0;
  91746. +
  91747. + DWC_DEBUGPL(DBG_PCDV, "%s(%p) otg_dev=%p\n", __func__, _dev, otg_dev);
  91748. +
  91749. + otg_dev->pcd = dwc_otg_pcd_init(otg_dev->core_if);
  91750. +
  91751. + if (!otg_dev->pcd) {
  91752. + DWC_ERROR("dwc_otg_pcd_init failed\n");
  91753. + return -ENOMEM;
  91754. + }
  91755. +
  91756. + otg_dev->pcd->otg_dev = otg_dev;
  91757. + gadget_wrapper = alloc_wrapper(_dev);
  91758. +
  91759. + /*
  91760. + * Initialize EP structures
  91761. + */
  91762. + gadget_add_eps(gadget_wrapper);
  91763. + /*
  91764. + * Setup interupt handler
  91765. + */
  91766. +#ifdef PLATFORM_INTERFACE
  91767. + DWC_DEBUGPL(DBG_ANY, "registering handler for irq%d\n",
  91768. + platform_get_irq(_dev, 0));
  91769. + retval = request_irq(platform_get_irq(_dev, 0), dwc_otg_pcd_irq,
  91770. + IRQF_SHARED, gadget_wrapper->gadget.name,
  91771. + otg_dev->pcd);
  91772. + if (retval != 0) {
  91773. + DWC_ERROR("request of irq%d failed\n",
  91774. + platform_get_irq(_dev, 0));
  91775. + free_wrapper(gadget_wrapper);
  91776. + return -EBUSY;
  91777. + }
  91778. +#else
  91779. + DWC_DEBUGPL(DBG_ANY, "registering handler for irq%d\n",
  91780. + _dev->irq);
  91781. + retval = request_irq(_dev->irq, dwc_otg_pcd_irq,
  91782. + IRQF_SHARED | IRQF_DISABLED,
  91783. + gadget_wrapper->gadget.name, otg_dev->pcd);
  91784. + if (retval != 0) {
  91785. + DWC_ERROR("request of irq%d failed\n", _dev->irq);
  91786. + free_wrapper(gadget_wrapper);
  91787. + return -EBUSY;
  91788. + }
  91789. +#endif
  91790. +
  91791. + dwc_otg_pcd_start(gadget_wrapper->pcd, &fops);
  91792. +
  91793. + return retval;
  91794. +}
  91795. +
  91796. +/**
  91797. + * Cleanup the PCD.
  91798. + */
  91799. +void pcd_remove(dwc_bus_dev_t *_dev)
  91800. +{
  91801. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  91802. + dwc_otg_pcd_t *pcd = otg_dev->pcd;
  91803. +
  91804. + DWC_DEBUGPL(DBG_PCDV, "%s(%p) otg_dev %p\n", __func__, _dev, otg_dev);
  91805. +
  91806. + /*
  91807. + * Free the IRQ
  91808. + */
  91809. +#ifdef PLATFORM_INTERFACE
  91810. + free_irq(platform_get_irq(_dev, 0), pcd);
  91811. +#else
  91812. + free_irq(_dev->irq, pcd);
  91813. +#endif
  91814. + dwc_otg_pcd_remove(otg_dev->pcd);
  91815. + free_wrapper(gadget_wrapper);
  91816. + otg_dev->pcd = 0;
  91817. +}
  91818. +
  91819. +/**
  91820. + * This function registers a gadget driver with the PCD.
  91821. + *
  91822. + * When a driver is successfully registered, it will receive control
  91823. + * requests including set_configuration(), which enables non-control
  91824. + * requests. then usb traffic follows until a disconnect is reported.
  91825. + * then a host may connect again, or the driver might get unbound.
  91826. + *
  91827. + * @param driver The driver being registered
  91828. + * @param bind The bind function of gadget driver
  91829. + */
  91830. +
  91831. +int usb_gadget_probe_driver(struct usb_gadget_driver *driver)
  91832. +{
  91833. + int retval;
  91834. +
  91835. + DWC_DEBUGPL(DBG_PCD, "registering gadget driver '%s'\n",
  91836. + driver->driver.name);
  91837. +
  91838. + if (!driver || driver->max_speed == USB_SPEED_UNKNOWN ||
  91839. + !driver->bind ||
  91840. + !driver->unbind || !driver->disconnect || !driver->setup) {
  91841. + DWC_DEBUGPL(DBG_PCDV, "EINVAL\n");
  91842. + return -EINVAL;
  91843. + }
  91844. + if (gadget_wrapper == 0) {
  91845. + DWC_DEBUGPL(DBG_PCDV, "ENODEV\n");
  91846. + return -ENODEV;
  91847. + }
  91848. + if (gadget_wrapper->driver != 0) {
  91849. + DWC_DEBUGPL(DBG_PCDV, "EBUSY (%p)\n", gadget_wrapper->driver);
  91850. + return -EBUSY;
  91851. + }
  91852. +
  91853. + /* hook up the driver */
  91854. + gadget_wrapper->driver = driver;
  91855. + gadget_wrapper->gadget.dev.driver = &driver->driver;
  91856. +
  91857. + DWC_DEBUGPL(DBG_PCD, "bind to driver %s\n", driver->driver.name);
  91858. + retval = driver->bind(&gadget_wrapper->gadget, gadget_wrapper->driver);
  91859. + if (retval) {
  91860. + DWC_ERROR("bind to driver %s --> error %d\n",
  91861. + driver->driver.name, retval);
  91862. + gadget_wrapper->driver = 0;
  91863. + gadget_wrapper->gadget.dev.driver = 0;
  91864. + return retval;
  91865. + }
  91866. + DWC_DEBUGPL(DBG_ANY, "registered gadget driver '%s'\n",
  91867. + driver->driver.name);
  91868. + return 0;
  91869. +}
  91870. +EXPORT_SYMBOL(usb_gadget_probe_driver);
  91871. +
  91872. +/**
  91873. + * This function unregisters a gadget driver
  91874. + *
  91875. + * @param driver The driver being unregistered
  91876. + */
  91877. +int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
  91878. +{
  91879. + //DWC_DEBUGPL(DBG_PCDV,"%s(%p)\n", __func__, _driver);
  91880. +
  91881. + if (gadget_wrapper == 0) {
  91882. + DWC_DEBUGPL(DBG_ANY, "%s Return(%d): s_pcd==0\n", __func__,
  91883. + -ENODEV);
  91884. + return -ENODEV;
  91885. + }
  91886. + if (driver == 0 || driver != gadget_wrapper->driver) {
  91887. + DWC_DEBUGPL(DBG_ANY, "%s Return(%d): driver?\n", __func__,
  91888. + -EINVAL);
  91889. + return -EINVAL;
  91890. + }
  91891. +
  91892. + driver->unbind(&gadget_wrapper->gadget);
  91893. + gadget_wrapper->driver = 0;
  91894. +
  91895. + DWC_DEBUGPL(DBG_ANY, "unregistered driver '%s'\n", driver->driver.name);
  91896. + return 0;
  91897. +}
  91898. +
  91899. +EXPORT_SYMBOL(usb_gadget_unregister_driver);
  91900. +
  91901. +#endif /* DWC_HOST_ONLY */
  91902. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_regs.h linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_regs.h
  91903. --- linux-3.12.26.orig/drivers/usb/host/dwc_otg/dwc_otg_regs.h 1970-01-01 01:00:00.000000000 +0100
  91904. +++ linux-3.12.26/drivers/usb/host/dwc_otg/dwc_otg_regs.h 2014-08-06 16:50:14.865965229 +0200
  91905. @@ -0,0 +1,2550 @@
  91906. +/* ==========================================================================
  91907. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_regs.h $
  91908. + * $Revision: #98 $
  91909. + * $Date: 2012/08/10 $
  91910. + * $Change: 2047372 $
  91911. + *
  91912. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  91913. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  91914. + * otherwise expressly agreed to in writing between Synopsys and you.
  91915. + *
  91916. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  91917. + * any End User Software License Agreement or Agreement for Licensed Product
  91918. + * with Synopsys or any supplement thereto. You are permitted to use and
  91919. + * redistribute this Software in source and binary forms, with or without
  91920. + * modification, provided that redistributions of source code must retain this
  91921. + * notice. You may not view, use, disclose, copy or distribute this file or
  91922. + * any information contained herein except pursuant to this license grant from
  91923. + * Synopsys. If you do not agree with this notice, including the disclaimer
  91924. + * below, then you are not authorized to use the Software.
  91925. + *
  91926. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  91927. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  91928. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  91929. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  91930. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  91931. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  91932. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  91933. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  91934. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  91935. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  91936. + * DAMAGE.
  91937. + * ========================================================================== */
  91938. +
  91939. +#ifndef __DWC_OTG_REGS_H__
  91940. +#define __DWC_OTG_REGS_H__
  91941. +
  91942. +#include "dwc_otg_core_if.h"
  91943. +
  91944. +/**
  91945. + * @file
  91946. + *
  91947. + * This file contains the data structures for accessing the DWC_otg core registers.
  91948. + *
  91949. + * The application interfaces with the HS OTG core by reading from and
  91950. + * writing to the Control and Status Register (CSR) space through the
  91951. + * AHB Slave interface. These registers are 32 bits wide, and the
  91952. + * addresses are 32-bit-block aligned.
  91953. + * CSRs are classified as follows:
  91954. + * - Core Global Registers
  91955. + * - Device Mode Registers
  91956. + * - Device Global Registers
  91957. + * - Device Endpoint Specific Registers
  91958. + * - Host Mode Registers
  91959. + * - Host Global Registers
  91960. + * - Host Port CSRs
  91961. + * - Host Channel Specific Registers
  91962. + *
  91963. + * Only the Core Global registers can be accessed in both Device and
  91964. + * Host modes. When the HS OTG core is operating in one mode, either
  91965. + * Device or Host, the application must not access registers from the
  91966. + * other mode. When the core switches from one mode to another, the
  91967. + * registers in the new mode of operation must be reprogrammed as they
  91968. + * would be after a power-on reset.
  91969. + */
  91970. +
  91971. +/****************************************************************************/
  91972. +/** DWC_otg Core registers .
  91973. + * The dwc_otg_core_global_regs structure defines the size
  91974. + * and relative field offsets for the Core Global registers.
  91975. + */
  91976. +typedef struct dwc_otg_core_global_regs {
  91977. + /** OTG Control and Status Register. <i>Offset: 000h</i> */
  91978. + volatile uint32_t gotgctl;
  91979. + /** OTG Interrupt Register. <i>Offset: 004h</i> */
  91980. + volatile uint32_t gotgint;
  91981. + /**Core AHB Configuration Register. <i>Offset: 008h</i> */
  91982. + volatile uint32_t gahbcfg;
  91983. +
  91984. +#define DWC_GLBINTRMASK 0x0001
  91985. +#define DWC_DMAENABLE 0x0020
  91986. +#define DWC_NPTXEMPTYLVL_EMPTY 0x0080
  91987. +#define DWC_NPTXEMPTYLVL_HALFEMPTY 0x0000
  91988. +#define DWC_PTXEMPTYLVL_EMPTY 0x0100
  91989. +#define DWC_PTXEMPTYLVL_HALFEMPTY 0x0000
  91990. +
  91991. + /**Core USB Configuration Register. <i>Offset: 00Ch</i> */
  91992. + volatile uint32_t gusbcfg;
  91993. + /**Core Reset Register. <i>Offset: 010h</i> */
  91994. + volatile uint32_t grstctl;
  91995. + /**Core Interrupt Register. <i>Offset: 014h</i> */
  91996. + volatile uint32_t gintsts;
  91997. + /**Core Interrupt Mask Register. <i>Offset: 018h</i> */
  91998. + volatile uint32_t gintmsk;
  91999. + /**Receive Status Queue Read Register (Read Only). <i>Offset: 01Ch</i> */
  92000. + volatile uint32_t grxstsr;
  92001. + /**Receive Status Queue Read & POP Register (Read Only). <i>Offset: 020h</i>*/
  92002. + volatile uint32_t grxstsp;
  92003. + /**Receive FIFO Size Register. <i>Offset: 024h</i> */
  92004. + volatile uint32_t grxfsiz;
  92005. + /**Non Periodic Transmit FIFO Size Register. <i>Offset: 028h</i> */
  92006. + volatile uint32_t gnptxfsiz;
  92007. + /**Non Periodic Transmit FIFO/Queue Status Register (Read
  92008. + * Only). <i>Offset: 02Ch</i> */
  92009. + volatile uint32_t gnptxsts;
  92010. + /**I2C Access Register. <i>Offset: 030h</i> */
  92011. + volatile uint32_t gi2cctl;
  92012. + /**PHY Vendor Control Register. <i>Offset: 034h</i> */
  92013. + volatile uint32_t gpvndctl;
  92014. + /**General Purpose Input/Output Register. <i>Offset: 038h</i> */
  92015. + volatile uint32_t ggpio;
  92016. + /**User ID Register. <i>Offset: 03Ch</i> */
  92017. + volatile uint32_t guid;
  92018. + /**Synopsys ID Register (Read Only). <i>Offset: 040h</i> */
  92019. + volatile uint32_t gsnpsid;
  92020. + /**User HW Config1 Register (Read Only). <i>Offset: 044h</i> */
  92021. + volatile uint32_t ghwcfg1;
  92022. + /**User HW Config2 Register (Read Only). <i>Offset: 048h</i> */
  92023. + volatile uint32_t ghwcfg2;
  92024. +#define DWC_SLAVE_ONLY_ARCH 0
  92025. +#define DWC_EXT_DMA_ARCH 1
  92026. +#define DWC_INT_DMA_ARCH 2
  92027. +
  92028. +#define DWC_MODE_HNP_SRP_CAPABLE 0
  92029. +#define DWC_MODE_SRP_ONLY_CAPABLE 1
  92030. +#define DWC_MODE_NO_HNP_SRP_CAPABLE 2
  92031. +#define DWC_MODE_SRP_CAPABLE_DEVICE 3
  92032. +#define DWC_MODE_NO_SRP_CAPABLE_DEVICE 4
  92033. +#define DWC_MODE_SRP_CAPABLE_HOST 5
  92034. +#define DWC_MODE_NO_SRP_CAPABLE_HOST 6
  92035. +
  92036. + /**User HW Config3 Register (Read Only). <i>Offset: 04Ch</i> */
  92037. + volatile uint32_t ghwcfg3;
  92038. + /**User HW Config4 Register (Read Only). <i>Offset: 050h</i>*/
  92039. + volatile uint32_t ghwcfg4;
  92040. + /** Core LPM Configuration register <i>Offset: 054h</i>*/
  92041. + volatile uint32_t glpmcfg;
  92042. + /** Global PowerDn Register <i>Offset: 058h</i> */
  92043. + volatile uint32_t gpwrdn;
  92044. + /** Global DFIFO SW Config Register <i>Offset: 05Ch</i> */
  92045. + volatile uint32_t gdfifocfg;
  92046. + /** ADP Control Register <i>Offset: 060h</i> */
  92047. + volatile uint32_t adpctl;
  92048. + /** Reserved <i>Offset: 064h-0FFh</i> */
  92049. + volatile uint32_t reserved39[39];
  92050. + /** Host Periodic Transmit FIFO Size Register. <i>Offset: 100h</i> */
  92051. + volatile uint32_t hptxfsiz;
  92052. + /** Device Periodic Transmit FIFO#n Register if dedicated fifos are disabled,
  92053. + otherwise Device Transmit FIFO#n Register.
  92054. + * <i>Offset: 104h + (FIFO_Number-1)*04h, 1 <= FIFO Number <= 15 (1<=n<=15).</i> */
  92055. + volatile uint32_t dtxfsiz[15];
  92056. +} dwc_otg_core_global_regs_t;
  92057. +
  92058. +/**
  92059. + * This union represents the bit fields of the Core OTG Control
  92060. + * and Status Register (GOTGCTL). Set the bits using the bit
  92061. + * fields then write the <i>d32</i> value to the register.
  92062. + */
  92063. +typedef union gotgctl_data {
  92064. + /** raw register data */
  92065. + uint32_t d32;
  92066. + /** register bits */
  92067. + struct {
  92068. + unsigned sesreqscs:1;
  92069. + unsigned sesreq:1;
  92070. + unsigned vbvalidoven:1;
  92071. + unsigned vbvalidovval:1;
  92072. + unsigned avalidoven:1;
  92073. + unsigned avalidovval:1;
  92074. + unsigned bvalidoven:1;
  92075. + unsigned bvalidovval:1;
  92076. + unsigned hstnegscs:1;
  92077. + unsigned hnpreq:1;
  92078. + unsigned hstsethnpen:1;
  92079. + unsigned devhnpen:1;
  92080. + unsigned reserved12_15:4;
  92081. + unsigned conidsts:1;
  92082. + unsigned dbnctime:1;
  92083. + unsigned asesvld:1;
  92084. + unsigned bsesvld:1;
  92085. + unsigned otgver:1;
  92086. + unsigned reserved1:1;
  92087. + unsigned multvalidbc:5;
  92088. + unsigned chirpen:1;
  92089. + unsigned reserved28_31:4;
  92090. + } b;
  92091. +} gotgctl_data_t;
  92092. +
  92093. +/**
  92094. + * This union represents the bit fields of the Core OTG Interrupt Register
  92095. + * (GOTGINT). Set/clear the bits using the bit fields then write the <i>d32</i>
  92096. + * value to the register.
  92097. + */
  92098. +typedef union gotgint_data {
  92099. + /** raw register data */
  92100. + uint32_t d32;
  92101. + /** register bits */
  92102. + struct {
  92103. + /** Current Mode */
  92104. + unsigned reserved0_1:2;
  92105. +
  92106. + /** Session End Detected */
  92107. + unsigned sesenddet:1;
  92108. +
  92109. + unsigned reserved3_7:5;
  92110. +
  92111. + /** Session Request Success Status Change */
  92112. + unsigned sesreqsucstschng:1;
  92113. + /** Host Negotiation Success Status Change */
  92114. + unsigned hstnegsucstschng:1;
  92115. +
  92116. + unsigned reserved10_16:7;
  92117. +
  92118. + /** Host Negotiation Detected */
  92119. + unsigned hstnegdet:1;
  92120. + /** A-Device Timeout Change */
  92121. + unsigned adevtoutchng:1;
  92122. + /** Debounce Done */
  92123. + unsigned debdone:1;
  92124. + /** Multi-Valued input changed */
  92125. + unsigned mvic:1;
  92126. +
  92127. + unsigned reserved31_21:11;
  92128. +
  92129. + } b;
  92130. +} gotgint_data_t;
  92131. +
  92132. +/**
  92133. + * This union represents the bit fields of the Core AHB Configuration
  92134. + * Register (GAHBCFG). Set/clear the bits using the bit fields then
  92135. + * write the <i>d32</i> value to the register.
  92136. + */
  92137. +typedef union gahbcfg_data {
  92138. + /** raw register data */
  92139. + uint32_t d32;
  92140. + /** register bits */
  92141. + struct {
  92142. + unsigned glblintrmsk:1;
  92143. +#define DWC_GAHBCFG_GLBINT_ENABLE 1
  92144. +
  92145. + unsigned hburstlen:4;
  92146. +#define DWC_GAHBCFG_INT_DMA_BURST_SINGLE 0
  92147. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR 1
  92148. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR4 3
  92149. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR8 5
  92150. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR16 7
  92151. +
  92152. + unsigned dmaenable:1;
  92153. +#define DWC_GAHBCFG_DMAENABLE 1
  92154. + unsigned reserved:1;
  92155. + unsigned nptxfemplvl_txfemplvl:1;
  92156. + unsigned ptxfemplvl:1;
  92157. +#define DWC_GAHBCFG_TXFEMPTYLVL_EMPTY 1
  92158. +#define DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY 0
  92159. + unsigned reserved9_20:12;
  92160. + unsigned remmemsupp:1;
  92161. + unsigned notialldmawrit:1;
  92162. + unsigned ahbsingle:1;
  92163. + unsigned reserved24_31:8;
  92164. + } b;
  92165. +} gahbcfg_data_t;
  92166. +
  92167. +/**
  92168. + * This union represents the bit fields of the Core USB Configuration
  92169. + * Register (GUSBCFG). Set the bits using the bit fields then write
  92170. + * the <i>d32</i> value to the register.
  92171. + */
  92172. +typedef union gusbcfg_data {
  92173. + /** raw register data */
  92174. + uint32_t d32;
  92175. + /** register bits */
  92176. + struct {
  92177. + unsigned toutcal:3;
  92178. + unsigned phyif:1;
  92179. + unsigned ulpi_utmi_sel:1;
  92180. + unsigned fsintf:1;
  92181. + unsigned physel:1;
  92182. + unsigned ddrsel:1;
  92183. + unsigned srpcap:1;
  92184. + unsigned hnpcap:1;
  92185. + unsigned usbtrdtim:4;
  92186. + unsigned reserved1:1;
  92187. + unsigned phylpwrclksel:1;
  92188. + unsigned otgutmifssel:1;
  92189. + unsigned ulpi_fsls:1;
  92190. + unsigned ulpi_auto_res:1;
  92191. + unsigned ulpi_clk_sus_m:1;
  92192. + unsigned ulpi_ext_vbus_drv:1;
  92193. + unsigned ulpi_int_vbus_indicator:1;
  92194. + unsigned term_sel_dl_pulse:1;
  92195. + unsigned indicator_complement:1;
  92196. + unsigned indicator_pass_through:1;
  92197. + unsigned ulpi_int_prot_dis:1;
  92198. + unsigned ic_usb_cap:1;
  92199. + unsigned ic_traffic_pull_remove:1;
  92200. + unsigned tx_end_delay:1;
  92201. + unsigned force_host_mode:1;
  92202. + unsigned force_dev_mode:1;
  92203. + unsigned reserved31:1;
  92204. + } b;
  92205. +} gusbcfg_data_t;
  92206. +
  92207. +/**
  92208. + * This union represents the bit fields of the Core Reset Register
  92209. + * (GRSTCTL). Set/clear the bits using the bit fields then write the
  92210. + * <i>d32</i> value to the register.
  92211. + */
  92212. +typedef union grstctl_data {
  92213. + /** raw register data */
  92214. + uint32_t d32;
  92215. + /** register bits */
  92216. + struct {
  92217. + /** Core Soft Reset (CSftRst) (Device and Host)
  92218. + *
  92219. + * The application can flush the control logic in the
  92220. + * entire core using this bit. This bit resets the
  92221. + * pipelines in the AHB Clock domain as well as the
  92222. + * PHY Clock domain.
  92223. + *
  92224. + * The state machines are reset to an IDLE state, the
  92225. + * control bits in the CSRs are cleared, all the
  92226. + * transmit FIFOs and the receive FIFO are flushed.
  92227. + *
  92228. + * The status mask bits that control the generation of
  92229. + * the interrupt, are cleared, to clear the
  92230. + * interrupt. The interrupt status bits are not
  92231. + * cleared, so the application can get the status of
  92232. + * any events that occurred in the core after it has
  92233. + * set this bit.
  92234. + *
  92235. + * Any transactions on the AHB are terminated as soon
  92236. + * as possible following the protocol. Any
  92237. + * transactions on the USB are terminated immediately.
  92238. + *
  92239. + * The configuration settings in the CSRs are
  92240. + * unchanged, so the software doesn't have to
  92241. + * reprogram these registers (Device
  92242. + * Configuration/Host Configuration/Core System
  92243. + * Configuration/Core PHY Configuration).
  92244. + *
  92245. + * The application can write to this bit, any time it
  92246. + * wants to reset the core. This is a self clearing
  92247. + * bit and the core clears this bit after all the
  92248. + * necessary logic is reset in the core, which may
  92249. + * take several clocks, depending on the current state
  92250. + * of the core.
  92251. + */
  92252. + unsigned csftrst:1;
  92253. + /** Hclk Soft Reset
  92254. + *
  92255. + * The application uses this bit to reset the control logic in
  92256. + * the AHB clock domain. Only AHB clock domain pipelines are
  92257. + * reset.
  92258. + */
  92259. + unsigned hsftrst:1;
  92260. + /** Host Frame Counter Reset (Host Only)<br>
  92261. + *
  92262. + * The application can reset the (micro)frame number
  92263. + * counter inside the core, using this bit. When the
  92264. + * (micro)frame counter is reset, the subsequent SOF
  92265. + * sent out by the core, will have a (micro)frame
  92266. + * number of 0.
  92267. + */
  92268. + unsigned hstfrm:1;
  92269. + /** In Token Sequence Learning Queue Flush
  92270. + * (INTknQFlsh) (Device Only)
  92271. + */
  92272. + unsigned intknqflsh:1;
  92273. + /** RxFIFO Flush (RxFFlsh) (Device and Host)
  92274. + *
  92275. + * The application can flush the entire Receive FIFO
  92276. + * using this bit. The application must first
  92277. + * ensure that the core is not in the middle of a
  92278. + * transaction. The application should write into
  92279. + * this bit, only after making sure that neither the
  92280. + * DMA engine is reading from the RxFIFO nor the MAC
  92281. + * is writing the data in to the FIFO. The
  92282. + * application should wait until the bit is cleared
  92283. + * before performing any other operations. This bit
  92284. + * will takes 8 clocks (slowest of PHY or AHB clock)
  92285. + * to clear.
  92286. + */
  92287. + unsigned rxfflsh:1;
  92288. + /** TxFIFO Flush (TxFFlsh) (Device and Host).
  92289. + *
  92290. + * This bit is used to selectively flush a single or
  92291. + * all transmit FIFOs. The application must first
  92292. + * ensure that the core is not in the middle of a
  92293. + * transaction. The application should write into
  92294. + * this bit, only after making sure that neither the
  92295. + * DMA engine is writing into the TxFIFO nor the MAC
  92296. + * is reading the data out of the FIFO. The
  92297. + * application should wait until the core clears this
  92298. + * bit, before performing any operations. This bit
  92299. + * will takes 8 clocks (slowest of PHY or AHB clock)
  92300. + * to clear.
  92301. + */
  92302. + unsigned txfflsh:1;
  92303. +
  92304. + /** TxFIFO Number (TxFNum) (Device and Host).
  92305. + *
  92306. + * This is the FIFO number which needs to be flushed,
  92307. + * using the TxFIFO Flush bit. This field should not
  92308. + * be changed until the TxFIFO Flush bit is cleared by
  92309. + * the core.
  92310. + * - 0x0 : Non Periodic TxFIFO Flush
  92311. + * - 0x1 : Periodic TxFIFO #1 Flush in device mode
  92312. + * or Periodic TxFIFO in host mode
  92313. + * - 0x2 : Periodic TxFIFO #2 Flush in device mode.
  92314. + * - ...
  92315. + * - 0xF : Periodic TxFIFO #15 Flush in device mode
  92316. + * - 0x10: Flush all the Transmit NonPeriodic and
  92317. + * Transmit Periodic FIFOs in the core
  92318. + */
  92319. + unsigned txfnum:5;
  92320. + /** Reserved */
  92321. + unsigned reserved11_29:19;
  92322. + /** DMA Request Signal. Indicated DMA request is in
  92323. + * probress. Used for debug purpose. */
  92324. + unsigned dmareq:1;
  92325. + /** AHB Master Idle. Indicates the AHB Master State
  92326. + * Machine is in IDLE condition. */
  92327. + unsigned ahbidle:1;
  92328. + } b;
  92329. +} grstctl_t;
  92330. +
  92331. +/**
  92332. + * This union represents the bit fields of the Core Interrupt Mask
  92333. + * Register (GINTMSK). Set/clear the bits using the bit fields then
  92334. + * write the <i>d32</i> value to the register.
  92335. + */
  92336. +typedef union gintmsk_data {
  92337. + /** raw register data */
  92338. + uint32_t d32;
  92339. + /** register bits */
  92340. + struct {
  92341. + unsigned reserved0:1;
  92342. + unsigned modemismatch:1;
  92343. + unsigned otgintr:1;
  92344. + unsigned sofintr:1;
  92345. + unsigned rxstsqlvl:1;
  92346. + unsigned nptxfempty:1;
  92347. + unsigned ginnakeff:1;
  92348. + unsigned goutnakeff:1;
  92349. + unsigned ulpickint:1;
  92350. + unsigned i2cintr:1;
  92351. + unsigned erlysuspend:1;
  92352. + unsigned usbsuspend:1;
  92353. + unsigned usbreset:1;
  92354. + unsigned enumdone:1;
  92355. + unsigned isooutdrop:1;
  92356. + unsigned eopframe:1;
  92357. + unsigned restoredone:1;
  92358. + unsigned epmismatch:1;
  92359. + unsigned inepintr:1;
  92360. + unsigned outepintr:1;
  92361. + unsigned incomplisoin:1;
  92362. + unsigned incomplisoout:1;
  92363. + unsigned fetsusp:1;
  92364. + unsigned resetdet:1;
  92365. + unsigned portintr:1;
  92366. + unsigned hcintr:1;
  92367. + unsigned ptxfempty:1;
  92368. + unsigned lpmtranrcvd:1;
  92369. + unsigned conidstschng:1;
  92370. + unsigned disconnect:1;
  92371. + unsigned sessreqintr:1;
  92372. + unsigned wkupintr:1;
  92373. + } b;
  92374. +} gintmsk_data_t;
  92375. +/**
  92376. + * This union represents the bit fields of the Core Interrupt Register
  92377. + * (GINTSTS). Set/clear the bits using the bit fields then write the
  92378. + * <i>d32</i> value to the register.
  92379. + */
  92380. +typedef union gintsts_data {
  92381. + /** raw register data */
  92382. + uint32_t d32;
  92383. +#define DWC_SOF_INTR_MASK 0x0008
  92384. + /** register bits */
  92385. + struct {
  92386. +#define DWC_HOST_MODE 1
  92387. + unsigned curmode:1;
  92388. + unsigned modemismatch:1;
  92389. + unsigned otgintr:1;
  92390. + unsigned sofintr:1;
  92391. + unsigned rxstsqlvl:1;
  92392. + unsigned nptxfempty:1;
  92393. + unsigned ginnakeff:1;
  92394. + unsigned goutnakeff:1;
  92395. + unsigned ulpickint:1;
  92396. + unsigned i2cintr:1;
  92397. + unsigned erlysuspend:1;
  92398. + unsigned usbsuspend:1;
  92399. + unsigned usbreset:1;
  92400. + unsigned enumdone:1;
  92401. + unsigned isooutdrop:1;
  92402. + unsigned eopframe:1;
  92403. + unsigned restoredone:1;
  92404. + unsigned epmismatch:1;
  92405. + unsigned inepint:1;
  92406. + unsigned outepintr:1;
  92407. + unsigned incomplisoin:1;
  92408. + unsigned incomplisoout:1;
  92409. + unsigned fetsusp:1;
  92410. + unsigned resetdet:1;
  92411. + unsigned portintr:1;
  92412. + unsigned hcintr:1;
  92413. + unsigned ptxfempty:1;
  92414. + unsigned lpmtranrcvd:1;
  92415. + unsigned conidstschng:1;
  92416. + unsigned disconnect:1;
  92417. + unsigned sessreqintr:1;
  92418. + unsigned wkupintr:1;
  92419. + } b;
  92420. +} gintsts_data_t;
  92421. +
  92422. +/**
  92423. + * This union represents the bit fields in the Device Receive Status Read and
  92424. + * Pop Registers (GRXSTSR, GRXSTSP) Read the register into the <i>d32</i>
  92425. + * element then read out the bits using the <i>b</i>it elements.
  92426. + */
  92427. +typedef union device_grxsts_data {
  92428. + /** raw register data */
  92429. + uint32_t d32;
  92430. + /** register bits */
  92431. + struct {
  92432. + unsigned epnum:4;
  92433. + unsigned bcnt:11;
  92434. + unsigned dpid:2;
  92435. +
  92436. +#define DWC_STS_DATA_UPDT 0x2 // OUT Data Packet
  92437. +#define DWC_STS_XFER_COMP 0x3 // OUT Data Transfer Complete
  92438. +
  92439. +#define DWC_DSTS_GOUT_NAK 0x1 // Global OUT NAK
  92440. +#define DWC_DSTS_SETUP_COMP 0x4 // Setup Phase Complete
  92441. +#define DWC_DSTS_SETUP_UPDT 0x6 // SETUP Packet
  92442. + unsigned pktsts:4;
  92443. + unsigned fn:4;
  92444. + unsigned reserved25_31:7;
  92445. + } b;
  92446. +} device_grxsts_data_t;
  92447. +
  92448. +/**
  92449. + * This union represents the bit fields in the Host Receive Status Read and
  92450. + * Pop Registers (GRXSTSR, GRXSTSP) Read the register into the <i>d32</i>
  92451. + * element then read out the bits using the <i>b</i>it elements.
  92452. + */
  92453. +typedef union host_grxsts_data {
  92454. + /** raw register data */
  92455. + uint32_t d32;
  92456. + /** register bits */
  92457. + struct {
  92458. + unsigned chnum:4;
  92459. + unsigned bcnt:11;
  92460. + unsigned dpid:2;
  92461. +
  92462. + unsigned pktsts:4;
  92463. +#define DWC_GRXSTS_PKTSTS_IN 0x2
  92464. +#define DWC_GRXSTS_PKTSTS_IN_XFER_COMP 0x3
  92465. +#define DWC_GRXSTS_PKTSTS_DATA_TOGGLE_ERR 0x5
  92466. +#define DWC_GRXSTS_PKTSTS_CH_HALTED 0x7
  92467. +
  92468. + unsigned reserved21_31:11;
  92469. + } b;
  92470. +} host_grxsts_data_t;
  92471. +
  92472. +/**
  92473. + * This union represents the bit fields in the FIFO Size Registers (HPTXFSIZ,
  92474. + * GNPTXFSIZ, DPTXFSIZn, DIEPTXFn). Read the register into the <i>d32</i> element
  92475. + * then read out the bits using the <i>b</i>it elements.
  92476. + */
  92477. +typedef union fifosize_data {
  92478. + /** raw register data */
  92479. + uint32_t d32;
  92480. + /** register bits */
  92481. + struct {
  92482. + unsigned startaddr:16;
  92483. + unsigned depth:16;
  92484. + } b;
  92485. +} fifosize_data_t;
  92486. +
  92487. +/**
  92488. + * This union represents the bit fields in the Non-Periodic Transmit
  92489. + * FIFO/Queue Status Register (GNPTXSTS). Read the register into the
  92490. + * <i>d32</i> element then read out the bits using the <i>b</i>it
  92491. + * elements.
  92492. + */
  92493. +typedef union gnptxsts_data {
  92494. + /** raw register data */
  92495. + uint32_t d32;
  92496. + /** register bits */
  92497. + struct {
  92498. + unsigned nptxfspcavail:16;
  92499. + unsigned nptxqspcavail:8;
  92500. + /** Top of the Non-Periodic Transmit Request Queue
  92501. + * - bit 24 - Terminate (Last entry for the selected
  92502. + * channel/EP)
  92503. + * - bits 26:25 - Token Type
  92504. + * - 2'b00 - IN/OUT
  92505. + * - 2'b01 - Zero Length OUT
  92506. + * - 2'b10 - PING/Complete Split
  92507. + * - 2'b11 - Channel Halt
  92508. + * - bits 30:27 - Channel/EP Number
  92509. + */
  92510. + unsigned nptxqtop_terminate:1;
  92511. + unsigned nptxqtop_token:2;
  92512. + unsigned nptxqtop_chnep:4;
  92513. + unsigned reserved:1;
  92514. + } b;
  92515. +} gnptxsts_data_t;
  92516. +
  92517. +/**
  92518. + * This union represents the bit fields in the Transmit
  92519. + * FIFO Status Register (DTXFSTS). Read the register into the
  92520. + * <i>d32</i> element then read out the bits using the <i>b</i>it
  92521. + * elements.
  92522. + */
  92523. +typedef union dtxfsts_data {
  92524. + /** raw register data */
  92525. + uint32_t d32;
  92526. + /** register bits */
  92527. + struct {
  92528. + unsigned txfspcavail:16;
  92529. + unsigned reserved:16;
  92530. + } b;
  92531. +} dtxfsts_data_t;
  92532. +
  92533. +/**
  92534. + * This union represents the bit fields in the I2C Control Register
  92535. + * (I2CCTL). Read the register into the <i>d32</i> element then read out the
  92536. + * bits using the <i>b</i>it elements.
  92537. + */
  92538. +typedef union gi2cctl_data {
  92539. + /** raw register data */
  92540. + uint32_t d32;
  92541. + /** register bits */
  92542. + struct {
  92543. + unsigned rwdata:8;
  92544. + unsigned regaddr:8;
  92545. + unsigned addr:7;
  92546. + unsigned i2cen:1;
  92547. + unsigned ack:1;
  92548. + unsigned i2csuspctl:1;
  92549. + unsigned i2cdevaddr:2;
  92550. + unsigned i2cdatse0:1;
  92551. + unsigned reserved:1;
  92552. + unsigned rw:1;
  92553. + unsigned bsydne:1;
  92554. + } b;
  92555. +} gi2cctl_data_t;
  92556. +
  92557. +/**
  92558. + * This union represents the bit fields in the PHY Vendor Control Register
  92559. + * (GPVNDCTL). Read the register into the <i>d32</i> element then read out the
  92560. + * bits using the <i>b</i>it elements.
  92561. + */
  92562. +typedef union gpvndctl_data {
  92563. + /** raw register data */
  92564. + uint32_t d32;
  92565. + /** register bits */
  92566. + struct {
  92567. + unsigned regdata:8;
  92568. + unsigned vctrl:8;
  92569. + unsigned regaddr16_21:6;
  92570. + unsigned regwr:1;
  92571. + unsigned reserved23_24:2;
  92572. + unsigned newregreq:1;
  92573. + unsigned vstsbsy:1;
  92574. + unsigned vstsdone:1;
  92575. + unsigned reserved28_30:3;
  92576. + unsigned disulpidrvr:1;
  92577. + } b;
  92578. +} gpvndctl_data_t;
  92579. +
  92580. +/**
  92581. + * This union represents the bit fields in the General Purpose
  92582. + * Input/Output Register (GGPIO).
  92583. + * Read the register into the <i>d32</i> element then read out the
  92584. + * bits using the <i>b</i>it elements.
  92585. + */
  92586. +typedef union ggpio_data {
  92587. + /** raw register data */
  92588. + uint32_t d32;
  92589. + /** register bits */
  92590. + struct {
  92591. + unsigned gpi:16;
  92592. + unsigned gpo:16;
  92593. + } b;
  92594. +} ggpio_data_t;
  92595. +
  92596. +/**
  92597. + * This union represents the bit fields in the User ID Register
  92598. + * (GUID). Read the register into the <i>d32</i> element then read out the
  92599. + * bits using the <i>b</i>it elements.
  92600. + */
  92601. +typedef union guid_data {
  92602. + /** raw register data */
  92603. + uint32_t d32;
  92604. + /** register bits */
  92605. + struct {
  92606. + unsigned rwdata:32;
  92607. + } b;
  92608. +} guid_data_t;
  92609. +
  92610. +/**
  92611. + * This union represents the bit fields in the Synopsys ID Register
  92612. + * (GSNPSID). Read the register into the <i>d32</i> element then read out the
  92613. + * bits using the <i>b</i>it elements.
  92614. + */
  92615. +typedef union gsnpsid_data {
  92616. + /** raw register data */
  92617. + uint32_t d32;
  92618. + /** register bits */
  92619. + struct {
  92620. + unsigned rwdata:32;
  92621. + } b;
  92622. +} gsnpsid_data_t;
  92623. +
  92624. +/**
  92625. + * This union represents the bit fields in the User HW Config1
  92626. + * Register. Read the register into the <i>d32</i> element then read
  92627. + * out the bits using the <i>b</i>it elements.
  92628. + */
  92629. +typedef union hwcfg1_data {
  92630. + /** raw register data */
  92631. + uint32_t d32;
  92632. + /** register bits */
  92633. + struct {
  92634. + unsigned ep_dir0:2;
  92635. + unsigned ep_dir1:2;
  92636. + unsigned ep_dir2:2;
  92637. + unsigned ep_dir3:2;
  92638. + unsigned ep_dir4:2;
  92639. + unsigned ep_dir5:2;
  92640. + unsigned ep_dir6:2;
  92641. + unsigned ep_dir7:2;
  92642. + unsigned ep_dir8:2;
  92643. + unsigned ep_dir9:2;
  92644. + unsigned ep_dir10:2;
  92645. + unsigned ep_dir11:2;
  92646. + unsigned ep_dir12:2;
  92647. + unsigned ep_dir13:2;
  92648. + unsigned ep_dir14:2;
  92649. + unsigned ep_dir15:2;
  92650. + } b;
  92651. +} hwcfg1_data_t;
  92652. +
  92653. +/**
  92654. + * This union represents the bit fields in the User HW Config2
  92655. + * Register. Read the register into the <i>d32</i> element then read
  92656. + * out the bits using the <i>b</i>it elements.
  92657. + */
  92658. +typedef union hwcfg2_data {
  92659. + /** raw register data */
  92660. + uint32_t d32;
  92661. + /** register bits */
  92662. + struct {
  92663. + /* GHWCFG2 */
  92664. + unsigned op_mode:3;
  92665. +#define DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG 0
  92666. +#define DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG 1
  92667. +#define DWC_HWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE_OTG 2
  92668. +#define DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE 3
  92669. +#define DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE 4
  92670. +#define DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST 5
  92671. +#define DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST 6
  92672. +
  92673. + unsigned architecture:2;
  92674. + unsigned point2point:1;
  92675. + unsigned hs_phy_type:2;
  92676. +#define DWC_HWCFG2_HS_PHY_TYPE_NOT_SUPPORTED 0
  92677. +#define DWC_HWCFG2_HS_PHY_TYPE_UTMI 1
  92678. +#define DWC_HWCFG2_HS_PHY_TYPE_ULPI 2
  92679. +#define DWC_HWCFG2_HS_PHY_TYPE_UTMI_ULPI 3
  92680. +
  92681. + unsigned fs_phy_type:2;
  92682. + unsigned num_dev_ep:4;
  92683. + unsigned num_host_chan:4;
  92684. + unsigned perio_ep_supported:1;
  92685. + unsigned dynamic_fifo:1;
  92686. + unsigned multi_proc_int:1;
  92687. + unsigned reserved21:1;
  92688. + unsigned nonperio_tx_q_depth:2;
  92689. + unsigned host_perio_tx_q_depth:2;
  92690. + unsigned dev_token_q_depth:5;
  92691. + unsigned otg_enable_ic_usb:1;
  92692. + } b;
  92693. +} hwcfg2_data_t;
  92694. +
  92695. +/**
  92696. + * This union represents the bit fields in the User HW Config3
  92697. + * Register. Read the register into the <i>d32</i> element then read
  92698. + * out the bits using the <i>b</i>it elements.
  92699. + */
  92700. +typedef union hwcfg3_data {
  92701. + /** raw register data */
  92702. + uint32_t d32;
  92703. + /** register bits */
  92704. + struct {
  92705. + /* GHWCFG3 */
  92706. + unsigned xfer_size_cntr_width:4;
  92707. + unsigned packet_size_cntr_width:3;
  92708. + unsigned otg_func:1;
  92709. + unsigned i2c:1;
  92710. + unsigned vendor_ctrl_if:1;
  92711. + unsigned optional_features:1;
  92712. + unsigned synch_reset_type:1;
  92713. + unsigned adp_supp:1;
  92714. + unsigned otg_enable_hsic:1;
  92715. + unsigned bc_support:1;
  92716. + unsigned otg_lpm_en:1;
  92717. + unsigned dfifo_depth:16;
  92718. + } b;
  92719. +} hwcfg3_data_t;
  92720. +
  92721. +/**
  92722. + * This union represents the bit fields in the User HW Config4
  92723. + * Register. Read the register into the <i>d32</i> element then read
  92724. + * out the bits using the <i>b</i>it elements.
  92725. + */
  92726. +typedef union hwcfg4_data {
  92727. + /** raw register data */
  92728. + uint32_t d32;
  92729. + /** register bits */
  92730. + struct {
  92731. + unsigned num_dev_perio_in_ep:4;
  92732. + unsigned power_optimiz:1;
  92733. + unsigned min_ahb_freq:1;
  92734. + unsigned hiber:1;
  92735. + unsigned xhiber:1;
  92736. + unsigned reserved:6;
  92737. + unsigned utmi_phy_data_width:2;
  92738. + unsigned num_dev_mode_ctrl_ep:4;
  92739. + unsigned iddig_filt_en:1;
  92740. + unsigned vbus_valid_filt_en:1;
  92741. + unsigned a_valid_filt_en:1;
  92742. + unsigned b_valid_filt_en:1;
  92743. + unsigned session_end_filt_en:1;
  92744. + unsigned ded_fifo_en:1;
  92745. + unsigned num_in_eps:4;
  92746. + unsigned desc_dma:1;
  92747. + unsigned desc_dma_dyn:1;
  92748. + } b;
  92749. +} hwcfg4_data_t;
  92750. +
  92751. +/**
  92752. + * This union represents the bit fields of the Core LPM Configuration
  92753. + * Register (GLPMCFG). Set the bits using bit fields then write
  92754. + * the <i>d32</i> value to the register.
  92755. + */
  92756. +typedef union glpmctl_data {
  92757. + /** raw register data */
  92758. + uint32_t d32;
  92759. + /** register bits */
  92760. + struct {
  92761. + /** LPM-Capable (LPMCap) (Device and Host)
  92762. + * The application uses this bit to control
  92763. + * the DWC_otg core LPM capabilities.
  92764. + */
  92765. + unsigned lpm_cap_en:1;
  92766. + /** LPM response programmed by application (AppL1Res) (Device)
  92767. + * Handshake response to LPM token pre-programmed
  92768. + * by device application software.
  92769. + */
  92770. + unsigned appl_resp:1;
  92771. + /** Host Initiated Resume Duration (HIRD) (Device and Host)
  92772. + * In Host mode this field indicates the value of HIRD
  92773. + * to be sent in an LPM transaction.
  92774. + * In Device mode this field is updated with the
  92775. + * Received LPM Token HIRD bmAttribute
  92776. + * when an ACK/NYET/STALL response is sent
  92777. + * to an LPM transaction.
  92778. + */
  92779. + unsigned hird:4;
  92780. + /** RemoteWakeEnable (bRemoteWake) (Device and Host)
  92781. + * In Host mode this bit indicates the value of remote
  92782. + * wake up to be sent in wIndex field of LPM transaction.
  92783. + * In Device mode this field is updated with the
  92784. + * Received LPM Token bRemoteWake bmAttribute
  92785. + * when an ACK/NYET/STALL response is sent
  92786. + * to an LPM transaction.
  92787. + */
  92788. + unsigned rem_wkup_en:1;
  92789. + /** Enable utmi_sleep_n (EnblSlpM) (Device and Host)
  92790. + * The application uses this bit to control
  92791. + * the utmi_sleep_n assertion to the PHY when in L1 state.
  92792. + */
  92793. + unsigned en_utmi_sleep:1;
  92794. + /** HIRD Threshold (HIRD_Thres) (Device and Host)
  92795. + */
  92796. + unsigned hird_thres:5;
  92797. + /** LPM Response (CoreL1Res) (Device and Host)
  92798. + * In Host mode this bit contains handsake response to
  92799. + * LPM transaction.
  92800. + * In Device mode the response of the core to
  92801. + * LPM transaction received is reflected in these two bits.
  92802. + - 0x0 : ERROR (No handshake response)
  92803. + - 0x1 : STALL
  92804. + - 0x2 : NYET
  92805. + - 0x3 : ACK
  92806. + */
  92807. + unsigned lpm_resp:2;
  92808. + /** Port Sleep Status (SlpSts) (Device and Host)
  92809. + * This bit is set as long as a Sleep condition
  92810. + * is present on the USB bus.
  92811. + */
  92812. + unsigned prt_sleep_sts:1;
  92813. + /** Sleep State Resume OK (L1ResumeOK) (Device and Host)
  92814. + * Indicates that the application or host
  92815. + * can start resume from Sleep state.
  92816. + */
  92817. + unsigned sleep_state_resumeok:1;
  92818. + /** LPM channel Index (LPM_Chnl_Indx) (Host)
  92819. + * The channel number on which the LPM transaction
  92820. + * has to be applied while sending
  92821. + * an LPM transaction to the local device.
  92822. + */
  92823. + unsigned lpm_chan_index:4;
  92824. + /** LPM Retry Count (LPM_Retry_Cnt) (Host)
  92825. + * Number host retries that would be performed
  92826. + * if the device response was not valid response.
  92827. + */
  92828. + unsigned retry_count:3;
  92829. + /** Send LPM Transaction (SndLPM) (Host)
  92830. + * When set by application software,
  92831. + * an LPM transaction containing two tokens
  92832. + * is sent.
  92833. + */
  92834. + unsigned send_lpm:1;
  92835. + /** LPM Retry status (LPM_RetryCnt_Sts) (Host)
  92836. + * Number of LPM Host Retries still remaining
  92837. + * to be transmitted for the current LPM sequence
  92838. + */
  92839. + unsigned retry_count_sts:3;
  92840. + unsigned reserved28_29:2;
  92841. + /** In host mode once this bit is set, the host
  92842. + * configures to drive the HSIC Idle state on the bus.
  92843. + * It then waits for the device to initiate the Connect sequence.
  92844. + * In device mode once this bit is set, the device waits for
  92845. + * the HSIC Idle line state on the bus. Upon receving the Idle
  92846. + * line state, it initiates the HSIC Connect sequence.
  92847. + */
  92848. + unsigned hsic_connect:1;
  92849. + /** This bit overrides and functionally inverts
  92850. + * the if_select_hsic input port signal.
  92851. + */
  92852. + unsigned inv_sel_hsic:1;
  92853. + } b;
  92854. +} glpmcfg_data_t;
  92855. +
  92856. +/**
  92857. + * This union represents the bit fields of the Core ADP Timer, Control and
  92858. + * Status Register (ADPTIMCTLSTS). Set the bits using bit fields then write
  92859. + * the <i>d32</i> value to the register.
  92860. + */
  92861. +typedef union adpctl_data {
  92862. + /** raw register data */
  92863. + uint32_t d32;
  92864. + /** register bits */
  92865. + struct {
  92866. + /** Probe Discharge (PRB_DSCHG)
  92867. + * These bits set the times for TADP_DSCHG.
  92868. + * These bits are defined as follows:
  92869. + * 2'b00 - 4 msec
  92870. + * 2'b01 - 8 msec
  92871. + * 2'b10 - 16 msec
  92872. + * 2'b11 - 32 msec
  92873. + */
  92874. + unsigned prb_dschg:2;
  92875. + /** Probe Delta (PRB_DELTA)
  92876. + * These bits set the resolution for RTIM value.
  92877. + * The bits are defined in units of 32 kHz clock cycles as follows:
  92878. + * 2'b00 - 1 cycles
  92879. + * 2'b01 - 2 cycles
  92880. + * 2'b10 - 3 cycles
  92881. + * 2'b11 - 4 cycles
  92882. + * For example if this value is chosen to 2'b01, it means that RTIM
  92883. + * increments for every 3(three) 32Khz clock cycles.
  92884. + */
  92885. + unsigned prb_delta:2;
  92886. + /** Probe Period (PRB_PER)
  92887. + * These bits sets the TADP_PRD as shown in Figure 4 as follows:
  92888. + * 2'b00 - 0.625 to 0.925 sec (typical 0.775 sec)
  92889. + * 2'b01 - 1.25 to 1.85 sec (typical 1.55 sec)
  92890. + * 2'b10 - 1.9 to 2.6 sec (typical 2.275 sec)
  92891. + * 2'b11 - Reserved
  92892. + */
  92893. + unsigned prb_per:2;
  92894. + /** These bits capture the latest time it took for VBUS to ramp from
  92895. + * VADP_SINK to VADP_PRB.
  92896. + * 0x000 - 1 cycles
  92897. + * 0x001 - 2 cycles
  92898. + * 0x002 - 3 cycles
  92899. + * etc
  92900. + * 0x7FF - 2048 cycles
  92901. + * A time of 1024 cycles at 32 kHz corresponds to a time of 32 msec.
  92902. + */
  92903. + unsigned rtim:11;
  92904. + /** Enable Probe (EnaPrb)
  92905. + * When programmed to 1'b1, the core performs a probe operation.
  92906. + * This bit is valid only if OTG_Ver = 1'b1.
  92907. + */
  92908. + unsigned enaprb:1;
  92909. + /** Enable Sense (EnaSns)
  92910. + * When programmed to 1'b1, the core performs a Sense operation.
  92911. + * This bit is valid only if OTG_Ver = 1'b1.
  92912. + */
  92913. + unsigned enasns:1;
  92914. + /** ADP Reset (ADPRes)
  92915. + * When set, ADP controller is reset.
  92916. + * This bit is valid only if OTG_Ver = 1'b1.
  92917. + */
  92918. + unsigned adpres:1;
  92919. + /** ADP Enable (ADPEn)
  92920. + * When set, the core performs either ADP probing or sensing
  92921. + * based on EnaPrb or EnaSns.
  92922. + * This bit is valid only if OTG_Ver = 1'b1.
  92923. + */
  92924. + unsigned adpen:1;
  92925. + /** ADP Probe Interrupt (ADP_PRB_INT)
  92926. + * When this bit is set, it means that the VBUS
  92927. + * voltage is greater than VADP_PRB or VADP_PRB is reached.
  92928. + * This bit is valid only if OTG_Ver = 1'b1.
  92929. + */
  92930. + unsigned adp_prb_int:1;
  92931. + /**
  92932. + * ADP Sense Interrupt (ADP_SNS_INT)
  92933. + * When this bit is set, it means that the VBUS voltage is greater than
  92934. + * VADP_SNS value or VADP_SNS is reached.
  92935. + * This bit is valid only if OTG_Ver = 1'b1.
  92936. + */
  92937. + unsigned adp_sns_int:1;
  92938. + /** ADP Tomeout Interrupt (ADP_TMOUT_INT)
  92939. + * This bit is relevant only for an ADP probe.
  92940. + * When this bit is set, it means that the ramp time has
  92941. + * completed ie ADPCTL.RTIM has reached its terminal value
  92942. + * of 0x7FF. This is a debug feature that allows software
  92943. + * to read the ramp time after each cycle.
  92944. + * This bit is valid only if OTG_Ver = 1'b1.
  92945. + */
  92946. + unsigned adp_tmout_int:1;
  92947. + /** ADP Probe Interrupt Mask (ADP_PRB_INT_MSK)
  92948. + * When this bit is set, it unmasks the interrupt due to ADP_PRB_INT.
  92949. + * This bit is valid only if OTG_Ver = 1'b1.
  92950. + */
  92951. + unsigned adp_prb_int_msk:1;
  92952. + /** ADP Sense Interrupt Mask (ADP_SNS_INT_MSK)
  92953. + * When this bit is set, it unmasks the interrupt due to ADP_SNS_INT.
  92954. + * This bit is valid only if OTG_Ver = 1'b1.
  92955. + */
  92956. + unsigned adp_sns_int_msk:1;
  92957. + /** ADP Timoeout Interrupt Mask (ADP_TMOUT_MSK)
  92958. + * When this bit is set, it unmasks the interrupt due to ADP_TMOUT_INT.
  92959. + * This bit is valid only if OTG_Ver = 1'b1.
  92960. + */
  92961. + unsigned adp_tmout_int_msk:1;
  92962. + /** Access Request
  92963. + * 2'b00 - Read/Write Valid (updated by the core)
  92964. + * 2'b01 - Read
  92965. + * 2'b00 - Write
  92966. + * 2'b00 - Reserved
  92967. + */
  92968. + unsigned ar:2;
  92969. + /** Reserved */
  92970. + unsigned reserved29_31:3;
  92971. + } b;
  92972. +} adpctl_data_t;
  92973. +
  92974. +////////////////////////////////////////////
  92975. +// Device Registers
  92976. +/**
  92977. + * Device Global Registers. <i>Offsets 800h-BFFh</i>
  92978. + *
  92979. + * The following structures define the size and relative field offsets
  92980. + * for the Device Mode Registers.
  92981. + *
  92982. + * <i>These registers are visible only in Device mode and must not be
  92983. + * accessed in Host mode, as the results are unknown.</i>
  92984. + */
  92985. +typedef struct dwc_otg_dev_global_regs {
  92986. + /** Device Configuration Register. <i>Offset 800h</i> */
  92987. + volatile uint32_t dcfg;
  92988. + /** Device Control Register. <i>Offset: 804h</i> */
  92989. + volatile uint32_t dctl;
  92990. + /** Device Status Register (Read Only). <i>Offset: 808h</i> */
  92991. + volatile uint32_t dsts;
  92992. + /** Reserved. <i>Offset: 80Ch</i> */
  92993. + uint32_t unused;
  92994. + /** Device IN Endpoint Common Interrupt Mask
  92995. + * Register. <i>Offset: 810h</i> */
  92996. + volatile uint32_t diepmsk;
  92997. + /** Device OUT Endpoint Common Interrupt Mask
  92998. + * Register. <i>Offset: 814h</i> */
  92999. + volatile uint32_t doepmsk;
  93000. + /** Device All Endpoints Interrupt Register. <i>Offset: 818h</i> */
  93001. + volatile uint32_t daint;
  93002. + /** Device All Endpoints Interrupt Mask Register. <i>Offset:
  93003. + * 81Ch</i> */
  93004. + volatile uint32_t daintmsk;
  93005. + /** Device IN Token Queue Read Register-1 (Read Only).
  93006. + * <i>Offset: 820h</i> */
  93007. + volatile uint32_t dtknqr1;
  93008. + /** Device IN Token Queue Read Register-2 (Read Only).
  93009. + * <i>Offset: 824h</i> */
  93010. + volatile uint32_t dtknqr2;
  93011. + /** Device VBUS discharge Register. <i>Offset: 828h</i> */
  93012. + volatile uint32_t dvbusdis;
  93013. + /** Device VBUS Pulse Register. <i>Offset: 82Ch</i> */
  93014. + volatile uint32_t dvbuspulse;
  93015. + /** Device IN Token Queue Read Register-3 (Read Only). /
  93016. + * Device Thresholding control register (Read/Write)
  93017. + * <i>Offset: 830h</i> */
  93018. + volatile uint32_t dtknqr3_dthrctl;
  93019. + /** Device IN Token Queue Read Register-4 (Read Only). /
  93020. + * Device IN EPs empty Inr. Mask Register (Read/Write)
  93021. + * <i>Offset: 834h</i> */
  93022. + volatile uint32_t dtknqr4_fifoemptymsk;
  93023. + /** Device Each Endpoint Interrupt Register (Read Only). /
  93024. + * <i>Offset: 838h</i> */
  93025. + volatile uint32_t deachint;
  93026. + /** Device Each Endpoint Interrupt mask Register (Read/Write). /
  93027. + * <i>Offset: 83Ch</i> */
  93028. + volatile uint32_t deachintmsk;
  93029. + /** Device Each In Endpoint Interrupt mask Register (Read/Write). /
  93030. + * <i>Offset: 840h</i> */
  93031. + volatile uint32_t diepeachintmsk[MAX_EPS_CHANNELS];
  93032. + /** Device Each Out Endpoint Interrupt mask Register (Read/Write). /
  93033. + * <i>Offset: 880h</i> */
  93034. + volatile uint32_t doepeachintmsk[MAX_EPS_CHANNELS];
  93035. +} dwc_otg_device_global_regs_t;
  93036. +
  93037. +/**
  93038. + * This union represents the bit fields in the Device Configuration
  93039. + * Register. Read the register into the <i>d32</i> member then
  93040. + * set/clear the bits using the <i>b</i>it elements. Write the
  93041. + * <i>d32</i> member to the dcfg register.
  93042. + */
  93043. +typedef union dcfg_data {
  93044. + /** raw register data */
  93045. + uint32_t d32;
  93046. + /** register bits */
  93047. + struct {
  93048. + /** Device Speed */
  93049. + unsigned devspd:2;
  93050. + /** Non Zero Length Status OUT Handshake */
  93051. + unsigned nzstsouthshk:1;
  93052. +#define DWC_DCFG_SEND_STALL 1
  93053. +
  93054. + unsigned ena32khzs:1;
  93055. + /** Device Addresses */
  93056. + unsigned devaddr:7;
  93057. + /** Periodic Frame Interval */
  93058. + unsigned perfrint:2;
  93059. +#define DWC_DCFG_FRAME_INTERVAL_80 0
  93060. +#define DWC_DCFG_FRAME_INTERVAL_85 1
  93061. +#define DWC_DCFG_FRAME_INTERVAL_90 2
  93062. +#define DWC_DCFG_FRAME_INTERVAL_95 3
  93063. +
  93064. + /** Enable Device OUT NAK for bulk in DDMA mode */
  93065. + unsigned endevoutnak:1;
  93066. +
  93067. + unsigned reserved14_17:4;
  93068. + /** In Endpoint Mis-match count */
  93069. + unsigned epmscnt:5;
  93070. + /** Enable Descriptor DMA in Device mode */
  93071. + unsigned descdma:1;
  93072. + unsigned perschintvl:2;
  93073. + unsigned resvalid:6;
  93074. + } b;
  93075. +} dcfg_data_t;
  93076. +
  93077. +/**
  93078. + * This union represents the bit fields in the Device Control
  93079. + * Register. Read the register into the <i>d32</i> member then
  93080. + * set/clear the bits using the <i>b</i>it elements.
  93081. + */
  93082. +typedef union dctl_data {
  93083. + /** raw register data */
  93084. + uint32_t d32;
  93085. + /** register bits */
  93086. + struct {
  93087. + /** Remote Wakeup */
  93088. + unsigned rmtwkupsig:1;
  93089. + /** Soft Disconnect */
  93090. + unsigned sftdiscon:1;
  93091. + /** Global Non-Periodic IN NAK Status */
  93092. + unsigned gnpinnaksts:1;
  93093. + /** Global OUT NAK Status */
  93094. + unsigned goutnaksts:1;
  93095. + /** Test Control */
  93096. + unsigned tstctl:3;
  93097. + /** Set Global Non-Periodic IN NAK */
  93098. + unsigned sgnpinnak:1;
  93099. + /** Clear Global Non-Periodic IN NAK */
  93100. + unsigned cgnpinnak:1;
  93101. + /** Set Global OUT NAK */
  93102. + unsigned sgoutnak:1;
  93103. + /** Clear Global OUT NAK */
  93104. + unsigned cgoutnak:1;
  93105. + /** Power-On Programming Done */
  93106. + unsigned pwronprgdone:1;
  93107. + /** Reserved */
  93108. + unsigned reserved:1;
  93109. + /** Global Multi Count */
  93110. + unsigned gmc:2;
  93111. + /** Ignore Frame Number for ISOC EPs */
  93112. + unsigned ifrmnum:1;
  93113. + /** NAK on Babble */
  93114. + unsigned nakonbble:1;
  93115. + /** Enable Continue on BNA */
  93116. + unsigned encontonbna:1;
  93117. +
  93118. + unsigned reserved18_31:14;
  93119. + } b;
  93120. +} dctl_data_t;
  93121. +
  93122. +/**
  93123. + * This union represents the bit fields in the Device Status
  93124. + * Register. Read the register into the <i>d32</i> member then
  93125. + * set/clear the bits using the <i>b</i>it elements.
  93126. + */
  93127. +typedef union dsts_data {
  93128. + /** raw register data */
  93129. + uint32_t d32;
  93130. + /** register bits */
  93131. + struct {
  93132. + /** Suspend Status */
  93133. + unsigned suspsts:1;
  93134. + /** Enumerated Speed */
  93135. + unsigned enumspd:2;
  93136. +#define DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ 0
  93137. +#define DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ 1
  93138. +#define DWC_DSTS_ENUMSPD_LS_PHY_6MHZ 2
  93139. +#define DWC_DSTS_ENUMSPD_FS_PHY_48MHZ 3
  93140. + /** Erratic Error */
  93141. + unsigned errticerr:1;
  93142. + unsigned reserved4_7:4;
  93143. + /** Frame or Microframe Number of the received SOF */
  93144. + unsigned soffn:14;
  93145. + unsigned reserved22_31:10;
  93146. + } b;
  93147. +} dsts_data_t;
  93148. +
  93149. +/**
  93150. + * This union represents the bit fields in the Device IN EP Interrupt
  93151. + * Register and the Device IN EP Common Mask Register.
  93152. + *
  93153. + * - Read the register into the <i>d32</i> member then set/clear the
  93154. + * bits using the <i>b</i>it elements.
  93155. + */
  93156. +typedef union diepint_data {
  93157. + /** raw register data */
  93158. + uint32_t d32;
  93159. + /** register bits */
  93160. + struct {
  93161. + /** Transfer complete mask */
  93162. + unsigned xfercompl:1;
  93163. + /** Endpoint disable mask */
  93164. + unsigned epdisabled:1;
  93165. + /** AHB Error mask */
  93166. + unsigned ahberr:1;
  93167. + /** TimeOUT Handshake mask (non-ISOC EPs) */
  93168. + unsigned timeout:1;
  93169. + /** IN Token received with TxF Empty mask */
  93170. + unsigned intktxfemp:1;
  93171. + /** IN Token Received with EP mismatch mask */
  93172. + unsigned intknepmis:1;
  93173. + /** IN Endpoint NAK Effective mask */
  93174. + unsigned inepnakeff:1;
  93175. + /** Reserved */
  93176. + unsigned emptyintr:1;
  93177. +
  93178. + unsigned txfifoundrn:1;
  93179. +
  93180. + /** BNA Interrupt mask */
  93181. + unsigned bna:1;
  93182. +
  93183. + unsigned reserved10_12:3;
  93184. + /** BNA Interrupt mask */
  93185. + unsigned nak:1;
  93186. +
  93187. + unsigned reserved14_31:18;
  93188. + } b;
  93189. +} diepint_data_t;
  93190. +
  93191. +/**
  93192. + * This union represents the bit fields in the Device IN EP
  93193. + * Common/Dedicated Interrupt Mask Register.
  93194. + */
  93195. +typedef union diepint_data diepmsk_data_t;
  93196. +
  93197. +/**
  93198. + * This union represents the bit fields in the Device OUT EP Interrupt
  93199. + * Registerand Device OUT EP Common Interrupt Mask Register.
  93200. + *
  93201. + * - Read the register into the <i>d32</i> member then set/clear the
  93202. + * bits using the <i>b</i>it elements.
  93203. + */
  93204. +typedef union doepint_data {
  93205. + /** raw register data */
  93206. + uint32_t d32;
  93207. + /** register bits */
  93208. + struct {
  93209. + /** Transfer complete */
  93210. + unsigned xfercompl:1;
  93211. + /** Endpoint disable */
  93212. + unsigned epdisabled:1;
  93213. + /** AHB Error */
  93214. + unsigned ahberr:1;
  93215. + /** Setup Phase Done (contorl EPs) */
  93216. + unsigned setup:1;
  93217. + /** OUT Token Received when Endpoint Disabled */
  93218. + unsigned outtknepdis:1;
  93219. +
  93220. + unsigned stsphsercvd:1;
  93221. + /** Back-to-Back SETUP Packets Received */
  93222. + unsigned back2backsetup:1;
  93223. +
  93224. + unsigned reserved7:1;
  93225. + /** OUT packet Error */
  93226. + unsigned outpkterr:1;
  93227. + /** BNA Interrupt */
  93228. + unsigned bna:1;
  93229. +
  93230. + unsigned reserved10:1;
  93231. + /** Packet Drop Status */
  93232. + unsigned pktdrpsts:1;
  93233. + /** Babble Interrupt */
  93234. + unsigned babble:1;
  93235. + /** NAK Interrupt */
  93236. + unsigned nak:1;
  93237. + /** NYET Interrupt */
  93238. + unsigned nyet:1;
  93239. + /** Bit indicating setup packet received */
  93240. + unsigned sr:1;
  93241. +
  93242. + unsigned reserved16_31:16;
  93243. + } b;
  93244. +} doepint_data_t;
  93245. +
  93246. +/**
  93247. + * This union represents the bit fields in the Device OUT EP
  93248. + * Common/Dedicated Interrupt Mask Register.
  93249. + */
  93250. +typedef union doepint_data doepmsk_data_t;
  93251. +
  93252. +/**
  93253. + * This union represents the bit fields in the Device All EP Interrupt
  93254. + * and Mask Registers.
  93255. + * - Read the register into the <i>d32</i> member then set/clear the
  93256. + * bits using the <i>b</i>it elements.
  93257. + */
  93258. +typedef union daint_data {
  93259. + /** raw register data */
  93260. + uint32_t d32;
  93261. + /** register bits */
  93262. + struct {
  93263. + /** IN Endpoint bits */
  93264. + unsigned in:16;
  93265. + /** OUT Endpoint bits */
  93266. + unsigned out:16;
  93267. + } ep;
  93268. + struct {
  93269. + /** IN Endpoint bits */
  93270. + unsigned inep0:1;
  93271. + unsigned inep1:1;
  93272. + unsigned inep2:1;
  93273. + unsigned inep3:1;
  93274. + unsigned inep4:1;
  93275. + unsigned inep5:1;
  93276. + unsigned inep6:1;
  93277. + unsigned inep7:1;
  93278. + unsigned inep8:1;
  93279. + unsigned inep9:1;
  93280. + unsigned inep10:1;
  93281. + unsigned inep11:1;
  93282. + unsigned inep12:1;
  93283. + unsigned inep13:1;
  93284. + unsigned inep14:1;
  93285. + unsigned inep15:1;
  93286. + /** OUT Endpoint bits */
  93287. + unsigned outep0:1;
  93288. + unsigned outep1:1;
  93289. + unsigned outep2:1;
  93290. + unsigned outep3:1;
  93291. + unsigned outep4:1;
  93292. + unsigned outep5:1;
  93293. + unsigned outep6:1;
  93294. + unsigned outep7:1;
  93295. + unsigned outep8:1;
  93296. + unsigned outep9:1;
  93297. + unsigned outep10:1;
  93298. + unsigned outep11:1;
  93299. + unsigned outep12:1;
  93300. + unsigned outep13:1;
  93301. + unsigned outep14:1;
  93302. + unsigned outep15:1;
  93303. + } b;
  93304. +} daint_data_t;
  93305. +
  93306. +/**
  93307. + * This union represents the bit fields in the Device IN Token Queue
  93308. + * Read Registers.
  93309. + * - Read the register into the <i>d32</i> member.
  93310. + * - READ-ONLY Register
  93311. + */
  93312. +typedef union dtknq1_data {
  93313. + /** raw register data */
  93314. + uint32_t d32;
  93315. + /** register bits */
  93316. + struct {
  93317. + /** In Token Queue Write Pointer */
  93318. + unsigned intknwptr:5;
  93319. + /** Reserved */
  93320. + unsigned reserved05_06:2;
  93321. + /** write pointer has wrapped. */
  93322. + unsigned wrap_bit:1;
  93323. + /** EP Numbers of IN Tokens 0 ... 4 */
  93324. + unsigned epnums0_5:24;
  93325. + } b;
  93326. +} dtknq1_data_t;
  93327. +
  93328. +/**
  93329. + * This union represents Threshold control Register
  93330. + * - Read and write the register into the <i>d32</i> member.
  93331. + * - READ-WRITABLE Register
  93332. + */
  93333. +typedef union dthrctl_data {
  93334. + /** raw register data */
  93335. + uint32_t d32;
  93336. + /** register bits */
  93337. + struct {
  93338. + /** non ISO Tx Thr. Enable */
  93339. + unsigned non_iso_thr_en:1;
  93340. + /** ISO Tx Thr. Enable */
  93341. + unsigned iso_thr_en:1;
  93342. + /** Tx Thr. Length */
  93343. + unsigned tx_thr_len:9;
  93344. + /** AHB Threshold ratio */
  93345. + unsigned ahb_thr_ratio:2;
  93346. + /** Reserved */
  93347. + unsigned reserved13_15:3;
  93348. + /** Rx Thr. Enable */
  93349. + unsigned rx_thr_en:1;
  93350. + /** Rx Thr. Length */
  93351. + unsigned rx_thr_len:9;
  93352. + unsigned reserved26:1;
  93353. + /** Arbiter Parking Enable*/
  93354. + unsigned arbprken:1;
  93355. + /** Reserved */
  93356. + unsigned reserved28_31:4;
  93357. + } b;
  93358. +} dthrctl_data_t;
  93359. +
  93360. +/**
  93361. + * Device Logical IN Endpoint-Specific Registers. <i>Offsets
  93362. + * 900h-AFCh</i>
  93363. + *
  93364. + * There will be one set of endpoint registers per logical endpoint
  93365. + * implemented.
  93366. + *
  93367. + * <i>These registers are visible only in Device mode and must not be
  93368. + * accessed in Host mode, as the results are unknown.</i>
  93369. + */
  93370. +typedef struct dwc_otg_dev_in_ep_regs {
  93371. + /** Device IN Endpoint Control Register. <i>Offset:900h +
  93372. + * (ep_num * 20h) + 00h</i> */
  93373. + volatile uint32_t diepctl;
  93374. + /** Reserved. <i>Offset:900h + (ep_num * 20h) + 04h</i> */
  93375. + uint32_t reserved04;
  93376. + /** Device IN Endpoint Interrupt Register. <i>Offset:900h +
  93377. + * (ep_num * 20h) + 08h</i> */
  93378. + volatile uint32_t diepint;
  93379. + /** Reserved. <i>Offset:900h + (ep_num * 20h) + 0Ch</i> */
  93380. + uint32_t reserved0C;
  93381. + /** Device IN Endpoint Transfer Size
  93382. + * Register. <i>Offset:900h + (ep_num * 20h) + 10h</i> */
  93383. + volatile uint32_t dieptsiz;
  93384. + /** Device IN Endpoint DMA Address Register. <i>Offset:900h +
  93385. + * (ep_num * 20h) + 14h</i> */
  93386. + volatile uint32_t diepdma;
  93387. + /** Device IN Endpoint Transmit FIFO Status Register. <i>Offset:900h +
  93388. + * (ep_num * 20h) + 18h</i> */
  93389. + volatile uint32_t dtxfsts;
  93390. + /** Device IN Endpoint DMA Buffer Register. <i>Offset:900h +
  93391. + * (ep_num * 20h) + 1Ch</i> */
  93392. + volatile uint32_t diepdmab;
  93393. +} dwc_otg_dev_in_ep_regs_t;
  93394. +
  93395. +/**
  93396. + * Device Logical OUT Endpoint-Specific Registers. <i>Offsets:
  93397. + * B00h-CFCh</i>
  93398. + *
  93399. + * There will be one set of endpoint registers per logical endpoint
  93400. + * implemented.
  93401. + *
  93402. + * <i>These registers are visible only in Device mode and must not be
  93403. + * accessed in Host mode, as the results are unknown.</i>
  93404. + */
  93405. +typedef struct dwc_otg_dev_out_ep_regs {
  93406. + /** Device OUT Endpoint Control Register. <i>Offset:B00h +
  93407. + * (ep_num * 20h) + 00h</i> */
  93408. + volatile uint32_t doepctl;
  93409. + /** Reserved. <i>Offset:B00h + (ep_num * 20h) + 04h</i> */
  93410. + uint32_t reserved04;
  93411. + /** Device OUT Endpoint Interrupt Register. <i>Offset:B00h +
  93412. + * (ep_num * 20h) + 08h</i> */
  93413. + volatile uint32_t doepint;
  93414. + /** Reserved. <i>Offset:B00h + (ep_num * 20h) + 0Ch</i> */
  93415. + uint32_t reserved0C;
  93416. + /** Device OUT Endpoint Transfer Size Register. <i>Offset:
  93417. + * B00h + (ep_num * 20h) + 10h</i> */
  93418. + volatile uint32_t doeptsiz;
  93419. + /** Device OUT Endpoint DMA Address Register. <i>Offset:B00h
  93420. + * + (ep_num * 20h) + 14h</i> */
  93421. + volatile uint32_t doepdma;
  93422. + /** Reserved. <i>Offset:B00h + * (ep_num * 20h) + 18h</i> */
  93423. + uint32_t unused;
  93424. + /** Device OUT Endpoint DMA Buffer Register. <i>Offset:B00h
  93425. + * + (ep_num * 20h) + 1Ch</i> */
  93426. + uint32_t doepdmab;
  93427. +} dwc_otg_dev_out_ep_regs_t;
  93428. +
  93429. +/**
  93430. + * This union represents the bit fields in the Device EP Control
  93431. + * Register. Read the register into the <i>d32</i> member then
  93432. + * set/clear the bits using the <i>b</i>it elements.
  93433. + */
  93434. +typedef union depctl_data {
  93435. + /** raw register data */
  93436. + uint32_t d32;
  93437. + /** register bits */
  93438. + struct {
  93439. + /** Maximum Packet Size
  93440. + * IN/OUT EPn
  93441. + * IN/OUT EP0 - 2 bits
  93442. + * 2'b00: 64 Bytes
  93443. + * 2'b01: 32
  93444. + * 2'b10: 16
  93445. + * 2'b11: 8 */
  93446. + unsigned mps:11;
  93447. +#define DWC_DEP0CTL_MPS_64 0
  93448. +#define DWC_DEP0CTL_MPS_32 1
  93449. +#define DWC_DEP0CTL_MPS_16 2
  93450. +#define DWC_DEP0CTL_MPS_8 3
  93451. +
  93452. + /** Next Endpoint
  93453. + * IN EPn/IN EP0
  93454. + * OUT EPn/OUT EP0 - reserved */
  93455. + unsigned nextep:4;
  93456. +
  93457. + /** USB Active Endpoint */
  93458. + unsigned usbactep:1;
  93459. +
  93460. + /** Endpoint DPID (INTR/Bulk IN and OUT endpoints)
  93461. + * This field contains the PID of the packet going to
  93462. + * be received or transmitted on this endpoint. The
  93463. + * application should program the PID of the first
  93464. + * packet going to be received or transmitted on this
  93465. + * endpoint , after the endpoint is
  93466. + * activated. Application use the SetD1PID and
  93467. + * SetD0PID fields of this register to program either
  93468. + * D0 or D1 PID.
  93469. + *
  93470. + * The encoding for this field is
  93471. + * - 0: D0
  93472. + * - 1: D1
  93473. + */
  93474. + unsigned dpid:1;
  93475. +
  93476. + /** NAK Status */
  93477. + unsigned naksts:1;
  93478. +
  93479. + /** Endpoint Type
  93480. + * 2'b00: Control
  93481. + * 2'b01: Isochronous
  93482. + * 2'b10: Bulk
  93483. + * 2'b11: Interrupt */
  93484. + unsigned eptype:2;
  93485. +
  93486. + /** Snoop Mode
  93487. + * OUT EPn/OUT EP0
  93488. + * IN EPn/IN EP0 - reserved */
  93489. + unsigned snp:1;
  93490. +
  93491. + /** Stall Handshake */
  93492. + unsigned stall:1;
  93493. +
  93494. + /** Tx Fifo Number
  93495. + * IN EPn/IN EP0
  93496. + * OUT EPn/OUT EP0 - reserved */
  93497. + unsigned txfnum:4;
  93498. +
  93499. + /** Clear NAK */
  93500. + unsigned cnak:1;
  93501. + /** Set NAK */
  93502. + unsigned snak:1;
  93503. + /** Set DATA0 PID (INTR/Bulk IN and OUT endpoints)
  93504. + * Writing to this field sets the Endpoint DPID (DPID)
  93505. + * field in this register to DATA0. Set Even
  93506. + * (micro)frame (SetEvenFr) (ISO IN and OUT Endpoints)
  93507. + * Writing to this field sets the Even/Odd
  93508. + * (micro)frame (EO_FrNum) field to even (micro)
  93509. + * frame.
  93510. + */
  93511. + unsigned setd0pid:1;
  93512. + /** Set DATA1 PID (INTR/Bulk IN and OUT endpoints)
  93513. + * Writing to this field sets the Endpoint DPID (DPID)
  93514. + * field in this register to DATA1 Set Odd
  93515. + * (micro)frame (SetOddFr) (ISO IN and OUT Endpoints)
  93516. + * Writing to this field sets the Even/Odd
  93517. + * (micro)frame (EO_FrNum) field to odd (micro) frame.
  93518. + */
  93519. + unsigned setd1pid:1;
  93520. +
  93521. + /** Endpoint Disable */
  93522. + unsigned epdis:1;
  93523. + /** Endpoint Enable */
  93524. + unsigned epena:1;
  93525. + } b;
  93526. +} depctl_data_t;
  93527. +
  93528. +/**
  93529. + * This union represents the bit fields in the Device EP Transfer
  93530. + * Size Register. Read the register into the <i>d32</i> member then
  93531. + * set/clear the bits using the <i>b</i>it elements.
  93532. + */
  93533. +typedef union deptsiz_data {
  93534. + /** raw register data */
  93535. + uint32_t d32;
  93536. + /** register bits */
  93537. + struct {
  93538. + /** Transfer size */
  93539. + unsigned xfersize:19;
  93540. +/** Max packet count for EP (pow(2,10)-1) */
  93541. +#define MAX_PKT_CNT 1023
  93542. + /** Packet Count */
  93543. + unsigned pktcnt:10;
  93544. + /** Multi Count - Periodic IN endpoints */
  93545. + unsigned mc:2;
  93546. + unsigned reserved:1;
  93547. + } b;
  93548. +} deptsiz_data_t;
  93549. +
  93550. +/**
  93551. + * This union represents the bit fields in the Device EP 0 Transfer
  93552. + * Size Register. Read the register into the <i>d32</i> member then
  93553. + * set/clear the bits using the <i>b</i>it elements.
  93554. + */
  93555. +typedef union deptsiz0_data {
  93556. + /** raw register data */
  93557. + uint32_t d32;
  93558. + /** register bits */
  93559. + struct {
  93560. + /** Transfer size */
  93561. + unsigned xfersize:7;
  93562. + /** Reserved */
  93563. + unsigned reserved7_18:12;
  93564. + /** Packet Count */
  93565. + unsigned pktcnt:2;
  93566. + /** Reserved */
  93567. + unsigned reserved21_28:8;
  93568. + /**Setup Packet Count (DOEPTSIZ0 Only) */
  93569. + unsigned supcnt:2;
  93570. + unsigned reserved31;
  93571. + } b;
  93572. +} deptsiz0_data_t;
  93573. +
  93574. +/////////////////////////////////////////////////
  93575. +// DMA Descriptor Specific Structures
  93576. +//
  93577. +
  93578. +/** Buffer status definitions */
  93579. +
  93580. +#define BS_HOST_READY 0x0
  93581. +#define BS_DMA_BUSY 0x1
  93582. +#define BS_DMA_DONE 0x2
  93583. +#define BS_HOST_BUSY 0x3
  93584. +
  93585. +/** Receive/Transmit status definitions */
  93586. +
  93587. +#define RTS_SUCCESS 0x0
  93588. +#define RTS_BUFFLUSH 0x1
  93589. +#define RTS_RESERVED 0x2
  93590. +#define RTS_BUFERR 0x3
  93591. +
  93592. +/**
  93593. + * This union represents the bit fields in the DMA Descriptor
  93594. + * status quadlet. Read the quadlet into the <i>d32</i> member then
  93595. + * set/clear the bits using the <i>b</i>it, <i>b_iso_out</i> and
  93596. + * <i>b_iso_in</i> elements.
  93597. + */
  93598. +typedef union dev_dma_desc_sts {
  93599. + /** raw register data */
  93600. + uint32_t d32;
  93601. + /** quadlet bits */
  93602. + struct {
  93603. + /** Received number of bytes */
  93604. + unsigned bytes:16;
  93605. + /** NAK bit - only for OUT EPs */
  93606. + unsigned nak:1;
  93607. + unsigned reserved17_22:6;
  93608. + /** Multiple Transfer - only for OUT EPs */
  93609. + unsigned mtrf:1;
  93610. + /** Setup Packet received - only for OUT EPs */
  93611. + unsigned sr:1;
  93612. + /** Interrupt On Complete */
  93613. + unsigned ioc:1;
  93614. + /** Short Packet */
  93615. + unsigned sp:1;
  93616. + /** Last */
  93617. + unsigned l:1;
  93618. + /** Receive Status */
  93619. + unsigned sts:2;
  93620. + /** Buffer Status */
  93621. + unsigned bs:2;
  93622. + } b;
  93623. +
  93624. +//#ifdef DWC_EN_ISOC
  93625. + /** iso out quadlet bits */
  93626. + struct {
  93627. + /** Received number of bytes */
  93628. + unsigned rxbytes:11;
  93629. +
  93630. + unsigned reserved11:1;
  93631. + /** Frame Number */
  93632. + unsigned framenum:11;
  93633. + /** Received ISO Data PID */
  93634. + unsigned pid:2;
  93635. + /** Interrupt On Complete */
  93636. + unsigned ioc:1;
  93637. + /** Short Packet */
  93638. + unsigned sp:1;
  93639. + /** Last */
  93640. + unsigned l:1;
  93641. + /** Receive Status */
  93642. + unsigned rxsts:2;
  93643. + /** Buffer Status */
  93644. + unsigned bs:2;
  93645. + } b_iso_out;
  93646. +
  93647. + /** iso in quadlet bits */
  93648. + struct {
  93649. + /** Transmited number of bytes */
  93650. + unsigned txbytes:12;
  93651. + /** Frame Number */
  93652. + unsigned framenum:11;
  93653. + /** Transmited ISO Data PID */
  93654. + unsigned pid:2;
  93655. + /** Interrupt On Complete */
  93656. + unsigned ioc:1;
  93657. + /** Short Packet */
  93658. + unsigned sp:1;
  93659. + /** Last */
  93660. + unsigned l:1;
  93661. + /** Transmit Status */
  93662. + unsigned txsts:2;
  93663. + /** Buffer Status */
  93664. + unsigned bs:2;
  93665. + } b_iso_in;
  93666. +//#endif /* DWC_EN_ISOC */
  93667. +} dev_dma_desc_sts_t;
  93668. +
  93669. +/**
  93670. + * DMA Descriptor structure
  93671. + *
  93672. + * DMA Descriptor structure contains two quadlets:
  93673. + * Status quadlet and Data buffer pointer.
  93674. + */
  93675. +typedef struct dwc_otg_dev_dma_desc {
  93676. + /** DMA Descriptor status quadlet */
  93677. + dev_dma_desc_sts_t status;
  93678. + /** DMA Descriptor data buffer pointer */
  93679. + uint32_t buf;
  93680. +} dwc_otg_dev_dma_desc_t;
  93681. +
  93682. +/**
  93683. + * The dwc_otg_dev_if structure contains information needed to manage
  93684. + * the DWC_otg controller acting in device mode. It represents the
  93685. + * programming view of the device-specific aspects of the controller.
  93686. + */
  93687. +typedef struct dwc_otg_dev_if {
  93688. + /** Pointer to device Global registers.
  93689. + * Device Global Registers starting at offset 800h
  93690. + */
  93691. + dwc_otg_device_global_regs_t *dev_global_regs;
  93692. +#define DWC_DEV_GLOBAL_REG_OFFSET 0x800
  93693. +
  93694. + /**
  93695. + * Device Logical IN Endpoint-Specific Registers 900h-AFCh
  93696. + */
  93697. + dwc_otg_dev_in_ep_regs_t *in_ep_regs[MAX_EPS_CHANNELS];
  93698. +#define DWC_DEV_IN_EP_REG_OFFSET 0x900
  93699. +#define DWC_EP_REG_OFFSET 0x20
  93700. +
  93701. + /** Device Logical OUT Endpoint-Specific Registers B00h-CFCh */
  93702. + dwc_otg_dev_out_ep_regs_t *out_ep_regs[MAX_EPS_CHANNELS];
  93703. +#define DWC_DEV_OUT_EP_REG_OFFSET 0xB00
  93704. +
  93705. + /* Device configuration information */
  93706. + uint8_t speed; /**< Device Speed 0: Unknown, 1: LS, 2:FS, 3: HS */
  93707. + uint8_t num_in_eps; /**< Number # of Tx EP range: 0-15 exept ep0 */
  93708. + uint8_t num_out_eps; /**< Number # of Rx EP range: 0-15 exept ep 0*/
  93709. +
  93710. + /** Size of periodic FIFOs (Bytes) */
  93711. + uint16_t perio_tx_fifo_size[MAX_PERIO_FIFOS];
  93712. +
  93713. + /** Size of Tx FIFOs (Bytes) */
  93714. + uint16_t tx_fifo_size[MAX_TX_FIFOS];
  93715. +
  93716. + /** Thresholding enable flags and length varaiables **/
  93717. + uint16_t rx_thr_en;
  93718. + uint16_t iso_tx_thr_en;
  93719. + uint16_t non_iso_tx_thr_en;
  93720. +
  93721. + uint16_t rx_thr_length;
  93722. + uint16_t tx_thr_length;
  93723. +
  93724. + /**
  93725. + * Pointers to the DMA Descriptors for EP0 Control
  93726. + * transfers (virtual and physical)
  93727. + */
  93728. +
  93729. + /** 2 descriptors for SETUP packets */
  93730. + dwc_dma_t dma_setup_desc_addr[2];
  93731. + dwc_otg_dev_dma_desc_t *setup_desc_addr[2];
  93732. +
  93733. + /** Pointer to Descriptor with latest SETUP packet */
  93734. + dwc_otg_dev_dma_desc_t *psetup;
  93735. +
  93736. + /** Index of current SETUP handler descriptor */
  93737. + uint32_t setup_desc_index;
  93738. +
  93739. + /** Descriptor for Data In or Status In phases */
  93740. + dwc_dma_t dma_in_desc_addr;
  93741. + dwc_otg_dev_dma_desc_t *in_desc_addr;
  93742. +
  93743. + /** Descriptor for Data Out or Status Out phases */
  93744. + dwc_dma_t dma_out_desc_addr;
  93745. + dwc_otg_dev_dma_desc_t *out_desc_addr;
  93746. +
  93747. + /** Setup Packet Detected - if set clear NAK when queueing */
  93748. + uint32_t spd;
  93749. + /** Isoc ep pointer on which incomplete happens */
  93750. + void *isoc_ep;
  93751. +
  93752. +} dwc_otg_dev_if_t;
  93753. +
  93754. +/////////////////////////////////////////////////
  93755. +// Host Mode Register Structures
  93756. +//
  93757. +/**
  93758. + * The Host Global Registers structure defines the size and relative
  93759. + * field offsets for the Host Mode Global Registers. Host Global
  93760. + * Registers offsets 400h-7FFh.
  93761. +*/
  93762. +typedef struct dwc_otg_host_global_regs {
  93763. + /** Host Configuration Register. <i>Offset: 400h</i> */
  93764. + volatile uint32_t hcfg;
  93765. + /** Host Frame Interval Register. <i>Offset: 404h</i> */
  93766. + volatile uint32_t hfir;
  93767. + /** Host Frame Number / Frame Remaining Register. <i>Offset: 408h</i> */
  93768. + volatile uint32_t hfnum;
  93769. + /** Reserved. <i>Offset: 40Ch</i> */
  93770. + uint32_t reserved40C;
  93771. + /** Host Periodic Transmit FIFO/ Queue Status Register. <i>Offset: 410h</i> */
  93772. + volatile uint32_t hptxsts;
  93773. + /** Host All Channels Interrupt Register. <i>Offset: 414h</i> */
  93774. + volatile uint32_t haint;
  93775. + /** Host All Channels Interrupt Mask Register. <i>Offset: 418h</i> */
  93776. + volatile uint32_t haintmsk;
  93777. + /** Host Frame List Base Address Register . <i>Offset: 41Ch</i> */
  93778. + volatile uint32_t hflbaddr;
  93779. +} dwc_otg_host_global_regs_t;
  93780. +
  93781. +/**
  93782. + * This union represents the bit fields in the Host Configuration Register.
  93783. + * Read the register into the <i>d32</i> member then set/clear the bits using
  93784. + * the <i>b</i>it elements. Write the <i>d32</i> member to the hcfg register.
  93785. + */
  93786. +typedef union hcfg_data {
  93787. + /** raw register data */
  93788. + uint32_t d32;
  93789. +
  93790. + /** register bits */
  93791. + struct {
  93792. + /** FS/LS Phy Clock Select */
  93793. + unsigned fslspclksel:2;
  93794. +#define DWC_HCFG_30_60_MHZ 0
  93795. +#define DWC_HCFG_48_MHZ 1
  93796. +#define DWC_HCFG_6_MHZ 2
  93797. +
  93798. + /** FS/LS Only Support */
  93799. + unsigned fslssupp:1;
  93800. + unsigned reserved3_6:4;
  93801. + /** Enable 32-KHz Suspend Mode */
  93802. + unsigned ena32khzs:1;
  93803. + /** Resume Validation Periiod */
  93804. + unsigned resvalid:8;
  93805. + unsigned reserved16_22:7;
  93806. + /** Enable Scatter/gather DMA in Host mode */
  93807. + unsigned descdma:1;
  93808. + /** Frame List Entries */
  93809. + unsigned frlisten:2;
  93810. + /** Enable Periodic Scheduling */
  93811. + unsigned perschedena:1;
  93812. + unsigned reserved27_30:4;
  93813. + unsigned modechtimen:1;
  93814. + } b;
  93815. +} hcfg_data_t;
  93816. +
  93817. +/**
  93818. + * This union represents the bit fields in the Host Frame Remaing/Number
  93819. + * Register.
  93820. + */
  93821. +typedef union hfir_data {
  93822. + /** raw register data */
  93823. + uint32_t d32;
  93824. +
  93825. + /** register bits */
  93826. + struct {
  93827. + unsigned frint:16;
  93828. + unsigned hfirrldctrl:1;
  93829. + unsigned reserved:15;
  93830. + } b;
  93831. +} hfir_data_t;
  93832. +
  93833. +/**
  93834. + * This union represents the bit fields in the Host Frame Remaing/Number
  93835. + * Register.
  93836. + */
  93837. +typedef union hfnum_data {
  93838. + /** raw register data */
  93839. + uint32_t d32;
  93840. +
  93841. + /** register bits */
  93842. + struct {
  93843. + unsigned frnum:16;
  93844. +#define DWC_HFNUM_MAX_FRNUM 0x3FFF
  93845. + unsigned frrem:16;
  93846. + } b;
  93847. +} hfnum_data_t;
  93848. +
  93849. +typedef union hptxsts_data {
  93850. + /** raw register data */
  93851. + uint32_t d32;
  93852. +
  93853. + /** register bits */
  93854. + struct {
  93855. + unsigned ptxfspcavail:16;
  93856. + unsigned ptxqspcavail:8;
  93857. + /** Top of the Periodic Transmit Request Queue
  93858. + * - bit 24 - Terminate (last entry for the selected channel)
  93859. + * - bits 26:25 - Token Type
  93860. + * - 2'b00 - Zero length
  93861. + * - 2'b01 - Ping
  93862. + * - 2'b10 - Disable
  93863. + * - bits 30:27 - Channel Number
  93864. + * - bit 31 - Odd/even microframe
  93865. + */
  93866. + unsigned ptxqtop_terminate:1;
  93867. + unsigned ptxqtop_token:2;
  93868. + unsigned ptxqtop_chnum:4;
  93869. + unsigned ptxqtop_odd:1;
  93870. + } b;
  93871. +} hptxsts_data_t;
  93872. +
  93873. +/**
  93874. + * This union represents the bit fields in the Host Port Control and Status
  93875. + * Register. Read the register into the <i>d32</i> member then set/clear the
  93876. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  93877. + * hprt0 register.
  93878. + */
  93879. +typedef union hprt0_data {
  93880. + /** raw register data */
  93881. + uint32_t d32;
  93882. + /** register bits */
  93883. + struct {
  93884. + unsigned prtconnsts:1;
  93885. + unsigned prtconndet:1;
  93886. + unsigned prtena:1;
  93887. + unsigned prtenchng:1;
  93888. + unsigned prtovrcurract:1;
  93889. + unsigned prtovrcurrchng:1;
  93890. + unsigned prtres:1;
  93891. + unsigned prtsusp:1;
  93892. + unsigned prtrst:1;
  93893. + unsigned reserved9:1;
  93894. + unsigned prtlnsts:2;
  93895. + unsigned prtpwr:1;
  93896. + unsigned prttstctl:4;
  93897. + unsigned prtspd:2;
  93898. +#define DWC_HPRT0_PRTSPD_HIGH_SPEED 0
  93899. +#define DWC_HPRT0_PRTSPD_FULL_SPEED 1
  93900. +#define DWC_HPRT0_PRTSPD_LOW_SPEED 2
  93901. + unsigned reserved19_31:13;
  93902. + } b;
  93903. +} hprt0_data_t;
  93904. +
  93905. +/**
  93906. + * This union represents the bit fields in the Host All Interrupt
  93907. + * Register.
  93908. + */
  93909. +typedef union haint_data {
  93910. + /** raw register data */
  93911. + uint32_t d32;
  93912. + /** register bits */
  93913. + struct {
  93914. + unsigned ch0:1;
  93915. + unsigned ch1:1;
  93916. + unsigned ch2:1;
  93917. + unsigned ch3:1;
  93918. + unsigned ch4:1;
  93919. + unsigned ch5:1;
  93920. + unsigned ch6:1;
  93921. + unsigned ch7:1;
  93922. + unsigned ch8:1;
  93923. + unsigned ch9:1;
  93924. + unsigned ch10:1;
  93925. + unsigned ch11:1;
  93926. + unsigned ch12:1;
  93927. + unsigned ch13:1;
  93928. + unsigned ch14:1;
  93929. + unsigned ch15:1;
  93930. + unsigned reserved:16;
  93931. + } b;
  93932. +
  93933. + struct {
  93934. + unsigned chint:16;
  93935. + unsigned reserved:16;
  93936. + } b2;
  93937. +} haint_data_t;
  93938. +
  93939. +/**
  93940. + * This union represents the bit fields in the Host All Interrupt
  93941. + * Register.
  93942. + */
  93943. +typedef union haintmsk_data {
  93944. + /** raw register data */
  93945. + uint32_t d32;
  93946. + /** register bits */
  93947. + struct {
  93948. + unsigned ch0:1;
  93949. + unsigned ch1:1;
  93950. + unsigned ch2:1;
  93951. + unsigned ch3:1;
  93952. + unsigned ch4:1;
  93953. + unsigned ch5:1;
  93954. + unsigned ch6:1;
  93955. + unsigned ch7:1;
  93956. + unsigned ch8:1;
  93957. + unsigned ch9:1;
  93958. + unsigned ch10:1;
  93959. + unsigned ch11:1;
  93960. + unsigned ch12:1;
  93961. + unsigned ch13:1;
  93962. + unsigned ch14:1;
  93963. + unsigned ch15:1;
  93964. + unsigned reserved:16;
  93965. + } b;
  93966. +
  93967. + struct {
  93968. + unsigned chint:16;
  93969. + unsigned reserved:16;
  93970. + } b2;
  93971. +} haintmsk_data_t;
  93972. +
  93973. +/**
  93974. + * Host Channel Specific Registers. <i>500h-5FCh</i>
  93975. + */
  93976. +typedef struct dwc_otg_hc_regs {
  93977. + /** Host Channel 0 Characteristic Register. <i>Offset: 500h + (chan_num * 20h) + 00h</i> */
  93978. + volatile uint32_t hcchar;
  93979. + /** Host Channel 0 Split Control Register. <i>Offset: 500h + (chan_num * 20h) + 04h</i> */
  93980. + volatile uint32_t hcsplt;
  93981. + /** Host Channel 0 Interrupt Register. <i>Offset: 500h + (chan_num * 20h) + 08h</i> */
  93982. + volatile uint32_t hcint;
  93983. + /** Host Channel 0 Interrupt Mask Register. <i>Offset: 500h + (chan_num * 20h) + 0Ch</i> */
  93984. + volatile uint32_t hcintmsk;
  93985. + /** Host Channel 0 Transfer Size Register. <i>Offset: 500h + (chan_num * 20h) + 10h</i> */
  93986. + volatile uint32_t hctsiz;
  93987. + /** Host Channel 0 DMA Address Register. <i>Offset: 500h + (chan_num * 20h) + 14h</i> */
  93988. + volatile uint32_t hcdma;
  93989. + volatile uint32_t reserved;
  93990. + /** Host Channel 0 DMA Buffer Address Register. <i>Offset: 500h + (chan_num * 20h) + 1Ch</i> */
  93991. + volatile uint32_t hcdmab;
  93992. +} dwc_otg_hc_regs_t;
  93993. +
  93994. +/**
  93995. + * This union represents the bit fields in the Host Channel Characteristics
  93996. + * Register. Read the register into the <i>d32</i> member then set/clear the
  93997. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  93998. + * hcchar register.
  93999. + */
  94000. +typedef union hcchar_data {
  94001. + /** raw register data */
  94002. + uint32_t d32;
  94003. +
  94004. + /** register bits */
  94005. + struct {
  94006. + /** Maximum packet size in bytes */
  94007. + unsigned mps:11;
  94008. +
  94009. + /** Endpoint number */
  94010. + unsigned epnum:4;
  94011. +
  94012. + /** 0: OUT, 1: IN */
  94013. + unsigned epdir:1;
  94014. +
  94015. + unsigned reserved:1;
  94016. +
  94017. + /** 0: Full/high speed device, 1: Low speed device */
  94018. + unsigned lspddev:1;
  94019. +
  94020. + /** 0: Control, 1: Isoc, 2: Bulk, 3: Intr */
  94021. + unsigned eptype:2;
  94022. +
  94023. + /** Packets per frame for periodic transfers. 0 is reserved. */
  94024. + unsigned multicnt:2;
  94025. +
  94026. + /** Device address */
  94027. + unsigned devaddr:7;
  94028. +
  94029. + /**
  94030. + * Frame to transmit periodic transaction.
  94031. + * 0: even, 1: odd
  94032. + */
  94033. + unsigned oddfrm:1;
  94034. +
  94035. + /** Channel disable */
  94036. + unsigned chdis:1;
  94037. +
  94038. + /** Channel enable */
  94039. + unsigned chen:1;
  94040. + } b;
  94041. +} hcchar_data_t;
  94042. +
  94043. +typedef union hcsplt_data {
  94044. + /** raw register data */
  94045. + uint32_t d32;
  94046. +
  94047. + /** register bits */
  94048. + struct {
  94049. + /** Port Address */
  94050. + unsigned prtaddr:7;
  94051. +
  94052. + /** Hub Address */
  94053. + unsigned hubaddr:7;
  94054. +
  94055. + /** Transaction Position */
  94056. + unsigned xactpos:2;
  94057. +#define DWC_HCSPLIT_XACTPOS_MID 0
  94058. +#define DWC_HCSPLIT_XACTPOS_END 1
  94059. +#define DWC_HCSPLIT_XACTPOS_BEGIN 2
  94060. +#define DWC_HCSPLIT_XACTPOS_ALL 3
  94061. +
  94062. + /** Do Complete Split */
  94063. + unsigned compsplt:1;
  94064. +
  94065. + /** Reserved */
  94066. + unsigned reserved:14;
  94067. +
  94068. + /** Split Enble */
  94069. + unsigned spltena:1;
  94070. + } b;
  94071. +} hcsplt_data_t;
  94072. +
  94073. +/**
  94074. + * This union represents the bit fields in the Host All Interrupt
  94075. + * Register.
  94076. + */
  94077. +typedef union hcint_data {
  94078. + /** raw register data */
  94079. + uint32_t d32;
  94080. + /** register bits */
  94081. + struct {
  94082. + /** Transfer Complete */
  94083. + unsigned xfercomp:1;
  94084. + /** Channel Halted */
  94085. + unsigned chhltd:1;
  94086. + /** AHB Error */
  94087. + unsigned ahberr:1;
  94088. + /** STALL Response Received */
  94089. + unsigned stall:1;
  94090. + /** NAK Response Received */
  94091. + unsigned nak:1;
  94092. + /** ACK Response Received */
  94093. + unsigned ack:1;
  94094. + /** NYET Response Received */
  94095. + unsigned nyet:1;
  94096. + /** Transaction Err */
  94097. + unsigned xacterr:1;
  94098. + /** Babble Error */
  94099. + unsigned bblerr:1;
  94100. + /** Frame Overrun */
  94101. + unsigned frmovrun:1;
  94102. + /** Data Toggle Error */
  94103. + unsigned datatglerr:1;
  94104. + /** Buffer Not Available (only for DDMA mode) */
  94105. + unsigned bna:1;
  94106. + /** Exessive transaction error (only for DDMA mode) */
  94107. + unsigned xcs_xact:1;
  94108. + /** Frame List Rollover interrupt */
  94109. + unsigned frm_list_roll:1;
  94110. + /** Reserved */
  94111. + unsigned reserved14_31:18;
  94112. + } b;
  94113. +} hcint_data_t;
  94114. +
  94115. +/**
  94116. + * This union represents the bit fields in the Host Channel Interrupt Mask
  94117. + * Register. Read the register into the <i>d32</i> member then set/clear the
  94118. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  94119. + * hcintmsk register.
  94120. + */
  94121. +typedef union hcintmsk_data {
  94122. + /** raw register data */
  94123. + uint32_t d32;
  94124. +
  94125. + /** register bits */
  94126. + struct {
  94127. + unsigned xfercompl:1;
  94128. + unsigned chhltd:1;
  94129. + unsigned ahberr:1;
  94130. + unsigned stall:1;
  94131. + unsigned nak:1;
  94132. + unsigned ack:1;
  94133. + unsigned nyet:1;
  94134. + unsigned xacterr:1;
  94135. + unsigned bblerr:1;
  94136. + unsigned frmovrun:1;
  94137. + unsigned datatglerr:1;
  94138. + unsigned bna:1;
  94139. + unsigned xcs_xact:1;
  94140. + unsigned frm_list_roll:1;
  94141. + unsigned reserved14_31:18;
  94142. + } b;
  94143. +} hcintmsk_data_t;
  94144. +
  94145. +/**
  94146. + * This union represents the bit fields in the Host Channel Transfer Size
  94147. + * Register. Read the register into the <i>d32</i> member then set/clear the
  94148. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  94149. + * hcchar register.
  94150. + */
  94151. +
  94152. +typedef union hctsiz_data {
  94153. + /** raw register data */
  94154. + uint32_t d32;
  94155. +
  94156. + /** register bits */
  94157. + struct {
  94158. + /** Total transfer size in bytes */
  94159. + unsigned xfersize:19;
  94160. +
  94161. + /** Data packets to transfer */
  94162. + unsigned pktcnt:10;
  94163. +
  94164. + /**
  94165. + * Packet ID for next data packet
  94166. + * 0: DATA0
  94167. + * 1: DATA2
  94168. + * 2: DATA1
  94169. + * 3: MDATA (non-Control), SETUP (Control)
  94170. + */
  94171. + unsigned pid:2;
  94172. +#define DWC_HCTSIZ_DATA0 0
  94173. +#define DWC_HCTSIZ_DATA1 2
  94174. +#define DWC_HCTSIZ_DATA2 1
  94175. +#define DWC_HCTSIZ_MDATA 3
  94176. +#define DWC_HCTSIZ_SETUP 3
  94177. +
  94178. + /** Do PING protocol when 1 */
  94179. + unsigned dopng:1;
  94180. + } b;
  94181. +
  94182. + /** register bits */
  94183. + struct {
  94184. + /** Scheduling information */
  94185. + unsigned schinfo:8;
  94186. +
  94187. + /** Number of transfer descriptors.
  94188. + * Max value:
  94189. + * 64 in general,
  94190. + * 256 only for HS isochronous endpoint.
  94191. + */
  94192. + unsigned ntd:8;
  94193. +
  94194. + /** Data packets to transfer */
  94195. + unsigned reserved16_28:13;
  94196. +
  94197. + /**
  94198. + * Packet ID for next data packet
  94199. + * 0: DATA0
  94200. + * 1: DATA2
  94201. + * 2: DATA1
  94202. + * 3: MDATA (non-Control)
  94203. + */
  94204. + unsigned pid:2;
  94205. +
  94206. + /** Do PING protocol when 1 */
  94207. + unsigned dopng:1;
  94208. + } b_ddma;
  94209. +} hctsiz_data_t;
  94210. +
  94211. +/**
  94212. + * This union represents the bit fields in the Host DMA Address
  94213. + * Register used in Descriptor DMA mode.
  94214. + */
  94215. +typedef union hcdma_data {
  94216. + /** raw register data */
  94217. + uint32_t d32;
  94218. + /** register bits */
  94219. + struct {
  94220. + unsigned reserved0_2:3;
  94221. + /** Current Transfer Descriptor. Not used for ISOC */
  94222. + unsigned ctd:8;
  94223. + /** Start Address of Descriptor List */
  94224. + unsigned dma_addr:21;
  94225. + } b;
  94226. +} hcdma_data_t;
  94227. +
  94228. +/**
  94229. + * This union represents the bit fields in the DMA Descriptor
  94230. + * status quadlet for host mode. Read the quadlet into the <i>d32</i> member then
  94231. + * set/clear the bits using the <i>b</i>it elements.
  94232. + */
  94233. +typedef union host_dma_desc_sts {
  94234. + /** raw register data */
  94235. + uint32_t d32;
  94236. + /** quadlet bits */
  94237. +
  94238. + /* for non-isochronous */
  94239. + struct {
  94240. + /** Number of bytes */
  94241. + unsigned n_bytes:17;
  94242. + /** QTD offset to jump when Short Packet received - only for IN EPs */
  94243. + unsigned qtd_offset:6;
  94244. + /**
  94245. + * Set to request the core to jump to alternate QTD if
  94246. + * Short Packet received - only for IN EPs
  94247. + */
  94248. + unsigned a_qtd:1;
  94249. + /**
  94250. + * Setup Packet bit. When set indicates that buffer contains
  94251. + * setup packet.
  94252. + */
  94253. + unsigned sup:1;
  94254. + /** Interrupt On Complete */
  94255. + unsigned ioc:1;
  94256. + /** End of List */
  94257. + unsigned eol:1;
  94258. + unsigned reserved27:1;
  94259. + /** Rx/Tx Status */
  94260. + unsigned sts:2;
  94261. +#define DMA_DESC_STS_PKTERR 1
  94262. + unsigned reserved30:1;
  94263. + /** Active Bit */
  94264. + unsigned a:1;
  94265. + } b;
  94266. + /* for isochronous */
  94267. + struct {
  94268. + /** Number of bytes */
  94269. + unsigned n_bytes:12;
  94270. + unsigned reserved12_24:13;
  94271. + /** Interrupt On Complete */
  94272. + unsigned ioc:1;
  94273. + unsigned reserved26_27:2;
  94274. + /** Rx/Tx Status */
  94275. + unsigned sts:2;
  94276. + unsigned reserved30:1;
  94277. + /** Active Bit */
  94278. + unsigned a:1;
  94279. + } b_isoc;
  94280. +} host_dma_desc_sts_t;
  94281. +
  94282. +#define MAX_DMA_DESC_SIZE 131071
  94283. +#define MAX_DMA_DESC_NUM_GENERIC 64
  94284. +#define MAX_DMA_DESC_NUM_HS_ISOC 256
  94285. +#define MAX_FRLIST_EN_NUM 64
  94286. +/**
  94287. + * Host-mode DMA Descriptor structure
  94288. + *
  94289. + * DMA Descriptor structure contains two quadlets:
  94290. + * Status quadlet and Data buffer pointer.
  94291. + */
  94292. +typedef struct dwc_otg_host_dma_desc {
  94293. + /** DMA Descriptor status quadlet */
  94294. + host_dma_desc_sts_t status;
  94295. + /** DMA Descriptor data buffer pointer */
  94296. + uint32_t buf;
  94297. +} dwc_otg_host_dma_desc_t;
  94298. +
  94299. +/** OTG Host Interface Structure.
  94300. + *
  94301. + * The OTG Host Interface Structure structure contains information
  94302. + * needed to manage the DWC_otg controller acting in host mode. It
  94303. + * represents the programming view of the host-specific aspects of the
  94304. + * controller.
  94305. + */
  94306. +typedef struct dwc_otg_host_if {
  94307. + /** Host Global Registers starting at offset 400h.*/
  94308. + dwc_otg_host_global_regs_t *host_global_regs;
  94309. +#define DWC_OTG_HOST_GLOBAL_REG_OFFSET 0x400
  94310. +
  94311. + /** Host Port 0 Control and Status Register */
  94312. + volatile uint32_t *hprt0;
  94313. +#define DWC_OTG_HOST_PORT_REGS_OFFSET 0x440
  94314. +
  94315. + /** Host Channel Specific Registers at offsets 500h-5FCh. */
  94316. + dwc_otg_hc_regs_t *hc_regs[MAX_EPS_CHANNELS];
  94317. +#define DWC_OTG_HOST_CHAN_REGS_OFFSET 0x500
  94318. +#define DWC_OTG_CHAN_REGS_OFFSET 0x20
  94319. +
  94320. + /* Host configuration information */
  94321. + /** Number of Host Channels (range: 1-16) */
  94322. + uint8_t num_host_channels;
  94323. + /** Periodic EPs supported (0: no, 1: yes) */
  94324. + uint8_t perio_eps_supported;
  94325. + /** Periodic Tx FIFO Size (Only 1 host periodic Tx FIFO) */
  94326. + uint16_t perio_tx_fifo_size;
  94327. +
  94328. +} dwc_otg_host_if_t;
  94329. +
  94330. +/**
  94331. + * This union represents the bit fields in the Power and Clock Gating Control
  94332. + * Register. Read the register into the <i>d32</i> member then set/clear the
  94333. + * bits using the <i>b</i>it elements.
  94334. + */
  94335. +typedef union pcgcctl_data {
  94336. + /** raw register data */
  94337. + uint32_t d32;
  94338. +
  94339. + /** register bits */
  94340. + struct {
  94341. + /** Stop Pclk */
  94342. + unsigned stoppclk:1;
  94343. + /** Gate Hclk */
  94344. + unsigned gatehclk:1;
  94345. + /** Power Clamp */
  94346. + unsigned pwrclmp:1;
  94347. + /** Reset Power Down Modules */
  94348. + unsigned rstpdwnmodule:1;
  94349. + /** Reserved */
  94350. + unsigned reserved:1;
  94351. + /** Enable Sleep Clock Gating (Enbl_L1Gating) */
  94352. + unsigned enbl_sleep_gating:1;
  94353. + /** PHY In Sleep (PhySleep) */
  94354. + unsigned phy_in_sleep:1;
  94355. + /** Deep Sleep*/
  94356. + unsigned deep_sleep:1;
  94357. + unsigned resetaftsusp:1;
  94358. + unsigned restoremode:1;
  94359. + unsigned enbl_extnd_hiber:1;
  94360. + unsigned extnd_hiber_pwrclmp:1;
  94361. + unsigned extnd_hiber_switch:1;
  94362. + unsigned ess_reg_restored:1;
  94363. + unsigned prt_clk_sel:2;
  94364. + unsigned port_power:1;
  94365. + unsigned max_xcvrselect:2;
  94366. + unsigned max_termsel:1;
  94367. + unsigned mac_dev_addr:7;
  94368. + unsigned p2hd_dev_enum_spd:2;
  94369. + unsigned p2hd_prt_spd:2;
  94370. + unsigned if_dev_mode:1;
  94371. + } b;
  94372. +} pcgcctl_data_t;
  94373. +
  94374. +/**
  94375. + * This union represents the bit fields in the Global Data FIFO Software
  94376. + * Configuration Register. Read the register into the <i>d32</i> member then
  94377. + * set/clear the bits using the <i>b</i>it elements.
  94378. + */
  94379. +typedef union gdfifocfg_data {
  94380. + /* raw register data */
  94381. + uint32_t d32;
  94382. + /** register bits */
  94383. + struct {
  94384. + /** OTG Data FIFO depth */
  94385. + unsigned gdfifocfg:16;
  94386. + /** Start address of EP info controller */
  94387. + unsigned epinfobase:16;
  94388. + } b;
  94389. +} gdfifocfg_data_t;
  94390. +
  94391. +/**
  94392. + * This union represents the bit fields in the Global Power Down Register
  94393. + * Register. Read the register into the <i>d32</i> member then set/clear the
  94394. + * bits using the <i>b</i>it elements.
  94395. + */
  94396. +typedef union gpwrdn_data {
  94397. + /* raw register data */
  94398. + uint32_t d32;
  94399. +
  94400. + /** register bits */
  94401. + struct {
  94402. + /** PMU Interrupt Select */
  94403. + unsigned pmuintsel:1;
  94404. + /** PMU Active */
  94405. + unsigned pmuactv:1;
  94406. + /** Restore */
  94407. + unsigned restore:1;
  94408. + /** Power Down Clamp */
  94409. + unsigned pwrdnclmp:1;
  94410. + /** Power Down Reset */
  94411. + unsigned pwrdnrstn:1;
  94412. + /** Power Down Switch */
  94413. + unsigned pwrdnswtch:1;
  94414. + /** Disable VBUS */
  94415. + unsigned dis_vbus:1;
  94416. + /** Line State Change */
  94417. + unsigned lnstschng:1;
  94418. + /** Line state change mask */
  94419. + unsigned lnstchng_msk:1;
  94420. + /** Reset Detected */
  94421. + unsigned rst_det:1;
  94422. + /** Reset Detect mask */
  94423. + unsigned rst_det_msk:1;
  94424. + /** Disconnect Detected */
  94425. + unsigned disconn_det:1;
  94426. + /** Disconnect Detect mask */
  94427. + unsigned disconn_det_msk:1;
  94428. + /** Connect Detected*/
  94429. + unsigned connect_det:1;
  94430. + /** Connect Detected Mask*/
  94431. + unsigned connect_det_msk:1;
  94432. + /** SRP Detected */
  94433. + unsigned srp_det:1;
  94434. + /** SRP Detect mask */
  94435. + unsigned srp_det_msk:1;
  94436. + /** Status Change Interrupt */
  94437. + unsigned sts_chngint:1;
  94438. + /** Status Change Interrupt Mask */
  94439. + unsigned sts_chngint_msk:1;
  94440. + /** Line State */
  94441. + unsigned linestate:2;
  94442. + /** Indicates current mode(status of IDDIG signal) */
  94443. + unsigned idsts:1;
  94444. + /** B Session Valid signal status*/
  94445. + unsigned bsessvld:1;
  94446. + /** ADP Event Detected */
  94447. + unsigned adp_int:1;
  94448. + /** Multi Valued ID pin */
  94449. + unsigned mult_val_id_bc:5;
  94450. + /** Reserved 24_31 */
  94451. + unsigned reserved29_31:3;
  94452. + } b;
  94453. +} gpwrdn_data_t;
  94454. +
  94455. +#endif
  94456. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_otg/Makefile linux-3.12.26/drivers/usb/host/dwc_otg/Makefile
  94457. --- linux-3.12.26.orig/drivers/usb/host/dwc_otg/Makefile 1970-01-01 01:00:00.000000000 +0100
  94458. +++ linux-3.12.26/drivers/usb/host/dwc_otg/Makefile 2014-08-06 16:50:14.865965229 +0200
  94459. @@ -0,0 +1,82 @@
  94460. +#
  94461. +# Makefile for DWC_otg Highspeed USB controller driver
  94462. +#
  94463. +
  94464. +ifneq ($(KERNELRELEASE),)
  94465. +
  94466. +# Use the BUS_INTERFACE variable to compile the software for either
  94467. +# PCI(PCI_INTERFACE) or LM(LM_INTERFACE) bus.
  94468. +ifeq ($(BUS_INTERFACE),)
  94469. +# BUS_INTERFACE = -DPCI_INTERFACE
  94470. +# BUS_INTERFACE = -DLM_INTERFACE
  94471. + BUS_INTERFACE = -DPLATFORM_INTERFACE
  94472. +endif
  94473. +
  94474. +#ccflags-y += -DDEBUG
  94475. +#ccflags-y += -DDWC_OTG_DEBUGLEV=1 # reduce common debug msgs
  94476. +
  94477. +# Use one of the following flags to compile the software in host-only or
  94478. +# device-only mode.
  94479. +#ccflags-y += -DDWC_HOST_ONLY
  94480. +#ccflags-y += -DDWC_DEVICE_ONLY
  94481. +
  94482. +ccflags-y += -Dlinux -DDWC_HS_ELECT_TST
  94483. +#ccflags-y += -DDWC_EN_ISOC
  94484. +ccflags-y += -I$(obj)/../dwc_common_port
  94485. +#ccflags-y += -I$(PORTLIB)
  94486. +ccflags-y += -DDWC_LINUX
  94487. +ccflags-y += $(CFI)
  94488. +ccflags-y += $(BUS_INTERFACE)
  94489. +#ccflags-y += -DDWC_DEV_SRPCAP
  94490. +
  94491. +obj-$(CONFIG_USB_DWCOTG) += dwc_otg.o
  94492. +
  94493. +dwc_otg-objs := dwc_otg_driver.o dwc_otg_attr.o
  94494. +dwc_otg-objs += dwc_otg_cil.o dwc_otg_cil_intr.o
  94495. +dwc_otg-objs += dwc_otg_pcd_linux.o dwc_otg_pcd.o dwc_otg_pcd_intr.o
  94496. +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
  94497. +dwc_otg-objs += dwc_otg_adp.o
  94498. +dwc_otg-objs += dwc_otg_fiq_fsm.o
  94499. +dwc_otg-objs += dwc_otg_fiq_stub.o
  94500. +ifneq ($(CFI),)
  94501. +dwc_otg-objs += dwc_otg_cfi.o
  94502. +endif
  94503. +
  94504. +kernrelwd := $(subst ., ,$(KERNELRELEASE))
  94505. +kernrel3 := $(word 1,$(kernrelwd)).$(word 2,$(kernrelwd)).$(word 3,$(kernrelwd))
  94506. +
  94507. +ifneq ($(kernrel3),2.6.20)
  94508. +ccflags-y += $(CPPFLAGS)
  94509. +endif
  94510. +
  94511. +else
  94512. +
  94513. +PWD := $(shell pwd)
  94514. +PORTLIB := $(PWD)/../dwc_common_port
  94515. +
  94516. +# Command paths
  94517. +CTAGS := $(CTAGS)
  94518. +DOXYGEN := $(DOXYGEN)
  94519. +
  94520. +default: portlib
  94521. + $(MAKE) -C$(KDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  94522. +
  94523. +install: default
  94524. + $(MAKE) -C$(KDIR) M=$(PORTLIB) modules_install
  94525. + $(MAKE) -C$(KDIR) M=$(PWD) modules_install
  94526. +
  94527. +portlib:
  94528. + $(MAKE) -C$(KDIR) M=$(PORTLIB) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  94529. + cp $(PORTLIB)/Module.symvers $(PWD)/
  94530. +
  94531. +docs: $(wildcard *.[hc]) doc/doxygen.cfg
  94532. + $(DOXYGEN) doc/doxygen.cfg
  94533. +
  94534. +tags: $(wildcard *.[hc])
  94535. + $(CTAGS) -e $(wildcard *.[hc]) $(wildcard linux/*.[hc]) $(wildcard $(KDIR)/include/linux/usb*.h)
  94536. +
  94537. +
  94538. +clean:
  94539. + rm -rf *.o *.ko .*cmd *.mod.c .tmp_versions Module.symvers
  94540. +
  94541. +endif
  94542. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm linux-3.12.26/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm
  94543. --- linux-3.12.26.orig/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm 1970-01-01 01:00:00.000000000 +0100
  94544. +++ linux-3.12.26/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm 2014-08-06 16:50:14.893965449 +0200
  94545. @@ -0,0 +1,337 @@
  94546. +package dwc_otg_test;
  94547. +
  94548. +use strict;
  94549. +use Exporter ();
  94550. +
  94551. +use vars qw(@ISA @EXPORT
  94552. +$sysfsdir $paramdir $errors $params
  94553. +);
  94554. +
  94555. +@ISA = qw(Exporter);
  94556. +
  94557. +#
  94558. +# Globals
  94559. +#
  94560. +$sysfsdir = "/sys/devices/lm0";
  94561. +$paramdir = "/sys/module/dwc_otg";
  94562. +$errors = 0;
  94563. +
  94564. +$params = [
  94565. + {
  94566. + NAME => "otg_cap",
  94567. + DEFAULT => 0,
  94568. + ENUM => [],
  94569. + LOW => 0,
  94570. + HIGH => 2
  94571. + },
  94572. + {
  94573. + NAME => "dma_enable",
  94574. + DEFAULT => 0,
  94575. + ENUM => [],
  94576. + LOW => 0,
  94577. + HIGH => 1
  94578. + },
  94579. + {
  94580. + NAME => "dma_burst_size",
  94581. + DEFAULT => 32,
  94582. + ENUM => [1, 4, 8, 16, 32, 64, 128, 256],
  94583. + LOW => 1,
  94584. + HIGH => 256
  94585. + },
  94586. + {
  94587. + NAME => "host_speed",
  94588. + DEFAULT => 0,
  94589. + ENUM => [],
  94590. + LOW => 0,
  94591. + HIGH => 1
  94592. + },
  94593. + {
  94594. + NAME => "host_support_fs_ls_low_power",
  94595. + DEFAULT => 0,
  94596. + ENUM => [],
  94597. + LOW => 0,
  94598. + HIGH => 1
  94599. + },
  94600. + {
  94601. + NAME => "host_ls_low_power_phy_clk",
  94602. + DEFAULT => 0,
  94603. + ENUM => [],
  94604. + LOW => 0,
  94605. + HIGH => 1
  94606. + },
  94607. + {
  94608. + NAME => "dev_speed",
  94609. + DEFAULT => 0,
  94610. + ENUM => [],
  94611. + LOW => 0,
  94612. + HIGH => 1
  94613. + },
  94614. + {
  94615. + NAME => "enable_dynamic_fifo",
  94616. + DEFAULT => 1,
  94617. + ENUM => [],
  94618. + LOW => 0,
  94619. + HIGH => 1
  94620. + },
  94621. + {
  94622. + NAME => "data_fifo_size",
  94623. + DEFAULT => 8192,
  94624. + ENUM => [],
  94625. + LOW => 32,
  94626. + HIGH => 32768
  94627. + },
  94628. + {
  94629. + NAME => "dev_rx_fifo_size",
  94630. + DEFAULT => 1064,
  94631. + ENUM => [],
  94632. + LOW => 16,
  94633. + HIGH => 32768
  94634. + },
  94635. + {
  94636. + NAME => "dev_nperio_tx_fifo_size",
  94637. + DEFAULT => 1024,
  94638. + ENUM => [],
  94639. + LOW => 16,
  94640. + HIGH => 32768
  94641. + },
  94642. + {
  94643. + NAME => "dev_perio_tx_fifo_size_1",
  94644. + DEFAULT => 256,
  94645. + ENUM => [],
  94646. + LOW => 4,
  94647. + HIGH => 768
  94648. + },
  94649. + {
  94650. + NAME => "dev_perio_tx_fifo_size_2",
  94651. + DEFAULT => 256,
  94652. + ENUM => [],
  94653. + LOW => 4,
  94654. + HIGH => 768
  94655. + },
  94656. + {
  94657. + NAME => "dev_perio_tx_fifo_size_3",
  94658. + DEFAULT => 256,
  94659. + ENUM => [],
  94660. + LOW => 4,
  94661. + HIGH => 768
  94662. + },
  94663. + {
  94664. + NAME => "dev_perio_tx_fifo_size_4",
  94665. + DEFAULT => 256,
  94666. + ENUM => [],
  94667. + LOW => 4,
  94668. + HIGH => 768
  94669. + },
  94670. + {
  94671. + NAME => "dev_perio_tx_fifo_size_5",
  94672. + DEFAULT => 256,
  94673. + ENUM => [],
  94674. + LOW => 4,
  94675. + HIGH => 768
  94676. + },
  94677. + {
  94678. + NAME => "dev_perio_tx_fifo_size_6",
  94679. + DEFAULT => 256,
  94680. + ENUM => [],
  94681. + LOW => 4,
  94682. + HIGH => 768
  94683. + },
  94684. + {
  94685. + NAME => "dev_perio_tx_fifo_size_7",
  94686. + DEFAULT => 256,
  94687. + ENUM => [],
  94688. + LOW => 4,
  94689. + HIGH => 768
  94690. + },
  94691. + {
  94692. + NAME => "dev_perio_tx_fifo_size_8",
  94693. + DEFAULT => 256,
  94694. + ENUM => [],
  94695. + LOW => 4,
  94696. + HIGH => 768
  94697. + },
  94698. + {
  94699. + NAME => "dev_perio_tx_fifo_size_9",
  94700. + DEFAULT => 256,
  94701. + ENUM => [],
  94702. + LOW => 4,
  94703. + HIGH => 768
  94704. + },
  94705. + {
  94706. + NAME => "dev_perio_tx_fifo_size_10",
  94707. + DEFAULT => 256,
  94708. + ENUM => [],
  94709. + LOW => 4,
  94710. + HIGH => 768
  94711. + },
  94712. + {
  94713. + NAME => "dev_perio_tx_fifo_size_11",
  94714. + DEFAULT => 256,
  94715. + ENUM => [],
  94716. + LOW => 4,
  94717. + HIGH => 768
  94718. + },
  94719. + {
  94720. + NAME => "dev_perio_tx_fifo_size_12",
  94721. + DEFAULT => 256,
  94722. + ENUM => [],
  94723. + LOW => 4,
  94724. + HIGH => 768
  94725. + },
  94726. + {
  94727. + NAME => "dev_perio_tx_fifo_size_13",
  94728. + DEFAULT => 256,
  94729. + ENUM => [],
  94730. + LOW => 4,
  94731. + HIGH => 768
  94732. + },
  94733. + {
  94734. + NAME => "dev_perio_tx_fifo_size_14",
  94735. + DEFAULT => 256,
  94736. + ENUM => [],
  94737. + LOW => 4,
  94738. + HIGH => 768
  94739. + },
  94740. + {
  94741. + NAME => "dev_perio_tx_fifo_size_15",
  94742. + DEFAULT => 256,
  94743. + ENUM => [],
  94744. + LOW => 4,
  94745. + HIGH => 768
  94746. + },
  94747. + {
  94748. + NAME => "host_rx_fifo_size",
  94749. + DEFAULT => 1024,
  94750. + ENUM => [],
  94751. + LOW => 16,
  94752. + HIGH => 32768
  94753. + },
  94754. + {
  94755. + NAME => "host_nperio_tx_fifo_size",
  94756. + DEFAULT => 1024,
  94757. + ENUM => [],
  94758. + LOW => 16,
  94759. + HIGH => 32768
  94760. + },
  94761. + {
  94762. + NAME => "host_perio_tx_fifo_size",
  94763. + DEFAULT => 1024,
  94764. + ENUM => [],
  94765. + LOW => 16,
  94766. + HIGH => 32768
  94767. + },
  94768. + {
  94769. + NAME => "max_transfer_size",
  94770. + DEFAULT => 65535,
  94771. + ENUM => [],
  94772. + LOW => 2047,
  94773. + HIGH => 65535
  94774. + },
  94775. + {
  94776. + NAME => "max_packet_count",
  94777. + DEFAULT => 511,
  94778. + ENUM => [],
  94779. + LOW => 15,
  94780. + HIGH => 511
  94781. + },
  94782. + {
  94783. + NAME => "host_channels",
  94784. + DEFAULT => 12,
  94785. + ENUM => [],
  94786. + LOW => 1,
  94787. + HIGH => 16
  94788. + },
  94789. + {
  94790. + NAME => "dev_endpoints",
  94791. + DEFAULT => 6,
  94792. + ENUM => [],
  94793. + LOW => 1,
  94794. + HIGH => 15
  94795. + },
  94796. + {
  94797. + NAME => "phy_type",
  94798. + DEFAULT => 1,
  94799. + ENUM => [],
  94800. + LOW => 0,
  94801. + HIGH => 2
  94802. + },
  94803. + {
  94804. + NAME => "phy_utmi_width",
  94805. + DEFAULT => 16,
  94806. + ENUM => [8, 16],
  94807. + LOW => 8,
  94808. + HIGH => 16
  94809. + },
  94810. + {
  94811. + NAME => "phy_ulpi_ddr",
  94812. + DEFAULT => 0,
  94813. + ENUM => [],
  94814. + LOW => 0,
  94815. + HIGH => 1
  94816. + },
  94817. + ];
  94818. +
  94819. +
  94820. +#
  94821. +#
  94822. +sub check_arch {
  94823. + $_ = `uname -m`;
  94824. + chomp;
  94825. + unless (m/armv4tl/) {
  94826. + warn "# \n# Can't execute on $_. Run on integrator platform.\n# \n";
  94827. + return 0;
  94828. + }
  94829. + return 1;
  94830. +}
  94831. +
  94832. +#
  94833. +#
  94834. +sub load_module {
  94835. + my $params = shift;
  94836. + print "\nRemoving Module\n";
  94837. + system "rmmod dwc_otg";
  94838. + print "Loading Module\n";
  94839. + if ($params ne "") {
  94840. + print "Module Parameters: $params\n";
  94841. + }
  94842. + if (system("modprobe dwc_otg $params")) {
  94843. + warn "Unable to load module\n";
  94844. + return 0;
  94845. + }
  94846. + return 1;
  94847. +}
  94848. +
  94849. +#
  94850. +#
  94851. +sub test_status {
  94852. + my $arg = shift;
  94853. +
  94854. + print "\n";
  94855. +
  94856. + if (defined $arg) {
  94857. + warn "WARNING: $arg\n";
  94858. + }
  94859. +
  94860. + if ($errors > 0) {
  94861. + warn "TEST FAILED with $errors errors\n";
  94862. + return 0;
  94863. + } else {
  94864. + print "TEST PASSED\n";
  94865. + return 0 if (defined $arg);
  94866. + }
  94867. + return 1;
  94868. +}
  94869. +
  94870. +#
  94871. +#
  94872. +@EXPORT = qw(
  94873. +$sysfsdir
  94874. +$paramdir
  94875. +$params
  94876. +$errors
  94877. +check_arch
  94878. +load_module
  94879. +test_status
  94880. +);
  94881. +
  94882. +1;
  94883. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_otg/test/Makefile linux-3.12.26/drivers/usb/host/dwc_otg/test/Makefile
  94884. --- linux-3.12.26.orig/drivers/usb/host/dwc_otg/test/Makefile 1970-01-01 01:00:00.000000000 +0100
  94885. +++ linux-3.12.26/drivers/usb/host/dwc_otg/test/Makefile 2014-08-06 16:50:14.893965449 +0200
  94886. @@ -0,0 +1,16 @@
  94887. +
  94888. +PERL=/usr/bin/perl
  94889. +PL_TESTS=test_sysfs.pl test_mod_param.pl
  94890. +
  94891. +.PHONY : test
  94892. +test : perl_tests
  94893. +
  94894. +perl_tests :
  94895. + @echo
  94896. + @echo Running perl tests
  94897. + @for test in $(PL_TESTS); do \
  94898. + if $(PERL) ./$$test ; then \
  94899. + echo "=======> $$test, PASSED" ; \
  94900. + else echo "=======> $$test, FAILED" ; \
  94901. + fi \
  94902. + done
  94903. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_otg/test/test_mod_param.pl linux-3.12.26/drivers/usb/host/dwc_otg/test/test_mod_param.pl
  94904. --- linux-3.12.26.orig/drivers/usb/host/dwc_otg/test/test_mod_param.pl 1970-01-01 01:00:00.000000000 +0100
  94905. +++ linux-3.12.26/drivers/usb/host/dwc_otg/test/test_mod_param.pl 2014-08-06 16:50:14.893965449 +0200
  94906. @@ -0,0 +1,133 @@
  94907. +#!/usr/bin/perl -w
  94908. +#
  94909. +# Run this program on the integrator.
  94910. +#
  94911. +# - Tests module parameter default values.
  94912. +# - Tests setting of valid module parameter values via modprobe.
  94913. +# - Tests invalid module parameter values.
  94914. +# -----------------------------------------------------------------------------
  94915. +use strict;
  94916. +use dwc_otg_test;
  94917. +
  94918. +check_arch() or die;
  94919. +
  94920. +#
  94921. +#
  94922. +sub test {
  94923. + my ($param,$expected) = @_;
  94924. + my $value = get($param);
  94925. +
  94926. + if ($value == $expected) {
  94927. + print "$param = $value, okay\n";
  94928. + }
  94929. +
  94930. + else {
  94931. + warn "ERROR: value of $param != $expected, $value\n";
  94932. + $errors ++;
  94933. + }
  94934. +}
  94935. +
  94936. +#
  94937. +#
  94938. +sub get {
  94939. + my $param = shift;
  94940. + my $tmp = `cat $paramdir/$param`;
  94941. + chomp $tmp;
  94942. + return $tmp;
  94943. +}
  94944. +
  94945. +#
  94946. +#
  94947. +sub test_main {
  94948. +
  94949. + print "\nTesting Module Parameters\n";
  94950. +
  94951. + load_module("") or die;
  94952. +
  94953. + # Test initial values
  94954. + print "\nTesting Default Values\n";
  94955. + foreach (@{$params}) {
  94956. + test ($_->{NAME}, $_->{DEFAULT});
  94957. + }
  94958. +
  94959. + # Test low value
  94960. + print "\nTesting Low Value\n";
  94961. + my $cmd_params = "";
  94962. + foreach (@{$params}) {
  94963. + $cmd_params = $cmd_params . "$_->{NAME}=$_->{LOW} ";
  94964. + }
  94965. + load_module($cmd_params) or die;
  94966. +
  94967. + foreach (@{$params}) {
  94968. + test ($_->{NAME}, $_->{LOW});
  94969. + }
  94970. +
  94971. + # Test high value
  94972. + print "\nTesting High Value\n";
  94973. + $cmd_params = "";
  94974. + foreach (@{$params}) {
  94975. + $cmd_params = $cmd_params . "$_->{NAME}=$_->{HIGH} ";
  94976. + }
  94977. + load_module($cmd_params) or die;
  94978. +
  94979. + foreach (@{$params}) {
  94980. + test ($_->{NAME}, $_->{HIGH});
  94981. + }
  94982. +
  94983. + # Test Enum
  94984. + print "\nTesting Enumerated\n";
  94985. + foreach (@{$params}) {
  94986. + if (defined $_->{ENUM}) {
  94987. + my $value;
  94988. + foreach $value (@{$_->{ENUM}}) {
  94989. + $cmd_params = "$_->{NAME}=$value";
  94990. + load_module($cmd_params) or die;
  94991. + test ($_->{NAME}, $value);
  94992. + }
  94993. + }
  94994. + }
  94995. +
  94996. + # Test Invalid Values
  94997. + print "\nTesting Invalid Values\n";
  94998. + $cmd_params = "";
  94999. + foreach (@{$params}) {
  95000. + $cmd_params = $cmd_params . sprintf "$_->{NAME}=%d ", $_->{LOW}-1;
  95001. + }
  95002. + load_module($cmd_params) or die;
  95003. +
  95004. + foreach (@{$params}) {
  95005. + test ($_->{NAME}, $_->{DEFAULT});
  95006. + }
  95007. +
  95008. + $cmd_params = "";
  95009. + foreach (@{$params}) {
  95010. + $cmd_params = $cmd_params . sprintf "$_->{NAME}=%d ", $_->{HIGH}+1;
  95011. + }
  95012. + load_module($cmd_params) or die;
  95013. +
  95014. + foreach (@{$params}) {
  95015. + test ($_->{NAME}, $_->{DEFAULT});
  95016. + }
  95017. +
  95018. + print "\nTesting Enumerated\n";
  95019. + foreach (@{$params}) {
  95020. + if (defined $_->{ENUM}) {
  95021. + my $value;
  95022. + foreach $value (@{$_->{ENUM}}) {
  95023. + $value = $value + 1;
  95024. + $cmd_params = "$_->{NAME}=$value";
  95025. + load_module($cmd_params) or die;
  95026. + test ($_->{NAME}, $_->{DEFAULT});
  95027. + $value = $value - 2;
  95028. + $cmd_params = "$_->{NAME}=$value";
  95029. + load_module($cmd_params) or die;
  95030. + test ($_->{NAME}, $_->{DEFAULT});
  95031. + }
  95032. + }
  95033. + }
  95034. +
  95035. + test_status() or die;
  95036. +}
  95037. +
  95038. +test_main();
  95039. +0;
  95040. diff -Nur linux-3.12.26.orig/drivers/usb/host/dwc_otg/test/test_sysfs.pl linux-3.12.26/drivers/usb/host/dwc_otg/test/test_sysfs.pl
  95041. --- linux-3.12.26.orig/drivers/usb/host/dwc_otg/test/test_sysfs.pl 1970-01-01 01:00:00.000000000 +0100
  95042. +++ linux-3.12.26/drivers/usb/host/dwc_otg/test/test_sysfs.pl 2014-08-06 16:50:14.893965449 +0200
  95043. @@ -0,0 +1,193 @@
  95044. +#!/usr/bin/perl -w
  95045. +#
  95046. +# Run this program on the integrator
  95047. +# - Tests select sysfs attributes.
  95048. +# - Todo ... test more attributes, hnp/srp, buspower/bussuspend, etc.
  95049. +# -----------------------------------------------------------------------------
  95050. +use strict;
  95051. +use dwc_otg_test;
  95052. +
  95053. +check_arch() or die;
  95054. +
  95055. +#
  95056. +#
  95057. +sub test {
  95058. + my ($attr,$expected) = @_;
  95059. + my $string = get($attr);
  95060. +
  95061. + if ($string eq $expected) {
  95062. + printf("$attr = $string, okay\n");
  95063. + }
  95064. + else {
  95065. + warn "ERROR: value of $attr != $expected, $string\n";
  95066. + $errors ++;
  95067. + }
  95068. +}
  95069. +
  95070. +#
  95071. +#
  95072. +sub set {
  95073. + my ($reg, $value) = @_;
  95074. + system "echo $value > $sysfsdir/$reg";
  95075. +}
  95076. +
  95077. +#
  95078. +#
  95079. +sub get {
  95080. + my $attr = shift;
  95081. + my $string = `cat $sysfsdir/$attr`;
  95082. + chomp $string;
  95083. + if ($string =~ m/\s\=\s/) {
  95084. + my $tmp;
  95085. + ($tmp, $string) = split /\s=\s/, $string;
  95086. + }
  95087. + return $string;
  95088. +}
  95089. +
  95090. +#
  95091. +#
  95092. +sub test_main {
  95093. + print("\nTesting Sysfs Attributes\n");
  95094. +
  95095. + load_module("") or die;
  95096. +
  95097. + # Test initial values of regoffset/regvalue/guid/gsnpsid
  95098. + print("\nTesting Default Values\n");
  95099. +
  95100. + test("regoffset", "0xffffffff");
  95101. + test("regvalue", "invalid offset");
  95102. + test("guid", "0x12345678"); # this will fail if it has been changed
  95103. + test("gsnpsid", "0x4f54200a");
  95104. +
  95105. + # Test operation of regoffset/regvalue
  95106. + print("\nTesting regoffset\n");
  95107. + set('regoffset', '5a5a5a5a');
  95108. + test("regoffset", "0xffffffff");
  95109. +
  95110. + set('regoffset', '0');
  95111. + test("regoffset", "0x00000000");
  95112. +
  95113. + set('regoffset', '40000');
  95114. + test("regoffset", "0x00000000");
  95115. +
  95116. + set('regoffset', '3ffff');
  95117. + test("regoffset", "0x0003ffff");
  95118. +
  95119. + set('regoffset', '1');
  95120. + test("regoffset", "0x00000001");
  95121. +
  95122. + print("\nTesting regvalue\n");
  95123. + set('regoffset', '3c');
  95124. + test("regvalue", "0x12345678");
  95125. + set('regvalue', '5a5a5a5a');
  95126. + test("regvalue", "0x5a5a5a5a");
  95127. + set('regvalue','a5a5a5a5');
  95128. + test("regvalue", "0xa5a5a5a5");
  95129. + set('guid','12345678');
  95130. +
  95131. + # Test HNP Capable
  95132. + print("\nTesting HNP Capable bit\n");
  95133. + set('hnpcapable', '1');
  95134. + test("hnpcapable", "0x1");
  95135. + set('hnpcapable','0');
  95136. + test("hnpcapable", "0x0");
  95137. +
  95138. + set('regoffset','0c');
  95139. +
  95140. + my $old = get('gusbcfg');
  95141. + print("setting hnpcapable\n");
  95142. + set('hnpcapable', '1');
  95143. + test("hnpcapable", "0x1");
  95144. + test('gusbcfg', sprintf "0x%08x", (oct ($old) | (1<<9)));
  95145. + test('regvalue', sprintf "0x%08x", (oct ($old) | (1<<9)));
  95146. +
  95147. + $old = get('gusbcfg');
  95148. + print("clearing hnpcapable\n");
  95149. + set('hnpcapable', '0');
  95150. + test("hnpcapable", "0x0");
  95151. + test ('gusbcfg', sprintf "0x%08x", oct ($old) & (~(1<<9)));
  95152. + test ('regvalue', sprintf "0x%08x", oct ($old) & (~(1<<9)));
  95153. +
  95154. + # Test SRP Capable
  95155. + print("\nTesting SRP Capable bit\n");
  95156. + set('srpcapable', '1');
  95157. + test("srpcapable", "0x1");
  95158. + set('srpcapable','0');
  95159. + test("srpcapable", "0x0");
  95160. +
  95161. + set('regoffset','0c');
  95162. +
  95163. + $old = get('gusbcfg');
  95164. + print("setting srpcapable\n");
  95165. + set('srpcapable', '1');
  95166. + test("srpcapable", "0x1");
  95167. + test('gusbcfg', sprintf "0x%08x", (oct ($old) | (1<<8)));
  95168. + test('regvalue', sprintf "0x%08x", (oct ($old) | (1<<8)));
  95169. +
  95170. + $old = get('gusbcfg');
  95171. + print("clearing srpcapable\n");
  95172. + set('srpcapable', '0');
  95173. + test("srpcapable", "0x0");
  95174. + test('gusbcfg', sprintf "0x%08x", oct ($old) & (~(1<<8)));
  95175. + test('regvalue', sprintf "0x%08x", oct ($old) & (~(1<<8)));
  95176. +
  95177. + # Test GGPIO
  95178. + print("\nTesting GGPIO\n");
  95179. + set('ggpio','5a5a5a5a');
  95180. + test('ggpio','0x5a5a0000');
  95181. + set('ggpio','a5a5a5a5');
  95182. + test('ggpio','0xa5a50000');
  95183. + set('ggpio','11110000');
  95184. + test('ggpio','0x11110000');
  95185. + set('ggpio','00001111');
  95186. + test('ggpio','0x00000000');
  95187. +
  95188. + # Test DEVSPEED
  95189. + print("\nTesting DEVSPEED\n");
  95190. + set('regoffset','800');
  95191. + $old = get('regvalue');
  95192. + set('devspeed','0');
  95193. + test('devspeed','0x0');
  95194. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3)));
  95195. + set('devspeed','1');
  95196. + test('devspeed','0x1');
  95197. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 1));
  95198. + set('devspeed','2');
  95199. + test('devspeed','0x2');
  95200. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 2));
  95201. + set('devspeed','3');
  95202. + test('devspeed','0x3');
  95203. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 3));
  95204. + set('devspeed','4');
  95205. + test('devspeed','0x0');
  95206. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3)));
  95207. + set('devspeed','5');
  95208. + test('devspeed','0x1');
  95209. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 1));
  95210. +
  95211. +
  95212. + # mode Returns the current mode:0 for device mode1 for host mode Read
  95213. + # hnp Initiate the Host Negotiation Protocol. Read returns the status. Read/Write
  95214. + # srp Initiate the Session Request Protocol. Read returns the status. Read/Write
  95215. + # buspower Get or Set the Power State of the bus (0 - Off or 1 - On) Read/Write
  95216. + # bussuspend Suspend the USB bus. Read/Write
  95217. + # busconnected Get the connection status of the bus Read
  95218. +
  95219. + # gotgctl Get or set the Core Control Status Register. Read/Write
  95220. + ## gusbcfg Get or set the Core USB Configuration Register Read/Write
  95221. + # grxfsiz Get or set the Receive FIFO Size Register Read/Write
  95222. + # gnptxfsiz Get or set the non-periodic Transmit Size Register Read/Write
  95223. + # gpvndctl Get or set the PHY Vendor Control Register Read/Write
  95224. + ## ggpio Get the value in the lower 16-bits of the General Purpose IO Register or Set the upper 16 bits. Read/Write
  95225. + ## guid Get or set the value of the User ID Register Read/Write
  95226. + ## gsnpsid Get the value of the Synopsys ID Regester Read
  95227. + ## devspeed Get or set the device speed setting in the DCFG register Read/Write
  95228. + # enumspeed Gets the device enumeration Speed. Read
  95229. + # hptxfsiz Get the value of the Host Periodic Transmit FIFO Read
  95230. + # hprt0 Get or Set the value in the Host Port Control and Status Register Read/Write
  95231. +
  95232. + test_status("TEST NYI") or die;
  95233. +}
  95234. +
  95235. +test_main();
  95236. +0;
  95237. diff -Nur linux-3.12.26.orig/drivers/usb/host/Kconfig linux-3.12.26/drivers/usb/host/Kconfig
  95238. --- linux-3.12.26.orig/drivers/usb/host/Kconfig 2014-07-30 18:02:44.000000000 +0200
  95239. +++ linux-3.12.26/drivers/usb/host/Kconfig 2014-08-06 16:50:14.897965480 +0200
  95240. @@ -650,6 +650,19 @@
  95241. To compile this driver a module, choose M here: the module
  95242. will be called "hwa-hc".
  95243. +config USB_DWCOTG
  95244. + tristate "Synopsis DWC host support"
  95245. + depends on USB
  95246. + help
  95247. + The Synopsis DWC controller is a dual-role
  95248. + host/peripheral/OTG ("On The Go") USB controllers.
  95249. +
  95250. + Enable this option to support this IP in host controller mode.
  95251. + If unsure, say N.
  95252. +
  95253. + To compile this driver as a module, choose M here: the
  95254. + modules built will be called dwc_otg and dwc_common_port.
  95255. +
  95256. config USB_IMX21_HCD
  95257. tristate "i.MX21 HCD support"
  95258. depends on ARM && ARCH_MXC
  95259. diff -Nur linux-3.12.26.orig/drivers/usb/host/Makefile linux-3.12.26/drivers/usb/host/Makefile
  95260. --- linux-3.12.26.orig/drivers/usb/host/Makefile 2014-07-30 18:02:44.000000000 +0200
  95261. +++ linux-3.12.26/drivers/usb/host/Makefile 2014-08-06 16:50:14.897965480 +0200
  95262. @@ -56,6 +56,8 @@
  95263. obj-$(CONFIG_USB_R8A66597_HCD) += r8a66597-hcd.o
  95264. obj-$(CONFIG_USB_ISP1760_HCD) += isp1760.o
  95265. obj-$(CONFIG_USB_HWA_HCD) += hwa-hc.o
  95266. +
  95267. +obj-$(CONFIG_USB_DWCOTG) += dwc_otg/ dwc_common_port/
  95268. obj-$(CONFIG_USB_IMX21_HCD) += imx21-hcd.o
  95269. obj-$(CONFIG_USB_FSL_MPH_DR_OF) += fsl-mph-dr-of.o
  95270. obj-$(CONFIG_USB_OCTEON2_COMMON) += octeon2-common.o
  95271. diff -Nur linux-3.12.26.orig/drivers/usb/Makefile linux-3.12.26/drivers/usb/Makefile
  95272. --- linux-3.12.26.orig/drivers/usb/Makefile 2014-07-30 18:02:44.000000000 +0200
  95273. +++ linux-3.12.26/drivers/usb/Makefile 2014-08-06 16:50:14.897965480 +0200
  95274. @@ -23,6 +23,7 @@
  95275. obj-$(CONFIG_USB_R8A66597_HCD) += host/
  95276. obj-$(CONFIG_USB_HWA_HCD) += host/
  95277. obj-$(CONFIG_USB_ISP1760_HCD) += host/
  95278. +obj-$(CONFIG_USB_DWCOTG) += host/
  95279. obj-$(CONFIG_USB_IMX21_HCD) += host/
  95280. obj-$(CONFIG_USB_FSL_MPH_DR_OF) += host/
  95281. obj-$(CONFIG_USB_FUSBH200_HCD) += host/
  95282. diff -Nur linux-3.12.26.orig/drivers/vhost/net.c linux-3.12.26/drivers/vhost/net.c
  95283. --- linux-3.12.26.orig/drivers/vhost/net.c 2014-07-30 18:02:44.000000000 +0200
  95284. +++ linux-3.12.26/drivers/vhost/net.c 2014-08-06 16:50:14.921965669 +0200
  95285. @@ -501,13 +501,9 @@
  95286. r = -ENOBUFS;
  95287. goto err;
  95288. }
  95289. - r = vhost_get_vq_desc(vq->dev, vq, vq->iov + seg,
  95290. + d = vhost_get_vq_desc(vq->dev, vq, vq->iov + seg,
  95291. ARRAY_SIZE(vq->iov) - seg, &out,
  95292. &in, log, log_num);
  95293. - if (unlikely(r < 0))
  95294. - goto err;
  95295. -
  95296. - d = r;
  95297. if (d == vq->num) {
  95298. r = 0;
  95299. goto err;
  95300. @@ -532,12 +528,6 @@
  95301. *iovcount = seg;
  95302. if (unlikely(log))
  95303. *log_num = nlogs;
  95304. -
  95305. - /* Detect overrun */
  95306. - if (unlikely(datalen > 0)) {
  95307. - r = UIO_MAXIOV + 1;
  95308. - goto err;
  95309. - }
  95310. return headcount;
  95311. err:
  95312. vhost_discard_vq_desc(vq, headcount);
  95313. @@ -593,14 +583,6 @@
  95314. /* On error, stop handling until the next kick. */
  95315. if (unlikely(headcount < 0))
  95316. break;
  95317. - /* On overrun, truncate and discard */
  95318. - if (unlikely(headcount > UIO_MAXIOV)) {
  95319. - msg.msg_iovlen = 1;
  95320. - err = sock->ops->recvmsg(NULL, sock, &msg,
  95321. - 1, MSG_DONTWAIT | MSG_TRUNC);
  95322. - pr_debug("Discarded rx packet: len %zd\n", sock_len);
  95323. - continue;
  95324. - }
  95325. /* OK, now we need to know about added descriptors. */
  95326. if (!headcount) {
  95327. if (unlikely(vhost_enable_notify(&net->dev, vq))) {
  95328. diff -Nur linux-3.12.26.orig/drivers/video/bcm2708_fb.c linux-3.12.26/drivers/video/bcm2708_fb.c
  95329. --- linux-3.12.26.orig/drivers/video/bcm2708_fb.c 1970-01-01 01:00:00.000000000 +0100
  95330. +++ linux-3.12.26/drivers/video/bcm2708_fb.c 2014-08-06 16:50:14.921965669 +0200
  95331. @@ -0,0 +1,762 @@
  95332. +/*
  95333. + * linux/drivers/video/bcm2708_fb.c
  95334. + *
  95335. + * Copyright (C) 2010 Broadcom
  95336. + *
  95337. + * This file is subject to the terms and conditions of the GNU General Public
  95338. + * License. See the file COPYING in the main directory of this archive
  95339. + * for more details.
  95340. + *
  95341. + * Broadcom simple framebuffer driver
  95342. + *
  95343. + * This file is derived from cirrusfb.c
  95344. + * Copyright 1999-2001 Jeff Garzik <jgarzik@pobox.com>
  95345. + *
  95346. + */
  95347. +#include <linux/module.h>
  95348. +#include <linux/kernel.h>
  95349. +#include <linux/errno.h>
  95350. +#include <linux/string.h>
  95351. +#include <linux/slab.h>
  95352. +#include <linux/mm.h>
  95353. +#include <linux/fb.h>
  95354. +#include <linux/init.h>
  95355. +#include <linux/interrupt.h>
  95356. +#include <linux/ioport.h>
  95357. +#include <linux/list.h>
  95358. +#include <linux/platform_device.h>
  95359. +#include <linux/clk.h>
  95360. +#include <linux/printk.h>
  95361. +#include <linux/console.h>
  95362. +#include <linux/debugfs.h>
  95363. +
  95364. +#include <mach/dma.h>
  95365. +#include <mach/platform.h>
  95366. +#include <mach/vcio.h>
  95367. +
  95368. +#include <asm/sizes.h>
  95369. +#include <linux/io.h>
  95370. +#include <linux/dma-mapping.h>
  95371. +
  95372. +#ifdef BCM2708_FB_DEBUG
  95373. +#define print_debug(fmt,...) pr_debug("%s:%s:%d: "fmt, MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  95374. +#else
  95375. +#define print_debug(fmt,...)
  95376. +#endif
  95377. +
  95378. +/* This is limited to 16 characters when displayed by X startup */
  95379. +static const char *bcm2708_name = "BCM2708 FB";
  95380. +
  95381. +#define DRIVER_NAME "bcm2708_fb"
  95382. +
  95383. +static int fbwidth = 800; /* module parameter */
  95384. +static int fbheight = 480; /* module parameter */
  95385. +static int fbdepth = 16; /* module parameter */
  95386. +static int fbswap = 0; /* module parameter */
  95387. +
  95388. +static u32 dma_busy_wait_threshold = 1<<15;
  95389. +module_param(dma_busy_wait_threshold, int, 0644);
  95390. +MODULE_PARM_DESC(dma_busy_wait_threshold, "Busy-wait for DMA completion below this area");
  95391. +
  95392. +/* this data structure describes each frame buffer device we find */
  95393. +
  95394. +struct fbinfo_s {
  95395. + u32 xres, yres, xres_virtual, yres_virtual;
  95396. + u32 pitch, bpp;
  95397. + u32 xoffset, yoffset;
  95398. + u32 base;
  95399. + u32 screen_size;
  95400. + u16 cmap[256];
  95401. +};
  95402. +
  95403. +struct bcm2708_fb_stats {
  95404. + struct debugfs_regset32 regset;
  95405. + u32 dma_copies;
  95406. + u32 dma_irqs;
  95407. +};
  95408. +
  95409. +struct bcm2708_fb {
  95410. + struct fb_info fb;
  95411. + struct platform_device *dev;
  95412. + struct fbinfo_s *info;
  95413. + dma_addr_t dma;
  95414. + u32 cmap[16];
  95415. + int dma_chan;
  95416. + int dma_irq;
  95417. + void __iomem *dma_chan_base;
  95418. + void *cb_base; /* DMA control blocks */
  95419. + dma_addr_t cb_handle;
  95420. + struct dentry *debugfs_dir;
  95421. + wait_queue_head_t dma_waitq;
  95422. + struct bcm2708_fb_stats stats;
  95423. +};
  95424. +
  95425. +#define to_bcm2708(info) container_of(info, struct bcm2708_fb, fb)
  95426. +
  95427. +static void bcm2708_fb_debugfs_deinit(struct bcm2708_fb *fb)
  95428. +{
  95429. + debugfs_remove_recursive(fb->debugfs_dir);
  95430. + fb->debugfs_dir = NULL;
  95431. +}
  95432. +
  95433. +static int bcm2708_fb_debugfs_init(struct bcm2708_fb *fb)
  95434. +{
  95435. + static struct debugfs_reg32 stats_registers[] = {
  95436. + {
  95437. + "dma_copies",
  95438. + offsetof(struct bcm2708_fb_stats, dma_copies)
  95439. + },
  95440. + {
  95441. + "dma_irqs",
  95442. + offsetof(struct bcm2708_fb_stats, dma_irqs)
  95443. + },
  95444. + };
  95445. +
  95446. + fb->debugfs_dir = debugfs_create_dir(DRIVER_NAME, NULL);
  95447. + if (!fb->debugfs_dir) {
  95448. + pr_warn("%s: could not create debugfs entry\n",
  95449. + __func__);
  95450. + return -EFAULT;
  95451. + }
  95452. +
  95453. + fb->stats.regset.regs = stats_registers;
  95454. + fb->stats.regset.nregs = ARRAY_SIZE(stats_registers);
  95455. + fb->stats.regset.base = &fb->stats;
  95456. +
  95457. + if (!debugfs_create_regset32(
  95458. + "stats", 0444, fb->debugfs_dir, &fb->stats.regset)) {
  95459. + pr_warn("%s: could not create statistics registers\n",
  95460. + __func__);
  95461. + goto fail;
  95462. + }
  95463. + return 0;
  95464. +
  95465. +fail:
  95466. + bcm2708_fb_debugfs_deinit(fb);
  95467. + return -EFAULT;
  95468. +}
  95469. +
  95470. +static int bcm2708_fb_set_bitfields(struct fb_var_screeninfo *var)
  95471. +{
  95472. + int ret = 0;
  95473. +
  95474. + memset(&var->transp, 0, sizeof(var->transp));
  95475. +
  95476. + var->red.msb_right = 0;
  95477. + var->green.msb_right = 0;
  95478. + var->blue.msb_right = 0;
  95479. +
  95480. + switch (var->bits_per_pixel) {
  95481. + case 1:
  95482. + case 2:
  95483. + case 4:
  95484. + case 8:
  95485. + var->red.length = var->bits_per_pixel;
  95486. + var->red.offset = 0;
  95487. + var->green.length = var->bits_per_pixel;
  95488. + var->green.offset = 0;
  95489. + var->blue.length = var->bits_per_pixel;
  95490. + var->blue.offset = 0;
  95491. + break;
  95492. + case 16:
  95493. + var->red.length = 5;
  95494. + var->blue.length = 5;
  95495. + /*
  95496. + * Green length can be 5 or 6 depending whether
  95497. + * we're operating in RGB555 or RGB565 mode.
  95498. + */
  95499. + if (var->green.length != 5 && var->green.length != 6)
  95500. + var->green.length = 6;
  95501. + break;
  95502. + case 24:
  95503. + var->red.length = 8;
  95504. + var->blue.length = 8;
  95505. + var->green.length = 8;
  95506. + break;
  95507. + case 32:
  95508. + var->red.length = 8;
  95509. + var->green.length = 8;
  95510. + var->blue.length = 8;
  95511. + var->transp.length = 8;
  95512. + break;
  95513. + default:
  95514. + ret = -EINVAL;
  95515. + break;
  95516. + }
  95517. +
  95518. + /*
  95519. + * >= 16bpp displays have separate colour component bitfields
  95520. + * encoded in the pixel data. Calculate their position from
  95521. + * the bitfield length defined above.
  95522. + */
  95523. + if (ret == 0 && var->bits_per_pixel >= 24 && fbswap) {
  95524. + var->blue.offset = 0;
  95525. + var->green.offset = var->blue.offset + var->blue.length;
  95526. + var->red.offset = var->green.offset + var->green.length;
  95527. + var->transp.offset = var->red.offset + var->red.length;
  95528. + } else if (ret == 0 && var->bits_per_pixel >= 24) {
  95529. + var->red.offset = 0;
  95530. + var->green.offset = var->red.offset + var->red.length;
  95531. + var->blue.offset = var->green.offset + var->green.length;
  95532. + var->transp.offset = var->blue.offset + var->blue.length;
  95533. + } else if (ret == 0 && var->bits_per_pixel >= 16) {
  95534. + var->blue.offset = 0;
  95535. + var->green.offset = var->blue.offset + var->blue.length;
  95536. + var->red.offset = var->green.offset + var->green.length;
  95537. + var->transp.offset = var->red.offset + var->red.length;
  95538. + }
  95539. +
  95540. + return ret;
  95541. +}
  95542. +
  95543. +static int bcm2708_fb_check_var(struct fb_var_screeninfo *var,
  95544. + struct fb_info *info)
  95545. +{
  95546. + /* info input, var output */
  95547. + int yres;
  95548. +
  95549. + /* info input, var output */
  95550. + print_debug("bcm2708_fb_check_var info(%p) %dx%d (%dx%d), %d, %d\n", info,
  95551. + info->var.xres, info->var.yres, info->var.xres_virtual,
  95552. + info->var.yres_virtual, (int)info->screen_size,
  95553. + info->var.bits_per_pixel);
  95554. + print_debug("bcm2708_fb_check_var var(%p) %dx%d (%dx%d), %d\n", var,
  95555. + var->xres, var->yres, var->xres_virtual, var->yres_virtual,
  95556. + var->bits_per_pixel);
  95557. +
  95558. + if (!var->bits_per_pixel)
  95559. + var->bits_per_pixel = 16;
  95560. +
  95561. + if (bcm2708_fb_set_bitfields(var) != 0) {
  95562. + pr_err("bcm2708_fb_check_var: invalid bits_per_pixel %d\n",
  95563. + var->bits_per_pixel);
  95564. + return -EINVAL;
  95565. + }
  95566. +
  95567. +
  95568. + if (var->xres_virtual < var->xres)
  95569. + var->xres_virtual = var->xres;
  95570. + /* use highest possible virtual resolution */
  95571. + if (var->yres_virtual == -1) {
  95572. + var->yres_virtual = 480;
  95573. +
  95574. + pr_err
  95575. + ("bcm2708_fb_check_var: virtual resolution set to maximum of %dx%d\n",
  95576. + var->xres_virtual, var->yres_virtual);
  95577. + }
  95578. + if (var->yres_virtual < var->yres)
  95579. + var->yres_virtual = var->yres;
  95580. +
  95581. + if (var->xoffset < 0)
  95582. + var->xoffset = 0;
  95583. + if (var->yoffset < 0)
  95584. + var->yoffset = 0;
  95585. +
  95586. + /* truncate xoffset and yoffset to maximum if too high */
  95587. + if (var->xoffset > var->xres_virtual - var->xres)
  95588. + var->xoffset = var->xres_virtual - var->xres - 1;
  95589. + if (var->yoffset > var->yres_virtual - var->yres)
  95590. + var->yoffset = var->yres_virtual - var->yres - 1;
  95591. +
  95592. + yres = var->yres;
  95593. + if (var->vmode & FB_VMODE_DOUBLE)
  95594. + yres *= 2;
  95595. + else if (var->vmode & FB_VMODE_INTERLACED)
  95596. + yres = (yres + 1) / 2;
  95597. +
  95598. + if (var->xres * yres > 1920 * 1200) {
  95599. + pr_err("bcm2708_fb_check_var: ERROR: Pixel size >= 1920x1200; "
  95600. + "special treatment required! (TODO)\n");
  95601. + return -EINVAL;
  95602. + }
  95603. +
  95604. + return 0;
  95605. +}
  95606. +
  95607. +static int bcm2708_fb_set_par(struct fb_info *info)
  95608. +{
  95609. + uint32_t val = 0;
  95610. + struct bcm2708_fb *fb = to_bcm2708(info);
  95611. + volatile struct fbinfo_s *fbinfo = fb->info;
  95612. + fbinfo->xres = info->var.xres;
  95613. + fbinfo->yres = info->var.yres;
  95614. + fbinfo->xres_virtual = info->var.xres_virtual;
  95615. + fbinfo->yres_virtual = info->var.yres_virtual;
  95616. + fbinfo->bpp = info->var.bits_per_pixel;
  95617. + fbinfo->xoffset = info->var.xoffset;
  95618. + fbinfo->yoffset = info->var.yoffset;
  95619. + fbinfo->base = 0; /* filled in by VC */
  95620. + fbinfo->pitch = 0; /* filled in by VC */
  95621. +
  95622. + print_debug("bcm2708_fb_set_par info(%p) %dx%d (%dx%d), %d, %d\n", info,
  95623. + info->var.xres, info->var.yres, info->var.xres_virtual,
  95624. + info->var.yres_virtual, (int)info->screen_size,
  95625. + info->var.bits_per_pixel);
  95626. +
  95627. + /* ensure last write to fbinfo is visible to GPU */
  95628. + wmb();
  95629. +
  95630. + /* inform vc about new framebuffer */
  95631. + bcm_mailbox_write(MBOX_CHAN_FB, fb->dma);
  95632. +
  95633. + /* TODO: replace fb driver with vchiq version */
  95634. + /* wait for response */
  95635. + bcm_mailbox_read(MBOX_CHAN_FB, &val);
  95636. +
  95637. + /* ensure GPU writes are visible to us */
  95638. + rmb();
  95639. +
  95640. + if (val == 0) {
  95641. + fb->fb.fix.line_length = fbinfo->pitch;
  95642. +
  95643. + if (info->var.bits_per_pixel <= 8)
  95644. + fb->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR;
  95645. + else
  95646. + fb->fb.fix.visual = FB_VISUAL_TRUECOLOR;
  95647. +
  95648. + fb->fb.fix.smem_start = fbinfo->base;
  95649. + fb->fb.fix.smem_len = fbinfo->pitch * fbinfo->yres_virtual;
  95650. + fb->fb.screen_size = fbinfo->screen_size;
  95651. + if (fb->fb.screen_base)
  95652. + iounmap(fb->fb.screen_base);
  95653. + fb->fb.screen_base =
  95654. + (void *)ioremap_wc(fb->fb.fix.smem_start, fb->fb.screen_size);
  95655. + if (!fb->fb.screen_base) {
  95656. + /* the console may currently be locked */
  95657. + console_trylock();
  95658. + console_unlock();
  95659. +
  95660. + BUG(); /* what can we do here */
  95661. + }
  95662. + }
  95663. + print_debug
  95664. + ("BCM2708FB: start = %p,%p width=%d, height=%d, bpp=%d, pitch=%d size=%d success=%d\n",
  95665. + (void *)fb->fb.screen_base, (void *)fb->fb.fix.smem_start,
  95666. + fbinfo->xres, fbinfo->yres, fbinfo->bpp,
  95667. + fbinfo->pitch, (int)fb->fb.screen_size, val);
  95668. +
  95669. + return val;
  95670. +}
  95671. +
  95672. +static inline u32 convert_bitfield(int val, struct fb_bitfield *bf)
  95673. +{
  95674. + unsigned int mask = (1 << bf->length) - 1;
  95675. +
  95676. + return (val >> (16 - bf->length) & mask) << bf->offset;
  95677. +}
  95678. +
  95679. +
  95680. +static int bcm2708_fb_setcolreg(unsigned int regno, unsigned int red,
  95681. + unsigned int green, unsigned int blue,
  95682. + unsigned int transp, struct fb_info *info)
  95683. +{
  95684. + struct bcm2708_fb *fb = to_bcm2708(info);
  95685. +
  95686. + /*print_debug("BCM2708FB: setcolreg %d:(%02x,%02x,%02x,%02x) %x\n", regno, red, green, blue, transp, fb->fb.fix.visual);*/
  95687. + if (fb->fb.var.bits_per_pixel <= 8) {
  95688. + if (regno < 256) {
  95689. + /* blue [0:4], green [5:10], red [11:15] */
  95690. + fb->info->cmap[regno] = ((red >> (16-5)) & 0x1f) << 11 |
  95691. + ((green >> (16-6)) & 0x3f) << 5 |
  95692. + ((blue >> (16-5)) & 0x1f) << 0;
  95693. + }
  95694. + /* 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 */
  95695. + /* So just call it for what looks like the last colour in a list for now. */
  95696. + if (regno == 15 || regno == 255)
  95697. + bcm2708_fb_set_par(info);
  95698. + } else if (regno < 16) {
  95699. + fb->cmap[regno] = convert_bitfield(transp, &fb->fb.var.transp) |
  95700. + convert_bitfield(blue, &fb->fb.var.blue) |
  95701. + convert_bitfield(green, &fb->fb.var.green) |
  95702. + convert_bitfield(red, &fb->fb.var.red);
  95703. + }
  95704. + return regno > 255;
  95705. +}
  95706. +
  95707. +static int bcm2708_fb_blank(int blank_mode, struct fb_info *info)
  95708. +{
  95709. + /*print_debug("bcm2708_fb_blank\n"); */
  95710. + return -1;
  95711. +}
  95712. +
  95713. +static void bcm2708_fb_fillrect(struct fb_info *info,
  95714. + const struct fb_fillrect *rect)
  95715. +{
  95716. + /* (is called) print_debug("bcm2708_fb_fillrect\n"); */
  95717. + cfb_fillrect(info, rect);
  95718. +}
  95719. +
  95720. +/* A helper function for configuring dma control block */
  95721. +static void set_dma_cb(struct bcm2708_dma_cb *cb,
  95722. + int burst_size,
  95723. + dma_addr_t dst,
  95724. + int dst_stride,
  95725. + dma_addr_t src,
  95726. + int src_stride,
  95727. + int w,
  95728. + int h)
  95729. +{
  95730. + cb->info = BCM2708_DMA_BURST(burst_size) | BCM2708_DMA_S_WIDTH |
  95731. + BCM2708_DMA_S_INC | BCM2708_DMA_D_WIDTH |
  95732. + BCM2708_DMA_D_INC | BCM2708_DMA_TDMODE;
  95733. + cb->dst = dst;
  95734. + cb->src = src;
  95735. + /*
  95736. + * This is not really obvious from the DMA documentation,
  95737. + * but the top 16 bits must be programmmed to "height -1"
  95738. + * and not "height" in 2D mode.
  95739. + */
  95740. + cb->length = ((h - 1) << 16) | w;
  95741. + cb->stride = ((dst_stride - w) << 16) | (u16)(src_stride - w);
  95742. + cb->pad[0] = 0;
  95743. + cb->pad[1] = 0;
  95744. +}
  95745. +
  95746. +static void bcm2708_fb_copyarea(struct fb_info *info,
  95747. + const struct fb_copyarea *region)
  95748. +{
  95749. + struct bcm2708_fb *fb = to_bcm2708(info);
  95750. + struct bcm2708_dma_cb *cb = fb->cb_base;
  95751. + int bytes_per_pixel = (info->var.bits_per_pixel + 7) >> 3;
  95752. + /* Channel 0 supports larger bursts and is a bit faster */
  95753. + int burst_size = (fb->dma_chan == 0) ? 8 : 2;
  95754. + int pixels = region->width * region->height;
  95755. +
  95756. + /* Fallback to cfb_copyarea() if we don't like something */
  95757. + if (bytes_per_pixel > 4 ||
  95758. + info->var.xres * info->var.yres > 1920 * 1200 ||
  95759. + region->width <= 0 || region->width > info->var.xres ||
  95760. + region->height <= 0 || region->height > info->var.yres ||
  95761. + region->sx < 0 || region->sx >= info->var.xres ||
  95762. + region->sy < 0 || region->sy >= info->var.yres ||
  95763. + region->dx < 0 || region->dx >= info->var.xres ||
  95764. + region->dy < 0 || region->dy >= info->var.yres ||
  95765. + region->sx + region->width > info->var.xres ||
  95766. + region->dx + region->width > info->var.xres ||
  95767. + region->sy + region->height > info->var.yres ||
  95768. + region->dy + region->height > info->var.yres) {
  95769. + cfb_copyarea(info, region);
  95770. + return;
  95771. + }
  95772. +
  95773. + if (region->dy == region->sy && region->dx > region->sx) {
  95774. + /*
  95775. + * A difficult case of overlapped copy. Because DMA can't
  95776. + * copy individual scanlines in backwards direction, we need
  95777. + * two-pass processing. We do it by programming a chain of dma
  95778. + * control blocks in the first 16K part of the buffer and use
  95779. + * the remaining 48K as the intermediate temporary scratch
  95780. + * buffer. The buffer size is sufficient to handle up to
  95781. + * 1920x1200 resolution at 32bpp pixel depth.
  95782. + */
  95783. + int y;
  95784. + dma_addr_t control_block_pa = fb->cb_handle;
  95785. + dma_addr_t scratchbuf = fb->cb_handle + 16 * 1024;
  95786. + int scanline_size = bytes_per_pixel * region->width;
  95787. + int scanlines_per_cb = (64 * 1024 - 16 * 1024) / scanline_size;
  95788. +
  95789. + for (y = 0; y < region->height; y += scanlines_per_cb) {
  95790. + dma_addr_t src =
  95791. + fb->fb.fix.smem_start +
  95792. + bytes_per_pixel * region->sx +
  95793. + (region->sy + y) * fb->fb.fix.line_length;
  95794. + dma_addr_t dst =
  95795. + fb->fb.fix.smem_start +
  95796. + bytes_per_pixel * region->dx +
  95797. + (region->dy + y) * fb->fb.fix.line_length;
  95798. +
  95799. + if (region->height - y < scanlines_per_cb)
  95800. + scanlines_per_cb = region->height - y;
  95801. +
  95802. + set_dma_cb(cb, burst_size, scratchbuf, scanline_size,
  95803. + src, fb->fb.fix.line_length,
  95804. + scanline_size, scanlines_per_cb);
  95805. + control_block_pa += sizeof(struct bcm2708_dma_cb);
  95806. + cb->next = control_block_pa;
  95807. + cb++;
  95808. +
  95809. + set_dma_cb(cb, burst_size, dst, fb->fb.fix.line_length,
  95810. + scratchbuf, scanline_size,
  95811. + scanline_size, scanlines_per_cb);
  95812. + control_block_pa += sizeof(struct bcm2708_dma_cb);
  95813. + cb->next = control_block_pa;
  95814. + cb++;
  95815. + }
  95816. + /* move the pointer back to the last dma control block */
  95817. + cb--;
  95818. + } else {
  95819. + /* A single dma control block is enough. */
  95820. + int sy, dy, stride;
  95821. + if (region->dy <= region->sy) {
  95822. + /* processing from top to bottom */
  95823. + dy = region->dy;
  95824. + sy = region->sy;
  95825. + stride = fb->fb.fix.line_length;
  95826. + } else {
  95827. + /* processing from bottom to top */
  95828. + dy = region->dy + region->height - 1;
  95829. + sy = region->sy + region->height - 1;
  95830. + stride = -fb->fb.fix.line_length;
  95831. + }
  95832. + set_dma_cb(cb, burst_size,
  95833. + fb->fb.fix.smem_start + dy * fb->fb.fix.line_length +
  95834. + bytes_per_pixel * region->dx,
  95835. + stride,
  95836. + fb->fb.fix.smem_start + sy * fb->fb.fix.line_length +
  95837. + bytes_per_pixel * region->sx,
  95838. + stride,
  95839. + region->width * bytes_per_pixel,
  95840. + region->height);
  95841. + }
  95842. +
  95843. + /* end of dma control blocks chain */
  95844. + cb->next = 0;
  95845. +
  95846. +
  95847. + if (pixels < dma_busy_wait_threshold) {
  95848. + bcm_dma_start(fb->dma_chan_base, fb->cb_handle);
  95849. + bcm_dma_wait_idle(fb->dma_chan_base);
  95850. + } else {
  95851. + void __iomem *dma_chan = fb->dma_chan_base;
  95852. + cb->info |= BCM2708_DMA_INT_EN;
  95853. + bcm_dma_start(fb->dma_chan_base, fb->cb_handle);
  95854. + while (bcm_dma_is_busy(dma_chan)) {
  95855. + wait_event_interruptible(
  95856. + fb->dma_waitq,
  95857. + !bcm_dma_is_busy(dma_chan));
  95858. + }
  95859. + fb->stats.dma_irqs++;
  95860. + }
  95861. + fb->stats.dma_copies++;
  95862. +}
  95863. +
  95864. +static void bcm2708_fb_imageblit(struct fb_info *info,
  95865. + const struct fb_image *image)
  95866. +{
  95867. + /* (is called) print_debug("bcm2708_fb_imageblit\n"); */
  95868. + cfb_imageblit(info, image);
  95869. +}
  95870. +
  95871. +static irqreturn_t bcm2708_fb_dma_irq(int irq, void *cxt)
  95872. +{
  95873. + struct bcm2708_fb *fb = cxt;
  95874. +
  95875. + /* FIXME: should read status register to check if this is
  95876. + * actually interrupting us or not, in case this interrupt
  95877. + * ever becomes shared amongst several DMA channels
  95878. + *
  95879. + * readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_IRQ;
  95880. + */
  95881. +
  95882. + /* acknowledge the interrupt */
  95883. + writel(BCM2708_DMA_INT, fb->dma_chan_base + BCM2708_DMA_CS);
  95884. +
  95885. + wake_up(&fb->dma_waitq);
  95886. + return IRQ_HANDLED;
  95887. +}
  95888. +
  95889. +static struct fb_ops bcm2708_fb_ops = {
  95890. + .owner = THIS_MODULE,
  95891. + .fb_check_var = bcm2708_fb_check_var,
  95892. + .fb_set_par = bcm2708_fb_set_par,
  95893. + .fb_setcolreg = bcm2708_fb_setcolreg,
  95894. + .fb_blank = bcm2708_fb_blank,
  95895. + .fb_fillrect = bcm2708_fb_fillrect,
  95896. + .fb_copyarea = bcm2708_fb_copyarea,
  95897. + .fb_imageblit = bcm2708_fb_imageblit,
  95898. +};
  95899. +
  95900. +static int bcm2708_fb_register(struct bcm2708_fb *fb)
  95901. +{
  95902. + int ret;
  95903. + dma_addr_t dma;
  95904. + void *mem;
  95905. +
  95906. + mem =
  95907. + dma_alloc_coherent(NULL, PAGE_ALIGN(sizeof(*fb->info)), &dma,
  95908. + GFP_KERNEL);
  95909. +
  95910. + if (NULL == mem) {
  95911. + pr_err(": unable to allocate fbinfo buffer\n");
  95912. + ret = -ENOMEM;
  95913. + } else {
  95914. + fb->info = (struct fbinfo_s *)mem;
  95915. + fb->dma = dma;
  95916. + }
  95917. + fb->fb.fbops = &bcm2708_fb_ops;
  95918. + fb->fb.flags = FBINFO_FLAG_DEFAULT | FBINFO_HWACCEL_COPYAREA;
  95919. + fb->fb.pseudo_palette = fb->cmap;
  95920. +
  95921. + strncpy(fb->fb.fix.id, bcm2708_name, sizeof(fb->fb.fix.id));
  95922. + fb->fb.fix.type = FB_TYPE_PACKED_PIXELS;
  95923. + fb->fb.fix.type_aux = 0;
  95924. + fb->fb.fix.xpanstep = 0;
  95925. + fb->fb.fix.ypanstep = 0;
  95926. + fb->fb.fix.ywrapstep = 0;
  95927. + fb->fb.fix.accel = FB_ACCEL_NONE;
  95928. +
  95929. + fb->fb.var.xres = fbwidth;
  95930. + fb->fb.var.yres = fbheight;
  95931. + fb->fb.var.xres_virtual = fbwidth;
  95932. + fb->fb.var.yres_virtual = fbheight;
  95933. + fb->fb.var.bits_per_pixel = fbdepth;
  95934. + fb->fb.var.vmode = FB_VMODE_NONINTERLACED;
  95935. + fb->fb.var.activate = FB_ACTIVATE_NOW;
  95936. + fb->fb.var.nonstd = 0;
  95937. + fb->fb.var.height = -1; /* height of picture in mm */
  95938. + fb->fb.var.width = -1; /* width of picture in mm */
  95939. + fb->fb.var.accel_flags = 0;
  95940. +
  95941. + fb->fb.monspecs.hfmin = 0;
  95942. + fb->fb.monspecs.hfmax = 100000;
  95943. + fb->fb.monspecs.vfmin = 0;
  95944. + fb->fb.monspecs.vfmax = 400;
  95945. + fb->fb.monspecs.dclkmin = 1000000;
  95946. + fb->fb.monspecs.dclkmax = 100000000;
  95947. +
  95948. + bcm2708_fb_set_bitfields(&fb->fb.var);
  95949. + init_waitqueue_head(&fb->dma_waitq);
  95950. +
  95951. + /*
  95952. + * Allocate colourmap.
  95953. + */
  95954. +
  95955. + fb_set_var(&fb->fb, &fb->fb.var);
  95956. +
  95957. + print_debug("BCM2708FB: registering framebuffer (%dx%d@%d) (%d)\n", fbwidth
  95958. + fbheight, fbdepth, fbswap);
  95959. +
  95960. + ret = register_framebuffer(&fb->fb);
  95961. + print_debug("BCM2708FB: register framebuffer (%d)\n", ret);
  95962. + if (ret == 0)
  95963. + goto out;
  95964. +
  95965. + print_debug("BCM2708FB: cannot register framebuffer (%d)\n", ret);
  95966. +out:
  95967. + return ret;
  95968. +}
  95969. +
  95970. +static int bcm2708_fb_probe(struct platform_device *dev)
  95971. +{
  95972. + struct bcm2708_fb *fb;
  95973. + int ret;
  95974. +
  95975. + fb = kzalloc(sizeof(struct bcm2708_fb), GFP_KERNEL);
  95976. + if (!fb) {
  95977. + dev_err(&dev->dev,
  95978. + "could not allocate new bcm2708_fb struct\n");
  95979. + ret = -ENOMEM;
  95980. + goto free_region;
  95981. + }
  95982. +
  95983. + bcm2708_fb_debugfs_init(fb);
  95984. +
  95985. + fb->cb_base = dma_alloc_writecombine(&dev->dev, SZ_64K,
  95986. + &fb->cb_handle, GFP_KERNEL);
  95987. + if (!fb->cb_base) {
  95988. + dev_err(&dev->dev, "cannot allocate DMA CBs\n");
  95989. + ret = -ENOMEM;
  95990. + goto free_fb;
  95991. + }
  95992. +
  95993. + pr_info("BCM2708FB: allocated DMA memory %08x\n",
  95994. + fb->cb_handle);
  95995. +
  95996. + ret = bcm_dma_chan_alloc(BCM_DMA_FEATURE_BULK,
  95997. + &fb->dma_chan_base, &fb->dma_irq);
  95998. + if (ret < 0) {
  95999. + dev_err(&dev->dev, "couldn't allocate a DMA channel\n");
  96000. + goto free_cb;
  96001. + }
  96002. + fb->dma_chan = ret;
  96003. +
  96004. + ret = request_irq(fb->dma_irq, bcm2708_fb_dma_irq,
  96005. + 0, "bcm2708_fb dma", fb);
  96006. + if (ret) {
  96007. + pr_err("%s: failed to request DMA irq\n", __func__);
  96008. + goto free_dma_chan;
  96009. + }
  96010. +
  96011. +
  96012. + pr_info("BCM2708FB: allocated DMA channel %d @ %p\n",
  96013. + fb->dma_chan, fb->dma_chan_base);
  96014. +
  96015. + fb->dev = dev;
  96016. +
  96017. + ret = bcm2708_fb_register(fb);
  96018. + if (ret == 0) {
  96019. + platform_set_drvdata(dev, fb);
  96020. + goto out;
  96021. + }
  96022. +
  96023. +free_dma_chan:
  96024. + bcm_dma_chan_free(fb->dma_chan);
  96025. +free_cb:
  96026. + dma_free_writecombine(&dev->dev, SZ_64K, fb->cb_base, fb->cb_handle);
  96027. +free_fb:
  96028. + kfree(fb);
  96029. +free_region:
  96030. + dev_err(&dev->dev, "probe failed, err %d\n", ret);
  96031. +out:
  96032. + return ret;
  96033. +}
  96034. +
  96035. +static int bcm2708_fb_remove(struct platform_device *dev)
  96036. +{
  96037. + struct bcm2708_fb *fb = platform_get_drvdata(dev);
  96038. +
  96039. + platform_set_drvdata(dev, NULL);
  96040. +
  96041. + if (fb->fb.screen_base)
  96042. + iounmap(fb->fb.screen_base);
  96043. + unregister_framebuffer(&fb->fb);
  96044. +
  96045. + dma_free_writecombine(&dev->dev, SZ_64K, fb->cb_base, fb->cb_handle);
  96046. + bcm_dma_chan_free(fb->dma_chan);
  96047. +
  96048. + dma_free_coherent(NULL, PAGE_ALIGN(sizeof(*fb->info)), (void *)fb->info,
  96049. + fb->dma);
  96050. + bcm2708_fb_debugfs_deinit(fb);
  96051. +
  96052. + free_irq(fb->dma_irq, fb);
  96053. +
  96054. + kfree(fb);
  96055. +
  96056. + return 0;
  96057. +}
  96058. +
  96059. +static struct platform_driver bcm2708_fb_driver = {
  96060. + .probe = bcm2708_fb_probe,
  96061. + .remove = bcm2708_fb_remove,
  96062. + .driver = {
  96063. + .name = DRIVER_NAME,
  96064. + .owner = THIS_MODULE,
  96065. + },
  96066. +};
  96067. +
  96068. +static int __init bcm2708_fb_init(void)
  96069. +{
  96070. + return platform_driver_register(&bcm2708_fb_driver);
  96071. +}
  96072. +
  96073. +module_init(bcm2708_fb_init);
  96074. +
  96075. +static void __exit bcm2708_fb_exit(void)
  96076. +{
  96077. + platform_driver_unregister(&bcm2708_fb_driver);
  96078. +}
  96079. +
  96080. +module_exit(bcm2708_fb_exit);
  96081. +
  96082. +module_param(fbwidth, int, 0644);
  96083. +module_param(fbheight, int, 0644);
  96084. +module_param(fbdepth, int, 0644);
  96085. +module_param(fbswap, int, 0644);
  96086. +
  96087. +MODULE_DESCRIPTION("BCM2708 framebuffer driver");
  96088. +MODULE_LICENSE("GPL");
  96089. +
  96090. +MODULE_PARM_DESC(fbwidth, "Width of ARM Framebuffer");
  96091. +MODULE_PARM_DESC(fbheight, "Height of ARM Framebuffer");
  96092. +MODULE_PARM_DESC(fbdepth, "Bit depth of ARM Framebuffer");
  96093. +MODULE_PARM_DESC(fbswap, "Swap order of red and blue in 24 and 32 bit modes");
  96094. diff -Nur linux-3.12.26.orig/drivers/video/cfbimgblt.c linux-3.12.26/drivers/video/cfbimgblt.c
  96095. --- linux-3.12.26.orig/drivers/video/cfbimgblt.c 2014-07-30 18:02:44.000000000 +0200
  96096. +++ linux-3.12.26/drivers/video/cfbimgblt.c 2014-08-06 16:50:14.921965669 +0200
  96097. @@ -28,6 +28,11 @@
  96098. *
  96099. * Also need to add code to deal with cards endians that are different than
  96100. * the native cpu endians. I also need to deal with MSB position in the word.
  96101. + * Modified by Harm Hanemaaijer (fgenfb@yahoo.com) 2013:
  96102. + * - Provide optimized versions of fast_imageblit for 16 and 32bpp that are
  96103. + * significantly faster than the previous implementation.
  96104. + * - Simplify the fast/slow_imageblit selection code, avoiding integer
  96105. + * divides.
  96106. */
  96107. #include <linux/module.h>
  96108. #include <linux/string.h>
  96109. @@ -262,6 +267,133 @@
  96110. }
  96111. }
  96112. +/*
  96113. + * Optimized fast_imageblit for bpp == 16. ppw = 2, bit_mask = 3 folded
  96114. + * into the code, main loop unrolled.
  96115. + */
  96116. +
  96117. +static inline void fast_imageblit16(const struct fb_image *image,
  96118. + struct fb_info *p, u8 __iomem * dst1,
  96119. + u32 fgcolor, u32 bgcolor)
  96120. +{
  96121. + u32 fgx = fgcolor, bgx = bgcolor;
  96122. + u32 spitch = (image->width + 7) / 8;
  96123. + u32 end_mask, eorx;
  96124. + const char *s = image->data, *src;
  96125. + u32 __iomem *dst;
  96126. + const u32 *tab = NULL;
  96127. + int i, j, k;
  96128. +
  96129. + tab = fb_be_math(p) ? cfb_tab16_be : cfb_tab16_le;
  96130. +
  96131. + fgx <<= 16;
  96132. + bgx <<= 16;
  96133. + fgx |= fgcolor;
  96134. + bgx |= bgcolor;
  96135. +
  96136. + eorx = fgx ^ bgx;
  96137. + k = image->width / 2;
  96138. +
  96139. + for (i = image->height; i--;) {
  96140. + dst = (u32 __iomem *) dst1;
  96141. + src = s;
  96142. +
  96143. + j = k;
  96144. + while (j >= 4) {
  96145. + u8 bits = *src;
  96146. + end_mask = tab[(bits >> 6) & 3];
  96147. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96148. + end_mask = tab[(bits >> 4) & 3];
  96149. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96150. + end_mask = tab[(bits >> 2) & 3];
  96151. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96152. + end_mask = tab[bits & 3];
  96153. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96154. + src++;
  96155. + j -= 4;
  96156. + }
  96157. + if (j != 0) {
  96158. + u8 bits = *src;
  96159. + end_mask = tab[(bits >> 6) & 3];
  96160. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96161. + if (j >= 2) {
  96162. + end_mask = tab[(bits >> 4) & 3];
  96163. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96164. + if (j == 3) {
  96165. + end_mask = tab[(bits >> 2) & 3];
  96166. + FB_WRITEL((end_mask & eorx) ^ bgx, dst);
  96167. + }
  96168. + }
  96169. + }
  96170. + dst1 += p->fix.line_length;
  96171. + s += spitch;
  96172. + }
  96173. +}
  96174. +
  96175. +/*
  96176. + * Optimized fast_imageblit for bpp == 32. ppw = 1, bit_mask = 1 folded
  96177. + * into the code, main loop unrolled.
  96178. + */
  96179. +
  96180. +static inline void fast_imageblit32(const struct fb_image *image,
  96181. + struct fb_info *p, u8 __iomem * dst1,
  96182. + u32 fgcolor, u32 bgcolor)
  96183. +{
  96184. + u32 fgx = fgcolor, bgx = bgcolor;
  96185. + u32 spitch = (image->width + 7) / 8;
  96186. + u32 end_mask, eorx;
  96187. + const char *s = image->data, *src;
  96188. + u32 __iomem *dst;
  96189. + const u32 *tab = NULL;
  96190. + int i, j, k;
  96191. +
  96192. + tab = cfb_tab32;
  96193. +
  96194. + eorx = fgx ^ bgx;
  96195. + k = image->width;
  96196. +
  96197. + for (i = image->height; i--;) {
  96198. + dst = (u32 __iomem *) dst1;
  96199. + src = s;
  96200. +
  96201. + j = k;
  96202. + while (j >= 8) {
  96203. + u8 bits = *src;
  96204. + end_mask = tab[(bits >> 7) & 1];
  96205. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96206. + end_mask = tab[(bits >> 6) & 1];
  96207. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96208. + end_mask = tab[(bits >> 5) & 1];
  96209. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96210. + end_mask = tab[(bits >> 4) & 1];
  96211. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96212. + end_mask = tab[(bits >> 3) & 1];
  96213. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96214. + end_mask = tab[(bits >> 2) & 1];
  96215. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96216. + end_mask = tab[(bits >> 1) & 1];
  96217. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96218. + end_mask = tab[bits & 1];
  96219. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96220. + src++;
  96221. + j -= 8;
  96222. + }
  96223. + if (j != 0) {
  96224. + u32 bits = (u32) * src;
  96225. + while (j > 1) {
  96226. + end_mask = tab[(bits >> 7) & 1];
  96227. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  96228. + bits <<= 1;
  96229. + j--;
  96230. + }
  96231. + end_mask = tab[(bits >> 7) & 1];
  96232. + FB_WRITEL((end_mask & eorx) ^ bgx, dst);
  96233. + }
  96234. + dst1 += p->fix.line_length;
  96235. + s += spitch;
  96236. + }
  96237. +}
  96238. +
  96239. void cfb_imageblit(struct fb_info *p, const struct fb_image *image)
  96240. {
  96241. u32 fgcolor, bgcolor, start_index, bitstart, pitch_index = 0;
  96242. @@ -294,11 +426,21 @@
  96243. bgcolor = image->bg_color;
  96244. }
  96245. - if (32 % bpp == 0 && !start_index && !pitch_index &&
  96246. - ((width & (32/bpp-1)) == 0) &&
  96247. - bpp >= 8 && bpp <= 32)
  96248. - fast_imageblit(image, p, dst1, fgcolor, bgcolor);
  96249. - else
  96250. + if (!start_index && !pitch_index) {
  96251. + if (bpp == 32)
  96252. + fast_imageblit32(image, p, dst1, fgcolor,
  96253. + bgcolor);
  96254. + else if (bpp == 16 && (width & 1) == 0)
  96255. + fast_imageblit16(image, p, dst1, fgcolor,
  96256. + bgcolor);
  96257. + else if (bpp == 8 && (width & 3) == 0)
  96258. + fast_imageblit(image, p, dst1, fgcolor,
  96259. + bgcolor);
  96260. + else
  96261. + slow_imageblit(image, p, dst1, fgcolor,
  96262. + bgcolor,
  96263. + start_index, pitch_index);
  96264. + } else
  96265. slow_imageblit(image, p, dst1, fgcolor, bgcolor,
  96266. start_index, pitch_index);
  96267. } else
  96268. diff -Nur linux-3.12.26.orig/drivers/video/fbmem.c linux-3.12.26/drivers/video/fbmem.c
  96269. --- linux-3.12.26.orig/drivers/video/fbmem.c 2014-07-30 18:02:44.000000000 +0200
  96270. +++ linux-3.12.26/drivers/video/fbmem.c 2014-08-06 16:50:14.941965825 +0200
  96271. @@ -1083,6 +1083,25 @@
  96272. }
  96273. EXPORT_SYMBOL(fb_blank);
  96274. +static int fb_copyarea_user(struct fb_info *info,
  96275. + struct fb_copyarea *copy)
  96276. +{
  96277. + int ret = 0;
  96278. + if (!lock_fb_info(info))
  96279. + return -ENODEV;
  96280. + if (copy->dx + copy->width > info->var.xres ||
  96281. + copy->sx + copy->width > info->var.xres ||
  96282. + copy->dy + copy->height > info->var.yres ||
  96283. + copy->sy + copy->height > info->var.yres) {
  96284. + ret = -EINVAL;
  96285. + goto out;
  96286. + }
  96287. + info->fbops->fb_copyarea(info, copy);
  96288. +out:
  96289. + unlock_fb_info(info);
  96290. + return ret;
  96291. +}
  96292. +
  96293. static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
  96294. unsigned long arg)
  96295. {
  96296. @@ -1093,6 +1112,7 @@
  96297. struct fb_cmap cmap_from;
  96298. struct fb_cmap_user cmap;
  96299. struct fb_event event;
  96300. + struct fb_copyarea copy;
  96301. void __user *argp = (void __user *)arg;
  96302. long ret = 0;
  96303. @@ -1108,16 +1128,14 @@
  96304. case FBIOPUT_VSCREENINFO:
  96305. if (copy_from_user(&var, argp, sizeof(var)))
  96306. return -EFAULT;
  96307. - console_lock();
  96308. - if (!lock_fb_info(info)) {
  96309. - console_unlock();
  96310. + if (!lock_fb_info(info))
  96311. return -ENODEV;
  96312. - }
  96313. + console_lock();
  96314. info->flags |= FBINFO_MISC_USEREVENT;
  96315. ret = fb_set_var(info, &var);
  96316. info->flags &= ~FBINFO_MISC_USEREVENT;
  96317. - unlock_fb_info(info);
  96318. console_unlock();
  96319. + unlock_fb_info(info);
  96320. if (!ret && copy_to_user(argp, &var, sizeof(var)))
  96321. ret = -EFAULT;
  96322. break;
  96323. @@ -1146,14 +1164,12 @@
  96324. case FBIOPAN_DISPLAY:
  96325. if (copy_from_user(&var, argp, sizeof(var)))
  96326. return -EFAULT;
  96327. - console_lock();
  96328. - if (!lock_fb_info(info)) {
  96329. - console_unlock();
  96330. + if (!lock_fb_info(info))
  96331. return -ENODEV;
  96332. - }
  96333. + console_lock();
  96334. ret = fb_pan_display(info, &var);
  96335. - unlock_fb_info(info);
  96336. console_unlock();
  96337. + unlock_fb_info(info);
  96338. if (ret == 0 && copy_to_user(argp, &var, sizeof(var)))
  96339. return -EFAULT;
  96340. break;
  96341. @@ -1188,28 +1204,33 @@
  96342. break;
  96343. }
  96344. event.data = &con2fb;
  96345. - console_lock();
  96346. - if (!lock_fb_info(info)) {
  96347. - console_unlock();
  96348. + if (!lock_fb_info(info))
  96349. return -ENODEV;
  96350. - }
  96351. + console_lock();
  96352. event.info = info;
  96353. ret = fb_notifier_call_chain(FB_EVENT_SET_CONSOLE_MAP, &event);
  96354. - unlock_fb_info(info);
  96355. console_unlock();
  96356. + unlock_fb_info(info);
  96357. break;
  96358. case FBIOBLANK:
  96359. - console_lock();
  96360. - if (!lock_fb_info(info)) {
  96361. - console_unlock();
  96362. + if (!lock_fb_info(info))
  96363. return -ENODEV;
  96364. - }
  96365. + console_lock();
  96366. info->flags |= FBINFO_MISC_USEREVENT;
  96367. ret = fb_blank(info, arg);
  96368. info->flags &= ~FBINFO_MISC_USEREVENT;
  96369. - unlock_fb_info(info);
  96370. console_unlock();
  96371. + unlock_fb_info(info);
  96372. break;
  96373. + case FBIOCOPYAREA:
  96374. + if (info->flags & FBINFO_HWACCEL_COPYAREA) {
  96375. + /* only provide this ioctl if it is accelerated */
  96376. + if (copy_from_user(&copy, argp, sizeof(copy)))
  96377. + return -EFAULT;
  96378. + ret = fb_copyarea_user(info, &copy);
  96379. + break;
  96380. + }
  96381. + /* fall through */
  96382. default:
  96383. if (!lock_fb_info(info))
  96384. return -ENODEV;
  96385. @@ -1364,6 +1385,7 @@
  96386. case FBIOPAN_DISPLAY:
  96387. case FBIOGET_CON2FBMAP:
  96388. case FBIOPUT_CON2FBMAP:
  96389. + case FBIOCOPYAREA:
  96390. arg = (unsigned long) compat_ptr(arg);
  96391. case FBIOBLANK:
  96392. ret = do_fb_ioctl(info, cmd, arg);
  96393. @@ -1577,10 +1599,10 @@
  96394. static int do_unregister_framebuffer(struct fb_info *fb_info);
  96395. #define VGA_FB_PHYS 0xA0000
  96396. -static int do_remove_conflicting_framebuffers(struct apertures_struct *a,
  96397. - const char *name, bool primary)
  96398. +static void do_remove_conflicting_framebuffers(struct apertures_struct *a,
  96399. + const char *name, bool primary)
  96400. {
  96401. - int i, ret;
  96402. + int i;
  96403. /* check all firmware fbs and kick off if the base addr overlaps */
  96404. for (i = 0 ; i < FB_MAX; i++) {
  96405. @@ -1596,31 +1618,25 @@
  96406. (primary && gen_aper && gen_aper->count &&
  96407. gen_aper->ranges[0].base == VGA_FB_PHYS)) {
  96408. - printk(KERN_INFO "fb: switching to %s from %s\n",
  96409. + printk(KERN_INFO "fb: conflicting fb hw usage "
  96410. + "%s vs %s - removing generic driver\n",
  96411. name, registered_fb[i]->fix.id);
  96412. - ret = do_unregister_framebuffer(registered_fb[i]);
  96413. - if (ret)
  96414. - return ret;
  96415. + do_unregister_framebuffer(registered_fb[i]);
  96416. }
  96417. }
  96418. -
  96419. - return 0;
  96420. }
  96421. static int do_register_framebuffer(struct fb_info *fb_info)
  96422. {
  96423. - int i, ret;
  96424. + int i;
  96425. struct fb_event event;
  96426. struct fb_videomode mode;
  96427. if (fb_check_foreignness(fb_info))
  96428. return -ENOSYS;
  96429. - ret = do_remove_conflicting_framebuffers(fb_info->apertures,
  96430. - fb_info->fix.id,
  96431. - fb_is_primary_device(fb_info));
  96432. - if (ret)
  96433. - return ret;
  96434. + do_remove_conflicting_framebuffers(fb_info->apertures, fb_info->fix.id,
  96435. + fb_is_primary_device(fb_info));
  96436. if (num_registered_fb == FB_MAX)
  96437. return -ENXIO;
  96438. @@ -1674,15 +1690,12 @@
  96439. registered_fb[i] = fb_info;
  96440. event.info = fb_info;
  96441. - console_lock();
  96442. - if (!lock_fb_info(fb_info)) {
  96443. - console_unlock();
  96444. + if (!lock_fb_info(fb_info))
  96445. return -ENODEV;
  96446. - }
  96447. -
  96448. + console_lock();
  96449. fb_notifier_call_chain(FB_EVENT_FB_REGISTERED, &event);
  96450. - unlock_fb_info(fb_info);
  96451. console_unlock();
  96452. + unlock_fb_info(fb_info);
  96453. return 0;
  96454. }
  96455. @@ -1695,16 +1708,13 @@
  96456. if (i < 0 || i >= FB_MAX || registered_fb[i] != fb_info)
  96457. return -EINVAL;
  96458. - console_lock();
  96459. - if (!lock_fb_info(fb_info)) {
  96460. - console_unlock();
  96461. + if (!lock_fb_info(fb_info))
  96462. return -ENODEV;
  96463. - }
  96464. -
  96465. + console_lock();
  96466. event.info = fb_info;
  96467. ret = fb_notifier_call_chain(FB_EVENT_FB_UNBIND, &event);
  96468. - unlock_fb_info(fb_info);
  96469. console_unlock();
  96470. + unlock_fb_info(fb_info);
  96471. if (ret)
  96472. return -EINVAL;
  96473. @@ -1745,16 +1755,12 @@
  96474. }
  96475. EXPORT_SYMBOL(unlink_framebuffer);
  96476. -int remove_conflicting_framebuffers(struct apertures_struct *a,
  96477. - const char *name, bool primary)
  96478. +void remove_conflicting_framebuffers(struct apertures_struct *a,
  96479. + const char *name, bool primary)
  96480. {
  96481. - int ret;
  96482. -
  96483. mutex_lock(&registration_lock);
  96484. - ret = do_remove_conflicting_framebuffers(a, name, primary);
  96485. + do_remove_conflicting_framebuffers(a, name, primary);
  96486. mutex_unlock(&registration_lock);
  96487. -
  96488. - return ret;
  96489. }
  96490. EXPORT_SYMBOL(remove_conflicting_framebuffers);
  96491. diff -Nur linux-3.12.26.orig/drivers/video/fbsysfs.c linux-3.12.26/drivers/video/fbsysfs.c
  96492. --- linux-3.12.26.orig/drivers/video/fbsysfs.c 2014-07-30 18:02:44.000000000 +0200
  96493. +++ linux-3.12.26/drivers/video/fbsysfs.c 2014-08-06 16:50:14.945965857 +0200
  96494. @@ -177,12 +177,9 @@
  96495. if (i * sizeof(struct fb_videomode) != count)
  96496. return -EINVAL;
  96497. - console_lock();
  96498. - if (!lock_fb_info(fb_info)) {
  96499. - console_unlock();
  96500. + if (!lock_fb_info(fb_info))
  96501. return -ENODEV;
  96502. - }
  96503. -
  96504. + console_lock();
  96505. list_splice(&fb_info->modelist, &old_list);
  96506. fb_videomode_to_modelist((const struct fb_videomode *)buf, i,
  96507. &fb_info->modelist);
  96508. @@ -192,8 +189,8 @@
  96509. } else
  96510. fb_destroy_modelist(&old_list);
  96511. - unlock_fb_info(fb_info);
  96512. console_unlock();
  96513. + unlock_fb_info(fb_info);
  96514. return 0;
  96515. }
  96516. @@ -407,16 +404,12 @@
  96517. state = simple_strtoul(buf, &last, 0);
  96518. - console_lock();
  96519. - if (!lock_fb_info(fb_info)) {
  96520. - console_unlock();
  96521. + if (!lock_fb_info(fb_info))
  96522. return -ENODEV;
  96523. - }
  96524. -
  96525. + console_lock();
  96526. fb_set_suspend(fb_info, (int)state);
  96527. -
  96528. - unlock_fb_info(fb_info);
  96529. console_unlock();
  96530. + unlock_fb_info(fb_info);
  96531. return count;
  96532. }
  96533. diff -Nur linux-3.12.26.orig/drivers/video/Kconfig linux-3.12.26/drivers/video/Kconfig
  96534. --- linux-3.12.26.orig/drivers/video/Kconfig 2014-07-30 18:02:44.000000000 +0200
  96535. +++ linux-3.12.26/drivers/video/Kconfig 2014-08-06 16:50:14.949965888 +0200
  96536. @@ -310,6 +310,20 @@
  96537. help
  96538. Support the Permedia2 FIFO disconnect feature.
  96539. +config FB_BCM2708
  96540. + tristate "BCM2708 framebuffer support"
  96541. + depends on FB && ARM
  96542. + select FB_CFB_FILLRECT
  96543. + select FB_CFB_COPYAREA
  96544. + select FB_CFB_IMAGEBLIT
  96545. + help
  96546. + This framebuffer device driver is for the BCM2708 framebuffer.
  96547. +
  96548. + If you want to compile this as a module (=code which can be
  96549. + inserted into and removed from the running kernel), say M
  96550. + here and read <file:Documentation/kbuild/modules.txt>. The module
  96551. + will be called bcm2708_fb.
  96552. +
  96553. config FB_ARMCLCD
  96554. tristate "ARM PrimeCell PL110 support"
  96555. depends on FB && ARM && ARM_AMBA
  96556. diff -Nur linux-3.12.26.orig/drivers/video/logo/logo_linux_clut224.ppm linux-3.12.26/drivers/video/logo/logo_linux_clut224.ppm
  96557. --- linux-3.12.26.orig/drivers/video/logo/logo_linux_clut224.ppm 2014-07-30 18:02:44.000000000 +0200
  96558. +++ linux-3.12.26/drivers/video/logo/logo_linux_clut224.ppm 2014-08-06 16:50:14.953965920 +0200
  96559. @@ -1,1604 +1,883 @@
  96560. P3
  96561. -# Standard 224-color Linux logo
  96562. -80 80
  96563. +63 80
  96564. 255
  96565. - 0 0 0 0 0 0 0 0 0 0 0 0
  96566. - 0 0 0 0 0 0 0 0 0 0 0 0
  96567. - 0 0 0 0 0 0 0 0 0 0 0 0
  96568. - 0 0 0 0 0 0 0 0 0 0 0 0
  96569. - 0 0 0 0 0 0 0 0 0 0 0 0
  96570. - 0 0 0 0 0 0 0 0 0 0 0 0
  96571. - 0 0 0 0 0 0 0 0 0 0 0 0
  96572. - 0 0 0 0 0 0 0 0 0 0 0 0
  96573. - 0 0 0 0 0 0 0 0 0 0 0 0
  96574. - 6 6 6 6 6 6 10 10 10 10 10 10
  96575. - 10 10 10 6 6 6 6 6 6 6 6 6
  96576. - 0 0 0 0 0 0 0 0 0 0 0 0
  96577. - 0 0 0 0 0 0 0 0 0 0 0 0
  96578. - 0 0 0 0 0 0 0 0 0 0 0 0
  96579. - 0 0 0 0 0 0 0 0 0 0 0 0
  96580. - 0 0 0 0 0 0 0 0 0 0 0 0
  96581. - 0 0 0 0 0 0 0 0 0 0 0 0
  96582. - 0 0 0 0 0 0 0 0 0 0 0 0
  96583. - 0 0 0 0 0 0 0 0 0 0 0 0
  96584. - 0 0 0 0 0 0 0 0 0 0 0 0
  96585. - 0 0 0 0 0 0 0 0 0 0 0 0
  96586. - 0 0 0 0 0 0 0 0 0 0 0 0
  96587. - 0 0 0 0 0 0 0 0 0 0 0 0
  96588. - 0 0 0 0 0 0 0 0 0 0 0 0
  96589. - 0 0 0 0 0 0 0 0 0 0 0 0
  96590. - 0 0 0 0 0 0 0 0 0 0 0 0
  96591. - 0 0 0 0 0 0 0 0 0 0 0 0
  96592. - 0 0 0 0 0 0 0 0 0 0 0 0
  96593. - 0 0 0 6 6 6 10 10 10 14 14 14
  96594. - 22 22 22 26 26 26 30 30 30 34 34 34
  96595. - 30 30 30 30 30 30 26 26 26 18 18 18
  96596. - 14 14 14 10 10 10 6 6 6 0 0 0
  96597. - 0 0 0 0 0 0 0 0 0 0 0 0
  96598. - 0 0 0 0 0 0 0 0 0 0 0 0
  96599. - 0 0 0 0 0 0 0 0 0 0 0 0
  96600. - 0 0 0 0 0 0 0 0 0 0 0 0
  96601. - 0 0 0 0 0 0 0 0 0 0 0 0
  96602. - 0 0 0 0 0 0 0 0 0 0 0 0
  96603. - 0 0 0 0 0 0 0 0 0 0 0 0
  96604. - 0 0 0 0 0 0 0 0 0 0 0 0
  96605. - 0 0 0 0 0 0 0 0 0 0 0 0
  96606. - 0 0 0 0 0 1 0 0 1 0 0 0
  96607. - 0 0 0 0 0 0 0 0 0 0 0 0
  96608. - 0 0 0 0 0 0 0 0 0 0 0 0
  96609. - 0 0 0 0 0 0 0 0 0 0 0 0
  96610. - 0 0 0 0 0 0 0 0 0 0 0 0
  96611. - 0 0 0 0 0 0 0 0 0 0 0 0
  96612. - 0 0 0 0 0 0 0 0 0 0 0 0
  96613. - 6 6 6 14 14 14 26 26 26 42 42 42
  96614. - 54 54 54 66 66 66 78 78 78 78 78 78
  96615. - 78 78 78 74 74 74 66 66 66 54 54 54
  96616. - 42 42 42 26 26 26 18 18 18 10 10 10
  96617. - 6 6 6 0 0 0 0 0 0 0 0 0
  96618. - 0 0 0 0 0 0 0 0 0 0 0 0
  96619. - 0 0 0 0 0 0 0 0 0 0 0 0
  96620. - 0 0 0 0 0 0 0 0 0 0 0 0
  96621. - 0 0 0 0 0 0 0 0 0 0 0 0
  96622. - 0 0 0 0 0 0 0 0 0 0 0 0
  96623. - 0 0 0 0 0 0 0 0 0 0 0 0
  96624. - 0 0 0 0 0 0 0 0 0 0 0 0
  96625. - 0 0 0 0 0 0 0 0 0 0 0 0
  96626. - 0 0 1 0 0 0 0 0 0 0 0 0
  96627. - 0 0 0 0 0 0 0 0 0 0 0 0
  96628. - 0 0 0 0 0 0 0 0 0 0 0 0
  96629. - 0 0 0 0 0 0 0 0 0 0 0 0
  96630. - 0 0 0 0 0 0 0 0 0 0 0 0
  96631. - 0 0 0 0 0 0 0 0 0 0 0 0
  96632. - 0 0 0 0 0 0 0 0 0 10 10 10
  96633. - 22 22 22 42 42 42 66 66 66 86 86 86
  96634. - 66 66 66 38 38 38 38 38 38 22 22 22
  96635. - 26 26 26 34 34 34 54 54 54 66 66 66
  96636. - 86 86 86 70 70 70 46 46 46 26 26 26
  96637. - 14 14 14 6 6 6 0 0 0 0 0 0
  96638. - 0 0 0 0 0 0 0 0 0 0 0 0
  96639. - 0 0 0 0 0 0 0 0 0 0 0 0
  96640. - 0 0 0 0 0 0 0 0 0 0 0 0
  96641. - 0 0 0 0 0 0 0 0 0 0 0 0
  96642. - 0 0 0 0 0 0 0 0 0 0 0 0
  96643. - 0 0 0 0 0 0 0 0 0 0 0 0
  96644. - 0 0 0 0 0 0 0 0 0 0 0 0
  96645. - 0 0 0 0 0 0 0 0 0 0 0 0
  96646. - 0 0 1 0 0 1 0 0 1 0 0 0
  96647. - 0 0 0 0 0 0 0 0 0 0 0 0
  96648. - 0 0 0 0 0 0 0 0 0 0 0 0
  96649. - 0 0 0 0 0 0 0 0 0 0 0 0
  96650. - 0 0 0 0 0 0 0 0 0 0 0 0
  96651. - 0 0 0 0 0 0 0 0 0 0 0 0
  96652. - 0 0 0 0 0 0 10 10 10 26 26 26
  96653. - 50 50 50 82 82 82 58 58 58 6 6 6
  96654. - 2 2 6 2 2 6 2 2 6 2 2 6
  96655. - 2 2 6 2 2 6 2 2 6 2 2 6
  96656. - 6 6 6 54 54 54 86 86 86 66 66 66
  96657. - 38 38 38 18 18 18 6 6 6 0 0 0
  96658. - 0 0 0 0 0 0 0 0 0 0 0 0
  96659. - 0 0 0 0 0 0 0 0 0 0 0 0
  96660. - 0 0 0 0 0 0 0 0 0 0 0 0
  96661. - 0 0 0 0 0 0 0 0 0 0 0 0
  96662. - 0 0 0 0 0 0 0 0 0 0 0 0
  96663. - 0 0 0 0 0 0 0 0 0 0 0 0
  96664. - 0 0 0 0 0 0 0 0 0 0 0 0
  96665. - 0 0 0 0 0 0 0 0 0 0 0 0
  96666. - 0 0 0 0 0 0 0 0 0 0 0 0
  96667. - 0 0 0 0 0 0 0 0 0 0 0 0
  96668. - 0 0 0 0 0 0 0 0 0 0 0 0
  96669. - 0 0 0 0 0 0 0 0 0 0 0 0
  96670. - 0 0 0 0 0 0 0 0 0 0 0 0
  96671. - 0 0 0 0 0 0 0 0 0 0 0 0
  96672. - 0 0 0 6 6 6 22 22 22 50 50 50
  96673. - 78 78 78 34 34 34 2 2 6 2 2 6
  96674. - 2 2 6 2 2 6 2 2 6 2 2 6
  96675. - 2 2 6 2 2 6 2 2 6 2 2 6
  96676. - 2 2 6 2 2 6 6 6 6 70 70 70
  96677. - 78 78 78 46 46 46 22 22 22 6 6 6
  96678. - 0 0 0 0 0 0 0 0 0 0 0 0
  96679. - 0 0 0 0 0 0 0 0 0 0 0 0
  96680. - 0 0 0 0 0 0 0 0 0 0 0 0
  96681. - 0 0 0 0 0 0 0 0 0 0 0 0
  96682. - 0 0 0 0 0 0 0 0 0 0 0 0
  96683. - 0 0 0 0 0 0 0 0 0 0 0 0
  96684. - 0 0 0 0 0 0 0 0 0 0 0 0
  96685. - 0 0 0 0 0 0 0 0 0 0 0 0
  96686. - 0 0 1 0 0 1 0 0 1 0 0 0
  96687. - 0 0 0 0 0 0 0 0 0 0 0 0
  96688. - 0 0 0 0 0 0 0 0 0 0 0 0
  96689. - 0 0 0 0 0 0 0 0 0 0 0 0
  96690. - 0 0 0 0 0 0 0 0 0 0 0 0
  96691. - 0 0 0 0 0 0 0 0 0 0 0 0
  96692. - 6 6 6 18 18 18 42 42 42 82 82 82
  96693. - 26 26 26 2 2 6 2 2 6 2 2 6
  96694. - 2 2 6 2 2 6 2 2 6 2 2 6
  96695. - 2 2 6 2 2 6 2 2 6 14 14 14
  96696. - 46 46 46 34 34 34 6 6 6 2 2 6
  96697. - 42 42 42 78 78 78 42 42 42 18 18 18
  96698. - 6 6 6 0 0 0 0 0 0 0 0 0
  96699. - 0 0 0 0 0 0 0 0 0 0 0 0
  96700. - 0 0 0 0 0 0 0 0 0 0 0 0
  96701. - 0 0 0 0 0 0 0 0 0 0 0 0
  96702. - 0 0 0 0 0 0 0 0 0 0 0 0
  96703. - 0 0 0 0 0 0 0 0 0 0 0 0
  96704. - 0 0 0 0 0 0 0 0 0 0 0 0
  96705. - 0 0 0 0 0 0 0 0 0 0 0 0
  96706. - 0 0 1 0 0 0 0 0 1 0 0 0
  96707. - 0 0 0 0 0 0 0 0 0 0 0 0
  96708. - 0 0 0 0 0 0 0 0 0 0 0 0
  96709. - 0 0 0 0 0 0 0 0 0 0 0 0
  96710. - 0 0 0 0 0 0 0 0 0 0 0 0
  96711. - 0 0 0 0 0 0 0 0 0 0 0 0
  96712. - 10 10 10 30 30 30 66 66 66 58 58 58
  96713. - 2 2 6 2 2 6 2 2 6 2 2 6
  96714. - 2 2 6 2 2 6 2 2 6 2 2 6
  96715. - 2 2 6 2 2 6 2 2 6 26 26 26
  96716. - 86 86 86 101 101 101 46 46 46 10 10 10
  96717. - 2 2 6 58 58 58 70 70 70 34 34 34
  96718. - 10 10 10 0 0 0 0 0 0 0 0 0
  96719. - 0 0 0 0 0 0 0 0 0 0 0 0
  96720. - 0 0 0 0 0 0 0 0 0 0 0 0
  96721. - 0 0 0 0 0 0 0 0 0 0 0 0
  96722. - 0 0 0 0 0 0 0 0 0 0 0 0
  96723. - 0 0 0 0 0 0 0 0 0 0 0 0
  96724. - 0 0 0 0 0 0 0 0 0 0 0 0
  96725. - 0 0 0 0 0 0 0 0 0 0 0 0
  96726. - 0 0 1 0 0 1 0 0 1 0 0 0
  96727. - 0 0 0 0 0 0 0 0 0 0 0 0
  96728. - 0 0 0 0 0 0 0 0 0 0 0 0
  96729. - 0 0 0 0 0 0 0 0 0 0 0 0
  96730. - 0 0 0 0 0 0 0 0 0 0 0 0
  96731. - 0 0 0 0 0 0 0 0 0 0 0 0
  96732. - 14 14 14 42 42 42 86 86 86 10 10 10
  96733. - 2 2 6 2 2 6 2 2 6 2 2 6
  96734. - 2 2 6 2 2 6 2 2 6 2 2 6
  96735. - 2 2 6 2 2 6 2 2 6 30 30 30
  96736. - 94 94 94 94 94 94 58 58 58 26 26 26
  96737. - 2 2 6 6 6 6 78 78 78 54 54 54
  96738. - 22 22 22 6 6 6 0 0 0 0 0 0
  96739. - 0 0 0 0 0 0 0 0 0 0 0 0
  96740. - 0 0 0 0 0 0 0 0 0 0 0 0
  96741. - 0 0 0 0 0 0 0 0 0 0 0 0
  96742. - 0 0 0 0 0 0 0 0 0 0 0 0
  96743. - 0 0 0 0 0 0 0 0 0 0 0 0
  96744. - 0 0 0 0 0 0 0 0 0 0 0 0
  96745. - 0 0 0 0 0 0 0 0 0 0 0 0
  96746. - 0 0 0 0 0 0 0 0 0 0 0 0
  96747. - 0 0 0 0 0 0 0 0 0 0 0 0
  96748. - 0 0 0 0 0 0 0 0 0 0 0 0
  96749. - 0 0 0 0 0 0 0 0 0 0 0 0
  96750. - 0 0 0 0 0 0 0 0 0 0 0 0
  96751. - 0 0 0 0 0 0 0 0 0 6 6 6
  96752. - 22 22 22 62 62 62 62 62 62 2 2 6
  96753. - 2 2 6 2 2 6 2 2 6 2 2 6
  96754. - 2 2 6 2 2 6 2 2 6 2 2 6
  96755. - 2 2 6 2 2 6 2 2 6 26 26 26
  96756. - 54 54 54 38 38 38 18 18 18 10 10 10
  96757. - 2 2 6 2 2 6 34 34 34 82 82 82
  96758. - 38 38 38 14 14 14 0 0 0 0 0 0
  96759. - 0 0 0 0 0 0 0 0 0 0 0 0
  96760. - 0 0 0 0 0 0 0 0 0 0 0 0
  96761. - 0 0 0 0 0 0 0 0 0 0 0 0
  96762. - 0 0 0 0 0 0 0 0 0 0 0 0
  96763. - 0 0 0 0 0 0 0 0 0 0 0 0
  96764. - 0 0 0 0 0 0 0 0 0 0 0 0
  96765. - 0 0 0 0 0 0 0 0 0 0 0 0
  96766. - 0 0 0 0 0 1 0 0 1 0 0 0
  96767. - 0 0 0 0 0 0 0 0 0 0 0 0
  96768. - 0 0 0 0 0 0 0 0 0 0 0 0
  96769. - 0 0 0 0 0 0 0 0 0 0 0 0
  96770. - 0 0 0 0 0 0 0 0 0 0 0 0
  96771. - 0 0 0 0 0 0 0 0 0 6 6 6
  96772. - 30 30 30 78 78 78 30 30 30 2 2 6
  96773. - 2 2 6 2 2 6 2 2 6 2 2 6
  96774. - 2 2 6 2 2 6 2 2 6 2 2 6
  96775. - 2 2 6 2 2 6 2 2 6 10 10 10
  96776. - 10 10 10 2 2 6 2 2 6 2 2 6
  96777. - 2 2 6 2 2 6 2 2 6 78 78 78
  96778. - 50 50 50 18 18 18 6 6 6 0 0 0
  96779. - 0 0 0 0 0 0 0 0 0 0 0 0
  96780. - 0 0 0 0 0 0 0 0 0 0 0 0
  96781. - 0 0 0 0 0 0 0 0 0 0 0 0
  96782. - 0 0 0 0 0 0 0 0 0 0 0 0
  96783. - 0 0 0 0 0 0 0 0 0 0 0 0
  96784. - 0 0 0 0 0 0 0 0 0 0 0 0
  96785. - 0 0 0 0 0 0 0 0 0 0 0 0
  96786. - 0 0 1 0 0 0 0 0 0 0 0 0
  96787. - 0 0 0 0 0 0 0 0 0 0 0 0
  96788. - 0 0 0 0 0 0 0 0 0 0 0 0
  96789. - 0 0 0 0 0 0 0 0 0 0 0 0
  96790. - 0 0 0 0 0 0 0 0 0 0 0 0
  96791. - 0 0 0 0 0 0 0 0 0 10 10 10
  96792. - 38 38 38 86 86 86 14 14 14 2 2 6
  96793. - 2 2 6 2 2 6 2 2 6 2 2 6
  96794. - 2 2 6 2 2 6 2 2 6 2 2 6
  96795. - 2 2 6 2 2 6 2 2 6 2 2 6
  96796. - 2 2 6 2 2 6 2 2 6 2 2 6
  96797. - 2 2 6 2 2 6 2 2 6 54 54 54
  96798. - 66 66 66 26 26 26 6 6 6 0 0 0
  96799. - 0 0 0 0 0 0 0 0 0 0 0 0
  96800. - 0 0 0 0 0 0 0 0 0 0 0 0
  96801. - 0 0 0 0 0 0 0 0 0 0 0 0
  96802. - 0 0 0 0 0 0 0 0 0 0 0 0
  96803. - 0 0 0 0 0 0 0 0 0 0 0 0
  96804. - 0 0 0 0 0 0 0 0 0 0 0 0
  96805. - 0 0 0 0 0 0 0 0 0 0 0 0
  96806. - 0 0 0 0 0 1 0 0 1 0 0 0
  96807. - 0 0 0 0 0 0 0 0 0 0 0 0
  96808. - 0 0 0 0 0 0 0 0 0 0 0 0
  96809. - 0 0 0 0 0 0 0 0 0 0 0 0
  96810. - 0 0 0 0 0 0 0 0 0 0 0 0
  96811. - 0 0 0 0 0 0 0 0 0 14 14 14
  96812. - 42 42 42 82 82 82 2 2 6 2 2 6
  96813. - 2 2 6 6 6 6 10 10 10 2 2 6
  96814. - 2 2 6 2 2 6 2 2 6 2 2 6
  96815. - 2 2 6 2 2 6 2 2 6 6 6 6
  96816. - 14 14 14 10 10 10 2 2 6 2 2 6
  96817. - 2 2 6 2 2 6 2 2 6 18 18 18
  96818. - 82 82 82 34 34 34 10 10 10 0 0 0
  96819. - 0 0 0 0 0 0 0 0 0 0 0 0
  96820. - 0 0 0 0 0 0 0 0 0 0 0 0
  96821. - 0 0 0 0 0 0 0 0 0 0 0 0
  96822. - 0 0 0 0 0 0 0 0 0 0 0 0
  96823. - 0 0 0 0 0 0 0 0 0 0 0 0
  96824. - 0 0 0 0 0 0 0 0 0 0 0 0
  96825. - 0 0 0 0 0 0 0 0 0 0 0 0
  96826. - 0 0 1 0 0 0 0 0 0 0 0 0
  96827. - 0 0 0 0 0 0 0 0 0 0 0 0
  96828. - 0 0 0 0 0 0 0 0 0 0 0 0
  96829. - 0 0 0 0 0 0 0 0 0 0 0 0
  96830. - 0 0 0 0 0 0 0 0 0 0 0 0
  96831. - 0 0 0 0 0 0 0 0 0 14 14 14
  96832. - 46 46 46 86 86 86 2 2 6 2 2 6
  96833. - 6 6 6 6 6 6 22 22 22 34 34 34
  96834. - 6 6 6 2 2 6 2 2 6 2 2 6
  96835. - 2 2 6 2 2 6 18 18 18 34 34 34
  96836. - 10 10 10 50 50 50 22 22 22 2 2 6
  96837. - 2 2 6 2 2 6 2 2 6 10 10 10
  96838. - 86 86 86 42 42 42 14 14 14 0 0 0
  96839. - 0 0 0 0 0 0 0 0 0 0 0 0
  96840. - 0 0 0 0 0 0 0 0 0 0 0 0
  96841. - 0 0 0 0 0 0 0 0 0 0 0 0
  96842. - 0 0 0 0 0 0 0 0 0 0 0 0
  96843. - 0 0 0 0 0 0 0 0 0 0 0 0
  96844. - 0 0 0 0 0 0 0 0 0 0 0 0
  96845. - 0 0 0 0 0 0 0 0 0 0 0 0
  96846. - 0 0 1 0 0 1 0 0 1 0 0 0
  96847. - 0 0 0 0 0 0 0 0 0 0 0 0
  96848. - 0 0 0 0 0 0 0 0 0 0 0 0
  96849. - 0 0 0 0 0 0 0 0 0 0 0 0
  96850. - 0 0 0 0 0 0 0 0 0 0 0 0
  96851. - 0 0 0 0 0 0 0 0 0 14 14 14
  96852. - 46 46 46 86 86 86 2 2 6 2 2 6
  96853. - 38 38 38 116 116 116 94 94 94 22 22 22
  96854. - 22 22 22 2 2 6 2 2 6 2 2 6
  96855. - 14 14 14 86 86 86 138 138 138 162 162 162
  96856. -154 154 154 38 38 38 26 26 26 6 6 6
  96857. - 2 2 6 2 2 6 2 2 6 2 2 6
  96858. - 86 86 86 46 46 46 14 14 14 0 0 0
  96859. - 0 0 0 0 0 0 0 0 0 0 0 0
  96860. - 0 0 0 0 0 0 0 0 0 0 0 0
  96861. - 0 0 0 0 0 0 0 0 0 0 0 0
  96862. - 0 0 0 0 0 0 0 0 0 0 0 0
  96863. - 0 0 0 0 0 0 0 0 0 0 0 0
  96864. - 0 0 0 0 0 0 0 0 0 0 0 0
  96865. - 0 0 0 0 0 0 0 0 0 0 0 0
  96866. - 0 0 0 0 0 0 0 0 0 0 0 0
  96867. - 0 0 0 0 0 0 0 0 0 0 0 0
  96868. - 0 0 0 0 0 0 0 0 0 0 0 0
  96869. - 0 0 0 0 0 0 0 0 0 0 0 0
  96870. - 0 0 0 0 0 0 0 0 0 0 0 0
  96871. - 0 0 0 0 0 0 0 0 0 14 14 14
  96872. - 46 46 46 86 86 86 2 2 6 14 14 14
  96873. -134 134 134 198 198 198 195 195 195 116 116 116
  96874. - 10 10 10 2 2 6 2 2 6 6 6 6
  96875. -101 98 89 187 187 187 210 210 210 218 218 218
  96876. -214 214 214 134 134 134 14 14 14 6 6 6
  96877. - 2 2 6 2 2 6 2 2 6 2 2 6
  96878. - 86 86 86 50 50 50 18 18 18 6 6 6
  96879. - 0 0 0 0 0 0 0 0 0 0 0 0
  96880. - 0 0 0 0 0 0 0 0 0 0 0 0
  96881. - 0 0 0 0 0 0 0 0 0 0 0 0
  96882. - 0 0 0 0 0 0 0 0 0 0 0 0
  96883. - 0 0 0 0 0 0 0 0 0 0 0 0
  96884. - 0 0 0 0 0 0 0 0 0 0 0 0
  96885. - 0 0 0 0 0 0 0 0 1 0 0 0
  96886. - 0 0 1 0 0 1 0 0 1 0 0 0
  96887. - 0 0 0 0 0 0 0 0 0 0 0 0
  96888. - 0 0 0 0 0 0 0 0 0 0 0 0
  96889. - 0 0 0 0 0 0 0 0 0 0 0 0
  96890. - 0 0 0 0 0 0 0 0 0 0 0 0
  96891. - 0 0 0 0 0 0 0 0 0 14 14 14
  96892. - 46 46 46 86 86 86 2 2 6 54 54 54
  96893. -218 218 218 195 195 195 226 226 226 246 246 246
  96894. - 58 58 58 2 2 6 2 2 6 30 30 30
  96895. -210 210 210 253 253 253 174 174 174 123 123 123
  96896. -221 221 221 234 234 234 74 74 74 2 2 6
  96897. - 2 2 6 2 2 6 2 2 6 2 2 6
  96898. - 70 70 70 58 58 58 22 22 22 6 6 6
  96899. - 0 0 0 0 0 0 0 0 0 0 0 0
  96900. - 0 0 0 0 0 0 0 0 0 0 0 0
  96901. - 0 0 0 0 0 0 0 0 0 0 0 0
  96902. - 0 0 0 0 0 0 0 0 0 0 0 0
  96903. - 0 0 0 0 0 0 0 0 0 0 0 0
  96904. - 0 0 0 0 0 0 0 0 0 0 0 0
  96905. - 0 0 0 0 0 0 0 0 0 0 0 0
  96906. - 0 0 0 0 0 0 0 0 0 0 0 0
  96907. - 0 0 0 0 0 0 0 0 0 0 0 0
  96908. - 0 0 0 0 0 0 0 0 0 0 0 0
  96909. - 0 0 0 0 0 0 0 0 0 0 0 0
  96910. - 0 0 0 0 0 0 0 0 0 0 0 0
  96911. - 0 0 0 0 0 0 0 0 0 14 14 14
  96912. - 46 46 46 82 82 82 2 2 6 106 106 106
  96913. -170 170 170 26 26 26 86 86 86 226 226 226
  96914. -123 123 123 10 10 10 14 14 14 46 46 46
  96915. -231 231 231 190 190 190 6 6 6 70 70 70
  96916. - 90 90 90 238 238 238 158 158 158 2 2 6
  96917. - 2 2 6 2 2 6 2 2 6 2 2 6
  96918. - 70 70 70 58 58 58 22 22 22 6 6 6
  96919. - 0 0 0 0 0 0 0 0 0 0 0 0
  96920. - 0 0 0 0 0 0 0 0 0 0 0 0
  96921. - 0 0 0 0 0 0 0 0 0 0 0 0
  96922. - 0 0 0 0 0 0 0 0 0 0 0 0
  96923. - 0 0 0 0 0 0 0 0 0 0 0 0
  96924. - 0 0 0 0 0 0 0 0 0 0 0 0
  96925. - 0 0 0 0 0 0 0 0 1 0 0 0
  96926. - 0 0 1 0 0 1 0 0 1 0 0 0
  96927. - 0 0 0 0 0 0 0 0 0 0 0 0
  96928. - 0 0 0 0 0 0 0 0 0 0 0 0
  96929. - 0 0 0 0 0 0 0 0 0 0 0 0
  96930. - 0 0 0 0 0 0 0 0 0 0 0 0
  96931. - 0 0 0 0 0 0 0 0 0 14 14 14
  96932. - 42 42 42 86 86 86 6 6 6 116 116 116
  96933. -106 106 106 6 6 6 70 70 70 149 149 149
  96934. -128 128 128 18 18 18 38 38 38 54 54 54
  96935. -221 221 221 106 106 106 2 2 6 14 14 14
  96936. - 46 46 46 190 190 190 198 198 198 2 2 6
  96937. - 2 2 6 2 2 6 2 2 6 2 2 6
  96938. - 74 74 74 62 62 62 22 22 22 6 6 6
  96939. - 0 0 0 0 0 0 0 0 0 0 0 0
  96940. - 0 0 0 0 0 0 0 0 0 0 0 0
  96941. - 0 0 0 0 0 0 0 0 0 0 0 0
  96942. - 0 0 0 0 0 0 0 0 0 0 0 0
  96943. - 0 0 0 0 0 0 0 0 0 0 0 0
  96944. - 0 0 0 0 0 0 0 0 0 0 0 0
  96945. - 0 0 0 0 0 0 0 0 1 0 0 0
  96946. - 0 0 1 0 0 0 0 0 1 0 0 0
  96947. - 0 0 0 0 0 0 0 0 0 0 0 0
  96948. - 0 0 0 0 0 0 0 0 0 0 0 0
  96949. - 0 0 0 0 0 0 0 0 0 0 0 0
  96950. - 0 0 0 0 0 0 0 0 0 0 0 0
  96951. - 0 0 0 0 0 0 0 0 0 14 14 14
  96952. - 42 42 42 94 94 94 14 14 14 101 101 101
  96953. -128 128 128 2 2 6 18 18 18 116 116 116
  96954. -118 98 46 121 92 8 121 92 8 98 78 10
  96955. -162 162 162 106 106 106 2 2 6 2 2 6
  96956. - 2 2 6 195 195 195 195 195 195 6 6 6
  96957. - 2 2 6 2 2 6 2 2 6 2 2 6
  96958. - 74 74 74 62 62 62 22 22 22 6 6 6
  96959. - 0 0 0 0 0 0 0 0 0 0 0 0
  96960. - 0 0 0 0 0 0 0 0 0 0 0 0
  96961. - 0 0 0 0 0 0 0 0 0 0 0 0
  96962. - 0 0 0 0 0 0 0 0 0 0 0 0
  96963. - 0 0 0 0 0 0 0 0 0 0 0 0
  96964. - 0 0 0 0 0 0 0 0 0 0 0 0
  96965. - 0 0 0 0 0 0 0 0 1 0 0 1
  96966. - 0 0 1 0 0 0 0 0 1 0 0 0
  96967. - 0 0 0 0 0 0 0 0 0 0 0 0
  96968. - 0 0 0 0 0 0 0 0 0 0 0 0
  96969. - 0 0 0 0 0 0 0 0 0 0 0 0
  96970. - 0 0 0 0 0 0 0 0 0 0 0 0
  96971. - 0 0 0 0 0 0 0 0 0 10 10 10
  96972. - 38 38 38 90 90 90 14 14 14 58 58 58
  96973. -210 210 210 26 26 26 54 38 6 154 114 10
  96974. -226 170 11 236 186 11 225 175 15 184 144 12
  96975. -215 174 15 175 146 61 37 26 9 2 2 6
  96976. - 70 70 70 246 246 246 138 138 138 2 2 6
  96977. - 2 2 6 2 2 6 2 2 6 2 2 6
  96978. - 70 70 70 66 66 66 26 26 26 6 6 6
  96979. - 0 0 0 0 0 0 0 0 0 0 0 0
  96980. - 0 0 0 0 0 0 0 0 0 0 0 0
  96981. - 0 0 0 0 0 0 0 0 0 0 0 0
  96982. - 0 0 0 0 0 0 0 0 0 0 0 0
  96983. - 0 0 0 0 0 0 0 0 0 0 0 0
  96984. - 0 0 0 0 0 0 0 0 0 0 0 0
  96985. - 0 0 0 0 0 0 0 0 0 0 0 0
  96986. - 0 0 0 0 0 0 0 0 0 0 0 0
  96987. - 0 0 0 0 0 0 0 0 0 0 0 0
  96988. - 0 0 0 0 0 0 0 0 0 0 0 0
  96989. - 0 0 0 0 0 0 0 0 0 0 0 0
  96990. - 0 0 0 0 0 0 0 0 0 0 0 0
  96991. - 0 0 0 0 0 0 0 0 0 10 10 10
  96992. - 38 38 38 86 86 86 14 14 14 10 10 10
  96993. -195 195 195 188 164 115 192 133 9 225 175 15
  96994. -239 182 13 234 190 10 232 195 16 232 200 30
  96995. -245 207 45 241 208 19 232 195 16 184 144 12
  96996. -218 194 134 211 206 186 42 42 42 2 2 6
  96997. - 2 2 6 2 2 6 2 2 6 2 2 6
  96998. - 50 50 50 74 74 74 30 30 30 6 6 6
  96999. - 0 0 0 0 0 0 0 0 0 0 0 0
  97000. - 0 0 0 0 0 0 0 0 0 0 0 0
  97001. - 0 0 0 0 0 0 0 0 0 0 0 0
  97002. - 0 0 0 0 0 0 0 0 0 0 0 0
  97003. - 0 0 0 0 0 0 0 0 0 0 0 0
  97004. - 0 0 0 0 0 0 0 0 0 0 0 0
  97005. - 0 0 0 0 0 0 0 0 0 0 0 0
  97006. - 0 0 0 0 0 0 0 0 0 0 0 0
  97007. - 0 0 0 0 0 0 0 0 0 0 0 0
  97008. - 0 0 0 0 0 0 0 0 0 0 0 0
  97009. - 0 0 0 0 0 0 0 0 0 0 0 0
  97010. - 0 0 0 0 0 0 0 0 0 0 0 0
  97011. - 0 0 0 0 0 0 0 0 0 10 10 10
  97012. - 34 34 34 86 86 86 14 14 14 2 2 6
  97013. -121 87 25 192 133 9 219 162 10 239 182 13
  97014. -236 186 11 232 195 16 241 208 19 244 214 54
  97015. -246 218 60 246 218 38 246 215 20 241 208 19
  97016. -241 208 19 226 184 13 121 87 25 2 2 6
  97017. - 2 2 6 2 2 6 2 2 6 2 2 6
  97018. - 50 50 50 82 82 82 34 34 34 10 10 10
  97019. - 0 0 0 0 0 0 0 0 0 0 0 0
  97020. - 0 0 0 0 0 0 0 0 0 0 0 0
  97021. - 0 0 0 0 0 0 0 0 0 0 0 0
  97022. - 0 0 0 0 0 0 0 0 0 0 0 0
  97023. - 0 0 0 0 0 0 0 0 0 0 0 0
  97024. - 0 0 0 0 0 0 0 0 0 0 0 0
  97025. - 0 0 0 0 0 0 0 0 0 0 0 0
  97026. - 0 0 0 0 0 0 0 0 0 0 0 0
  97027. - 0 0 0 0 0 0 0 0 0 0 0 0
  97028. - 0 0 0 0 0 0 0 0 0 0 0 0
  97029. - 0 0 0 0 0 0 0 0 0 0 0 0
  97030. - 0 0 0 0 0 0 0 0 0 0 0 0
  97031. - 0 0 0 0 0 0 0 0 0 10 10 10
  97032. - 34 34 34 82 82 82 30 30 30 61 42 6
  97033. -180 123 7 206 145 10 230 174 11 239 182 13
  97034. -234 190 10 238 202 15 241 208 19 246 218 74
  97035. -246 218 38 246 215 20 246 215 20 246 215 20
  97036. -226 184 13 215 174 15 184 144 12 6 6 6
  97037. - 2 2 6 2 2 6 2 2 6 2 2 6
  97038. - 26 26 26 94 94 94 42 42 42 14 14 14
  97039. - 0 0 0 0 0 0 0 0 0 0 0 0
  97040. - 0 0 0 0 0 0 0 0 0 0 0 0
  97041. - 0 0 0 0 0 0 0 0 0 0 0 0
  97042. - 0 0 0 0 0 0 0 0 0 0 0 0
  97043. - 0 0 0 0 0 0 0 0 0 0 0 0
  97044. - 0 0 0 0 0 0 0 0 0 0 0 0
  97045. - 0 0 0 0 0 0 0 0 0 0 0 0
  97046. - 0 0 0 0 0 0 0 0 0 0 0 0
  97047. - 0 0 0 0 0 0 0 0 0 0 0 0
  97048. - 0 0 0 0 0 0 0 0 0 0 0 0
  97049. - 0 0 0 0 0 0 0 0 0 0 0 0
  97050. - 0 0 0 0 0 0 0 0 0 0 0 0
  97051. - 0 0 0 0 0 0 0 0 0 10 10 10
  97052. - 30 30 30 78 78 78 50 50 50 104 69 6
  97053. -192 133 9 216 158 10 236 178 12 236 186 11
  97054. -232 195 16 241 208 19 244 214 54 245 215 43
  97055. -246 215 20 246 215 20 241 208 19 198 155 10
  97056. -200 144 11 216 158 10 156 118 10 2 2 6
  97057. - 2 2 6 2 2 6 2 2 6 2 2 6
  97058. - 6 6 6 90 90 90 54 54 54 18 18 18
  97059. - 6 6 6 0 0 0 0 0 0 0 0 0
  97060. - 0 0 0 0 0 0 0 0 0 0 0 0
  97061. - 0 0 0 0 0 0 0 0 0 0 0 0
  97062. - 0 0 0 0 0 0 0 0 0 0 0 0
  97063. - 0 0 0 0 0 0 0 0 0 0 0 0
  97064. - 0 0 0 0 0 0 0 0 0 0 0 0
  97065. - 0 0 0 0 0 0 0 0 0 0 0 0
  97066. - 0 0 0 0 0 0 0 0 0 0 0 0
  97067. - 0 0 0 0 0 0 0 0 0 0 0 0
  97068. - 0 0 0 0 0 0 0 0 0 0 0 0
  97069. - 0 0 0 0 0 0 0 0 0 0 0 0
  97070. - 0 0 0 0 0 0 0 0 0 0 0 0
  97071. - 0 0 0 0 0 0 0 0 0 10 10 10
  97072. - 30 30 30 78 78 78 46 46 46 22 22 22
  97073. -137 92 6 210 162 10 239 182 13 238 190 10
  97074. -238 202 15 241 208 19 246 215 20 246 215 20
  97075. -241 208 19 203 166 17 185 133 11 210 150 10
  97076. -216 158 10 210 150 10 102 78 10 2 2 6
  97077. - 6 6 6 54 54 54 14 14 14 2 2 6
  97078. - 2 2 6 62 62 62 74 74 74 30 30 30
  97079. - 10 10 10 0 0 0 0 0 0 0 0 0
  97080. - 0 0 0 0 0 0 0 0 0 0 0 0
  97081. - 0 0 0 0 0 0 0 0 0 0 0 0
  97082. - 0 0 0 0 0 0 0 0 0 0 0 0
  97083. - 0 0 0 0 0 0 0 0 0 0 0 0
  97084. - 0 0 0 0 0 0 0 0 0 0 0 0
  97085. - 0 0 0 0 0 0 0 0 0 0 0 0
  97086. - 0 0 0 0 0 0 0 0 0 0 0 0
  97087. - 0 0 0 0 0 0 0 0 0 0 0 0
  97088. - 0 0 0 0 0 0 0 0 0 0 0 0
  97089. - 0 0 0 0 0 0 0 0 0 0 0 0
  97090. - 0 0 0 0 0 0 0 0 0 0 0 0
  97091. - 0 0 0 0 0 0 0 0 0 10 10 10
  97092. - 34 34 34 78 78 78 50 50 50 6 6 6
  97093. - 94 70 30 139 102 15 190 146 13 226 184 13
  97094. -232 200 30 232 195 16 215 174 15 190 146 13
  97095. -168 122 10 192 133 9 210 150 10 213 154 11
  97096. -202 150 34 182 157 106 101 98 89 2 2 6
  97097. - 2 2 6 78 78 78 116 116 116 58 58 58
  97098. - 2 2 6 22 22 22 90 90 90 46 46 46
  97099. - 18 18 18 6 6 6 0 0 0 0 0 0
  97100. - 0 0 0 0 0 0 0 0 0 0 0 0
  97101. - 0 0 0 0 0 0 0 0 0 0 0 0
  97102. - 0 0 0 0 0 0 0 0 0 0 0 0
  97103. - 0 0 0 0 0 0 0 0 0 0 0 0
  97104. - 0 0 0 0 0 0 0 0 0 0 0 0
  97105. - 0 0 0 0 0 0 0 0 0 0 0 0
  97106. - 0 0 0 0 0 0 0 0 0 0 0 0
  97107. - 0 0 0 0 0 0 0 0 0 0 0 0
  97108. - 0 0 0 0 0 0 0 0 0 0 0 0
  97109. - 0 0 0 0 0 0 0 0 0 0 0 0
  97110. - 0 0 0 0 0 0 0 0 0 0 0 0
  97111. - 0 0 0 0 0 0 0 0 0 10 10 10
  97112. - 38 38 38 86 86 86 50 50 50 6 6 6
  97113. -128 128 128 174 154 114 156 107 11 168 122 10
  97114. -198 155 10 184 144 12 197 138 11 200 144 11
  97115. -206 145 10 206 145 10 197 138 11 188 164 115
  97116. -195 195 195 198 198 198 174 174 174 14 14 14
  97117. - 2 2 6 22 22 22 116 116 116 116 116 116
  97118. - 22 22 22 2 2 6 74 74 74 70 70 70
  97119. - 30 30 30 10 10 10 0 0 0 0 0 0
  97120. - 0 0 0 0 0 0 0 0 0 0 0 0
  97121. - 0 0 0 0 0 0 0 0 0 0 0 0
  97122. - 0 0 0 0 0 0 0 0 0 0 0 0
  97123. - 0 0 0 0 0 0 0 0 0 0 0 0
  97124. - 0 0 0 0 0 0 0 0 0 0 0 0
  97125. - 0 0 0 0 0 0 0 0 0 0 0 0
  97126. - 0 0 0 0 0 0 0 0 0 0 0 0
  97127. - 0 0 0 0 0 0 0 0 0 0 0 0
  97128. - 0 0 0 0 0 0 0 0 0 0 0 0
  97129. - 0 0 0 0 0 0 0 0 0 0 0 0
  97130. - 0 0 0 0 0 0 0 0 0 0 0 0
  97131. - 0 0 0 0 0 0 6 6 6 18 18 18
  97132. - 50 50 50 101 101 101 26 26 26 10 10 10
  97133. -138 138 138 190 190 190 174 154 114 156 107 11
  97134. -197 138 11 200 144 11 197 138 11 192 133 9
  97135. -180 123 7 190 142 34 190 178 144 187 187 187
  97136. -202 202 202 221 221 221 214 214 214 66 66 66
  97137. - 2 2 6 2 2 6 50 50 50 62 62 62
  97138. - 6 6 6 2 2 6 10 10 10 90 90 90
  97139. - 50 50 50 18 18 18 6 6 6 0 0 0
  97140. - 0 0 0 0 0 0 0 0 0 0 0 0
  97141. - 0 0 0 0 0 0 0 0 0 0 0 0
  97142. - 0 0 0 0 0 0 0 0 0 0 0 0
  97143. - 0 0 0 0 0 0 0 0 0 0 0 0
  97144. - 0 0 0 0 0 0 0 0 0 0 0 0
  97145. - 0 0 0 0 0 0 0 0 0 0 0 0
  97146. - 0 0 0 0 0 0 0 0 0 0 0 0
  97147. - 0 0 0 0 0 0 0 0 0 0 0 0
  97148. - 0 0 0 0 0 0 0 0 0 0 0 0
  97149. - 0 0 0 0 0 0 0 0 0 0 0 0
  97150. - 0 0 0 0 0 0 0 0 0 0 0 0
  97151. - 0 0 0 0 0 0 10 10 10 34 34 34
  97152. - 74 74 74 74 74 74 2 2 6 6 6 6
  97153. -144 144 144 198 198 198 190 190 190 178 166 146
  97154. -154 121 60 156 107 11 156 107 11 168 124 44
  97155. -174 154 114 187 187 187 190 190 190 210 210 210
  97156. -246 246 246 253 253 253 253 253 253 182 182 182
  97157. - 6 6 6 2 2 6 2 2 6 2 2 6
  97158. - 2 2 6 2 2 6 2 2 6 62 62 62
  97159. - 74 74 74 34 34 34 14 14 14 0 0 0
  97160. - 0 0 0 0 0 0 0 0 0 0 0 0
  97161. - 0 0 0 0 0 0 0 0 0 0 0 0
  97162. - 0 0 0 0 0 0 0 0 0 0 0 0
  97163. - 0 0 0 0 0 0 0 0 0 0 0 0
  97164. - 0 0 0 0 0 0 0 0 0 0 0 0
  97165. - 0 0 0 0 0 0 0 0 0 0 0 0
  97166. - 0 0 0 0 0 0 0 0 0 0 0 0
  97167. - 0 0 0 0 0 0 0 0 0 0 0 0
  97168. - 0 0 0 0 0 0 0 0 0 0 0 0
  97169. - 0 0 0 0 0 0 0 0 0 0 0 0
  97170. - 0 0 0 0 0 0 0 0 0 0 0 0
  97171. - 0 0 0 10 10 10 22 22 22 54 54 54
  97172. - 94 94 94 18 18 18 2 2 6 46 46 46
  97173. -234 234 234 221 221 221 190 190 190 190 190 190
  97174. -190 190 190 187 187 187 187 187 187 190 190 190
  97175. -190 190 190 195 195 195 214 214 214 242 242 242
  97176. -253 253 253 253 253 253 253 253 253 253 253 253
  97177. - 82 82 82 2 2 6 2 2 6 2 2 6
  97178. - 2 2 6 2 2 6 2 2 6 14 14 14
  97179. - 86 86 86 54 54 54 22 22 22 6 6 6
  97180. - 0 0 0 0 0 0 0 0 0 0 0 0
  97181. - 0 0 0 0 0 0 0 0 0 0 0 0
  97182. - 0 0 0 0 0 0 0 0 0 0 0 0
  97183. - 0 0 0 0 0 0 0 0 0 0 0 0
  97184. - 0 0 0 0 0 0 0 0 0 0 0 0
  97185. - 0 0 0 0 0 0 0 0 0 0 0 0
  97186. - 0 0 0 0 0 0 0 0 0 0 0 0
  97187. - 0 0 0 0 0 0 0 0 0 0 0 0
  97188. - 0 0 0 0 0 0 0 0 0 0 0 0
  97189. - 0 0 0 0 0 0 0 0 0 0 0 0
  97190. - 0 0 0 0 0 0 0 0 0 0 0 0
  97191. - 6 6 6 18 18 18 46 46 46 90 90 90
  97192. - 46 46 46 18 18 18 6 6 6 182 182 182
  97193. -253 253 253 246 246 246 206 206 206 190 190 190
  97194. -190 190 190 190 190 190 190 190 190 190 190 190
  97195. -206 206 206 231 231 231 250 250 250 253 253 253
  97196. -253 253 253 253 253 253 253 253 253 253 253 253
  97197. -202 202 202 14 14 14 2 2 6 2 2 6
  97198. - 2 2 6 2 2 6 2 2 6 2 2 6
  97199. - 42 42 42 86 86 86 42 42 42 18 18 18
  97200. - 6 6 6 0 0 0 0 0 0 0 0 0
  97201. - 0 0 0 0 0 0 0 0 0 0 0 0
  97202. - 0 0 0 0 0 0 0 0 0 0 0 0
  97203. - 0 0 0 0 0 0 0 0 0 0 0 0
  97204. - 0 0 0 0 0 0 0 0 0 0 0 0
  97205. - 0 0 0 0 0 0 0 0 0 0 0 0
  97206. - 0 0 0 0 0 0 0 0 0 0 0 0
  97207. - 0 0 0 0 0 0 0 0 0 0 0 0
  97208. - 0 0 0 0 0 0 0 0 0 0 0 0
  97209. - 0 0 0 0 0 0 0 0 0 0 0 0
  97210. - 0 0 0 0 0 0 0 0 0 6 6 6
  97211. - 14 14 14 38 38 38 74 74 74 66 66 66
  97212. - 2 2 6 6 6 6 90 90 90 250 250 250
  97213. -253 253 253 253 253 253 238 238 238 198 198 198
  97214. -190 190 190 190 190 190 195 195 195 221 221 221
  97215. -246 246 246 253 253 253 253 253 253 253 253 253
  97216. -253 253 253 253 253 253 253 253 253 253 253 253
  97217. -253 253 253 82 82 82 2 2 6 2 2 6
  97218. - 2 2 6 2 2 6 2 2 6 2 2 6
  97219. - 2 2 6 78 78 78 70 70 70 34 34 34
  97220. - 14 14 14 6 6 6 0 0 0 0 0 0
  97221. - 0 0 0 0 0 0 0 0 0 0 0 0
  97222. - 0 0 0 0 0 0 0 0 0 0 0 0
  97223. - 0 0 0 0 0 0 0 0 0 0 0 0
  97224. - 0 0 0 0 0 0 0 0 0 0 0 0
  97225. - 0 0 0 0 0 0 0 0 0 0 0 0
  97226. - 0 0 0 0 0 0 0 0 0 0 0 0
  97227. - 0 0 0 0 0 0 0 0 0 0 0 0
  97228. - 0 0 0 0 0 0 0 0 0 0 0 0
  97229. - 0 0 0 0 0 0 0 0 0 0 0 0
  97230. - 0 0 0 0 0 0 0 0 0 14 14 14
  97231. - 34 34 34 66 66 66 78 78 78 6 6 6
  97232. - 2 2 6 18 18 18 218 218 218 253 253 253
  97233. -253 253 253 253 253 253 253 253 253 246 246 246
  97234. -226 226 226 231 231 231 246 246 246 253 253 253
  97235. -253 253 253 253 253 253 253 253 253 253 253 253
  97236. -253 253 253 253 253 253 253 253 253 253 253 253
  97237. -253 253 253 178 178 178 2 2 6 2 2 6
  97238. - 2 2 6 2 2 6 2 2 6 2 2 6
  97239. - 2 2 6 18 18 18 90 90 90 62 62 62
  97240. - 30 30 30 10 10 10 0 0 0 0 0 0
  97241. - 0 0 0 0 0 0 0 0 0 0 0 0
  97242. - 0 0 0 0 0 0 0 0 0 0 0 0
  97243. - 0 0 0 0 0 0 0 0 0 0 0 0
  97244. - 0 0 0 0 0 0 0 0 0 0 0 0
  97245. - 0 0 0 0 0 0 0 0 0 0 0 0
  97246. - 0 0 0 0 0 0 0 0 0 0 0 0
  97247. - 0 0 0 0 0 0 0 0 0 0 0 0
  97248. - 0 0 0 0 0 0 0 0 0 0 0 0
  97249. - 0 0 0 0 0 0 0 0 0 0 0 0
  97250. - 0 0 0 0 0 0 10 10 10 26 26 26
  97251. - 58 58 58 90 90 90 18 18 18 2 2 6
  97252. - 2 2 6 110 110 110 253 253 253 253 253 253
  97253. -253 253 253 253 253 253 253 253 253 253 253 253
  97254. -250 250 250 253 253 253 253 253 253 253 253 253
  97255. -253 253 253 253 253 253 253 253 253 253 253 253
  97256. -253 253 253 253 253 253 253 253 253 253 253 253
  97257. -253 253 253 231 231 231 18 18 18 2 2 6
  97258. - 2 2 6 2 2 6 2 2 6 2 2 6
  97259. - 2 2 6 2 2 6 18 18 18 94 94 94
  97260. - 54 54 54 26 26 26 10 10 10 0 0 0
  97261. - 0 0 0 0 0 0 0 0 0 0 0 0
  97262. - 0 0 0 0 0 0 0 0 0 0 0 0
  97263. - 0 0 0 0 0 0 0 0 0 0 0 0
  97264. - 0 0 0 0 0 0 0 0 0 0 0 0
  97265. - 0 0 0 0 0 0 0 0 0 0 0 0
  97266. - 0 0 0 0 0 0 0 0 0 0 0 0
  97267. - 0 0 0 0 0 0 0 0 0 0 0 0
  97268. - 0 0 0 0 0 0 0 0 0 0 0 0
  97269. - 0 0 0 0 0 0 0 0 0 0 0 0
  97270. - 0 0 0 6 6 6 22 22 22 50 50 50
  97271. - 90 90 90 26 26 26 2 2 6 2 2 6
  97272. - 14 14 14 195 195 195 250 250 250 253 253 253
  97273. -253 253 253 253 253 253 253 253 253 253 253 253
  97274. -253 253 253 253 253 253 253 253 253 253 253 253
  97275. -253 253 253 253 253 253 253 253 253 253 253 253
  97276. -253 253 253 253 253 253 253 253 253 253 253 253
  97277. -250 250 250 242 242 242 54 54 54 2 2 6
  97278. - 2 2 6 2 2 6 2 2 6 2 2 6
  97279. - 2 2 6 2 2 6 2 2 6 38 38 38
  97280. - 86 86 86 50 50 50 22 22 22 6 6 6
  97281. - 0 0 0 0 0 0 0 0 0 0 0 0
  97282. - 0 0 0 0 0 0 0 0 0 0 0 0
  97283. - 0 0 0 0 0 0 0 0 0 0 0 0
  97284. - 0 0 0 0 0 0 0 0 0 0 0 0
  97285. - 0 0 0 0 0 0 0 0 0 0 0 0
  97286. - 0 0 0 0 0 0 0 0 0 0 0 0
  97287. - 0 0 0 0 0 0 0 0 0 0 0 0
  97288. - 0 0 0 0 0 0 0 0 0 0 0 0
  97289. - 0 0 0 0 0 0 0 0 0 0 0 0
  97290. - 6 6 6 14 14 14 38 38 38 82 82 82
  97291. - 34 34 34 2 2 6 2 2 6 2 2 6
  97292. - 42 42 42 195 195 195 246 246 246 253 253 253
  97293. -253 253 253 253 253 253 253 253 253 250 250 250
  97294. -242 242 242 242 242 242 250 250 250 253 253 253
  97295. -253 253 253 253 253 253 253 253 253 253 253 253
  97296. -253 253 253 250 250 250 246 246 246 238 238 238
  97297. -226 226 226 231 231 231 101 101 101 6 6 6
  97298. - 2 2 6 2 2 6 2 2 6 2 2 6
  97299. - 2 2 6 2 2 6 2 2 6 2 2 6
  97300. - 38 38 38 82 82 82 42 42 42 14 14 14
  97301. - 6 6 6 0 0 0 0 0 0 0 0 0
  97302. - 0 0 0 0 0 0 0 0 0 0 0 0
  97303. - 0 0 0 0 0 0 0 0 0 0 0 0
  97304. - 0 0 0 0 0 0 0 0 0 0 0 0
  97305. - 0 0 0 0 0 0 0 0 0 0 0 0
  97306. - 0 0 0 0 0 0 0 0 0 0 0 0
  97307. - 0 0 0 0 0 0 0 0 0 0 0 0
  97308. - 0 0 0 0 0 0 0 0 0 0 0 0
  97309. - 0 0 0 0 0 0 0 0 0 0 0 0
  97310. - 10 10 10 26 26 26 62 62 62 66 66 66
  97311. - 2 2 6 2 2 6 2 2 6 6 6 6
  97312. - 70 70 70 170 170 170 206 206 206 234 234 234
  97313. -246 246 246 250 250 250 250 250 250 238 238 238
  97314. -226 226 226 231 231 231 238 238 238 250 250 250
  97315. -250 250 250 250 250 250 246 246 246 231 231 231
  97316. -214 214 214 206 206 206 202 202 202 202 202 202
  97317. -198 198 198 202 202 202 182 182 182 18 18 18
  97318. - 2 2 6 2 2 6 2 2 6 2 2 6
  97319. - 2 2 6 2 2 6 2 2 6 2 2 6
  97320. - 2 2 6 62 62 62 66 66 66 30 30 30
  97321. - 10 10 10 0 0 0 0 0 0 0 0 0
  97322. - 0 0 0 0 0 0 0 0 0 0 0 0
  97323. - 0 0 0 0 0 0 0 0 0 0 0 0
  97324. - 0 0 0 0 0 0 0 0 0 0 0 0
  97325. - 0 0 0 0 0 0 0 0 0 0 0 0
  97326. - 0 0 0 0 0 0 0 0 0 0 0 0
  97327. - 0 0 0 0 0 0 0 0 0 0 0 0
  97328. - 0 0 0 0 0 0 0 0 0 0 0 0
  97329. - 0 0 0 0 0 0 0 0 0 0 0 0
  97330. - 14 14 14 42 42 42 82 82 82 18 18 18
  97331. - 2 2 6 2 2 6 2 2 6 10 10 10
  97332. - 94 94 94 182 182 182 218 218 218 242 242 242
  97333. -250 250 250 253 253 253 253 253 253 250 250 250
  97334. -234 234 234 253 253 253 253 253 253 253 253 253
  97335. -253 253 253 253 253 253 253 253 253 246 246 246
  97336. -238 238 238 226 226 226 210 210 210 202 202 202
  97337. -195 195 195 195 195 195 210 210 210 158 158 158
  97338. - 6 6 6 14 14 14 50 50 50 14 14 14
  97339. - 2 2 6 2 2 6 2 2 6 2 2 6
  97340. - 2 2 6 6 6 6 86 86 86 46 46 46
  97341. - 18 18 18 6 6 6 0 0 0 0 0 0
  97342. - 0 0 0 0 0 0 0 0 0 0 0 0
  97343. - 0 0 0 0 0 0 0 0 0 0 0 0
  97344. - 0 0 0 0 0 0 0 0 0 0 0 0
  97345. - 0 0 0 0 0 0 0 0 0 0 0 0
  97346. - 0 0 0 0 0 0 0 0 0 0 0 0
  97347. - 0 0 0 0 0 0 0 0 0 0 0 0
  97348. - 0 0 0 0 0 0 0 0 0 0 0 0
  97349. - 0 0 0 0 0 0 0 0 0 6 6 6
  97350. - 22 22 22 54 54 54 70 70 70 2 2 6
  97351. - 2 2 6 10 10 10 2 2 6 22 22 22
  97352. -166 166 166 231 231 231 250 250 250 253 253 253
  97353. -253 253 253 253 253 253 253 253 253 250 250 250
  97354. -242 242 242 253 253 253 253 253 253 253 253 253
  97355. -253 253 253 253 253 253 253 253 253 253 253 253
  97356. -253 253 253 253 253 253 253 253 253 246 246 246
  97357. -231 231 231 206 206 206 198 198 198 226 226 226
  97358. - 94 94 94 2 2 6 6 6 6 38 38 38
  97359. - 30 30 30 2 2 6 2 2 6 2 2 6
  97360. - 2 2 6 2 2 6 62 62 62 66 66 66
  97361. - 26 26 26 10 10 10 0 0 0 0 0 0
  97362. - 0 0 0 0 0 0 0 0 0 0 0 0
  97363. - 0 0 0 0 0 0 0 0 0 0 0 0
  97364. - 0 0 0 0 0 0 0 0 0 0 0 0
  97365. - 0 0 0 0 0 0 0 0 0 0 0 0
  97366. - 0 0 0 0 0 0 0 0 0 0 0 0
  97367. - 0 0 0 0 0 0 0 0 0 0 0 0
  97368. - 0 0 0 0 0 0 0 0 0 0 0 0
  97369. - 0 0 0 0 0 0 0 0 0 10 10 10
  97370. - 30 30 30 74 74 74 50 50 50 2 2 6
  97371. - 26 26 26 26 26 26 2 2 6 106 106 106
  97372. -238 238 238 253 253 253 253 253 253 253 253 253
  97373. -253 253 253 253 253 253 253 253 253 253 253 253
  97374. -253 253 253 253 253 253 253 253 253 253 253 253
  97375. -253 253 253 253 253 253 253 253 253 253 253 253
  97376. -253 253 253 253 253 253 253 253 253 253 253 253
  97377. -253 253 253 246 246 246 218 218 218 202 202 202
  97378. -210 210 210 14 14 14 2 2 6 2 2 6
  97379. - 30 30 30 22 22 22 2 2 6 2 2 6
  97380. - 2 2 6 2 2 6 18 18 18 86 86 86
  97381. - 42 42 42 14 14 14 0 0 0 0 0 0
  97382. - 0 0 0 0 0 0 0 0 0 0 0 0
  97383. - 0 0 0 0 0 0 0 0 0 0 0 0
  97384. - 0 0 0 0 0 0 0 0 0 0 0 0
  97385. - 0 0 0 0 0 0 0 0 0 0 0 0
  97386. - 0 0 0 0 0 0 0 0 0 0 0 0
  97387. - 0 0 0 0 0 0 0 0 0 0 0 0
  97388. - 0 0 0 0 0 0 0 0 0 0 0 0
  97389. - 0 0 0 0 0 0 0 0 0 14 14 14
  97390. - 42 42 42 90 90 90 22 22 22 2 2 6
  97391. - 42 42 42 2 2 6 18 18 18 218 218 218
  97392. -253 253 253 253 253 253 253 253 253 253 253 253
  97393. -253 253 253 253 253 253 253 253 253 253 253 253
  97394. -253 253 253 253 253 253 253 253 253 253 253 253
  97395. -253 253 253 253 253 253 253 253 253 253 253 253
  97396. -253 253 253 253 253 253 253 253 253 253 253 253
  97397. -253 253 253 253 253 253 250 250 250 221 221 221
  97398. -218 218 218 101 101 101 2 2 6 14 14 14
  97399. - 18 18 18 38 38 38 10 10 10 2 2 6
  97400. - 2 2 6 2 2 6 2 2 6 78 78 78
  97401. - 58 58 58 22 22 22 6 6 6 0 0 0
  97402. - 0 0 0 0 0 0 0 0 0 0 0 0
  97403. - 0 0 0 0 0 0 0 0 0 0 0 0
  97404. - 0 0 0 0 0 0 0 0 0 0 0 0
  97405. - 0 0 0 0 0 0 0 0 0 0 0 0
  97406. - 0 0 0 0 0 0 0 0 0 0 0 0
  97407. - 0 0 0 0 0 0 0 0 0 0 0 0
  97408. - 0 0 0 0 0 0 0 0 0 0 0 0
  97409. - 0 0 0 0 0 0 6 6 6 18 18 18
  97410. - 54 54 54 82 82 82 2 2 6 26 26 26
  97411. - 22 22 22 2 2 6 123 123 123 253 253 253
  97412. -253 253 253 253 253 253 253 253 253 253 253 253
  97413. -253 253 253 253 253 253 253 253 253 253 253 253
  97414. -253 253 253 253 253 253 253 253 253 253 253 253
  97415. -253 253 253 253 253 253 253 253 253 253 253 253
  97416. -253 253 253 253 253 253 253 253 253 253 253 253
  97417. -253 253 253 253 253 253 253 253 253 250 250 250
  97418. -238 238 238 198 198 198 6 6 6 38 38 38
  97419. - 58 58 58 26 26 26 38 38 38 2 2 6
  97420. - 2 2 6 2 2 6 2 2 6 46 46 46
  97421. - 78 78 78 30 30 30 10 10 10 0 0 0
  97422. - 0 0 0 0 0 0 0 0 0 0 0 0
  97423. - 0 0 0 0 0 0 0 0 0 0 0 0
  97424. - 0 0 0 0 0 0 0 0 0 0 0 0
  97425. - 0 0 0 0 0 0 0 0 0 0 0 0
  97426. - 0 0 0 0 0 0 0 0 0 0 0 0
  97427. - 0 0 0 0 0 0 0 0 0 0 0 0
  97428. - 0 0 0 0 0 0 0 0 0 0 0 0
  97429. - 0 0 0 0 0 0 10 10 10 30 30 30
  97430. - 74 74 74 58 58 58 2 2 6 42 42 42
  97431. - 2 2 6 22 22 22 231 231 231 253 253 253
  97432. -253 253 253 253 253 253 253 253 253 253 253 253
  97433. -253 253 253 253 253 253 253 253 253 250 250 250
  97434. -253 253 253 253 253 253 253 253 253 253 253 253
  97435. -253 253 253 253 253 253 253 253 253 253 253 253
  97436. -253 253 253 253 253 253 253 253 253 253 253 253
  97437. -253 253 253 253 253 253 253 253 253 253 253 253
  97438. -253 253 253 246 246 246 46 46 46 38 38 38
  97439. - 42 42 42 14 14 14 38 38 38 14 14 14
  97440. - 2 2 6 2 2 6 2 2 6 6 6 6
  97441. - 86 86 86 46 46 46 14 14 14 0 0 0
  97442. - 0 0 0 0 0 0 0 0 0 0 0 0
  97443. - 0 0 0 0 0 0 0 0 0 0 0 0
  97444. - 0 0 0 0 0 0 0 0 0 0 0 0
  97445. - 0 0 0 0 0 0 0 0 0 0 0 0
  97446. - 0 0 0 0 0 0 0 0 0 0 0 0
  97447. - 0 0 0 0 0 0 0 0 0 0 0 0
  97448. - 0 0 0 0 0 0 0 0 0 0 0 0
  97449. - 0 0 0 6 6 6 14 14 14 42 42 42
  97450. - 90 90 90 18 18 18 18 18 18 26 26 26
  97451. - 2 2 6 116 116 116 253 253 253 253 253 253
  97452. -253 253 253 253 253 253 253 253 253 253 253 253
  97453. -253 253 253 253 253 253 250 250 250 238 238 238
  97454. -253 253 253 253 253 253 253 253 253 253 253 253
  97455. -253 253 253 253 253 253 253 253 253 253 253 253
  97456. -253 253 253 253 253 253 253 253 253 253 253 253
  97457. -253 253 253 253 253 253 253 253 253 253 253 253
  97458. -253 253 253 253 253 253 94 94 94 6 6 6
  97459. - 2 2 6 2 2 6 10 10 10 34 34 34
  97460. - 2 2 6 2 2 6 2 2 6 2 2 6
  97461. - 74 74 74 58 58 58 22 22 22 6 6 6
  97462. - 0 0 0 0 0 0 0 0 0 0 0 0
  97463. - 0 0 0 0 0 0 0 0 0 0 0 0
  97464. - 0 0 0 0 0 0 0 0 0 0 0 0
  97465. - 0 0 0 0 0 0 0 0 0 0 0 0
  97466. - 0 0 0 0 0 0 0 0 0 0 0 0
  97467. - 0 0 0 0 0 0 0 0 0 0 0 0
  97468. - 0 0 0 0 0 0 0 0 0 0 0 0
  97469. - 0 0 0 10 10 10 26 26 26 66 66 66
  97470. - 82 82 82 2 2 6 38 38 38 6 6 6
  97471. - 14 14 14 210 210 210 253 253 253 253 253 253
  97472. -253 253 253 253 253 253 253 253 253 253 253 253
  97473. -253 253 253 253 253 253 246 246 246 242 242 242
  97474. -253 253 253 253 253 253 253 253 253 253 253 253
  97475. -253 253 253 253 253 253 253 253 253 253 253 253
  97476. -253 253 253 253 253 253 253 253 253 253 253 253
  97477. -253 253 253 253 253 253 253 253 253 253 253 253
  97478. -253 253 253 253 253 253 144 144 144 2 2 6
  97479. - 2 2 6 2 2 6 2 2 6 46 46 46
  97480. - 2 2 6 2 2 6 2 2 6 2 2 6
  97481. - 42 42 42 74 74 74 30 30 30 10 10 10
  97482. - 0 0 0 0 0 0 0 0 0 0 0 0
  97483. - 0 0 0 0 0 0 0 0 0 0 0 0
  97484. - 0 0 0 0 0 0 0 0 0 0 0 0
  97485. - 0 0 0 0 0 0 0 0 0 0 0 0
  97486. - 0 0 0 0 0 0 0 0 0 0 0 0
  97487. - 0 0 0 0 0 0 0 0 0 0 0 0
  97488. - 0 0 0 0 0 0 0 0 0 0 0 0
  97489. - 6 6 6 14 14 14 42 42 42 90 90 90
  97490. - 26 26 26 6 6 6 42 42 42 2 2 6
  97491. - 74 74 74 250 250 250 253 253 253 253 253 253
  97492. -253 253 253 253 253 253 253 253 253 253 253 253
  97493. -253 253 253 253 253 253 242 242 242 242 242 242
  97494. -253 253 253 253 253 253 253 253 253 253 253 253
  97495. -253 253 253 253 253 253 253 253 253 253 253 253
  97496. -253 253 253 253 253 253 253 253 253 253 253 253
  97497. -253 253 253 253 253 253 253 253 253 253 253 253
  97498. -253 253 253 253 253 253 182 182 182 2 2 6
  97499. - 2 2 6 2 2 6 2 2 6 46 46 46
  97500. - 2 2 6 2 2 6 2 2 6 2 2 6
  97501. - 10 10 10 86 86 86 38 38 38 10 10 10
  97502. - 0 0 0 0 0 0 0 0 0 0 0 0
  97503. - 0 0 0 0 0 0 0 0 0 0 0 0
  97504. - 0 0 0 0 0 0 0 0 0 0 0 0
  97505. - 0 0 0 0 0 0 0 0 0 0 0 0
  97506. - 0 0 0 0 0 0 0 0 0 0 0 0
  97507. - 0 0 0 0 0 0 0 0 0 0 0 0
  97508. - 0 0 0 0 0 0 0 0 0 0 0 0
  97509. - 10 10 10 26 26 26 66 66 66 82 82 82
  97510. - 2 2 6 22 22 22 18 18 18 2 2 6
  97511. -149 149 149 253 253 253 253 253 253 253 253 253
  97512. -253 253 253 253 253 253 253 253 253 253 253 253
  97513. -253 253 253 253 253 253 234 234 234 242 242 242
  97514. -253 253 253 253 253 253 253 253 253 253 253 253
  97515. -253 253 253 253 253 253 253 253 253 253 253 253
  97516. -253 253 253 253 253 253 253 253 253 253 253 253
  97517. -253 253 253 253 253 253 253 253 253 253 253 253
  97518. -253 253 253 253 253 253 206 206 206 2 2 6
  97519. - 2 2 6 2 2 6 2 2 6 38 38 38
  97520. - 2 2 6 2 2 6 2 2 6 2 2 6
  97521. - 6 6 6 86 86 86 46 46 46 14 14 14
  97522. - 0 0 0 0 0 0 0 0 0 0 0 0
  97523. - 0 0 0 0 0 0 0 0 0 0 0 0
  97524. - 0 0 0 0 0 0 0 0 0 0 0 0
  97525. - 0 0 0 0 0 0 0 0 0 0 0 0
  97526. - 0 0 0 0 0 0 0 0 0 0 0 0
  97527. - 0 0 0 0 0 0 0 0 0 0 0 0
  97528. - 0 0 0 0 0 0 0 0 0 6 6 6
  97529. - 18 18 18 46 46 46 86 86 86 18 18 18
  97530. - 2 2 6 34 34 34 10 10 10 6 6 6
  97531. -210 210 210 253 253 253 253 253 253 253 253 253
  97532. -253 253 253 253 253 253 253 253 253 253 253 253
  97533. -253 253 253 253 253 253 234 234 234 242 242 242
  97534. -253 253 253 253 253 253 253 253 253 253 253 253
  97535. -253 253 253 253 253 253 253 253 253 253 253 253
  97536. -253 253 253 253 253 253 253 253 253 253 253 253
  97537. -253 253 253 253 253 253 253 253 253 253 253 253
  97538. -253 253 253 253 253 253 221 221 221 6 6 6
  97539. - 2 2 6 2 2 6 6 6 6 30 30 30
  97540. - 2 2 6 2 2 6 2 2 6 2 2 6
  97541. - 2 2 6 82 82 82 54 54 54 18 18 18
  97542. - 6 6 6 0 0 0 0 0 0 0 0 0
  97543. - 0 0 0 0 0 0 0 0 0 0 0 0
  97544. - 0 0 0 0 0 0 0 0 0 0 0 0
  97545. - 0 0 0 0 0 0 0 0 0 0 0 0
  97546. - 0 0 0 0 0 0 0 0 0 0 0 0
  97547. - 0 0 0 0 0 0 0 0 0 0 0 0
  97548. - 0 0 0 0 0 0 0 0 0 10 10 10
  97549. - 26 26 26 66 66 66 62 62 62 2 2 6
  97550. - 2 2 6 38 38 38 10 10 10 26 26 26
  97551. -238 238 238 253 253 253 253 253 253 253 253 253
  97552. -253 253 253 253 253 253 253 253 253 253 253 253
  97553. -253 253 253 253 253 253 231 231 231 238 238 238
  97554. -253 253 253 253 253 253 253 253 253 253 253 253
  97555. -253 253 253 253 253 253 253 253 253 253 253 253
  97556. -253 253 253 253 253 253 253 253 253 253 253 253
  97557. -253 253 253 253 253 253 253 253 253 253 253 253
  97558. -253 253 253 253 253 253 231 231 231 6 6 6
  97559. - 2 2 6 2 2 6 10 10 10 30 30 30
  97560. - 2 2 6 2 2 6 2 2 6 2 2 6
  97561. - 2 2 6 66 66 66 58 58 58 22 22 22
  97562. - 6 6 6 0 0 0 0 0 0 0 0 0
  97563. - 0 0 0 0 0 0 0 0 0 0 0 0
  97564. - 0 0 0 0 0 0 0 0 0 0 0 0
  97565. - 0 0 0 0 0 0 0 0 0 0 0 0
  97566. - 0 0 0 0 0 0 0 0 0 0 0 0
  97567. - 0 0 0 0 0 0 0 0 0 0 0 0
  97568. - 0 0 0 0 0 0 0 0 0 10 10 10
  97569. - 38 38 38 78 78 78 6 6 6 2 2 6
  97570. - 2 2 6 46 46 46 14 14 14 42 42 42
  97571. -246 246 246 253 253 253 253 253 253 253 253 253
  97572. -253 253 253 253 253 253 253 253 253 253 253 253
  97573. -253 253 253 253 253 253 231 231 231 242 242 242
  97574. -253 253 253 253 253 253 253 253 253 253 253 253
  97575. -253 253 253 253 253 253 253 253 253 253 253 253
  97576. -253 253 253 253 253 253 253 253 253 253 253 253
  97577. -253 253 253 253 253 253 253 253 253 253 253 253
  97578. -253 253 253 253 253 253 234 234 234 10 10 10
  97579. - 2 2 6 2 2 6 22 22 22 14 14 14
  97580. - 2 2 6 2 2 6 2 2 6 2 2 6
  97581. - 2 2 6 66 66 66 62 62 62 22 22 22
  97582. - 6 6 6 0 0 0 0 0 0 0 0 0
  97583. - 0 0 0 0 0 0 0 0 0 0 0 0
  97584. - 0 0 0 0 0 0 0 0 0 0 0 0
  97585. - 0 0 0 0 0 0 0 0 0 0 0 0
  97586. - 0 0 0 0 0 0 0 0 0 0 0 0
  97587. - 0 0 0 0 0 0 0 0 0 0 0 0
  97588. - 0 0 0 0 0 0 6 6 6 18 18 18
  97589. - 50 50 50 74 74 74 2 2 6 2 2 6
  97590. - 14 14 14 70 70 70 34 34 34 62 62 62
  97591. -250 250 250 253 253 253 253 253 253 253 253 253
  97592. -253 253 253 253 253 253 253 253 253 253 253 253
  97593. -253 253 253 253 253 253 231 231 231 246 246 246
  97594. -253 253 253 253 253 253 253 253 253 253 253 253
  97595. -253 253 253 253 253 253 253 253 253 253 253 253
  97596. -253 253 253 253 253 253 253 253 253 253 253 253
  97597. -253 253 253 253 253 253 253 253 253 253 253 253
  97598. -253 253 253 253 253 253 234 234 234 14 14 14
  97599. - 2 2 6 2 2 6 30 30 30 2 2 6
  97600. - 2 2 6 2 2 6 2 2 6 2 2 6
  97601. - 2 2 6 66 66 66 62 62 62 22 22 22
  97602. - 6 6 6 0 0 0 0 0 0 0 0 0
  97603. - 0 0 0 0 0 0 0 0 0 0 0 0
  97604. - 0 0 0 0 0 0 0 0 0 0 0 0
  97605. - 0 0 0 0 0 0 0 0 0 0 0 0
  97606. - 0 0 0 0 0 0 0 0 0 0 0 0
  97607. - 0 0 0 0 0 0 0 0 0 0 0 0
  97608. - 0 0 0 0 0 0 6 6 6 18 18 18
  97609. - 54 54 54 62 62 62 2 2 6 2 2 6
  97610. - 2 2 6 30 30 30 46 46 46 70 70 70
  97611. -250 250 250 253 253 253 253 253 253 253 253 253
  97612. -253 253 253 253 253 253 253 253 253 253 253 253
  97613. -253 253 253 253 253 253 231 231 231 246 246 246
  97614. -253 253 253 253 253 253 253 253 253 253 253 253
  97615. -253 253 253 253 253 253 253 253 253 253 253 253
  97616. -253 253 253 253 253 253 253 253 253 253 253 253
  97617. -253 253 253 253 253 253 253 253 253 253 253 253
  97618. -253 253 253 253 253 253 226 226 226 10 10 10
  97619. - 2 2 6 6 6 6 30 30 30 2 2 6
  97620. - 2 2 6 2 2 6 2 2 6 2 2 6
  97621. - 2 2 6 66 66 66 58 58 58 22 22 22
  97622. - 6 6 6 0 0 0 0 0 0 0 0 0
  97623. - 0 0 0 0 0 0 0 0 0 0 0 0
  97624. - 0 0 0 0 0 0 0 0 0 0 0 0
  97625. - 0 0 0 0 0 0 0 0 0 0 0 0
  97626. - 0 0 0 0 0 0 0 0 0 0 0 0
  97627. - 0 0 0 0 0 0 0 0 0 0 0 0
  97628. - 0 0 0 0 0 0 6 6 6 22 22 22
  97629. - 58 58 58 62 62 62 2 2 6 2 2 6
  97630. - 2 2 6 2 2 6 30 30 30 78 78 78
  97631. -250 250 250 253 253 253 253 253 253 253 253 253
  97632. -253 253 253 253 253 253 253 253 253 253 253 253
  97633. -253 253 253 253 253 253 231 231 231 246 246 246
  97634. -253 253 253 253 253 253 253 253 253 253 253 253
  97635. -253 253 253 253 253 253 253 253 253 253 253 253
  97636. -253 253 253 253 253 253 253 253 253 253 253 253
  97637. -253 253 253 253 253 253 253 253 253 253 253 253
  97638. -253 253 253 253 253 253 206 206 206 2 2 6
  97639. - 22 22 22 34 34 34 18 14 6 22 22 22
  97640. - 26 26 26 18 18 18 6 6 6 2 2 6
  97641. - 2 2 6 82 82 82 54 54 54 18 18 18
  97642. - 6 6 6 0 0 0 0 0 0 0 0 0
  97643. - 0 0 0 0 0 0 0 0 0 0 0 0
  97644. - 0 0 0 0 0 0 0 0 0 0 0 0
  97645. - 0 0 0 0 0 0 0 0 0 0 0 0
  97646. - 0 0 0 0 0 0 0 0 0 0 0 0
  97647. - 0 0 0 0 0 0 0 0 0 0 0 0
  97648. - 0 0 0 0 0 0 6 6 6 26 26 26
  97649. - 62 62 62 106 106 106 74 54 14 185 133 11
  97650. -210 162 10 121 92 8 6 6 6 62 62 62
  97651. -238 238 238 253 253 253 253 253 253 253 253 253
  97652. -253 253 253 253 253 253 253 253 253 253 253 253
  97653. -253 253 253 253 253 253 231 231 231 246 246 246
  97654. -253 253 253 253 253 253 253 253 253 253 253 253
  97655. -253 253 253 253 253 253 253 253 253 253 253 253
  97656. -253 253 253 253 253 253 253 253 253 253 253 253
  97657. -253 253 253 253 253 253 253 253 253 253 253 253
  97658. -253 253 253 253 253 253 158 158 158 18 18 18
  97659. - 14 14 14 2 2 6 2 2 6 2 2 6
  97660. - 6 6 6 18 18 18 66 66 66 38 38 38
  97661. - 6 6 6 94 94 94 50 50 50 18 18 18
  97662. - 6 6 6 0 0 0 0 0 0 0 0 0
  97663. - 0 0 0 0 0 0 0 0 0 0 0 0
  97664. - 0 0 0 0 0 0 0 0 0 0 0 0
  97665. - 0 0 0 0 0 0 0 0 0 0 0 0
  97666. - 0 0 0 0 0 0 0 0 0 0 0 0
  97667. - 0 0 0 0 0 0 0 0 0 6 6 6
  97668. - 10 10 10 10 10 10 18 18 18 38 38 38
  97669. - 78 78 78 142 134 106 216 158 10 242 186 14
  97670. -246 190 14 246 190 14 156 118 10 10 10 10
  97671. - 90 90 90 238 238 238 253 253 253 253 253 253
  97672. -253 253 253 253 253 253 253 253 253 253 253 253
  97673. -253 253 253 253 253 253 231 231 231 250 250 250
  97674. -253 253 253 253 253 253 253 253 253 253 253 253
  97675. -253 253 253 253 253 253 253 253 253 253 253 253
  97676. -253 253 253 253 253 253 253 253 253 253 253 253
  97677. -253 253 253 253 253 253 253 253 253 246 230 190
  97678. -238 204 91 238 204 91 181 142 44 37 26 9
  97679. - 2 2 6 2 2 6 2 2 6 2 2 6
  97680. - 2 2 6 2 2 6 38 38 38 46 46 46
  97681. - 26 26 26 106 106 106 54 54 54 18 18 18
  97682. - 6 6 6 0 0 0 0 0 0 0 0 0
  97683. - 0 0 0 0 0 0 0 0 0 0 0 0
  97684. - 0 0 0 0 0 0 0 0 0 0 0 0
  97685. - 0 0 0 0 0 0 0 0 0 0 0 0
  97686. - 0 0 0 0 0 0 0 0 0 0 0 0
  97687. - 0 0 0 6 6 6 14 14 14 22 22 22
  97688. - 30 30 30 38 38 38 50 50 50 70 70 70
  97689. -106 106 106 190 142 34 226 170 11 242 186 14
  97690. -246 190 14 246 190 14 246 190 14 154 114 10
  97691. - 6 6 6 74 74 74 226 226 226 253 253 253
  97692. -253 253 253 253 253 253 253 253 253 253 253 253
  97693. -253 253 253 253 253 253 231 231 231 250 250 250
  97694. -253 253 253 253 253 253 253 253 253 253 253 253
  97695. -253 253 253 253 253 253 253 253 253 253 253 253
  97696. -253 253 253 253 253 253 253 253 253 253 253 253
  97697. -253 253 253 253 253 253 253 253 253 228 184 62
  97698. -241 196 14 241 208 19 232 195 16 38 30 10
  97699. - 2 2 6 2 2 6 2 2 6 2 2 6
  97700. - 2 2 6 6 6 6 30 30 30 26 26 26
  97701. -203 166 17 154 142 90 66 66 66 26 26 26
  97702. - 6 6 6 0 0 0 0 0 0 0 0 0
  97703. - 0 0 0 0 0 0 0 0 0 0 0 0
  97704. - 0 0 0 0 0 0 0 0 0 0 0 0
  97705. - 0 0 0 0 0 0 0 0 0 0 0 0
  97706. - 0 0 0 0 0 0 0 0 0 0 0 0
  97707. - 6 6 6 18 18 18 38 38 38 58 58 58
  97708. - 78 78 78 86 86 86 101 101 101 123 123 123
  97709. -175 146 61 210 150 10 234 174 13 246 186 14
  97710. -246 190 14 246 190 14 246 190 14 238 190 10
  97711. -102 78 10 2 2 6 46 46 46 198 198 198
  97712. -253 253 253 253 253 253 253 253 253 253 253 253
  97713. -253 253 253 253 253 253 234 234 234 242 242 242
  97714. -253 253 253 253 253 253 253 253 253 253 253 253
  97715. -253 253 253 253 253 253 253 253 253 253 253 253
  97716. -253 253 253 253 253 253 253 253 253 253 253 253
  97717. -253 253 253 253 253 253 253 253 253 224 178 62
  97718. -242 186 14 241 196 14 210 166 10 22 18 6
  97719. - 2 2 6 2 2 6 2 2 6 2 2 6
  97720. - 2 2 6 2 2 6 6 6 6 121 92 8
  97721. -238 202 15 232 195 16 82 82 82 34 34 34
  97722. - 10 10 10 0 0 0 0 0 0 0 0 0
  97723. - 0 0 0 0 0 0 0 0 0 0 0 0
  97724. - 0 0 0 0 0 0 0 0 0 0 0 0
  97725. - 0 0 0 0 0 0 0 0 0 0 0 0
  97726. - 0 0 0 0 0 0 0 0 0 0 0 0
  97727. - 14 14 14 38 38 38 70 70 70 154 122 46
  97728. -190 142 34 200 144 11 197 138 11 197 138 11
  97729. -213 154 11 226 170 11 242 186 14 246 190 14
  97730. -246 190 14 246 190 14 246 190 14 246 190 14
  97731. -225 175 15 46 32 6 2 2 6 22 22 22
  97732. -158 158 158 250 250 250 253 253 253 253 253 253
  97733. -253 253 253 253 253 253 253 253 253 253 253 253
  97734. -253 253 253 253 253 253 253 253 253 253 253 253
  97735. -253 253 253 253 253 253 253 253 253 253 253 253
  97736. -253 253 253 253 253 253 253 253 253 253 253 253
  97737. -253 253 253 250 250 250 242 242 242 224 178 62
  97738. -239 182 13 236 186 11 213 154 11 46 32 6
  97739. - 2 2 6 2 2 6 2 2 6 2 2 6
  97740. - 2 2 6 2 2 6 61 42 6 225 175 15
  97741. -238 190 10 236 186 11 112 100 78 42 42 42
  97742. - 14 14 14 0 0 0 0 0 0 0 0 0
  97743. - 0 0 0 0 0 0 0 0 0 0 0 0
  97744. - 0 0 0 0 0 0 0 0 0 0 0 0
  97745. - 0 0 0 0 0 0 0 0 0 0 0 0
  97746. - 0 0 0 0 0 0 0 0 0 6 6 6
  97747. - 22 22 22 54 54 54 154 122 46 213 154 11
  97748. -226 170 11 230 174 11 226 170 11 226 170 11
  97749. -236 178 12 242 186 14 246 190 14 246 190 14
  97750. -246 190 14 246 190 14 246 190 14 246 190 14
  97751. -241 196 14 184 144 12 10 10 10 2 2 6
  97752. - 6 6 6 116 116 116 242 242 242 253 253 253
  97753. -253 253 253 253 253 253 253 253 253 253 253 253
  97754. -253 253 253 253 253 253 253 253 253 253 253 253
  97755. -253 253 253 253 253 253 253 253 253 253 253 253
  97756. -253 253 253 253 253 253 253 253 253 253 253 253
  97757. -253 253 253 231 231 231 198 198 198 214 170 54
  97758. -236 178 12 236 178 12 210 150 10 137 92 6
  97759. - 18 14 6 2 2 6 2 2 6 2 2 6
  97760. - 6 6 6 70 47 6 200 144 11 236 178 12
  97761. -239 182 13 239 182 13 124 112 88 58 58 58
  97762. - 22 22 22 6 6 6 0 0 0 0 0 0
  97763. - 0 0 0 0 0 0 0 0 0 0 0 0
  97764. - 0 0 0 0 0 0 0 0 0 0 0 0
  97765. - 0 0 0 0 0 0 0 0 0 0 0 0
  97766. - 0 0 0 0 0 0 0 0 0 10 10 10
  97767. - 30 30 30 70 70 70 180 133 36 226 170 11
  97768. -239 182 13 242 186 14 242 186 14 246 186 14
  97769. -246 190 14 246 190 14 246 190 14 246 190 14
  97770. -246 190 14 246 190 14 246 190 14 246 190 14
  97771. -246 190 14 232 195 16 98 70 6 2 2 6
  97772. - 2 2 6 2 2 6 66 66 66 221 221 221
  97773. -253 253 253 253 253 253 253 253 253 253 253 253
  97774. -253 253 253 253 253 253 253 253 253 253 253 253
  97775. -253 253 253 253 253 253 253 253 253 253 253 253
  97776. -253 253 253 253 253 253 253 253 253 253 253 253
  97777. -253 253 253 206 206 206 198 198 198 214 166 58
  97778. -230 174 11 230 174 11 216 158 10 192 133 9
  97779. -163 110 8 116 81 8 102 78 10 116 81 8
  97780. -167 114 7 197 138 11 226 170 11 239 182 13
  97781. -242 186 14 242 186 14 162 146 94 78 78 78
  97782. - 34 34 34 14 14 14 6 6 6 0 0 0
  97783. - 0 0 0 0 0 0 0 0 0 0 0 0
  97784. - 0 0 0 0 0 0 0 0 0 0 0 0
  97785. - 0 0 0 0 0 0 0 0 0 0 0 0
  97786. - 0 0 0 0 0 0 0 0 0 6 6 6
  97787. - 30 30 30 78 78 78 190 142 34 226 170 11
  97788. -239 182 13 246 190 14 246 190 14 246 190 14
  97789. -246 190 14 246 190 14 246 190 14 246 190 14
  97790. -246 190 14 246 190 14 246 190 14 246 190 14
  97791. -246 190 14 241 196 14 203 166 17 22 18 6
  97792. - 2 2 6 2 2 6 2 2 6 38 38 38
  97793. -218 218 218 253 253 253 253 253 253 253 253 253
  97794. -253 253 253 253 253 253 253 253 253 253 253 253
  97795. -253 253 253 253 253 253 253 253 253 253 253 253
  97796. -253 253 253 253 253 253 253 253 253 253 253 253
  97797. -250 250 250 206 206 206 198 198 198 202 162 69
  97798. -226 170 11 236 178 12 224 166 10 210 150 10
  97799. -200 144 11 197 138 11 192 133 9 197 138 11
  97800. -210 150 10 226 170 11 242 186 14 246 190 14
  97801. -246 190 14 246 186 14 225 175 15 124 112 88
  97802. - 62 62 62 30 30 30 14 14 14 6 6 6
  97803. - 0 0 0 0 0 0 0 0 0 0 0 0
  97804. - 0 0 0 0 0 0 0 0 0 0 0 0
  97805. - 0 0 0 0 0 0 0 0 0 0 0 0
  97806. - 0 0 0 0 0 0 0 0 0 10 10 10
  97807. - 30 30 30 78 78 78 174 135 50 224 166 10
  97808. -239 182 13 246 190 14 246 190 14 246 190 14
  97809. -246 190 14 246 190 14 246 190 14 246 190 14
  97810. -246 190 14 246 190 14 246 190 14 246 190 14
  97811. -246 190 14 246 190 14 241 196 14 139 102 15
  97812. - 2 2 6 2 2 6 2 2 6 2 2 6
  97813. - 78 78 78 250 250 250 253 253 253 253 253 253
  97814. -253 253 253 253 253 253 253 253 253 253 253 253
  97815. -253 253 253 253 253 253 253 253 253 253 253 253
  97816. -253 253 253 253 253 253 253 253 253 253 253 253
  97817. -250 250 250 214 214 214 198 198 198 190 150 46
  97818. -219 162 10 236 178 12 234 174 13 224 166 10
  97819. -216 158 10 213 154 11 213 154 11 216 158 10
  97820. -226 170 11 239 182 13 246 190 14 246 190 14
  97821. -246 190 14 246 190 14 242 186 14 206 162 42
  97822. -101 101 101 58 58 58 30 30 30 14 14 14
  97823. - 6 6 6 0 0 0 0 0 0 0 0 0
  97824. - 0 0 0 0 0 0 0 0 0 0 0 0
  97825. - 0 0 0 0 0 0 0 0 0 0 0 0
  97826. - 0 0 0 0 0 0 0 0 0 10 10 10
  97827. - 30 30 30 74 74 74 174 135 50 216 158 10
  97828. -236 178 12 246 190 14 246 190 14 246 190 14
  97829. -246 190 14 246 190 14 246 190 14 246 190 14
  97830. -246 190 14 246 190 14 246 190 14 246 190 14
  97831. -246 190 14 246 190 14 241 196 14 226 184 13
  97832. - 61 42 6 2 2 6 2 2 6 2 2 6
  97833. - 22 22 22 238 238 238 253 253 253 253 253 253
  97834. -253 253 253 253 253 253 253 253 253 253 253 253
  97835. -253 253 253 253 253 253 253 253 253 253 253 253
  97836. -253 253 253 253 253 253 253 253 253 253 253 253
  97837. -253 253 253 226 226 226 187 187 187 180 133 36
  97838. -216 158 10 236 178 12 239 182 13 236 178 12
  97839. -230 174 11 226 170 11 226 170 11 230 174 11
  97840. -236 178 12 242 186 14 246 190 14 246 190 14
  97841. -246 190 14 246 190 14 246 186 14 239 182 13
  97842. -206 162 42 106 106 106 66 66 66 34 34 34
  97843. - 14 14 14 6 6 6 0 0 0 0 0 0
  97844. - 0 0 0 0 0 0 0 0 0 0 0 0
  97845. - 0 0 0 0 0 0 0 0 0 0 0 0
  97846. - 0 0 0 0 0 0 0 0 0 6 6 6
  97847. - 26 26 26 70 70 70 163 133 67 213 154 11
  97848. -236 178 12 246 190 14 246 190 14 246 190 14
  97849. -246 190 14 246 190 14 246 190 14 246 190 14
  97850. -246 190 14 246 190 14 246 190 14 246 190 14
  97851. -246 190 14 246 190 14 246 190 14 241 196 14
  97852. -190 146 13 18 14 6 2 2 6 2 2 6
  97853. - 46 46 46 246 246 246 253 253 253 253 253 253
  97854. -253 253 253 253 253 253 253 253 253 253 253 253
  97855. -253 253 253 253 253 253 253 253 253 253 253 253
  97856. -253 253 253 253 253 253 253 253 253 253 253 253
  97857. -253 253 253 221 221 221 86 86 86 156 107 11
  97858. -216 158 10 236 178 12 242 186 14 246 186 14
  97859. -242 186 14 239 182 13 239 182 13 242 186 14
  97860. -242 186 14 246 186 14 246 190 14 246 190 14
  97861. -246 190 14 246 190 14 246 190 14 246 190 14
  97862. -242 186 14 225 175 15 142 122 72 66 66 66
  97863. - 30 30 30 10 10 10 0 0 0 0 0 0
  97864. - 0 0 0 0 0 0 0 0 0 0 0 0
  97865. - 0 0 0 0 0 0 0 0 0 0 0 0
  97866. - 0 0 0 0 0 0 0 0 0 6 6 6
  97867. - 26 26 26 70 70 70 163 133 67 210 150 10
  97868. -236 178 12 246 190 14 246 190 14 246 190 14
  97869. -246 190 14 246 190 14 246 190 14 246 190 14
  97870. -246 190 14 246 190 14 246 190 14 246 190 14
  97871. -246 190 14 246 190 14 246 190 14 246 190 14
  97872. -232 195 16 121 92 8 34 34 34 106 106 106
  97873. -221 221 221 253 253 253 253 253 253 253 253 253
  97874. -253 253 253 253 253 253 253 253 253 253 253 253
  97875. -253 253 253 253 253 253 253 253 253 253 253 253
  97876. -253 253 253 253 253 253 253 253 253 253 253 253
  97877. -242 242 242 82 82 82 18 14 6 163 110 8
  97878. -216 158 10 236 178 12 242 186 14 246 190 14
  97879. -246 190 14 246 190 14 246 190 14 246 190 14
  97880. -246 190 14 246 190 14 246 190 14 246 190 14
  97881. -246 190 14 246 190 14 246 190 14 246 190 14
  97882. -246 190 14 246 190 14 242 186 14 163 133 67
  97883. - 46 46 46 18 18 18 6 6 6 0 0 0
  97884. - 0 0 0 0 0 0 0 0 0 0 0 0
  97885. - 0 0 0 0 0 0 0 0 0 0 0 0
  97886. - 0 0 0 0 0 0 0 0 0 10 10 10
  97887. - 30 30 30 78 78 78 163 133 67 210 150 10
  97888. -236 178 12 246 186 14 246 190 14 246 190 14
  97889. -246 190 14 246 190 14 246 190 14 246 190 14
  97890. -246 190 14 246 190 14 246 190 14 246 190 14
  97891. -246 190 14 246 190 14 246 190 14 246 190 14
  97892. -241 196 14 215 174 15 190 178 144 253 253 253
  97893. -253 253 253 253 253 253 253 253 253 253 253 253
  97894. -253 253 253 253 253 253 253 253 253 253 253 253
  97895. -253 253 253 253 253 253 253 253 253 253 253 253
  97896. -253 253 253 253 253 253 253 253 253 218 218 218
  97897. - 58 58 58 2 2 6 22 18 6 167 114 7
  97898. -216 158 10 236 178 12 246 186 14 246 190 14
  97899. -246 190 14 246 190 14 246 190 14 246 190 14
  97900. -246 190 14 246 190 14 246 190 14 246 190 14
  97901. -246 190 14 246 190 14 246 190 14 246 190 14
  97902. -246 190 14 246 186 14 242 186 14 190 150 46
  97903. - 54 54 54 22 22 22 6 6 6 0 0 0
  97904. - 0 0 0 0 0 0 0 0 0 0 0 0
  97905. - 0 0 0 0 0 0 0 0 0 0 0 0
  97906. - 0 0 0 0 0 0 0 0 0 14 14 14
  97907. - 38 38 38 86 86 86 180 133 36 213 154 11
  97908. -236 178 12 246 186 14 246 190 14 246 190 14
  97909. -246 190 14 246 190 14 246 190 14 246 190 14
  97910. -246 190 14 246 190 14 246 190 14 246 190 14
  97911. -246 190 14 246 190 14 246 190 14 246 190 14
  97912. -246 190 14 232 195 16 190 146 13 214 214 214
  97913. -253 253 253 253 253 253 253 253 253 253 253 253
  97914. -253 253 253 253 253 253 253 253 253 253 253 253
  97915. -253 253 253 253 253 253 253 253 253 253 253 253
  97916. -253 253 253 250 250 250 170 170 170 26 26 26
  97917. - 2 2 6 2 2 6 37 26 9 163 110 8
  97918. -219 162 10 239 182 13 246 186 14 246 190 14
  97919. -246 190 14 246 190 14 246 190 14 246 190 14
  97920. -246 190 14 246 190 14 246 190 14 246 190 14
  97921. -246 190 14 246 190 14 246 190 14 246 190 14
  97922. -246 186 14 236 178 12 224 166 10 142 122 72
  97923. - 46 46 46 18 18 18 6 6 6 0 0 0
  97924. - 0 0 0 0 0 0 0 0 0 0 0 0
  97925. - 0 0 0 0 0 0 0 0 0 0 0 0
  97926. - 0 0 0 0 0 0 6 6 6 18 18 18
  97927. - 50 50 50 109 106 95 192 133 9 224 166 10
  97928. -242 186 14 246 190 14 246 190 14 246 190 14
  97929. -246 190 14 246 190 14 246 190 14 246 190 14
  97930. -246 190 14 246 190 14 246 190 14 246 190 14
  97931. -246 190 14 246 190 14 246 190 14 246 190 14
  97932. -242 186 14 226 184 13 210 162 10 142 110 46
  97933. -226 226 226 253 253 253 253 253 253 253 253 253
  97934. -253 253 253 253 253 253 253 253 253 253 253 253
  97935. -253 253 253 253 253 253 253 253 253 253 253 253
  97936. -198 198 198 66 66 66 2 2 6 2 2 6
  97937. - 2 2 6 2 2 6 50 34 6 156 107 11
  97938. -219 162 10 239 182 13 246 186 14 246 190 14
  97939. -246 190 14 246 190 14 246 190 14 246 190 14
  97940. -246 190 14 246 190 14 246 190 14 246 190 14
  97941. -246 190 14 246 190 14 246 190 14 242 186 14
  97942. -234 174 13 213 154 11 154 122 46 66 66 66
  97943. - 30 30 30 10 10 10 0 0 0 0 0 0
  97944. - 0 0 0 0 0 0 0 0 0 0 0 0
  97945. - 0 0 0 0 0 0 0 0 0 0 0 0
  97946. - 0 0 0 0 0 0 6 6 6 22 22 22
  97947. - 58 58 58 154 121 60 206 145 10 234 174 13
  97948. -242 186 14 246 186 14 246 190 14 246 190 14
  97949. -246 190 14 246 190 14 246 190 14 246 190 14
  97950. -246 190 14 246 190 14 246 190 14 246 190 14
  97951. -246 190 14 246 190 14 246 190 14 246 190 14
  97952. -246 186 14 236 178 12 210 162 10 163 110 8
  97953. - 61 42 6 138 138 138 218 218 218 250 250 250
  97954. -253 253 253 253 253 253 253 253 253 250 250 250
  97955. -242 242 242 210 210 210 144 144 144 66 66 66
  97956. - 6 6 6 2 2 6 2 2 6 2 2 6
  97957. - 2 2 6 2 2 6 61 42 6 163 110 8
  97958. -216 158 10 236 178 12 246 190 14 246 190 14
  97959. -246 190 14 246 190 14 246 190 14 246 190 14
  97960. -246 190 14 246 190 14 246 190 14 246 190 14
  97961. -246 190 14 239 182 13 230 174 11 216 158 10
  97962. -190 142 34 124 112 88 70 70 70 38 38 38
  97963. - 18 18 18 6 6 6 0 0 0 0 0 0
  97964. - 0 0 0 0 0 0 0 0 0 0 0 0
  97965. - 0 0 0 0 0 0 0 0 0 0 0 0
  97966. - 0 0 0 0 0 0 6 6 6 22 22 22
  97967. - 62 62 62 168 124 44 206 145 10 224 166 10
  97968. -236 178 12 239 182 13 242 186 14 242 186 14
  97969. -246 186 14 246 190 14 246 190 14 246 190 14
  97970. -246 190 14 246 190 14 246 190 14 246 190 14
  97971. -246 190 14 246 190 14 246 190 14 246 190 14
  97972. -246 190 14 236 178 12 216 158 10 175 118 6
  97973. - 80 54 7 2 2 6 6 6 6 30 30 30
  97974. - 54 54 54 62 62 62 50 50 50 38 38 38
  97975. - 14 14 14 2 2 6 2 2 6 2 2 6
  97976. - 2 2 6 2 2 6 2 2 6 2 2 6
  97977. - 2 2 6 6 6 6 80 54 7 167 114 7
  97978. -213 154 11 236 178 12 246 190 14 246 190 14
  97979. -246 190 14 246 190 14 246 190 14 246 190 14
  97980. -246 190 14 242 186 14 239 182 13 239 182 13
  97981. -230 174 11 210 150 10 174 135 50 124 112 88
  97982. - 82 82 82 54 54 54 34 34 34 18 18 18
  97983. - 6 6 6 0 0 0 0 0 0 0 0 0
  97984. - 0 0 0 0 0 0 0 0 0 0 0 0
  97985. - 0 0 0 0 0 0 0 0 0 0 0 0
  97986. - 0 0 0 0 0 0 6 6 6 18 18 18
  97987. - 50 50 50 158 118 36 192 133 9 200 144 11
  97988. -216 158 10 219 162 10 224 166 10 226 170 11
  97989. -230 174 11 236 178 12 239 182 13 239 182 13
  97990. -242 186 14 246 186 14 246 190 14 246 190 14
  97991. -246 190 14 246 190 14 246 190 14 246 190 14
  97992. -246 186 14 230 174 11 210 150 10 163 110 8
  97993. -104 69 6 10 10 10 2 2 6 2 2 6
  97994. - 2 2 6 2 2 6 2 2 6 2 2 6
  97995. - 2 2 6 2 2 6 2 2 6 2 2 6
  97996. - 2 2 6 2 2 6 2 2 6 2 2 6
  97997. - 2 2 6 6 6 6 91 60 6 167 114 7
  97998. -206 145 10 230 174 11 242 186 14 246 190 14
  97999. -246 190 14 246 190 14 246 186 14 242 186 14
  98000. -239 182 13 230 174 11 224 166 10 213 154 11
  98001. -180 133 36 124 112 88 86 86 86 58 58 58
  98002. - 38 38 38 22 22 22 10 10 10 6 6 6
  98003. - 0 0 0 0 0 0 0 0 0 0 0 0
  98004. - 0 0 0 0 0 0 0 0 0 0 0 0
  98005. - 0 0 0 0 0 0 0 0 0 0 0 0
  98006. - 0 0 0 0 0 0 0 0 0 14 14 14
  98007. - 34 34 34 70 70 70 138 110 50 158 118 36
  98008. -167 114 7 180 123 7 192 133 9 197 138 11
  98009. -200 144 11 206 145 10 213 154 11 219 162 10
  98010. -224 166 10 230 174 11 239 182 13 242 186 14
  98011. -246 186 14 246 186 14 246 186 14 246 186 14
  98012. -239 182 13 216 158 10 185 133 11 152 99 6
  98013. -104 69 6 18 14 6 2 2 6 2 2 6
  98014. - 2 2 6 2 2 6 2 2 6 2 2 6
  98015. - 2 2 6 2 2 6 2 2 6 2 2 6
  98016. - 2 2 6 2 2 6 2 2 6 2 2 6
  98017. - 2 2 6 6 6 6 80 54 7 152 99 6
  98018. -192 133 9 219 162 10 236 178 12 239 182 13
  98019. -246 186 14 242 186 14 239 182 13 236 178 12
  98020. -224 166 10 206 145 10 192 133 9 154 121 60
  98021. - 94 94 94 62 62 62 42 42 42 22 22 22
  98022. - 14 14 14 6 6 6 0 0 0 0 0 0
  98023. - 0 0 0 0 0 0 0 0 0 0 0 0
  98024. - 0 0 0 0 0 0 0 0 0 0 0 0
  98025. - 0 0 0 0 0 0 0 0 0 0 0 0
  98026. - 0 0 0 0 0 0 0 0 0 6 6 6
  98027. - 18 18 18 34 34 34 58 58 58 78 78 78
  98028. -101 98 89 124 112 88 142 110 46 156 107 11
  98029. -163 110 8 167 114 7 175 118 6 180 123 7
  98030. -185 133 11 197 138 11 210 150 10 219 162 10
  98031. -226 170 11 236 178 12 236 178 12 234 174 13
  98032. -219 162 10 197 138 11 163 110 8 130 83 6
  98033. - 91 60 6 10 10 10 2 2 6 2 2 6
  98034. - 18 18 18 38 38 38 38 38 38 38 38 38
  98035. - 38 38 38 38 38 38 38 38 38 38 38 38
  98036. - 38 38 38 38 38 38 26 26 26 2 2 6
  98037. - 2 2 6 6 6 6 70 47 6 137 92 6
  98038. -175 118 6 200 144 11 219 162 10 230 174 11
  98039. -234 174 13 230 174 11 219 162 10 210 150 10
  98040. -192 133 9 163 110 8 124 112 88 82 82 82
  98041. - 50 50 50 30 30 30 14 14 14 6 6 6
  98042. - 0 0 0 0 0 0 0 0 0 0 0 0
  98043. - 0 0 0 0 0 0 0 0 0 0 0 0
  98044. - 0 0 0 0 0 0 0 0 0 0 0 0
  98045. - 0 0 0 0 0 0 0 0 0 0 0 0
  98046. - 0 0 0 0 0 0 0 0 0 0 0 0
  98047. - 6 6 6 14 14 14 22 22 22 34 34 34
  98048. - 42 42 42 58 58 58 74 74 74 86 86 86
  98049. -101 98 89 122 102 70 130 98 46 121 87 25
  98050. -137 92 6 152 99 6 163 110 8 180 123 7
  98051. -185 133 11 197 138 11 206 145 10 200 144 11
  98052. -180 123 7 156 107 11 130 83 6 104 69 6
  98053. - 50 34 6 54 54 54 110 110 110 101 98 89
  98054. - 86 86 86 82 82 82 78 78 78 78 78 78
  98055. - 78 78 78 78 78 78 78 78 78 78 78 78
  98056. - 78 78 78 82 82 82 86 86 86 94 94 94
  98057. -106 106 106 101 101 101 86 66 34 124 80 6
  98058. -156 107 11 180 123 7 192 133 9 200 144 11
  98059. -206 145 10 200 144 11 192 133 9 175 118 6
  98060. -139 102 15 109 106 95 70 70 70 42 42 42
  98061. - 22 22 22 10 10 10 0 0 0 0 0 0
  98062. - 0 0 0 0 0 0 0 0 0 0 0 0
  98063. - 0 0 0 0 0 0 0 0 0 0 0 0
  98064. - 0 0 0 0 0 0 0 0 0 0 0 0
  98065. - 0 0 0 0 0 0 0 0 0 0 0 0
  98066. - 0 0 0 0 0 0 0 0 0 0 0 0
  98067. - 0 0 0 0 0 0 6 6 6 10 10 10
  98068. - 14 14 14 22 22 22 30 30 30 38 38 38
  98069. - 50 50 50 62 62 62 74 74 74 90 90 90
  98070. -101 98 89 112 100 78 121 87 25 124 80 6
  98071. -137 92 6 152 99 6 152 99 6 152 99 6
  98072. -138 86 6 124 80 6 98 70 6 86 66 30
  98073. -101 98 89 82 82 82 58 58 58 46 46 46
  98074. - 38 38 38 34 34 34 34 34 34 34 34 34
  98075. - 34 34 34 34 34 34 34 34 34 34 34 34
  98076. - 34 34 34 34 34 34 38 38 38 42 42 42
  98077. - 54 54 54 82 82 82 94 86 76 91 60 6
  98078. -134 86 6 156 107 11 167 114 7 175 118 6
  98079. -175 118 6 167 114 7 152 99 6 121 87 25
  98080. -101 98 89 62 62 62 34 34 34 18 18 18
  98081. - 6 6 6 0 0 0 0 0 0 0 0 0
  98082. - 0 0 0 0 0 0 0 0 0 0 0 0
  98083. - 0 0 0 0 0 0 0 0 0 0 0 0
  98084. - 0 0 0 0 0 0 0 0 0 0 0 0
  98085. - 0 0 0 0 0 0 0 0 0 0 0 0
  98086. - 0 0 0 0 0 0 0 0 0 0 0 0
  98087. - 0 0 0 0 0 0 0 0 0 0 0 0
  98088. - 0 0 0 6 6 6 6 6 6 10 10 10
  98089. - 18 18 18 22 22 22 30 30 30 42 42 42
  98090. - 50 50 50 66 66 66 86 86 86 101 98 89
  98091. -106 86 58 98 70 6 104 69 6 104 69 6
  98092. -104 69 6 91 60 6 82 62 34 90 90 90
  98093. - 62 62 62 38 38 38 22 22 22 14 14 14
  98094. - 10 10 10 10 10 10 10 10 10 10 10 10
  98095. - 10 10 10 10 10 10 6 6 6 10 10 10
  98096. - 10 10 10 10 10 10 10 10 10 14 14 14
  98097. - 22 22 22 42 42 42 70 70 70 89 81 66
  98098. - 80 54 7 104 69 6 124 80 6 137 92 6
  98099. -134 86 6 116 81 8 100 82 52 86 86 86
  98100. - 58 58 58 30 30 30 14 14 14 6 6 6
  98101. - 0 0 0 0 0 0 0 0 0 0 0 0
  98102. - 0 0 0 0 0 0 0 0 0 0 0 0
  98103. - 0 0 0 0 0 0 0 0 0 0 0 0
  98104. - 0 0 0 0 0 0 0 0 0 0 0 0
  98105. - 0 0 0 0 0 0 0 0 0 0 0 0
  98106. - 0 0 0 0 0 0 0 0 0 0 0 0
  98107. - 0 0 0 0 0 0 0 0 0 0 0 0
  98108. - 0 0 0 0 0 0 0 0 0 0 0 0
  98109. - 0 0 0 6 6 6 10 10 10 14 14 14
  98110. - 18 18 18 26 26 26 38 38 38 54 54 54
  98111. - 70 70 70 86 86 86 94 86 76 89 81 66
  98112. - 89 81 66 86 86 86 74 74 74 50 50 50
  98113. - 30 30 30 14 14 14 6 6 6 0 0 0
  98114. - 0 0 0 0 0 0 0 0 0 0 0 0
  98115. - 0 0 0 0 0 0 0 0 0 0 0 0
  98116. - 0 0 0 0 0 0 0 0 0 0 0 0
  98117. - 6 6 6 18 18 18 34 34 34 58 58 58
  98118. - 82 82 82 89 81 66 89 81 66 89 81 66
  98119. - 94 86 66 94 86 76 74 74 74 50 50 50
  98120. - 26 26 26 14 14 14 6 6 6 0 0 0
  98121. - 0 0 0 0 0 0 0 0 0 0 0 0
  98122. - 0 0 0 0 0 0 0 0 0 0 0 0
  98123. - 0 0 0 0 0 0 0 0 0 0 0 0
  98124. - 0 0 0 0 0 0 0 0 0 0 0 0
  98125. - 0 0 0 0 0 0 0 0 0 0 0 0
  98126. - 0 0 0 0 0 0 0 0 0 0 0 0
  98127. - 0 0 0 0 0 0 0 0 0 0 0 0
  98128. - 0 0 0 0 0 0 0 0 0 0 0 0
  98129. - 0 0 0 0 0 0 0 0 0 0 0 0
  98130. - 6 6 6 6 6 6 14 14 14 18 18 18
  98131. - 30 30 30 38 38 38 46 46 46 54 54 54
  98132. - 50 50 50 42 42 42 30 30 30 18 18 18
  98133. - 10 10 10 0 0 0 0 0 0 0 0 0
  98134. - 0 0 0 0 0 0 0 0 0 0 0 0
  98135. - 0 0 0 0 0 0 0 0 0 0 0 0
  98136. - 0 0 0 0 0 0 0 0 0 0 0 0
  98137. - 0 0 0 6 6 6 14 14 14 26 26 26
  98138. - 38 38 38 50 50 50 58 58 58 58 58 58
  98139. - 54 54 54 42 42 42 30 30 30 18 18 18
  98140. - 10 10 10 0 0 0 0 0 0 0 0 0
  98141. - 0 0 0 0 0 0 0 0 0 0 0 0
  98142. - 0 0 0 0 0 0 0 0 0 0 0 0
  98143. - 0 0 0 0 0 0 0 0 0 0 0 0
  98144. - 0 0 0 0 0 0 0 0 0 0 0 0
  98145. - 0 0 0 0 0 0 0 0 0 0 0 0
  98146. - 0 0 0 0 0 0 0 0 0 0 0 0
  98147. - 0 0 0 0 0 0 0 0 0 0 0 0
  98148. - 0 0 0 0 0 0 0 0 0 0 0 0
  98149. - 0 0 0 0 0 0 0 0 0 0 0 0
  98150. - 0 0 0 0 0 0 0 0 0 6 6 6
  98151. - 6 6 6 10 10 10 14 14 14 18 18 18
  98152. - 18 18 18 14 14 14 10 10 10 6 6 6
  98153. - 0 0 0 0 0 0 0 0 0 0 0 0
  98154. - 0 0 0 0 0 0 0 0 0 0 0 0
  98155. - 0 0 0 0 0 0 0 0 0 0 0 0
  98156. - 0 0 0 0 0 0 0 0 0 0 0 0
  98157. - 0 0 0 0 0 0 0 0 0 6 6 6
  98158. - 14 14 14 18 18 18 22 22 22 22 22 22
  98159. - 18 18 18 14 14 14 10 10 10 6 6 6
  98160. - 0 0 0 0 0 0 0 0 0 0 0 0
  98161. - 0 0 0 0 0 0 0 0 0 0 0 0
  98162. - 0 0 0 0 0 0 0 0 0 0 0 0
  98163. - 0 0 0 0 0 0 0 0 0 0 0 0
  98164. - 0 0 0 0 0 0 0 0 0 0 0 0
  98165. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98166. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98167. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98168. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98169. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98170. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98171. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98172. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98173. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98174. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98175. +0 0 0 0 0 0 0 0 0
  98176. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98177. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98178. +0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 1 0
  98179. +0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98180. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98181. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98182. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98183. +0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0
  98184. +0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98185. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98186. +0 0 0 0 0 0 0 0 0
  98187. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98188. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
  98189. +10 15 3 2 3 1 12 18 4 42 61 14 19 27 6 11 16 4
  98190. +38 55 13 10 15 3 3 4 1 10 15 3 0 0 0 0 0 0
  98191. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98192. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98193. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 3 1
  98194. +12 18 4 1 1 0 23 34 8 31 45 11 10 15 3 32 47 11
  98195. +34 49 12 3 4 1 3 4 1 3 4 1 0 0 0 0 0 0
  98196. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98197. +0 0 0 0 0 0 0 0 0
  98198. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98199. +0 0 0 0 0 0 10 15 3 29 42 10 26 37 9 12 18 4
  98200. +55 80 19 81 118 28 55 80 19 92 132 31 106 153 36 69 100 23
  98201. +100 144 34 80 116 27 42 61 14 81 118 28 23 34 8 27 40 9
  98202. +15 21 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98203. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98204. +0 0 0 0 0 0 1 1 0 29 42 10 15 21 5 50 72 17
  98205. +74 107 25 45 64 15 102 148 35 80 116 27 84 121 28 111 160 38
  98206. +69 100 23 65 94 22 81 118 28 29 42 10 17 25 6 29 42 10
  98207. +23 34 8 2 3 1 0 0 0 0 0 0 0 0 0 0 0 0
  98208. +0 0 0 0 0 0 0 0 0
  98209. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 4 1
  98210. +15 21 5 15 21 5 34 49 12 101 146 34 111 161 38 97 141 33
  98211. +97 141 33 119 172 41 117 170 40 116 167 40 118 170 40 118 171 40
  98212. +117 169 40 118 170 40 111 160 38 118 170 40 96 138 32 89 128 30
  98213. +81 118 28 11 16 4 10 15 3 1 1 0 0 0 0 0 0 0
  98214. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98215. +3 4 1 3 4 1 34 49 12 101 146 34 79 115 27 111 160 38
  98216. +114 165 39 113 163 39 118 170 40 117 169 40 118 171 40 117 169 40
  98217. +116 167 40 119 172 41 113 163 39 92 132 31 105 151 36 113 163 39
  98218. +75 109 26 19 27 6 16 23 5 11 16 4 0 1 0 0 0 0
  98219. +0 0 0 0 0 0 0 0 0
  98220. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 15 3
  98221. +80 116 27 106 153 36 105 151 36 114 165 39 118 170 40 118 171 40
  98222. +118 171 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98223. +117 169 40 117 169 40 117 170 40 117 169 40 118 170 40 118 170 40
  98224. +117 170 40 75 109 26 75 109 26 34 49 12 0 0 0 0 0 0
  98225. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 4 1
  98226. +64 92 22 65 94 22 100 144 34 118 171 40 118 170 40 117 169 40
  98227. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98228. +117 169 40 117 169 40 117 169 40 118 171 41 118 170 40 117 169 40
  98229. +109 158 37 105 151 36 104 150 35 47 69 16 0 0 0 0 0 0
  98230. +0 0 0 0 0 0 0 0 0
  98231. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98232. +42 61 14 115 167 39 118 170 40 117 169 40 117 169 40 117 169 40
  98233. +117 170 40 117 170 40 117 169 40 117 169 40 117 169 40 117 169 40
  98234. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98235. +117 169 40 117 169 40 118 170 40 96 138 32 17 25 6 0 0 0
  98236. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 47 69 16
  98237. +114 165 39 117 168 40 117 170 40 117 169 40 117 169 40 117 169 40
  98238. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98239. +117 169 40 117 169 40 118 170 40 117 169 40 117 169 40 117 169 40
  98240. +117 170 40 119 172 41 96 138 32 12 18 4 0 0 0 0 0 0
  98241. +0 0 0 0 0 0 0 0 0
  98242. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 15 3
  98243. +32 47 11 105 151 36 118 170 40 117 169 40 117 169 40 116 168 40
  98244. +109 157 37 111 160 38 117 169 40 118 171 40 117 169 40 117 169 40
  98245. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98246. +117 169 40 117 169 40 117 169 40 118 171 40 69 100 23 2 3 1
  98247. +0 0 0 0 0 0 0 0 0 0 0 0 19 27 6 101 146 34
  98248. +118 171 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98249. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 170 40
  98250. +118 171 40 115 166 39 107 154 36 111 161 38 117 169 40 117 169 40
  98251. +117 169 40 118 171 40 75 109 26 19 27 6 2 3 1 0 0 0
  98252. +0 0 0 0 0 0 0 0 0
  98253. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 16 23 5
  98254. +89 128 30 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98255. +111 160 38 92 132 31 79 115 27 96 138 32 115 166 39 119 171 41
  98256. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98257. +117 169 40 117 169 40 117 169 40 118 170 40 109 157 37 26 37 9
  98258. +0 0 0 0 0 0 0 0 0 0 0 0 64 92 22 118 171 40
  98259. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98260. +117 169 40 117 169 40 117 169 40 118 170 40 118 171 40 109 157 37
  98261. +89 128 30 81 118 28 100 144 34 115 166 39 117 169 40 117 169 40
  98262. +117 169 40 117 170 40 113 163 39 60 86 20 1 1 0 0 0 0
  98263. +0 0 0 0 0 0 0 0 0
  98264. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98265. +27 40 9 96 138 32 118 170 40 117 169 40 117 169 40 117 169 40
  98266. +117 170 40 117 169 40 101 146 34 67 96 23 55 80 19 84 121 28
  98267. +113 163 39 119 171 41 117 169 40 117 169 40 117 169 40 117 169 40
  98268. +117 169 40 117 169 40 117 169 40 117 169 40 119 171 41 65 94 22
  98269. +0 0 0 0 0 0 0 0 0 15 21 5 101 146 34 118 171 40
  98270. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98271. +117 169 40 118 170 40 118 171 40 104 150 35 69 100 23 53 76 18
  98272. +81 118 28 111 160 38 118 170 40 117 169 40 117 169 40 117 169 40
  98273. +117 169 40 114 165 39 69 100 23 10 15 3 0 0 0 0 0 0
  98274. +0 0 0 0 0 0 0 0 0
  98275. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
  98276. +31 45 11 77 111 26 117 169 40 117 169 40 117 169 40 117 169 40
  98277. +117 169 40 117 169 40 118 170 40 116 168 40 92 132 31 47 69 16
  98278. +38 55 13 81 118 28 113 163 39 119 171 41 117 169 40 117 169 40
  98279. +117 169 40 117 169 40 117 169 40 117 169 40 118 171 41 92 132 31
  98280. +10 15 3 0 0 0 0 0 0 36 52 12 115 166 39 117 169 40
  98281. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 118 170 40
  98282. +118 171 40 102 148 35 64 92 22 34 49 12 65 94 22 106 153 36
  98283. +118 171 40 117 170 40 117 169 40 117 169 40 117 169 40 117 169 40
  98284. +118 170 40 107 154 36 55 80 19 15 21 5 0 0 0 0 0 0
  98285. +0 0 0 0 0 0 0 0 0
  98286. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98287. +29 42 10 101 146 34 118 171 40 117 169 40 117 169 40 117 169 40
  98288. +117 169 40 117 169 40 117 169 40 117 169 40 118 171 40 113 163 39
  98289. +75 109 26 27 40 9 36 52 12 89 128 30 116 167 40 118 171 40
  98290. +117 169 40 117 169 40 117 169 40 117 169 40 118 170 40 104 150 35
  98291. +16 23 5 0 0 0 0 0 0 53 76 18 118 171 40 117 169 40
  98292. +117 169 40 117 169 40 117 169 40 117 169 40 119 171 41 109 157 37
  98293. +67 96 23 23 34 8 42 61 14 96 138 32 118 170 40 118 170 40
  98294. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98295. +117 169 40 117 169 40 74 107 25 10 15 3 0 0 0 0 0 0
  98296. +0 0 0 0 0 0 0 0 0
  98297. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98298. +0 0 0 31 45 11 101 146 34 118 170 40 117 169 40 117 169 40
  98299. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98300. +119 171 41 102 148 35 47 69 16 14 20 5 50 72 17 102 148 35
  98301. +118 171 40 117 169 40 117 169 40 117 169 40 118 170 40 102 148 35
  98302. +15 21 5 0 0 0 0 0 0 50 72 17 118 170 40 117 169 40
  98303. +117 169 40 117 169 40 118 170 40 116 167 40 84 121 28 27 40 9
  98304. +19 27 6 74 107 25 114 165 39 118 171 40 117 169 40 117 169 40
  98305. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98306. +117 169 40 75 109 26 10 15 4 0 0 0 0 0 0 0 0 0
  98307. +0 0 0 0 0 0 0 0 0
  98308. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98309. +0 0 0 38 55 13 102 148 35 118 171 40 117 169 40 117 169 40
  98310. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98311. +117 169 40 118 170 40 115 167 39 77 111 26 17 25 6 19 27 6
  98312. +77 111 26 115 166 39 118 170 40 117 169 40 119 172 41 81 118 28
  98313. +3 4 1 0 0 0 0 0 0 27 40 9 111 160 38 118 170 40
  98314. +117 169 40 118 171 40 105 151 36 50 72 17 10 15 3 38 55 13
  98315. +100 144 34 118 171 40 117 169 40 117 169 40 117 169 40 117 169 40
  98316. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98317. +117 169 40 79 115 27 15 21 5 0 0 0 0 0 0 0 0 0
  98318. +0 0 0 0 0 0 0 0 0
  98319. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98320. +0 0 0 10 15 3 64 92 22 111 160 38 117 169 40 117 169 40
  98321. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98322. +117 169 40 117 169 40 117 169 40 118 171 40 96 138 32 32 47 11
  98323. +3 4 1 50 72 17 107 154 36 120 173 41 105 151 36 31 45 11
  98324. +0 0 0 0 0 0 0 0 0 3 4 1 65 94 22 117 169 40
  98325. +118 170 40 89 128 30 26 37 9 3 4 1 60 86 20 111 161 38
  98326. +118 171 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98327. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98328. +97 141 33 36 52 12 1 1 0 0 0 0 0 0 0 0 0 0
  98329. +0 0 0 0 0 0 0 0 0
  98330. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98331. +0 0 0 0 0 0 14 20 5 75 109 26 117 168 40 117 169 40
  98332. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98333. +117 169 40 117 169 40 117 169 40 117 169 40 118 171 40 107 154 36
  98334. +45 64 15 2 3 1 31 45 11 75 109 26 32 47 11 0 1 0
  98335. +0 0 0 0 0 0 0 0 0 0 0 0 10 15 3 55 80 19
  98336. +65 94 22 11 16 4 11 16 4 75 109 26 116 168 40 118 170 40
  98337. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98338. +117 169 40 117 169 40 117 169 40 117 169 40 118 170 40 107 154 36
  98339. +47 69 16 3 4 1 0 0 0 0 0 0 0 0 0 0 0 0
  98340. +0 0 0 0 0 0 0 0 0
  98341. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98342. +0 0 0 0 0 0 12 18 4 69 100 23 111 161 38 118 171 40
  98343. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98344. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 118 170 40
  98345. +111 160 38 50 72 17 2 3 1 2 3 1 0 0 0 0 0 0
  98346. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
  98347. +1 1 0 12 18 4 81 118 28 118 170 40 117 169 40 117 169 40
  98348. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98349. +117 169 40 117 169 40 117 169 40 117 170 40 118 171 40 101 146 34
  98350. +42 61 14 2 3 1 0 0 0 0 0 0 0 0 0 0 0 0
  98351. +0 0 0 0 0 0 0 0 0
  98352. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98353. +0 0 0 0 0 0 0 0 0 3 4 1 36 52 12 89 128 30
  98354. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98355. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98356. +118 171 41 101 146 34 14 20 5 0 0 0 0 0 0 0 0 0
  98357. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98358. +0 0 0 47 69 16 118 170 40 117 169 40 117 169 40 117 169 40
  98359. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98360. +117 169 40 117 169 40 117 170 40 111 160 38 69 100 23 19 27 6
  98361. +0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98362. +0 0 0 0 0 0 0 0 0
  98363. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98364. +0 0 0 0 0 0 0 0 0 0 0 0 11 16 4 69 100 23
  98365. +115 167 39 119 172 41 117 169 40 117 169 40 117 169 40 117 169 40
  98366. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98367. +119 172 41 75 109 26 3 4 1 0 0 0 0 0 0 0 0 0
  98368. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98369. +0 0 0 23 34 8 106 153 36 118 170 40 117 169 40 117 169 40
  98370. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98371. +117 169 40 118 170 40 119 172 41 105 151 36 42 61 14 2 3 1
  98372. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98373. +0 0 0 0 0 0 0 0 0
  98374. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98375. +0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 15 21 5
  98376. +45 64 15 80 116 27 114 165 39 118 170 40 117 169 40 117 169 40
  98377. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 119 172 41
  98378. +97 141 33 20 30 7 0 0 0 0 0 0 0 0 0 0 0 0
  98379. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98380. +0 0 0 1 1 0 53 76 18 114 165 39 118 171 40 117 169 40
  98381. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  98382. +118 171 40 104 150 35 64 92 22 31 45 11 10 15 3 0 0 0
  98383. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98384. +0 0 0 0 0 0 0 0 0
  98385. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98386. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98387. +0 0 0 36 52 12 97 141 33 109 158 37 113 163 39 116 168 40
  98388. +117 169 40 117 170 40 118 170 40 119 172 41 115 167 39 84 121 28
  98389. +23 34 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98390. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98391. +0 0 0 0 0 0 3 4 1 50 72 17 102 148 35 118 171 40
  98392. +119 171 41 118 170 40 117 169 40 117 169 40 115 166 39 111 161 38
  98393. +109 157 37 79 115 27 12 18 4 0 0 0 0 0 0 0 0 0
  98394. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98395. +0 0 0 0 0 0 0 0 0
  98396. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98397. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98398. +0 0 0 3 4 1 15 21 5 23 34 8 45 64 15 106 153 36
  98399. +116 167 40 111 160 38 101 146 34 79 115 27 42 61 14 10 15 3
  98400. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98401. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98402. +0 0 0 0 0 0 0 0 0 1 1 0 20 30 7 60 86 20
  98403. +89 128 30 106 153 36 113 163 39 117 169 40 84 121 28 29 42 10
  98404. +19 27 6 10 15 3 2 3 1 0 0 0 0 0 0 0 0 0
  98405. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98406. +0 0 0 0 0 0 0 0 0
  98407. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98408. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98409. +0 0 0 0 0 0 0 0 0 0 0 0 16 23 5 38 55 13
  98410. +36 52 12 26 37 9 12 18 4 2 3 1 0 0 0 0 0 0
  98411. +0 0 0 0 0 0 0 0 0 1 0 0 19 2 7 52 5 18
  98412. +78 7 27 88 8 31 81 7 29 56 5 19 25 2 9 3 0 1
  98413. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98414. +3 4 1 19 27 6 31 45 11 38 55 13 32 47 11 3 4 1
  98415. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98416. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98417. +0 0 0 0 0 0 0 0 0
  98418. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98419. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98420. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 1
  98421. +9 0 3 12 1 4 9 0 3 4 0 1 0 0 0 0 0 0
  98422. +0 0 0 0 0 0 28 3 10 99 9 35 156 14 55 182 16 64
  98423. +189 17 66 190 17 67 189 17 66 184 17 65 166 15 58 118 13 41
  98424. +45 4 16 3 0 1 0 0 0 0 0 0 0 0 0 0 0 0
  98425. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98426. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98427. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98428. +0 0 0 0 0 0 0 0 0
  98429. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98430. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98431. +0 0 0 0 0 0 11 1 4 52 5 18 101 9 35 134 12 47
  98432. +151 14 53 154 14 54 151 14 53 113 10 40 11 1 4 0 0 0
  98433. +3 0 1 67 6 24 159 14 56 190 17 67 190 17 67 188 17 66
  98434. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 191 17 67
  98435. +174 16 61 101 9 35 14 1 5 0 0 0 35 3 12 108 10 38
  98436. +122 11 43 122 11 43 112 10 39 87 8 30 50 5 17 13 1 5
  98437. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98438. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98439. +0 0 0 0 0 0 0 0 0
  98440. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98441. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98442. +3 0 1 56 5 19 141 13 49 182 16 64 191 17 67 191 17 67
  98443. +190 17 67 190 17 67 191 17 67 113 10 40 3 0 1 1 0 0
  98444. +79 7 28 180 16 63 190 17 67 188 17 66 188 17 66 188 17 66
  98445. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98446. +189 17 66 188 17 66 122 11 43 11 1 4 41 4 14 176 16 62
  98447. +191 17 67 191 17 67 191 17 67 190 17 67 181 16 63 146 13 51
  98448. +75 7 26 10 1 4 0 0 0 0 0 0 0 0 0 0 0 0
  98449. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98450. +0 0 0 0 0 0 0 0 0
  98451. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98452. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 1 2
  98453. +90 8 32 178 16 62 191 17 67 188 17 66 188 17 66 188 17 66
  98454. +188 17 66 190 17 67 141 13 49 22 2 8 0 0 0 41 4 14
  98455. +173 16 61 190 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  98456. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98457. +188 17 66 188 17 66 188 17 66 88 8 31 1 0 0 89 8 31
  98458. +185 17 65 189 17 66 188 17 66 188 17 66 189 17 66 191 17 67
  98459. +186 17 65 124 11 43 25 2 9 0 0 0 0 0 0 0 0 0
  98460. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98461. +0 0 0 0 0 0 0 0 0
  98462. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98463. +0 0 0 0 0 0 0 0 0 0 0 0 2 0 1 89 8 31
  98464. +184 17 65 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98465. +190 17 67 151 14 53 34 3 12 0 0 0 0 0 0 79 7 28
  98466. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98467. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98468. +188 17 66 188 17 66 191 17 67 146 13 51 9 1 3 7 1 2
  98469. +108 10 38 187 17 66 189 17 66 188 17 66 188 17 66 188 17 66
  98470. +188 17 66 190 17 67 141 13 49 22 2 8 0 0 0 0 0 0
  98471. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98472. +0 0 0 0 0 0 0 0 0
  98473. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98474. +0 0 0 0 0 0 0 0 0 0 0 0 52 5 18 176 16 62
  98475. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  98476. +151 14 53 38 3 13 0 0 0 0 0 0 0 0 0 50 5 17
  98477. +180 16 63 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98478. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98479. +188 17 66 188 17 66 191 17 67 141 13 49 7 1 3 0 0 0
  98480. +11 1 4 112 10 39 187 17 66 189 17 66 188 17 66 188 17 66
  98481. +188 17 66 188 17 66 190 17 67 113 10 40 5 0 2 0 0 0
  98482. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98483. +0 0 0 0 0 0 0 0 0
  98484. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98485. +0 0 0 0 0 0 0 0 0 7 1 3 132 12 46 191 17 67
  98486. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 146 13 51
  98487. +35 3 12 0 0 0 0 0 0 0 0 0 0 0 0 5 0 2
  98488. +101 9 35 185 17 65 190 17 67 188 17 66 188 17 66 188 17 66
  98489. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98490. +188 17 66 190 17 67 180 16 63 67 6 24 0 0 0 0 0 0
  98491. +0 0 0 11 1 4 108 10 38 186 17 65 189 17 66 188 17 66
  98492. +188 17 66 188 17 66 189 17 66 180 16 63 56 5 19 0 0 0
  98493. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98494. +0 0 0 0 0 0 0 0 0
  98495. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98496. +0 0 0 0 0 0 0 0 0 44 4 15 177 16 62 189 17 66
  98497. +188 17 66 188 17 66 189 17 66 189 17 66 134 12 47 28 3 10
  98498. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98499. +8 1 3 79 7 28 159 14 56 188 17 66 191 17 67 190 17 67
  98500. +189 17 66 189 17 66 189 17 66 189 17 66 190 17 67 191 17 67
  98501. +188 17 66 158 14 55 72 7 25 4 0 1 0 0 0 0 0 0
  98502. +0 0 0 0 0 0 8 1 3 95 9 33 182 16 64 189 17 67
  98503. +188 17 66 188 17 66 188 17 66 191 17 67 122 11 43 3 0 1
  98504. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98505. +0 0 0 0 0 0 0 0 0
  98506. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98507. +0 0 0 0 0 0 0 0 0 88 8 31 190 17 67 188 17 66
  98508. +188 17 66 189 17 66 185 17 65 113 10 40 18 2 6 0 0 0
  98509. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98510. +0 0 0 1 0 0 24 2 8 77 7 27 124 11 43 154 14 54
  98511. +168 15 59 173 16 61 173 16 61 168 15 59 154 14 54 124 11 43
  98512. +77 7 27 22 2 8 0 0 0 0 0 0 0 0 0 0 0 0
  98513. +0 0 0 0 0 0 0 0 0 5 0 2 77 7 27 173 16 61
  98514. +190 17 67 188 17 66 188 17 66 190 17 67 164 15 57 23 2 8
  98515. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98516. +0 0 0 0 0 0 0 0 0
  98517. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98518. +0 0 0 0 0 0 1 0 0 118 13 41 191 17 67 188 17 66
  98519. +190 17 67 174 16 61 87 8 30 8 1 3 0 0 0 0 0 0
  98520. +0 0 0 0 0 0 10 1 4 29 3 10 40 4 14 36 3 13
  98521. +18 2 6 2 0 1 0 0 0 0 0 0 3 0 1 14 1 5
  98522. +26 2 9 33 3 11 32 3 11 25 2 9 13 1 5 3 0 1
  98523. +0 0 0 14 1 5 56 5 19 95 9 33 109 10 38 101 9 35
  98524. +77 7 27 35 3 12 5 0 2 0 0 0 1 0 0 56 5 19
  98525. +156 14 55 190 17 67 188 17 66 188 17 66 182 16 64 50 5 17
  98526. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98527. +0 0 0 0 0 0 0 0 0
  98528. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98529. +0 0 0 0 0 0 5 0 2 134 12 47 191 17 67 189 17 66
  98530. +151 14 53 52 5 18 2 0 1 0 0 0 0 0 0 1 0 0
  98531. +28 3 10 90 8 32 146 13 51 170 15 60 178 16 62 174 16 61
  98532. +158 14 55 112 10 39 40 4 14 1 0 0 0 0 0 0 0 0
  98533. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 1
  98534. +56 5 19 146 13 51 183 17 64 191 17 67 191 17 67 191 17 67
  98535. +188 17 66 173 16 61 122 11 43 41 4 14 1 0 0 0 0 0
  98536. +30 3 10 124 11 43 185 17 65 190 17 67 187 17 66 67 6 24
  98537. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98538. +0 0 0 0 0 0 0 0 0
  98539. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98540. +0 0 0 0 0 0 6 1 2 134 12 47 168 15 59 99 9 35
  98541. +21 2 7 0 0 0 0 0 0 0 0 0 6 1 2 77 7 27
  98542. +162 15 57 190 17 67 191 17 67 189 17 66 189 17 66 189 17 66
  98543. +190 17 67 191 17 67 169 15 59 75 7 26 3 0 1 0 0 0
  98544. +0 0 0 0 0 0 0 0 0 0 0 0 2 0 1 79 7 28
  98545. +178 16 62 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  98546. +188 17 66 189 17 66 191 17 67 170 15 60 79 7 28 5 0 2
  98547. +0 0 0 10 1 3 78 7 27 159 14 56 188 17 66 75 7 26
  98548. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98549. +0 0 0 0 0 0 0 0 0
  98550. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98551. +0 0 0 0 0 0 1 0 0 35 3 12 29 3 10 2 0 1
  98552. +0 0 0 0 0 0 0 0 0 9 1 3 101 9 35 183 17 64
  98553. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98554. +188 17 66 188 17 66 190 17 67 178 16 63 67 6 23 0 0 0
  98555. +0 0 0 0 0 0 0 0 0 0 0 0 52 5 18 174 16 61
  98556. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98557. +188 17 66 188 17 66 188 17 66 190 17 67 182 16 64 89 8 31
  98558. +4 0 1 0 0 0 0 0 0 25 2 9 73 7 26 31 3 11
  98559. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98560. +0 0 0 0 0 0 0 0 0
  98561. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98562. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98563. +0 0 0 0 0 0 4 0 1 98 9 34 187 17 66 189 17 66
  98564. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98565. +188 17 66 188 17 66 188 17 66 190 17 67 158 14 55 25 2 9
  98566. +0 0 0 0 0 0 0 0 0 8 1 3 134 12 47 191 17 67
  98567. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98568. +188 17 66 188 17 66 188 17 66 188 17 66 189 17 66 180 16 63
  98569. +68 6 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98570. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98571. +0 0 0 0 0 0 0 0 0
  98572. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98573. +0 0 0 6 1 2 19 2 7 3 0 1 0 0 0 0 0 0
  98574. +0 0 0 0 0 0 65 6 23 180 16 63 189 17 66 188 17 66
  98575. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98576. +188 17 66 188 17 66 188 17 66 188 17 66 189 17 66 83 8 29
  98577. +0 0 0 0 0 0 0 0 0 41 4 14 177 16 62 189 17 66
  98578. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98579. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  98580. +159 14 56 28 3 10 0 0 0 0 0 0 0 0 0 23 2 8
  98581. +41 4 14 5 0 2 0 0 0 0 0 0 0 0 0 0 0 0
  98582. +0 0 0 0 0 0 0 0 0
  98583. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98584. +23 2 8 113 10 40 159 14 56 65 6 23 0 0 0 0 0 0
  98585. +0 0 0 16 1 6 146 13 51 191 17 67 188 17 66 188 17 66
  98586. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98587. +188 17 66 188 17 66 188 17 66 188 17 66 191 17 67 132 12 46
  98588. +5 0 2 0 0 0 0 0 0 77 7 27 189 17 66 188 17 66
  98589. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98590. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98591. +190 17 67 98 9 34 0 0 0 0 0 0 12 1 4 134 12 47
  98592. +178 16 63 108 10 38 16 1 6 0 0 0 0 0 0 0 0 0
  98593. +0 0 0 0 0 0 0 0 0
  98594. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 30 3 10
  98595. +141 13 49 190 17 67 191 17 67 134 12 47 6 1 2 0 0 0
  98596. +0 0 0 68 6 24 186 17 65 188 17 66 188 17 66 188 17 66
  98597. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98598. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 156 14 55
  98599. +14 1 5 0 0 0 0 0 0 98 9 34 191 17 67 188 17 66
  98600. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98601. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98602. +190 17 67 156 14 55 19 2 7 0 0 0 47 4 16 181 16 63
  98603. +190 17 67 189 17 66 126 14 44 17 2 6 0 0 0 0 0 0
  98604. +0 0 0 0 0 0 0 0 0
  98605. +0 0 0 0 0 0 0 0 0 0 0 0 16 1 6 134 12 47
  98606. +191 17 67 188 17 66 190 17 67 162 15 57 19 2 7 0 0 0
  98607. +3 0 1 123 11 43 191 17 67 188 17 66 188 17 66 188 17 66
  98608. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98609. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 163 15 57
  98610. +20 2 7 0 0 0 0 0 0 101 9 35 191 17 67 188 17 66
  98611. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98612. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98613. +188 17 66 182 16 64 52 5 18 0 0 0 73 7 26 188 17 66
  98614. +188 17 66 188 17 66 189 17 66 109 10 38 5 0 2 0 0 0
  98615. +0 0 0 0 0 0 0 0 0
  98616. +0 0 0 0 0 0 0 0 0 0 0 0 95 9 33 189 17 66
  98617. +188 17 66 188 17 66 189 17 66 171 15 60 29 3 10 0 0 0
  98618. +16 1 6 156 14 55 190 17 67 188 17 66 188 17 66 188 17 66
  98619. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98620. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 158 14 55
  98621. +17 2 6 0 0 0 0 0 0 85 8 30 190 17 67 188 17 66
  98622. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98623. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98624. +188 17 66 189 17 66 81 7 29 0 0 0 85 8 30 190 17 67
  98625. +188 17 66 188 17 66 189 17 66 180 16 63 56 5 19 0 0 0
  98626. +0 0 0 0 0 0 0 0 0
  98627. +0 0 0 0 0 0 0 0 0 25 2 9 162 15 57 190 17 67
  98628. +188 17 66 188 17 66 189 17 66 173 16 61 31 3 11 0 0 0
  98629. +30 3 10 171 15 60 189 17 66 188 17 66 188 17 66 188 17 66
  98630. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98631. +188 17 66 188 17 66 188 17 66 188 17 66 191 17 67 141 13 49
  98632. +7 1 2 0 0 0 0 0 0 56 5 19 183 17 64 188 17 66
  98633. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98634. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98635. +188 17 66 191 17 67 98 9 34 0 0 0 88 8 31 190 17 67
  98636. +188 17 66 188 17 66 188 17 66 191 17 67 124 11 43 5 0 2
  98637. +0 0 0 0 0 0 0 0 0
  98638. +0 0 0 0 0 0 0 0 0 68 6 24 187 17 66 188 17 66
  98639. +188 17 66 188 17 66 189 17 66 170 15 60 28 3 10 0 0 0
  98640. +34 3 12 174 16 61 189 17 66 188 17 66 188 17 66 188 17 66
  98641. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98642. +188 17 66 188 17 66 188 17 66 188 17 66 191 17 67 101 9 35
  98643. +0 0 0 0 0 0 0 0 0 21 2 7 159 14 56 190 17 67
  98644. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98645. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98646. +188 17 66 191 17 67 98 9 34 0 0 0 81 7 29 189 17 66
  98647. +188 17 66 188 17 66 188 17 66 189 17 66 168 15 59 28 3 10
  98648. +0 0 0 0 0 0 0 0 0
  98649. +0 0 0 0 0 0 0 0 0 109 10 38 191 17 67 188 17 66
  98650. +188 17 66 188 17 66 190 17 67 163 15 57 21 2 7 0 0 0
  98651. +26 2 9 168 15 59 189 17 66 188 17 66 188 17 66 188 17 66
  98652. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98653. +188 17 66 188 17 66 188 17 66 189 17 66 180 16 63 47 4 16
  98654. +0 0 0 0 0 0 0 0 0 0 0 0 108 10 38 190 17 67
  98655. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98656. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98657. +188 17 66 189 17 66 78 7 27 0 0 0 68 6 24 187 17 66
  98658. +188 17 66 188 17 66 188 17 66 188 17 66 183 17 64 56 5 19
  98659. +0 0 0 0 0 0 0 0 0
  98660. +0 0 0 0 0 0 3 0 1 131 12 46 191 17 67 188 17 66
  98661. +188 17 66 188 17 66 190 17 67 151 14 53 12 1 4 0 0 0
  98662. +11 1 4 146 13 51 190 17 67 188 17 66 188 17 66 188 17 66
  98663. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98664. +188 17 66 188 17 66 188 17 66 191 17 67 126 14 44 7 1 2
  98665. +0 0 0 0 0 0 0 0 0 0 0 0 32 3 11 164 15 58
  98666. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98667. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98668. +189 17 66 178 16 62 44 4 15 0 0 0 50 5 17 182 16 64
  98669. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 72 7 25
  98670. +0 0 0 0 0 0 0 0 0
  98671. +0 0 0 0 0 0 5 0 2 134 12 47 191 17 67 188 17 66
  98672. +188 17 66 188 17 66 191 17 67 131 12 46 3 0 1 0 0 0
  98673. +0 0 0 101 9 35 190 17 67 188 17 66 188 17 66 188 17 66
  98674. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98675. +188 17 66 188 17 66 190 17 67 170 15 60 44 4 15 0 0 0
  98676. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 77 7 27
  98677. +183 17 64 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98678. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98679. +191 17 67 134 12 47 9 1 3 0 0 0 31 3 11 171 15 60
  98680. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 72 7 25
  98681. +0 0 0 0 0 0 0 0 0
  98682. +0 0 0 0 0 0 2 0 1 124 11 43 191 17 67 188 17 66
  98683. +188 17 66 188 17 66 191 17 67 101 9 35 0 0 0 0 0 0
  98684. +0 0 0 35 3 12 168 15 59 190 17 67 188 17 66 188 17 66
  98685. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98686. +188 17 66 189 17 66 182 16 64 77 7 27 0 0 0 0 0 0
  98687. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 1 2
  98688. +99 9 35 185 17 65 189 17 66 188 17 66 188 17 66 188 17 66
  98689. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 189 17 66
  98690. +177 16 62 56 5 19 0 0 0 0 0 0 13 1 5 151 14 53
  98691. +190 17 67 188 17 66 188 17 66 188 17 66 185 17 65 56 5 19
  98692. +0 0 0 0 0 0 0 0 0
  98693. +0 0 0 0 0 0 0 0 0 99 9 35 191 17 67 188 17 66
  98694. +188 17 66 188 17 66 186 17 65 65 6 23 0 0 0 0 0 0
  98695. +0 0 0 0 0 0 79 7 28 182 16 64 190 17 67 188 17 66
  98696. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98697. +191 17 67 177 16 62 83 8 29 4 0 1 0 0 0 0 0 0
  98698. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98699. +8 1 3 89 8 31 175 16 62 191 17 67 189 17 66 188 17 66
  98700. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 181 16 63
  98701. +85 8 30 3 0 1 0 0 0 0 0 0 1 0 0 118 13 41
  98702. +191 17 67 188 17 66 188 17 66 189 17 66 173 16 61 34 3 12
  98703. +0 0 0 0 0 0 0 0 0
  98704. +0 0 0 0 0 0 0 0 0 56 5 19 183 17 64 188 17 66
  98705. +188 17 66 189 17 66 169 15 59 30 3 10 0 0 0 0 0 0
  98706. +0 0 0 0 0 0 5 0 2 83 8 29 173 16 61 191 17 67
  98707. +190 17 67 189 17 66 189 17 66 190 17 67 191 17 67 187 17 66
  98708. +151 14 53 56 5 19 3 0 1 0 0 0 16 1 6 50 5 17
  98709. +79 7 28 95 9 33 95 9 33 75 7 26 41 4 14 10 1 4
  98710. +0 0 0 2 0 1 50 5 17 132 12 46 178 16 62 190 17 67
  98711. +191 17 67 191 17 67 191 17 67 186 17 65 154 14 54 68 6 24
  98712. +4 0 1 0 0 0 0 0 0 0 0 0 0 0 0 72 7 25
  98713. +187 17 66 188 17 66 188 17 66 191 17 67 141 13 49 9 1 3
  98714. +0 0 0 0 0 0 0 0 0
  98715. +0 0 0 0 0 0 0 0 0 14 1 5 151 14 53 190 17 67
  98716. +188 17 66 191 17 67 131 12 46 5 0 2 0 0 0 0 0 0
  98717. +0 0 0 0 0 0 0 0 0 2 0 1 44 4 15 113 10 40
  98718. +156 14 55 173 16 61 174 16 61 164 15 58 134 12 47 77 7 27
  98719. +18 2 6 0 0 0 16 1 6 85 8 30 151 14 53 182 16 64
  98720. +189 17 66 191 17 67 190 17 67 188 17 66 177 16 62 141 13 49
  98721. +68 6 24 8 1 3 0 0 0 8 1 3 44 4 15 88 8 31
  98722. +113 10 40 122 11 43 108 10 38 67 6 24 20 2 7 0 0 0
  98723. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 28 3 10
  98724. +166 15 58 190 17 67 188 17 66 187 17 66 79 7 28 0 0 0
  98725. +0 0 0 0 0 0 0 0 0
  98726. +0 0 0 0 0 0 0 0 0 0 0 0 73 7 26 185 17 65
  98727. +189 17 66 184 17 65 65 6 23 0 0 0 0 0 0 0 0 0
  98728. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 1
  98729. +17 2 6 32 3 11 34 3 12 22 2 8 6 1 2 0 0 0
  98730. +0 0 0 38 3 13 141 13 49 188 17 66 190 17 67 188 17 66
  98731. +188 17 66 188 17 66 188 17 66 188 17 66 189 17 66 191 17 67
  98732. +184 17 65 122 11 43 21 2 7 0 0 0 0 0 0 0 0 0
  98733. +0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98734. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
  98735. +108 10 38 191 17 67 191 17 67 141 13 49 16 1 6 0 0 0
  98736. +0 0 0 0 0 0 0 0 0
  98737. +0 0 0 0 0 0 0 0 0 0 0 0 8 1 3 112 10 39
  98738. +186 17 65 124 11 43 10 1 4 0 0 0 0 0 0 0 0 0
  98739. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98740. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98741. +36 3 13 156 14 55 191 17 67 188 17 66 188 17 66 188 17 66
  98742. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98743. +189 17 66 190 17 67 134 12 47 18 2 6 0 0 0 0 0 0
  98744. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98745. +0 0 0 7 1 2 41 4 14 75 7 26 66 5 23 19 2 7
  98746. +26 2 9 144 13 50 154 14 54 40 4 14 0 0 0 0 0 0
  98747. +0 0 0 0 0 0 0 0 0
  98748. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 13 1 5
  98749. +56 5 19 19 2 7 0 0 0 7 1 2 29 3 10 35 3 12
  98750. +19 2 7 2 0 1 0 0 0 0 0 0 0 0 0 0 0 0
  98751. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 13 1 5
  98752. +134 12 47 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  98753. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98754. +188 17 66 188 17 66 189 17 67 108 10 38 3 0 1 0 0 0
  98755. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
  98756. +40 4 14 124 11 43 177 16 62 188 17 66 187 17 66 144 13 50
  98757. +24 2 8 17 2 6 22 2 8 0 0 0 0 0 0 0 0 0
  98758. +0 0 0 0 0 0 0 0 0
  98759. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98760. +0 0 0 0 0 0 19 2 7 122 11 43 171 15 60 175 16 62
  98761. +159 14 56 112 10 39 40 4 14 2 0 1 0 0 0 0 0 0
  98762. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 72 7 25
  98763. +186 17 65 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98764. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98765. +188 17 66 188 17 66 189 17 66 174 16 61 41 4 14 0 0 0
  98766. +0 0 0 0 0 0 0 0 0 0 0 0 3 0 1 72 7 25
  98767. +168 15 59 191 17 67 189 17 66 188 17 66 188 17 66 190 17 67
  98768. +95 9 33 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98769. +0 0 0 0 0 0 0 0 0
  98770. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98771. +0 0 0 0 0 0 95 9 33 191 17 67 189 17 66 189 17 66
  98772. +190 17 67 191 17 67 171 15 60 90 8 32 12 1 4 0 0 0
  98773. +0 0 0 0 0 0 0 0 0 0 0 0 5 0 2 132 12 46
  98774. +191 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98775. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98776. +188 17 66 188 17 66 188 17 66 190 17 67 98 9 34 0 0 0
  98777. +0 0 0 0 0 0 0 0 0 5 0 2 88 8 31 180 16 63
  98778. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 191 17 67
  98779. +146 13 51 11 1 4 0 0 0 0 0 0 0 0 0 0 0 0
  98780. +0 0 0 0 0 0 0 0 0
  98781. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98782. +0 0 0 9 1 3 144 13 50 191 17 67 188 17 66 188 17 66
  98783. +188 17 66 188 17 66 189 17 66 187 17 66 123 11 43 20 2 7
  98784. +0 0 0 0 0 0 0 0 0 0 0 0 21 2 7 163 15 57
  98785. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98786. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98787. +188 17 66 188 17 66 188 17 66 191 17 67 134 12 47 5 0 2
  98788. +0 0 0 0 0 0 3 0 1 88 8 31 182 16 64 189 17 66
  98789. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 189 17 66
  98790. +171 15 60 31 3 11 0 0 0 0 0 0 0 0 0 0 0 0
  98791. +0 0 0 0 0 0 0 0 0
  98792. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98793. +0 0 0 20 2 7 162 15 57 190 17 67 188 17 66 188 17 66
  98794. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 132 12 46
  98795. +20 2 7 0 0 0 0 0 0 0 0 0 32 3 11 173 16 61
  98796. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98797. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98798. +188 17 66 188 17 66 188 17 66 190 17 67 151 14 53 12 1 4
  98799. +0 0 0 0 0 0 72 7 25 180 16 63 189 17 66 188 17 66
  98800. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98801. +181 16 63 47 4 16 0 0 0 0 0 0 0 0 0 0 0 0
  98802. +0 0 0 0 0 0 0 0 0
  98803. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98804. +0 0 0 21 2 7 163 15 57 190 17 67 188 17 66 188 17 66
  98805. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  98806. +122 11 43 9 1 3 0 0 0 0 0 0 30 3 10 171 15 60
  98807. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98808. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98809. +188 17 66 188 17 66 188 17 66 190 17 67 146 13 51 10 1 4
  98810. +0 0 0 38 3 13 166 15 58 190 17 67 188 17 66 188 17 66
  98811. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98812. +183 17 64 52 5 18 0 0 0 0 0 0 0 0 0 0 0 0
  98813. +0 0 0 0 0 0 0 0 0
  98814. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98815. +0 0 0 13 1 5 154 14 54 190 17 67 188 17 66 188 17 66
  98816. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98817. +186 17 65 79 7 28 0 0 0 0 0 0 14 1 5 156 14 54
  98818. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98819. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98820. +188 17 66 188 17 66 188 17 66 191 17 67 124 11 43 2 0 1
  98821. +5 0 2 122 11 43 191 17 67 188 17 66 188 17 66 188 17 66
  98822. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98823. +182 16 64 47 4 16 0 0 0 0 0 0 0 0 0 0 0 0
  98824. +0 0 0 0 0 0 0 0 0
  98825. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98826. +0 0 0 3 0 1 126 14 44 191 17 67 188 17 66 188 17 66
  98827. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98828. +190 17 67 158 14 55 23 2 8 0 0 0 1 0 0 113 10 40
  98829. +191 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98830. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98831. +188 17 66 188 17 66 188 17 66 188 17 66 78 7 27 0 0 0
  98832. +47 4 16 177 16 62 189 17 66 188 17 66 188 17 66 188 17 66
  98833. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 189 17 66
  98834. +173 16 61 34 3 12 0 0 0 0 0 0 0 0 0 0 0 0
  98835. +0 0 0 0 0 0 0 0 0
  98836. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98837. +0 0 0 0 0 0 85 8 30 189 17 66 188 17 66 188 17 66
  98838. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98839. +188 17 66 188 17 66 79 7 28 0 0 0 0 0 0 47 4 16
  98840. +175 16 62 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98841. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98842. +188 17 66 188 17 66 190 17 67 156 14 55 22 2 8 0 0 0
  98843. +109 10 38 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  98844. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  98845. +151 14 53 13 1 5 0 0 0 0 0 0 0 0 0 0 0 0
  98846. +0 0 0 0 0 0 0 0 0
  98847. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98848. +0 0 0 0 0 0 35 3 12 173 16 61 189 17 66 188 17 66
  98849. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98850. +188 17 66 191 17 67 134 12 47 7 1 2 0 0 0 3 0 1
  98851. +99 9 35 188 17 66 189 17 66 188 17 66 188 17 66 188 17 66
  98852. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98853. +188 17 66 189 17 66 181 16 63 68 6 24 0 0 0 18 2 6
  98854. +156 14 55 190 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  98855. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  98856. +101 9 35 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98857. +0 0 0 0 0 0 0 0 0
  98858. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98859. +0 0 0 0 0 0 3 0 1 118 13 41 191 17 67 188 17 66
  98860. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98861. +188 17 66 189 17 66 168 15 59 28 3 10 0 0 0 0 0 0
  98862. +12 1 4 113 10 40 187 17 66 189 17 67 188 17 66 188 17 66
  98863. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98864. +190 17 67 180 16 63 88 8 31 4 0 1 0 0 0 47 4 16
  98865. +180 16 63 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98866. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 168 15 59
  98867. +36 3 13 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98868. +0 0 0 0 0 0 0 0 0
  98869. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98870. +0 0 0 0 0 0 0 0 0 38 3 13 164 15 58 190 17 67
  98871. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98872. +188 17 66 188 17 66 182 16 64 50 5 17 0 0 0 0 0 0
  98873. +0 0 0 11 1 4 90 8 32 169 15 59 190 17 67 190 17 67
  98874. +189 17 66 189 17 66 189 17 66 189 17 66 191 17 67 189 17 66
  98875. +158 14 55 68 6 24 4 0 1 0 0 0 0 0 0 73 7 26
  98876. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98877. +188 17 66 188 17 66 188 17 66 189 17 66 185 17 65 83 8 29
  98878. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98879. +0 0 0 0 0 0 0 0 0
  98880. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98881. +0 0 0 0 0 0 0 0 0 0 0 0 65 6 23 174 16 61
  98882. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98883. +188 17 66 188 17 66 185 17 65 56 5 19 0 0 0 0 0 0
  98884. +0 0 0 0 0 0 2 0 1 35 3 12 99 9 35 146 13 51
  98885. +170 15 60 177 16 62 177 16 62 166 15 58 141 13 49 85 8 30
  98886. +24 2 8 0 0 0 0 0 0 0 0 0 0 0 0 85 8 30
  98887. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98888. +188 17 66 188 17 66 188 17 66 189 17 66 112 10 39 8 1 3
  98889. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98890. +0 0 0 0 0 0 0 0 0
  98891. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98892. +0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 68 6 24
  98893. +170 15 60 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  98894. +188 17 66 188 17 66 182 16 64 50 5 17 0 0 0 0 0 0
  98895. +0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 11 1 4
  98896. +28 3 10 40 4 14 38 3 13 25 2 9 8 1 3 0 0 0
  98897. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 78 7 27
  98898. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98899. +188 17 66 189 17 66 187 17 66 113 10 40 14 1 5 0 0 0
  98900. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98901. +0 0 0 0 0 0 0 0 0
  98902. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98903. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
  98904. +47 4 16 141 13 49 186 17 65 191 17 67 190 17 67 189 17 66
  98905. +189 17 66 191 17 67 156 14 55 20 2 7 0 0 0 0 0 0
  98906. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98907. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98908. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 44 4 15
  98909. +178 16 62 190 17 67 188 17 66 188 17 66 188 17 66 190 17 67
  98910. +191 17 67 173 16 61 90 8 32 10 1 4 0 0 0 0 0 0
  98911. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98912. +0 0 0 0 0 0 0 0 0
  98913. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98914. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98915. +0 0 0 14 1 5 68 6 24 131 12 46 162 15 57 174 16 61
  98916. +171 15 60 146 13 51 56 5 19 0 0 0 0 0 0 0 0 0
  98917. +0 0 0 0 0 0 0 0 0 3 0 1 14 1 5 29 3 10
  98918. +41 4 14 47 4 16 50 5 17 45 4 16 34 3 12 18 2 6
  98919. +5 0 2 0 0 0 0 0 0 0 0 0 0 0 0 5 0 2
  98920. +90 8 32 169 15 59 185 17 65 187 17 66 182 16 64 163 15 57
  98921. +113 10 40 41 4 14 2 0 1 0 0 0 0 0 0 0 0 0
  98922. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98923. +0 0 0 0 0 0 0 0 0
  98924. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98925. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98926. +0 0 0 0 0 0 0 0 0 5 0 2 21 2 7 34 3 12
  98927. +29 3 10 11 1 4 0 0 0 0 0 0 0 0 0 0 0 0
  98928. +3 0 1 32 3 11 79 7 28 124 11 43 154 14 54 171 15 60
  98929. +180 16 63 182 16 64 182 16 64 180 16 63 174 16 61 159 14 56
  98930. +132 12 46 88 8 31 34 3 12 3 0 1 0 0 0 0 0 0
  98931. +3 0 1 29 3 10 56 5 19 65 6 23 50 5 17 23 2 8
  98932. +3 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98933. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98934. +0 0 0 0 0 0 0 0 0
  98935. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98936. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98937. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98938. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 25 2 9
  98939. +109 10 38 169 15 59 189 17 66 191 17 67 190 17 67 189 17 66
  98940. +189 17 66 188 17 66 188 17 66 188 17 66 189 17 66 190 17 67
  98941. +191 17 67 190 17 67 171 15 60 98 9 34 10 1 3 0 0 0
  98942. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98943. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98944. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98945. +0 0 0 0 0 0 0 0 0
  98946. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98947. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98948. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98949. +0 0 0 0 0 0 0 0 0 0 0 0 14 1 5 141 13 49
  98950. +191 17 67 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98951. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98952. +188 17 66 188 17 66 189 17 67 186 17 65 65 6 23 0 0 0
  98953. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98954. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98955. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98956. +0 0 0 0 0 0 0 0 0
  98957. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98958. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98959. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98960. +0 0 0 0 0 0 0 0 0 0 0 0 23 2 8 166 15 58
  98961. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98962. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98963. +188 17 66 188 17 66 189 17 66 176 16 62 45 4 16 0 0 0
  98964. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98965. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98966. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98967. +0 0 0 0 0 0 0 0 0
  98968. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98969. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98970. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98971. +0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 83 8 29
  98972. +183 17 64 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98973. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98974. +188 17 66 189 17 66 185 17 65 95 9 33 3 0 1 0 0 0
  98975. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98976. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98977. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98978. +0 0 0 0 0 0 0 0 0
  98979. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98980. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98981. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98982. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 0 2
  98983. +85 8 30 176 16 62 191 17 67 188 17 66 188 17 66 188 17 66
  98984. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  98985. +191 17 67 180 16 63 95 9 33 7 1 3 0 0 0 0 0 0
  98986. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98987. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98988. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98989. +0 0 0 0 0 0 0 0 0
  98990. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98991. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98992. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98993. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98994. +2 0 1 52 5 18 141 13 49 185 17 65 191 17 67 189 17 67
  98995. +189 17 66 188 17 66 188 17 66 189 17 66 191 17 67 187 17 66
  98996. +146 13 51 56 5 19 4 0 1 0 0 0 0 0 0 0 0 0
  98997. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98998. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  98999. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99000. +0 0 0 0 0 0 0 0 0
  99001. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99002. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99003. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99004. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99005. +0 0 0 0 0 0 14 1 5 68 6 24 131 12 46 166 15 58
  99006. +180 16 63 183 17 64 180 16 63 168 15 59 134 12 47 75 7 26
  99007. +17 2 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99008. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99009. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99010. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99011. +0 0 0 0 0 0 0 0 0
  99012. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99013. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99014. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99015. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99016. +0 0 0 0 0 0 0 0 0 0 0 0 5 0 2 24 2 8
  99017. +44 4 15 52 5 18 45 4 16 26 2 9 6 1 2 0 0 0
  99018. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99019. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99020. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99021. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99022. +0 0 0 0 0 0 0 0 0
  99023. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99024. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99025. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99026. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99027. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99028. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99029. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99030. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99031. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99032. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99033. +0 0 0 0 0 0 0 0 0
  99034. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99035. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99036. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99037. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99038. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99039. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99040. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99041. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99042. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99043. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  99044. +0 0 0 0 0 0 0 0 0
  99045. diff -Nur linux-3.12.26.orig/drivers/video/Makefile linux-3.12.26/drivers/video/Makefile
  99046. --- linux-3.12.26.orig/drivers/video/Makefile 2014-07-30 18:02:44.000000000 +0200
  99047. +++ linux-3.12.26/drivers/video/Makefile 2014-08-06 16:50:14.953965920 +0200
  99048. @@ -100,6 +100,7 @@
  99049. obj-$(CONFIG_FB_VOODOO1) += sstfb.o
  99050. obj-$(CONFIG_FB_ARMCLCD) += amba-clcd.o
  99051. obj-$(CONFIG_FB_GOLDFISH) += goldfishfb.o
  99052. +obj-$(CONFIG_FB_BCM2708) += bcm2708_fb.o
  99053. obj-$(CONFIG_FB_68328) += 68328fb.o
  99054. obj-$(CONFIG_FB_GBE) += gbefb.o
  99055. obj-$(CONFIG_FB_CIRRUS) += cirrusfb.o
  99056. diff -Nur linux-3.12.26.orig/drivers/video/sh_mobile_lcdcfb.c linux-3.12.26/drivers/video/sh_mobile_lcdcfb.c
  99057. --- linux-3.12.26.orig/drivers/video/sh_mobile_lcdcfb.c 2014-07-30 18:02:44.000000000 +0200
  99058. +++ linux-3.12.26/drivers/video/sh_mobile_lcdcfb.c 2014-08-06 16:50:14.953965920 +0200
  99059. @@ -574,9 +574,8 @@
  99060. switch (event) {
  99061. case SH_MOBILE_LCDC_EVENT_DISPLAY_CONNECT:
  99062. /* HDMI plug in */
  99063. - console_lock();
  99064. if (lock_fb_info(info)) {
  99065. -
  99066. + console_lock();
  99067. ch->display.width = monspec->max_x * 10;
  99068. ch->display.height = monspec->max_y * 10;
  99069. @@ -595,20 +594,19 @@
  99070. fb_set_suspend(info, 0);
  99071. }
  99072. -
  99073. + console_unlock();
  99074. unlock_fb_info(info);
  99075. }
  99076. - console_unlock();
  99077. break;
  99078. case SH_MOBILE_LCDC_EVENT_DISPLAY_DISCONNECT:
  99079. /* HDMI disconnect */
  99080. - console_lock();
  99081. if (lock_fb_info(info)) {
  99082. + console_lock();
  99083. fb_set_suspend(info, 1);
  99084. + console_unlock();
  99085. unlock_fb_info(info);
  99086. }
  99087. - console_unlock();
  99088. break;
  99089. case SH_MOBILE_LCDC_EVENT_DISPLAY_MODE:
  99090. diff -Nur linux-3.12.26.orig/drivers/w1/masters/w1-gpio.c linux-3.12.26/drivers/w1/masters/w1-gpio.c
  99091. --- linux-3.12.26.orig/drivers/w1/masters/w1-gpio.c 2014-07-30 18:02:44.000000000 +0200
  99092. +++ linux-3.12.26/drivers/w1/masters/w1-gpio.c 2014-08-06 16:50:14.961965982 +0200
  99093. @@ -22,6 +22,9 @@
  99094. #include "../w1.h"
  99095. #include "../w1_int.h"
  99096. +static int w1_gpio_pullup = 0;
  99097. +module_param_named(pullup, w1_gpio_pullup, int, 0);
  99098. +
  99099. static void w1_gpio_write_bit_dir(void *data, u8 bit)
  99100. {
  99101. struct w1_gpio_platform_data *pdata = data;
  99102. @@ -46,6 +49,16 @@
  99103. return gpio_get_value(pdata->pin) ? 1 : 0;
  99104. }
  99105. +static void w1_gpio_bitbang_pullup(void *data, u8 on)
  99106. +{
  99107. + struct w1_gpio_platform_data *pdata = data;
  99108. +
  99109. + if (on)
  99110. + gpio_direction_output(pdata->pin, 1);
  99111. + else
  99112. + gpio_direction_input(pdata->pin);
  99113. +}
  99114. +
  99115. #if defined(CONFIG_OF)
  99116. static struct of_device_id w1_gpio_dt_ids[] = {
  99117. { .compatible = "w1-gpio" },
  99118. @@ -127,6 +140,13 @@
  99119. master->write_bit = w1_gpio_write_bit_dir;
  99120. }
  99121. + if (w1_gpio_pullup)
  99122. + if (pdata->is_open_drain)
  99123. + printk(KERN_ERR "w1-gpio 'pullup' option "
  99124. + "doesn't work with open drain GPIO\n");
  99125. + else
  99126. + master->bitbang_pullup = w1_gpio_bitbang_pullup;
  99127. +
  99128. err = w1_add_master_device(master);
  99129. if (err) {
  99130. dev_err(&pdev->dev, "w1_add_master device failed\n");
  99131. diff -Nur linux-3.12.26.orig/drivers/w1/w1.h linux-3.12.26/drivers/w1/w1.h
  99132. --- linux-3.12.26.orig/drivers/w1/w1.h 2014-07-30 18:02:44.000000000 +0200
  99133. +++ linux-3.12.26/drivers/w1/w1.h 2014-08-06 16:50:14.973966077 +0200
  99134. @@ -148,6 +148,12 @@
  99135. */
  99136. u8 (*set_pullup)(void *, int);
  99137. + /**
  99138. + * Turns the pullup on/off in bitbanging mode, takes an on/off argument.
  99139. + * @return -1=Error, 0=completed
  99140. + */
  99141. + void (*bitbang_pullup) (void *, u8);
  99142. +
  99143. /** Really nice hardware can handles the different types of ROM search
  99144. * w1_master* is passed to the slave found callback.
  99145. */
  99146. diff -Nur linux-3.12.26.orig/drivers/w1/w1_int.c linux-3.12.26/drivers/w1/w1_int.c
  99147. --- linux-3.12.26.orig/drivers/w1/w1_int.c 2014-07-30 18:02:44.000000000 +0200
  99148. +++ linux-3.12.26/drivers/w1/w1_int.c 2014-08-06 16:50:14.973966077 +0200
  99149. @@ -130,6 +130,20 @@
  99150. master->set_pullup = NULL;
  99151. }
  99152. + /* bitbanging hardware uses bitbang_pullup, other hardware uses set_pullup
  99153. + * and takes care of timing itself */
  99154. + if (!master->write_byte && !master->touch_bit && master->set_pullup) {
  99155. + printk(KERN_ERR "w1_add_master_device: set_pullup requires "
  99156. + "write_byte or touch_bit, disabling\n");
  99157. + master->set_pullup = NULL;
  99158. + }
  99159. +
  99160. + if (master->set_pullup && master->bitbang_pullup) {
  99161. + printk(KERN_ERR "w1_add_master_device: set_pullup should not "
  99162. + "be set when bitbang_pullup is used, disabling\n");
  99163. + master->set_pullup = NULL;
  99164. + }
  99165. +
  99166. /* Lock until the device is added (or not) to w1_masters. */
  99167. mutex_lock(&w1_mlock);
  99168. /* Search for the first available id (starting at 1). */
  99169. diff -Nur linux-3.12.26.orig/drivers/w1/w1_io.c linux-3.12.26/drivers/w1/w1_io.c
  99170. --- linux-3.12.26.orig/drivers/w1/w1_io.c 2014-07-30 18:02:44.000000000 +0200
  99171. +++ linux-3.12.26/drivers/w1/w1_io.c 2014-08-06 16:50:14.973966077 +0200
  99172. @@ -127,10 +127,22 @@
  99173. static void w1_post_write(struct w1_master *dev)
  99174. {
  99175. if (dev->pullup_duration) {
  99176. - if (dev->enable_pullup && dev->bus_master->set_pullup)
  99177. - dev->bus_master->set_pullup(dev->bus_master->data, 0);
  99178. - else
  99179. + if (dev->enable_pullup) {
  99180. + if (dev->bus_master->set_pullup) {
  99181. + dev->bus_master->set_pullup(dev->
  99182. + bus_master->data,
  99183. + 0);
  99184. + } else if (dev->bus_master->bitbang_pullup) {
  99185. + dev->bus_master->
  99186. + bitbang_pullup(dev->bus_master->data, 1);
  99187. msleep(dev->pullup_duration);
  99188. + dev->bus_master->
  99189. + bitbang_pullup(dev->bus_master->data, 0);
  99190. + }
  99191. + } else {
  99192. + msleep(dev->pullup_duration);
  99193. + }
  99194. +
  99195. dev->pullup_duration = 0;
  99196. }
  99197. }
  99198. diff -Nur linux-3.12.26.orig/drivers/watchdog/bcm2708_wdog.c linux-3.12.26/drivers/watchdog/bcm2708_wdog.c
  99199. --- linux-3.12.26.orig/drivers/watchdog/bcm2708_wdog.c 1970-01-01 01:00:00.000000000 +0100
  99200. +++ linux-3.12.26/drivers/watchdog/bcm2708_wdog.c 2014-08-06 16:50:15.001966297 +0200
  99201. @@ -0,0 +1,384 @@
  99202. +/*
  99203. + * Broadcom BCM2708 watchdog driver.
  99204. + *
  99205. + * (c) Copyright 2010 Broadcom Europe Ltd
  99206. + *
  99207. + * This program is free software; you can redistribute it and/or
  99208. + * modify it under the terms of the GNU General Public License
  99209. + * as published by the Free Software Foundation; either version
  99210. + * 2 of the License, or (at your option) any later version.
  99211. + *
  99212. + * BCM2708 watchdog driver. Loosely based on wdt driver.
  99213. + */
  99214. +
  99215. +#include <linux/interrupt.h>
  99216. +#include <linux/module.h>
  99217. +#include <linux/moduleparam.h>
  99218. +#include <linux/types.h>
  99219. +#include <linux/miscdevice.h>
  99220. +#include <linux/watchdog.h>
  99221. +#include <linux/fs.h>
  99222. +#include <linux/ioport.h>
  99223. +#include <linux/notifier.h>
  99224. +#include <linux/reboot.h>
  99225. +#include <linux/init.h>
  99226. +#include <linux/io.h>
  99227. +#include <linux/uaccess.h>
  99228. +#include <mach/platform.h>
  99229. +
  99230. +#include <asm/system.h>
  99231. +
  99232. +#define SECS_TO_WDOG_TICKS(x) ((x) << 16)
  99233. +#define WDOG_TICKS_TO_SECS(x) ((x) >> 16)
  99234. +
  99235. +static unsigned long wdog_is_open;
  99236. +static uint32_t wdog_ticks; /* Ticks to load into wdog timer */
  99237. +static char expect_close;
  99238. +
  99239. +/*
  99240. + * Module parameters
  99241. + */
  99242. +
  99243. +#define WD_TIMO 10 /* Default heartbeat = 60 seconds */
  99244. +static int heartbeat = WD_TIMO; /* Heartbeat in seconds */
  99245. +
  99246. +module_param(heartbeat, int, 0);
  99247. +MODULE_PARM_DESC(heartbeat,
  99248. + "Watchdog heartbeat in seconds. (0 < heartbeat < 65536, default="
  99249. + __MODULE_STRING(WD_TIMO) ")");
  99250. +
  99251. +static int nowayout = WATCHDOG_NOWAYOUT;
  99252. +module_param(nowayout, int, 0);
  99253. +MODULE_PARM_DESC(nowayout,
  99254. + "Watchdog cannot be stopped once started (default="
  99255. + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
  99256. +
  99257. +static DEFINE_SPINLOCK(wdog_lock);
  99258. +
  99259. +/**
  99260. + * Start the watchdog driver.
  99261. + */
  99262. +
  99263. +static int wdog_start(unsigned long timeout)
  99264. +{
  99265. + uint32_t cur;
  99266. + unsigned long flags;
  99267. + spin_lock_irqsave(&wdog_lock, flags);
  99268. +
  99269. + /* enable the watchdog */
  99270. + iowrite32(PM_PASSWORD | (timeout & PM_WDOG_TIME_SET),
  99271. + __io_address(PM_WDOG));
  99272. + cur = ioread32(__io_address(PM_RSTC));
  99273. + iowrite32(PM_PASSWORD | (cur & PM_RSTC_WRCFG_CLR) |
  99274. + PM_RSTC_WRCFG_FULL_RESET, __io_address(PM_RSTC));
  99275. +
  99276. + spin_unlock_irqrestore(&wdog_lock, flags);
  99277. + return 0;
  99278. +}
  99279. +
  99280. +/**
  99281. + * Stop the watchdog driver.
  99282. + */
  99283. +
  99284. +static int wdog_stop(void)
  99285. +{
  99286. + iowrite32(PM_PASSWORD | PM_RSTC_RESET, __io_address(PM_RSTC));
  99287. + printk(KERN_INFO "watchdog stopped\n");
  99288. + return 0;
  99289. +}
  99290. +
  99291. +/**
  99292. + * Reload counter one with the watchdog heartbeat. We don't bother
  99293. + * reloading the cascade counter.
  99294. + */
  99295. +
  99296. +static void wdog_ping(void)
  99297. +{
  99298. + wdog_start(wdog_ticks);
  99299. +}
  99300. +
  99301. +/**
  99302. + * @t: the new heartbeat value that needs to be set.
  99303. + *
  99304. + * Set a new heartbeat value for the watchdog device. If the heartbeat
  99305. + * value is incorrect we keep the old value and return -EINVAL. If
  99306. + * successful we return 0.
  99307. + */
  99308. +
  99309. +static int wdog_set_heartbeat(int t)
  99310. +{
  99311. + if (t < 1 || t > WDOG_TICKS_TO_SECS(PM_WDOG_TIME_SET))
  99312. + return -EINVAL;
  99313. +
  99314. + heartbeat = t;
  99315. + wdog_ticks = SECS_TO_WDOG_TICKS(t);
  99316. + return 0;
  99317. +}
  99318. +
  99319. +/**
  99320. + * @file: file handle to the watchdog
  99321. + * @buf: buffer to write (unused as data does not matter here
  99322. + * @count: count of bytes
  99323. + * @ppos: pointer to the position to write. No seeks allowed
  99324. + *
  99325. + * A write to a watchdog device is defined as a keepalive signal.
  99326. + *
  99327. + * if 'nowayout' is set then normally a close() is ignored. But
  99328. + * if you write 'V' first then the close() will stop the timer.
  99329. + */
  99330. +
  99331. +static ssize_t wdog_write(struct file *file, const char __user *buf,
  99332. + size_t count, loff_t *ppos)
  99333. +{
  99334. + if (count) {
  99335. + if (!nowayout) {
  99336. + size_t i;
  99337. +
  99338. + /* In case it was set long ago */
  99339. + expect_close = 0;
  99340. +
  99341. + for (i = 0; i != count; i++) {
  99342. + char c;
  99343. + if (get_user(c, buf + i))
  99344. + return -EFAULT;
  99345. + if (c == 'V')
  99346. + expect_close = 42;
  99347. + }
  99348. + }
  99349. + wdog_ping();
  99350. + }
  99351. + return count;
  99352. +}
  99353. +
  99354. +static int wdog_get_status(void)
  99355. +{
  99356. + unsigned long flags;
  99357. + int status = 0;
  99358. + spin_lock_irqsave(&wdog_lock, flags);
  99359. + /* FIXME: readback reset reason */
  99360. + spin_unlock_irqrestore(&wdog_lock, flags);
  99361. + return status;
  99362. +}
  99363. +
  99364. +static uint32_t wdog_get_remaining(void)
  99365. +{
  99366. + uint32_t ret = ioread32(__io_address(PM_WDOG));
  99367. + return ret & PM_WDOG_TIME_SET;
  99368. +}
  99369. +
  99370. +/**
  99371. + * @file: file handle to the device
  99372. + * @cmd: watchdog command
  99373. + * @arg: argument pointer
  99374. + *
  99375. + * The watchdog API defines a common set of functions for all watchdogs
  99376. + * according to their available features. We only actually usefully support
  99377. + * querying capabilities and current status.
  99378. + */
  99379. +
  99380. +static long wdog_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  99381. +{
  99382. + void __user *argp = (void __user *)arg;
  99383. + int __user *p = argp;
  99384. + int new_heartbeat;
  99385. + int status;
  99386. + int options;
  99387. + uint32_t remaining;
  99388. +
  99389. + struct watchdog_info ident = {
  99390. + .options = WDIOF_SETTIMEOUT|
  99391. + WDIOF_MAGICCLOSE|
  99392. + WDIOF_KEEPALIVEPING,
  99393. + .firmware_version = 1,
  99394. + .identity = "BCM2708",
  99395. + };
  99396. +
  99397. + switch (cmd) {
  99398. + case WDIOC_GETSUPPORT:
  99399. + return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0;
  99400. + case WDIOC_GETSTATUS:
  99401. + status = wdog_get_status();
  99402. + return put_user(status, p);
  99403. + case WDIOC_GETBOOTSTATUS:
  99404. + return put_user(0, p);
  99405. + case WDIOC_KEEPALIVE:
  99406. + wdog_ping();
  99407. + return 0;
  99408. + case WDIOC_SETTIMEOUT:
  99409. + if (get_user(new_heartbeat, p))
  99410. + return -EFAULT;
  99411. + if (wdog_set_heartbeat(new_heartbeat))
  99412. + return -EINVAL;
  99413. + wdog_ping();
  99414. + /* Fall */
  99415. + case WDIOC_GETTIMEOUT:
  99416. + return put_user(heartbeat, p);
  99417. + case WDIOC_GETTIMELEFT:
  99418. + remaining = WDOG_TICKS_TO_SECS(wdog_get_remaining());
  99419. + return put_user(remaining, p);
  99420. + case WDIOC_SETOPTIONS:
  99421. + if (get_user(options, p))
  99422. + return -EFAULT;
  99423. + if (options & WDIOS_DISABLECARD)
  99424. + wdog_stop();
  99425. + if (options & WDIOS_ENABLECARD)
  99426. + wdog_start(wdog_ticks);
  99427. + return 0;
  99428. + default:
  99429. + return -ENOTTY;
  99430. + }
  99431. +}
  99432. +
  99433. +/**
  99434. + * @inode: inode of device
  99435. + * @file: file handle to device
  99436. + *
  99437. + * The watchdog device has been opened. The watchdog device is single
  99438. + * open and on opening we load the counters.
  99439. + */
  99440. +
  99441. +static int wdog_open(struct inode *inode, struct file *file)
  99442. +{
  99443. + if (test_and_set_bit(0, &wdog_is_open))
  99444. + return -EBUSY;
  99445. + /*
  99446. + * Activate
  99447. + */
  99448. + wdog_start(wdog_ticks);
  99449. + return nonseekable_open(inode, file);
  99450. +}
  99451. +
  99452. +/**
  99453. + * @inode: inode to board
  99454. + * @file: file handle to board
  99455. + *
  99456. + * The watchdog has a configurable API. There is a religious dispute
  99457. + * between people who want their watchdog to be able to shut down and
  99458. + * those who want to be sure if the watchdog manager dies the machine
  99459. + * reboots. In the former case we disable the counters, in the latter
  99460. + * case you have to open it again very soon.
  99461. + */
  99462. +
  99463. +static int wdog_release(struct inode *inode, struct file *file)
  99464. +{
  99465. + if (expect_close == 42) {
  99466. + wdog_stop();
  99467. + } else {
  99468. + printk(KERN_CRIT
  99469. + "wdt: WDT device closed unexpectedly. WDT will not stop!\n");
  99470. + wdog_ping();
  99471. + }
  99472. + clear_bit(0, &wdog_is_open);
  99473. + expect_close = 0;
  99474. + return 0;
  99475. +}
  99476. +
  99477. +/**
  99478. + * @this: our notifier block
  99479. + * @code: the event being reported
  99480. + * @unused: unused
  99481. + *
  99482. + * Our notifier is called on system shutdowns. Turn the watchdog
  99483. + * off so that it does not fire during the next reboot.
  99484. + */
  99485. +
  99486. +static int wdog_notify_sys(struct notifier_block *this, unsigned long code,
  99487. + void *unused)
  99488. +{
  99489. + if (code == SYS_DOWN || code == SYS_HALT)
  99490. + wdog_stop();
  99491. + return NOTIFY_DONE;
  99492. +}
  99493. +
  99494. +/*
  99495. + * Kernel Interfaces
  99496. + */
  99497. +
  99498. +
  99499. +static const struct file_operations wdog_fops = {
  99500. + .owner = THIS_MODULE,
  99501. + .llseek = no_llseek,
  99502. + .write = wdog_write,
  99503. + .unlocked_ioctl = wdog_ioctl,
  99504. + .open = wdog_open,
  99505. + .release = wdog_release,
  99506. +};
  99507. +
  99508. +static struct miscdevice wdog_miscdev = {
  99509. + .minor = WATCHDOG_MINOR,
  99510. + .name = "watchdog",
  99511. + .fops = &wdog_fops,
  99512. +};
  99513. +
  99514. +/*
  99515. + * The WDT card needs to learn about soft shutdowns in order to
  99516. + * turn the timebomb registers off.
  99517. + */
  99518. +
  99519. +static struct notifier_block wdog_notifier = {
  99520. + .notifier_call = wdog_notify_sys,
  99521. +};
  99522. +
  99523. +/**
  99524. + * cleanup_module:
  99525. + *
  99526. + * Unload the watchdog. You cannot do this with any file handles open.
  99527. + * If your watchdog is set to continue ticking on close and you unload
  99528. + * it, well it keeps ticking. We won't get the interrupt but the board
  99529. + * will not touch PC memory so all is fine. You just have to load a new
  99530. + * module in 60 seconds or reboot.
  99531. + */
  99532. +
  99533. +static void __exit wdog_exit(void)
  99534. +{
  99535. + misc_deregister(&wdog_miscdev);
  99536. + unregister_reboot_notifier(&wdog_notifier);
  99537. +}
  99538. +
  99539. +static int __init wdog_init(void)
  99540. +{
  99541. + int ret;
  99542. +
  99543. + /* Check that the heartbeat value is within it's range;
  99544. + if not reset to the default */
  99545. + if (wdog_set_heartbeat(heartbeat)) {
  99546. + wdog_set_heartbeat(WD_TIMO);
  99547. + printk(KERN_INFO "bcm2708_wdog: heartbeat value must be "
  99548. + "0 < heartbeat < %d, using %d\n",
  99549. + WDOG_TICKS_TO_SECS(PM_WDOG_TIME_SET),
  99550. + WD_TIMO);
  99551. + }
  99552. +
  99553. + ret = register_reboot_notifier(&wdog_notifier);
  99554. + if (ret) {
  99555. + printk(KERN_ERR
  99556. + "wdt: cannot register reboot notifier (err=%d)\n", ret);
  99557. + goto out_reboot;
  99558. + }
  99559. +
  99560. + ret = misc_register(&wdog_miscdev);
  99561. + if (ret) {
  99562. + printk(KERN_ERR
  99563. + "wdt: cannot register miscdev on minor=%d (err=%d)\n",
  99564. + WATCHDOG_MINOR, ret);
  99565. + goto out_misc;
  99566. + }
  99567. +
  99568. + printk(KERN_INFO "bcm2708 watchdog, heartbeat=%d sec (nowayout=%d)\n",
  99569. + heartbeat, nowayout);
  99570. + return 0;
  99571. +
  99572. +out_misc:
  99573. + unregister_reboot_notifier(&wdog_notifier);
  99574. +out_reboot:
  99575. + return ret;
  99576. +}
  99577. +
  99578. +module_init(wdog_init);
  99579. +module_exit(wdog_exit);
  99580. +
  99581. +MODULE_AUTHOR("Luke Diamand");
  99582. +MODULE_DESCRIPTION("Driver for BCM2708 watchdog");
  99583. +MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
  99584. +MODULE_ALIAS_MISCDEV(TEMP_MINOR);
  99585. +MODULE_LICENSE("GPL");
  99586. diff -Nur linux-3.12.26.orig/drivers/watchdog/Kconfig linux-3.12.26/drivers/watchdog/Kconfig
  99587. --- linux-3.12.26.orig/drivers/watchdog/Kconfig 2014-07-30 18:02:44.000000000 +0200
  99588. +++ linux-3.12.26/drivers/watchdog/Kconfig 2014-08-06 16:50:15.017966422 +0200
  99589. @@ -392,6 +392,12 @@
  99590. To compile this driver as a module, choose M here: the
  99591. module will be called retu_wdt.
  99592. +config BCM2708_WDT
  99593. + tristate "BCM2708 Watchdog"
  99594. + depends on ARCH_BCM2708
  99595. + help
  99596. + Enables BCM2708 watchdog support.
  99597. +
  99598. # AVR32 Architecture
  99599. config AT32AP700X_WDT
  99600. diff -Nur linux-3.12.26.orig/drivers/watchdog/Makefile linux-3.12.26/drivers/watchdog/Makefile
  99601. --- linux-3.12.26.orig/drivers/watchdog/Makefile 2014-07-30 18:02:44.000000000 +0200
  99602. +++ linux-3.12.26/drivers/watchdog/Makefile 2014-08-06 16:50:15.017966422 +0200
  99603. @@ -54,6 +54,7 @@
  99604. obj-$(CONFIG_IMX2_WDT) += imx2_wdt.o
  99605. obj-$(CONFIG_UX500_WATCHDOG) += ux500_wdt.o
  99606. obj-$(CONFIG_RETU_WATCHDOG) += retu_wdt.o
  99607. +obj-$(CONFIG_BCM2708_WDT) += bcm2708_wdog.o
  99608. obj-$(CONFIG_BCM2835_WDT) += bcm2835_wdt.o
  99609. # AVR32 Architecture
  99610. diff -Nur linux-3.12.26.orig/fs/ext4/inode.c linux-3.12.26/fs/ext4/inode.c
  99611. --- linux-3.12.26.orig/fs/ext4/inode.c 2014-07-30 18:02:44.000000000 +0200
  99612. +++ linux-3.12.26/fs/ext4/inode.c 2014-08-06 16:50:15.017966422 +0200
  99613. @@ -4463,12 +4463,7 @@
  99614. return -EIO;
  99615. }
  99616. - /*
  99617. - * No need to force transaction in WB_SYNC_NONE mode. Also
  99618. - * ext4_sync_fs() will force the commit after everything is
  99619. - * written.
  99620. - */
  99621. - if (wbc->sync_mode != WB_SYNC_ALL || wbc->for_sync)
  99622. + if (wbc->sync_mode != WB_SYNC_ALL)
  99623. return 0;
  99624. err = ext4_force_commit(inode->i_sb);
  99625. @@ -4478,11 +4473,7 @@
  99626. err = __ext4_get_inode_loc(inode, &iloc, 0);
  99627. if (err)
  99628. return err;
  99629. - /*
  99630. - * sync(2) will flush the whole buffer cache. No need to do
  99631. - * it here separately for each inode.
  99632. - */
  99633. - if (wbc->sync_mode == WB_SYNC_ALL && !wbc->for_sync)
  99634. + if (wbc->sync_mode == WB_SYNC_ALL)
  99635. sync_dirty_buffer(iloc.bh);
  99636. if (buffer_req(iloc.bh) && !buffer_uptodate(iloc.bh)) {
  99637. EXT4_ERROR_INODE_BLOCK(inode, iloc.bh->b_blocknr,
  99638. diff -Nur linux-3.12.26.orig/fs/nfs/nfs3acl.c linux-3.12.26/fs/nfs/nfs3acl.c
  99639. --- linux-3.12.26.orig/fs/nfs/nfs3acl.c 2014-07-30 18:02:44.000000000 +0200
  99640. +++ linux-3.12.26/fs/nfs/nfs3acl.c 2014-08-06 16:50:15.017966422 +0200
  99641. @@ -289,8 +289,8 @@
  99642. return acl;
  99643. }
  99644. -static int __nfs3_proc_setacls(struct inode *inode, struct posix_acl *acl,
  99645. - struct posix_acl *dfacl)
  99646. +static int nfs3_proc_setacls(struct inode *inode, struct posix_acl *acl,
  99647. + struct posix_acl *dfacl)
  99648. {
  99649. struct nfs_server *server = NFS_SERVER(inode);
  99650. struct nfs_fattr *fattr;
  99651. @@ -373,15 +373,6 @@
  99652. return status;
  99653. }
  99654. -int nfs3_proc_setacls(struct inode *inode, struct posix_acl *acl,
  99655. - struct posix_acl *dfacl)
  99656. -{
  99657. - int ret;
  99658. - ret = __nfs3_proc_setacls(inode, acl, dfacl);
  99659. - return (ret == -EOPNOTSUPP) ? 0 : ret;
  99660. -
  99661. -}
  99662. -
  99663. int nfs3_proc_setacl(struct inode *inode, int type, struct posix_acl *acl)
  99664. {
  99665. struct posix_acl *alloc = NULL, *dfacl = NULL;
  99666. @@ -415,7 +406,7 @@
  99667. if (IS_ERR(alloc))
  99668. goto fail;
  99669. }
  99670. - status = __nfs3_proc_setacls(inode, acl, dfacl);
  99671. + status = nfs3_proc_setacls(inode, acl, dfacl);
  99672. posix_acl_release(alloc);
  99673. return status;
  99674. diff -Nur linux-3.12.26.orig/fs/nfs/nfs4xdr.c linux-3.12.26/fs/nfs/nfs4xdr.c
  99675. --- linux-3.12.26.orig/fs/nfs/nfs4xdr.c 2014-07-30 18:02:44.000000000 +0200
  99676. +++ linux-3.12.26/fs/nfs/nfs4xdr.c 2014-08-06 16:50:15.021966454 +0200
  99677. @@ -3405,7 +3405,7 @@
  99678. {
  99679. __be32 *p;
  99680. - *res = 0;
  99681. + *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
  99682. if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
  99683. return -EIO;
  99684. if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
  99685. diff -Nur linux-3.12.26.orig/include/drm/drm_crtc.h linux-3.12.26/include/drm/drm_crtc.h
  99686. --- linux-3.12.26.orig/include/drm/drm_crtc.h 2014-07-30 18:02:44.000000000 +0200
  99687. +++ linux-3.12.26/include/drm/drm_crtc.h 2014-08-06 16:50:15.021966454 +0200
  99688. @@ -1108,8 +1108,6 @@
  99689. int GTF_2C, int GTF_K, int GTF_2J);
  99690. extern int drm_add_modes_noedid(struct drm_connector *connector,
  99691. int hdisplay, int vdisplay);
  99692. -extern void drm_set_preferred_mode(struct drm_connector *connector,
  99693. - int hpref, int vpref);
  99694. extern int drm_edid_header_is_valid(const u8 *raw_edid);
  99695. extern bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid);
  99696. diff -Nur linux-3.12.26.orig/include/linux/broadcom/vc_cma.h linux-3.12.26/include/linux/broadcom/vc_cma.h
  99697. --- linux-3.12.26.orig/include/linux/broadcom/vc_cma.h 1970-01-01 01:00:00.000000000 +0100
  99698. +++ linux-3.12.26/include/linux/broadcom/vc_cma.h 2014-08-06 16:50:15.041966611 +0200
  99699. @@ -0,0 +1,29 @@
  99700. +/*****************************************************************************
  99701. +* Copyright 2012 Broadcom Corporation. All rights reserved.
  99702. +*
  99703. +* Unless you and Broadcom execute a separate written software license
  99704. +* agreement governing use of this software, this software is licensed to you
  99705. +* under the terms of the GNU General Public License version 2, available at
  99706. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  99707. +*
  99708. +* Notwithstanding the above, under no circumstances may you combine this
  99709. +* software in any way with any other Broadcom software provided under a
  99710. +* license other than the GPL, without Broadcom's express prior written
  99711. +* consent.
  99712. +*****************************************************************************/
  99713. +
  99714. +#if !defined( VC_CMA_H )
  99715. +#define VC_CMA_H
  99716. +
  99717. +#include <linux/ioctl.h>
  99718. +
  99719. +#define VC_CMA_IOC_MAGIC 0xc5
  99720. +
  99721. +#define VC_CMA_IOC_RESERVE _IO(VC_CMA_IOC_MAGIC, 0)
  99722. +
  99723. +#ifdef __KERNEL__
  99724. +extern void __init vc_cma_early_init(void);
  99725. +extern void __init vc_cma_reserve(void);
  99726. +#endif
  99727. +
  99728. +#endif /* VC_CMA_H */
  99729. diff -Nur linux-3.12.26.orig/include/linux/fb.h linux-3.12.26/include/linux/fb.h
  99730. --- linux-3.12.26.orig/include/linux/fb.h 2014-07-30 18:02:44.000000000 +0200
  99731. +++ linux-3.12.26/include/linux/fb.h 2014-08-06 16:50:15.041966611 +0200
  99732. @@ -613,8 +613,8 @@
  99733. extern int register_framebuffer(struct fb_info *fb_info);
  99734. extern int unregister_framebuffer(struct fb_info *fb_info);
  99735. extern int unlink_framebuffer(struct fb_info *fb_info);
  99736. -extern int remove_conflicting_framebuffers(struct apertures_struct *a,
  99737. - const char *name, bool primary);
  99738. +extern void remove_conflicting_framebuffers(struct apertures_struct *a,
  99739. + const char *name, bool primary);
  99740. extern int fb_prepare_logo(struct fb_info *fb_info, int rotate);
  99741. extern int fb_show_logo(struct fb_info *fb_info, int rotate);
  99742. extern char* fb_get_buffer_offset(struct fb_info *info, struct fb_pixmap *buf, u32 size);
  99743. diff -Nur linux-3.12.26.orig/include/linux/futex.h linux-3.12.26/include/linux/futex.h
  99744. --- linux-3.12.26.orig/include/linux/futex.h 2014-07-30 18:02:44.000000000 +0200
  99745. +++ linux-3.12.26/include/linux/futex.h 2014-08-06 16:50:15.061966768 +0200
  99746. @@ -55,11 +55,7 @@
  99747. #ifdef CONFIG_FUTEX
  99748. extern void exit_robust_list(struct task_struct *curr);
  99749. extern void exit_pi_state_list(struct task_struct *curr);
  99750. -#ifdef CONFIG_HAVE_FUTEX_CMPXCHG
  99751. -#define futex_cmpxchg_enabled 1
  99752. -#else
  99753. extern int futex_cmpxchg_enabled;
  99754. -#endif
  99755. #else
  99756. static inline void exit_robust_list(struct task_struct *curr)
  99757. {
  99758. diff -Nur linux-3.12.26.orig/include/linux/mmc/host.h linux-3.12.26/include/linux/mmc/host.h
  99759. --- linux-3.12.26.orig/include/linux/mmc/host.h 2014-07-30 18:02:44.000000000 +0200
  99760. +++ linux-3.12.26/include/linux/mmc/host.h 2014-08-06 16:50:15.069966830 +0200
  99761. @@ -281,6 +281,7 @@
  99762. MMC_CAP2_PACKED_WR)
  99763. #define MMC_CAP2_NO_PRESCAN_POWERUP (1 << 14) /* Don't power up before scan */
  99764. #define MMC_CAP2_SANITIZE (1 << 15) /* Support Sanitize */
  99765. +#define MMC_CAP2_FORCE_MULTIBLOCK (1 << 31) /* Always use multiblock transfers */
  99766. mmc_pm_flag_t pm_caps; /* supported pm features */
  99767. diff -Nur linux-3.12.26.orig/include/linux/mmc/sdhci.h linux-3.12.26/include/linux/mmc/sdhci.h
  99768. --- linux-3.12.26.orig/include/linux/mmc/sdhci.h 2014-07-30 18:02:44.000000000 +0200
  99769. +++ linux-3.12.26/include/linux/mmc/sdhci.h 2014-08-06 16:50:15.069966830 +0200
  99770. @@ -100,6 +100,7 @@
  99771. #define SDHCI_QUIRK2_BROKEN_HOST_CONTROL (1<<5)
  99772. int irq; /* Device IRQ */
  99773. + int second_irq; /* Additional IRQ to disable/enable in low-latency mode */
  99774. void __iomem *ioaddr; /* Mapped address */
  99775. const struct sdhci_ops *ops; /* Low level hw interface */
  99776. @@ -131,6 +132,7 @@
  99777. #define SDHCI_SDIO_IRQ_ENABLED (1<<9) /* SDIO irq enabled */
  99778. #define SDHCI_SDR104_NEEDS_TUNING (1<<10) /* SDR104/HS200 needs tuning */
  99779. #define SDHCI_USING_RETUNING_TIMER (1<<11) /* Host is using a retuning timer for the card */
  99780. +#define SDHCI_USE_PLATDMA (1<<12) /* Host uses 3rd party DMA */
  99781. unsigned int version; /* SDHCI spec. version */
  99782. @@ -146,6 +148,7 @@
  99783. struct mmc_request *mrq; /* Current request */
  99784. struct mmc_command *cmd; /* Current command */
  99785. + int last_cmdop; /* Opcode of last cmd sent */
  99786. struct mmc_data *data; /* Current data request */
  99787. unsigned int data_early:1; /* Data finished before cmd */
  99788. diff -Nur linux-3.12.26.orig/include/linux/usb/usbnet.h linux-3.12.26/include/linux/usb/usbnet.h
  99789. --- linux-3.12.26.orig/include/linux/usb/usbnet.h 2014-07-30 18:02:44.000000000 +0200
  99790. +++ linux-3.12.26/include/linux/usb/usbnet.h 2014-08-06 16:50:15.069966830 +0200
  99791. @@ -30,7 +30,7 @@
  99792. struct driver_info *driver_info;
  99793. const char *driver_name;
  99794. void *driver_priv;
  99795. - wait_queue_head_t wait;
  99796. + wait_queue_head_t *wait;
  99797. struct mutex phy_mutex;
  99798. unsigned char suspend_count;
  99799. unsigned char pkt_cnt, pkt_err;
  99800. diff -Nur linux-3.12.26.orig/include/net/sock.h linux-3.12.26/include/net/sock.h
  99801. --- linux-3.12.26.orig/include/net/sock.h 2014-07-30 18:02:44.000000000 +0200
  99802. +++ linux-3.12.26/include/net/sock.h 2014-08-06 16:50:15.069966830 +0200
  99803. @@ -1459,11 +1459,6 @@
  99804. */
  99805. #define sock_owned_by_user(sk) ((sk)->sk_lock.owned)
  99806. -static inline void sock_release_ownership(struct sock *sk)
  99807. -{
  99808. - sk->sk_lock.owned = 0;
  99809. -}
  99810. -
  99811. /*
  99812. * Macro so as to not evaluate some arguments when
  99813. * lockdep is not enabled.
  99814. diff -Nur linux-3.12.26.orig/include/net/tcp.h linux-3.12.26/include/net/tcp.h
  99815. --- linux-3.12.26.orig/include/net/tcp.h 2014-07-30 18:02:44.000000000 +0200
  99816. +++ linux-3.12.26/include/net/tcp.h 2014-08-06 16:50:15.069966830 +0200
  99817. @@ -484,21 +484,20 @@
  99818. #ifdef CONFIG_SYN_COOKIES
  99819. #include <linux/ktime.h>
  99820. -/* Syncookies use a monotonic timer which increments every 60 seconds.
  99821. +/* Syncookies use a monotonic timer which increments every 64 seconds.
  99822. * This counter is used both as a hash input and partially encoded into
  99823. * the cookie value. A cookie is only validated further if the delta
  99824. * between the current counter value and the encoded one is less than this,
  99825. - * i.e. a sent cookie is valid only at most for 2*60 seconds (or less if
  99826. + * i.e. a sent cookie is valid only at most for 128 seconds (or less if
  99827. * the counter advances immediately after a cookie is generated).
  99828. */
  99829. #define MAX_SYNCOOKIE_AGE 2
  99830. static inline u32 tcp_cookie_time(void)
  99831. {
  99832. - u64 val = get_jiffies_64();
  99833. -
  99834. - do_div(val, 60 * HZ);
  99835. - return val;
  99836. + struct timespec now;
  99837. + getnstimeofday(&now);
  99838. + return now.tv_sec >> 6; /* 64 seconds granularity */
  99839. }
  99840. extern u32 __cookie_v4_init_sequence(const struct iphdr *iph,
  99841. diff -Nur linux-3.12.26.orig/include/sound/soc-dai.h linux-3.12.26/include/sound/soc-dai.h
  99842. --- linux-3.12.26.orig/include/sound/soc-dai.h 2014-07-30 18:02:44.000000000 +0200
  99843. +++ linux-3.12.26/include/sound/soc-dai.h 2014-08-06 16:50:15.069966830 +0200
  99844. @@ -105,6 +105,8 @@
  99845. int snd_soc_dai_set_pll(struct snd_soc_dai *dai,
  99846. int pll_id, int source, unsigned int freq_in, unsigned int freq_out);
  99847. +int snd_soc_dai_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio);
  99848. +
  99849. /* Digital Audio interface formatting */
  99850. int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt);
  99851. @@ -131,6 +133,7 @@
  99852. int (*set_pll)(struct snd_soc_dai *dai, int pll_id, int source,
  99853. unsigned int freq_in, unsigned int freq_out);
  99854. int (*set_clkdiv)(struct snd_soc_dai *dai, int div_id, int div);
  99855. + int (*set_bclk_ratio)(struct snd_soc_dai *dai, unsigned int ratio);
  99856. /*
  99857. * DAI format configuration
  99858. diff -Nur linux-3.12.26.orig/include/uapi/linux/fb.h linux-3.12.26/include/uapi/linux/fb.h
  99859. --- linux-3.12.26.orig/include/uapi/linux/fb.h 2014-07-30 18:02:44.000000000 +0200
  99860. +++ linux-3.12.26/include/uapi/linux/fb.h 2014-08-06 16:50:15.069966830 +0200
  99861. @@ -34,6 +34,11 @@
  99862. #define FBIOPUT_MODEINFO 0x4617
  99863. #define FBIOGET_DISPINFO 0x4618
  99864. #define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32)
  99865. +/*
  99866. + * HACK: use 'z' in order not to clash with any other ioctl numbers which might
  99867. + * be concurrently added to the mainline kernel
  99868. + */
  99869. +#define FBIOCOPYAREA _IOW('z', 0x21, struct fb_copyarea)
  99870. #define FB_TYPE_PACKED_PIXELS 0 /* Packed Pixels */
  99871. #define FB_TYPE_PLANES 1 /* Non interleaved planes */
  99872. diff -Nur linux-3.12.26.orig/include/uapi/linux/fd.h linux-3.12.26/include/uapi/linux/fd.h
  99873. --- linux-3.12.26.orig/include/uapi/linux/fd.h 2014-07-30 18:02:44.000000000 +0200
  99874. +++ linux-3.12.26/include/uapi/linux/fd.h 2014-08-06 16:50:15.069966830 +0200
  99875. @@ -185,8 +185,7 @@
  99876. * to clear media change status */
  99877. FD_UNUSED_BIT,
  99878. FD_DISK_CHANGED_BIT, /* disk has been changed since last i/o */
  99879. - FD_DISK_WRITABLE_BIT, /* disk is writable */
  99880. - FD_OPEN_SHOULD_FAIL_BIT
  99881. + FD_DISK_WRITABLE_BIT /* disk is writable */
  99882. };
  99883. #define FDSETDRVPRM _IOW(2, 0x90, struct floppy_drive_params)
  99884. diff -Nur linux-3.12.26.orig/init/Kconfig linux-3.12.26/init/Kconfig
  99885. --- linux-3.12.26.orig/init/Kconfig 2014-07-30 18:02:44.000000000 +0200
  99886. +++ linux-3.12.26/init/Kconfig 2014-08-06 16:50:15.073966862 +0200
  99887. @@ -1406,13 +1406,6 @@
  99888. support for "fast userspace mutexes". The resulting kernel may not
  99889. run glibc-based applications correctly.
  99890. -config HAVE_FUTEX_CMPXCHG
  99891. - bool
  99892. - help
  99893. - Architectures should select this if futex_atomic_cmpxchg_inatomic()
  99894. - is implemented and always working. This removes a couple of runtime
  99895. - checks.
  99896. -
  99897. config EPOLL
  99898. bool "Enable eventpoll support" if EXPERT
  99899. default y
  99900. diff -Nur linux-3.12.26.orig/kernel/cgroup.c linux-3.12.26/kernel/cgroup.c
  99901. --- linux-3.12.26.orig/kernel/cgroup.c 2014-07-30 18:02:44.000000000 +0200
  99902. +++ linux-3.12.26/kernel/cgroup.c 2014-08-06 16:50:15.073966862 +0200
  99903. @@ -5558,6 +5558,33 @@
  99904. }
  99905. __setup("cgroup_disable=", cgroup_disable);
  99906. +static int __init cgroup_enable(char *str)
  99907. +{
  99908. + struct cgroup_subsys *ss;
  99909. + char *token;
  99910. + int i;
  99911. +
  99912. + while ((token = strsep(&str, ",")) != NULL) {
  99913. + if (!*token)
  99914. + continue;
  99915. +
  99916. + /*
  99917. + * cgroup_disable, being at boot time, can't know about
  99918. + * module subsystems, so we don't worry about them.
  99919. + */
  99920. + for_each_builtin_subsys(ss, i) {
  99921. + if (!strcmp(token, ss->name)) {
  99922. + ss->disabled = 0;
  99923. + printk(KERN_INFO "Disabling %s control group"
  99924. + " subsystem\n", ss->name);
  99925. + break;
  99926. + }
  99927. + }
  99928. + }
  99929. + return 1;
  99930. +}
  99931. +__setup("cgroup_enable=", cgroup_enable);
  99932. +
  99933. /*
  99934. * Functons for CSS ID.
  99935. */
  99936. diff -Nur linux-3.12.26.orig/kernel/futex.c linux-3.12.26/kernel/futex.c
  99937. --- linux-3.12.26.orig/kernel/futex.c 2014-07-30 18:02:44.000000000 +0200
  99938. +++ linux-3.12.26/kernel/futex.c 2014-08-06 16:50:15.089966988 +0200
  99939. @@ -68,9 +68,7 @@
  99940. #include "rtmutex_common.h"
  99941. -#ifndef CONFIG_HAVE_FUTEX_CMPXCHG
  99942. int __read_mostly futex_cmpxchg_enabled;
  99943. -#endif
  99944. #define FUTEX_HASHBITS (CONFIG_BASE_SMALL ? 4 : 8)
  99945. @@ -2866,10 +2864,10 @@
  99946. return do_futex(uaddr, op, val, tp, uaddr2, val2, val3);
  99947. }
  99948. -static void __init futex_detect_cmpxchg(void)
  99949. +static int __init futex_init(void)
  99950. {
  99951. -#ifndef CONFIG_HAVE_FUTEX_CMPXCHG
  99952. u32 curval;
  99953. + int i;
  99954. /*
  99955. * This will fail and we want it. Some arch implementations do
  99956. @@ -2883,14 +2881,6 @@
  99957. */
  99958. if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
  99959. futex_cmpxchg_enabled = 1;
  99960. -#endif
  99961. -}
  99962. -
  99963. -static int __init futex_init(void)
  99964. -{
  99965. - int i;
  99966. -
  99967. - futex_detect_cmpxchg();
  99968. for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
  99969. plist_head_init(&futex_queues[i].chain);
  99970. diff -Nur linux-3.12.26.orig/lib/nlattr.c linux-3.12.26/lib/nlattr.c
  99971. --- linux-3.12.26.orig/lib/nlattr.c 2014-07-30 18:02:44.000000000 +0200
  99972. +++ linux-3.12.26/lib/nlattr.c 2014-08-06 16:50:15.089966988 +0200
  99973. @@ -303,15 +303,9 @@
  99974. */
  99975. int nla_strcmp(const struct nlattr *nla, const char *str)
  99976. {
  99977. - int len = strlen(str);
  99978. - char *buf = nla_data(nla);
  99979. - int attrlen = nla_len(nla);
  99980. - int d;
  99981. + int len = strlen(str) + 1;
  99982. + int d = nla_len(nla) - len;
  99983. - if (attrlen > 0 && buf[attrlen - 1] == '\0')
  99984. - attrlen--;
  99985. -
  99986. - d = attrlen - len;
  99987. if (d == 0)
  99988. d = memcmp(nla_data(nla), str, len);
  99989. diff -Nur linux-3.12.26.orig/mm/memcontrol.c linux-3.12.26/mm/memcontrol.c
  99990. --- linux-3.12.26.orig/mm/memcontrol.c 2014-07-30 18:02:44.000000000 +0200
  99991. +++ linux-3.12.26/mm/memcontrol.c 2014-08-06 16:50:15.101967082 +0200
  99992. @@ -7035,6 +7035,7 @@
  99993. .base_cftypes = mem_cgroup_files,
  99994. .early_init = 0,
  99995. .use_id = 1,
  99996. + .disabled = 1,
  99997. };
  99998. #ifdef CONFIG_MEMCG_SWAP
  99999. diff -Nur linux-3.12.26.orig/net/8021q/vlan.c linux-3.12.26/net/8021q/vlan.c
  100000. --- linux-3.12.26.orig/net/8021q/vlan.c 2014-07-30 18:02:44.000000000 +0200
  100001. +++ linux-3.12.26/net/8021q/vlan.c 2014-08-06 16:50:15.101967082 +0200
  100002. @@ -307,11 +307,9 @@
  100003. static void vlan_transfer_features(struct net_device *dev,
  100004. struct net_device *vlandev)
  100005. {
  100006. - struct vlan_dev_priv *vlan = vlan_dev_priv(vlandev);
  100007. -
  100008. vlandev->gso_max_size = dev->gso_max_size;
  100009. - if (vlan_hw_offload_capable(dev->features, vlan->vlan_proto))
  100010. + if (dev->features & NETIF_F_HW_VLAN_CTAG_TX)
  100011. vlandev->hard_header_len = dev->hard_header_len;
  100012. else
  100013. vlandev->hard_header_len = dev->hard_header_len + VLAN_HLEN;
  100014. diff -Nur linux-3.12.26.orig/net/8021q/vlan_dev.c linux-3.12.26/net/8021q/vlan_dev.c
  100015. --- linux-3.12.26.orig/net/8021q/vlan_dev.c 2014-07-30 18:02:44.000000000 +0200
  100016. +++ linux-3.12.26/net/8021q/vlan_dev.c 2014-08-06 16:50:15.101967082 +0200
  100017. @@ -595,9 +595,6 @@
  100018. struct vlan_dev_priv *vlan = vlan_dev_priv(dev);
  100019. struct net_device *real_dev = vlan->real_dev;
  100020. - if (saddr == NULL)
  100021. - saddr = dev->dev_addr;
  100022. -
  100023. return dev_hard_header(skb, real_dev, type, daddr, saddr, len);
  100024. }
  100025. @@ -649,8 +646,7 @@
  100026. #endif
  100027. dev->needed_headroom = real_dev->needed_headroom;
  100028. - if (vlan_hw_offload_capable(real_dev->features,
  100029. - vlan_dev_priv(dev)->vlan_proto)) {
  100030. + if (real_dev->features & NETIF_F_HW_VLAN_CTAG_TX) {
  100031. dev->header_ops = &vlan_passthru_header_ops;
  100032. dev->hard_header_len = real_dev->hard_header_len;
  100033. } else {
  100034. diff -Nur linux-3.12.26.orig/net/bridge/br_multicast.c linux-3.12.26/net/bridge/br_multicast.c
  100035. --- linux-3.12.26.orig/net/bridge/br_multicast.c 2014-07-30 18:02:44.000000000 +0200
  100036. +++ linux-3.12.26/net/bridge/br_multicast.c 2014-08-06 16:50:15.101967082 +0200
  100037. @@ -1129,10 +1129,9 @@
  100038. struct net_bridge_port *port,
  100039. struct bridge_mcast_querier *querier,
  100040. int saddr,
  100041. - bool is_general_query,
  100042. unsigned long max_delay)
  100043. {
  100044. - if (saddr && is_general_query)
  100045. + if (saddr)
  100046. br_multicast_update_querier_timer(br, querier, max_delay);
  100047. else if (timer_pending(&querier->timer))
  100048. return;
  100049. @@ -1184,16 +1183,8 @@
  100050. IGMPV3_MRC(ih3->code) * (HZ / IGMP_TIMER_SCALE) : 1;
  100051. }
  100052. - /* RFC2236+RFC3376 (IGMPv2+IGMPv3) require the multicast link layer
  100053. - * all-systems destination addresses (224.0.0.1) for general queries
  100054. - */
  100055. - if (!group && iph->daddr != htonl(INADDR_ALLHOSTS_GROUP)) {
  100056. - err = -EINVAL;
  100057. - goto out;
  100058. - }
  100059. -
  100060. br_multicast_query_received(br, port, &br->ip4_querier, !!iph->saddr,
  100061. - !group, max_delay);
  100062. + max_delay);
  100063. if (!group)
  100064. goto out;
  100065. @@ -1239,7 +1230,6 @@
  100066. unsigned long max_delay;
  100067. unsigned long now = jiffies;
  100068. const struct in6_addr *group = NULL;
  100069. - bool is_general_query;
  100070. int err = 0;
  100071. u16 vid = 0;
  100072. @@ -1248,12 +1238,6 @@
  100073. (port && port->state == BR_STATE_DISABLED))
  100074. goto out;
  100075. - /* RFC2710+RFC3810 (MLDv1+MLDv2) require link-local source addresses */
  100076. - if (!(ipv6_addr_type(&ip6h->saddr) & IPV6_ADDR_LINKLOCAL)) {
  100077. - err = -EINVAL;
  100078. - goto out;
  100079. - }
  100080. -
  100081. if (skb->len == sizeof(*mld)) {
  100082. if (!pskb_may_pull(skb, sizeof(*mld))) {
  100083. err = -EINVAL;
  100084. @@ -1275,19 +1259,8 @@
  100085. max_delay = max(msecs_to_jiffies(mldv2_mrc(mld2q)), 1UL);
  100086. }
  100087. - is_general_query = group && ipv6_addr_any(group);
  100088. -
  100089. - /* RFC2710+RFC3810 (MLDv1+MLDv2) require the multicast link layer
  100090. - * all-nodes destination address (ff02::1) for general queries
  100091. - */
  100092. - if (is_general_query && !ipv6_addr_is_ll_all_nodes(&ip6h->daddr)) {
  100093. - err = -EINVAL;
  100094. - goto out;
  100095. - }
  100096. -
  100097. br_multicast_query_received(br, port, &br->ip6_querier,
  100098. - !ipv6_addr_any(&ip6h->saddr),
  100099. - is_general_query, max_delay);
  100100. + !ipv6_addr_any(&ip6h->saddr), max_delay);
  100101. if (!group)
  100102. goto out;
  100103. diff -Nur linux-3.12.26.orig/net/core/netpoll.c linux-3.12.26/net/core/netpoll.c
  100104. --- linux-3.12.26.orig/net/core/netpoll.c 2014-07-30 18:02:44.000000000 +0200
  100105. +++ linux-3.12.26/net/core/netpoll.c 2014-08-06 16:50:15.101967082 +0200
  100106. @@ -740,7 +740,7 @@
  100107. struct nd_msg *msg;
  100108. struct ipv6hdr *hdr;
  100109. - if (skb->protocol != htons(ETH_P_IPV6))
  100110. + if (skb->protocol != htons(ETH_P_ARP))
  100111. return false;
  100112. if (!pskb_may_pull(skb, sizeof(struct ipv6hdr) + sizeof(struct nd_msg)))
  100113. return false;
  100114. diff -Nur linux-3.12.26.orig/net/core/rtnetlink.c linux-3.12.26/net/core/rtnetlink.c
  100115. --- linux-3.12.26.orig/net/core/rtnetlink.c 2014-07-30 18:02:44.000000000 +0200
  100116. +++ linux-3.12.26/net/core/rtnetlink.c 2014-08-06 16:50:15.101967082 +0200
  100117. @@ -2071,13 +2071,12 @@
  100118. static int nlmsg_populate_fdb_fill(struct sk_buff *skb,
  100119. struct net_device *dev,
  100120. u8 *addr, u32 pid, u32 seq,
  100121. - int type, unsigned int flags,
  100122. - int nlflags)
  100123. + int type, unsigned int flags)
  100124. {
  100125. struct nlmsghdr *nlh;
  100126. struct ndmsg *ndm;
  100127. - nlh = nlmsg_put(skb, pid, seq, type, sizeof(*ndm), nlflags);
  100128. + nlh = nlmsg_put(skb, pid, seq, type, sizeof(*ndm), NLM_F_MULTI);
  100129. if (!nlh)
  100130. return -EMSGSIZE;
  100131. @@ -2115,7 +2114,7 @@
  100132. if (!skb)
  100133. goto errout;
  100134. - err = nlmsg_populate_fdb_fill(skb, dev, addr, 0, 0, type, NTF_SELF, 0);
  100135. + err = nlmsg_populate_fdb_fill(skb, dev, addr, 0, 0, type, NTF_SELF);
  100136. if (err < 0) {
  100137. kfree_skb(skb);
  100138. goto errout;
  100139. @@ -2340,8 +2339,7 @@
  100140. err = nlmsg_populate_fdb_fill(skb, dev, ha->addr,
  100141. portid, seq,
  100142. - RTM_NEWNEIGH, NTF_SELF,
  100143. - NLM_F_MULTI);
  100144. + RTM_NEWNEIGH, NTF_SELF);
  100145. if (err < 0)
  100146. return err;
  100147. skip:
  100148. diff -Nur linux-3.12.26.orig/net/core/sock.c linux-3.12.26/net/core/sock.c
  100149. --- linux-3.12.26.orig/net/core/sock.c 2014-07-30 18:02:44.000000000 +0200
  100150. +++ linux-3.12.26/net/core/sock.c 2014-08-06 16:50:15.105967113 +0200
  100151. @@ -2408,13 +2408,10 @@
  100152. if (sk->sk_backlog.tail)
  100153. __release_sock(sk);
  100154. - /* Warning : release_cb() might need to release sk ownership,
  100155. - * ie call sock_release_ownership(sk) before us.
  100156. - */
  100157. if (sk->sk_prot->release_cb)
  100158. sk->sk_prot->release_cb(sk);
  100159. - sock_release_ownership(sk);
  100160. + sk->sk_lock.owned = 0;
  100161. if (waitqueue_active(&sk->sk_lock.wq))
  100162. wake_up(&sk->sk_lock.wq);
  100163. spin_unlock_bh(&sk->sk_lock.slock);
  100164. diff -Nur linux-3.12.26.orig/net/ipv4/gre_demux.c linux-3.12.26/net/ipv4/gre_demux.c
  100165. --- linux-3.12.26.orig/net/ipv4/gre_demux.c 2014-07-30 18:02:44.000000000 +0200
  100166. +++ linux-3.12.26/net/ipv4/gre_demux.c 2014-08-06 16:50:15.105967113 +0200
  100167. @@ -211,14 +211,6 @@
  100168. int i;
  100169. bool csum_err = false;
  100170. -#ifdef CONFIG_NET_IPGRE_BROADCAST
  100171. - if (ipv4_is_multicast(ip_hdr(skb)->daddr)) {
  100172. - /* Looped back packet, drop it! */
  100173. - if (rt_is_output_route(skb_rtable(skb)))
  100174. - goto drop;
  100175. - }
  100176. -#endif
  100177. -
  100178. if (parse_gre_header(skb, &tpi, &csum_err) < 0)
  100179. goto drop;
  100180. diff -Nur linux-3.12.26.orig/net/ipv4/inet_fragment.c linux-3.12.26/net/ipv4/inet_fragment.c
  100181. --- linux-3.12.26.orig/net/ipv4/inet_fragment.c 2014-07-30 18:02:44.000000000 +0200
  100182. +++ linux-3.12.26/net/ipv4/inet_fragment.c 2014-08-06 16:50:15.105967113 +0200
  100183. @@ -211,7 +211,7 @@
  100184. }
  100185. work = frag_mem_limit(nf) - nf->low_thresh;
  100186. - while (work > 0 || force) {
  100187. + while (work > 0) {
  100188. spin_lock(&nf->lru_lock);
  100189. if (list_empty(&nf->lru_list)) {
  100190. @@ -281,10 +281,9 @@
  100191. atomic_inc(&qp->refcnt);
  100192. hlist_add_head(&qp->list, &hb->chain);
  100193. - inet_frag_lru_add(nf, qp);
  100194. spin_unlock(&hb->chain_lock);
  100195. read_unlock(&f->lock);
  100196. -
  100197. + inet_frag_lru_add(nf, qp);
  100198. return qp;
  100199. }
  100200. diff -Nur linux-3.12.26.orig/net/ipv4/ipmr.c linux-3.12.26/net/ipv4/ipmr.c
  100201. --- linux-3.12.26.orig/net/ipv4/ipmr.c 2014-07-30 18:02:44.000000000 +0200
  100202. +++ linux-3.12.26/net/ipv4/ipmr.c 2014-08-06 16:50:15.105967113 +0200
  100203. @@ -2253,14 +2253,13 @@
  100204. }
  100205. static int ipmr_fill_mroute(struct mr_table *mrt, struct sk_buff *skb,
  100206. - u32 portid, u32 seq, struct mfc_cache *c, int cmd,
  100207. - int flags)
  100208. + u32 portid, u32 seq, struct mfc_cache *c, int cmd)
  100209. {
  100210. struct nlmsghdr *nlh;
  100211. struct rtmsg *rtm;
  100212. int err;
  100213. - nlh = nlmsg_put(skb, portid, seq, cmd, sizeof(*rtm), flags);
  100214. + nlh = nlmsg_put(skb, portid, seq, cmd, sizeof(*rtm), NLM_F_MULTI);
  100215. if (nlh == NULL)
  100216. return -EMSGSIZE;
  100217. @@ -2328,7 +2327,7 @@
  100218. if (skb == NULL)
  100219. goto errout;
  100220. - err = ipmr_fill_mroute(mrt, skb, 0, 0, mfc, cmd, 0);
  100221. + err = ipmr_fill_mroute(mrt, skb, 0, 0, mfc, cmd);
  100222. if (err < 0)
  100223. goto errout;
  100224. @@ -2367,8 +2366,7 @@
  100225. if (ipmr_fill_mroute(mrt, skb,
  100226. NETLINK_CB(cb->skb).portid,
  100227. cb->nlh->nlmsg_seq,
  100228. - mfc, RTM_NEWROUTE,
  100229. - NLM_F_MULTI) < 0)
  100230. + mfc, RTM_NEWROUTE) < 0)
  100231. goto done;
  100232. next_entry:
  100233. e++;
  100234. @@ -2382,8 +2380,7 @@
  100235. if (ipmr_fill_mroute(mrt, skb,
  100236. NETLINK_CB(cb->skb).portid,
  100237. cb->nlh->nlmsg_seq,
  100238. - mfc, RTM_NEWROUTE,
  100239. - NLM_F_MULTI) < 0) {
  100240. + mfc, RTM_NEWROUTE) < 0) {
  100241. spin_unlock_bh(&mfc_unres_lock);
  100242. goto done;
  100243. }
  100244. diff -Nur linux-3.12.26.orig/net/ipv4/ip_tunnel.c linux-3.12.26/net/ipv4/ip_tunnel.c
  100245. --- linux-3.12.26.orig/net/ipv4/ip_tunnel.c 2014-07-30 18:02:44.000000000 +0200
  100246. +++ linux-3.12.26/net/ipv4/ip_tunnel.c 2014-08-06 16:50:15.105967113 +0200
  100247. @@ -415,6 +415,9 @@
  100248. #ifdef CONFIG_NET_IPGRE_BROADCAST
  100249. if (ipv4_is_multicast(iph->daddr)) {
  100250. + /* Looped back packet, drop it! */
  100251. + if (rt_is_output_route(skb_rtable(skb)))
  100252. + goto drop;
  100253. tunnel->dev->stats.multicast++;
  100254. skb->pkt_type = PACKET_BROADCAST;
  100255. }
  100256. diff -Nur linux-3.12.26.orig/net/ipv4/ip_tunnel_core.c linux-3.12.26/net/ipv4/ip_tunnel_core.c
  100257. --- linux-3.12.26.orig/net/ipv4/ip_tunnel_core.c 2014-07-30 18:02:44.000000000 +0200
  100258. +++ linux-3.12.26/net/ipv4/ip_tunnel_core.c 2014-08-06 16:50:15.105967113 +0200
  100259. @@ -109,7 +109,6 @@
  100260. secpath_reset(skb);
  100261. if (!skb->l4_rxhash)
  100262. skb->rxhash = 0;
  100263. - skb_dst_drop(skb);
  100264. skb->vlan_tci = 0;
  100265. skb_set_queue_mapping(skb, 0);
  100266. skb->pkt_type = PACKET_HOST;
  100267. diff -Nur linux-3.12.26.orig/net/ipv4/tcp_output.c linux-3.12.26/net/ipv4/tcp_output.c
  100268. --- linux-3.12.26.orig/net/ipv4/tcp_output.c 2014-07-30 18:02:44.000000000 +0200
  100269. +++ linux-3.12.26/net/ipv4/tcp_output.c 2014-08-06 16:50:15.105967113 +0200
  100270. @@ -765,17 +765,6 @@
  100271. if (flags & (1UL << TCP_TSQ_DEFERRED))
  100272. tcp_tsq_handler(sk);
  100273. - /* Here begins the tricky part :
  100274. - * We are called from release_sock() with :
  100275. - * 1) BH disabled
  100276. - * 2) sk_lock.slock spinlock held
  100277. - * 3) socket owned by us (sk->sk_lock.owned == 1)
  100278. - *
  100279. - * But following code is meant to be called from BH handlers,
  100280. - * so we should keep BH disabled, but early release socket ownership
  100281. - */
  100282. - sock_release_ownership(sk);
  100283. -
  100284. if (flags & (1UL << TCP_WRITE_TIMER_DEFERRED)) {
  100285. tcp_write_timer_handler(sk);
  100286. __sock_put(sk);
  100287. diff -Nur linux-3.12.26.orig/net/ipv6/addrconf.c linux-3.12.26/net/ipv6/addrconf.c
  100288. --- linux-3.12.26.orig/net/ipv6/addrconf.c 2014-07-30 18:02:44.000000000 +0200
  100289. +++ linux-3.12.26/net/ipv6/addrconf.c 2014-08-06 16:50:15.109967145 +0200
  100290. @@ -1079,11 +1079,8 @@
  100291. * Lifetime is greater than REGEN_ADVANCE time units. In particular,
  100292. * an implementation must not create a temporary address with a zero
  100293. * Preferred Lifetime.
  100294. - * Use age calculation as in addrconf_verify to avoid unnecessary
  100295. - * temporary addresses being generated.
  100296. */
  100297. - age = (now - tmp_tstamp + ADDRCONF_TIMER_FUZZ_MINUS) / HZ;
  100298. - if (tmp_prefered_lft <= regen_advance + age) {
  100299. + if (tmp_prefered_lft <= regen_advance) {
  100300. in6_ifa_put(ifp);
  100301. in6_dev_put(idev);
  100302. ret = -1;
  100303. diff -Nur linux-3.12.26.orig/net/ipv6/exthdrs_offload.c linux-3.12.26/net/ipv6/exthdrs_offload.c
  100304. --- linux-3.12.26.orig/net/ipv6/exthdrs_offload.c 2014-07-30 18:02:44.000000000 +0200
  100305. +++ linux-3.12.26/net/ipv6/exthdrs_offload.c 2014-08-06 16:50:15.109967145 +0200
  100306. @@ -25,11 +25,11 @@
  100307. int ret;
  100308. ret = inet6_add_offload(&rthdr_offload, IPPROTO_ROUTING);
  100309. - if (ret)
  100310. + if (!ret)
  100311. goto out;
  100312. ret = inet6_add_offload(&dstopt_offload, IPPROTO_DSTOPTS);
  100313. - if (ret)
  100314. + if (!ret)
  100315. goto out_rt;
  100316. out:
  100317. diff -Nur linux-3.12.26.orig/net/ipv6/icmp.c linux-3.12.26/net/ipv6/icmp.c
  100318. --- linux-3.12.26.orig/net/ipv6/icmp.c 2014-07-30 18:02:44.000000000 +0200
  100319. +++ linux-3.12.26/net/ipv6/icmp.c 2014-08-06 16:50:15.109967145 +0200
  100320. @@ -516,7 +516,7 @@
  100321. np->tclass, NULL, &fl6, (struct rt6_info *)dst,
  100322. MSG_DONTWAIT, np->dontfrag);
  100323. if (err) {
  100324. - ICMP6_INC_STATS(net, idev, ICMP6_MIB_OUTERRORS);
  100325. + ICMP6_INC_STATS_BH(net, idev, ICMP6_MIB_OUTERRORS);
  100326. ip6_flush_pending_frames(sk);
  100327. } else {
  100328. err = icmpv6_push_pending_frames(sk, &fl6, &tmp_hdr,
  100329. diff -Nur linux-3.12.26.orig/net/ipv6/ip6mr.c linux-3.12.26/net/ipv6/ip6mr.c
  100330. --- linux-3.12.26.orig/net/ipv6/ip6mr.c 2014-07-30 18:02:44.000000000 +0200
  100331. +++ linux-3.12.26/net/ipv6/ip6mr.c 2014-08-06 16:50:15.109967145 +0200
  100332. @@ -2349,14 +2349,13 @@
  100333. }
  100334. static int ip6mr_fill_mroute(struct mr6_table *mrt, struct sk_buff *skb,
  100335. - u32 portid, u32 seq, struct mfc6_cache *c, int cmd,
  100336. - int flags)
  100337. + u32 portid, u32 seq, struct mfc6_cache *c, int cmd)
  100338. {
  100339. struct nlmsghdr *nlh;
  100340. struct rtmsg *rtm;
  100341. int err;
  100342. - nlh = nlmsg_put(skb, portid, seq, cmd, sizeof(*rtm), flags);
  100343. + nlh = nlmsg_put(skb, portid, seq, cmd, sizeof(*rtm), NLM_F_MULTI);
  100344. if (nlh == NULL)
  100345. return -EMSGSIZE;
  100346. @@ -2424,7 +2423,7 @@
  100347. if (skb == NULL)
  100348. goto errout;
  100349. - err = ip6mr_fill_mroute(mrt, skb, 0, 0, mfc, cmd, 0);
  100350. + err = ip6mr_fill_mroute(mrt, skb, 0, 0, mfc, cmd);
  100351. if (err < 0)
  100352. goto errout;
  100353. @@ -2463,8 +2462,7 @@
  100354. if (ip6mr_fill_mroute(mrt, skb,
  100355. NETLINK_CB(cb->skb).portid,
  100356. cb->nlh->nlmsg_seq,
  100357. - mfc, RTM_NEWROUTE,
  100358. - NLM_F_MULTI) < 0)
  100359. + mfc, RTM_NEWROUTE) < 0)
  100360. goto done;
  100361. next_entry:
  100362. e++;
  100363. @@ -2478,8 +2476,7 @@
  100364. if (ip6mr_fill_mroute(mrt, skb,
  100365. NETLINK_CB(cb->skb).portid,
  100366. cb->nlh->nlmsg_seq,
  100367. - mfc, RTM_NEWROUTE,
  100368. - NLM_F_MULTI) < 0) {
  100369. + mfc, RTM_NEWROUTE) < 0) {
  100370. spin_unlock_bh(&mfc_unres_lock);
  100371. goto done;
  100372. }
  100373. diff -Nur linux-3.12.26.orig/net/ipv6/ip6_output.c linux-3.12.26/net/ipv6/ip6_output.c
  100374. --- linux-3.12.26.orig/net/ipv6/ip6_output.c 2014-07-30 18:02:44.000000000 +0200
  100375. +++ linux-3.12.26/net/ipv6/ip6_output.c 2014-08-06 16:50:15.113967176 +0200
  100376. @@ -1092,19 +1092,21 @@
  100377. unsigned int fragheaderlen,
  100378. struct sk_buff *skb,
  100379. struct rt6_info *rt,
  100380. - unsigned int orig_mtu)
  100381. + bool pmtuprobe)
  100382. {
  100383. if (!(rt->dst.flags & DST_XFRM_TUNNEL)) {
  100384. if (skb == NULL) {
  100385. /* first fragment, reserve header_len */
  100386. - *mtu = orig_mtu - rt->dst.header_len;
  100387. + *mtu = *mtu - rt->dst.header_len;
  100388. } else {
  100389. /*
  100390. * this fragment is not first, the headers
  100391. * space is regarded as data space.
  100392. */
  100393. - *mtu = orig_mtu;
  100394. + *mtu = min(*mtu, pmtuprobe ?
  100395. + rt->dst.dev->mtu :
  100396. + dst_mtu(rt->dst.path));
  100397. }
  100398. *maxfraglen = ((*mtu - fragheaderlen) & ~7)
  100399. + fragheaderlen - sizeof(struct frag_hdr);
  100400. @@ -1121,7 +1123,7 @@
  100401. struct ipv6_pinfo *np = inet6_sk(sk);
  100402. struct inet_cork *cork;
  100403. struct sk_buff *skb, *skb_prev = NULL;
  100404. - unsigned int maxfraglen, fragheaderlen, mtu, orig_mtu;
  100405. + unsigned int maxfraglen, fragheaderlen, mtu;
  100406. int exthdrlen;
  100407. int dst_exthdrlen;
  100408. int hh_len;
  100409. @@ -1203,7 +1205,6 @@
  100410. dst_exthdrlen = 0;
  100411. mtu = cork->fragsize;
  100412. }
  100413. - orig_mtu = mtu;
  100414. hh_len = LL_RESERVED_SPACE(rt->dst.dev);
  100415. @@ -1283,7 +1284,8 @@
  100416. if (skb == NULL || skb_prev == NULL)
  100417. ip6_append_data_mtu(&mtu, &maxfraglen,
  100418. fragheaderlen, skb, rt,
  100419. - orig_mtu);
  100420. + np->pmtudisc ==
  100421. + IPV6_PMTUDISC_PROBE);
  100422. skb_prev = skb;
  100423. @@ -1539,8 +1541,8 @@
  100424. if (proto == IPPROTO_ICMPV6) {
  100425. struct inet6_dev *idev = ip6_dst_idev(skb_dst(skb));
  100426. - ICMP6MSGOUT_INC_STATS(net, idev, icmp6_hdr(skb)->icmp6_type);
  100427. - ICMP6_INC_STATS(net, idev, ICMP6_MIB_OUTMSGS);
  100428. + ICMP6MSGOUT_INC_STATS_BH(net, idev, icmp6_hdr(skb)->icmp6_type);
  100429. + ICMP6_INC_STATS_BH(net, idev, ICMP6_MIB_OUTMSGS);
  100430. }
  100431. err = ip6_local_out(skb);
  100432. diff -Nur linux-3.12.26.orig/net/ipv6/mcast.c linux-3.12.26/net/ipv6/mcast.c
  100433. --- linux-3.12.26.orig/net/ipv6/mcast.c 2014-07-30 18:02:44.000000000 +0200
  100434. +++ linux-3.12.26/net/ipv6/mcast.c 2014-08-06 16:50:15.113967176 +0200
  100435. @@ -1620,12 +1620,11 @@
  100436. dst_output);
  100437. out:
  100438. if (!err) {
  100439. - ICMP6MSGOUT_INC_STATS(net, idev, ICMPV6_MLD2_REPORT);
  100440. - ICMP6_INC_STATS(net, idev, ICMP6_MIB_OUTMSGS);
  100441. - IP6_UPD_PO_STATS(net, idev, IPSTATS_MIB_OUTMCAST, payload_len);
  100442. - } else {
  100443. - IP6_INC_STATS(net, idev, IPSTATS_MIB_OUTDISCARDS);
  100444. - }
  100445. + ICMP6MSGOUT_INC_STATS_BH(net, idev, ICMPV6_MLD2_REPORT);
  100446. + ICMP6_INC_STATS_BH(net, idev, ICMP6_MIB_OUTMSGS);
  100447. + IP6_UPD_PO_STATS_BH(net, idev, IPSTATS_MIB_OUTMCAST, payload_len);
  100448. + } else
  100449. + IP6_INC_STATS_BH(net, idev, IPSTATS_MIB_OUTDISCARDS);
  100450. rcu_read_unlock();
  100451. return;
  100452. diff -Nur linux-3.12.26.orig/net/ipv6/ping.c linux-3.12.26/net/ipv6/ping.c
  100453. --- linux-3.12.26.orig/net/ipv6/ping.c 2014-07-30 18:02:44.000000000 +0200
  100454. +++ linux-3.12.26/net/ipv6/ping.c 2014-08-06 16:50:15.113967176 +0200
  100455. @@ -182,8 +182,8 @@
  100456. MSG_DONTWAIT, np->dontfrag);
  100457. if (err) {
  100458. - ICMP6_INC_STATS(sock_net(sk), rt->rt6i_idev,
  100459. - ICMP6_MIB_OUTERRORS);
  100460. + ICMP6_INC_STATS_BH(sock_net(sk), rt->rt6i_idev,
  100461. + ICMP6_MIB_OUTERRORS);
  100462. ip6_flush_pending_frames(sk);
  100463. } else {
  100464. err = icmpv6_push_pending_frames(sk, &fl6,
  100465. diff -Nur linux-3.12.26.orig/net/ipv6/route.c linux-3.12.26/net/ipv6/route.c
  100466. --- linux-3.12.26.orig/net/ipv6/route.c 2014-07-30 18:02:44.000000000 +0200
  100467. +++ linux-3.12.26/net/ipv6/route.c 2014-08-06 16:50:15.113967176 +0200
  100468. @@ -1501,7 +1501,7 @@
  100469. if (!table)
  100470. goto out;
  100471. - rt = ip6_dst_alloc(net, NULL, (cfg->fc_flags & RTF_ADDRCONF) ? 0 : DST_NOCOUNT, table);
  100472. + rt = ip6_dst_alloc(net, NULL, DST_NOCOUNT, table);
  100473. if (!rt) {
  100474. err = -ENOMEM;
  100475. diff -Nur linux-3.12.26.orig/net/rds/iw.c linux-3.12.26/net/rds/iw.c
  100476. --- linux-3.12.26.orig/net/rds/iw.c 2014-07-30 18:02:44.000000000 +0200
  100477. +++ linux-3.12.26/net/rds/iw.c 2014-08-06 16:50:15.117967208 +0200
  100478. @@ -239,8 +239,7 @@
  100479. ret = rdma_bind_addr(cm_id, (struct sockaddr *)&sin);
  100480. /* due to this, we will claim to support IB devices unless we
  100481. check node_type. */
  100482. - if (ret || !cm_id->device ||
  100483. - cm_id->device->node_type != RDMA_NODE_RNIC)
  100484. + if (ret || cm_id->device->node_type != RDMA_NODE_RNIC)
  100485. ret = -EADDRNOTAVAIL;
  100486. rdsdebug("addr %pI4 ret %d node type %d\n",
  100487. diff -Nur linux-3.12.26.orig/net/sched/sch_fq.c linux-3.12.26/net/sched/sch_fq.c
  100488. --- linux-3.12.26.orig/net/sched/sch_fq.c 2014-07-30 18:02:44.000000000 +0200
  100489. +++ linux-3.12.26/net/sched/sch_fq.c 2014-08-06 16:50:15.133967333 +0200
  100490. @@ -577,11 +577,9 @@
  100491. q->stat_gc_flows += fcnt;
  100492. }
  100493. -static int fq_resize(struct Qdisc *sch, u32 log)
  100494. +static int fq_resize(struct fq_sched_data *q, u32 log)
  100495. {
  100496. - struct fq_sched_data *q = qdisc_priv(sch);
  100497. struct rb_root *array;
  100498. - void *old_fq_root;
  100499. u32 idx;
  100500. if (q->fq_root && log == q->fq_trees_log)
  100501. @@ -594,19 +592,13 @@
  100502. for (idx = 0; idx < (1U << log); idx++)
  100503. array[idx] = RB_ROOT;
  100504. - sch_tree_lock(sch);
  100505. -
  100506. - old_fq_root = q->fq_root;
  100507. - if (old_fq_root)
  100508. - fq_rehash(q, old_fq_root, q->fq_trees_log, array, log);
  100509. -
  100510. + if (q->fq_root) {
  100511. + fq_rehash(q, q->fq_root, q->fq_trees_log, array, log);
  100512. + kfree(q->fq_root);
  100513. + }
  100514. q->fq_root = array;
  100515. q->fq_trees_log = log;
  100516. - sch_tree_unlock(sch);
  100517. -
  100518. - kfree(old_fq_root);
  100519. -
  100520. return 0;
  100521. }
  100522. @@ -682,11 +674,9 @@
  100523. q->flow_refill_delay = usecs_to_jiffies(usecs_delay);
  100524. }
  100525. - if (!err) {
  100526. - sch_tree_unlock(sch);
  100527. - err = fq_resize(sch, fq_log);
  100528. - sch_tree_lock(sch);
  100529. - }
  100530. + if (!err)
  100531. + err = fq_resize(q, fq_log);
  100532. +
  100533. while (sch->q.qlen > sch->limit) {
  100534. struct sk_buff *skb = fq_dequeue(sch);
  100535. @@ -732,7 +722,7 @@
  100536. if (opt)
  100537. err = fq_change(sch, opt);
  100538. else
  100539. - err = fq_resize(sch, q->fq_trees_log);
  100540. + err = fq_resize(q, q->fq_trees_log);
  100541. return err;
  100542. }
  100543. diff -Nur linux-3.12.26.orig/net/sctp/sm_make_chunk.c linux-3.12.26/net/sctp/sm_make_chunk.c
  100544. --- linux-3.12.26.orig/net/sctp/sm_make_chunk.c 2014-07-30 18:02:44.000000000 +0200
  100545. +++ linux-3.12.26/net/sctp/sm_make_chunk.c 2014-08-06 16:50:15.133967333 +0200
  100546. @@ -1434,8 +1434,8 @@
  100547. BUG_ON(!list_empty(&chunk->list));
  100548. list_del_init(&chunk->transmitted_list);
  100549. - consume_skb(chunk->skb);
  100550. - consume_skb(chunk->auth_chunk);
  100551. + /* Free the chunk skb data and the SCTP_chunk stub itself. */
  100552. + dev_kfree_skb(chunk->skb);
  100553. SCTP_DBG_OBJCNT_DEC(chunk);
  100554. kmem_cache_free(sctp_chunk_cachep, chunk);
  100555. diff -Nur linux-3.12.26.orig/net/sctp/sm_statefuns.c linux-3.12.26/net/sctp/sm_statefuns.c
  100556. --- linux-3.12.26.orig/net/sctp/sm_statefuns.c 2014-07-30 18:02:44.000000000 +0200
  100557. +++ linux-3.12.26/net/sctp/sm_statefuns.c 2014-08-06 16:50:15.133967333 +0200
  100558. @@ -761,6 +761,7 @@
  100559. /* Make sure that we and the peer are AUTH capable */
  100560. if (!net->sctp.auth_enable || !new_asoc->peer.auth_capable) {
  100561. + kfree_skb(chunk->auth_chunk);
  100562. sctp_association_free(new_asoc);
  100563. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  100564. }
  100565. @@ -775,6 +776,10 @@
  100566. auth.transport = chunk->transport;
  100567. ret = sctp_sf_authenticate(net, ep, new_asoc, type, &auth);
  100568. +
  100569. + /* We can now safely free the auth_chunk clone */
  100570. + kfree_skb(chunk->auth_chunk);
  100571. +
  100572. if (ret != SCTP_IERROR_NO_ERROR) {
  100573. sctp_association_free(new_asoc);
  100574. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  100575. diff -Nur linux-3.12.26.orig/net/socket.c linux-3.12.26/net/socket.c
  100576. --- linux-3.12.26.orig/net/socket.c 2014-07-30 18:02:44.000000000 +0200
  100577. +++ linux-3.12.26/net/socket.c 2014-08-06 16:50:15.153967491 +0200
  100578. @@ -1972,10 +1972,6 @@
  100579. {
  100580. if (copy_from_user(kmsg, umsg, sizeof(struct msghdr)))
  100581. return -EFAULT;
  100582. -
  100583. - if (kmsg->msg_namelen < 0)
  100584. - return -EINVAL;
  100585. -
  100586. if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
  100587. kmsg->msg_namelen = sizeof(struct sockaddr_storage);
  100588. return 0;
  100589. diff -Nur linux-3.12.26.orig/net/sunrpc/backchannel_rqst.c linux-3.12.26/net/sunrpc/backchannel_rqst.c
  100590. --- linux-3.12.26.orig/net/sunrpc/backchannel_rqst.c 2014-07-30 18:02:44.000000000 +0200
  100591. +++ linux-3.12.26/net/sunrpc/backchannel_rqst.c 2014-08-06 16:50:15.157967521 +0200
  100592. @@ -64,6 +64,7 @@
  100593. free_page((unsigned long)xbufp->head[0].iov_base);
  100594. xbufp = &req->rq_snd_buf;
  100595. free_page((unsigned long)xbufp->head[0].iov_base);
  100596. + list_del(&req->rq_bc_pa_list);
  100597. kfree(req);
  100598. }
  100599. @@ -167,10 +168,8 @@
  100600. /*
  100601. * Memory allocation failed, free the temporary list
  100602. */
  100603. - list_for_each_entry_safe(req, tmp, &tmp_list, rq_bc_pa_list) {
  100604. - list_del(&req->rq_bc_pa_list);
  100605. + list_for_each_entry_safe(req, tmp, &tmp_list, rq_bc_pa_list)
  100606. xprt_free_allocation(req);
  100607. - }
  100608. dprintk("RPC: setup backchannel transport failed\n");
  100609. return -ENOMEM;
  100610. @@ -199,7 +198,6 @@
  100611. xprt_dec_alloc_count(xprt, max_reqs);
  100612. list_for_each_entry_safe(req, tmp, &xprt->bc_pa_list, rq_bc_pa_list) {
  100613. dprintk("RPC: req=%p\n", req);
  100614. - list_del(&req->rq_bc_pa_list);
  100615. xprt_free_allocation(req);
  100616. if (--max_reqs == 0)
  100617. break;
  100618. diff -Nur linux-3.12.26.orig/net/unix/af_unix.c linux-3.12.26/net/unix/af_unix.c
  100619. --- linux-3.12.26.orig/net/unix/af_unix.c 2014-07-30 18:02:44.000000000 +0200
  100620. +++ linux-3.12.26/net/unix/af_unix.c 2014-08-06 16:50:15.161967553 +0200
  100621. @@ -1785,11 +1785,8 @@
  100622. goto out;
  100623. err = mutex_lock_interruptible(&u->readlock);
  100624. - if (unlikely(err)) {
  100625. - /* recvmsg() in non blocking mode is supposed to return -EAGAIN
  100626. - * sk_rcvtimeo is not honored by mutex_lock_interruptible()
  100627. - */
  100628. - err = noblock ? -EAGAIN : -ERESTARTSYS;
  100629. + if (err) {
  100630. + err = sock_intr_errno(sock_rcvtimeo(sk, noblock));
  100631. goto out;
  100632. }
  100633. @@ -1914,7 +1911,6 @@
  100634. struct unix_sock *u = unix_sk(sk);
  100635. struct sockaddr_un *sunaddr = msg->msg_name;
  100636. int copied = 0;
  100637. - int noblock = flags & MSG_DONTWAIT;
  100638. int check_creds = 0;
  100639. int target;
  100640. int err = 0;
  100641. @@ -1930,7 +1926,7 @@
  100642. goto out;
  100643. target = sock_rcvlowat(sk, flags&MSG_WAITALL, size);
  100644. - timeo = sock_rcvtimeo(sk, noblock);
  100645. + timeo = sock_rcvtimeo(sk, flags&MSG_DONTWAIT);
  100646. /* Lock the socket to prevent queue disordering
  100647. * while sleeps in memcpy_tomsg
  100648. @@ -1942,11 +1938,8 @@
  100649. }
  100650. err = mutex_lock_interruptible(&u->readlock);
  100651. - if (unlikely(err)) {
  100652. - /* recvmsg() in non blocking mode is supposed to return -EAGAIN
  100653. - * sk_rcvtimeo is not honored by mutex_lock_interruptible()
  100654. - */
  100655. - err = noblock ? -EAGAIN : -ERESTARTSYS;
  100656. + if (err) {
  100657. + err = sock_intr_errno(timeo);
  100658. goto out;
  100659. }
  100660. diff -Nur linux-3.12.26.orig/security/selinux/hooks.c linux-3.12.26/security/selinux/hooks.c
  100661. --- linux-3.12.26.orig/security/selinux/hooks.c 2014-07-30 18:02:44.000000000 +0200
  100662. +++ linux-3.12.26/security/selinux/hooks.c 2014-08-06 16:50:15.161967553 +0200
  100663. @@ -1386,33 +1386,15 @@
  100664. isec->sid = sbsec->sid;
  100665. if ((sbsec->flags & SE_SBPROC) && !S_ISLNK(inode->i_mode)) {
  100666. - /* We must have a dentry to determine the label on
  100667. - * procfs inodes */
  100668. - if (opt_dentry)
  100669. - /* Called from d_instantiate or
  100670. - * d_splice_alias. */
  100671. - dentry = dget(opt_dentry);
  100672. - else
  100673. - /* Called from selinux_complete_init, try to
  100674. - * find a dentry. */
  100675. - dentry = d_find_alias(inode);
  100676. - /*
  100677. - * This can be hit on boot when a file is accessed
  100678. - * before the policy is loaded. When we load policy we
  100679. - * may find inodes that have no dentry on the
  100680. - * sbsec->isec_head list. No reason to complain as
  100681. - * these will get fixed up the next time we go through
  100682. - * inode_doinit() with a dentry, before these inodes
  100683. - * could be used again by userspace.
  100684. - */
  100685. - if (!dentry)
  100686. - goto out_unlock;
  100687. - isec->sclass = inode_mode_to_security_class(inode->i_mode);
  100688. - rc = selinux_proc_get_sid(dentry, isec->sclass, &sid);
  100689. - dput(dentry);
  100690. - if (rc)
  100691. - goto out_unlock;
  100692. - isec->sid = sid;
  100693. + if (opt_dentry) {
  100694. + isec->sclass = inode_mode_to_security_class(inode->i_mode);
  100695. + rc = selinux_proc_get_sid(opt_dentry,
  100696. + isec->sclass,
  100697. + &sid);
  100698. + if (rc)
  100699. + goto out_unlock;
  100700. + isec->sid = sid;
  100701. + }
  100702. }
  100703. break;
  100704. }
  100705. diff -Nur linux-3.12.26.orig/sound/arm/bcm2835.c linux-3.12.26/sound/arm/bcm2835.c
  100706. --- linux-3.12.26.orig/sound/arm/bcm2835.c 1970-01-01 01:00:00.000000000 +0100
  100707. +++ linux-3.12.26/sound/arm/bcm2835.c 2014-08-06 16:50:15.161967553 +0200
  100708. @@ -0,0 +1,420 @@
  100709. +/*****************************************************************************
  100710. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  100711. +*
  100712. +* Unless you and Broadcom execute a separate written software license
  100713. +* agreement governing use of this software, this software is licensed to you
  100714. +* under the terms of the GNU General Public License version 2, available at
  100715. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  100716. +*
  100717. +* Notwithstanding the above, under no circumstances may you combine this
  100718. +* software in any way with any other Broadcom software provided under a
  100719. +* license other than the GPL, without Broadcom's express prior written
  100720. +* consent.
  100721. +*****************************************************************************/
  100722. +
  100723. +#include <linux/platform_device.h>
  100724. +
  100725. +#include <linux/init.h>
  100726. +#include <linux/slab.h>
  100727. +#include <linux/module.h>
  100728. +
  100729. +#include "bcm2835.h"
  100730. +
  100731. +/* module parameters (see "Module Parameters") */
  100732. +/* SNDRV_CARDS: maximum number of cards supported by this module */
  100733. +static int index[MAX_SUBSTREAMS] = {[0 ... (MAX_SUBSTREAMS - 1)] = -1 };
  100734. +static char *id[MAX_SUBSTREAMS] = {[0 ... (MAX_SUBSTREAMS - 1)] = NULL };
  100735. +static int enable[MAX_SUBSTREAMS] = {[0 ... (MAX_SUBSTREAMS - 1)] = 1 };
  100736. +
  100737. +/* HACKY global pointers needed for successive probes to work : ssp
  100738. + * But compared against the changes we will have to do in VC audio_ipc code
  100739. + * to export 8 audio_ipc devices as a single IPC device and then monitor all
  100740. + * four devices in a thread, this gets things done quickly and should be easier
  100741. + * to debug if we run into issues
  100742. + */
  100743. +
  100744. +static struct snd_card *g_card = NULL;
  100745. +static bcm2835_chip_t *g_chip = NULL;
  100746. +
  100747. +static int snd_bcm2835_free(bcm2835_chip_t * chip)
  100748. +{
  100749. + kfree(chip);
  100750. + return 0;
  100751. +}
  100752. +
  100753. +/* component-destructor
  100754. + * (see "Management of Cards and Components")
  100755. + */
  100756. +static int snd_bcm2835_dev_free(struct snd_device *device)
  100757. +{
  100758. + return snd_bcm2835_free(device->device_data);
  100759. +}
  100760. +
  100761. +/* chip-specific constructor
  100762. + * (see "Management of Cards and Components")
  100763. + */
  100764. +static int snd_bcm2835_create(struct snd_card *card,
  100765. + struct platform_device *pdev,
  100766. + bcm2835_chip_t ** rchip)
  100767. +{
  100768. + bcm2835_chip_t *chip;
  100769. + int err;
  100770. + static struct snd_device_ops ops = {
  100771. + .dev_free = snd_bcm2835_dev_free,
  100772. + };
  100773. +
  100774. + *rchip = NULL;
  100775. +
  100776. + chip = kzalloc(sizeof(*chip), GFP_KERNEL);
  100777. + if (chip == NULL)
  100778. + return -ENOMEM;
  100779. +
  100780. + chip->card = card;
  100781. +
  100782. + err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
  100783. + if (err < 0) {
  100784. + snd_bcm2835_free(chip);
  100785. + return err;
  100786. + }
  100787. +
  100788. + *rchip = chip;
  100789. + return 0;
  100790. +}
  100791. +
  100792. +static int snd_bcm2835_alsa_probe(struct platform_device *pdev)
  100793. +{
  100794. + static int dev;
  100795. + bcm2835_chip_t *chip;
  100796. + struct snd_card *card;
  100797. + int err;
  100798. +
  100799. + if (dev >= MAX_SUBSTREAMS)
  100800. + return -ENODEV;
  100801. +
  100802. + if (!enable[dev]) {
  100803. + dev++;
  100804. + return -ENOENT;
  100805. + }
  100806. +
  100807. + if (dev > 0)
  100808. + goto add_register_map;
  100809. +
  100810. + err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &g_card);
  100811. + if (err < 0)
  100812. + goto out;
  100813. +
  100814. + snd_card_set_dev(g_card, &pdev->dev);
  100815. + strcpy(g_card->driver, "bcm2835");
  100816. + strcpy(g_card->shortname, "bcm2835 ALSA");
  100817. + sprintf(g_card->longname, "%s", g_card->shortname);
  100818. +
  100819. + err = snd_bcm2835_create(g_card, pdev, &chip);
  100820. + if (err < 0) {
  100821. + dev_err(&pdev->dev, "Failed to create bcm2835 chip\n");
  100822. + goto out_bcm2835_create;
  100823. + }
  100824. +
  100825. + g_chip = chip;
  100826. + err = snd_bcm2835_new_pcm(chip);
  100827. + if (err < 0) {
  100828. + dev_err(&pdev->dev, "Failed to create new BCM2835 pcm device\n");
  100829. + goto out_bcm2835_new_pcm;
  100830. + }
  100831. +
  100832. + err = snd_bcm2835_new_spdif_pcm(chip);
  100833. + if (err < 0) {
  100834. + dev_err(&pdev->dev, "Failed to create new BCM2835 spdif pcm device\n");
  100835. + goto out_bcm2835_new_spdif;
  100836. + }
  100837. +
  100838. + err = snd_bcm2835_new_ctl(chip);
  100839. + if (err < 0) {
  100840. + dev_err(&pdev->dev, "Failed to create new BCM2835 ctl\n");
  100841. + goto out_bcm2835_new_ctl;
  100842. + }
  100843. +
  100844. +add_register_map:
  100845. + card = g_card;
  100846. + chip = g_chip;
  100847. +
  100848. + BUG_ON(!(card && chip));
  100849. +
  100850. + chip->avail_substreams |= (1 << dev);
  100851. + chip->pdev[dev] = pdev;
  100852. +
  100853. + if (dev == 0) {
  100854. + err = snd_card_register(card);
  100855. + if (err < 0) {
  100856. + dev_err(&pdev->dev,
  100857. + "Failed to register bcm2835 ALSA card \n");
  100858. + goto out_card_register;
  100859. + }
  100860. + platform_set_drvdata(pdev, card);
  100861. + audio_info("bcm2835 ALSA card created!\n");
  100862. + } else {
  100863. + audio_info("bcm2835 ALSA chip created!\n");
  100864. + platform_set_drvdata(pdev, (void *)dev);
  100865. + }
  100866. +
  100867. + dev++;
  100868. +
  100869. + return 0;
  100870. +
  100871. +out_card_register:
  100872. +out_bcm2835_new_ctl:
  100873. +out_bcm2835_new_spdif:
  100874. +out_bcm2835_new_pcm:
  100875. +out_bcm2835_create:
  100876. + BUG_ON(!g_card);
  100877. + if (snd_card_free(g_card))
  100878. + dev_err(&pdev->dev, "Failed to free Registered alsa card\n");
  100879. + g_card = NULL;
  100880. +out:
  100881. + dev = SNDRV_CARDS; /* stop more avail_substreams from being probed */
  100882. + dev_err(&pdev->dev, "BCM2835 ALSA Probe failed !!\n");
  100883. + return err;
  100884. +}
  100885. +
  100886. +static int snd_bcm2835_alsa_remove(struct platform_device *pdev)
  100887. +{
  100888. + uint32_t idx;
  100889. + void *drv_data;
  100890. +
  100891. + drv_data = platform_get_drvdata(pdev);
  100892. +
  100893. + if (drv_data == (void *)g_card) {
  100894. + /* This is the card device */
  100895. + snd_card_free((struct snd_card *)drv_data);
  100896. + g_card = NULL;
  100897. + g_chip = NULL;
  100898. + } else {
  100899. + idx = (uint32_t) drv_data;
  100900. + if (g_card != NULL) {
  100901. + BUG_ON(!g_chip);
  100902. + /* We pass chip device numbers in audio ipc devices
  100903. + * other than the one we registered our card with
  100904. + */
  100905. + idx = (uint32_t) drv_data;
  100906. + BUG_ON(!idx || idx > MAX_SUBSTREAMS);
  100907. + g_chip->avail_substreams &= ~(1 << idx);
  100908. + /* There should be atleast one substream registered
  100909. + * after we are done here, as it wil be removed when
  100910. + * the *remove* is called for the card device
  100911. + */
  100912. + BUG_ON(!g_chip->avail_substreams);
  100913. + }
  100914. + }
  100915. +
  100916. + platform_set_drvdata(pdev, NULL);
  100917. +
  100918. + return 0;
  100919. +}
  100920. +
  100921. +#ifdef CONFIG_PM
  100922. +static int snd_bcm2835_alsa_suspend(struct platform_device *pdev,
  100923. + pm_message_t state)
  100924. +{
  100925. + return 0;
  100926. +}
  100927. +
  100928. +static int snd_bcm2835_alsa_resume(struct platform_device *pdev)
  100929. +{
  100930. + return 0;
  100931. +}
  100932. +
  100933. +#endif
  100934. +
  100935. +static struct platform_driver bcm2835_alsa0_driver = {
  100936. + .probe = snd_bcm2835_alsa_probe,
  100937. + .remove = snd_bcm2835_alsa_remove,
  100938. +#ifdef CONFIG_PM
  100939. + .suspend = snd_bcm2835_alsa_suspend,
  100940. + .resume = snd_bcm2835_alsa_resume,
  100941. +#endif
  100942. + .driver = {
  100943. + .name = "bcm2835_AUD0",
  100944. + .owner = THIS_MODULE,
  100945. + },
  100946. +};
  100947. +
  100948. +static struct platform_driver bcm2835_alsa1_driver = {
  100949. + .probe = snd_bcm2835_alsa_probe,
  100950. + .remove = snd_bcm2835_alsa_remove,
  100951. +#ifdef CONFIG_PM
  100952. + .suspend = snd_bcm2835_alsa_suspend,
  100953. + .resume = snd_bcm2835_alsa_resume,
  100954. +#endif
  100955. + .driver = {
  100956. + .name = "bcm2835_AUD1",
  100957. + .owner = THIS_MODULE,
  100958. + },
  100959. +};
  100960. +
  100961. +static struct platform_driver bcm2835_alsa2_driver = {
  100962. + .probe = snd_bcm2835_alsa_probe,
  100963. + .remove = snd_bcm2835_alsa_remove,
  100964. +#ifdef CONFIG_PM
  100965. + .suspend = snd_bcm2835_alsa_suspend,
  100966. + .resume = snd_bcm2835_alsa_resume,
  100967. +#endif
  100968. + .driver = {
  100969. + .name = "bcm2835_AUD2",
  100970. + .owner = THIS_MODULE,
  100971. + },
  100972. +};
  100973. +
  100974. +static struct platform_driver bcm2835_alsa3_driver = {
  100975. + .probe = snd_bcm2835_alsa_probe,
  100976. + .remove = snd_bcm2835_alsa_remove,
  100977. +#ifdef CONFIG_PM
  100978. + .suspend = snd_bcm2835_alsa_suspend,
  100979. + .resume = snd_bcm2835_alsa_resume,
  100980. +#endif
  100981. + .driver = {
  100982. + .name = "bcm2835_AUD3",
  100983. + .owner = THIS_MODULE,
  100984. + },
  100985. +};
  100986. +
  100987. +static struct platform_driver bcm2835_alsa4_driver = {
  100988. + .probe = snd_bcm2835_alsa_probe,
  100989. + .remove = snd_bcm2835_alsa_remove,
  100990. +#ifdef CONFIG_PM
  100991. + .suspend = snd_bcm2835_alsa_suspend,
  100992. + .resume = snd_bcm2835_alsa_resume,
  100993. +#endif
  100994. + .driver = {
  100995. + .name = "bcm2835_AUD4",
  100996. + .owner = THIS_MODULE,
  100997. + },
  100998. +};
  100999. +
  101000. +static struct platform_driver bcm2835_alsa5_driver = {
  101001. + .probe = snd_bcm2835_alsa_probe,
  101002. + .remove = snd_bcm2835_alsa_remove,
  101003. +#ifdef CONFIG_PM
  101004. + .suspend = snd_bcm2835_alsa_suspend,
  101005. + .resume = snd_bcm2835_alsa_resume,
  101006. +#endif
  101007. + .driver = {
  101008. + .name = "bcm2835_AUD5",
  101009. + .owner = THIS_MODULE,
  101010. + },
  101011. +};
  101012. +
  101013. +static struct platform_driver bcm2835_alsa6_driver = {
  101014. + .probe = snd_bcm2835_alsa_probe,
  101015. + .remove = snd_bcm2835_alsa_remove,
  101016. +#ifdef CONFIG_PM
  101017. + .suspend = snd_bcm2835_alsa_suspend,
  101018. + .resume = snd_bcm2835_alsa_resume,
  101019. +#endif
  101020. + .driver = {
  101021. + .name = "bcm2835_AUD6",
  101022. + .owner = THIS_MODULE,
  101023. + },
  101024. +};
  101025. +
  101026. +static struct platform_driver bcm2835_alsa7_driver = {
  101027. + .probe = snd_bcm2835_alsa_probe,
  101028. + .remove = snd_bcm2835_alsa_remove,
  101029. +#ifdef CONFIG_PM
  101030. + .suspend = snd_bcm2835_alsa_suspend,
  101031. + .resume = snd_bcm2835_alsa_resume,
  101032. +#endif
  101033. + .driver = {
  101034. + .name = "bcm2835_AUD7",
  101035. + .owner = THIS_MODULE,
  101036. + },
  101037. +};
  101038. +
  101039. +static int bcm2835_alsa_device_init(void)
  101040. +{
  101041. + int err;
  101042. + err = platform_driver_register(&bcm2835_alsa0_driver);
  101043. + if (err) {
  101044. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  101045. + goto out;
  101046. + }
  101047. +
  101048. + err = platform_driver_register(&bcm2835_alsa1_driver);
  101049. + if (err) {
  101050. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  101051. + goto unregister_0;
  101052. + }
  101053. +
  101054. + err = platform_driver_register(&bcm2835_alsa2_driver);
  101055. + if (err) {
  101056. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  101057. + goto unregister_1;
  101058. + }
  101059. +
  101060. + err = platform_driver_register(&bcm2835_alsa3_driver);
  101061. + if (err) {
  101062. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  101063. + goto unregister_2;
  101064. + }
  101065. +
  101066. + err = platform_driver_register(&bcm2835_alsa4_driver);
  101067. + if (err) {
  101068. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  101069. + goto unregister_3;
  101070. + }
  101071. +
  101072. + err = platform_driver_register(&bcm2835_alsa5_driver);
  101073. + if (err) {
  101074. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  101075. + goto unregister_4;
  101076. + }
  101077. +
  101078. + err = platform_driver_register(&bcm2835_alsa6_driver);
  101079. + if (err) {
  101080. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  101081. + goto unregister_5;
  101082. + }
  101083. +
  101084. + err = platform_driver_register(&bcm2835_alsa7_driver);
  101085. + if (err) {
  101086. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  101087. + goto unregister_6;
  101088. + }
  101089. +
  101090. + return 0;
  101091. +
  101092. +unregister_6:
  101093. + platform_driver_unregister(&bcm2835_alsa6_driver);
  101094. +unregister_5:
  101095. + platform_driver_unregister(&bcm2835_alsa5_driver);
  101096. +unregister_4:
  101097. + platform_driver_unregister(&bcm2835_alsa4_driver);
  101098. +unregister_3:
  101099. + platform_driver_unregister(&bcm2835_alsa3_driver);
  101100. +unregister_2:
  101101. + platform_driver_unregister(&bcm2835_alsa2_driver);
  101102. +unregister_1:
  101103. + platform_driver_unregister(&bcm2835_alsa1_driver);
  101104. +unregister_0:
  101105. + platform_driver_unregister(&bcm2835_alsa0_driver);
  101106. +out:
  101107. + return err;
  101108. +}
  101109. +
  101110. +static void bcm2835_alsa_device_exit(void)
  101111. +{
  101112. + platform_driver_unregister(&bcm2835_alsa0_driver);
  101113. + platform_driver_unregister(&bcm2835_alsa1_driver);
  101114. + platform_driver_unregister(&bcm2835_alsa2_driver);
  101115. + platform_driver_unregister(&bcm2835_alsa3_driver);
  101116. + platform_driver_unregister(&bcm2835_alsa4_driver);
  101117. + platform_driver_unregister(&bcm2835_alsa5_driver);
  101118. + platform_driver_unregister(&bcm2835_alsa6_driver);
  101119. + platform_driver_unregister(&bcm2835_alsa7_driver);
  101120. +}
  101121. +
  101122. +late_initcall(bcm2835_alsa_device_init);
  101123. +module_exit(bcm2835_alsa_device_exit);
  101124. +
  101125. +MODULE_AUTHOR("Dom Cobley");
  101126. +MODULE_DESCRIPTION("Alsa driver for BCM2835 chip");
  101127. +MODULE_LICENSE("GPL");
  101128. +MODULE_ALIAS("platform:bcm2835_alsa");
  101129. diff -Nur linux-3.12.26.orig/sound/arm/bcm2835-ctl.c linux-3.12.26/sound/arm/bcm2835-ctl.c
  101130. --- linux-3.12.26.orig/sound/arm/bcm2835-ctl.c 1970-01-01 01:00:00.000000000 +0100
  101131. +++ linux-3.12.26/sound/arm/bcm2835-ctl.c 2014-08-06 16:50:15.165967585 +0200
  101132. @@ -0,0 +1,323 @@
  101133. +/*****************************************************************************
  101134. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  101135. +*
  101136. +* Unless you and Broadcom execute a separate written software license
  101137. +* agreement governing use of this software, this software is licensed to you
  101138. +* under the terms of the GNU General Public License version 2, available at
  101139. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  101140. +*
  101141. +* Notwithstanding the above, under no circumstances may you combine this
  101142. +* software in any way with any other Broadcom software provided under a
  101143. +* license other than the GPL, without Broadcom's express prior written
  101144. +* consent.
  101145. +*****************************************************************************/
  101146. +
  101147. +#include <linux/platform_device.h>
  101148. +#include <linux/init.h>
  101149. +#include <linux/io.h>
  101150. +#include <linux/jiffies.h>
  101151. +#include <linux/slab.h>
  101152. +#include <linux/time.h>
  101153. +#include <linux/wait.h>
  101154. +#include <linux/delay.h>
  101155. +#include <linux/moduleparam.h>
  101156. +#include <linux/sched.h>
  101157. +
  101158. +#include <sound/core.h>
  101159. +#include <sound/control.h>
  101160. +#include <sound/pcm.h>
  101161. +#include <sound/pcm_params.h>
  101162. +#include <sound/rawmidi.h>
  101163. +#include <sound/initval.h>
  101164. +#include <sound/tlv.h>
  101165. +#include <sound/asoundef.h>
  101166. +
  101167. +#include "bcm2835.h"
  101168. +
  101169. +/* volume maximum and minimum in terms of 0.01dB */
  101170. +#define CTRL_VOL_MAX 400
  101171. +#define CTRL_VOL_MIN -10239 /* originally -10240 */
  101172. +
  101173. +
  101174. +static int snd_bcm2835_ctl_info(struct snd_kcontrol *kcontrol,
  101175. + struct snd_ctl_elem_info *uinfo)
  101176. +{
  101177. + audio_info(" ... IN\n");
  101178. + if (kcontrol->private_value == PCM_PLAYBACK_VOLUME) {
  101179. + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  101180. + uinfo->count = 1;
  101181. + uinfo->value.integer.min = CTRL_VOL_MIN;
  101182. + uinfo->value.integer.max = CTRL_VOL_MAX; /* 2303 */
  101183. + } else if (kcontrol->private_value == PCM_PLAYBACK_MUTE) {
  101184. + uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  101185. + uinfo->count = 1;
  101186. + uinfo->value.integer.min = 0;
  101187. + uinfo->value.integer.max = 1;
  101188. + } else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE) {
  101189. + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  101190. + uinfo->count = 1;
  101191. + uinfo->value.integer.min = 0;
  101192. + uinfo->value.integer.max = AUDIO_DEST_MAX-1;
  101193. + }
  101194. + audio_info(" ... OUT\n");
  101195. + return 0;
  101196. +}
  101197. +
  101198. +/* toggles mute on or off depending on the value of nmute, and returns
  101199. + * 1 if the mute value was changed, otherwise 0
  101200. + */
  101201. +static int toggle_mute(struct bcm2835_chip *chip, int nmute)
  101202. +{
  101203. + /* if settings are ok, just return 0 */
  101204. + if(chip->mute == nmute)
  101205. + return 0;
  101206. +
  101207. + /* if the sound is muted then we need to unmute */
  101208. + if(chip->mute == CTRL_VOL_MUTE)
  101209. + {
  101210. + chip->volume = chip->old_volume; /* copy the old volume back */
  101211. + audio_info("Unmuting, old_volume = %d, volume = %d ...\n", chip->old_volume, chip->volume);
  101212. + }
  101213. + else /* otherwise we mute */
  101214. + {
  101215. + chip->old_volume = chip->volume;
  101216. + chip->volume = 26214; /* set volume to minimum level AKA mute */
  101217. + audio_info("Muting, old_volume = %d, volume = %d ...\n", chip->old_volume, chip->volume);
  101218. + }
  101219. +
  101220. + chip->mute = nmute;
  101221. + return 1;
  101222. +}
  101223. +
  101224. +static int snd_bcm2835_ctl_get(struct snd_kcontrol *kcontrol,
  101225. + struct snd_ctl_elem_value *ucontrol)
  101226. +{
  101227. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  101228. +
  101229. + BUG_ON(!chip && !(chip->avail_substreams & AVAIL_SUBSTREAMS_MASK));
  101230. +
  101231. + if (kcontrol->private_value == PCM_PLAYBACK_VOLUME)
  101232. + ucontrol->value.integer.value[0] = chip2alsa(chip->volume);
  101233. + else if (kcontrol->private_value == PCM_PLAYBACK_MUTE)
  101234. + ucontrol->value.integer.value[0] = chip->mute;
  101235. + else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE)
  101236. + ucontrol->value.integer.value[0] = chip->dest;
  101237. +
  101238. + return 0;
  101239. +}
  101240. +
  101241. +static int snd_bcm2835_ctl_put(struct snd_kcontrol *kcontrol,
  101242. + struct snd_ctl_elem_value *ucontrol)
  101243. +{
  101244. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  101245. + int changed = 0;
  101246. +
  101247. + if (kcontrol->private_value == PCM_PLAYBACK_VOLUME) {
  101248. + audio_info("Volume change attempted.. volume = %d new_volume = %d\n", chip->volume, (int)ucontrol->value.integer.value[0]);
  101249. + if (chip->mute == CTRL_VOL_MUTE) {
  101250. + /* changed = toggle_mute(chip, CTRL_VOL_UNMUTE); */
  101251. + return 1; /* should return 0 to signify no change but the mixer takes this as the opposite sign (no idea why) */
  101252. + }
  101253. + if (changed
  101254. + || (ucontrol->value.integer.value[0] != chip2alsa(chip->volume))) {
  101255. +
  101256. + chip->volume = alsa2chip(ucontrol->value.integer.value[0]);
  101257. + changed = 1;
  101258. + }
  101259. +
  101260. + } else if (kcontrol->private_value == PCM_PLAYBACK_MUTE) {
  101261. + /* Now implemented */
  101262. + audio_info(" Mute attempted\n");
  101263. + changed = toggle_mute(chip, ucontrol->value.integer.value[0]);
  101264. +
  101265. + } else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE) {
  101266. + if (ucontrol->value.integer.value[0] != chip->dest) {
  101267. + chip->dest = ucontrol->value.integer.value[0];
  101268. + changed = 1;
  101269. + }
  101270. + }
  101271. +
  101272. + if (changed) {
  101273. + if (bcm2835_audio_set_ctls(chip))
  101274. + printk(KERN_ERR "Failed to set ALSA controls..\n");
  101275. + }
  101276. +
  101277. + return changed;
  101278. +}
  101279. +
  101280. +static DECLARE_TLV_DB_SCALE(snd_bcm2835_db_scale, CTRL_VOL_MIN, 1, 1);
  101281. +
  101282. +static struct snd_kcontrol_new snd_bcm2835_ctl[] = {
  101283. + {
  101284. + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  101285. + .name = "PCM Playback Volume",
  101286. + .index = 0,
  101287. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
  101288. + .private_value = PCM_PLAYBACK_VOLUME,
  101289. + .info = snd_bcm2835_ctl_info,
  101290. + .get = snd_bcm2835_ctl_get,
  101291. + .put = snd_bcm2835_ctl_put,
  101292. + .count = 1,
  101293. + .tlv = {.p = snd_bcm2835_db_scale}
  101294. + },
  101295. + {
  101296. + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  101297. + .name = "PCM Playback Switch",
  101298. + .index = 0,
  101299. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  101300. + .private_value = PCM_PLAYBACK_MUTE,
  101301. + .info = snd_bcm2835_ctl_info,
  101302. + .get = snd_bcm2835_ctl_get,
  101303. + .put = snd_bcm2835_ctl_put,
  101304. + .count = 1,
  101305. + },
  101306. + {
  101307. + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  101308. + .name = "PCM Playback Route",
  101309. + .index = 0,
  101310. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  101311. + .private_value = PCM_PLAYBACK_DEVICE,
  101312. + .info = snd_bcm2835_ctl_info,
  101313. + .get = snd_bcm2835_ctl_get,
  101314. + .put = snd_bcm2835_ctl_put,
  101315. + .count = 1,
  101316. + },
  101317. +};
  101318. +
  101319. +static int snd_bcm2835_spdif_default_info(struct snd_kcontrol *kcontrol,
  101320. + struct snd_ctl_elem_info *uinfo)
  101321. +{
  101322. + uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  101323. + uinfo->count = 1;
  101324. + return 0;
  101325. +}
  101326. +
  101327. +static int snd_bcm2835_spdif_default_get(struct snd_kcontrol *kcontrol,
  101328. + struct snd_ctl_elem_value *ucontrol)
  101329. +{
  101330. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  101331. + int i;
  101332. +
  101333. + for (i = 0; i < 4; i++)
  101334. + ucontrol->value.iec958.status[i] =
  101335. + (chip->spdif_status >> (i * 8)) && 0xff;
  101336. +
  101337. + return 0;
  101338. +}
  101339. +
  101340. +static int snd_bcm2835_spdif_default_put(struct snd_kcontrol *kcontrol,
  101341. + struct snd_ctl_elem_value *ucontrol)
  101342. +{
  101343. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  101344. + unsigned int val = 0;
  101345. + int i, change;
  101346. +
  101347. + for (i = 0; i < 4; i++)
  101348. + val |= (unsigned int)ucontrol->value.iec958.status[i] << (i * 8);
  101349. +
  101350. + change = val != chip->spdif_status;
  101351. + chip->spdif_status = val;
  101352. +
  101353. + return change;
  101354. +}
  101355. +
  101356. +static int snd_bcm2835_spdif_mask_info(struct snd_kcontrol *kcontrol,
  101357. + struct snd_ctl_elem_info *uinfo)
  101358. +{
  101359. + uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  101360. + uinfo->count = 1;
  101361. + return 0;
  101362. +}
  101363. +
  101364. +static int snd_bcm2835_spdif_mask_get(struct snd_kcontrol *kcontrol,
  101365. + struct snd_ctl_elem_value *ucontrol)
  101366. +{
  101367. + /* bcm2835 supports only consumer mode and sets all other format flags
  101368. + * automatically. So the only thing left is signalling non-audio
  101369. + * content */
  101370. + ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO;
  101371. + return 0;
  101372. +}
  101373. +
  101374. +static int snd_bcm2835_spdif_stream_info(struct snd_kcontrol *kcontrol,
  101375. + struct snd_ctl_elem_info *uinfo)
  101376. +{
  101377. + uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  101378. + uinfo->count = 1;
  101379. + return 0;
  101380. +}
  101381. +
  101382. +static int snd_bcm2835_spdif_stream_get(struct snd_kcontrol *kcontrol,
  101383. + struct snd_ctl_elem_value *ucontrol)
  101384. +{
  101385. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  101386. + int i;
  101387. +
  101388. + for (i = 0; i < 4; i++)
  101389. + ucontrol->value.iec958.status[i] =
  101390. + (chip->spdif_status >> (i * 8)) & 0xff;
  101391. + return 0;
  101392. +}
  101393. +
  101394. +static int snd_bcm2835_spdif_stream_put(struct snd_kcontrol *kcontrol,
  101395. + struct snd_ctl_elem_value *ucontrol)
  101396. +{
  101397. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  101398. + unsigned int val = 0;
  101399. + int i, change;
  101400. +
  101401. + for (i = 0; i < 4; i++)
  101402. + val |= (unsigned int)ucontrol->value.iec958.status[i] << (i * 8);
  101403. + change = val != chip->spdif_status;
  101404. + chip->spdif_status = val;
  101405. +
  101406. + return change;
  101407. +}
  101408. +
  101409. +static struct snd_kcontrol_new snd_bcm2835_spdif[] = {
  101410. + {
  101411. + .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  101412. + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
  101413. + .info = snd_bcm2835_spdif_default_info,
  101414. + .get = snd_bcm2835_spdif_default_get,
  101415. + .put = snd_bcm2835_spdif_default_put
  101416. + },
  101417. + {
  101418. + .access = SNDRV_CTL_ELEM_ACCESS_READ,
  101419. + .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  101420. + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, CON_MASK),
  101421. + .info = snd_bcm2835_spdif_mask_info,
  101422. + .get = snd_bcm2835_spdif_mask_get,
  101423. + },
  101424. + {
  101425. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  101426. + SNDRV_CTL_ELEM_ACCESS_INACTIVE,
  101427. + .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  101428. + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM),
  101429. + .info = snd_bcm2835_spdif_stream_info,
  101430. + .get = snd_bcm2835_spdif_stream_get,
  101431. + .put = snd_bcm2835_spdif_stream_put,
  101432. + },
  101433. +};
  101434. +
  101435. +int snd_bcm2835_new_ctl(bcm2835_chip_t * chip)
  101436. +{
  101437. + int err;
  101438. + unsigned int idx;
  101439. +
  101440. + strcpy(chip->card->mixername, "Broadcom Mixer");
  101441. + for (idx = 0; idx < ARRAY_SIZE(snd_bcm2835_ctl); idx++) {
  101442. + err =
  101443. + snd_ctl_add(chip->card,
  101444. + snd_ctl_new1(&snd_bcm2835_ctl[idx], chip));
  101445. + if (err < 0)
  101446. + return err;
  101447. + }
  101448. + for (idx = 0; idx < ARRAY_SIZE(snd_bcm2835_spdif); idx++) {
  101449. + err = snd_ctl_add(chip->card,
  101450. + snd_ctl_new1(&snd_bcm2835_spdif[idx], chip));
  101451. + if (err < 0)
  101452. + return err;
  101453. + }
  101454. + return 0;
  101455. +}
  101456. diff -Nur linux-3.12.26.orig/sound/arm/bcm2835.h linux-3.12.26/sound/arm/bcm2835.h
  101457. --- linux-3.12.26.orig/sound/arm/bcm2835.h 1970-01-01 01:00:00.000000000 +0100
  101458. +++ linux-3.12.26/sound/arm/bcm2835.h 2014-08-06 16:50:15.165967585 +0200
  101459. @@ -0,0 +1,166 @@
  101460. +/*****************************************************************************
  101461. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  101462. +*
  101463. +* Unless you and Broadcom execute a separate written software license
  101464. +* agreement governing use of this software, this software is licensed to you
  101465. +* under the terms of the GNU General Public License version 2, available at
  101466. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  101467. +*
  101468. +* Notwithstanding the above, under no circumstances may you combine this
  101469. +* software in any way with any other Broadcom software provided under a
  101470. +* license other than the GPL, without Broadcom's express prior written
  101471. +* consent.
  101472. +*****************************************************************************/
  101473. +
  101474. +#ifndef __SOUND_ARM_BCM2835_H
  101475. +#define __SOUND_ARM_BCM2835_H
  101476. +
  101477. +#include <linux/device.h>
  101478. +#include <linux/list.h>
  101479. +#include <linux/interrupt.h>
  101480. +#include <linux/wait.h>
  101481. +#include <sound/core.h>
  101482. +#include <sound/initval.h>
  101483. +#include <sound/pcm.h>
  101484. +#include <sound/pcm_params.h>
  101485. +#include <sound/pcm-indirect.h>
  101486. +#include <linux/workqueue.h>
  101487. +
  101488. +/*
  101489. +#define AUDIO_DEBUG_ENABLE
  101490. +#define AUDIO_VERBOSE_DEBUG_ENABLE
  101491. +*/
  101492. +
  101493. +/* Debug macros */
  101494. +
  101495. +#ifdef AUDIO_DEBUG_ENABLE
  101496. +#ifdef AUDIO_VERBOSE_DEBUG_ENABLE
  101497. +
  101498. +#define audio_debug(fmt, arg...) \
  101499. + printk(KERN_INFO"%s:%d " fmt, __func__, __LINE__, ##arg)
  101500. +
  101501. +#define audio_info(fmt, arg...) \
  101502. + printk(KERN_INFO"%s:%d " fmt, __func__, __LINE__, ##arg)
  101503. +
  101504. +#else
  101505. +
  101506. +#define audio_debug(fmt, arg...)
  101507. +
  101508. +#define audio_info(fmt, arg...)
  101509. +
  101510. +#endif /* AUDIO_VERBOSE_DEBUG_ENABLE */
  101511. +
  101512. +#else
  101513. +
  101514. +#define audio_debug(fmt, arg...)
  101515. +
  101516. +#define audio_info(fmt, arg...)
  101517. +
  101518. +#endif /* AUDIO_DEBUG_ENABLE */
  101519. +
  101520. +#define audio_error(fmt, arg...) \
  101521. + printk(KERN_ERR"%s:%d " fmt, __func__, __LINE__, ##arg)
  101522. +
  101523. +#define audio_warning(fmt, arg...) \
  101524. + printk(KERN_WARNING"%s:%d " fmt, __func__, __LINE__, ##arg)
  101525. +
  101526. +#define audio_alert(fmt, arg...) \
  101527. + printk(KERN_ALERT"%s:%d " fmt, __func__, __LINE__, ##arg)
  101528. +
  101529. +#define MAX_SUBSTREAMS (8)
  101530. +#define AVAIL_SUBSTREAMS_MASK (0xff)
  101531. +enum {
  101532. + CTRL_VOL_MUTE,
  101533. + CTRL_VOL_UNMUTE
  101534. +};
  101535. +
  101536. +/* macros for alsa2chip and chip2alsa, instead of functions */
  101537. +
  101538. +#define alsa2chip(vol) (uint)(-((vol << 8) / 100)) /* convert alsa to chip volume (defined as macro rather than function call) */
  101539. +#define chip2alsa(vol) -((vol * 100) >> 8) /* convert chip to alsa volume */
  101540. +
  101541. +/* Some constants for values .. */
  101542. +typedef enum {
  101543. + AUDIO_DEST_AUTO = 0,
  101544. + AUDIO_DEST_HEADPHONES = 1,
  101545. + AUDIO_DEST_HDMI = 2,
  101546. + AUDIO_DEST_MAX,
  101547. +} SND_BCM2835_ROUTE_T;
  101548. +
  101549. +typedef enum {
  101550. + PCM_PLAYBACK_VOLUME,
  101551. + PCM_PLAYBACK_MUTE,
  101552. + PCM_PLAYBACK_DEVICE,
  101553. +} SND_BCM2835_CTRL_T;
  101554. +
  101555. +/* definition of the chip-specific record */
  101556. +typedef struct bcm2835_chip {
  101557. + struct snd_card *card;
  101558. + struct snd_pcm *pcm;
  101559. + struct snd_pcm *pcm_spdif;
  101560. + /* Bitmat for valid reg_base and irq numbers */
  101561. + uint32_t avail_substreams;
  101562. + struct platform_device *pdev[MAX_SUBSTREAMS];
  101563. + struct bcm2835_alsa_stream *alsa_stream[MAX_SUBSTREAMS];
  101564. +
  101565. + int volume;
  101566. + int old_volume; /* stores the volume value whist muted */
  101567. + int dest;
  101568. + int mute;
  101569. +
  101570. + unsigned int opened;
  101571. + unsigned int spdif_status;
  101572. +} bcm2835_chip_t;
  101573. +
  101574. +typedef struct bcm2835_alsa_stream {
  101575. + bcm2835_chip_t *chip;
  101576. + struct snd_pcm_substream *substream;
  101577. + struct snd_pcm_indirect pcm_indirect;
  101578. +
  101579. + struct semaphore buffers_update_sem;
  101580. + struct semaphore control_sem;
  101581. + spinlock_t lock;
  101582. + volatile uint32_t control;
  101583. + volatile uint32_t status;
  101584. +
  101585. + int open;
  101586. + int running;
  101587. + int draining;
  101588. +
  101589. + int channels;
  101590. + int params_rate;
  101591. + int pcm_format_width;
  101592. +
  101593. + unsigned int pos;
  101594. + unsigned int buffer_size;
  101595. + unsigned int period_size;
  101596. +
  101597. + uint32_t enable_fifo_irq;
  101598. + irq_handler_t fifo_irq_handler;
  101599. +
  101600. + atomic_t retrieved;
  101601. + struct opaque_AUDIO_INSTANCE_T *instance;
  101602. + struct workqueue_struct *my_wq;
  101603. + int idx;
  101604. +} bcm2835_alsa_stream_t;
  101605. +
  101606. +int snd_bcm2835_new_ctl(bcm2835_chip_t * chip);
  101607. +int snd_bcm2835_new_pcm(bcm2835_chip_t * chip);
  101608. +int snd_bcm2835_new_spdif_pcm(bcm2835_chip_t * chip);
  101609. +
  101610. +int bcm2835_audio_open(bcm2835_alsa_stream_t * alsa_stream);
  101611. +int bcm2835_audio_close(bcm2835_alsa_stream_t * alsa_stream);
  101612. +int bcm2835_audio_set_params(bcm2835_alsa_stream_t * alsa_stream,
  101613. + uint32_t channels, uint32_t samplerate,
  101614. + uint32_t bps);
  101615. +int bcm2835_audio_setup(bcm2835_alsa_stream_t * alsa_stream);
  101616. +int bcm2835_audio_start(bcm2835_alsa_stream_t * alsa_stream);
  101617. +int bcm2835_audio_stop(bcm2835_alsa_stream_t * alsa_stream);
  101618. +int bcm2835_audio_set_ctls(bcm2835_chip_t * chip);
  101619. +int bcm2835_audio_write(bcm2835_alsa_stream_t * alsa_stream, uint32_t count,
  101620. + void *src);
  101621. +uint32_t bcm2835_audio_retrieve_buffers(bcm2835_alsa_stream_t * alsa_stream);
  101622. +void bcm2835_audio_flush_buffers(bcm2835_alsa_stream_t * alsa_stream);
  101623. +void bcm2835_audio_flush_playback_buffers(bcm2835_alsa_stream_t * alsa_stream);
  101624. +
  101625. +#endif /* __SOUND_ARM_BCM2835_H */
  101626. diff -Nur linux-3.12.26.orig/sound/arm/bcm2835-pcm.c linux-3.12.26/sound/arm/bcm2835-pcm.c
  101627. --- linux-3.12.26.orig/sound/arm/bcm2835-pcm.c 1970-01-01 01:00:00.000000000 +0100
  101628. +++ linux-3.12.26/sound/arm/bcm2835-pcm.c 2014-08-06 16:50:15.165967585 +0200
  101629. @@ -0,0 +1,518 @@
  101630. +/*****************************************************************************
  101631. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  101632. +*
  101633. +* Unless you and Broadcom execute a separate written software license
  101634. +* agreement governing use of this software, this software is licensed to you
  101635. +* under the terms of the GNU General Public License version 2, available at
  101636. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  101637. +*
  101638. +* Notwithstanding the above, under no circumstances may you combine this
  101639. +* software in any way with any other Broadcom software provided under a
  101640. +* license other than the GPL, without Broadcom's express prior written
  101641. +* consent.
  101642. +*****************************************************************************/
  101643. +
  101644. +#include <linux/interrupt.h>
  101645. +#include <linux/slab.h>
  101646. +
  101647. +#include <sound/asoundef.h>
  101648. +
  101649. +#include "bcm2835.h"
  101650. +
  101651. +/* hardware definition */
  101652. +static struct snd_pcm_hardware snd_bcm2835_playback_hw = {
  101653. + .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
  101654. + SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID),
  101655. + .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
  101656. + .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
  101657. + .rate_min = 8000,
  101658. + .rate_max = 48000,
  101659. + .channels_min = 1,
  101660. + .channels_max = 2,
  101661. + .buffer_bytes_max = 128 * 1024,
  101662. + .period_bytes_min = 1 * 1024,
  101663. + .period_bytes_max = 128 * 1024,
  101664. + .periods_min = 1,
  101665. + .periods_max = 128,
  101666. +};
  101667. +
  101668. +static struct snd_pcm_hardware snd_bcm2835_playback_spdif_hw = {
  101669. + .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
  101670. + SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID),
  101671. + .formats = SNDRV_PCM_FMTBIT_S16_LE,
  101672. + .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_44100 |
  101673. + SNDRV_PCM_RATE_48000,
  101674. + .rate_min = 44100,
  101675. + .rate_max = 48000,
  101676. + .channels_min = 2,
  101677. + .channels_max = 2,
  101678. + .buffer_bytes_max = 128 * 1024,
  101679. + .period_bytes_min = 1 * 1024,
  101680. + .period_bytes_max = 128 * 1024,
  101681. + .periods_min = 1,
  101682. + .periods_max = 128,
  101683. +};
  101684. +
  101685. +static void snd_bcm2835_playback_free(struct snd_pcm_runtime *runtime)
  101686. +{
  101687. + audio_info("Freeing up alsa stream here ..\n");
  101688. + if (runtime->private_data)
  101689. + kfree(runtime->private_data);
  101690. + runtime->private_data = NULL;
  101691. +}
  101692. +
  101693. +static irqreturn_t bcm2835_playback_fifo_irq(int irq, void *dev_id)
  101694. +{
  101695. + bcm2835_alsa_stream_t *alsa_stream = (bcm2835_alsa_stream_t *) dev_id;
  101696. + uint32_t consumed = 0;
  101697. + int new_period = 0;
  101698. +
  101699. + audio_info(" .. IN\n");
  101700. +
  101701. + audio_info("alsa_stream=%p substream=%p\n", alsa_stream,
  101702. + alsa_stream ? alsa_stream->substream : 0);
  101703. +
  101704. + if (alsa_stream->open)
  101705. + consumed = bcm2835_audio_retrieve_buffers(alsa_stream);
  101706. +
  101707. + /* We get called only if playback was triggered, So, the number of buffers we retrieve in
  101708. + * each iteration are the buffers that have been played out already
  101709. + */
  101710. +
  101711. + if (alsa_stream->period_size) {
  101712. + if ((alsa_stream->pos / alsa_stream->period_size) !=
  101713. + ((alsa_stream->pos + consumed) / alsa_stream->period_size))
  101714. + new_period = 1;
  101715. + }
  101716. + audio_debug("updating pos cur: %d + %d max:%d period_bytes:%d, hw_ptr: %d new_period:%d\n",
  101717. + alsa_stream->pos,
  101718. + consumed,
  101719. + alsa_stream->buffer_size,
  101720. + (int)(alsa_stream->period_size*alsa_stream->substream->runtime->periods),
  101721. + frames_to_bytes(alsa_stream->substream->runtime, alsa_stream->substream->runtime->status->hw_ptr),
  101722. + new_period);
  101723. + if (alsa_stream->buffer_size) {
  101724. + alsa_stream->pos += consumed &~ (1<<30);
  101725. + alsa_stream->pos %= alsa_stream->buffer_size;
  101726. + }
  101727. +
  101728. + if (alsa_stream->substream) {
  101729. + if (new_period)
  101730. + snd_pcm_period_elapsed(alsa_stream->substream);
  101731. + } else {
  101732. + audio_warning(" unexpected NULL substream\n");
  101733. + }
  101734. + audio_info(" .. OUT\n");
  101735. +
  101736. + return IRQ_HANDLED;
  101737. +}
  101738. +
  101739. +/* open callback */
  101740. +static int snd_bcm2835_playback_open_generic(
  101741. + struct snd_pcm_substream *substream, int spdif)
  101742. +{
  101743. + bcm2835_chip_t *chip = snd_pcm_substream_chip(substream);
  101744. + struct snd_pcm_runtime *runtime = substream->runtime;
  101745. + bcm2835_alsa_stream_t *alsa_stream;
  101746. + int idx;
  101747. + int err;
  101748. +
  101749. + audio_info(" .. IN (%d)\n", substream->number);
  101750. +
  101751. + audio_info("Alsa open (%d)\n", substream->number);
  101752. + idx = substream->number;
  101753. +
  101754. + if (spdif && chip->opened != 0)
  101755. + return -EBUSY;
  101756. + else if (!spdif && (chip->opened & (1 << idx)))
  101757. + return -EBUSY;
  101758. +
  101759. + if (idx > MAX_SUBSTREAMS) {
  101760. + audio_error
  101761. + ("substream(%d) device doesn't exist max(%d) substreams allowed\n",
  101762. + idx, MAX_SUBSTREAMS);
  101763. + err = -ENODEV;
  101764. + goto out;
  101765. + }
  101766. +
  101767. + /* Check if we are ready */
  101768. + if (!(chip->avail_substreams & (1 << idx))) {
  101769. + /* We are not ready yet */
  101770. + audio_error("substream(%d) device is not ready yet\n", idx);
  101771. + err = -EAGAIN;
  101772. + goto out;
  101773. + }
  101774. +
  101775. + alsa_stream = kzalloc(sizeof(bcm2835_alsa_stream_t), GFP_KERNEL);
  101776. + if (alsa_stream == NULL) {
  101777. + return -ENOMEM;
  101778. + }
  101779. +
  101780. + /* Initialise alsa_stream */
  101781. + alsa_stream->chip = chip;
  101782. + alsa_stream->substream = substream;
  101783. + alsa_stream->idx = idx;
  101784. +
  101785. + sema_init(&alsa_stream->buffers_update_sem, 0);
  101786. + sema_init(&alsa_stream->control_sem, 0);
  101787. + spin_lock_init(&alsa_stream->lock);
  101788. +
  101789. + /* Enabled in start trigger, called on each "fifo irq" after that */
  101790. + alsa_stream->enable_fifo_irq = 0;
  101791. + alsa_stream->fifo_irq_handler = bcm2835_playback_fifo_irq;
  101792. +
  101793. + runtime->private_data = alsa_stream;
  101794. + runtime->private_free = snd_bcm2835_playback_free;
  101795. + if (spdif) {
  101796. + runtime->hw = snd_bcm2835_playback_spdif_hw;
  101797. + } else {
  101798. + /* clear spdif status, as we are not in spdif mode */
  101799. + chip->spdif_status = 0;
  101800. + runtime->hw = snd_bcm2835_playback_hw;
  101801. + }
  101802. + /* minimum 16 bytes alignment (for vchiq bulk transfers) */
  101803. + snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
  101804. + 16);
  101805. +
  101806. + err = bcm2835_audio_open(alsa_stream);
  101807. + if (err != 0) {
  101808. + kfree(alsa_stream);
  101809. + return err;
  101810. + }
  101811. + chip->alsa_stream[idx] = alsa_stream;
  101812. +
  101813. + chip->opened |= (1 << idx);
  101814. + alsa_stream->open = 1;
  101815. + alsa_stream->draining = 1;
  101816. +
  101817. +out:
  101818. + audio_info(" .. OUT =%d\n", err);
  101819. +
  101820. + return err;
  101821. +}
  101822. +
  101823. +static int snd_bcm2835_playback_open(struct snd_pcm_substream *substream)
  101824. +{
  101825. + return snd_bcm2835_playback_open_generic(substream, 0);
  101826. +}
  101827. +
  101828. +static int snd_bcm2835_playback_spdif_open(struct snd_pcm_substream *substream)
  101829. +{
  101830. + return snd_bcm2835_playback_open_generic(substream, 1);
  101831. +}
  101832. +
  101833. +/* close callback */
  101834. +static int snd_bcm2835_playback_close(struct snd_pcm_substream *substream)
  101835. +{
  101836. + /* the hardware-specific codes will be here */
  101837. +
  101838. + struct snd_pcm_runtime *runtime = substream->runtime;
  101839. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  101840. + bcm2835_chip_t *chip = snd_pcm_substream_chip(substream);
  101841. +
  101842. + audio_info(" .. IN\n");
  101843. + audio_info("Alsa close\n");
  101844. +
  101845. + /*
  101846. + * Call stop if it's still running. This happens when app
  101847. + * is force killed and we don't get a stop trigger.
  101848. + */
  101849. + if (alsa_stream->running) {
  101850. + int err;
  101851. + err = bcm2835_audio_stop(alsa_stream);
  101852. + alsa_stream->running = 0;
  101853. + if (err != 0)
  101854. + audio_error(" Failed to STOP alsa device\n");
  101855. + }
  101856. +
  101857. + alsa_stream->period_size = 0;
  101858. + alsa_stream->buffer_size = 0;
  101859. +
  101860. + if (alsa_stream->open) {
  101861. + alsa_stream->open = 0;
  101862. + bcm2835_audio_close(alsa_stream);
  101863. + }
  101864. + if (alsa_stream->chip)
  101865. + alsa_stream->chip->alsa_stream[alsa_stream->idx] = NULL;
  101866. + /*
  101867. + * Do not free up alsa_stream here, it will be freed up by
  101868. + * runtime->private_free callback we registered in *_open above
  101869. + */
  101870. +
  101871. + chip->opened &= ~(1 << substream->number);
  101872. +
  101873. + audio_info(" .. OUT\n");
  101874. +
  101875. + return 0;
  101876. +}
  101877. +
  101878. +/* hw_params callback */
  101879. +static int snd_bcm2835_pcm_hw_params(struct snd_pcm_substream *substream,
  101880. + struct snd_pcm_hw_params *params)
  101881. +{
  101882. + struct snd_pcm_runtime *runtime = substream->runtime;
  101883. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  101884. + int err;
  101885. +
  101886. + audio_info(" .. IN\n");
  101887. +
  101888. + err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
  101889. + if (err < 0) {
  101890. + audio_error
  101891. + (" pcm_lib_malloc failed to allocated pages for buffers\n");
  101892. + return err;
  101893. + }
  101894. +
  101895. + alsa_stream->channels = params_channels(params);
  101896. + alsa_stream->params_rate = params_rate(params);
  101897. + alsa_stream->pcm_format_width = snd_pcm_format_width(params_format (params));
  101898. + audio_info(" .. OUT\n");
  101899. +
  101900. + return err;
  101901. +}
  101902. +
  101903. +/* hw_free callback */
  101904. +static int snd_bcm2835_pcm_hw_free(struct snd_pcm_substream *substream)
  101905. +{
  101906. + audio_info(" .. IN\n");
  101907. + return snd_pcm_lib_free_pages(substream);
  101908. +}
  101909. +
  101910. +/* prepare callback */
  101911. +static int snd_bcm2835_pcm_prepare(struct snd_pcm_substream *substream)
  101912. +{
  101913. + bcm2835_chip_t *chip = snd_pcm_substream_chip(substream);
  101914. + struct snd_pcm_runtime *runtime = substream->runtime;
  101915. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  101916. + int channels;
  101917. + int err;
  101918. +
  101919. + audio_info(" .. IN\n");
  101920. +
  101921. + /* notify the vchiq that it should enter spdif passthrough mode by
  101922. + * setting channels=0 (see
  101923. + * https://github.com/raspberrypi/linux/issues/528) */
  101924. + if (chip->spdif_status & IEC958_AES0_NONAUDIO)
  101925. + channels = 0;
  101926. + else
  101927. + channels = alsa_stream->channels;
  101928. +
  101929. + err = bcm2835_audio_set_params(alsa_stream, channels,
  101930. + alsa_stream->params_rate,
  101931. + alsa_stream->pcm_format_width);
  101932. + if (err < 0) {
  101933. + audio_error(" error setting hw params\n");
  101934. + }
  101935. +
  101936. + bcm2835_audio_setup(alsa_stream);
  101937. +
  101938. + /* in preparation of the stream, set the controls (volume level) of the stream */
  101939. + bcm2835_audio_set_ctls(alsa_stream->chip);
  101940. +
  101941. +
  101942. + memset(&alsa_stream->pcm_indirect, 0, sizeof(alsa_stream->pcm_indirect));
  101943. +
  101944. + alsa_stream->pcm_indirect.hw_buffer_size =
  101945. + alsa_stream->pcm_indirect.sw_buffer_size =
  101946. + snd_pcm_lib_buffer_bytes(substream);
  101947. +
  101948. + alsa_stream->buffer_size = snd_pcm_lib_buffer_bytes(substream);
  101949. + alsa_stream->period_size = snd_pcm_lib_period_bytes(substream);
  101950. + alsa_stream->pos = 0;
  101951. +
  101952. + audio_debug("buffer_size=%d, period_size=%d pos=%d frame_bits=%d\n",
  101953. + alsa_stream->buffer_size, alsa_stream->period_size,
  101954. + alsa_stream->pos, runtime->frame_bits);
  101955. +
  101956. + audio_info(" .. OUT\n");
  101957. + return 0;
  101958. +}
  101959. +
  101960. +static void snd_bcm2835_pcm_transfer(struct snd_pcm_substream *substream,
  101961. + struct snd_pcm_indirect *rec, size_t bytes)
  101962. +{
  101963. + struct snd_pcm_runtime *runtime = substream->runtime;
  101964. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  101965. + void *src = (void *)(substream->runtime->dma_area + rec->sw_data);
  101966. + int err;
  101967. +
  101968. + err = bcm2835_audio_write(alsa_stream, bytes, src);
  101969. + if (err)
  101970. + audio_error(" Failed to transfer to alsa device (%d)\n", err);
  101971. +
  101972. +}
  101973. +
  101974. +static int snd_bcm2835_pcm_ack(struct snd_pcm_substream *substream)
  101975. +{
  101976. + struct snd_pcm_runtime *runtime = substream->runtime;
  101977. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  101978. + struct snd_pcm_indirect *pcm_indirect = &alsa_stream->pcm_indirect;
  101979. +
  101980. + pcm_indirect->hw_queue_size = runtime->hw.buffer_bytes_max;
  101981. + snd_pcm_indirect_playback_transfer(substream, pcm_indirect,
  101982. + snd_bcm2835_pcm_transfer);
  101983. + return 0;
  101984. +}
  101985. +
  101986. +/* trigger callback */
  101987. +static int snd_bcm2835_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
  101988. +{
  101989. + struct snd_pcm_runtime *runtime = substream->runtime;
  101990. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  101991. + int err = 0;
  101992. +
  101993. + audio_info(" .. IN\n");
  101994. +
  101995. + switch (cmd) {
  101996. + case SNDRV_PCM_TRIGGER_START:
  101997. + audio_debug("bcm2835_AUDIO_TRIGGER_START running=%d\n",
  101998. + alsa_stream->running);
  101999. + if (!alsa_stream->running) {
  102000. + err = bcm2835_audio_start(alsa_stream);
  102001. + if (err == 0) {
  102002. + alsa_stream->pcm_indirect.hw_io =
  102003. + alsa_stream->pcm_indirect.hw_data =
  102004. + bytes_to_frames(runtime,
  102005. + alsa_stream->pos);
  102006. + substream->ops->ack(substream);
  102007. + alsa_stream->running = 1;
  102008. + alsa_stream->draining = 1;
  102009. + } else {
  102010. + audio_error(" Failed to START alsa device (%d)\n", err);
  102011. + }
  102012. + }
  102013. + break;
  102014. + case SNDRV_PCM_TRIGGER_STOP:
  102015. + audio_debug
  102016. + ("bcm2835_AUDIO_TRIGGER_STOP running=%d draining=%d\n",
  102017. + alsa_stream->running, runtime->status->state == SNDRV_PCM_STATE_DRAINING);
  102018. + if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
  102019. + audio_info("DRAINING\n");
  102020. + alsa_stream->draining = 1;
  102021. + } else {
  102022. + audio_info("DROPPING\n");
  102023. + alsa_stream->draining = 0;
  102024. + }
  102025. + if (alsa_stream->running) {
  102026. + err = bcm2835_audio_stop(alsa_stream);
  102027. + if (err != 0)
  102028. + audio_error(" Failed to STOP alsa device (%d)\n", err);
  102029. + alsa_stream->running = 0;
  102030. + }
  102031. + break;
  102032. + default:
  102033. + err = -EINVAL;
  102034. + }
  102035. +
  102036. + audio_info(" .. OUT\n");
  102037. + return err;
  102038. +}
  102039. +
  102040. +/* pointer callback */
  102041. +static snd_pcm_uframes_t
  102042. +snd_bcm2835_pcm_pointer(struct snd_pcm_substream *substream)
  102043. +{
  102044. + struct snd_pcm_runtime *runtime = substream->runtime;
  102045. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  102046. +
  102047. + audio_info(" .. IN\n");
  102048. +
  102049. + audio_debug("pcm_pointer... (%d) hwptr=%d appl=%d pos=%d\n", 0,
  102050. + frames_to_bytes(runtime, runtime->status->hw_ptr),
  102051. + frames_to_bytes(runtime, runtime->control->appl_ptr),
  102052. + alsa_stream->pos);
  102053. +
  102054. + audio_info(" .. OUT\n");
  102055. + return snd_pcm_indirect_playback_pointer(substream,
  102056. + &alsa_stream->pcm_indirect,
  102057. + alsa_stream->pos);
  102058. +}
  102059. +
  102060. +static int snd_bcm2835_pcm_lib_ioctl(struct snd_pcm_substream *substream,
  102061. + unsigned int cmd, void *arg)
  102062. +{
  102063. + int ret = snd_pcm_lib_ioctl(substream, cmd, arg);
  102064. + audio_info(" .. substream=%p, cmd=%d, arg=%p (%x) ret=%d\n", substream,
  102065. + cmd, arg, arg ? *(unsigned *)arg : 0, ret);
  102066. + return ret;
  102067. +}
  102068. +
  102069. +/* operators */
  102070. +static struct snd_pcm_ops snd_bcm2835_playback_ops = {
  102071. + .open = snd_bcm2835_playback_open,
  102072. + .close = snd_bcm2835_playback_close,
  102073. + .ioctl = snd_bcm2835_pcm_lib_ioctl,
  102074. + .hw_params = snd_bcm2835_pcm_hw_params,
  102075. + .hw_free = snd_bcm2835_pcm_hw_free,
  102076. + .prepare = snd_bcm2835_pcm_prepare,
  102077. + .trigger = snd_bcm2835_pcm_trigger,
  102078. + .pointer = snd_bcm2835_pcm_pointer,
  102079. + .ack = snd_bcm2835_pcm_ack,
  102080. +};
  102081. +
  102082. +static struct snd_pcm_ops snd_bcm2835_playback_spdif_ops = {
  102083. + .open = snd_bcm2835_playback_spdif_open,
  102084. + .close = snd_bcm2835_playback_close,
  102085. + .ioctl = snd_bcm2835_pcm_lib_ioctl,
  102086. + .hw_params = snd_bcm2835_pcm_hw_params,
  102087. + .hw_free = snd_bcm2835_pcm_hw_free,
  102088. + .prepare = snd_bcm2835_pcm_prepare,
  102089. + .trigger = snd_bcm2835_pcm_trigger,
  102090. + .pointer = snd_bcm2835_pcm_pointer,
  102091. + .ack = snd_bcm2835_pcm_ack,
  102092. +};
  102093. +
  102094. +/* create a pcm device */
  102095. +int snd_bcm2835_new_pcm(bcm2835_chip_t * chip)
  102096. +{
  102097. + struct snd_pcm *pcm;
  102098. + int err;
  102099. +
  102100. + audio_info(" .. IN\n");
  102101. + err =
  102102. + snd_pcm_new(chip->card, "bcm2835 ALSA", 0, MAX_SUBSTREAMS, 0, &pcm);
  102103. + if (err < 0)
  102104. + return err;
  102105. + pcm->private_data = chip;
  102106. + strcpy(pcm->name, "bcm2835 ALSA");
  102107. + chip->pcm = pcm;
  102108. + chip->dest = AUDIO_DEST_AUTO;
  102109. + chip->volume = alsa2chip(0);
  102110. + chip->mute = CTRL_VOL_UNMUTE; /*disable mute on startup */
  102111. + /* set operators */
  102112. + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
  102113. + &snd_bcm2835_playback_ops);
  102114. +
  102115. + /* pre-allocation of buffers */
  102116. + /* NOTE: this may fail */
  102117. + snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
  102118. + snd_dma_continuous_data
  102119. + (GFP_KERNEL), 64 * 1024,
  102120. + 64 * 1024);
  102121. +
  102122. + audio_info(" .. OUT\n");
  102123. +
  102124. + return 0;
  102125. +}
  102126. +
  102127. +int snd_bcm2835_new_spdif_pcm(bcm2835_chip_t * chip)
  102128. +{
  102129. + struct snd_pcm *pcm;
  102130. + int err;
  102131. +
  102132. + err = snd_pcm_new(chip->card, "bcm2835 ALSA", 1, 1, 0, &pcm);
  102133. + if (err < 0)
  102134. + return err;
  102135. +
  102136. + pcm->private_data = chip;
  102137. + strcpy(pcm->name, "bcm2835 IEC958/HDMI");
  102138. + chip->pcm_spdif = pcm;
  102139. + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
  102140. + &snd_bcm2835_playback_spdif_ops);
  102141. +
  102142. + snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
  102143. + snd_dma_continuous_data (GFP_KERNEL),
  102144. + 64 * 1024, 64 * 1024);
  102145. +
  102146. + return 0;
  102147. +}
  102148. diff -Nur linux-3.12.26.orig/sound/arm/bcm2835-vchiq.c linux-3.12.26/sound/arm/bcm2835-vchiq.c
  102149. --- linux-3.12.26.orig/sound/arm/bcm2835-vchiq.c 1970-01-01 01:00:00.000000000 +0100
  102150. +++ linux-3.12.26/sound/arm/bcm2835-vchiq.c 2014-08-06 16:50:15.165967585 +0200
  102151. @@ -0,0 +1,879 @@
  102152. +/*****************************************************************************
  102153. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  102154. +*
  102155. +* Unless you and Broadcom execute a separate written software license
  102156. +* agreement governing use of this software, this software is licensed to you
  102157. +* under the terms of the GNU General Public License version 2, available at
  102158. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  102159. +*
  102160. +* Notwithstanding the above, under no circumstances may you combine this
  102161. +* software in any way with any other Broadcom software provided under a
  102162. +* license other than the GPL, without Broadcom's express prior written
  102163. +* consent.
  102164. +*****************************************************************************/
  102165. +
  102166. +#include <linux/device.h>
  102167. +#include <sound/core.h>
  102168. +#include <sound/initval.h>
  102169. +#include <sound/pcm.h>
  102170. +#include <linux/io.h>
  102171. +#include <linux/interrupt.h>
  102172. +#include <linux/fs.h>
  102173. +#include <linux/file.h>
  102174. +#include <linux/mm.h>
  102175. +#include <linux/syscalls.h>
  102176. +#include <asm/uaccess.h>
  102177. +#include <linux/slab.h>
  102178. +#include <linux/delay.h>
  102179. +#include <linux/atomic.h>
  102180. +#include <linux/module.h>
  102181. +#include <linux/completion.h>
  102182. +
  102183. +#include "bcm2835.h"
  102184. +
  102185. +/* ---- Include Files -------------------------------------------------------- */
  102186. +
  102187. +#include "interface/vchi/vchi.h"
  102188. +#include "vc_vchi_audioserv_defs.h"
  102189. +
  102190. +/* ---- Private Constants and Types ------------------------------------------ */
  102191. +
  102192. +#define BCM2835_AUDIO_STOP 0
  102193. +#define BCM2835_AUDIO_START 1
  102194. +#define BCM2835_AUDIO_WRITE 2
  102195. +
  102196. +/* Logging macros (for remapping to other logging mechanisms, i.e., printf) */
  102197. +#ifdef AUDIO_DEBUG_ENABLE
  102198. + #define LOG_ERR( fmt, arg... ) pr_err( "%s:%d " fmt, __func__, __LINE__, ##arg)
  102199. + #define LOG_WARN( fmt, arg... ) pr_info( "%s:%d " fmt, __func__, __LINE__, ##arg)
  102200. + #define LOG_INFO( fmt, arg... ) pr_info( "%s:%d " fmt, __func__, __LINE__, ##arg)
  102201. + #define LOG_DBG( fmt, arg... ) pr_info( "%s:%d " fmt, __func__, __LINE__, ##arg)
  102202. +#else
  102203. + #define LOG_ERR( fmt, arg... ) pr_err( "%s:%d " fmt, __func__, __LINE__, ##arg)
  102204. + #define LOG_WARN( fmt, arg... )
  102205. + #define LOG_INFO( fmt, arg... )
  102206. + #define LOG_DBG( fmt, arg... )
  102207. +#endif
  102208. +
  102209. +typedef struct opaque_AUDIO_INSTANCE_T {
  102210. + uint32_t num_connections;
  102211. + VCHI_SERVICE_HANDLE_T vchi_handle[VCHI_MAX_NUM_CONNECTIONS];
  102212. + struct completion msg_avail_comp;
  102213. + struct mutex vchi_mutex;
  102214. + bcm2835_alsa_stream_t *alsa_stream;
  102215. + int32_t result;
  102216. + short peer_version;
  102217. +} AUDIO_INSTANCE_T;
  102218. +
  102219. +bool force_bulk = false;
  102220. +
  102221. +/* ---- Private Variables ---------------------------------------------------- */
  102222. +
  102223. +/* ---- Private Function Prototypes ------------------------------------------ */
  102224. +
  102225. +/* ---- Private Functions ---------------------------------------------------- */
  102226. +
  102227. +static int bcm2835_audio_stop_worker(bcm2835_alsa_stream_t * alsa_stream);
  102228. +static int bcm2835_audio_start_worker(bcm2835_alsa_stream_t * alsa_stream);
  102229. +static int bcm2835_audio_write_worker(bcm2835_alsa_stream_t *alsa_stream,
  102230. + uint32_t count, void *src);
  102231. +
  102232. +typedef struct {
  102233. + struct work_struct my_work;
  102234. + bcm2835_alsa_stream_t *alsa_stream;
  102235. + int cmd;
  102236. + void *src;
  102237. + uint32_t count;
  102238. +} my_work_t;
  102239. +
  102240. +static void my_wq_function(struct work_struct *work)
  102241. +{
  102242. + my_work_t *w = (my_work_t *) work;
  102243. + int ret = -9;
  102244. + LOG_DBG(" .. IN %p:%d\n", w->alsa_stream, w->cmd);
  102245. + switch (w->cmd) {
  102246. + case BCM2835_AUDIO_START:
  102247. + ret = bcm2835_audio_start_worker(w->alsa_stream);
  102248. + break;
  102249. + case BCM2835_AUDIO_STOP:
  102250. + ret = bcm2835_audio_stop_worker(w->alsa_stream);
  102251. + break;
  102252. + case BCM2835_AUDIO_WRITE:
  102253. + ret = bcm2835_audio_write_worker(w->alsa_stream, w->count,
  102254. + w->src);
  102255. + break;
  102256. + default:
  102257. + LOG_ERR(" Unexpected work: %p:%d\n", w->alsa_stream, w->cmd);
  102258. + break;
  102259. + }
  102260. + kfree((void *)work);
  102261. + LOG_DBG(" .. OUT %d\n", ret);
  102262. +}
  102263. +
  102264. +int bcm2835_audio_start(bcm2835_alsa_stream_t * alsa_stream)
  102265. +{
  102266. + int ret = -1;
  102267. + LOG_DBG(" .. IN\n");
  102268. + if (alsa_stream->my_wq) {
  102269. + my_work_t *work = kmalloc(sizeof(my_work_t), GFP_ATOMIC);
  102270. + /*--- Queue some work (item 1) ---*/
  102271. + if (work) {
  102272. + INIT_WORK((struct work_struct *)work, my_wq_function);
  102273. + work->alsa_stream = alsa_stream;
  102274. + work->cmd = BCM2835_AUDIO_START;
  102275. + if (queue_work
  102276. + (alsa_stream->my_wq, (struct work_struct *)work))
  102277. + ret = 0;
  102278. + } else
  102279. + LOG_ERR(" .. Error: NULL work kmalloc\n");
  102280. + }
  102281. + LOG_DBG(" .. OUT %d\n", ret);
  102282. + return ret;
  102283. +}
  102284. +
  102285. +int bcm2835_audio_stop(bcm2835_alsa_stream_t * alsa_stream)
  102286. +{
  102287. + int ret = -1;
  102288. + LOG_DBG(" .. IN\n");
  102289. + if (alsa_stream->my_wq) {
  102290. + my_work_t *work = kmalloc(sizeof(my_work_t), GFP_ATOMIC);
  102291. + /*--- Queue some work (item 1) ---*/
  102292. + if (work) {
  102293. + INIT_WORK((struct work_struct *)work, my_wq_function);
  102294. + work->alsa_stream = alsa_stream;
  102295. + work->cmd = BCM2835_AUDIO_STOP;
  102296. + if (queue_work
  102297. + (alsa_stream->my_wq, (struct work_struct *)work))
  102298. + ret = 0;
  102299. + } else
  102300. + LOG_ERR(" .. Error: NULL work kmalloc\n");
  102301. + }
  102302. + LOG_DBG(" .. OUT %d\n", ret);
  102303. + return ret;
  102304. +}
  102305. +
  102306. +int bcm2835_audio_write(bcm2835_alsa_stream_t *alsa_stream,
  102307. + uint32_t count, void *src)
  102308. +{
  102309. + int ret = -1;
  102310. + LOG_DBG(" .. IN\n");
  102311. + if (alsa_stream->my_wq) {
  102312. + my_work_t *work = kmalloc(sizeof(my_work_t), GFP_ATOMIC);
  102313. + /*--- Queue some work (item 1) ---*/
  102314. + if (work) {
  102315. + INIT_WORK((struct work_struct *)work, my_wq_function);
  102316. + work->alsa_stream = alsa_stream;
  102317. + work->cmd = BCM2835_AUDIO_WRITE;
  102318. + work->src = src;
  102319. + work->count = count;
  102320. + if (queue_work
  102321. + (alsa_stream->my_wq, (struct work_struct *)work))
  102322. + ret = 0;
  102323. + } else
  102324. + LOG_ERR(" .. Error: NULL work kmalloc\n");
  102325. + }
  102326. + LOG_DBG(" .. OUT %d\n", ret);
  102327. + return ret;
  102328. +}
  102329. +
  102330. +void my_workqueue_init(bcm2835_alsa_stream_t * alsa_stream)
  102331. +{
  102332. + alsa_stream->my_wq = alloc_workqueue("my_queue", WQ_HIGHPRI, 1);
  102333. + return;
  102334. +}
  102335. +
  102336. +void my_workqueue_quit(bcm2835_alsa_stream_t * alsa_stream)
  102337. +{
  102338. + if (alsa_stream->my_wq) {
  102339. + flush_workqueue(alsa_stream->my_wq);
  102340. + destroy_workqueue(alsa_stream->my_wq);
  102341. + alsa_stream->my_wq = NULL;
  102342. + }
  102343. + return;
  102344. +}
  102345. +
  102346. +static void audio_vchi_callback(void *param,
  102347. + const VCHI_CALLBACK_REASON_T reason,
  102348. + void *msg_handle)
  102349. +{
  102350. + AUDIO_INSTANCE_T *instance = (AUDIO_INSTANCE_T *) param;
  102351. + int32_t status;
  102352. + int32_t msg_len;
  102353. + VC_AUDIO_MSG_T m;
  102354. + bcm2835_alsa_stream_t *alsa_stream = 0;
  102355. + LOG_DBG(" .. IN instance=%p, param=%p, reason=%d, handle=%p\n",
  102356. + instance, param, reason, msg_handle);
  102357. +
  102358. + if (!instance || reason != VCHI_CALLBACK_MSG_AVAILABLE) {
  102359. + return;
  102360. + }
  102361. + alsa_stream = instance->alsa_stream;
  102362. + status = vchi_msg_dequeue(instance->vchi_handle[0],
  102363. + &m, sizeof m, &msg_len, VCHI_FLAGS_NONE);
  102364. + if (m.type == VC_AUDIO_MSG_TYPE_RESULT) {
  102365. + LOG_DBG
  102366. + (" .. instance=%p, m.type=VC_AUDIO_MSG_TYPE_RESULT, success=%d\n",
  102367. + instance, m.u.result.success);
  102368. + instance->result = m.u.result.success;
  102369. + complete(&instance->msg_avail_comp);
  102370. + } else if (m.type == VC_AUDIO_MSG_TYPE_COMPLETE) {
  102371. + irq_handler_t callback = (irq_handler_t) m.u.complete.callback;
  102372. + LOG_DBG
  102373. + (" .. instance=%p, m.type=VC_AUDIO_MSG_TYPE_COMPLETE, complete=%d\n",
  102374. + instance, m.u.complete.count);
  102375. + if (alsa_stream && callback) {
  102376. + atomic_add(m.u.complete.count, &alsa_stream->retrieved);
  102377. + callback(0, alsa_stream);
  102378. + } else {
  102379. + LOG_DBG(" .. unexpected alsa_stream=%p, callback=%p\n",
  102380. + alsa_stream, callback);
  102381. + }
  102382. + } else {
  102383. + LOG_DBG(" .. unexpected m.type=%d\n", m.type);
  102384. + }
  102385. + LOG_DBG(" .. OUT\n");
  102386. +}
  102387. +
  102388. +static AUDIO_INSTANCE_T *vc_vchi_audio_init(VCHI_INSTANCE_T vchi_instance,
  102389. + VCHI_CONNECTION_T **
  102390. + vchi_connections,
  102391. + uint32_t num_connections)
  102392. +{
  102393. + uint32_t i;
  102394. + AUDIO_INSTANCE_T *instance;
  102395. + int status;
  102396. +
  102397. + LOG_DBG("%s: start", __func__);
  102398. +
  102399. + if (num_connections > VCHI_MAX_NUM_CONNECTIONS) {
  102400. + LOG_ERR("%s: unsupported number of connections %u (max=%u)\n",
  102401. + __func__, num_connections, VCHI_MAX_NUM_CONNECTIONS);
  102402. +
  102403. + return NULL;
  102404. + }
  102405. + /* Allocate memory for this instance */
  102406. + instance = kmalloc(sizeof(*instance), GFP_KERNEL);
  102407. +
  102408. + memset(instance, 0, sizeof(*instance));
  102409. + instance->num_connections = num_connections;
  102410. +
  102411. + /* Create a lock for exclusive, serialized VCHI connection access */
  102412. + mutex_init(&instance->vchi_mutex);
  102413. + /* Open the VCHI service connections */
  102414. + for (i = 0; i < num_connections; i++) {
  102415. + SERVICE_CREATION_T params = {
  102416. + VCHI_VERSION_EX(VC_AUDIOSERV_VER, VC_AUDIOSERV_MIN_VER),
  102417. + VC_AUDIO_SERVER_NAME, // 4cc service code
  102418. + vchi_connections[i], // passed in fn pointers
  102419. + 0, // rx fifo size (unused)
  102420. + 0, // tx fifo size (unused)
  102421. + audio_vchi_callback, // service callback
  102422. + instance, // service callback parameter
  102423. + 1, //TODO: remove VCOS_FALSE, // unaligned bulk recieves
  102424. + 1, //TODO: remove VCOS_FALSE, // unaligned bulk transmits
  102425. + 0 // want crc check on bulk transfers
  102426. + };
  102427. +
  102428. + status = vchi_service_open(vchi_instance, &params,
  102429. + &instance->vchi_handle[i]);
  102430. + if (status) {
  102431. + LOG_ERR
  102432. + ("%s: failed to open VCHI service connection (status=%d)\n",
  102433. + __func__, status);
  102434. +
  102435. + goto err_close_services;
  102436. + }
  102437. + /* Finished with the service for now */
  102438. + vchi_service_release(instance->vchi_handle[i]);
  102439. + }
  102440. +
  102441. + return instance;
  102442. +
  102443. +err_close_services:
  102444. + for (i = 0; i < instance->num_connections; i++) {
  102445. + vchi_service_close(instance->vchi_handle[i]);
  102446. + }
  102447. +
  102448. + kfree(instance);
  102449. +
  102450. + return NULL;
  102451. +}
  102452. +
  102453. +static int32_t vc_vchi_audio_deinit(AUDIO_INSTANCE_T * instance)
  102454. +{
  102455. + uint32_t i;
  102456. +
  102457. + LOG_DBG(" .. IN\n");
  102458. +
  102459. + if (instance == NULL) {
  102460. + LOG_ERR("%s: invalid handle %p\n", __func__, instance);
  102461. +
  102462. + return -1;
  102463. + }
  102464. +
  102465. + LOG_DBG(" .. about to lock (%d)\n", instance->num_connections);
  102466. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  102467. + {
  102468. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  102469. + return -EINTR;
  102470. + }
  102471. +
  102472. + /* Close all VCHI service connections */
  102473. + for (i = 0; i < instance->num_connections; i++) {
  102474. + int32_t success;
  102475. + LOG_DBG(" .. %i:closing %p\n", i, instance->vchi_handle[i]);
  102476. + vchi_service_use(instance->vchi_handle[i]);
  102477. +
  102478. + success = vchi_service_close(instance->vchi_handle[i]);
  102479. + if (success != 0) {
  102480. + LOG_ERR
  102481. + ("%s: failed to close VCHI service connection (status=%d)\n",
  102482. + __func__, success);
  102483. + }
  102484. + }
  102485. +
  102486. + mutex_unlock(&instance->vchi_mutex);
  102487. +
  102488. + kfree(instance);
  102489. +
  102490. + LOG_DBG(" .. OUT\n");
  102491. +
  102492. + return 0;
  102493. +}
  102494. +
  102495. +static int bcm2835_audio_open_connection(bcm2835_alsa_stream_t * alsa_stream)
  102496. +{
  102497. + static VCHI_INSTANCE_T vchi_instance;
  102498. + static VCHI_CONNECTION_T *vchi_connection;
  102499. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  102500. + int ret;
  102501. + LOG_DBG(" .. IN\n");
  102502. +
  102503. + LOG_INFO("%s: start", __func__);
  102504. + //BUG_ON(instance);
  102505. + if (instance) {
  102506. + LOG_ERR("%s: VCHI instance already open (%p)\n",
  102507. + __func__, instance);
  102508. + instance->alsa_stream = alsa_stream;
  102509. + alsa_stream->instance = instance;
  102510. + ret = 0; // xxx todo -1;
  102511. + goto err_free_mem;
  102512. + }
  102513. +
  102514. + /* Initialize and create a VCHI connection */
  102515. + ret = vchi_initialise(&vchi_instance);
  102516. + if (ret != 0) {
  102517. + LOG_ERR("%s: failed to initialise VCHI instance (ret=%d)\n",
  102518. + __func__, ret);
  102519. +
  102520. + ret = -EIO;
  102521. + goto err_free_mem;
  102522. + }
  102523. + ret = vchi_connect(NULL, 0, vchi_instance);
  102524. + if (ret != 0) {
  102525. + LOG_ERR("%s: failed to connect VCHI instance (ret=%d)\n",
  102526. + __func__, ret);
  102527. +
  102528. + ret = -EIO;
  102529. + goto err_free_mem;
  102530. + }
  102531. +
  102532. + /* Initialize an instance of the audio service */
  102533. + instance = vc_vchi_audio_init(vchi_instance, &vchi_connection, 1);
  102534. +
  102535. + if (instance == NULL /*|| audio_handle != instance */ ) {
  102536. + LOG_ERR("%s: failed to initialize audio service\n", __func__);
  102537. +
  102538. + ret = -EPERM;
  102539. + goto err_free_mem;
  102540. + }
  102541. +
  102542. + instance->alsa_stream = alsa_stream;
  102543. + alsa_stream->instance = instance;
  102544. +
  102545. + LOG_DBG(" success !\n");
  102546. +err_free_mem:
  102547. + LOG_DBG(" .. OUT\n");
  102548. +
  102549. + return ret;
  102550. +}
  102551. +
  102552. +int bcm2835_audio_open(bcm2835_alsa_stream_t * alsa_stream)
  102553. +{
  102554. + AUDIO_INSTANCE_T *instance;
  102555. + VC_AUDIO_MSG_T m;
  102556. + int32_t success;
  102557. + int ret;
  102558. + LOG_DBG(" .. IN\n");
  102559. +
  102560. + my_workqueue_init(alsa_stream);
  102561. +
  102562. + ret = bcm2835_audio_open_connection(alsa_stream);
  102563. + if (ret != 0) {
  102564. + ret = -1;
  102565. + goto exit;
  102566. + }
  102567. + instance = alsa_stream->instance;
  102568. +
  102569. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  102570. + {
  102571. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  102572. + return -EINTR;
  102573. + }
  102574. + vchi_service_use(instance->vchi_handle[0]);
  102575. +
  102576. + m.type = VC_AUDIO_MSG_TYPE_OPEN;
  102577. +
  102578. + /* Send the message to the videocore */
  102579. + success = vchi_msg_queue(instance->vchi_handle[0],
  102580. + &m, sizeof m,
  102581. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  102582. +
  102583. + if (success != 0) {
  102584. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  102585. + __func__, success);
  102586. +
  102587. + ret = -1;
  102588. + goto unlock;
  102589. + }
  102590. +
  102591. + ret = 0;
  102592. +
  102593. +unlock:
  102594. + vchi_service_release(instance->vchi_handle[0]);
  102595. + mutex_unlock(&instance->vchi_mutex);
  102596. +exit:
  102597. + LOG_DBG(" .. OUT\n");
  102598. + return ret;
  102599. +}
  102600. +
  102601. +static int bcm2835_audio_set_ctls_chan(bcm2835_alsa_stream_t * alsa_stream,
  102602. + bcm2835_chip_t * chip)
  102603. +{
  102604. + VC_AUDIO_MSG_T m;
  102605. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  102606. + int32_t success;
  102607. + int ret;
  102608. + LOG_DBG(" .. IN\n");
  102609. +
  102610. + LOG_INFO
  102611. + (" Setting ALSA dest(%d), volume(%d)\n", chip->dest, chip->volume);
  102612. +
  102613. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  102614. + {
  102615. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  102616. + return -EINTR;
  102617. + }
  102618. + vchi_service_use(instance->vchi_handle[0]);
  102619. +
  102620. + instance->result = -1;
  102621. +
  102622. + m.type = VC_AUDIO_MSG_TYPE_CONTROL;
  102623. + m.u.control.dest = chip->dest;
  102624. + m.u.control.volume = chip->volume;
  102625. +
  102626. + /* Create the message available completion */
  102627. + init_completion(&instance->msg_avail_comp);
  102628. +
  102629. + /* Send the message to the videocore */
  102630. + success = vchi_msg_queue(instance->vchi_handle[0],
  102631. + &m, sizeof m,
  102632. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  102633. +
  102634. + if (success != 0) {
  102635. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  102636. + __func__, success);
  102637. +
  102638. + ret = -1;
  102639. + goto unlock;
  102640. + }
  102641. +
  102642. + /* We are expecting a reply from the videocore */
  102643. + ret = wait_for_completion_interruptible(&instance->msg_avail_comp);
  102644. + if (ret) {
  102645. + LOG_ERR("%s: failed on waiting for event (status=%d)\n",
  102646. + __func__, success);
  102647. + goto unlock;
  102648. + }
  102649. +
  102650. + if (instance->result != 0) {
  102651. + LOG_ERR("%s: result=%d\n", __func__, instance->result);
  102652. +
  102653. + ret = -1;
  102654. + goto unlock;
  102655. + }
  102656. +
  102657. + ret = 0;
  102658. +
  102659. +unlock:
  102660. + vchi_service_release(instance->vchi_handle[0]);
  102661. + mutex_unlock(&instance->vchi_mutex);
  102662. +
  102663. + LOG_DBG(" .. OUT\n");
  102664. + return ret;
  102665. +}
  102666. +
  102667. +int bcm2835_audio_set_ctls(bcm2835_chip_t * chip)
  102668. +{
  102669. + int i;
  102670. + int ret = 0;
  102671. + LOG_DBG(" .. IN\n");
  102672. +
  102673. + /* change ctls for all substreams */
  102674. + for (i = 0; i < MAX_SUBSTREAMS; i++) {
  102675. + if (chip->avail_substreams & (1 << i)) {
  102676. + if (!chip->alsa_stream[i])
  102677. + {
  102678. + LOG_DBG(" No ALSA stream available?! %i:%p (%x)\n", i, chip->alsa_stream[i], chip->avail_substreams);
  102679. + ret = 0;
  102680. + }
  102681. + else if (bcm2835_audio_set_ctls_chan /* returns 0 on success */
  102682. + (chip->alsa_stream[i], chip) != 0)
  102683. + {
  102684. + LOG_DBG("Couldn't set the controls for stream %d\n", i);
  102685. + ret = -1;
  102686. + }
  102687. + else LOG_DBG(" Controls set for stream %d\n", i);
  102688. + }
  102689. + }
  102690. + LOG_DBG(" .. OUT ret=%d\n", ret);
  102691. + return ret;
  102692. +}
  102693. +
  102694. +int bcm2835_audio_set_params(bcm2835_alsa_stream_t * alsa_stream,
  102695. + uint32_t channels, uint32_t samplerate,
  102696. + uint32_t bps)
  102697. +{
  102698. + VC_AUDIO_MSG_T m;
  102699. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  102700. + int32_t success;
  102701. + int ret;
  102702. + LOG_DBG(" .. IN\n");
  102703. +
  102704. + LOG_INFO
  102705. + (" Setting ALSA channels(%d), samplerate(%d), bits-per-sample(%d)\n",
  102706. + channels, samplerate, bps);
  102707. +
  102708. + /* resend ctls - alsa_stream may not have been open when first send */
  102709. + ret = bcm2835_audio_set_ctls_chan(alsa_stream, alsa_stream->chip);
  102710. + if (ret != 0) {
  102711. + LOG_ERR(" Alsa controls not supported\n");
  102712. + return -EINVAL;
  102713. + }
  102714. +
  102715. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  102716. + {
  102717. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  102718. + return -EINTR;
  102719. + }
  102720. + vchi_service_use(instance->vchi_handle[0]);
  102721. +
  102722. + instance->result = -1;
  102723. +
  102724. + m.type = VC_AUDIO_MSG_TYPE_CONFIG;
  102725. + m.u.config.channels = channels;
  102726. + m.u.config.samplerate = samplerate;
  102727. + m.u.config.bps = bps;
  102728. +
  102729. + /* Create the message available completion */
  102730. + init_completion(&instance->msg_avail_comp);
  102731. +
  102732. + /* Send the message to the videocore */
  102733. + success = vchi_msg_queue(instance->vchi_handle[0],
  102734. + &m, sizeof m,
  102735. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  102736. +
  102737. + if (success != 0) {
  102738. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  102739. + __func__, success);
  102740. +
  102741. + ret = -1;
  102742. + goto unlock;
  102743. + }
  102744. +
  102745. + /* We are expecting a reply from the videocore */
  102746. + ret = wait_for_completion_interruptible(&instance->msg_avail_comp);
  102747. + if (ret) {
  102748. + LOG_ERR("%s: failed on waiting for event (status=%d)\n",
  102749. + __func__, success);
  102750. + goto unlock;
  102751. + }
  102752. +
  102753. + if (instance->result != 0) {
  102754. + LOG_ERR("%s: result=%d", __func__, instance->result);
  102755. +
  102756. + ret = -1;
  102757. + goto unlock;
  102758. + }
  102759. +
  102760. + ret = 0;
  102761. +
  102762. +unlock:
  102763. + vchi_service_release(instance->vchi_handle[0]);
  102764. + mutex_unlock(&instance->vchi_mutex);
  102765. +
  102766. + LOG_DBG(" .. OUT\n");
  102767. + return ret;
  102768. +}
  102769. +
  102770. +int bcm2835_audio_setup(bcm2835_alsa_stream_t * alsa_stream)
  102771. +{
  102772. + LOG_DBG(" .. IN\n");
  102773. +
  102774. + LOG_DBG(" .. OUT\n");
  102775. +
  102776. + return 0;
  102777. +}
  102778. +
  102779. +static int bcm2835_audio_start_worker(bcm2835_alsa_stream_t * alsa_stream)
  102780. +{
  102781. + VC_AUDIO_MSG_T m;
  102782. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  102783. + int32_t success;
  102784. + int ret;
  102785. + LOG_DBG(" .. IN\n");
  102786. +
  102787. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  102788. + {
  102789. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  102790. + return -EINTR;
  102791. + }
  102792. + vchi_service_use(instance->vchi_handle[0]);
  102793. +
  102794. + m.type = VC_AUDIO_MSG_TYPE_START;
  102795. +
  102796. + /* Send the message to the videocore */
  102797. + success = vchi_msg_queue(instance->vchi_handle[0],
  102798. + &m, sizeof m,
  102799. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  102800. +
  102801. + if (success != 0) {
  102802. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)",
  102803. + __func__, success);
  102804. +
  102805. + ret = -1;
  102806. + goto unlock;
  102807. + }
  102808. +
  102809. + ret = 0;
  102810. +
  102811. +unlock:
  102812. + vchi_service_release(instance->vchi_handle[0]);
  102813. + mutex_unlock(&instance->vchi_mutex);
  102814. + LOG_DBG(" .. OUT\n");
  102815. + return ret;
  102816. +}
  102817. +
  102818. +static int bcm2835_audio_stop_worker(bcm2835_alsa_stream_t * alsa_stream)
  102819. +{
  102820. + VC_AUDIO_MSG_T m;
  102821. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  102822. + int32_t success;
  102823. + int ret;
  102824. + LOG_DBG(" .. IN\n");
  102825. +
  102826. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  102827. + {
  102828. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  102829. + return -EINTR;
  102830. + }
  102831. + vchi_service_use(instance->vchi_handle[0]);
  102832. +
  102833. + m.type = VC_AUDIO_MSG_TYPE_STOP;
  102834. + m.u.stop.draining = alsa_stream->draining;
  102835. +
  102836. + /* Send the message to the videocore */
  102837. + success = vchi_msg_queue(instance->vchi_handle[0],
  102838. + &m, sizeof m,
  102839. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  102840. +
  102841. + if (success != 0) {
  102842. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)",
  102843. + __func__, success);
  102844. +
  102845. + ret = -1;
  102846. + goto unlock;
  102847. + }
  102848. +
  102849. + ret = 0;
  102850. +
  102851. +unlock:
  102852. + vchi_service_release(instance->vchi_handle[0]);
  102853. + mutex_unlock(&instance->vchi_mutex);
  102854. + LOG_DBG(" .. OUT\n");
  102855. + return ret;
  102856. +}
  102857. +
  102858. +int bcm2835_audio_close(bcm2835_alsa_stream_t * alsa_stream)
  102859. +{
  102860. + VC_AUDIO_MSG_T m;
  102861. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  102862. + int32_t success;
  102863. + int ret;
  102864. + LOG_DBG(" .. IN\n");
  102865. +
  102866. + my_workqueue_quit(alsa_stream);
  102867. +
  102868. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  102869. + {
  102870. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  102871. + return -EINTR;
  102872. + }
  102873. + vchi_service_use(instance->vchi_handle[0]);
  102874. +
  102875. + m.type = VC_AUDIO_MSG_TYPE_CLOSE;
  102876. +
  102877. + /* Create the message available completion */
  102878. + init_completion(&instance->msg_avail_comp);
  102879. +
  102880. + /* Send the message to the videocore */
  102881. + success = vchi_msg_queue(instance->vchi_handle[0],
  102882. + &m, sizeof m,
  102883. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  102884. +
  102885. + if (success != 0) {
  102886. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)",
  102887. + __func__, success);
  102888. + ret = -1;
  102889. + goto unlock;
  102890. + }
  102891. +
  102892. + ret = wait_for_completion_interruptible(&instance->msg_avail_comp);
  102893. + if (ret) {
  102894. + LOG_ERR("%s: failed on waiting for event (status=%d)",
  102895. + __func__, success);
  102896. + goto unlock;
  102897. + }
  102898. + if (instance->result != 0) {
  102899. + LOG_ERR("%s: failed result (status=%d)",
  102900. + __func__, instance->result);
  102901. +
  102902. + ret = -1;
  102903. + goto unlock;
  102904. + }
  102905. +
  102906. + ret = 0;
  102907. +
  102908. +unlock:
  102909. + vchi_service_release(instance->vchi_handle[0]);
  102910. + mutex_unlock(&instance->vchi_mutex);
  102911. +
  102912. + /* Stop the audio service */
  102913. + if (instance) {
  102914. + vc_vchi_audio_deinit(instance);
  102915. + alsa_stream->instance = NULL;
  102916. + }
  102917. + LOG_DBG(" .. OUT\n");
  102918. + return ret;
  102919. +}
  102920. +
  102921. +int bcm2835_audio_write_worker(bcm2835_alsa_stream_t *alsa_stream,
  102922. + uint32_t count, void *src)
  102923. +{
  102924. + VC_AUDIO_MSG_T m;
  102925. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  102926. + int32_t success;
  102927. + int ret;
  102928. +
  102929. + LOG_DBG(" .. IN\n");
  102930. +
  102931. + LOG_INFO(" Writing %d bytes from %p\n", count, src);
  102932. +
  102933. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  102934. + {
  102935. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  102936. + return -EINTR;
  102937. + }
  102938. + vchi_service_use(instance->vchi_handle[0]);
  102939. +
  102940. + if ( instance->peer_version==0 && vchi_get_peer_version(instance->vchi_handle[0], &instance->peer_version) == 0 ) {
  102941. + LOG_DBG("%s: client version %d connected\n", __func__, instance->peer_version);
  102942. + }
  102943. + m.type = VC_AUDIO_MSG_TYPE_WRITE;
  102944. + m.u.write.count = count;
  102945. + // old version uses bulk, new version uses control
  102946. + m.u.write.max_packet = instance->peer_version < 2 || force_bulk ? 0:4000;
  102947. + m.u.write.callback = alsa_stream->fifo_irq_handler;
  102948. + m.u.write.cookie = alsa_stream;
  102949. + m.u.write.silence = src == NULL;
  102950. +
  102951. + /* Send the message to the videocore */
  102952. + success = vchi_msg_queue(instance->vchi_handle[0],
  102953. + &m, sizeof m,
  102954. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  102955. +
  102956. + if (success != 0) {
  102957. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)",
  102958. + __func__, success);
  102959. +
  102960. + ret = -1;
  102961. + goto unlock;
  102962. + }
  102963. + if (!m.u.write.silence) {
  102964. + if (m.u.write.max_packet == 0) {
  102965. + /* Send the message to the videocore */
  102966. + success = vchi_bulk_queue_transmit(instance->vchi_handle[0],
  102967. + src, count,
  102968. + 0 *
  102969. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED
  102970. + +
  102971. + 1 *
  102972. + VCHI_FLAGS_BLOCK_UNTIL_DATA_READ,
  102973. + NULL);
  102974. + } else {
  102975. + while (count > 0) {
  102976. + int bytes = min((int)m.u.write.max_packet, (int)count);
  102977. + success = vchi_msg_queue(instance->vchi_handle[0],
  102978. + src, bytes,
  102979. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  102980. + src = (char *)src + bytes;
  102981. + count -= bytes;
  102982. + }
  102983. + }
  102984. + if (success != 0) {
  102985. + LOG_ERR
  102986. + ("%s: failed on vchi_bulk_queue_transmit (status=%d)",
  102987. + __func__, success);
  102988. +
  102989. + ret = -1;
  102990. + goto unlock;
  102991. + }
  102992. + }
  102993. + ret = 0;
  102994. +
  102995. +unlock:
  102996. + vchi_service_release(instance->vchi_handle[0]);
  102997. + mutex_unlock(&instance->vchi_mutex);
  102998. + LOG_DBG(" .. OUT\n");
  102999. + return ret;
  103000. +}
  103001. +
  103002. +/**
  103003. + * Returns all buffers from arm->vc
  103004. + */
  103005. +void bcm2835_audio_flush_buffers(bcm2835_alsa_stream_t * alsa_stream)
  103006. +{
  103007. + LOG_DBG(" .. IN\n");
  103008. + LOG_DBG(" .. OUT\n");
  103009. + return;
  103010. +}
  103011. +
  103012. +/**
  103013. + * Forces VC to flush(drop) its filled playback buffers and
  103014. + * return them the us. (VC->ARM)
  103015. + */
  103016. +void bcm2835_audio_flush_playback_buffers(bcm2835_alsa_stream_t * alsa_stream)
  103017. +{
  103018. + LOG_DBG(" .. IN\n");
  103019. + LOG_DBG(" .. OUT\n");
  103020. +}
  103021. +
  103022. +uint32_t bcm2835_audio_retrieve_buffers(bcm2835_alsa_stream_t * alsa_stream)
  103023. +{
  103024. + uint32_t count = atomic_read(&alsa_stream->retrieved);
  103025. + atomic_sub(count, &alsa_stream->retrieved);
  103026. + return count;
  103027. +}
  103028. +
  103029. +module_param(force_bulk, bool, 0444);
  103030. +MODULE_PARM_DESC(force_bulk, "Force use of vchiq bulk for audio");
  103031. diff -Nur linux-3.12.26.orig/sound/arm/Kconfig linux-3.12.26/sound/arm/Kconfig
  103032. --- linux-3.12.26.orig/sound/arm/Kconfig 2014-07-30 18:02:44.000000000 +0200
  103033. +++ linux-3.12.26/sound/arm/Kconfig 2014-08-06 16:50:15.165967585 +0200
  103034. @@ -39,5 +39,12 @@
  103035. Say Y or M if you want to support any AC97 codec attached to
  103036. the PXA2xx AC97 interface.
  103037. +config SND_BCM2835
  103038. + tristate "BCM2835 ALSA driver"
  103039. + depends on ARCH_BCM2708 && BCM2708_VCHIQ && SND
  103040. + select SND_PCM
  103041. + help
  103042. + Say Y or M if you want to support BCM2835 Alsa pcm card driver
  103043. +
  103044. endif # SND_ARM
  103045. diff -Nur linux-3.12.26.orig/sound/arm/Makefile linux-3.12.26/sound/arm/Makefile
  103046. --- linux-3.12.26.orig/sound/arm/Makefile 2014-07-30 18:02:44.000000000 +0200
  103047. +++ linux-3.12.26/sound/arm/Makefile 2014-08-06 16:50:15.165967585 +0200
  103048. @@ -14,3 +14,8 @@
  103049. obj-$(CONFIG_SND_PXA2XX_AC97) += snd-pxa2xx-ac97.o
  103050. snd-pxa2xx-ac97-objs := pxa2xx-ac97.o
  103051. +
  103052. +obj-$(CONFIG_SND_BCM2835) += snd-bcm2835.o
  103053. +snd-bcm2835-objs := bcm2835.o bcm2835-ctl.o bcm2835-pcm.o bcm2835-vchiq.o
  103054. +
  103055. +ccflags-y += -Idrivers/misc/vc04_services -Idrivers/misc/vc04_services/interface/vcos/linuxkernel -D__VCCOREVER__=0x04000000
  103056. diff -Nur linux-3.12.26.orig/sound/arm/vc_vchi_audioserv_defs.h linux-3.12.26/sound/arm/vc_vchi_audioserv_defs.h
  103057. --- linux-3.12.26.orig/sound/arm/vc_vchi_audioserv_defs.h 1970-01-01 01:00:00.000000000 +0100
  103058. +++ linux-3.12.26/sound/arm/vc_vchi_audioserv_defs.h 2014-08-06 16:50:15.165967585 +0200
  103059. @@ -0,0 +1,116 @@
  103060. +/*****************************************************************************
  103061. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  103062. +*
  103063. +* Unless you and Broadcom execute a separate written software license
  103064. +* agreement governing use of this software, this software is licensed to you
  103065. +* under the terms of the GNU General Public License version 2, available at
  103066. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  103067. +*
  103068. +* Notwithstanding the above, under no circumstances may you combine this
  103069. +* software in any way with any other Broadcom software provided under a
  103070. +* license other than the GPL, without Broadcom's express prior written
  103071. +* consent.
  103072. +*****************************************************************************/
  103073. +
  103074. +#ifndef _VC_AUDIO_DEFS_H_
  103075. +#define _VC_AUDIO_DEFS_H_
  103076. +
  103077. +#define VC_AUDIOSERV_MIN_VER 1
  103078. +#define VC_AUDIOSERV_VER 2
  103079. +
  103080. +// FourCC code used for VCHI connection
  103081. +#define VC_AUDIO_SERVER_NAME MAKE_FOURCC("AUDS")
  103082. +
  103083. +// Maximum message length
  103084. +#define VC_AUDIO_MAX_MSG_LEN (sizeof( VC_AUDIO_MSG_T ))
  103085. +
  103086. +// List of screens that are currently supported
  103087. +// All message types supported for HOST->VC direction
  103088. +typedef enum {
  103089. + VC_AUDIO_MSG_TYPE_RESULT, // Generic result
  103090. + VC_AUDIO_MSG_TYPE_COMPLETE, // Generic result
  103091. + VC_AUDIO_MSG_TYPE_CONFIG, // Configure audio
  103092. + VC_AUDIO_MSG_TYPE_CONTROL, // Configure audio
  103093. + VC_AUDIO_MSG_TYPE_OPEN, // Configure audio
  103094. + VC_AUDIO_MSG_TYPE_CLOSE, // Configure audio
  103095. + VC_AUDIO_MSG_TYPE_START, // Configure audio
  103096. + VC_AUDIO_MSG_TYPE_STOP, // Configure audio
  103097. + VC_AUDIO_MSG_TYPE_WRITE, // Configure audio
  103098. + VC_AUDIO_MSG_TYPE_MAX
  103099. +} VC_AUDIO_MSG_TYPE;
  103100. +
  103101. +// configure the audio
  103102. +typedef struct {
  103103. + uint32_t channels;
  103104. + uint32_t samplerate;
  103105. + uint32_t bps;
  103106. +
  103107. +} VC_AUDIO_CONFIG_T;
  103108. +
  103109. +typedef struct {
  103110. + uint32_t volume;
  103111. + uint32_t dest;
  103112. +
  103113. +} VC_AUDIO_CONTROL_T;
  103114. +
  103115. +// audio
  103116. +typedef struct {
  103117. + uint32_t dummy;
  103118. +
  103119. +} VC_AUDIO_OPEN_T;
  103120. +
  103121. +// audio
  103122. +typedef struct {
  103123. + uint32_t dummy;
  103124. +
  103125. +} VC_AUDIO_CLOSE_T;
  103126. +// audio
  103127. +typedef struct {
  103128. + uint32_t dummy;
  103129. +
  103130. +} VC_AUDIO_START_T;
  103131. +// audio
  103132. +typedef struct {
  103133. + uint32_t draining;
  103134. +
  103135. +} VC_AUDIO_STOP_T;
  103136. +
  103137. +// configure the write audio samples
  103138. +typedef struct {
  103139. + uint32_t count; // in bytes
  103140. + void *callback;
  103141. + void *cookie;
  103142. + uint16_t silence;
  103143. + uint16_t max_packet;
  103144. +} VC_AUDIO_WRITE_T;
  103145. +
  103146. +// Generic result for a request (VC->HOST)
  103147. +typedef struct {
  103148. + int32_t success; // Success value
  103149. +
  103150. +} VC_AUDIO_RESULT_T;
  103151. +
  103152. +// Generic result for a request (VC->HOST)
  103153. +typedef struct {
  103154. + int32_t count; // Success value
  103155. + void *callback;
  103156. + void *cookie;
  103157. +} VC_AUDIO_COMPLETE_T;
  103158. +
  103159. +// Message header for all messages in HOST->VC direction
  103160. +typedef struct {
  103161. + int32_t type; // Message type (VC_AUDIO_MSG_TYPE)
  103162. + union {
  103163. + VC_AUDIO_CONFIG_T config;
  103164. + VC_AUDIO_CONTROL_T control;
  103165. + VC_AUDIO_OPEN_T open;
  103166. + VC_AUDIO_CLOSE_T close;
  103167. + VC_AUDIO_START_T start;
  103168. + VC_AUDIO_STOP_T stop;
  103169. + VC_AUDIO_WRITE_T write;
  103170. + VC_AUDIO_RESULT_T result;
  103171. + VC_AUDIO_COMPLETE_T complete;
  103172. + } u;
  103173. +} VC_AUDIO_MSG_T;
  103174. +
  103175. +#endif // _VC_AUDIO_DEFS_H_
  103176. diff -Nur linux-3.12.26.orig/sound/soc/bcm/bcm2708-i2s.c linux-3.12.26/sound/soc/bcm/bcm2708-i2s.c
  103177. --- linux-3.12.26.orig/sound/soc/bcm/bcm2708-i2s.c 1970-01-01 01:00:00.000000000 +0100
  103178. +++ linux-3.12.26/sound/soc/bcm/bcm2708-i2s.c 2014-08-06 16:50:15.205967899 +0200
  103179. @@ -0,0 +1,945 @@
  103180. +/*
  103181. + * ALSA SoC I2S Audio Layer for Broadcom BCM2708 SoC
  103182. + *
  103183. + * Author: Florian Meier <florian.meier@koalo.de>
  103184. + * Copyright 2013
  103185. + *
  103186. + * Based on
  103187. + * Raspberry Pi PCM I2S ALSA Driver
  103188. + * Copyright (c) by Phil Poole 2013
  103189. + *
  103190. + * ALSA SoC I2S (McBSP) Audio Layer for TI DAVINCI processor
  103191. + * Vladimir Barinov, <vbarinov@embeddedalley.com>
  103192. + * Copyright (C) 2007 MontaVista Software, Inc., <source@mvista.com>
  103193. + *
  103194. + * OMAP ALSA SoC DAI driver using McBSP port
  103195. + * Copyright (C) 2008 Nokia Corporation
  103196. + * Contact: Jarkko Nikula <jarkko.nikula@bitmer.com>
  103197. + * Peter Ujfalusi <peter.ujfalusi@ti.com>
  103198. + *
  103199. + * Freescale SSI ALSA SoC Digital Audio Interface (DAI) driver
  103200. + * Author: Timur Tabi <timur@freescale.com>
  103201. + * Copyright 2007-2010 Freescale Semiconductor, Inc.
  103202. + *
  103203. + * This program is free software; you can redistribute it and/or
  103204. + * modify it under the terms of the GNU General Public License
  103205. + * version 2 as published by the Free Software Foundation.
  103206. + *
  103207. + * This program is distributed in the hope that it will be useful, but
  103208. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  103209. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  103210. + * General Public License for more details.
  103211. + */
  103212. +
  103213. +#include <linux/init.h>
  103214. +#include <linux/module.h>
  103215. +#include <linux/device.h>
  103216. +#include <linux/slab.h>
  103217. +#include <linux/delay.h>
  103218. +#include <linux/io.h>
  103219. +#include <linux/clk.h>
  103220. +
  103221. +#include <sound/core.h>
  103222. +#include <sound/pcm.h>
  103223. +#include <sound/pcm_params.h>
  103224. +#include <sound/initval.h>
  103225. +#include <sound/soc.h>
  103226. +#include <sound/dmaengine_pcm.h>
  103227. +
  103228. +/* Clock registers */
  103229. +#define BCM2708_CLK_PCMCTL_REG 0x00
  103230. +#define BCM2708_CLK_PCMDIV_REG 0x04
  103231. +
  103232. +/* Clock register settings */
  103233. +#define BCM2708_CLK_PASSWD (0x5a000000)
  103234. +#define BCM2708_CLK_PASSWD_MASK (0xff000000)
  103235. +#define BCM2708_CLK_MASH(v) ((v) << 9)
  103236. +#define BCM2708_CLK_FLIP BIT(8)
  103237. +#define BCM2708_CLK_BUSY BIT(7)
  103238. +#define BCM2708_CLK_KILL BIT(5)
  103239. +#define BCM2708_CLK_ENAB BIT(4)
  103240. +#define BCM2708_CLK_SRC(v) (v)
  103241. +
  103242. +#define BCM2708_CLK_SHIFT (12)
  103243. +#define BCM2708_CLK_DIVI(v) ((v) << BCM2708_CLK_SHIFT)
  103244. +#define BCM2708_CLK_DIVF(v) (v)
  103245. +#define BCM2708_CLK_DIVF_MASK (0xFFF)
  103246. +
  103247. +enum {
  103248. + BCM2708_CLK_MASH_0 = 0,
  103249. + BCM2708_CLK_MASH_1,
  103250. + BCM2708_CLK_MASH_2,
  103251. + BCM2708_CLK_MASH_3,
  103252. +};
  103253. +
  103254. +enum {
  103255. + BCM2708_CLK_SRC_GND = 0,
  103256. + BCM2708_CLK_SRC_OSC,
  103257. + BCM2708_CLK_SRC_DBG0,
  103258. + BCM2708_CLK_SRC_DBG1,
  103259. + BCM2708_CLK_SRC_PLLA,
  103260. + BCM2708_CLK_SRC_PLLC,
  103261. + BCM2708_CLK_SRC_PLLD,
  103262. + BCM2708_CLK_SRC_HDMI,
  103263. +};
  103264. +
  103265. +/* Most clocks are not useable (freq = 0) */
  103266. +static const unsigned int bcm2708_clk_freq[BCM2708_CLK_SRC_HDMI+1] = {
  103267. + [BCM2708_CLK_SRC_GND] = 0,
  103268. + [BCM2708_CLK_SRC_OSC] = 19200000,
  103269. + [BCM2708_CLK_SRC_DBG0] = 0,
  103270. + [BCM2708_CLK_SRC_DBG1] = 0,
  103271. + [BCM2708_CLK_SRC_PLLA] = 0,
  103272. + [BCM2708_CLK_SRC_PLLC] = 0,
  103273. + [BCM2708_CLK_SRC_PLLD] = 500000000,
  103274. + [BCM2708_CLK_SRC_HDMI] = 0,
  103275. +};
  103276. +
  103277. +/* I2S registers */
  103278. +#define BCM2708_I2S_CS_A_REG 0x00
  103279. +#define BCM2708_I2S_FIFO_A_REG 0x04
  103280. +#define BCM2708_I2S_MODE_A_REG 0x08
  103281. +#define BCM2708_I2S_RXC_A_REG 0x0c
  103282. +#define BCM2708_I2S_TXC_A_REG 0x10
  103283. +#define BCM2708_I2S_DREQ_A_REG 0x14
  103284. +#define BCM2708_I2S_INTEN_A_REG 0x18
  103285. +#define BCM2708_I2S_INTSTC_A_REG 0x1c
  103286. +#define BCM2708_I2S_GRAY_REG 0x20
  103287. +
  103288. +/* I2S register settings */
  103289. +#define BCM2708_I2S_STBY BIT(25)
  103290. +#define BCM2708_I2S_SYNC BIT(24)
  103291. +#define BCM2708_I2S_RXSEX BIT(23)
  103292. +#define BCM2708_I2S_RXF BIT(22)
  103293. +#define BCM2708_I2S_TXE BIT(21)
  103294. +#define BCM2708_I2S_RXD BIT(20)
  103295. +#define BCM2708_I2S_TXD BIT(19)
  103296. +#define BCM2708_I2S_RXR BIT(18)
  103297. +#define BCM2708_I2S_TXW BIT(17)
  103298. +#define BCM2708_I2S_CS_RXERR BIT(16)
  103299. +#define BCM2708_I2S_CS_TXERR BIT(15)
  103300. +#define BCM2708_I2S_RXSYNC BIT(14)
  103301. +#define BCM2708_I2S_TXSYNC BIT(13)
  103302. +#define BCM2708_I2S_DMAEN BIT(9)
  103303. +#define BCM2708_I2S_RXTHR(v) ((v) << 7)
  103304. +#define BCM2708_I2S_TXTHR(v) ((v) << 5)
  103305. +#define BCM2708_I2S_RXCLR BIT(4)
  103306. +#define BCM2708_I2S_TXCLR BIT(3)
  103307. +#define BCM2708_I2S_TXON BIT(2)
  103308. +#define BCM2708_I2S_RXON BIT(1)
  103309. +#define BCM2708_I2S_EN (1)
  103310. +
  103311. +#define BCM2708_I2S_CLKDIS BIT(28)
  103312. +#define BCM2708_I2S_PDMN BIT(27)
  103313. +#define BCM2708_I2S_PDME BIT(26)
  103314. +#define BCM2708_I2S_FRXP BIT(25)
  103315. +#define BCM2708_I2S_FTXP BIT(24)
  103316. +#define BCM2708_I2S_CLKM BIT(23)
  103317. +#define BCM2708_I2S_CLKI BIT(22)
  103318. +#define BCM2708_I2S_FSM BIT(21)
  103319. +#define BCM2708_I2S_FSI BIT(20)
  103320. +#define BCM2708_I2S_FLEN(v) ((v) << 10)
  103321. +#define BCM2708_I2S_FSLEN(v) (v)
  103322. +
  103323. +#define BCM2708_I2S_CHWEX BIT(15)
  103324. +#define BCM2708_I2S_CHEN BIT(14)
  103325. +#define BCM2708_I2S_CHPOS(v) ((v) << 4)
  103326. +#define BCM2708_I2S_CHWID(v) (v)
  103327. +#define BCM2708_I2S_CH1(v) ((v) << 16)
  103328. +#define BCM2708_I2S_CH2(v) (v)
  103329. +
  103330. +#define BCM2708_I2S_TX_PANIC(v) ((v) << 24)
  103331. +#define BCM2708_I2S_RX_PANIC(v) ((v) << 16)
  103332. +#define BCM2708_I2S_TX(v) ((v) << 8)
  103333. +#define BCM2708_I2S_RX(v) (v)
  103334. +
  103335. +#define BCM2708_I2S_INT_RXERR BIT(3)
  103336. +#define BCM2708_I2S_INT_TXERR BIT(2)
  103337. +#define BCM2708_I2S_INT_RXR BIT(1)
  103338. +#define BCM2708_I2S_INT_TXW BIT(0)
  103339. +
  103340. +/* I2S DMA interface */
  103341. +#define BCM2708_I2S_FIFO_PHYSICAL_ADDR 0x7E203004
  103342. +#define BCM2708_DMA_DREQ_PCM_TX 2
  103343. +#define BCM2708_DMA_DREQ_PCM_RX 3
  103344. +
  103345. +/* General device struct */
  103346. +struct bcm2708_i2s_dev {
  103347. + struct device *dev;
  103348. + struct snd_dmaengine_dai_dma_data dma_data[2];
  103349. + unsigned int fmt;
  103350. + unsigned int bclk_ratio;
  103351. +
  103352. + struct regmap *i2s_regmap;
  103353. + struct regmap *clk_regmap;
  103354. +};
  103355. +
  103356. +static void bcm2708_i2s_start_clock(struct bcm2708_i2s_dev *dev)
  103357. +{
  103358. + /* Start the clock if in master mode */
  103359. + unsigned int master = dev->fmt & SND_SOC_DAIFMT_MASTER_MASK;
  103360. +
  103361. + switch (master) {
  103362. + case SND_SOC_DAIFMT_CBS_CFS:
  103363. + case SND_SOC_DAIFMT_CBS_CFM:
  103364. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  103365. + BCM2708_CLK_PASSWD_MASK | BCM2708_CLK_ENAB,
  103366. + BCM2708_CLK_PASSWD | BCM2708_CLK_ENAB);
  103367. + break;
  103368. + default:
  103369. + break;
  103370. + }
  103371. +}
  103372. +
  103373. +static void bcm2708_i2s_stop_clock(struct bcm2708_i2s_dev *dev)
  103374. +{
  103375. + uint32_t clkreg;
  103376. + int timeout = 1000;
  103377. +
  103378. + /* Stop clock */
  103379. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  103380. + BCM2708_CLK_PASSWD_MASK | BCM2708_CLK_ENAB,
  103381. + BCM2708_CLK_PASSWD);
  103382. +
  103383. + /* Wait for the BUSY flag going down */
  103384. + while (--timeout) {
  103385. + regmap_read(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG, &clkreg);
  103386. + if (!(clkreg & BCM2708_CLK_BUSY))
  103387. + break;
  103388. + }
  103389. +
  103390. + if (!timeout) {
  103391. + /* KILL the clock */
  103392. + dev_err(dev->dev, "I2S clock didn't stop. Kill the clock!\n");
  103393. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  103394. + BCM2708_CLK_KILL | BCM2708_CLK_PASSWD_MASK,
  103395. + BCM2708_CLK_KILL | BCM2708_CLK_PASSWD);
  103396. + }
  103397. +}
  103398. +
  103399. +static void bcm2708_i2s_clear_fifos(struct bcm2708_i2s_dev *dev,
  103400. + bool tx, bool rx)
  103401. +{
  103402. + int timeout = 1000;
  103403. + uint32_t syncval;
  103404. + uint32_t csreg;
  103405. + uint32_t i2s_active_state;
  103406. + uint32_t clkreg;
  103407. + uint32_t clk_active_state;
  103408. + uint32_t off;
  103409. + uint32_t clr;
  103410. +
  103411. + off = tx ? BCM2708_I2S_TXON : 0;
  103412. + off |= rx ? BCM2708_I2S_RXON : 0;
  103413. +
  103414. + clr = tx ? BCM2708_I2S_TXCLR : 0;
  103415. + clr |= rx ? BCM2708_I2S_RXCLR : 0;
  103416. +
  103417. + /* Backup the current state */
  103418. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &csreg);
  103419. + i2s_active_state = csreg & (BCM2708_I2S_RXON | BCM2708_I2S_TXON);
  103420. +
  103421. + regmap_read(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG, &clkreg);
  103422. + clk_active_state = clkreg & BCM2708_CLK_ENAB;
  103423. +
  103424. + /* Start clock if not running */
  103425. + if (!clk_active_state) {
  103426. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  103427. + BCM2708_CLK_PASSWD_MASK | BCM2708_CLK_ENAB,
  103428. + BCM2708_CLK_PASSWD | BCM2708_CLK_ENAB);
  103429. + }
  103430. +
  103431. + /* Stop I2S module */
  103432. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, off, 0);
  103433. +
  103434. + /*
  103435. + * Clear the FIFOs
  103436. + * Requires at least 2 PCM clock cycles to take effect
  103437. + */
  103438. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, clr, clr);
  103439. +
  103440. + /* Wait for 2 PCM clock cycles */
  103441. +
  103442. + /*
  103443. + * Toggle the SYNC flag. After 2 PCM clock cycles it can be read back
  103444. + * FIXME: This does not seem to work for slave mode!
  103445. + */
  103446. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &syncval);
  103447. + syncval &= BCM2708_I2S_SYNC;
  103448. +
  103449. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  103450. + BCM2708_I2S_SYNC, ~syncval);
  103451. +
  103452. + /* Wait for the SYNC flag changing it's state */
  103453. + while (--timeout) {
  103454. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &csreg);
  103455. + if ((csreg & BCM2708_I2S_SYNC) != syncval)
  103456. + break;
  103457. + }
  103458. +
  103459. + if (!timeout)
  103460. + dev_err(dev->dev, "I2S SYNC error!\n");
  103461. +
  103462. + /* Stop clock if it was not running before */
  103463. + if (!clk_active_state)
  103464. + bcm2708_i2s_stop_clock(dev);
  103465. +
  103466. + /* Restore I2S state */
  103467. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  103468. + BCM2708_I2S_RXON | BCM2708_I2S_TXON, i2s_active_state);
  103469. +}
  103470. +
  103471. +static int bcm2708_i2s_set_dai_fmt(struct snd_soc_dai *dai,
  103472. + unsigned int fmt)
  103473. +{
  103474. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  103475. + dev->fmt = fmt;
  103476. + return 0;
  103477. +}
  103478. +
  103479. +static int bcm2708_i2s_set_dai_bclk_ratio(struct snd_soc_dai *dai,
  103480. + unsigned int ratio)
  103481. +{
  103482. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  103483. + dev->bclk_ratio = ratio;
  103484. + return 0;
  103485. +}
  103486. +
  103487. +static int bcm2708_i2s_hw_params(struct snd_pcm_substream *substream,
  103488. + struct snd_pcm_hw_params *params,
  103489. + struct snd_soc_dai *dai)
  103490. +{
  103491. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  103492. +
  103493. + unsigned int sampling_rate = params_rate(params);
  103494. + unsigned int data_length, data_delay, bclk_ratio;
  103495. + unsigned int ch1pos, ch2pos, mode, format;
  103496. + unsigned int mash = BCM2708_CLK_MASH_1;
  103497. + unsigned int divi, divf, target_frequency;
  103498. + int clk_src = -1;
  103499. + unsigned int master = dev->fmt & SND_SOC_DAIFMT_MASTER_MASK;
  103500. + bool bit_master = (master == SND_SOC_DAIFMT_CBS_CFS
  103501. + || master == SND_SOC_DAIFMT_CBS_CFM);
  103502. +
  103503. + bool frame_master = (master == SND_SOC_DAIFMT_CBS_CFS
  103504. + || master == SND_SOC_DAIFMT_CBM_CFS);
  103505. + uint32_t csreg;
  103506. +
  103507. + /*
  103508. + * If a stream is already enabled,
  103509. + * the registers are already set properly.
  103510. + */
  103511. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &csreg);
  103512. +
  103513. + if (csreg & (BCM2708_I2S_TXON | BCM2708_I2S_RXON))
  103514. + return 0;
  103515. +
  103516. + /*
  103517. + * Adjust the data length according to the format.
  103518. + * We prefill the half frame length with an integer
  103519. + * divider of 2400 as explained at the clock settings.
  103520. + * Maybe it is overwritten there, if the Integer mode
  103521. + * does not apply.
  103522. + */
  103523. + switch (params_format(params)) {
  103524. + case SNDRV_PCM_FORMAT_S16_LE:
  103525. + data_length = 16;
  103526. + bclk_ratio = 40;
  103527. + break;
  103528. + case SNDRV_PCM_FORMAT_S24_LE:
  103529. + data_length = 24;
  103530. + bclk_ratio = 40;
  103531. + break;
  103532. + case SNDRV_PCM_FORMAT_S32_LE:
  103533. + data_length = 32;
  103534. + bclk_ratio = 80;
  103535. + break;
  103536. + default:
  103537. + return -EINVAL;
  103538. + }
  103539. +
  103540. + /* If bclk_ratio already set, use that one. */
  103541. + if (dev->bclk_ratio)
  103542. + bclk_ratio = dev->bclk_ratio;
  103543. +
  103544. + /*
  103545. + * Clock Settings
  103546. + *
  103547. + * The target frequency of the bit clock is
  103548. + * sampling rate * frame length
  103549. + *
  103550. + * Integer mode:
  103551. + * Sampling rates that are multiples of 8000 kHz
  103552. + * can be driven by the oscillator of 19.2 MHz
  103553. + * with an integer divider as long as the frame length
  103554. + * is an integer divider of 19200000/8000=2400 as set up above.
  103555. + * This is no longer possible if the sampling rate
  103556. + * is too high (e.g. 192 kHz), because the oscillator is too slow.
  103557. + *
  103558. + * MASH mode:
  103559. + * For all other sampling rates, it is not possible to
  103560. + * have an integer divider. Approximate the clock
  103561. + * with the MASH module that induces a slight frequency
  103562. + * variance. To minimize that it is best to have the fastest
  103563. + * clock here. That is PLLD with 500 MHz.
  103564. + */
  103565. + target_frequency = sampling_rate * bclk_ratio;
  103566. + clk_src = BCM2708_CLK_SRC_OSC;
  103567. + mash = BCM2708_CLK_MASH_0;
  103568. +
  103569. + if (bcm2708_clk_freq[clk_src] % target_frequency == 0
  103570. + && bit_master && frame_master) {
  103571. + divi = bcm2708_clk_freq[clk_src] / target_frequency;
  103572. + divf = 0;
  103573. + } else {
  103574. + uint64_t dividend;
  103575. +
  103576. + if (!dev->bclk_ratio) {
  103577. + /*
  103578. + * Overwrite bclk_ratio, because the
  103579. + * above trick is not needed or can
  103580. + * not be used.
  103581. + */
  103582. + bclk_ratio = 2 * data_length;
  103583. + }
  103584. +
  103585. + target_frequency = sampling_rate * bclk_ratio;
  103586. +
  103587. + clk_src = BCM2708_CLK_SRC_PLLD;
  103588. + mash = BCM2708_CLK_MASH_1;
  103589. +
  103590. + dividend = bcm2708_clk_freq[clk_src];
  103591. + dividend <<= BCM2708_CLK_SHIFT;
  103592. + do_div(dividend, target_frequency);
  103593. + divi = dividend >> BCM2708_CLK_SHIFT;
  103594. + divf = dividend & BCM2708_CLK_DIVF_MASK;
  103595. + }
  103596. +
  103597. + /* Set clock divider */
  103598. + regmap_write(dev->clk_regmap, BCM2708_CLK_PCMDIV_REG, BCM2708_CLK_PASSWD
  103599. + | BCM2708_CLK_DIVI(divi)
  103600. + | BCM2708_CLK_DIVF(divf));
  103601. +
  103602. + /* Setup clock, but don't start it yet */
  103603. + regmap_write(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG, BCM2708_CLK_PASSWD
  103604. + | BCM2708_CLK_MASH(mash)
  103605. + | BCM2708_CLK_SRC(clk_src));
  103606. +
  103607. + /* Setup the frame format */
  103608. + format = BCM2708_I2S_CHEN;
  103609. +
  103610. + if (data_length >= 24)
  103611. + format |= BCM2708_I2S_CHWEX;
  103612. +
  103613. + format |= BCM2708_I2S_CHWID((data_length-8)&0xf);
  103614. +
  103615. + switch (dev->fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  103616. + case SND_SOC_DAIFMT_I2S:
  103617. + data_delay = 1;
  103618. + break;
  103619. + default:
  103620. + /*
  103621. + * TODO
  103622. + * Others are possible but are not implemented at the moment.
  103623. + */
  103624. + dev_err(dev->dev, "%s:bad format\n", __func__);
  103625. + return -EINVAL;
  103626. + }
  103627. +
  103628. + ch1pos = data_delay;
  103629. + ch2pos = bclk_ratio / 2 + data_delay;
  103630. +
  103631. + switch (params_channels(params)) {
  103632. + case 2:
  103633. + format = BCM2708_I2S_CH1(format) | BCM2708_I2S_CH2(format);
  103634. + format |= BCM2708_I2S_CH1(BCM2708_I2S_CHPOS(ch1pos));
  103635. + format |= BCM2708_I2S_CH2(BCM2708_I2S_CHPOS(ch2pos));
  103636. + break;
  103637. + default:
  103638. + return -EINVAL;
  103639. + }
  103640. +
  103641. + /*
  103642. + * Set format for both streams.
  103643. + * We cannot set another frame length
  103644. + * (and therefore word length) anyway,
  103645. + * so the format will be the same.
  103646. + */
  103647. + regmap_write(dev->i2s_regmap, BCM2708_I2S_RXC_A_REG, format);
  103648. + regmap_write(dev->i2s_regmap, BCM2708_I2S_TXC_A_REG, format);
  103649. +
  103650. + /* Setup the I2S mode */
  103651. + mode = 0;
  103652. +
  103653. + if (data_length <= 16) {
  103654. + /*
  103655. + * Use frame packed mode (2 channels per 32 bit word)
  103656. + * We cannot set another frame length in the second stream
  103657. + * (and therefore word length) anyway,
  103658. + * so the format will be the same.
  103659. + */
  103660. + mode |= BCM2708_I2S_FTXP | BCM2708_I2S_FRXP;
  103661. + }
  103662. +
  103663. + mode |= BCM2708_I2S_FLEN(bclk_ratio - 1);
  103664. + mode |= BCM2708_I2S_FSLEN(bclk_ratio / 2);
  103665. +
  103666. + /* Master or slave? */
  103667. + switch (dev->fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  103668. + case SND_SOC_DAIFMT_CBS_CFS:
  103669. + /* CPU is master */
  103670. + break;
  103671. + case SND_SOC_DAIFMT_CBM_CFS:
  103672. + /*
  103673. + * CODEC is bit clock master
  103674. + * CPU is frame master
  103675. + */
  103676. + mode |= BCM2708_I2S_CLKM;
  103677. + break;
  103678. + case SND_SOC_DAIFMT_CBS_CFM:
  103679. + /*
  103680. + * CODEC is frame master
  103681. + * CPU is bit clock master
  103682. + */
  103683. + mode |= BCM2708_I2S_FSM;
  103684. + break;
  103685. + case SND_SOC_DAIFMT_CBM_CFM:
  103686. + /* CODEC is master */
  103687. + mode |= BCM2708_I2S_CLKM;
  103688. + mode |= BCM2708_I2S_FSM;
  103689. + break;
  103690. + default:
  103691. + dev_err(dev->dev, "%s:bad master\n", __func__);
  103692. + return -EINVAL;
  103693. + }
  103694. +
  103695. + /*
  103696. + * Invert clocks?
  103697. + *
  103698. + * The BCM approach seems to be inverted to the classical I2S approach.
  103699. + */
  103700. + switch (dev->fmt & SND_SOC_DAIFMT_INV_MASK) {
  103701. + case SND_SOC_DAIFMT_NB_NF:
  103702. + /* None. Therefore, both for BCM */
  103703. + mode |= BCM2708_I2S_CLKI;
  103704. + mode |= BCM2708_I2S_FSI;
  103705. + break;
  103706. + case SND_SOC_DAIFMT_IB_IF:
  103707. + /* Both. Therefore, none for BCM */
  103708. + break;
  103709. + case SND_SOC_DAIFMT_NB_IF:
  103710. + /*
  103711. + * Invert only frame sync. Therefore,
  103712. + * invert only bit clock for BCM
  103713. + */
  103714. + mode |= BCM2708_I2S_CLKI;
  103715. + break;
  103716. + case SND_SOC_DAIFMT_IB_NF:
  103717. + /*
  103718. + * Invert only bit clock. Therefore,
  103719. + * invert only frame sync for BCM
  103720. + */
  103721. + mode |= BCM2708_I2S_FSI;
  103722. + break;
  103723. + default:
  103724. + return -EINVAL;
  103725. + }
  103726. +
  103727. + regmap_write(dev->i2s_regmap, BCM2708_I2S_MODE_A_REG, mode);
  103728. +
  103729. + /* Setup the DMA parameters */
  103730. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  103731. + BCM2708_I2S_RXTHR(1)
  103732. + | BCM2708_I2S_TXTHR(1)
  103733. + | BCM2708_I2S_DMAEN, 0xffffffff);
  103734. +
  103735. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_DREQ_A_REG,
  103736. + BCM2708_I2S_TX_PANIC(0x10)
  103737. + | BCM2708_I2S_RX_PANIC(0x30)
  103738. + | BCM2708_I2S_TX(0x30)
  103739. + | BCM2708_I2S_RX(0x20), 0xffffffff);
  103740. +
  103741. + /* Clear FIFOs */
  103742. + bcm2708_i2s_clear_fifos(dev, true, true);
  103743. +
  103744. + return 0;
  103745. +}
  103746. +
  103747. +static int bcm2708_i2s_prepare(struct snd_pcm_substream *substream,
  103748. + struct snd_soc_dai *dai)
  103749. +{
  103750. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  103751. + uint32_t cs_reg;
  103752. +
  103753. + bcm2708_i2s_start_clock(dev);
  103754. +
  103755. + /*
  103756. + * Clear both FIFOs if the one that should be started
  103757. + * is not empty at the moment. This should only happen
  103758. + * after overrun. Otherwise, hw_params would have cleared
  103759. + * the FIFO.
  103760. + */
  103761. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &cs_reg);
  103762. +
  103763. + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK
  103764. + && !(cs_reg & BCM2708_I2S_TXE))
  103765. + bcm2708_i2s_clear_fifos(dev, true, false);
  103766. + else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE
  103767. + && (cs_reg & BCM2708_I2S_RXD))
  103768. + bcm2708_i2s_clear_fifos(dev, false, true);
  103769. +
  103770. + return 0;
  103771. +}
  103772. +
  103773. +static void bcm2708_i2s_stop(struct bcm2708_i2s_dev *dev,
  103774. + struct snd_pcm_substream *substream,
  103775. + struct snd_soc_dai *dai)
  103776. +{
  103777. + uint32_t mask;
  103778. +
  103779. + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  103780. + mask = BCM2708_I2S_RXON;
  103781. + else
  103782. + mask = BCM2708_I2S_TXON;
  103783. +
  103784. + regmap_update_bits(dev->i2s_regmap,
  103785. + BCM2708_I2S_CS_A_REG, mask, 0);
  103786. +
  103787. + /* Stop also the clock when not SND_SOC_DAIFMT_CONT */
  103788. + if (!dai->active && !(dev->fmt & SND_SOC_DAIFMT_CONT))
  103789. + bcm2708_i2s_stop_clock(dev);
  103790. +}
  103791. +
  103792. +static int bcm2708_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
  103793. + struct snd_soc_dai *dai)
  103794. +{
  103795. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  103796. + uint32_t mask;
  103797. +
  103798. + switch (cmd) {
  103799. + case SNDRV_PCM_TRIGGER_START:
  103800. + case SNDRV_PCM_TRIGGER_RESUME:
  103801. + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  103802. + bcm2708_i2s_start_clock(dev);
  103803. +
  103804. + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  103805. + mask = BCM2708_I2S_RXON;
  103806. + else
  103807. + mask = BCM2708_I2S_TXON;
  103808. +
  103809. + regmap_update_bits(dev->i2s_regmap,
  103810. + BCM2708_I2S_CS_A_REG, mask, mask);
  103811. + break;
  103812. +
  103813. + case SNDRV_PCM_TRIGGER_STOP:
  103814. + case SNDRV_PCM_TRIGGER_SUSPEND:
  103815. + case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  103816. + bcm2708_i2s_stop(dev, substream, dai);
  103817. + break;
  103818. + default:
  103819. + return -EINVAL;
  103820. + }
  103821. +
  103822. + return 0;
  103823. +}
  103824. +
  103825. +static int bcm2708_i2s_startup(struct snd_pcm_substream *substream,
  103826. + struct snd_soc_dai *dai)
  103827. +{
  103828. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  103829. +
  103830. + if (dai->active)
  103831. + return 0;
  103832. +
  103833. + /* Should this still be running stop it */
  103834. + bcm2708_i2s_stop_clock(dev);
  103835. +
  103836. + /* Enable PCM block */
  103837. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  103838. + BCM2708_I2S_EN, BCM2708_I2S_EN);
  103839. +
  103840. + /*
  103841. + * Disable STBY.
  103842. + * Requires at least 4 PCM clock cycles to take effect.
  103843. + */
  103844. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  103845. + BCM2708_I2S_STBY, BCM2708_I2S_STBY);
  103846. +
  103847. + return 0;
  103848. +}
  103849. +
  103850. +static void bcm2708_i2s_shutdown(struct snd_pcm_substream *substream,
  103851. + struct snd_soc_dai *dai)
  103852. +{
  103853. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  103854. +
  103855. + bcm2708_i2s_stop(dev, substream, dai);
  103856. +
  103857. + /* If both streams are stopped, disable module and clock */
  103858. + if (dai->active)
  103859. + return;
  103860. +
  103861. + /* Disable the module */
  103862. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  103863. + BCM2708_I2S_EN, 0);
  103864. +
  103865. + /*
  103866. + * Stopping clock is necessary, because stop does
  103867. + * not stop the clock when SND_SOC_DAIFMT_CONT
  103868. + */
  103869. + bcm2708_i2s_stop_clock(dev);
  103870. +}
  103871. +
  103872. +static const struct snd_soc_dai_ops bcm2708_i2s_dai_ops = {
  103873. + .startup = bcm2708_i2s_startup,
  103874. + .shutdown = bcm2708_i2s_shutdown,
  103875. + .prepare = bcm2708_i2s_prepare,
  103876. + .trigger = bcm2708_i2s_trigger,
  103877. + .hw_params = bcm2708_i2s_hw_params,
  103878. + .set_fmt = bcm2708_i2s_set_dai_fmt,
  103879. + .set_bclk_ratio = bcm2708_i2s_set_dai_bclk_ratio
  103880. +};
  103881. +
  103882. +static int bcm2708_i2s_dai_probe(struct snd_soc_dai *dai)
  103883. +{
  103884. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  103885. +
  103886. + dai->playback_dma_data = &dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK];
  103887. + dai->capture_dma_data = &dev->dma_data[SNDRV_PCM_STREAM_CAPTURE];
  103888. +
  103889. + return 0;
  103890. +}
  103891. +
  103892. +static struct snd_soc_dai_driver bcm2708_i2s_dai = {
  103893. + .name = "bcm2708-i2s",
  103894. + .probe = bcm2708_i2s_dai_probe,
  103895. + .playback = {
  103896. + .channels_min = 2,
  103897. + .channels_max = 2,
  103898. + .rates = SNDRV_PCM_RATE_8000_192000,
  103899. + .formats = SNDRV_PCM_FMTBIT_S16_LE
  103900. + // | SNDRV_PCM_FMTBIT_S24_LE : disable for now, it causes white noise with xbmc
  103901. + | SNDRV_PCM_FMTBIT_S32_LE
  103902. + },
  103903. + .capture = {
  103904. + .channels_min = 2,
  103905. + .channels_max = 2,
  103906. + .rates = SNDRV_PCM_RATE_8000_192000,
  103907. + .formats = SNDRV_PCM_FMTBIT_S16_LE
  103908. + | SNDRV_PCM_FMTBIT_S24_LE
  103909. + | SNDRV_PCM_FMTBIT_S32_LE
  103910. + },
  103911. + .ops = &bcm2708_i2s_dai_ops,
  103912. + .symmetric_rates = 1
  103913. +};
  103914. +
  103915. +static bool bcm2708_i2s_volatile_reg(struct device *dev, unsigned int reg)
  103916. +{
  103917. + switch (reg) {
  103918. + case BCM2708_I2S_CS_A_REG:
  103919. + case BCM2708_I2S_FIFO_A_REG:
  103920. + case BCM2708_I2S_INTSTC_A_REG:
  103921. + case BCM2708_I2S_GRAY_REG:
  103922. + return true;
  103923. + default:
  103924. + return false;
  103925. + };
  103926. +}
  103927. +
  103928. +static bool bcm2708_i2s_precious_reg(struct device *dev, unsigned int reg)
  103929. +{
  103930. + switch (reg) {
  103931. + case BCM2708_I2S_FIFO_A_REG:
  103932. + return true;
  103933. + default:
  103934. + return false;
  103935. + };
  103936. +}
  103937. +
  103938. +static bool bcm2708_clk_volatile_reg(struct device *dev, unsigned int reg)
  103939. +{
  103940. + switch (reg) {
  103941. + case BCM2708_CLK_PCMCTL_REG:
  103942. + return true;
  103943. + default:
  103944. + return false;
  103945. + };
  103946. +}
  103947. +
  103948. +static const struct regmap_config bcm2708_regmap_config[] = {
  103949. + {
  103950. + .reg_bits = 32,
  103951. + .reg_stride = 4,
  103952. + .val_bits = 32,
  103953. + .max_register = BCM2708_I2S_GRAY_REG,
  103954. + .precious_reg = bcm2708_i2s_precious_reg,
  103955. + .volatile_reg = bcm2708_i2s_volatile_reg,
  103956. + .cache_type = REGCACHE_RBTREE,
  103957. + },
  103958. + {
  103959. + .reg_bits = 32,
  103960. + .reg_stride = 4,
  103961. + .val_bits = 32,
  103962. + .max_register = BCM2708_CLK_PCMDIV_REG,
  103963. + .volatile_reg = bcm2708_clk_volatile_reg,
  103964. + .cache_type = REGCACHE_RBTREE,
  103965. + },
  103966. +};
  103967. +
  103968. +static const struct snd_soc_component_driver bcm2708_i2s_component = {
  103969. + .name = "bcm2708-i2s-comp",
  103970. +};
  103971. +
  103972. +
  103973. +static void bcm2708_i2s_setup_gpio(void)
  103974. +{
  103975. + /*
  103976. + * This is the common way to handle the GPIO pins for
  103977. + * the Raspberry Pi.
  103978. + * TODO Better way would be to handle
  103979. + * this in the device tree!
  103980. + */
  103981. +#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
  103982. +#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
  103983. +
  103984. + unsigned int *gpio;
  103985. + int pin;
  103986. + gpio = ioremap(GPIO_BASE, SZ_16K);
  103987. +
  103988. + /* SPI is on GPIO 7..11 */
  103989. + for (pin = 28; pin <= 31; pin++) {
  103990. + INP_GPIO(pin); /* set mode to GPIO input first */
  103991. + SET_GPIO_ALT(pin, 2); /* set mode to ALT 0 */
  103992. + }
  103993. +#undef INP_GPIO
  103994. +#undef SET_GPIO_ALT
  103995. +}
  103996. +
  103997. +static const struct snd_pcm_hardware bcm2708_pcm_hardware = {
  103998. + .info = SNDRV_PCM_INFO_INTERLEAVED |
  103999. + SNDRV_PCM_INFO_JOINT_DUPLEX,
  104000. + .formats = SNDRV_PCM_FMTBIT_S16_LE |
  104001. + SNDRV_PCM_FMTBIT_S24_LE |
  104002. + SNDRV_PCM_FMTBIT_S32_LE,
  104003. + .period_bytes_min = 32,
  104004. + .period_bytes_max = 64 * PAGE_SIZE,
  104005. + .periods_min = 2,
  104006. + .periods_max = 255,
  104007. + .buffer_bytes_max = 128 * PAGE_SIZE,
  104008. +};
  104009. +
  104010. +static const struct snd_dmaengine_pcm_config bcm2708_dmaengine_pcm_config = {
  104011. + .prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config,
  104012. + .pcm_hardware = &bcm2708_pcm_hardware,
  104013. + .prealloc_buffer_size = 256 * PAGE_SIZE,
  104014. +};
  104015. +
  104016. +
  104017. +static int bcm2708_i2s_probe(struct platform_device *pdev)
  104018. +{
  104019. + struct bcm2708_i2s_dev *dev;
  104020. + int i;
  104021. + int ret;
  104022. + struct regmap *regmap[2];
  104023. + struct resource *mem[2];
  104024. +
  104025. + /* Request both ioareas */
  104026. + for (i = 0; i <= 1; i++) {
  104027. + void __iomem *base;
  104028. +
  104029. + mem[i] = platform_get_resource(pdev, IORESOURCE_MEM, i);
  104030. + base = devm_ioremap_resource(&pdev->dev, mem[i]);
  104031. + if (IS_ERR(base))
  104032. + return PTR_ERR(base);
  104033. +
  104034. + regmap[i] = devm_regmap_init_mmio(&pdev->dev, base,
  104035. + &bcm2708_regmap_config[i]);
  104036. + if (IS_ERR(regmap[i])) {
  104037. + dev_err(&pdev->dev, "I2S probe: regmap init failed\n");
  104038. + return PTR_ERR(regmap[i]);
  104039. + }
  104040. + }
  104041. +
  104042. + dev = devm_kzalloc(&pdev->dev, sizeof(*dev),
  104043. + GFP_KERNEL);
  104044. + if (IS_ERR(dev))
  104045. + return PTR_ERR(dev);
  104046. +
  104047. + bcm2708_i2s_setup_gpio();
  104048. +
  104049. + dev->i2s_regmap = regmap[0];
  104050. + dev->clk_regmap = regmap[1];
  104051. +
  104052. + /* Set the DMA address */
  104053. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].addr =
  104054. + (dma_addr_t)BCM2708_I2S_FIFO_PHYSICAL_ADDR;
  104055. +
  104056. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].addr =
  104057. + (dma_addr_t)BCM2708_I2S_FIFO_PHYSICAL_ADDR;
  104058. +
  104059. + /* Set the DREQ */
  104060. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].slave_id =
  104061. + BCM2708_DMA_DREQ_PCM_TX;
  104062. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].slave_id =
  104063. + BCM2708_DMA_DREQ_PCM_RX;
  104064. +
  104065. + /* Set the bus width */
  104066. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].addr_width =
  104067. + DMA_SLAVE_BUSWIDTH_4_BYTES;
  104068. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].addr_width =
  104069. + DMA_SLAVE_BUSWIDTH_4_BYTES;
  104070. +
  104071. + /* Set burst */
  104072. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].maxburst = 2;
  104073. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].maxburst = 2;
  104074. +
  104075. + /* BCLK ratio - use default */
  104076. + dev->bclk_ratio = 0;
  104077. +
  104078. + /* Store the pdev */
  104079. + dev->dev = &pdev->dev;
  104080. + dev_set_drvdata(&pdev->dev, dev);
  104081. +
  104082. + ret = snd_soc_register_component(&pdev->dev,
  104083. + &bcm2708_i2s_component, &bcm2708_i2s_dai, 1);
  104084. +
  104085. + if (ret) {
  104086. + dev_err(&pdev->dev, "Could not register DAI: %d\n", ret);
  104087. + ret = -ENOMEM;
  104088. + return ret;
  104089. + }
  104090. +
  104091. + ret = snd_dmaengine_pcm_register(&pdev->dev,
  104092. + &bcm2708_dmaengine_pcm_config,
  104093. + SND_DMAENGINE_PCM_FLAG_COMPAT);
  104094. + if (ret) {
  104095. + dev_err(&pdev->dev, "Could not register PCM: %d\n", ret);
  104096. + snd_soc_unregister_component(&pdev->dev);
  104097. + return ret;
  104098. + }
  104099. +
  104100. + return 0;
  104101. +}
  104102. +
  104103. +static int bcm2708_i2s_remove(struct platform_device *pdev)
  104104. +{
  104105. + snd_dmaengine_pcm_unregister(&pdev->dev);
  104106. + snd_soc_unregister_component(&pdev->dev);
  104107. + return 0;
  104108. +}
  104109. +
  104110. +static struct platform_driver bcm2708_i2s_driver = {
  104111. + .probe = bcm2708_i2s_probe,
  104112. + .remove = bcm2708_i2s_remove,
  104113. + .driver = {
  104114. + .name = "bcm2708-i2s",
  104115. + .owner = THIS_MODULE,
  104116. + },
  104117. +};
  104118. +
  104119. +module_platform_driver(bcm2708_i2s_driver);
  104120. +
  104121. +MODULE_ALIAS("platform:bcm2708-i2s");
  104122. +MODULE_DESCRIPTION("BCM2708 I2S interface");
  104123. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  104124. +MODULE_LICENSE("GPL v2");
  104125. diff -Nur linux-3.12.26.orig/sound/soc/bcm/hifiberry_dac.c linux-3.12.26/sound/soc/bcm/hifiberry_dac.c
  104126. --- linux-3.12.26.orig/sound/soc/bcm/hifiberry_dac.c 1970-01-01 01:00:00.000000000 +0100
  104127. +++ linux-3.12.26/sound/soc/bcm/hifiberry_dac.c 2014-08-06 16:50:15.205967899 +0200
  104128. @@ -0,0 +1,100 @@
  104129. +/*
  104130. + * ASoC Driver for HifiBerry DAC
  104131. + *
  104132. + * Author: Florian Meier <florian.meier@koalo.de>
  104133. + * Copyright 2013
  104134. + *
  104135. + * This program is free software; you can redistribute it and/or
  104136. + * modify it under the terms of the GNU General Public License
  104137. + * version 2 as published by the Free Software Foundation.
  104138. + *
  104139. + * This program is distributed in the hope that it will be useful, but
  104140. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  104141. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  104142. + * General Public License for more details.
  104143. + */
  104144. +
  104145. +#include <linux/module.h>
  104146. +#include <linux/platform_device.h>
  104147. +
  104148. +#include <sound/core.h>
  104149. +#include <sound/pcm.h>
  104150. +#include <sound/pcm_params.h>
  104151. +#include <sound/soc.h>
  104152. +#include <sound/jack.h>
  104153. +
  104154. +static int snd_rpi_hifiberry_dac_init(struct snd_soc_pcm_runtime *rtd)
  104155. +{
  104156. + return 0;
  104157. +}
  104158. +
  104159. +static int snd_rpi_hifiberry_dac_hw_params(struct snd_pcm_substream *substream,
  104160. + struct snd_pcm_hw_params *params)
  104161. +{
  104162. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  104163. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  104164. +
  104165. + unsigned int sample_bits =
  104166. + snd_pcm_format_physical_width(params_format(params));
  104167. +
  104168. + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
  104169. +}
  104170. +
  104171. +/* machine stream operations */
  104172. +static struct snd_soc_ops snd_rpi_hifiberry_dac_ops = {
  104173. + .hw_params = snd_rpi_hifiberry_dac_hw_params,
  104174. +};
  104175. +
  104176. +static struct snd_soc_dai_link snd_rpi_hifiberry_dac_dai[] = {
  104177. +{
  104178. + .name = "HifiBerry DAC",
  104179. + .stream_name = "HifiBerry DAC HiFi",
  104180. + .cpu_dai_name = "bcm2708-i2s.0",
  104181. + .codec_dai_name = "pcm5102a-hifi",
  104182. + .platform_name = "bcm2708-i2s.0",
  104183. + .codec_name = "pcm5102a-codec",
  104184. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  104185. + SND_SOC_DAIFMT_CBS_CFS,
  104186. + .ops = &snd_rpi_hifiberry_dac_ops,
  104187. + .init = snd_rpi_hifiberry_dac_init,
  104188. +},
  104189. +};
  104190. +
  104191. +/* audio machine driver */
  104192. +static struct snd_soc_card snd_rpi_hifiberry_dac = {
  104193. + .name = "snd_rpi_hifiberry_dac",
  104194. + .dai_link = snd_rpi_hifiberry_dac_dai,
  104195. + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dac_dai),
  104196. +};
  104197. +
  104198. +static int snd_rpi_hifiberry_dac_probe(struct platform_device *pdev)
  104199. +{
  104200. + int ret = 0;
  104201. +
  104202. + snd_rpi_hifiberry_dac.dev = &pdev->dev;
  104203. + ret = snd_soc_register_card(&snd_rpi_hifiberry_dac);
  104204. + if (ret)
  104205. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  104206. +
  104207. + return ret;
  104208. +}
  104209. +
  104210. +static int snd_rpi_hifiberry_dac_remove(struct platform_device *pdev)
  104211. +{
  104212. + return snd_soc_unregister_card(&snd_rpi_hifiberry_dac);
  104213. +}
  104214. +
  104215. +static struct platform_driver snd_rpi_hifiberry_dac_driver = {
  104216. + .driver = {
  104217. + .name = "snd-hifiberry-dac",
  104218. + .owner = THIS_MODULE,
  104219. + },
  104220. + .probe = snd_rpi_hifiberry_dac_probe,
  104221. + .remove = snd_rpi_hifiberry_dac_remove,
  104222. +};
  104223. +
  104224. +module_platform_driver(snd_rpi_hifiberry_dac_driver);
  104225. +
  104226. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  104227. +MODULE_DESCRIPTION("ASoC Driver for HifiBerry DAC");
  104228. +MODULE_LICENSE("GPL v2");
  104229. diff -Nur linux-3.12.26.orig/sound/soc/bcm/hifiberry_digi.c linux-3.12.26/sound/soc/bcm/hifiberry_digi.c
  104230. --- linux-3.12.26.orig/sound/soc/bcm/hifiberry_digi.c 1970-01-01 01:00:00.000000000 +0100
  104231. +++ linux-3.12.26/sound/soc/bcm/hifiberry_digi.c 2014-08-06 16:50:15.205967899 +0200
  104232. @@ -0,0 +1,153 @@
  104233. +/*
  104234. + * ASoC Driver for HifiBerry Digi
  104235. + *
  104236. + * Author: Daniel Matuschek <info@crazy-audio.com>
  104237. + * based on the HifiBerry DAC driver by Florian Meier <florian.meier@koalo.de>
  104238. + * Copyright 2013
  104239. + *
  104240. + * This program is free software; you can redistribute it and/or
  104241. + * modify it under the terms of the GNU General Public License
  104242. + * version 2 as published by the Free Software Foundation.
  104243. + *
  104244. + * This program is distributed in the hope that it will be useful, but
  104245. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  104246. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  104247. + * General Public License for more details.
  104248. + */
  104249. +
  104250. +#include <linux/module.h>
  104251. +#include <linux/platform_device.h>
  104252. +
  104253. +#include <sound/core.h>
  104254. +#include <sound/pcm.h>
  104255. +#include <sound/pcm_params.h>
  104256. +#include <sound/soc.h>
  104257. +#include <sound/jack.h>
  104258. +
  104259. +#include "../codecs/wm8804.h"
  104260. +
  104261. +static int samplerate=44100;
  104262. +
  104263. +static int snd_rpi_hifiberry_digi_init(struct snd_soc_pcm_runtime *rtd)
  104264. +{
  104265. + struct snd_soc_codec *codec = rtd->codec;
  104266. +
  104267. + /* enable TX output */
  104268. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
  104269. +
  104270. + return 0;
  104271. +}
  104272. +
  104273. +static int snd_rpi_hifiberry_digi_hw_params(struct snd_pcm_substream *substream,
  104274. + struct snd_pcm_hw_params *params)
  104275. +{
  104276. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  104277. + struct snd_soc_dai *codec_dai = rtd->codec_dai;
  104278. + struct snd_soc_codec *codec = rtd->codec;
  104279. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  104280. +
  104281. + int sysclk = 27000000; /* This is fixed on this board */
  104282. +
  104283. + long mclk_freq=0;
  104284. + int mclk_div=1;
  104285. +
  104286. + int ret;
  104287. +
  104288. + samplerate = params_rate(params);
  104289. +
  104290. + switch (samplerate) {
  104291. + case 44100:
  104292. + case 48000:
  104293. + case 88200:
  104294. + case 96000:
  104295. + mclk_freq=samplerate*256;
  104296. + mclk_div=WM8804_MCLKDIV_256FS;
  104297. + break;
  104298. + case 176400:
  104299. + case 192000:
  104300. + mclk_freq=samplerate*128;
  104301. + mclk_div=WM8804_MCLKDIV_128FS;
  104302. + break;
  104303. + default:
  104304. + dev_err(substream->pcm->dev,
  104305. + "Failed to set WM8804 SYSCLK, unsupported samplerate\n");
  104306. + }
  104307. +
  104308. + snd_soc_dai_set_clkdiv(codec_dai, WM8804_MCLK_DIV, mclk_div);
  104309. + snd_soc_dai_set_pll(codec_dai, 0, 0, sysclk, mclk_freq);
  104310. +
  104311. + ret = snd_soc_dai_set_sysclk(codec_dai, WM8804_TX_CLKSRC_PLL,
  104312. + sysclk, SND_SOC_CLOCK_OUT);
  104313. + if (ret < 0) {
  104314. + dev_err(substream->pcm->dev,
  104315. + "Failed to set WM8804 SYSCLK: %d\n", ret);
  104316. + return ret;
  104317. + }
  104318. +
  104319. + /* Enable TX output */
  104320. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
  104321. +
  104322. + /* Power on */
  104323. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x9, 0);
  104324. +
  104325. + return snd_soc_dai_set_bclk_ratio(cpu_dai,64);
  104326. +}
  104327. +
  104328. +/* machine stream operations */
  104329. +static struct snd_soc_ops snd_rpi_hifiberry_digi_ops = {
  104330. + .hw_params = snd_rpi_hifiberry_digi_hw_params,
  104331. +};
  104332. +
  104333. +static struct snd_soc_dai_link snd_rpi_hifiberry_digi_dai[] = {
  104334. +{
  104335. + .name = "HifiBerry Digi",
  104336. + .stream_name = "HifiBerry Digi HiFi",
  104337. + .cpu_dai_name = "bcm2708-i2s.0",
  104338. + .codec_dai_name = "wm8804-spdif",
  104339. + .platform_name = "bcm2708-i2s.0",
  104340. + .codec_name = "wm8804.1-003b",
  104341. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  104342. + SND_SOC_DAIFMT_CBM_CFM,
  104343. + .ops = &snd_rpi_hifiberry_digi_ops,
  104344. + .init = snd_rpi_hifiberry_digi_init,
  104345. +},
  104346. +};
  104347. +
  104348. +/* audio machine driver */
  104349. +static struct snd_soc_card snd_rpi_hifiberry_digi = {
  104350. + .name = "snd_rpi_hifiberry_digi",
  104351. + .dai_link = snd_rpi_hifiberry_digi_dai,
  104352. + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_digi_dai),
  104353. +};
  104354. +
  104355. +static int snd_rpi_hifiberry_digi_probe(struct platform_device *pdev)
  104356. +{
  104357. + int ret = 0;
  104358. +
  104359. + snd_rpi_hifiberry_digi.dev = &pdev->dev;
  104360. + ret = snd_soc_register_card(&snd_rpi_hifiberry_digi);
  104361. + if (ret)
  104362. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  104363. +
  104364. + return ret;
  104365. +}
  104366. +
  104367. +static int snd_rpi_hifiberry_digi_remove(struct platform_device *pdev)
  104368. +{
  104369. + return snd_soc_unregister_card(&snd_rpi_hifiberry_digi);
  104370. +}
  104371. +
  104372. +static struct platform_driver snd_rpi_hifiberry_digi_driver = {
  104373. + .driver = {
  104374. + .name = "snd-hifiberry-digi",
  104375. + .owner = THIS_MODULE,
  104376. + },
  104377. + .probe = snd_rpi_hifiberry_digi_probe,
  104378. + .remove = snd_rpi_hifiberry_digi_remove,
  104379. +};
  104380. +
  104381. +module_platform_driver(snd_rpi_hifiberry_digi_driver);
  104382. +
  104383. +MODULE_AUTHOR("Daniel Matuschek <info@crazy-audio.com>");
  104384. +MODULE_DESCRIPTION("ASoC Driver for HifiBerry Digi");
  104385. +MODULE_LICENSE("GPL v2");
  104386. diff -Nur linux-3.12.26.orig/sound/soc/bcm/iqaudio-dac.c linux-3.12.26/sound/soc/bcm/iqaudio-dac.c
  104387. --- linux-3.12.26.orig/sound/soc/bcm/iqaudio-dac.c 1970-01-01 01:00:00.000000000 +0100
  104388. +++ linux-3.12.26/sound/soc/bcm/iqaudio-dac.c 2014-08-06 16:50:15.205967899 +0200
  104389. @@ -0,0 +1,111 @@
  104390. +/*
  104391. + * ASoC Driver for IQaudIO DAC
  104392. + *
  104393. + * Author: Florian Meier <florian.meier@koalo.de>
  104394. + * Copyright 2013
  104395. + *
  104396. + * This program is free software; you can redistribute it and/or
  104397. + * modify it under the terms of the GNU General Public License
  104398. + * version 2 as published by the Free Software Foundation.
  104399. + *
  104400. + * This program is distributed in the hope that it will be useful, but
  104401. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  104402. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  104403. + * General Public License for more details.
  104404. + */
  104405. +
  104406. +#include <linux/module.h>
  104407. +#include <linux/platform_device.h>
  104408. +
  104409. +#include <sound/core.h>
  104410. +#include <sound/pcm.h>
  104411. +#include <sound/pcm_params.h>
  104412. +#include <sound/soc.h>
  104413. +#include <sound/jack.h>
  104414. +
  104415. +static int snd_rpi_iqaudio_dac_init(struct snd_soc_pcm_runtime *rtd)
  104416. +{
  104417. +// NOT USED struct snd_soc_codec *codec = rtd->codec;
  104418. +
  104419. + return 0;
  104420. +}
  104421. +
  104422. +static int snd_rpi_iqaudio_dac_hw_params(struct snd_pcm_substream *substream,
  104423. + struct snd_pcm_hw_params *params)
  104424. +{
  104425. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  104426. +// NOT USED struct snd_soc_dai *codec_dai = rtd->codec_dai;
  104427. +// NOT USED struct snd_soc_codec *codec = rtd->codec;
  104428. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  104429. +
  104430. + unsigned int sample_bits =
  104431. + snd_pcm_format_physical_width(params_format(params));
  104432. +
  104433. + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
  104434. +}
  104435. +
  104436. +/* machine stream operations */
  104437. +static struct snd_soc_ops snd_rpi_iqaudio_dac_ops = {
  104438. + .hw_params = snd_rpi_iqaudio_dac_hw_params,
  104439. +};
  104440. +
  104441. +static struct snd_soc_dai_link snd_rpi_iqaudio_dac_dai[] = {
  104442. +{
  104443. + .name = "IQaudIO DAC",
  104444. + .stream_name = "IQaudIO DAC HiFi",
  104445. + .cpu_dai_name = "bcm2708-i2s.0",
  104446. + .codec_dai_name = "pcm512x-hifi",
  104447. + .platform_name = "bcm2708-i2s.0",
  104448. + .codec_name = "pcm512x.1-004c",
  104449. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  104450. + SND_SOC_DAIFMT_CBS_CFS,
  104451. + .ops = &snd_rpi_iqaudio_dac_ops,
  104452. + .init = snd_rpi_iqaudio_dac_init,
  104453. +},
  104454. +};
  104455. +
  104456. +/* audio machine driver */
  104457. +static struct snd_soc_card snd_rpi_iqaudio_dac = {
  104458. + .name = "snd_rpi_iqaudio_dac",
  104459. + .dai_link = snd_rpi_iqaudio_dac_dai,
  104460. + .num_links = ARRAY_SIZE(snd_rpi_iqaudio_dac_dai),
  104461. +};
  104462. +
  104463. +static int snd_rpi_iqaudio_dac_probe(struct platform_device *pdev)
  104464. +{
  104465. + int ret = 0;
  104466. +
  104467. + snd_rpi_iqaudio_dac.dev = &pdev->dev;
  104468. + ret = snd_soc_register_card(&snd_rpi_iqaudio_dac);
  104469. + if (ret)
  104470. + dev_err(&pdev->dev,
  104471. + "snd_soc_register_card() failed: %d\n", ret);
  104472. +
  104473. + return ret;
  104474. +}
  104475. +
  104476. +static int snd_rpi_iqaudio_dac_remove(struct platform_device *pdev)
  104477. +{
  104478. + return snd_soc_unregister_card(&snd_rpi_iqaudio_dac);
  104479. +}
  104480. +
  104481. +static const struct of_device_id iqaudio_of_match[] = {
  104482. + { .compatible = "iqaudio,iqaudio-dac", },
  104483. + {},
  104484. +};
  104485. +
  104486. +static struct platform_driver snd_rpi_iqaudio_dac_driver = {
  104487. + .driver = {
  104488. + .name = "snd-rpi-iqaudio-dac",
  104489. + .owner = THIS_MODULE,
  104490. + .of_match_table = iqaudio_of_match,
  104491. + },
  104492. + .probe = snd_rpi_iqaudio_dac_probe,
  104493. + .remove = snd_rpi_iqaudio_dac_remove,
  104494. +};
  104495. +
  104496. +module_platform_driver(snd_rpi_iqaudio_dac_driver);
  104497. +
  104498. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  104499. +MODULE_DESCRIPTION("ASoC Driver for IQAudio DAC");
  104500. +MODULE_LICENSE("GPL v2");
  104501. diff -Nur linux-3.12.26.orig/sound/soc/bcm/Kconfig linux-3.12.26/sound/soc/bcm/Kconfig
  104502. --- linux-3.12.26.orig/sound/soc/bcm/Kconfig 1970-01-01 01:00:00.000000000 +0100
  104503. +++ linux-3.12.26/sound/soc/bcm/Kconfig 2014-08-06 16:50:15.205967899 +0200
  104504. @@ -0,0 +1,38 @@
  104505. +config SND_BCM2708_SOC_I2S
  104506. + tristate "SoC Audio support for the Broadcom BCM2708 I2S module"
  104507. + depends on MACH_BCM2708
  104508. + select REGMAP_MMIO
  104509. + select SND_SOC_DMAENGINE_PCM
  104510. + select SND_SOC_GENERIC_DMAENGINE_PCM
  104511. + help
  104512. + Say Y or M if you want to add support for codecs attached to
  104513. + the BCM2708 I2S interface. You will also need
  104514. + to select the audio interfaces to support below.
  104515. +
  104516. +config SND_BCM2708_SOC_HIFIBERRY_DAC
  104517. + tristate "Support for HifiBerry DAC"
  104518. + depends on SND_BCM2708_SOC_I2S
  104519. + select SND_SOC_PCM5102A
  104520. + help
  104521. + Say Y or M if you want to add support for HifiBerry DAC.
  104522. +
  104523. +config SND_BCM2708_SOC_HIFIBERRY_DIGI
  104524. + tristate "Support for HifiBerry Digi"
  104525. + depends on SND_BCM2708_SOC_I2S
  104526. + select SND_SOC_WM8804
  104527. + help
  104528. + Say Y or M if you want to add support for HifiBerry Digi S/PDIF output board.
  104529. +
  104530. +config SND_BCM2708_SOC_RPI_DAC
  104531. + tristate "Support for RPi-DAC"
  104532. + depends on SND_BCM2708_SOC_I2S
  104533. + select SND_SOC_PCM1794A
  104534. + help
  104535. + Say Y or M if you want to add support for RPi-DAC.
  104536. +
  104537. +config SND_BCM2708_SOC_IQAUDIO_DAC
  104538. + tristate "Support for IQaudIO-DAC"
  104539. + depends on SND_BCM2708_SOC_I2S
  104540. + select SND_SOC_PCM512x
  104541. + help
  104542. + Say Y or M if you want to add support for IQaudIO-DAC.
  104543. diff -Nur linux-3.12.26.orig/sound/soc/bcm/Makefile linux-3.12.26/sound/soc/bcm/Makefile
  104544. --- linux-3.12.26.orig/sound/soc/bcm/Makefile 1970-01-01 01:00:00.000000000 +0100
  104545. +++ linux-3.12.26/sound/soc/bcm/Makefile 2014-08-06 16:50:15.205967899 +0200
  104546. @@ -0,0 +1,15 @@
  104547. +# BCM2708 Platform Support
  104548. +snd-soc-bcm2708-i2s-objs := bcm2708-i2s.o
  104549. +
  104550. +obj-$(CONFIG_SND_BCM2708_SOC_I2S) += snd-soc-bcm2708-i2s.o
  104551. +
  104552. +# BCM2708 Machine Support
  104553. +snd-soc-hifiberry-dac-objs := hifiberry_dac.o
  104554. +snd-soc-hifiberry-digi-objs := hifiberry_digi.o
  104555. +snd-soc-rpi-dac-objs := rpi-dac.o
  104556. +snd-soc-iqaudio-dac-objs := iqaudio-dac.o
  104557. +
  104558. +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
  104559. +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) += snd-soc-hifiberry-digi.o
  104560. +obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
  104561. +obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
  104562. diff -Nur linux-3.12.26.orig/sound/soc/bcm/rpi-dac.c linux-3.12.26/sound/soc/bcm/rpi-dac.c
  104563. --- linux-3.12.26.orig/sound/soc/bcm/rpi-dac.c 1970-01-01 01:00:00.000000000 +0100
  104564. +++ linux-3.12.26/sound/soc/bcm/rpi-dac.c 2014-08-06 16:50:15.209967931 +0200
  104565. @@ -0,0 +1,97 @@
  104566. +/*
  104567. + * ASoC Driver for RPi-DAC.
  104568. + *
  104569. + * Author: Florian Meier <florian.meier@koalo.de>
  104570. + * Copyright 2013
  104571. + *
  104572. + * This program is free software; you can redistribute it and/or
  104573. + * modify it under the terms of the GNU General Public License
  104574. + * version 2 as published by the Free Software Foundation.
  104575. + *
  104576. + * This program is distributed in the hope that it will be useful, but
  104577. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  104578. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  104579. + * General Public License for more details.
  104580. + */
  104581. +
  104582. +#include <linux/module.h>
  104583. +#include <linux/platform_device.h>
  104584. +
  104585. +#include <sound/core.h>
  104586. +#include <sound/pcm.h>
  104587. +#include <sound/pcm_params.h>
  104588. +#include <sound/soc.h>
  104589. +#include <sound/jack.h>
  104590. +
  104591. +static int snd_rpi_rpi_dac_init(struct snd_soc_pcm_runtime *rtd)
  104592. +{
  104593. + return 0;
  104594. +}
  104595. +
  104596. +static int snd_rpi_rpi_dac_hw_params(struct snd_pcm_substream *substream,
  104597. + struct snd_pcm_hw_params *params)
  104598. +{
  104599. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  104600. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  104601. +
  104602. + return snd_soc_dai_set_bclk_ratio(cpu_dai, 32*2);
  104603. +}
  104604. +
  104605. +/* machine stream operations */
  104606. +static struct snd_soc_ops snd_rpi_rpi_dac_ops = {
  104607. + .hw_params = snd_rpi_rpi_dac_hw_params,
  104608. +};
  104609. +
  104610. +static struct snd_soc_dai_link snd_rpi_rpi_dac_dai[] = {
  104611. +{
  104612. + .name = "HifiBerry Mini",
  104613. + .stream_name = "HifiBerry Mini HiFi",
  104614. + .cpu_dai_name = "bcm2708-i2s.0",
  104615. + .codec_dai_name = "pcm1794a-hifi",
  104616. + .platform_name = "bcm2708-i2s.0",
  104617. + .codec_name = "pcm1794a-codec",
  104618. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  104619. + SND_SOC_DAIFMT_CBS_CFS,
  104620. + .ops = &snd_rpi_rpi_dac_ops,
  104621. + .init = snd_rpi_rpi_dac_init,
  104622. +},
  104623. +};
  104624. +
  104625. +/* audio machine driver */
  104626. +static struct snd_soc_card snd_rpi_rpi_dac = {
  104627. + .name = "snd_rpi_rpi_dac",
  104628. + .dai_link = snd_rpi_rpi_dac_dai,
  104629. + .num_links = ARRAY_SIZE(snd_rpi_rpi_dac_dai),
  104630. +};
  104631. +
  104632. +static int snd_rpi_rpi_dac_probe(struct platform_device *pdev)
  104633. +{
  104634. + int ret = 0;
  104635. +
  104636. + snd_rpi_rpi_dac.dev = &pdev->dev;
  104637. + ret = snd_soc_register_card(&snd_rpi_rpi_dac);
  104638. + if (ret)
  104639. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  104640. +
  104641. + return ret;
  104642. +}
  104643. +
  104644. +static int snd_rpi_rpi_dac_remove(struct platform_device *pdev)
  104645. +{
  104646. + return snd_soc_unregister_card(&snd_rpi_rpi_dac);
  104647. +}
  104648. +
  104649. +static struct platform_driver snd_rpi_rpi_dac_driver = {
  104650. + .driver = {
  104651. + .name = "snd-rpi-dac",
  104652. + .owner = THIS_MODULE,
  104653. + },
  104654. + .probe = snd_rpi_rpi_dac_probe,
  104655. + .remove = snd_rpi_rpi_dac_remove,
  104656. +};
  104657. +
  104658. +module_platform_driver(snd_rpi_rpi_dac_driver);
  104659. +
  104660. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  104661. +MODULE_DESCRIPTION("ASoC Driver for RPi-DAC");
  104662. +MODULE_LICENSE("GPL v2");
  104663. diff -Nur linux-3.12.26.orig/sound/soc/codecs/Kconfig linux-3.12.26/sound/soc/codecs/Kconfig
  104664. --- linux-3.12.26.orig/sound/soc/codecs/Kconfig 2014-07-30 18:02:44.000000000 +0200
  104665. +++ linux-3.12.26/sound/soc/codecs/Kconfig 2014-08-06 16:50:15.209967931 +0200
  104666. @@ -59,6 +59,9 @@
  104667. select SND_SOC_PCM1681 if I2C
  104668. select SND_SOC_PCM1792A if SPI_MASTER
  104669. select SND_SOC_PCM3008
  104670. + select SND_SOC_PCM1794A
  104671. + select SND_SOC_PCM5102A
  104672. + select SND_SOC_PCM512x if SND_SOC_I2C_AND_SPI
  104673. select SND_SOC_RT5631 if I2C
  104674. select SND_SOC_RT5640 if I2C
  104675. select SND_SOC_SGTL5000 if I2C
  104676. @@ -311,6 +314,15 @@
  104677. config SND_SOC_PCM3008
  104678. tristate
  104679. +config SND_SOC_PCM1794A
  104680. + tristate
  104681. +
  104682. +config SND_SOC_PCM5102A
  104683. + tristate
  104684. +
  104685. +config SND_SOC_PCM512x
  104686. + tristate
  104687. +
  104688. config SND_SOC_RT5631
  104689. tristate
  104690. diff -Nur linux-3.12.26.orig/sound/soc/codecs/Makefile linux-3.12.26/sound/soc/codecs/Makefile
  104691. --- linux-3.12.26.orig/sound/soc/codecs/Makefile 2014-07-30 18:02:44.000000000 +0200
  104692. +++ linux-3.12.26/sound/soc/codecs/Makefile 2014-08-06 16:50:15.209967931 +0200
  104693. @@ -46,6 +46,9 @@
  104694. snd-soc-pcm1681-objs := pcm1681.o
  104695. snd-soc-pcm1792a-codec-objs := pcm1792a.o
  104696. snd-soc-pcm3008-objs := pcm3008.o
  104697. +snd-soc-pcm1794a-objs := pcm1794a.o
  104698. +snd-soc-pcm5102a-objs := pcm5102a.o
  104699. +snd-soc-pcm512x-objs := pcm512x.o
  104700. snd-soc-rt5631-objs := rt5631.o
  104701. snd-soc-rt5640-objs := rt5640.o
  104702. snd-soc-sgtl5000-objs := sgtl5000.o
  104703. @@ -179,6 +182,9 @@
  104704. obj-$(CONFIG_SND_SOC_PCM1681) += snd-soc-pcm1681.o
  104705. obj-$(CONFIG_SND_SOC_PCM1792A) += snd-soc-pcm1792a-codec.o
  104706. obj-$(CONFIG_SND_SOC_PCM3008) += snd-soc-pcm3008.o
  104707. +obj-$(CONFIG_SND_SOC_PCM1794A) += snd-soc-pcm1794a.o
  104708. +obj-$(CONFIG_SND_SOC_PCM5102A) += snd-soc-pcm5102a.o
  104709. +obj-$(CONFIG_SND_SOC_PCM512x) += snd-soc-pcm512x.o
  104710. obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o
  104711. obj-$(CONFIG_SND_SOC_RT5640) += snd-soc-rt5640.o
  104712. obj-$(CONFIG_SND_SOC_SGTL5000) += snd-soc-sgtl5000.o
  104713. diff -Nur linux-3.12.26.orig/sound/soc/codecs/pcm1794a.c linux-3.12.26/sound/soc/codecs/pcm1794a.c
  104714. --- linux-3.12.26.orig/sound/soc/codecs/pcm1794a.c 1970-01-01 01:00:00.000000000 +0100
  104715. +++ linux-3.12.26/sound/soc/codecs/pcm1794a.c 2014-08-06 16:50:15.209967931 +0200
  104716. @@ -0,0 +1,62 @@
  104717. +/*
  104718. + * Driver for the PCM1794A codec
  104719. + *
  104720. + * Author: Florian Meier <florian.meier@koalo.de>
  104721. + * Copyright 2013
  104722. + *
  104723. + * This program is free software; you can redistribute it and/or
  104724. + * modify it under the terms of the GNU General Public License
  104725. + * version 2 as published by the Free Software Foundation.
  104726. + *
  104727. + * This program is distributed in the hope that it will be useful, but
  104728. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  104729. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  104730. + * General Public License for more details.
  104731. + */
  104732. +
  104733. +
  104734. +#include <linux/init.h>
  104735. +#include <linux/module.h>
  104736. +#include <linux/platform_device.h>
  104737. +
  104738. +#include <sound/soc.h>
  104739. +
  104740. +static struct snd_soc_dai_driver pcm1794a_dai = {
  104741. + .name = "pcm1794a-hifi",
  104742. + .playback = {
  104743. + .channels_min = 2,
  104744. + .channels_max = 2,
  104745. + .rates = SNDRV_PCM_RATE_8000_192000,
  104746. + .formats = SNDRV_PCM_FMTBIT_S16_LE |
  104747. + SNDRV_PCM_FMTBIT_S24_LE
  104748. + },
  104749. +};
  104750. +
  104751. +static struct snd_soc_codec_driver soc_codec_dev_pcm1794a;
  104752. +
  104753. +static int pcm1794a_probe(struct platform_device *pdev)
  104754. +{
  104755. + return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_pcm1794a,
  104756. + &pcm1794a_dai, 1);
  104757. +}
  104758. +
  104759. +static int pcm1794a_remove(struct platform_device *pdev)
  104760. +{
  104761. + snd_soc_unregister_codec(&pdev->dev);
  104762. + return 0;
  104763. +}
  104764. +
  104765. +static struct platform_driver pcm1794a_codec_driver = {
  104766. + .probe = pcm1794a_probe,
  104767. + .remove = pcm1794a_remove,
  104768. + .driver = {
  104769. + .name = "pcm1794a-codec",
  104770. + .owner = THIS_MODULE,
  104771. + },
  104772. +};
  104773. +
  104774. +module_platform_driver(pcm1794a_codec_driver);
  104775. +
  104776. +MODULE_DESCRIPTION("ASoC PCM1794A codec driver");
  104777. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  104778. +MODULE_LICENSE("GPL v2");
  104779. diff -Nur linux-3.12.26.orig/sound/soc/codecs/pcm5102a.c linux-3.12.26/sound/soc/codecs/pcm5102a.c
  104780. --- linux-3.12.26.orig/sound/soc/codecs/pcm5102a.c 1970-01-01 01:00:00.000000000 +0100
  104781. +++ linux-3.12.26/sound/soc/codecs/pcm5102a.c 2014-08-06 16:50:15.209967931 +0200
  104782. @@ -0,0 +1,63 @@
  104783. +/*
  104784. + * Driver for the PCM5102A codec
  104785. + *
  104786. + * Author: Florian Meier <florian.meier@koalo.de>
  104787. + * Copyright 2013
  104788. + *
  104789. + * This program is free software; you can redistribute it and/or
  104790. + * modify it under the terms of the GNU General Public License
  104791. + * version 2 as published by the Free Software Foundation.
  104792. + *
  104793. + * This program is distributed in the hope that it will be useful, but
  104794. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  104795. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  104796. + * General Public License for more details.
  104797. + */
  104798. +
  104799. +
  104800. +#include <linux/init.h>
  104801. +#include <linux/module.h>
  104802. +#include <linux/platform_device.h>
  104803. +
  104804. +#include <sound/soc.h>
  104805. +
  104806. +static struct snd_soc_dai_driver pcm5102a_dai = {
  104807. + .name = "pcm5102a-hifi",
  104808. + .playback = {
  104809. + .channels_min = 2,
  104810. + .channels_max = 2,
  104811. + .rates = SNDRV_PCM_RATE_8000_192000,
  104812. + .formats = SNDRV_PCM_FMTBIT_S16_LE |
  104813. + // SNDRV_PCM_FMTBIT_S24_LE | : disable for now, it causes white noise with xbmc
  104814. + SNDRV_PCM_FMTBIT_S32_LE
  104815. + },
  104816. +};
  104817. +
  104818. +static struct snd_soc_codec_driver soc_codec_dev_pcm5102a;
  104819. +
  104820. +static int pcm5102a_probe(struct platform_device *pdev)
  104821. +{
  104822. + return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_pcm5102a,
  104823. + &pcm5102a_dai, 1);
  104824. +}
  104825. +
  104826. +static int pcm5102a_remove(struct platform_device *pdev)
  104827. +{
  104828. + snd_soc_unregister_codec(&pdev->dev);
  104829. + return 0;
  104830. +}
  104831. +
  104832. +static struct platform_driver pcm5102a_codec_driver = {
  104833. + .probe = pcm5102a_probe,
  104834. + .remove = pcm5102a_remove,
  104835. + .driver = {
  104836. + .name = "pcm5102a-codec",
  104837. + .owner = THIS_MODULE,
  104838. + },
  104839. +};
  104840. +
  104841. +module_platform_driver(pcm5102a_codec_driver);
  104842. +
  104843. +MODULE_DESCRIPTION("ASoC PCM5102A codec driver");
  104844. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  104845. +MODULE_LICENSE("GPL v2");
  104846. diff -Nur linux-3.12.26.orig/sound/soc/codecs/pcm512x.c linux-3.12.26/sound/soc/codecs/pcm512x.c
  104847. --- linux-3.12.26.orig/sound/soc/codecs/pcm512x.c 1970-01-01 01:00:00.000000000 +0100
  104848. +++ linux-3.12.26/sound/soc/codecs/pcm512x.c 2014-08-06 16:50:15.209967931 +0200
  104849. @@ -0,0 +1,678 @@
  104850. +/*
  104851. + * Driver for the PCM512x CODECs
  104852. + *
  104853. + * Author: Mark Brown <broonie@linaro.org>
  104854. + * Copyright 2014 Linaro Ltd
  104855. + *
  104856. + * This program is free software; you can redistribute it and/or
  104857. + * modify it under the terms of the GNU General Public License
  104858. + * version 2 as published by the Free Software Foundation.
  104859. + *
  104860. + * This program is distributed in the hope that it will be useful, but
  104861. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  104862. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  104863. + * General Public License for more details.
  104864. + */
  104865. +
  104866. +
  104867. +#include <linux/init.h>
  104868. +#include <linux/module.h>
  104869. +#include <linux/clk.h>
  104870. +#include <linux/i2c.h>
  104871. +#include <linux/pm_runtime.h>
  104872. +#include <linux/regmap.h>
  104873. +#include <linux/regulator/consumer.h>
  104874. +#include <linux/spi/spi.h>
  104875. +#include <sound/soc.h>
  104876. +#include <sound/soc-dapm.h>
  104877. +#include <sound/tlv.h>
  104878. +
  104879. +#include "pcm512x.h"
  104880. +
  104881. +#define PCM512x_NUM_SUPPLIES 3
  104882. +static const char *pcm512x_supply_names[PCM512x_NUM_SUPPLIES] = {
  104883. + "AVDD",
  104884. + "DVDD",
  104885. + "CPVDD",
  104886. +};
  104887. +
  104888. +struct pcm512x_priv {
  104889. + struct regmap *regmap;
  104890. + struct clk *sclk;
  104891. + struct regulator_bulk_data supplies[PCM512x_NUM_SUPPLIES];
  104892. + struct notifier_block supply_nb[PCM512x_NUM_SUPPLIES];
  104893. +};
  104894. +
  104895. +/*
  104896. + * We can't use the same notifier block for more than one supply and
  104897. + * there's no way I can see to get from a callback to the caller
  104898. + * except container_of().
  104899. + */
  104900. +#define PCM512x_REGULATOR_EVENT(n) \
  104901. +static int pcm512x_regulator_event_##n(struct notifier_block *nb, \
  104902. + unsigned long event, void *data) \
  104903. +{ \
  104904. + struct pcm512x_priv *pcm512x = container_of(nb, struct pcm512x_priv, \
  104905. + supply_nb[n]); \
  104906. + if (event & REGULATOR_EVENT_DISABLE) { \
  104907. + regcache_mark_dirty(pcm512x->regmap); \
  104908. + regcache_cache_only(pcm512x->regmap, true); \
  104909. + } \
  104910. + return 0; \
  104911. +}
  104912. +
  104913. +PCM512x_REGULATOR_EVENT(0)
  104914. +PCM512x_REGULATOR_EVENT(1)
  104915. +PCM512x_REGULATOR_EVENT(2)
  104916. +
  104917. +static const struct reg_default pcm512x_reg_defaults[] = {
  104918. + { PCM512x_RESET, 0x00 },
  104919. + { PCM512x_POWER, 0x00 },
  104920. + { PCM512x_MUTE, 0x00 },
  104921. + { PCM512x_DSP, 0x00 },
  104922. + { PCM512x_PLL_REF, 0x00 },
  104923. + { PCM512x_DAC_ROUTING, 0x11 },
  104924. + { PCM512x_DSP_PROGRAM, 0x01 },
  104925. + { PCM512x_CLKDET, 0x00 },
  104926. + { PCM512x_AUTO_MUTE, 0x00 },
  104927. + { PCM512x_ERROR_DETECT, 0x00 },
  104928. + { PCM512x_DIGITAL_VOLUME_1, 0x00 },
  104929. + { PCM512x_DIGITAL_VOLUME_2, 0x30 },
  104930. + { PCM512x_DIGITAL_VOLUME_3, 0x30 },
  104931. + { PCM512x_DIGITAL_MUTE_1, 0x22 },
  104932. + { PCM512x_DIGITAL_MUTE_2, 0x00 },
  104933. + { PCM512x_DIGITAL_MUTE_3, 0x07 },
  104934. +};
  104935. +
  104936. +static bool pcm512x_readable(struct device *dev, unsigned int reg)
  104937. +{
  104938. + switch (reg) {
  104939. + case PCM512x_RESET:
  104940. + case PCM512x_POWER:
  104941. + case PCM512x_MUTE:
  104942. + case PCM512x_PLL_EN:
  104943. + case PCM512x_SPI_MISO_FUNCTION:
  104944. + case PCM512x_DSP:
  104945. + case PCM512x_GPIO_EN:
  104946. + case PCM512x_BCLK_LRCLK_CFG:
  104947. + case PCM512x_DSP_GPIO_INPUT:
  104948. + case PCM512x_MASTER_MODE:
  104949. + case PCM512x_PLL_REF:
  104950. + case PCM512x_PLL_COEFF_0:
  104951. + case PCM512x_PLL_COEFF_1:
  104952. + case PCM512x_PLL_COEFF_2:
  104953. + case PCM512x_PLL_COEFF_3:
  104954. + case PCM512x_PLL_COEFF_4:
  104955. + case PCM512x_DSP_CLKDIV:
  104956. + case PCM512x_DAC_CLKDIV:
  104957. + case PCM512x_NCP_CLKDIV:
  104958. + case PCM512x_OSR_CLKDIV:
  104959. + case PCM512x_MASTER_CLKDIV_1:
  104960. + case PCM512x_MASTER_CLKDIV_2:
  104961. + case PCM512x_FS_SPEED_MODE:
  104962. + case PCM512x_IDAC_1:
  104963. + case PCM512x_IDAC_2:
  104964. + case PCM512x_ERROR_DETECT:
  104965. + case PCM512x_I2S_1:
  104966. + case PCM512x_I2S_2:
  104967. + case PCM512x_DAC_ROUTING:
  104968. + case PCM512x_DSP_PROGRAM:
  104969. + case PCM512x_CLKDET:
  104970. + case PCM512x_AUTO_MUTE:
  104971. + case PCM512x_DIGITAL_VOLUME_1:
  104972. + case PCM512x_DIGITAL_VOLUME_2:
  104973. + case PCM512x_DIGITAL_VOLUME_3:
  104974. + case PCM512x_DIGITAL_MUTE_1:
  104975. + case PCM512x_DIGITAL_MUTE_2:
  104976. + case PCM512x_DIGITAL_MUTE_3:
  104977. + case PCM512x_GPIO_OUTPUT_1:
  104978. + case PCM512x_GPIO_OUTPUT_2:
  104979. + case PCM512x_GPIO_OUTPUT_3:
  104980. + case PCM512x_GPIO_OUTPUT_4:
  104981. + case PCM512x_GPIO_OUTPUT_5:
  104982. + case PCM512x_GPIO_OUTPUT_6:
  104983. + case PCM512x_GPIO_CONTROL_1:
  104984. + case PCM512x_GPIO_CONTROL_2:
  104985. + case PCM512x_OVERFLOW:
  104986. + case PCM512x_RATE_DET_1:
  104987. + case PCM512x_RATE_DET_2:
  104988. + case PCM512x_RATE_DET_3:
  104989. + case PCM512x_RATE_DET_4:
  104990. + case PCM512x_ANALOG_MUTE_DET:
  104991. + case PCM512x_GPIN:
  104992. + case PCM512x_DIGITAL_MUTE_DET:
  104993. + return true;
  104994. + default:
  104995. + return false;
  104996. + }
  104997. +}
  104998. +
  104999. +static bool pcm512x_volatile(struct device *dev, unsigned int reg)
  105000. +{
  105001. + switch (reg) {
  105002. + case PCM512x_PLL_EN:
  105003. + case PCM512x_OVERFLOW:
  105004. + case PCM512x_RATE_DET_1:
  105005. + case PCM512x_RATE_DET_2:
  105006. + case PCM512x_RATE_DET_3:
  105007. + case PCM512x_RATE_DET_4:
  105008. + case PCM512x_ANALOG_MUTE_DET:
  105009. + case PCM512x_GPIN:
  105010. + case PCM512x_DIGITAL_MUTE_DET:
  105011. + return true;
  105012. + default:
  105013. + return false;
  105014. + }
  105015. +}
  105016. +
  105017. +static const DECLARE_TLV_DB_SCALE(digital_tlv, -10350, 50, 1);
  105018. +
  105019. +static const char *pcm512x_dsp_program_texts[] = {
  105020. + "FIR interpolation with de-emphasis",
  105021. + "Low latency IIR with de-emphasis",
  105022. + "High attenuation with de-emphasis",
  105023. + "Ringing-less low latency FIR",
  105024. +};
  105025. +
  105026. +static const unsigned int pcm512x_dsp_program_values[] = {
  105027. + 1,
  105028. + 2,
  105029. + 3,
  105030. + 5,
  105031. + 7,
  105032. +};
  105033. +
  105034. +static const SOC_VALUE_ENUM_SINGLE_DECL(pcm512x_dsp_program,
  105035. + PCM512x_DSP_PROGRAM, 0, 0x1f,
  105036. + pcm512x_dsp_program_texts,
  105037. + pcm512x_dsp_program_values);
  105038. +
  105039. +static const char *pcm512x_clk_missing_text[] = {
  105040. + "1s", "2s", "3s", "4s", "5s", "6s", "7s", "8s"
  105041. +};
  105042. +
  105043. +static const struct soc_enum pcm512x_clk_missing =
  105044. + SOC_ENUM_SINGLE(PCM512x_CLKDET, 0, 7, pcm512x_clk_missing_text);
  105045. +
  105046. +static const char *pcm512x_autom_text[] = {
  105047. + "21ms", "106ms", "213ms", "533ms", "1.07s", "2.13s", "5.33s", "10.66s"
  105048. +};
  105049. +
  105050. +static const struct soc_enum pcm512x_autom_l =
  105051. + SOC_ENUM_SINGLE(PCM512x_AUTO_MUTE, PCM512x_ATML_SHIFT, 7,
  105052. + pcm512x_autom_text);
  105053. +
  105054. +static const struct soc_enum pcm512x_autom_r =
  105055. + SOC_ENUM_SINGLE(PCM512x_AUTO_MUTE, PCM512x_ATMR_SHIFT, 7,
  105056. + pcm512x_autom_text);
  105057. +
  105058. +static const char *pcm512x_ramp_rate_text[] = {
  105059. + "1 sample/update", "2 samples/update", "4 samples/update",
  105060. + "Immediate"
  105061. +};
  105062. +
  105063. +static const struct soc_enum pcm512x_vndf =
  105064. + SOC_ENUM_SINGLE(PCM512x_DIGITAL_MUTE_1, PCM512x_VNDF_SHIFT, 4,
  105065. + pcm512x_ramp_rate_text);
  105066. +
  105067. +static const struct soc_enum pcm512x_vnuf =
  105068. + SOC_ENUM_SINGLE(PCM512x_DIGITAL_MUTE_1, PCM512x_VNUF_SHIFT, 4,
  105069. + pcm512x_ramp_rate_text);
  105070. +
  105071. +static const struct soc_enum pcm512x_vedf =
  105072. + SOC_ENUM_SINGLE(PCM512x_DIGITAL_MUTE_2, PCM512x_VEDF_SHIFT, 4,
  105073. + pcm512x_ramp_rate_text);
  105074. +
  105075. +static const char *pcm512x_ramp_step_text[] = {
  105076. + "4dB/step", "2dB/step", "1dB/step", "0.5dB/step"
  105077. +};
  105078. +
  105079. +static const struct soc_enum pcm512x_vnds =
  105080. + SOC_ENUM_SINGLE(PCM512x_DIGITAL_MUTE_1, PCM512x_VNDS_SHIFT, 4,
  105081. + pcm512x_ramp_step_text);
  105082. +
  105083. +static const struct soc_enum pcm512x_vnus =
  105084. + SOC_ENUM_SINGLE(PCM512x_DIGITAL_MUTE_1, PCM512x_VNUS_SHIFT, 4,
  105085. + pcm512x_ramp_step_text);
  105086. +
  105087. +static const struct soc_enum pcm512x_veds =
  105088. + SOC_ENUM_SINGLE(PCM512x_DIGITAL_MUTE_2, PCM512x_VEDS_SHIFT, 4,
  105089. + pcm512x_ramp_step_text);
  105090. +
  105091. +/* Don't let the DAC go into clipping by limiting the alsa volume control range */
  105092. +static const struct snd_kcontrol_new pcm512x_controls[] = {
  105093. +SOC_DOUBLE_R_RANGE_TLV("Playback Digital Volume", PCM512x_DIGITAL_VOLUME_2,
  105094. + PCM512x_DIGITAL_VOLUME_3, 0, 40, 255, 1, digital_tlv),
  105095. +SOC_DOUBLE("Playback Digital Switch", PCM512x_MUTE, PCM512x_RQML_SHIFT,
  105096. + PCM512x_RQMR_SHIFT, 1, 1),
  105097. +
  105098. +SOC_SINGLE("Deemphasis Switch", PCM512x_DSP, PCM512x_DEMP_SHIFT, 1, 1),
  105099. +SOC_VALUE_ENUM("DSP Program", pcm512x_dsp_program),
  105100. +
  105101. +SOC_ENUM("Clock Missing Period", pcm512x_clk_missing),
  105102. +SOC_ENUM("Auto Mute Time Left", pcm512x_autom_l),
  105103. +SOC_ENUM("Auto Mute Time Right", pcm512x_autom_r),
  105104. +SOC_SINGLE("Auto Mute Mono Switch", PCM512x_DIGITAL_MUTE_3,
  105105. + PCM512x_ACTL_SHIFT, 1, 0),
  105106. +SOC_DOUBLE("Auto Mute Switch", PCM512x_DIGITAL_MUTE_3, PCM512x_AMLE_SHIFT,
  105107. + PCM512x_AMLR_SHIFT, 1, 0),
  105108. +
  105109. +SOC_ENUM("Volume Ramp Down Rate", pcm512x_vndf),
  105110. +SOC_ENUM("Volume Ramp Down Step", pcm512x_vnds),
  105111. +SOC_ENUM("Volume Ramp Up Rate", pcm512x_vnuf),
  105112. +SOC_ENUM("Volume Ramp Up Step", pcm512x_vnus),
  105113. +SOC_ENUM("Volume Ramp Down Emergency Rate", pcm512x_vedf),
  105114. +SOC_ENUM("Volume Ramp Down Emergency Step", pcm512x_veds),
  105115. +};
  105116. +
  105117. +static const struct snd_soc_dapm_widget pcm512x_dapm_widgets[] = {
  105118. +SND_SOC_DAPM_DAC("DACL", NULL, SND_SOC_NOPM, 0, 0),
  105119. +SND_SOC_DAPM_DAC("DACR", NULL, SND_SOC_NOPM, 0, 0),
  105120. +
  105121. +SND_SOC_DAPM_OUTPUT("OUTL"),
  105122. +SND_SOC_DAPM_OUTPUT("OUTR"),
  105123. +};
  105124. +
  105125. +static const struct snd_soc_dapm_route pcm512x_dapm_routes[] = {
  105126. + { "DACL", NULL, "Playback" },
  105127. + { "DACR", NULL, "Playback" },
  105128. +
  105129. + { "OUTL", NULL, "DACL" },
  105130. + { "OUTR", NULL, "DACR" },
  105131. +};
  105132. +
  105133. +static int pcm512x_set_bias_level(struct snd_soc_codec *codec,
  105134. + enum snd_soc_bias_level level)
  105135. +{
  105136. + struct pcm512x_priv *pcm512x = dev_get_drvdata(codec->dev);
  105137. + int ret;
  105138. +
  105139. + switch (level) {
  105140. + case SND_SOC_BIAS_ON:
  105141. + case SND_SOC_BIAS_PREPARE:
  105142. + break;
  105143. +
  105144. + case SND_SOC_BIAS_STANDBY:
  105145. + ret = regmap_update_bits(pcm512x->regmap, PCM512x_POWER,
  105146. + PCM512x_RQST, 0);
  105147. + if (ret != 0) {
  105148. + dev_err(codec->dev, "Failed to remove standby: %d\n",
  105149. + ret);
  105150. + return ret;
  105151. + }
  105152. + break;
  105153. +
  105154. + case SND_SOC_BIAS_OFF:
  105155. + ret = regmap_update_bits(pcm512x->regmap, PCM512x_POWER,
  105156. + PCM512x_RQST, PCM512x_RQST);
  105157. + if (ret != 0) {
  105158. + dev_err(codec->dev, "Failed to request standby: %d\n",
  105159. + ret);
  105160. + return ret;
  105161. + }
  105162. + break;
  105163. + }
  105164. +
  105165. + codec->dapm.bias_level = level;
  105166. +
  105167. + return 0;
  105168. +}
  105169. +
  105170. +static struct snd_soc_dai_driver pcm512x_dai = {
  105171. + .name = "pcm512x-hifi",
  105172. + .playback = {
  105173. + .stream_name = "Playback",
  105174. + .channels_min = 2,
  105175. + .channels_max = 2,
  105176. + .rates = SNDRV_PCM_RATE_8000_192000,
  105177. + .formats = SNDRV_PCM_FMTBIT_S16_LE |
  105178. + SNDRV_PCM_FMTBIT_S24_LE |
  105179. + SNDRV_PCM_FMTBIT_S32_LE
  105180. + },
  105181. +};
  105182. +
  105183. +static struct snd_soc_codec_driver pcm512x_codec_driver = {
  105184. + .set_bias_level = pcm512x_set_bias_level,
  105185. + .idle_bias_off = true,
  105186. +
  105187. + .controls = pcm512x_controls,
  105188. + .num_controls = ARRAY_SIZE(pcm512x_controls),
  105189. + .dapm_widgets = pcm512x_dapm_widgets,
  105190. + .num_dapm_widgets = ARRAY_SIZE(pcm512x_dapm_widgets),
  105191. + .dapm_routes = pcm512x_dapm_routes,
  105192. + .num_dapm_routes = ARRAY_SIZE(pcm512x_dapm_routes),
  105193. +};
  105194. +
  105195. +static const struct regmap_config pcm512x_regmap = {
  105196. + .reg_bits = 8,
  105197. + .val_bits = 8,
  105198. +
  105199. + .readable_reg = pcm512x_readable,
  105200. + .volatile_reg = pcm512x_volatile,
  105201. +
  105202. + .max_register = PCM512x_MAX_REGISTER,
  105203. + .reg_defaults = pcm512x_reg_defaults,
  105204. + .num_reg_defaults = ARRAY_SIZE(pcm512x_reg_defaults),
  105205. + .cache_type = REGCACHE_RBTREE,
  105206. +};
  105207. +
  105208. +static const struct of_device_id pcm512x_of_match[] = {
  105209. + { .compatible = "ti,pcm5121", },
  105210. + { .compatible = "ti,pcm5122", },
  105211. + { }
  105212. +};
  105213. +MODULE_DEVICE_TABLE(of, pcm512x_of_match);
  105214. +
  105215. +static int pcm512x_probe(struct device *dev, struct regmap *regmap)
  105216. +{
  105217. + struct pcm512x_priv *pcm512x;
  105218. + int i, ret;
  105219. +
  105220. + pcm512x = devm_kzalloc(dev, sizeof(struct pcm512x_priv), GFP_KERNEL);
  105221. + if (!pcm512x)
  105222. + return -ENOMEM;
  105223. +
  105224. + dev_set_drvdata(dev, pcm512x);
  105225. + pcm512x->regmap = regmap;
  105226. +
  105227. + for (i = 0; i < ARRAY_SIZE(pcm512x->supplies); i++)
  105228. + pcm512x->supplies[i].supply = pcm512x_supply_names[i];
  105229. +
  105230. + ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(pcm512x->supplies),
  105231. + pcm512x->supplies);
  105232. + if (ret != 0) {
  105233. + dev_err(dev, "Failed to get supplies: %d\n", ret);
  105234. + return ret;
  105235. + }
  105236. +
  105237. + pcm512x->supply_nb[0].notifier_call = pcm512x_regulator_event_0;
  105238. + pcm512x->supply_nb[1].notifier_call = pcm512x_regulator_event_1;
  105239. + pcm512x->supply_nb[2].notifier_call = pcm512x_regulator_event_2;
  105240. +
  105241. + for (i = 0; i < ARRAY_SIZE(pcm512x->supplies); i++) {
  105242. + ret = regulator_register_notifier(pcm512x->supplies[i].consumer,
  105243. + &pcm512x->supply_nb[i]);
  105244. + if (ret != 0) {
  105245. + dev_err(dev,
  105246. + "Failed to register regulator notifier: %d\n",
  105247. + ret);
  105248. + }
  105249. + }
  105250. +
  105251. + ret = regulator_bulk_enable(ARRAY_SIZE(pcm512x->supplies),
  105252. + pcm512x->supplies);
  105253. + if (ret != 0) {
  105254. + dev_err(dev, "Failed to enable supplies: %d\n", ret);
  105255. + return ret;
  105256. + }
  105257. +
  105258. + /* Reset the device, verifying I/O in the process for I2C */
  105259. + ret = regmap_write(regmap, PCM512x_RESET,
  105260. + PCM512x_RSTM | PCM512x_RSTR);
  105261. + if (ret != 0) {
  105262. + dev_err(dev, "Failed to reset device: %d\n", ret);
  105263. + goto err;
  105264. + }
  105265. +
  105266. + ret = regmap_write(regmap, PCM512x_RESET, 0);
  105267. + if (ret != 0) {
  105268. + dev_err(dev, "Failed to reset device: %d\n", ret);
  105269. + goto err;
  105270. + }
  105271. +
  105272. + pcm512x->sclk = devm_clk_get(dev, NULL);
  105273. + if (IS_ERR(pcm512x->sclk)) {
  105274. + if (PTR_ERR(pcm512x->sclk) == -EPROBE_DEFER)
  105275. + return -EPROBE_DEFER;
  105276. +
  105277. + dev_info(dev, "No SCLK, using BCLK: %ld\n",
  105278. + PTR_ERR(pcm512x->sclk));
  105279. +
  105280. + /* Disable reporting of missing SCLK as an error */
  105281. + regmap_update_bits(regmap, PCM512x_ERROR_DETECT,
  105282. + PCM512x_IDCH, PCM512x_IDCH);
  105283. +
  105284. + /* Switch PLL input to BCLK */
  105285. + regmap_update_bits(regmap, PCM512x_PLL_REF,
  105286. + PCM512x_SREF, PCM512x_SREF);
  105287. + } else {
  105288. + ret = clk_prepare_enable(pcm512x->sclk);
  105289. + if (ret != 0) {
  105290. + dev_err(dev, "Failed to enable SCLK: %d\n", ret);
  105291. + return ret;
  105292. + }
  105293. + }
  105294. +
  105295. + /* Default to standby mode */
  105296. + ret = regmap_update_bits(pcm512x->regmap, PCM512x_POWER,
  105297. + PCM512x_RQST, PCM512x_RQST);
  105298. + if (ret != 0) {
  105299. + dev_err(dev, "Failed to request standby: %d\n",
  105300. + ret);
  105301. + goto err_clk;
  105302. + }
  105303. +
  105304. + pm_runtime_set_active(dev);
  105305. + pm_runtime_enable(dev);
  105306. + pm_runtime_idle(dev);
  105307. +
  105308. + ret = snd_soc_register_codec(dev, &pcm512x_codec_driver,
  105309. + &pcm512x_dai, 1);
  105310. + if (ret != 0) {
  105311. + dev_err(dev, "Failed to register CODEC: %d\n", ret);
  105312. + goto err_pm;
  105313. + }
  105314. +
  105315. + dev_info(dev, "Completed initialisation - pcm512x_probe");
  105316. +
  105317. + return 0;
  105318. +
  105319. +err_pm:
  105320. + pm_runtime_disable(dev);
  105321. +err_clk:
  105322. + if (!IS_ERR(pcm512x->sclk))
  105323. + clk_disable_unprepare(pcm512x->sclk);
  105324. +err:
  105325. + regulator_bulk_disable(ARRAY_SIZE(pcm512x->supplies),
  105326. + pcm512x->supplies);
  105327. + return ret;
  105328. +}
  105329. +
  105330. +static void pcm512x_remove(struct device *dev)
  105331. +{
  105332. + struct pcm512x_priv *pcm512x = dev_get_drvdata(dev);
  105333. +
  105334. + snd_soc_unregister_codec(dev);
  105335. + pm_runtime_disable(dev);
  105336. + if (!IS_ERR(pcm512x->sclk))
  105337. + clk_disable_unprepare(pcm512x->sclk);
  105338. + regulator_bulk_disable(ARRAY_SIZE(pcm512x->supplies),
  105339. + pcm512x->supplies);
  105340. +}
  105341. +
  105342. +/* TODO
  105343. +static int pcm512x_suspend(struct device *dev)
  105344. +{
  105345. + struct pcm512x_priv *pcm512x = dev_get_drvdata(dev);
  105346. + int ret;
  105347. +
  105348. + ret = regmap_update_bits(pcm512x->regmap, PCM512x_POWER,
  105349. + PCM512x_RQPD, PCM512x_RQPD);
  105350. + if (ret != 0) {
  105351. + dev_err(dev, "Failed to request power down: %d\n", ret);
  105352. + return ret;
  105353. + }
  105354. +
  105355. + ret = regulator_bulk_disable(ARRAY_SIZE(pcm512x->supplies),
  105356. + pcm512x->supplies);
  105357. + if (ret != 0) {
  105358. + dev_err(dev, "Failed to disable supplies: %d\n", ret);
  105359. + return ret;
  105360. + }
  105361. +
  105362. + if (!IS_ERR(pcm512x->sclk))
  105363. + clk_disable_unprepare(pcm512x->sclk);
  105364. +
  105365. + return 0;
  105366. +}
  105367. +
  105368. +static int pcm512x_resume(struct device *dev)
  105369. +{
  105370. + struct pcm512x_priv *pcm512x = dev_get_drvdata(dev);
  105371. + int ret;
  105372. +
  105373. + if (!IS_ERR(pcm512x->sclk)) {
  105374. + ret = clk_prepare_enable(pcm512x->sclk);
  105375. + if (ret != 0) {
  105376. + dev_err(dev, "Failed to enable SCLK: %d\n", ret);
  105377. + return ret;
  105378. + }
  105379. + }
  105380. +
  105381. + ret = regulator_bulk_enable(ARRAY_SIZE(pcm512x->supplies),
  105382. + pcm512x->supplies);
  105383. + if (ret != 0) {
  105384. + dev_err(dev, "Failed to enable supplies: %d\n", ret);
  105385. + return ret;
  105386. + }
  105387. +
  105388. + regcache_cache_only(pcm512x->regmap, false);
  105389. + ret = regcache_sync(pcm512x->regmap);
  105390. + if (ret != 0) {
  105391. + dev_err(dev, "Failed to sync cache: %d\n", ret);
  105392. + return ret;
  105393. + }
  105394. +
  105395. + ret = regmap_update_bits(pcm512x->regmap, PCM512x_POWER,
  105396. + PCM512x_RQPD, 0);
  105397. + if (ret != 0) {
  105398. + dev_err(dev, "Failed to remove power down: %d\n", ret);
  105399. + return ret;
  105400. + }
  105401. +
  105402. + return 0;
  105403. +}
  105404. +
  105405. +// END OF PCM512x_suspend and resume calls TODO
  105406. +*/
  105407. +
  105408. +static const struct dev_pm_ops pcm512x_pm_ops = {
  105409. + SET_RUNTIME_PM_OPS(pcm512x_suspend, pcm512x_resume, NULL)
  105410. +};
  105411. +
  105412. +#if IS_ENABLED(CONFIG_I2C)
  105413. +static int pcm512x_i2c_probe(struct i2c_client *i2c,
  105414. + const struct i2c_device_id *id)
  105415. +{
  105416. + struct regmap *regmap;
  105417. +
  105418. + regmap = devm_regmap_init_i2c(i2c, &pcm512x_regmap);
  105419. + if (IS_ERR(regmap))
  105420. + return PTR_ERR(regmap);
  105421. +
  105422. + return pcm512x_probe(&i2c->dev, regmap);
  105423. +}
  105424. +
  105425. +static int pcm512x_i2c_remove(struct i2c_client *i2c)
  105426. +{
  105427. + pcm512x_remove(&i2c->dev);
  105428. + return 0;
  105429. +}
  105430. +
  105431. +static const struct i2c_device_id pcm512x_i2c_id[] = {
  105432. + { "pcm5121", },
  105433. + { "pcm5122", },
  105434. + { }
  105435. +};
  105436. +MODULE_DEVICE_TABLE(i2c, pcm512x_i2c_id);
  105437. +
  105438. +static struct i2c_driver pcm512x_i2c_driver = {
  105439. + .probe = pcm512x_i2c_probe,
  105440. + .remove = pcm512x_i2c_remove,
  105441. + .id_table = pcm512x_i2c_id,
  105442. + .driver = {
  105443. + .name = "pcm512x",
  105444. + .owner = THIS_MODULE,
  105445. + .of_match_table = pcm512x_of_match,
  105446. + .pm = &pcm512x_pm_ops,
  105447. + },
  105448. +};
  105449. +#endif
  105450. +
  105451. +#if defined(CONFIG_SPI_MASTER)
  105452. +static int pcm512x_spi_probe(struct spi_device *spi)
  105453. +{
  105454. + struct regmap *regmap;
  105455. + int ret;
  105456. +
  105457. + regmap = devm_regmap_init_spi(spi, &pcm512x_regmap);
  105458. + if (IS_ERR(regmap)) {
  105459. + ret = PTR_ERR(regmap);
  105460. + return ret;
  105461. + }
  105462. +
  105463. + return pcm512x_probe(&spi->dev, regmap);
  105464. +}
  105465. +
  105466. +static int pcm512x_spi_remove(struct spi_device *spi)
  105467. +{
  105468. + pcm512x_remove(&spi->dev);
  105469. + return 0;
  105470. +}
  105471. +
  105472. +static const struct spi_device_id pcm512x_spi_id[] = {
  105473. + { "pcm5121", },
  105474. + { "pcm5122", },
  105475. + { },
  105476. +};
  105477. +MODULE_DEVICE_TABLE(spi, pcm512x_spi_id);
  105478. +
  105479. +static struct spi_driver pcm512x_spi_driver = {
  105480. + .probe = pcm512x_spi_probe,
  105481. + .remove = pcm512x_spi_remove,
  105482. + .id_table = pcm512x_spi_id,
  105483. + .driver = {
  105484. + .name = "pcm512x",
  105485. + .owner = THIS_MODULE,
  105486. + .of_match_table = pcm512x_of_match,
  105487. + .pm = &pcm512x_pm_ops,
  105488. + },
  105489. +};
  105490. +#endif
  105491. +
  105492. +static int __init pcm512x_modinit(void)
  105493. +{
  105494. + int ret = 0;
  105495. +
  105496. +#if IS_ENABLED(CONFIG_I2C)
  105497. + ret = i2c_add_driver(&pcm512x_i2c_driver);
  105498. + if (ret) {
  105499. + printk(KERN_ERR "Failed to register pcm512x I2C driver: %d\n",
  105500. + ret);
  105501. + }
  105502. +#endif
  105503. +#if defined(CONFIG_SPI_MASTER)
  105504. + ret = spi_register_driver(&pcm512x_spi_driver);
  105505. + if (ret != 0) {
  105506. + printk(KERN_ERR "Failed to register pcm512x SPI driver: %d\n",
  105507. + ret);
  105508. + }
  105509. +#endif
  105510. + return ret;
  105511. +}
  105512. +module_init(pcm512x_modinit);
  105513. +
  105514. +static void __exit pcm512x_exit(void)
  105515. +{
  105516. +#if IS_ENABLED(CONFIG_I2C)
  105517. + i2c_del_driver(&pcm512x_i2c_driver);
  105518. +#endif
  105519. +#if defined(CONFIG_SPI_MASTER)
  105520. + spi_unregister_driver(&pcm512x_spi_driver);
  105521. +#endif
  105522. +}
  105523. +module_exit(pcm512x_exit);
  105524. +
  105525. +MODULE_DESCRIPTION("ASoC PCM512x codec driver");
  105526. +MODULE_AUTHOR("Mark Brown <broonie@linaro.org>");
  105527. +MODULE_LICENSE("GPL v2");
  105528. diff -Nur linux-3.12.26.orig/sound/soc/codecs/pcm512x.h linux-3.12.26/sound/soc/codecs/pcm512x.h
  105529. --- linux-3.12.26.orig/sound/soc/codecs/pcm512x.h 1970-01-01 01:00:00.000000000 +0100
  105530. +++ linux-3.12.26/sound/soc/codecs/pcm512x.h 2014-08-06 16:50:15.209967931 +0200
  105531. @@ -0,0 +1,142 @@
  105532. +/*
  105533. + * Driver for the PCM512x CODECs
  105534. + *
  105535. + * Author: Mark Brown <broonie@linaro.org>
  105536. + * Copyright 2014 Linaro Ltd
  105537. + *
  105538. + * This program is free software; you can redistribute it and/or
  105539. + * modify it under the terms of the GNU General Public License
  105540. + * version 2 as published by the Free Software Foundation.
  105541. + *
  105542. + * This program is distributed in the hope that it will be useful, but
  105543. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  105544. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  105545. + * General Public License for more details.
  105546. + */
  105547. +
  105548. +#ifndef _SND_SOC_PCM512X
  105549. +#define _SND_SOC_PCM512X
  105550. +
  105551. +#define PCM512x_PAGE_0_BASE 0
  105552. +
  105553. +#define PCM512x_PAGE 0
  105554. +
  105555. +#define PCM512x_RESET (PCM512x_PAGE_0_BASE + 1)
  105556. +#define PCM512x_POWER (PCM512x_PAGE_0_BASE + 2)
  105557. +#define PCM512x_MUTE (PCM512x_PAGE_0_BASE + 3)
  105558. +#define PCM512x_PLL_EN (PCM512x_PAGE_0_BASE + 4)
  105559. +#define PCM512x_SPI_MISO_FUNCTION (PCM512x_PAGE_0_BASE + 6)
  105560. +#define PCM512x_DSP (PCM512x_PAGE_0_BASE + 7)
  105561. +#define PCM512x_GPIO_EN (PCM512x_PAGE_0_BASE + 8)
  105562. +#define PCM512x_BCLK_LRCLK_CFG (PCM512x_PAGE_0_BASE + 9)
  105563. +#define PCM512x_DSP_GPIO_INPUT (PCM512x_PAGE_0_BASE + 10)
  105564. +#define PCM512x_MASTER_MODE (PCM512x_PAGE_0_BASE + 12)
  105565. +#define PCM512x_PLL_REF (PCM512x_PAGE_0_BASE + 13)
  105566. +#define PCM512x_PLL_COEFF_0 (PCM512x_PAGE_0_BASE + 20)
  105567. +#define PCM512x_PLL_COEFF_1 (PCM512x_PAGE_0_BASE + 21)
  105568. +#define PCM512x_PLL_COEFF_2 (PCM512x_PAGE_0_BASE + 22)
  105569. +#define PCM512x_PLL_COEFF_3 (PCM512x_PAGE_0_BASE + 23)
  105570. +#define PCM512x_PLL_COEFF_4 (PCM512x_PAGE_0_BASE + 24)
  105571. +#define PCM512x_DSP_CLKDIV (PCM512x_PAGE_0_BASE + 27)
  105572. +#define PCM512x_DAC_CLKDIV (PCM512x_PAGE_0_BASE + 28)
  105573. +#define PCM512x_NCP_CLKDIV (PCM512x_PAGE_0_BASE + 29)
  105574. +#define PCM512x_OSR_CLKDIV (PCM512x_PAGE_0_BASE + 30)
  105575. +#define PCM512x_MASTER_CLKDIV_1 (PCM512x_PAGE_0_BASE + 32)
  105576. +#define PCM512x_MASTER_CLKDIV_2 (PCM512x_PAGE_0_BASE + 33)
  105577. +#define PCM512x_FS_SPEED_MODE (PCM512x_PAGE_0_BASE + 34)
  105578. +#define PCM512x_IDAC_1 (PCM512x_PAGE_0_BASE + 35)
  105579. +#define PCM512x_IDAC_2 (PCM512x_PAGE_0_BASE + 36)
  105580. +#define PCM512x_ERROR_DETECT (PCM512x_PAGE_0_BASE + 37)
  105581. +#define PCM512x_I2S_1 (PCM512x_PAGE_0_BASE + 40)
  105582. +#define PCM512x_I2S_2 (PCM512x_PAGE_0_BASE + 41)
  105583. +#define PCM512x_DAC_ROUTING (PCM512x_PAGE_0_BASE + 42)
  105584. +#define PCM512x_DSP_PROGRAM (PCM512x_PAGE_0_BASE + 43)
  105585. +#define PCM512x_CLKDET (PCM512x_PAGE_0_BASE + 44)
  105586. +#define PCM512x_AUTO_MUTE (PCM512x_PAGE_0_BASE + 59)
  105587. +#define PCM512x_DIGITAL_VOLUME_1 (PCM512x_PAGE_0_BASE + 60)
  105588. +#define PCM512x_DIGITAL_VOLUME_2 (PCM512x_PAGE_0_BASE + 61)
  105589. +#define PCM512x_DIGITAL_VOLUME_3 (PCM512x_PAGE_0_BASE + 62)
  105590. +#define PCM512x_DIGITAL_MUTE_1 (PCM512x_PAGE_0_BASE + 63)
  105591. +#define PCM512x_DIGITAL_MUTE_2 (PCM512x_PAGE_0_BASE + 64)
  105592. +#define PCM512x_DIGITAL_MUTE_3 (PCM512x_PAGE_0_BASE + 65)
  105593. +#define PCM512x_GPIO_OUTPUT_1 (PCM512x_PAGE_0_BASE + 80)
  105594. +#define PCM512x_GPIO_OUTPUT_2 (PCM512x_PAGE_0_BASE + 81)
  105595. +#define PCM512x_GPIO_OUTPUT_3 (PCM512x_PAGE_0_BASE + 82)
  105596. +#define PCM512x_GPIO_OUTPUT_4 (PCM512x_PAGE_0_BASE + 83)
  105597. +#define PCM512x_GPIO_OUTPUT_5 (PCM512x_PAGE_0_BASE + 84)
  105598. +#define PCM512x_GPIO_OUTPUT_6 (PCM512x_PAGE_0_BASE + 85)
  105599. +#define PCM512x_GPIO_CONTROL_1 (PCM512x_PAGE_0_BASE + 86)
  105600. +#define PCM512x_GPIO_CONTROL_2 (PCM512x_PAGE_0_BASE + 87)
  105601. +#define PCM512x_OVERFLOW (PCM512x_PAGE_0_BASE + 90)
  105602. +#define PCM512x_RATE_DET_1 (PCM512x_PAGE_0_BASE + 91)
  105603. +#define PCM512x_RATE_DET_2 (PCM512x_PAGE_0_BASE + 92)
  105604. +#define PCM512x_RATE_DET_3 (PCM512x_PAGE_0_BASE + 93)
  105605. +#define PCM512x_RATE_DET_4 (PCM512x_PAGE_0_BASE + 94)
  105606. +#define PCM512x_ANALOG_MUTE_DET (PCM512x_PAGE_0_BASE + 108)
  105607. +#define PCM512x_GPIN (PCM512x_PAGE_0_BASE + 119)
  105608. +#define PCM512x_DIGITAL_MUTE_DET (PCM512x_PAGE_0_BASE + 120)
  105609. +
  105610. +#define PCM512x_MAX_REGISTER (PCM512x_PAGE_0_BASE + 120)
  105611. +
  105612. +/* Page 0, Register 1 - reset */
  105613. +#define PCM512x_RSTR (1 << 0)
  105614. +#define PCM512x_RSTM (1 << 4)
  105615. +
  105616. +/* Page 0, Register 2 - power */
  105617. +#define PCM512x_RQPD (1 << 0)
  105618. +#define PCM512x_RQPD_SHIFT 0
  105619. +#define PCM512x_RQST (1 << 4)
  105620. +#define PCM512x_RQST_SHIFT 4
  105621. +
  105622. +/* Page 0, Register 3 - mute */
  105623. +#define PCM512x_RQMR_SHIFT 0
  105624. +#define PCM512x_RQML_SHIFT 4
  105625. +
  105626. +/* Page 0, Register 4 - PLL */
  105627. +#define PCM512x_PLCE (1 << 0)
  105628. +#define PCM512x_RLCE_SHIFT 0
  105629. +#define PCM512x_PLCK (1 << 4)
  105630. +#define PCM512x_PLCK_SHIFT 4
  105631. +
  105632. +/* Page 0, Register 7 - DSP */
  105633. +#define PCM512x_SDSL (1 << 0)
  105634. +#define PCM512x_SDSL_SHIFT 0
  105635. +#define PCM512x_DEMP (1 << 4)
  105636. +#define PCM512x_DEMP_SHIFT 4
  105637. +
  105638. +/* Page 0, Register 13 - PLL reference */
  105639. +#define PCM512x_SREF (1 << 4)
  105640. +
  105641. +/* Page 0, Register 37 - Error detection */
  105642. +#define PCM512x_IPLK (1 << 0)
  105643. +#define PCM512x_DCAS (1 << 1)
  105644. +#define PCM512x_IDCM (1 << 2)
  105645. +#define PCM512x_IDCH (1 << 3)
  105646. +#define PCM512x_IDSK (1 << 4)
  105647. +#define PCM512x_IDBK (1 << 5)
  105648. +#define PCM512x_IDFS (1 << 6)
  105649. +
  105650. +/* Page 0, Register 42 - DAC routing */
  105651. +#define PCM512x_AUPR_SHIFT 0
  105652. +#define PCM512x_AUPL_SHIFT 4
  105653. +
  105654. +/* Page 0, Register 59 - auto mute */
  105655. +#define PCM512x_ATMR_SHIFT 0
  105656. +#define PCM512x_ATML_SHIFT 4
  105657. +
  105658. +/* Page 0, Register 63 - ramp rates */
  105659. +#define PCM512x_VNDF_SHIFT 6
  105660. +#define PCM512x_VNDS_SHIFT 4
  105661. +#define PCM512x_VNUF_SHIFT 2
  105662. +#define PCM512x_VNUS_SHIFT 0
  105663. +
  105664. +/* Page 0, Register 64 - emergency ramp rates */
  105665. +#define PCM512x_VEDF_SHIFT 6
  105666. +#define PCM512x_VEDS_SHIFT 4
  105667. +
  105668. +/* Page 0, Register 65 - Digital mute enables */
  105669. +#define PCM512x_ACTL_SHIFT 2
  105670. +#define PCM512x_AMLE_SHIFT 1
  105671. +#define PCM512x_AMLR_SHIFT 0
  105672. +
  105673. +#endif
  105674. diff -Nur linux-3.12.26.orig/sound/soc/codecs/wm8804.c linux-3.12.26/sound/soc/codecs/wm8804.c
  105675. --- linux-3.12.26.orig/sound/soc/codecs/wm8804.c 2014-07-30 18:02:44.000000000 +0200
  105676. +++ linux-3.12.26/sound/soc/codecs/wm8804.c 2014-08-06 16:50:15.213967961 +0200
  105677. @@ -63,6 +63,7 @@
  105678. struct regmap *regmap;
  105679. struct regulator_bulk_data supplies[WM8804_NUM_SUPPLIES];
  105680. struct notifier_block disable_nb[WM8804_NUM_SUPPLIES];
  105681. + int mclk_div;
  105682. };
  105683. static int txsrc_get(struct snd_kcontrol *kcontrol,
  105684. @@ -277,6 +278,7 @@
  105685. blen = 0x1;
  105686. break;
  105687. case SNDRV_PCM_FORMAT_S24_LE:
  105688. + case SNDRV_PCM_FORMAT_S32_LE:
  105689. blen = 0x2;
  105690. break;
  105691. default:
  105692. @@ -318,7 +320,7 @@
  105693. #define FIXED_PLL_SIZE ((1ULL << 22) * 10)
  105694. static int pll_factors(struct pll_div *pll_div, unsigned int target,
  105695. - unsigned int source)
  105696. + unsigned int source, unsigned int mclk_div)
  105697. {
  105698. u64 Kpart;
  105699. unsigned long int K, Ndiv, Nmod, tmp;
  105700. @@ -330,7 +332,8 @@
  105701. */
  105702. for (i = 0; i < ARRAY_SIZE(post_table); i++) {
  105703. tmp = target * post_table[i].div;
  105704. - if (tmp >= 90000000 && tmp <= 100000000) {
  105705. + if ((tmp >= 90000000 && tmp <= 100000000) &&
  105706. + (mclk_div == post_table[i].mclkdiv)) {
  105707. pll_div->freqmode = post_table[i].freqmode;
  105708. pll_div->mclkdiv = post_table[i].mclkdiv;
  105709. target *= post_table[i].div;
  105710. @@ -387,8 +390,11 @@
  105711. } else {
  105712. int ret;
  105713. struct pll_div pll_div;
  105714. + struct wm8804_priv *wm8804;
  105715. - ret = pll_factors(&pll_div, freq_out, freq_in);
  105716. + wm8804 = snd_soc_codec_get_drvdata(codec);
  105717. +
  105718. + ret = pll_factors(&pll_div, freq_out, freq_in, wm8804->mclk_div);
  105719. if (ret)
  105720. return ret;
  105721. @@ -452,6 +458,7 @@
  105722. int div_id, int div)
  105723. {
  105724. struct snd_soc_codec *codec;
  105725. + struct wm8804_priv *wm8804;
  105726. codec = dai->codec;
  105727. switch (div_id) {
  105728. @@ -459,6 +466,10 @@
  105729. snd_soc_update_bits(codec, WM8804_PLL5, 0x30,
  105730. (div & 0x3) << 4);
  105731. break;
  105732. + case WM8804_MCLK_DIV:
  105733. + wm8804 = snd_soc_codec_get_drvdata(codec);
  105734. + wm8804->mclk_div = div;
  105735. + break;
  105736. default:
  105737. dev_err(dai->dev, "Unknown clock divider: %d\n", div_id);
  105738. return -EINVAL;
  105739. @@ -641,7 +652,7 @@
  105740. };
  105741. #define WM8804_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
  105742. - SNDRV_PCM_FMTBIT_S24_LE)
  105743. + SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE)
  105744. #define WM8804_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
  105745. SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_64000 | \
  105746. @@ -674,7 +685,7 @@
  105747. .suspend = wm8804_suspend,
  105748. .resume = wm8804_resume,
  105749. .set_bias_level = wm8804_set_bias_level,
  105750. - .idle_bias_off = true,
  105751. + .idle_bias_off = false,
  105752. .controls = wm8804_snd_controls,
  105753. .num_controls = ARRAY_SIZE(wm8804_snd_controls),
  105754. diff -Nur linux-3.12.26.orig/sound/soc/codecs/wm8804.h linux-3.12.26/sound/soc/codecs/wm8804.h
  105755. --- linux-3.12.26.orig/sound/soc/codecs/wm8804.h 2014-07-30 18:02:44.000000000 +0200
  105756. +++ linux-3.12.26/sound/soc/codecs/wm8804.h 2014-08-06 16:50:15.213967961 +0200
  105757. @@ -57,5 +57,9 @@
  105758. #define WM8804_CLKOUT_SRC_OSCCLK 4
  105759. #define WM8804_CLKOUT_DIV 1
  105760. +#define WM8804_MCLK_DIV 2
  105761. +
  105762. +#define WM8804_MCLKDIV_256FS 0
  105763. +#define WM8804_MCLKDIV_128FS 1
  105764. #endif /* _WM8804_H */
  105765. diff -Nur linux-3.12.26.orig/sound/soc/Kconfig linux-3.12.26/sound/soc/Kconfig
  105766. --- linux-3.12.26.orig/sound/soc/Kconfig 2014-07-30 18:02:44.000000000 +0200
  105767. +++ linux-3.12.26/sound/soc/Kconfig 2014-08-06 16:50:15.213967961 +0200
  105768. @@ -33,6 +33,7 @@
  105769. # All the supported SoCs
  105770. source "sound/soc/atmel/Kconfig"
  105771. source "sound/soc/au1x/Kconfig"
  105772. +source "sound/soc/bcm/Kconfig"
  105773. source "sound/soc/blackfin/Kconfig"
  105774. source "sound/soc/cirrus/Kconfig"
  105775. source "sound/soc/davinci/Kconfig"
  105776. diff -Nur linux-3.12.26.orig/sound/soc/Makefile linux-3.12.26/sound/soc/Makefile
  105777. --- linux-3.12.26.orig/sound/soc/Makefile 2014-07-30 18:02:44.000000000 +0200
  105778. +++ linux-3.12.26/sound/soc/Makefile 2014-08-06 16:50:15.213967961 +0200
  105779. @@ -10,6 +10,7 @@
  105780. obj-$(CONFIG_SND_SOC) += generic/
  105781. obj-$(CONFIG_SND_SOC) += atmel/
  105782. obj-$(CONFIG_SND_SOC) += au1x/
  105783. +obj-$(CONFIG_SND_SOC) += bcm/
  105784. obj-$(CONFIG_SND_SOC) += blackfin/
  105785. obj-$(CONFIG_SND_SOC) += cirrus/
  105786. obj-$(CONFIG_SND_SOC) += davinci/
  105787. diff -Nur linux-3.12.26.orig/sound/soc/soc-core.c linux-3.12.26/sound/soc/soc-core.c
  105788. --- linux-3.12.26.orig/sound/soc/soc-core.c 2014-07-30 18:02:44.000000000 +0200
  105789. +++ linux-3.12.26/sound/soc/soc-core.c 2014-08-06 16:50:15.213967961 +0200
  105790. @@ -3038,8 +3038,8 @@
  105791. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  105792. uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1;
  105793. - uinfo->value.integer.min = 0;
  105794. - uinfo->value.integer.max = platform_max - min;
  105795. + uinfo->value.integer.min = min;
  105796. + uinfo->value.integer.max = platform_max;
  105797. return 0;
  105798. }
  105799. @@ -3070,9 +3070,10 @@
  105800. unsigned int val, val_mask;
  105801. int ret;
  105802. - val = ((ucontrol->value.integer.value[0] + min) & mask);
  105803. if (invert)
  105804. - val = max - val;
  105805. + val = ((max - ucontrol->value.integer.value[0] + min) & mask);
  105806. + else
  105807. + val = (ucontrol->value.integer.value[0] & mask);
  105808. val_mask = mask << shift;
  105809. val = val << shift;
  105810. @@ -3081,9 +3082,10 @@
  105811. return ret;
  105812. if (snd_soc_volsw_is_stereo(mc)) {
  105813. - val = ((ucontrol->value.integer.value[1] + min) & mask);
  105814. if (invert)
  105815. - val = max - val;
  105816. + val = ((max - ucontrol->value.integer.value[1] + min) & mask);
  105817. + else
  105818. + val = (ucontrol->value.integer.value[1] & mask);
  105819. val_mask = mask << shift;
  105820. val = val << shift;
  105821. @@ -3121,18 +3123,14 @@
  105822. (snd_soc_read(codec, reg) >> shift) & mask;
  105823. if (invert)
  105824. ucontrol->value.integer.value[0] =
  105825. - max - ucontrol->value.integer.value[0];
  105826. - ucontrol->value.integer.value[0] =
  105827. - ucontrol->value.integer.value[0] - min;
  105828. + max - ucontrol->value.integer.value[0] + min;
  105829. if (snd_soc_volsw_is_stereo(mc)) {
  105830. ucontrol->value.integer.value[1] =
  105831. (snd_soc_read(codec, rreg) >> shift) & mask;
  105832. if (invert)
  105833. ucontrol->value.integer.value[1] =
  105834. - max - ucontrol->value.integer.value[1];
  105835. - ucontrol->value.integer.value[1] =
  105836. - ucontrol->value.integer.value[1] - min;
  105837. + max - ucontrol->value.integer.value[1] + min;
  105838. }
  105839. return 0;
  105840. @@ -3576,6 +3574,22 @@
  105841. EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll);
  105842. /**
  105843. + * snd_soc_dai_set_bclk_ratio - configure BCLK to sample rate ratio.
  105844. + * @dai: DAI
  105845. + * @ratio Ratio of BCLK to Sample rate.
  105846. + *
  105847. + * Configures the DAI for a preset BCLK to sample rate ratio.
  105848. + */
  105849. +int snd_soc_dai_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio)
  105850. +{
  105851. + if (dai->driver && dai->driver->ops->set_bclk_ratio)
  105852. + return dai->driver->ops->set_bclk_ratio(dai, ratio);
  105853. + else
  105854. + return -EINVAL;
  105855. +}
  105856. +EXPORT_SYMBOL_GPL(snd_soc_dai_set_bclk_ratio);
  105857. +
  105858. +/**
  105859. * snd_soc_dai_set_fmt - configure DAI hardware audio format.
  105860. * @dai: DAI
  105861. * @fmt: SND_SOC_DAIFMT_ format value.